@hellotext/hellotext 1.3.3 → 1.3.4

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.
@@ -13,7 +13,7 @@ jobs:
13
13
  runs-on: ubuntu-latest
14
14
  strategy:
15
15
  matrix:
16
- node: ['14', '16']
16
+ node: ['16']
17
17
  name: Node ${{ matrix.node }}
18
18
  steps:
19
19
  - uses: actions/checkout@v2
package/README.md CHANGED
@@ -44,22 +44,15 @@ Hellotext.track("page.viewed");
44
44
 
45
45
  In the example above only the name of the action is required.
46
46
 
47
- The library takes care of handling the `url` parameter with the current URL automatically and is not required to specify it explicitly.
48
- If you want to provide another url, you can pass a `url` key in the params object when tracking an event.
47
+ ### Handling Responses
49
48
 
50
- ```javascript
51
- Hellotext.track("page.viewed", {
52
- url: "www.example.org"
53
- });
54
- ```
55
-
56
- The `track` method returns a Promise that can be `await`ed using the async/await syntax. Or using `.then` on the returned Promise
49
+ The `track` method returns a Promise that can be `await`ed using the async/await syntax. Or using `.then` on the returned Promise.
57
50
 
58
51
  ```javascript
59
52
  const response = await Hellotext.track("page.viewed");
60
53
  ```
61
54
 
62
- The return of the `Hellotext.track` method is an instance of a `Response` object that ships with the package. You can check the status of the response via methods, like
55
+ The return of the `Hellotext.track` method is an instance of a `Response` object that ships with the package. You can check the status of the response via methods, like:
63
56
 
64
57
  ```javascript
65
58
  if(response.failed) {
@@ -72,13 +65,28 @@ if(response.succeeded) {
72
65
  }
73
66
  ```
74
67
 
68
+ ### Parameters
69
+
75
70
  The parameters passed to the action must be a valid set of parameters as described in
