@viibe/impulse-integration-js 2.3.11 → 2.4.0

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/src/index.js CHANGED
@@ -81,15 +81,15 @@ function openAuthPopup(src) {
81
81
  // events from auth.viibe.tech
82
82
  if (event.data && event.data.event && event.data.payload) {
83
83
  switch (event.data.event) {
84
- case 'authentication:success':
85
- destroy();
84
+ case 'authentication:success':
85
+ destroy();
86
86
 
87
- return resolve(event.data);
88
- case 'authentication:failure':
89
- destroy();
87
+ return resolve(event.data);
88
+ case 'authentication:failure':
89
+ destroy();
90
90
 
91
- return reject(event.data);
92
- default:
91
+ return reject(event.data);
92
+ default:
93
93
 
94
94
  }
95
95
 
@@ -177,7 +177,9 @@ class Viibe {
177
177
  throw new Error('fillSource');
178
178
  }
179
179
 
180
- const src = this.generateIframeSrc(options);
180
+ // eslint-no-unused-vars
181
+ const { token, ...params } = options;
182
+ const src = this.generateIframeSrc(params);
181
183
 
182
184
  const iframe = document.createElement('iframe');
183
185
 
@@ -191,79 +193,81 @@ class Viibe {
191
193
  return iframe;
192
194
  }
193
195
 
194
- generateIframeSrc(options = {}) {
196
+ generateIframeSrc(params = {}) {
195
197
  const {
196
198
  clipboard = false,
197
199
  components,
198
200
  links,
199
201
  o2m = false,
200
202
  ticket,
201
- token,
202
203
  locale,
203
204
  standalone,
204
205
  suggestions,
205
- } = options;
206
+ } = params;
206
207
 
207
208
  let src = `${this.origin}/integration/features/ticket`;
208
209
 
209
- const params = new URLSearchParams({
210
+ const urlParams = new URLSearchParams({
210
211
  origin: document.location.origin,
211
212
  resize: 'true',
212
213
  source: this.source,
213
214
  });
214
215
 
215
216
  if (ticket && ticket.title) {
216
- params.set('title', ticket.title);
217
+ urlParams.set('title', ticket.title);
217
218
  }
218
219
 
219
220
  if (ticket && ticket.integration) {
220
- params.set('thirdPartyId', ticket.integration.id);
221
+ urlParams.set('thirdPartyId', ticket.integration.id);
222
+
223
+ const { entUuid } = ticket.integration.customData || {}
224
+ if (entUuid) urlParams.set('entUuid', entUuid)
221
225
  }
222
226
 
223
227
  if (links) {
224
228
  const linksParams = (links instanceof Array)
225
- ? links.map(link => `${link.category}:${link.value}`).join(',')
226
- : String(links);
229
+ ? links.map(link => `${link.category}:${link.value}`).join(',')
230
+ : String(links);
227
231
 
228
- params.set('links', linksParams);
232
+ urlParams.set('links', linksParams);
229
233
  }
230
234
 
231
235
  if (suggestions) {
232
236
  const suggestionsParams = (suggestions instanceof Array)
233
- ? suggestions.map(({ category, value, description }) => {
234
- let res = `${category}:${value}`
235
- if (description) res += `:${description}`
236
- return res
237
- }).join(',')
238
- : String(suggestions);
239
-
240
- params.set('suggestions', suggestionsParams);
241
- }
242
-
243
- if (token) {
244
- params.set('token', token);
237
+ ? suggestions.map(({ category, value, description }) => {
238
+ let res = `${category}:${value}`;
239
+
240
+ if (description) {
241
+ res += `:${description}`;
242
+ }
243
+
244
+ return res;
245
+ }).join(',')
246
+ : String(suggestions);
247
+
248
+ urlParams.set('suggestions', suggestionsParams);
245
249
  }
246
250
 
247
251
  if (locale) {
248
- params.set('locale', locale);
252
+ urlParams.set('locale', locale);
249
253
  }
250
254
 
251
255
  if (components) {
252
256
  const componentsParams = (components instanceof Array)
253
- ? components.join(',')
254
- : String(components);
257
+ ? components.join(',')
258
+ : String(components);
255
259
 
256
- params.set('components', componentsParams);
260
+ urlParams.set('components', componentsParams);
257
261
  }
258
262
 
259
263
  if (standalone) {
260
- params.set('standalone', Boolean(standalone));
264
+ urlParams.set('standalone', Boolean(standalone));
261
265
  }
262
266
 
263
- params.set('clipboard', Boolean(clipboard));
264
- params.set('o2m', Boolean(o2m));
267
+ urlParams.set('clipboard', Boolean(clipboard));
268
+ urlParams.set('o2m', Boolean(o2m));
265
269
 
266
- src += `?${params}`;
270
+ src += `?${urlParams}`;
267
271
 
268
272
  return src;
269
273
  }
@@ -275,16 +279,14 @@ class Viibe {
275
279
  *
276
280
  * @param {string} eventName
277
281
  * @param {any} payload
282
+ * @param {any} event
278
283
  * @param {string} windowName
279
284
  * @returns
280
285
  */
281
- dispatch(eventName, payload, windowName) {
286
+ dispatch(eventName, payload, event, windowName) {
282
287
  return this.handlers
283
- .filter(handler =>
284
- handler.eventName === eventName &&
285
- (!handler.windowName || (handler.windowName === windowName)),
286
- )
287
- .map(handler => handler.func(payload));
288
+ .filter(handler => handler.eventName === eventName && (!handler.windowName || (handler.windowName === windowName)))
289
+ .map(handler => handler.func(payload, event));
288
290
  }
289
291
 
290
292
  /**
@@ -297,17 +299,17 @@ class Viibe {
297
299
  return null;
298
300
  }
299
301
 
300
- if (event.data && event.data.event && event.data.payload) {
301
- return this.dispatch(event.data.event, event.data.payload, event.data.windowName);
302
+ if (event.data && event.data.event) {
303
+ return this.dispatch(event.data.event, event.data.payload, event, event.data.windowName);
302
304
  }
303
305
 
304
306
  // FIXME: legacy authentication messages
305
307
  if (event.data && event.data.token) {
306
- return this.dispatch('authentication:token', event.data.token);
308
+ return this.dispatch('authentication:token', event.data.token, event);
307
309
  }
308
310
 
309
311
  if (event.data && event.data.error) {
310
- return this.dispatch('authentication:error', event.data.error);
312
+ return this.dispatch('authentication:error', event.data.error, event);
311
313
  }
312
314
 
313
315
  return null;
package/test/dist.test.js CHANGED
@@ -2,6 +2,7 @@
2
2
  * @jest-environment jsdom
3
3
  */
4
4
 
5
+ // eslint-disable-next-line node/no-missing-require
5
6
  const Viibe = require('../dist');
6
7
 
7
8
  describe('dist', () => {
@@ -18,7 +19,7 @@ describe('dist', () => {
18
19
  expect(() => viibe.createCallIframe()).toThrow('fillHost');
19
20
 
20
21
  const viibeWithHost = new Viibe({
21
- host: 'clement.viibe.tech',
22
+ host: 'praxedo-qa.viibe.tech',
22
23
  });
23
24
 
24
25
  expect(() => viibeWithHost.createNotificationIframe()).toThrow('fillSource');
@@ -27,13 +28,13 @@ describe('dist', () => {
27
28
 
28
29
  test('constructor', () => {
29
30
  const viibe = new Viibe({
30
- host: 'clement.viibe.tech',
31
+ host: 'praxedo-qa.viibe.tech',
31
32
  source: 'jest',
32
33
  });
33
34
 
34
- expect(viibe.host).toBe('clement.viibe.tech');
35
+ expect(viibe.host).toBe('praxedo-qa.viibe.tech');
35
36
  expect(viibe.source).toBe('jest');
36
- expect(viibe.origin).toBe('https://clement.viibe.tech');
37
+ expect(viibe.origin).toBe('https://praxedo-qa.viibe.tech');
37
38
 
38
39
  const viibeLocalhost = new Viibe({
39
40
  host: 'localhost:6666',
@@ -44,7 +45,7 @@ describe('dist', () => {
44
45
 
45
46
  test('createNotificationIframe', () => {
46
47
  const viibe = new Viibe({
47
- host: 'clement.viibe.tech',
48
+ host: 'praxedo-qa.viibe.tech',
48
49
  source: 'jest',
49
50
  });
50
51
  const iframe = viibe.createNotificationIframe();
@@ -53,16 +54,15 @@ describe('dist', () => {
53
54
  expect(iframe.name).toMatch(/^viibe-[0-9]{1,4}$/);
54
55
  expect(iframe.style.border).toBe('0px');
55
56
  expect(iframe.style.width).toBe('0px');
56
- expect(iframe.src).toBe('https://clement.viibe.tech/integration/features/notifications');
57
+ expect(iframe.src).toBe('https://praxedo-qa.viibe.tech/integration/features/notifications');
57
58
  });
58
59
 
59
60
  test('createCallIframe', () => {
60
61
  const viibe = new Viibe({
61
- host: 'clement.viibe.tech',
62
+ host: 'praxedo-qa.viibe.tech',
62
63
  source: 'jest',
63
64
  });
64
65
  const iframe = viibe.createCallIframe();
65
- //const callUrl = viibe.createCallUrl();
66
66
 
67
67
  expect(iframe).toBeInstanceOf(HTMLIFrameElement);
68
68
  expect(iframe.name).toMatch(/^viibe-[0-9]{1,4}$/);
@@ -70,6 +70,5 @@ describe('dist', () => {
70
70
  expect(iframe.style.border).toBe('0px');
71
71
  expect(iframe.style.margin).toBe('0.5rem');
72
72
  expect(iframe.style.width).toBe('calc(100% - 1rem)');
73
- //expect(iframe.src).toEqual(callUrl);
74
73
  });
75
74
  });