@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
@@ -8,40 +8,24 @@ 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 SubmissionsAPI = /*#__PURE__*/function () {
17
- function SubmissionsAPI() {
18
- _classCallCheck(this, SubmissionsAPI);
11
+ class SubmissionsAPI {
12
+ static get endpoint() {
13
+ return _core.Configuration.endpoint('public/submissions');
19
14
  }
20
- _createClass(SubmissionsAPI, null, [{
21
- key: "endpoint",
22
- get: function () {
23
- return _core.Configuration.endpoint('public/submissions');
24
- }
25
- }, {
26
- key: "resendOTP",
27
- value: async function resendOTP(id) {
28
- const response = await fetch(`${this.endpoint}/${id}/otps`, {
29
- method: 'POST',
30
- headers: _hellotext.default.headers
31
- });
32
- return new _response.Response(response.ok, response);
33
- }
34
- }, {
35
- key: "verifyOTP",
36
- value: async function verifyOTP(id, otp) {
37
- const response = await fetch(`${this.endpoint}/${id}/otps/${otp}/verify`, {
38
- method: 'POST',
39
- headers: _hellotext.default.headers
40
- });
41
- return new _response.Response(response.ok, response);
42
- }
43
- }]);
44
- return SubmissionsAPI;
45
- }();
15
+ static async resendOTP(id) {
16
+ const response = await fetch(`${this.endpoint}/${id}/otps`, {
17
+ method: 'POST',
18
+ headers: _hellotext.default.headers
19
+ });
20
+ return new _response.Response(response.ok, response);
21
+ }
22
+ static async verifyOTP(id, otp) {
23
+ const response = await fetch(`${this.endpoint}/${id}/otps/${otp}/verify`, {
24
+ method: 'POST',
25
+ headers: _hellotext.default.headers
26
+ });
27
+ return new _response.Response(response.ok, response);
28
+ }
29
+ }
46
30
  var _default = SubmissionsAPI;
47
31
  exports.default = _default;
@@ -1,53 +1,23 @@
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 Hellotext from '../hellotext';
9
2
  import { Configuration } from '../core';
10
3
  import { Response } from './response';
11
- var SubmissionsAPI = /*#__PURE__*/function () {
12
- function SubmissionsAPI() {
13
- _classCallCheck(this, SubmissionsAPI);
4
+ class SubmissionsAPI {
5
+ static get endpoint() {
6
+ return Configuration.endpoint('public/submissions');
14
7
  }
15
- _createClass(SubmissionsAPI, null, [{
16
- key: "endpoint",
17
- get: function get() {
18
- return Configuration.endpoint('public/submissions');
19
- }
20
- }, {
21
- key: "resendOTP",
22
- value: function () {
23
- var _resendOTP = _asyncToGenerator(function* (id) {
24
- var response = yield fetch("".concat(this.endpoint, "/").concat(id, "/otps"), {
25
- method: 'POST',
26
- headers: Hellotext.headers
27
- });
28
- return new Response(response.ok, response);
29
- });
30
- function resendOTP(_x) {
31
- return _resendOTP.apply(this, arguments);
32
- }
33
- return resendOTP;
34
- }()
35
- }, {
36
- key: "verifyOTP",
37
- value: function () {
38
- var _verifyOTP = _asyncToGenerator(function* (id, otp) {
39
- var response = yield fetch("".concat(this.endpoint, "/").concat(id, "/otps/").concat(otp, "/verify"), {
40
- method: 'POST',
41
- headers: Hellotext.headers
42
- });
43
- return new Response(response.ok, response);
44
- });
45
- function verifyOTP(_x2, _x3) {
46
- return _verifyOTP.apply(this, arguments);
47
- }
48
- return verifyOTP;
49
- }()
50
- }]);
51
- return SubmissionsAPI;
52
- }();
8
+ static async resendOTP(id) {
9
+ const response = await fetch(`${this.endpoint}/${id}/otps`, {
10
+ method: 'POST',
11
+ headers: Hellotext.headers
12
+ });
13
+ return new Response(response.ok, response);
14
+ }
15
+ static async verifyOTP(id, otp) {
16
+ const response = await fetch(`${this.endpoint}/${id}/otps/${otp}/verify`, {
17
+ method: 'POST',
18
+ headers: Hellotext.headers
19
+ });
20
+ return new Response(response.ok, response);
21
+ }
22
+ }
53
23
  export default SubmissionsAPI;
@@ -8,72 +8,52 @@ 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 WebchatMessagesAPI = /*#__PURE__*/function () {
17
- function WebchatMessagesAPI(webchatId) {
18
- _classCallCheck(this, WebchatMessagesAPI);
11
+ class WebchatMessagesAPI {
12
+ static get endpoint() {
13
+ return _core.Configuration.endpoint(`public/webchats/:id/messages`);
14
+ }
15
+ constructor(webchatId) {
19
16
  this.webchatId = webchatId;
20
17
  }
21
- _createClass(WebchatMessagesAPI, [{
22
- key: "index",
23
- value: async function index(params) {
24
- const url = new URL(this.url);
25
- Object.entries(params).forEach(([key, value]) => {
26
- url.searchParams.append(key, value);
27
- });
28
- return await fetch(url, {
29
- method: 'GET',
30
- headers: _hellotext.default.headers
31
- });
32
- }
33
- }, {
34
- key: "catchUp",
35
- value: function catchUp(afterId) {
36
- return this.index({
37
- after_id: afterId,
18
+ async index(params) {
19
+ const url = new URL(this.url);
20
+ Object.entries(params).forEach(([key, value]) => {
21
+ url.searchParams.append(key, value);
22
+ });
23
+ return await fetch(url, {
24
+ method: 'GET',
25
+ headers: _hellotext.default.headers
26
+ });
27
+ }
28
+ catchUp(afterId) {
29
+ return this.index({
30
+ after_id: afterId,
31
+ session: _hellotext.default.session
32
+ });
33
+ }
34
+ async create(formData) {
35
+ const response = await fetch(this.url, {
36
+ method: 'POST',
37
+ headers: {
38
+ Authorization: `Bearer ${_hellotext.default.business.id}`
39
+ },
40
+ body: formData
41
+ });
42
+ return new _response.Response(response.ok, response);
43
+ }
44
+ markAsSeen(messageId = null) {
45
+ const url = messageId ? this.url + `/${messageId}` : this.url + '/seen';
46
+ fetch(url, {
47
+ method: 'PATCH',
48
+ headers: _hellotext.default.headers,
49
+ body: JSON.stringify({
38
50
  session: _hellotext.default.session
39
- });
40
- }
41
- }, {
42
- key: "create",
43
- value: async function create(formData) {
44
- const response = await fetch(this.url, {
45
- method: 'POST',
46
- headers: {
47
- Authorization: `Bearer ${_hellotext.default.business.id}`
48
- },
49
- body: formData
50
- });
51
- return new _response.Response(response.ok, response);
52
- }
53
- }, {
54
- key: "markAsSeen",
55
- value: function markAsSeen(messageId = null) {
56
- const url = messageId ? this.url + `/${messageId}` : this.url + '/seen';
57
- fetch(url, {
58
- method: 'PATCH',
59
- headers: _hellotext.default.headers,
60
- body: JSON.stringify({
61
- session: _hellotext.default.session
62
- })
63
- });
64
- }
65
- }, {
66
- key: "url",
67
- get: function () {
68
- return WebchatMessagesAPI.endpoint.replace(':id', this.webchatId);
69
- }
70
- }], [{
71
- key: "endpoint",
72
- get: function () {
73
- return _core.Configuration.endpoint(`public/webchats/:id/messages`);
74
- }
75
- }]);
76
- return WebchatMessagesAPI;
77
- }();
51
+ })
52
+ });
53
+ }
54
+ get url() {
55
+ return WebchatMessagesAPI.endpoint.replace(':id', this.webchatId);
56
+ }
57
+ }
78
58
  var _default = WebchatMessagesAPI;
79
59
  exports.default = _default;
@@ -1,87 +1,51 @@
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 Hellotext from '../../hellotext';
10
3
  import { Response } from '../response';
11
- var WebchatMessagesAPI = /*#__PURE__*/function () {
12
- function WebchatMessagesAPI(webchatId) {
13
- _classCallCheck(this, WebchatMessagesAPI);
4
+ class WebchatMessagesAPI {
5
+ static get endpoint() {
6
+ return Configuration.endpoint(`public/webchats/:id/messages`);
7
+ }
8
+ constructor(webchatId) {
14
9
  this.webchatId = webchatId;
15
10
  }
16
- _createClass(WebchatMessagesAPI, [{
17
- key: "index",
18
- value: function () {
19
- var _index = _asyncToGenerator(function* (params) {
20
- var url = new URL(this.url);
21
- Object.entries(params).forEach(_ref => {
22
- var [key, value] = _ref;
23
- url.searchParams.append(key, value);
24
- });
25
- return yield fetch(url, {
26
- method: 'GET',
27
- headers: Hellotext.headers
28
- });
29
- });
30
- function index(_x) {
31
- return _index.apply(this, arguments);
32
- }
33
- return index;
34
- }()
35
- }, {
36
- key: "catchUp",
37
- value: function catchUp(afterId) {
38
- return this.index({
39
- after_id: afterId,
11
+ async index(params) {
12
+ const url = new URL(this.url);
13
+ Object.entries(params).forEach(([key, value]) => {
14
+ url.searchParams.append(key, value);
15
+ });
16
+ return await fetch(url, {
17
+ method: 'GET',
18
+ headers: Hellotext.headers
19
+ });
20
+ }
21
+ catchUp(afterId) {
22
+ return this.index({
23
+ after_id: afterId,
24
+ session: Hellotext.session
25
+ });
26
+ }
27
+ async create(formData) {
28
+ const response = await fetch(this.url, {
29
+ method: 'POST',
30
+ headers: {
31
+ Authorization: `Bearer ${Hellotext.business.id}`
32
+ },
33
+ body: formData
34
+ });
35
+ return new Response(response.ok, response);
36
+ }
37
+ markAsSeen(messageId = null) {
38
+ const url = messageId ? this.url + `/${messageId}` : this.url + '/seen';
39
+ fetch(url, {
40
+ method: 'PATCH',
41
+ headers: Hellotext.headers,
42
+ body: JSON.stringify({
40
43
  session: Hellotext.session
41
- });
42
- }
43
- }, {
44
- key: "create",
45
- value: function () {
46
- var _create = _asyncToGenerator(function* (formData) {
47
- var response = yield fetch(this.url, {
48
- method: 'POST',
49
- headers: {
50
- Authorization: "Bearer ".concat(Hellotext.business.id)
51
- },
52
- body: formData
53
- });
54
- return new Response(response.ok, response);
55
- });
56
- function create(_x2) {
57
- return _create.apply(this, arguments);
58
- }
59
- return create;
60
- }()
61
- }, {
62
- key: "markAsSeen",
63
- value: function markAsSeen() {
64
- var messageId = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
65
- var url = messageId ? this.url + "/".concat(messageId) : this.url + '/seen';
66
- fetch(url, {
67
- method: 'PATCH',
68
- headers: Hellotext.headers,
69
- body: JSON.stringify({
70
- session: Hellotext.session
71
- })
72
- });
73
- }
74
- }, {
75
- key: "url",
76
- get: function get() {
77
- return WebchatMessagesAPI.endpoint.replace(':id', this.webchatId);
78
- }
79
- }], [{
80
- key: "endpoint",
81
- get: function get() {
82
- return Configuration.endpoint("public/webchats/:id/messages");
83
- }
84
- }]);
85
- return WebchatMessagesAPI;
86
- }();
44
+ })
45
+ });
46
+ }
47
+ get url() {
48
+ return WebchatMessagesAPI.endpoint.replace(':id', this.webchatId);
49
+ }
50
+ }
87
51
  export default WebchatMessagesAPI;
@@ -7,63 +7,44 @@ exports.default = void 0;
7
7
  var _core = require("../core");
8
8
  var _hellotext = _interopRequireDefault(require("../hellotext"));
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 WebchatsAPI = /*#__PURE__*/function () {
16
- function WebchatsAPI() {
17
- _classCallCheck(this, WebchatsAPI);
10
+ class WebchatsAPI {
11
+ static get endpoint() {
12
+ return _core.Configuration.endpoint('public/webchats');
18
13
  }
19
- _createClass(WebchatsAPI, null, [{
20
- key: "endpoint",
21
- get: function () {
22
- return _core.Configuration.endpoint('public/webchats');
14
+ static async get(id) {
15
+ const url = new URL(`${this.endpoint}/${id}`);
16
+ url.searchParams.append('session', _hellotext.default.session);
17
+ url.searchParams.append('locale', _core.Locale.toString());
18
+ Object.entries(_core.Configuration.webchat.style).forEach(([key, value]) => {
19
+ url.searchParams.append(`style[${key}]`, value);
20
+ });
21
+ this.appendWebchatOverrides(url);
22
+ url.searchParams.append('placement', _core.Configuration.webchat.placement);
23
+ const response = await fetch(url, {
24
+ method: 'GET',
25
+ headers: _hellotext.default.headers
26
+ });
27
+ const data = await response.json();
28
+ if (!_hellotext.default.business.data) {
29
+ _hellotext.default.business.setData(data.business);
30
+ _hellotext.default.business.setLocale(data.locale);
23
31
  }
24
- }, {
25
- key: "get",
26
- value: async function get(id) {
27
- const url = new URL(`${this.endpoint}/${id}`);
28
- url.searchParams.append('session', _hellotext.default.session);
29
- url.searchParams.append('locale', _core.Locale.toString());
30
- Object.entries(_core.Configuration.webchat.style).forEach(([key, value]) => {
31
- url.searchParams.append(`style[${key}]`, value);
32
- });
33
- this.appendWebchatOverrides(url);
34
- url.searchParams.append('placement', _core.Configuration.webchat.placement);
35
- const response = await fetch(url, {
36
- method: 'GET',
37
- headers: _hellotext.default.headers
38
- });
39
- const data = await response.json();
40
- if (!_hellotext.default.business.data) {
41
- _hellotext.default.business.setData(data.business);
42
- _hellotext.default.business.setLocale(data.locale);
43
- }
44
- return new DOMParser().parseFromString(data.html, 'text/html').querySelector('article');
45
- }
46
- }, {
47
- key: "appendWebchatOverrides",
48
- value: function appendWebchatOverrides(url) {
49
- var _appearance$header, _appearance$launcher;
50
- const {
51
- appearance,
52
- whatsapp
53
- } = _core.Configuration.webchat;
54
- this.appendIfSupplied(url, 'webchat[appearance][header][name]', (_appearance$header = appearance.header) === null || _appearance$header === void 0 ? void 0 : _appearance$header.name);
55
- this.appendIfSupplied(url, 'webchat[appearance][launcher][icon_url]', (_appearance$launcher = appearance.launcher) === null || _appearance$launcher === void 0 ? void 0 : _appearance$launcher.iconUrl);
56
- this.appendIfSupplied(url, 'webchat[handoff][identifier]', whatsapp.number);
57
- this.appendIfSupplied(url, 'webchat[handoff][restrict_to_channel]', whatsapp.restrictToChannel);
58
- }
59
- }, {
60
- key: "appendIfSupplied",
61
- value: function appendIfSupplied(url, key, value) {
62
- if (value === undefined || value === null) return;
63
- url.searchParams.append(key, String(value));
64
- }
65
- }]);
66
- return WebchatsAPI;
67
- }();
32
+ return new DOMParser().parseFromString(data.html, 'text/html').querySelector('article');
33
+ }
34
+ static appendWebchatOverrides(url) {
35
+ const {
36
+ appearance,
37
+ whatsapp
38
+ } = _core.Configuration.webchat;
39
+ this.appendIfSupplied(url, 'webchat[appearance][header][name]', appearance.header?.name);
40
+ this.appendIfSupplied(url, 'webchat[appearance][launcher][icon_url]', appearance.launcher?.iconUrl);
41
+ this.appendIfSupplied(url, 'webchat[handoff][identifier]', whatsapp.number);
42
+ this.appendIfSupplied(url, 'webchat[handoff][restrict_to_channel]', whatsapp.restrictToChannel);
43
+ }
44
+ static appendIfSupplied(url, key, value) {
45
+ if (value === undefined || value === null) return;
46
+ url.searchParams.append(key, String(value));
47
+ }
48
+ }
68
49
  var _default = WebchatsAPI;
69
50
  exports.default = _default;
@@ -1,70 +1,42 @@
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, Locale } from '../core';
9
2
  import Hellotext from '../hellotext';
10
- var WebchatsAPI = /*#__PURE__*/function () {
11
- function WebchatsAPI() {
12
- _classCallCheck(this, WebchatsAPI);
3
+ class WebchatsAPI {
4
+ static get endpoint() {
5
+ return Configuration.endpoint('public/webchats');
13
6
  }
14
- _createClass(WebchatsAPI, null, [{
15
- key: "endpoint",
16
- get: function get() {
17
- return Configuration.endpoint('public/webchats');
7
+ static async get(id) {
8
+ const url = new URL(`${this.endpoint}/${id}`);
9
+ url.searchParams.append('session', Hellotext.session);
10
+ url.searchParams.append('locale', Locale.toString());
11
+ Object.entries(Configuration.webchat.style).forEach(([key, value]) => {
12
+ url.searchParams.append(`style[${key}]`, value);
13
+ });
14
+ this.appendWebchatOverrides(url);
15
+ url.searchParams.append('placement', Configuration.webchat.placement);
16
+ const response = await fetch(url, {
17
+ method: 'GET',
18
+ headers: Hellotext.headers
19
+ });
20
+ const data = await response.json();
21
+ if (!Hellotext.business.data) {
22
+ Hellotext.business.setData(data.business);
23
+ Hellotext.business.setLocale(data.locale);
18
24
  }
19
- }, {
20
- key: "get",
21
- value: function () {
22
- var _get = _asyncToGenerator(function* (id) {
23
- var url = new URL("".concat(this.endpoint, "/").concat(id));
24
- url.searchParams.append('session', Hellotext.session);
25
- url.searchParams.append('locale', Locale.toString());
26
- Object.entries(Configuration.webchat.style).forEach(_ref => {
27
- var [key, value] = _ref;
28
- url.searchParams.append("style[".concat(key, "]"), value);
29
- });
30
- this.appendWebchatOverrides(url);
31
- url.searchParams.append('placement', Configuration.webchat.placement);
32
- var response = yield fetch(url, {
33
- method: 'GET',
34
- headers: Hellotext.headers
35
- });
36
- var data = yield response.json();
37
- if (!Hellotext.business.data) {
38
- Hellotext.business.setData(data.business);
39
- Hellotext.business.setLocale(data.locale);
40
- }
41
- return new DOMParser().parseFromString(data.html, 'text/html').querySelector('article');
42
- });
43
- function get(_x) {
44
- return _get.apply(this, arguments);
45
- }
46
- return get;
47
- }()
48
- }, {
49
- key: "appendWebchatOverrides",
50
- value: function appendWebchatOverrides(url) {
51
- var _appearance$header, _appearance$launcher;
52
- var {
53
- appearance,
54
- whatsapp
55
- } = Configuration.webchat;
56
- this.appendIfSupplied(url, 'webchat[appearance][header][name]', (_appearance$header = appearance.header) === null || _appearance$header === void 0 ? void 0 : _appearance$header.name);
57
- this.appendIfSupplied(url, 'webchat[appearance][launcher][icon_url]', (_appearance$launcher = appearance.launcher) === null || _appearance$launcher === void 0 ? void 0 : _appearance$launcher.iconUrl);
58
- this.appendIfSupplied(url, 'webchat[handoff][identifier]', whatsapp.number);
59
- this.appendIfSupplied(url, 'webchat[handoff][restrict_to_channel]', whatsapp.restrictToChannel);
60
- }
61
- }, {
62
- key: "appendIfSupplied",
63
- value: function appendIfSupplied(url, key, value) {
64
- if (value === undefined || value === null) return;
65
- url.searchParams.append(key, String(value));
66
- }
67
- }]);
68
- return WebchatsAPI;
69
- }();
25
+ return new DOMParser().parseFromString(data.html, 'text/html').querySelector('article');
26
+ }
27
+ static appendWebchatOverrides(url) {
28
+ const {
29
+ appearance,
30
+ whatsapp
31
+ } = Configuration.webchat;
32
+ this.appendIfSupplied(url, 'webchat[appearance][header][name]', appearance.header?.name);
33
+ this.appendIfSupplied(url, 'webchat[appearance][launcher][icon_url]', appearance.launcher?.iconUrl);
34
+ this.appendIfSupplied(url, 'webchat[handoff][identifier]', whatsapp.number);
35
+ this.appendIfSupplied(url, 'webchat[handoff][restrict_to_channel]', whatsapp.restrictToChannel);
36
+ }
37
+ static appendIfSupplied(url, key, value) {
38
+ if (value === undefined || value === null) return;
39
+ url.searchParams.append(key, String(value));
40
+ }
41
+ }
70
42
  export default WebchatsAPI;