@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
|
@@ -1,16 +1,11 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.Configuration = void 0;
|
|
7
|
-
var _forms = require("./configuration/forms");
|
|
8
|
-
var _webchat = require("./configuration/webchat");
|
|
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; }
|
|
12
4
|
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
13
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 { Forms } from './configuration/forms';
|
|
7
|
+
import { Webchat } from './configuration/webchat';
|
|
8
|
+
|
|
14
9
|
/**
|
|
15
10
|
* @class Configuration
|
|
16
11
|
* @classdesc
|
|
@@ -40,9 +35,9 @@ var Configuration = /*#__PURE__*/function () {
|
|
|
40
35
|
Object.entries(props).forEach(_ref => {
|
|
41
36
|
var [key, value] = _ref;
|
|
42
37
|
if (key === 'forms') {
|
|
43
|
-
this.forms =
|
|
38
|
+
this.forms = Forms.assign(value);
|
|
44
39
|
} else if (key === 'webChat') {
|
|
45
|
-
this.webchat =
|
|
40
|
+
this.webchat = Webchat.assign(value);
|
|
46
41
|
} else {
|
|
47
42
|
this[key] = value;
|
|
48
43
|
}
|
|
@@ -58,9 +53,9 @@ var Configuration = /*#__PURE__*/function () {
|
|
|
58
53
|
}]);
|
|
59
54
|
return Configuration;
|
|
60
55
|
}();
|
|
61
|
-
exports.Configuration = Configuration;
|
|
62
56
|
Configuration.apiRoot = 'https://api.hellotext.com/v1';
|
|
63
57
|
Configuration.autoGenerateSession = true;
|
|
64
58
|
Configuration.session = null;
|
|
65
|
-
Configuration.forms =
|
|
66
|
-
Configuration.webchat =
|
|
59
|
+
Configuration.forms = Forms;
|
|
60
|
+
Configuration.webchat = Webchat;
|
|
61
|
+
export { Configuration };
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _errors = require("../errors");
|
|
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 Event = /*#__PURE__*/function () {
|
|
14
|
+
function Event() {
|
|
15
|
+
_classCallCheck(this, Event);
|
|
16
|
+
this.subscribers = {};
|
|
17
|
+
}
|
|
18
|
+
_createClass(Event, [{
|
|
19
|
+
key: "addSubscriber",
|
|
20
|
+
value: function addSubscriber(eventName, callback) {
|
|
21
|
+
if (Event.invalid(eventName)) {
|
|
22
|
+
throw new _errors.InvalidEvent(eventName);
|
|
23
|
+
}
|
|
24
|
+
this.subscribers = {
|
|
25
|
+
...this.subscribers,
|
|
26
|
+
[eventName]: this.subscribers[eventName] ? [...this.subscribers[eventName], callback] : [callback]
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
}, {
|
|
30
|
+
key: "removeSubscriber",
|
|
31
|
+
value: function removeSubscriber(eventName, callback) {
|
|
32
|
+
if (Event.invalid(eventName)) {
|
|
33
|
+
throw new _errors.InvalidEvent(eventName);
|
|
34
|
+
}
|
|
35
|
+
if (this.subscribers[eventName]) {
|
|
36
|
+
this.subscribers[eventName] = this.subscribers[eventName].filter(cb => cb !== callback);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}, {
|
|
40
|
+
key: "dispatch",
|
|
41
|
+
value: function dispatch(eventName, data) {
|
|
42
|
+
var _this$subscribers$eve;
|
|
43
|
+
(_this$subscribers$eve = this.subscribers[eventName]) === null || _this$subscribers$eve === void 0 ? void 0 : _this$subscribers$eve.forEach(subscriber => {
|
|
44
|
+
subscriber(data);
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
}, {
|
|
48
|
+
key: "listeners",
|
|
49
|
+
get: function () {
|
|
50
|
+
return Object.keys(this.subscribers).length !== 0;
|
|
51
|
+
}
|
|
52
|
+
}], [{
|
|
53
|
+
key: "valid",
|
|
54
|
+
value: function valid(name) {
|
|
55
|
+
return Event.exists(name);
|
|
56
|
+
}
|
|
57
|
+
}, {
|
|
58
|
+
key: "invalid",
|
|
59
|
+
value: function invalid(name) {
|
|
60
|
+
return !this.valid(name);
|
|
61
|
+
}
|
|
62
|
+
}, {
|
|
63
|
+
key: "exists",
|
|
64
|
+
value: function exists(name) {
|
|
65
|
+
return this.events.find(eventName => eventName === name) !== undefined;
|
|
66
|
+
}
|
|
67
|
+
}]);
|
|
68
|
+
return Event;
|
|
69
|
+
}();
|
|
70
|
+
exports.default = Event;
|
|
71
|
+
Event.events = ['session-set', 'forms:collected', 'form:completed', 'webchat:mounted', 'webchat:opened', 'webchat:closed', 'webchat:message:sent', 'webchat:message:received'];
|
package/lib/core/event.js
CHANGED
|
@@ -1,10 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
var _errors = require("../errors");
|
|
8
1
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
9
2
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
10
3
|
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
@@ -13,6 +6,7 @@ function _defineProperties(target, props) { for (var i = 0; i < props.length; i+
|
|
|
13
6
|
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
7
|
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
15
8
|
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); }
|
|
9
|
+
import { InvalidEvent } from '../errors';
|
|
16
10
|
var Event = /*#__PURE__*/function () {
|
|
17
11
|
function Event() {
|
|
18
12
|
_classCallCheck(this, Event);
|
|
@@ -22,7 +16,7 @@ var Event = /*#__PURE__*/function () {
|
|
|
22
16
|
key: "addSubscriber",
|
|
23
17
|
value: function addSubscriber(eventName, callback) {
|
|
24
18
|
if (Event.invalid(eventName)) {
|
|
25
|
-
throw new
|
|
19
|
+
throw new InvalidEvent(eventName);
|
|
26
20
|
}
|
|
27
21
|
this.subscribers = _objectSpread(_objectSpread({}, this.subscribers), {}, {
|
|
28
22
|
[eventName]: this.subscribers[eventName] ? [...this.subscribers[eventName], callback] : [callback]
|
|
@@ -32,7 +26,7 @@ var Event = /*#__PURE__*/function () {
|
|
|
32
26
|
key: "removeSubscriber",
|
|
33
27
|
value: function removeSubscriber(eventName, callback) {
|
|
34
28
|
if (Event.invalid(eventName)) {
|
|
35
|
-
throw new
|
|
29
|
+
throw new InvalidEvent(eventName);
|
|
36
30
|
}
|
|
37
31
|
if (this.subscribers[eventName]) {
|
|
38
32
|
this.subscribers[eventName] = this.subscribers[eventName].filter(cb => cb !== callback);
|
|
@@ -69,5 +63,5 @@ var Event = /*#__PURE__*/function () {
|
|
|
69
63
|
}]);
|
|
70
64
|
return Event;
|
|
71
65
|
}();
|
|
72
|
-
|
|
73
|
-
|
|
66
|
+
Event.events = ['session-set', 'forms:collected', 'form:completed', 'webchat:mounted', 'webchat:opened', 'webchat:closed', 'webchat:message:sent', 'webchat:message:received'];
|
|
67
|
+
export { Event as default };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "Configuration", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _configuration.Configuration;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
Object.defineProperty(exports, "Event", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () {
|
|
15
|
+
return _event.default;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
var _event = _interopRequireDefault(require("./event"));
|
|
19
|
+
var _configuration = require("./configuration");
|
|
20
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
package/lib/core/index.js
CHANGED
|
@@ -1,20 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
Object.defineProperty(exports, "Configuration", {
|
|
7
|
-
enumerable: true,
|
|
8
|
-
get: function get() {
|
|
9
|
-
return _configuration.Configuration;
|
|
10
|
-
}
|
|
11
|
-
});
|
|
12
|
-
Object.defineProperty(exports, "Event", {
|
|
13
|
-
enumerable: true,
|
|
14
|
-
get: function get() {
|
|
15
|
-
return _event.default;
|
|
16
|
-
}
|
|
17
|
-
});
|
|
18
|
-
var _event = _interopRequireDefault(require("./event"));
|
|
19
|
-
var _configuration = require("./configuration");
|
|
20
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
1
|
+
export { default as Event } from './event';
|
|
2
|
+
export { Configuration } from './configuration';
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "InvalidEvent", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _invalid_event.InvalidEvent;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
Object.defineProperty(exports, "NotInitializedError", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () {
|
|
15
|
+
return _not_initialized_error.NotInitializedError;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
var _invalid_event = require("./invalid_event");
|
|
19
|
+
var _not_initialized_error = require("./not_initialized_error");
|
package/lib/errors/index.js
CHANGED
|
@@ -1,19 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
Object.defineProperty(exports, "InvalidEvent", {
|
|
7
|
-
enumerable: true,
|
|
8
|
-
get: function get() {
|
|
9
|
-
return _invalid_event.InvalidEvent;
|
|
10
|
-
}
|
|
11
|
-
});
|
|
12
|
-
Object.defineProperty(exports, "NotInitializedError", {
|
|
13
|
-
enumerable: true,
|
|
14
|
-
get: function get() {
|
|
15
|
-
return _not_initialized_error.NotInitializedError;
|
|
16
|
-
}
|
|
17
|
-
});
|
|
18
|
-
var _invalid_event = require("./invalid_event");
|
|
19
|
-
var _not_initialized_error = require("./not_initialized_error");
|
|
1
|
+
export { InvalidEvent } from './invalid_event';
|
|
2
|
+
export { NotInitializedError } from './not_initialized_error';
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.InvalidEvent = void 0;
|
|
7
|
+
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); } }
|
|
8
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
9
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
10
|
+
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); }
|
|
11
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
12
|
+
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
13
|
+
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
14
|
+
function _possibleConstructorReturn(self, call) { if (call && (typeof call === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
|
|
15
|
+
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
16
|
+
function _wrapNativeSuper(Class) { var _cache = typeof Map === "function" ? new Map() : undefined; _wrapNativeSuper = function _wrapNativeSuper(Class) { if (Class === null || !_isNativeFunction(Class)) return Class; if (typeof Class !== "function") { throw new TypeError("Super expression must either be null or a function"); } if (typeof _cache !== "undefined") { if (_cache.has(Class)) return _cache.get(Class); _cache.set(Class, Wrapper); } function Wrapper() { return _construct(Class, arguments, _getPrototypeOf(this).constructor); } Wrapper.prototype = Object.create(Class.prototype, { constructor: { value: Wrapper, enumerable: false, writable: true, configurable: true } }); return _setPrototypeOf(Wrapper, Class); }; return _wrapNativeSuper(Class); }
|
|
17
|
+
function _construct(Parent, args, Class) { if (_isNativeReflectConstruct()) { _construct = Reflect.construct.bind(); } else { _construct = function _construct(Parent, args, Class) { var a = [null]; a.push.apply(a, args); var Constructor = Function.bind.apply(Parent, a); var instance = new Constructor(); if (Class) _setPrototypeOf(instance, Class.prototype); return instance; }; } return _construct.apply(null, arguments); }
|
|
18
|
+
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
19
|
+
function _isNativeFunction(fn) { return Function.toString.call(fn).indexOf("[native code]") !== -1; }
|
|
20
|
+
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
21
|
+
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
22
|
+
let InvalidEvent = /*#__PURE__*/function (_Error) {
|
|
23
|
+
_inherits(InvalidEvent, _Error);
|
|
24
|
+
var _super = _createSuper(InvalidEvent);
|
|
25
|
+
function InvalidEvent(event) {
|
|
26
|
+
var _this;
|
|
27
|
+
_classCallCheck(this, InvalidEvent);
|
|
28
|
+
_this = _super.call(this, `${event} is not valid. Please provide a valid event name`);
|
|
29
|
+
_this.name = 'InvalidEvent';
|
|
30
|
+
return _this;
|
|
31
|
+
}
|
|
32
|
+
return _createClass(InvalidEvent);
|
|
33
|
+
}( /*#__PURE__*/_wrapNativeSuper(Error));
|
|
34
|
+
exports.InvalidEvent = InvalidEvent;
|
|
@@ -1,9 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.InvalidEvent = void 0;
|
|
7
1
|
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); } }
|
|
8
2
|
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
9
3
|
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
@@ -31,4 +25,4 @@ var InvalidEvent = /*#__PURE__*/function (_Error) {
|
|
|
31
25
|
}
|
|
32
26
|
return _createClass(InvalidEvent);
|
|
33
27
|
}( /*#__PURE__*/_wrapNativeSuper(Error));
|
|
34
|
-
|
|
28
|
+
export { InvalidEvent };
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.NotInitializedError = void 0;
|
|
7
|
+
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); } }
|
|
8
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
9
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
10
|
+
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); }
|
|
11
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
12
|
+
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
13
|
+
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
14
|
+
function _possibleConstructorReturn(self, call) { if (call && (typeof call === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
|
|
15
|
+
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
16
|
+
function _wrapNativeSuper(Class) { var _cache = typeof Map === "function" ? new Map() : undefined; _wrapNativeSuper = function _wrapNativeSuper(Class) { if (Class === null || !_isNativeFunction(Class)) return Class; if (typeof Class !== "function") { throw new TypeError("Super expression must either be null or a function"); } if (typeof _cache !== "undefined") { if (_cache.has(Class)) return _cache.get(Class); _cache.set(Class, Wrapper); } function Wrapper() { return _construct(Class, arguments, _getPrototypeOf(this).constructor); } Wrapper.prototype = Object.create(Class.prototype, { constructor: { value: Wrapper, enumerable: false, writable: true, configurable: true } }); return _setPrototypeOf(Wrapper, Class); }; return _wrapNativeSuper(Class); }
|
|
17
|
+
function _construct(Parent, args, Class) { if (_isNativeReflectConstruct()) { _construct = Reflect.construct.bind(); } else { _construct = function _construct(Parent, args, Class) { var a = [null]; a.push.apply(a, args); var Constructor = Function.bind.apply(Parent, a); var instance = new Constructor(); if (Class) _setPrototypeOf(instance, Class.prototype); return instance; }; } return _construct.apply(null, arguments); }
|
|
18
|
+
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
19
|
+
function _isNativeFunction(fn) { return Function.toString.call(fn).indexOf("[native code]") !== -1; }
|
|
20
|
+
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
21
|
+
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
22
|
+
let NotInitializedError = /*#__PURE__*/function (_Error) {
|
|
23
|
+
_inherits(NotInitializedError, _Error);
|
|
24
|
+
var _super = _createSuper(NotInitializedError);
|
|
25
|
+
function NotInitializedError() {
|
|
26
|
+
var _this;
|
|
27
|
+
_classCallCheck(this, NotInitializedError);
|
|
28
|
+
_this = _super.call(this, 'You need to initialize before tracking events. Call Hellotext.initialize and pass your public business id');
|
|
29
|
+
_this.name = 'NotInitializedError';
|
|
30
|
+
return _this;
|
|
31
|
+
}
|
|
32
|
+
return _createClass(NotInitializedError);
|
|
33
|
+
}( /*#__PURE__*/_wrapNativeSuper(Error));
|
|
34
|
+
exports.NotInitializedError = NotInitializedError;
|
|
@@ -1,9 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.NotInitializedError = void 0;
|
|
7
1
|
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); } }
|
|
8
2
|
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
9
3
|
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
@@ -31,4 +25,4 @@ var NotInitializedError = /*#__PURE__*/function (_Error) {
|
|
|
31
25
|
}
|
|
32
26
|
return _createClass(NotInitializedError);
|
|
33
27
|
}( /*#__PURE__*/_wrapNativeSuper(Error));
|
|
34
|
-
|
|
28
|
+
export { NotInitializedError };
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _core = require("./core");
|
|
8
|
+
var _api = _interopRequireWildcard(require("./api"));
|
|
9
|
+
var _models = require("./models");
|
|
10
|
+
var _errors = require("./errors");
|
|
11
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
12
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
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 _session = /*#__PURE__*/_classPrivateFieldLooseKey("session");
|
|
22
|
+
var _query = /*#__PURE__*/_classPrivateFieldLooseKey("query");
|
|
23
|
+
let Hellotext = /*#__PURE__*/function () {
|
|
24
|
+
function Hellotext() {
|
|
25
|
+
_classCallCheck(this, Hellotext);
|
|
26
|
+
}
|
|
27
|
+
_createClass(Hellotext, null, [{
|
|
28
|
+
key: "initialize",
|
|
29
|
+
value:
|
|
30
|
+
/**
|
|
31
|
+
* initialize the module.
|
|
32
|
+
* @param business public business id
|
|
33
|
+
* @param { Configuration } config
|
|
34
|
+
*/
|
|
35
|
+
async function initialize(business, config) {
|
|
36
|
+
this.business = new _models.Business(business);
|
|
37
|
+
_core.Configuration.assign(config);
|
|
38
|
+
_models.Session.initialize();
|
|
39
|
+
_classPrivateFieldLooseBase(this, _query)[_query] = new _models.Query();
|
|
40
|
+
this.forms = new _models.FormCollection();
|
|
41
|
+
if (_core.Configuration.webchat.id) {
|
|
42
|
+
this.webchat = await _models.Webchat.load(_core.Configuration.webchat.id);
|
|
43
|
+
}
|
|
44
|
+
this.forms.collect();
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Tracks an action that has happened on the page
|
|
49
|
+
*
|
|
50
|
+
* @param { String } action a valid action name
|
|
51
|
+
* @param { Object } params
|
|
52
|
+
* @returns {Promise<Response>}
|
|
53
|
+
*/
|
|
54
|
+
}, {
|
|
55
|
+
key: "track",
|
|
56
|
+
value: async function track(action, params = {}) {
|
|
57
|
+
if (this.notInitialized) {
|
|
58
|
+
throw new _errors.NotInitializedError();
|
|
59
|
+
}
|
|
60
|
+
const headers = {
|
|
61
|
+
...(params && params.headers || {}),
|
|
62
|
+
...this.headers
|
|
63
|
+
};
|
|
64
|
+
const body = {
|
|
65
|
+
session: this.session,
|
|
66
|
+
action,
|
|
67
|
+
...params,
|
|
68
|
+
url: params && params.url || window.location.href
|
|
69
|
+
};
|
|
70
|
+
delete body.headers;
|
|
71
|
+
return await _api.default.events.create({
|
|
72
|
+
headers,
|
|
73
|
+
body
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Registers an event listener
|
|
79
|
+
* @param event the name of the event to listen to
|
|
80
|
+
* @param callback the callback. This method will be called with the payload
|
|
81
|
+
*/
|
|
82
|
+
}, {
|
|
83
|
+
key: "on",
|
|
84
|
+
value: function on(event, callback) {
|
|
85
|
+
this.eventEmitter.addSubscriber(event, callback);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Removes an event listener
|
|
90
|
+
* @param event the name of the event to remove
|
|
91
|
+
* @param callback the callback to remove
|
|
92
|
+
*/
|
|
93
|
+
}, {
|
|
94
|
+
key: "removeEventListener",
|
|
95
|
+
value: function removeEventListener(event, callback) {
|
|
96
|
+
this.eventEmitter.removeSubscriber(event, callback);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
*
|
|
101
|
+
* @returns {String}
|
|
102
|
+
*/
|
|
103
|
+
}, {
|
|
104
|
+
key: "session",
|
|
105
|
+
get: function () {
|
|
106
|
+
return _models.Session.session;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Determines if the session is set or not
|
|
111
|
+
* @returns {boolean}
|
|
112
|
+
*/
|
|
113
|
+
}, {
|
|
114
|
+
key: "isInitialized",
|
|
115
|
+
get: function () {
|
|
116
|
+
return _models.Session.session !== undefined;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// private
|
|
120
|
+
}, {
|
|
121
|
+
key: "notInitialized",
|
|
122
|
+
get: function () {
|
|
123
|
+
return this.business.id === undefined;
|
|
124
|
+
}
|
|
125
|
+
}, {
|
|
126
|
+
key: "headers",
|
|
127
|
+
get: function () {
|
|
128
|
+
if (this.notInitialized) {
|
|
129
|
+
throw new _errors.NotInitializedError();
|
|
130
|
+
}
|
|
131
|
+
return {
|
|
132
|
+
Authorization: `Bearer ${this.business.id}`,
|
|
133
|
+
Accept: 'application/json',
|
|
134
|
+
'Content-Type': 'application/json'
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
}]);
|
|
138
|
+
return Hellotext;
|
|
139
|
+
}();
|
|
140
|
+
Object.defineProperty(Hellotext, _session, {
|
|
141
|
+
writable: true,
|
|
142
|
+
value: void 0
|
|
143
|
+
});
|
|
144
|
+
Object.defineProperty(Hellotext, _query, {
|
|
145
|
+
writable: true,
|
|
146
|
+
value: void 0
|
|
147
|
+
});
|
|
148
|
+
Hellotext.eventEmitter = new _core.Event();
|
|
149
|
+
Hellotext.forms = void 0;
|
|
150
|
+
Hellotext.business = void 0;
|
|
151
|
+
Hellotext.webchat = void 0;
|
|
152
|
+
var _default = Hellotext;
|
|
153
|
+
exports.default = _default;
|
package/lib/hellotext.js
CHANGED
|
@@ -1,15 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
var _core = require("./core");
|
|
8
|
-
var _api = _interopRequireWildcard(require("./api"));
|
|
9
|
-
var _models = require("./models");
|
|
10
|
-
var _errors = require("./errors");
|
|
11
|
-
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
12
|
-
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
13
1
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
14
2
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
15
3
|
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
@@ -23,6 +11,10 @@ function _toPrimitive(input, hint) { if (typeof input !== "object" || input ===
|
|
|
23
11
|
function _classPrivateFieldLooseBase(receiver, privateKey) { if (!Object.prototype.hasOwnProperty.call(receiver, privateKey)) { throw new TypeError("attempted to use private field on non-instance"); } return receiver; }
|
|
24
12
|
var id = 0;
|
|
25
13
|
function _classPrivateFieldLooseKey(name) { return "__private_" + id++ + "_" + name; }
|
|
14
|
+
import { Configuration, Event } from './core';
|
|
15
|
+
import API, { Response } from './api';
|
|
16
|
+
import { Business, FormCollection, Query, Session, Webchat } from './models';
|
|
17
|
+
import { NotInitializedError } from './errors';
|
|
26
18
|
var _session = /*#__PURE__*/_classPrivateFieldLooseKey("session");
|
|
27
19
|
var _query = /*#__PURE__*/_classPrivateFieldLooseKey("query");
|
|
28
20
|
var Hellotext = /*#__PURE__*/function () {
|
|
@@ -39,14 +31,15 @@ var Hellotext = /*#__PURE__*/function () {
|
|
|
39
31
|
*/
|
|
40
32
|
function () {
|
|
41
33
|
var _initialize = _asyncToGenerator(function* (business, config) {
|
|
42
|
-
this.business = new
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
_classPrivateFieldLooseBase(this, _query)[_query] = new
|
|
46
|
-
this.forms = new
|
|
47
|
-
if (
|
|
48
|
-
this.webchat = yield
|
|
34
|
+
this.business = new Business(business);
|
|
35
|
+
Configuration.assign(config);
|
|
36
|
+
Session.initialize();
|
|
37
|
+
_classPrivateFieldLooseBase(this, _query)[_query] = new Query();
|
|
38
|
+
this.forms = new FormCollection();
|
|
39
|
+
if (Configuration.webchat.id) {
|
|
40
|
+
this.webchat = yield Webchat.load(Configuration.webchat.id);
|
|
49
41
|
}
|
|
42
|
+
this.forms.collect();
|
|
50
43
|
});
|
|
51
44
|
function initialize(_x, _x2) {
|
|
52
45
|
return _initialize.apply(this, arguments);
|
|
@@ -66,7 +59,7 @@ var Hellotext = /*#__PURE__*/function () {
|
|
|
66
59
|
var _track = _asyncToGenerator(function* (action) {
|
|
67
60
|
var params = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
68
61
|
if (this.notInitialized) {
|
|
69
|
-
throw new
|
|
62
|
+
throw new NotInitializedError();
|
|
70
63
|
}
|
|
71
64
|
var headers = _objectSpread(_objectSpread({}, params && params.headers || {}), this.headers);
|
|
72
65
|
var body = _objectSpread(_objectSpread({
|
|
@@ -76,7 +69,7 @@ var Hellotext = /*#__PURE__*/function () {
|
|
|
76
69
|
url: params && params.url || window.location.href
|
|
77
70
|
});
|
|
78
71
|
delete body.headers;
|
|
79
|
-
return yield
|
|
72
|
+
return yield API.events.create({
|
|
80
73
|
headers,
|
|
81
74
|
body
|
|
82
75
|
});
|
|
@@ -115,7 +108,7 @@ var Hellotext = /*#__PURE__*/function () {
|
|
|
115
108
|
}, {
|
|
116
109
|
key: "session",
|
|
117
110
|
get: function get() {
|
|
118
|
-
return
|
|
111
|
+
return Session.session;
|
|
119
112
|
}
|
|
120
113
|
|
|
121
114
|
/**
|
|
@@ -125,7 +118,7 @@ var Hellotext = /*#__PURE__*/function () {
|
|
|
125
118
|
}, {
|
|
126
119
|
key: "isInitialized",
|
|
127
120
|
get: function get() {
|
|
128
|
-
return
|
|
121
|
+
return Session.session !== undefined;
|
|
129
122
|
}
|
|
130
123
|
|
|
131
124
|
// private
|
|
@@ -138,7 +131,7 @@ var Hellotext = /*#__PURE__*/function () {
|
|
|
138
131
|
key: "headers",
|
|
139
132
|
get: function get() {
|
|
140
133
|
if (this.notInitialized) {
|
|
141
|
-
throw new
|
|
134
|
+
throw new NotInitializedError();
|
|
142
135
|
}
|
|
143
136
|
return {
|
|
144
137
|
Authorization: "Bearer ".concat(this.business.id),
|
|
@@ -157,9 +150,8 @@ Object.defineProperty(Hellotext, _query, {
|
|
|
157
150
|
writable: true,
|
|
158
151
|
value: void 0
|
|
159
152
|
});
|
|
160
|
-
Hellotext.eventEmitter = new
|
|
153
|
+
Hellotext.eventEmitter = new Event();
|
|
161
154
|
Hellotext.forms = void 0;
|
|
162
155
|
Hellotext.business = void 0;
|
|
163
156
|
Hellotext.webchat = void 0;
|
|
164
|
-
|
|
165
|
-
exports.default = _default;
|
|
157
|
+
export default Hellotext;
|
package/lib/index.cjs
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _stimulus = require("@hotwired/stimulus");
|
|
8
|
+
var _hellotext = _interopRequireDefault(require("./hellotext"));
|
|
9
|
+
var _form_controller = _interopRequireDefault(require("./controllers/form_controller"));
|
|
10
|
+
var _emoji_picker_controller = _interopRequireDefault(require("./controllers/webchat/emoji_picker_controller"));
|
|
11
|
+
var _webchat_controller = _interopRequireDefault(require("./controllers/webchat_controller"));
|
|
12
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
+
const application = _stimulus.Application.start();
|
|
14
|
+
application.register('hellotext--form', _form_controller.default);
|
|
15
|
+
application.register('hellotext--webchat', _webchat_controller.default);
|
|
16
|
+
application.register('hellotext--webchat--emoji', _emoji_picker_controller.default);
|
|
17
|
+
window.Hellotext = _hellotext.default;
|
|
18
|
+
var _default = _hellotext.default;
|
|
19
|
+
exports.default = _default;
|