@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.
- package/lib/AbstractMessagingAdapter.d.ts +0 -3
- package/lib/AbstractMessagingAdapter.js +0 -7
- package/lib/MessageFormatter.d.ts +1 -3
- package/lib/MessageFormatter.js +2 -2
- package/lib/Messaging.d.ts +8 -8
- package/lib/Messaging.js +9 -9
- package/lib/index.d.ts +3 -2
- package/lib/index.js +3 -1
- package/lib/types/EmailCapableAdapter copy.d.ts +6 -0
- package/lib/types/EmailCapableAdapter copy.js +2 -0
- package/lib/types/MessageType.d.ts +6 -0
- package/lib/types/MessageType.js +2 -0
- package/lib/types/NotificationCapableAdapter.d.ts +1 -2
- package/lib/types/NotificationMessage.d.ts +2 -2
- package/lib/types/TextCapableAdapter.d.ts +6 -0
- package/lib/types/TextCapableAdapter.js +2 -0
- package/package.json +1 -1
|
@@ -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(
|
|
3
|
+
static formatBody(body: string, data?: {}): string;
|
|
6
4
|
}
|
package/lib/MessageFormatter.js
CHANGED
|
@@ -9,8 +9,8 @@ class MessageFormatter {
|
|
|
9
9
|
static formatTitle(title) {
|
|
10
10
|
return title.replace(/(<([^>]+)>)/gi, '');
|
|
11
11
|
}
|
|
12
|
-
static formatBody(
|
|
13
|
-
return mustache_1.default.render(
|
|
12
|
+
static formatBody(body, data) {
|
|
13
|
+
return mustache_1.default.render(body, data);
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
16
|
exports.MessageFormatter = MessageFormatter;
|
package/lib/Messaging.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Core } from '@quatrain/core';
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
}
|
|
5
|
-
export type MessagingRegistry<T extends
|
|
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
|
|
13
|
+
static defaultMessager: string;
|
|
14
14
|
static logger: any;
|
|
15
|
-
protected static
|
|
16
|
-
static
|
|
17
|
-
static
|
|
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
|
|
8
|
-
this.
|
|
7
|
+
static addMessager(messager, alias, setDefault = false) {
|
|
8
|
+
this._messagers[alias] = messager;
|
|
9
9
|
if (setDefault) {
|
|
10
|
-
this.
|
|
10
|
+
this.defaultMessager = alias;
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
|
-
static
|
|
14
|
-
if (this.
|
|
15
|
-
return this.
|
|
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
|
|
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.
|
|
24
|
+
Messaging.defaultMessager = 'default';
|
|
25
25
|
Messaging.logger = _a.addLogger('Messaging');
|
|
26
|
-
Messaging.
|
|
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 {
|
|
5
|
+
import { MessageType } from './types/MessageType';
|
|
6
6
|
import { EmailCapableAdapter } from './types/EmailCapableAdapter';
|
|
7
7
|
import { NotificationCapableAdapter } from './types/NotificationCapableAdapter';
|
|
8
|
-
|
|
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
|
+
}
|
|
@@ -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
|
|
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 {
|
|
2
|
-
export interface NotificationMessage extends
|
|
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
|
+
}
|