@viibe/impulse-integration-js 2.3.10 → 2.3.12

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
@@ -62,6 +62,27 @@ The contact itself;
62
62
  - for `phone` category, should be a full phone number (including national prefix)
63
63
  - for `expertise` category, should be an `id_expertise`
64
64
 
65
+ `suggestions[]` **(array, optional)**
66
+
67
+ A list of suggested contacts to call.
68
+ Each item is an object with the following format:
69
+
70
+ `category` **(string, mandatory)**
71
+
72
+ The type of contact (`email` or `phone`)
73
+
74
+ `value` **(string, mandatory)**
75
+
76
+ The contact itself;
77
+
78
+ - for `email` category, should be a valid email
79
+ - for `phone` category, should be a full phone number (including national prefix)
80
+
81
+ `description` **(string, optional)**
82
+
83
+ An optional text to add information about the contact (his name for example).
84
+ Displayed between brackets after the `value` field.
85
+
65
86
  `ticket`
66
87
 
67
88
  Represents the host application entity the call will be attached to. Viibe calls should typically be attached to a ticket, conversation or issue within the host application
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- (()=>{var t={579:t=>{function n(t,n){if(!(t instanceof n))throw new TypeError("Cannot call a class as a function")}function e(t,n){for(var e=0;e<n.length;e++){var o=n[e];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,o.key,o)}}function o(t,n,o){return n&&e(t.prototype,n),o&&e(t,o),t}function i(t){return function(n){return Boolean(n.isTrusted&&0===n.origin.indexOf(t))}}function a(t){var n=new URL(t),e="".concat(n.protocol,"//").concat(n.host),o=window.screen.width/2-240,a=window.screen.height/2-300,r=["toolbar=no","location=no","directories=no","status=no","menubar=no","scrollbars=no","resizable=no","copyhistory=no","width=".concat(480),"height=".concat(600),"top=".concat(a),"left=".concat(o)];return new Promise((function(n,o){var a=window.open(t,"Authorization",r.join(", "));a||o("Failed to open window");var c=setInterval((function(){a.closed&&(s(),o("User closed window"))}),100);function s(){window.removeEventListener("message",u),clearInterval(c)}function u(t){if(!i(e)(t))return null;if(t.data.token&&(s(),n(t.data.token)),t.data.error&&(s(),o(t.data.error)),t.data&&t.data.event&&t.data.payload)switch(t.data.event){case"authentication:success":return s(),n(t.data);case"authentication:failure":return s(),o(t.data)}return null}window.addEventListener("message",u)}))}var r="auth.viibe.pro",c=1e4,s=function(){function t(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:r;n(this,t),this.host=e}return o(t,[{key:"loginZendesk",value:function(t){var n=document.location.origin;return a("https://".concat(this.host,"/auth/zendesk/login?subdomain=").concat(t,"&origin=").concat(n))}}]),t}(),u=function(){function t(e){n(this,t),this.handlers=[],this.host=e.host,this.origin=/^localhost/.test(this.host)?"http://".concat(this.host):"https://".concat(this.host),this.apiOrigin=/^localhost/.test(this.host)?"http://".concat(this.host):"https://api-".concat(this.host),this.source=e.source,this.isViibeEvent=i(this.origin),window.addEventListener("message",this.onMessage.bind(this))}return o(t,[{key:"createNotificationIframe",value:function(){if(!this.host)throw new Error("fillHost");if(!this.source)throw new Error("fillSource");var t=document.createElement("iframe");return t.name="viibe-".concat(Math.floor(Math.random()*c)),t.style="border: 0;width: 0;",t.src="".concat(this.origin,"/integration/features/notifications"),t}},{key:"createCallIframe",value:function(){var t=this,n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if(!this.host)throw new Error("fillHost");if(!this.source)throw new Error("fillSource");var e=this.generateIframeSrc(n),o=document.createElement("iframe");return o.name="viibe-".concat(Math.floor(Math.random()*c)),o.style="border: 0;width: calc(100% - 1rem);margin: 0.5rem;",o.src=e,o.allow="geolocation;autoplay;microphone;camera;midi;encrypted-media;clipboard-write;",this.on(o,"document",(function(n){return t.onDocument(n)})),o}},{key:"generateIframeSrc",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=t.clipboard,e=void 0!==n&&n,o=t.components,i=t.links,a=t.o2m,r=void 0!==a&&a,c=t.ticket,s=t.token,u=t.locale,l=t.standalone,h=t.suggestions,d="".concat(this.origin,"/integration/features/ticket"),f=new URLSearchParams({origin:document.location.origin,resize:"true",source:this.source});if(c&&c.title&&f.set("title",c.title),c&&c.integration&&f.set("thirdPartyId",c.integration.id),i){var v=i instanceof Array?i.map((function(t){return"".concat(t.category,":").concat(t.value)})).join(","):String(i);f.set("links",v)}if(h){var m=h instanceof Array?h.map((function(t){var n=t.category,e=t.value,o=t.description,i="".concat(n,":").concat(e);return o&&(i+=":".concat(o)),i})).join(","):String(h);f.set("suggestions",m)}if(s&&f.set("token",s),u&&f.set("locale",u),o){var w=o instanceof Array?o.join(","):String(o);f.set("components",w)}return l&&f.set("standalone",Boolean(l)),f.set("clipboard",Boolean(e)),f.set("o2m",Boolean(r)),d+"?".concat(f)}},{key:"dispatch",value:function(t,n,e){return this.handlers.filter((function(n){return n.eventName===t&&(!n.windowName||n.windowName===e)})).map((function(t){return t.func(n)}))}},{key:"onMessage",value:function(t){return this.isViibeEvent(t)?t.data&&t.data.event&&t.data.payload?this.dispatch(t.data.event,t.data.payload,t.data.windowName):t.data&&t.data.token?this.dispatch("authentication:token",t.data.token):t.data&&t.data.error?this.dispatch("authentication:error",t.data.error):null:null}},{key:"on",value:function(t,n,e){"string"==typeof t&&"function"==typeof n&&void 0===e&&(e=n,n=t,t=null);var o={eventName:n,func:e,windowName:t?t.name:null};this.handlers.push(o)}},{key:"onDocument",value:function(t){window.open(t.signed_url,"_blank")}},{key:"authenticate",value:function(t){var n=document.location,e=n.protocol,o=n.host;return a("".concat(e,"//api-").concat(o,"/auth/login/").concat(t,"?origin=").concat(origin))}}]),t}();u.Auth=s,"undefined"!=typeof window&&(window.Viibe=u),t.exports=u}},n={},e=function e(o){var i=n[o];if(void 0!==i)return i.exports;var a=n[o]={exports:{}};return t[o](a,a.exports,e),a.exports}(579);module.exports=e})();
1
+ (()=>{var t={579:t=>{var n=["token"];function e(t,n){if(!(t instanceof n))throw new TypeError("Cannot call a class as a function")}function o(t,n){for(var e=0;e<n.length;e++){var o=n[e];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,o.key,o)}}function i(t,n,e){return n&&o(t.prototype,n),e&&o(t,e),t}function r(t){return function(n){return Boolean(n.isTrusted&&0===n.origin.indexOf(t))}}function a(t){var n=new URL(t),e="".concat(n.protocol,"//").concat(n.host),o=window.screen.width/2-240,i=window.screen.height/2-300,a=["toolbar=no","location=no","directories=no","status=no","menubar=no","scrollbars=no","resizable=no","copyhistory=no","width=".concat(480),"height=".concat(600),"top=".concat(i),"left=".concat(o)];return new Promise((function(n,o){var i=window.open(t,"Authorization",a.join(", "));i||o("Failed to open window");var c=setInterval((function(){i.closed&&(s(),o("User closed window"))}),100);function s(){window.removeEventListener("message",u),clearInterval(c)}function u(t){if(!r(e)(t))return null;if(t.data.token&&(s(),n(t.data.token)),t.data.error&&(s(),o(t.data.error)),t.data&&t.data.event&&t.data.payload)switch(t.data.event){case"authentication:success":return s(),n(t.data);case"authentication:failure":return s(),o(t.data)}return null}window.addEventListener("message",u)}))}var c=function(){function t(){var n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"auth.viibe.pro";e(this,t),this.host=n}return i(t,[{key:"loginZendesk",value:function(t){var n=document.location.origin;return a("https://".concat(this.host,"/auth/zendesk/login?subdomain=").concat(t,"&origin=").concat(n))}}]),t}(),s=function(){function t(n){e(this,t),this.handlers=[],this.host=n.host,this.origin=/^localhost/.test(this.host)?"http://".concat(this.host):"https://".concat(this.host),this.apiOrigin=/^localhost/.test(this.host)?"http://".concat(this.host):"https://api-".concat(this.host),this.source=n.source,this.isViibeEvent=r(this.origin),window.addEventListener("message",this.onMessage.bind(this))}return i(t,[{key:"createNotificationIframe",value:function(){if(!this.host)throw new Error("fillHost");if(!this.source)throw new Error("fillSource");var t=document.createElement("iframe");return t.name="viibe-".concat(Math.floor(1e4*Math.random())),t.style="border: 0;width: 0;",t.src="".concat(this.origin,"/integration/features/notifications"),t}},{key:"createCallIframe",value:function(){var t=this,e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if(!this.host)throw new Error("fillHost");if(!this.source)throw new Error("fillSource");e.token;var o=function(t,n){if(null==t)return{};var e,o,i=function(t,n){if(null==t)return{};var e,o,i={},r=Object.keys(t);for(o=0;o<r.length;o++)e=r[o],n.indexOf(e)>=0||(i[e]=t[e]);return i}(t,n);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);for(o=0;o<r.length;o++)e=r[o],n.indexOf(e)>=0||Object.prototype.propertyIsEnumerable.call(t,e)&&(i[e]=t[e])}return i}(e,n),i=this.generateIframeSrc(o),r=document.createElement("iframe");return r.name="viibe-".concat(Math.floor(1e4*Math.random())),r.style="border: 0;width: calc(100% - 1rem);margin: 0.5rem;",r.src=i,r.allow="geolocation;autoplay;microphone;camera;midi;encrypted-media;clipboard-write;",this.on(r,"document",(function(n){return t.onDocument(n)})),r}},{key:"generateIframeSrc",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=t.clipboard,e=void 0!==n&&n,o=t.components,i=t.links,r=t.o2m,a=void 0!==r&&r,c=t.ticket,s=(t.token,t.locale),u=t.standalone,l=t.suggestions,h="".concat(this.origin,"/integration/features/ticket"),d=new URLSearchParams({origin:document.location.origin,resize:"true",source:this.source});if(c&&c.title&&d.set("title",c.title),c&&c.integration&&d.set("thirdPartyId",c.integration.id),i){var f=i instanceof Array?i.map((function(t){return"".concat(t.category,":").concat(t.value)})).join(","):String(i);d.set("links",f)}if(l){var v=l instanceof Array?l.map((function(t){var n=t.category,e=t.value,o=t.description,i="".concat(n,":").concat(e);return o&&(i+=":".concat(o)),i})).join(","):String(l);d.set("suggestions",v)}if(s&&d.set("locale",s),o){var m=o instanceof Array?o.join(","):String(o);d.set("components",m)}return u&&d.set("standalone",Boolean(u)),d.set("clipboard",Boolean(e)),d.set("o2m",Boolean(a)),h+"?".concat(d)}},{key:"dispatch",value:function(t,n,e,o){return this.handlers.filter((function(n){return n.eventName===t&&(!n.windowName||n.windowName===o)})).map((function(t){return t.func(n,e)}))}},{key:"onMessage",value:function(t){return this.isViibeEvent(t)?t.data&&t.data.event?this.dispatch(t.data.event,t.data.payload,t,t.data.windowName):t.data&&t.data.token?this.dispatch("authentication:token",t.data.token,t):t.data&&t.data.error?this.dispatch("authentication:error",t.data.error,t):null:null}},{key:"on",value:function(t,n,e){"string"==typeof t&&"function"==typeof n&&void 0===e&&(e=n,n=t,t=null);var o={eventName:n,func:e,windowName:t?t.name:null};this.handlers.push(o)}},{key:"onDocument",value:function(t){window.open(t.signed_url,"_blank")}},{key:"authenticate",value:function(t){var n=document.location,e=n.protocol,o=n.host;return a("".concat(e,"//api-").concat(o,"/auth/login/").concat(t,"?origin=").concat(origin))}}]),t}();s.Auth=c,"undefined"!=typeof window&&(window.Viibe=s),t.exports=s}},n={},e=function e(o){var i=n[o];if(void 0!==i)return i.exports;var r=n[o]={exports:{}};return t[o](r,r.exports,e),r.exports}(579);module.exports=e})();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@viibe/impulse-integration-js",
3
- "version": "2.3.10",
3
+ "version": "2.3.12",
4
4
  "engines": {
5
5
  "node": ">= 10.0.0"
6
6
  },
