@quatrain/messaging 1.0.1 → 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.
Files changed (35) hide show
  1. package/lib/AbstractMessagingAdapter.d.ts +1 -8
  2. package/lib/AbstractMessagingAdapter.js +0 -7
  3. package/lib/MessageFormatter.d.ts +4 -0
  4. package/lib/MessageFormatter.js +16 -0
  5. package/lib/Messaging.d.ts +8 -8
  6. package/lib/Messaging.js +9 -9
  7. package/lib/index.d.ts +7 -2
  8. package/lib/index.js +3 -1
  9. package/lib/types/AbstractMessage.d.ts +1 -1
  10. package/lib/types/EmailCapableAdapter copy.d.ts +6 -0
  11. package/lib/types/EmailCapableAdapter.d.ts +6 -0
  12. package/lib/types/MessageType.d.ts +6 -0
  13. package/lib/types/MessageType.js +2 -0
  14. package/lib/types/MessagingInterface.d.ts +1 -0
  15. package/lib/types/MessagingRecipient.d.ts +6 -2
  16. package/lib/types/MessagingTemplate.d.ts +1 -0
  17. package/lib/types/MessagingTemplate.js +2 -0
  18. package/lib/types/NotificationCapableAdapter.d.ts +6 -0
  19. package/lib/types/NotificationCapableAdapter.js +2 -0
  20. package/lib/types/NotificationMessage.d.ts +2 -2
  21. package/lib/types/TextCapableAdapter.d.ts +6 -0
  22. package/lib/types/TextCapableAdapter.js +2 -0
  23. package/package.json +4 -2
  24. package/lib/AbstractAuthAdapter.d.ts +0 -22
  25. package/lib/AbstractAuthAdapter.js +0 -25
  26. package/lib/Auth.d.ts +0 -36
  27. package/lib/Auth.js +0 -33
  28. package/lib/AuthenticationError.d.ts +0 -2
  29. package/lib/AuthenticationError.js +0 -6
  30. package/lib/middlewares/AbstractAuthMiddleware.d.ts +0 -0
  31. package/lib/middlewares/AbstractAuthMiddleware.js +0 -1
  32. package/lib/middlewares/AuthMiddleware.d.ts +0 -5
  33. package/lib/types/AuthInterface.d.ts +0 -10
  34. /package/lib/{middlewares/AuthMiddleware.js → types/EmailCapableAdapter copy.js} +0 -0
  35. /package/lib/types/{AuthInterface.js → EmailCapableAdapter.js} +0 -0
@@ -1,12 +1,5 @@
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 implements MessagingInterface {
6
- protected _alias: string;
2
+ export declare abstract class AbstractMessagingAdapter {
7
3
  protected _params: MessagingParameters;
8
4
  constructor(params?: MessagingParameters);
9
- set alias(alias: string);
10
- get alias(): string;
11
- abstract sendNotification(recipient: MessagingRecipient, message: NotificationMessage): Promise<any>;
12
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;
@@ -0,0 +1,4 @@
1
+ export declare class MessageFormatter {
2
+ static formatTitle(title: string): string;
3
+ static formatBody(body: string, data?: {}): string;
4
+ }
@@ -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(body, data) {
13
+ return mustache_1.default.render(body, data);
14
+ }
15
+ }
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
@@ -1,4 +1,9 @@
1
1
  import { Messaging, MessagingParameters } from './Messaging';
2
2
  import { AbstractMessagingAdapter } from './AbstractMessagingAdapter';
3
- import { MessagingInterface } from './types/MessagingInterface';
4
- export { Messaging, MessagingParameters, AbstractMessagingAdapter, MessagingInterface, };
3
+ import { MessagingRecipient } from './types/MessagingRecipient';
4
+ import { NotificationMessage } from './types/NotificationMessage';
5
+ import { MessageType } from './types/MessageType';
6
+ import { EmailCapableAdapter } from './types/EmailCapableAdapter';
7
+ import { NotificationCapableAdapter } from './types/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; } });
@@ -1,6 +1,6 @@
1
1
  export interface AbstractMessage {
2
2
  token?: string;
3
3
  title: string;
4
- body?: string;
4
+ body: string;
5
5
  data?: any;
6
6
  }
@@ -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,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,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 });
@@ -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 "@quatrain/core";
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,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,6 @@
1
+ import { MessagingRecipient } from './MessagingRecipient';
2
+ import { NotificationMessage } from './NotificationMessage';
3
+ export interface NotificationCapableAdapter {
4
+ sendNotification(recipient: MessagingRecipient, message: NotificationMessage): Promise<any>;
5
+ sendNotifications(recipients: MessagingRecipient[], message: NotificationMessage): Promise<any>;
6
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -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.1",
3
+ "version": "1.0.3",
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 = {};
@@ -1,2 +0,0 @@
1
- export declare class AuthenticationError extends Error {
2
- }
@@ -1,6 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AuthenticationError = void 0;
4
- class AuthenticationError extends Error {
5
- }
6
- exports.AuthenticationError = AuthenticationError;
File without changes
@@ -1 +0,0 @@
1
- "use strict";
@@ -1,5 +0,0 @@
1
- import { AuthAction } from '../Auth';
2
- import { User } from '@quatrain/backend';
3
- export default interface AuthMiddleware {
4
- execute: (user: User, action: AuthAction) => void;
5
- }
@@ -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
- }