@hellotext/hellotext 2.5.6 → 2.5.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (113) hide show
  1. package/README.md +5 -26
  2. package/dist/hellotext.js +1 -1
  3. package/dist/hellotext.js.LICENSE.txt +1 -1
  4. package/index.d.ts +15 -6
  5. package/lib/api/acks.cjs +17 -31
  6. package/lib/api/acks.js +17 -42
  7. package/lib/api/businesses.cjs +14 -28
  8. package/lib/api/businesses.js +13 -36
  9. package/lib/api/events.cjs +26 -40
  10. package/lib/api/events.js +28 -52
  11. package/lib/api/forms.cjs +24 -40
  12. package/lib/api/forms.js +24 -57
  13. package/lib/api/identifications.cjs +15 -29
  14. package/lib/api/identifications.js +15 -40
  15. package/lib/api/index.cjs +26 -46
  16. package/lib/api/index.js +28 -49
  17. package/lib/api/push/identities.cjs +43 -0
  18. package/lib/api/push/identities.js +35 -0
  19. package/lib/api/response.cjs +30 -52
  20. package/lib/api/response.js +31 -60
  21. package/lib/api/submissions.cjs +18 -34
  22. package/lib/api/submissions.js +18 -48
  23. package/lib/api/webchat/messages.cjs +44 -64
  24. package/lib/api/webchat/messages.js +44 -80
  25. package/lib/api/webchats.cjs +37 -56
  26. package/lib/api/webchats.js +37 -65
  27. package/lib/api/whatsapp_widgets.cjs +49 -72
  28. package/lib/api/whatsapp_widgets.js +48 -91
  29. package/lib/builders/input_builder.cjs +36 -48
  30. package/lib/builders/input_builder.js +36 -48
  31. package/lib/builders/logo_builder.cjs +10 -29
  32. package/lib/builders/logo_builder.js +20 -28
  33. package/lib/channels/application_channel.cjs +136 -178
  34. package/lib/channels/application_channel.js +137 -180
  35. package/lib/channels/webchat_channel.cjs +125 -170
  36. package/lib/channels/webchat_channel.js +125 -170
  37. package/lib/controllers/form_controller.cjs +82 -121
  38. package/lib/controllers/form_controller.js +82 -130
  39. package/lib/controllers/message_controller.cjs +211 -282
  40. package/lib/controllers/message_controller.js +209 -284
  41. package/lib/controllers/mixins/usePopover.cjs +3 -6
  42. package/lib/controllers/mixins/usePopover.js +17 -22
  43. package/lib/controllers/webchat/emoji_picker_controller.cjs +106 -150
  44. package/lib/controllers/webchat/emoji_picker_controller.js +105 -170
  45. package/lib/controllers/webchat/useBehaviour.js +5 -5
  46. package/lib/controllers/webchat/useOpeningSequence.js +6 -6
  47. package/lib/controllers/webchat/useTeaser.js +9 -9
  48. package/lib/controllers/webchat_controller.cjs +916 -1088
  49. package/lib/controllers/webchat_controller.js +926 -1152
  50. package/lib/core/configuration/forms.cjs +21 -35
  51. package/lib/core/configuration/forms.js +20 -35
  52. package/lib/core/configuration/locale.cjs +36 -71
  53. package/lib/core/configuration/locale.js +36 -70
  54. package/lib/core/configuration/push.cjs +16 -0
  55. package/lib/core/configuration/push.js +10 -0
  56. package/lib/core/configuration/webchat.cjs +142 -182
  57. package/lib/core/configuration/webchat.js +145 -189
  58. package/lib/core/configuration/whatsapp.cjs +76 -102
  59. package/lib/core/configuration/whatsapp.js +76 -105
  60. package/lib/core/configuration.cjs +62 -75
  61. package/lib/core/configuration.js +61 -75
  62. package/lib/core/event.cjs +36 -59
  63. package/lib/core/event.js +35 -61
  64. package/lib/core/sanitize_html.js +4 -4
  65. package/lib/errors/invalid_event.cjs +5 -26
  66. package/lib/errors/invalid_event.js +5 -26
  67. package/lib/errors/not_initialized_error.cjs +5 -26
  68. package/lib/errors/not_initialized_error.js +5 -26
  69. package/lib/hellotext.cjs +186 -211
  70. package/lib/hellotext.js +189 -236
  71. package/lib/index.js +1 -1
  72. package/lib/models/business.cjs +115 -152
  73. package/lib/models/business.js +118 -162
  74. package/lib/models/cookies.cjs +34 -51
  75. package/lib/models/cookies.js +34 -51
  76. package/lib/models/fingerprint.cjs +8 -23
  77. package/lib/models/fingerprint.js +25 -58
  78. package/lib/models/form.cjs +106 -142
  79. package/lib/models/form.js +105 -153
  80. package/lib/models/form_collection.cjs +63 -101
  81. package/lib/models/form_collection.js +61 -107
  82. package/lib/models/index.cjs +7 -0
  83. package/lib/models/index.js +1 -0
  84. package/lib/models/page.cjs +106 -129
  85. package/lib/models/page.js +106 -131
  86. package/lib/models/push.cjs +345 -0
  87. package/lib/models/push.js +339 -0
  88. package/lib/models/query.cjs +21 -41
  89. package/lib/models/query.js +21 -41
  90. package/lib/models/session.cjs +33 -65
  91. package/lib/models/session.js +30 -63
  92. package/lib/models/user.cjs +29 -51
  93. package/lib/models/user.js +29 -51
  94. package/lib/models/utm.cjs +15 -27
  95. package/lib/models/utm.js +17 -32
  96. package/lib/models/webchat.cjs +52 -76
  97. package/lib/models/webchat.js +52 -90
  98. package/lib/models/whatsapp_widget.cjs +41 -59
  99. package/lib/models/whatsapp_widget.js +41 -73
  100. package/lib/vanilla.cjs +4 -7
  101. package/lib/vanilla.js +2 -1
  102. package/package.json +2 -10
  103. package/src/api/index.js +5 -0
  104. package/src/api/push/identities.js +42 -0
  105. package/src/core/configuration/push.js +12 -0
  106. package/src/core/configuration.js +5 -0
  107. package/src/hellotext.js +15 -1
  108. package/src/index.bundle.js +0 -1
  109. package/src/models/business.js +1 -0
  110. package/src/models/index.js +1 -0
  111. package/src/models/push.js +397 -0
  112. package/src/vanilla.js +2 -1
  113. package/styles/index.css +0 -30
