@hellotext/hellotext 1.4.0 → 1.4.1

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/hellotext.js CHANGED
@@ -1 +1 @@
1
- (()=>{"use strict";var t={413:(t,e)=>{function r(t){var e="function"==typeof Map?new Map:void 0;return r=function(t){if(null===t||(r=t,-1===Function.toString.call(r).indexOf("[native code]")))return t;var r;if("function"!=typeof t)throw new TypeError("Super expression must either be null or a function");if(void 0!==e){if(e.has(t))return e.get(t);e.set(t,o)}function o(){return n(t,arguments,a(this).constructor)}return o.prototype=Object.create(t.prototype,{constructor:{value:o,enumerable:!1,writable:!0,configurable:!0}}),i(o,t)},r(t)}function n(t,e,r){return n=o()?Reflect.construct.bind():function(t,e,r){var n=[null];n.push.apply(n,e);var o=new(Function.bind.apply(t,n));return r&&i(o,r.prototype),o},n.apply(null,arguments)}function o(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}function i(t,e){return i=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},i(t,e)}function a(t){return a=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},a(t)}Object.defineProperty(e,"__esModule",{value:!0}),e.InvalidEvent=void 0;var s=function(t){!function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&i(t,e)}(u,t);var e,r,n,s=(r=u,n=o(),function(){var t,e=a(r);if(n){var o=a(this).constructor;t=Reflect.construct(e,arguments,o)}else t=e.apply(this,arguments);return function(t,e){if(e&&("object"==typeof e||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}(this,t)});function u(t){var e;return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,u),(e=s.call(this,"".concat(t," is not valid. Please provide a valid event name"))).name="InvalidEvent",e}return e=u,Object.defineProperty(e,"prototype",{writable:!1}),e}(r(Error));e.InvalidEvent=s},215:(t,e)=>{function r(t){var e="function"==typeof Map?new Map:void 0;return r=function(t){if(null===t||(r=t,-1===Function.toString.call(r).indexOf("[native code]")))return t;var r;if("function"!=typeof t)throw new TypeError("Super expression must either be null or a function");if(void 0!==e){if(e.has(t))return e.get(t);e.set(t,o)}function o(){return n(t,arguments,a(this).constructor)}return o.prototype=Object.create(t.prototype,{constructor:{value:o,enumerable:!1,writable:!0,configurable:!0}}),i(o,t)},r(t)}function n(t,e,r){return n=o()?Reflect.construct.bind():function(t,e,r){var n=[null];n.push.apply(n,e);var o=new(Function.bind.apply(t,n));return r&&i(o,r.prototype),o},n.apply(null,arguments)}function o(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}function i(t,e){return i=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},i(t,e)}function a(t){return a=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},a(t)}Object.defineProperty(e,"__esModule",{value:!0}),e.NotInitializedError=void 0;var s=function(t){!function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&i(t,e)}(u,t);var e,r,n,s=(r=u,n=o(),function(){var t,e=a(r);if(n){var o=a(this).constructor;t=Reflect.construct(e,arguments,o)}else t=e.apply(this,arguments);return function(t,e){if(e&&("object"==typeof e||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}(this,t)});function u(){var t;return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,u),(t=s.call(this,"You need to initialize before tracking events. Call Hellotext.initialize and pass your public business id")).name="NotInitializedError",t}return e=u,Object.defineProperty(e,"prototype",{writable:!1}),e}(r(Error));e.NotInitializedError=s},372:(t,e)=>{function r(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,(void 0,"symbol"==typeof(o=function(t,e){if("object"!=typeof t||null===t)return t;var r=t[Symbol.toPrimitive];if(void 0!==r){var n=r.call(t,"string");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(n.key))?o:String(o)),n)}var o}Object.defineProperty(e,"__esModule",{value:!0}),e.default=void 0;var n=function(){function t(){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t)}var e,n;return e=t,n=[{key:"valid",value:function(e){return t.exists(e)}},{key:"invalid",value:function(t){return!this.valid(t)}},{key:"exists",value:function(t){return void 0!==this.events.find((e=>e===t))}}],null&&r(e.prototype,null),n&&r(e,n),Object.defineProperty(e,"prototype",{writable:!1}),t}();e.default=n,n.events=["session-set"]},179:(t,e)=>{function r(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),r.push.apply(r,n)}return r}function n(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?r(Object(n),!0).forEach((function(e){o(t,e,n[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):r(Object(n)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))}))}return t}function o(t,e,r){return(e=a(e))in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function i(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,a(n.key),n)}}function a(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var r=t[Symbol.toPrimitive];if(void 0!==r){var n=r.call(t,"string");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==typeof e?e:String(e)}Object.defineProperty(e,"__esModule",{value:!0}),e.default=void 0;var s=function(){function t(){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.subscribers={}}var e,r;return e=t,(r=[{key:"addSubscriber",value:function(t,e){this.subscribers=n(n({},this.subscribers),{},{[t]:this.subscribers[t]?[...this.subscribers[t],e]:[e]})}},{key:"removeSubscriber",value:function(t,e){this.subscribers[t]&&(this.subscribers[t]=this.subscribers[t].filter((t=>t!==e)))}},{key:"emit",value:function(t,e){this.subscribers[t].forEach((t=>{t(e)}))}},{key:"listeners",get:function(){return 0!==Object.keys(this.subscribers).length}}])&&i(e.prototype,r),Object.defineProperty(e,"prototype",{writable:!1}),t}();e.default=s},474:(t,e)=>{function r(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,(void 0,"symbol"==typeof(o=function(t,e){if("object"!=typeof t||null===t)return t;var r=t[Symbol.toPrimitive];if(void 0!==r){var n=r.call(t,"string");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(n.key))?o:String(o)),n)}var o}Object.defineProperty(e,"__esModule",{value:!0}),e.default=void 0;var n=function(){function t(e){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.urlSearchParams=new URLSearchParams(e)}var e,n;return e=t,(n=[{key:"get",value:function(t){return this.urlSearchParams.get(this.toHellotextParam(t))}},{key:"has",value:function(t){return this.urlSearchParams.has(this.toHellotextParam(t))}},{key:"toHellotextParam",value:function(t){return"hello_".concat(t)}}])&&r(e.prototype,n),Object.defineProperty(e,"prototype",{writable:!1}),t}();e.default=n},310:(t,e)=>{function r(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,(void 0,"symbol"==typeof(o=function(t,e){if("object"!=typeof t||null===t)return t;var r=t[Symbol.toPrimitive];if(void 0!==r){var n=r.call(t,"string");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(n.key))?o:String(o)),n)}var o}function n(t,e){if(!Object.prototype.hasOwnProperty.call(t,e))throw new TypeError("attempted to use private field on non-instance");return t}Object.defineProperty(e,"__esModule",{value:!0}),e.default=void 0;var o=0;function i(t){return"__private_"+o+++"_"+t}var a=i("success"),s=i("response"),u=function(){function t(e,r){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),Object.defineProperty(this,a,{writable:!0,value:void 0}),Object.defineProperty(this,s,{writable:!0,value:void 0}),n(this,a)[a]=e,n(this,s)[s]=r}var e,o;return e=t,(o=[{key:"data",get:function(){return n(this,s)[s]}},{key:"failed",get:function(){return!1===n(this,a)[a]}},{key:"succeeded",get:function(){return!0===n(this,a)[a]}}])&&r(e.prototype,o),Object.defineProperty(e,"prototype",{writable:!1}),t}();e.default=u}},e={};function r(n){var o=e[n];if(void 0!==o)return o.exports;var i=e[n]={exports:{}};return t[n](i,i.exports,r),i.exports}r.d=(t,e)=>{for(var n in e)r.o(e,n)&&!r.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:e[n]})},r.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),(()=>{var t="undefined"!=typeof globalThis&&globalThis||"undefined"!=typeof self&&self||void 0!==t&&t,e={searchParams:"URLSearchParams"in t,iterable:"Symbol"in t&&"iterator"in Symbol,blob:"FileReader"in t&&"Blob"in t&&function(){try{return new Blob,!0}catch(t){return!1}}(),formData:"FormData"in t,arrayBuffer:"ArrayBuffer"in t};if(e.arrayBuffer)var r=["[object Int8Array]","[object Uint8Array]","[object Uint8ClampedArray]","[object Int16Array]","[object Uint16Array]","[object Int32Array]","[object Uint32Array]","[object Float32Array]","[object Float64Array]"],n=ArrayBuffer.isView||function(t){return t&&r.indexOf(Object.prototype.toString.call(t))>-1};function o(t){if("string"!=typeof t&&(t=String(t)),/[^a-z0-9\-#$%&'*+.^_`|~!]/i.test(t)||""===t)throw new TypeError('Invalid character in header field name: "'+t+'"');return t.toLowerCase()}function i(t){return"string"!=typeof t&&(t=String(t)),t}function a(t){var r={next:function(){var e=t.shift();return{done:void 0===e,value:e}}};return e.iterable&&(r[Symbol.iterator]=function(){return r}),r}function s(t){this.map={},t instanceof s?t.forEach((function(t,e){this.append(e,t)}),this):Array.isArray(t)?t.forEach((function(t){this.append(t[0],t[1])}),this):t&&Object.getOwnPropertyNames(t).forEach((function(e){this.append(e,t[e])}),this)}function u(t){if(t.bodyUsed)return Promise.reject(new TypeError("Already read"));t.bodyUsed=!0}function c(t){return new Promise((function(e,r){t.onload=function(){e(t.result)},t.onerror=function(){r(t.error)}}))}function f(t){var e=new FileReader,r=c(e);return e.readAsArrayBuffer(t),r}function l(t){if(t.slice)return t.slice(0);var e=new Uint8Array(t.byteLength);return e.set(new Uint8Array(t)),e.buffer}function p(){return this.bodyUsed=!1,this._initBody=function(t){var r;this.bodyUsed=this.bodyUsed,this._bodyInit=t,t?"string"==typeof t?this._bodyText=t:e.blob&&Blob.prototype.isPrototypeOf(t)?this._bodyBlob=t:e.formData&&FormData.prototype.isPrototypeOf(t)?this._bodyFormData=t:e.searchParams&&URLSearchParams.prototype.isPrototypeOf(t)?this._bodyText=t.toString():e.arrayBuffer&&e.blob&&(r=t)&&DataView.prototype.isPrototypeOf(r)?(this._bodyArrayBuffer=l(t.buffer),this._bodyInit=new Blob([this._bodyArrayBuffer])):e.arrayBuffer&&(ArrayBuffer.prototype.isPrototypeOf(t)||n(t))?this._bodyArrayBuffer=l(t):this._bodyText=t=Object.prototype.toString.call(t):this._bodyText="",this.headers.get("content-type")||("string"==typeof t?this.headers.set("content-type","text/plain;charset=UTF-8"):this._bodyBlob&&this._bodyBlob.type?this.headers.set("content-type",this._bodyBlob.type):e.searchParams&&URLSearchParams.prototype.isPrototypeOf(t)&&this.headers.set("content-type","application/x-www-form-urlencoded;charset=UTF-8"))},e.blob&&(this.blob=function(){var t=u(this);if(t)return t;if(this._bodyBlob)return Promise.resolve(this._bodyBlob);if(this._bodyArrayBuffer)return Promise.resolve(new Blob([this._bodyArrayBuffer]));if(this._bodyFormData)throw new Error("could not read FormData body as blob");return Promise.resolve(new Blob([this._bodyText]))},this.arrayBuffer=function(){return this._bodyArrayBuffer?u(this)||(ArrayBuffer.isView(this._bodyArrayBuffer)?Promise.resolve(this._bodyArrayBuffer.buffer.slice(this._bodyArrayBuffer.byteOffset,this._bodyArrayBuffer.byteOffset+this._bodyArrayBuffer.byteLength)):Promise.resolve(this._bodyArrayBuffer)):this.blob().then(f)}),this.text=function(){var t,e,r,n=u(this);if(n)return n;if(this._bodyBlob)return t=this._bodyBlob,r=c(e=new FileReader),e.readAsText(t),r;if(this._bodyArrayBuffer)return Promise.resolve(function(t){for(var e=new Uint8Array(t),r=new Array(e.length),n=0;n<e.length;n++)r[n]=String.fromCharCode(e[n]);return r.join("")}(this._bodyArrayBuffer));if(this._bodyFormData)throw new Error("could not read FormData body as text");return Promise.resolve(this._bodyText)},e.formData&&(this.formData=function(){return this.text().then(d)}),this.json=function(){return this.text().then(JSON.parse)},this}s.prototype.append=function(t,e){t=o(t),e=i(e);var r=this.map[t];this.map[t]=r?r+", "+e:e},s.prototype.delete=function(t){delete this.map[o(t)]},s.prototype.get=function(t){return t=o(t),this.has(t)?this.map[t]:null},s.prototype.has=function(t){return this.map.hasOwnProperty(o(t))},s.prototype.set=function(t,e){this.map[o(t)]=i(e)},s.prototype.forEach=function(t,e){for(var r in this.map)this.map.hasOwnProperty(r)&&t.call(e,this.map[r],r,this)},s.prototype.keys=function(){var t=[];return this.forEach((function(e,r){t.push(r)})),a(t)},s.prototype.values=function(){var t=[];return this.forEach((function(e){t.push(e)})),a(t)},s.prototype.entries=function(){var t=[];return this.forEach((function(e,r){t.push([r,e])})),a(t)},e.iterable&&(s.prototype[Symbol.iterator]=s.prototype.entries);var h=["DELETE","GET","HEAD","OPTIONS","POST","PUT"];function y(t,e){if(!(this instanceof y))throw new TypeError('Please use the "new" operator, this DOM object constructor cannot be called as a function.');var r,n,o=(e=e||{}).body;if(t instanceof y){if(t.bodyUsed)throw new TypeError("Already read");this.url=t.url,this.credentials=t.credentials,e.headers||(this.headers=new s(t.headers)),this.method=t.method,this.mode=t.mode,this.signal=t.signal,o||null==t._bodyInit||(o=t._bodyInit,t.bodyUsed=!0)}else this.url=String(t);if(this.credentials=e.credentials||this.credentials||"same-origin",!e.headers&&this.headers||(this.headers=new s(e.headers)),this.method=(n=(r=e.method||this.method||"GET").toUpperCase(),h.indexOf(n)>-1?n:r),this.mode=e.mode||this.mode||null,this.signal=e.signal||this.signal,this.referrer=null,("GET"===this.method||"HEAD"===this.method)&&o)throw new TypeError("Body not allowed for GET or HEAD requests");if(this._initBody(o),!("GET"!==this.method&&"HEAD"!==this.method||"no-store"!==e.cache&&"no-cache"!==e.cache)){var i=/([?&])_=[^&]*/;i.test(this.url)?this.url=this.url.replace(i,"$1_="+(new Date).getTime()):this.url+=(/\?/.test(this.url)?"&":"?")+"_="+(new Date).getTime()}}function d(t){var e=new FormData;return t.trim().split("&").forEach((function(t){if(t){var r=t.split("="),n=r.shift().replace(/\+/g," "),o=r.join("=").replace(/\+/g," ");e.append(decodeURIComponent(n),decodeURIComponent(o))}})),e}function b(t,e){if(!(this instanceof b))throw new TypeError('Please use the "new" operator, this DOM object constructor cannot be called as a function.');e||(e={}),this.type="default",this.status=void 0===e.status?200:e.status,this.ok=this.status>=200&&this.status<300,this.statusText=void 0===e.statusText?"":""+e.statusText,this.headers=new s(e.headers),this.url=e.url||"",this._initBody(t)}y.prototype.clone=function(){return new y(this,{body:this._bodyInit})},p.call(y.prototype),p.call(b.prototype),b.prototype.clone=function(){return new b(this._bodyInit,{status:this.status,statusText:this.statusText,headers:new s(this.headers),url:this.url})},b.error=function(){var t=new b(null,{status:0,statusText:""});return t.type="error",t};var v=[301,302,303,307,308];b.redirect=function(t,e){if(-1===v.indexOf(e))throw new RangeError("Invalid status code");return new b(null,{status:e,headers:{location:t}})};var w=t.DOMException;try{new w}catch(t){(w=function(t,e){this.message=t,this.name=e;var r=Error(t);this.stack=r.stack}).prototype=Object.create(Error.prototype),w.prototype.constructor=w}function m(r,n){return new Promise((function(o,a){var u=new y(r,n);if(u.signal&&u.signal.aborted)return a(new w("Aborted","AbortError"));var c=new XMLHttpRequest;function f(){c.abort()}c.onload=function(){var t,e,r={status:c.status,statusText:c.statusText,headers:(t=c.getAllResponseHeaders()||"",e=new s,t.replace(/\r?\n[\t ]+/g," ").split("\r").map((function(t){return 0===t.indexOf("\n")?t.substr(1,t.length):t})).forEach((function(t){var r=t.split(":"),n=r.shift().trim();if(n){var o=r.join(":").trim();e.append(n,o)}})),e)};r.url="responseURL"in c?c.responseURL:r.headers.get("X-Request-URL");var n="response"in c?c.response:c.responseText;setTimeout((function(){o(new b(n,r))}),0)},c.onerror=function(){setTimeout((function(){a(new TypeError("Network request failed"))}),0)},c.ontimeout=function(){setTimeout((function(){a(new TypeError("Network request failed"))}),0)},c.onabort=function(){setTimeout((function(){a(new w("Aborted","AbortError"))}),0)},c.open(u.method,function(e){try{return""===e&&t.location.href?t.location.href:e}catch(t){return e}}(u.url),!0),"include"===u.credentials?c.withCredentials=!0:"omit"===u.credentials&&(c.withCredentials=!1),"responseType"in c&&(e.blob?c.responseType="blob":e.arrayBuffer&&u.headers.get("Content-Type")&&-1!==u.headers.get("Content-Type").indexOf("application/octet-stream")&&(c.responseType="arraybuffer")),!n||"object"!=typeof n.headers||n.headers instanceof s?u.headers.forEach((function(t,e){c.setRequestHeader(e,t)})):Object.getOwnPropertyNames(n.headers).forEach((function(t){c.setRequestHeader(t,i(n.headers[t]))})),u.signal&&(u.signal.addEventListener("abort",f),c.onreadystatechange=function(){4===c.readyState&&u.signal.removeEventListener("abort",f)}),c.send(void 0===u._bodyInit?null:u._bodyInit)}))}m.polyfill=!0,t.fetch||(t.fetch=m,t.Headers=s,t.Request=y,t.Response=b)})(),(()=>{var t=s(r(372)),e=s(r(179)),n=s(r(310)),o=s(r(474)),i=r(215),a=r(413);function s(t){return t&&t.__esModule?t:{default:t}}function u(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),r.push.apply(r,n)}return r}function c(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{};e%2?u(Object(r),!0).forEach((function(e){f(t,e,r[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):u(Object(r)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))}))}return t}function f(t,e,r){return(e=y(e))in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function l(t,e,r,n,o,i,a){try{var s=t[i](a),u=s.value}catch(t){return void r(t)}s.done?e(u):Promise.resolve(u).then(n,o)}function p(t){return function(){var e=this,r=arguments;return new Promise((function(n,o){var i=t.apply(e,r);function a(t){l(i,n,o,a,s,"next",t)}function s(t){l(i,n,o,a,s,"throw",t)}a(void 0)}))}}function h(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,y(n.key),n)}}function y(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var r=t[Symbol.toPrimitive];if(void 0!==r){var n=r.call(t,"string");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==typeof e?e:String(e)}function d(t,e){if(!Object.prototype.hasOwnProperty.call(t,e))throw new TypeError("attempted to use private field on non-instance");return t}var b=0;function v(t){return"__private_"+b+++"_"+t}var w=v("session"),m=v("business"),O=v("eventEmitter"),P=v("query"),g=v("notInitialized"),j=v("mintAnonymousSession"),_=v("headers"),E=v("setSessionCookie"),T=v("cookie"),S=function(){function e(){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e)}var r,s,u;return r=e,null,s=[{key:"initialize",value:function(t){if(d(this,m)[m]=t,d(this,P)[P]=new o.default(window.location.search),!d(this,P)[P].has("preview")){var e=d(this,P)[P].get("session")||d(this,T)[T];e&&"undefined"!==e&&"null"!==e?(d(this,w)[w]=e,d(this,E)[E]()):d(this,j)[j]().then((t=>{d(this,w)[w]=t.id,d(this,E)[E]()}))}}},{key:"track",value:(u=p((function*(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(d(this,g)[g])throw new i.NotInitializedError;if(d(this,P)[P].has("preview"))return new n.default(!0,{received:!0});var r=yield fetch(this.__apiURL+"track/events",{headers:d(this,_)[_],method:"post",body:JSON.stringify(c(c({session:this.session,action:t},e),{},{url:e&&e.url||window.location.href}))});return new n.default(200===r.status,yield r.json())})),function(t){return u.apply(this,arguments)})},{key:"on",value:function(e,r){if(t.default.invalid(e))throw new a.InvalidEvent(e);d(this,O)[O].addSubscriber(e,r)}},{key:"removeEventListener",value:function(e,r){if(t.default.invalid(e))throw new a.InvalidEvent(e);d(this,O)[O].removeSubscriber(e,r)}},{key:"session",get:function(){if(d(this,g)[g])throw new i.NotInitializedError;return d(this,w)[w]}},{key:"isInitialized",get:function(){return void 0!==d(this,w)[w]}}],s&&h(r,s),Object.defineProperty(r,"prototype",{writable:!1}),e}();function A(){return(A=p((function*(){if(d(this,g)[g])throw new i.NotInitializedError;var t=this.__apiURL+"track/sessions";return this.mintingPromise=yield fetch(t,{method:"post",headers:{Authorization:"Bearer ".concat(d(this,m)[m])}}),this.mintingPromise.json()}))).apply(this,arguments)}Object.defineProperty(S,T,{get:function(){var t;return null===(t=document.cookie.match("(^|;)\\s*hello_session\\s*=\\s*([^;]+)"))||void 0===t?void 0:t.pop()},set:void 0}),Object.defineProperty(S,E,{value:function(){if(d(this,g)[g])throw new i.NotInitializedError;d(this,O)[O].listeners&&d(this,O)[O].emit("session-set",d(this,w)[w]),document.cookie="hello_session=".concat(d(this,w)[w])}}),Object.defineProperty(S,_,{get:function(){if(d(this,g)[g])throw new i.NotInitializedError;return{Authorization:"Bearer ".concat(d(this,m)[m]),Accept:"application.json","Content-Type":"application/json"}},set:void 0}),Object.defineProperty(S,j,{value:function(){return A.apply(this,arguments)}}),Object.defineProperty(S,g,{get:function(){return void 0===d(this,m)[m]},set:void 0}),S.__apiURL="https://api.hellotext.com/v1/",Object.defineProperty(S,w,{writable:!0,value:void 0}),Object.defineProperty(S,m,{writable:!0,value:void 0}),Object.defineProperty(S,O,{writable:!0,value:new e.default}),Object.defineProperty(S,P,{writable:!0,value:void 0})})()})();
1
+ (()=>{"use strict";var e={413:(e,t)=>{function r(e){var t="function"==typeof Map?new Map:void 0;return r=function(e){if(null===e||(r=e,-1===Function.toString.call(r).indexOf("[native code]")))return e;var r;if("function"!=typeof e)throw new TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,o)}function o(){return n(e,arguments,a(this).constructor)}return o.prototype=Object.create(e.prototype,{constructor:{value:o,enumerable:!1,writable:!0,configurable:!0}}),i(o,e)},r(e)}function n(e,t,r){return n=o()?Reflect.construct.bind():function(e,t,r){var n=[null];n.push.apply(n,t);var o=new(Function.bind.apply(e,n));return r&&i(o,r.prototype),o},n.apply(null,arguments)}function o(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}function i(e,t){return i=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},i(e,t)}function a(e){return a=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},a(e)}Object.defineProperty(t,"__esModule",{value:!0}),t.InvalidEvent=void 0;var s=function(e){!function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&i(e,t)}(u,e);var t,r,n,s=(r=u,n=o(),function(){var e,t=a(r);if(n){var o=a(this).constructor;e=Reflect.construct(t,arguments,o)}else e=t.apply(this,arguments);return function(e,t){if(t&&("object"==typeof t||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}(this,e)});function u(e){var t;return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,u),(t=s.call(this,"".concat(e," is not valid. Please provide a valid event name"))).name="InvalidEvent",t}return t=u,Object.defineProperty(t,"prototype",{writable:!1}),t}(r(Error));t.InvalidEvent=s},215:(e,t)=>{function r(e){var t="function"==typeof Map?new Map:void 0;return r=function(e){if(null===e||(r=e,-1===Function.toString.call(r).indexOf("[native code]")))return e;var r;if("function"!=typeof e)throw new TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,o)}function o(){return n(e,arguments,a(this).constructor)}return o.prototype=Object.create(e.prototype,{constructor:{value:o,enumerable:!1,writable:!0,configurable:!0}}),i(o,e)},r(e)}function n(e,t,r){return n=o()?Reflect.construct.bind():function(e,t,r){var n=[null];n.push.apply(n,t);var o=new(Function.bind.apply(e,n));return r&&i(o,r.prototype),o},n.apply(null,arguments)}function o(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}function i(e,t){return i=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},i(e,t)}function a(e){return a=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},a(e)}Object.defineProperty(t,"__esModule",{value:!0}),t.NotInitializedError=void 0;var s=function(e){!function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&i(e,t)}(u,e);var t,r,n,s=(r=u,n=o(),function(){var e,t=a(r);if(n){var o=a(this).constructor;e=Reflect.construct(t,arguments,o)}else e=t.apply(this,arguments);return function(e,t){if(t&&("object"==typeof t||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}(this,e)});function u(){var e;return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,u),(e=s.call(this,"You need to initialize before tracking events. Call Hellotext.initialize and pass your public business id")).name="NotInitializedError",e}return t=u,Object.defineProperty(t,"prototype",{writable:!1}),t}(r(Error));t.NotInitializedError=s},372:(e,t)=>{function r(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,(void 0,"symbol"==typeof(o=function(e,t){if("object"!=typeof e||null===e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,"string");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(n.key))?o:String(o)),n)}var o}Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;var n=function(){function e(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e)}var t,n;return t=e,n=[{key:"valid",value:function(t){return e.exists(t)}},{key:"invalid",value:function(e){return!this.valid(e)}},{key:"exists",value:function(e){return void 0!==this.events.find((t=>t===e))}}],null&&r(t.prototype,null),n&&r(t,n),Object.defineProperty(t,"prototype",{writable:!1}),e}();t.default=n,n.events=["session-set"]},179:(e,t)=>{function r(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function n(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?r(Object(n),!0).forEach((function(t){o(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):r(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function o(e,t,r){return(t=a(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function i(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,a(n.key),n)}}function a(e){var t=function(e,t){if("object"!=typeof e||null===e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,"string");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==typeof t?t:String(t)}Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;var s=function(){function e(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.subscribers={}}var t,r;return t=e,(r=[{key:"addSubscriber",value:function(e,t){this.subscribers=n(n({},this.subscribers),{},{[e]:this.subscribers[e]?[...this.subscribers[e],t]:[t]})}},{key:"removeSubscriber",value:function(e,t){this.subscribers[e]&&(this.subscribers[e]=this.subscribers[e].filter((e=>e!==t)))}},{key:"emit",value:function(e,t){this.subscribers[e].forEach((e=>{e(t)}))}},{key:"listeners",get:function(){return 0!==Object.keys(this.subscribers).length}}])&&i(t.prototype,r),Object.defineProperty(t,"prototype",{writable:!1}),e}();t.default=s},474:(e,t)=>{function r(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,(void 0,"symbol"==typeof(o=function(e,t){if("object"!=typeof e||null===e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,"string");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(n.key))?o:String(o)),n)}var o}Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;var n=function(){function e(t){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.urlSearchParams=new URLSearchParams(t)}var t,n;return t=e,(n=[{key:"get",value:function(e){return this.urlSearchParams.get(this.toHellotextParam(e))}},{key:"has",value:function(e){return this.urlSearchParams.has(this.toHellotextParam(e))}},{key:"toHellotextParam",value:function(e){return"hello_".concat(e)}}])&&r(t.prototype,n),Object.defineProperty(t,"prototype",{writable:!1}),e}();t.default=n},310:(e,t)=>{function r(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,(void 0,"symbol"==typeof(o=function(e,t){if("object"!=typeof e||null===e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,"string");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(n.key))?o:String(o)),n)}var o}function n(e,t){if(!Object.prototype.hasOwnProperty.call(e,t))throw new TypeError("attempted to use private field on non-instance");return e}Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;var o=0;function i(e){return"__private_"+o+++"_"+e}var a=i("success"),s=i("response"),u=function(){function e(t,r){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),Object.defineProperty(this,a,{writable:!0,value:void 0}),Object.defineProperty(this,s,{writable:!0,value:void 0}),n(this,a)[a]=t,n(this,s)[s]=r}var t,o;return t=e,(o=[{key:"data",get:function(){return n(this,s)[s]}},{key:"failed",get:function(){return!1===n(this,a)[a]}},{key:"succeeded",get:function(){return!0===n(this,a)[a]}}])&&r(t.prototype,o),Object.defineProperty(t,"prototype",{writable:!1}),e}();t.default=u}},t={};function r(n){var o=t[n];if(void 0!==o)return o.exports;var i=t[n]={exports:{}};return e[n](i,i.exports,r),i.exports}r.d=(e,t)=>{for(var n in t)r.o(t,n)&&!r.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),(()=>{var e="undefined"!=typeof globalThis&&globalThis||"undefined"!=typeof self&&self||void 0!==e&&e,t={searchParams:"URLSearchParams"in e,iterable:"Symbol"in e&&"iterator"in Symbol,blob:"FileReader"in e&&"Blob"in e&&function(){try{return new Blob,!0}catch(e){return!1}}(),formData:"FormData"in e,arrayBuffer:"ArrayBuffer"in e};if(t.arrayBuffer)var r=["[object Int8Array]","[object Uint8Array]","[object Uint8ClampedArray]","[object Int16Array]","[object Uint16Array]","[object Int32Array]","[object Uint32Array]","[object Float32Array]","[object Float64Array]"],n=ArrayBuffer.isView||function(e){return e&&r.indexOf(Object.prototype.toString.call(e))>-1};function o(e){if("string"!=typeof e&&(e=String(e)),/[^a-z0-9\-#$%&'*+.^_`|~!]/i.test(e)||""===e)throw new TypeError('Invalid character in header field name: "'+e+'"');return e.toLowerCase()}function i(e){return"string"!=typeof e&&(e=String(e)),e}function a(e){var r={next:function(){var t=e.shift();return{done:void 0===t,value:t}}};return t.iterable&&(r[Symbol.iterator]=function(){return r}),r}function s(e){this.map={},e instanceof s?e.forEach((function(e,t){this.append(t,e)}),this):Array.isArray(e)?e.forEach((function(e){this.append(e[0],e[1])}),this):e&&Object.getOwnPropertyNames(e).forEach((function(t){this.append(t,e[t])}),this)}function u(e){if(e.bodyUsed)return Promise.reject(new TypeError("Already read"));e.bodyUsed=!0}function c(e){return new Promise((function(t,r){e.onload=function(){t(e.result)},e.onerror=function(){r(e.error)}}))}function f(e){var t=new FileReader,r=c(t);return t.readAsArrayBuffer(e),r}function l(e){if(e.slice)return e.slice(0);var t=new Uint8Array(e.byteLength);return t.set(new Uint8Array(e)),t.buffer}function p(){return this.bodyUsed=!1,this._initBody=function(e){var r;this.bodyUsed=this.bodyUsed,this._bodyInit=e,e?"string"==typeof e?this._bodyText=e:t.blob&&Blob.prototype.isPrototypeOf(e)?this._bodyBlob=e:t.formData&&FormData.prototype.isPrototypeOf(e)?this._bodyFormData=e:t.searchParams&&URLSearchParams.prototype.isPrototypeOf(e)?this._bodyText=e.toString():t.arrayBuffer&&t.blob&&(r=e)&&DataView.prototype.isPrototypeOf(r)?(this._bodyArrayBuffer=l(e.buffer),this._bodyInit=new Blob([this._bodyArrayBuffer])):t.arrayBuffer&&(ArrayBuffer.prototype.isPrototypeOf(e)||n(e))?this._bodyArrayBuffer=l(e):this._bodyText=e=Object.prototype.toString.call(e):this._bodyText="",this.headers.get("content-type")||("string"==typeof e?this.headers.set("content-type","text/plain;charset=UTF-8"):this._bodyBlob&&this._bodyBlob.type?this.headers.set("content-type",this._bodyBlob.type):t.searchParams&&URLSearchParams.prototype.isPrototypeOf(e)&&this.headers.set("content-type","application/x-www-form-urlencoded;charset=UTF-8"))},t.blob&&(this.blob=function(){var e=u(this);if(e)return e;if(this._bodyBlob)return Promise.resolve(this._bodyBlob);if(this._bodyArrayBuffer)return Promise.resolve(new Blob([this._bodyArrayBuffer]));if(this._bodyFormData)throw new Error("could not read FormData body as blob");return Promise.resolve(new Blob([this._bodyText]))},this.arrayBuffer=function(){return this._bodyArrayBuffer?u(this)||(ArrayBuffer.isView(this._bodyArrayBuffer)?Promise.resolve(this._bodyArrayBuffer.buffer.slice(this._bodyArrayBuffer.byteOffset,this._bodyArrayBuffer.byteOffset+this._bodyArrayBuffer.byteLength)):Promise.resolve(this._bodyArrayBuffer)):this.blob().then(f)}),this.text=function(){var e,t,r,n=u(this);if(n)return n;if(this._bodyBlob)return e=this._bodyBlob,r=c(t=new FileReader),t.readAsText(e),r;if(this._bodyArrayBuffer)return Promise.resolve(function(e){for(var t=new Uint8Array(e),r=new Array(t.length),n=0;n<t.length;n++)r[n]=String.fromCharCode(t[n]);return r.join("")}(this._bodyArrayBuffer));if(this._bodyFormData)throw new Error("could not read FormData body as text");return Promise.resolve(this._bodyText)},t.formData&&(this.formData=function(){return this.text().then(d)}),this.json=function(){return this.text().then(JSON.parse)},this}s.prototype.append=function(e,t){e=o(e),t=i(t);var r=this.map[e];this.map[e]=r?r+", "+t:t},s.prototype.delete=function(e){delete this.map[o(e)]},s.prototype.get=function(e){return e=o(e),this.has(e)?this.map[e]:null},s.prototype.has=function(e){return this.map.hasOwnProperty(o(e))},s.prototype.set=function(e,t){this.map[o(e)]=i(t)},s.prototype.forEach=function(e,t){for(var r in this.map)this.map.hasOwnProperty(r)&&e.call(t,this.map[r],r,this)},s.prototype.keys=function(){var e=[];return this.forEach((function(t,r){e.push(r)})),a(e)},s.prototype.values=function(){var e=[];return this.forEach((function(t){e.push(t)})),a(e)},s.prototype.entries=function(){var e=[];return this.forEach((function(t,r){e.push([r,t])})),a(e)},t.iterable&&(s.prototype[Symbol.iterator]=s.prototype.entries);var h=["DELETE","GET","HEAD","OPTIONS","POST","PUT"];function y(e,t){if(!(this instanceof y))throw new TypeError('Please use the "new" operator, this DOM object constructor cannot be called as a function.');var r,n,o=(t=t||{}).body;if(e instanceof y){if(e.bodyUsed)throw new TypeError("Already read");this.url=e.url,this.credentials=e.credentials,t.headers||(this.headers=new s(e.headers)),this.method=e.method,this.mode=e.mode,this.signal=e.signal,o||null==e._bodyInit||(o=e._bodyInit,e.bodyUsed=!0)}else this.url=String(e);if(this.credentials=t.credentials||this.credentials||"same-origin",!t.headers&&this.headers||(this.headers=new s(t.headers)),this.method=(n=(r=t.method||this.method||"GET").toUpperCase(),h.indexOf(n)>-1?n:r),this.mode=t.mode||this.mode||null,this.signal=t.signal||this.signal,this.referrer=null,("GET"===this.method||"HEAD"===this.method)&&o)throw new TypeError("Body not allowed for GET or HEAD requests");if(this._initBody(o),!("GET"!==this.method&&"HEAD"!==this.method||"no-store"!==t.cache&&"no-cache"!==t.cache)){var i=/([?&])_=[^&]*/;i.test(this.url)?this.url=this.url.replace(i,"$1_="+(new Date).getTime()):this.url+=(/\?/.test(this.url)?"&":"?")+"_="+(new Date).getTime()}}function d(e){var t=new FormData;return e.trim().split("&").forEach((function(e){if(e){var r=e.split("="),n=r.shift().replace(/\+/g," "),o=r.join("=").replace(/\+/g," ");t.append(decodeURIComponent(n),decodeURIComponent(o))}})),t}function b(e,t){if(!(this instanceof b))throw new TypeError('Please use the "new" operator, this DOM object constructor cannot be called as a function.');t||(t={}),this.type="default",this.status=void 0===t.status?200:t.status,this.ok=this.status>=200&&this.status<300,this.statusText=void 0===t.statusText?"":""+t.statusText,this.headers=new s(t.headers),this.url=t.url||"",this._initBody(e)}y.prototype.clone=function(){return new y(this,{body:this._bodyInit})},p.call(y.prototype),p.call(b.prototype),b.prototype.clone=function(){return new b(this._bodyInit,{status:this.status,statusText:this.statusText,headers:new s(this.headers),url:this.url})},b.error=function(){var e=new b(null,{status:0,statusText:""});return e.type="error",e};var v=[301,302,303,307,308];b.redirect=function(e,t){if(-1===v.indexOf(t))throw new RangeError("Invalid status code");return new b(null,{status:t,headers:{location:e}})};var w=e.DOMException;try{new w}catch(e){(w=function(e,t){this.message=e,this.name=t;var r=Error(e);this.stack=r.stack}).prototype=Object.create(Error.prototype),w.prototype.constructor=w}function m(r,n){return new Promise((function(o,a){var u=new y(r,n);if(u.signal&&u.signal.aborted)return a(new w("Aborted","AbortError"));var c=new XMLHttpRequest;function f(){c.abort()}c.onload=function(){var e,t,r={status:c.status,statusText:c.statusText,headers:(e=c.getAllResponseHeaders()||"",t=new s,e.replace(/\r?\n[\t ]+/g," ").split("\r").map((function(e){return 0===e.indexOf("\n")?e.substr(1,e.length):e})).forEach((function(e){var r=e.split(":"),n=r.shift().trim();if(n){var o=r.join(":").trim();t.append(n,o)}})),t)};r.url="responseURL"in c?c.responseURL:r.headers.get("X-Request-URL");var n="response"in c?c.response:c.responseText;setTimeout((function(){o(new b(n,r))}),0)},c.onerror=function(){setTimeout((function(){a(new TypeError("Network request failed"))}),0)},c.ontimeout=function(){setTimeout((function(){a(new TypeError("Network request failed"))}),0)},c.onabort=function(){setTimeout((function(){a(new w("Aborted","AbortError"))}),0)},c.open(u.method,function(t){try{return""===t&&e.location.href?e.location.href:t}catch(e){return t}}(u.url),!0),"include"===u.credentials?c.withCredentials=!0:"omit"===u.credentials&&(c.withCredentials=!1),"responseType"in c&&(t.blob?c.responseType="blob":t.arrayBuffer&&u.headers.get("Content-Type")&&-1!==u.headers.get("Content-Type").indexOf("application/octet-stream")&&(c.responseType="arraybuffer")),!n||"object"!=typeof n.headers||n.headers instanceof s?u.headers.forEach((function(e,t){c.setRequestHeader(t,e)})):Object.getOwnPropertyNames(n.headers).forEach((function(e){c.setRequestHeader(e,i(n.headers[e]))})),u.signal&&(u.signal.addEventListener("abort",f),c.onreadystatechange=function(){4===c.readyState&&u.signal.removeEventListener("abort",f)}),c.send(void 0===u._bodyInit?null:u._bodyInit)}))}m.polyfill=!0,e.fetch||(e.fetch=m,e.Headers=s,e.Request=y,e.Response=b)})(),(()=>{var e=s(r(372)),t=s(r(179)),n=s(r(310)),o=s(r(474)),i=r(215),a=r(413);function s(e){return e&&e.__esModule?e:{default:e}}function u(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function c(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?u(Object(r),!0).forEach((function(t){f(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):u(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function f(e,t,r){return(t=y(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function l(e,t,r,n,o,i,a){try{var s=e[i](a),u=s.value}catch(e){return void r(e)}s.done?t(u):Promise.resolve(u).then(n,o)}function p(e){return function(){var t=this,r=arguments;return new Promise((function(n,o){var i=e.apply(t,r);function a(e){l(i,n,o,a,s,"next",e)}function s(e){l(i,n,o,a,s,"throw",e)}a(void 0)}))}}function h(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,y(n.key),n)}}function y(e){var t=function(e,t){if("object"!=typeof e||null===e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,"string");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==typeof t?t:String(t)}function d(e,t){if(!Object.prototype.hasOwnProperty.call(e,t))throw new TypeError("attempted to use private field on non-instance");return e}var b=0;function v(e){return"__private_"+b+++"_"+e}var w=v("session"),m=v("business"),O=v("config"),g=v("eventEmitter"),P=v("query"),j=v("notInitialized"),_=v("mintAnonymousSession"),E=v("headers"),T=v("setSessionCookie"),S=v("cookie"),A=function(){function t(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t)}var r,s,u;return r=t,null,s=[{key:"initialize",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{autogenerateSession:!0};if(d(this,m)[m]=e,d(this,O)[O]=t,d(this,P)[P]=new o.default(window.location.search),!d(this,P)[P].has("preview")){var r=d(this,P)[P].get("session")||d(this,S)[S];r&&"undefined"!==r&&"null"!==r?(d(this,w)[w]=r,d(this,T)[T]()):t.autogenerateSession&&d(this,_)[_]().then((e=>{d(this,w)[w]=e.id,d(this,T)[T]()}))}}},{key:"track",value:(u=p((function*(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(d(this,j)[j])throw new i.NotInitializedError;if(d(this,P)[P].has("preview"))return new n.default(!0,{received:!0});var r=yield fetch(this.__apiURL+"track/events",{headers:d(this,E)[E],method:"post",body:JSON.stringify(c(c({session:this.session,action:e},t),{},{url:t&&t.url||window.location.href}))});return new n.default(200===r.status,yield r.json())})),function(e){return u.apply(this,arguments)})},{key:"on",value:function(t,r){if(e.default.invalid(t))throw new a.InvalidEvent(t);d(this,g)[g].addSubscriber(t,r)}},{key:"removeEventListener",value:function(t,r){if(e.default.invalid(t))throw new a.InvalidEvent(t);d(this,g)[g].removeSubscriber(t,r)}},{key:"session",get:function(){if(d(this,j)[j])throw new i.NotInitializedError;return d(this,w)[w]}},{key:"isInitialized",get:function(){return void 0!==d(this,w)[w]}}],s&&h(r,s),Object.defineProperty(r,"prototype",{writable:!1}),t}();function x(){return(x=p((function*(){if(d(this,j)[j])throw new i.NotInitializedError;var e=this.__apiURL+"track/sessions";return this.mintingPromise=yield fetch(e,{method:"post",headers:{Authorization:"Bearer ".concat(d(this,m)[m])}}),this.mintingPromise.json()}))).apply(this,arguments)}Object.defineProperty(A,S,{get:function(){var e;return null===(e=document.cookie.match("(^|;)\\s*hello_session\\s*=\\s*([^;]+)"))||void 0===e?void 0:e.pop()},set:void 0}),Object.defineProperty(A,T,{value:function(){if(d(this,j)[j])throw new i.NotInitializedError;d(this,g)[g].listeners&&d(this,g)[g].emit("session-set",d(this,w)[w]),document.cookie="hello_session=".concat(d(this,w)[w])}}),Object.defineProperty(A,E,{get:function(){if(d(this,j)[j])throw new i.NotInitializedError;return{Authorization:"Bearer ".concat(d(this,m)[m]),Accept:"application.json","Content-Type":"application/json"}},set:void 0}),Object.defineProperty(A,_,{value:function(){return x.apply(this,arguments)}}),Object.defineProperty(A,j,{get:function(){return void 0===d(this,m)[m]},set:void 0}),A.__apiURL="https://api.hellotext.com/v1/",Object.defineProperty(A,w,{writable:!0,value:void 0}),Object.defineProperty(A,m,{writable:!0,value:void 0}),Object.defineProperty(A,O,{writable:!0,value:void 0}),Object.defineProperty(A,g,{writable:!0,value:new t.default}),Object.defineProperty(A,P,{writable:!0,value:void 0})})()})();
package/lib/hellotext.js CHANGED
@@ -26,6 +26,7 @@ var id = 0;
26
26
  function _classPrivateFieldLooseKey(name) { return "__private_" + id++ + "_" + name; }
27
27
  var _session = /*#__PURE__*/_classPrivateFieldLooseKey("session");
28
28
  var _business = /*#__PURE__*/_classPrivateFieldLooseKey("business");
29
+ var _config = /*#__PURE__*/_classPrivateFieldLooseKey("config");
29
30
  var _eventEmitter = /*#__PURE__*/_classPrivateFieldLooseKey("eventEmitter");
30
31
  var _query = /*#__PURE__*/_classPrivateFieldLooseKey("query");
31
32
  var _notInitialized = /*#__PURE__*/_classPrivateFieldLooseKey("notInitialized");
@@ -33,6 +34,10 @@ var _mintAnonymousSession = /*#__PURE__*/_classPrivateFieldLooseKey("mintAnonymo
33
34
  var _headers = /*#__PURE__*/_classPrivateFieldLooseKey("headers");
34
35
  var _setSessionCookie = /*#__PURE__*/_classPrivateFieldLooseKey("setSessionCookie");
35
36
  var _cookie = /*#__PURE__*/_classPrivateFieldLooseKey("cookie");
37
+ /**
38
+ * @typedef {Object} Config
39
+ * @property {Boolean} autogenerateSession
40
+ */
36
41
  var Hellotext = /*#__PURE__*/function () {
37
42
  function Hellotext() {
38
43
  _classCallCheck(this, Hellotext);
@@ -43,16 +48,21 @@ var Hellotext = /*#__PURE__*/function () {
43
48
  /**
44
49
  * initialize the module.
45
50
  * @param business public business id
51
+ * @param { Config } config
46
52
  */
47
53
  function initialize(business) {
54
+ var config = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
55
+ autogenerateSession: true
56
+ };
48
57
  _classPrivateFieldLooseBase(this, _business)[_business] = business;
58
+ _classPrivateFieldLooseBase(this, _config)[_config] = config;
49
59
  _classPrivateFieldLooseBase(this, _query)[_query] = new _query2.default(window.location.search);
50
60
  if (_classPrivateFieldLooseBase(this, _query)[_query].has("preview")) return;
51
61
  var session = _classPrivateFieldLooseBase(this, _query)[_query].get("session") || _classPrivateFieldLooseBase(this, _cookie)[_cookie];
52
62
  if (session && session !== "undefined" && session !== "null") {
53
63
  _classPrivateFieldLooseBase(this, _session)[_session] = session;
54
64
  _classPrivateFieldLooseBase(this, _setSessionCookie)[_setSessionCookie]();
55
- } else {
65
+ } else if (config.autogenerateSession) {
56
66
  _classPrivateFieldLooseBase(this, _mintAnonymousSession)[_mintAnonymousSession]().then(response => {
57
67
  _classPrivateFieldLooseBase(this, _session)[_session] = response.id;
58
68
  _classPrivateFieldLooseBase(this, _setSessionCookie)[_setSessionCookie]();
@@ -224,6 +234,10 @@ Object.defineProperty(Hellotext, _business, {
224
234
  writable: true,
225
235
  value: void 0
226
236
  });
237
+ Object.defineProperty(Hellotext, _config, {
238
+ writable: true,
239
+ value: void 0
240
+ });
227
241
  Object.defineProperty(Hellotext, _eventEmitter, {
228
242
  writable: true,
229
243
  value: new _eventEmitter2.default()
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hellotext/hellotext",
3
- "version": "1.4.0",
3
+ "version": "1.4.1",
4
4
  "description": "Hellotext JavaScript Client",
5
5
  "source": "src/index.js",
6
6
  "main": "lib/index.js",
@@ -30,6 +30,7 @@
30
30
  ],
31
31
  "scripts": {
32
32
  "test": "NODE_ENV=test jest",
33
+ "build": "npm run build:babel && npm run build:webpack",
33
34
  "build:babel": "babel src -d lib",
34
35
  "build:webpack": "webpack"
35
36
  },