diff --git a/services/audit-service/README.md b/services/audit-service/README.md index 7029fae274..ca4c7c5497 100644 --- a/services/audit-service/README.md +++ b/services/audit-service/README.md @@ -22,7 +22,7 @@ ## Overview -The `@sourceloop/audit-service` is a powerful LoopBack microservice specifically designed for managing audit logs. It offers extensive functionality to track and record user actions such as inserts, updates, and deletes. Built on the foundation of [@sourceloop/audit-log](https://www.npmjs.com/package/@sourceloop/audit-log), this service provides a repository mixin for easy integration. +The `@sourceloop/audit-service` is a powerful microservice specifically designed for managing audit logs. It offers extensive functionality to track and record user actions such as inserts, updates, and deletes. Built on the foundation of [@sourceloop/audit-log](https://www.npmjs.com/package/@sourceloop/audit-log), this service provides a repository mixin for easy integration. While the repository mixin logs all actions by default, the audit-service takes customization to the next level. It allows you to selectively audit specific scenarios or cases, giving you complete control over the auditing process. With the service's exposed APIs, you can effortlessly insert and retrieve audited data, enabling you to tailor your auditing approach to your unique needs. @@ -127,6 +127,10 @@ export class AuditDbDataSource The migrations required for this service are processed during the installation automatically if you set the `AUDIT_MIGRATION` or `SOURCELOOP_MIGRATION` env variable. The migrations use [`db-migrate`](https://www.npmjs.com/package/db-migrate) with [`db-migrate-pg`](https://www.npmjs.com/package/db-migrate-pg) driver for migrations, so you will have to install these packages to use auto-migration. Please note that if you are using some pre-existing migrations or databases, they may be affected. In such a scenario, it is advised that you copy the migration files in your project root, using the `AUDIT_MIGRATION_COPY` or `SOURCELOOP_MIGRATION_COPY` env variables. You can customize or cherry-pick the migrations in the copied files according to your specific requirements and then apply them to the DB. + +Additionally, there is now an option to choose between SQL migration or PostgreSQL migration. +NOTE : for [`@sourceloop/cli`](https://www.npmjs.com/package/@sourceloop/cli?activeTab=readme) users, this choice can be specified during the scaffolding process by selecting the "type of datasource" option. + ## Usage ### Creating Logs diff --git a/services/authentication-service/README.md b/services/authentication-service/README.md index 8e23aa06c8..7f829ca03a 100644 --- a/services/authentication-service/README.md +++ b/services/authentication-service/README.md @@ -12,7 +12,7 @@ ## Overview -A Loopback Microservice for handling authentications. It provides - +A Microservice for handling authentications. It provides - - Multi-Tenant support, you can see the database schema [here](#database-schema). - External Identity Provider integration. @@ -130,6 +130,101 @@ npm i @sourceloop/authentication-service - It works for almost all authentication methods provided by this service. - Use `/verify-otp` to enter otp or code from authenticator app. +- **OAuth- using Azure AD** - + - Passport strategy for authenticating via Azure Ad using [passport-azure-ad](https://www.npmjs.com/package/passport-azure-ad). + Make sure you have an account on Azure and have your application registered. Follow the steps [here](https://docs.microsoft.com/en-us/azure/active-directory-b2c/configure-a-sample-node-web-app). + - Refer the .env.example file to add all the relevant env variables for Azure Auth. Note - For boolean values that need to passed as false keep them blank. + We are using cookie based approach instead of session based, so the library requires a cookie-parser middleware. To bind the middleware to you application set AZURE_AUTH_ENABLED=true in env file so the middleware will be added to the sequence. + Also the verifier function uses Signup provider whose implementation needs to be added by the user. + Bind the provider key to its corresponding value. + + ```ts + this.providers[SignUpBindings.AZURE_AD_SIGN_UP_PROVIDER.key] = + AzureAdSignupProvider; + ``` + + ```ts + export class AzureAdSignupProvider implements Provider { + value(): AzureAdSignUpFn { + // sonarignore:start + return async profile => { + // sonarignore:end + throw new HttpErrors.NotImplemented( + `AzureAdSignupProvider not implemented`, + ); + }; + } + } + ``` + + Also bind `VerifyBindings.AZURE_AD_PRE_VERIFY_PROVIDER` and `VerifyBindings.AZURE_AD_POST_VERIFY_PROVIDER` to override the basic implementation provided by [default](https://github.com/sourcefuse/loopback4-microservice-catalog/tree/master/services/authentication-service/src/providers). + +- **Authorizing Public & Private Clients** - + + - In order to authorize public and private clients separately in your application, add the following to application.ts before binding AuthenticationComponent + + ```typescript + import { AuthenticationBindings, AuthenticationConfig} from 'loopback4-authentication'; + this.bind(AuthenticationBindings.CONFIG).to({ + secureClient: true, + } as Authentication Config); + ``` + + - Authorizing Public & Private Clients-Migrations : + + add client_type column to auth_clients table with values public/private + + ```sql + ALTER TABLE main.auth_clients + ADD client_type varchar(100) DEFAULT 'public'; + ``` + +- **Authenticating JWT using RSA Encryption** + + In order to authenticate JWT token using RSA encrytion, we need to provide JWT_PUBLIC_KEY and JWT_PRIVATE_KEY where the JWT_PUBLIC_KEY and JWT_PRIVATE_KEY are the paths to your public and private keys(.pem files).Steps to create Public key and private key are as follows: + + -For creating RSA key pair,use the following command: + To generate private key of length 2048: + + ```bash + openssl genrsa -out private.pem 2048 + ``` + + To generate public key: + + ```bash + openssl rsa -in private.pem -pubout -out public.pem + ``` + + Both the files should be in (.pem) format. + for example: private.pem file for private key and public.pem file for public key. + (refer [this](https://cryptotools.net/rsagen)) + +- **Authenticating Password using RSA Encryption** + + In order to authenticate password using RSA encrytion we need to provide private key through an env variable called `PRIVATE_DECRYPTION_KEY`. + By employing RSA encryption and the private key through the environment variable, this approach enhances the security of password authentication, ensuring that passwords are transmitted and stored in an encrypted manner, and can only be deciphered using the designated private key. + + Its implemented through password decryption provider [here](https://github.com/sourcefuse/loopback4-microservice-catalog/blob/master/services/authentication-service/src/providers/password-decryption.provider.ts) which accepts password in encrypted format.It uses node-forge as default for decryption but can be overriden through this password decryption provider for using any other library. + + Note: When using `.env` file put your private key in single line with line breaks escaped with `\n`, one of the ways of doing so can be found [here](https://serverfault.com/questions/466683/can-an-ssl-certificate-be-on-a-single-line-in-a-file-no-line-breaks). + + +- **Using with Sequelize** + + This service supports Sequelize as the underlying ORM using [@loopback/sequelize](https://www.npmjs.com/package/@loopback/sequelize) extension. And in order to use it, you'll need to do following changes. + + - To use Sequelize in your application, add following to application.ts: + + ```ts + this.bind(AuthServiceBindings.Config).to({ + useCustomSequence: false, + useSequelize: true, + }); + ``` + + - Use the `SequelizeDataSource` in your audit datasource as the parent class. Refer [this](https://www.npmjs.com/package/@loopback/sequelize#step-1-configure-datasource) for more details. + - Start the application `npm start` @@ -370,6 +465,9 @@ export class AuthenticationDbDataSource The migrations required for this service are processed during the installation automatically if you set the `AUTH_MIGRATION` or `SOURCELOOP_MIGRATION` env variable. The migrations use [`db-migrate`](https://www.npmjs.com/package/db-migrate) with [`db-migrate-pg`](https://www.npmjs.com/package/db-migrate-pg) driver for migrations, so you will have to install these packages to use auto-migration. Please note that if you are using some pre-existing migrations or databases, they may be affected. In such a scenario, it is advised that you copy the migration files in your project root, using the `AUTH_MIGRATION_COPY` or `SOURCELOOP_MIGRATION_COPY` env variables. You can customize or cherry-pick the migrations in the copied files according to your specific requirements and then apply them to the DB. +Additionally, there is now an option to choose between SQL migration or PostgreSQL migration. +NOTE : For [`@sourceloop/cli`](https://www.npmjs.com/package/@sourceloop/cli?activeTab=readme) users, this choice can be specified during the scaffolding process by selecting the "type of datasource" option. + ### Database Schema ![Auth DB Schema](https://user-images.githubusercontent.com/77672713/126612271-3ce065aa-9f87-45d4-bf9a-c5cc8ad21764.jpg) @@ -378,119 +476,6 @@ The migrations required for this service are processed during the installation a You can find documentation for some of the providers available in this service [here](./src/providers/README.md) -# **Using AZURE AD for OAuth** - -Passport strategy for authenticating via Azure Ad using [passport-azure-ad](https://www.npmjs.com/package/passport-azure-ad). -Make sure you have an account on Azure and have your application registered. Follow the steps [here](https://docs.microsoft.com/en-us/azure/active-directory-b2c/configure-a-sample-node-web-app). - -### Application Binding - -To use this in your application bind `AuthenticationServiceComponent` the component in your appliation. - -```ts -import {AuthenticationServiceComponent} from '@sourceloop/authentication-service'; - -this.component(AuthenticationServiceComponent); -``` - -### Set the environment variables - -Refer the .env.example file to add all the relevant env variables for Azure Auth. -Note - For boolean values that need to passed as false keep them blank. - -We are using cookie based approach instead of session based, so the library requires a cookie-parser middleware. To bind the middleware to you application set -AZURE_AUTH_ENABLED=true in env file so the middleware will be added to the sequence. - -Also the verifier function uses Signup provider whose implementation needs to be added by the user. - -Bind the provider key to its corresponding value. - -```ts -this.providers[SignUpBindings.AZURE_AD_SIGN_UP_PROVIDER.key] = - AzureAdSignupProvider; -``` - -```ts -export class AzureAdSignupProvider implements Provider { - value(): AzureAdSignUpFn { - // sonarignore:start - return async profile => { - // sonarignore:end - throw new HttpErrors.NotImplemented( - `AzureAdSignupProvider not implemented`, - ); - }; - } -} -``` - -Also bind `VerifyBindings.AZURE_AD_PRE_VERIFY_PROVIDER` and `VerifyBindings.AZURE_AD_POST_VERIFY_PROVIDER` to override the basic implementation provided by [default](https://github.com/sourcefuse/loopback4-microservice-catalog/tree/master/services/authentication-service/src/providers). - -### Authorizing Public & Private Clients - -In order to authorize public and private clients separately in your application, add the following to application.ts before binding AuthenticationComponent - -```typescript -import { AuthenticationBindings, AuthenticationConfig} from 'loopback4-authentication'; -this.bind(AuthenticationBindings.CONFIG).to({ -secureClient: true, -} as Authentication Config); -``` - -#### Authorizing Public & Private Clients-Migrations - -add client_type column to auth_clients table with values public/private - -```sql -ALTER TABLE main.auth_clients -ADD client_type varchar(100) DEFAULT 'public'; -``` - -### Authenticating JWT using RSA Encryption - -In order to authenticate JWT token using RSA encrytion, we need to provide JWT_PUBLIC_KEY and JWT_PRIVATE_KEY where the JWT_PUBLIC_KEY and JWT_PRIVATE_KEY are the paths to your public and private keys(.pem files).Steps to create Public key and private key are as follows: - --For creating RSA key pair,use the following command: -To generate private key of length 2048: - -```bash -openssl genrsa -out private.pem 2048 -``` - -To generate public key: - -```bash -openssl rsa -in private.pem -pubout -out public.pem -``` - -- Both the files should be in (.pem) format. - for example: private.pem file for private key and public.pem file for public key. - (refer [this](https://cryptotools.net/rsagen)) - -### Authenticating Password using RSA Encryption - -In order to authenticate password using RSA encrytion we need to provide private key through an env variable called `PRIVATE_DECRYPTION_KEY`. -By employing RSA encryption and the private key through the environment variable, this approach enhances the security of password authentication, ensuring that passwords are transmitted and stored in an encrypted manner, and can only be deciphered using the designated private key. - -Its implemented through password decryption provider [here](https://github.com/sourcefuse/loopback4-microservice-catalog/blob/master/services/authentication-service/src/providers/password-decryption.provider.ts) which accepts password in encrypted format.It uses node-forge as default for decryption but can be overriden through this password decryption provider for using any other library. - -Note: When using `.env` file put your private key in single line with line breaks escaped with `\n`, one of the ways of doing so can be found [here](https://serverfault.com/questions/466683/can-an-ssl-certificate-be-on-a-single-line-in-a-file-no-line-breaks). - -### Using with Sequelize - -This service supports Sequelize as the underlying ORM using [@loopback/sequelize](https://www.npmjs.com/package/@loopback/sequelize) extension. And in order to use it, you'll need to do following changes. - -1.To use Sequelize in your application, add following to application.ts: - -```ts -this.bind(AuthServiceBindings.Config).to({ - useCustomSequence: false, - useSequelize: true, -}); -``` - -2. Use the `SequelizeDataSource` in your audit datasource as the parent class. Refer [this](https://www.npmjs.com/package/@loopback/sequelize#step-1-configure-datasource) for more details. - #### Common Headers Authorization: Bearer where is a JWT token signed using JWT issuer and secret. diff --git a/services/bpmn-service/README.md b/services/bpmn-service/README.md index 01069b4b0f..de2a3ea73f 100644 --- a/services/bpmn-service/README.md +++ b/services/bpmn-service/README.md @@ -10,7 +10,9 @@ ## Overview -A Loopback Microservice for handling BPMN workflows using engines like [Camunda](https://camunda.com/products/cloud/). NOTE: The microservice currently works with only one workflow definition for a single diagram. It provides - +A Microservice for handling BPMN workflows using engines like [Camunda](https://camunda.com/products/cloud/). + +NOTE: The microservice currently works with only one workflow definition for a single diagram. It provides - - Deployment and management of Workflows in a BPMN engine. - Process Versioning. @@ -63,6 +65,21 @@ npm i @sourceloop/bpmn-service - Start the application `npm start` +#### Using with Sequelize + +This service supports Sequelize as the underlying ORM using [@loopback/sequelize](https://www.npmjs.com/package/@loopback/sequelize) extension. And in order to use it, you'll need to do following changes. + +- To use Sequelize in your application, add following to application.ts along with other config specific to the service: + + ```ts + this.bind(WorkflowServiceBindings.Config).to({ + useCustomSequence: false, + useSequelize: true, + }); + ``` + +- Use the `SequelizeDataSource` in your audit datasource as the parent class. Refer [this](https://www.npmjs.com/package/@loopback/sequelize#step-1-configure-datasource) for more. + ### Setting up a `DataSource` Here is a sample Implementation `DataSource` implementation using environment variables and PostgreSQL as the data source. @@ -123,56 +140,56 @@ A sample implementation of a `DataSource` using environment variables and Postgr ### Providers -#### BPMNProvider - -To use the services, you need to implement a provider and bind it to the `BPMNBindings.BPMNProvider` key. The provider returns a value containing the 5 methods - `getWorkflowById`, `startWorkflow`, `createWorkflow`, `updateWorkflow` and `deleteWorkflowById`. These methods are responsible for performing their respective tasks in the workflow engine. Here is the default implementation of this provider - - -```ts -import {bind, /* inject, */ BindingScope, Provider} from '@loopback/core'; -import {HttpErrors} from '@loopback/rest'; -import {WorflowManager} from '../types'; - -@bind({scope: BindingScope.TRANSIENT}) -export class WorkflowProvider implements Provider { - value() { - return { - getWorkflowById: async () => { - throw new HttpErrors.BadRequest( - 'getWorkflowId function not implemented', - ); - }, - startWorkflow: async () => { - throw new HttpErrors.BadRequest( - 'startWorkflow function not implemented', - ); - }, - createWorkflow: async () => { - throw new HttpErrors.BadRequest( - 'createWorkflow function not implemented', - ); - }, - updateWorkflow: async () => { - throw new HttpErrors.BadRequest( - 'updateWorkflow function not implemented', - ); - }, - deleteWorkflowById: async () => { - throw new HttpErrors.BadRequest( - 'deleteWorkflowById function not implemented', - ); - }, - }; +- BPMNProvider + + To use the services, you need to implement a provider and bind it to the `BPMNBindings.BPMNProvider` key. The provider returns a value containing the 5 methods - `getWorkflowById`, `startWorkflow`, `createWorkflow`, `updateWorkflow` and `deleteWorkflowById`. These methods are responsible for performing their respective tasks in the workflow engine. Here is the default implementation of this provider - + + ```ts + import {bind, /* inject, */ BindingScope, Provider} from '@loopback/core'; + import {HttpErrors} from '@loopback/rest'; + import {WorflowManager} from '../types'; + + @bind({scope: BindingScope.TRANSIENT}) + export class WorkflowProvider implements Provider { + value() { + return { + getWorkflowById: async () => { + throw new HttpErrors.BadRequest( + 'getWorkflowId function not implemented', + ); + }, + startWorkflow: async () => { + throw new HttpErrors.BadRequest( + 'startWorkflow function not implemented', + ); + }, + createWorkflow: async () => { + throw new HttpErrors.BadRequest( + 'createWorkflow function not implemented', + ); + }, + updateWorkflow: async () => { + throw new HttpErrors.BadRequest( + 'updateWorkflow function not implemented', + ); + }, + deleteWorkflowById: async () => { + throw new HttpErrors.BadRequest( + 'deleteWorkflowById function not implemented', + ); + }, + }; + } } -} -``` + ``` -#### WorkerImplementationProvider +- WorkerImplementationProvider -Your workers are automatically initiated once a workflow is executed, to provide the implementation details of workers, you need to give an implementation template of one such worker using the `WorkflowServiceBindings.WorkerImplementationFunction`, a default implementation is provided [here](/src/providers/worker-implementation.provider.ts). You also need to register individual worker commands using the `WorkflowServiceBindings.RegisterWorkerFunction` function; + Your workers are automatically initiated once a workflow is executed, to provide the implementation details of workers, you need to give an implementation template of one such worker using the `WorkflowServiceBindings.WorkerImplementationFunction`, a default implementation is provided [here](/src/providers/worker-implementation.provider.ts). You also need to register individual worker commands using the `WorkflowServiceBindings.RegisterWorkerFunction` function; -#### ExecutionInputValidationProvider +- ExecutionInputValidationProvider -If you need to validate the inputs of a workflow execution, you can bind a custom validation provider using `WorkflowServiceBindings.ExecutionInputValidatorFn` key. The microservice comes with a default implementation using [AJV](https://www.npmjs.com/package/ajv). + If you need to validate the inputs of a workflow execution, you can bind a custom validation provider using `WorkflowServiceBindings.ExecutionInputValidatorFn` key. The microservice comes with a default implementation using [AJV](https://www.npmjs.com/package/ajv). ### Migrations @@ -180,20 +197,8 @@ The migrations required for this service are processed during the installation a This project includes no migrations to seed your BPMN engine. If you are using Camunda BPM Run, you can use either the `resources` folder to seed a model, or you can config it to use a custom DB where you can seed your data. The steps to config Platform Run are given [here](https://camunda.com/blog/2020/03/introducing-camunda-bpm-run/). -### Using with Sequelize - -This service supports Sequelize as the underlying ORM using [@loopback/sequelize](https://www.npmjs.com/package/@loopback/sequelize) extension. And in order to use it, you'll need to do following changes. - -1.To use Sequelize in your application, add following to application.ts along with other config specific to the service: - -```ts -this.bind(WorkflowServiceBindings.Config).to({ - useCustomSequence: false, - useSequelize: true, -}); -``` - -2. Use the `SequelizeDataSource` in your audit datasource as the parent class. Refer [this](https://www.npmjs.com/package/@loopback/sequelize#step-1-configure-datasource) for more. +Additionally, there is now an option to choose between SQL migration or PostgreSQL migration. +NOTE: For [`@sourceloop/cli`](https://www.npmjs.com/package/@sourceloop/cli?activeTab=readme) users, this choice can be specified during the scaffolding process by selecting the "type of datasource" option. ### API Documentation diff --git a/services/chat-service/README.md b/services/chat-service/README.md index c6ef78db8d..a1e8561754 100644 --- a/services/chat-service/README.md +++ b/services/chat-service/README.md @@ -10,7 +10,7 @@ ## Overview -Microservice for handling chat between users and user groups. +A microservice designed to facilitate real-time communication between users and user groups. It provides a scalable and modular solution for handling both individual and group chat functionalities. ### Installation @@ -18,6 +18,23 @@ Microservice for handling chat between users and user groups. npm i @sourceloop/chat-service ``` +### Usage + +### Using with Sequelize + +This service supports Sequelize as the underlying ORM using [@loopback/sequelize](https://www.npmjs.com/package/@loopback/sequelize) extension. And in order to use it, you'll need to do following changes. + +1.To use Sequelize in your application, add following to application.ts: + +```ts +this.bind(ChatServiceBindings.Config).to({ + useCustomSequence: false, + useSequelize: true, +}); +``` + +2. Use the `SequelizeDataSource` in your audit datasource as the parent class. Refer [this](https://www.npmjs.com/package/@loopback/sequelize#step-1-configure-datasource) for more. + ## Implementation Create a new Application using Loopback CLI and add the Component for `ChatService` in `application.ts` @@ -130,20 +147,8 @@ export class ChatDataSource The migrations required for this service are processed during the installation automatically if you set the `CHAT_MIGRATION` or `SOURCELOOP_MIGRATION` env variable. The migrations use [`db-migrate`](https://www.npmjs.com/package/db-migrate) with [`db-migrate-pg`](https://www.npmjs.com/package/db-migrate-pg) driver for migrations, so you will have to install these packages to use auto-migration. Please note that if you are using some pre-existing migrations or databasea, they may be affected. In such a scenario, it is advised that you copy the migration files in your project root, using the `CHAT_MIGRATION_COPY` or `SOURCELOOP_MIGRATION_COPY` env variables. You can customize or cherry-pick the migrations in the copied files according to your specific requirements and then apply them to the DB. -### Using with Sequelize - -This service supports Sequelize as the underlying ORM using [@loopback/sequelize](https://www.npmjs.com/package/@loopback/sequelize) extension. And in order to use it, you'll need to do following changes. - -1.To use Sequelize in your application, add following to application.ts: - -```ts -this.bind(ChatServiceBindings.Config).to({ - useCustomSequence: false, - useSequelize: true, -}); -``` - -2. Use the `SequelizeDataSource` in your audit datasource as the parent class. Refer [this](https://www.npmjs.com/package/@loopback/sequelize#step-1-configure-datasource) for more. +Additionally, there is now an option to choose between SQL migration or PostgreSQL migration. +NOTE: For [`@sourceloop/cli`](https://www.npmjs.com/package/@sourceloop/cli?activeTab=readme) users, this choice can be specified during the scaffolding process by selecting the "type of datasource" option. ### API Documentation diff --git a/services/feature-toggle-service/README.md b/services/feature-toggle-service/README.md index a46be7330f..07752a0a76 100644 --- a/services/feature-toggle-service/README.md +++ b/services/feature-toggle-service/README.md @@ -20,13 +20,12 @@ This feature is an extension of the feature-toggle package -- @sourceloop/featur Initial implementation for system level, tenant level and user level feature flag is provided. ## Installation +```bash npm i @sourceloop/feature-toggle-service - +``` ## Usage -### Service Setup - - Create a new Loopback4 Application (If you don't have one already) lb4 testapp - Install the service - npm i @sourceloop/feature-toggle-service - Set up the [environment variables](#environment-variables) @@ -105,6 +104,10 @@ export class FeatureToggleDbDataSource The migrations required for this service are processed during the installation automatically if you set the `FEATURETOGGLE_MIGRATION` or `SOURCELOOP_MIGRATION` env variable. The migrations use [`db-migrate`](https://www.npmjs.com/package/db-migrate) with [`db-migrate-pg`](https://www.npmjs.com/package/db-migrate-pg) driver for migrations, so you will have to install these packages to use auto-migration. Please note that if you are using some pre-existing migrations or database, they may be effected. In such scenario, it is advised that you copy the migration files in your project root, using the `FEATURETOGGLE_MIGRATION_COPY` or `SOURCELOOP_MIGRATION_COPY` env variables. You can customize or cherry-pick the migrations in the copied files according to your specific requirements and then apply them to the DB. + +Additionally, there is now an option to choose between SQL migration or PostgreSQL migration. +NOTE : For [`@sourceloop/cli`](https://www.npmjs.com/package/@sourceloop/cli?activeTab=readme) users, this choice can be specified during the scaffolding process by selecting the "type of datasource" option. + ### API Documentation #### Common Headers diff --git a/services/in-mail-service/README.md b/services/in-mail-service/README.md index e6edb3afda..1ecff8cd03 100644 --- a/services/in-mail-service/README.md +++ b/services/in-mail-service/README.md @@ -8,8 +8,8 @@ ![npm (prod) dependency version (scoped)](https://img.shields.io/npm/dependency-version/@sourceloop/in-mail-service/@loopback/core) -A Loopback Microservice primarily used for in-mail implementation to compose and view in-mails for -any client application. +## Overview +A Microservice primarily used for in-mail implementation to compose and view in-mails for any client application. ## Installation @@ -78,6 +78,9 @@ export class InmailDataSource The migrations required for this service are processed during the installation automatically if you set the `INMAIL_MIGRATION` or `SOURCELOOP_MIGRATION` env variable. The migrations use [`db-migrate`](https://www.npmjs.com/package/db-migrate) with [`db-migrate-pg`](https://www.npmjs.com/package/db-migrate-pg) driver for migrations, so you will have to install these packages to use auto-migration. Please note that if you are using some pre-existing migrations or databases, they may be affected. In such a scenario, it is advised that you copy the migration files in your project root, using the `INMAIL_MIGRATION_COPY` or `SOURCELOOP_MIGRATION_COPY` env variables. You can customize or cherry-pick the migrations in the copied files according to your specific requirements and then apply them to the DB. +Additionally, there is now an option to choose between SQL migration or PostgreSQL migration. +NOTE : For @sourceloop/cli users, this choice can be specified during the scaffolding process by selecting the "type of datasource" option. + #### Database Model ![db-schema](./migrations/in_mail_db.png) diff --git a/services/notification-service/README.md b/services/notification-service/README.md index 26f3efa82f..ae7d1ee73d 100644 --- a/services/notification-service/README.md +++ b/services/notification-service/README.md @@ -28,106 +28,110 @@ npm i @sourceloop/notification-service - Run the [migrations](#migrations). - Add the `NotificationServiceComponent` to your Loopback4 Application (in `application.ts`). ```typescript - // add Component for AuthenticationService + // add Component for NotificationService this.component(NotificationServiceComponent); ``` - Set up a [Loopback4 Datasource](https://loopback.io/doc/en/lb4/DataSource.html) with `dataSourceName` property set to `NotifDbSourceName`. You can see an example datasource [here](#setting-up-a-datasource). - Using this service you can send Email, SMS and push notifications. Steps to add any of these are described below. You may choose to add one or more of these depending on your requirement. - - **Email Notifications with Amazon SES** - +- **Email Notifications with Amazon SES** - - - Bind the SES Config to the `SESBindings.Config` key - + - Bind the SES Config to the `SESBindings.Config` key - - ```typescript - this.bind(SESBindings.Config).to({ - accessKeyId: process.env.SES_ACCESS_KEY_ID, - secretAccessKey: process.env.SES_SECRET_ACCESS_KEY, - region: process.env.SES_REGION, - }); - ``` + ```typescript + this.bind(SESBindings.Config).to({ + accessKeyId: process.env.SES_ACCESS_KEY_ID, + secretAccessKey: process.env.SES_SECRET_ACCESS_KEY, + region: process.env.SES_REGION, + }); + ``` - - Implement an SES Provider(refer [this](https://github.com/sourcefuse/loopback4-notifications/tree/master/src/providers/email/ses)) or you can import the default SES provider from the [loopback4-notifications](https://www.npmjs.com/package/loopback4-notifications) module and bind it to the `NotificationBindings.EmailProvider` key as described [here](https://github.com/sourcefuse/loopback4-notifications#email-notifications). + - Implement an SES Provider(refer [this](https://github.com/sourcefuse/loopback4-notifications/tree/master/src/providers/email/ses)) or you can import the default SES provider from the [loopback4-notifications](https://www.npmjs.com/package/loopback4-notifications) module and bind it to the `NotificationBindings.EmailProvider` key as described [here](https://github.com/sourcefuse/loopback4-notifications#email-notifications). - - **Email Notifications with Nodemailer** - +- **Email Notifications with Nodemailer** - - - Bind the Nodemailer Config to the `NodemailerBindings.Config` key - + - Bind the Nodemailer Config to the `NodemailerBindings.Config` key - - ```typescript - this.bind(NodemailerBindings.Config).to({ - pool: true, - maxConnections: 100, - url: '', - host: 'smtp.example.com', - port: 80, - secure: false, - auth: { - user: 'username', - pass: 'password', - }, - tls: { - rejectUnauthorized: true, - }, - }); - ``` + ```typescript + this.bind(NodemailerBindings.Config).to({ + pool: true, + maxConnections: 100, + url: '', + host: 'smtp.example.com', + port: 80, + secure: false, + auth: { + user: 'username', + pass: 'password', + }, + tls: { + rejectUnauthorized: true, + }, + }); + ``` - - Implement a Nodemailer Provider(refer [this](https://github.com/sourcefuse/loopback4-notifications/tree/master/src/providers/email/nodemailer)) or import the default Nodemailer provider from the [loopback4-notifications](https://www.npmjs.com/package/loopback4-notifications) module and bind it to the `NotificationBindings.EmailProvider` key as described [here](https://github.com/sourcefuse/loopback4-notifications#email-notifications), + - Implement a Nodemailer Provider(refer [this](https://github.com/sourcefuse/loopback4-notifications/tree/master/src/providers/email/nodemailer)) or import the default Nodemailer provider from the [loopback4-notifications](https://www.npmjs.com/package/loopback4-notifications) module and bind it to the `NotificationBindings.EmailProvider` key as described [here](https://github.com/sourcefuse/loopback4-notifications#email-notifications), - - **SMS Notification with Amazon SNS** - - - Bind the SNS Config to the `SNSBindings.Config` key - - ```typescript - this.bind(SNSBindings.Config).to({ - accessKeyId: process.env.SNS_ACCESS_KEY_ID, - secretAccessKey: process.env.SNS_SECRET_ACCESS_KEY, - region: process.env.SNS_REGION, - }); - ``` - - Implement an SnsProvider(refer [this](https://github.com/sourcefuse/loopback4-notifications/tree/master/src/providers/sms/sns)) or import the default SNS provider from the [loopback4-notifications](https://www.npmjs.com/package/loopback4-notifications) module and bind it to the `NotificationBindings.SMSProvider` key - - ```typescript - import {NotificationBindings} from 'loopback4-notifications'; - import {SnsProvider} from 'loopback4-notifications/sns'; // or your own provider - ... - this.bind(NotificationBindings.SMSProvider).toProvider(SnsProvider); - ... - ``` - - **Push Notifications with Pubnub** - - - Bind the Pubnub Config to the `PubnubBindings.Config` key - - ```typescript - this.bind(PubnubBindings.Config).to({ - subscribeKey: process.env.PUBNUB_SUBSCRIBE_KEY, - publishKey: process.env.PUBNUB_PUBLISH_KEY, - secretKey: process.env.PUBNUB_SECRET_KEY, - ssl: true, - logVerbosity: true, - uuid: 'my-app', - cipherKey: process.env.PUBNUB_CIPHER_KEY, - apns2Env: 'production', - apns2BundleId: 'com.app.myapp', - }); - ``` - - Implement a Pubnub Provider(refer [this](https://github.com/sourcefuse/loopback4-notifications/tree/master/src/providers/push/pubnuba)) or import the default Pubnub provider from the [loopback4-notifications](https://www.npmjs.com/package/loopback4-notifications) module and bind it to the `NotificationBindings.PushProvider` key - - ```typescript - import {NotificationBindings} from 'loopback4-notifications'; - import {PubNubProvider} from 'loopback4-notifications/pubnub'; //or your own provider - ... - this.bind(NotificationBindings.PushProvider).toProvider(PubNubProvider); - ... - ``` - - **Push Notifications with Socket.io** - - - Bind the Socket.io Config to the `SocketBindings.Config` key - - ```typescript - this.bind(SocketBindings.Config).to({ - url: process.env.SOCKETIO_SERVER_URL, - }); - ``` - - Implement a SocketIO Provider(refer [this](https://github.com/sourcefuse/loopback4-notifications/tree/master/src/providers/push/socketio)) or import the default Socket.io provider from the [loopback4-notifications](https://www.npmjs.com/package/loopback4-notifications) module and bind it to the `NotificationBindings.PushProvider` key - - ```typescript - import {NotificationBindings} from 'loopback4-notifications'; - import {SocketIOProvider} from 'loopback4-notifications/socketio'; //or your own provider - ... - this.bind(NotificationBindings.PushProvider).toProvider(SocketIOProvider); - ... - ``` +- **SMS Notification with Amazon SNS** - + - Bind the SNS Config to the `SNSBindings.Config` key - + ```typescript + this.bind(SNSBindings.Config).to({ + accessKeyId: process.env.SNS_ACCESS_KEY_ID, + secretAccessKey: process.env.SNS_SECRET_ACCESS_KEY, + region: process.env.SNS_REGION, + }); + ``` + - Implement an SnsProvider(refer [this](https://github.com/sourcefuse/loopback4-notifications/tree/master/src/providers/sms/sns)) or import the default SNS provider from the [loopback4-notifications](https://www.npmjs.com/package/loopback4-notifications) module and bind it to the `NotificationBindings.SMSProvider` key - + ```typescript + import {NotificationBindings} from 'loopback4-notifications'; + import {SnsProvider} from 'loopback4-notifications/sns'; // or your own provider + ... + this.bind(NotificationBindings.SMSProvider).toProvider(SnsProvider); + ... + ``` +- **Push Notifications with Pubnub** - + - Bind the Pubnub Config to the `PubnubBindings.Config` key - + ```typescript + this.bind(PubnubBindings.Config).to({ + subscribeKey: process.env.PUBNUB_SUBSCRIBE_KEY, + publishKey: process.env.PUBNUB_PUBLISH_KEY, + secretKey: process.env.PUBNUB_SECRET_KEY, + ssl: true, + logVerbosity: true, + uuid: 'my-app', + cipherKey: process.env.PUBNUB_CIPHER_KEY, + apns2Env: 'production', + apns2BundleId: 'com.app.myapp', + }); + ``` + - Implement a Pubnub Provider(refer [this](https://github.com/sourcefuse/loopback4-notifications/tree/master/src/providers/push/pubnuba)) or import the default Pubnub provider from the [loopback4-notifications](https://www.npmjs.com/package/loopback4-notifications) module and bind it to the `NotificationBindings.PushProvider` key - + ```typescript + import {NotificationBindings} from 'loopback4-notifications'; + import {PubNubProvider} from 'loopback4-notifications/pubnub'; //or your own provider + ... + this.bind(NotificationBindings.PushProvider).toProvider(PubNubProvider); + ... + ``` +- **Push Notifications with Socket.io** - + + - Bind the Socket.io Config to the `SocketBindings.Config` key - + + ```typescript + this.bind(SocketBindings.Config).to({ + url: process.env.SOCKETIO_SERVER_URL, + }); + ``` + + - Implement a SocketIO Provider(refer [this](https://github.com/sourcefuse/loopback4-notifications/tree/master/src/providers/push/socketio)) or import the default Socket.io provider from the [loopback4-notifications](https://www.npmjs.com/package/loopback4-notifications) module and bind it to the `NotificationBindings.PushProvider` key - + + ```typescript + import {NotificationBindings} from 'loopback4-notifications'; + import {SocketIOProvider} from 'loopback4-notifications/socketio'; //or your own provider + ... + this.bind(NotificationBindings.PushProvider).toProvider(SocketIOProvider); + ... + ``` - Start the application `npm start` @@ -256,60 +260,21 @@ interface SocketMessage { } ``` -### Environment Variables - -| Name | Required | Default Value | Description | -| ------------- | -------- | ------------- | ---------------------------------------------------------------------------------------------------------------------------------- | -| `NODE_ENV` | Y | | Node environment value, i.e. `dev`, `test`, `prod` | -| `LOG_LEVEL` | Y | | Log level value, i.e. `error`, `warn`, `info`, `verbose`, `debug` | -| `DB_HOST` | Y | | Hostname for the database server. | -| `DB_PORT` | Y | | Port for the database server. | -| `DB_USER` | Y | | User for the database. | -| `DB_PASSWORD` | Y | | Password for the database user. | -| `DB_DATABASE` | Y | | Database to connect to on the database server. | -| `DB_SCHEMA` | Y | | Database schema used for the data source. In PostgreSQL, this will be `public` unless a schema is made explicitly for the service. | -| `JWT_SECRET` | Y | | Symmetric signing key of the JWT token. | -| `JWT_ISSUER` | Y | | Issuer of the JWT token. | - -### Setting up a `DataSource` - -Here is a sample Implementation `DataSource` implementation using environment variables and PostgreSQL as the data source. - -```typescript -import {inject, lifeCycleObserver, LifeCycleObserver} from '@loopback/core'; -import {juggler} from '@loopback/repository'; -import {NotifDbSourceName} from '@sourceloop/notification-service'; +### Using with Sequelize -const config = { - name: NotifDbSourceName, - connector: 'postgresql', - url: '', - host: process.env.DB_HOST, - port: process.env.DB_PORT, - user: process.env.DB_USER, - password: process.env.DB_PASSWORD, - database: process.env.DB_DATABASE, - schema: process.env.DB_SCHEMA, -}; +This service supports Sequelize as the underlying ORM using [@loopback/sequelize](https://www.npmjs.com/package/@loopback/sequelize) extension. And in order to use it, you'll need to do following changes. -@lifeCycleObserver('datasource') -export class NotificationDbDataSource - extends juggler.DataSource - implements LifeCycleObserver -{ - static dataSourceName = NotifDbSourceName; - static readonly defaultConfig = config; +1.To use Sequelize in your application, add following to application.ts: - constructor( - // You need to set datasource configuration name as 'datasources.config.Notification' otherwise you might get Errors - @inject('datasources.config.Notification', {optional: true}) - dsConfig: object = config, - ) { - super(dsConfig); - } -} +```ts +this.bind(NotifServiceBindings.Config).to({ + useCustomSequence: false, + useSequelize: true, +}); ``` +2. Use the `SequelizeDataSource` in your audit datasource as the parent class. Refer [this](https://www.npmjs.com/package/@loopback/sequelize#step-1-configure-datasource) for more. + ### Blacklisting Users Here is a sample implementation of how we can blacklist a user(s). @@ -357,153 +322,210 @@ this.bind(NotifServiceBindings.NotificationFilter).toProvider( Note: One can modify the provider according to the requirements ### **Drafting Notification** - - Notification drafting i.e. draft or save notification to send it later. - 1. For this, there is a POST API to save notification as draft. There is one column in DB in `notifications` table `is_draft` which is used to mark a notification as draft. - 2. The drafted notification could be `based on a group key` OR `without a group key`. In DB group key is saved in a column called `group_key`. - - - There is a POST API with end url `/notifications/drafts` to save notification(s) as draft. - - The draft notification request body `with group key` looks like: - - ```json - { - "body": "text", - "groupKey":"text", - "type": "number" - } - ``` - - The draft notification request body `without group key` looks like, e.g. the email notification draft: - - ```json - { - "body": "text", - "body":"text", - "type": "number", - "receiver": - { - "to": [ - { - "type": "number", - "id": "text" - } - ] - } - } - ``` -### **Grouping Notification** - - - Notification grouping i.e. send many notification as one notification by grouping those together using the `groupKey` OR `group_key` field from DB table. - 1. There is an API's to send already saved or already drafted notifications by grouping it using `groupKey`. - 2. The API end point looks like `/notifications/groups/{groupKey}`. - 3. The request body of the API to send the grouped notification looks like below. Note that, this `example` request body is for email notification. - ```json - { - "subject": "text", - "receiver": { - "to": [ - { - "type": "number", - "id": "text" - } - ] - }, - "options": { - "fromEmail": "string" - }, - "isCritical":"boolean", - "type": "number" - } - ``` - - In above request body one can add additional key to the json object in case they want to concatenate new thing in addition to saved drafts and then request body will look like below: + +Notification drafting i.e. draft or save notification to send it later. + +1. For this, there is a POST API to save notification as draft. There is one column in DB in `notifications` table `is_draft` which is used to mark a notification as draft. +2. The drafted notification could be `based on a group key` OR `without a group key`. In DB group key is saved in a column called `group_key`. + + - There is a POST API with end url `/notifications/drafts` to save notification(s) as draft. + - The draft notification request body `with group key` looks like: + + ```json + { + "body": "text", + "groupKey": "text", + "type": "number" + } + ``` + + - The draft notification request body `without group key` looks like, e.g. the email notification draft: + ```json - { - "subject": "text", - "body": "text", - "receiver": { - "to": [ - { - "type": "number", - "id": "text" - } - ] - }, - "options": { - "fromEmail": "string" - }, - "isCritical":"boolean", - "type": "number" - } - ``` + { + "body": "text", + "body": "text", + "type": "number", + "receiver": { + "to": [ + { + "type": "number", + "id": "text" + } + ] + } + } + ``` + +### **Grouping Notification** - + +Notification grouping i.e. send many notification as one notification by grouping those together using the `groupKey` OR `group_key` field from DB table. + +1. There is an API's to send already saved or already drafted notifications by grouping it using `groupKey`. +2. The API end point looks like `/notifications/groups/{groupKey}`. +3. The request body of the API to send the grouped notification looks like below. Note that, this `example` request body is for email notification. + + ```json + { + "subject": "text", + "receiver": { + "to": [ + { + "type": "number", + "id": "text" + } + ] + }, + "options": { + "fromEmail": "string" + }, + "isCritical": "boolean", + "type": "number" + } + ``` + + - In above request body one can add additional key to the json object in case they want to concatenate new thing in addition to saved drafts and then request body will look like below: + + ```json + { + "subject": "text", + "body": "text", + "receiver": { + "to": [ + { + "type": "number", + "id": "text" + } + ] + }, + "options": { + "fromEmail": "string" + }, + "isCritical": "boolean", + "type": "number" + } + ``` + ### **Sending Drafted Notification Independently** - - There is one API for sending drafted notification independently using `id` of already saved or drafted notification. - 1. This API has `id` (of an already drafted notification) in it's end point which looks like `/notifications/{draftedNotificationId}/send` and it sends already saved or drafted notification to the receiver(s). - 2. The request body for this API looks like - ```json - { - "options": { - "fromEmail": "string" - }, - "isCritical":"boolean", - } - ``` + +There is one API for sending drafted notification independently using `id` of already saved or drafted notification. + +1. This API has `id` (of an already drafted notification) in it's end point which looks like `/notifications/{draftedNotificationId}/send` and it sends already saved or drafted notification to the receiver(s). +2. The request body for this API looks like + + ```json + { + "options": { + "fromEmail": "string" + }, + "isCritical": "boolean" + } + ``` + ### **User Notification Sleep Time Settings** - - User or receiver's sleep time settings will allow user to stop from getting notifications for any given time interval. There are API's as mentioned below which are used to manage User notification settings for sleep time - 1. There is a POST API with end url `/notifications/user-notification-settings` to add sleep time of user or receiver into DB. The request body for this looks like below: - ```json - { - "userId": "text", - "sleepStartTime": "timestamp", - "sleepEndTime": "timestamp", - "type":"number" - } - ``` - 2. There is a PATCH API with end url `/notifications/user-notification-settings/{id}` to update sleep time of user or receiver in DB. The request body for this looks like below: + +User or receiver's sleep time settings will allow user to stop from getting notifications for any given time interval. There are API's as mentioned below which are used to manage User notification settings for sleep time + +1. There is a POST API with end url `/notifications/user-notification-settings` to add sleep time of user or receiver into DB. The request body for this looks like below: + + ```json + { + "userId": "text", + "sleepStartTime": "timestamp", + "sleepEndTime": "timestamp", + "type": "number" + } + ``` + +2. There is a PATCH API with end url `/notifications/user-notification-settings/{id}` to update sleep time of user or receiver in DB. The request body for this looks like below: + + ```json + { + "userId": "text", + "sleepStartTime": "timestamp", + "sleepEndTime": "timestamp", + "type": "number" + } + ``` + +3. There is a GET API with end url `/notifications/user-notification-settings` to get all sleep time settings of users or receivers from DB. +4. There is a GET API with end url `/notifications/user-notification-settings/{id}` to get sleep time setting of a user or a receiver from DB by given id. +5. There is a DELETE API with end url `/notifications/user-notification-settings/{id}` to delete sleep time setting of a user or a receiver from DB by given id. + +- **Note:** _Sleep time is applicable for send grouped notification API as well as for send drafted notification by id except in case request body contains parameter `isCritical` and it's value is true. The value of field `isCritical` is saved in DB into the column named `is_critical`._ +- **Send notification to users having sleep time in past:** + - There is one POST API with end url `/notifications/send` which sends notifications to users (with respect a given search criteria in the request body) who where having sleep time when notifications were being sent (in past). For this API the request body looks like: ```json - { - "userId": "text", - "sleepStartTime": "timestamp", - "sleepEndTime": "timestamp", - "type":"number" - } - ``` - 3. There is a GET API with end url `/notifications/user-notification-settings` to get all sleep time settings of users or receivers from DB. - 4. There is a GET API with end url `/notifications/user-notification-settings/{id}` to get sleep time setting of a user or a receiver from DB by given id. - 5. There is a DELETE API with end url `/notifications/user-notification-settings/{id}` to delete sleep time setting of a user or a receiver from DB by given id. - - **Note:** *Sleep time is applicable for send grouped notification API as well as for send drafted notification by id except in case request body contains parameter `isCritical` and it's value is true. The value of field `isCritical` is saved in DB into the column named `is_critical`.* - - **Send notification to users having sleep time in past:** - - There is one POST API with end url `/notifications/send` which sends notifications to users (with respect a given search criteria in the request body) who where having sleep time when notifications were being sent (in past). For this API the request body looks like: - ```json - { - "ids": [ - "text" - ], - "userId": [ - "text" - ], - "startTime": "timestamp", - "endTime": "timestamp" - } - ``` - - Based on given search criteria in the request body, this API finds the receiver(s) and the respective notifications which could not be sent due to the receiver's sleep time interval and sends it. - - **Note:** To use this feature in your application, please run the required migrations. Also if one want to make some logical changes they can make changes in the provider. + { + "ids": ["text"], + "userId": ["text"], + "startTime": "timestamp", + "endTime": "timestamp" + } + ``` + - Based on given search criteria in the request body, this API finds the receiver(s) and the respective notifications which could not be sent due to the receiver's sleep time interval and sends it. +- **Note:** To use this feature in your application, please run the required migrations. Also if one want to make some logical changes they can make changes in the provider. -### Migrations +### Environment Variables -The migrations required for this service are processed during the installation automatically if you set the `NOTIF_MIGRATION` or `SOURCELOOP_MIGRATION` env variable. The migrations use [`db-migrate`](https://www.npmjs.com/package/db-migrate) with [`db-migrate-pg`](https://www.npmjs.com/package/db-migrate-pg) driver for migrations, so you will have to install these packages to use auto-migration. Please note that if you are using some pre-existing migrations or databases, they may be affected. In such a scenario, it is advised that you copy the migration files in your project root, using the `NOTIF_MIGRATION_COPY` or `SOURCELOOP_MIGRATION_COPY` env variables. You can customize or cherry-pick the migrations in the copied files according to your specific requirements and then apply them to the DB. +| Name | Required | Default Value | Description | +| ------------- | -------- | ------------- | ---------------------------------------------------------------------------------------------------------------------------------- | +| `NODE_ENV` | Y | | Node environment value, i.e. `dev`, `test`, `prod` | +| `LOG_LEVEL` | Y | | Log level value, i.e. `error`, `warn`, `info`, `verbose`, `debug` | +| `DB_HOST` | Y | | Hostname for the database server. | +| `DB_PORT` | Y | | Port for the database server. | +| `DB_USER` | Y | | User for the database. | +| `DB_PASSWORD` | Y | | Password for the database user. | +| `DB_DATABASE` | Y | | Database to connect to on the database server. | +| `DB_SCHEMA` | Y | | Database schema used for the data source. In PostgreSQL, this will be `public` unless a schema is made explicitly for the service. | +| `JWT_SECRET` | Y | | Symmetric signing key of the JWT token. | +| `JWT_ISSUER` | Y | | Issuer of the JWT token. | -### Using with Sequelize +### Setting up a `DataSource` -This service supports Sequelize as the underlying ORM using [@loopback/sequelize](https://www.npmjs.com/package/@loopback/sequelize) extension. And in order to use it, you'll need to do following changes. +Here is a sample Implementation `DataSource` implementation using environment variables and PostgreSQL as the data source. -1.To use Sequelize in your application, add following to application.ts: +```typescript +import {inject, lifeCycleObserver, LifeCycleObserver} from '@loopback/core'; +import {juggler} from '@loopback/repository'; +import {NotifDbSourceName} from '@sourceloop/notification-service'; -```ts -this.bind(NotifServiceBindings.Config).to({ - useCustomSequence: false, - useSequelize: true, -}); +const config = { + name: NotifDbSourceName, + connector: 'postgresql', + url: '', + host: process.env.DB_HOST, + port: process.env.DB_PORT, + user: process.env.DB_USER, + password: process.env.DB_PASSWORD, + database: process.env.DB_DATABASE, + schema: process.env.DB_SCHEMA, +}; + +@lifeCycleObserver('datasource') +export class NotificationDbDataSource + extends juggler.DataSource + implements LifeCycleObserver +{ + static dataSourceName = NotifDbSourceName; + static readonly defaultConfig = config; + + constructor( + // You need to set datasource configuration name as 'datasources.config.Notification' otherwise you might get Errors + @inject('datasources.config.Notification', {optional: true}) + dsConfig: object = config, + ) { + super(dsConfig); + } +} ``` -2. Use the `SequelizeDataSource` in your audit datasource as the parent class. Refer [this](https://www.npmjs.com/package/@loopback/sequelize#step-1-configure-datasource) for more. +### Migrations + +The migrations required for this service are processed during the installation automatically if you set the `NOTIF_MIGRATION` or `SOURCELOOP_MIGRATION` env variable. The migrations use [`db-migrate`](https://www.npmjs.com/package/db-migrate) with [`db-migrate-pg`](https://www.npmjs.com/package/db-migrate-pg) driver for migrations, so you will have to install these packages to use auto-migration. Please note that if you are using some pre-existing migrations or databases, they may be affected. In such a scenario, it is advised that you copy the migration files in your project root, using the `NOTIF_MIGRATION_COPY` or `SOURCELOOP_MIGRATION_COPY` env variables. You can customize or cherry-pick the migrations in the copied files according to your specific requirements and then apply them to the DB. + +Additionally, there is now an option to choose between SQL migration or PostgreSQL migration. +NOTE: For [`@sourceloop/cli`](https://www.npmjs.com/package/@sourceloop/cli?activeTab=readme) users, this choice can be specified during the scaffolding process by selecting the "type of datasource" option. ### API Documentation diff --git a/services/oidc-service/README.md b/services/oidc-service/README.md index 32e218edf0..2836be6d2c 100644 --- a/services/oidc-service/README.md +++ b/services/oidc-service/README.md @@ -324,6 +324,31 @@ Detailed description for above keys here: https://openid.net/specs/openid-connec The migrations required for this service are processed during the installation automatically if you set the `OIDC_MIGRATION` or `SOURCELOOP_MIGRATION` env variable. The migrations use [`db-migrate`](https://www.npmjs.com/package/db-migrate) with [`db-migrate-pg`](https://www.npmjs.com/package/db-migrate-pg) driver for migrations, so you will have to install these packages to use auto-migration. Please note that if you are using some pre-existing migrations or databasea, they may be affected. In such a scenario, it is advised that you copy the migration files in your project root, using the `OIDC_MIGRATION_COPY` or `SOURCELOOP_MIGRATION_COPY` env variables. You can customize or cherry-pick the migrations in the copied files according to your specific requirements and then apply them to the DB. +Additionally, there is now an option to choose between SQL migration or PostgreSQL migration. +NOTE : For @sourceloop/cli users, this choice can be specified during the scaffolding process by selecting the "type of datasource" option. + + +### API Documentation + +#### Common Headers + +Authorization: Bearer where is a JWT token signed using JWT issuer and secret. +`Content-Type: application/json` in the response and in request if the API method is NOT GET + +#### Common Request path Parameters + +{version}: Defines the API Version + +### Common Responses + +200: Successful Response. Response body varies w.r.t API +401: Unauthorized: The JWT token is missing or invalid +403: Forbidden : Not allowed to execute the concerned API +404: Entity Not Found +400: Bad Request (Error message varies w.r.t API) +201: No content: Empty Response + + #### API Details Visit the [OpenAPI spec docs](./openapi.md) diff --git a/services/payment-service/README.md b/services/payment-service/README.md index 6331f1207d..f2765d6183 100644 --- a/services/payment-service/README.md +++ b/services/payment-service/README.md @@ -8,9 +8,14 @@ ![npm (prod) dependency version (scoped)](https://img.shields.io/npm/dependency-version/@sourceloop/payment-service/@loopback/core) +## Overview + A Loopback Microservice primarily used for payment implementation to charge the payments for any client application. +- Users can seamlessly integrate PayPal for payment transactions. +- The microservice supports Stripe as a preferred payment gateway option. +- Razorpay integration is also available for users seeking diverse payment methods. ## Installation ```bash @@ -32,32 +37,68 @@ npm i @sourceloop/payment-service // add Component for PaymentServiceComponent this.component(PaymentServiceComponent); ``` - **Binding the Providers** +- Set up a [Loopback4 Datasource](https://loopback.io/doc/en/lb4/DataSource.html) with `dataSourceName` property set to `PaymentDatasourceName`. You can see an example datasource [here](#setting-up-a-datasource). +- Bind any of the custom [providers](#providers) you need. +- **Using Paypal payment Gateway** + Bind the PayPalHelper and PayPalConfig as shown below + ```typescript + //import Providers + import { + PayPalBindings, + PaypalProvider + } from 'payment-service/dist/providers'; + //Bind the providers + this.bind(PayPalBindings.PayPalHelper.key).toProvider(PaypalProvider); + this.bind(PayPalBindings.PayPalConfig).to({ + clientId: process.env.PAYPAL_CLIENT_ID ?? '', + clientSecret: process.env.PAYPAL_CLIENT_SECRET ?? '', + }); + ``` -```typescript -//import Providers -import { - GatewayBindings, - GatewayProvider, - RazorpayBindings, - RazorpayProvider, - StripeBindings, - StripeProvider, -} from 'payment-service/dist/providers'; -//Bind the providers -this.bind(StripeBindings.Config).to({dataKey: '', publishKey: ''}); -this.bind(StripeBindings.StripeHelper).toProvider(StripeProvider); -this.bind(RazorpayBindings.RazorpayConfig).to({dataKey: '', publishKey: ''}); -this.bind(RazorpayBindings.RazorpayHelper).toProvider(RazorpayProvider); -this.bind(GatewayBindings.GatewayHelper).toProvider(GatewayProvider); -this.bind(PayPalBindings.PayPalHelper.key).toProvider(PaypalProvider); -this.bind(PayPalBindings.PayPalConfig).to({ - clientId: process.env.PAYPAL_CLIENT_ID ?? '', - clientSecret: process.env.PAYPAL_CLIENT_SECRET ?? '', -}); -``` +- **Using Stripe payment Gateway** + Bind the StripeHelper and Config as shown below + + + ```typescript + //import Providers + import { + StripeBindings, + StripeProvider, + } from 'payment-service/dist/providers'; + //Bind the providers + this.bind(StripeBindings.Config).to({dataKey: '', publishKey: ''}); + this.bind(StripeBindings.StripeHelper).toProvider(StripeProvider); + ``` + +- **Using RazorPay payment Gateway** + Bind the RazorPayHelper and RazorPayConfig as shown below + + ```typescript + //import Providers + import { + RazorpayBindings, + RazorpayProvider, + } from 'payment-service/dist/providers'; + //Bind the providers + this.bind(RazorpayBindings.RazorpayConfig).to({dataKey: '', publishKey: ''}); + this.bind(RazorpayBindings.RazorpayHelper).toProvider(RazorpayProvider); + ``` + +- **Using with Sequelize** + + This service supports Sequelize as the underlying ORM using [@loopback/sequelize](https://www.npmjs.com/package/@loopback/sequelize) extension. And in order to use it, you'll need to do following changes. + + - To use Sequelize in your application, add following to application.ts: + + ```ts + this.bind(PaymentServiceBindings.Config).to({ + useCustomSequence: false, + useSequelize: true, + }); + ``` + + - Use the `SequelizeDataSource` in your datasource as the parent class. Refer [this](https://www.npmjs.com/package/@loopback/sequelize#step-1-configure-datasource) for more. -- Set up a [Loopback4 Datasource](https://loopback.io/doc/en/lb4/DataSource.html) with `dataSourceName` property set to `PaymentDatasourceName`. You can see an example datasource [here](#setting-up-a-datasource). - Start the application `npm start` @@ -102,6 +143,9 @@ export class InmailDataSource The migrations required for this service are processed during the installation automatically if you set the `PAYMENT_MIGRATION` or `SOURCELOOP_MIGRATION` env variable. The migrations use [`db-migrate`](https://www.npmjs.com/package/db-migrate) with [`db-migrate-pg`](https://www.npmjs.com/package/db-migrate-pg) driver for migrations, so you will have to install these packages to use auto-migration. Please note that if you are using some pre-existing migrations or databases, they may be affected. In such a scenario, it is advised that you copy the migration files in your project root, using the `PAYMENT_MIGRATION_COPY` or `SOURCELOOP_MIGRATION_COPY` env variables. You can customize or cherry-pick the migrations in the copied files according to your specific requirements and then apply them to the DB. +Additionally, there is now an option to choose between SQL migration or PostgreSQL migration. +NOTE : For @sourceloop/cli users, this choice can be specified during the scaffolding process by selecting the "type of datasource" option. + ### Database Schema ![Database Schema](https://user-images.githubusercontent.com/98279679/186740482-496cd283-8073-4db5-b9d1-cd066d85d313.png) @@ -139,21 +183,9 @@ JWT_ISSUER=https://authentication.service | `DB_SCHEMA` | Y | `public` | Database schema used for the data source. In PostgreSQL, this will be `public` unless a schema is made explicitly for the service. | | `JWT_SECRET` | Y | | Symmetric signing key of the JWT token. | | `JWT_ISSUER` | Y | | Issuer of the JWT token. | +### Providers -### Using with Sequelize - -This service supports Sequelize as the underlying ORM using [@loopback/sequelize](https://www.npmjs.com/package/@loopback/sequelize) extension. And in order to use it, you'll need to do following changes. - -1.To use Sequelize in your application, add following to application.ts: - -```ts -this.bind(PaymentServiceBindings.Config).to({ - useCustomSequence: false, - useSequelize: true, -}); -``` - -2. Use the `SequelizeDataSource` in your datasource as the parent class. Refer [this](https://www.npmjs.com/package/@loopback/sequelize#step-1-configure-datasource) for more. +You can find documentation for some of the providers available in this service [here](./src/providers/README.md) ### API Documentation diff --git a/services/scheduler-service/README.md b/services/scheduler-service/README.md index d38daba6f0..aa437d3ed6 100644 --- a/services/scheduler-service/README.md +++ b/services/scheduler-service/README.md @@ -8,6 +8,7 @@ ![npm (prod) dependency version (scoped)](https://img.shields.io/npm/dependency-version/@sourceloop/scheduler-service/@loopback/core) +## Overview This is a loopback4 component for scheduling events in calendar (scheduler/calendar server). Various features of Scheduler Service: @@ -43,6 +44,13 @@ To get started with a basic implementation of this service, see [/sandbox/schedu npm install @sourceloop/scheduler-service ``` +### Workflow Diagrams + +![Schedular](https://user-images.githubusercontent.com/82804130/127480876-7dad27cf-11c6-4dbc-9988-f7af6f91c5b8.jpg) + +![event](https://user-images.githubusercontent.com/82804130/127480906-3c70d4e0-03b8-426f-bb63-ec726eb39353.jpg) + + ### Usage - Create a new Loopback4 Application (If you don't have one already) @@ -75,14 +83,80 @@ npm install @sourceloop/scheduler-service `SchedulerDatasourceName`. You can see an example datasource [here](#setting-up-a-datasource). - Set up a [Loopback4 Datasource](https://loopback.io/doc/en/lb4/DataSource.html) with `dataSourceName` property set to `AuthCacheDatasourceName`. You can see an example datasource [here](#setting-up-a-datasource). -- Start the application - `npm start` +- **Audit Logs** + + To generate audit logs for video conferencing service, you'll have to set the env var `ADD_AUDIT_LOG_MIXIN` to `true` and configure a datasource for it like below: + + ```ts + import {inject, lifeCycleObserver, LifeCycleObserver} from '@loopback/core'; + import {juggler} from '@loopback/repository'; + import {AuditDbSourceName} from '@sourceloop/audit-log'; + + const config = { + name: 'audit', + connector: 'postgresql', + url: '', + host: '', + port: 0, + user: '', + password: '', + database: '', + }; + + @lifeCycleObserver('datasource') + export class AuditDataSource + extends juggler.DataSource + implements LifeCycleObserver + { + static dataSourceName = AuditDbSourceName; + static readonly defaultConfig = config; + + constructor( + @inject('datasources.config.audit', {optional: true}) + dsConfig: object = config, + ) { + const auditEnvConfig = { + host: process.env.AUDIT_DB_HOST, + port: process.env.AUDIT_DB_PORT, + user: process.env.AUDIT_DB_USER, + password: process.env.AUDIT_DB_PASSWORD, + database: process.env.AUDIT_DB_DATABASE, + schema: process.env.AUDIT_DB_SCHEMA, + }; + Object.assign(dsConfig, auditEnvConfig); + super(dsConfig); + } + } + ``` -### Workflow Diagrams + Configure .env of application in index.ts before exporting application like follows -![Schedular](https://user-images.githubusercontent.com/82804130/127480876-7dad27cf-11c6-4dbc-9988-f7af6f91c5b8.jpg) + ```ts + import * as dotenv from 'dotenv'; + dotenv.config(); -![event](https://user-images.githubusercontent.com/82804130/127480906-3c70d4e0-03b8-426f-bb63-ec726eb39353.jpg) + import {ApplicationConfig, SchedulerExampleApplication} from './application'; + export * from './application'; + //... + ``` + +- **Using with Sequelize** + + This service supports Sequelize as the underlying ORM using [@loopback/sequelize](https://www.npmjs.com/package/@loopback/sequelize) extension. And in order to use it, you'll need to do following changes. + + - To use Sequelize in your application, add following to application.ts: + + ```ts + this.bind(CoreSchedulerBindings.Config).to({ + useCustomSequence: false, + useSequelize: true, + }); + ``` + + - Use the `SequelizeDataSource` in your datasource as the parent class. Refer [this](https://www.npmjs.com/package/@loopback/sequelize#step-1-configure-datasource) for more. + +- Start the application + `npm start` ### Environment Variables @@ -203,82 +277,13 @@ export class AuthCacheDataSource The migrations required for this service are processed during the installation automatically if you set the `SCHEDULER_MIGRATION` or `SOURCELOOP_MIGRATION` env variable. The migrations use [`db-migrate`](https://www.npmjs.com/package/db-migrate) with [`db-migrate-pg`](https://www.npmjs.com/package/db-migrate-pg) driver for migrations, so you will have to install these packages to use auto-migration. Please note that if you are using some pre-existing migrations or databases, they may be affected. In such a scenario, it is advised that you copy the migration files in your project root, using the `SCHEDULER_MIGRATION_COPY` or `SOURCELOOP_MIGRATION_COPY` env variables. You can customize or cherry-pick the migrations in the copied files according to your specific requirements and then apply them to the DB. +Additionally, there is now an option to choose between SQL migration or PostgreSQL migration. +NOTE : For @sourceloop/cli users, this choice can be specified during the scaffolding process by selecting the "type of datasource" option. + ## Database Schema ![db-schema](https://github.com/sourcefuse/loopback4-microservice-catalog/blob/master/services/scheduler-service/migrations/scheduler_db_schema.png?raw=true) -## Audit Logs - -To generate audit logs for video conferencing service, you'll have to set the env var `ADD_AUDIT_LOG_MIXIN` to `true` and configure a datasource for it like below: - -```ts -import {inject, lifeCycleObserver, LifeCycleObserver} from '@loopback/core'; -import {juggler} from '@loopback/repository'; -import {AuditDbSourceName} from '@sourceloop/audit-log'; - -const config = { - name: 'audit', - connector: 'postgresql', - url: '', - host: '', - port: 0, - user: '', - password: '', - database: '', -}; - -@lifeCycleObserver('datasource') -export class AuditDataSource - extends juggler.DataSource - implements LifeCycleObserver -{ - static dataSourceName = AuditDbSourceName; - static readonly defaultConfig = config; - - constructor( - @inject('datasources.config.audit', {optional: true}) - dsConfig: object = config, - ) { - const auditEnvConfig = { - host: process.env.AUDIT_DB_HOST, - port: process.env.AUDIT_DB_PORT, - user: process.env.AUDIT_DB_USER, - password: process.env.AUDIT_DB_PASSWORD, - database: process.env.AUDIT_DB_DATABASE, - schema: process.env.AUDIT_DB_SCHEMA, - }; - Object.assign(dsConfig, auditEnvConfig); - super(dsConfig); - } -} -``` - -Configure .env of application in index.ts before exporting application like follows - -```ts -import * as dotenv from 'dotenv'; -dotenv.config(); - -import {ApplicationConfig, SchedulerExampleApplication} from './application'; -export * from './application'; -//... -``` - -### Using with Sequelize - -This service supports Sequelize as the underlying ORM using [@loopback/sequelize](https://www.npmjs.com/package/@loopback/sequelize) extension. And in order to use it, you'll need to do following changes. - -1.To use Sequelize in your application, add following to application.ts: - -```ts -this.bind(CoreSchedulerBindings.Config).to({ - useCustomSequence: false, - useSequelize: true, -}); -``` - -2. Use the `SequelizeDataSource` in your datasource as the parent class. Refer [this](https://www.npmjs.com/package/@loopback/sequelize#step-1-configure-datasource) for more. - ## API's Details Visit the [OpenAPI spec docs](./openapi.md) diff --git a/services/search-service/README.md b/services/search-service/README.md index bb173c5324..175044ce6d 100644 --- a/services/search-service/README.md +++ b/services/search-service/README.md @@ -8,6 +8,8 @@ ![npm (prod) dependency version (scoped)](https://img.shields.io/npm/dependency-version/@sourceloop/search-service/@loopback/core) +## Overview + A LoopBack microservice used for searching over configured models. It uses in-build Full Text Search support in PostgreSQL and MySQL databases to perform searches. ## Installation @@ -63,17 +65,17 @@ npm i @sourceloop/search-service - Start the application `npm start` -### Configurations +## Configurations -#### useCustomSequence +**useCustomSequence** The service comes with a default sequence with inbuilt authentication and authorization using the [loopback4-authentication](https://github.com/sourcefuse/loopback4-authentication) and [loopback4-authorization](https://github.com/sourcefuse/loopback4-authorization). If you want to use your custom sequence instead, set this option as true. -#### type +**type** Type of the result set, by default it is a model with two properties - `name` and `description`; -#### models +**models** It sets the models and columns over which the search is performed. It's value is a list with two types of values - @@ -82,7 +84,7 @@ It sets the models and columns over which the search is performed. It's value is - model - A class that extends the Loopback Model - columns - A key-value map that maps the keys of the database model to the keys in the result set. -#### controller +**controller** Configuration for the controller, it accepts three properties - @@ -145,7 +147,14 @@ CREATE INDEX tbl_fts_idx ON main. USING GIN ( to_tsvector('english', f_concat_ws(' ', , ))); ``` -### API Documentation +## Migrations + +The migrations required for this service are processed during the installation automatically if you set the `CHAT_MIGRATION` or `SOURCELOOP_MIGRATION` env variable. The migrations use [`db-migrate`](https://www.npmjs.com/package/db-migrate) with [`db-migrate-pg`](https://www.npmjs.com/package/db-migrate-pg) driver for migrations, so you will have to install these packages to use auto-migration. Please note that if you are using some pre-existing migrations or databasea, they may be affected. In such a scenario, it is advised that you copy the migration files in your project root, using the `CHAT_MIGRATION_COPY` or `SOURCELOOP_MIGRATION_COPY` env variables. You can customize or cherry-pick the migrations in the copied files according to your specific requirements and then apply them to the DB. + +Additionally, there is now an option to choose between SQL migration or PostgreSQL migration. +NOTE: For [`@sourceloop/cli`](https://www.npmjs.com/package/@sourceloop/cli?activeTab=readme) users, this choice can be specified during the scaffolding process by selecting the "type of datasource" option. + +## API Documentation #### Common Headers diff --git a/services/survey-service/README.md b/services/survey-service/README.md index acfcf18ea2..fbef64ff4e 100644 --- a/services/survey-service/README.md +++ b/services/survey-service/README.md @@ -53,6 +53,22 @@ $ [npm install | yarn add] @sourceloop/survey-service this.component(SurveyServiceComponent); ``` - Set up a [Loopback4 Datasource](https://loopback.io/doc/en/lb4/DataSource.html) with `dataSourceName` property set to `SurveyDbSourceName`. You can see an example datasource [here](#setting-up-a-datasource). + +- **Using with Sequelize** + + This service supports Sequelize as the underlying ORM using [@loopback/sequelize](https://www.npmjs.com/package/@loopback/sequelize) extension. And in order to use it, you'll need to do following changes. + + - To use Sequelize in your application, add following to application.ts: + + ```ts + this.bind(SurveyServiceBindings.Config).to({ + useCustomSequence: false, + useSequelize: true, + }); + ``` + + - Use the `SequelizeDataSource` in your audit datasource as the parent class. Refer [this](https://www.npmjs.com/package/@loopback/sequelize#step-1-configure-datasource) for more. + - Start the application `npm start` @@ -137,20 +153,10 @@ export class MysqlDataSource The migrations required for this service are processed during the installation automatically if you set the `SURVEY_MIGRATION` or `SOURCELOOP_MIGRATION` env variable. The migrations use [`db-migrate`] with [`db-migrate-mysql`] driver for migrations, so you will have to install these packages to use auto-migration. Please note that if you are using some pre-existing migrations or databases, they may be affected. In such a scenario, it is advised that you copy the migration files in your project root, using the `SURVEY_MIGRATION_COPY` or `SOURCELOOP_MIGRATION_COPY` env variables. You can customize or cherry-pick the migrations in the copied files according to your specific requirements and then apply them to the DB. -### Using with Sequelize - -This service supports Sequelize as the underlying ORM using [@loopback/sequelize](https://www.npmjs.com/package/@loopback/sequelize) extension. And in order to use it, you'll need to do following changes. -1.To use Sequelize in your application, add following to application.ts: - -```ts -this.bind(SurveyServiceBindings.Config).to({ - useCustomSequence: false, - useSequelize: true, -}); -``` +Additionally, there is now an option to choose between SQL migration or PostgreSQL migration. +NOTE : For @sourceloop/cli users, this choice can be specified during the scaffolding process by selecting the "type of datasource" option. -2. Use the `SequelizeDataSource` in your audit datasource as the parent class. Refer [this](https://www.npmjs.com/package/@loopback/sequelize#step-1-configure-datasource) for more. #### Common Headers diff --git a/services/task-service/README.md b/services/task-service/README.md index 1d17127311..744e362a6a 100644 --- a/services/task-service/README.md +++ b/services/task-service/README.md @@ -79,6 +79,9 @@ export class PgDbDataSource - To run the migrations provided by the task service (available in the migrations folder of both the source code and the packed version in your `node_modules`), use the [db-migrate](https://db-migrate.readthedocs.io/en/latest/) package. - Run the HTTP migrations only if you plan to use the Http Outgoing connector. +- Additionally, there is now an option to choose between SQL migration or PostgreSQL migration. +NOTE : For @sourceloop/cli users, this choice can be specified during the scaffolding process by selecting the "type of datasource" option. + ## Commands diff --git a/services/user-tenant-service/README.md b/services/user-tenant-service/README.md index 95729fd2b4..69b59da60c 100644 --- a/services/user-tenant-service/README.md +++ b/services/user-tenant-service/README.md @@ -1,7 +1,24 @@ -# user-tenant-service +# @sourceloop/user-tenant-service [![LoopBack]()](http://loopback.io/) +![npm](https://img.shields.io/npm/dm/@sourceloop/user-tenant-service) + +![node-current (scoped)](https://img.shields.io/node/v/@sourceloop/user-tenant-service) + +![npm (prod) dependency version (scoped)](https://img.shields.io/npm/dependency-version/@sourceloop/user-tenant-service/@loopback/core) + + +## Overview +This microservice efficiently supports tenant-specific operations, empowering you to leverage the benefits of multitenancy. + +- Multi-tenant support +- Tenant management with dedicated functionality +- Seamless team management within each tenant +- User management at both the team and tenant levels +- Role management specific to each tenant +- Efficient user permission management across the entire system. + ## Installation Install UserTenantServiceComponent using `npm`; @@ -10,38 +27,229 @@ Install UserTenantServiceComponent using `npm`; $ [npm install | yarn add] user-tenant-service ``` -## Basic Use +## Usage + +- Create a new Loopback4 Application (If you don't have one already) + `lb4 testapp` +- Install the authentication service + `npm i @sourceloop/user-tenant-service` +- Set the [environment variables](#environment-variables). +- Run the [migrations](#migrations). +- Add the `UserTenantServiceComponent` to your Loopback4 Application (in `application.ts`). + ```typescript + // import the UserTenantServiceComponent + import {UserTenantServiceComponent} from '@sourceloop/user-tenant-service'; + // add Component for UserTenantService + this.component(UserTenantServiceComponent); + ``` +- Set up a [Loopback4 Datasource](https://loopback.io/doc/en/lb4/DataSource.html) with `dataSourceName` property set to + `AuthDb`. You can see an example datasource [here](#setting-up-a-datasource). +- Bind any of the custom [providers](#providers) you need. +- **Using with Sequelize** + + This service supports Sequelize as the underlying ORM using [@loopback/sequelize](https://www.npmjs.com/package/@loopback/sequelize) extension. And in order to use it, you'll need to do following changes. -Configure and load UserTenantServiceComponent in the application constructor -as shown below. + - To use Sequelize in your application, add following to application.ts: -```ts -import {UserTenantServiceComponent, UserTenantServiceComponentOptions, DEFAULT_USER_SERVICE_OPTIONS} from 'user-tenant-service'; -// ... -export class MyApplication extends BootMixin(ServiceMixin(RepositoryMixin(RestApplication))) { - constructor(options: ApplicationConfig = {}) { - const opts: UserTenantServiceComponentOptions = DEFAULT_USER_SERVICE_OPTIONS; - this.configure(UserTenantServiceComponentBindings.COMPONENT).to(opts); - // Put the configuration options here + ```ts + this.bind(UserTenantServiceComponentBindings.Config).to({ + useCustomSequence: false, + useSequelize: true, }); - this.component(UserTenantServiceComponent); - // ... + ``` + + - Use the `SequelizeDataSource` in your datasource as the parent class. Refer [this](https://www.npmjs.com/package/@loopback/sequelize#step-1-configure-datasource) for more. + +- Start the application + `npm start` + +### Environment Variables + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameRequiredDescriptionDefault Value
NODE_ENVYNode environment value, i.e. `dev`, `test`, `prod
LOG_LEVELYLog level value, i.e. `error`, `warn`, `info`, `verbose`, `debug`
DB_HOSTYHostname for the database server.
DB_PORTYPort for the database server.
DB_USERYUser for the database.
DB_PASSWORDYPassword for the database user.
DB_DATABASEYDatabase to connect to on the database server.
DB_SCHEMAYDatabase schema used for the data source. In PostgreSQL, this will be `public` unless a schema is made explicitly for the service.
REDIS_HOSTYHostname of the Redis server.
REDIS_PORTYPort to connect to the Redis server over.
REDIS_URLYFully composed URL for Redis connection. Used instead of other settings if set.
REDIS_PASSWORDYPassword for Redis if authentication is enabled.
REDIS_DATABASEYDatabase within Redis to connect to.
JWT_PRIVATE_KEYYAsymmetric signing key of the JWT token.
JWT_PUBLIC_KEYYVerifying signed JWT Token.
JWT_SECRETYSymmetric signing key of the JWT token.
JWT_ISSUERYIssuer of the JWT token.
+ +### Setting up a `DataSource` + +Here is a sample Implementation `DataSource` implementation using environment variables and PostgreSQL as the data source. + +```typescript +import {inject, lifeCycleObserver, LifeCycleObserver} from '@loopback/core'; +import {juggler} from '@loopback/repository'; + +const config = { + name: AuthDbSourceName, + connector: 'postgresql', + url: '', + host: process.env.DB_HOST, + port: process.env.DB_PORT, + user: process.env.DB_USER, + password: process.env.DB_PASSWORD, + database: process.env.DB_DATABASE, + schema: process.env.DB_SCHEMA, +}; + +@lifeCycleObserver('datasource') +export class AuthenticationDbDataSource + extends juggler.DataSource + implements LifeCycleObserver +{ + static dataSourceName = "AuthDb"; + static readonly defaultConfig = config; + + constructor( + // You need to set datasource configuration name as 'datasources.config.Authentication' otherwise you might get Errors + @inject('datasources.config.authentication', {optional: true}) + dsConfig: object = config, + ) { + super(dsConfig); } - // ... } ``` -### Using with Sequelize +### Migrations -This service supports Sequelize as the underlying ORM using [@loopback/sequelize](https://www.npmjs.com/package/@loopback/sequelize) extension. And in order to use it, you'll need to do following changes. +The migrations required for this service are processed during the installation automatically if you set the `AUTH_MIGRATION` or `SOURCELOOP_MIGRATION` env variable. The migrations use [`db-migrate`](https://www.npmjs.com/package/db-migrate) with [`db-migrate-pg`](https://www.npmjs.com/package/db-migrate-pg) driver for migrations, so you will have to install these packages to use auto-migration. Please note that if you are using some pre-existing migrations or databases, they may be affected. In such a scenario, it is advised that you copy the migration files in your project root, using the `AUTH_MIGRATION_COPY` or `SOURCELOOP_MIGRATION_COPY` env variables. You can customize or cherry-pick the migrations in the copied files according to your specific requirements and then apply them to the DB. -1.To use Sequelize in your application, add following to application.ts: +Additionally, there is now an option to choose between SQL migration or PostgreSQL migration. +NOTE : For [`@sourceloop/cli`](https://www.npmjs.com/package/@sourceloop/cli?activeTab=readme) users, this choice can be specified during the scaffolding process by selecting the "type of datasource" option. -```ts -this.bind(UserTenantServiceComponentBindings.Config).to({ - useCustomSequence: false, - useSequelize: true, -}); -``` +### Database Schema + +![Auth DB Schema](https://user-images.githubusercontent.com/77672713/126612271-3ce065aa-9f87-45d4-bf9a-c5cc8ad21764.jpg) + +### Providers + +You can find documentation for some of the providers available in this service [here](./src/providers/README.md) + +#### Common Headers + +Authorization: Bearer where is a JWT token signed using JWT issuer and secret. +`Content-Type: application/json` in the response and in request if the API method is NOT GET + +#### Common Request path Parameters + +`{version}`: Defines the API Version + +### Common Responses + +200: Successful Response. Response body varies w.r.t API +401: Unauthorized: The JWT token is missing or invalid +403: Forbidden : Not allowed to execute the concerned API +404: Entity Not Found +400: Bad Request (Error message varies w.r.t API) +201: No content: Empty Response + +#### API Details -2. Use the `SequelizeDataSource` in your datasource as the parent class. Refer [this](https://www.npmjs.com/package/@loopback/sequelize#step-1-configure-datasource) for more. +Visit the [OpenAPI spec docs](./openapi.md) diff --git a/services/video-conferencing-service/README.md b/services/video-conferencing-service/README.md index 606380aaab..c8f1fc0edb 100644 --- a/services/video-conferencing-service/README.md +++ b/services/video-conferencing-service/README.md @@ -8,6 +8,8 @@ ![npm (prod) dependency version (scoped)](https://img.shields.io/npm/dependency-version/@sourceloop/video-conferencing-service/@loopback/core) +## Overview + Various features of Video Conferencing Services: 1. Schedule Meetings and Generate a Token @@ -34,6 +36,11 @@ To get started with a basic implementation of this service, see [/sandbox/video- npm i @sourceloop/video-conferencing-service ``` +## Working and Flow + +![video](https://user-images.githubusercontent.com/82804130/126984338-754c0788-270a-40df-b601-ff66dcd3d5f8.jpg) + + ## Usage - Create a new Loopback4 Application (If you don't have one already) @@ -75,27 +82,84 @@ npm i @sourceloop/video-conferencing-service ``` - Set up a [Loopback4 Datasource](https://loopback.io/doc/en/lb4/DataSource.html) with `dataSourceName` property set to `VideoConfDatasource`. You can see an example datasource [here](#setting-up-a-datasource). -- Start the application - `npm start` - -## Working and Flow - -![video](https://user-images.githubusercontent.com/82804130/126984338-754c0788-270a-40df-b601-ff66dcd3d5f8.jpg) +- **Using with Sequelize** + + This service supports Sequelize as the underlying ORM using [@loopback/sequelize](https://www.npmjs.com/package/@loopback/sequelize) extension. And in order to use it, you'll need to do following changes. + + - To use Sequelize in your application, add following to application.ts: + + ```ts + this.bind(VideoChatBindings.Config).to({ + useCustomSequence: false, + useSequelize: true, + }); + ``` + + - Use the `SequelizeDataSource` in your audit datasource as the parent class. Refer [this](https://www.npmjs.com/package/@loopback/sequelize#step-1-configure-datasource) for more details. + +- **Configurable Audit Logs** + + To generate audit logs for video conferencing service, you'll have to set the env var `ADD_AUDIT_LOG_MIXIN` to `true` and configure a datasource for it like below: + + ```ts + import {inject, lifeCycleObserver, LifeCycleObserver} from '@loopback/core'; + import {juggler} from '@loopback/repository'; + import {AuditDbSourceName} from '@sourceloop/audit-log'; + + const config = { + name: 'audit', + connector: 'postgresql', + url: '', + host: '', + port: 0, + user: '', + password: '', + database: '', + }; + + @lifeCycleObserver('datasource') + export class AuditDataSource + extends juggler.DataSource + implements LifeCycleObserver + { + static dataSourceName = AuditDbSourceName; + static readonly defaultConfig = config; + + constructor( + @inject('datasources.config.audit', {optional: true}) + dsConfig: object = config, + ) { + const auditEnvConfig = { + host: process.env.AUDIT_DB_HOST, + port: process.env.AUDIT_DB_PORT, + user: process.env.AUDIT_DB_USER, + password: process.env.AUDIT_DB_PASSWORD, + database: process.env.AUDIT_DB_DATABASE, + schema: process.env.AUDIT_DB_SCHEMA, + }; + Object.assign(dsConfig, auditEnvConfig); + super(dsConfig); + } + } + ``` -### Using with Sequelize + Configure .env of application in index.ts before exporting application like follows -This service supports Sequelize as the underlying ORM using [@loopback/sequelize](https://www.npmjs.com/package/@loopback/sequelize) extension. And in order to use it, you'll need to do following changes. + ```ts + import * as dotenv from 'dotenv'; + dotenv.config(); -1.To use Sequelize in your application, add following to application.ts: + import { + ApplicationConfig, + VideoConferencingExampleApplication, + } from './application'; + export * from './application'; + //... + ``` -```ts -this.bind(VideoChatBindings.Config).to({ - useCustomSequence: false, - useSequelize: true, -}); -``` +- Start the application + `npm start` -2. Use the `SequelizeDataSource` in your audit datasource as the parent class. Refer [this](https://www.npmjs.com/package/@loopback/sequelize#step-1-configure-datasource) for more details. ### Environment Variables @@ -289,65 +353,9 @@ export class VideoDbDataSource The migrations required for this service are processed during the installation automatically if you set the `VIDEOCONF_MIGRATION` or `SOURCELOOP_MIGRATION` env variable. The migrations use [`db-migrate`](https://www.npmjs.com/package/db-migrate) with [`db-migrate-pg`](https://www.npmjs.com/package/db-migrate-pg) driver for migrations, so you will have to install these packages to use auto-migration. Please note that if you are using some pre-existing migrations or databases, they may be affected. In such a scenario, it is advised that you copy the migration files in your project root, using the `VIDEOCONF_MIGRATION_COPY` or `SOURCELOOP_MIGRATION_COPY` env variables. You can customize or cherry-pick the migrations in the copied files according to your specific requirements and then apply them to the DB. -## Audit Logs - -To generate audit logs for video conferencing service, you'll have to set the env var `ADD_AUDIT_LOG_MIXIN` to `true` and configure a datasource for it like below: - -```ts -import {inject, lifeCycleObserver, LifeCycleObserver} from '@loopback/core'; -import {juggler} from '@loopback/repository'; -import {AuditDbSourceName} from '@sourceloop/audit-log'; - -const config = { - name: 'audit', - connector: 'postgresql', - url: '', - host: '', - port: 0, - user: '', - password: '', - database: '', -}; - -@lifeCycleObserver('datasource') -export class AuditDataSource - extends juggler.DataSource - implements LifeCycleObserver -{ - static dataSourceName = AuditDbSourceName; - static readonly defaultConfig = config; - - constructor( - @inject('datasources.config.audit', {optional: true}) - dsConfig: object = config, - ) { - const auditEnvConfig = { - host: process.env.AUDIT_DB_HOST, - port: process.env.AUDIT_DB_PORT, - user: process.env.AUDIT_DB_USER, - password: process.env.AUDIT_DB_PASSWORD, - database: process.env.AUDIT_DB_DATABASE, - schema: process.env.AUDIT_DB_SCHEMA, - }; - Object.assign(dsConfig, auditEnvConfig); - super(dsConfig); - } -} -``` - -Configure .env of application in index.ts before exporting application like follows +Additionally, there is now an option to choose between SQL migration or PostgreSQL migration. +NOTE : For @sourceloop/cli users, this choice can be specified during the scaffolding process by selecting the "type of datasource" option. -```ts -import * as dotenv from 'dotenv'; -dotenv.config(); - -import { - ApplicationConfig, - VideoConferencingExampleApplication, -} from './application'; -export * from './application'; -//... -``` ## API's Details