@maxzima/wa-communicator 0.0.13 → 0.0.16

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/.editorconfig ADDED
@@ -0,0 +1,16 @@
1
+ root = true
2
+
3
+ [*]
4
+ charset = utf-8
5
+ indent_style = space
6
+ indent_size = 2
7
+ end_of_line = lf
8
+ insert_final_newline = true
9
+ trim_trailing_whitespace = true
10
+
11
+ [*.{diff,md,sh}]
12
+ trim_trailing_whitespace = false
13
+ insert_final_newline = false
14
+
15
+ [*.json]
16
+ insert_final_newline = false
package/.eslintrc.js ADDED
@@ -0,0 +1,58 @@
1
+ 'use strict';
2
+
3
+ module.exports = {
4
+ root: true,
5
+ parser: '@typescript-eslint/parser',
6
+ extends: [
7
+ 'eslint:recommended',
8
+ 'plugin:eslint-comments/recommended',
9
+ 'plugin:@typescript-eslint/recommended',
10
+ 'plugin:import/typescript',
11
+ 'prettier',
12
+ ],
13
+ plugins: [
14
+ '@typescript-eslint',
15
+ 'prettier',
16
+ 'import',
17
+ 'eslint-comments',
18
+ 'editorconfig',
19
+ ],
20
+ parserOptions: {
21
+ ecmaVersion: 6,
22
+ sourceType: 'module',
23
+ },
24
+ env: {
25
+ es6: true,
26
+ node: true,
27
+ browser: true,
28
+ },
29
+ ignorePatterns: [
30
+ 'node_modules',
31
+ 'dist'
32
+ ],
33
+ globals: {
34
+ BigInt: true,
35
+ console: true,
36
+ document: true,
37
+ navigator: true,
38
+ window: true,
39
+ Math: true,
40
+ module: true,
41
+ require: true,
42
+ global: true,
43
+ },
44
+ rules: {
45
+ 'no-empty': 'off',
46
+ 'no-async-promise-executor': 'off',
47
+ "no-extra-boolean-cast": 'off',
48
+ '@typescript-eslint/explicit-module-boundary-types': 'off',
49
+ 'eslint-comments/disable-enable-pair': ['error', {allowWholeFile: true}],
50
+ 'eslint-comments/no-unused-disable': 'error',
51
+ // 'eslint-comments/no-unlimited-disable': 'off',
52
+ '@typescript-eslint/ban-ts-ignore': 'off',
53
+ '@typescript-eslint/ban-ts-comment': 'off',
54
+ '@typescript-eslint/no-empty-function': 'off',
55
+ 'semi': ['error', 'always'],
56
+ 'no-prototype-builtins': 'off',
57
+ },
58
+ };
package/.gitattributes ADDED
@@ -0,0 +1,29 @@
1
+ #*.php text eol=lf
2
+ *.sh text eol=lf
3
+ *.js text eol=lf
4
+ *.ts text eol=lf
5
+ *.json text eol=lf
6
+ *.css text eol=lf
7
+ *.scss text eol=lf
8
+ *.sql text eol=lf
9
+
10
+ *.jpg binary
11
+ *.jpeg binary
12
+ *.apng binary
13
+ *.png binary
14
+ *.gif binary
15
+ *.swf binary
16
+ *.ico binary
17
+
18
+ *.ttf binary
19
+ *.woff binary
20
+ *.woff2 binary
21
+
22
+ *.exe binary
23
+
24
+ *.mp3 binary
25
+ *.ogg binary
26
+ *.mov binary
27
+ *.mp4 binary
28
+
29
+ *.zip binary
@@ -0,0 +1,9 @@
1
+ # Dependencies
2
+ node_modules
3
+
4
+ # Production
5
+ dist/
6
+
7
+ # package.json is formatted by package managers, so we ignore it here
8
+ package-lock.json
9
+ package.json
package/.prettierrc.js ADDED
@@ -0,0 +1,16 @@
1
+ 'use strict';
2
+
3
+ module.exports = {
4
+ 'semi': true,
5
+ 'singleQuote': true,
6
+ 'arrowParens': 'always',
7
+ 'printWidth': 180,
8
+ 'bracketSpacing': false,
9
+ 'endOfLine': 'lf',
10
+ 'bracketSameLine': false,
11
+ 'proseWrap': 'preserve',
12
+ 'requirePragma': false,
13
+ 'tabWidth': 2,
14
+ 'trailingComma': 'es5',
15
+ 'useTabs': false
16
+ }
@@ -6,5 +6,5 @@
6
6
  },
7
7
  "exclude": [
8
8
  "../src/types/index.ts",
9
- ]
9
+ ],
10
10
  }
