@flusys/nestjs-shared 7.1.0 → 8.0.0
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/classes/api-controller.class.d.ts +4 -4
- package/classes/api-service.class.d.ts +7 -7
- package/classes/disabled-event-bus.class.d.ts +1 -1
- package/classes/domain-event.publisher.d.ts +1 -1
- package/classes/event-bus.registry.d.ts +1 -1
- package/classes/event-transports/event-transport.registry.d.ts +1 -1
- package/classes/event-transports/index.d.ts +2 -2
- package/classes/event-transports/kafka-transport.optional.d.ts +1 -1
- package/classes/event-transports/memory-transport.d.ts +1 -1
- package/classes/event-transports/rabbitmq-transport.optional.d.ts +1 -1
- package/classes/hybrid-event-bus.class.d.ts +1 -1
- package/classes/index.d.ts +11 -11
- package/constants/index.d.ts +2 -2
- package/decorators/api-response.decorator.d.ts +1 -1
- package/decorators/current-user.decorator.d.ts +1 -1
- package/decorators/index.d.ts +6 -6
- package/decorators/require-permission.decorator.d.ts +1 -1
- package/dtos/filter-and-pagination.dto.d.ts +1 -1
- package/dtos/index.d.ts +6 -6
- package/entities/index.d.ts +3 -3
- package/enums/index.d.ts +3 -3
- package/exceptions/index.d.ts +2 -2
- package/fesm/470.js +2713 -0
- package/fesm/509.js +793 -0
- package/fesm/667.js +606 -0
- package/fesm/67.js +808 -0
- package/fesm/720.js +914 -0
- package/{cjs/classes/event-transports/rabbitmq-transport.optional.js → fesm/chunks/123.js} +78 -55
- package/fesm/{classes/event-transports/kafka-transport.optional.js → chunks/37.js} +74 -41
- package/fesm/classes/index.js +62 -12
- package/fesm/constants/index.js +445 -17
- package/fesm/decorators/index.js +341 -6
- package/fesm/dtos/index.js +23 -6
- package/fesm/entities/index.js +336 -3
- package/fesm/enums/index.js +57 -3
- package/fesm/exceptions/index.js +280 -2
- package/fesm/guards/index.js +1003 -3
- package/fesm/index.js +1524 -14
- package/fesm/interceptors/index.js +924 -5
- package/fesm/interfaces/index.js +57 -11
- package/fesm/middlewares/index.js +33 -1
- package/fesm/modules/index.js +432 -9
- package/fesm/runtime.js +134 -0
- package/fesm/utils/index.js +1045 -8
- package/filters/global-exception.filter.d.ts +1 -1
- package/filters/index.d.ts +1 -1
- package/guards/index.d.ts +3 -3
- package/guards/jwt-auth.guard.d.ts +1 -1
- package/guards/optional-jwt-auth.guard.d.ts +1 -1
- package/guards/permission.guard.d.ts +2 -2
- package/index.d.ts +14 -14
- package/interceptors/delete-empty-id-from-body.interceptor.d.ts +1 -1
- package/interceptors/idempotency.interceptor.d.ts +2 -2
- package/interceptors/index.d.ts +5 -5
- package/interceptors/response-meta.interceptor.d.ts +1 -1
- package/interceptors/set-user-field-on-body.interceptor.d.ts +1 -1
- package/interceptors/slug.interceptor.d.ts +2 -2
- package/interfaces/ai-assistant-adapter.interface.d.ts +1 -1
- package/interfaces/api.interface.d.ts +2 -2
- package/interfaces/datasource.interface.d.ts +1 -1
- package/interfaces/event-manager-adapter.interface.d.ts +2 -2
- package/interfaces/index.d.ts +11 -11
- package/interfaces/module-config.interface.d.ts +1 -1
- package/interfaces/notification-adapter.interface.d.ts +1 -1
- package/middlewares/index.d.ts +1 -1
- package/middlewares/logger.middleware.d.ts +2 -2
- package/modules/cache/cache.module.d.ts +1 -1
- package/modules/datasource/index.d.ts +1 -1
- package/modules/datasource/multi-tenant-datasource.service.d.ts +4 -4
- package/modules/event-bus/event-bus.explorer.d.ts +2 -2
- package/modules/event-bus/event-bus.module.d.ts +2 -2
- package/modules/event-bus/module-events.provider.d.ts +1 -1
- package/modules/index.d.ts +9 -9
- package/modules/shared-permission-cache/shared-permission-cache.service.d.ts +3 -3
- package/modules/utils/utils.service.d.ts +1 -1
- package/package.json +30 -44
- package/utils/index.d.ts +8 -8
- package/utils/permission-cache-key.util.d.ts +1 -1
- package/utils/query-helpers.util.d.ts +2 -2
- package/utils/request.util.d.ts +1 -1
- package/cjs/classes/api-controller.class.js +0 -728
- package/cjs/classes/api-controller.class.spec.js +0 -684
- package/cjs/classes/api-service.class.js +0 -631
- package/cjs/classes/api-service.class.spec.js +0 -1137
- package/cjs/classes/disabled-event-bus.class.js +0 -15
- package/cjs/classes/disabled-event-bus.class.spec.js +0 -40
- package/cjs/classes/domain-event.publisher.js +0 -76
- package/cjs/classes/domain-event.publisher.spec.js +0 -234
- package/cjs/classes/event-bus.registry.js +0 -68
- package/cjs/classes/event-bus.registry.spec.js +0 -141
- package/cjs/classes/event-transports/event-transport.registry.js +0 -41
- package/cjs/classes/event-transports/event-transport.registry.spec.js +0 -31
- package/cjs/classes/event-transports/index.js +0 -23
- package/cjs/classes/event-transports/kafka-transport.optional.js +0 -151
- package/cjs/classes/event-transports/kafka-transport.optional.spec.js +0 -198
- package/cjs/classes/event-transports/memory-transport.js +0 -53
- package/cjs/classes/event-transports/memory-transport.spec.js +0 -57
- package/cjs/classes/event-transports/rabbitmq-transport.optional.spec.js +0 -255
- package/cjs/classes/handle-custome-db.js +0 -37
- package/cjs/classes/handle-custome-db.spec.js +0 -82
- package/cjs/classes/hybrid-cache.class.js +0 -96
- package/cjs/classes/hybrid-cache.class.spec.js +0 -168
- package/cjs/classes/hybrid-event-bus.class.js +0 -281
- package/cjs/classes/hybrid-event-bus.class.spec.js +0 -218
- package/cjs/classes/index.js +0 -28
- package/cjs/classes/winston.logger.class.js +0 -274
- package/cjs/classes/winston.logger.class.spec.js +0 -330
- package/cjs/constants/index.js +0 -88
- package/cjs/constants/message-keys.js +0 -68
- package/cjs/constants/permissions.js +0 -307
- package/cjs/decorators/api-response.decorator.js +0 -52
- package/cjs/decorators/api-response.decorator.spec.js +0 -126
- package/cjs/decorators/current-user.decorator.js +0 -16
- package/cjs/decorators/current-user.decorator.spec.js +0 -74
- package/cjs/decorators/index.js +0 -23
- package/cjs/decorators/log-action.decorator.js +0 -149
- package/cjs/decorators/log-action.decorator.spec.js +0 -353
- package/cjs/decorators/on-domain-event.decorator.js +0 -13
- package/cjs/decorators/on-domain-event.decorator.spec.js +0 -50
- package/cjs/decorators/public.decorator.js +0 -13
- package/cjs/decorators/public.decorator.spec.js +0 -50
- package/cjs/decorators/require-permission.decorator.js +0 -32
- package/cjs/decorators/require-permission.decorator.spec.js +0 -147
- package/cjs/dtos/delete.dto.js +0 -92
- package/cjs/dtos/filter-and-pagination.dto.js +0 -164
- package/cjs/dtos/get-by-ids.dto.js +0 -65
- package/cjs/dtos/identity-response.dto.js +0 -108
- package/cjs/dtos/index.js +0 -23
- package/cjs/dtos/pagination.dto.js +0 -67
- package/cjs/dtos/response-payload.dto.js +0 -369
- package/cjs/entities/identity.js +0 -100
- package/cjs/entities/index.js +0 -20
- package/cjs/entities/raw-type.js +0 -4
- package/cjs/entities/user-root.js +0 -189
- package/cjs/enums/index.js +0 -20
- package/cjs/enums/notification-type.enum.js +0 -17
- package/cjs/enums/participant-status.enum.js +0 -17
- package/cjs/enums/recurrence-type.enum.js +0 -18
- package/cjs/exceptions/base-app.exception.js +0 -151
- package/cjs/exceptions/base-app.exception.spec.js +0 -157
- package/cjs/exceptions/index.js +0 -19
- package/cjs/exceptions/permission.exception.js +0 -56
- package/cjs/exceptions/permission.exception.spec.js +0 -82
- package/cjs/filters/global-exception.filter.js +0 -279
- package/cjs/filters/global-exception.filter.spec.js +0 -440
- package/cjs/filters/index.js +0 -18
- package/cjs/guards/index.js +0 -20
- package/cjs/guards/jwt-auth.guard.js +0 -75
- package/cjs/guards/jwt-auth.guard.spec.js +0 -75
- package/cjs/guards/optional-jwt-auth.guard.js +0 -67
- package/cjs/guards/optional-jwt-auth.guard.spec.js +0 -55
- package/cjs/guards/permission.guard.js +0 -179
- package/cjs/guards/permission.guard.spec.js +0 -373
- package/cjs/index.js +0 -31
- package/cjs/interceptors/delete-empty-id-from-body.interceptor.js +0 -40
- package/cjs/interceptors/delete-empty-id-from-body.interceptor.spec.js +0 -107
- package/cjs/interceptors/idempotency.interceptor.js +0 -96
- package/cjs/interceptors/idempotency.interceptor.spec.js +0 -116
- package/cjs/interceptors/index.js +0 -22
- package/cjs/interceptors/response-meta.interceptor.js +0 -47
- package/cjs/interceptors/response-meta.interceptor.spec.js +0 -89
- package/cjs/interceptors/set-user-field-on-body.interceptor.js +0 -60
- package/cjs/interceptors/set-user-field-on-body.interceptor.spec.js +0 -128
- package/cjs/interceptors/slug.interceptor.js +0 -75
- package/cjs/interceptors/slug.interceptor.spec.js +0 -110
- package/cjs/interfaces/ai-assistant-adapter.interface.js +0 -24
- package/cjs/interfaces/api.interface.js +0 -4
- package/cjs/interfaces/datasource.interface.js +0 -4
- package/cjs/interfaces/event-bus.interface.js +0 -4
- package/cjs/interfaces/event-manager-adapter.interface.js +0 -11
- package/cjs/interfaces/identity.interface.js +0 -4
- package/cjs/interfaces/index.js +0 -28
- package/cjs/interfaces/logged-user-info.interface.js +0 -6
- package/cjs/interfaces/module-config.interface.js +0 -4
- package/cjs/interfaces/notification-adapter.interface.js +0 -11
- package/cjs/interfaces/permission-sync-adapter.interface.js +0 -11
- package/cjs/interfaces/permission.interface.js +0 -4
- package/cjs/middlewares/index.js +0 -18
- package/cjs/middlewares/logger.middleware.js +0 -264
- package/cjs/middlewares/logger.middleware.spec.js +0 -462
- package/cjs/modules/cache/cache.module.js +0 -39
- package/cjs/modules/cache/cache.module.spec.js +0 -48
- package/cjs/modules/datasource/index.js +0 -18
- package/cjs/modules/datasource/multi-tenant-datasource.service.js +0 -222
- package/cjs/modules/datasource/multi-tenant-datasource.service.spec.js +0 -381
- package/cjs/modules/event-bus/event-bus.explorer.js +0 -124
- package/cjs/modules/event-bus/event-bus.explorer.spec.js +0 -189
- package/cjs/modules/event-bus/event-bus.integration.spec.js +0 -253
- package/cjs/modules/event-bus/event-bus.module.js +0 -94
- package/cjs/modules/event-bus/event-bus.module.spec.js +0 -149
- package/cjs/modules/event-bus/module-events.provider.js +0 -39
- package/cjs/modules/event-bus/module-events.provider.spec.js +0 -56
- package/cjs/modules/index.js +0 -26
- package/cjs/modules/shared-permission-cache/shared-permission-cache.module.js +0 -32
- package/cjs/modules/shared-permission-cache/shared-permission-cache.service.js +0 -101
- package/cjs/modules/shared-permission-cache/shared-permission-cache.service.spec.js +0 -165
- package/cjs/modules/utils/utils.module.js +0 -32
- package/cjs/modules/utils/utils.service.js +0 -76
- package/cjs/modules/utils/utils.service.spec.js +0 -169
- package/cjs/utils/date-time.util.js +0 -94
- package/cjs/utils/date-time.util.spec.js +0 -84
- package/cjs/utils/event-pattern.util.js +0 -103
- package/cjs/utils/event-pattern.util.spec.js +0 -251
- package/cjs/utils/html-sanitizer.util.js +0 -64
- package/cjs/utils/html-sanitizer.util.spec.js +0 -76
- package/cjs/utils/index.js +0 -25
- package/cjs/utils/optional-module.util.js +0 -35
- package/cjs/utils/optional-module.util.spec.js +0 -14
- package/cjs/utils/permission-cache-key.util.js +0 -31
- package/cjs/utils/permission-cache-key.util.spec.js +0 -88
- package/cjs/utils/query-helpers.util.js +0 -60
- package/cjs/utils/query-helpers.util.spec.js +0 -209
- package/cjs/utils/request.util.js +0 -96
- package/cjs/utils/request.util.spec.js +0 -249
- package/cjs/utils/string.util.js +0 -63
- package/cjs/utils/string.util.spec.js +0 -63
- package/fesm/classes/api-controller.class.js +0 -718
- package/fesm/classes/api-controller.class.spec.js +0 -680
- package/fesm/classes/api-service.class.js +0 -621
- package/fesm/classes/api-service.class.spec.js +0 -1133
- package/fesm/classes/disabled-event-bus.class.js +0 -11
- package/fesm/classes/disabled-event-bus.class.spec.js +0 -36
- package/fesm/classes/domain-event.publisher.js +0 -63
- package/fesm/classes/domain-event.publisher.spec.js +0 -230
- package/fesm/classes/event-bus.registry.js +0 -64
- package/fesm/classes/event-bus.registry.spec.js +0 -137
- package/fesm/classes/event-transports/event-transport.registry.js +0 -35
- package/fesm/classes/event-transports/event-transport.registry.spec.js +0 -27
- package/fesm/classes/event-transports/index.js +0 -6
- package/fesm/classes/event-transports/kafka-transport.optional.spec.js +0 -194
- package/fesm/classes/event-transports/memory-transport.js +0 -49
- package/fesm/classes/event-transports/memory-transport.spec.js +0 -53
- package/fesm/classes/event-transports/rabbitmq-transport.optional.js +0 -174
- package/fesm/classes/event-transports/rabbitmq-transport.optional.spec.js +0 -251
- package/fesm/classes/handle-custome-db.js +0 -19
- package/fesm/classes/handle-custome-db.spec.js +0 -78
- package/fesm/classes/hybrid-cache.class.js +0 -81
- package/fesm/classes/hybrid-cache.class.spec.js +0 -164
- package/fesm/classes/hybrid-event-bus.class.js +0 -237
- package/fesm/classes/hybrid-event-bus.class.spec.js +0 -214
- package/fesm/classes/winston.logger.class.js +0 -228
- package/fesm/classes/winston.logger.class.spec.js +0 -327
- package/fesm/constants/message-keys.js +0 -49
- package/fesm/constants/permissions.js +0 -215
- package/fesm/decorators/api-response.decorator.js +0 -42
- package/fesm/decorators/api-response.decorator.spec.js +0 -122
- package/fesm/decorators/current-user.decorator.js +0 -18
- package/fesm/decorators/current-user.decorator.spec.js +0 -73
- package/fesm/decorators/log-action.decorator.js +0 -139
- package/fesm/decorators/log-action.decorator.spec.js +0 -349
- package/fesm/decorators/on-domain-event.decorator.js +0 -10
- package/fesm/decorators/on-domain-event.decorator.spec.js +0 -46
- package/fesm/decorators/public.decorator.js +0 -20
- package/fesm/decorators/public.decorator.spec.js +0 -46
- package/fesm/decorators/require-permission.decorator.js +0 -27
- package/fesm/decorators/require-permission.decorator.spec.js +0 -143
- package/fesm/dtos/delete.dto.js +0 -82
- package/fesm/dtos/filter-and-pagination.dto.js +0 -148
- package/fesm/dtos/get-by-ids.dto.js +0 -55
- package/fesm/dtos/identity-response.dto.js +0 -98
- package/fesm/dtos/pagination.dto.js +0 -57
- package/fesm/dtos/response-payload.dto.js +0 -336
- package/fesm/entities/identity.js +0 -90
- package/fesm/entities/raw-type.js +0 -1
- package/fesm/entities/user-root.js +0 -179
- package/fesm/enums/notification-type.enum.js +0 -7
- package/fesm/enums/participant-status.enum.js +0 -7
- package/fesm/enums/recurrence-type.enum.js +0 -8
- package/fesm/exceptions/base-app.exception.js +0 -115
- package/fesm/exceptions/base-app.exception.spec.js +0 -153
- package/fesm/exceptions/permission.exception.js +0 -35
- package/fesm/exceptions/permission.exception.spec.js +0 -78
- package/fesm/filters/global-exception.filter.js +0 -269
- package/fesm/filters/global-exception.filter.spec.js +0 -436
- package/fesm/filters/index.js +0 -1
- package/fesm/guards/jwt-auth.guard.js +0 -65
- package/fesm/guards/jwt-auth.guard.spec.js +0 -71
- package/fesm/guards/optional-jwt-auth.guard.js +0 -57
- package/fesm/guards/optional-jwt-auth.guard.spec.js +0 -51
- package/fesm/guards/permission.guard.js +0 -169
- package/fesm/guards/permission.guard.spec.js +0 -369
- package/fesm/interceptors/delete-empty-id-from-body.interceptor.js +0 -30
- package/fesm/interceptors/delete-empty-id-from-body.interceptor.spec.js +0 -103
- package/fesm/interceptors/idempotency.interceptor.js +0 -86
- package/fesm/interceptors/idempotency.interceptor.spec.js +0 -112
- package/fesm/interceptors/response-meta.interceptor.js +0 -37
- package/fesm/interceptors/response-meta.interceptor.spec.js +0 -85
- package/fesm/interceptors/set-user-field-on-body.interceptor.js +0 -39
- package/fesm/interceptors/set-user-field-on-body.interceptor.spec.js +0 -124
- package/fesm/interceptors/slug.interceptor.js +0 -65
- package/fesm/interceptors/slug.interceptor.spec.js +0 -106
- package/fesm/interfaces/ai-assistant-adapter.interface.js +0 -3
- package/fesm/interfaces/api.interface.js +0 -1
- package/fesm/interfaces/datasource.interface.js +0 -1
- package/fesm/interfaces/event-bus.interface.js +0 -1
- package/fesm/interfaces/event-manager-adapter.interface.js +0 -1
- package/fesm/interfaces/identity.interface.js +0 -1
- package/fesm/interfaces/logged-user-info.interface.js +0 -3
- package/fesm/interfaces/module-config.interface.js +0 -5
- package/fesm/interfaces/notification-adapter.interface.js +0 -1
- package/fesm/interfaces/permission-sync-adapter.interface.js +0 -1
- package/fesm/interfaces/permission.interface.js +0 -1
- package/fesm/middlewares/logger.middleware.js +0 -235
- package/fesm/middlewares/logger.middleware.spec.js +0 -459
- package/fesm/modules/cache/cache.module.js +0 -29
- package/fesm/modules/cache/cache.module.spec.js +0 -44
- package/fesm/modules/datasource/index.js +0 -1
- package/fesm/modules/datasource/multi-tenant-datasource.service.js +0 -212
- package/fesm/modules/datasource/multi-tenant-datasource.service.spec.js +0 -377
- package/fesm/modules/event-bus/event-bus.explorer.js +0 -114
- package/fesm/modules/event-bus/event-bus.explorer.spec.js +0 -185
- package/fesm/modules/event-bus/event-bus.integration.spec.js +0 -249
- package/fesm/modules/event-bus/event-bus.module.js +0 -84
- package/fesm/modules/event-bus/event-bus.module.spec.js +0 -145
- package/fesm/modules/event-bus/module-events.provider.js +0 -26
- package/fesm/modules/event-bus/module-events.provider.spec.js +0 -52
- package/fesm/modules/shared-permission-cache/shared-permission-cache.module.js +0 -22
- package/fesm/modules/shared-permission-cache/shared-permission-cache.service.js +0 -91
- package/fesm/modules/shared-permission-cache/shared-permission-cache.service.spec.js +0 -161
- package/fesm/modules/utils/utils.module.js +0 -22
- package/fesm/modules/utils/utils.service.js +0 -66
- package/fesm/modules/utils/utils.service.spec.js +0 -165
- package/fesm/utils/date-time.util.js +0 -70
- package/fesm/utils/date-time.util.spec.js +0 -80
- package/fesm/utils/event-pattern.util.js +0 -91
- package/fesm/utils/event-pattern.util.spec.js +0 -247
- package/fesm/utils/html-sanitizer.util.js +0 -69
- package/fesm/utils/html-sanitizer.util.spec.js +0 -72
- package/fesm/utils/optional-module.util.js +0 -25
- package/fesm/utils/optional-module.util.spec.js +0 -10
- package/fesm/utils/permission-cache-key.util.js +0 -10
- package/fesm/utils/permission-cache-key.util.spec.js +0 -84
- package/fesm/utils/query-helpers.util.js +0 -85
- package/fesm/utils/query-helpers.util.spec.js +0 -205
- package/fesm/utils/request.util.js +0 -81
- package/fesm/utils/request.util.spec.js +0 -245
- package/fesm/utils/string.util.js +0 -71
- package/fesm/utils/string.util.spec.js +0 -59
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Stands in for HybridEventBus when the subsystem is switched off.
|
|
3
|
-
*
|
|
4
|
-
* Injecting `EVENT_BUS_INSTANCE` keeps working, so turning events off cannot
|
|
5
|
-
* break a provider's dependencies, but nothing here can ever open a broker
|
|
6
|
-
* connection or run a handler.
|
|
7
|
-
*/ export class DisabledEventBus {
|
|
8
|
-
async publish(_event) {}
|
|
9
|
-
async subscribe(_pattern, _handler) {}
|
|
10
|
-
async close() {}
|
|
11
|
-
}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { DisabledEventBus } from './disabled-event-bus.class';
|
|
2
|
-
describe('DisabledEventBus', ()=>{
|
|
3
|
-
const event = {
|
|
4
|
-
id: 'e1',
|
|
5
|
-
name: 'auth.session.logged-in',
|
|
6
|
-
module: 'auth',
|
|
7
|
-
entity: 'session',
|
|
8
|
-
action: 'logged-in',
|
|
9
|
-
payload: {
|
|
10
|
-
ids: [
|
|
11
|
-
'u1'
|
|
12
|
-
]
|
|
13
|
-
},
|
|
14
|
-
actor: {
|
|
15
|
-
userId: 'u1',
|
|
16
|
-
companyId: null,
|
|
17
|
-
tenantId: null,
|
|
18
|
-
requestId: null
|
|
19
|
-
},
|
|
20
|
-
occurredAt: new Date().toISOString(),
|
|
21
|
-
version: 1
|
|
22
|
-
};
|
|
23
|
-
it('should never deliver an event to a subscriber', async ()=>{
|
|
24
|
-
const bus = new DisabledEventBus();
|
|
25
|
-
const handler = jest.fn();
|
|
26
|
-
await bus.subscribe('**', handler);
|
|
27
|
-
await bus.publish(event);
|
|
28
|
-
expect(handler).not.toHaveBeenCalled();
|
|
29
|
-
});
|
|
30
|
-
it('should resolve without throwing so callers need no special case', async ()=>{
|
|
31
|
-
const bus = new DisabledEventBus();
|
|
32
|
-
await expect(bus.publish(event)).resolves.toBeUndefined();
|
|
33
|
-
await expect(bus.subscribe('**', jest.fn())).resolves.toBeUndefined();
|
|
34
|
-
await expect(bus.close()).resolves.toBeUndefined();
|
|
35
|
-
});
|
|
36
|
-
});
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import { randomUUID } from 'crypto';
|
|
2
|
-
import { getCompanyId, getRequestId, getTenantId } from '../middlewares/logger.middleware';
|
|
3
|
-
import { sanitizeEventPayload } from '../utils/event-pattern.util';
|
|
4
|
-
import { EventBusRegistry } from './event-bus.registry';
|
|
5
|
-
export const DOMAIN_EVENT_VERSION = 1;
|
|
6
|
-
export function buildDomainEvent(input) {
|
|
7
|
-
const rows = input.data === undefined ? [] : toArray(input.data);
|
|
8
|
-
const ids = input.ids ?? collectIds(rows);
|
|
9
|
-
return {
|
|
10
|
-
id: randomUUID(),
|
|
11
|
-
name: `${input.module}.${input.entity}.${input.action}`,
|
|
12
|
-
module: input.module,
|
|
13
|
-
entity: input.entity,
|
|
14
|
-
action: input.action,
|
|
15
|
-
payload: {
|
|
16
|
-
ids,
|
|
17
|
-
...rows.length && EventBusRegistry.shouldIncludePayload(input.module) ? {
|
|
18
|
-
data: sanitizeEventPayload(rows)
|
|
19
|
-
} : {},
|
|
20
|
-
...input.metadata ? {
|
|
21
|
-
metadata: sanitizeEventPayload(input.metadata)
|
|
22
|
-
} : {}
|
|
23
|
-
},
|
|
24
|
-
actor: {
|
|
25
|
-
userId: input.user?.id ?? null,
|
|
26
|
-
companyId: input.user?.companyId ?? getCompanyId() ?? null,
|
|
27
|
-
tenantId: getTenantId() ?? null,
|
|
28
|
-
requestId: getRequestId() ?? null
|
|
29
|
-
},
|
|
30
|
-
occurredAt: new Date().toISOString(),
|
|
31
|
-
version: DOMAIN_EVENT_VERSION
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* Publishes a domain event for an operation that is not plain CRUD - a form
|
|
36
|
-
* submission, a login, a file upload. Honours the publishing module's own
|
|
37
|
-
* `events` config and never throws, so a broker outage cannot break the caller.
|
|
38
|
-
*
|
|
39
|
-
* Supplying `eventBus` chooses which bus to publish on; it never overrides the
|
|
40
|
-
* module's on/off switch, otherwise turning a module's events off would leave
|
|
41
|
-
* every service holding its own bus still publishing.
|
|
42
|
-
*/ export async function publishDomainEvent(input) {
|
|
43
|
-
const bus = input.eventBus ?? EventBusRegistry.getBus();
|
|
44
|
-
if (!bus) return;
|
|
45
|
-
if (!EventBusRegistry.isEnabled(input.module, input.entity, input.action)) return;
|
|
46
|
-
try {
|
|
47
|
-
await bus.publish(buildDomainEvent(input));
|
|
48
|
-
} catch {
|
|
49
|
-
// Events must never break the operation that produced them
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
function toArray(value) {
|
|
53
|
-
return Array.isArray(value) ? value : [
|
|
54
|
-
value
|
|
55
|
-
];
|
|
56
|
-
}
|
|
57
|
-
function collectIds(rows) {
|
|
58
|
-
return rows.reduce((ids, row)=>{
|
|
59
|
-
const id = row?.id;
|
|
60
|
-
if (id) ids.push(id);
|
|
61
|
-
return ids;
|
|
62
|
-
}, []);
|
|
63
|
-
}
|
|
@@ -1,230 +0,0 @@
|
|
|
1
|
-
import { buildDomainEvent, publishDomainEvent } from './domain-event.publisher';
|
|
2
|
-
import { EventBusRegistry } from './event-bus.registry';
|
|
3
|
-
const user = {
|
|
4
|
-
id: 'user-1',
|
|
5
|
-
email: 'ada@example.com',
|
|
6
|
-
companyId: 'company-1'
|
|
7
|
-
};
|
|
8
|
-
describe('buildDomainEvent', ()=>{
|
|
9
|
-
beforeEach(()=>{
|
|
10
|
-
EventBusRegistry.reset();
|
|
11
|
-
EventBusRegistry.configureModule('form-builder', {
|
|
12
|
-
enabled: true
|
|
13
|
-
});
|
|
14
|
-
});
|
|
15
|
-
afterEach(()=>{
|
|
16
|
-
EventBusRegistry.reset();
|
|
17
|
-
});
|
|
18
|
-
it('should name the event <module>.<entity>.<action>', ()=>{
|
|
19
|
-
const event = buildDomainEvent({
|
|
20
|
-
module: 'form-builder',
|
|
21
|
-
entity: 'form_result',
|
|
22
|
-
action: 'submitted'
|
|
23
|
-
});
|
|
24
|
-
expect(event.name).toBe('form-builder.form_result.submitted');
|
|
25
|
-
expect(event.version).toBe(1);
|
|
26
|
-
expect(event.id).toEqual(expect.any(String));
|
|
27
|
-
});
|
|
28
|
-
it('should derive ids from the supplied rows when none are given', ()=>{
|
|
29
|
-
const event = buildDomainEvent({
|
|
30
|
-
module: 'form-builder',
|
|
31
|
-
entity: 'form_result',
|
|
32
|
-
action: 'submitted',
|
|
33
|
-
data: [
|
|
34
|
-
{
|
|
35
|
-
id: 'a'
|
|
36
|
-
},
|
|
37
|
-
{
|
|
38
|
-
id: 'b'
|
|
39
|
-
}
|
|
40
|
-
]
|
|
41
|
-
});
|
|
42
|
-
expect(event.payload.ids).toEqual([
|
|
43
|
-
'a',
|
|
44
|
-
'b'
|
|
45
|
-
]);
|
|
46
|
-
});
|
|
47
|
-
it('should prefer explicitly supplied ids', ()=>{
|
|
48
|
-
const event = buildDomainEvent({
|
|
49
|
-
module: 'form-builder',
|
|
50
|
-
entity: 'form_result',
|
|
51
|
-
action: 'submitted',
|
|
52
|
-
ids: [
|
|
53
|
-
'explicit'
|
|
54
|
-
],
|
|
55
|
-
data: {
|
|
56
|
-
id: 'ignored'
|
|
57
|
-
}
|
|
58
|
-
});
|
|
59
|
-
expect(event.payload.ids).toEqual([
|
|
60
|
-
'explicit'
|
|
61
|
-
]);
|
|
62
|
-
});
|
|
63
|
-
it('should attach metadata regardless of the includePayload setting', ()=>{
|
|
64
|
-
EventBusRegistry.configureModule('form-builder', {
|
|
65
|
-
enabled: true,
|
|
66
|
-
includePayload: false
|
|
67
|
-
});
|
|
68
|
-
const event = buildDomainEvent({
|
|
69
|
-
module: 'form-builder',
|
|
70
|
-
entity: 'form_result',
|
|
71
|
-
action: 'submitted',
|
|
72
|
-
data: {
|
|
73
|
-
id: 'a',
|
|
74
|
-
answer: 'secret-ish'
|
|
75
|
-
},
|
|
76
|
-
metadata: {
|
|
77
|
-
formId: 'form-1',
|
|
78
|
-
isDraft: false
|
|
79
|
-
}
|
|
80
|
-
});
|
|
81
|
-
expect(event.payload.data).toBeUndefined();
|
|
82
|
-
expect(event.payload.metadata).toEqual({
|
|
83
|
-
formId: 'form-1',
|
|
84
|
-
isDraft: false
|
|
85
|
-
});
|
|
86
|
-
});
|
|
87
|
-
it('should redact credential-like fields from data and metadata', ()=>{
|
|
88
|
-
const event = buildDomainEvent({
|
|
89
|
-
module: 'form-builder',
|
|
90
|
-
entity: 'form_result',
|
|
91
|
-
action: 'submitted',
|
|
92
|
-
data: {
|
|
93
|
-
id: 'a',
|
|
94
|
-
password: 'hunter2'
|
|
95
|
-
},
|
|
96
|
-
metadata: {
|
|
97
|
-
token: 'abc'
|
|
98
|
-
}
|
|
99
|
-
});
|
|
100
|
-
expect(event.payload.data).toEqual([
|
|
101
|
-
{
|
|
102
|
-
id: 'a',
|
|
103
|
-
password: '[REDACTED]'
|
|
104
|
-
}
|
|
105
|
-
]);
|
|
106
|
-
expect(event.payload.metadata).toEqual({
|
|
107
|
-
token: '[REDACTED]'
|
|
108
|
-
});
|
|
109
|
-
});
|
|
110
|
-
it('should record the acting user', ()=>{
|
|
111
|
-
const event = buildDomainEvent({
|
|
112
|
-
module: 'form-builder',
|
|
113
|
-
entity: 'form_result',
|
|
114
|
-
action: 'submitted',
|
|
115
|
-
user
|
|
116
|
-
});
|
|
117
|
-
expect(event.actor).toEqual(expect.objectContaining({
|
|
118
|
-
userId: 'user-1',
|
|
119
|
-
companyId: 'company-1'
|
|
120
|
-
}));
|
|
121
|
-
});
|
|
122
|
-
});
|
|
123
|
-
describe('publishDomainEvent', ()=>{
|
|
124
|
-
let publish;
|
|
125
|
-
beforeEach(()=>{
|
|
126
|
-
publish = jest.fn().mockResolvedValue(undefined);
|
|
127
|
-
EventBusRegistry.reset();
|
|
128
|
-
EventBusRegistry.setBus({
|
|
129
|
-
publish,
|
|
130
|
-
subscribe: jest.fn(),
|
|
131
|
-
close: jest.fn()
|
|
132
|
-
});
|
|
133
|
-
});
|
|
134
|
-
afterEach(()=>{
|
|
135
|
-
EventBusRegistry.reset();
|
|
136
|
-
});
|
|
137
|
-
it('should publish when the module has events enabled', async ()=>{
|
|
138
|
-
EventBusRegistry.configureModule('auth', {
|
|
139
|
-
enabled: true
|
|
140
|
-
});
|
|
141
|
-
await publishDomainEvent({
|
|
142
|
-
module: 'auth',
|
|
143
|
-
entity: 'session',
|
|
144
|
-
action: 'logged-in'
|
|
145
|
-
});
|
|
146
|
-
expect(publish).toHaveBeenCalledWith(expect.objectContaining({
|
|
147
|
-
name: 'auth.session.logged-in'
|
|
148
|
-
}));
|
|
149
|
-
});
|
|
150
|
-
it('should stay silent when the module has events disabled', async ()=>{
|
|
151
|
-
EventBusRegistry.configureModule('auth', {
|
|
152
|
-
enabled: false
|
|
153
|
-
});
|
|
154
|
-
await publishDomainEvent({
|
|
155
|
-
module: 'auth',
|
|
156
|
-
entity: 'session',
|
|
157
|
-
action: 'logged-in'
|
|
158
|
-
});
|
|
159
|
-
expect(publish).not.toHaveBeenCalled();
|
|
160
|
-
});
|
|
161
|
-
it('should honour an action allowlist that names a domain action', async ()=>{
|
|
162
|
-
EventBusRegistry.configureModule('auth', {
|
|
163
|
-
enabled: true,
|
|
164
|
-
actions: [
|
|
165
|
-
'logged-in'
|
|
166
|
-
]
|
|
167
|
-
});
|
|
168
|
-
await publishDomainEvent({
|
|
169
|
-
module: 'auth',
|
|
170
|
-
entity: 'session',
|
|
171
|
-
action: 'logged-in'
|
|
172
|
-
});
|
|
173
|
-
await publishDomainEvent({
|
|
174
|
-
module: 'auth',
|
|
175
|
-
entity: 'session',
|
|
176
|
-
action: 'logged-out'
|
|
177
|
-
});
|
|
178
|
-
expect(publish).toHaveBeenCalledTimes(1);
|
|
179
|
-
});
|
|
180
|
-
it('should publish through an explicitly supplied bus instead of the registered one', async ()=>{
|
|
181
|
-
const directPublish = jest.fn().mockResolvedValue(undefined);
|
|
182
|
-
EventBusRegistry.configureModule('auth', {
|
|
183
|
-
enabled: true
|
|
184
|
-
});
|
|
185
|
-
await publishDomainEvent({
|
|
186
|
-
module: 'auth',
|
|
187
|
-
entity: 'session',
|
|
188
|
-
action: 'logged-in',
|
|
189
|
-
eventBus: {
|
|
190
|
-
publish: directPublish
|
|
191
|
-
}
|
|
192
|
-
});
|
|
193
|
-
expect(directPublish).toHaveBeenCalled();
|
|
194
|
-
expect(publish).not.toHaveBeenCalled();
|
|
195
|
-
});
|
|
196
|
-
it('should still respect the module switch when a bus is supplied explicitly', async ()=>{
|
|
197
|
-
const directPublish = jest.fn().mockResolvedValue(undefined);
|
|
198
|
-
EventBusRegistry.configureModule('auth', {
|
|
199
|
-
enabled: false
|
|
200
|
-
});
|
|
201
|
-
await publishDomainEvent({
|
|
202
|
-
module: 'auth',
|
|
203
|
-
entity: 'session',
|
|
204
|
-
action: 'logged-in',
|
|
205
|
-
eventBus: {
|
|
206
|
-
publish: directPublish
|
|
207
|
-
}
|
|
208
|
-
});
|
|
209
|
-
expect(directPublish).not.toHaveBeenCalled();
|
|
210
|
-
});
|
|
211
|
-
it('should do nothing when no bus is registered', async ()=>{
|
|
212
|
-
EventBusRegistry.reset();
|
|
213
|
-
await expect(publishDomainEvent({
|
|
214
|
-
module: 'auth',
|
|
215
|
-
entity: 'session',
|
|
216
|
-
action: 'logged-in'
|
|
217
|
-
})).resolves.toBeUndefined();
|
|
218
|
-
});
|
|
219
|
-
it('should swallow a broker failure', async ()=>{
|
|
220
|
-
EventBusRegistry.configureModule('auth', {
|
|
221
|
-
enabled: true
|
|
222
|
-
});
|
|
223
|
-
publish.mockRejectedValue(new Error('broker down'));
|
|
224
|
-
await expect(publishDomainEvent({
|
|
225
|
-
module: 'auth',
|
|
226
|
-
entity: 'session',
|
|
227
|
-
action: 'logged-in'
|
|
228
|
-
})).resolves.toBeUndefined();
|
|
229
|
-
});
|
|
230
|
-
});
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
function _define_property(obj, key, value) {
|
|
2
|
-
if (key in obj) {
|
|
3
|
-
Object.defineProperty(obj, key, {
|
|
4
|
-
value: value,
|
|
5
|
-
enumerable: true,
|
|
6
|
-
configurable: true,
|
|
7
|
-
writable: true
|
|
8
|
-
});
|
|
9
|
-
} else {
|
|
10
|
-
obj[key] = value;
|
|
11
|
-
}
|
|
12
|
-
return obj;
|
|
13
|
-
}
|
|
14
|
-
import { matchEventPattern } from '../utils/event-pattern.util';
|
|
15
|
-
const DISABLED = {
|
|
16
|
-
enabled: false
|
|
17
|
-
};
|
|
18
|
-
/**
|
|
19
|
-
* Ambient access point for the event bus.
|
|
20
|
-
*
|
|
21
|
-
* ApiService is request scoped and is extended by every feature package, so the
|
|
22
|
-
* bus is resolved from here instead of being threaded through 20+ constructors.
|
|
23
|
-
* Services may still receive a bus explicitly - that instance wins.
|
|
24
|
-
*/ export class EventBusRegistry {
|
|
25
|
-
static setBus(bus) {
|
|
26
|
-
this.bus = bus;
|
|
27
|
-
}
|
|
28
|
-
static getBus() {
|
|
29
|
-
return this.bus;
|
|
30
|
-
}
|
|
31
|
-
static setDefaultModuleEvents(config) {
|
|
32
|
-
this.defaultConfig = config ?? DISABLED;
|
|
33
|
-
}
|
|
34
|
-
/** Called by each feature module with the `events` block from its own config */ static configureModule(moduleName, config) {
|
|
35
|
-
this.moduleConfigs.set(moduleName, config ?? DISABLED);
|
|
36
|
-
}
|
|
37
|
-
static getModuleConfig(moduleName) {
|
|
38
|
-
if (!moduleName) return this.defaultConfig;
|
|
39
|
-
return this.moduleConfigs.get(moduleName) ?? this.defaultConfig;
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* Answers only "is this module configured to publish this" - whether a bus
|
|
43
|
-
* exists is the publisher's concern, so an explicitly supplied bus is still
|
|
44
|
-
* held to the module's own on/off switch.
|
|
45
|
-
*/ static isEnabled(moduleName, entity, action) {
|
|
46
|
-
const config = this.getModuleConfig(moduleName);
|
|
47
|
-
if (!config.enabled) return false;
|
|
48
|
-
// Without an explicit allowlist, CRUD lifecycle actions and every domain
|
|
49
|
-
// action a package defines are all published.
|
|
50
|
-
if (!config.actions?.length) return true;
|
|
51
|
-
return config.actions.some((entry)=>entry.includes('.') ? matchEventPattern(entry, `${entity}.${action}`) : matchEventPattern(entry, action));
|
|
52
|
-
}
|
|
53
|
-
static shouldIncludePayload(moduleName) {
|
|
54
|
-
return this.getModuleConfig(moduleName).includePayload ?? true;
|
|
55
|
-
}
|
|
56
|
-
static reset() {
|
|
57
|
-
this.bus = undefined;
|
|
58
|
-
this.moduleConfigs.clear();
|
|
59
|
-
this.defaultConfig = DISABLED;
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
_define_property(EventBusRegistry, "bus", void 0);
|
|
63
|
-
_define_property(EventBusRegistry, "moduleConfigs", new Map());
|
|
64
|
-
_define_property(EventBusRegistry, "defaultConfig", DISABLED);
|
|
@@ -1,137 +0,0 @@
|
|
|
1
|
-
import { EventBusRegistry } from './event-bus.registry';
|
|
2
|
-
const bus = {
|
|
3
|
-
publish: jest.fn(),
|
|
4
|
-
subscribe: jest.fn(),
|
|
5
|
-
close: jest.fn()
|
|
6
|
-
};
|
|
7
|
-
describe('EventBusRegistry', ()=>{
|
|
8
|
-
beforeEach(()=>{
|
|
9
|
-
EventBusRegistry.reset();
|
|
10
|
-
EventBusRegistry.setBus(bus);
|
|
11
|
-
});
|
|
12
|
-
afterEach(()=>{
|
|
13
|
-
EventBusRegistry.reset();
|
|
14
|
-
});
|
|
15
|
-
it('should expose the registered bus', ()=>{
|
|
16
|
-
expect(EventBusRegistry.getBus()).toBe(bus);
|
|
17
|
-
});
|
|
18
|
-
it('should answer from the module config alone, independent of any registered bus', ()=>{
|
|
19
|
-
EventBusRegistry.reset();
|
|
20
|
-
EventBusRegistry.configureModule('storage', {
|
|
21
|
-
enabled: true
|
|
22
|
-
});
|
|
23
|
-
expect(EventBusRegistry.getBus()).toBeUndefined();
|
|
24
|
-
expect(EventBusRegistry.isEnabled('storage', 'folder', 'created')).toBe(true);
|
|
25
|
-
});
|
|
26
|
-
it('should report disabled for a module that never registered a config', ()=>{
|
|
27
|
-
expect(EventBusRegistry.isEnabled('storage', 'folder', 'created')).toBe(false);
|
|
28
|
-
});
|
|
29
|
-
it('should enable every action of an enabled module by default', ()=>{
|
|
30
|
-
EventBusRegistry.configureModule('storage', {
|
|
31
|
-
enabled: true
|
|
32
|
-
});
|
|
33
|
-
expect(EventBusRegistry.isEnabled('storage', 'folder', 'created')).toBe(true);
|
|
34
|
-
expect(EventBusRegistry.isEnabled('storage', 'folder', 'deleted')).toBe(true);
|
|
35
|
-
});
|
|
36
|
-
it('should honour an action allowlist', ()=>{
|
|
37
|
-
EventBusRegistry.configureModule('storage', {
|
|
38
|
-
enabled: true,
|
|
39
|
-
actions: [
|
|
40
|
-
'created'
|
|
41
|
-
]
|
|
42
|
-
});
|
|
43
|
-
expect(EventBusRegistry.isEnabled('storage', 'folder', 'created')).toBe(true);
|
|
44
|
-
expect(EventBusRegistry.isEnabled('storage', 'folder', 'updated')).toBe(false);
|
|
45
|
-
});
|
|
46
|
-
it('should honour an allowlist that mixes CRUD lifecycle and domain actions', ()=>{
|
|
47
|
-
EventBusRegistry.configureModule('auth', {
|
|
48
|
-
enabled: true,
|
|
49
|
-
actions: [
|
|
50
|
-
'created',
|
|
51
|
-
'logged-in'
|
|
52
|
-
]
|
|
53
|
-
});
|
|
54
|
-
expect(EventBusRegistry.isEnabled('auth', 'appuser', 'created')).toBe(true);
|
|
55
|
-
expect(EventBusRegistry.isEnabled('auth', 'session', 'logged-in')).toBe(true);
|
|
56
|
-
expect(EventBusRegistry.isEnabled('auth', 'appuser', 'updated')).toBe(false);
|
|
57
|
-
expect(EventBusRegistry.isEnabled('auth', 'session', 'logged-out')).toBe(false);
|
|
58
|
-
});
|
|
59
|
-
it('should silence CRUD when the allowlist names only domain actions', ()=>{
|
|
60
|
-
EventBusRegistry.configureModule('auth', {
|
|
61
|
-
enabled: true,
|
|
62
|
-
actions: [
|
|
63
|
-
'logged-in'
|
|
64
|
-
]
|
|
65
|
-
});
|
|
66
|
-
expect(EventBusRegistry.isEnabled('auth', 'session', 'logged-in')).toBe(true);
|
|
67
|
-
expect(EventBusRegistry.isEnabled('auth', 'appuser', 'created')).toBe(false);
|
|
68
|
-
});
|
|
69
|
-
it('should scope an action to one entity when the entry names it', ()=>{
|
|
70
|
-
EventBusRegistry.configureModule('iam', {
|
|
71
|
-
enabled: true,
|
|
72
|
-
actions: [
|
|
73
|
-
'created',
|
|
74
|
-
'role.updated'
|
|
75
|
-
]
|
|
76
|
-
});
|
|
77
|
-
expect(EventBusRegistry.isEnabled('iam', 'role', 'updated')).toBe(true);
|
|
78
|
-
expect(EventBusRegistry.isEnabled('iam', 'action', 'updated')).toBe(false);
|
|
79
|
-
expect(EventBusRegistry.isEnabled('iam', 'action', 'created')).toBe(true);
|
|
80
|
-
});
|
|
81
|
-
it('should treat a scoped entry as a routing pattern', ()=>{
|
|
82
|
-
EventBusRegistry.configureModule('iam', {
|
|
83
|
-
enabled: true,
|
|
84
|
-
actions: [
|
|
85
|
-
'role.*',
|
|
86
|
-
'*.purged'
|
|
87
|
-
]
|
|
88
|
-
});
|
|
89
|
-
expect(EventBusRegistry.isEnabled('iam', 'role', 'updated')).toBe(true);
|
|
90
|
-
expect(EventBusRegistry.isEnabled('iam', 'role', 'permissions-assigned')).toBe(true);
|
|
91
|
-
expect(EventBusRegistry.isEnabled('iam', 'action', 'purged')).toBe(true);
|
|
92
|
-
expect(EventBusRegistry.isEnabled('iam', 'action', 'updated')).toBe(false);
|
|
93
|
-
});
|
|
94
|
-
it('should publish only the entity and action pairs an app lists', ()=>{
|
|
95
|
-
EventBusRegistry.configureModule('auth', {
|
|
96
|
-
enabled: true,
|
|
97
|
-
actions: [
|
|
98
|
-
'company.created',
|
|
99
|
-
'company.updated',
|
|
100
|
-
'session.logged-in'
|
|
101
|
-
]
|
|
102
|
-
});
|
|
103
|
-
expect(EventBusRegistry.isEnabled('auth', 'company', 'created')).toBe(true);
|
|
104
|
-
expect(EventBusRegistry.isEnabled('auth', 'company', 'updated')).toBe(true);
|
|
105
|
-
expect(EventBusRegistry.isEnabled('auth', 'company', 'purged')).toBe(false);
|
|
106
|
-
expect(EventBusRegistry.isEnabled('auth', 'appuser', 'created')).toBe(false);
|
|
107
|
-
expect(EventBusRegistry.isEnabled('auth', 'session', 'logged-in')).toBe(true);
|
|
108
|
-
expect(EventBusRegistry.isEnabled('auth', 'session', 'logged-out')).toBe(false);
|
|
109
|
-
});
|
|
110
|
-
it('should fall back to the default config for unregistered modules', ()=>{
|
|
111
|
-
EventBusRegistry.setDefaultModuleEvents({
|
|
112
|
-
enabled: true
|
|
113
|
-
});
|
|
114
|
-
expect(EventBusRegistry.isEnabled('unknown-module', 'thing', 'created')).toBe(true);
|
|
115
|
-
});
|
|
116
|
-
it('should include the payload unless a module opts out', ()=>{
|
|
117
|
-
EventBusRegistry.configureModule('storage', {
|
|
118
|
-
enabled: true
|
|
119
|
-
});
|
|
120
|
-
EventBusRegistry.configureModule('auth', {
|
|
121
|
-
enabled: true,
|
|
122
|
-
includePayload: false
|
|
123
|
-
});
|
|
124
|
-
expect(EventBusRegistry.shouldIncludePayload('storage')).toBe(true);
|
|
125
|
-
expect(EventBusRegistry.shouldIncludePayload('auth')).toBe(false);
|
|
126
|
-
});
|
|
127
|
-
it('should clear everything on reset', ()=>{
|
|
128
|
-
EventBusRegistry.configureModule('storage', {
|
|
129
|
-
enabled: true
|
|
130
|
-
});
|
|
131
|
-
EventBusRegistry.reset();
|
|
132
|
-
expect(EventBusRegistry.getBus()).toBeUndefined();
|
|
133
|
-
expect(EventBusRegistry.getModuleConfig('storage')).toEqual({
|
|
134
|
-
enabled: false
|
|
135
|
-
});
|
|
136
|
-
});
|
|
137
|
-
});
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
function _define_property(obj, key, value) {
|
|
2
|
-
if (key in obj) {
|
|
3
|
-
Object.defineProperty(obj, key, {
|
|
4
|
-
value: value,
|
|
5
|
-
enumerable: true,
|
|
6
|
-
configurable: true,
|
|
7
|
-
writable: true
|
|
8
|
-
});
|
|
9
|
-
} else {
|
|
10
|
-
obj[key] = value;
|
|
11
|
-
}
|
|
12
|
-
return obj;
|
|
13
|
-
}
|
|
14
|
-
/**
|
|
15
|
-
* Static registry for event transports.
|
|
16
|
-
* Broker transports register themselves on import so nestjs-shared never has to
|
|
17
|
-
* depend on `amqplib` or `kafkajs` at build time.
|
|
18
|
-
*/ export class EventTransportRegistry {
|
|
19
|
-
static register(name, factory) {
|
|
20
|
-
this.transports.set(name.toLowerCase(), factory);
|
|
21
|
-
}
|
|
22
|
-
static get(name) {
|
|
23
|
-
return this.transports.get(name.toLowerCase());
|
|
24
|
-
}
|
|
25
|
-
static has(name) {
|
|
26
|
-
return this.transports.has(name.toLowerCase());
|
|
27
|
-
}
|
|
28
|
-
static getAll() {
|
|
29
|
-
return Array.from(this.transports.keys());
|
|
30
|
-
}
|
|
31
|
-
static clear() {
|
|
32
|
-
this.transports.clear();
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
_define_property(EventTransportRegistry, "transports", new Map());
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { EventTransportRegistry } from './event-transport.registry';
|
|
2
|
-
const stubTransport = {};
|
|
3
|
-
describe('EventTransportRegistry', ()=>{
|
|
4
|
-
afterEach(()=>{
|
|
5
|
-
EventTransportRegistry.clear();
|
|
6
|
-
});
|
|
7
|
-
it('should register and resolve a transport factory', ()=>{
|
|
8
|
-
EventTransportRegistry.register('rabbitmq', ()=>stubTransport);
|
|
9
|
-
expect(EventTransportRegistry.get('rabbitmq')({})).toBe(stubTransport);
|
|
10
|
-
});
|
|
11
|
-
it('should resolve case insensitively', ()=>{
|
|
12
|
-
EventTransportRegistry.register('Kafka', ()=>stubTransport);
|
|
13
|
-
expect(EventTransportRegistry.has('kafka')).toBe(true);
|
|
14
|
-
});
|
|
15
|
-
it('should return undefined for an unknown transport', ()=>{
|
|
16
|
-
expect(EventTransportRegistry.get('nats')).toBeUndefined();
|
|
17
|
-
expect(EventTransportRegistry.has('nats')).toBe(false);
|
|
18
|
-
});
|
|
19
|
-
it('should list every registered transport', ()=>{
|
|
20
|
-
EventTransportRegistry.register('memory', ()=>stubTransport);
|
|
21
|
-
EventTransportRegistry.register('kafka', ()=>stubTransport);
|
|
22
|
-
expect(EventTransportRegistry.getAll().sort()).toEqual([
|
|
23
|
-
'kafka',
|
|
24
|
-
'memory'
|
|
25
|
-
]);
|
|
26
|
-
});
|
|
27
|
-
});
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
export * from './event-transport.registry';
|
|
2
|
-
// Built-in transport (no external dependencies)
|
|
3
|
-
export * from './memory-transport'; // Note: Broker transports are loaded dynamically by HybridEventBus.
|
|
4
|
-
// Import them directly when registering manually:
|
|
5
|
-
// - import { RabbitMqTransport } from '@flusys/nestjs-shared/classes/event-transports/rabbitmq-transport.optional';
|
|
6
|
-
// - import { KafkaTransport } from '@flusys/nestjs-shared/classes/event-transports/kafka-transport.optional';
|