@hellotext/hellotext 1.3.2 → 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.
- package/.babelrc +2 -1
- package/.github/workflows/ci.yml +1 -1
- package/README.md +43 -31
- package/dist/hellotext.js +1 -1
- package/lib/errors/invalidEvent.js +26 -5
- package/lib/errors/notInitializedError.js +26 -5
- package/lib/event.js +26 -10
- package/lib/eventEmitter.js +34 -20
- package/lib/hellotext.js +114 -92
- package/lib/query.js +26 -12
- package/lib/response.js +26 -12
- package/package.json +1 -1
- package/src/hellotext.js +5 -5
package/.babelrc
CHANGED
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
"loose": true
|
|
15
15
|
}],
|
|
16
16
|
["@babel/plugin-proposal-private-property-in-object", { "loose": true }],
|
|
17
|
-
["@babel/plugin-proposal-class-properties", { "loose": true }]
|
|
17
|
+
["@babel/plugin-proposal-class-properties", { "loose": true }],
|
|
18
|
+
"@babel/plugin-transform-classes"
|
|
18
19
|
]
|
|
19
20
|
}
|
package/.github/workflows/ci.yml
CHANGED
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
|
-
|
|
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
|
-
|
|
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", {
|
|
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
|
|
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
|
-
|
|
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
|
|
135
|
-
|
|
136
|
-
| **app.installed** | An app was installed.
|
|
137
|
-
| **app.removed** | An app was removed.
|
|
138
|
-
| **app.spent** | A customer spent on an app.
|
|
139
|
-
| **cart.
|
|
140
|
-
| **cart.
|
|
141
|
-
| **
|
|
142
|
-
| **
|
|
143
|
-
| **
|
|
144
|
-
| **order.
|
|
145
|
-
| **order.
|
|
146
|
-
| **order.
|
|
147
|
-
| **
|
|
148
|
-
| **
|
|
149
|
-
| **
|
|
150
|
-
| **
|
|
151
|
-
| **
|
|
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 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})})()})();
|
|
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})})()})();
|
|
@@ -4,10 +4,31 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.InvalidEvent = void 0;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
|
|
8
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
9
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
10
|
+
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
11
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
12
|
+
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
13
|
+
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
14
|
+
function _possibleConstructorReturn(self, call) { if (call && (typeof call === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
|
|
15
|
+
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
16
|
+
function _wrapNativeSuper(Class) { var _cache = typeof Map === "function" ? new Map() : undefined; _wrapNativeSuper = function _wrapNativeSuper(Class) { if (Class === null || !_isNativeFunction(Class)) return Class; if (typeof Class !== "function") { throw new TypeError("Super expression must either be null or a function"); } if (typeof _cache !== "undefined") { if (_cache.has(Class)) return _cache.get(Class); _cache.set(Class, Wrapper); } function Wrapper() { return _construct(Class, arguments, _getPrototypeOf(this).constructor); } Wrapper.prototype = Object.create(Class.prototype, { constructor: { value: Wrapper, enumerable: false, writable: true, configurable: true } }); return _setPrototypeOf(Wrapper, Class); }; return _wrapNativeSuper(Class); }
|
|
17
|
+
function _construct(Parent, args, Class) { if (_isNativeReflectConstruct()) { _construct = Reflect.construct.bind(); } else { _construct = function _construct(Parent, args, Class) { var a = [null]; a.push.apply(a, args); var Constructor = Function.bind.apply(Parent, a); var instance = new Constructor(); if (Class) _setPrototypeOf(instance, Class.prototype); return instance; }; } return _construct.apply(null, arguments); }
|
|
18
|
+
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
19
|
+
function _isNativeFunction(fn) { return Function.toString.call(fn).indexOf("[native code]") !== -1; }
|
|
20
|
+
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
21
|
+
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
22
|
+
var InvalidEvent = /*#__PURE__*/function (_Error) {
|
|
23
|
+
_inherits(InvalidEvent, _Error);
|
|
24
|
+
var _super = _createSuper(InvalidEvent);
|
|
25
|
+
function InvalidEvent(event) {
|
|
26
|
+
var _this;
|
|
27
|
+
_classCallCheck(this, InvalidEvent);
|
|
28
|
+
_this = _super.call(this, "".concat(event, " is not valid. Please provide a valid event name"));
|
|
29
|
+
_this.name = 'InvalidEvent';
|
|
30
|
+
return _this;
|
|
11
31
|
}
|
|
12
|
-
|
|
32
|
+
return _createClass(InvalidEvent);
|
|
33
|
+
}( /*#__PURE__*/_wrapNativeSuper(Error));
|
|
13
34
|
exports.InvalidEvent = InvalidEvent;
|
|
@@ -4,10 +4,31 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.NotInitializedError = void 0;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
|
|
8
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
9
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
10
|
+
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
11
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
12
|
+
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
13
|
+
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
14
|
+
function _possibleConstructorReturn(self, call) { if (call && (typeof call === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
|
|
15
|
+
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
16
|
+
function _wrapNativeSuper(Class) { var _cache = typeof Map === "function" ? new Map() : undefined; _wrapNativeSuper = function _wrapNativeSuper(Class) { if (Class === null || !_isNativeFunction(Class)) return Class; if (typeof Class !== "function") { throw new TypeError("Super expression must either be null or a function"); } if (typeof _cache !== "undefined") { if (_cache.has(Class)) return _cache.get(Class); _cache.set(Class, Wrapper); } function Wrapper() { return _construct(Class, arguments, _getPrototypeOf(this).constructor); } Wrapper.prototype = Object.create(Class.prototype, { constructor: { value: Wrapper, enumerable: false, writable: true, configurable: true } }); return _setPrototypeOf(Wrapper, Class); }; return _wrapNativeSuper(Class); }
|
|
17
|
+
function _construct(Parent, args, Class) { if (_isNativeReflectConstruct()) { _construct = Reflect.construct.bind(); } else { _construct = function _construct(Parent, args, Class) { var a = [null]; a.push.apply(a, args); var Constructor = Function.bind.apply(Parent, a); var instance = new Constructor(); if (Class) _setPrototypeOf(instance, Class.prototype); return instance; }; } return _construct.apply(null, arguments); }
|
|
18
|
+
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
19
|
+
function _isNativeFunction(fn) { return Function.toString.call(fn).indexOf("[native code]") !== -1; }
|
|
20
|
+
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
21
|
+
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
22
|
+
var NotInitializedError = /*#__PURE__*/function (_Error) {
|
|
23
|
+
_inherits(NotInitializedError, _Error);
|
|
24
|
+
var _super = _createSuper(NotInitializedError);
|
|
25
|
+
function NotInitializedError() {
|
|
26
|
+
var _this;
|
|
27
|
+
_classCallCheck(this, NotInitializedError);
|
|
28
|
+
_this = _super.call(this, 'You need to initialize before tracking events. Call Hellotext.initialize and pass your public business id');
|
|
29
|
+
_this.name = 'NotInitializedError';
|
|
30
|
+
return _this;
|
|
11
31
|
}
|
|
12
|
-
|
|
32
|
+
return _createClass(NotInitializedError);
|
|
33
|
+
}( /*#__PURE__*/_wrapNativeSuper(Error));
|
|
13
34
|
exports.NotInitializedError = NotInitializedError;
|
package/lib/event.js
CHANGED
|
@@ -4,16 +4,32 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
class
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
8
|
+
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
|
|
9
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
10
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
11
|
+
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
12
|
+
var Event = /*#__PURE__*/function () {
|
|
13
|
+
function Event() {
|
|
14
|
+
_classCallCheck(this, Event);
|
|
10
15
|
}
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
17
|
-
|
|
16
|
+
_createClass(Event, null, [{
|
|
17
|
+
key: "valid",
|
|
18
|
+
value: function valid(name) {
|
|
19
|
+
return Event.exists(name);
|
|
20
|
+
}
|
|
21
|
+
}, {
|
|
22
|
+
key: "invalid",
|
|
23
|
+
value: function invalid(name) {
|
|
24
|
+
return !this.valid(name);
|
|
25
|
+
}
|
|
26
|
+
}, {
|
|
27
|
+
key: "exists",
|
|
28
|
+
value: function exists(name) {
|
|
29
|
+
return this.events.find(eventName => eventName === name) !== undefined;
|
|
30
|
+
}
|
|
31
|
+
}]);
|
|
32
|
+
return Event;
|
|
33
|
+
}();
|
|
18
34
|
exports.default = Event;
|
|
19
35
|
Event.events = ["session-set"];
|
package/lib/eventEmitter.js
CHANGED
|
@@ -7,29 +7,43 @@ exports.default = void 0;
|
|
|
7
7
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
8
8
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
9
9
|
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
10
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
11
|
+
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
|
|
12
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
10
13
|
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
11
14
|
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
12
|
-
|
|
13
|
-
|
|
15
|
+
var EventEmitter = /*#__PURE__*/function () {
|
|
16
|
+
function EventEmitter() {
|
|
17
|
+
_classCallCheck(this, EventEmitter);
|
|
14
18
|
this.subscribers = {};
|
|
15
19
|
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
if (this.subscribers[eventName]) {
|
|
23
|
-
this.subscribers[eventName] = this.subscribers[eventName].filter(cb => cb !== callback);
|
|
20
|
+
_createClass(EventEmitter, [{
|
|
21
|
+
key: "addSubscriber",
|
|
22
|
+
value: function addSubscriber(eventName, callback) {
|
|
23
|
+
this.subscribers = _objectSpread(_objectSpread({}, this.subscribers), {}, {
|
|
24
|
+
[eventName]: this.subscribers[eventName] ? [...this.subscribers[eventName], callback] : [callback]
|
|
25
|
+
});
|
|
24
26
|
}
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
27
|
+
}, {
|
|
28
|
+
key: "removeSubscriber",
|
|
29
|
+
value: function removeSubscriber(eventName, callback) {
|
|
30
|
+
if (this.subscribers[eventName]) {
|
|
31
|
+
this.subscribers[eventName] = this.subscribers[eventName].filter(cb => cb !== callback);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}, {
|
|
35
|
+
key: "emit",
|
|
36
|
+
value: function emit(eventName, data) {
|
|
37
|
+
this.subscribers[eventName].forEach(subscriber => {
|
|
38
|
+
subscriber(data);
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
}, {
|
|
42
|
+
key: "listeners",
|
|
43
|
+
get: function get() {
|
|
44
|
+
return Object.keys(this.subscribers).length !== 0;
|
|
45
|
+
}
|
|
46
|
+
}]);
|
|
47
|
+
return EventEmitter;
|
|
48
|
+
}();
|
|
35
49
|
exports.default = EventEmitter;
|
package/lib/hellotext.js
CHANGED
|
@@ -14,14 +14,16 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
14
14
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
15
15
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
16
16
|
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
17
|
-
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
18
|
-
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
19
17
|
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
20
18
|
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
19
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
20
|
+
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
|
|
21
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
22
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
23
|
+
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
21
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; }
|
|
22
25
|
var id = 0;
|
|
23
26
|
function _classPrivateFieldLooseKey(name) { return "__private_" + id++ + "_" + name; }
|
|
24
|
-
var apiUrl = 'https://api.hellotext.com/v1/';
|
|
25
27
|
var _session = /*#__PURE__*/_classPrivateFieldLooseKey("session");
|
|
26
28
|
var _business = /*#__PURE__*/_classPrivateFieldLooseKey("business");
|
|
27
29
|
var _eventEmitter = /*#__PURE__*/_classPrivateFieldLooseKey("eventEmitter");
|
|
@@ -31,106 +33,125 @@ var _mintAnonymousSession = /*#__PURE__*/_classPrivateFieldLooseKey("mintAnonymo
|
|
|
31
33
|
var _headers = /*#__PURE__*/_classPrivateFieldLooseKey("headers");
|
|
32
34
|
var _setSessionCookie = /*#__PURE__*/_classPrivateFieldLooseKey("setSessionCookie");
|
|
33
35
|
var _cookie = /*#__PURE__*/_classPrivateFieldLooseKey("cookie");
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
_classPrivateFieldLooseBase(this,
|
|
47
|
-
|
|
48
|
-
_classPrivateFieldLooseBase(this,
|
|
49
|
-
|
|
36
|
+
var Hellotext = /*#__PURE__*/function () {
|
|
37
|
+
function Hellotext() {
|
|
38
|
+
_classCallCheck(this, Hellotext);
|
|
39
|
+
}
|
|
40
|
+
_createClass(Hellotext, null, [{
|
|
41
|
+
key: "initialize",
|
|
42
|
+
value:
|
|
43
|
+
/**
|
|
44
|
+
* initialize the module.
|
|
45
|
+
* @param business public business id
|
|
46
|
+
*/
|
|
47
|
+
function initialize(business) {
|
|
48
|
+
_classPrivateFieldLooseBase(this, _business)[_business] = business;
|
|
49
|
+
_classPrivateFieldLooseBase(this, _query)[_query] = new _query2.default(window.location.search);
|
|
50
|
+
if (_classPrivateFieldLooseBase(this, _query)[_query].has("preview")) return;
|
|
51
|
+
var session = _classPrivateFieldLooseBase(this, _query)[_query].get("session") || _classPrivateFieldLooseBase(this, _cookie)[_cookie];
|
|
52
|
+
if (session && session !== "undefined" && session !== "null") {
|
|
53
|
+
_classPrivateFieldLooseBase(this, _session)[_session] = session;
|
|
50
54
|
_classPrivateFieldLooseBase(this, _setSessionCookie)[_setSessionCookie]();
|
|
51
|
-
}
|
|
55
|
+
} else {
|
|
56
|
+
_classPrivateFieldLooseBase(this, _mintAnonymousSession)[_mintAnonymousSession]().then(response => {
|
|
57
|
+
_classPrivateFieldLooseBase(this, _session)[_session] = response.id;
|
|
58
|
+
_classPrivateFieldLooseBase(this, _setSessionCookie)[_setSessionCookie]();
|
|
59
|
+
});
|
|
60
|
+
}
|
|
52
61
|
}
|
|
53
|
-
}
|
|
54
62
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
63
|
+
/**
|
|
64
|
+
* Tracks an action that has happened on the page
|
|
65
|
+
*
|
|
66
|
+
* @param { String } action a valid action name
|
|
67
|
+
* @param { Object } params
|
|
68
|
+
* @returns {Promise<Response>}
|
|
69
|
+
*/
|
|
70
|
+
}, {
|
|
71
|
+
key: "track",
|
|
72
|
+
value: function () {
|
|
73
|
+
var _track = _asyncToGenerator(function* (action) {
|
|
74
|
+
var params = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
75
|
+
if (_classPrivateFieldLooseBase(this, _notInitialized)[_notInitialized]) {
|
|
76
|
+
throw new _notInitializedError.NotInitializedError();
|
|
77
|
+
}
|
|
78
|
+
if (_classPrivateFieldLooseBase(this, _query)[_query].has("preview")) {
|
|
79
|
+
return new _response.default(true, {
|
|
80
|
+
received: true
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
var response = yield fetch(this.__apiURL + 'track/events', {
|
|
84
|
+
headers: _classPrivateFieldLooseBase(this, _headers)[_headers],
|
|
85
|
+
method: 'post',
|
|
86
|
+
body: JSON.stringify(_objectSpread(_objectSpread({
|
|
87
|
+
session: this.session,
|
|
88
|
+
action
|
|
89
|
+
}, params), {}, {
|
|
90
|
+
url: params && params.url || window.location.href
|
|
91
|
+
}))
|
|
73
92
|
});
|
|
74
|
-
|
|
75
|
-
var response = yield fetch(apiUrl + 'track/events', {
|
|
76
|
-
headers: _classPrivateFieldLooseBase(_this, _headers)[_headers],
|
|
77
|
-
method: 'post',
|
|
78
|
-
body: JSON.stringify(_objectSpread(_objectSpread({
|
|
79
|
-
session: _this.session,
|
|
80
|
-
action
|
|
81
|
-
}, params), {}, {
|
|
82
|
-
url: params && params.url || window.location.href
|
|
83
|
-
}))
|
|
93
|
+
return new _response.default(response.status === 200, yield response.json());
|
|
84
94
|
});
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
95
|
+
function track(_x) {
|
|
96
|
+
return _track.apply(this, arguments);
|
|
97
|
+
}
|
|
98
|
+
return track;
|
|
99
|
+
}()
|
|
100
|
+
/**
|
|
101
|
+
* Registers an event listener
|
|
102
|
+
* @param event the name of the event to listen to
|
|
103
|
+
* @param callback the callback. This method will be called with the payload
|
|
104
|
+
*/
|
|
105
|
+
}, {
|
|
106
|
+
key: "on",
|
|
107
|
+
value: function on(event, callback) {
|
|
108
|
+
if (_event.default.invalid(event)) {
|
|
109
|
+
throw new _invalidEvent.InvalidEvent(event);
|
|
110
|
+
}
|
|
111
|
+
_classPrivateFieldLooseBase(this, _eventEmitter)[_eventEmitter].addSubscriber(event, callback);
|
|
97
112
|
}
|
|
98
|
-
_classPrivateFieldLooseBase(this, _eventEmitter)[_eventEmitter].addSubscriber(event, callback);
|
|
99
|
-
}
|
|
100
113
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
114
|
+
/**
|
|
115
|
+
* Removes an event listener
|
|
116
|
+
* @param event the name of the event to remove
|
|
117
|
+
* @param callback the callback to remove
|
|
118
|
+
*/
|
|
119
|
+
}, {
|
|
120
|
+
key: "removeEventListener",
|
|
121
|
+
value: function removeEventListener(event, callback) {
|
|
122
|
+
if (_event.default.invalid(event)) {
|
|
123
|
+
throw new _invalidEvent.InvalidEvent(event);
|
|
124
|
+
}
|
|
125
|
+
_classPrivateFieldLooseBase(this, _eventEmitter)[_eventEmitter].removeSubscriber(event, callback);
|
|
109
126
|
}
|
|
110
|
-
_classPrivateFieldLooseBase(this, _eventEmitter)[_eventEmitter].removeSubscriber(event, callback);
|
|
111
|
-
}
|
|
112
127
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
128
|
+
/**
|
|
129
|
+
*
|
|
130
|
+
* @returns {String}
|
|
131
|
+
*/
|
|
132
|
+
}, {
|
|
133
|
+
key: "session",
|
|
134
|
+
get: function get() {
|
|
135
|
+
if (_classPrivateFieldLooseBase(this, _notInitialized)[_notInitialized]) {
|
|
136
|
+
throw new _notInitializedError.NotInitializedError();
|
|
137
|
+
}
|
|
138
|
+
return _classPrivateFieldLooseBase(this, _session)[_session];
|
|
120
139
|
}
|
|
121
|
-
return _classPrivateFieldLooseBase(this, _session)[_session];
|
|
122
|
-
}
|
|
123
140
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
141
|
+
/**
|
|
142
|
+
* Determines if the session is set or not
|
|
143
|
+
* @returns {boolean}
|
|
144
|
+
*/
|
|
145
|
+
}, {
|
|
146
|
+
key: "isInitialized",
|
|
147
|
+
get: function get() {
|
|
148
|
+
return _classPrivateFieldLooseBase(this, _session)[_session] !== undefined;
|
|
149
|
+
}
|
|
131
150
|
|
|
132
|
-
|
|
133
|
-
}
|
|
151
|
+
// private
|
|
152
|
+
}]);
|
|
153
|
+
return Hellotext;
|
|
154
|
+
}();
|
|
134
155
|
function _get_notInitialized() {
|
|
135
156
|
return _classPrivateFieldLooseBase(this, _business)[_business] === undefined;
|
|
136
157
|
}
|
|
@@ -142,7 +163,7 @@ function _mintAnonymousSession3() {
|
|
|
142
163
|
if (_classPrivateFieldLooseBase(this, _notInitialized)[_notInitialized]) {
|
|
143
164
|
throw new _notInitializedError.NotInitializedError();
|
|
144
165
|
}
|
|
145
|
-
var trackingUrl =
|
|
166
|
+
var trackingUrl = this.__apiURL + 'track/sessions';
|
|
146
167
|
this.mintingPromise = yield fetch(trackingUrl, {
|
|
147
168
|
method: 'post',
|
|
148
169
|
headers: {
|
|
@@ -194,6 +215,7 @@ Object.defineProperty(Hellotext, _notInitialized, {
|
|
|
194
215
|
get: _get_notInitialized,
|
|
195
216
|
set: void 0
|
|
196
217
|
});
|
|
218
|
+
Hellotext.__apiURL = 'https://api.hellotext.com/v1/';
|
|
197
219
|
Object.defineProperty(Hellotext, _session, {
|
|
198
220
|
writable: true,
|
|
199
221
|
value: void 0
|
package/lib/query.js
CHANGED
|
@@ -4,18 +4,32 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
class
|
|
8
|
-
|
|
7
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
8
|
+
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
|
|
9
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
10
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
11
|
+
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
12
|
+
var Query = /*#__PURE__*/function () {
|
|
13
|
+
function Query(urlQueries) {
|
|
14
|
+
_classCallCheck(this, Query);
|
|
9
15
|
this.urlSearchParams = new URLSearchParams(urlQueries);
|
|
10
16
|
}
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
}
|
|
17
|
+
_createClass(Query, [{
|
|
18
|
+
key: "get",
|
|
19
|
+
value: function get(param) {
|
|
20
|
+
return this.urlSearchParams.get(this.toHellotextParam(param));
|
|
21
|
+
}
|
|
22
|
+
}, {
|
|
23
|
+
key: "has",
|
|
24
|
+
value: function has(param) {
|
|
25
|
+
return this.urlSearchParams.has(this.toHellotextParam(param));
|
|
26
|
+
}
|
|
27
|
+
}, {
|
|
28
|
+
key: "toHellotextParam",
|
|
29
|
+
value: function toHellotextParam(param) {
|
|
30
|
+
return "hello_".concat(param);
|
|
31
|
+
}
|
|
32
|
+
}]);
|
|
33
|
+
return Query;
|
|
34
|
+
}();
|
|
21
35
|
exports.default = Query;
|
package/lib/response.js
CHANGED
|
@@ -4,13 +4,19 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
8
|
+
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
|
|
9
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
10
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
11
|
+
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
7
12
|
function _classPrivateFieldLooseBase(receiver, privateKey) { if (!Object.prototype.hasOwnProperty.call(receiver, privateKey)) { throw new TypeError("attempted to use private field on non-instance"); } return receiver; }
|
|
8
13
|
var id = 0;
|
|
9
14
|
function _classPrivateFieldLooseKey(name) { return "__private_" + id++ + "_" + name; }
|
|
10
15
|
var _success = /*#__PURE__*/_classPrivateFieldLooseKey("success");
|
|
11
16
|
var _response = /*#__PURE__*/_classPrivateFieldLooseKey("response");
|
|
12
|
-
|
|
13
|
-
|
|
17
|
+
var Response = /*#__PURE__*/function () {
|
|
18
|
+
function Response(success, response) {
|
|
19
|
+
_classCallCheck(this, Response);
|
|
14
20
|
Object.defineProperty(this, _success, {
|
|
15
21
|
writable: true,
|
|
16
22
|
value: void 0
|
|
@@ -22,14 +28,22 @@ class Response {
|
|
|
22
28
|
_classPrivateFieldLooseBase(this, _success)[_success] = success;
|
|
23
29
|
_classPrivateFieldLooseBase(this, _response)[_response] = response;
|
|
24
30
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
}
|
|
31
|
+
_createClass(Response, [{
|
|
32
|
+
key: "data",
|
|
33
|
+
get: function get() {
|
|
34
|
+
return _classPrivateFieldLooseBase(this, _response)[_response];
|
|
35
|
+
}
|
|
36
|
+
}, {
|
|
37
|
+
key: "failed",
|
|
38
|
+
get: function get() {
|
|
39
|
+
return _classPrivateFieldLooseBase(this, _success)[_success] === false;
|
|
40
|
+
}
|
|
41
|
+
}, {
|
|
42
|
+
key: "succeeded",
|
|
43
|
+
get: function get() {
|
|
44
|
+
return _classPrivateFieldLooseBase(this, _success)[_success] === true;
|
|
45
|
+
}
|
|
46
|
+
}]);
|
|
47
|
+
return Response;
|
|
48
|
+
}();
|
|
35
49
|
exports.default = Response;
|
package/package.json
CHANGED
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(
|
|
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 =
|
|
119
|
+
const trackingUrl = this.__apiURL + 'track/sessions'
|
|
120
120
|
|
|
121
121
|
this.mintingPromise = await fetch(trackingUrl, {
|
|
122
122
|
method: 'post',
|