@viibe/impulse-integration-js 2.3.7 → 2.3.9

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/package.json CHANGED
@@ -1,6 +1,9 @@
1
1
  {
2
2
  "name": "@viibe/impulse-integration-js",
3
- "version": "2.3.7",
3
+ "version": "2.3.9",
4
+ "engines": {
5
+ "node": ">= 10.0.0"
6
+ },
4
7
  "description": "ViiBE integration in js native",
5
8
  "main": "index.js",
6
9
  "publishConfig": {
package/src/index.js CHANGED
@@ -1,19 +1,20 @@
1
1
  function isFromOrigin(origin) {
2
- return function (event) {
3
- return Boolean(event.isTrusted && event.origin.indexOf(origin) === 0)
4
- }
2
+ return function isEventFromOrigin(event) {
3
+ return Boolean(event.isTrusted && event.origin.indexOf(origin) === 0);
4
+ };
5
5
  }
6
6
 
7
7
  function openAuthPopup(src) {
8
8
  const url = new URL(src);
9
9
  const origin = `${url.protocol}//${url.host}`;
10
10
 
11
- const width = 480
12
- const height = 600
13
- const TWO = 2
11
+ const width = 480;
12
+ const height = 600;
13
+ const TWO = 2;
14
+ const WINDOW_CLOSE_INTERVAL = 100;
14
15
 
15
- const left = (window.screen.width / TWO) - (width / TWO)
16
- const top = (window.screen.height / TWO) - (height / TWO)
16
+ const left = (window.screen.width / TWO) - (width / TWO);
17
+ const top = (window.screen.height / TWO) - (height / TWO);
17
18
  const windowParams = [
18
19
  'toolbar=no',
19
20
  'location=no',
@@ -27,13 +28,15 @@ function openAuthPopup(src) {
27
28
  `height=${height}`,
28
29
  `top=${top}`,
29
30
  `left=${left}`,
30
- ]
31
+ ];
31
32
 
33
+ // eslint-disable-next-line promise/avoid-new
32
34
  return new Promise((resolve, reject) => {
33
- const win = window.open(src, 'Authorization', windowParams.join(', '))
35
+ const win = window.open(src, 'Authorization', windowParams.join(', '));
34
36
 
35
37
  if (!win) {
36
- reject('Failed to open window')
38
+ // eslint-disable-next-line prefer-promise-reject-errors
39
+ reject('Failed to open window');
37
40
  }
38
41
 
39
42
  // pings the login window to check if it was closed
@@ -43,53 +46,64 @@ function openAuthPopup(src) {
43
46
  onClose();
44
47
  }
45
48
 
46
- }, 100)
49
+ }, WINDOW_CLOSE_INTERVAL);
47
50
 
48
51
  // triggered if the window was closed
49
52
  function onClose() {
50
- reject('User closed window')
53
+ // eslint-disable-next-line prefer-promise-reject-errors
54
+ reject('User closed window');
51
55
  }
52
56
 
53
57
  // completes the process, either because the user closes or because the authentication completed
54
58
  // cleans intervals and event listeners
55
59
  function destroy() {
56
- window.removeEventListener('message', onMessage)
57
- clearInterval(closeCheck)
60
+ window.removeEventListener('message', onMessage);
61
+ clearInterval(closeCheck);
58
62
  }
59
63
 
60
64
  // triggered when a message is received on the current window
61
65
  function onMessage(event) {
62
66
  if (!isFromOrigin(origin)(event)) {
63
- return null
67
+ return null;
64
68
  }
69
+
65
70
  // legacy ViiBE iframe messages (oauth.html)
66
71
  if (event.data.token) {
67
72
  destroy();
68
- resolve(event.data.token)
73
+ resolve(event.data.token);
69
74
  }
75
+
70
76
  if (event.data.error) {
71
77
  destroy();
72
- reject(event.data.error)
78
+ reject(event.data.error);
73
79
  }
74
80
 
75
81
  // events from auth.viibe.tech
76
- if(event.data && event.data.event && event.data.payload) {
77
- switch(event.data.event) {
78
- case 'authentication:success':
79
- destroy();
80
- return resolve(event.data);
81
- case 'authentication:failure':
82
- destroy();
83
- return reject(event.data);
82
+ if (event.data && event.data.event && event.data.payload) {
83
+ switch (event.data.event) {
84
+ case 'authentication:success':
85
+ destroy();
86
+
87
+ return resolve(event.data);
88
+ case 'authentication:failure':
89
+ destroy();
90
+
91
+ return reject(event.data);
92
+ default:
93
+
84
94
  }
95
+
85
96
  }
97
+
98
+ return null;
86
99
  }
87
100
 
88
- window.addEventListener('message', onMessage)
89
- })
101
+ window.addEventListener('message', onMessage);
102
+ });
90
103
  }
