Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@livechat/accounts-sdk

Package Overview
Dependencies
Maintainers
38
Versions
46
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@livechat/accounts-sdk - npm Package Compare versions

Comparing version 1.3.1 to 1.3.2

dist/accounts-sdk.js

2

dist/accounts-sdk.min.js

@@ -1,1 +0,1 @@

!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e=e||self).AccountsSDK=t()}(this,function(){"use strict";var u=function(e,t){if(null==e)throw new TypeError("Cannot convert undefined or null to object");for(var n=Object(e),o=1;o<arguments.length;o++){var i=arguments[o];if(null!=i)for(var s in i)Object.prototype.hasOwnProperty.call(i,s)&&(n[s]=i[s])}return n};function i(){return(i=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var o in n)Object.prototype.hasOwnProperty.call(n,o)&&(e[o]=n[o])}return e}).apply(this,arguments)}var o=new function(){this.submit=function(e,t){(t=u({},t)).headers=t.headers||[],t.success=t.success||function(){},t.error=t.error||function(){},t.method=t.method||"POST";var n=new XMLHttpRequest;n.open(t.method,e,!0),Object.keys(t.headers).forEach(function(e){return n.setRequestHeader(e,t.headers[e])}),n.onreadystatechange=function(){if(4!==n.readyState)return!1;n.status<200||299<n.status?t.error(n.responseText,n.status):t.success(n.responseText,n.status)},n.send(t.postData)},this.get=function(e,t){var n=new XMLHttpRequest;n.open("GET",e,!0),!0===t.withCredentials&&(n.withCredentials=!0),Object.keys(t.headers).forEach(function(e){return n.setRequestHeader(e,t.headers[e])}),n.onreadystatechange=function(){if(n.readyState!==XMLHttpRequest.DONE)return!1;200===n.status?t.success(n.responseText,n.status):t.error(n.responseText,n.status)},n.send(t.postData)}},s=new(function(i){var e,t;function n(){for(var n,e=arguments.length,t=Array(e),o=0;o<e;o++)t[o]=arguments[o];return(n=i.call.apply(i,[this].concat(t))||this).getInfoByCode=function(e,t){void 0===t&&(t={}),n._get("/info?code="+e+"&type=code",t)},n.getInfoByAccessToken=function(e,t){void 0===t&&(t={}),t.headers=u({Authorization:"Bearer "+e},t.headers),n._get("/info",t)},n}return(e=n).prototype=Object.create((t=i).prototype),(e.prototype.constructor=e).__proto__=t,n}(function(){function e(e,t,n){var c=this;void 0===t&&(t={}),void 0===n&&(n={}),this._promisify=function(e){if(null==e.success&&null==e.error)return new Promise(function(n,o){e.success=function(e,t){n({data:e,statusCode:t})},e.error=function(e,t){o({data:e,statusCode:t})}})},this._URL=function(e){return"function"==typeof c.endpoint?c.endpoint()+e:c.endpoint+e},this._finalOptions=function(n,o,i,s){var r,a,e=JSON.stringify(o),t=u({},i);return t.postData=e,t.headers=u(t.headers||{},c.headers),t.success&&(t.success=(r=t.success,function(t,e){try{t=JSON.parse(t)}catch(e){t={}}r(t,e)})),t.error&&(t.error=(a=t.error,function(t,e){try{t=JSON.parse(t)}catch(e){t={}}if("wrong region"===t.error)return c.options.onIncorrectRegion&&c.options.onIncorrectRegion(t.region),void c[s](n,o,i);a(t,e)})),t},this._get=function(e,t){o.get(c._URL(e),c._finalOptions(e,{},t,"_get"))},this._post=function(e,t,n){o.submit(c._URL(e),c._finalOptions(e,t,n,"_post"))},this._put=function(e,t,n){n.method="PUT",o.submit(c._URL(e),c._finalOptions(e,t,n,"_put"))},this._setDefaults=function(e){return(e=e||{}).headers=e.headers||{},e},this.endpoint=e,this.headers=t,this.options=n}return e.prototype.setEndpoint=function(e){this.endpoint=e},e}()))("https://accounts.livechatinc.com"),t=new(function(){function e(){}var t=e.prototype;return t.set=function(e,t,n){void 0===n&&(n=null);var o={value:t,expires_in:(new Date).getTime()+1e3*n};try{localStorage.setItem(e,JSON.stringify(o))}catch(e){}},t.get=function(e){var t;try{t=JSON.parse(localStorage.getItem(e))}catch(e){return null}if(null!==t){if(null===t.expires_in||t.expires_in>=(new Date).getTime())return t.value;localStorage.removeItem(e)}return null},t.remove=function(e){try{localStorage.removeItem(e)}catch(e){}},e}());function r(t){return 0===Object.keys(t).length?"":"?"+Object.keys(t).map(function(e){return encodeURIComponent(e)+"="+encodeURIComponent(t[e])}).join("&")}var n={"popup-window-name":"livechat-login-popup","console-url":"https://developers.livechatinc.com/console/","login-button-class":"livechat-login-button","cache-prefix":"livechat_cache","text-button-product-name":"Live<span>Chat</span>"},c=function(e){return n[e]},d="https://accounts.livechatinc.com",a=function(e){var a=this;this._options={client_id:null,response_type:"token",linkLabel:null,onIdentityFetched:function(){},onSignedOut:function(){},queryStringParams:{utm_source:"accounts.livechatinc.com",utm_medium:"accounts-sdk"},popupRoute:""},this._postMessageUniqueId=null,this._listenerInited=!1,this._messageReceived=!1,this._lastIdentityError=null,this._lastIdentityData=null,this.updateOptions=function(e){a._options=u(a._options,e),e.backendAddress&&(d=e.backendAddress),s.setEndpoint(d)},this.openPopup=function(e){e&&e.preventDefault&&e.preventDefault();var t=screen.width/2-250,n=screen.height/2-325,o=a._getCurrentPath();a._startListening(),window.open(d+"/"+a._options.popupRoute+r(i({client_id:a._options.client_id,state:a._postMessageUniqueId,response_type:a._options.response_type,redirect_uri:o,flow:"button"},a._options.queryStringParams)),c("popup-window-name"),"resizable,scrollbars,width=500,height=650,left="+t+",top="+n)},this.signOut=function(e){return"function"==typeof e&&(a._options.onSignedOut=e),a._buildIframe("signout")},this.displayButtons=function(e){if(!0!==(e=e||{}).internalCall&&a._lastIdentityError&&"invalid_request"===a._lastIdentityError.oauth_exception)return a._displayError(["Button could not be displayed. Probably you are running this script on a domain that is not whitelisted in your app's settings.","Visit developers console to update your app's domain list: "+c("console-url")]),!1;var t=document.getElementsByClassName(c("login-button-class"));if(0<t.length){var n=document.createElement("link");n.id=c("login-button-class")+"-font",n.rel="stylesheet",n.href="//fonts.googleapis.com/css?family=Lato:300,400,700,900",document.head.appendChild(n),document.head.insertAdjacentHTML("beforeend","<style>."+c("login-button-class")+' a {color: #5a6976;display: inline-block;font-size: 16px;line-height: 1.5;font-family: "Lato", sans-serif;font-weight: 400;text-decoration: none;border: 1px solid #ddd;border-radius: 3px;padding: 8px 24px 9px}.'+c("login-button-class")+" a:hover {border-color: #888;color: #5a6976}."+c("login-button-class")+" span {color: #f56e21</style>");for(var o=0,i=t.length;o<i;o++){var s=t[o];if("1"!==s.getAttribute("data-inited")){s.setAttribute("data-inited","1");var r=document.createElement("a");r.href="",r.onclick=a.openPopup,a._options.linkLabel?r.text=a._options.linkLabel:r.innerHTML="Sign in with <strong>"+c("text-button-product-name")+"</strong>",s.appendChild(r)}}}},this._displayError=function(e){if(!window.console||!window.console.warn)return!1;e instanceof Array||(e=[e]),e.forEach(function(e){return window.console.warn("[accountsSdk] "+e)})},this._returnSuccessResponse=function(t,n){void 0===n&&(n={});var o={};t.code?(o.code=t.code,s.getInfoByCode(t.code,{success:function(e){o.client_id=e.client_id,o.entity_id=e.entity_id,o.license=e.license_id,o.expires_in=e.expires_in,o.scopes=e.scope?e.scope.split(","):[],a._onIdentityFetched(null,o)},error:function(e){n.fromIframeCache?(a._removeCachedData(),a._buildIframe()):a._onIdentityFetched(e,null)}})):(o.access_token=t.access_token,s.getInfoByAccessToken(t.access_token,{success:function(e){o.client_id=e.client_id,o.entity_id=e.entity_id,o.license=e.license_id,o.expires_in=e.expires_in,o.scopes=e.scope?e.scope.split(","):[],a._onIdentityFetched(null,o),a._cacheData({access_token:t.access_token,expires_in:e.expires_in})},error:function(e){n.fromIframeCache?(a._removeCachedData(),a._buildIframe()):a._onIdentityFetched(e,null)}}))},this._removeIframe=function(){var e=document.getElementById(a._getIframeId());e&&e.parentNode&&e.parentNode.removeChild(e),a._stopListening()},this._receiveMessage=function(e){e.origin===d&&e.data&&e.data.state&&e.data.state===a._postMessageUniqueId&&(a._messageReceived=!0,a._removeIframe(),e.data.error?a._parseError(e.data.error):!0===e.data.signed_out?a._options.onSignedOut():e.data.data&&a._returnSuccessResponse(e.data.data))},this._parseError=function(e){a._onIdentityFetched(e,null),a._lastIdentityError&&("invalid_request"===a._lastIdentityError.oauth_exception?a._displayError(["Authorization process returned 'invalid_request' error.","Probably you are running this script on a domain that is not whitelisted in your app's settings.","Visit developers console to update your app's domain list: "+c("console-url")]):"access_denied"===a._lastIdentityError.oauth_exception?a._displayError(["Authorization process returned 'access_denied' error.","Probably this application is installed on a different account and you do not have access to it."]):"invalid_request"===a._lastIdentityError.identity_exception&&a._displayError(["Authentication process returned 'invalid_request' error.","You may be loading accountsSdk on a domain that is not whitelisted."]))},this._onIdentityFetched=function(e,t){a._lastIdentityError=e,a._lastIdentityData=t,a.displayButtons({internalCall:!0}),a._options.onIdentityFetched(e,t)},this._buildIframe=function(e){void 0===e&&(e=""),a._startListening();var t=document.createElement("iframe");t.setAttribute("src",d+"/"+e+r(i({client_id:a._options.client_id,state:a._postMessageUniqueId,response_type:a._options.response_type,redirect_uri:a._getCurrentPath(),flow:"button"},a._options.queryStringParams))),t.setAttribute("id",a._getIframeId()),t.style.width="1px",t.style.height="1px",t.style.position="fixed",t.style.top="0",t.style.right="0",t.style.opacity="0",t.style.visibility="none",document.body.appendChild(t)},this._getCurrentPath=function(){return window.location.protocol+"//"+window.location.hostname+(window.location.port?":"+window.location.port:"")+window.location.pathname},this._getCacheKey=function(){return c("cache-prefix")+"."+a._options.client_id+"."+a._options.response_type},this._cacheData=function(e){t.set(a._getCacheKey(),e,e.expires_in)},this._getCachedData=function(){return t.get(a._getCacheKey())},this._removeCachedData=function(){return t.remove(a._getCacheKey())},this._getIframeId=function(){return c("login-button-class")+"-iframe."+a._options.client_id+"."+a._options.response_type},this._startListening=function(){if(a._listenerInited)return!1;a._listenerInited=!0,a._messageReceived=!1,window.addEventListener("message",a._receiveMessage,!1)},this._stopListening=function(){a._listenerInited=!1,window.removeEventListener("message",a._receiveMessage,!1)},this.initSDK=function(){if(!a._options.client_id)return window.console&&window.console.warn&&console.warn('[accountsSdk] Required "client_id" param is missing in init() method.'),!1;var e=a._getCachedData();e?a._returnSuccessResponse(e,{fromIframeCache:!0}):(a._buildIframe(),setTimeout(function(){a._messageReceived||a._parseError({identity_exception:"invalid_request"})},5e3))},this._postMessageUniqueId=Math.random().toString(36).substr(2,9),this.updateOptions(e)};return{init:function(e){var t=new a(e);return t.initSDK(),t}}});
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t=t||self).AccountsSDK=e()}(this,function(){"use strict";var u=function(t,e){if(null==t)throw new TypeError("Cannot convert undefined or null to object");for(var n=Object(t),o=1;o<arguments.length;o++){var i=arguments[o];if(null!=i)for(var s in i)Object.prototype.hasOwnProperty.call(i,s)&&(n[s]=i[s])}return n};function i(){return(i=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var o in n)Object.prototype.hasOwnProperty.call(n,o)&&(t[o]=n[o])}return t}).apply(this,arguments)}var o=new function(){this.submit=function(t,e){(e=u({},e)).headers=e.headers||[],e.success=e.success||function(){},e.error=e.error||function(){},e.method=e.method||"POST";var n=new XMLHttpRequest;n.open(e.method,t,!0),Object.keys(e.headers).forEach(function(t){return n.setRequestHeader(t,e.headers[t])}),n.onreadystatechange=function(){return 4===n.readyState&&(n.status<200||299<n.status?e.error(n.responseText,n.status):e.success(n.responseText,n.status),!0)},n.send(e.postData)},this.get=function(t,e){var n=new XMLHttpRequest;n.open("GET",t,!0),!0===e.withCredentials&&(n.withCredentials=!0),Object.keys(e.headers).forEach(function(t){return n.setRequestHeader(t,e.headers[t])}),n.onreadystatechange=function(){return n.readyState===XMLHttpRequest.DONE&&(200===n.status?e.success(n.responseText,n.status):e.error(n.responseText,n.status),!0)},n.send(e.postData)}},s=new(function(i){var t,e;function n(){for(var o,t=arguments.length,e=Array(t),n=0;n<t;n++)e[n]=arguments[n];return(o=i.call.apply(i,[this].concat(e))||this).getInfoByCode=function(t,e){void 0===e&&(e={}),o.get("/info?code="+t+"&type=code",e)},o.getInfoByAccessToken=function(t,e){void 0===e&&(e={});var n=e;n.headers=u({Authorization:"Bearer "+t},n.headers),o.get("/info",n)},o}return(t=n).prototype=Object.create((e=i).prototype),(t.prototype.constructor=t).__proto__=e,n}(function(){function t(t,e,n){var c=this;void 0===e&&(e={}),void 0===n&&(n={}),this.endpoint=void 0,this.headers=void 0,this.options=void 0,this.promisify=function(t){return null==t.success&&null==t.error?new Promise(function(n,o){t.success=function(t,e){n({data:t,statusCode:e})},t.error=function(t,e){o({data:t,statusCode:e})}}):null},this.URL=function(t){return"function"==typeof c.endpoint?c.endpoint()+t:c.endpoint+t},this.finalOptions=function(n,o,i,s){var r,a,t=JSON.stringify(o),e=u({},i);return e.postData=t,e.headers=u(e.headers||{},c.headers),e.success&&(e.success=(r=e.success,function(e,t){try{e=JSON.parse(e)}catch(t){e={}}r(e,t)})),e.error&&(e.error=(a=e.error,function(e,t){try{e=JSON.parse(e)}catch(t){e={}}if("wrong region"===e.error)return c.options.onIncorrectRegion&&c.options.onIncorrectRegion(e.region),void c[s](n,o,i);a(e,t)})),e},this.get=function(t,e){o.get(c.URL(t),c.finalOptions(t,{},e,"get"))},this.post=function(t,e,n){o.submit(c.URL(t),c.finalOptions(t,e,n,"post"))},this.put=function(t,e,n){n.method="PUT",o.submit(c.URL(t),c.finalOptions(t,e,n,"put"))},this.setDefaults=function(t){return(t=t||{}).headers=t.headers||{},t},this.endpoint=t,this.headers=e,this.options=n}return t.prototype.setEndpoint=function(t){this.endpoint=t},t}()))("https://accounts.livechatinc.com"),e=new(function(){function t(){}var e=t.prototype;return e.set=function(t,e,n){void 0===n&&(n=null);var o={value:e,expiresIn:(new Date).getTime()+1e3*n};try{localStorage.setItem(t,JSON.stringify(o))}catch(t){}},e.get=function(t){var e;try{e=JSON.parse(localStorage.getItem(t))}catch(t){return null}if(null!==e){if(null===e.expiresIn||e.expiresIn>=(new Date).getTime())return e.value;localStorage.removeItem(t)}return null},e.remove=function(t){try{localStorage.removeItem(t)}catch(t){}},t}());function r(e){return 0===Object.keys(e).length?"":"?"+Object.keys(e).map(function(t){return encodeURIComponent(t)+"="+encodeURIComponent(e[t])}).join("&")}var n={"popup-window-name":"livechat-login-popup","console-url":"https://developers.livechatinc.com/console/","login-button-class":"livechat-login-button","cache-prefix":"livechat_cache","text-button-product-name":"Live<span>Chat</span>"},c=function(t){return n[t]},d="https://accounts.livechatinc.com",a=function(t){var a=this;this._options={client_id:null,response_type:"token",linkLabel:null,onIdentityFetched:function(){},onSignedOut:function(){},queryStringParams:{utm_source:"accounts.livechatinc.com",utm_medium:"accounts-sdk"},popupRoute:""},this._postMessageUniqueId=null,this._listenerInited=!1,this._tid=!1,this._lastIdentityError=null,this._lastIdentityData=null,this.updateOptions=function(t){a._options=u(a._options,t),t.backendAddress&&(d=t.backendAddress),s.setEndpoint(d)},this.openPopup=function(t){t&&t.preventDefault&&t.preventDefault();var e=screen.width/2-250,n=screen.height/2-325,o=a._getCurrentPath();a._startListening(),window.open(d+"/"+a._options.popupRoute+r(i({client_id:a._options.client_id,state:a._postMessageUniqueId,response_type:a._options.response_type,redirect_uri:o,flow:"button"},a._options.queryStringParams)),c("popup-window-name"),"resizable,scrollbars,width=500,height=650,left="+e+",top="+n)},this.signOut=function(t){return"function"==typeof t&&(a._options.onSignedOut=t),a._buildIframe("signout")},this.displayButtons=function(t){if(!0!==(t=t||{}).internalCall&&a._lastIdentityError&&"invalid_request"===a._lastIdentityError.oauth_exception)return a._displayError(["Button could not be displayed. Probably you are running this script on a domain that is not whitelisted in your app's settings.","Visit developers console to update your app's domain list: "+c("console-url")]),!1;var e=document.getElementsByClassName(c("login-button-class"));if(0<e.length){var n=document.createElement("link");n.id=c("login-button-class")+"-font",n.rel="stylesheet",n.href="//fonts.googleapis.com/css?family=Lato:300,400,700,900",document.head.appendChild(n),document.head.insertAdjacentHTML("beforeend","<style>."+c("login-button-class")+' a {color: #5a6976;display: inline-block;font-size: 16px;line-height: 1.5;font-family: "Lato", sans-serif;font-weight: 400;text-decoration: none;border: 1px solid #ddd;border-radius: 3px;padding: 8px 24px 9px}.'+c("login-button-class")+" a:hover {border-color: #888;color: #5a6976}."+c("login-button-class")+" span {color: #f56e21</style>");for(var o=0,i=e.length;o<i;o++){var s=e[o];if("1"!==s.getAttribute("data-inited")){s.setAttribute("data-inited","1");var r=document.createElement("a");r.href="",r.onclick=a.openPopup,a._options.linkLabel?r.text=a._options.linkLabel:r.innerHTML="Sign in with <strong>"+c("text-button-product-name")+"</strong>",s.appendChild(r)}}}},this._displayError=function(t){if(!window.console||!window.console.warn)return!1;t instanceof Array||(t=[t]),t.forEach(function(t){return window.console.warn("[accountsSdk] "+t)})},this._returnSuccessResponse=function(e,n){void 0===n&&(n={});var o={};e.code?(o.code=e.code,s.getInfoByCode(e.code,{success:function(t){o.client_id=t.client_id,o.entity_id=t.entity_id,o.license=t.license_id,o.expires_in=t.expires_in,o.scopes=t.scope?t.scope.split(","):[],a._onIdentityFetched(null,o)},error:function(t){n.fromIframeCache?(a._removeCachedData(),a._buildIframe()):a._onIdentityFetched(t,null)}})):(o.access_token=e.access_token,s.getInfoByAccessToken(e.access_token,{success:function(t){o.client_id=t.client_id,o.entity_id=t.entity_id,o.license=t.license_id,o.expires_in=t.expires_in,o.scopes=t.scope?t.scope.split(","):[],a._onIdentityFetched(null,o),a._cacheData({access_token:e.access_token,expires_in:t.expires_in})},error:function(t){n.fromIframeCache?(a._removeCachedData(),a._buildIframe()):a._onIdentityFetched(t,null)}}))},this._removeIframe=function(){var t=document.getElementById(a._getIframeId());t&&t.parentNode&&t.parentNode.removeChild(t),a._stopListening()},this._parseJwt=function(t){var e=t.split(".")[1].replace(/-/g,"+").replace(/_/g,"/"),n=decodeURIComponent(atob(e).split("").map(function(t){return"%"+("00"+t.charCodeAt(0).toString(16)).slice(-2)}).join(""));return JSON.parse(n)},this._checkPostMessageUniqueId=function(t){if(t===a._postMessageUniqueId)return!0;try{return a._parseJwt(t).state===a._postMessageUniqueId}catch(t){return!1}},this._receiveMessage=function(t){t.origin===d&&t.data&&t.data.state&&a._checkPostMessageUniqueId(t.data.state)&&(clearTimeout(a._tid),a._removeIframe(),t.data.error?a._parseError(t.data.error):!0===t.data.signed_out?a._options.onSignedOut():t.data.data&&a._returnSuccessResponse(t.data.data))},this._parseError=function(t){a._onIdentityFetched(t,null),a._lastIdentityError&&("invalid_request"===a._lastIdentityError.oauth_exception?a._displayError(["Authorization process returned 'invalid_request' error.","Probably you are running this script on a domain that is not whitelisted in your app's settings.","Visit developers console to update your app's domain list: "+c("console-url")]):"access_denied"===a._lastIdentityError.oauth_exception?a._displayError(["Authorization process returned 'access_denied' error.","Probably this application is installed on a different account and you do not have access to it."]):"invalid_request"===a._lastIdentityError.identity_exception&&a._displayError(["Authentication process returned 'invalid_request' error.","You may be loading accountsSdk on a domain that is not whitelisted."]))},this._onIdentityFetched=function(t,e){a._lastIdentityError=t,a._lastIdentityData=e,a.displayButtons({internalCall:!0}),a._options.onIdentityFetched(t,e)},this._buildIframe=function(t){void 0===t&&(t=""),a._startListening({timeout:5e3});var e=document.createElement("iframe");e.setAttribute("src",d+"/"+t+r(i({client_id:a._options.client_id,state:a._postMessageUniqueId,response_type:a._options.response_type,redirect_uri:a._getCurrentPath(),flow:"button"},a._options.queryStringParams))),e.setAttribute("id",a._getIframeId()),e.style.width="1px",e.style.height="1px",e.style.position="fixed",e.style.top="0",e.style.right="0",e.style.opacity="0",e.style.visibility="none",document.body.appendChild(e)},this._getCurrentPath=function(){return window.location.protocol+"//"+window.location.hostname+(window.location.port?":"+window.location.port:"")+window.location.pathname},this._getCacheKey=function(){return c("cache-prefix")+"."+a._options.client_id+"."+a._options.response_type},this._cacheData=function(t){e.set(a._getCacheKey(),t,t.expires_in)},this._getCachedData=function(){return e.get(a._getCacheKey())},this._removeCachedData=function(){return e.remove(a._getCacheKey())},this._getIframeId=function(){return c("login-button-class")+"-iframe."+a._options.client_id+"."+a._options.response_type},this._startListening=function(t){if(void 0===t&&(t={}),a._listenerInited)return!1;t.timeout&&(a._tid=setTimeout(function(){this._parseError({identity_exception:"invalid_request"})},t.timeout)),a._listenerInited=!0,window.addEventListener("message",a._receiveMessage,!1)},this._stopListening=function(){a._listenerInited=!1,window.removeEventListener("message",a._receiveMessage,!1)},this.initSDK=function(){if(!a._options.client_id)return window.console&&window.console.warn&&console.warn('[accountsSdk] Required "client_id" param is missing in init() method.'),!1;var t=a._getCachedData();t?a._returnSuccessResponse(t,{fromIframeCache:!0}):a._buildIframe()},this._postMessageUniqueId=Math.random().toString(36).substr(2,9),this.updateOptions(t)};return{init:function(t){var e=new a(t);return e.initSDK(),e}}});

