@hellotext/hellotext 1.4.1 → 1.5.0
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
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.FormCollection = void 0;
|
|
7
|
+
var _hellotext = _interopRequireDefault(require("../hellotext.js"));
|
|
8
|
+
var _api = _interopRequireDefault(require("../api"));
|
|
9
|
+
var _form = require("./form");
|
|
10
|
+
var _errors = require("../errors");
|
|
11
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
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
|
+
function _classPrivateFieldLooseBase(receiver, privateKey) { if (!Object.prototype.hasOwnProperty.call(receiver, privateKey)) { throw new TypeError("attempted to use private field on non-instance"); } return receiver; }
|
|
18
|
+
var id = 0;
|
|
19
|
+
function _classPrivateFieldLooseKey(name) { return "__private_" + id++ + "_" + name; }
|
|
20
|
+
var _formIdsToFetch = /*#__PURE__*/_classPrivateFieldLooseKey("formIdsToFetch");
|
|
21
|
+
var FormCollection = /*#__PURE__*/function () {
|
|
22
|
+
function FormCollection() {
|
|
23
|
+
_classCallCheck(this, FormCollection);
|
|
24
|
+
Object.defineProperty(this, _formIdsToFetch, {
|
|
25
|
+
get: _get_formIdsToFetch,
|
|
26
|
+
set: void 0
|
|
27
|
+
});
|
|
28
|
+
this.forms = [];
|
|
29
|
+
this.includes = this.includes.bind(this);
|
|
30
|
+
this.excludes = this.excludes.bind(this);
|
|
31
|
+
this.add = this.add.bind(this);
|
|
32
|
+
}
|
|
33
|
+
_createClass(FormCollection, [{
|
|
34
|
+
key: "collect",
|
|
35
|
+
value: function collect() {
|
|
36
|
+
if (_hellotext.default.notInitialized) {
|
|
37
|
+
throw new _errors.NotInitializedError();
|
|
38
|
+
}
|
|
39
|
+
var formsIdsToFetch = _classPrivateFieldLooseBase(this, _formIdsToFetch)[_formIdsToFetch];
|
|
40
|
+
if (formsIdsToFetch.length === 0) return;
|
|
41
|
+
var promises = formsIdsToFetch.map(id => {
|
|
42
|
+
return _api.default.forms.get(id).then(response => response.json());
|
|
43
|
+
});
|
|
44
|
+
if (!_hellotext.default.business.enabledWhitelist) {
|
|
45
|
+
console.warn('No whitelist has been configured. It is advised to whitelist the domain to avoid bots from submitting forms.');
|
|
46
|
+
}
|
|
47
|
+
Promise.all(promises).then(forms => forms.forEach(this.add)).then(() => _hellotext.default.eventEmitter.dispatch('forms:collected', this));
|
|
48
|
+
}
|
|
49
|
+
}, {
|
|
50
|
+
key: "forEach",
|
|
51
|
+
value: function forEach(callback) {
|
|
52
|
+
this.forms.forEach(callback);
|
|
53
|
+
}
|
|
54
|
+
}, {
|
|
55
|
+
key: "map",
|
|
56
|
+
value: function map(callback) {
|
|
57
|
+
return this.forms.map(callback);
|
|
58
|
+
}
|
|
59
|
+
}, {
|
|
60
|
+
key: "add",
|
|
61
|
+
value: function add(data) {
|
|
62
|
+
if (this.includes(data.id)) return;
|
|
63
|
+
this.forms.push(new _form.Form(data));
|
|
64
|
+
}
|
|
65
|
+
}, {
|
|
66
|
+
key: "getById",
|
|
67
|
+
value: function getById(id) {
|
|
68
|
+
return this.forms.find(form => form.id === id);
|
|
69
|
+
}
|
|
70
|
+
}, {
|
|
71
|
+
key: "getByIndex",
|
|
72
|
+
value: function getByIndex(index) {
|
|
73
|
+
return this.forms[index];
|
|
74
|
+
}
|
|
75
|
+
}, {
|
|
76
|
+
key: "includes",
|
|
77
|
+
value: function includes(formId) {
|
|
78
|
+
return this.forms.some(form => form.id === formId);
|
|
79
|
+
}
|
|
80
|
+
}, {
|
|
81
|
+
key: "excludes",
|
|
82
|
+
value: function excludes(id) {
|
|
83
|
+
return !this.includes(id);
|
|
84
|
+
}
|
|
85
|
+
}, {
|
|
86
|
+
key: "length",
|
|
87
|
+
get: function get() {
|
|
88
|
+
return this.forms.length;
|
|
89
|
+
}
|
|
90
|
+
}]);
|
|
91
|
+
return FormCollection;
|
|
92
|
+
}();
|
|
93
|
+
exports.FormCollection = FormCollection;
|
|
94
|
+
function _get_formIdsToFetch() {
|
|
95
|
+
return Array.from(document.querySelectorAll('[data-hello-form]')).map(form => form.dataset.helloForm).filter(this.excludes);
|
|
96
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "Business", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function get() {
|
|
9
|
+
return _business.Business;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
Object.defineProperty(exports, "Cookies", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function get() {
|
|
15
|
+
return _cookies.Cookies;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
Object.defineProperty(exports, "Form", {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: function get() {
|
|
21
|
+
return _form.Form;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
Object.defineProperty(exports, "FormCollection", {
|
|
25
|
+
enumerable: true,
|
|
26
|
+
get: function get() {
|
|
27
|
+
return _form_collection.FormCollection;
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
Object.defineProperty(exports, "Query", {
|
|
31
|
+
enumerable: true,
|
|
32
|
+
get: function get() {
|
|
33
|
+
return _query.Query;
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
var _business = require("./business");
|
|
37
|
+
var _form = require("./form");
|
|
38
|
+
var _query = require("./query");
|
|
39
|
+
var _cookies = require("./cookies");
|
|
40
|
+
var _form_collection = require("./form_collection");
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.Query = void 0;
|
|
7
|
+
var _cookies = require("./cookies");
|
|
8
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
9
|
+
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); } }
|
|
10
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
11
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
12
|
+
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); }
|
|
13
|
+
var Query = /*#__PURE__*/function () {
|
|
14
|
+
function Query() {
|
|
15
|
+
_classCallCheck(this, Query);
|
|
16
|
+
this.urlSearchParams = new URLSearchParams(window.location.search);
|
|
17
|
+
}
|
|
18
|
+
_createClass(Query, [{
|
|
19
|
+
key: "get",
|
|
20
|
+
value: function get(param) {
|
|
21
|
+
return this.urlSearchParams.get(this.toHellotextParam(param));
|
|
22
|
+
}
|
|
23
|
+
}, {
|
|
24
|
+
key: "has",
|
|
25
|
+
value: function has(param) {
|
|
26
|
+
return this.urlSearchParams.has(this.toHellotextParam(param));
|
|
27
|
+
}
|
|
28
|
+
}, {
|
|
29
|
+
key: "inPreviewMode",
|
|
30
|
+
get: function get() {
|
|
31
|
+
return this.has('preview');
|
|
32
|
+
}
|
|
33
|
+
}, {
|
|
34
|
+
key: "session",
|
|
35
|
+
get: function get() {
|
|
36
|
+
return this.get('session') || _cookies.Cookies.get('hello_session');
|
|
37
|
+
}
|
|
38
|
+
}, {
|
|
39
|
+
key: "toHellotextParam",
|
|
40
|
+
value: function toHellotextParam(param) {
|
|
41
|
+
return "hello_".concat(param);
|
|
42
|
+
}
|
|
43
|
+
}], [{
|
|
44
|
+
key: "inPreviewMode",
|
|
45
|
+
get: function get() {
|
|
46
|
+
return new this().inPreviewMode;
|
|
47
|
+
}
|
|
48
|
+
}]);
|
|
49
|
+
return Query;
|
|
50
|
+
}();
|
|
51
|
+
exports.Query = Query;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.Step = 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); }
|
|
12
|
+
var Step = /*#__PURE__*/function () {
|
|
13
|
+
function Step(data) {
|
|
14
|
+
_classCallCheck(this, Step);
|
|
15
|
+
this.data = data;
|
|
16
|
+
}
|
|
17
|
+
_createClass(Step, [{
|
|
18
|
+
key: "header",
|
|
19
|
+
get: function get() {
|
|
20
|
+
return this.data.header;
|
|
21
|
+
}
|
|
22
|
+
}, {
|
|
23
|
+
key: "inputs",
|
|
24
|
+
get: function get() {
|
|
25
|
+
return this.data.inputs;
|
|
26
|
+
}
|
|
27
|
+
}, {
|
|
28
|
+
key: "button",
|
|
29
|
+
get: function get() {
|
|
30
|
+
return this.data.button;
|
|
31
|
+
}
|
|
32
|
+
}, {
|
|
33
|
+
key: "footer",
|
|
34
|
+
get: function get() {
|
|
35
|
+
return this.data.footer;
|
|
36
|
+
}
|
|
37
|
+
}, {
|
|
38
|
+
key: "hasRequiredInputs",
|
|
39
|
+
get: function get() {
|
|
40
|
+
return this.inputs.some(input => input.required);
|
|
41
|
+
}
|
|
42
|
+
}]);
|
|
43
|
+
return Step;
|
|
44
|
+
}();
|
|
45
|
+
exports.Step = Step;
|
package/lib/query.js
CHANGED
|
@@ -1,35 +1,68 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict'
|
|
2
2
|
|
|
3
|
-
Object.defineProperty(exports,
|
|
4
|
-
value: true
|
|
5
|
-
})
|
|
6
|
-
exports.default = void 0
|
|
7
|
-
function _classCallCheck(instance, Constructor) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
3
|
+
Object.defineProperty(exports, '__esModule', {
|
|
4
|
+
value: true,
|
|
5
|
+
})
|
|
6
|
+
exports.default = void 0
|
|
7
|
+
function _classCallCheck(instance, Constructor) {
|
|
8
|
+
if (!(instance instanceof Constructor)) {
|
|
9
|
+
throw new TypeError('Cannot call a class as a function')
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
function _defineProperties(target, props) {
|
|
13
|
+
for (var i = 0; i < props.length; i++) {
|
|
14
|
+
var descriptor = props[i]
|
|
15
|
+
descriptor.enumerable = descriptor.enumerable || false
|
|
16
|
+
descriptor.configurable = true
|
|
17
|
+
if ('value' in descriptor) descriptor.writable = true
|
|
18
|
+
Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor)
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
function _createClass(Constructor, protoProps, staticProps) {
|
|
22
|
+
if (protoProps) _defineProperties(Constructor.prototype, protoProps)
|
|
23
|
+
if (staticProps) _defineProperties(Constructor, staticProps)
|
|
24
|
+
Object.defineProperty(Constructor, 'prototype', { writable: false })
|
|
25
|
+
return Constructor
|
|
26
|
+
}
|
|
27
|
+
function _toPropertyKey(arg) {
|
|
28
|
+
var key = _toPrimitive(arg, 'string')
|
|
29
|
+
return typeof key === 'symbol' ? key : String(key)
|
|
30
|
+
}
|
|
31
|
+
function _toPrimitive(input, hint) {
|
|
32
|
+
if (typeof input !== 'object' || input === null) return input
|
|
33
|
+
var prim = input[Symbol.toPrimitive]
|
|
34
|
+
if (prim !== undefined) {
|
|
35
|
+
var res = prim.call(input, hint || 'default')
|
|
36
|
+
if (typeof res !== 'object') return res
|
|
37
|
+
throw new TypeError('@@toPrimitive must return a primitive value.')
|
|
38
|
+
}
|
|
39
|
+
return (hint === 'string' ? String : Number)(input)
|
|
40
|
+
}
|
|
41
|
+
var Query = /*#__PURE__*/ (function () {
|
|
13
42
|
function Query(urlQueries) {
|
|
14
|
-
_classCallCheck(this, Query)
|
|
15
|
-
this.urlSearchParams = new URLSearchParams(urlQueries)
|
|
43
|
+
_classCallCheck(this, Query)
|
|
44
|
+
this.urlSearchParams = new URLSearchParams(urlQueries)
|
|
16
45
|
}
|
|
17
|
-
_createClass(Query, [
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
}
|
|
35
|
-
|
|
46
|
+
_createClass(Query, [
|
|
47
|
+
{
|
|
48
|
+
key: 'get',
|
|
49
|
+
value: function get(param) {
|
|
50
|
+
return this.urlSearchParams.get(this.toHellotextParam(param))
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
key: 'has',
|
|
55
|
+
value: function has(param) {
|
|
56
|
+
return this.urlSearchParams.has(this.toHellotextParam(param))
|
|
57
|
+
},
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
key: 'toHellotextParam',
|
|
61
|
+
value: function toHellotextParam(param) {
|
|
62
|
+
return 'hello_'.concat(param)
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
])
|
|
66
|
+
return Query
|
|
67
|
+
})()
|
|
68
|
+
exports.default = Query
|
package/lib/response.js
CHANGED
|
@@ -1,49 +1,89 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict'
|
|
2
2
|
|
|
3
|
-
Object.defineProperty(exports,
|
|
4
|
-
value: true
|
|
5
|
-
})
|
|
6
|
-
exports.default = void 0
|
|
7
|
-
function _classCallCheck(instance, Constructor) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
function
|
|
13
|
-
var
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
3
|
+
Object.defineProperty(exports, '__esModule', {
|
|
4
|
+
value: true,
|
|
5
|
+
})
|
|
6
|
+
exports.default = void 0
|
|
7
|
+
function _classCallCheck(instance, Constructor) {
|
|
8
|
+
if (!(instance instanceof Constructor)) {
|
|
9
|
+
throw new TypeError('Cannot call a class as a function')
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
function _defineProperties(target, props) {
|
|
13
|
+
for (var i = 0; i < props.length; i++) {
|
|
14
|
+
var descriptor = props[i]
|
|
15
|
+
descriptor.enumerable = descriptor.enumerable || false
|
|
16
|
+
descriptor.configurable = true
|
|
17
|
+
if ('value' in descriptor) descriptor.writable = true
|
|
18
|
+
Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor)
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
function _createClass(Constructor, protoProps, staticProps) {
|
|
22
|
+
if (protoProps) _defineProperties(Constructor.prototype, protoProps)
|
|
23
|
+
if (staticProps) _defineProperties(Constructor, staticProps)
|
|
24
|
+
Object.defineProperty(Constructor, 'prototype', { writable: false })
|
|
25
|
+
return Constructor
|
|
26
|
+
}
|
|
27
|
+
function _toPropertyKey(arg) {
|
|
28
|
+
var key = _toPrimitive(arg, 'string')
|
|
29
|
+
return typeof key === 'symbol' ? key : String(key)
|
|
30
|
+
}
|
|
31
|
+
function _toPrimitive(input, hint) {
|
|
32
|
+
if (typeof input !== 'object' || input === null) return input
|
|
33
|
+
var prim = input[Symbol.toPrimitive]
|
|
34
|
+
if (prim !== undefined) {
|
|
35
|
+
var res = prim.call(input, hint || 'default')
|
|
36
|
+
if (typeof res !== 'object') return res
|
|
37
|
+
throw new TypeError('@@toPrimitive must return a primitive value.')
|
|
38
|
+
}
|
|
39
|
+
return (hint === 'string' ? String : Number)(input)
|
|
40
|
+
}
|
|
41
|
+
function _classPrivateFieldLooseBase(receiver, privateKey) {
|
|
42
|
+
if (!Object.prototype.hasOwnProperty.call(receiver, privateKey)) {
|
|
43
|
+
throw new TypeError('attempted to use private field on non-instance')
|
|
44
|
+
}
|
|
45
|
+
return receiver
|
|
46
|
+
}
|
|
47
|
+
var id = 0
|
|
48
|
+
function _classPrivateFieldLooseKey(name) {
|
|
49
|
+
return '__private_' + id++ + '_' + name
|
|
50
|
+
}
|
|
51
|
+
var _success = /*#__PURE__*/ _classPrivateFieldLooseKey('success')
|
|
52
|
+
var _response = /*#__PURE__*/ _classPrivateFieldLooseKey('response')
|
|
53
|
+
var Response = /*#__PURE__*/ (function () {
|
|
18
54
|
function Response(success, response) {
|
|
19
|
-
_classCallCheck(this, Response)
|
|
55
|
+
_classCallCheck(this, Response)
|
|
20
56
|
Object.defineProperty(this, _success, {
|
|
21
57
|
writable: true,
|
|
22
|
-
value: void 0
|
|
23
|
-
})
|
|
58
|
+
value: void 0,
|
|
59
|
+
})
|
|
24
60
|
Object.defineProperty(this, _response, {
|
|
25
61
|
writable: true,
|
|
26
|
-
value: void 0
|
|
27
|
-
})
|
|
28
|
-
_classPrivateFieldLooseBase(this, _success)[_success] = success
|
|
29
|
-
_classPrivateFieldLooseBase(this, _response)[_response] = response
|
|
62
|
+
value: void 0,
|
|
63
|
+
})
|
|
64
|
+
_classPrivateFieldLooseBase(this, _success)[_success] = success
|
|
65
|
+
_classPrivateFieldLooseBase(this, _response)[_response] = response
|
|
30
66
|
}
|
|
31
|
-
_createClass(Response, [
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
}
|
|
49
|
-
|
|
67
|
+
_createClass(Response, [
|
|
68
|
+
{
|
|
69
|
+
key: 'data',
|
|
70
|
+
get: function get() {
|
|
71
|
+
return _classPrivateFieldLooseBase(this, _response)[_response]
|
|
72
|
+
},
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
key: 'failed',
|
|
76
|
+
get: function get() {
|
|
77
|
+
return _classPrivateFieldLooseBase(this, _success)[_success] === false
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
key: 'succeeded',
|
|
82
|
+
get: function get() {
|
|
83
|
+
return _classPrivateFieldLooseBase(this, _success)[_success] === true
|
|
84
|
+
},
|
|
85
|
+
},
|
|
86
|
+
])
|
|
87
|
+
return Response
|
|
88
|
+
})()
|
|
89
|
+
exports.default = Response
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hellotext/hellotext",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.0",
|
|
4
4
|
"description": "Hellotext JavaScript Client",
|
|
5
5
|
"source": "src/index.js",
|
|
6
6
|
"main": "lib/index.js",
|
|
@@ -18,7 +18,9 @@
|
|
|
18
18
|
"jest-environment-jsdom": "^29.3.1",
|
|
19
19
|
"prettier": "2.8.2",
|
|
20
20
|
"webpack": "^5.75.0",
|
|
21
|
-
"webpack-cli": "^5.0.1"
|
|
21
|
+
"webpack-cli": "^5.0.1",
|
|
22
|
+
"style-loader": "^3.3.1",
|
|
23
|
+
"css-loader": "^6.5.0"
|
|
22
24
|
},
|
|
23
25
|
"repository": {
|
|
24
26
|
"type": "git",
|
|
@@ -39,6 +41,7 @@
|
|
|
39
41
|
},
|
|
40
42
|
"dependencies": {
|
|
41
43
|
"core-js": "3.27.2",
|
|
42
|
-
"whatwg-fetch": "^3.6.2"
|
|
44
|
+
"whatwg-fetch": "^3.6.2",
|
|
45
|
+
"@hotwired/stimulus": "^3.0.0"
|
|
43
46
|
}
|
|
44
47
|
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Configuration } from '../core'
|
|
2
|
+
|
|
3
|
+
export default class {
|
|
4
|
+
static get endpoint() {
|
|
5
|
+
return Configuration.endpoint('public/businesses')
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
static async get(id) {
|
|
9
|
+
return fetch(`${this.endpoint}/${id}`, {
|
|
10
|
+
method: 'GET',
|
|
11
|
+
headers: {
|
|
12
|
+
Authorization: `Bearer ${id}`,
|
|
13
|
+
Accept: 'application.json',
|
|
14
|
+
'Content-Type': 'application/json',
|
|
15
|
+
},
|
|
16
|
+
})
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Configuration } from '../core'
|
|
2
|
+
|
|
3
|
+
import { Query } from '../models'
|
|
4
|
+
import { Response } from './response'
|
|
5
|
+
|
|
6
|
+
export default class EventsAPI {
|
|
7
|
+
static get endpoint() {
|
|
8
|
+
return Configuration.endpoint('track/events')
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
static async create({ headers, body }) {
|
|
12
|
+
if (Query.inPreviewMode) {
|
|
13
|
+
return new Response(true, { received: true })
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const response = await fetch(this.endpoint, {
|
|
17
|
+
method: 'POST',
|
|
18
|
+
headers,
|
|
19
|
+
body: JSON.stringify(body),
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
return new Response(response.status === 200, await response.json())
|
|
23
|
+
}
|
|
24
|
+
}
|
package/src/api/forms.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import Hellotext from '../hellotext'
|
|
2
|
+
import { Configuration } from '../core'
|
|
3
|
+
|
|
4
|
+
import { Response } from './response'
|
|
5
|
+
|
|
6
|
+
export default class FormsAPI {
|
|
7
|
+
static get endpoint() {
|
|
8
|
+
return Configuration.endpoint('public/forms')
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
static async get(id) {
|
|
12
|
+
return fetch(`${this.endpoint}/${id}`, {
|
|
13
|
+
method: 'GET',
|
|
14
|
+
headers: Hellotext.headers,
|
|
15
|
+
})
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
static async submit(id, data) {
|
|
19
|
+
const response = await fetch(`${this.endpoint}/${id}/submissions`, {
|
|
20
|
+
method: 'POST',
|
|
21
|
+
headers: Hellotext.headers,
|
|
22
|
+
body: JSON.stringify({
|
|
23
|
+
session: Hellotext.session,
|
|
24
|
+
...data,
|
|
25
|
+
}),
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
return new Response(response.ok, response)
|
|
29
|
+
}
|
|
30
|
+
}
|
package/src/api/index.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import SessionsAPI from './sessions'
|
|
2
|
+
import BusinessesAPI from './businesses'
|
|
3
|
+
import EventsAPI from './events'
|
|
4
|
+
import FormsAPI from './forms'
|
|
5
|
+
|
|
6
|
+
export default class API {
|
|
7
|
+
static sessions(businessId) {
|
|
8
|
+
return new SessionsAPI(businessId)
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
static get businesses() {
|
|
12
|
+
return BusinessesAPI
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
static get events() {
|
|
16
|
+
return EventsAPI
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
static get forms() {
|
|
20
|
+
return FormsAPI
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export { Response } from './response'
|
|
@@ -1,14 +1,17 @@
|
|
|
1
|
-
|
|
1
|
+
class Response {
|
|
2
2
|
#success
|
|
3
|
-
#response
|
|
4
3
|
|
|
5
4
|
constructor(success, response) {
|
|
5
|
+
this.response = response
|
|
6
6
|
this.#success = success
|
|
7
|
-
this.#response = response
|
|
8
7
|
}
|
|
9
8
|
|
|
10
9
|
get data() {
|
|
11
|
-
return this
|
|
10
|
+
return this.response
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
async json() {
|
|
14
|
+
return await this.response.json()
|
|
12
15
|
}
|
|
13
16
|
|
|
14
17
|
get failed() {
|
|
@@ -19,3 +22,5 @@ export default class Response {
|
|
|
19
22
|
return this.#success === true
|
|
20
23
|
}
|
|
21
24
|
}
|
|
25
|
+
|
|
26
|
+
export { Response }
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Configuration } from '../core'
|
|
2
|
+
|
|
3
|
+
export default class SessionsAPI {
|
|
4
|
+
static get endpoint() {
|
|
5
|
+
return Configuration.endpoint('track/sessions')
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
constructor(businessId) {
|
|
9
|
+
this.businessId = businessId
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
async create() {
|
|
13
|
+
const response = await fetch(SessionsAPI.endpoint, {
|
|
14
|
+
method: 'POST',
|
|
15
|
+
headers: {
|
|
16
|
+
Authorization: `Bearer ${this.businessId}`,
|
|
17
|
+
Accept: 'application/json',
|
|
18
|
+
},
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
return response.json()
|
|
22
|
+
}
|
|
23
|
+
}
|