91
104
 
92
- const DEFAULT_AUTH_HOST = 'auth.viibe.pro'
105
+ const DEFAULT_AUTH_HOST = 'auth.viibe.pro';
106
+ const IFRAME_NAME_RANGE = 10000;
93
107
 
94
108
  class ViibeAuth {
95
109
 
@@ -98,16 +112,15 @@ class ViibeAuth {
98
112
  }
99
113
 
100
114
  loginZendesk(subdomain) {
101
- const { origin } = document.location
115
+ const { origin } = document.location;
102
116
  const url = `https://${this.host}/auth/zendesk/login?subdomain=${subdomain}&origin=${origin}`;
117
+
103
118
  return openAuthPopup(url);
104
119
  }
105
120
  }
106
121
 
107
122
  class Viibe {
108
123
 
109
- static Auth = ViibeAuth;
110
-
111
124
  /**
112
125
  * @typedef Handler
113
126
  * @type {object}
@@ -126,43 +139,56 @@ class Viibe {
126
139
  /**
127
140
  * @type {Handler[]}
128
141
  */
129
- this.handlers = []
130
- this.host = options.host
131
- this.origin = /^localhost/.test(this.host) ? `http://${this.host}` : `https://${this.host}`
132
- this.apiOrigin = /^localhost/.test(this.host) ? `http://${this.host}` : `https://api-${this.host}`
133
- this.source = options.source
142
+ this.handlers = [];
143
+ this.host = options.host;
144
+ this.origin = /^localhost/.test(this.host) ? `http://${this.host}` : `https://${this.host}`;
145
+ this.apiOrigin = /^localhost/.test(this.host) ? `http://${this.host}` : `https://api-${this.host}`;
146
+ this.source = options.source;
134
147
 
135
148
  this.isViibeEvent = isFromOrigin(this.origin);
136
149
 
137
- window.addEventListener('message', this.onMessage.bind(this))
150
+ window.addEventListener('message', this.onMessage.bind(this));
138
151
  }
139
152
 
140
153
  createNotificationIframe() {
141
- if (!this.host) throw new Error('fillHost')
142
- if (!this.source) throw new Error('fillSource')
143
-
144
- const iframe = document.createElement('iframe')
145
- iframe.name = 'viibe-' + Math.floor(Math.random() * 10000)
146
- iframe.style = 'border: 0;width: 0;'
147
- iframe.src = `${this.origin}/integration/features/notifications`
148
- return iframe
154
+ if (!this.host) {
155
+ throw new Error('fillHost');
156
+ }
157
+
158
+ if (!this.source) {
159
+ throw new Error('fillSource');
160
+ }
161
+
162
+ const iframe = document.createElement('iframe');
163
+
164
+ iframe.name = `viibe-${Math.floor(Math.random() * IFRAME_NAME_RANGE)}`;
165
+ iframe.style = 'border: 0;width: 0;';
166
+ iframe.src = `${this.origin}/integration/features/notifications`;
167
+
168
+ return iframe;
149
169
  }
150
170
 
