@hellotext/hellotext 1.8.6 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (107) hide show
  1. package/README.md +3 -0
  2. package/dist/hellotext.js +1 -1
  3. package/lib/api/businesses.cjs +37 -0
  4. package/lib/api/businesses.js +3 -9
  5. package/lib/api/events.cjs +45 -0
  6. package/lib/api/events.js +8 -14
  7. package/lib/api/forms.cjs +51 -0
  8. package/lib/api/forms.js +10 -17
  9. package/lib/api/index.cjs +51 -0
  10. package/lib/api/index.js +10 -23
  11. package/lib/api/response.cjs +76 -0
  12. package/lib/api/response.js +1 -7
  13. package/lib/api/submissions.cjs +47 -0
  14. package/lib/api/submissions.js +9 -17
  15. package/lib/api/webchat/messages.cjs +70 -0
  16. package/lib/api/webchat/messages.js +10 -18
  17. package/lib/api/webchats.cjs +44 -0
  18. package/lib/api/webchats.js +8 -16
  19. package/lib/builders/input_builder.cjs +61 -0
  20. package/lib/builders/input_builder.js +4 -11
  21. package/lib/builders/logo_builder.cjs +50 -0
  22. package/lib/builders/logo_builder.js +5 -12
  23. package/lib/channels/application_channel.cjs +67 -0
  24. package/lib/channels/application_channel.js +1 -8
  25. package/lib/channels/{web_chat_channel.js → webchat_channel.cjs} +35 -20
  26. package/lib/channels/webchat_channel.js +3 -11
  27. package/lib/controllers/form_controller.cjs +141 -0
  28. package/lib/controllers/form_controller.js +15 -22
  29. package/lib/controllers/mixins/usePopover.cjs +59 -0
  30. package/lib/controllers/mixins/usePopover.js +6 -14
  31. package/lib/controllers/{web_chat/pagination_controller.js → webchat/emoji_picker_controller.cjs} +74 -29
  32. package/lib/controllers/webchat/emoji_picker_controller.js +11 -17
  33. package/lib/controllers/webchat_controller.cjs +433 -0
  34. package/lib/controllers/webchat_controller.js +49 -51
  35. package/lib/core/configuration/forms.cjs +49 -0
  36. package/lib/core/configuration/forms.js +2 -8
  37. package/lib/core/configuration/{web_chat.js → webchat.cjs} +53 -38
  38. package/lib/core/configuration/webchat.js +2 -9
  39. package/lib/core/configuration.cjs +65 -0
  40. package/lib/core/configuration.js +8 -13
  41. package/lib/core/event.cjs +71 -0
  42. package/lib/core/event.js +5 -11
  43. package/lib/core/index.cjs +20 -0
  44. package/lib/core/index.js +2 -20
  45. package/lib/errors/index.cjs +19 -0
  46. package/lib/errors/index.js +2 -19
  47. package/lib/errors/invalid_event.cjs +34 -0
  48. package/lib/errors/invalid_event.js +1 -7
  49. package/lib/errors/not_initialized_error.cjs +34 -0
  50. package/lib/errors/not_initialized_error.js +1 -7
  51. package/lib/hellotext.cjs +152 -0
  52. package/lib/hellotext.js +18 -27
  53. package/lib/index.cjs +20 -0
  54. package/lib/index.js +12 -20
  55. package/lib/locales/en.cjs +22 -0
  56. package/lib/locales/en.js +2 -9
  57. package/lib/locales/es.cjs +22 -0
  58. package/lib/locales/es.js +2 -9
  59. package/lib/locales/index.cjs +14 -0
  60. package/lib/locales/index.js +6 -14
  61. package/lib/models/business.cjs +65 -0
  62. package/lib/models/business.js +5 -12
  63. package/lib/models/cookies.cjs +40 -0
  64. package/lib/models/cookies.js +3 -10
  65. package/lib/models/form.cjs +166 -0
  66. package/lib/models/form.js +10 -17
  67. package/lib/models/form_collection.cjs +119 -0
  68. package/lib/models/form_collection.js +15 -22
  69. package/lib/models/index.cjs +54 -0
  70. package/lib/models/index.js +7 -54
  71. package/lib/models/query.cjs +51 -0
  72. package/lib/models/query.js +3 -9
  73. package/lib/models/session.cjs +58 -0
  74. package/lib/models/session.js +12 -17
  75. package/lib/models/{web_chat.js → webchat.cjs} +14 -22
  76. package/lib/models/webchat.js +6 -13
  77. package/lib/vanilla.cjs +13 -0
  78. package/lib/vanilla.js +1 -13
  79. package/package.json +34 -7
  80. package/src/controllers/webchat_controller.js +72 -47
  81. package/src/hellotext.js +5 -6
  82. package/src/models/session.js +4 -3
  83. package/.babelrc +0 -24
  84. package/.github/workflows/ci.yml +0 -24
  85. package/.prettierignore +0 -3
  86. package/.prettierrc.json +0 -18
  87. package/MIT-LICENSE +0 -20
  88. package/__tests__/builders/input_builder_test.js +0 -117
  89. package/__tests__/core/configuration/forms_test.js +0 -30
  90. package/__tests__/core/configuration/webchat_test.js +0 -163
  91. package/__tests__/core/configuration_test.js +0 -28
  92. package/__tests__/core/event_test.js +0 -56
  93. package/__tests__/hellotext_test.js +0 -197
  94. package/__tests__/models/business_test.js +0 -26
  95. package/__tests__/models/cookies_test.js +0 -25
  96. package/__tests__/models/form_collection_test.js +0 -103
  97. package/__tests__/models/form_test.js +0 -131
  98. package/__tests__/models/query_test.js +0 -97
  99. package/docs/forms.md +0 -176
  100. package/docs/tracking.md +0 -168
  101. package/docs/webchat.md +0 -101
  102. package/jest.config.js +0 -4
  103. package/jest.setup.js +0 -16
  104. package/lib/api/web_chat/messages.js +0 -74
  105. package/lib/api/web_chats.js +0 -53
  106. package/styles/index.css +0 -38
  107. 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 = _forms.Forms.assign(value);
