@twin.org/messaging-service 0.0.3-next.6 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,7 +2,7 @@
2
2
  // SPDX-License-Identifier: Apache-2.0.
3
3
  import { entity, property, SortDirection } from "@twin.org/entity";
4
4
  /**
5
- * Call defining a template message entry.
5
+ * Class defining a message template entry.
6
6
  */
7
7
  let TemplateEntry = class TemplateEntry {
8
8
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"templateEntry.js","sourceRoot":"","sources":["../../../src/entities/templateEntry.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAEnE;;GAEG;AAEI,IAAM,aAAa,GAAnB,MAAM,aAAa;IACzB;;OAEG;IAEI,EAAE,CAAU;IAEnB;;OAEG;IAEI,KAAK,CAAU;IAEtB;;OAEG;IAEI,OAAO,CAAU;IAExB;;OAEG;IAEI,WAAW,CAAU;CAC5B,CAAA;AAnBO;IADN,QAAQ,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;;yCAC3B;AAMZ;IADN,QAAQ,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC;;4CACP;AAMf;IADN,QAAQ,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC;;8CACL;AAMjB;IADN,QAAQ,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,WAAW,EAAE,aAAa,EAAE,aAAa,CAAC,UAAU,EAAE,CAAC;;kDAC/D;AAvBhB,aAAa;IADzB,MAAM,EAAE;GACI,aAAa,CAwBzB","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { entity, property, SortDirection } from \"@twin.org/entity\";\n\n/**\n * Call defining a template message entry.\n */\n@entity()\nexport class TemplateEntry {\n\t/**\n\t * The id.\n\t */\n\t@property({ type: \"string\", isPrimary: true })\n\tpublic id!: string;\n\n\t/**\n\t * The title.\n\t */\n\t@property({ type: \"string\" })\n\tpublic title!: string;\n\n\t/**\n\t * The content.\n\t */\n\t@property({ type: \"string\" })\n\tpublic content!: string;\n\n\t/**\n\t * The timestamp of the template entry.\n\t */\n\t@property({ type: \"string\", format: \"date-time\", sortDirection: SortDirection.Descending })\n\tpublic dateCreated!: string;\n}\n"]}
1
+ {"version":3,"file":"templateEntry.js","sourceRoot":"","sources":["../../../src/entities/templateEntry.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAEnE;;GAEG;AAEI,IAAM,aAAa,GAAnB,MAAM,aAAa;IACzB;;OAEG;IAEI,EAAE,CAAU;IAEnB;;OAEG;IAEI,KAAK,CAAU;IAEtB;;OAEG;IAEI,OAAO,CAAU;IAExB;;OAEG;IAEI,WAAW,CAAU;CAC5B,CAAA;AAnBO;IADN,QAAQ,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;;yCAC3B;AAMZ;IADN,QAAQ,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC;;4CACP;AAMf;IADN,QAAQ,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC;;8CACL;AAMjB;IADN,QAAQ,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,WAAW,EAAE,aAAa,EAAE,aAAa,CAAC,UAAU,EAAE,CAAC;;kDAC/D;AAvBhB,aAAa;IADzB,MAAM,EAAE;GACI,aAAa,CAwBzB","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { entity, property, SortDirection } from \"@twin.org/entity\";\n\n/**\n * Class defining a message template entry.\n */\n@entity()\nexport class TemplateEntry {\n\t/**\n\t * The id.\n\t */\n\t@property({ type: \"string\", isPrimary: true })\n\tpublic id!: string;\n\n\t/**\n\t * The title.\n\t */\n\t@property({ type: \"string\" })\n\tpublic title!: string;\n\n\t/**\n\t * The content.\n\t */\n\t@property({ type: \"string\" })\n\tpublic content!: string;\n\n\t/**\n\t * The timestamp of the template entry.\n\t */\n\t@property({ type: \"string\", format: \"date-time\", sortDirection: SortDirection.Descending })\n\tpublic dateCreated!: string;\n}\n"]}
@@ -4,7 +4,7 @@ import { GeneralError, Guards, Is } from "@twin.org/core";
4
4
  import { EntityStorageConnectorFactory } from "@twin.org/entity-storage-models";
5
5
  import { TemplateEntry } from "./entities/templateEntry.js";
6
6
  /**
7
- * Service for performing email messaging operations to a connector.
7
+ * Service for managing message templates stored via entity storage.
8
8
  */