@@ -63,2 +63,3 @@ 'use strict';

/* eslint-disable no-param-reassign, @typescript-eslint/explicit-function-return-type */
var Http = function Http() {

@@ -73,3 +74,3 @@ this.submit = function (url, options) {

options.method = options.method || "POST";
options.method = options.method || 'POST';
var http = new XMLHttpRequest();

@@ -91,2 +92,4 @@ http.open(options.method, url, true);

}
return true;
};

@@ -99,3 +102,3 @@

var http = new XMLHttpRequest();
http.open("GET", url, true);
http.open('GET', url, true);

@@ -120,2 +123,4 @@ if (options.withCredentials === true) {

}
return true;
};

@@ -129,2 +134,6 @@

/* @todo fix eslint errors */
/* eslint-disable no-param-reassign, @typescript-eslint/explicit-function-return-type, prefer-promise-reject-errors */
var HttpAPI =

@@ -144,3 +153,7 @@ /*#__PURE__*/

this._promisify = function (options) {
this.endpoint = void 0;
this.headers = void 0;
this.options = void 0;
this.promisify = function (options) {
if (options.success == null && options.error == null) {

@@ -163,13 +176,15 @@ return new Promise(function (resolve, reject) {

}
return null;
};
this._URL = function (path) {
if (typeof _this.endpoint === "function") {
this.URL = function (path) {
if (typeof _this.endpoint === 'function') {
return _this.endpoint() + path;
} else {
return _this.endpoint + path;
}
return _this.endpoint + path;
};
this._finalOptions = function (path, data, options, method) {
this.finalOptions = function (path, data, options, method) {
var parsedData = JSON.stringify(data);

@@ -205,3 +220,3 @@ var finalOptions = LC_OBJECT_ASSIGN({}, options);

if (responseText.error === "wrong region") {
if (responseText.error === 'wrong region') {
if (_this.options.onIncorrectRegion) {

@@ -224,16 +239,16 @@ _this.options.onIncorrectRegion(responseText.region);

this._get = function (path, options) {
Http$1.get(_this._URL(path), _this._finalOptions(path, {}, options, "_get"));
this.get = function (path, options) {
Http$1.get(_this.URL(path), _this.finalOptions(path, {}, options, 'get'));
};
this._post = function (path, data, options) {
Http$1.submit(_this._URL(path), _this._finalOptions(path, data, options, "_post"));
this.post = function (path, data, options) {
Http$1.submit(_this.URL(path), _this.finalOptions(path, data, options, 'post'));
};
this._put = function (path, data, options) {
options.method = "PUT";
Http$1.submit(_this._URL(path), _this._finalOptions(path, data, options, "_put"));
this.put = function (path, data, options) {
options.method = 'PUT';
Http$1.submit(_this.URL(path), _this.finalOptions(path, data, options, 'put'));
};
this._setDefaults = function (options) {
this.setDefaults = function (options) {
options = options || {};

@@ -277,10 +292,11 @@ options.headers = options.headers || {};

_this._get("/info?code=" + code + "&type=code", options);
_this.get("/info?code=" + code + "&type=code", options);
};
_this.getInfoByAccessToken = function (accessToken, options) {
if (options === void 0) {
options = {};
_this.getInfoByAccessToken = function (accessToken, opts) {
if (opts === void 0) {
opts = {};
}
var options = opts;
options.headers = LC_OBJECT_ASSIGN({

@@ -290,3 +306,3 @@ Authorization: "Bearer " + accessToken

_this._get("/info", options);
_this.get('/info', options);
};

@@ -316,3 +332,3 @@

value: value,
expires_in: new Date().getTime() + expirationInSeconds * 1000
expiresIn: new Date().getTime() + expirationInSeconds * 1000
};

@@ -322,3 +338,4 @@

localStorage.setItem(key, JSON.stringify(data));
} catch (e) {}
} catch (e) {//
}
};

@@ -336,3 +353,3 @@

if (data !== null) {
if (data.expires_in !== null && data.expires_in < new Date().getTime()) {
if (data.expiresIn !== null && data.expiresIn < new Date().getTime()) {
localStorage.removeItem(key);

@@ -350,3 +367,4 @@ } else {

localStorage.removeItem(key);
} catch (e) {}
} catch (e) {//
}
};

@@ -367,7 +385,7 @@

var _variables = {
"popup-window-name": "livechat-login-popup",
"console-url": "https://developers.livechatinc.com/console/",
"login-button-class": "livechat-login-button",
"cache-prefix": "livechat_cache",
"text-button-product-name": "Live<span>Chat</span>"
'popup-window-name': 'livechat-login-popup',
'console-url': 'https://developers.livechatinc.com/console/',
'login-button-class': 'livechat-login-button',
'cache-prefix': 'livechat_cache',
'text-button-product-name': 'Live<span>Chat</span>'
};

@@ -379,3 +397,3 @@

var _postMessageDomain = "https://accounts.livechatinc.com";
var _postMessageDomain = 'https://accounts.livechatinc.com';

@@ -387,3 +405,3 @@ var SDK = function SDK(_options) {

client_id: null,
response_type: "token",
response_type: 'token',
linkLabel: null,

@@ -393,10 +411,10 @@ onIdentityFetched: function onIdentityFetched() {},

queryStringParams: {
utm_source: "accounts.livechatinc.com",
utm_medium: "accounts-sdk"
utm_source: 'accounts.livechatinc.com',
utm_medium: 'accounts-sdk'
},
popupRoute: ""
popupRoute: ''
};
this._postMessageUniqueId = null;
this._listenerInited = false;
this._messageReceived = false;
this._tid = false;
this._lastIdentityError = null;

@@ -434,12 +452,12 @@ this._lastIdentityData = null;

redirect_uri: origin,
flow: "button"
}, _this._options.queryStringParams)), _getVar("popup-window-name"), "resizable,scrollbars,width=" + w + ",height=" + h + ",left=" + left + ",top=" + top);
flow: 'button'
}, _this._options.queryStringParams)), _getVar('popup-window-name'), "resizable,scrollbars,width=" + w + ",height=" + h + ",left=" + left + ",top=" + top);
};
this.signOut = function (callback) {
if (typeof callback === "function") {
if (typeof callback === 'function') {
_this._options.onSignedOut = callback;
}
return _this._buildIframe("signout");
return _this._buildIframe('signout');
};

@@ -450,4 +468,4 @@

if (opts.internalCall !== true && _this._lastIdentityError && _this._lastIdentityError.oauth_exception === "invalid_request") {
_this._displayError(["Button could not be displayed. Probably you are running this script on a domain that is not whitelisted in your app's settings.", "Visit developers console to update your app's domain list: " + _getVar("console-url")]);
if (opts.internalCall !== true && _this._lastIdentityError && _this._lastIdentityError.oauth_exception === 'invalid_request') {
_this._displayError(["Button could not be displayed. Probably you are running this script on a domain that is not whitelisted in your app's settings.", "Visit developers console to update your app's domain list: " + _getVar('console-url')]);

@@ -458,13 +476,13 @@ return false;

var elements = document.getElementsByClassName(_getVar("login-button-class"));
var elements = document.getElementsByClassName(_getVar('login-button-class'));
if (elements.length > 0) {
// include Lato font
var link = document.createElement("link");
link.id = _getVar("login-button-class") + "-font";
link.rel = "stylesheet";
link.href = "//fonts.googleapis.com/css?family=Lato:300,400,700,900";
var link = document.createElement('link');
link.id = _getVar('login-button-class') + "-font";
link.rel = 'stylesheet';
link.href = '//fonts.googleapis.com/css?family=Lato:300,400,700,900';
document.head.appendChild(link); // include CSS styles
document.head.insertAdjacentHTML("beforeend", "<style>" + ("." + _getVar("login-button-class") + " a {") + ["color: #5a6976", "display: inline-block", "font-size: 16px", "line-height: 1.5", 'font-family: "Lato", sans-serif', "font-weight: 400", "text-decoration: none", "border: 1px solid #ddd", "border-radius: 3px", "padding: 8px 24px 9px"].join(";") + "}" + ("." + _getVar("login-button-class") + " a:hover {") + ["border-color: #888", "color: #5a6976"].join(";") + "}" + ("." + _getVar("login-button-class") + " span {") + ["color: #f56e21"].join(";") + "</style>"); // inject <a> link with button
document.head.insertAdjacentHTML('beforeend', "" + ('<style>' + ("." + _getVar('login-button-class') + " a {")) + ['color: #5a6976', 'display: inline-block', 'font-size: 16px', 'line-height: 1.5', 'font-family: "Lato", sans-serif', 'font-weight: 400', 'text-decoration: none', 'border: 1px solid #ddd', 'border-radius: 3px', 'padding: 8px 24px 9px'].join(';') + "}" + ("." + _getVar('login-button-class') + " a:hover {" + ['border-color: #888', 'color: #5a6976'].join(';') + "}") + ("." + _getVar('login-button-class') + " span {" + ['color: #f56e21'].join(';') + "</style>")); // inject <a> link with button

@@ -474,6 +492,6 @@ for (var i = 0, len = elements.length; i < len; i++) {

if (element.getAttribute("data-inited") !== "1") {
element.setAttribute("data-inited", "1");
var a = document.createElement("a");
a.href = "";
if (element.getAttribute('data-inited') !== '1') {
element.setAttribute('data-inited', '1');
var a = document.createElement('a');
a.href = '';
a.onclick = _this.openPopup;

@@ -484,3 +502,3 @@

} else {
a.innerHTML = "Sign in with <strong>" + _getVar("text-button-product-name") + "</strong>";
a.innerHTML = "Sign in with <strong>" + _getVar('text-button-product-name') + "</strong>";
}

@@ -523,3 +541,3 @@

response.expires_in = successResponse.expires_in;
response.scopes = successResponse.scope ? successResponse.scope.split(",") : [];
response.scopes = successResponse.scope ? successResponse.scope.split(',') : [];

@@ -546,3 +564,3 @@ _this._onIdentityFetched(null, response);

response.expires_in = successResponse.expires_in;
response.scopes = successResponse.scope ? successResponse.scope.split(",") : [];
response.scopes = successResponse.scope ? successResponse.scope.split(',') : [];

@@ -579,2 +597,23 @@ _this._onIdentityFetched(null, response);

this._parseJwt = function (token) {
var base64Url = token.split('.')[1];
var base64 = base64Url.replace(/-/g, '+').replace(/_/g, '/');
var jsonPayload = decodeURIComponent(atob(base64).split('').map(function (c) {
return "%" + ("00" + c.charCodeAt(0).toString(16)).slice(-2);
}).join(''));
return JSON.parse(jsonPayload);
};
this._checkPostMessageUniqueId = function (state) {
if (state === _this._postMessageUniqueId) {
return true;
}
try {
return _this._parseJwt(state).state === _this._postMessageUniqueId;
} catch (e) {
return false;
}
};
this._receiveMessage = function (event) {

@@ -585,7 +624,7 @@ if (event.origin !== _postMessageDomain) {

if (!event.data || !event.data.state || event.data.state !== _this._postMessageUniqueId) {
if (!event.data || !event.data.state || !_this._checkPostMessageUniqueId(event.data.state)) {
return;
}
_this._messageReceived = true;
clearTimeout(_this._tid);

@@ -607,8 +646,8 @@ _this._removeIframe();

if (_this._lastIdentityError) {
if (_this._lastIdentityError.oauth_exception === "invalid_request") {
_this._displayError(["Authorization process returned 'invalid_request' error.", "Probably you are running this script on a domain that is not whitelisted in your app's settings.", "Visit developers console to update your app's domain list: " + _getVar("console-url")]);
} else if (_this._lastIdentityError.oauth_exception === "access_denied") {
_this._displayError(["Authorization process returned 'access_denied' error.", "Probably this application is installed on a different account and you do not have access to it."]);
} else if (_this._lastIdentityError.identity_exception === "invalid_request") {
_this._displayError(["Authentication process returned 'invalid_request' error.", "You may be loading accountsSdk on a domain that is not whitelisted."]);
if (_this._lastIdentityError.oauth_exception === 'invalid_request') {
_this._displayError(["Authorization process returned 'invalid_request' error.", "Probably you are running this script on a domain that is not whitelisted in your app's settings.", "Visit developers console to update your app's domain list: " + _getVar('console-url')]);
} else if (_this._lastIdentityError.oauth_exception === 'access_denied') {
_this._displayError(["Authorization process returned 'access_denied' error.", 'Probably this application is installed on a different account and you do not have access to it.']);
} else if (_this._lastIdentityError.identity_exception === 'invalid_request') {
_this._displayError(["Authentication process returned 'invalid_request' error.", 'You may be loading accountsSdk on a domain that is not whitelisted.']);
}

@@ -631,9 +670,11 @@ }

if (endpoint === void 0) {
endpoint = "";
endpoint = '';
}
_this._startListening();
_this._startListening({
timeout: 5000
});
var iframe = document.createElement("iframe");
iframe.setAttribute("src", _postMessageDomain + "/" + endpoint + buildQueryString(_extends({
var iframe = document.createElement('iframe');
iframe.setAttribute('src', _postMessageDomain + "/" + endpoint + buildQueryString(_extends({
client_id: _this._options.client_id,

@@ -643,12 +684,12 @@ state: _this._postMessageUniqueId,

redirect_uri: _this._getCurrentPath(),
flow: "button"
flow: 'button'
}, _this._options.queryStringParams)));
iframe.setAttribute("id", _this._getIframeId());
iframe.style.width = "1px";
iframe.style.height = "1px";
iframe.style.position = "fixed";
iframe.style.top = "0";
iframe.style.right = "0";
iframe.style.opacity = "0";
iframe.style.visibility = "none";
iframe.setAttribute('id', _this._getIframeId());
iframe.style.width = '1px';
iframe.style.height = '1px';
iframe.style.position = 'fixed';
iframe.style.top = '0';
iframe.style.right = '0';
iframe.style.opacity = '0';
iframe.style.visibility = 'none';
document.body.appendChild(iframe);

@@ -658,7 +699,7 @@ };

this._getCurrentPath = function () {
return window.location.protocol + "//" + window.location.hostname + (window.location.port ? ":" + window.location.port : "") + window.location.pathname;
return window.location.protocol + "//" + window.location.hostname + (window.location.port ? ":" + window.location.port : '') + window.location.pathname;
};
this._getCacheKey = function () {
return _getVar("cache-prefix") + "." + _this._options.client_id + "." + _this._options.response_type;
return _getVar('cache-prefix') + "." + _this._options.client_id + "." + _this._options.response_type;
};

@@ -679,6 +720,10 @@

this._getIframeId = function () {
return _getVar("login-button-class") + "-iframe." + _this._options.client_id + "." + _this._options.response_type;
return _getVar('login-button-class') + "-iframe." + _this._options.client_id + "." + _this._options.response_type;
};
this._startListening = function () {
this._startListening = function (options) {
if (options === void 0) {
options = {};
}
if (_this._listenerInited) {

@@ -688,5 +733,12 @@ return false;

if (options.timeout) {
_this._tid = setTimeout(function () {
this._parseError({
identity_exception: 'invalid_request'
});
}, options.timeout);
}
_this._listenerInited = true;
_this._messageReceived = false;
window.addEventListener("message", _this._receiveMessage, false);
window.addEventListener('message', _this._receiveMessage, false);
};

@@ -696,3 +748,3 @@

_this._listenerInited = false;
window.removeEventListener("message", _this._receiveMessage, false);
window.removeEventListener('message', _this._receiveMessage, false);
};

@@ -717,10 +769,2 @@

_this._buildIframe();
setTimeout(function () {
if (!_this._messageReceived) {
_this._parseError({
identity_exception: "invalid_request"
});
}
}, 5000);
}

@@ -727,0 +771,0 @@ };

@@ -59,2 +59,3 @@ var LC_OBJECT_ASSIGN = (function () {

/* eslint-disable no-param-reassign, @typescript-eslint/explicit-function-return-type */
var Http = function Http() {

@@ -69,3 +70,3 @@ this.submit = function (url, options) {

options.method = options.method || "POST";
options.method = options.method || 'POST';
var http = new XMLHttpRequest();

@@ -87,2 +88,4 @@ http.open(options.method, url, true);

}
return true;
};

@@ -95,3 +98,3 @@

var http = new XMLHttpRequest();
http.open("GET", url, true);
http.open('GET', url, true);

@@ -116,2 +119,4 @@ if (options.withCredentials === true) {

}
return true;
};

@@ -125,2 +130,6 @@

/* @todo fix eslint errors */
/* eslint-disable no-param-reassign, @typescript-eslint/explicit-function-return-type, prefer-promise-reject-errors */
var HttpAPI =

@@ -140,3 +149,7 @@ /*#__PURE__*/

this._promisify = function (options) {
this.endpoint = void 0;
this.headers = void 0;
this.options = void 0;
this.promisify = function (options) {
if (options.success == null && options.error == null) {

@@ -159,13 +172,15 @@ return new Promise(function (resolve, reject) {

}
return null;
};
this._URL = function (path) {
if (typeof _this.endpoint === "function") {
this.URL = function (path) {
if (typeof _this.endpoint === 'function') {
return _this.endpoint() + path;
} else {
return _this.endpoint + path;
}
return _this.endpoint + path;
};
this._finalOptions = function (path, data, options, method) {
this.finalOptions = function (path, data, options, method) {
var parsedData = JSON.stringify(data);

@@ -201,3 +216,3 @@ var finalOptions = LC_OBJECT_ASSIGN({}, options);

if (responseText.error === "wrong region") {
if (responseText.error === 'wrong region') {
if (_this.options.onIncorrectRegion) {

@@ -220,16 +235,16 @@ _this.options.onIncorrectRegion(responseText.region);

this._get = function (path, options) {
Http$1.get(_this._URL(path), _this._finalOptions(path, {}, options, "_get"));
this.get = function (path, options) {
Http$1.get(_this.URL(path), _this.finalOptions(path, {}, options, 'get'));
};
this._post = function (path, data, options) {
Http$1.submit(_this._URL(path), _this._finalOptions(path, data, options, "_post"));
this.post = function (path, data, options) {
Http$1.submit(_this.URL(path), _this.finalOptions(path, data, options, 'post'));
};
this._put = function (path, data, options) {
options.method = "PUT";
Http$1.submit(_this._URL(path), _this._finalOptions(path, data, options, "_put"));
this.put = function (path, data, options) {
options.method = 'PUT';
Http$1.submit(_this.URL(path), _this.finalOptions(path, data, options, 'put'));
};
this._setDefaults = function (options) {
this.setDefaults = function (options) {
options = options || {};

@@ -273,10 +288,11 @@ options.headers = options.headers || {};

_this._get("/info?code=" + code + "&type=code", options);
_this.get("/info?code=" + code + "&type=code", options);
};
_this.getInfoByAccessToken = function (accessToken, options) {
if (options === void 0) {
options = {};
_this.getInfoByAccessToken = function (accessToken, opts) {
if (opts === void 0) {
opts = {};
}
var options = opts;
options.headers = LC_OBJECT_ASSIGN({

@@ -286,3 +302,3 @@ Authorization: "Bearer " + accessToken

_this._get("/info", options);
_this.get('/info', options);
};

@@ -312,3 +328,3 @@

value: value,
expires_in: new Date().getTime() + expirationInSeconds * 1000
expiresIn: new Date().getTime() + expirationInSeconds * 1000
};

@@ -318,3 +334,4 @@

localStorage.setItem(key, JSON.stringify(data));
} catch (e) {}
} catch (e) {//
}
};

@@ -332,3 +349,3 @@

if (data !== null) {
if (data.expires_in !== null && data.expires_in < new Date().getTime()) {
if (data.expiresIn !== null && data.expiresIn < new Date().getTime()) {
localStorage.removeItem(key);

@@ -346,3 +363,4 @@ } else {

localStorage.removeItem(key);
} catch (e) {}
} catch (e) {//
}
};

@@ -363,7 +381,7 @@

var _variables = {
"popup-window-name": "livechat-login-popup",
"console-url": "https://developers.livechatinc.com/console/",
"login-button-class": "livechat-login-button",
"cache-prefix": "livechat_cache",
"text-button-product-name": "Live<span>Chat</span>"
'popup-window-name': 'livechat-login-popup',
'console-url': 'https://developers.livechatinc.com/console/',
'login-button-class': 'livechat-login-button',
'cache-prefix': 'livechat_cache',
'text-button-product-name': 'Live<span>Chat</span>'
};

@@ -375,3 +393,3 @@

var _postMessageDomain = "https://accounts.livechatinc.com";
var _postMessageDomain = 'https://accounts.livechatinc.com';

@@ -383,3 +401,3 @@ var SDK = function SDK(_options) {

client_id: null,
response_type: "token",
response_type: 'token',
linkLabel: null,

@@ -389,10 +407,10 @@ onIdentityFetched: function onIdentityFetched() {},

queryStringParams: {
utm_source: "accounts.livechatinc.com",
utm_medium: "accounts-sdk"
utm_source: 'accounts.livechatinc.com',
utm_medium: 'accounts-sdk'
},
popupRoute: ""
popupRoute: ''
};
this._postMessageUniqueId = null;
this._listenerInited = false;
this._messageReceived = false;
this._tid = false;
this._lastIdentityError = null;

@@ -430,12 +448,12 @@ this._lastIdentityData = null;

redirect_uri: origin,
flow: "button"
}, _this._options.queryStringParams)), _getVar("popup-window-name"), "resizable,scrollbars,width=" + w + ",height=" + h + ",left=" + left + ",top=" + top);
flow: 'button'
}, _this._options.queryStringParams)), _getVar('popup-window-name'), "resizable,scrollbars,width=" + w + ",height=" + h + ",left=" + left + ",top=" + top);
};
this.signOut = function (callback) {
if (typeof callback === "function") {
if (typeof callback === 'function') {
_this._options.onSignedOut = callback;
}
return _this._buildIframe("signout");
return _this._buildIframe('signout');
};

@@ -446,4 +464,4 @@

if (opts.internalCall !== true && _this._lastIdentityError && _this._lastIdentityError.oauth_exception === "invalid_request") {
_this._displayError(["Button could not be displayed. Probably you are running this script on a domain that is not whitelisted in your app's settings.", "Visit developers console to update your app's domain list: " + _getVar("console-url")]);
if (opts.internalCall !== true && _this._lastIdentityError && _this._lastIdentityError.oauth_exception === 'invalid_request') {
_this._displayError(["Button could not be displayed. Probably you are running this script on a domain that is not whitelisted in your app's settings.", "Visit developers console to update your app's domain list: " + _getVar('console-url')]);

@@ -454,13 +472,13 @@ return false;

var elements = document.getElementsByClassName(_getVar("login-button-class"));
var elements = document.getElementsByClassName(_getVar('login-button-class'));
if (elements.length > 0) {
// include Lato font
var link = document.createElement("link");
link.id = _getVar("login-button-class") + "-font";
link.rel = "stylesheet";
link.href = "//fonts.googleapis.com/css?family=Lato:300,400,700,900";
var link = document.createElement('link');
link.id = _getVar('login-button-class') + "-font";
link.rel = 'stylesheet';
link.href = '//fonts.googleapis.com/css?family=Lato:300,400,700,900';
document.head.appendChild(link); // include CSS styles
document.head.insertAdjacentHTML("beforeend", "<style>" + ("." + _getVar("login-button-class") + " a {") + ["color: #5a6976", "display: inline-block", "font-size: 16px", "line-height: 1.5", 'font-family: "Lato", sans-serif', "font-weight: 400", "text-decoration: none", "border: 1px solid #ddd", "border-radius: 3px", "padding: 8px 24px 9px"].join(";") + "}" + ("." + _getVar("login-button-class") + " a:hover {") + ["border-color: #888", "color: #5a6976"].join(";") + "}" + ("." + _getVar("login-button-class") + " span {") + ["color: #f56e21"].join(";") + "</style>"); // inject <a> link with button
document.head.insertAdjacentHTML('beforeend', "" + ('<style>' + ("." + _getVar('login-button-class') + " a {")) + ['color: #5a6976', 'display: inline-block', 'font-size: 16px', 'line-height: 1.5', 'font-family: "Lato", sans-serif', 'font-weight: 400', 'text-decoration: none', 'border: 1px solid #ddd', 'border-radius: 3px', 'padding: 8px 24px 9px'].join(';') + "}" + ("." + _getVar('login-button-class') + " a:hover {" + ['border-color: #888', 'color: #5a6976'].join(';') + "}") + ("." + _getVar('login-button-class') + " span {" + ['color: #f56e21'].join(';') + "</style>")); // inject <a> link with button

@@ -470,6 +488,6 @@ for (var i = 0, len = elements.length; i < len; i++) {

if (element.getAttribute("data-inited") !== "1") {
element.setAttribute("data-inited", "1");
var a = document.createElement("a");
a.href = "";
if (element.getAttribute('data-inited') !== '1') {
element.setAttribute('data-inited', '1');
var a = document.createElement('a');
a.href = '';
a.onclick = _this.openPopup;

@@ -480,3 +498,3 @@

} else {
a.innerHTML = "Sign in with <strong>" + _getVar("text-button-product-name") + "</strong>";
a.innerHTML = "Sign in with <strong>" + _getVar('text-button-product-name') + "</strong>";
}

@@ -519,3 +537,3 @@

response.expires_in = successResponse.expires_in;
response.scopes = successResponse.scope ? successResponse.scope.split(",") : [];
response.scopes = successResponse.scope ? successResponse.scope.split(',') : [];

@@ -542,3 +560,3 @@ _this._onIdentityFetched(null, response);

response.expires_in = successResponse.expires_in;
response.scopes = successResponse.scope ? successResponse.scope.split(",") : [];
response.scopes = successResponse.scope ? successResponse.scope.split(',') : [];

@@ -575,2 +593,23 @@ _this._onIdentityFetched(null, response);

this._parseJwt = function (token) {
var base64Url = token.split('.')[1];
var base64 = base64Url.replace(/-/g, '+').replace(/_/g, '/');
var jsonPayload = decodeURIComponent(atob(base64).split('').map(function (c) {
return "%" + ("00" + c.charCodeAt(0).toString(16)).slice(-2);
}).join(''));
return JSON.parse(jsonPayload);
};
this._checkPostMessageUniqueId = function (state) {
if (state === _this._postMessageUniqueId) {
return true;
}
try {
return _this._parseJwt(state).state === _this._postMessageUniqueId;
} catch (e) {
return false;
}
};
this._receiveMessage = function (event) {

@@ -581,7 +620,7 @@ if (event.origin !== _postMessageDomain) {

if (!event.data || !event.data.state || event.data.state !== _this._postMessageUniqueId) {
if (!event.data || !event.data.state || !_this._checkPostMessageUniqueId(event.data.state)) {
return;
}
_this._messageReceived = true;
clearTimeout(_this._tid);

@@ -603,8 +642,8 @@ _this._removeIframe();

if (_this._lastIdentityError) {
if (_this._lastIdentityError.oauth_exception === "invalid_request") {
_this._displayError(["Authorization process returned 'invalid_request' error.", "Probably you are running this script on a domain that is not whitelisted in your app's settings.", "Visit developers console to update your app's domain list: " + _getVar("console-url")]);
} else if (_this._lastIdentityError.oauth_exception === "access_denied") {
_this._displayError(["Authorization process returned 'access_denied' error.", "Probably this application is installed on a different account and you do not have access to it."]);
} else if (_this._lastIdentityError.identity_exception === "invalid_request") {
_this._displayError(["Authentication process returned 'invalid_request' error.", "You may be loading accountsSdk on a domain that is not whitelisted."]);
if (_this._lastIdentityError.oauth_exception === 'invalid_request') {
_this._displayError(["Authorization process returned 'invalid_request' error.", "Probably you are running this script on a domain that is not whitelisted in your app's settings.", "Visit developers console to update your app's domain list: " + _getVar('console-url')]);
} else if (_this._lastIdentityError.oauth_exception === 'access_denied') {
_this._displayError(["Authorization process returned 'access_denied' error.", 'Probably this application is installed on a different account and you do not have access to it.']);
} else if (_this._lastIdentityError.identity_exception === 'invalid_request') {
_this._displayError(["Authentication process returned 'invalid_request' error.", 'You may be loading accountsSdk on a domain that is not whitelisted.']);
}

@@ -627,9 +666,11 @@ }

if (endpoint === void 0) {
endpoint = "";
endpoint = '';
}
_this._startListening();
_this._startListening({
timeout: 5000
});
var iframe = document.createElement("iframe");
iframe.setAttribute("src", _postMessageDomain + "/" + endpoint + buildQueryString(_extends({
var iframe = document.createElement('iframe');
iframe.setAttribute('src', _postMessageDomain + "/" + endpoint + buildQueryString(_extends({
client_id: _this._options.client_id,

@@ -639,12 +680,12 @@ state: _this._postMessageUniqueId,

redirect_uri: _this._getCurrentPath(),
flow: "button"
flow: 'button'
}, _this._options.queryStringParams)));
iframe.setAttribute("id", _this._getIframeId());
iframe.style.width = "1px";
iframe.style.height = "1px";
iframe.style.position = "fixed";
iframe.style.top = "0";
iframe.style.right = "0";
iframe.style.opacity = "0";
iframe.style.visibility = "none";
iframe.setAttribute('id', _this._getIframeId());
iframe.style.width = '1px';
iframe.style.height = '1px';
iframe.style.position = 'fixed';
iframe.style.top = '0';
iframe.style.right = '0';
iframe.style.opacity = '0';
iframe.style.visibility = 'none';
document.body.appendChild(iframe);

@@ -654,7 +695,7 @@ };

this._getCurrentPath = function () {
return window.location.protocol + "//" + window.location.hostname + (window.location.port ? ":" + window.location.port : "") + window.location.pathname;
return window.location.protocol + "//" + window.location.hostname + (window.location.port ? ":" + window.location.port : '') + window.location.pathname;
};
this._getCacheKey = function () {
return _getVar("cache-prefix") + "." + _this._options.client_id + "." + _this._options.response_type;
return _getVar('cache-prefix') + "." + _this._options.client_id + "." + _this._options.response_type;
};

@@ -675,6 +716,10 @@

this._getIframeId = function () {
return _getVar("login-button-class") + "-iframe." + _this._options.client_id + "." + _this._options.response_type;
return _getVar('login-button-class') + "-iframe." + _this._options.client_id + "." + _this._options.response_type;
};
this._startListening = function () {
this._startListening = function (options) {
if (options === void 0) {
options = {};
}
if (_this._listenerInited) {

@@ -684,5 +729,12 @@ return false;

if (options.timeout) {
_this._tid = setTimeout(function () {
this._parseError({
identity_exception: 'invalid_request'
});
}, options.timeout);
}
_this._listenerInited = true;
_this._messageReceived = false;
window.addEventListener("message", _this._receiveMessage, false);
window.addEventListener('message', _this._receiveMessage, false);
};

@@ -692,3 +744,3 @@

_this._listenerInited = false;
window.removeEventListener("message", _this._receiveMessage, false);
window.removeEventListener('message', _this._receiveMessage, false);
};

@@ -713,10 +765,2 @@

_this._buildIframe();
setTimeout(function () {
if (!_this._messageReceived) {
_this._parseError({
identity_exception: "invalid_request"
});
}
}, 5000);
}

@@ -723,0 +767,0 @@ };

{
"name": "@livechat/accounts-sdk",
"version": "1.3.1",
"version": "1.3.2",
"description": "SDK for 'Sign in with LiveChat'. Read more here: https://developers.livechatinc.com/docs/sign-in-with-livechat/",
"main": "./dist/index.cjs.js",
"module": "./dist/index.esm.js",
"unpkg": "./dist/index.js",
"unpkg": "./dist/accounts-sdk.min.js",
"types": "./index.d.ts",
"author": "LiveChat, Inc.",

@@ -13,3 +14,2 @@ "license": "MIT",

],
"types": "./dist/index.d.ts",
"scripts": {

@@ -19,3 +19,3 @@ "prepare": "npm run build",

"prebuild": "rimraf dist && mkdir dist",
"build": "cp src/index.d.ts dist/ && rollup -c && cp dist/index.js dist/accounts-sdk.min.js"
"build": "rollup -c"
},

@@ -26,2 +26,3 @@ "devDependencies": {

"@babel/preset-env": "^7.4.4",
"@babel/preset-typescript": "^7.3.3",
"rimraf": "^2.6.2",

@@ -31,2 +32,3 @@ "rollup": "^1.12.3",

"rollup-plugin-legacy": "^1.0.0",
"rollup-plugin-node-resolve": "^5.2.0",
"rollup-plugin-replace": "^2.2.0",

@@ -33,0 +35,0 @@ "rollup-plugin-uglify": "^6.0.0"

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc