Package Exports
- service-activities2-node
- service-activities2-node/obj/src/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (service-activities2-node) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Party Activities Microservice for Node.js / ES2017 V2
This is a party activity logging microservice from the Pip.Services library.
- Logs important party activities (sign-ups, sign-ins, creation, changes or deletion of data items, ...)
The microservice currently supports the following deployment options:
- Deployment platforms: Standalone process, AWS Lambda function
- External APIs: HTTP/REST, gRPC
- Persistence: In-memory, flat files, MongoDB
This microservice has no dependencies on other microservices.
Quick Links
- Contract
- Download
- Develop:
- Configure:
- Run:
- Use
- Acknowledgements
- Source Documentation
- Client Libraries:
Contract
The logical contract of the microservice is presented below. For physical implementation (HTTP/REST, gRPC, Lambda), please refer to the documentation of the specific protocol.
class PartyActivityV1 implements IStringIdentifiable {
/* Identification */
public id: string;
public org_id?: string;
/* Identification fields */
public time: Date;
public type: string;
public party: ReferenceV1;
/* References objects (notes, goals, etc.) */
public ref_item?: ReferenceV1;
public ref_parents?: ReferenceV1[];
public ref_party?: ReferenceV1;
/* Other details like % of progress or new status */
public details?: StringValueMap;
}
class ReferenceV1 {
public id: string;
public type: string;
public name?: string;
}
interface IActivitiesService {
getPartyActivities(ctx: IContext, filter: FilterParams, paging: PagingParams): Promise<DataPage<PartyActivityV1>>;
logPartyActivity(ctx: IContext, activity: PartyActivityV1): Promise<PartyActivityV1>;
batchPartyActivities(ctx: IContext, activities: PartyActivityV1[]): Promise<void>;
deletePartyActivities(ctx: IContext, filter: FilterParams): Promise<void>;
}Download
The main way to get the microservice is to check it out directly from the Bitbucket repository:
git clone git@bitbucket.org:entinco/eic-services-users2.gitThe microservice is also available as a NPM package under the same name. You can add a dependency to the microservice into the package.json file of your project:
{
...
"dependencies": {
...
"service-activities2-node": "^1.0.*",
...
}
}Develop
Environment Setup
This is a Node.js project and you have to install Node.js tools. You can download them from the official Node.js website: https://nodejs.org/en/download/
After Node.js is installed, you can verify its version:
node --versionThen you need to install some node tools (recommended to be global):
# Install typescript compiler
npm install typescript -g
# Install mocha test runner
npm install mocha -gTo work with the code repository, you need to install Git: https://git-scm.com/downloads
If you are planning to develop and test using persistent storages other than flat files, you may need to install database servers:
- Install MongoDB: https://www.mongodb.org/downloads
Installing
After your environment is ready, you can copy the microservice source code from the repository:
git clone git@bitbucket.org:entinco/eic-services-users2.gitThen go to the project folder and install dependent modules:
# Install dependencies
npm installIf you have worked with the microservice before, you can check out the latest changes and update the dependencies:
# Update source code
git pull
# Update dependencies
npm updateBuilding
This microservice is written in TypeScript language which is transcompiled into JavaScript. So, if you make changes to the source code, you need to compile it before running or committing. The process will output compiled JavaScript files into the "obj" folder:
tscWhen you do continuous edit-build-test cycles, you can run the TypeScript compiler with "--watch" to detect and compile changes you make automatically:
tsc --watchTesting
Before you execute tests, you may need to set configuration options into a config.yml file, located by default in the "config" folder in the root of the project. For more information, see the Configure guide.
Run unit tests:
npm testExecute benchmarks:
npm run benchmarkContributing
Developers interested in contributing should read the following instructions:
Please do not ask general questions in an issue. Issues are only to report bugs, request enhancements, or request new features. For general questions and discussions, use the Contributors Forum.
It is important to note that for each release, the Changelog is a resource that will itemize all:
- Bug Fixes
- New Features
- Breaking Changes
Configure
As a starting point, you can use this example to create your own config.yml file: ```yaml
descriptor: "pip-services:context-info:default:default:1.0" name: "service-activities2" description: "Activities microservice for pip-services V2"
descriptor: "pip-services:logger:console:default:1.0" level: "trace"
descriptor: "activities:persistence:file:default:1.0" path: "../data/activities.json"
descriptor: "activities:service:default:default:1.0"
descriptor: "pip-services:endpoint:http:default:1.0" connection: protocol: "http" host: "0.0.0.0" port: 8080
descriptor: "activities:controller:commandable-http:default:1.0"
Afterwards, check all configuration options. Specifically, pay attention to connection options
for database and dependent microservices.
For more information on this section, read the
[Pip.Services Configuration Guide](http://docs.pipservices.org/toolkit/recipes/config_file_syntax/).
### <a name="persistence"></a> Persistence
The microservice supports three types of persistence: in-memory, flat files, or MongoDB.
In-memory and flat files are great for development and testing,
while MongoDB is a good option with outstanding performance and scalability, suitable for demanding production installations.
You can choose and configure the option that suits your needs.
#### <a name="memory"></a> Memory
Memory persistence has the following configuration properties:
* options: object - Misc configuration options
- max_page_size: number - Maximum number of items per page (default: 100)
Example:
```yaml
- descriptor: "activities:persistence:memory:default:1.0"
options:
max_page_size: 100File
Flat file persistence has the following configuration properties:
- path: string - file path where SystemEventV1 objects are stored. The object are written into the file in JSON format.
- options: object - Misc configuration options
- max_page_size: number - Maximum number of items per page (default: 100)
Example:
- descriptor: "activities:persistence:file:default:1.0"
path: "./data/activities.json"MongoDB
MongoDB persistence has the following configuration properties:
- connection(s): object - MongoDB connection properties
- options: object - (optional) MongoDB connection options. See http://mongoosejs.com/docs/connections.html for more details.
- debug: boolean - (optional) Enables or disables connection debugging
Example:
- descriptor: "accounts:persistence:file:default:1.0"
connection:
uri: "mongodb://localhost/pipservicestest"
options:
server:
poolSize: 4
socketOptions:
keepAlive: 1
connectTimeoutMS: 5000
auto_reconnect: trueService
Service has no configuration properties.
Example:
- descriptor: "activities:service:default:default:1.0"Controllers
The controller components (also called "endpoints") expose external microservice API for consumers. Each microservice can expose multiple APIs (HTTP/REST, gRPC) and multiple versions of the same API type. At least one controller is required for the microservice to run successfully.
HTTP
HTTP/REST controller has the following configuration properties:
- connection: object - HTTP transport configuration options
- protocol: string - HTTP protocol - 'http' or 'https' (default is 'http')
- host: string - IP address/hostname binding (default is '0.0.0.0')
- port: number - HTTP port number
- swagger: object - (optional) Swagger controller integration options
- enable: boolean - (optional) whether to enable Swagger integration
- auto: boolean - (optional) whether to automatically configure Swagger integration
Example:
# Common HTTP endpoint
- descriptor: "pip-services:endpoint:http:default:1.0"
connection:
protocol: "http"
host: "0.0.0.0"
port: "8080"
# HTTP controller
- descriptor: "activities:controller:commandable-http:default:1.0"
swagger:
enable: true
auto: truegRPC
gRPC controller has the following configuration properties:
- connection: object - gRPC transport configuration options
- protocol: string - gRPC protocol - 'http' or 'https' (default is 'http')
- host: string - IP address/hostname binding (default is '0.0.0.0')
- port: number - gRPC port number
Example:
# Common GRPC endpoint
- descriptor: "pip-services:endpoint:grpc:default:1.0"
connection:
protocol: "http"
host: "0.0.0.0"
port: 8090
# GRPC controller
- descriptor: "activities:controller:grpc:default:1.0"
# Commandable GRPC controller
- descriptor: "activities:controller:commandable-grpc:default:1.0"For more information on this section, read the Pip.Services Configuration Guide.
Run
Standalone Process
The simplest way to deploy the microservice is to run it as a standalone process. This microservice is implemented in JavaScript and requires installation of Node.js. You can get it from the official site at https://nodejs.org/en/download
Step 1. Download the microservice by following the Download instructions.
Step 2. Add a config.yml file to the "config" folder in the root of the project and set configuration parameters. See the Configure guide for details.
Step 3. Start the microservice:
node ./bin/main.jsAWS Lambda Function
This microservice can also be packaged and deployed to AWS as a Lambda function. This microservice is implemented in JavaScript and requires the installation of Node.js. You can download it from the official Node.js website: https://nodejs.org/en/download/
Step 1. Download the microservice by following the Download instructions.
Step 2. Add a config.yml file to the "config" folder in the root of the project and set configuration parameters. See the Configure guide for details.
Step 3. Go to the project folder and install the dependent modules:
npm installStep 4. Package the project folder into a .zip file:
zip -r lambda_function.zip .Step 5. Go to the AWS Lambda console and create a new Lambda function.
- Name: "service-activities2-node"
- Runtime: Choose "Node.js 14.x" or newer
- Function code: Upload the .zip package of the project folder
Step 6: Configure any triggers necessary to invoke the function or invoke it via the AWS Lambda console.
Use
The easiest way to work with the microservice is to use the client library. The complete list of available client libraries for different languages is listed in the Quick Links.
If you use Node.js, then you can add a dependency to the client library into the package.json file of your project:
{
...
"dependencies": {
...
"client-activities2-node": "^1.0.*",
...
}
}Then install the dependency:
# Install new dependencies
npm install
# Update already installed dependencies
npm updateInside your code, get the reference to the client library:
let node_lib = new require('client-activities2-node');Define client configuration parameters that match the configuration of the microservice external API:
// Client configuration
let config = {
connection: {
protocol: 'http',
host: 'localhost',
port: 8080
}
};Instantiate the client and open a connection to the microservice:
// Create the client instance
let client = node_lib.ActivitiesHttpClientV1(config);
// Connect to the microservice
try {
await client.open(null);
// Work with the microservice
...
}
catch (err) {
console.error('Connection to the microservice failed');
console.error(err);
}Now the client is ready to perform operations:
// Log party activity
let activity = await client.logPartyActivity(
null,
{
type: 'signup',
party: {
id: '123',
name: 'Test User'
}
}
);let now = new Date();
// Get the list of system activities
let page = await client.getPartyActivities(
null,
{
party_id: '123',
from_time: new Date(now.getTime() - 24 * 3600 * 1000),
to_time: now
},
{
total: true,
skip: 0,
take: 10
}
);Acknowledgements
This microservice was created by Sergey Seroukhov and is currently maintained by Michael Seroukhov.