@wildix/xbees-connect 1.1.21 → 1.2.0-alpha.2
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 +25 -48
- package/dist-es/src/enums/index.js +2 -3
- package/dist-es/src/helpers/ClientParams.js +26 -0
- package/dist-es/src/helpers/PostMessageController.js +42 -0
- package/dist-es/types/Callback.js +1 -0
- package/dist-es/types/Client.js +1 -0
- package/dist-es/types/Contact.js +1 -0
- package/dist-es/types/Event.js +1 -0
- package/dist-es/types/Listener.js +1 -0
- package/dist-es/types/Message.js +1 -0
- package/dist-es/types/MessageSender.js +1 -0
- package/dist-es/types/Payload.js +1 -0
- package/dist-es/types/Platform.js +1 -0
- package/dist-es/types/Resolver.js +1 -0
- package/dist-es/types/Storage.js +1 -0
- package/dist-es/types/Toast.js +1 -0
- package/dist-es/types/WorkVariant.js +1 -0
- package/dist-es/types/conversation.js +1 -0
- package/dist-es/types/index.js +1 -1
- package/dist-types/src/Client.d.ts +18 -18
- package/dist-types/src/enums/index.d.ts +3 -3
- package/dist-types/src/helpers/ClientParams.d.ts +12 -0
- package/dist-types/src/helpers/LocalStorageManager.d.ts +1 -1
- package/dist-types/src/helpers/PostMessageController.d.ts +13 -0
- package/dist-types/src/helpers/PostMessageControllerNative.d.ts +3 -2
- package/dist-types/src/helpers/PostMessageControllerWeb.d.ts +3 -2
- package/dist-types/types/Callback.d.ts +4 -0
- package/dist-types/types/Client.d.ts +150 -0
- package/dist-types/types/Contact.d.ts +24 -0
- package/dist-types/types/Event.d.ts +22 -0
- package/dist-types/types/Listener.d.ts +7 -0
- package/dist-types/types/Message.d.ts +14 -0
- package/dist-types/types/MessageSender.d.ts +4 -0
- package/dist-types/types/Payload.d.ts +56 -0
- package/dist-types/types/Platform.d.ts +1 -0
- package/dist-types/types/Resolver.d.ts +4 -0
- package/dist-types/types/Storage.d.ts +1 -0
- package/dist-types/types/Toast.d.ts +1 -0
- package/dist-types/types/WorkVariant.d.ts +3 -0
- package/dist-types/types/conversation.d.ts +4 -0
- package/dist-types/types/index.d.ts +3 -263
- 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.
|
|
3
|
+
"version": "1.2.0-alpha.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
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import packageJson from '../package.json';
|
|
2
|
-
import { ClientEventType,
|
|
2
|
+
import { ClientEventType, EventType } from './enums';
|
|
3
|
+
import ClientParams from './helpers/ClientParams';
|
|
3
4
|
import LocalStorageManager from './helpers/LocalStorageManager';
|
|
4
|
-
import
|
|
5
|
-
import PostMessageControllerWeb from './helpers/PostMessageControllerWeb';
|
|
6
|
-
import { getUrlSearchParamsMap } from './utils/url/getUrlSearchParamsMap';
|
|
5
|
+
import PostMessageController from './helpers/PostMessageController';
|
|
7
6
|
/**
|
|
8
7
|
* Client provides functionality of communication between xBees and integrated web applications via iFrame or ReactNative WebView
|
|
9
8
|
* integration creates na instance with new Client()
|
|
@@ -29,43 +28,14 @@ export class Client {
|
|
|
29
28
|
void this.getInstance().ready();
|
|
30
29
|
}
|
|
31
30
|
}
|
|
32
|
-
worker;
|
|
33
31
|
listeners = [];
|
|
34
32
|
useSubscription = false;
|
|
35
|
-
userToken;
|
|
36
|
-
userEmail;
|
|
37
|
-
referrer;
|
|
38
|
-
needAuthorize;
|
|
39
|
-
isParentReactNativeWebView;
|
|
40
|
-
iframeId;
|
|
41
|
-
variant = null;
|
|
42
33
|
localStorageManager = LocalStorageManager.getInstance();
|
|
43
34
|
constructor() {
|
|
44
|
-
|
|
45
|
-
this.iframeId = (params.get(UrlParams.ID) ?? params.get(DeprecatedUrlParams.ID));
|
|
46
|
-
this.variant = (params.get(UrlParams.VARIANT) ?? params.get(DeprecatedUrlParams.VARIANT));
|
|
47
|
-
this.userEmail = (params.get(UrlParams.USER) ?? params.get(DeprecatedUrlParams.USER));
|
|
48
|
-
this.userToken = (params.get(UrlParams.TOKEN) ?? params.get(DeprecatedUrlParams.TOKEN));
|
|
49
|
-
this.referrer = (params.get(UrlParams.REFERRER) ?? params.get(DeprecatedUrlParams.REFERRER));
|
|
50
|
-
this.needAuthorize = params.has(UrlParams.AUTHORIZE) ?? params.has(DeprecatedUrlParams.AUTHORIZE);
|
|
51
|
-
// @ts-expect-error window.ReactNativeWebView will be provided by ReactNative WebView
|
|
52
|
-
this.isParentReactNativeWebView = !!window.ReactNativeWebView;
|
|
53
|
-
this.worker = this.isParentReactNativeWebView ? new PostMessageControllerNative() : new PostMessageControllerWeb();
|
|
54
|
-
this.addEventListener(EventType.PBX_TOKEN, (token) => (this.userToken = token));
|
|
35
|
+
this.addEventListener(EventType.PBX_TOKEN, (token) => (ClientParams.getInstance().userToken = token));
|
|
55
36
|
}
|
|
56
37
|
sendAsync(data) {
|
|
57
|
-
return
|
|
58
|
-
...data,
|
|
59
|
-
iframeId: this.iframeId,
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
async sendAsyncErrorSafe(data) {
|
|
63
|
-
try {
|
|
64
|
-
return await this.sendAsync(data);
|
|
65
|
-
}
|
|
66
|
-
catch (error) {
|
|
67
|
-
console.debug('send error - type:', error);
|
|
68
|
-
}
|
|
38
|
+
return PostMessageController.getInstance().sendAsync(data);
|
|
69
39
|
}
|
|
70
40
|
parseMessage(message) {
|
|
71
41
|
try {
|
|
@@ -81,6 +51,10 @@ export class Client {
|
|
|
81
51
|
}
|
|
82
52
|
}
|
|
83
53
|
onMessage(message) {
|
|
54
|
+
if (window.location.host === message.origin || window === message.source) {
|
|
55
|
+
// skip events started from integration itself if any
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
84
58
|
const data = this.parseMessage(message);
|
|
85
59
|
if (!data) {
|
|
86
60
|
return;
|
|
@@ -110,40 +84,40 @@ export class Client {
|
|
|
110
84
|
return packageJson.version;
|
|
111
85
|
}
|
|
112
86
|
isPlatformNative() {
|
|
113
|
-
return
|
|
87
|
+
return PostMessageController.getInstance().isPlatformNative();
|
|
114
88
|
}
|
|
115
89
|
isPlatformWeb() {
|
|
116
|
-
return
|
|
90
|
+
return PostMessageController.getInstance().isPlatformWeb();
|
|
117
91
|
}
|
|
118
92
|
isOpenedFromXBees() {
|
|
119
|
-
return
|
|
93
|
+
return PostMessageController.getInstance().isOpenedFromXBees();
|
|
120
94
|
}
|
|
121
95
|
getUserPbxToken() {
|
|
122
|
-
return
|
|
96
|
+
return ClientParams.getInstance().userToken;
|
|
123
97
|
}
|
|
124
98
|
getUserEmail() {
|
|
125
|
-
return
|
|
99
|
+
return ClientParams.getInstance().userEmail;
|
|
126
100
|
}
|
|
127
101
|
getReferrer() {
|
|
128
|
-
return
|
|
102
|
+
return ClientParams.getInstance().referrer;
|
|
129
103
|
}
|
|
130
104
|
getBackToAppUrl() {
|
|
131
105
|
if (Client.getInstance().isPlatformNative()) {
|
|
132
|
-
return `com.wildix.rnc://integrations/${
|
|
106
|
+
return `com.wildix.rnc://integrations/${ClientParams.getInstance().iframeId}`;
|
|
133
107
|
}
|
|
134
|
-
return `${
|
|
108
|
+
return `${ClientParams.getInstance().referrer}/integrations/${ClientParams.getInstance().iframeId}`;
|
|
135
109
|
}
|
|
136
110
|
isDataOnly() {
|
|
137
|
-
return
|
|
111
|
+
return ClientParams.getInstance().variant === 'no-ui' || ClientParams.getInstance().variant === 'daemon';
|
|
138
112
|
}
|
|
139
113
|
isSetupDialog() {
|
|
140
|
-
return
|
|
114
|
+
return ClientParams.getInstance().variant === 'd' || ClientParams.getInstance().variant === 'dialog';
|
|
141
115
|
}
|
|
142
116
|
showsUi() {
|
|
143
117
|
return !this.isDataOnly();
|
|
144
118
|
}
|
|
145
119
|
isActivationOnly() {
|
|
146
|
-
return
|
|
120
|
+
return ClientParams.getInstance().needAuthorize;
|
|
147
121
|
}
|
|
148
122
|
getContext() {
|
|
149
123
|
return this.sendAsync({ type: ClientEventType.CONTEXT });
|
|
@@ -157,6 +131,9 @@ export class Client {
|
|
|
157
131
|
contactUpdated(query, contact) {
|
|
158
132
|
return this.sendAsync({ type: ClientEventType.CONTACT_CREATE_OR_UPDATE, payload: { query, contact } });
|
|
159
133
|
}
|
|
134
|
+
contactMatchUpdated(query, contact) {
|
|
135
|
+
return this.sendAsync({ type: ClientEventType.CONTACT_MATCH_UPDATE, payload: { query, contact } });
|
|
136
|
+
}
|
|
160
137
|
getThemeMode() {
|
|
161
138
|
return this.sendAsync({ type: ClientEventType.THEME_MODE });
|
|
162
139
|
}
|
|
@@ -228,7 +205,7 @@ export class Client {
|
|
|
228
205
|
}
|
|
229
206
|
onSuggestContacts(callback) {
|
|
230
207
|
// send event to x-bees
|
|
231
|
-
void
|
|
208
|
+
void PostMessageController.getInstance().sendAsyncErrorSafe({
|
|
232
209
|
type: ClientEventType.CONTACTS_AUTO_SUGGEST_IS_SUPPORTED,
|
|
233
210
|
});
|
|
234
211
|
return this.addEventListener(EventType.GET_CONTACTS_AUTO_SUGGEST, (query) => {
|
|
@@ -252,7 +229,7 @@ export class Client {
|
|
|
252
229
|
}
|
|
253
230
|
onLookupAndMatchContact(callback) {
|
|
254
231
|
// send event to x-bees
|
|
255
|
-
void
|
|
232
|
+
void PostMessageController.getInstance().sendAsyncErrorSafe({
|
|
256
233
|
type: ClientEventType.CONTACT_LOOK_UP_AND_MATCH_IS_SUPPORTED,
|
|
257
234
|
});
|
|
258
235
|
return this.addEventListener(EventType.GET_LOOK_UP_AND_MATCH, (query) => {
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
export var EventType1;
|
|
2
|
-
(function (EventType1) {
|
|
3
|
-
})(EventType1 || (EventType1 = {}));
|
|
4
1
|
export var EventType;
|
|
5
2
|
(function (EventType) {
|
|
6
3
|
EventType["GET_CONTACTS_AUTO_SUGGEST"] = "xBeesGetContactsAutoSuggest";
|
|
@@ -32,10 +29,12 @@ export var ClientEventType;
|
|
|
32
29
|
ClientEventType["CONTACT_LOOKUP_AND_MATCH"] = "xBeesContactLookupAndMatch";
|
|
33
30
|
ClientEventType["CONTACT_LOOKUP_AND_MATCH_NOT_FOUND"] = "xBeesContactLookupAndMatchNotFound";
|
|
34
31
|
ClientEventType["CONTACT_CREATE_OR_UPDATE"] = "xBeesContactCreateOrUpdate";
|
|
32
|
+
ClientEventType["CONTACT_MATCH_UPDATE"] = "xBeesContactMatchUpdate";
|
|
35
33
|
ClientEventType["CONTACTS_AUTO_SUGGEST_IS_SUPPORTED"] = "xBeesContactsAutoSuggestIsSupported";
|
|
36
34
|
ClientEventType["CONTACT_LOOK_UP_AND_MATCH_IS_SUPPORTED"] = "xBeesContactLookupAndMatchIsSupported";
|
|
37
35
|
ClientEventType["LOGOUT_IS_SUPPORTED"] = "xBeesLogoutIsSupported";
|
|
38
36
|
ClientEventType["SEND_ANALYTICS"] = "xBeesSendAnalytics";
|
|
37
|
+
ClientEventType["SEND_TECHNICAL_SUPPORT_INFORMATION"] = "xBeesSendTechInfo";
|
|
39
38
|
})(ClientEventType || (ClientEventType = {}));
|
|
40
39
|
export var DeprecatedUrlParams;
|
|
41
40
|
(function (DeprecatedUrlParams) {
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { DeprecatedUrlParams, UrlParams } from '../enums';
|
|
2
|
+
import { getUrlSearchParamsMap } from '../utils/url/getUrlSearchParamsMap';
|
|
3
|
+
export default class ClientParams {
|
|
4
|
+
static instance = null;
|
|
5
|
+
static getInstance() {
|
|
6
|
+
if (!this.instance) {
|
|
7
|
+
this.instance = new ClientParams();
|
|
8
|
+
}
|
|
9
|
+
return this.instance;
|
|
10
|
+
}
|
|
11
|
+
userToken;
|
|
12
|
+
userEmail;
|
|
13
|
+
referrer;
|
|
14
|
+
needAuthorize;
|
|
15
|
+
iframeId;
|
|
16
|
+
variant = null;
|
|
17
|
+
constructor() {
|
|
18
|
+
const params = getUrlSearchParamsMap();
|
|
19
|
+
this.iframeId = (params.get(UrlParams.ID) ?? params.get(DeprecatedUrlParams.ID));
|
|
20
|
+
this.variant = (params.get(UrlParams.VARIANT) ?? params.get(DeprecatedUrlParams.VARIANT));
|
|
21
|
+
this.userEmail = (params.get(UrlParams.USER) ?? params.get(DeprecatedUrlParams.USER));
|
|
22
|
+
this.userToken = (params.get(UrlParams.TOKEN) ?? params.get(DeprecatedUrlParams.TOKEN));
|
|
23
|
+
this.referrer = (params.get(UrlParams.REFERRER) ?? params.get(DeprecatedUrlParams.REFERRER));
|
|
24
|
+
this.needAuthorize = params.has(UrlParams.AUTHORIZE) ?? params.has(DeprecatedUrlParams.AUTHORIZE);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import ClientParams from './ClientParams';
|
|
2
|
+
import PostMessageControllerNative from './PostMessageControllerNative';
|
|
3
|
+
import PostMessageControllerWeb from './PostMessageControllerWeb';
|
|
4
|
+
export default class PostMessageController {
|
|
5
|
+
static instance = null;
|
|
6
|
+
static getInstance() {
|
|
7
|
+
if (!this.instance) {
|
|
8
|
+
this.instance = new PostMessageController();
|
|
9
|
+
}
|
|
10
|
+
return this.instance;
|
|
11
|
+
}
|
|
12
|
+
worker;
|
|
13
|
+
isParentReactNativeWebView;
|
|
14
|
+
constructor() {
|
|
15
|
+
// @ts-expect-error window.ReactNativeWebView will be provided by ReactNative WebView
|
|
16
|
+
this.isParentReactNativeWebView = !!window.ReactNativeWebView;
|
|
17
|
+
this.worker = this.isParentReactNativeWebView ? new PostMessageControllerNative() : new PostMessageControllerWeb();
|
|
18
|
+
}
|
|
19
|
+
sendAsync(data) {
|
|
20
|
+
return this.worker.sendAsync({
|
|
21
|
+
...data,
|
|
22
|
+
iframeId: ClientParams.getInstance().iframeId,
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
async sendAsyncErrorSafe(data) {
|
|
26
|
+
try {
|
|
27
|
+
return await this.sendAsync(data);
|
|
28
|
+
}
|
|
29
|
+
catch (error) {
|
|
30
|
+
console.debug('send error - type:', error);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
isPlatformNative() {
|
|
34
|
+
return this.isParentReactNativeWebView;
|
|
35
|
+
}
|
|
36
|
+
isPlatformWeb() {
|
|
37
|
+
return !this.isParentReactNativeWebView;
|
|
38
|
+
}
|
|
39
|
+
isOpenedFromXBees() {
|
|
40
|
+
return this.isParentReactNativeWebView || (!!parent && parent !== window);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import { EventType } from '../src/enums';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist-es/types/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
export {};
|
|
@@ -1,4 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Contact, ContactQuery, IPayloadViewPort } from '../types';
|
|
2
|
+
import { Callback } from '../types/Callback';
|
|
3
|
+
import { ConnectClient } from '../types/Client';
|
|
4
|
+
import { RemoveEventListener } from '../types/Listener';
|
|
5
|
+
import { ResponseMessage } from '../types/Message';
|
|
6
|
+
import { SupportedPlatformVariant } from '../types/Platform';
|
|
7
|
+
import { LookupAndMatchContactsResolver, Reject, SuggestContactsResolver } from '../types/Resolver';
|
|
8
|
+
import { StorageEventCallback } from '../types/Storage';
|
|
9
|
+
import { ToastSeverity } from '../types/Toast';
|
|
2
10
|
import { ClientEventType, EventType } from './enums';
|
|
3
11
|
/**
|
|
4
12
|
* Client provides functionality of communication between xBees and integrated web applications via iFrame or ReactNative WebView
|
|
@@ -8,20 +16,11 @@ export declare class Client implements ConnectClient {
|
|
|
8
16
|
private static instance;
|
|
9
17
|
static getInstance(): ConnectClient;
|
|
10
18
|
static initialize(renderer: () => Promise<void>): void;
|
|
11
|
-
private worker;
|
|
12
19
|
private listeners;
|
|
13
20
|
private useSubscription;
|
|
14
|
-
private userToken;
|
|
15
|
-
private readonly userEmail;
|
|
16
|
-
private readonly referrer;
|
|
17
|
-
private readonly needAuthorize;
|
|
18
|
-
private readonly isParentReactNativeWebView;
|
|
19
|
-
private readonly iframeId;
|
|
20
|
-
private readonly variant;
|
|
21
21
|
private readonly localStorageManager;
|
|
22
22
|
constructor();
|
|
23
23
|
private sendAsync;
|
|
24
|
-
private sendAsyncErrorSafe;
|
|
25
24
|
private parseMessage;
|
|
26
25
|
private onMessage;
|
|
27
26
|
ready(platform?: SupportedPlatformVariant | undefined): Promise<ResponseMessage>;
|
|
@@ -37,13 +36,14 @@ export declare class Client implements ConnectClient {
|
|
|
37
36
|
isSetupDialog(): boolean;
|
|
38
37
|
showsUi(): boolean;
|
|
39
38
|
isActivationOnly(): boolean;
|
|
40
|
-
getContext(): Promise<
|
|
41
|
-
getCurrentContact(): Promise<
|
|
42
|
-
getCurrentConversation(): Promise<
|
|
43
|
-
contactUpdated(query: ContactQuery, contact: Contact): Promise<
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
39
|
+
getContext(): Promise<ResponseMessage<ClientEventType.CONTEXT>>;
|
|
40
|
+
getCurrentContact(): Promise<ResponseMessage<ClientEventType.CURRENT_CONTACT>>;
|
|
41
|
+
getCurrentConversation(): Promise<ResponseMessage<ClientEventType.CURRENT_CONVERSATION>>;
|
|
42
|
+
contactUpdated(query: ContactQuery, contact: Contact): Promise<ResponseMessage<ClientEventType.CONTACT_CREATE_OR_UPDATE>>;
|
|
43
|
+
contactMatchUpdated(query: ContactQuery, contact: Contact): Promise<ResponseMessage<ClientEventType.CONTACT_MATCH_UPDATE>>;
|
|
44
|
+
getThemeMode(): Promise<ResponseMessage<ClientEventType.THEME_MODE>>;
|
|
45
|
+
getTheme(): Promise<ResponseMessage<ClientEventType.THEME>>;
|
|
46
|
+
startCall(phoneNumber: string): Promise<ResponseMessage>;
|
|
47
47
|
reboot(): Promise<ResponseMessage>;
|
|
48
48
|
setViewport(payload: IPayloadViewPort): Promise<ResponseMessage>;
|
|
49
49
|
toClipboard(payload: string): Promise<ResponseMessage>;
|
|
@@ -57,7 +57,7 @@ export declare class Client implements ConnectClient {
|
|
|
57
57
|
onCallEnded(callback: Callback<EventType.TERMINATE_CALL>): RemoveEventListener;
|
|
58
58
|
onCallStarted(callback: Callback<EventType.ADD_CALL>): RemoveEventListener;
|
|
59
59
|
onPbxTokenChange(callback: Callback<EventType.PBX_TOKEN>): RemoveEventListener;
|
|
60
|
-
getXBeesToken(): Promise<
|
|
60
|
+
getXBeesToken(): Promise<ResponseMessage<ClientEventType.TOKEN>>;
|
|
61
61
|
onSuggestContacts(callback: (query: string, resolve: SuggestContactsResolver, reject: Reject) => void): RemoveEventListener;
|
|
62
62
|
onLookupAndMatchContact(callback: (query: ContactQuery, resolve: LookupAndMatchContactsResolver, reject: Reject) => void): RemoveEventListener;
|
|
63
63
|
onThemeChange(callback: Callback<EventType.USE_THEME>): RemoveEventListener;
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
export declare enum EventType1 {
|
|
2
|
-
}
|
|
3
1
|
export declare enum EventType {
|
|
4
2
|
GET_CONTACTS_AUTO_SUGGEST = "xBeesGetContactsAutoSuggest",
|
|
5
3
|
GET_LOOK_UP_AND_MATCH = "xBeesGetLookUpAndMatch",
|
|
@@ -29,10 +27,12 @@ export declare enum ClientEventType {
|
|
|
29
27
|
CONTACT_LOOKUP_AND_MATCH = "xBeesContactLookupAndMatch",
|
|
30
28
|
CONTACT_LOOKUP_AND_MATCH_NOT_FOUND = "xBeesContactLookupAndMatchNotFound",
|
|
31
29
|
CONTACT_CREATE_OR_UPDATE = "xBeesContactCreateOrUpdate",
|
|
30
|
+
CONTACT_MATCH_UPDATE = "xBeesContactMatchUpdate",
|
|
32
31
|
CONTACTS_AUTO_SUGGEST_IS_SUPPORTED = "xBeesContactsAutoSuggestIsSupported",
|
|
33
32
|
CONTACT_LOOK_UP_AND_MATCH_IS_SUPPORTED = "xBeesContactLookupAndMatchIsSupported",
|
|
34
33
|
LOGOUT_IS_SUPPORTED = "xBeesLogoutIsSupported",
|
|
35
|
-
SEND_ANALYTICS = "xBeesSendAnalytics"
|
|
34
|
+
SEND_ANALYTICS = "xBeesSendAnalytics",
|
|
35
|
+
SEND_TECHNICAL_SUPPORT_INFORMATION = "xBeesSendTechInfo"
|
|
36
36
|
}
|
|
37
37
|
export declare enum DeprecatedUrlParams {
|
|
38
38
|
TOKEN = "token",
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { WorkVariants } from '../../types/WorkVariant';
|
|
2
|
+
export default class ClientParams {
|
|
3
|
+
private static instance;
|
|
4
|
+
static getInstance(): ClientParams;
|
|
5
|
+
userToken: string;
|
|
6
|
+
readonly userEmail: string;
|
|
7
|
+
readonly referrer: string;
|
|
8
|
+
readonly needAuthorize: boolean;
|
|
9
|
+
readonly iframeId: string;
|
|
10
|
+
readonly variant: WorkVariants | null;
|
|
11
|
+
constructor();
|
|
12
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Message, MessageType } from '../../types/Message';
|
|
2
|
+
export default class PostMessageController {
|
|
3
|
+
private static instance;
|
|
4
|
+
static getInstance(): PostMessageController;
|
|
5
|
+
private worker;
|
|
6
|
+
private readonly isParentReactNativeWebView;
|
|
7
|
+
constructor();
|
|
8
|
+
sendAsync<T extends MessageType>(data: Message<T>): Promise<import("../../types/Message").ResponseMessage<T>>;
|
|
9
|
+
sendAsyncErrorSafe<T extends MessageType>(data: Message<T>): Promise<import("../../types/Message").ResponseMessage<T> | undefined>;
|
|
10
|
+
isPlatformNative(): boolean;
|
|
11
|
+
isPlatformWeb(): boolean;
|
|
12
|
+
isOpenedFromXBees(): boolean;
|
|
13
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { MessageIFrameResponse, MessageType,
|
|
2
|
-
|
|
1
|
+
import { MessageIFrameResponse, MessageType, ResponseMessage } from '../../types/Message';
|
|
2
|
+
import { MessageSender } from '../../types/MessageSender';
|
|
3
|
+
export default class PostMessageControllerNative implements MessageSender {
|
|
3
4
|
private readonly target;
|
|
4
5
|
private timeout;
|
|
5
6
|
constructor();
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { MessageIFrameResponse, MessageType,
|
|
2
|
-
|
|
1
|
+
import { MessageIFrameResponse, MessageType, ResponseMessage } from '../../types/Message';
|
|
2
|
+
import { MessageSender } from '../../types/MessageSender';
|
|
3
|
+
export default class PostMessageControllerWeb implements MessageSender {
|
|
3
4
|
private readonly target;
|
|
4
5
|
private timeout;
|
|
5
6
|
constructor();
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { EventType } from '../src/enums';
|
|
2
|
+
import { EventCallbackMap } from './Event';
|
|
3
|
+
export type DefaultCallback = (...args: unknown[]) => void;
|
|
4
|
+
export type Callback<T extends EventType = EventType> = T extends keyof EventCallbackMap ? EventCallbackMap[T] : DefaultCallback;
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import { ClientEventType, EventType } from '../src/enums';
|
|
2
|
+
import { Callback } from './Callback';
|
|
3
|
+
import { Contact, ContactQuery } from './Contact';
|
|
4
|
+
import { RemoveEventListener } from './Listener';
|
|
5
|
+
import { ResponseMessage } from './Message';
|
|
6
|
+
import { IPayloadViewPort } from './Payload';
|
|
7
|
+
import { SupportedPlatformVariant } from './Platform';
|
|
8
|
+
import { LookupAndMatchContactsResolver, Reject, SuggestContactsResolver } from './Resolver';
|
|
9
|
+
import { StorageEventCallback } from './Storage';
|
|
10
|
+
import { ToastSeverity } from './Toast';
|
|
11
|
+
export interface ConnectClient {
|
|
12
|
+
/**
|
|
13
|
+
* Sends to x-bees signal that iFrame is ready to be shown. iFrame should send it when the application starts and ready */
|
|
14
|
+
ready: (platform?: SupportedPlatformVariant) => Promise<ResponseMessage>;
|
|
15
|
+
/**
|
|
16
|
+
* Retrieves current pbx token */
|
|
17
|
+
getUserPbxToken: () => string;
|
|
18
|
+
/**
|
|
19
|
+
* Retrieves current user's email */
|
|
20
|
+
getUserEmail: () => string;
|
|
21
|
+
/**
|
|
22
|
+
* Retrieves url for x-bees app which uses integration */
|
|
23
|
+
getReferrer: () => string;
|
|
24
|
+
/**
|
|
25
|
+
* Retrieves url to get back to x-bees app integration */
|
|
26
|
+
getBackToAppUrl: () => string;
|
|
27
|
+
/**
|
|
28
|
+
* Retrieves the version of xBeesConnect */
|
|
29
|
+
version: () => string;
|
|
30
|
+
/**
|
|
31
|
+
* Determines x-bees is running on mobile native platform */
|
|
32
|
+
isPlatformNative: () => boolean;
|
|
33
|
+
/**
|
|
34
|
+
* Determines x-bees is running on web browser platform */
|
|
35
|
+
isPlatformWeb: () => boolean;
|
|
36
|
+
/**
|
|
37
|
+
* Determines application is opened as x-bees child in Browser iFrame or Native WebView */
|
|
38
|
+
isOpenedFromXBees: () => boolean;
|
|
39
|
+
/**
|
|
40
|
+
* Determines x-bees is using this connect for messages only and this integration will not be shown on UI */
|
|
41
|
+
isDataOnly: () => boolean;
|
|
42
|
+
/**
|
|
43
|
+
* Determines x-bees is using this connect for show dialog of setup flow */
|
|
44
|
+
isSetupDialog: () => boolean;
|
|
45
|
+
/**
|
|
46
|
+
* Determines x-bees is using this connect for representation on UI and this integration will be shown on UI
|
|
47
|
+
* this opposite to {@link isDataOnly} */
|
|
48
|
+
showsUi: () => boolean;
|
|
49
|
+
/**
|
|
50
|
+
* Determines x-bees is using this connect for activation/authorization on UI and this call of integration UI should show
|
|
51
|
+
* dialog which leads to integration be activated
|
|
52
|
+
* */
|
|
53
|
+
isActivationOnly: () => boolean;
|
|
54
|
+
/**
|
|
55
|
+
* Retrieves current x-bees context data */
|
|
56
|
+
getContext: () => Promise<ResponseMessage<ClientEventType.CONTEXT>>;
|
|
57
|
+
/**
|
|
58
|
+
* Retrieves current opened in x-bees contact data */
|
|
59
|
+
getCurrentContact: () => Promise<ResponseMessage<ClientEventType.CURRENT_CONTACT>>;
|
|
60
|
+
/**
|
|
61
|
+
* Retrieves current opened in x-bees conversation data or undefined if the conversation is temporary */
|
|
62
|
+
getCurrentConversation: () => Promise<ResponseMessage<ClientEventType.CURRENT_CONVERSATION>>;
|
|
63
|
+
/**
|
|
64
|
+
* Sends notification to x-bees about contact data updated */
|
|
65
|
+
contactUpdated(query: ContactQuery, contact: Contact): Promise<ResponseMessage<ClientEventType.CONTACT_CREATE_OR_UPDATE>>;
|
|
66
|
+
/**
|
|
67
|
+
* Sends notification to x-bees about contact match was updated */
|
|
68
|
+
contactMatchUpdated(query: ContactQuery, contact: Contact): Promise<ResponseMessage<ClientEventType.CONTACT_MATCH_UPDATE>>;
|
|
69
|
+
/**
|
|
70
|
+
* Retrieves current theme mode (light or dark) */
|
|
71
|
+
getThemeMode: () => Promise<ResponseMessage<ClientEventType.THEME_MODE>>;
|
|
72
|
+
/**
|
|
73
|
+
* Retrieves current theme with mode (light or dark) and theme options like typography settings and palette */
|
|
74
|
+
getTheme: () => Promise<ResponseMessage<ClientEventType.THEME>>;
|
|
75
|
+
/**
|
|
76
|
+
* Sends request to x-bees to start a call with the number */
|
|
77
|
+
startCall: (phoneNumber: string) => Promise<ResponseMessage>;
|
|
78
|
+
/**
|
|
79
|
+
* Sends request to x-bees to restart the iFrame, reload with actual params and token */
|
|
80
|
+
reboot: () => Promise<ResponseMessage>;
|
|
81
|
+
/**
|
|
82
|
+
* Sends request to x-bees about current frame size change */
|
|
83
|
+
setViewport: (payload: IPayloadViewPort) => Promise<ResponseMessage>;
|
|
84
|
+
/**
|
|
85
|
+
* Sends request to x-bees to put string to the users clipboard */
|
|
86
|
+
toClipboard: (payload: string) => Promise<ResponseMessage>;
|
|
87
|
+
/**
|
|
88
|
+
* Sends message to x-bees to be shown as a toast with specified severity level */
|
|
89
|
+
showToast: (message: string, severity?: ToastSeverity) => Promise<ResponseMessage>;
|
|
90
|
+
/**
|
|
91
|
+
* pushes to x-bees message that user is authorized and no more actions required */
|
|
92
|
+
isAuthorized: () => Promise<ResponseMessage>;
|
|
93
|
+
/**
|
|
94
|
+
* pushes to x-bees message that user actions required */
|
|
95
|
+
isNotAuthorized: () => Promise<ResponseMessage>;
|
|
96
|
+
/**
|
|
97
|
+
* Starts listen for one of the events of the x-bees and handle with the provided callback */
|
|
98
|
+
addEventListener: <T extends EventType = EventType>(eventName: T, callback: Callback<T>) => RemoveEventListener;
|
|
99
|
+
/**
|
|
100
|
+
* Stops listen for one of the events of the x-bees with this particular callback */
|
|
101
|
+
removeEventListener: <T extends EventType = EventType>(eventName: T, callback: Callback<T>) => void;
|
|
102
|
+
/**
|
|
103
|
+
* Starts listen for the events of changing theme and handle with the provided callback */
|
|
104
|
+
onThemeChange: (callback: Callback<EventType.USE_THEME>) => RemoveEventListener;
|
|
105
|
+
/**
|
|
106
|
+
* Starts listen for the events of changing pbx token and handle with the provided callback */
|
|
107
|
+
onPbxTokenChange: (callback: Callback<EventType.PBX_TOKEN>) => RemoveEventListener;
|
|
108
|
+
/**
|
|
109
|
+
* Retrieves current x-bees token */
|
|
110
|
+
getXBeesToken: () => Promise<ResponseMessage<ClientEventType.TOKEN>>;
|
|
111
|
+
/**
|
|
112
|
+
* Starts listen for the events of searching contacts and handle autosuggestion with the provided callback */
|
|
113
|
+
onSuggestContacts: (callback: (query: string, resolve: SuggestContactsResolver, reject: Reject) => void) => RemoveEventListener;
|
|
114
|
+
/**
|
|
115
|
+
* Starts listen for the events of searching contact info and handle match with the provided callback */
|
|
116
|
+
onLookupAndMatchContact: (callback: (query: ContactQuery, resolve: LookupAndMatchContactsResolver, reject: Reject) => void) => RemoveEventListener;
|
|
117
|
+
/**
|
|
118
|
+
* Starts listen for the events of starting the call and handle with the provided callback */
|
|
119
|
+
onCallStarted: (callback: Callback<EventType.ADD_CALL>) => RemoveEventListener;
|
|
120
|
+
/**
|
|
121
|
+
* Starts listen for the events of ending the call and handle with the provided callback */
|
|
122
|
+
onCallEnded: (callback: Callback<EventType.TERMINATE_CALL>) => RemoveEventListener;
|
|
123
|
+
/**
|
|
124
|
+
* Starts listen for redirect query message which fires when user opens app with deeplink to integration */
|
|
125
|
+
onRedirectQuery: (callback: Callback<EventType.REDIRECT_QUERY>) => RemoveEventListener;
|
|
126
|
+
/**
|
|
127
|
+
* Removes particular callback from handling events */
|
|
128
|
+
off: (callback: Callback | StorageEventCallback) => void;
|
|
129
|
+
/**
|
|
130
|
+
* saves data to localStorage */
|
|
131
|
+
saveToStorage: <SavingType>(key: string, value: SavingType) => void;
|
|
132
|
+
/**
|
|
133
|
+
* Retrieves data from localStorage */
|
|
134
|
+
getFromStorage: <Type>(key: string) => Type | null;
|
|
135
|
+
/**
|
|
136
|
+
* Removes data from localStorage */
|
|
137
|
+
deleteFromStorage: (key: string) => void;
|
|
138
|
+
/**
|
|
139
|
+
* Set parent integration key to switch to parent integration localStorage data */
|
|
140
|
+
setIntegrationStorageKey: (integrationKey: string) => void;
|
|
141
|
+
/**
|
|
142
|
+
* listens on localStorage */
|
|
143
|
+
onStorage: (listener: StorageEventCallback) => () => void;
|
|
144
|
+
/**
|
|
145
|
+
* starts listen on logout event and send event to the x-bees about logout able */
|
|
146
|
+
onLogout: (callback: Callback<EventType.LOGOUT>) => RemoveEventListener;
|
|
147
|
+
/**
|
|
148
|
+
* send analytics data to x-bees for track into analytics data */
|
|
149
|
+
sendAnalytics: (eventName: string, params?: Record<string, string>) => void;
|
|
150
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
interface ContactShape {
|
|
2
|
+
id: string;
|
|
3
|
+
name: string;
|
|
4
|
+
email?: string;
|
|
5
|
+
phone?: string;
|
|
6
|
+
mobileNumber?: string;
|
|
7
|
+
officeNumber?: string;
|
|
8
|
+
faxNumber?: string;
|
|
9
|
+
homeNumber?: string;
|
|
10
|
+
homeMobileNumber?: string;
|
|
11
|
+
extension?: string;
|
|
12
|
+
organization?: string;
|
|
13
|
+
}
|
|
14
|
+
export type Contact = (ContactShape & {
|
|
15
|
+
email: string;
|
|
16
|
+
}) | (ContactShape & {
|
|
17
|
+
phone: string;
|
|
18
|
+
});
|
|
19
|
+
export type ContactQuery = {
|
|
20
|
+
id?: string;
|
|
21
|
+
email?: string;
|
|
22
|
+
phone?: string;
|
|
23
|
+
};
|
|
24
|
+
export {};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { ClientEventType, EventType } from '../src/enums';
|
|
2
|
+
import { ContactQuery } from './Contact';
|
|
3
|
+
import { Message, MessageType } from './Message';
|
|
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 : never;
|
|
6
|
+
export type EventPayloadMap = {
|
|
7
|
+
[EventType.GET_CONTACTS_AUTO_SUGGEST]: string;
|
|
8
|
+
[EventType.GET_LOOK_UP_AND_MATCH]: ContactQuery;
|
|
9
|
+
[EventType.ADD_CALL]: IPayloadCallStartedInfo;
|
|
10
|
+
[EventType.USE_THEME]: IPayloadThemeChange;
|
|
11
|
+
[EventType.PBX_TOKEN]: string;
|
|
12
|
+
[EventType.REDIRECT_QUERY]: string;
|
|
13
|
+
};
|
|
14
|
+
export type EventCallbackMap = {
|
|
15
|
+
[EventType.GET_CONTACTS_AUTO_SUGGEST]: (query: EventPayloadMap[EventType.GET_CONTACTS_AUTO_SUGGEST]) => void;
|
|
16
|
+
[EventType.GET_LOOK_UP_AND_MATCH]: (query: EventPayloadMap[EventType.GET_LOOK_UP_AND_MATCH]) => void;
|
|
17
|
+
[EventType.ADD_CALL]: (callStartInfo: EventPayloadMap[EventType.ADD_CALL]) => void;
|
|
18
|
+
[EventType.USE_THEME]: (theme: EventPayloadMap[EventType.USE_THEME]) => void;
|
|
19
|
+
[EventType.PBX_TOKEN]: (token: EventPayloadMap[EventType.PBX_TOKEN]) => void;
|
|
20
|
+
[EventType.REDIRECT_QUERY]: (query: EventPayloadMap[EventType.REDIRECT_QUERY]) => void;
|
|
21
|
+
};
|
|
22
|
+
export type RawMessageEvent = MessageEvent<'string' | Message>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { ClientEventType, EventType } from '../src/enums';
|
|
2
|
+
import { EventPayload } from './Event';
|
|
3
|
+
export type MessageType = ClientEventType | EventType;
|
|
4
|
+
export type Message<T extends MessageType = MessageType> = {
|
|
5
|
+
type: T;
|
|
6
|
+
payload?: EventPayload<T>;
|
|
7
|
+
};
|
|
8
|
+
export type MessageIFrameResponse<T extends MessageType = MessageType> = Message<T> & {
|
|
9
|
+
iframeId: string;
|
|
10
|
+
};
|
|
11
|
+
export type ErrorMessage = {
|
|
12
|
+
errorMessage?: string;
|
|
13
|
+
};
|
|
14
|
+
export type ResponseMessage<T extends MessageType = MessageType> = Message<T> & ErrorMessage;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { Contact, ContactQuery } from './Contact';
|
|
2
|
+
import { Conversation } from './conversation';
|
|
3
|
+
import { SupportedPlatformVariant } from './Platform';
|
|
4
|
+
import { ToastSeverity } from './Toast';
|
|
5
|
+
export interface IPayloadViewPort {
|
|
6
|
+
height: number | string;
|
|
7
|
+
width: number | string;
|
|
8
|
+
}
|
|
9
|
+
export interface IPayloadVersion {
|
|
10
|
+
version: string;
|
|
11
|
+
platform?: SupportedPlatformVariant;
|
|
12
|
+
}
|
|
13
|
+
export interface IPayloadToast {
|
|
14
|
+
severity: ToastSeverity;
|
|
15
|
+
message: string;
|
|
16
|
+
}
|
|
17
|
+
export interface IPayloadThemeChange {
|
|
18
|
+
mode: 'light' | 'dark';
|
|
19
|
+
themeOptions?: {
|
|
20
|
+
typography?: unknown;
|
|
21
|
+
palette?: unknown;
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
export interface IPayloadCallStartedInfo {
|
|
25
|
+
destination: string;
|
|
26
|
+
video: boolean;
|
|
27
|
+
}
|
|
28
|
+
export interface IPayloadCallStart {
|
|
29
|
+
phoneNumber: string;
|
|
30
|
+
}
|
|
31
|
+
export interface IPayloadAutoSuggestResult {
|
|
32
|
+
contacts: Contact[];
|
|
33
|
+
query: string;
|
|
34
|
+
}
|
|
35
|
+
export interface IPayloadContactMatchResult {
|
|
36
|
+
contact: Contact;
|
|
37
|
+
query: ContactQuery;
|
|
38
|
+
}
|
|
39
|
+
export interface IPayloadContactMatchResultNotFound {
|
|
40
|
+
query: ContactQuery;
|
|
41
|
+
}
|
|
42
|
+
export interface IPayloadContactResult {
|
|
43
|
+
contact: Contact;
|
|
44
|
+
}
|
|
45
|
+
export interface IPayloadConversationResult {
|
|
46
|
+
conversation?: Conversation;
|
|
47
|
+
}
|
|
48
|
+
export interface IPayloadContextResult extends IPayloadContactResult, IPayloadConversationResult {
|
|
49
|
+
}
|
|
50
|
+
export interface IPayloadSendAnalytics {
|
|
51
|
+
eventName: string;
|
|
52
|
+
params?: Record<string, string>;
|
|
53
|
+
}
|
|
54
|
+
export interface IPayloadTechSupport {
|
|
55
|
+
message: string;
|
|
56
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type SupportedPlatformVariant = 'all' | 'web' | 'mobile';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type StorageEventCallback = (event: StorageEvent) => void;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type ToastSeverity = 'INFO' | 'WARNING' | 'ERROR' | 'SUCCESS' | 'NOTICE';
|
|
@@ -1,263 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
id: string;
|
|
5
|
-
name: string;
|
|
6
|
-
email?: string;
|
|
7
|
-
phone?: string;
|
|
8
|
-
mobileNumber?: string;
|
|
9
|
-
officeNumber?: string;
|
|
10
|
-
faxNumber?: string;
|
|
11
|
-
homeNumber?: string;
|
|
12
|
-
homeMobileNumber?: string;
|
|
13
|
-
extension?: string;
|
|
14
|
-
organization?: string;
|
|
15
|
-
}
|
|
16
|
-
export type Contact = (ContactShape & {
|
|
17
|
-
email: string;
|
|
18
|
-
}) | (ContactShape & {
|
|
19
|
-
phone: string;
|
|
20
|
-
});
|
|
21
|
-
export type Conversation = {
|
|
22
|
-
id: string;
|
|
23
|
-
type: string;
|
|
24
|
-
};
|
|
25
|
-
export type ContactQuery = {
|
|
26
|
-
id?: string;
|
|
27
|
-
email?: string;
|
|
28
|
-
phone?: string;
|
|
29
|
-
};
|
|
30
|
-
export interface IPayloadViewPort {
|
|
31
|
-
height: number | string;
|
|
32
|
-
width: number | string;
|
|
33
|
-
}
|
|
34
|
-
export interface IPayloadVersion {
|
|
35
|
-
version: string;
|
|
36
|
-
platform?: SupportedPlatformVariant;
|
|
37
|
-
}
|
|
38
|
-
export type ToastSeverity = 'INFO' | 'WARNING' | 'ERROR' | 'SUCCESS' | 'NOTICE';
|
|
39
|
-
export interface IPayloadToast {
|
|
40
|
-
severity: ToastSeverity;
|
|
41
|
-
message: string;
|
|
42
|
-
}
|
|
43
|
-
export interface IPayloadThemeChange {
|
|
44
|
-
mode: 'light' | 'dark';
|
|
45
|
-
themeOptions?: {
|
|
46
|
-
typography?: unknown;
|
|
47
|
-
palette?: unknown;
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
export interface IPayloadCallStartedInfo {
|
|
51
|
-
destination: string;
|
|
52
|
-
video: boolean;
|
|
53
|
-
}
|
|
54
|
-
export interface IPayloadCallStart {
|
|
55
|
-
phoneNumber: string;
|
|
56
|
-
}
|
|
57
|
-
export interface IPayloadAutoSuggestResult {
|
|
58
|
-
contacts: Contact[];
|
|
59
|
-
query: string;
|
|
60
|
-
}
|
|
61
|
-
export interface IPayloadContactMatchResult {
|
|
62
|
-
contact: Contact;
|
|
63
|
-
query: ContactQuery;
|
|
64
|
-
}
|
|
65
|
-
export interface IPayloadContactMatchResultNotFound {
|
|
66
|
-
query: ContactQuery;
|
|
67
|
-
}
|
|
68
|
-
export interface IPayloadContactResult {
|
|
69
|
-
contact: Contact;
|
|
70
|
-
}
|
|
71
|
-
export interface IPayloadConversationResult {
|
|
72
|
-
conversation?: Conversation;
|
|
73
|
-
}
|
|
74
|
-
export interface IPayloadContextResult extends IPayloadContactResult, IPayloadConversationResult {
|
|
75
|
-
}
|
|
76
|
-
export interface IPayloadSendAnalytics {
|
|
77
|
-
eventName: string;
|
|
78
|
-
params?: Record<string, string>;
|
|
79
|
-
}
|
|
80
|
-
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_LOOKUP_AND_MATCH_NOT_FOUND ? IPayloadContactMatchResultNotFound : T extends ClientEventType.CONTACT_CREATE_OR_UPDATE ? IPayloadContactMatchResult : 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 EventType.PBX_TOKEN ? string : T extends ClientEventType.TOKEN ? string : T extends ClientEventType.TO_CLIPBOARD ? string : never;
|
|
81
|
-
export type Message<T extends MessageType = MessageType> = {
|
|
82
|
-
type: T;
|
|
83
|
-
payload?: EventPayload<T>;
|
|
84
|
-
};
|
|
85
|
-
export type ErrorMessage = {
|
|
86
|
-
errorMessage?: string;
|
|
87
|
-
};
|
|
88
|
-
export type MessageIFrameResponse<T extends MessageType = MessageType> = Message<T> & {
|
|
89
|
-
iframeId: string;
|
|
90
|
-
};
|
|
91
|
-
export type ResponseMessage<T extends MessageType = MessageType> = Message<T> & ErrorMessage;
|
|
92
|
-
export type RawMessageEvent = MessageEvent<'string' | Message>;
|
|
93
|
-
export type DefaultCallback = (...args: unknown[]) => void;
|
|
94
|
-
export type EventPayloadMap = {
|
|
95
|
-
[EventType.GET_CONTACTS_AUTO_SUGGEST]: string;
|
|
96
|
-
[EventType.GET_LOOK_UP_AND_MATCH]: ContactQuery;
|
|
97
|
-
[EventType.ADD_CALL]: IPayloadCallStartedInfo;
|
|
98
|
-
[EventType.USE_THEME]: IPayloadThemeChange;
|
|
99
|
-
[EventType.PBX_TOKEN]: string;
|
|
100
|
-
[EventType.REDIRECT_QUERY]: string;
|
|
101
|
-
};
|
|
102
|
-
export type EventCallbackMap = {
|
|
103
|
-
[EventType.GET_CONTACTS_AUTO_SUGGEST]: (query: EventPayloadMap[EventType.GET_CONTACTS_AUTO_SUGGEST]) => void;
|
|
104
|
-
[EventType.GET_LOOK_UP_AND_MATCH]: (query: EventPayloadMap[EventType.GET_LOOK_UP_AND_MATCH]) => void;
|
|
105
|
-
[EventType.ADD_CALL]: (callStartInfo: EventPayloadMap[EventType.ADD_CALL]) => void;
|
|
106
|
-
[EventType.USE_THEME]: (theme: EventPayloadMap[EventType.USE_THEME]) => void;
|
|
107
|
-
[EventType.PBX_TOKEN]: (token: EventPayloadMap[EventType.PBX_TOKEN]) => void;
|
|
108
|
-
[EventType.REDIRECT_QUERY]: (query: EventPayloadMap[EventType.REDIRECT_QUERY]) => void;
|
|
109
|
-
};
|
|
110
|
-
export type StorageEventCallback = (event: StorageEvent) => void;
|
|
111
|
-
export type Callback<T extends EventType = EventType> = T extends keyof EventCallbackMap ? EventCallbackMap[T] : DefaultCallback;
|
|
112
|
-
export interface Listener<T extends EventType = EventType> {
|
|
113
|
-
eventName: T;
|
|
114
|
-
callback: Callback<T>;
|
|
115
|
-
}
|
|
116
|
-
type DeprecatedWorkVariants = 'info-frame' | 'daemon' | 'dialog';
|
|
117
|
-
export type WorkVariants = 'ui' | 'no-ui' | 'd' | DeprecatedWorkVariants;
|
|
118
|
-
export interface PostMessageController {
|
|
119
|
-
sendAsync<T extends MessageType>(data: MessageIFrameResponse<T>): Promise<ResponseMessage<T>>;
|
|
120
|
-
}
|
|
121
|
-
export type SuggestContactsResolver = (contacts: Contact[]) => void;
|
|
122
|
-
export type LookupAndMatchContactsResolver = (contact: Contact) => void;
|
|
123
|
-
export type Reject = (reason: string) => void;
|
|
124
|
-
export type RemoveEventListener = () => void;
|
|
125
|
-
export type SupportedPlatformVariant = 'all' | 'web' | 'mobile';
|
|
126
|
-
export interface ConnectClient {
|
|
127
|
-
/**
|
|
128
|
-
* Sends to x-bees signal that iFrame is ready to be shown. iFrame should send it when the application starts and ready */
|
|
129
|
-
ready: (platform?: SupportedPlatformVariant) => Promise<ResponseMessage>;
|
|
130
|
-
/**
|
|
131
|
-
* Retrieves current pbx token */
|
|
132
|
-
getUserPbxToken: () => string;
|
|
133
|
-
/**
|
|
134
|
-
* Retrieves current user's email */
|
|
135
|
-
getUserEmail: () => string;
|
|
136
|
-
/**
|
|
137
|
-
* Retrieves url for x-bees app which uses integration */
|
|
138
|
-
getReferrer: () => string;
|
|
139
|
-
/**
|
|
140
|
-
* Retrieves url to get back to x-bees app integration */
|
|
141
|
-
getBackToAppUrl: () => string;
|
|
142
|
-
/**
|
|
143
|
-
* Retrieves the version of xBeesConnect */
|
|
144
|
-
version: () => string;
|
|
145
|
-
/**
|
|
146
|
-
* Determines x-bees is running on mobile native platform */
|
|
147
|
-
isPlatformNative: () => boolean;
|
|
148
|
-
/**
|
|
149
|
-
* Determines x-bees is running on web browser platform */
|
|
150
|
-
isPlatformWeb: () => boolean;
|
|
151
|
-
/**
|
|
152
|
-
* Determines application is opened as x-bees child in Browser iFrame or Native WebView */
|
|
153
|
-
isOpenedFromXBees: () => boolean;
|
|
154
|
-
/**
|
|
155
|
-
* Determines x-bees is using this connect for messages only and this integration will not be shown on UI */
|
|
156
|
-
isDataOnly: () => boolean;
|
|
157
|
-
/**
|
|
158
|
-
* Determines x-bees is using this connect for show dialog of setup flow */
|
|
159
|
-
isSetupDialog: () => boolean;
|
|
160
|
-
/**
|
|
161
|
-
* Determines x-bees is using this connect for representation on UI and this integration will be shown on UI
|
|
162
|
-
* this opposite to {@link isDataOnly} */
|
|
163
|
-
showsUi: () => boolean;
|
|
164
|
-
/**
|
|
165
|
-
* Determines x-bees is using this connect for activation/authorization on UI and this call of integration UI should show
|
|
166
|
-
* dialog which leads to integration be activated
|
|
167
|
-
* */
|
|
168
|
-
isActivationOnly: () => boolean;
|
|
169
|
-
/**
|
|
170
|
-
* Retrieves current x-bees context data */
|
|
171
|
-
getContext: () => Promise<Message<ClientEventType.CONTEXT>>;
|
|
172
|
-
/**
|
|
173
|
-
* Retrieves current opened in x-bees contact data */
|
|
174
|
-
getCurrentContact: () => Promise<Message<ClientEventType.CURRENT_CONTACT>>;
|
|
175
|
-
/**
|
|
176
|
-
* Retrieves current opened in x-bees conversation data or undefined if the conversation is temporary */
|
|
177
|
-
getCurrentConversation: () => Promise<Message<ClientEventType.CURRENT_CONVERSATION>>;
|
|
178
|
-
/**
|
|
179
|
-
* Sends notification to x-bees about contact data updated */
|
|
180
|
-
contactUpdated(query: ContactQuery, contact: Contact): Promise<Message<ClientEventType.CONTACT_CREATE_OR_UPDATE>>;
|
|
181
|
-
/**
|
|
182
|
-
* Retrieves current theme mode (light or dark) */
|
|
183
|
-
getThemeMode: () => Promise<Message<ClientEventType.THEME_MODE>>;
|
|
184
|
-
/**
|
|
185
|
-
* Retrieves current theme with mode (light or dark) and theme options like typography settings and palette */
|
|
186
|
-
getTheme: () => Promise<Message<ClientEventType.THEME>>;
|
|
187
|
-
/**
|
|
188
|
-
* Sends request to x-bees to start a call with the number */
|
|
189
|
-
startCall: (phoneNumber: string) => Promise<Message<ClientEventType.START_CALL>>;
|
|
190
|
-
/**
|
|
191
|
-
* Sends request to x-bees to restart the iFrame, reload with actual params and token */
|
|
192
|
-
reboot: () => Promise<ResponseMessage>;
|
|
193
|
-
/**
|
|
194
|
-
* Sends request to x-bees about current frame size change */
|
|
195
|
-
setViewport: (payload: IPayloadViewPort) => Promise<ResponseMessage>;
|
|
196
|
-
/**
|
|
197
|
-
* Sends request to x-bees to put string to the users clipboard */
|
|
198
|
-
toClipboard: (payload: string) => Promise<ResponseMessage>;
|
|
199
|
-
/**
|
|
200
|
-
* Sends message to x-bees to be shown as a toast with specified severity level */
|
|
201
|
-
showToast: (message: string, severity?: ToastSeverity) => Promise<ResponseMessage>;
|
|
202
|
-
/**
|
|
203
|
-
* pushes to x-bees message that user is authorized and no more actions required */
|
|
204
|
-
isAuthorized: () => Promise<ResponseMessage>;
|
|
205
|
-
/**
|
|
206
|
-
* pushes to x-bees message that user actions required */
|
|
207
|
-
isNotAuthorized: () => Promise<ResponseMessage>;
|
|
208
|
-
/**
|
|
209
|
-
* Starts listen for one of the events of the x-bees and handle with the provided callback */
|
|
210
|
-
addEventListener: <T extends EventType = EventType>(eventName: T, callback: Callback<T>) => RemoveEventListener;
|
|
211
|
-
/**
|
|
212
|
-
* Stops listen for one of the events of the x-bees with this particular callback */
|
|
213
|
-
removeEventListener: <T extends EventType = EventType>(eventName: T, callback: Callback<T>) => void;
|
|
214
|
-
/**
|
|
215
|
-
* Starts listen for the events of changing theme and handle with the provided callback */
|
|
216
|
-
onThemeChange: (callback: Callback<EventType.USE_THEME>) => RemoveEventListener;
|
|
217
|
-
/**
|
|
218
|
-
* Starts listen for the events of changing pbx token and handle with the provided callback */
|
|
219
|
-
onPbxTokenChange: (callback: Callback<EventType.PBX_TOKEN>) => RemoveEventListener;
|
|
220
|
-
/**
|
|
221
|
-
* Retrieves current x-bees token */
|
|
222
|
-
getXBeesToken: () => Promise<Message<ClientEventType.TOKEN>>;
|
|
223
|
-
/**
|
|
224
|
-
* Starts listen for the events of searching contacts and handle autosuggestion with the provided callback */
|
|
225
|
-
onSuggestContacts: (callback: (query: string, resolve: SuggestContactsResolver, reject: Reject) => void) => RemoveEventListener;
|
|
226
|
-
/**
|
|
227
|
-
* Starts listen for the events of searching contact info and handle match with the provided callback */
|
|
228
|
-
onLookupAndMatchContact: (callback: (query: ContactQuery, resolve: LookupAndMatchContactsResolver, reject: Reject) => void) => RemoveEventListener;
|
|
229
|
-
/**
|
|
230
|
-
* Starts listen for the events of starting the call and handle with the provided callback */
|
|
231
|
-
onCallStarted: (callback: Callback<EventType.ADD_CALL>) => RemoveEventListener;
|
|
232
|
-
/**
|
|
233
|
-
* Starts listen for the events of ending the call and handle with the provided callback */
|
|
234
|
-
onCallEnded: (callback: Callback<EventType.TERMINATE_CALL>) => RemoveEventListener;
|
|
235
|
-
/**
|
|
236
|
-
* Starts listen for redirect query message which fires when user opens app with deeplink to integration */
|
|
237
|
-
onRedirectQuery: (callback: Callback<EventType.REDIRECT_QUERY>) => RemoveEventListener;
|
|
238
|
-
/**
|
|
239
|
-
* Removes particular callback from handling events */
|
|
240
|
-
off: (callback: Callback | StorageEventCallback) => void;
|
|
241
|
-
/**
|
|
242
|
-
* saves data to localStorage */
|
|
243
|
-
saveToStorage: <SavingType>(key: string, value: SavingType) => void;
|
|
244
|
-
/**
|
|
245
|
-
* Retrieves data from localStorage */
|
|
246
|
-
getFromStorage: <Type>(key: string) => Type | null;
|
|
247
|
-
/**
|
|
248
|
-
* Removes data from localStorage */
|
|
249
|
-
deleteFromStorage: (key: string) => void;
|
|
250
|
-
/**
|
|
251
|
-
* Set parent integration key to switch to parent integration localStorage data */
|
|
252
|
-
setIntegrationStorageKey: (integrationKey: string) => void;
|
|
253
|
-
/**
|
|
254
|
-
* listens on localStorage */
|
|
255
|
-
onStorage: (listener: StorageEventCallback) => () => void;
|
|
256
|
-
/**
|
|
257
|
-
* starts listen on logout event and send event to the xbees about logout able */
|
|
258
|
-
onLogout: (callback: Callback<EventType.LOGOUT>) => RemoveEventListener;
|
|
259
|
-
/**
|
|
260
|
-
* send analytics data to xbees for track into analytics data */
|
|
261
|
-
sendAnalytics: (eventName: string, params?: Record<string, string>) => void;
|
|
262
|
-
}
|
|
263
|
-
export {};
|
|
1
|
+
import { Contact, ContactQuery } from './Contact';
|
|
2
|
+
import { IPayloadAutoSuggestResult, IPayloadCallStart, IPayloadCallStartedInfo, IPayloadContactMatchResult, IPayloadContactMatchResultNotFound, IPayloadContactResult, IPayloadContextResult, IPayloadConversationResult, IPayloadSendAnalytics, IPayloadTechSupport, IPayloadThemeChange, IPayloadToast, IPayloadVersion, IPayloadViewPort } from './Payload';
|
|
3
|
+
export type { Contact, ContactQuery, IPayloadAutoSuggestResult, IPayloadCallStart, IPayloadCallStartedInfo, IPayloadContactMatchResult, IPayloadContactMatchResultNotFound, IPayloadContactResult, IPayloadContextResult, IPayloadConversationResult, IPayloadSendAnalytics, IPayloadTechSupport, IPayloadThemeChange, IPayloadToast, IPayloadVersion, IPayloadViewPort, };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wildix/xbees-connect",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0-alpha.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": "",
|
|
@@ -42,5 +42,5 @@
|
|
|
42
42
|
"engines": {
|
|
43
43
|
"node": ">=16"
|
|
44
44
|
},
|
|
45
|
-
"gitHead": "
|
|
45
|
+
"gitHead": "e18b94393f098d28bdcdf727173e765802584692"
|
|
46
46
|
}
|