@wildix/xbees-connect 1.1.2 → 1.1.4-y.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/dist-es/package.json +1 -1
- package/dist-es/src/Client.js +19 -2
- package/dist-es/src/helpers/LocalStorageManager.js +2 -2
- package/dist-types/src/Client.d.ts +7 -1
- package/dist-types/src/helpers/LocalStorageManager.d.ts +1 -1
- package/dist-types/types/index.d.ts +17 -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.3",
|
|
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
|
@@ -35,6 +35,7 @@ export class Client {
|
|
|
35
35
|
userEmail;
|
|
36
36
|
referrer;
|
|
37
37
|
needAuthorize;
|
|
38
|
+
isParentReactNativeWebView;
|
|
38
39
|
iframeId;
|
|
39
40
|
variant = null;
|
|
40
41
|
localStorageManager = LocalStorageManager.getInstance();
|
|
@@ -47,7 +48,8 @@ export class Client {
|
|
|
47
48
|
this.referrer = (params.get(UrlParams.REFERRER) ?? params.get(DeprecatedUrlParams.REFERRER));
|
|
48
49
|
this.needAuthorize = (params.has(UrlParams.AUTHORIZE) ?? params.has(DeprecatedUrlParams.AUTHORIZE));
|
|
49
50
|
// @ts-expect-error window.ReactNativeWebView will be provided by ReactNative WebView
|
|
50
|
-
this.
|
|
51
|
+
this.isParentReactNativeWebView = !!window.ReactNativeWebView;
|
|
52
|
+
this.worker = this.isParentReactNativeWebView
|
|
51
53
|
? new PostMessageControllerNative()
|
|
52
54
|
: new PostMessageControllerWeb();
|
|
53
55
|
this.addEventListener(EventType.PBX_TOKEN, (token) => this.userToken = token);
|
|
@@ -102,15 +104,30 @@ export class Client {
|
|
|
102
104
|
version() {
|
|
103
105
|
return packageJson.version;
|
|
104
106
|
}
|
|
107
|
+
isPlatformNative() {
|
|
108
|
+
return this.isParentReactNativeWebView;
|
|
109
|
+
}
|
|
110
|
+
isPlatformWeb() {
|
|
111
|
+
return !this.isParentReactNativeWebView;
|
|
112
|
+
}
|
|
105
113
|
getUserPbxToken() {
|
|
106
114
|
return this.userToken;
|
|
107
115
|
}
|
|
108
116
|
getUserEmail() {
|
|
109
117
|
return this.userEmail;
|
|
110
118
|
}
|
|
119
|
+
getReferrer() {
|
|
120
|
+
return this.referrer;
|
|
121
|
+
}
|
|
122
|
+
getBackToAppUrl() {
|
|
123
|
+
return `${this.referrer}/integrations/${this.iframeId}`;
|
|
124
|
+
}
|
|
111
125
|
isDataOnly() {
|
|
112
126
|
return this.variant === 'no-ui' || this.variant === 'daemon';
|
|
113
127
|
}
|
|
128
|
+
isSetupDialog() {
|
|
129
|
+
return this.variant === 'd' || this.variant === 'dialog';
|
|
130
|
+
}
|
|
114
131
|
showsUi() {
|
|
115
132
|
return !this.isDataOnly();
|
|
116
133
|
}
|
|
@@ -252,6 +269,6 @@ export class Client {
|
|
|
252
269
|
this.localStorageManager.delete(key);
|
|
253
270
|
}
|
|
254
271
|
onStorage(listener) {
|
|
255
|
-
this.localStorageManager.onStorage(listener);
|
|
272
|
+
return this.localStorageManager.onStorage(listener);
|
|
256
273
|
}
|
|
257
274
|
}
|
|
@@ -37,8 +37,7 @@ class LocalStorageManager {
|
|
|
37
37
|
return '';
|
|
38
38
|
}
|
|
39
39
|
shouldUseIntegrationKey() {
|
|
40
|
-
return
|
|
41
|
-
window.location.pathname.endsWith('/index.html'));
|
|
40
|
+
return window.location.host.endsWith('integrations.x-bees.com');
|
|
42
41
|
}
|
|
43
42
|
save(key, value) {
|
|
44
43
|
// Save data to localStorage
|
|
@@ -64,6 +63,7 @@ class LocalStorageManager {
|
|
|
64
63
|
}
|
|
65
64
|
onStorage(listener) {
|
|
66
65
|
this.listeners.add(listener);
|
|
66
|
+
return () => this.removeOnStorage(listener);
|
|
67
67
|
}
|
|
68
68
|
removeOnStorage(listener) {
|
|
69
69
|
this.listeners.delete(listener);
|
|
@@ -15,6 +15,7 @@ export declare class Client implements ConnectClient {
|
|
|
15
15
|
private readonly userEmail;
|
|
16
16
|
private readonly referrer;
|
|
17
17
|
private readonly needAuthorize;
|
|
18
|
+
private readonly isParentReactNativeWebView;
|
|
18
19
|
private readonly iframeId;
|
|
19
20
|
private readonly variant;
|
|
20
21
|
private readonly localStorageManager;
|
|
@@ -24,9 +25,14 @@ export declare class Client implements ConnectClient {
|
|
|
24
25
|
private onMessage;
|
|
25
26
|
ready(): Promise<ResponseMessage<ClientEventType.READY>>;
|
|
26
27
|
version(): string;
|
|
28
|
+
isPlatformNative(): boolean;
|
|
29
|
+
isPlatformWeb(): boolean;
|
|
27
30
|
getUserPbxToken(): string;
|
|
28
31
|
getUserEmail(): string;
|
|
32
|
+
getReferrer(): string;
|
|
33
|
+
getBackToAppUrl(): string;
|
|
29
34
|
isDataOnly(): boolean;
|
|
35
|
+
isSetupDialog(): boolean;
|
|
30
36
|
showsUi(): boolean;
|
|
31
37
|
isActivationOnly(): boolean;
|
|
32
38
|
getContext(): Promise<Message<ClientEventType.CONTEXT>>;
|
|
@@ -54,5 +60,5 @@ export declare class Client implements ConnectClient {
|
|
|
54
60
|
getFromStorage<Type>(key: string): Type | null;
|
|
55
61
|
saveToStorage<SavingType>(key: string, value: SavingType): void;
|
|
56
62
|
deleteFromStorage(key: string): void;
|
|
57
|
-
onStorage(listener: StorageEventCallback): void;
|
|
63
|
+
onStorage(listener: StorageEventCallback): () => void;
|
|
58
64
|
}
|
|
@@ -13,7 +13,7 @@ declare class LocalStorageManager {
|
|
|
13
13
|
delete(key: string): void;
|
|
14
14
|
retrieve(key: string): any;
|
|
15
15
|
get(key: string): any;
|
|
16
|
-
onStorage(listener: StorageEventCallback): void;
|
|
16
|
+
onStorage(listener: StorageEventCallback): () => void;
|
|
17
17
|
removeOnStorage(listener: StorageEventCallback): void;
|
|
18
18
|
}
|
|
19
19
|
export default LocalStorageManager;
|
|
@@ -57,7 +57,7 @@ export interface IPayloadContactResult {
|
|
|
57
57
|
}
|
|
58
58
|
export interface IPayloadContextResult extends IPayloadContactResult {
|
|
59
59
|
}
|
|
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 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;
|
|
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;
|
|
61
61
|
export type Message<T extends MessageType = MessageType> = {
|
|
62
62
|
type: T;
|
|
63
63
|
payload?: EventPayload<T>;
|
|
@@ -110,12 +110,27 @@ export interface ConnectClient {
|
|
|
110
110
|
/**
|
|
111
111
|
* Retrieves current user's email */
|
|
112
112
|
getUserEmail: () => string;
|
|
113
|
+
/**
|
|
114
|
+
* Retrieves url for x-bees app which uses integration */
|
|
115
|
+
getReferrer: () => string;
|
|
116
|
+
/**
|
|
117
|
+
* Retrieves url to get back to x-bees app integration */
|
|
118
|
+
getBackToAppUrl: () => string;
|
|
113
119
|
/**
|
|
114
120
|
* Retrieves the version of xBeesConnect */
|
|
115
121
|
version: () => string;
|
|
122
|
+
/**
|
|
123
|
+
* Determines x-bees is running on mobile native platform */
|
|
124
|
+
isPlatformNative: () => boolean;
|
|
125
|
+
/**
|
|
126
|
+
* Determines x-bees is running on web browser platform */
|
|
127
|
+
isPlatformWeb: () => boolean;
|
|
116
128
|
/**
|
|
117
129
|
* Determines x-bees is using this connect for messages only and this integration will not be shown on UI */
|
|
118
130
|
isDataOnly: () => boolean;
|
|
131
|
+
/**
|
|
132
|
+
* Determines x-bees is using this connect for show dialog of setup flow */
|
|
133
|
+
isSetupDialog: () => boolean;
|
|
119
134
|
/**
|
|
120
135
|
* Determines x-bees is using this connect for representation on UI and this integration will be shown on UI
|
|
121
136
|
* this opposite to {@link isDataOnly} */
|
|
@@ -202,6 +217,6 @@ export interface ConnectClient {
|
|
|
202
217
|
deleteFromStorage: (key: string) => void;
|
|
203
218
|
/**
|
|
204
219
|
* listens on localStorage */
|
|
205
|
-
onStorage: (listener: StorageEventCallback) => void;
|
|
220
|
+
onStorage: (listener: StorageEventCallback) => () => void;
|
|
206
221
|
}
|
|
207
222
|
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wildix/xbees-connect",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.4-y.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": "",
|
|
@@ -42,5 +42,5 @@
|
|
|
42
42
|
"engines": {
|
|
43
43
|
"node": ">=16"
|
|
44
44
|
},
|
|
45
|
-
"gitHead": "
|
|
45
|
+
"gitHead": "25634a49d107ae0911bcd1d41ad29e292db2f4e1"
|
|
46
46
|
}
|