151
171
  createCallIframe(options = {}) {
152
- if (!this.host) throw new Error('fillHost')
153
- if (!this.source) throw new Error('fillSource')
172
+ if (!this.host) {
173
+ throw new Error('fillHost');
174
+ }
175
+
176
+ if (!this.source) {
177
+ throw new Error('fillSource');
178
+ }
154
179
 
155
- const src = this.generateIframeSrc(options)
180
+ const src = this.generateIframeSrc(options);
156
181
 
157
- const iframe = document.createElement('iframe')
158
- iframe.name = 'viibe-' + Math.floor(Math.random() * 10000)
159
- iframe.style = 'border: 0;width: calc(100% - 1rem);margin: 0.5rem;'
160
- iframe.src = src
161
- iframe.allow = 'geolocation;autoplay;microphone;camera;midi;encrypted-media;clipboard-write;'
182
+ const iframe = document.createElement('iframe');
162
183
 
163
- this.on(iframe, 'document', event => this.onDocument(event))
184
+ iframe.name = `viibe-${Math.floor(Math.random() * IFRAME_NAME_RANGE)}`;
185
+ iframe.style = 'border: 0;width: calc(100% - 1rem);margin: 0.5rem;';
186
+ iframe.src = src;
187
+ iframe.allow = 'geolocation;autoplay;microphone;camera;midi;encrypted-media;clipboard-write;';
164
188
 
165
- return iframe
189
+ this.on(iframe, 'document', event => this.onDocument(event));
190
+
191
+ return iframe;
166
192
  }
167
193
 
168
194
  generateIframeSrc(options = {}) {
@@ -175,48 +201,58 @@ class Viibe {
175
201
  token,
176
202
  locale,
177
203
  standalone,
178
- } = options
204
+ } = options;
179
205
 
180
- let src = `${this.origin}/integration/features/ticket`
206
+ let src = `${this.origin}/integration/features/ticket`;
181
207
 
182
208
  const params = new URLSearchParams({
209
+ origin: document.location.origin,
183
210
  resize: 'true',
184
211
  source: this.source,
185
- origin: document.location.origin,
186
212
  });
187
213
 
188
- if (ticket && ticket.title) params.set('title', ticket.title)
189
- if (ticket && ticket.integration) params.set('thirdPartyId', ticket.integration.id)
214
+ if (ticket && ticket.title) {
215
+ params.set('title', ticket.title);
216
+ }
217
+
218
+ if (ticket && ticket.integration) {
219
+ params.set('thirdPartyId', ticket.integration.id);
220
+ }
190
221
 
191
222
  if (links) {
192
- let linksParams = (links instanceof Array)
223
+ const linksParams = (links instanceof Array)
193
224
  ? links.map(link => `${link.category}:${link.value}`).join(',')
194
- : String(links)
225
+ : String(links);
195
226
 
196
- params.set('links', linksParams)
227
+ params.set('links', linksParams);
197
228
  }
198
229
 
199
- if (token) params.set('token', token)
230
+ if (token) {
231
+ params.set('token', token);
232
+ }
200
233
 
201
- if (locale) params.set('locale', locale)
234
+ if (locale) {
235
+ params.set('locale', locale);
236
+ }
202
237
 
203
238
  if (components) {
204
- let componentsParams = (components instanceof Array)
239
+ const componentsParams = (components instanceof Array)
205
240
  ? components.join(',')
206
- : String(components)
241
+ : String(components);
207
242
 
208
- params.set('components', componentsParams)
243
+ params.set('components', componentsParams);
209
244
  }
210
245
 
211
- if (standalone) params.set('standalone', Boolean(standalone))
212
-
246
+ if (standalone) {
247
+ params.set('standalone', Boolean(standalone));
248
+ }
213
249
 
214
- params.set('clipboard', Boolean(clipboard))
215
- params.set('o2m', Boolean(o2m))
250
+ params.set('clipboard', Boolean(clipboard));
251
+ params.set('o2m', Boolean(o2m));
216
252
 
217
253
  src += `?${params}`;
218
254
 
219
- return src
255
+ return src;
220
256
  }
221
257
 
