@wildix/xbees-connect 1.3.5 → 1.3.7
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 +381 -73
- package/dist-cjs/index.js +2 -1
- package/dist-cjs/package.json +1 -1
- package/dist-cjs/src/Client.js +5 -0
- package/dist-cjs/src/enums/index.js +8 -1
- package/dist-cjs/src/helpers/ClientParams.js +2 -0
- package/dist-es/index.js +1 -1
- package/dist-es/package.json +1 -1
- package/dist-es/src/Client.js +5 -0
- package/dist-es/src/enums/index.js +7 -0
- package/dist-es/src/helpers/ClientParams.js +2 -0
- package/dist-types/index.d.ts +1 -1
- package/dist-types/src/Client.d.ts +3 -1
- package/dist-types/src/enums/index.d.ts +7 -1
- package/dist-types/src/helpers/ClientParams.d.ts +2 -1
- package/dist-types/types/Client.d.ts +4 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -18,8 +18,8 @@ npm install @wildix/xbees-connect
|
|
|
18
18
|
The integration can be launched in different modes via the `v` URL parameter:
|
|
19
19
|
|
|
20
20
|
- `ui` - Standard UI mode (default)
|
|
21
|
-
- `no-ui` - Data-only mode, no UI shown
|
|
22
|
-
- `d` - Dialog/setup mode
|
|
21
|
+
- `no-ui` / `daemon` - Data-only mode, no UI shown
|
|
22
|
+
- `d` / `dialog` - Dialog/setup mode
|
|
23
23
|
- `f` - Fullsize mode, integration takes full viewport dimensions
|
|
24
24
|
|
|
25
25
|
You can check the current mode using:
|
|
@@ -27,10 +27,10 @@ You can check the current mode using:
|
|
|
27
27
|
```ts
|
|
28
28
|
const client = Client.getInstance();
|
|
29
29
|
|
|
30
|
-
client.showsUi();
|
|
31
|
-
client.isDataOnly();
|
|
32
|
-
client.isSetupDialog(); // Returns true for dialog mode (d)
|
|
33
|
-
client.isFullsize();
|
|
30
|
+
client.showsUi(); // Returns true for UI modes (ui, d, f)
|
|
31
|
+
client.isDataOnly(); // Returns true for no-ui / daemon mode
|
|
32
|
+
client.isSetupDialog(); // Returns true for dialog mode (d / dialog)
|
|
33
|
+
client.isFullsize(); // Returns true for fullsize mode (f)
|
|
34
34
|
```
|
|
35
35
|
|
|
36
36
|
## Usage
|
|
@@ -41,136 +41,444 @@ import Client from "@wildix/xbees-connect";
|
|
|
41
41
|
const xBeesClient = Client.getInstance();
|
|
42
42
|
|
|
43
43
|
console.log(xBeesClient.version());
|
|
44
|
-
|
|
45
44
|
```
|
|
46
45
|
|
|
47
46
|
## API
|
|
48
47
|
|
|
48
|
+
### Class helpers
|
|
49
|
+
|
|
50
|
+
#### `Client.getInstance(): ConnectClient`
|
|
51
|
+
|
|
52
|
+
Returns the singleton `Client` instance. Prefer this over `new Client()` to avoid duplicate message listeners.
|
|
53
|
+
|
|
54
|
+
```ts
|
|
55
|
+
const client = Client.getInstance();
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
#### `Client.initialize(renderer: () => Promise<void>): void`
|
|
59
|
+
|
|
60
|
+
Calls `renderer` only when the integration runs in a UI mode (`showsUi() === true`). Use this as the entry point to conditionally boot your React/Vue tree.
|
|
61
|
+
|
|
62
|
+
```ts
|
|
63
|
+
Client.initialize(async () => {
|
|
64
|
+
ReactDOM.render(<App />, document.getElementById('root'));
|
|
65
|
+
});
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
---
|
|
69
|
+
|
|
49
70
|
### Initialization
|
|
50
71
|
|
|
51
|
-
#### `ready()
|
|
72
|
+
#### `ready(props?: SupportedPlatformVariant | ReadyExtendedProps): Promise<ResponseMessage>`
|
|
52
73
|
|
|
53
|
-
Sends the signal to x-bees that iFrame is ready to be shown.
|
|
74
|
+
Sends the signal to x-bees that the iFrame is ready to be shown. Call this once when the application starts and is fully initialised. Accepts an optional platform variant string or an extended props object (e.g. `templateId`, `analyticTitle`).
|
|
54
75
|
|
|
55
|
-
#### `isAuthorized
|
|
76
|
+
#### `isAuthorized(): Promise<ResponseMessage>`
|
|
56
77
|
|
|
57
78
|
Sends the message to x-bees that the user is authorized and no more actions are required.
|
|
58
79
|
|
|
59
|
-
#### `isNotAuthorized
|
|
80
|
+
#### `isNotAuthorized(): Promise<ResponseMessage>`
|
|
81
|
+
|
|
82
|
+
Sends the message to x-bees that the user is not authorized and interaction is required.
|
|
83
|
+
|
|
84
|
+
---
|
|
85
|
+
|
|
86
|
+
### Identity and user data
|
|
87
|
+
|
|
88
|
+
#### `version(): string`
|
|
89
|
+
|
|
90
|
+
Returns the version string of the `xbees-connect` package.
|
|
91
|
+
|
|
92
|
+
#### `getUserEmail(): string`
|
|
93
|
+
|
|
94
|
+
Returns the email of the currently authenticated x-bees user, taken from URL parameters at construction time.
|
|
95
|
+
|
|
96
|
+
#### `getUserPbxToken(): string`
|
|
97
|
+
|
|
98
|
+
Returns the current PBX token. The token is updated automatically whenever the `PBX_TOKEN` event fires. The initial value is an empty string until the first token event is received.
|
|
99
|
+
|
|
100
|
+
#### `getPbxDomain(): string`
|
|
101
|
+
|
|
102
|
+
Returns the current PBX domain. Populated after user data is fetched from x-bees.
|
|
103
|
+
|
|
104
|
+
#### `getUserExtension(): string | null`
|
|
105
|
+
|
|
106
|
+
Returns the PBX extension of the current user, or `null` if not available.
|
|
107
|
+
|
|
108
|
+
#### `getXBeesUser(): XBeesUser | null`
|
|
109
|
+
|
|
110
|
+
Returns a cached `XBeesUser` object (`{ id, email, extension, domain, name }`) or `null` if the data has not been fetched yet. Triggers a background fetch on first call.
|
|
111
|
+
|
|
112
|
+
> **Deprecated behaviour:** this method does not wait for the fetch to complete. If you need the user data before rendering, use `getXBeesUserAsync()` instead.
|
|
113
|
+
|
|
114
|
+
#### `getXBeesUserAsync(): Promise<XBeesUser | null>`
|
|
115
|
+
|
|
116
|
+
Asynchronous version of `getXBeesUser`. Waits for the user data to be fetched from x-bees before returning. Prefer this over the synchronous variant when the user object is required immediately.
|
|
117
|
+
|
|
118
|
+
```ts
|
|
119
|
+
const user = await client.getXBeesUserAsync();
|
|
120
|
+
if (user) {
|
|
121
|
+
console.log(user.name, user.email);
|
|
122
|
+
}
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
#### `getReferrer(): string`
|
|
126
|
+
|
|
127
|
+
Returns the URL of the x-bees app that opened this integration, taken from URL parameters at construction time.
|
|
128
|
+
|
|
129
|
+
#### `getBackToAppUrl(): string`
|
|
130
|
+
|
|
131
|
+
Returns the deep-link URL that navigates the user back to this integration inside the x-bees app. The format differs between native and web platforms.
|
|
132
|
+
|
|
133
|
+
#### `getStartPage(): StartPage | null`
|
|
134
|
+
|
|
135
|
+
Returns the `StartPage` enum value parsed from the URL, or `null` if not present.
|
|
136
|
+
|
|
137
|
+
#### `getProduct(): Product | null`
|
|
138
|
+
|
|
139
|
+
Returns the `Product` enum value indicating from which x-bees product the integration was opened (e.g. contacts, conversations), or `null` if not specified.
|
|
140
|
+
|
|
141
|
+
---
|
|
142
|
+
|
|
143
|
+
### Environment and platform
|
|
144
|
+
|
|
145
|
+
#### `isPlatformNative(): boolean`
|
|
146
|
+
|
|
147
|
+
Returns `true` when x-bees is running inside a React Native WebView.
|
|
148
|
+
|
|
149
|
+
#### `isPlatformWeb(): boolean`
|
|
150
|
+
|
|
151
|
+
Returns `true` when x-bees is running in a web browser (iFrame).
|
|
152
|
+
|
|
153
|
+
#### `isOpenedFromXBees(): boolean`
|
|
154
|
+
|
|
155
|
+
Returns `true` when the integration is running inside an x-bees iFrame or a React Native WebView. Returns `false` in standalone/dev mode; all `send*` calls will be no-ops in that case.
|
|
156
|
+
|
|
157
|
+
#### `isVisible(): boolean`
|
|
158
|
+
|
|
159
|
+
Returns `true` when the UI iFrame is currently active (visible to the user). Updated automatically via the `VISIBILITY` event.
|
|
160
|
+
|
|
161
|
+
---
|
|
162
|
+
|
|
163
|
+
### UI state and launch mode
|
|
164
|
+
|
|
165
|
+
#### `showsUi(): boolean`
|
|
166
|
+
|
|
167
|
+
Returns `true` for all modes that render UI (`ui`, `d`, `f`). Opposite of `isDataOnly()`.
|
|
168
|
+
|
|
169
|
+
#### `isDataOnly(): boolean`
|
|
170
|
+
|
|
171
|
+
Returns `true` when the integration is launched in `no-ui` or `daemon` mode (no UI rendered).
|
|
172
|
+
|
|
173
|
+
#### `isSetupDialog(): boolean`
|
|
174
|
+
|
|
175
|
+
Returns `true` when the integration is launched in dialog/setup mode (`d` or `dialog`).
|
|
176
|
+
|
|
177
|
+
#### `isFullsize(): boolean`
|
|
178
|
+
|
|
179
|
+
Returns `true` when the integration is launched in fullsize mode (`f`).
|
|
180
|
+
|
|
181
|
+
#### `isActivationOnly(): boolean`
|
|
182
|
+
|
|
183
|
+
Returns `true` when the integration is opened for activation/authorization purposes only (URL contains the `authorize` parameter).
|
|
184
|
+
|
|
185
|
+
---
|
|
186
|
+
|
|
187
|
+
### Context
|
|
188
|
+
|
|
189
|
+
#### `getContext(): Promise<ResponseMessage>`
|
|
190
|
+
|
|
191
|
+
Retrieves the current x-bees context data. The shape of the payload depends on the active context (e.g. contact view, conversation view).
|
|
192
|
+
|
|
193
|
+
#### `getCurrentContact(): Promise<ResponseMessage>`
|
|
194
|
+
|
|
195
|
+
Retrieves the contact data currently open in x-bees.
|
|
196
|
+
|
|
197
|
+
#### `getCurrentConversation(): Promise<ResponseMessage>`
|
|
198
|
+
|
|
199
|
+
Retrieves the conversation data (`{ id, type }`) currently open in x-bees. Resolves with `undefined` payload if the conversation is temporary.
|
|
200
|
+
|
|
201
|
+
#### `getAvailableContactData(): Promise<ResponseMessage>`
|
|
202
|
+
|
|
203
|
+
Retrieves contact data that x-bees has available for the current context (phone numbers, emails, etc.). Useful to pre-populate integration forms.
|
|
204
|
+
|
|
205
|
+
---
|
|
206
|
+
|
|
207
|
+
### Theme
|
|
208
|
+
|
|
209
|
+
#### `getThemeMode(): Promise<ResponseMessage>`
|
|
210
|
+
|
|
211
|
+
Retrieves the current theme mode (`'light'` or `'dark'`).
|
|
212
|
+
|
|
213
|
+
#### `getTheme(): Promise<ResponseMessage>`
|
|
214
|
+
|
|
215
|
+
Retrieves the full theme object including mode and theme options (typography, palette).
|
|
60
216
|
|
|
61
|
-
|
|
217
|
+
#### `onThemeChange(callback: (theme: IPayloadThemeChange) => void): RemoveEventListener`
|
|
62
218
|
|
|
63
|
-
|
|
219
|
+
Starts listening for theme-change events. Invokes `callback` whenever the user changes the x-bees theme. Returns an unsubscribe function.
|
|
64
220
|
|
|
65
|
-
|
|
221
|
+
---
|
|
66
222
|
|
|
67
|
-
|
|
223
|
+
### Token
|
|
68
224
|
|
|
69
|
-
|
|
225
|
+
#### `getXBeesToken(): Promise<ResponseMessage>`
|
|
226
|
+
|
|
227
|
+
Requests the current x-bees authentication token from x-bees. Use this when you need the token for API calls to x-bees services.
|
|
228
|
+
|
|
229
|
+
#### `onPbxTokenChange(callback: (token: string) => void): RemoveEventListener`
|
|
230
|
+
|
|
231
|
+
Starts listening for PBX token change events. Invokes `callback` with the new token value. Returns an unsubscribe function.
|
|
232
|
+
|
|
233
|
+
---
|
|
234
|
+
|
|
235
|
+
### Calls
|
|
236
|
+
|
|
237
|
+
#### `startCall(phoneNumber: string): Promise<ResponseMessage>`
|
|
238
|
+
|
|
239
|
+
Sends a request to x-bees to initiate a call to the given phone number.
|
|
240
|
+
|
|
241
|
+
#### `onCallStarted(callback: (info: IPayloadCallStartedInfo) => void): RemoveEventListener`
|
|
242
|
+
|
|
243
|
+
Starts listening for the event fired when a call starts. Returns an unsubscribe function.
|
|
244
|
+
|
|
245
|
+
#### `onCallEnded(callback: () => void): RemoveEventListener`
|
|
246
|
+
|
|
247
|
+
Starts listening for the event fired when a call ends. Returns an unsubscribe function.
|
|
248
|
+
|
|
249
|
+
---
|
|
250
|
+
|
|
251
|
+
### Contacts
|
|
252
|
+
|
|
253
|
+
#### `contactUpdated(query: ContactQuery, contact: Contact): Promise<ResponseMessage>`
|
|
254
|
+
|
|
255
|
+
Notifies x-bees that a contact was created or updated. `query` identifies the contact (`{ id?, email?, phone? }`); `contact` contains the updated data.
|
|
256
|
+
|
|
257
|
+
#### `contactMatchUpdated(query: ContactQuery, contact: Contact): Promise<ResponseMessage>`
|
|
258
|
+
|
|
259
|
+
Notifies x-bees that a contact match was updated. Used when the integration resolves a contact lookup initiated by x-bees.
|
|
260
|
+
|
|
261
|
+
#### `onSuggestContacts(callback: (query: string, resolve: SuggestContactsResolver, reject: Reject) => void): RemoveEventListener`
|
|
262
|
+
|
|
263
|
+
Starts listening for contact auto-suggest requests from x-bees. When the user types in a contact search field, x-bees calls `callback` with the search string. Call `resolve(contacts)` to return results.
|
|
264
|
+
|
|
265
|
+
```ts
|
|
70
266
|
Client.getInstance().onSuggestContacts(async (query, resolve) => {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
267
|
+
try {
|
|
268
|
+
const contacts = await fetchContacts(query);
|
|
269
|
+
resolve(contacts);
|
|
270
|
+
} catch (error) {
|
|
271
|
+
console.log('catch', error);
|
|
272
|
+
}
|
|
77
273
|
});
|
|
78
274
|
```
|
|
79
275
|
|
|
80
|
-
#### `onLookupAndMatchContact: (
|
|
276
|
+
#### `onLookupAndMatchContact(callback: (query: ContactQuery, resolve: LookupAndMatchContactsResolver, reject: Reject) => void): RemoveEventListener`
|
|
81
277
|
|
|
82
|
-
Starts
|
|
278
|
+
Starts listening for single-contact lookup requests. x-bees supplies a `ContactQuery` and expects a single matched `Contact` via `resolve`.
|
|
83
279
|
|
|
84
|
-
```
|
|
280
|
+
```ts
|
|
85
281
|
Client.getInstance().onLookupAndMatchContact(async (query, resolve) => {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
282
|
+
try {
|
|
283
|
+
const contact = await fetchContactAndMatch(query);
|
|
284
|
+
resolve(contact);
|
|
285
|
+
} catch (error) {
|
|
286
|
+
console.log('catch', error);
|
|
287
|
+
}
|
|
92
288
|
});
|
|
93
289
|
```
|
|
94
290
|
|
|
95
|
-
|
|
96
|
-
#### `getContext(): Promise<Response>`
|
|
291
|
+
#### `onLookupAndMatchBatchContacts(callback: (queries: ContactQuery[], returnResults: LookupAndMatchBatchContactsResolver) => void): RemoveEventListener`
|
|
97
292
|
|
|
98
|
-
|
|
293
|
+
Starts listening for batch contact lookup requests. x-bees sends an array of `ContactQuery` objects. Call `returnResults` with a `Map<ContactQuery, Contact | null | undefined>` mapping each query to its result.
|
|
99
294
|
|
|
100
|
-
|
|
295
|
+
```ts
|
|
296
|
+
Client.getInstance().onLookupAndMatchBatchContacts(async (queries, returnResults) => {
|
|
297
|
+
const resultsMap = new Map<ContactQuery, Contact | null>();
|
|
298
|
+
for (const query of queries) {
|
|
299
|
+
resultsMap.set(query, await fetchContact(query));
|
|
300
|
+
}
|
|
301
|
+
returnResults(resultsMap);
|
|
302
|
+
});
|
|
303
|
+
```
|
|
101
304
|
|
|
102
|
-
|
|
305
|
+
#### `createContactIsSupported(): Promise<ResponseMessage>`
|
|
103
306
|
|
|
104
|
-
|
|
307
|
+
Sends a signal to x-bees indicating that this integration supports creating contacts. Call once during initialization if your integration handles contact creation.
|
|
105
308
|
|
|
106
|
-
|
|
107
|
-
If the conversation is temporary - retrieves undefined
|
|
309
|
+
#### `createContactHasNoPermission(): Promise<ResponseMessage>`
|
|
108
310
|
|
|
109
|
-
|
|
311
|
+
Sends a signal to x-bees indicating that the current user does not have permission to create contacts.
|
|
110
312
|
|
|
111
|
-
|
|
313
|
+
---
|
|
112
314
|
|
|
113
|
-
|
|
315
|
+
### Navigation
|
|
114
316
|
|
|
115
|
-
|
|
317
|
+
#### `onRedirectQuery(callback: Callback<EventType.REDIRECT_QUERY>): RemoveEventListener`
|
|
116
318
|
|
|
117
|
-
|
|
319
|
+
Starts listening for redirect query events. Fires when the user opens the app via a deep-link that targets this integration. Returns an unsubscribe function.
|
|
118
320
|
|
|
119
|
-
|
|
321
|
+
#### `onStartRedirectToEntityPage(callback: Callback<EventType.START_REDIRECT_TO_ENTITY_PAGE>): RemoveEventListener`
|
|
120
322
|
|
|
121
|
-
|
|
323
|
+
Starts listening for the event that signals x-bees is navigating to an entity page (e.g. conversation). The payload contains `{ conversationId, pageName }`. Returns an unsubscribe function.
|
|
122
324
|
|
|
123
|
-
|
|
325
|
+
#### `onCancelRedirectToEntityPage(callback: Callback<EventType.CANCEL_REDIRECT_TO_ENTITY_PAGE>): RemoveEventListener`
|
|
124
326
|
|
|
125
|
-
|
|
327
|
+
Starts listening for the event that signals a pending redirect to an entity page was cancelled. The payload contains `{ conversationId }`. Returns an unsubscribe function.
|
|
126
328
|
|
|
127
|
-
|
|
329
|
+
---
|
|
128
330
|
|
|
129
|
-
|
|
331
|
+
### Visibility and lifecycle
|
|
130
332
|
|
|
131
|
-
|
|
333
|
+
#### `onVisibilityChange(callback: (isVisible: boolean) => void): RemoveEventListener`
|
|
132
334
|
|
|
133
|
-
|
|
335
|
+
Starts listening for iframe visibility changes. `callback` receives `true` when the iFrame becomes active and `false` when it is hidden. Returns an unsubscribe function.
|
|
134
336
|
|
|
135
|
-
|
|
337
|
+
#### `reboot(): Promise<ResponseMessage>`
|
|
136
338
|
|
|
339
|
+
Sends a request to x-bees to restart the iFrame and reload it with the latest parameters and token.
|
|
137
340
|
|
|
138
|
-
|
|
139
|
-
|
|
341
|
+
#### `onLogout(callback: Callback<EventType.LOGOUT>): RemoveEventListener`
|
|
342
|
+
|
|
343
|
+
Starts listening for the logout event. Notifies x-bees that the integration supports logout. `callback` is invoked when x-bees requests a logout action.
|
|
344
|
+
|
|
345
|
+
---
|
|
346
|
+
|
|
347
|
+
### Contact events
|
|
348
|
+
|
|
349
|
+
#### `onContactWeightUpdate(callback: Callback<EventType.CONTACT_WEIGHT_UPDATE>): RemoveEventListener`
|
|
350
|
+
|
|
351
|
+
Starts listening for contact weight update events. Fires when x-bees recalculates the relevance weight of a contact. The payload contains `{ id, query }`. Returns an unsubscribe function.
|
|
352
|
+
|
|
353
|
+
#### `onContactRefresh(callback: Callback<EventType.CONTACT_REFRESH>): RemoveEventListener`
|
|
354
|
+
|
|
355
|
+
Starts listening for contact refresh events. Fires when a contact was updated in the x-bees daemon and the open integration should re-fetch its data. Returns an unsubscribe function.
|
|
356
|
+
|
|
357
|
+
---
|
|
358
|
+
|
|
359
|
+
### UI utilities
|
|
360
|
+
|
|
361
|
+
#### `showToast(message: string, severity?: ToastSeverity): Promise<ResponseMessage>`
|
|
362
|
+
|
|
363
|
+
Displays a toast notification inside the x-bees UI. `severity` defaults to `'INFO'`. Accepted values: `'INFO'`, `'WARNING'`, `'ERROR'`, `'SUCCESS'`, `'NOTICE'`.
|
|
364
|
+
|
|
365
|
+
```ts
|
|
366
|
+
client.showToast('Contact saved', 'SUCCESS');
|
|
367
|
+
```
|
|
368
|
+
|
|
369
|
+
#### `setViewport(payload: { height: number | string; width: number | string }): Promise<ResponseMessage>`
|
|
140
370
|
|
|
141
|
-
|
|
371
|
+
Sends a request to x-bees to resize the iFrame to the specified dimensions.
|
|
142
372
|
|
|
143
|
-
#### `
|
|
373
|
+
#### `toClipboard(payload: string): Promise<ResponseMessage>`
|
|
144
374
|
|
|
145
|
-
Sends a request to x-bees to
|
|
375
|
+
Sends a request to x-bees to write the given string to the user's clipboard.
|
|
146
376
|
|
|
147
|
-
|
|
377
|
+
---
|
|
148
378
|
|
|
149
|
-
|
|
379
|
+
### Event listeners (generic)
|
|
150
380
|
|
|
151
|
-
#### `
|
|
381
|
+
#### `addEventListener<T extends EventType>(eventName: T, callback: Callback<T>): RemoveEventListener`
|
|
152
382
|
|
|
153
|
-
|
|
383
|
+
Starts listening for any x-bees event by name. Returns an unsubscribe function. Prefer the typed convenience methods (`onThemeChange`, `onCallStarted`, etc.) when available.
|
|
154
384
|
|
|
155
|
-
#### `
|
|
385
|
+
#### `removeEventListener<T extends EventType>(eventName: T, callback: Callback<T>): void`
|
|
156
386
|
|
|
157
|
-
|
|
387
|
+
Stops listening for the specified event with the given callback reference.
|
|
388
|
+
|
|
389
|
+
#### `off(callback: Callback | StorageEventCallback): void`
|
|
390
|
+
|
|
391
|
+
Removes the given callback from all event listeners, including local storage listeners registered via `onStorage`.
|
|
392
|
+
|
|
393
|
+
---
|
|
394
|
+
|
|
395
|
+
### Analytics
|
|
396
|
+
|
|
397
|
+
#### `sendAnalytics(eventName: string, params?: Record<string, string>): void`
|
|
398
|
+
|
|
399
|
+
Sends an analytics event to x-bees for tracking. `params` is an optional map of string key-value pairs.
|
|
400
|
+
|
|
401
|
+
```ts
|
|
402
|
+
client.sendAnalytics('contact_viewed', { contactId: '123' });
|
|
403
|
+
```
|
|
404
|
+
|
|
405
|
+
---
|
|
406
|
+
|
|
407
|
+
### Local storage
|
|
408
|
+
|
|
409
|
+
These methods read and write to the browser's `localStorage`, namespaced per integration.
|
|
410
|
+
|
|
411
|
+
#### `saveToStorage<T>(key: string, value: T): void`
|
|
412
|
+
|
|
413
|
+
Saves a value to `localStorage` under the given key. The value is serialized to JSON automatically.
|
|
414
|
+
|
|
415
|
+
#### `getFromStorage<T>(key: string): T | null`
|
|
416
|
+
|
|
417
|
+
Retrieves and deserializes a value from `localStorage`. Returns `null` if the key does not exist.
|
|
418
|
+
|
|
419
|
+
#### `deleteFromStorage(key: string): void`
|
|
420
|
+
|
|
421
|
+
Removes the entry with the given key from `localStorage`.
|
|
422
|
+
|
|
423
|
+
#### `setIntegrationStorageKey(integrationKey: string): void`
|
|
424
|
+
|
|
425
|
+
Switches the localStorage namespace to the specified parent integration key. Use this when the integration inherits storage from a parent integration.
|
|
426
|
+
|
|
427
|
+
#### `onStorage(listener: StorageEventCallback): () => void`
|
|
428
|
+
|
|
429
|
+
Registers a listener for `localStorage` change events (native `StorageEvent`). Returns an unsubscribe function.
|
|
430
|
+
|
|
431
|
+
```ts
|
|
432
|
+
const unsubscribe = client.onStorage((event) => {
|
|
433
|
+
console.log('Storage changed:', event.key, event.newValue);
|
|
434
|
+
});
|
|
435
|
+
```
|
|
436
|
+
|
|
437
|
+
---
|
|
438
|
+
|
|
439
|
+
### x-bees storage
|
|
440
|
+
|
|
441
|
+
These methods persist data in x-bees' own server-side storage, not in the browser's `localStorage`. Data stored here survives browser clears and is available across devices.
|
|
442
|
+
|
|
443
|
+
#### `saveInXbeesStorage<T>(key: string, value: T): void`
|
|
444
|
+
|
|
445
|
+
Saves a value to the x-bees storage. The value is serialized to a JSON string before sending.
|
|
446
|
+
|
|
447
|
+
#### `getFromXbeesStorage(key: string): Promise<ResponseMessage>`
|
|
448
|
+
|
|
449
|
+
Requests a stored value from x-bees storage by key. Resolves with a `ResponseMessage` whose payload contains the stored value.
|
|
450
|
+
|
|
451
|
+
#### `removeFromXbeesStorage(key: string): void`
|
|
452
|
+
|
|
453
|
+
Removes the entry with the given key from x-bees storage.
|
|
454
|
+
|
|
455
|
+
---
|
|
456
|
+
|
|
457
|
+
### Custom events
|
|
458
|
+
|
|
459
|
+
#### `sendCustomEvent({ type: string, payload?: JSONValue }): void`
|
|
460
|
+
|
|
461
|
+
Sends a custom event to x-bees with an arbitrary `type` string and optional JSON-serializable payload. Use this for integration-specific communication not covered by the built-in event types.
|
|
462
|
+
|
|
463
|
+
```ts
|
|
464
|
+
client.sendCustomEvent({ type: 'my_action', payload: { foo: 'bar' } });
|
|
465
|
+
```
|
|
158
466
|
|
|
159
|
-
#### `
|
|
467
|
+
#### `sendDropdownVisibilityEvent(dropdownVisibilityStatus: boolean): void`
|
|
160
468
|
|
|
161
|
-
|
|
469
|
+
> **Legacy:** prefer `sendCustomEvent` for new integrations.
|
|
162
470
|
|
|
163
|
-
|
|
471
|
+
Notifies x-bees when a dropdown inside the integration opens or closes, which allows x-bees to enable nested scrolling on Android WebView.
|
|
164
472
|
|
|
165
|
-
|
|
473
|
+
---
|
|
166
474
|
|
|
167
|
-
|
|
475
|
+
### Technical support
|
|
168
476
|
|
|
169
|
-
|
|
477
|
+
#### `getTechnicalSupport(): TechnicalSupport`
|
|
170
478
|
|
|
171
|
-
|
|
479
|
+
Returns the `TechnicalSupport` singleton, which provides utilities for reporting diagnostic information to x-bees support.
|
|
172
480
|
|
|
173
|
-
|
|
481
|
+
---
|
|
174
482
|
|
|
175
483
|
## Known issues
|
|
176
484
|
|
|
@@ -178,6 +486,6 @@ The below function can fix cases when `String.replaceAll()` does not work in the
|
|
|
178
486
|
|
|
179
487
|
```ts
|
|
180
488
|
function replaceAll(str: string, search: string, replace: string) {
|
|
181
|
-
|
|
489
|
+
return str.split(search).join(replace);
|
|
182
490
|
}
|
|
183
491
|
```
|
package/dist-cjs/index.js
CHANGED
|
@@ -14,13 +14,14 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.UrlParams = exports.StartPage = exports.ClientEventType = exports.EventType = void 0;
|
|
17
|
+
exports.UrlParams = exports.StartPage = exports.Product = exports.ClientEventType = exports.EventType = void 0;
|
|
18
18
|
const Client_1 = require("./src/Client");
|
|
19
19
|
var enums_1 = require("./src/enums");
|
|
20
20
|
Object.defineProperty(exports, "EventType", { enumerable: true, get: function () { return enums_1.EventType; } });
|
|
21
21
|
var enums_2 = require("./src/enums");
|
|
22
22
|
Object.defineProperty(exports, "ClientEventType", { enumerable: true, get: function () { return enums_2.ClientEventType; } });
|
|
23
23
|
var enums_3 = require("./src/enums");
|
|
24
|
+
Object.defineProperty(exports, "Product", { enumerable: true, get: function () { return enums_3.Product; } });
|
|
24
25
|
Object.defineProperty(exports, "StartPage", { enumerable: true, get: function () { return enums_3.StartPage; } });
|
|
25
26
|
Object.defineProperty(exports, "UrlParams", { enumerable: true, get: function () { return enums_3.UrlParams; } });
|
|
26
27
|
__exportStar(require("./types"), exports);
|
package/dist-cjs/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wildix/xbees-connect",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.6",
|
|
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-cjs/src/Client.js
CHANGED
|
@@ -50,6 +50,7 @@ class Client {
|
|
|
50
50
|
iframeId;
|
|
51
51
|
variant = null;
|
|
52
52
|
startPage = null;
|
|
53
|
+
product = null;
|
|
53
54
|
localStorageManager = LocalStorageManager_1.default.getInstance();
|
|
54
55
|
constructor() {
|
|
55
56
|
const params = (0, getUrlSearchParamsMap_1.getUrlSearchParamsMap)();
|
|
@@ -59,6 +60,7 @@ class Client {
|
|
|
59
60
|
this.referrer = params.get(enums_1.UrlParams.REFERRER);
|
|
60
61
|
this.needAuthorize = params.has(enums_1.UrlParams.AUTHORIZE);
|
|
61
62
|
this.startPage = params.get(enums_1.UrlParams.START_PAGE);
|
|
63
|
+
this.product = params.get(enums_1.UrlParams.PRODUCT);
|
|
62
64
|
// @ts-expect-error window.ReactNativeWebView will be provided by ReactNative WebView
|
|
63
65
|
this.isParentReactNativeWebView = !!window.ReactNativeWebView;
|
|
64
66
|
this.worker = this.isParentReactNativeWebView ? new PostMessageControllerNative_1.default() : new PostMessageControllerWeb_1.default();
|
|
@@ -199,6 +201,9 @@ class Client {
|
|
|
199
201
|
getStartPage() {
|
|
200
202
|
return this.startPage;
|
|
201
203
|
}
|
|
204
|
+
getProduct() {
|
|
205
|
+
return this.product;
|
|
206
|
+
}
|
|
202
207
|
isVisible() {
|
|
203
208
|
return this.visible;
|
|
204
209
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.StartPage = exports.UrlParams = exports.ClientEventType = exports.EventType = void 0;
|
|
3
|
+
exports.Product = exports.StartPage = exports.UrlParams = exports.ClientEventType = exports.EventType = void 0;
|
|
4
4
|
var EventType;
|
|
5
5
|
(function (EventType) {
|
|
6
6
|
EventType["GET_CONTACTS_AUTO_SUGGEST"] = "xBeesGetContactsAutoSuggest";
|
|
@@ -67,8 +67,15 @@ var UrlParams;
|
|
|
67
67
|
UrlParams["REFERRER"] = "r";
|
|
68
68
|
UrlParams["AUTHORIZE"] = "a";
|
|
69
69
|
UrlParams["START_PAGE"] = "sp";
|
|
70
|
+
UrlParams["PRODUCT"] = "p";
|
|
70
71
|
})(UrlParams || (exports.UrlParams = UrlParams = {}));
|
|
71
72
|
var StartPage;
|
|
72
73
|
(function (StartPage) {
|
|
73
74
|
StartPage["CREATE_CONTACT"] = "createContact";
|
|
74
75
|
})(StartPage || (exports.StartPage = StartPage = {}));
|
|
76
|
+
var Product;
|
|
77
|
+
(function (Product) {
|
|
78
|
+
Product["XBEES"] = "xbees";
|
|
79
|
+
Product["XHOPPERS"] = "xhoppers";
|
|
80
|
+
Product["COLLABORATION"] = "collaboration";
|
|
81
|
+
})(Product || (exports.Product = Product = {}));
|
|
@@ -18,6 +18,7 @@ class ClientParams {
|
|
|
18
18
|
variant = null;
|
|
19
19
|
userExtension = null;
|
|
20
20
|
startPage = null;
|
|
21
|
+
product = null;
|
|
21
22
|
constructor() {
|
|
22
23
|
const params = (0, getUrlSearchParamsMap_1.getUrlSearchParamsMap)();
|
|
23
24
|
this.iframeId = params.get(enums_1.UrlParams.ID);
|
|
@@ -28,6 +29,7 @@ class ClientParams {
|
|
|
28
29
|
this.referrer = params.get(enums_1.UrlParams.REFERRER);
|
|
29
30
|
this.needAuthorize = params.has(enums_1.UrlParams.AUTHORIZE);
|
|
30
31
|
this.startPage = params.get(enums_1.UrlParams.START_PAGE);
|
|
32
|
+
this.product = params.get(enums_1.UrlParams.PRODUCT);
|
|
31
33
|
}
|
|
32
34
|
toString() {
|
|
33
35
|
const { userToken, ...props } = this;
|
package/dist-es/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Client } from './src/Client';
|
|
2
2
|
export { EventType } from './src/enums';
|
|
3
3
|
export { ClientEventType } from './src/enums';
|
|
4
|
-
export { StartPage, UrlParams } from './src/enums';
|
|
4
|
+
export { Product, StartPage, UrlParams } from './src/enums';
|
|
5
5
|
export * from './types';
|
|
6
6
|
export default Client;
|
package/dist-es/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wildix/xbees-connect",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.6",
|
|
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
|
@@ -44,6 +44,7 @@ export class Client {
|
|
|
44
44
|
iframeId;
|
|
45
45
|
variant = null;
|
|
46
46
|
startPage = null;
|
|
47
|
+
product = null;
|
|
47
48
|
localStorageManager = LocalStorageManager.getInstance();
|
|
48
49
|
constructor() {
|
|
49
50
|
const params = getUrlSearchParamsMap();
|
|
@@ -53,6 +54,7 @@ export class Client {
|
|
|
53
54
|
this.referrer = params.get(UrlParams.REFERRER);
|
|
54
55
|
this.needAuthorize = params.has(UrlParams.AUTHORIZE);
|
|
55
56
|
this.startPage = params.get(UrlParams.START_PAGE);
|
|
57
|
+
this.product = params.get(UrlParams.PRODUCT);
|
|
56
58
|
// @ts-expect-error window.ReactNativeWebView will be provided by ReactNative WebView
|
|
57
59
|
this.isParentReactNativeWebView = !!window.ReactNativeWebView;
|
|
58
60
|
this.worker = this.isParentReactNativeWebView ? new PostMessageControllerNative() : new PostMessageControllerWeb();
|
|
@@ -193,6 +195,9 @@ export class Client {
|
|
|
193
195
|
getStartPage() {
|
|
194
196
|
return this.startPage;
|
|
195
197
|
}
|
|
198
|
+
getProduct() {
|
|
199
|
+
return this.product;
|
|
200
|
+
}
|
|
196
201
|
isVisible() {
|
|
197
202
|
return this.visible;
|
|
198
203
|
}
|
|
@@ -64,8 +64,15 @@ export var UrlParams;
|
|
|
64
64
|
UrlParams["REFERRER"] = "r";
|
|
65
65
|
UrlParams["AUTHORIZE"] = "a";
|
|
66
66
|
UrlParams["START_PAGE"] = "sp";
|
|
67
|
+
UrlParams["PRODUCT"] = "p";
|
|
67
68
|
})(UrlParams || (UrlParams = {}));
|
|
68
69
|
export var StartPage;
|
|
69
70
|
(function (StartPage) {
|
|
70
71
|
StartPage["CREATE_CONTACT"] = "createContact";
|
|
71
72
|
})(StartPage || (StartPage = {}));
|
|
73
|
+
export var Product;
|
|
74
|
+
(function (Product) {
|
|
75
|
+
Product["XBEES"] = "xbees";
|
|
76
|
+
Product["XHOPPERS"] = "xhoppers";
|
|
77
|
+
Product["COLLABORATION"] = "collaboration";
|
|
78
|
+
})(Product || (Product = {}));
|
|
@@ -16,6 +16,7 @@ export default class ClientParams {
|
|
|
16
16
|
variant = null;
|
|
17
17
|
userExtension = null;
|
|
18
18
|
startPage = null;
|
|
19
|
+
product = null;
|
|
19
20
|
constructor() {
|
|
20
21
|
const params = getUrlSearchParamsMap();
|
|
21
22
|
this.iframeId = params.get(UrlParams.ID);
|
|
@@ -26,6 +27,7 @@ export default class ClientParams {
|
|
|
26
27
|
this.referrer = params.get(UrlParams.REFERRER);
|
|
27
28
|
this.needAuthorize = params.has(UrlParams.AUTHORIZE);
|
|
28
29
|
this.startPage = params.get(UrlParams.START_PAGE);
|
|
30
|
+
this.product = params.get(UrlParams.PRODUCT);
|
|
29
31
|
}
|
|
30
32
|
toString() {
|
|
31
33
|
const { userToken, ...props } = this;
|
package/dist-types/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Client } from './src/Client';
|
|
2
2
|
export { EventType } from './src/enums';
|
|
3
3
|
export { ClientEventType } from './src/enums';
|
|
4
|
-
export { StartPage, UrlParams } from './src/enums';
|
|
4
|
+
export { Product, StartPage, UrlParams } from './src/enums';
|
|
5
5
|
export * from './types';
|
|
6
6
|
export default Client;
|
|
@@ -2,7 +2,7 @@ import { Callback, ConnectClient, Contact, ContactQuery, IPayloadViewPort, Looku
|
|
|
2
2
|
import { ReadyExtendedProps } from '../types/Event';
|
|
3
3
|
import { JSONValue } from '../types/Json';
|
|
4
4
|
import { LookupAndMatchBatchContactsResolver } from '../types/Resolver';
|
|
5
|
-
import { ClientEventType, EventType, StartPage } from './enums';
|
|
5
|
+
import { ClientEventType, EventType, Product, StartPage } from './enums';
|
|
6
6
|
import TechnicalSupport from './helpers/TechnicalSupport';
|
|
7
7
|
/**
|
|
8
8
|
* Client provides functionality of communication between xBees and integrated web applications via iFrame or ReactNative WebView
|
|
@@ -27,6 +27,7 @@ export declare class Client implements ConnectClient {
|
|
|
27
27
|
private readonly iframeId;
|
|
28
28
|
private readonly variant;
|
|
29
29
|
private readonly startPage;
|
|
30
|
+
private readonly product;
|
|
30
31
|
private readonly localStorageManager;
|
|
31
32
|
constructor();
|
|
32
33
|
private sendAsync;
|
|
@@ -56,6 +57,7 @@ export declare class Client implements ConnectClient {
|
|
|
56
57
|
getUserExtension(): string | null;
|
|
57
58
|
getReferrer(): string;
|
|
58
59
|
getStartPage(): StartPage | null;
|
|
60
|
+
getProduct(): Product | null;
|
|
59
61
|
isVisible(): boolean;
|
|
60
62
|
getBackToAppUrl(): string;
|
|
61
63
|
isDataOnly(): boolean;
|
|
@@ -60,8 +60,14 @@ export declare enum UrlParams {
|
|
|
60
60
|
EXTENSION = "e",
|
|
61
61
|
REFERRER = "r",
|
|
62
62
|
AUTHORIZE = "a",
|
|
63
|
-
START_PAGE = "sp"
|
|
63
|
+
START_PAGE = "sp",
|
|
64
|
+
PRODUCT = "p"
|
|
64
65
|
}
|
|
65
66
|
export declare enum StartPage {
|
|
66
67
|
CREATE_CONTACT = "createContact"
|
|
67
68
|
}
|
|
69
|
+
export declare enum Product {
|
|
70
|
+
XBEES = "xbees",
|
|
71
|
+
XHOPPERS = "xhoppers",
|
|
72
|
+
COLLABORATION = "collaboration"
|
|
73
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { WorkVariants } from '../../types';
|
|
2
|
-
import { StartPage } from '../enums';
|
|
2
|
+
import { Product, StartPage } from '../enums';
|
|
3
3
|
export default class ClientParams {
|
|
4
4
|
private static instance;
|
|
5
5
|
static getInstance(): ClientParams;
|
|
@@ -11,6 +11,7 @@ export default class ClientParams {
|
|
|
11
11
|
readonly variant: WorkVariants | null;
|
|
12
12
|
readonly userExtension: string | null;
|
|
13
13
|
readonly startPage: StartPage | null;
|
|
14
|
+
readonly product: Product | null;
|
|
14
15
|
constructor();
|
|
15
16
|
toString(): string;
|
|
16
17
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ClientEventType, EventType, StartPage } from '../src/enums';
|
|
1
|
+
import { ClientEventType, EventType, Product, StartPage } from '../src/enums';
|
|
2
2
|
import TechnicalSupport from '../src/helpers/TechnicalSupport';
|
|
3
3
|
import { Callback } from './Callback';
|
|
4
4
|
import { Contact, ContactQuery } from './Contact';
|
|
@@ -40,6 +40,9 @@ export interface ConnectClient {
|
|
|
40
40
|
/**
|
|
41
41
|
* Retrieves start page from url */
|
|
42
42
|
getStartPage: () => StartPage | null;
|
|
43
|
+
/**
|
|
44
|
+
* Retrieves the product type from which the integration is opened */
|
|
45
|
+
getProduct: () => Product | null;
|
|
43
46
|
/**
|
|
44
47
|
* Retrieves the version of xBeesConnect */
|
|
45
48
|
version: () => string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wildix/xbees-connect",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.7",
|
|
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": "",
|