@wildix/xbees-connect 1.0.6-alpha.1 → 1.0.6-alpha.11

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/index.js CHANGED
@@ -1,3 +1,5 @@
1
1
  import { Client } from './src/Client';
2
- export * from './src/types';
2
+ export { EventType } from './src/enums';
3
+ export { ClientEventType } from './src/enums';
4
+ export { UrlParams } from './src/enums';
3
5
  export default Client;
@@ -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": "",
@@ -11,6 +11,7 @@
11
11
  "module": "./dist-es/index.js",
12
12
  "type": "module",
13
13
  "scripts": {
14
+ "build": "yarn clean && yarn build:es && yarn build:types",
14
15
  "build:es": "tsc -p tsconfig.es.json",
15
16
  "build:types": "tsc -p tsconfig.types.json",
16
17
  "build:docs": "typedoc",
@@ -1,7 +1,7 @@
1
1
  import packageJson from '../package.json';
2
+ import { ClientEventType, DeprecatedUrlParams, EventType, UrlParams } from './enums';
2
3
  import PostMessageControllerNative from './helpers/PostMessageControllerNative';
3
4
  import PostMessageControllerWeb from './helpers/PostMessageControllerWeb';
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()
@@ -38,12 +38,12 @@ export class Client {
38
38
  variant = null;
39
39
  constructor() {
40
40
  const params = new URLSearchParams(window.location.search);
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);
41
+ this.iframeId = (params.get(UrlParams.ID) ?? params.get(DeprecatedUrlParams.ID));
42
+ this.variant = (params.get(UrlParams.VARIANT) ?? params.get(DeprecatedUrlParams.VARIANT));
43
+ this.userEmail = (params.get(UrlParams.USER) ?? params.get(DeprecatedUrlParams.USER));
44
+ this.userToken = (params.get(UrlParams.TOKEN) ?? params.get(DeprecatedUrlParams.TOKEN));
45
+ this.referrer = (params.get(UrlParams.REFERRER) ?? params.get(DeprecatedUrlParams.REFERRER));
46
+ this.needAuthorize = (params.has(UrlParams.AUTHORIZE) ?? params.has(DeprecatedUrlParams.AUTHORIZE));
47
47
  // @ts-expect-error window.ReactNativeWebView will be provided by ReactNative WebView
48
48
  this.worker = window.ReactNativeWebView
49
49
  ? new PostMessageControllerNative()
@@ -107,7 +107,7 @@ export class Client {
107
107
  return this.userEmail;
108
108
  }
109
109
  isDataOnly() {
110
- return this.variant === 'd';
110
+ return this.variant === 'd' || this.variant === 'daemon';
111
111
  }
112
112
  showsUi() {
113
113
  return !this.isDataOnly();
@@ -23,6 +23,15 @@ export var ClientEventType;
23
23
  ClientEventType["CONTACTS_AUTO_SUGGEST"] = "xBeesContactsAutoSuggest";
24
24
  ClientEventType["CONTACT_LOOKUP_AND_MATCH"] = "xBeesContactLookupAndMatch";
25
25
  })(ClientEventType || (ClientEventType = {}));
26
+ export var DeprecatedUrlParams;
27
+ (function (DeprecatedUrlParams) {
28
+ DeprecatedUrlParams["TOKEN"] = "token";
29
+ DeprecatedUrlParams["ID"] = "iframeId";
30
+ DeprecatedUrlParams["VARIANT"] = "variant";
31
+ DeprecatedUrlParams["USER"] = "u";
32
+ DeprecatedUrlParams["REFERRER"] = "referrer";
33
+ DeprecatedUrlParams["AUTHORIZE"] = "authorize";
34
+ })(DeprecatedUrlParams || (DeprecatedUrlParams = {}));
26
35
  export var UrlParams;
27
36
  (function (UrlParams) {
28
37
  UrlParams["TOKEN"] = "t";
@@ -0,0 +1 @@
1
+ import { EventType } from '../src/enums';
@@ -1,3 +1,5 @@
1
1
  import { Client } from './src/Client';
2
- export * from './src/types';
2
+ export { EventType } from './src/enums';
3
+ export { ClientEventType } from './src/enums';
4
+ export { UrlParams } from './src/enums';
3
5
  export default Client;
@@ -1,4 +1,5 @@
1
- import { Callback, ClientEventType, ConnectClient, ContactQuery, EventType, IPayloadAutoSuggestResult, IPayloadContactMatchResult, IPayloadViewPort, LookupAndMatchContactsResolver, Message, Reject, RemoveEventListener, ResponseMessage, SuggestContactsResolver } 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()
@@ -0,0 +1,39 @@
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 DeprecatedUrlParams {
25
+ TOKEN = "token",
26
+ ID = "iframeId",
27
+ VARIANT = "variant",
28
+ USER = "u",
29
+ REFERRER = "referrer",
30
+ AUTHORIZE = "authorize"
31
+ }
32
+ export declare enum UrlParams {
33
+ TOKEN = "t",
34
+ ID = "i",
35
+ VARIANT = "v",
36
+ USER = "u",
37
+ REFERRER = "r",
38
+ AUTHORIZE = "a"
39
+ }
@@ -1,4 +1,4 @@
1
- import { MessageIFrameResponse, MessageType, PostMessageController, ResponseMessage } 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;
@@ -1,4 +1,4 @@
1
- import { MessageIFrameResponse, MessageType, PostMessageController, ResponseMessage } 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;
@@ -1,26 +1,4 @@
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
- }
1
+ import { ClientEventType, EventType } from '../src/enums';
24
2
  export type MessageType = ClientEventType | EventType;
25
3
  interface ContactShape {
26
4
  id: string;
@@ -41,13 +19,9 @@ export type Contact = (ContactShape & {
41
19
  phone: string;
42
20
  });
43
21
  export type ContactQuery = {
44
- email: string;
45
- phone?: string;
46
- } | {
22
+ id?: string;
47
23
  email?: string;
48
- phone: string;
49
- } | {
50
- id: string;
24
+ phone?: string;
51
25
  };
52
26
  export interface IPayloadViewPort {
53
27
  height: number | string;
@@ -83,13 +57,13 @@ export interface IPayloadContactResult {
83
57
  }
84
58
  export interface IPayloadContextResult extends IPayloadContactResult {
85
59
  }
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;
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;
87
61
  export type Message<T extends MessageType = MessageType> = {
88
62
  type: T;
89
63
  payload?: EventPayload<T>;
90
64
  };
91
65
  export type ErrorMessage = {
92
- errorMessage: string;
66
+ errorMessage?: string;
93
67
  };
94
68
  export type MessageIFrameResponse<T extends MessageType = MessageType> = Message<T> & {
95
69
  iframeId: string;
@@ -101,41 +75,23 @@ export type EventPayloadMap = {
101
75
  [EventType.GET_CONTACTS_AUTO_SUGGEST]: string;
102
76
  [EventType.GET_LOOK_UP_AND_MATCH]: ContactQuery;
103
77
  [EventType.ADD_CALL]: IPayloadCallStartedInfo;
104
- [EventType.USE_THEME]: string | IPayloadThemeChange;
78
+ [EventType.USE_THEME]: IPayloadThemeChange;
105
79
  [EventType.PBX_TOKEN]: string;
106
80
  };
107
81
  export type EventCallbackMap = {
108
82
  [EventType.GET_CONTACTS_AUTO_SUGGEST]: (query: EventPayloadMap[EventType.GET_CONTACTS_AUTO_SUGGEST]) => void;
109
83
  [EventType.GET_LOOK_UP_AND_MATCH]: (query: EventPayloadMap[EventType.GET_LOOK_UP_AND_MATCH]) => void;
110
84
  [EventType.ADD_CALL]: (callStartInfo: EventPayloadMap[EventType.ADD_CALL]) => void;
111
- [EventType.USE_THEME]: (themeName: EventPayloadMap[EventType.USE_THEME]) => void;
85
+ [EventType.USE_THEME]: (theme: EventPayloadMap[EventType.USE_THEME]) => void;
112
86
  [EventType.PBX_TOKEN]: (token: EventPayloadMap[EventType.PBX_TOKEN]) => void;
113
87
  };
114
- export type ClientEventCallbackMap = {
115
- [ClientEventType.READY]: () => void;
116
- [ClientEventType.CONTEXT]: (context: any) => void;
117
- [ClientEventType.CURRENT_CONTACT]: (contact: Contact) => void;
118
- [ClientEventType.THEME_MODE]: (themeMode: string) => void;
119
- [ClientEventType.REBOOT]: () => void;
120
- [ClientEventType.TO_CLIPBOARD]: (text: string) => void;
121
- [ClientEventType.NOT_AUTHORIZED]: () => void;
122
- [ClientEventType.AUTHORIZED]: () => void;
123
- [ClientEventType.CONTACTS_AUTO_SUGGEST]: (suggestions: string[]) => void;
124
- };
125
88
  export type Callback<T extends EventType = EventType> = T extends keyof EventCallbackMap ? EventCallbackMap[T] : DefaultCallback;
126
89
  export interface Listener<T extends EventType = EventType> {
127
90
  eventName: T;
128
91
  callback: Callback<T>;
129
92
  }
130
- export declare enum UrlParams {
131
- TOKEN = "t",
132
- ID = "i",
133
- VARIANT = "v",
134
- USER = "u",
135
- REFERRER = "r",
136
- AUTHORIZE = "a"
137
- }
138
- export type WorkVariants = 'ui' | 'no-ui' | 'd';
93
+ type DeprecatedWorkVariants = 'info-frame' | 'daemon' | 'dialog';
94
+ export type WorkVariants = 'ui' | 'no-ui' | 'd' | DeprecatedWorkVariants;
139
95
  export interface PostMessageController {
140
96
  sendAsync<T extends MessageType>(data: MessageIFrameResponse<T>): Promise<ResponseMessage<T>>;
141
97
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wildix/xbees-connect",
3
- "version": "1.0.6-alpha.1",
3
+ "version": "1.0.6-alpha.11",
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": "",
@@ -11,6 +11,7 @@
11
11
  "module": "./dist-es/index.js",
12
12
  "type": "module",
13
13
  "scripts": {
14
+ "build": "yarn clean && yarn build:es && yarn build:types",
14
15
  "build:es": "tsc -p tsconfig.es.json",
15
16
  "build:types": "tsc -p tsconfig.types.json",
16
17
  "build:docs": "typedoc",
@@ -41,5 +42,5 @@
41
42
  "engines": {
42
43
  "node": ">=16"
43
44
  },
44
- "gitHead": "49f97f25e700f11a7f2a04f3a386d474c9f01395"
45
+ "gitHead": "727dd9ae4ffb95271b79bfdc308838dddd82c860"
45
46
  }