@flusys/nestjs-shared 7.0.2 → 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/constants/permissions.d.ts +12 -0
- 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 -297
- 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 -208
- 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
package/fesm/67.js
ADDED
|
@@ -0,0 +1,808 @@
|
|
|
1
|
+
import * as __rspack_external__flusys_nestjs_core_ff4ca4e2 from "@flusys/nestjs-core";
|
|
2
|
+
import * as __rspack_external__nestjs_core_d7b00a1a from "@nestjs/core";
|
|
3
|
+
import * as __rspack_external_typeorm from "typeorm";
|
|
4
|
+
import * as __rspack_external__keyv_redis_139d03ca from "@keyv/redis";
|
|
5
|
+
import * as __rspack_external_cacheable from "cacheable";
|
|
6
|
+
import * as __rspack_external_keyv from "keyv";
|
|
7
|
+
import * as __rspack_external_events from "events";
|
|
8
|
+
export const __rspack_esm_id = 67;
|
|
9
|
+
export const __rspack_esm_ids = [67];
|
|
10
|
+
export const __webpack_modules__ = {
|
|
11
|
+
864(__unused_rspack_module, __webpack_exports__, __webpack_require__) {
|
|
12
|
+
/**
|
|
13
|
+
* Stands in for HybridEventBus when the subsystem is switched off.
|
|
14
|
+
*
|
|
15
|
+
* Injecting `EVENT_BUS_INSTANCE` keeps working, so turning events off cannot
|
|
16
|
+
* break a provider's dependencies, but nothing here can ever open a broker
|
|
17
|
+
* connection or run a handler.
|
|
18
|
+
*/ class DisabledEventBus {
|
|
19
|
+
async publish(_event) {}
|
|
20
|
+
async subscribe(_pattern, _handler) {}
|
|
21
|
+
async close() {}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
25
|
+
X: () => (DisabledEventBus)
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
},
|
|
30
|
+
228(__unused_rspack_module, __webpack_exports__, __webpack_require__) {
|
|
31
|
+
/* import */ var _utils_event_pattern_util_js__rspack_import_0 = __webpack_require__(456);
|
|
32
|
+
|
|
33
|
+
const DISABLED = {
|
|
34
|
+
enabled: false
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Ambient access point for the event bus.
|
|
38
|
+
*
|
|
39
|
+
* ApiService is request scoped and is extended by every feature package, so the
|
|
40
|
+
* bus is resolved from here instead of being threaded through 20+ constructors.
|
|
41
|
+
* Services may still receive a bus explicitly - that instance wins.
|
|
42
|
+
*/ class EventBusRegistry {
|
|
43
|
+
static bus;
|
|
44
|
+
static moduleConfigs = new Map();
|
|
45
|
+
static defaultConfig = DISABLED;
|
|
46
|
+
static setBus(bus) {
|
|
47
|
+
this.bus = bus;
|
|
48
|
+
}
|
|
49
|
+
static getBus() {
|
|
50
|
+
return this.bus;
|
|
51
|
+
}
|
|
52
|
+
static setDefaultModuleEvents(config) {
|
|
53
|
+
this.defaultConfig = config ?? DISABLED;
|
|
54
|
+
}
|
|
55
|
+
/** Called by each feature module with the `events` block from its own config */ static configureModule(moduleName, config) {
|
|
56
|
+
this.moduleConfigs.set(moduleName, config ?? DISABLED);
|
|
57
|
+
}
|
|
58
|
+
static getModuleConfig(moduleName) {
|
|
59
|
+
if (!moduleName) return this.defaultConfig;
|
|
60
|
+
return this.moduleConfigs.get(moduleName) ?? this.defaultConfig;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Answers only "is this module configured to publish this" - whether a bus
|
|
64
|
+
* exists is the publisher's concern, so an explicitly supplied bus is still
|
|
65
|
+
* held to the module's own on/off switch.
|
|
66
|
+
*/ static isEnabled(moduleName, entity, action) {
|
|
67
|
+
const config = this.getModuleConfig(moduleName);
|
|
68
|
+
if (!config.enabled) return false;
|
|
69
|
+
// Without an explicit allowlist, CRUD lifecycle actions and every domain
|
|
70
|
+
// action a package defines are all published.
|
|
71
|
+
if (!config.actions?.length) return true;
|
|
72
|
+
return config.actions.some((entry)=>entry.includes('.') ? (0,_utils_event_pattern_util_js__rspack_import_0/* .matchEventPattern */.qe)(entry, `${entity}.${action}`) : (0,_utils_event_pattern_util_js__rspack_import_0/* .matchEventPattern */.qe)(entry, action));
|
|
73
|
+
}
|
|
74
|
+
static shouldIncludePayload(moduleName) {
|
|
75
|
+
return this.getModuleConfig(moduleName).includePayload ?? true;
|
|
76
|
+
}
|
|
77
|
+
static reset() {
|
|
78
|
+
this.bus = undefined;
|
|
79
|
+
this.moduleConfigs.clear();
|
|
80
|
+
this.defaultConfig = DISABLED;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
85
|
+
q: () => (EventBusRegistry)
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
},
|
|
90
|
+
149(__unused_rspack_module, __webpack_exports__, __webpack_require__) {
|
|
91
|
+
/**
|
|
92
|
+
* Static registry for event transports.
|
|
93
|
+
* Broker transports register themselves on import so nestjs-shared never has to
|
|
94
|
+
* depend on `amqplib` or `kafkajs` at build time.
|
|
95
|
+
*/ class EventTransportRegistry {
|
|
96
|
+
static transports = new Map();
|
|
97
|
+
static register(name, factory) {
|
|
98
|
+
this.transports.set(name.toLowerCase(), factory);
|
|
99
|
+
}
|
|
100
|
+
static get(name) {
|
|
101
|
+
return this.transports.get(name.toLowerCase());
|
|
102
|
+
}
|
|
103
|
+
static has(name) {
|
|
104
|
+
return this.transports.has(name.toLowerCase());
|
|
105
|
+
}
|
|
106
|
+
static getAll() {
|
|
107
|
+
return Array.from(this.transports.keys());
|
|
108
|
+
}
|
|
109
|
+
static clear() {
|
|
110
|
+
this.transports.clear();
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
115
|
+
P: () => (EventTransportRegistry)
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
},
|
|
120
|
+
346(__unused_rspack_module, __webpack_exports__, __webpack_require__) {
|
|
121
|
+
|
|
122
|
+
// EXPORTS
|
|
123
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
124
|
+
P: () => (/* binding */ MemoryTransport)
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
;// CONCATENATED MODULE: external "events"
|
|
128
|
+
|
|
129
|
+
;// CONCATENATED MODULE: ./projects/nestjs-shared/src/classes/event-transports/memory-transport.ts
|
|
130
|
+
|
|
131
|
+
const CHANNEL = 'domain-event';
|
|
132
|
+
const MAX_LISTENERS = 100;
|
|
133
|
+
/**
|
|
134
|
+
* In-process transport. Always available, needs no broker, and is the default.
|
|
135
|
+
*
|
|
136
|
+
* HybridEventBus constructs it directly rather than through
|
|
137
|
+
* EventTransportRegistry, which exists for the broker transports it must not
|
|
138
|
+
* depend on at build time.
|
|
139
|
+
*/ class MemoryTransport {
|
|
140
|
+
name = 'memory';
|
|
141
|
+
emitter = new __rspack_external_events.EventEmitter();
|
|
142
|
+
ready = false;
|
|
143
|
+
constructor(){
|
|
144
|
+
this.emitter.setMaxListeners(MAX_LISTENERS);
|
|
145
|
+
}
|
|
146
|
+
async connect() {
|
|
147
|
+
this.ready = true;
|
|
148
|
+
}
|
|
149
|
+
async publish(event) {
|
|
150
|
+
this.emitter.emit(CHANNEL, event);
|
|
151
|
+
}
|
|
152
|
+
async bind(_pattern) {}
|
|
153
|
+
onMessage(handler) {
|
|
154
|
+
this.emitter.on(CHANNEL, (event)=>{
|
|
155
|
+
void handler(event);
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
async close() {
|
|
159
|
+
this.emitter.removeAllListeners();
|
|
160
|
+
this.ready = false;
|
|
161
|
+
}
|
|
162
|
+
isReady() {
|
|
163
|
+
return this.ready;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
},
|
|
169
|
+
375(__unused_rspack_module, __webpack_exports__, __webpack_require__) {
|
|
170
|
+
|
|
171
|
+
// EXPORTS
|
|
172
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
173
|
+
l: () => (/* binding */ HybridCache)
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
// EXTERNAL MODULE: external "@flusys/nestjs-core/config"
|
|
177
|
+
var config_ = __webpack_require__(307);
|
|
178
|
+
;// CONCATENATED MODULE: external "@keyv/redis"
|
|
179
|
+
|
|
180
|
+
;// CONCATENATED MODULE: external "cacheable"
|
|
181
|
+
|
|
182
|
+
;// CONCATENATED MODULE: external "keyv"
|
|
183
|
+
|
|
184
|
+
;// CONCATENATED MODULE: ./projects/nestjs-shared/src/classes/hybrid-cache.class.ts
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
class HybridCache {
|
|
190
|
+
memory;
|
|
191
|
+
redis;
|
|
192
|
+
constructor(memoryTtl = 60 * 1000, memorySize = 5000){
|
|
193
|
+
// Default to 'memory' if not specified
|
|
194
|
+
const useCacheLabel = config_.envConfig.tryGetValue('USE_CACHE_LABEL', false) || 'memory';
|
|
195
|
+
if (useCacheLabel === 'memory' || useCacheLabel === 'hybrid') {
|
|
196
|
+
this.memory = new __rspack_external_keyv["default"]({
|
|
197
|
+
store: new __rspack_external_cacheable.CacheableMemory({
|
|
198
|
+
ttl: memoryTtl,
|
|
199
|
+
lruSize: memorySize
|
|
200
|
+
})
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
if (useCacheLabel === 'redis' || useCacheLabel === 'hybrid') {
|
|
204
|
+
this.redis = new __rspack_external_keyv["default"]({
|
|
205
|
+
store: new __rspack_external__keyv_redis_139d03ca["default"](config_.envConfig.getRedisUrl())
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
async get(key) {
|
|
210
|
+
// Prefer memory first if available
|
|
211
|
+
if (this.memory) {
|
|
212
|
+
const value = await this.memory.get(key);
|
|
213
|
+
if (value !== undefined) return value;
|
|
214
|
+
}
|
|
215
|
+
// Fallback to redis
|
|
216
|
+
if (this.redis) {
|
|
217
|
+
const value = await this.redis.get(key);
|
|
218
|
+
if (value !== undefined && this.memory) {
|
|
219
|
+
// backfill L1 memory cache
|
|
220
|
+
await this.memory.set(key, value);
|
|
221
|
+
}
|
|
222
|
+
return value;
|
|
223
|
+
}
|
|
224
|
+
return undefined;
|
|
225
|
+
}
|
|
226
|
+
async set(key, value, ttl) {
|
|
227
|
+
if (this.memory) {
|
|
228
|
+
await this.memory.set(key, value, ttl);
|
|
229
|
+
}
|
|
230
|
+
if (this.redis) {
|
|
231
|
+
await this.redis.set(key, value, ttl);
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
async del(key) {
|
|
235
|
+
if (this.memory) {
|
|
236
|
+
await this.memory.delete(key);
|
|
237
|
+
}
|
|
238
|
+
if (this.redis) {
|
|
239
|
+
await this.redis.delete(key);
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
async reset() {
|
|
243
|
+
if (this.memory) {
|
|
244
|
+
await this.memory.clear();
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
async resetL2() {
|
|
248
|
+
if (this.redis) {
|
|
249
|
+
await this.redis.clear();
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
|
|
255
|
+
},
|
|
256
|
+
710(__unused_rspack_module, __webpack_exports__, __webpack_require__) {
|
|
257
|
+
/* import */ var _flusys_nestjs_core_config__rspack_import_0 = __webpack_require__(307);
|
|
258
|
+
/* import */ var _nestjs_common__rspack_import_1 = __webpack_require__(157);
|
|
259
|
+
/* import */ var _utils_event_pattern_util_js__rspack_import_4 = __webpack_require__(456);
|
|
260
|
+
/* import */ var _event_transports_event_transport_registry_js__rspack_import_2 = __webpack_require__(149);
|
|
261
|
+
/* import */ var _event_transports_memory_transport_js__rspack_import_3 = __webpack_require__(346);
|
|
262
|
+
|
|
263
|
+
|
|
264
|
+
|
|
265
|
+
|
|
266
|
+
|
|
267
|
+
const DEFAULT_DEDUPE_SIZE = 5000;
|
|
268
|
+
/**
|
|
269
|
+
* Event counterpart of HybridCache: one wrapper, transport chosen by configuration.
|
|
270
|
+
*
|
|
271
|
+
* - `memory` in-process only, no broker required (default)
|
|
272
|
+
* - `rabbitmq` topic exchange, cross-service
|
|
273
|
+
* - `kafka` single topic, cross-service
|
|
274
|
+
* - `hybrid` both, with duplicate delivery suppressed by event id
|
|
275
|
+
*/ class HybridEventBus {
|
|
276
|
+
options;
|
|
277
|
+
logger = new _nestjs_common__rspack_import_1.Logger(HybridEventBus.name);
|
|
278
|
+
subscriptions = [];
|
|
279
|
+
transports = [];
|
|
280
|
+
boundPatterns = new Set();
|
|
281
|
+
seenIds = new Set();
|
|
282
|
+
seenOrder = [];
|
|
283
|
+
label;
|
|
284
|
+
dedupeSize;
|
|
285
|
+
memory;
|
|
286
|
+
connecting;
|
|
287
|
+
connected = false;
|
|
288
|
+
constructor(options = {}){
|
|
289
|
+
this.options = options;
|
|
290
|
+
this.label = options.transport ?? this.resolveLabelFromEnv();
|
|
291
|
+
this.dedupeSize = options.dedupeSize ?? DEFAULT_DEDUPE_SIZE;
|
|
292
|
+
}
|
|
293
|
+
getTransportLabel() {
|
|
294
|
+
return this.label;
|
|
295
|
+
}
|
|
296
|
+
getActiveTransports() {
|
|
297
|
+
return this.transports.map((transport)=>transport.name);
|
|
298
|
+
}
|
|
299
|
+
async connect() {
|
|
300
|
+
if (this.connected) return;
|
|
301
|
+
if (!this.connecting) {
|
|
302
|
+
this.connecting = this.buildTransports().catch((error)=>{
|
|
303
|
+
// A cached rejection would leave the bus dead for the process lifetime
|
|
304
|
+
this.connecting = undefined;
|
|
305
|
+
throw error;
|
|
306
|
+
});
|
|
307
|
+
}
|
|
308
|
+
await this.connecting;
|
|
309
|
+
this.connected = true;
|
|
310
|
+
}
|
|
311
|
+
async publish(event) {
|
|
312
|
+
if (!await this.ensureConnected()) return;
|
|
313
|
+
await Promise.all(this.transports.map((transport)=>transport.publish(event).catch((error)=>{
|
|
314
|
+
this.logger.warn(`Publish failed on ${transport.name}: ${error.message}`);
|
|
315
|
+
})));
|
|
316
|
+
}
|
|
317
|
+
async subscribe(pattern, handler) {
|
|
318
|
+
this.subscriptions.push({
|
|
319
|
+
pattern,
|
|
320
|
+
handler: handler
|
|
321
|
+
});
|
|
322
|
+
if (!await this.ensureConnected()) return;
|
|
323
|
+
await this.bindSubscriptions();
|
|
324
|
+
}
|
|
325
|
+
async close() {
|
|
326
|
+
await Promise.allSettled(this.transports.map((transport)=>transport.close()));
|
|
327
|
+
this.transports.length = 0;
|
|
328
|
+
this.subscriptions.length = 0;
|
|
329
|
+
this.boundPatterns.clear();
|
|
330
|
+
this.seenIds.clear();
|
|
331
|
+
this.seenOrder.length = 0;
|
|
332
|
+
this.memory = undefined;
|
|
333
|
+
this.connecting = undefined;
|
|
334
|
+
this.connected = false;
|
|
335
|
+
}
|
|
336
|
+
// ─── Private Helpers ────────────────────────────────────────────────────────
|
|
337
|
+
/**
|
|
338
|
+
* Connecting must never throw at the call site - a bus that cannot start is
|
|
339
|
+
* a degraded system, not a failed request. The next call retries.
|
|
340
|
+
*/ async ensureConnected() {
|
|
341
|
+
try {
|
|
342
|
+
await this.connect();
|
|
343
|
+
return true;
|
|
344
|
+
} catch (error) {
|
|
345
|
+
const message = error instanceof Error ? error.message : 'Unknown error';
|
|
346
|
+
this.logger.error(`Event bus is not available: ${message}`);
|
|
347
|
+
return false;
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
resolveLabelFromEnv() {
|
|
351
|
+
const value = _flusys_nestjs_core_config__rspack_import_0.envConfig.tryGetValue('USE_EVENT_LABEL', false) || 'memory';
|
|
352
|
+
return value;
|
|
353
|
+
}
|
|
354
|
+
async buildTransports() {
|
|
355
|
+
// Fresh transports know nothing of what was bound on the ones they replace
|
|
356
|
+
this.boundPatterns.clear();
|
|
357
|
+
if (this.label === 'memory' || this.label === 'hybrid') {
|
|
358
|
+
this.memory = new _event_transports_memory_transport_js__rspack_import_3/* .MemoryTransport */.P();
|
|
359
|
+
await this.memory.connect();
|
|
360
|
+
this.registerTransport(this.memory);
|
|
361
|
+
}
|
|
362
|
+
if (this.label !== 'memory') {
|
|
363
|
+
const broker = await this.createBrokerTransport(this.label);
|
|
364
|
+
if (broker) {
|
|
365
|
+
this.registerTransport(broker);
|
|
366
|
+
} else {
|
|
367
|
+
this.logger.error(`Event transport '${this.label}' was requested but is unavailable - delivering ` + `in-process only, so no event will reach another service. Check the broker URL ` + `and that its driver is installed.`);
|
|
368
|
+
if (!this.memory) {
|
|
369
|
+
this.memory = new _event_transports_memory_transport_js__rspack_import_3/* .MemoryTransport */.P();
|
|
370
|
+
await this.memory.connect();
|
|
371
|
+
this.registerTransport(this.memory);
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
await this.bindSubscriptions();
|
|
376
|
+
}
|
|
377
|
+
/**
|
|
378
|
+
* Binds every pattern the bus knows about, skipping the ones already bound.
|
|
379
|
+
*
|
|
380
|
+
* Called once the transports are built, not only from `subscribe`: a
|
|
381
|
+
* subscription taken while the bus was down returns before any transport
|
|
382
|
+
* exists, so nothing would ever bind its routing key on the broker that
|
|
383
|
+
* finally comes up, leaving the process publishing but never consuming.
|
|
384
|
+
*/ async bindSubscriptions() {
|
|
385
|
+
for (const { pattern } of this.subscriptions){
|
|
386
|
+
if (this.boundPatterns.has(pattern)) continue;
|
|
387
|
+
this.boundPatterns.add(pattern);
|
|
388
|
+
await Promise.all(this.transports.map((transport)=>transport.bind(pattern).catch((error)=>{
|
|
389
|
+
this.logger.warn(`Bind failed on ${transport.name}: ${error.message}`);
|
|
390
|
+
})));
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
async createBrokerTransport(label) {
|
|
394
|
+
const name = label === 'hybrid' ? this.resolveHybridBrokerName() : label;
|
|
395
|
+
try {
|
|
396
|
+
await this.loadOptionalTransport(name);
|
|
397
|
+
const factory = _event_transports_event_transport_registry_js__rspack_import_2/* .EventTransportRegistry.get */.P.get(name);
|
|
398
|
+
if (!factory) {
|
|
399
|
+
this.logger.error(`Event transport '${name}' is not registered. Available: ${_event_transports_event_transport_registry_js__rspack_import_2/* .EventTransportRegistry.getAll */.P.getAll().join(', ')}`);
|
|
400
|
+
return undefined;
|
|
401
|
+
}
|
|
402
|
+
const transport = factory(this.getTransportConfig(name));
|
|
403
|
+
await transport.connect();
|
|
404
|
+
return transport;
|
|
405
|
+
} catch (error) {
|
|
406
|
+
const message = error instanceof Error ? error.message : 'Unknown error';
|
|
407
|
+
this.logger.error(`Failed to start the '${name}' event transport: ${message}`);
|
|
408
|
+
return undefined;
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
resolveHybridBrokerName() {
|
|
412
|
+
return _flusys_nestjs_core_config__rspack_import_0.envConfig.tryGetValue('EVENT_BROKER', false) || 'rabbitmq';
|
|
413
|
+
}
|
|
414
|
+
/**
|
|
415
|
+
* Registers explicitly rather than relying on the transport file's own
|
|
416
|
+
* side effect, which a tree shaking bundler is free to drop.
|
|
417
|
+
*/ async loadOptionalTransport(name) {
|
|
418
|
+
if (_event_transports_event_transport_registry_js__rspack_import_2/* .EventTransportRegistry.has */.P.has(name)) return;
|
|
419
|
+
if (name === 'rabbitmq') {
|
|
420
|
+
const { RabbitMqTransport } = await __webpack_require__.e(/* import() */ 123).then(__webpack_require__.bind(__webpack_require__, 46));
|
|
421
|
+
_event_transports_event_transport_registry_js__rspack_import_2/* .EventTransportRegistry.register */.P.register('rabbitmq', (config)=>new RabbitMqTransport(config));
|
|
422
|
+
return;
|
|
423
|
+
}
|
|
424
|
+
if (name === 'kafka') {
|
|
425
|
+
const { KafkaTransport } = await __webpack_require__.e(/* import() */ 37).then(__webpack_require__.bind(__webpack_require__, 20));
|
|
426
|
+
_event_transports_event_transport_registry_js__rspack_import_2/* .EventTransportRegistry.register */.P.register('kafka', (config)=>new KafkaTransport(config));
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
getTransportConfig(name) {
|
|
430
|
+
if (name === 'rabbitmq') {
|
|
431
|
+
return {
|
|
432
|
+
url: _flusys_nestjs_core_config__rspack_import_0.envConfig.tryGetValue('RABBITMQ_URL', false) || undefined,
|
|
433
|
+
queue: this.options.serviceName ? `${this.options.serviceName}.events` : undefined,
|
|
434
|
+
...this.options.rabbitmq
|
|
435
|
+
};
|
|
436
|
+
}
|
|
437
|
+
if (name === 'kafka') {
|
|
438
|
+
return {
|
|
439
|
+
brokers: this.parseBrokers(_flusys_nestjs_core_config__rspack_import_0.envConfig.tryGetValue('KAFKA_BROKERS', false)),
|
|
440
|
+
clientId: this.options.serviceName,
|
|
441
|
+
groupId: this.options.serviceName ? `${this.options.serviceName}-events` : undefined,
|
|
442
|
+
...this.options.kafka
|
|
443
|
+
};
|
|
444
|
+
}
|
|
445
|
+
return {};
|
|
446
|
+
}
|
|
447
|
+
parseBrokers(value) {
|
|
448
|
+
if (!value) return undefined;
|
|
449
|
+
return value.split(',').map((broker)=>broker.trim()).filter(Boolean);
|
|
450
|
+
}
|
|
451
|
+
registerTransport(transport) {
|
|
452
|
+
transport.onMessage((event)=>this.dispatch(event));
|
|
453
|
+
this.transports.push(transport);
|
|
454
|
+
}
|
|
455
|
+
async dispatch(event) {
|
|
456
|
+
if (this.isDuplicate(event.id)) return;
|
|
457
|
+
const matched = this.subscriptions.filter((subscription)=>(0,_utils_event_pattern_util_js__rspack_import_4/* .matchEventPattern */.qe)(subscription.pattern, event.name));
|
|
458
|
+
await Promise.all(matched.map(async (subscription)=>{
|
|
459
|
+
try {
|
|
460
|
+
await subscription.handler(event);
|
|
461
|
+
} catch (error) {
|
|
462
|
+
const message = error instanceof Error ? error.message : 'Unknown error';
|
|
463
|
+
this.logger.error(`Handler for '${subscription.pattern}' failed: ${message}`);
|
|
464
|
+
}
|
|
465
|
+
}));
|
|
466
|
+
}
|
|
467
|
+
isDuplicate(eventId) {
|
|
468
|
+
if (!eventId) return false;
|
|
469
|
+
if (this.seenIds.has(eventId)) return true;
|
|
470
|
+
this.seenIds.add(eventId);
|
|
471
|
+
this.seenOrder.push(eventId);
|
|
472
|
+
if (this.seenOrder.length > this.dedupeSize) {
|
|
473
|
+
const evicted = this.seenOrder.shift();
|
|
474
|
+
if (evicted) this.seenIds.delete(evicted);
|
|
475
|
+
}
|
|
476
|
+
return false;
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
481
|
+
Z: () => (HybridEventBus)
|
|
482
|
+
});
|
|
483
|
+
|
|
484
|
+
|
|
485
|
+
},
|
|
486
|
+
657(__unused_rspack_module, __webpack_exports__, __webpack_require__) {
|
|
487
|
+
/* import */ var _nestjs_common__rspack_import_0 = __webpack_require__(157);
|
|
488
|
+
/* import */ var _classes_hybrid_cache_class_js__rspack_import_1 = __webpack_require__(375);
|
|
489
|
+
/* import */ var _constants_index_js__rspack_import_3 = __webpack_require__(43);
|
|
490
|
+
/* import */ var _utils_permission_cache_key_util_js__rspack_import_2 = __webpack_require__(199);
|
|
491
|
+
function _ts_decorate(decorators, target, key, desc) {
|
|
492
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
493
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
|
|
494
|
+
r = Reflect.decorate(decorators, target, key, desc);
|
|
495
|
+
} else {
|
|
496
|
+
for(var i = decorators.length - 1; i >= 0; i--){
|
|
497
|
+
if (d = decorators[i]) {
|
|
498
|
+
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
503
|
+
}
|
|
504
|
+
function _ts_metadata(metadataKey, metadataValue) {
|
|
505
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
|
|
506
|
+
return Reflect.metadata(metadataKey, metadataValue);
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
function _ts_param(paramIndex, decorator) {
|
|
510
|
+
return function(target, key) {
|
|
511
|
+
decorator(target, key, paramIndex);
|
|
512
|
+
};
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
|
|
516
|
+
|
|
517
|
+
|
|
518
|
+
class SharedPermissionCacheService {
|
|
519
|
+
cache;
|
|
520
|
+
config;
|
|
521
|
+
constructor(cache, config){
|
|
522
|
+
this.cache = cache;
|
|
523
|
+
this.config = {
|
|
524
|
+
enableCompanyFeature: false,
|
|
525
|
+
userPermissionKeyFormat: _utils_permission_cache_key_util_js__rspack_import_2/* .DEFAULT_USER_PERMISSION_KEY_FORMAT */.q6,
|
|
526
|
+
companyPermissionKeyFormat: _utils_permission_cache_key_util_js__rspack_import_2/* .DEFAULT_COMPANY_PERMISSION_KEY_FORMAT */.s8,
|
|
527
|
+
...config
|
|
528
|
+
};
|
|
529
|
+
}
|
|
530
|
+
/** Read the cached permission codes for a user; empty array when cache is unavailable or unset */ async getPermissions(options) {
|
|
531
|
+
if (!this.cache) return [];
|
|
532
|
+
const cacheKey = (0,_utils_permission_cache_key_util_js__rspack_import_2/* .buildPermissionCacheKey */.nt)(options, this.config);
|
|
533
|
+
const cached = await this.cache.get(cacheKey);
|
|
534
|
+
if (!cached) return [];
|
|
535
|
+
return Array.isArray(cached) ? cached : cached.backendCodes || [];
|
|
536
|
+
}
|
|
537
|
+
/** Overwrite the cached permission codes for a user with a fixed list */ async setPermissions(options, permissions, ttl) {
|
|
538
|
+
if (!this.cache) return;
|
|
539
|
+
const cacheKey = (0,_utils_permission_cache_key_util_js__rspack_import_2/* .buildPermissionCacheKey */.nt)(options, this.config);
|
|
540
|
+
await this.cache.set(cacheKey, permissions, ttl);
|
|
541
|
+
}
|
|
542
|
+
/** Clear the cached permission codes for a user */ async clearPermissions(options) {
|
|
543
|
+
if (!this.cache) return;
|
|
544
|
+
const cacheKey = (0,_utils_permission_cache_key_util_js__rspack_import_2/* .buildPermissionCacheKey */.nt)(options, this.config);
|
|
545
|
+
await this.cache.del(cacheKey);
|
|
546
|
+
}
|
|
547
|
+
/** Check a single permission against the cached list, honoring `*` and `prefix.*` wildcards */ async hasPermission(options, requiredPermission) {
|
|
548
|
+
const permissions = await this.getPermissions(options);
|
|
549
|
+
return this.matchPermission(permissions, requiredPermission);
|
|
550
|
+
}
|
|
551
|
+
/** Whether a cache instance is wired up; false means permission checks can't be served at all */ isCacheConfigured() {
|
|
552
|
+
return !!this.cache;
|
|
553
|
+
}
|
|
554
|
+
/** Match an already-fetched permission list against a required permission, honoring `*` and `prefix.*` wildcards */ matchPermission(userPermissions, requiredPermission) {
|
|
555
|
+
if (userPermissions.includes(requiredPermission)) return true;
|
|
556
|
+
for (const permission of userPermissions){
|
|
557
|
+
if (permission === '*') return true;
|
|
558
|
+
if (permission.endsWith('.*') && requiredPermission.startsWith(permission.slice(0, -1))) {
|
|
559
|
+
return true;
|
|
560
|
+
}
|
|
561
|
+
}
|
|
562
|
+
return false;
|
|
563
|
+
}
|
|
564
|
+
}
|
|
565
|
+
SharedPermissionCacheService = _ts_decorate([
|
|
566
|
+
(0,_nestjs_common__rspack_import_0.Injectable)(),
|
|
567
|
+
_ts_param(0, (0,_nestjs_common__rspack_import_0.Optional)()),
|
|
568
|
+
_ts_param(0, (0,_nestjs_common__rspack_import_0.Inject)(_constants_index_js__rspack_import_3/* .CACHE_INSTANCE */.zl)),
|
|
569
|
+
_ts_param(1, (0,_nestjs_common__rspack_import_0.Optional)()),
|
|
570
|
+
_ts_param(1, (0,_nestjs_common__rspack_import_0.Inject)(_constants_index_js__rspack_import_3/* .PERMISSION_GUARD_CONFIG */.Lw)),
|
|
571
|
+
_ts_metadata("design:type", Function),
|
|
572
|
+
_ts_metadata("design:paramtypes", [
|
|
573
|
+
typeof _classes_hybrid_cache_class_js__rspack_import_1/* .HybridCache */.l === "undefined" ? Object : _classes_hybrid_cache_class_js__rspack_import_1/* .HybridCache */.l,
|
|
574
|
+
typeof PermissionGuardConfig === "undefined" ? Object : PermissionGuardConfig
|
|
575
|
+
])
|
|
576
|
+
], SharedPermissionCacheService);
|
|
577
|
+
|
|
578
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
579
|
+
U: () => (SharedPermissionCacheService)
|
|
580
|
+
});
|
|
581
|
+
|
|
582
|
+
|
|
583
|
+
},
|
|
584
|
+
169(__unused_rspack_module, __webpack_exports__, __webpack_require__) {
|
|
585
|
+
/* import */ var _nestjs_common__rspack_import_0 = __webpack_require__(157);
|
|
586
|
+
function _ts_decorate(decorators, target, key, desc) {
|
|
587
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
588
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
|
|
589
|
+
r = Reflect.decorate(decorators, target, key, desc);
|
|
590
|
+
} else {
|
|
591
|
+
for(var i = decorators.length - 1; i >= 0; i--){
|
|
592
|
+
if (d = decorators[i]) {
|
|
593
|
+
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
594
|
+
}
|
|
595
|
+
}
|
|
596
|
+
}
|
|
597
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
class UtilsService {
|
|
601
|
+
// ---------------- CACHE HELPERS ----------------
|
|
602
|
+
/**
|
|
603
|
+
* Generate cache key with optional tenant prefix for multi-tenant isolation
|
|
604
|
+
*/ getCacheKey(entityName, params, entityId, tenantId) {
|
|
605
|
+
const prefix = this.buildTenantPrefix(tenantId);
|
|
606
|
+
if (entityId) {
|
|
607
|
+
return `${prefix}entity_${entityName}_id_${entityId}${params ? '_select_' + JSON.stringify(params) : ''}`;
|
|
608
|
+
}
|
|
609
|
+
return `${prefix}entity_${entityName}_all_${JSON.stringify(params)}`;
|
|
610
|
+
}
|
|
611
|
+
/**
|
|
612
|
+
* Track cache key for later invalidation with optional tenant prefix
|
|
613
|
+
*/ async trackCacheKey(cacheKey, entityName, cacheManager, entityId, tenantId) {
|
|
614
|
+
try {
|
|
615
|
+
const trackingKey = this.buildTrackingKey(entityName, entityId, tenantId);
|
|
616
|
+
const keys = await cacheManager.get(trackingKey) || [];
|
|
617
|
+
if (!keys.includes(cacheKey)) keys.push(cacheKey);
|
|
618
|
+
await cacheManager.set(trackingKey, keys);
|
|
619
|
+
} catch {
|
|
620
|
+
// Silent failure - cache tracking is non-critical
|
|
621
|
+
}
|
|
622
|
+
}
|
|
623
|
+
/**
|
|
624
|
+
* Clear cache for entity with optional tenant prefix
|
|
625
|
+
*/ async clearCache(entityName, cacheManager, entityId, tenantId) {
|
|
626
|
+
try {
|
|
627
|
+
const trackingKey = this.buildTrackingKey(entityName, entityId, tenantId);
|
|
628
|
+
const keys = await cacheManager.get(trackingKey) || [];
|
|
629
|
+
await Promise.allSettled(keys.map((key)=>cacheManager.del(key)));
|
|
630
|
+
await cacheManager.del(trackingKey);
|
|
631
|
+
} catch {
|
|
632
|
+
// Silent failure - cache invalidation is non-critical
|
|
633
|
+
}
|
|
634
|
+
}
|
|
635
|
+
// ---------------- STRING HELPERS ----------------
|
|
636
|
+
/**
|
|
637
|
+
* Transform string to URL-friendly slug
|
|
638
|
+
*/ transformToSlug(value, salt) {
|
|
639
|
+
const slug = value?.trim().replace(/[^A-Z0-9]+/gi, '-').toLowerCase();
|
|
640
|
+
return salt ? `${slug}-${this.getRandomInt(1, 100)}` : slug;
|
|
641
|
+
}
|
|
642
|
+
/**
|
|
643
|
+
* Generate random integer between min and max (inclusive)
|
|
644
|
+
*/ getRandomInt(min, max) {
|
|
645
|
+
return Math.floor(Math.random() * (max - min + 1)) + min;
|
|
646
|
+
}
|
|
647
|
+
// ---------------- PRIVATE HELPERS ----------------
|
|
648
|
+
buildTenantPrefix(tenantId) {
|
|
649
|
+
return tenantId ? `tenant_${tenantId}_` : '';
|
|
650
|
+
}
|
|
651
|
+
buildTrackingKey(entityName, entityId, tenantId) {
|
|
652
|
+
const prefix = this.buildTenantPrefix(tenantId);
|
|
653
|
+
return entityId ? `${prefix}entity_${entityName}_id_${entityId}_keys` : `${prefix}entity_${entityName}_keys`;
|
|
654
|
+
}
|
|
655
|
+
}
|
|
656
|
+
UtilsService = _ts_decorate([
|
|
657
|
+
(0,_nestjs_common__rspack_import_0.Injectable)()
|
|
658
|
+
], UtilsService);
|
|
659
|
+
|
|
660
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
661
|
+
T: () => (UtilsService)
|
|
662
|
+
});
|
|
663
|
+
|
|
664
|
+
|
|
665
|
+
},
|
|
666
|
+
456(__unused_rspack_module, __webpack_exports__, __webpack_require__) {
|
|
667
|
+
const SENSITIVE_KEYS = [
|
|
668
|
+
'password',
|
|
669
|
+
'secret',
|
|
670
|
+
'token',
|
|
671
|
+
'apikey',
|
|
672
|
+
'authorization',
|
|
673
|
+
'salt',
|
|
674
|
+
'hash',
|
|
675
|
+
'credential',
|
|
676
|
+
'accesskey',
|
|
677
|
+
'accountkey',
|
|
678
|
+
'privatekey',
|
|
679
|
+
'connectionstring',
|
|
680
|
+
'passphrase'
|
|
681
|
+
];
|
|
682
|
+
/**
|
|
683
|
+
* Matched whole, not as a substring - `pass` must be redacted without also
|
|
684
|
+
* redacting `bypassCache`, and a storage row's `key` is a path, not a secret.
|
|
685
|
+
*
|
|
686
|
+
* `config` is the provider settings blob on the storage and email config rows:
|
|
687
|
+
* S3, Azure, SFTP and SMTP credentials live in it, so it never leaves the
|
|
688
|
+
* process, even though the row itself still publishes.
|
|
689
|
+
*/ const SENSITIVE_EXACT_KEYS = [
|
|
690
|
+
'pass',
|
|
691
|
+
'pwd',
|
|
692
|
+
'config'
|
|
693
|
+
];
|
|
694
|
+
const REDACTED = '[REDACTED]';
|
|
695
|
+
const CIRCULAR = '[CIRCULAR]';
|
|
696
|
+
const TRUNCATED = '[TRUNCATED]';
|
|
697
|
+
const BINARY = '[BINARY]';
|
|
698
|
+
const MAX_DEPTH = 8;
|
|
699
|
+
/**
|
|
700
|
+
* Matches a dot separated event name against a routing pattern.
|
|
701
|
+
* `*` matches exactly one segment, `#` and `**` match zero or more segments.
|
|
702
|
+
*/ function matchEventPattern(pattern, eventName) {
|
|
703
|
+
if (pattern === eventName) return true;
|
|
704
|
+
const patternSegments = pattern.split('.');
|
|
705
|
+
const nameSegments = eventName.split('.');
|
|
706
|
+
return matchSegments(patternSegments, 0, nameSegments, 0);
|
|
707
|
+
}
|
|
708
|
+
function isMultiWildcard(segment) {
|
|
709
|
+
return segment === '#' || segment === '**';
|
|
710
|
+
}
|
|
711
|
+
function matchSegments(pattern, patternIndex, name, nameIndex) {
|
|
712
|
+
if (patternIndex === pattern.length) return nameIndex === name.length;
|
|
713
|
+
const segment = pattern[patternIndex];
|
|
714
|
+
if (isMultiWildcard(segment)) {
|
|
715
|
+
for(let skip = nameIndex; skip <= name.length; skip++){
|
|
716
|
+
if (matchSegments(pattern, patternIndex + 1, name, skip)) return true;
|
|
717
|
+
}
|
|
718
|
+
return false;
|
|
719
|
+
}
|
|
720
|
+
if (nameIndex === name.length) return false;
|
|
721
|
+
if (segment !== '*' && segment !== name[nameIndex]) return false;
|
|
722
|
+
return matchSegments(pattern, patternIndex + 1, name, nameIndex + 1);
|
|
723
|
+
}
|
|
724
|
+
/**
|
|
725
|
+
* Strips credential-like fields before a row leaves the process on an event.
|
|
726
|
+
*
|
|
727
|
+
* Saved TypeORM rows routinely carry bidirectional relations, so the walk
|
|
728
|
+
* tracks the current path and caps its depth - a cycle or a very deep graph
|
|
729
|
+
* must never turn an event into a stack overflow.
|
|
730
|
+
*/ function sanitizeEventPayload(value) {
|
|
731
|
+
return sanitizeValue(value, new WeakSet(), 0);
|
|
732
|
+
}
|
|
733
|
+
function sanitizeValue(value, ancestors, depth) {
|
|
734
|
+
if (value === null || typeof value !== 'object') return value;
|
|
735
|
+
if (value instanceof Date) return value;
|
|
736
|
+
if (Buffer.isBuffer(value)) return BINARY;
|
|
737
|
+
if (ancestors.has(value)) return CIRCULAR;
|
|
738
|
+
if (depth >= MAX_DEPTH) return TRUNCATED;
|
|
739
|
+
ancestors.add(value);
|
|
740
|
+
try {
|
|
741
|
+
if (Array.isArray(value)) {
|
|
742
|
+
return value.map((item)=>sanitizeValue(item, ancestors, depth + 1));
|
|
743
|
+
}
|
|
744
|
+
const sanitized = {};
|
|
745
|
+
for (const [key, entry] of Object.entries(value)){
|
|
746
|
+
sanitized[key] = isSensitiveKey(key) ? REDACTED : sanitizeValue(entry, ancestors, depth + 1);
|
|
747
|
+
}
|
|
748
|
+
return sanitized;
|
|
749
|
+
} finally{
|
|
750
|
+
ancestors.delete(value);
|
|
751
|
+
}
|
|
752
|
+
}
|
|
753
|
+
function isSensitiveKey(key) {
|
|
754
|
+
const lowered = key.toLowerCase();
|
|
755
|
+
if (SENSITIVE_EXACT_KEYS.includes(lowered)) return true;
|
|
756
|
+
return SENSITIVE_KEYS.some((sensitive)=>lowered.includes(sensitive));
|
|
757
|
+
}
|
|
758
|
+
|
|
759
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
760
|
+
IN: () => (sanitizeEventPayload),
|
|
761
|
+
_c: () => (isMultiWildcard),
|
|
762
|
+
qe: () => (matchEventPattern)
|
|
763
|
+
});
|
|
764
|
+
|
|
765
|
+
|
|
766
|
+
},
|
|
767
|
+
199(__unused_rspack_module, __webpack_exports__, __webpack_require__) {
|
|
768
|
+
/* import */ var _constants_index_js__rspack_import_0 = __webpack_require__(43);
|
|
769
|
+
|
|
770
|
+
const DEFAULT_USER_PERMISSION_KEY_FORMAT = `${_constants_index_js__rspack_import_0/* .PERMISSIONS_CACHE_PREFIX */.fG}:user:{userId}`;
|
|
771
|
+
const DEFAULT_COMPANY_PERMISSION_KEY_FORMAT = `${_constants_index_js__rspack_import_0/* .PERMISSIONS_CACHE_PREFIX */.fG}:company:{companyId}:branch:{branchId}:user:{userId}`;
|
|
772
|
+
/** Single source of truth for permission cache keys, shared by the guard (reader) and cache service (writer) so a config override can't desync them; company scope requires enableCompanyFeature, not just a companyId */ function buildPermissionCacheKey(options, config) {
|
|
773
|
+
const isCompanyScope = Boolean(config?.enableCompanyFeature && options.companyId);
|
|
774
|
+
if (isCompanyScope) {
|
|
775
|
+
return (config?.companyPermissionKeyFormat || DEFAULT_COMPANY_PERMISSION_KEY_FORMAT).replace('{userId}', options.userId).replace('{companyId}', options.companyId).replace('{branchId}', options.branchId || 'null');
|
|
776
|
+
}
|
|
777
|
+
return (config?.userPermissionKeyFormat || DEFAULT_USER_PERMISSION_KEY_FORMAT).replace('{userId}', options.userId);
|
|
778
|
+
}
|
|
779
|
+
|
|
780
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
781
|
+
nt: () => (buildPermissionCacheKey)
|
|
782
|
+
}, {
|
|
783
|
+
q6: DEFAULT_USER_PERMISSION_KEY_FORMAT,
|
|
784
|
+
s8: DEFAULT_COMPANY_PERMISSION_KEY_FORMAT
|
|
785
|
+
});
|
|
786
|
+
|
|
787
|
+
|
|
788
|
+
},
|
|
789
|
+
436(module) {
|
|
790
|
+
|
|
791
|
+
module.exports = __rspack_external__flusys_nestjs_core_ff4ca4e2;
|
|
792
|
+
|
|
793
|
+
|
|
794
|
+
},
|
|
795
|
+
75(module) {
|
|
796
|
+
|
|
797
|
+
module.exports = __rspack_external__nestjs_core_d7b00a1a;
|
|
798
|
+
|
|
799
|
+
|
|
800
|
+
},
|
|
801
|
+
158(module) {
|
|
802
|
+
|
|
803
|
+
module.exports = __rspack_external_typeorm;
|
|
804
|
+
|
|
805
|
+
|
|
806
|
+
},
|
|
807
|
+
|
|
808
|
+
};
|