service-personalprofiles-node
v1.0.0
Published
This data microservice stores and retrieves personal profiles.
Downloads
5
Readme
Personal Profiles microservice in Node.js
This data microservice stores and retrieves personal profiles.
Supported functionality:
- Deployment platforms: Standalone Process, Docker
- External APIs: Commandable HTTP
- Persistence: Memory, Flat Files, MongoDB
- Health checks: Heartbeat, Status
- Consolidated logging: ElasticSearch
- Consolidated metrics: Prometheus
- Swagger: http://localhost:8080/swagger/index.html
There are no dependencies on other microservices.
Quick links:
- Client Libraries:
- API Reference
- Change Log
- License
- ToDo List
- Usage Notes
Contract
class PersonalProfileV1 implements IStringIdentifiable {
public id: string;
public org_ids?: string[];
public first_name: string;
public last_name?: string;
public photo_id?: string;
public email?: string;
public phone?: string;
public route: string;
public about_info?: string;
public mail_address?: MailAddressV1;
public social_links?: SocialLinkV1[];
}
class MailAddressV1 {
public address_line1?: string;
public address_line2?: string;
public city?: string;
public region?: string;
public postal_code?: string;
public country?: string;
}
class SocialLinkV1 {
public type: string;
public link?: string;
public enabled: boolean;
}
class SocialLinkTypeV1 {
public static Website = "website";
public static Email = "email";
public static Facebook = "facebook";
public static Twitter = "twitter";
public static Linkedin = "linkedin";
public static Instagram = "instagram";
public static Telegram = "telegram";
public static Whatsapp = "whatsapp";
}
interface IPersonalProfilesController {
getPersonalProfiles(correlationId: string, filter: FilterParams, paging: PagingParams): Promise<DataPage<PersonalProfileV1>>;
getPersonalProfileById(correlationId: string, profileId: string): Promise<PersonalProfileV1>;
createPersonalProfile(correlationId: string, profile: PersonalProfileV1): Promise<PersonalProfileV1>;
updatePersonalProfile(correlationId: string, profile: PersonalProfileV1): Promise<PersonalProfileV1>;
deletePersonalProfileById(correlationId: string, profileId: string): Promise<PersonalProfileV1>;
checkIfRouteExists(correlationId: string, route: string): Promise<boolean>;
addOrganization(correlationId: string, profileId: string, orgId: string): Promise<PersonalProfileV1>;
removeOrganization(correlationId: string, profileId: string, orgId: string): Promise<PersonalProfileV1>;
}
Get
Get the microservice source from BitBucket:
git clone [email protected]:entinco/eic-templates-services-node.git
cd service-personalprofiles-node
Get the docker image for the microservice:
docker pull entinco/service-personalprofiles-node:latest
Run
The microservice can be configured using the following environment variables:
- ELASTICSEARCH_LOGGING_ENABLED - turn on Elasticsearch logs and metrics
- ELASTICSEARCH_PROTOCOL - connection protocol: http or https
- ELASTICSEARCH_SERVICE_URI - resource URI or connection string with all parameters in it
- ELASTICSEARCH_SERVICE_HOST - host name or IP address
- ELASTICSEARCH_SERVICE_PORT - port number
- DEFAULT_RESPONSE - default response from service if empty request
- MONGO_SERVICE_URI - URI to connect to MongoDB. When it's defined other database parameters are ignored
- MONGO_SERVICE_HOST - MongoDB hostname or server address
- MONGO_SERVICE_PORT - MongoDB port number (default: 3360)
- MONGO_DB - MongoDB database name (default: app)
- MONGO_COLLECTION - MongoDB collection (default: id_records)
- MONGO_USER - MongoDB user login
- MONGO_PASS - MongoDB user password
- HTTP_ENABLED - turn on HTTP endpoint
- HTTP_PORT - HTTP port number (default: 8080)
- PUSHGATEWAY_METRICS_ENABLED - turn on pushgetway for prometheus
- PUSHGATEWAY_PROTOCOL - connection protocol: http or https
- PUSHGATEWAY_METRICS_SERVICE_URI - resource URI or connection string with all parameters in it
- PUSHGATEWAY_METRICS_SERVICE_HOST - host name or IP address
- PUSHGATEWAY_METRICS_SERVICE_PORT - port number
- SWAGGER_ROUTE - the path where the swagger service will be available
- SWAGGER_NAME - the header name of swagger service
- SWAGGER_DESCRIPTION - the text description of swagger service
Start the microservice as a process:
node ./bin/main
Run the microservice in docker. Then use the following command:
./run.ps1
Launch the microservice with all infrastructure services using docker-compose:
docker-compose -f ./docker/docker-compose.yml up
Use
Install the client NPM package as:
npm install client-basic-node --save
Inside your code, get the reference to the client library:
import { PersonalProfilesCommandableHttpClientV1 } from 'client-personalprofiles-node';
Instantiate the client:
// Create the client instance
let client = new PersonalProfilesCommandableHttpClientV1();
Define client configuration parameters:
// Client configuration
let httpConfig = ConfigParams.fromTuples(
"connection.protocol", "http",
"connection.host", "localhost",
"connection.port", 3000
);
client.configure(httpConfig);
Connect to the microservice:
// Connect to the microservice
await client.open("123");
Create a new profile:
let profile: PersonalProfileV1 = {
id: '1',
org_ids: ['1', '2'],
first_name: 'profile_first_name',
last_name: 'profile_last_name',
photo_id: 'profile_photo_id',
email: 'profile_email_address',
phone: 'profile_phone_num',
route: 'profile_route',
about_info: 'profile_about_info',
mail_address: <MailAddressV1>{
address_line1: 'mail_address_line1',
address_line2: 'mail_address_line2',
city: 'mail_address_city',
region: 'mail_address_region',
postal_code: '01010',
country: 'mail_address_country'
},
social_links: [
<SocialLinkV1>{
type: SocialLinkTypeV1.Website,
link: 'social_link_website_URL',
enabled: true
},
<SocialLinkV1> {
type: SocialLinkTypeV1.Email,
link: 'social_link_email_address',
enabled: false
},
<SocialLinkV1> {
type: SocialLinkTypeV1.Facebook,
link: 'social_link_facebook_username',
enabled: true
},
<SocialLinkV1> {
type: SocialLinkTypeV1.Twitter,
link: 'social_link_twitter_handle',
enabled: false
},
<SocialLinkV1> {
type: SocialLinkTypeV1.Linkedin,
link: 'social_link_linkedin_username',
enabled: true
},
<SocialLinkV1> {
type: SocialLinkTypeV1.Instagram,
link: 'social_link_instagram_username',
enabled: false
},
<SocialLinkV1> {
type: SocialLinkTypeV1.Telegram,
link: 'social_link_telegram_username',
enabled: true
},
<SocialLinkV1> {
type: SocialLinkTypeV1.Whatsapp,
link: 'social_link_whatsapp_phone_num',
enabled: false
}
]
};
res = await client.createPersonalProfile("123", profile);
console.log("Created profile: ", profile);
Develop
For development, you will need to install the following prerequisites:
- Node.js 14+
- Visual Studio Code or another IDE of your choice
- Docker
Install dependencies:
npm install
Compile the microservice:
tsc
Before running tests, launch the infrastructure services and required microservices:
docker-compose -f ./docker-compose.dev.yml up
Run automated tests:
npm test
Run automated benchmarks:
npm run benchmark
Run linter:
npm run lint
Generate API documentation:
./docgen.ps1
Before committing changes, run dockerized build and test as:
./build.ps1
./test.ps1
./package.ps1
./run.ps1
./clean.ps1
Contacts
This microservice was created by and is currently maintained by Michael Seroukhov.