@wildix/xbees-connect 1.2.0-alpha.1 → 1.2.0-alpha.10
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 +54 -23
- package/dist-es/src/helpers/ClientParams.js +3 -0
- package/dist-es/src/helpers/MessageListener.js +81 -0
- package/dist-es/src/helpers/TechnicalSupport.js +25 -0
- package/dist-es/types/Json.js +1 -0
- package/dist-types/src/Client.d.ts +20 -17
- package/dist-types/src/helpers/ClientParams.d.ts +2 -1
- package/dist-types/src/helpers/LocalStorageManager.d.ts +1 -1
- package/dist-types/src/helpers/MessageListener.d.ts +14 -0
- package/dist-types/src/helpers/PostMessageController.d.ts +3 -3
- package/dist-types/src/helpers/PostMessageControllerNative.d.ts +1 -2
- package/dist-types/src/helpers/PostMessageControllerWeb.d.ts +1 -2
- package/dist-types/src/helpers/TechnicalSupport.d.ts +9 -0
- package/dist-types/types/Client.d.ts +13 -9
- package/dist-types/types/Event.d.ts +1 -1
- package/dist-types/types/Json.d.ts +7 -0
- package/dist-types/types/Payload.d.ts +4 -0
- package/dist-types/types/index.d.ts +14 -3
- 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.2.0-alpha.
|
|
3
|
+
"version": "1.2.0-alpha.10",
|
|
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,8 +1,11 @@
|
|
|
1
1
|
import packageJson from '../package.json';
|
|
2
|
-
import { ClientEventType, EventType } from './enums';
|
|
3
|
-
import ClientParams from './helpers/ClientParams';
|
|
2
|
+
import { ClientEventType, DeprecatedUrlParams, EventType, UrlParams } from './enums';
|
|
4
3
|
import LocalStorageManager from './helpers/LocalStorageManager';
|
|
5
|
-
import
|
|
4
|
+
import { MessageListener } from './helpers/MessageListener';
|
|
5
|
+
import PostMessageControllerNative from './helpers/PostMessageControllerNative';
|
|
6
|
+
import PostMessageControllerWeb from './helpers/PostMessageControllerWeb';
|
|
7
|
+
import TechnicalSupport from './helpers/TechnicalSupport';
|
|
8
|
+
import { getUrlSearchParamsMap } from './utils/url/getUrlSearchParamsMap';
|
|
6
9
|
/**
|
|
7
10
|
* Client provides functionality of communication between xBees and integrated web applications via iFrame or ReactNative WebView
|
|
8
11
|
* integration creates na instance with new Client()
|
|
@@ -28,18 +31,47 @@ export class Client {
|
|
|
28
31
|
void this.getInstance().ready();
|
|
29
32
|
}
|
|
30
33
|
}
|
|
34
|
+
worker;
|
|
31
35
|
listeners = [];
|
|
32
36
|
useSubscription = false;
|
|
37
|
+
userToken;
|
|
38
|
+
userEmail;
|
|
39
|
+
referrer;
|
|
40
|
+
needAuthorize;
|
|
41
|
+
isParentReactNativeWebView;
|
|
42
|
+
iframeId;
|
|
43
|
+
variant = null;
|
|
33
44
|
localStorageManager = LocalStorageManager.getInstance();
|
|
34
45
|
constructor() {
|
|
35
|
-
|
|
46
|
+
const params = getUrlSearchParamsMap();
|
|
47
|
+
this.iframeId = (params.get(UrlParams.ID) ?? params.get(DeprecatedUrlParams.ID));
|
|
48
|
+
this.variant = (params.get(UrlParams.VARIANT) ?? params.get(DeprecatedUrlParams.VARIANT));
|
|
49
|
+
this.userEmail = (params.get(UrlParams.USER) ?? params.get(DeprecatedUrlParams.USER));
|
|
50
|
+
this.userToken = (params.get(UrlParams.TOKEN) ?? params.get(DeprecatedUrlParams.TOKEN));
|
|
51
|
+
this.referrer = (params.get(UrlParams.REFERRER) ?? params.get(DeprecatedUrlParams.REFERRER));
|
|
52
|
+
this.needAuthorize = params.has(UrlParams.AUTHORIZE) ?? params.has(DeprecatedUrlParams.AUTHORIZE);
|
|
53
|
+
// @ts-expect-error window.ReactNativeWebView will be provided by ReactNative WebView
|
|
54
|
+
this.isParentReactNativeWebView = !!window.ReactNativeWebView;
|
|
55
|
+
this.worker = this.isParentReactNativeWebView ? new PostMessageControllerNative() : new PostMessageControllerWeb();
|
|
56
|
+
this.addEventListener(EventType.PBX_TOKEN, (token) => (this.userToken = token));
|
|
36
57
|
}
|
|
37
58
|
sendAsync(data) {
|
|
38
|
-
return
|
|
59
|
+
return this.worker.sendAsync({
|
|
60
|
+
...data,
|
|
61
|
+
iframeId: this.iframeId,
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
async sendAsyncErrorSafe(data) {
|
|
65
|
+
try {
|
|
66
|
+
return await this.sendAsync(data);
|
|
67
|
+
}
|
|
68
|
+
catch (error) {
|
|
69
|
+
console.debug('send error - type:', error);
|
|
70
|
+
}
|
|
39
71
|
}
|
|
40
72
|
parseMessage(message) {
|
|
41
73
|
try {
|
|
42
|
-
const data = typeof message.data === 'string' ?
|
|
74
|
+
const data = typeof message.data === 'string' ? MessageListener.parseJSON(message.data) : message.data;
|
|
43
75
|
if (!data?.type) {
|
|
44
76
|
return null;
|
|
45
77
|
}
|
|
@@ -51,10 +83,6 @@ export class Client {
|
|
|
51
83
|
}
|
|
52
84
|
}
|
|
53
85
|
onMessage(message) {
|
|
54
|
-
if (window.location.host === message.origin || window === message.source) {
|
|
55
|
-
// skip events started from integration itself if any
|
|
56
|
-
return;
|
|
57
|
-
}
|
|
58
86
|
const data = this.parseMessage(message);
|
|
59
87
|
if (!data) {
|
|
60
88
|
return;
|
|
@@ -84,40 +112,40 @@ export class Client {
|
|
|
84
112
|
return packageJson.version;
|
|
85
113
|
}
|
|
86
114
|
isPlatformNative() {
|
|
87
|
-
return
|
|
115
|
+
return this.isParentReactNativeWebView;
|
|
88
116
|
}
|
|
89
117
|
isPlatformWeb() {
|
|
90
|
-
return
|
|
118
|
+
return !this.isParentReactNativeWebView;
|
|
91
119
|
}
|
|
92
120
|
isOpenedFromXBees() {
|
|
93
|
-
return
|
|
121
|
+
return this.isParentReactNativeWebView || (!!parent && parent !== window);
|
|
94
122
|
}
|
|
95
123
|
getUserPbxToken() {
|
|
96
|
-
return
|
|
124
|
+
return this.userToken;
|
|
97
125
|
}
|
|
98
126
|
getUserEmail() {
|
|
99
|
-
return
|
|
127
|
+
return this.userEmail;
|
|
100
128
|
}
|
|
101
129
|
getReferrer() {
|
|
102
|
-
return
|
|
130
|
+
return this.referrer;
|
|
103
131
|
}
|
|
104
132
|
getBackToAppUrl() {
|
|
105
133
|
if (Client.getInstance().isPlatformNative()) {
|
|
106
|
-
return `com.wildix.rnc://integrations/${
|
|
134
|
+
return `com.wildix.rnc://integrations/${this.iframeId}`;
|
|
107
135
|
}
|
|
108
|
-
return `${
|
|
136
|
+
return `${this.referrer}/integrations/${this.iframeId}`;
|
|
109
137
|
}
|
|
110
138
|
isDataOnly() {
|
|
111
|
-
return
|
|
139
|
+
return this.variant === 'no-ui' || this.variant === 'daemon';
|
|
112
140
|
}
|
|
113
141
|
isSetupDialog() {
|
|
114
|
-
return
|
|
142
|
+
return this.variant === 'd' || this.variant === 'dialog';
|
|
115
143
|
}
|
|
116
144
|
showsUi() {
|
|
117
145
|
return !this.isDataOnly();
|
|
118
146
|
}
|
|
119
147
|
isActivationOnly() {
|
|
120
|
-
return
|
|
148
|
+
return this.needAuthorize;
|
|
121
149
|
}
|
|
122
150
|
getContext() {
|
|
123
151
|
return this.sendAsync({ type: ClientEventType.CONTEXT });
|
|
@@ -205,7 +233,7 @@ export class Client {
|
|
|
205
233
|
}
|
|
206
234
|
onSuggestContacts(callback) {
|
|
207
235
|
// send event to x-bees
|
|
208
|
-
void
|
|
236
|
+
void this.sendAsyncErrorSafe({
|
|
209
237
|
type: ClientEventType.CONTACTS_AUTO_SUGGEST_IS_SUPPORTED,
|
|
210
238
|
});
|
|
211
239
|
return this.addEventListener(EventType.GET_CONTACTS_AUTO_SUGGEST, (query) => {
|
|
@@ -229,7 +257,7 @@ export class Client {
|
|
|
229
257
|
}
|
|
230
258
|
onLookupAndMatchContact(callback) {
|
|
231
259
|
// send event to x-bees
|
|
232
|
-
void
|
|
260
|
+
void this.sendAsyncErrorSafe({
|
|
233
261
|
type: ClientEventType.CONTACT_LOOK_UP_AND_MATCH_IS_SUPPORTED,
|
|
234
262
|
});
|
|
235
263
|
return this.addEventListener(EventType.GET_LOOK_UP_AND_MATCH, (query) => {
|
|
@@ -289,4 +317,7 @@ export class Client {
|
|
|
289
317
|
setIntegrationStorageKey(integrationKey) {
|
|
290
318
|
this.localStorageManager.setIntegrationKey(integrationKey);
|
|
291
319
|
}
|
|
320
|
+
getTechnicalSupport() {
|
|
321
|
+
return TechnicalSupport.getInstance();
|
|
322
|
+
}
|
|
292
323
|
}
|
|
@@ -23,4 +23,7 @@ export default class ClientParams {
|
|
|
23
23
|
this.referrer = (params.get(UrlParams.REFERRER) ?? params.get(DeprecatedUrlParams.REFERRER));
|
|
24
24
|
this.needAuthorize = params.has(UrlParams.AUTHORIZE) ?? params.has(DeprecatedUrlParams.AUTHORIZE);
|
|
25
25
|
}
|
|
26
|
+
toString() {
|
|
27
|
+
return JSON.stringify(this);
|
|
28
|
+
}
|
|
26
29
|
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { EventType } from '../enums';
|
|
2
|
+
export class MessageListener {
|
|
3
|
+
static instance = null;
|
|
4
|
+
static getInstance() {
|
|
5
|
+
if (!this.instance) {
|
|
6
|
+
this.instance = new MessageListener();
|
|
7
|
+
}
|
|
8
|
+
return this.instance;
|
|
9
|
+
}
|
|
10
|
+
listeners = [];
|
|
11
|
+
useSubscription = false;
|
|
12
|
+
// eslint-disable-next-line
|
|
13
|
+
constructor() { }
|
|
14
|
+
parseMessage(message) {
|
|
15
|
+
try {
|
|
16
|
+
const data = typeof message.data === 'string' ? MessageListener.parseJSON(message.data) : message.data;
|
|
17
|
+
if (!data?.type) {
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
return data;
|
|
21
|
+
}
|
|
22
|
+
catch (error) {
|
|
23
|
+
console.error('parse message error', error);
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
static parseJSON(messageData) {
|
|
28
|
+
const trimmedData = messageData.trim();
|
|
29
|
+
if (!trimmedData || !trimmedData.startsWith('{') || !trimmedData.endsWith('}')) {
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
return JSON.parse(trimmedData);
|
|
33
|
+
}
|
|
34
|
+
onMessage = (message) => {
|
|
35
|
+
if (window.location.host === message.origin || window === message.source) {
|
|
36
|
+
console.debug(`onMessage skipped ${window.location.host} - ${message.origin} - ${window === message.source} - ${message}`);
|
|
37
|
+
// skip events started from integration itself if any
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
const data = this.parseMessage(message);
|
|
41
|
+
if (!data) {
|
|
42
|
+
console.debug('onMessage skipped', message);
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
const { type, payload } = data;
|
|
46
|
+
console.debug(`onMessage call - ${type} - ${payload}`);
|
|
47
|
+
this.listeners.forEach(({ eventName, callback }) => {
|
|
48
|
+
if (eventName === type) {
|
|
49
|
+
if (type === EventType.ADD_CALL) {
|
|
50
|
+
const callbackFn = callback;
|
|
51
|
+
callbackFn(payload);
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
// @ts-expect-error TODO: check the type for Callback<?>
|
|
55
|
+
const callbackFn = callback;
|
|
56
|
+
callbackFn(payload);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
};
|
|
61
|
+
listen(eventName, callback) {
|
|
62
|
+
if (!this.useSubscription) {
|
|
63
|
+
this.useSubscription = true;
|
|
64
|
+
window.addEventListener('message', this.onMessage);
|
|
65
|
+
}
|
|
66
|
+
const foundThisEvent = this.listeners.find(({ eventName: _eventName, callback: _callback }) => eventName === _eventName && Object.is(callback, _callback));
|
|
67
|
+
if (!foundThisEvent) {
|
|
68
|
+
this.listeners.push({ eventName, callback });
|
|
69
|
+
}
|
|
70
|
+
return () => {
|
|
71
|
+
this.off(eventName, callback);
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
off(eventName, callback) {
|
|
75
|
+
this.listeners = this.listeners.filter(({ eventName: _eventName, callback: _callback }) => !(Object.is(callback, _callback) && (!eventName ? true : eventName === _eventName)));
|
|
76
|
+
if (this.useSubscription && !this.listeners.length) {
|
|
77
|
+
this.useSubscription = false;
|
|
78
|
+
window.removeEventListener('message', this.onMessage);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { ClientEventType } from '../enums';
|
|
2
|
+
import ClientParams from './ClientParams';
|
|
3
|
+
import PostMessageController from './PostMessageController';
|
|
4
|
+
class TechnicalSupport {
|
|
5
|
+
static instance = null;
|
|
6
|
+
static getInstance() {
|
|
7
|
+
if (!this.instance) {
|
|
8
|
+
this.instance = new TechnicalSupport();
|
|
9
|
+
}
|
|
10
|
+
return this.instance;
|
|
11
|
+
}
|
|
12
|
+
// eslint-disable-next-line
|
|
13
|
+
constructor() { }
|
|
14
|
+
sendTechnicalInformation(message, data) {
|
|
15
|
+
return PostMessageController.getInstance().sendAsyncErrorSafe({
|
|
16
|
+
type: ClientEventType.SEND_TECHNICAL_SUPPORT_INFORMATION,
|
|
17
|
+
payload: {
|
|
18
|
+
'x-iframe-params': ClientParams.getInstance(),
|
|
19
|
+
message,
|
|
20
|
+
data,
|
|
21
|
+
},
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
export default TechnicalSupport;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,13 +1,6 @@
|
|
|
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';
|
|
1
|
+
import { Callback, ConnectClient, Contact, ContactQuery, IPayloadViewPort, LookupAndMatchContactsResolver, Message, Reject, RemoveEventListener, ResponseMessage, StorageEventCallback, SuggestContactsResolver, SupportedPlatformVariant, ToastSeverity } from '../types';
|
|
10
2
|
import { ClientEventType, EventType } from './enums';
|
|
3
|
+
import TechnicalSupport from './helpers/TechnicalSupport';
|
|
11
4
|
/**
|
|
12
5
|
* Client provides functionality of communication between xBees and integrated web applications via iFrame or ReactNative WebView
|
|
13
6
|
* integration creates na instance with new Client()
|
|
@@ -16,11 +9,20 @@ export declare class Client implements ConnectClient {
|
|
|
16
9
|
private static instance;
|
|
17
10
|
static getInstance(): ConnectClient;
|
|
18
11
|
static initialize(renderer: () => Promise<void>): void;
|
|
12
|
+
private worker;
|
|
19
13
|
private listeners;
|
|
20
14
|
private useSubscription;
|
|
15
|
+
private userToken;
|
|
16
|
+
private readonly userEmail;
|
|
17
|
+
private readonly referrer;
|
|
18
|
+
private readonly needAuthorize;
|
|
19
|
+
private readonly isParentReactNativeWebView;
|
|
20
|
+
private readonly iframeId;
|
|
21
|
+
private readonly variant;
|
|
21
22
|
private readonly localStorageManager;
|
|
22
23
|
constructor();
|
|
23
24
|
private sendAsync;
|
|
25
|
+
private sendAsyncErrorSafe;
|
|
24
26
|
private parseMessage;
|
|
25
27
|
private onMessage;
|
|
26
28
|
ready(platform?: SupportedPlatformVariant | undefined): Promise<ResponseMessage>;
|
|
@@ -36,14 +38,14 @@ export declare class Client implements ConnectClient {
|
|
|
36
38
|
isSetupDialog(): boolean;
|
|
37
39
|
showsUi(): boolean;
|
|
38
40
|
isActivationOnly(): boolean;
|
|
39
|
-
getContext(): Promise<
|
|
40
|
-
getCurrentContact(): Promise<
|
|
41
|
-
getCurrentConversation(): Promise<
|
|
42
|
-
contactUpdated(query: ContactQuery, contact: Contact): Promise<
|
|
41
|
+
getContext(): Promise<Message<ClientEventType.CONTEXT>>;
|
|
42
|
+
getCurrentContact(): Promise<Message<ClientEventType.CURRENT_CONTACT>>;
|
|
43
|
+
getCurrentConversation(): Promise<Message<ClientEventType.CURRENT_CONVERSATION>>;
|
|
44
|
+
contactUpdated(query: ContactQuery, contact: Contact): Promise<Message<ClientEventType.CONTACT_CREATE_OR_UPDATE>>;
|
|
43
45
|
contactMatchUpdated(query: ContactQuery, contact: Contact): Promise<ResponseMessage<ClientEventType.CONTACT_MATCH_UPDATE>>;
|
|
44
|
-
getThemeMode(): Promise<
|
|
45
|
-
getTheme(): Promise<
|
|
46
|
-
startCall(phoneNumber: string): Promise<
|
|
46
|
+
getThemeMode(): Promise<Message<ClientEventType.THEME_MODE>>;
|
|
47
|
+
getTheme(): Promise<Message<ClientEventType.THEME>>;
|
|
48
|
+
startCall(phoneNumber: string): Promise<Message<ClientEventType.START_CALL>>;
|
|
47
49
|
reboot(): Promise<ResponseMessage>;
|
|
48
50
|
setViewport(payload: IPayloadViewPort): Promise<ResponseMessage>;
|
|
49
51
|
toClipboard(payload: string): Promise<ResponseMessage>;
|
|
@@ -57,7 +59,7 @@ export declare class Client implements ConnectClient {
|
|
|
57
59
|
onCallEnded(callback: Callback<EventType.TERMINATE_CALL>): RemoveEventListener;
|
|
58
60
|
onCallStarted(callback: Callback<EventType.ADD_CALL>): RemoveEventListener;
|
|
59
61
|
onPbxTokenChange(callback: Callback<EventType.PBX_TOKEN>): RemoveEventListener;
|
|
60
|
-
getXBeesToken(): Promise<
|
|
62
|
+
getXBeesToken(): Promise<Message<ClientEventType.TOKEN>>;
|
|
61
63
|
onSuggestContacts(callback: (query: string, resolve: SuggestContactsResolver, reject: Reject) => void): RemoveEventListener;
|
|
62
64
|
onLookupAndMatchContact(callback: (query: ContactQuery, resolve: LookupAndMatchContactsResolver, reject: Reject) => void): RemoveEventListener;
|
|
63
65
|
onThemeChange(callback: Callback<EventType.USE_THEME>): RemoveEventListener;
|
|
@@ -68,4 +70,5 @@ export declare class Client implements ConnectClient {
|
|
|
68
70
|
onLogout(callback: Callback<EventType.LOGOUT>): RemoveEventListener;
|
|
69
71
|
sendAnalytics(eventName: string, params?: Record<string, string>): void;
|
|
70
72
|
setIntegrationStorageKey(integrationKey: string): void;
|
|
73
|
+
getTechnicalSupport(): TechnicalSupport;
|
|
71
74
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { WorkVariants } from '../../types
|
|
1
|
+
import { WorkVariants } from '../../types';
|
|
2
2
|
export default class ClientParams {
|
|
3
3
|
private static instance;
|
|
4
4
|
static getInstance(): ClientParams;
|
|
@@ -9,4 +9,5 @@ export default class ClientParams {
|
|
|
9
9
|
readonly iframeId: string;
|
|
10
10
|
readonly variant: WorkVariants | null;
|
|
11
11
|
constructor();
|
|
12
|
+
toString(): string;
|
|
12
13
|
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Callback, RemoveEventListener } from '../../types';
|
|
2
|
+
import { EventType } from '../enums';
|
|
3
|
+
export declare class MessageListener {
|
|
4
|
+
private static instance;
|
|
5
|
+
static getInstance(): MessageListener;
|
|
6
|
+
private listeners;
|
|
7
|
+
private useSubscription;
|
|
8
|
+
private constructor();
|
|
9
|
+
private parseMessage;
|
|
10
|
+
static parseJSON(messageData: string): any;
|
|
11
|
+
private onMessage;
|
|
12
|
+
listen<T extends EventType = EventType>(eventName: T, callback: Callback<T>): RemoveEventListener;
|
|
13
|
+
off<T extends EventType = EventType>(eventName: T | null, callback: Callback<T>): void;
|
|
14
|
+
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { Message, MessageType } from '../../types
|
|
1
|
+
import { Message, MessageType } from '../../types';
|
|
2
2
|
export default class PostMessageController {
|
|
3
3
|
private static instance;
|
|
4
4
|
static getInstance(): PostMessageController;
|
|
5
5
|
private worker;
|
|
6
6
|
private readonly isParentReactNativeWebView;
|
|
7
7
|
constructor();
|
|
8
|
-
sendAsync<T extends MessageType>(data: Message<T>): Promise<import("../../types
|
|
9
|
-
sendAsyncErrorSafe<T extends MessageType>(data: Message<T>): Promise<import("../../types
|
|
8
|
+
sendAsync<T extends MessageType>(data: Message<T>): Promise<import("../../types").ResponseMessage<T>>;
|
|
9
|
+
sendAsyncErrorSafe<T extends MessageType>(data: Message<T>): Promise<import("../../types").ResponseMessage<T> | undefined>;
|
|
10
10
|
isPlatformNative(): boolean;
|
|
11
11
|
isPlatformWeb(): boolean;
|
|
12
12
|
isOpenedFromXBees(): boolean;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { MessageIFrameResponse, MessageType, ResponseMessage } from '../../types
|
|
2
|
-
import { MessageSender } from '../../types/MessageSender';
|
|
1
|
+
import { MessageIFrameResponse, MessageSender, MessageType, ResponseMessage } from '../../types';
|
|
3
2
|
export default class PostMessageControllerNative implements MessageSender {
|
|
4
3
|
private readonly target;
|
|
5
4
|
private timeout;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { MessageIFrameResponse, MessageType, ResponseMessage } from '../../types
|
|
2
|
-
import { MessageSender } from '../../types/MessageSender';
|
|
1
|
+
import { MessageIFrameResponse, MessageSender, MessageType, ResponseMessage } from '../../types';
|
|
3
2
|
export default class PostMessageControllerWeb implements MessageSender {
|
|
4
3
|
private readonly target;
|
|
5
4
|
private timeout;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { JSONArray, JSONObject } from '../../types';
|
|
2
|
+
import { ClientEventType } from '../enums';
|
|
3
|
+
declare class TechnicalSupport {
|
|
4
|
+
private static instance;
|
|
5
|
+
static getInstance(): TechnicalSupport;
|
|
6
|
+
private constructor();
|
|
7
|
+
sendTechnicalInformation(message: string, data?: JSONObject | JSONArray): Promise<import("../../types").ResponseMessage<ClientEventType.SEND_TECHNICAL_SUPPORT_INFORMATION> | undefined>;
|
|
8
|
+
}
|
|
9
|
+
export default TechnicalSupport;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { EventType } from '../src/enums';
|
|
1
|
+
import { ClientEventType, EventType } from '../src/enums';
|
|
2
|
+
import TechnicalSupport from '../src/helpers/TechnicalSupport';
|
|
2
3
|
import { Callback } from './Callback';
|
|
3
4
|
import { Contact, ContactQuery } from './Contact';
|
|
4
5
|
import { RemoveEventListener } from './Listener';
|
|
@@ -53,25 +54,25 @@ export interface ConnectClient {
|
|
|
53
54
|
isActivationOnly: () => boolean;
|
|
54
55
|
/**
|
|
55
56
|
* Retrieves current x-bees context data */
|
|
56
|
-
getContext: () => Promise<ResponseMessage
|
|
57
|
+
getContext: () => Promise<ResponseMessage<ClientEventType.CONTEXT>>;
|
|
57
58
|
/**
|
|
58
59
|
* Retrieves current opened in x-bees contact data */
|
|
59
|
-
getCurrentContact: () => Promise<ResponseMessage
|
|
60
|
+
getCurrentContact: () => Promise<ResponseMessage<ClientEventType.CURRENT_CONTACT>>;
|
|
60
61
|
/**
|
|
61
62
|
* Retrieves current opened in x-bees conversation data or undefined if the conversation is temporary */
|
|
62
|
-
getCurrentConversation: () => Promise<ResponseMessage
|
|
63
|
+
getCurrentConversation: () => Promise<ResponseMessage<ClientEventType.CURRENT_CONVERSATION>>;
|
|
63
64
|
/**
|
|
64
65
|
* Sends notification to x-bees about contact data updated */
|
|
65
|
-
contactUpdated(query: ContactQuery, contact: Contact): Promise<ResponseMessage
|
|
66
|
+
contactUpdated(query: ContactQuery, contact: Contact): Promise<ResponseMessage<ClientEventType.CONTACT_CREATE_OR_UPDATE>>;
|
|
66
67
|
/**
|
|
67
68
|
* Sends notification to x-bees about contact match was updated */
|
|
68
|
-
contactMatchUpdated(query: ContactQuery, contact: Contact): Promise<ResponseMessage
|
|
69
|
+
contactMatchUpdated(query: ContactQuery, contact: Contact): Promise<ResponseMessage<ClientEventType.CONTACT_MATCH_UPDATE>>;
|
|
69
70
|
/**
|
|
70
71
|
* Retrieves current theme mode (light or dark) */
|
|
71
|
-
getThemeMode: () => Promise<ResponseMessage
|
|
72
|
+
getThemeMode: () => Promise<ResponseMessage<ClientEventType.THEME_MODE>>;
|
|
72
73
|
/**
|
|
73
74
|
* Retrieves current theme with mode (light or dark) and theme options like typography settings and palette */
|
|
74
|
-
getTheme: () => Promise<ResponseMessage
|
|
75
|
+
getTheme: () => Promise<ResponseMessage<ClientEventType.THEME>>;
|
|
75
76
|
/**
|
|
76
77
|
* Sends request to x-bees to start a call with the number */
|
|
77
78
|
startCall: (phoneNumber: string) => Promise<ResponseMessage>;
|
|
@@ -107,7 +108,7 @@ export interface ConnectClient {
|
|
|
107
108
|
onPbxTokenChange: (callback: Callback<EventType.PBX_TOKEN>) => RemoveEventListener;
|
|
108
109
|
/**
|
|
109
110
|
* Retrieves current x-bees token */
|
|
110
|
-
getXBeesToken: () => Promise<ResponseMessage
|
|
111
|
+
getXBeesToken: () => Promise<ResponseMessage<ClientEventType.TOKEN>>;
|
|
111
112
|
/**
|
|
112
113
|
* Starts listen for the events of searching contacts and handle autosuggestion with the provided callback */
|
|
113
114
|
onSuggestContacts: (callback: (query: string, resolve: SuggestContactsResolver, reject: Reject) => void) => RemoveEventListener;
|
|
@@ -147,4 +148,7 @@ export interface ConnectClient {
|
|
|
147
148
|
/**
|
|
148
149
|
* send analytics data to x-bees for track into analytics data */
|
|
149
150
|
sendAnalytics: (eventName: string, params?: Record<string, string>) => void;
|
|
151
|
+
/**
|
|
152
|
+
* special object to provide x-bees technical support */
|
|
153
|
+
getTechnicalSupport: () => TechnicalSupport;
|
|
150
154
|
}
|
|
@@ -19,4 +19,4 @@ export type EventCallbackMap = {
|
|
|
19
19
|
[EventType.PBX_TOKEN]: (token: EventPayloadMap[EventType.PBX_TOKEN]) => void;
|
|
20
20
|
[EventType.REDIRECT_QUERY]: (query: EventPayloadMap[EventType.REDIRECT_QUERY]) => void;
|
|
21
21
|
};
|
|
22
|
-
export type RawMessageEvent = MessageEvent<
|
|
22
|
+
export type RawMessageEvent = MessageEvent<string | Message>;
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import ClientParams from '../src/helpers/ClientParams';
|
|
1
2
|
import { Contact, ContactQuery } from './Contact';
|
|
2
3
|
import { Conversation } from './conversation';
|
|
4
|
+
import { JSONArray, JSONObject } from './Json';
|
|
3
5
|
import { SupportedPlatformVariant } from './Platform';
|
|
4
6
|
import { ToastSeverity } from './Toast';
|
|
5
7
|
export interface IPayloadViewPort {
|
|
@@ -52,5 +54,7 @@ export interface IPayloadSendAnalytics {
|
|
|
52
54
|
params?: Record<string, string>;
|
|
53
55
|
}
|
|
54
56
|
export interface IPayloadTechSupport {
|
|
57
|
+
'x-iframe-params': ClientParams;
|
|
55
58
|
message: string;
|
|
59
|
+
data?: JSONObject | JSONArray;
|
|
56
60
|
}
|
|
@@ -1,3 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export type { Contact, ContactQuery
|
|
1
|
+
export type { Callback } from './Callback';
|
|
2
|
+
export type { ConnectClient } from './Client';
|
|
3
|
+
export type { Contact, ContactQuery } from './Contact';
|
|
4
|
+
export type { EventPayloadMap, RawMessageEvent } from './Event';
|
|
5
|
+
export type { JSONArray, JSONObject } from './Json';
|
|
6
|
+
export type { Listener, RemoveEventListener } from './Listener';
|
|
7
|
+
export type { Message, MessageIFrameResponse, MessageType, ResponseMessage } from './Message';
|
|
8
|
+
export type { MessageSender } from './MessageSender';
|
|
9
|
+
export type { IPayloadAutoSuggestResult, IPayloadCallStart, IPayloadCallStartedInfo, IPayloadContactMatchResult, IPayloadContactMatchResultNotFound, IPayloadContactResult, IPayloadContextResult, IPayloadConversationResult, IPayloadSendAnalytics, IPayloadTechSupport, IPayloadThemeChange, IPayloadToast, IPayloadVersion, IPayloadViewPort, } from './Payload';
|
|
10
|
+
export type { SupportedPlatformVariant } from './Platform';
|
|
11
|
+
export type { LookupAndMatchContactsResolver, Reject, SuggestContactsResolver } from './Resolver';
|
|
12
|
+
export type { StorageEventCallback } from './Storage';
|
|
13
|
+
export type { ToastSeverity } from './Toast';
|
|
14
|
+
export type { WorkVariants } from './WorkVariant';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wildix/xbees-connect",
|
|
3
|
-
"version": "1.2.0-alpha.
|
|
3
|
+
"version": "1.2.0-alpha.10",
|
|
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": "0b96d918e6bee6ddf1a5f7e8c7a86a20f3ae3c72"
|
|
46
46
|
}
|