222
258
  /**
@@ -232,10 +268,10 @@ class Viibe {
232
268
  dispatch(eventName, payload, windowName) {
233
269
  return this.handlers
234
270
  .filter(handler =>
235
- handler.eventName === eventName
236
- && (!handler.windowName || (handler.windowName === windowName))
271
+ handler.eventName === eventName &&
272
+ (!handler.windowName || (handler.windowName === windowName)),
237
273
  )
238
- .map(handler => handler.func(payload))
274
+ .map(handler => handler.func(payload));
239
275
  }
240
276
 
241
277
  /**
@@ -245,22 +281,23 @@ class Viibe {
245
281
  */
246
282
  onMessage(event) {
247
283
  if (!this.isViibeEvent(event)) {
248
- return null
284
+ return null;
249
285
  }
250
286
 
251
287
  if (event.data && event.data.event && event.data.payload) {
252
- return this.dispatch(event.data.event, event.data.payload, event.data.windowName)
288
+ return this.dispatch(event.data.event, event.data.payload, event.data.windowName);
253
289
  }
254
290
 
255
291
  // FIXME: legacy authentication messages
256
292
  if (event.data && event.data.token) {
257
- return this.dispatch('authentication:token', event.data.token)
293
+ return this.dispatch('authentication:token', event.data.token);
258
294
  }
295
+
259
296
  if (event.data && event.data.error) {
260
- return this.dispatch('authentication:error', event.data.error)
297
+ return this.dispatch('authentication:error', event.data.error);
261
298
  }
262
299
 
263
- return null
300
+ return null;
264
301
  }
265
302
 
266
303
  /**
@@ -272,9 +309,9 @@ class Viibe {
272
309
  * @param {Function} handler
273
310
  */
274
311
  on(iframe, eventName, func) {
275
- if (typeof iframe === 'string'
276
- && typeof eventName === 'function'
277
- && typeof func === 'undefined') {
312
+ if (typeof iframe === 'string' &&
313
+ typeof eventName === 'function' &&
314
+ typeof func === 'undefined') {
278
315
  func = eventName;
279
316
  eventName = iframe;
280
317
  iframe = null;
@@ -282,14 +319,15 @@ class Viibe {
282
319
 
283
320
  const handler = {
284
321
  eventName,
285
- windowName: iframe ? iframe.name : null,
286
322
  func,
287
- }
323
+ windowName: iframe ? iframe.name : null,
324
+ };
325
+
288
326
  this.handlers.push(handler);
289
327
  }
290
328
 
291
329
  onDocument(document) {
292
- window.open(document.signed_url, '_blank')
330
+ window.open(document.signed_url, '_blank');
293
331
  }
294
332
 
295
333
  /**
@@ -298,17 +336,20 @@ class Viibe {
298
336
  * @returns
299
337
  */
300
338
  authenticate(provider) {
301
- const { protocol, host } = document.location
302
- const src = `${protocol}//api-${host}/auth/login/${provider}?origin=${origin}`
339
+ const { protocol, host } = document.location;
340
+ const src = `${protocol}//api-${host}/auth/login/${provider}?origin=${origin}`;
303
341
 
304
342
  return openAuthPopup(src);
305
343
  }
306
344
 
307
345
  }
308
346
 
347
+ Viibe.Auth = ViibeAuth;
348
+
309
349
  if (typeof window !== 'undefined') {
310
- window.Viibe = Viibe
350
+ window.Viibe = Viibe;
311
351
  }
352
+
312
353
  if (typeof module !== 'undefined') {
313
- module.exports = Viibe
354
+ module.exports = Viibe;
314
355
  }
package/test/dist.test.js CHANGED
@@ -6,62 +6,70 @@ const Viibe = require('../dist');
6
6
 
7
7
  describe('dist', () => {
8
8
  test('exposes Viibe constructor', () => {
9
- expect(typeof Viibe).toBe('function')
10
- expect(() => new Viibe()).toThrowError()
11
- expect(new Viibe({})).toBeInstanceOf(Viibe)
9
+ expect(typeof Viibe).toBe('function');
10
+ expect(() => new Viibe()).toThrowError();
11
+ expect(new Viibe({})).toBeInstanceOf(Viibe);
12
12
  });
13
13
 
14
14
  test('throws errors when host or source are not defined', () => {
15
15
  const viibe = new Viibe({});
16
- expect(() => viibe.createNotificationIframe()).toThrow('fillHost')
17
- expect(() => viibe.createCallIframe()).toThrow('fillHost')
18
16
 
19
- const viibeWithHost = new Viibe({host: 'clement.viibe.tech'})
20
- expect(() => viibeWithHost.createNotificationIframe()).toThrow('fillSource')
21
- expect(() => viibeWithHost.createCallIframe()).toThrow('fillSource')
22
- })
17
+ expect(() => viibe.createNotificationIframe()).toThrow('fillHost');
18
+ expect(() => viibe.createCallIframe()).toThrow('fillHost');
19
+
20
+ const viibeWithHost = new Viibe({
21
+ host: 'clement.viibe.tech',
22
+ });
23
+
24
+ expect(() => viibeWithHost.createNotificationIframe()).toThrow('fillSource');
25
+ expect(() => viibeWithHost.createCallIframe()).toThrow('fillSource');
26
+ });
23
27
 
24
28
  test('constructor', () => {
25
29
  const viibe = new Viibe({
26
- host: 'clement.viibe.tech',
27
- source: 'jest'
28
- })
29
- expect(viibe.host).toBe('clement.viibe.tech')
30
- expect(viibe.source).toBe('jest')
31
- expect(viibe.origin).toBe('https://clement.viibe.tech')
30
+ host: 'clement.viibe.tech',
31
+ source: 'jest',
32
+ });
33
+
34
+ expect(viibe.host).toBe('clement.viibe.tech');
35
+ expect(viibe.source).toBe('jest');
36
+ expect(viibe.origin).toBe('https://clement.viibe.tech');
32
37
 
33
38
  const viibeLocalhost = new Viibe({
34
- host: 'localhost:6666'
35
- })
36
- expect(viibeLocalhost.origin).toBe('http://localhost:6666')
39
+ host: 'localhost:6666',
40
+ });
41
+
42
+ expect(viibeLocalhost.origin).toBe('http://localhost:6666');
37
43
  });