@@ -3,6 +3,6 @@
3
3
  "compilerOptions": {
4
4
  "declaration": true,
5
5
  "emitDeclarationOnly": true,
6
- "outDir": "../dist"
7
- }
6
+ "outDir": "../dist",
7
+ },
8
8
  }
@@ -1,4 +1,4 @@
1
- import { isValidMessage, modifyOrigin } from "./utils";
1
+ import { isValidMessage, modifyOrigin, sortMessageQueue } from "./utils";
2
2
  import { CommunicatorTargetEnum_isCorrect } from '../enums/CommunicatorTargetEnum';
3
3
  import { CommunicatorActionEnum_isCorrect, CommunicatorActionEnum_scenario } from '../enums/CommunicatorActionEnum';
4
4
  export class CommunicatorReceiver {
@@ -24,29 +24,10 @@ export class CommunicatorReceiver {
24
24
  }
25
25
  const queue = this.queue.filter(item => item.target === message.target && message.action.hasOwnProperty(item.action));
26
26
  const defaultScenario = CommunicatorActionEnum_scenario();
27
- let sortedQueue = queue.sort((a, b) => {
28
- if (defaultScenario.indexOf(a.action) > defaultScenario.indexOf(b.action)) {
29
- return -1;
30
- }
31
- if (defaultScenario.indexOf(a.action) < defaultScenario.indexOf(b.action)) {
32
- return 1;
33
- }
34
- return 0;
35
- });
27
+ let sortedQueue = sortMessageQueue(queue, defaultScenario);
36
28
  const scenario = this.getMessageScenario(message.target);
37
29
  if (defaultScenario !== scenario) {
38
- sortedQueue = queue.sort((a, b) => {
39
- if (scenario.indexOf(a.action) === -1 || scenario.indexOf(b.action) === -1) {
40
- return 0;
41
- }
42
- if (scenario.indexOf(a.action) > scenario.indexOf(b.action)) {
43
- return 1;
44
- }
45
- if (scenario.indexOf(a.action) < scenario.indexOf(b.action)) {
46
- return -1;
47
- }
48
- return 0;
49
- });
30
+ sortedQueue = sortMessageQueue(queue, scenario);
50
31
  }
51
32
  if (sortedQueue.length) {
52
33
  sortedQueue.forEach(item => {
@@ -102,7 +83,7 @@ export class CommunicatorReceiver {
102
83
  return false;
103
84
  };
104
85
  this.getMessageScenario = (target) => {
105
- let scenario = this.scenario[target];
86
+ const scenario = this.scenario[target];
106
87
  if (scenario) {
107
88
  return scenario;
108
89
  }
@@ -1,3 +1,5 @@
1
- import { TCommunicatorMessage } from "../types";
1
+ import { TCommunicatorMessage, TReceiverMessageQueue } from "../types";
2
+ import { CommunicatorActionEnum } from "../enums/CommunicatorActionEnum";
2
3
  export declare function modifyOrigin(address: string): string;
3
4
  export declare function isValidMessage(message: TCommunicatorMessage): boolean;
5
+ export declare function sortMessageQueue(queue: TReceiverMessageQueue, scenario: CommunicatorActionEnum[]): TReceiverMessageQueue;
@@ -10,7 +10,7 @@ export function modifyOrigin(address) {
10
10
  catch (_) {
11
11
  return null;
12
12
  }
13
- return url.origin;
13
+ return url.origin !== 'null' ? url.origin : null;
14
14
  }
15
15
  export function isValidMessage(message) {
16
16
  const isValidTarget = message.target && CommunicatorTargetEnum_isCorrect(message.target);
@@ -28,3 +28,14 @@ export function isValidMessage(message) {
28
28
  }
29
29
  return isValidTarget && isValidActions;
30
30
  }
31
+ export function sortMessageQueue(queue, scenario) {
32
+ return queue.sort((a, b) => {
33
+ if (scenario.indexOf(a.action) > scenario.indexOf(b.action)) {
34
+ return 1;
35
+ }
36
+ if (scenario.indexOf(a.action) < scenario.indexOf(b.action)) {
37
+ return -1;
38
+ }
39
+ return 0;
40
+ });
41
+ }
@@ -1,4 +1,5 @@
1
1
  export declare enum CommunicatorActionEnum {
2
+ LOADED = "loaded",
2
3
  TOKEN = "token",
3
4
  RESIZE = "resize",
4
5
  CLOSE = "close",
@@ -6,4 +7,4 @@ export declare enum CommunicatorActionEnum {
6
7
  GOTO = "goto"
7
8
  }
8
9
  export declare function CommunicatorActionEnum_isCorrect(item: string): boolean;
9
- export declare function CommunicatorActionEnum_scenario(): string[];
10
+ export declare function CommunicatorActionEnum_scenario(): CommunicatorActionEnum[];
@@ -1,5 +1,6 @@
1
1
  export var CommunicatorActionEnum;
2
2
  (function (CommunicatorActionEnum) {
3
+ CommunicatorActionEnum["LOADED"] = "loaded";
3
4
  CommunicatorActionEnum["TOKEN"] = "token";
4
5
  CommunicatorActionEnum["RESIZE"] = "resize";
5
6
  CommunicatorActionEnum["CLOSE"] = "close";
@@ -23,6 +23,7 @@ export declare type TCommunicatorActionGotoParams = {
23
23
  isTargetBlank?: boolean;
24
24
  };
25
25
  export declare type TCommunicatorSenderActionMap = {
26
+ [CommunicatorActionEnum.LOADED]?: true;
26
27
  [CommunicatorActionEnum.TOKEN]?: TCommunicatorActionTokenParams;
27
28
  [CommunicatorActionEnum.RESIZE]?: TCommunicatorActionResizeParams;
28
29
  [CommunicatorActionEnum.GOTO]?: TCommunicatorActionGotoParams;
package/jest.config.js ADDED
@@ -0,0 +1,18 @@
1
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
2
+ const { defaultsESM: tsjPreset } = require('ts-jest/presets');
3
+
4
+ module.exports = {
5
+ roots: ['<rootDir>/test'],
6
+ testMatch: [
7
+ '**/__tests__/**/*.+(ts|js)',
8
+ '**/?(*.)+(spec).+(ts|js)',
9
+ ],
10
+ transform: {
11
+ ...tsjPreset.transform,
12
+ },
13
+ globals: {
14
+ 'ts-jest': {
15
+ 'tsconfig': 'tsconfig.json'
16
+ }
17
+ }
18
+ };
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.0.13",
2
+ "version": "0.0.16",
3
3
  "name": "@maxzima/wa-communicator",
4
4
  "description": "",
5
5
  "author": "Noname",
@@ -13,16 +13,51 @@
13
13
  "type": "git",
14
14
  "url": ""
15
15
  },
16
+ "publishConfig": {
17
+ "access": "public"
18
+ },
19
+ "size-limit": [
20
+ {
21
+ "path": "dist/index.js",
22
+ "limit": "10 KB"
23
+ },
24
+ {
25
+ "path": "dist/sender.js",
26
+ "limit": "10 KB"
27
+ },
28
+ {
29
+ "path": "dist/receiver.js",
30
+ "limit": "10 KB"
31
+ }
32
+ ],
16
33
  "scripts": {
17
- "prepublishOnly": "npm run build",
34
+ "prepublishOnly": "npm run test && npm run build && npm run size",
18
35
  "clean": "node tools/cleanup",
19
36
  "build": "npm run clean && run-p build:*",
20
37
  "build:esm": "tsc -p config/tsconfig.esm.json",
21
38
  "build:types": "tsc -p config/tsconfig.types.json",
22
- "package": "npm run build"
39
+ "package": "npm run build",
40
+ "lint": "eslint --cache --ext .ts ./src",
41
+ "lint:fix": "npm run lint -- --fix",
42
+ "test": "jest --no-cache --runInBand",
43
+ "size": "size-limit"
23
44
  },
24
45
  "devDependencies": {
46
+ "@size-limit/preset-small-lib": "^8.1.0",
47
+ "@types/jest": "^28.1.8",
48
+ "@typescript-eslint/eslint-plugin": "^5.35.1",
49
+ "@typescript-eslint/parser": "^5.35.1",
50
+ "eslint": "^8.22.0",
51
+ "eslint-config-prettier": "^8.5.0",
52
+ "eslint-plugin-editorconfig": "^4.0.2",
53
+ "eslint-plugin-eslint-comments": "^3.2.0",
54
+ "eslint-plugin-import": "^2.26.0",
55
+ "eslint-plugin-prettier": "^4.2.1",
56
+ "jest": "^28.1.3",
25
57
  "npm-run-all": "^4.1.5",
58
+ "prettier": "^2.7.1",
59
+ "size-limit": "^8.1.0",
60
+ "ts-jest": "^28.0.8",
26
61
  "typescript": "^4.7.4"
27
62
  }
28
63
  }
@@ -6,7 +6,7 @@ import {
6
6
  TReceiverTargetScenario,
7
7
  TReceiverUnsubscribeMessageParams,
8
8
  } from '../types';
9
- import {isValidMessage, modifyOrigin} from "./utils";
9
+ import {isValidMessage, modifyOrigin, sortMessageQueue} from "./utils";
10
10
  import {CommunicatorTargetEnum, CommunicatorTargetEnum_isCorrect} from '../enums/CommunicatorTargetEnum';
11
11
  import {
12
12
  CommunicatorActionEnum,
@@ -55,36 +55,16 @@ export class CommunicatorReceiver {
55
55
  return;
56
56
  }
57
57
 
58
- // Find queue by target and action
59
58
  const queue = this.queue.filter(item => item.target === message.target && message.action.hasOwnProperty(item.action));
60
59
 
61
60
  // default sort queue
62
61
  const defaultScenario = CommunicatorActionEnum_scenario();
63
- let sortedQueue = queue.sort((a, b) => {
64
- if (defaultScenario.indexOf(a.action) > defaultScenario.indexOf(b.action)) {
65
- return -1;
66
- }
67
- if (defaultScenario.indexOf(a.action) < defaultScenario.indexOf(b.action)) {
68
- return 1;
69
- }
70
- return 0;
71
- })
62
+ let sortedQueue = sortMessageQueue(queue, defaultScenario);
72
63
 
73
64
  // sort queue
74
65
  const scenario = this.getMessageScenario(message.target);
75
66
  if (defaultScenario !== scenario) {
76
- sortedQueue = queue.sort((a, b) => {
77
- if (scenario.indexOf(a.action) === -1 || scenario.indexOf(b.action) === -1) {
78
- return 0;
79
- }
80
- if (scenario.indexOf(a.action) > scenario.indexOf(b.action)) {
81
- return 1;
82
- }
83
- if (scenario.indexOf(a.action) < scenario.indexOf(b.action)) {
84
- return -1;
85
- }
86
- return 0;
87
- })
67
+ sortedQueue = sortMessageQueue(queue, scenario);
88
68
  }
89
69
 
90
70
  if (sortedQueue.length) {
@@ -92,7 +72,7 @@ export class CommunicatorReceiver {
92
72
  if (typeof item.params.callback === 'function') {
93
73
  item.params.callback(message);
94
74
  }
95
- })
75
+ });
96
76
  }
97
77
  };
98
78
 
@@ -134,7 +114,7 @@ export class CommunicatorReceiver {
134
114
  }
135
115
 
136
116
  this.queue.push(newQueueItem);
137
- }
117
+ };
138
118
 
139
119
  /**
140
120
  * Subscribe by code or target or action
@@ -159,18 +139,27 @@ export class CommunicatorReceiver {
159
139
  }
160
140
 
161
141
  return false;
162
- }
142
+ };
163
143
 
144
+ /**
145
+ * Get scenario for target
146
+ * @param target
147
+ */
164
148
  private getMessageScenario = (target: CommunicatorTargetEnum) => {
165
- let scenario = this.scenario[target];
149
+ const scenario = this.scenario[target];
166
150
 
167
151
  if (scenario) {
168
152
  return scenario;
169
153
  }
170
154
 
171
155
  return CommunicatorActionEnum_scenario();
172
- }
156
+ };
173
157
 
158
+ /**
159
+ * Change scenario for target
160
+ * @param target
161
+ * @param scenario
162
+ */
174
163
  public setMessageScenario = (target: CommunicatorTargetEnum, scenario: CommunicatorActionEnum[]) => {
175
164
  if (
176
165
  !CommunicatorTargetEnum_isCorrect(target) ||
@@ -185,9 +174,9 @@ export class CommunicatorReceiver {
185
174
  if (!CommunicatorActionEnum_isCorrect(item)) {
186
175
  throw new Error('WAC: failed scenario action!');
187
176
  }
188
- })
177
+ });
189
178
 
