@hellotext/hellotext 1.8.7 → 2.0.0

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 (106) hide show
  1. package/dist/hellotext.js +1 -1
  2. package/lib/api/businesses.cjs +37 -0
  3. package/lib/api/businesses.js +3 -9
  4. package/lib/api/events.cjs +45 -0
  5. package/lib/api/events.js +8 -14
  6. package/lib/api/forms.cjs +51 -0
  7. package/lib/api/forms.js +10 -17
  8. package/lib/api/index.cjs +51 -0
  9. package/lib/api/index.js +10 -23
  10. package/lib/api/response.cjs +76 -0
  11. package/lib/api/response.js +1 -7
  12. package/lib/api/submissions.cjs +47 -0
  13. package/lib/api/submissions.js +9 -17
  14. package/lib/api/webchat/messages.cjs +70 -0
  15. package/lib/api/webchat/messages.js +10 -18
  16. package/lib/api/webchats.cjs +44 -0
  17. package/lib/api/webchats.js +8 -16
  18. package/lib/builders/input_builder.cjs +61 -0
  19. package/lib/builders/input_builder.js +4 -11
  20. package/lib/builders/logo_builder.cjs +50 -0
  21. package/lib/builders/logo_builder.js +5 -12
  22. package/lib/channels/application_channel.cjs +67 -0
  23. package/lib/channels/application_channel.js +1 -8
  24. package/lib/channels/{web_chat_channel.js → webchat_channel.cjs} +35 -20
  25. package/lib/channels/webchat_channel.js +3 -11
  26. package/lib/controllers/form_controller.cjs +141 -0
  27. package/lib/controllers/form_controller.js +15 -22
  28. package/lib/controllers/mixins/usePopover.cjs +59 -0
  29. package/lib/controllers/mixins/usePopover.js +6 -14
  30. package/lib/controllers/{web_chat/pagination_controller.js → webchat/emoji_picker_controller.cjs} +74 -29
  31. package/lib/controllers/webchat/emoji_picker_controller.js +11 -17
  32. package/lib/controllers/webchat_controller.cjs +433 -0
  33. package/lib/controllers/webchat_controller.js +49 -51
  34. package/lib/core/configuration/forms.cjs +49 -0
  35. package/lib/core/configuration/forms.js +2 -8
  36. package/lib/core/configuration/{web_chat.js → webchat.cjs} +53 -38
  37. package/lib/core/configuration/webchat.js +2 -9
  38. package/lib/core/configuration.cjs +65 -0
  39. package/lib/core/configuration.js +8 -13
  40. package/lib/core/event.cjs +71 -0
  41. package/lib/core/event.js +5 -11
  42. package/lib/core/index.cjs +20 -0
  43. package/lib/core/index.js +2 -20
  44. package/lib/errors/index.cjs +19 -0
  45. package/lib/errors/index.js +2 -19
  46. package/lib/errors/invalid_event.cjs +34 -0
  47. package/lib/errors/invalid_event.js +1 -7
  48. package/lib/errors/not_initialized_error.cjs +34 -0
  49. package/lib/errors/not_initialized_error.js +1 -7
  50. package/lib/hellotext.cjs +152 -0
  51. package/lib/hellotext.js +18 -27
  52. package/lib/index.cjs +20 -0
  53. package/lib/index.js +12 -20
  54. package/lib/locales/en.cjs +22 -0
  55. package/lib/locales/en.js +2 -9
  56. package/lib/locales/es.cjs +22 -0
  57. package/lib/locales/es.js +2 -9
  58. package/lib/locales/index.cjs +14 -0
  59. package/lib/locales/index.js +6 -14
  60. package/lib/models/business.cjs +65 -0
  61. package/lib/models/business.js +5 -12
  62. package/lib/models/cookies.cjs +40 -0
  63. package/lib/models/cookies.js +3 -10
  64. package/lib/models/form.cjs +166 -0
  65. package/lib/models/form.js +10 -17
  66. package/lib/models/form_collection.cjs +119 -0
  67. package/lib/models/form_collection.js +15 -22
  68. package/lib/models/index.cjs +54 -0
  69. package/lib/models/index.js +7 -54
  70. package/lib/models/query.cjs +51 -0
  71. package/lib/models/query.js +3 -9
  72. package/lib/models/session.cjs +58 -0
  73. package/lib/models/session.js +12 -17
  74. package/lib/models/{web_chat.js → webchat.cjs} +14 -22
  75. package/lib/models/webchat.js +6 -13
  76. package/lib/vanilla.cjs +13 -0
  77. package/lib/vanilla.js +1 -13
  78. package/package.json +34 -7
  79. package/src/controllers/webchat_controller.js +72 -47
  80. package/src/hellotext.js +3 -4
  81. package/src/models/session.js +4 -3
  82. package/.babelrc +0 -24
  83. package/.github/workflows/ci.yml +0 -24
  84. package/.prettierignore +0 -3
  85. package/.prettierrc.json +0 -18
  86. package/MIT-LICENSE +0 -20
  87. package/__tests__/builders/input_builder_test.js +0 -117
  88. package/__tests__/core/configuration/forms_test.js +0 -30
  89. package/__tests__/core/configuration/webchat_test.js +0 -163
  90. package/__tests__/core/configuration_test.js +0 -28
  91. package/__tests__/core/event_test.js +0 -56
  92. package/__tests__/hellotext_test.js +0 -197
  93. package/__tests__/models/business_test.js +0 -26
  94. package/__tests__/models/cookies_test.js +0 -25
  95. package/__tests__/models/form_collection_test.js +0 -103
  96. package/__tests__/models/form_test.js +0 -131
  97. package/__tests__/models/query_test.js +0 -97
  98. package/docs/forms.md +0 -176
  99. package/docs/tracking.md +0 -203
  100. package/docs/webchat.md +0 -101
  101. package/jest.config.js +0 -4
  102. package/jest.setup.js +0 -16
  103. package/lib/api/web_chat/messages.js +0 -74
  104. package/lib/api/web_chats.js +0 -53
  105. package/styles/index.css +0 -38
  106. package/webpack.config.js +0 -24
