@twin.org/messaging-connector-entity-storage 0.0.2-next.6 → 0.0.3-next.2
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/dist/es/entities/emailEntry.js +75 -0
- package/dist/es/entities/emailEntry.js.map +1 -0
- package/dist/es/entities/pushNotificationDeviceEntry.js +59 -0
- package/dist/es/entities/pushNotificationDeviceEntry.js.map +1 -0
- package/dist/es/entities/pushNotificationMessageEntry.js +67 -0
- package/dist/es/entities/pushNotificationMessageEntry.js.map +1 -0
- package/dist/es/entities/smsEntry.js +59 -0
- package/dist/es/entities/smsEntry.js.map +1 -0
- package/dist/es/entityStorageMessagingEmailConnector.js +83 -0
- package/dist/es/entityStorageMessagingEmailConnector.js.map +1 -0
- package/dist/es/entityStorageMessagingPushNotificationConnector.js +114 -0
- package/dist/es/entityStorageMessagingPushNotificationConnector.js.map +1 -0
- package/dist/es/entityStorageMessagingSmsConnector.js +74 -0
- package/dist/es/entityStorageMessagingSmsConnector.js.map +1 -0
- package/dist/es/index.js +14 -0
- package/dist/es/index.js.map +1 -0
- package/dist/es/models/IEntityStorageMessagingEmailConnectorConstructorOptions.js +4 -0
- package/dist/es/models/IEntityStorageMessagingEmailConnectorConstructorOptions.js.map +1 -0
- package/dist/es/models/IEntityStorageMessagingPushNotificationConnectorConstructorOptions.js +4 -0
- package/dist/es/models/IEntityStorageMessagingPushNotificationConnectorConstructorOptions.js.map +1 -0
- package/dist/es/models/IEntityStorageMessagingSmsConnectorConstructorOptions.js +4 -0
- package/dist/es/models/IEntityStorageMessagingSmsConnectorConstructorOptions.js.map +1 -0
- package/dist/es/schema.js +27 -0
- package/dist/es/schema.js.map +1 -0
- package/dist/types/entityStorageMessagingEmailConnector.d.ts +6 -1
- package/dist/types/entityStorageMessagingPushNotificationConnector.d.ts +6 -1
- package/dist/types/entityStorageMessagingSmsConnector.d.ts +6 -1
- package/dist/types/index.d.ts +11 -11
- package/docs/changelog.md +41 -0
- package/docs/reference/classes/EntityStorageMessagingEmailConnector.md +18 -0
- package/docs/reference/classes/EntityStorageMessagingPushNotificationConnector.md +18 -0
- package/docs/reference/classes/EntityStorageMessagingSmsConnector.md +18 -0
- package/package.json +7 -10
- package/dist/cjs/index.cjs +0 -528
- package/dist/esm/index.mjs +0 -523
package/dist/esm/index.mjs
DELETED
|
@@ -1,523 +0,0 @@
|
|
|
1
|
-
import { property, SortDirection, entity, EntitySchemaFactory, EntitySchemaHelper } from '@twin.org/entity';
|
|
2
|
-
import { ComponentFactory, Guards, Converter, RandomHelper, GeneralError } from '@twin.org/core';
|
|
3
|
-
import { EntityStorageConnectorFactory } from '@twin.org/entity-storage-models';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Call defining an email entry.
|
|
7
|
-
*/
|
|
8
|
-
let EmailEntry = class EmailEntry {
|
|
9
|
-
/**
|
|
10
|
-
* The id.
|
|
11
|
-
*/
|
|
12
|
-
id;
|
|
13
|
-
/**
|
|
14
|
-
* The sender email address.
|
|
15
|
-
*/
|
|
16
|
-
sender;
|
|
17
|
-
/**
|
|
18
|
-
* The recipient email addresses.
|
|
19
|
-
*/
|
|
20
|
-
recipients;
|
|
21
|
-
/**
|
|
22
|
-
* The timestamp of the email entry.
|
|
23
|
-
*/
|
|
24
|
-
ts;
|
|
25
|
-
/**
|
|
26
|
-
* The message.
|
|
27
|
-
*/
|
|
28
|
-
message;
|
|
29
|
-
/**
|
|
30
|
-
* The subject.
|
|
31
|
-
*/
|
|
32
|
-
subject;
|
|
33
|
-
/**
|
|
34
|
-
* The status.
|
|
35
|
-
*/
|
|
36
|
-
status;
|
|
37
|
-
/**
|
|
38
|
-
* The error.
|
|
39
|
-
*/
|
|
40
|
-
error;
|
|
41
|
-
};
|
|
42
|
-
__decorate([
|
|
43
|
-
property({ type: "string", isPrimary: true }),
|
|
44
|
-
__metadata("design:type", String)
|
|
45
|
-
], EmailEntry.prototype, "id", void 0);
|
|
46
|
-
__decorate([
|
|
47
|
-
property({ type: "string" }),
|
|
48
|
-
__metadata("design:type", String)
|
|
49
|
-
], EmailEntry.prototype, "sender", void 0);
|
|
50
|
-
__decorate([
|
|
51
|
-
property({ type: "array", itemType: "string" }),
|
|
52
|
-
__metadata("design:type", Array)
|
|
53
|
-
], EmailEntry.prototype, "recipients", void 0);
|
|
54
|
-
__decorate([
|
|
55
|
-
property({ type: "integer", format: "uint64", sortDirection: SortDirection.Descending }),
|
|
56
|
-
__metadata("design:type", Number)
|
|
57
|
-
], EmailEntry.prototype, "ts", void 0);
|
|
58
|
-
__decorate([
|
|
59
|
-
property({ type: "string" }),
|
|
60
|
-
__metadata("design:type", String)
|
|
61
|
-
], EmailEntry.prototype, "message", void 0);
|
|
62
|
-
__decorate([
|
|
63
|
-
property({ type: "string" }),
|
|
64
|
-
__metadata("design:type", String)
|
|
65
|
-
], EmailEntry.prototype, "subject", void 0);
|
|
66
|
-
__decorate([
|
|
67
|
-
property({ type: "string" }),
|
|
68
|
-
__metadata("design:type", String)
|
|
69
|
-
], EmailEntry.prototype, "status", void 0);
|
|
70
|
-
__decorate([
|
|
71
|
-
property({ type: "object", optional: true }),
|
|
72
|
-
__metadata("design:type", Object)
|
|
73
|
-
], EmailEntry.prototype, "error", void 0);
|
|
74
|
-
EmailEntry = __decorate([
|
|
75
|
-
entity()
|
|
76
|
-
], EmailEntry);
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* Call defining an push notification device entry.
|
|
80
|
-
*/
|
|
81
|
-
let PushNotificationDeviceEntry = class PushNotificationDeviceEntry {
|
|
82
|
-
/**
|
|
83
|
-
* The id.
|
|
84
|
-
*/
|
|
85
|
-
id;
|
|
86
|
-
/**
|
|
87
|
-
* The applicationId.
|
|
88
|
-
*/
|
|
89
|
-
applicationId;
|
|
90
|
-
/**
|
|
91
|
-
* The device token.
|
|
92
|
-
*/
|
|
93
|
-
deviceToken;
|
|
94
|
-
/**
|
|
95
|
-
* The timestamp of the push notification device entry.
|
|
96
|
-
*/
|
|
97
|
-
ts;
|
|
98
|
-
/**
|
|
99
|
-
* The status.
|
|
100
|
-
*/
|
|
101
|
-
status;
|
|
102
|
-
/**
|
|
103
|
-
* The error.
|
|
104
|
-
*/
|
|
105
|
-
error;
|
|
106
|
-
};
|
|
107
|
-
__decorate([
|
|
108
|
-
property({ type: "string", isPrimary: true }),
|
|
109
|
-
__metadata("design:type", String)
|
|
110
|
-
], PushNotificationDeviceEntry.prototype, "id", void 0);
|
|
111
|
-
__decorate([
|
|
112
|
-
property({ type: "string" }),
|
|
113
|
-
__metadata("design:type", String)
|
|
114
|
-
], PushNotificationDeviceEntry.prototype, "applicationId", void 0);
|
|
115
|
-
__decorate([
|
|
116
|
-
property({ type: "string" }),
|
|
117
|
-
__metadata("design:type", String)
|
|
118
|
-
], PushNotificationDeviceEntry.prototype, "deviceToken", void 0);
|
|
119
|
-
__decorate([
|
|
120
|
-
property({ type: "integer", format: "uint64", sortDirection: SortDirection.Descending }),
|
|
121
|
-
__metadata("design:type", Number)
|
|
122
|
-
], PushNotificationDeviceEntry.prototype, "ts", void 0);
|
|
123
|
-
__decorate([
|
|
124
|
-
property({ type: "string" }),
|
|
125
|
-
__metadata("design:type", String)
|
|
126
|
-
], PushNotificationDeviceEntry.prototype, "status", void 0);
|
|
127
|
-
__decorate([
|
|
128
|
-
property({ type: "object", optional: true }),
|
|
129
|
-
__metadata("design:type", Object)
|
|
130
|
-
], PushNotificationDeviceEntry.prototype, "error", void 0);
|
|
131
|
-
PushNotificationDeviceEntry = __decorate([
|
|
132
|
-
entity()
|
|
133
|
-
], PushNotificationDeviceEntry);
|
|
134
|
-
|
|
135
|
-
/**
|
|
136
|
-
* Call defining an push notification message entry.
|
|
137
|
-
*/
|
|
138
|
-
let PushNotificationMessageEntry = class PushNotificationMessageEntry {
|
|
139
|
-
/**
|
|
140
|
-
* The id.
|
|
141
|
-
*/
|
|
142
|
-
id;
|
|
143
|
-
/**
|
|
144
|
-
* The device address.
|
|
145
|
-
*/
|
|
146
|
-
deviceAddress;
|
|
147
|
-
/**
|
|
148
|
-
* The title.
|
|
149
|
-
*/
|
|
150
|
-
title;
|
|
151
|
-
/**
|
|
152
|
-
* The message.
|
|
153
|
-
*/
|
|
154
|
-
message;
|
|
155
|
-
/**
|
|
156
|
-
* The timestamp of the push notification entry.
|
|
157
|
-
*/
|
|
158
|
-
ts;
|
|
159
|
-
/**
|
|
160
|
-
* The status.
|
|
161
|
-
*/
|
|
162
|
-
status;
|
|
163
|
-
/**
|
|
164
|
-
* The error.
|
|
165
|
-
*/
|
|
166
|
-
error;
|
|
167
|
-
};
|
|
168
|
-
__decorate([
|
|
169
|
-
property({ type: "string", isPrimary: true }),
|
|
170
|
-
__metadata("design:type", String)
|
|
171
|
-
], PushNotificationMessageEntry.prototype, "id", void 0);
|
|
172
|
-
__decorate([
|
|
173
|
-
property({ type: "string" }),
|
|
174
|
-
__metadata("design:type", String)
|
|
175
|
-
], PushNotificationMessageEntry.prototype, "deviceAddress", void 0);
|
|
176
|
-
__decorate([
|
|
177
|
-
property({ type: "string" }),
|
|
178
|
-
__metadata("design:type", String)
|
|
179
|
-
], PushNotificationMessageEntry.prototype, "title", void 0);
|
|
180
|
-
__decorate([
|
|
181
|
-
property({ type: "string" }),
|
|
182
|
-
__metadata("design:type", String)
|
|
183
|
-
], PushNotificationMessageEntry.prototype, "message", void 0);
|
|
184
|
-
__decorate([
|
|
185
|
-
property({ type: "integer", format: "uint64", sortDirection: SortDirection.Descending }),
|
|
186
|
-
__metadata("design:type", Number)
|
|
187
|
-
], PushNotificationMessageEntry.prototype, "ts", void 0);
|
|
188
|
-
__decorate([
|
|
189
|
-
property({ type: "string" }),
|
|
190
|
-
__metadata("design:type", String)
|
|
191
|
-
], PushNotificationMessageEntry.prototype, "status", void 0);
|
|
192
|
-
__decorate([
|
|
193
|
-
property({ type: "object", optional: true }),
|
|
194
|
-
__metadata("design:type", Object)
|
|
195
|
-
], PushNotificationMessageEntry.prototype, "error", void 0);
|
|
196
|
-
PushNotificationMessageEntry = __decorate([
|
|
197
|
-
entity()
|
|
198
|
-
], PushNotificationMessageEntry);
|
|
199
|
-
|
|
200
|
-
/**
|
|
201
|
-
* Call defining an sms entry.
|
|
202
|
-
*/
|
|
203
|
-
let SmsEntry = class SmsEntry {
|
|
204
|
-
/**
|
|
205
|
-
* The id.
|
|
206
|
-
*/
|
|
207
|
-
id;
|
|
208
|
-
/**
|
|
209
|
-
* The phone number to deliver the message.
|
|
210
|
-
*/
|
|
211
|
-
phoneNumber;
|
|
212
|
-
/**
|
|
213
|
-
* The timestamp of the sms entry.
|
|
214
|
-
*/
|
|
215
|
-
ts;
|
|
216
|
-
/**
|
|
217
|
-
* The message.
|
|
218
|
-
*/
|
|
219
|
-
message;
|
|
220
|
-
/**
|
|
221
|
-
* The status.
|
|
222
|
-
*/
|
|
223
|
-
status;
|
|
224
|
-
/**
|
|
225
|
-
* The error.
|
|
226
|
-
*/
|
|
227
|
-
error;
|
|
228
|
-
};
|
|
229
|
-
__decorate([
|
|
230
|
-
property({ type: "string", isPrimary: true }),
|
|
231
|
-
__metadata("design:type", String)
|
|
232
|
-
], SmsEntry.prototype, "id", void 0);
|
|
233
|
-
__decorate([
|
|
234
|
-
property({ type: "string" }),
|
|
235
|
-
__metadata("design:type", String)
|
|
236
|
-
], SmsEntry.prototype, "phoneNumber", void 0);
|
|
237
|
-
__decorate([
|
|
238
|
-
property({ type: "integer", format: "uint64", sortDirection: SortDirection.Descending }),
|
|
239
|
-
__metadata("design:type", Number)
|
|
240
|
-
], SmsEntry.prototype, "ts", void 0);
|
|
241
|
-
__decorate([
|
|
242
|
-
property({ type: "string" }),
|
|
243
|
-
__metadata("design:type", String)
|
|
244
|
-
], SmsEntry.prototype, "message", void 0);
|
|
245
|
-
__decorate([
|
|
246
|
-
property({ type: "string" }),
|
|
247
|
-
__metadata("design:type", String)
|
|
248
|
-
], SmsEntry.prototype, "status", void 0);
|
|
249
|
-
__decorate([
|
|
250
|
-
property({ type: "object", optional: true }),
|
|
251
|
-
__metadata("design:type", Object)
|
|
252
|
-
], SmsEntry.prototype, "error", void 0);
|
|
253
|
-
SmsEntry = __decorate([
|
|
254
|
-
entity()
|
|
255
|
-
], SmsEntry);
|
|
256
|
-
|
|
257
|
-
// Copyright 2024 IOTA Stiftung.
|
|
258
|
-
// SPDX-License-Identifier: Apache-2.0.
|
|
259
|
-
/**
|
|
260
|
-
* Class for connecting to the email messaging operations of the Entity Storage.
|
|
261
|
-
*/
|
|
262
|
-
class EntityStorageMessagingEmailConnector {
|
|
263
|
-
/**
|
|
264
|
-
* The namespace for the connector.
|
|
265
|
-
*/
|
|
266
|
-
static NAMESPACE = "entity-storage";
|
|
267
|
-
/**
|
|
268
|
-
* Runtime name for the class.
|
|
269
|
-
*/
|
|
270
|
-
static CLASS_NAME = "EntityStorageMessagingEmailConnector";
|
|
271
|
-
/**
|
|
272
|
-
* The logging component.
|
|
273
|
-
* @internal
|
|
274
|
-
*/
|
|
275
|
-
_logging;
|
|
276
|
-
/**
|
|
277
|
-
* The entity storage for the emails entries.
|
|
278
|
-
* @internal
|
|
279
|
-
*/
|
|
280
|
-
_messagingEmailEntryStorage;
|
|
281
|
-
/**
|
|
282
|
-
* Create a new instance of EntityStorageMessagingEmailConnector.
|
|
283
|
-
* @param options The options for the connector.
|
|
284
|
-
*/
|
|
285
|
-
constructor(options) {
|
|
286
|
-
this._logging = ComponentFactory.getIfExists(options?.loggingComponentType ?? "logging");
|
|
287
|
-
this._messagingEmailEntryStorage = EntityStorageConnectorFactory.get(options?.messagingEmailEntryStorageConnectorType ?? "email-entry");
|
|
288
|
-
}
|
|
289
|
-
/**
|
|
290
|
-
* Store a custom email using Entity Storage.
|
|
291
|
-
* @param sender The sender email address.
|
|
292
|
-
* @param recipients An array of recipients email addresses.
|
|
293
|
-
* @param subject The subject of the email.
|
|
294
|
-
* @param content The html content of the email.
|
|
295
|
-
* @returns True if the email was send successfully, otherwise undefined.
|
|
296
|
-
*/
|
|
297
|
-
async sendCustomEmail(sender, recipients, subject, content) {
|
|
298
|
-
Guards.stringValue(EntityStorageMessagingEmailConnector.CLASS_NAME, "sender", sender);
|
|
299
|
-
Guards.arrayValue(EntityStorageMessagingEmailConnector.CLASS_NAME, "recipients", recipients);
|
|
300
|
-
Guards.stringValue(EntityStorageMessagingEmailConnector.CLASS_NAME, "subject", subject);
|
|
301
|
-
Guards.stringValue(EntityStorageMessagingEmailConnector.CLASS_NAME, "content", content);
|
|
302
|
-
try {
|
|
303
|
-
await this._logging?.log({
|
|
304
|
-
level: "info",
|
|
305
|
-
source: EntityStorageMessagingEmailConnector.CLASS_NAME,
|
|
306
|
-
ts: Date.now(),
|
|
307
|
-
message: "emailSending",
|
|
308
|
-
data: {
|
|
309
|
-
type: "Custom Email"
|
|
310
|
-
}
|
|
311
|
-
});
|
|
312
|
-
const id = Converter.bytesToHex(RandomHelper.generate(32));
|
|
313
|
-
const entity = {
|
|
314
|
-
id,
|
|
315
|
-
sender,
|
|
316
|
-
recipients,
|
|
317
|
-
ts: Date.now(),
|
|
318
|
-
message: content,
|
|
319
|
-
subject,
|
|
320
|
-
status: "pending"
|
|
321
|
-
};
|
|
322
|
-
await this._messagingEmailEntryStorage.set(entity);
|
|
323
|
-
return true;
|
|
324
|
-
}
|
|
325
|
-
catch (err) {
|
|
326
|
-
throw new GeneralError(EntityStorageMessagingEmailConnector.CLASS_NAME, "sendCustomEmailFailed", undefined, err);
|
|
327
|
-
}
|
|
328
|
-
}
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
// Copyright 2024 IOTA Stiftung.
|
|
332
|
-
// SPDX-License-Identifier: Apache-2.0.
|
|
333
|
-
/**
|
|
334
|
-
* Class for connecting to the push notifications messaging operations of the Entity Storage.
|
|
335
|
-
*/
|
|
336
|
-
class EntityStorageMessagingPushNotificationConnector {
|
|
337
|
-
/**
|
|
338
|
-
* The namespace for the connector.
|
|
339
|
-
*/
|
|
340
|
-
static NAMESPACE = "entity-storage";
|
|
341
|
-
/**
|
|
342
|
-
* Runtime name for the class.
|
|
343
|
-
*/
|
|
344
|
-
static CLASS_NAME = "EntityStorageMessagingPushNotificationConnector";
|
|
345
|
-
/**
|
|
346
|
-
* The logging component.
|
|
347
|
-
* @internal
|
|
348
|
-
*/
|
|
349
|
-
_logging;
|
|
350
|
-
/**
|
|
351
|
-
* The entity storage for the push notifications device entries.
|
|
352
|
-
* @internal
|
|
353
|
-
*/
|
|
354
|
-
_messagingDeviceEntryStorage;
|
|
355
|
-
/**
|
|
356
|
-
* The entity storage for the push notifications message entries.
|
|
357
|
-
* @internal
|
|
358
|
-
*/
|
|
359
|
-
_messagingMessageEntryStorage;
|
|
360
|
-
/**
|
|
361
|
-
* Create a new instance of EntityStorageMessagingPushNotificationConnector.
|
|
362
|
-
* @param options The options for the connector.
|
|
363
|
-
*/
|
|
364
|
-
constructor(options) {
|
|
365
|
-
this._logging = ComponentFactory.getIfExists(options?.loggingComponentType ?? "logging");
|
|
366
|
-
this._messagingDeviceEntryStorage = EntityStorageConnectorFactory.get(options?.messagingDeviceEntryStorageConnectorType ?? "push-notification-device-entry");
|
|
367
|
-
this._messagingMessageEntryStorage = EntityStorageConnectorFactory.get(options?.messagingMessageEntryStorageConnectorType ?? "push-notification-message-entry");
|
|
368
|
-
}
|
|
369
|
-
/**
|
|
370
|
-
* Registers a device to an specific app in order to send notifications to it.
|
|
371
|
-
* @param applicationId The application address.
|
|
372
|
-
* @param deviceToken The device token.
|
|
373
|
-
* @returns If the device was registered successfully.
|
|
374
|
-
*/
|
|
375
|
-
async registerDevice(applicationId, deviceToken) {
|
|
376
|
-
Guards.stringValue(EntityStorageMessagingPushNotificationConnector.CLASS_NAME, "applicationId", applicationId);
|
|
377
|
-
Guards.stringValue(EntityStorageMessagingPushNotificationConnector.CLASS_NAME, "deviceToken", deviceToken);
|
|
378
|
-
try {
|
|
379
|
-
await this._logging?.log({
|
|
380
|
-
level: "info",
|
|
381
|
-
source: EntityStorageMessagingPushNotificationConnector.CLASS_NAME,
|
|
382
|
-
ts: Date.now(),
|
|
383
|
-
message: "deviceRegistering"
|
|
384
|
-
});
|
|
385
|
-
const id = Converter.bytesToHex(RandomHelper.generate(32));
|
|
386
|
-
const entity = {
|
|
387
|
-
id,
|
|
388
|
-
applicationId,
|
|
389
|
-
deviceToken,
|
|
390
|
-
ts: Date.now(),
|
|
391
|
-
status: "pending"
|
|
392
|
-
};
|
|
393
|
-
await this._messagingDeviceEntryStorage.set(entity);
|
|
394
|
-
return id;
|
|
395
|
-
}
|
|
396
|
-
catch (err) {
|
|
397
|
-
throw new GeneralError(EntityStorageMessagingPushNotificationConnector.CLASS_NAME, "deviceTokenRegisterFailed", { property: "applicationId", value: applicationId }, err);
|
|
398
|
-
}
|
|
399
|
-
}
|
|
400
|
-
/**
|
|
401
|
-
* Send a push notification to a device.
|
|
402
|
-
* @param deviceAddress The address of the device.
|
|
403
|
-
* @param title The title of the notification.
|
|
404
|
-
* @param message The message to send.
|
|
405
|
-
* @returns If the notification was sent successfully.
|
|
406
|
-
*/
|
|
407
|
-
async sendSinglePushNotification(deviceAddress, title, message) {
|
|
408
|
-
Guards.stringValue(EntityStorageMessagingPushNotificationConnector.CLASS_NAME, "deviceAddress", deviceAddress);
|
|
409
|
-
Guards.stringValue(EntityStorageMessagingPushNotificationConnector.CLASS_NAME, "title", title);
|
|
410
|
-
Guards.stringValue(EntityStorageMessagingPushNotificationConnector.CLASS_NAME, "message", message);
|
|
411
|
-
try {
|
|
412
|
-
await this._logging?.log({
|
|
413
|
-
level: "info",
|
|
414
|
-
source: EntityStorageMessagingPushNotificationConnector.CLASS_NAME,
|
|
415
|
-
ts: Date.now(),
|
|
416
|
-
message: "pushNotificationSending"
|
|
417
|
-
});
|
|
418
|
-
const id = Converter.bytesToHex(RandomHelper.generate(32));
|
|
419
|
-
const entity = {
|
|
420
|
-
id,
|
|
421
|
-
deviceAddress,
|
|
422
|
-
title,
|
|
423
|
-
message,
|
|
424
|
-
ts: Date.now(),
|
|
425
|
-
status: "pending"
|
|
426
|
-
};
|
|
427
|
-
await this._messagingMessageEntryStorage.set(entity);
|
|
428
|
-
return true;
|
|
429
|
-
}
|
|
430
|
-
catch (err) {
|
|
431
|
-
throw new GeneralError(EntityStorageMessagingPushNotificationConnector.CLASS_NAME, "sendPushNotificationFailed", { value: deviceAddress }, err);
|
|
432
|
-
}
|
|
433
|
-
}
|
|
434
|
-
}
|
|
435
|
-
|
|
436
|
-
// Copyright 2024 IOTA Stiftung.
|
|
437
|
-
// SPDX-License-Identifier: Apache-2.0.
|
|
438
|
-
/**
|
|
439
|
-
* Class for connecting to the SMS messaging operations of the Entity Storage.
|
|
440
|
-
*/
|
|
441
|
-
class EntityStorageMessagingSmsConnector {
|
|
442
|
-
/**
|
|
443
|
-
* The namespace for the connector.
|
|
444
|
-
*/
|
|
445
|
-
static NAMESPACE = "entity-storage";
|
|
446
|
-
/**
|
|
447
|
-
* Runtime name for the class.
|
|
448
|
-
*/
|
|
449
|
-
static CLASS_NAME = "EntityStorageMessagingSmsConnector";
|
|
450
|
-
/**
|
|
451
|
-
* The logging component.
|
|
452
|
-
* @internal
|
|
453
|
-
*/
|
|
454
|
-
_logging;
|
|
455
|
-
/**
|
|
456
|
-
* The entity storage for the sms entries.
|
|
457
|
-
* @internal
|
|
458
|
-
*/
|
|
459
|
-
_messagingSmsEntryStorage;
|
|
460
|
-
/**
|
|
461
|
-
* Create a new instance of EntityStorageMessagingSmsConnector.
|
|
462
|
-
* @param options The options for the connector.
|
|
463
|
-
*/
|
|
464
|
-
constructor(options) {
|
|
465
|
-
this._logging = ComponentFactory.getIfExists(options?.loggingComponentType ?? "logging");
|
|
466
|
-
this._messagingSmsEntryStorage = EntityStorageConnectorFactory.get(options?.messagingSmsEntryStorageConnectorType ?? "sms-entry");
|
|
467
|
-
}
|
|
468
|
-
/**
|
|
469
|
-
* Send a SMS message to a phone number.
|
|
470
|
-
* @param phoneNumber The recipient phone number.
|
|
471
|
-
* @param message The message to send.
|
|
472
|
-
* @returns If the SMS was sent successfully.
|
|
473
|
-
*/
|
|
474
|
-
async sendSMS(phoneNumber, message) {
|
|
475
|
-
Guards.stringValue(EntityStorageMessagingSmsConnector.CLASS_NAME, "phoneNumber", phoneNumber);
|
|
476
|
-
Guards.stringValue(EntityStorageMessagingSmsConnector.CLASS_NAME, "message", message);
|
|
477
|
-
try {
|
|
478
|
-
await this._logging?.log({
|
|
479
|
-
level: "info",
|
|
480
|
-
source: EntityStorageMessagingSmsConnector.CLASS_NAME,
|
|
481
|
-
ts: Date.now(),
|
|
482
|
-
message: "smsSending"
|
|
483
|
-
});
|
|
484
|
-
const id = Converter.bytesToHex(RandomHelper.generate(32));
|
|
485
|
-
const entity = {
|
|
486
|
-
id,
|
|
487
|
-
phoneNumber,
|
|
488
|
-
message,
|
|
489
|
-
ts: Date.now(),
|
|
490
|
-
status: "sent"
|
|
491
|
-
};
|
|
492
|
-
await this._messagingSmsEntryStorage.set(entity);
|
|
493
|
-
return true;
|
|
494
|
-
}
|
|
495
|
-
catch (err) {
|
|
496
|
-
throw new GeneralError(EntityStorageMessagingSmsConnector.CLASS_NAME, "sendSMSFailed", undefined, err);
|
|
497
|
-
}
|
|
498
|
-
}
|
|
499
|
-
}
|
|
500
|
-
|
|
501
|
-
// Copyright 2024 IOTA Stiftung.
|
|
502
|
-
// SPDX-License-Identifier: Apache-2.0.
|
|
503
|
-
/**
|
|
504
|
-
* Initialize the schema for the messaging connector entity storage.
|
|
505
|
-
* @param options The options for the initialisation.
|
|
506
|
-
* @param options.email Should we register email schemas.
|
|
507
|
-
* @param options.sms Should we register sms schemas.
|
|
508
|
-
* @param options.pushNotification Should we register push notification schemas.
|
|
509
|
-
*/
|
|
510
|
-
function initSchema(options) {
|
|
511
|
-
if (options?.email ?? true) {
|
|
512
|
-
EntitySchemaFactory.register("EmailEntry", () => EntitySchemaHelper.getSchema(EmailEntry));
|
|
513
|
-
}
|
|
514
|
-
if (options?.pushNotification ?? true) {
|
|
515
|
-
EntitySchemaFactory.register("PushNotificationDeviceEntry", () => EntitySchemaHelper.getSchema(PushNotificationDeviceEntry));
|
|
516
|
-
EntitySchemaFactory.register("PushNotificationMessageEntry", () => EntitySchemaHelper.getSchema(PushNotificationMessageEntry));
|
|
517
|
-
}
|
|
518
|
-
if (options?.sms ?? true) {
|
|
519
|
-
EntitySchemaFactory.register("SmsEntry", () => EntitySchemaHelper.getSchema(SmsEntry));
|
|
520
|
-
}
|
|
521
|
-
}
|
|
522
|
-
|
|
523
|
-
export { EmailEntry, EntityStorageMessagingEmailConnector, EntityStorageMessagingPushNotificationConnector, EntityStorageMessagingSmsConnector, PushNotificationDeviceEntry, PushNotificationMessageEntry, SmsEntry, initSchema };
|