@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
@@ -7,61 +7,44 @@ exports.Cookies = void 0;
7
7
  var _hellotext = _interopRequireDefault(require("../hellotext"));
8
8
  var _page = require("./page");
9
9
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
10
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
11
- 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); } }
12
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
13
- function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
14
- 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); }
15
- let Cookies = /*#__PURE__*/function () {
16
- function Cookies() {
17
- _classCallCheck(this, Cookies);
18
- }
19
- _createClass(Cookies, null, [{
20
- key: "set",
21
- value: function set(name, value) {
22
- if (typeof document !== 'undefined') {
23
- const secure = window.location.protocol === 'https:' ? '; Secure' : '';
24
- const domain = _page.Page.getRootDomain();
25
- const maxAge = 10 * 365 * 24 * 60 * 60; // 10 years in seconds
10
+ class Cookies {
11
+ static set(name, value) {
12
+ if (typeof document !== 'undefined') {
13
+ const secure = window.location.protocol === 'https:' ? '; Secure' : '';
14
+ const domain = _page.Page.getRootDomain();
15
+ const maxAge = 10 * 365 * 24 * 60 * 60; // 10 years in seconds
26
16
 
27
- if (domain) {
28
- document.cookie = `${name}=${value}; path=/${secure}; domain=${domain}; max-age=${maxAge}; SameSite=Lax`;
29
- } else {
30
- document.cookie = `${name}=${value}; path=/${secure}; max-age=${maxAge}; SameSite=Lax`;
31
- }
32
- }
33
- if (name === 'hello_session') {
34
- _hellotext.default.eventEmitter.dispatch('session-set', value);
35
- }
36
- if (name === 'hello_utm') {
37
- _hellotext.default.eventEmitter.dispatch('utm-set', value);
38
- }
39
- return value;
40
- }
41
- }, {
42
- key: "get",
43
- value: function get(name) {
44
- if (typeof document !== 'undefined') {
45
- var _document$cookie$matc;
46
- return (_document$cookie$matc = document.cookie.match('(^|;)\\s*' + name + '\\s*=\\s*([^;]+)')) === null || _document$cookie$matc === void 0 ? void 0 : _document$cookie$matc.pop();
17
+ if (domain) {
18
+ document.cookie = `${name}=${value}; path=/${secure}; domain=${domain}; max-age=${maxAge}; SameSite=Lax`;
47
19
  } else {
48
- return undefined;
20
+ document.cookie = `${name}=${value}; path=/${secure}; max-age=${maxAge}; SameSite=Lax`;
49
21
  }
50
22
  }
51
- }, {
52
- key: "delete",
53
- value: function _delete(name) {
54
- if (typeof document !== 'undefined') {
55
- const domain = _page.Page.getRootDomain();
56
- const secure = window.location.protocol === 'https:' ? '; Secure' : '';
57
- if (domain) {
58
- document.cookie = `${name}=; path=/; expires=Thu, 01 Jan 1970 00:00:00 GMT${secure}; domain=${domain}; SameSite=Lax`;
59
- } else {
60
- document.cookie = `${name}=; path=/; expires=Thu, 01 Jan 1970 00:00:00 GMT${secure}; SameSite=Lax`;
61
- }
23
+ if (name === 'hello_session') {
24
+ _hellotext.default.eventEmitter.dispatch('session-set', value);
25
+ }
26
+ if (name === 'hello_utm') {
27
+ _hellotext.default.eventEmitter.dispatch('utm-set', value);
28
+ }
29
+ return value;
30
+ }
31
+ static get(name) {
32
+ if (typeof document !== 'undefined') {
33
+ return document.cookie.match('(^|;)\\s*' + name + '\\s*=\\s*([^;]+)')?.pop();
34
+ } else {
35
+ return undefined;
36
+ }
37
+ }
38
+ static delete(name) {
39
+ if (typeof document !== 'undefined') {
40
+ const domain = _page.Page.getRootDomain();
41
+ const secure = window.location.protocol === 'https:' ? '; Secure' : '';
42
+ if (domain) {
43
+ document.cookie = `${name}=; path=/; expires=Thu, 01 Jan 1970 00:00:00 GMT${secure}; domain=${domain}; SameSite=Lax`;
44
+ } else {
45
+ document.cookie = `${name}=; path=/; expires=Thu, 01 Jan 1970 00:00:00 GMT${secure}; SameSite=Lax`;
62
46
  }
63
47
  }
64
- }]);
65
- return Cookies;
66
- }();
48
+ }
49
+ }
67
50
  exports.Cookies = Cookies;
@@ -1,60 +1,43 @@
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 Hellotext from '../hellotext';
7
2
  import { Page } from './page';
8
- var Cookies = /*#__PURE__*/function () {
9
- function Cookies() {
10
- _classCallCheck(this, Cookies);
11
- }
12
- _createClass(Cookies, null, [{
13
- key: "set",
14
- value: function set(name, value) {
15
- if (typeof document !== 'undefined') {
16
- var secure = window.location.protocol === 'https:' ? '; Secure' : '';
17
- var domain = Page.getRootDomain();
18
- var maxAge = 10 * 365 * 24 * 60 * 60; // 10 years in seconds
3
+ class Cookies {
4
+ static set(name, value) {
5
+ if (typeof document !== 'undefined') {
6
+ const secure = window.location.protocol === 'https:' ? '; Secure' : '';
7
+ const domain = Page.getRootDomain();
8
+ const maxAge = 10 * 365 * 24 * 60 * 60; // 10 years in seconds
19
9
 
20
- if (domain) {
21
- document.cookie = "".concat(name, "=").concat(value, "; path=/").concat(secure, "; domain=").concat(domain, "; max-age=").concat(maxAge, "; SameSite=Lax");
22
- } else {
23
- document.cookie = "".concat(name, "=").concat(value, "; path=/").concat(secure, "; max-age=").concat(maxAge, "; SameSite=Lax");
24
- }
25
- }
26
- if (name === 'hello_session') {
27
- Hellotext.eventEmitter.dispatch('session-set', value);
28
- }
29
- if (name === 'hello_utm') {
30
- Hellotext.eventEmitter.dispatch('utm-set', value);
31
- }
32
- return value;
33
- }
34
- }, {
35
- key: "get",
36
- value: function get(name) {
37
- if (typeof document !== 'undefined') {
38
- var _document$cookie$matc;
39
- return (_document$cookie$matc = document.cookie.match('(^|;)\\s*' + name + '\\s*=\\s*([^;]+)')) === null || _document$cookie$matc === void 0 ? void 0 : _document$cookie$matc.pop();
10
+ if (domain) {
11
+ document.cookie = `${name}=${value}; path=/${secure}; domain=${domain}; max-age=${maxAge}; SameSite=Lax`;
40
12
  } else {
41
- return undefined;
13
+ document.cookie = `${name}=${value}; path=/${secure}; max-age=${maxAge}; SameSite=Lax`;
42
14
  }
43
15
  }
44
- }, {
45
- key: "delete",
46
- value: function _delete(name) {
47
- if (typeof document !== 'undefined') {
48
- var domain = Page.getRootDomain();
49
- var secure = window.location.protocol === 'https:' ? '; Secure' : '';
50
- if (domain) {
51
- document.cookie = "".concat(name, "=; path=/; expires=Thu, 01 Jan 1970 00:00:00 GMT").concat(secure, "; domain=").concat(domain, "; SameSite=Lax");
52
- } else {
53
- document.cookie = "".concat(name, "=; path=/; expires=Thu, 01 Jan 1970 00:00:00 GMT").concat(secure, "; SameSite=Lax");
54
- }
16
+ if (name === 'hello_session') {
17
+ Hellotext.eventEmitter.dispatch('session-set', value);
18
+ }
19
+ if (name === 'hello_utm') {
20
+ Hellotext.eventEmitter.dispatch('utm-set', value);
21
+ }
22
+ return value;
23
+ }
24
+ static get(name) {
25
+ if (typeof document !== 'undefined') {
26
+ return document.cookie.match('(^|;)\\s*' + name + '\\s*=\\s*([^;]+)')?.pop();
27
+ } else {
28
+ return undefined;
29
+ }
30
+ }
31
+ static delete(name) {
32
+ if (typeof document !== 'undefined') {
33
+ const domain = Page.getRootDomain();
34
+ const secure = window.location.protocol === 'https:' ? '; Secure' : '';
35
+ if (domain) {
36
+ document.cookie = `${name}=; path=/; expires=Thu, 01 Jan 1970 00:00:00 GMT${secure}; domain=${domain}; SameSite=Lax`;
37
+ } else {
38
+ document.cookie = `${name}=; path=/; expires=Thu, 01 Jan 1970 00:00:00 GMT${secure}; SameSite=Lax`;
55
39
  }
56
40
  }
57
- }]);
58
- return Cookies;
59
- }();
41
+ }
42
+ }
60
43
  export { Cookies };
@@ -4,11 +4,6 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.Fingerprint = void 0;
7
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
8
- 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); } }
9
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
10
- function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
11
- 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); }
12
7
  function normalizeValue(value) {
13
8
  // Collapse "missing" values so callers can add optional fields incrementally
14
9
  // without changing the fingerprint when the effective payload is the same.
@@ -61,29 +56,19 @@ function fallbackHash(value) {
61
56
  return `v1:${(hash >>> 0).toString(16)}`;
62
57
  }
63
58
  async function sha256(value) {
64
- var _globalThis$crypto;
65
- if (!((_globalThis$crypto = globalThis.crypto) !== null && _globalThis$crypto !== void 0 && _globalThis$crypto.subtle) || typeof TextEncoder === 'undefined') {
59
+ if (!globalThis.crypto?.subtle || typeof TextEncoder === 'undefined') {
66
60
  return fallbackHash(value);
67
61
  }
68
62
  const digest = await globalThis.crypto.subtle.digest('SHA-256', new TextEncoder().encode(value));
69
63
  const hex = Array.from(new Uint8Array(digest)).map(byte => byte.toString(16).padStart(2, '0')).join('');
70
64
  return `v1:${hex}`;
71
65
  }
72
- let Fingerprint = /*#__PURE__*/function () {
73
- function Fingerprint() {
74
- _classCallCheck(this, Fingerprint);
66
+ class Fingerprint {
67
+ static matches(storedFingerprint, fingerprint) {
68
+ return !!storedFingerprint && storedFingerprint === fingerprint;
75
69
  }
76
- _createClass(Fingerprint, null, [{
77
- key: "matches",
78
- value: function matches(storedFingerprint, fingerprint) {
79
- return !!storedFingerprint && storedFingerprint === fingerprint;
80
- }
81
- }, {
82
- key: "generate",
83
- value: async function generate(session, userId, options = {}) {
84
- return await sha256(serializePayload(session, userId, options));
85
- }
86
- }]);
87
- return Fingerprint;
88
- }();
70
+ static async generate(session, userId, options = {}) {
71
+ return await sha256(serializePayload(session, userId, options));
72
+ }
73
+ }
89
74
  exports.Fingerprint = Fingerprint;
@@ -1,13 +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 asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
5
- function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
6
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
7
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
8
- function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
9
- function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
10
- function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
11
1
  function normalizeValue(value) {
12
2
  // Collapse "missing" values so callers can add optional fields incrementally
13
3
  // without changing the fingerprint when the effective payload is the same.
@@ -15,7 +5,7 @@ function normalizeValue(value) {
15
5
  return undefined;
16
6
  }
17
7
  if (typeof value === 'string') {
18
- var trimmedValue = value.trim();
8
+ const trimmedValue = value.trim();
19
9
 
20
10
  // Treat blank strings as absent values so "" and an omitted field compare equally.
21
11
  return trimmedValue === '' ? undefined : trimmedValue;
@@ -30,8 +20,8 @@ function normalizeValue(value) {
30
20
  }
31
21
  if (typeof value === 'object') {
32
22
  // Canonicalize object shape by sorting keys recursively, so key placement never affects equality.
33
- var normalizedObject = Object.keys(value).sort((leftKey, rightKey) => leftKey.localeCompare(rightKey)).reduce((result, key) => {
34
- var normalizedChild = normalizeValue(value[key]);
23
+ const normalizedObject = Object.keys(value).sort((leftKey, rightKey) => leftKey.localeCompare(rightKey)).reduce((result, key) => {
24
+ const normalizedChild = normalizeValue(value[key]);
35
25
  if (normalizedChild !== undefined) {
36
26
  result[key] = normalizedChild;
37
27
  }
@@ -44,58 +34,35 @@ function normalizeValue(value) {
44
34
  }
45
35
  return undefined;
46
36
  }
47
- function serializePayload(session, userId) {
48
- var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
49
- var normalizedPayload = normalizeValue(_objectSpread({
37
+ function serializePayload(session, userId, options = {}) {
38
+ const normalizedPayload = normalizeValue({
50
39
  session,
51
- user_id: userId
52
- }, options)) || {};
40
+ user_id: userId,
41
+ ...options
42
+ }) || {};
53
43
  return JSON.stringify(normalizedPayload);
54
44
  }
55
45
  function fallbackHash(value) {
56
- var hash = 5381;
57
- for (var index = 0; index < value.length; index += 1) {
46
+ let hash = 5381;
47
+ for (let index = 0; index < value.length; index += 1) {
58
48
  hash = hash * 33 ^ value.charCodeAt(index);
59
49
  }
60
- return "v1:".concat((hash >>> 0).toString(16));
50
+ return `v1:${(hash >>> 0).toString(16)}`;
61
51
  }
62
- function sha256(_x) {
63
- return _sha.apply(this, arguments);
64
- }
65
- function _sha() {
66
- _sha = _asyncToGenerator(function* (value) {
67
- var _globalThis$crypto;
68
- if (!((_globalThis$crypto = globalThis.crypto) !== null && _globalThis$crypto !== void 0 && _globalThis$crypto.subtle) || typeof TextEncoder === 'undefined') {
69
- return fallbackHash(value);
70
- }
71
- var digest = yield globalThis.crypto.subtle.digest('SHA-256', new TextEncoder().encode(value));
72
- var hex = Array.from(new Uint8Array(digest)).map(byte => byte.toString(16).padStart(2, '0')).join('');
73
- return "v1:".concat(hex);
74
- });
75
- return _sha.apply(this, arguments);
52
+ async function sha256(value) {
53
+ if (!globalThis.crypto?.subtle || typeof TextEncoder === 'undefined') {
54
+ return fallbackHash(value);
55
+ }
56
+ const digest = await globalThis.crypto.subtle.digest('SHA-256', new TextEncoder().encode(value));
57
+ const hex = Array.from(new Uint8Array(digest)).map(byte => byte.toString(16).padStart(2, '0')).join('');
58
+ return `v1:${hex}`;
76
59
  }
77
- var Fingerprint = /*#__PURE__*/function () {
78
- function Fingerprint() {
79
- _classCallCheck(this, Fingerprint);
60
+ class Fingerprint {
61
+ static matches(storedFingerprint, fingerprint) {
62
+ return !!storedFingerprint && storedFingerprint === fingerprint;
80
63
  }
81
- _createClass(Fingerprint, null, [{
82
- key: "matches",
83
- value: function matches(storedFingerprint, fingerprint) {
84
- return !!storedFingerprint && storedFingerprint === fingerprint;
85
- }
86
- }, {
87
- key: "generate",
88
- value: function () {
89
- var _generate = _asyncToGenerator(function* (session, userId) {
90
- var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
91
- return yield sha256(serializePayload(session, userId, options));
92
- });
93
- function generate(_x2, _x3) {
94
- return _generate.apply(this, arguments);
95
- }
96
- return generate;
97
- }()
98
- }]);
99
- return Fingerprint;
100
- }();
64
+ static async generate(session, userId, options = {}) {
65
+ return await sha256(serializePayload(session, userId, options));
66
+ }
67
+ }
101
68
  export { Fingerprint };
@@ -9,159 +9,123 @@ var _input_builder = require("../builders/input_builder");
9
9
  var _logo_builder = require("../builders/logo_builder");
10
10
  var _sanitize_html = require("../core/sanitize_html");
11
11
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
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
- function _classPrivateFieldLooseBase(receiver, privateKey) { if (!Object.prototype.hasOwnProperty.call(receiver, privateKey)) { throw new TypeError("attempted to use private field on non-instance"); } return receiver; }
18
- var id = 0;
19
- function _classPrivateFieldLooseKey(name) { return "__private_" + id++ + "_" + name; }
20
- var _findOrCreateComponent = /*#__PURE__*/_classPrivateFieldLooseKey("findOrCreateComponent");
21
- let Form = /*#__PURE__*/function () {
22
- function Form(data, element = null) {
23
- _classCallCheck(this, Form);
24
- Object.defineProperty(this, _findOrCreateComponent, {
25
- value: _findOrCreateComponent2
26
- });
12
+ class Form {
13
+ constructor(data, element = null) {
27
14
  this.data = data;
28
15
  this.element = element || document.querySelector(`[data-hello-form="${this.id}"]`) || document.createElement('form');
29
16
  }
30
- _createClass(Form, [{
31
- key: "mount",
32
- value: async function mount({
33
- ifCompleted = true
34
- } = {}) {
35
- if (ifCompleted && this.hasBeenCompleted) {
36
- var _this$element;
37
- (_this$element = this.element) === null || _this$element === void 0 ? void 0 : _this$element.remove();
38
- return _hellotext.default.eventEmitter.dispatch('form:completed', {
39
- id: this.id,
40
- ...JSON.parse(localStorage.getItem(`hello-form-${this.id}`))
41
- });
42
- }
43
- const firstStep = this.data.steps[0];
44
- this.buildHeader(firstStep.header);
45
- this.buildInputs(firstStep.inputs);
46
- this.buildButton(firstStep.button);
47
- this.buildFooter(firstStep.footer);
48
- this.elementAttributes.forEach(attribute => {
49
- this.element.setAttribute(attribute.name, attribute.value);
17
+ async mount({
18
+ ifCompleted = true
19
+ } = {}) {
20
+ if (ifCompleted && this.hasBeenCompleted) {
21
+ this.element?.remove();
22
+ return _hellotext.default.eventEmitter.dispatch('form:completed', {
23
+ id: this.id,
24
+ ...JSON.parse(localStorage.getItem(`hello-form-${this.id}`))
50
25
  });
51
- if (!document.contains(this.element)) {
52
- document.body.appendChild(this.element);
53
- }
54
- if (!_hellotext.default.business.features.white_label) {
55
- this.element.prepend(_logo_builder.LogoBuilder.build());
56
- }
57
26
  }
58
- }, {
59
- key: "buildHeader",
60
- value: function buildHeader(header) {
61
- const headerElement = _classPrivateFieldLooseBase(this, _findOrCreateComponent)[_findOrCreateComponent]('[data-form-header]', 'header');
62
- (0, _sanitize_html.setSanitizedRichText)(headerElement, header.content);
63
- if (this.element.querySelector('[data-form-header]')) {
64
- this.element.querySelector('[data-form-header]').replaceWith(headerElement);
65
- } else {
66
- this.element.prepend(headerElement);
67
- }
68
- }
69
- }, {
70
- key: "buildInputs",
71
- value: function buildInputs(inputs) {
72
- const inputsContainerElement = _classPrivateFieldLooseBase(this, _findOrCreateComponent)[_findOrCreateComponent]('[data-form-inputs]', 'main');
73
- const inputElements = inputs.map(input => _input_builder.InputBuilder.build(input));
74
- inputElements.forEach(inputElement => inputsContainerElement.appendChild(inputElement));
75
- if (this.element.querySelector('[data-form-inputs]')) {
76
- this.element.querySelector('[data-form-inputs]').replaceWith(inputsContainerElement);
77
- } else {
78
- this.element.querySelector('[data-form-header]').insertAdjacentHTML('afterend', inputsContainerElement.outerHTML);
79
- }
27
+ const firstStep = this.data.steps[0];
28
+ this.buildHeader(firstStep.header);
29
+ this.buildInputs(firstStep.inputs);
30
+ this.buildButton(firstStep.button);
31
+ this.buildFooter(firstStep.footer);
32
+ this.elementAttributes.forEach(attribute => {
33
+ this.element.setAttribute(attribute.name, attribute.value);
34
+ });
35
+ if (!document.contains(this.element)) {
36
+ document.body.appendChild(this.element);
80
37
  }
81
- }, {
82
- key: "buildButton",
83
- value: function buildButton(button) {
84
- const buttonElement = _classPrivateFieldLooseBase(this, _findOrCreateComponent)[_findOrCreateComponent]('[data-form-button]', 'button');
85
- buttonElement.innerText = button.text;
86
- buttonElement.setAttribute('data-action', 'click->hellotext--form#submit');
87
- buttonElement.setAttribute('data-hellotext--form-target', 'button');
88
- if (this.element.querySelector('[data-form-button]')) {
89
- this.element.querySelector('[data-form-button]').replaceWith(buttonElement);
90
- } else {
91
- this.element.querySelector('[data-form-inputs]').insertAdjacentHTML('afterend', buttonElement.outerHTML);
92
- }
38
+ if (!_hellotext.default.business.features.white_label) {
39
+ this.element.prepend(_logo_builder.LogoBuilder.build());
93
40
  }
94
- }, {
95
- key: "buildFooter",
96
- value: function buildFooter(footer) {
97
- const element = _classPrivateFieldLooseBase(this, _findOrCreateComponent)[_findOrCreateComponent]('[data-form-footer]', 'footer');
98
- (0, _sanitize_html.setSanitizedRichText)(element, footer.content);
99
- if (this.element.querySelector('[data-form-footer]')) {
100
- this.element.querySelector('[data-form-footer]').replaceWith(element);
101
- } else {
102
- this.element.appendChild(element);
103
- }
41
+ }
42
+ buildHeader(header) {
43
+ const headerElement = this.#findOrCreateComponent('[data-form-header]', 'header');
44
+ (0, _sanitize_html.setSanitizedRichText)(headerElement, header.content);
45
+ if (this.element.querySelector('[data-form-header]')) {
46
+ this.element.querySelector('[data-form-header]').replaceWith(headerElement);
47
+ } else {
48
+ this.element.prepend(headerElement);
104
49
  }
105
- }, {
106
- key: "markAsCompleted",
107
- value: function markAsCompleted(data) {
108
- const payload = {
109
- state: 'completed',
110
- id: this.id,
111
- data,
112
- completedAt: new Date().getTime()
113
- };
114
- localStorage.setItem(`hello-form-${this.id}`, JSON.stringify(payload));
115
- _hellotext.default.eventEmitter.dispatch('form:completed', payload);
50
+ }
51
+ buildInputs(inputs) {
52
+ const inputsContainerElement = this.#findOrCreateComponent('[data-form-inputs]', 'main');
53
+ const inputElements = inputs.map(input => _input_builder.InputBuilder.build(input));
54
+ inputElements.forEach(inputElement => inputsContainerElement.appendChild(inputElement));
55
+ if (this.element.querySelector('[data-form-inputs]')) {
56
+ this.element.querySelector('[data-form-inputs]').replaceWith(inputsContainerElement);
57
+ } else {
58
+ this.element.querySelector('[data-form-header]').insertAdjacentHTML('afterend', inputsContainerElement.outerHTML);
116
59
  }
117
- }, {
118
- key: "hasBeenCompleted",
119
- get: function () {
120
- return localStorage.getItem(`hello-form-${this.id}`) !== null;
60
+ }
61
+ buildButton(button) {
62
+ const buttonElement = this.#findOrCreateComponent('[data-form-button]', 'button');
63
+ buttonElement.innerText = button.text;
64
+ buttonElement.setAttribute('data-action', 'click->hellotext--form#submit');
65
+ buttonElement.setAttribute('data-hellotext--form-target', 'button');
66
+ if (this.element.querySelector('[data-form-button]')) {
67
+ this.element.querySelector('[data-form-button]').replaceWith(buttonElement);
68
+ } else {
69
+ this.element.querySelector('[data-form-inputs]').insertAdjacentHTML('afterend', buttonElement.outerHTML);
121
70
  }
122
- }, {
123
- key: "id",
124
- get: function () {
125
- return this.data.id;
71
+ }
72
+ buildFooter(footer) {
73
+ const element = this.#findOrCreateComponent('[data-form-footer]', 'footer');
74
+ (0, _sanitize_html.setSanitizedRichText)(element, footer.content);
75
+ if (this.element.querySelector('[data-form-footer]')) {
76
+ this.element.querySelector('[data-form-footer]').replaceWith(element);
77
+ } else {
78
+ this.element.appendChild(element);
126
79
  }
127
- }, {
128
- key: "localeAuthKey",
129
- get: function () {
130
- const firstStep = this.data.steps[0];
131
- if (firstStep.inputs.some(input => input.kind === 'email') && firstStep.inputs.some(input => input.kind === 'phone')) {
132
- return 'phone_and_email';
133
- } else if (firstStep.inputs.some(input => input.kind === 'email')) {
134
- return 'email';
135
- } else if (firstStep.inputs.some(input => input.kind === 'phone')) {
136
- return 'phone';
137
- } else {
138
- return 'none';
139
- }
80
+ }
81
+ markAsCompleted(data) {
82
+ const payload = {
83
+ state: 'completed',
84
+ id: this.id,
85
+ data,
86
+ completedAt: new Date().getTime()
87
+ };
88
+ localStorage.setItem(`hello-form-${this.id}`, JSON.stringify(payload));
89
+ _hellotext.default.eventEmitter.dispatch('form:completed', payload);
90
+ }
91
+ get hasBeenCompleted() {
92
+ return localStorage.getItem(`hello-form-${this.id}`) !== null;
93
+ }
94
+ get id() {
95
+ return this.data.id;
96
+ }
97
+ get localeAuthKey() {
98
+ const firstStep = this.data.steps[0];
99
+ if (firstStep.inputs.some(input => input.kind === 'email') && firstStep.inputs.some(input => input.kind === 'phone')) {
100
+ return 'phone_and_email';
101
+ } else if (firstStep.inputs.some(input => input.kind === 'email')) {
102
+ return 'email';
103
+ } else if (firstStep.inputs.some(input => input.kind === 'phone')) {
104
+ return 'phone';
105
+ } else {
106
+ return 'none';
140
107
  }
141
- }, {
142
- key: "elementAttributes",
143
- get: function () {
144
- return [{
145
- name: 'data-controller',
146
- value: 'hellotext--form'
147
- }, {
148
- name: 'data-hello-form',
149
- value: this.id
150
- }, {
151
- name: 'data-hellotext--form-data-value',
152
- value: JSON.stringify(this.data)
153
- }];
108
+ }
109
+ get elementAttributes() {
110
+ return [{
111
+ name: 'data-controller',
112
+ value: 'hellotext--form'
113
+ }, {
114
+ name: 'data-hello-form',
115
+ value: this.id
116
+ }, {
117
+ name: 'data-hellotext--form-data-value',
118
+ value: JSON.stringify(this.data)
119
+ }];
120
+ }
121
+ #findOrCreateComponent(selector, tag) {
122
+ const existingElement = this.element.querySelector(selector);
123
+ if (existingElement) {
124
+ return existingElement.cloneNode(true);
154
125
  }
155
- }]);
156
- return Form;
157
- }();
158
- exports.Form = Form;
159
- function _findOrCreateComponent2(selector, tag) {
160
- const existingElement = this.element.querySelector(selector);
161
- if (existingElement) {
162
- return existingElement.cloneNode(true);
126
+ const createdElement = document.createElement(tag);
127
+ createdElement.setAttribute(selector.replace('[', '').replace(']', ''), '');
128
+ return createdElement;
163
129
  }
164
- const createdElement = document.createElement(tag);
165
- createdElement.setAttribute(selector.replace('[', '').replace(']', ''), '');
166
- return createdElement;
167
- }
130
+ }
131
+ exports.Form = Form;