@wildix/xbees-connect 1.0.5 → 1.0.6-alpha.1
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/README.md +15 -0
- package/dist-es/index.js +1 -0
- package/dist-es/package.json +2 -2
- package/dist-es/src/Client.js +54 -9
- package/dist-es/src/types.js +11 -0
- package/dist-types/index.d.ts +1 -0
- package/dist-types/src/Client.d.ts +25 -16
- package/dist-types/src/helpers/PostMessageControllerNative.d.ts +2 -2
- package/dist-types/src/helpers/PostMessageControllerWeb.d.ts +2 -2
- package/dist-types/src/types.d.ts +96 -60
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -57,6 +57,21 @@ Client.getInstance().onSuggestContacts(async (query, resolve) => {
|
|
|
57
57
|
});
|
|
58
58
|
```
|
|
59
59
|
|
|
60
|
+
#### `onLookupAndMatchContact: ((query: ContactQuery, resolve: Resolve, reject: Reject) => void) => RemoveEventListener`
|
|
61
|
+
|
|
62
|
+
Starts listen for the events of searching contact info and handle match with the provided callback
|
|
63
|
+
|
|
64
|
+
```jsx
|
|
65
|
+
Client.getInstance().onLookupAndMatchContact(async (query, resolve) => {
|
|
66
|
+
try {
|
|
67
|
+
const contact = await fetchContactAndMatch(query);
|
|
68
|
+
resolve(contact);
|
|
69
|
+
} catch (error) {
|
|
70
|
+
console.log('catch', error);
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
```
|
|
74
|
+
|
|
60
75
|
### Context
|
|
61
76
|
#### `getContext(): Promise<Response>`
|
|
62
77
|
|
package/dist-es/index.js
CHANGED
package/dist-es/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wildix/xbees-connect",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.6-alpha.0",
|
|
4
4
|
"description": "This library provides easy communication between x-bees and integrated web applications",
|
|
5
5
|
"author": "dimitri.chernykh <dimitri.chernykh@wildix.com>",
|
|
6
6
|
"homepage": "",
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"build:es": "tsc -p tsconfig.es.json",
|
|
15
15
|
"build:types": "tsc -p tsconfig.types.json",
|
|
16
16
|
"build:docs": "typedoc",
|
|
17
|
-
"lint": "eslint .",
|
|
17
|
+
"lint": "eslint . && tsc --noEmit",
|
|
18
18
|
"lint:fix": "eslint . --fix",
|
|
19
19
|
"clean": "rimraf ./dist-* && rimraf *.tsbuildinfo"
|
|
20
20
|
},
|
package/dist-es/src/Client.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import packageJson from '../package.json';
|
|
2
2
|
import PostMessageControllerNative from './helpers/PostMessageControllerNative';
|
|
3
3
|
import PostMessageControllerWeb from './helpers/PostMessageControllerWeb';
|
|
4
|
-
import { ClientEventType, EventType, } from './types';
|
|
4
|
+
import { ClientEventType, EventType, UrlParams, } from './types';
|
|
5
5
|
/**
|
|
6
6
|
* Client provides functionality of communication between xBees and integrated web applications via iFrame or ReactNative WebView
|
|
7
7
|
* integration creates na instance with new Client()
|
|
@@ -24,23 +24,31 @@ export class Client {
|
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
26
|
else {
|
|
27
|
-
console.log('run daemon');
|
|
28
27
|
void this.getInstance().ready();
|
|
29
28
|
}
|
|
30
29
|
}
|
|
31
30
|
worker;
|
|
32
31
|
listeners = [];
|
|
33
32
|
useSubscription = false;
|
|
33
|
+
userToken;
|
|
34
|
+
userEmail;
|
|
35
|
+
referrer;
|
|
36
|
+
needAuthorize;
|
|
34
37
|
iframeId;
|
|
35
38
|
variant = null;
|
|
36
39
|
constructor() {
|
|
37
40
|
const params = new URLSearchParams(window.location.search);
|
|
38
|
-
this.iframeId = params.get(
|
|
39
|
-
this.variant = params.get(
|
|
41
|
+
this.iframeId = params.get(UrlParams.ID);
|
|
42
|
+
this.variant = params.get(UrlParams.VARIANT);
|
|
43
|
+
this.userEmail = params.get(UrlParams.USER);
|
|
44
|
+
this.userToken = params.get(UrlParams.TOKEN);
|
|
45
|
+
this.referrer = params.get(UrlParams.REFERRER);
|
|
46
|
+
this.needAuthorize = params.has(UrlParams.AUTHORIZE);
|
|
40
47
|
// @ts-expect-error window.ReactNativeWebView will be provided by ReactNative WebView
|
|
41
48
|
this.worker = window.ReactNativeWebView
|
|
42
49
|
? new PostMessageControllerNative()
|
|
43
50
|
: new PostMessageControllerWeb();
|
|
51
|
+
this.addEventListener(EventType.PBX_TOKEN, (token) => this.userToken = token);
|
|
44
52
|
}
|
|
45
53
|
sendAsync(data) {
|
|
46
54
|
return this.worker.sendAsync({
|
|
@@ -50,7 +58,9 @@ export class Client {
|
|
|
50
58
|
}
|
|
51
59
|
parseMessage(message) {
|
|
52
60
|
try {
|
|
53
|
-
const data = message
|
|
61
|
+
const data = typeof message.data === 'string'
|
|
62
|
+
? JSON.parse(message.data)
|
|
63
|
+
: message.data;
|
|
54
64
|
if (!data?.type) {
|
|
55
65
|
return null;
|
|
56
66
|
}
|
|
@@ -90,11 +100,20 @@ export class Client {
|
|
|
90
100
|
version() {
|
|
91
101
|
return packageJson.version;
|
|
92
102
|
}
|
|
93
|
-
|
|
94
|
-
return this.
|
|
103
|
+
getUserPbxToken() {
|
|
104
|
+
return this.userToken;
|
|
105
|
+
}
|
|
106
|
+
getUserEmail() {
|
|
107
|
+
return this.userEmail;
|
|
108
|
+
}
|
|
109
|
+
isDataOnly() {
|
|
110
|
+
return this.variant === 'd';
|
|
95
111
|
}
|
|
96
112
|
showsUi() {
|
|
97
|
-
return !this.
|
|
113
|
+
return !this.isDataOnly();
|
|
114
|
+
}
|
|
115
|
+
isActivationOnly() {
|
|
116
|
+
return this.needAuthorize;
|
|
98
117
|
}
|
|
99
118
|
getContext() {
|
|
100
119
|
return this.sendAsync({ type: ClientEventType.CONTEXT });
|
|
@@ -129,12 +148,18 @@ export class Client {
|
|
|
129
148
|
isAuthorized() {
|
|
130
149
|
return this.sendAsync({ type: ClientEventType.AUTHORIZED });
|
|
131
150
|
}
|
|
132
|
-
|
|
151
|
+
sendContactsAutoSuggest(payload) {
|
|
133
152
|
return this.sendAsync({
|
|
134
153
|
type: ClientEventType.CONTACTS_AUTO_SUGGEST,
|
|
135
154
|
payload,
|
|
136
155
|
});
|
|
137
156
|
}
|
|
157
|
+
sendContactMatch(payload) {
|
|
158
|
+
return this.sendAsync({
|
|
159
|
+
type: ClientEventType.CONTACT_LOOKUP_AND_MATCH,
|
|
160
|
+
payload,
|
|
161
|
+
});
|
|
162
|
+
}
|
|
138
163
|
addEventListener(eventName, callback) {
|
|
139
164
|
if (!this.useSubscription) {
|
|
140
165
|
this.useSubscription = true;
|
|
@@ -188,6 +213,26 @@ export class Client {
|
|
|
188
213
|
}
|
|
189
214
|
});
|
|
190
215
|
}
|
|
216
|
+
onLookupAndMatchContact(callback) {
|
|
217
|
+
return this.addEventListener(EventType.GET_LOOK_UP_AND_MATCH, (query) => {
|
|
218
|
+
const resolve = (contact) => this.sendAsync({
|
|
219
|
+
type: ClientEventType.CONTACT_LOOKUP_AND_MATCH,
|
|
220
|
+
payload: {
|
|
221
|
+
contact,
|
|
222
|
+
query,
|
|
223
|
+
},
|
|
224
|
+
});
|
|
225
|
+
const reject = (reason) => {
|
|
226
|
+
console.debug(reason);
|
|
227
|
+
};
|
|
228
|
+
try {
|
|
229
|
+
callback(query, resolve, reject);
|
|
230
|
+
}
|
|
231
|
+
catch (error) {
|
|
232
|
+
reject(`${error}`);
|
|
233
|
+
}
|
|
234
|
+
});
|
|
235
|
+
}
|
|
191
236
|
onThemeChange(callback) {
|
|
192
237
|
this.addEventListener(EventType.USE_THEME, callback);
|
|
193
238
|
}
|
package/dist-es/src/types.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export var EventType;
|
|
2
2
|
(function (EventType) {
|
|
3
3
|
EventType["GET_CONTACTS_AUTO_SUGGEST"] = "xBeesGetContactsAutoSuggest";
|
|
4
|
+
EventType["GET_LOOK_UP_AND_MATCH"] = "xBeesGetLookUpAndMatch";
|
|
4
5
|
EventType["ADD_CALL"] = "xBeesAddCall";
|
|
5
6
|
EventType["TERMINATE_CALL"] = "xBeesTerminateCall";
|
|
6
7
|
EventType["USE_THEME"] = "xBeesUseTheme";
|
|
@@ -20,4 +21,14 @@ export var ClientEventType;
|
|
|
20
21
|
ClientEventType["NOT_AUTHORIZED"] = "xBeesNotAuthorized";
|
|
21
22
|
ClientEventType["AUTHORIZED"] = "xBeesAuthorized";
|
|
22
23
|
ClientEventType["CONTACTS_AUTO_SUGGEST"] = "xBeesContactsAutoSuggest";
|
|
24
|
+
ClientEventType["CONTACT_LOOKUP_AND_MATCH"] = "xBeesContactLookupAndMatch";
|
|
23
25
|
})(ClientEventType || (ClientEventType = {}));
|
|
26
|
+
export var UrlParams;
|
|
27
|
+
(function (UrlParams) {
|
|
28
|
+
UrlParams["TOKEN"] = "t";
|
|
29
|
+
UrlParams["ID"] = "i";
|
|
30
|
+
UrlParams["VARIANT"] = "v";
|
|
31
|
+
UrlParams["USER"] = "u";
|
|
32
|
+
UrlParams["REFERRER"] = "r";
|
|
33
|
+
UrlParams["AUTHORIZE"] = "a";
|
|
34
|
+
})(UrlParams || (UrlParams = {}));
|
package/dist-types/index.d.ts
CHANGED
|
@@ -1,42 +1,51 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Callback, ClientEventType, ConnectClient, ContactQuery, EventType, IPayloadAutoSuggestResult, IPayloadContactMatchResult, IPayloadViewPort, LookupAndMatchContactsResolver, Message, Reject, RemoveEventListener, ResponseMessage, SuggestContactsResolver } from './types';
|
|
2
2
|
/**
|
|
3
3
|
* Client provides functionality of communication between xBees and integrated web applications via iFrame or ReactNative WebView
|
|
4
4
|
* integration creates na instance with new Client()
|
|
5
5
|
* */
|
|
6
6
|
export declare class Client implements ConnectClient {
|
|
7
7
|
private static instance;
|
|
8
|
-
static getInstance():
|
|
8
|
+
static getInstance(): ConnectClient;
|
|
9
9
|
static initialize(renderer: () => Promise<void>): void;
|
|
10
10
|
private worker;
|
|
11
11
|
private listeners;
|
|
12
12
|
private useSubscription;
|
|
13
|
+
private userToken;
|
|
14
|
+
private readonly userEmail;
|
|
15
|
+
private readonly referrer;
|
|
16
|
+
private readonly needAuthorize;
|
|
13
17
|
private readonly iframeId;
|
|
14
18
|
private readonly variant;
|
|
15
19
|
constructor();
|
|
16
20
|
private sendAsync;
|
|
17
21
|
private parseMessage;
|
|
18
22
|
private onMessage;
|
|
19
|
-
ready(): Promise<
|
|
23
|
+
ready(): Promise<ResponseMessage<ClientEventType.READY>>;
|
|
20
24
|
version(): string;
|
|
21
|
-
|
|
25
|
+
getUserPbxToken(): string;
|
|
26
|
+
getUserEmail(): string;
|
|
27
|
+
isDataOnly(): boolean;
|
|
22
28
|
showsUi(): boolean;
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
29
|
+
isActivationOnly(): boolean;
|
|
30
|
+
getContext(): Promise<Message<ClientEventType.CONTEXT>>;
|
|
31
|
+
getCurrentContact(): Promise<Message<ClientEventType.CURRENT_CONTACT>>;
|
|
32
|
+
getThemeMode(): Promise<Message<ClientEventType.THEME_MODE>>;
|
|
33
|
+
getTheme(): Promise<Message<ClientEventType.THEME>>;
|
|
34
|
+
startCall(phoneNumber: string): Promise<Message<ClientEventType.START_CALL>>;
|
|
35
|
+
reboot(): Promise<ResponseMessage>;
|
|
36
|
+
setViewport(payload: IPayloadViewPort): Promise<ResponseMessage>;
|
|
37
|
+
toClipboard(payload: string): Promise<ResponseMessage>;
|
|
38
|
+
isNotAuthorized(): Promise<ResponseMessage>;
|
|
39
|
+
isAuthorized(): Promise<ResponseMessage>;
|
|
40
|
+
sendContactsAutoSuggest(payload: IPayloadAutoSuggestResult): Promise<Message<ClientEventType.CONTACTS_AUTO_SUGGEST>>;
|
|
41
|
+
sendContactMatch(payload: IPayloadContactMatchResult): Promise<Message<ClientEventType.CONTACT_LOOKUP_AND_MATCH>>;
|
|
34
42
|
addEventListener<T extends EventType = EventType>(eventName: T, callback: Callback<T>): RemoveEventListener;
|
|
35
43
|
removeEventListener<T extends EventType = EventType>(eventName: T | null, callback: Callback<T>): void;
|
|
36
44
|
off(callback: Callback): void;
|
|
37
45
|
onCallEnded(callback: Callback<EventType.TERMINATE_CALL>): void;
|
|
38
46
|
onCallStarted(callback: Callback<EventType.ADD_CALL>): void;
|
|
39
47
|
onPbxTokenChange(callback: Callback<EventType.PBX_TOKEN>): void;
|
|
40
|
-
onSuggestContacts(callback: (query: string, resolve:
|
|
48
|
+
onSuggestContacts(callback: (query: string, resolve: SuggestContactsResolver, reject: Reject) => void): RemoveEventListener;
|
|
49
|
+
onLookupAndMatchContact(callback: (query: ContactQuery, resolve: LookupAndMatchContactsResolver, reject: Reject) => void): RemoveEventListener;
|
|
41
50
|
onThemeChange(callback: Callback<EventType.USE_THEME>): void;
|
|
42
51
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { MessageIFrameResponse, MessageType, PostMessageController, ResponseMessage } from '../types';
|
|
2
2
|
export default class PostMessageControllerNative implements PostMessageController {
|
|
3
3
|
private readonly target;
|
|
4
4
|
private timeout;
|
|
5
5
|
constructor();
|
|
6
|
-
sendAsync(data:
|
|
6
|
+
sendAsync<T extends MessageType>(data: MessageIFrameResponse<T>): Promise<ResponseMessage<T>>;
|
|
7
7
|
private send;
|
|
8
8
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { MessageIFrameResponse, MessageType, PostMessageController, ResponseMessage } from '../types';
|
|
2
2
|
export default class PostMessageControllerWeb implements PostMessageController {
|
|
3
3
|
private readonly target;
|
|
4
4
|
private timeout;
|
|
5
5
|
constructor();
|
|
6
|
-
sendAsync(data:
|
|
6
|
+
sendAsync<T extends MessageType>(data: MessageIFrameResponse<T>): Promise<ResponseMessage<T>>;
|
|
7
7
|
private send;
|
|
8
8
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export declare enum EventType {
|
|
2
2
|
GET_CONTACTS_AUTO_SUGGEST = "xBeesGetContactsAutoSuggest",
|
|
3
|
+
GET_LOOK_UP_AND_MATCH = "xBeesGetLookUpAndMatch",
|
|
3
4
|
ADD_CALL = "xBeesAddCall",
|
|
4
5
|
TERMINATE_CALL = "xBeesTerminateCall",
|
|
5
6
|
USE_THEME = "xBeesUseTheme",
|
|
@@ -17,7 +18,8 @@ export declare enum ClientEventType {
|
|
|
17
18
|
TO_CLIPBOARD = "xBeesToClipboard",
|
|
18
19
|
NOT_AUTHORIZED = "xBeesNotAuthorized",
|
|
19
20
|
AUTHORIZED = "xBeesAuthorized",
|
|
20
|
-
CONTACTS_AUTO_SUGGEST = "xBeesContactsAutoSuggest"
|
|
21
|
+
CONTACTS_AUTO_SUGGEST = "xBeesContactsAutoSuggest",
|
|
22
|
+
CONTACT_LOOKUP_AND_MATCH = "xBeesContactLookupAndMatch"
|
|
21
23
|
}
|
|
22
24
|
export type MessageType = ClientEventType | EventType;
|
|
23
25
|
interface ContactShape {
|
|
@@ -38,58 +40,73 @@ export type Contact = (ContactShape & {
|
|
|
38
40
|
}) | (ContactShape & {
|
|
39
41
|
phone: string;
|
|
40
42
|
});
|
|
41
|
-
export type
|
|
42
|
-
|
|
43
|
-
|
|
43
|
+
export type ContactQuery = {
|
|
44
|
+
email: string;
|
|
45
|
+
phone?: string;
|
|
46
|
+
} | {
|
|
47
|
+
email?: string;
|
|
48
|
+
phone: string;
|
|
49
|
+
} | {
|
|
50
|
+
id: string;
|
|
44
51
|
};
|
|
45
|
-
|
|
52
|
+
export interface IPayloadViewPort {
|
|
53
|
+
height: number | string;
|
|
54
|
+
width: number | string;
|
|
55
|
+
}
|
|
56
|
+
export interface IPayloadVersion {
|
|
46
57
|
version: string;
|
|
47
|
-
}
|
|
48
|
-
export
|
|
49
|
-
type: T;
|
|
50
|
-
payload?: EventPayload<T>;
|
|
51
|
-
};
|
|
52
|
-
export type MessageResponse<T extends MessageType = MessageType> = Message<T> & {
|
|
53
|
-
iframeId: string;
|
|
54
|
-
};
|
|
55
|
-
export type Payload = string | Record<string, string> | ThemeChangePayload;
|
|
56
|
-
export type Response<T extends Payload = Payload> = {
|
|
57
|
-
type?: string;
|
|
58
|
-
message?: string;
|
|
59
|
-
errorMessage?: string;
|
|
60
|
-
payload?: T;
|
|
61
|
-
};
|
|
62
|
-
export type RawMessage = {
|
|
63
|
-
data?: string;
|
|
64
|
-
};
|
|
65
|
-
export type SendPayload = {
|
|
66
|
-
type: ClientEventType;
|
|
67
|
-
payload?: any;
|
|
68
|
-
};
|
|
69
|
-
export type ThemeChangePayload = {
|
|
58
|
+
}
|
|
59
|
+
export interface IPayloadThemeChange {
|
|
70
60
|
mode: 'light' | 'dark';
|
|
71
61
|
themeOptions?: {
|
|
72
62
|
typography?: unknown;
|
|
73
63
|
palette?: unknown;
|
|
74
64
|
};
|
|
75
|
-
}
|
|
76
|
-
export
|
|
77
|
-
export type DefaultCallback = (...args: unknown[]) => void;
|
|
78
|
-
type CallStartInfo = {
|
|
65
|
+
}
|
|
66
|
+
export interface IPayloadCallStartedInfo {
|
|
79
67
|
destination: string;
|
|
80
68
|
video: boolean;
|
|
81
|
-
}
|
|
82
|
-
|
|
69
|
+
}
|
|
70
|
+
export interface IPayloadCallStart {
|
|
83
71
|
phoneNumber: string;
|
|
72
|
+
}
|
|
73
|
+
export interface IPayloadAutoSuggestResult {
|
|
74
|
+
contacts: Contact[];
|
|
75
|
+
query: string;
|
|
76
|
+
}
|
|
77
|
+
export interface IPayloadContactMatchResult {
|
|
78
|
+
contact: Contact;
|
|
79
|
+
query: ContactQuery;
|
|
80
|
+
}
|
|
81
|
+
export interface IPayloadContactResult {
|
|
82
|
+
contact: Contact;
|
|
83
|
+
}
|
|
84
|
+
export interface IPayloadContextResult extends IPayloadContactResult {
|
|
85
|
+
}
|
|
86
|
+
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.CONTEXT ? IPayloadContextResult : T extends EventType.ADD_CALL ? IPayloadCallStartedInfo : T extends ClientEventType.START_CALL ? IPayloadCallStart : T extends ClientEventType.READY ? IPayloadVersion : T extends ClientEventType.VIEW_PORT ? IPayloadViewPort : T extends ClientEventType.THEME ? IPayloadThemeChange : T extends EventType.USE_THEME ? string : T extends EventType.PBX_TOKEN ? string : T extends ClientEventType.TO_CLIPBOARD ? string : never;
|
|
87
|
+
export type Message<T extends MessageType = MessageType> = {
|
|
88
|
+
type: T;
|
|
89
|
+
payload?: EventPayload<T>;
|
|
84
90
|
};
|
|
91
|
+
export type ErrorMessage = {
|
|
92
|
+
errorMessage: string;
|
|
93
|
+
};
|
|
94
|
+
export type MessageIFrameResponse<T extends MessageType = MessageType> = Message<T> & {
|
|
95
|
+
iframeId: string;
|
|
96
|
+
};
|
|
97
|
+
export type ResponseMessage<T extends MessageType = MessageType> = Message<T> & ErrorMessage;
|
|
98
|
+
export type RawMessageEvent = MessageEvent<'string' | Message>;
|
|
99
|
+
export type DefaultCallback = (...args: unknown[]) => void;
|
|
85
100
|
export type EventPayloadMap = {
|
|
86
101
|
[EventType.GET_CONTACTS_AUTO_SUGGEST]: string;
|
|
87
|
-
[EventType.
|
|
88
|
-
[EventType.
|
|
102
|
+
[EventType.GET_LOOK_UP_AND_MATCH]: ContactQuery;
|
|
103
|
+
[EventType.ADD_CALL]: IPayloadCallStartedInfo;
|
|
104
|
+
[EventType.USE_THEME]: string | IPayloadThemeChange;
|
|
89
105
|
[EventType.PBX_TOKEN]: string;
|
|
90
106
|
};
|
|
91
107
|
export type EventCallbackMap = {
|
|
92
108
|
[EventType.GET_CONTACTS_AUTO_SUGGEST]: (query: EventPayloadMap[EventType.GET_CONTACTS_AUTO_SUGGEST]) => void;
|
|
109
|
+
[EventType.GET_LOOK_UP_AND_MATCH]: (query: EventPayloadMap[EventType.GET_LOOK_UP_AND_MATCH]) => void;
|
|
93
110
|
[EventType.ADD_CALL]: (callStartInfo: EventPayloadMap[EventType.ADD_CALL]) => void;
|
|
94
111
|
[EventType.USE_THEME]: (themeName: EventPayloadMap[EventType.USE_THEME]) => void;
|
|
95
112
|
[EventType.PBX_TOKEN]: (token: EventPayloadMap[EventType.PBX_TOKEN]) => void;
|
|
@@ -105,72 +122,88 @@ export type ClientEventCallbackMap = {
|
|
|
105
122
|
[ClientEventType.AUTHORIZED]: () => void;
|
|
106
123
|
[ClientEventType.CONTACTS_AUTO_SUGGEST]: (suggestions: string[]) => void;
|
|
107
124
|
};
|
|
108
|
-
export interface ReactNativeWebView {
|
|
109
|
-
postMessage: (payload: unknown, origin?: string, d?: unknown[]) => void;
|
|
110
|
-
}
|
|
111
125
|
export type Callback<T extends EventType = EventType> = T extends keyof EventCallbackMap ? EventCallbackMap[T] : DefaultCallback;
|
|
112
126
|
export interface Listener<T extends EventType = EventType> {
|
|
113
127
|
eventName: T;
|
|
114
128
|
callback: Callback<T>;
|
|
115
129
|
}
|
|
116
|
-
export
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
130
|
+
export declare enum UrlParams {
|
|
131
|
+
TOKEN = "t",
|
|
132
|
+
ID = "i",
|
|
133
|
+
VARIANT = "v",
|
|
134
|
+
USER = "u",
|
|
135
|
+
REFERRER = "r",
|
|
136
|
+
AUTHORIZE = "a"
|
|
120
137
|
}
|
|
138
|
+
export type WorkVariants = 'ui' | 'no-ui' | 'd';
|
|
121
139
|
export interface PostMessageController {
|
|
122
|
-
sendAsync(data:
|
|
140
|
+
sendAsync<T extends MessageType>(data: MessageIFrameResponse<T>): Promise<ResponseMessage<T>>;
|
|
123
141
|
}
|
|
124
|
-
export type
|
|
142
|
+
export type SuggestContactsResolver = (contacts: Contact[]) => void;
|
|
143
|
+
export type LookupAndMatchContactsResolver = (contact: Contact) => void;
|
|
125
144
|
export type Reject = (reason: string) => void;
|
|
126
145
|
export type RemoveEventListener = () => void;
|
|
127
146
|
export interface ConnectClient {
|
|
128
147
|
/**
|
|
129
148
|
* Sends to x-bees signal that iFrame is ready to be shown. iFrame should send it when the application starts and ready */
|
|
130
|
-
ready: () => Promise<
|
|
149
|
+
ready: () => Promise<ResponseMessage>;
|
|
150
|
+
/**
|
|
151
|
+
* Retrieves current pbx token */
|
|
152
|
+
getUserPbxToken: () => string;
|
|
153
|
+
/**
|
|
154
|
+
* Retrieves current user's email */
|
|
155
|
+
getUserEmail: () => string;
|
|
131
156
|
/**
|
|
132
157
|
* Retrieves the version of xBeesConnect */
|
|
133
158
|
version: () => string;
|
|
134
159
|
/**
|
|
135
160
|
* Determines x-bees is using this connect for messages only and this integration will not be shown on UI */
|
|
136
|
-
|
|
161
|
+
isDataOnly: () => boolean;
|
|
137
162
|
/**
|
|
138
163
|
* Determines x-bees is using this connect for representation on UI and this integration will be shown on UI
|
|
139
|
-
* this opposite to {@link
|
|
164
|
+
* this opposite to {@link isDataOnly} */
|
|
140
165
|
showsUi: () => boolean;
|
|
166
|
+
/**
|
|
167
|
+
* Determines x-bees is using this connect for activation/authorization on UI and this call of integration UI should show
|
|
168
|
+
* dialog which leads to integration be activated
|
|
169
|
+
* */
|
|
170
|
+
isActivationOnly: () => boolean;
|
|
141
171
|
/**
|
|
142
172
|
* Retrieves current x-bees context data */
|
|
143
|
-
getContext: () => Promise<
|
|
173
|
+
getContext: () => Promise<Message<ClientEventType.CONTEXT>>;
|
|
144
174
|
/**
|
|
145
175
|
* Retrieves current opened in x-bees contact data */
|
|
146
|
-
getCurrentContact: () => Promise<
|
|
176
|
+
getCurrentContact: () => Promise<Message<ClientEventType.CURRENT_CONTACT>>;
|
|
147
177
|
/**
|
|
148
178
|
* Retrieves current theme mode (light or dark) */
|
|
149
|
-
getThemeMode: () => Promise<
|
|
179
|
+
getThemeMode: () => Promise<Message<ClientEventType.THEME_MODE>>;
|
|
150
180
|
/**
|
|
151
181
|
* Retrieves current theme with mode (light or dark) and theme options like typography settings and palette */
|
|
152
|
-
getTheme: () => Promise<
|
|
182
|
+
getTheme: () => Promise<Message<ClientEventType.THEME>>;
|
|
153
183
|
/**
|
|
154
184
|
* Sends request to x-bees to start a call with the number */
|
|
155
|
-
startCall: (phoneNumber: string) => Promise<
|
|
185
|
+
startCall: (phoneNumber: string) => Promise<Message<ClientEventType.START_CALL>>;
|
|
156
186
|
/**
|
|
157
187
|
* Sends request to x-bees to restart the iFrame, reload with actual params and token */
|
|
158
|
-
reboot: () => Promise<
|
|
188
|
+
reboot: () => Promise<ResponseMessage>;
|
|
159
189
|
/**
|
|
160
190
|
* Sends request to x-bees about current frame size change */
|
|
161
|
-
setViewport: (payload:
|
|
191
|
+
setViewport: (payload: IPayloadViewPort) => Promise<ResponseMessage>;
|
|
162
192
|
/**
|
|
163
193
|
* Sends request to x-bees to put string to the users clipboard */
|
|
164
|
-
toClipboard: (payload: string) => Promise<
|
|
194
|
+
toClipboard: (payload: string) => Promise<ResponseMessage>;
|
|
165
195
|
/**
|
|
166
196
|
* Sends a response to x-bees for contacts autoSuggest */
|
|
167
|
-
|
|
197
|
+
sendContactsAutoSuggest: (payload: IPayloadAutoSuggestResult) => Promise<Message<ClientEventType.CONTACTS_AUTO_SUGGEST>>;
|
|
198
|
+
/**
|
|
199
|
+
* Sends a response to x-bees for contact match */
|
|
200
|
+
sendContactMatch: (payload: IPayloadContactMatchResult) => Promise<Message<ClientEventType.CONTACT_LOOKUP_AND_MATCH>>;
|
|
168
201
|
/**
|
|
169
202
|
* pushes to x-bees message that user is authorized and no more actions required */
|
|
170
|
-
isAuthorized: () => Promise<
|
|
203
|
+
isAuthorized: () => Promise<ResponseMessage>;
|
|
171
204
|
/**
|
|
172
205
|
* pushes to x-bees message that user actions required */
|
|
173
|
-
isNotAuthorized: () => Promise<
|
|
206
|
+
isNotAuthorized: () => Promise<ResponseMessage>;
|
|
174
207
|
/**
|
|
175
208
|
* Starts listen for one of the events of the x-bees and handle with the provided callback */
|
|
176
209
|
addEventListener: <T extends EventType = EventType>(eventName: T, callback: Callback<T>) => RemoveEventListener;
|
|
@@ -185,7 +218,10 @@ export interface ConnectClient {
|
|
|
185
218
|
onPbxTokenChange: (callback: Callback<EventType.PBX_TOKEN>) => void;
|
|
186
219
|
/**
|
|
187
220
|
* Starts listen for the events of searching contacts and handle autosuggestion with the provided callback */
|
|
188
|
-
onSuggestContacts: (callback: (query: string, resolve:
|
|
221
|
+
onSuggestContacts: (callback: (query: string, resolve: SuggestContactsResolver, reject: Reject) => void) => RemoveEventListener;
|
|
222
|
+
/**
|
|
223
|
+
* Starts listen for the events of searching contact info and handle match with the provided callback */
|
|
224
|
+
onLookupAndMatchContact: (callback: (query: ContactQuery, resolve: LookupAndMatchContactsResolver, reject: Reject) => void) => RemoveEventListener;
|
|
189
225
|
/**
|
|
190
226
|
* Starts listen for the events of starting the call and handle with the provided callback */
|
|
191
227
|
onCallStarted: (callback: Callback<EventType.ADD_CALL>) => void;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wildix/xbees-connect",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.6-alpha.1",
|
|
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": "",
|
|
@@ -41,5 +41,5 @@
|
|
|
41
41
|
"engines": {
|
|
42
42
|
"node": ">=16"
|
|
43
43
|
},
|
|
44
|
-
"gitHead": "
|
|
44
|
+
"gitHead": "49f97f25e700f11a7f2a04f3a386d474c9f01395"
|
|
45
45
|
}
|