@hellotext/hellotext 1.4.1 → 1.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.babelrc +6 -3
- package/.github/workflows/ci.yml +1 -1
- package/.prettierignore +2 -0
- package/README.md +30 -170
- package/__tests__/api/sessions_test.js +12 -0
- package/__tests__/builders/input_builder_test.js +117 -0
- package/__tests__/{event_emitter_test.js → core/event_test.js} +26 -6
- package/__tests__/hellotext_test.js +12 -0
- package/__tests__/models/business_test.js +26 -0
- package/__tests__/models/cookies_test.js +25 -0
- package/__tests__/models/form_collection_test.js +100 -0
- package/__tests__/models/form_test.js +29 -0
- package/__tests__/models/query_test.js +97 -0
- package/dist/hellotext.js +1 -1
- package/docs/forms.md +127 -0
- package/docs/tracking.md +155 -0
- package/lib/api/businesses.js +45 -0
- package/lib/api/events.js +54 -0
- package/lib/api/forms.js +65 -0
- package/lib/api/index.js +51 -0
- package/lib/api/response.js +57 -0
- package/lib/api/sessions.js +46 -0
- package/lib/api/submissions.js +61 -0
- package/lib/api.js +73 -0
- package/lib/builders/inputBuilder.js +97 -0
- package/lib/builders/input_builder.js +61 -0
- package/lib/builders/logo_builder.js +38 -0
- package/lib/builders/otp_builder.js +39 -0
- package/lib/controllers/form_controller.js +139 -0
- package/lib/controllers/otp_controller.js +114 -0
- package/lib/core/configuration.js +37 -0
- package/lib/core/event.js +73 -0
- package/lib/core/index.js +20 -0
- package/lib/errors/index.js +19 -0
- package/lib/errors/invalid_event.js +34 -0
- package/lib/errors/not_initialized_error.js +34 -0
- package/lib/event.js +159 -32
- package/lib/eventEmitter.js +139 -46
- package/lib/forms.js +133 -0
- package/lib/hellotext.js +53 -105
- package/lib/index.js +7 -0
- package/lib/locales/en.js +20 -0
- package/lib/locales/es.js +20 -0
- package/lib/locales/index.js +14 -0
- package/lib/models/business.js +57 -0
- package/lib/models/configuration.js +66 -0
- package/lib/models/cookies.js +34 -0
- package/lib/models/form.js +148 -0
- package/lib/models/form_collection.js +96 -0
- package/lib/models/index.js +40 -0
- package/lib/models/query.js +51 -0
- package/lib/models/step.js +45 -0
- package/lib/query.js +65 -32
- package/lib/response.js +82 -42
- package/package.json +6 -3
- package/src/api/businesses.js +18 -0
- package/src/api/events.js +24 -0
- package/src/api/forms.js +30 -0
- package/src/api/index.js +24 -0
- package/src/{response.js → api/response.js} +9 -4
- package/src/api/sessions.js +23 -0
- package/src/api/submissions.js +30 -0
- package/src/builders/input_builder.js +55 -0
- package/src/builders/logo_builder.js +25 -0
- package/src/builders/otp_builder.js +42 -0
- package/src/controllers/form_controller.js +105 -0
- package/src/controllers/otp_controller.js +77 -0
- package/src/core/configuration.js +16 -0
- package/src/core/event.js +54 -0
- package/src/core/index.js +2 -0
- package/src/errors/index.js +2 -0
- package/src/hellotext.js +50 -72
- package/src/index.js +10 -0
- package/src/locales/en.js +13 -0
- package/src/locales/es.js +13 -0
- package/src/locales/index.js +7 -0
- package/src/models/business.js +41 -0
- package/src/models/cookies.js +16 -0
- package/src/models/form.js +133 -0
- package/src/models/form_collection.js +81 -0
- package/src/models/index.js +5 -0
- package/src/models/query.js +33 -0
- package/styles/index.css +32 -0
- package/webpack.config.js +15 -9
- package/__tests__/event_test.js +0 -21
- package/__tests__/query_test.js +0 -13
- package/src/event.js +0 -15
- package/src/eventEmitter.js +0 -28
- package/src/query.js +0 -21
- /package/src/errors/{invalidEvent.js → invalid_event.js} +0 -0
- /package/src/errors/{notInitializedError.js → not_initialized_error.js} +0 -0
package/docs/tracking.md
ADDED
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
## Tracking Events
|
|
2
|
+
|
|
3
|
+
Track subscriber events as they happen on your website and let Hellotext report them back to your business.
|
|
4
|
+
|
|
5
|
+
Tracking events is straightforward and perhaps the simplest example is tracking a page view:
|
|
6
|
+
|
|
7
|
+
```javascript
|
|
8
|
+
Hellotext.track('page.viewed')
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
In the example above only the name of the action is required.
|
|
12
|
+
|
|
13
|
+
### Handling Responses
|
|
14
|
+
|
|
15
|
+
The `track` method returns a Promise that can be `await`ed using the async/await syntax. Or using `.then` on the returned Promise.
|
|
16
|
+
|
|
17
|
+
```javascript
|
|
18
|
+
const response = await Hellotext.track('page.viewed')
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
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:
|
|
22
|
+
|
|
23
|
+
```javascript
|
|
24
|
+
if (response.failed) {
|
|
25
|
+
console.log('failed because', response.data)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if (response.succeeded) {
|
|
29
|
+
console.log('success')
|
|
30
|
+
console.log(response.data) // { status: "received" }
|
|
31
|
+
}
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
### Parameters
|
|
35
|
+
|
|
36
|
+
The parameters passed to the action must be a valid set of parameters as described in
|
|
37
|
+
[Tracking Actions](https://www.hellotext.com/api#tracking).
|
|
38
|
+
|
|
39
|
+
#### URL Parameter
|
|
40
|
+
|
|
41
|
+
The library takes care of handling the `url` parameter with the current URL automatically and is not required to specify it explicitly.
|
|
42
|
+
If you want to provide another url, you can pass a `url` key in the params object when tracking an event.
|
|
43
|
+
|
|
44
|
+
```javascript
|
|
45
|
+
Hellotext.track('page.viewed', {
|
|
46
|
+
url: 'www.example.org',
|
|
47
|
+
})
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
### Errors
|
|
51
|
+
|
|
52
|
+
Failing to provide valid set of parameters will result in an error object being returned, describing the parameters that did not satisfy the rules.
|
|
53
|
+
|
|
54
|
+
```javascript
|
|
55
|
+
const response = await Hellotext.track('app.installed', { app_parameters: { name: 'My App' } })
|
|
56
|
+
|
|
57
|
+
console.log(response.data)
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
yields
|
|
61
|
+
|
|
62
|
+
```javascript
|
|
63
|
+
{
|
|
64
|
+
errors: [
|
|
65
|
+
{
|
|
66
|
+
type: 'parameter_not_unique',
|
|
67
|
+
parameter: 'name',
|
|
68
|
+
description:
|
|
69
|
+
'The value must be unique and it is already present in another object of the same type.',
|
|
70
|
+
},
|
|
71
|
+
]
|
|
72
|
+
}
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
For a complete list of errors types. See [Error Types](https://www.hellotext.com/api#errors)
|
|
76
|
+
|
|
77
|
+
### Associated objects
|
|
78
|
+
|
|
79
|
+
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).
|
|
80
|
+
Aside from [Custom Actions](https://www.hellotext.com/api#create_an_action), which don't require the trackable to be present.
|
|
81
|
+
|
|
82
|
+
You can create the associated object directly by defining its parameters in a hash:
|
|
83
|
+
|
|
84
|
+
```javascript
|
|
85
|
+
Hellotext.track('order.placed', {
|
|
86
|
+
amount: 395.0,
|
|
87
|
+
currency: 'USD',
|
|
88
|
+
order_parameters: {
|
|
89
|
+
amount: '395.00',
|
|
90
|
+
reference: '654321',
|
|
91
|
+
},
|
|
92
|
+
})
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
If you want to reuse existing objects, you must pass the identifier of an existing associated object. For example, to track a product purchase the identifier of a previously created product object as the `product`.
|
|
96
|
+
For more information about identifiers, view the [Tracking API](https://www.hellotext.com/api#tracking)
|
|
97
|
+
|
|
98
|
+
```javascript
|
|
99
|
+
Hellotext.track('product.purchased', {
|
|
100
|
+
amount: 395.0,
|
|
101
|
+
currency: 'USD',
|
|
102
|
+
product: 'erA2RAXE',
|
|
103
|
+
})
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
## List of actions
|
|
107
|
+
|
|
108
|
+
The following is a complete list of built-in actions and their required associated objects.
|
|
109
|
+
|
|
110
|
+
| Action | Description | Required Parameter |
|
|
111
|
+
| --------------------- | -------------------------------------------------------- | ------------------------------------------------------------------------- |
|
|
112
|
+
| **app.installed** | An app was installed. | `app` or [app_parameters](https://www.hellotext.com/api#app) |
|
|
113
|
+
| **app.removed** | An app was removed. | `app` or [app_parameters](https://www.hellotext.com/api#app) |
|
|
114
|
+
| **app.spent** | A customer spent on an app. | `app` or [app_parameters](https://www.hellotext.com/api#app) |
|
|
115
|
+
| **cart.abandoned** | A cart was abandoned. | `product` or [product_parameters](https://www.hellotext.com/api#products) |
|
|
116
|
+
| **cart.added** | Added an item to the cart. | `product` or [product_parameters](https://www.hellotext.com/api#products) |
|
|
117
|
+
| **cart.removed** | Removed an item from the cart. | `product` or [product_parameters](https://www.hellotext.com/api#products) |
|
|
118
|
+
| **coupon.redeemed** | A coupon was redeem by a customer. | `coupon` or [coupon_parameters](https://www.hellotext.com/api#coupons) |
|
|
119
|
+
| **form.completed** | A form was completed by the customer. | `form` or [form_parameters](https://www.hellotext.com/api#forms) |
|
|
120
|
+
| **order.placed** | Order has been placed. | `order` or [order_parameters](https://www.hellotext.com/api#orders) |
|
|
121
|
+
| **order.confirmed** | Order has been confirmed by you. | `order` or [order_parameters](https://www.hellotext.com/api#orders) |
|
|
122
|
+
| **order.cancelled** | Order has been cancelled either by you or your customer. | `order` or [order_parameters](https://www.hellotext.com/api#orders) |
|
|
123
|
+
| **order.shipped** | Order has been shipped to your customer. | `order` or [order_parameters](https://www.hellotext.com/api#orders) |
|
|
124
|
+
| **order.delivered** | Order has been delivered to your customer. | `order` or [order_parameters](https://www.hellotext.com/api#orders) |
|
|
125
|
+
| **page.viewed** | A page was viewed by a customer. | `url` |
|
|
126
|
+
| **product.purchased** | A product has been purchased. | `product` or [product_parameters](https://www.hellotext.com/api#products) |
|
|
127
|
+
| **product.viewed** | A product page has been viewed. | `product` or [product_parameters](https://www.hellotext.com/api#products) |
|
|
128
|
+
| **refund.requested** | A customer requested a refund. | `refund` or [refund_parameters](https://www.hellotext.com/api#refunds) |
|
|
129
|
+
| **refund.received** | A refund was issued by you to your customer. | `refund` or [refund_parameters](https://www.hellotext.com/api#refunds) |
|
|
130
|
+
|
|
131
|
+
You can also create your **[own defined actions](https://www.hellotext.com/api#actions)**.
|
|
132
|
+
|
|
133
|
+
## Additional Properties
|
|
134
|
+
|
|
135
|
+
You can include additional attributes to the tracked event, additional properties must be included inside the `metadata` object:
|
|
136
|
+
|
|
137
|
+
```javascript
|
|
138
|
+
Hellotext.track('product.purchased', {
|
|
139
|
+
amount: 0.2,
|
|
140
|
+
currency: 'USD',
|
|
141
|
+
metadata: {
|
|
142
|
+
myProperty: 'custom',
|
|
143
|
+
},
|
|
144
|
+
tracked_at: 1665684173,
|
|
145
|
+
})
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
### List of additional attributes
|
|
149
|
+
|
|
150
|
+
| Property | Description | Type | Default |
|
|
151
|
+
| -------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------- | ------- |
|
|
152
|
+
| **amount** | Monetary amount that represents the revenue associated to this tracked event. | float | `0` |
|
|
153
|
+
| **currency** | Currency for the `amount` given in ISO 4217 format. | currency | `USD` |
|
|
154
|
+
| **metadata** | Set of key-value pairs that you can attach to an event. This can be useful for storing additional information about the object in a structured format. | hash | `{}` |
|
|
155
|
+
| **tracked_at** | Original date when the event happened. This is useful if you want to record an event that happened in the past. If no value is provided its value will be the same from `created_at`. | epoch | `null` |
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _core = require("../core");
|
|
8
|
+
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); } }
|
|
9
|
+
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); }); }; }
|
|
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; }
|
|
13
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
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); }
|
|
15
|
+
var _default = /*#__PURE__*/function () {
|
|
16
|
+
function _default() {
|
|
17
|
+
_classCallCheck(this, _default);
|
|
18
|
+
}
|
|
19
|
+
_createClass(_default, null, [{
|
|
20
|
+
key: "endpoint",
|
|
21
|
+
get: function get() {
|
|
22
|
+
return _core.Configuration.endpoint('public/businesses');
|
|
23
|
+
}
|
|
24
|
+
}, {
|
|
25
|
+
key: "get",
|
|
26
|
+
value: function () {
|
|
27
|
+
var _get = _asyncToGenerator(function* (id) {
|
|
28
|
+
return fetch("".concat(this.endpoint, "/").concat(id), {
|
|
29
|
+
method: 'GET',
|
|
30
|
+
headers: {
|
|
31
|
+
Authorization: "Bearer ".concat(id),
|
|
32
|
+
Accept: 'application.json',
|
|
33
|
+
'Content-Type': 'application/json'
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
function get(_x) {
|
|
38
|
+
return _get.apply(this, arguments);
|
|
39
|
+
}
|
|
40
|
+
return get;
|
|
41
|
+
}()
|
|
42
|
+
}]);
|
|
43
|
+
return _default;
|
|
44
|
+
}();
|
|
45
|
+
exports.default = _default;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _core = require("../core");
|
|
8
|
+
var _models = require("../models");
|
|
9
|
+
var _response = require("./response");
|
|
10
|
+
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); } }
|
|
11
|
+
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); }); }; }
|
|
12
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
13
|
+
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); } }
|
|
14
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
15
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
16
|
+
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); }
|
|
17
|
+
var EventsAPI = /*#__PURE__*/function () {
|
|
18
|
+
function EventsAPI() {
|
|
19
|
+
_classCallCheck(this, EventsAPI);
|
|
20
|
+
}
|
|
21
|
+
_createClass(EventsAPI, null, [{
|
|
22
|
+
key: "endpoint",
|
|
23
|
+
get: function get() {
|
|
24
|
+
return _core.Configuration.endpoint('track/events');
|
|
25
|
+
}
|
|
26
|
+
}, {
|
|
27
|
+
key: "create",
|
|
28
|
+
value: function () {
|
|
29
|
+
var _create = _asyncToGenerator(function* (_ref) {
|
|
30
|
+
var {
|
|
31
|
+
headers,
|
|
32
|
+
body
|
|
33
|
+
} = _ref;
|
|
34
|
+
if (_models.Query.inPreviewMode) {
|
|
35
|
+
return new _response.Response(true, {
|
|
36
|
+
received: true
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
var response = yield fetch(this.endpoint, {
|
|
40
|
+
method: 'POST',
|
|
41
|
+
headers,
|
|
42
|
+
body: JSON.stringify(body)
|
|
43
|
+
});
|
|
44
|
+
return new _response.Response(response.status === 200, yield response.json());
|
|
45
|
+
});
|
|
46
|
+
function create(_x) {
|
|
47
|
+
return _create.apply(this, arguments);
|
|
48
|
+
}
|
|
49
|
+
return create;
|
|
50
|
+
}()
|
|
51
|
+
}]);
|
|
52
|
+
return EventsAPI;
|
|
53
|
+
}();
|
|
54
|
+
exports.default = EventsAPI;
|
package/lib/api/forms.js
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _hellotext = _interopRequireDefault(require("../hellotext"));
|
|
8
|
+
var _core = require("../core");
|
|
9
|
+
var _response = require("./response");
|
|
10
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
+
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; }
|
|
12
|
+
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; }
|
|
13
|
+
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; }
|
|
14
|
+
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); } }
|
|
15
|
+
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); }); }; }
|
|
16
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
17
|
+
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); } }
|
|
18
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
19
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
20
|
+
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
|
+
var FormsAPI = /*#__PURE__*/function () {
|
|
22
|
+
function FormsAPI() {
|
|
23
|
+
_classCallCheck(this, FormsAPI);
|
|
24
|
+
}
|
|
25
|
+
_createClass(FormsAPI, null, [{
|
|
26
|
+
key: "endpoint",
|
|
27
|
+
get: function get() {
|
|
28
|
+
return _core.Configuration.endpoint('public/forms');
|
|
29
|
+
}
|
|
30
|
+
}, {
|
|
31
|
+
key: "get",
|
|
32
|
+
value: function () {
|
|
33
|
+
var _get = _asyncToGenerator(function* (id) {
|
|
34
|
+
return fetch("".concat(this.endpoint, "/").concat(id), {
|
|
35
|
+
method: 'GET',
|
|
36
|
+
headers: _hellotext.default.headers
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
function get(_x) {
|
|
40
|
+
return _get.apply(this, arguments);
|
|
41
|
+
}
|
|
42
|
+
return get;
|
|
43
|
+
}()
|
|
44
|
+
}, {
|
|
45
|
+
key: "submit",
|
|
46
|
+
value: function () {
|
|
47
|
+
var _submit = _asyncToGenerator(function* (id, data) {
|
|
48
|
+
var response = yield fetch("".concat(this.endpoint, "/").concat(id, "/submissions"), {
|
|
49
|
+
method: 'POST',
|
|
50
|
+
headers: _hellotext.default.headers,
|
|
51
|
+
body: JSON.stringify(_objectSpread({
|
|
52
|
+
session: _hellotext.default.session
|
|
53
|
+
}, data))
|
|
54
|
+
});
|
|
55
|
+
return new _response.Response(response.ok, response);
|
|
56
|
+
});
|
|
57
|
+
function submit(_x2, _x3) {
|
|
58
|
+
return _submit.apply(this, arguments);
|
|
59
|
+
}
|
|
60
|
+
return submit;
|
|
61
|
+
}()
|
|
62
|
+
}]);
|
|
63
|
+
return FormsAPI;
|
|
64
|
+
}();
|
|
65
|
+
exports.default = FormsAPI;
|
package/lib/api/index.js
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "Response", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function get() {
|
|
9
|
+
return _response.Response;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
exports.default = void 0;
|
|
13
|
+
var _sessions = _interopRequireDefault(require("./sessions"));
|
|
14
|
+
var _businesses = _interopRequireDefault(require("./businesses"));
|
|
15
|
+
var _events = _interopRequireDefault(require("./events"));
|
|
16
|
+
var _forms = _interopRequireDefault(require("./forms"));
|
|
17
|
+
var _response = require("./response");
|
|
18
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
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); }
|
|
24
|
+
var API = /*#__PURE__*/function () {
|
|
25
|
+
function API() {
|
|
26
|
+
_classCallCheck(this, API);
|
|
27
|
+
}
|
|
28
|
+
_createClass(API, null, [{
|
|
29
|
+
key: "sessions",
|
|
30
|
+
value: function sessions(businessId) {
|
|
31
|
+
return new _sessions.default(businessId);
|
|
32
|
+
}
|
|
33
|
+
}, {
|
|
34
|
+
key: "businesses",
|
|
35
|
+
get: function get() {
|
|
36
|
+
return _businesses.default;
|
|
37
|
+
}
|
|
38
|
+
}, {
|
|
39
|
+
key: "events",
|
|
40
|
+
get: function get() {
|
|
41
|
+
return _events.default;
|
|
42
|
+
}
|
|
43
|
+
}, {
|
|
44
|
+
key: "forms",
|
|
45
|
+
get: function get() {
|
|
46
|
+
return _forms.default;
|
|
47
|
+
}
|
|
48
|
+
}]);
|
|
49
|
+
return API;
|
|
50
|
+
}();
|
|
51
|
+
exports.default = API;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.Response = void 0;
|
|
7
|
+
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); } }
|
|
8
|
+
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); }); }; }
|
|
9
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
10
|
+
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); } }
|
|
11
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
12
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
13
|
+
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); }
|
|
14
|
+
function _classPrivateFieldLooseBase(receiver, privateKey) { if (!Object.prototype.hasOwnProperty.call(receiver, privateKey)) { throw new TypeError("attempted to use private field on non-instance"); } return receiver; }
|
|
15
|
+
var id = 0;
|
|
16
|
+
function _classPrivateFieldLooseKey(name) { return "__private_" + id++ + "_" + name; }
|
|
17
|
+
var _success = /*#__PURE__*/_classPrivateFieldLooseKey("success");
|
|
18
|
+
var Response = /*#__PURE__*/function () {
|
|
19
|
+
function Response(success, response) {
|
|
20
|
+
_classCallCheck(this, Response);
|
|
21
|
+
Object.defineProperty(this, _success, {
|
|
22
|
+
writable: true,
|
|
23
|
+
value: void 0
|
|
24
|
+
});
|
|
25
|
+
this.response = response;
|
|
26
|
+
_classPrivateFieldLooseBase(this, _success)[_success] = success;
|
|
27
|
+
}
|
|
28
|
+
_createClass(Response, [{
|
|
29
|
+
key: "data",
|
|
30
|
+
get: function get() {
|
|
31
|
+
return this.response;
|
|
32
|
+
}
|
|
33
|
+
}, {
|
|
34
|
+
key: "json",
|
|
35
|
+
value: function () {
|
|
36
|
+
var _json = _asyncToGenerator(function* () {
|
|
37
|
+
return yield this.response.json();
|
|
38
|
+
});
|
|
39
|
+
function json() {
|
|
40
|
+
return _json.apply(this, arguments);
|
|
41
|
+
}
|
|
42
|
+
return json;
|
|
43
|
+
}()
|
|
44
|
+
}, {
|
|
45
|
+
key: "failed",
|
|
46
|
+
get: function get() {
|
|
47
|
+
return _classPrivateFieldLooseBase(this, _success)[_success] === false;
|
|
48
|
+
}
|
|
49
|
+
}, {
|
|
50
|
+
key: "succeeded",
|
|
51
|
+
get: function get() {
|
|
52
|
+
return _classPrivateFieldLooseBase(this, _success)[_success] === true;
|
|
53
|
+
}
|
|
54
|
+
}]);
|
|
55
|
+
return Response;
|
|
56
|
+
}();
|
|
57
|
+
exports.Response = Response;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _core = require("../core");
|
|
8
|
+
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); } }
|
|
9
|
+
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); }); }; }
|
|
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; }
|
|
13
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
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); }
|
|
15
|
+
var SessionsAPI = /*#__PURE__*/function () {
|
|
16
|
+
function SessionsAPI(businessId) {
|
|
17
|
+
_classCallCheck(this, SessionsAPI);
|
|
18
|
+
this.businessId = businessId;
|
|
19
|
+
}
|
|
20
|
+
_createClass(SessionsAPI, [{
|
|
21
|
+
key: "create",
|
|
22
|
+
value: function () {
|
|
23
|
+
var _create = _asyncToGenerator(function* () {
|
|
24
|
+
var response = yield fetch(SessionsAPI.endpoint, {
|
|
25
|
+
method: 'POST',
|
|
26
|
+
headers: {
|
|
27
|
+
Authorization: "Bearer ".concat(this.businessId),
|
|
28
|
+
Accept: 'application/json'
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
return response.json();
|
|
32
|
+
});
|
|
33
|
+
function create() {
|
|
34
|
+
return _create.apply(this, arguments);
|
|
35
|
+
}
|
|
36
|
+
return create;
|
|
37
|
+
}()
|
|
38
|
+
}], [{
|
|
39
|
+
key: "endpoint",
|
|
40
|
+
get: function get() {
|
|
41
|
+
return _core.Configuration.endpoint('track/sessions');
|
|
42
|
+
}
|
|
43
|
+
}]);
|
|
44
|
+
return SessionsAPI;
|
|
45
|
+
}();
|
|
46
|
+
exports.default = SessionsAPI;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _hellotext = _interopRequireDefault(require("../hellotext"));
|
|
8
|
+
var _core = require("../core");
|
|
9
|
+
var _response = require("./response");
|
|
10
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
+
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); } }
|
|
12
|
+
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); }); }; }
|
|
13
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
14
|
+
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); } }
|
|
15
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
16
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
17
|
+
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); }
|
|
18
|
+
var SubmissionsAPI = /*#__PURE__*/function () {
|
|
19
|
+
function SubmissionsAPI() {
|
|
20
|
+
_classCallCheck(this, SubmissionsAPI);
|
|
21
|
+
}
|
|
22
|
+
_createClass(SubmissionsAPI, null, [{
|
|
23
|
+
key: "endpoint",
|
|
24
|
+
get: function get() {
|
|
25
|
+
return _core.Configuration.endpoint('public/submissions');
|
|
26
|
+
}
|
|
27
|
+
}, {
|
|
28
|
+
key: "resendOTP",
|
|
29
|
+
value: function () {
|
|
30
|
+
var _resendOTP = _asyncToGenerator(function* (id) {
|
|
31
|
+
var response = yield fetch("".concat(this.endpoint, "/").concat(id, "/otps"), {
|
|
32
|
+
method: 'POST',
|
|
33
|
+
headers: _hellotext.default.headers
|
|
34
|
+
});
|
|
35
|
+
return new _response.Response(response.ok, response);
|
|
36
|
+
});
|
|
37
|
+
function resendOTP(_x) {
|
|
38
|
+
return _resendOTP.apply(this, arguments);
|
|
39
|
+
}
|
|
40
|
+
return resendOTP;
|
|
41
|
+
}()
|
|
42
|
+
}, {
|
|
43
|
+
key: "verifyOTP",
|
|
44
|
+
value: function () {
|
|
45
|
+
var _verifyOTP = _asyncToGenerator(function* (id, otp) {
|
|
46
|
+
var response = yield fetch("".concat(this.endpoint, "/").concat(id, "/otps/").concat(otp, "/verify"), {
|
|
47
|
+
method: 'POST',
|
|
48
|
+
headers: _hellotext.default.headers
|
|
49
|
+
});
|
|
50
|
+
return new _response.Response(response.ok, response);
|
|
51
|
+
});
|
|
52
|
+
function verifyOTP(_x2, _x3) {
|
|
53
|
+
return _verifyOTP.apply(this, arguments);
|
|
54
|
+
}
|
|
55
|
+
return verifyOTP;
|
|
56
|
+
}()
|
|
57
|
+
}]);
|
|
58
|
+
return SubmissionsAPI;
|
|
59
|
+
}();
|
|
60
|
+
var _default = SubmissionsAPI;
|
|
61
|
+
exports.default = _default;
|
package/lib/api.js
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', {
|
|
4
|
+
value: true,
|
|
5
|
+
})
|
|
6
|
+
exports.default = void 0
|
|
7
|
+
var _sessions = _interopRequireDefault(require('./api/sessions'))
|
|
8
|
+
var _businesses = _interopRequireDefault(require('./api/businesses'))
|
|
9
|
+
var _events = _interopRequireDefault(require('./api/events'))
|
|
10
|
+
function _interopRequireDefault(obj) {
|
|
11
|
+
return obj && obj.__esModule ? obj : { default: obj }
|
|
12
|
+
}
|
|
13
|
+
function _classCallCheck(instance, Constructor) {
|
|
14
|
+
if (!(instance instanceof Constructor)) {
|
|
15
|
+
throw new TypeError('Cannot call a class as a function')
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
function _defineProperties(target, props) {
|
|
19
|
+
for (var i = 0; i < props.length; i++) {
|
|
20
|
+
var descriptor = props[i]
|
|
21
|
+
descriptor.enumerable = descriptor.enumerable || false
|
|
22
|
+
descriptor.configurable = true
|
|
23
|
+
if ('value' in descriptor) descriptor.writable = true
|
|
24
|
+
Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor)
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
function _createClass(Constructor, protoProps, staticProps) {
|
|
28
|
+
if (protoProps) _defineProperties(Constructor.prototype, protoProps)
|
|
29
|
+
if (staticProps) _defineProperties(Constructor, staticProps)
|
|
30
|
+
Object.defineProperty(Constructor, 'prototype', { writable: false })
|
|
31
|
+
return Constructor
|
|
32
|
+
}
|
|
33
|
+
function _toPropertyKey(arg) {
|
|
34
|
+
var key = _toPrimitive(arg, 'string')
|
|
35
|
+
return typeof key === 'symbol' ? key : String(key)
|
|
36
|
+
}
|
|
37
|
+
function _toPrimitive(input, hint) {
|
|
38
|
+
if (typeof input !== 'object' || input === null) return input
|
|
39
|
+
var prim = input[Symbol.toPrimitive]
|
|
40
|
+
if (prim !== undefined) {
|
|
41
|
+
var res = prim.call(input, hint || 'default')
|
|
42
|
+
if (typeof res !== 'object') return res
|
|
43
|
+
throw new TypeError('@@toPrimitive must return a primitive value.')
|
|
44
|
+
}
|
|
45
|
+
return (hint === 'string' ? String : Number)(input)
|
|
46
|
+
}
|
|
47
|
+
var API = /*#__PURE__*/ (function () {
|
|
48
|
+
function API() {
|
|
49
|
+
_classCallCheck(this, API)
|
|
50
|
+
}
|
|
51
|
+
_createClass(API, null, [
|
|
52
|
+
{
|
|
53
|
+
key: 'sessions',
|
|
54
|
+
value: function sessions(businessId) {
|
|
55
|
+
return new _sessions.default(businessId)
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
key: 'businesses',
|
|
60
|
+
get: function get() {
|
|
61
|
+
return _businesses.default
|
|
62
|
+
},
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
key: 'events',
|
|
66
|
+
get: function get() {
|
|
67
|
+
return _events.default
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
])
|
|
71
|
+
return API
|
|
72
|
+
})()
|
|
73
|
+
exports.default = API
|