package/docs/webchat.md DELETED
@@ -1,101 +0,0 @@
1
- ## Webchat
2
-
3
- Hellotext allows you to build webchats via the dashboard and allow Hellotext.js to load a given webchat with
4
- a specific ID and show it to the user. A webchat can be specified when initializing the library by passing a `webchat` property
5
- to the configuration option.
6
-
7
- ```js
8
- Hellotext.initialize('PUBLIC_BUSINESS_ID', {
9
- webchat: {
10
- id,
11
- container,
12
- placement,
13
- classes,
14
- triggerClasses,
15
- style: {
16
- primaryColor,
17
- secondaryColor,
18
- typography
19
- },
20
- behaviour,
21
- }
22
- })
23
- ```
24
-
25
- | Property | Description | Type | Default |
26
- |----------------|------------------------------------------------------------------------------------------------------------------------------------------|--------|----------------|
27
- | id | The id of the webchat to load. **required** | String | null |
28
- | container | The container to append the webchat to, must be a valid CSS selector. If none specified, the webchat is appended at the end of the body. | String | `body` |
29
- | placement | The placement of the webchat, determined according to the parent `container`. | Enum | `bottom-right` |
30
- | classes | An array or comma separated String of additional CSS classes to apply to the webchat popover. | String | null |
31
- | triggerClasses | An array or comma separated String of additional CSS classes to apply to the webchat trigger. | String | null |
32
- | style | Style overrides to the WebChat's style configuration as created on the dashboard. | Object | null |
33
- | behaviour | The behaviour of the webchat when it is open and a click was made outside of it | Enum | `popover` |
34
-
35
- ### Position
36
-
37
- The default position for a webchat is `bottom-right`, but you can specify any of the following values
38
-
39
- - `bottom-left`
40
- - `bottom-right`
41
- - `top-left`
42
- - `top-right`
43
-
44
- ### Style
45
-
46
- The following properties are accepted for the `style` object.
47
-
48
- - `primaryColor` - The primary color of the Webchat. Must be either in hex or rgb/a formats. Affects the following elements:
49
- - Trigger background
50
- - Popover header background
51
- - Agent icon color
52
- - Toolbar button hover
53
- - Incoming message background
54
-
55
- The primary color is controlled via a `--webchat-primary-color` CSS variable.
56
-
57
- - `secondaryColor` - The secondary color of the webchat. Must be either in hex or rgb/a formats. Affects the following elements:
58
- - Trigger icon color
59
- - Popover header text color
60
- - Agent icon background
61
- - Incoming message text color
62
-
63
- The secondary color is controlled via a `--webchat-secondary-color` CSS variable.
64
- - `typography` - The font family to use for the webchat.
65
-
66
- All properties accept a valid CSS value, for example, `primaryColor: '#EEEEEE'` or `secondaryColor: '#ff0000'`.
67
-
68
- ### behaviour
69
-
70
- Determines how the webchat functions when it is open and a click is made outside of it. The following values are accepted.
71
-
72
- - `popover` - Closes the webchat when a click is made outside of it. This is the default behaviour.
73
- - `modal` - Prevents the webchat from closing when a click is made outside of it. The webchat can only be closed by clicking on the trigger.
74
-
75
- ### Events
76
-
77
- The webchat emits the following events which can be listened to, to add an event listener you can `Hellotext.addEventListener(event, callback)`.
78
-
79
- - `webchat:mounted` - Emitted when the webchat is mounted
80
- - `webchat:opened` - Emitted when the webchat is opened
81
- - `webchat:closed` - Emitted when the webchat is closed
82
-
83
- - `webchat:message:sent` - Emitted when a message is sent by the user. The message is passed as an argument to the callback, containing the following properties
84
-
85
- ```javascript
86
- {
87
- id: 'xxxxxx'
88
- body: 'The message the client sent',
89
- attachments: [], // An array of File objects that reference the attachments the user sent.
90
- }
91
- ```
92
-
93
- - `webchat:message:received` - Emitted when a message is received by the webchat from Hellotext. The message is passed as an argument to the callback, containing the following properties
94
-
95
- ```javascript
96
- {
97
- id: 'xxxxxx',
98
- body: 'The message the client received from Hellotext',
99
- attachments: [], // An Array of URLs referencing the attachments the user received.
100
- }
101
- ```
package/jest.config.js DELETED
@@ -1,4 +0,0 @@
1
- module.exports = {
2
- setupFiles: ['<rootDir>/jest.setup.js'], // Setup file to run before tests
3
- testEnvironment: 'jsdom',
4
- };
package/jest.setup.js DELETED
@@ -1,16 +0,0 @@
1
- require('whatwg-fetch');
2
-
3
- global.crypto.randomUUID = () => {
4
- return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
5
- const r = (Math.random() * 16) | 0;
6
- const v = c === 'x' ? r : (r & 0x3) | 0x8;
7
- return v.toString(16);
8
- });
9
- };
10
-
11
- global.fetch = jest.fn(() =>
12
- Promise.resolve({
13
- json: () => Promise.resolve({}),
14
- text: () => Promise.resolve(''),
15
- })
16
- );
@@ -1,74 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
- var _hellotext = _interopRequireDefault(require("../../hellotext"));
8
- var _core = require("../../core");
9
- var _response = require("../response");
10
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
- 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); } }
12
- 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); }); }; }
13
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
14
- function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
15
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
16
- function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
17
- function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
18
- var WebChatMessagesAPI = /*#__PURE__*/function () {
19
- function WebChatMessagesAPI(webChatId) {
20
- _classCallCheck(this, WebChatMessagesAPI);
21
- this.webChatId = webChatId;
22
- }
23
- _createClass(WebChatMessagesAPI, [{
24
- key: "index",
25
- value: function () {
26
- var _index = _asyncToGenerator(function* (params) {
27
- var url = new URL(this.url);
28
- Object.entries(params).forEach(_ref => {
29
- var [key, value] = _ref;
30
- url.searchParams.append(key, value);
31
- });
32
- return yield fetch(url, {
33
- method: 'GET',
34
- headers: _hellotext.default.headers
35
- });
36
- });
37
- function index(_x) {
38
- return _index.apply(this, arguments);
39
- }
40
- return index;
41
- }()
42
- }, {
43
- key: "create",
44
- value: function () {
45
- var _create = _asyncToGenerator(function* (formData) {
46
- var response = yield fetch(this.url, {
47
- method: 'POST',
48
- headers: {
49
- Authorization: "Bearer ".concat(_hellotext.default.business.id)
50
- },
51
- body: formData
52
- });
53
- return new _response.Response(response.ok, response);
54
- });
55
- function create(_x2) {
56
- return _create.apply(this, arguments);
57
- }
58
- return create;
59
- }()
60
- }, {
61
- key: "url",
62
- get: function get() {
63
- return WebChatMessagesAPI.endpoint.replace(':id', this.webChatId);
64
- }
65
- }], [{
66
- key: "endpoint",
67
- get: function get() {
68
- return _core.Configuration.endpoint("public/webchats/:id/messages");
69
- }
70
- }]);
71
- return WebChatMessagesAPI;
72
- }();
73
- var _default = WebChatMessagesAPI;
74
- exports.default = _default;
@@ -1,53 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
- var _hellotext = _interopRequireDefault(require("../hellotext"));
8
- var _core = require("../core");
9
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
10
- 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); } }
11
- 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); }); }; }
12
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
13
- function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
14
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
15
- function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
16
- function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
17
- var WebChatsAPI = /*#__PURE__*/function () {
18
- function WebChatsAPI() {
19
- _classCallCheck(this, WebChatsAPI);
20
- }
21
- _createClass(WebChatsAPI, null, [{
22
- key: "endpoint",
23
- get: function get() {
24
- return _core.Configuration.endpoint('public/webchats');
25
- }
26
- }, {
27
- key: "get",
28
- value: function () {
29
- var _get = _asyncToGenerator(function* (id) {
30
- var url = new URL("".concat(this.endpoint, "/").concat(id));
31
- url.searchParams.append('session', _hellotext.default.session);
32
- Object.entries(_core.Configuration.webChat.style).forEach(_ref => {
33
- var [key, value] = _ref;
34
- url.searchParams.append("style[".concat(key, "]"), value);
35
- });
36
- url.searchParams.append('placement', _core.Configuration.webChat.placement);
37
- var response = yield fetch(url, {
38
- method: 'GET',
39
- headers: _hellotext.default.headers
40
- });
41
- var htmlText = yield response.text();
42
- return new DOMParser().parseFromString(htmlText, "text/html").querySelector('article');
43
- });
44
- function get(_x) {
45
- return _get.apply(this, arguments);
46
- }
47
- return get;
48
- }()
49
- }]);
50
- return WebChatsAPI;
51
- }();
52
- var _default = WebChatsAPI;
53
- exports.default = _default;
package/styles/index.css DELETED
@@ -1,38 +0,0 @@
1
- .hidden {
2
- display: none;
3
- }
4
-
5
- form[data-hello-form] {
6
- position: relative;
7
-
8
- & article {
9
- & [data-error-container] {
10
- font-size: 0.875rem;
11
- line-height: 1.25rem;
12
- display: none;
13
- }
14
-
15
- &:has(input:invalid) {
16
- & [data-error-container] {
17
- display: block;
18
- }
19
- }
20
- }
21
-
22
- & [data-logo-container] {
23
- display: flex;
24
- justify-content: center;
25
- align-items: flex-end;
26
- position: absolute;
27
- right: 1rem;
28
- bottom: 1rem;
29
-
30
- & small {
31
- margin: 0 0.3rem;
32
- }
33
-
34
- & [data-hello-brand] {
35
- width: 4rem;
36
- }
37
- }
38
- }
package/webpack.config.js DELETED
@@ -1,24 +0,0 @@
1
- module.exports = {
2
- mode: 'production',
3
- entry: ['@hotwired/stimulus', './lib/index.js'],
4
- output: {
5
- filename: 'hellotext.js',
6
- },
7
- module: {
8
- rules: [
9
- {
10
- test: /\.m?js$/,
11
- exclude: [/node_modules/],
12
- use: [
13
- {
14
- loader: 'babel-loader',
15
- },
16
- ],
17
- },
18
- {
19
- test: /\.css$/i,
20
- use: ['style-loader', 'css-loader'],
21
- },
22
- ],
23
- },
24
- }