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