@quatrain/messaging 1.0.2 → 1.0.3

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.
@@ -1,8 +1,5 @@
1
1
  import { MessagingParameters } from './Messaging';
2
2
  export declare abstract class AbstractMessagingAdapter {
3
- protected _alias: string;
4
3
  protected _params: MessagingParameters;
5
4
  constructor(params?: MessagingParameters);
6
- set alias(alias: string);
7
- get alias(): string;
8
5
  }
@@ -3,15 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.AbstractMessagingAdapter = void 0;
4
4
  class AbstractMessagingAdapter {
5
5
  constructor(params = {}) {
6
- this._alias = '';
7
6
  this._params = {};
8
7
  this._params = params;
9
8
  }
10
- set alias(alias) {
11
- this._alias = alias;
12
- }
13
- get alias() {
14
- return this._alias;
15
- }
16
9
  }
17
10
  exports.AbstractMessagingAdapter = AbstractMessagingAdapter;
@@ -1,6 +1,4 @@
1
- import { MessagingRecipient } from './types/MessagingRecipient';
2
- import { AbstractMessage } from './types/AbstractMessage';
3
1
  export declare class MessageFormatter {
4
2
  static formatTitle(title: string): string;
5
- static formatBody(recipient: MessagingRecipient, message: AbstractMessage): string;
3
+ static formatBody(body: string, data?: {}): string;
6
4
  }
