@n8n/chat 0.9.0 → 0.9.1

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 (207) hide show
  1. package/__stories__/App.stories.d.ts +16 -0
  2. package/__stories__/App.stories.js +38 -0
  3. package/__stories__/App.stories.mjs +32 -0
  4. package/__tests__/index.spec.d.ts +1 -0
  5. package/__tests__/index.spec.js +146 -0
  6. package/__tests__/index.spec.mjs +172 -0
  7. package/__tests__/setup.js +3 -0
  8. package/__tests__/setup.mjs +1 -0
  9. package/__tests__/utils/create.d.ts +5 -0
  10. package/__tests__/utils/create.js +16 -0
  11. package/__tests__/utils/create.mjs +10 -0
  12. package/__tests__/utils/fetch.d.ts +3 -0
  13. package/__tests__/utils/fetch.js +20 -0
  14. package/__tests__/utils/fetch.mjs +9 -0
  15. package/__tests__/utils/index.js +38 -0
  16. package/__tests__/utils/index.mjs +3 -0
  17. package/__tests__/utils/selectors.d.ts +12 -0
  18. package/__tests__/utils/selectors.js +58 -0
  19. package/__tests__/utils/selectors.mjs +41 -0
  20. package/api/generic.d.ts +6 -0
  21. package/api/generic.js +68 -0
  22. package/api/generic.mjs +54 -0
  23. package/api/index.js +27 -0
  24. package/api/index.mjs +2 -0
  25. package/api/message.d.ts +3 -0
  26. package/api/message.js +33 -0
  27. package/api/message.mjs +30 -0
  28. package/chat.bundle.es.js +10761 -0
  29. package/chat.bundle.umd.js +18 -0
  30. package/chat.es.js +6872 -0
  31. package/chat.umd.js +18 -0
  32. package/components/Button.vue +34 -0
  33. package/components/ChatWindow.vue +104 -0
  34. package/{src/components → components}/GetStarted.vue +7 -7
  35. package/{src/components → components}/GetStartedFooter.vue +2 -2
  36. package/{src/components → components}/Input.vue +34 -39
  37. package/{src/components → components}/Layout.vue +26 -42
  38. package/{src/components → components}/Message.vue +39 -46
  39. package/components/MessageTyping.vue +101 -0
  40. package/{src/components → components}/MessagesList.vue +4 -4
  41. package/{src/components → components}/PoweredBy.vue +6 -7
  42. package/components/index.js +76 -0
  43. package/components/index.mjs +10 -0
  44. package/composables/index.js +38 -0
  45. package/composables/index.mjs +3 -0
  46. package/composables/useChat.d.ts +1 -0
  47. package/composables/useChat.js +11 -0
  48. package/composables/useChat.mjs +5 -0
  49. package/composables/useI18n.d.ts +4 -0
  50. package/composables/useI18n.js +23 -0
  51. package/composables/useI18n.mjs +12 -0
  52. package/composables/useOptions.d.ts +3 -0
  53. package/composables/useOptions.js +14 -0
  54. package/composables/useOptions.mjs +8 -0
  55. package/constants/defaults.d.ts +3 -0
  56. package/constants/defaults.js +32 -0
  57. package/constants/defaults.mjs +26 -0
  58. package/constants/index.js +38 -0
  59. package/constants/index.mjs +3 -0
  60. package/constants/localStorage.d.ts +2 -0
  61. package/constants/localStorage.js +8 -0
  62. package/{src/constants/localStorage.ts → constants/localStorage.mjs} +1 -1
  63. package/constants/symbols.d.ts +3 -0
  64. package/constants/symbols.js +8 -0
  65. package/constants/symbols.mjs +2 -0
  66. package/css/index.css +31 -0
  67. package/event-buses/chatEventBus.d.ts +1 -0
  68. package/event-buses/chatEventBus.js +8 -0
  69. package/event-buses/chatEventBus.mjs +2 -0
  70. package/event-buses/index.js +16 -0
  71. package/event-buses/index.mjs +1 -0
  72. package/index.d.ts +3 -0
  73. package/index.js +43 -0
  74. package/index.mjs +36 -0
  75. package/main.css +151 -0
  76. package/package.json +35 -2
  77. package/plugins/chat.d.ts +3 -0
  78. package/plugins/chat.js +91 -0
  79. package/plugins/chat.mjs +90 -0
  80. package/plugins/index.js +16 -0
  81. package/plugins/index.mjs +1 -0
  82. package/style.css +1 -0
  83. package/types/App.vue.d.ts +8 -0
  84. package/types/__stories__/App.stories.d.ts +17 -0
  85. package/types/__tests__/index.spec.d.ts +1 -0
  86. package/types/__tests__/setup.d.ts +0 -0
  87. package/types/__tests__/utils/create.d.ts +5 -0
  88. package/types/__tests__/utils/fetch.d.ts +4 -0
  89. package/types/__tests__/utils/index.d.ts +3 -0
  90. package/types/__tests__/utils/selectors.d.ts +12 -0
  91. package/types/api/generic.d.ts +6 -0
  92. package/types/api/index.d.ts +2 -0
  93. package/types/api/message.d.ts +3 -0
  94. package/types/chat.d.ts +11 -0
  95. package/types/chat.js +1 -0
  96. package/types/chat.mjs +0 -0
  97. package/types/components/Button.vue.d.ts +9 -0
  98. package/types/components/Chat.vue.d.ts +2 -0
  99. package/types/components/ChatWindow.vue.d.ts +2 -0
  100. package/types/components/GetStarted.vue.d.ts +2 -0
  101. package/types/components/GetStartedFooter.vue.d.ts +2 -0
  102. package/types/components/Input.vue.d.ts +2 -0
  103. package/types/components/Layout.vue.d.ts +11 -0
  104. package/types/components/Message.vue.d.ts +21 -0
  105. package/types/components/MessageTyping.vue.d.ts +15 -0
  106. package/types/components/MessagesList.vue.d.ts +14 -0
  107. package/types/components/PoweredBy.vue.d.ts +2 -0
  108. package/types/components/index.d.ts +10 -0
  109. package/types/composables/index.d.ts +3 -0
  110. package/types/composables/useChat.d.ts +2 -0
  111. package/types/composables/useI18n.d.ts +4 -0
  112. package/types/composables/useOptions.d.ts +4 -0
  113. package/types/constants/defaults.d.ts +3 -0
  114. package/types/constants/index.d.ts +3 -0
  115. package/types/constants/localStorage.d.ts +2 -0
  116. package/types/constants/symbols.d.ts +4 -0
  117. package/types/event-buses/chatEventBus.d.ts +1 -0
  118. package/types/event-buses/index.d.ts +1 -0
  119. package/types/index.js +49 -0
  120. package/types/index.mjs +4 -0
  121. package/types/messages.d.ts +6 -0
  122. package/types/messages.js +1 -0
  123. package/types/messages.mjs +0 -0
  124. package/types/options.d.ts +25 -0
  125. package/types/options.js +1 -0
  126. package/types/options.mjs +0 -0
  127. package/types/plugins/chat.d.ts +3 -0
  128. package/types/plugins/index.d.ts +1 -0
  129. package/types/types/chat.d.ts +11 -0
  130. package/types/types/index.d.ts +4 -0
  131. package/types/types/messages.d.ts +6 -0
  132. package/types/types/options.d.ts +25 -0
  133. package/types/types/webhook.d.ts +16 -0
  134. package/types/utils/event-bus.d.ts +8 -0
  135. package/types/utils/mount.d.ts +1 -0
  136. package/types/webhook.d.ts +16 -0
  137. package/types/webhook.js +1 -0
  138. package/types/webhook.mjs +0 -0
  139. package/utils/event-bus.d.ts +8 -0
  140. package/utils/event-bus.js +38 -0
  141. package/utils/event-bus.mjs +32 -0
  142. package/utils/index.d.ts +2 -0
  143. package/utils/index.js +27 -0
  144. package/utils/index.mjs +2 -0
  145. package/utils/mount.d.ts +1 -0
  146. package/utils/mount.js +19 -0
  147. package/utils/mount.mjs +13 -0
  148. package/.eslintignore +0 -2
  149. package/.eslintrc.cjs +0 -10
  150. package/.np-config.json +0 -5
  151. package/.storybook/main.ts +0 -27
  152. package/.storybook/preview.scss +0 -4
  153. package/.storybook/preview.ts +0 -16
  154. package/.vscode/extensions.json +0 -3
  155. package/build.config.js +0 -21
  156. package/env.d.ts +0 -1
  157. package/index.html +0 -13
  158. package/resources/images/fullscreen.png +0 -0
  159. package/resources/images/windowed.png +0 -0
  160. package/resources/workflow-manual.json +0 -238
  161. package/resources/workflow.json +0 -119
  162. package/scripts/pack.js +0 -11
  163. package/scripts/postbuild.js +0 -36
  164. package/src/__stories__/App.stories.ts +0 -43
  165. package/src/__tests__/index.spec.ts +0 -218
  166. package/src/__tests__/utils/create.ts +0 -16
  167. package/src/__tests__/utils/fetch.ts +0 -18
  168. package/src/__tests__/utils/selectors.ts +0 -53
  169. package/src/api/generic.ts +0 -63
  170. package/src/api/message.ts +0 -37
  171. package/src/components/Button.vue +0 -41
  172. package/src/components/ChatWindow.vue +0 -125
  173. package/src/components/MessageTyping.vue +0 -109
  174. package/src/composables/useChat.ts +0 -7
  175. package/src/composables/useI18n.ts +0 -16
  176. package/src/composables/useOptions.ts +0 -11
  177. package/src/constants/defaults.ts +0 -29
  178. package/src/constants/symbols.ts +0 -8
  179. package/src/css/_tokens.scss +0 -36
  180. package/src/css/index.scss +0 -1
  181. package/src/event-buses/chatEventBus.ts +0 -3
  182. package/src/index.ts +0 -42
  183. package/src/main.scss +0 -5
  184. package/src/plugins/chat.ts +0 -105
  185. package/src/types/chat.ts +0 -12
  186. package/src/types/messages.ts +0 -6
  187. package/src/types/options.ts +0 -28
  188. package/src/types/webhook.ts +0 -17
  189. package/src/utils/event-bus.ts +0 -51
  190. package/src/utils/mount.ts +0 -16
  191. package/tsconfig.json +0 -27
  192. package/vite.config.ts +0 -59
  193. package/vitest.config.ts +0 -20
  194. /package/{src/App.vue → App.vue} +0 -0
  195. /package/{src/__tests__/setup.ts → __tests__/setup.d.ts} +0 -0
  196. /package/{src/__tests__/utils/index.ts → __tests__/utils/index.d.ts} +0 -0
  197. /package/{src/api/index.ts → api/index.d.ts} +0 -0
  198. /package/{src/components → components}/Chat.vue +0 -0
  199. /package/{src/components/index.ts → components/index.d.ts} +0 -0
  200. /package/{src/composables/index.ts → composables/index.d.ts} +0 -0
  201. /package/{src/constants/index.ts → constants/index.d.ts} +0 -0
  202. /package/{src/event-buses/index.ts → event-buses/index.d.ts} +0 -0
  203. /package/{public/favicon.ico → favicon.ico} +0 -0
  204. /package/{src/plugins/index.ts → plugins/index.d.ts} +0 -0
  205. /package/{src/shims.d.ts → shims.d.ts} +0 -0
  206. /package/{src/types/index.ts → types/index.d.ts} +0 -0
  207. /package/{src/utils/index.ts → types/utils/index.d.ts} +0 -0
