@hellotext/hellotext 2.5.6 → 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 (113) hide show
  1. package/README.md +5 -26
  2. package/dist/hellotext.js +1 -1
  3. package/dist/hellotext.js.LICENSE.txt +1 -1
  4. package/index.d.ts +15 -6
  5. package/lib/api/acks.cjs +17 -31
  6. package/lib/api/acks.js +17 -42
  7. package/lib/api/businesses.cjs +14 -28
  8. package/lib/api/businesses.js +13 -36
  9. package/lib/api/events.cjs +26 -40
  10. package/lib/api/events.js +28 -52
  11. package/lib/api/forms.cjs +24 -40
  12. package/lib/api/forms.js +24 -57
  13. package/lib/api/identifications.cjs +15 -29
  14. package/lib/api/identifications.js +15 -40
  15. package/lib/api/index.cjs +26 -46
  16. package/lib/api/index.js +28 -49
  17. package/lib/api/push/identities.cjs +43 -0
  18. package/lib/api/push/identities.js +35 -0
  19. package/lib/api/response.cjs +30 -52
  20. package/lib/api/response.js +31 -60
  21. package/lib/api/submissions.cjs +18 -34
  22. package/lib/api/submissions.js +18 -48
  23. package/lib/api/webchat/messages.cjs +44 -64
  24. package/lib/api/webchat/messages.js +44 -80
  25. package/lib/api/webchats.cjs +37 -56
  26. package/lib/api/webchats.js +37 -65
  27. package/lib/api/whatsapp_widgets.cjs +49 -72
  28. package/lib/api/whatsapp_widgets.js +48 -91
  29. package/lib/builders/input_builder.cjs +36 -48
  30. package/lib/builders/input_builder.js +36 -48
  31. package/lib/builders/logo_builder.cjs +10 -29
  32. package/lib/builders/logo_builder.js +20 -28
  33. package/lib/channels/application_channel.cjs +136 -178
  34. package/lib/channels/application_channel.js +137 -180
  35. package/lib/channels/webchat_channel.cjs +125 -170
  36. package/lib/channels/webchat_channel.js +125 -170
  37. package/lib/controllers/form_controller.cjs +82 -121
  38. package/lib/controllers/form_controller.js +82 -130
  39. package/lib/controllers/message_controller.cjs +211 -282
  40. package/lib/controllers/message_controller.js +209 -284
  41. package/lib/controllers/mixins/usePopover.cjs +3 -6
  42. package/lib/controllers/mixins/usePopover.js +17 -22
  43. package/lib/controllers/webchat/emoji_picker_controller.cjs +106 -150
  44. package/lib/controllers/webchat/emoji_picker_controller.js +105 -170
  45. package/lib/controllers/webchat/useBehaviour.js +5 -5
  46. package/lib/controllers/webchat/useOpeningSequence.js +6 -6
  47. package/lib/controllers/webchat/useTeaser.js +9 -9
  48. package/lib/controllers/webchat_controller.cjs +916 -1088
  49. package/lib/controllers/webchat_controller.js +926 -1152
  50. package/lib/core/configuration/forms.cjs +21 -35
  51. package/lib/core/configuration/forms.js +20 -35
  52. package/lib/core/configuration/locale.cjs +36 -71
  53. package/lib/core/configuration/locale.js +36 -70
  54. package/lib/core/configuration/push.cjs +16 -0
  55. package/lib/core/configuration/push.js +10 -0
  56. package/lib/core/configuration/webchat.cjs +142 -182
  57. package/lib/core/configuration/webchat.js +145 -189
  58. package/lib/core/configuration/whatsapp.cjs +76 -102
  59. package/lib/core/configuration/whatsapp.js +76 -105
  60. package/lib/core/configuration.cjs +62 -75
  61. package/lib/core/configuration.js +61 -75
  62. package/lib/core/event.cjs +36 -59
  63. package/lib/core/event.js +35 -61
  64. package/lib/core/sanitize_html.js +4 -4
  65. package/lib/errors/invalid_event.cjs +5 -26
  66. package/lib/errors/invalid_event.js +5 -26
  67. package/lib/errors/not_initialized_error.cjs +5 -26
  68. package/lib/errors/not_initialized_error.js +5 -26
  69. package/lib/hellotext.cjs +186 -211
  70. package/lib/hellotext.js +189 -236
  71. package/lib/index.js +1 -1
  72. package/lib/models/business.cjs +115 -152
  73. package/lib/models/business.js +118 -162
  74. package/lib/models/cookies.cjs +34 -51
  75. package/lib/models/cookies.js +34 -51
  76. package/lib/models/fingerprint.cjs +8 -23
  77. package/lib/models/fingerprint.js +25 -58
  78. package/lib/models/form.cjs +106 -142
  79. package/lib/models/form.js +105 -153
  80. package/lib/models/form_collection.cjs +63 -101
  81. package/lib/models/form_collection.js +61 -107
  82. package/lib/models/index.cjs +7 -0
  83. package/lib/models/index.js +1 -0
  84. package/lib/models/page.cjs +106 -129
  85. package/lib/models/page.js +106 -131
  86. package/lib/models/push.cjs +345 -0
  87. package/lib/models/push.js +339 -0
  88. package/lib/models/query.cjs +21 -41
  89. package/lib/models/query.js +21 -41
  90. package/lib/models/session.cjs +33 -65
  91. package/lib/models/session.js +30 -63
  92. package/lib/models/user.cjs +29 -51
  93. package/lib/models/user.js +29 -51
  94. package/lib/models/utm.cjs +15 -27
  95. package/lib/models/utm.js +17 -32
  96. package/lib/models/webchat.cjs +52 -76
  97. package/lib/models/webchat.js +52 -90
  98. package/lib/models/whatsapp_widget.cjs +41 -59
  99. package/lib/models/whatsapp_widget.js +41 -73
  100. package/lib/vanilla.cjs +4 -7
  101. package/lib/vanilla.js +2 -1
  102. package/package.json +2 -10
  103. package/src/api/index.js +5 -0
  104. package/src/api/push/identities.js +42 -0
  105. package/src/core/configuration/push.js +12 -0
  106. package/src/core/configuration.js +5 -0
  107. package/src/hellotext.js +15 -1
  108. package/src/index.bundle.js +0 -1
  109. package/src/models/business.js +1 -0
  110. package/src/models/index.js +1 -0
  111. package/src/models/push.js +397 -0
  112. package/src/vanilla.js +2 -1
  113. 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 };
