@viibe/impulse-integration-js 2.3.5 → 2.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 +1 -1
- package/dist/index.js +1 -1
- package/package.json +1 -1
- package/src/index.js +11 -7
- package/.vscode/settings.json +0 -2
package/README.md
CHANGED
|
@@ -132,7 +132,7 @@ Triggered when the user clicks on an ongoing call. The host app may open a modal
|
|
|
132
132
|
- event `authentication:error`
|
|
133
133
|
- handler payload: `error: string`
|
|
134
134
|
|
|
135
|
-
Triggered when the user is not authenticated. The host app may display a login button in place of the iframe (`{host}/
|
|
135
|
+
Triggered when the user is not authenticated. The host app may display a login button in place of the iframe (`api-{host}/auth/login/{provider}`). Otherwise the iframe should display a "login" button with username / password method
|
|
136
136
|
|
|
137
137
|
- event `authentication:token`
|
|
138
138
|
- handler payload: `{token: string}`
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
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
|
|
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})();
|
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -98,7 +98,8 @@ class ViibeAuth {
|
|
|
98
98
|
}
|
|
99
99
|
|
|
100
100
|
loginZendesk(subdomain) {
|
|
101
|
-
const
|
|
101
|
+
const { origin } = document.location
|
|
102
|
+
const url = `https://${this.host}/auth/zendesk/login?subdomain=${subdomain}&origin=${origin}`;
|
|
102
103
|
return openAuthPopup(url);
|
|
103
104
|
}
|
|
104
105
|
}
|
|
@@ -116,10 +117,10 @@ class Viibe {
|
|
|
116
117
|
*/
|
|
117
118
|
|
|
118
119
|
/**
|
|
119
|
-
*
|
|
120
|
+
*
|
|
120
121
|
* @param {object} options
|
|
121
122
|
* @param {string} options.host Target ViiBE subdomain (e.g. test.viibe.tech)
|
|
122
|
-
* @param {string} options.source Integration source (e.g. zendesk)
|
|
123
|
+
* @param {string} options.source Integration source (e.g. zendesk)
|
|
123
124
|
*/
|
|
124
125
|
constructor(options) {
|
|
125
126
|
/**
|
|
@@ -128,6 +129,7 @@ class Viibe {
|
|
|
128
129
|
this.handlers = []
|
|
129
130
|
this.host = options.host
|
|
130
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}`
|
|
131
133
|
this.source = options.source
|
|
132
134
|
|
|
133
135
|
this.isViibeEvent = isFromOrigin(this.origin);
|
|
@@ -150,7 +152,7 @@ class Viibe {
|
|
|
150
152
|
if (!this.host) throw new Error('fillHost')
|
|
151
153
|
if (!this.source) throw new Error('fillSource')
|
|
152
154
|
|
|
153
|
-
const src = this.
|
|
155
|
+
const src = this.generateIframeSrc(options)
|
|
154
156
|
|
|
155
157
|
const iframe = document.createElement('iframe')
|
|
156
158
|
iframe.name = 'viibe-' + Math.floor(Math.random() * 10000)
|
|
@@ -163,7 +165,7 @@ class Viibe {
|
|
|
163
165
|
return iframe
|
|
164
166
|
}
|
|
165
167
|
|
|
166
|
-
|
|
168
|
+
generateIframeSrc(options = {}) {
|
|
167
169
|
const {
|
|
168
170
|
clipboard = false,
|
|
169
171
|
components,
|
|
@@ -175,11 +177,12 @@ class Viibe {
|
|
|
175
177
|
standalone,
|
|
176
178
|
} = options
|
|
177
179
|
|
|
178
|
-
let src = `${this.origin}/integration/features/
|
|
180
|
+
let src = `${this.origin}/integration/features/ticket`
|
|
179
181
|
|
|
180
182
|
const params = new URLSearchParams({
|
|
181
183
|
resize: 'true',
|
|
182
184
|
source: this.source,
|
|
185
|
+
origin: document.location.origin,
|
|
183
186
|
});
|
|
184
187
|
|
|
185
188
|
if (ticket && ticket.title) params.set('title', ticket.title)
|
|
@@ -295,7 +298,8 @@ class Viibe {
|
|
|
295
298
|
* @returns
|
|
296
299
|
*/
|
|
297
300
|
authenticate(provider) {
|
|
298
|
-
const
|
|
301
|
+
const { protocol, host } = document.location
|
|
302
|
+
const src = `${protocol}//api-${host}/auth/login/${provider}?origin=${origin}`
|
|
299
303
|
|
|
300
304
|
return openAuthPopup(src);
|
|
301
305
|
}
|
package/.vscode/settings.json
DELETED