@wildix/xbees-connect 1.2.5 → 1.2.7-alpha.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 +2 -1
- package/dist-es/src/Client.js +26 -8
- package/dist-es/src/enums/index.js +0 -9
- package/dist-es/src/helpers/ClientParams.js +7 -7
- package/dist-es/src/utils/getPbxDomainFromJwt.js +11 -0
- package/dist-types/src/Client.d.ts +3 -0
- package/dist-types/src/enums/index.d.ts +0 -8
- package/dist-types/src/utils/getPbxDomainFromJwt.d.ts +1 -0
- package/dist-types/types/Client.d.ts +3 -0
- package/package.json +3 -2
package/dist-es/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wildix/xbees-connect",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.7-alpha.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": "",
|
|
@@ -32,6 +32,7 @@
|
|
|
32
32
|
"devDependencies": {
|
|
33
33
|
"@wildix/eslint-config-style-guide": "^1.2.2",
|
|
34
34
|
"eslint": "^8.55.0",
|
|
35
|
+
"jwt-decode": "^4.0.0",
|
|
35
36
|
"rimraf": "^5.0.5",
|
|
36
37
|
"typescript": "^5.3.3"
|
|
37
38
|
},
|
package/dist-es/src/Client.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import packageJson from '../package.json';
|
|
2
|
-
import { ClientEventType,
|
|
2
|
+
import { ClientEventType, EventType, UrlParams } from './enums';
|
|
3
3
|
import LocalStorageManager from './helpers/LocalStorageManager';
|
|
4
4
|
import { MessageListener } from './helpers/MessageListener';
|
|
5
5
|
import PostMessageControllerNative from './helpers/PostMessageControllerNative';
|
|
6
6
|
import PostMessageControllerWeb from './helpers/PostMessageControllerWeb';
|
|
7
7
|
import TechnicalSupport from './helpers/TechnicalSupport';
|
|
8
|
+
import { getPbxDomainFromJwt } from './utils/getPbxDomainFromJwt';
|
|
8
9
|
import { getUrlSearchParamsMap } from './utils/url/getUrlSearchParamsMap';
|
|
9
10
|
/**
|
|
10
11
|
* Client provides functionality of communication between xBees and integrated web applications via iFrame or ReactNative WebView
|
|
@@ -35,6 +36,7 @@ export class Client {
|
|
|
35
36
|
listeners = [];
|
|
36
37
|
useSubscription = false;
|
|
37
38
|
userToken;
|
|
39
|
+
pbxDomain;
|
|
38
40
|
visible = false;
|
|
39
41
|
userEmail;
|
|
40
42
|
referrer;
|
|
@@ -46,17 +48,21 @@ export class Client {
|
|
|
46
48
|
userExtension;
|
|
47
49
|
constructor() {
|
|
48
50
|
const params = getUrlSearchParamsMap();
|
|
49
|
-
this.iframeId =
|
|
50
|
-
this.variant =
|
|
51
|
-
this.userEmail =
|
|
51
|
+
this.iframeId = params.get(UrlParams.ID);
|
|
52
|
+
this.variant = params.get(UrlParams.VARIANT);
|
|
53
|
+
this.userEmail = params.get(UrlParams.USER);
|
|
52
54
|
this.userExtension = params.get(UrlParams.EXTENSION);
|
|
53
|
-
this.userToken =
|
|
54
|
-
this.referrer =
|
|
55
|
-
this.needAuthorize = params.has(UrlParams.AUTHORIZE)
|
|
55
|
+
this.userToken = params.get(UrlParams.TOKEN);
|
|
56
|
+
this.referrer = params.get(UrlParams.REFERRER);
|
|
57
|
+
this.needAuthorize = params.has(UrlParams.AUTHORIZE);
|
|
56
58
|
// @ts-expect-error window.ReactNativeWebView will be provided by ReactNative WebView
|
|
57
59
|
this.isParentReactNativeWebView = !!window.ReactNativeWebView;
|
|
58
60
|
this.worker = this.isParentReactNativeWebView ? new PostMessageControllerNative() : new PostMessageControllerWeb();
|
|
59
|
-
this.
|
|
61
|
+
this.pbxDomain = getPbxDomainFromJwt(this.userToken);
|
|
62
|
+
this.addEventListener(EventType.PBX_TOKEN, (token) => {
|
|
63
|
+
this.userToken = token;
|
|
64
|
+
this.pbxDomain = getPbxDomainFromJwt(token);
|
|
65
|
+
});
|
|
60
66
|
this.addEventListener(EventType.VISIBILITY, (isActive) => (this.visible = isActive));
|
|
61
67
|
}
|
|
62
68
|
sendAsync(data) {
|
|
@@ -106,6 +112,14 @@ export class Client {
|
|
|
106
112
|
}
|
|
107
113
|
});
|
|
108
114
|
}
|
|
115
|
+
sendDailyIntegrationUsageAnalytics() {
|
|
116
|
+
const sendedUsageAnalyticsDate = this.getFromStorage('sendedUsageAnalyticsDate');
|
|
117
|
+
const today = new Date().toDateString();
|
|
118
|
+
if (sendedUsageAnalyticsDate !== today) {
|
|
119
|
+
this.sendAnalytics('xBeesIntegrationUsage');
|
|
120
|
+
this.saveToStorage('sendedUsageAnalyticsDate', new Date().toDateString());
|
|
121
|
+
}
|
|
122
|
+
}
|
|
109
123
|
ready(platform = 'all') {
|
|
110
124
|
return this.sendAsync({
|
|
111
125
|
type: ClientEventType.READY,
|
|
@@ -130,6 +144,9 @@ export class Client {
|
|
|
130
144
|
getUserEmail() {
|
|
131
145
|
return this.userEmail;
|
|
132
146
|
}
|
|
147
|
+
getPbxDomain() {
|
|
148
|
+
return this.pbxDomain;
|
|
149
|
+
}
|
|
133
150
|
getUserExtension() {
|
|
134
151
|
return this.userExtension;
|
|
135
152
|
}
|
|
@@ -200,6 +217,7 @@ export class Client {
|
|
|
200
217
|
return this.sendAsync({ type: ClientEventType.NOT_AUTHORIZED });
|
|
201
218
|
}
|
|
202
219
|
isAuthorized() {
|
|
220
|
+
this.sendDailyIntegrationUsageAnalytics();
|
|
203
221
|
return this.sendAsync({ type: ClientEventType.AUTHORIZED });
|
|
204
222
|
}
|
|
205
223
|
addEventListener(eventName, callback) {
|
|
@@ -37,15 +37,6 @@ export var ClientEventType;
|
|
|
37
37
|
ClientEventType["SEND_ANALYTICS"] = "xBeesSendAnalytics";
|
|
38
38
|
ClientEventType["SEND_TECHNICAL_SUPPORT_INFORMATION"] = "xBeesSendTechInfo";
|
|
39
39
|
})(ClientEventType || (ClientEventType = {}));
|
|
40
|
-
export var DeprecatedUrlParams;
|
|
41
|
-
(function (DeprecatedUrlParams) {
|
|
42
|
-
DeprecatedUrlParams["TOKEN"] = "token";
|
|
43
|
-
DeprecatedUrlParams["ID"] = "iframeId";
|
|
44
|
-
DeprecatedUrlParams["VARIANT"] = "variant";
|
|
45
|
-
DeprecatedUrlParams["USER"] = "u";
|
|
46
|
-
DeprecatedUrlParams["REFERRER"] = "referrer";
|
|
47
|
-
DeprecatedUrlParams["AUTHORIZE"] = "authorize";
|
|
48
|
-
})(DeprecatedUrlParams || (DeprecatedUrlParams = {}));
|
|
49
40
|
export var UrlParams;
|
|
50
41
|
(function (UrlParams) {
|
|
51
42
|
UrlParams["TOKEN"] = "t";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { UrlParams } from '../enums';
|
|
2
2
|
import { getUrlSearchParamsMap } from '../utils/url/getUrlSearchParamsMap';
|
|
3
3
|
export default class ClientParams {
|
|
4
4
|
static instance = null;
|
|
@@ -17,13 +17,13 @@ export default class ClientParams {
|
|
|
17
17
|
userExtension = null;
|
|
18
18
|
constructor() {
|
|
19
19
|
const params = getUrlSearchParamsMap();
|
|
20
|
-
this.iframeId =
|
|
21
|
-
this.variant =
|
|
22
|
-
this.userEmail =
|
|
20
|
+
this.iframeId = params.get(UrlParams.ID);
|
|
21
|
+
this.variant = params.get(UrlParams.VARIANT);
|
|
22
|
+
this.userEmail = params.get(UrlParams.USER);
|
|
23
23
|
this.userExtension = params.get(UrlParams.EXTENSION);
|
|
24
|
-
this.userToken =
|
|
25
|
-
this.referrer =
|
|
26
|
-
this.needAuthorize = params.has(UrlParams.AUTHORIZE)
|
|
24
|
+
this.userToken = params.get(UrlParams.TOKEN);
|
|
25
|
+
this.referrer = params.get(UrlParams.REFERRER);
|
|
26
|
+
this.needAuthorize = params.has(UrlParams.AUTHORIZE);
|
|
27
27
|
}
|
|
28
28
|
toString() {
|
|
29
29
|
return JSON.stringify(this);
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { jwtDecode } from 'jwt-decode';
|
|
2
|
+
export function getPbxDomainFromJwt(jwt) {
|
|
3
|
+
try {
|
|
4
|
+
const tokenDecode = jwtDecode(jwt);
|
|
5
|
+
return tokenDecode['custom:pbx_domain'] || '';
|
|
6
|
+
}
|
|
7
|
+
catch (error) {
|
|
8
|
+
console.error('Failed to decode JWT:', error);
|
|
9
|
+
return '';
|
|
10
|
+
}
|
|
11
|
+
}
|
|
@@ -13,6 +13,7 @@ export declare class Client implements ConnectClient {
|
|
|
13
13
|
private listeners;
|
|
14
14
|
private useSubscription;
|
|
15
15
|
private userToken;
|
|
16
|
+
private pbxDomain;
|
|
16
17
|
private visible;
|
|
17
18
|
private readonly userEmail;
|
|
18
19
|
private readonly referrer;
|
|
@@ -27,6 +28,7 @@ export declare class Client implements ConnectClient {
|
|
|
27
28
|
private sendAsyncErrorSafe;
|
|
28
29
|
private parseMessage;
|
|
29
30
|
private onMessage;
|
|
31
|
+
private sendDailyIntegrationUsageAnalytics;
|
|
30
32
|
ready(platform?: SupportedPlatformVariant | undefined): Promise<ResponseMessage>;
|
|
31
33
|
version(): string;
|
|
32
34
|
isPlatformNative(): boolean;
|
|
@@ -34,6 +36,7 @@ export declare class Client implements ConnectClient {
|
|
|
34
36
|
isOpenedFromXBees(): boolean;
|
|
35
37
|
getUserPbxToken(): string;
|
|
36
38
|
getUserEmail(): string;
|
|
39
|
+
getPbxDomain(): string;
|
|
37
40
|
getUserExtension(): string | null;
|
|
38
41
|
getReferrer(): string;
|
|
39
42
|
isVisible(): boolean;
|
|
@@ -35,14 +35,6 @@ export declare enum ClientEventType {
|
|
|
35
35
|
SEND_ANALYTICS = "xBeesSendAnalytics",
|
|
36
36
|
SEND_TECHNICAL_SUPPORT_INFORMATION = "xBeesSendTechInfo"
|
|
37
37
|
}
|
|
38
|
-
export declare enum DeprecatedUrlParams {
|
|
39
|
-
TOKEN = "token",
|
|
40
|
-
ID = "iframeId",
|
|
41
|
-
VARIANT = "variant",
|
|
42
|
-
USER = "u",
|
|
43
|
-
REFERRER = "referrer",
|
|
44
|
-
AUTHORIZE = "authorize"
|
|
45
|
-
}
|
|
46
38
|
export declare enum UrlParams {
|
|
47
39
|
TOKEN = "t",
|
|
48
40
|
ID = "i",
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getPbxDomainFromJwt(jwt: string): string;
|
|
@@ -19,6 +19,9 @@ export interface ConnectClient {
|
|
|
19
19
|
/**
|
|
20
20
|
* Retrieves current user's email */
|
|
21
21
|
getUserEmail: () => string;
|
|
22
|
+
/**
|
|
23
|
+
* Retrieves current pbx domain */
|
|
24
|
+
getPbxDomain: () => string;
|
|
22
25
|
/**
|
|
23
26
|
* Retrieves current user's extension */
|
|
24
27
|
getUserExtension: () => string | null;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wildix/xbees-connect",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.7-alpha.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": "",
|
|
@@ -32,6 +32,7 @@
|
|
|
32
32
|
"devDependencies": {
|
|
33
33
|
"@wildix/eslint-config-style-guide": "^1.2.2",
|
|
34
34
|
"eslint": "^8.55.0",
|
|
35
|
+
"jwt-decode": "^4.0.0",
|
|
35
36
|
"rimraf": "^5.0.5",
|
|
36
37
|
"typescript": "^5.3.3"
|
|
37
38
|
},
|
|
@@ -43,5 +44,5 @@
|
|
|
43
44
|
"engines": {
|
|
44
45
|
"node": ">=16"
|
|
45
46
|
},
|
|
46
|
-
"gitHead": "
|
|
47
|
+
"gitHead": "b1ea62e4673e933c09309c92a8fbd6dbe249a3ed"
|
|
47
48
|
}
|