@wildix/xbees-connect 1.0.4-alpha.0 → 1.0.4-alpha.10

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 Wildix Inc.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,11 +1,46 @@
1
- # `xbees-connect`
1
+ # xbees connect client
2
2
 
3
- > TODO: description
3
+ This package is the Community plan edition of the client for UI integration applications.
4
+
5
+ ## Installation
6
+
7
+ Install the package in your project directory with:
8
+
9
+ yarn
10
+
11
+ ```bash
12
+ yarn add @wildix/xbees-connect
13
+ ```
14
+
15
+ npm
16
+
17
+ ```bash
18
+ npm install @wildix/xbees-connect
19
+ ```
4
20
 
5
21
  ## Usage
6
22
 
7
23
  ```
8
- const xbeesConnect = require('xbees-connect');
24
+ import Client from "@wildix/xbees-connect";
25
+
26
+ const xBeesClient = Client.getInstance();
27
+ console.log(xBeesClient.version());
9
28
 
10
- // TODO: DEMONSTRATE API....
11
29
  ```
30
+
31
+ This component has the following peer dependencies that you will need to install as well.
32
+
33
+ ```json
34
+ {
35
+ "peerDependencies": {
36
+ "@mui/material": "^5.4.1",
37
+ "@mui/system": "^5.4.1",
38
+ "react": "^17.0.0 || ^18.0.0",
39
+ "react-dom": "^17.0.0 || ^18.0.0"
40
+ }
41
+ }
42
+ ```
43
+
44
+ ## Documentation
45
+
46
+ Visit [https://mui.com/x/react-data-grid/](https://mui.com/x/react-data-grid/) to view the full documentation.
package/dist-es/index.js CHANGED
@@ -1,6 +1,2 @@
1
1
  import { Client } from './src/Client';
2
- (function () {
3
- // @ts-expect-error window.xBeesConnect will be used inside another app
4
- window.xBeesConnect = Client;
5
- })();
6
2
  export default Client;
@@ -1,10 +1,11 @@
1
1
  {
2
- "name": "xbees-connect",
3
- "version": "1.0.0",
2
+ "name": "@wildix/xbees-connect",
3
+ "version": "1.0.4-alpha.1",
4
4
  "description": "This library provides easy communication between x-bees and integrated web applications",
5
5
  "author": "dimitri.chernykh <dimitri.chernykh@wildix.com>",
6
6
  "homepage": "",
7
- "license": "UNLICENSED",
7
+ "sideEffects": false,
8
+ "license": "MIT",
8
9
  "main": "./dist-cjs/index.js",
9
10
  "types": "./dist-types/index.d.ts",
10
11
  "module": "./dist-es/index.js",
@@ -13,6 +14,8 @@
13
14
  "build:es": "tsc -p tsconfig.es.json",
14
15
  "build:types": "tsc -p tsconfig.types.json",
15
16
  "build:docs": "typedoc",
17
+ "lint": "eslint .",
18
+ "lint:fix": "eslint . --fix",
16
19
  "clean": "rimraf ./dist-* && rimraf *.tsbuildinfo"
17
20
  },
18
21
  "files": [
@@ -22,13 +25,18 @@
22
25
  "type": "git",
23
26
  "url": "git@git.wildix.com:dimitri.chernykh/sdk-ui.git"
24
27
  },
25
- "engines": {
26
- "node": ">=18"
28
+ "publishConfig": {
29
+ "access": "public"
27
30
  },
28
- "dependencies": {
31
+ "devDependencies": {
32
+ "eslint": "^8.53.0",
33
+ "rimraf": "^5.0.5",
29
34
  "typescript": "^5.2.2"
30
35
  },
31
- "devDependencies": {
32
- "rimraf": "^5.0.5"
36
+ "parserOptions": {
37
+ "project": ["./tsconfig.json"]
38
+ },
39
+ "engines": {
40
+ "node": ">=16"
33
41
  }
34
42
  }
@@ -1,30 +1,34 @@
1
- import { ClientEventType, EventType, } from './types';
2
- import PostMessageControllerNative from './PostMessageControllerNative';
3
- import PostMessageControllerWeb from './PostMessageControllerWeb';
4
1
  import packageJson from '../package.json';
2
+ import PostMessageControllerNative from './helpers/PostMessageControllerNative';
3
+ import PostMessageControllerWeb from './helpers/PostMessageControllerWeb';
4
+ import { ClientEventType, EventType, } from './types';
5
5
  /**
6
6
  * Client provides functionality of communication between xBees and integrated web applications via iFrame or ReactNative WebView
7
7
  * integration creates na instance with new Client()
8
8
  * */
9
9
  export class Client {
10
+ static instance = null;
10
11
  static getInstance() {
11
12
  if (!this.instance) {
12
13
  this.instance = new Client();
13
14
  }
14
15
  return this.instance;
15
16
  }
17
+ worker;
18
+ listeners = [];
19
+ useSubscription = false;
20
+ iframeId;
21
+ variant = null;
16
22
  constructor() {
17
- this.listeners = [];
18
- this.useSubscription = false;
19
- this.iframeId = null;
20
- this.variant = null;
21
23
  const params = new URLSearchParams(window.location.search);
22
- this.iframeId = params.get('iframeId');
24
+ this.iframeId = params.get('iframeId') ?? undefined;
23
25
  this.variant = params.get('variant');
24
26
  // @ts-expect-error window.ReactNativeWebView will be provided by ReactNative WebView
25
- this.worker = window.ReactNativeWebView ? new PostMessageControllerNative() : new PostMessageControllerWeb();
27
+ this.worker = window.ReactNativeWebView
28
+ ? new PostMessageControllerNative()
29
+ : new PostMessageControllerWeb();
26
30
  }
27
- async sendAsync(data) {
31
+ sendAsync(data) {
28
32
  return this.worker.sendAsync({
29
33
  ...data,
30
34
  iframeId: this.iframeId,
@@ -38,7 +42,8 @@ export class Client {
38
42
  }
39
43
  return data;
40
44
  }
41
- catch (e) {
45
+ catch (error) {
46
+ console.error('parse message error', error);
42
47
  return null;
43
48
  }
44
49
  }
@@ -51,19 +56,22 @@ export class Client {
51
56
  this.listeners.forEach(({ eventName, callback }) => {
52
57
  if (eventName === type) {
53
58
  if (type === EventType.ADD_CALL) {
54
- const cb = callback;
55
- cb(payload);
59
+ const callbackFn = callback;
60
+ callbackFn(payload);
56
61
  }
57
62
  else {
58
63
  // @ts-expect-error TODO: check the type for Callback<?>
59
- const cb = callback;
60
- cb(payload);
64
+ const callbackFn = callback;
65
+ callbackFn(payload);
61
66
  }
62
67
  }
63
68
  });
64
69
  }
65
- async ready() {
66
- return this.sendAsync({ type: ClientEventType.READY, payload: { version: this.version() } });
70
+ ready() {
71
+ return this.sendAsync({
72
+ type: ClientEventType.READY,
73
+ payload: { version: this.version() },
74
+ });
67
75
  }
68
76
  version() {
69
77
  return packageJson.version;
@@ -74,40 +82,43 @@ export class Client {
74
82
  showsUi() {
75
83
  return !this.isDaemon();
76
84
  }
77
- async getContext() {
85
+ getContext() {
78
86
  return this.sendAsync({ type: ClientEventType.CONTEXT });
79
87
  }
80
- async getCurrentContact() {
88
+ getCurrentContact() {
81
89
  return this.sendAsync({ type: ClientEventType.CURRENT_CONTACT });
82
90
  }
83
- async getThemeMode() {
91
+ getThemeMode() {
84
92
  return this.sendAsync({ type: ClientEventType.THEME_MODE });
85
93
  }
86
- async getTheme() {
94
+ getTheme() {
87
95
  return this.sendAsync({ type: ClientEventType.THEME });
88
96
  }
89
- async startCall(phoneNumber) {
90
- return this.sendAsync({ type: ClientEventType.START_CALL, payload: { phoneNumber } });
97
+ startCall(phoneNumber) {
98
+ return this.sendAsync({
99
+ type: ClientEventType.START_CALL,
100
+ payload: { phoneNumber },
101
+ });
91
102
  }
92
- async reboot() {
103
+ reboot() {
93
104
  return this.sendAsync({ type: ClientEventType.REBOOT });
94
105
  }
95
- async setViewport(payload) {
106
+ setViewport(payload) {
96
107
  return this.sendAsync({ type: ClientEventType.VIEW_PORT, payload });
97
108
  }
98
- async toClipboard(payload) {
109
+ toClipboard(payload) {
99
110
  return this.sendAsync({ type: ClientEventType.TO_CLIPBOARD, payload });
100
111
  }
101
- async isNotAuthorized(payload) {
112
+ isNotAuthorized(payload) {
102
113
  return this.sendAsync({ type: ClientEventType.NOT_AUTHORIZED, payload });
103
114
  }
104
- async isAuthorized(payload) {
115
+ isAuthorized(payload) {
105
116
  return this.sendAsync({ type: ClientEventType.AUTHORIZED, payload });
106
117
  }
107
- async getContactsAutoSuggest(payload) {
118
+ getContactsAutoSuggest(payload) {
108
119
  return this.sendAsync({
109
120
  type: ClientEventType.CONTACTS_AUTO_SUGGEST,
110
- payload: payload,
121
+ payload,
111
122
  });
112
123
  }
113
124
  addEventListener(eventName, callback) {
@@ -115,14 +126,21 @@ export class Client {
115
126
  this.useSubscription = true;
116
127
  window.addEventListener('message', this.onMessage.bind(this));
117
128
  }
118
- const foundThisEvent = this.listeners.find(({ eventName: _eventName, callback: _callback }) => eventName === _eventName && Object.is(callback, _callback));
129
+ const foundThisEvent = this.listeners.find(({ eventName: _eventName, callback: _callback }) => {
130
+ return eventName === _eventName && Object.is(callback, _callback);
131
+ });
119
132
  if (!foundThisEvent) {
120
133
  this.listeners.push({ eventName, callback });
121
134
  }
122
- return () => { this.removeEventListener(eventName, callback); };
135
+ return () => {
136
+ this.removeEventListener(eventName, callback);
137
+ };
123
138
  }
124
139
  removeEventListener(eventName, callback) {
125
- this.listeners = this.listeners.filter(({ eventName: _eventName, callback: _callback }) => !(Object.is(callback, _callback) && (!eventName ? true : eventName === _eventName)));
140
+ this.listeners = this.listeners.filter(({ eventName: _eventName, callback: _callback }) => {
141
+ return !(Object.is(callback, _callback) &&
142
+ (!eventName ? true : eventName === _eventName));
143
+ });
126
144
  if (this.useSubscription && !this.listeners.length) {
127
145
  this.useSubscription = false;
128
146
  window.removeEventListener('message', this.onMessage.bind(this));
@@ -147,7 +165,7 @@ export class Client {
147
165
  type: ClientEventType.CONTACTS_AUTO_SUGGEST,
148
166
  payload: {
149
167
  contacts,
150
- query
168
+ query,
151
169
  },
152
170
  });
153
171
  };
@@ -157,8 +175,8 @@ export class Client {
157
175
  try {
158
176
  callback(query, resolve, reject);
159
177
  }
160
- catch (e) {
161
- reject(e.toString());
178
+ catch (error) {
179
+ reject(`${error}`);
162
180
  }
163
181
  });
164
182
  }
@@ -166,4 +184,3 @@ export class Client {
166
184
  this.addEventListener(EventType.USE_THEME, callback);
167
185
  }
168
186
  }
169
- Client.instance = null;
@@ -1,43 +1,44 @@
1
1
  export default class PostMessageControllerNative {
2
+ target;
3
+ timeout = 10000;
2
4
  constructor() {
3
- this.timeout = 10000;
4
5
  // @ts-expect-error window.ReactNativeWebView will be provided by ReactNative WebView
5
6
  this.target = window.ReactNativeWebView;
6
7
  }
7
- async sendAsync(data) {
8
+ sendAsync(data) {
8
9
  if (!this.target) {
9
- return Promise.reject('xBeesConnect should be wrapped within iframe to perform the connection');
10
+ return Promise.reject('your application should be wrapped within iframe to xbees-connect perform the connection');
10
11
  }
11
12
  return this.send(this.target, data);
12
13
  }
13
- send(target, payload) {
14
- return new Promise((res, rej) => {
14
+ send(target, message) {
15
+ return new Promise((resolve, reject) => {
15
16
  const channel = new MessageChannel();
16
17
  const listener = (event) => {
17
18
  try {
18
19
  const parsedData = JSON.parse(event.data);
19
- if (parsedData?.type === payload.type) {
20
+ if (parsedData?.type === message.type) {
20
21
  clearTimeout(timeout);
21
22
  window.removeEventListener('message', listener);
22
23
  if (!parsedData.errorMessage) {
23
- res(parsedData);
24
+ resolve(parsedData);
24
25
  }
25
26
  else {
26
- rej(parsedData);
27
+ reject(parsedData);
27
28
  }
28
29
  }
29
30
  }
30
- catch (e) {
31
- console.error("on receive response Error", e);
31
+ catch (error) {
32
+ console.error('on receive response Error', error);
32
33
  }
33
34
  };
34
35
  window.addEventListener('message', listener);
35
36
  const timeout = setTimeout(() => {
36
37
  channel.port1.close();
37
38
  window.removeEventListener('message', listener);
38
- rej({ errorMessage: 'timeout', type: payload.type });
39
+ reject({ errorMessage: 'timeout', type: message.type });
39
40
  }, this.timeout);
40
- target.postMessage(JSON.stringify(payload));
41
+ target.postMessage(JSON.stringify(message));
41
42
  });
42
43
  }
43
44
  }
@@ -1,29 +1,30 @@
1
1
  export default class PostMessageControllerWeb {
2
+ target;
3
+ timeout = 10000;
2
4
  constructor() {
3
- this.timeout = 10000;
4
5
  this.target = parent;
5
6
  }
6
- async sendAsync(data) {
7
+ sendAsync(data) {
7
8
  if (!this.target || this.target === window) {
8
- return Promise.reject('xBeesConnect should be wrapped within iframe to perform the connection');
9
+ return Promise.reject('your application should be wrapped within iframe to xbees-connect perform the connection');
9
10
  }
10
11
  return this.send(this.target, data);
11
12
  }
12
13
  send(target, payload) {
13
- return new Promise((res, rej) => {
14
+ return new Promise((resolve, reject) => {
14
15
  const channel = new MessageChannel();
15
16
  const timeout = setTimeout(() => {
16
17
  channel.port1.close();
17
- rej({ errorMessage: 'timeout', type: payload.type });
18
+ reject({ errorMessage: 'timeout', type: payload.type });
18
19
  }, this.timeout);
19
20
  channel.port1.onmessage = ({ data }) => {
20
21
  clearTimeout(timeout);
21
22
  channel.port1.close();
22
23
  if (!data.errorMessage) {
23
- res(data);
24
+ resolve(data);
24
25
  }
25
26
  else {
26
- rej(data);
27
+ reject(data);
27
28
  }
28
29
  };
29
30
  target.postMessage(payload, '*', [channel.port2]);
@@ -1,15 +1,15 @@
1
- import { AutoSuggestResult, Callback, ClientConnect, EventType, Reject, RemoveEventListener, Resolve, Response } from './types';
1
+ import { AutoSuggestResult, Callback, ConnectClient, EventType, Reject, RemoveEventListener, Resolve, Response, ViewPortSize } from './types';
2
2
  /**
3
3
  * Client provides functionality of communication between xBees and integrated web applications via iFrame or ReactNative WebView
4
4
  * integration creates na instance with new Client()
5
5
  * */
6
- export declare class Client implements ClientConnect {
6
+ export declare class Client implements ConnectClient {
7
7
  private static instance;
8
- static getInstance(): Client;
8
+ static getInstance(): ConnectClient;
9
9
  private worker;
10
10
  private listeners;
11
11
  private useSubscription;
12
- private readonly iframeId;
12
+ private readonly iframeId?;
13
13
  private readonly variant;
14
14
  constructor();
15
15
  private sendAsync;
@@ -25,10 +25,7 @@ export declare class Client implements ClientConnect {
25
25
  getTheme(): Promise<Response>;
26
26
  startCall(phoneNumber: string): Promise<Response>;
27
27
  reboot(): Promise<Response>;
28
- setViewport(payload: {
29
- height: number;
30
- width: number;
31
- }): Promise<Response>;
28
+ setViewport(payload: ViewPortSize): Promise<Response>;
32
29
  toClipboard(payload: string): Promise<Response>;
33
30
  isNotAuthorized(payload: string): Promise<Response>;
34
31
  isAuthorized(payload: string): Promise<Response>;
@@ -0,0 +1,8 @@
1
+ import { MessageResponse, PostMessageController, Response } from '../types';
2
+ export default class PostMessageControllerNative implements PostMessageController {
3
+ private readonly target;
4
+ private timeout;
5
+ constructor();
6
+ sendAsync(data: MessageResponse): Promise<Response>;
7
+ private send;
8
+ }
@@ -0,0 +1,8 @@
1
+ import { MessageResponse, PostMessageController, Response } from '../types';
2
+ export default class PostMessageControllerWeb implements PostMessageController {
3
+ private readonly target;
4
+ private timeout;
5
+ constructor();
6
+ sendAsync(data: MessageResponse): Promise<Response>;
7
+ private send;
8
+ }
@@ -1,3 +1,25 @@
1
+ export declare enum EventType {
2
+ GET_CONTACTS_AUTO_SUGGEST = "xBeesGetContactsAutoSuggest",
3
+ ADD_CALL = "xBeesAddCall",
4
+ TERMINATE_CALL = "xBeesTerminateCall",
5
+ USE_THEME = "xBeesUseTheme",
6
+ PBX_TOKEN = "xBeesPbxToken"
7
+ }
8
+ export declare enum ClientEventType {
9
+ READY = "xBeesReady",
10
+ CONTEXT = "xBeesContext",
11
+ CURRENT_CONTACT = "xBeesCurrentContact",
12
+ THEME_MODE = "xBeesThemeMode",
13
+ THEME = "xBeesTheme",
14
+ START_CALL = "xBeesStartCall",
15
+ VIEW_PORT = "xBeesViewPort",
16
+ REBOOT = "xBeesReboot",
17
+ TO_CLIPBOARD = "xBeesToClipboard",
18
+ NOT_AUTHORIZED = "xBeesNotAuthorized",
19
+ AUTHORIZED = "xBeesAuthorized",
20
+ CONTACTS_AUTO_SUGGEST = "xBeesContactsAutoSuggest"
21
+ }
22
+ export type MessageType = ClientEventType | EventType;
1
23
  interface ContactShape {
2
24
  id: string;
3
25
  name: string;
@@ -11,62 +33,59 @@ interface ContactShape {
11
33
  extension?: string;
12
34
  organization?: string;
13
35
  }
14
- export type Contact = ContactShape & {
36
+ export type Contact = (ContactShape & {
15
37
  email: string;
16
- } | ContactShape & {
38
+ }) | (ContactShape & {
17
39
  phone: string;
40
+ });
41
+ export type ViewPortSize = {
42
+ height: number;
43
+ width: number;
18
44
  };
19
- export type Message<T extends EventType = EventType> = {
45
+ type EventPayload<T extends MessageType> = T extends EventType.GET_CONTACTS_AUTO_SUGGEST ? string : T extends ClientEventType.CONTACTS_AUTO_SUGGEST ? AutoSuggestResult : T extends EventType.ADD_CALL ? CallStartInfo : T extends ClientEventType.START_CALL ? StartCallPayload : T extends ClientEventType.READY ? {
46
+ version: string;
47
+ } : T extends ClientEventType.VIEW_PORT ? ViewPortSize : T extends EventType.USE_THEME ? string : T extends EventType.PBX_TOKEN ? string : never;
48
+ export type Message<T extends MessageType = MessageType> = {
20
49
  type: T;
21
- payload: EventPayload<T>;
50
+ payload?: EventPayload<T>;
22
51
  };
23
- export type Response = {
52
+ export type MessageResponse<T extends MessageType = MessageType> = Message<T> & {
53
+ iframeId?: string;
54
+ };
55
+ export type Payload = string | Record<string, string> | ThemeChangePayload;
56
+ export type Response<T extends Payload = Payload> = {
24
57
  type?: string;
25
58
  message?: string;
26
59
  errorMessage?: string;
60
+ payload?: T;
61
+ };
62
+ export type RawMessage = {
63
+ data?: string;
64
+ };
65
+ export type SendPayload = {
66
+ type: ClientEventType;
27
67
  payload?: any;
28
68
  };
29
- export declare enum EventType {
30
- GET_CONTACTS_AUTO_SUGGEST = "xBeesGetContactsAutoSuggest",
31
- ADD_CALL = "xBeesAddCall",
32
- TERMINATE_CALL = "xBeesTerminateCall",
33
- USE_THEME = "xBeesUseTheme",
34
- PBX_TOKEN = "xBeesPbxToken"
35
- }
36
- export declare enum ClientEventType {
37
- READY = "xBeesReady",
38
- CONTEXT = "xBeesContext",
39
- CURRENT_CONTACT = "xBeesCurrentContact",
40
- THEME_MODE = "xBeesThemeMode",
41
- THEME = "xBeesTheme",
42
- START_CALL = "xBeesStartCall",
43
- VIEW_PORT = "xBeesViewPort",
44
- REBOOT = "xBeesReboot",
45
- TO_CLIPBOARD = "xBeesToClipboard",
46
- NOT_AUTHORIZED = "xBeesNotAuthorized",
47
- AUTHORIZED = "xBeesAuthorized",
48
- CONTACTS_AUTO_SUGGEST = "xBeesContactsAutoSuggest"
49
- }
50
- export type MessageType = ClientEventType | EventType;
51
69
  export type ThemeChangePayload = {
52
- mode: "light" | "dark";
70
+ mode: 'light' | 'dark';
53
71
  themeOptions?: {
54
72
  typography?: unknown;
55
73
  palette?: unknown;
56
74
  };
57
75
  };
58
- export type ThemeChangeListenerCallback = (payload: ThemeChangePayload | unknown) => void;
59
76
  export type ListenerCallback = (payload: unknown) => void;
60
77
  export type DefaultCallback = (...args: unknown[]) => void;
61
78
  type CallStartInfo = {
62
79
  destination: string;
63
80
  video: boolean;
64
81
  };
65
- type EventPayload<T extends EventType> = T extends EventType.GET_CONTACTS_AUTO_SUGGEST ? string : T extends EventType.ADD_CALL ? CallStartInfo : T extends EventType.USE_THEME ? string : T extends EventType.PBX_TOKEN ? string : never;
82
+ type StartCallPayload = {
83
+ phoneNumber: string;
84
+ };
66
85
  export type EventPayloadMap = {
67
86
  [EventType.GET_CONTACTS_AUTO_SUGGEST]: string;
68
87
  [EventType.ADD_CALL]: CallStartInfo;
69
- [EventType.USE_THEME]: string;
88
+ [EventType.USE_THEME]: string | ThemeChangePayload;
70
89
  [EventType.PBX_TOKEN]: string;
71
90
  };
72
91
  export type EventCallbackMap = {
@@ -89,6 +108,7 @@ export type ClientEventCallbackMap = {
89
108
  export interface ReactNativeWebView {
90
109
  postMessage: (payload: unknown, origin?: string, d?: unknown[]) => void;
91
110
  }
111
+ export type Callback<T extends EventType = EventType> = T extends keyof EventCallbackMap ? EventCallbackMap[T] : DefaultCallback;
92
112
  export interface Listener<T extends EventType = EventType> {
93
113
  eventName: T;
94
114
  callback: Callback<T>;
@@ -98,14 +118,13 @@ export interface AutoSuggestResult {
98
118
  contacts: Contact[];
99
119
  query: string;
100
120
  }
101
- export interface SendData {
102
- sendAsync(data: any): Promise<Response>;
121
+ export interface PostMessageController {
122
+ sendAsync(data: MessageResponse): Promise<Response>;
103
123
  }
104
124
  export type Resolve = (contacts: Contact[]) => void;
105
125
  export type Reject = (reason: string) => void;
106
- export type Callback<T extends EventType = EventType> = T extends keyof EventCallbackMap ? EventCallbackMap[T] : DefaultCallback;
107
126
  export type RemoveEventListener = () => void;
108
- export interface ClientConnect {
127
+ export interface ConnectClient {
109
128
  /**
110
129
  * Sends to x-bees signal that iFrame is ready to be shown. iFrame should send it when the application starts and ready */
111
130
  ready: () => Promise<Response>;
@@ -139,10 +158,7 @@ export interface ClientConnect {
139
158
  reboot: () => Promise<Response>;
140
159
  /**
141
160
  * Sends request to x-bees about current frame size change */
142
- setViewport: (payload: {
143
- height: number;
144
- width: number;
145
- }) => Promise<Response>;
161
+ setViewport: (payload: ViewPortSize) => Promise<Response>;
146
162
  /**
147
163
  * Sends request to x-bees to put string to the users clipboard */
148
164
  toClipboard: (payload: string) => Promise<Response>;
package/package.json CHANGED
@@ -1,9 +1,10 @@
1
1
  {
2
2
  "name": "@wildix/xbees-connect",
3
- "version": "1.0.4-alpha.0",
3
+ "version": "1.0.4-alpha.10",
4
4
  "description": "This library provides easy communication between x-bees and integrated web applications",
5
5
  "author": "dimitri.chernykh <dimitri.chernykh@wildix.com>",
6
6
  "homepage": "",
7
+ "sideEffects": false,
7
8
  "license": "MIT",
8
9
  "main": "./dist-cjs/index.js",
9
10
  "types": "./dist-types/index.d.ts",
@@ -13,6 +14,8 @@
13
14
  "build:es": "tsc -p tsconfig.es.json",
14
15
  "build:types": "tsc -p tsconfig.types.json",
15
16
  "build:docs": "typedoc",
17
+ "lint": "eslint .",
18
+ "lint:fix": "eslint . --fix",
16
19
  "clean": "rimraf ./dist-* && rimraf *.tsbuildinfo"
17
20
  },
18
21
  "files": [
@@ -25,14 +28,18 @@
25
28
  "publishConfig": {
26
29
  "access": "public"
27
30
  },
28
- "engines": {
29
- "node": ">=18"
30
- },
31
- "dependencies": {
31
+ "devDependencies": {
32
+ "eslint": "^8.53.0",
33
+ "rimraf": "^5.0.5",
32
34
  "typescript": "^5.2.2"
33
35
  },
34
- "devDependencies": {
35
- "rimraf": "^5.0.5"
36
+ "parserOptions": {
37
+ "project": [
38
+ "./tsconfig.json"
39
+ ]
40
+ },
41
+ "engines": {
42
+ "node": ">=16"
36
43
  },
37
- "gitHead": "88d4593f7ab0adcff767df0f6297531a632558aa"
44
+ "gitHead": "2a4305e68084729846257fbee0d565c4beb0272c"
38
45
  }
@@ -1,8 +0,0 @@
1
- import { SendData, Response } from './types';
2
- export default class PostMessageControllerNative implements SendData {
3
- private readonly target;
4
- private timeout;
5
- constructor();
6
- sendAsync(data: any): Promise<Response>;
7
- private send;
8
- }
@@ -1,8 +0,0 @@
1
- import { SendData, Response } from './types';
2
- export default class PostMessageControllerWeb implements SendData {
3
- private readonly target;
4
- private timeout;
5
- constructor();
6
- sendAsync(data: any): Promise<Response>;
7
- private send;
8
- }