package/api/generic.js ADDED
@@ -0,0 +1,68 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.authenticatedFetch = authenticatedFetch;
7
+ exports.del = del;
8
+ exports.get = get;
9
+ exports.patch = patch;
10
+ exports.post = post;
11
+ exports.put = put;
12
+ async function getAccessToken() {
13
+ return "";
14
+ }
15
+ async function authenticatedFetch(...args) {
16
+ const accessToken = await getAccessToken();
17
+ const response = await fetch(args[0], {
18
+ ...args[1],
19
+ mode: "cors",
20
+ cache: "no-cache",
21
+ headers: {
22
+ "Content-Type": "application/json",
23
+ ...(accessToken ? {
24
+ authorization: `Bearer ${accessToken}`
25
+ } : {}),
26
+ ...args[1]?.headers
27
+ }
28
+ });
29
+ return await response.json();
30
+ }
31
+ async function get(url, query = {}, options = {}) {
32
+ let resolvedUrl = url;
33
+ if (Object.keys(query).length > 0) {
34
+ resolvedUrl = `${resolvedUrl}?${new URLSearchParams(query).toString()}`;
35
+ }
36
+ return await authenticatedFetch(resolvedUrl, {
37
+ ...options,
38
+ method: "GET"
39
+ });
40
+ }
41
+ async function post(url, body = {}, options = {}) {
42
+ return await authenticatedFetch(url, {
43
+ ...options,
44
+ method: "POST",
45
+ body: JSON.stringify(body)
46
+ });
47
+ }
48
+ async function put(url, body = {}, options = {}) {
49
+ return await authenticatedFetch(url, {
50
+ ...options,
51
+ method: "PUT",
52
+ body: JSON.stringify(body)
53
+ });
54
+ }
55
+ async function patch(url, body = {}, options = {}) {
56
+ return await authenticatedFetch(url, {
57
+ ...options,
58
+ method: "PATCH",
59
+ body: JSON.stringify(body)
60
+ });
61
+ }
62
+ async function del(url, body = {}, options = {}) {
63
+ return await authenticatedFetch(url, {
64
+ ...options,
65
+ method: "DELETE",
66
+ body: JSON.stringify(body)
67
+ });
68
+ }
@@ -0,0 +1,54 @@
1
+ async function getAccessToken() {
2
+ return "";
3
+ }
4
+ export async function authenticatedFetch(...args) {
5
+ const accessToken = await getAccessToken();
6
+ const response = await fetch(args[0], {
7
+ ...args[1],
8
+ mode: "cors",
9
+ cache: "no-cache",
10
+ headers: {
11
+ "Content-Type": "application/json",
12
+ ...accessToken ? { authorization: `Bearer ${accessToken}` } : {},
13
+ ...args[1]?.headers
14
+ }
15
+ });
16
+ return await response.json();
17
+ }
18
+ export async function get(url, query = {}, options = {}) {
19
+ let resolvedUrl = url;
20
+ if (Object.keys(query).length > 0) {
21
+ resolvedUrl = `${resolvedUrl}?${new URLSearchParams(
22
+ query
23
+ ).toString()}`;
24
+ }
25
+ return await authenticatedFetch(resolvedUrl, { ...options, method: "GET" });
26
+ }
27
+ export async function post(url, body = {}, options = {}) {
28
+ return await authenticatedFetch(url, {
29
+ ...options,
30
+ method: "POST",
31
+ body: JSON.stringify(body)
32
+ });
33
+ }
34
+ export async function put(url, body = {}, options = {}) {
35
+ return await authenticatedFetch(url, {
36
+ ...options,
37
+ method: "PUT",
38
+ body: JSON.stringify(body)
39
+ });
40
+ }
41
+ export async function patch(url, body = {}, options = {}) {
42
+ return await authenticatedFetch(url, {
43
+ ...options,
44
+ method: "PATCH",
45
+ body: JSON.stringify(body)
46
+ });
47
+ }
48
+ export async function del(url, body = {}, options = {}) {
49
+ return await authenticatedFetch(url, {
50
+ ...options,
51
+ method: "DELETE",
52
+ body: JSON.stringify(body)
53
+ });
54
+ }
package/api/index.js ADDED
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ var _generic = require("./generic");
7
+ Object.keys(_generic).forEach(function (key) {
8
+ if (key === "default" || key === "__esModule") return;
9
+ if (key in exports && exports[key] === _generic[key]) return;
10
+ Object.defineProperty(exports, key, {
11
+ enumerable: true,
12
+ get: function () {
13
+ return _generic[key];
14
+ }
15
+ });
16
+ });
17
+ var _message = require("./message");
18
+ Object.keys(_message).forEach(function (key) {
19
+ if (key === "default" || key === "__esModule") return;
20
+ if (key in exports && exports[key] === _message[key]) return;
21
+ Object.defineProperty(exports, key, {
22
+ enumerable: true,
23
+ get: function () {
24
+ return _message[key];
25
+ }
26
+ });
27
+ });
package/api/index.mjs ADDED
@@ -0,0 +1,2 @@
1
+ export * from "./generic.mjs";
2
+ export * from "./message.mjs";
@@ -0,0 +1,3 @@
1
+ import type { ChatOptions } from '@n8n/chat/types';
2
+ export declare function loadPreviousSession(sessionId: string, options: ChatOptions): Promise<any>;
3
+ export declare function sendMessage(message: string, sessionId: string, options: ChatOptions): Promise<any>;
package/api/message.js ADDED
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.loadPreviousSession = loadPreviousSession;
7
+ exports.sendMessage = sendMessage;
8
+ var _generic = require("@n8n/chat/api/generic");
9
+ async function loadPreviousSession(sessionId, options) {
10
+ const method = options.webhookConfig?.method === "POST" ? _generic.post : _generic.get;
11
+ return await method(`${options.webhookUrl}`, {
12
+ action: "loadPreviousSession",
13
+ [options.chatSessionKey]: sessionId,
14
+ ...(options.metadata ? {
15
+ metadata: options.metadata
16
+ } : {})
17
+ }, {
18
+ headers: options.webhookConfig?.headers
19
+ });
20
+ }
21
+ async function sendMessage(message, sessionId, options) {
22
+ const method = options.webhookConfig?.method === "POST" ? _generic.post : _generic.get;
23
+ return await method(`${options.webhookUrl}`, {
24
+ action: "sendMessage",
25
+ [options.chatSessionKey]: sessionId,
26
+ [options.chatInputKey]: message,
27
+ ...(options.metadata ? {
28
+ metadata: options.metadata
29
+ } : {})
30
+ }, {
31
+ headers: options.webhookConfig?.headers
32
+ });
33
+ }
@@ -0,0 +1,30 @@
1
+ import { get, post } from "@n8n/chat/api/generic";
2
+ export async function loadPreviousSession(sessionId, options) {
3
+ const method = options.webhookConfig?.method === "POST" ? post : get;
4
+ return await method(
5
+ `${options.webhookUrl}`,
6
+ {
7
+ action: "loadPreviousSession",
8
+ [options.chatSessionKey]: sessionId,
9
+ ...options.metadata ? { metadata: options.metadata } : {}
10
+ },
11
+ {
12
+ headers: options.webhookConfig?.headers
13
+ }
14
+ );
15
+ }
16
+ export async function sendMessage(message, sessionId, options) {
17
+ const method = options.webhookConfig?.method === "POST" ? post : get;
18
+ return await method(
19
+ `${options.webhookUrl}`,
20
+ {
21
+ action: "sendMessage",
22
+ [options.chatSessionKey]: sessionId,
23
+ [options.chatInputKey]: message,
24
+ ...options.metadata ? { metadata: options.metadata } : {}
25
+ },
26
+ {
27
+ headers: options.webhookConfig?.headers
28
+ }
29
+ );
30
+ }