@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,251 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
const _eventpatternutil = require("./event-pattern.util");
|
|
6
|
-
describe('matchEventPattern', ()=>{
|
|
7
|
-
it('should match an exact event name', ()=>{
|
|
8
|
-
expect((0, _eventpatternutil.matchEventPattern)('storage.folder.created', 'storage.folder.created')).toBe(true);
|
|
9
|
-
});
|
|
10
|
-
it('should not match a different event name', ()=>{
|
|
11
|
-
expect((0, _eventpatternutil.matchEventPattern)('storage.folder.created', 'storage.folder.updated')).toBe(false);
|
|
12
|
-
});
|
|
13
|
-
it('should treat * as exactly one segment', ()=>{
|
|
14
|
-
expect((0, _eventpatternutil.matchEventPattern)('storage.*.created', 'storage.folder.created')).toBe(true);
|
|
15
|
-
expect((0, _eventpatternutil.matchEventPattern)('storage.*', 'storage.folder.created')).toBe(false);
|
|
16
|
-
});
|
|
17
|
-
it('should treat # and ** as any number of segments', ()=>{
|
|
18
|
-
expect((0, _eventpatternutil.matchEventPattern)('storage.#', 'storage.folder.created')).toBe(true);
|
|
19
|
-
expect((0, _eventpatternutil.matchEventPattern)('**', 'auth.appuser.deleted')).toBe(true);
|
|
20
|
-
expect((0, _eventpatternutil.matchEventPattern)('storage.**', 'storage.folder.created')).toBe(true);
|
|
21
|
-
});
|
|
22
|
-
it('should let a multi wildcard match zero segments', ()=>{
|
|
23
|
-
expect((0, _eventpatternutil.matchEventPattern)('storage.folder.created.#', 'storage.folder.created')).toBe(true);
|
|
24
|
-
});
|
|
25
|
-
it('should not match across a different module', ()=>{
|
|
26
|
-
expect((0, _eventpatternutil.matchEventPattern)('storage.#', 'auth.appuser.created')).toBe(false);
|
|
27
|
-
});
|
|
28
|
-
});
|
|
29
|
-
describe('isMultiWildcard', ()=>{
|
|
30
|
-
it.each([
|
|
31
|
-
[
|
|
32
|
-
'#',
|
|
33
|
-
true
|
|
34
|
-
],
|
|
35
|
-
[
|
|
36
|
-
'**',
|
|
37
|
-
true
|
|
38
|
-
],
|
|
39
|
-
[
|
|
40
|
-
'*',
|
|
41
|
-
false
|
|
42
|
-
],
|
|
43
|
-
[
|
|
44
|
-
'folder',
|
|
45
|
-
false
|
|
46
|
-
]
|
|
47
|
-
])('should classify %s as %s', (segment, expected)=>{
|
|
48
|
-
expect((0, _eventpatternutil.isMultiWildcard)(segment)).toBe(expected);
|
|
49
|
-
});
|
|
50
|
-
});
|
|
51
|
-
describe('sanitizeEventPayload', ()=>{
|
|
52
|
-
it('should redact credential-like fields', ()=>{
|
|
53
|
-
const result = (0, _eventpatternutil.sanitizeEventPayload)({
|
|
54
|
-
id: '1',
|
|
55
|
-
password: 'secret',
|
|
56
|
-
apiKey: 'k'
|
|
57
|
-
});
|
|
58
|
-
expect(result).toEqual({
|
|
59
|
-
id: '1',
|
|
60
|
-
password: '[REDACTED]',
|
|
61
|
-
apiKey: '[REDACTED]'
|
|
62
|
-
});
|
|
63
|
-
});
|
|
64
|
-
it('should redact the whole provider settings blob of a storage or email config row', ()=>{
|
|
65
|
-
const result = (0, _eventpatternutil.sanitizeEventPayload)({
|
|
66
|
-
name: 'primary-s3',
|
|
67
|
-
provider: 's3',
|
|
68
|
-
isActive: true,
|
|
69
|
-
config: {
|
|
70
|
-
region: 'us-east-1',
|
|
71
|
-
bucket: 'assets',
|
|
72
|
-
accessKeyId: 'AKIA...',
|
|
73
|
-
secretAccessKey: 's3cr3t'
|
|
74
|
-
}
|
|
75
|
-
});
|
|
76
|
-
expect(result).toEqual({
|
|
77
|
-
name: 'primary-s3',
|
|
78
|
-
provider: 's3',
|
|
79
|
-
isActive: true,
|
|
80
|
-
config: '[REDACTED]'
|
|
81
|
-
});
|
|
82
|
-
});
|
|
83
|
-
it('should redact the credential keys used by the storage and email providers', ()=>{
|
|
84
|
-
const result = (0, _eventpatternutil.sanitizeEventPayload)({
|
|
85
|
-
settings: {
|
|
86
|
-
region: 'us-east-1',
|
|
87
|
-
bucket: 'assets',
|
|
88
|
-
accessKeyId: 'AKIA...',
|
|
89
|
-
secretAccessKey: 's3cr3t',
|
|
90
|
-
accountKey: 'azure-key',
|
|
91
|
-
privateKey: '-----BEGIN...',
|
|
92
|
-
connectionString: 'DefaultEndpointsProtocol=...;AccountKey=abc',
|
|
93
|
-
auth: {
|
|
94
|
-
user: 'mailer',
|
|
95
|
-
pass: 'hunter2'
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
});
|
|
99
|
-
expect(result).toEqual({
|
|
100
|
-
settings: {
|
|
101
|
-
region: 'us-east-1',
|
|
102
|
-
bucket: 'assets',
|
|
103
|
-
accessKeyId: '[REDACTED]',
|
|
104
|
-
secretAccessKey: '[REDACTED]',
|
|
105
|
-
accountKey: '[REDACTED]',
|
|
106
|
-
privateKey: '[REDACTED]',
|
|
107
|
-
connectionString: '[REDACTED]',
|
|
108
|
-
auth: {
|
|
109
|
-
user: 'mailer',
|
|
110
|
-
pass: '[REDACTED]'
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
});
|
|
114
|
-
});
|
|
115
|
-
it('should not over-redact keys that merely contain a credential word', ()=>{
|
|
116
|
-
const result = (0, _eventpatternutil.sanitizeEventPayload)({
|
|
117
|
-
key: 'uploads/2026/report.pdf',
|
|
118
|
-
bypassCache: true,
|
|
119
|
-
passengerCount: 4
|
|
120
|
-
});
|
|
121
|
-
expect(result).toEqual({
|
|
122
|
-
key: 'uploads/2026/report.pdf',
|
|
123
|
-
bypassCache: true,
|
|
124
|
-
passengerCount: 4
|
|
125
|
-
});
|
|
126
|
-
});
|
|
127
|
-
it('should redact nested fields', ()=>{
|
|
128
|
-
const result = (0, _eventpatternutil.sanitizeEventPayload)({
|
|
129
|
-
user: {
|
|
130
|
-
name: 'Ada',
|
|
131
|
-
passwordHash: 'x'
|
|
132
|
-
}
|
|
133
|
-
});
|
|
134
|
-
expect(result).toEqual({
|
|
135
|
-
user: {
|
|
136
|
-
name: 'Ada',
|
|
137
|
-
passwordHash: '[REDACTED]'
|
|
138
|
-
}
|
|
139
|
-
});
|
|
140
|
-
});
|
|
141
|
-
it('should map over arrays', ()=>{
|
|
142
|
-
const result = (0, _eventpatternutil.sanitizeEventPayload)([
|
|
143
|
-
{
|
|
144
|
-
token: 't'
|
|
145
|
-
},
|
|
146
|
-
{
|
|
147
|
-
token: 'u'
|
|
148
|
-
}
|
|
149
|
-
]);
|
|
150
|
-
expect(result).toEqual([
|
|
151
|
-
{
|
|
152
|
-
token: '[REDACTED]'
|
|
153
|
-
},
|
|
154
|
-
{
|
|
155
|
-
token: '[REDACTED]'
|
|
156
|
-
}
|
|
157
|
-
]);
|
|
158
|
-
});
|
|
159
|
-
it('should leave dates and primitives untouched', ()=>{
|
|
160
|
-
const date = new Date('2026-01-01T00:00:00.000Z');
|
|
161
|
-
expect((0, _eventpatternutil.sanitizeEventPayload)({
|
|
162
|
-
createdAt: date,
|
|
163
|
-
count: 3
|
|
164
|
-
})).toEqual({
|
|
165
|
-
createdAt: date,
|
|
166
|
-
count: 3
|
|
167
|
-
});
|
|
168
|
-
});
|
|
169
|
-
it('should mark a circular relation instead of recursing forever', ()=>{
|
|
170
|
-
const folder = {
|
|
171
|
-
id: 'folder-1',
|
|
172
|
-
name: 'Docs'
|
|
173
|
-
};
|
|
174
|
-
const file = {
|
|
175
|
-
id: 'file-1',
|
|
176
|
-
folder
|
|
177
|
-
};
|
|
178
|
-
folder.files = [
|
|
179
|
-
file
|
|
180
|
-
];
|
|
181
|
-
expect((0, _eventpatternutil.sanitizeEventPayload)(folder)).toEqual({
|
|
182
|
-
id: 'folder-1',
|
|
183
|
-
name: 'Docs',
|
|
184
|
-
files: [
|
|
185
|
-
{
|
|
186
|
-
id: 'file-1',
|
|
187
|
-
folder: '[CIRCULAR]'
|
|
188
|
-
}
|
|
189
|
-
]
|
|
190
|
-
});
|
|
191
|
-
});
|
|
192
|
-
it('should survive a self referencing row', ()=>{
|
|
193
|
-
const row = {
|
|
194
|
-
id: '1'
|
|
195
|
-
};
|
|
196
|
-
row.self = row;
|
|
197
|
-
expect(()=>(0, _eventpatternutil.sanitizeEventPayload)(row)).not.toThrow();
|
|
198
|
-
expect((0, _eventpatternutil.sanitizeEventPayload)(row)).toEqual({
|
|
199
|
-
id: '1',
|
|
200
|
-
self: '[CIRCULAR]'
|
|
201
|
-
});
|
|
202
|
-
});
|
|
203
|
-
it('should repeat a shared row rather than calling the second one circular', ()=>{
|
|
204
|
-
const shared = {
|
|
205
|
-
id: 'shared'
|
|
206
|
-
};
|
|
207
|
-
expect((0, _eventpatternutil.sanitizeEventPayload)([
|
|
208
|
-
{
|
|
209
|
-
a: shared
|
|
210
|
-
},
|
|
211
|
-
{
|
|
212
|
-
b: shared
|
|
213
|
-
}
|
|
214
|
-
])).toEqual([
|
|
215
|
-
{
|
|
216
|
-
a: {
|
|
217
|
-
id: 'shared'
|
|
218
|
-
}
|
|
219
|
-
},
|
|
220
|
-
{
|
|
221
|
-
b: {
|
|
222
|
-
id: 'shared'
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
]);
|
|
226
|
-
});
|
|
227
|
-
it('should truncate a graph deeper than the depth cap', ()=>{
|
|
228
|
-
const deep = {};
|
|
229
|
-
let cursor = deep;
|
|
230
|
-
for(let level = 0; level < 12; level++){
|
|
231
|
-
const next = {};
|
|
232
|
-
cursor.child = next;
|
|
233
|
-
cursor = next;
|
|
234
|
-
}
|
|
235
|
-
let result = (0, _eventpatternutil.sanitizeEventPayload)(deep);
|
|
236
|
-
for(let level = 0; level < 7; level++){
|
|
237
|
-
result = result.child;
|
|
238
|
-
}
|
|
239
|
-
expect(result.child).toBe('[TRUNCATED]');
|
|
240
|
-
});
|
|
241
|
-
it('should replace a buffer with a marker instead of exploding it into indexes', ()=>{
|
|
242
|
-
const result = (0, _eventpatternutil.sanitizeEventPayload)({
|
|
243
|
-
id: '1',
|
|
244
|
-
content: Buffer.from('hello')
|
|
245
|
-
});
|
|
246
|
-
expect(result).toEqual({
|
|
247
|
-
id: '1',
|
|
248
|
-
content: '[BINARY]'
|
|
249
|
-
});
|
|
250
|
-
});
|
|
251
|
-
});
|
|
@@ -1,64 +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 escapeHtml () {
|
|
13
|
-
return escapeHtml;
|
|
14
|
-
},
|
|
15
|
-
get escapeHtmlVariables () {
|
|
16
|
-
return escapeHtmlVariables;
|
|
17
|
-
}
|
|
18
|
-
});
|
|
19
|
-
/**
|
|
20
|
-
* HTML Sanitizer Utilities
|
|
21
|
-
*
|
|
22
|
-
* Provides functions for escaping HTML content to prevent XSS attacks.
|
|
23
|
-
* Use these utilities when interpolating user-provided variables into HTML content.
|
|
24
|
-
*/ /**
|
|
25
|
-
* HTML entity mapping for escaping special characters
|
|
26
|
-
*/ const HTML_ESCAPE_MAP = {
|
|
27
|
-
'&': '&',
|
|
28
|
-
'<': '<',
|
|
29
|
-
'>': '>',
|
|
30
|
-
'"': '"',
|
|
31
|
-
"'": ''',
|
|
32
|
-
'/': '/',
|
|
33
|
-
'`': '`',
|
|
34
|
-
'=': '='
|
|
35
|
-
};
|
|
36
|
-
/**
|
|
37
|
-
* Regex pattern matching characters that need HTML escaping
|
|
38
|
-
*/ const HTML_ESCAPE_REGEX = /[&<>"'`=/]/g;
|
|
39
|
-
function escapeHtml(str) {
|
|
40
|
-
if (!str || typeof str !== 'string') {
|
|
41
|
-
return str ?? '';
|
|
42
|
-
}
|
|
43
|
-
return str.replace(HTML_ESCAPE_REGEX, (char)=>HTML_ESCAPE_MAP[char]);
|
|
44
|
-
}
|
|
45
|
-
function escapeHtmlVariables(variables) {
|
|
46
|
-
if (!variables || typeof variables !== 'object') {
|
|
47
|
-
return {};
|
|
48
|
-
}
|
|
49
|
-
const escaped = {};
|
|
50
|
-
for (const [key, value] of Object.entries(variables)){
|
|
51
|
-
if (value === null || value === undefined) {
|
|
52
|
-
escaped[key] = '';
|
|
53
|
-
} else if (typeof value === 'string') {
|
|
54
|
-
escaped[key] = escapeHtml(value);
|
|
55
|
-
} else if (typeof value === 'object') {
|
|
56
|
-
// For objects/arrays, stringify and escape
|
|
57
|
-
escaped[key] = escapeHtml(JSON.stringify(value));
|
|
58
|
-
} else {
|
|
59
|
-
// For numbers, booleans, etc., convert to string (no escaping needed)
|
|
60
|
-
escaped[key] = String(value);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
return escaped;
|
|
64
|
-
}
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
const _htmlsanitizerutil = require("./html-sanitizer.util");
|
|
6
|
-
describe('html-sanitizer.util', ()=>{
|
|
7
|
-
describe('escapeHtml', ()=>{
|
|
8
|
-
it('should escape all special HTML characters', ()=>{
|
|
9
|
-
expect((0, _htmlsanitizerutil.escapeHtml)('<script>alert("xss")</script>')).toBe('<script>alert("xss")</script>');
|
|
10
|
-
});
|
|
11
|
-
it('should escape ampersands', ()=>{
|
|
12
|
-
expect((0, _htmlsanitizerutil.escapeHtml)('a & b')).toBe('a & b');
|
|
13
|
-
});
|
|
14
|
-
it('should escape single quotes, backticks, and equals signs', ()=>{
|
|
15
|
-
expect((0, _htmlsanitizerutil.escapeHtml)(`a='b' c=\`d\``)).toBe('a='b' c=`d`');
|
|
16
|
-
});
|
|
17
|
-
it('should return an empty string for empty input', ()=>{
|
|
18
|
-
expect((0, _htmlsanitizerutil.escapeHtml)('')).toBe('');
|
|
19
|
-
});
|
|
20
|
-
it('should return input unchanged when it has no special characters', ()=>{
|
|
21
|
-
expect((0, _htmlsanitizerutil.escapeHtml)('Hello World 123')).toBe('Hello World 123');
|
|
22
|
-
});
|
|
23
|
-
it('should return non-string input coerced via nullish fallback', ()=>{
|
|
24
|
-
expect((0, _htmlsanitizerutil.escapeHtml)(null)).toBe('');
|
|
25
|
-
expect((0, _htmlsanitizerutil.escapeHtml)(undefined)).toBe('');
|
|
26
|
-
});
|
|
27
|
-
it('should return non-string, truthy input unchanged (not throw)', ()=>{
|
|
28
|
-
// e.g. a number passed at runtime despite the TS signature
|
|
29
|
-
expect((0, _htmlsanitizerutil.escapeHtml)(42)).toBe(42);
|
|
30
|
-
});
|
|
31
|
-
});
|
|
32
|
-
describe('escapeHtmlVariables', ()=>{
|
|
33
|
-
it('should escape string values', ()=>{
|
|
34
|
-
expect((0, _htmlsanitizerutil.escapeHtmlVariables)({
|
|
35
|
-
name: '<b>bold</b>'
|
|
36
|
-
})).toEqual({
|
|
37
|
-
name: '<b>bold</b>'
|
|
38
|
-
});
|
|
39
|
-
});
|
|
40
|
-
it('should convert numbers and booleans to strings without escaping', ()=>{
|
|
41
|
-
expect((0, _htmlsanitizerutil.escapeHtmlVariables)({
|
|
42
|
-
count: 5,
|
|
43
|
-
active: true
|
|
44
|
-
})).toEqual({
|
|
45
|
-
count: '5',
|
|
46
|
-
active: 'true'
|
|
47
|
-
});
|
|
48
|
-
});
|
|
49
|
-
it('should stringify and escape object/array values', ()=>{
|
|
50
|
-
const result = (0, _htmlsanitizerutil.escapeHtmlVariables)({
|
|
51
|
-
meta: {
|
|
52
|
-
a: '<x>'
|
|
53
|
-
}
|
|
54
|
-
});
|
|
55
|
-
expect(result.meta).toBe((0, _htmlsanitizerutil.escapeHtml)(JSON.stringify({
|
|
56
|
-
a: '<x>'
|
|
57
|
-
})));
|
|
58
|
-
});
|
|
59
|
-
it('should convert null/undefined values to empty string', ()=>{
|
|
60
|
-
expect((0, _htmlsanitizerutil.escapeHtmlVariables)({
|
|
61
|
-
a: null,
|
|
62
|
-
b: undefined
|
|
63
|
-
})).toEqual({
|
|
64
|
-
a: '',
|
|
65
|
-
b: ''
|
|
66
|
-
});
|
|
67
|
-
});
|
|
68
|
-
it('should return an empty object for null/non-object input', ()=>{
|
|
69
|
-
expect((0, _htmlsanitizerutil.escapeHtmlVariables)(null)).toEqual({});
|
|
70
|
-
expect((0, _htmlsanitizerutil.escapeHtmlVariables)(undefined)).toEqual({});
|
|
71
|
-
});
|
|
72
|
-
it('should return an empty object for an empty input object', ()=>{
|
|
73
|
-
expect((0, _htmlsanitizerutil.escapeHtmlVariables)({})).toEqual({});
|
|
74
|
-
});
|
|
75
|
-
});
|
|
76
|
-
});
|
package/cjs/utils/index.js
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
_export_star(require("./date-time.util"), exports);
|
|
6
|
-
_export_star(require("./event-pattern.util"), exports);
|
|
7
|
-
_export_star(require("./html-sanitizer.util"), exports);
|
|
8
|
-
_export_star(require("./optional-module.util"), exports);
|
|
9
|
-
_export_star(require("./permission-cache-key.util"), exports);
|
|
10
|
-
_export_star(require("./query-helpers.util"), exports);
|
|
11
|
-
_export_star(require("./request.util"), exports);
|
|
12
|
-
_export_star(require("./string.util"), exports);
|
|
13
|
-
function _export_star(from, to) {
|
|
14
|
-
Object.keys(from).forEach(function(k) {
|
|
15
|
-
if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
|
|
16
|
-
Object.defineProperty(to, k, {
|
|
17
|
-
enumerable: true,
|
|
18
|
-
get: function() {
|
|
19
|
-
return from[k];
|
|
20
|
-
}
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
});
|
|
24
|
-
return from;
|
|
25
|
-
}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Loads an optional peer dependency at runtime.
|
|
3
|
-
*
|
|
4
|
-
* The specifier has to stay invisible to the bundler. A plain `import(name)`
|
|
5
|
-
* looks dynamic in source but webpack rewrites it into a context module rooted
|
|
6
|
-
* at this directory - one that can only ever resolve files sitting next to this
|
|
7
|
-
* one - so `amqplib` and `kafkajs` fail to load in the bundled app no matter how
|
|
8
|
-
* correctly they are installed. Both lookups below are assembled at runtime,
|
|
9
|
-
* where no bundler can rewrite them.
|
|
10
|
-
*
|
|
11
|
-
* `require` is used first because it is what the CommonJS builds actually run
|
|
12
|
-
* on; native ESM has no `require`, and there `import()` is the only way in.
|
|
13
|
-
*/ "use strict";
|
|
14
|
-
Object.defineProperty(exports, "__esModule", {
|
|
15
|
-
value: true
|
|
16
|
-
});
|
|
17
|
-
Object.defineProperty(exports, "loadOptionalModule", {
|
|
18
|
-
enumerable: true,
|
|
19
|
-
get: function() {
|
|
20
|
-
return loadOptionalModule;
|
|
21
|
-
}
|
|
22
|
-
});
|
|
23
|
-
async function loadOptionalModule(name) {
|
|
24
|
-
const runtimeRequire = resolveRuntimeRequire();
|
|
25
|
-
if (runtimeRequire) return runtimeRequire(name);
|
|
26
|
-
const runtimeImport = new Function('specifier', 'return import(specifier);');
|
|
27
|
-
return runtimeImport(name);
|
|
28
|
-
}
|
|
29
|
-
/** Undefined under native ESM and inside a bundle that shadows nothing back */ function resolveRuntimeRequire() {
|
|
30
|
-
try {
|
|
31
|
-
return eval('typeof require === "function" ? require : undefined');
|
|
32
|
-
} catch {
|
|
33
|
-
return undefined;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
const _optionalmoduleutil = require("./optional-module.util");
|
|
6
|
-
describe('loadOptionalModule', ()=>{
|
|
7
|
-
it('should resolve an installed module', async ()=>{
|
|
8
|
-
const events = await (0, _optionalmoduleutil.loadOptionalModule)('events');
|
|
9
|
-
expect(typeof events.EventEmitter).toBe('function');
|
|
10
|
-
});
|
|
11
|
-
it('should reject for a module that is not installed', async ()=>{
|
|
12
|
-
await expect((0, _optionalmoduleutil.loadOptionalModule)('definitely-not-installed-pkg')).rejects.toThrow();
|
|
13
|
-
});
|
|
14
|
-
});
|
|
@@ -1,31 +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 DEFAULT_COMPANY_PERMISSION_KEY_FORMAT () {
|
|
13
|
-
return DEFAULT_COMPANY_PERMISSION_KEY_FORMAT;
|
|
14
|
-
},
|
|
15
|
-
get DEFAULT_USER_PERMISSION_KEY_FORMAT () {
|
|
16
|
-
return DEFAULT_USER_PERMISSION_KEY_FORMAT;
|
|
17
|
-
},
|
|
18
|
-
get buildPermissionCacheKey () {
|
|
19
|
-
return buildPermissionCacheKey;
|
|
20
|
-
}
|
|
21
|
-
});
|
|
22
|
-
const _constants = require("../constants");
|
|
23
|
-
const DEFAULT_USER_PERMISSION_KEY_FORMAT = `${_constants.PERMISSIONS_CACHE_PREFIX}:user:{userId}`;
|
|
24
|
-
const DEFAULT_COMPANY_PERMISSION_KEY_FORMAT = `${_constants.PERMISSIONS_CACHE_PREFIX}:company:{companyId}:branch:{branchId}:user:{userId}`;
|
|
25
|
-
function buildPermissionCacheKey(options, config) {
|
|
26
|
-
const isCompanyScope = Boolean(config?.enableCompanyFeature && options.companyId);
|
|
27
|
-
if (isCompanyScope) {
|
|
28
|
-
return (config?.companyPermissionKeyFormat || DEFAULT_COMPANY_PERMISSION_KEY_FORMAT).replace('{userId}', options.userId).replace('{companyId}', options.companyId).replace('{branchId}', options.branchId || 'null');
|
|
29
|
-
}
|
|
30
|
-
return (config?.userPermissionKeyFormat || DEFAULT_USER_PERMISSION_KEY_FORMAT).replace('{userId}', options.userId);
|
|
31
|
-
}
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
const _permissioncachekeyutil = require("./permission-cache-key.util");
|
|
6
|
-
describe('permission-cache-key.util', ()=>{
|
|
7
|
-
describe('buildPermissionCacheKey', ()=>{
|
|
8
|
-
it('should build a user-scoped key when no config is provided', ()=>{
|
|
9
|
-
const key = (0, _permissioncachekeyutil.buildPermissionCacheKey)({
|
|
10
|
-
userId: 'user-1'
|
|
11
|
-
});
|
|
12
|
-
expect(key).toBe(_permissioncachekeyutil.DEFAULT_USER_PERMISSION_KEY_FORMAT.replace('{userId}', 'user-1'));
|
|
13
|
-
});
|
|
14
|
-
it('should build a user-scoped key when company feature is disabled', ()=>{
|
|
15
|
-
const key = (0, _permissioncachekeyutil.buildPermissionCacheKey)({
|
|
16
|
-
userId: 'user-1',
|
|
17
|
-
companyId: 'company-1'
|
|
18
|
-
}, {
|
|
19
|
-
enableCompanyFeature: false
|
|
20
|
-
});
|
|
21
|
-
expect(key).toBe(_permissioncachekeyutil.DEFAULT_USER_PERMISSION_KEY_FORMAT.replace('{userId}', 'user-1'));
|
|
22
|
-
});
|
|
23
|
-
it('should build a user-scoped key when company feature enabled but no companyId given', ()=>{
|
|
24
|
-
const key = (0, _permissioncachekeyutil.buildPermissionCacheKey)({
|
|
25
|
-
userId: 'user-1'
|
|
26
|
-
}, {
|
|
27
|
-
enableCompanyFeature: true
|
|
28
|
-
});
|
|
29
|
-
expect(key).toBe(_permissioncachekeyutil.DEFAULT_USER_PERMISSION_KEY_FORMAT.replace('{userId}', 'user-1'));
|
|
30
|
-
});
|
|
31
|
-
it('should build a company-scoped key when company feature is enabled and companyId is present', ()=>{
|
|
32
|
-
const key = (0, _permissioncachekeyutil.buildPermissionCacheKey)({
|
|
33
|
-
userId: 'user-1',
|
|
34
|
-
companyId: 'company-1',
|
|
35
|
-
branchId: 'branch-1'
|
|
36
|
-
}, {
|
|
37
|
-
enableCompanyFeature: true
|
|
38
|
-
});
|
|
39
|
-
expect(key).toBe(_permissioncachekeyutil.DEFAULT_COMPANY_PERMISSION_KEY_FORMAT.replace('{userId}', 'user-1').replace('{companyId}', 'company-1').replace('{branchId}', 'branch-1'));
|
|
40
|
-
});
|
|
41
|
-
it('should default branchId placeholder to "null" when branchId is missing', ()=>{
|
|
42
|
-
const key = (0, _permissioncachekeyutil.buildPermissionCacheKey)({
|
|
43
|
-
userId: 'user-1',
|
|
44
|
-
companyId: 'company-1'
|
|
45
|
-
}, {
|
|
46
|
-
enableCompanyFeature: true
|
|
47
|
-
});
|
|
48
|
-
expect(key).toContain(':branch:null:');
|
|
49
|
-
});
|
|
50
|
-
it('should default branchId placeholder to "null" when branchId is explicitly null', ()=>{
|
|
51
|
-
const key = (0, _permissioncachekeyutil.buildPermissionCacheKey)({
|
|
52
|
-
userId: 'user-1',
|
|
53
|
-
companyId: 'company-1',
|
|
54
|
-
branchId: null
|
|
55
|
-
}, {
|
|
56
|
-
enableCompanyFeature: true
|
|
57
|
-
});
|
|
58
|
-
expect(key).toContain(':branch:null:');
|
|
59
|
-
});
|
|
60
|
-
it('should use a custom userPermissionKeyFormat when provided', ()=>{
|
|
61
|
-
const key = (0, _permissioncachekeyutil.buildPermissionCacheKey)({
|
|
62
|
-
userId: 'user-1'
|
|
63
|
-
}, {
|
|
64
|
-
userPermissionKeyFormat: 'custom:{userId}'
|
|
65
|
-
});
|
|
66
|
-
expect(key).toBe('custom:user-1');
|
|
67
|
-
});
|
|
68
|
-
it('should use a custom companyPermissionKeyFormat when provided', ()=>{
|
|
69
|
-
const key = (0, _permissioncachekeyutil.buildPermissionCacheKey)({
|
|
70
|
-
userId: 'user-1',
|
|
71
|
-
companyId: 'company-1'
|
|
72
|
-
}, {
|
|
73
|
-
enableCompanyFeature: true,
|
|
74
|
-
companyPermissionKeyFormat: 'custom:{companyId}:{userId}:{branchId}'
|
|
75
|
-
});
|
|
76
|
-
expect(key).toBe('custom:company-1:user-1:null');
|
|
77
|
-
});
|
|
78
|
-
it('should treat an empty-string companyId as no company scope', ()=>{
|
|
79
|
-
const key = (0, _permissioncachekeyutil.buildPermissionCacheKey)({
|
|
80
|
-
userId: 'user-1',
|
|
81
|
-
companyId: ''
|
|
82
|
-
}, {
|
|
83
|
-
enableCompanyFeature: true
|
|
84
|
-
});
|
|
85
|
-
expect(key).toBe(_permissioncachekeyutil.DEFAULT_USER_PERMISSION_KEY_FORMAT.replace('{userId}', 'user-1'));
|
|
86
|
-
});
|
|
87
|
-
});
|
|
88
|
-
});
|
|
@@ -1,60 +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 applyCompanyFilter () {
|
|
13
|
-
return applyCompanyFilter;
|
|
14
|
-
},
|
|
15
|
-
get buildCompanyWhereCondition () {
|
|
16
|
-
return buildCompanyWhereCondition;
|
|
17
|
-
},
|
|
18
|
-
get hasCompanyId () {
|
|
19
|
-
return hasCompanyId;
|
|
20
|
-
},
|
|
21
|
-
get validateCompanyOwnership () {
|
|
22
|
-
return validateCompanyOwnership;
|
|
23
|
-
}
|
|
24
|
-
});
|
|
25
|
-
const _common = require("@nestjs/common");
|
|
26
|
-
const _constants = require("../constants");
|
|
27
|
-
function applyCompanyFilter(query, config, user) {
|
|
28
|
-
const columnName = config.columnName ?? 'companyId';
|
|
29
|
-
if (config.isCompanyFeatureEnabled && user?.companyId) {
|
|
30
|
-
query.andWhere(`${config.entityAlias}.${columnName} = :companyId`, {
|
|
31
|
-
companyId: user.companyId
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
return query;
|
|
35
|
-
}
|
|
36
|
-
function buildCompanyWhereCondition(baseWhere, isCompanyFeatureEnabled, user) {
|
|
37
|
-
if (isCompanyFeatureEnabled && user?.companyId) {
|
|
38
|
-
return {
|
|
39
|
-
...baseWhere,
|
|
40
|
-
companyId: user.companyId
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
return baseWhere;
|
|
44
|
-
}
|
|
45
|
-
function hasCompanyId(entity) {
|
|
46
|
-
return entity !== null && typeof entity === 'object' && 'companyId' in entity;
|
|
47
|
-
}
|
|
48
|
-
function validateCompanyOwnership(entity, user, isCompanyFeatureEnabled, entityName) {
|
|
49
|
-
if (isCompanyFeatureEnabled && user?.companyId && hasCompanyId(entity)) {
|
|
50
|
-
if (entity.companyId && entity.companyId !== user.companyId) {
|
|
51
|
-
throw new _common.BadRequestException({
|
|
52
|
-
message: `${entityName} belongs to another company`,
|
|
53
|
-
messageKey: _constants.AUTH_MESSAGES.ENTITY_BELOG_ANOTHER_COMPANY,
|
|
54
|
-
messageVariables: {
|
|
55
|
-
entity: entityName
|
|
56
|
-
}
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
}
|