@flusys/nestjs-notification 7.1.0 → 8.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/adapters/index.d.ts +1 -1
- package/adapters/notification.adapter.d.ts +2 -2
- package/config/index.d.ts +3 -3
- package/controllers/index.d.ts +1 -1
- package/controllers/notification.controller.d.ts +4 -4
- package/docs/index.d.ts +1 -1
- package/docs/notification-swagger.config.d.ts +2 -2
- package/dtos/index.d.ts +1 -1
- package/entities/index.d.ts +5 -5
- package/entities/notification-with-company.entity.d.ts +1 -1
- package/fesm/244.js +816 -0
- package/fesm/446.js +939 -0
- package/fesm/adapters/index.js +79 -1
- package/fesm/config/index.js +84 -3
- package/fesm/controllers/index.js +13 -1
- package/fesm/docs/index.js +112 -1
- package/fesm/dtos/index.js +311 -1
- package/fesm/entities/index.js +211 -8
- package/fesm/gateways/index.js +286 -1
- package/fesm/index.js +467 -10
- package/fesm/interfaces/index.js +16 -2
- package/fesm/modules/index.js +269 -1
- package/fesm/runtime.js +85 -0
- package/fesm/services/index.js +357 -4
- package/gateways/index.d.ts +1 -1
- package/gateways/notification.gateway.d.ts +2 -2
- package/index.d.ts +10 -10
- package/interfaces/index.d.ts +2 -2
- package/interfaces/notification-module.interface.d.ts +3 -3
- package/interfaces/notification.interface.d.ts +1 -1
- package/modules/index.d.ts +1 -1
- package/modules/notification.module.d.ts +2 -2
- package/package.json +33 -44
- package/services/index.d.ts +4 -4
- package/services/notification-config.service.d.ts +3 -3
- package/services/notification-datasource.provider.d.ts +3 -3
- package/services/notification-helper.service.d.ts +5 -5
- package/services/notification.service.d.ts +8 -8
- package/cjs/adapters/index.js +0 -18
- package/cjs/adapters/notification.adapter.js +0 -62
- package/cjs/adapters/notification.adapter.spec.js +0 -73
- package/cjs/config/event-actions.js +0 -33
- package/cjs/config/index.js +0 -20
- package/cjs/config/message-keys.js +0 -19
- package/cjs/config/notification.constants.js +0 -11
- package/cjs/controllers/index.js +0 -18
- package/cjs/controllers/notification.controller.js +0 -299
- package/cjs/controllers/notification.controller.spec.js +0 -214
- package/cjs/docs/index.js +0 -18
- package/cjs/docs/notification-swagger.config.js +0 -97
- package/cjs/docs/notification-swagger.config.spec.js +0 -68
- package/cjs/dtos/index.js +0 -18
- package/cjs/dtos/notification.dto.js +0 -295
- package/cjs/entities/index.js +0 -48
- package/cjs/entities/index.spec.js +0 -13
- package/cjs/entities/notification-with-company.entity.js +0 -57
- package/cjs/entities/notification.entity.js +0 -112
- package/cjs/gateways/index.js +0 -18
- package/cjs/gateways/notification.gateway.js +0 -172
- package/cjs/gateways/notification.gateway.spec.js +0 -359
- package/cjs/index.js +0 -28
- package/cjs/interfaces/index.js +0 -19
- package/cjs/interfaces/notification-module.interface.js +0 -4
- package/cjs/interfaces/notification.interface.js +0 -4
- package/cjs/modules/index.js +0 -18
- package/cjs/modules/notification.module.js +0 -139
- package/cjs/modules/notification.module.spec.js +0 -152
- package/cjs/services/index.js +0 -21
- package/cjs/services/notification-config.service.js +0 -69
- package/cjs/services/notification-config.service.spec.js +0 -113
- package/cjs/services/notification-datasource.provider.js +0 -133
- package/cjs/services/notification-datasource.provider.spec.js +0 -136
- package/cjs/services/notification-helper.service.js +0 -197
- package/cjs/services/notification-helper.service.spec.js +0 -392
- package/cjs/services/notification.service.js +0 -281
- package/cjs/services/notification.service.spec.js +0 -560
- package/fesm/adapters/notification.adapter.js +0 -52
- package/fesm/adapters/notification.adapter.spec.js +0 -69
- package/fesm/config/event-actions.js +0 -12
- package/fesm/config/message-keys.js +0 -9
- package/fesm/config/notification.constants.js +0 -1
- package/fesm/controllers/notification.controller.js +0 -289
- package/fesm/controllers/notification.controller.spec.js +0 -210
- package/fesm/docs/notification-swagger.config.js +0 -87
- package/fesm/docs/notification-swagger.config.spec.js +0 -64
- package/fesm/dtos/notification.dto.js +0 -262
- package/fesm/entities/index.spec.js +0 -9
- package/fesm/entities/notification-with-company.entity.js +0 -47
- package/fesm/entities/notification.entity.js +0 -102
- package/fesm/gateways/notification.gateway.js +0 -162
- package/fesm/gateways/notification.gateway.spec.js +0 -355
- package/fesm/interfaces/notification-module.interface.js +0 -1
- package/fesm/interfaces/notification.interface.js +0 -1
- package/fesm/modules/notification.module.js +0 -129
- package/fesm/modules/notification.module.spec.js +0 -148
- package/fesm/services/notification-config.service.js +0 -59
- package/fesm/services/notification-config.service.spec.js +0 -109
- package/fesm/services/notification-datasource.provider.js +0 -82
- package/fesm/services/notification-datasource.provider.spec.js +0 -132
- package/fesm/services/notification-helper.service.js +0 -187
- package/fesm/services/notification-helper.service.spec.js +0 -388
- package/fesm/services/notification.service.js +0 -271
- package/fesm/services/notification.service.spec.js +0 -556
|
@@ -1,139 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
Object.defineProperty(exports, "NotificationModule", {
|
|
6
|
-
enumerable: true,
|
|
7
|
-
get: function() {
|
|
8
|
-
return NotificationModule;
|
|
9
|
-
}
|
|
10
|
-
});
|
|
11
|
-
const _modules = require("@flusys/nestjs-shared/modules");
|
|
12
|
-
const _interfaces = require("@flusys/nestjs-shared/interfaces");
|
|
13
|
-
const _common = require("@nestjs/common");
|
|
14
|
-
const _jwt = require("@nestjs/jwt");
|
|
15
|
-
const _notificationconstants = require("../config/notification.constants");
|
|
16
|
-
const _controllers = require("../controllers");
|
|
17
|
-
const _adapters = require("../adapters");
|
|
18
|
-
const _services = require("../services");
|
|
19
|
-
const _gateways = require("../gateways");
|
|
20
|
-
function _ts_decorate(decorators, target, key, desc) {
|
|
21
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
22
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
23
|
-
else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
24
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
25
|
-
}
|
|
26
|
-
const CONTROLLERS = [
|
|
27
|
-
_controllers.NotificationController
|
|
28
|
-
];
|
|
29
|
-
const EXPORTED_SERVICES = [
|
|
30
|
-
_services.NotificationConfigService,
|
|
31
|
-
_services.NotificationDataSourceProvider,
|
|
32
|
-
_services.NotificationService,
|
|
33
|
-
_services.NotificationHelperService
|
|
34
|
-
];
|
|
35
|
-
const ADAPTER_PROVIDER = {
|
|
36
|
-
provide: _interfaces.NOTIFICATION_ADAPTER,
|
|
37
|
-
useClass: _adapters.NotificationAdapter
|
|
38
|
-
};
|
|
39
|
-
let NotificationModule = class NotificationModule {
|
|
40
|
-
static forRoot(options) {
|
|
41
|
-
return {
|
|
42
|
-
module: NotificationModule,
|
|
43
|
-
global: options.global ?? false,
|
|
44
|
-
imports: [
|
|
45
|
-
_modules.CacheModule,
|
|
46
|
-
_modules.UtilsModule
|
|
47
|
-
],
|
|
48
|
-
controllers: options.includeController !== false ? CONTROLLERS : [],
|
|
49
|
-
providers: [
|
|
50
|
-
...this.buildProviders(options),
|
|
51
|
-
_jwt.JwtService,
|
|
52
|
-
_gateways.NotificationGateway,
|
|
53
|
-
_adapters.NotificationAdapter,
|
|
54
|
-
ADAPTER_PROVIDER
|
|
55
|
-
],
|
|
56
|
-
exports: [
|
|
57
|
-
...EXPORTED_SERVICES,
|
|
58
|
-
_gateways.NotificationGateway,
|
|
59
|
-
_interfaces.NOTIFICATION_ADAPTER
|
|
60
|
-
]
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
static forRootAsync(options) {
|
|
64
|
-
return {
|
|
65
|
-
module: NotificationModule,
|
|
66
|
-
global: options.global ?? false,
|
|
67
|
-
imports: [
|
|
68
|
-
...options.imports || [],
|
|
69
|
-
_modules.CacheModule,
|
|
70
|
-
_modules.UtilsModule
|
|
71
|
-
],
|
|
72
|
-
controllers: options.includeController !== false ? CONTROLLERS : [],
|
|
73
|
-
providers: [
|
|
74
|
-
...this.createAsyncProviders(options),
|
|
75
|
-
...this.buildProviders(),
|
|
76
|
-
_jwt.JwtService,
|
|
77
|
-
_gateways.NotificationGateway,
|
|
78
|
-
_adapters.NotificationAdapter,
|
|
79
|
-
ADAPTER_PROVIDER
|
|
80
|
-
],
|
|
81
|
-
exports: [
|
|
82
|
-
...EXPORTED_SERVICES,
|
|
83
|
-
_gateways.NotificationGateway,
|
|
84
|
-
_interfaces.NOTIFICATION_ADAPTER
|
|
85
|
-
]
|
|
86
|
-
};
|
|
87
|
-
}
|
|
88
|
-
static buildProviders(options) {
|
|
89
|
-
const providers = [
|
|
90
|
-
...EXPORTED_SERVICES
|
|
91
|
-
];
|
|
92
|
-
if (options) {
|
|
93
|
-
providers.unshift({
|
|
94
|
-
provide: _notificationconstants.NOTIFICATION_MODULE_OPTIONS,
|
|
95
|
-
useValue: options
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
providers.push((0, _modules.createModuleEventsProvider)('notification', _notificationconstants.NOTIFICATION_MODULE_OPTIONS));
|
|
99
|
-
return providers;
|
|
100
|
-
}
|
|
101
|
-
static createAsyncProviders(options) {
|
|
102
|
-
if (options.useFactory) {
|
|
103
|
-
return [
|
|
104
|
-
{
|
|
105
|
-
provide: _notificationconstants.NOTIFICATION_MODULE_OPTIONS,
|
|
106
|
-
useFactory: async (...args)=>({
|
|
107
|
-
...options,
|
|
108
|
-
config: await options.useFactory(...args)
|
|
109
|
-
}),
|
|
110
|
-
inject: options.inject || []
|
|
111
|
-
}
|
|
112
|
-
];
|
|
113
|
-
}
|
|
114
|
-
const factoryClass = options.useClass || options.useExisting;
|
|
115
|
-
if (!factoryClass) return [];
|
|
116
|
-
const providers = [
|
|
117
|
-
{
|
|
118
|
-
provide: _notificationconstants.NOTIFICATION_MODULE_OPTIONS,
|
|
119
|
-
useFactory: async (factory)=>({
|
|
120
|
-
...options,
|
|
121
|
-
config: await factory.createNotificationOptions()
|
|
122
|
-
}),
|
|
123
|
-
inject: [
|
|
124
|
-
factoryClass
|
|
125
|
-
]
|
|
126
|
-
}
|
|
127
|
-
];
|
|
128
|
-
if (options.useClass) {
|
|
129
|
-
providers.push({
|
|
130
|
-
provide: options.useClass,
|
|
131
|
-
useClass: options.useClass
|
|
132
|
-
});
|
|
133
|
-
}
|
|
134
|
-
return providers;
|
|
135
|
-
}
|
|
136
|
-
};
|
|
137
|
-
NotificationModule = _ts_decorate([
|
|
138
|
-
(0, _common.Module)({})
|
|
139
|
-
], NotificationModule);
|
|
@@ -1,152 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
const _interfaces = require("@flusys/nestjs-shared/interfaces");
|
|
6
|
-
const _notificationmodule = require("./notification.module");
|
|
7
|
-
const _notificationconstants = require("../config/notification.constants");
|
|
8
|
-
const _controllers = require("../controllers");
|
|
9
|
-
const _gateways = require("../gateways");
|
|
10
|
-
const _adapters = require("../adapters");
|
|
11
|
-
function _define_property(obj, key, value) {
|
|
12
|
-
if (key in obj) {
|
|
13
|
-
Object.defineProperty(obj, key, {
|
|
14
|
-
value: value,
|
|
15
|
-
enumerable: true,
|
|
16
|
-
configurable: true,
|
|
17
|
-
writable: true
|
|
18
|
-
});
|
|
19
|
-
} else {
|
|
20
|
-
obj[key] = value;
|
|
21
|
-
}
|
|
22
|
-
return obj;
|
|
23
|
-
}
|
|
24
|
-
function providerTokens(providers) {
|
|
25
|
-
return providers.map((p)=>typeof p === 'function' ? p : p.provide);
|
|
26
|
-
}
|
|
27
|
-
describe('NotificationModule', ()=>{
|
|
28
|
-
describe('forRoot', ()=>{
|
|
29
|
-
it('should default to a non-global module with the notification controller registered', ()=>{
|
|
30
|
-
const dynamicModule = _notificationmodule.NotificationModule.forRoot({});
|
|
31
|
-
expect(dynamicModule.module).toBe(_notificationmodule.NotificationModule);
|
|
32
|
-
expect(dynamicModule.global).toBe(false);
|
|
33
|
-
expect(dynamicModule.controllers).toEqual([
|
|
34
|
-
_controllers.NotificationController
|
|
35
|
-
]);
|
|
36
|
-
});
|
|
37
|
-
it('should respect global: true', ()=>{
|
|
38
|
-
expect(_notificationmodule.NotificationModule.forRoot({
|
|
39
|
-
global: true
|
|
40
|
-
}).global).toBe(true);
|
|
41
|
-
});
|
|
42
|
-
it('should register no controllers when includeController is false', ()=>{
|
|
43
|
-
expect(_notificationmodule.NotificationModule.forRoot({
|
|
44
|
-
includeController: false
|
|
45
|
-
}).controllers).toEqual([]);
|
|
46
|
-
});
|
|
47
|
-
it('should register the NOTIFICATION_ADAPTER provider backed by NotificationAdapter', ()=>{
|
|
48
|
-
const dynamicModule = _notificationmodule.NotificationModule.forRoot({});
|
|
49
|
-
const adapterProvider = dynamicModule.providers.find((p)=>p.provide === _interfaces.NOTIFICATION_ADAPTER);
|
|
50
|
-
expect(adapterProvider.useClass).toBe(_adapters.NotificationAdapter);
|
|
51
|
-
expect(providerTokens(dynamicModule.providers)).toContain(_gateways.NotificationGateway);
|
|
52
|
-
});
|
|
53
|
-
it('should export NotificationGateway and NOTIFICATION_ADAPTER alongside the base services', ()=>{
|
|
54
|
-
const dynamicModule = _notificationmodule.NotificationModule.forRoot({});
|
|
55
|
-
expect(dynamicModule.exports).toEqual(expect.arrayContaining([
|
|
56
|
-
_gateways.NotificationGateway,
|
|
57
|
-
_interfaces.NOTIFICATION_ADAPTER
|
|
58
|
-
]));
|
|
59
|
-
});
|
|
60
|
-
it('should register a NOTIFICATION_MODULE_OPTIONS provider carrying the given options', ()=>{
|
|
61
|
-
const options = {
|
|
62
|
-
bootstrapAppConfig: {
|
|
63
|
-
enableCompanyFeature: true
|
|
64
|
-
}
|
|
65
|
-
};
|
|
66
|
-
const dynamicModule = _notificationmodule.NotificationModule.forRoot(options);
|
|
67
|
-
const provider = dynamicModule.providers.find((p)=>p.provide === _notificationconstants.NOTIFICATION_MODULE_OPTIONS);
|
|
68
|
-
expect(provider.useValue).toBe(options);
|
|
69
|
-
});
|
|
70
|
-
});
|
|
71
|
-
describe('forRootAsync', ()=>{
|
|
72
|
-
it('should forward external imports alongside CacheModule/UtilsModule', ()=>{
|
|
73
|
-
let FakeImportedModule = class FakeImportedModule {
|
|
74
|
-
};
|
|
75
|
-
const dynamicModule = _notificationmodule.NotificationModule.forRootAsync({
|
|
76
|
-
imports: [
|
|
77
|
-
FakeImportedModule
|
|
78
|
-
]
|
|
79
|
-
});
|
|
80
|
-
expect(dynamicModule.imports).toEqual(expect.arrayContaining([
|
|
81
|
-
FakeImportedModule
|
|
82
|
-
]));
|
|
83
|
-
});
|
|
84
|
-
it('should still wire the adapter/gateway providers when using async registration', ()=>{
|
|
85
|
-
const dynamicModule = _notificationmodule.NotificationModule.forRootAsync({
|
|
86
|
-
useFactory: jest.fn()
|
|
87
|
-
});
|
|
88
|
-
const adapterProvider = dynamicModule.providers.find((p)=>p.provide === _interfaces.NOTIFICATION_ADAPTER);
|
|
89
|
-
expect(adapterProvider.useClass).toBe(_adapters.NotificationAdapter);
|
|
90
|
-
});
|
|
91
|
-
it('useFactory: builds a NOTIFICATION_MODULE_OPTIONS provider merging resolved config', async ()=>{
|
|
92
|
-
const useFactory = jest.fn().mockResolvedValue({
|
|
93
|
-
foo: 'bar'
|
|
94
|
-
});
|
|
95
|
-
const dynamicModule = _notificationmodule.NotificationModule.forRootAsync({
|
|
96
|
-
useFactory,
|
|
97
|
-
inject: [
|
|
98
|
-
'SOME_TOKEN'
|
|
99
|
-
]
|
|
100
|
-
});
|
|
101
|
-
const provider = dynamicModule.providers.find((p)=>p.provide === _notificationconstants.NOTIFICATION_MODULE_OPTIONS);
|
|
102
|
-
expect(provider.inject).toEqual([
|
|
103
|
-
'SOME_TOKEN'
|
|
104
|
-
]);
|
|
105
|
-
const resolved = await provider.useFactory('injected');
|
|
106
|
-
expect(useFactory).toHaveBeenCalledWith('injected');
|
|
107
|
-
expect(resolved.config).toEqual({
|
|
108
|
-
foo: 'bar'
|
|
109
|
-
});
|
|
110
|
-
});
|
|
111
|
-
it('useClass: registers both the class provider and an options provider calling createNotificationOptions()', async ()=>{
|
|
112
|
-
let MyOptionsFactory = class MyOptionsFactory {
|
|
113
|
-
constructor(){
|
|
114
|
-
_define_property(this, "createNotificationOptions", jest.fn().mockResolvedValue({
|
|
115
|
-
foo: 'from-class'
|
|
116
|
-
}));
|
|
117
|
-
}
|
|
118
|
-
};
|
|
119
|
-
const dynamicModule = _notificationmodule.NotificationModule.forRootAsync({
|
|
120
|
-
useClass: MyOptionsFactory
|
|
121
|
-
});
|
|
122
|
-
const classProvider = dynamicModule.providers.find((p)=>p.provide === MyOptionsFactory);
|
|
123
|
-
expect(classProvider.useClass).toBe(MyOptionsFactory);
|
|
124
|
-
const optionsProvider = dynamicModule.providers.find((p)=>p.provide === _notificationconstants.NOTIFICATION_MODULE_OPTIONS);
|
|
125
|
-
const instance = new MyOptionsFactory();
|
|
126
|
-
const resolved = await optionsProvider.useFactory(instance);
|
|
127
|
-
expect(instance.createNotificationOptions).toHaveBeenCalled();
|
|
128
|
-
expect(resolved.config).toEqual({
|
|
129
|
-
foo: 'from-class'
|
|
130
|
-
});
|
|
131
|
-
});
|
|
132
|
-
it('useExisting: registers a single options provider without a duplicate class registration', ()=>{
|
|
133
|
-
let MyOptionsFactory = class MyOptionsFactory {
|
|
134
|
-
constructor(){
|
|
135
|
-
_define_property(this, "createNotificationOptions", jest.fn());
|
|
136
|
-
}
|
|
137
|
-
};
|
|
138
|
-
const dynamicModule = _notificationmodule.NotificationModule.forRootAsync({
|
|
139
|
-
useExisting: MyOptionsFactory
|
|
140
|
-
});
|
|
141
|
-
expect(dynamicModule.providers.filter((p)=>p.provide === MyOptionsFactory)).toHaveLength(0);
|
|
142
|
-
const optionsProvider = dynamicModule.providers.find((p)=>p.provide === _notificationconstants.NOTIFICATION_MODULE_OPTIONS);
|
|
143
|
-
expect(optionsProvider.inject).toEqual([
|
|
144
|
-
MyOptionsFactory
|
|
145
|
-
]);
|
|
146
|
-
});
|
|
147
|
-
it('should register no NOTIFICATION_MODULE_OPTIONS provider when neither useFactory, useClass, nor useExisting is given', ()=>{
|
|
148
|
-
const dynamicModule = _notificationmodule.NotificationModule.forRootAsync({});
|
|
149
|
-
expect(providerTokens(dynamicModule.providers)).not.toContain(_notificationconstants.NOTIFICATION_MODULE_OPTIONS);
|
|
150
|
-
});
|
|
151
|
-
});
|
|
152
|
-
});
|
package/cjs/services/index.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
_export_star(require("./notification-config.service"), exports);
|
|
6
|
-
_export_star(require("./notification-datasource.provider"), exports);
|
|
7
|
-
_export_star(require("./notification.service"), exports);
|
|
8
|
-
_export_star(require("./notification-helper.service"), exports);
|
|
9
|
-
function _export_star(from, to) {
|
|
10
|
-
Object.keys(from).forEach(function(k) {
|
|
11
|
-
if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
|
|
12
|
-
Object.defineProperty(to, k, {
|
|
13
|
-
enumerable: true,
|
|
14
|
-
get: function() {
|
|
15
|
-
return from[k];
|
|
16
|
-
}
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
});
|
|
20
|
-
return from;
|
|
21
|
-
}
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
Object.defineProperty(exports, "NotificationConfigService", {
|
|
6
|
-
enumerable: true,
|
|
7
|
-
get: function() {
|
|
8
|
-
return NotificationConfigService;
|
|
9
|
-
}
|
|
10
|
-
});
|
|
11
|
-
const _common = require("@nestjs/common");
|
|
12
|
-
const _interfaces = require("../interfaces");
|
|
13
|
-
const _notificationconstants = require("../config/notification.constants");
|
|
14
|
-
function _define_property(obj, key, value) {
|
|
15
|
-
if (key in obj) {
|
|
16
|
-
Object.defineProperty(obj, key, {
|
|
17
|
-
value: value,
|
|
18
|
-
enumerable: true,
|
|
19
|
-
configurable: true,
|
|
20
|
-
writable: true
|
|
21
|
-
});
|
|
22
|
-
} else {
|
|
23
|
-
obj[key] = value;
|
|
24
|
-
}
|
|
25
|
-
return obj;
|
|
26
|
-
}
|
|
27
|
-
function _ts_decorate(decorators, target, key, desc) {
|
|
28
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
29
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
30
|
-
else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
31
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
32
|
-
}
|
|
33
|
-
function _ts_metadata(k, v) {
|
|
34
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
35
|
-
}
|
|
36
|
-
function _ts_param(paramIndex, decorator) {
|
|
37
|
-
return function(target, key) {
|
|
38
|
-
decorator(target, key, paramIndex);
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
let NotificationConfigService = class NotificationConfigService {
|
|
42
|
-
isCompanyFeatureEnabled() {
|
|
43
|
-
return this.options.bootstrapAppConfig?.enableCompanyFeature ?? false;
|
|
44
|
-
}
|
|
45
|
-
getDatabaseMode() {
|
|
46
|
-
return this.options.bootstrapAppConfig?.databaseMode ?? 'single';
|
|
47
|
-
}
|
|
48
|
-
isMultiTenant() {
|
|
49
|
-
return this.getDatabaseMode() === 'multi-tenant';
|
|
50
|
-
}
|
|
51
|
-
getJwtSecret() {
|
|
52
|
-
return this.options.config?.jwtSecret;
|
|
53
|
-
}
|
|
54
|
-
getOptions() {
|
|
55
|
-
return this.options;
|
|
56
|
-
}
|
|
57
|
-
constructor(options){
|
|
58
|
-
_define_property(this, "options", void 0);
|
|
59
|
-
this.options = options;
|
|
60
|
-
}
|
|
61
|
-
};
|
|
62
|
-
NotificationConfigService = _ts_decorate([
|
|
63
|
-
(0, _common.Injectable)(),
|
|
64
|
-
_ts_param(0, (0, _common.Inject)(_notificationconstants.NOTIFICATION_MODULE_OPTIONS)),
|
|
65
|
-
_ts_metadata("design:type", Function),
|
|
66
|
-
_ts_metadata("design:paramtypes", [
|
|
67
|
-
typeof _interfaces.NotificationModuleOptions === "undefined" ? Object : _interfaces.NotificationModuleOptions
|
|
68
|
-
])
|
|
69
|
-
], NotificationConfigService);
|
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
const _notificationconfigservice = require("./notification-config.service");
|
|
6
|
-
function buildOptions(overrides = {}) {
|
|
7
|
-
return {
|
|
8
|
-
bootstrapAppConfig: {
|
|
9
|
-
databaseMode: 'single',
|
|
10
|
-
enableCompanyFeature: false
|
|
11
|
-
},
|
|
12
|
-
config: {},
|
|
13
|
-
...overrides
|
|
14
|
-
};
|
|
15
|
-
}
|
|
16
|
-
describe('NotificationConfigService', ()=>{
|
|
17
|
-
describe('isCompanyFeatureEnabled', ()=>{
|
|
18
|
-
it('returns true when bootstrapAppConfig enables the company feature', ()=>{
|
|
19
|
-
const service = new _notificationconfigservice.NotificationConfigService(buildOptions({
|
|
20
|
-
bootstrapAppConfig: {
|
|
21
|
-
databaseMode: 'single',
|
|
22
|
-
enableCompanyFeature: true
|
|
23
|
-
}
|
|
24
|
-
}));
|
|
25
|
-
expect(service.isCompanyFeatureEnabled()).toBe(true);
|
|
26
|
-
});
|
|
27
|
-
it('returns false when bootstrapAppConfig disables the company feature', ()=>{
|
|
28
|
-
const service = new _notificationconfigservice.NotificationConfigService(buildOptions({
|
|
29
|
-
bootstrapAppConfig: {
|
|
30
|
-
databaseMode: 'single',
|
|
31
|
-
enableCompanyFeature: false
|
|
32
|
-
}
|
|
33
|
-
}));
|
|
34
|
-
expect(service.isCompanyFeatureEnabled()).toBe(false);
|
|
35
|
-
});
|
|
36
|
-
it('defaults to false when bootstrapAppConfig is missing', ()=>{
|
|
37
|
-
const service = new _notificationconfigservice.NotificationConfigService(buildOptions({
|
|
38
|
-
bootstrapAppConfig: undefined
|
|
39
|
-
}));
|
|
40
|
-
expect(service.isCompanyFeatureEnabled()).toBe(false);
|
|
41
|
-
});
|
|
42
|
-
});
|
|
43
|
-
describe('getDatabaseMode', ()=>{
|
|
44
|
-
it('returns the configured database mode', ()=>{
|
|
45
|
-
const service = new _notificationconfigservice.NotificationConfigService(buildOptions({
|
|
46
|
-
bootstrapAppConfig: {
|
|
47
|
-
databaseMode: 'multi-tenant',
|
|
48
|
-
enableCompanyFeature: true
|
|
49
|
-
}
|
|
50
|
-
}));
|
|
51
|
-
expect(service.getDatabaseMode()).toBe('multi-tenant');
|
|
52
|
-
});
|
|
53
|
-
it('defaults to "single" when bootstrapAppConfig is missing', ()=>{
|
|
54
|
-
const service = new _notificationconfigservice.NotificationConfigService(buildOptions({
|
|
55
|
-
bootstrapAppConfig: undefined
|
|
56
|
-
}));
|
|
57
|
-
expect(service.getDatabaseMode()).toBe('single');
|
|
58
|
-
});
|
|
59
|
-
});
|
|
60
|
-
describe('isMultiTenant', ()=>{
|
|
61
|
-
it('returns true when database mode is multi-tenant', ()=>{
|
|
62
|
-
const service = new _notificationconfigservice.NotificationConfigService(buildOptions({
|
|
63
|
-
bootstrapAppConfig: {
|
|
64
|
-
databaseMode: 'multi-tenant',
|
|
65
|
-
enableCompanyFeature: true
|
|
66
|
-
}
|
|
67
|
-
}));
|
|
68
|
-
expect(service.isMultiTenant()).toBe(true);
|
|
69
|
-
});
|
|
70
|
-
it('returns false when database mode is single', ()=>{
|
|
71
|
-
const service = new _notificationconfigservice.NotificationConfigService(buildOptions({
|
|
72
|
-
bootstrapAppConfig: {
|
|
73
|
-
databaseMode: 'single',
|
|
74
|
-
enableCompanyFeature: false
|
|
75
|
-
}
|
|
76
|
-
}));
|
|
77
|
-
expect(service.isMultiTenant()).toBe(false);
|
|
78
|
-
});
|
|
79
|
-
});
|
|
80
|
-
describe('getJwtSecret', ()=>{
|
|
81
|
-
it('returns the configured jwt secret', ()=>{
|
|
82
|
-
const service = new _notificationconfigservice.NotificationConfigService(buildOptions({
|
|
83
|
-
config: {
|
|
84
|
-
jwtSecret: 'top-secret'
|
|
85
|
-
}
|
|
86
|
-
}));
|
|
87
|
-
expect(service.getJwtSecret()).toBe('top-secret');
|
|
88
|
-
});
|
|
89
|
-
it('returns undefined when no jwt secret is configured', ()=>{
|
|
90
|
-
const service = new _notificationconfigservice.NotificationConfigService(buildOptions({
|
|
91
|
-
config: {}
|
|
92
|
-
}));
|
|
93
|
-
expect(service.getJwtSecret()).toBeUndefined();
|
|
94
|
-
});
|
|
95
|
-
it('returns undefined when config is missing entirely', ()=>{
|
|
96
|
-
const service = new _notificationconfigservice.NotificationConfigService(buildOptions({
|
|
97
|
-
config: undefined
|
|
98
|
-
}));
|
|
99
|
-
expect(service.getJwtSecret()).toBeUndefined();
|
|
100
|
-
});
|
|
101
|
-
});
|
|
102
|
-
describe('getOptions', ()=>{
|
|
103
|
-
it('returns the raw options object passed to the constructor', ()=>{
|
|
104
|
-
const options = buildOptions({
|
|
105
|
-
config: {
|
|
106
|
-
jwtSecret: 'abc'
|
|
107
|
-
}
|
|
108
|
-
});
|
|
109
|
-
const service = new _notificationconfigservice.NotificationConfigService(options);
|
|
110
|
-
expect(service.getOptions()).toBe(options);
|
|
111
|
-
});
|
|
112
|
-
});
|
|
113
|
-
});
|
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
Object.defineProperty(exports, "NotificationDataSourceProvider", {
|
|
6
|
-
enumerable: true,
|
|
7
|
-
get: function() {
|
|
8
|
-
return NotificationDataSourceProvider;
|
|
9
|
-
}
|
|
10
|
-
});
|
|
11
|
-
const _modules = require("@flusys/nestjs-shared/modules");
|
|
12
|
-
const _common = require("@nestjs/common");
|
|
13
|
-
const _core = require("@nestjs/core");
|
|
14
|
-
const _express = require("express");
|
|
15
|
-
const _notificationconfigservice = require("./notification-config.service");
|
|
16
|
-
function _define_property(obj, key, value) {
|
|
17
|
-
if (key in obj) {
|
|
18
|
-
Object.defineProperty(obj, key, {
|
|
19
|
-
value: value,
|
|
20
|
-
enumerable: true,
|
|
21
|
-
configurable: true,
|
|
22
|
-
writable: true
|
|
23
|
-
});
|
|
24
|
-
} else {
|
|
25
|
-
obj[key] = value;
|
|
26
|
-
}
|
|
27
|
-
return obj;
|
|
28
|
-
}
|
|
29
|
-
function _getRequireWildcardCache(nodeInterop) {
|
|
30
|
-
if (typeof WeakMap !== "function") return null;
|
|
31
|
-
var cacheBabelInterop = new WeakMap();
|
|
32
|
-
var cacheNodeInterop = new WeakMap();
|
|
33
|
-
return (_getRequireWildcardCache = function(nodeInterop) {
|
|
34
|
-
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
|
|
35
|
-
})(nodeInterop);
|
|
36
|
-
}
|
|
37
|
-
function _interop_require_wildcard(obj, nodeInterop) {
|
|
38
|
-
if (!nodeInterop && obj && obj.__esModule) {
|
|
39
|
-
return obj;
|
|
40
|
-
}
|
|
41
|
-
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
|
|
42
|
-
return {
|
|
43
|
-
default: obj
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
var cache = _getRequireWildcardCache(nodeInterop);
|
|
47
|
-
if (cache && cache.has(obj)) {
|
|
48
|
-
return cache.get(obj);
|
|
49
|
-
}
|
|
50
|
-
var newObj = {
|
|
51
|
-
__proto__: null
|
|
52
|
-
};
|
|
53
|
-
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
54
|
-
for(var key in obj){
|
|
55
|
-
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
56
|
-
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
|
|
57
|
-
if (desc && (desc.get || desc.set)) {
|
|
58
|
-
Object.defineProperty(newObj, key, desc);
|
|
59
|
-
} else {
|
|
60
|
-
newObj[key] = obj[key];
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
newObj.default = obj;
|
|
65
|
-
if (cache) {
|
|
66
|
-
cache.set(obj, newObj);
|
|
67
|
-
}
|
|
68
|
-
return newObj;
|
|
69
|
-
}
|
|
70
|
-
function _ts_decorate(decorators, target, key, desc) {
|
|
71
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
72
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
73
|
-
else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
74
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
75
|
-
}
|
|
76
|
-
function _ts_metadata(k, v) {
|
|
77
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
78
|
-
}
|
|
79
|
-
function _ts_param(paramIndex, decorator) {
|
|
80
|
-
return function(target, key) {
|
|
81
|
-
decorator(target, key, paramIndex);
|
|
82
|
-
};
|
|
83
|
-
}
|
|
84
|
-
let NotificationDataSourceProvider = class NotificationDataSourceProvider extends _modules.MultiTenantDataSourceService {
|
|
85
|
-
static buildParentOptions(options) {
|
|
86
|
-
return {
|
|
87
|
-
bootstrapAppConfig: options.bootstrapAppConfig,
|
|
88
|
-
defaultDatabaseConfig: options.config?.defaultDatabaseConfig,
|
|
89
|
-
tenantDefaultDatabaseConfig: options.config?.tenantDefaultDatabaseConfig,
|
|
90
|
-
tenants: options.config?.tenants
|
|
91
|
-
};
|
|
92
|
-
}
|
|
93
|
-
getEnableCompanyFeatureForTenant(tenant) {
|
|
94
|
-
return tenant?.enableCompanyFeature ?? this.configService.isCompanyFeatureEnabled();
|
|
95
|
-
}
|
|
96
|
-
async getNotificationEntities(enableCompanyFeature) {
|
|
97
|
-
const enable = enableCompanyFeature ?? this.configService.isCompanyFeatureEnabled();
|
|
98
|
-
const entities = await Promise.resolve().then(()=>/*#__PURE__*/ _interop_require_wildcard(require("../entities")));
|
|
99
|
-
return enable ? [
|
|
100
|
-
entities.NotificationWithCompany
|
|
101
|
-
] : [
|
|
102
|
-
entities.Notification
|
|
103
|
-
];
|
|
104
|
-
}
|
|
105
|
-
async createDataSourceFromConfig(config) {
|
|
106
|
-
const currentTenant = this.getCurrentTenant();
|
|
107
|
-
const enableCompanyFeature = this.getEnableCompanyFeatureForTenant(currentTenant ?? undefined);
|
|
108
|
-
const entities = await this.getNotificationEntities(enableCompanyFeature);
|
|
109
|
-
return super.createDataSourceFromConfig(config, entities);
|
|
110
|
-
}
|
|
111
|
-
constructor(configService, request){
|
|
112
|
-
super(NotificationDataSourceProvider.buildParentOptions(configService.getOptions()), request), _define_property(this, "configService", void 0), this.configService = configService;
|
|
113
|
-
}
|
|
114
|
-
};
|
|
115
|
-
_define_property(NotificationDataSourceProvider, "tenantConnections", new Map());
|
|
116
|
-
_define_property(NotificationDataSourceProvider, "singleDataSource", null);
|
|
117
|
-
_define_property(NotificationDataSourceProvider, "tenantsRegistry", new Map());
|
|
118
|
-
_define_property(NotificationDataSourceProvider, "initialized", false);
|
|
119
|
-
_define_property(NotificationDataSourceProvider, "connectionLocks", new Map());
|
|
120
|
-
_define_property(NotificationDataSourceProvider, "singleConnectionLock", null);
|
|
121
|
-
NotificationDataSourceProvider = _ts_decorate([
|
|
122
|
-
(0, _common.Injectable)({
|
|
123
|
-
scope: _common.Scope.REQUEST
|
|
124
|
-
}),
|
|
125
|
-
_ts_param(0, (0, _common.Inject)(_notificationconfigservice.NotificationConfigService)),
|
|
126
|
-
_ts_param(1, (0, _common.Optional)()),
|
|
127
|
-
_ts_param(1, (0, _common.Inject)(_core.REQUEST)),
|
|
128
|
-
_ts_metadata("design:type", Function),
|
|
129
|
-
_ts_metadata("design:paramtypes", [
|
|
130
|
-
typeof _notificationconfigservice.NotificationConfigService === "undefined" ? Object : _notificationconfigservice.NotificationConfigService,
|
|
131
|
-
typeof _express.Request === "undefined" ? Object : _express.Request
|
|
132
|
-
])
|
|
133
|
-
], NotificationDataSourceProvider);
|