Skip to content

Commit 01b9ab8

Browse files
committed
docs(all-services): add docs to generate via cli
add docs to generate via cli GH-0
1 parent 00a1d31 commit 01b9ab8

2 files changed

Lines changed: 120 additions & 1 deletion

File tree

services/subscription-service/README.md

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,47 @@ This microservice uses [loopback4-authentication](https://www.npmjs.com/package/
123123

124124
- Bind any of the custom [providers](#providers) you need.
125125

126+
### Usage Via Sourceloop CLI
127+
You need to have [@sourceloop/cli](https://www.npmjs.com/package/@sourceloop/cli) installed on your system
128+
```sh
129+
$ [npm install | yarn add] @sourceloop/cli
130+
```
131+
follow the below steps:
132+
- Run ***sl scaffold myapp*** to scaffold a Lerna monorepo, if you already don't have any monorepo.
133+
- select all the required configuration by answering to prompted questions.
134+
- Navigate into your project using cd myapp.
135+
- Run ***sl microservice subscription-service***.
136+
- Through the prompts, you can set up migrations, configure the datasource, bind components in application.ts, and complete other necessary setups.
137+
- This microservice uses loopback4-authentication and @sourceloop/core and that uses asymmetric token encryption and decryption by default for that setup please refer their documentation but if you wish to override
138+
139+
```typescript
140+
141+
this.bind(SubscriptionServiceBindings.Config).to({
142+
useCustomSequence: true,
143+
});
144+
this.component(AuthenticationComponent);
145+
this.sequence(ServiceSequence);
146+
// Add bearer verifier component
147+
this.bind(BearerVerifierBindings.Config).to({
148+
type: BearerVerifierType.service,
149+
useSymmetricEncryption: true,
150+
} as BearerVerifierConfig);
151+
this.component(BearerVerifierComponent);
152+
// Add authorization component
153+
this.bind(AuthorizationBindings.CONFIG).to({
154+
allowAlwaysPaths: ['/explorer', '/openapi.json'],
155+
});
156+
this.component(AuthorizationComponent);
157+
158+
```
159+
160+
comment the following since we are using our custom sequence
161+
162+
```typescript
163+
// Set up the custom sequence
164+
//this.sequence(MySequence);
165+
```
166+
126167
## Integrating Billing Functionality into Subscription Service using LoopBack 4
127168

128169
We are leveraging the [loopback4-billing](https://github.com/sourcefuse/loopback4-billing) package to integrate billing capabilities into our Subscription Service.
@@ -455,6 +496,19 @@ export class FeatureToggleDbDataSource
455496

456497
The migrations required for this service can be copied from the service. You can customize or cherry-pick the migrations in the copied files according to your specific requirements and then apply them to the DB.
457498

499+
- copy the selected migration according to your need. we have provided the postgresql migration files.
500+
- copy them in your application with directory migration/sql at root.
501+
- add the below scripts to your applciation package.json
502+
503+
```
504+
"migrate:up": "db-migrate up --config database.json -m ./migrations",
505+
"migrate:down": "db-migrate down --config database.json -m ./migrations",
506+
"migrate:create": "db-migrate create --sql-file"
507+
```
508+
- do npm i db-migrate db-migrate-pg,
509+
510+
if you are generating the application using [@sourceloop/cli](https://www.npmjs.com/package/@sourceloop/cli), then you can skip these configuration and and generate all the migration related configuration by providing the answering the prmpted question on running - sl microservice
511+
458512
## Database Schema
459513
460514
![ERD](static/subscription-erd.png)

services/tenant-management-service/README.md

Lines changed: 66 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ $ [npm install | yarn add] @sourceloop/ctrl-plane-tenant-management-service
6363
`npm install @sourceloop/core loopback4-authorization loopback4-authentication`
6464
- Add the following to your `application.ts`
6565

66-
```typecript
66+
```typescript
6767
this.bind(TenantManagementServiceBindings.Config).to({
6868
useCustomSequence: true,
6969
});
@@ -98,7 +98,47 @@ comment the following since we are using our custom sequence
9898

9999
- Set up a [Loopback4 Datasource](https://loopback.io/doc/en/lb4/DataSource.html) with `dataSourceName` property set to
100100
`TenantManagementDB`. You can see an example datasource [here](#setting-up-a-datasource).
101+
-
102+
103+
### Usage Via Sourceloop CLI
104+
You need to have [@sourceloop/cli](https://www.npmjs.com/package/@sourceloop/cli) installed on your system
105+
```sh
106+
$ [npm install | yarn add] @sourceloop/cli
107+
```
108+
follow the below steps:
109+
- Run ***sl scaffold myapp*** to scaffold a Lerna monorepo.
110+
- select all the required configuration by answering to prompted questions.
111+
- Navigate into your project using cd myapp.
112+
- Run ***sl microservice tenant-mgmt-service***.
113+
- Through the prompts, you can set up migrations, configure the datasource, bind components in application.ts, and complete other necessary setups.
114+
- This microservice uses loopback4-authentication and @sourceloop/core and that uses asymmetric token encryption and decryption by default for that setup please refer their documentation but if you wish to override
115+
116+
```typescript
117+
this.bind(TenantManagementServiceBindings.Config).to({
118+
useCustomSequence: true,
119+
});
120+
121+
this.component(TenantManagementServiceComponent);
122+
123+
this.component(AuthenticationComponent);
124+
this.sequence(ServiceSequence);
125+
126+
// Add bearer verifier component
127+
this.bind(BearerVerifierBindings.Config).to({
128+
type: BearerVerifierType.service,
129+
useSymmetricEncryption: true,
130+
} as BearerVerifierConfig);
131+
132+
this.component(BearerVerifierComponent);
133+
134+
// Add authorization component
135+
this.bind(AuthorizationBindings.CONFIG).to({
136+
allowAlwaysPaths: ['/explorer', '/openapi.json'],
137+
});
138+
this.component(AuthorizationComponent);
101139

140+
```
141+
- Bind the Event publisher as mentioned below.
102142
## Onboarding a tenant
103143

104144
- The onboarding process starts through a concept of a `Lead`. A `Lead` is a prospective client who may or may not end being a tenant in our system.
@@ -162,6 +202,17 @@ export class TenantEventPublisher {
162202
}
163203
```
164204

205+
### Configure EventBridge for publishing events
206+
bind the below binding to the application.ts
207+
208+
```typescript
209+
this.bind(EventBridgeStreamBindings.Config).to({
210+
source: 'tenant-management',
211+
});
212+
this.component(EventBridgeConnector);
213+
```
214+
215+
165216
## IDP - Identity Provider
166217

167218
The IDP (Identity Provider) Controller provides an endpoint to manage identity provider configurations for tenants. It supports multiple identity providers, such as Keycloak and Auth0, and ensures secure handling of identity provider setup requests through rate-limiting, authorization, and input validation.
@@ -673,6 +724,20 @@ export class RedisDataSource
673724

674725
The migrations required for this service can be copied from the service. You can customize or cherry-pick the migrations in the copied files according to your specific requirements and then apply them to the DB.
675726

727+
- copy the selected migration according to your need. we have provided the postgresql migration files.
728+
- copy them in your application with directory migration/sql at root.
729+
- add the below scripts to your applciation package.json
730+
731+
```
732+
"migrate:up": "db-migrate up --config database.json -m ./migrations",
733+
"migrate:down": "db-migrate down --config database.json -m ./migrations",
734+
"migrate:create": "db-migrate create --sql-file"
735+
```
736+
- do npm i db-migrate db-migrate-pg,
737+
738+
if you are generating the application using [@sourceloop/cli](https://www.npmjs.com/package/@sourceloop/cli), then you can skip these configuration and and generate all the migration related configuration by providing the answering the prmpted question on running - sl microservice
739+
740+
676741
## Database Schema
677742
678743
![alt text](./docs/db_schema.png)

0 commit comments

Comments
 (0)