@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 CHANGED
@@ -1,4 +1,34 @@
1
- # Sender
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({
@@ -0,0 +1,10 @@
1
+ {
2
+ "extends": "../tsconfig",
3
+ "compilerOptions": {
4
+ "module": "ESNext",
5
+ "outDir": "../dist",
6
+ },
7
+ "exclude": [
8
+ "../src/types/index.ts",
9
+ ]
10
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "extends": "../tsconfig",
3
+ "compilerOptions": {
4
+ "declaration": true,
5
+ "emitDeclarationOnly": true,
6
+ "outDir": "../dist"
7
+ }
8
+ }
@@ -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
  }
@@ -3,9 +3,5 @@ export declare class CommunicatorSender {
3
3
  private readonly otherWindow;
4
4
  private readonly targetOrigin;
5
5
  constructor(props: TSenderProps);
6
- /**
7
- * Send PostMessage
8
- * @param message
9
- */
10
6
  sendMessage(message: TCommunicatorMessage): void;
11
7
  }
@@ -1,14 +1,10 @@
1
- import { modifyUrl } from '../utils';
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, };
@@ -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, };
@@ -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 "./enums/CommunicatorActionEnum";
2
- import { CommunicatorTargetEnum } from "./enums/CommunicatorTargetEnum";
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.5",
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.ts",
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
- "prepublish": "rm -rf dist",
14
- "postinstall": "npm run build",
15
- "build": "tsc --project tsconfig.json"
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
  }
@@ -1,5 +1,5 @@
1
1
  import {TCommunicatorMessage, TSenderProps} from '../types';
2
- import {modifyUrl} from '../utils';
2
+ import {modifyUrl} from './utils';
3
3
  import {CommunicatorTargetEnum_isCorrect} from '../enums/CommunicatorTargetEnum';
4
4
 
5
5
  export class CommunicatorSender {
File without changes
@@ -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 "./enums/CommunicatorActionEnum";
2
- import {CommunicatorTargetEnum} from "./enums/CommunicatorTargetEnum";
1
+ import {CommunicatorActionEnum} from "../enums/CommunicatorActionEnum";
2
+ import {CommunicatorTargetEnum} from "../enums/CommunicatorTargetEnum";
3
3
 
4
4
  export type TSenderProps = {
5
5
  targetOrigin: string,
@@ -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": "./src",
15
+ "baseUrl": "./",
17
16
  "outDir": "dist",
18
- "declaration": true,
19
17
  "alwaysStrict": true,
20
- "removeComments": false,
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
  }
@@ -1,8 +0,0 @@
1
- export default abstract class BaseEnum {
2
- static array: string[];
3
- static isCorrect(value: string): boolean;
4
- /**
5
- * Gets array of all possible values
6
- */
7
- static getAsArray(): string[];
8
- }
@@ -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";