@wildix/xbees-connect 1.1.17 → 1.1.21

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.
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wildix/xbees-connect",
3
- "version": "1.1.16",
3
+ "version": "1.1.21",
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": "",
@@ -47,13 +47,11 @@ export class Client {
47
47
  this.userEmail = (params.get(UrlParams.USER) ?? params.get(DeprecatedUrlParams.USER));
48
48
  this.userToken = (params.get(UrlParams.TOKEN) ?? params.get(DeprecatedUrlParams.TOKEN));
49
49
  this.referrer = (params.get(UrlParams.REFERRER) ?? params.get(DeprecatedUrlParams.REFERRER));
50
- this.needAuthorize = (params.has(UrlParams.AUTHORIZE) ?? params.has(DeprecatedUrlParams.AUTHORIZE));
50
+ this.needAuthorize = params.has(UrlParams.AUTHORIZE) ?? params.has(DeprecatedUrlParams.AUTHORIZE);
51
51
  // @ts-expect-error window.ReactNativeWebView will be provided by ReactNative WebView
52
52
  this.isParentReactNativeWebView = !!window.ReactNativeWebView;
53
- this.worker = this.isParentReactNativeWebView
54
- ? new PostMessageControllerNative()
55
- : new PostMessageControllerWeb();
56
- this.addEventListener(EventType.PBX_TOKEN, (token) => this.userToken = token);
53
+ this.worker = this.isParentReactNativeWebView ? new PostMessageControllerNative() : new PostMessageControllerWeb();
54
+ this.addEventListener(EventType.PBX_TOKEN, (token) => (this.userToken = token));
57
55
  }
58
56
  sendAsync(data) {
59
57
  return this.worker.sendAsync({
@@ -61,11 +59,17 @@ export class Client {
61
59
  iframeId: this.iframeId,
62
60
  });
63
61
  }
62
+ async sendAsyncErrorSafe(data) {
63
+ try {
64
+ return await this.sendAsync(data);
65
+ }
66
+ catch (error) {
67
+ console.debug('send error - type:', error);
68
+ }
69
+ }
64
70
  parseMessage(message) {
65
71
  try {
66
- const data = typeof message.data === 'string'
67
- ? JSON.parse(message.data)
68
- : message.data;
72
+ const data = typeof message.data === 'string' ? JSON.parse(message.data) : message.data;
69
73
  if (!data?.type) {
70
74
  return null;
71
75
  }
@@ -197,8 +201,7 @@ export class Client {
197
201
  };
198
202
  }
199
203
  removeEventListener(eventName, callback) {
200
- this.listeners = this.listeners.filter(({ eventName: _eventName, callback: _callback }) => !(Object.is(callback, _callback) &&
201
- (!eventName ? true : eventName === _eventName)));
204
+ this.listeners = this.listeners.filter(({ eventName: _eventName, callback: _callback }) => !(Object.is(callback, _callback) && (!eventName ? true : eventName === _eventName)));
202
205
  if (this.useSubscription && !this.listeners.length) {
203
206
  this.useSubscription = false;
204
207
  window.removeEventListener('message', this.onMessage.bind(this));
@@ -225,14 +228,9 @@ export class Client {
225
228
  }
226
229
  onSuggestContacts(callback) {
227
230
  // send event to x-bees
228
- try {
229
- void this.sendAsync({
230
- type: ClientEventType.CONTACTS_AUTO_SUGGEST_IS_SUPPORTED,
231
- });
232
- }
233
- catch (error) {
234
- console.debug('send error - type:', error);
235
- }
231
+ void this.sendAsyncErrorSafe({
232
+ type: ClientEventType.CONTACTS_AUTO_SUGGEST_IS_SUPPORTED,
233
+ });
236
234
  return this.addEventListener(EventType.GET_CONTACTS_AUTO_SUGGEST, (query) => {
237
235
  const resolve = (contacts) => this.sendAsync({
238
236
  type: ClientEventType.CONTACTS_AUTO_SUGGEST,
@@ -254,14 +252,9 @@ export class Client {
254
252
  }
255
253
  onLookupAndMatchContact(callback) {
256
254
  // send event to x-bees
257
- try {
258
- void this.sendAsync({
259
- type: ClientEventType.CONTACT_LOOK_UP_AND_MATCH_IS_SUPPORTED,
260
- });
261
- }
262
- catch (error) {
263
- console.debug('send error - type:', error);
264
- }
255
+ void this.sendAsyncErrorSafe({
256
+ type: ClientEventType.CONTACT_LOOK_UP_AND_MATCH_IS_SUPPORTED,
257
+ });
265
258
  return this.addEventListener(EventType.GET_LOOK_UP_AND_MATCH, (query) => {
266
259
  const resolve = (contact) => this.sendAsync({
267
260
  type: ClientEventType.CONTACT_LOOKUP_AND_MATCH,
@@ -1,3 +1,6 @@
1
+ export var EventType1;
2
+ (function (EventType1) {
3
+ })(EventType1 || (EventType1 = {}));
1
4
  export var EventType;
2
5
  (function (EventType) {
3
6
  EventType["GET_CONTACTS_AUTO_SUGGEST"] = "xBeesGetContactsAutoSuggest";
@@ -15,9 +15,7 @@ class LocalStorageManager {
15
15
  return !this.integrationKey ? key : `${this.integrationKey}_${key}`;
16
16
  }
17
17
  getKey(key) {
18
- return !this.integrationKey
19
- ? key
20
- : key.slice(`${this.integrationKey}_`.length);
18
+ return !this.integrationKey ? key : key.slice(`${this.integrationKey}_`.length);
21
19
  }
22
20
  constructor() {
23
21
  if (this.shouldUseIntegrationKey()) {
@@ -21,6 +21,7 @@ export declare class Client implements ConnectClient {
21
21
  private readonly localStorageManager;
22
22
  constructor();
23
23
  private sendAsync;
24
+ private sendAsyncErrorSafe;
24
25
  private parseMessage;
25
26
  private onMessage;
26
27
  ready(platform?: SupportedPlatformVariant | undefined): Promise<ResponseMessage>;
@@ -1,3 +1,5 @@
1
+ export declare enum EventType1 {
2
+ }
1
3
  export declare enum EventType {
2
4
  GET_CONTACTS_AUTO_SUGGEST = "xBeesGetContactsAutoSuggest",
3
5
  GET_LOOK_UP_AND_MATCH = "xBeesGetLookUpAndMatch",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wildix/xbees-connect",
3
- "version": "1.1.17",
3
+ "version": "1.1.21",
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": "",
@@ -42,5 +42,5 @@
42
42
  "engines": {
43
43
  "node": ">=16"
44
44
  },
45
- "gitHead": "4e7dcc5d346412949b0b9ad31ba5aa7ecb685d92"
45
+ "gitHead": "48e2a82b88e4228028e3d0e0470d06aa3c20a1df"
46
46
  }