@@ -8,11 +8,7 @@ var _forms = require("./configuration/forms");
8
8
  var _locale = require("./configuration/locale");
9
9
  var _webchat = require("./configuration/webchat");
10
10
  var _whatsapp = require("./configuration/whatsapp");
11
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
12
- function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
13
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
14
- function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
15
- function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
11
+ var _push = require("./configuration/push");
16
12
  /**
17
13
  * @class Configuration
18
14
  * @classdesc
@@ -22,79 +18,70 @@ function _toPrimitive(input, hint) { if (typeof input !== "object" || input ===
22
18
  * @property {Forms} [forms] - form configuration
23
19
  * @property {Webchat} [webchat] - webchat configuration
24
20
  * @property {WhatsApp} [whatsappWidget] - WhatsApp widget configuration
21
+ * @property {Push} [push] - push subscription configuration
25
22
  * @property {Locale} [locale] - locale configuration
26
23
  */
27
- let Configuration = /*#__PURE__*/function () {
28
- function Configuration() {
29
- _classCallCheck(this, Configuration);
30
- }
31
- _createClass(Configuration, null, [{
32
- key: "assign",
33
- value:
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
- function 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 {
53
- this[key] = value;
54
- }
55
- });
56
- if (shouldInferActionCableUrl) {
57
- 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;
58
56
  }
57
+ });
58
+ if (shouldInferActionCableUrl) {
59
+ this.actionCableUrl = this.actionCableUrlForApiRoot(this.apiRoot);
59
60
  }