76
71
  [Tracking Actions](https://www.hellotext.com/api#tracking).
77
72
 
73
+ #### URL Parameter
74
+
75
+ The library takes care of handling the `url` parameter with the current URL automatically and is not required to specify it explicitly.
76
+ If you want to provide another url, you can pass a `url` key in the params object when tracking an event.
77
+
78
+ ```javascript
79
+ Hellotext.track("page.viewed", {
80
+ url: "www.example.org"
81
+ });
82
+ ```
83
+
84
+ ### Errors
85
+
78
86
  Failing to provide valid set of parameters will result in an error object being returned, describing the parameters that did not satisfy the rules.
79
87
 
80
88
  ```javascript
81
- const response = await Hellotext.track("app.installed", { app_attributes: { name: "My App" }})
89
+ const response = await Hellotext.track("app.installed", { app_parameters: { name: "My App" }})
82
90
 
83
91
  console.log(response.data)
84
92
  ```
@@ -99,17 +107,19 @@ yields
99
107
 
100
108
  For a complete list of errors types. See [Error Types](https://www.hellotext.com/api#errors)
101
109
 
110
+ ### Associated objects
111
+
102
112
  Generally, most actions also require an associated object. These can be of type [`app`](https://www.hellotext.com/api#apps), [`coupon`](https://www.hellotext.com/api#coupons), [`form`](https://www.hellotext.com/api#forms), [`order`](https://www.hellotext.com/api#orders), [`product`](https://www.hellotext.com/api#products) and [`refund`](https://www.hellotext.com/api#refunds).
103
113
  Aside from [Custom Actions](https://www.hellotext.com/api#create_an_action), which don't require the trackable to be present.
104
114
 
105
115
 
106
- You can create the associated object directly by defining its attributes in a hash:
116
+ You can create the associated object directly by defining its parameters in a hash:
107
117
 
108
118
  ```javascript
109
119
  Hellotext.track("order.placed", {
110
120
  amount: 395.00,
111
121
  currency: "USD",
112
- order_attributes: {
122
+ order_parameters: {
113
123
  "amount": "395.00",
114
124
  "reference": "654321",
115
125
  }
@@ -131,24 +141,26 @@ Hellotext.track("product.purchased", {
131
141
 
132
142
  The following is a complete list of built-in actions and their required associated objects.
133
143
 
134
- | Action | Description | Required Parameter |
135
- |-----------------------| --- | --- |
136
- | **app.installed** | An app was installed. | `app` or [app_attributes](https://www.hellotext.com/api#app)
137
- | **app.removed** | An app was removed. | `app` or [app_attributes](https://www.hellotext.com/api#app)
138
- | **app.spent** | A customer spent on an app. | `app` or [app_attributes](https://www.hellotext.com/api#app)
139
- | **cart.added** | Added an item to the cart. | `product` or [product_attributes](https://www.hellotext.com/api#products)
140
- | **cart.removed** | Removed an item from the cart. | `product` or [product_attributes](https://www.hellotext.com/api#products)
141
- | **coupon.redeemed** | A coupon was redeem by a customer. | `coupon` or [coupon_attributes](https://www.hellotext.com/api#coupons)
142
- | **form.completed** | A form was completed by the customer. | `form` or [form_attributes](https://www.hellotext.com/api#forms)
143
- | **order.placed** | Order has been placed. | `order` or [order_attributes](https://www.hellotext.com/api#orders)
144
- | **order.confirmed** | Order has been confirmed by you. | `order` or [order_attributes](https://www.hellotext.com/api#orders)
145
- | **order.cancelled** | Order has been cancelled either by you or your customer. | `order` or [order_attributes](https://www.hellotext.com/api#orders)
146
- | **order.shipped** | Order has been shipped to your customer. | `order` or [order_attributes](https://www.hellotext.com/api#orders)
147
- | **page.viewed** | A page was viewed by a customer. | `url`
148
- | **product.purchased** | A product has been purchased. | `product` or [product_attributes](https://www.hellotext.com/api#products)
149
- | **product.viewed** | A product page has been viewed. | `product` or [product_attributes](https://www.hellotext.com/api#products)
150
- | **refund.requested** | A customer requested a refund. | `refund` or [refund_attributes](https://www.hellotext.com/api#refunds)
151
- | **refund.received** | A refund was issued by you to your customer. | `refund` or [refund_attributes](https://www.hellotext.com/api#refunds)
144
+ | Action | Description | Required Parameter |
145
+ |-----------------------|----------------------------------------------------------| --- |
146
+ | **app.installed** | An app was installed. | `app` or [app_parameters](https://www.hellotext.com/api#app)
147
+ | **app.removed** | An app was removed. | `app` or [app_parameters](https://www.hellotext.com/api#app)
148
+ | **app.spent** | A customer spent on an app. | `app` or [app_parameters](https://www.hellotext.com/api#app)
149
+ | **cart.abandoned** | A cart was abandoned. | `product` or [product_parameters](https://www.hellotext.com/api#products)
150
+ | **cart.added** | Added an item to the cart. | `product` or [product_parameters](https://www.hellotext.com/api#products)
151
+ | **cart.removed** | Removed an item from the cart. | `product` or [product_parameters](https://www.hellotext.com/api#products)
152
+ | **coupon.redeemed** | A coupon was redeem by a customer. | `coupon` or [coupon_parameters](https://www.hellotext.com/api#coupons)
153
+ | **form.completed** | A form was completed by the customer. | `form` or [form_parameters](https://www.hellotext.com/api#forms)
154
+ | **order.placed** | Order has been placed. | `order` or [order_parameters](https://www.hellotext.com/api#orders)
155
+ | **order.confirmed** | Order has been confirmed by you. | `order` or [order_parameters](https://www.hellotext.com/api#orders)
156
+ | **order.cancelled** | Order has been cancelled either by you or your customer. | `order` or [order_parameters](https://www.hellotext.com/api#orders)
157
+ | **order.shipped** | Order has been shipped to your customer. | `order` or [order_parameters](https://www.hellotext.com/api#orders)
158
+ | **order.delivered** | Order has been delivered to your customer. | `order` or [order_parameters](https://www.hellotext.com/api#orders)
159
+ | **page.viewed** | A page was viewed by a customer. | `url`
160
+ | **product.purchased** | A product has been purchased. | `product` or [product_parameters](https://www.hellotext.com/api#products)
161
+ | **product.viewed** | A product page has been viewed. | `product` or [product_parameters](https://www.hellotext.com/api#products)
162
+ | **refund.requested** | A customer requested a refund. | `refund` or [refund_parameters](https://www.hellotext.com/api#refunds)
163
+ | **refund.received** | A refund was issued by you to your customer. | `refund` or [refund_parameters](https://www.hellotext.com/api#refunds)
152
164
 
153
165
  You can also create your **[own defined actions](https://www.hellotext.com/api#actions)**.
154
166
 
package/dist/hellotext.js CHANGED
@@ -1 +1 @@
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="https://api.hellotext.com/v1/",m=v("session"),O=v("business"),P=v("eventEmitter"),g=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){if(d(this,O)[O]=e,d(this,g)[g]=new o.default(window.location.search),!d(this,g)[g].has("preview")){var t=d(this,g)[g].get("session")||d(this,S)[S];t&&"undefined"!==t&&"null"!==t?(d(this,m)[m]=t,d(this,T)[T]()):d(this,_)[_]().then((e=>{d(this,m)[m]=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,g)[g].has("preview"))return new n.default(!0,{received:!0});var r=yield fetch(w+"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,P)[P].addSubscriber(t,r)}},{key:"removeEventListener",value:function(t,r){if(e.default.invalid(t))throw new a.InvalidEvent(t);d(this,P)[P].removeSubscriber(t,r)}},{key:"session",get:function(){if(d(this,j)[j])throw new i.NotInitializedError;return d(this,m)[m]}},{key:"isInitialized",get:function(){return void 0!==d(this,m)[m]}}],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=w+"track/sessions";return this.mintingPromise=yield fetch(e,{method:"post",headers:{Authorization:"Bearer ".concat(d(this,O)[O])}}),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,P)[P].listeners&&d(this,P)[P].emit("session-set",d(this,m)[m]),document.cookie="hello_session=".concat(d(this,m)[m])}}),Object.defineProperty(A,E,{get:function(){if(d(this,j)[j])throw new i.NotInitializedError;return{Authorization:"Bearer ".concat(d(this,O)[O]),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,O)[O]},set:void 0}),Object.defineProperty(A,m,{writable:!0,value:void 0}),Object.defineProperty(A,O,{writable:!0,value:void 0}),Object.defineProperty(A,P,{writable:!0,value:new t.default}),Object.defineProperty(A,g,{writable:!0,value:void 0})})()})();
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})})()})();
package/lib/hellotext.js CHANGED
@@ -24,7 +24,6 @@ function _toPrimitive(input, hint) { if (typeof input !== "object" || input ===
24
24
  function _classPrivateFieldLooseBase(receiver, privateKey) { if (!Object.prototype.hasOwnProperty.call(receiver, privateKey)) { throw new TypeError("attempted to use private field on non-instance"); } return receiver; }
25
25
  var id = 0;
26
26
  function _classPrivateFieldLooseKey(name) { return "__private_" + id++ + "_" + name; }
27
- var apiUrl = 'https://api.hellotext.com/v1/';
28
27
  var _session = /*#__PURE__*/_classPrivateFieldLooseKey("session");
29
28
  var _business = /*#__PURE__*/_classPrivateFieldLooseKey("business");
30
29
  var _eventEmitter = /*#__PURE__*/_classPrivateFieldLooseKey("eventEmitter");
@@ -81,7 +80,7 @@ var Hellotext = /*#__PURE__*/function () {
81
80
  received: true
82
81
  });
83
82
  }
84
- var response = yield fetch(apiUrl + 'track/events', {
83
+ var response = yield fetch(this.__apiURL + 'track/events', {
85
84
  headers: _classPrivateFieldLooseBase(this, _headers)[_headers],
86
85
  method: 'post',
87
86
  body: JSON.stringify(_objectSpread(_objectSpread({
@@ -164,7 +163,7 @@ function _mintAnonymousSession3() {
164
163
  if (_classPrivateFieldLooseBase(this, _notInitialized)[_notInitialized]) {
165
164
  throw new _notInitializedError.NotInitializedError();
166
165
  }
167
- var trackingUrl = apiUrl + 'track/sessions';
166
+ var trackingUrl = this.__apiURL + 'track/sessions';
168
167
  this.mintingPromise = yield fetch(trackingUrl, {
169
168
  method: 'post',
170
169
  headers: {
@@ -216,6 +215,7 @@ Object.defineProperty(Hellotext, _notInitialized, {
216
215
  get: _get_notInitialized,
217
216
  set: void 0
218
217
  });
218
+ Hellotext.__apiURL = 'https://api.hellotext.com/v1/';
219
219
  Object.defineProperty(Hellotext, _session, {
220
220
  writable: true,
221
221
  value: void 0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hellotext/hellotext",
3
- "version": "1.3.3",
3
+ "version": "1.3.4",
4
4
  "description": "Hellotext JavaScript Client",
5
5
  "source": "src/index.js",
6
6
  "main": "lib/index.js",
package/src/hellotext.js CHANGED
@@ -6,13 +6,13 @@ import Query from "./query";
6
6
  import { NotInitializedError } from './errors/notInitializedError'
7
7
  import { InvalidEvent } from "./errors/invalidEvent"
8
8
 
9
- const apiUrl = 'https://api.hellotext.com/v1/'
10
-
11
9
  class Hellotext {
10
+ static __apiURL = 'https://api.hellotext.com/v1/'
11
+
12
12
  static #session
13
13
  static #business
14
14
  static #eventEmitter = new EventEmitter()
15
- static #query;
15
+ static #query
16
16
 
17
17
  /**
18
18
  * initialize the module.
@@ -53,7 +53,7 @@ class Hellotext {
53
53
  return new Response(true, { received: true })
54
54
  }
55
55
 
56
- const response = await fetch(apiUrl + 'track/events', {
56
+ const response = await fetch(this.__apiURL + 'track/events', {
57
57
  headers: this.#headers,
58
58
  method: 'post',
59
59
  body: JSON.stringify({
@@ -116,7 +116,7 @@ class Hellotext {
116
116
  static async #mintAnonymousSession() {
117
117
  if (this.#notInitialized) { throw new NotInitializedError() }
118
118
 
119
- const trackingUrl = apiUrl + 'track/sessions'
119
+ const trackingUrl = this.__apiURL + 'track/sessions'
120
120
 
121
121
  this.mintingPromise = await fetch(trackingUrl, {
122
122
  method: 'post',