@maxzima/wa-communicator 0.0.2 → 0.0.7
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/README.md +44 -19
- package/config/tsconfig.esm.json +10 -0
- package/config/tsconfig.types.json +8 -0
- package/dist/engine/CommunicatorReceiver.d.ts +8 -0
- package/dist/engine/CommunicatorReceiver.js +29 -0
- package/dist/engine/CommunicatorSender.d.ts +7 -0
- package/dist/engine/CommunicatorSender.js +16 -0
- package/dist/engine/utils.d.ts +1 -0
- package/dist/engine/utils.js +12 -0
- package/dist/enums/CommunicatorActionEnum.d.ts +7 -0
- package/dist/enums/CommunicatorActionEnum.js +10 -0
- package/dist/enums/CommunicatorTargetEnum.d.ts +5 -0
- package/dist/enums/CommunicatorTargetEnum.js +8 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +6 -0
- package/dist/receiver.d.ts +5 -0
- package/dist/receiver.js +5 -0
- package/dist/sender.d.ts +5 -0
- package/dist/sender.js +5 -0
- package/dist/types/index.d.ts +29 -0
- package/dist/types/index.js +1 -0
- package/package.json +13 -4
- package/src/engine/CommunicatorReceiver.ts +8 -10
- package/src/engine/CommunicatorSender.ts +11 -7
- package/src/{utils.ts → engine/utils.ts} +0 -0
- package/src/enums/CommunicatorActionEnum.ts +8 -7
- package/src/enums/CommunicatorTargetEnum.ts +6 -5
- package/src/receiver.ts +11 -0
- package/src/sender.ts +11 -0
- package/src/types/index.ts +36 -0
- package/tools/cleanup.js +26 -0
- package/tsconfig.json +4 -9
- package/src/enums/BaseEnum.ts +0 -36
- package/src/types.ts +0 -43
package/README.md
CHANGED
|
@@ -1,36 +1,61 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Import communicator modules
|
|
2
|
+
|
|
3
|
+
Import all
|
|
4
|
+
```javascript
|
|
5
|
+
import {
|
|
6
|
+
CommunicatorReceiver,
|
|
7
|
+
CommunicatorSender,
|
|
8
|
+
CommunicatorTargetEnum,
|
|
9
|
+
CommunicatorActionEnum,
|
|
10
|
+
} from '@maxzima/wa-communicator';
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Import only sender
|
|
14
|
+
```javascript
|
|
15
|
+
import {
|
|
16
|
+
CommunicatorSender,
|
|
17
|
+
CommunicatorTargetEnum,
|
|
18
|
+
CommunicatorActionEnum,
|
|
19
|
+
} from '@maxzima/wa-communicator/dit/sender';
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
Import only receiver
|
|
23
|
+
```javascript
|
|
24
|
+
import {
|
|
25
|
+
CommunicatorReceiver,
|
|
26
|
+
CommunicatorTargetEnum,
|
|
27
|
+
CommunicatorActionEnum,
|
|
28
|
+
} from '@maxzima/wa-communicator';
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
# Usage Sender
|
|
2
32
|
|
|
3
33
|
```javascript
|
|
4
34
|
const communicator = new CommunicatorSender({
|
|
5
|
-
|
|
35
|
+
receiverOrigin: 'google.com',
|
|
6
36
|
otherWindow: window.parent,
|
|
7
37
|
});
|
|
8
38
|
|
|
9
39
|
communicator.sendMessage({
|
|
10
|
-
target:
|
|
11
|
-
action:
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
19
|
-
]
|
|
40
|
+
target: CommunicatorTargetEnum.SIGN_UP,
|
|
41
|
+
action: {
|
|
42
|
+
[CommunicatorActionEnum.CLOSE]: true,
|
|
43
|
+
[CommunicatorActionEnum.GOTO]: {
|
|
44
|
+
url: 'clients.google.com',
|
|
45
|
+
isTargetBlank: true
|
|
46
|
+
},
|
|
47
|
+
}
|
|
20
48
|
});
|
|
21
49
|
```
|
|
22
50
|
|
|
23
|
-
# Receiver
|
|
51
|
+
# Usage Receiver
|
|
24
52
|
|
|
25
53
|
```javascript
|
|
26
54
|
const communicator = new CommunicatorReceiver({
|
|
55
|
+
senderOrigin: 'clients.google.com',
|
|
27
56
|
callback: (message) => {
|
|
28
|
-
if (message.target ===
|
|
29
|
-
message.action.
|
|
30
|
-
if (action.key === CommunicatorActionEnum.GOTO) {
|
|
31
|
-
window.location = action.params['url'];
|
|
32
|
-
}
|
|
33
|
-
})
|
|
57
|
+
if (message.target === CommunicatorTargetEnum.SIGN_UP && message.action[CommunicatorActionEnum.GOTO]) {
|
|
58
|
+
window.location.href = message.action[CommunicatorActionEnum.GOTO].url;
|
|
34
59
|
}
|
|
35
60
|
}
|
|
36
61
|
});
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export class CommunicatorReceiver {
|
|
2
|
+
constructor(props) {
|
|
3
|
+
this.onMessage = (event) => {
|
|
4
|
+
if (!event || !event.origin || !event.data) {
|
|
5
|
+
return;
|
|
6
|
+
}
|
|
7
|
+
let message;
|
|
8
|
+
try {
|
|
9
|
+
message = JSON.parse(event.data);
|
|
10
|
+
}
|
|
11
|
+
catch (error) {
|
|
12
|
+
console.log('PostMessage read error');
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
if (this.senderOrigin !== event.origin) {
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
if (typeof this.callback !== 'function') {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
this.callback(message);
|
|
22
|
+
};
|
|
23
|
+
this.callback = props.callback;
|
|
24
|
+
this.senderOrigin = props.senderOrigin;
|
|
25
|
+
}
|
|
26
|
+
watch() {
|
|
27
|
+
window.addEventListener('message', this.onMessage, false);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { modifyUrl } from './utils';
|
|
2
|
+
import { CommunicatorTargetEnum_isCorrect } from '../enums/CommunicatorTargetEnum';
|
|
3
|
+
export class CommunicatorSender {
|
|
4
|
+
constructor(props) {
|
|
5
|
+
this.otherWindow = props.otherWindow;
|
|
6
|
+
this.receiverOrigin = modifyUrl(props.receiverOrigin);
|
|
7
|
+
}
|
|
8
|
+
sendMessage(message) {
|
|
9
|
+
if (!this.receiverOrigin ||
|
|
10
|
+
!CommunicatorTargetEnum_isCorrect(message.target)) {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
const jsonMessage = JSON.stringify(message);
|
|
14
|
+
this.otherWindow.postMessage(jsonMessage, this.receiverOrigin);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function modifyUrl(address: string): string;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export function modifyUrl(address) {
|
|
2
|
+
let url;
|
|
3
|
+
try {
|
|
4
|
+
let targetOrigin = address.trim();
|
|
5
|
+
targetOrigin = (targetOrigin.indexOf('://') === -1) ? 'https://' + targetOrigin : targetOrigin;
|
|
6
|
+
url = new URL(targetOrigin);
|
|
7
|
+
}
|
|
8
|
+
catch (_) {
|
|
9
|
+
return null;
|
|
10
|
+
}
|
|
11
|
+
return url.toString();
|
|
12
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export var CommunicatorActionEnum;
|
|
2
|
+
(function (CommunicatorActionEnum) {
|
|
3
|
+
CommunicatorActionEnum["CLOSE"] = "close";
|
|
4
|
+
CommunicatorActionEnum["OPEN"] = "open";
|
|
5
|
+
CommunicatorActionEnum["GOTO"] = "goto";
|
|
6
|
+
CommunicatorActionEnum["RESIZE"] = "resize";
|
|
7
|
+
})(CommunicatorActionEnum || (CommunicatorActionEnum = {}));
|
|
8
|
+
export function CommunicatorActionEnum_isCorrect(item) {
|
|
9
|
+
return Object.values(CommunicatorActionEnum).includes(item);
|
|
10
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export var CommunicatorTargetEnum;
|
|
2
|
+
(function (CommunicatorTargetEnum) {
|
|
3
|
+
CommunicatorTargetEnum["SIGN_UP"] = "sign_up";
|
|
4
|
+
CommunicatorTargetEnum["SIGN_IN"] = "sign_in";
|
|
5
|
+
})(CommunicatorTargetEnum || (CommunicatorTargetEnum = {}));
|
|
6
|
+
export function CommunicatorTargetEnum_isCorrect(item) {
|
|
7
|
+
return Object.values(CommunicatorTargetEnum).includes(item);
|
|
8
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
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
|
+
import * as types from "./types";
|
|
6
|
+
export { CommunicatorReceiver, CommunicatorSender, CommunicatorTargetEnum, CommunicatorActionEnum, types, };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
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
|
+
import * as types from "./types";
|
|
6
|
+
export { CommunicatorReceiver, CommunicatorSender, CommunicatorTargetEnum, CommunicatorActionEnum, types, };
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { CommunicatorReceiver } from "./engine/CommunicatorReceiver";
|
|
2
|
+
import { CommunicatorTargetEnum } from "./enums/CommunicatorTargetEnum";
|
|
3
|
+
import { CommunicatorActionEnum } from "./enums/CommunicatorActionEnum";
|
|
4
|
+
import * as types from "./types";
|
|
5
|
+
export { CommunicatorReceiver, CommunicatorTargetEnum, CommunicatorActionEnum, types, };
|
package/dist/receiver.js
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { CommunicatorReceiver } from "./engine/CommunicatorReceiver";
|
|
2
|
+
import { CommunicatorTargetEnum } from "./enums/CommunicatorTargetEnum";
|
|
3
|
+
import { CommunicatorActionEnum } from "./enums/CommunicatorActionEnum";
|
|
4
|
+
import * as types from "./types";
|
|
5
|
+
export { CommunicatorReceiver, CommunicatorTargetEnum, CommunicatorActionEnum, types, };
|
package/dist/sender.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { CommunicatorSender } from "./engine/CommunicatorSender";
|
|
2
|
+
import { CommunicatorTargetEnum } from "./enums/CommunicatorTargetEnum";
|
|
3
|
+
import { CommunicatorActionEnum } from "./enums/CommunicatorActionEnum";
|
|
4
|
+
import * as types from "./types";
|
|
5
|
+
export { CommunicatorSender, CommunicatorTargetEnum, CommunicatorActionEnum, types, };
|
package/dist/sender.js
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { CommunicatorSender } from "./engine/CommunicatorSender";
|
|
2
|
+
import { CommunicatorTargetEnum } from "./enums/CommunicatorTargetEnum";
|
|
3
|
+
import { CommunicatorActionEnum } from "./enums/CommunicatorActionEnum";
|
|
4
|
+
import * as types from "./types";
|
|
5
|
+
export { CommunicatorSender, CommunicatorTargetEnum, CommunicatorActionEnum, types, };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { CommunicatorActionEnum } from "../enums/CommunicatorActionEnum";
|
|
2
|
+
import { CommunicatorTargetEnum } from "../enums/CommunicatorTargetEnum";
|
|
3
|
+
export declare type TSenderProps = {
|
|
4
|
+
receiverOrigin: string;
|
|
5
|
+
otherWindow: Window;
|
|
6
|
+
};
|
|
7
|
+
export declare type TReceiverProps = {
|
|
8
|
+
callback: TReceiverCallback;
|
|
9
|
+
senderOrigin: string;
|
|
10
|
+
};
|
|
11
|
+
export declare type TReceiverCallback = (message: TCommunicatorMessage) => void;
|
|
12
|
+
export declare type TCommunicatorActionResizeParams = {
|
|
13
|
+
width?: number;
|
|
14
|
+
height?: number;
|
|
15
|
+
};
|
|
16
|
+
export declare type TCommunicatorActionGotoParams = {
|
|
17
|
+
url: string;
|
|
18
|
+
isTargetBlank?: boolean;
|
|
19
|
+
};
|
|
20
|
+
export declare type TCommunicatorSenderActionMap = {
|
|
21
|
+
[CommunicatorActionEnum.RESIZE]?: TCommunicatorActionResizeParams;
|
|
22
|
+
[CommunicatorActionEnum.GOTO]?: TCommunicatorActionGotoParams;
|
|
23
|
+
[CommunicatorActionEnum.CLOSE]?: true;
|
|
24
|
+
[CommunicatorActionEnum.OPEN]?: CommunicatorTargetEnum;
|
|
25
|
+
};
|
|
26
|
+
export declare type TCommunicatorMessage = {
|
|
27
|
+
target: CommunicatorTargetEnum;
|
|
28
|
+
action: TCommunicatorSenderActionMap;
|
|
29
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import { CommunicatorActionEnum } from "../enums/CommunicatorActionEnum";
|
package/package.json
CHANGED
|
@@ -1,19 +1,28 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "0.0.
|
|
2
|
+
"version": "0.0.7",
|
|
3
3
|
"name": "@maxzima/wa-communicator",
|
|
4
4
|
"description": "",
|
|
5
5
|
"author": "Noname",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"main": "dist/index.js",
|
|
8
|
-
"types": "dist/index.d.
|
|
8
|
+
"types": "dist/index.d.js",
|
|
9
9
|
"engines": {
|
|
10
10
|
"node": ">=14"
|
|
11
11
|
},
|
|
12
|
+
"repository": {
|
|
13
|
+
"type": "git",
|
|
14
|
+
"url": ""
|
|
15
|
+
},
|
|
12
16
|
"scripts": {
|
|
13
|
-
"
|
|
14
|
-
"
|
|
17
|
+
"prepublishOnly": "npm run build",
|
|
18
|
+
"clean": "node tools/cleanup",
|
|
19
|
+
"build": "npm run clean && run-p build:*",
|
|
20
|
+
"build:esm": "tsc -p config/tsconfig.esm.json",
|
|
21
|
+
"build:types": "tsc -p config/tsconfig.types.json",
|
|
22
|
+
"package": "npm run build"
|
|
15
23
|
},
|
|
16
24
|
"devDependencies": {
|
|
25
|
+
"npm-run-all": "^4.1.5",
|
|
17
26
|
"typescript": "^4.7.4"
|
|
18
27
|
}
|
|
19
28
|
}
|
|
@@ -1,24 +1,26 @@
|
|
|
1
|
-
import {TCommunicatorMessage, TReceiverProps} from '../types';
|
|
1
|
+
import {TCommunicatorMessage, TReceiverCallback, TReceiverProps} from '../types';
|
|
2
2
|
|
|
3
3
|
export class CommunicatorReceiver {
|
|
4
|
-
private readonly callback:
|
|
4
|
+
private readonly callback: TReceiverCallback;
|
|
5
|
+
private readonly senderOrigin: string;
|
|
5
6
|
|
|
6
7
|
constructor(props: TReceiverProps) {
|
|
7
8
|
this.callback = props.callback;
|
|
9
|
+
this.senderOrigin = props.senderOrigin;
|
|
8
10
|
}
|
|
9
11
|
|
|
10
12
|
/**
|
|
11
13
|
* Watch Messages
|
|
12
14
|
*/
|
|
13
15
|
public watch() {
|
|
14
|
-
window.addEventListener('message', this.
|
|
16
|
+
window.addEventListener('message', this.onMessage, false);
|
|
15
17
|
}
|
|
16
18
|
|
|
17
19
|
/**
|
|
18
|
-
*
|
|
20
|
+
* Message Receive Callback
|
|
19
21
|
* @param event
|
|
20
22
|
*/
|
|
21
|
-
private
|
|
23
|
+
private onMessage = (event: MessageEvent) => {
|
|
22
24
|
if (!event || !event.origin || !event.data) {
|
|
23
25
|
return;
|
|
24
26
|
}
|
|
@@ -32,14 +34,10 @@ export class CommunicatorReceiver {
|
|
|
32
34
|
return;
|
|
33
35
|
}
|
|
34
36
|
|
|
35
|
-
if (
|
|
37
|
+
if (this.senderOrigin !== event.origin) {
|
|
36
38
|
return;
|
|
37
39
|
}
|
|
38
40
|
|
|
39
|
-
if (!Array.isArray(message.action)) {
|
|
40
|
-
message.action = [message.action];
|
|
41
|
-
}
|
|
42
|
-
|
|
43
41
|
if (typeof this.callback !== 'function') {
|
|
44
42
|
return;
|
|
45
43
|
}
|
|
@@ -1,26 +1,30 @@
|
|
|
1
1
|
import {TCommunicatorMessage, TSenderProps} from '../types';
|
|
2
|
-
import {modifyUrl} from '
|
|
3
|
-
import {
|
|
2
|
+
import {modifyUrl} from './utils';
|
|
3
|
+
import {CommunicatorTargetEnum_isCorrect} from '../enums/CommunicatorTargetEnum';
|
|
4
4
|
|
|
5
5
|
export class CommunicatorSender {
|
|
6
6
|
private readonly otherWindow: Window;
|
|
7
|
-
private readonly
|
|
7
|
+
private readonly receiverOrigin: string;
|
|
8
8
|
|
|
9
9
|
constructor(props: TSenderProps) {
|
|
10
10
|
this.otherWindow = props.otherWindow;
|
|
11
|
-
this.
|
|
11
|
+
this.receiverOrigin = modifyUrl(props.receiverOrigin);
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
+
/**
|
|
15
|
+
* Send PostMessage
|
|
16
|
+
* @param message
|
|
17
|
+
*/
|
|
14
18
|
public sendMessage(message: TCommunicatorMessage) {
|
|
15
19
|
if (
|
|
16
|
-
!this.
|
|
17
|
-
!
|
|
20
|
+
!this.receiverOrigin ||
|
|
21
|
+
!CommunicatorTargetEnum_isCorrect(message.target)
|
|
18
22
|
) {
|
|
19
23
|
return;
|
|
20
24
|
}
|
|
21
25
|
|
|
22
26
|
const jsonMessage = JSON.stringify(message);
|
|
23
|
-
this.otherWindow.postMessage(jsonMessage, this.
|
|
27
|
+
this.otherWindow.postMessage(jsonMessage, this.receiverOrigin);
|
|
24
28
|
}
|
|
25
29
|
}
|
|
26
30
|
|
|
File without changes
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
export enum CommunicatorActionEnum {
|
|
2
|
+
CLOSE = 'close',
|
|
3
|
+
OPEN = 'open',
|
|
4
|
+
GOTO = 'goto',
|
|
5
|
+
RESIZE = 'resize',
|
|
6
|
+
}
|
|
3
7
|
|
|
4
|
-
export
|
|
5
|
-
|
|
6
|
-
public static OPEN: TCommunicatorActionKey = 'open';
|
|
7
|
-
public static GOTO: TCommunicatorActionKey = 'goto';
|
|
8
|
-
public static RESIZE: TCommunicatorActionKey = 'resize';
|
|
8
|
+
export function CommunicatorActionEnum_isCorrect(item: string): boolean {
|
|
9
|
+
return Object.values(CommunicatorActionEnum).includes(item as CommunicatorActionEnum);
|
|
9
10
|
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
export enum CommunicatorTargetEnum {
|
|
2
|
+
SIGN_UP = 'sign_up',
|
|
3
|
+
SIGN_IN = 'sign_in',
|
|
4
|
+
}
|
|
3
5
|
|
|
4
|
-
export
|
|
5
|
-
|
|
6
|
-
public static SIGN_IN: TCommunicatorTargetKey = 'sign_in';
|
|
6
|
+
export function CommunicatorTargetEnum_isCorrect(item: string): boolean {
|
|
7
|
+
return Object.values(CommunicatorTargetEnum).includes(item as CommunicatorTargetEnum);
|
|
7
8
|
}
|
package/src/receiver.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import {CommunicatorReceiver} from "./engine/CommunicatorReceiver"
|
|
2
|
+
import {CommunicatorTargetEnum} from "./enums/CommunicatorTargetEnum"
|
|
3
|
+
import {CommunicatorActionEnum} from "./enums/CommunicatorActionEnum"
|
|
4
|
+
import * as types from "./types";
|
|
5
|
+
|
|
6
|
+
export {
|
|
7
|
+
CommunicatorReceiver,
|
|
8
|
+
CommunicatorTargetEnum,
|
|
9
|
+
CommunicatorActionEnum,
|
|
10
|
+
types,
|
|
11
|
+
}
|
package/src/sender.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import {CommunicatorSender} from "./engine/CommunicatorSender"
|
|
2
|
+
import {CommunicatorTargetEnum} from "./enums/CommunicatorTargetEnum"
|
|
3
|
+
import {CommunicatorActionEnum} from "./enums/CommunicatorActionEnum"
|
|
4
|
+
import * as types from "./types";
|
|
5
|
+
|
|
6
|
+
export {
|
|
7
|
+
CommunicatorSender,
|
|
8
|
+
CommunicatorTargetEnum,
|
|
9
|
+
CommunicatorActionEnum,
|
|
10
|
+
types,
|
|
11
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import {CommunicatorActionEnum} from "../enums/CommunicatorActionEnum";
|
|
2
|
+
import {CommunicatorTargetEnum} from "../enums/CommunicatorTargetEnum";
|
|
3
|
+
|
|
4
|
+
export type TSenderProps = {
|
|
5
|
+
receiverOrigin: string,
|
|
6
|
+
otherWindow: Window,
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export type TReceiverProps = {
|
|
10
|
+
callback: TReceiverCallback,
|
|
11
|
+
senderOrigin: string,
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export type TReceiverCallback = (message: TCommunicatorMessage) => void;
|
|
15
|
+
|
|
16
|
+
export type TCommunicatorActionResizeParams = {
|
|
17
|
+
width?: number,
|
|
18
|
+
height?: number,
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export type TCommunicatorActionGotoParams = {
|
|
22
|
+
url: string,
|
|
23
|
+
isTargetBlank?: boolean,
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export type TCommunicatorSenderActionMap = {
|
|
27
|
+
[CommunicatorActionEnum.RESIZE]?: TCommunicatorActionResizeParams,
|
|
28
|
+
[CommunicatorActionEnum.GOTO]?: TCommunicatorActionGotoParams,
|
|
29
|
+
[CommunicatorActionEnum.CLOSE]?: true,
|
|
30
|
+
[CommunicatorActionEnum.OPEN]?: CommunicatorTargetEnum,
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export type TCommunicatorMessage = {
|
|
34
|
+
target: CommunicatorTargetEnum,
|
|
35
|
+
action: TCommunicatorSenderActionMap
|
|
36
|
+
}
|
package/tools/cleanup.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/* eslint-disable */
|
|
2
|
+
const fs = require('fs')
|
|
3
|
+
const Path = require('path')
|
|
4
|
+
/* eslint-enable */
|
|
5
|
+
|
|
6
|
+
const deleteFolderRecursive = (path) => {
|
|
7
|
+
if (fs.existsSync(path)) {
|
|
8
|
+
fs.readdirSync(path).forEach((file) => {
|
|
9
|
+
const curPath = Path.join(path, file)
|
|
10
|
+
if (fs.lstatSync(curPath).isDirectory()) {
|
|
11
|
+
deleteFolderRecursive(curPath)
|
|
12
|
+
} else {
|
|
13
|
+
fs.unlinkSync(curPath)
|
|
14
|
+
}
|
|
15
|
+
})
|
|
16
|
+
fs.rmdirSync(path)
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const folder = process.argv.slice(2)[0]
|
|
21
|
+
|
|
22
|
+
if (folder) {
|
|
23
|
+
deleteFolderRecursive(Path.join(__dirname, '../dist', folder))
|
|
24
|
+
} else {
|
|
25
|
+
deleteFolderRecursive(Path.join(__dirname, '../dist'))
|
|
26
|
+
}
|
package/tsconfig.json
CHANGED
|
@@ -7,17 +7,15 @@
|
|
|
7
7
|
"ESNext"
|
|
8
8
|
],
|
|
9
9
|
"target": "ES6",
|
|
10
|
-
"module": "esnext",
|
|
11
10
|
"moduleResolution": "node",
|
|
12
11
|
"strictNullChecks": false,
|
|
13
12
|
"esModuleInterop": true,
|
|
14
13
|
"skipLibCheck": true,
|
|
15
14
|
"forceConsistentCasingInFileNames": true,
|
|
16
|
-
"baseUrl": "./
|
|
15
|
+
"baseUrl": "./",
|
|
17
16
|
"outDir": "dist",
|
|
18
|
-
"declaration": true,
|
|
19
17
|
"alwaysStrict": true,
|
|
20
|
-
"removeComments":
|
|
18
|
+
"removeComments": true,
|
|
21
19
|
"noImplicitReturns": true,
|
|
22
20
|
"noEmit": false,
|
|
23
21
|
"noFallthroughCasesInSwitch": true,
|
|
@@ -25,13 +23,10 @@
|
|
|
25
23
|
"noUnusedParameters": true,
|
|
26
24
|
"importHelpers": true,
|
|
27
25
|
"sourceMap": false,
|
|
28
|
-
"typeRoots": [
|
|
29
|
-
"./node_modules/@types",
|
|
30
|
-
"./src/types"
|
|
31
|
-
],
|
|
32
26
|
},
|
|
33
27
|
"exclude": [
|
|
34
28
|
"dist",
|
|
35
29
|
"node_modules",
|
|
36
|
-
]
|
|
30
|
+
],
|
|
31
|
+
"include": ["src/**/*"]
|
|
37
32
|
}
|
package/src/enums/BaseEnum.ts
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
export default abstract class BaseEnum {
|
|
2
|
-
public static array: string[] = null;
|
|
3
|
-
|
|
4
|
-
public static isCorrect(value: string): boolean {
|
|
5
|
-
return value && value.trim() && this.getAsArray().indexOf(value) !== -1;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Gets array of all possible values
|
|
10
|
-
*/
|
|
11
|
-
public static getAsArray(): string[] {
|
|
12
|
-
if (!this.array) {
|
|
13
|
-
let props = Object.getOwnPropertyNames(this);
|
|
14
|
-
let obj = Object.getPrototypeOf(this);
|
|
15
|
-
|
|
16
|
-
this.array = [];
|
|
17
|
-
|
|
18
|
-
while (Object.prototype.isPrototypeOf.call(BaseEnum, obj)) {
|
|
19
|
-
props = [...props, ...Object.getOwnPropertyNames(obj)];
|
|
20
|
-
obj = Object.getPrototypeOf(obj);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
for (const prop of props) {
|
|
24
|
-
if (['caller', 'arguments', 'name', 'length', 'prototype'].indexOf(prop) !== -1) {
|
|
25
|
-
continue;
|
|
26
|
-
}
|
|
27
|
-
const self = this as {[index: string]: any};
|
|
28
|
-
const propValue = self[prop];
|
|
29
|
-
if (typeof propValue === 'string' && prop.indexOf('CONTEXT') === -1) {
|
|
30
|
-
this.array.push(propValue);
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
return this.array;
|
|
35
|
-
}
|
|
36
|
-
}
|
package/src/types.ts
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
export type TSenderProps = {
|
|
2
|
-
targetOrigin: string,
|
|
3
|
-
otherWindow: Window,
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
export type TReceiverProps = {
|
|
7
|
-
callback: (message: TCommunicatorMessageReceiver) => void,
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export type TCommunicatorTargetKey = 'sign_up' | 'sign_in';
|
|
11
|
-
export type TCommunicatorActionKey = keyof TCommunicatorSenderActionMap;
|
|
12
|
-
|
|
13
|
-
export type TCommunicatorActionResizeParams = {
|
|
14
|
-
width?: number,
|
|
15
|
-
height?: number,
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export type TCommunicatorActionGotoParams = {
|
|
19
|
-
url: string,
|
|
20
|
-
isTargetBlank?: boolean,
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export type TCommunicatorSenderActionMap = {
|
|
24
|
-
'resize': TCommunicatorActionResizeParams,
|
|
25
|
-
'goto': TCommunicatorActionGotoParams,
|
|
26
|
-
'close': null,
|
|
27
|
-
'open': TCommunicatorTargetKey,
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export type TCommunicatorMessage = {
|
|
31
|
-
target: TCommunicatorTargetKey,
|
|
32
|
-
action: TCommunicatorActionItem | TCommunicatorActionItem[]
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export type TCommunicatorMessageReceiver = {
|
|
36
|
-
target: TCommunicatorTargetKey,
|
|
37
|
-
action: TCommunicatorActionItem[]
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export type TCommunicatorActionItem = {
|
|
41
|
-
key: TCommunicatorActionKey,
|
|
42
|
-
params?: TCommunicatorSenderActionMap[TCommunicatorActionKey]
|
|
43
|
-
};
|