@wildix/xbees-connect 1.1.2-alpha.4 → 1.1.3
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 +13 -2
- package/dist-es/src/helpers/LocalStorageManager.js +4 -3
- package/dist-types/src/Client.d.ts +5 -1
- package/dist-types/src/helpers/LocalStorageManager.d.ts +1 -1
- package/dist-types/types/index.d.ts +11 -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.2
|
|
3
|
+
"version": "1.1.2",
|
|
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,6 +104,12 @@ 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
|
}
|
|
@@ -111,6 +119,9 @@ export class Client {
|
|
|
111
119
|
isDataOnly() {
|
|
112
120
|
return this.variant === 'no-ui' || this.variant === 'daemon';
|
|
113
121
|
}
|
|
122
|
+
isSetupDialog() {
|
|
123
|
+
return this.variant === 'd' || this.variant === 'dialog';
|
|
124
|
+
}
|
|
114
125
|
showsUi() {
|
|
115
126
|
return !this.isDataOnly();
|
|
116
127
|
}
|
|
@@ -252,6 +263,6 @@ export class Client {
|
|
|
252
263
|
this.localStorageManager.delete(key);
|
|
253
264
|
}
|
|
254
265
|
onStorage(listener) {
|
|
255
|
-
this.localStorageManager.onStorage(listener);
|
|
266
|
+
return this.localStorageManager.onStorage(listener);
|
|
256
267
|
}
|
|
257
268
|
}
|
|
@@ -42,7 +42,7 @@ class LocalStorageManager {
|
|
|
42
42
|
}
|
|
43
43
|
save(key, value) {
|
|
44
44
|
// Save data to localStorage
|
|
45
|
-
localStorage.setItem(this.getStorageKey(key), JSON.stringify(value));
|
|
45
|
+
localStorage.setItem(this.getStorageKey(key), typeof value === 'string' ? value : JSON.stringify(value));
|
|
46
46
|
}
|
|
47
47
|
delete(key) {
|
|
48
48
|
// Save data to localStorage
|
|
@@ -55,8 +55,8 @@ class LocalStorageManager {
|
|
|
55
55
|
return !data ? data : JSON.parse(data);
|
|
56
56
|
}
|
|
57
57
|
catch (error) {
|
|
58
|
-
console.
|
|
59
|
-
return
|
|
58
|
+
console.debug('parse data error', error);
|
|
59
|
+
return data;
|
|
60
60
|
}
|
|
61
61
|
}
|
|
62
62
|
get(key) {
|
|
@@ -64,6 +64,7 @@ class LocalStorageManager {
|
|
|
64
64
|
}
|
|
65
65
|
onStorage(listener) {
|
|
66
66
|
this.listeners.add(listener);
|
|
67
|
+
return () => this.removeOnStorage(listener);
|
|
67
68
|
}
|
|
68
69
|
removeOnStorage(listener) {
|
|
69
70
|
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,12 @@ 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;
|
|
29
32
|
isDataOnly(): boolean;
|
|
33
|
+
isSetupDialog(): boolean;
|
|
30
34
|
showsUi(): boolean;
|
|
31
35
|
isActivationOnly(): boolean;
|
|
32
36
|
getContext(): Promise<Message<ClientEventType.CONTEXT>>;
|
|
@@ -54,5 +58,5 @@ export declare class Client implements ConnectClient {
|
|
|
54
58
|
getFromStorage<Type>(key: string): Type | null;
|
|
55
59
|
saveToStorage<SavingType>(key: string, value: SavingType): void;
|
|
56
60
|
deleteFromStorage(key: string): void;
|
|
57
|
-
onStorage(listener: StorageEventCallback): void;
|
|
61
|
+
onStorage(listener: StorageEventCallback): () => void;
|
|
58
62
|
}
|
|
@@ -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>;
|
|
@@ -113,9 +113,18 @@ export interface ConnectClient {
|
|
|
113
113
|
/**
|
|
114
114
|
* Retrieves the version of xBeesConnect */
|
|
115
115
|
version: () => string;
|
|
116
|
+
/**
|
|
117
|
+
* Determines x-bees is running on mobile native platform */
|
|
118
|
+
isPlatformNative: () => boolean;
|
|
119
|
+
/**
|
|
120
|
+
* Determines x-bees is running on web browser platform */
|
|
121
|
+
isPlatformWeb: () => boolean;
|
|
116
122
|
/**
|
|
117
123
|
* Determines x-bees is using this connect for messages only and this integration will not be shown on UI */
|
|
118
124
|
isDataOnly: () => boolean;
|
|
125
|
+
/**
|
|
126
|
+
* Determines x-bees is using this connect for show dialog of setup flow */
|
|
127
|
+
isSetupDialog: () => boolean;
|
|
119
128
|
/**
|
|
120
129
|
* Determines x-bees is using this connect for representation on UI and this integration will be shown on UI
|
|
121
130
|
* this opposite to {@link isDataOnly} */
|
|
@@ -202,6 +211,6 @@ export interface ConnectClient {
|
|
|
202
211
|
deleteFromStorage: (key: string) => void;
|
|
203
212
|
/**
|
|
204
213
|
* listens on localStorage */
|
|
205
|
-
onStorage: (listener: StorageEventCallback) => void;
|
|
214
|
+
onStorage: (listener: StorageEventCallback) => () => void;
|
|
206
215
|
}
|
|
207
216
|
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.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": "",
|
|
@@ -42,5 +42,5 @@
|
|
|
42
42
|
"engines": {
|
|
43
43
|
"node": ">=16"
|
|
44
44
|
},
|
|
45
|
-
"gitHead": "
|
|
45
|
+
"gitHead": "435537928a3ad44f978eb4ab850d66d5729f06dc"
|
|
46
46
|
}
|