38
44
 
39
45
  test('createNotificationIframe', () => {
40
46
  const viibe = new Viibe({
41
- host: 'clement.viibe.tech',
42
- source: 'jest',
43
- })
44
- const iframe = viibe.createNotificationIframe()
45
- expect(iframe).toBeInstanceOf(HTMLIFrameElement)
46
- expect(iframe.name).toMatch(/^viibe-[0-9]{1,4}$/)
47
- expect(iframe.style.border).toBe('0px')
48
- expect(iframe.style.width).toBe('0px')
49
- expect(iframe.src).toBe('https://clement.viibe.tech/integration/features/notifications')
50
- })
47
+ host: 'clement.viibe.tech',
48
+ source: 'jest',
49
+ });
50
+ const iframe = viibe.createNotificationIframe();
51
+
52
+ expect(iframe).toBeInstanceOf(HTMLIFrameElement);
53
+ expect(iframe.name).toMatch(/^viibe-[0-9]{1,4}$/);
54
+ expect(iframe.style.border).toBe('0px');
55
+ expect(iframe.style.width).toBe('0px');
56
+ expect(iframe.src).toBe('https://clement.viibe.tech/integration/features/notifications');
57
+ });
51
58
 
52
59
  test('createCallIframe', () => {
53
60
  const viibe = new Viibe({
54
- host: 'clement.viibe.tech',
55
- source: 'jest',
56
- })
57
- const iframe = viibe.createCallIframe()
58
- const callUrl = viibe.createCallUrl()
59
- expect(iframe).toBeInstanceOf(HTMLIFrameElement)
60
- expect(iframe.name).toMatch(/^viibe-[0-9]{1,4}$/)
61
- expect(iframe.allow).toBe('geolocation;autoplay;microphone;camera;midi;encrypted-media;clipboard-write;')
62
- expect(iframe.style.border).toBe('0px')
63
- expect(iframe.style.margin).toBe('0.5rem')
64
- expect(iframe.style.width).toBe('calc(100% - 1rem)')
65
- expect(iframe.src).toEqual(callUrl)
66
- })
67
- });
61
+ host: 'clement.viibe.tech',
62
+ source: 'jest',
63
+ });
64
+ const iframe = viibe.createCallIframe();
65
+ const callUrl = viibe.createCallUrl();
66
+
67
+ expect(iframe).toBeInstanceOf(HTMLIFrameElement);
68
+ expect(iframe.name).toMatch(/^viibe-[0-9]{1,4}$/);
69
+ expect(iframe.allow).toBe('geolocation;autoplay;microphone;camera;midi;encrypted-media;clipboard-write;');
70
+ expect(iframe.style.border).toBe('0px');
71
+ expect(iframe.style.margin).toBe('0.5rem');
72
+ expect(iframe.style.width).toBe('calc(100% - 1rem)');
73
+ expect(iframe.src).toEqual(callUrl);
74
+ });
75
+ });
package/dist/index.js DELETED
@@ -1 +0,0 @@
1
- (()=>{var t={579:t=>{function e(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function n(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,o.key,o)}}function o(t,e,o){return e&&n(t.prototype,e),o&&n(t,o),t}function i(t){return function(e){return Boolean(e.isTrusted&&0===e.origin.indexOf(t))}}function a(t){var e=new URL(t),n="".concat(e.protocol,"//").concat(e.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(e,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(n)(t))return null;if(t.data.token&&(s(),e(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(),e(t.data);case"authentication:failure":return s(),o(t.data)}}window.addEventListener("message",u)}))}var r,c,s,u="auth.viibe.pro",l=function(){function t(){var n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:u;e(this,t),this.host=n}return o(t,[{key:"loginZendesk",value:function(t){var e=document.location.origin;return a("https://".concat(this.host,"/auth/zendesk/login?subdomain=").concat(t,"&origin=").concat(e))}}]),t}(),h=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=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-"+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");var n=this.generateIframeSrc(e),o=document.createElement("iframe");return o.name="viibe-"+Math.floor(1e4*Math.random()),o.style="border: 0;width: calc(100% - 1rem);margin: 0.5rem;",o.src=n,o.allow="geolocation;autoplay;microphone;camera;midi;encrypted-media;clipboard-write;",this.on(o,"document",(function(e){return t.onDocument(e)})),o}},{key:"generateIframeSrc",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},e=t.clipboard,n=void 0!==e&&e,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="".concat(this.origin,"/integration/features/ticket"),d=new URLSearchParams({resize:"true",source:this.source,origin:document.location.origin});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(s&&d.set("token",s),u&&d.set("locale",u),o){var v=o instanceof Array?o.join(","):String(o);d.set("components",v)}return l&&d.set("standalone",Boolean(l)),d.set("clipboard",Boolean(n)),d.set("o2m",Boolean(r)),h+"?".concat(d)}},{key:"dispatch",value:function(t,e,n){return this.handlers.filter((function(e){return e.eventName===t&&(!e.windowName||e.windowName===n)})).map((function(t){return t.func(e)}))}},{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,e,n){"string"==typeof t&&"function"==typeof e&&void 0===n&&(n=e,e=t,t=null);var o={eventName:e,windowName:t?t.name:null,func:n};this.handlers.push(o)}},{key:"onDocument",value:function(t){window.open(t.signed_url,"_blank")}},{key:"authenticate",value:function(t){var e=document.location,n=e.protocol,o=e.host;return a("".concat(n,"//api-").concat(o,"/auth/login/").concat(t,"?origin=").concat(origin))}}]),t}();s=l,(c="Auth")in(r=h)?Object.defineProperty(r,c,{value:s,enumerable:!0,configurable:!0,writable:!0}):r.Auth=s,"undefined"!=typeof window&&(window.Viibe=h),t.exports=h}},e={},n=function n(o){var i=e[o];if(void 0!==i)return i.exports;var a=e[o]={exports:{}};return t[o](a,a.exports,n),a.exports}(579);module.exports=n})();