190
179
  this.scenario[target] = scenario;
191
- }
180
+ };
192
181
  }
193
182
 
@@ -1,6 +1,6 @@
1
- import {TCommunicatorMessage} from "../types";
1
+ import {TCommunicatorMessage, TReceiverMessageQueue} from "../types";
2
2
  import {CommunicatorTargetEnum_isCorrect} from "../enums/CommunicatorTargetEnum";
3
- import {CommunicatorActionEnum_isCorrect} from "../enums/CommunicatorActionEnum";
3
+ import {CommunicatorActionEnum, CommunicatorActionEnum_isCorrect} from "../enums/CommunicatorActionEnum";
4
4
 
5
5
  /**
6
6
  * @param address
@@ -14,7 +14,7 @@ export function modifyOrigin(address: string): string {
14
14
  } catch (_) {
15
15
  return null;
16
16
  }
17
- return url.origin;
17
+ return url.origin !== 'null' ? url.origin : null;
18
18
  }
19
19
 
20
20
  /**
@@ -39,3 +39,15 @@ export function isValidMessage(message: TCommunicatorMessage) {
39
39
 
40
40
  return isValidTarget && isValidActions;
41
41
  }
42
+
43
+ export function sortMessageQueue(queue: TReceiverMessageQueue, scenario: CommunicatorActionEnum[]) {
44
+ return queue.sort((a, b) => {
45
+ if (scenario.indexOf(a.action) > scenario.indexOf(b.action)) {
46
+ return 1;
47
+ }
48
+ if (scenario.indexOf(a.action) < scenario.indexOf(b.action)) {
49
+ return -1;
50
+ }
51
+ return 0;
52
+ });
53
+ }
@@ -1,4 +1,5 @@
1
1
  export enum CommunicatorActionEnum {
2
+ LOADED = 'loaded',
2
3
  TOKEN = 'token',
3
4
  RESIZE = 'resize',
4
5
  CLOSE = 'close',
@@ -10,6 +11,6 @@ export function CommunicatorActionEnum_isCorrect(item: string): boolean {
10
11
  return Object.values(CommunicatorActionEnum).includes(item as CommunicatorActionEnum);
11
12
  }
12
13
 
13
- export function CommunicatorActionEnum_scenario(): string[] {
14
- return Object.values(CommunicatorActionEnum);
14
+ export function CommunicatorActionEnum_scenario(): CommunicatorActionEnum[] {
15
+ return Object.values(CommunicatorActionEnum) as CommunicatorActionEnum[];
15
16
  }
package/src/index.ts CHANGED
@@ -1,7 +1,7 @@
1
- import {CommunicatorReceiver} from "./engine/CommunicatorReceiver"
2
- import {CommunicatorSender} from "./engine/CommunicatorSender"
3
- import {CommunicatorTargetEnum} from "./enums/CommunicatorTargetEnum"
4
- import {CommunicatorActionEnum} from "./enums/CommunicatorActionEnum"
1
+ import {CommunicatorReceiver} from "./engine/CommunicatorReceiver";
2
+ import {CommunicatorSender} from "./engine/CommunicatorSender";
3
+ import {CommunicatorTargetEnum} from "./enums/CommunicatorTargetEnum";
4
+ import {CommunicatorActionEnum} from "./enums/CommunicatorActionEnum";
5
5
  import * as types from "./types";
6
6
 
7
7
  export {
@@ -10,4 +10,4 @@ export {
10
10
  CommunicatorTargetEnum,
11
11
  CommunicatorActionEnum,
12
12
  types,
13
- }
13
+ };
package/src/receiver.ts CHANGED
@@ -1,6 +1,6 @@
1
- import {CommunicatorReceiver} from "./engine/CommunicatorReceiver"
2
- import {CommunicatorTargetEnum} from "./enums/CommunicatorTargetEnum"
3
- import {CommunicatorActionEnum} from "./enums/CommunicatorActionEnum"
1
+ import {CommunicatorReceiver} from "./engine/CommunicatorReceiver";
2
+ import {CommunicatorTargetEnum} from "./enums/CommunicatorTargetEnum";
3
+ import {CommunicatorActionEnum} from "./enums/CommunicatorActionEnum";
4
4
  import * as types from "./types";
5
5
  import {isValidMessage as communicatorMessageIsValid} from "./engine/utils";
6
6
 
@@ -10,4 +10,4 @@ export {
10
10
  CommunicatorActionEnum,
11
11
  types,
12
12
  communicatorMessageIsValid
13
- }
13
+ };
package/src/sender.ts CHANGED
@@ -1,6 +1,6 @@
1
- import {CommunicatorSender} from "./engine/CommunicatorSender"
2
- import {CommunicatorTargetEnum} from "./enums/CommunicatorTargetEnum"
3
- import {CommunicatorActionEnum} from "./enums/CommunicatorActionEnum"
1
+ import {CommunicatorSender} from "./engine/CommunicatorSender";
2
+ import {CommunicatorTargetEnum} from "./enums/CommunicatorTargetEnum";
3
+ import {CommunicatorActionEnum} from "./enums/CommunicatorActionEnum";
4
4
  import * as types from "./types";
5
5
 
6
6
  export {
@@ -8,4 +8,4 @@ export {
8
8
  CommunicatorTargetEnum,
9
9
  CommunicatorActionEnum,
10
10
  types,
11
- }
11
+ };
@@ -30,6 +30,7 @@ export type TCommunicatorActionGotoParams = {
30
30
  }
31
31
 
32
32
  export type TCommunicatorSenderActionMap = {
33
+ [CommunicatorActionEnum.LOADED]?: true,
33
34
  [CommunicatorActionEnum.TOKEN]?: TCommunicatorActionTokenParams,
34
35
  [CommunicatorActionEnum.RESIZE]?: TCommunicatorActionResizeParams,
35
36
  [CommunicatorActionEnum.GOTO]?: TCommunicatorActionGotoParams,
@@ -0,0 +1,44 @@
1
+ import {TCommunicatorMessage} from '../../src/types';
2
+ import {CommunicatorActionEnum, CommunicatorTargetEnum} from '../../src';
3
+
4
+ const normalMessage: TCommunicatorMessage = {
5
+ target: CommunicatorTargetEnum.SIGN_UP,
6
+ action: {
7
+ [CommunicatorActionEnum.OPEN]: CommunicatorTargetEnum.SIGN_IN,
8
+ [CommunicatorActionEnum.CLOSE]: true,
9
+ [CommunicatorActionEnum.GOTO]: {
10
+ url: 'google.com',
11
+ },
12
+ }
13
+ };
14
+
15
+ const messageWithInvalidTarget: TCommunicatorMessage = {
16
+ target: 'Invalid' as CommunicatorTargetEnum,
17
+ action: {
18
+ [CommunicatorActionEnum.OPEN]: CommunicatorTargetEnum.SIGN_IN,
19
+ [CommunicatorActionEnum.CLOSE]: true,
20
+ }
21
+ };
22
+
23
+ const messageWithInvalidAction: TCommunicatorMessage = {
24
+ target: CommunicatorTargetEnum.SIGN_UP,
25
+ action: {
26
+ ['Invalid' as CommunicatorActionEnum]: CommunicatorTargetEnum.SIGN_IN,
27
+ [CommunicatorActionEnum.CLOSE]: true,
28
+ }
29
+ };
30
+
31
+ const messageWithInvalidActionParams: TCommunicatorMessage = {
32
+ target: 'Invalid' as CommunicatorTargetEnum,
33
+ action: {
34
+ [CommunicatorActionEnum.OPEN]: 'failed' as CommunicatorTargetEnum,
35
+ [CommunicatorActionEnum.CLOSE]: true,
36
+ }
37
+ };
38
+
39
+ export {
40
+ normalMessage,
41
+ messageWithInvalidTarget,
42
+ messageWithInvalidAction,
43
+ messageWithInvalidActionParams
44
+ };
@@ -0,0 +1,165 @@
1
+ import {TReceiverMessageQueue} from '../../src/types';
2
+ import {CommunicatorActionEnum, CommunicatorTargetEnum} from '../../src';
3
+
4
+ const queueWithoutSorting: TReceiverMessageQueue = [
5
+ {
6
+ target: CommunicatorTargetEnum.SIGN_IN,
7
+ action: CommunicatorActionEnum.OPEN,
8
+ params: {
9
+ callback: () => {}
10
+ }
11
+ },
12
+ {
13
+ target: CommunicatorTargetEnum.SIGN_IN,
14
+ action: CommunicatorActionEnum.CLOSE,
15
+ params: {
16
+ callback: () => {}
17
+ }
18
+ },
19
+ {
20
+ target: CommunicatorTargetEnum.SIGN_IN,
21
+ action: CommunicatorActionEnum.GOTO,
22
+ params: {
23
+ callback: () => {}
24
+ }
25
+ },
26
+ {
27
+ target: CommunicatorTargetEnum.SIGN_IN,
28
+ action: CommunicatorActionEnum.TOKEN,
29
+ params: {
30
+ callback: () => {}
31
+ }
32
+ },
33
+ ];
34
+
35
+ const queueWithDefaultScenario: TReceiverMessageQueue = [
36
+ {
37
+ target: CommunicatorTargetEnum.SIGN_IN,
38
+ action: CommunicatorActionEnum.TOKEN,
39
+ params: {
40
+ callback: () => {}
41
+ }
42
+ },
43
+ {
44
+ target: CommunicatorTargetEnum.SIGN_IN,
45
+ action: CommunicatorActionEnum.CLOSE,
46
+ params: {
47
+ callback: () => {}
48
+ }
49
+ },
50
+ {
51
+ target: CommunicatorTargetEnum.SIGN_IN,
52
+ action: CommunicatorActionEnum.OPEN,
53
+ params: {
54
+ callback: () => {}
55
+ }
56
+ },
57
+ {
58
+ target: CommunicatorTargetEnum.SIGN_IN,
59
+ action: CommunicatorActionEnum.GOTO,
60
+ params: {
61
+ callback: () => {}
62
+ }
63
+ },
64
+ ];
65
+
66
+ const queueWithCustomScenario: TReceiverMessageQueue = [
67
+ {
68
+ target: CommunicatorTargetEnum.SIGN_IN,
69
+ action: CommunicatorActionEnum.OPEN,
70
+ params: {
71
+ callback: () => {}
72
+ }
73
+ },
74
+ {
75
+ target: CommunicatorTargetEnum.SIGN_IN,
76
+ action: CommunicatorActionEnum.CLOSE,
77
+ params: {
78
+ callback: () => {}
79
+ }
80
+ },
81
+ {
82
+ target: CommunicatorTargetEnum.SIGN_IN,
83
+ action: CommunicatorActionEnum.TOKEN,
84
+ params: {
85
+ callback: () => {}
86
+ }
87
+ },
88
+ {
89
+ target: CommunicatorTargetEnum.SIGN_IN,
90
+ action: CommunicatorActionEnum.GOTO,
91
+ params: {
92
+ callback: () => {}
93
+ }
94
+ },
95
+ ];
96
+
97
+ const queueWithCustomV2Scenario: TReceiverMessageQueue = [
98
+ {
99
+ target: CommunicatorTargetEnum.SIGN_IN,
100
+ action: CommunicatorActionEnum.CLOSE,
101
+ params: {
102
+ callback: () => {}
103
+ }
104
+ },
105
+ {
106
+ target: CommunicatorTargetEnum.SIGN_IN,
107
+ action: CommunicatorActionEnum.TOKEN,
108
+ params: {
109
+ callback: () => {}
110
+ }
111
+ },
112
+ {
113
+ target: CommunicatorTargetEnum.SIGN_IN,
114
+ action: CommunicatorActionEnum.OPEN,
115
+ params: {
116
+ callback: () => {}
117
+ }
118
+ },
119
+ {
120
+ target: CommunicatorTargetEnum.SIGN_IN,
121
+ action: CommunicatorActionEnum.GOTO,
122
+ params: {
123
+ callback: () => {}
124
+ }
125
+ },
126
+ ];
127
+
128
+ const queueWithCustomV3Scenario: TReceiverMessageQueue = [
129
+ {
130
+ target: CommunicatorTargetEnum.SIGN_IN,
131
+ action: CommunicatorActionEnum.OPEN,
132
+ params: {
133
+ callback: () => {}
134
+ }
135
+ },
136
+ {
137
+ target: CommunicatorTargetEnum.SIGN_IN,
138
+ action: CommunicatorActionEnum.CLOSE,
139
+ params: {
140
+ callback: () => {}
141
+ }
142
+ },
143
+ {
144
+ target: CommunicatorTargetEnum.SIGN_IN,
145
+ action: CommunicatorActionEnum.TOKEN,
146
+ params: {
147
+ callback: () => {}
148
+ }
149
+ },
150
+ {
151
+ target: CommunicatorTargetEnum.SIGN_IN,
152
+ action: CommunicatorActionEnum.GOTO,
153
+ params: {
154
+ callback: () => {}
155
+ }
156
+ },
157
+ ];
158
+
159
+ export {
160
+ queueWithoutSorting,
161
+ queueWithDefaultScenario,
162
+ queueWithCustomScenario,
163
+ queueWithCustomV2Scenario,
164
+ queueWithCustomV3Scenario,
165
+ };
@@ -0,0 +1,31 @@
1
+ import {CommunicatorActionEnum, CommunicatorActionEnum_scenario} from '../../src/enums/CommunicatorActionEnum';
2
+
3
+ const defaultScenario = CommunicatorActionEnum_scenario();
4
+
5
+ const scenarioCustom = [
6
+ CommunicatorActionEnum.CLOSE,
7
+ CommunicatorActionEnum.TOKEN,
8
+ CommunicatorActionEnum.GOTO,
9
+ ];
10
+
11
+ const scenarioCustomV2 = [
12
+ CommunicatorActionEnum.CLOSE,
13
+ CommunicatorActionEnum.TOKEN,
14
+ CommunicatorActionEnum.OPEN,
15
+ CommunicatorActionEnum.GOTO,
16
+ ];
17
+
18
+ const scenarioCustomV3 = [
19
+ CommunicatorActionEnum.OPEN,
20
+ CommunicatorActionEnum.CLOSE,
21
+ CommunicatorActionEnum.TOKEN,
22
+ CommunicatorActionEnum.OPEN,
23
+ CommunicatorActionEnum.GOTO,
24
+ ];
25
+
26
+ export {
27
+ defaultScenario,
28
+ scenarioCustom,
29
+ scenarioCustomV2,
30
+ scenarioCustomV3
31
+ };
@@ -0,0 +1,69 @@
1
+ import {isValidMessage, modifyOrigin, sortMessageQueue} from '../src/engine/utils';
2
+ import {
3
+ queueWithCustomScenario,
4
+ queueWithCustomV2Scenario, queueWithCustomV3Scenario,
5
+ queueWithDefaultScenario,
6
+ queueWithoutSorting
7
+ } from './testUnits/queue';
8
+ import {messageWithInvalidAction, messageWithInvalidTarget, normalMessage} from './testUnits/message';
9
+ import {scenarioCustom, defaultScenario, scenarioCustomV2, scenarioCustomV3} from './testUnits/scenario';
10
+
11
+ test('modifyOrigin', () => {
12
+ expect(modifyOrigin('google.com')).toBe('https://google.com');
13
+ expect(modifyOrigin('google.com/test')).toBe('https://google.com');
14
+ expect(modifyOrigin('https://google.com/')).toBe('https://google.com');
15
+ expect(modifyOrigin(' https://google.com/')).toBe('https://google.com');
16
+ expect(modifyOrigin('htts://google.com')).toBe(null);
17
+ });
18
+
19
+ describe('isValidMessage', () => {
20
+ it('message is valid', () => {
21
+ expect(isValidMessage(normalMessage)).toBeTruthy();
22
+ });
23
+
24
+ it('message has invalid target', () => {
25
+ expect(
26
+ isValidMessage(messageWithInvalidTarget)
27
+ ).toBeFalsy();
28
+ });
29
+
30
+ it('message has invalid action', () => {
31
+ expect(
32
+ isValidMessage(messageWithInvalidAction)
33
+ ).toBeFalsy();
34
+ });
35
+
36
+ // TODO: need validation action params
37
+ // it('Invalid Action Params', () => {
38
+ // expect(
39
+ // isValidMessage(messageWithInvalidActionParams)
40
+ // ).toBeFalsy();
41
+ // });
42
+ });
43
+
44
+ describe('sortMessageQueue', () => {
45
+ it('Default Sorting (Default scenario)', () => {
46
+ expect(
47
+ JSON.stringify(sortMessageQueue(queueWithoutSorting, defaultScenario))
48
+ ).toBe(JSON.stringify(queueWithDefaultScenario));
49
+ });
50
+
51
+ it('Custom Sorting (Not full scenario)', () => {
52
+ expect(
53
+ JSON.stringify(sortMessageQueue(queueWithoutSorting, scenarioCustom))
54
+ ).toBe(JSON.stringify(queueWithCustomScenario));
55
+ });
56
+
57
+ it('Custom Sorting (Full scenario)', () => {
58
+ expect(
59
+ JSON.stringify(sortMessageQueue(queueWithoutSorting, scenarioCustomV2))
60
+ ).toBe(JSON.stringify(queueWithCustomV2Scenario));
61
+ });
62
+
63
+ it('Custom Sorting (Full scenario with Doubling)', () => {
64
+ expect(
65
+ JSON.stringify(sortMessageQueue(queueWithoutSorting, scenarioCustomV3))
66
+ ).toBe(JSON.stringify(queueWithCustomV3Scenario));
67
+ });
68
+ });
69
+
package/tools/cleanup.js CHANGED
@@ -1,26 +1,26 @@
1
- /* eslint-disable */
2
- const fs = require('fs')
3
- const Path = require('path')
4
- /* eslint-enable */
1
+ /* eslint-disable @typescript-eslint/no-var-requires */
2
+ const fs = require('fs');
3
+ const Path = require('path');
4
+ /* eslint-enable @typescript-eslint/no-var-requires */
5
5
 
6
6
  const deleteFolderRecursive = (path) => {
7
7
  if (fs.existsSync(path)) {
8
8
  fs.readdirSync(path).forEach((file) => {
9
- const curPath = Path.join(path, file)
9
+ const curPath = Path.join(path, file);
10
10
  if (fs.lstatSync(curPath).isDirectory()) {
11
- deleteFolderRecursive(curPath)
11
+ deleteFolderRecursive(curPath);
12
12
  } else {
13
- fs.unlinkSync(curPath)
13
+ fs.unlinkSync(curPath);
14
14
  }
15
- })
16
- fs.rmdirSync(path)
15
+ });
16
+ fs.rmdirSync(path);
17
17
  }
18
- }
18
+ };
19
19
 
20
- const folder = process.argv.slice(2)[0]
20
+ const folder = process.argv.slice(2)[0];
21
21
 
22
22
  if (folder) {
23
- deleteFolderRecursive(Path.join(__dirname, '../dist', folder))
23
+ deleteFolderRecursive(Path.join(__dirname, '../dist', folder));
24
24
  } else {
25
- deleteFolderRecursive(Path.join(__dirname, '../dist'))
25
+ deleteFolderRecursive(Path.join(__dirname, '../dist'));
26
26
  }