@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/index.d.ts CHANGED
@@ -175,9 +175,3 @@ export declare class Cookies {
175
175
  }
176
176
 
177
177
  export default Hellotext
178
-
179
- // Declare the CSS module
180
- declare module '@hellotext/hellotext/styles/index.css' {
181
- const styles: string
182
- export default styles
183
- }
package/lib/api/acks.cjs CHANGED
@@ -7,37 +7,23 @@ exports.default = void 0;
7
7
  var _hellotext = _interopRequireDefault(require("../hellotext"));
8
8
  var _core = require("../core");
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 AcksAPI = /*#__PURE__*/function () {
16
- function AcksAPI() {
17
- _classCallCheck(this, AcksAPI);
10
+ class AcksAPI {
11
+ static get endpoint() {
12
+ return _core.Configuration.endpoint('public/acks');
18
13
  }
19
- _createClass(AcksAPI, null, [{
20
- key: "endpoint",
21
- get: function () {
22
- return _core.Configuration.endpoint('public/acks');
23
- }
24
- }, {
25
- key: "send",
26
- value: async function send(params = {}) {
27
- const payload = {
28
- ...params,
29
- session: _hellotext.default.session,
30
- at: new Date().toISOString()
31
- };
32
- fetch(this.endpoint, {
33
- method: 'POST',
34
- headers: _hellotext.default.headers,
35
- body: JSON.stringify(payload),
36
- keepalive: true
37
- });
38
- }
39
- }]);
40
- return AcksAPI;
41
- }();
14
+ static async send(params = {}) {
15
+ const payload = {
16
+ ...params,
17
+ session: _hellotext.default.session,
18
+ at: new Date().toISOString()
19
+ };
20
+ fetch(this.endpoint, {
21
+ method: 'POST',
22
+ headers: _hellotext.default.headers,
23
+ body: JSON.stringify(payload),
24
+ keepalive: true
25
+ });
26
+ }
27
+ }
42
28
  var _default = AcksAPI;
43
29
  exports.default = _default;
package/lib/api/acks.js CHANGED
@@ -1,46 +1,21 @@
1
- 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; }
2
- 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; }
3
- 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; }
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 _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
7
- 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); } }
8
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
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
  import Hellotext from '../hellotext';
12
2
  import { Configuration } from '../core';
13
- var AcksAPI = /*#__PURE__*/function () {
14
- function AcksAPI() {
15
- _classCallCheck(this, AcksAPI);
3
+ class AcksAPI {
4
+ static get endpoint() {
5
+ return Configuration.endpoint('public/acks');
16
6
  }
17
- _createClass(AcksAPI, null, [{
18
- key: "endpoint",
19
- get: function get() {
20
- return Configuration.endpoint('public/acks');
21
- }
22
- }, {
23
- key: "send",
24
- value: function () {
25
- var _send = _asyncToGenerator(function* () {
26
- var params = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
27
- var payload = _objectSpread(_objectSpread({}, params), {}, {
28
- session: Hellotext.session,
29
- at: new Date().toISOString()
30
- });
31
- fetch(this.endpoint, {
32
- method: 'POST',
33
- headers: Hellotext.headers,
34
- body: JSON.stringify(payload),
35
- keepalive: true
36
- });
37
- });
38
- function send() {
39
- return _send.apply(this, arguments);
40
- }
41
- return send;
42
- }()
43
- }]);
44
- return AcksAPI;
45
- }();
7
+ static async send(params = {}) {
8
+ const payload = {
9
+ ...params,
10
+ session: Hellotext.session,
11
+ at: new Date().toISOString()
12
+ };
13
+ fetch(this.endpoint, {
14
+ method: 'POST',
15
+ headers: Hellotext.headers,
16
+ body: JSON.stringify(payload),
17
+ keepalive: true
18
+ });
19
+ }
20
+ }
46
21
  export default AcksAPI;
@@ -5,33 +5,19 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = void 0;
7
7
  var _core = require("../core");
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 _default = /*#__PURE__*/function () {
14
- function _default() {
15
- _classCallCheck(this, _default);
8
+ class _default {
9
+ static get endpoint() {
10
+ return _core.Configuration.endpoint('public/businesses');
16
11
  }
17
- _createClass(_default, null, [{
18
- key: "endpoint",
19
- get: function () {
20
- return _core.Configuration.endpoint('public/businesses');
21
- }
22
- }, {
23
- key: "get",
24
- value: async function get(id) {
25
- return fetch(`${this.endpoint}/${id}`, {
26
- method: 'GET',
27
- headers: {
28
- Authorization: `Bearer ${id}`,
29
- Accept: 'application/json',
30
- 'Content-Type': 'application/json'
31
- }
32
- });
33
- }
34
- }]);
35
- return _default;
36
- }();
12
+ static async get(id) {
13
+ return fetch(`${this.endpoint}/${id}`, {
14
+ method: 'GET',
15
+ headers: {
16
+ Authorization: `Bearer ${id}`,
17
+ Accept: 'application/json',
18
+ 'Content-Type': 'application/json'
19
+ }
20
+ });
21
+ }
22
+ }
37
23
  exports.default = _default;
@@ -1,39 +1,16 @@
1
- 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); } }
2
- 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); }); }; }
3
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
4
- 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); } }
5
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
6
- function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
7
- 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); }
8
1
  import { Configuration } from '../core';