@@ -25,7 +25,7 @@
25
25
  "core-js": "^3.18.2",
26
26
  "jest": "^28.1.1",
27
27
  "jest-environment-jsdom": "^28.1.1",
28
- "webpack": "^5.58.1",
28
+ "webpack": "5.82.0",
29
29
  "webpack-cli": "^4.9.0"
30
30
  }
31
31
  }
package/src/index.js CHANGED
@@ -83,18 +83,18 @@ function openAuthPopup(src) {
83
83
  switch (event.data.event) {
84
84
  case 'authentication:success':
85
85
  destroy();
86
-
86
+
87
87
  return resolve(event.data);
88
88
  case 'authentication:failure':
89
89
  destroy();
90
-
90
+
91
91
  return reject(event.data);
92
92
  default:
93
-
93
+
94
94
  }
95
-
95
+
96
96
  }
97
-
97
+
98
98
  return null;
99
99
  }
100
100
 
@@ -114,7 +114,7 @@ class ViibeAuth {
114
114
  loginZendesk(subdomain) {
115
115
  const { origin } = document.location;
116
116
  const url = `https://${this.host}/auth/zendesk/login?subdomain=${subdomain}&origin=${origin}`;
117
-
117
+
118
118
  return openAuthPopup(url);
119
119
  }
120
120
  }
