@wildix/xbees-connect 1.1.5 → 1.1.7
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/dist-es/package.json +1 -1
- package/dist-es/src/Client.js +12 -6
- package/dist-es/src/enums/index.js +2 -0
- package/dist-es/src/helpers/LocalStorageManager.js +0 -1
- package/dist-es/src/utils/url/getUrlSearchParamsMap.js +3 -0
- package/dist-types/src/Client.d.ts +4 -2
- package/dist-types/src/enums/index.d.ts +2 -0
- package/dist-types/src/utils/url/getUrlSearchParamsMap.d.ts +1 -0
- package/dist-types/types/index.d.ts +15 -2
- package/package.json +2 -2
package/dist-es/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wildix/xbees-connect",
|
|
3
|
-
"version": "1.1.
|
|
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": "",
|
package/dist-es/src/Client.js
CHANGED
|
@@ -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 =
|
|
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,11 +121,10 @@ export class Client {
|
|
|
120
121
|
return this.referrer;
|
|
121
122
|
}
|
|
122
123
|
getBackToAppUrl() {
|
|
123
|
-
const url = new URL(`${this.referrer}/integrations/${this.iframeId}`);
|
|
124
124
|
if (Client.getInstance().isPlatformNative()) {
|
|
125
|
-
|
|
125
|
+
return `com.wildix.rnc://integrations/${this.iframeId}`;
|
|
126
126
|
}
|
|
127
|
-
return
|
|
127
|
+
return `${this.referrer}/integrations/${this.iframeId}`;
|
|
128
128
|
}
|
|
129
129
|
isDataOnly() {
|
|
130
130
|
return this.variant === 'no-ui' || this.variant === 'daemon';
|
|
@@ -168,6 +168,9 @@ export class Client {
|
|
|
168
168
|
toClipboard(payload) {
|
|
169
169
|
return this.sendAsync({ type: ClientEventType.TO_CLIPBOARD, payload });
|
|
170
170
|
}
|
|
171
|
+
showToast(message, severity = 'INFO') {
|
|
172
|
+
return this.sendAsync({ type: ClientEventType.TOAST, payload: { message, severity } });
|
|
173
|
+
}
|
|
171
174
|
isNotAuthorized() {
|
|
172
175
|
return this.sendAsync({ type: ClientEventType.NOT_AUTHORIZED });
|
|
173
176
|
}
|
|
@@ -223,6 +226,9 @@ export class Client {
|
|
|
223
226
|
onPbxTokenChange(callback) {
|
|
224
227
|
return this.addEventListener(EventType.PBX_TOKEN, callback);
|
|
225
228
|
}
|
|
229
|
+
getXBeesToken() {
|
|
230
|
+
return this.sendAsync({ type: ClientEventType.TOKEN });
|
|
231
|
+
}
|
|
226
232
|
onSuggestContacts(callback) {
|
|
227
233
|
return this.addEventListener(EventType.GET_CONTACTS_AUTO_SUGGEST, (query) => {
|
|
228
234
|
const resolve = (contacts) => this.sendAsync({
|
|
@@ -19,8 +19,10 @@ 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";
|
|
25
|
+
ClientEventType["TOKEN"] = "xBeesToken";
|
|
24
26
|
ClientEventType["CONTACTS_AUTO_SUGGEST"] = "xBeesContactsAutoSuggest";
|
|
25
27
|
ClientEventType["CONTACT_LOOKUP_AND_MATCH"] = "xBeesContactLookupAndMatch";
|
|
26
28
|
ClientEventType["CONTACT_CREATE_OR_UPDATE"] = "xBeesContactCreateOrUpdate";
|
|
@@ -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
|
|
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>>;
|
|
@@ -55,6 +56,7 @@ export declare class Client implements ConnectClient {
|
|
|
55
56
|
onCallEnded(callback: Callback<EventType.TERMINATE_CALL>): RemoveEventListener;
|
|
56
57
|
onCallStarted(callback: Callback<EventType.ADD_CALL>): RemoveEventListener;
|
|
57
58
|
onPbxTokenChange(callback: Callback<EventType.PBX_TOKEN>): RemoveEventListener;
|
|
59
|
+
getXBeesToken(): Promise<Message<ClientEventType.TOKEN>>;
|
|
58
60
|
onSuggestContacts(callback: (query: string, resolve: SuggestContactsResolver, reject: Reject) => void): RemoveEventListener;
|
|
59
61
|
onLookupAndMatchContact(callback: (query: ContactQuery, resolve: LookupAndMatchContactsResolver, reject: Reject) => void): RemoveEventListener;
|
|
60
62
|
onThemeChange(callback: Callback<EventType.USE_THEME>): RemoveEventListener;
|
|
@@ -17,8 +17,10 @@ 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",
|
|
23
|
+
TOKEN = "xBeesToken",
|
|
22
24
|
CONTACTS_AUTO_SUGGEST = "xBeesContactsAutoSuggest",
|
|
23
25
|
CONTACT_LOOKUP_AND_MATCH = "xBeesContactLookupAndMatch",
|
|
24
26
|
CONTACT_CREATE_OR_UPDATE = "xBeesContactCreateOrUpdate"
|
|
@@ -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.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>>;
|
|
@@ -193,6 +203,9 @@ export interface ConnectClient {
|
|
|
193
203
|
/**
|
|
194
204
|
* Starts listen for the events of changing pbx token and handle with the provided callback */
|
|
195
205
|
onPbxTokenChange: (callback: Callback<EventType.PBX_TOKEN>) => RemoveEventListener;
|
|
206
|
+
/**
|
|
207
|
+
* Retrieves current x-bees token */
|
|
208
|
+
getXBeesToken: () => Promise<Message<ClientEventType.TOKEN>>;
|
|
196
209
|
/**
|
|
197
210
|
* Starts listen for the events of searching contacts and handle autosuggestion with the provided callback */
|
|
198
211
|
onSuggestContacts: (callback: (query: string, resolve: SuggestContactsResolver, reject: Reject) => void) => RemoveEventListener;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wildix/xbees-connect",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.7",
|
|
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": "
|
|
45
|
+
"gitHead": "0f4783eaf917b09c70b65745fc2a264331d4c721"
|
|
46
46
|
}
|