@hellotext/hellotext 2.5.7 → 2.5.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (102) hide show
  1. package/README.md +0 -25
  2. package/dist/hellotext.js +1 -1
  3. package/index.d.ts +0 -6
  4. package/lib/api/acks.cjs +17 -31
  5. package/lib/api/acks.js +17 -42
  6. package/lib/api/businesses.cjs +14 -28
  7. package/lib/api/businesses.js +13 -36
  8. package/lib/api/events.cjs +26 -40
  9. package/lib/api/events.js +28 -52
  10. package/lib/api/forms.cjs +24 -40
  11. package/lib/api/forms.js +24 -57
  12. package/lib/api/identifications.cjs +15 -29
  13. package/lib/api/identifications.js +15 -40
  14. package/lib/api/index.cjs +25 -51
  15. package/lib/api/index.js +27 -54
  16. package/lib/api/push/identities.cjs +30 -46
  17. package/lib/api/push/identities.js +30 -63
  18. package/lib/api/response.cjs +30 -52
  19. package/lib/api/response.js +31 -60
  20. package/lib/api/submissions.cjs +18 -34
  21. package/lib/api/submissions.js +18 -48
  22. package/lib/api/webchat/messages.cjs +44 -64
  23. package/lib/api/webchat/messages.js +44 -80
  24. package/lib/api/webchats.cjs +37 -56
  25. package/lib/api/webchats.js +37 -65
  26. package/lib/api/whatsapp_widgets.cjs +49 -72
  27. package/lib/api/whatsapp_widgets.js +48 -91
  28. package/lib/builders/input_builder.cjs +36 -48
  29. package/lib/builders/input_builder.js +36 -48
  30. package/lib/builders/logo_builder.cjs +10 -29
  31. package/lib/builders/logo_builder.js +20 -28
  32. package/lib/channels/application_channel.cjs +136 -178
  33. package/lib/channels/application_channel.js +137 -180
  34. package/lib/channels/webchat_channel.cjs +125 -170
  35. package/lib/channels/webchat_channel.js +125 -170
  36. package/lib/controllers/form_controller.cjs +82 -121
  37. package/lib/controllers/form_controller.js +82 -130
  38. package/lib/controllers/message_controller.cjs +211 -282
  39. package/lib/controllers/message_controller.js +209 -284
  40. package/lib/controllers/mixins/usePopover.cjs +3 -6
  41. package/lib/controllers/mixins/usePopover.js +17 -22
  42. package/lib/controllers/webchat/emoji_picker_controller.cjs +106 -150
  43. package/lib/controllers/webchat/emoji_picker_controller.js +105 -170
  44. package/lib/controllers/webchat/useBehaviour.js +5 -5
  45. package/lib/controllers/webchat/useOpeningSequence.js +6 -6
  46. package/lib/controllers/webchat/useTeaser.js +9 -9
  47. package/lib/controllers/webchat_controller.cjs +916 -1088
  48. package/lib/controllers/webchat_controller.js +926 -1152
  49. package/lib/core/configuration/forms.cjs +21 -35
  50. package/lib/core/configuration/forms.js +20 -35
  51. package/lib/core/configuration/locale.cjs +36 -71
  52. package/lib/core/configuration/locale.js +36 -70
  53. package/lib/core/configuration/push.cjs +9 -21
  54. package/lib/core/configuration/push.js +8 -20
  55. package/lib/core/configuration/webchat.cjs +142 -182
  56. package/lib/core/configuration/webchat.js +145 -189
  57. package/lib/core/configuration/whatsapp.cjs +76 -102
  58. package/lib/core/configuration/whatsapp.js +76 -105
  59. package/lib/core/configuration.cjs +60 -78
  60. package/lib/core/configuration.js +59 -78
  61. package/lib/core/event.cjs +36 -59
  62. package/lib/core/event.js +35 -61
  63. package/lib/core/sanitize_html.js +4 -4
  64. package/lib/errors/invalid_event.cjs +5 -26
  65. package/lib/errors/invalid_event.js +5 -26
  66. package/lib/errors/not_initialized_error.cjs +5 -26
  67. package/lib/errors/not_initialized_error.js +5 -26
  68. package/lib/hellotext.cjs +185 -223
  69. package/lib/hellotext.js +188 -247
  70. package/lib/index.js +1 -1
  71. package/lib/models/business.cjs +114 -152
  72. package/lib/models/business.js +117 -162
  73. package/lib/models/cookies.cjs +34 -51
  74. package/lib/models/cookies.js +34 -51
  75. package/lib/models/fingerprint.cjs +8 -23
  76. package/lib/models/fingerprint.js +25 -58
  77. package/lib/models/form.cjs +106 -142
  78. package/lib/models/form.js +105 -153
  79. package/lib/models/form_collection.cjs +63 -101
  80. package/lib/models/form_collection.js +61 -107
  81. package/lib/models/page.cjs +106 -129
  82. package/lib/models/page.js +106 -131
  83. package/lib/models/push.cjs +278 -322
  84. package/lib/models/push.js +284 -357
  85. package/lib/models/query.cjs +21 -41
  86. package/lib/models/query.js +21 -41
  87. package/lib/models/session.cjs +33 -65
  88. package/lib/models/session.js +30 -63
  89. package/lib/models/user.cjs +29 -51
  90. package/lib/models/user.js +29 -51
  91. package/lib/models/utm.cjs +15 -27
  92. package/lib/models/utm.js +17 -32
  93. package/lib/models/webchat.cjs +52 -76
  94. package/lib/models/webchat.js +52 -90
  95. package/lib/models/whatsapp_widget.cjs +41 -59
  96. package/lib/models/whatsapp_widget.js +41 -73
  97. package/lib/vanilla.cjs +4 -7
  98. package/lib/vanilla.js +2 -1
  99. package/package.json +1 -9
  100. package/src/index.bundle.js +0 -1
  101. package/src/vanilla.js +2 -1
  102. package/styles/index.css +0 -30
