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