@node-in-layers/notifications 0.0.0-stage → 1.0.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/README.md +605 -2
- package/backend/features.d.ts +5 -0
- package/backend/features.js +350 -0
- package/backend/features.js.map +1 -0
- package/backend/index.d.ts +6 -0
- package/backend/index.js +7 -0
- package/backend/index.js.map +1 -0
- package/backend/internal-libs.d.ts +63 -0
- package/backend/internal-libs.js +100 -0
- package/backend/internal-libs.js.map +1 -0
- package/backend/libs.d.ts +23 -0
- package/backend/libs.js +48 -0
- package/backend/libs.js.map +1 -0
- package/backend/services.d.ts +4 -0
- package/backend/services.js +57 -0
- package/backend/services.js.map +1 -0
- package/backend/types.d.ts +36 -0
- package/backend/types.js +2 -0
- package/backend/types.js.map +1 -0
- package/core/features.d.ts +4 -0
- package/core/features.js +6 -0
- package/core/features.js.map +1 -0
- package/core/index.d.ts +7 -0
- package/core/index.js +8 -0
- package/core/index.js.map +1 -0
- package/core/internal-libs.d.ts +5 -0
- package/core/internal-libs.js +34 -0
- package/core/internal-libs.js.map +1 -0
- package/core/libs.d.ts +28 -0
- package/core/libs.js +57 -0
- package/core/libs.js.map +1 -0
- package/core/models/NotificationConfigs.d.ts +13 -0
- package/core/models/NotificationConfigs.js +44 -0
- package/core/models/NotificationConfigs.js.map +1 -0
- package/core/models/NotificationTemplates.d.ts +11 -0
- package/core/models/NotificationTemplates.js +40 -0
- package/core/models/NotificationTemplates.js.map +1 -0
- package/core/models/Notifications.d.ts +49 -0
- package/core/models/Notifications.js +94 -0
- package/core/models/Notifications.js.map +1 -0
- package/core/models/index.d.ts +3 -0
- package/core/models/index.js +4 -0
- package/core/models/index.js.map +1 -0
- package/core/services.d.ts +4 -0
- package/core/services.js +6 -0
- package/core/services.js.map +1 -0
- package/core/types.d.ts +323 -0
- package/core/types.js +220 -0
- package/core/types.js.map +1 -0
- package/index.d.ts +4 -0
- package/index.js +5 -0
- package/index.js.map +1 -0
- package/package.json +99 -4
- package/types.d.ts +55 -0
- package/types.js +6 -0
- package/types.js.map +1 -0
|
@@ -0,0 +1,350 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { randomUUID } from 'node:crypto';
|
|
11
|
+
import { annotatedFunction, createErrorObject, isErrorObject, } from '@node-in-layers/core';
|
|
12
|
+
import { asyncMap } from 'modern-async';
|
|
13
|
+
import { queryBuilder, } from 'functional-models';
|
|
14
|
+
import { NotificationsNamespace, } from '../types.js';
|
|
15
|
+
import { NotificationChannel, NotificationSeverity, NotificationStatus, NotificationType, SendExecutionFailureNotificationSchema, SendNotificationSchema, SendSystemNotificationSchema, SendUserNotificationSchema, } from '../core/types.js';
|
|
16
|
+
import { parseNotifierTarget, renderNotificationTemplate, } from '../core/libs.js';
|
|
17
|
+
import { buildExecutionFailureTemplateData, buildSystemTemplateData, mergeNotificationConfig, } from './libs.js';
|
|
18
|
+
import { createDeliveryResults, createUserTargets, createUserTemplateData, getStaticTemplate, parseModelReference, resolveDeliveryStatus, resolveInvocations, } from './internal-libs.js';
|
|
19
|
+
const defaultDatabaseConfigKey = 'default';
|
|
20
|
+
export const create = (context) => {
|
|
21
|
+
const _getCoreCruds = () => { var _a; return (_a = context.services[NotificationsNamespace.Core]) === null || _a === void 0 ? void 0 : _a.cruds; };
|
|
22
|
+
const _getStaticConfig = () => { var _a; return (_a = context.config[NotificationsNamespace.Backend]) !== null && _a !== void 0 ? _a : {}; };
|
|
23
|
+
const _findDatabaseConfig = (staticConfig) => __awaiter(void 0, void 0, void 0, function* () {
|
|
24
|
+
var _a;
|
|
25
|
+
var _b;
|
|
26
|
+
const cruds = _getCoreCruds();
|
|
27
|
+
if (!staticConfig.useDatabaseConfig || !(cruds === null || cruds === void 0 ? void 0 : cruds.NotificationConfigs)) {
|
|
28
|
+
return undefined;
|
|
29
|
+
}
|
|
30
|
+
const result = yield cruds.NotificationConfigs.search(queryBuilder()
|
|
31
|
+
.property('key', (_b = staticConfig.databaseConfigKey) !== null && _b !== void 0 ? _b : defaultDatabaseConfigKey)
|
|
32
|
+
.compile());
|
|
33
|
+
return (_a = result.instances[0]) === null || _a === void 0 ? void 0 : _a.toObj();
|
|
34
|
+
});
|
|
35
|
+
const _getEffectiveConfig = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
36
|
+
const staticConfig = _getStaticConfig();
|
|
37
|
+
const databaseConfig = yield _findDatabaseConfig(staticConfig);
|
|
38
|
+
return mergeNotificationConfig({
|
|
39
|
+
staticConfig,
|
|
40
|
+
databaseConfig,
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
const _getDatabaseTemplate = (config, channel, type) => __awaiter(void 0, void 0, void 0, function* () {
|
|
44
|
+
var _a;
|
|
45
|
+
const cruds = _getCoreCruds();
|
|
46
|
+
if (!config.useDatabaseTemplates || !(cruds === null || cruds === void 0 ? void 0 : cruds.NotificationTemplates)) {
|
|
47
|
+
return {};
|
|
48
|
+
}
|
|
49
|
+
const result = yield cruds.NotificationTemplates.search(queryBuilder()
|
|
50
|
+
.property('channel', channel)
|
|
51
|
+
.and()
|
|
52
|
+
.property('type', type)
|
|
53
|
+
.compile());
|
|
54
|
+
const row = yield (_a = result.instances[0]) === null || _a === void 0 ? void 0 : _a.toObj();
|
|
55
|
+
return row
|
|
56
|
+
? {
|
|
57
|
+
template: row.body,
|
|
58
|
+
htmlTemplate: row.htmlBody,
|
|
59
|
+
}
|
|
60
|
+
: {};
|
|
61
|
+
});
|
|
62
|
+
const _resolveTemplates = (config, channel, type) => __awaiter(void 0, void 0, void 0, function* () {
|
|
63
|
+
const databaseTemplate = yield _getDatabaseTemplate(config, channel, type);
|
|
64
|
+
if (databaseTemplate.template || databaseTemplate.htmlTemplate) {
|
|
65
|
+
return databaseTemplate;
|
|
66
|
+
}
|
|
67
|
+
return getStaticTemplate({
|
|
68
|
+
config,
|
|
69
|
+
channel,
|
|
70
|
+
type,
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
const _persistNotification = (notification) => __awaiter(void 0, void 0, void 0, function* () {
|
|
74
|
+
const cruds = _getCoreCruds();
|
|
75
|
+
if (!_getStaticConfig().persistNotifications || !(cruds === null || cruds === void 0 ? void 0 : cruds.Notifications)) {
|
|
76
|
+
return notification;
|
|
77
|
+
}
|
|
78
|
+
const created = yield cruds.Notifications.create(notification);
|
|
79
|
+
return created.toObj();
|
|
80
|
+
});
|
|
81
|
+
const _updatePersistedNotification = (notification) => __awaiter(void 0, void 0, void 0, function* () {
|
|
82
|
+
const cruds = _getCoreCruds();
|
|
83
|
+
if (!_getStaticConfig().persistNotifications || !(cruds === null || cruds === void 0 ? void 0 : cruds.Notifications)) {
|
|
84
|
+
return notification;
|
|
85
|
+
}
|
|
86
|
+
const updated = yield cruds.Notifications.update(notification.id, notification);
|
|
87
|
+
return updated.toObj();
|
|
88
|
+
});
|
|
89
|
+
const _dispatchNotification = (notification, options, crossLayerProps) => __awaiter(void 0, void 0, void 0, function* () {
|
|
90
|
+
const config = yield _getEffectiveConfig();
|
|
91
|
+
const invocations = resolveInvocations({
|
|
92
|
+
config,
|
|
93
|
+
notification,
|
|
94
|
+
});
|
|
95
|
+
const results = yield asyncMap(invocations, (invocation) => __awaiter(void 0, void 0, void 0, function* () {
|
|
96
|
+
if (!invocation.notifier) {
|
|
97
|
+
if (invocation.channel === NotificationChannel.Email && config.email) {
|
|
98
|
+
const templates = yield _resolveTemplates(config, invocation.channel, notification.type);
|
|
99
|
+
const emailResult = yield _sendEmailChannelNotification({
|
|
100
|
+
channel: invocation.channel,
|
|
101
|
+
notification,
|
|
102
|
+
target: invocation.target,
|
|
103
|
+
template: templates.template,
|
|
104
|
+
htmlTemplate: templates.htmlTemplate,
|
|
105
|
+
options,
|
|
106
|
+
}, crossLayerProps);
|
|
107
|
+
if (isErrorObject(emailResult)) {
|
|
108
|
+
return {
|
|
109
|
+
channel: invocation.channel,
|
|
110
|
+
notifier: 'email',
|
|
111
|
+
success: false,
|
|
112
|
+
sentAt: new Date().toISOString(),
|
|
113
|
+
error: emailResult.error,
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
return emailResult;
|
|
117
|
+
}
|
|
118
|
+
return {
|
|
119
|
+
channel: invocation.channel,
|
|
120
|
+
notifier: '',
|
|
121
|
+
success: false,
|
|
122
|
+
sentAt: new Date().toISOString(),
|
|
123
|
+
error: {
|
|
124
|
+
code: 'NOTIFIER_NOT_CONFIGURED',
|
|
125
|
+
message: `No notifier is configured for channel ${invocation.channel}.`,
|
|
126
|
+
},
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
const target = parseNotifierTarget({ notifier: invocation.notifier });
|
|
130
|
+
const features = context.features.getFeatures(target.domain);
|
|
131
|
+
const notifier = features === null || features === void 0 ? void 0 : features[target.feature];
|
|
132
|
+
if (!notifier) {
|
|
133
|
+
return {
|
|
134
|
+
channel: invocation.channel,
|
|
135
|
+
notifier: invocation.notifier,
|
|
136
|
+
success: false,
|
|
137
|
+
sentAt: new Date().toISOString(),
|
|
138
|
+
error: {
|
|
139
|
+
code: 'NOTIFIER_FEATURE_NOT_FOUND',
|
|
140
|
+
message: `Notifier ${invocation.notifier} was not found.`,
|
|
141
|
+
},
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
const templates = yield _resolveTemplates(config, invocation.channel, notification.type);
|
|
145
|
+
const result = yield notifier({
|
|
146
|
+
channel: invocation.channel,
|
|
147
|
+
notification,
|
|
148
|
+
target: invocation.target,
|
|
149
|
+
template: templates.template,
|
|
150
|
+
htmlTemplate: templates.htmlTemplate,
|
|
151
|
+
options,
|
|
152
|
+
}, crossLayerProps);
|
|
153
|
+
if (isErrorObject(result)) {
|
|
154
|
+
return {
|
|
155
|
+
channel: invocation.channel,
|
|
156
|
+
notifier: invocation.notifier,
|
|
157
|
+
success: false,
|
|
158
|
+
sentAt: new Date().toISOString(),
|
|
159
|
+
error: result.error,
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
return result;
|
|
163
|
+
}));
|
|
164
|
+
const deliveryResults = createDeliveryResults(results);
|
|
165
|
+
const status = resolveDeliveryStatus(results);
|
|
166
|
+
return _updatePersistedNotification(Object.assign(Object.assign({}, notification), { status,
|
|
167
|
+
deliveryResults, sentAt: new Date().toISOString() }));
|
|
168
|
+
});
|
|
169
|
+
const _sendEmailChannelNotification = (props, crossLayerProps) => __awaiter(void 0, void 0, void 0, function* () {
|
|
170
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
171
|
+
var _h, _j, _k, _l;
|
|
172
|
+
const config = yield _getEffectiveConfig();
|
|
173
|
+
const recipients = (_l = (_k = (_j = (_h = (_a = props.target) === null || _a === void 0 ? void 0 : _a.to) !== null && _h !== void 0 ? _h : props.notification.recipients) !== null && _j !== void 0 ? _j : config.adminEmails) !== null && _k !== void 0 ? _k : (_b = config.email) === null || _b === void 0 ? void 0 : _b.defaultTo) !== null && _l !== void 0 ? _l : [];
|
|
174
|
+
const subjectPrefix = ((_c = config.email) === null || _c === void 0 ? void 0 : _c.subjectPrefix)
|
|
175
|
+
? `${config.email.subjectPrefix} `
|
|
176
|
+
: '';
|
|
177
|
+
const text = props.template
|
|
178
|
+
? renderNotificationTemplate({
|
|
179
|
+
template: props.template,
|
|
180
|
+
notification: props.notification,
|
|
181
|
+
channel: props.channel,
|
|
182
|
+
})
|
|
183
|
+
: props.notification.message;
|
|
184
|
+
const html = props.htmlTemplate
|
|
185
|
+
? renderNotificationTemplate({
|
|
186
|
+
template: props.htmlTemplate,
|
|
187
|
+
notification: props.notification,
|
|
188
|
+
channel: props.channel,
|
|
189
|
+
})
|
|
190
|
+
: props.notification.htmlMessage;
|
|
191
|
+
const result = yield context.services[NotificationsNamespace.Backend].sendEmail({
|
|
192
|
+
from: (_d = config.email) === null || _d === void 0 ? void 0 : _d.from,
|
|
193
|
+
to: recipients,
|
|
194
|
+
cc: (_e = props.target) === null || _e === void 0 ? void 0 : _e.cc,
|
|
195
|
+
bcc: (_f = props.target) === null || _f === void 0 ? void 0 : _f.bcc,
|
|
196
|
+
replyTo: (_g = props.target) === null || _g === void 0 ? void 0 : _g.replyTo,
|
|
197
|
+
subject: `${subjectPrefix}${props.notification.title}`,
|
|
198
|
+
text,
|
|
199
|
+
html,
|
|
200
|
+
}, crossLayerProps);
|
|
201
|
+
if (isErrorObject(result)) {
|
|
202
|
+
return result;
|
|
203
|
+
}
|
|
204
|
+
return {
|
|
205
|
+
channel: props.channel,
|
|
206
|
+
notifier: 'email',
|
|
207
|
+
success: true,
|
|
208
|
+
sentAt: new Date().toISOString(),
|
|
209
|
+
details: {
|
|
210
|
+
messageId: result.messageId,
|
|
211
|
+
accepted: result.accepted,
|
|
212
|
+
rejected: result.rejected,
|
|
213
|
+
},
|
|
214
|
+
};
|
|
215
|
+
});
|
|
216
|
+
const sendNotification = annotatedFunction(SendNotificationSchema, (props, crossLayerProps) => __awaiter(void 0, void 0, void 0, function* () {
|
|
217
|
+
var _a, _b;
|
|
218
|
+
const notification = yield _persistNotification({
|
|
219
|
+
id: randomUUID(),
|
|
220
|
+
type: (_a = props.type) !== null && _a !== void 0 ? _a : NotificationType.System,
|
|
221
|
+
severity: (_b = props.severity) !== null && _b !== void 0 ? _b : NotificationSeverity.Info,
|
|
222
|
+
title: props.title,
|
|
223
|
+
message: props.message,
|
|
224
|
+
htmlMessage: props.htmlMessage,
|
|
225
|
+
data: props.data,
|
|
226
|
+
userId: props.userId,
|
|
227
|
+
recipients: props.recipients,
|
|
228
|
+
targets: props.targets,
|
|
229
|
+
channels: props.channels,
|
|
230
|
+
notifiers: props.notifiers,
|
|
231
|
+
idempotencyKey: props.idempotencyKey,
|
|
232
|
+
status: NotificationStatus.Pending,
|
|
233
|
+
crossLayerProps: crossLayerProps,
|
|
234
|
+
ttl: props.ttl,
|
|
235
|
+
createdAt: new Date().toISOString(),
|
|
236
|
+
});
|
|
237
|
+
const dispatched = yield _dispatchNotification(notification, props.options, crossLayerProps);
|
|
238
|
+
return {
|
|
239
|
+
notification: dispatched,
|
|
240
|
+
};
|
|
241
|
+
}));
|
|
242
|
+
const sendSystemNotification = annotatedFunction(SendSystemNotificationSchema, (props, crossLayerProps) => {
|
|
243
|
+
const systemData = buildSystemTemplateData({
|
|
244
|
+
config: context.config,
|
|
245
|
+
crossLayerProps,
|
|
246
|
+
data: props.data,
|
|
247
|
+
});
|
|
248
|
+
return sendNotification(Object.assign(Object.assign({}, props), { type: NotificationType.System, data: Object.assign(Object.assign({}, systemData), { runtimeId: context.constants.runtimeId }) }), crossLayerProps);
|
|
249
|
+
});
|
|
250
|
+
const sendExecutionFailureNotification = annotatedFunction(SendExecutionFailureNotificationSchema, (props, crossLayerProps) => {
|
|
251
|
+
var _a, _b, _c;
|
|
252
|
+
const data = buildExecutionFailureTemplateData({
|
|
253
|
+
config: context.config,
|
|
254
|
+
domain: props.domain,
|
|
255
|
+
functionName: props.functionName,
|
|
256
|
+
error: props.error,
|
|
257
|
+
functionArgs: props.args,
|
|
258
|
+
crossLayerProps,
|
|
259
|
+
data: props.data,
|
|
260
|
+
});
|
|
261
|
+
return sendNotification(Object.assign(Object.assign({}, props), { type: NotificationType.ExecutionFailure, title: (_a = props.title) !== null && _a !== void 0 ? _a : `${props.domain}.${props.functionName} failed`, message: (_b = props.message) !== null && _b !== void 0 ? _b : 'A feature or service execution failed.', severity: (_c = props.severity) !== null && _c !== void 0 ? _c : NotificationSeverity.Error, data: Object.assign(Object.assign({}, data), { runtimeId: context.constants.runtimeId }), options: props.options }), crossLayerProps);
|
|
262
|
+
});
|
|
263
|
+
const _resolveUserFromModel = (userId) => __awaiter(void 0, void 0, void 0, function* () {
|
|
264
|
+
var _a, _b, _c;
|
|
265
|
+
var _d, _e;
|
|
266
|
+
const backendConfig = _getStaticConfig();
|
|
267
|
+
const authConfig = context.config['@node-in-layers/auth/core'];
|
|
268
|
+
const reference = (_e = (_d = (_a = backendConfig.userResolution) === null || _a === void 0 ? void 0 : _a.userModel) !== null && _d !== void 0 ? _d : authConfig === null || authConfig === void 0 ? void 0 : authConfig.userModel) !== null && _e !== void 0 ? _e : '@node-in-layers/auth/core.Users';
|
|
269
|
+
const parsed = parseModelReference(reference);
|
|
270
|
+
if (isErrorObject(parsed)) {
|
|
271
|
+
return parsed;
|
|
272
|
+
}
|
|
273
|
+
const services = context.services.getServices(parsed.domain);
|
|
274
|
+
const user = yield (_c = (_b = services === null || services === void 0 ? void 0 : services.cruds) === null || _b === void 0 ? void 0 : _b[parsed.modelName]) === null || _c === void 0 ? void 0 : _c.retrieve(userId);
|
|
275
|
+
return user === null || user === void 0 ? void 0 : user.toObj();
|
|
276
|
+
});
|
|
277
|
+
const _resolveUser = (userId, user, crossLayerProps) => __awaiter(void 0, void 0, void 0, function* () {
|
|
278
|
+
if (user) {
|
|
279
|
+
return user;
|
|
280
|
+
}
|
|
281
|
+
const crossLayerUser = crossLayerProps === null || crossLayerProps === void 0 ? void 0 : crossLayerProps.user;
|
|
282
|
+
if (crossLayerUser && (!userId || crossLayerUser.id === userId)) {
|
|
283
|
+
return crossLayerUser;
|
|
284
|
+
}
|
|
285
|
+
if (!userId) {
|
|
286
|
+
return undefined;
|
|
287
|
+
}
|
|
288
|
+
return _resolveUserFromModel(userId);
|
|
289
|
+
});
|
|
290
|
+
const sendUserNotification = annotatedFunction(SendUserNotificationSchema, (props, crossLayerProps) => __awaiter(void 0, void 0, void 0, function* () {
|
|
291
|
+
var _a;
|
|
292
|
+
var _b, _c, _d, _e, _f, _g;
|
|
293
|
+
const merged = Object.assign(Object.assign({}, props), ((_b = props.notificationProps) !== null && _b !== void 0 ? _b : {}));
|
|
294
|
+
const user = yield _resolveUser(merged.userId, merged.user, crossLayerProps);
|
|
295
|
+
if (isErrorObject(user)) {
|
|
296
|
+
return user;
|
|
297
|
+
}
|
|
298
|
+
if (!user) {
|
|
299
|
+
return createErrorObject('USER_NOT_FOUND', 'A user is required to send a user notification.');
|
|
300
|
+
}
|
|
301
|
+
if (user.enabled === false) {
|
|
302
|
+
return createErrorObject('USER_DISABLED', 'Disabled users cannot be notified.');
|
|
303
|
+
}
|
|
304
|
+
const channels = (_e = (_d = (_c = merged.channels) !== null && _c !== void 0 ? _c : (_a = _getStaticConfig().userResolution) === null || _a === void 0 ? void 0 : _a.defaultChannels) !== null && _d !== void 0 ? _d : _getStaticConfig().defaultChannels) !== null && _e !== void 0 ? _e : [NotificationChannel.Email];
|
|
305
|
+
const userTargets = createUserTargets({
|
|
306
|
+
channels,
|
|
307
|
+
user,
|
|
308
|
+
});
|
|
309
|
+
return sendNotification(Object.assign(Object.assign({}, merged), { type: NotificationType.User, userId: user.id, data: Object.assign(Object.assign({}, ((_f = merged.data) !== null && _f !== void 0 ? _f : {})), { user: createUserTemplateData(user) }), targets: [...userTargets, ...((_g = merged.targets) !== null && _g !== void 0 ? _g : [])] }), crossLayerProps);
|
|
310
|
+
}));
|
|
311
|
+
const wrapWithFailureNotification = (metadata, method) => {
|
|
312
|
+
const wrapped = ((methodProps, crossLayerProps) => Promise.resolve()
|
|
313
|
+
.then(() => method(methodProps, crossLayerProps))
|
|
314
|
+
.then((result) => __awaiter(void 0, void 0, void 0, function* () {
|
|
315
|
+
if (isErrorObject(result)) {
|
|
316
|
+
yield sendExecutionFailureNotification({
|
|
317
|
+
domain: metadata.domain,
|
|
318
|
+
functionName: metadata.functionName,
|
|
319
|
+
error: result,
|
|
320
|
+
args: methodProps,
|
|
321
|
+
}, crossLayerProps).catch(() => undefined);
|
|
322
|
+
}
|
|
323
|
+
return result;
|
|
324
|
+
}))
|
|
325
|
+
.catch((error) => __awaiter(void 0, void 0, void 0, function* () {
|
|
326
|
+
yield sendExecutionFailureNotification({
|
|
327
|
+
domain: metadata.domain,
|
|
328
|
+
functionName: metadata.functionName,
|
|
329
|
+
error: error,
|
|
330
|
+
args: methodProps,
|
|
331
|
+
}, crossLayerProps).catch(() => undefined);
|
|
332
|
+
throw error;
|
|
333
|
+
})));
|
|
334
|
+
// Preserve annotatedFunction metadata on the wrapper function object.
|
|
335
|
+
// eslint-disable-next-line functional/immutable-data
|
|
336
|
+
return Object.assign(wrapped, {
|
|
337
|
+
functionName: method.functionName,
|
|
338
|
+
domain: method.domain,
|
|
339
|
+
schema: method.schema,
|
|
340
|
+
});
|
|
341
|
+
};
|
|
342
|
+
return {
|
|
343
|
+
sendNotification,
|
|
344
|
+
sendUserNotification,
|
|
345
|
+
sendSystemNotification,
|
|
346
|
+
sendExecutionFailureNotification,
|
|
347
|
+
wrapWithFailureNotification,
|
|
348
|
+
};
|
|
349
|
+
};
|
|
350
|
+
//# sourceMappingURL=features.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features.js","sourceRoot":"","sources":["../../src/backend/features.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AACxC,OAAO,EAKL,iBAAiB,EACjB,iBAAiB,EACjB,aAAa,GACd,MAAM,sBAAsB,CAAA;AAC7B,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAA;AACvC,OAAO,EAIL,YAAY,GACb,MAAM,mBAAmB,CAAA;AAC1B,OAAO,EAGL,sBAAsB,GACvB,MAAM,aAAa,CAAA;AACpB,OAAO,EAGL,mBAAmB,EAKnB,oBAAoB,EACpB,kBAAkB,EAElB,gBAAgB,EAEhB,sCAAsC,EAGtC,sBAAsB,EACtB,4BAA4B,EAC5B,0BAA0B,GAC3B,MA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AAK,CAAC,CAAM,KAAK,EAAC,EAAE;YACnB,MAAM,gCAAgC,CACpC;gBACE,MAAM,EAAE,QAAQ,CAAC,MAAM;gBACvB,YAAY,EAAE,QAAQ,CAAC,YAAY;gBACnC,KAAK,EAAE,KAAiB;gBACxB,IAAI,EAAE,WAAsB;aAC7B,EACD,eAAe,CAChB,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAA;YACxB,MAAM,KAAK,CAAA;QACb,CAAC,CAAA,CAAC,CAAyB,CAAA;QAE/B,sEAAsE;QACtE,qDAAqD;QACrD,OAAO,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE;YAC5B,YAAY,EAAG,MAAc,CAAC,YAAY;YAC1C,MAAM,EAAG,MAAc,CAAC,MAAM;YAC9B,MAAM,EAAG,MAAc,CAAC,MAAM;SAC/B,CAAc,CAAA;IACjB,CAAC,CAAA;IAED,OAAO;QACL,gBAAgB;QAChB,oBAAoB;QACpB,sBAAsB;QACtB,gCAAgC;QAChC,2BAA2B;KAC5B,CAAA;AACH,CAAC,CAAA"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { NotificationsNamespace } from '../types.js';
|
|
2
|
+
export declare const name = NotificationsNamespace.Backend;
|
|
3
|
+
export * as services from './services.js';
|
|
4
|
+
export * as features from './features.js';
|
|
5
|
+
export * from './types.js';
|
|
6
|
+
export * as libs from './libs.js';
|
package/backend/index.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { NotificationsNamespace } from '../types.js';
|
|
2
|
+
export const name = NotificationsNamespace.Backend;
|
|
3
|
+
export * as services from './services.js';
|
|
4
|
+
export * as features from './features.js';
|
|
5
|
+
export * from './types.js';
|
|
6
|
+
export * as libs from './libs.js';
|
|
7
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/backend/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAA;AAEpD,MAAM,CAAC,MAAM,IAAI,GAAG,sBAAsB,CAAC,OAAO,CAAA;AAClD,OAAO,KAAK,QAAQ,MAAM,eAAe,CAAA;AACzC,OAAO,KAAK,QAAQ,MAAM,eAAe,CAAA;AACzC,cAAc,YAAY,CAAA;AAC1B,OAAO,KAAK,IAAI,MAAM,WAAW,CAAA"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { BackendNotificationsConfig } from '../types.js';
|
|
2
|
+
import { Notification, NotificationChannel, NotificationDeliveryResult, NotificationStatus, NotificationTarget, NotificationUser } from '../core/types.js';
|
|
3
|
+
export type NotificationInvocation = Readonly<{
|
|
4
|
+
channel: string;
|
|
5
|
+
target?: NotificationTarget;
|
|
6
|
+
notifier?: string;
|
|
7
|
+
}>;
|
|
8
|
+
export declare const getEffectiveNotifiers: (args: Readonly<{
|
|
9
|
+
config: BackendNotificationsConfig;
|
|
10
|
+
notification: Notification;
|
|
11
|
+
}>) => {
|
|
12
|
+
[x: string]: string;
|
|
13
|
+
};
|
|
14
|
+
export declare const resolveChannels: (args: Readonly<{
|
|
15
|
+
config: BackendNotificationsConfig;
|
|
16
|
+
notification: Notification;
|
|
17
|
+
}>) => readonly string[];
|
|
18
|
+
export declare const resolveInvocations: (args: Readonly<{
|
|
19
|
+
config: BackendNotificationsConfig;
|
|
20
|
+
notification: Notification;
|
|
21
|
+
}>) => readonly NotificationInvocation[];
|
|
22
|
+
export declare const getStaticTemplate: (args: Readonly<{
|
|
23
|
+
config: BackendNotificationsConfig;
|
|
24
|
+
channel: string;
|
|
25
|
+
type: string;
|
|
26
|
+
}>) => Readonly<{
|
|
27
|
+
template?: string;
|
|
28
|
+
htmlTemplate?: string;
|
|
29
|
+
}>;
|
|
30
|
+
export declare const createDeliveryResults: (results: readonly NotificationDeliveryResult[]) => Record<string, Readonly<{
|
|
31
|
+
channel: NotificationChannel | string;
|
|
32
|
+
notifier: string;
|
|
33
|
+
success: boolean;
|
|
34
|
+
sentAt?: string;
|
|
35
|
+
details?: import("functional-models").JsonObj;
|
|
36
|
+
error?: import("@node-in-layers/core").ErrorObject['error'];
|
|
37
|
+
}>>;
|
|
38
|
+
export declare const resolveDeliveryStatus: (results: readonly NotificationDeliveryResult[]) => NotificationStatus.Sent | NotificationStatus.PartialFailure | NotificationStatus.Failed;
|
|
39
|
+
export declare const parseModelReference: (reference: string) => Readonly<{
|
|
40
|
+
error: Readonly<{
|
|
41
|
+
code: string;
|
|
42
|
+
message: string;
|
|
43
|
+
details?: string;
|
|
44
|
+
data?: Record<string, import("functional-models").JsonAble>;
|
|
45
|
+
trace?: string;
|
|
46
|
+
cause?: import("@node-in-layers/core").ErrorObject;
|
|
47
|
+
}>;
|
|
48
|
+
}> | {
|
|
49
|
+
domain: string;
|
|
50
|
+
modelName: string;
|
|
51
|
+
};
|
|
52
|
+
export declare const createUserTargets: (args: Readonly<{
|
|
53
|
+
channels: readonly (NotificationChannel | string)[];
|
|
54
|
+
user: NotificationUser;
|
|
55
|
+
}>) => readonly NotificationTarget[];
|
|
56
|
+
export declare const createUserTemplateData: (user: NotificationUser) => {
|
|
57
|
+
id: import("functional-models").PrimaryKeyType;
|
|
58
|
+
email: string | undefined;
|
|
59
|
+
firstName: string | undefined;
|
|
60
|
+
lastName: string | undefined;
|
|
61
|
+
username: string | undefined;
|
|
62
|
+
phoneNumber: string | undefined;
|
|
63
|
+
};
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { createErrorObject } from '@node-in-layers/core';
|
|
2
|
+
import { NotificationChannel, NotificationStatus, } from '../core/types.js';
|
|
3
|
+
export const getEffectiveNotifiers = (args) => { var _a, _b; return (Object.assign(Object.assign({}, ((_a = args.config.notifiers) !== null && _a !== void 0 ? _a : {})), ((_b = args.notification.notifiers) !== null && _b !== void 0 ? _b : {}))); };
|
|
4
|
+
export const resolveChannels = (args) => {
|
|
5
|
+
var _a, _b;
|
|
6
|
+
const notifiers = getEffectiveNotifiers(args);
|
|
7
|
+
if (args.notification.targets && args.notification.targets.length > 0) {
|
|
8
|
+
return args.notification.targets.map(target => target.channel);
|
|
9
|
+
}
|
|
10
|
+
const configuredChannels = (_b = (_a = args.notification.channels) !== null && _a !== void 0 ? _a : args.config.defaultChannels) !== null && _b !== void 0 ? _b : Object.keys(notifiers);
|
|
11
|
+
if (configuredChannels.length > 0) {
|
|
12
|
+
return configuredChannels;
|
|
13
|
+
}
|
|
14
|
+
return args.config.email ? [NotificationChannel.Email] : [];
|
|
15
|
+
};
|
|
16
|
+
export const resolveInvocations = (args) => {
|
|
17
|
+
const notifiers = getEffectiveNotifiers(args);
|
|
18
|
+
if (args.notification.targets && args.notification.targets.length > 0) {
|
|
19
|
+
return args.notification.targets.map(target => { var _a; return ({
|
|
20
|
+
channel: target.channel,
|
|
21
|
+
target,
|
|
22
|
+
notifier: (_a = target.notifier) !== null && _a !== void 0 ? _a : notifiers[target.channel],
|
|
23
|
+
}); });
|
|
24
|
+
}
|
|
25
|
+
return resolveChannels(args).map(channel => ({
|
|
26
|
+
channel,
|
|
27
|
+
notifier: notifiers[channel],
|
|
28
|
+
}));
|
|
29
|
+
};
|
|
30
|
+
export const getStaticTemplate = (args) => {
|
|
31
|
+
var _a, _b;
|
|
32
|
+
const source = (_b = (_a = args.config.templates) === null || _a === void 0 ? void 0 : _a[args.channel]) === null || _b === void 0 ? void 0 : _b[args.type];
|
|
33
|
+
if (!source) {
|
|
34
|
+
return {};
|
|
35
|
+
}
|
|
36
|
+
if (typeof source === 'string') {
|
|
37
|
+
return {
|
|
38
|
+
template: source,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
return {
|
|
42
|
+
template: source.text,
|
|
43
|
+
htmlTemplate: source.html,
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
export const createDeliveryResults = (results) => {
|
|
47
|
+
return results.reduce((acc, result) => {
|
|
48
|
+
return Object.assign(Object.assign({}, acc), { [result.channel]: result });
|
|
49
|
+
}, {});
|
|
50
|
+
};
|
|
51
|
+
export const resolveDeliveryStatus = (results) => {
|
|
52
|
+
const successes = results.filter(result => result.success);
|
|
53
|
+
if (successes.length === results.length) {
|
|
54
|
+
return NotificationStatus.Sent;
|
|
55
|
+
}
|
|
56
|
+
if (successes.length > 0) {
|
|
57
|
+
return NotificationStatus.PartialFailure;
|
|
58
|
+
}
|
|
59
|
+
return NotificationStatus.Failed;
|
|
60
|
+
};
|
|
61
|
+
export const parseModelReference = (reference) => {
|
|
62
|
+
const index = reference.lastIndexOf('.');
|
|
63
|
+
if (index === -1) {
|
|
64
|
+
return createErrorObject('INVALID_USER_MODEL_REFERENCE', `Invalid user model reference "${reference}". Expected "domain.PluralModelName".`);
|
|
65
|
+
}
|
|
66
|
+
return {
|
|
67
|
+
domain: reference.slice(0, index),
|
|
68
|
+
modelName: reference.slice(index + 1),
|
|
69
|
+
};
|
|
70
|
+
};
|
|
71
|
+
export const createUserTargets = (args) => {
|
|
72
|
+
return args.channels.reduce((acc, channel) => {
|
|
73
|
+
if (channel === NotificationChannel.Email && args.user.email) {
|
|
74
|
+
return acc.concat([
|
|
75
|
+
{
|
|
76
|
+
channel,
|
|
77
|
+
to: [args.user.email],
|
|
78
|
+
},
|
|
79
|
+
]);
|
|
80
|
+
}
|
|
81
|
+
if (channel === NotificationChannel.Sms && args.user.phoneNumber) {
|
|
82
|
+
return acc.concat([
|
|
83
|
+
{
|
|
84
|
+
channel,
|
|
85
|
+
phoneNumbers: [args.user.phoneNumber],
|
|
86
|
+
},
|
|
87
|
+
]);
|
|
88
|
+
}
|
|
89
|
+
return acc;
|
|
90
|
+
}, []);
|
|
91
|
+
};
|
|
92
|
+
export const createUserTemplateData = (user) => ({
|
|
93
|
+
id: user.id,
|
|
94
|
+
email: user.email,
|
|
95
|
+
firstName: user.firstName,
|
|
96
|
+
lastName: user.lastName,
|
|
97
|
+
username: user.username,
|
|
98
|
+
phoneNumber: user.phoneNumber,
|
|
99
|
+
});
|
|
100
|
+
//# s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AK,IAAI,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC;YAC7D,OAAO,GAAG,CAAC,MAAM,CAAC;gBAChB;oBACE,OAAO;oBACP,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC;iBACtB;aACF,CAAC,CAAA;QACJ,CAAC;QACD,IAAI,OAAO,KAAK,mBAAmB,CAAC,GAAG,IAAI,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC;YACjE,OAAO,GAAG,CAAC,MAAM,CAAC;gBAChB;oBACE,OAAO;oBACP,YAAY,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC;iBACtC;aACF,CAAC,CAAA;QACJ,CAAC;QACD,OAAO,GAAG,CAAA;IACZ,CAAC,EAAE,EAAE,CAAC,CAAA;AACR,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,IAAsB,EAAE,EAAE,CAAC,CAAC;IACjE,EAAE,EAAE,IAAI,CAAC,EAAE;IACX,KAAK,EAAE,IAAI,CAAC,KAAK;IACjB,SAAS,EAAE,IAAI,CAAC,SAAS;IACzB,QAAQ,EAAE,IAAI,CAAC,QAAQ;IACvB,QAAQ,EAAE,IAAI,CAAC,QAAQ;IACvB,WAAW,EAAE,IAAI,CAAC,WAAW;CAC9B,CAAC,CAAA"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { CrossLayerProps, ErrorObject } from '@node-in-layers/core';
|
|
2
|
+
import { JsonAble, JsonObj } from 'functional-models';
|
|
3
|
+
import { BackendNotificationsConfig, ConfigWithNotifications } from '../types.js';
|
|
4
|
+
import { NotificationConfigRecord } from '../core/types.js';
|
|
5
|
+
export declare const normalizeFailureError: (error: JsonAble | ErrorObject | unknown) => ErrorObject['error'];
|
|
6
|
+
export declare const mergeNotificationConfig: (args: Readonly<{
|
|
7
|
+
staticConfig: BackendNotificationsConfig | undefined;
|
|
8
|
+
databaseConfig?: NotificationConfigRecord;
|
|
9
|
+
}>) => BackendNotificationsConfig;
|
|
10
|
+
export declare const buildSystemTemplateData: (args: Readonly<{
|
|
11
|
+
config: ConfigWithNotifications;
|
|
12
|
+
crossLayerProps?: CrossLayerProps;
|
|
13
|
+
data?: JsonObj;
|
|
14
|
+
}>) => JsonObj;
|
|
15
|
+
export declare const buildExecutionFailureTemplateData: (args: Readonly<{
|
|
16
|
+
config: ConfigWithNotifications;
|
|
17
|
+
domain: string;
|
|
18
|
+
functionName: string;
|
|
19
|
+
error: JsonAble | ErrorObject;
|
|
20
|
+
functionArgs?: JsonObj;
|
|
21
|
+
crossLayerProps?: CrossLayerProps;
|
|
22
|
+
data?: JsonObj;
|
|
23
|
+
}>) => JsonObj;
|
package/backend/libs.js
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import merge from 'lodash/merge.js';
|
|
2
|
+
import { createErrorObject, isErrorObject, } from '@node-in-layers/core';
|
|
3
|
+
import { NotificationsNamespace, } from '../types.js';
|
|
4
|
+
const omitUndefined = (value) => Object.fromEntries(Object.entries(value).filter((entry) => {
|
|
5
|
+
return entry[1] !== undefined;
|
|
6
|
+
}));
|
|
7
|
+
export const normalizeFailureError = (error) => {
|
|
8
|
+
if (isErrorObject(error)) {
|
|
9
|
+
return error.error;
|
|
10
|
+
}
|
|
11
|
+
if (error instanceof Error) {
|
|
12
|
+
return {
|
|
13
|
+
code: error.name || 'ERROR',
|
|
14
|
+
message: error.message,
|
|
15
|
+
trace: error.stack,
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
return createErrorObject('EXECUTION_FAILURE', 'Execution failed.', error)
|
|
19
|
+
.error;
|
|
20
|
+
};
|
|
21
|
+
export const mergeNotificationConfig = (args) => {
|
|
22
|
+
var _a;
|
|
23
|
+
const databaseConfig = args.databaseConfig
|
|
24
|
+
? omitUndefined({
|
|
25
|
+
adminEmails: args.databaseConfig.adminEmails,
|
|
26
|
+
email: omitUndefined({
|
|
27
|
+
from: args.databaseConfig.fromEmail,
|
|
28
|
+
subjectPrefix: args.databaseConfig.subjectPrefix,
|
|
29
|
+
}),
|
|
30
|
+
defaultChannels: args.databaseConfig.defaultChannels,
|
|
31
|
+
notifiers: args.databaseConfig.notifiers,
|
|
32
|
+
})
|
|
33
|
+
: {};
|
|
34
|
+
return merge({}, (_a = args.staticConfig) !== null && _a !== void 0 ? _a : {}, databaseConfig);
|
|
35
|
+
};
|
|
36
|
+
export const buildSystemTemplateData = (args) => {
|
|
37
|
+
var _a, _b, _c;
|
|
38
|
+
var _d, _e;
|
|
39
|
+
return Object.assign({ systemName: args.config.systemName, environment: args.config.environment, runtimeId: '', datetime: new Date().toISOString(), ids: (_d = (_b = (_a = args.crossLayerProps) === null || _a === void 0 ? void 0 : _a.logging) === null || _b === void 0 ? void 0 : _b.ids) !== null && _d !== void 0 ? _d : [], adminUrl: (_c = args.config[NotificationsNamespace.Backend]) === null || _c === void 0 ? void 0 : _c.adminUrl }, ((_e = args.data) !== null && _e !== void 0 ? _e : {}));
|
|
40
|
+
};
|
|
41
|
+
export const buildExecutionFailureTemplateData = (args) => {
|
|
42
|
+
return Object.assign(Object.assign({}, buildSystemTemplateData({
|
|
43
|
+
config: args.config,
|
|
44
|
+
crossLayerProps: args.crossLayerProps,
|
|
45
|
+
data: args.data,
|
|
46
|
+
})), { domain: args.domain, functionName: args.functionName, args: args.functionArgs, error: normalizeFailureError(args.error) });
|
|
47
|
+
};
|
|
48
|
+
//# sourceMappingURL=libs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"libs.js","sourceRoot":"","sources":["../../src/backend/libs.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,iBAAiB,CAAA;AACnC,OAAO,EAGL,iBAAiB,EACjB,aAAa,GACd,MAAM,sBAAsB,CAAA;AAE7B,OAAO,EAGL,sBAAsB,GACvB,MAAM,aAAa,CAAA;AAGpB,MAAM,aAAa,GAAG,CAAoC,KAAQ,EAAE,EAAE,CACpE,MAAM,CA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