9
- var _default = /*#__PURE__*/function () {
10
- function _default() {
11
- _classCallCheck(this, _default);
2
+ export default class {
3
+ static get endpoint() {
4
+ return Configuration.endpoint('public/businesses');
12
5
  }
13
- _createClass(_default, null, [{
14
- key: "endpoint",
15
- get: function get() {
16
- return Configuration.endpoint('public/businesses');
17
- }
18
- }, {
19
- key: "get",
20
- value: function () {
21
- var _get = _asyncToGenerator(function* (id) {
22
- return fetch("".concat(this.endpoint, "/").concat(id), {
23
- method: 'GET',
24
- headers: {
25
- Authorization: "Bearer ".concat(id),
26
- Accept: 'application/json',
27
- 'Content-Type': 'application/json'
28
- }
29
- });
30
- });
31
- function get(_x) {
32
- return _get.apply(this, arguments);
6
+ static async get(id) {
7
+ return fetch(`${this.endpoint}/${id}`, {
8
+ method: 'GET',
9
+ headers: {
10
+ Authorization: `Bearer ${id}`,
11
+ Accept: 'application/json',
12
+ 'Content-Type': 'application/json'
33
13
  }
34
- return get;
35
- }()
36
- }]);
37
- return _default;
38
- }();
39
- export { _default as default };
14
+ });
15
+ }
16
+ }
@@ -7,49 +7,35 @@ exports.default = void 0;
7
7
  var _core = require("../core");
8
8
  var _models = require("../models");
9
9
  var _response = require("./response");
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 EventsAPI = /*#__PURE__*/function () {
16
- function EventsAPI() {
17
- _classCallCheck(this, EventsAPI);
10
+ class EventsAPI {
11
+ static get endpoint() {
12
+ return _core.Configuration.endpoint('track/events');
18
13
  }
19
- _createClass(EventsAPI, null, [{
20
- key: "endpoint",
21
- get: function () {
22
- return _core.Configuration.endpoint('track/events');
14
+ static async create({
15
+ headers,
16
+ body,
17
+ keepalive = false
18
+ }) {
19
+ if (_models.Query.inPreviewMode) {
20
+ return new _response.Response(true, {
21
+ received: true
22
+ });
23
23
  }
24
- }, {
25
- key: "create",
26
- value: async function create({
24
+ const fetchOptions = {
25
+ method: 'POST',
27
26
  headers,
28
- body,
29
- keepalive = false
30
- }) {
31
- if (_models.Query.inPreviewMode) {
32
- return new _response.Response(true, {
33
- received: true
34
- });
35
- }
36
- const fetchOptions = {
37
- method: 'POST',
38
- headers,
39
- body: JSON.stringify(body)
40
- };
27
+ body: JSON.stringify(body)
28
+ };
41
29
 
42
- // Do not send `keepalive: false`. The track caller opts in only for payloads
43
- // that fit the browser keepalive budget; omitting the key for larger events
44
- // preserves normal fetch behavior for rich carts/orders instead of asking
45
- // the browser to use an unload-safe transport it may reject.
46
- if (keepalive) {
47
- fetchOptions.keepalive = true;
48
- }
49
- const response = await fetch(this.endpoint, fetchOptions);
50
- return new _response.Response(response.status === 200, await response.json());
30
+ // Do not send `keepalive: false`. The track caller opts in only for payloads
31
+ // that fit the browser keepalive budget; omitting the key for larger events
32
+ // preserves normal fetch behavior for rich carts/orders instead of asking
33
+ // the browser to use an unload-safe transport it may reject.
34
+ if (keepalive) {
35
+ fetchOptions.keepalive = true;
51
36
  }
52
- }]);
53
- return EventsAPI;
54
- }();
37
+ const response = await fetch(this.endpoint, fetchOptions);
38
+ return new _response.Response(response.status === 200, await response.json());
39
+ }
40
+ }
55
41
  exports.default = EventsAPI;
package/lib/api/events.js CHANGED
@@ -1,58 +1,34 @@
1
- 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); } }
2
- 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); }); }; }
3
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
4
- 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); } }
5
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
6
- function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
7
- 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); }
8
1
  import { Configuration } from '../core';
