@twin.org/messaging-service 0.0.1-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.
@@ -0,0 +1,403 @@
1
+ {
2
+ "openapi": "3.1.0",
3
+ "info": {
4
+ "title": "TWIN - Test Endpoints",
5
+ "description": "REST API for TWIN - Test Endpoints.",
6
+ "version": "1.0.0",
7
+ "license": {
8
+ "name": "Apache 2.0 License",
9
+ "url": "https://opensource.org/licenses/Apache-2.0"
10
+ }
11
+ },
12
+ "servers": [
13
+ {
14
+ "url": "https://localhost"
15
+ }
16
+ ],
17
+ "tags": [
18
+ {
19
+ "name": "Logging",
20
+ "description": "Endpoints which are modelled to access a logging contract."
21
+ }
22
+ ],
23
+ "paths": {
24
+ "/logging": {
25
+ "post": {
26
+ "operationId": "loggingEntryCreate",
27
+ "summary": "Create a log entry",
28
+ "tags": [
29
+ "Logging"
30
+ ],
31
+ "security": [
32
+ {
33
+ "jwtBearerAuthScheme": []
34
+ }
35
+ ],
36
+ "requestBody": {
37
+ "description": "Create a new log entry.",
38
+ "required": true,
39
+ "content": {
40
+ "application/json": {
41
+ "schema": {
42
+ "$ref": "#/components/schemas/LogEntry"
43
+ },
44
+ "examples": {
45
+ "loggingEntryCreateInfoExample": {
46
+ "value": {
47
+ "level": "info",
48
+ "message": "This is an information message",
49
+ "source": "source",
50
+ "ts": 1715252922273
51
+ }
52
+ },
53
+ "loggingEntryCreateErrorExample": {
54
+ "value": {
55
+ "level": "info",
56
+ "message": "This is an error message",
57
+ "source": "source",
58
+ "ts": 1715252922273,
59
+ "error": {
60
+ "name": "GeneralError",
61
+ "message": "component.error",
62
+ "properties": {
63
+ "foo": "bar"
64
+ }
65
+ }
66
+ }
67
+ }
68
+ }
69
+ }
70
+ }
71
+ },
72
+ "responses": {
73
+ "204": {
74
+ "description": "The rest request ended in success with no data."
75
+ },
76
+ "400": {
77
+ "description": "The server cannot process the request, see the content for more details.",
78
+ "content": {
79
+ "application/json": {
80
+ "schema": {
81
+ "$ref": "#/components/schemas/Error"
82
+ },
83
+ "examples": {
84
+ "exampleResponse": {
85
+ "value": {
86
+ "name": "GeneralError",
87
+ "message": "component.error",
88
+ "properties": {
89
+ "foo": "bar"
90
+ }
91
+ }
92
+ }
93
+ }
94
+ }
95
+ }
96
+ },
97
+ "401": {
98
+ "description": "You are not authorized to use the API or no credentials were supplied, see the content for more details.",
99
+ "content": {
100
+ "application/json": {
101
+ "schema": {
102
+ "$ref": "#/components/schemas/Error"
103
+ },
104
+ "examples": {
105
+ "exampleResponse": {
106
+ "value": {
107
+ "name": "UnauthorizedError",
108
+ "message": "component.error"
109
+ }
110
+ }
111
+ }
112
+ }
113
+ }
114
+ },
115
+ "500": {
116
+ "description": "The server has encountered a situation it does not know how to handle, see the content for more details.",
117
+ "content": {
118
+ "application/json": {
119
+ "schema": {
120
+ "$ref": "#/components/schemas/Error"
121
+ },
122
+ "examples": {
123
+ "exampleResponse": {
124
+ "value": {
125
+ "name": "InternalServerError",
126
+ "message": "component.error"
127
+ }
128
+ }
129
+ }
130
+ }
131
+ }
132
+ }
133
+ }
134
+ },
135
+ "get": {
136
+ "operationId": "loggingListEntries",
137
+ "summary": "Get a list of the log entries",
138
+ "tags": [
139
+ "Logging"
140
+ ],
141
+ "parameters": [
142
+ {
143
+ "name": "level",
144
+ "description": "The level of the log entries to retrieve.",
145
+ "in": "query",
146
+ "required": false,
147
+ "schema": {
148
+ "$ref": "#/components/schemas/LogLevel"
149
+ },
150
+ "example": "info"
151
+ },
152
+ {
153
+ "name": "source",
154
+ "description": "The source of the log entries to retrieve.",
155
+ "in": "query",
156
+ "required": false,
157
+ "schema": {
158
+ "type": "string"
159
+ }
160
+ },
161
+ {
162
+ "name": "timeStart",
163
+ "description": "The start time of the metrics to retrieve as a timestamp in ms.",
164
+ "in": "query",
165
+ "required": false,
166
+ "schema": {
167
+ "type": "number"
168
+ }
169
+ },
170
+ {
171
+ "name": "timeEnd",
172
+ "description": "The end time of the metrics to retrieve as a timestamp in ms.",
173
+ "in": "query",
174
+ "required": false,
175
+ "schema": {
176
+ "type": "number"
177
+ }
178
+ },
179
+ {
180
+ "name": "cursor",
181
+ "description": "The optional cursor to get next chunk.",
182
+ "in": "query",
183
+ "required": false,
184
+ "schema": {
185
+ "type": "string"
186
+ }
187
+ },
188
+ {
189
+ "name": "pageSize",
190
+ "description": "The maximum number of entities in a page.",
191
+ "in": "query",
192
+ "required": false,
193
+ "schema": {
194
+ "type": "number"
195
+ }
196
+ }
197
+ ],
198
+ "security": [
199
+ {
200
+ "jwtBearerAuthScheme": []
201
+ }
202
+ ],
203
+ "responses": {
204
+ "200": {
205
+ "description": "Response for log entry list request.",
206
+ "content": {
207
+ "application/json": {
208
+ "schema": {
209
+ "$ref": "#/components/schemas/LoggingListResponse"
210
+ },
211
+ "examples": {
212
+ "listResponseExample": {
213
+ "value": {
214
+ "entities": [
215
+ {
216
+ "level": "info",
217
+ "message": "This is an information message",
218
+ "source": "source",
219
+ "ts": 1715252922273
220
+ }
221
+ ],
222
+ "cursor": "1"
223
+ }
224
+ }
225
+ }
226
+ }
227
+ }
228
+ },
229
+ "400": {
230
+ "description": "The server cannot process the request, see the content for more details.",
231
+ "content": {
232
+ "application/json": {
233
+ "schema": {
234
+ "$ref": "#/components/schemas/Error"
235
+ },
236
+ "examples": {
237
+ "exampleResponse": {
238
+ "value": {
239
+ "name": "GeneralError",
240
+ "message": "component.error",
241
+ "properties": {
242
+ "foo": "bar"
243
+ }
244
+ }
245
+ }
246
+ }
247
+ }
248
+ }
249
+ },
250
+ "401": {
251
+ "description": "You are not authorized to use the API or no credentials were supplied, see the content for more details.",
252
+ "content": {
253
+ "application/json": {
254
+ "schema": {
255
+ "$ref": "#/components/schemas/Error"
256
+ },
257
+ "examples": {
258
+ "exampleResponse": {
259
+ "value": {
260
+ "name": "UnauthorizedError",
261
+ "message": "component.error"
262
+ }
263
+ }
264
+ }
265
+ }
266
+ }
267
+ },
268
+ "500": {
269
+ "description": "The server has encountered a situation it does not know how to handle, see the content for more details.",
270
+ "content": {
271
+ "application/json": {
272
+ "schema": {
273
+ "$ref": "#/components/schemas/Error"
274
+ },
275
+ "examples": {
276
+ "exampleResponse": {
277
+ "value": {
278
+ "name": "InternalServerError",
279
+ "message": "component.error"
280
+ }
281
+ }
282
+ }
283
+ }
284
+ }
285
+ }
286
+ }
287
+ }
288
+ }
289
+ },
290
+ "components": {
291
+ "schemas": {
292
+ "Error": {
293
+ "type": "object",
294
+ "properties": {
295
+ "name": {
296
+ "type": "string",
297
+ "description": "The name for the error."
298
+ },
299
+ "message": {
300
+ "type": "string",
301
+ "description": "The message for the error."
302
+ },
303
+ "source": {
304
+ "type": "string",
305
+ "description": "The source of the error."
306
+ },
307
+ "properties": {
308
+ "type": "object",
309
+ "additionalProperties": {},
310
+ "description": "Any additional information for the error."
311
+ },
312
+ "stack": {
313
+ "type": "string",
314
+ "description": "The stack trace for the error."
315
+ },
316
+ "inner": {
317
+ "$ref": "#/components/schemas/Error"
318
+ }
319
+ },
320
+ "required": [
321
+ "name",
322
+ "message"
323
+ ],
324
+ "additionalProperties": false,
325
+ "description": "Model to describe serialized error."
326
+ },
327
+ "LogEntry": {
328
+ "type": "object",
329
+ "properties": {
330
+ "level": {
331
+ "$ref": "#/components/schemas/LogLevel"
332
+ },
333
+ "source": {
334
+ "type": "string",
335
+ "description": "The source of the log entry."
336
+ },
337
+ "ts": {
338
+ "type": "number",
339
+ "description": "The timestamp of the log entry, if left blank will be populated by the connector."
340
+ },
341
+ "message": {
342
+ "type": "string",
343
+ "description": "The message."
344
+ },
345
+ "error": {
346
+ "$ref": "#/components/schemas/Error"
347
+ },
348
+ "data": {
349
+ "type": "object",
350
+ "additionalProperties": {},
351
+ "description": "Optional data for the message."
352
+ }
353
+ },
354
+ "required": [
355
+ "level",
356
+ "source",
357
+ "message"
358
+ ],
359
+ "additionalProperties": false,
360
+ "description": "Interface describing a log entry."
361
+ },
362
+ "LogLevel": {
363
+ "type": "string",
364
+ "enum": [
365
+ "info",
366
+ "error",
367
+ "warn",
368
+ "trace",
369
+ "debug"
370
+ ],
371
+ "description": "Log level."
372
+ },
373
+ "LoggingListResponse": {
374
+ "type": "object",
375
+ "properties": {
376
+ "entities": {
377
+ "type": "array",
378
+ "items": {
379
+ "$ref": "#/components/schemas/LogEntry"
380
+ },
381
+ "description": "The entities, which can be partial if a limited keys list was provided."
382
+ },
383
+ "cursor": {
384
+ "type": "string",
385
+ "description": "An optional cursor, when defined can be used to call find to get more entities."
386
+ }
387
+ },
388
+ "required": [
389
+ "entities"
390
+ ],
391
+ "additionalProperties": false,
392
+ "description": "The response payload."
393
+ }
394
+ },
395
+ "securitySchemes": {
396
+ "jwtBearerAuthScheme": {
397
+ "type": "http",
398
+ "scheme": "bearer",
399
+ "bearerFormat": "JWT"
400
+ }
401
+ }
402
+ }
403
+ }
@@ -0,0 +1,225 @@
1
+ # Class: MessagingService
2
+
3
+ Service for performing email messaging operations to a connector.
4
+
5
+ ## Implements
6
+
7
+ - `IMessagingComponent`
8
+
9
+ ## Constructors
10
+
11
+ ### new MessagingService()
12
+
13
+ > **new MessagingService**(`options`?): [`MessagingService`](MessagingService.md)
14
+
15
+ Create a new instance of MessagingService.
16
+
17
+ #### Parameters
18
+
19
+ • **options?**
20
+
21
+ The options for the connector.
22
+
23
+ • **options.messagingEmailConnectorType?**: `string`
24
+
25
+ The type of the email messaging connector to use, defaults to not configured.
26
+
27
+ • **options.messagingPushNotificationConnectorType?**: `string`
28
+
29
+ The type of the push notifications messaging connector to use, defaults to not configured.
30
+
31
+ • **options.messagingSmsConnectorType?**: `string`
32
+
33
+ The type of the sms messaging connector to use, defaults to not configured.
34
+
35
+ • **options.templateEntryStorageConnectorType?**: `string`
36
+
37
+ The type of the entity connector to use, defaults to "messaging-templates".
38
+
39
+ #### Returns
40
+
41
+ [`MessagingService`](MessagingService.md)
42
+
43
+ ## Properties
44
+
45
+ ### CLASS\_NAME
46
+
47
+ > `readonly` **CLASS\_NAME**: `string`
48
+
49
+ Runtime name for the class.
50
+
51
+ #### Implementation of
52
+
53
+ `IMessagingComponent.CLASS_NAME`
54
+
55
+ ## Methods
56
+
57
+ ### sendCustomEmail()
58
+
59
+ > **sendCustomEmail**(`sender`, `recipients`, `templateId`, `data`, `locale`): `Promise`\<`boolean`\>
60
+
61
+ Send a custom email.
62
+
63
+ #### Parameters
64
+
65
+ • **sender**: `string`
66
+
67
+ The sender email address.
68
+
69
+ • **recipients**: `string`[]
70
+
71
+ An array of recipients email addresses.
72
+
73
+ • **templateId**: `string`
74
+
75
+ The id of the email template.
76
+
77
+ • **data**
78
+
79
+ The data to populate the email template.
80
+
81
+ • **locale**: `string`
82
+
83
+ The locale of the email template.
84
+
85
+ #### Returns
86
+
87
+ `Promise`\<`boolean`\>
88
+
89
+ If the email was sent successfully.
90
+
91
+ #### Implementation of
92
+
93
+ `IMessagingComponent.sendCustomEmail`
94
+
95
+ ***
96
+
97
+ ### registerDevice()
98
+
99
+ > **registerDevice**(`applicationId`, `deviceToken`): `Promise`\<`string`\>
100
+
101
+ Registers a device to an specific app in order to send notifications to it.
102
+
103
+ #### Parameters
104
+
105
+ • **applicationId**: `string`
106
+
107
+ The application address.
108
+
109
+ • **deviceToken**: `string`
110
+
111
+ The device token.
112
+
113
+ #### Returns
114
+
115
+ `Promise`\<`string`\>
116
+
117
+ If the device was registered successfully.
118
+
119
+ #### Implementation of
120
+
121
+ `IMessagingComponent.registerDevice`
122
+
123
+ ***
124
+
125
+ ### sendSinglePushNotification()
126
+
127
+ > **sendSinglePushNotification**(`deviceAddress`, `templateId`, `data`, `locale`): `Promise`\<`boolean`\>
128
+
129
+ Send a push notification to a device.
130
+
131
+ #### Parameters
132
+
133
+ • **deviceAddress**: `string`
134
+
135
+ The address of the device.
136
+
137
+ • **templateId**: `string`
138
+
139
+ The id of the push notification template.
140
+
141
+ • **data**
142
+
143
+ The data to populate the push notification template.
144
+
145
+ • **locale**: `string`
146
+
147
+ The locale of the push notification template.
148
+
149
+ #### Returns
150
+
151
+ `Promise`\<`boolean`\>
152
+
153
+ If the notification was sent successfully.
154
+
155
+ #### Implementation of
156
+
157
+ `IMessagingComponent.sendSinglePushNotification`
158
+
159
+ ***
160
+
161
+ ### sendSMS()
162
+
163
+ > **sendSMS**(`phoneNumber`, `templateId`, `data`, `locale`): `Promise`\<`boolean`\>
164
+
165
+ Send a SMS message to a phone number.
166
+
167
+ #### Parameters
168
+
169
+ • **phoneNumber**: `string`
170
+
171
+ The recipient phone number.
172
+
173
+ • **templateId**: `string`
174
+
175
+ The id of the SMS template.
176
+
177
+ • **data**
178
+
179
+ The data to populate the SMS template.
180
+
181
+ • **locale**: `string`
182
+
183
+ The locale of the SMS template.
184
+
185
+ #### Returns
186
+
187
+ `Promise`\<`boolean`\>
188
+
189
+ If the SMS was sent successfully.
190
+
191
+ #### Implementation of
192
+
193
+ `IMessagingComponent.sendSMS`
194
+
195
+ ***
196
+
197
+ ### createOrUpdateTemplate()
198
+
199
+ > **createOrUpdateTemplate**(`templateId`, `locale`, `title`, `content`): `Promise`\<`boolean`\>
200
+
201
+ Create or update a template.
202
+
203
+ #### Parameters
204
+
205
+ • **templateId**: `string`
206
+
207
+ The id of the template.
208
+
209
+ • **locale**: `string`
210
+
211
+ The locale of the template.
212
+
213
+ • **title**: `string`
214
+
215
+ The title of the template.
216
+
217
+ • **content**: `string`
218
+
219
+ The content of the template.
220
+
221
+ #### Returns
222
+
223
+ `Promise`\<`boolean`\>
224
+
225
+ If the template was created or updated successfully.
@@ -0,0 +1,5 @@
1
+ # @twin.org/messaging-service
2
+
3
+ ## Classes
4
+
5
+ - [MessagingService](classes/MessagingService.md)
@@ -0,0 +1,13 @@
1
+ {
2
+ "info": {
3
+ "messagingService": {}
4
+ },
5
+ "error": {
6
+ "messagingService": {
7
+ "getTemplateFailed": "Failed to get template with id: \"{templateId}\" and locale: \"{locale}\"",
8
+ "notConfiguredEmailMessagingConnector": "Email messaging connector was not configured",
9
+ "notConfiguredPushNotificationMessagingConnector": "Push notification messaging connector was not configured",
10
+ "notConfiguredSmsMessagingConnector": "SMS messaging connector was not configured"
11
+ }
12
+ }
13
+ }
package/package.json ADDED
@@ -0,0 +1,42 @@
1
+ {
2
+ "name": "@twin.org/messaging-service",
3
+ "version": "0.0.1-next.2",
4
+ "description": "Messaging service implementation",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "git+https://github.com/twinfoundation/messaging.git",
8
+ "directory": "packages/messaging-service"
9
+ },
10
+ "author": "adrian.sanchez.sequeira@iota.org",
11
+ "license": "Apache-2.0",
12
+ "type": "module",
13
+ "engines": {
14
+ "node": ">=20.0.0"
15
+ },
16
+ "dependencies": {
17
+ "@twin.org/core": "next",
18
+ "@twin.org/entity": "next",
19
+ "@twin.org/entity-storage-models": "^0.0.1-next.2",
20
+ "@twin.org/logging-models": "next",
21
+ "@twin.org/messaging-models": "0.0.1-next.2",
22
+ "@twin.org/nameof": "next"
23
+ },
24
+ "main": "./dist/cjs/index.cjs",
25
+ "module": "./dist/esm/index.mjs",
26
+ "types": "./dist/types/index.d.ts",
27
+ "exports": {
28
+ ".": {
29
+ "require": "./dist/cjs/index.cjs",
30
+ "import": "./dist/esm/index.mjs",
31
+ "types": "./dist/types/index.d.ts"
32
+ },
33
+ "./locales": "./locales"
34
+ },
35
+ "files": [
36
+ "dist/cjs",
37
+ "dist/esm",
38
+ "dist/types",
39
+ "locales",
40
+ "docs"
41
+ ]
42
+ }