customerio-gist-web 3.6.13 → 3.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/gist.min.js +1 -1
- package/package.json +1 -1
- package/src/managers/queue-manager.js +29 -22
- package/src/services/queue-service.js +32 -3
package/dist/gist.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.Gist=t():e.Gist=t()}(this,(function(){return function(e){var t={};function n(r){if(t[r])return t[r].exports;var s=t[r]={i:r,l:!1,exports:{}};return e[r].call(s.exports,s,s.exports,n),s.l=!0,s.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var s in e)n.d(r,s,function(t){return e[t]}.bind(null,s));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=11)}([function(e,t,n){"use strict";var r=n(2),s=Object.prototype.toString;function i(e){return"[object Array]"===s.call(e)}function o(e){return void 0===e}function a(e){return null!==e&&"object"==typeof e}function u(e){if("[object Object]"!==s.call(e))return!1;var t=Object.getPrototypeOf(e);return null===t||t===Object.prototype}function c(e){return"[object Function]"===s.call(e)}function d(e,t){if(null!=e)if("object"!=typeof e&&(e=[e]),i(e))for(var n=0,r=e.length;n<r;n++)t.call(null,e[n],n,e);else for(var s in e)Object.prototype.hasOwnProperty.call(e,s)&&t.call(null,e[s],s,e)}e.exports={isArray:i,isArrayBuffer:function(e){return"[object ArrayBuffer]"===s.call(e)},isBuffer:function(e){return null!==e&&!o(e)&&null!==e.constructor&&!o(e.constructor)&&"function"==typeof e.constructor.isBuffer&&e.constructor.isBuffer(e)},isFormData:function(e){return"undefined"!=typeof FormData&&e instanceof FormData},isArrayBufferView:function(e){return"undefined"!=typeof ArrayBuffer&&ArrayBuffer.isView?ArrayBuffer.isView(e):e&&e.buffer&&e.buffer instanceof ArrayBuffer},isString:function(e){return"string"==typeof e},isNumber:function(e){return"number"==typeof e},isObject:a,isPlainObject:u,isUndefined:o,isDate:function(e){return"[object Date]"===s.call(e)},isFile:function(e){return"[object File]"===s.call(e)},isBlob:function(e){return"[object Blob]"===s.call(e)},isFunction:c,isStream:function(e){return a(e)&&c(e.pipe)},isURLSearchParams:function(e){return"undefined"!=typeof URLSearchParams&&e instanceof URLSearchParams},isStandardBrowserEnv:function(){return("undefined"==typeof navigator||"ReactNative"!==navigator.product&&"NativeScript"!==navigator.product&&"NS"!==navigator.product)&&("undefined"!=typeof window&&"undefined"!=typeof document)},forEach:d,merge:function e(){var t={};function n(n,r){u(t[r])&&u(n)?t[r]=e(t[r],n):u(n)?t[r]=e({},n):i(n)?t[r]=n.slice():t[r]=n}for(var r=0,s=arguments.length;r<s;r++)d(arguments[r],n);return t},extend:function(e,t,n){return d(t,(function(t,s){e[s]=n&&"function"==typeof t?r(t,n):t})),e},trim:function(e){return e.replace(/^\s*/,"").replace(/\s*$/,"")},stripBOM:function(e){return 65279===e.charCodeAt(0)&&(e=e.slice(1)),e}}},,function(e,t,n){"use strict";e.exports=function(e,t){return function(){for(var n=new Array(arguments.length),r=0;r<n.length;r++)n[r]=arguments[r];return e.apply(t,n)}}},function(e,t,n){"use strict";var r=n(0);function s(e){return encodeURIComponent(e).replace(/%3A/gi,":").replace(/%24/g,"$").replace(/%2C/gi,",").replace(/%20/g,"+").replace(/%5B/gi,"[").replace(/%5D/gi,"]")}e.exports=function(e,t,n){if(!t)return e;var i;if(n)i=n(t);else if(r.isURLSearchParams(t))i=t.toString();else{var o=[];r.forEach(t,(function(e,t){null!=e&&(r.isArray(e)?t+="[]":e=[e],r.forEach(e,(function(e){r.isDate(e)?e=e.toISOString():r.isObject(e)&&(e=JSON.stringify(e)),o.push(s(t)+"="+s(e))})))})),i=o.join("&")}if(i){var a=e.indexOf("#");-1!==a&&(e=e.slice(0,a)),e+=(-1===e.indexOf("?")?"?":"&")+i}return e}},function(e,t,n){"use strict";e.exports=function(e){return!(!e||!e.__CANCEL__)}},function(e,t,n){"use strict";(function(t){var r=n(0),s=n(18),i={"Content-Type":"application/x-www-form-urlencoded"};function o(e,t){!r.isUndefined(e)&&r.isUndefined(e["Content-Type"])&&(e["Content-Type"]=t)}var a,u={adapter:(("undefined"!=typeof XMLHttpRequest||void 0!==t&&"[object process]"===Object.prototype.toString.call(t))&&(a=n(6)),a),transformRequest:[function(e,t){return s(t,"Accept"),s(t,"Content-Type"),r.isFormData(e)||r.isArrayBuffer(e)||r.isBuffer(e)||r.isStream(e)||r.isFile(e)||r.isBlob(e)?e:r.isArrayBufferView(e)?e.buffer:r.isURLSearchParams(e)?(o(t,"application/x-www-form-urlencoded;charset=utf-8"),e.toString()):r.isObject(e)?(o(t,"application/json;charset=utf-8"),JSON.stringify(e)):e}],transformResponse:[function(e){if("string"==typeof e)try{e=JSON.parse(e)}catch(e){}return e}],timeout:0,xsrfCookieName:"XSRF-TOKEN",xsrfHeaderName:"X-XSRF-TOKEN",maxContentLength:-1,maxBodyLength:-1,validateStatus:function(e){return e>=200&&e<300}};u.headers={common:{Accept:"application/json, text/plain, */*"}},r.forEach(["delete","get","head"],(function(e){u.headers[e]={}})),r.forEach(["post","put","patch"],(function(e){u.headers[e]=r.merge(i)})),e.exports=u}).call(this,n(17))},function(e,t,n){"use strict";var r=n(0),s=n(19),i=n(21),o=n(3),a=n(22),u=n(25),c=n(26),d=n(7);e.exports=function(e){return new Promise((function(t,n){var f=e.data,l=e.headers;r.isFormData(f)&&delete l["Content-Type"];var p=new XMLHttpRequest;if(e.auth){var g=e.auth.username||"",h=e.auth.password?unescape(encodeURIComponent(e.auth.password)):"";l.Authorization="Basic "+btoa(g+":"+h)}var m=a(e.baseURL,e.url);if(p.open(e.method.toUpperCase(),o(m,e.params,e.paramsSerializer),!0),p.timeout=e.timeout,p.onreadystatechange=function(){if(p&&4===p.readyState&&(0!==p.status||p.responseURL&&0===p.responseURL.indexOf("file:"))){var r="getAllResponseHeaders"in p?u(p.getAllResponseHeaders()):null,i={data:e.responseType&&"text"!==e.responseType?p.response:p.responseText,status:p.status,statusText:p.statusText,headers:r,config:e,request:p};s(t,n,i),p=null}},p.onabort=function(){p&&(n(d("Request aborted",e,"ECONNABORTED",p)),p=null)},p.onerror=function(){n(d("Network Error",e,null,p)),p=null},p.ontimeout=function(){var t="timeout of "+e.timeout+"ms exceeded";e.timeoutErrorMessage&&(t=e.timeoutErrorMessage),n(d(t,e,"ECONNABORTED",p)),p=null},r.isStandardBrowserEnv()){var v=(e.withCredentials||c(m))&&e.xsrfCookieName?i.read(e.xsrfCookieName):void 0;v&&(l[e.xsrfHeaderName]=v)}if("setRequestHeader"in p&&r.forEach(l,(function(e,t){void 0===f&&"content-type"===t.toLowerCase()?delete l[t]:p.setRequestHeader(t,e)})),r.isUndefined(e.withCredentials)||(p.withCredentials=!!e.withCredentials),e.responseType)try{p.responseType=e.responseType}catch(t){if("json"!==e.responseType)throw t}"function"==typeof e.onDownloadProgress&&p.addEventListener("progress",e.onDownloadProgress),"function"==typeof e.onUploadProgress&&p.upload&&p.upload.addEventListener("progress",e.onUploadProgress),e.cancelToken&&e.cancelToken.promise.then((function(e){p&&(p.abort(),n(e),p=null)})),f||(f=null),p.send(f)}))}},function(e,t,n){"use strict";var r=n(20);e.exports=function(e,t,n,s,i){var o=new Error(e);return r(o,t,n,s,i)}},function(e,t,n){"use strict";var r=n(0);e.exports=function(e,t){t=t||{};var n={},s=["url","method","data"],i=["headers","auth","proxy","params"],o=["baseURL","transformRequest","transformResponse","paramsSerializer","timeout","timeoutMessage","withCredentials","adapter","responseType","xsrfCookieName","xsrfHeaderName","onUploadProgress","onDownloadProgress","decompress","maxContentLength","maxBodyLength","maxRedirects","transport","httpAgent","httpsAgent","cancelToken","socketPath","responseEncoding"],a=["validateStatus"];function u(e,t){return r.isPlainObject(e)&&r.isPlainObject(t)?r.merge(e,t):r.isPlainObject(t)?r.merge({},t):r.isArray(t)?t.slice():t}function c(s){r.isUndefined(t[s])?r.isUndefined(e[s])||(n[s]=u(void 0,e[s])):n[s]=u(e[s],t[s])}r.forEach(s,(function(e){r.isUndefined(t[e])||(n[e]=u(void 0,t[e]))})),r.forEach(i,c),r.forEach(o,(function(s){r.isUndefined(t[s])?r.isUndefined(e[s])||(n[s]=u(void 0,e[s])):n[s]=u(void 0,t[s])})),r.forEach(a,(function(r){r in t?n[r]=u(e[r],t[r]):r in e&&(n[r]=u(void 0,e[r]))}));var d=s.concat(i).concat(o).concat(a),f=Object.keys(e).concat(Object.keys(t)).filter((function(e){return-1===d.indexOf(e)}));return r.forEach(f,c),n}},function(e,t,n){"use strict";function r(e){this.message=e}r.prototype.toString=function(){return"Cancel"+(this.message?": "+this.message:"")},r.prototype.__CANCEL__=!0,e.exports=r},function(e,t,n){e.exports=n(12)},function(e,t,n){const r=n(30).default;e.exports=r},function(e,t,n){"use strict";var r=n(0),s=n(2),i=n(13),o=n(8);function a(e){var t=new i(e),n=s(i.prototype.request,t);return r.extend(n,i.prototype,t),r.extend(n,t),n}var u=a(n(5));u.Axios=i,u.create=function(e){return a(o(u.defaults,e))},u.Cancel=n(9),u.CancelToken=n(27),u.isCancel=n(4),u.all=function(e){return Promise.all(e)},u.spread=n(28),u.isAxiosError=n(29),e.exports=u,e.exports.default=u},function(e,t,n){"use strict";var r=n(0),s=n(3),i=n(14),o=n(15),a=n(8);function u(e){this.defaults=e,this.interceptors={request:new i,response:new i}}u.prototype.request=function(e){"string"==typeof e?(e=arguments[1]||{}).url=arguments[0]:e=e||{},(e=a(this.defaults,e)).method?e.method=e.method.toLowerCase():this.defaults.method?e.method=this.defaults.method.toLowerCase():e.method="get";var t=[o,void 0],n=Promise.resolve(e);for(this.interceptors.request.forEach((function(e){t.unshift(e.fulfilled,e.rejected)})),this.interceptors.response.forEach((function(e){t.push(e.fulfilled,e.rejected)}));t.length;)n=n.then(t.shift(),t.shift());return n},u.prototype.getUri=function(e){return e=a(this.defaults,e),s(e.url,e.params,e.paramsSerializer).replace(/^\?/,"")},r.forEach(["delete","get","head","options"],(function(e){u.prototype[e]=function(t,n){return this.request(a(n||{},{method:e,url:t,data:(n||{}).data}))}})),r.forEach(["post","put","patch"],(function(e){u.prototype[e]=function(t,n,r){return this.request(a(r||{},{method:e,url:t,data:n}))}})),e.exports=u},function(e,t,n){"use strict";var r=n(0);function s(){this.handlers=[]}s.prototype.use=function(e,t){return this.handlers.push({fulfilled:e,rejected:t}),this.handlers.length-1},s.prototype.eject=function(e){this.handlers[e]&&(this.handlers[e]=null)},s.prototype.forEach=function(e){r.forEach(this.handlers,(function(t){null!==t&&e(t)}))},e.exports=s},function(e,t,n){"use strict";var r=n(0),s=n(16),i=n(4),o=n(5);function a(e){e.cancelToken&&e.cancelToken.throwIfRequested()}e.exports=function(e){return a(e),e.headers=e.headers||{},e.data=s(e.data,e.headers,e.transformRequest),e.headers=r.merge(e.headers.common||{},e.headers[e.method]||{},e.headers),r.forEach(["delete","get","head","post","put","patch","common"],(function(t){delete e.headers[t]})),(e.adapter||o.adapter)(e).then((function(t){return a(e),t.data=s(t.data,t.headers,e.transformResponse),t}),(function(t){return i(t)||(a(e),t&&t.response&&(t.response.data=s(t.response.data,t.response.headers,e.transformResponse))),Promise.reject(t)}))}},function(e,t,n){"use strict";var r=n(0);e.exports=function(e,t,n){return r.forEach(n,(function(n){e=n(e,t)})),e}},function(e,t){var n,r,s=e.exports={};function i(){throw new Error("setTimeout has not been defined")}function o(){throw new Error("clearTimeout has not been defined")}function a(e){if(n===setTimeout)return setTimeout(e,0);if((n===i||!n)&&setTimeout)return n=setTimeout,setTimeout(e,0);try{return n(e,0)}catch(t){try{return n.call(null,e,0)}catch(t){return n.call(this,e,0)}}}!function(){try{n="function"==typeof setTimeout?setTimeout:i}catch(e){n=i}try{r="function"==typeof clearTimeout?clearTimeout:o}catch(e){r=o}}();var u,c=[],d=!1,f=-1;function l(){d&&u&&(d=!1,u.length?c=u.concat(c):f=-1,c.length&&p())}function p(){if(!d){var e=a(l);d=!0;for(var t=c.length;t;){for(u=c,c=[];++f<t;)u&&u[f].run();f=-1,t=c.length}u=null,d=!1,function(e){if(r===clearTimeout)return clearTimeout(e);if((r===o||!r)&&clearTimeout)return r=clearTimeout,clearTimeout(e);try{r(e)}catch(t){try{return r.call(null,e)}catch(t){return r.call(this,e)}}}(e)}}function g(e,t){this.fun=e,this.array=t}function h(){}s.nextTick=function(e){var t=new Array(arguments.length-1);if(arguments.length>1)for(var n=1;n<arguments.length;n++)t[n-1]=arguments[n];c.push(new g(e,t)),1!==c.length||d||a(p)},g.prototype.run=function(){this.fun.apply(null,this.array)},s.title="browser",s.browser=!0,s.env={},s.argv=[],s.version="",s.versions={},s.on=h,s.addListener=h,s.once=h,s.off=h,s.removeListener=h,s.removeAllListeners=h,s.emit=h,s.prependListener=h,s.prependOnceListener=h,s.listeners=function(e){return[]},s.binding=function(e){throw new Error("process.binding is not supported")},s.cwd=function(){return"/"},s.chdir=function(e){throw new Error("process.chdir is not supported")},s.umask=function(){return 0}},function(e,t,n){"use strict";var r=n(0);e.exports=function(e,t){r.forEach(e,(function(n,r){r!==t&&r.toUpperCase()===t.toUpperCase()&&(e[t]=n,delete e[r])}))}},function(e,t,n){"use strict";var r=n(7);e.exports=function(e,t,n){var s=n.config.validateStatus;n.status&&s&&!s(n.status)?t(r("Request failed with status code "+n.status,n.config,null,n.request,n)):e(n)}},function(e,t,n){"use strict";e.exports=function(e,t,n,r,s){return e.config=t,n&&(e.code=n),e.request=r,e.response=s,e.isAxiosError=!0,e.toJSON=function(){return{message:this.message,name:this.name,description:this.description,number:this.number,fileName:this.fileName,lineNumber:this.lineNumber,columnNumber:this.columnNumber,stack:this.stack,config:this.config,code:this.code}},e}},function(e,t,n){"use strict";var r=n(0);e.exports=r.isStandardBrowserEnv()?{write:function(e,t,n,s,i,o){var a=[];a.push(e+"="+encodeURIComponent(t)),r.isNumber(n)&&a.push("expires="+new Date(n).toGMTString()),r.isString(s)&&a.push("path="+s),r.isString(i)&&a.push("domain="+i),!0===o&&a.push("secure"),document.cookie=a.join("; ")},read:function(e){var t=document.cookie.match(new RegExp("(^|;\\s*)("+e+")=([^;]*)"));return t?decodeURIComponent(t[3]):null},remove:function(e){this.write(e,"",Date.now()-864e5)}}:{write:function(){},read:function(){return null},remove:function(){}}},function(e,t,n){"use strict";var r=n(23),s=n(24);e.exports=function(e,t){return e&&!r(t)?s(e,t):t}},function(e,t,n){"use strict";e.exports=function(e){return/^([a-z][a-z\d\+\-\.]*:)?\/\//i.test(e)}},function(e,t,n){"use strict";e.exports=function(e,t){return t?e.replace(/\/+$/,"")+"/"+t.replace(/^\/+/,""):e}},function(e,t,n){"use strict";var r=n(0),s=["age","authorization","content-length","content-type","etag","expires","from","host","if-modified-since","if-unmodified-since","last-modified","location","max-forwards","proxy-authorization","referer","retry-after","user-agent"];e.exports=function(e){var t,n,i,o={};return e?(r.forEach(e.split("\n"),(function(e){if(i=e.indexOf(":"),t=r.trim(e.substr(0,i)).toLowerCase(),n=r.trim(e.substr(i+1)),t){if(o[t]&&s.indexOf(t)>=0)return;o[t]="set-cookie"===t?(o[t]?o[t]:[]).concat([n]):o[t]?o[t]+", "+n:n}})),o):o}},function(e,t,n){"use strict";var r=n(0);e.exports=r.isStandardBrowserEnv()?function(){var e,t=/(msie|trident)/i.test(navigator.userAgent),n=document.createElement("a");function s(e){var r=e;return t&&(n.setAttribute("href",r),r=n.href),n.setAttribute("href",r),{href:n.href,protocol:n.protocol?n.protocol.replace(/:$/,""):"",host:n.host,search:n.search?n.search.replace(/^\?/,""):"",hash:n.hash?n.hash.replace(/^#/,""):"",hostname:n.hostname,port:n.port,pathname:"/"===n.pathname.charAt(0)?n.pathname:"/"+n.pathname}}return e=s(window.location.href),function(t){var n=r.isString(t)?s(t):t;return n.protocol===e.protocol&&n.host===e.host}}():function(){return!0}},function(e,t,n){"use strict";var r=n(9);function s(e){if("function"!=typeof e)throw new TypeError("executor must be a function.");var t;this.promise=new Promise((function(e){t=e}));var n=this;e((function(e){n.reason||(n.reason=new r(e),t(n.reason))}))}s.prototype.throwIfRequested=function(){if(this.reason)throw this.reason},s.source=function(){var e;return{token:new s((function(t){e=t})),cancel:e}},e.exports=s},function(e,t,n){"use strict";e.exports=function(e){return function(t){return e.apply(null,t)}}},function(e,t,n){"use strict";e.exports=function(e){return"object"==typeof e&&!0===e.isAxiosError}},function(e,t,n){"use strict";n.r(t);class r{on(e,t){var n=this[e];n?n.push(t):this[e]=[t]}dispatch(e,t){var n=this[e];n&&n.forEach(e=>e(t))}}function s(e){Z.config.logging&&console.log("Gist: "+e)}function i(e,t,n){const r={value:t,expiry:n};localStorage.setItem(e,JSON.stringify(r))}function o(e){const t=localStorage.getItem(e);if(!t)return null;const n=JSON.parse(t),r=new Date,s=new Date(n.expiry);return r.getTime()>s.getTime()?(localStorage.removeItem(e),null):n.value}function a(e){localStorage.removeItem(e)}var u,c=new Uint8Array(16);function d(){if(!u&&!(u="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||"undefined"!=typeof msCrypto&&"function"==typeof msCrypto.getRandomValues&&msCrypto.getRandomValues.bind(msCrypto)))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return u(c)}var f=/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i;for(var l=function(e){return"string"==typeof e&&f.test(e)},p=[],g=0;g<256;++g)p.push((g+256).toString(16).substr(1));var h=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,n=(p[e[t+0]]+p[e[t+1]]+p[e[t+2]]+p[e[t+3]]+"-"+p[e[t+4]]+p[e[t+5]]+"-"+p[e[t+6]]+p[e[t+7]]+"-"+p[e[t+8]]+p[e[t+9]]+"-"+p[e[t+10]]+p[e[t+11]]+p[e[t+12]]+p[e[t+13]]+p[e[t+14]]+p[e[t+15]]).toLowerCase();if(!l(n))throw TypeError("Stringified UUID is invalid");return n};var m=function(e,t,n){var r=(e=e||{}).random||(e.rng||d)();if(r[6]=15&r[6]|64,r[8]=63&r[8]|128,t){n=n||0;for(var s=0;s<16;++s)t[n+s]=r[s];return t}return h(r)};function v(){return o("gist.web.userToken")}function y(){var e=new Date;if(e.setDate(e.getDate()+365),null===v()){var t=o("gist.web.guestUserToken");null==t&&(i("gist.web.guestUserToken",t=m(),e),s(`Set guest user token "${t}" with expiry date set to 1 year from today`)),i("gist.web.userToken",t,e),i("gist.web.usingGuestUserToken",!0,e)}}var w=n(10),b=n.n(w);const x={ENGINE_API_ENDPOINT:{prod:"https://engine.api.gist.build",dev:"https://engine.api.dev.gist.build",local:"http://engine.api.local.gist.build:82"},GIST_QUEUE_API_ENDPOINT:{prod:"https://gist-queue-consumer-api.cloud.gist.build",dev:"https://gist-queue-consumer-api.cloud.dev.gist.build",local:"http://api.local.gist.build:86"},GIST_VIEW_ENDPOINT:{prod:"https://renderer.gist.build/2.0",dev:"https://renderer.gist.build/2.0",local:"http://app.local.gist.build:8080/web"}};function I(){var e={"X-CIO-Site-Id":Z.config.siteId,"X-CIO-Datacenter":Z.config.dataCenter},t=v();return null!=t&&(e["X-Gist-Encoded-User-Token"]=btoa(t)),b.a.create({baseURL:x.GIST_QUEUE_API_ENDPOINT[Z.config.env],timeout:2e4,headers:e})}function S(e){var t="",n="",r="",s=!1,i=!1,o=!1,a=!1,u=null,c=!1,d="#00000033",f=414,l=!1;return e.properties&&e.properties.gist&&(e.properties.gist.campaignId&&(u=e.properties.gist.campaignId),e.properties.gist.elementId&&(t=e.properties.gist.elementId,s=!0),e.properties.gist.routeRuleWeb&&(n=e.properties.gist.routeRuleWeb,i=!0),e.properties.gist.position&&(r=e.properties.gist.position,o=!0),e.properties.gist.scale&&(a=e.properties.gist.scale),e.properties.gist.overlayColor&&(d=e.properties.gist.overlayColor),e.properties.gist.messageWidth&&e.properties.gist.messageWidth>0&&(f=e.properties.gist.messageWidth,l=!0),e.properties.gist.persistent&&(c=!0)),{isEmbedded:s,elementId:t,hasRouteRule:i,routeRule:n,position:r,hasPosition:o,shouldScale:a,campaignId:u,messageWidth:f,overlayColor:d,persistent:c,hasCustomWidth:l}}const T=e=>new Promise(t=>setTimeout(t,e));function E(e,t,n){var r=N(e);r?(C(e)||(r.style.height="0px"),r.innerHTML=function(e,t){return function(e,t){var n=800;e.messageWidth>n&&(n=e.messageWidth);var r=e.messageWidth+"px";return["x-gist-top","x-gist-bottom","x-gist-floating-top","x-gist-floating-bottom"].includes(e.elementId)&&!e.hasCustomWidth&&(r="100%"),`\n <div id="gist-embed">\n <style>\n #x-gist-floating-top, #x-gist-floating-top-left, #x-gist-floating-top-right {\n position: fixed;\n top: 0px;\n z-index: 1000000;\n }\n #x-gist-floating-bottom, #x-gist-floating-bottom-left, #x-gist-floating-bottom-right {\n position: fixed;\n bottom: 0px;\n z-index: 1000000;\n }\n #x-gist-bottom, #x-gist-top, #x-gist-floating-top, #x-gist-floating-bottom {\n left: 50%;\n transform: translate(-50%, 0%);\n width: ${r};\n }\n #x-gist-floating-top-left, #x-gist-floating-top-right, #x-gist-floating-bottom-left, #x-gist-floating-bottom-right {\n width: ${r};\n }\n #x-gist-floating-top-right, #x-gist-floating-bottom-right {\n right: 0px;\n }\n #gist-embed {\n position: relative;\n height: 100%;\n width: 100%;\n }\n #gist-embed-container {\n position: relative;\n height: 100%;\n width: 100%;\n }\n #gist-embed-container .gist-frame {\n height: 100%;\n width: 100%;\n border: none;\n }\n @media (max-width: ${n}px) {\n #x-gist-top, #x-gist-bottom, #x-gist-floating-top, #x-gist-floating-bottom, #x-gist-floating-top-left, #x-gist-floating-top-right, #x-gist-floating-bottom-left, #x-gist-floating-bottom-right {\n width: 100%;\n }\n }\n </style>\n <div id="gist-embed-container">\n <iframe class="gist-frame" src="${t}"></iframe>\n </div>\n </div>`}(S(t),e)}(t,n)):s(`Message could not be embedded, elementId ${e} not found.`)}function C(e){var t=N(e);if(t)return t.style&&t.style.height&&"0px"!=t.style.height}function R(e,t,n){var r=N(e);if(r){var s=r.style;if(t.height>0)if(t.height>window.innerHeight){var i=1-(t.height/window.innerHeight-1);n&&i>=.4?(s.height=t.height+"px",s.transform=`translateX(-50%) translateY(-50%) scale(${i})`):s.height=window.innerHeight+"px"}else s.height=t.height+"px"}}function k(e,t){document.body.insertAdjacentHTML("beforeend",function(e,t){return function(e,t){var n=600;return e.messageWidth>n&&(n=e.messageWidth),`\n <div id="gist-embed-message">\n <style>\n #gist-overlay.background {\n position: fixed;\n z-index: 9999999998;\n left: 0;\n top: 0;\n width: 100%;\n height: 100%;\n background-color: ${e.overlayColor};\n visibility: hidden;\n }\n #gist-overlay.background.visible {\n visibility: visible;\n }\n #gist-overlay.background.is-blacked-out {\n display: block;\n }\n #gist-message {\n width: ${e.messageWidth}px;\n position: absolute;\n border: none;\n opacity: 0;\n transition: opacity 0.3s ease-in-out;\n z-index: 9999999999;\n left: 50%;\n transform: translateX(-50%);\n }\n #gist-message.visible {\n opacity: 1;\n }\n #gist-message.center {\n transform: translate(-50%, -50%);\n top: 50%;\n }\n #gist-message.bottom {\n bottom: 0;\n }\n #gist-message.top {\n top: 0;\n }\n @media (max-width: ${n}px) {\n #gist-message {\n width: 100%;\n }\n }\n </style>\n <div id="gist-overlay" class="background">\n <iframe id="gist-message" class="message" src="${t}"></iframe>\n </div>\n </div>`}(S(t),e)}(e,t))}function O(){var e=document.querySelector("#gist-embed-message");e&&e.parentNode.removeChild(e)}function L(){var e=document.querySelector("#gist-message");e&&e.classList.add("visible")}function N(e){try{var t=document.querySelector("#"+e);return t||null}catch{return null}}var P=["x-gist-top","x-gist-floating-top","x-gist-bottom","x-gist-floating-bottom","x-gist-floating-bottom-left","x-gist-floating-bottom-right","x-gist-floating-top-left","x-gist-floating-top-right"];var j=[];async function D(e){if(Z.isDocumentVisible){if(Z.overlayInstanceId)return s(`Message ${Z.overlayInstanceId} already showing.`),null;var t=S(e);return e.instanceId=m(),e.overlay=!0,e.firstLoad=!0,e.shouldResizeHeight=!0,e.shouldScale=t.shouldScale,e.renderStartTime=(new Date).getTime(),Z.overlayInstanceId=e.instanceId,Z.currentMessages.push(e),B(e)}return s("Document hidden, not showing message now."),null}async function U(e,t){return Z.isDocumentVisible?(e.instanceId=m(),e.overlay=!1,e.firstLoad=!0,e.shouldScale=!1,e.elementId=t,e.shouldResizeHeight=!C(t),e.renderStartTime=(new Date).getTime(),Z.currentMessages.push(e),B(e,t)):(s("Document hidden, not showing message now."),null)}async function A(e){e?(Z.messageDismissed(e),e.overlay?await $(!0,e):M(e)):s(`Message with instance id: ${instanceId} not found`)}async function q(e){var t=S(e);e?t.persistent&&(s("Persistent message dismissed, logging view"),await _(e)):s(`Message with instance id: ${instanceId} not found`)}function M(e){var t,n;G(e.instanceId),t=e.elementId,(n=N(t))&&(n.classList.remove("gist-visible"),n.style.removeProperty("height"),n.innerHTML="")}async function $(e,t){G(t.instanceId),Z.overlayInstanceId=null,e?await async function(){var e=document.querySelector("#gist-message");e&&(e.classList.remove("visible"),await T(300)),O()}():O(),0==Z.currentMessages.length&&(window.removeEventListener("message",z),window.removeEventListener("touchstart",V))}function B(e,t=null){if(t&&function(e){var t=N(e);return!(!t||!t.classList.contains("gist-visible"))}(t))return s(`Message ${e.messageId} already showing in element ${t}.`),null;var n,r,i={endpoint:x.ENGINE_API_ENDPOINT[Z.config.env],siteId:Z.config.siteId,dataCenter:Z.config.dataCenter,messageId:e.messageId,instanceId:e.instanceId,livePreview:!1,properties:e.properties},o=`${x.GIST_VIEW_ENDPOINT[Z.config.env]}/index.html?options=${n=JSON.stringify(i),r=btoa(encodeURIComponent(n).replace(/%([0-9A-F]{2})/g,(function(e,t){return String.fromCharCode("0x"+t)}))),encodeURIComponent(r)}`;return window.addEventListener("message",z),window.addEventListener("touchstart",V),t?(P.includes(t)&&function(e){const t=document.createElement("div");switch(t.id=e,e){case"x-gist-top":document.body.insertBefore(t,document.body.firstChild);break;default:document.body.insertAdjacentElement("beforeend",t)}s("Top & bottom elements injected into page")}(t),E(t,o,e)):k(o,e),e}async function _(e){s("Message shown, logging view for: "+e.messageId);var t={};200===(t=null!=e.queueId?await async function(e){try{return await I().post("/api/v1/logs/queue/"+e)}catch(e){return e.response}}(e.queueId):await async function(e){try{return await I().post("/api/v1/logs/message/"+e)}catch(e){return e.response}}(e.messageId)).status?s("Message view logged"):s("Problem logging message: "+t.status)}function W(e){return Z.currentMessages.find(t=>t.instanceId===e)}function G(e){Z.currentMessages=Z.currentMessages.filter(t=>t.instanceId!==e)}function H(e,t){G(e),Z.currentMessages.push(t)}function V(e){}async function z(e){if(e.data.gist){var t=e.data.gist.instanceId,n=W(t);if(!n)return;var r=S(n);switch(e.data.gist.method){case"routeLoaded":var i=.001*((new Date).getTime()-n.renderStartTime);s(`Engine render for message: ${n.messageId} timer elapsed in ${i.toFixed(3)} seconds`),n.currentRoute=e.data.gist.parameters.route,n.firstLoad&&(j.push(n),n.overlay?function(e){var t=document.querySelector("#gist-overlay");if(t){t.classList.add("visible");var n=document.querySelector("#gist-message");e.position?n.classList.add(e.position):n.classList.add("center"),setTimeout(L,100)}else O()}(n):(f=n.elementId,(l=N(f))&&l.classList.add("gist-visible")),Z.messageShown(n),r.persistent?s("Persistent message shown, skipping logging view"):await _(n),n.firstLoad=!1),H(t,n);break;case"tap":var o=e.data.gist.parameters.action,a=e.data.gist.parameters.name;if(Z.messageAction(n,o,a),e.data.gist.parameters.system&&!r.persistent){await A(n);break}try{if((d=new URL(o))&&"gist:"===d.protocol)switch(d.href.replace("gist://","").split("?")[0]){case"close":await A(n),await q(n),await K();break;case"showMessage":var u=d.searchParams.get("messageId"),c=d.searchParams.get("properties");u&&(c&&(c=JSON.parse(atob(c))),await Z.showMessage({messageId:u,properties:c}));break;case"loadPage":var d;(d=d.href.substring(d.href.indexOf("?url=")+5))&&(d.startsWith("https://")||d.startsWith("http://")||d.startsWith("/")?window.location.href=d:window.location.href=window.location+d)}}catch(e){}break;case"routeChanged":n.currentRoute=e.data.gist.parameters.route,n.renderStartTime=(new Date).getTime(),H(t,n),s("Route changed to: "+n.currentRoute);break;case"sizeChanged":s(`Size Changed Width: ${e.data.gist.parameters.width} - Height: ${e.data.gist.parameters.height}`),n.elementId&&n.shouldResizeHeight?R(n.elementId,e.data.gist.parameters,n.shouldScale):R("gist-message",e.data.gist.parameters,n.shouldScale);break;case"error":case"routeError":Z.messageError(n),Z.overlayInstanceId?$(!1,n):M(n)}}var f,l}var F=(e,t)=>e().then((e=>new Promise(t=>setTimeout(t,e)))(t).then(()=>F(e,t))),X=!1,J=[];async function Q(){X?await K():(!async function(){var e="G"+m().substring(0,8),t=document.createElement("div");t.setAttribute("id",e),t.style.display="none",document.body.appendChild(t),await T(5e3),U({messageId:""},e)}(),v()?(s("Queue watcher started"),X=!0,F(()=>new Promise(()=>async function(){if(v())if(Z.isDocumentVisible){var e=await async function(){try{return await I().post("/api/v1/users",{})}catch(e){return e.response}}(),t=[];if(e){if(200===e.status||204===e.status){var n=new Date((new Date).getTime()+6e4);i("gist.web.userQueue",e.data,n),t=e.data}else 304===e.status&&(t=o("gist.web.userQueue"));t&&t.length>0?(s(`Message queue checked for user ${v()}, ${t.length} messages found.`),J=t,await K()):(J=[],s("No messages for user token."))}else s("There was an error while checking message queue.")}else s("Document not visible, skipping queue check.");else s("User token reset, skipping queue check.")}()),1e4)):s("User token not setup, queue not started."))}async function K(){s("Messages in local queue: "+J.length);var e=[],t=J.sort((e,t)=>e.priority-t.priority);for(const i of t){if(!await Y(i)){var n=e.find(e=>e.queueId===i.queueId),r=Z.currentMessages.find(e=>e.queueId===i.queueId);n||r?s(`Message with queueId: ${i.queueId} already in queue, discarding.`):e.push(i)}}J=e}async function Y(e){if(!function(e){return void 0!==j.find(t=>t.queueId===e.queueId)}(e)){var t=S(e);if(t.hasRouteRule){var n=Z.currentRoute;null==n&&(n=new URL(window.location.href).pathname);var r=t.routeRule;if(s("Verifying route against rule: "+r),!new RegExp(r).test(n))return s(`Route ${n} does not match rule.`),!1}return t.hasPosition&&(e.position=t.position),t.isEmbedded?await U(e,t.elementId):await D(e)}s(`Message with ${e.queueId} has been shown before, skipping.`)}var Z=t.default=class{static async setup(e){this.events=new r,this.config={useGuestSession:void 0!==e.useGuestSession&&e.useGuestSession,siteId:e.siteId,dataCenter:e.dataCenter,env:void 0===e.env?"prod":e.env,logging:void 0!==e.logging&&e.logging,experiments:void 0!==e.experiments&&e.experiments},this.currentMessages=[],this.overlayInstanceId=null,this.currentRoute=null,this.isDocumentVisible=!0,s(`Setup complete on ${this.config.env} environment.`),this.config.useGuestSession&&y(),await Q(),document.addEventListener("visibilitychange",async()=>{"hidden"===document.visibilityState?this.isDocumentVisible=!1:(this.isDocumentVisible=!0,await K())},!1)}static async setCurrentRoute(e){this.currentRoute=e,s("Current route set to: "+e),await K()}static async setUserToken(e,t){!function(e,t){void 0===t&&(t=new Date).setDate(t.getDate()+30),i("gist.web.userToken",e,t),a("gist.web.usingGuestUserToken"),s(`Set user token "${e}" with expiry date set to ${t}`)}(e,t),await Q()}static async clearUserToken(){a("gist.web.userToken"),s("Cleared user token"),this.config.useGuestSession&&y(),await Q()}static async dismissMessage(e){var t=W(e);await A(t),await q(t),await K()}static async embedMessage(e,t){var n=await U(e,t);return n?n.instanceId:null}static async showMessage(e){var t=await D(e);return t?t.instanceId:null}static messageShown(e){s("Message shown: "+e.messageId),this.events.dispatch("messageShown",e)}static messageDismissed(e){null!==e&&(s("Message dismissed: "+e.messageId),this.events.dispatch("messageDismissed",e))}static messageError(e){s("Message error: "+e.messageId),this.events.dispatch("messageError",e)}static messageAction(e,t,n){s(`Message action: ${e.currentRoute}, ${t} with name ${n} on ${e.instanceId}`),this.events.dispatch("messageAction",{message:e,action:t,name:n})}}}])}));
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.Gist=t():e.Gist=t()}(this,(function(){return function(e){var t={};function n(r){if(t[r])return t[r].exports;var s=t[r]={i:r,l:!1,exports:{}};return e[r].call(s.exports,s,s.exports,n),s.l=!0,s.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var s in e)n.d(r,s,function(t){return e[t]}.bind(null,s));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=11)}([function(e,t,n){"use strict";var r=n(2),s=Object.prototype.toString;function i(e){return"[object Array]"===s.call(e)}function o(e){return void 0===e}function a(e){return null!==e&&"object"==typeof e}function u(e){if("[object Object]"!==s.call(e))return!1;var t=Object.getPrototypeOf(e);return null===t||t===Object.prototype}function c(e){return"[object Function]"===s.call(e)}function d(e,t){if(null!=e)if("object"!=typeof e&&(e=[e]),i(e))for(var n=0,r=e.length;n<r;n++)t.call(null,e[n],n,e);else for(var s in e)Object.prototype.hasOwnProperty.call(e,s)&&t.call(null,e[s],s,e)}e.exports={isArray:i,isArrayBuffer:function(e){return"[object ArrayBuffer]"===s.call(e)},isBuffer:function(e){return null!==e&&!o(e)&&null!==e.constructor&&!o(e.constructor)&&"function"==typeof e.constructor.isBuffer&&e.constructor.isBuffer(e)},isFormData:function(e){return"undefined"!=typeof FormData&&e instanceof FormData},isArrayBufferView:function(e){return"undefined"!=typeof ArrayBuffer&&ArrayBuffer.isView?ArrayBuffer.isView(e):e&&e.buffer&&e.buffer instanceof ArrayBuffer},isString:function(e){return"string"==typeof e},isNumber:function(e){return"number"==typeof e},isObject:a,isPlainObject:u,isUndefined:o,isDate:function(e){return"[object Date]"===s.call(e)},isFile:function(e){return"[object File]"===s.call(e)},isBlob:function(e){return"[object Blob]"===s.call(e)},isFunction:c,isStream:function(e){return a(e)&&c(e.pipe)},isURLSearchParams:function(e){return"undefined"!=typeof URLSearchParams&&e instanceof URLSearchParams},isStandardBrowserEnv:function(){return("undefined"==typeof navigator||"ReactNative"!==navigator.product&&"NativeScript"!==navigator.product&&"NS"!==navigator.product)&&("undefined"!=typeof window&&"undefined"!=typeof document)},forEach:d,merge:function e(){var t={};function n(n,r){u(t[r])&&u(n)?t[r]=e(t[r],n):u(n)?t[r]=e({},n):i(n)?t[r]=n.slice():t[r]=n}for(var r=0,s=arguments.length;r<s;r++)d(arguments[r],n);return t},extend:function(e,t,n){return d(t,(function(t,s){e[s]=n&&"function"==typeof t?r(t,n):t})),e},trim:function(e){return e.replace(/^\s*/,"").replace(/\s*$/,"")},stripBOM:function(e){return 65279===e.charCodeAt(0)&&(e=e.slice(1)),e}}},,function(e,t,n){"use strict";e.exports=function(e,t){return function(){for(var n=new Array(arguments.length),r=0;r<n.length;r++)n[r]=arguments[r];return e.apply(t,n)}}},function(e,t,n){"use strict";var r=n(0);function s(e){return encodeURIComponent(e).replace(/%3A/gi,":").replace(/%24/g,"$").replace(/%2C/gi,",").replace(/%20/g,"+").replace(/%5B/gi,"[").replace(/%5D/gi,"]")}e.exports=function(e,t,n){if(!t)return e;var i;if(n)i=n(t);else if(r.isURLSearchParams(t))i=t.toString();else{var o=[];r.forEach(t,(function(e,t){null!=e&&(r.isArray(e)?t+="[]":e=[e],r.forEach(e,(function(e){r.isDate(e)?e=e.toISOString():r.isObject(e)&&(e=JSON.stringify(e)),o.push(s(t)+"="+s(e))})))})),i=o.join("&")}if(i){var a=e.indexOf("#");-1!==a&&(e=e.slice(0,a)),e+=(-1===e.indexOf("?")?"?":"&")+i}return e}},function(e,t,n){"use strict";e.exports=function(e){return!(!e||!e.__CANCEL__)}},function(e,t,n){"use strict";(function(t){var r=n(0),s=n(18),i={"Content-Type":"application/x-www-form-urlencoded"};function o(e,t){!r.isUndefined(e)&&r.isUndefined(e["Content-Type"])&&(e["Content-Type"]=t)}var a,u={adapter:(("undefined"!=typeof XMLHttpRequest||void 0!==t&&"[object process]"===Object.prototype.toString.call(t))&&(a=n(6)),a),transformRequest:[function(e,t){return s(t,"Accept"),s(t,"Content-Type"),r.isFormData(e)||r.isArrayBuffer(e)||r.isBuffer(e)||r.isStream(e)||r.isFile(e)||r.isBlob(e)?e:r.isArrayBufferView(e)?e.buffer:r.isURLSearchParams(e)?(o(t,"application/x-www-form-urlencoded;charset=utf-8"),e.toString()):r.isObject(e)?(o(t,"application/json;charset=utf-8"),JSON.stringify(e)):e}],transformResponse:[function(e){if("string"==typeof e)try{e=JSON.parse(e)}catch(e){}return e}],timeout:0,xsrfCookieName:"XSRF-TOKEN",xsrfHeaderName:"X-XSRF-TOKEN",maxContentLength:-1,maxBodyLength:-1,validateStatus:function(e){return e>=200&&e<300}};u.headers={common:{Accept:"application/json, text/plain, */*"}},r.forEach(["delete","get","head"],(function(e){u.headers[e]={}})),r.forEach(["post","put","patch"],(function(e){u.headers[e]=r.merge(i)})),e.exports=u}).call(this,n(17))},function(e,t,n){"use strict";var r=n(0),s=n(19),i=n(21),o=n(3),a=n(22),u=n(25),c=n(26),d=n(7);e.exports=function(e){return new Promise((function(t,n){var f=e.data,l=e.headers;r.isFormData(f)&&delete l["Content-Type"];var p=new XMLHttpRequest;if(e.auth){var g=e.auth.username||"",h=e.auth.password?unescape(encodeURIComponent(e.auth.password)):"";l.Authorization="Basic "+btoa(g+":"+h)}var m=a(e.baseURL,e.url);if(p.open(e.method.toUpperCase(),o(m,e.params,e.paramsSerializer),!0),p.timeout=e.timeout,p.onreadystatechange=function(){if(p&&4===p.readyState&&(0!==p.status||p.responseURL&&0===p.responseURL.indexOf("file:"))){var r="getAllResponseHeaders"in p?u(p.getAllResponseHeaders()):null,i={data:e.responseType&&"text"!==e.responseType?p.response:p.responseText,status:p.status,statusText:p.statusText,headers:r,config:e,request:p};s(t,n,i),p=null}},p.onabort=function(){p&&(n(d("Request aborted",e,"ECONNABORTED",p)),p=null)},p.onerror=function(){n(d("Network Error",e,null,p)),p=null},p.ontimeout=function(){var t="timeout of "+e.timeout+"ms exceeded";e.timeoutErrorMessage&&(t=e.timeoutErrorMessage),n(d(t,e,"ECONNABORTED",p)),p=null},r.isStandardBrowserEnv()){var v=(e.withCredentials||c(m))&&e.xsrfCookieName?i.read(e.xsrfCookieName):void 0;v&&(l[e.xsrfHeaderName]=v)}if("setRequestHeader"in p&&r.forEach(l,(function(e,t){void 0===f&&"content-type"===t.toLowerCase()?delete l[t]:p.setRequestHeader(t,e)})),r.isUndefined(e.withCredentials)||(p.withCredentials=!!e.withCredentials),e.responseType)try{p.responseType=e.responseType}catch(t){if("json"!==e.responseType)throw t}"function"==typeof e.onDownloadProgress&&p.addEventListener("progress",e.onDownloadProgress),"function"==typeof e.onUploadProgress&&p.upload&&p.upload.addEventListener("progress",e.onUploadProgress),e.cancelToken&&e.cancelToken.promise.then((function(e){p&&(p.abort(),n(e),p=null)})),f||(f=null),p.send(f)}))}},function(e,t,n){"use strict";var r=n(20);e.exports=function(e,t,n,s,i){var o=new Error(e);return r(o,t,n,s,i)}},function(e,t,n){"use strict";var r=n(0);e.exports=function(e,t){t=t||{};var n={},s=["url","method","data"],i=["headers","auth","proxy","params"],o=["baseURL","transformRequest","transformResponse","paramsSerializer","timeout","timeoutMessage","withCredentials","adapter","responseType","xsrfCookieName","xsrfHeaderName","onUploadProgress","onDownloadProgress","decompress","maxContentLength","maxBodyLength","maxRedirects","transport","httpAgent","httpsAgent","cancelToken","socketPath","responseEncoding"],a=["validateStatus"];function u(e,t){return r.isPlainObject(e)&&r.isPlainObject(t)?r.merge(e,t):r.isPlainObject(t)?r.merge({},t):r.isArray(t)?t.slice():t}function c(s){r.isUndefined(t[s])?r.isUndefined(e[s])||(n[s]=u(void 0,e[s])):n[s]=u(e[s],t[s])}r.forEach(s,(function(e){r.isUndefined(t[e])||(n[e]=u(void 0,t[e]))})),r.forEach(i,c),r.forEach(o,(function(s){r.isUndefined(t[s])?r.isUndefined(e[s])||(n[s]=u(void 0,e[s])):n[s]=u(void 0,t[s])})),r.forEach(a,(function(r){r in t?n[r]=u(e[r],t[r]):r in e&&(n[r]=u(void 0,e[r]))}));var d=s.concat(i).concat(o).concat(a),f=Object.keys(e).concat(Object.keys(t)).filter((function(e){return-1===d.indexOf(e)}));return r.forEach(f,c),n}},function(e,t,n){"use strict";function r(e){this.message=e}r.prototype.toString=function(){return"Cancel"+(this.message?": "+this.message:"")},r.prototype.__CANCEL__=!0,e.exports=r},function(e,t,n){e.exports=n(12)},function(e,t,n){const r=n(30).default;e.exports=r},function(e,t,n){"use strict";var r=n(0),s=n(2),i=n(13),o=n(8);function a(e){var t=new i(e),n=s(i.prototype.request,t);return r.extend(n,i.prototype,t),r.extend(n,t),n}var u=a(n(5));u.Axios=i,u.create=function(e){return a(o(u.defaults,e))},u.Cancel=n(9),u.CancelToken=n(27),u.isCancel=n(4),u.all=function(e){return Promise.all(e)},u.spread=n(28),u.isAxiosError=n(29),e.exports=u,e.exports.default=u},function(e,t,n){"use strict";var r=n(0),s=n(3),i=n(14),o=n(15),a=n(8);function u(e){this.defaults=e,this.interceptors={request:new i,response:new i}}u.prototype.request=function(e){"string"==typeof e?(e=arguments[1]||{}).url=arguments[0]:e=e||{},(e=a(this.defaults,e)).method?e.method=e.method.toLowerCase():this.defaults.method?e.method=this.defaults.method.toLowerCase():e.method="get";var t=[o,void 0],n=Promise.resolve(e);for(this.interceptors.request.forEach((function(e){t.unshift(e.fulfilled,e.rejected)})),this.interceptors.response.forEach((function(e){t.push(e.fulfilled,e.rejected)}));t.length;)n=n.then(t.shift(),t.shift());return n},u.prototype.getUri=function(e){return e=a(this.defaults,e),s(e.url,e.params,e.paramsSerializer).replace(/^\?/,"")},r.forEach(["delete","get","head","options"],(function(e){u.prototype[e]=function(t,n){return this.request(a(n||{},{method:e,url:t,data:(n||{}).data}))}})),r.forEach(["post","put","patch"],(function(e){u.prototype[e]=function(t,n,r){return this.request(a(r||{},{method:e,url:t,data:n}))}})),e.exports=u},function(e,t,n){"use strict";var r=n(0);function s(){this.handlers=[]}s.prototype.use=function(e,t){return this.handlers.push({fulfilled:e,rejected:t}),this.handlers.length-1},s.prototype.eject=function(e){this.handlers[e]&&(this.handlers[e]=null)},s.prototype.forEach=function(e){r.forEach(this.handlers,(function(t){null!==t&&e(t)}))},e.exports=s},function(e,t,n){"use strict";var r=n(0),s=n(16),i=n(4),o=n(5);function a(e){e.cancelToken&&e.cancelToken.throwIfRequested()}e.exports=function(e){return a(e),e.headers=e.headers||{},e.data=s(e.data,e.headers,e.transformRequest),e.headers=r.merge(e.headers.common||{},e.headers[e.method]||{},e.headers),r.forEach(["delete","get","head","post","put","patch","common"],(function(t){delete e.headers[t]})),(e.adapter||o.adapter)(e).then((function(t){return a(e),t.data=s(t.data,t.headers,e.transformResponse),t}),(function(t){return i(t)||(a(e),t&&t.response&&(t.response.data=s(t.response.data,t.response.headers,e.transformResponse))),Promise.reject(t)}))}},function(e,t,n){"use strict";var r=n(0);e.exports=function(e,t,n){return r.forEach(n,(function(n){e=n(e,t)})),e}},function(e,t){var n,r,s=e.exports={};function i(){throw new Error("setTimeout has not been defined")}function o(){throw new Error("clearTimeout has not been defined")}function a(e){if(n===setTimeout)return setTimeout(e,0);if((n===i||!n)&&setTimeout)return n=setTimeout,setTimeout(e,0);try{return n(e,0)}catch(t){try{return n.call(null,e,0)}catch(t){return n.call(this,e,0)}}}!function(){try{n="function"==typeof setTimeout?setTimeout:i}catch(e){n=i}try{r="function"==typeof clearTimeout?clearTimeout:o}catch(e){r=o}}();var u,c=[],d=!1,f=-1;function l(){d&&u&&(d=!1,u.length?c=u.concat(c):f=-1,c.length&&p())}function p(){if(!d){var e=a(l);d=!0;for(var t=c.length;t;){for(u=c,c=[];++f<t;)u&&u[f].run();f=-1,t=c.length}u=null,d=!1,function(e){if(r===clearTimeout)return clearTimeout(e);if((r===o||!r)&&clearTimeout)return r=clearTimeout,clearTimeout(e);try{r(e)}catch(t){try{return r.call(null,e)}catch(t){return r.call(this,e)}}}(e)}}function g(e,t){this.fun=e,this.array=t}function h(){}s.nextTick=function(e){var t=new Array(arguments.length-1);if(arguments.length>1)for(var n=1;n<arguments.length;n++)t[n-1]=arguments[n];c.push(new g(e,t)),1!==c.length||d||a(p)},g.prototype.run=function(){this.fun.apply(null,this.array)},s.title="browser",s.browser=!0,s.env={},s.argv=[],s.version="",s.versions={},s.on=h,s.addListener=h,s.once=h,s.off=h,s.removeListener=h,s.removeAllListeners=h,s.emit=h,s.prependListener=h,s.prependOnceListener=h,s.listeners=function(e){return[]},s.binding=function(e){throw new Error("process.binding is not supported")},s.cwd=function(){return"/"},s.chdir=function(e){throw new Error("process.chdir is not supported")},s.umask=function(){return 0}},function(e,t,n){"use strict";var r=n(0);e.exports=function(e,t){r.forEach(e,(function(n,r){r!==t&&r.toUpperCase()===t.toUpperCase()&&(e[t]=n,delete e[r])}))}},function(e,t,n){"use strict";var r=n(7);e.exports=function(e,t,n){var s=n.config.validateStatus;n.status&&s&&!s(n.status)?t(r("Request failed with status code "+n.status,n.config,null,n.request,n)):e(n)}},function(e,t,n){"use strict";e.exports=function(e,t,n,r,s){return e.config=t,n&&(e.code=n),e.request=r,e.response=s,e.isAxiosError=!0,e.toJSON=function(){return{message:this.message,name:this.name,description:this.description,number:this.number,fileName:this.fileName,lineNumber:this.lineNumber,columnNumber:this.columnNumber,stack:this.stack,config:this.config,code:this.code}},e}},function(e,t,n){"use strict";var r=n(0);e.exports=r.isStandardBrowserEnv()?{write:function(e,t,n,s,i,o){var a=[];a.push(e+"="+encodeURIComponent(t)),r.isNumber(n)&&a.push("expires="+new Date(n).toGMTString()),r.isString(s)&&a.push("path="+s),r.isString(i)&&a.push("domain="+i),!0===o&&a.push("secure"),document.cookie=a.join("; ")},read:function(e){var t=document.cookie.match(new RegExp("(^|;\\s*)("+e+")=([^;]*)"));return t?decodeURIComponent(t[3]):null},remove:function(e){this.write(e,"",Date.now()-864e5)}}:{write:function(){},read:function(){return null},remove:function(){}}},function(e,t,n){"use strict";var r=n(23),s=n(24);e.exports=function(e,t){return e&&!r(t)?s(e,t):t}},function(e,t,n){"use strict";e.exports=function(e){return/^([a-z][a-z\d\+\-\.]*:)?\/\//i.test(e)}},function(e,t,n){"use strict";e.exports=function(e,t){return t?e.replace(/\/+$/,"")+"/"+t.replace(/^\/+/,""):e}},function(e,t,n){"use strict";var r=n(0),s=["age","authorization","content-length","content-type","etag","expires","from","host","if-modified-since","if-unmodified-since","last-modified","location","max-forwards","proxy-authorization","referer","retry-after","user-agent"];e.exports=function(e){var t,n,i,o={};return e?(r.forEach(e.split("\n"),(function(e){if(i=e.indexOf(":"),t=r.trim(e.substr(0,i)).toLowerCase(),n=r.trim(e.substr(i+1)),t){if(o[t]&&s.indexOf(t)>=0)return;o[t]="set-cookie"===t?(o[t]?o[t]:[]).concat([n]):o[t]?o[t]+", "+n:n}})),o):o}},function(e,t,n){"use strict";var r=n(0);e.exports=r.isStandardBrowserEnv()?function(){var e,t=/(msie|trident)/i.test(navigator.userAgent),n=document.createElement("a");function s(e){var r=e;return t&&(n.setAttribute("href",r),r=n.href),n.setAttribute("href",r),{href:n.href,protocol:n.protocol?n.protocol.replace(/:$/,""):"",host:n.host,search:n.search?n.search.replace(/^\?/,""):"",hash:n.hash?n.hash.replace(/^#/,""):"",hostname:n.hostname,port:n.port,pathname:"/"===n.pathname.charAt(0)?n.pathname:"/"+n.pathname}}return e=s(window.location.href),function(t){var n=r.isString(t)?s(t):t;return n.protocol===e.protocol&&n.host===e.host}}():function(){return!0}},function(e,t,n){"use strict";var r=n(9);function s(e){if("function"!=typeof e)throw new TypeError("executor must be a function.");var t;this.promise=new Promise((function(e){t=e}));var n=this;e((function(e){n.reason||(n.reason=new r(e),t(n.reason))}))}s.prototype.throwIfRequested=function(){if(this.reason)throw this.reason},s.source=function(){var e;return{token:new s((function(t){e=t})),cancel:e}},e.exports=s},function(e,t,n){"use strict";e.exports=function(e){return function(t){return e.apply(null,t)}}},function(e,t,n){"use strict";e.exports=function(e){return"object"==typeof e&&!0===e.isAxiosError}},function(e,t,n){"use strict";n.r(t);class r{on(e,t){var n=this[e];n?n.push(t):this[e]=[t]}dispatch(e,t){var n=this[e];n&&n.forEach(e=>e(t))}}function s(e){ne.config.logging&&console.log("Gist: "+e)}function i(e,t,n){const r={value:t,expiry:n};localStorage.setItem(e,JSON.stringify(r))}function o(e){const t=localStorage.getItem(e);if(!t)return null;const n=JSON.parse(t),r=new Date,s=new Date(n.expiry);return r.getTime()>s.getTime()?(localStorage.removeItem(e),null):n.value}function a(e){localStorage.removeItem(e)}var u,c=new Uint8Array(16);function d(){if(!u&&!(u="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||"undefined"!=typeof msCrypto&&"function"==typeof msCrypto.getRandomValues&&msCrypto.getRandomValues.bind(msCrypto)))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return u(c)}var f=/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i;for(var l=function(e){return"string"==typeof e&&f.test(e)},p=[],g=0;g<256;++g)p.push((g+256).toString(16).substr(1));var h=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,n=(p[e[t+0]]+p[e[t+1]]+p[e[t+2]]+p[e[t+3]]+"-"+p[e[t+4]]+p[e[t+5]]+"-"+p[e[t+6]]+p[e[t+7]]+"-"+p[e[t+8]]+p[e[t+9]]+"-"+p[e[t+10]]+p[e[t+11]]+p[e[t+12]]+p[e[t+13]]+p[e[t+14]]+p[e[t+15]]).toLowerCase();if(!l(n))throw TypeError("Stringified UUID is invalid");return n};var m=function(e,t,n){var r=(e=e||{}).random||(e.rng||d)();if(r[6]=15&r[6]|64,r[8]=63&r[8]|128,t){n=n||0;for(var s=0;s<16;++s)t[n+s]=r[s];return t}return h(r)};function v(){return o("gist.web.userToken")}function y(){var e=new Date;if(e.setDate(e.getDate()+365),null===v()){var t=o("gist.web.guestUserToken");null==t&&(i("gist.web.guestUserToken",t=m(),e),s(`Set guest user token "${t}" with expiry date set to 1 year from today`)),i("gist.web.userToken",t,e),i("gist.web.usingGuestUserToken",!0,e)}}var w=n(10),b=n.n(w);const x={ENGINE_API_ENDPOINT:{prod:"https://engine.api.gist.build",dev:"https://engine.api.dev.gist.build",local:"http://engine.api.local.gist.build:82"},GIST_QUEUE_API_ENDPOINT:{prod:"https://gist-queue-consumer-api.cloud.gist.build",dev:"https://gist-queue-consumer-api.cloud.dev.gist.build",local:"http://api.local.gist.build:86"},GIST_VIEW_ENDPOINT:{prod:"https://renderer.gist.build/2.0",dev:"https://renderer.gist.build/2.0",local:"http://app.local.gist.build:8080/web"}};function I(){var e={"X-CIO-Site-Id":ne.config.siteId,"X-CIO-Datacenter":ne.config.dataCenter},t=v();return null!=t&&(e["X-Gist-Encoded-User-Token"]=btoa(t)),b.a.create({baseURL:x.GIST_QUEUE_API_ENDPOINT[ne.config.env],timeout:2e4,headers:e})}var S=600,T=!1;async function E(){var e;try{T||(T=!0,e=await I().post("/api/v1/users",{}))}catch(t){t.response?e=t.response:s("Error getting user queue: "+t)}finally{return T=!1,function(e){if(e&&e.headers){var t=e.headers["x-gist-queue-polling-interval"];t&&t>0&&(S=t)}var n=new Date((new Date).getTime()+1e3*S);i("gist.web.userQueueNextPullCheck",S,n)}(e),e}}function C(e){var t="",n="",r="",s=!1,i=!1,o=!1,a=!1,u=null,c=!1,d="#00000033",f=414,l=!1;return e.properties&&e.properties.gist&&(e.properties.gist.campaignId&&(u=e.properties.gist.campaignId),e.properties.gist.elementId&&(t=e.properties.gist.elementId,s=!0),e.properties.gist.routeRuleWeb&&(n=e.properties.gist.routeRuleWeb,i=!0),e.properties.gist.position&&(r=e.properties.gist.position,o=!0),e.properties.gist.scale&&(a=e.properties.gist.scale),e.properties.gist.overlayColor&&(d=e.properties.gist.overlayColor),e.properties.gist.messageWidth&&e.properties.gist.messageWidth>0&&(f=e.properties.gist.messageWidth,l=!0),e.properties.gist.persistent&&(c=!0)),{isEmbedded:s,elementId:t,hasRouteRule:i,routeRule:n,position:r,hasPosition:o,shouldScale:a,campaignId:u,messageWidth:f,overlayColor:d,persistent:c,hasCustomWidth:l}}const R=e=>new Promise(t=>setTimeout(t,e));function k(e,t,n){var r=j(e);r?(N(e)||(r.style.height="0px"),r.innerHTML=function(e,t){return function(e,t){var n=800;e.messageWidth>n&&(n=e.messageWidth);var r=e.messageWidth+"px";return["x-gist-top","x-gist-bottom","x-gist-floating-top","x-gist-floating-bottom"].includes(e.elementId)&&!e.hasCustomWidth&&(r="100%"),`\n <div id="gist-embed">\n <style>\n #x-gist-floating-top, #x-gist-floating-top-left, #x-gist-floating-top-right {\n position: fixed;\n top: 0px;\n z-index: 1000000;\n }\n #x-gist-floating-bottom, #x-gist-floating-bottom-left, #x-gist-floating-bottom-right {\n position: fixed;\n bottom: 0px;\n z-index: 1000000;\n }\n #x-gist-bottom, #x-gist-top, #x-gist-floating-top, #x-gist-floating-bottom {\n left: 50%;\n transform: translate(-50%, 0%);\n width: ${r};\n }\n #x-gist-floating-top-left, #x-gist-floating-top-right, #x-gist-floating-bottom-left, #x-gist-floating-bottom-right {\n width: ${r};\n }\n #x-gist-floating-top-right, #x-gist-floating-bottom-right {\n right: 0px;\n }\n #gist-embed {\n position: relative;\n height: 100%;\n width: 100%;\n }\n #gist-embed-container {\n position: relative;\n height: 100%;\n width: 100%;\n }\n #gist-embed-container .gist-frame {\n height: 100%;\n width: 100%;\n border: none;\n }\n @media (max-width: ${n}px) {\n #x-gist-top, #x-gist-bottom, #x-gist-floating-top, #x-gist-floating-bottom, #x-gist-floating-top-left, #x-gist-floating-top-right, #x-gist-floating-bottom-left, #x-gist-floating-bottom-right {\n width: 100%;\n }\n }\n </style>\n <div id="gist-embed-container">\n <iframe class="gist-frame" src="${t}"></iframe>\n </div>\n </div>`}(C(t),e)}(t,n)):s(`Message could not be embedded, elementId ${e} not found.`)}function N(e){var t=j(e);if(t)return t.style&&t.style.height&&"0px"!=t.style.height}function O(e,t,n){var r=j(e);if(r){var s=r.style;if(t.height>0)if(t.height>window.innerHeight){var i=1-(t.height/window.innerHeight-1);n&&i>=.4?(s.height=t.height+"px",s.transform=`translateX(-50%) translateY(-50%) scale(${i})`):s.height=window.innerHeight+"px"}else s.height=t.height+"px"}}function L(e,t){document.body.insertAdjacentHTML("beforeend",function(e,t){return function(e,t){var n=600;return e.messageWidth>n&&(n=e.messageWidth),`\n <div id="gist-embed-message">\n <style>\n #gist-overlay.background {\n position: fixed;\n z-index: 9999999998;\n left: 0;\n top: 0;\n width: 100%;\n height: 100%;\n background-color: ${e.overlayColor};\n visibility: hidden;\n }\n #gist-overlay.background.visible {\n visibility: visible;\n }\n #gist-overlay.background.is-blacked-out {\n display: block;\n }\n #gist-message {\n width: ${e.messageWidth}px;\n position: absolute;\n border: none;\n opacity: 0;\n transition: opacity 0.3s ease-in-out;\n z-index: 9999999999;\n left: 50%;\n transform: translateX(-50%);\n }\n #gist-message.visible {\n opacity: 1;\n }\n #gist-message.center {\n transform: translate(-50%, -50%);\n top: 50%;\n }\n #gist-message.bottom {\n bottom: 0;\n }\n #gist-message.top {\n top: 0;\n }\n @media (max-width: ${n}px) {\n #gist-message {\n width: 100%;\n }\n }\n </style>\n <div id="gist-overlay" class="background">\n <iframe id="gist-message" class="message" src="${t}"></iframe>\n </div>\n </div>`}(C(t),e)}(e,t))}function P(){var e=document.querySelector("#gist-embed-message");e&&e.parentNode.removeChild(e)}function D(){var e=document.querySelector("#gist-message");e&&e.classList.add("visible")}function j(e){try{var t=document.querySelector("#"+e);return t||null}catch{return null}}var q=["x-gist-top","x-gist-floating-top","x-gist-bottom","x-gist-floating-bottom","x-gist-floating-bottom-left","x-gist-floating-bottom-right","x-gist-floating-top-left","x-gist-floating-top-right"];var U=[];async function A(e){if(ne.isDocumentVisible){if(ne.overlayInstanceId)return s(`Message ${ne.overlayInstanceId} already showing.`),null;var t=C(e);return e.instanceId=m(),e.overlay=!0,e.firstLoad=!0,e.shouldResizeHeight=!0,e.shouldScale=t.shouldScale,e.renderStartTime=(new Date).getTime(),ne.overlayInstanceId=e.instanceId,ne.currentMessages.push(e),G(e)}return s("Document hidden, not showing message now."),null}async function M(e,t){return ne.isDocumentVisible?(e.instanceId=m(),e.overlay=!1,e.firstLoad=!0,e.shouldScale=!1,e.elementId=t,e.shouldResizeHeight=!N(t),e.renderStartTime=(new Date).getTime(),ne.currentMessages.push(e),G(e,t)):(s("Document hidden, not showing message now."),null)}async function $(e){e?(ne.messageDismissed(e),e.overlay?await W(!0,e):_(e)):s(`Message with instance id: ${instanceId} not found`)}async function B(e){var t=C(e);e?t.persistent&&(s("Persistent message dismissed, logging view"),await H(e)):s(`Message with instance id: ${instanceId} not found`)}function _(e){var t,n;z(e.instanceId),t=e.elementId,(n=j(t))&&(n.classList.remove("gist-visible"),n.style.removeProperty("height"),n.innerHTML="")}async function W(e,t){z(t.instanceId),ne.overlayInstanceId=null,e?await async function(){var e=document.querySelector("#gist-message");e&&(e.classList.remove("visible"),await R(300)),P()}():P(),0==ne.currentMessages.length&&(window.removeEventListener("message",J),window.removeEventListener("touchstart",X))}function G(e,t=null){if(t&&function(e){var t=j(e);return!(!t||!t.classList.contains("gist-visible"))}(t))return s(`Message ${e.messageId} already showing in element ${t}.`),null;var n,r,i={endpoint:x.ENGINE_API_ENDPOINT[ne.config.env],siteId:ne.config.siteId,dataCenter:ne.config.dataCenter,messageId:e.messageId,instanceId:e.instanceId,livePreview:!1,properties:e.properties},o=`${x.GIST_VIEW_ENDPOINT[ne.config.env]}/index.html?options=${n=JSON.stringify(i),r=btoa(encodeURIComponent(n).replace(/%([0-9A-F]{2})/g,(function(e,t){return String.fromCharCode("0x"+t)}))),encodeURIComponent(r)}`;return window.addEventListener("message",J),window.addEventListener("touchstart",X),t?(q.includes(t)&&function(e){const t=document.createElement("div");switch(t.id=e,e){case"x-gist-top":document.body.insertBefore(t,document.body.firstChild);break;default:document.body.insertAdjacentElement("beforeend",t)}s("Top & bottom elements injected into page")}(t),k(t,o,e)):L(o,e),e}async function H(e){s("Message shown, logging view for: "+e.messageId);var t={};200===(t=null!=e.queueId?await async function(e){try{return await I().post("/api/v1/logs/queue/"+e)}catch(e){return e.response}}(e.queueId):await async function(e){try{return await I().post("/api/v1/logs/message/"+e)}catch(e){return e.response}}(e.messageId)).status?s("Message view logged"):s("Problem logging message: "+t.status)}function V(e){return ne.currentMessages.find(t=>t.instanceId===e)}function z(e){ne.currentMessages=ne.currentMessages.filter(t=>t.instanceId!==e)}function F(e,t){z(e),ne.currentMessages.push(t)}function X(e){}async function J(e){if(e.data.gist){var t=e.data.gist.instanceId,n=V(t);if(!n)return;var r=C(n);switch(e.data.gist.method){case"routeLoaded":var i=.001*((new Date).getTime()-n.renderStartTime);s(`Engine render for message: ${n.messageId} timer elapsed in ${i.toFixed(3)} seconds`),n.currentRoute=e.data.gist.parameters.route,n.firstLoad&&(U.push(n),n.overlay?function(e){var t=document.querySelector("#gist-overlay");if(t){t.classList.add("visible");var n=document.querySelector("#gist-message");e.position?n.classList.add(e.position):n.classList.add("center"),setTimeout(D,100)}else P()}(n):(f=n.elementId,(l=j(f))&&l.classList.add("gist-visible")),ne.messageShown(n),r.persistent?s("Persistent message shown, skipping logging view"):await H(n),n.firstLoad=!1),F(t,n);break;case"tap":var o=e.data.gist.parameters.action,a=e.data.gist.parameters.name;if(ne.messageAction(n,o,a),e.data.gist.parameters.system&&!r.persistent){await $(n);break}try{if((d=new URL(o))&&"gist:"===d.protocol)switch(d.href.replace("gist://","").split("?")[0]){case"close":await $(n),await B(n),await ee();break;case"showMessage":var u=d.searchParams.get("messageId"),c=d.searchParams.get("properties");u&&(c&&(c=JSON.parse(atob(c))),await ne.showMessage({messageId:u,properties:c}));break;case"loadPage":var d;(d=d.href.substring(d.href.indexOf("?url=")+5))&&(d.startsWith("https://")||d.startsWith("http://")||d.startsWith("/")?window.location.href=d:window.location.href=window.location+d)}}catch(e){}break;case"routeChanged":n.currentRoute=e.data.gist.parameters.route,n.renderStartTime=(new Date).getTime(),F(t,n),s("Route changed to: "+n.currentRoute);break;case"sizeChanged":s(`Size Changed Width: ${e.data.gist.parameters.width} - Height: ${e.data.gist.parameters.height}`),n.elementId&&n.shouldResizeHeight?O(n.elementId,e.data.gist.parameters,n.shouldScale):O("gist-message",e.data.gist.parameters,n.shouldScale);break;case"error":case"routeError":ne.messageError(n),ne.overlayInstanceId?W(!1,n):_(n)}}var f,l}var Q=(e,t)=>e().then((e=>new Promise(t=>setTimeout(t,e)))(t).then(()=>Q(e,t))),K=!1,Y=[];async function Z(){K?await ee():(!async function(){var e="G"+m().substring(0,8),t=document.createElement("div");t.setAttribute("id",e),t.style.display="none",document.body.appendChild(t),await R(5e3),M({messageId:""},e)}(),v()?(s("Queue watcher started"),K=!0,Q(()=>new Promise(()=>async function(){if(v())if(ne.isDocumentVisible)if(null===o("gist.web.userQueueNextPullCheck")){var e=await E(),t=[];if(e){if(200===e.status||204===e.status){var n=new Date((new Date).getTime()+36e5);i("gist.web.userQueue",e.data,n),t=e.data}else 304===e.status&&(s("304 response, using local store."),t=o("gist.web.userQueue"));t&&t.length>0?(s(`Message queue checked for user ${v()}, ${t.length} messages found.`),Y=t,await ee()):(Y=[],s("No messages for user token."))}else s("There was an error while checking message queue.")}else s("Next queue pull scheduled for later");else s("Document not visible, skipping queue check.");else s("User token reset, skipping queue check.")}()),1e3)):s("User token not setup, queue not started."))}async function ee(){s("Messages in local queue: "+Y.length);var e=[],t=Y.sort((e,t)=>e.priority-t.priority);for(const i of t){if(!await te(i)){var n=e.find(e=>e.queueId===i.queueId),r=ne.currentMessages.find(e=>e.queueId===i.queueId);n||r?s(`Message with queueId: ${i.queueId} already in queue, discarding.`):e.push(i)}}Y=e}async function te(e){if(!function(e){return void 0!==U.find(t=>t.queueId===e.queueId)}(e)){var t=C(e);if(t.hasRouteRule){var n=ne.currentRoute;null==n&&(n=new URL(window.location.href).pathname);var r=t.routeRule;if(s("Verifying route against rule: "+r),!new RegExp(r).test(n))return s(`Route ${n} does not match rule.`),!1}return t.hasPosition&&(e.position=t.position),t.isEmbedded?await M(e,t.elementId):await A(e)}s(`Message with ${e.queueId} has been shown before, skipping.`)}var ne=t.default=class{static async setup(e){this.events=new r,this.config={useGuestSession:void 0!==e.useGuestSession&&e.useGuestSession,siteId:e.siteId,dataCenter:e.dataCenter,env:void 0===e.env?"prod":e.env,logging:void 0!==e.logging&&e.logging,experiments:void 0!==e.experiments&&e.experiments},this.currentMessages=[],this.overlayInstanceId=null,this.currentRoute=null,this.isDocumentVisible=!0,s(`Setup complete on ${this.config.env} environment.`),this.config.useGuestSession&&y(),await Z(),document.addEventListener("visibilitychange",async()=>{"hidden"===document.visibilityState?this.isDocumentVisible=!1:(this.isDocumentVisible=!0,await ee())},!1)}static async setCurrentRoute(e){this.currentRoute=e,s("Current route set to: "+e),await ee()}static async setUserToken(e,t){!function(e,t){void 0===t&&(t=new Date).setDate(t.getDate()+30),i("gist.web.userToken",e,t),a("gist.web.usingGuestUserToken"),s(`Set user token "${e}" with expiry date set to ${t}`)}(e,t),await Z()}static async clearUserToken(){a("gist.web.userToken"),s("Cleared user token"),this.config.useGuestSession&&y(),await Z()}static async dismissMessage(e){var t=V(e);await $(t),await B(t),await ee()}static async embedMessage(e,t){var n=await M(e,t);return n?n.instanceId:null}static async showMessage(e){var t=await A(e);return t?t.instanceId:null}static messageShown(e){s("Message shown: "+e.messageId),this.events.dispatch("messageShown",e)}static messageDismissed(e){null!==e&&(s("Message dismissed: "+e.messageId),this.events.dispatch("messageDismissed",e))}static messageError(e){s("Message error: "+e.messageId),this.events.dispatch("messageError",e)}static messageAction(e,t,n){s(`Message action: ${e.currentRoute}, ${t} with name ${n} on ${e.instanceId}`),this.events.dispatch("messageAction",{message:e,action:t,name:n})}}}])}));
|
package/package.json
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import Gist from '../gist';
|
|
2
2
|
import { log } from "../utilities/log";
|
|
3
3
|
import { getUserToken } from "./user-manager";
|
|
4
|
-
import { getUserQueue } from "../services/queue-service";
|
|
4
|
+
import { getUserQueue, userQueueNextPullCheckLocalStoreName } from "../services/queue-service";
|
|
5
5
|
import { showMessage, embedMessage, hasMessageBeenShownBefore } from "./message-manager";
|
|
6
6
|
import { resolveMessageProperties } from "./gist-properties-manager";
|
|
7
7
|
import { preloadRenderer } from "./message-component-manager";
|
|
8
8
|
import { setKeyWithExpiryToLocalStore, getKeyFromLocalStore } from '../utilities/local-storage';
|
|
9
9
|
|
|
10
10
|
const userQueueLocalStoreName = "gist.web.userQueue";
|
|
11
|
-
const
|
|
11
|
+
const MESSAGES_LOCAL_STORE_CACHE_IN_MINUTES = 60000 * 60;
|
|
12
|
+
|
|
12
13
|
var sleep = time => new Promise(resolve => setTimeout(resolve, time))
|
|
13
14
|
var poll = (promiseFn, time) => promiseFn().then(sleep(time).then(() => poll(promiseFn, time)));
|
|
14
15
|
var pollingSetup = false;
|
|
@@ -20,7 +21,7 @@ export async function startQueueListener() {
|
|
|
20
21
|
if (getUserToken()) {
|
|
21
22
|
log("Queue watcher started");
|
|
22
23
|
pollingSetup = true;
|
|
23
|
-
poll(() => new Promise(() =>
|
|
24
|
+
poll(() => new Promise(() => pullMessagesFromQueue()), 1000);
|
|
24
25
|
} else {
|
|
25
26
|
log(`User token not setup, queue not started.`);
|
|
26
27
|
}
|
|
@@ -78,30 +79,36 @@ async function handleMessage(message) {
|
|
|
78
79
|
}
|
|
79
80
|
}
|
|
80
81
|
|
|
81
|
-
export async function
|
|
82
|
+
export async function pullMessagesFromQueue() {
|
|
82
83
|
if (getUserToken()) {
|
|
83
84
|
if (Gist.isDocumentVisible) {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
85
|
+
// We're using the TTL as a way to determine if we should check the queue, so if the key is not there, we check the queue.
|
|
86
|
+
if (getKeyFromLocalStore(userQueueNextPullCheckLocalStoreName) === null) {
|
|
87
|
+
var response = await getUserQueue();
|
|
88
|
+
var responseData = [];
|
|
89
|
+
if (response) {
|
|
90
|
+
if (response.status === 200 || response.status === 204) {
|
|
91
|
+
var expiryDate = new Date(new Date().getTime() + MESSAGES_LOCAL_STORE_CACHE_IN_MINUTES);
|
|
92
|
+
setKeyWithExpiryToLocalStore(userQueueLocalStoreName, response.data, expiryDate);
|
|
93
|
+
responseData = response.data;
|
|
94
|
+
}
|
|
95
|
+
else if (response.status === 304) {
|
|
96
|
+
log("304 response, using local store.");
|
|
97
|
+
responseData = getKeyFromLocalStore(userQueueLocalStoreName);
|
|
98
|
+
}
|
|
99
|
+
if (responseData && responseData.length > 0) {
|
|
100
|
+
log(`Message queue checked for user ${getUserToken()}, ${responseData.length} messages found.`);
|
|
101
|
+
messages = responseData;
|
|
102
|
+
await checkMessageQueue();
|
|
103
|
+
} else {
|
|
104
|
+
messages = [];
|
|
105
|
+
log(`No messages for user token.`);
|
|
106
|
+
}
|
|
99
107
|
} else {
|
|
100
|
-
|
|
101
|
-
log(`No messages for user token.`);
|
|
108
|
+
log(`There was an error while checking message queue.`);
|
|
102
109
|
}
|
|
103
110
|
} else {
|
|
104
|
-
log(`
|
|
111
|
+
log(`Next queue pull scheduled for later`);
|
|
105
112
|
}
|
|
106
113
|
} else {
|
|
107
114
|
log(`Document not visible, skipping queue check.`);
|
|
@@ -1,10 +1,39 @@
|
|
|
1
1
|
import { UserNetworkInstance } from './network';
|
|
2
|
+
import { setKeyWithExpiryToLocalStore } from '../utilities/local-storage';
|
|
3
|
+
import { log } from "../utilities/log";
|
|
2
4
|
|
|
5
|
+
const DEFAULT_POLLING_DELAY_IN_SECONDS = 600;
|
|
6
|
+
var currentPollingDelayInSeconds = DEFAULT_POLLING_DELAY_IN_SECONDS;
|
|
7
|
+
var checkInProgress = false;
|
|
8
|
+
|
|
9
|
+
export const userQueueNextPullCheckLocalStoreName = "gist.web.userQueueNextPullCheck";
|
|
3
10
|
export async function getUserQueue() {
|
|
11
|
+
var response;
|
|
4
12
|
try {
|
|
5
|
-
|
|
6
|
-
|
|
13
|
+
if (!checkInProgress) {
|
|
14
|
+
checkInProgress = true;
|
|
15
|
+
response = await UserNetworkInstance().post(`/api/v1/users`, {});
|
|
16
|
+
}
|
|
7
17
|
} catch (error) {
|
|
8
|
-
|
|
18
|
+
if (error.response) {
|
|
19
|
+
response = error.response;
|
|
20
|
+
} else {
|
|
21
|
+
log(`Error getting user queue: ${error}`);
|
|
22
|
+
}
|
|
23
|
+
} finally {
|
|
24
|
+
checkInProgress = false;
|
|
25
|
+
scheduleNextQueuePull(response);
|
|
26
|
+
return response;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function scheduleNextQueuePull(response) {
|
|
31
|
+
if (response && response.headers) {
|
|
32
|
+
var pollingInterval = response.headers['x-gist-queue-polling-interval'];
|
|
33
|
+
if (pollingInterval && pollingInterval > 0) {
|
|
34
|
+
currentPollingDelayInSeconds = pollingInterval;
|
|
35
|
+
}
|
|
9
36
|
}
|
|
37
|
+
var expiryDate = new Date(new Date().getTime() + currentPollingDelayInSeconds * 1000);
|
|
38
|
+
setKeyWithExpiryToLocalStore(userQueueNextPullCheckLocalStoreName, currentPollingDelayInSeconds, expiryDate);
|
|
10
39
|
}
|