@wildix/xbees-connect 1.1.4 → 1.1.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.
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wildix/xbees-connect",
3
- "version": "1.1.4-y.0",
3
+ "version": "1.1.5",
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": "",
@@ -3,6 +3,7 @@ import { ClientEventType, DeprecatedUrlParams, EventType, UrlParams } from './en
3
3
  import LocalStorageManager from './helpers/LocalStorageManager';
4
4
  import PostMessageControllerNative from './helpers/PostMessageControllerNative';
5
5
  import PostMessageControllerWeb from './helpers/PostMessageControllerWeb';
6
+ import { getUrlSearchParamsMap } from './utils/url/getUrlSearchParamsMap';
6
7
  /**
7
8
  * Client provides functionality of communication between xBees and integrated web applications via iFrame or ReactNative WebView
8
9
  * integration creates na instance with new Client()
@@ -40,7 +41,7 @@ export class Client {
40
41
  variant = null;
41
42
  localStorageManager = LocalStorageManager.getInstance();
42
43
  constructor() {
43
- const params = new URLSearchParams(window.location.search);
44
+ const params = getUrlSearchParamsMap();
44
45
  this.iframeId = (params.get(UrlParams.ID) ?? params.get(DeprecatedUrlParams.ID));
45
46
  this.variant = (params.get(UrlParams.VARIANT) ?? params.get(DeprecatedUrlParams.VARIANT));
46
47
  this.userEmail = (params.get(UrlParams.USER) ?? params.get(DeprecatedUrlParams.USER));
@@ -95,10 +96,10 @@ export class Client {
95
96
  }
96
97
  });
97
98
  }
98
- ready() {
99
+ ready(platform = 'all') {
99
100
  return this.sendAsync({
100
101
  type: ClientEventType.READY,
101
- payload: { version: this.version() },
102
+ payload: { version: this.version(), platform },
102
103
  });
103
104
  }
104
105
  version() {
@@ -120,6 +121,9 @@ export class Client {
120
121
  return this.referrer;
121
122
  }
122
123
  getBackToAppUrl() {
124
+ if (Client.getInstance().isPlatformNative()) {
125
+ return `com.wildix.rnc://integrations/${this.iframeId}`;
126
+ }
123
127
  return `${this.referrer}/integrations/${this.iframeId}`;
124
128
  }
125
129
  isDataOnly() {
@@ -164,6 +168,9 @@ export class Client {
164
168
  toClipboard(payload) {
165
169
  return this.sendAsync({ type: ClientEventType.TO_CLIPBOARD, payload });
166
170
  }
171
+ showToast(message, severity = 'INFO') {
172
+ return this.sendAsync({ type: ClientEventType.TOAST, payload: { message, severity } });
173
+ }
167
174
  isNotAuthorized() {
168
175
  return this.sendAsync({ type: ClientEventType.NOT_AUTHORIZED });
169
176
  }
@@ -19,6 +19,7 @@ export var ClientEventType;
19
19
  ClientEventType["VIEW_PORT"] = "xBeesViewPort";
20
20
  ClientEventType["REBOOT"] = "xBeesReboot";
21
21
  ClientEventType["TO_CLIPBOARD"] = "xBeesToClipboard";
22
+ ClientEventType["TOAST"] = "xBeesShowToast";
22
23
  ClientEventType["NOT_AUTHORIZED"] = "xBeesNotAuthorized";
23
24
  ClientEventType["AUTHORIZED"] = "xBeesAuthorized";
24
25
  ClientEventType["CONTACTS_AUTO_SUGGEST"] = "xBeesContactsAutoSuggest";
@@ -54,7 +54,6 @@ class LocalStorageManager {
54
54
  return !data ? data : JSON.parse(data);
55
55
  }
56
56
  catch (error) {
57
- console.debug('parse data error', error);
58
57
  return data;
59
58
  }
60
59
  }
@@ -0,0 +1,3 @@
1
+ export function getUrlSearchParamsMap() {
2
+ return new URLSearchParams(window.location.search);
3
+ }
@@ -1,4 +1,4 @@
1
- import { Callback, ConnectClient, Contact, ContactQuery, IPayloadAutoSuggestResult, IPayloadContactMatchResult, IPayloadViewPort, LookupAndMatchContactsResolver, Message, Reject, RemoveEventListener, ResponseMessage, StorageEventCallback, SuggestContactsResolver } from '../types';
1
+ import { Callback, ConnectClient, Contact, ContactQuery, IPayloadAutoSuggestResult, IPayloadContactMatchResult, IPayloadViewPort, LookupAndMatchContactsResolver, Message, Reject, RemoveEventListener, ResponseMessage, StorageEventCallback, SuggestContactsResolver, SupportedPlatformVariant, ToastSeverity } from '../types';
2
2
  import { ClientEventType, EventType } from './enums';
3
3
  /**
4
4
  * Client provides functionality of communication between xBees and integrated web applications via iFrame or ReactNative WebView
@@ -23,7 +23,7 @@ export declare class Client implements ConnectClient {
23
23
  private sendAsync;
24
24
  private parseMessage;
25
25
  private onMessage;
26
- ready(): Promise<ResponseMessage<ClientEventType.READY>>;
26
+ ready(platform?: SupportedPlatformVariant | undefined): Promise<ResponseMessage>;
27
27
  version(): string;
28
28
  isPlatformNative(): boolean;
29
29
  isPlatformWeb(): boolean;
@@ -44,6 +44,7 @@ export declare class Client implements ConnectClient {
44
44
  reboot(): Promise<ResponseMessage>;
45
45
  setViewport(payload: IPayloadViewPort): Promise<ResponseMessage>;
46
46
  toClipboard(payload: string): Promise<ResponseMessage>;
47
+ showToast(message: string, severity?: ToastSeverity | undefined): Promise<ResponseMessage>;
47
48
  isNotAuthorized(): Promise<ResponseMessage>;
48
49
  isAuthorized(): Promise<ResponseMessage>;
49
50
  sendContactsAutoSuggest(payload: IPayloadAutoSuggestResult): Promise<Message<ClientEventType.CONTACTS_AUTO_SUGGEST>>;
@@ -17,6 +17,7 @@ export declare enum ClientEventType {
17
17
  VIEW_PORT = "xBeesViewPort",
18
18
  REBOOT = "xBeesReboot",
19
19
  TO_CLIPBOARD = "xBeesToClipboard",
20
+ TOAST = "xBeesShowToast",
20
21
  NOT_AUTHORIZED = "xBeesNotAuthorized",
21
22
  AUTHORIZED = "xBeesAuthorized",
22
23
  CONTACTS_AUTO_SUGGEST = "xBeesContactsAutoSuggest",
@@ -0,0 +1 @@
1
+ export declare function getUrlSearchParamsMap(): URLSearchParams;
@@ -29,6 +29,12 @@ export interface IPayloadViewPort {
29
29
  }
30
30
  export interface IPayloadVersion {
31
31
  version: string;
32
+ platform?: SupportedPlatformVariant;
33
+ }
34
+ export type ToastSeverity = 'INFO' | 'WARNING' | 'ERROR' | 'SUCCESS' | 'NOTICE';
35
+ export interface IPayloadToast {
36
+ severity: ToastSeverity;
37
+ message: string;
32
38
  }
33
39
  export interface IPayloadThemeChange {
34
40
  mode: 'light' | 'dark';
@@ -57,7 +63,7 @@ export interface IPayloadContactResult {
57
63
  }
58
64
  export interface IPayloadContextResult extends IPayloadContactResult {
59
65
  }
60
- type EventPayload<T extends MessageType> = T extends EventType.GET_CONTACTS_AUTO_SUGGEST ? string : T extends ClientEventType.CONTACTS_AUTO_SUGGEST ? IPayloadAutoSuggestResult : T extends ClientEventType.CONTACT_LOOKUP_AND_MATCH ? IPayloadContactMatchResult : T extends ClientEventType.CONTACT_CREATE_OR_UPDATE ? IPayloadContactMatchResult : T extends ClientEventType.CONTEXT ? IPayloadContextResult : T extends ClientEventType.CURRENT_CONTACT ? IPayloadContactResult : T extends EventType.ADD_CALL ? IPayloadCallStartedInfo : T extends ClientEventType.START_CALL ? IPayloadCallStart : T extends ClientEventType.READY ? IPayloadVersion : T extends ClientEventType.VIEW_PORT ? IPayloadViewPort : T extends ClientEventType.THEME ? IPayloadThemeChange : T extends EventType.USE_THEME ? IPayloadThemeChange : T extends EventType.PBX_TOKEN ? string : T extends ClientEventType.TO_CLIPBOARD ? string : never;
66
+ type EventPayload<T extends MessageType> = T extends EventType.GET_CONTACTS_AUTO_SUGGEST ? string : T extends ClientEventType.CONTACTS_AUTO_SUGGEST ? IPayloadAutoSuggestResult : T extends ClientEventType.CONTACT_LOOKUP_AND_MATCH ? IPayloadContactMatchResult : T extends ClientEventType.CONTACT_CREATE_OR_UPDATE ? IPayloadContactMatchResult : T extends ClientEventType.CONTEXT ? IPayloadContextResult : T extends ClientEventType.CURRENT_CONTACT ? IPayloadContactResult : T extends EventType.ADD_CALL ? IPayloadCallStartedInfo : T extends ClientEventType.START_CALL ? IPayloadCallStart : T extends ClientEventType.READY ? IPayloadVersion : T extends ClientEventType.VIEW_PORT ? IPayloadViewPort : T extends ClientEventType.THEME ? IPayloadThemeChange : T extends EventType.USE_THEME ? IPayloadThemeChange : T extends ClientEventType.TOAST ? IPayloadToast : T extends EventType.PBX_TOKEN ? string : T extends ClientEventType.TO_CLIPBOARD ? string : never;
61
67
  export type Message<T extends MessageType = MessageType> = {
62
68
  type: T;
63
69
  payload?: EventPayload<T>;
@@ -102,10 +108,11 @@ export type SuggestContactsResolver = (contacts: Contact[]) => void;
102
108
  export type LookupAndMatchContactsResolver = (contact: Contact) => void;
103
109
  export type Reject = (reason: string) => void;
104
110
  export type RemoveEventListener = () => void;
111
+ export type SupportedPlatformVariant = 'all' | 'web' | 'mobile';
105
112
  export interface ConnectClient {
106
113
  /**
107
114
  * Sends to x-bees signal that iFrame is ready to be shown. iFrame should send it when the application starts and ready */
108
- ready: () => Promise<ResponseMessage>;
115
+ ready: (platform?: SupportedPlatformVariant) => Promise<ResponseMessage>;
109
116
  /**
110
117
  * Retrieves current pbx token */
111
118
  getUserPbxToken: () => string;
@@ -169,6 +176,9 @@ export interface ConnectClient {
169
176
  /**
170
177
  * Sends request to x-bees to put string to the users clipboard */
171
178
  toClipboard: (payload: string) => Promise<ResponseMessage>;
179
+ /**
180
+ * Sends message to x-bees to be shown as a toast with specified severity level */
181
+ showToast: (message: string, severity?: ToastSeverity) => Promise<ResponseMessage>;
172
182
  /**
173
183
  * Sends a response to x-bees for contacts autoSuggest */
174
184
  sendContactsAutoSuggest: (payload: IPayloadAutoSuggestResult) => Promise<Message<ClientEventType.CONTACTS_AUTO_SUGGEST>>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wildix/xbees-connect",
3
- "version": "1.1.4",
3
+ "version": "1.1.6",
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": "485f83d2aa614de28b039aaa7c3bc788e10cbbb9"
45
+ "gitHead": "1374b364b1fe0c035ffd6e8dbb040cca28088edf"
46
46
  }