@maxzima/wa-communicator 0.0.11 → 0.0.14
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 +16 -0
- package/.eslintrc.js +58 -0
- package/.gitattributes +29 -0
- package/.prettierignore +9 -0
- package/.prettierrc.js +16 -0
- package/config/tsconfig.esm.json +1 -1
- package/config/tsconfig.types.json +2 -2
- package/dist/engine/CommunicatorReceiver.js +6 -24
- package/dist/engine/utils.d.ts +3 -1
- package/dist/engine/utils.js +11 -0
- package/dist/enums/CommunicatorActionEnum.d.ts +1 -1
- package/dist/types/index.d.ts +1 -1
- package/jest.config.js +18 -0
- package/package.json +21 -3
- package/src/engine/CommunicatorReceiver.ts +21 -39
- package/src/engine/utils.ts +14 -2
- package/src/enums/CommunicatorActionEnum.ts +1 -1
- package/src/index.ts +5 -5
- package/src/receiver.ts +4 -4
- package/src/sender.ts +4 -4
- package/src/types/index.ts +1 -1
- package/test/testUnits/message.ts +44 -0
- package/test/testUnits/queue.ts +56 -0
- package/test/utiles.spec.ts +44 -0
- package/tools/cleanup.js +13 -13
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
|
package/.prettierignore
ADDED
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
|
+
}
|
package/config/tsconfig.esm.json
CHANGED
|
@@ -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
|
|
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
|
|
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 => {
|
|
@@ -70,6 +51,7 @@ export class CommunicatorReceiver {
|
|
|
70
51
|
item.action === params.action;
|
|
71
52
|
})) {
|
|
72
53
|
console.log(`WAB: subscribe is exists!`);
|
|
54
|
+
return;
|
|
73
55
|
}
|
|
74
56
|
const newQueueItem = {
|
|
75
57
|
target: params.target,
|
|
@@ -84,7 +66,7 @@ export class CommunicatorReceiver {
|
|
|
84
66
|
this.queue.push(newQueueItem);
|
|
85
67
|
};
|
|
86
68
|
this.unsubscribe = (params) => {
|
|
87
|
-
if (!params) {
|
|
69
|
+
if (!params || Object.keys(params).length === 0) {
|
|
88
70
|
this.queue = [];
|
|
89
71
|
return true;
|
|
90
72
|
}
|
|
@@ -101,7 +83,7 @@ export class CommunicatorReceiver {
|
|
|
101
83
|
return false;
|
|
102
84
|
};
|
|
103
85
|
this.getMessageScenario = (target) => {
|
|
104
|
-
|
|
86
|
+
const scenario = this.scenario[target];
|
|
105
87
|
if (scenario) {
|
|
106
88
|
return scenario;
|
|
107
89
|
}
|
package/dist/engine/utils.d.ts
CHANGED
|
@@ -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;
|
package/dist/engine/utils.js
CHANGED
|
@@ -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
|
+
}
|
|
@@ -6,4 +6,4 @@ export declare enum CommunicatorActionEnum {
|
|
|
6
6
|
GOTO = "goto"
|
|
7
7
|
}
|
|
8
8
|
export declare function CommunicatorActionEnum_isCorrect(item: string): boolean;
|
|
9
|
-
export declare function CommunicatorActionEnum_scenario():
|
|
9
|
+
export declare function CommunicatorActionEnum_scenario(): CommunicatorActionEnum[];
|
package/dist/types/index.d.ts
CHANGED
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.
|
|
2
|
+
"version": "0.0.14",
|
|
3
3
|
"name": "@maxzima/wa-communicator",
|
|
4
4
|
"description": "",
|
|
5
5
|
"author": "Noname",
|
|
@@ -13,16 +13,34 @@
|
|
|
13
13
|
"type": "git",
|
|
14
14
|
"url": ""
|
|
15
15
|
},
|
|
16
|
+
"publishConfig": {
|
|
17
|
+
"access": "public"
|
|
18
|
+
},
|
|
16
19
|
"scripts": {
|
|
17
|
-
"prepublishOnly": "npm run build",
|
|
20
|
+
"prepublishOnly": "npm run test && npm run build",
|
|
18
21
|
"clean": "node tools/cleanup",
|
|
19
22
|
"build": "npm run clean && run-p build:*",
|
|
20
23
|
"build:esm": "tsc -p config/tsconfig.esm.json",
|
|
21
24
|
"build:types": "tsc -p config/tsconfig.types.json",
|
|
22
|
-
"package": "npm run build"
|
|
25
|
+
"package": "npm run build",
|
|
26
|
+
"lint": "eslint --cache --ext .ts ./src",
|
|
27
|
+
"lint:fix": "npm run lint -- --fix",
|
|
28
|
+
"test": "jest --no-cache --runInBand"
|
|
23
29
|
},
|
|
24
30
|
"devDependencies": {
|
|
31
|
+
"@types/jest": "^28.1.8",
|
|
32
|
+
"@typescript-eslint/eslint-plugin": "^5.35.1",
|
|
33
|
+
"@typescript-eslint/parser": "^5.35.1",
|
|
34
|
+
"eslint": "^8.22.0",
|
|
35
|
+
"eslint-config-prettier": "^8.5.0",
|
|
36
|
+
"eslint-plugin-editorconfig": "^4.0.2",
|
|
37
|
+
"eslint-plugin-eslint-comments": "^3.2.0",
|
|
38
|
+
"eslint-plugin-import": "^2.26.0",
|
|
39
|
+
"eslint-plugin-prettier": "^4.2.1",
|
|
40
|
+
"jest": "^28.1.3",
|
|
25
41
|
"npm-run-all": "^4.1.5",
|
|
42
|
+
"prettier": "^2.7.1",
|
|
43
|
+
"ts-jest": "^28.0.8",
|
|
26
44
|
"typescript": "^4.7.4"
|
|
27
45
|
}
|
|
28
46
|
}
|
|
@@ -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,
|
|
@@ -14,14 +14,6 @@ import {
|
|
|
14
14
|
CommunicatorActionEnum_scenario
|
|
15
15
|
} from '../enums/CommunicatorActionEnum';
|
|
16
16
|
|
|
17
|
-
// const defaultScenario = [
|
|
18
|
-
// CommunicatorActionEnum.TOKEN,
|
|
19
|
-
// CommunicatorActionEnum.RESIZE,
|
|
20
|
-
// CommunicatorActionEnum.GOTO,
|
|
21
|
-
// CommunicatorActionEnum.CLOSE,
|
|
22
|
-
// CommunicatorActionEnum.OPEN,
|
|
23
|
-
// ];
|
|
24
|
-
|
|
25
17
|
export class CommunicatorReceiver {
|
|
26
18
|
private readonly senderOrigin: string;
|
|
27
19
|
private queue: TReceiverMessageQueue = [];
|
|
@@ -63,36 +55,16 @@ export class CommunicatorReceiver {
|
|
|
63
55
|
return;
|
|
64
56
|
}
|
|
65
57
|
|
|
66
|
-
// Find queue by target and action
|
|
67
58
|
const queue = this.queue.filter(item => item.target === message.target && message.action.hasOwnProperty(item.action));
|
|
68
59
|
|
|
69
60
|
// default sort queue
|
|
70
61
|
const defaultScenario = CommunicatorActionEnum_scenario();
|
|
71
|
-
let sortedQueue = queue
|
|
72
|
-
if (defaultScenario.indexOf(a.action) > defaultScenario.indexOf(b.action)) {
|
|
73
|
-
return -1;
|
|
74
|
-
}
|
|
75
|
-
if (defaultScenario.indexOf(a.action) < defaultScenario.indexOf(b.action)) {
|
|
76
|
-
return 1;
|
|
77
|
-
}
|
|
78
|
-
return 0;
|
|
79
|
-
})
|
|
62
|
+
let sortedQueue = sortMessageQueue(queue, defaultScenario);
|
|
80
63
|
|
|
81
64
|
// sort queue
|
|
82
65
|
const scenario = this.getMessageScenario(message.target);
|
|
83
66
|
if (defaultScenario !== scenario) {
|
|
84
|
-
sortedQueue = queue
|
|
85
|
-
if (scenario.indexOf(a.action) === -1 || scenario.indexOf(b.action) === -1) {
|
|
86
|
-
return 0;
|
|
87
|
-
}
|
|
88
|
-
if (scenario.indexOf(a.action) > scenario.indexOf(b.action)) {
|
|
89
|
-
return 1;
|
|
90
|
-
}
|
|
91
|
-
if (scenario.indexOf(a.action) < scenario.indexOf(b.action)) {
|
|
92
|
-
return -1;
|
|
93
|
-
}
|
|
94
|
-
return 0;
|
|
95
|
-
})
|
|
67
|
+
sortedQueue = sortMessageQueue(queue, scenario);
|
|
96
68
|
}
|
|
97
69
|
|
|
98
70
|
if (sortedQueue.length) {
|
|
@@ -100,7 +72,7 @@ export class CommunicatorReceiver {
|
|
|
100
72
|
if (typeof item.params.callback === 'function') {
|
|
101
73
|
item.params.callback(message);
|
|
102
74
|
}
|
|
103
|
-
})
|
|
75
|
+
});
|
|
104
76
|
}
|
|
105
77
|
};
|
|
106
78
|
|
|
@@ -126,6 +98,7 @@ export class CommunicatorReceiver {
|
|
|
126
98
|
item.action === params.action;
|
|
127
99
|
})) {
|
|
128
100
|
console.log(`WAB: subscribe is exists!`);
|
|
101
|
+
return;
|
|
129
102
|
}
|
|
130
103
|
|
|
131
104
|
const newQueueItem = {
|
|
@@ -141,14 +114,14 @@ export class CommunicatorReceiver {
|
|
|
141
114
|
}
|
|
142
115
|
|
|
143
116
|
this.queue.push(newQueueItem);
|
|
144
|
-
}
|
|
117
|
+
};
|
|
145
118
|
|
|
146
119
|
/**
|
|
147
120
|
* Subscribe by code or target or action
|
|
148
121
|
* @param params
|
|
149
122
|
*/
|
|
150
123
|
public unsubscribe = (params?: TReceiverUnsubscribeMessageParams): boolean => {
|
|
151
|
-
if (!params) {
|
|
124
|
+
if (!params || Object.keys(params).length === 0) {
|
|
152
125
|
this.queue = [];
|
|
153
126
|
return true;
|
|
154
127
|
}
|
|
@@ -166,18 +139,27 @@ export class CommunicatorReceiver {
|
|
|
166
139
|
}
|
|
167
140
|
|
|
168
141
|
return false;
|
|
169
|
-
}
|
|
142
|
+
};
|
|
170
143
|
|
|
144
|
+
/**
|
|
145
|
+
* Get scenario for target
|
|
146
|
+
* @param target
|
|
147
|
+
*/
|
|
171
148
|
private getMessageScenario = (target: CommunicatorTargetEnum) => {
|
|
172
|
-
|
|
149
|
+
const scenario = this.scenario[target];
|
|
173
150
|
|
|
174
151
|
if (scenario) {
|
|
175
152
|
return scenario;
|
|
176
153
|
}
|
|
177
154
|
|
|
178
155
|
return CommunicatorActionEnum_scenario();
|
|
179
|
-
}
|
|
156
|
+
};
|
|
180
157
|
|
|
158
|
+
/**
|
|
159
|
+
* Change scenario for target
|
|
160
|
+
* @param target
|
|
161
|
+
* @param scenario
|
|
162
|
+
*/
|
|
181
163
|
public setMessageScenario = (target: CommunicatorTargetEnum, scenario: CommunicatorActionEnum[]) => {
|
|
182
164
|
if (
|
|
183
165
|
!CommunicatorTargetEnum_isCorrect(target) ||
|
|
@@ -192,9 +174,9 @@ export class CommunicatorReceiver {
|
|
|
192
174
|
if (!CommunicatorActionEnum_isCorrect(item)) {
|
|
193
175
|
throw new Error('WAC: failed scenario action!');
|
|
194
176
|
}
|
|
195
|
-
})
|
|
177
|
+
});
|
|
196
178
|
|
|
197
179
|
this.scenario[target] = scenario;
|
|
198
|
-
}
|
|
180
|
+
};
|
|
199
181
|
}
|
|
200
182
|
|
package/src/engine/utils.ts
CHANGED
|
@@ -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
|
|
@@ -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
|
+
}
|
|
@@ -10,6 +10,6 @@ export function CommunicatorActionEnum_isCorrect(item: string): boolean {
|
|
|
10
10
|
return Object.values(CommunicatorActionEnum).includes(item as CommunicatorActionEnum);
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
export function CommunicatorActionEnum_scenario():
|
|
13
|
+
export function CommunicatorActionEnum_scenario(): CommunicatorActionEnum[] {
|
|
14
14
|
return Object.values(CommunicatorActionEnum);
|
|
15
15
|
}
|
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
|
+
};
|
package/src/types/index.ts
CHANGED
|
@@ -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,56 @@
|
|
|
1
|
+
import {TReceiverMessageQueue} from '../../src/types';
|
|
2
|
+
import {CommunicatorActionEnum, CommunicatorTargetEnum} from '../../src';
|
|
3
|
+
|
|
4
|
+
const getQueue = (isDefaultSort = false): TReceiverMessageQueue => {
|
|
5
|
+
if (isDefaultSort) {
|
|
6
|
+
return [
|
|
7
|
+
{
|
|
8
|
+
target: CommunicatorTargetEnum.SIGN_IN,
|
|
9
|
+
action: CommunicatorActionEnum.CLOSE,
|
|
10
|
+
params: {
|
|
11
|
+
callback: () => {}
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
target: CommunicatorTargetEnum.SIGN_IN,
|
|
16
|
+
action: CommunicatorActionEnum.OPEN,
|
|
17
|
+
params: {
|
|
18
|
+
callback: () => {}
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
target: CommunicatorTargetEnum.SIGN_IN,
|
|
23
|
+
action: CommunicatorActionEnum.GOTO,
|
|
24
|
+
params: {
|
|
25
|
+
callback: () => {}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
];
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return [
|
|
32
|
+
{
|
|
33
|
+
target: CommunicatorTargetEnum.SIGN_IN,
|
|
34
|
+
action: CommunicatorActionEnum.OPEN,
|
|
35
|
+
params: {
|
|
36
|
+
callback: () => {}
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
target: CommunicatorTargetEnum.SIGN_IN,
|
|
41
|
+
action: CommunicatorActionEnum.CLOSE,
|
|
42
|
+
params: {
|
|
43
|
+
callback: () => {}
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
target: CommunicatorTargetEnum.SIGN_IN,
|
|
48
|
+
action: CommunicatorActionEnum.GOTO,
|
|
49
|
+
params: {
|
|
50
|
+
callback: () => {}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
];
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
export default getQueue;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import {isValidMessage, modifyOrigin, sortMessageQueue} from '../src/engine/utils';
|
|
2
|
+
import {CommunicatorActionEnum_scenario} from '../src/enums/CommunicatorActionEnum';
|
|
3
|
+
import getQueue from './testUnits/queue';
|
|
4
|
+
import {messageWithInvalidAction, messageWithInvalidTarget, normalMessage} from './testUnits/message';
|
|
5
|
+
|
|
6
|
+
test('modifyOrigin', () => {
|
|
7
|
+
expect(modifyOrigin('google.com')).toBe('https://google.com');
|
|
8
|
+
expect(modifyOrigin('google.com/test')).toBe('https://google.com');
|
|
9
|
+
expect(modifyOrigin('https://google.com/')).toBe('https://google.com');
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
describe('isValidMessage', () => {
|
|
13
|
+
it('message is valid', () => {
|
|
14
|
+
expect(isValidMessage(normalMessage)).toBeTruthy();
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it('message has invalid target', () => {
|
|
18
|
+
expect(
|
|
19
|
+
isValidMessage(messageWithInvalidTarget)
|
|
20
|
+
).toBeFalsy();
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it('message has invalid action', () => {
|
|
24
|
+
expect(
|
|
25
|
+
isValidMessage(messageWithInvalidAction)
|
|
26
|
+
).toBeFalsy();
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
// TODO: need validation action params
|
|
30
|
+
// it('Invalid Action Params', () => {
|
|
31
|
+
// expect(
|
|
32
|
+
// isValidMessage(messageWithInvalidActionParams)
|
|
33
|
+
// ).toBeFalsy();
|
|
34
|
+
// });
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
describe('sortMessageQueue', () => {
|
|
38
|
+
it('Default Sorting', () => {
|
|
39
|
+
expect(
|
|
40
|
+
JSON.stringify(sortMessageQueue(getQueue(), CommunicatorActionEnum_scenario()))
|
|
41
|
+
).toBe(JSON.stringify(getQueue(true)));
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
|
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
|
}
|