@edifice.io/edifice-nestjs-core 1.0.0-develop-pedago.20251204183503 → 1.0.0-develop.20251211080353
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 +144 -42
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +4 -3
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,16 @@ 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
|
|
|
143
|
-
|
|
144
153
|
**Additional configuration:**
|
|
145
154
|
|
|
146
155
|
You can also provide additional configuration like so
|
|
156
|
+
|
|
147
157
|
```typescript
|
|
148
158
|
import { Module } from '@nestjs/common';
|
|
149
|
-
import { configuration as CoreConfig } from
|
|
150
|
-
import AppConfig from
|
|
159
|
+
import { configuration as CoreConfig } from '@edifice.io/edifice-nestjs-core';
|
|
160
|
+
import AppConfig from './config/configuration'; // Your app's configuration object
|
|
151
161
|
import { CoreModule } from '@edifice.io/edifice-nestjs-core';
|
|
152
|
-
import { ConfigModule } from
|
|
162
|
+
import { ConfigModule } from '@nestjs/config';
|
|
153
163
|
|
|
154
164
|
@Module({
|
|
155
165
|
imports: [
|
|
@@ -170,11 +180,13 @@ export class AppModule {}
|
|
|
170
180
|
The `DatabaseModule` provides seamless integration with MikroORM and PostgreSQL for your Edifice backend application.
|
|
171
181
|
|
|
172
182
|
**Features:**
|
|
183
|
+
|
|
173
184
|
- Automatic database connection and configuration using NestJS `ConfigModule`.
|
|
174
185
|
- Runs pending migrations automatically at startup (if enabled in configuration).
|
|
175
186
|
- Provides helpers to execute SQL scripts and manage schema evolution.
|
|
176
187
|
|
|
177
188
|
**How to use:**
|
|
189
|
+
|
|
178
190
|
- Import `DatabaseModule` in your main application module (already included in `CoreModule`).
|
|
179
191
|
- Configure your database connection via environment variables (`DATABASE_URL`, `DATABASE_USER`, etc.).
|
|
180
192
|
- Place your migration scripts in the `sql/` directory, following the naming convention:
|
|
@@ -183,9 +195,11 @@ The `DatabaseModule` provides seamless integration with MikroORM and PostgreSQL
|
|
|
183
195
|
- Implement migration classes in `./src/migrations/`, each using the helper to execute the corresponding SQL files.
|
|
184
196
|
|
|
185
197
|
**Example:**
|
|
198
|
+
|
|
186
199
|
- Implement migration classes in `./src/migrations/`, each using the helper to execute the corresponding SQL files.
|
|
187
200
|
|
|
188
|
-
|
|
201
|
+
_SQL migration script (`sql/01-init.sql`):_
|
|
202
|
+
|
|
189
203
|
```sql
|
|
190
204
|
-- Create a demo table
|
|
191
205
|
CREATE TABLE demo_table (
|
|
@@ -194,13 +208,15 @@ CREATE TABLE demo_table (
|
|
|
194
208
|
);
|
|
195
209
|
```
|
|
196
210
|
|
|
197
|
-
|
|
211
|
+
_SQL rollback script (`sql/01-rollback.sql`):_
|
|
212
|
+
|
|
198
213
|
```sql
|
|
199
214
|
-- Drop the demo table
|
|
200
215
|
DROP TABLE IF EXISTS demo_table;
|
|
201
216
|
```
|
|
202
217
|
|
|
203
|
-
|
|
218
|
+
_Migration class (`src/migrations/Migration01.ts`):_
|
|
219
|
+
|
|
204
220
|
```typescript
|
|
205
221
|
import { Migration } from '@mikro-orm/migrations';
|
|
206
222
|
import { executeScript } from '@edifice.io/edifice-nestjs-core';
|
|
@@ -216,7 +232,8 @@ export class Migration01 extends Migration {
|
|
|
216
232
|
}
|
|
217
233
|
```
|
|
218
234
|
|
|
219
|
-
|
|
235
|
+
_Entity definition (`src/entities/demo.entity.ts`):_
|
|
236
|
+
|
|
220
237
|
```typescript
|
|
221
238
|
import { Entity, PrimaryKey, Property } from '@mikro-orm/core';
|
|
222
239
|
|
|
@@ -230,7 +247,8 @@ export class Demo {
|
|
|
230
247
|
}
|
|
231
248
|
```
|
|
232
249
|
|
|
233
|
-
|
|
250
|
+
_Service using EntityRepository (`src/demo/demo.service.ts`):_
|
|
251
|
+
|
|
234
252
|
```typescript
|
|
235
253
|
import { Injectable } from '@nestjs/common';
|
|
236
254
|
import { InjectRepository } from '@mikro-orm/nestjs';
|
|
@@ -256,7 +274,8 @@ export class DemoService {
|
|
|
256
274
|
}
|
|
257
275
|
```
|
|
258
276
|
|
|
259
|
-
|
|
277
|
+
_Demo module (`src/demo/demo.module.ts`):_
|
|
278
|
+
|
|
260
279
|
```typescript
|
|
261
280
|
import { Module } from '@nestjs/common';
|
|
262
281
|
import { CoreModule } from '@edifice.io/edifice-nestjs-core';
|
|
@@ -265,17 +284,15 @@ import { Demo } from '../entities/demo.entity';
|
|
|
265
284
|
import { MikroOrmModule } from '@mikro-orm/nestjs';
|
|
266
285
|
|
|
267
286
|
@Module({
|
|
268
|
-
imports: [
|
|
269
|
-
CoreModule,
|
|
270
|
-
MikroOrmModule.forFeature([Demo]),
|
|
271
|
-
],
|
|
287
|
+
imports: [CoreModule, MikroOrmModule.forFeature([Demo])],
|
|
272
288
|
providers: [DemoService],
|
|
273
289
|
exports: [DemoService],
|
|
274
290
|
})
|
|
275
291
|
export class DemoModule {}
|
|
276
292
|
```
|
|
277
293
|
|
|
278
|
-
**Note:**
|
|
294
|
+
**Note:**
|
|
295
|
+
|
|
279
296
|
- Database connection parameters and migration behavior are controlled via environment variables.
|
|
280
297
|
- The module ensures your database schema is up-to-date and provides utilities for advanced migration workflows.
|
|
281
298
|
|
|
@@ -284,17 +301,20 @@ export class DemoModule {}
|
|
|
284
301
|
The `EventModule` provides services for tracking and recording user events (such as access and creation) in your Edifice backend application.
|
|
285
302
|
|
|
286
303
|
**Features:**
|
|
304
|
+
|
|
287
305
|
- Publishes user events (ACCESS, CREATE) to the Edifice event system via NATS.
|
|
288
306
|
- Automatically extracts user/session information from requests.
|
|
289
307
|
- Skips access events for mobile webview requests.
|
|
290
308
|
- Centralizes event logging for analytics and auditing.
|
|
291
309
|
|
|
292
310
|
**How to use:**
|
|
311
|
+
|
|
293
312
|
- Import `CoreModule` in your main application module (already includes `EventModule`).
|
|
294
313
|
- Inject `EventService` into your controllers or services.
|
|
295
314
|
- Call `createAccessEvent(request, resourceType)` or `createCreateEvent(request, resourceType)` to record events.
|
|
296
315
|
|
|
297
316
|
**Example:**
|
|
317
|
+
|
|
298
318
|
```typescript
|
|
299
319
|
import { Controller, Get, Post, Req, Injectable } from '@nestjs/common';
|
|
300
320
|
import { EventService, CoreModule } from '@edifice.io/edifice-nestjs-core';
|
|
@@ -322,10 +342,12 @@ export class ResourceController {
|
|
|
322
342
|
```
|
|
323
343
|
|
|
324
344
|
**Configuration:**
|
|
345
|
+
|
|
325
346
|
- The module uses `ConfigService` to get the application name (`app.name`).
|
|
326
347
|
- Events are sent via the NATS client (`EntNatsServiceClient`), which is configured automatically by the core module.
|
|
327
348
|
|
|
328
|
-
**Note:**
|
|
349
|
+
**Note:**
|
|
350
|
+
|
|
329
351
|
- You do not need to configure the event system manually; it is ready to use when you import `CoreModule`.
|
|
330
352
|
- Events are useful for analytics, auditing, and workflow triggers.
|
|
331
353
|
|
|
@@ -335,21 +357,25 @@ The `HealthModule` is automatically included when you import `CoreModule` in you
|
|
|
335
357
|
It provides endpoints and services for readiness and liveness checks, integrating with NestJS Terminus.
|
|
336
358
|
|
|
337
359
|
**Features:**
|
|
360
|
+
|
|
338
361
|
- Exposes a `/health` endpoint for readiness and liveness checks.
|
|
339
362
|
- Checks database connectivity (MikroORM), memory usage, and NATS connection.
|
|
340
363
|
- Customizable thresholds for memory usage via configuration.
|
|
341
364
|
- Integrates with monitoring and orchestration systems (Kubernetes, Docker, etc.).
|
|
342
365
|
|
|
343
366
|
**How it works:**
|
|
367
|
+
|
|
344
368
|
- The `HealthController` aggregates checks for database, memory, and NATS.
|
|
345
369
|
- Health indicators are injected and run automatically.
|
|
346
370
|
- The `/health` endpoint is public and can be used for probes.
|
|
347
371
|
|
|
348
372
|
**Where and when:**
|
|
373
|
+
|
|
349
374
|
- The health system is initialized automatically at application startup by `CoreModule`.
|
|
350
375
|
- No manual configuration is needed; all dependencies are wired by the core module.
|
|
351
376
|
|
|
352
377
|
**Configuration:**
|
|
378
|
+
|
|
353
379
|
- Memory thresholds and other health parameters are set using environment variables:
|
|
354
380
|
```env
|
|
355
381
|
HEAP_MEMORY=300
|
|
@@ -358,6 +384,7 @@ It provides endpoints and services for readiness and liveness checks, integratin
|
|
|
358
384
|
- You can adjust these values to fit your deployment requirements.
|
|
359
385
|
|
|
360
386
|
**Example:**
|
|
387
|
+
|
|
361
388
|
```typescript
|
|
362
389
|
import { Module } from '@nestjs/common';
|
|
363
390
|
import { CoreModule } from '@edifice.io/edifice-nestjs-core';
|
|
@@ -378,6 +405,7 @@ The `I18nModule` is automatically included when you import `CoreModule` in your
|
|
|
378
405
|
It provides services for registering and fetching translations, enabling multi-language support for your Edifice backend.
|
|
379
406
|
|
|
380
407
|
**Features:**
|
|
408
|
+
|
|
381
409
|
- Registers translation files for your application at startup.
|
|
382
410
|
- Fetches translations dynamically based on request headers (language detection).
|
|
383
411
|
- Integrates with the Edifice ENT client for centralized translation management.
|
|
@@ -385,20 +413,24 @@ It provides services for registering and fetching translations, enabling multi-l
|
|
|
385
413
|
- Used by other modules such as notifications to provide localized content.
|
|
386
414
|
|
|
387
415
|
**How it works:**
|
|
416
|
+
|
|
388
417
|
- The `I18nService` is initialized and injected by the core module.
|
|
389
418
|
- On application startup, translation files in `assets/i18n/` are registered automatically.
|
|
390
419
|
- You can fetch translations for the current request or application using provided service methods.
|
|
391
420
|
- The notification system (`TimelineService` and custom notification services) uses `I18nService` to localize notification content.
|
|
392
421
|
|
|
393
422
|
**Where and when:**
|
|
423
|
+
|
|
394
424
|
- The i18n system is initialized automatically at application startup by `CoreModule`.
|
|
395
425
|
- No manual configuration is needed; all dependencies are wired by the core module.
|
|
396
426
|
|
|
397
427
|
**Configuration:**
|
|
428
|
+
|
|
398
429
|
- The application name (`APP_NAME`) must be set using environment variables.
|
|
399
430
|
- Place your translation files in the `assets/i18n/` directory (e.g., `fr.json`, `en.json`).
|
|
400
431
|
|
|
401
432
|
**Example:**
|
|
433
|
+
|
|
402
434
|
```typescript
|
|
403
435
|
import { Module, Controller, Get, Req } from '@nestjs/common';
|
|
404
436
|
import { CoreModule, I18nService } from '@edifice.io/edifice-nestjs-core';
|
|
@@ -414,7 +446,9 @@ export class MyService {
|
|
|
414
446
|
constructor(private readonly i18nService: I18nService) {}
|
|
415
447
|
|
|
416
448
|
async getTranslations(@Req() request: FastifyRequest) {
|
|
417
|
-
return await this.i18nService.fetchCurrentAppTranslationsForRequest(
|
|
449
|
+
return await this.i18nService.fetchCurrentAppTranslationsForRequest(
|
|
450
|
+
request,
|
|
451
|
+
);
|
|
418
452
|
}
|
|
419
453
|
}
|
|
420
454
|
```
|
|
@@ -429,21 +463,25 @@ The `LoggerModule` is automatically included when you import `CoreModule` in you
|
|
|
429
463
|
It provides structured logging using Pino, including access logs and request logs for your Edifice backend.
|
|
430
464
|
|
|
431
465
|
**Features:**
|
|
466
|
+
|
|
432
467
|
- Structured JSON logging for all requests and application events.
|
|
433
468
|
- Request-scoped logger (`RequestLogger`) for contextual logs (user, path, method).
|
|
434
469
|
- Access logger (`AccessLogger`) for logging authentication and access events.
|
|
435
470
|
- Integrates with NestJS and supports log levels, child loggers, and custom fields.
|
|
436
471
|
|
|
437
472
|
**How it works:**
|
|
473
|
+
|
|
438
474
|
- The logger is initialized and injected by the core module.
|
|
439
475
|
- You can inject `RequestLogger` or `AccessLogger` into your controllers, services, or middleware.
|
|
440
476
|
- Logs are automatically enriched with request/session/user information.
|
|
441
477
|
|
|
442
478
|
**Where and when:**
|
|
479
|
+
|
|
443
480
|
- Logging is initialized automatically at application startup by `CoreModule`.
|
|
444
481
|
- No manual configuration is needed; all dependencies are wired by the core module.
|
|
445
482
|
|
|
446
483
|
**Configuration:**
|
|
484
|
+
|
|
447
485
|
- Log level and options are set using environment variables:
|
|
448
486
|
```env
|
|
449
487
|
LOG_LEVEL=info
|
|
@@ -452,9 +490,10 @@ It provides structured logging using Pino, including access logs and request log
|
|
|
452
490
|
- You can adjust these values to fit your deployment requirements.
|
|
453
491
|
|
|
454
492
|
**Example:**
|
|
493
|
+
|
|
455
494
|
```typescript
|
|
456
495
|
import { Module, Controller, Get, Req } from '@nestjs/common';
|
|
457
|
-
import { Logger } from
|
|
496
|
+
import { Logger } from 'nestjs-pino';
|
|
458
497
|
import { CoreModule } from '@edifice.io/edifice-nestjs-core';
|
|
459
498
|
import { FastifyRequest } from 'fastify';
|
|
460
499
|
|
|
@@ -469,7 +508,7 @@ export class MyController {
|
|
|
469
508
|
|
|
470
509
|
@Get('hello')
|
|
471
510
|
async hello(@Req() request: FastifyRequest) {
|
|
472
|
-
this.logger.info(
|
|
511
|
+
this.logger.info({ path: request.url }, 'Hello endpoint accessed');
|
|
473
512
|
return { message: 'Hello world' };
|
|
474
513
|
}
|
|
475
514
|
}
|
|
@@ -485,6 +524,7 @@ The `NatsModule` is automatically included when you import `CoreModule` in your
|
|
|
485
524
|
It provides a centralized NATS client for messaging, service calls, and pub/sub communication between Edifice microservices.
|
|
486
525
|
|
|
487
526
|
**Features:**
|
|
527
|
+
|
|
488
528
|
- Centralized NATS configuration and connection management.
|
|
489
529
|
- Exports a configured NATS `ClientProxy` for messaging and service communication.
|
|
490
530
|
- Supports pub/sub and request/response patterns using NestJS decorators (`EventPattern`, `MessagePattern`).
|
|
@@ -493,15 +533,18 @@ It provides a centralized NATS client for messaging, service calls, and pub/sub
|
|
|
493
533
|
- Provides `EntNatsServiceClient` for calling external Edifice services (request/response).
|
|
494
534
|
|
|
495
535
|
**How it works:**
|
|
536
|
+
|
|
496
537
|
- The NATS client is initialized and injected by the core module.
|
|
497
538
|
- You can inject `EntNatsServiceClient` to call external services.
|
|
498
539
|
- You can use abstract subscriber classes (generated by the CLI) to handle incoming events and requests.
|
|
499
540
|
|
|
500
541
|
**Where and when:**
|
|
542
|
+
|
|
501
543
|
- The NATS system is initialized automatically at application startup by `CoreModule`.
|
|
502
544
|
- No manual configuration is needed; all dependencies are wired by the core module.
|
|
503
545
|
|
|
504
546
|
**Configuration:**
|
|
547
|
+
|
|
505
548
|
- NATS connection parameters are set using environment variables:
|
|
506
549
|
```env
|
|
507
550
|
NATS_URL=nats://localhost:4222
|
|
@@ -525,7 +568,10 @@ import { EntNatsServiceClient } from '@edifice.io/edifice-ent-client';
|
|
|
525
568
|
export class CommunicationService {
|
|
526
569
|
constructor(private readonly entServiceClient: EntNatsServiceClient) {}
|
|
527
570
|
|
|
528
|
-
async addLinkBetweenGroups(
|
|
571
|
+
async addLinkBetweenGroups(
|
|
572
|
+
sourceGroupId: string,
|
|
573
|
+
targetGroupId: string,
|
|
574
|
+
): Promise<boolean> {
|
|
529
575
|
const request = { startGroupId: sourceGroupId, endGroupId: targetGroupId };
|
|
530
576
|
const response = await this.entServiceClient.addLinkBetweenGroups(request);
|
|
531
577
|
return response.created ?? false;
|
|
@@ -538,7 +584,13 @@ export class CommunicationService {
|
|
|
538
584
|
> This example shows how to subscribe to events or respond to service requests using NestJS decorators and abstract classes generated by the CLI.
|
|
539
585
|
|
|
540
586
|
```typescript
|
|
541
|
-
import {
|
|
587
|
+
import {
|
|
588
|
+
EventPattern,
|
|
589
|
+
MessagePattern,
|
|
590
|
+
Payload,
|
|
591
|
+
Ctx,
|
|
592
|
+
NatsContext,
|
|
593
|
+
} from '@nestjs/microservices';
|
|
542
594
|
|
|
543
595
|
// These abstract subscriber classes are generated by the CLI.
|
|
544
596
|
// You should extend them to implement your own event/message handling logic.
|
|
@@ -546,40 +598,58 @@ import { EventPattern, MessagePattern, Payload, Ctx, NatsContext } from '@nestjs
|
|
|
546
598
|
// Example: Subscribe to events
|
|
547
599
|
export abstract class BrokerSubscriber {
|
|
548
600
|
@EventPattern('directory.groups.deleted')
|
|
549
|
-
onGroupsDeleted(
|
|
601
|
+
onGroupsDeleted(
|
|
602
|
+
@Payload() data: GroupsDeletedDTO,
|
|
603
|
+
@Ctx() context: NatsContext,
|
|
604
|
+
) {
|
|
550
605
|
this.handleGroupsDeletedEvent(data, context.getSubject());
|
|
551
606
|
}
|
|
552
|
-
abstract handleGroupsDeletedEvent(
|
|
607
|
+
abstract handleGroupsDeletedEvent(
|
|
608
|
+
data: GroupsDeletedDTO,
|
|
609
|
+
subject: string,
|
|
610
|
+
): void;
|
|
553
611
|
}
|
|
554
612
|
|
|
555
613
|
// Example: Respond to service requests
|
|
556
614
|
export abstract class AudienceSubscriber {
|
|
557
615
|
@MessagePattern('audience.check.right.communities.*')
|
|
558
|
-
onCheckResourceAccess(
|
|
616
|
+
onCheckResourceAccess(
|
|
617
|
+
@Payload() request: CheckResourceAccessRequestDTO,
|
|
618
|
+
@Ctx() ctx: NatsContext,
|
|
619
|
+
): Promise<CheckResourceAccessResponseDTO> {
|
|
559
620
|
return this.handleCheckAnnouncementAccess(request, ctx.getSubject());
|
|
560
621
|
}
|
|
561
|
-
abstract handleCheckAnnouncementAccess(
|
|
622
|
+
abstract handleCheckAnnouncementAccess(
|
|
623
|
+
request: CheckResourceAccessRequestDTO,
|
|
624
|
+
subject: string,
|
|
625
|
+
): Promise<CheckResourceAccessResponseDTO>;
|
|
562
626
|
}
|
|
563
627
|
|
|
564
628
|
// Example: Concrete implementation
|
|
565
|
-
@
|
|
629
|
+
@Controller()
|
|
566
630
|
export class MyBrokerSubscriber extends BrokerSubscriber {
|
|
567
631
|
handleGroupsDeletedEvent(data: GroupsDeletedDTO, subject: string): void {
|
|
568
632
|
// Your custom logic here
|
|
569
|
-
console.log(
|
|
633
|
+
console.log(
|
|
634
|
+
`Groups deleted: ${JSON.stringify(data)} from subject: ${subject}`,
|
|
635
|
+
);
|
|
570
636
|
}
|
|
571
637
|
}
|
|
572
638
|
|
|
573
|
-
@
|
|
639
|
+
@Controller()
|
|
574
640
|
export class MyAudienceSubscriber extends AudienceSubscriber {
|
|
575
|
-
async handleCheckAnnouncementAccess(
|
|
641
|
+
async handleCheckAnnouncementAccess(
|
|
642
|
+
request: CheckResourceAccessRequestDTO,
|
|
643
|
+
subject: string,
|
|
644
|
+
): Promise<CheckResourceAccessResponseDTO> {
|
|
576
645
|
// Your custom logic here
|
|
577
646
|
return { accessGranted: true };
|
|
578
647
|
}
|
|
579
648
|
}
|
|
580
649
|
```
|
|
581
650
|
|
|
582
|
-
**Note:**
|
|
651
|
+
**Note:**
|
|
652
|
+
|
|
583
653
|
- You do not need to configure NATS manually; it is ready to use when you import `CoreModule`.
|
|
584
654
|
- Use `EntNatsServiceClient` for external service calls, and abstract subscriber classes for pub/sub and request/response patterns.
|
|
585
655
|
- The CLI can generate abstract subscriber classes to help you implement event and message handlers.
|
|
@@ -590,28 +660,38 @@ The `PermissionModule` is automatically included when you import `CoreModule` in
|
|
|
590
660
|
It provides decorators and guards for workflow-based and admin authorization, enabling fine-grained access control for your endpoints.
|
|
591
661
|
|
|
592
662
|
**Features:**
|
|
663
|
+
|
|
593
664
|
- `@RequirePermission('PERMISSION_NAME')`: Restricts access to endpoints based on user workflow rights.
|
|
594
665
|
- `@RequireAdmc()`: Restricts access to endpoints for super administrators (ADMC).
|
|
595
666
|
- `@Public()`: Marks endpoints as public (no authentication required).
|
|
596
667
|
- Guards (`PermissionGuard`, `AdmcGuard`) are applied globally by the core module.
|
|
597
668
|
|
|
598
669
|
**How it works:**
|
|
670
|
+
|
|
599
671
|
- Decorators set metadata on your controllers and endpoints.
|
|
600
672
|
- Guards read this metadata and check the user's session and permissions.
|
|
601
673
|
- Permissions are automatically registered at startup by the AppRegistry service.
|
|
602
674
|
|
|
603
675
|
**Where and when:**
|
|
676
|
+
|
|
604
677
|
- The permission system is initialized automatically at application startup by `CoreModule`.
|
|
605
678
|
- No manual configuration is needed; all dependencies are wired by the core module.
|
|
606
679
|
|
|
607
680
|
**Configuration:**
|
|
681
|
+
|
|
608
682
|
- User permissions and roles are provided in the session object (`entSession`).
|
|
609
683
|
- Workflow rights are defined in your business logic and registered via decorators.
|
|
610
684
|
|
|
611
685
|
**Example:**
|
|
686
|
+
|
|
612
687
|
```typescript
|
|
613
688
|
import { Controller, Get, Post } from '@nestjs/common';
|
|
614
|
-
import {
|
|
689
|
+
import {
|
|
690
|
+
RequirePermission,
|
|
691
|
+
RequireAdmc,
|
|
692
|
+
Public,
|
|
693
|
+
CoreModule,
|
|
694
|
+
} from '@edifice.io/edifice-nestjs-core';
|
|
615
695
|
|
|
616
696
|
@Module({
|
|
617
697
|
imports: [CoreModule], // PermissionModule is included automatically
|
|
@@ -650,23 +730,28 @@ The `SessionModule` is automatically included when you import `CoreModule` in yo
|
|
|
650
730
|
It provides middleware, decorators, and helpers for managing user sessions in your Edifice backend.
|
|
651
731
|
|
|
652
732
|
**Features:**
|
|
733
|
+
|
|
653
734
|
- Middleware to validate and attach user sessions to each request.
|
|
654
735
|
- Session decorator (`@Session()`) to inject the session directly into your controller methods.
|
|
655
736
|
- Exposes session information on the raw Fastify request object (`request.raw.entSession`).
|
|
656
737
|
- Integrates with the ENT service via NATS for session validation and refresh.
|
|
657
738
|
|
|
658
739
|
**How it works:**
|
|
740
|
+
|
|
659
741
|
- The session middleware runs on every API request, validates the session via the ENT service, and attaches it to the request.
|
|
660
742
|
- You can access the session in your controllers using either the `@Session()` decorator or directly from the request object.
|
|
661
743
|
|
|
662
744
|
**Where and when:**
|
|
745
|
+
|
|
663
746
|
- The session system is initialized automatically at application startup by `CoreModule`.
|
|
664
747
|
- No manual configuration is needed; all dependencies are wired by the core module.
|
|
665
748
|
|
|
666
749
|
**Configuration:**
|
|
750
|
+
|
|
667
751
|
- Session validation uses the NATS connection provided by the core module.
|
|
668
752
|
|
|
669
753
|
**Example:**
|
|
754
|
+
|
|
670
755
|
```typescript
|
|
671
756
|
import { Controller, Get, Req } from '@nestjs/common';
|
|
672
757
|
import { CoreModule, Session } from '@edifice.io/edifice-nestjs-core';
|
|
@@ -705,21 +790,25 @@ The `TimelineModule` is automatically included when you import `CoreModule` in y
|
|
|
705
790
|
It provides services for registering notification templates and sending notifications to users via the Edifice timeline system.
|
|
706
791
|
|
|
707
792
|
**Features:**
|
|
793
|
+
|
|
708
794
|
- Register notification templates for your application.
|
|
709
795
|
- Send notifications to users (with push, mail, and preview options).
|
|
710
796
|
- Integrates with the ENT client and NATS for delivery.
|
|
711
797
|
- Supports localization via the I18n service.
|
|
712
798
|
|
|
713
799
|
**How it works:**
|
|
800
|
+
|
|
714
801
|
- The `TimelineService` is initialized and injected by the core module.
|
|
715
802
|
- You can register notification templates at startup or on demand.
|
|
716
803
|
- You can send notifications to users by calling the service methods.
|
|
717
804
|
|
|
718
805
|
**Where and when:**
|
|
806
|
+
|
|
719
807
|
- The timeline system is initialized automatically at application startup by `CoreModule`.
|
|
720
808
|
- No manual configuration is needed; all dependencies are wired by the core module.
|
|
721
809
|
|
|
722
810
|
**Configuration:**
|
|
811
|
+
|
|
723
812
|
- The application name (`APP_NAME`) must be set using environment variables.
|
|
724
813
|
- Notification templates can be registered at module initialization or dynamically.
|
|
725
814
|
|
|
@@ -792,7 +881,6 @@ export class MyNotificationService implements OnModuleInit {
|
|
|
792
881
|
constructor(private readonly timelineService: TimelineService) {}
|
|
793
882
|
|
|
794
883
|
async onModuleInit() {
|
|
795
|
-
|
|
796
884
|
const templates: RegisterNotificationRequestDTO[] = [
|
|
797
885
|
{
|
|
798
886
|
notificationName: 'MY_EVENT',
|
|
@@ -807,9 +895,13 @@ export class MyNotificationService implements OnModuleInit {
|
|
|
807
895
|
```
|
|
808
896
|
|
|
809
897
|
**Sending a notification:**
|
|
898
|
+
|
|
810
899
|
```typescript
|
|
811
900
|
import { TimelineService } from '@edifice.io/edifice-nestjs-core';
|
|
812
|
-
import {
|
|
901
|
+
import {
|
|
902
|
+
SessionDto,
|
|
903
|
+
SendNotificationRequestDTO,
|
|
904
|
+
} from '@edifice.io/edifice-ent-client';
|
|
813
905
|
|
|
814
906
|
@Injectable()
|
|
815
907
|
export class MyService {
|
|
@@ -832,7 +924,8 @@ export class MyService {
|
|
|
832
924
|
}
|
|
833
925
|
```
|
|
834
926
|
|
|
835
|
-
**Note:**
|
|
927
|
+
**Note:**
|
|
928
|
+
|
|
836
929
|
- You do not need to configure the timeline system manually; it is ready to use when you import `CoreModule`.
|
|
837
930
|
- Notifications are localized using the I18n service and delivered via NATS and the ENT client.
|
|
838
931
|
|
|
@@ -842,16 +935,19 @@ The Swagger module is automatically enabled when you import `CoreModule` in your
|
|
|
842
935
|
It provides an interactive OpenAPI documentation for your API, available at `/openapi`.
|
|
843
936
|
|
|
844
937
|
**Features:**
|
|
938
|
+
|
|
845
939
|
- Auto-generates OpenAPI documentation from your controllers and DTOs.
|
|
846
940
|
- Serves the Swagger UI at `/openapi` by default.
|
|
847
941
|
- Supports custom title, description, version, and server URL via environment variables.
|
|
848
942
|
|
|
849
943
|
**How it works:**
|
|
944
|
+
|
|
850
945
|
- On application startup, Swagger is configured and started automatically if `ENABLE_SWAGGER=true` (default).
|
|
851
946
|
- The configuration is read from environment variables and injected via `ConfigService`.
|
|
852
947
|
|
|
853
948
|
**Configuration:**
|
|
854
949
|
Set the following environment variables to customize Swagger:
|
|
950
|
+
|
|
855
951
|
```env
|
|
856
952
|
ENABLE_SWAGGER=true
|
|
857
953
|
SWAGGER_SERVER_URL=https://api.example.com
|
|
@@ -879,9 +975,7 @@ import { Module } from '@nestjs/common';
|
|
|
879
975
|
import { CoreModule } from '@edifice.io/edifice-nestjs-core';
|
|
880
976
|
|
|
881
977
|
@Module({
|
|
882
|
-
imports: [
|
|
883
|
-
CoreModule,
|
|
884
|
-
],
|
|
978
|
+
imports: [CoreModule],
|
|
885
979
|
})
|
|
886
980
|
export class AppModule {}
|
|
887
981
|
```
|
|
@@ -902,12 +996,14 @@ Each tool is available as a binary when you install `@edifice.io/edifice-nestjs-
|
|
|
902
996
|
**Purpose:**
|
|
903
997
|
Generate MikroORM entity files from your PostgreSQL database schema.
|
|
904
998
|
|
|
905
|
-
**Usage:**
|
|
999
|
+
**Usage:**
|
|
1000
|
+
|
|
906
1001
|
```bash
|
|
907
1002
|
pnpm edifice-generate-entities --schema <schema-name> [options]
|
|
908
1003
|
```
|
|
909
1004
|
|
|
910
1005
|
**Arguments:**
|
|
1006
|
+
|
|
911
1007
|
- `--schema` (required): Name of the database schema to use for entity generation.
|
|
912
1008
|
- `--path`: Target directory for generated entities (default: `./src/entities`).
|
|
913
1009
|
- `--temp-dir`: Temporary directory for initial generation (default: `./src/temp/entities`).
|
|
@@ -915,6 +1011,7 @@ pnpm edifice-generate-entities --schema <schema-name> [options]
|
|
|
915
1011
|
- `--keep-temp`: Keep temporary directory after generation (`true` or `false`, default: `false`).
|
|
916
1012
|
|
|
917
1013
|
**Examples:**
|
|
1014
|
+
|
|
918
1015
|
```bash
|
|
919
1016
|
pnpm edifice-generate-entities --schema community
|
|
920
1017
|
pnpm edifice-generate-entities --schema community --temp-dir ./src/temp --path ./src/entities
|
|
@@ -929,15 +1026,18 @@ pnpm edifice-generate-entities --schema community --keep-temp true
|
|
|
929
1026
|
**Purpose:**
|
|
930
1027
|
Generate a build metadata file containing build date, git commit hash, and branch name.
|
|
931
1028
|
|
|
932
|
-
**Usage:**
|
|
1029
|
+
**Usage:**
|
|
1030
|
+
|
|
933
1031
|
```bash
|
|
934
1032
|
pnpm edifice-generate-metadata <target-file-path>
|
|
935
1033
|
```
|
|
936
1034
|
|
|
937
1035
|
**Arguments:**
|
|
1036
|
+
|
|
938
1037
|
- `<target-file-path>` (required): Path to the file where metadata will be written.
|
|
939
1038
|
|
|
940
1039
|
**Example:**
|
|
1040
|
+
|
|
941
1041
|
```bash
|
|
942
1042
|
pnpm edifice-generate-metadata ./dist/metadata.txt
|
|
943
1043
|
```
|
|
@@ -949,7 +1049,8 @@ pnpm edifice-generate-metadata ./dist/metadata.txt
|
|
|
949
1049
|
**Purpose:**
|
|
950
1050
|
Synchronize DTO TypeScript definitions to K6-compatible types for API testing.
|
|
951
1051
|
|
|
952
|
-
**Usage:**
|
|
1052
|
+
**Usage:**
|
|
1053
|
+
|
|
953
1054
|
```bash
|
|
954
1055
|
pnpm edifice-k6-sync-dto
|
|
955
1056
|
```
|
|
@@ -959,11 +1060,13 @@ This script uses configuration constants for DTOs and output paths.
|
|
|
959
1060
|
You can adjust the paths in the script or via environment variables if supported.
|
|
960
1061
|
|
|
961
1062
|
**Example:**
|
|
1063
|
+
|
|
962
1064
|
```bash
|
|
963
1065
|
pnpm edifice-k6-sync-dto
|
|
964
1066
|
```
|
|
965
1067
|
|
|
966
|
-
**Details:**
|
|
1068
|
+
**Details:**
|
|
1069
|
+
|
|
967
1070
|
- Parses DTOs from `client/rest/src/dtos`.
|
|
968
1071
|
- Generates K6-compatible types in `types/generated`.
|
|
969
1072
|
- Excludes files named `index.ts` by default.
|
|
@@ -1005,7 +1108,6 @@ pnpm lint
|
|
|
1005
1108
|
|
|
1006
1109
|
- [@edifice.io/edifice-ent-client](https://github.com/edificeio/entcore) - Edifice ENT client library
|
|
1007
1110
|
|
|
1008
|
-
|
|
1009
1111
|
## 🐛 Issues
|
|
1010
1112
|
|
|
1011
1113
|
Report issues on [GitHub Issues](https://github.com/edificeio/edifice-nestjs-core/issues).
|