60
- return this;
61
- }
62
- }, {
63
- key: "locale",
64
- get: function () {
65
- return _locale.Locale.toString();
66
- },
67
- set: function (locale) {
68
- _locale.Locale.identifier = locale;
69
61
  }
70
- }, {
71
- key: "endpoint",
72
- value: function endpoint(path) {
73
- return `${this.apiRoot}/${path}`;
74
- }
75
- }, {
76
- key: "actionCableUrlForApiRoot",
77
- value: function actionCableUrlForApiRoot(apiRoot) {
78
- try {
79
- const url = new URL(apiRoot);
80
- const 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
- }
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;
89
84
  }
90
- }]);
91
- return Configuration;
92
- }();
93
- exports.Configuration = Configuration;
94
- Configuration.apiRoot = 'https://api.hellotext.com/v1';
95
- Configuration.actionCableUrl = 'wss://www.hellotext.com/cable';
96
- Configuration.autoGenerateSession = true;
97
- Configuration.session = null;
98
- Configuration.forms = _forms.Forms;
99
- Configuration.webchat = _webchat.Webchat;
100
- Configuration.whatsapp = _whatsapp.WhatsApp;
85
+ }
86
+ }
87
+ exports.Configuration = Configuration;
@@ -1,12 +1,8 @@
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';
9
4
  import { WhatsApp } from './configuration/whatsapp';
5
+ import { Push } from './configuration/push';
10
6
 
11
7
  /**
12
8
  * @class Configuration
@@ -17,80 +13,70 @@ import { WhatsApp } from './configuration/whatsapp';
17
13
  * @property {Forms} [forms] - form configuration
18
14
  * @property {Webchat} [webchat] - webchat configuration
19
15
  * @property {WhatsApp} [whatsappWidget] - WhatsApp widget configuration
16
+ * @property {Push} [push] - push subscription configuration
20
17
  * @property {Locale} [locale] - locale configuration
21
18
  */
22
- var Configuration = /*#__PURE__*/function () {
23
- function Configuration() {
24
- _classCallCheck(this, Configuration);
25
- }
26
- _createClass(Configuration, null, [{
27
- key: "assign",
28
- value:
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
- function assign(props) {
38
- if (props) {
39
- var shouldInferActionCableUrl = Object.prototype.hasOwnProperty.call(props, 'apiRoot') && !Object.prototype.hasOwnProperty.call(props, 'actionCableUrl');
40
- Object.entries(props).forEach(_ref => {
41
- var [key, value] = _ref;
42
- if (key === 'forms') {
43
- this.forms = Forms.assign(value);
44
- } else if (key === 'webchat') {
45
- this.webchat = Webchat.assign(value);
46
- } else if (key === 'whatsappWidget') {
47
- this.whatsapp = WhatsApp.assign(value);
48
- } else {
49
- this[key] = value;
50
- }
51
- });
52
- if (shouldInferActionCableUrl) {
53
- 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;
54
51
  }
52
+ });
53
+ if (shouldInferActionCableUrl) {
54
+ this.actionCableUrl = this.actionCableUrlForApiRoot(this.apiRoot);
55
55
  }
56
- return this;
57
- }
58
- }, {
59
- key: "locale",
60
- get: function get() {
61
- return Locale.toString();
62
- },
63
- set: function set(locale) {
64
- Locale.identifier = locale;
65
56
  }
66
- }, {
67
- key: "endpoint",
68
- value: function endpoint(path) {
69
- return "".concat(this.apiRoot, "/").concat(path);
70
- }
71
- }, {
72
- key: "actionCableUrlForApiRoot",
73
- value: function actionCableUrlForApiRoot(apiRoot) {
74
- try {
75
- var url = new URL(apiRoot);
76
- var 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;
84
- }
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;
85
79
  }
86
- }]);
87
- return Configuration;
88
- }();
89
- Configuration.apiRoot = 'https://api.hellotext.com/v1';
90
- Configuration.actionCableUrl = 'wss://www.hellotext.com/cable';
91
- Configuration.autoGenerateSession = true;
92
- Configuration.session = null;
93
- Configuration.forms = Forms;
94
- Configuration.webchat = Webchat;
95
- Configuration.whatsapp = WhatsApp;
80
+ }
81
+ }
96
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;