@maxzima/wa-communicator 0.0.5 → 0.0.6
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 +32 -2
- package/config/tsconfig.esm.json +10 -0
- package/config/tsconfig.types.json +8 -0
- package/dist/engine/CommunicatorReceiver.d.ts +0 -7
- package/dist/engine/CommunicatorReceiver.js +0 -7
- package/dist/engine/CommunicatorSender.d.ts +0 -4
- package/dist/engine/CommunicatorSender.js +1 -5
- package/dist/{utils.d.ts → engine/utils.d.ts} +0 -0
- package/dist/{utils.js → engine/utils.js} +0 -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.d.ts → types/index.d.ts} +2 -2
- package/dist/types/index.js +1 -0
- package/package.json +13 -5
- package/src/engine/CommunicatorSender.ts +1 -1
- package/src/{utils.ts → engine/utils.ts} +0 -0
- package/src/receiver.ts +11 -0
- package/src/sender.ts +11 -0
- package/src/{types.ts → types/index.ts} +2 -2
- package/tools/cleanup.js +26 -0
- package/tsconfig.json +4 -9
- package/dist/enums/BaseEnum.d.ts +0 -8
- package/dist/enums/BaseEnum.js +0 -31
- package/dist/types.js +0 -1
package/README.md
CHANGED
|
@@ -1,4 +1,34 @@
|
|
|
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({
|
|
@@ -18,7 +48,7 @@ communicator.sendMessage({
|
|
|
18
48
|
});
|
|
19
49
|
```
|
|
20
50
|
|
|
21
|
-
# Receiver
|
|
51
|
+
# Usage Receiver
|
|
22
52
|
|
|
23
53
|
```javascript
|
|
24
54
|
const communicator = new CommunicatorReceiver({
|
|
@@ -2,13 +2,6 @@ import { TReceiverProps } from '../types';
|
|
|
2
2
|
export declare class CommunicatorReceiver {
|
|
3
3
|
private readonly callback;
|
|
4
4
|
constructor(props: TReceiverProps);
|
|
5
|
-
/**
|
|
6
|
-
* Watch Messages
|
|
7
|
-
*/
|
|
8
5
|
watch(): void;
|
|
9
|
-
/**
|
|
10
|
-
* Message Receive Callback
|
|
11
|
-
* @param event
|
|
12
|
-
*/
|
|
13
6
|
private onMessage;
|
|
14
7
|
}
|
|
@@ -1,9 +1,5 @@
|
|
|
1
1
|
export class CommunicatorReceiver {
|
|
2
2
|
constructor(props) {
|
|
3
|
-
/**
|
|
4
|
-
* Message Receive Callback
|
|
5
|
-
* @param event
|
|
6
|
-
*/
|
|
7
3
|
this.onMessage = (event) => {
|
|
8
4
|
if (!event || !event.origin || !event.data) {
|
|
9
5
|
return;
|
|
@@ -26,9 +22,6 @@ export class CommunicatorReceiver {
|
|
|
26
22
|
};
|
|
27
23
|
this.callback = props.callback;
|
|
28
24
|
}
|
|
29
|
-
/**
|
|
30
|
-
* Watch Messages
|
|
31
|
-
*/
|
|
32
25
|
watch() {
|
|
33
26
|
window.addEventListener('message', this.onMessage, false);
|
|
34
27
|
}
|
|
@@ -1,14 +1,10 @@
|
|
|
1
|
-
import { modifyUrl } from '
|
|
1
|
+
import { modifyUrl } from './utils';
|
|
2
2
|
import { CommunicatorTargetEnum_isCorrect } from '../enums/CommunicatorTargetEnum';
|
|
3
3
|
export class CommunicatorSender {
|
|
4
4
|
constructor(props) {
|
|
5
5
|
this.otherWindow = props.otherWindow;
|
|
6
6
|
this.targetOrigin = modifyUrl(props.targetOrigin);
|
|
7
7
|
}
|
|
8
|
-
/**
|
|
9
|
-
* Send PostMessage
|
|
10
|
-
* @param message
|
|
11
|
-
*/
|
|
12
8
|
sendMessage(message) {
|
|
13
9
|
if (!this.targetOrigin ||
|
|
14
10
|
!CommunicatorTargetEnum_isCorrect(message.target)) {
|
|
File without changes
|
|
File without changes
|
|
@@ -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, };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { CommunicatorActionEnum } from "
|
|
2
|
-
import { CommunicatorTargetEnum } from "
|
|
1
|
+
import { CommunicatorActionEnum } from "../enums/CommunicatorActionEnum";
|
|
2
|
+
import { CommunicatorTargetEnum } from "../enums/CommunicatorTargetEnum";
|
|
3
3
|
export declare type TSenderProps = {
|
|
4
4
|
targetOrigin: string;
|
|
5
5
|
otherWindow: Window;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import { CommunicatorActionEnum } from "../enums/CommunicatorActionEnum";
|
package/package.json
CHANGED
|
@@ -1,20 +1,28 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "0.0.
|
|
2
|
+
"version": "0.0.6",
|
|
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
|
-
"
|
|
15
|
-
"build": "
|
|
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"
|
|
16
23
|
},
|
|
17
24
|
"devDependencies": {
|
|
25
|
+
"npm-run-all": "^4.1.5",
|
|
18
26
|
"typescript": "^4.7.4"
|
|
19
27
|
}
|
|
20
28
|
}
|
|
File without changes
|
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
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {CommunicatorActionEnum} from "
|
|
2
|
-
import {CommunicatorTargetEnum} from "
|
|
1
|
+
import {CommunicatorActionEnum} from "../enums/CommunicatorActionEnum";
|
|
2
|
+
import {CommunicatorTargetEnum} from "../enums/CommunicatorTargetEnum";
|
|
3
3
|
|
|
4
4
|
export type TSenderProps = {
|
|
5
5
|
targetOrigin: string,
|
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/dist/enums/BaseEnum.d.ts
DELETED
package/dist/enums/BaseEnum.js
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
export default class BaseEnum {
|
|
2
|
-
static isCorrect(value) {
|
|
3
|
-
return value && value.trim() && this.getAsArray().indexOf(value) !== -1;
|
|
4
|
-
}
|
|
5
|
-
/**
|
|
6
|
-
* Gets array of all possible values
|
|
7
|
-
*/
|
|
8
|
-
static getAsArray() {
|
|
9
|
-
if (!this.array) {
|
|
10
|
-
let props = Object.getOwnPropertyNames(this);
|
|
11
|
-
let obj = Object.getPrototypeOf(this);
|
|
12
|
-
this.array = [];
|
|
13
|
-
while (Object.prototype.isPrototypeOf.call(BaseEnum, obj)) {
|
|
14
|
-
props = [...props, ...Object.getOwnPropertyNames(obj)];
|
|
15
|
-
obj = Object.getPrototypeOf(obj);
|
|
16
|
-
}
|
|
17
|
-
for (const prop of props) {
|
|
18
|
-
if (['caller', 'arguments', 'name', 'length', 'prototype'].indexOf(prop) !== -1) {
|
|
19
|
-
continue;
|
|
20
|
-
}
|
|
21
|
-
const self = this;
|
|
22
|
-
const propValue = self[prop];
|
|
23
|
-
if (typeof propValue === 'string' && prop.indexOf('CONTEXT') === -1) {
|
|
24
|
-
this.array.push(propValue);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
return this.array;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
BaseEnum.array = null;
|
package/dist/types.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import { CommunicatorActionEnum } from "./enums/CommunicatorActionEnum";
|