9
2
  import { Query } from '../models';
10
3
  import { Response } from './response';
11
- var EventsAPI = /*#__PURE__*/function () {
12
- function EventsAPI() {
13
- _classCallCheck(this, EventsAPI);
4
+ export default class EventsAPI {
5
+ static get endpoint() {
6
+ return Configuration.endpoint('track/events');
14
7
  }
15
- _createClass(EventsAPI, null, [{
16
- key: "endpoint",
17
- get: function get() {
18
- return Configuration.endpoint('track/events');
8
+ static async create({
9
+ headers,
10
+ body,
11
+ keepalive = false
12
+ }) {
13
+ if (Query.inPreviewMode) {
14
+ return new Response(true, {
15
+ received: true
16
+ });
19
17
  }
20
- }, {
21
- key: "create",
22
- value: function () {
23
- var _create = _asyncToGenerator(function* (_ref) {
24
- var {
25
- headers,
26
- body,
27
- keepalive = false
28
- } = _ref;
29
- if (Query.inPreviewMode) {
30
- return new Response(true, {
31
- received: true
32
- });
33
- }
34
- var fetchOptions = {
35
- method: 'POST',
36
- headers,
37
- body: JSON.stringify(body)
38
- };
18
+ const fetchOptions = {
19
+ method: 'POST',
20
+ headers,
21
+ body: JSON.stringify(body)
22
+ };
39
23
 
40
- // Do not send `keepalive: false`. The track caller opts in only for payloads
41
- // that fit the browser keepalive budget; omitting the key for larger events
42
- // preserves normal fetch behavior for rich carts/orders instead of asking
43
- // the browser to use an unload-safe transport it may reject.
44
- if (keepalive) {
45
- fetchOptions.keepalive = true;
46
- }
47
- var response = yield fetch(this.endpoint, fetchOptions);
48
- return new Response(response.status === 200, yield response.json());
49
- });
50
- function create(_x) {
51
- return _create.apply(this, arguments);
52
- }
53
- return create;
54
- }()
55
- }]);
56
- return EventsAPI;
57
- }();
58
- export { EventsAPI as default };
24
+ // Do not send `keepalive: false`. The track caller opts in only for payloads
25
+ // that fit the browser keepalive budget; omitting the key for larger events
26
+ // preserves normal fetch behavior for rich carts/orders instead of asking
27
+ // the browser to use an unload-safe transport it may reject.
28
+ if (keepalive) {
29
+ fetchOptions.keepalive = true;
30
+ }
31
+ const response = await fetch(this.endpoint, fetchOptions);
32
+ return new Response(response.status === 200, await response.json());
33
+ }
34
+ }
package/lib/api/forms.cjs CHANGED
@@ -8,45 +8,29 @@ var _core = require("../core");
8
8
  var _hellotext = _interopRequireDefault(require("../hellotext"));
9
9
  var _response = require("./response");
10
10
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
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); }
16
- let FormsAPI = /*#__PURE__*/function () {
17
- function FormsAPI() {
18
- _classCallCheck(this, FormsAPI);
11
+ class FormsAPI {
12
+ static get endpoint() {
13
+ return _core.Configuration.endpoint('public/forms');
19
14
  }
20
- _createClass(FormsAPI, null, [{
21
- key: "endpoint",
22
- get: function () {
23
- return _core.Configuration.endpoint('public/forms');
24
- }
25
- }, {
26
- key: "get",
27
- value: async function get(id) {
28
- const url = new URL(`${this.endpoint}/${id}`);
29
- url.searchParams.append('session', _hellotext.default.session);
30
- url.searchParams.append('locale', _core.Locale.toString());
31
- return fetch(url, {
32
- method: 'GET',
33
- headers: _hellotext.default.headers
34
- });
35
- }
36
- }, {
37
- key: "submit",
38
- value: async function submit(id, data) {
39
- const response = await fetch(`${this.endpoint}/${id}/submissions`, {
40
- method: 'POST',
41
- headers: _hellotext.default.headers,
42
- body: JSON.stringify({
43
- session: _hellotext.default.session,
44
- ...data
45
- })
46
- });
47
- return new _response.Response(response.ok, response);
48
- }
49
- }]);
50
- return FormsAPI;
51
- }();
15
+ static async get(id) {
16
+ const url = new URL(`${this.endpoint}/${id}`);
17
+ url.searchParams.append('session', _hellotext.default.session);
18
+ url.searchParams.append('locale', _core.Locale.toString());
19
+ return fetch(url, {
20
+ method: 'GET',
21
+ headers: _hellotext.default.headers
22
+ });
23
+ }
24
+ static async submit(id, data) {
25
+ const response = await fetch(`${this.endpoint}/${id}/submissions`, {
26
+ method: 'POST',
27
+ headers: _hellotext.default.headers,
28
+ body: JSON.stringify({
29
+ session: _hellotext.default.session,
30
+ ...data
31
+ })
32
+ });
33
+ return new _response.Response(response.ok, response);
34
+ }
35
+ }
52
36
  exports.default = FormsAPI;
package/lib/api/forms.js CHANGED
@@ -1,61 +1,28 @@
1
- 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; }
2
- 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; }
3
- 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; }
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 _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
7
- 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); } }
8
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
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
  import { Configuration, Locale } from '../core';
