@flusys/nestjs-shared 7.1.0 → 8.0.0-beta.1
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,15 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
Object.defineProperty(exports, "DisabledEventBus", {
|
|
6
|
-
enumerable: true,
|
|
7
|
-
get: function() {
|
|
8
|
-
return DisabledEventBus;
|
|
9
|
-
}
|
|
10
|
-
});
|
|
11
|
-
let DisabledEventBus = class DisabledEventBus {
|
|
12
|
-
async publish(_event) {}
|
|
13
|
-
async subscribe(_pattern, _handler) {}
|
|
14
|
-
async close() {}
|
|
15
|
-
};
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
const _disabledeventbusclass = require("./disabled-event-bus.class");
|
|
6
|
-
describe('DisabledEventBus', ()=>{
|
|
7
|
-
const event = {
|
|
8
|
-
id: 'e1',
|
|
9
|
-
name: 'auth.session.logged-in',
|
|
10
|
-
module: 'auth',
|
|
11
|
-
entity: 'session',
|
|
12
|
-
action: 'logged-in',
|
|
13
|
-
payload: {
|
|
14
|
-
ids: [
|
|
15
|
-
'u1'
|
|
16
|
-
]
|
|
17
|
-
},
|
|
18
|
-
actor: {
|
|
19
|
-
userId: 'u1',
|
|
20
|
-
companyId: null,
|
|
21
|
-
tenantId: null,
|
|
22
|
-
requestId: null
|
|
23
|
-
},
|
|
24
|
-
occurredAt: new Date().toISOString(),
|
|
25
|
-
version: 1
|
|
26
|
-
};
|
|
27
|
-
it('should never deliver an event to a subscriber', async ()=>{
|
|
28
|
-
const bus = new _disabledeventbusclass.DisabledEventBus();
|
|
29
|
-
const handler = jest.fn();
|
|
30
|
-
await bus.subscribe('**', handler);
|
|
31
|
-
await bus.publish(event);
|
|
32
|
-
expect(handler).not.toHaveBeenCalled();
|
|
33
|
-
});
|
|
34
|
-
it('should resolve without throwing so callers need no special case', async ()=>{
|
|
35
|
-
const bus = new _disabledeventbusclass.DisabledEventBus();
|
|
36
|
-
await expect(bus.publish(event)).resolves.toBeUndefined();
|
|
37
|
-
await expect(bus.subscribe('**', jest.fn())).resolves.toBeUndefined();
|
|
38
|
-
await expect(bus.close()).resolves.toBeUndefined();
|
|
39
|
-
});
|
|
40
|
-
});
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
function _export(target, all) {
|
|
6
|
-
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
-
enumerable: true,
|
|
8
|
-
get: Object.getOwnPropertyDescriptor(all, name).get
|
|
9
|
-
});
|
|
10
|
-
}
|
|
11
|
-
_export(exports, {
|
|
12
|
-
get DOMAIN_EVENT_VERSION () {
|
|
13
|
-
return DOMAIN_EVENT_VERSION;
|
|
14
|
-
},
|
|
15
|
-
get buildDomainEvent () {
|
|
16
|
-
return buildDomainEvent;
|
|
17
|
-
},
|
|
18
|
-
get publishDomainEvent () {
|
|
19
|
-
return publishDomainEvent;
|
|
20
|
-
}
|
|
21
|
-
});
|
|
22
|
-
const _crypto = require("crypto");
|
|
23
|
-
const _loggermiddleware = require("../middlewares/logger.middleware");
|
|
24
|
-
const _eventpatternutil = require("../utils/event-pattern.util");
|
|
25
|
-
const _eventbusregistry = require("./event-bus.registry");
|
|
26
|
-
const DOMAIN_EVENT_VERSION = 1;
|
|
27
|
-
function buildDomainEvent(input) {
|
|
28
|
-
const rows = input.data === undefined ? [] : toArray(input.data);
|
|
29
|
-
const ids = input.ids ?? collectIds(rows);
|
|
30
|
-
return {
|
|
31
|
-
id: (0, _crypto.randomUUID)(),
|
|
32
|
-
name: `${input.module}.${input.entity}.${input.action}`,
|
|
33
|
-
module: input.module,
|
|
34
|
-
entity: input.entity,
|
|
35
|
-
action: input.action,
|
|
36
|
-
payload: {
|
|
37
|
-
ids,
|
|
38
|
-
...rows.length && _eventbusregistry.EventBusRegistry.shouldIncludePayload(input.module) ? {
|
|
39
|
-
data: (0, _eventpatternutil.sanitizeEventPayload)(rows)
|
|
40
|
-
} : {},
|
|
41
|
-
...input.metadata ? {
|
|
42
|
-
metadata: (0, _eventpatternutil.sanitizeEventPayload)(input.metadata)
|
|
43
|
-
} : {}
|
|
44
|
-
},
|
|
45
|
-
actor: {
|
|
46
|
-
userId: input.user?.id ?? null,
|
|
47
|
-
companyId: input.user?.companyId ?? (0, _loggermiddleware.getCompanyId)() ?? null,
|
|
48
|
-
tenantId: (0, _loggermiddleware.getTenantId)() ?? null,
|
|
49
|
-
requestId: (0, _loggermiddleware.getRequestId)() ?? null
|
|
50
|
-
},
|
|
51
|
-
occurredAt: new Date().toISOString(),
|
|
52
|
-
version: DOMAIN_EVENT_VERSION
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
async function publishDomainEvent(input) {
|
|
56
|
-
const bus = input.eventBus ?? _eventbusregistry.EventBusRegistry.getBus();
|
|
57
|
-
if (!bus) return;
|
|
58
|
-
if (!_eventbusregistry.EventBusRegistry.isEnabled(input.module, input.entity, input.action)) return;
|
|
59
|
-
try {
|
|
60
|
-
await bus.publish(buildDomainEvent(input));
|
|
61
|
-
} catch {
|
|
62
|
-
// Events must never break the operation that produced them
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
function toArray(value) {
|
|
66
|
-
return Array.isArray(value) ? value : [
|
|
67
|
-
value
|
|
68
|
-
];
|
|
69
|
-
}
|
|
70
|
-
function collectIds(rows) {
|
|
71
|
-
return rows.reduce((ids, row)=>{
|
|
72
|
-
const id = row?.id;
|
|
73
|
-
if (id) ids.push(id);
|
|
74
|
-
return ids;
|
|
75
|
-
}, []);
|
|
76
|
-
}
|
|
@@ -1,234 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
const _domaineventpublisher = require("./domain-event.publisher");
|
|
6
|
-
const _eventbusregistry = require("./event-bus.registry");
|
|
7
|
-
const user = {
|
|
8
|
-
id: 'user-1',
|
|
9
|
-
email: 'ada@example.com',
|
|
10
|
-
companyId: 'company-1'
|
|
11
|
-
};
|
|
12
|
-
describe('buildDomainEvent', ()=>{
|
|
13
|
-
beforeEach(()=>{
|
|
14
|
-
_eventbusregistry.EventBusRegistry.reset();
|
|
15
|
-
_eventbusregistry.EventBusRegistry.configureModule('form-builder', {
|
|
16
|
-
enabled: true
|
|
17
|
-
});
|
|
18
|
-
});
|
|
19
|
-
afterEach(()=>{
|
|
20
|
-
_eventbusregistry.EventBusRegistry.reset();
|
|
21
|
-
});
|
|
22
|
-
it('should name the event <module>.<entity>.<action>', ()=>{
|
|
23
|
-
const event = (0, _domaineventpublisher.buildDomainEvent)({
|
|
24
|
-
module: 'form-builder',
|
|
25
|
-
entity: 'form_result',
|
|
26
|
-
action: 'submitted'
|
|
27
|
-
});
|
|
28
|
-
expect(event.name).toBe('form-builder.form_result.submitted');
|
|
29
|
-
expect(event.version).toBe(1);
|
|
30
|
-
expect(event.id).toEqual(expect.any(String));
|
|
31
|
-
});
|
|
32
|
-
it('should derive ids from the supplied rows when none are given', ()=>{
|
|
33
|
-
const event = (0, _domaineventpublisher.buildDomainEvent)({
|
|
34
|
-
module: 'form-builder',
|
|
35
|
-
entity: 'form_result',
|
|
36
|
-
action: 'submitted',
|
|
37
|
-
data: [
|
|
38
|
-
{
|
|
39
|
-
id: 'a'
|
|
40
|
-
},
|
|
41
|
-
{
|
|
42
|
-
id: 'b'
|
|
43
|
-
}
|
|
44
|
-
]
|
|
45
|
-
});
|
|
46
|
-
expect(event.payload.ids).toEqual([
|
|
47
|
-
'a',
|
|
48
|
-
'b'
|
|
49
|
-
]);
|
|
50
|
-
});
|
|
51
|
-
it('should prefer explicitly supplied ids', ()=>{
|
|
52
|
-
const event = (0, _domaineventpublisher.buildDomainEvent)({
|
|
53
|
-
module: 'form-builder',
|
|
54
|
-
entity: 'form_result',
|
|
55
|
-
action: 'submitted',
|
|
56
|
-
ids: [
|
|
57
|
-
'explicit'
|
|
58
|
-
],
|
|
59
|
-
data: {
|
|
60
|
-
id: 'ignored'
|
|
61
|
-
}
|
|
62
|
-
});
|
|
63
|
-
expect(event.payload.ids).toEqual([
|
|
64
|
-
'explicit'
|
|
65
|
-
]);
|
|
66
|
-
});
|
|
67
|
-
it('should attach metadata regardless of the includePayload setting', ()=>{
|
|
68
|
-
_eventbusregistry.EventBusRegistry.configureModule('form-builder', {
|
|
69
|
-
enabled: true,
|
|
70
|
-
includePayload: false
|
|
71
|
-
});
|
|
72
|
-
const event = (0, _domaineventpublisher.buildDomainEvent)({
|
|
73
|
-
module: 'form-builder',
|
|
74
|
-
entity: 'form_result',
|
|
75
|
-
action: 'submitted',
|
|
76
|
-
data: {
|
|
77
|
-
id: 'a',
|
|
78
|
-
answer: 'secret-ish'
|
|
79
|
-
},
|
|
80
|
-
metadata: {
|
|
81
|
-
formId: 'form-1',
|
|
82
|
-
isDraft: false
|
|
83
|
-
}
|
|
84
|
-
});
|
|
85
|
-
expect(event.payload.data).toBeUndefined();
|
|
86
|
-
expect(event.payload.metadata).toEqual({
|
|
87
|
-
formId: 'form-1',
|
|
88
|
-
isDraft: false
|
|
89
|
-
});
|
|
90
|
-
});
|
|
91
|
-
it('should redact credential-like fields from data and metadata', ()=>{
|
|
92
|
-
const event = (0, _domaineventpublisher.buildDomainEvent)({
|
|
93
|
-
module: 'form-builder',
|
|
94
|
-
entity: 'form_result',
|
|
95
|
-
action: 'submitted',
|
|
96
|
-
data: {
|
|
97
|
-
id: 'a',
|
|
98
|
-
password: 'hunter2'
|
|
99
|
-
},
|
|
100
|
-
metadata: {
|
|
101
|
-
token: 'abc'
|
|
102
|
-
}
|
|
103
|
-
});
|
|
104
|
-
expect(event.payload.data).toEqual([
|
|
105
|
-
{
|
|
106
|
-
id: 'a',
|
|
107
|
-
password: '[REDACTED]'
|
|
108
|
-
}
|
|
109
|
-
]);
|
|
110
|
-
expect(event.payload.metadata).toEqual({
|
|
111
|
-
token: '[REDACTED]'
|
|
112
|
-
});
|
|
113
|
-
});
|
|
114
|
-
it('should record the acting user', ()=>{
|
|
115
|
-
const event = (0, _domaineventpublisher.buildDomainEvent)({
|
|
116
|
-
module: 'form-builder',
|
|
117
|
-
entity: 'form_result',
|
|
118
|
-
action: 'submitted',
|
|
119
|
-
user
|
|
120
|
-
});
|
|
121
|
-
expect(event.actor).toEqual(expect.objectContaining({
|
|
122
|
-
userId: 'user-1',
|
|
123
|
-
companyId: 'company-1'
|
|
124
|
-
}));
|
|
125
|
-
});
|
|
126
|
-
});
|
|
127
|
-
describe('publishDomainEvent', ()=>{
|
|
128
|
-
let publish;
|
|
129
|
-
beforeEach(()=>{
|
|
130
|
-
publish = jest.fn().mockResolvedValue(undefined);
|
|
131
|
-
_eventbusregistry.EventBusRegistry.reset();
|
|
132
|
-
_eventbusregistry.EventBusRegistry.setBus({
|
|
133
|
-
publish,
|
|
134
|
-
subscribe: jest.fn(),
|
|
135
|
-
close: jest.fn()
|
|
136
|
-
});
|
|
137
|
-
});
|
|
138
|
-
afterEach(()=>{
|
|
139
|
-
_eventbusregistry.EventBusRegistry.reset();
|
|
140
|
-
});
|
|
141
|
-
it('should publish when the module has events enabled', async ()=>{
|
|
142
|
-
_eventbusregistry.EventBusRegistry.configureModule('auth', {
|
|
143
|
-
enabled: true
|
|
144
|
-
});
|
|
145
|
-
await (0, _domaineventpublisher.publishDomainEvent)({
|
|
146
|
-
module: 'auth',
|
|
147
|
-
entity: 'session',
|
|
148
|
-
action: 'logged-in'
|
|
149
|
-
});
|
|
150
|
-
expect(publish).toHaveBeenCalledWith(expect.objectContaining({
|
|
151
|
-
name: 'auth.session.logged-in'
|
|
152
|
-
}));
|
|
153
|
-
});
|
|
154
|
-
it('should stay silent when the module has events disabled', async ()=>{
|
|
155
|
-
_eventbusregistry.EventBusRegistry.configureModule('auth', {
|
|
156
|
-
enabled: false
|
|
157
|
-
});
|
|
158
|
-
await (0, _domaineventpublisher.publishDomainEvent)({
|
|
159
|
-
module: 'auth',
|
|
160
|
-
entity: 'session',
|
|
161
|
-
action: 'logged-in'
|
|
162
|
-
});
|
|
163
|
-
expect(publish).not.toHaveBeenCalled();
|
|
164
|
-
});
|
|
165
|
-
it('should honour an action allowlist that names a domain action', async ()=>{
|
|
166
|
-
_eventbusregistry.EventBusRegistry.configureModule('auth', {
|
|
167
|
-
enabled: true,
|
|
168
|
-
actions: [
|
|
169
|
-
'logged-in'
|
|
170
|
-
]
|
|
171
|
-
});
|
|
172
|
-
await (0, _domaineventpublisher.publishDomainEvent)({
|
|
173
|
-
module: 'auth',
|
|
174
|
-
entity: 'session',
|
|
175
|
-
action: 'logged-in'
|
|
176
|
-
});
|
|
177
|
-
await (0, _domaineventpublisher.publishDomainEvent)({
|
|
178
|
-
module: 'auth',
|
|
179
|
-
entity: 'session',
|
|
180
|
-
action: 'logged-out'
|
|
181
|
-
});
|
|
182
|
-
expect(publish).toHaveBeenCalledTimes(1);
|
|
183
|
-
});
|
|
184
|
-
it('should publish through an explicitly supplied bus instead of the registered one', async ()=>{
|
|
185
|
-
const directPublish = jest.fn().mockResolvedValue(undefined);
|
|
186
|
-
_eventbusregistry.EventBusRegistry.configureModule('auth', {
|
|
187
|
-
enabled: true
|
|
188
|
-
});
|
|
189
|
-
await (0, _domaineventpublisher.publishDomainEvent)({
|
|
190
|
-
module: 'auth',
|
|
191
|
-
entity: 'session',
|
|
192
|
-
action: 'logged-in',
|
|
193
|
-
eventBus: {
|
|
194
|
-
publish: directPublish
|
|
195
|
-
}
|
|
196
|
-
});
|
|
197
|
-
expect(directPublish).toHaveBeenCalled();
|
|
198
|
-
expect(publish).not.toHaveBeenCalled();
|
|
199
|
-
});
|
|
200
|
-
it('should still respect the module switch when a bus is supplied explicitly', async ()=>{
|
|
201
|
-
const directPublish = jest.fn().mockResolvedValue(undefined);
|
|
202
|
-
_eventbusregistry.EventBusRegistry.configureModule('auth', {
|
|
203
|
-
enabled: false
|
|
204
|
-
});
|
|
205
|
-
await (0, _domaineventpublisher.publishDomainEvent)({
|
|
206
|
-
module: 'auth',
|
|
207
|
-
entity: 'session',
|
|
208
|
-
action: 'logged-in',
|
|
209
|
-
eventBus: {
|
|
210
|
-
publish: directPublish
|
|
211
|
-
}
|
|
212
|
-
});
|
|
213
|
-
expect(directPublish).not.toHaveBeenCalled();
|
|
214
|
-
});
|
|
215
|
-
it('should do nothing when no bus is registered', async ()=>{
|
|
216
|
-
_eventbusregistry.EventBusRegistry.reset();
|
|
217
|
-
await expect((0, _domaineventpublisher.publishDomainEvent)({
|
|
218
|
-
module: 'auth',
|
|
219
|
-
entity: 'session',
|
|
220
|
-
action: 'logged-in'
|
|
221
|
-
})).resolves.toBeUndefined();
|
|
222
|
-
});
|
|
223
|
-
it('should swallow a broker failure', async ()=>{
|
|
224
|
-
_eventbusregistry.EventBusRegistry.configureModule('auth', {
|
|
225
|
-
enabled: true
|
|
226
|
-
});
|
|
227
|
-
publish.mockRejectedValue(new Error('broker down'));
|
|
228
|
-
await expect((0, _domaineventpublisher.publishDomainEvent)({
|
|
229
|
-
module: 'auth',
|
|
230
|
-
entity: 'session',
|
|
231
|
-
action: 'logged-in'
|
|
232
|
-
})).resolves.toBeUndefined();
|
|
233
|
-
});
|
|
234
|
-
});
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
Object.defineProperty(exports, "EventBusRegistry", {
|
|
6
|
-
enumerable: true,
|
|
7
|
-
get: function() {
|
|
8
|
-
return EventBusRegistry;
|
|
9
|
-
}
|
|
10
|
-
});
|
|
11
|
-
const _eventpatternutil = require("../utils/event-pattern.util");
|
|
12
|
-
function _define_property(obj, key, value) {
|
|
13
|
-
if (key in obj) {
|
|
14
|
-
Object.defineProperty(obj, key, {
|
|
15
|
-
value: value,
|
|
16
|
-
enumerable: true,
|
|
17
|
-
configurable: true,
|
|
18
|
-
writable: true
|
|
19
|
-
});
|
|
20
|
-
} else {
|
|
21
|
-
obj[key] = value;
|
|
22
|
-
}
|
|
23
|
-
return obj;
|
|
24
|
-
}
|
|
25
|
-
const DISABLED = {
|
|
26
|
-
enabled: false
|
|
27
|
-
};
|
|
28
|
-
let EventBusRegistry = class EventBusRegistry {
|
|
29
|
-
static setBus(bus) {
|
|
30
|
-
this.bus = bus;
|
|
31
|
-
}
|
|
32
|
-
static getBus() {
|
|
33
|
-
return this.bus;
|
|
34
|
-
}
|
|
35
|
-
static setDefaultModuleEvents(config) {
|
|
36
|
-
this.defaultConfig = config ?? DISABLED;
|
|
37
|
-
}
|
|
38
|
-
/** Called by each feature module with the `events` block from its own config */ static configureModule(moduleName, config) {
|
|
39
|
-
this.moduleConfigs.set(moduleName, config ?? DISABLED);
|
|
40
|
-
}
|
|
41
|
-
static getModuleConfig(moduleName) {
|
|
42
|
-
if (!moduleName) return this.defaultConfig;
|
|
43
|
-
return this.moduleConfigs.get(moduleName) ?? this.defaultConfig;
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* Answers only "is this module configured to publish this" - whether a bus
|
|
47
|
-
* exists is the publisher's concern, so an explicitly supplied bus is still
|
|
48
|
-
* held to the module's own on/off switch.
|
|
49
|
-
*/ static isEnabled(moduleName, entity, action) {
|
|
50
|
-
const config = this.getModuleConfig(moduleName);
|
|
51
|
-
if (!config.enabled) return false;
|
|
52
|
-
// Without an explicit allowlist, CRUD lifecycle actions and every domain
|
|
53
|
-
// action a package defines are all published.
|
|
54
|
-
if (!config.actions?.length) return true;
|
|
55
|
-
return config.actions.some((entry)=>entry.includes('.') ? (0, _eventpatternutil.matchEventPattern)(entry, `${entity}.${action}`) : (0, _eventpatternutil.matchEventPattern)(entry, action));
|
|
56
|
-
}
|
|
57
|
-
static shouldIncludePayload(moduleName) {
|
|
58
|
-
return this.getModuleConfig(moduleName).includePayload ?? true;
|
|
59
|
-
}
|
|
60
|
-
static reset() {
|
|
61
|
-
this.bus = undefined;
|
|
62
|
-
this.moduleConfigs.clear();
|
|
63
|
-
this.defaultConfig = DISABLED;
|
|
64
|
-
}
|
|
65
|
-
};
|
|
66
|
-
_define_property(EventBusRegistry, "bus", void 0);
|
|
67
|
-
_define_property(EventBusRegistry, "moduleConfigs", new Map());
|
|
68
|
-
_define_property(EventBusRegistry, "defaultConfig", DISABLED);
|
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
const _eventbusregistry = require("./event-bus.registry");
|
|
6
|
-
const bus = {
|
|
7
|
-
publish: jest.fn(),
|
|
8
|
-
subscribe: jest.fn(),
|
|
9
|
-
close: jest.fn()
|
|
10
|
-
};
|
|
11
|
-
describe('EventBusRegistry', ()=>{
|
|
12
|
-
beforeEach(()=>{
|
|
13
|
-
_eventbusregistry.EventBusRegistry.reset();
|
|
14
|
-
_eventbusregistry.EventBusRegistry.setBus(bus);
|
|
15
|
-
});
|
|
16
|
-
afterEach(()=>{
|
|
17
|
-
_eventbusregistry.EventBusRegistry.reset();
|
|
18
|
-
});
|
|
19
|
-
it('should expose the registered bus', ()=>{
|
|
20
|
-
expect(_eventbusregistry.EventBusRegistry.getBus()).toBe(bus);
|
|
21
|
-
});
|
|
22
|
-
it('should answer from the module config alone, independent of any registered bus', ()=>{
|
|
23
|
-
_eventbusregistry.EventBusRegistry.reset();
|
|
24
|
-
_eventbusregistry.EventBusRegistry.configureModule('storage', {
|
|
25
|
-
enabled: true
|
|
26
|
-
});
|
|
27
|
-
expect(_eventbusregistry.EventBusRegistry.getBus()).toBeUndefined();
|
|
28
|
-
expect(_eventbusregistry.EventBusRegistry.isEnabled('storage', 'folder', 'created')).toBe(true);
|
|
29
|
-
});
|
|
30
|
-
it('should report disabled for a module that never registered a config', ()=>{
|
|
31
|
-
expect(_eventbusregistry.EventBusRegistry.isEnabled('storage', 'folder', 'created')).toBe(false);
|
|
32
|
-
});
|
|
33
|
-
it('should enable every action of an enabled module by default', ()=>{
|
|
34
|
-
_eventbusregistry.EventBusRegistry.configureModule('storage', {
|
|
35
|
-
enabled: true
|
|
36
|
-
});
|
|
37
|
-
expect(_eventbusregistry.EventBusRegistry.isEnabled('storage', 'folder', 'created')).toBe(true);
|
|
38
|
-
expect(_eventbusregistry.EventBusRegistry.isEnabled('storage', 'folder', 'deleted')).toBe(true);
|
|
39
|
-
});
|
|
40
|
-
it('should honour an action allowlist', ()=>{
|
|
41
|
-
_eventbusregistry.EventBusRegistry.configureModule('storage', {
|
|
42
|
-
enabled: true,
|
|
43
|
-
actions: [
|
|
44
|
-
'created'
|
|
45
|
-
]
|
|
46
|
-
});
|
|
47
|
-
expect(_eventbusregistry.EventBusRegistry.isEnabled('storage', 'folder', 'created')).toBe(true);
|
|
48
|
-
expect(_eventbusregistry.EventBusRegistry.isEnabled('storage', 'folder', 'updated')).toBe(false);
|
|
49
|
-
});
|
|
50
|
-
it('should honour an allowlist that mixes CRUD lifecycle and domain actions', ()=>{
|
|
51
|
-
_eventbusregistry.EventBusRegistry.configureModule('auth', {
|
|
52
|
-
enabled: true,
|
|
53
|
-
actions: [
|
|
54
|
-
'created',
|
|
55
|
-
'logged-in'
|
|
56
|
-
]
|
|
57
|
-
});
|
|
58
|
-
expect(_eventbusregistry.EventBusRegistry.isEnabled('auth', 'appuser', 'created')).toBe(true);
|
|
59
|
-
expect(_eventbusregistry.EventBusRegistry.isEnabled('auth', 'session', 'logged-in')).toBe(true);
|
|
60
|
-
expect(_eventbusregistry.EventBusRegistry.isEnabled('auth', 'appuser', 'updated')).toBe(false);
|
|
61
|
-
expect(_eventbusregistry.EventBusRegistry.isEnabled('auth', 'session', 'logged-out')).toBe(false);
|
|
62
|
-
});
|
|
63
|
-
it('should silence CRUD when the allowlist names only domain actions', ()=>{
|
|
64
|
-
_eventbusregistry.EventBusRegistry.configureModule('auth', {
|
|
65
|
-
enabled: true,
|
|
66
|
-
actions: [
|
|
67
|
-
'logged-in'
|
|
68
|
-
]
|
|
69
|
-
});
|
|
70
|
-
expect(_eventbusregistry.EventBusRegistry.isEnabled('auth', 'session', 'logged-in')).toBe(true);
|
|
71
|
-
expect(_eventbusregistry.EventBusRegistry.isEnabled('auth', 'appuser', 'created')).toBe(false);
|
|
72
|
-
});
|
|
73
|
-
it('should scope an action to one entity when the entry names it', ()=>{
|
|
74
|
-
_eventbusregistry.EventBusRegistry.configureModule('iam', {
|
|
75
|
-
enabled: true,
|
|
76
|
-
actions: [
|
|
77
|
-
'created',
|
|
78
|
-
'role.updated'
|
|
79
|
-
]
|
|
80
|
-
});
|
|
81
|
-
expect(_eventbusregistry.EventBusRegistry.isEnabled('iam', 'role', 'updated')).toBe(true);
|
|
82
|
-
expect(_eventbusregistry.EventBusRegistry.isEnabled('iam', 'action', 'updated')).toBe(false);
|
|
83
|
-
expect(_eventbusregistry.EventBusRegistry.isEnabled('iam', 'action', 'created')).toBe(true);
|
|
84
|
-
});
|
|
85
|
-
it('should treat a scoped entry as a routing pattern', ()=>{
|
|
86
|
-
_eventbusregistry.EventBusRegistry.configureModule('iam', {
|
|
87
|
-
enabled: true,
|
|
88
|
-
actions: [
|
|
89
|
-
'role.*',
|
|
90
|
-
'*.purged'
|
|
91
|
-
]
|
|
92
|
-
});
|
|
93
|
-
expect(_eventbusregistry.EventBusRegistry.isEnabled('iam', 'role', 'updated')).toBe(true);
|
|
94
|
-
expect(_eventbusregistry.EventBusRegistry.isEnabled('iam', 'role', 'permissions-assigned')).toBe(true);
|
|
95
|
-
expect(_eventbusregistry.EventBusRegistry.isEnabled('iam', 'action', 'purged')).toBe(true);
|
|
96
|
-
expect(_eventbusregistry.EventBusRegistry.isEnabled('iam', 'action', 'updated')).toBe(false);
|
|
97
|
-
});
|
|
98
|
-
it('should publish only the entity and action pairs an app lists', ()=>{
|
|
99
|
-
_eventbusregistry.EventBusRegistry.configureModule('auth', {
|
|
100
|
-
enabled: true,
|
|
101
|
-
actions: [
|
|
102
|
-
'company.created',
|
|
103
|
-
'company.updated',
|
|
104
|
-
'session.logged-in'
|
|
105
|
-
]
|
|
106
|
-
});
|
|
107
|
-
expect(_eventbusregistry.EventBusRegistry.isEnabled('auth', 'company', 'created')).toBe(true);
|
|
108
|
-
expect(_eventbusregistry.EventBusRegistry.isEnabled('auth', 'company', 'updated')).toBe(true);
|
|
109
|
-
expect(_eventbusregistry.EventBusRegistry.isEnabled('auth', 'company', 'purged')).toBe(false);
|
|
110
|
-
expect(_eventbusregistry.EventBusRegistry.isEnabled('auth', 'appuser', 'created')).toBe(false);
|
|
111
|
-
expect(_eventbusregistry.EventBusRegistry.isEnabled('auth', 'session', 'logged-in')).toBe(true);
|
|
112
|
-
expect(_eventbusregistry.EventBusRegistry.isEnabled('auth', 'session', 'logged-out')).toBe(false);
|
|
113
|
-
});
|
|
114
|
-
it('should fall back to the default config for unregistered modules', ()=>{
|
|
115
|
-
_eventbusregistry.EventBusRegistry.setDefaultModuleEvents({
|
|
116
|
-
enabled: true
|
|
117
|
-
});
|
|
118
|
-
expect(_eventbusregistry.EventBusRegistry.isEnabled('unknown-module', 'thing', 'created')).toBe(true);
|
|
119
|
-
});
|
|
120
|
-
it('should include the payload unless a module opts out', ()=>{
|
|
121
|
-
_eventbusregistry.EventBusRegistry.configureModule('storage', {
|
|
122
|
-
enabled: true
|
|
123
|
-
});
|
|
124
|
-
_eventbusregistry.EventBusRegistry.configureModule('auth', {
|
|
125
|
-
enabled: true,
|
|
126
|
-
includePayload: false
|
|
127
|
-
});
|
|
128
|
-
expect(_eventbusregistry.EventBusRegistry.shouldIncludePayload('storage')).toBe(true);
|
|
129
|
-
expect(_eventbusregistry.EventBusRegistry.shouldIncludePayload('auth')).toBe(false);
|
|
130
|
-
});
|
|
131
|
-
it('should clear everything on reset', ()=>{
|
|
132
|
-
_eventbusregistry.EventBusRegistry.configureModule('storage', {
|
|
133
|
-
enabled: true
|
|
134
|
-
});
|
|
135
|
-
_eventbusregistry.EventBusRegistry.reset();
|
|
136
|
-
expect(_eventbusregistry.EventBusRegistry.getBus()).toBeUndefined();
|
|
137
|
-
expect(_eventbusregistry.EventBusRegistry.getModuleConfig('storage')).toEqual({
|
|
138
|
-
enabled: false
|
|
139
|
-
});
|
|
140
|
-
});
|
|
141
|
-
});
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
Object.defineProperty(exports, "EventTransportRegistry", {
|
|
6
|
-
enumerable: true,
|
|
7
|
-
get: function() {
|
|
8
|
-
return EventTransportRegistry;
|
|
9
|
-
}
|
|
10
|
-
});
|
|
11
|
-
function _define_property(obj, key, value) {
|
|
12
|
-
if (key in obj) {
|
|
13
|
-
Object.defineProperty(obj, key, {
|
|
14
|
-
value: value,
|
|
15
|
-
enumerable: true,
|
|
16
|
-
configurable: true,
|
|
17
|
-
writable: true
|
|
18
|
-
});
|
|
19
|
-
} else {
|
|
20
|
-
obj[key] = value;
|
|
21
|
-
}
|
|
22
|
-
return obj;
|
|
23
|
-
}
|
|
24
|
-
let EventTransportRegistry = class EventTransportRegistry {
|
|
25
|
-
static register(name, factory) {
|
|
26
|
-
this.transports.set(name.toLowerCase(), factory);
|
|
27
|
-
}
|
|
28
|
-
static get(name) {
|
|
29
|
-
return this.transports.get(name.toLowerCase());
|
|
30
|
-
}
|
|
31
|
-
static has(name) {
|
|
32
|
-
return this.transports.has(name.toLowerCase());
|
|
33
|
-
}
|
|
34
|
-
static getAll() {
|
|
35
|
-
return Array.from(this.transports.keys());
|
|
36
|
-
}
|
|
37
|
-
static clear() {
|
|
38
|
-
this.transports.clear();
|
|
39
|
-
}
|
|
40
|
-
};
|
|
41
|
-
_define_property(EventTransportRegistry, "transports", new Map());
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
const _eventtransportregistry = require("./event-transport.registry");
|
|
6
|
-
const stubTransport = {};
|
|
7
|
-
describe('EventTransportRegistry', ()=>{
|
|
8
|
-
afterEach(()=>{
|
|
9
|
-
_eventtransportregistry.EventTransportRegistry.clear();
|
|
10
|
-
});
|
|
11
|
-
it('should register and resolve a transport factory', ()=>{
|
|
12
|
-
_eventtransportregistry.EventTransportRegistry.register('rabbitmq', ()=>stubTransport);
|
|
13
|
-
expect(_eventtransportregistry.EventTransportRegistry.get('rabbitmq')({})).toBe(stubTransport);
|
|
14
|
-
});
|
|
15
|
-
it('should resolve case insensitively', ()=>{
|
|
16
|
-
_eventtransportregistry.EventTransportRegistry.register('Kafka', ()=>stubTransport);
|
|
17
|
-
expect(_eventtransportregistry.EventTransportRegistry.has('kafka')).toBe(true);
|
|
18
|
-
});
|
|
19
|
-
it('should return undefined for an unknown transport', ()=>{
|
|
20
|
-
expect(_eventtransportregistry.EventTransportRegistry.get('nats')).toBeUndefined();
|
|
21
|
-
expect(_eventtransportregistry.EventTransportRegistry.has('nats')).toBe(false);
|
|
22
|
-
});
|
|
23
|
-
it('should list every registered transport', ()=>{
|
|
24
|
-
_eventtransportregistry.EventTransportRegistry.register('memory', ()=>stubTransport);
|
|
25
|
-
_eventtransportregistry.EventTransportRegistry.register('kafka', ()=>stubTransport);
|
|
26
|
-
expect(_eventtransportregistry.EventTransportRegistry.getAll().sort()).toEqual([
|
|
27
|
-
'kafka',
|
|
28
|
-
'memory'
|
|
29
|
-
]);
|
|
30
|
-
});
|
|
31
|
-
});
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
_export_star(require("./event-transport.registry"), exports);
|
|
6
|
-
_export_star(require("./memory-transport"), exports);
|
|
7
|
-
function _export_star(from, to) {
|
|
8
|
-
Object.keys(from).forEach(function(k) {
|
|
9
|
-
if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
|
|
10
|
-
Object.defineProperty(to, k, {
|
|
11
|
-
enumerable: true,
|
|
12
|
-
get: function() {
|
|
13
|
-
return from[k];
|
|
14
|
-
}
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
|
-
});
|
|
18
|
-
return from;
|
|
19
|
-
}
|
|
20
|
-
// Note: Broker transports are loaded dynamically by HybridEventBus.
|
|
21
|
-
// Import them directly when registering manually:
|
|
22
|
-
// - import { RabbitMqTransport } from '@flusys/nestjs-shared/classes/event-transports/rabbitmq-transport.optional';
|
|
23
|
-
// - import { KafkaTransport } from '@flusys/nestjs-shared/classes/event-transports/kafka-transport.optional';
|