@mbc-cqrs-serverless/core 1.3.3 → 1.3.4
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/README.md +37 -0
- package/dist/app.module.js +2 -0
- package/dist/app.module.js.map +1 -1
- package/dist/auth/auth.module.d.ts +2 -0
- package/dist/auth/auth.module.js +30 -0
- package/dist/auth/auth.module.js.map +1 -0
- package/dist/auth/authz-bootstrap.service.d.ts +11 -0
- package/dist/auth/authz-bootstrap.service.js +47 -0
- package/dist/auth/authz-bootstrap.service.js.map +1 -0
- package/dist/auth/group-role-resolver.interface.d.ts +13 -0
- package/dist/auth/group-role-resolver.interface.js +3 -0
- package/dist/auth/group-role-resolver.interface.js.map +1 -0
- package/dist/auth/group-role-resolver.registry.d.ts +6 -0
- package/dist/auth/group-role-resolver.registry.js +26 -0
- package/dist/auth/group-role-resolver.registry.js.map +1 -0
- package/dist/auth/index.d.ts +4 -0
- package/dist/auth/index.js +21 -0
- package/dist/auth/index.js.map +1 -0
- package/dist/commands/command.event.handler.js +8 -2
- package/dist/commands/command.event.handler.js.map +1 -1
- package/dist/commands/command.service.js +35 -9
- package/dist/commands/command.service.js.map +1 -1
- package/dist/context/invoke.d.ts +1 -0
- package/dist/context/invoke.js +1 -1
- package/dist/context/invoke.js.map +1 -1
- package/dist/context/user.d.ts +4 -0
- package/dist/context/user.js +50 -0
- package/dist/context/user.js.map +1 -1
- package/dist/decorators/constants.d.ts +2 -0
- package/dist/decorators/constants.js +3 -1
- package/dist/decorators/constants.js.map +1 -1
- package/dist/decorators/data-sync-handler.decorator.d.ts +19 -0
- package/dist/decorators/data-sync-handler.decorator.js +19 -0
- package/dist/decorators/data-sync-handler.decorator.js.map +1 -1
- package/dist/decorators/group-role-resolver.decorator.d.ts +9 -0
- package/dist/decorators/group-role-resolver.decorator.js +17 -0
- package/dist/decorators/group-role-resolver.decorator.js.map +1 -0
- package/dist/decorators/index.d.ts +2 -0
- package/dist/decorators/index.js +2 -0
- package/dist/decorators/index.js.map +1 -1
- package/dist/decorators/notification-transport.decorator.d.ts +6 -0
- package/dist/decorators/notification-transport.decorator.js +14 -0
- package/dist/decorators/notification-transport.decorator.js.map +1 -0
- package/dist/env.validation.d.ts +19 -0
- package/dist/env.validation.js +22 -1
- package/dist/env.validation.js.map +1 -1
- package/dist/guard/roles.guard.d.ts +11 -1
- package/dist/guard/roles.guard.js +44 -8
- package/dist/guard/roles.guard.js.map +1 -1
- package/dist/helpers/serializer.d.ts +1 -2
- package/dist/helpers/serializer.js +34 -7
- package/dist/helpers/serializer.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/interfaces/command-module-options.interface.d.ts +11 -1
- package/dist/notification-env.validation.d.ts +8 -0
- package/dist/notification-env.validation.js +36 -0
- package/dist/notification-env.validation.js.map +1 -0
- package/dist/notifications/appsync-events.service.d.ts +44 -0
- package/dist/notifications/appsync-events.service.js +147 -0
- package/dist/notifications/appsync-events.service.js.map +1 -0
- package/dist/notifications/appsync.service.d.ts +3 -2
- package/dist/notifications/appsync.service.js +20 -12
- package/dist/notifications/appsync.service.js.map +1 -1
- package/dist/notifications/enums/index.d.ts +1 -0
- package/dist/notifications/enums/index.js +18 -0
- package/dist/notifications/enums/index.js.map +1 -0
- package/dist/notifications/enums/notification-transport.enum.d.ts +4 -0
- package/dist/notifications/enums/notification-transport.enum.js +9 -0
- package/dist/notifications/enums/notification-transport.enum.js.map +1 -0
- package/dist/notifications/event/notification.event.handler.d.ts +13 -5
- package/dist/notifications/event/notification.event.handler.js +31 -7
- package/dist/notifications/event/notification.event.handler.js.map +1 -1
- package/dist/notifications/index.d.ts +3 -0
- package/dist/notifications/index.js +3 -0
- package/dist/notifications/index.js.map +1 -1
- package/dist/notifications/interfaces/index.d.ts +1 -0
- package/dist/notifications/interfaces/index.js +18 -0
- package/dist/notifications/interfaces/index.js.map +1 -0
- package/dist/notifications/interfaces/notification-transport.interface.d.ts +7 -0
- package/dist/notifications/interfaces/notification-transport.interface.js +5 -0
- package/dist/notifications/interfaces/notification-transport.interface.js.map +1 -0
- package/dist/notifications/notification.module.js +12 -2
- package/dist/notifications/notification.module.js.map +1 -1
- package/dist/services/explorer.service.d.ts +5 -0
- package/dist/services/explorer.service.js +12 -1
- package/dist/services/explorer.service.js.map +1 -1
- package/dist/services/mocks/group-role-resolver.mock.d.ts +4 -0
- package/dist/services/mocks/group-role-resolver.mock.js +20 -0
- package/dist/services/mocks/group-role-resolver.mock.js.map +1 -0
- package/package.json +4 -4
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { ConfigService } from '@nestjs/config';
|
|
2
|
+
import { INotification } from '../interfaces';
|
|
3
|
+
import { INotificationTransport } from './interfaces';
|
|
4
|
+
export declare class AppSyncEventsService implements INotificationTransport {
|
|
5
|
+
private readonly config;
|
|
6
|
+
private readonly logger;
|
|
7
|
+
private readonly url;
|
|
8
|
+
private readonly namespace;
|
|
9
|
+
private readonly signer;
|
|
10
|
+
constructor(config: ConfigService);
|
|
11
|
+
/**
|
|
12
|
+
* Publish INotification to an AppSync Events channel via IAM SigV4.
|
|
13
|
+
*
|
|
14
|
+
* Channel structure (max 5 segments, seg 1 = namespace):
|
|
15
|
+
* /{namespace}/{tenantCode}/{action}/{sanitizedId}
|
|
16
|
+
*
|
|
17
|
+
* Client subscription options (wildcard /* catches all sub-channels):
|
|
18
|
+
* /{namespace}/{tenantCode}/* — all events for tenant
|
|
19
|
+
* /{namespace}/{tenantCode}/{action}/* — filtered by action
|
|
20
|
+
* /{namespace}/{tenantCode}/{action}/{id} — specific command
|
|
21
|
+
*
|
|
22
|
+
* Requires: Lambda execution role must have appsync:EventPublish permission.
|
|
23
|
+
*/
|
|
24
|
+
sendMessage(notification: INotification): Promise<void>;
|
|
25
|
+
/**
|
|
26
|
+
* Resolves the most specific channel path for a notification.
|
|
27
|
+
* Non-alphanumeric characters (e.g. #, @) are sanitized to dashes
|
|
28
|
+
* since AppSync Events channel segments only allow [a-zA-Z0-9-].
|
|
29
|
+
*/
|
|
30
|
+
resolveChannel(notification: INotification): string;
|
|
31
|
+
/**
|
|
32
|
+
* Formats a string to comply with AppSync Events API channel segment rules:
|
|
33
|
+
* 1. Only alphanumeric characters and dashes.
|
|
34
|
+
* 2. Cannot start or end with a dash.
|
|
35
|
+
* 3. Maximum length of 50 characters.
|
|
36
|
+
*/
|
|
37
|
+
private sanitizeSegment;
|
|
38
|
+
private postToChannel;
|
|
39
|
+
/**
|
|
40
|
+
* Builds and signs an HttpRequest for the given channel and notification.
|
|
41
|
+
* Separating signing from the fetch call makes each step independently testable.
|
|
42
|
+
*/
|
|
43
|
+
private signRequest;
|
|
44
|
+
}
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
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;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
var AppSyncEventsService_1;
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
exports.AppSyncEventsService = void 0;
|
|
17
|
+
const node_crypto_1 = require("node:crypto");
|
|
18
|
+
const sha256_js_1 = require("@aws-crypto/sha256-js");
|
|
19
|
+
const credential_provider_node_1 = require("@aws-sdk/credential-provider-node");
|
|
20
|
+
const common_1 = require("@nestjs/common");
|
|
21
|
+
const config_1 = require("@nestjs/config");
|
|
22
|
+
const protocol_http_1 = require("@smithy/protocol-http");
|
|
23
|
+
const signature_v4_1 = require("@smithy/signature-v4");
|
|
24
|
+
const node_fetch_1 = __importDefault(require("node-fetch"));
|
|
25
|
+
const decorators_1 = require("../decorators");
|
|
26
|
+
const enums_1 = require("./enums");
|
|
27
|
+
/** Default headers required for AppSync Events API requests */
|
|
28
|
+
const DEFAULT_HEADERS = {
|
|
29
|
+
accept: 'application/json, text/javascript',
|
|
30
|
+
'content-encoding': 'amz-1.0',
|
|
31
|
+
'content-type': 'application/json; charset=UTF-8',
|
|
32
|
+
};
|
|
33
|
+
let AppSyncEventsService = AppSyncEventsService_1 = class AppSyncEventsService {
|
|
34
|
+
constructor(config) {
|
|
35
|
+
this.config = config;
|
|
36
|
+
this.logger = new common_1.Logger(AppSyncEventsService_1.name);
|
|
37
|
+
const endpoint = config.get('APPSYNC_EVENTS_ENDPOINT');
|
|
38
|
+
this.namespace = config.get('APPSYNC_EVENTS_NAMESPACE') ?? 'default';
|
|
39
|
+
if (endpoint) {
|
|
40
|
+
this.url = new URL(endpoint);
|
|
41
|
+
// Region is parsed from the hostname automatically:
|
|
42
|
+
// <id>.appsync-api.<region>.amazonaws.com → region
|
|
43
|
+
// Falls back to AWS_REGION env var (always set in Lambda runtime).
|
|
44
|
+
const match = this.url.hostname.match(/\w+\.appsync-api\.([\w-]+)\.amazonaws\.com/);
|
|
45
|
+
const region = match?.[1] ?? process.env.AWS_REGION ?? 'ap-northeast-1';
|
|
46
|
+
this.signer = new signature_v4_1.SignatureV4({
|
|
47
|
+
credentials: (0, credential_provider_node_1.defaultProvider)(),
|
|
48
|
+
service: 'appsync',
|
|
49
|
+
region,
|
|
50
|
+
sha256: sha256_js_1.Sha256,
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Publish INotification to an AppSync Events channel via IAM SigV4.
|
|
56
|
+
*
|
|
57
|
+
* Channel structure (max 5 segments, seg 1 = namespace):
|
|
58
|
+
* /{namespace}/{tenantCode}/{action}/{sanitizedId}
|
|
59
|
+
*
|
|
60
|
+
* Client subscription options (wildcard /* catches all sub-channels):
|
|
61
|
+
* /{namespace}/{tenantCode}/* — all events for tenant
|
|
62
|
+
* /{namespace}/{tenantCode}/{action}/* — filtered by action
|
|
63
|
+
* /{namespace}/{tenantCode}/{action}/{id} — specific command
|
|
64
|
+
*
|
|
65
|
+
* Requires: Lambda execution role must have appsync:EventPublish permission.
|
|
66
|
+
*/
|
|
67
|
+
async sendMessage(notification) {
|
|
68
|
+
if (!this.url || !this.signer) {
|
|
69
|
+
this.logger.warn('APPSYNC_EVENTS_ENDPOINT not set, skipping');
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
const channel = this.resolveChannel(notification);
|
|
73
|
+
this.logger.debug(`sendMessage:: channel=${channel}`);
|
|
74
|
+
await this.postToChannel(channel, notification);
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Resolves the most specific channel path for a notification.
|
|
78
|
+
* Non-alphanumeric characters (e.g. #, @) are sanitized to dashes
|
|
79
|
+
* since AppSync Events channel segments only allow [a-zA-Z0-9-].
|
|
80
|
+
*/
|
|
81
|
+
resolveChannel(notification) {
|
|
82
|
+
const namespace = this.sanitizeSegment(this.namespace);
|
|
83
|
+
const tenantCode = this.sanitizeSegment(notification.tenantCode);
|
|
84
|
+
const action = this.sanitizeSegment(notification.action);
|
|
85
|
+
const id = this.sanitizeSegment(notification.id);
|
|
86
|
+
return `/${namespace}/${tenantCode}/${action}/${id}`;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Formats a string to comply with AppSync Events API channel segment rules:
|
|
90
|
+
* 1. Only alphanumeric characters and dashes.
|
|
91
|
+
* 2. Cannot start or end with a dash.
|
|
92
|
+
* 3. Maximum length of 50 characters.
|
|
93
|
+
*/
|
|
94
|
+
sanitizeSegment(segment) {
|
|
95
|
+
if (!segment)
|
|
96
|
+
return 'none';
|
|
97
|
+
// Replace any non-alphanumeric character (like _, %, =) with a dash
|
|
98
|
+
let s = segment.replace(/[^a-zA-Z0-9]/g, '-');
|
|
99
|
+
// Truncate to AWS's strict 50 character limit
|
|
100
|
+
s = s.substring(0, 50);
|
|
101
|
+
// Strip out any dashes from the very beginning or end
|
|
102
|
+
s = s.replace(/^-+|-+$/g, '');
|
|
103
|
+
// Fallback if the string became empty after trimming
|
|
104
|
+
return s || 'none';
|
|
105
|
+
}
|
|
106
|
+
async postToChannel(channel, notification) {
|
|
107
|
+
const signedReq = await this.signRequest(channel, notification);
|
|
108
|
+
const res = await (0, node_fetch_1.default)(this.url.toString(), {
|
|
109
|
+
method: signedReq.method,
|
|
110
|
+
headers: signedReq.headers,
|
|
111
|
+
body: signedReq.body,
|
|
112
|
+
});
|
|
113
|
+
if (!res.ok) {
|
|
114
|
+
const text = await res.text();
|
|
115
|
+
throw new Error(`AppSync Events publish failed [${res.status}] on channel ${channel}: ${text}`);
|
|
116
|
+
}
|
|
117
|
+
this.logger.debug(`sendMessage:: published successfully to ${channel}`);
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Builds and signs an HttpRequest for the given channel and notification.
|
|
121
|
+
* Separating signing from the fetch call makes each step independently testable.
|
|
122
|
+
*/
|
|
123
|
+
async signRequest(channel, notification) {
|
|
124
|
+
const body = JSON.stringify({
|
|
125
|
+
id: (0, node_crypto_1.randomUUID)(),
|
|
126
|
+
channel,
|
|
127
|
+
events: [JSON.stringify(notification)],
|
|
128
|
+
});
|
|
129
|
+
const httpRequest = new protocol_http_1.HttpRequest({
|
|
130
|
+
method: 'POST',
|
|
131
|
+
headers: {
|
|
132
|
+
...DEFAULT_HEADERS,
|
|
133
|
+
host: this.url.hostname,
|
|
134
|
+
},
|
|
135
|
+
body,
|
|
136
|
+
hostname: this.url.hostname,
|
|
137
|
+
path: this.url.pathname,
|
|
138
|
+
});
|
|
139
|
+
return this.signer.sign(httpRequest);
|
|
140
|
+
}
|
|
141
|
+
};
|
|
142
|
+
exports.AppSyncEventsService = AppSyncEventsService;
|
|
143
|
+
exports.AppSyncEventsService = AppSyncEventsService = AppSyncEventsService_1 = __decorate([
|
|
144
|
+
(0, decorators_1.NotificationTransport)(enums_1.NotificationTransports.APPSYNC_EVENT),
|
|
145
|
+
__metadata("design:paramtypes", [config_1.ConfigService])
|
|
146
|
+
], AppSyncEventsService);
|
|
147
|
+
//# sourceMappingURL=appsync-events.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"appsync-events.service.js","sourceRoot":"","sources":["../../src/notifications/appsync-events.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,6CAAwC;AAExC,qDAA8C;AAC9C,gFAAmE;AACnE,2CAAuC;AACvC,2CAA8C;AAC9C,yDAAmD;AACnD,uDAAkD;AAClD,4DAA8B;AAE9B,8CAAqD;AAErD,mCAAgD;AAGhD,+DAA+D;AAC/D,MAAM,eAAe,GAAG;IACtB,MAAM,EAAE,mCAAmC;IAC3C,kBAAkB,EAAE,SAAS;IAC7B,cAAc,EAAE,iCAAiC;CAClD,CAAA;AAGM,IAAM,oBAAoB,4BAA1B,MAAM,oBAAoB;IAO/B,YAA6B,MAAqB;QAArB,WAAM,GAAN,MAAM,CAAe;QANjC,WAAM,GAAG,IAAI,eAAM,CAAC,sBAAoB,CAAC,IAAI,CAAC,CAAA;QAO7D,MAAM,QAAQ,GAAG,MAAM,CAAC,GAAG,CAAS,yBAAyB,CAAC,CAAA;QAC9D,IAAI,CAAC,SAAS,GAAG,MAAM,CAAC,GAAG,CAAS,0BAA0B,CAAC,IAAI,SAAS,CAAA;QAE5E,IAAI,QAAQ,EAAE,CAAC;YACb,IAAI,CAAC,GAAG,GAAG,IAAI,GAA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AC,WAAW,CACvB,OAAe,EACf,YAA2B;QAE3B,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC;YAC1B,EAAE,EAAE,IAAA,wBAAU,GAAE;YAChB,OAAO;YACP,MAAM,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,YAAY,CAAC,CAAC;SACvC,CAAC,CAAA;QAEF,MAAM,WAAW,GAAG,IAAI,2BAAW,CAAC;YAClC,MAAM,EAAE,MAAM;YACd,OAAO,EAAE;gBACP,GAAG,eAAe;gBAClB,IAAI,EAAE,IAAI,CAAC,GAAI,CAAC,QAAQ;aACzB;YACD,IAAI;YACJ,QAAQ,EAAE,IAAI,CAAC,GAAI,CAAC,QAAQ;YAC5B,IAAI,EAAE,IAAI,CAAC,GAAI,CAAC,QAAQ;SACzB,CAAC,CAAA;QAEF,OAAO,IAAI,CAAC,MAAO,CAAC,IAAI,CAAC,WAAW,CAAyB,CAAA;IAC/D,CAAC;CACF,CAAA;AA5IY,oDAAoB;+BAApB,oBAAoB;IADhC,IAAA,kCAAqB,EAAC,8BAAsB,CAAC,aAAa,CAAC;qCAQrB,sBAAa;GAPvC,oBAAoB,CA4IhC"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { ConfigService } from '@nestjs/config';
|
|
2
2
|
import { INotification } from '../interfaces';
|
|
3
|
-
|
|
3
|
+
import { INotificationTransport } from './interfaces';
|
|
4
|
+
export declare class AppSyncService implements INotificationTransport {
|
|
4
5
|
private readonly config;
|
|
5
6
|
private readonly logger;
|
|
6
7
|
private readonly endpoint;
|
|
@@ -9,5 +10,5 @@ export declare class AppSyncService {
|
|
|
9
10
|
private readonly region;
|
|
10
11
|
private readonly signer;
|
|
11
12
|
constructor(config: ConfigService);
|
|
12
|
-
sendMessage(
|
|
13
|
+
sendMessage(notification: INotification): Promise<void>;
|
|
13
14
|
}
|
|
@@ -20,6 +20,8 @@ const signature_v4_1 = require("@aws-sdk/signature-v4");
|
|
|
20
20
|
const common_1 = require("@nestjs/common");
|
|
21
21
|
const config_1 = require("@nestjs/config");
|
|
22
22
|
const node_fetch_1 = __importDefault(require("node-fetch"));
|
|
23
|
+
const decorators_1 = require("../decorators");
|
|
24
|
+
const enums_1 = require("./enums");
|
|
23
25
|
const query = /* GraphQL */ `
|
|
24
26
|
mutation SEND_MESSAGE($message: AWSJSON!) {
|
|
25
27
|
sendMessage(message: $message) {
|
|
@@ -37,18 +39,24 @@ let AppSyncService = AppSyncService_1 = class AppSyncService {
|
|
|
37
39
|
constructor(config) {
|
|
38
40
|
this.config = config;
|
|
39
41
|
this.logger = new common_1.Logger(AppSyncService_1.name);
|
|
40
|
-
this.endpoint = config.get('APPSYNC_ENDPOINT');
|
|
41
|
-
this.apiKey = config.get('APPSYNC_API_KEY');
|
|
42
|
+
this.endpoint = config.get('APPSYNC_ENDPOINT') ?? '';
|
|
43
|
+
this.apiKey = config.get('APPSYNC_API_KEY') ?? '';
|
|
42
44
|
this.region = 'ap-northeast-1';
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
45
|
+
if (this.endpoint) {
|
|
46
|
+
this.hostname = new URL(this.endpoint).hostname;
|
|
47
|
+
this.signer = new signature_v4_1.SignatureV4({
|
|
48
|
+
credentials: (0, credential_provider_node_1.defaultProvider)(),
|
|
49
|
+
region: this.region,
|
|
50
|
+
service: 'appsync',
|
|
51
|
+
sha256: sha256_js_1.Sha256,
|
|
52
|
+
});
|
|
53
|
+
}
|
|
50
54
|
}
|
|
51
|
-
async sendMessage(
|
|
55
|
+
async sendMessage(notification) {
|
|
56
|
+
if (!this.endpoint?.trim() || !this.hostname) {
|
|
57
|
+
this.logger.warn('APPSYNC_ENDPOINT is not set, skipping.');
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
52
60
|
const headers = {
|
|
53
61
|
'Content-Type': 'application/json',
|
|
54
62
|
host: this.hostname,
|
|
@@ -56,7 +64,7 @@ let AppSyncService = AppSyncService_1 = class AppSyncService {
|
|
|
56
64
|
const body = JSON.stringify({
|
|
57
65
|
query,
|
|
58
66
|
variables: {
|
|
59
|
-
message: JSON.stringify(
|
|
67
|
+
message: JSON.stringify(notification),
|
|
60
68
|
},
|
|
61
69
|
});
|
|
62
70
|
const method = 'POST';
|
|
@@ -96,7 +104,7 @@ let AppSyncService = AppSyncService_1 = class AppSyncService {
|
|
|
96
104
|
};
|
|
97
105
|
exports.AppSyncService = AppSyncService;
|
|
98
106
|
exports.AppSyncService = AppSyncService = AppSyncService_1 = __decorate([
|
|
99
|
-
(0,
|
|
107
|
+
(0, decorators_1.NotificationTransport)(enums_1.NotificationTransports.APPSYNC_GRAPHQL),
|
|
100
108
|
__metadata("design:paramtypes", [config_1.ConfigService])
|
|
101
109
|
], AppSyncService);
|
|
102
110
|
//# sourceMappingURL=appsync.service.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"appsync.service.js","sourceRoot":"","sources":["../../src/notifications/appsync.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,qDAA8C;AAC9C,gFAAmE;AACnE,wDAAmD;AACnD,
|
|
1
|
+
{"version":3,"file":"appsync.service.js","sourceRoot":"","sources":["../../src/notifications/appsync.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,qDAA8C;AAC9C,gFAAmE;AACnE,wDAAmD;AACnD,2CAAuC;AACvC,2CAA8C;AAC9C,4DAA4C;AAE5C,8CAAqD;AAErD,mCAAgD;AAEhD,MAAM,KAAK,GAAG,aAAa,CAAC;;;;;;;;;;;;CAY3B,CAAA;AAGM,IAAM,cAAc,sBAApB,MAAM,cAAc;IASzB,YAA6B,MAAqB;QAArB,WAAM,GAAN,MAAM,CAAe;QARjC,WAAM,GAAG,IAAI,eAAM,CAAC,gBAAc,CAAC,IAAI,CAAC,CAAA;QASvD,IAAI,CAAC,QAAQ,GAAG,MAAM,CAAC,GAAG,CAAS,kBAAkB,CAAC,IAAI,EAAE,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P,IAAI;aACL,CAAC,CAAA;QACJ,CAAC;aAAM,CAAC;YACN,MAAM,OAAO,GAAG;gBACd,MAAM;gBACN,OAAO;gBACP,QAAQ,EAAE,QAAQ;gBAClB,QAAQ,EAAE,IAAI,CAAC,QAAQ;gBACvB,IAAI,EAAE,UAAU;gBAChB,IAAI;gBACJ,MAAM,EAAE,IAAI,CAAC,MAAM;gBACnB,OAAO,EAAE,SAAS;aACnB,CAAA;YACD,MAAM,aAAa,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE;gBACpD,WAAW,EAAE,IAAI,IAAI,EAAE;aACxB,CAAC,CAAA;YACF,GAAG,GAAG,MAAM,IAAA,oBAAK,EAAC,IAAI,CAAC,QAAQ,EAAE;gBAC/B,MAAM,EAAE,aAAa,CAAC,MAAM;gBAC5B,OAAO,EAAE,aAAa,CAAC,OAAO;gBAC9B,IAAI,EAAE,aAAa,CAAC,IAAI;aACzB,CAAC,CAAA;QACJ,CAAC;QACD,MAAM,IAAI,GAAG,MAAM,GAAG,CAAC,IAAI,EAAE,CAAA;QAC7B,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,sCAAsC,EAAE,IAAI,CAAC,CAAA;QAE/D,OAAO,IAAI,CAAA;IACb,CAAC;CACF,CAAA;AA3EY,wCAAc;yBAAd,cAAc;IAD1B,IAAA,kCAAqB,EAAC,8BAAsB,CAAC,eAAe,CAAC;qCAUvB,sBAAa;GATvC,cAAc,CA2E1B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './notification-transport.enum';
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./notification-transport.enum"), exports);
|
|
18
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/notifications/enums/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,gEAA6C"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NotificationTransports = void 0;
|
|
4
|
+
var NotificationTransports;
|
|
5
|
+
(function (NotificationTransports) {
|
|
6
|
+
NotificationTransports["APPSYNC_GRAPHQL"] = "appsync-graphql";
|
|
7
|
+
NotificationTransports["APPSYNC_EVENT"] = "appsync-event";
|
|
8
|
+
})(NotificationTransports || (exports.NotificationTransports = NotificationTransports = {}));
|
|
9
|
+
//# sourceMappingURL=notification-transport.enum.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"notification-transport.enum.js","sourceRoot":"","sources":["../../../src/notifications/enums/notification-transport.enum.ts"],"names":[],"mappings":";;;AAAA,IAAY,sBAGX;AAHD,WAAY,sBAAsB;IAChC,6DAAmC,CAAA;IACnC,yDAA+B,CAAA;AACjC,CAAC,EAHW,sBAAsB,sCAAtB,sBAAsB,QAGjC"}
|
|
@@ -1,9 +1,17 @@
|
|
|
1
|
+
import { OnModuleInit } from '@nestjs/common';
|
|
2
|
+
import { ConfigService } from '@nestjs/config';
|
|
3
|
+
import { ModuleRef } from '@nestjs/core';
|
|
1
4
|
import { IEventHandler } from '../../interfaces';
|
|
2
|
-
import {
|
|
5
|
+
import { ExplorerService } from '../../services';
|
|
3
6
|
import { NotificationEvent } from './notification.event';
|
|
4
|
-
export declare class NotificationEventHandler implements IEventHandler<NotificationEvent
|
|
5
|
-
private readonly
|
|
7
|
+
export declare class NotificationEventHandler implements IEventHandler<NotificationEvent>, OnModuleInit {
|
|
8
|
+
private readonly moduleRef;
|
|
9
|
+
private readonly explorerService;
|
|
10
|
+
private readonly config;
|
|
6
11
|
private readonly logger;
|
|
7
|
-
|
|
8
|
-
|
|
12
|
+
private readonly transports;
|
|
13
|
+
private readonly activeTransportNames;
|
|
14
|
+
constructor(moduleRef: ModuleRef, explorerService: ExplorerService, config: ConfigService);
|
|
15
|
+
onModuleInit(): void;
|
|
16
|
+
execute(event: NotificationEvent): Promise<void>;
|
|
9
17
|
}
|
|
@@ -12,24 +12,48 @@ var NotificationEventHandler_1;
|
|
|
12
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
13
|
exports.NotificationEventHandler = void 0;
|
|
14
14
|
const common_1 = require("@nestjs/common");
|
|
15
|
+
const config_1 = require("@nestjs/config");
|
|
16
|
+
const core_1 = require("@nestjs/core");
|
|
15
17
|
const decorators_1 = require("../../decorators");
|
|
16
|
-
const
|
|
18
|
+
const notification_env_validation_1 = require("../../notification-env.validation");
|
|
19
|
+
const services_1 = require("../../services");
|
|
17
20
|
const notification_event_1 = require("./notification.event");
|
|
18
21
|
let NotificationEventHandler = NotificationEventHandler_1 = class NotificationEventHandler {
|
|
19
|
-
constructor(
|
|
20
|
-
this.
|
|
22
|
+
constructor(moduleRef, explorerService, config) {
|
|
23
|
+
this.moduleRef = moduleRef;
|
|
24
|
+
this.explorerService = explorerService;
|
|
25
|
+
this.config = config;
|
|
21
26
|
this.logger = new common_1.Logger(NotificationEventHandler_1.name);
|
|
27
|
+
this.transports = new Map();
|
|
28
|
+
this.activeTransportNames = (0, notification_env_validation_1.parseNotificationTransports)(this.config.get('NOTIFICATION_TRANSPORTS'));
|
|
29
|
+
}
|
|
30
|
+
onModuleInit() {
|
|
31
|
+
this.logger.debug('Finding notification transports from decorators');
|
|
32
|
+
const { notificationTransports } = this.explorerService.exploreNotificationTransports();
|
|
33
|
+
for (const TransportClass of notificationTransports) {
|
|
34
|
+
const name = Reflect.getMetadata(decorators_1.NOTIFICATION_TRANSPORT_METADATA, TransportClass);
|
|
35
|
+
if (this.activeTransportNames.includes(name)) {
|
|
36
|
+
const instance = this.moduleRef.get(TransportClass, { strict: false });
|
|
37
|
+
// Give the instance its decorator name automatically if it isn't set
|
|
38
|
+
if (!instance.name) {
|
|
39
|
+
instance.name = name;
|
|
40
|
+
}
|
|
41
|
+
this.transports.set(name, instance);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
this.logger.debug(`Initialized active transports: [${[...this.transports.keys()].join(', ')}]`);
|
|
22
45
|
}
|
|
23
46
|
async execute(event) {
|
|
24
|
-
this.logger.debug('notification event executing:: ', event);
|
|
25
|
-
//send to appsync
|
|
26
47
|
const body = JSON.parse(event.body);
|
|
27
|
-
|
|
48
|
+
this.logger.debug(`execute:: broadcasting via ${this.transports.size} transport(s)`);
|
|
49
|
+
await Promise.all([...this.transports.values()].map((t) => t.sendMessage(body)));
|
|
28
50
|
}
|
|
29
51
|
};
|
|
30
52
|
exports.NotificationEventHandler = NotificationEventHandler;
|
|
31
53
|
exports.NotificationEventHandler = NotificationEventHandler = NotificationEventHandler_1 = __decorate([
|
|
32
54
|
(0, decorators_1.EventHandler)(notification_event_1.NotificationEvent),
|
|
33
|
-
__metadata("design:paramtypes", [
|
|
55
|
+
__metadata("design:paramtypes", [core_1.ModuleRef,
|
|
56
|
+
services_1.ExplorerService,
|
|
57
|
+
config_1.ConfigService])
|
|
34
58
|
], NotificationEventHandler);
|
|
35
59
|
//# sourceMappingURL=notification.event.handler.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"notification.event.handler.js","sourceRoot":"","sources":["../../../src/notifications/event/notification.event.handler.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"notification.event.handler.js","sourceRoot":"","sources":["../../../src/notifications/event/notification.event.handler.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,2CAAqD;AACrD,2CAA8C;AAC9C,uCAAwC;AAExC,iDAAgF;AAEhF,mFAA+E;AAC/E,6CAAgD;AAEhD,6DAAwD;AAGjD,IAAM,wBAAwB,gCAA9B,MAAM,wBAAwB;IAOnC,YACmB,SAAoB,EACpB,eAAgC,EAChC,MAAqB;QAFrB,cAAS,GAAT,SAAS,CAAW;QACpB,oBAAe,GAAf,eAAe,CAAiB;QAChC,WAAM,GAAN,MAAM,CAAe;QAPvB,WAAM,GAAG,IAAI,eAAM,CAAC,0BAAwB,CAAC,IAAI,CAAC,CAAA;QAClD,eAAU,GAAG,IAAI,GAAG,EAAkC,CAAA;QAQrE,IAAI,CAAC,oBAAoB,GAAG,IAAA,yDAA2B,EACrD,IAAI,CAAC,MAAM,CAAC,GAAG,CAAS,yBAAyB,CAAC,CACnD,CAAA;IACH,CAAC;IAED,YAAY;QACV,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,iDAAiD,CAAC,CAAA;QAEpE,MAAM,EAAE,sBAAsB,EAAE,GAC9B,IAAI,CAAC,eAAe,CAAC,6BAA6B,EAAE,CAAA;QAEtD,KAAK,MAAM,cAAc,IAAI,sBAAsB,EAAE,CAAC;YACpD,MAAM,IAAI,GAAG,OAAO,CAAC,WAAW,CAC9B,4CAA+B,EAC/B,cAAc,CACf,CAAA;YAED,IAAI,IAAI,CAAC,oBAAoB,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;gBAC7C,MAAM,QAAQ,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,CACjC,cAAc,EACd,EAAE,MAAM,EAAE,KAAK,EAAE,CAClB,CAAA;gBAED,qEAAqE;gBACrE,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC;oBACnB,QAAQ,CAAC,IAAI,GAAG,IAAI,CAAA;gBACtB,CAAC;gBAED,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAA;YACrC,CAAC;QACH,CAAC;QAED,IAAI,CAAC,MAAM,CAAC,KAAK,CACf,mCAAmC,CAAC,GAAG,IAAI,CAAC,UAAU,CAAC,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAC7E,CAAA;IACH,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,KAAwB;QACpC,MAAM,IAAI,GAAkB,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;QAElD,IAAI,CAAC,MAAM,CAAC,KAAK,CACf,8BAA8B,IAAI,CAAC,UAAU,CAAC,IAAI,eAAe,CAClE,CAAA;QAED,MAAM,OAAO,CAAC,GAAG,CACf,CAAC,GAAG,IAAI,CAAC,UAAU,CAAC,MAAM,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,CAC9D,CAAA;IACH,CAAC;CACF,CAAA;AA5DY,4DAAwB;mCAAxB,wBAAwB;IADpC,IAAA,yBAAY,EAAC,sCAAiB,CAAC;qCASA,gBAAS;QACH,0BAAe;QACxB,sBAAa;GAV7B,wBAAwB,CA4DpC"}
|
|
@@ -15,7 +15,10 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./appsync.service"), exports);
|
|
18
|
+
__exportStar(require("./appsync-events.service"), exports);
|
|
18
19
|
__exportStar(require("./email.service"), exports);
|
|
20
|
+
__exportStar(require("./enums"), exports);
|
|
19
21
|
__exportStar(require("./event"), exports);
|
|
22
|
+
__exportStar(require("./interfaces"), exports);
|
|
20
23
|
__exportStar(require("./notification.module"), exports);
|
|
21
24
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/notifications/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,oDAAiC;AACjC,kDAA+B;AAC/B,0CAAuB;AACvB,wDAAqC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/notifications/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,oDAAiC;AACjC,2DAAwC;AACxC,kDAA+B;AAC/B,0CAAuB;AACvB,0CAAuB;AACvB,+CAA4B;AAC5B,wDAAqC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './notification-transport.interface';
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./notification-transport.interface"), exports);
|
|
18
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/notifications/interfaces/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,qEAAkD"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { INotification } from '../../interfaces';
|
|
2
|
+
export declare const NOTIFICATION_TRANSPORT = "NOTIFICATION_TRANSPORT";
|
|
3
|
+
export interface INotificationTransport {
|
|
4
|
+
name?: string;
|
|
5
|
+
sendMessage(notification: INotification): Promise<void>;
|
|
6
|
+
}
|
|
7
|
+
export type NotificationTransportMap = Map<string, INotificationTransport>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"notification-transport.interface.js","sourceRoot":"","sources":["../../../src/notifications/interfaces/notification-transport.interface.ts"],"names":[],"mappings":";;;AAEa,QAAA,sBAAsB,GAAG,wBAAwB,CAAA"}
|
|
@@ -8,7 +8,10 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.NotificationModule = void 0;
|
|
10
10
|
const common_1 = require("@nestjs/common");
|
|
11
|
+
const config_1 = require("@nestjs/config");
|
|
12
|
+
const services_1 = require("../services");
|
|
11
13
|
const appsync_service_1 = require("./appsync.service");
|
|
14
|
+
const appsync_events_service_1 = require("./appsync-events.service");
|
|
12
15
|
const email_service_1 = require("./email.service");
|
|
13
16
|
const notification_event_handler_1 = require("./event/notification.event.handler");
|
|
14
17
|
let NotificationModule = class NotificationModule {
|
|
@@ -17,8 +20,15 @@ exports.NotificationModule = NotificationModule;
|
|
|
17
20
|
exports.NotificationModule = NotificationModule = __decorate([
|
|
18
21
|
(0, common_1.Global)(),
|
|
19
22
|
(0, common_1.Module)({
|
|
20
|
-
|
|
21
|
-
|
|
23
|
+
imports: [config_1.ConfigModule],
|
|
24
|
+
providers: [
|
|
25
|
+
services_1.ExplorerService,
|
|
26
|
+
email_service_1.EmailService,
|
|
27
|
+
notification_event_handler_1.NotificationEventHandler,
|
|
28
|
+
appsync_service_1.AppSyncService,
|
|
29
|
+
appsync_events_service_1.AppSyncEventsService,
|
|
30
|
+
],
|
|
31
|
+
exports: [email_service_1.EmailService, appsync_service_1.AppSyncService, appsync_events_service_1.AppSyncEventsService],
|
|
22
32
|
})
|
|
23
33
|
], NotificationModule);
|
|
24
34
|
//# sourceMappingURL=notification.module.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"notification.module.js","sourceRoot":"","sources":["../../src/notifications/notification.module.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAA+C;
|
|
1
|
+
{"version":3,"file":"notification.module.js","sourceRoot":"","sources":["../../src/notifications/notification.module.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAA+C;AAC/C,2CAA6C;AAE7C,0CAA6C;AAC7C,uDAAkD;AAClD,qEAA+D;AAC/D,mDAA8C;AAC9C,mFAA6E;AActE,IAAM,kBAAkB,GAAxB,MAAM,kBAAkB;CAAG,CAAA;AAArB,gDAAkB;6BAAlB,kBAAkB;IAZ9B,IAAA,eAAM,GAAE;IACR,IAAA,eAAM,EAAC;QACN,OAAO,EAAE,CAAC,qBAAY,CAAC;QACvB,SAAS,EAAE;YACT,0BAAe;YACf,4BAAY;YACZ,qDAAwB;YACxB,gCAAc;YACd,6CAAoB;SACrB;QACD,OAAO,EAAE,CAAC,4BAAY,EAAE,gCAAc,EAAE,6CAAoB,CAAC;KAC9D,CAAC;GACW,kBAAkB,CAAG"}
|
|
@@ -2,6 +2,7 @@ import { Type } from '@nestjs/common';
|
|
|
2
2
|
import { InstanceWrapper } from '@nestjs/core/injector/instance-wrapper';
|
|
3
3
|
import { Module } from '@nestjs/core/injector/module';
|
|
4
4
|
import { ModulesContainer } from '@nestjs/core/injector/modules-container';
|
|
5
|
+
import { IGroupRoleResolver } from '../auth/group-role-resolver.interface';
|
|
5
6
|
import { IDataSyncHandler, IEventFactory, IEventHandler } from '../interfaces';
|
|
6
7
|
export declare class ExplorerService {
|
|
7
8
|
private readonly modulesContainer;
|
|
@@ -14,6 +15,10 @@ export declare class ExplorerService {
|
|
|
14
15
|
exploreDataSyncHandlers(commandTableName: string): {
|
|
15
16
|
dataSyncHandlers: Type<IDataSyncHandler<any, any>>[];
|
|
16
17
|
};
|
|
18
|
+
exploreNotificationTransports(): {
|
|
19
|
+
notificationTransports: Type<any>[];
|
|
20
|
+
};
|
|
21
|
+
exploreGroupRoleResolvers(): Type<IGroupRoleResolver>[];
|
|
17
22
|
flatMap<T>(modules: Module[], callback: (instance: InstanceWrapper) => Type<any> | undefined): Type<T>[];
|
|
18
23
|
filterProvider(wrapper: InstanceWrapper, metadataKey: string, metadataValue?: string): Type<any> | undefined;
|
|
19
24
|
extractMetadata(instance: Record<string, any>, metadataKey: string, metadataValue?: string): Type<any>;
|
|
@@ -27,9 +27,20 @@ let ExplorerService = ExplorerService_1 = class ExplorerService {
|
|
|
27
27
|
}
|
|
28
28
|
exploreDataSyncHandlers(commandTableName) {
|
|
29
29
|
const modules = [...this.modulesContainer.values()];
|
|
30
|
-
const dataSyncHandlers =
|
|
30
|
+
const dataSyncHandlers = [
|
|
31
|
+
...new Set(this.flatMap(modules, (instance) => this.filterProvider(instance, decorators_1.DATA_SYNC_HANDLER_METADATA, commandTableName))),
|
|
32
|
+
];
|
|
31
33
|
return { dataSyncHandlers };
|
|
32
34
|
}
|
|
35
|
+
exploreNotificationTransports() {
|
|
36
|
+
const modules = [...this.modulesContainer.values()];
|
|
37
|
+
const notificationTransports = this.flatMap(modules, (instance) => this.filterProvider(instance, decorators_1.NOTIFICATION_TRANSPORT_METADATA));
|
|
38
|
+
return { notificationTransports };
|
|
39
|
+
}
|
|
40
|
+
exploreGroupRoleResolvers() {
|
|
41
|
+
const modules = [...this.modulesContainer.values()];
|
|
42
|
+
return this.flatMap(modules, (instance) => this.filterProvider(instance, decorators_1.GROUP_ROLE_RESOLVER_METADATA));
|
|
43
|
+
}
|
|
33
44
|
flatMap(modules, callback) {
|
|
34
45
|
const items = modules
|
|
35
46
|
.map((module) => [...module.providers.values()].map(callback))
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"explorer.service.js","sourceRoot":"","sources":["../../src/services/explorer.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,2CAAyD;AAGzD,+EAA0E;
|
|
1
|
+
{"version":3,"file":"explorer.service.js","sourceRoot":"","sources":["../../src/services/explorer.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,2CAAyD;AAGzD,+EAA0E;AAG1E,8CAMsB;AAIf,IAAM,eAAe,uBAArB,MAAM,eAAe;IAG1B,YAA6B,gBAAkC;QAAlC,qBAAgB,GAAhB,gBAAgB,CAAkB;QAF9C,WAAM,GAAG,IAAI,eAAM,CAAC,iBAAe,CAAC,IAAI,CAAC,CAAA;IAEQ,CAAC;IAEnE,OAAO;QACL,MAAM,OAAO,GAAG,CAAC,GAAG,IAAI,CAAC,gBAAgB,CAAC,MAAM,EAAE,CAAC,CAAA;QAEnD,MAAM,MAAM,GAAG,IAAI,CAAC,OAAO,CAAgB,OAAO,EAAE,CAAC,QAAQ,EAAE,EAAE,CAC/D,IAAI,CAAC,cAAc,CAAC,QAAQ,EAAE,mCAAsB,CAAC,CACtD,CAAA;QACD,MAAM,aAAa,GAAG,IAAI,CAAC,OAAO,CAAgB,OAAO,EAAE,CAAC,QAAQ,EAAE,EAAE,CACtE,IAAI,CAAC,cAAc,CAAC,QAAQ,EAAE,mCAAsB,CAAC,CACtD,CAAA;QACD,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,CAAA;IAClC,CAAC;IAED,uBAAuB,CAAC,gBAAwB;QAC9C,MAAM,OAAO,GAAG,CAAC,GAAG,IAAI,CAAC,gBAAgB,CAAC,MAAM,EAAE,CAAC,CAAA;QACnD,MAAM,gBAAgB,GAAG;YACvB,GAAG,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cAAc,CACZ,OAAwB,EACxB,WAAmB,EACnB,aAAsB;QAEtB,MAAM,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAA;QAC5B,IAAI,CAAC,QAAQ,EAAE,CAAC;YACd,OAAO,SAAS,CAAA;QAClB,CAAC;QACD,OAAO,IAAI,CAAC,eAAe,CAAC,QAAQ,EAAE,WAAW,EAAE,aAAa,CAAC,CAAA;IACnE,CAAC;IAED,eAAe,CACb,QAA6B,EAC7B,WAAmB,EACnB,aAAsB;QAEtB,IAAI,CAAC,QAAQ,CAAC,WAAW,EAAE,CAAC;YAC1B,OAAM;QACR,CAAC;QACD,MAAM,QAAQ,GAAG,OAAO,CAAC,WAAW,CAAC,WAAW,EAAE,QAAQ,CAAC,WAAW,CAAC,CAAA;QACvE,IAAI,CAAC,QAAQ,IAAI,CAAC,aAAa,IAAI,QAAQ,KAAK,aAAa,CAAC,EAAE,CAAC;YAC/D,OAAO,SAAS,CAAA;QAClB,CAAC;QACD,OAAO,QAAQ,CAAC,WAAwB,CAAA;IAC1C,CAAC;CACF,CAAA;AApFY,0CAAe;0BAAf,eAAe;IAD3B,IAAA,mBAAU,GAAE;qCAIoC,oCAAgB;GAHpD,eAAe,CAoF3B"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
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;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.MockGroupRoleResolver = void 0;
|
|
10
|
+
const decorators_1 = require("../../decorators");
|
|
11
|
+
let MockGroupRoleResolver = class MockGroupRoleResolver {
|
|
12
|
+
async resolveRoles() {
|
|
13
|
+
return [];
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
exports.MockGroupRoleResolver = MockGroupRoleResolver;
|
|
17
|
+
exports.MockGroupRoleResolver = MockGroupRoleResolver = __decorate([
|
|
18
|
+
(0, decorators_1.GroupRoleResolver)()
|
|
19
|
+
], MockGroupRoleResolver);
|
|
20
|
+
//# sourceMappingURL=group-role-resolver.mock.js.map
|