@edifice.io/edifice-nestjs-core 1.0.0-develop-pedago.7 → 1.0.0-develop-pedago.20251210153355
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +165 -38
- package/dist/bin/update-rn-version.d.ts +2 -0
- package/dist/bin/update-rn-version.js +56 -0
- package/dist/bin/update-rn-version.js.map +1 -0
- package/dist/bin/update-version.d.ts +2 -0
- package/dist/bin/update-version.js +50 -0
- package/dist/bin/update-version.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +22 -6
package/README.md
CHANGED
|
@@ -34,20 +34,24 @@ It registers your application with the Edifice App Registry at startup.
|
|
|
34
34
|
This process scans all controllers for `@RequirePermission` decorators, collects all declared workflow permissions, and sends them to the registry along with application metadata.
|
|
35
35
|
|
|
36
36
|
**How it works:**
|
|
37
|
+
|
|
37
38
|
- On application bootstrap, `AppRegistryService.registerApp()` is called.
|
|
38
39
|
- It extracts all permissions from your controllers using reflection.
|
|
39
40
|
- It sends an `AppRegistrationRequestDTO` to the registry via NATS.
|
|
40
41
|
- The registration is retried every 10 seconds until successful.
|
|
41
42
|
|
|
42
43
|
**Where and when:**
|
|
44
|
+
|
|
43
45
|
- Registration happens automatically during the bootstrap phase (see `createApp()` in `bootstrap.utils.ts`).
|
|
44
46
|
- You do not need to call it manually; it is triggered by the core module (`CoreModule`).
|
|
45
47
|
|
|
46
48
|
**Why:**
|
|
49
|
+
|
|
47
50
|
- This ensures your app and its permissions are discoverable and manageable by the Edifice platform.
|
|
48
51
|
- It enables centralized permission management and workflow integration.
|
|
49
52
|
|
|
50
53
|
**Example:**
|
|
54
|
+
|
|
51
55
|
```typescript
|
|
52
56
|
import { CoreModule } from '@edifice.io/edifice-nestjs-core';
|
|
53
57
|
|
|
@@ -72,24 +76,29 @@ The `ConfigModule` is automatically included when you import `CoreModule` in you
|
|
|
72
76
|
It provides centralized configuration management for your Edifice backend, using NestJS's `ConfigModule` and supporting environment variables.
|
|
73
77
|
|
|
74
78
|
**Features:**
|
|
79
|
+
|
|
75
80
|
- Loads configuration from environment variables.
|
|
76
81
|
- Exposes configuration via NestJS `ConfigService` for dependency injection.
|
|
77
82
|
- Provides helpers for logging, database, Swagger, and other modules to read their settings.
|
|
78
83
|
|
|
79
84
|
**How it works:**
|
|
85
|
+
|
|
80
86
|
- On application startup, the configuration is loaded from environment variables and injected globally.
|
|
81
87
|
- All modules (database, logger, NATS, etc.) read their settings from `ConfigService`.
|
|
82
88
|
- You can override configuration by setting environment variables.
|
|
83
89
|
|
|
84
90
|
**Where and when:**
|
|
91
|
+
|
|
85
92
|
- The configuration system is initialized automatically at application startup by `CoreModule`.
|
|
86
93
|
- No manual setup is needed; just set the required environment variables.
|
|
87
94
|
|
|
88
95
|
**Configuration:**
|
|
96
|
+
|
|
89
97
|
- Set your main configuration using environment variables.
|
|
90
98
|
- See [`src/config/EnvVars.md`](src/config/EnvVars.md) for a full list of supported variables and their defaults.
|
|
91
99
|
|
|
92
100
|
**Example environment variables:**
|
|
101
|
+
|
|
93
102
|
```env
|
|
94
103
|
APP_NAME=my-edifice-app
|
|
95
104
|
APP_DISPLAY_NAME=My Edifice App
|
|
@@ -120,6 +129,7 @@ RSS_MEMORY=300
|
|
|
120
129
|
```
|
|
121
130
|
|
|
122
131
|
**Example:**
|
|
132
|
+
|
|
123
133
|
```typescript
|
|
124
134
|
import { Module } from '@nestjs/common';
|
|
125
135
|
import { CoreModule } from '@edifice.io/edifice-nestjs-core';
|
|
@@ -140,16 +150,43 @@ export class AppModule {
|
|
|
140
150
|
You do not need to configure the configuration system manually; it is ready to use when you import `CoreModule`.
|
|
141
151
|
All modules and services can access configuration via dependency injection of `ConfigService`.
|
|
142
152
|
|
|
153
|
+
**Additional configuration:**
|
|
154
|
+
|
|
155
|
+
You can also provide additional configuration like so
|
|
156
|
+
|
|
157
|
+
```typescript
|
|
158
|
+
import { Module } from '@nestjs/common';
|
|
159
|
+
import { configuration as CoreConfig } from '@edifice.io/edifice-nestjs-core';
|
|
160
|
+
import AppConfig from './config/configuration'; // Your app's configuration object
|
|
161
|
+
import { CoreModule } from '@edifice.io/edifice-nestjs-core';
|
|
162
|
+
import { ConfigModule } from '@nestjs/config';
|
|
163
|
+
|
|
164
|
+
@Module({
|
|
165
|
+
imports: [
|
|
166
|
+
CoreModule,
|
|
167
|
+
// Use config defined in core + app config
|
|
168
|
+
// (warn: does not override core config fields)
|
|
169
|
+
ConfigModule.forRoot({
|
|
170
|
+
isGlobal: true,
|
|
171
|
+
load: [CoreConfig, AppConfig],
|
|
172
|
+
}),
|
|
173
|
+
],
|
|
174
|
+
})
|
|
175
|
+
export class AppModule {}
|
|
176
|
+
```
|
|
177
|
+
|
|
143
178
|
#### Database (MikroORM Integration)
|
|
144
179
|
|
|
145
180
|
The `DatabaseModule` provides seamless integration with MikroORM and PostgreSQL for your Edifice backend application.
|
|
146
181
|
|
|
147
182
|
**Features:**
|
|
183
|
+
|
|
148
184
|
- Automatic database connection and configuration using NestJS `ConfigModule`.
|
|
149
185
|
- Runs pending migrations automatically at startup (if enabled in configuration).
|
|
150
186
|
- Provides helpers to execute SQL scripts and manage schema evolution.
|
|
151
187
|
|
|
152
188
|
**How to use:**
|
|
189
|
+
|
|
153
190
|
- Import `DatabaseModule` in your main application module (already included in `CoreModule`).
|
|
154
191
|
- Configure your database connection via environment variables (`DATABASE_URL`, `DATABASE_USER`, etc.).
|
|
155
192
|
- Place your migration scripts in the `sql/` directory, following the naming convention:
|
|
@@ -158,9 +195,11 @@ The `DatabaseModule` provides seamless integration with MikroORM and PostgreSQL
|
|
|
158
195
|
- Implement migration classes in `./src/migrations/`, each using the helper to execute the corresponding SQL files.
|
|
159
196
|
|
|
160
197
|
**Example:**
|
|
198
|
+
|
|
161
199
|
- Implement migration classes in `./src/migrations/`, each using the helper to execute the corresponding SQL files.
|
|
162
200
|
|
|
163
|
-
|
|
201
|
+
_SQL migration script (`sql/01-init.sql`):_
|
|
202
|
+
|
|
164
203
|
```sql
|
|
165
204
|
-- Create a demo table
|
|
166
205
|
CREATE TABLE demo_table (
|
|
@@ -169,13 +208,15 @@ CREATE TABLE demo_table (
|
|
|
169
208
|
);
|
|
170
209
|
```
|
|
171
210
|
|
|
172
|
-
|
|
211
|
+
_SQL rollback script (`sql/01-rollback.sql`):_
|
|
212
|
+
|
|
173
213
|
```sql
|
|
174
214
|
-- Drop the demo table
|
|
175
215
|
DROP TABLE IF EXISTS demo_table;
|
|
176
216
|
```
|
|
177
217
|
|
|
178
|
-
|
|
218
|
+
_Migration class (`src/migrations/Migration01.ts`):_
|
|
219
|
+
|
|
179
220
|
```typescript
|
|
180
221
|
import { Migration } from '@mikro-orm/migrations';
|
|
181
222
|
import { executeScript } from '@edifice.io/edifice-nestjs-core';
|
|
@@ -191,7 +232,8 @@ export class Migration01 extends Migration {
|
|
|
191
232
|
}
|
|
192
233
|
```
|
|
193
234
|
|
|
194
|
-
|
|
235
|
+
_Entity definition (`src/entities/demo.entity.ts`):_
|
|
236
|
+
|
|
195
237
|
```typescript
|
|
196
238
|
import { Entity, PrimaryKey, Property } from '@mikro-orm/core';
|
|
197
239
|
|
|
@@ -205,7 +247,8 @@ export class Demo {
|
|
|
205
247
|
}
|
|
206
248
|
```
|
|
207
249
|
|
|
208
|
-
|
|
250
|
+
_Service using EntityRepository (`src/demo/demo.service.ts`):_
|
|
251
|
+
|
|
209
252
|
```typescript
|
|
210
253
|
import { Injectable } from '@nestjs/common';
|
|
211
254
|
import { InjectRepository } from '@mikro-orm/nestjs';
|
|
@@ -231,7 +274,8 @@ export class DemoService {
|
|
|
231
274
|
}
|
|
232
275
|
```
|
|
233
276
|
|
|
234
|
-
|
|
277
|
+
_Demo module (`src/demo/demo.module.ts`):_
|
|
278
|
+
|
|
235
279
|
```typescript
|
|
236
280
|
import { Module } from '@nestjs/common';
|
|
237
281
|
import { CoreModule } from '@edifice.io/edifice-nestjs-core';
|
|
@@ -240,17 +284,15 @@ import { Demo } from '../entities/demo.entity';
|
|
|
240
284
|
import { MikroOrmModule } from '@mikro-orm/nestjs';
|
|
241
285
|
|
|
242
286
|
@Module({
|
|
243
|
-
imports: [
|
|
244
|
-
CoreModule,
|
|
245
|
-
MikroOrmModule.forFeature([Demo]),
|
|
246
|
-
],
|
|
287
|
+
imports: [CoreModule, MikroOrmModule.forFeature([Demo])],
|
|
247
288
|
providers: [DemoService],
|
|
248
289
|
exports: [DemoService],
|
|
249
290
|
})
|
|
250
291
|
export class DemoModule {}
|
|
251
292
|
```
|
|
252
293
|
|
|
253
|
-
**Note:**
|
|
294
|
+
**Note:**
|
|
295
|
+
|
|
254
296
|
- Database connection parameters and migration behavior are controlled via environment variables.
|
|
255
297
|
- The module ensures your database schema is up-to-date and provides utilities for advanced migration workflows.
|
|
256
298
|
|
|
@@ -259,17 +301,20 @@ export class DemoModule {}
|
|
|
259
301
|
The `EventModule` provides services for tracking and recording user events (such as access and creation) in your Edifice backend application.
|
|
260
302
|
|
|
261
303
|
**Features:**
|
|
304
|
+
|
|
262
305
|
- Publishes user events (ACCESS, CREATE) to the Edifice event system via NATS.
|
|
263
306
|
- Automatically extracts user/session information from requests.
|
|
264
307
|
- Skips access events for mobile webview requests.
|
|
265
308
|
- Centralizes event logging for analytics and auditing.
|
|
266
309
|
|
|
267
310
|
**How to use:**
|
|
311
|
+
|
|
268
312
|
- Import `CoreModule` in your main application module (already includes `EventModule`).
|
|
269
313
|
- Inject `EventService` into your controllers or services.
|
|
270
314
|
- Call `createAccessEvent(request, resourceType)` or `createCreateEvent(request, resourceType)` to record events.
|
|
271
315
|
|
|
272
316
|
**Example:**
|
|
317
|
+
|
|
273
318
|
```typescript
|
|
274
319
|
import { Controller, Get, Post, Req, Injectable } from '@nestjs/common';
|
|
275
320
|
import { EventService, CoreModule } from '@edifice.io/edifice-nestjs-core';
|
|
@@ -297,10 +342,12 @@ export class ResourceController {
|
|
|
297
342
|
```
|
|
298
343
|
|
|
299
344
|
**Configuration:**
|
|
345
|
+
|
|
300
346
|
- The module uses `ConfigService` to get the application name (`app.name`).
|
|
301
347
|
- Events are sent via the NATS client (`EntNatsServiceClient`), which is configured automatically by the core module.
|
|
302
348
|
|
|
303
|
-
**Note:**
|
|
349
|
+
**Note:**
|
|
350
|
+
|
|
304
351
|
- You do not need to configure the event system manually; it is ready to use when you import `CoreModule`.
|
|
305
352
|
- Events are useful for analytics, auditing, and workflow triggers.
|
|
306
353
|
|
|
@@ -310,21 +357,25 @@ The `HealthModule` is automatically included when you import `CoreModule` in you
|
|
|
310
357
|
It provides endpoints and services for readiness and liveness checks, integrating with NestJS Terminus.
|
|
311
358
|
|
|
312
359
|
**Features:**
|
|
360
|
+
|
|
313
361
|
- Exposes a `/health` endpoint for readiness and liveness checks.
|
|
314
362
|
- Checks database connectivity (MikroORM), memory usage, and NATS connection.
|
|
315
363
|
- Customizable thresholds for memory usage via configuration.
|
|
316
364
|
- Integrates with monitoring and orchestration systems (Kubernetes, Docker, etc.).
|
|
317
365
|
|
|
318
366
|
**How it works:**
|
|
367
|
+
|
|
319
368
|
- The `HealthController` aggregates checks for database, memory, and NATS.
|
|
320
369
|
- Health indicators are injected and run automatically.
|
|
321
370
|
- The `/health` endpoint is public and can be used for probes.
|
|
322
371
|
|
|
323
372
|
**Where and when:**
|
|
373
|
+
|
|
324
374
|
- The health system is initialized automatically at application startup by `CoreModule`.
|
|
325
375
|
- No manual configuration is needed; all dependencies are wired by the core module.
|
|
326
376
|
|
|
327
377
|
**Configuration:**
|
|
378
|
+
|
|
328
379
|
- Memory thresholds and other health parameters are set using environment variables:
|
|
329
380
|
```env
|
|
330
381
|
HEAP_MEMORY=300
|
|
@@ -333,6 +384,7 @@ It provides endpoints and services for readiness and liveness checks, integratin
|
|
|
333
384
|
- You can adjust these values to fit your deployment requirements.
|
|
334
385
|
|
|
335
386
|
**Example:**
|
|
387
|
+
|
|
336
388
|
```typescript
|
|
337
389
|
import { Module } from '@nestjs/common';
|
|
338
390
|
import { CoreModule } from '@edifice.io/edifice-nestjs-core';
|
|
@@ -353,6 +405,7 @@ The `I18nModule` is automatically included when you import `CoreModule` in your
|
|
|
353
405
|
It provides services for registering and fetching translations, enabling multi-language support for your Edifice backend.
|
|
354
406
|
|
|
355
407
|
**Features:**
|
|
408
|
+
|
|
356
409
|
- Registers translation files for your application at startup.
|
|
357
410
|
- Fetches translations dynamically based on request headers (language detection).
|
|
358
411
|
- Integrates with the Edifice ENT client for centralized translation management.
|
|
@@ -360,20 +413,24 @@ It provides services for registering and fetching translations, enabling multi-l
|
|
|
360
413
|
- Used by other modules such as notifications to provide localized content.
|
|
361
414
|
|
|
362
415
|
**How it works:**
|
|
416
|
+
|
|
363
417
|
- The `I18nService` is initialized and injected by the core module.
|
|
364
418
|
- On application startup, translation files in `assets/i18n/` are registered automatically.
|
|
365
419
|
- You can fetch translations for the current request or application using provided service methods.
|
|
366
420
|
- The notification system (`TimelineService` and custom notification services) uses `I18nService` to localize notification content.
|
|
367
421
|
|
|
368
422
|
**Where and when:**
|
|
423
|
+
|
|
369
424
|
- The i18n system is initialized automatically at application startup by `CoreModule`.
|
|
370
425
|
- No manual configuration is needed; all dependencies are wired by the core module.
|
|
371
426
|
|
|
372
427
|
**Configuration:**
|
|
428
|
+
|
|
373
429
|
- The application name (`APP_NAME`) must be set using environment variables.
|
|
374
430
|
- Place your translation files in the `assets/i18n/` directory (e.g., `fr.json`, `en.json`).
|
|
375
431
|
|
|
376
432
|
**Example:**
|
|
433
|
+
|
|
377
434
|
```typescript
|
|
378
435
|
import { Module, Controller, Get, Req } from '@nestjs/common';
|
|
379
436
|
import { CoreModule, I18nService } from '@edifice.io/edifice-nestjs-core';
|
|
@@ -389,7 +446,9 @@ export class MyService {
|
|
|
389
446
|
constructor(private readonly i18nService: I18nService) {}
|
|
390
447
|
|
|
391
448
|
async getTranslations(@Req() request: FastifyRequest) {
|
|
392
|
-
return await this.i18nService.fetchCurrentAppTranslationsForRequest(
|
|
449
|
+
return await this.i18nService.fetchCurrentAppTranslationsForRequest(
|
|
450
|
+
request,
|
|
451
|
+
);
|
|
393
452
|
}
|
|
394
453
|
}
|
|
395
454
|
```
|
|
@@ -404,21 +463,25 @@ The `LoggerModule` is automatically included when you import `CoreModule` in you
|
|
|
404
463
|
It provides structured logging using Pino, including access logs and request logs for your Edifice backend.
|
|
405
464
|
|
|
406
465
|
**Features:**
|
|
466
|
+
|
|
407
467
|
- Structured JSON logging for all requests and application events.
|
|
408
468
|
- Request-scoped logger (`RequestLogger`) for contextual logs (user, path, method).
|
|
409
469
|
- Access logger (`AccessLogger`) for logging authentication and access events.
|
|
410
470
|
- Integrates with NestJS and supports log levels, child loggers, and custom fields.
|
|
411
471
|
|
|
412
472
|
**How it works:**
|
|
473
|
+
|
|
413
474
|
- The logger is initialized and injected by the core module.
|
|
414
475
|
- You can inject `RequestLogger` or `AccessLogger` into your controllers, services, or middleware.
|
|
415
476
|
- Logs are automatically enriched with request/session/user information.
|
|
416
477
|
|
|
417
478
|
**Where and when:**
|
|
479
|
+
|
|
418
480
|
- Logging is initialized automatically at application startup by `CoreModule`.
|
|
419
481
|
- No manual configuration is needed; all dependencies are wired by the core module.
|
|
420
482
|
|
|
421
483
|
**Configuration:**
|
|
484
|
+
|
|
422
485
|
- Log level and options are set using environment variables:
|
|
423
486
|
```env
|
|
424
487
|
LOG_LEVEL=info
|
|
@@ -427,9 +490,10 @@ It provides structured logging using Pino, including access logs and request log
|
|
|
427
490
|
- You can adjust these values to fit your deployment requirements.
|
|
428
491
|
|
|
429
492
|
**Example:**
|
|
493
|
+
|
|
430
494
|
```typescript
|
|
431
495
|
import { Module, Controller, Get, Req } from '@nestjs/common';
|
|
432
|
-
import { Logger } from
|
|
496
|
+
import { Logger } from 'nestjs-pino';
|
|
433
497
|
import { CoreModule } from '@edifice.io/edifice-nestjs-core';
|
|
434
498
|
import { FastifyRequest } from 'fastify';
|
|
435
499
|
|
|
@@ -444,7 +508,7 @@ export class MyController {
|
|
|
444
508
|
|
|
445
509
|
@Get('hello')
|
|
446
510
|
async hello(@Req() request: FastifyRequest) {
|
|
447
|
-
this.logger.info(
|
|
511
|
+
this.logger.info({ path: request.url }, 'Hello endpoint accessed');
|
|
448
512
|
return { message: 'Hello world' };
|
|
449
513
|
}
|
|
450
514
|
}
|
|
@@ -460,6 +524,7 @@ The `NatsModule` is automatically included when you import `CoreModule` in your
|
|
|
460
524
|
It provides a centralized NATS client for messaging, service calls, and pub/sub communication between Edifice microservices.
|
|
461
525
|
|
|
462
526
|
**Features:**
|
|
527
|
+
|
|
463
528
|
- Centralized NATS configuration and connection management.
|
|
464
529
|
- Exports a configured NATS `ClientProxy` for messaging and service communication.
|
|
465
530
|
- Supports pub/sub and request/response patterns using NestJS decorators (`EventPattern`, `MessagePattern`).
|
|
@@ -468,15 +533,18 @@ It provides a centralized NATS client for messaging, service calls, and pub/sub
|
|
|
468
533
|
- Provides `EntNatsServiceClient` for calling external Edifice services (request/response).
|
|
469
534
|
|
|
470
535
|
**How it works:**
|
|
536
|
+
|
|
471
537
|
- The NATS client is initialized and injected by the core module.
|
|
472
538
|
- You can inject `EntNatsServiceClient` to call external services.
|
|
473
539
|
- You can use abstract subscriber classes (generated by the CLI) to handle incoming events and requests.
|
|
474
540
|
|
|
475
541
|
**Where and when:**
|
|
542
|
+
|
|
476
543
|
- The NATS system is initialized automatically at application startup by `CoreModule`.
|
|
477
544
|
- No manual configuration is needed; all dependencies are wired by the core module.
|
|
478
545
|
|
|
479
546
|
**Configuration:**
|
|
547
|
+
|
|
480
548
|
- NATS connection parameters are set using environment variables:
|
|
481
549
|
```env
|
|
482
550
|
NATS_URL=nats://localhost:4222
|
|
@@ -500,7 +568,10 @@ import { EntNatsServiceClient } from '@edifice.io/edifice-ent-client';
|
|
|
500
568
|
export class CommunicationService {
|
|
501
569
|
constructor(private readonly entServiceClient: EntNatsServiceClient) {}
|
|
502
570
|
|
|
503
|
-
async addLinkBetweenGroups(
|
|
571
|
+
async addLinkBetweenGroups(
|
|
572
|
+
sourceGroupId: string,
|
|
573
|
+
targetGroupId: string,
|
|
574
|
+
): Promise<boolean> {
|
|
504
575
|
const request = { startGroupId: sourceGroupId, endGroupId: targetGroupId };
|
|
505
576
|
const response = await this.entServiceClient.addLinkBetweenGroups(request);
|
|
506
577
|
return response.created ?? false;
|
|
@@ -513,7 +584,13 @@ export class CommunicationService {
|
|
|
513
584
|
> This example shows how to subscribe to events or respond to service requests using NestJS decorators and abstract classes generated by the CLI.
|
|
514
585
|
|
|
515
586
|
```typescript
|
|
516
|
-
import {
|
|
587
|
+
import {
|
|
588
|
+
EventPattern,
|
|
589
|
+
MessagePattern,
|
|
590
|
+
Payload,
|
|
591
|
+
Ctx,
|
|
592
|
+
NatsContext,
|
|
593
|
+
} from '@nestjs/microservices';
|
|
517
594
|
|
|
518
595
|
// These abstract subscriber classes are generated by the CLI.
|
|
519
596
|
// You should extend them to implement your own event/message handling logic.
|
|
@@ -521,40 +598,58 @@ import { EventPattern, MessagePattern, Payload, Ctx, NatsContext } from '@nestjs
|
|
|
521
598
|
// Example: Subscribe to events
|
|
522
599
|
export abstract class BrokerSubscriber {
|
|
523
600
|
@EventPattern('directory.groups.deleted')
|
|
524
|
-
onGroupsDeleted(
|
|
601
|
+
onGroupsDeleted(
|
|
602
|
+
@Payload() data: GroupsDeletedDTO,
|
|
603
|
+
@Ctx() context: NatsContext,
|
|
604
|
+
) {
|
|
525
605
|
this.handleGroupsDeletedEvent(data, context.getSubject());
|
|
526
606
|
}
|
|
527
|
-
abstract handleGroupsDeletedEvent(
|
|
607
|
+
abstract handleGroupsDeletedEvent(
|
|
608
|
+
data: GroupsDeletedDTO,
|
|
609
|
+
subject: string,
|
|
610
|
+
): void;
|
|
528
611
|
}
|
|
529
612
|
|
|
530
613
|
// Example: Respond to service requests
|
|
531
614
|
export abstract class AudienceSubscriber {
|
|
532
615
|
@MessagePattern('audience.check.right.communities.*')
|
|
533
|
-
onCheckResourceAccess(
|
|
616
|
+
onCheckResourceAccess(
|
|
617
|
+
@Payload() request: CheckResourceAccessRequestDTO,
|
|
618
|
+
@Ctx() ctx: NatsContext,
|
|
619
|
+
): Promise<CheckResourceAccessResponseDTO> {
|
|
534
620
|
return this.handleCheckAnnouncementAccess(request, ctx.getSubject());
|
|
535
621
|
}
|
|
536
|
-
abstract handleCheckAnnouncementAccess(
|
|
622
|
+
abstract handleCheckAnnouncementAccess(
|
|
623
|
+
request: CheckResourceAccessRequestDTO,
|
|
624
|
+
subject: string,
|
|
625
|
+
): Promise<CheckResourceAccessResponseDTO>;
|
|
537
626
|
}
|
|
538
627
|
|
|
539
628
|
// Example: Concrete implementation
|
|
540
|
-
@
|
|
629
|
+
@Controller()
|
|
541
630
|
export class MyBrokerSubscriber extends BrokerSubscriber {
|
|
542
631
|
handleGroupsDeletedEvent(data: GroupsDeletedDTO, subject: string): void {
|
|
543
632
|
// Your custom logic here
|
|
544
|
-
console.log(
|
|
633
|
+
console.log(
|
|
634
|
+
`Groups deleted: ${JSON.stringify(data)} from subject: ${subject}`,
|
|
635
|
+
);
|
|
545
636
|
}
|
|
546
637
|
}
|
|
547
638
|
|
|
548
|
-
@
|
|
639
|
+
@Controller()
|
|
549
640
|
export class MyAudienceSubscriber extends AudienceSubscriber {
|
|
550
|
-
async handleCheckAnnouncementAccess(
|
|
641
|
+
async handleCheckAnnouncementAccess(
|
|
642
|
+
request: CheckResourceAccessRequestDTO,
|
|
643
|
+
subject: string,
|
|
644
|
+
): Promise<CheckResourceAccessResponseDTO> {
|
|
551
645
|
// Your custom logic here
|
|
552
646
|
return { accessGranted: true };
|
|
553
647
|
}
|
|
554
648
|
}
|
|
555
649
|
```
|
|
556
650
|
|
|
557
|
-
**Note:**
|
|
651
|
+
**Note:**
|
|
652
|
+
|
|
558
653
|
- You do not need to configure NATS manually; it is ready to use when you import `CoreModule`.
|
|
559
654
|
- Use `EntNatsServiceClient` for external service calls, and abstract subscriber classes for pub/sub and request/response patterns.
|
|
560
655
|
- The CLI can generate abstract subscriber classes to help you implement event and message handlers.
|
|
@@ -565,28 +660,38 @@ The `PermissionModule` is automatically included when you import `CoreModule` in
|
|
|
565
660
|
It provides decorators and guards for workflow-based and admin authorization, enabling fine-grained access control for your endpoints.
|
|
566
661
|
|
|
567
662
|
**Features:**
|
|
663
|
+
|
|
568
664
|
- `@RequirePermission('PERMISSION_NAME')`: Restricts access to endpoints based on user workflow rights.
|
|
569
665
|
- `@RequireAdmc()`: Restricts access to endpoints for super administrators (ADMC).
|
|
570
666
|
- `@Public()`: Marks endpoints as public (no authentication required).
|
|
571
667
|
- Guards (`PermissionGuard`, `AdmcGuard`) are applied globally by the core module.
|
|
572
668
|
|
|
573
669
|
**How it works:**
|
|
670
|
+
|
|
574
671
|
- Decorators set metadata on your controllers and endpoints.
|
|
575
672
|
- Guards read this metadata and check the user's session and permissions.
|
|
576
673
|
- Permissions are automatically registered at startup by the AppRegistry service.
|
|
577
674
|
|
|
578
675
|
**Where and when:**
|
|
676
|
+
|
|
579
677
|
- The permission system is initialized automatically at application startup by `CoreModule`.
|
|
580
678
|
- No manual configuration is needed; all dependencies are wired by the core module.
|
|
581
679
|
|
|
582
680
|
**Configuration:**
|
|
681
|
+
|
|
583
682
|
- User permissions and roles are provided in the session object (`entSession`).
|
|
584
683
|
- Workflow rights are defined in your business logic and registered via decorators.
|
|
585
684
|
|
|
586
685
|
**Example:**
|
|
686
|
+
|
|
587
687
|
```typescript
|
|
588
688
|
import { Controller, Get, Post } from '@nestjs/common';
|
|
589
|
-
import {
|
|
689
|
+
import {
|
|
690
|
+
RequirePermission,
|
|
691
|
+
RequireAdmc,
|
|
692
|
+
Public,
|
|
693
|
+
CoreModule,
|
|
694
|
+
} from '@edifice.io/edifice-nestjs-core';
|
|
590
695
|
|
|
591
696
|
@Module({
|
|
592
697
|
imports: [CoreModule], // PermissionModule is included automatically
|
|
@@ -625,23 +730,28 @@ The `SessionModule` is automatically included when you import `CoreModule` in yo
|
|
|
625
730
|
It provides middleware, decorators, and helpers for managing user sessions in your Edifice backend.
|
|
626
731
|
|
|
627
732
|
**Features:**
|
|
733
|
+
|
|
628
734
|
- Middleware to validate and attach user sessions to each request.
|
|
629
735
|
- Session decorator (`@Session()`) to inject the session directly into your controller methods.
|
|
630
736
|
- Exposes session information on the raw Fastify request object (`request.raw.entSession`).
|
|
631
737
|
- Integrates with the ENT service via NATS for session validation and refresh.
|
|
632
738
|
|
|
633
739
|
**How it works:**
|
|
740
|
+
|
|
634
741
|
- The session middleware runs on every API request, validates the session via the ENT service, and attaches it to the request.
|
|
635
742
|
- You can access the session in your controllers using either the `@Session()` decorator or directly from the request object.
|
|
636
743
|
|
|
637
744
|
**Where and when:**
|
|
745
|
+
|
|
638
746
|
- The session system is initialized automatically at application startup by `CoreModule`.
|
|
639
747
|
- No manual configuration is needed; all dependencies are wired by the core module.
|
|
640
748
|
|
|
641
749
|
**Configuration:**
|
|
750
|
+
|
|
642
751
|
- Session validation uses the NATS connection provided by the core module.
|
|
643
752
|
|
|
644
753
|
**Example:**
|
|
754
|
+
|
|
645
755
|
```typescript
|
|
646
756
|
import { Controller, Get, Req } from '@nestjs/common';
|
|
647
757
|
import { CoreModule, Session } from '@edifice.io/edifice-nestjs-core';
|
|
@@ -680,21 +790,25 @@ The `TimelineModule` is automatically included when you import `CoreModule` in y
|
|
|
680
790
|
It provides services for registering notification templates and sending notifications to users via the Edifice timeline system.
|
|
681
791
|
|
|
682
792
|
**Features:**
|
|
793
|
+
|
|
683
794
|
- Register notification templates for your application.
|
|
684
795
|
- Send notifications to users (with push, mail, and preview options).
|
|
685
796
|
- Integrates with the ENT client and NATS for delivery.
|
|
686
797
|
- Supports localization via the I18n service.
|
|
687
798
|
|
|
688
799
|
**How it works:**
|
|
800
|
+
|
|
689
801
|
- The `TimelineService` is initialized and injected by the core module.
|
|
690
802
|
- You can register notification templates at startup or on demand.
|
|
691
803
|
- You can send notifications to users by calling the service methods.
|
|
692
804
|
|
|
693
805
|
**Where and when:**
|
|
806
|
+
|
|
694
807
|
- The timeline system is initialized automatically at application startup by `CoreModule`.
|
|
695
808
|
- No manual configuration is needed; all dependencies are wired by the core module.
|
|
696
809
|
|
|
697
810
|
**Configuration:**
|
|
811
|
+
|
|
698
812
|
- The application name (`APP_NAME`) must be set using environment variables.
|
|
699
813
|
- Notification templates can be registered at module initialization or dynamically.
|
|
700
814
|
|
|
@@ -767,7 +881,6 @@ export class MyNotificationService implements OnModuleInit {
|
|
|
767
881
|
constructor(private readonly timelineService: TimelineService) {}
|
|
768
882
|
|
|
769
883
|
async onModuleInit() {
|
|
770
|
-
|
|
771
884
|
const templates: RegisterNotificationRequestDTO[] = [
|
|
772
885
|
{
|
|
773
886
|
notificationName: 'MY_EVENT',
|
|
@@ -782,9 +895,13 @@ export class MyNotificationService implements OnModuleInit {
|
|
|
782
895
|
```
|
|
783
896
|
|
|
784
897
|
**Sending a notification:**
|
|
898
|
+
|
|
785
899
|
```typescript
|
|
786
900
|
import { TimelineService } from '@edifice.io/edifice-nestjs-core';
|
|
787
|
-
import {
|
|
901
|
+
import {
|
|
902
|
+
SessionDto,
|
|
903
|
+
SendNotificationRequestDTO,
|
|
904
|
+
} from '@edifice.io/edifice-ent-client';
|
|
788
905
|
|
|
789
906
|
@Injectable()
|
|
790
907
|
export class MyService {
|
|
@@ -807,7 +924,8 @@ export class MyService {
|
|
|
807
924
|
}
|
|
808
925
|
```
|
|
809
926
|
|
|
810
|
-
**Note:**
|
|
927
|
+
**Note:**
|
|
928
|
+
|
|
811
929
|
- You do not need to configure the timeline system manually; it is ready to use when you import `CoreModule`.
|
|
812
930
|
- Notifications are localized using the I18n service and delivered via NATS and the ENT client.
|
|
813
931
|
|
|
@@ -817,16 +935,19 @@ The Swagger module is automatically enabled when you import `CoreModule` in your
|
|
|
817
935
|
It provides an interactive OpenAPI documentation for your API, available at `/openapi`.
|
|
818
936
|
|
|
819
937
|
**Features:**
|
|
938
|
+
|
|
820
939
|
- Auto-generates OpenAPI documentation from your controllers and DTOs.
|
|
821
940
|
- Serves the Swagger UI at `/openapi` by default.
|
|
822
941
|
- Supports custom title, description, version, and server URL via environment variables.
|
|
823
942
|
|
|
824
943
|
**How it works:**
|
|
944
|
+
|
|
825
945
|
- On application startup, Swagger is configured and started automatically if `ENABLE_SWAGGER=true` (default).
|
|
826
946
|
- The configuration is read from environment variables and injected via `ConfigService`.
|
|
827
947
|
|
|
828
948
|
**Configuration:**
|
|
829
949
|
Set the following environment variables to customize Swagger:
|
|
950
|
+
|
|
830
951
|
```env
|
|
831
952
|
ENABLE_SWAGGER=true
|
|
832
953
|
SWAGGER_SERVER_URL=https://api.example.com
|
|
@@ -854,9 +975,7 @@ import { Module } from '@nestjs/common';
|
|
|
854
975
|
import { CoreModule } from '@edifice.io/edifice-nestjs-core';
|
|
855
976
|
|
|
856
977
|
@Module({
|
|
857
|
-
imports: [
|
|
858
|
-
CoreModule,
|
|
859
|
-
],
|
|
978
|
+
imports: [CoreModule],
|
|
860
979
|
})
|
|
861
980
|
export class AppModule {}
|
|
862
981
|
```
|
|
@@ -877,12 +996,14 @@ Each tool is available as a binary when you install `@edifice.io/edifice-nestjs-
|
|
|
877
996
|
**Purpose:**
|
|
878
997
|
Generate MikroORM entity files from your PostgreSQL database schema.
|
|
879
998
|
|
|
880
|
-
**Usage:**
|
|
999
|
+
**Usage:**
|
|
1000
|
+
|
|
881
1001
|
```bash
|
|
882
1002
|
pnpm edifice-generate-entities --schema <schema-name> [options]
|
|
883
1003
|
```
|
|
884
1004
|
|
|
885
1005
|
**Arguments:**
|
|
1006
|
+
|
|
886
1007
|
- `--schema` (required): Name of the database schema to use for entity generation.
|
|
887
1008
|
- `--path`: Target directory for generated entities (default: `./src/entities`).
|
|
888
1009
|
- `--temp-dir`: Temporary directory for initial generation (default: `./src/temp/entities`).
|
|
@@ -890,6 +1011,7 @@ pnpm edifice-generate-entities --schema <schema-name> [options]
|
|
|
890
1011
|
- `--keep-temp`: Keep temporary directory after generation (`true` or `false`, default: `false`).
|
|
891
1012
|
|
|
892
1013
|
**Examples:**
|
|
1014
|
+
|
|
893
1015
|
```bash
|
|
894
1016
|
pnpm edifice-generate-entities --schema community
|
|
895
1017
|
pnpm edifice-generate-entities --schema community --temp-dir ./src/temp --path ./src/entities
|
|
@@ -904,15 +1026,18 @@ pnpm edifice-generate-entities --schema community --keep-temp true
|
|
|
904
1026
|
**Purpose:**
|
|
905
1027
|
Generate a build metadata file containing build date, git commit hash, and branch name.
|
|
906
1028
|
|
|
907
|
-
**Usage:**
|
|
1029
|
+
**Usage:**
|
|
1030
|
+
|
|
908
1031
|
```bash
|
|
909
1032
|
pnpm edifice-generate-metadata <target-file-path>
|
|
910
1033
|
```
|
|
911
1034
|
|
|
912
1035
|
**Arguments:**
|
|
1036
|
+
|
|
913
1037
|
- `<target-file-path>` (required): Path to the file where metadata will be written.
|
|
914
1038
|
|
|
915
1039
|
**Example:**
|
|
1040
|
+
|
|
916
1041
|
```bash
|
|
917
1042
|
pnpm edifice-generate-metadata ./dist/metadata.txt
|
|
918
1043
|
```
|
|
@@ -924,7 +1049,8 @@ pnpm edifice-generate-metadata ./dist/metadata.txt
|
|
|
924
1049
|
**Purpose:**
|
|
925
1050
|
Synchronize DTO TypeScript definitions to K6-compatible types for API testing.
|
|
926
1051
|
|
|
927
|
-
**Usage:**
|
|
1052
|
+
**Usage:**
|
|
1053
|
+
|
|
928
1054
|
```bash
|
|
929
1055
|
pnpm edifice-k6-sync-dto
|
|
930
1056
|
```
|
|
@@ -934,11 +1060,13 @@ This script uses configuration constants for DTOs and output paths.
|
|
|
934
1060
|
You can adjust the paths in the script or via environment variables if supported.
|
|
935
1061
|
|
|
936
1062
|
**Example:**
|
|
1063
|
+
|
|
937
1064
|
```bash
|
|
938
1065
|
pnpm edifice-k6-sync-dto
|
|
939
1066
|
```
|
|
940
1067
|
|
|
941
|
-
**Details:**
|
|
1068
|
+
**Details:**
|
|
1069
|
+
|
|
942
1070
|
- Parses DTOs from `client/rest/src/dtos`.
|
|
943
1071
|
- Generates K6-compatible types in `types/generated`.
|
|
944
1072
|
- Excludes files named `index.ts` by default.
|
|
@@ -980,7 +1108,6 @@ pnpm lint
|
|
|
980
1108
|
|
|
981
1109
|
- [@edifice.io/edifice-ent-client](https://github.com/edificeio/entcore) - Edifice ENT client library
|
|
982
1110
|
|
|
983
|
-
|
|
984
1111
|
## 🐛 Issues
|
|
985
1112
|
|
|
986
1113
|
Report issues on [GitHub Issues](https://github.com/edificeio/edifice-nestjs-core/issues).
|