@@ -164,7 +164,7 @@ class Viibe {
164
164
  iframe.name = `viibe-${Math.floor(Math.random() * IFRAME_NAME_RANGE)}`;
165
165
  iframe.style = 'border: 0;width: 0;';
166
166
  iframe.src = `${this.origin}/integration/features/notifications`;
167
-
167
+
168
168
  return iframe;
169
169
  }
170
170
 
@@ -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,33 +193,32 @@ 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);
221
222
  }
222
223
 
223
224
  if (links) {
@@ -225,27 +226,27 @@ class Viibe {
225
226
  ? links.map(link => `${link.category}:${link.value}`).join(',')
226
227
  : String(links);
227
228
 
228
- params.set('links', linksParams);
229
+ urlParams.set('links', linksParams);
229
230
  }
230
231
 
231
232
  if (suggestions) {
232
233
  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
- }
234
+ ? suggestions.map(({ category, value, description }) => {
235
+ let res = `${category}:${value}`;
242
236
 
243
- if (token) {
244
- params.set('token', token);
237
+ if (description) {
238
+ res += `:${description}`;
239
+ }
240
+
241
+ return res;
242
+ }).join(',')
243
+ : String(suggestions);
244
+
245
+ urlParams.set('suggestions', suggestionsParams);
245
246
  }
246
247
 
247
248
  if (locale) {
248
- params.set('locale', locale);
249
+ urlParams.set('locale', locale);
249
250
  }
250
251
 
251
252
  if (components) {
@@ -253,17 +254,17 @@ class Viibe {
253
254
  ? components.join(',')
254
255
  : String(components);
255
256
 
256
- params.set('components', componentsParams);
257
+ urlParams.set('components', componentsParams);
257
258
  }
258
259
 
259
260
  if (standalone) {
260
- params.set('standalone', Boolean(standalone));
261
+ urlParams.set('standalone', Boolean(standalone));
261
262
  }
262
263
 
263
- params.set('clipboard', Boolean(clipboard));
264
- params.set('o2m', Boolean(o2m));
264
+ urlParams.set('clipboard', Boolean(clipboard));
265
+ urlParams.set('o2m', Boolean(o2m));
265
266
 
266
- src += `?${params}`;
267
+ src += `?${urlParams}`;
267
268
 
268
269
  return src;
269
270
  }
@@ -275,16 +276,14 @@ class Viibe {
275
276
  *
276
277
  * @param {string} eventName
277
278
  * @param {any} payload
279
+ * @param {any} event
278
280
  * @param {string} windowName
279
281
  * @returns
280
282
  */
281
- dispatch(eventName, payload, windowName) {
283
+ dispatch(eventName, payload, event, windowName) {
282
284
  return this.handlers
283
- .filter(handler =>
284
- handler.eventName === eventName &&
285
- (!handler.windowName || (handler.windowName === windowName)),
286
- )
287
- .map(handler => handler.func(payload));
285
+ .filter(handler => handler.eventName === eventName && (!handler.windowName || (handler.windowName === windowName)))
286
+ .map(handler => handler.func(payload, event));
288
287
  }
289
288
 
290
289
  /**
@@ -297,17 +296,17 @@ class Viibe {
297
296
  return null;
298
297
  }
299
298
 
300
- if (event.data && event.data.event && event.data.payload) {
301
- return this.dispatch(event.data.event, event.data.payload, event.data.windowName);
299
+ if (event.data && event.data.event) {
300
+ return this.dispatch(event.data.event, event.data.payload, event, event.data.windowName);
302
301
  }
303
302
 
304
303
  // FIXME: legacy authentication messages
305
304
  if (event.data && event.data.token) {
306
- return this.dispatch('authentication:token', event.data.token);
305
+ return this.dispatch('authentication:token', event.data.token, event);
307
306
  }
308
307
 
309
308
  if (event.data && event.data.error) {
310
- return this.dispatch('authentication:error', event.data.error);
309
+ return this.dispatch('authentication:error', event.data.error, event);
311
310
  }
312
311
 
313
312
  return null;
@@ -323,8 +322,8 @@ class Viibe {
323
322
  */
324
323
  on(iframe, eventName, func) {
325
324
  if (typeof iframe === 'string' &&
326
- typeof eventName === 'function' &&
327
- typeof func === 'undefined') {
325
+ typeof eventName === 'function' &&
326
+ typeof func === 'undefined') {
328
327
  func = eventName;
329
328
  eventName = iframe;
330
329
  iframe = null;
package/test/dist.test.js CHANGED
@@ -62,7 +62,6 @@ describe('dist', () => {
62
62
  source: 'jest',
63
63
  });
64
64
  const iframe = viibe.createCallIframe();
65
- // const callUrl = viibe.createCallUrl();
66
65
 
67
66
  expect(iframe).toBeInstanceOf(HTMLIFrameElement);
68
67
  expect(iframe.name).toMatch(/^viibe-[0-9]{1,4}$/);
@@ -70,6 +69,5 @@ describe('dist', () => {
70
69
  expect(iframe.style.border).toBe('0px');
71
70
  expect(iframe.style.margin).toBe('0.5rem');
72
71
  expect(iframe.style.width).toBe('calc(100% - 1rem)');
73
- // expect(iframe.src).toEqual(callUrl);
74
72
  });
75
73
  });