38
+ this.forms = Forms.assign(value);
44
39
  } else if (key === 'webChat') {
45
- this.webchat = _webchat.Webchat.assign(value);
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 = _forms.Forms;
66
- Configuration.webchat = _webchat.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 _errors.InvalidEvent(eventName);
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 _errors.InvalidEvent(eventName);
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
- exports.default = Event;
73
- Event.events = ['session-set', 'forms:collected', 'form:completed', 'webchat:mounted', 'webchat:opened', 'webchat:closed', 'webchat:message:sent', 'webchat:message:received'];
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
- "use strict";
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");
@@ -1,19 +1,2 @@
1
- "use strict";
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
- exports.InvalidEvent = InvalidEvent;
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
- exports.NotInitializedError = NotInitializedError;
28
+ export { NotInitializedError };
@@ -0,0 +1,152 @@
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
+ }
45
+
46
+ /**
47
+ * Tracks an action that has happened on the page
48
+ *
49
+ * @param { String } action a valid action name
50
+ * @param { Object } params
51
+ * @returns {Promise<Response>}
52
+ */
53
+ }, {
54
+ key: "track",
55
+ value: async function track(action, params = {}) {
56
+ if (this.notInitialized) {
57
+ throw new _errors.NotInitializedError();
58
+ }
59
+ const headers = {
60
+ ...(params && params.headers || {}),
61
+ ...this.headers
62
+ };
63
+ const body = {
64
+ session: this.session,
65
+ action,
66
+ ...params,
67
+ url: params && params.url || window.location.href
68
+ };
69
+ delete body.headers;
70
+ return await _api.default.events.create({
71
+ headers,
72
+ body
73
+ });
74
+ }
75
+
76
+ /**
77
+ * Registers an event listener
78
+ * @param event the name of the event to listen to
79
+ * @param callback the callback. This method will be called with the payload
80
+ */
81
+ }, {
82
+ key: "on",
83
+ value: function on(event, callback) {
84
+ this.eventEmitter.addSubscriber(event, callback);
85
+ }
86
+
87
+ /**
88
+ * Removes an event listener
89
+ * @param event the name of the event to remove
90
+ * @param callback the callback to remove
91
+ */
92
+ }, {
93
+ key: "removeEventListener",
94
+ value: function removeEventListener(event, callback) {
95
+ this.eventEmitter.removeSubscriber(event, callback);
96
+ }
97
+
98
+ /**
99
+ *
100
+ * @returns {String}
101
+ */
102
+ }, {
103
+ key: "session",
104
+ get: function () {
105
+ return _models.Session.session;
106
+ }
107
+
108
+ /**
109
+ * Determines if the session is set or not
110
+ * @returns {boolean}
111
+ */
112
+ }, {
113
+ key: "isInitialized",
114
+ get: function () {
115
+ return _models.Session.session !== undefined;
116
+ }
117
+
118
+ // private
119
+ }, {
120
+ key: "notInitialized",
121
+ get: function () {
122
+ return this.business.id === undefined;
123
+ }
124
+ }, {
125
+ key: "headers",
126
+ get: function () {
127
+ if (this.notInitialized) {
128
+ throw new _errors.NotInitializedError();
129
+ }
130
+ return {
131
+ Authorization: `Bearer ${this.business.id}`,
132
+ Accept: 'application/json',
133
+ 'Content-Type': 'application/json'
134
+ };
135
+ }
136
+ }]);
137
+ return Hellotext;
138
+ }();
139
+ Object.defineProperty(Hellotext, _session, {
140
+ writable: true,
141
+ value: void 0
142
+ });
143
+ Object.defineProperty(Hellotext, _query, {
144
+ writable: true,
145
+ value: void 0
146
+ });
147
+ Hellotext.eventEmitter = new _core.Event();
148
+ Hellotext.forms = void 0;
149
+ Hellotext.business = void 0;
150
+ Hellotext.webchat = void 0;
151
+ var _default = Hellotext;
152
+ 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,13 +31,13 @@ var Hellotext = /*#__PURE__*/function () {
39
31
  */
40
32
  function () {
41
33
  var _initialize = _asyncToGenerator(function* (business, config) {
42
- _core.Configuration.assign(config);
43
- _models.Session.initialize();
44
- _classPrivateFieldLooseBase(this, _query)[_query] = new _models.Query();
45
- this.business = new _models.Business(business);
46
- this.forms = new _models.FormCollection();
47
- if (_core.Configuration.webchat.id) {
48
- this.webchat = yield _models.Webchat.load(_core.Configuration.webchat.id);
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
  }
50
42
  });
51
43
  function initialize(_x, _x2) {
@@ -66,7 +58,7 @@ var Hellotext = /*#__PURE__*/function () {
66
58
  var _track = _asyncToGenerator(function* (action) {
67
59
  var params = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
68
60
  if (this.notInitialized) {
69
- throw new _errors.NotInitializedError();
61
+ throw new NotInitializedError();
70
62
  }
71
63
  var headers = _objectSpread(_objectSpread({}, params && params.headers || {}), this.headers);
72
64
  var body = _objectSpread(_objectSpread({
@@ -76,7 +68,7 @@ var Hellotext = /*#__PURE__*/function () {
76
68
  url: params && params.url || window.location.href
77
69
  });
78
70
  delete body.headers;
79
- return yield _api.default.events.create({
71
+ return yield API.events.create({
80
72
  headers,
81
73
  body
82
74
  });
@@ -115,7 +107,7 @@ var Hellotext = /*#__PURE__*/function () {
115
107
  }, {
116
108
  key: "session",
117
109
  get: function get() {
118
- return _models.Session.session;
110
+ return Session.session;
119
111
  }
120
112
 
121
113
  /**
@@ -125,7 +117,7 @@ var Hellotext = /*#__PURE__*/function () {
125
117
  }, {
126
118
  key: "isInitialized",
127
119
  get: function get() {
128
- return _models.Session.session !== undefined;
120
+ return Session.session !== undefined;
129
121
  }
130
122
 
131
123
  // private
@@ -138,7 +130,7 @@ var Hellotext = /*#__PURE__*/function () {
138
130
  key: "headers",
139
131
  get: function get() {
140
132
  if (this.notInitialized) {
141
- throw new _errors.NotInitializedError();
133
+ throw new NotInitializedError();
142
134
  }
143
135
  return {
144
136
  Authorization: "Bearer ".concat(this.business.id),
@@ -157,9 +149,8 @@ Object.defineProperty(Hellotext, _query, {
157
149
  writable: true,
158
150
  value: void 0
159
151
  });
160
- Hellotext.eventEmitter = new _core.Event();
152
+ Hellotext.eventEmitter = new Event();
161
153
  Hellotext.forms = void 0;
162
154
  Hellotext.business = void 0;
163
155
  Hellotext.webchat = void 0;
164
- var _default = Hellotext;
165
- exports.default = _default;
156
+ export default Hellotext;
package/lib/index.cjs ADDED
@@ -0,0 +1,20 @@
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 _webchat_controller = _interopRequireDefault(require("./controllers/webchat_controller"));
11
+ var _emoji_picker_controller = _interopRequireDefault(require("./controllers/webchat/emoji_picker_controller"));
12
+ require("../styles/index.css");
13
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
14
+ const application = _stimulus.Application.start();
15
+ application.register('hellotext--form', _form_controller.default);
16
+ application.register('hellotext--webchat', _webchat_controller.default);
17
+ application.register('hellotext--webchat--emoji', _emoji_picker_controller.default);
18
+ window.Hellotext = _hellotext.default;
19
+ var _default = _hellotext.default;
20
+ exports.default = _default;