12
2
  import Hellotext from '../hellotext';
13
3
  import { Response } from './response';
14
- var FormsAPI = /*#__PURE__*/function () {
15
- function FormsAPI() {
16
- _classCallCheck(this, FormsAPI);
4
+ export default class FormsAPI {
5
+ static get endpoint() {
6
+ return Configuration.endpoint('public/forms');
17
7
  }
18
- _createClass(FormsAPI, null, [{
19
- key: "endpoint",
20
- get: function get() {
21
- return Configuration.endpoint('public/forms');
22
- }
23
- }, {
24
- key: "get",
25
- value: function () {
26
- var _get = _asyncToGenerator(function* (id) {
27
- var url = new URL("".concat(this.endpoint, "/").concat(id));
28
- url.searchParams.append('session', Hellotext.session);
29
- url.searchParams.append('locale', Locale.toString());
30
- return fetch(url, {
31
- method: 'GET',
32
- headers: Hellotext.headers
33
- });
34
- });
35
- function get(_x) {
36
- return _get.apply(this, arguments);
37
- }
38
- return get;
39
- }()
40
- }, {
41
- key: "submit",
42
- value: function () {
43
- var _submit = _asyncToGenerator(function* (id, data) {
44
- var response = yield fetch("".concat(this.endpoint, "/").concat(id, "/submissions"), {
45
- method: 'POST',
46
- headers: Hellotext.headers,
47
- body: JSON.stringify(_objectSpread({
48
- session: Hellotext.session
49
- }, data))
50
- });
51
- return new Response(response.ok, response);
52
- });
53
- function submit(_x2, _x3) {
54
- return _submit.apply(this, arguments);
55
- }
56
- return submit;
57
- }()
58
- }]);
59
- return FormsAPI;
60
- }();
61
- export { FormsAPI as default };
8
+ static async get(id) {
9
+ const url = new URL(`${this.endpoint}/${id}`);
10
+ url.searchParams.append('session', Hellotext.session);
11
+ url.searchParams.append('locale', Locale.toString());
12
+ return fetch(url, {
13
+ method: 'GET',
14
+ headers: Hellotext.headers
15
+ });
16
+ }
17
+ static async submit(id, data) {
18
+ const response = await fetch(`${this.endpoint}/${id}/submissions`, {
19
+ method: 'POST',
20
+ headers: Hellotext.headers,
21
+ body: JSON.stringify({
22
+ session: Hellotext.session,
23
+ ...data
24
+ })
25
+ });
26
+ return new Response(response.ok, response);
27
+ }
28
+ }
@@ -8,35 +8,21 @@ var _hellotext = _interopRequireDefault(require("../hellotext"));
8
8
  var _core = require("../core");
9
9
  var _response = require("./response");
10
10
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
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); }
16
- let IdentificationsAPI = /*#__PURE__*/function () {
17
- function IdentificationsAPI() {
18
- _classCallCheck(this, IdentificationsAPI);
11
+ class IdentificationsAPI {
12
+ static get endpoint() {
13
+ return _core.Configuration.endpoint('public/identifications');
19
14
  }
20
- _createClass(IdentificationsAPI, null, [{
21
- key: "endpoint",
22
- get: function () {
23
- return _core.Configuration.endpoint('public/identifications');
24
- }
25
- }, {
26
- key: "create",
27
- value: async function create(data = {}) {
28
- const response = await fetch(this.endpoint, {
29
- method: 'POST',
30
- headers: _hellotext.default.headers,
31
- body: JSON.stringify({
32
- session: _hellotext.default.session,
33
- ...data
34
- })
35
- });
36
- return new _response.Response(response.ok, response);
37
- }
38
- }]);
39
- return IdentificationsAPI;
40
- }();
15
+ static async create(data = {}) {
16
+ const response = await fetch(this.endpoint, {
17
+ method: 'POST',
18
+ headers: _hellotext.default.headers,
19
+ body: JSON.stringify({
20
+ session: _hellotext.default.session,
21
+ ...data
22
+ })
23
+ });
24
+ return new _response.Response(response.ok, response);
25
+ }
26
+ }
41
27
  var _default = IdentificationsAPI;
42
28
  exports.default = _default;