@hellotext/hellotext 1.3.1 → 1.3.2

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.
@@ -0,0 +1 @@
1
+ (()=>{"use strict";var t={413:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.InvalidEvent=void 0;class r extends Error{constructor(t){super("".concat(t," is not valid. Please provide a valid event name")),this.name="InvalidEvent"}}e.InvalidEvent=r},215:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.NotInitializedError=void 0;class r extends Error{constructor(){super("You need to initialize before tracking events. Call Hellotext.initialize and pass your public business id"),this.name="NotInitializedError"}}e.NotInitializedError=r},372:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.default=void 0;class r{static valid(t){return r.exists(t)}static invalid(t){return!this.valid(t)}static exists(t){return void 0!==this.events.find((e=>e===t))}}e.default=r,r.events=["session-set"]},179:(t,e)=>{function r(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(t);e&&(i=i.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),r.push.apply(r,i)}return r}function i(t){for(var e=1;e<arguments.length;e++){var i=null!=arguments[e]?arguments[e]:{};e%2?r(Object(i),!0).forEach((function(e){o(t,e,i[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(i)):r(Object(i)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(i,e))}))}return t}function o(t,e,r){return(e=function(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var r=t[Symbol.toPrimitive];if(void 0!==r){var i=r.call(t,"string");if("object"!=typeof i)return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==typeof e?e:String(e)}(e))in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}Object.defineProperty(e,"__esModule",{value:!0}),e.default=void 0,e.default=class{constructor(){this.subscribers={}}addSubscriber(t,e){this.subscribers=i(i({},this.subscribers),{},{[t]:this.subscribers[t]?[...this.subscribers[t],e]:[e]})}removeSubscriber(t,e){this.subscribers[t]&&(this.subscribers[t]=this.subscribers[t].filter((t=>t!==e)))}emit(t,e){this.subscribers[t].forEach((t=>{t(e)}))}get listeners(){return 0!==Object.keys(this.subscribers).length}}},474:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.default=void 0,e.default=class{constructor(t){this.urlSearchParams=new URLSearchParams(t)}get(t){return this.urlSearchParams.get(this.toHellotextParam(t))}has(t){return this.urlSearchParams.has(this.toHellotextParam(t))}toHellotextParam(t){return"hello_".concat(t)}}},310:(t,e)=>{function r(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 i=0;function o(t){return"__private_"+i+++"_"+t}var n=o("success"),s=o("response");e.default=class{constructor(t,e){Object.defineProperty(this,n,{writable:!0,value:void 0}),Object.defineProperty(this,s,{writable:!0,value:void 0}),r(this,n)[n]=t,r(this,s)[s]=e}get data(){return r(this,s)[s]}get failed(){return!1===r(this,n)[n]}get succeeded(){return!0===r(this,n)[n]}}}},e={};function r(i){var o=e[i];if(void 0!==o)return o.exports;var n=e[i]={exports:{}};return t[i](n,n.exports,r),n.exports}r.d=(t,e)=>{for(var i in e)r.o(e,i)&&!r.o(t,i)&&Object.defineProperty(t,i,{enumerable:!0,get:e[i]})},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]"],i=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 n(t){return"string"!=typeof t&&(t=String(t)),t}function s(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 a(t){this.map={},t instanceof a?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 h(t){var e=new FileReader,r=c(e);return e.readAsArrayBuffer(t),r}function f(t){if(t.slice)return t.slice(0);var e=new Uint8Array(t.byteLength);return e.set(new Uint8Array(t)),e.buffer}function l(){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=f(t.buffer),this._bodyInit=new Blob([this._bodyArrayBuffer])):e.arrayBuffer&&(ArrayBuffer.prototype.isPrototypeOf(t)||i(t))?this._bodyArrayBuffer=f(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(h)}),this.text=function(){var t,e,r,i=u(this);if(i)return i;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),i=0;i<e.length;i++)r[i]=String.fromCharCode(e[i]);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(y)}),this.json=function(){return this.text().then(JSON.parse)},this}a.prototype.append=function(t,e){t=o(t),e=n(e);var r=this.map[t];this.map[t]=r?r+", "+e:e},a.prototype.delete=function(t){delete this.map[o(t)]},a.prototype.get=function(t){return t=o(t),this.has(t)?this.map[t]:null},a.prototype.has=function(t){return this.map.hasOwnProperty(o(t))},a.prototype.set=function(t,e){this.map[o(t)]=n(e)},a.prototype.forEach=function(t,e){for(var r in this.map)this.map.hasOwnProperty(r)&&t.call(e,this.map[r],r,this)},a.prototype.keys=function(){var t=[];return this.forEach((function(e,r){t.push(r)})),s(t)},a.prototype.values=function(){var t=[];return this.forEach((function(e){t.push(e)})),s(t)},a.prototype.entries=function(){var t=[];return this.forEach((function(e,r){t.push([r,e])})),s(t)},e.iterable&&(a.prototype[Symbol.iterator]=a.prototype.entries);var d=["DELETE","GET","HEAD","OPTIONS","POST","PUT"];function p(t,e){if(!(this instanceof p))throw new TypeError('Please use the "new" operator, this DOM object constructor cannot be called as a function.');var r,i,o=(e=e||{}).body;if(t instanceof p){if(t.bodyUsed)throw new TypeError("Already read");this.url=t.url,this.credentials=t.credentials,e.headers||(this.headers=new a(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 a(e.headers)),this.method=(i=(r=e.method||this.method||"GET").toUpperCase(),d.indexOf(i)>-1?i: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 n=/([?&])_=[^&]*/;n.test(this.url)?this.url=this.url.replace(n,"$1_="+(new Date).getTime()):this.url+=(/\?/.test(this.url)?"&":"?")+"_="+(new Date).getTime()}}function y(t){var e=new FormData;return t.trim().split("&").forEach((function(t){if(t){var r=t.split("="),i=r.shift().replace(/\+/g," "),o=r.join("=").replace(/\+/g," ");e.append(decodeURIComponent(i),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 a(e.headers),this.url=e.url||"",this._initBody(t)}p.prototype.clone=function(){return new p(this,{body:this._bodyInit})},l.call(p.prototype),l.call(b.prototype),b.prototype.clone=function(){return new b(this._bodyInit,{status:this.status,statusText:this.statusText,headers:new a(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 m=t.DOMException;try{new m}catch(t){(m=function(t,e){this.message=t,this.name=e;var r=Error(t);this.stack=r.stack}).prototype=Object.create(Error.prototype),m.prototype.constructor=m}function w(r,i){return new Promise((function(o,s){var u=new p(r,i);if(u.signal&&u.signal.aborted)return s(new m("Aborted","AbortError"));var c=new XMLHttpRequest;function h(){c.abort()}c.onload=function(){var t,e,r={status:c.status,statusText:c.statusText,headers:(t=c.getAllResponseHeaders()||"",e=new a,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(":"),i=r.shift().trim();if(i){var o=r.join(":").trim();e.append(i,o)}})),e)};r.url="responseURL"in c?c.responseURL:r.headers.get("X-Request-URL");var i="response"in c?c.response:c.responseText;setTimeout((function(){o(new b(i,r))}),0)},c.onerror=function(){setTimeout((function(){s(new TypeError("Network request failed"))}),0)},c.ontimeout=function(){setTimeout((function(){s(new TypeError("Network request failed"))}),0)},c.onabort=function(){setTimeout((function(){s(new m("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")),!i||"object"!=typeof i.headers||i.headers instanceof a?u.headers.forEach((function(t,e){c.setRequestHeader(e,t)})):Object.getOwnPropertyNames(i.headers).forEach((function(t){c.setRequestHeader(t,n(i.headers[t]))})),u.signal&&(u.signal.addEventListener("abort",h),c.onreadystatechange=function(){4===c.readyState&&u.signal.removeEventListener("abort",h)}),c.send(void 0===u._bodyInit?null:u._bodyInit)}))}w.polyfill=!0,t.fetch||(t.fetch=w,t.Headers=a,t.Request=p,t.Response=b)})(),(()=>{var t=a(r(372)),e=a(r(179)),i=a(r(310)),o=a(r(474)),n=r(215),s=r(413);function a(t){return t&&t.__esModule?t:{default:t}}function u(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(t);e&&(i=i.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),r.push.apply(r,i)}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){h(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 h(t,e,r){return(e=function(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var r=t[Symbol.toPrimitive];if(void 0!==r){var i=r.call(t,"string");if("object"!=typeof i)return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==typeof e?e:String(e)}(e))in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function f(t,e,r,i,o,n,s){try{var a=t[n](s),u=a.value}catch(t){return void r(t)}a.done?e(u):Promise.resolve(u).then(i,o)}function l(t){return function(){var e=this,r=arguments;return new Promise((function(i,o){var n=t.apply(e,r);function s(t){f(n,i,o,s,a,"next",t)}function a(t){f(n,i,o,s,a,"throw",t)}s(void 0)}))}}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 p=0;function y(t){return"__private_"+p+++"_"+t}var b="https://api.hellotext.com/v1/",v=y("session"),m=y("business"),w=y("eventEmitter"),O=y("query"),g=y("notInitialized"),P=y("mintAnonymousSession"),j=y("headers"),_=y("setSessionCookie"),E=y("cookie");class T{static initialize(t){if(d(this,m)[m]=t,d(this,O)[O]=new o.default(window.location.search),!d(this,O)[O].has("preview")){var e=d(this,O)[O].get("session")||d(this,E)[E];e&&"undefined"!==e&&"null"!==e?(d(this,v)[v]=e,d(this,_)[_]()):d(this,P)[P]().then((t=>{d(this,v)[v]=t.id,d(this,_)[_]()}))}}static track(t){var e=arguments,r=this;return l((function*(){var o=e.length>1&&void 0!==e[1]?e[1]:{};if(d(r,g)[g])throw new n.NotInitializedError;if(d(r,O)[O].has("preview"))return new i.default(!0,{received:!0});var s=yield fetch(b+"track/events",{headers:d(r,j)[j],method:"post",body:JSON.stringify(c(c({session:r.session,action:t},o),{},{url:o&&o.url||window.location.href}))});return new i.default(200===s.status,yield s.json())}))()}static on(e,r){if(t.default.invalid(e))throw new s.InvalidEvent(e);d(this,w)[w].addSubscriber(e,r)}static removeEventListener(e,r){if(t.default.invalid(e))throw new s.InvalidEvent(e);d(this,w)[w].removeSubscriber(e,r)}static get session(){if(d(this,g)[g])throw new n.NotInitializedError;return d(this,v)[v]}static get isInitialized(){return void 0!==d(this,v)[v]}}function A(){return(A=l((function*(){if(d(this,g)[g])throw new n.NotInitializedError;var t=b+"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(T,E,{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(T,_,{value:function(){if(d(this,g)[g])throw new n.NotInitializedError;d(this,w)[w].listeners&&d(this,w)[w].emit("session-set",d(this,v)[v]),document.cookie="hello_session=".concat(d(this,v)[v])}}),Object.defineProperty(T,j,{get:function(){if(d(this,g)[g])throw new n.NotInitializedError;return{Authorization:"Bearer ".concat(d(this,m)[m]),Accept:"application.json","Content-Type":"application/json"}},set:void 0}),Object.defineProperty(T,P,{value:function(){return A.apply(this,arguments)}}),Object.defineProperty(T,g,{get:function(){return void 0===d(this,m)[m]},set:void 0}),Object.defineProperty(T,v,{writable:!0,value:void 0}),Object.defineProperty(T,m,{writable:!0,value:void 0}),Object.defineProperty(T,w,{writable:!0,value:new e.default}),Object.defineProperty(T,O,{writable:!0,value:void 0})})()})();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hellotext/hellotext",
3
- "version": "1.3.1",
3
+ "version": "1.3.2",
4
4
  "description": "Hellotext JavaScript Client",
5
5
  "source": "src/index.js",
6
6
  "main": "lib/index.js",
package/webpack.config.js CHANGED
@@ -1,5 +1,5 @@
1
1
  module.exports = {
2
- mode: 'development',
2
+ mode: 'production',
3
3
  entry: ['whatwg-fetch', './lib/hellotext.js'],
4
4
  output: {
5
5
  filename: 'hellotext.js'