@hellotext/hellotext 1.6.6 → 1.6.8

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/lib/forms.js DELETED
@@ -1,133 +0,0 @@
1
- 'use strict'
2
-
3
- Object.defineProperty(exports, '__esModule', {
4
- value: true,
5
- })
6
- exports.Forms = void 0
7
- var _hellotext = _interopRequireDefault(require('./hellotext.js'))
8
- var _models = require('./models')
9
- var _forms = _interopRequireDefault(require('./api/forms'))
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
- function _classPrivateFieldLooseBase(receiver, privateKey) {
48
- if (!Object.prototype.hasOwnProperty.call(receiver, privateKey)) {
49
- throw new TypeError('attempted to use private field on non-instance')
50
- }
51
- return receiver
52
- }
53
- var id = 0
54
- function _classPrivateFieldLooseKey(name) {
55
- return '__private_' + id++ + '_' + name
56
- }
57
- var _formIdsToFetch = /*#__PURE__*/ _classPrivateFieldLooseKey('formIdsToFetch')
58
- var Forms = /*#__PURE__*/ (function () {
59
- function Forms() {
60
- _classCallCheck(this, Forms)
61
- Object.defineProperty(this, _formIdsToFetch, {
62
- get: _get_formIdsToFetch,
63
- set: void 0,
64
- })
65
- this.forms = []
66
- this.includes = this.includes.bind(this)
67
- this.excludes = this.excludes.bind(this)
68
- }
69
- _createClass(Forms, [
70
- {
71
- key: 'collect',
72
- value: function collect() {
73
- var formsIdsToFetch = _classPrivateFieldLooseBase(this, _formIdsToFetch)[_formIdsToFetch]
74
- if (formsIdsToFetch.length === 0) return
75
- var promises = formsIdsToFetch.map(id => {
76
- return _forms.default.get(id).then(response => response.json())
77
- })
78
- if (!_hellotext.default.business.enabledWhitelist) {
79
- console.warn(
80
- 'No whitelist has been configured. It is advised to whitelist the domain to avoid bots from submitting forms.',
81
- )
82
- }
83
- Promise.all(promises)
84
- .then(forms => forms.forEach(form => this.add(form)))
85
- .then(() => _hellotext.default.eventEmitter.emit('forms:collected', this))
86
- },
87
- },
88
- {
89
- key: 'add',
90
- value: function add(data) {
91
- if (this.includes(data.id)) return
92
- this.forms.push(new _models.Form(data))
93
- },
94
- },
95
- {
96
- key: 'getById',
97
- value: function getById(id) {
98
- return this.forms.find(form => form.id === id)
99
- },
100
- },
101
- {
102
- key: 'getByIndex',
103
- value: function getByIndex(index) {
104
- return this.forms[index]
105
- },
106
- },
107
- {
108
- key: 'includes',
109
- value: function includes(formId) {
110
- return this.forms.some(form => form.id === formId)
111
- },
112
- },
113
- {
114
- key: 'excludes',
115
- value: function excludes(id) {
116
- return !this.includes(id)
117
- },
118
- },
119
- {
120
- key: 'length',
121
- get: function get() {
122
- return this.forms.length
123
- },
124
- },
125
- ])
126
- return Forms
127
- })()
128
- exports.Forms = Forms
129
- function _get_formIdsToFetch() {
130
- return Array.from(document.querySelectorAll('[data-hello-form]'))
131
- .map(form => form.dataset.helloForm)
132
- .filter(this.excludes)
133
- }
@@ -1,66 +0,0 @@
1
- 'use strict'
2
-
3
- Object.defineProperty(exports, '__esModule', {
4
- value: true,
5
- })
6
- exports.Configuration = 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 Configuration = /*#__PURE__*/ (function () {
42
- function Configuration() {
43
- _classCallCheck(this, Configuration)
44
- }
45
- _createClass(Configuration, null, [
46
- {
47
- key: 'assign',
48
- value: function assign(_ref) {
49
- var { apiRoot, autoGenerateSession } = _ref
50
- this.apiRoot = apiRoot
51
- this.autoGenerateSession = autoGenerateSession
52
- return this
53
- },
54
- },
55
- {
56
- key: 'endpoint',
57
- value: function endpoint(path) {
58
- return ''.concat(this.apiRoot, '/').concat(path)
59
- },
60
- },
61
- ])
62
- return Configuration
63
- })()
64
- exports.Configuration = Configuration
65
- Configuration.apiRoot = 'http://api.lvh.me:3000/v1/'
66
- Configuration.autoGenerateSession = true
@@ -1,45 +0,0 @@
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 DELETED
@@ -1,68 +0,0 @@
1
- 'use strict'
2
-
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 () {
42
- function Query(urlQueries) {
43
- _classCallCheck(this, Query)
44
- this.urlSearchParams = new URLSearchParams(urlQueries)
45
- }
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 DELETED
@@ -1,89 +0,0 @@
1
- 'use strict'
2
-
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 () {
54
- function Response(success, response) {
55
- _classCallCheck(this, Response)
56
- Object.defineProperty(this, _success, {
57
- writable: true,
58
- value: void 0,
59
- })
60
- Object.defineProperty(this, _response, {
61
- writable: true,
62
- value: void 0,
63
- })
64
- _classPrivateFieldLooseBase(this, _success)[_success] = success
65
- _classPrivateFieldLooseBase(this, _response)[_response] = response
66
- }
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