@hellotext/hellotext 1.8.7 → 2.0.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/README.md +27 -2
- package/dist/hellotext.js +1 -1
- package/index.d.ts +61 -0
- package/lib/api/businesses.cjs +37 -0
- package/lib/api/businesses.js +3 -9
- package/lib/api/events.cjs +45 -0
- package/lib/api/events.js +8 -14
- package/lib/api/forms.cjs +51 -0
- package/lib/api/forms.js +10 -17
- package/lib/api/index.cjs +51 -0
- package/lib/api/index.js +10 -23
- package/lib/api/response.cjs +76 -0
- package/lib/api/response.js +1 -7
- package/lib/api/submissions.cjs +47 -0
- package/lib/api/submissions.js +9 -17
- package/lib/api/webchat/messages.cjs +70 -0
- package/lib/api/webchat/messages.js +10 -18
- package/lib/api/webchats.cjs +44 -0
- package/lib/api/webchats.js +8 -16
- package/lib/builders/input_builder.cjs +61 -0
- package/lib/builders/input_builder.js +4 -11
- package/lib/builders/logo_builder.cjs +50 -0
- package/lib/builders/logo_builder.js +5 -12
- package/lib/channels/application_channel.cjs +67 -0
- package/lib/channels/application_channel.js +1 -8
- package/lib/channels/{web_chat_channel.js → webchat_channel.cjs} +35 -20
- package/lib/channels/webchat_channel.js +3 -11
- package/lib/controllers/form_controller.cjs +141 -0
- package/lib/controllers/form_controller.js +15 -22
- package/lib/controllers/mixins/usePopover.cjs +59 -0
- package/lib/controllers/mixins/usePopover.js +6 -14
- package/lib/controllers/{web_chat/pagination_controller.js → webchat/emoji_picker_controller.cjs} +74 -29
- package/lib/controllers/webchat/emoji_picker_controller.js +11 -17
- package/lib/controllers/webchat_controller.cjs +433 -0
- package/lib/controllers/webchat_controller.js +49 -51
- package/lib/core/configuration/forms.cjs +49 -0
- package/lib/core/configuration/forms.js +2 -8
- package/lib/core/configuration/{web_chat.js → webchat.cjs} +53 -38
- package/lib/core/configuration/webchat.js +2 -9
- package/lib/core/configuration.cjs +65 -0
- package/lib/core/configuration.js +8 -13
- package/lib/core/event.cjs +71 -0
- package/lib/core/event.js +5 -11
- package/lib/core/index.cjs +20 -0
- package/lib/core/index.js +2 -20
- package/lib/errors/index.cjs +19 -0
- package/lib/errors/index.js +2 -19
- package/lib/errors/invalid_event.cjs +34 -0
- package/lib/errors/invalid_event.js +1 -7
- package/lib/errors/not_initialized_error.cjs +34 -0
- package/lib/errors/not_initialized_error.js +1 -7
- package/lib/hellotext.cjs +153 -0
- package/lib/hellotext.js +19 -27
- package/lib/index.cjs +19 -0
- package/lib/index.js +11 -20
- package/lib/locales/en.cjs +22 -0
- package/lib/locales/en.js +2 -9
- package/lib/locales/es.cjs +22 -0
- package/lib/locales/es.js +2 -9
- package/lib/locales/index.cjs +14 -0
- package/lib/locales/index.js +6 -14
- package/lib/models/business.cjs +62 -0
- package/lib/models/business.js +22 -24
- package/lib/models/cookies.cjs +40 -0
- package/lib/models/cookies.js +3 -10
- package/lib/models/form.cjs +166 -0
- package/lib/models/form.js +10 -17
- package/lib/models/form_collection.cjs +122 -0
- package/lib/models/form_collection.js +18 -22
- package/lib/models/index.cjs +54 -0
- package/lib/models/index.js +7 -54
- package/lib/models/query.cjs +51 -0
- package/lib/models/query.js +3 -9
- package/lib/models/session.cjs +58 -0
- package/lib/models/session.js +12 -17
- package/lib/models/{web_chat.js → webchat.cjs} +14 -22
- package/lib/models/webchat.js +6 -13
- package/lib/vanilla.cjs +13 -0
- package/lib/vanilla.js +1 -13
- package/package.json +41 -7
- package/src/controllers/webchat_controller.js +72 -47
- package/src/hellotext.js +5 -4
- package/src/index.bundle.js +5 -0
- package/src/index.js +1 -3
- package/src/models/business.js +3 -6
- package/src/models/form_collection.js +10 -4
- package/src/models/session.js +4 -3
- package/styles/index.css +22 -30
- package/.babelrc +0 -24
- package/.github/workflows/ci.yml +0 -24
- package/.prettierignore +0 -3
- package/.prettierrc.json +0 -18
- package/MIT-LICENSE +0 -20
- package/__tests__/builders/input_builder_test.js +0 -117
- package/__tests__/core/configuration/forms_test.js +0 -30
- package/__tests__/core/configuration/webchat_test.js +0 -163
- package/__tests__/core/configuration_test.js +0 -28
- package/__tests__/core/event_test.js +0 -56
- package/__tests__/hellotext_test.js +0 -197
- package/__tests__/models/business_test.js +0 -26
- package/__tests__/models/cookies_test.js +0 -25
- package/__tests__/models/form_collection_test.js +0 -103
- package/__tests__/models/form_test.js +0 -131
- package/__tests__/models/query_test.js +0 -97
- package/docs/forms.md +0 -176
- package/docs/tracking.md +0 -203
- package/docs/webchat.md +0 -101
- package/jest.config.js +0 -4
- package/jest.setup.js +0 -16
- package/lib/api/web_chat/messages.js +0 -74
- package/lib/api/web_chats.js +0 -53
- package/webpack.config.js +0 -24
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.FormCollection = void 0;
|
|
7
|
+
var _forms = _interopRequireDefault(require("../api/forms"));
|
|
8
|
+
var _hellotext = _interopRequireDefault(require("../hellotext"));
|
|
9
|
+
var _core = require("../core");
|
|
10
|
+
var _form = require("./form");
|
|
11
|
+
var _errors = require("../errors");
|
|
12
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
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
|
+
function _classPrivateFieldLooseBase(receiver, privateKey) { if (!Object.prototype.hasOwnProperty.call(receiver, privateKey)) { throw new TypeError("attempted to use private field on non-instance"); } return receiver; }
|
|
19
|
+
var id = 0;
|
|
20
|
+
function _classPrivateFieldLooseKey(name) { return "__private_" + id++ + "_" + name; }
|
|
21
|
+
var _formIdsToFetch = /*#__PURE__*/_classPrivateFieldLooseKey("formIdsToFetch");
|
|
22
|
+
let FormCollection = /*#__PURE__*/function () {
|
|
23
|
+
function FormCollection() {
|
|
24
|
+
_classCallCheck(this, FormCollection);
|
|
25
|
+
Object.defineProperty(this, _formIdsToFetch, {
|
|
26
|
+
get: _get_formIdsToFetch,
|
|
27
|
+
set: void 0
|
|
28
|
+
});
|
|
29
|
+
this.forms = [];
|
|
30
|
+
this.includes = this.includes.bind(this);
|
|
31
|
+
this.excludes = this.excludes.bind(this);
|
|
32
|
+
this.add = this.add.bind(this);
|
|
33
|
+
if (typeof MutationObserver !== 'undefined') {
|
|
34
|
+
this.mutationObserver = new MutationObserver(this.formMutationObserver.bind(this));
|
|
35
|
+
this.mutationObserver.observe(document.body, {
|
|
36
|
+
childList: true,
|
|
37
|
+
subtree: true
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
_createClass(FormCollection, [{
|
|
42
|
+
key: "formMutationObserver",
|
|
43
|
+
value: function formMutationObserver(mutations) {
|
|
44
|
+
const mutation = mutations.find(mutation => mutation.type === 'childList' && mutation.addedNodes.length > 0);
|
|
45
|
+
if (!mutation) return;
|
|
46
|
+
const forms = Array.from(document.querySelectorAll('[data-hello-form]'));
|
|
47
|
+
if (forms && _core.Configuration.forms.autoMount) {
|
|
48
|
+
this.collect();
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}, {
|
|
52
|
+
key: "collect",
|
|
53
|
+
value: async function collect() {
|
|
54
|
+
if (_hellotext.default.notInitialized) {
|
|
55
|
+
throw new _errors.NotInitializedError();
|
|
56
|
+
}
|
|
57
|
+
if (this.fetching) return;
|
|
58
|
+
if (typeof document === 'undefined' || !('querySelectorAll' in document)) {
|
|
59
|
+
return console.warn('Document is not defined, collection is not possible. Please make sure to initialize the library after the document is loaded.');
|
|
60
|
+
}
|
|
61
|
+
const formsIdsToFetch = _classPrivateFieldLooseBase(this, _formIdsToFetch)[_formIdsToFetch];
|
|
62
|
+
if (formsIdsToFetch.length === 0) return;
|
|
63
|
+
const promises = formsIdsToFetch.map(id => {
|
|
64
|
+
return _forms.default.get(id).then(response => response.json());
|
|
65
|
+
});
|
|
66
|
+
if (!_hellotext.default.business.enabledWhitelist) {
|
|
67
|
+
console.warn('No whitelist has been configured. It is advised to whitelist the domain to avoid bots from submitting forms.');
|
|
68
|
+
}
|
|
69
|
+
this.fetching = true;
|
|
70
|
+
await Promise.all(promises).then(forms => forms.forEach(this.add)).then(() => _hellotext.default.eventEmitter.dispatch('forms:collected', this)).then(() => this.fetching = false);
|
|
71
|
+
if (_core.Configuration.forms.autoMount) {
|
|
72
|
+
this.forms.forEach(form => form.mount());
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}, {
|
|
76
|
+
key: "forEach",
|
|
77
|
+
value: function forEach(callback) {
|
|
78
|
+
this.forms.forEach(callback);
|
|
79
|
+
}
|
|
80
|
+
}, {
|
|
81
|
+
key: "map",
|
|
82
|
+
value: function map(callback) {
|
|
83
|
+
return this.forms.map(callback);
|
|
84
|
+
}
|
|
85
|
+
}, {
|
|
86
|
+
key: "add",
|
|
87
|
+
value: function add(data) {
|
|
88
|
+
if (this.includes(data.id)) return;
|
|
89
|
+
this.forms.push(new _form.Form(data));
|
|
90
|
+
}
|
|
91
|
+
}, {
|
|
92
|
+
key: "getById",
|
|
93
|
+
value: function getById(id) {
|
|
94
|
+
return this.forms.find(form => form.id === id);
|
|
95
|
+
}
|
|
96
|
+
}, {
|
|
97
|
+
key: "getByIndex",
|
|
98
|
+
value: function getByIndex(index) {
|
|
99
|
+
return this.forms[index];
|
|
100
|
+
}
|
|
101
|
+
}, {
|
|
102
|
+
key: "includes",
|
|
103
|
+
value: function includes(formId) {
|
|
104
|
+
return this.forms.some(form => form.id === formId);
|
|
105
|
+
}
|
|
106
|
+
}, {
|
|
107
|
+
key: "excludes",
|
|
108
|
+
value: function excludes(id) {
|
|
109
|
+
return !this.includes(id);
|
|
110
|
+
}
|
|
111
|
+
}, {
|
|
112
|
+
key: "length",
|
|
113
|
+
get: function () {
|
|
114
|
+
return this.forms.length;
|
|
115
|
+
}
|
|
116
|
+
}]);
|
|
117
|
+
return FormCollection;
|
|
118
|
+
}();
|
|
119
|
+
exports.FormCollection = FormCollection;
|
|
120
|
+
function _get_formIdsToFetch() {
|
|
121
|
+
return Array.from(document.querySelectorAll('[data-hello-form]')).map(form => form.dataset.helloForm).filter(this.excludes);
|
|
122
|
+
}
|
|
@@ -1,15 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.FormCollection = void 0;
|
|
7
|
-
var _hellotext = _interopRequireDefault(require("../hellotext"));
|
|
8
|
-
var _forms = _interopRequireDefault(require("../api/forms"));
|
|
9
|
-
var _core = require("../core");
|
|
10
|
-
var _form = require("./form");
|
|
11
|
-
var _errors = require("../errors");
|
|
12
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
1
|
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); } }
|
|
14
2
|
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); }); }; }
|
|
15
3
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
@@ -20,6 +8,11 @@ function _toPrimitive(input, hint) { if (typeof input !== "object" || input ===
|
|
|
20
8
|
function _classPrivateFieldLooseBase(receiver, privateKey) { if (!Object.prototype.hasOwnProperty.call(receiver, privateKey)) { throw new TypeError("attempted to use private field on non-instance"); } return receiver; }
|
|
21
9
|
var id = 0;
|
|
22
10
|
function _classPrivateFieldLooseKey(name) { return "__private_" + id++ + "_" + name; }
|
|
11
|
+
import API from '../api/forms';
|
|
12
|
+
import Hellotext from '../hellotext';
|
|
13
|
+
import { Configuration } from '../core';
|
|
14
|
+
import { Form } from './form';
|
|
15
|
+
import { NotInitializedError } from '../errors';
|
|
23
16
|
var _formIdsToFetch = /*#__PURE__*/_classPrivateFieldLooseKey("formIdsToFetch");
|
|
24
17
|
var FormCollection = /*#__PURE__*/function () {
|
|
25
18
|
function FormCollection() {
|
|
@@ -46,7 +39,7 @@ var FormCollection = /*#__PURE__*/function () {
|
|
|
46
39
|
var mutation = mutations.find(mutation => mutation.type === 'childList' && mutation.addedNodes.length > 0);
|
|
47
40
|
if (!mutation) return;
|
|
48
41
|
var forms = Array.from(document.querySelectorAll('[data-hello-form]'));
|
|
49
|
-
if (forms &&
|
|
42
|
+
if (forms && Configuration.forms.autoMount) {
|
|
50
43
|
this.collect();
|
|
51
44
|
}
|
|
52
45
|
}
|
|
@@ -54,21 +47,24 @@ var FormCollection = /*#__PURE__*/function () {
|
|
|
54
47
|
key: "collect",
|
|
55
48
|
value: function () {
|
|
56
49
|
var _collect = _asyncToGenerator(function* () {
|
|
57
|
-
if (
|
|
58
|
-
throw new
|
|
50
|
+
if (Hellotext.notInitialized) {
|
|
51
|
+
throw new NotInitializedError();
|
|
59
52
|
}
|
|
60
53
|
if (this.fetching) return;
|
|
54
|
+
if (typeof document === 'undefined' || !('querySelectorAll' in document)) {
|
|
55
|
+
return console.warn('Document is not defined, collection is not possible. Please make sure to initialize the library after the document is loaded.');
|
|
56
|
+
}
|
|
61
57
|
var formsIdsToFetch = _classPrivateFieldLooseBase(this, _formIdsToFetch)[_formIdsToFetch];
|
|
62
58
|
if (formsIdsToFetch.length === 0) return;
|
|
63
59
|
var promises = formsIdsToFetch.map(id => {
|
|
64
|
-
return
|
|
60
|
+
return API.get(id).then(response => response.json());
|
|
65
61
|
});
|
|
66
|
-
if (!
|
|
62
|
+
if (!Hellotext.business.enabledWhitelist) {
|
|
67
63
|
console.warn('No whitelist has been configured. It is advised to whitelist the domain to avoid bots from submitting forms.');
|
|
68
64
|
}
|
|
69
65
|
this.fetching = true;
|
|
70
|
-
yield Promise.all(promises).then(forms => forms.forEach(this.add)).then(() =>
|
|
71
|
-
if (
|
|
66
|
+
yield Promise.all(promises).then(forms => forms.forEach(this.add)).then(() => Hellotext.eventEmitter.dispatch('forms:collected', this)).then(() => this.fetching = false);
|
|
67
|
+
if (Configuration.forms.autoMount) {
|
|
72
68
|
this.forms.forEach(form => form.mount());
|
|
73
69
|
}
|
|
74
70
|
});
|
|
@@ -91,7 +87,7 @@ var FormCollection = /*#__PURE__*/function () {
|
|
|
91
87
|
key: "add",
|
|
92
88
|
value: function add(data) {
|
|
93
89
|
if (this.includes(data.id)) return;
|
|
94
|
-
this.forms.push(new
|
|
90
|
+
this.forms.push(new Form(data));
|
|
95
91
|
}
|
|
96
92
|
}, {
|
|
97
93
|
key: "getById",
|
|
@@ -121,7 +117,7 @@ var FormCollection = /*#__PURE__*/function () {
|
|
|
121
117
|
}]);
|
|
122
118
|
return FormCollection;
|
|
123
119
|
}();
|
|
124
|
-
exports.FormCollection = FormCollection;
|
|
125
120
|
function _get_formIdsToFetch() {
|
|
126
121
|
return Array.from(document.querySelectorAll('[data-hello-form]')).map(form => form.dataset.helloForm).filter(this.excludes);
|
|
127
|
-
}
|
|
122
|
+
}
|
|
123
|
+
export { FormCollection };
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "Business", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _business.Business;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
Object.defineProperty(exports, "Cookies", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () {
|
|
15
|
+
return _cookies.Cookies;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
Object.defineProperty(exports, "Form", {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: function () {
|
|
21
|
+
return _form.Form;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
Object.defineProperty(exports, "FormCollection", {
|
|
25
|
+
enumerable: true,
|
|
26
|
+
get: function () {
|
|
27
|
+
return _form_collection.FormCollection;
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
Object.defineProperty(exports, "Query", {
|
|
31
|
+
enumerable: true,
|
|
32
|
+
get: function () {
|
|
33
|
+
return _query.Query;
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
Object.defineProperty(exports, "Session", {
|
|
37
|
+
enumerable: true,
|
|
38
|
+
get: function () {
|
|
39
|
+
return _session.Session;
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
Object.defineProperty(exports, "Webchat", {
|
|
43
|
+
enumerable: true,
|
|
44
|
+
get: function () {
|
|
45
|
+
return _webchat.Webchat;
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
var _business = require("./business");
|
|
49
|
+
var _form = require("./form");
|
|
50
|
+
var _query = require("./query");
|
|
51
|
+
var _cookies = require("./cookies");
|
|
52
|
+
var _form_collection = require("./form_collection");
|
|
53
|
+
var _webchat = require("./webchat");
|
|
54
|
+
var _session = require("./session");
|
package/lib/models/index.js
CHANGED
|
@@ -1,54 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
|
|
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
|
-
Object.defineProperty(exports, "Session", {
|
|
37
|
-
enumerable: true,
|
|
38
|
-
get: function get() {
|
|
39
|
-
return _session.Session;
|
|
40
|
-
}
|
|
41
|
-
});
|
|
42
|
-
Object.defineProperty(exports, "Webchat", {
|
|
43
|
-
enumerable: true,
|
|
44
|
-
get: function get() {
|
|
45
|
-
return _webchat.Webchat;
|
|
46
|
-
}
|
|
47
|
-
});
|
|
48
|
-
var _business = require("./business");
|
|
49
|
-
var _form = require("./form");
|
|
50
|
-
var _query = require("./query");
|
|
51
|
-
var _cookies = require("./cookies");
|
|
52
|
-
var _form_collection = require("./form_collection");
|
|
53
|
-
var _webchat = require("./webchat");
|
|
54
|
-
var _session = require("./session");
|
|
1
|
+
export { Business } from './business';
|
|
2
|
+
export { Form } from './form';
|
|
3
|
+
export { Query } from './query';
|
|
4
|
+
export { Cookies } from './cookies';
|
|
5
|
+
export { FormCollection } from './form_collection';
|
|
6
|
+
export { Webchat } from './webchat';
|
|
7
|
+
export { Session } from './session';
|
|
@@ -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
|
+
let 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 () {
|
|
31
|
+
return this.has('preview');
|
|
32
|
+
}
|
|
33
|
+
}, {
|
|
34
|
+
key: "session",
|
|
35
|
+
get: function () {
|
|
36
|
+
return this.get('session') || _cookies.Cookies.get('hello_session');
|
|
37
|
+
}
|
|
38
|
+
}, {
|
|
39
|
+
key: "toHellotextParam",
|
|
40
|
+
value: function toHellotextParam(param) {
|
|
41
|
+
return `hello_${param}`;
|
|
42
|
+
}
|
|
43
|
+
}], [{
|
|
44
|
+
key: "inPreviewMode",
|
|
45
|
+
get: function () {
|
|
46
|
+
return new this().inPreviewMode;
|
|
47
|
+
}
|
|
48
|
+
}]);
|
|
49
|
+
return Query;
|
|
50
|
+
}();
|
|
51
|
+
exports.Query = Query;
|
package/lib/models/query.js
CHANGED
|
@@ -1,15 +1,9 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.Query = void 0;
|
|
7
|
-
var _cookies = require("./cookies");
|
|
8
1
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
9
2
|
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
3
|
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
4
|
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
12
5
|
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); }
|
|
6
|
+
import { Cookies } from './cookies';
|
|
13
7
|
var Query = /*#__PURE__*/function () {
|
|
14
8
|
function Query() {
|
|
15
9
|
_classCallCheck(this, Query);
|
|
@@ -33,7 +27,7 @@ var Query = /*#__PURE__*/function () {
|
|
|
33
27
|
}, {
|
|
34
28
|
key: "session",
|
|
35
29
|
get: function get() {
|
|
36
|
-
return this.get('session') ||
|
|
30
|
+
return this.get('session') || Cookies.get('hello_session');
|
|
37
31
|
}
|
|
38
32
|
}, {
|
|
39
33
|
key: "toHellotextParam",
|
|
@@ -48,4 +42,4 @@ var Query = /*#__PURE__*/function () {
|
|
|
48
42
|
}]);
|
|
49
43
|
return Query;
|
|
50
44
|
}();
|
|
51
|
-
|
|
45
|
+
export { Query };
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.Session = void 0;
|
|
7
|
+
var _core = require("../core");
|
|
8
|
+
var _cookies = require("./cookies");
|
|
9
|
+
var _query2 = require("./query");
|
|
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
|
+
function _classPrivateFieldLooseBase(receiver, privateKey) { if (!Object.prototype.hasOwnProperty.call(receiver, privateKey)) { throw new TypeError("attempted to use private field on non-instance"); } return receiver; }
|
|
16
|
+
var id = 0;
|
|
17
|
+
function _classPrivateFieldLooseKey(name) { return "__private_" + id++ + "_" + name; }
|
|
18
|
+
var _session = /*#__PURE__*/_classPrivateFieldLooseKey("session");
|
|
19
|
+
var _query = /*#__PURE__*/_classPrivateFieldLooseKey("query");
|
|
20
|
+
let Session = /*#__PURE__*/function () {
|
|
21
|
+
function Session() {
|
|
22
|
+
_classCallCheck(this, Session);
|
|
23
|
+
}
|
|
24
|
+
_createClass(Session, null, [{
|
|
25
|
+
key: "session",
|
|
26
|
+
get: function () {
|
|
27
|
+
return _classPrivateFieldLooseBase(this, _session)[_session];
|
|
28
|
+
},
|
|
29
|
+
set: function (value) {
|
|
30
|
+
_classPrivateFieldLooseBase(this, _session)[_session] = value;
|
|
31
|
+
_cookies.Cookies.set('hello_session', value);
|
|
32
|
+
}
|
|
33
|
+
}, {
|
|
34
|
+
key: "initialize",
|
|
35
|
+
value: function initialize() {
|
|
36
|
+
_classPrivateFieldLooseBase(this, _query)[_query] = new _query2.Query();
|
|
37
|
+
if (_core.Configuration.session) {
|
|
38
|
+
this.session = _core.Configuration.session;
|
|
39
|
+
} else if (_classPrivateFieldLooseBase(this, _query)[_query].session) {
|
|
40
|
+
this.session = _classPrivateFieldLooseBase(this, _query)[_query].session;
|
|
41
|
+
} else if (_cookies.Cookies.get('hello_session')) {
|
|
42
|
+
this.session = _cookies.Cookies.get('hello_session');
|
|
43
|
+
} else if (_core.Configuration.autoGenerateSession) {
|
|
44
|
+
this.session = crypto.randomUUID();
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}]);
|
|
48
|
+
return Session;
|
|
49
|
+
}();
|
|
50
|
+
exports.Session = Session;
|
|
51
|
+
Object.defineProperty(Session, _session, {
|
|
52
|
+
writable: true,
|
|
53
|
+
value: void 0
|
|
54
|
+
});
|
|
55
|
+
Object.defineProperty(Session, _query, {
|
|
56
|
+
writable: true,
|
|
57
|
+
value: void 0
|
|
58
|
+
});
|
package/lib/models/session.js
CHANGED
|
@@ -1,11 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.Session = void 0;
|
|
7
|
-
var _core = require("../core");
|
|
8
|
-
var _index = require("./index");
|
|
9
1
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
10
2
|
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
3
|
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
@@ -14,6 +6,9 @@ function _toPrimitive(input, hint) { if (typeof input !== "object" || input ===
|
|
|
14
6
|
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
7
|
var id = 0;
|
|
16
8
|
function _classPrivateFieldLooseKey(name) { return "__private_" + id++ + "_" + name; }
|
|
9
|
+
import { Configuration } from '../core';
|
|
10
|
+
import { Cookies } from './cookies';
|
|
11
|
+
import { Query } from './query';
|
|
17
12
|
var _session = /*#__PURE__*/_classPrivateFieldLooseKey("session");
|
|
18
13
|
var _query = /*#__PURE__*/_classPrivateFieldLooseKey("query");
|
|
19
14
|
var Session = /*#__PURE__*/function () {
|
|
@@ -27,26 +22,25 @@ var Session = /*#__PURE__*/function () {
|
|
|
27
22
|
},
|
|
28
23
|
set: function set(value) {
|
|
29
24
|
_classPrivateFieldLooseBase(this, _session)[_session] = value;
|
|
30
|
-
|
|
25
|
+
Cookies.set('hello_session', value);
|
|
31
26
|
}
|
|
32
27
|
}, {
|
|
33
28
|
key: "initialize",
|
|
34
29
|
value: function initialize() {
|
|
35
|
-
_classPrivateFieldLooseBase(this, _query)[_query] = new
|
|
36
|
-
if (
|
|
37
|
-
this.session =
|
|
30
|
+
_classPrivateFieldLooseBase(this, _query)[_query] = new Query();
|
|
31
|
+
if (Configuration.session) {
|
|
32
|
+
this.session = Configuration.session;
|
|
38
33
|
} else if (_classPrivateFieldLooseBase(this, _query)[_query].session) {
|
|
39
34
|
this.session = _classPrivateFieldLooseBase(this, _query)[_query].session;
|
|
40
|
-
} else if (
|
|
41
|
-
this.session =
|
|
42
|
-
} else if (
|
|
35
|
+
} else if (Cookies.get('hello_session')) {
|
|
36
|
+
this.session = Cookies.get('hello_session');
|
|
37
|
+
} else if (Configuration.autoGenerateSession) {
|
|
43
38
|
this.session = crypto.randomUUID();
|
|
44
39
|
}
|
|
45
40
|
}
|
|
46
41
|
}]);
|
|
47
42
|
return Session;
|
|
48
43
|
}();
|
|
49
|
-
exports.Session = Session;
|
|
50
44
|
Object.defineProperty(Session, _session, {
|
|
51
45
|
writable: true,
|
|
52
46
|
value: void 0
|
|
@@ -54,4 +48,5 @@ Object.defineProperty(Session, _session, {
|
|
|
54
48
|
Object.defineProperty(Session, _query, {
|
|
55
49
|
writable: true,
|
|
56
50
|
value: void 0
|
|
57
|
-
});
|
|
51
|
+
});
|
|
52
|
+
export { Session };
|
|
@@ -3,49 +3,41 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
6
|
+
exports.Webchat = void 0;
|
|
7
7
|
var _hellotext = _interopRequireDefault(require("../hellotext"));
|
|
8
8
|
var _core = require("../core");
|
|
9
9
|
var _api = _interopRequireDefault(require("../api"));
|
|
10
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
11
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
14
12
|
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
13
|
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
14
|
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
17
15
|
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
|
-
|
|
19
|
-
function
|
|
20
|
-
_classCallCheck(this,
|
|
16
|
+
let Webchat = /*#__PURE__*/function () {
|
|
17
|
+
function Webchat(data) {
|
|
18
|
+
_classCallCheck(this, Webchat);
|
|
21
19
|
this.data = data;
|
|
22
20
|
this.render();
|
|
23
21
|
}
|
|
24
|
-
_createClass(
|
|
22
|
+
_createClass(Webchat, [{
|
|
25
23
|
key: "render",
|
|
26
24
|
value: function render() {
|
|
27
25
|
this.containerToAppendTo.appendChild(this.data.html);
|
|
28
26
|
}
|
|
29
27
|
}, {
|
|
30
28
|
key: "containerToAppendTo",
|
|
31
|
-
get: function
|
|
32
|
-
return document.querySelector(_core.Configuration.
|
|
29
|
+
get: function () {
|
|
30
|
+
return document.querySelector(_core.Configuration.webchat.container);
|
|
33
31
|
}
|
|
34
32
|
}], [{
|
|
35
33
|
key: "load",
|
|
36
|
-
value: function () {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
html: yield _api.default.webChats.get(id)
|
|
41
|
-
});
|
|
34
|
+
value: async function load(id) {
|
|
35
|
+
return new Webchat({
|
|
36
|
+
id,
|
|
37
|
+
html: await _api.default.webchats.get(id)
|
|
42
38
|
});
|
|
43
|
-
|
|
44
|
-
return _load.apply(this, arguments);
|
|
45
|
-
}
|
|
46
|
-
return load;
|
|
47
|
-
}()
|
|
39
|
+
}
|
|
48
40
|
}]);
|
|
49
|
-
return
|
|
41
|
+
return Webchat;
|
|
50
42
|
}();
|
|
51
|
-
exports.
|
|
43
|
+
exports.Webchat = Webchat;
|
package/lib/models/webchat.js
CHANGED
|
@@ -1,13 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.Webchat = void 0;
|
|
7
|
-
var _hellotext = _interopRequireDefault(require("../hellotext"));
|
|
8
|
-
var _core = require("../core");
|
|
9
|
-
var _api = _interopRequireDefault(require("../api"));
|
|
10
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
1
|
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
2
|
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
3
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
@@ -15,6 +5,9 @@ function _defineProperties(target, props) { for (var i = 0; i < props.length; i+
|
|
|
15
5
|
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
6
|
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
17
7
|
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); }
|
|
8
|
+
import Hellotext from '../hellotext';
|
|
9
|
+
import { Configuration } from '../core';
|
|
10
|
+
import API from '../api';
|
|
18
11
|
var Webchat = /*#__PURE__*/function () {
|
|
19
12
|
function Webchat(data) {
|
|
20
13
|
_classCallCheck(this, Webchat);
|
|
@@ -29,7 +22,7 @@ var Webchat = /*#__PURE__*/function () {
|
|
|
29
22
|
}, {
|
|
30
23
|
key: "containerToAppendTo",
|
|
31
24
|
get: function get() {
|
|
32
|
-
return document.querySelector(
|
|
25
|
+
return document.querySelector(Configuration.webchat.container);
|
|
33
26
|
}
|
|
34
27
|
}], [{
|
|
35
28
|
key: "load",
|
|
@@ -37,7 +30,7 @@ var Webchat = /*#__PURE__*/function () {
|
|
|
37
30
|
var _load = _asyncToGenerator(function* (id) {
|
|
38
31
|
return new Webchat({
|
|
39
32
|
id,
|
|
40
|
-
html: yield
|
|
33
|
+
html: yield API.webchats.get(id)
|
|
41
34
|
});
|
|
42
35
|
});
|
|
43
36
|
function load(_x) {
|
|
@@ -48,4 +41,4 @@ var Webchat = /*#__PURE__*/function () {
|
|
|
48
41
|
}]);
|
|
49
42
|
return Webchat;
|
|
50
43
|
}();
|
|
51
|
-
|
|
44
|
+
export { Webchat };
|
package/lib/vanilla.cjs
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "default", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _hellotext.default;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
var _hellotext = _interopRequireDefault(require("./hellotext"));
|
|
13
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|