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

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,4 @@
1
- # xbees connect client
1
+ # x-bees-connect client
2
2
 
3
3
  This package is the Community plan edition of the client for UI integration applications.
4
4
 
@@ -6,41 +6,130 @@ This package is the Community plan edition of the client for UI integration appl
6
6
 
7
7
  Install the package in your project directory with:
8
8
 
9
- yarn
10
-
11
9
  ```bash
12
10
  yarn add @wildix/xbees-connect
13
11
  ```
14
-
15
- npm
16
-
17
12
  ```bash
18
13
  npm install @wildix/xbees-connect
19
14
  ```
20
15
 
21
16
  ## Usage
22
17
 
23
- ```
18
+ ```ts
24
19
  import Client from "@wildix/xbees-connect";
25
20
 
26
21
  const xBeesClient = Client.getInstance();
22
+
27
23
  console.log(xBeesClient.version());
28
24
 
29
25
  ```
30
26
 
31
- This component has the following peer dependencies that you will need to install as well.
27
+ ## API
32
28
 
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
- }
29
+ ### Initialization
30
+
31
+ #### `ready()`
32
+
33
+ Sends the signal to x-bees that iFrame is ready to be shown. iFrame should send it when the application starts and is ready.
34
+
35
+ #### `isAuthorized: (payload: string) => Promise<ResponseFromChannel>`
36
+
37
+ Sends the message to x-bees that the user is authorized and no more actions are required.
38
+
39
+ #### `isNotAuthorized: (payload: string) => Promise<ResponseFromChannel>`
40
+
41
+ Sends the message to x-bees that user actions are required:
42
+
43
+ ### Contacts search
44
+
45
+ #### `onSuggestContacts: ((query: string, resolve: Resolve, reject: Reject) => void) => RemoveEventListener`
46
+
47
+ Starts listen for the events of searching contacts and handle autosuggestion with the provided callback */
48
+
49
+ ```jsx
50
+ Client.getInstance().onSuggestContacts(async (query, resolve) => {
51
+ try {
52
+ const contacts = await fetchContacts(query);
53
+ resolve(contacts);
54
+ } catch (error) {
55
+ console.log('catch', error);
56
+ }
57
+ });
42
58
  ```
43
59
 
44
- ## Documentation
60
+ ### Context
61
+ #### `getContext(): Promise<Response>`
62
+
63
+ Retrieves current x-bees context data. The data may be different depending on context.
64
+
65
+ #### `getCurrentContact(): Promise<Response>`
66
+
67
+ Retrieves contact data currently opened in x-bees.
68
+
69
+ #### `getThemeMode(): Promise<Response>`
70
+
71
+ Retrieves current theme mode (light or dark)
72
+
73
+ #### `getTheme(): Promise<Response>`
74
+
75
+ Retrieves current theme mode and theme options
76
+
77
+ #### `onThemeChange: (callback: ThemeChangeListenerCallback) => void;`
78
+
79
+ Starts to listen for the events of changing theme and returns the provided callback
80
+
81
+ #### `onPbxTokenChange: (callback: ListenerCallback) => void;`
45
82
 
46
- Visit [https://mui.com/x/react-data-grid/](https://mui.com/x/react-data-grid/) to view the full documentation.
83
+ Starts to listen for the events of changing PBX token and returns the provided callback
84
+
85
+ #### `onCallStarted: (callback: ListenerCallback) => void;`
86
+
87
+ Starts to listen for the events of starting the call and returns the provided callback
88
+
89
+ #### `onCallEnded: (callback: ListenerCallback) => void;`
90
+
91
+ Starts to listen for the events of ending the call and returns the provided callback
92
+
93
+ #### `off: (callback: ListenerCallback) => void;`
94
+
95
+ Removes particular callback from handling events
96
+
97
+
98
+ ### Other
99
+ #### `version(): string`
100
+
101
+ Retrieves the version of xBeesConnect
102
+
103
+ #### `startCall(phoneNumber: string)`
104
+
105
+ Sends a request to x-bees to start a call with a number
106
+
107
+ #### `reboot()`
108
+
109
+ Sends a request to x-bees to restart the iFrame, reload with actual parameters and token
110
+
111
+ #### `setViewport({height: number; width: number})`
112
+
113
+ Sends a request to x-bees about changes of the current frame size
114
+
115
+ #### `toClipboard(payload: string)`
116
+
117
+ Sends a request to x-bees to put a string to the user's clipboard
118
+
119
+ #### `addEventListener()`
120
+
121
+ Starts listening for one of the x-bees events and returns the provided callback
122
+
123
+ #### `removeEventListener()`
124
+
125
+ Stops listening for one of the x-bees events with the particular callback
126
+
127
+ ## Known issues
128
+
129
+ The below function can fix cases when `String.replaceAll()` does not work in the mobile version. Most likely, this is some kind of WebView bug.
130
+
131
+ ```ts
132
+ function replaceAll(str: string, search: string, replace: string) {
133
+ return str.split(search).join(replace);
134
+ }
135
+ ```
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wildix/xbees-connect",
3
- "version": "1.0.4-alpha.1",
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": "",
@@ -23,7 +23,7 @@
23
23
  ],
24
24
  "repository": {
25
25
  "type": "git",
26
- "url": "git@git.wildix.com:dimitri.chernykh/sdk-ui.git"
26
+ "url": "git@git.wildix.com:xbs/sdk-ui.git"
27
27
  },
28
28
  "publishConfig": {
29
29
  "access": "public"
@@ -34,7 +34,9 @@
34
34
  "typescript": "^5.2.2"
35
35
  },
36
36
  "parserOptions": {
37
- "project": ["./tsconfig.json"]
37
+ "project": [
38
+ "./tsconfig.json"
39
+ ]
38
40
  },
39
41
  "engines": {
40
42
  "node": ">=16"
@@ -14,6 +14,20 @@ export class Client {
14
14
  }
15
15
  return this.instance;
16
16
  }
17
+ static initialize(renderer) {
18
+ if (this.getInstance().showsUi()) {
19
+ try {
20
+ void renderer();
21
+ }
22
+ catch (error) {
23
+ console.error('Error on init rendering widget:', error);
24
+ }
25
+ }
26
+ else {
27
+ console.log('run daemon');
28
+ void this.getInstance().ready();
29
+ }
30
+ }
17
31
  worker;
18
32
  listeners = [];
19
33
  useSubscription = false;
@@ -21,7 +35,7 @@ export class Client {
21
35
  variant = null;
22
36
  constructor() {
23
37
  const params = new URLSearchParams(window.location.search);
24
- this.iframeId = params.get('iframeId') ?? undefined;
38
+ this.iframeId = params.get('iframeId');
25
39
  this.variant = params.get('variant');
26
40
  // @ts-expect-error window.ReactNativeWebView will be provided by ReactNative WebView
27
41
  this.worker = window.ReactNativeWebView
@@ -109,11 +123,11 @@ export class Client {
109
123
  toClipboard(payload) {
110
124
  return this.sendAsync({ type: ClientEventType.TO_CLIPBOARD, payload });
111
125
  }
112
- isNotAuthorized(payload) {
113
- return this.sendAsync({ type: ClientEventType.NOT_AUTHORIZED, payload });
126
+ isNotAuthorized() {
127
+ return this.sendAsync({ type: ClientEventType.NOT_AUTHORIZED });
114
128
  }
115
- isAuthorized(payload) {
116
- return this.sendAsync({ type: ClientEventType.AUTHORIZED, payload });
129
+ isAuthorized() {
130
+ return this.sendAsync({ type: ClientEventType.AUTHORIZED });
117
131
  }
118
132
  getContactsAutoSuggest(payload) {
119
133
  return this.sendAsync({
@@ -126,9 +140,7 @@ export class Client {
126
140
  this.useSubscription = true;
127
141
  window.addEventListener('message', this.onMessage.bind(this));
128
142
  }
129
- const foundThisEvent = this.listeners.find(({ eventName: _eventName, callback: _callback }) => {
130
- return eventName === _eventName && Object.is(callback, _callback);
131
- });
143
+ const foundThisEvent = this.listeners.find(({ eventName: _eventName, callback: _callback }) => eventName === _eventName && Object.is(callback, _callback));
132
144
  if (!foundThisEvent) {
133
145
  this.listeners.push({ eventName, callback });
134
146
  }
@@ -137,10 +149,8 @@ export class Client {
137
149
  };
138
150
  }
139
151
  removeEventListener(eventName, callback) {
140
- this.listeners = this.listeners.filter(({ eventName: _eventName, callback: _callback }) => {
141
- return !(Object.is(callback, _callback) &&
142
- (!eventName ? true : eventName === _eventName));
143
- });
152
+ this.listeners = this.listeners.filter(({ eventName: _eventName, callback: _callback }) => !(Object.is(callback, _callback) &&
153
+ (!eventName ? true : eventName === _eventName)));
144
154
  if (this.useSubscription && !this.listeners.length) {
145
155
  this.useSubscription = false;
146
156
  window.removeEventListener('message', this.onMessage.bind(this));
@@ -160,15 +170,13 @@ export class Client {
160
170
  }
161
171
  onSuggestContacts(callback) {
162
172
  return this.addEventListener(EventType.GET_CONTACTS_AUTO_SUGGEST, (query) => {
163
- const resolve = (contacts) => {
164
- return this.sendAsync({
165
- type: ClientEventType.CONTACTS_AUTO_SUGGEST,
166
- payload: {
167
- contacts,
168
- query,
169
- },
170
- });
171
- };
173
+ const resolve = (contacts) => this.sendAsync({
174
+ type: ClientEventType.CONTACTS_AUTO_SUGGEST,
175
+ payload: {
176
+ contacts,
177
+ query,
178
+ },
179
+ });
172
180
  const reject = (reason) => {
173
181
  console.debug(reason);
174
182
  };
@@ -5,11 +5,12 @@ import { AutoSuggestResult, Callback, ConnectClient, EventType, Reject, RemoveEv
5
5
  * */
6
6
  export declare class Client implements ConnectClient {
7
7
  private static instance;
8
- static getInstance(): ConnectClient;
8
+ static getInstance(): Client;
9
+ static initialize(renderer: () => Promise<void>): void;
9
10
  private worker;
10
11
  private listeners;
11
12
  private useSubscription;
12
- private readonly iframeId?;
13
+ private readonly iframeId;
13
14
  private readonly variant;
14
15
  constructor();
15
16
  private sendAsync;
@@ -27,8 +28,8 @@ export declare class Client implements ConnectClient {
27
28
  reboot(): Promise<Response>;
28
29
  setViewport(payload: ViewPortSize): Promise<Response>;
29
30
  toClipboard(payload: string): Promise<Response>;
30
- isNotAuthorized(payload: string): Promise<Response>;
31
- isAuthorized(payload: string): Promise<Response>;
31
+ isNotAuthorized(): Promise<Response>;
32
+ isAuthorized(): Promise<Response>;
32
33
  getContactsAutoSuggest(payload: AutoSuggestResult): Promise<Response>;
33
34
  addEventListener<T extends EventType = EventType>(eventName: T, callback: Callback<T>): RemoveEventListener;
34
35
  removeEventListener<T extends EventType = EventType>(eventName: T | null, callback: Callback<T>): void;
@@ -50,7 +50,7 @@ export type Message<T extends MessageType = MessageType> = {
50
50
  payload?: EventPayload<T>;
51
51
  };
52
52
  export type MessageResponse<T extends MessageType = MessageType> = Message<T> & {
53
- iframeId?: string;
53
+ iframeId: string;
54
54
  };
55
55
  export type Payload = string | Record<string, string> | ThemeChangePayload;
56
56
  export type Response<T extends Payload = Payload> = {
@@ -167,10 +167,10 @@ export interface ConnectClient {
167
167
  getContactsAutoSuggest: (payload: AutoSuggestResult) => Promise<Response>;
168
168
  /**
169
169
  * pushes to x-bees message that user is authorized and no more actions required */
170
- isAuthorized: (payload: string) => Promise<Response>;
170
+ isAuthorized: () => Promise<Response>;
171
171
  /**
172
172
  * pushes to x-bees message that user actions required */
173
- isNotAuthorized: (payload: string) => Promise<Response>;
173
+ isNotAuthorized: () => Promise<Response>;
174
174
  /**
175
175
  * Starts listen for one of the events of the x-bees and handle with the provided callback */
176
176
  addEventListener: <T extends EventType = EventType>(eventName: T, callback: Callback<T>) => RemoveEventListener;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wildix/xbees-connect",
3
- "version": "1.0.4-alpha.10",
3
+ "version": "1.0.5-alpha.0",
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": "",
@@ -14,7 +14,7 @@
14
14
  "build:es": "tsc -p tsconfig.es.json",
15
15
  "build:types": "tsc -p tsconfig.types.json",
16
16
  "build:docs": "typedoc",
17
- "lint": "eslint .",
17
+ "lint": "eslint . && tsc --noEmit",
18
18
  "lint:fix": "eslint . --fix",
19
19
  "clean": "rimraf ./dist-* && rimraf *.tsbuildinfo"
20
20
  },
@@ -23,7 +23,7 @@
23
23
  ],
24
24
  "repository": {
25
25
  "type": "git",
26
- "url": "git@git.wildix.com:dimitri.chernykh/sdk-ui.git"
26
+ "url": "git@git.wildix.com:xbs/sdk-ui.git"
27
27
  },
28
28
  "publishConfig": {
29
29
  "access": "public"
@@ -41,5 +41,5 @@
41
41
  "engines": {
42
42
  "node": ">=16"
43
43
  },
44
- "gitHead": "2a4305e68084729846257fbee0d565c4beb0272c"
44
+ "gitHead": "feeea3ba3e36abc8ac978906e83ba8015d57a3ba"
45
45
  }