@wildix/xbees-connect 1.2.11 → 1.2.13
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-cjs/index.js +26 -0
- package/dist-cjs/package.json +49 -0
- package/dist-cjs/src/Client.js +359 -0
- package/dist-cjs/src/enums/index.js +52 -0
- package/dist-cjs/src/helpers/ClientParams.js +35 -0
- package/dist-cjs/src/helpers/LocalStorageManager.js +74 -0
- package/dist-cjs/src/helpers/MessageListener.js +85 -0
- package/dist-cjs/src/helpers/PostMessageController.js +48 -0
- package/dist-cjs/src/helpers/PostMessageControllerNative.js +47 -0
- package/dist-cjs/src/helpers/PostMessageControllerWeb.js +36 -0
- package/dist-cjs/src/helpers/TechnicalSupport.js +30 -0
- package/dist-cjs/src/utils/getPbxDomainFromJwt.js +18 -0
- package/dist-cjs/src/utils/url/getUrlSearchParamsMap.js +7 -0
- package/dist-cjs/types/Callback.js +2 -0
- package/dist-cjs/types/Client.js +2 -0
- package/dist-cjs/types/Contact.js +2 -0
- package/dist-cjs/types/Event.js +3 -0
- package/dist-cjs/types/Json.js +2 -0
- package/dist-cjs/types/Listener.js +2 -0
- package/dist-cjs/types/Message.js +2 -0
- package/dist-cjs/types/MessageSender.js +2 -0
- package/dist-cjs/types/Payload.js +2 -0
- package/dist-cjs/types/Platform.js +2 -0
- package/dist-cjs/types/Resolver.js +2 -0
- package/dist-cjs/types/Storage.js +2 -0
- package/dist-cjs/types/Toast.js +2 -0
- package/dist-cjs/types/WorkVariant.js +2 -0
- package/dist-cjs/types/conversation.js +2 -0
- package/dist-cjs/types/index.js +2 -0
- package/dist-es/package.json +3 -3
- package/dist-es/src/Client.js +2 -2
- package/dist-types/src/Client.d.ts +1 -1
- package/dist-types/types/Client.d.ts +1 -1
- package/dist-types/types/Event.d.ts +1 -1
- package/dist-types/types/Payload.d.ts +1 -0
- package/package.json +4 -4
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.UrlParams = exports.ClientEventType = exports.EventType = void 0;
|
|
18
|
+
const Client_1 = require("./src/Client");
|
|
19
|
+
var enums_1 = require("./src/enums");
|
|
20
|
+
Object.defineProperty(exports, "EventType", { enumerable: true, get: function () { return enums_1.EventType; } });
|
|
21
|
+
var enums_2 = require("./src/enums");
|
|
22
|
+
Object.defineProperty(exports, "ClientEventType", { enumerable: true, get: function () { return enums_2.ClientEventType; } });
|
|
23
|
+
var enums_3 = require("./src/enums");
|
|
24
|
+
Object.defineProperty(exports, "UrlParams", { enumerable: true, get: function () { return enums_3.UrlParams; } });
|
|
25
|
+
__exportStar(require("./types"), exports);
|
|
26
|
+
exports.default = Client_1.Client;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@wildix/xbees-connect",
|
|
3
|
+
"version": "1.2.13",
|
|
4
|
+
"description": "This library provides easy communication between x-bees and integrated web applications",
|
|
5
|
+
"author": "dimitri.chernykh <dimitri.chernykh@wildix.com>",
|
|
6
|
+
"homepage": "",
|
|
7
|
+
"sideEffects": false,
|
|
8
|
+
"license": "MIT",
|
|
9
|
+
"main": "./dist-cjs/index.js",
|
|
10
|
+
"types": "./dist-types/index.d.ts",
|
|
11
|
+
"module": "./dist-es/index.js",
|
|
12
|
+
"scripts": {
|
|
13
|
+
"build": "yarn clean && yarn build:es && yarn build:cjs && yarn build:types",
|
|
14
|
+
"build:es": "tsc -p tsconfig.es.json",
|
|
15
|
+
"build:cjs": "tsc -p tsconfig.cjs.json",
|
|
16
|
+
"build:types": "tsc -p tsconfig.types.json",
|
|
17
|
+
"build:docs": "typedoc",
|
|
18
|
+
"lint": "eslint . && tsc --noEmit",
|
|
19
|
+
"lint:fix": "eslint . --fix",
|
|
20
|
+
"clean": "rimraf ./dist-* && rimraf *.tsbuildinfo"
|
|
21
|
+
},
|
|
22
|
+
"files": [
|
|
23
|
+
"dist-*/**"
|
|
24
|
+
],
|
|
25
|
+
"repository": {
|
|
26
|
+
"type": "git",
|
|
27
|
+
"url": "git@git.wildix.com:xbs/sdk-ui.git"
|
|
28
|
+
},
|
|
29
|
+
"publishConfig": {
|
|
30
|
+
"access": "public"
|
|
31
|
+
},
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"@wildix/eslint-config-style-guide": "^1.2.2",
|
|
34
|
+
"eslint": "^8.55.0",
|
|
35
|
+
"rimraf": "^5.0.5",
|
|
36
|
+
"typescript": "^5.3.3"
|
|
37
|
+
},
|
|
38
|
+
"parserOptions": {
|
|
39
|
+
"project": [
|
|
40
|
+
"./tsconfig.json"
|
|
41
|
+
]
|
|
42
|
+
},
|
|
43
|
+
"engines": {
|
|
44
|
+
"node": ">=16"
|
|
45
|
+
},
|
|
46
|
+
"dependencies": {
|
|
47
|
+
"jwt-decode": "^4.0.0"
|
|
48
|
+
}
|
|
49
|
+
}
|
|
@@ -0,0 +1,359 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.Client = void 0;
|
|
7
|
+
const package_json_1 = __importDefault(require("../package.json"));
|
|
8
|
+
const enums_1 = require("./enums");
|
|
9
|
+
const LocalStorageManager_1 = __importDefault(require("./helpers/LocalStorageManager"));
|
|
10
|
+
const MessageListener_1 = require("./helpers/MessageListener");
|
|
11
|
+
const PostMessageControllerNative_1 = __importDefault(require("./helpers/PostMessageControllerNative"));
|
|
12
|
+
const PostMessageControllerWeb_1 = __importDefault(require("./helpers/PostMessageControllerWeb"));
|
|
13
|
+
const TechnicalSupport_1 = __importDefault(require("./helpers/TechnicalSupport"));
|
|
14
|
+
const getPbxDomainFromJwt_1 = require("./utils/getPbxDomainFromJwt");
|
|
15
|
+
const getUrlSearchParamsMap_1 = require("./utils/url/getUrlSearchParamsMap");
|
|
16
|
+
/**
|
|
17
|
+
* Client provides functionality of communication between xBees and integrated web applications via iFrame or ReactNative WebView
|
|
18
|
+
* integration creates na instance with new Client()
|
|
19
|
+
* */
|
|
20
|
+
class Client {
|
|
21
|
+
static instance = null;
|
|
22
|
+
static getInstance() {
|
|
23
|
+
if (!this.instance) {
|
|
24
|
+
this.instance = new Client();
|
|
25
|
+
}
|
|
26
|
+
return this.instance;
|
|
27
|
+
}
|
|
28
|
+
static initialize(renderer) {
|
|
29
|
+
if (this.getInstance().showsUi()) {
|
|
30
|
+
try {
|
|
31
|
+
void renderer();
|
|
32
|
+
}
|
|
33
|
+
catch (error) {
|
|
34
|
+
console.error('Error on init rendering widget:', error);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
void this.getInstance().ready();
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
worker;
|
|
42
|
+
listeners = [];
|
|
43
|
+
useSubscription = false;
|
|
44
|
+
userToken = '';
|
|
45
|
+
pbxDomain = '';
|
|
46
|
+
visible = false;
|
|
47
|
+
userEmail;
|
|
48
|
+
referrer;
|
|
49
|
+
needAuthorize;
|
|
50
|
+
isParentReactNativeWebView;
|
|
51
|
+
iframeId;
|
|
52
|
+
variant = null;
|
|
53
|
+
localStorageManager = LocalStorageManager_1.default.getInstance();
|
|
54
|
+
userExtension;
|
|
55
|
+
constructor() {
|
|
56
|
+
const params = (0, getUrlSearchParamsMap_1.getUrlSearchParamsMap)();
|
|
57
|
+
this.iframeId = params.get(enums_1.UrlParams.ID);
|
|
58
|
+
this.variant = params.get(enums_1.UrlParams.VARIANT);
|
|
59
|
+
this.userEmail = params.get(enums_1.UrlParams.USER);
|
|
60
|
+
this.userExtension = params.get(enums_1.UrlParams.EXTENSION);
|
|
61
|
+
this.referrer = params.get(enums_1.UrlParams.REFERRER);
|
|
62
|
+
this.needAuthorize = params.has(enums_1.UrlParams.AUTHORIZE);
|
|
63
|
+
// @ts-expect-error window.ReactNativeWebView will be provided by ReactNative WebView
|
|
64
|
+
this.isParentReactNativeWebView = !!window.ReactNativeWebView;
|
|
65
|
+
this.worker = this.isParentReactNativeWebView ? new PostMessageControllerNative_1.default() : new PostMessageControllerWeb_1.default();
|
|
66
|
+
this.addEventListener(enums_1.EventType.PBX_TOKEN, (token) => {
|
|
67
|
+
this.userToken = token;
|
|
68
|
+
this.pbxDomain = (0, getPbxDomainFromJwt_1.getPbxDomainFromJwt)(token);
|
|
69
|
+
});
|
|
70
|
+
this.addEventListener(enums_1.EventType.VISIBILITY, (isActive) => (this.visible = isActive));
|
|
71
|
+
}
|
|
72
|
+
sendAsync(data) {
|
|
73
|
+
return this.worker.sendAsync({
|
|
74
|
+
...data,
|
|
75
|
+
iframeId: this.iframeId,
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
async sendAsyncErrorSafe(data) {
|
|
79
|
+
try {
|
|
80
|
+
return await this.sendAsync(data);
|
|
81
|
+
}
|
|
82
|
+
catch (error) {
|
|
83
|
+
console.debug('send error - type:', error);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
parseMessage(message) {
|
|
87
|
+
try {
|
|
88
|
+
const data = typeof message.data === 'string' ? MessageListener_1.MessageListener.parseJSON(message.data) : message.data;
|
|
89
|
+
if (!data?.type) {
|
|
90
|
+
return null;
|
|
91
|
+
}
|
|
92
|
+
return data;
|
|
93
|
+
}
|
|
94
|
+
catch (error) {
|
|
95
|
+
console.error('parse message error', error);
|
|
96
|
+
return null;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
onMessage(message) {
|
|
100
|
+
const data = this.parseMessage(message);
|
|
101
|
+
if (!data) {
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
const { type, payload } = data;
|
|
105
|
+
this.listeners.forEach(({ eventName, callback }) => {
|
|
106
|
+
if (eventName === type) {
|
|
107
|
+
if (type === enums_1.EventType.ADD_CALL) {
|
|
108
|
+
const callbackFn = callback;
|
|
109
|
+
callbackFn(payload);
|
|
110
|
+
}
|
|
111
|
+
else {
|
|
112
|
+
// @ts-expect-error TODO: check the type for Callback<?>
|
|
113
|
+
const callbackFn = callback;
|
|
114
|
+
callbackFn(payload);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
sendDailyIntegrationUsageAnalytics() {
|
|
120
|
+
const sendedUsageAnalyticsDate = this.getFromStorage('sendedUsageAnalyticsDate');
|
|
121
|
+
const today = new Date().toDateString();
|
|
122
|
+
if (sendedUsageAnalyticsDate !== today) {
|
|
123
|
+
this.sendAnalytics('xBeesIntegrationUsage');
|
|
124
|
+
this.saveToStorage('sendedUsageAnalyticsDate', today);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
ready(templateId, platform = 'all') {
|
|
128
|
+
return this.sendAsync({
|
|
129
|
+
type: enums_1.ClientEventType.READY,
|
|
130
|
+
payload: { version: this.version(), platform, templateId },
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
version() {
|
|
134
|
+
return package_json_1.default.version;
|
|
135
|
+
}
|
|
136
|
+
isPlatformNative() {
|
|
137
|
+
return this.isParentReactNativeWebView;
|
|
138
|
+
}
|
|
139
|
+
isPlatformWeb() {
|
|
140
|
+
return !this.isParentReactNativeWebView;
|
|
141
|
+
}
|
|
142
|
+
isOpenedFromXBees() {
|
|
143
|
+
return this.isParentReactNativeWebView || (!!parent && parent !== window);
|
|
144
|
+
}
|
|
145
|
+
getUserPbxToken() {
|
|
146
|
+
return this.userToken;
|
|
147
|
+
}
|
|
148
|
+
getUserEmail() {
|
|
149
|
+
return this.userEmail;
|
|
150
|
+
}
|
|
151
|
+
getPbxDomain() {
|
|
152
|
+
return this.pbxDomain;
|
|
153
|
+
}
|
|
154
|
+
getUserExtension() {
|
|
155
|
+
return this.userExtension;
|
|
156
|
+
}
|
|
157
|
+
getReferrer() {
|
|
158
|
+
return this.referrer;
|
|
159
|
+
}
|
|
160
|
+
isVisible() {
|
|
161
|
+
return this.visible;
|
|
162
|
+
}
|
|
163
|
+
getBackToAppUrl() {
|
|
164
|
+
if (Client.getInstance().isPlatformNative()) {
|
|
165
|
+
return `com.wildix.rnc://integrations/${this.iframeId}`;
|
|
166
|
+
}
|
|
167
|
+
return `${this.referrer}/integrations/${this.iframeId}`;
|
|
168
|
+
}
|
|
169
|
+
isDataOnly() {
|
|
170
|
+
return this.variant === 'no-ui' || this.variant === 'daemon';
|
|
171
|
+
}
|
|
172
|
+
isSetupDialog() {
|
|
173
|
+
return this.variant === 'd' || this.variant === 'dialog';
|
|
174
|
+
}
|
|
175
|
+
showsUi() {
|
|
176
|
+
return !this.isDataOnly();
|
|
177
|
+
}
|
|
178
|
+
isActivationOnly() {
|
|
179
|
+
return this.needAuthorize;
|
|
180
|
+
}
|
|
181
|
+
getContext() {
|
|
182
|
+
return this.sendAsync({ type: enums_1.ClientEventType.CONTEXT });
|
|
183
|
+
}
|
|
184
|
+
getCurrentContact() {
|
|
185
|
+
return this.sendAsync({ type: enums_1.ClientEventType.CURRENT_CONTACT });
|
|
186
|
+
}
|
|
187
|
+
getCurrentConversation() {
|
|
188
|
+
return this.sendAsync({ type: enums_1.ClientEventType.CURRENT_CONVERSATION });
|
|
189
|
+
}
|
|
190
|
+
contactUpdated(query, contact) {
|
|
191
|
+
return this.sendAsync({ type: enums_1.ClientEventType.CONTACT_CREATE_OR_UPDATE, payload: { query, contact } });
|
|
192
|
+
}
|
|
193
|
+
contactMatchUpdated(query, contact) {
|
|
194
|
+
return this.sendAsync({ type: enums_1.ClientEventType.CONTACT_MATCH_UPDATE, payload: { query, contact } });
|
|
195
|
+
}
|
|
196
|
+
getThemeMode() {
|
|
197
|
+
return this.sendAsync({ type: enums_1.ClientEventType.THEME_MODE });
|
|
198
|
+
}
|
|
199
|
+
getTheme() {
|
|
200
|
+
return this.sendAsync({ type: enums_1.ClientEventType.THEME });
|
|
201
|
+
}
|
|
202
|
+
startCall(phoneNumber) {
|
|
203
|
+
return this.sendAsync({
|
|
204
|
+
type: enums_1.ClientEventType.START_CALL,
|
|
205
|
+
payload: { phoneNumber },
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
reboot() {
|
|
209
|
+
return this.sendAsync({ type: enums_1.ClientEventType.REBOOT });
|
|
210
|
+
}
|
|
211
|
+
setViewport(payload) {
|
|
212
|
+
return this.sendAsync({ type: enums_1.ClientEventType.VIEW_PORT, payload });
|
|
213
|
+
}
|
|
214
|
+
toClipboard(payload) {
|
|
215
|
+
return this.sendAsync({ type: enums_1.ClientEventType.TO_CLIPBOARD, payload });
|
|
216
|
+
}
|
|
217
|
+
showToast(message, severity = 'INFO') {
|
|
218
|
+
return this.sendAsync({ type: enums_1.ClientEventType.TOAST, payload: { message, severity } });
|
|
219
|
+
}
|
|
220
|
+
isNotAuthorized() {
|
|
221
|
+
return this.sendAsync({ type: enums_1.ClientEventType.NOT_AUTHORIZED });
|
|
222
|
+
}
|
|
223
|
+
isAuthorized() {
|
|
224
|
+
this.sendDailyIntegrationUsageAnalytics();
|
|
225
|
+
return this.sendAsync({ type: enums_1.ClientEventType.AUTHORIZED });
|
|
226
|
+
}
|
|
227
|
+
addEventListener(eventName, callback) {
|
|
228
|
+
if (!this.useSubscription) {
|
|
229
|
+
this.useSubscription = true;
|
|
230
|
+
window.addEventListener('message', this.onMessage.bind(this));
|
|
231
|
+
}
|
|
232
|
+
const foundThisEvent = this.listeners.find(({ eventName: _eventName, callback: _callback }) => eventName === _eventName && Object.is(callback, _callback));
|
|
233
|
+
if (!foundThisEvent) {
|
|
234
|
+
this.listeners.push({ eventName, callback });
|
|
235
|
+
}
|
|
236
|
+
return () => {
|
|
237
|
+
this.removeEventListener(eventName, callback);
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
removeEventListener(eventName, callback) {
|
|
241
|
+
this.listeners = this.listeners.filter(({ eventName: _eventName, callback: _callback }) => !(Object.is(callback, _callback) && (!eventName ? true : eventName === _eventName)));
|
|
242
|
+
if (this.useSubscription && !this.listeners.length) {
|
|
243
|
+
this.useSubscription = false;
|
|
244
|
+
window.removeEventListener('message', this.onMessage.bind(this));
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
off(callback) {
|
|
248
|
+
this.localStorageManager.removeOnStorage(callback);
|
|
249
|
+
this.removeEventListener(null, callback);
|
|
250
|
+
}
|
|
251
|
+
onRedirectQuery(callback) {
|
|
252
|
+
return this.addEventListener(enums_1.EventType.REDIRECT_QUERY, callback);
|
|
253
|
+
}
|
|
254
|
+
onCallEnded(callback) {
|
|
255
|
+
return this.addEventListener(enums_1.EventType.TERMINATE_CALL, callback);
|
|
256
|
+
}
|
|
257
|
+
onCallStarted(callback) {
|
|
258
|
+
return this.addEventListener(enums_1.EventType.ADD_CALL, callback);
|
|
259
|
+
}
|
|
260
|
+
onPbxTokenChange(callback) {
|
|
261
|
+
return this.addEventListener(enums_1.EventType.PBX_TOKEN, callback);
|
|
262
|
+
}
|
|
263
|
+
getXBeesToken() {
|
|
264
|
+
return this.sendAsync({ type: enums_1.ClientEventType.TOKEN });
|
|
265
|
+
}
|
|
266
|
+
onSuggestContacts(callback) {
|
|
267
|
+
// send event to x-bees
|
|
268
|
+
void this.sendAsyncErrorSafe({
|
|
269
|
+
type: enums_1.ClientEventType.CONTACTS_AUTO_SUGGEST_IS_SUPPORTED,
|
|
270
|
+
});
|
|
271
|
+
return this.addEventListener(enums_1.EventType.GET_CONTACTS_AUTO_SUGGEST, (query) => {
|
|
272
|
+
const resolve = (contacts) => this.sendAsync({
|
|
273
|
+
type: enums_1.ClientEventType.CONTACTS_AUTO_SUGGEST,
|
|
274
|
+
payload: {
|
|
275
|
+
contacts,
|
|
276
|
+
query,
|
|
277
|
+
},
|
|
278
|
+
});
|
|
279
|
+
const reject = (reason) => {
|
|
280
|
+
console.debug(reason);
|
|
281
|
+
};
|
|
282
|
+
try {
|
|
283
|
+
callback(query, resolve, reject);
|
|
284
|
+
}
|
|
285
|
+
catch (error) {
|
|
286
|
+
reject(`${error}`);
|
|
287
|
+
}
|
|
288
|
+
});
|
|
289
|
+
}
|
|
290
|
+
onLookupAndMatchContact(callback) {
|
|
291
|
+
// send event to x-bees
|
|
292
|
+
void this.sendAsyncErrorSafe({
|
|
293
|
+
type: enums_1.ClientEventType.CONTACT_LOOK_UP_AND_MATCH_IS_SUPPORTED,
|
|
294
|
+
});
|
|
295
|
+
return this.addEventListener(enums_1.EventType.GET_LOOK_UP_AND_MATCH, (query) => {
|
|
296
|
+
const resolve = (contact) => this.sendAsync({
|
|
297
|
+
type: enums_1.ClientEventType.CONTACT_LOOKUP_AND_MATCH,
|
|
298
|
+
payload: {
|
|
299
|
+
contact,
|
|
300
|
+
query,
|
|
301
|
+
},
|
|
302
|
+
});
|
|
303
|
+
const reject = (reason) => {
|
|
304
|
+
console.debug(reason);
|
|
305
|
+
void this.sendAsync({
|
|
306
|
+
type: enums_1.ClientEventType.CONTACT_LOOKUP_AND_MATCH_NOT_FOUND,
|
|
307
|
+
payload: { query },
|
|
308
|
+
});
|
|
309
|
+
};
|
|
310
|
+
try {
|
|
311
|
+
callback(query, resolve, reject);
|
|
312
|
+
}
|
|
313
|
+
catch (error) {
|
|
314
|
+
reject(`${error}`);
|
|
315
|
+
}
|
|
316
|
+
});
|
|
317
|
+
}
|
|
318
|
+
onThemeChange(callback) {
|
|
319
|
+
return this.addEventListener(enums_1.EventType.USE_THEME, callback);
|
|
320
|
+
}
|
|
321
|
+
getFromStorage(key) {
|
|
322
|
+
return this.localStorageManager.retrieve(key);
|
|
323
|
+
}
|
|
324
|
+
saveToStorage(key, value) {
|
|
325
|
+
this.localStorageManager.save(key, value);
|
|
326
|
+
}
|
|
327
|
+
deleteFromStorage(key) {
|
|
328
|
+
this.localStorageManager.delete(key);
|
|
329
|
+
}
|
|
330
|
+
onStorage(listener) {
|
|
331
|
+
return this.localStorageManager.onStorage(listener);
|
|
332
|
+
}
|
|
333
|
+
onLogout(callback) {
|
|
334
|
+
// send event to x-bees
|
|
335
|
+
void this.sendAsync({
|
|
336
|
+
type: enums_1.ClientEventType.LOGOUT_IS_SUPPORTED,
|
|
337
|
+
});
|
|
338
|
+
return this.addEventListener(enums_1.EventType.LOGOUT, callback);
|
|
339
|
+
}
|
|
340
|
+
sendAnalytics(eventName, params) {
|
|
341
|
+
void this.sendAsync({
|
|
342
|
+
type: enums_1.ClientEventType.SEND_ANALYTICS,
|
|
343
|
+
payload: {
|
|
344
|
+
eventName,
|
|
345
|
+
params,
|
|
346
|
+
},
|
|
347
|
+
});
|
|
348
|
+
}
|
|
349
|
+
setIntegrationStorageKey(integrationKey) {
|
|
350
|
+
this.localStorageManager.setIntegrationKey(integrationKey);
|
|
351
|
+
}
|
|
352
|
+
getTechnicalSupport() {
|
|
353
|
+
return TechnicalSupport_1.default.getInstance();
|
|
354
|
+
}
|
|
355
|
+
onVisibilityChange(callback) {
|
|
356
|
+
return this.addEventListener(enums_1.EventType.VISIBILITY, callback);
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
exports.Client = Client;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.UrlParams = exports.ClientEventType = exports.EventType = void 0;
|
|
4
|
+
var EventType;
|
|
5
|
+
(function (EventType) {
|
|
6
|
+
EventType["GET_CONTACTS_AUTO_SUGGEST"] = "xBeesGetContactsAutoSuggest";
|
|
7
|
+
EventType["GET_LOOK_UP_AND_MATCH"] = "xBeesGetLookUpAndMatch";
|
|
8
|
+
EventType["ADD_CALL"] = "xBeesAddCall";
|
|
9
|
+
EventType["TERMINATE_CALL"] = "xBeesTerminateCall";
|
|
10
|
+
EventType["USE_THEME"] = "xBeesUseTheme";
|
|
11
|
+
EventType["PBX_TOKEN"] = "xBeesPbxToken";
|
|
12
|
+
EventType["REDIRECT_QUERY"] = "xBeesRedirectQuery";
|
|
13
|
+
EventType["LOGOUT"] = "xBeesLogout";
|
|
14
|
+
EventType["VISIBILITY"] = "xBeesVisibility";
|
|
15
|
+
})(EventType || (exports.EventType = EventType = {}));
|
|
16
|
+
var ClientEventType;
|
|
17
|
+
(function (ClientEventType) {
|
|
18
|
+
ClientEventType["READY"] = "xBeesReady";
|
|
19
|
+
ClientEventType["CONTEXT"] = "xBeesContext";
|
|
20
|
+
ClientEventType["CURRENT_CONTACT"] = "xBeesCurrentContact";
|
|
21
|
+
ClientEventType["CURRENT_CONVERSATION"] = "xBeesCurrentConversation";
|
|
22
|
+
ClientEventType["THEME_MODE"] = "xBeesThemeMode";
|
|
23
|
+
ClientEventType["THEME"] = "xBeesTheme";
|
|
24
|
+
ClientEventType["START_CALL"] = "xBeesStartCall";
|
|
25
|
+
ClientEventType["VIEW_PORT"] = "xBeesViewPort";
|
|
26
|
+
ClientEventType["REBOOT"] = "xBeesReboot";
|
|
27
|
+
ClientEventType["TO_CLIPBOARD"] = "xBeesToClipboard";
|
|
28
|
+
ClientEventType["TOAST"] = "xBeesShowToast";
|
|
29
|
+
ClientEventType["NOT_AUTHORIZED"] = "xBeesNotAuthorized";
|
|
30
|
+
ClientEventType["AUTHORIZED"] = "xBeesAuthorized";
|
|
31
|
+
ClientEventType["TOKEN"] = "xBeesToken";
|
|
32
|
+
ClientEventType["CONTACTS_AUTO_SUGGEST"] = "xBeesContactsAutoSuggest";
|
|
33
|
+
ClientEventType["CONTACT_LOOKUP_AND_MATCH"] = "xBeesContactLookupAndMatch";
|
|
34
|
+
ClientEventType["CONTACT_LOOKUP_AND_MATCH_NOT_FOUND"] = "xBeesContactLookupAndMatchNotFound";
|
|
35
|
+
ClientEventType["CONTACT_CREATE_OR_UPDATE"] = "xBeesContactCreateOrUpdate";
|
|
36
|
+
ClientEventType["CONTACT_MATCH_UPDATE"] = "xBeesContactMatchUpdate";
|
|
37
|
+
ClientEventType["CONTACTS_AUTO_SUGGEST_IS_SUPPORTED"] = "xBeesContactsAutoSuggestIsSupported";
|
|
38
|
+
ClientEventType["CONTACT_LOOK_UP_AND_MATCH_IS_SUPPORTED"] = "xBeesContactLookupAndMatchIsSupported";
|
|
39
|
+
ClientEventType["LOGOUT_IS_SUPPORTED"] = "xBeesLogoutIsSupported";
|
|
40
|
+
ClientEventType["SEND_ANALYTICS"] = "xBeesSendAnalytics";
|
|
41
|
+
ClientEventType["SEND_TECHNICAL_SUPPORT_INFORMATION"] = "xBeesSendTechInfo";
|
|
42
|
+
})(ClientEventType || (exports.ClientEventType = ClientEventType = {}));
|
|
43
|
+
var UrlParams;
|
|
44
|
+
(function (UrlParams) {
|
|
45
|
+
UrlParams["TOKEN"] = "t";
|
|
46
|
+
UrlParams["ID"] = "i";
|
|
47
|
+
UrlParams["VARIANT"] = "v";
|
|
48
|
+
UrlParams["USER"] = "u";
|
|
49
|
+
UrlParams["EXTENSION"] = "e";
|
|
50
|
+
UrlParams["REFERRER"] = "r";
|
|
51
|
+
UrlParams["AUTHORIZE"] = "a";
|
|
52
|
+
})(UrlParams || (exports.UrlParams = UrlParams = {}));
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const enums_1 = require("../enums");
|
|
4
|
+
const getUrlSearchParamsMap_1 = require("../utils/url/getUrlSearchParamsMap");
|
|
5
|
+
class ClientParams {
|
|
6
|
+
static instance = null;
|
|
7
|
+
static getInstance() {
|
|
8
|
+
if (!this.instance) {
|
|
9
|
+
this.instance = new ClientParams();
|
|
10
|
+
}
|
|
11
|
+
return this.instance;
|
|
12
|
+
}
|
|
13
|
+
userToken;
|
|
14
|
+
userEmail;
|
|
15
|
+
referrer;
|
|
16
|
+
needAuthorize;
|
|
17
|
+
iframeId;
|
|
18
|
+
variant = null;
|
|
19
|
+
userExtension = null;
|
|
20
|
+
constructor() {
|
|
21
|
+
const params = (0, getUrlSearchParamsMap_1.getUrlSearchParamsMap)();
|
|
22
|
+
this.iframeId = params.get(enums_1.UrlParams.ID);
|
|
23
|
+
this.variant = params.get(enums_1.UrlParams.VARIANT);
|
|
24
|
+
this.userEmail = params.get(enums_1.UrlParams.USER);
|
|
25
|
+
this.userExtension = params.get(enums_1.UrlParams.EXTENSION);
|
|
26
|
+
this.userToken = params.get(enums_1.UrlParams.TOKEN);
|
|
27
|
+
this.referrer = params.get(enums_1.UrlParams.REFERRER);
|
|
28
|
+
this.needAuthorize = params.has(enums_1.UrlParams.AUTHORIZE);
|
|
29
|
+
}
|
|
30
|
+
toString() {
|
|
31
|
+
const { userToken, ...props } = this;
|
|
32
|
+
return JSON.stringify({ ...props, userToken: userToken && `...${userToken.slice(-5)}` });
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
exports.default = ClientParams;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
class LocalStorageManager {
|
|
4
|
+
static instance = null;
|
|
5
|
+
static getInstance() {
|
|
6
|
+
if (!this.instance) {
|
|
7
|
+
this.instance = new LocalStorageManager();
|
|
8
|
+
}
|
|
9
|
+
return this.instance;
|
|
10
|
+
}
|
|
11
|
+
listeners = new Set();
|
|
12
|
+
integrationKey = '';
|
|
13
|
+
setIntegrationKey(integrationKey) {
|
|
14
|
+
this.integrationKey = integrationKey;
|
|
15
|
+
}
|
|
16
|
+
getStorageKey(key) {
|
|
17
|
+
return !this.integrationKey ? key : `${this.integrationKey}_${key}`;
|
|
18
|
+
}
|
|
19
|
+
getKey(key) {
|
|
20
|
+
return !this.integrationKey ? key : key.slice(`${this.integrationKey}_`.length);
|
|
21
|
+
}
|
|
22
|
+
constructor() {
|
|
23
|
+
if (this.shouldUseIntegrationKey()) {
|
|
24
|
+
this.integrationKey = this.calculateIntegrationKey();
|
|
25
|
+
}
|
|
26
|
+
window.addEventListener('storage', (event) => {
|
|
27
|
+
if (!event.key)
|
|
28
|
+
return;
|
|
29
|
+
const key = this.getKey(event.key);
|
|
30
|
+
this.listeners.forEach((listener) => listener({ ...event, key }));
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
calculateIntegrationKey() {
|
|
34
|
+
const pattern = /^\/([^/]+)\/index\.html$/;
|
|
35
|
+
const match = window.location.pathname.match(pattern);
|
|
36
|
+
if (match && match[1]) {
|
|
37
|
+
const [, key] = match;
|
|
38
|
+
return key;
|
|
39
|
+
}
|
|
40
|
+
return '';
|
|
41
|
+
}
|
|
42
|
+
shouldUseIntegrationKey() {
|
|
43
|
+
return window.location.host.endsWith('integrations.x-bees.com');
|
|
44
|
+
}
|
|
45
|
+
save(key, value) {
|
|
46
|
+
// Save data to localStorage
|
|
47
|
+
localStorage.setItem(this.getStorageKey(key), typeof value === 'string' ? value : JSON.stringify(value));
|
|
48
|
+
}
|
|
49
|
+
delete(key) {
|
|
50
|
+
// Save data to localStorage
|
|
51
|
+
localStorage.removeItem(this.getStorageKey(key));
|
|
52
|
+
}
|
|
53
|
+
retrieve(key) {
|
|
54
|
+
// Retrieve data from localStorage
|
|
55
|
+
const data = localStorage.getItem(this.getStorageKey(key));
|
|
56
|
+
try {
|
|
57
|
+
return !data ? data : JSON.parse(data);
|
|
58
|
+
}
|
|
59
|
+
catch (error) {
|
|
60
|
+
return data;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
get(key) {
|
|
64
|
+
return localStorage.getItem(this.getStorageKey(key));
|
|
65
|
+
}
|
|
66
|
+
onStorage(listener) {
|
|
67
|
+
this.listeners.add(listener);
|
|
68
|
+
return () => this.removeOnStorage(listener);
|
|
69
|
+
}
|
|
70
|
+
removeOnStorage(listener) {
|
|
71
|
+
this.listeners.delete(listener);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
exports.default = LocalStorageManager;
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MessageListener = void 0;
|
|
4
|
+
const enums_1 = require("../enums");
|
|
5
|
+
class MessageListener {
|
|
6
|
+
static instance = null;
|
|
7
|
+
static getInstance() {
|
|
8
|
+
if (!this.instance) {
|
|
9
|
+
this.instance = new MessageListener();
|
|
10
|
+
}
|
|
11
|
+
return this.instance;
|
|
12
|
+
}
|
|
13
|
+
listeners = [];
|
|
14
|
+
useSubscription = false;
|
|
15
|
+
// eslint-disable-next-line
|
|
16
|
+
constructor() { }
|
|
17
|
+
parseMessage(message) {
|
|
18
|
+
try {
|
|
19
|
+
const data = typeof message.data === 'string' ? MessageListener.parseJSON(message.data) : message.data;
|
|
20
|
+
if (!data?.type) {
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
return data;
|
|
24
|
+
}
|
|
25
|
+
catch (error) {
|
|
26
|
+
console.error('parse message error', error);
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
static parseJSON(messageData) {
|
|
31
|
+
const trimmedData = messageData.trim();
|
|
32
|
+
if (!trimmedData || !trimmedData.startsWith('{') || !trimmedData.endsWith('}')) {
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
return JSON.parse(trimmedData);
|
|
36
|
+
}
|
|
37
|
+
onMessage = (message) => {
|
|
38
|
+
if (window.location.host === message.origin || window === message.source) {
|
|
39
|
+
console.debug(`onMessage skipped ${window.location.host} - ${message.origin} - ${window === message.source} - ${message}`);
|
|
40
|
+
// skip events started from integration itself if any
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
const data = this.parseMessage(message);
|
|
44
|
+
if (!data) {
|
|
45
|
+
console.debug('onMessage skipped', message);
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
const { type, payload } = data;
|
|
49
|
+
console.debug(`onMessage call - ${type} - ${payload}`);
|
|
50
|
+
this.listeners.forEach(({ eventName, callback }) => {
|
|
51
|
+
if (eventName === type) {
|
|
52
|
+
if (type === enums_1.EventType.ADD_CALL) {
|
|
53
|
+
const callbackFn = callback;
|
|
54
|
+
callbackFn(payload);
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
// @ts-expect-error TODO: check the type for Callback<?>
|
|
58
|
+
const callbackFn = callback;
|
|
59
|
+
callbackFn(payload);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
};
|
|
64
|
+
listen(eventName, callback) {
|
|
65
|
+
if (!this.useSubscription) {
|
|
66
|
+
this.useSubscription = true;
|
|
67
|
+
window.addEventListener('message', this.onMessage);
|
|
68
|
+
}
|
|
69
|
+
const foundThisEvent = this.listeners.find(({ eventName: _eventName, callback: _callback }) => eventName === _eventName && Object.is(callback, _callback));
|
|
70
|
+
if (!foundThisEvent) {
|
|
71
|
+
this.listeners.push({ eventName, callback });
|
|
72
|
+
}
|
|
73
|
+
return () => {
|
|
74
|
+
this.off(eventName, callback);
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
off(eventName, callback) {
|
|
78
|
+
this.listeners = this.listeners.filter(({ eventName: _eventName, callback: _callback }) => !(Object.is(callback, _callback) && (!eventName ? true : eventName === _eventName)));
|
|
79
|
+
if (this.useSubscription && !this.listeners.length) {
|
|
80
|
+
this.useSubscription = false;
|
|
81
|
+
window.removeEventListener('message', this.onMessage);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
exports.MessageListener = MessageListener;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const ClientParams_1 = __importDefault(require("./ClientParams"));
|
|
7
|
+
const PostMessageControllerNative_1 = __importDefault(require("./PostMessageControllerNative"));
|
|
8
|
+
const PostMessageControllerWeb_1 = __importDefault(require("./PostMessageControllerWeb"));
|
|
9
|
+
class PostMessageController {
|
|
10
|
+
static instance = null;
|
|
11
|
+
static getInstance() {
|
|
12
|
+
if (!this.instance) {
|
|
13
|
+
this.instance = new PostMessageController();
|
|
14
|
+
}
|
|
15
|
+
return this.instance;
|
|
16
|
+
}
|
|
17
|
+
worker;
|
|
18
|
+
isParentReactNativeWebView;
|
|
19
|
+
constructor() {
|
|
20
|
+
// @ts-expect-error window.ReactNativeWebView will be provided by ReactNative WebView
|
|
21
|
+
this.isParentReactNativeWebView = !!window.ReactNativeWebView;
|
|
22
|
+
this.worker = this.isParentReactNativeWebView ? new PostMessageControllerNative_1.default() : new PostMessageControllerWeb_1.default();
|
|
23
|
+
}
|
|
24
|
+
sendAsync(data) {
|
|
25
|
+
return this.worker.sendAsync({
|
|
26
|
+
...data,
|
|
27
|
+
iframeId: ClientParams_1.default.getInstance().iframeId,
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
async sendAsyncErrorSafe(data) {
|
|
31
|
+
try {
|
|
32
|
+
return await this.sendAsync(data);
|
|
33
|
+
}
|
|
34
|
+
catch (error) {
|
|
35
|
+
console.debug('send error - type:', error);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
isPlatformNative() {
|
|
39
|
+
return this.isParentReactNativeWebView;
|
|
40
|
+
}
|
|
41
|
+
isPlatformWeb() {
|
|
42
|
+
return !this.isParentReactNativeWebView;
|
|
43
|
+
}
|
|
44
|
+
isOpenedFromXBees() {
|
|
45
|
+
return this.isParentReactNativeWebView || (!!parent && parent !== window);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
exports.default = PostMessageController;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
class PostMessageControllerNative {
|
|
4
|
+
target;
|
|
5
|
+
timeout = 10000;
|
|
6
|
+
constructor() {
|
|
7
|
+
// @ts-expect-error window.ReactNativeWebView will be provided by ReactNative WebView
|
|
8
|
+
this.target = window.ReactNativeWebView;
|
|
9
|
+
}
|
|
10
|
+
sendAsync(data) {
|
|
11
|
+
if (!this.target) {
|
|
12
|
+
return Promise.reject('your application should be wrapped within iframe to xbees-connect perform the connection');
|
|
13
|
+
}
|
|
14
|
+
return this.send(this.target, data);
|
|
15
|
+
}
|
|
16
|
+
send(target, message) {
|
|
17
|
+
return new Promise((resolve, reject) => {
|
|
18
|
+
const channel = new MessageChannel();
|
|
19
|
+
const listener = (event) => {
|
|
20
|
+
try {
|
|
21
|
+
const parsedData = JSON.parse(event.data);
|
|
22
|
+
if (parsedData?.type === message.type) {
|
|
23
|
+
clearTimeout(timeout);
|
|
24
|
+
window.removeEventListener('message', listener);
|
|
25
|
+
if (!parsedData.errorMessage) {
|
|
26
|
+
resolve(parsedData);
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
reject(parsedData);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
catch (error) {
|
|
34
|
+
console.error('on receive response Error', error);
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
window.addEventListener('message', listener);
|
|
38
|
+
const timeout = setTimeout(() => {
|
|
39
|
+
channel.port1.close();
|
|
40
|
+
window.removeEventListener('message', listener);
|
|
41
|
+
reject({ errorMessage: 'timeout', type: message.type });
|
|
42
|
+
}, this.timeout);
|
|
43
|
+
target.postMessage(JSON.stringify(message));
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
exports.default = PostMessageControllerNative;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
class PostMessageControllerWeb {
|
|
4
|
+
target;
|
|
5
|
+
timeout = 10000;
|
|
6
|
+
constructor() {
|
|
7
|
+
this.target = parent;
|
|
8
|
+
}
|
|
9
|
+
sendAsync(data) {
|
|
10
|
+
if (!this.target || this.target === window) {
|
|
11
|
+
return Promise.reject('your application should be wrapped within iframe to xbees-connect perform the connection');
|
|
12
|
+
}
|
|
13
|
+
return this.send(this.target, data);
|
|
14
|
+
}
|
|
15
|
+
send(target, payload) {
|
|
16
|
+
return new Promise((resolve, reject) => {
|
|
17
|
+
const channel = new MessageChannel();
|
|
18
|
+
const timeout = setTimeout(() => {
|
|
19
|
+
channel.port1.close();
|
|
20
|
+
reject({ errorMessage: 'timeout', type: payload.type });
|
|
21
|
+
}, this.timeout);
|
|
22
|
+
channel.port1.onmessage = ({ data }) => {
|
|
23
|
+
clearTimeout(timeout);
|
|
24
|
+
channel.port1.close();
|
|
25
|
+
if (!data.errorMessage) {
|
|
26
|
+
resolve(data);
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
reject(data);
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
target.postMessage(payload, '*', [channel.port2]);
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
exports.default = PostMessageControllerWeb;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const enums_1 = require("../enums");
|
|
7
|
+
const ClientParams_1 = __importDefault(require("./ClientParams"));
|
|
8
|
+
const PostMessageController_1 = __importDefault(require("./PostMessageController"));
|
|
9
|
+
class TechnicalSupport {
|
|
10
|
+
static instance = null;
|
|
11
|
+
static getInstance() {
|
|
12
|
+
if (!this.instance) {
|
|
13
|
+
this.instance = new TechnicalSupport();
|
|
14
|
+
}
|
|
15
|
+
return this.instance;
|
|
16
|
+
}
|
|
17
|
+
// eslint-disable-next-line
|
|
18
|
+
constructor() { }
|
|
19
|
+
sendTechnicalInformation(message, data) {
|
|
20
|
+
return PostMessageController_1.default.getInstance().sendAsyncErrorSafe({
|
|
21
|
+
type: enums_1.ClientEventType.SEND_TECHNICAL_SUPPORT_INFORMATION,
|
|
22
|
+
payload: {
|
|
23
|
+
'x-iframe-params': ClientParams_1.default.getInstance(),
|
|
24
|
+
message,
|
|
25
|
+
data,
|
|
26
|
+
},
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
exports.default = TechnicalSupport;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getPbxDomainFromJwt = void 0;
|
|
4
|
+
const jwt_decode_1 = require("jwt-decode");
|
|
5
|
+
function getPbxDomainFromJwt(jwt) {
|
|
6
|
+
try {
|
|
7
|
+
if (!jwt) {
|
|
8
|
+
return '';
|
|
9
|
+
}
|
|
10
|
+
const tokenDecode = (0, jwt_decode_1.jwtDecode)(jwt);
|
|
11
|
+
return tokenDecode['custom:pbx_domain'] || '';
|
|
12
|
+
}
|
|
13
|
+
catch (error) {
|
|
14
|
+
console.error('Failed to decode JWT:', error);
|
|
15
|
+
return '';
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
exports.getPbxDomainFromJwt = getPbxDomainFromJwt;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getUrlSearchParamsMap = void 0;
|
|
4
|
+
function getUrlSearchParamsMap() {
|
|
5
|
+
return new URLSearchParams(window.location.search);
|
|
6
|
+
}
|
|
7
|
+
exports.getUrlSearchParamsMap = getUrlSearchParamsMap;
|
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.13",
|
|
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": "",
|
|
@@ -9,10 +9,10 @@
|
|
|
9
9
|
"main": "./dist-cjs/index.js",
|
|
10
10
|
"types": "./dist-types/index.d.ts",
|
|
11
11
|
"module": "./dist-es/index.js",
|
|
12
|
-
"type": "module",
|
|
13
12
|
"scripts": {
|
|
14
|
-
"build": "yarn clean && yarn build:es && yarn build:types",
|
|
13
|
+
"build": "yarn clean && yarn build:es && yarn build:cjs && yarn build:types",
|
|
15
14
|
"build:es": "tsc -p tsconfig.es.json",
|
|
15
|
+
"build:cjs": "tsc -p tsconfig.cjs.json",
|
|
16
16
|
"build:types": "tsc -p tsconfig.types.json",
|
|
17
17
|
"build:docs": "typedoc",
|
|
18
18
|
"lint": "eslint . && tsc --noEmit",
|
package/dist-es/src/Client.js
CHANGED
|
@@ -118,10 +118,10 @@ export class Client {
|
|
|
118
118
|
this.saveToStorage('sendedUsageAnalyticsDate', today);
|
|
119
119
|
}
|
|
120
120
|
}
|
|
121
|
-
ready(platform = 'all') {
|
|
121
|
+
ready(templateId, platform = 'all') {
|
|
122
122
|
return this.sendAsync({
|
|
123
123
|
type: ClientEventType.READY,
|
|
124
|
-
payload: { version: this.version(), platform },
|
|
124
|
+
payload: { version: this.version(), platform, templateId },
|
|
125
125
|
});
|
|
126
126
|
}
|
|
127
127
|
version() {
|
|
@@ -29,7 +29,7 @@ export declare class Client implements ConnectClient {
|
|
|
29
29
|
private parseMessage;
|
|
30
30
|
private onMessage;
|
|
31
31
|
private sendDailyIntegrationUsageAnalytics;
|
|
32
|
-
ready(platform?: SupportedPlatformVariant | undefined): Promise<ResponseMessage>;
|
|
32
|
+
ready(templateId?: string, platform?: SupportedPlatformVariant | undefined): Promise<ResponseMessage>;
|
|
33
33
|
version(): string;
|
|
34
34
|
isPlatformNative(): boolean;
|
|
35
35
|
isPlatformWeb(): boolean;
|
|
@@ -12,7 +12,7 @@ import { ToastSeverity } from './Toast';
|
|
|
12
12
|
export interface ConnectClient {
|
|
13
13
|
/**
|
|
14
14
|
* Sends to x-bees signal that iFrame is ready to be shown. iFrame should send it when the application starts and ready */
|
|
15
|
-
ready: (platform?: SupportedPlatformVariant) => Promise<ResponseMessage>;
|
|
15
|
+
ready: (templateId?: string, platform?: SupportedPlatformVariant) => Promise<ResponseMessage>;
|
|
16
16
|
/**
|
|
17
17
|
* Retrieves current pbx token */
|
|
18
18
|
getUserPbxToken: () => string;
|
|
@@ -2,7 +2,7 @@ import { ClientEventType, EventType } from '../src/enums';
|
|
|
2
2
|
import { ContactQuery } from './Contact';
|
|
3
3
|
import { Message, MessageType } from './Message';
|
|
4
4
|
import { IPayloadAutoSuggestResult, IPayloadCallStart, IPayloadCallStartedInfo, IPayloadContactMatchResult, IPayloadContactMatchResultNotFound, IPayloadContactResult, IPayloadContextResult, IPayloadConversationResult, IPayloadSendAnalytics, IPayloadTechSupport, IPayloadThemeChange, IPayloadToast, IPayloadVersion, IPayloadViewPort } from './Payload';
|
|
5
|
-
export 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 | ClientEventType.CONTACT_CREATE_OR_UPDATE | ClientEventType.CONTACT_MATCH_UPDATE ? IPayloadContactMatchResult : T extends ClientEventType.CONTACT_LOOKUP_AND_MATCH_NOT_FOUND ? IPayloadContactMatchResultNotFound : T extends ClientEventType.CONTEXT ? IPayloadContextResult : T extends ClientEventType.CURRENT_CONTACT ? IPayloadContactResult : T extends ClientEventType.CURRENT_CONVERSATION ? IPayloadConversationResult : 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 ClientEventType.SEND_ANALYTICS ? IPayloadSendAnalytics : T extends ClientEventType.SEND_TECHNICAL_SUPPORT_INFORMATION ? IPayloadTechSupport : T extends EventType.PBX_TOKEN ? string : T extends ClientEventType.TOKEN ? string : T extends ClientEventType.TO_CLIPBOARD ? string : T extends EventType.GET_LOOK_UP_AND_MATCH ? ContactQuery : never;
|
|
5
|
+
export 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 | ClientEventType.CONTACT_CREATE_OR_UPDATE | ClientEventType.CONTACT_MATCH_UPDATE ? IPayloadContactMatchResult : T extends ClientEventType.CONTACT_LOOKUP_AND_MATCH_NOT_FOUND ? IPayloadContactMatchResultNotFound : T extends ClientEventType.CONTEXT ? IPayloadContextResult : T extends ClientEventType.CURRENT_CONTACT ? IPayloadContactResult : T extends ClientEventType.CURRENT_CONVERSATION ? IPayloadConversationResult : 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 ClientEventType.SEND_ANALYTICS ? IPayloadSendAnalytics : T extends ClientEventType.SEND_TECHNICAL_SUPPORT_INFORMATION ? IPayloadTechSupport : T extends EventType.PBX_TOKEN ? string : T extends ClientEventType.TOKEN ? string : T extends ClientEventType.TO_CLIPBOARD ? string : T extends EventType.GET_LOOK_UP_AND_MATCH ? ContactQuery : T extends EventType.VISIBILITY ? boolean : never;
|
|
6
6
|
export type EventPayloadMap = {
|
|
7
7
|
[EventType.GET_CONTACTS_AUTO_SUGGEST]: string;
|
|
8
8
|
[EventType.GET_LOOK_UP_AND_MATCH]: ContactQuery;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wildix/xbees-connect",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.13",
|
|
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": "",
|
|
@@ -9,10 +9,10 @@
|
|
|
9
9
|
"main": "./dist-cjs/index.js",
|
|
10
10
|
"types": "./dist-types/index.d.ts",
|
|
11
11
|
"module": "./dist-es/index.js",
|
|
12
|
-
"type": "module",
|
|
13
12
|
"scripts": {
|
|
14
|
-
"build": "yarn clean && yarn build:es && yarn build:types",
|
|
13
|
+
"build": "yarn clean && yarn build:es && yarn build:cjs && yarn build:types",
|
|
15
14
|
"build:es": "tsc -p tsconfig.es.json",
|
|
15
|
+
"build:cjs": "tsc -p tsconfig.cjs.json",
|
|
16
16
|
"build:types": "tsc -p tsconfig.types.json",
|
|
17
17
|
"build:docs": "typedoc",
|
|
18
18
|
"lint": "eslint . && tsc --noEmit",
|
|
@@ -46,5 +46,5 @@
|
|
|
46
46
|
"dependencies": {
|
|
47
47
|
"jwt-decode": "^4.0.0"
|
|
48
48
|
},
|
|
49
|
-
"gitHead": "
|
|
49
|
+
"gitHead": "0f28736f8508d1ec0520f8f4cad83aa49546c141"
|
|
50
50
|
}
|