@maxzima/wa-communicator 0.0.14 → 0.0.17
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/dist/engine/utils.js +1 -1
- package/dist/enums/CommunicatorActionEnum.d.ts +2 -0
- package/dist/enums/CommunicatorActionEnum.js +2 -0
- package/dist/types/index.d.ts +2 -0
- package/package.json +20 -3
- package/src/engine/utils.ts +1 -1
- package/src/enums/CommunicatorActionEnum.ts +3 -1
- package/src/types/index.ts +2 -0
- package/test/testUnits/queue.ts +160 -51
- package/test/testUnits/scenario.ts +31 -0
- package/test/utiles.spec.ts +30 -5
package/dist/engine/utils.js
CHANGED
|
@@ -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);
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
export var CommunicatorActionEnum;
|
|
2
2
|
(function (CommunicatorActionEnum) {
|
|
3
|
+
CommunicatorActionEnum["LOADED"] = "loaded";
|
|
4
|
+
CommunicatorActionEnum["BLUR"] = "blur";
|
|
3
5
|
CommunicatorActionEnum["TOKEN"] = "token";
|
|
4
6
|
CommunicatorActionEnum["RESIZE"] = "resize";
|
|
5
7
|
CommunicatorActionEnum["CLOSE"] = "close";
|
package/dist/types/index.d.ts
CHANGED
|
@@ -23,6 +23,8 @@ export declare type TCommunicatorActionGotoParams = {
|
|
|
23
23
|
isTargetBlank?: boolean;
|
|
24
24
|
};
|
|
25
25
|
export declare type TCommunicatorSenderActionMap = {
|
|
26
|
+
[CommunicatorActionEnum.LOADED]?: true;
|
|
27
|
+
[CommunicatorActionEnum.BLUR]?: true;
|
|
26
28
|
[CommunicatorActionEnum.TOKEN]?: TCommunicatorActionTokenParams;
|
|
27
29
|
[CommunicatorActionEnum.RESIZE]?: TCommunicatorActionResizeParams;
|
|
28
30
|
[CommunicatorActionEnum.GOTO]?: TCommunicatorActionGotoParams;
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "0.0.
|
|
2
|
+
"version": "0.0.17",
|
|
3
3
|
"name": "@maxzima/wa-communicator",
|
|
4
4
|
"description": "",
|
|
5
5
|
"author": "Noname",
|
|
@@ -16,8 +16,22 @@
|
|
|
16
16
|
"publishConfig": {
|
|
17
17
|
"access": "public"
|
|
18
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
|
+
],
|
|
19
33
|
"scripts": {
|
|
20
|
-
"prepublishOnly": "npm run test && npm run build",
|
|
34
|
+
"prepublishOnly": "npm run test && npm run build && npm run size",
|
|
21
35
|
"clean": "node tools/cleanup",
|
|
22
36
|
"build": "npm run clean && run-p build:*",
|
|
23
37
|
"build:esm": "tsc -p config/tsconfig.esm.json",
|
|
@@ -25,9 +39,11 @@
|
|
|
25
39
|
"package": "npm run build",
|
|
26
40
|
"lint": "eslint --cache --ext .ts ./src",
|
|
27
41
|
"lint:fix": "npm run lint -- --fix",
|
|
28
|
-
"test": "jest --no-cache --runInBand"
|
|
42
|
+
"test": "jest --no-cache --runInBand",
|
|
43
|
+
"size": "size-limit"
|
|
29
44
|
},
|
|
30
45
|
"devDependencies": {
|
|
46
|
+
"@size-limit/preset-small-lib": "^8.1.0",
|
|
31
47
|
"@types/jest": "^28.1.8",
|
|
32
48
|
"@typescript-eslint/eslint-plugin": "^5.35.1",
|
|
33
49
|
"@typescript-eslint/parser": "^5.35.1",
|
|
@@ -40,6 +56,7 @@
|
|
|
40
56
|
"jest": "^28.1.3",
|
|
41
57
|
"npm-run-all": "^4.1.5",
|
|
42
58
|
"prettier": "^2.7.1",
|
|
59
|
+
"size-limit": "^8.1.0",
|
|
43
60
|
"ts-jest": "^28.0.8",
|
|
44
61
|
"typescript": "^4.7.4"
|
|
45
62
|
}
|
package/src/engine/utils.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
export enum CommunicatorActionEnum {
|
|
2
|
+
LOADED = 'loaded',
|
|
3
|
+
BLUR = 'blur',
|
|
2
4
|
TOKEN = 'token',
|
|
3
5
|
RESIZE = 'resize',
|
|
4
6
|
CLOSE = 'close',
|
|
@@ -11,5 +13,5 @@ export function CommunicatorActionEnum_isCorrect(item: string): boolean {
|
|
|
11
13
|
}
|
|
12
14
|
|
|
13
15
|
export function CommunicatorActionEnum_scenario(): CommunicatorActionEnum[] {
|
|
14
|
-
return Object.values(CommunicatorActionEnum);
|
|
16
|
+
return Object.values(CommunicatorActionEnum) as CommunicatorActionEnum[];
|
|
15
17
|
}
|
package/src/types/index.ts
CHANGED
|
@@ -30,6 +30,8 @@ export type TCommunicatorActionGotoParams = {
|
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
export type TCommunicatorSenderActionMap = {
|
|
33
|
+
[CommunicatorActionEnum.LOADED]?: true,
|
|
34
|
+
[CommunicatorActionEnum.BLUR]?: true,
|
|
33
35
|
[CommunicatorActionEnum.TOKEN]?: TCommunicatorActionTokenParams,
|
|
34
36
|
[CommunicatorActionEnum.RESIZE]?: TCommunicatorActionResizeParams,
|
|
35
37
|
[CommunicatorActionEnum.GOTO]?: TCommunicatorActionGotoParams,
|
package/test/testUnits/queue.ts
CHANGED
|
@@ -1,56 +1,165 @@
|
|
|
1
1
|
import {TReceiverMessageQueue} from '../../src/types';
|
|
2
2
|
import {CommunicatorActionEnum, CommunicatorTargetEnum} from '../../src';
|
|
3
3
|
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
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
|
+
];
|
|
30
34
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
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
|
+
];
|
|
55
65
|
|
|
56
|
-
|
|
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
|
+
};
|
package/test/utiles.spec.ts
CHANGED
|
@@ -1,12 +1,19 @@
|
|
|
1
1
|
import {isValidMessage, modifyOrigin, sortMessageQueue} from '../src/engine/utils';
|
|
2
|
-
import {
|
|
3
|
-
|
|
2
|
+
import {
|
|
3
|
+
queueWithCustomScenario,
|
|
4
|
+
queueWithCustomV2Scenario, queueWithCustomV3Scenario,
|
|
5
|
+
queueWithDefaultScenario,
|
|
6
|
+
queueWithoutSorting
|
|
7
|
+
} from './testUnits/queue';
|
|
4
8
|
import {messageWithInvalidAction, messageWithInvalidTarget, normalMessage} from './testUnits/message';
|
|
9
|
+
import {scenarioCustom, defaultScenario, scenarioCustomV2, scenarioCustomV3} from './testUnits/scenario';
|
|
5
10
|
|
|
6
11
|
test('modifyOrigin', () => {
|
|
7
12
|
expect(modifyOrigin('google.com')).toBe('https://google.com');
|
|
8
13
|
expect(modifyOrigin('google.com/test')).toBe('https://google.com');
|
|
9
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);
|
|
10
17
|
});
|
|
11
18
|
|
|
12
19
|
describe('isValidMessage', () => {
|
|
@@ -35,10 +42,28 @@ describe('isValidMessage', () => {
|
|
|
35
42
|
});
|
|
36
43
|
|
|
37
44
|
describe('sortMessageQueue', () => {
|
|
38
|
-
it('Default Sorting', () => {
|
|
45
|
+
it('Default Sorting (Default scenario)', () => {
|
|
39
46
|
expect(
|
|
40
|
-
JSON.stringify(sortMessageQueue(
|
|
41
|
-
).toBe(JSON.stringify(
|
|
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));
|
|
42
67
|
});
|
|
43
68
|
});
|
|
44
69
|
|