@hellotext/hellotext 2.0.4 → 2.0.6
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/dist/hellotext.js +1 -1
- package/lib/api/webchats.cjs +6 -3
- package/lib/api/webchats.js +6 -3
- package/lib/hellotext.cjs +1 -2
- package/lib/hellotext.js +1 -2
- package/lib/models/business.cjs +12 -15
- package/lib/models/business.js +12 -23
- package/lib/models/form_collection.cjs +6 -3
- package/lib/models/form_collection.js +6 -3
- package/lib/models/webchat.cjs +0 -1
- package/lib/models/webchat.js +0 -1
- package/package.json +1 -1
- package/src/api/webchats.js +8 -3
- package/src/hellotext.js +1 -3
- package/src/models/business.js +13 -19
- package/src/models/form_collection.js +11 -6
- package/src/models/webchat.js +1 -2
package/lib/api/webchats.cjs
CHANGED
|
@@ -4,8 +4,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
var _hellotext = _interopRequireDefault(require("../hellotext"));
|
|
8
7
|
var _core = require("../core");
|
|
8
|
+
var _hellotext = _interopRequireDefault(require("../hellotext"));
|
|
9
9
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
10
10
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
11
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); } }
|
|
@@ -34,8 +34,11 @@ let WebchatsAPI = /*#__PURE__*/function () {
|
|
|
34
34
|
method: 'GET',
|
|
35
35
|
headers: _hellotext.default.headers
|
|
36
36
|
});
|
|
37
|
-
const
|
|
38
|
-
|
|
37
|
+
const data = await response.json();
|
|
38
|
+
if (!_hellotext.default.business.data) {
|
|
39
|
+
_hellotext.default.business.setData(data.business);
|
|
40
|
+
}
|
|
41
|
+
return new DOMParser().parseFromString(data.html, 'text/html').querySelector('article');
|
|
39
42
|
}
|
|
40
43
|
}]);
|
|
41
44
|
return WebchatsAPI;
|
package/lib/api/webchats.js
CHANGED
|
@@ -5,8 +5,8 @@ function _defineProperties(target, props) { for (var i = 0; i < props.length; i+
|
|
|
5
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; }
|
|
6
6
|
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
7
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
8
|
import { Configuration } from '../core';
|
|
9
|
+
import Hellotext from '../hellotext';
|
|
10
10
|
var WebchatsAPI = /*#__PURE__*/function () {
|
|
11
11
|
function WebchatsAPI() {
|
|
12
12
|
_classCallCheck(this, WebchatsAPI);
|
|
@@ -31,8 +31,11 @@ var WebchatsAPI = /*#__PURE__*/function () {
|
|
|
31
31
|
method: 'GET',
|
|
32
32
|
headers: Hellotext.headers
|
|
33
33
|
});
|
|
34
|
-
var
|
|
35
|
-
|
|
34
|
+
var data = yield response.json();
|
|
35
|
+
if (!Hellotext.business.data) {
|
|
36
|
+
Hellotext.business.setData(data.business);
|
|
37
|
+
}
|
|
38
|
+
return new DOMParser().parseFromString(data.html, 'text/html').querySelector('article');
|
|
36
39
|
});
|
|
37
40
|
function get(_x) {
|
|
38
41
|
return _get.apply(this, arguments);
|
package/lib/hellotext.cjs
CHANGED
|
@@ -33,11 +33,10 @@ let Hellotext = /*#__PURE__*/function () {
|
|
|
33
33
|
* @param { Configuration } config
|
|
34
34
|
*/
|
|
35
35
|
async function initialize(business, config) {
|
|
36
|
-
this.forms = new _models.FormCollection();
|
|
37
36
|
this.business = new _models.Business(business);
|
|
37
|
+
this.forms = new _models.FormCollection();
|
|
38
38
|
_core.Configuration.assign(config);
|
|
39
39
|
_models.Session.initialize();
|
|
40
|
-
this.business.fetchPublicData().then(() => this.forms.collect());
|
|
41
40
|
_classPrivateFieldLooseBase(this, _query)[_query] = new _models.Query();
|
|
42
41
|
if (_core.Configuration.webchat.id) {
|
|
43
42
|
this.webchat = await _models.Webchat.load(_core.Configuration.webchat.id);
|
package/lib/hellotext.js
CHANGED
|
@@ -31,11 +31,10 @@ var Hellotext = /*#__PURE__*/function () {
|
|
|
31
31
|
*/
|
|
32
32
|
function () {
|
|
33
33
|
var _initialize = _asyncToGenerator(function* (business, config) {
|
|
34
|
-
this.forms = new FormCollection();
|
|
35
34
|
this.business = new Business(business);
|
|
35
|
+
this.forms = new FormCollection();
|
|
36
36
|
Configuration.assign(config);
|
|
37
37
|
Session.initialize();
|
|
38
|
-
this.business.fetchPublicData().then(() => this.forms.collect());
|
|
39
38
|
_classPrivateFieldLooseBase(this, _query)[_query] = new Query();
|
|
40
39
|
if (Configuration.webchat.id) {
|
|
41
40
|
this.webchat = yield Webchat.load(Configuration.webchat.id);
|
package/lib/models/business.cjs
CHANGED
|
@@ -4,7 +4,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.Business = void 0;
|
|
7
|
-
var _businesses = _interopRequireDefault(require("../api/businesses"));
|
|
8
7
|
var _locales = _interopRequireDefault(require("../locales"));
|
|
9
8
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
10
9
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
@@ -16,9 +15,20 @@ let Business = /*#__PURE__*/function () {
|
|
|
16
15
|
function Business(id) {
|
|
17
16
|
_classCallCheck(this, Business);
|
|
18
17
|
this.id = id;
|
|
19
|
-
this.data =
|
|
18
|
+
this.data = null;
|
|
20
19
|
}
|
|
21
20
|
_createClass(Business, [{
|
|
21
|
+
key: "setData",
|
|
22
|
+
value: function setData(data) {
|
|
23
|
+
this.data = data;
|
|
24
|
+
if (typeof document !== 'undefined') {
|
|
25
|
+
const linkTag = document.createElement('link');
|
|
26
|
+
linkTag.rel = 'stylesheet';
|
|
27
|
+
linkTag.href = data.style_url;
|
|
28
|
+
document.head.append(linkTag);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}, {
|
|
22
32
|
key: "subscription",
|
|
23
33
|
get: function () {
|
|
24
34
|
return this.data.subscription;
|
|
@@ -43,19 +53,6 @@ let Business = /*#__PURE__*/function () {
|
|
|
43
53
|
get: function () {
|
|
44
54
|
return this.data.features;
|
|
45
55
|
}
|
|
46
|
-
}, {
|
|
47
|
-
key: "fetchPublicData",
|
|
48
|
-
value: async function fetchPublicData() {
|
|
49
|
-
return _businesses.default.get(this.id).then(response => response.json()).then(data => {
|
|
50
|
-
this.data = data;
|
|
51
|
-
if (typeof document !== 'undefined') {
|
|
52
|
-
const linkTag = document.createElement('link');
|
|
53
|
-
linkTag.rel = 'stylesheet';
|
|
54
|
-
linkTag.href = data.style_url;
|
|
55
|
-
document.head.append(linkTag);
|
|
56
|
-
}
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
56
|
}]);
|
|
60
57
|
return Business;
|
|
61
58
|
}();
|
package/lib/models/business.js
CHANGED
|
@@ -1,19 +1,27 @@
|
|
|
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); } }
|
|
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); }); }; }
|
|
3
1
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
4
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); } }
|
|
5
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; }
|
|
6
4
|
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
7
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); }
|
|
8
|
-
import API from '../api/businesses';
|
|
9
6
|
import locales from '../locales';
|
|
10
7
|
var Business = /*#__PURE__*/function () {
|
|
11
8
|
function Business(id) {
|
|
12
9
|
_classCallCheck(this, Business);
|
|
13
10
|
this.id = id;
|
|
14
|
-
this.data =
|
|
11
|
+
this.data = null;
|
|
15
12
|
}
|
|
16
13
|
_createClass(Business, [{
|
|
14
|
+
key: "setData",
|
|
15
|
+
value: function setData(data) {
|
|
16
|
+
this.data = data;
|
|
17
|
+
if (typeof document !== 'undefined') {
|
|
18
|
+
var linkTag = document.createElement('link');
|
|
19
|
+
linkTag.rel = 'stylesheet';
|
|
20
|
+
linkTag.href = data.style_url;
|
|
21
|
+
document.head.append(linkTag);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}, {
|
|
17
25
|
key: "subscription",
|
|
18
26
|
get: function get() {
|
|
19
27
|
return this.data.subscription;
|
|
@@ -38,25 +46,6 @@ var Business = /*#__PURE__*/function () {
|
|
|
38
46
|
get: function get() {
|
|
39
47
|
return this.data.features;
|
|
40
48
|
}
|
|
41
|
-
}, {
|
|
42
|
-
key: "fetchPublicData",
|
|
43
|
-
value: function () {
|
|
44
|
-
var _fetchPublicData = _asyncToGenerator(function* () {
|
|
45
|
-
return API.get(this.id).then(response => response.json()).then(data => {
|
|
46
|
-
this.data = data;
|
|
47
|
-
if (typeof document !== 'undefined') {
|
|
48
|
-
var linkTag = document.createElement('link');
|
|
49
|
-
linkTag.rel = 'stylesheet';
|
|
50
|
-
linkTag.href = data.style_url;
|
|
51
|
-
document.head.append(linkTag);
|
|
52
|
-
}
|
|
53
|
-
});
|
|
54
|
-
});
|
|
55
|
-
function fetchPublicData() {
|
|
56
|
-
return _fetchPublicData.apply(this, arguments);
|
|
57
|
-
}
|
|
58
|
-
return fetchPublicData;
|
|
59
|
-
}()
|
|
60
49
|
}]);
|
|
61
50
|
return Business;
|
|
62
51
|
}();
|
|
@@ -63,9 +63,6 @@ let FormCollection = /*#__PURE__*/function () {
|
|
|
63
63
|
const promises = formsIdsToFetch.map(id => {
|
|
64
64
|
return _forms.default.get(id).then(response => response.json());
|
|
65
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
66
|
this.fetching = true;
|
|
70
67
|
await Promise.all(promises).then(forms => forms.forEach(this.add)).then(() => _hellotext.default.eventEmitter.dispatch('forms:collected', this)).then(() => this.fetching = false);
|
|
71
68
|
if (_core.Configuration.forms.autoMount) {
|
|
@@ -87,6 +84,12 @@ let FormCollection = /*#__PURE__*/function () {
|
|
|
87
84
|
value: function add(data) {
|
|
88
85
|
if (this.includes(data.id)) return;
|
|
89
86
|
this.forms.push(new _form.Form(data));
|
|
87
|
+
if (!_hellotext.default.business.data) {
|
|
88
|
+
_hellotext.default.business.setData(data.business);
|
|
89
|
+
}
|
|
90
|
+
if (!_hellotext.default.business.enabledWhitelist) {
|
|
91
|
+
console.warn('No whitelist has been configured. It is advised to whitelist the domain to avoid bots from submitting forms.');
|
|
92
|
+
}
|
|
90
93
|
}
|
|
91
94
|
}, {
|
|
92
95
|
key: "getById",
|
|
@@ -59,9 +59,6 @@ var FormCollection = /*#__PURE__*/function () {
|
|
|
59
59
|
var promises = formsIdsToFetch.map(id => {
|
|
60
60
|
return API.get(id).then(response => response.json());
|
|
61
61
|
});
|
|
62
|
-
if (!Hellotext.business.enabledWhitelist) {
|
|
63
|
-
console.warn('No whitelist has been configured. It is advised to whitelist the domain to avoid bots from submitting forms.');
|
|
64
|
-
}
|
|
65
62
|
this.fetching = true;
|
|
66
63
|
yield Promise.all(promises).then(forms => forms.forEach(this.add)).then(() => Hellotext.eventEmitter.dispatch('forms:collected', this)).then(() => this.fetching = false);
|
|
67
64
|
if (Configuration.forms.autoMount) {
|
|
@@ -88,6 +85,12 @@ var FormCollection = /*#__PURE__*/function () {
|
|
|
88
85
|
value: function add(data) {
|
|
89
86
|
if (this.includes(data.id)) return;
|
|
90
87
|
this.forms.push(new Form(data));
|
|
88
|
+
if (!Hellotext.business.data) {
|
|
89
|
+
Hellotext.business.setData(data.business);
|
|
90
|
+
}
|
|
91
|
+
if (!Hellotext.business.enabledWhitelist) {
|
|
92
|
+
console.warn('No whitelist has been configured. It is advised to whitelist the domain to avoid bots from submitting forms.');
|
|
93
|
+
}
|
|
91
94
|
}
|
|
92
95
|
}, {
|
|
93
96
|
key: "getById",
|
package/lib/models/webchat.cjs
CHANGED
|
@@ -4,7 +4,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.Webchat = void 0;
|
|
7
|
-
var _hellotext = _interopRequireDefault(require("../hellotext"));
|
|
8
7
|
var _core = require("../core");
|
|
9
8
|
var _api = _interopRequireDefault(require("../api"));
|
|
10
9
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
package/lib/models/webchat.js
CHANGED
|
@@ -5,7 +5,6 @@ function _defineProperties(target, props) { for (var i = 0; i < props.length; i+
|
|
|
5
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; }
|
|
6
6
|
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
7
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
8
|
import { Configuration } from '../core';
|
|
10
9
|
import API from '../api';
|
|
11
10
|
var Webchat = /*#__PURE__*/function () {
|
package/package.json
CHANGED
package/src/api/webchats.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import Hellotext from '../hellotext'
|
|
2
1
|
import { Configuration } from '../core'
|
|
2
|
+
import Hellotext from '../hellotext'
|
|
3
3
|
|
|
4
4
|
class WebchatsAPI {
|
|
5
5
|
static get endpoint() {
|
|
@@ -22,8 +22,13 @@ class WebchatsAPI {
|
|
|
22
22
|
headers: Hellotext.headers,
|
|
23
23
|
})
|
|
24
24
|
|
|
25
|
-
const
|
|
26
|
-
|
|
25
|
+
const data = await response.json()
|
|
26
|
+
|
|
27
|
+
if (!Hellotext.business.data) {
|
|
28
|
+
Hellotext.business.setData(data.business)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return new DOMParser().parseFromString(data.html, 'text/html').querySelector('article')
|
|
27
32
|
}
|
|
28
33
|
}
|
|
29
34
|
|
package/src/hellotext.js
CHANGED
|
@@ -20,14 +20,12 @@ class Hellotext {
|
|
|
20
20
|
* @param { Configuration } config
|
|
21
21
|
*/
|
|
22
22
|
static async initialize(business, config) {
|
|
23
|
-
this.forms = new FormCollection()
|
|
24
23
|
this.business = new Business(business)
|
|
24
|
+
this.forms = new FormCollection()
|
|
25
25
|
|
|
26
26
|
Configuration.assign(config)
|
|
27
27
|
Session.initialize()
|
|
28
28
|
|
|
29
|
-
this.business.fetchPublicData().then(() => this.forms.collect())
|
|
30
|
-
|
|
31
29
|
this.#query = new Query()
|
|
32
30
|
|
|
33
31
|
if (Configuration.webchat.id) {
|
package/src/models/business.js
CHANGED
|
@@ -1,11 +1,21 @@
|
|
|
1
|
-
import API from '../api/businesses'
|
|
2
|
-
|
|
3
1
|
import locales from '../locales'
|
|
4
2
|
|
|
5
3
|
class Business {
|
|
6
4
|
constructor(id) {
|
|
7
5
|
this.id = id
|
|
8
|
-
this.data =
|
|
6
|
+
this.data = null
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
setData(data) {
|
|
10
|
+
this.data = data
|
|
11
|
+
|
|
12
|
+
if (typeof document !== 'undefined') {
|
|
13
|
+
const linkTag = document.createElement('link')
|
|
14
|
+
linkTag.rel = 'stylesheet'
|
|
15
|
+
linkTag.href = data.style_url
|
|
16
|
+
|
|
17
|
+
document.head.append(linkTag)
|
|
18
|
+
}
|
|
9
19
|
}
|
|
10
20
|
|
|
11
21
|
get subscription() {
|
|
@@ -27,22 +37,6 @@ class Business {
|
|
|
27
37
|
get features() {
|
|
28
38
|
return this.data.features
|
|
29
39
|
}
|
|
30
|
-
|
|
31
|
-
async fetchPublicData() {
|
|
32
|
-
return API.get(this.id)
|
|
33
|
-
.then(response => response.json())
|
|
34
|
-
.then(data => {
|
|
35
|
-
this.data = data
|
|
36
|
-
|
|
37
|
-
if (typeof document !== 'undefined') {
|
|
38
|
-
const linkTag = document.createElement('link')
|
|
39
|
-
linkTag.rel = 'stylesheet'
|
|
40
|
-
linkTag.href = data.style_url
|
|
41
|
-
|
|
42
|
-
document.head.append(linkTag)
|
|
43
|
-
}
|
|
44
|
-
})
|
|
45
|
-
}
|
|
46
40
|
}
|
|
47
41
|
|
|
48
42
|
export { Business }
|
|
@@ -55,12 +55,6 @@ class FormCollection {
|
|
|
55
55
|
return API.get(id).then(response => response.json())
|
|
56
56
|
})
|
|
57
57
|
|
|
58
|
-
if (!Hellotext.business.enabledWhitelist) {
|
|
59
|
-
console.warn(
|
|
60
|
-
'No whitelist has been configured. It is advised to whitelist the domain to avoid bots from submitting forms.',
|
|
61
|
-
)
|
|
62
|
-
}
|
|
63
|
-
|
|
64
58
|
this.fetching = true
|
|
65
59
|
|
|
66
60
|
await Promise.all(promises)
|
|
@@ -83,7 +77,18 @@ class FormCollection {
|
|
|
83
77
|
|
|
84
78
|
add(data) {
|
|
85
79
|
if (this.includes(data.id)) return
|
|
80
|
+
|
|
86
81
|
this.forms.push(new Form(data))
|
|
82
|
+
|
|
83
|
+
if (!Hellotext.business.data) {
|
|
84
|
+
Hellotext.business.setData(data.business)
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
if (!Hellotext.business.enabledWhitelist) {
|
|
88
|
+
console.warn(
|
|
89
|
+
'No whitelist has been configured. It is advised to whitelist the domain to avoid bots from submitting forms.',
|
|
90
|
+
)
|
|
91
|
+
}
|
|
87
92
|
}
|
|
88
93
|
|
|
89
94
|
getById(id) {
|