@quatrain/messaging 1.0.1

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.
@@ -0,0 +1,22 @@
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
+ }
@@ -0,0 +1,25 @@
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;
@@ -0,0 +1,12 @@
1
+ import { MessagingInterface } from './types/MessagingInterface';
2
+ import { NotificationMessage } from './types/NotificationMessage';
3
+ import { MessagingRecipient } from './types/MessagingRecipient';
4
+ import { MessagingParameters } from './Messaging';
5
+ export declare abstract class AbstractMessagingAdapter implements MessagingInterface {
6
+ protected _alias: string;
7
+ protected _params: MessagingParameters;
8
+ constructor(params?: MessagingParameters);
9
+ set alias(alias: string);
10
+ get alias(): string;
11
+ abstract sendNotification(recipient: MessagingRecipient, message: NotificationMessage): Promise<any>;
12
+ }
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AbstractMessagingAdapter = void 0;
4
+ class AbstractMessagingAdapter {
5
+ constructor(params = {}) {
6
+ this._alias = '';
7
+ this._params = {};
8
+ this._params = params;
9
+ }
10
+ set alias(alias) {
11
+ this._alias = alias;
12
+ }
13
+ get alias() {
14
+ return this._alias;
15
+ }
16
+ }
17
+ exports.AbstractMessagingAdapter = AbstractMessagingAdapter;
package/lib/Auth.d.ts ADDED
@@ -0,0 +1,36 @@
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 ADDED
@@ -0,0 +1,33 @@
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 = {};
@@ -0,0 +1,2 @@
1
+ export declare class AuthenticationError extends Error {
2
+ }
@@ -0,0 +1,6 @@
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;
@@ -0,0 +1,18 @@
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> = {
6
+ [x: string]: T;
7
+ };
8
+ export interface MessagingParameters {
9
+ config?: any;
10
+ debug?: boolean;
11
+ }
12
+ export declare class Messaging extends Core {
13
+ static defaultProvider: string;
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;
18
+ }
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ var _a;
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.Messaging = void 0;
5
+ const core_1 = require("@quatrain/core");
6
+ class Messaging extends core_1.Core {
7
+ static addProvider(provider, alias, setDefault = false) {
8
+ this._providers[alias] = provider;
9
+ if (setDefault) {
10
+ this.defaultProvider = alias;
11
+ }
12
+ }
13
+ static getProvider(alias = this.defaultProvider) {
14
+ if (this._providers[alias]) {
15
+ return this._providers[alias];
16
+ }
17
+ else {
18
+ throw new Error(`Unknown provider alias: '${alias}'`);
19
+ }
20
+ }
21
+ }
22
+ exports.Messaging = Messaging;
23
+ _a = Messaging;
24
+ Messaging.defaultProvider = 'default';
25
+ Messaging.logger = _a.addLogger('Messaging');
26
+ Messaging._providers = {};
package/lib/index.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ import { Messaging, MessagingParameters } from './Messaging';
2
+ import { AbstractMessagingAdapter } from './AbstractMessagingAdapter';
3
+ import { MessagingInterface } from './types/MessagingInterface';
4
+ export { Messaging, MessagingParameters, AbstractMessagingAdapter, MessagingInterface, };
package/lib/index.js ADDED
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AbstractMessagingAdapter = exports.Messaging = void 0;
4
+ const Messaging_1 = require("./Messaging");
5
+ Object.defineProperty(exports, "Messaging", { enumerable: true, get: function () { return Messaging_1.Messaging; } });
6
+ const AbstractMessagingAdapter_1 = require("./AbstractMessagingAdapter");
7
+ Object.defineProperty(exports, "AbstractMessagingAdapter", { enumerable: true, get: function () { return AbstractMessagingAdapter_1.AbstractMessagingAdapter; } });
File without changes
@@ -0,0 +1 @@
1
+ "use strict";
@@ -0,0 +1,5 @@
1
+ import { AuthAction } from '../Auth';
2
+ import { User } from '@quatrain/backend';
3
+ export default interface AuthMiddleware {
4
+ execute: (user: User, action: AuthAction) => void;
5
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,6 @@
1
+ export interface AbstractMessage {
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 });
@@ -0,0 +1,10 @@
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
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,5 @@
1
+ import { AbstractMessage } from './AbstractMessage';
2
+ import { MessagingRecipient } from './MessagingRecipient';
3
+ export interface MessagingInterface {
4
+ sendNotification(recipient: MessagingRecipient, message: AbstractMessage): Promise<any>;
5
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ import { UserType } from "@quatrain/core";
2
+ export type MessagingRecipient = Pick<UserType, 'firstname' | 'lastname' | 'email' | 'messageToken'>;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,3 @@
1
+ import { AbstractMessage } from './AbstractMessage';
2
+ export interface NotificationMessage extends AbstractMessage {
3
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/package.json ADDED
@@ -0,0 +1,39 @@
1
+ {
2
+ "name": "@quatrain/messaging",
3
+ "version": "1.0.1",
4
+ "license": "MIT",
5
+ "description": "Messaging adapters commons",
6
+ "main": "lib/index.js",
7
+ "types": "lib/index.d.ts",
8
+ "files": [
9
+ "lib/",
10
+ "README.md"
11
+ ],
12
+ "author": "Quatrain Développement SAS <developers@quatrain.com>",
13
+ "dependencies": {
14
+ "@quatrain/core": "^1.1.19"
15
+ },
16
+ "devDependencies": {
17
+ "@tsconfig/recommended": "^1.0.1",
18
+ "@types/jest": "^27.0.3",
19
+ "@types/node": "^22.10.1",
20
+ "jest": "^27.4.7",
21
+ "jest-node-exports-resolver": "^1.1.6",
22
+ "jest-serial-runner": "^1.2.1",
23
+ "trace-unhandled": "^2.0.1",
24
+ "ts-jest": "^27.1.2",
25
+ "ts-node": "^10.9.1",
26
+ "typescript": "^5.1.5"
27
+ },
28
+ "scripts": {
29
+ "test-ci": "jest --runInBand",
30
+ "build": "tsc",
31
+ "wbuild": "tsc --watch",
32
+ "bump-to": "yarn version",
33
+ "hash": "node ../../bin/hashFolder.js",
34
+ "hash:persist": "yarn hash > .hash_latest.txt",
35
+ "hash:compare": "yarn hash > .hash_newest.txt && cmp -s .hash_latest.txt .hash_newest.txt",
36
+ "publish": "yarn hash:compare || yarn publish:process",
37
+ "publish:process": "yarn version patch && yarn build && yarn npm publish --access public && yarn hash:persist"
38
+ }
39
+ }