Skip to content
Snippets Groups Projects
Verified Commit 971ad6f6 authored by Konstantin Tsabolov's avatar Konstantin Tsabolov
Browse files

chore: add script for tenant creation

parent 6c8f7a53
No related branches found
No related tags found
No related merge requests found
......@@ -3,6 +3,7 @@
# Except these files
!*.ts
!*.mts
!*.d.ts
# .. also in subdirectories
......
......@@ -14,9 +14,9 @@ module.exports = {
project: ['./tsconfig.eslint.json'],
},
settings: {
'import/extensions': ['.js', '.ts'],
'import/extensions': ['.js', '.mjs', '.ts', '.mts'],
'import/parsers': {
'@typescript-eslint/parser': ['.ts', '.tsx'],
'@typescript-eslint/parser': ['.ts', '.tsx', '.mts'],
},
'import/resolver': {
typescript: {
......@@ -75,7 +75,7 @@ module.exports = {
},
overrides: [
{
files: ['*.spec.ts', '*.e2e-spec.ts', '**/tests/**'],
files: ['*.spec.ts', '*.e2e-spec.ts', '**/tests/**', 'scripts/*.ts', 'scripts/*.mts'],
env: {
jest: true,
node: true,
......
......@@ -44,6 +44,14 @@ OCM (Organizational Credential Manager) is a Node.js-based microservice system d
docker compose up -d
```
6. Create a new tenant:
```bash
pnpm createTenant [tenantName]
```
Desired label for the new tenant could be set with `tenantName`.
## Example Flows (OCM Usage)
Please refer to [OCM-flow-overview](documentation/ocm-flow-overview.md)
......
......@@ -15,11 +15,15 @@
"format": "prettier --write",
"format:all": "pnpm format -- .",
"lint-staged": "lint-staged",
"prepare": "husky install"
"prepare": "husky install",
"createTenant": "vite-node scripts/create_tenant.mts"
},
"devDependencies": {
"@commitlint/cli": "^18.4.2",
"@commitlint/config-conventional": "^18.4.2",
"@nestjs/common": "^10.3.0",
"@nestjs/core": "^10.3.0",
"@nestjs/microservices": "^10.3.0",
"@typescript-eslint/eslint-plugin": "^6.12.0",
"@typescript-eslint/parser": "^6.12.0",
"eslint": "^8.54.0",
......@@ -30,6 +34,9 @@
"eslint-plugin-workspaces": "^0.10.0",
"husky": "^8.0.0",
"lint-staged": "^15.1.0",
"prettier": "^3.1.0"
"prettier": "^3.1.0",
"reflect-metadata": "^0.1.13",
"rxjs": "^7.8.1",
"vite-node": "^1.2.1"
}
}
This diff is collapsed.
import type { EventTenantsCreateInput } from '../apps/shared/dist/index.js';
import { Logger, Module } from '@nestjs/common';
import { NestFactory } from '@nestjs/core';
import {
ClientsModule,
Transport,
type ClientProxy,
} from '@nestjs/microservices';
import { randomBytes } from 'node:crypto';
import { firstValueFrom } from 'rxjs';
import { EventTenantsCreate } from '../apps/shared/src/events/tenantEvents.js';
// These values are from the docker-compose.yml file
const NATS_URL = process.env.NATS_URL || 'nats://localhost:4222';
const NATS_USER = process.env.NATS_USER || 'nats_user';
const NATS_PASSWORD =
process.env.NATS_PASSWORD || 'Rw+dYIymAQm9H6ELLNwSuGo1812jqQ==';
@Module({
imports: [
ClientsModule.register([
{
transport: Transport.NATS,
name: 'TENANTS_CLIENT_SERVICE',
options: {
url: NATS_URL,
user: NATS_USER,
pass: NATS_PASSWORD,
},
},
]),
],
})
class Application {}
void (async () => {
const app = await NestFactory.createApplicationContext(Application);
const client: ClientProxy = app.get('TENANTS_CLIENT_SERVICE');
await client.connect();
const tenantLabel = process.argv[2] || "tenant_" + randomBytes(4).toString('hex');
const response$ = client.send<EventTenantsCreate, EventTenantsCreateInput>(
EventTenantsCreate.token,
{
label: tenantLabel,
},
);
const response = await firstValueFrom(response$);
Logger.log(`Tenant "${tenantLabel}" created with id: ${response.data.id}`);
// Logger.debug(response);
await app.close();
})();
{
"extends": "./tsconfig.json",
"include": ["apps", "./.eslintrc.js"],
"include": ["apps", "./.eslintrc.js", "scripts"],
"exclude": ["node_modules", "**/dist/**"]
}
......@@ -16,5 +16,6 @@
"experimentalDecorators": true,
"noImplicitAny": true
},
"include": ["src", "scripts"],
"exclude": ["node_modules"]
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment