@quatrain/messaging 1.0.1 → 1.0.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/lib/AbstractMessagingAdapter.d.ts +1 -5
- package/lib/MessageFormatter.d.ts +6 -0
- package/lib/MessageFormatter.js +16 -0
- package/lib/index.d.ts +6 -2
- package/lib/types/AbstractMessage.d.ts +1 -1
- package/lib/types/EmailCapableAdapter.d.ts +6 -0
- package/lib/types/MessagingInterface.d.ts +1 -0
- package/lib/types/MessagingRecipient.d.ts +6 -2
- package/lib/types/MessagingTemplate.d.ts +1 -0
- package/lib/types/NotificationCapableAdapter.d.ts +7 -0
- package/lib/types/NotificationCapableAdapter.js +2 -0
- package/package.json +4 -2
- package/lib/AbstractAuthAdapter.d.ts +0 -22
- package/lib/AbstractAuthAdapter.js +0 -25
- package/lib/Auth.d.ts +0 -36
- package/lib/Auth.js +0 -33
- package/lib/AuthenticationError.d.ts +0 -2
- package/lib/AuthenticationError.js +0 -6
- package/lib/middlewares/AbstractAuthMiddleware.d.ts +0 -0
- package/lib/middlewares/AbstractAuthMiddleware.js +0 -1
- package/lib/middlewares/AuthMiddleware.d.ts +0 -5
- package/lib/types/AuthInterface.d.ts +0 -10
- /package/lib/{middlewares/AuthMiddleware.js → types/EmailCapableAdapter.js} +0 -0
- /package/lib/types/{AuthInterface.js → MessagingTemplate.js} +0 -0
|
@@ -1,12 +1,8 @@
|
|
|
1
|
-
import { MessagingInterface } from './types/MessagingInterface';
|
|
2
|
-
import { NotificationMessage } from './types/NotificationMessage';
|
|
3
|
-
import { MessagingRecipient } from './types/MessagingRecipient';
|
|
4
1
|
import { MessagingParameters } from './Messaging';
|
|
5
|
-
export declare abstract class AbstractMessagingAdapter
|
|
2
|
+
export declare abstract class AbstractMessagingAdapter {
|
|
6
3
|
protected _alias: string;
|
|
7
4
|
protected _params: MessagingParameters;
|
|
8
5
|
constructor(params?: MessagingParameters);
|
|
9
6
|
set alias(alias: string);
|
|
10
7
|
get alias(): string;
|
|
11
|
-
abstract sendNotification(recipient: MessagingRecipient, message: NotificationMessage): Promise<any>;
|
|
12
8
|
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { MessagingRecipient } from './types/MessagingRecipient';
|
|
2
|
+
import { AbstractMessage } from './types/AbstractMessage';
|
|
3
|
+
export declare class MessageFormatter {
|
|
4
|
+
static formatTitle(title: string): string;
|
|
5
|
+
static formatBody(recipient: MessagingRecipient, message: AbstractMessage): string;
|
|
6
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.MessageFormatter = void 0;
|
|
7
|
+
const mustache_1 = __importDefault(require("mustache"));
|
|
8
|
+
class MessageFormatter {
|
|
9
|
+
static formatTitle(title) {
|
|
10
|
+
return title.replace(/(<([^>]+)>)/gi, '');
|
|
11
|
+
}
|
|
12
|
+
static formatBody(recipient, message) {
|
|
13
|
+
return mustache_1.default.render(message.body, recipient.data || message.data);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
exports.MessageFormatter = MessageFormatter;
|
package/lib/index.d.ts
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
import { Messaging, MessagingParameters } from './Messaging';
|
|
2
2
|
import { AbstractMessagingAdapter } from './AbstractMessagingAdapter';
|
|
3
|
-
import {
|
|
4
|
-
|
|
3
|
+
import { MessagingRecipient } from './types/MessagingRecipient';
|
|
4
|
+
import { NotificationMessage } from './types/NotificationMessage';
|
|
5
|
+
import { AbstractMessage } from './types/AbstractMessage';
|
|
6
|
+
import { EmailCapableAdapter } from './types/EmailCapableAdapter';
|
|
7
|
+
import { NotificationCapableAdapter } from './types/NotificationCapableAdapter';
|
|
8
|
+
export { Messaging, MessagingParameters, AbstractMessagingAdapter, MessagingRecipient, NotificationMessage, AbstractMessage, EmailCapableAdapter, NotificationCapableAdapter, };
|
|
@@ -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
|
+
}
|
|
@@ -2,4 +2,5 @@ import { AbstractMessage } from './AbstractMessage';
|
|
|
2
2
|
import { MessagingRecipient } from './MessagingRecipient';
|
|
3
3
|
export interface MessagingInterface {
|
|
4
4
|
sendNotification(recipient: MessagingRecipient, message: AbstractMessage): Promise<any>;
|
|
5
|
+
sendNotifications(recipients: MessagingRecipient[], message: AbstractMessage): Promise<any>;
|
|
5
6
|
}
|
|
@@ -1,2 +1,6 @@
|
|
|
1
|
-
import { UserType } from
|
|
2
|
-
export type MessagingRecipient = Pick<UserType, 'firstname' | 'lastname' | 'email' | 'messageToken'
|
|
1
|
+
import { UserType } from '@quatrain/core';
|
|
2
|
+
export type MessagingRecipient = Pick<UserType, 'firstname' | 'lastname' | 'email' | 'messageToken'> & {
|
|
3
|
+
data?: {
|
|
4
|
+
[x: string]: any;
|
|
5
|
+
};
|
|
6
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type MessagingTemplate = {};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { AbstractMessagingAdapter } from '../AbstractMessagingAdapter';
|
|
2
|
+
import { MessagingRecipient } from './MessagingRecipient';
|
|
3
|
+
import { NotificationMessage } from './NotificationMessage';
|
|
4
|
+
export interface NotificationCapableAdapter extends AbstractMessagingAdapter {
|
|
5
|
+
sendNotification(recipient: MessagingRecipient, message: NotificationMessage): Promise<any>;
|
|
6
|
+
sendNotifications(recipients: MessagingRecipient[], message: NotificationMessage): Promise<any>;
|
|
7
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@quatrain/messaging",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "Messaging adapters commons",
|
|
6
6
|
"main": "lib/index.js",
|
|
@@ -11,11 +11,13 @@
|
|
|
11
11
|
],
|
|
12
12
|
"author": "Quatrain Développement SAS <developers@quatrain.com>",
|
|
13
13
|
"dependencies": {
|
|
14
|
-
"@quatrain/core": "^1.1.19"
|
|
14
|
+
"@quatrain/core": "^1.1.19",
|
|
15
|
+
"mustache": "^4.2.0"
|
|
15
16
|
},
|
|
16
17
|
"devDependencies": {
|
|
17
18
|
"@tsconfig/recommended": "^1.0.1",
|
|
18
19
|
"@types/jest": "^27.0.3",
|
|
20
|
+
"@types/mustache": "^4",
|
|
19
21
|
"@types/node": "^22.10.1",
|
|
20
22
|
"jest": "^27.4.7",
|
|
21
23
|
"jest-node-exports-resolver": "^1.1.6",
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { AuthParameters, AuthParametersKeys } from './Auth';
|
|
2
|
-
import { User } from '@quatrain/backend';
|
|
3
|
-
import { AuthInterface } from './types/AuthInterface';
|
|
4
|
-
export declare abstract class AbstractAuthAdapter implements AuthInterface {
|
|
5
|
-
static UserClass: typeof User;
|
|
6
|
-
protected _alias: string;
|
|
7
|
-
protected _params: AuthParameters;
|
|
8
|
-
constructor(params?: AuthParameters);
|
|
9
|
-
setParam(key: AuthParametersKeys, value: any): void;
|
|
10
|
-
getParam(key: AuthParametersKeys): any;
|
|
11
|
-
set alias(alias: string);
|
|
12
|
-
get alias(): string;
|
|
13
|
-
abstract register(user: User, clearPassword?: string): Promise<any>;
|
|
14
|
-
abstract signup(login: string, password: string): Promise<any>;
|
|
15
|
-
abstract signout(user: User): Promise<any>;
|
|
16
|
-
abstract update(user: User, updatable: any): Promise<any>;
|
|
17
|
-
abstract delete(user: User): Promise<any>;
|
|
18
|
-
abstract getAuthToken(token: string): any;
|
|
19
|
-
abstract refreshToken(refreshToken: string): Promise<any>;
|
|
20
|
-
abstract revokeAuthToken(token: string): any;
|
|
21
|
-
abstract setCustomUserClaims(id: string, claims: any): any;
|
|
22
|
-
}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.AbstractAuthAdapter = void 0;
|
|
4
|
-
const backend_1 = require("@quatrain/backend");
|
|
5
|
-
class AbstractAuthAdapter {
|
|
6
|
-
constructor(params = {}) {
|
|
7
|
-
this._alias = '';
|
|
8
|
-
this._params = {};
|
|
9
|
-
this._params = params;
|
|
10
|
-
}
|
|
11
|
-
setParam(key, value) {
|
|
12
|
-
this._params[key] = value;
|
|
13
|
-
}
|
|
14
|
-
getParam(key) {
|
|
15
|
-
return this._params[key];
|
|
16
|
-
}
|
|
17
|
-
set alias(alias) {
|
|
18
|
-
this._alias = alias;
|
|
19
|
-
}
|
|
20
|
-
get alias() {
|
|
21
|
-
return this._alias;
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
exports.AbstractAuthAdapter = AbstractAuthAdapter;
|
|
25
|
-
AbstractAuthAdapter.UserClass = backend_1.User;
|
package/lib/Auth.d.ts
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { Core } from '@quatrain/core';
|
|
2
|
-
import { AbstractAuthAdapter } from './AbstractAuthAdapter';
|
|
3
|
-
import Middleware from './middlewares/AuthMiddleware';
|
|
4
|
-
export declare enum AuthAction {
|
|
5
|
-
SIGNIN = "signin",
|
|
6
|
-
SIGNUP = "signup",
|
|
7
|
-
SIGNOUT = "signout"
|
|
8
|
-
}
|
|
9
|
-
/**
|
|
10
|
-
* Authentication Parameters acceptable keys
|
|
11
|
-
*/
|
|
12
|
-
export type AuthParametersKeys = 'host' | 'alias' | 'middlewares' | 'config' | 'fixtures' | 'debug';
|
|
13
|
-
/**
|
|
14
|
-
* Backend parameters interface
|
|
15
|
-
*/
|
|
16
|
-
export interface AuthParameters {
|
|
17
|
-
host?: string;
|
|
18
|
-
alias?: string;
|
|
19
|
-
middlewares?: Middleware[];
|
|
20
|
-
config?: any;
|
|
21
|
-
fixtures?: any;
|
|
22
|
-
debug?: boolean;
|
|
23
|
-
}
|
|
24
|
-
export interface AuthAdapter extends AbstractAuthAdapter {
|
|
25
|
-
}
|
|
26
|
-
export type AuthRegistry<T extends AbstractAuthAdapter> = {
|
|
27
|
-
[x: string]: T;
|
|
28
|
-
};
|
|
29
|
-
export declare class Auth extends Core {
|
|
30
|
-
static defaultProvider: string;
|
|
31
|
-
static logger: any;
|
|
32
|
-
static ERROR_EMAIL_EXISTS: string;
|
|
33
|
-
protected static _providers: AuthRegistry<any>;
|
|
34
|
-
static addProvider(provider: AbstractAuthAdapter, alias: string, setDefault?: boolean): void;
|
|
35
|
-
static getProvider<T extends AbstractAuthAdapter>(alias?: string): T;
|
|
36
|
-
}
|
package/lib/Auth.js
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var _a;
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.Auth = exports.AuthAction = void 0;
|
|
5
|
-
const core_1 = require("@quatrain/core");
|
|
6
|
-
var AuthAction;
|
|
7
|
-
(function (AuthAction) {
|
|
8
|
-
AuthAction["SIGNIN"] = "signin";
|
|
9
|
-
AuthAction["SIGNUP"] = "signup";
|
|
10
|
-
AuthAction["SIGNOUT"] = "signout";
|
|
11
|
-
})(AuthAction || (exports.AuthAction = AuthAction = {}));
|
|
12
|
-
class Auth extends core_1.Core {
|
|
13
|
-
static addProvider(provider, alias, setDefault = false) {
|
|
14
|
-
this._providers[alias] = provider;
|
|
15
|
-
if (setDefault) {
|
|
16
|
-
this.defaultProvider = alias;
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
static getProvider(alias = this.defaultProvider) {
|
|
20
|
-
if (this._providers[alias]) {
|
|
21
|
-
return this._providers[alias];
|
|
22
|
-
}
|
|
23
|
-
else {
|
|
24
|
-
throw new Error(`Unknown provider alias: '${alias}'`);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
exports.Auth = Auth;
|
|
29
|
-
_a = Auth;
|
|
30
|
-
Auth.defaultProvider = 'default';
|
|
31
|
-
Auth.logger = _a.addLogger('Auth');
|
|
32
|
-
Auth.ERROR_EMAIL_EXISTS = `User email already exists`;
|
|
33
|
-
Auth._providers = {};
|
|
File without changes
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { User } from '@quatrain/core';
|
|
2
|
-
export interface AuthInterface {
|
|
3
|
-
register(user: User): Promise<any>;
|
|
4
|
-
signup(login: string, password: string): Promise<any>;
|
|
5
|
-
signout(user: User): Promise<any>;
|
|
6
|
-
update(user: User, updatable: any): Promise<any>;
|
|
7
|
-
delete(user: User): Promise<any>;
|
|
8
|
-
getAuthToken(token: string): any;
|
|
9
|
-
refreshToken(refreshToken: string): Promise<any>;
|
|
10
|
-
}
|
|
File without changes
|
|
File without changes
|