9
9
  export class MessagingAdminService {
10
10
  /**
@@ -28,7 +28,7 @@ export class MessagingAdminService {
28
28
  _defaultLocale;
29
29
  /**
30
30
  * Create a new instance of MessagingAdminService.
31
- * @param options The options for the connector.
31
+ * @param options The options for the service.
32
32
  */
33
33
  constructor(options) {
34
34
  this._entityStorageConnector = EntityStorageConnectorFactory.get(options?.templateEntryStorageConnectorType ?? "template-entry");
@@ -47,7 +47,7 @@ export class MessagingAdminService {
47
47
  * @param locale The locale of the template.
48
48
  * @param title The title of the template.
49
49
  * @param content The content of the template.
50
- * @returns Nothing.
50
+ * @returns A promise that resolves when the template has been stored.
51
51
  */
52
52
  async setTemplate(templateId, locale, title, content) {
53
53
  Guards.stringValue(MessagingAdminService.CLASS_NAME, "templateId", templateId);
@@ -96,7 +96,7 @@ export class MessagingAdminService {
96
96
  * Remove a template.
97
97
  * @param templateId The id of the template.
98
98
  * @param locale The locale of the template.
99
- * @returns Nothing
99
+ * @returns A promise that resolves when the template has been removed.
100
100
  */
101
101
  async removeTemplate(templateId, locale) {
102
102
  Guards.stringValue(MessagingAdminService.CLASS_NAME, "templateId", templateId);
@@ -1 +1 @@
1
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gBAC7E,UAAU;gBACV,MAAM;aACN,CAAC,CAAC;QACJ,CAAC;QAED,OAAO,aAAa,CAAC;IACtB,CAAC;IAED;;;;;OAKG;IACI,KAAK,CAAC,cAAc,CAAC,UAAkB,EAAE,MAAc;QAC7D,MAAM,CAAC,WAAW,CAAC,qBAAqB,CAAC,UAAU,gBAAsB,UAAU,CAAC,CAAC;QACrF,MAAM,CAAC,WAAW,CAAC,qBAAqB,CAAC,UAAU,YAAkB,MAAM,CAAC,CAAC;QAE7E,OAAO,IAAI,CAAC,uBAAuB,CAAC,MAAM,CAAC,GAAG,UAAU,IAAI,MAAM,EAAE,CAAC,CAAC;IACvE,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { GeneralError, Guards, Is } from \"@twin.org/core\";\nimport {\n\tEntityStorageConnectorFactory,\n\ttype IEntityStorageConnector\n} from \"@twin.org/entity-storage-models\";\nimport type { IMessagingAdminComponent } from \"@twin.org/messaging-models\";\nimport { nameof } from \"@twin.org/nameof\";\nimport { TemplateEntry } from \"./entities/templateEntry.js\";\nimport type { IMessagingAdminServiceConstructorOptions } from \"./models/IMessagingAdminServiceConstructorOptions.js\";\n\n/**\n * Service for performing email messaging operations to a connector.\n */\nexport class MessagingAdminService implements IMessagingAdminComponent {\n\t/**\n\t * Runtime name for the class.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<MessagingAdminService>();\n\n\t/**\n\t * Default locale for the messaging service.\n\t * @internal\n\t */\n\tprivate static readonly _DEFAULT_LOCALE: string = \"en\";\n\n\t/**\n\t * Entity storage connector used by the service.\n\t * @internal\n\t */\n\tprivate readonly _entityStorageConnector: IEntityStorageConnector<TemplateEntry>;\n\n\t/**\n\t * The default locale to use for the messaging service.\n\t * @internal\n\t */\n\tprivate readonly _defaultLocale: string;\n\n\t/**\n\t * Create a new instance of MessagingAdminService.\n\t * @param options The options for the connector.\n\t */\n\tconstructor(options?: IMessagingAdminServiceConstructorOptions) {\n\t\tthis._entityStorageConnector = EntityStorageConnectorFactory.get(\n\t\t\toptions?.templateEntryStorageConnectorType ?? \"template-entry\"\n\t\t);\n\n\t\tthis._defaultLocale = options?.config?.defaultLocale ?? MessagingAdminService._DEFAULT_LOCALE;\n\t}\n\n\t/**\n\t * Returns the class name of the component.\n\t * @returns The class name of the component.\n\t */\n\tpublic className(): string {\n\t\treturn MessagingAdminService.CLASS_NAME;\n\t}\n\n\t/**\n\t * Create or update a template.\n\t * @param templateId The id of the template.\n\t * @param locale The locale of the template.\n\t * @param title The title of the template.\n\t * @param content The content of the template.\n\t * @returns Nothing.\n\t */\n\tpublic async setTemplate(\n\t\ttemplateId: string,\n\t\tlocale: string,\n\t\ttitle: string,\n\t\tcontent: string\n\t): Promise<void> {\n\t\tGuards.stringValue(MessagingAdminService.CLASS_NAME, nameof(templateId), templateId);\n\t\tGuards.stringValue(MessagingAdminService.CLASS_NAME, nameof(locale), locale);\n\t\tGuards.stringValue(MessagingAdminService.CLASS_NAME, nameof(title), title);\n\t\tGuards.stringValue(MessagingAdminService.CLASS_NAME, nameof(content), content);\n\n\t\tconst templateEntry = new TemplateEntry();\n\t\ttemplateEntry.id = `${templateId}:${locale}`;\n\t\ttemplateEntry.dateCreated = new Date(Date.now()).toISOString();\n\t\ttemplateEntry.title = title;\n\t\ttemplateEntry.content = content;\n\n\t\tawait this._entityStorageConnector.set(templateEntry);\n\t}\n\n\t/**\n\t * Get the email template by id and locale.\n\t * @param templateId The id of the email template.\n\t * @param locale The locale of the email template.\n\t * @returns The email template.\n\t */\n\tpublic async getTemplate(\n\t\ttemplateId: string,\n\t\tlocale: string\n\t): Promise<{ title: string; content: string }> {\n\t\tGuards.stringValue(MessagingAdminService.CLASS_NAME, nameof(templateId), templateId);\n\t\tGuards.stringValue(MessagingAdminService.CLASS_NAME, nameof(locale), locale);\n\n\t\tlet templateEntry;\n\n\t\ttry {\n\t\t\t// First try to get the template for the requested locale\n\t\t\ttemplateEntry = await this._entityStorageConnector.get(`${templateId}:${locale}`);\n\t\t} catch {}\n\n\t\t// If the template is not found for the requested locale, try to get it for the default locale\n\t\t// only if the requested locale is different from the default locale\n\t\tif (Is.empty(templateEntry) && this._defaultLocale !== locale) {\n\t\t\ttry {\n\t\t\t\ttemplateEntry = await this._entityStorageConnector.get(\n\t\t\t\t\t`${templateId}:${this._defaultLocale}`\n\t\t\t\t);\n\t\t\t} catch {}\n\t\t}\n\n\t\tif (Is.empty(templateEntry)) {\n\t\t\tthrow new GeneralError(MessagingAdminService.CLASS_NAME, \"getTemplateFailed\", {\n\t\t\t\ttemplateId,\n\t\t\t\tlocale\n\t\t\t});\n\t\t}\n\n\t\treturn templateEntry;\n\t}\n\n\t/**\n\t * Remove a template.\n\t * @param templateId The id of the template.\n\t * @param locale The locale of the template.\n\t * @returns Nothing\n\t */\n\tpublic async removeTemplate(templateId: string, locale: string): Promise<void> {\n\t\tGuards.stringValue(MessagingAdminService.CLASS_NAME, nameof(templateId), templateId);\n\t\tGuards.stringValue(MessagingAdminService.CLASS_NAME, nameof(locale), locale);\n\n\t\treturn this._entityStorageConnector.remove(`${templateId}:${locale}`);\n\t}\n}\n"]}
1
+ {"version":3,"file":"messagingAdminService.js","sourceRoot":"","sources":["../../src/messagingAdminService.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,YAAY,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,gBAAgB,CAAC;AAC1D,OAAO,EACN,6BAA6B,EAE7B,MAAM,iCAAiC,CAAC;AAGzC,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAG5D;;GAEG;AACH,MAAM,OAAO,qBAAqB;IACjC;;OAEG;IACI,MAAM,CAAU,UAAU,2BAA2C;IAE5E;;;OAGG;IACK,MAAM,CAAU,eAAe,GAAW,IAAI,CAAC;IAEvD;;;OAGG;IACc,uBAAuB,CAAyC;IAEjF;;;OAGG;IACc,cAAc,CAAS;IAExC;;;OAGG;IAC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";\nimport {\n\tEntityStorageConnectorFactory,\n\ttype IEntityStorageConnector\n} from \"@twin.org/entity-storage-models\";\nimport type { IMessagingAdminComponent } from \"@twin.org/messaging-models\";\nimport { nameof } from \"@twin.org/nameof\";\nimport { TemplateEntry } from \"./entities/templateEntry.js\";\nimport type { IMessagingAdminServiceConstructorOptions } from \"./models/IMessagingAdminServiceConstructorOptions.js\";\n\n/**\n * Service for managing message templates stored via entity storage.\n */\nexport class MessagingAdminService implements IMessagingAdminComponent {\n\t/**\n\t * Runtime name for the class.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<MessagingAdminService>();\n\n\t/**\n\t * Default locale for the messaging service.\n\t * @internal\n\t */\n\tprivate static readonly _DEFAULT_LOCALE: string = \"en\";\n\n\t/**\n\t * Entity storage connector used by the service.\n\t * @internal\n\t */\n\tprivate readonly _entityStorageConnector: IEntityStorageConnector<TemplateEntry>;\n\n\t/**\n\t * The default locale to use for the messaging service.\n\t * @internal\n\t */\n\tprivate readonly _defaultLocale: string;\n\n\t/**\n\t * Create a new instance of MessagingAdminService.\n\t * @param options The options for the service.\n\t */\n\tconstructor(options?: IMessagingAdminServiceConstructorOptions) {\n\t\tthis._entityStorageConnector = EntityStorageConnectorFactory.get(\n\t\t\toptions?.templateEntryStorageConnectorType ?? \"template-entry\"\n\t\t);\n\n\t\tthis._defaultLocale = options?.config?.defaultLocale ?? MessagingAdminService._DEFAULT_LOCALE;\n\t}\n\n\t/**\n\t * Returns the class name of the component.\n\t * @returns The class name of the component.\n\t */\n\tpublic className(): string {\n\t\treturn MessagingAdminService.CLASS_NAME;\n\t}\n\n\t/**\n\t * Create or update a template.\n\t * @param templateId The id of the template.\n\t * @param locale The locale of the template.\n\t * @param title The title of the template.\n\t * @param content The content of the template.\n\t * @returns A promise that resolves when the template has been stored.\n\t */\n\tpublic async setTemplate(\n\t\ttemplateId: string,\n\t\tlocale: string,\n\t\ttitle: string,\n\t\tcontent: string\n\t): Promise<void> {\n\t\tGuards.stringValue(MessagingAdminService.CLASS_NAME, nameof(templateId), templateId);\n\t\tGuards.stringValue(MessagingAdminService.CLASS_NAME, nameof(locale), locale);\n\t\tGuards.stringValue(MessagingAdminService.CLASS_NAME, nameof(title), title);\n\t\tGuards.stringValue(MessagingAdminService.CLASS_NAME, nameof(content), content);\n\n\t\tconst templateEntry = new TemplateEntry();\n\t\ttemplateEntry.id = `${templateId}:${locale}`;\n\t\ttemplateEntry.dateCreated = new Date(Date.now()).toISOString();\n\t\ttemplateEntry.title = title;\n\t\ttemplateEntry.content = content;\n\n\t\tawait this._entityStorageConnector.set(templateEntry);\n\t}\n\n\t/**\n\t * Get the email template by id and locale.\n\t * @param templateId The id of the email template.\n\t * @param locale The locale of the email template.\n\t * @returns The email template.\n\t */\n\tpublic async getTemplate(\n\t\ttemplateId: string,\n\t\tlocale: string\n\t): Promise<{ title: string; content: string }> {\n\t\tGuards.stringValue(MessagingAdminService.CLASS_NAME, nameof(templateId), templateId);\n\t\tGuards.stringValue(MessagingAdminService.CLASS_NAME, nameof(locale), locale);\n\n\t\tlet templateEntry;\n\n\t\ttry {\n\t\t\t// First try to get the template for the requested locale\n\t\t\ttemplateEntry = await this._entityStorageConnector.get(`${templateId}:${locale}`);\n\t\t} catch {}\n\n\t\t// If the template is not found for the requested locale, try to get it for the default locale\n\t\t// only if the requested locale is different from the default locale\n\t\tif (Is.empty(templateEntry) && this._defaultLocale !== locale) {\n\t\t\ttry {\n\t\t\t\ttemplateEntry = await this._entityStorageConnector.get(\n\t\t\t\t\t`${templateId}:${this._defaultLocale}`\n\t\t\t\t);\n\t\t\t} catch {}\n\t\t}\n\n\t\tif (Is.empty(templateEntry)) {\n\t\t\tthrow new GeneralError(MessagingAdminService.CLASS_NAME, \"getTemplateFailed\", {\n\t\t\t\ttemplateId,\n\t\t\t\tlocale\n\t\t\t});\n\t\t}\n\n\t\treturn templateEntry;\n\t}\n\n\t/**\n\t * Remove a template.\n\t * @param templateId The id of the template.\n\t * @param locale The locale of the template.\n\t * @returns A promise that resolves when the template has been removed.\n\t */\n\tpublic async removeTemplate(templateId: string, locale: string): Promise<void> {\n\t\tGuards.stringValue(MessagingAdminService.CLASS_NAME, nameof(templateId), templateId);\n\t\tGuards.stringValue(MessagingAdminService.CLASS_NAME, nameof(locale), locale);\n\n\t\treturn this._entityStorageConnector.remove(`${templateId}:${locale}`);\n\t}\n}\n"]}
@@ -3,7 +3,7 @@
3
3
  import { ComponentFactory, GeneralError, Guards, Is } from "@twin.org/core";
4
4
  import { MessagingEmailConnectorFactory, MessagingPushNotificationsConnectorFactory, MessagingSmsConnectorFactory } from "@twin.org/messaging-models";
5
5
  /**
6
- * Service for performing email messaging operations to a connector.
6
+ * Service for dispatching messages via configured email, push notification, and SMS connectors.
7
7
  */
8
8
  export class MessagingService {
9
9
  /**
@@ -32,7 +32,7 @@ export class MessagingService {
32
32
  _messagingAdminComponent;
33
33
  /**
34
34
  * Create a new instance of MessagingService.
35
- * @param options The options for the connector.
35
+ * @param options The options for the service.
36
36
  */
37
37
  constructor(options) {
38
38
  if (Is.stringValue(options?.messagingEmailConnectorType)) {
@@ -60,7 +60,7 @@ export class MessagingService {
60
60
  * @param templateId The id of the email template.
61
61
  * @param data The data to populate the email template.
62
62
  * @param locale The locale of the email template.
63
- * @returns If the email was sent successfully.
63
+ * @returns True if the email was sent successfully.
64
64
  */
65
65
  async sendCustomEmail(sender, recipients, templateId, data, locale) {
66
66
  if (Is.empty(this._emailMessagingConnector)) {
@@ -76,10 +76,10 @@ export class MessagingService {
76
76
  return this._emailMessagingConnector.sendCustomEmail(sender, recipients, populatedTemplate.title, populatedTemplate.content);
77
77
  }
78
78
  /**
79
- * Registers a device to an specific app in order to send notifications to it.
79
+ * Registers a device to a specific application in order to send notifications to it.
80
80
  * @param applicationId The application address.
81
81
  * @param deviceToken The device token.
82
- * @returns If the device was registered successfully.
82
+ * @returns The address assigned to the registered device.
83
83
  */
84
84
  async registerDevice(applicationId, deviceToken) {
85
85
  if (Is.empty(this._pushNotificationMessagingConnector)) {
@@ -95,7 +95,7 @@ export class MessagingService {
95
95
  * @param templateId The id of the push notification template.
96
96
  * @param data The data to populate the push notification template.
97
97
  * @param locale The locale of the push notification template.
98
- * @returns If the notification was sent successfully.
98
+ * @returns True if the notification was sent successfully.
99
99
  */
100
100
  async sendSinglePushNotification(deviceAddress, templateId, data, locale) {
101
101
  if (Is.empty(this._pushNotificationMessagingConnector)) {
@@ -115,7 +115,7 @@ export class MessagingService {
115
115
  * @param templateId The id of the SMS template.
116
116
  * @param data The data to populate the SMS template.
117
117
  * @param locale The locale of the SMS template.
118
- * @returns If the SMS was sent successfully.
118
+ * @returns True if the SMS was sent successfully.
119
119
  */
120
120
  async sendSMS(phoneNumber, templateId, data, locale) {
121
121
  if (Is.empty(this._smsMessagingConnector)) {
@@ -130,13 +130,13 @@ export class MessagingService {
130
130
  return this._smsMessagingConnector.sendSMS(phoneNumber, populatedTemplate.content);
131
131
  }
132
132
  /**
133
- * Populate the template with data.
133
+ * Populates a template by replacing placeholders with the provided data values.
134
134
  * @param template The template.
135
135
  * @param template.title The title of the template.
136
136
  * @param template.content The content of the template.
137
137
  * @param data The data to populate the template.
138
+ * @returns The template with all placeholders replaced.
138
139
  * @internal
139
- * @returns The populated template.
140
140
  */
141
141
  populateTemplate(template, data) {
142
142
  let populatedTitle = template.title;
@@ -1 +1 @@
1
- {"version":3,"file":"messagingService.js","sourceRoot":"","sources":["../../src/messagingService.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,gBAAgB,CAAC;AAC5E,OAAO,EAEN,8BAA8B,EAC9B,0CAA0C,EAC1C,4BAA4B,EAK5B,MAAM,4BAA4B,CAAC;AAIpC;;GAEG;AACH,MAAM,OAAO,gBAAgB;IAC5B;;OAEG;IACI,MAAM,CAAU,UAAU,sBAAsC;IAEvE;;;OAGG;IACc,wBAAwB,CAA4B;I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D,MAAM,CAAC,WAAW,CAAC,gBAAgB,CAAC,UAAU,YAAkB,MAAM,CAAC,CAAC;QAExE,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,wBAAwB,CAAC,WAAW,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC;QACrF,MAAM,iBAAiB,GAAG,IAAI,CAAC,gBAAgB,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;QAEhE,OAAO,IAAI,CAAC,sBAAsB,CAAC,OAAO,CAAC,WAAW,EAAE,iBAAiB,CAAC,OAAO,CAAC,CAAC;IACpF,CAAC;IAED;;;;;;;;OAQG;IACK,gBAAgB,CACvB,QAA4C,EAC5C,IAA+B;QAE/B,IAAI,cAAc,GAAG,QAAQ,CAAC,KAAK,CAAC;QACpC,IAAI,gBAAgB,GAAG,QAAQ,CAAC,OAAO,CAAC;QAExC,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;YACxB,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC;YACxB,MAAM,WAAW,GAAG,KAAK,GAAG,IAAI,CAAC;YACjC,cAAc,GAAG,cAAc,CAAC,OAAO,CAAC,IAAI,MAAM,CAAC,WAAW,EAAE,GAAG,CAAC,EAAE,KAAK,CAAC,CAAC;YAC7E,gBAAgB,GAAG,gBAAgB,CAAC,OAAO,CAAC,IAAI,MAAM,CAAC,WAAW,EAAE,GAAG,CAAC,EAAE,KAAK,CAAC,CAAC;QAClF,CAAC;QAED,OAAO;YACN,KAAK,EAAE,cAAc;YACrB,OAAO,EAAE,gBAAgB;SACzB,CAAC;IACH,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { ComponentFactory, GeneralError, Guards, Is } from \"@twin.org/core\";\nimport {\n\ttype IMessagingAdminComponent,\n\tMessagingEmailConnectorFactory,\n\tMessagingPushNotificationsConnectorFactory,\n\tMessagingSmsConnectorFactory,\n\ttype IMessagingComponent,\n\ttype IMessagingEmailConnector,\n\ttype IMessagingPushNotificationsConnector,\n\ttype IMessagingSmsConnector\n} from \"@twin.org/messaging-models\";\nimport { nameof } from \"@twin.org/nameof\";\nimport type { IMessagingServiceConstructorOptions } from \"./models/IMessagingServiceConstructorOptions.js\";\n\n/**\n * Service for performing email messaging operations to a connector.\n */\nexport class MessagingService implements IMessagingComponent {\n\t/**\n\t * Runtime name for the class.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<MessagingService>();\n\n\t/**\n\t * Emails messaging connector used by the service.\n\t * @internal\n\t */\n\tprivate readonly _emailMessagingConnector?: IMessagingEmailConnector;\n\n\t/**\n\t * Push notifications messaging connector used by the service.\n\t * @internal\n\t */\n\tprivate readonly _pushNotificationMessagingConnector?: IMessagingPushNotificationsConnector;\n\n\t/**\n\t * SMS messaging connector used by the service.\n\t * @internal\n\t */\n\tprivate readonly _smsMessagingConnector?: IMessagingSmsConnector;\n\n\t/**\n\t * The admin component for the messaging.\n\t * @internal\n\t */\n\tprivate readonly _messagingAdminComponent: IMessagingAdminComponent;\n\n\t/**\n\t * Create a new instance of MessagingService.\n\t * @param options The options for the connector.\n\t */\n\tconstructor(options?: IMessagingServiceConstructorOptions) {\n\t\tif (Is.stringValue(options?.messagingEmailConnectorType)) {\n\t\t\tthis._emailMessagingConnector = MessagingEmailConnectorFactory.get(\n\t\t\t\toptions.messagingEmailConnectorType\n\t\t\t);\n\t\t}\n\n\t\tif (Is.stringValue(options?.messagingPushNotificationConnectorType)) {\n\t\t\tthis._pushNotificationMessagingConnector = MessagingPushNotificationsConnectorFactory.get(\n\t\t\t\toptions.messagingPushNotificationConnectorType\n\t\t\t);\n\t\t}\n\n\t\tif (Is.stringValue(options?.messagingSmsConnectorType)) {\n\t\t\tthis._smsMessagingConnector = MessagingSmsConnectorFactory.get(\n\t\t\t\toptions.messagingSmsConnectorType\n\t\t\t);\n\t\t}\n\n\t\tthis._messagingAdminComponent = ComponentFactory.get(\n\t\t\toptions?.messagingAdminComponentType ?? \"messaging-admin\"\n\t\t);\n\t}\n\n\t/**\n\t * Returns the class name of the component.\n\t * @returns The class name of the component.\n\t */\n\tpublic className(): string {\n\t\treturn MessagingService.CLASS_NAME;\n\t}\n\n\t/**\n\t * Send a custom email.\n\t * @param sender The sender email address.\n\t * @param recipients An array of recipients email addresses.\n\t * @param templateId The id of the email template.\n\t * @param data The data to populate the email template.\n\t * @param locale The locale of the email template.\n\t * @returns If the email was sent successfully.\n\t */\n\tpublic async sendCustomEmail(\n\t\tsender: string,\n\t\trecipients: string[],\n\t\ttemplateId: string,\n\t\tdata: { [key: string]: string },\n\t\tlocale: string\n\t): Promise<boolean> {\n\t\tif (Is.empty(this._emailMessagingConnector)) {\n\t\t\tthrow new GeneralError(MessagingService.CLASS_NAME, \"notConfiguredEmailMessagingConnector\");\n\t\t}\n\n\t\tGuards.stringValue(MessagingService.CLASS_NAME, nameof(sender), sender);\n\t\tGuards.arrayValue(MessagingService.CLASS_NAME, nameof(recipients), recipients);\n\t\tGuards.stringValue(MessagingService.CLASS_NAME, nameof(templateId), templateId);\n\t\tGuards.object(MessagingService.CLASS_NAME, nameof(data), data);\n\t\tGuards.stringValue(MessagingService.CLASS_NAME, nameof(locale), locale);\n\n\t\tconst template = await this._messagingAdminComponent.getTemplate(templateId, locale);\n\t\tconst populatedTemplate = this.populateTemplate(template, data);\n\n\t\treturn this._emailMessagingConnector.sendCustomEmail(\n\t\t\tsender,\n\t\t\trecipients,\n\t\t\tpopulatedTemplate.title,\n\t\t\tpopulatedTemplate.content\n\t\t);\n\t}\n\n\t/**\n\t * Registers a device to an specific app in order to send notifications to it.\n\t * @param applicationId The application address.\n\t * @param deviceToken The device token.\n\t * @returns If the device was registered successfully.\n\t */\n\tpublic async registerDevice(applicationId: string, deviceToken: string): Promise<string> {\n\t\tif (Is.empty(this._pushNotificationMessagingConnector)) {\n\t\t\tthrow new GeneralError(\n\t\t\t\tMessagingService.CLASS_NAME,\n\t\t\t\t\"notConfiguredPushNotificationMessagingConnector\"\n\t\t\t);\n\t\t}\n\n\t\tGuards.stringValue(MessagingService.CLASS_NAME, nameof(applicationId), applicationId);\n\t\tGuards.stringValue(MessagingService.CLASS_NAME, nameof(deviceToken), deviceToken);\n\n\t\treturn this._pushNotificationMessagingConnector.registerDevice(applicationId, deviceToken);\n\t}\n\n\t/**\n\t * Send a push notification to a device.\n\t * @param deviceAddress The address of the device.\n\t * @param templateId The id of the push notification template.\n\t * @param data The data to populate the push notification template.\n\t * @param locale The locale of the push notification template.\n\t * @returns If the notification was sent successfully.\n\t */\n\tpublic async sendSinglePushNotification(\n\t\tdeviceAddress: string,\n\t\ttemplateId: string,\n\t\tdata: { [key: string]: string },\n\t\tlocale: string\n\t): Promise<boolean> {\n\t\tif (Is.empty(this._pushNotificationMessagingConnector)) {\n\t\t\tthrow new GeneralError(\n\t\t\t\tMessagingService.CLASS_NAME,\n\t\t\t\t\"notConfiguredPushNotificationMessagingConnector\"\n\t\t\t);\n\t\t}\n\n\t\tGuards.stringValue(MessagingService.CLASS_NAME, nameof(deviceAddress), deviceAddress);\n\t\tGuards.stringValue(MessagingService.CLASS_NAME, nameof(templateId), templateId);\n\t\tGuards.object(MessagingService.CLASS_NAME, nameof(data), data);\n\t\tGuards.stringValue(MessagingService.CLASS_NAME, nameof(locale), locale);\n\n\t\tconst template = await this._messagingAdminComponent.getTemplate(templateId, locale);\n\t\tconst populatedTemplate = this.populateTemplate(template, data);\n\n\t\treturn this._pushNotificationMessagingConnector.sendSinglePushNotification(\n\t\t\tdeviceAddress,\n\t\t\tpopulatedTemplate.title,\n\t\t\tpopulatedTemplate.content\n\t\t);\n\t}\n\n\t/**\n\t * Send a SMS message to a phone number.\n\t * @param phoneNumber The recipient phone number.\n\t * @param templateId The id of the SMS template.\n\t * @param data The data to populate the SMS template.\n\t * @param locale The locale of the SMS template.\n\t * @returns If the SMS was sent successfully.\n\t */\n\tpublic async sendSMS(\n\t\tphoneNumber: string,\n\t\ttemplateId: string,\n\t\tdata: { [key: string]: string },\n\t\tlocale: string\n\t): Promise<boolean> {\n\t\tif (Is.empty(this._smsMessagingConnector)) {\n\t\t\tthrow new GeneralError(MessagingService.CLASS_NAME, \"notConfiguredSmsMessagingConnector\");\n\t\t}\n\n\t\tGuards.stringValue(MessagingService.CLASS_NAME, nameof(phoneNumber), phoneNumber);\n\t\tGuards.stringValue(MessagingService.CLASS_NAME, nameof(templateId), templateId);\n\t\tGuards.object(MessagingService.CLASS_NAME, nameof(data), data);\n\t\tGuards.stringValue(MessagingService.CLASS_NAME, nameof(locale), locale);\n\n\t\tconst template = await this._messagingAdminComponent.getTemplate(templateId, locale);\n\t\tconst populatedTemplate = this.populateTemplate(template, data);\n\n\t\treturn this._smsMessagingConnector.sendSMS(phoneNumber, populatedTemplate.content);\n\t}\n\n\t/**\n\t * Populate the template with data.\n\t * @param template The template.\n\t * @param template.title The title of the template.\n\t * @param template.content The content of the template.\n\t * @param data The data to populate the template.\n\t * @internal\n\t * @returns The populated template.\n\t */\n\tprivate populateTemplate(\n\t\ttemplate: { title: string; content: string },\n\t\tdata: { [key: string]: string }\n\t): { title: string; content: string } {\n\t\tlet populatedTitle = template.title;\n\t\tlet populatedContent = template.content;\n\n\t\tfor (const key in data) {\n\t\t\tconst value = data[key];\n\t\t\tconst placeholder = `{{${key}}}`;\n\t\t\tpopulatedTitle = populatedTitle.replace(new RegExp(placeholder, \"g\"), value);\n\t\t\tpopulatedContent = populatedContent.replace(new RegExp(placeholder, \"g\"), value);\n\t\t}\n\n\t\treturn {\n\t\t\ttitle: populatedTitle,\n\t\t\tcontent: populatedContent\n\t\t};\n\t}\n}\n"]}
1
+ {"version":3,"file":"messagingService.js","sourceRoot":"","sources":["../../src/messagingService.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,gBAAgB,CAAC;AAC5E,OAAO,EAEN,8BAA8B,EAC9B,0CAA0C,EA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ory, GeneralError, Guards, Is } from \"@twin.org/core\";\nimport {\n\ttype IMessagingAdminComponent,\n\tMessagingEmailConnectorFactory,\n\tMessagingPushNotificationsConnectorFactory,\n\tMessagingSmsConnectorFactory,\n\ttype IMessagingComponent,\n\ttype IMessagingEmailConnector,\n\ttype IMessagingPushNotificationsConnector,\n\ttype IMessagingSmsConnector\n} from \"@twin.org/messaging-models\";\nimport { nameof } from \"@twin.org/nameof\";\nimport type { IMessagingServiceConstructorOptions } from \"./models/IMessagingServiceConstructorOptions.js\";\n\n/**\n * Service for dispatching messages via configured email, push notification, and SMS connectors.\n */\nexport class MessagingService implements IMessagingComponent {\n\t/**\n\t * Runtime name for the class.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<MessagingService>();\n\n\t/**\n\t * Emails messaging connector used by the service.\n\t * @internal\n\t */\n\tprivate readonly _emailMessagingConnector?: IMessagingEmailConnector;\n\n\t/**\n\t * Push notifications messaging connector used by the service.\n\t * @internal\n\t */\n\tprivate readonly _pushNotificationMessagingConnector?: IMessagingPushNotificationsConnector;\n\n\t/**\n\t * SMS messaging connector used by the service.\n\t * @internal\n\t */\n\tprivate readonly _smsMessagingConnector?: IMessagingSmsConnector;\n\n\t/**\n\t * The admin component for the messaging.\n\t * @internal\n\t */\n\tprivate readonly _messagingAdminComponent: IMessagingAdminComponent;\n\n\t/**\n\t * Create a new instance of MessagingService.\n\t * @param options The options for the service.\n\t */\n\tconstructor(options?: IMessagingServiceConstructorOptions) {\n\t\tif (Is.stringValue(options?.messagingEmailConnectorType)) {\n\t\t\tthis._emailMessagingConnector = MessagingEmailConnectorFactory.get(\n\t\t\t\toptions.messagingEmailConnectorType\n\t\t\t);\n\t\t}\n\n\t\tif (Is.stringValue(options?.messagingPushNotificationConnectorType)) {\n\t\t\tthis._pushNotificationMessagingConnector = MessagingPushNotificationsConnectorFactory.get(\n\t\t\t\toptions.messagingPushNotificationConnectorType\n\t\t\t);\n\t\t}\n\n\t\tif (Is.stringValue(options?.messagingSmsConnectorType)) {\n\t\t\tthis._smsMessagingConnector = MessagingSmsConnectorFactory.get(\n\t\t\t\toptions.messagingSmsConnectorType\n\t\t\t);\n\t\t}\n\n\t\tthis._messagingAdminComponent = ComponentFactory.get(\n\t\t\toptions?.messagingAdminComponentType ?? \"messaging-admin\"\n\t\t);\n\t}\n\n\t/**\n\t * Returns the class name of the component.\n\t * @returns The class name of the component.\n\t */\n\tpublic className(): string {\n\t\treturn MessagingService.CLASS_NAME;\n\t}\n\n\t/**\n\t * Send a custom email.\n\t * @param sender The sender email address.\n\t * @param recipients An array of recipients email addresses.\n\t * @param templateId The id of the email template.\n\t * @param data The data to populate the email template.\n\t * @param locale The locale of the email template.\n\t * @returns True if the email was sent successfully.\n\t */\n\tpublic async sendCustomEmail(\n\t\tsender: string,\n\t\trecipients: string[],\n\t\ttemplateId: string,\n\t\tdata: { [key: string]: string },\n\t\tlocale: string\n\t): Promise<boolean> {\n\t\tif (Is.empty(this._emailMessagingConnector)) {\n\t\t\tthrow new GeneralError(MessagingService.CLASS_NAME, \"notConfiguredEmailMessagingConnector\");\n\t\t}\n\n\t\tGuards.stringValue(MessagingService.CLASS_NAME, nameof(sender), sender);\n\t\tGuards.arrayValue(MessagingService.CLASS_NAME, nameof(recipients), recipients);\n\t\tGuards.stringValue(MessagingService.CLASS_NAME, nameof(templateId), templateId);\n\t\tGuards.object(MessagingService.CLASS_NAME, nameof(data), data);\n\t\tGuards.stringValue(MessagingService.CLASS_NAME, nameof(locale), locale);\n\n\t\tconst template = await this._messagingAdminComponent.getTemplate(templateId, locale);\n\t\tconst populatedTemplate = this.populateTemplate(template, data);\n\n\t\treturn this._emailMessagingConnector.sendCustomEmail(\n\t\t\tsender,\n\t\t\trecipients,\n\t\t\tpopulatedTemplate.title,\n\t\t\tpopulatedTemplate.content\n\t\t);\n\t}\n\n\t/**\n\t * Registers a device to a specific application in order to send notifications to it.\n\t * @param applicationId The application address.\n\t * @param deviceToken The device token.\n\t * @returns The address assigned to the registered device.\n\t */\n\tpublic async registerDevice(applicationId: string, deviceToken: string): Promise<string> {\n\t\tif (Is.empty(this._pushNotificationMessagingConnector)) {\n\t\t\tthrow new GeneralError(\n\t\t\t\tMessagingService.CLASS_NAME,\n\t\t\t\t\"notConfiguredPushNotificationMessagingConnector\"\n\t\t\t);\n\t\t}\n\n\t\tGuards.stringValue(MessagingService.CLASS_NAME, nameof(applicationId), applicationId);\n\t\tGuards.stringValue(MessagingService.CLASS_NAME, nameof(deviceToken), deviceToken);\n\n\t\treturn this._pushNotificationMessagingConnector.registerDevice(applicationId, deviceToken);\n\t}\n\n\t/**\n\t * Send a push notification to a device.\n\t * @param deviceAddress The address of the device.\n\t * @param templateId The id of the push notification template.\n\t * @param data The data to populate the push notification template.\n\t * @param locale The locale of the push notification template.\n\t * @returns True if the notification was sent successfully.\n\t */\n\tpublic async sendSinglePushNotification(\n\t\tdeviceAddress: string,\n\t\ttemplateId: string,\n\t\tdata: { [key: string]: string },\n\t\tlocale: string\n\t): Promise<boolean> {\n\t\tif (Is.empty(this._pushNotificationMessagingConnector)) {\n\t\t\tthrow new GeneralError(\n\t\t\t\tMessagingService.CLASS_NAME,\n\t\t\t\t\"notConfiguredPushNotificationMessagingConnector\"\n\t\t\t);\n\t\t}\n\n\t\tGuards.stringValue(MessagingService.CLASS_NAME, nameof(deviceAddress), deviceAddress);\n\t\tGuards.stringValue(MessagingService.CLASS_NAME, nameof(templateId), templateId);\n\t\tGuards.object(MessagingService.CLASS_NAME, nameof(data), data);\n\t\tGuards.stringValue(MessagingService.CLASS_NAME, nameof(locale), locale);\n\n\t\tconst template = await this._messagingAdminComponent.getTemplate(templateId, locale);\n\t\tconst populatedTemplate = this.populateTemplate(template, data);\n\n\t\treturn this._pushNotificationMessagingConnector.sendSinglePushNotification(\n\t\t\tdeviceAddress,\n\t\t\tpopulatedTemplate.title,\n\t\t\tpopulatedTemplate.content\n\t\t);\n\t}\n\n\t/**\n\t * Send a SMS message to a phone number.\n\t * @param phoneNumber The recipient phone number.\n\t * @param templateId The id of the SMS template.\n\t * @param data The data to populate the SMS template.\n\t * @param locale The locale of the SMS template.\n\t * @returns True if the SMS was sent successfully.\n\t */\n\tpublic async sendSMS(\n\t\tphoneNumber: string,\n\t\ttemplateId: string,\n\t\tdata: { [key: string]: string },\n\t\tlocale: string\n\t): Promise<boolean> {\n\t\tif (Is.empty(this._smsMessagingConnector)) {\n\t\t\tthrow new GeneralError(MessagingService.CLASS_NAME, \"notConfiguredSmsMessagingConnector\");\n\t\t}\n\n\t\tGuards.stringValue(MessagingService.CLASS_NAME, nameof(phoneNumber), phoneNumber);\n\t\tGuards.stringValue(MessagingService.CLASS_NAME, nameof(templateId), templateId);\n\t\tGuards.object(MessagingService.CLASS_NAME, nameof(data), data);\n\t\tGuards.stringValue(MessagingService.CLASS_NAME, nameof(locale), locale);\n\n\t\tconst template = await this._messagingAdminComponent.getTemplate(templateId, locale);\n\t\tconst populatedTemplate = this.populateTemplate(template, data);\n\n\t\treturn this._smsMessagingConnector.sendSMS(phoneNumber, populatedTemplate.content);\n\t}\n\n\t/**\n\t * Populates a template by replacing placeholders with the provided data values.\n\t * @param template The template.\n\t * @param template.title The title of the template.\n\t * @param template.content The content of the template.\n\t * @param data The data to populate the template.\n\t * @returns The template with all placeholders replaced.\n\t * @internal\n\t */\n\tprivate populateTemplate(\n\t\ttemplate: { title: string; content: string },\n\t\tdata: { [key: string]: string }\n\t): { title: string; content: string } {\n\t\tlet populatedTitle = template.title;\n\t\tlet populatedContent = template.content;\n\n\t\tfor (const key in data) {\n\t\t\tconst value = data[key];\n\t\t\tconst placeholder = `{{${key}}}`;\n\t\t\tpopulatedTitle = populatedTitle.replace(new RegExp(placeholder, \"g\"), value);\n\t\t\tpopulatedContent = populatedContent.replace(new RegExp(placeholder, \"g\"), value);\n\t\t}\n\n\t\treturn {\n\t\t\ttitle: populatedTitle,\n\t\t\tcontent: populatedContent\n\t\t};\n\t}\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"IMessagingAdminServiceConfig.js","sourceRoot":"","sources":["../../../src/models/IMessagingAdminServiceConfig.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\n\n/**\n * Options for the messaging service.\n */\nexport interface IMessagingAdminServiceConfig {\n\t/**\n\t * The default locale to use for the messaging service.\n\t * @default en\n\t */\n\tdefaultLocale?: string;\n}\n"]}
1
+ {"version":3,"file":"IMessagingAdminServiceConfig.js","sourceRoot":"","sources":["../../../src/models/IMessagingAdminServiceConfig.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\n\n/**\n * Configuration for the messaging admin service.\n */\nexport interface IMessagingAdminServiceConfig {\n\t/**\n\t * The default locale to use for the messaging service.\n\t * @default en\n\t */\n\tdefaultLocale?: string;\n}\n"]}
package/dist/es/schema.js CHANGED
@@ -3,7 +3,7 @@
3
3
  import { EntitySchemaFactory, EntitySchemaHelper } from "@twin.org/entity";
4
4
  import { TemplateEntry } from "./entities/templateEntry.js";
5
5
  /**
6
- * Initialize the schema for the messaging service.
6
+ * Registers entity schemas required by the messaging service.
7
7
  */
8
8
  export function initSchema() {
9
9
  EntitySchemaFactory.register("TemplateEntry", () => EntitySchemaHelper.getSchema(TemplateEntry));
@@ -1 +1 @@
1
- {"version":3,"file":"schema.js","sourceRoot":"","sources":["../../src/schema.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAE3E,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAE5D;;GAEG;AACH,MAAM,UAAU,UAAU;IACzB,mBAAmB,CAAC,QAAQ,kBAA0B,GAAG,EAAE,CAC1D,kBAAkB,CAAC,SAAS,CAAC,aAAa,CAAC,CAC3C,CAAC;AACH,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { EntitySchemaFactory, EntitySchemaHelper } from \"@twin.org/entity\";\nimport { nameof } from \"@twin.org/nameof\";\nimport { TemplateEntry } from \"./entities/templateEntry.js\";\n\n/**\n * Initialize the schema for the messaging service.\n */\nexport function initSchema(): void {\n\tEntitySchemaFactory.register(nameof<TemplateEntry>(), () =>\n\t\tEntitySchemaHelper.getSchema(TemplateEntry)\n\t);\n}\n"]}
1
+ {"version":3,"file":"schema.js","sourceRoot":"","sources":["../../src/schema.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAE3E,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAE5D;;GAEG;AACH,MAAM,UAAU,UAAU;IACzB,mBAAmB,CAAC,QAAQ,kBAA0B,GAAG,EAAE,CAC1D,kBAAkB,CAAC,SAAS,CAAC,aAAa,CAAC,CAC3C,CAAC;AACH,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { EntitySchemaFactory, EntitySchemaHelper } from \"@twin.org/entity\";\nimport { nameof } from \"@twin.org/nameof\";\nimport { TemplateEntry } from \"./entities/templateEntry.js\";\n\n/**\n * Registers entity schemas required by the messaging service.\n */\nexport function initSchema(): void {\n\tEntitySchemaFactory.register(nameof<TemplateEntry>(), () =>\n\t\tEntitySchemaHelper.getSchema(TemplateEntry)\n\t);\n}\n"]}
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Call defining a template message entry.
2
+ * Class defining a message template entry.
3
3
  */
4
4
  export declare class TemplateEntry {
5
5
  /**
@@ -1,7 +1,7 @@
1
1
  import type { IMessagingAdminComponent } from "@twin.org/messaging-models";
2
2
  import type { IMessagingAdminServiceConstructorOptions } from "./models/IMessagingAdminServiceConstructorOptions.js";
3
3
  /**
4
- * Service for performing email messaging operations to a connector.
4
+ * Service for managing message templates stored via entity storage.
5
5
  */
6
6
  export declare class MessagingAdminService implements IMessagingAdminComponent {
7
7
  /**
@@ -10,7 +10,7 @@ export declare class MessagingAdminService implements IMessagingAdminComponent {
10
10
  static readonly CLASS_NAME: string;
11
11
  /**
12
12
  * Create a new instance of MessagingAdminService.
13
- * @param options The options for the connector.
13
+ * @param options The options for the service.
14
14
  */
15
15
  constructor(options?: IMessagingAdminServiceConstructorOptions);
16
16
  /**
@@ -24,7 +24,7 @@ export declare class MessagingAdminService implements IMessagingAdminComponent {
24
24
  * @param locale The locale of the template.
25
25
  * @param title The title of the template.
26
26
  * @param content The content of the template.
27
- * @returns Nothing.
27
+ * @returns A promise that resolves when the template has been stored.
28
28
  */
29
29
  setTemplate(templateId: string, locale: string, title: string, content: string): Promise<void>;
30
30
  /**
@@ -41,7 +41,7 @@ export declare class MessagingAdminService implements IMessagingAdminComponent {
41
41
  * Remove a template.
42
42
  * @param templateId The id of the template.
43
43
  * @param locale The locale of the template.
44
- * @returns Nothing
44
+ * @returns A promise that resolves when the template has been removed.
45
45
  */
46
46
  removeTemplate(templateId: string, locale: string): Promise<void>;
47
47
  }
@@ -1,7 +1,7 @@
1
1
  import { type IMessagingComponent } from "@twin.org/messaging-models";
2
2
  import type { IMessagingServiceConstructorOptions } from "./models/IMessagingServiceConstructorOptions.js";
3
3
  /**
4
- * Service for performing email messaging operations to a connector.
4
+ * Service for dispatching messages via configured email, push notification, and SMS connectors.
5
5
  */
6
6
  export declare class MessagingService implements IMessagingComponent {
7
7
  /**
@@ -10,7 +10,7 @@ export declare class MessagingService implements IMessagingComponent {
10
10
  static readonly CLASS_NAME: string;
11
11
  /**
12
12
  * Create a new instance of MessagingService.
13
- * @param options The options for the connector.
13
+ * @param options The options for the service.
14
14
  */
15
15
  constructor(options?: IMessagingServiceConstructorOptions);
16
16
  /**
@@ -25,16 +25,16 @@ export declare class MessagingService implements IMessagingComponent {
25
25
  * @param templateId The id of the email template.
26
26
  * @param data The data to populate the email template.
27
27
  * @param locale The locale of the email template.
28
- * @returns If the email was sent successfully.
28
+ * @returns True if the email was sent successfully.
29
29
  */
30
30
  sendCustomEmail(sender: string, recipients: string[], templateId: string, data: {
31
31
  [key: string]: string;
32
32
  }, locale: string): Promise<boolean>;
33
33
  /**
34
- * Registers a device to an specific app in order to send notifications to it.
34
+ * Registers a device to a specific application in order to send notifications to it.
35
35
  * @param applicationId The application address.
36
36
  * @param deviceToken The device token.
37
- * @returns If the device was registered successfully.
37
+ * @returns The address assigned to the registered device.
38
38
  */
39
39
  registerDevice(applicationId: string, deviceToken: string): Promise<string>;
40
40
  /**
@@ -43,7 +43,7 @@ export declare class MessagingService implements IMessagingComponent {
43
43
  * @param templateId The id of the push notification template.
44
44
  * @param data The data to populate the push notification template.
45
45
  * @param locale The locale of the push notification template.
46
- * @returns If the notification was sent successfully.
46
+ * @returns True if the notification was sent successfully.
47
47
  */
48
48
  sendSinglePushNotification(deviceAddress: string, templateId: string, data: {
49
49
  [key: string]: string;
@@ -54,7 +54,7 @@ export declare class MessagingService implements IMessagingComponent {
54
54
  * @param templateId The id of the SMS template.
55
55
  * @param data The data to populate the SMS template.
56
56
  * @param locale The locale of the SMS template.
57
- * @returns If the SMS was sent successfully.
57
+ * @returns True if the SMS was sent successfully.
58
58
  */
59
59
  sendSMS(phoneNumber: string, templateId: string, data: {
60
60
  [key: string]: string;
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Options for the messaging service.
2
+ * Configuration for the messaging admin service.
3
3
  */
4
4
  export interface IMessagingAdminServiceConfig {
5
5
  /**
@@ -1,4 +1,4 @@
1
1
  /**
2
- * Initialize the schema for the messaging service.
2
+ * Registers entity schemas required by the messaging service.
3
3
  */
4
4
  export declare function initSchema(): void;
package/docs/changelog.md CHANGED
@@ -1,5 +1,45 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.9.0](https://github.com/iotaledger/twin-messaging/compare/messaging-service-v0.9.0...messaging-service-v0.9.0) (2026-06-25)
4
+
5
+
6
+ ### Features
7
+
8
+ * release to production ([cc714a7](https://github.com/iotaledger/twin-messaging/commit/cc714a7e1db251ab8e1a158f7753387a56d60271))
9
+ * release to production ([#40](https://github.com/iotaledger/twin-messaging/issues/40)) ([08faed5](https://github.com/iotaledger/twin-messaging/commit/08faed56591b92e54aae3696e9a9e6186d2631bb))
10
+
11
+ ## [0.9.0-next.1](https://github.com/iotaledger/twin-messaging/compare/messaging-service-v0.9.0-next.0...messaging-service-v0.9.0-next.1) (2026-06-23)
12
+
13
+
14
+ ### Features
15
+
16
+ * add context id features ([#24](https://github.com/iotaledger/twin-messaging/issues/24)) ([42b94e8](https://github.com/iotaledger/twin-messaging/commit/42b94e8be32c86db6afc5ccf5e9ff2c93d15d05d))
17
+ * add initial templates config ([66b40eb](https://github.com/iotaledger/twin-messaging/commit/66b40eb57a478d9f79de540eb847a4fb37894235))
18
+ * add messaging admin component ([cbaaca3](https://github.com/iotaledger/twin-messaging/commit/cbaaca34db6a9f5c51438c201535b4b43a1aea1f))
19
+ * add validate-locales ([5eeff9b](https://github.com/iotaledger/twin-messaging/commit/5eeff9b9bf6cecf93b249b56c4bb74b4c5bf86c9))
20
+ * eslint migration to flat config ([faa02ec](https://github.com/iotaledger/twin-messaging/commit/faa02ec0ef450db88b08e938415e40cf13625d15))
21
+ * Messaging services ([#3](https://github.com/iotaledger/twin-messaging/issues/3)) ([32571b5](https://github.com/iotaledger/twin-messaging/commit/32571b5abf5d3fc3b168074c23507e926c5d00b0))
22
+ * remove unused namespace ([2201898](https://github.com/iotaledger/twin-messaging/commit/22018988b84e4b3e76da1a1e16f29bfde7e6f0e6))
23
+ * typescript 6 update ([0aabd3e](https://github.com/iotaledger/twin-messaging/commit/0aabd3e05fbdf1cbc5df34cf24c461a75abc9d7e))
24
+ * update dependencies ([eda66c5](https://github.com/iotaledger/twin-messaging/commit/eda66c5c670f36f1ba86a8f768e4781b629c88ff))
25
+ * update dependencies ([53dcde6](https://github.com/iotaledger/twin-messaging/commit/53dcde60d6efaee5957296f6d097cb97c0fb2f9d))
26
+ * update framework core ([fc476b4](https://github.com/iotaledger/twin-messaging/commit/fc476b48e6075de0ae871e3cec1fa179aa04b5eb))
27
+ * use shared store mechanism ([#8](https://github.com/iotaledger/twin-messaging/issues/8)) ([9ad65c2](https://github.com/iotaledger/twin-messaging/commit/9ad65c239ba77bb75604a1f6e51b975357f3228d))
28
+
29
+
30
+ ### Bug Fixes
31
+
32
+ * Adding format to the MessagingEntries ts number ([8b99d4f](https://github.com/iotaledger/twin-messaging/commit/8b99d4f01c4f2b08da8d2affc1b9554fcb0d3690))
33
+ * use async getStore in tests ([bd00e17](https://github.com/iotaledger/twin-messaging/commit/bd00e17218c1954bbb3a740e5628756764fa2598))
34
+ * use async getStore in tests ([50057a6](https://github.com/iotaledger/twin-messaging/commit/50057a6ae962623aaa2ab778ea29c08b6f885452))
35
+
36
+
37
+ ### Dependencies
38
+
39
+ * The following workspace dependencies were updated
40
+ * dependencies
41
+ * @twin.org/messaging-models bumped from 0.9.0-next.0 to 0.9.0-next.1
42
+
3
43
  ## [0.0.3-next.6](https://github.com/iotaledger/twin-messaging/compare/messaging-service-v0.0.3-next.5...messaging-service-v0.0.3-next.6) (2026-06-11)
4
44
 
5
45
 
@@ -1,6 +1,6 @@
1
1
  # Class: MessagingAdminService
2
2
 
3
- Service for performing email messaging operations to a connector.
3
+ Service for managing message templates stored via entity storage.
4
4
 
5
5
  ## Implements
6
6
 
@@ -20,7 +20,7 @@ Create a new instance of MessagingAdminService.
20
20
 
21
21
  [`IMessagingAdminServiceConstructorOptions`](../interfaces/IMessagingAdminServiceConstructorOptions.md)
22
22
 
23
- The options for the connector.
23
+ The options for the service.
24
24
 
25
25
  #### Returns
26
26
 
@@ -90,7 +90,7 @@ The content of the template.
90
90
 
91
91
  `Promise`\<`void`\>
92
92
 
93
- Nothing.
93
+ A promise that resolves when the template has been stored.
94
94
 
95
95
  #### Implementation of
96
96
 
@@ -154,7 +154,7 @@ The locale of the template.
154
154
 
155
155
  `Promise`\<`void`\>
156
156
 
157
- Nothing
157
+ A promise that resolves when the template has been removed.
158
158
 
159
159
  #### Implementation of
160
160
 
@@ -1,6 +1,6 @@
1
1
  # Class: MessagingService
2
2
 
3
- Service for performing email messaging operations to a connector.
3
+ Service for dispatching messages via configured email, push notification, and SMS connectors.
4
4
 
5
5
  ## Implements
6
6
 
@@ -20,7 +20,7 @@ Create a new instance of MessagingService.
20
20
 
21
21
  [`IMessagingServiceConstructorOptions`](../interfaces/IMessagingServiceConstructorOptions.md)
22
22
 
23
- The options for the connector.
23
+ The options for the service.
24
24
 
25
25
  #### Returns
26
26
 
@@ -94,7 +94,7 @@ The locale of the email template.
94
94
 
95
95
  `Promise`\<`boolean`\>
96
96
 
97
- If the email was sent successfully.
97
+ True if the email was sent successfully.
98
98
 
99
99
  #### Implementation of
100
100
 
@@ -106,7 +106,7 @@ If the email was sent successfully.
106
106
 
107
107
  > **registerDevice**(`applicationId`, `deviceToken`): `Promise`\<`string`\>
108
108
 
109
- Registers a device to an specific app in order to send notifications to it.
109
+ Registers a device to a specific application in order to send notifications to it.
110
110
 
111
111
  #### Parameters
112
112
 
@@ -126,7 +126,7 @@ The device token.
126
126
 
127
127
  `Promise`\<`string`\>
128
128
 
129
- If the device was registered successfully.
129
+ The address assigned to the registered device.
130
130
 
131
131
  #### Implementation of
132
132
 
@@ -168,7 +168,7 @@ The locale of the push notification template.
168
168
 
169
169
  `Promise`\<`boolean`\>
170
170
 
171
- If the notification was sent successfully.
171
+ True if the notification was sent successfully.
172
172
 
173
173
  #### Implementation of
174
174
 
@@ -210,7 +210,7 @@ The locale of the SMS template.
210
210
 
211
211
  `Promise`\<`boolean`\>
212
212
 
213
- If the SMS was sent successfully.
213
+ True if the SMS was sent successfully.
214
214
 
215
215
  #### Implementation of
216
216
 
@@ -1,6 +1,6 @@
1
1
  # Class: TemplateEntry
2
2
 
3
- Call defining a template message entry.
3
+ Class defining a message template entry.
4
4
 
5
5
  ## Constructors
6
6
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  > **initSchema**(): `void`
4
4
 
5
- Initialize the schema for the messaging service.
5
+ Registers entity schemas required by the messaging service.
6
6
 
7
7
  ## Returns
8
8
 
@@ -1,6 +1,6 @@
1
1
  # Interface: IMessagingAdminServiceConfig
2
2
 
3
- Options for the messaging service.
3
+ Configuration for the messaging admin service.
4
4
 
5
5
  ## Properties
6
6
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@twin.org/messaging-service",
3
- "version": "0.0.3-next.6",
3
+ "version": "0.9.0",
4
4
  "description": "Implements the messaging service layer that orchestrates delivery workflows across connectors.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -14,12 +14,12 @@
14
14
  "node": ">=20.0.0"
15
15
  },
16
16
  "dependencies": {
17
- "@twin.org/core": "next",
18
- "@twin.org/entity": "next",
19
- "@twin.org/entity-storage-models": "next",
20
- "@twin.org/logging-models": "next",
21
- "@twin.org/messaging-models": "0.0.3-next.6",
22
- "@twin.org/nameof": "next"
17
+ "@twin.org/core": "^0.9.0",
18
+ "@twin.org/entity": "^0.9.0",
19
+ "@twin.org/entity-storage-models": "^0.9.0",
20
+ "@twin.org/logging-models": "^0.9.0",
21
+ "@twin.org/messaging-models": "^0.9.0",
22
+ "@twin.org/nameof": "^0.9.0"
23
23
  },
24
24
  "main": "./dist/es/index.js",
25
25
  "types": "./dist/types/index.d.ts",