@@ -9,8 +9,8 @@ class MessageFormatter {
9
9
  static formatTitle(title) {
10
10
  return title.replace(/(<([^>]+)>)/gi, '');
11
11
  }
12
- static formatBody(recipient, message) {
13
- return mustache_1.default.render(message.body, recipient.data || message.data);
12
+ static formatBody(body, data) {
13
+ return mustache_1.default.render(body, data);
14
14
  }
15
15
  }
16
16
  exports.MessageFormatter = MessageFormatter;
@@ -1,8 +1,8 @@
1
1
  import { Core } from '@quatrain/core';
2
- import { AbstractMessagingAdapter } from './AbstractMessagingAdapter';
3
- export interface MessagingAdapter extends AbstractMessagingAdapter {
4
- }
5
- export type MessagingRegistry<T extends AbstractMessagingAdapter> = {
2
+ import { NotificationCapableAdapter } from './types/NotificationCapableAdapter';
3
+ import { EmailCapableAdapter } from './types/EmailCapableAdapter';
4
+ import { TextCapableAdapter } from './types/TextCapableAdapter';
5
+ export type MessagingRegistry<T extends NotificationCapableAdapter | EmailCapableAdapter | TextCapableAdapter> = {
6
6
  [x: string]: T;
7
7
  };
8
8
  export interface MessagingParameters {
@@ -10,9 +10,9 @@ export interface MessagingParameters {
10
10
  debug?: boolean;
11
11
  }
12
12
  export declare class Messaging extends Core {
13
- static defaultProvider: string;
13
+ static defaultMessager: string;
14
14
  static logger: any;
15
- protected static _providers: MessagingRegistry<any>;
16
- static addProvider(provider: AbstractMessagingAdapter, alias: string, setDefault?: boolean): void;
17
- static getProvider<T extends AbstractMessagingAdapter>(alias?: string): T;
15
+ protected static _messagers: MessagingRegistry<any>;
16
+ static addMessager(messager: NotificationCapableAdapter | EmailCapableAdapter | TextCapableAdapter, alias: string, setDefault?: boolean): void;
17
+ static getMessager(alias?: string): any;
18
18
  }
package/lib/Messaging.js CHANGED
@@ -4,23 +4,23 @@ Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.Messaging = void 0;
5
5
  const core_1 = require("@quatrain/core");
6
6
  class Messaging extends core_1.Core {
7
- static addProvider(provider, alias, setDefault = false) {
8
- this._providers[alias] = provider;
7
+ static addMessager(messager, alias, setDefault = false) {
8
+ this._messagers[alias] = messager;
9
9
  if (setDefault) {
10
- this.defaultProvider = alias;
10
+ this.defaultMessager = alias;
11
11
  }
12
12
  }
13
- static getProvider(alias = this.defaultProvider) {
14
- if (this._providers[alias]) {
15
- return this._providers[alias];
13
+ static getMessager(alias = this.defaultMessager) {
14
+ if (this._messagers[alias]) {
15
+ return this._messagers[alias];
16
16
  }
17
17
  else {
18
- throw new Error(`Unknown provider alias: '${alias}'`);
18
+ throw new Error(`Unknown messager alias: '${alias}'`);
19
19
  }
20
20
  }
21
21
  }
22
22
  exports.Messaging = Messaging;
23
23
  _a = Messaging;
24
- Messaging.defaultProvider = 'default';
24
+ Messaging.defaultMessager = 'default';
25
25
  Messaging.logger = _a.addLogger('Messaging');
26
- Messaging._providers = {};
26
+ Messaging._messagers = {};
package/lib/index.d.ts CHANGED
@@ -2,7 +2,8 @@ import { Messaging, MessagingParameters } from './Messaging';
2
2
  import { AbstractMessagingAdapter } from './AbstractMessagingAdapter';
3
3
  import { MessagingRecipient } from './types/MessagingRecipient';
4
4
  import { NotificationMessage } from './types/NotificationMessage';
5
- import { AbstractMessage } from './types/AbstractMessage';
5
+ import { MessageType } from './types/MessageType';
6
6
  import { EmailCapableAdapter } from './types/EmailCapableAdapter';
7
7
  import { NotificationCapableAdapter } from './types/NotificationCapableAdapter';
8
- export { Messaging, MessagingParameters, AbstractMessagingAdapter, MessagingRecipient, NotificationMessage, AbstractMessage, EmailCapableAdapter, NotificationCapableAdapter, };
8
+ import { MessageFormatter } from './MessageFormatter';
9
+ export { Messaging, MessagingParameters, AbstractMessagingAdapter, MessagingRecipient, NotificationMessage, MessageType, EmailCapableAdapter, NotificationCapableAdapter, MessageFormatter, };
package/lib/index.js CHANGED
@@ -1,7 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AbstractMessagingAdapter = exports.Messaging = void 0;
3
+ exports.MessageFormatter = exports.AbstractMessagingAdapter = exports.Messaging = void 0;
4
4
  const Messaging_1 = require("./Messaging");
5
5
  Object.defineProperty(exports, "Messaging", { enumerable: true, get: function () { return Messaging_1.Messaging; } });
6
6
  const AbstractMessagingAdapter_1 = require("./AbstractMessagingAdapter");
7
7
  Object.defineProperty(exports, "AbstractMessagingAdapter", { enumerable: true, get: function () { return AbstractMessagingAdapter_1.AbstractMessagingAdapter; } });
8
+ const MessageFormatter_1 = require("./MessageFormatter");
9
+ Object.defineProperty(exports, "MessageFormatter", { enumerable: true, get: function () { return MessageFormatter_1.MessageFormatter; } });
@@ -0,0 +1,6 @@
1
+ import { MessagingRecipient } from './MessagingRecipient';
2
+ import { NotificationMessage } from './NotificationMessage';
3
+ export interface EmailCapableAdapter {
4
+ sendEmail(recipient: MessagingRecipient, message: NotificationMessage): Promise<any>;
5
+ sendEmails(recipients: MessagingRecipient[], message: NotificationMessage): Promise<any>;
6
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,6 @@
1
+ export interface MessageType {
2
+ token?: string;
3
+ title: string;
4
+ body: string;
5
+ data?: any;
6
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,7 +1,6 @@
1
- import { AbstractMessagingAdapter } from '../AbstractMessagingAdapter';
2
1
  import { MessagingRecipient } from './MessagingRecipient';
3
2
  import { NotificationMessage } from './NotificationMessage';
4
- export interface NotificationCapableAdapter extends AbstractMessagingAdapter {
3
+ export interface NotificationCapableAdapter {
5
4
  sendNotification(recipient: MessagingRecipient, message: NotificationMessage): Promise<any>;
6
5
  sendNotifications(recipients: MessagingRecipient[], message: NotificationMessage): Promise<any>;
7
6
  }
@@ -1,3 +1,3 @@
1
- import { AbstractMessage } from './AbstractMessage';
2
- export interface NotificationMessage extends AbstractMessage {
1
+ import { MessageType } from './MessageType';
2
+ export interface NotificationMessage extends MessageType {
3
3
  }
@@ -0,0 +1,6 @@
1
+ import { MessagingRecipient } from './MessagingRecipient';
2
+ import { NotificationMessage } from './NotificationMessage';
3
+ export interface TextCapableAdapter {
4
+ sendTextMessage(recipient: MessagingRecipient, message: NotificationMessage): Promise<any>;
5
+ sendTextMessages(recipients: MessagingRecipient[], message: NotificationMessage): Promise<any>;
6
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quatrain/messaging",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "license": "MIT",
5
5
  "description": "Messaging adapters commons",
6
6
  "main": "lib/index.js",