@@ -1 +1 @@
1
- /*! @license DOMPurify 3.4.13 | (c) Cure53 and other contributors | Released under the Apache license 2.0 and Mozilla Public License 2.0 | github.com/cure53/DOMPurify/blob/3.4.13/LICENSE */
1
+ /*! @license DOMPurify 3.4.14 | (c) Cure53 and other contributors | Released under the Apache license 2.0 and Mozilla Public License 2.0 | github.com/cure53/DOMPurify/blob/3.4.14/LICENSE */
package/index.d.ts CHANGED
@@ -7,6 +7,7 @@ export interface HellotextConfig {
7
7
  }
8
8
  webchat?: false | HellotextWebchatConfig
9
9
  whatsappWidget?: false | HellotextWhatsAppWidgetConfig
10
+ push?: false | HellotextPushConfig
10
11
  session?: string
11
12
  autoGenerateSession?: boolean
12
13
  }
@@ -67,6 +68,18 @@ export interface HellotextWhatsAppWidgetConfig {
67
68
  appearance?: HellotextWhatsAppWidgetAppearance
68
69
  }
69
70
 
71
+ export interface HellotextPushConfig {
72
+ serviceWorkerUrl?: string | null
73
+ channelId?: string | null
74
+ }
75
+
76
+ export interface HellotextPush {
77
+ readonly ready: Promise<void>
78
+ readonly subscribed: boolean
79
+ subscribe(): Promise<Response | void>
80
+ unsubscribe(): Promise<Response | null | void>
81
+ }
82
+
70
83
  export interface HellotextBusinessCountry {
71
84
  code?: string
72
85
  prefix?: string
@@ -81,6 +94,7 @@ export interface HellotextBusinessData {
81
94
  style_url?: string
82
95
  webchat?: HellotextWebchatConfig | null
83
96
  whatsapp?: HellotextWhatsAppWidgetConfig | null
97
+ push?: { public_key: string } | null
84
98
  whitelist?: string | string[] | null
85
99
  subscription?: string | null
86
100
  [key: string]: any
@@ -142,6 +156,7 @@ declare class Hellotext {
142
156
  static business: HellotextBusiness
143
157
  static webchat: any
144
158
  static whatsapp: any
159
+ static push: HellotextPush | null
145
160
  }
146
161
 
147
162
  export declare class User {
@@ -160,9 +175,3 @@ export declare class Cookies {
160
175
  }
161
176
 
162
177
  export default Hellotext
163
-
164
- // Declare the CSS module
165
- declare module '@hellotext/hellotext/styles/index.css' {
166
- const styles: string
167
- export default styles
168
- }
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
+ }