shadow-claw 1.23.3 → 1.24.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.
- package/README.md +42 -5
- package/bin/assert-version-bump.mjs +60 -38
- package/bin/assert-version-bump.test.mjs +74 -11
- package/bin/cli.mjs +166 -0
- package/bin/cli.test.mjs +60 -0
- package/bin/commands/backup.mjs +70 -0
- package/bin/commands/clients.mjs +41 -0
- package/bin/commands/peer-id.mjs +76 -0
- package/bin/commands/peer-id.test.mjs +104 -0
- package/bin/commands/send.mjs +51 -0
- package/bin/commands/tasks.mjs +59 -0
- package/bin/commands/webrtc-listen.mjs +254 -0
- package/bin/prerender-dsd-shell/prerender-dsd-shell.test.mjs +46 -0
- package/bin/rolldown.config.test.mjs +401 -8
- package/bin/utils/control-client.mjs +243 -0
- package/bin/utils/control-client.test.mjs +83 -0
- package/bin/utils/ulid.mjs +45 -0
- package/bin/utils/webrtc-control-client.mjs +699 -0
- package/bin/utils/webrtc-control-client.test.mjs +318 -0
- package/dist/electron/main.cjs +1 -1
- package/dist/public/AGENTS.md +5 -3
- package/dist/public/README.md +42 -5
- package/dist/public/agent.worker.js +6 -6
- package/dist/public/{app-routes-B0ePT49v.js → app-routes-Bs-riIvr.js} +1 -1
- package/dist/public/backup-controller-C_s9in2t.js +1 -0
- package/dist/public/components/settings/shadow-claw-control-plane/shadow-claw-control-plane.css +1 -0
- package/dist/public/components/settings/shadow-claw-control-plane/shadow-claw-control-plane.html +1 -0
- package/dist/public/components/settings/shadow-claw-storage/shadow-claw-storage.html +1 -1
- package/dist/public/components/settings/shadow-claw-task-server/shadow-claw-task-server.css +1 -1
- package/dist/public/components/settings/shadow-claw-task-server/shadow-claw-task-server.html +1 -1
- package/dist/public/components/shadow-claw-files/shadow-claw-files.css +1 -1
- package/dist/public/components/shadow-claw-files/shadow-claw-files.html +1 -1
- package/dist/public/components/shadow-claw-settings/shadow-claw-settings.html +1 -1
- package/dist/public/config-CrHchneq.js +1 -0
- package/dist/public/{configurePeerJs-B7kNU8AQ.js → configurePeerJs-CxpZeDJJ.js} +1 -1
- package/dist/public/{connections-xd_66YVU.js → connections-DvbgdkaB.js} +1 -1
- package/dist/public/{custom-element-security-CZ92anB8.js → custom-element-security-NCqQ5lmC.js} +1 -1
- package/dist/public/docs/README.md +3 -1
- package/dist/public/docs/architecture/overview.md +12 -12
- package/dist/public/docs/architecture/storage.md +5 -2
- package/dist/public/docs/decisions/bundled-typescript-architecture.md +1 -1
- package/dist/public/docs/decisions/indexeddb-and-opfs-storage.md +6 -3
- package/dist/public/docs/decisions/native-web-components-and-signals.md +1 -1
- package/dist/public/docs/example/article/index.html +2 -2
- package/dist/public/docs/guides/configuring-messaging-channels.md +41 -6
- package/dist/public/docs/guides/server-development-configuration.md +24 -0
- package/dist/public/docs/publishing/index.html +19 -76
- package/dist/public/docs/skill-creator/index.html +2 -2
- package/dist/public/docs/subsystems/backup.md +56 -0
- package/dist/public/docs/subsystems/cli.md +124 -0
- package/dist/public/docs/subsystems/control-plane.md +158 -0
- package/dist/public/docs/subsystems/notifications.md +54 -2
- package/dist/public/docs/subsystems/reactive-ui.md +1 -0
- package/dist/public/downloadGroupFile-By0GR6eV.js +1 -0
- package/dist/public/e2e/README.md +5 -1
- package/dist/public/{e2e-bridge-DkS5xFGX.js → e2e-bridge-IGWsRl4i.js} +1 -1
- package/dist/public/file-viewer-D0eflgt6.js +1 -0
- package/dist/public/files/main/~/docs/publishing-to-github-pages.md +17 -82
- package/dist/public/getAllTasks-vpBlgGsc.js +1 -0
- package/dist/public/getGroupDir-P1h9wl6S.js +1 -0
- package/dist/public/{git-BkjrsRXX.js → git-7Vq_SJSp.js} +2 -2
- package/dist/public/{iframe-sanitizer-L6Jyu__Z.js → iframe-sanitizer-y2Z1pPwY.js} +1 -1
- package/dist/public/index.html +2 -2
- package/dist/public/index.js +1 -1
- package/dist/public/{initChatSplitResize-BslPXAXS.js → initChatSplitResize-CzV2E7Ul.js} +1 -1
- package/dist/public/initControlPlane-C9jpnWev.js +1 -0
- package/dist/public/llms.txt +1 -1
- package/dist/public/main/index.html +2 -2
- package/dist/public/main/memory/index.html +2 -2
- package/dist/public/{markdown-6MBrIo-S.js → markdown-BnpKxSxl.js} +1 -1
- package/dist/public/mcp-reconnect-9emsqGRe.js +1 -0
- package/dist/public/{memoryStorage-CjGseKI1.js → memoryStorage-C0KvLNUp.js} +1 -1
- package/dist/public/{orchestrator-B9KmIj8Q.js → orchestrator-3h9xxHUm.js} +676 -676
- package/dist/public/orchestrator-nJj59RqD.js +15 -0
- package/dist/public/pages/main/~/docs/publishing-to-github-pages.md +17 -82
- package/dist/public/{peerjs-Dv8JNm7v.js → peerjs-BP4laMXj.js} +1 -1
- package/dist/public/{push-client-Dqq06wbB.js → push-client-CrjEXK3U.js} +1 -1
- package/dist/public/service-worker/fetch-proxy.js +1 -1
- package/dist/public/service-worker/push-handler.js +1 -1
- package/dist/public/service-worker.js +1 -1
- package/dist/public/{shadow-claw-Bd1rfuVC.js → shadow-claw-CbwETBWf.js} +2 -2
- package/dist/public/{shadow-claw-accounts-DL2l3oM0.js → shadow-claw-accounts-B4sBTQEj.js} +3 -3
- package/dist/public/{shadow-claw-channels-BGXDsQ38.js → shadow-claw-channels-BDWG5Qa3.js} +1 -1
- package/dist/public/{shadow-claw-chat-NXg6zz_l.js → shadow-claw-chat-Crv0DTCY.js} +6 -6
- package/dist/public/shadow-claw-control-plane-CX1IGbh9.js +199 -0
- package/dist/public/{shadow-claw-conversations-C8eqGpP9.js → shadow-claw-conversations-_9qAaRXk.js} +1 -1
- package/dist/public/shadow-claw-dialog-BrOwAOdk.js +1 -0
- package/dist/public/shadow-claw-file-viewer-Blf6yGVD.js +577 -0
- package/dist/public/shadow-claw-files-CYySBDCl.js +840 -0
- package/dist/public/{shadow-claw-git-C0ntz7aX.js → shadow-claw-git-v8S0JjuR.js} +3 -3
- package/dist/public/{shadow-claw-integrations-DCXV2r69.js → shadow-claw-integrations-D7ufpwhX.js} +1 -1
- package/dist/public/{shadow-claw-llm-CudgFQsS.js → shadow-claw-llm-GWgoVfhI.js} +2 -2
- package/dist/public/{shadow-claw-mcp-remote-B8RkpX28.js → shadow-claw-mcp-remote-kY4LMFNN.js} +1 -1
- package/dist/public/{shadow-claw-networking-BLiRsrsK.js → shadow-claw-networking-qHbP95z9.js} +1 -1
- package/dist/public/{shadow-claw-notifications-CQhQcjtL.js → shadow-claw-notifications-YyHOK2Fr.js} +1 -1
- package/dist/public/{shadow-claw-page-header-NeRD0tKU.js → shadow-claw-page-header-DMKbkv3s.js} +1 -1
- package/dist/public/{shadow-claw-pages-DCHnFh6r.js → shadow-claw-pages-DFZHhzFZ.js} +3 -3
- package/dist/public/{shadow-claw-settings-VAfjKFQg.js → shadow-claw-settings-DhxrKIfA.js} +10 -3
- package/dist/public/shadow-claw-storage-BFynbP0j.js +219 -0
- package/dist/public/{shadow-claw-task-server-Dk33N_1G.js → shadow-claw-task-server-3BIeb5oZ.js} +25 -4
- package/dist/public/{shadow-claw-tasks-xA1VfmWN.js → shadow-claw-tasks-Caxc9atL.js} +4 -4
- package/dist/public/{shadow-claw-terminal-Du2r0ciq.js → shadow-claw-terminal-Beb5qF-U.js} +1 -1
- package/dist/public/{shadow-claw-tools-CZj4rq7l.js → shadow-claw-tools-BfJx3A9W.js} +2 -2
- package/dist/public/{shadow-claw-webvm-JYUkWICG.js → shadow-claw-webvm-BCS8ykeP.js} +1 -1
- package/dist/public/static-main/~/docs/publishing-to-github-pages.md +17 -82
- package/dist/public/static-main-manifest.json +1 -1
- package/dist/public/{syncWebMcpRegistration-DfpvASnh.js → syncWebMcpRegistration-B_M2fCjH.js} +1 -1
- package/dist/server.js +286 -189
- package/package.json +2 -1
- package/src/__mocks__/jszip.cjs +15 -5
- package/src/components/settings/shadow-claw-accounts/shadow-claw-accounts.test.ts +35 -0
- package/src/components/settings/shadow-claw-control-plane/shadow-claw-control-plane.css +117 -0
- package/src/components/settings/shadow-claw-control-plane/shadow-claw-control-plane.html +81 -0
- package/src/components/settings/shadow-claw-control-plane/shadow-claw-control-plane.test.ts +127 -0
- package/src/components/settings/shadow-claw-control-plane/shadow-claw-control-plane.ts +292 -0
- package/src/components/settings/shadow-claw-git/shadow-claw-git.test.ts +72 -0
- package/src/components/settings/shadow-claw-integrations/connection-test-auth.test.ts +20 -30
- package/src/components/settings/shadow-claw-integrations/shadow-claw-integrations.test.ts +116 -0
- package/src/components/settings/shadow-claw-llm/model-ranking.test.ts +143 -51
- package/src/components/settings/shadow-claw-llm/shadow-claw-llm.test.ts +307 -4
- package/src/components/settings/shadow-claw-llm/shadow-claw-llm.ts +8 -8
- package/src/components/settings/shadow-claw-mcp-remote/shadow-claw-mcp-remote.test.ts +31 -0
- package/src/components/settings/shadow-claw-peerjs/shadow-claw-peerjs.test.ts +186 -0
- package/src/components/settings/shadow-claw-storage/shadow-claw-storage.html +17 -0
- package/src/components/settings/shadow-claw-storage/shadow-claw-storage.test.ts +120 -0
- package/src/components/settings/shadow-claw-storage/shadow-claw-storage.ts +56 -0
- package/src/components/settings/shadow-claw-task-server/shadow-claw-task-server.css +23 -2
- package/src/components/settings/shadow-claw-task-server/shadow-claw-task-server.html +1 -1
- package/src/components/settings/shadow-claw-task-server/shadow-claw-task-server.test.ts +19 -0
- package/src/components/settings/shadow-claw-task-server/shadow-claw-task-server.ts +2 -1
- package/src/components/shadow-claw/utils/initChatSplitResize.test.ts +180 -13
- package/src/components/shadow-claw/utils/setupEffects.test.ts +39 -0
- package/src/components/shadow-claw-a2ui/catalog/basic/shared.test.ts +117 -0
- package/src/components/shadow-claw-a2ui/shadow-claw-a2ui.test.ts +1159 -1
- package/src/components/shadow-claw-chat/shadow-claw-chat.test.ts +1523 -19
- package/src/components/shadow-claw-chat/utils/escapeHtml.test.ts +13 -0
- package/src/components/shadow-claw-chat/utils/getPeerChatDisplayStatus.test.ts +20 -0
- package/src/components/shadow-claw-conversations/shadow-claw-conversations.test.ts +494 -0
- package/src/components/shadow-claw-dialog/shadow-claw-dialog.ts +13 -2
- package/src/components/shadow-claw-file-viewer/shadow-claw-file-viewer.test.ts +378 -0
- package/src/components/shadow-claw-file-viewer/shadow-claw-file-viewer.ts +11 -9
- package/src/components/shadow-claw-files/shadow-claw-files.css +41 -17
- package/src/components/shadow-claw-files/shadow-claw-files.html +35 -0
- package/src/components/shadow-claw-files/shadow-claw-files.test.ts +627 -1
- package/src/components/shadow-claw-files/shadow-claw-files.ts +170 -6
- package/src/components/shadow-claw-pages/utils/resolveWorkspaceLinkPath.test.ts +31 -0
- package/src/components/shadow-claw-pages/utils/resolveWorkspaceLinkPath.ts +2 -1
- package/src/components/shadow-claw-pages/utils/rewriteWorkspacePreviewHtml.test.ts +15 -0
- package/src/components/shadow-claw-pdf-viewer/utils/installGetOrInsertComputedPolyfill.test.ts +65 -0
- package/src/components/shadow-claw-settings/shadow-claw-settings.html +7 -0
- package/src/components/shadow-claw-settings/shadow-claw-settings.test.ts +221 -0
- package/src/components/shadow-claw-settings/shadow-claw-settings.ts +2 -0
- package/src/components/shadow-claw-tasks/shadow-claw-tasks.test.ts +407 -0
- package/src/components/shadow-claw-terminal/utils/consumeEscapeSequence.test.ts +58 -0
- package/src/components/shadow-claw-tools/shadow-claw-tools.test.ts +80 -0
- package/src/config/config.test.ts +9 -0
- package/src/config/config.ts +15 -0
- package/src/core/app-routes.test.ts +56 -0
- package/src/core/app-routes.ts +8 -1
- package/src/core/backup-controller.test.ts +101 -0
- package/src/core/backup-controller.ts +137 -0
- package/src/core/control-plane-client.test.ts +408 -0
- package/src/core/control-plane-client.ts +425 -0
- package/src/core/orchestrator/orchestrator.ts +4 -0
- package/src/core/orchestrator/utils/compactContext.test.ts +78 -0
- package/src/core/orchestrator/utils/operations/channel.test.ts +254 -9
- package/src/core/orchestrator/utils/operations/provider.test.ts +326 -34
- package/src/core/orchestrator/utils/operations/vm.test.ts +114 -2
- package/src/core/orchestrator/utils/syncProxyConfigToServiceWorker.test.ts +60 -0
- package/src/core/utils/initControlPlane.test.ts +276 -0
- package/src/core/utils/initControlPlane.ts +437 -0
- package/src/core/utils/initializeApp.ts +18 -0
- package/src/db/getSession.test.ts +13 -1
- package/src/db/openDatabase.test.ts +10 -1
- package/src/db/openDatabase.ts +3 -1
- package/src/server/app.test.ts +12 -0
- package/src/server/app.ts +18 -8
- package/src/server/client-registry.test.ts +250 -0
- package/src/server/client-registry.ts +477 -0
- package/src/server/config.ts +15 -0
- package/src/server/control-plane-types.ts +120 -0
- package/src/server/control-plane.test.ts +472 -0
- package/src/server/control-plane.ts +581 -0
- package/src/server/routes/backup.test.ts +263 -0
- package/src/server/routes/backup.ts +262 -0
- package/src/server/routes/integrations-email.test.ts +532 -0
- package/src/server/routes/llamafile.test.ts +172 -48
- package/src/server/routes/mesh-llm.test.ts +192 -0
- package/src/server/routes/ollama.test.ts +49 -0
- package/src/server/server-peer.test.ts +86 -0
- package/src/server/server-peer.ts +330 -0
- package/src/server/server.ts +35 -0
- package/src/server/services/llamafile-manager.test.ts +230 -6
- package/src/server/services/transformers-runtime.test.ts +186 -18
- package/src/server/webrtc.test.ts +21 -0
- package/src/server/webrtc.ts +72 -0
- package/src/service-worker/fetch-proxy.test.ts +64 -1
- package/src/service-worker/push-handler.ts +39 -0
- package/src/shell/vm.test.ts +744 -12
- package/src/storage/ensureMainGroupIndex.test.ts +153 -0
- package/src/storage/getGroupFile.test.ts +66 -0
- package/src/storage/memoryStorage.test.ts +82 -2
- package/src/storage/migrateLegacyOpfs.test.ts +327 -0
- package/src/storage/migrateLegacyOpfs.ts +117 -0
- package/src/storage/writeGroupFileBytes.test.ts +143 -0
- package/src/stores/chat-ui.test.ts +20 -0
- package/src/stores/orchestrator.test.ts +134 -0
- package/src/stores/toast.test.ts +50 -0
- package/src/stores/tools.test.ts +147 -10
- package/src/subsystems/channels/imessage.test.ts +59 -0
- package/src/subsystems/channels/peerjs.test.ts +500 -62
- package/src/subsystems/channels/peerjs.ts +71 -4
- package/src/subsystems/channels/telegram.test.ts +177 -0
- package/src/subsystems/email/catalog.test.ts +1 -0
- package/src/subsystems/email/connections.test.ts +39 -1
- package/src/subsystems/git/credentials.test.ts +160 -825
- package/src/subsystems/git/git.test.ts +463 -0
- package/src/subsystems/notifications/__mocks__/node-sqlite.cjs +12 -1
- package/src/subsystems/notifications/push-routes.test.ts +33 -0
- package/src/subsystems/notifications/push-routes.ts +23 -0
- package/src/subsystems/notifications/push-store.ts +1 -1
- package/src/subsystems/providers/builtin-ai-tasks.test.ts +74 -0
- package/src/subsystems/providers/litert-lm-provider.test.ts +212 -51
- package/src/subsystems/providers/model-registry.test.ts +115 -0
- package/src/subsystems/providers/providers.test.ts +94 -1
- package/src/subsystems/providers/transformers-js-provider.test.ts +279 -0
- package/src/subsystems/providers/utils/createModelCacheFetch.test.ts +2 -2
- package/src/subsystems/providers/utils/downloadModelToCache.test.ts +2 -2
- package/src/subsystems/providers/utils/loadModelStream.test.ts +2 -2
- package/src/subsystems/skills/activateSkill.test.ts +101 -0
- package/src/subsystems/skills/discoverSkills.test.ts +251 -0
- package/src/subsystems/tools/cron.test.ts +64 -0
- package/src/subsystems/tools/declarative.test.ts +255 -89
- package/src/testing/assets/v86.9pfs/libv86.mjs +63 -0
- package/src/testing/assets/v86.ext2/libv86.mjs +3 -0
- package/src/testing/assets_missing_v86/assets/v86.9pfs/libv86.mjs +1 -0
- package/src/testing/jest-setup.ts +328 -40
- package/src/testing/mock-v86.mjs +49 -0
- package/src/ui/a2ui/types.ts +4 -3
- package/src/ui/a2ui/utils/normaliseComponentsToMap.test.ts +102 -0
- package/src/ui/a2ui/utils/resolveChildIds.test.ts +63 -0
- package/src/ui/a2ui/utils/resolveDynamicNumber.test.ts +13 -1
- package/src/worker/tools/bash/utils/waitForVMReady.test.ts +40 -0
- package/src/worker/tools/email/email.test.ts +193 -8
- package/src/worker/tools/email/utils/asEmailAttachmentInputs.test.ts +47 -0
- package/src/worker/tools/git/git.test.ts +214 -3
- package/src/worker/tools/rooms/invite-to-room.test.ts +54 -0
- package/src/worker/tools/rooms/leave-room.test.ts +40 -0
- package/src/worker/tools/rooms/list-room-members.test.ts +75 -0
- package/src/worker/tools/tasks/tasks-utils.test.ts +22 -0
- package/src/worker/tools/ui/ask-user.test.ts +50 -0
- package/src/worker/tools/ui/clear-chat.test.ts +19 -0
- package/src/worker/tools/ui/get-current-time.test.ts +19 -0
- package/src/worker/tools/ui/javascript.test.ts +116 -0
- package/src/worker/tools/ui/list-components.test.ts +10 -0
- package/src/worker/tools/ui/list-tool-profiles.test.ts +42 -0
- package/src/worker/tools/ui/manage-tools.test.ts +34 -0
- package/src/worker/tools/ui/render-component.test.ts +346 -0
- package/src/worker/tools/ui/send-notification.test.ts +40 -0
- package/src/worker/tools/ui/utils/getAllowFullInternetAccess.test.ts +31 -0
- package/src/worker/tools/ui/utils/parseBooleanConfig.test.ts +25 -0
- package/src/worker/tools/workspace/attach-file.test.ts +84 -0
- package/src/worker/tools/workspace/copy-file.test.ts +69 -0
- package/src/worker/tools/workspace/create-directory.test.ts +40 -0
- package/src/worker/tools/workspace/delete-file.test.ts +73 -0
- package/src/worker/tools/workspace/diff-files.test.ts +94 -0
- package/src/worker/tools/workspace/list-files.test.ts +36 -0
- package/src/worker/tools/workspace/move-file.test.ts +66 -0
- package/src/worker/tools/workspace/open-file.test.ts +57 -0
- package/src/worker/tools/workspace/patch-file.test.ts +81 -0
- package/src/worker/tools/workspace/read-file.test.ts +116 -0
- package/src/worker/tools/workspace/send-file.test.ts +82 -0
- package/src/worker/tools/workspace/update-memory.test.ts +29 -0
- package/src/worker/tools/workspace/write-file.test.ts +28 -0
- package/src/worker/utils/rate-limit.test.ts +199 -0
- package/src/worker/utils/tool-state.test.ts +29 -0
- package/src/worker/utils/transformers-js-utils.test.ts +59 -0
- package/dist/public/config-AL77QAx4.js +0 -1
- package/dist/public/downloadGroupFile-BABv_1mJ.js +0 -1
- package/dist/public/file-viewer-CCSABMsE.js +0 -1
- package/dist/public/mcp-reconnect-DoicazQd.js +0 -1
- package/dist/public/orchestrator-4su7iyWj.js +0 -15
- package/dist/public/shadow-claw-dialog-ByyHgxM9.js +0 -1
- package/dist/public/shadow-claw-file-viewer-9Qkwc30T.js +0 -577
- package/dist/public/shadow-claw-files-aDyq6Hv7.js +0 -781
- package/dist/public/shadow-claw-storage-Cf31np81.js +0 -202
|
@@ -0,0 +1,532 @@
|
|
|
1
|
+
import { jest } from "@jest/globals";
|
|
2
|
+
|
|
3
|
+
describe("integrations-email routes", () => {
|
|
4
|
+
let routes: Map<string, any>;
|
|
5
|
+
let mockConnect: jest.Mock<any>;
|
|
6
|
+
let mockMailboxOpen: jest.Mock<any>;
|
|
7
|
+
let mockFetchOne: jest.Mock<any>;
|
|
8
|
+
let mockDownload: jest.Mock<any>;
|
|
9
|
+
let mockMessageFlagsAdd: jest.Mock<any>;
|
|
10
|
+
let mockMessageFlagsRemove: jest.Mock<any>;
|
|
11
|
+
let mockMessageDelete: jest.Mock<any>;
|
|
12
|
+
let mockSearch: jest.Mock<any>;
|
|
13
|
+
let mockLogout: jest.Mock<any>;
|
|
14
|
+
let mockSendMail: jest.Mock<any>;
|
|
15
|
+
let mockCreateTransport: jest.Mock<any>;
|
|
16
|
+
let clientUsable: boolean;
|
|
17
|
+
|
|
18
|
+
function createResponse() {
|
|
19
|
+
const res: any = {
|
|
20
|
+
statusCode: 200,
|
|
21
|
+
body: undefined,
|
|
22
|
+
headers: {},
|
|
23
|
+
status: jest.fn().mockImplementation((code: any) => {
|
|
24
|
+
res.statusCode = code;
|
|
25
|
+
return res;
|
|
26
|
+
}),
|
|
27
|
+
json: jest.fn().mockImplementation((payload: any) => {
|
|
28
|
+
res.body = payload;
|
|
29
|
+
return res;
|
|
30
|
+
}),
|
|
31
|
+
};
|
|
32
|
+
return res;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
beforeEach(async () => {
|
|
36
|
+
jest.resetModules();
|
|
37
|
+
routes = new Map();
|
|
38
|
+
clientUsable = true;
|
|
39
|
+
|
|
40
|
+
mockConnect = jest.fn().mockResolvedValue(undefined as never);
|
|
41
|
+
mockMailboxOpen = jest.fn().mockResolvedValue(undefined as never);
|
|
42
|
+
mockFetchOne = jest.fn().mockResolvedValue(undefined as never);
|
|
43
|
+
mockDownload = jest.fn().mockResolvedValue(undefined as never);
|
|
44
|
+
mockMessageFlagsAdd = jest.fn().mockResolvedValue(undefined as never);
|
|
45
|
+
mockMessageFlagsRemove = jest.fn().mockResolvedValue(undefined as never);
|
|
46
|
+
mockMessageDelete = jest.fn().mockResolvedValue(undefined as never);
|
|
47
|
+
mockSearch = jest.fn().mockResolvedValue([] as never);
|
|
48
|
+
mockLogout = jest.fn().mockResolvedValue(undefined as never);
|
|
49
|
+
|
|
50
|
+
mockSendMail = jest.fn().mockResolvedValue({
|
|
51
|
+
messageId: "<msg-123@domain.com>",
|
|
52
|
+
accepted: ["recipient@domain.com"],
|
|
53
|
+
rejected: [],
|
|
54
|
+
response: "250 OK",
|
|
55
|
+
} as never);
|
|
56
|
+
|
|
57
|
+
mockCreateTransport = jest.fn().mockReturnValue({
|
|
58
|
+
sendMail: mockSendMail,
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
class MockImapFlow {
|
|
62
|
+
get usable() {
|
|
63
|
+
return clientUsable;
|
|
64
|
+
}
|
|
65
|
+
connect = mockConnect;
|
|
66
|
+
mailboxOpen = mockMailboxOpen;
|
|
67
|
+
fetchOne = mockFetchOne;
|
|
68
|
+
download = mockDownload;
|
|
69
|
+
messageFlagsAdd = mockMessageFlagsAdd;
|
|
70
|
+
messageFlagsRemove = mockMessageFlagsRemove;
|
|
71
|
+
messageDelete = mockMessageDelete;
|
|
72
|
+
search = mockSearch;
|
|
73
|
+
logout = mockLogout;
|
|
74
|
+
constructor(_opts: any) {}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
jest.unstable_mockModule("imapflow", () => ({
|
|
78
|
+
ImapFlow: MockImapFlow,
|
|
79
|
+
}));
|
|
80
|
+
|
|
81
|
+
jest.unstable_mockModule("nodemailer", () => ({
|
|
82
|
+
createTransport: mockCreateTransport,
|
|
83
|
+
}));
|
|
84
|
+
|
|
85
|
+
const { registerIntegrationEmailRoutes } =
|
|
86
|
+
await import("./integrations-email.js");
|
|
87
|
+
|
|
88
|
+
const app = {
|
|
89
|
+
post: jest.fn((path: string, handler: any) => {
|
|
90
|
+
routes.set(`POST ${path}`, handler);
|
|
91
|
+
}),
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
registerIntegrationEmailRoutes(app as any, { verbose: false });
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
describe("POST /integrations/email/download-attachments", () => {
|
|
98
|
+
const route = "POST /integrations/email/download-attachments";
|
|
99
|
+
|
|
100
|
+
it("returns 400 on missing credentials or messageUid", async () => {
|
|
101
|
+
const handler = routes.get(route);
|
|
102
|
+
const res1 = createResponse();
|
|
103
|
+
await handler({ body: {} }, res1);
|
|
104
|
+
expect(res1.status).toHaveBeenCalledWith(400);
|
|
105
|
+
|
|
106
|
+
const res2 = createResponse();
|
|
107
|
+
await handler(
|
|
108
|
+
{
|
|
109
|
+
body: { host: "imap.example.com", username: "user", password: "pwd" },
|
|
110
|
+
},
|
|
111
|
+
res2,
|
|
112
|
+
);
|
|
113
|
+
expect(res2.status).toHaveBeenCalledWith(400);
|
|
114
|
+
expect(res2.body.error).toContain("Missing required field: messageUid.");
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
it("downloads specified attachment parts successfully", async () => {
|
|
118
|
+
const handler = routes.get(route);
|
|
119
|
+
mockFetchOne.mockResolvedValue({
|
|
120
|
+
uid: 101,
|
|
121
|
+
bodyStructure: {
|
|
122
|
+
part: "1",
|
|
123
|
+
disposition: "attachment",
|
|
124
|
+
dispositionParameters: { filename: "test.pdf" },
|
|
125
|
+
type: "application",
|
|
126
|
+
subtype: "pdf",
|
|
127
|
+
size: 1024,
|
|
128
|
+
},
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
const chunkStream = (async function* () {
|
|
132
|
+
yield Buffer.from("hello attachment data");
|
|
133
|
+
})();
|
|
134
|
+
mockDownload.mockResolvedValue({ content: chunkStream });
|
|
135
|
+
|
|
136
|
+
const req = {
|
|
137
|
+
body: {
|
|
138
|
+
host: "imap.example.com",
|
|
139
|
+
username: "user@example.com",
|
|
140
|
+
password: "password123",
|
|
141
|
+
messageUid: 101,
|
|
142
|
+
attachmentParts: ["1"],
|
|
143
|
+
},
|
|
144
|
+
};
|
|
145
|
+
const res = createResponse();
|
|
146
|
+
await handler(req, res);
|
|
147
|
+
|
|
148
|
+
expect(mockConnect).toHaveBeenCalled();
|
|
149
|
+
expect(mockMailboxOpen).toHaveBeenCalledWith("INBOX");
|
|
150
|
+
expect(mockDownload).toHaveBeenCalledWith(101, "1", { uid: true });
|
|
151
|
+
expect(mockLogout).toHaveBeenCalled();
|
|
152
|
+
expect(res.body.count).toBe(1);
|
|
153
|
+
expect(res.body.attachments[0].filename).toBe("test.pdf");
|
|
154
|
+
expect(res.body.attachments[0].contentBase64).toBe(
|
|
155
|
+
Buffer.from("hello attachment data").toString("base64"),
|
|
156
|
+
);
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
it("handles OAuth download authentication failure with Gmail custom message", async () => {
|
|
160
|
+
const handler = routes.get(route);
|
|
161
|
+
mockConnect.mockRejectedValue({
|
|
162
|
+
authenticationFailed: true,
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
const req = {
|
|
166
|
+
body: {
|
|
167
|
+
authType: "oauth",
|
|
168
|
+
host: "imap.gmail.com",
|
|
169
|
+
username: "user@gmail.com",
|
|
170
|
+
accessToken: "expired-token",
|
|
171
|
+
messageUid: 5,
|
|
172
|
+
},
|
|
173
|
+
};
|
|
174
|
+
const res = createResponse();
|
|
175
|
+
await handler(req, res);
|
|
176
|
+
|
|
177
|
+
expect(res.status).toHaveBeenCalledWith(401);
|
|
178
|
+
expect(res.body.error).toContain(
|
|
179
|
+
"The Google OAuth token was rejected or expired",
|
|
180
|
+
);
|
|
181
|
+
});
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
describe("POST /integrations/email/modify", () => {
|
|
185
|
+
const route = "POST /integrations/email/modify";
|
|
186
|
+
|
|
187
|
+
it("returns 400 for invalid action", async () => {
|
|
188
|
+
const handler = routes.get(route);
|
|
189
|
+
const res = createResponse();
|
|
190
|
+
await handler({ body: { action: "unsupported" } }, res);
|
|
191
|
+
expect(res.status).toHaveBeenCalledWith(400);
|
|
192
|
+
expect(res.body.error).toContain("Missing or invalid action");
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
it("returns 400 for missing messageUids", async () => {
|
|
196
|
+
const handler = routes.get(route);
|
|
197
|
+
const res = createResponse();
|
|
198
|
+
await handler(
|
|
199
|
+
{
|
|
200
|
+
body: {
|
|
201
|
+
action: "mark_as_read",
|
|
202
|
+
host: "imap.example.com",
|
|
203
|
+
username: "u",
|
|
204
|
+
password: "p",
|
|
205
|
+
messageUids: [],
|
|
206
|
+
},
|
|
207
|
+
},
|
|
208
|
+
res,
|
|
209
|
+
);
|
|
210
|
+
expect(res.status).toHaveBeenCalledWith(400);
|
|
211
|
+
expect(res.body.error).toContain("Missing required field: messageUids");
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
it("executes mark_as_read action", async () => {
|
|
215
|
+
const handler = routes.get(route);
|
|
216
|
+
const req = {
|
|
217
|
+
body: {
|
|
218
|
+
action: "mark_as_read",
|
|
219
|
+
host: "imap.example.com",
|
|
220
|
+
username: "u",
|
|
221
|
+
password: "p",
|
|
222
|
+
messageUids: [10, 20],
|
|
223
|
+
},
|
|
224
|
+
};
|
|
225
|
+
const res = createResponse();
|
|
226
|
+
await handler(req, res);
|
|
227
|
+
|
|
228
|
+
expect(mockConnect).toHaveBeenCalled();
|
|
229
|
+
expect(mockMessageFlagsAdd).toHaveBeenCalledWith([10, 20], ["\\Seen"], {
|
|
230
|
+
uid: true,
|
|
231
|
+
});
|
|
232
|
+
expect(res.body.action).toBe("mark_as_read");
|
|
233
|
+
expect(res.body.count).toBe(2);
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
it("executes mark_as_unread action", async () => {
|
|
237
|
+
const handler = routes.get(route);
|
|
238
|
+
const req = {
|
|
239
|
+
body: {
|
|
240
|
+
action: "mark_as_unread",
|
|
241
|
+
host: "imap.example.com",
|
|
242
|
+
username: "u",
|
|
243
|
+
password: "p",
|
|
244
|
+
messageUids: [15],
|
|
245
|
+
},
|
|
246
|
+
};
|
|
247
|
+
const res = createResponse();
|
|
248
|
+
await handler(req, res);
|
|
249
|
+
|
|
250
|
+
expect(mockMessageFlagsRemove).toHaveBeenCalledWith([15], ["\\Seen"], {
|
|
251
|
+
uid: true,
|
|
252
|
+
});
|
|
253
|
+
expect(res.body.action).toBe("mark_as_unread");
|
|
254
|
+
});
|
|
255
|
+
|
|
256
|
+
it("executes delete_messages action", async () => {
|
|
257
|
+
const handler = routes.get(route);
|
|
258
|
+
const req = {
|
|
259
|
+
body: {
|
|
260
|
+
action: "delete_messages",
|
|
261
|
+
host: "imap.example.com",
|
|
262
|
+
username: "u",
|
|
263
|
+
password: "p",
|
|
264
|
+
messageUids: [99],
|
|
265
|
+
},
|
|
266
|
+
};
|
|
267
|
+
const res = createResponse();
|
|
268
|
+
await handler(req, res);
|
|
269
|
+
|
|
270
|
+
expect(mockMessageDelete).toHaveBeenCalledWith([99], { uid: true });
|
|
271
|
+
expect(res.body.action).toBe("delete_messages");
|
|
272
|
+
});
|
|
273
|
+
|
|
274
|
+
it("handles connection failure with 502 status", async () => {
|
|
275
|
+
const handler = routes.get(route);
|
|
276
|
+
mockConnect.mockRejectedValue(new Error("Connection reset by peer"));
|
|
277
|
+
|
|
278
|
+
const req = {
|
|
279
|
+
body: {
|
|
280
|
+
action: "delete_messages",
|
|
281
|
+
host: "imap.example.com",
|
|
282
|
+
username: "u",
|
|
283
|
+
password: "p",
|
|
284
|
+
messageUids: [99],
|
|
285
|
+
},
|
|
286
|
+
};
|
|
287
|
+
const res = createResponse();
|
|
288
|
+
await handler(req, res);
|
|
289
|
+
|
|
290
|
+
expect(res.status).toHaveBeenCalledWith(502);
|
|
291
|
+
expect(res.body.error).toContain(
|
|
292
|
+
"Failed to modify mailbox messages: Connection reset by peer",
|
|
293
|
+
);
|
|
294
|
+
});
|
|
295
|
+
});
|
|
296
|
+
|
|
297
|
+
describe("POST /integrations/email/read", () => {
|
|
298
|
+
const route = "POST /integrations/email/read";
|
|
299
|
+
|
|
300
|
+
it("returns 400 for missing credentials", async () => {
|
|
301
|
+
const handler = routes.get(route);
|
|
302
|
+
const res = createResponse();
|
|
303
|
+
await handler({ body: {} }, res);
|
|
304
|
+
expect(res.status).toHaveBeenCalledWith(400);
|
|
305
|
+
});
|
|
306
|
+
|
|
307
|
+
it("reads mailbox messages and collects attachments", async () => {
|
|
308
|
+
const handler = routes.get(route);
|
|
309
|
+
mockSearch.mockResolvedValue([101, 102]);
|
|
310
|
+
mockFetchOne.mockImplementation(async (uid: number) => ({
|
|
311
|
+
uid,
|
|
312
|
+
envelope: {
|
|
313
|
+
subject: `Subject for ${uid}`,
|
|
314
|
+
date: new Date(1700000000000),
|
|
315
|
+
from: [{ name: "Sender", address: "sender@example.com" }],
|
|
316
|
+
to: [{ name: "Receiver", address: "receiver@example.com" }],
|
|
317
|
+
},
|
|
318
|
+
flags: new Set(["\\Seen"]),
|
|
319
|
+
bodyStructure: {
|
|
320
|
+
childNodes: [
|
|
321
|
+
{
|
|
322
|
+
part: "1.1",
|
|
323
|
+
disposition: "attachment",
|
|
324
|
+
parameters: { name: "doc.docx" },
|
|
325
|
+
type: "application",
|
|
326
|
+
subtype:
|
|
327
|
+
"vnd.openxmlformats-officedocument.wordprocessingml.document",
|
|
328
|
+
},
|
|
329
|
+
],
|
|
330
|
+
},
|
|
331
|
+
}));
|
|
332
|
+
|
|
333
|
+
const req = {
|
|
334
|
+
body: {
|
|
335
|
+
host: "imap.example.com",
|
|
336
|
+
username: "u",
|
|
337
|
+
password: "p",
|
|
338
|
+
unreadOnly: false,
|
|
339
|
+
limit: 10,
|
|
340
|
+
},
|
|
341
|
+
};
|
|
342
|
+
const res = createResponse();
|
|
343
|
+
await handler(req, res);
|
|
344
|
+
|
|
345
|
+
expect(mockSearch).toHaveBeenCalledWith({ all: true }, { uid: true });
|
|
346
|
+
expect(res.body.count).toBe(2);
|
|
347
|
+
expect(res.body.messages[0].subject).toBe("Subject for 102");
|
|
348
|
+
expect(res.body.messages[0].attachments[0].filename).toBe("doc.docx");
|
|
349
|
+
});
|
|
350
|
+
|
|
351
|
+
it("handles basic auth password failure on gmail", async () => {
|
|
352
|
+
const handler = routes.get(route);
|
|
353
|
+
mockConnect.mockRejectedValue({
|
|
354
|
+
responseText: "Invalid credentials (Failure)",
|
|
355
|
+
});
|
|
356
|
+
|
|
357
|
+
const req = {
|
|
358
|
+
body: {
|
|
359
|
+
host: "imap.gmail.com",
|
|
360
|
+
username: "user@gmail.com",
|
|
361
|
+
password: "myNormalPassword",
|
|
362
|
+
},
|
|
363
|
+
};
|
|
364
|
+
const res = createResponse();
|
|
365
|
+
await handler(req, res);
|
|
366
|
+
|
|
367
|
+
expect(res.status).toHaveBeenCalledWith(401);
|
|
368
|
+
expect(res.body.error).toContain(
|
|
369
|
+
"Gmail rejected the username/password. Use a Google App Password",
|
|
370
|
+
);
|
|
371
|
+
});
|
|
372
|
+
});
|
|
373
|
+
|
|
374
|
+
describe("POST /integrations/email/send", () => {
|
|
375
|
+
const route = "POST /integrations/email/send";
|
|
376
|
+
|
|
377
|
+
it("returns 400 when required fields are missing", async () => {
|
|
378
|
+
const handler = routes.get(route);
|
|
379
|
+
const res1 = createResponse();
|
|
380
|
+
await handler({ body: {} }, res1);
|
|
381
|
+
expect(res1.status).toHaveBeenCalledWith(400);
|
|
382
|
+
|
|
383
|
+
const res2 = createResponse();
|
|
384
|
+
await handler(
|
|
385
|
+
{
|
|
386
|
+
body: { smtpHost: "smtp.example.com", username: "u", password: "p" },
|
|
387
|
+
},
|
|
388
|
+
res2,
|
|
389
|
+
);
|
|
390
|
+
expect(res2.status).toHaveBeenCalledWith(400);
|
|
391
|
+
expect(res2.body.error).toContain("Missing required field: to.");
|
|
392
|
+
|
|
393
|
+
const res3 = createResponse();
|
|
394
|
+
await handler(
|
|
395
|
+
{
|
|
396
|
+
body: {
|
|
397
|
+
smtpHost: "smtp.example.com",
|
|
398
|
+
username: "u",
|
|
399
|
+
password: "p",
|
|
400
|
+
to: ["a@b.com"],
|
|
401
|
+
},
|
|
402
|
+
},
|
|
403
|
+
res3,
|
|
404
|
+
);
|
|
405
|
+
expect(res3.status).toHaveBeenCalledWith(400);
|
|
406
|
+
expect(res3.body.error).toContain("Missing required field: subject.");
|
|
407
|
+
|
|
408
|
+
const res4 = createResponse();
|
|
409
|
+
await handler(
|
|
410
|
+
{
|
|
411
|
+
body: {
|
|
412
|
+
smtpHost: "smtp.example.com",
|
|
413
|
+
username: "u",
|
|
414
|
+
password: "p",
|
|
415
|
+
to: ["a@b.com"],
|
|
416
|
+
subject: "Hello",
|
|
417
|
+
},
|
|
418
|
+
},
|
|
419
|
+
res4,
|
|
420
|
+
);
|
|
421
|
+
expect(res4.status).toHaveBeenCalledWith(400);
|
|
422
|
+
expect(res4.body.error).toContain("Provide text or html content.");
|
|
423
|
+
});
|
|
424
|
+
|
|
425
|
+
it("sends email successfully with basic authentication and attachments", async () => {
|
|
426
|
+
const handler = routes.get(route);
|
|
427
|
+
const req = {
|
|
428
|
+
body: {
|
|
429
|
+
smtpHost: "smtp.example.com",
|
|
430
|
+
smtpPort: 587,
|
|
431
|
+
username: "sender@example.com",
|
|
432
|
+
password: "secretpassword",
|
|
433
|
+
to: ["recipient@example.com"],
|
|
434
|
+
cc: ["cc@example.com"],
|
|
435
|
+
bcc: ["bcc@example.com"],
|
|
436
|
+
subject: "Test Subject",
|
|
437
|
+
text: "Plain text content",
|
|
438
|
+
html: "<p>HTML content</p>",
|
|
439
|
+
attachments: [
|
|
440
|
+
{
|
|
441
|
+
filename: "notes.txt",
|
|
442
|
+
contentType: "text/plain",
|
|
443
|
+
contentBase64: Buffer.from("Hello note").toString("base64"),
|
|
444
|
+
},
|
|
445
|
+
],
|
|
446
|
+
},
|
|
447
|
+
};
|
|
448
|
+
const res = createResponse();
|
|
449
|
+
await handler(req, res);
|
|
450
|
+
|
|
451
|
+
expect(mockCreateTransport).toHaveBeenCalledWith({
|
|
452
|
+
host: "smtp.example.com",
|
|
453
|
+
port: 587,
|
|
454
|
+
secure: false,
|
|
455
|
+
auth: {
|
|
456
|
+
user: "sender@example.com",
|
|
457
|
+
pass: "secretpassword",
|
|
458
|
+
},
|
|
459
|
+
});
|
|
460
|
+
expect(mockSendMail).toHaveBeenCalledWith(
|
|
461
|
+
expect.objectContaining({
|
|
462
|
+
from: "sender@example.com",
|
|
463
|
+
to: ["recipient@example.com"],
|
|
464
|
+
cc: ["cc@example.com"],
|
|
465
|
+
bcc: ["bcc@example.com"],
|
|
466
|
+
subject: "Test Subject",
|
|
467
|
+
text: "Plain text content",
|
|
468
|
+
html: "<p>HTML content</p>",
|
|
469
|
+
attachments: [
|
|
470
|
+
expect.objectContaining({
|
|
471
|
+
filename: "notes.txt",
|
|
472
|
+
contentType: "text/plain",
|
|
473
|
+
content: Buffer.from("Hello note"),
|
|
474
|
+
}),
|
|
475
|
+
],
|
|
476
|
+
}),
|
|
477
|
+
);
|
|
478
|
+
expect(res.body.messageId).toBe("<msg-123@domain.com>");
|
|
479
|
+
});
|
|
480
|
+
|
|
481
|
+
it("sends email with OAuth2 authentication", async () => {
|
|
482
|
+
const handler = routes.get(route);
|
|
483
|
+
const req = {
|
|
484
|
+
body: {
|
|
485
|
+
authType: "oauth",
|
|
486
|
+
smtpHost: "smtp.gmail.com",
|
|
487
|
+
username: "sender@gmail.com",
|
|
488
|
+
accessToken: "oauth-access-token",
|
|
489
|
+
to: ["recipient@example.com"],
|
|
490
|
+
subject: "OAuth Email",
|
|
491
|
+
text: "Hello via OAuth",
|
|
492
|
+
},
|
|
493
|
+
};
|
|
494
|
+
const res = createResponse();
|
|
495
|
+
await handler(req, res);
|
|
496
|
+
|
|
497
|
+
expect(mockCreateTransport).toHaveBeenCalledWith(
|
|
498
|
+
expect.objectContaining({
|
|
499
|
+
auth: {
|
|
500
|
+
type: "OAuth2",
|
|
501
|
+
user: "sender@gmail.com",
|
|
502
|
+
accessToken: "oauth-access-token",
|
|
503
|
+
},
|
|
504
|
+
}),
|
|
505
|
+
);
|
|
506
|
+
expect(res.body.messageId).toBe("<msg-123@domain.com>");
|
|
507
|
+
});
|
|
508
|
+
|
|
509
|
+
it("handles SMTP failure with 502 status", async () => {
|
|
510
|
+
const handler = routes.get(route);
|
|
511
|
+
mockSendMail.mockRejectedValue(new Error("550 Mailbox unavailable"));
|
|
512
|
+
|
|
513
|
+
const req = {
|
|
514
|
+
body: {
|
|
515
|
+
smtpHost: "smtp.example.com",
|
|
516
|
+
username: "sender@example.com",
|
|
517
|
+
password: "secretpassword",
|
|
518
|
+
to: ["bad@example.com"],
|
|
519
|
+
subject: "Test",
|
|
520
|
+
text: "Fail test",
|
|
521
|
+
},
|
|
522
|
+
};
|
|
523
|
+
const res = createResponse();
|
|
524
|
+
await handler(req, res);
|
|
525
|
+
|
|
526
|
+
expect(res.status).toHaveBeenCalledWith(502);
|
|
527
|
+
expect(res.body.error).toContain(
|
|
528
|
+
"Failed to send message: 550 Mailbox unavailable",
|
|
529
|
+
);
|
|
530
|
+
});
|
|
531
|
+
});
|
|
532
|
+
});
|