@@ -1,8 +1,3 @@
1
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
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); } }
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; }
4
- function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
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
1
  /**
7
2
  * @typedef {'top-left' | 'top-right' | 'bottom-left' | 'bottom-right'} Placement
8
3
  * @description Valid placements for the WhatsApp widget.
@@ -11,7 +6,7 @@ function _toPrimitive(input, hint) { if (typeof input !== "object" || input ===
11
6
  /**
12
7
  * @enum {Placement}
13
8
  */
14
- var placements = {
9
+ const placements = {
15
10
  TOP_LEFT: 'top-left',
16
11
  TOP_RIGHT: 'top-right',
17
12
  BOTTOM_LEFT: 'bottom-left',
@@ -34,114 +29,90 @@ var placements = {
34
29
  * @property {String} body - Prefilled WhatsApp compose text.
35
30
  * @property {WhatsAppWidgetAppearance} appearance - Appearance overrides.
36
31
  */
37
- var WhatsApp = /*#__PURE__*/function () {
38
- function WhatsApp() {
39
- _classCallCheck(this, WhatsApp);
32
+ class WhatsApp {
33
+ static _id;
34
+ static _container = 'body';
35
+ static _placement = 'bottom-right';
36
+ static _appearance = {};
37
+ static _number = null;
38
+ static _body = null;
39
+ static set id(value) {
40
+ this._id = value;
40
41
  }
41
- _createClass(WhatsApp, null, [{
42
- key: "id",
43
- get: function get() {
44
- return this._id;
45
- },
46
- set: function set(value) {
47
- this._id = value;
42
+ static get id() {
43
+ return this._id;
44
+ }
45
+ static set container(value) {
46
+ this._container = value;
47
+ }
48
+ static get container() {
49
+ return this._container;
50
+ }
51
+ static set placement(value) {
52
+ if (!Object.values(placements).includes(value)) {
53
+ throw new Error(`Invalid placement value: ${value}`);
48
54
  }
49
- }, {
50
- key: "container",
51
- get: function get() {
52
- return this._container;
53
- },
54
- set: function set(value) {
55
- this._container = value;
55
+ this._placement = value;
56
+ }
57
+ static get placement() {
58
+ return this._placement;
59
+ }
60
+ static get appearance() {
61
+ return this._appearance;
62
+ }
63
+ static set appearance(value) {
64
+ if (!this.isPlainObject(value)) {
65
+ throw new Error('Appearance must be an object');
56
66
  }
57
- }, {
58
- key: "placement",
59
- get: function get() {
60
- return this._placement;
61
- },
62
- set: function set(value) {
63
- if (!Object.values(placements).includes(value)) {
64
- throw new Error("Invalid placement value: ".concat(value));
67
+ Object.entries(value).forEach(([key, nestedValue]) => {
68
+ if (key !== 'launcher') {
69
+ throw new Error(`Invalid appearance property: ${key}`);
65
70
  }
66
- this._placement = value;
67
- }
68
- }, {
69
- key: "appearance",
70
- get: function get() {
71
- return this._appearance;
72
- },
73
- set: function set(value) {
74
- if (!this.isPlainObject(value)) {
75
- throw new Error('Appearance must be an object');
71
+ if (!this.isPlainObject(nestedValue)) {
72
+ throw new Error(`Appearance ${key} must be an object`);
76
73
  }
77
- Object.entries(value).forEach(_ref => {
78
- var [key, nestedValue] = _ref;
79
- if (key !== 'launcher') {
80
- throw new Error("Invalid appearance property: ".concat(key));
74
+ Object.entries(nestedValue).forEach(([nestedKey, propertyValue]) => {
75
+ if (nestedKey !== 'iconUrl') {
76
+ throw new Error(`Invalid appearance launcher property: ${nestedKey}`);
77
+ }
78
+ if (propertyValue == null) {
79
+ return;
81
80
  }
82
- if (!this.isPlainObject(nestedValue)) {
83
- throw new Error("Appearance ".concat(key, " must be an object"));
81
+ if (typeof propertyValue !== 'string') {
82
+ throw new Error(`Invalid appearance ${key}.${nestedKey} value: ${propertyValue}`);
84
83
  }
85
- Object.entries(nestedValue).forEach(_ref2 => {
86
- var [nestedKey, propertyValue] = _ref2;
87
- if (nestedKey !== 'iconUrl') {
88
- throw new Error("Invalid appearance launcher property: ".concat(nestedKey));
89
- }
90
- if (propertyValue == null) {
91
- return;
92
- }
93
- if (typeof propertyValue !== 'string') {
94
- throw new Error("Invalid appearance ".concat(key, ".").concat(nestedKey, " value: ").concat(propertyValue));
95
- }
96
- });
97
84
  });
98
- this._appearance = value;
99
- }
100
- }, {
101
- key: "number",
102
- get: function get() {
103
- return this._number;
104
- },
105
- set: function set(value) {
106
- if (value != null && typeof value !== 'string') {
107
- throw new Error("Invalid number value: ".concat(value));
108
- }
109
- this._number = value;
110
- }
111
- }, {
112
- key: "body",
113
- get: function get() {
114
- return this._body;
115
- },
116
- set: function set(value) {
117
- if (value != null && typeof value !== 'string') {
118
- throw new Error("Invalid body value: ".concat(value));
119
- }
120
- this._body = value;
85
+ });
86
+ this._appearance = value;
87
+ }
88
+ static get number() {
89
+ return this._number;
90
+ }
91
+ static set number(value) {
92
+ if (value != null && typeof value !== 'string') {
93
+ throw new Error(`Invalid number value: ${value}`);
121
94
  }
122
- }, {
123
- key: "assign",
124
- value: function assign(props) {
125
- if (props) {
126
- Object.entries(props).forEach(_ref3 => {
127
- var [key, value] = _ref3;
128
- this[key] = value;
129
- });
130
- }
131
- return this;
95
+ this._number = value;
96
+ }
97
+ static get body() {
98
+ return this._body;
99
+ }
100
+ static set body(value) {
101
+ if (value != null && typeof value !== 'string') {
102
+ throw new Error(`Invalid body value: ${value}`);
132
103
  }
133
- }, {
134
- key: "isPlainObject",
135
- value: function isPlainObject(value) {
136
- return typeof value === 'object' && value !== null && !Array.isArray(value);
104
+ this._body = value;
105
+ }
106
+ static assign(props) {
107
+ if (props) {
108
+ Object.entries(props).forEach(([key, value]) => {
109
+ this[key] = value;
110
+ });
137
111
  }
138
- }]);
139
- return WhatsApp;
140
- }();
141
- WhatsApp._id = void 0;
142
- WhatsApp._container = 'body';
143
- WhatsApp._placement = 'bottom-right';
144
- WhatsApp._appearance = {};
145
- WhatsApp._number = null;
146
- WhatsApp._body = null;
112
+ return this;
113
+ }
114
+ static isPlainObject(value) {
115
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
116
+ }
117
+ }
147
118
  export { WhatsApp };
@@ -9,11 +9,6 @@ var _locale = require("./configuration/locale");
9
9
  var _webchat = require("./configuration/webchat");
10
10
  var _whatsapp = require("./configuration/whatsapp");
11
11
  var _push = require("./configuration/push");
12
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
13
- 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); } }
14
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
15
- function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
16
- 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); }
17
12
  /**
18
13
  * @class Configuration
19
14
  * @classdesc
@@ -26,80 +21,67 @@ function _toPrimitive(input, hint) { if (typeof input !== "object" || input ===
26
21
  * @property {Push} [push] - push subscription configuration
27
22
  * @property {Locale} [locale] - locale configuration
28
23
  */
29
- let Configuration = /*#__PURE__*/function () {
30
- function Configuration() {
31
- _classCallCheck(this, Configuration);
32
- }
33
- _createClass(Configuration, null, [{
34
- key: "assign",
35
- value:
36
- /**
37
- *
38
- * @param props
39
- * @param {Boolean} [props.autoGenerateSession=true] - whether to auto generate session or not
40
- * @param {String} [props.session] - session id
41
- * @param {Object} [props.forms] - form configuration
42
- * @returns {Configuration}
43
- */
44
- function assign(props) {
45
- if (props) {
46
- const shouldInferActionCableUrl = Object.prototype.hasOwnProperty.call(props, 'apiRoot') && !Object.prototype.hasOwnProperty.call(props, 'actionCableUrl');
47
- Object.entries(props).forEach(([key, value]) => {
48
- if (key === 'forms') {
49
- this.forms = _forms.Forms.assign(value);
50
- } else if (key === 'webchat') {
51
- this.webchat = _webchat.Webchat.assign(value);
52
- } else if (key === 'whatsappWidget') {
53
- this.whatsapp = _whatsapp.WhatsApp.assign(value);
54
- } else if (key === 'push') {
55
- this.push = _push.Push.assign(value);
56
- } else {
57
- this[key] = value;
58
- }
59
- });
60
- if (shouldInferActionCableUrl) {
61
- this.actionCableUrl = this.actionCableUrlForApiRoot(this.apiRoot);
24
+ class Configuration {
25
+ static apiRoot = 'https://api.hellotext.com/v1';
26
+ static actionCableUrl = 'wss://www.hellotext.com/cable';
27
+ static autoGenerateSession = true;
28
+ static session = null;
29
+ static forms = _forms.Forms;
30
+ static webchat = _webchat.Webchat;
31
+ static whatsapp = _whatsapp.WhatsApp;
32
+ static push = _push.Push;
33
+
34
+ /**
35
+ *
36
+ * @param props
37
+ * @param {Boolean} [props.autoGenerateSession=true] - whether to auto generate session or not
38
+ * @param {String} [props.session] - session id
39
+ * @param {Object} [props.forms] - form configuration
40
+ * @returns {Configuration}
41
+ */
42
+ static assign(props) {
43
+ if (props) {
44
+ const shouldInferActionCableUrl = Object.prototype.hasOwnProperty.call(props, 'apiRoot') && !Object.prototype.hasOwnProperty.call(props, 'actionCableUrl');
45
+ Object.entries(props).forEach(([key, value]) => {
46
+ if (key === 'forms') {
47
+ this.forms = _forms.Forms.assign(value);
48
+ } else if (key === 'webchat') {
49
+ this.webchat = _webchat.Webchat.assign(value);
50
+ } else if (key === 'whatsappWidget') {
51
+ this.whatsapp = _whatsapp.WhatsApp.assign(value);
52
+ } else if (key === 'push') {
53
+ this.push = _push.Push.assign(value);
54
+ } else {
55
+ this[key] = value;
62
56
  }
57
+ });
58
+ if (shouldInferActionCableUrl) {
59
+ this.actionCableUrl = this.actionCableUrlForApiRoot(this.apiRoot);
63
60
  }
64
- return this;
65
- }
66
- }, {
67
- key: "locale",
68
- get: function () {
69
- return _locale.Locale.toString();
70
- },
71
- set: function (locale) {
72
- _locale.Locale.identifier = locale;
73
61
  }
74
- }, {
75
- key: "endpoint",
76
- value: function endpoint(path) {
77
- return `${this.apiRoot}/${path}`;
78
- }
79
- }, {
80
- key: "actionCableUrlForApiRoot",
81
- value: function actionCableUrlForApiRoot(apiRoot) {
82
- try {
83
- const url = new URL(apiRoot);
84
- const protocol = url.protocol === 'https:' ? 'wss:' : 'ws:';
85
- url.protocol = protocol;
86
- url.pathname = '/cable';
87
- url.search = '';
88
- url.hash = '';
89
- return url.toString();
90
- } catch (_) {
91
- return this.actionCableUrl;
92
- }
62
+ return this;
63
+ }
64
+ static set locale(locale) {
65
+ _locale.Locale.identifier = locale;
66
+ }
67
+ static get locale() {
68
+ return _locale.Locale.toString();
69
+ }
70
+ static endpoint(path) {
71
+ return `${this.apiRoot}/${path}`;
72
+ }
73
+ static actionCableUrlForApiRoot(apiRoot) {
74
+ try {
75
+ const url = new URL(apiRoot);
76
+ const protocol = url.protocol === 'https:' ? 'wss:' : 'ws:';
77
+ url.protocol = protocol;
78
+ url.pathname = '/cable';
79
+ url.search = '';
80
+ url.hash = '';
81
+ return url.toString();
82
+ } catch (_) {
83
+ return this.actionCableUrl;
93
84
  }
94
- }]);
95
- return Configuration;
96
- }();
97
- exports.Configuration = Configuration;
98
- Configuration.apiRoot = 'https://api.hellotext.com/v1';
99
- Configuration.actionCableUrl = 'wss://www.hellotext.com/cable';
100
- Configuration.autoGenerateSession = true;
101
- Configuration.session = null;
102
- Configuration.forms = _forms.Forms;
103
- Configuration.webchat = _webchat.Webchat;
104
- Configuration.whatsapp = _whatsapp.WhatsApp;
105
- Configuration.push = _push.Push;
85
+ }
86
+ }
87
+ exports.Configuration = Configuration;
@@ -1,8 +1,3 @@
1
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
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); } }
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; }
4
- function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
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
1
  import { Forms } from './configuration/forms';
7
2
  import { Locale } from './configuration/locale';
8
3
  import { Webchat } from './configuration/webchat';
@@ -21,81 +16,67 @@ import { Push } from './configuration/push';
21
16
  * @property {Push} [push] - push subscription configuration
22
17
  * @property {Locale} [locale] - locale configuration
23
18
  */
24
- var Configuration = /*#__PURE__*/function () {
25
- function Configuration() {
26
- _classCallCheck(this, Configuration);
27
- }
28
- _createClass(Configuration, null, [{
29
- key: "assign",
30
- value:
31
- /**
32
- *
33
- * @param props
34
- * @param {Boolean} [props.autoGenerateSession=true] - whether to auto generate session or not
35
- * @param {String} [props.session] - session id
36
- * @param {Object} [props.forms] - form configuration
37
- * @returns {Configuration}
38
- */
39
- function assign(props) {
40
- if (props) {
41
- var shouldInferActionCableUrl = Object.prototype.hasOwnProperty.call(props, 'apiRoot') && !Object.prototype.hasOwnProperty.call(props, 'actionCableUrl');
42
- Object.entries(props).forEach(_ref => {
43
- var [key, value] = _ref;
44
- if (key === 'forms') {
45
- this.forms = Forms.assign(value);
46
- } else if (key === 'webchat') {
47
- this.webchat = Webchat.assign(value);
48
- } else if (key === 'whatsappWidget') {
49
- this.whatsapp = WhatsApp.assign(value);
50
- } else if (key === 'push') {
51
- this.push = Push.assign(value);
52
- } else {
53
- this[key] = value;
54
- }
55
- });
56
- if (shouldInferActionCableUrl) {
57
- this.actionCableUrl = this.actionCableUrlForApiRoot(this.apiRoot);
19
+ class Configuration {
20
+ static apiRoot = 'https://api.hellotext.com/v1';
21
+ static actionCableUrl = 'wss://www.hellotext.com/cable';
22
+ static autoGenerateSession = true;
23
+ static session = null;
24
+ static forms = Forms;
25
+ static webchat = Webchat;
26
+ static whatsapp = WhatsApp;
27
+ static push = Push;
28
+
29
+ /**
30
+ *
31
+ * @param props
32
+ * @param {Boolean} [props.autoGenerateSession=true] - whether to auto generate session or not
33
+ * @param {String} [props.session] - session id
34
+ * @param {Object} [props.forms] - form configuration
35
+ * @returns {Configuration}
36
+ */
37
+ static assign(props) {
38
+ if (props) {
39
+ const shouldInferActionCableUrl = Object.prototype.hasOwnProperty.call(props, 'apiRoot') && !Object.prototype.hasOwnProperty.call(props, 'actionCableUrl');
40
+ Object.entries(props).forEach(([key, value]) => {
41
+ if (key === 'forms') {
42
+ this.forms = Forms.assign(value);
43
+ } else if (key === 'webchat') {
44
+ this.webchat = Webchat.assign(value);
45
+ } else if (key === 'whatsappWidget') {
46
+ this.whatsapp = WhatsApp.assign(value);
47
+ } else if (key === 'push') {
48
+ this.push = Push.assign(value);
49
+ } else {
50
+ this[key] = value;
58
51
  }
52
+ });
53
+ if (shouldInferActionCableUrl) {
54
+ this.actionCableUrl = this.actionCableUrlForApiRoot(this.apiRoot);
59
55
  }
60
- return this;
61
- }
62
- }, {
63
- key: "locale",
64
- get: function get() {
65
- return Locale.toString();
66
- },
67
- set: function set(locale) {
68
- Locale.identifier = locale;
69
56
  }
70
- }, {
71
- key: "endpoint",
72
- value: function endpoint(path) {
73
- return "".concat(this.apiRoot, "/").concat(path);
74
- }
75
- }, {
76
- key: "actionCableUrlForApiRoot",
77
- value: function actionCableUrlForApiRoot(apiRoot) {
78
- try {
79
- var url = new URL(apiRoot);
80
- var protocol = url.protocol === 'https:' ? 'wss:' : 'ws:';
81
- url.protocol = protocol;
82
- url.pathname = '/cable';
83
- url.search = '';
84
- url.hash = '';
85
- return url.toString();
86
- } catch (_) {
87
- return this.actionCableUrl;
88
- }
57
+ return this;
58
+ }
59
+ static set locale(locale) {
60
+ Locale.identifier = locale;
61
+ }
62
+ static get locale() {
63
+ return Locale.toString();
64
+ }
65
+ static endpoint(path) {
66
+ return `${this.apiRoot}/${path}`;
67
+ }
68
+ static actionCableUrlForApiRoot(apiRoot) {
69
+ try {
70
+ const url = new URL(apiRoot);
71
+ const protocol = url.protocol === 'https:' ? 'wss:' : 'ws:';
72
+ url.protocol = protocol;
73
+ url.pathname = '/cable';
74
+ url.search = '';
75
+ url.hash = '';
76
+ return url.toString();
77
+ } catch (_) {
78
+ return this.actionCableUrl;
89
79
  }
90
- }]);
91
- return Configuration;
92
- }();
93
- Configuration.apiRoot = 'https://api.hellotext.com/v1';
94
- Configuration.actionCableUrl = 'wss://www.hellotext.com/cable';
95
- Configuration.autoGenerateSession = true;
96
- Configuration.session = null;
97
- Configuration.forms = Forms;
98
- Configuration.webchat = Webchat;
99
- Configuration.whatsapp = WhatsApp;
100
- Configuration.push = Push;
80
+ }
81
+ }
101
82
  export { Configuration };
@@ -5,67 +5,44 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = void 0;
7
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);
8
+ class Event {
9
+ static events = ['session-set', 'utm-set', 'forms:collected', 'form:completed', 'webchat:mounted', 'webchat:opened', 'webchat:closed', 'webchat:message:sent', 'webchat:message:received', 'cart.added'];
10
+ static valid(name) {
11
+ return Event.exists(name);
12
+ }
13
+ static invalid(name) {
14
+ return !this.valid(name);
15
+ }
16
+ static exists(name) {
17
+ return this.events.find(eventName => eventName === name) !== undefined;
18
+ }
19
+ constructor() {
16
20
  this.subscribers = {};
17
21
  }
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;
22
+ addSubscriber(eventName, callback) {
23
+ if (Event.invalid(eventName)) {
24
+ throw new _errors.InvalidEvent(eventName);
51
25
  }
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);
26
+ this.subscribers = {
27
+ ...this.subscribers,
28
+ [eventName]: this.subscribers[eventName] ? [...this.subscribers[eventName], callback] : [callback]
29
+ };
30
+ }
31
+ removeSubscriber(eventName, callback) {
32
+ if (Event.invalid(eventName)) {
33
+ throw new _errors.InvalidEvent(eventName);
61
34
  }
62
- }, {
63
- key: "exists",
64
- value: function exists(name) {
65
- return this.events.find(eventName => eventName === name) !== undefined;
35
+ if (this.subscribers[eventName]) {
36
+ this.subscribers[eventName] = this.subscribers[eventName].filter(cb => cb !== callback);
66
37
  }
67
- }]);
68
- return Event;
69
- }();
70
- exports.default = Event;
71
- Event.events = ['session-set', 'utm-set', 'forms:collected', 'form:completed', 'webchat:mounted', 'webchat:opened', 'webchat:closed', 'webchat:message:sent', 'webchat:message:received', 'cart.added'];
38
+ }
39
+ dispatch(eventName, data) {
40
+ this.subscribers[eventName]?.forEach(subscriber => {
41
+ subscriber(data);
42
+ });
43
+ }
44
+ get listeners() {
45
+ return Object.keys(this.subscribers).length !== 0;
46
+ }
47
+ }
48
+ exports.default = Event;