@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
package/lib/hellotext.cjs CHANGED
@@ -10,245 +10,207 @@ var _models = require("./models");
10
10
  var _errors = require("./errors");
11
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
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
- let Hellotext = /*#__PURE__*/function () {
19
- function Hellotext() {
20
- _classCallCheck(this, Hellotext);
21
- }
22
- _createClass(Hellotext, null, [{
23
- key: "initialize",
24
- value:
25
- /**
26
- * initialize the module.
27
- * @param business public business id
28
- * @param { Configuration } config
29
- */
30
- async function initialize(business, config = {}) {
31
- var _this$push, _businessData$push;
32
- (_this$push = this.push) === null || _this$push === void 0 ? void 0 : _this$push.dispose();
33
- this.push = null;
34
- this.business = new _models.Business(business);
35
- this.page = new _models.Page();
36
- _core.Configuration.assign({
37
- push: {},
38
- ...config
13
+ class Hellotext {
14
+ static eventEmitter = new _core.Event();
15
+ static forms;
16
+ static business;
17
+ static webchat;
18
+ static whatsapp;
19
+ static push;
20
+
21
+ /**
22
+ * initialize the module.
23
+ * @param business public business id
24
+ * @param { Configuration } config
25
+ */
26
+ static async initialize(business, config = {}) {
27
+ this.push?.dispose();
28
+ this.push = null;
29
+ this.business = new _models.Business(business);
30
+ this.page = new _models.Page();
31
+ _core.Configuration.assign({
32
+ push: {},
33
+ ...config
34
+ });
35
+ _models.Session.initialize(this.page);
36
+ this.forms = new _models.FormCollection();
37
+ this.query = new _models.Query();
38
+ const businessData = await this.business.hydrate();
39
+ if (config.push !== false && businessData?.push?.public_key && _models.Push.supported) {
40
+ this.push = new _models.Push(businessData.push);
41
+ this.push.initialize().catch(error => {
42
+ console.warn('Hellotext Push initialization failed:', error);
39
43
  });
40
- _models.Session.initialize(this.page);
41
- this.forms = new _models.FormCollection();
42
- this.query = new _models.Query();
43
- const businessData = await this.business.hydrate();
44
- if (config.push !== false && businessData !== null && businessData !== void 0 && (_businessData$push = businessData.push) !== null && _businessData$push !== void 0 && _businessData$push.public_key && _models.Push.supported) {
45
- this.push = new _models.Push(businessData.push);
46
- this.push.initialize().catch(error => {
47
- console.warn('Hellotext Push initialization failed:', error);
48
- });
49
- }
50
- const webchatConfig = config.webchat === false ? false : this.mergeWebchatConfig(businessData && businessData.webchat || {}, config.webchat || {});
51
- const whatsappConfig = config.whatsappWidget === false ? false : this.mergeWhatsAppConfig(businessData && businessData.whatsapp || {}, config.whatsappWidget || {});
52
- const hasExplicitBehaviourOverride = config.webchat && config.webchat !== false && Object.prototype.hasOwnProperty.call(config.webchat, 'behaviour');
53
- _core.Configuration.webchat.behaviourOverride = hasExplicitBehaviourOverride;
54
- if (webchatConfig && webchatConfig.id) {
55
- _core.Configuration.webchat.assign(webchatConfig);
56
- this.webchat = await _models.Webchat.load(webchatConfig.id);
57
- }
58
- if (whatsappConfig && whatsappConfig.id) {
59
- _core.Configuration.whatsapp.assign(whatsappConfig);
60
- this.whatsapp = await _models.WhatsAppWidget.load(whatsappConfig.id);
61
- }
62
- if (typeof MutationObserver !== 'undefined') {
63
- this.forms.collectExistingFormsOnPage();
64
- }
65
- }
66
- }, {
67
- key: "mergeWebchatConfig",
68
- value: function mergeWebchatConfig(dashboardConfig, localConfig) {
69
- return this.deepMergePlainObjects(dashboardConfig, localConfig);
70
44
  }
71
- }, {
72
- key: "mergeWhatsAppConfig",
73
- value: function mergeWhatsAppConfig(dashboardConfig, localConfig) {
74
- return this.deepMergePlainObjects(dashboardConfig, localConfig);
45
+ const webchatConfig = config.webchat === false ? false : this.mergeWebchatConfig(businessData && businessData.webchat || {}, config.webchat || {});
46
+ const whatsappConfig = config.whatsappWidget === false ? false : this.mergeWhatsAppConfig(businessData && businessData.whatsapp || {}, config.whatsappWidget || {});
47
+ const hasExplicitBehaviourOverride = config.webchat && config.webchat !== false && Object.prototype.hasOwnProperty.call(config.webchat, 'behaviour');
48
+ _core.Configuration.webchat.behaviourOverride = hasExplicitBehaviourOverride;
49
+ if (webchatConfig && webchatConfig.id) {
50
+ _core.Configuration.webchat.assign(webchatConfig);
51
+ this.webchat = await _models.Webchat.load(webchatConfig.id);
75
52
  }
76
- }, {
77
- key: "deepMergePlainObjects",
78
- value: function deepMergePlainObjects(base, override) {
79
- const result = {
80
- ...base
81
- };
82
- Object.entries(override).forEach(([key, value]) => {
83
- if (this.isPlainObject(value) && this.isPlainObject(result[key])) {
84
- result[key] = this.deepMergePlainObjects(result[key], value);
85
- } else {
86
- result[key] = value;
87
- }
88
- });
89
- return result;
53
+ if (whatsappConfig && whatsappConfig.id) {
54
+ _core.Configuration.whatsapp.assign(whatsappConfig);
55
+ this.whatsapp = await _models.WhatsAppWidget.load(whatsappConfig.id);
90
56
  }
91
- }, {
92
- key: "isPlainObject",
93
- value: function isPlainObject(value) {
94
- return typeof value === 'object' && value !== null && !Array.isArray(value);
57
+ if (typeof MutationObserver !== 'undefined') {
58
+ this.forms.collectExistingFormsOnPage();
95
59
  }
96
-
97
- /**
98
- * Tracks an action that has happened on the page
99
- *
100
- * @param { String } action a valid action name
101
- * @param { Object } params
102
- * @returns {Promise<Response>}
103
- */
104
- }, {
105
- key: "track",
106
- value: async function track(action, params = {}) {
107
- if (this.notInitialized) {
108
- throw new _errors.NotInitializedError();
60
+ }
61
+ static mergeWebchatConfig(dashboardConfig, localConfig) {
62
+ return this.deepMergePlainObjects(dashboardConfig, localConfig);
63
+ }
64
+ static mergeWhatsAppConfig(dashboardConfig, localConfig) {
65
+ return this.deepMergePlainObjects(dashboardConfig, localConfig);
66
+ }
67
+ static deepMergePlainObjects(base, override) {
68
+ const result = {
69
+ ...base
70
+ };
71
+ Object.entries(override).forEach(([key, value]) => {
72
+ if (this.isPlainObject(value) && this.isPlainObject(result[key])) {
73
+ result[key] = this.deepMergePlainObjects(result[key], value);
74
+ } else {
75
+ result[key] = value;
109
76
  }
110
- const headers = {
111
- ...(params && params.headers || {}),
112
- ...this.headers
113
- };
114
- const user_parameters = {
115
- ..._models.User.identificationData,
116
- ...(params.user_parameters || {})
117
- };
118
- const pageInstance = params && params.url ? new _models.Page(params.url) : this.page;
119
- const body = {
120
- session: this.session,
121
- user_parameters,
122
- action,
123
- ...params,
124
- ...pageInstance.trackingData
125
- };
126
- delete body.headers;
127
- return await _api.default.events.create({
128
- headers,
129
- body,
130
- // Track is the SDK's unload-sensitive analytics path. Keepalive belongs
131
- // here rather than on identify/forms/webchat calls because event tracking
132
- // is allowed to be fire-and-navigate, while those other calls have
133
- // stronger request/response or interaction contracts.
134
- keepalive: (0, _api.keepaliveFor)(body)
135
- });
77
+ });
78
+ return result;
79
+ }
80
+ static isPlainObject(value) {
81
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
82
+ }
83
+
84
+ /**
85
+ * Tracks an action that has happened on the page
86
+ *
87
+ * @param { String } action a valid action name
88
+ * @param { Object } params
89
+ * @returns {Promise<Response>}
90
+ */
91
+ static async track(action, params = {}) {
92
+ if (this.notInitialized) {
93
+ throw new _errors.NotInitializedError();
136
94
  }
95
+ const headers = {
96
+ ...(params && params.headers || {}),
97
+ ...this.headers
98
+ };
99
+ const user_parameters = {
100
+ ..._models.User.identificationData,
101
+ ...(params.user_parameters || {})
102
+ };
103
+ const pageInstance = params && params.url ? new _models.Page(params.url) : this.page;
104
+ const body = {
105
+ session: this.session,
106
+ user_parameters,
107
+ action,
108
+ ...params,
109
+ ...pageInstance.trackingData
110
+ };
111
+ delete body.headers;
112
+ return await _api.default.events.create({
113
+ headers,
114
+ body,
115
+ // Track is the SDK's unload-sensitive analytics path. Keepalive belongs
116
+ // here rather than on identify/forms/webchat calls because event tracking
117
+ // is allowed to be fire-and-navigate, while those other calls have
118
+ // stronger request/response or interaction contracts.
119
+ keepalive: (0, _api.keepaliveFor)(body)
120
+ });
121
+ }
137
122
 
138
- /**
139
- * @typedef { Object } IdentificationOptions
140
- * @property { String } [email] - the email of the user
141
- * @property { String } [phone] - the phone number of the user
142
- * @property { String } [name] - the name of the user
143
- * @property { String } [source] - the platform specific identifier where this pixel is running on.
144
- *
145
- * Identifies a user and attaches the hello_session to the user ID.
146
- * Repeated calls are skipped only when the last successful identify payload
147
- * for the current session remains unchanged.
148
- * @param { String } externalId - the user ID
149
- * @param { IdentificationOptions } options - the options for the identification
150
- * @returns {Promise<Response>}
151
- */
152
- }, {
153
- key: "identify",
154
- value: async function identify(externalId, options = {}) {
155
- const fingerprint = await _models.Fingerprint.generate(this.session, externalId, options);
156
- if (_models.Fingerprint.matches(_models.User.fingerprint, fingerprint)) {
157
- return new _api.Response(true, {
158
- json: async () => ({
159
- already_identified: true
160
- })
161
- });
162
- }
163
- const response = await _api.default.identifications.create({
164
- user_id: externalId,
165
- ...options
123
+ /**
124
+ * @typedef { Object } IdentificationOptions
125
+ * @property { String } [email] - the email of the user
126
+ * @property { String } [phone] - the phone number of the user
127
+ * @property { String } [name] - the name of the user
128
+ * @property { String } [source] - the platform specific identifier where this pixel is running on.
129
+ *
130
+ * Identifies a user and attaches the hello_session to the user ID.
131
+ * Repeated calls are skipped only when the last successful identify payload
132
+ * for the current session remains unchanged.
133
+ * @param { String } externalId - the user ID
134
+ * @param { IdentificationOptions } options - the options for the identification
135
+ * @returns {Promise<Response>}
136
+ */
137
+ static async identify(externalId, options = {}) {
138
+ const fingerprint = await _models.Fingerprint.generate(this.session, externalId, options);
139
+ if (_models.Fingerprint.matches(_models.User.fingerprint, fingerprint)) {
140
+ return new _api.Response(true, {
141
+ json: async () => ({
142
+ already_identified: true
143
+ })
166
144
  });
167
- if (response.succeeded) {
168
- _models.User.remember(externalId, options.source, fingerprint);
169
- }
170
- return response;
171
145
  }
172
-
173
- /**
174
- * Clears the user session, use when the user logs out to clear the hello cookies
175
- *
176
- * @returns {void}
177
- */
178
- }, {
179
- key: "forget",
180
- value: function forget() {
181
- _models.User.forget();
146
+ const response = await _api.default.identifications.create({
147
+ user_id: externalId,
148
+ ...options
149
+ });
150
+ if (response.succeeded) {
151
+ _models.User.remember(externalId, options.source, fingerprint);
182
152
  }
153
+ return response;
154
+ }
183
155
 
184
- /**
185
- * Registers an event listener
186
- * @param event the name of the event to listen to
187
- * @param callback the callback. This method will be called with the payload
188
- */
189
- }, {
190
- key: "on",
191
- value: function on(event, callback) {
192
- this.eventEmitter.addSubscriber(event, callback);
193
- }
156
+ /**
157
+ * Clears the user session, use when the user logs out to clear the hello cookies
158
+ *
159
+ * @returns {void}
160
+ */
161
+ static forget() {
162
+ _models.User.forget();
163
+ }
194
164
 
195
- /**
196
- * Removes an event listener
197
- * @param event the name of the event to remove
198
- * @param callback the callback to remove
199
- */
200
- }, {
201
- key: "removeEventListener",
202
- value: function removeEventListener(event, callback) {
203
- this.eventEmitter.removeSubscriber(event, callback);
204
- }
165
+ /**
166
+ * Registers an event listener
167
+ * @param event the name of the event to listen to
168
+ * @param callback the callback. This method will be called with the payload
169
+ */
170
+ static on(event, callback) {
171
+ this.eventEmitter.addSubscriber(event, callback);
172
+ }
205
173
 
206
- /**
207
- *
208
- * @returns {String}
209
- */
210
- }, {
211
- key: "session",
212
- get: function () {
213
- return _models.Session.session;
214
- }
174
+ /**
175
+ * Removes an event listener
176
+ * @param event the name of the event to remove
177
+ * @param callback the callback to remove
178
+ */
179
+ static removeEventListener(event, callback) {
180
+ this.eventEmitter.removeSubscriber(event, callback);
181
+ }
215
182
 
216
- /**
217
- * Determines if the session is set or not
218
- * @returns {boolean}
219
- */
220
- }, {
221
- key: "isInitialized",
222
- get: function () {
223
- return _models.Session.session !== undefined;
224
- }
183
+ /**
184
+ *
185
+ * @returns {String}
186
+ */
187
+ static get session() {
188
+ return _models.Session.session;
189
+ }
225
190
 
226
- // private
227
- }, {
228
- key: "notInitialized",
229
- get: function () {
230
- return !this.business || this.business.id === undefined;
231
- }
232
- }, {
233
- key: "headers",
234
- get: function () {
235
- if (this.notInitialized) {
236
- throw new _errors.NotInitializedError();
237
- }
238
- return {
239
- Authorization: `Bearer ${this.business.id}`,
240
- Accept: 'application/json',
241
- 'Content-Type': 'application/json'
242
- };
191
+ /**
192
+ * Determines if the session is set or not
193
+ * @returns {boolean}
194
+ */
195
+ static get isInitialized() {
196
+ return _models.Session.session !== undefined;
197
+ }
198
+
199
+ // private
200
+
201
+ static get notInitialized() {
202
+ return !this.business || this.business.id === undefined;
203
+ }
204
+ static get headers() {
205
+ if (this.notInitialized) {
206
+ throw new _errors.NotInitializedError();
243
207
  }
244
- }]);
245
- return Hellotext;
246
- }();
247
- Hellotext.eventEmitter = new _core.Event();
248
- Hellotext.forms = void 0;
249
- Hellotext.business = void 0;
250
- Hellotext.webchat = void 0;
251
- Hellotext.whatsapp = void 0;
252
- Hellotext.push = void 0;
208
+ return {
209
+ Authorization: `Bearer ${this.business.id}`,
210
+ Accept: 'application/json',
211
+ 'Content-Type': 'application/json'
212
+ };
213
+ }
214
+ }
253
215
  var _default = Hellotext;
254
216
  exports.default = _default;