@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,274 +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 createModuleLogger () {
|
|
13
|
-
return createModuleLogger;
|
|
14
|
-
},
|
|
15
|
-
get instance () {
|
|
16
|
-
return instance;
|
|
17
|
-
}
|
|
18
|
-
});
|
|
19
|
-
const _config = require("@flusys/nestjs-core/config");
|
|
20
|
-
const _fs = require("fs");
|
|
21
|
-
const _path = require("path");
|
|
22
|
-
const _winston = require("winston");
|
|
23
|
-
const _winstondailyrotatefile = /*#__PURE__*/ _interop_require_wildcard(require("winston-daily-rotate-file"));
|
|
24
|
-
const _winstontransport = /*#__PURE__*/ _interop_require_wildcard(require("winston-transport"));
|
|
25
|
-
function _define_property(obj, key, value) {
|
|
26
|
-
if (key in obj) {
|
|
27
|
-
Object.defineProperty(obj, key, {
|
|
28
|
-
value: value,
|
|
29
|
-
enumerable: true,
|
|
30
|
-
configurable: true,
|
|
31
|
-
writable: true
|
|
32
|
-
});
|
|
33
|
-
} else {
|
|
34
|
-
obj[key] = value;
|
|
35
|
-
}
|
|
36
|
-
return obj;
|
|
37
|
-
}
|
|
38
|
-
function _getRequireWildcardCache(nodeInterop) {
|
|
39
|
-
if (typeof WeakMap !== "function") return null;
|
|
40
|
-
var cacheBabelInterop = new WeakMap();
|
|
41
|
-
var cacheNodeInterop = new WeakMap();
|
|
42
|
-
return (_getRequireWildcardCache = function(nodeInterop) {
|
|
43
|
-
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
|
|
44
|
-
})(nodeInterop);
|
|
45
|
-
}
|
|
46
|
-
function _interop_require_wildcard(obj, nodeInterop) {
|
|
47
|
-
if (!nodeInterop && obj && obj.__esModule) {
|
|
48
|
-
return obj;
|
|
49
|
-
}
|
|
50
|
-
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
|
|
51
|
-
return {
|
|
52
|
-
default: obj
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
var cache = _getRequireWildcardCache(nodeInterop);
|
|
56
|
-
if (cache && cache.has(obj)) {
|
|
57
|
-
return cache.get(obj);
|
|
58
|
-
}
|
|
59
|
-
var newObj = {
|
|
60
|
-
__proto__: null
|
|
61
|
-
};
|
|
62
|
-
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
63
|
-
for(var key in obj){
|
|
64
|
-
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
65
|
-
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
|
|
66
|
-
if (desc && (desc.get || desc.set)) {
|
|
67
|
-
Object.defineProperty(newObj, key, desc);
|
|
68
|
-
} else {
|
|
69
|
-
newObj[key] = obj[key];
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
newObj.default = obj;
|
|
74
|
-
if (cache) {
|
|
75
|
-
cache.set(obj, newObj);
|
|
76
|
-
}
|
|
77
|
-
return newObj;
|
|
78
|
-
}
|
|
79
|
-
const Transport = _winstontransport.default || _winstontransport;
|
|
80
|
-
const DailyRotateFile = _winstondailyrotatefile.default || _winstondailyrotatefile;
|
|
81
|
-
// Configuration
|
|
82
|
-
const logConfig = _config.envConfig.getLogConfig();
|
|
83
|
-
const LOG_DIR = logConfig.dir;
|
|
84
|
-
const LOG_LEVEL = logConfig.level;
|
|
85
|
-
const LOG_MAX_SIZE = logConfig.maxSize;
|
|
86
|
-
const LOG_MAX_FILES = logConfig.maxFiles;
|
|
87
|
-
const USE_TENANT_MODE = _config.envConfig.useTenantMode();
|
|
88
|
-
// Ensure logs directory exists
|
|
89
|
-
if (!(0, _fs.existsSync)(LOG_DIR)) {
|
|
90
|
-
(0, _fs.mkdirSync)(LOG_DIR, {
|
|
91
|
-
recursive: true
|
|
92
|
-
});
|
|
93
|
-
}
|
|
94
|
-
// Custom Formats
|
|
95
|
-
/**
|
|
96
|
-
* Custom format for structured logging (production)
|
|
97
|
-
* Multi-line format:
|
|
98
|
-
* - Line 1: Timestamp
|
|
99
|
-
* - Line 2: Log Level
|
|
100
|
-
* - Line 3: [RequestId]
|
|
101
|
-
* - Line 4: Empty
|
|
102
|
-
* - Line 5+: Message with context
|
|
103
|
-
*/ const LEVEL_MAP = {
|
|
104
|
-
error: 'Error',
|
|
105
|
-
warn: 'Warning',
|
|
106
|
-
info: 'Information',
|
|
107
|
-
debug: 'Debug',
|
|
108
|
-
verbose: 'Verbose'
|
|
109
|
-
};
|
|
110
|
-
const LOG_SEPARATOR = '─'.repeat(80);
|
|
111
|
-
const structuredFormat = _winston.format.printf(({ timestamp, level, message, context, requestId, userId, tenantId, companyId, method, url, path, statusCode, duration, stack, ...metadata })=>{
|
|
112
|
-
const reqId = requestId || 'no-request-id';
|
|
113
|
-
const levelFormatted = LEVEL_MAP[level] || level.charAt(0).toUpperCase() + level.slice(1);
|
|
114
|
-
const contextParts = [];
|
|
115
|
-
if (context) contextParts.push(`Context: ${context}`);
|
|
116
|
-
if (method && (path || url)) contextParts.push(`Endpoint: ${method} ${path || url}`);
|
|
117
|
-
if (statusCode) contextParts.push(`Status: ${statusCode}`);
|
|
118
|
-
if (duration) contextParts.push(`Duration: ${duration}`);
|
|
119
|
-
if (userId) contextParts.push(`UserId: ${userId}`);
|
|
120
|
-
if (tenantId) contextParts.push(`TenantId: ${tenantId}`);
|
|
121
|
-
if (companyId) contextParts.push(`CompanyId: ${companyId}`);
|
|
122
|
-
let content = message;
|
|
123
|
-
if (contextParts.length > 0) {
|
|
124
|
-
content = `${contextParts.join(' | ')}\n${message}`;
|
|
125
|
-
}
|
|
126
|
-
const metaKeys = Object.keys(metadata).filter((k)=>k !== 'splat');
|
|
127
|
-
if (metaKeys.length > 0) {
|
|
128
|
-
const metaStr = JSON.stringify(metaKeys.reduce((acc, k)=>({
|
|
129
|
-
...acc,
|
|
130
|
-
[k]: metadata[k]
|
|
131
|
-
}), {}));
|
|
132
|
-
content += `\nMetadata: ${metaStr}`;
|
|
133
|
-
}
|
|
134
|
-
if (stack) {
|
|
135
|
-
content += `\nStack: ${stack}`;
|
|
136
|
-
}
|
|
137
|
-
return `${LOG_SEPARATOR}\n${timestamp} | ${levelFormatted} | [${reqId}]\n${content}`;
|
|
138
|
-
});
|
|
139
|
-
// Transports
|
|
140
|
-
/**
|
|
141
|
-
* Daily rotating file transport for all logs
|
|
142
|
-
*/ const combinedRotateTransport = new DailyRotateFile({
|
|
143
|
-
filename: `${LOG_DIR}/combined-%DATE%.log`,
|
|
144
|
-
datePattern: 'YYYY-MM-DD',
|
|
145
|
-
zippedArchive: true,
|
|
146
|
-
maxSize: LOG_MAX_SIZE,
|
|
147
|
-
maxFiles: LOG_MAX_FILES,
|
|
148
|
-
level: LOG_LEVEL
|
|
149
|
-
});
|
|
150
|
-
/**
|
|
151
|
-
* Daily rotating file transport for error logs only
|
|
152
|
-
*/ const errorRotateTransport = new DailyRotateFile({
|
|
153
|
-
filename: `${LOG_DIR}/error-%DATE%.log`,
|
|
154
|
-
datePattern: 'YYYY-MM-DD',
|
|
155
|
-
zippedArchive: true,
|
|
156
|
-
maxSize: LOG_MAX_SIZE,
|
|
157
|
-
maxFiles: LOG_MAX_FILES,
|
|
158
|
-
level: 'error'
|
|
159
|
-
});
|
|
160
|
-
// Transport Caches
|
|
161
|
-
const moduleTransportCache = new Map();
|
|
162
|
-
const tenantTransportCache = new Map();
|
|
163
|
-
function getCachedTransport(cache, name) {
|
|
164
|
-
const cached = cache.get(name);
|
|
165
|
-
if (cached) return cached;
|
|
166
|
-
const logDir = (0, _path.join)(LOG_DIR, name);
|
|
167
|
-
if (!(0, _fs.existsSync)(logDir)) {
|
|
168
|
-
(0, _fs.mkdirSync)(logDir, {
|
|
169
|
-
recursive: true
|
|
170
|
-
});
|
|
171
|
-
}
|
|
172
|
-
const transport = new DailyRotateFile({
|
|
173
|
-
filename: `${logDir}/combined-%DATE%.log`,
|
|
174
|
-
datePattern: 'YYYY-MM-DD',
|
|
175
|
-
zippedArchive: true,
|
|
176
|
-
maxSize: LOG_MAX_SIZE,
|
|
177
|
-
maxFiles: LOG_MAX_FILES,
|
|
178
|
-
level: LOG_LEVEL
|
|
179
|
-
});
|
|
180
|
-
cache.set(name, transport);
|
|
181
|
-
return transport;
|
|
182
|
-
}
|
|
183
|
-
const getModuleTransport = (name)=>getCachedTransport(moduleTransportCache, name);
|
|
184
|
-
const getTenantTransport = (name)=>getCachedTransport(tenantTransportCache, name);
|
|
185
|
-
let TenantAwareTransport = class TenantAwareTransport extends Transport {
|
|
186
|
-
log(info, callback) {
|
|
187
|
-
setImmediate(()=>this.emit('logged', info));
|
|
188
|
-
const tenantId = info.tenantId || info.metadata?.tenantId;
|
|
189
|
-
const transport = USE_TENANT_MODE && tenantId ? getTenantTransport(tenantId) : this.defaultTransport;
|
|
190
|
-
transport.log(info, callback);
|
|
191
|
-
}
|
|
192
|
-
constructor(defaultTransport){
|
|
193
|
-
super(), _define_property(this, "defaultTransport", void 0), this.defaultTransport = defaultTransport;
|
|
194
|
-
}
|
|
195
|
-
};
|
|
196
|
-
const tenantAwareCombinedTransport = new TenantAwareTransport(combinedRotateTransport);
|
|
197
|
-
const consoleTransport = new _winston.transports.Console({
|
|
198
|
-
level: LOG_LEVEL,
|
|
199
|
-
format: _winston.format.combine(_winston.format.colorize({
|
|
200
|
-
all: true
|
|
201
|
-
}), _winston.format.timestamp({
|
|
202
|
-
format: 'YYYY-MM-DD HH:mm:ss'
|
|
203
|
-
}), _winston.format.errors({
|
|
204
|
-
stack: true
|
|
205
|
-
}), structuredFormat)
|
|
206
|
-
});
|
|
207
|
-
// Logger Instances
|
|
208
|
-
/**
|
|
209
|
-
* Development logger configuration
|
|
210
|
-
* - Console output with colors
|
|
211
|
-
* - Human-readable format
|
|
212
|
-
* - Debug level by default
|
|
213
|
-
*/ const devLogger = (0, _winston.createLogger)({
|
|
214
|
-
level: LOG_LEVEL,
|
|
215
|
-
format: _winston.format.combine(_winston.format.timestamp({
|
|
216
|
-
format: 'YYYY-MM-DD HH:mm:ss'
|
|
217
|
-
}), _winston.format.errors({
|
|
218
|
-
stack: true
|
|
219
|
-
})),
|
|
220
|
-
transports: [
|
|
221
|
-
consoleTransport
|
|
222
|
-
],
|
|
223
|
-
exitOnError: false
|
|
224
|
-
});
|
|
225
|
-
/**
|
|
226
|
-
* Production logger configuration
|
|
227
|
-
* - File-based logging with rotation
|
|
228
|
-
* - JSON structured format
|
|
229
|
-
* - Separate error log file
|
|
230
|
-
* - Compressed old logs
|
|
231
|
-
* - Tenant-aware routing (when USE_TENANT_MODE=true)
|
|
232
|
-
*/ const prodLogger = (0, _winston.createLogger)({
|
|
233
|
-
level: LOG_LEVEL,
|
|
234
|
-
format: _winston.format.combine(_winston.format.timestamp({
|
|
235
|
-
format: 'YYYY-MM-DD HH:mm:ss.SSS'
|
|
236
|
-
}), _winston.format.errors({
|
|
237
|
-
stack: true
|
|
238
|
-
}), structuredFormat),
|
|
239
|
-
transports: [
|
|
240
|
-
tenantAwareCombinedTransport,
|
|
241
|
-
errorRotateTransport
|
|
242
|
-
],
|
|
243
|
-
exitOnError: false
|
|
244
|
-
});
|
|
245
|
-
const instance = _config.envConfig.isProduction() ? prodLogger : devLogger;
|
|
246
|
-
/**
|
|
247
|
-
* Module logger cache to avoid creating multiple loggers for the same module
|
|
248
|
-
*/ const moduleLoggerCache = new Map();
|
|
249
|
-
function createModuleLogger(moduleName) {
|
|
250
|
-
// In dev mode, use global console logger
|
|
251
|
-
if (!_config.envConfig.isProduction()) {
|
|
252
|
-
return devLogger;
|
|
253
|
-
}
|
|
254
|
-
// Check cache first
|
|
255
|
-
if (moduleLoggerCache.has(moduleName)) {
|
|
256
|
-
return moduleLoggerCache.get(moduleName);
|
|
257
|
-
}
|
|
258
|
-
// Create module-specific logger for production
|
|
259
|
-
const moduleLogger = (0, _winston.createLogger)({
|
|
260
|
-
level: LOG_LEVEL,
|
|
261
|
-
format: _winston.format.combine(_winston.format.timestamp({
|
|
262
|
-
format: 'YYYY-MM-DD HH:mm:ss.SSS'
|
|
263
|
-
}), _winston.format.errors({
|
|
264
|
-
stack: true
|
|
265
|
-
}), structuredFormat),
|
|
266
|
-
transports: [
|
|
267
|
-
getModuleTransport(moduleName),
|
|
268
|
-
errorRotateTransport
|
|
269
|
-
],
|
|
270
|
-
exitOnError: false
|
|
271
|
-
});
|
|
272
|
-
moduleLoggerCache.set(moduleName, moduleLogger);
|
|
273
|
-
return moduleLogger;
|
|
274
|
-
}
|
|
@@ -1,330 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
function _define_property(obj, key, value) {
|
|
6
|
-
if (key in obj) {
|
|
7
|
-
Object.defineProperty(obj, key, {
|
|
8
|
-
value: value,
|
|
9
|
-
enumerable: true,
|
|
10
|
-
configurable: true,
|
|
11
|
-
writable: true
|
|
12
|
-
});
|
|
13
|
-
} else {
|
|
14
|
-
obj[key] = value;
|
|
15
|
-
}
|
|
16
|
-
return obj;
|
|
17
|
-
}
|
|
18
|
-
const mockExistsSync = jest.fn();
|
|
19
|
-
const mockMkdirSync = jest.fn();
|
|
20
|
-
jest.mock('fs', ()=>({
|
|
21
|
-
existsSync: (...args)=>mockExistsSync(...args),
|
|
22
|
-
mkdirSync: (...args)=>mockMkdirSync(...args)
|
|
23
|
-
}));
|
|
24
|
-
const mockGetLogConfig = jest.fn();
|
|
25
|
-
const mockUseTenantMode = jest.fn();
|
|
26
|
-
const mockIsProduction = jest.fn();
|
|
27
|
-
jest.mock('@flusys/nestjs-core/config', ()=>({
|
|
28
|
-
envConfig: {
|
|
29
|
-
getLogConfig: (...args)=>mockGetLogConfig(...args),
|
|
30
|
-
useTenantMode: (...args)=>mockUseTenantMode(...args),
|
|
31
|
-
isProduction: (...args)=>mockIsProduction(...args)
|
|
32
|
-
}
|
|
33
|
-
}));
|
|
34
|
-
const { EventEmitter } = require('events');
|
|
35
|
-
let FakeDailyRotateFile = class FakeDailyRotateFile extends EventEmitter {
|
|
36
|
-
constructor(options){
|
|
37
|
-
super(), _define_property(this, "options", void 0), _define_property(this, "log", jest.fn((_info, callback)=>callback?.()));
|
|
38
|
-
this.options = options;
|
|
39
|
-
}
|
|
40
|
-
};
|
|
41
|
-
jest.mock('winston-daily-rotate-file', ()=>({
|
|
42
|
-
__esModule: true,
|
|
43
|
-
default: FakeDailyRotateFile
|
|
44
|
-
}));
|
|
45
|
-
let capturedPrintf;
|
|
46
|
-
jest.mock('winston', ()=>{
|
|
47
|
-
const actual = jest.requireActual('winston');
|
|
48
|
-
// winston's `format` export exposes its sub-formatters (colorize, combine, printf, ...)
|
|
49
|
-
// as non-enumerable getters, so a plain object spread silently drops them. Delegate through
|
|
50
|
-
// the prototype chain instead and only shadow `printf` to capture the formatter callback.
|
|
51
|
-
const realPrintf = actual.format.printf;
|
|
52
|
-
const mockFormat = Object.create(actual.format);
|
|
53
|
-
Object.defineProperty(mockFormat, 'printf', {
|
|
54
|
-
value: (fn)=>{
|
|
55
|
-
capturedPrintf = fn;
|
|
56
|
-
return realPrintf(fn);
|
|
57
|
-
}
|
|
58
|
-
});
|
|
59
|
-
return {
|
|
60
|
-
...actual,
|
|
61
|
-
format: mockFormat
|
|
62
|
-
};
|
|
63
|
-
});
|
|
64
|
-
describe('winston.logger.class', ()=>{
|
|
65
|
-
let consoleErrorSpy;
|
|
66
|
-
beforeEach(()=>{
|
|
67
|
-
jest.resetModules();
|
|
68
|
-
jest.clearAllMocks();
|
|
69
|
-
// FakeDailyRotateFile isn't a real winston-transport instance, so winston logs a
|
|
70
|
-
// harmless "legacy transport" deprecation warning via console.error on each createLogger call.
|
|
71
|
-
consoleErrorSpy = jest.spyOn(console, 'error').mockImplementation(()=>undefined);
|
|
72
|
-
mockExistsSync.mockReturnValue(true);
|
|
73
|
-
mockGetLogConfig.mockReturnValue({
|
|
74
|
-
dir: 'logs',
|
|
75
|
-
level: 'debug',
|
|
76
|
-
maxSize: '20m',
|
|
77
|
-
maxFiles: '14d',
|
|
78
|
-
disableHttpLogging: false
|
|
79
|
-
});
|
|
80
|
-
mockUseTenantMode.mockReturnValue(false);
|
|
81
|
-
});
|
|
82
|
-
afterEach(()=>{
|
|
83
|
-
consoleErrorSpy.mockRestore();
|
|
84
|
-
});
|
|
85
|
-
it('should create the log directory when it does not exist', ()=>{
|
|
86
|
-
mockExistsSync.mockReturnValue(false);
|
|
87
|
-
mockIsProduction.mockReturnValue(false);
|
|
88
|
-
require('./winston.logger.class');
|
|
89
|
-
expect(mockMkdirSync).toHaveBeenCalledWith('logs', {
|
|
90
|
-
recursive: true
|
|
91
|
-
});
|
|
92
|
-
});
|
|
93
|
-
it('should not attempt to create the log directory when it already exists', ()=>{
|
|
94
|
-
mockExistsSync.mockReturnValue(true);
|
|
95
|
-
mockIsProduction.mockReturnValue(false);
|
|
96
|
-
require('./winston.logger.class');
|
|
97
|
-
expect(mockMkdirSync).not.toHaveBeenCalledWith('logs', {
|
|
98
|
-
recursive: true
|
|
99
|
-
});
|
|
100
|
-
});
|
|
101
|
-
it('should export a dev (console-based) instance when not in production', ()=>{
|
|
102
|
-
mockIsProduction.mockReturnValue(false);
|
|
103
|
-
const { instance } = require('./winston.logger.class');
|
|
104
|
-
expect(instance).toBeDefined();
|
|
105
|
-
expect(typeof instance.log).toBe('function');
|
|
106
|
-
});
|
|
107
|
-
it('should export a prod (file-rotation-based) instance when in production', ()=>{
|
|
108
|
-
mockIsProduction.mockReturnValue(true);
|
|
109
|
-
const { instance } = require('./winston.logger.class');
|
|
110
|
-
expect(instance).toBeDefined();
|
|
111
|
-
expect(typeof instance.log).toBe('function');
|
|
112
|
-
});
|
|
113
|
-
describe('createModuleLogger', ()=>{
|
|
114
|
-
it('should return the shared dev logger instance in non-production mode', ()=>{
|
|
115
|
-
mockIsProduction.mockReturnValue(false);
|
|
116
|
-
const { createModuleLogger, instance } = require('./winston.logger.class');
|
|
117
|
-
expect(createModuleLogger('auth')).toBe(instance);
|
|
118
|
-
expect(createModuleLogger('iam')).toBe(instance);
|
|
119
|
-
});
|
|
120
|
-
it('should create a distinct, cached logger per module in production mode', ()=>{
|
|
121
|
-
mockIsProduction.mockReturnValue(true);
|
|
122
|
-
const { createModuleLogger } = require('./winston.logger.class');
|
|
123
|
-
const authLogger1 = createModuleLogger('auth');
|
|
124
|
-
const authLogger2 = createModuleLogger('auth');
|
|
125
|
-
const iamLogger = createModuleLogger('iam');
|
|
126
|
-
expect(authLogger1).toBe(authLogger2);
|
|
127
|
-
expect(authLogger1).not.toBe(iamLogger);
|
|
128
|
-
});
|
|
129
|
-
it('should create the module-specific log directory on first use in production mode', ()=>{
|
|
130
|
-
mockIsProduction.mockReturnValue(true);
|
|
131
|
-
mockExistsSync.mockImplementation((p)=>p === 'logs');
|
|
132
|
-
const { createModuleLogger } = require('./winston.logger.class');
|
|
133
|
-
createModuleLogger('storage');
|
|
134
|
-
expect(mockMkdirSync).toHaveBeenCalledWith(expect.stringContaining('storage'), {
|
|
135
|
-
recursive: true
|
|
136
|
-
});
|
|
137
|
-
});
|
|
138
|
-
it('should not recreate the module directory or transport on subsequent calls', ()=>{
|
|
139
|
-
mockIsProduction.mockReturnValue(true);
|
|
140
|
-
mockExistsSync.mockReturnValue(true);
|
|
141
|
-
const { createModuleLogger } = require('./winston.logger.class');
|
|
142
|
-
createModuleLogger('storage');
|
|
143
|
-
const mkdirCallsAfterFirst = mockMkdirSync.mock.calls.length;
|
|
144
|
-
createModuleLogger('storage');
|
|
145
|
-
expect(mockMkdirSync.mock.calls.length).toBe(mkdirCallsAfterFirst);
|
|
146
|
-
});
|
|
147
|
-
});
|
|
148
|
-
describe('structuredFormat (captured printf callback)', ()=>{
|
|
149
|
-
beforeEach(()=>{
|
|
150
|
-
mockIsProduction.mockReturnValue(true);
|
|
151
|
-
capturedPrintf = undefined;
|
|
152
|
-
require('./winston.logger.class');
|
|
153
|
-
});
|
|
154
|
-
it('should capture the printf formatter', ()=>{
|
|
155
|
-
expect(capturedPrintf).toBeInstanceOf(Function);
|
|
156
|
-
});
|
|
157
|
-
it('should default the request id when absent and map known levels', ()=>{
|
|
158
|
-
const out = capturedPrintf({
|
|
159
|
-
timestamp: 'T',
|
|
160
|
-
level: 'error',
|
|
161
|
-
message: 'boom'
|
|
162
|
-
});
|
|
163
|
-
expect(out).toContain('[no-request-id]');
|
|
164
|
-
expect(out).toContain('Error');
|
|
165
|
-
});
|
|
166
|
-
it('should use the provided requestId and title-case unknown levels', ()=>{
|
|
167
|
-
const out = capturedPrintf({
|
|
168
|
-
timestamp: 'T',
|
|
169
|
-
level: 'silly',
|
|
170
|
-
message: 'x',
|
|
171
|
-
requestId: 'req-1'
|
|
172
|
-
});
|
|
173
|
-
expect(out).toContain('[req-1]');
|
|
174
|
-
expect(out).toContain('Silly');
|
|
175
|
-
});
|
|
176
|
-
it('should render context, endpoint, status, duration and user/tenant/company parts', ()=>{
|
|
177
|
-
const out = capturedPrintf({
|
|
178
|
-
timestamp: 'T',
|
|
179
|
-
level: 'info',
|
|
180
|
-
message: 'handled',
|
|
181
|
-
context: 'AuthService',
|
|
182
|
-
method: 'POST',
|
|
183
|
-
path: '/login',
|
|
184
|
-
statusCode: 200,
|
|
185
|
-
duration: '12ms',
|
|
186
|
-
userId: 'u1',
|
|
187
|
-
tenantId: 't1',
|
|
188
|
-
companyId: 'c1'
|
|
189
|
-
});
|
|
190
|
-
expect(out).toContain('Context: AuthService');
|
|
191
|
-
expect(out).toContain('Endpoint: POST /login');
|
|
192
|
-
expect(out).toContain('Status: 200');
|
|
193
|
-
expect(out).toContain('Duration: 12ms');
|
|
194
|
-
expect(out).toContain('UserId: u1');
|
|
195
|
-
expect(out).toContain('TenantId: t1');
|
|
196
|
-
expect(out).toContain('CompanyId: c1');
|
|
197
|
-
expect(out).toContain('handled');
|
|
198
|
-
});
|
|
199
|
-
it('should fall back to `url` for the endpoint line when `path` is absent', ()=>{
|
|
200
|
-
const out = capturedPrintf({
|
|
201
|
-
timestamp: 'T',
|
|
202
|
-
level: 'info',
|
|
203
|
-
message: 'm',
|
|
204
|
-
method: 'GET',
|
|
205
|
-
url: '/legacy'
|
|
206
|
-
});
|
|
207
|
-
expect(out).toContain('Endpoint: GET /legacy');
|
|
208
|
-
});
|
|
209
|
-
it('should omit the endpoint line entirely when method has no path or url', ()=>{
|
|
210
|
-
const out = capturedPrintf({
|
|
211
|
-
timestamp: 'T',
|
|
212
|
-
level: 'info',
|
|
213
|
-
message: 'm',
|
|
214
|
-
method: 'GET'
|
|
215
|
-
});
|
|
216
|
-
expect(out).not.toContain('Endpoint:');
|
|
217
|
-
});
|
|
218
|
-
it('should append remaining metadata as JSON, excluding the `splat` key', ()=>{
|
|
219
|
-
const out = capturedPrintf({
|
|
220
|
-
timestamp: 'T',
|
|
221
|
-
level: 'info',
|
|
222
|
-
message: 'm',
|
|
223
|
-
splat: [
|
|
224
|
-
'ignored'
|
|
225
|
-
],
|
|
226
|
-
orderId: 'o1',
|
|
227
|
-
amount: 50
|
|
228
|
-
});
|
|
229
|
-
expect(out).toContain('Metadata: {"orderId":"o1","amount":50}');
|
|
230
|
-
expect(out).not.toContain('ignored');
|
|
231
|
-
});
|
|
232
|
-
it('should omit the Metadata line when no extra metadata remains', ()=>{
|
|
233
|
-
const out = capturedPrintf({
|
|
234
|
-
timestamp: 'T',
|
|
235
|
-
level: 'info',
|
|
236
|
-
message: 'm',
|
|
237
|
-
splat: []
|
|
238
|
-
});
|
|
239
|
-
expect(out).not.toContain('Metadata:');
|
|
240
|
-
});
|
|
241
|
-
it('should append the stack trace when present', ()=>{
|
|
242
|
-
const out = capturedPrintf({
|
|
243
|
-
timestamp: 'T',
|
|
244
|
-
level: 'error',
|
|
245
|
-
message: 'crashed',
|
|
246
|
-
stack: 'Error: crashed\n at foo.ts:1:1'
|
|
247
|
-
});
|
|
248
|
-
expect(out).toContain('Stack: Error: crashed');
|
|
249
|
-
});
|
|
250
|
-
});
|
|
251
|
-
describe('TenantAwareTransport routing', ()=>{
|
|
252
|
-
it('should route to the default transport when tenant mode is disabled', ()=>{
|
|
253
|
-
mockIsProduction.mockReturnValue(true);
|
|
254
|
-
mockUseTenantMode.mockReturnValue(false);
|
|
255
|
-
const { instance } = require('./winston.logger.class');
|
|
256
|
-
const tenantAwareTransport = instance.transports[0];
|
|
257
|
-
const defaultTransport = tenantAwareTransport.defaultTransport;
|
|
258
|
-
const logSpy = jest.spyOn(defaultTransport, 'log');
|
|
259
|
-
const cb = jest.fn();
|
|
260
|
-
tenantAwareTransport.log({
|
|
261
|
-
level: 'info',
|
|
262
|
-
message: 'x',
|
|
263
|
-
tenantId: 't1'
|
|
264
|
-
}, cb);
|
|
265
|
-
expect(logSpy).toHaveBeenCalled();
|
|
266
|
-
});
|
|
267
|
-
it('should route to the default transport when tenant mode is enabled but no tenantId is present', ()=>{
|
|
268
|
-
mockIsProduction.mockReturnValue(true);
|
|
269
|
-
mockUseTenantMode.mockReturnValue(true);
|
|
270
|
-
const { instance } = require('./winston.logger.class');
|
|
271
|
-
const tenantAwareTransport = instance.transports[0];
|
|
272
|
-
const defaultTransport = tenantAwareTransport.defaultTransport;
|
|
273
|
-
const logSpy = jest.spyOn(defaultTransport, 'log');
|
|
274
|
-
const cb = jest.fn();
|
|
275
|
-
tenantAwareTransport.log({
|
|
276
|
-
level: 'info',
|
|
277
|
-
message: 'x'
|
|
278
|
-
}, cb);
|
|
279
|
-
expect(logSpy).toHaveBeenCalled();
|
|
280
|
-
});
|
|
281
|
-
it('should route to a tenant-specific transport when tenant mode is enabled and tenantId is present', ()=>{
|
|
282
|
-
mockIsProduction.mockReturnValue(true);
|
|
283
|
-
mockUseTenantMode.mockReturnValue(true);
|
|
284
|
-
mockExistsSync.mockReturnValue(true);
|
|
285
|
-
const { instance } = require('./winston.logger.class');
|
|
286
|
-
const tenantAwareTransport = instance.transports[0];
|
|
287
|
-
const defaultTransport = tenantAwareTransport.defaultTransport;
|
|
288
|
-
const defaultLogSpy = jest.spyOn(defaultTransport, 'log');
|
|
289
|
-
const cb = jest.fn();
|
|
290
|
-
tenantAwareTransport.log({
|
|
291
|
-
level: 'info',
|
|
292
|
-
message: 'x',
|
|
293
|
-
tenantId: 'tenant-a'
|
|
294
|
-
}, cb);
|
|
295
|
-
expect(defaultLogSpy).not.toHaveBeenCalled();
|
|
296
|
-
});
|
|
297
|
-
it('should read tenantId from nested `metadata.tenantId` when top-level tenantId is absent', ()=>{
|
|
298
|
-
mockIsProduction.mockReturnValue(true);
|
|
299
|
-
mockUseTenantMode.mockReturnValue(true);
|
|
300
|
-
mockExistsSync.mockReturnValue(true);
|
|
301
|
-
const { instance } = require('./winston.logger.class');
|
|
302
|
-
const tenantAwareTransport = instance.transports[0];
|
|
303
|
-
const defaultTransport = tenantAwareTransport.defaultTransport;
|
|
304
|
-
const defaultLogSpy = jest.spyOn(defaultTransport, 'log');
|
|
305
|
-
const cb = jest.fn();
|
|
306
|
-
tenantAwareTransport.log({
|
|
307
|
-
level: 'info',
|
|
308
|
-
message: 'x',
|
|
309
|
-
metadata: {
|
|
310
|
-
tenantId: 'tenant-b'
|
|
311
|
-
}
|
|
312
|
-
}, cb);
|
|
313
|
-
expect(defaultLogSpy).not.toHaveBeenCalled();
|
|
314
|
-
});
|
|
315
|
-
it('should re-emit "logged" so winston can track transport completion', (done)=>{
|
|
316
|
-
mockIsProduction.mockReturnValue(true);
|
|
317
|
-
mockUseTenantMode.mockReturnValue(false);
|
|
318
|
-
const { instance } = require('./winston.logger.class');
|
|
319
|
-
const tenantAwareTransport = instance.transports[0];
|
|
320
|
-
tenantAwareTransport.once('logged', (info)=>{
|
|
321
|
-
expect(info.message).toBe('done-check');
|
|
322
|
-
done();
|
|
323
|
-
});
|
|
324
|
-
tenantAwareTransport.log({
|
|
325
|
-
level: 'info',
|
|
326
|
-
message: 'done-check'
|
|
327
|
-
}, jest.fn());
|
|
328
|
-
});
|
|
329
|
-
});
|
|
330
|
-
});
|
package/cjs/constants/index.js
DELETED
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
// Metadata keys
|
|
2
|
-
"use strict";
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
function _export(target, all) {
|
|
7
|
-
for(var name in all)Object.defineProperty(target, name, {
|
|
8
|
-
enumerable: true,
|
|
9
|
-
get: Object.getOwnPropertyDescriptor(all, name).get
|
|
10
|
-
});
|
|
11
|
-
}
|
|
12
|
-
_export(exports, {
|
|
13
|
-
get CACHE_INSTANCE () {
|
|
14
|
-
return CACHE_INSTANCE;
|
|
15
|
-
},
|
|
16
|
-
get CLIENT_TYPE_HEADER () {
|
|
17
|
-
return CLIENT_TYPE_HEADER;
|
|
18
|
-
},
|
|
19
|
-
get DEFAULT_EVENT_EXCHANGE () {
|
|
20
|
-
return DEFAULT_EVENT_EXCHANGE;
|
|
21
|
-
},
|
|
22
|
-
get DEFAULT_EVENT_SERVICE_NAME () {
|
|
23
|
-
return DEFAULT_EVENT_SERVICE_NAME;
|
|
24
|
-
},
|
|
25
|
-
get DEFAULT_EVENT_TOPIC () {
|
|
26
|
-
return DEFAULT_EVENT_TOPIC;
|
|
27
|
-
},
|
|
28
|
-
get DOMAIN_EVENT_HANDLER_KEY () {
|
|
29
|
-
return DOMAIN_EVENT_HANDLER_KEY;
|
|
30
|
-
},
|
|
31
|
-
get EVENT_BUS_INSTANCE () {
|
|
32
|
-
return EVENT_BUS_INSTANCE;
|
|
33
|
-
},
|
|
34
|
-
get EVENT_BUS_MODULE_OPTIONS () {
|
|
35
|
-
return EVENT_BUS_MODULE_OPTIONS;
|
|
36
|
-
},
|
|
37
|
-
get IDEMPOTENCY_CACHE_PREFIX () {
|
|
38
|
-
return IDEMPOTENCY_CACHE_PREFIX;
|
|
39
|
-
},
|
|
40
|
-
get IDEMPOTENCY_KEY_HEADER () {
|
|
41
|
-
return IDEMPOTENCY_KEY_HEADER;
|
|
42
|
-
},
|
|
43
|
-
get IS_PUBLIC_KEY () {
|
|
44
|
-
return IS_PUBLIC_KEY;
|
|
45
|
-
},
|
|
46
|
-
get PERMISSIONS_CACHE_PREFIX () {
|
|
47
|
-
return PERMISSIONS_CACHE_PREFIX;
|
|
48
|
-
},
|
|
49
|
-
get PERMISSIONS_KEY () {
|
|
50
|
-
return PERMISSIONS_KEY;
|
|
51
|
-
},
|
|
52
|
-
get PERMISSION_GUARD_CONFIG () {
|
|
53
|
-
return PERMISSION_GUARD_CONFIG;
|
|
54
|
-
},
|
|
55
|
-
get REQUEST_ID_HEADER () {
|
|
56
|
-
return REQUEST_ID_HEADER;
|
|
57
|
-
}
|
|
58
|
-
});
|
|
59
|
-
_export_star(require("./permissions"), exports);
|
|
60
|
-
_export_star(require("./message-keys"), exports);
|
|
61
|
-
function _export_star(from, to) {
|
|
62
|
-
Object.keys(from).forEach(function(k) {
|
|
63
|
-
if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
|
|
64
|
-
Object.defineProperty(to, k, {
|
|
65
|
-
enumerable: true,
|
|
66
|
-
get: function() {
|
|
67
|
-
return from[k];
|
|
68
|
-
}
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
});
|
|
72
|
-
return from;
|
|
73
|
-
}
|
|
74
|
-
const IS_PUBLIC_KEY = 'isPublic';
|
|
75
|
-
const PERMISSIONS_KEY = 'permissions';
|
|
76
|
-
const DOMAIN_EVENT_HANDLER_KEY = 'domainEventHandler';
|
|
77
|
-
const CACHE_INSTANCE = 'CACHE_INSTANCE';
|
|
78
|
-
const PERMISSION_GUARD_CONFIG = 'PERMISSION_GUARD_CONFIG';
|
|
79
|
-
const EVENT_BUS_INSTANCE = 'EVENT_BUS_INSTANCE';
|
|
80
|
-
const EVENT_BUS_MODULE_OPTIONS = 'EVENT_BUS_MODULE_OPTIONS';
|
|
81
|
-
const IDEMPOTENCY_KEY_HEADER = 'x-idempotency-key';
|
|
82
|
-
const REQUEST_ID_HEADER = 'x-request-id';
|
|
83
|
-
const CLIENT_TYPE_HEADER = 'x-client-type';
|
|
84
|
-
const PERMISSIONS_CACHE_PREFIX = 'my-permissions';
|
|
85
|
-
const IDEMPOTENCY_CACHE_PREFIX = 'idempotency';
|
|
86
|
-
const DEFAULT_EVENT_EXCHANGE = 'flusys.events';
|
|
87
|
-
const DEFAULT_EVENT_TOPIC = 'flusys.domain-events';
|
|
88
|
-
const DEFAULT_EVENT_SERVICE_NAME = 'flusys';
|