claude-mux 0.7.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/.beads/README.md +81 -0
- package/.beads/config.yaml +62 -0
- package/.beads/interactions.jsonl +0 -0
- package/.beads/issues.jsonl +5 -0
- package/.beads/metadata.json +4 -0
- package/.eslintrc.json +25 -0
- package/.gitattributes +3 -0
- package/.prettierrc +7 -0
- package/CLAUDE.md +123 -0
- package/LICENSE +21 -0
- package/PLAN-beads-integration.md +250 -0
- package/README.md +366 -0
- package/dist/app.d.ts +2 -0
- package/dist/app.d.ts.map +1 -0
- package/dist/app.js +147 -0
- package/dist/app.js.map +1 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +65 -0
- package/dist/cli.js.map +1 -0
- package/dist/commands/index.d.ts +5 -0
- package/dist/commands/index.d.ts.map +1 -0
- package/dist/commands/index.js +5 -0
- package/dist/commands/index.js.map +1 -0
- package/dist/commands/serve.d.ts +8 -0
- package/dist/commands/serve.d.ts.map +1 -0
- package/dist/commands/serve.js +59 -0
- package/dist/commands/serve.js.map +1 -0
- package/dist/commands/setup.d.ts +4 -0
- package/dist/commands/setup.d.ts.map +1 -0
- package/dist/commands/setup.js +12 -0
- package/dist/commands/setup.js.map +1 -0
- package/dist/commands/tui.d.ts +9 -0
- package/dist/commands/tui.d.ts.map +1 -0
- package/dist/commands/tui.js +234 -0
- package/dist/commands/tui.js.map +1 -0
- package/dist/commands/uninstall.d.ts +4 -0
- package/dist/commands/uninstall.d.ts.map +1 -0
- package/dist/commands/uninstall.js +12 -0
- package/dist/commands/uninstall.js.map +1 -0
- package/dist/components/Header.d.ts +7 -0
- package/dist/components/Header.d.ts.map +1 -0
- package/dist/components/Header.js +14 -0
- package/dist/components/Header.js.map +1 -0
- package/dist/components/HelpDialog.d.ts +6 -0
- package/dist/components/HelpDialog.d.ts.map +1 -0
- package/dist/components/HelpDialog.js +14 -0
- package/dist/components/HelpDialog.js.map +1 -0
- package/dist/components/SessionEntry.d.ts +17 -0
- package/dist/components/SessionEntry.d.ts.map +1 -0
- package/dist/components/SessionEntry.js +102 -0
- package/dist/components/SessionEntry.js.map +1 -0
- package/dist/components/SessionList.d.ts +14 -0
- package/dist/components/SessionList.d.ts.map +1 -0
- package/dist/components/SessionList.js +57 -0
- package/dist/components/SessionList.js.map +1 -0
- package/dist/components/StatusBar.d.ts +6 -0
- package/dist/components/StatusBar.d.ts.map +1 -0
- package/dist/components/StatusBar.js +7 -0
- package/dist/components/StatusBar.js.map +1 -0
- package/dist/components/index.d.ts +6 -0
- package/dist/components/index.d.ts.map +1 -0
- package/dist/components/index.js +6 -0
- package/dist/components/index.js.map +1 -0
- package/dist/db/index.d.ts +2 -0
- package/dist/db/index.d.ts.map +1 -0
- package/dist/db/index.js +3 -0
- package/dist/db/index.js.map +1 -0
- package/dist/db/schema.d.ts +4 -0
- package/dist/db/schema.d.ts.map +1 -0
- package/dist/db/schema.js +23 -0
- package/dist/db/schema.js.map +1 -0
- package/dist/db/sessions-json.d.ts +85 -0
- package/dist/db/sessions-json.d.ts.map +1 -0
- package/dist/db/sessions-json.js +242 -0
- package/dist/db/sessions-json.js.map +1 -0
- package/dist/db/sessions.d.ts +38 -0
- package/dist/db/sessions.d.ts.map +1 -0
- package/dist/db/sessions.js +87 -0
- package/dist/db/sessions.js.map +1 -0
- package/dist/hooks/claude-mux-hook.d.ts +15 -0
- package/dist/hooks/claude-mux-hook.d.ts.map +1 -0
- package/dist/hooks/claude-mux-hook.js +396 -0
- package/dist/hooks/claude-mux-hook.js.map +1 -0
- package/dist/hooks/claude-watch-hook.d.ts +15 -0
- package/dist/hooks/claude-watch-hook.d.ts.map +1 -0
- package/dist/hooks/claude-watch-hook.js +396 -0
- package/dist/hooks/claude-watch-hook.js.map +1 -0
- package/dist/server/custom-server.d.ts +13 -0
- package/dist/server/custom-server.d.ts.map +1 -0
- package/dist/server/custom-server.js +63 -0
- package/dist/server/custom-server.js.map +1 -0
- package/dist/server/index.d.ts +9 -0
- package/dist/server/index.d.ts.map +1 -0
- package/dist/server/index.js +1143 -0
- package/dist/server/index.js.map +1 -0
- package/dist/server/middleware/cors.d.ts +2 -0
- package/dist/server/middleware/cors.d.ts.map +1 -0
- package/dist/server/middleware/cors.js +11 -0
- package/dist/server/middleware/cors.js.map +1 -0
- package/dist/server/routes/sessions.d.ts +3 -0
- package/dist/server/routes/sessions.d.ts.map +1 -0
- package/dist/server/routes/sessions.js +78 -0
- package/dist/server/routes/sessions.js.map +1 -0
- package/dist/server/routes/stream.d.ts +3 -0
- package/dist/server/routes/stream.d.ts.map +1 -0
- package/dist/server/routes/stream.js +45 -0
- package/dist/server/routes/stream.js.map +1 -0
- package/dist/server/types.d.ts +28 -0
- package/dist/server/types.d.ts.map +1 -0
- package/dist/server/types.js +2 -0
- package/dist/server/types.js.map +1 -0
- package/dist/server/watcher.d.ts +22 -0
- package/dist/server/watcher.d.ts.map +1 -0
- package/dist/server/watcher.js +119 -0
- package/dist/server/watcher.js.map +1 -0
- package/dist/server/websocket.d.ts +51 -0
- package/dist/server/websocket.d.ts.map +1 -0
- package/dist/server/websocket.js +156 -0
- package/dist/server/websocket.js.map +1 -0
- package/dist/server/ws-handlers.d.ts +174 -0
- package/dist/server/ws-handlers.d.ts.map +1 -0
- package/dist/server/ws-handlers.js +695 -0
- package/dist/server/ws-handlers.js.map +1 -0
- package/dist/setup/hooks.d.ts +44 -0
- package/dist/setup/hooks.d.ts.map +1 -0
- package/dist/setup/hooks.js +267 -0
- package/dist/setup/hooks.js.map +1 -0
- package/dist/setup/index.d.ts +3 -0
- package/dist/setup/index.d.ts.map +1 -0
- package/dist/setup/index.js +3 -0
- package/dist/setup/index.js.map +1 -0
- package/dist/setup/wizard.d.ts +4 -0
- package/dist/setup/wizard.d.ts.map +1 -0
- package/dist/setup/wizard.js +72 -0
- package/dist/setup/wizard.js.map +1 -0
- package/dist/tmux/detect.d.ts +25 -0
- package/dist/tmux/detect.d.ts.map +1 -0
- package/dist/tmux/detect.js +71 -0
- package/dist/tmux/detect.js.map +1 -0
- package/dist/tmux/navigate.d.ts +13 -0
- package/dist/tmux/navigate.d.ts.map +1 -0
- package/dist/tmux/navigate.js +41 -0
- package/dist/tmux/navigate.js.map +1 -0
- package/dist/tmux/pane.d.ts +57 -0
- package/dist/tmux/pane.d.ts.map +1 -0
- package/dist/tmux/pane.js +156 -0
- package/dist/tmux/pane.js.map +1 -0
- package/dist/tmux/resize.d.ts +10 -0
- package/dist/tmux/resize.d.ts.map +1 -0
- package/dist/tmux/resize.js +25 -0
- package/dist/tmux/resize.js.map +1 -0
- package/dist/utils/paths.d.ts +7 -0
- package/dist/utils/paths.d.ts.map +1 -0
- package/dist/utils/paths.js +9 -0
- package/dist/utils/paths.js.map +1 -0
- package/dist/utils/pid.d.ts +5 -0
- package/dist/utils/pid.d.ts.map +1 -0
- package/dist/utils/pid.js +14 -0
- package/dist/utils/pid.js.map +1 -0
- package/dist/utils/version.d.ts +6 -0
- package/dist/utils/version.d.ts.map +1 -0
- package/dist/utils/version.js +6 -0
- package/dist/utils/version.js.map +1 -0
- package/dist/web/client/_app/immutable/assets/0.WptSHSUl.css +1 -0
- package/dist/web/client/_app/immutable/assets/2.s6Kx4oz1.css +1 -0
- package/dist/web/client/_app/immutable/assets/4.DoNWy7tW.css +1 -0
- package/dist/web/client/_app/immutable/assets/AllSessionsPanel.CGHY3HLy.css +1 -0
- package/dist/web/client/_app/immutable/chunks/-3mUPuLP.js +1 -0
- package/dist/web/client/_app/immutable/chunks/B5U4_V3d.js +1 -0
- package/dist/web/client/_app/immutable/chunks/BHwiZXRv.js +1 -0
- package/dist/web/client/_app/immutable/chunks/C9P-coqM.js +1 -0
- package/dist/web/client/_app/immutable/chunks/Cegv0r8x.js +1 -0
- package/dist/web/client/_app/immutable/chunks/DU91Ml7U.js +3 -0
- package/dist/web/client/_app/immutable/chunks/DmdO6ygw.js +1 -0
- package/dist/web/client/_app/immutable/chunks/HKNo9LID.js +5 -0
- package/dist/web/client/_app/immutable/chunks/U4ip-C0d.js +2 -0
- package/dist/web/client/_app/immutable/chunks/cgUjKIhX.js +2 -0
- package/dist/web/client/_app/immutable/entry/app.CGIBnoln.js +2 -0
- package/dist/web/client/_app/immutable/entry/start.CJk8zB1j.js +1 -0
- package/dist/web/client/_app/immutable/nodes/0.CqlJ9a31.js +1 -0
- package/dist/web/client/_app/immutable/nodes/1.BQUZh2-w.js +1 -0
- package/dist/web/client/_app/immutable/nodes/2.CCV1YdgF.js +1 -0
- package/dist/web/client/_app/immutable/nodes/3.D9tDCdq8.js +1 -0
- package/dist/web/client/_app/immutable/nodes/4.BqPyNkFA.js +6 -0
- package/dist/web/client/_app/version.json +1 -0
- package/dist/web/client/robots.txt +3 -0
- package/dist/web/env.js +32 -0
- package/dist/web/handler.js +744 -0
- package/dist/web/index.js +49 -0
- package/dist/web/server/chunks/0-BHWsmCJv.js +23 -0
- package/dist/web/server/chunks/0-BHWsmCJv.js.map +1 -0
- package/dist/web/server/chunks/1-YRx6A8Tm.js +17 -0
- package/dist/web/server/chunks/1-YRx6A8Tm.js.map +1 -0
- package/dist/web/server/chunks/2-eC6JuGAo.js +22 -0
- package/dist/web/server/chunks/2-eC6JuGAo.js.map +1 -0
- package/dist/web/server/chunks/3-Bk-wV20p.js +32 -0
- package/dist/web/server/chunks/3-Bk-wV20p.js.map +1 -0
- package/dist/web/server/chunks/4-nteBgDrW.js +21 -0
- package/dist/web/server/chunks/4-nteBgDrW.js.map +1 -0
- package/dist/web/server/chunks/AllSessionsPanel.svelte_svelte_type_style_lang-Bt4B0-oi.js +35 -0
- package/dist/web/server/chunks/AllSessionsPanel.svelte_svelte_type_style_lang-Bt4B0-oi.js.map +1 -0
- package/dist/web/server/chunks/_layout.svelte-BIF9eZCY.js +453 -0
- package/dist/web/server/chunks/_layout.svelte-BIF9eZCY.js.map +1 -0
- package/dist/web/server/chunks/_page.svelte-Be6iabRn.js +34 -0
- package/dist/web/server/chunks/_page.svelte-Be6iabRn.js.map +1 -0
- package/dist/web/server/chunks/_page.svelte-C_fGJVSE.js +576 -0
- package/dist/web/server/chunks/_page.svelte-C_fGJVSE.js.map +1 -0
- package/dist/web/server/chunks/_page.svelte-CnfJk6cu.js +2722 -0
- package/dist/web/server/chunks/_page.svelte-CnfJk6cu.js.map +1 -0
- package/dist/web/server/chunks/_server.ts-3WAmKvn2.js +34 -0
- package/dist/web/server/chunks/_server.ts-3WAmKvn2.js.map +1 -0
- package/dist/web/server/chunks/_server.ts-BAWJCSFb.js +29 -0
- package/dist/web/server/chunks/_server.ts-BAWJCSFb.js.map +1 -0
- package/dist/web/server/chunks/_server.ts-BPpMOZCm.js +24 -0
- package/dist/web/server/chunks/_server.ts-BPpMOZCm.js.map +1 -0
- package/dist/web/server/chunks/_server.ts-BUKgRb6U.js +13 -0
- package/dist/web/server/chunks/_server.ts-BUKgRb6U.js.map +1 -0
- package/dist/web/server/chunks/_server.ts-BVHUS8fm.js +41 -0
- package/dist/web/server/chunks/_server.ts-BVHUS8fm.js.map +1 -0
- package/dist/web/server/chunks/_server.ts-BrF3od0O.js +45 -0
- package/dist/web/server/chunks/_server.ts-BrF3od0O.js.map +1 -0
- package/dist/web/server/chunks/_server.ts-C4oPmOJR.js +38 -0
- package/dist/web/server/chunks/_server.ts-C4oPmOJR.js.map +1 -0
- package/dist/web/server/chunks/_server.ts-CDAUUmG_.js +21 -0
- package/dist/web/server/chunks/_server.ts-CDAUUmG_.js.map +1 -0
- package/dist/web/server/chunks/_server.ts-CR0uWvpz.js +24 -0
- package/dist/web/server/chunks/_server.ts-CR0uWvpz.js.map +1 -0
- package/dist/web/server/chunks/_server.ts-CSqdCNGi.js +21 -0
- package/dist/web/server/chunks/_server.ts-CSqdCNGi.js.map +1 -0
- package/dist/web/server/chunks/_server.ts-DI9fzUo9.js +52 -0
- package/dist/web/server/chunks/_server.ts-DI9fzUo9.js.map +1 -0
- package/dist/web/server/chunks/_server.ts-DNjJTClI.js +46 -0
- package/dist/web/server/chunks/_server.ts-DNjJTClI.js.map +1 -0
- package/dist/web/server/chunks/_server.ts-DdbOAkOj.js +22 -0
- package/dist/web/server/chunks/_server.ts-DdbOAkOj.js.map +1 -0
- package/dist/web/server/chunks/_server.ts-Df2isGQc.js +41 -0
- package/dist/web/server/chunks/_server.ts-Df2isGQc.js.map +1 -0
- package/dist/web/server/chunks/_server.ts-Vpw25_-3.js +12 -0
- package/dist/web/server/chunks/_server.ts-Vpw25_-3.js.map +1 -0
- package/dist/web/server/chunks/_server.ts-WldRpSRi.js +26 -0
- package/dist/web/server/chunks/_server.ts-WldRpSRi.js.map +1 -0
- package/dist/web/server/chunks/alert-dialog-description-DDA6u-nS.js +2890 -0
- package/dist/web/server/chunks/alert-dialog-description-DDA6u-nS.js.map +1 -0
- package/dist/web/server/chunks/auth-DrUf-v4J.js +51 -0
- package/dist/web/server/chunks/auth-DrUf-v4J.js.map +1 -0
- package/dist/web/server/chunks/button-D6xS9rHt.js +2335 -0
- package/dist/web/server/chunks/button-D6xS9rHt.js.map +1 -0
- package/dist/web/server/chunks/chunk-EKzHsMy_.js +42 -0
- package/dist/web/server/chunks/chunks-DmdqVYC7.js +58 -0
- package/dist/web/server/chunks/chunks-DmdqVYC7.js.map +1 -0
- package/dist/web/server/chunks/client-CUrSQijh.js +18 -0
- package/dist/web/server/chunks/client-CUrSQijh.js.map +1 -0
- package/dist/web/server/chunks/clsx-FzI4_gi0.js +332 -0
- package/dist/web/server/chunks/clsx-FzI4_gi0.js.map +1 -0
- package/dist/web/server/chunks/error.svelte-D-c-9pTE.js +27 -0
- package/dist/web/server/chunks/error.svelte-D-c-9pTE.js.map +1 -0
- package/dist/web/server/chunks/events-BDBlYddw.js +89 -0
- package/dist/web/server/chunks/events-BDBlYddw.js.map +1 -0
- package/dist/web/server/chunks/exports-CCurQ-Tl.js +131 -0
- package/dist/web/server/chunks/exports-CCurQ-Tl.js.map +1 -0
- package/dist/web/server/chunks/hooks.server-BK1bopsh.js +86 -0
- package/dist/web/server/chunks/hooks.server-BK1bopsh.js.map +1 -0
- package/dist/web/server/chunks/index2-BQnysSj-.js +2588 -0
- package/dist/web/server/chunks/index2-BQnysSj-.js.map +1 -0
- package/dist/web/server/chunks/internal-DLENj6YI.js +61 -0
- package/dist/web/server/chunks/internal-DLENj6YI.js.map +1 -0
- package/dist/web/server/chunks/pane-Dg3pKvsm.js +94 -0
- package/dist/web/server/chunks/pane-Dg3pKvsm.js.map +1 -0
- package/dist/web/server/chunks/sessions-json-DgfkCLO7.js +107 -0
- package/dist/web/server/chunks/sessions-json-DgfkCLO7.js.map +1 -0
- package/dist/web/server/chunks/sessions.svelte-Ds82MvkB.js +178 -0
- package/dist/web/server/chunks/sessions.svelte-Ds82MvkB.js.map +1 -0
- package/dist/web/server/chunks/state.svelte-xeAZvWZ6.js +7 -0
- package/dist/web/server/chunks/state.svelte-xeAZvWZ6.js.map +1 -0
- package/dist/web/server/chunks/ws-handlers-B4r5eSP2.js +733 -0
- package/dist/web/server/chunks/ws-handlers-B4r5eSP2.js.map +1 -0
- package/dist/web/server/index.js +4907 -0
- package/dist/web/server/index.js.map +1 -0
- package/dist/web/server/manifest.js +233 -0
- package/dist/web/server/manifest.js.map +1 -0
- package/docs/images/desktop-dashboard.png +0 -0
- package/docs/images/desktop-session.png +0 -0
- package/docs/images/mobile-dashboard.png +0 -0
- package/docs/images/mobile-session.png +0 -0
- package/docs/release-checklist.md +228 -0
- package/docs/removing-hooks.md +135 -0
- package/docs/state-transitions.md +109 -0
- package/package.json +71 -0
- package/src/app.tsx +188 -0
- package/src/cli.ts +83 -0
- package/src/commands/index.ts +4 -0
- package/src/commands/serve.ts +75 -0
- package/src/commands/setup.ts +13 -0
- package/src/commands/tui.ts +255 -0
- package/src/commands/uninstall.ts +13 -0
- package/src/components/Header.tsx +32 -0
- package/src/components/HelpDialog.tsx +45 -0
- package/src/components/SessionEntry.tsx +202 -0
- package/src/components/SessionList.tsx +98 -0
- package/src/components/StatusBar.tsx +26 -0
- package/src/components/index.ts +5 -0
- package/src/db/index.ts +20 -0
- package/src/db/sessions-json.ts +314 -0
- package/src/hooks/claude-mux-hook.ts +498 -0
- package/src/server/watcher.ts +128 -0
- package/src/server/ws-handlers.ts +922 -0
- package/src/setup/hooks.ts +333 -0
- package/src/setup/index.ts +2 -0
- package/src/setup/wizard.ts +81 -0
- package/src/tmux/detect.ts +87 -0
- package/src/tmux/navigate.ts +42 -0
- package/src/tmux/pane.ts +167 -0
- package/src/tmux/resize.ts +28 -0
- package/src/utils/paths.ts +11 -0
- package/src/utils/pid.ts +12 -0
- package/src/utils/version.ts +5 -0
- package/tests/components/Header.test.tsx +42 -0
- package/tests/components/SessionEntry-extended.test.tsx +165 -0
- package/tests/components/SessionEntry.test.tsx +138 -0
- package/tests/components/SessionList.test.tsx +110 -0
- package/tests/components/StatusBar.test.tsx +31 -0
- package/tests/db/index.test.ts +78 -0
- package/tests/db/sessions.test.ts +230 -0
- package/tests/server/integration.test.ts +319 -0
- package/tests/server/sessions.test.ts +114 -0
- package/tests/setup/hooks-integration.test.ts +148 -0
- package/tests/setup/hooks.test.ts +123 -0
- package/tests/tmux/detect.test.ts +54 -0
- package/tests/tmux/navigate.test.ts +30 -0
- package/tests/utils/pid.test.ts +17 -0
- package/tsconfig.cli.json +9 -0
- package/tsconfig.json +22 -0
- package/vitest.config.ts +29 -0
- package/web/.svelte-kit/adapter-bun/.vite/manifest.json +408 -0
- package/web/.svelte-kit/adapter-bun/_app/immutable/assets/AllSessionsPanel.BKhqOrbV.css +1 -0
- package/web/.svelte-kit/adapter-bun/_app/immutable/assets/_layout.WptSHSUl.css +1 -0
- package/web/.svelte-kit/adapter-bun/_app/immutable/assets/_page.DldLgTc-.css +1 -0
- package/web/.svelte-kit/adapter-bun/_app/immutable/assets/_page.DoNWy7tW.css +1 -0
- package/web/.svelte-kit/adapter-bun/chunks/AllSessionsPanel.svelte_svelte_type_style_lang.js +49 -0
- package/web/.svelte-kit/adapter-bun/chunks/alert-dialog-description.js +2670 -0
- package/web/.svelte-kit/adapter-bun/chunks/auth.js +59 -0
- package/web/.svelte-kit/adapter-bun/chunks/button.js +82 -0
- package/web/.svelte-kit/adapter-bun/chunks/client.js +29 -0
- package/web/.svelte-kit/adapter-bun/chunks/context.js +133 -0
- package/web/.svelte-kit/adapter-bun/chunks/environment.js +34 -0
- package/web/.svelte-kit/adapter-bun/chunks/events.js +121 -0
- package/web/.svelte-kit/adapter-bun/chunks/exports.js +174 -0
- package/web/.svelte-kit/adapter-bun/chunks/false.js +4 -0
- package/web/.svelte-kit/adapter-bun/chunks/index.js +59 -0
- package/web/.svelte-kit/adapter-bun/chunks/index2.js +2828 -0
- package/web/.svelte-kit/adapter-bun/chunks/internal.js +920 -0
- package/web/.svelte-kit/adapter-bun/chunks/pane.js +82 -0
- package/web/.svelte-kit/adapter-bun/chunks/sessions-json.js +124 -0
- package/web/.svelte-kit/adapter-bun/chunks/sessions.svelte.js +229 -0
- package/web/.svelte-kit/adapter-bun/chunks/shared.js +542 -0
- package/web/.svelte-kit/adapter-bun/chunks/state.svelte.js +16 -0
- package/web/.svelte-kit/adapter-bun/chunks/utils.js +43 -0
- package/web/.svelte-kit/adapter-bun/chunks/ws-handlers.js +782 -0
- package/web/.svelte-kit/adapter-bun/entries/endpoints/api/auth/login/_server.ts.js +22 -0
- package/web/.svelte-kit/adapter-bun/entries/endpoints/api/auth/logout/_server.ts.js +9 -0
- package/web/.svelte-kit/adapter-bun/entries/endpoints/api/beads/_server.ts.js +22 -0
- package/web/.svelte-kit/adapter-bun/entries/endpoints/api/browse/_server.ts.js +50 -0
- package/web/.svelte-kit/adapter-bun/entries/endpoints/api/chrome/_server.ts.js +30 -0
- package/web/.svelte-kit/adapter-bun/entries/endpoints/api/files/image/_server.ts.js +53 -0
- package/web/.svelte-kit/adapter-bun/entries/endpoints/api/health/_server.ts.js +7 -0
- package/web/.svelte-kit/adapter-bun/entries/endpoints/api/projects/new-session/_server.ts.js +44 -0
- package/web/.svelte-kit/adapter-bun/entries/endpoints/api/sessions/_id_/_server.ts.js +20 -0
- package/web/.svelte-kit/adapter-bun/entries/endpoints/api/sessions/_id_/kill/_server.ts.js +36 -0
- package/web/.svelte-kit/adapter-bun/entries/endpoints/api/sessions/_id_/restart/_server.ts.js +40 -0
- package/web/.svelte-kit/adapter-bun/entries/endpoints/api/sessions/_id_/screenshots/_server.ts.js +28 -0
- package/web/.svelte-kit/adapter-bun/entries/endpoints/api/sessions/_id_/send/_server.ts.js +29 -0
- package/web/.svelte-kit/adapter-bun/entries/endpoints/api/sessions/_server.ts.js +49 -0
- package/web/.svelte-kit/adapter-bun/entries/endpoints/api/sessions/_target_/output/_server.ts.js +14 -0
- package/web/.svelte-kit/adapter-bun/entries/endpoints/api/tmux/panes/_server.ts.js +21 -0
- package/web/.svelte-kit/adapter-bun/entries/fallbacks/error.svelte.js +27 -0
- package/web/.svelte-kit/adapter-bun/entries/hooks.server.js +105 -0
- package/web/.svelte-kit/adapter-bun/entries/pages/_layout.svelte.js +499 -0
- package/web/.svelte-kit/adapter-bun/entries/pages/_page.svelte.js +3057 -0
- package/web/.svelte-kit/adapter-bun/entries/pages/login/_page.server.ts.js +15 -0
- package/web/.svelte-kit/adapter-bun/entries/pages/login/_page.svelte.js +37 -0
- package/web/.svelte-kit/adapter-bun/entries/pages/session/_target_/_page.svelte.js +653 -0
- package/web/.svelte-kit/adapter-bun/index.js +3864 -0
- package/web/.svelte-kit/adapter-bun/internal.js +13 -0
- package/web/.svelte-kit/adapter-bun/manifest-full.js +167 -0
- package/web/.svelte-kit/adapter-bun/manifest.js +171 -0
- package/web/.svelte-kit/adapter-bun/nodes/0.js +8 -0
- package/web/.svelte-kit/adapter-bun/nodes/1.js +8 -0
- package/web/.svelte-kit/adapter-bun/nodes/2.js +8 -0
- package/web/.svelte-kit/adapter-bun/nodes/3.js +10 -0
- package/web/.svelte-kit/adapter-bun/nodes/4.js +8 -0
- package/web/.svelte-kit/adapter-bun/remote-entry.js +541 -0
- package/web/.svelte-kit/adapter-node/.vite/manifest.json +223 -0
- package/web/.svelte-kit/adapter-node/_app/immutable/assets/_layout.4NiX29PU.css +1 -0
- package/web/.svelte-kit/adapter-node/_app/immutable/assets/_page.BEMzYUGV.css +1 -0
- package/web/.svelte-kit/adapter-node/_app/immutable/assets/_page.DOJn7TG7.css +1 -0
- package/web/.svelte-kit/adapter-node/chunks/context.js +121 -0
- package/web/.svelte-kit/adapter-node/chunks/environment.js +34 -0
- package/web/.svelte-kit/adapter-node/chunks/exports.js +174 -0
- package/web/.svelte-kit/adapter-node/chunks/false.js +4 -0
- package/web/.svelte-kit/adapter-node/chunks/index.js +59 -0
- package/web/.svelte-kit/adapter-node/chunks/index2.js +2710 -0
- package/web/.svelte-kit/adapter-node/chunks/internal.js +1005 -0
- package/web/.svelte-kit/adapter-node/chunks/sessions-json.js +109 -0
- package/web/.svelte-kit/adapter-node/chunks/sessions.svelte.js +67 -0
- package/web/.svelte-kit/adapter-node/chunks/shared.js +542 -0
- package/web/.svelte-kit/adapter-node/chunks/state.svelte.js +16 -0
- package/web/.svelte-kit/adapter-node/chunks/utils.js +43 -0
- package/web/.svelte-kit/adapter-node/entries/endpoints/api/browse/_server.ts.js +50 -0
- package/web/.svelte-kit/adapter-node/entries/endpoints/api/health/_server.ts.js +7 -0
- package/web/.svelte-kit/adapter-node/entries/endpoints/api/projects/new-session/_server.ts.js +44 -0
- package/web/.svelte-kit/adapter-node/entries/endpoints/api/sessions/_id_/_server.ts.js +20 -0
- package/web/.svelte-kit/adapter-node/entries/endpoints/api/sessions/_id_/kill/_server.ts.js +30 -0
- package/web/.svelte-kit/adapter-node/entries/endpoints/api/sessions/_id_/send/_server.ts.js +22 -0
- package/web/.svelte-kit/adapter-node/entries/endpoints/api/sessions/_server.ts.js +126 -0
- package/web/.svelte-kit/adapter-node/entries/endpoints/api/sessions/_target_/output/_server.ts.js +14 -0
- package/web/.svelte-kit/adapter-node/entries/fallbacks/error.svelte.js +44 -0
- package/web/.svelte-kit/adapter-node/entries/pages/_layout.svelte.js +12 -0
- package/web/.svelte-kit/adapter-node/entries/pages/_page.svelte.js +87 -0
- package/web/.svelte-kit/adapter-node/entries/pages/session/_target_/_page.svelte.js +76 -0
- package/web/.svelte-kit/adapter-node/index.js +3864 -0
- package/web/.svelte-kit/adapter-node/internal.js +13 -0
- package/web/.svelte-kit/adapter-node/manifest-full.js +103 -0
- package/web/.svelte-kit/adapter-node/manifest.js +107 -0
- package/web/.svelte-kit/adapter-node/nodes/0.js +8 -0
- package/web/.svelte-kit/adapter-node/nodes/1.js +8 -0
- package/web/.svelte-kit/adapter-node/nodes/2.js +8 -0
- package/web/.svelte-kit/adapter-node/nodes/3.js +8 -0
- package/web/.svelte-kit/adapter-node/remote-entry.js +541 -0
- package/web/.svelte-kit/ambient.d.ts +187 -0
- package/web/.svelte-kit/generated/client/app.js +33 -0
- package/web/.svelte-kit/generated/client/matchers.js +1 -0
- package/web/.svelte-kit/generated/client/nodes/0.js +1 -0
- package/web/.svelte-kit/generated/client/nodes/1.js +1 -0
- package/web/.svelte-kit/generated/client/nodes/2.js +1 -0
- package/web/.svelte-kit/generated/client/nodes/3.js +1 -0
- package/web/.svelte-kit/generated/client/nodes/4.js +1 -0
- package/web/.svelte-kit/generated/client-optimized/app.js +33 -0
- package/web/.svelte-kit/generated/client-optimized/matchers.js +1 -0
- package/web/.svelte-kit/generated/client-optimized/nodes/0.js +1 -0
- package/web/.svelte-kit/generated/client-optimized/nodes/1.js +1 -0
- package/web/.svelte-kit/generated/client-optimized/nodes/2.js +1 -0
- package/web/.svelte-kit/generated/client-optimized/nodes/3.js +1 -0
- package/web/.svelte-kit/generated/client-optimized/nodes/4.js +1 -0
- package/web/.svelte-kit/generated/root.js +3 -0
- package/web/.svelte-kit/generated/root.svelte +68 -0
- package/web/.svelte-kit/generated/server/internal.js +53 -0
- package/web/.svelte-kit/non-ambient.d.ts +73 -0
- package/web/.svelte-kit/output/client/.vite/manifest.json +203 -0
- package/web/.svelte-kit/output/client/_app/immutable/assets/0.WptSHSUl.css +1 -0
- package/web/.svelte-kit/output/client/_app/immutable/assets/2.s6Kx4oz1.css +1 -0
- package/web/.svelte-kit/output/client/_app/immutable/assets/4.DoNWy7tW.css +1 -0
- package/web/.svelte-kit/output/client/_app/immutable/assets/AllSessionsPanel.CGHY3HLy.css +1 -0
- package/web/.svelte-kit/output/client/_app/immutable/chunks/-3mUPuLP.js +1 -0
- package/web/.svelte-kit/output/client/_app/immutable/chunks/B5U4_V3d.js +1 -0
- package/web/.svelte-kit/output/client/_app/immutable/chunks/BHwiZXRv.js +1 -0
- package/web/.svelte-kit/output/client/_app/immutable/chunks/C9P-coqM.js +1 -0
- package/web/.svelte-kit/output/client/_app/immutable/chunks/Cegv0r8x.js +1 -0
- package/web/.svelte-kit/output/client/_app/immutable/chunks/DU91Ml7U.js +3 -0
- package/web/.svelte-kit/output/client/_app/immutable/chunks/DmdO6ygw.js +1 -0
- package/web/.svelte-kit/output/client/_app/immutable/chunks/HKNo9LID.js +5 -0
- package/web/.svelte-kit/output/client/_app/immutable/chunks/U4ip-C0d.js +2 -0
- package/web/.svelte-kit/output/client/_app/immutable/chunks/cgUjKIhX.js +2 -0
- package/web/.svelte-kit/output/client/_app/immutable/entry/app.CGIBnoln.js +2 -0
- package/web/.svelte-kit/output/client/_app/immutable/entry/start.CJk8zB1j.js +1 -0
- package/web/.svelte-kit/output/client/_app/immutable/nodes/0.CqlJ9a31.js +1 -0
- package/web/.svelte-kit/output/client/_app/immutable/nodes/1.BQUZh2-w.js +1 -0
- package/web/.svelte-kit/output/client/_app/immutable/nodes/2.CCV1YdgF.js +1 -0
- package/web/.svelte-kit/output/client/_app/immutable/nodes/3.D9tDCdq8.js +1 -0
- package/web/.svelte-kit/output/client/_app/immutable/nodes/4.BqPyNkFA.js +6 -0
- package/web/.svelte-kit/output/client/_app/version.json +1 -0
- package/web/.svelte-kit/output/client/robots.txt +3 -0
- package/web/.svelte-kit/output/server/.vite/manifest.json +408 -0
- package/web/.svelte-kit/output/server/_app/immutable/assets/AllSessionsPanel.BKhqOrbV.css +1 -0
- package/web/.svelte-kit/output/server/_app/immutable/assets/_layout.WptSHSUl.css +1 -0
- package/web/.svelte-kit/output/server/_app/immutable/assets/_page.DldLgTc-.css +1 -0
- package/web/.svelte-kit/output/server/_app/immutable/assets/_page.DoNWy7tW.css +1 -0
- package/web/.svelte-kit/output/server/chunks/AllSessionsPanel.svelte_svelte_type_style_lang.js +49 -0
- package/web/.svelte-kit/output/server/chunks/alert-dialog-description.js +2670 -0
- package/web/.svelte-kit/output/server/chunks/auth.js +59 -0
- package/web/.svelte-kit/output/server/chunks/button.js +82 -0
- package/web/.svelte-kit/output/server/chunks/client.js +29 -0
- package/web/.svelte-kit/output/server/chunks/context.js +133 -0
- package/web/.svelte-kit/output/server/chunks/environment.js +34 -0
- package/web/.svelte-kit/output/server/chunks/events.js +121 -0
- package/web/.svelte-kit/output/server/chunks/exports.js +174 -0
- package/web/.svelte-kit/output/server/chunks/false.js +4 -0
- package/web/.svelte-kit/output/server/chunks/index.js +59 -0
- package/web/.svelte-kit/output/server/chunks/index2.js +2828 -0
- package/web/.svelte-kit/output/server/chunks/internal.js +920 -0
- package/web/.svelte-kit/output/server/chunks/pane.js +82 -0
- package/web/.svelte-kit/output/server/chunks/sessions-json.js +124 -0
- package/web/.svelte-kit/output/server/chunks/sessions.svelte.js +229 -0
- package/web/.svelte-kit/output/server/chunks/shared.js +542 -0
- package/web/.svelte-kit/output/server/chunks/state.svelte.js +16 -0
- package/web/.svelte-kit/output/server/chunks/utils.js +43 -0
- package/web/.svelte-kit/output/server/chunks/ws-handlers.js +782 -0
- package/web/.svelte-kit/output/server/entries/endpoints/api/auth/login/_server.ts.js +22 -0
- package/web/.svelte-kit/output/server/entries/endpoints/api/auth/logout/_server.ts.js +9 -0
- package/web/.svelte-kit/output/server/entries/endpoints/api/beads/_server.ts.js +22 -0
- package/web/.svelte-kit/output/server/entries/endpoints/api/browse/_server.ts.js +50 -0
- package/web/.svelte-kit/output/server/entries/endpoints/api/chrome/_server.ts.js +30 -0
- package/web/.svelte-kit/output/server/entries/endpoints/api/files/image/_server.ts.js +53 -0
- package/web/.svelte-kit/output/server/entries/endpoints/api/health/_server.ts.js +7 -0
- package/web/.svelte-kit/output/server/entries/endpoints/api/projects/new-session/_server.ts.js +44 -0
- package/web/.svelte-kit/output/server/entries/endpoints/api/sessions/_id_/_server.ts.js +20 -0
- package/web/.svelte-kit/output/server/entries/endpoints/api/sessions/_id_/kill/_server.ts.js +36 -0
- package/web/.svelte-kit/output/server/entries/endpoints/api/sessions/_id_/restart/_server.ts.js +40 -0
- package/web/.svelte-kit/output/server/entries/endpoints/api/sessions/_id_/screenshots/_server.ts.js +28 -0
- package/web/.svelte-kit/output/server/entries/endpoints/api/sessions/_id_/send/_server.ts.js +29 -0
- package/web/.svelte-kit/output/server/entries/endpoints/api/sessions/_server.ts.js +49 -0
- package/web/.svelte-kit/output/server/entries/endpoints/api/sessions/_target_/output/_server.ts.js +14 -0
- package/web/.svelte-kit/output/server/entries/endpoints/api/tmux/panes/_server.ts.js +21 -0
- package/web/.svelte-kit/output/server/entries/fallbacks/error.svelte.js +27 -0
- package/web/.svelte-kit/output/server/entries/hooks.server.js +105 -0
- package/web/.svelte-kit/output/server/entries/pages/_layout.svelte.js +499 -0
- package/web/.svelte-kit/output/server/entries/pages/_page.svelte.js +3057 -0
- package/web/.svelte-kit/output/server/entries/pages/login/_page.server.ts.js +15 -0
- package/web/.svelte-kit/output/server/entries/pages/login/_page.svelte.js +37 -0
- package/web/.svelte-kit/output/server/entries/pages/session/_target_/_page.svelte.js +653 -0
- package/web/.svelte-kit/output/server/index.js +3864 -0
- package/web/.svelte-kit/output/server/internal.js +13 -0
- package/web/.svelte-kit/output/server/manifest-full.js +167 -0
- package/web/.svelte-kit/output/server/manifest.js +167 -0
- package/web/.svelte-kit/output/server/nodes/0.js +8 -0
- package/web/.svelte-kit/output/server/nodes/1.js +8 -0
- package/web/.svelte-kit/output/server/nodes/2.js +8 -0
- package/web/.svelte-kit/output/server/nodes/3.js +10 -0
- package/web/.svelte-kit/output/server/nodes/4.js +8 -0
- package/web/.svelte-kit/output/server/remote-entry.js +541 -0
- package/web/.svelte-kit/tsconfig.json +58 -0
- package/web/.svelte-kit/types/route_meta_data.json +55 -0
- package/web/.svelte-kit/types/src/routes/$types.d.ts +24 -0
- package/web/.svelte-kit/types/src/routes/api/auth/login/$types.d.ts +10 -0
- package/web/.svelte-kit/types/src/routes/api/auth/logout/$types.d.ts +10 -0
- package/web/.svelte-kit/types/src/routes/api/beads/$types.d.ts +10 -0
- package/web/.svelte-kit/types/src/routes/api/browse/$types.d.ts +10 -0
- package/web/.svelte-kit/types/src/routes/api/chrome/$types.d.ts +10 -0
- package/web/.svelte-kit/types/src/routes/api/files/image/$types.d.ts +10 -0
- package/web/.svelte-kit/types/src/routes/api/health/$types.d.ts +10 -0
- package/web/.svelte-kit/types/src/routes/api/projects/new-session/$types.d.ts +10 -0
- package/web/.svelte-kit/types/src/routes/api/sessions/$types.d.ts +10 -0
- package/web/.svelte-kit/types/src/routes/api/sessions/[id]/$types.d.ts +11 -0
- package/web/.svelte-kit/types/src/routes/api/sessions/[id]/kill/$types.d.ts +11 -0
- package/web/.svelte-kit/types/src/routes/api/sessions/[id]/restart/$types.d.ts +11 -0
- package/web/.svelte-kit/types/src/routes/api/sessions/[id]/screenshots/$types.d.ts +11 -0
- package/web/.svelte-kit/types/src/routes/api/sessions/[id]/send/$types.d.ts +11 -0
- package/web/.svelte-kit/types/src/routes/api/sessions/[target]/output/$types.d.ts +11 -0
- package/web/.svelte-kit/types/src/routes/api/tmux/panes/$types.d.ts +10 -0
- package/web/.svelte-kit/types/src/routes/login/$types.d.ts +25 -0
- package/web/.svelte-kit/types/src/routes/login/proxy+page.server.ts +19 -0
- package/web/.svelte-kit/types/src/routes/session/[target]/$types.d.ts +19 -0
- package/web/README.md +42 -0
- package/web/components.json +16 -0
- package/web/package.json +35 -0
- package/web/src/app.css +128 -0
- package/web/src/app.d.ts +13 -0
- package/web/src/app.html +11 -0
- package/web/src/hooks.server.ts +156 -0
- package/web/src/lib/assets/favicon.svg +1 -0
- package/web/src/lib/components/AllSessionsPanel.svelte +789 -0
- package/web/src/lib/components/BeadsPanel.svelte +146 -0
- package/web/src/lib/components/IssueItem.svelte +287 -0
- package/web/src/lib/components/ScreenshotsPanel.svelte +336 -0
- package/web/src/lib/components/SessionsSidebar.svelte +312 -0
- package/web/src/lib/components/TerminalRenderer.svelte +189 -0
- package/web/src/lib/components/ui/alert-dialog/alert-dialog-action.svelte +18 -0
- package/web/src/lib/components/ui/alert-dialog/alert-dialog-cancel.svelte +18 -0
- package/web/src/lib/components/ui/alert-dialog/alert-dialog-content.svelte +29 -0
- package/web/src/lib/components/ui/alert-dialog/alert-dialog-description.svelte +17 -0
- package/web/src/lib/components/ui/alert-dialog/alert-dialog-footer.svelte +20 -0
- package/web/src/lib/components/ui/alert-dialog/alert-dialog-header.svelte +20 -0
- package/web/src/lib/components/ui/alert-dialog/alert-dialog-overlay.svelte +20 -0
- package/web/src/lib/components/ui/alert-dialog/alert-dialog-portal.svelte +7 -0
- package/web/src/lib/components/ui/alert-dialog/alert-dialog-title.svelte +17 -0
- package/web/src/lib/components/ui/alert-dialog/alert-dialog-trigger.svelte +7 -0
- package/web/src/lib/components/ui/alert-dialog/alert-dialog.svelte +7 -0
- package/web/src/lib/components/ui/alert-dialog/index.ts +37 -0
- package/web/src/lib/components/ui/badge/badge.svelte +50 -0
- package/web/src/lib/components/ui/badge/index.ts +2 -0
- package/web/src/lib/components/ui/button/button.svelte +86 -0
- package/web/src/lib/components/ui/button/index.ts +17 -0
- package/web/src/lib/components/ui/checkbox/checkbox.svelte +36 -0
- package/web/src/lib/components/ui/checkbox/index.ts +6 -0
- package/web/src/lib/components/ui/dialog/dialog-close.svelte +7 -0
- package/web/src/lib/components/ui/dialog/dialog-content.svelte +45 -0
- package/web/src/lib/components/ui/dialog/dialog-description.svelte +17 -0
- package/web/src/lib/components/ui/dialog/dialog-footer.svelte +20 -0
- package/web/src/lib/components/ui/dialog/dialog-header.svelte +20 -0
- package/web/src/lib/components/ui/dialog/dialog-overlay.svelte +20 -0
- package/web/src/lib/components/ui/dialog/dialog-portal.svelte +7 -0
- package/web/src/lib/components/ui/dialog/dialog-title.svelte +17 -0
- package/web/src/lib/components/ui/dialog/dialog-trigger.svelte +7 -0
- package/web/src/lib/components/ui/dialog/dialog.svelte +7 -0
- package/web/src/lib/components/ui/dialog/index.ts +34 -0
- package/web/src/lib/components/ui/scroll-area/index.ts +10 -0
- package/web/src/lib/components/ui/scroll-area/scroll-area-scrollbar.svelte +31 -0
- package/web/src/lib/components/ui/scroll-area/scroll-area.svelte +43 -0
- package/web/src/lib/components/ui/textarea/index.ts +7 -0
- package/web/src/lib/components/ui/textarea/textarea.svelte +23 -0
- package/web/src/lib/index.ts +1 -0
- package/web/src/lib/server/auth.ts +90 -0
- package/web/src/lib/stores/beads.svelte.ts +163 -0
- package/web/src/lib/stores/input-injection.svelte.ts +39 -0
- package/web/src/lib/stores/preferences.svelte.ts +55 -0
- package/web/src/lib/stores/sessions.svelte.ts +108 -0
- package/web/src/lib/stores/terminal.svelte.ts +96 -0
- package/web/src/lib/stores/websocket-base.svelte.ts +209 -0
- package/web/src/lib/types/terminal.ts +31 -0
- package/web/src/lib/utils/terminal-parser.ts +239 -0
- package/web/src/lib/utils.ts +13 -0
- package/web/src/routes/+layout.svelte +450 -0
- package/web/src/routes/+page.svelte +19 -0
- package/web/src/routes/api/auth/login/+server.ts +34 -0
- package/web/src/routes/api/auth/logout/+server.ts +10 -0
- package/web/src/routes/api/beads/+server.ts +28 -0
- package/web/src/routes/api/browse/+server.ts +59 -0
- package/web/src/routes/api/chrome/+server.ts +35 -0
- package/web/src/routes/api/files/image/+server.ts +64 -0
- package/web/src/routes/api/health/+server.ts +6 -0
- package/web/src/routes/api/projects/new-session/+server.ts +50 -0
- package/web/src/routes/api/sessions/+server.ts +62 -0
- package/web/src/routes/api/sessions/[id]/+server.ts +19 -0
- package/web/src/routes/api/sessions/[id]/kill/+server.ts +46 -0
- package/web/src/routes/api/sessions/[id]/restart/+server.ts +59 -0
- package/web/src/routes/api/sessions/[id]/screenshots/+server.ts +32 -0
- package/web/src/routes/api/sessions/[id]/send/+server.ts +31 -0
- package/web/src/routes/api/sessions/[target]/output/+server.ts +13 -0
- package/web/src/routes/api/tmux/panes/+server.ts +32 -0
- package/web/src/routes/login/+page.server.ts +18 -0
- package/web/src/routes/login/+page.svelte +69 -0
- package/web/src/routes/session/[target]/+page.svelte +450 -0
- package/web/static/robots.txt +3 -0
- package/web/svelte.config.js +20 -0
- package/web/tsconfig.json +20 -0
- package/web/vite.config.ts +154 -0
|
@@ -0,0 +1,3864 @@
|
|
|
1
|
+
import { B as BROWSER } from "./chunks/false.js";
|
|
2
|
+
import { json, text, error } from "@sveltejs/kit";
|
|
3
|
+
import { HttpError, SvelteKitError, Redirect, ActionFailure } from "@sveltejs/kit/internal";
|
|
4
|
+
import { with_request_store, merge_tracing, try_get_request_store } from "@sveltejs/kit/internal/server";
|
|
5
|
+
import { a as assets, b as base, c as app_dir, r as relative, o as override, d as reset } from "./chunks/environment.js";
|
|
6
|
+
import { B as BINARY_FORM_CONTENT_TYPE, c as create_remote_key, p as parse_remote_arg, s as stringify, d as deserialize_binary_form, T as TRAILING_SLASH_PARAM, I as INVALIDATED_PARAM } from "./chunks/shared.js";
|
|
7
|
+
import * as devalue from "devalue";
|
|
8
|
+
import { m as make_trackable, d as disable_search, a as decode_params, S as SCHEME, v as validate_layout_server_exports, b as validate_layout_exports, c as validate_page_server_exports, e as validate_page_exports, n as normalize_path, r as resolve, f as decode_pathname, g as validate_server_exports } from "./chunks/exports.js";
|
|
9
|
+
import { b as base64_encode, t as text_decoder, a as text_encoder, g as get_relative_path } from "./chunks/utils.js";
|
|
10
|
+
import { w as writable, r as readable } from "./chunks/index.js";
|
|
11
|
+
import { p as public_env, r as read_implementation, o as options, s as set_private_env, a as set_public_env, g as get_hooks, b as set_read_implementation } from "./chunks/internal.js";
|
|
12
|
+
import { parse, serialize } from "cookie";
|
|
13
|
+
import * as set_cookie_parser from "set-cookie-parser";
|
|
14
|
+
function with_resolvers() {
|
|
15
|
+
let resolve2;
|
|
16
|
+
let reject;
|
|
17
|
+
const promise = new Promise((res, rej) => {
|
|
18
|
+
resolve2 = res;
|
|
19
|
+
reject = rej;
|
|
20
|
+
});
|
|
21
|
+
return { promise, resolve: resolve2, reject };
|
|
22
|
+
}
|
|
23
|
+
const NULL_BODY_STATUS = [101, 103, 204, 205, 304];
|
|
24
|
+
const IN_WEBCONTAINER = !!globalThis.process?.versions?.webcontainer;
|
|
25
|
+
const SVELTE_KIT_ASSETS = "/_svelte_kit_assets";
|
|
26
|
+
const ENDPOINT_METHODS = ["GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS", "HEAD"];
|
|
27
|
+
const PAGE_METHODS = ["GET", "POST", "HEAD"];
|
|
28
|
+
function negotiate(accept, types) {
|
|
29
|
+
const parts = [];
|
|
30
|
+
accept.split(",").forEach((str, i) => {
|
|
31
|
+
const match = /([^/ \t]+)\/([^; \t]+)[ \t]*(?:;[ \t]*q=([0-9.]+))?/.exec(str);
|
|
32
|
+
if (match) {
|
|
33
|
+
const [, type, subtype, q = "1"] = match;
|
|
34
|
+
parts.push({ type, subtype, q: +q, i });
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
parts.sort((a, b) => {
|
|
38
|
+
if (a.q !== b.q) {
|
|
39
|
+
return b.q - a.q;
|
|
40
|
+
}
|
|
41
|
+
if (a.subtype === "*" !== (b.subtype === "*")) {
|
|
42
|
+
return a.subtype === "*" ? 1 : -1;
|
|
43
|
+
}
|
|
44
|
+
if (a.type === "*" !== (b.type === "*")) {
|
|
45
|
+
return a.type === "*" ? 1 : -1;
|
|
46
|
+
}
|
|
47
|
+
return a.i - b.i;
|
|
48
|
+
});
|
|
49
|
+
let accepted;
|
|
50
|
+
let min_priority = Infinity;
|
|
51
|
+
for (const mimetype of types) {
|
|
52
|
+
const [type, subtype] = mimetype.split("/");
|
|
53
|
+
const priority = parts.findIndex(
|
|
54
|
+
(part) => (part.type === type || part.type === "*") && (part.subtype === subtype || part.subtype === "*")
|
|
55
|
+
);
|
|
56
|
+
if (priority !== -1 && priority < min_priority) {
|
|
57
|
+
accepted = mimetype;
|
|
58
|
+
min_priority = priority;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return accepted;
|
|
62
|
+
}
|
|
63
|
+
function is_content_type(request, ...types) {
|
|
64
|
+
const type = request.headers.get("content-type")?.split(";", 1)[0].trim() ?? "";
|
|
65
|
+
return types.includes(type.toLowerCase());
|
|
66
|
+
}
|
|
67
|
+
function is_form_content_type(request) {
|
|
68
|
+
return is_content_type(
|
|
69
|
+
request,
|
|
70
|
+
"application/x-www-form-urlencoded",
|
|
71
|
+
"multipart/form-data",
|
|
72
|
+
"text/plain",
|
|
73
|
+
BINARY_FORM_CONTENT_TYPE
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
function coalesce_to_error(err) {
|
|
77
|
+
return err instanceof Error || err && /** @type {any} */
|
|
78
|
+
err.name && /** @type {any} */
|
|
79
|
+
err.message ? (
|
|
80
|
+
/** @type {Error} */
|
|
81
|
+
err
|
|
82
|
+
) : new Error(JSON.stringify(err));
|
|
83
|
+
}
|
|
84
|
+
function normalize_error(error2) {
|
|
85
|
+
return (
|
|
86
|
+
/** @type {import('../exports/internal/index.js').Redirect | HttpError | SvelteKitError | Error} */
|
|
87
|
+
error2
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
function get_status(error2) {
|
|
91
|
+
return error2 instanceof HttpError || error2 instanceof SvelteKitError ? error2.status : 500;
|
|
92
|
+
}
|
|
93
|
+
function get_message(error2) {
|
|
94
|
+
return error2 instanceof SvelteKitError ? error2.text : "Internal Error";
|
|
95
|
+
}
|
|
96
|
+
const escape_html_attr_dict = {
|
|
97
|
+
"&": "&",
|
|
98
|
+
'"': """
|
|
99
|
+
// Svelte also escapes < because the escape function could be called inside a `noscript` there
|
|
100
|
+
// https://github.com/sveltejs/svelte/security/advisories/GHSA-8266-84wp-wv5c
|
|
101
|
+
// However, that doesn't apply in SvelteKit
|
|
102
|
+
};
|
|
103
|
+
const escape_html_dict = {
|
|
104
|
+
"&": "&",
|
|
105
|
+
"<": "<"
|
|
106
|
+
};
|
|
107
|
+
const surrogates = (
|
|
108
|
+
// high surrogate without paired low surrogate
|
|
109
|
+
"[\\ud800-\\udbff](?![\\udc00-\\udfff])|[\\ud800-\\udbff][\\udc00-\\udfff]|[\\udc00-\\udfff]"
|
|
110
|
+
);
|
|
111
|
+
const escape_html_attr_regex = new RegExp(
|
|
112
|
+
`[${Object.keys(escape_html_attr_dict).join("")}]|` + surrogates,
|
|
113
|
+
"g"
|
|
114
|
+
);
|
|
115
|
+
const escape_html_regex = new RegExp(
|
|
116
|
+
`[${Object.keys(escape_html_dict).join("")}]|` + surrogates,
|
|
117
|
+
"g"
|
|
118
|
+
);
|
|
119
|
+
function escape_html(str, is_attr) {
|
|
120
|
+
const dict = is_attr ? escape_html_attr_dict : escape_html_dict;
|
|
121
|
+
const escaped_str = str.replace(is_attr ? escape_html_attr_regex : escape_html_regex, (match) => {
|
|
122
|
+
if (match.length === 2) {
|
|
123
|
+
return match;
|
|
124
|
+
}
|
|
125
|
+
return dict[match] ?? `&#${match.charCodeAt(0)};`;
|
|
126
|
+
});
|
|
127
|
+
return escaped_str;
|
|
128
|
+
}
|
|
129
|
+
function method_not_allowed(mod, method) {
|
|
130
|
+
return text(`${method} method not allowed`, {
|
|
131
|
+
status: 405,
|
|
132
|
+
headers: {
|
|
133
|
+
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/405
|
|
134
|
+
// "The server must generate an Allow header field in a 405 status code response"
|
|
135
|
+
allow: allowed_methods(mod).join(", ")
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
function allowed_methods(mod) {
|
|
140
|
+
const allowed = ENDPOINT_METHODS.filter((method) => method in mod);
|
|
141
|
+
if ("GET" in mod && !("HEAD" in mod)) {
|
|
142
|
+
allowed.push("HEAD");
|
|
143
|
+
}
|
|
144
|
+
return allowed;
|
|
145
|
+
}
|
|
146
|
+
function get_global_name(options2) {
|
|
147
|
+
return `__sveltekit_${options2.version_hash}`;
|
|
148
|
+
}
|
|
149
|
+
function static_error_page(options2, status, message) {
|
|
150
|
+
let page = options2.templates.error({ status, message: escape_html(message) });
|
|
151
|
+
return text(page, {
|
|
152
|
+
headers: { "content-type": "text/html; charset=utf-8" },
|
|
153
|
+
status
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
async function handle_fatal_error(event, state, options2, error2) {
|
|
157
|
+
error2 = error2 instanceof HttpError ? error2 : coalesce_to_error(error2);
|
|
158
|
+
const status = get_status(error2);
|
|
159
|
+
const body2 = await handle_error_and_jsonify(event, state, options2, error2);
|
|
160
|
+
const type = negotiate(event.request.headers.get("accept") || "text/html", [
|
|
161
|
+
"application/json",
|
|
162
|
+
"text/html"
|
|
163
|
+
]);
|
|
164
|
+
if (event.isDataRequest || type === "application/json") {
|
|
165
|
+
return json(body2, {
|
|
166
|
+
status
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
return static_error_page(options2, status, body2.message);
|
|
170
|
+
}
|
|
171
|
+
async function handle_error_and_jsonify(event, state, options2, error2) {
|
|
172
|
+
if (error2 instanceof HttpError) {
|
|
173
|
+
return { message: "Unknown Error", ...error2.body };
|
|
174
|
+
}
|
|
175
|
+
const status = get_status(error2);
|
|
176
|
+
const message = get_message(error2);
|
|
177
|
+
return await with_request_store(
|
|
178
|
+
{ event, state },
|
|
179
|
+
() => options2.hooks.handleError({ error: error2, event, status, message })
|
|
180
|
+
) ?? { message };
|
|
181
|
+
}
|
|
182
|
+
function redirect_response(status, location) {
|
|
183
|
+
const response = new Response(void 0, {
|
|
184
|
+
status,
|
|
185
|
+
headers: { location }
|
|
186
|
+
});
|
|
187
|
+
return response;
|
|
188
|
+
}
|
|
189
|
+
function clarify_devalue_error(event, error2) {
|
|
190
|
+
if (error2.path) {
|
|
191
|
+
return `Data returned from \`load\` while rendering ${event.route.id} is not serializable: ${error2.message} (${error2.path}). If you need to serialize/deserialize custom types, use transport hooks: https://svelte.dev/docs/kit/hooks#Universal-hooks-transport.`;
|
|
192
|
+
}
|
|
193
|
+
if (error2.path === "") {
|
|
194
|
+
return `Data returned from \`load\` while rendering ${event.route.id} is not a plain object`;
|
|
195
|
+
}
|
|
196
|
+
return error2.message;
|
|
197
|
+
}
|
|
198
|
+
function serialize_uses(node) {
|
|
199
|
+
const uses = {};
|
|
200
|
+
if (node.uses && node.uses.dependencies.size > 0) {
|
|
201
|
+
uses.dependencies = Array.from(node.uses.dependencies);
|
|
202
|
+
}
|
|
203
|
+
if (node.uses && node.uses.search_params.size > 0) {
|
|
204
|
+
uses.search_params = Array.from(node.uses.search_params);
|
|
205
|
+
}
|
|
206
|
+
if (node.uses && node.uses.params.size > 0) {
|
|
207
|
+
uses.params = Array.from(node.uses.params);
|
|
208
|
+
}
|
|
209
|
+
if (node.uses?.parent) uses.parent = 1;
|
|
210
|
+
if (node.uses?.route) uses.route = 1;
|
|
211
|
+
if (node.uses?.url) uses.url = 1;
|
|
212
|
+
return uses;
|
|
213
|
+
}
|
|
214
|
+
function has_prerendered_path(manifest, pathname) {
|
|
215
|
+
return manifest._.prerendered_routes.has(pathname) || pathname.at(-1) === "/" && manifest._.prerendered_routes.has(pathname.slice(0, -1));
|
|
216
|
+
}
|
|
217
|
+
function format_server_error(status, error2, event) {
|
|
218
|
+
const formatted_text = `
|
|
219
|
+
\x1B[1;31m[${status}] ${event.request.method} ${event.url.pathname}\x1B[0m`;
|
|
220
|
+
if (status === 404) {
|
|
221
|
+
return formatted_text;
|
|
222
|
+
}
|
|
223
|
+
return `${formatted_text}
|
|
224
|
+
${error2.stack}`;
|
|
225
|
+
}
|
|
226
|
+
function get_node_type(node_id) {
|
|
227
|
+
const parts = node_id?.split("/");
|
|
228
|
+
const filename = parts?.at(-1);
|
|
229
|
+
if (!filename) return "unknown";
|
|
230
|
+
const dot_parts = filename.split(".");
|
|
231
|
+
return dot_parts.slice(0, -1).join(".");
|
|
232
|
+
}
|
|
233
|
+
async function render_endpoint(event, event_state, mod, state) {
|
|
234
|
+
const method = (
|
|
235
|
+
/** @type {import('types').HttpMethod} */
|
|
236
|
+
event.request.method
|
|
237
|
+
);
|
|
238
|
+
let handler = mod[method] || mod.fallback;
|
|
239
|
+
if (method === "HEAD" && !mod.HEAD && mod.GET) {
|
|
240
|
+
handler = mod.GET;
|
|
241
|
+
}
|
|
242
|
+
if (!handler) {
|
|
243
|
+
return method_not_allowed(mod, method);
|
|
244
|
+
}
|
|
245
|
+
const prerender = mod.prerender ?? state.prerender_default;
|
|
246
|
+
if (prerender && (mod.POST || mod.PATCH || mod.PUT || mod.DELETE)) {
|
|
247
|
+
throw new Error("Cannot prerender endpoints that have mutative methods");
|
|
248
|
+
}
|
|
249
|
+
if (state.prerendering && !state.prerendering.inside_reroute && !prerender) {
|
|
250
|
+
if (state.depth > 0) {
|
|
251
|
+
throw new Error(`${event.route.id} is not prerenderable`);
|
|
252
|
+
} else {
|
|
253
|
+
return new Response(void 0, { status: 204 });
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
event_state.is_endpoint_request = true;
|
|
257
|
+
try {
|
|
258
|
+
const response = await with_request_store(
|
|
259
|
+
{ event, state: event_state },
|
|
260
|
+
() => handler(
|
|
261
|
+
/** @type {import('@sveltejs/kit').RequestEvent<Record<string, any>>} */
|
|
262
|
+
event
|
|
263
|
+
)
|
|
264
|
+
);
|
|
265
|
+
if (!(response instanceof Response)) {
|
|
266
|
+
throw new Error(
|
|
267
|
+
`Invalid response from route ${event.url.pathname}: handler should return a Response object`
|
|
268
|
+
);
|
|
269
|
+
}
|
|
270
|
+
if (state.prerendering && (!state.prerendering.inside_reroute || prerender)) {
|
|
271
|
+
const cloned = new Response(response.clone().body, {
|
|
272
|
+
status: response.status,
|
|
273
|
+
statusText: response.statusText,
|
|
274
|
+
headers: new Headers(response.headers)
|
|
275
|
+
});
|
|
276
|
+
cloned.headers.set("x-sveltekit-prerender", String(prerender));
|
|
277
|
+
if (state.prerendering.inside_reroute && prerender) {
|
|
278
|
+
cloned.headers.set(
|
|
279
|
+
"x-sveltekit-routeid",
|
|
280
|
+
encodeURI(
|
|
281
|
+
/** @type {string} */
|
|
282
|
+
event.route.id
|
|
283
|
+
)
|
|
284
|
+
);
|
|
285
|
+
state.prerendering.dependencies.set(event.url.pathname, { response: cloned, body: null });
|
|
286
|
+
} else {
|
|
287
|
+
return cloned;
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
return response;
|
|
291
|
+
} catch (e) {
|
|
292
|
+
if (e instanceof Redirect) {
|
|
293
|
+
return new Response(void 0, {
|
|
294
|
+
status: e.status,
|
|
295
|
+
headers: { location: e.location }
|
|
296
|
+
});
|
|
297
|
+
}
|
|
298
|
+
throw e;
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
function is_endpoint_request(event) {
|
|
302
|
+
const { method, headers: headers2 } = event.request;
|
|
303
|
+
if (ENDPOINT_METHODS.includes(method) && !PAGE_METHODS.includes(method)) {
|
|
304
|
+
return true;
|
|
305
|
+
}
|
|
306
|
+
if (method === "POST" && headers2.get("x-sveltekit-action") === "true") return false;
|
|
307
|
+
const accept = event.request.headers.get("accept") ?? "*/*";
|
|
308
|
+
return negotiate(accept, ["*", "text/html"]) !== "text/html";
|
|
309
|
+
}
|
|
310
|
+
function compact(arr) {
|
|
311
|
+
return arr.filter(
|
|
312
|
+
/** @returns {val is NonNullable<T>} */
|
|
313
|
+
(val) => val != null
|
|
314
|
+
);
|
|
315
|
+
}
|
|
316
|
+
const DATA_SUFFIX = "/__data.json";
|
|
317
|
+
const HTML_DATA_SUFFIX = ".html__data.json";
|
|
318
|
+
function has_data_suffix(pathname) {
|
|
319
|
+
return pathname.endsWith(DATA_SUFFIX) || pathname.endsWith(HTML_DATA_SUFFIX);
|
|
320
|
+
}
|
|
321
|
+
function add_data_suffix(pathname) {
|
|
322
|
+
if (pathname.endsWith(".html")) return pathname.replace(/\.html$/, HTML_DATA_SUFFIX);
|
|
323
|
+
return pathname.replace(/\/$/, "") + DATA_SUFFIX;
|
|
324
|
+
}
|
|
325
|
+
function strip_data_suffix(pathname) {
|
|
326
|
+
if (pathname.endsWith(HTML_DATA_SUFFIX)) {
|
|
327
|
+
return pathname.slice(0, -HTML_DATA_SUFFIX.length) + ".html";
|
|
328
|
+
}
|
|
329
|
+
return pathname.slice(0, -DATA_SUFFIX.length);
|
|
330
|
+
}
|
|
331
|
+
const ROUTE_SUFFIX = "/__route.js";
|
|
332
|
+
function has_resolution_suffix(pathname) {
|
|
333
|
+
return pathname.endsWith(ROUTE_SUFFIX);
|
|
334
|
+
}
|
|
335
|
+
function add_resolution_suffix(pathname) {
|
|
336
|
+
return pathname.replace(/\/$/, "") + ROUTE_SUFFIX;
|
|
337
|
+
}
|
|
338
|
+
function strip_resolution_suffix(pathname) {
|
|
339
|
+
return pathname.slice(0, -ROUTE_SUFFIX.length);
|
|
340
|
+
}
|
|
341
|
+
const noop_span = {
|
|
342
|
+
spanContext() {
|
|
343
|
+
return noop_span_context;
|
|
344
|
+
},
|
|
345
|
+
setAttribute() {
|
|
346
|
+
return this;
|
|
347
|
+
},
|
|
348
|
+
setAttributes() {
|
|
349
|
+
return this;
|
|
350
|
+
},
|
|
351
|
+
addEvent() {
|
|
352
|
+
return this;
|
|
353
|
+
},
|
|
354
|
+
setStatus() {
|
|
355
|
+
return this;
|
|
356
|
+
},
|
|
357
|
+
updateName() {
|
|
358
|
+
return this;
|
|
359
|
+
},
|
|
360
|
+
end() {
|
|
361
|
+
return this;
|
|
362
|
+
},
|
|
363
|
+
isRecording() {
|
|
364
|
+
return false;
|
|
365
|
+
},
|
|
366
|
+
recordException() {
|
|
367
|
+
return this;
|
|
368
|
+
},
|
|
369
|
+
addLink() {
|
|
370
|
+
return this;
|
|
371
|
+
},
|
|
372
|
+
addLinks() {
|
|
373
|
+
return this;
|
|
374
|
+
}
|
|
375
|
+
};
|
|
376
|
+
const noop_span_context = {
|
|
377
|
+
traceId: "",
|
|
378
|
+
spanId: "",
|
|
379
|
+
traceFlags: 0
|
|
380
|
+
};
|
|
381
|
+
async function record_span({ name, attributes, fn }) {
|
|
382
|
+
{
|
|
383
|
+
return fn(noop_span);
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
function is_action_json_request(event) {
|
|
387
|
+
const accept = negotiate(event.request.headers.get("accept") ?? "*/*", [
|
|
388
|
+
"application/json",
|
|
389
|
+
"text/html"
|
|
390
|
+
]);
|
|
391
|
+
return accept === "application/json" && event.request.method === "POST";
|
|
392
|
+
}
|
|
393
|
+
async function handle_action_json_request(event, event_state, options2, server) {
|
|
394
|
+
const actions = server?.actions;
|
|
395
|
+
if (!actions) {
|
|
396
|
+
const no_actions_error = new SvelteKitError(
|
|
397
|
+
405,
|
|
398
|
+
"Method Not Allowed",
|
|
399
|
+
`POST method not allowed. No form actions exist for ${"this page"}`
|
|
400
|
+
);
|
|
401
|
+
return action_json(
|
|
402
|
+
{
|
|
403
|
+
type: "error",
|
|
404
|
+
error: await handle_error_and_jsonify(event, event_state, options2, no_actions_error)
|
|
405
|
+
},
|
|
406
|
+
{
|
|
407
|
+
status: no_actions_error.status,
|
|
408
|
+
headers: {
|
|
409
|
+
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/405
|
|
410
|
+
// "The server must generate an Allow header field in a 405 status code response"
|
|
411
|
+
allow: "GET"
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
);
|
|
415
|
+
}
|
|
416
|
+
check_named_default_separate(actions);
|
|
417
|
+
try {
|
|
418
|
+
const data = await call_action(event, event_state, actions);
|
|
419
|
+
if (BROWSER) ;
|
|
420
|
+
if (data instanceof ActionFailure) {
|
|
421
|
+
return action_json({
|
|
422
|
+
type: "failure",
|
|
423
|
+
status: data.status,
|
|
424
|
+
// @ts-expect-error we assign a string to what is supposed to be an object. That's ok
|
|
425
|
+
// because we don't use the object outside, and this way we have better code navigation
|
|
426
|
+
// through knowing where the related interface is used.
|
|
427
|
+
data: stringify_action_response(
|
|
428
|
+
data.data,
|
|
429
|
+
/** @type {string} */
|
|
430
|
+
event.route.id,
|
|
431
|
+
options2.hooks.transport
|
|
432
|
+
)
|
|
433
|
+
});
|
|
434
|
+
} else {
|
|
435
|
+
return action_json({
|
|
436
|
+
type: "success",
|
|
437
|
+
status: data ? 200 : 204,
|
|
438
|
+
// @ts-expect-error see comment above
|
|
439
|
+
data: stringify_action_response(
|
|
440
|
+
data,
|
|
441
|
+
/** @type {string} */
|
|
442
|
+
event.route.id,
|
|
443
|
+
options2.hooks.transport
|
|
444
|
+
)
|
|
445
|
+
});
|
|
446
|
+
}
|
|
447
|
+
} catch (e) {
|
|
448
|
+
const err = normalize_error(e);
|
|
449
|
+
if (err instanceof Redirect) {
|
|
450
|
+
return action_json_redirect(err);
|
|
451
|
+
}
|
|
452
|
+
return action_json(
|
|
453
|
+
{
|
|
454
|
+
type: "error",
|
|
455
|
+
error: await handle_error_and_jsonify(
|
|
456
|
+
event,
|
|
457
|
+
event_state,
|
|
458
|
+
options2,
|
|
459
|
+
check_incorrect_fail_use(err)
|
|
460
|
+
)
|
|
461
|
+
},
|
|
462
|
+
{
|
|
463
|
+
status: get_status(err)
|
|
464
|
+
}
|
|
465
|
+
);
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
function check_incorrect_fail_use(error2) {
|
|
469
|
+
return error2 instanceof ActionFailure ? new Error('Cannot "throw fail()". Use "return fail()"') : error2;
|
|
470
|
+
}
|
|
471
|
+
function action_json_redirect(redirect) {
|
|
472
|
+
return action_json({
|
|
473
|
+
type: "redirect",
|
|
474
|
+
status: redirect.status,
|
|
475
|
+
location: redirect.location
|
|
476
|
+
});
|
|
477
|
+
}
|
|
478
|
+
function action_json(data, init2) {
|
|
479
|
+
return json(data, init2);
|
|
480
|
+
}
|
|
481
|
+
function is_action_request(event) {
|
|
482
|
+
return event.request.method === "POST";
|
|
483
|
+
}
|
|
484
|
+
async function handle_action_request(event, event_state, server) {
|
|
485
|
+
const actions = server?.actions;
|
|
486
|
+
if (!actions) {
|
|
487
|
+
event.setHeaders({
|
|
488
|
+
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/405
|
|
489
|
+
// "The server must generate an Allow header field in a 405 status code response"
|
|
490
|
+
allow: "GET"
|
|
491
|
+
});
|
|
492
|
+
return {
|
|
493
|
+
type: "error",
|
|
494
|
+
error: new SvelteKitError(
|
|
495
|
+
405,
|
|
496
|
+
"Method Not Allowed",
|
|
497
|
+
`POST method not allowed. No form actions exist for ${"this page"}`
|
|
498
|
+
)
|
|
499
|
+
};
|
|
500
|
+
}
|
|
501
|
+
check_named_default_separate(actions);
|
|
502
|
+
try {
|
|
503
|
+
const data = await call_action(event, event_state, actions);
|
|
504
|
+
if (BROWSER) ;
|
|
505
|
+
if (data instanceof ActionFailure) {
|
|
506
|
+
return {
|
|
507
|
+
type: "failure",
|
|
508
|
+
status: data.status,
|
|
509
|
+
data: data.data
|
|
510
|
+
};
|
|
511
|
+
} else {
|
|
512
|
+
return {
|
|
513
|
+
type: "success",
|
|
514
|
+
status: 200,
|
|
515
|
+
// @ts-expect-error this will be removed upon serialization, so `undefined` is the same as omission
|
|
516
|
+
data
|
|
517
|
+
};
|
|
518
|
+
}
|
|
519
|
+
} catch (e) {
|
|
520
|
+
const err = normalize_error(e);
|
|
521
|
+
if (err instanceof Redirect) {
|
|
522
|
+
return {
|
|
523
|
+
type: "redirect",
|
|
524
|
+
status: err.status,
|
|
525
|
+
location: err.location
|
|
526
|
+
};
|
|
527
|
+
}
|
|
528
|
+
return {
|
|
529
|
+
type: "error",
|
|
530
|
+
error: check_incorrect_fail_use(err)
|
|
531
|
+
};
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
function check_named_default_separate(actions) {
|
|
535
|
+
if (actions.default && Object.keys(actions).length > 1) {
|
|
536
|
+
throw new Error(
|
|
537
|
+
"When using named actions, the default action cannot be used. See the docs for more info: https://svelte.dev/docs/kit/form-actions#named-actions"
|
|
538
|
+
);
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
async function call_action(event, event_state, actions) {
|
|
542
|
+
const url = new URL(event.request.url);
|
|
543
|
+
let name = "default";
|
|
544
|
+
for (const param of url.searchParams) {
|
|
545
|
+
if (param[0].startsWith("/")) {
|
|
546
|
+
name = param[0].slice(1);
|
|
547
|
+
if (name === "default") {
|
|
548
|
+
throw new Error('Cannot use reserved action name "default"');
|
|
549
|
+
}
|
|
550
|
+
break;
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
const action = actions[name];
|
|
554
|
+
if (!action) {
|
|
555
|
+
throw new SvelteKitError(404, "Not Found", `No action with name '${name}' found`);
|
|
556
|
+
}
|
|
557
|
+
if (!is_form_content_type(event.request)) {
|
|
558
|
+
throw new SvelteKitError(
|
|
559
|
+
415,
|
|
560
|
+
"Unsupported Media Type",
|
|
561
|
+
`Form actions expect form-encoded data — received ${event.request.headers.get(
|
|
562
|
+
"content-type"
|
|
563
|
+
)}`
|
|
564
|
+
);
|
|
565
|
+
}
|
|
566
|
+
return record_span({
|
|
567
|
+
name: "sveltekit.form_action",
|
|
568
|
+
attributes: {
|
|
569
|
+
"http.route": event.route.id || "unknown"
|
|
570
|
+
},
|
|
571
|
+
fn: async (current2) => {
|
|
572
|
+
const traced_event = merge_tracing(event, current2);
|
|
573
|
+
const result = await with_request_store(
|
|
574
|
+
{ event: traced_event, state: event_state },
|
|
575
|
+
() => action(traced_event)
|
|
576
|
+
);
|
|
577
|
+
if (result instanceof ActionFailure) {
|
|
578
|
+
current2.setAttributes({
|
|
579
|
+
"sveltekit.form_action.result.type": "failure",
|
|
580
|
+
"sveltekit.form_action.result.status": result.status
|
|
581
|
+
});
|
|
582
|
+
}
|
|
583
|
+
return result;
|
|
584
|
+
}
|
|
585
|
+
});
|
|
586
|
+
}
|
|
587
|
+
function validate_action_return(data) {
|
|
588
|
+
if (data instanceof Redirect) {
|
|
589
|
+
throw new Error("Cannot `return redirect(...)` — use `redirect(...)` instead");
|
|
590
|
+
}
|
|
591
|
+
if (data instanceof HttpError) {
|
|
592
|
+
throw new Error("Cannot `return error(...)` — use `error(...)` or `return fail(...)` instead");
|
|
593
|
+
}
|
|
594
|
+
}
|
|
595
|
+
function uneval_action_response(data, route_id, transport) {
|
|
596
|
+
const replacer = (thing) => {
|
|
597
|
+
for (const key2 in transport) {
|
|
598
|
+
const encoded = transport[key2].encode(thing);
|
|
599
|
+
if (encoded) {
|
|
600
|
+
return `app.decode('${key2}', ${devalue.uneval(encoded, replacer)})`;
|
|
601
|
+
}
|
|
602
|
+
}
|
|
603
|
+
};
|
|
604
|
+
return try_serialize(data, (value) => devalue.uneval(value, replacer), route_id);
|
|
605
|
+
}
|
|
606
|
+
function stringify_action_response(data, route_id, transport) {
|
|
607
|
+
const encoders = Object.fromEntries(
|
|
608
|
+
Object.entries(transport).map(([key2, value]) => [key2, value.encode])
|
|
609
|
+
);
|
|
610
|
+
return try_serialize(data, (value) => devalue.stringify(value, encoders), route_id);
|
|
611
|
+
}
|
|
612
|
+
function try_serialize(data, fn, route_id) {
|
|
613
|
+
try {
|
|
614
|
+
return fn(data);
|
|
615
|
+
} catch (e) {
|
|
616
|
+
const error2 = (
|
|
617
|
+
/** @type {any} */
|
|
618
|
+
e
|
|
619
|
+
);
|
|
620
|
+
if (data instanceof Response) {
|
|
621
|
+
throw new Error(
|
|
622
|
+
`Data returned from action inside ${route_id} is not serializable. Form actions need to return plain objects or fail(). E.g. return { success: true } or return fail(400, { message: "invalid" });`
|
|
623
|
+
);
|
|
624
|
+
}
|
|
625
|
+
if ("path" in error2) {
|
|
626
|
+
let message = `Data returned from action inside ${route_id} is not serializable: ${error2.message}`;
|
|
627
|
+
if (error2.path !== "") message += ` (data.${error2.path})`;
|
|
628
|
+
throw new Error(message);
|
|
629
|
+
}
|
|
630
|
+
throw error2;
|
|
631
|
+
}
|
|
632
|
+
}
|
|
633
|
+
function create_async_iterator() {
|
|
634
|
+
let resolved = -1;
|
|
635
|
+
let returned = -1;
|
|
636
|
+
const deferred = [];
|
|
637
|
+
return {
|
|
638
|
+
iterate: (transform = (x) => x) => {
|
|
639
|
+
return {
|
|
640
|
+
[Symbol.asyncIterator]() {
|
|
641
|
+
return {
|
|
642
|
+
next: async () => {
|
|
643
|
+
const next = deferred[++returned];
|
|
644
|
+
if (!next) return { value: null, done: true };
|
|
645
|
+
const value = await next.promise;
|
|
646
|
+
return { value: transform(value), done: false };
|
|
647
|
+
}
|
|
648
|
+
};
|
|
649
|
+
}
|
|
650
|
+
};
|
|
651
|
+
},
|
|
652
|
+
add: (promise) => {
|
|
653
|
+
deferred.push(with_resolvers());
|
|
654
|
+
void promise.then((value) => {
|
|
655
|
+
deferred[++resolved].resolve(value);
|
|
656
|
+
});
|
|
657
|
+
}
|
|
658
|
+
};
|
|
659
|
+
}
|
|
660
|
+
function server_data_serializer(event, event_state, options2) {
|
|
661
|
+
let promise_id = 1;
|
|
662
|
+
let max_nodes = -1;
|
|
663
|
+
const iterator = create_async_iterator();
|
|
664
|
+
const global = get_global_name(options2);
|
|
665
|
+
function get_replacer(index) {
|
|
666
|
+
return function replacer(thing) {
|
|
667
|
+
if (typeof thing?.then === "function") {
|
|
668
|
+
const id = promise_id++;
|
|
669
|
+
const promise = thing.then(
|
|
670
|
+
/** @param {any} data */
|
|
671
|
+
(data) => ({ data })
|
|
672
|
+
).catch(
|
|
673
|
+
/** @param {any} error */
|
|
674
|
+
async (error2) => ({
|
|
675
|
+
error: await handle_error_and_jsonify(event, event_state, options2, error2)
|
|
676
|
+
})
|
|
677
|
+
).then(
|
|
678
|
+
/**
|
|
679
|
+
* @param {{data: any; error: any}} result
|
|
680
|
+
*/
|
|
681
|
+
async ({ data, error: error2 }) => {
|
|
682
|
+
let str;
|
|
683
|
+
try {
|
|
684
|
+
str = devalue.uneval(error2 ? [, error2] : [data], replacer);
|
|
685
|
+
} catch {
|
|
686
|
+
error2 = await handle_error_and_jsonify(
|
|
687
|
+
event,
|
|
688
|
+
event_state,
|
|
689
|
+
options2,
|
|
690
|
+
new Error(`Failed to serialize promise while rendering ${event.route.id}`)
|
|
691
|
+
);
|
|
692
|
+
data = void 0;
|
|
693
|
+
str = devalue.uneval([, error2], replacer);
|
|
694
|
+
}
|
|
695
|
+
return {
|
|
696
|
+
index,
|
|
697
|
+
str: `${global}.resolve(${id}, ${str.includes("app.decode") ? `(app) => ${str}` : `() => ${str}`})`
|
|
698
|
+
};
|
|
699
|
+
}
|
|
700
|
+
);
|
|
701
|
+
iterator.add(promise);
|
|
702
|
+
return `${global}.defer(${id})`;
|
|
703
|
+
} else {
|
|
704
|
+
for (const key2 in options2.hooks.transport) {
|
|
705
|
+
const encoded = options2.hooks.transport[key2].encode(thing);
|
|
706
|
+
if (encoded) {
|
|
707
|
+
return `app.decode('${key2}', ${devalue.uneval(encoded, replacer)})`;
|
|
708
|
+
}
|
|
709
|
+
}
|
|
710
|
+
}
|
|
711
|
+
};
|
|
712
|
+
}
|
|
713
|
+
const strings = (
|
|
714
|
+
/** @type {string[]} */
|
|
715
|
+
[]
|
|
716
|
+
);
|
|
717
|
+
return {
|
|
718
|
+
set_max_nodes(i) {
|
|
719
|
+
max_nodes = i;
|
|
720
|
+
},
|
|
721
|
+
add_node(i, node) {
|
|
722
|
+
try {
|
|
723
|
+
if (!node) {
|
|
724
|
+
strings[i] = "null";
|
|
725
|
+
return;
|
|
726
|
+
}
|
|
727
|
+
const payload = { type: "data", data: node.data, uses: serialize_uses(node) };
|
|
728
|
+
if (node.slash) payload.slash = node.slash;
|
|
729
|
+
strings[i] = devalue.uneval(payload, get_replacer(i));
|
|
730
|
+
} catch (e) {
|
|
731
|
+
e.path = e.path.slice(1);
|
|
732
|
+
throw new Error(clarify_devalue_error(
|
|
733
|
+
event,
|
|
734
|
+
/** @type {any} */
|
|
735
|
+
e
|
|
736
|
+
));
|
|
737
|
+
}
|
|
738
|
+
},
|
|
739
|
+
get_data(csp) {
|
|
740
|
+
const open = `<script${csp.script_needs_nonce ? ` nonce="${csp.nonce}"` : ""}>`;
|
|
741
|
+
const close = `<\/script>
|
|
742
|
+
`;
|
|
743
|
+
return {
|
|
744
|
+
data: `[${compact(max_nodes > -1 ? strings.slice(0, max_nodes) : strings).join(",")}]`,
|
|
745
|
+
chunks: promise_id > 1 ? iterator.iterate(({ index, str }) => {
|
|
746
|
+
if (max_nodes > -1 && index >= max_nodes) {
|
|
747
|
+
return "";
|
|
748
|
+
}
|
|
749
|
+
return open + str + close;
|
|
750
|
+
}) : null
|
|
751
|
+
};
|
|
752
|
+
}
|
|
753
|
+
};
|
|
754
|
+
}
|
|
755
|
+
function server_data_serializer_json(event, event_state, options2) {
|
|
756
|
+
let promise_id = 1;
|
|
757
|
+
const iterator = create_async_iterator();
|
|
758
|
+
const reducers = {
|
|
759
|
+
...Object.fromEntries(
|
|
760
|
+
Object.entries(options2.hooks.transport).map(([key2, value]) => [key2, value.encode])
|
|
761
|
+
),
|
|
762
|
+
/** @param {any} thing */
|
|
763
|
+
Promise: (thing) => {
|
|
764
|
+
if (typeof thing?.then !== "function") {
|
|
765
|
+
return;
|
|
766
|
+
}
|
|
767
|
+
const id = promise_id++;
|
|
768
|
+
let key2 = "data";
|
|
769
|
+
const promise = thing.catch(
|
|
770
|
+
/** @param {any} e */
|
|
771
|
+
async (e) => {
|
|
772
|
+
key2 = "error";
|
|
773
|
+
return handle_error_and_jsonify(
|
|
774
|
+
event,
|
|
775
|
+
event_state,
|
|
776
|
+
options2,
|
|
777
|
+
/** @type {any} */
|
|
778
|
+
e
|
|
779
|
+
);
|
|
780
|
+
}
|
|
781
|
+
).then(
|
|
782
|
+
/** @param {any} value */
|
|
783
|
+
async (value) => {
|
|
784
|
+
let str;
|
|
785
|
+
try {
|
|
786
|
+
str = devalue.stringify(value, reducers);
|
|
787
|
+
} catch {
|
|
788
|
+
const error2 = await handle_error_and_jsonify(
|
|
789
|
+
event,
|
|
790
|
+
event_state,
|
|
791
|
+
options2,
|
|
792
|
+
new Error(`Failed to serialize promise while rendering ${event.route.id}`)
|
|
793
|
+
);
|
|
794
|
+
key2 = "error";
|
|
795
|
+
str = devalue.stringify(error2, reducers);
|
|
796
|
+
}
|
|
797
|
+
return `{"type":"chunk","id":${id},"${key2}":${str}}
|
|
798
|
+
`;
|
|
799
|
+
}
|
|
800
|
+
);
|
|
801
|
+
iterator.add(promise);
|
|
802
|
+
return id;
|
|
803
|
+
}
|
|
804
|
+
};
|
|
805
|
+
const strings = (
|
|
806
|
+
/** @type {string[]} */
|
|
807
|
+
[]
|
|
808
|
+
);
|
|
809
|
+
return {
|
|
810
|
+
add_node(i, node) {
|
|
811
|
+
try {
|
|
812
|
+
if (!node) {
|
|
813
|
+
strings[i] = "null";
|
|
814
|
+
return;
|
|
815
|
+
}
|
|
816
|
+
if (node.type === "error" || node.type === "skip") {
|
|
817
|
+
strings[i] = JSON.stringify(node);
|
|
818
|
+
return;
|
|
819
|
+
}
|
|
820
|
+
strings[i] = `{"type":"data","data":${devalue.stringify(node.data, reducers)},"uses":${JSON.stringify(
|
|
821
|
+
serialize_uses(node)
|
|
822
|
+
)}${node.slash ? `,"slash":${JSON.stringify(node.slash)}` : ""}}`;
|
|
823
|
+
} catch (e) {
|
|
824
|
+
e.path = "data" + e.path;
|
|
825
|
+
throw new Error(clarify_devalue_error(
|
|
826
|
+
event,
|
|
827
|
+
/** @type {any} */
|
|
828
|
+
e
|
|
829
|
+
));
|
|
830
|
+
}
|
|
831
|
+
},
|
|
832
|
+
get_data() {
|
|
833
|
+
return {
|
|
834
|
+
data: `{"type":"data","nodes":[${strings.join(",")}]}
|
|
835
|
+
`,
|
|
836
|
+
chunks: promise_id > 1 ? iterator.iterate() : null
|
|
837
|
+
};
|
|
838
|
+
}
|
|
839
|
+
};
|
|
840
|
+
}
|
|
841
|
+
async function load_server_data({ event, event_state, state, node, parent }) {
|
|
842
|
+
if (!node?.server) return null;
|
|
843
|
+
let is_tracking = true;
|
|
844
|
+
const uses = {
|
|
845
|
+
dependencies: /* @__PURE__ */ new Set(),
|
|
846
|
+
params: /* @__PURE__ */ new Set(),
|
|
847
|
+
parent: false,
|
|
848
|
+
route: false,
|
|
849
|
+
url: false,
|
|
850
|
+
search_params: /* @__PURE__ */ new Set()
|
|
851
|
+
};
|
|
852
|
+
const load = node.server.load;
|
|
853
|
+
const slash = node.server.trailingSlash;
|
|
854
|
+
if (!load) {
|
|
855
|
+
return { type: "data", data: null, uses, slash };
|
|
856
|
+
}
|
|
857
|
+
const url = make_trackable(
|
|
858
|
+
event.url,
|
|
859
|
+
() => {
|
|
860
|
+
if (is_tracking) {
|
|
861
|
+
uses.url = true;
|
|
862
|
+
}
|
|
863
|
+
},
|
|
864
|
+
(param) => {
|
|
865
|
+
if (is_tracking) {
|
|
866
|
+
uses.search_params.add(param);
|
|
867
|
+
}
|
|
868
|
+
}
|
|
869
|
+
);
|
|
870
|
+
if (state.prerendering) {
|
|
871
|
+
disable_search(url);
|
|
872
|
+
}
|
|
873
|
+
const result = await record_span({
|
|
874
|
+
name: "sveltekit.load",
|
|
875
|
+
attributes: {
|
|
876
|
+
"sveltekit.load.node_id": node.server_id || "unknown",
|
|
877
|
+
"sveltekit.load.node_type": get_node_type(node.server_id),
|
|
878
|
+
"http.route": event.route.id || "unknown"
|
|
879
|
+
},
|
|
880
|
+
fn: async (current2) => {
|
|
881
|
+
const traced_event = merge_tracing(event, current2);
|
|
882
|
+
const result2 = await with_request_store(
|
|
883
|
+
{ event: traced_event, state: event_state },
|
|
884
|
+
() => load.call(null, {
|
|
885
|
+
...traced_event,
|
|
886
|
+
fetch: (info, init2) => {
|
|
887
|
+
new URL(info instanceof Request ? info.url : info, event.url);
|
|
888
|
+
return event.fetch(info, init2);
|
|
889
|
+
},
|
|
890
|
+
/** @param {string[]} deps */
|
|
891
|
+
depends: (...deps) => {
|
|
892
|
+
for (const dep of deps) {
|
|
893
|
+
const { href } = new URL(dep, event.url);
|
|
894
|
+
uses.dependencies.add(href);
|
|
895
|
+
}
|
|
896
|
+
},
|
|
897
|
+
params: new Proxy(event.params, {
|
|
898
|
+
get: (target, key2) => {
|
|
899
|
+
if (is_tracking) {
|
|
900
|
+
uses.params.add(key2);
|
|
901
|
+
}
|
|
902
|
+
return target[
|
|
903
|
+
/** @type {string} */
|
|
904
|
+
key2
|
|
905
|
+
];
|
|
906
|
+
}
|
|
907
|
+
}),
|
|
908
|
+
parent: async () => {
|
|
909
|
+
if (is_tracking) {
|
|
910
|
+
uses.parent = true;
|
|
911
|
+
}
|
|
912
|
+
return parent();
|
|
913
|
+
},
|
|
914
|
+
route: new Proxy(event.route, {
|
|
915
|
+
get: (target, key2) => {
|
|
916
|
+
if (is_tracking) {
|
|
917
|
+
uses.route = true;
|
|
918
|
+
}
|
|
919
|
+
return target[
|
|
920
|
+
/** @type {'id'} */
|
|
921
|
+
key2
|
|
922
|
+
];
|
|
923
|
+
}
|
|
924
|
+
}),
|
|
925
|
+
url,
|
|
926
|
+
untrack(fn) {
|
|
927
|
+
is_tracking = false;
|
|
928
|
+
try {
|
|
929
|
+
return fn();
|
|
930
|
+
} finally {
|
|
931
|
+
is_tracking = true;
|
|
932
|
+
}
|
|
933
|
+
}
|
|
934
|
+
})
|
|
935
|
+
);
|
|
936
|
+
return result2;
|
|
937
|
+
}
|
|
938
|
+
});
|
|
939
|
+
return {
|
|
940
|
+
type: "data",
|
|
941
|
+
data: result ?? null,
|
|
942
|
+
uses,
|
|
943
|
+
slash
|
|
944
|
+
};
|
|
945
|
+
}
|
|
946
|
+
async function load_data({
|
|
947
|
+
event,
|
|
948
|
+
event_state,
|
|
949
|
+
fetched,
|
|
950
|
+
node,
|
|
951
|
+
parent,
|
|
952
|
+
server_data_promise,
|
|
953
|
+
state,
|
|
954
|
+
resolve_opts,
|
|
955
|
+
csr
|
|
956
|
+
}) {
|
|
957
|
+
const server_data_node = await server_data_promise;
|
|
958
|
+
const load = node?.universal?.load;
|
|
959
|
+
if (!load) {
|
|
960
|
+
return server_data_node?.data ?? null;
|
|
961
|
+
}
|
|
962
|
+
const result = await record_span({
|
|
963
|
+
name: "sveltekit.load",
|
|
964
|
+
attributes: {
|
|
965
|
+
"sveltekit.load.node_id": node.universal_id || "unknown",
|
|
966
|
+
"sveltekit.load.node_type": get_node_type(node.universal_id),
|
|
967
|
+
"http.route": event.route.id || "unknown"
|
|
968
|
+
},
|
|
969
|
+
fn: async (current2) => {
|
|
970
|
+
const traced_event = merge_tracing(event, current2);
|
|
971
|
+
return await with_request_store(
|
|
972
|
+
{ event: traced_event, state: event_state },
|
|
973
|
+
() => load.call(null, {
|
|
974
|
+
url: event.url,
|
|
975
|
+
params: event.params,
|
|
976
|
+
data: server_data_node?.data ?? null,
|
|
977
|
+
route: event.route,
|
|
978
|
+
fetch: create_universal_fetch(event, state, fetched, csr, resolve_opts),
|
|
979
|
+
setHeaders: event.setHeaders,
|
|
980
|
+
depends: () => {
|
|
981
|
+
},
|
|
982
|
+
parent,
|
|
983
|
+
untrack: (fn) => fn(),
|
|
984
|
+
tracing: traced_event.tracing
|
|
985
|
+
})
|
|
986
|
+
);
|
|
987
|
+
}
|
|
988
|
+
});
|
|
989
|
+
return result ?? null;
|
|
990
|
+
}
|
|
991
|
+
function create_universal_fetch(event, state, fetched, csr, resolve_opts) {
|
|
992
|
+
const universal_fetch = async (input, init2) => {
|
|
993
|
+
const cloned_body = input instanceof Request && input.body ? input.clone().body : null;
|
|
994
|
+
const cloned_headers = input instanceof Request && [...input.headers].length ? new Headers(input.headers) : init2?.headers;
|
|
995
|
+
let response = await event.fetch(input, init2);
|
|
996
|
+
const url = new URL(input instanceof Request ? input.url : input, event.url);
|
|
997
|
+
const same_origin = url.origin === event.url.origin;
|
|
998
|
+
let dependency;
|
|
999
|
+
if (same_origin) {
|
|
1000
|
+
if (state.prerendering) {
|
|
1001
|
+
dependency = { response, body: null };
|
|
1002
|
+
state.prerendering.dependencies.set(url.pathname, dependency);
|
|
1003
|
+
}
|
|
1004
|
+
} else if (url.protocol === "https:" || url.protocol === "http:") {
|
|
1005
|
+
const mode = input instanceof Request ? input.mode : init2?.mode ?? "cors";
|
|
1006
|
+
if (mode === "no-cors") {
|
|
1007
|
+
response = new Response("", {
|
|
1008
|
+
status: response.status,
|
|
1009
|
+
statusText: response.statusText,
|
|
1010
|
+
headers: response.headers
|
|
1011
|
+
});
|
|
1012
|
+
} else {
|
|
1013
|
+
const acao = response.headers.get("access-control-allow-origin");
|
|
1014
|
+
if (!acao || acao !== event.url.origin && acao !== "*") {
|
|
1015
|
+
throw new Error(
|
|
1016
|
+
`CORS error: ${acao ? "Incorrect" : "No"} 'Access-Control-Allow-Origin' header is present on the requested resource`
|
|
1017
|
+
);
|
|
1018
|
+
}
|
|
1019
|
+
}
|
|
1020
|
+
}
|
|
1021
|
+
let teed_body;
|
|
1022
|
+
const proxy = new Proxy(response, {
|
|
1023
|
+
get(response2, key2, receiver) {
|
|
1024
|
+
async function push_fetched(body2, is_b64) {
|
|
1025
|
+
const status_number = Number(response2.status);
|
|
1026
|
+
if (isNaN(status_number)) {
|
|
1027
|
+
throw new Error(
|
|
1028
|
+
`response.status is not a number. value: "${response2.status}" type: ${typeof response2.status}`
|
|
1029
|
+
);
|
|
1030
|
+
}
|
|
1031
|
+
fetched.push({
|
|
1032
|
+
url: same_origin ? url.href.slice(event.url.origin.length) : url.href,
|
|
1033
|
+
method: event.request.method,
|
|
1034
|
+
request_body: (
|
|
1035
|
+
/** @type {string | ArrayBufferView | undefined} */
|
|
1036
|
+
input instanceof Request && cloned_body ? await stream_to_string(cloned_body) : init2?.body
|
|
1037
|
+
),
|
|
1038
|
+
request_headers: cloned_headers,
|
|
1039
|
+
response_body: body2,
|
|
1040
|
+
response: response2,
|
|
1041
|
+
is_b64
|
|
1042
|
+
});
|
|
1043
|
+
}
|
|
1044
|
+
if (key2 === "body") {
|
|
1045
|
+
if (response2.body === null) {
|
|
1046
|
+
return null;
|
|
1047
|
+
}
|
|
1048
|
+
if (teed_body) {
|
|
1049
|
+
return teed_body;
|
|
1050
|
+
}
|
|
1051
|
+
const [a, b] = response2.body.tee();
|
|
1052
|
+
void (async () => {
|
|
1053
|
+
let result = new Uint8Array();
|
|
1054
|
+
for await (const chunk of a) {
|
|
1055
|
+
const combined = new Uint8Array(result.length + chunk.length);
|
|
1056
|
+
combined.set(result, 0);
|
|
1057
|
+
combined.set(chunk, result.length);
|
|
1058
|
+
result = combined;
|
|
1059
|
+
}
|
|
1060
|
+
if (dependency) {
|
|
1061
|
+
dependency.body = new Uint8Array(result);
|
|
1062
|
+
}
|
|
1063
|
+
void push_fetched(base64_encode(result), true);
|
|
1064
|
+
})();
|
|
1065
|
+
return teed_body = b;
|
|
1066
|
+
}
|
|
1067
|
+
if (key2 === "arrayBuffer") {
|
|
1068
|
+
return async () => {
|
|
1069
|
+
const buffer = await response2.arrayBuffer();
|
|
1070
|
+
const bytes = new Uint8Array(buffer);
|
|
1071
|
+
if (dependency) {
|
|
1072
|
+
dependency.body = bytes;
|
|
1073
|
+
}
|
|
1074
|
+
if (buffer instanceof ArrayBuffer) {
|
|
1075
|
+
await push_fetched(base64_encode(bytes), true);
|
|
1076
|
+
}
|
|
1077
|
+
return buffer;
|
|
1078
|
+
};
|
|
1079
|
+
}
|
|
1080
|
+
async function text2() {
|
|
1081
|
+
const body2 = await response2.text();
|
|
1082
|
+
if (body2 === "" && NULL_BODY_STATUS.includes(response2.status)) {
|
|
1083
|
+
await push_fetched(void 0, false);
|
|
1084
|
+
return void 0;
|
|
1085
|
+
}
|
|
1086
|
+
if (!body2 || typeof body2 === "string") {
|
|
1087
|
+
await push_fetched(body2, false);
|
|
1088
|
+
}
|
|
1089
|
+
if (dependency) {
|
|
1090
|
+
dependency.body = body2;
|
|
1091
|
+
}
|
|
1092
|
+
return body2;
|
|
1093
|
+
}
|
|
1094
|
+
if (key2 === "text") {
|
|
1095
|
+
return text2;
|
|
1096
|
+
}
|
|
1097
|
+
if (key2 === "json") {
|
|
1098
|
+
return async () => {
|
|
1099
|
+
const body2 = await text2();
|
|
1100
|
+
return body2 ? JSON.parse(body2) : void 0;
|
|
1101
|
+
};
|
|
1102
|
+
}
|
|
1103
|
+
const value = Reflect.get(response2, key2, response2);
|
|
1104
|
+
if (value instanceof Function) {
|
|
1105
|
+
return Object.defineProperties(
|
|
1106
|
+
/**
|
|
1107
|
+
* @this {any}
|
|
1108
|
+
*/
|
|
1109
|
+
function() {
|
|
1110
|
+
return Reflect.apply(value, this === receiver ? response2 : this, arguments);
|
|
1111
|
+
},
|
|
1112
|
+
{
|
|
1113
|
+
name: { value: value.name },
|
|
1114
|
+
length: { value: value.length }
|
|
1115
|
+
}
|
|
1116
|
+
);
|
|
1117
|
+
}
|
|
1118
|
+
return value;
|
|
1119
|
+
}
|
|
1120
|
+
});
|
|
1121
|
+
if (csr) {
|
|
1122
|
+
const get = response.headers.get;
|
|
1123
|
+
response.headers.get = (key2) => {
|
|
1124
|
+
const lower = key2.toLowerCase();
|
|
1125
|
+
const value = get.call(response.headers, lower);
|
|
1126
|
+
if (value && !lower.startsWith("x-sveltekit-")) {
|
|
1127
|
+
const included = resolve_opts.filterSerializedResponseHeaders(lower, value);
|
|
1128
|
+
if (!included) {
|
|
1129
|
+
throw new Error(
|
|
1130
|
+
`Failed to get response header "${lower}" — it must be included by the \`filterSerializedResponseHeaders\` option: https://svelte.dev/docs/kit/hooks#Server-hooks-handle (at ${event.route.id})`
|
|
1131
|
+
);
|
|
1132
|
+
}
|
|
1133
|
+
}
|
|
1134
|
+
return value;
|
|
1135
|
+
};
|
|
1136
|
+
}
|
|
1137
|
+
return proxy;
|
|
1138
|
+
};
|
|
1139
|
+
return (input, init2) => {
|
|
1140
|
+
const response = universal_fetch(input, init2);
|
|
1141
|
+
response.catch(() => {
|
|
1142
|
+
});
|
|
1143
|
+
return response;
|
|
1144
|
+
};
|
|
1145
|
+
}
|
|
1146
|
+
async function stream_to_string(stream) {
|
|
1147
|
+
let result = "";
|
|
1148
|
+
const reader = stream.getReader();
|
|
1149
|
+
while (true) {
|
|
1150
|
+
const { done, value } = await reader.read();
|
|
1151
|
+
if (done) {
|
|
1152
|
+
break;
|
|
1153
|
+
}
|
|
1154
|
+
result += text_decoder.decode(value);
|
|
1155
|
+
}
|
|
1156
|
+
return result;
|
|
1157
|
+
}
|
|
1158
|
+
function hash(...values) {
|
|
1159
|
+
let hash2 = 5381;
|
|
1160
|
+
for (const value of values) {
|
|
1161
|
+
if (typeof value === "string") {
|
|
1162
|
+
let i = value.length;
|
|
1163
|
+
while (i) hash2 = hash2 * 33 ^ value.charCodeAt(--i);
|
|
1164
|
+
} else if (ArrayBuffer.isView(value)) {
|
|
1165
|
+
const buffer = new Uint8Array(value.buffer, value.byteOffset, value.byteLength);
|
|
1166
|
+
let i = buffer.length;
|
|
1167
|
+
while (i) hash2 = hash2 * 33 ^ buffer[--i];
|
|
1168
|
+
} else {
|
|
1169
|
+
throw new TypeError("value must be a string or TypedArray");
|
|
1170
|
+
}
|
|
1171
|
+
}
|
|
1172
|
+
return (hash2 >>> 0).toString(36);
|
|
1173
|
+
}
|
|
1174
|
+
const replacements = {
|
|
1175
|
+
"<": "\\u003C",
|
|
1176
|
+
"\u2028": "\\u2028",
|
|
1177
|
+
"\u2029": "\\u2029"
|
|
1178
|
+
};
|
|
1179
|
+
const pattern = new RegExp(`[${Object.keys(replacements).join("")}]`, "g");
|
|
1180
|
+
function serialize_data(fetched, filter, prerendering = false) {
|
|
1181
|
+
const headers2 = {};
|
|
1182
|
+
let cache_control = null;
|
|
1183
|
+
let age = null;
|
|
1184
|
+
let varyAny = false;
|
|
1185
|
+
for (const [key2, value] of fetched.response.headers) {
|
|
1186
|
+
if (filter(key2, value)) {
|
|
1187
|
+
headers2[key2] = value;
|
|
1188
|
+
}
|
|
1189
|
+
if (key2 === "cache-control") cache_control = value;
|
|
1190
|
+
else if (key2 === "age") age = value;
|
|
1191
|
+
else if (key2 === "vary" && value.trim() === "*") varyAny = true;
|
|
1192
|
+
}
|
|
1193
|
+
const payload = {
|
|
1194
|
+
status: fetched.response.status,
|
|
1195
|
+
statusText: fetched.response.statusText,
|
|
1196
|
+
headers: headers2,
|
|
1197
|
+
body: fetched.response_body
|
|
1198
|
+
};
|
|
1199
|
+
const safe_payload = JSON.stringify(payload).replace(pattern, (match) => replacements[match]);
|
|
1200
|
+
const attrs = [
|
|
1201
|
+
'type="application/json"',
|
|
1202
|
+
"data-sveltekit-fetched",
|
|
1203
|
+
`data-url="${escape_html(fetched.url, true)}"`
|
|
1204
|
+
];
|
|
1205
|
+
if (fetched.is_b64) {
|
|
1206
|
+
attrs.push("data-b64");
|
|
1207
|
+
}
|
|
1208
|
+
if (fetched.request_headers || fetched.request_body) {
|
|
1209
|
+
const values = [];
|
|
1210
|
+
if (fetched.request_headers) {
|
|
1211
|
+
values.push([...new Headers(fetched.request_headers)].join(","));
|
|
1212
|
+
}
|
|
1213
|
+
if (fetched.request_body) {
|
|
1214
|
+
values.push(fetched.request_body);
|
|
1215
|
+
}
|
|
1216
|
+
attrs.push(`data-hash="${hash(...values)}"`);
|
|
1217
|
+
}
|
|
1218
|
+
if (!prerendering && fetched.method === "GET" && cache_control && !varyAny) {
|
|
1219
|
+
const match = /s-maxage=(\d+)/g.exec(cache_control) ?? /max-age=(\d+)/g.exec(cache_control);
|
|
1220
|
+
if (match) {
|
|
1221
|
+
const ttl = +match[1] - +(age ?? "0");
|
|
1222
|
+
attrs.push(`data-ttl="${ttl}"`);
|
|
1223
|
+
}
|
|
1224
|
+
}
|
|
1225
|
+
return `<script ${attrs.join(" ")}>${safe_payload}<\/script>`;
|
|
1226
|
+
}
|
|
1227
|
+
const s = JSON.stringify;
|
|
1228
|
+
function sha256(data) {
|
|
1229
|
+
if (!key[0]) precompute();
|
|
1230
|
+
const out = init.slice(0);
|
|
1231
|
+
const array2 = encode(data);
|
|
1232
|
+
for (let i = 0; i < array2.length; i += 16) {
|
|
1233
|
+
const w = array2.subarray(i, i + 16);
|
|
1234
|
+
let tmp;
|
|
1235
|
+
let a;
|
|
1236
|
+
let b;
|
|
1237
|
+
let out0 = out[0];
|
|
1238
|
+
let out1 = out[1];
|
|
1239
|
+
let out2 = out[2];
|
|
1240
|
+
let out3 = out[3];
|
|
1241
|
+
let out4 = out[4];
|
|
1242
|
+
let out5 = out[5];
|
|
1243
|
+
let out6 = out[6];
|
|
1244
|
+
let out7 = out[7];
|
|
1245
|
+
for (let i2 = 0; i2 < 64; i2++) {
|
|
1246
|
+
if (i2 < 16) {
|
|
1247
|
+
tmp = w[i2];
|
|
1248
|
+
} else {
|
|
1249
|
+
a = w[i2 + 1 & 15];
|
|
1250
|
+
b = w[i2 + 14 & 15];
|
|
1251
|
+
tmp = w[i2 & 15] = (a >>> 7 ^ a >>> 18 ^ a >>> 3 ^ a << 25 ^ a << 14) + (b >>> 17 ^ b >>> 19 ^ b >>> 10 ^ b << 15 ^ b << 13) + w[i2 & 15] + w[i2 + 9 & 15] | 0;
|
|
1252
|
+
}
|
|
1253
|
+
tmp = tmp + out7 + (out4 >>> 6 ^ out4 >>> 11 ^ out4 >>> 25 ^ out4 << 26 ^ out4 << 21 ^ out4 << 7) + (out6 ^ out4 & (out5 ^ out6)) + key[i2];
|
|
1254
|
+
out7 = out6;
|
|
1255
|
+
out6 = out5;
|
|
1256
|
+
out5 = out4;
|
|
1257
|
+
out4 = out3 + tmp | 0;
|
|
1258
|
+
out3 = out2;
|
|
1259
|
+
out2 = out1;
|
|
1260
|
+
out1 = out0;
|
|
1261
|
+
out0 = tmp + (out1 & out2 ^ out3 & (out1 ^ out2)) + (out1 >>> 2 ^ out1 >>> 13 ^ out1 >>> 22 ^ out1 << 30 ^ out1 << 19 ^ out1 << 10) | 0;
|
|
1262
|
+
}
|
|
1263
|
+
out[0] = out[0] + out0 | 0;
|
|
1264
|
+
out[1] = out[1] + out1 | 0;
|
|
1265
|
+
out[2] = out[2] + out2 | 0;
|
|
1266
|
+
out[3] = out[3] + out3 | 0;
|
|
1267
|
+
out[4] = out[4] + out4 | 0;
|
|
1268
|
+
out[5] = out[5] + out5 | 0;
|
|
1269
|
+
out[6] = out[6] + out6 | 0;
|
|
1270
|
+
out[7] = out[7] + out7 | 0;
|
|
1271
|
+
}
|
|
1272
|
+
const bytes = new Uint8Array(out.buffer);
|
|
1273
|
+
reverse_endianness(bytes);
|
|
1274
|
+
return btoa(String.fromCharCode(...bytes));
|
|
1275
|
+
}
|
|
1276
|
+
const init = new Uint32Array(8);
|
|
1277
|
+
const key = new Uint32Array(64);
|
|
1278
|
+
function precompute() {
|
|
1279
|
+
function frac(x) {
|
|
1280
|
+
return (x - Math.floor(x)) * 4294967296;
|
|
1281
|
+
}
|
|
1282
|
+
let prime = 2;
|
|
1283
|
+
for (let i = 0; i < 64; prime++) {
|
|
1284
|
+
let is_prime = true;
|
|
1285
|
+
for (let factor = 2; factor * factor <= prime; factor++) {
|
|
1286
|
+
if (prime % factor === 0) {
|
|
1287
|
+
is_prime = false;
|
|
1288
|
+
break;
|
|
1289
|
+
}
|
|
1290
|
+
}
|
|
1291
|
+
if (is_prime) {
|
|
1292
|
+
if (i < 8) {
|
|
1293
|
+
init[i] = frac(prime ** (1 / 2));
|
|
1294
|
+
}
|
|
1295
|
+
key[i] = frac(prime ** (1 / 3));
|
|
1296
|
+
i++;
|
|
1297
|
+
}
|
|
1298
|
+
}
|
|
1299
|
+
}
|
|
1300
|
+
function reverse_endianness(bytes) {
|
|
1301
|
+
for (let i = 0; i < bytes.length; i += 4) {
|
|
1302
|
+
const a = bytes[i + 0];
|
|
1303
|
+
const b = bytes[i + 1];
|
|
1304
|
+
const c = bytes[i + 2];
|
|
1305
|
+
const d = bytes[i + 3];
|
|
1306
|
+
bytes[i + 0] = d;
|
|
1307
|
+
bytes[i + 1] = c;
|
|
1308
|
+
bytes[i + 2] = b;
|
|
1309
|
+
bytes[i + 3] = a;
|
|
1310
|
+
}
|
|
1311
|
+
}
|
|
1312
|
+
function encode(str) {
|
|
1313
|
+
const encoded = text_encoder.encode(str);
|
|
1314
|
+
const length = encoded.length * 8;
|
|
1315
|
+
const size = 512 * Math.ceil((length + 65) / 512);
|
|
1316
|
+
const bytes = new Uint8Array(size / 8);
|
|
1317
|
+
bytes.set(encoded);
|
|
1318
|
+
bytes[encoded.length] = 128;
|
|
1319
|
+
reverse_endianness(bytes);
|
|
1320
|
+
const words = new Uint32Array(bytes.buffer);
|
|
1321
|
+
words[words.length - 2] = Math.floor(length / 4294967296);
|
|
1322
|
+
words[words.length - 1] = length;
|
|
1323
|
+
return words;
|
|
1324
|
+
}
|
|
1325
|
+
const array = new Uint8Array(16);
|
|
1326
|
+
function generate_nonce() {
|
|
1327
|
+
crypto.getRandomValues(array);
|
|
1328
|
+
return btoa(String.fromCharCode(...array));
|
|
1329
|
+
}
|
|
1330
|
+
const quoted = /* @__PURE__ */ new Set([
|
|
1331
|
+
"self",
|
|
1332
|
+
"unsafe-eval",
|
|
1333
|
+
"unsafe-hashes",
|
|
1334
|
+
"unsafe-inline",
|
|
1335
|
+
"none",
|
|
1336
|
+
"strict-dynamic",
|
|
1337
|
+
"report-sample",
|
|
1338
|
+
"wasm-unsafe-eval",
|
|
1339
|
+
"script"
|
|
1340
|
+
]);
|
|
1341
|
+
const crypto_pattern = /^(nonce|sha\d\d\d)-/;
|
|
1342
|
+
class BaseProvider {
|
|
1343
|
+
/** @type {boolean} */
|
|
1344
|
+
#use_hashes;
|
|
1345
|
+
/** @type {boolean} */
|
|
1346
|
+
#script_needs_csp;
|
|
1347
|
+
/** @type {boolean} */
|
|
1348
|
+
#script_src_needs_csp;
|
|
1349
|
+
/** @type {boolean} */
|
|
1350
|
+
#script_src_elem_needs_csp;
|
|
1351
|
+
/** @type {boolean} */
|
|
1352
|
+
#style_needs_csp;
|
|
1353
|
+
/** @type {boolean} */
|
|
1354
|
+
#style_src_needs_csp;
|
|
1355
|
+
/** @type {boolean} */
|
|
1356
|
+
#style_src_attr_needs_csp;
|
|
1357
|
+
/** @type {boolean} */
|
|
1358
|
+
#style_src_elem_needs_csp;
|
|
1359
|
+
/** @type {import('types').CspDirectives} */
|
|
1360
|
+
#directives;
|
|
1361
|
+
/** @type {import('types').Csp.Source[]} */
|
|
1362
|
+
#script_src;
|
|
1363
|
+
/** @type {import('types').Csp.Source[]} */
|
|
1364
|
+
#script_src_elem;
|
|
1365
|
+
/** @type {import('types').Csp.Source[]} */
|
|
1366
|
+
#style_src;
|
|
1367
|
+
/** @type {import('types').Csp.Source[]} */
|
|
1368
|
+
#style_src_attr;
|
|
1369
|
+
/** @type {import('types').Csp.Source[]} */
|
|
1370
|
+
#style_src_elem;
|
|
1371
|
+
/** @type {string} */
|
|
1372
|
+
#nonce;
|
|
1373
|
+
/**
|
|
1374
|
+
* @param {boolean} use_hashes
|
|
1375
|
+
* @param {import('types').CspDirectives} directives
|
|
1376
|
+
* @param {string} nonce
|
|
1377
|
+
*/
|
|
1378
|
+
constructor(use_hashes, directives, nonce) {
|
|
1379
|
+
this.#use_hashes = use_hashes;
|
|
1380
|
+
this.#directives = directives;
|
|
1381
|
+
const d = this.#directives;
|
|
1382
|
+
this.#script_src = [];
|
|
1383
|
+
this.#script_src_elem = [];
|
|
1384
|
+
this.#style_src = [];
|
|
1385
|
+
this.#style_src_attr = [];
|
|
1386
|
+
this.#style_src_elem = [];
|
|
1387
|
+
const effective_script_src = d["script-src"] || d["default-src"];
|
|
1388
|
+
const script_src_elem = d["script-src-elem"];
|
|
1389
|
+
const effective_style_src = d["style-src"] || d["default-src"];
|
|
1390
|
+
const style_src_attr = d["style-src-attr"];
|
|
1391
|
+
const style_src_elem = d["style-src-elem"];
|
|
1392
|
+
const needs_csp = (directive) => !!directive && !directive.some((value) => value === "unsafe-inline");
|
|
1393
|
+
this.#script_src_needs_csp = needs_csp(effective_script_src);
|
|
1394
|
+
this.#script_src_elem_needs_csp = needs_csp(script_src_elem);
|
|
1395
|
+
this.#style_src_needs_csp = needs_csp(effective_style_src);
|
|
1396
|
+
this.#style_src_attr_needs_csp = needs_csp(style_src_attr);
|
|
1397
|
+
this.#style_src_elem_needs_csp = needs_csp(style_src_elem);
|
|
1398
|
+
this.#script_needs_csp = this.#script_src_needs_csp || this.#script_src_elem_needs_csp;
|
|
1399
|
+
this.#style_needs_csp = this.#style_src_needs_csp || this.#style_src_attr_needs_csp || this.#style_src_elem_needs_csp;
|
|
1400
|
+
this.script_needs_nonce = this.#script_needs_csp && !this.#use_hashes;
|
|
1401
|
+
this.style_needs_nonce = this.#style_needs_csp && !this.#use_hashes;
|
|
1402
|
+
this.#nonce = nonce;
|
|
1403
|
+
}
|
|
1404
|
+
/** @param {string} content */
|
|
1405
|
+
add_script(content) {
|
|
1406
|
+
if (!this.#script_needs_csp) return;
|
|
1407
|
+
const source = this.#use_hashes ? `sha256-${sha256(content)}` : `nonce-${this.#nonce}`;
|
|
1408
|
+
if (this.#script_src_needs_csp) {
|
|
1409
|
+
this.#script_src.push(source);
|
|
1410
|
+
}
|
|
1411
|
+
if (this.#script_src_elem_needs_csp) {
|
|
1412
|
+
this.#script_src_elem.push(source);
|
|
1413
|
+
}
|
|
1414
|
+
}
|
|
1415
|
+
/** @param {string} content */
|
|
1416
|
+
add_style(content) {
|
|
1417
|
+
if (!this.#style_needs_csp) return;
|
|
1418
|
+
const source = this.#use_hashes ? `sha256-${sha256(content)}` : `nonce-${this.#nonce}`;
|
|
1419
|
+
if (this.#style_src_needs_csp) {
|
|
1420
|
+
this.#style_src.push(source);
|
|
1421
|
+
}
|
|
1422
|
+
if (this.#style_src_attr_needs_csp) {
|
|
1423
|
+
this.#style_src_attr.push(source);
|
|
1424
|
+
}
|
|
1425
|
+
if (this.#style_src_elem_needs_csp) {
|
|
1426
|
+
const sha256_empty_comment_hash = "sha256-9OlNO0DNEeaVzHL4RZwCLsBHA8WBQ8toBp/4F5XV2nc=";
|
|
1427
|
+
const d = this.#directives;
|
|
1428
|
+
if (d["style-src-elem"] && !d["style-src-elem"].includes(sha256_empty_comment_hash) && !this.#style_src_elem.includes(sha256_empty_comment_hash)) {
|
|
1429
|
+
this.#style_src_elem.push(sha256_empty_comment_hash);
|
|
1430
|
+
}
|
|
1431
|
+
if (source !== sha256_empty_comment_hash) {
|
|
1432
|
+
this.#style_src_elem.push(source);
|
|
1433
|
+
}
|
|
1434
|
+
}
|
|
1435
|
+
}
|
|
1436
|
+
/**
|
|
1437
|
+
* @param {boolean} [is_meta]
|
|
1438
|
+
*/
|
|
1439
|
+
get_header(is_meta = false) {
|
|
1440
|
+
const header = [];
|
|
1441
|
+
const directives = { ...this.#directives };
|
|
1442
|
+
if (this.#style_src.length > 0) {
|
|
1443
|
+
directives["style-src"] = [
|
|
1444
|
+
...directives["style-src"] || directives["default-src"] || [],
|
|
1445
|
+
...this.#style_src
|
|
1446
|
+
];
|
|
1447
|
+
}
|
|
1448
|
+
if (this.#style_src_attr.length > 0) {
|
|
1449
|
+
directives["style-src-attr"] = [
|
|
1450
|
+
...directives["style-src-attr"] || [],
|
|
1451
|
+
...this.#style_src_attr
|
|
1452
|
+
];
|
|
1453
|
+
}
|
|
1454
|
+
if (this.#style_src_elem.length > 0) {
|
|
1455
|
+
directives["style-src-elem"] = [
|
|
1456
|
+
...directives["style-src-elem"] || [],
|
|
1457
|
+
...this.#style_src_elem
|
|
1458
|
+
];
|
|
1459
|
+
}
|
|
1460
|
+
if (this.#script_src.length > 0) {
|
|
1461
|
+
directives["script-src"] = [
|
|
1462
|
+
...directives["script-src"] || directives["default-src"] || [],
|
|
1463
|
+
...this.#script_src
|
|
1464
|
+
];
|
|
1465
|
+
}
|
|
1466
|
+
if (this.#script_src_elem.length > 0) {
|
|
1467
|
+
directives["script-src-elem"] = [
|
|
1468
|
+
...directives["script-src-elem"] || [],
|
|
1469
|
+
...this.#script_src_elem
|
|
1470
|
+
];
|
|
1471
|
+
}
|
|
1472
|
+
for (const key2 in directives) {
|
|
1473
|
+
if (is_meta && (key2 === "frame-ancestors" || key2 === "report-uri" || key2 === "sandbox")) {
|
|
1474
|
+
continue;
|
|
1475
|
+
}
|
|
1476
|
+
const value = (
|
|
1477
|
+
/** @type {string[] | true} */
|
|
1478
|
+
directives[key2]
|
|
1479
|
+
);
|
|
1480
|
+
if (!value) continue;
|
|
1481
|
+
const directive = [key2];
|
|
1482
|
+
if (Array.isArray(value)) {
|
|
1483
|
+
value.forEach((value2) => {
|
|
1484
|
+
if (quoted.has(value2) || crypto_pattern.test(value2)) {
|
|
1485
|
+
directive.push(`'${value2}'`);
|
|
1486
|
+
} else {
|
|
1487
|
+
directive.push(value2);
|
|
1488
|
+
}
|
|
1489
|
+
});
|
|
1490
|
+
}
|
|
1491
|
+
header.push(directive.join(" "));
|
|
1492
|
+
}
|
|
1493
|
+
return header.join("; ");
|
|
1494
|
+
}
|
|
1495
|
+
}
|
|
1496
|
+
class CspProvider extends BaseProvider {
|
|
1497
|
+
get_meta() {
|
|
1498
|
+
const content = this.get_header(true);
|
|
1499
|
+
if (!content) {
|
|
1500
|
+
return;
|
|
1501
|
+
}
|
|
1502
|
+
return `<meta http-equiv="content-security-policy" content="${escape_html(content, true)}">`;
|
|
1503
|
+
}
|
|
1504
|
+
}
|
|
1505
|
+
class CspReportOnlyProvider extends BaseProvider {
|
|
1506
|
+
/**
|
|
1507
|
+
* @param {boolean} use_hashes
|
|
1508
|
+
* @param {import('types').CspDirectives} directives
|
|
1509
|
+
* @param {string} nonce
|
|
1510
|
+
*/
|
|
1511
|
+
constructor(use_hashes, directives, nonce) {
|
|
1512
|
+
super(use_hashes, directives, nonce);
|
|
1513
|
+
if (Object.values(directives).filter((v) => !!v).length > 0) {
|
|
1514
|
+
const has_report_to = directives["report-to"]?.length ?? 0 > 0;
|
|
1515
|
+
const has_report_uri = directives["report-uri"]?.length ?? 0 > 0;
|
|
1516
|
+
if (!has_report_to && !has_report_uri) {
|
|
1517
|
+
throw Error(
|
|
1518
|
+
"`content-security-policy-report-only` must be specified with either the `report-to` or `report-uri` directives, or both"
|
|
1519
|
+
);
|
|
1520
|
+
}
|
|
1521
|
+
}
|
|
1522
|
+
}
|
|
1523
|
+
}
|
|
1524
|
+
class Csp {
|
|
1525
|
+
/** @readonly */
|
|
1526
|
+
nonce = generate_nonce();
|
|
1527
|
+
/** @type {CspProvider} */
|
|
1528
|
+
csp_provider;
|
|
1529
|
+
/** @type {CspReportOnlyProvider} */
|
|
1530
|
+
report_only_provider;
|
|
1531
|
+
/**
|
|
1532
|
+
* @param {import('./types.js').CspConfig} config
|
|
1533
|
+
* @param {import('./types.js').CspOpts} opts
|
|
1534
|
+
*/
|
|
1535
|
+
constructor({ mode, directives, reportOnly }, { prerender }) {
|
|
1536
|
+
const use_hashes = mode === "hash" || mode === "auto" && prerender;
|
|
1537
|
+
this.csp_provider = new CspProvider(use_hashes, directives, this.nonce);
|
|
1538
|
+
this.report_only_provider = new CspReportOnlyProvider(use_hashes, reportOnly, this.nonce);
|
|
1539
|
+
}
|
|
1540
|
+
get script_needs_nonce() {
|
|
1541
|
+
return this.csp_provider.script_needs_nonce || this.report_only_provider.script_needs_nonce;
|
|
1542
|
+
}
|
|
1543
|
+
get style_needs_nonce() {
|
|
1544
|
+
return this.csp_provider.style_needs_nonce || this.report_only_provider.style_needs_nonce;
|
|
1545
|
+
}
|
|
1546
|
+
/** @param {string} content */
|
|
1547
|
+
add_script(content) {
|
|
1548
|
+
this.csp_provider.add_script(content);
|
|
1549
|
+
this.report_only_provider.add_script(content);
|
|
1550
|
+
}
|
|
1551
|
+
/** @param {string} content */
|
|
1552
|
+
add_style(content) {
|
|
1553
|
+
this.csp_provider.add_style(content);
|
|
1554
|
+
this.report_only_provider.add_style(content);
|
|
1555
|
+
}
|
|
1556
|
+
}
|
|
1557
|
+
function exec(match, params, matchers) {
|
|
1558
|
+
const result = {};
|
|
1559
|
+
const values = match.slice(1);
|
|
1560
|
+
const values_needing_match = values.filter((value) => value !== void 0);
|
|
1561
|
+
let buffered = 0;
|
|
1562
|
+
for (let i = 0; i < params.length; i += 1) {
|
|
1563
|
+
const param = params[i];
|
|
1564
|
+
let value = values[i - buffered];
|
|
1565
|
+
if (param.chained && param.rest && buffered) {
|
|
1566
|
+
value = values.slice(i - buffered, i + 1).filter((s2) => s2).join("/");
|
|
1567
|
+
buffered = 0;
|
|
1568
|
+
}
|
|
1569
|
+
if (value === void 0) {
|
|
1570
|
+
if (param.rest) result[param.name] = "";
|
|
1571
|
+
continue;
|
|
1572
|
+
}
|
|
1573
|
+
if (!param.matcher || matchers[param.matcher](value)) {
|
|
1574
|
+
result[param.name] = value;
|
|
1575
|
+
const next_param = params[i + 1];
|
|
1576
|
+
const next_value = values[i + 1];
|
|
1577
|
+
if (next_param && !next_param.rest && next_param.optional && next_value && param.chained) {
|
|
1578
|
+
buffered = 0;
|
|
1579
|
+
}
|
|
1580
|
+
if (!next_param && !next_value && Object.keys(result).length === values_needing_match.length) {
|
|
1581
|
+
buffered = 0;
|
|
1582
|
+
}
|
|
1583
|
+
continue;
|
|
1584
|
+
}
|
|
1585
|
+
if (param.optional && param.chained) {
|
|
1586
|
+
buffered++;
|
|
1587
|
+
continue;
|
|
1588
|
+
}
|
|
1589
|
+
return;
|
|
1590
|
+
}
|
|
1591
|
+
if (buffered) return;
|
|
1592
|
+
return result;
|
|
1593
|
+
}
|
|
1594
|
+
function generate_route_object(route, url, manifest) {
|
|
1595
|
+
const { errors, layouts, leaf } = route;
|
|
1596
|
+
const nodes = [...errors, ...layouts.map((l) => l?.[1]), leaf[1]].filter((n) => typeof n === "number").map((n) => `'${n}': () => ${create_client_import(manifest._.client.nodes?.[n], url)}`).join(",\n ");
|
|
1597
|
+
return [
|
|
1598
|
+
`{
|
|
1599
|
+
id: ${s(route.id)}`,
|
|
1600
|
+
`errors: ${s(route.errors)}`,
|
|
1601
|
+
`layouts: ${s(route.layouts)}`,
|
|
1602
|
+
`leaf: ${s(route.leaf)}`,
|
|
1603
|
+
`nodes: {
|
|
1604
|
+
${nodes}
|
|
1605
|
+
}
|
|
1606
|
+
}`
|
|
1607
|
+
].join(",\n ");
|
|
1608
|
+
}
|
|
1609
|
+
function create_client_import(import_path, url) {
|
|
1610
|
+
if (!import_path) return "Promise.resolve({})";
|
|
1611
|
+
if (import_path[0] === "/") {
|
|
1612
|
+
return `import('${import_path}')`;
|
|
1613
|
+
}
|
|
1614
|
+
if (assets !== "") {
|
|
1615
|
+
return `import('${assets}/${import_path}')`;
|
|
1616
|
+
}
|
|
1617
|
+
let path = get_relative_path(url.pathname, `${base}/${import_path}`);
|
|
1618
|
+
if (path[0] !== ".") path = `./${path}`;
|
|
1619
|
+
return `import('${path}')`;
|
|
1620
|
+
}
|
|
1621
|
+
async function resolve_route(resolved_path, url, manifest) {
|
|
1622
|
+
if (!manifest._.client.routes) {
|
|
1623
|
+
return text("Server-side route resolution disabled", { status: 400 });
|
|
1624
|
+
}
|
|
1625
|
+
let route = null;
|
|
1626
|
+
let params = {};
|
|
1627
|
+
const matchers = await manifest._.matchers();
|
|
1628
|
+
for (const candidate of manifest._.client.routes) {
|
|
1629
|
+
const match = candidate.pattern.exec(resolved_path);
|
|
1630
|
+
if (!match) continue;
|
|
1631
|
+
const matched = exec(match, candidate.params, matchers);
|
|
1632
|
+
if (matched) {
|
|
1633
|
+
route = candidate;
|
|
1634
|
+
params = decode_params(matched);
|
|
1635
|
+
break;
|
|
1636
|
+
}
|
|
1637
|
+
}
|
|
1638
|
+
return create_server_routing_response(route, params, url, manifest).response;
|
|
1639
|
+
}
|
|
1640
|
+
function create_server_routing_response(route, params, url, manifest) {
|
|
1641
|
+
const headers2 = new Headers({
|
|
1642
|
+
"content-type": "application/javascript; charset=utf-8"
|
|
1643
|
+
});
|
|
1644
|
+
if (route) {
|
|
1645
|
+
const csr_route = generate_route_object(route, url, manifest);
|
|
1646
|
+
const body2 = `${create_css_import(route, url, manifest)}
|
|
1647
|
+
export const route = ${csr_route}; export const params = ${JSON.stringify(params)};`;
|
|
1648
|
+
return { response: text(body2, { headers: headers2 }), body: body2 };
|
|
1649
|
+
} else {
|
|
1650
|
+
return { response: text("", { headers: headers2 }), body: "" };
|
|
1651
|
+
}
|
|
1652
|
+
}
|
|
1653
|
+
function create_css_import(route, url, manifest) {
|
|
1654
|
+
const { errors, layouts, leaf } = route;
|
|
1655
|
+
let css = "";
|
|
1656
|
+
for (const node of [...errors, ...layouts.map((l) => l?.[1]), leaf[1]]) {
|
|
1657
|
+
if (typeof node !== "number") continue;
|
|
1658
|
+
const node_css = manifest._.client.css?.[node];
|
|
1659
|
+
for (const css_path of node_css ?? []) {
|
|
1660
|
+
css += `'${assets || base}/${css_path}',`;
|
|
1661
|
+
}
|
|
1662
|
+
}
|
|
1663
|
+
if (!css) return "";
|
|
1664
|
+
return `${create_client_import(
|
|
1665
|
+
/** @type {string} */
|
|
1666
|
+
manifest._.client.start,
|
|
1667
|
+
url
|
|
1668
|
+
)}.then(x => x.load_css([${css}]));`;
|
|
1669
|
+
}
|
|
1670
|
+
const updated = {
|
|
1671
|
+
...readable(false),
|
|
1672
|
+
check: () => false
|
|
1673
|
+
};
|
|
1674
|
+
async function render_response({
|
|
1675
|
+
branch,
|
|
1676
|
+
fetched,
|
|
1677
|
+
options: options2,
|
|
1678
|
+
manifest,
|
|
1679
|
+
state,
|
|
1680
|
+
page_config,
|
|
1681
|
+
status,
|
|
1682
|
+
error: error2 = null,
|
|
1683
|
+
event,
|
|
1684
|
+
event_state,
|
|
1685
|
+
resolve_opts,
|
|
1686
|
+
action_result,
|
|
1687
|
+
data_serializer
|
|
1688
|
+
}) {
|
|
1689
|
+
if (state.prerendering) {
|
|
1690
|
+
if (options2.csp.mode === "nonce") {
|
|
1691
|
+
throw new Error('Cannot use prerendering if config.kit.csp.mode === "nonce"');
|
|
1692
|
+
}
|
|
1693
|
+
if (options2.app_template_contains_nonce) {
|
|
1694
|
+
throw new Error("Cannot use prerendering if page template contains %sveltekit.nonce%");
|
|
1695
|
+
}
|
|
1696
|
+
}
|
|
1697
|
+
const { client } = manifest._;
|
|
1698
|
+
const modulepreloads = new Set(client.imports);
|
|
1699
|
+
const stylesheets = new Set(client.stylesheets);
|
|
1700
|
+
const fonts = new Set(client.fonts);
|
|
1701
|
+
const link_headers = /* @__PURE__ */ new Set();
|
|
1702
|
+
const link_tags = /* @__PURE__ */ new Set();
|
|
1703
|
+
const inline_styles = /* @__PURE__ */ new Map();
|
|
1704
|
+
let rendered;
|
|
1705
|
+
const form_value = action_result?.type === "success" || action_result?.type === "failure" ? action_result.data ?? null : null;
|
|
1706
|
+
let base$1 = base;
|
|
1707
|
+
let assets$1 = assets;
|
|
1708
|
+
let base_expression = s(base);
|
|
1709
|
+
{
|
|
1710
|
+
if (!state.prerendering?.fallback) {
|
|
1711
|
+
const segments = event.url.pathname.slice(base.length).split("/").slice(2);
|
|
1712
|
+
base$1 = segments.map(() => "..").join("/") || ".";
|
|
1713
|
+
base_expression = `new URL(${s(base$1)}, location).pathname.slice(0, -1)`;
|
|
1714
|
+
if (!assets || assets[0] === "/" && assets !== SVELTE_KIT_ASSETS) {
|
|
1715
|
+
assets$1 = base$1;
|
|
1716
|
+
}
|
|
1717
|
+
} else if (options2.hash_routing) {
|
|
1718
|
+
base_expression = "new URL('.', location).pathname.slice(0, -1)";
|
|
1719
|
+
}
|
|
1720
|
+
}
|
|
1721
|
+
if (page_config.ssr) {
|
|
1722
|
+
const props = {
|
|
1723
|
+
stores: {
|
|
1724
|
+
page: writable(null),
|
|
1725
|
+
navigating: writable(null),
|
|
1726
|
+
updated
|
|
1727
|
+
},
|
|
1728
|
+
constructors: await Promise.all(
|
|
1729
|
+
branch.map(({ node }) => {
|
|
1730
|
+
if (!node.component) {
|
|
1731
|
+
throw new Error(`Missing +page.svelte component for route ${event.route.id}`);
|
|
1732
|
+
}
|
|
1733
|
+
return node.component();
|
|
1734
|
+
})
|
|
1735
|
+
),
|
|
1736
|
+
form: form_value
|
|
1737
|
+
};
|
|
1738
|
+
let data2 = {};
|
|
1739
|
+
for (let i = 0; i < branch.length; i += 1) {
|
|
1740
|
+
data2 = { ...data2, ...branch[i].data };
|
|
1741
|
+
props[`data_${i}`] = data2;
|
|
1742
|
+
}
|
|
1743
|
+
props.page = {
|
|
1744
|
+
error: error2,
|
|
1745
|
+
params: (
|
|
1746
|
+
/** @type {Record<string, any>} */
|
|
1747
|
+
event.params
|
|
1748
|
+
),
|
|
1749
|
+
route: event.route,
|
|
1750
|
+
status,
|
|
1751
|
+
url: event.url,
|
|
1752
|
+
data: data2,
|
|
1753
|
+
form: form_value,
|
|
1754
|
+
state: {}
|
|
1755
|
+
};
|
|
1756
|
+
const render_opts = {
|
|
1757
|
+
context: /* @__PURE__ */ new Map([
|
|
1758
|
+
[
|
|
1759
|
+
"__request__",
|
|
1760
|
+
{
|
|
1761
|
+
page: props.page
|
|
1762
|
+
}
|
|
1763
|
+
]
|
|
1764
|
+
])
|
|
1765
|
+
};
|
|
1766
|
+
const fetch2 = globalThis.fetch;
|
|
1767
|
+
try {
|
|
1768
|
+
if (BROWSER) ;
|
|
1769
|
+
rendered = await with_request_store({ event, state: event_state }, async () => {
|
|
1770
|
+
if (relative) override({ base: base$1, assets: assets$1 });
|
|
1771
|
+
const maybe_promise = options2.root.render(props, render_opts);
|
|
1772
|
+
const rendered2 = options2.async && "then" in maybe_promise ? (
|
|
1773
|
+
/** @type {ReturnType<typeof options.root.render> & Promise<any>} */
|
|
1774
|
+
maybe_promise.then((r) => r)
|
|
1775
|
+
) : maybe_promise;
|
|
1776
|
+
if (options2.async) {
|
|
1777
|
+
reset();
|
|
1778
|
+
}
|
|
1779
|
+
const { head: head2, html: html2, css } = options2.async ? await rendered2 : rendered2;
|
|
1780
|
+
return { head: head2, html: html2, css };
|
|
1781
|
+
});
|
|
1782
|
+
} finally {
|
|
1783
|
+
reset();
|
|
1784
|
+
}
|
|
1785
|
+
for (const { node } of branch) {
|
|
1786
|
+
for (const url of node.imports) modulepreloads.add(url);
|
|
1787
|
+
for (const url of node.stylesheets) stylesheets.add(url);
|
|
1788
|
+
for (const url of node.fonts) fonts.add(url);
|
|
1789
|
+
if (node.inline_styles && !client.inline) {
|
|
1790
|
+
Object.entries(await node.inline_styles()).forEach(([k, v]) => inline_styles.set(k, v));
|
|
1791
|
+
}
|
|
1792
|
+
}
|
|
1793
|
+
} else {
|
|
1794
|
+
rendered = { head: "", html: "", css: { code: "", map: null } };
|
|
1795
|
+
}
|
|
1796
|
+
let head = "";
|
|
1797
|
+
let body2 = rendered.html;
|
|
1798
|
+
const csp = new Csp(options2.csp, {
|
|
1799
|
+
prerender: !!state.prerendering
|
|
1800
|
+
});
|
|
1801
|
+
const prefixed = (path) => {
|
|
1802
|
+
if (path.startsWith("/")) {
|
|
1803
|
+
return base + path;
|
|
1804
|
+
}
|
|
1805
|
+
return `${assets$1}/${path}`;
|
|
1806
|
+
};
|
|
1807
|
+
const style = client.inline ? client.inline?.style : Array.from(inline_styles.values()).join("\n");
|
|
1808
|
+
if (style) {
|
|
1809
|
+
const attributes = [];
|
|
1810
|
+
if (csp.style_needs_nonce) attributes.push(` nonce="${csp.nonce}"`);
|
|
1811
|
+
csp.add_style(style);
|
|
1812
|
+
head += `
|
|
1813
|
+
<style${attributes.join("")}>${style}</style>`;
|
|
1814
|
+
}
|
|
1815
|
+
for (const dep of stylesheets) {
|
|
1816
|
+
const path = prefixed(dep);
|
|
1817
|
+
const attributes = ['rel="stylesheet"'];
|
|
1818
|
+
if (inline_styles.has(dep)) {
|
|
1819
|
+
attributes.push("disabled", 'media="(max-width: 0)"');
|
|
1820
|
+
} else {
|
|
1821
|
+
if (resolve_opts.preload({ type: "css", path })) {
|
|
1822
|
+
link_headers.add(`<${encodeURI(path)}>; rel="preload"; as="style"; nopush`);
|
|
1823
|
+
}
|
|
1824
|
+
}
|
|
1825
|
+
head += `
|
|
1826
|
+
<link href="${path}" ${attributes.join(" ")}>`;
|
|
1827
|
+
}
|
|
1828
|
+
for (const dep of fonts) {
|
|
1829
|
+
const path = prefixed(dep);
|
|
1830
|
+
if (resolve_opts.preload({ type: "font", path })) {
|
|
1831
|
+
const ext = dep.slice(dep.lastIndexOf(".") + 1);
|
|
1832
|
+
link_tags.add(`<link rel="preload" as="font" type="font/${ext}" href="${path}" crossorigin>`);
|
|
1833
|
+
link_headers.add(
|
|
1834
|
+
`<${encodeURI(path)}>; rel="preload"; as="font"; type="font/${ext}"; crossorigin; nopush`
|
|
1835
|
+
);
|
|
1836
|
+
}
|
|
1837
|
+
}
|
|
1838
|
+
const global = get_global_name(options2);
|
|
1839
|
+
const { data, chunks } = data_serializer.get_data(csp);
|
|
1840
|
+
if (page_config.ssr && page_config.csr) {
|
|
1841
|
+
body2 += `
|
|
1842
|
+
${fetched.map(
|
|
1843
|
+
(item) => serialize_data(item, resolve_opts.filterSerializedResponseHeaders, !!state.prerendering)
|
|
1844
|
+
).join("\n ")}`;
|
|
1845
|
+
}
|
|
1846
|
+
if (page_config.csr) {
|
|
1847
|
+
const route = manifest._.client.routes?.find((r) => r.id === event.route.id) ?? null;
|
|
1848
|
+
if (client.uses_env_dynamic_public && state.prerendering) {
|
|
1849
|
+
modulepreloads.add(`${app_dir}/env.js`);
|
|
1850
|
+
}
|
|
1851
|
+
if (!client.inline) {
|
|
1852
|
+
const included_modulepreloads = Array.from(modulepreloads, (dep) => prefixed(dep)).filter(
|
|
1853
|
+
(path) => resolve_opts.preload({ type: "js", path })
|
|
1854
|
+
);
|
|
1855
|
+
for (const path of included_modulepreloads) {
|
|
1856
|
+
link_headers.add(`<${encodeURI(path)}>; rel="modulepreload"; nopush`);
|
|
1857
|
+
if (options2.preload_strategy !== "modulepreload") {
|
|
1858
|
+
head += `
|
|
1859
|
+
<link rel="preload" as="script" crossorigin="anonymous" href="${path}">`;
|
|
1860
|
+
} else {
|
|
1861
|
+
link_tags.add(`<link rel="modulepreload" href="${path}">`);
|
|
1862
|
+
}
|
|
1863
|
+
}
|
|
1864
|
+
}
|
|
1865
|
+
if (state.prerendering && link_tags.size > 0) {
|
|
1866
|
+
head += Array.from(link_tags).map((tag) => `
|
|
1867
|
+
${tag}`).join("");
|
|
1868
|
+
}
|
|
1869
|
+
if (manifest._.client.routes && state.prerendering && !state.prerendering.fallback) {
|
|
1870
|
+
const pathname = add_resolution_suffix(event.url.pathname);
|
|
1871
|
+
state.prerendering.dependencies.set(
|
|
1872
|
+
pathname,
|
|
1873
|
+
create_server_routing_response(route, event.params, new URL(pathname, event.url), manifest)
|
|
1874
|
+
);
|
|
1875
|
+
}
|
|
1876
|
+
const blocks = [];
|
|
1877
|
+
const load_env_eagerly = client.uses_env_dynamic_public && state.prerendering;
|
|
1878
|
+
const properties = [`base: ${base_expression}`];
|
|
1879
|
+
if (assets) {
|
|
1880
|
+
properties.push(`assets: ${s(assets)}`);
|
|
1881
|
+
}
|
|
1882
|
+
if (client.uses_env_dynamic_public) {
|
|
1883
|
+
properties.push(`env: ${load_env_eagerly ? "null" : s(public_env)}`);
|
|
1884
|
+
}
|
|
1885
|
+
if (chunks) {
|
|
1886
|
+
blocks.push("const deferred = new Map();");
|
|
1887
|
+
properties.push(`defer: (id) => new Promise((fulfil, reject) => {
|
|
1888
|
+
deferred.set(id, { fulfil, reject });
|
|
1889
|
+
})`);
|
|
1890
|
+
let app_declaration = "";
|
|
1891
|
+
if (Object.keys(options2.hooks.transport).length > 0) {
|
|
1892
|
+
if (client.inline) {
|
|
1893
|
+
app_declaration = `const app = __sveltekit_${options2.version_hash}.app.app;`;
|
|
1894
|
+
} else if (client.app) {
|
|
1895
|
+
app_declaration = `const app = await import(${s(prefixed(client.app))});`;
|
|
1896
|
+
} else {
|
|
1897
|
+
app_declaration = `const { app } = await import(${s(prefixed(client.start))});`;
|
|
1898
|
+
}
|
|
1899
|
+
}
|
|
1900
|
+
const prelude = app_declaration ? `${app_declaration}
|
|
1901
|
+
const [data, error] = fn(app);` : `const [data, error] = fn();`;
|
|
1902
|
+
properties.push(`resolve: async (id, fn) => {
|
|
1903
|
+
${prelude}
|
|
1904
|
+
|
|
1905
|
+
const try_to_resolve = () => {
|
|
1906
|
+
if (!deferred.has(id)) {
|
|
1907
|
+
setTimeout(try_to_resolve, 0);
|
|
1908
|
+
return;
|
|
1909
|
+
}
|
|
1910
|
+
const { fulfil, reject } = deferred.get(id);
|
|
1911
|
+
deferred.delete(id);
|
|
1912
|
+
if (error) reject(error);
|
|
1913
|
+
else fulfil(data);
|
|
1914
|
+
}
|
|
1915
|
+
try_to_resolve();
|
|
1916
|
+
}`);
|
|
1917
|
+
}
|
|
1918
|
+
blocks.push(`${global} = {
|
|
1919
|
+
${properties.join(",\n ")}
|
|
1920
|
+
};`);
|
|
1921
|
+
const args = ["element"];
|
|
1922
|
+
blocks.push("const element = document.currentScript.parentElement;");
|
|
1923
|
+
if (page_config.ssr) {
|
|
1924
|
+
const serialized = { form: "null", error: "null" };
|
|
1925
|
+
if (form_value) {
|
|
1926
|
+
serialized.form = uneval_action_response(
|
|
1927
|
+
form_value,
|
|
1928
|
+
/** @type {string} */
|
|
1929
|
+
event.route.id,
|
|
1930
|
+
options2.hooks.transport
|
|
1931
|
+
);
|
|
1932
|
+
}
|
|
1933
|
+
if (error2) {
|
|
1934
|
+
serialized.error = devalue.uneval(error2);
|
|
1935
|
+
}
|
|
1936
|
+
const hydrate = [
|
|
1937
|
+
`node_ids: [${branch.map(({ node }) => node.index).join(", ")}]`,
|
|
1938
|
+
`data: ${data}`,
|
|
1939
|
+
`form: ${serialized.form}`,
|
|
1940
|
+
`error: ${serialized.error}`
|
|
1941
|
+
];
|
|
1942
|
+
if (status !== 200) {
|
|
1943
|
+
hydrate.push(`status: ${status}`);
|
|
1944
|
+
}
|
|
1945
|
+
if (manifest._.client.routes) {
|
|
1946
|
+
if (route) {
|
|
1947
|
+
const stringified = generate_route_object(route, event.url, manifest).replaceAll(
|
|
1948
|
+
"\n",
|
|
1949
|
+
"\n "
|
|
1950
|
+
);
|
|
1951
|
+
hydrate.push(`params: ${devalue.uneval(event.params)}`, `server_route: ${stringified}`);
|
|
1952
|
+
}
|
|
1953
|
+
} else if (options2.embedded) {
|
|
1954
|
+
hydrate.push(`params: ${devalue.uneval(event.params)}`, `route: ${s(event.route)}`);
|
|
1955
|
+
}
|
|
1956
|
+
const indent = " ".repeat(load_env_eagerly ? 7 : 6);
|
|
1957
|
+
args.push(`{
|
|
1958
|
+
${indent} ${hydrate.join(`,
|
|
1959
|
+
${indent} `)}
|
|
1960
|
+
${indent}}`);
|
|
1961
|
+
}
|
|
1962
|
+
const { remote_data: remote_cache } = event_state;
|
|
1963
|
+
let serialized_remote_data = "";
|
|
1964
|
+
if (remote_cache) {
|
|
1965
|
+
const remote = {};
|
|
1966
|
+
for (const [info, cache] of remote_cache) {
|
|
1967
|
+
if (!info.id) continue;
|
|
1968
|
+
for (const key2 in cache) {
|
|
1969
|
+
remote[create_remote_key(info.id, key2)] = await cache[key2];
|
|
1970
|
+
}
|
|
1971
|
+
}
|
|
1972
|
+
const replacer = (thing) => {
|
|
1973
|
+
for (const key2 in options2.hooks.transport) {
|
|
1974
|
+
const encoded = options2.hooks.transport[key2].encode(thing);
|
|
1975
|
+
if (encoded) {
|
|
1976
|
+
return `app.decode('${key2}', ${devalue.uneval(encoded, replacer)})`;
|
|
1977
|
+
}
|
|
1978
|
+
}
|
|
1979
|
+
};
|
|
1980
|
+
serialized_remote_data = `${global}.data = ${devalue.uneval(remote, replacer)};
|
|
1981
|
+
|
|
1982
|
+
`;
|
|
1983
|
+
}
|
|
1984
|
+
const boot = client.inline ? `${client.inline.script}
|
|
1985
|
+
|
|
1986
|
+
${serialized_remote_data}${global}.app.start(${args.join(", ")});` : client.app ? `Promise.all([
|
|
1987
|
+
import(${s(prefixed(client.start))}),
|
|
1988
|
+
import(${s(prefixed(client.app))})
|
|
1989
|
+
]).then(([kit, app]) => {
|
|
1990
|
+
${serialized_remote_data}kit.start(app, ${args.join(", ")});
|
|
1991
|
+
});` : `import(${s(prefixed(client.start))}).then((app) => {
|
|
1992
|
+
${serialized_remote_data}app.start(${args.join(", ")})
|
|
1993
|
+
});`;
|
|
1994
|
+
if (load_env_eagerly) {
|
|
1995
|
+
blocks.push(`import(${s(`${base$1}/${app_dir}/env.js`)}).then(({ env }) => {
|
|
1996
|
+
${global}.env = env;
|
|
1997
|
+
|
|
1998
|
+
${boot.replace(/\n/g, "\n ")}
|
|
1999
|
+
});`);
|
|
2000
|
+
} else {
|
|
2001
|
+
blocks.push(boot);
|
|
2002
|
+
}
|
|
2003
|
+
if (options2.service_worker) {
|
|
2004
|
+
let opts = "";
|
|
2005
|
+
if (options2.service_worker_options != null) {
|
|
2006
|
+
const service_worker_options = { ...options2.service_worker_options };
|
|
2007
|
+
opts = `, ${s(service_worker_options)}`;
|
|
2008
|
+
}
|
|
2009
|
+
blocks.push(`if ('serviceWorker' in navigator) {
|
|
2010
|
+
addEventListener('load', function () {
|
|
2011
|
+
navigator.serviceWorker.register('${prefixed("service-worker.js")}'${opts});
|
|
2012
|
+
});
|
|
2013
|
+
}`);
|
|
2014
|
+
}
|
|
2015
|
+
const init_app = `
|
|
2016
|
+
{
|
|
2017
|
+
${blocks.join("\n\n ")}
|
|
2018
|
+
}
|
|
2019
|
+
`;
|
|
2020
|
+
csp.add_script(init_app);
|
|
2021
|
+
body2 += `
|
|
2022
|
+
<script${csp.script_needs_nonce ? ` nonce="${csp.nonce}"` : ""}>${init_app}<\/script>
|
|
2023
|
+
`;
|
|
2024
|
+
}
|
|
2025
|
+
const headers2 = new Headers({
|
|
2026
|
+
"x-sveltekit-page": "true",
|
|
2027
|
+
"content-type": "text/html"
|
|
2028
|
+
});
|
|
2029
|
+
if (state.prerendering) {
|
|
2030
|
+
const http_equiv = [];
|
|
2031
|
+
const csp_headers = csp.csp_provider.get_meta();
|
|
2032
|
+
if (csp_headers) {
|
|
2033
|
+
http_equiv.push(csp_headers);
|
|
2034
|
+
}
|
|
2035
|
+
if (state.prerendering.cache) {
|
|
2036
|
+
http_equiv.push(`<meta http-equiv="cache-control" content="${state.prerendering.cache}">`);
|
|
2037
|
+
}
|
|
2038
|
+
if (http_equiv.length > 0) {
|
|
2039
|
+
head = http_equiv.join("\n") + head;
|
|
2040
|
+
}
|
|
2041
|
+
} else {
|
|
2042
|
+
const csp_header = csp.csp_provider.get_header();
|
|
2043
|
+
if (csp_header) {
|
|
2044
|
+
headers2.set("content-security-policy", csp_header);
|
|
2045
|
+
}
|
|
2046
|
+
const report_only_header = csp.report_only_provider.get_header();
|
|
2047
|
+
if (report_only_header) {
|
|
2048
|
+
headers2.set("content-security-policy-report-only", report_only_header);
|
|
2049
|
+
}
|
|
2050
|
+
if (link_headers.size) {
|
|
2051
|
+
headers2.set("link", Array.from(link_headers).join(", "));
|
|
2052
|
+
}
|
|
2053
|
+
}
|
|
2054
|
+
head += rendered.head;
|
|
2055
|
+
const html = options2.templates.app({
|
|
2056
|
+
head,
|
|
2057
|
+
body: body2,
|
|
2058
|
+
assets: assets$1,
|
|
2059
|
+
nonce: (
|
|
2060
|
+
/** @type {string} */
|
|
2061
|
+
csp.nonce
|
|
2062
|
+
),
|
|
2063
|
+
env: public_env
|
|
2064
|
+
});
|
|
2065
|
+
const transformed = await resolve_opts.transformPageChunk({
|
|
2066
|
+
html,
|
|
2067
|
+
done: true
|
|
2068
|
+
}) || "";
|
|
2069
|
+
if (!chunks) {
|
|
2070
|
+
headers2.set("etag", `"${hash(transformed)}"`);
|
|
2071
|
+
}
|
|
2072
|
+
return !chunks ? text(transformed, {
|
|
2073
|
+
status,
|
|
2074
|
+
headers: headers2
|
|
2075
|
+
}) : new Response(
|
|
2076
|
+
new ReadableStream({
|
|
2077
|
+
async start(controller) {
|
|
2078
|
+
controller.enqueue(text_encoder.encode(transformed + "\n"));
|
|
2079
|
+
for await (const chunk of chunks) {
|
|
2080
|
+
if (chunk.length) controller.enqueue(text_encoder.encode(chunk));
|
|
2081
|
+
}
|
|
2082
|
+
controller.close();
|
|
2083
|
+
},
|
|
2084
|
+
type: "bytes"
|
|
2085
|
+
}),
|
|
2086
|
+
{
|
|
2087
|
+
headers: headers2
|
|
2088
|
+
}
|
|
2089
|
+
);
|
|
2090
|
+
}
|
|
2091
|
+
class PageNodes {
|
|
2092
|
+
data;
|
|
2093
|
+
/**
|
|
2094
|
+
* @param {Array<import('types').SSRNode | undefined>} nodes
|
|
2095
|
+
*/
|
|
2096
|
+
constructor(nodes) {
|
|
2097
|
+
this.data = nodes;
|
|
2098
|
+
}
|
|
2099
|
+
layouts() {
|
|
2100
|
+
return this.data.slice(0, -1);
|
|
2101
|
+
}
|
|
2102
|
+
page() {
|
|
2103
|
+
return this.data.at(-1);
|
|
2104
|
+
}
|
|
2105
|
+
validate() {
|
|
2106
|
+
for (const layout of this.layouts()) {
|
|
2107
|
+
if (layout) {
|
|
2108
|
+
validate_layout_server_exports(
|
|
2109
|
+
layout.server,
|
|
2110
|
+
/** @type {string} */
|
|
2111
|
+
layout.server_id
|
|
2112
|
+
);
|
|
2113
|
+
validate_layout_exports(
|
|
2114
|
+
layout.universal,
|
|
2115
|
+
/** @type {string} */
|
|
2116
|
+
layout.universal_id
|
|
2117
|
+
);
|
|
2118
|
+
}
|
|
2119
|
+
}
|
|
2120
|
+
const page = this.page();
|
|
2121
|
+
if (page) {
|
|
2122
|
+
validate_page_server_exports(
|
|
2123
|
+
page.server,
|
|
2124
|
+
/** @type {string} */
|
|
2125
|
+
page.server_id
|
|
2126
|
+
);
|
|
2127
|
+
validate_page_exports(
|
|
2128
|
+
page.universal,
|
|
2129
|
+
/** @type {string} */
|
|
2130
|
+
page.universal_id
|
|
2131
|
+
);
|
|
2132
|
+
}
|
|
2133
|
+
}
|
|
2134
|
+
/**
|
|
2135
|
+
* @template {'prerender' | 'ssr' | 'csr' | 'trailingSlash'} Option
|
|
2136
|
+
* @param {Option} option
|
|
2137
|
+
* @returns {Value | undefined}
|
|
2138
|
+
*/
|
|
2139
|
+
#get_option(option) {
|
|
2140
|
+
return this.data.reduce(
|
|
2141
|
+
(value, node) => {
|
|
2142
|
+
return node?.universal?.[option] ?? node?.server?.[option] ?? value;
|
|
2143
|
+
},
|
|
2144
|
+
/** @type {Value | undefined} */
|
|
2145
|
+
void 0
|
|
2146
|
+
);
|
|
2147
|
+
}
|
|
2148
|
+
csr() {
|
|
2149
|
+
return this.#get_option("csr") ?? true;
|
|
2150
|
+
}
|
|
2151
|
+
ssr() {
|
|
2152
|
+
return this.#get_option("ssr") ?? true;
|
|
2153
|
+
}
|
|
2154
|
+
prerender() {
|
|
2155
|
+
return this.#get_option("prerender") ?? false;
|
|
2156
|
+
}
|
|
2157
|
+
trailing_slash() {
|
|
2158
|
+
return this.#get_option("trailingSlash") ?? "never";
|
|
2159
|
+
}
|
|
2160
|
+
get_config() {
|
|
2161
|
+
let current2 = {};
|
|
2162
|
+
for (const node of this.data) {
|
|
2163
|
+
if (!node?.universal?.config && !node?.server?.config) continue;
|
|
2164
|
+
current2 = {
|
|
2165
|
+
...current2,
|
|
2166
|
+
// TODO: should we override the server config value with the universal value similar to other page options?
|
|
2167
|
+
...node?.universal?.config,
|
|
2168
|
+
...node?.server?.config
|
|
2169
|
+
};
|
|
2170
|
+
}
|
|
2171
|
+
return Object.keys(current2).length ? current2 : void 0;
|
|
2172
|
+
}
|
|
2173
|
+
should_prerender_data() {
|
|
2174
|
+
return this.data.some(
|
|
2175
|
+
// prerender in case of trailingSlash because the client retrieves that value from the server
|
|
2176
|
+
(node) => node?.server?.load || node?.server?.trailingSlash !== void 0
|
|
2177
|
+
);
|
|
2178
|
+
}
|
|
2179
|
+
}
|
|
2180
|
+
async function respond_with_error({
|
|
2181
|
+
event,
|
|
2182
|
+
event_state,
|
|
2183
|
+
options: options2,
|
|
2184
|
+
manifest,
|
|
2185
|
+
state,
|
|
2186
|
+
status,
|
|
2187
|
+
error: error2,
|
|
2188
|
+
resolve_opts
|
|
2189
|
+
}) {
|
|
2190
|
+
if (event.request.headers.get("x-sveltekit-error")) {
|
|
2191
|
+
return static_error_page(
|
|
2192
|
+
options2,
|
|
2193
|
+
status,
|
|
2194
|
+
/** @type {Error} */
|
|
2195
|
+
error2.message
|
|
2196
|
+
);
|
|
2197
|
+
}
|
|
2198
|
+
const fetched = [];
|
|
2199
|
+
try {
|
|
2200
|
+
const branch = [];
|
|
2201
|
+
const default_layout = await manifest._.nodes[0]();
|
|
2202
|
+
const nodes = new PageNodes([default_layout]);
|
|
2203
|
+
const ssr = nodes.ssr();
|
|
2204
|
+
const csr = nodes.csr();
|
|
2205
|
+
const data_serializer = server_data_serializer(event, event_state, options2);
|
|
2206
|
+
if (ssr) {
|
|
2207
|
+
state.error = true;
|
|
2208
|
+
const server_data_promise = load_server_data({
|
|
2209
|
+
event,
|
|
2210
|
+
event_state,
|
|
2211
|
+
state,
|
|
2212
|
+
node: default_layout,
|
|
2213
|
+
// eslint-disable-next-line @typescript-eslint/require-await
|
|
2214
|
+
parent: async () => ({})
|
|
2215
|
+
});
|
|
2216
|
+
const server_data = await server_data_promise;
|
|
2217
|
+
data_serializer.add_node(0, server_data);
|
|
2218
|
+
const data = await load_data({
|
|
2219
|
+
event,
|
|
2220
|
+
event_state,
|
|
2221
|
+
fetched,
|
|
2222
|
+
node: default_layout,
|
|
2223
|
+
// eslint-disable-next-line @typescript-eslint/require-await
|
|
2224
|
+
parent: async () => ({}),
|
|
2225
|
+
resolve_opts,
|
|
2226
|
+
server_data_promise,
|
|
2227
|
+
state,
|
|
2228
|
+
csr
|
|
2229
|
+
});
|
|
2230
|
+
branch.push(
|
|
2231
|
+
{
|
|
2232
|
+
node: default_layout,
|
|
2233
|
+
server_data,
|
|
2234
|
+
data
|
|
2235
|
+
},
|
|
2236
|
+
{
|
|
2237
|
+
node: await manifest._.nodes[1](),
|
|
2238
|
+
// 1 is always the root error
|
|
2239
|
+
data: null,
|
|
2240
|
+
server_data: null
|
|
2241
|
+
}
|
|
2242
|
+
);
|
|
2243
|
+
}
|
|
2244
|
+
return await render_response({
|
|
2245
|
+
options: options2,
|
|
2246
|
+
manifest,
|
|
2247
|
+
state,
|
|
2248
|
+
page_config: {
|
|
2249
|
+
ssr,
|
|
2250
|
+
csr
|
|
2251
|
+
},
|
|
2252
|
+
status,
|
|
2253
|
+
error: await handle_error_and_jsonify(event, event_state, options2, error2),
|
|
2254
|
+
branch,
|
|
2255
|
+
fetched,
|
|
2256
|
+
event,
|
|
2257
|
+
event_state,
|
|
2258
|
+
resolve_opts,
|
|
2259
|
+
data_serializer
|
|
2260
|
+
});
|
|
2261
|
+
} catch (e) {
|
|
2262
|
+
if (e instanceof Redirect) {
|
|
2263
|
+
return redirect_response(e.status, e.location);
|
|
2264
|
+
}
|
|
2265
|
+
return static_error_page(
|
|
2266
|
+
options2,
|
|
2267
|
+
get_status(e),
|
|
2268
|
+
(await handle_error_and_jsonify(event, event_state, options2, e)).message
|
|
2269
|
+
);
|
|
2270
|
+
}
|
|
2271
|
+
}
|
|
2272
|
+
async function handle_remote_call(event, state, options2, manifest, id) {
|
|
2273
|
+
return record_span({
|
|
2274
|
+
name: "sveltekit.remote.call",
|
|
2275
|
+
attributes: {},
|
|
2276
|
+
fn: (current2) => {
|
|
2277
|
+
const traced_event = merge_tracing(event, current2);
|
|
2278
|
+
return with_request_store(
|
|
2279
|
+
{ event: traced_event, state },
|
|
2280
|
+
() => handle_remote_call_internal(traced_event, state, options2, manifest, id)
|
|
2281
|
+
);
|
|
2282
|
+
}
|
|
2283
|
+
});
|
|
2284
|
+
}
|
|
2285
|
+
async function handle_remote_call_internal(event, state, options2, manifest, id) {
|
|
2286
|
+
const [hash2, name, additional_args] = id.split("/");
|
|
2287
|
+
const remotes = manifest._.remotes;
|
|
2288
|
+
if (!remotes[hash2]) error(404);
|
|
2289
|
+
const module = await remotes[hash2]();
|
|
2290
|
+
const fn = module.default[name];
|
|
2291
|
+
if (!fn) error(404);
|
|
2292
|
+
const info = fn.__;
|
|
2293
|
+
const transport = options2.hooks.transport;
|
|
2294
|
+
event.tracing.current.setAttributes({
|
|
2295
|
+
"sveltekit.remote.call.type": info.type,
|
|
2296
|
+
"sveltekit.remote.call.name": info.name
|
|
2297
|
+
});
|
|
2298
|
+
let form_client_refreshes;
|
|
2299
|
+
try {
|
|
2300
|
+
if (info.type === "query_batch") {
|
|
2301
|
+
if (event.request.method !== "POST") {
|
|
2302
|
+
throw new SvelteKitError(
|
|
2303
|
+
405,
|
|
2304
|
+
"Method Not Allowed",
|
|
2305
|
+
`\`query.batch\` functions must be invoked via POST request, not ${event.request.method}`
|
|
2306
|
+
);
|
|
2307
|
+
}
|
|
2308
|
+
const { payloads } = await event.request.json();
|
|
2309
|
+
const args = payloads.map((payload2) => parse_remote_arg(payload2, transport));
|
|
2310
|
+
const get_result = await with_request_store({ event, state }, () => info.run(args));
|
|
2311
|
+
const results = await Promise.all(
|
|
2312
|
+
args.map(async (arg, i) => {
|
|
2313
|
+
try {
|
|
2314
|
+
return { type: "result", data: get_result(arg, i) };
|
|
2315
|
+
} catch (error2) {
|
|
2316
|
+
return {
|
|
2317
|
+
type: "error",
|
|
2318
|
+
error: await handle_error_and_jsonify(event, state, options2, error2),
|
|
2319
|
+
status: error2 instanceof HttpError || error2 instanceof SvelteKitError ? error2.status : 500
|
|
2320
|
+
};
|
|
2321
|
+
}
|
|
2322
|
+
})
|
|
2323
|
+
);
|
|
2324
|
+
return json(
|
|
2325
|
+
/** @type {RemoteFunctionResponse} */
|
|
2326
|
+
{
|
|
2327
|
+
type: "result",
|
|
2328
|
+
result: stringify(results, transport)
|
|
2329
|
+
}
|
|
2330
|
+
);
|
|
2331
|
+
}
|
|
2332
|
+
if (info.type === "form") {
|
|
2333
|
+
if (event.request.method !== "POST") {
|
|
2334
|
+
throw new SvelteKitError(
|
|
2335
|
+
405,
|
|
2336
|
+
"Method Not Allowed",
|
|
2337
|
+
`\`form\` functions must be invoked via POST request, not ${event.request.method}`
|
|
2338
|
+
);
|
|
2339
|
+
}
|
|
2340
|
+
if (!is_form_content_type(event.request)) {
|
|
2341
|
+
throw new SvelteKitError(
|
|
2342
|
+
415,
|
|
2343
|
+
"Unsupported Media Type",
|
|
2344
|
+
`\`form\` functions expect form-encoded data — received ${event.request.headers.get(
|
|
2345
|
+
"content-type"
|
|
2346
|
+
)}`
|
|
2347
|
+
);
|
|
2348
|
+
}
|
|
2349
|
+
const { data: data2, meta, form_data } = await deserialize_binary_form(event.request);
|
|
2350
|
+
if (additional_args && !("id" in data2)) {
|
|
2351
|
+
data2.id = JSON.parse(decodeURIComponent(additional_args));
|
|
2352
|
+
}
|
|
2353
|
+
const fn2 = info.fn;
|
|
2354
|
+
const result = await with_request_store({ event, state }, () => fn2(data2, meta, form_data));
|
|
2355
|
+
return json(
|
|
2356
|
+
/** @type {RemoteFunctionResponse} */
|
|
2357
|
+
{
|
|
2358
|
+
type: "result",
|
|
2359
|
+
result: stringify(result, transport),
|
|
2360
|
+
refreshes: result.issues ? void 0 : await serialize_refreshes(meta.remote_refreshes)
|
|
2361
|
+
}
|
|
2362
|
+
);
|
|
2363
|
+
}
|
|
2364
|
+
if (info.type === "command") {
|
|
2365
|
+
const { payload: payload2, refreshes } = await event.request.json();
|
|
2366
|
+
const arg = parse_remote_arg(payload2, transport);
|
|
2367
|
+
const data2 = await with_request_store({ event, state }, () => fn(arg));
|
|
2368
|
+
return json(
|
|
2369
|
+
/** @type {RemoteFunctionResponse} */
|
|
2370
|
+
{
|
|
2371
|
+
type: "result",
|
|
2372
|
+
result: stringify(data2, transport),
|
|
2373
|
+
refreshes: await serialize_refreshes(refreshes)
|
|
2374
|
+
}
|
|
2375
|
+
);
|
|
2376
|
+
}
|
|
2377
|
+
const payload = info.type === "prerender" ? additional_args : (
|
|
2378
|
+
/** @type {string} */
|
|
2379
|
+
// new URL(...) necessary because we're hiding the URL from the user in the event object
|
|
2380
|
+
new URL(event.request.url).searchParams.get("payload")
|
|
2381
|
+
);
|
|
2382
|
+
const data = await with_request_store(
|
|
2383
|
+
{ event, state },
|
|
2384
|
+
() => fn(parse_remote_arg(payload, transport))
|
|
2385
|
+
);
|
|
2386
|
+
return json(
|
|
2387
|
+
/** @type {RemoteFunctionResponse} */
|
|
2388
|
+
{
|
|
2389
|
+
type: "result",
|
|
2390
|
+
result: stringify(data, transport)
|
|
2391
|
+
}
|
|
2392
|
+
);
|
|
2393
|
+
} catch (error2) {
|
|
2394
|
+
if (error2 instanceof Redirect) {
|
|
2395
|
+
return json(
|
|
2396
|
+
/** @type {RemoteFunctionResponse} */
|
|
2397
|
+
{
|
|
2398
|
+
type: "redirect",
|
|
2399
|
+
location: error2.location,
|
|
2400
|
+
refreshes: await serialize_refreshes(form_client_refreshes)
|
|
2401
|
+
}
|
|
2402
|
+
);
|
|
2403
|
+
}
|
|
2404
|
+
const status = error2 instanceof HttpError || error2 instanceof SvelteKitError ? error2.status : 500;
|
|
2405
|
+
return json(
|
|
2406
|
+
/** @type {RemoteFunctionResponse} */
|
|
2407
|
+
{
|
|
2408
|
+
type: "error",
|
|
2409
|
+
error: await handle_error_and_jsonify(event, state, options2, error2),
|
|
2410
|
+
status
|
|
2411
|
+
},
|
|
2412
|
+
{
|
|
2413
|
+
// By setting a non-200 during prerendering we fail the prerender process (unless handleHttpError handles it).
|
|
2414
|
+
// Errors at runtime will be passed to the client and are handled there
|
|
2415
|
+
status: state.prerendering ? status : void 0,
|
|
2416
|
+
headers: {
|
|
2417
|
+
"cache-control": "private, no-store"
|
|
2418
|
+
}
|
|
2419
|
+
}
|
|
2420
|
+
);
|
|
2421
|
+
}
|
|
2422
|
+
async function serialize_refreshes(client_refreshes) {
|
|
2423
|
+
const refreshes = state.refreshes ?? {};
|
|
2424
|
+
if (client_refreshes) {
|
|
2425
|
+
for (const key2 of client_refreshes) {
|
|
2426
|
+
if (refreshes[key2] !== void 0) continue;
|
|
2427
|
+
const [hash3, name2, payload] = key2.split("/");
|
|
2428
|
+
const loader = manifest._.remotes[hash3];
|
|
2429
|
+
const fn2 = (await loader?.())?.default?.[name2];
|
|
2430
|
+
if (!fn2) error(400, "Bad Request");
|
|
2431
|
+
refreshes[key2] = with_request_store(
|
|
2432
|
+
{ event, state },
|
|
2433
|
+
() => fn2(parse_remote_arg(payload, transport))
|
|
2434
|
+
);
|
|
2435
|
+
}
|
|
2436
|
+
}
|
|
2437
|
+
if (Object.keys(refreshes).length === 0) {
|
|
2438
|
+
return void 0;
|
|
2439
|
+
}
|
|
2440
|
+
return stringify(
|
|
2441
|
+
Object.fromEntries(
|
|
2442
|
+
await Promise.all(
|
|
2443
|
+
Object.entries(refreshes).map(async ([key2, promise]) => [key2, await promise])
|
|
2444
|
+
)
|
|
2445
|
+
),
|
|
2446
|
+
transport
|
|
2447
|
+
);
|
|
2448
|
+
}
|
|
2449
|
+
}
|
|
2450
|
+
async function handle_remote_form_post(event, state, manifest, id) {
|
|
2451
|
+
return record_span({
|
|
2452
|
+
name: "sveltekit.remote.form.post",
|
|
2453
|
+
attributes: {},
|
|
2454
|
+
fn: (current2) => {
|
|
2455
|
+
const traced_event = merge_tracing(event, current2);
|
|
2456
|
+
return with_request_store(
|
|
2457
|
+
{ event: traced_event, state },
|
|
2458
|
+
() => handle_remote_form_post_internal(traced_event, state, manifest, id)
|
|
2459
|
+
);
|
|
2460
|
+
}
|
|
2461
|
+
});
|
|
2462
|
+
}
|
|
2463
|
+
async function handle_remote_form_post_internal(event, state, manifest, id) {
|
|
2464
|
+
const [hash2, name, action_id] = id.split("/");
|
|
2465
|
+
const remotes = manifest._.remotes;
|
|
2466
|
+
const module = await remotes[hash2]?.();
|
|
2467
|
+
let form = (
|
|
2468
|
+
/** @type {RemoteForm<any, any>} */
|
|
2469
|
+
module?.default[name]
|
|
2470
|
+
);
|
|
2471
|
+
if (!form) {
|
|
2472
|
+
event.setHeaders({
|
|
2473
|
+
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/405
|
|
2474
|
+
// "The server must generate an Allow header field in a 405 status code response"
|
|
2475
|
+
allow: "GET"
|
|
2476
|
+
});
|
|
2477
|
+
return {
|
|
2478
|
+
type: "error",
|
|
2479
|
+
error: new SvelteKitError(
|
|
2480
|
+
405,
|
|
2481
|
+
"Method Not Allowed",
|
|
2482
|
+
`POST method not allowed. No form actions exist for ${"this page"}`
|
|
2483
|
+
)
|
|
2484
|
+
};
|
|
2485
|
+
}
|
|
2486
|
+
if (action_id) {
|
|
2487
|
+
form = with_request_store({ event, state }, () => form.for(JSON.parse(action_id)));
|
|
2488
|
+
}
|
|
2489
|
+
try {
|
|
2490
|
+
const fn = (
|
|
2491
|
+
/** @type {RemoteInfo & { type: 'form' }} */
|
|
2492
|
+
/** @type {any} */
|
|
2493
|
+
form.__.fn
|
|
2494
|
+
);
|
|
2495
|
+
const { data, meta, form_data } = await deserialize_binary_form(event.request);
|
|
2496
|
+
if (action_id && !("id" in data)) {
|
|
2497
|
+
data.id = JSON.parse(decodeURIComponent(action_id));
|
|
2498
|
+
}
|
|
2499
|
+
await with_request_store({ event, state }, () => fn(data, meta, form_data));
|
|
2500
|
+
return {
|
|
2501
|
+
type: "success",
|
|
2502
|
+
status: 200
|
|
2503
|
+
};
|
|
2504
|
+
} catch (e) {
|
|
2505
|
+
const err = normalize_error(e);
|
|
2506
|
+
if (err instanceof Redirect) {
|
|
2507
|
+
return {
|
|
2508
|
+
type: "redirect",
|
|
2509
|
+
status: err.status,
|
|
2510
|
+
location: err.location
|
|
2511
|
+
};
|
|
2512
|
+
}
|
|
2513
|
+
return {
|
|
2514
|
+
type: "error",
|
|
2515
|
+
error: check_incorrect_fail_use(err)
|
|
2516
|
+
};
|
|
2517
|
+
}
|
|
2518
|
+
}
|
|
2519
|
+
function get_remote_id(url) {
|
|
2520
|
+
return url.pathname.startsWith(`${base}/${app_dir}/remote/`) && url.pathname.replace(`${base}/${app_dir}/remote/`, "");
|
|
2521
|
+
}
|
|
2522
|
+
function get_remote_action(url) {
|
|
2523
|
+
return url.searchParams.get("/remote");
|
|
2524
|
+
}
|
|
2525
|
+
const MAX_DEPTH = 10;
|
|
2526
|
+
async function render_page(event, event_state, page, options2, manifest, state, nodes, resolve_opts) {
|
|
2527
|
+
if (state.depth > MAX_DEPTH) {
|
|
2528
|
+
return text(`Not found: ${event.url.pathname}`, {
|
|
2529
|
+
status: 404
|
|
2530
|
+
// TODO in some cases this should be 500. not sure how to differentiate
|
|
2531
|
+
});
|
|
2532
|
+
}
|
|
2533
|
+
if (is_action_json_request(event)) {
|
|
2534
|
+
const node = await manifest._.nodes[page.leaf]();
|
|
2535
|
+
return handle_action_json_request(event, event_state, options2, node?.server);
|
|
2536
|
+
}
|
|
2537
|
+
try {
|
|
2538
|
+
const leaf_node = (
|
|
2539
|
+
/** @type {import('types').SSRNode} */
|
|
2540
|
+
nodes.page()
|
|
2541
|
+
);
|
|
2542
|
+
let status = 200;
|
|
2543
|
+
let action_result = void 0;
|
|
2544
|
+
if (is_action_request(event)) {
|
|
2545
|
+
const remote_id = get_remote_action(event.url);
|
|
2546
|
+
if (remote_id) {
|
|
2547
|
+
action_result = await handle_remote_form_post(event, event_state, manifest, remote_id);
|
|
2548
|
+
} else {
|
|
2549
|
+
action_result = await handle_action_request(event, event_state, leaf_node.server);
|
|
2550
|
+
}
|
|
2551
|
+
if (action_result?.type === "redirect") {
|
|
2552
|
+
return redirect_response(action_result.status, action_result.location);
|
|
2553
|
+
}
|
|
2554
|
+
if (action_result?.type === "error") {
|
|
2555
|
+
status = get_status(action_result.error);
|
|
2556
|
+
}
|
|
2557
|
+
if (action_result?.type === "failure") {
|
|
2558
|
+
status = action_result.status;
|
|
2559
|
+
}
|
|
2560
|
+
}
|
|
2561
|
+
const should_prerender = nodes.prerender();
|
|
2562
|
+
if (should_prerender) {
|
|
2563
|
+
const mod = leaf_node.server;
|
|
2564
|
+
if (mod?.actions) {
|
|
2565
|
+
throw new Error("Cannot prerender pages with actions");
|
|
2566
|
+
}
|
|
2567
|
+
} else if (state.prerendering) {
|
|
2568
|
+
return new Response(void 0, {
|
|
2569
|
+
status: 204
|
|
2570
|
+
});
|
|
2571
|
+
}
|
|
2572
|
+
state.prerender_default = should_prerender;
|
|
2573
|
+
const should_prerender_data = nodes.should_prerender_data();
|
|
2574
|
+
const data_pathname = add_data_suffix(event.url.pathname);
|
|
2575
|
+
const fetched = [];
|
|
2576
|
+
const ssr = nodes.ssr();
|
|
2577
|
+
const csr = nodes.csr();
|
|
2578
|
+
if (ssr === false && !(state.prerendering && should_prerender_data)) {
|
|
2579
|
+
if (BROWSER && action_result && !event.request.headers.has("x-sveltekit-action")) ;
|
|
2580
|
+
return await render_response({
|
|
2581
|
+
branch: [],
|
|
2582
|
+
fetched,
|
|
2583
|
+
page_config: {
|
|
2584
|
+
ssr: false,
|
|
2585
|
+
csr
|
|
2586
|
+
},
|
|
2587
|
+
status,
|
|
2588
|
+
error: null,
|
|
2589
|
+
event,
|
|
2590
|
+
event_state,
|
|
2591
|
+
options: options2,
|
|
2592
|
+
manifest,
|
|
2593
|
+
state,
|
|
2594
|
+
resolve_opts,
|
|
2595
|
+
data_serializer: server_data_serializer(event, event_state, options2)
|
|
2596
|
+
});
|
|
2597
|
+
}
|
|
2598
|
+
const branch = [];
|
|
2599
|
+
let load_error = null;
|
|
2600
|
+
const data_serializer = server_data_serializer(event, event_state, options2);
|
|
2601
|
+
const data_serializer_json = state.prerendering && should_prerender_data ? server_data_serializer_json(event, event_state, options2) : null;
|
|
2602
|
+
const server_promises = nodes.data.map((node, i) => {
|
|
2603
|
+
if (load_error) {
|
|
2604
|
+
throw load_error;
|
|
2605
|
+
}
|
|
2606
|
+
return Promise.resolve().then(async () => {
|
|
2607
|
+
try {
|
|
2608
|
+
if (node === leaf_node && action_result?.type === "error") {
|
|
2609
|
+
throw action_result.error;
|
|
2610
|
+
}
|
|
2611
|
+
const server_data = await load_server_data({
|
|
2612
|
+
event,
|
|
2613
|
+
event_state,
|
|
2614
|
+
state,
|
|
2615
|
+
node,
|
|
2616
|
+
parent: async () => {
|
|
2617
|
+
const data = {};
|
|
2618
|
+
for (let j = 0; j < i; j += 1) {
|
|
2619
|
+
const parent = await server_promises[j];
|
|
2620
|
+
if (parent) Object.assign(data, parent.data);
|
|
2621
|
+
}
|
|
2622
|
+
return data;
|
|
2623
|
+
}
|
|
2624
|
+
});
|
|
2625
|
+
if (node) {
|
|
2626
|
+
data_serializer.add_node(i, server_data);
|
|
2627
|
+
}
|
|
2628
|
+
data_serializer_json?.add_node(i, server_data);
|
|
2629
|
+
return server_data;
|
|
2630
|
+
} catch (e) {
|
|
2631
|
+
load_error = /** @type {Error} */
|
|
2632
|
+
e;
|
|
2633
|
+
throw load_error;
|
|
2634
|
+
}
|
|
2635
|
+
});
|
|
2636
|
+
});
|
|
2637
|
+
const load_promises = nodes.data.map((node, i) => {
|
|
2638
|
+
if (load_error) throw load_error;
|
|
2639
|
+
return Promise.resolve().then(async () => {
|
|
2640
|
+
try {
|
|
2641
|
+
return await load_data({
|
|
2642
|
+
event,
|
|
2643
|
+
event_state,
|
|
2644
|
+
fetched,
|
|
2645
|
+
node,
|
|
2646
|
+
parent: async () => {
|
|
2647
|
+
const data = {};
|
|
2648
|
+
for (let j = 0; j < i; j += 1) {
|
|
2649
|
+
Object.assign(data, await load_promises[j]);
|
|
2650
|
+
}
|
|
2651
|
+
return data;
|
|
2652
|
+
},
|
|
2653
|
+
resolve_opts,
|
|
2654
|
+
server_data_promise: server_promises[i],
|
|
2655
|
+
state,
|
|
2656
|
+
csr
|
|
2657
|
+
});
|
|
2658
|
+
} catch (e) {
|
|
2659
|
+
load_error = /** @type {Error} */
|
|
2660
|
+
e;
|
|
2661
|
+
throw load_error;
|
|
2662
|
+
}
|
|
2663
|
+
});
|
|
2664
|
+
});
|
|
2665
|
+
for (const p of server_promises) p.catch(() => {
|
|
2666
|
+
});
|
|
2667
|
+
for (const p of load_promises) p.catch(() => {
|
|
2668
|
+
});
|
|
2669
|
+
for (let i = 0; i < nodes.data.length; i += 1) {
|
|
2670
|
+
const node = nodes.data[i];
|
|
2671
|
+
if (node) {
|
|
2672
|
+
try {
|
|
2673
|
+
const server_data = await server_promises[i];
|
|
2674
|
+
const data = await load_promises[i];
|
|
2675
|
+
branch.push({ node, server_data, data });
|
|
2676
|
+
} catch (e) {
|
|
2677
|
+
const err = normalize_error(e);
|
|
2678
|
+
if (err instanceof Redirect) {
|
|
2679
|
+
if (state.prerendering && should_prerender_data) {
|
|
2680
|
+
const body2 = JSON.stringify({
|
|
2681
|
+
type: "redirect",
|
|
2682
|
+
location: err.location
|
|
2683
|
+
});
|
|
2684
|
+
state.prerendering.dependencies.set(data_pathname, {
|
|
2685
|
+
response: text(body2),
|
|
2686
|
+
body: body2
|
|
2687
|
+
});
|
|
2688
|
+
}
|
|
2689
|
+
return redirect_response(err.status, err.location);
|
|
2690
|
+
}
|
|
2691
|
+
const status2 = get_status(err);
|
|
2692
|
+
const error2 = await handle_error_and_jsonify(event, event_state, options2, err);
|
|
2693
|
+
while (i--) {
|
|
2694
|
+
if (page.errors[i]) {
|
|
2695
|
+
const index = (
|
|
2696
|
+
/** @type {number} */
|
|
2697
|
+
page.errors[i]
|
|
2698
|
+
);
|
|
2699
|
+
const node2 = await manifest._.nodes[index]();
|
|
2700
|
+
let j = i;
|
|
2701
|
+
while (!branch[j]) j -= 1;
|
|
2702
|
+
data_serializer.set_max_nodes(j + 1);
|
|
2703
|
+
const layouts = compact(branch.slice(0, j + 1));
|
|
2704
|
+
const nodes2 = new PageNodes(layouts.map((layout) => layout.node));
|
|
2705
|
+
return await render_response({
|
|
2706
|
+
event,
|
|
2707
|
+
event_state,
|
|
2708
|
+
options: options2,
|
|
2709
|
+
manifest,
|
|
2710
|
+
state,
|
|
2711
|
+
resolve_opts,
|
|
2712
|
+
page_config: {
|
|
2713
|
+
ssr: nodes2.ssr(),
|
|
2714
|
+
csr: nodes2.csr()
|
|
2715
|
+
},
|
|
2716
|
+
status: status2,
|
|
2717
|
+
error: error2,
|
|
2718
|
+
branch: layouts.concat({
|
|
2719
|
+
node: node2,
|
|
2720
|
+
data: null,
|
|
2721
|
+
server_data: null
|
|
2722
|
+
}),
|
|
2723
|
+
fetched,
|
|
2724
|
+
data_serializer
|
|
2725
|
+
});
|
|
2726
|
+
}
|
|
2727
|
+
}
|
|
2728
|
+
return static_error_page(options2, status2, error2.message);
|
|
2729
|
+
}
|
|
2730
|
+
} else {
|
|
2731
|
+
branch.push(null);
|
|
2732
|
+
}
|
|
2733
|
+
}
|
|
2734
|
+
if (state.prerendering && data_serializer_json) {
|
|
2735
|
+
let { data, chunks } = data_serializer_json.get_data();
|
|
2736
|
+
if (chunks) {
|
|
2737
|
+
for await (const chunk of chunks) {
|
|
2738
|
+
data += chunk;
|
|
2739
|
+
}
|
|
2740
|
+
}
|
|
2741
|
+
state.prerendering.dependencies.set(data_pathname, {
|
|
2742
|
+
response: text(data),
|
|
2743
|
+
body: data
|
|
2744
|
+
});
|
|
2745
|
+
}
|
|
2746
|
+
return await render_response({
|
|
2747
|
+
event,
|
|
2748
|
+
event_state,
|
|
2749
|
+
options: options2,
|
|
2750
|
+
manifest,
|
|
2751
|
+
state,
|
|
2752
|
+
resolve_opts,
|
|
2753
|
+
page_config: {
|
|
2754
|
+
csr,
|
|
2755
|
+
ssr
|
|
2756
|
+
},
|
|
2757
|
+
status,
|
|
2758
|
+
error: null,
|
|
2759
|
+
branch: ssr === false ? [] : compact(branch),
|
|
2760
|
+
action_result,
|
|
2761
|
+
fetched,
|
|
2762
|
+
data_serializer: ssr === false ? server_data_serializer(event, event_state, options2) : data_serializer
|
|
2763
|
+
});
|
|
2764
|
+
} catch (e) {
|
|
2765
|
+
return await respond_with_error({
|
|
2766
|
+
event,
|
|
2767
|
+
event_state,
|
|
2768
|
+
options: options2,
|
|
2769
|
+
manifest,
|
|
2770
|
+
state,
|
|
2771
|
+
status: 500,
|
|
2772
|
+
error: e,
|
|
2773
|
+
resolve_opts
|
|
2774
|
+
});
|
|
2775
|
+
}
|
|
2776
|
+
}
|
|
2777
|
+
function once(fn) {
|
|
2778
|
+
let done = false;
|
|
2779
|
+
let result;
|
|
2780
|
+
return () => {
|
|
2781
|
+
if (done) return result;
|
|
2782
|
+
done = true;
|
|
2783
|
+
return result = fn();
|
|
2784
|
+
};
|
|
2785
|
+
}
|
|
2786
|
+
async function render_data(event, event_state, route, options2, manifest, state, invalidated_data_nodes, trailing_slash) {
|
|
2787
|
+
if (!route.page) {
|
|
2788
|
+
return new Response(void 0, {
|
|
2789
|
+
status: 404
|
|
2790
|
+
});
|
|
2791
|
+
}
|
|
2792
|
+
try {
|
|
2793
|
+
const node_ids = [...route.page.layouts, route.page.leaf];
|
|
2794
|
+
const invalidated = invalidated_data_nodes ?? node_ids.map(() => true);
|
|
2795
|
+
let aborted = false;
|
|
2796
|
+
const url = new URL(event.url);
|
|
2797
|
+
url.pathname = normalize_path(url.pathname, trailing_slash);
|
|
2798
|
+
const new_event = { ...event, url };
|
|
2799
|
+
const functions = node_ids.map((n, i) => {
|
|
2800
|
+
return once(async () => {
|
|
2801
|
+
try {
|
|
2802
|
+
if (aborted) {
|
|
2803
|
+
return (
|
|
2804
|
+
/** @type {import('types').ServerDataSkippedNode} */
|
|
2805
|
+
{
|
|
2806
|
+
type: "skip"
|
|
2807
|
+
}
|
|
2808
|
+
);
|
|
2809
|
+
}
|
|
2810
|
+
const node = n == void 0 ? n : await manifest._.nodes[n]();
|
|
2811
|
+
return load_server_data({
|
|
2812
|
+
event: new_event,
|
|
2813
|
+
event_state,
|
|
2814
|
+
state,
|
|
2815
|
+
node,
|
|
2816
|
+
parent: async () => {
|
|
2817
|
+
const data2 = {};
|
|
2818
|
+
for (let j = 0; j < i; j += 1) {
|
|
2819
|
+
const parent = (
|
|
2820
|
+
/** @type {import('types').ServerDataNode | null} */
|
|
2821
|
+
await functions[j]()
|
|
2822
|
+
);
|
|
2823
|
+
if (parent) {
|
|
2824
|
+
Object.assign(data2, parent.data);
|
|
2825
|
+
}
|
|
2826
|
+
}
|
|
2827
|
+
return data2;
|
|
2828
|
+
}
|
|
2829
|
+
});
|
|
2830
|
+
} catch (e) {
|
|
2831
|
+
aborted = true;
|
|
2832
|
+
throw e;
|
|
2833
|
+
}
|
|
2834
|
+
});
|
|
2835
|
+
});
|
|
2836
|
+
const promises = functions.map(async (fn, i) => {
|
|
2837
|
+
if (!invalidated[i]) {
|
|
2838
|
+
return (
|
|
2839
|
+
/** @type {import('types').ServerDataSkippedNode} */
|
|
2840
|
+
{
|
|
2841
|
+
type: "skip"
|
|
2842
|
+
}
|
|
2843
|
+
);
|
|
2844
|
+
}
|
|
2845
|
+
return fn();
|
|
2846
|
+
});
|
|
2847
|
+
let length = promises.length;
|
|
2848
|
+
const nodes = await Promise.all(
|
|
2849
|
+
promises.map(
|
|
2850
|
+
(p, i) => p.catch(async (error2) => {
|
|
2851
|
+
if (error2 instanceof Redirect) {
|
|
2852
|
+
throw error2;
|
|
2853
|
+
}
|
|
2854
|
+
length = Math.min(length, i + 1);
|
|
2855
|
+
return (
|
|
2856
|
+
/** @type {import('types').ServerErrorNode} */
|
|
2857
|
+
{
|
|
2858
|
+
type: "error",
|
|
2859
|
+
error: await handle_error_and_jsonify(event, event_state, options2, error2),
|
|
2860
|
+
status: error2 instanceof HttpError || error2 instanceof SvelteKitError ? error2.status : void 0
|
|
2861
|
+
}
|
|
2862
|
+
);
|
|
2863
|
+
})
|
|
2864
|
+
)
|
|
2865
|
+
);
|
|
2866
|
+
const data_serializer = server_data_serializer_json(event, event_state, options2);
|
|
2867
|
+
for (let i = 0; i < nodes.length; i++) data_serializer.add_node(i, nodes[i]);
|
|
2868
|
+
const { data, chunks } = data_serializer.get_data();
|
|
2869
|
+
if (!chunks) {
|
|
2870
|
+
return json_response(data);
|
|
2871
|
+
}
|
|
2872
|
+
return new Response(
|
|
2873
|
+
new ReadableStream({
|
|
2874
|
+
async start(controller) {
|
|
2875
|
+
controller.enqueue(text_encoder.encode(data));
|
|
2876
|
+
for await (const chunk of chunks) {
|
|
2877
|
+
controller.enqueue(text_encoder.encode(chunk));
|
|
2878
|
+
}
|
|
2879
|
+
controller.close();
|
|
2880
|
+
},
|
|
2881
|
+
type: "bytes"
|
|
2882
|
+
}),
|
|
2883
|
+
{
|
|
2884
|
+
headers: {
|
|
2885
|
+
// we use a proprietary content type to prevent buffering.
|
|
2886
|
+
// the `text` prefix makes it inspectable
|
|
2887
|
+
"content-type": "text/sveltekit-data",
|
|
2888
|
+
"cache-control": "private, no-store"
|
|
2889
|
+
}
|
|
2890
|
+
}
|
|
2891
|
+
);
|
|
2892
|
+
} catch (e) {
|
|
2893
|
+
const error2 = normalize_error(e);
|
|
2894
|
+
if (error2 instanceof Redirect) {
|
|
2895
|
+
return redirect_json_response(error2);
|
|
2896
|
+
} else {
|
|
2897
|
+
return json_response(await handle_error_and_jsonify(event, event_state, options2, error2), 500);
|
|
2898
|
+
}
|
|
2899
|
+
}
|
|
2900
|
+
}
|
|
2901
|
+
function json_response(json2, status = 200) {
|
|
2902
|
+
return text(typeof json2 === "string" ? json2 : JSON.stringify(json2), {
|
|
2903
|
+
status,
|
|
2904
|
+
headers: {
|
|
2905
|
+
"content-type": "application/json",
|
|
2906
|
+
"cache-control": "private, no-store"
|
|
2907
|
+
}
|
|
2908
|
+
});
|
|
2909
|
+
}
|
|
2910
|
+
function redirect_json_response(redirect) {
|
|
2911
|
+
return json_response(
|
|
2912
|
+
/** @type {import('types').ServerRedirectNode} */
|
|
2913
|
+
{
|
|
2914
|
+
type: "redirect",
|
|
2915
|
+
location: redirect.location
|
|
2916
|
+
}
|
|
2917
|
+
);
|
|
2918
|
+
}
|
|
2919
|
+
const INVALID_COOKIE_CHARACTER_REGEX = /[\x00-\x1F\x7F()<>@,;:"/[\]?={} \t]/;
|
|
2920
|
+
function validate_options(options2) {
|
|
2921
|
+
if (options2?.path === void 0) {
|
|
2922
|
+
throw new Error("You must specify a `path` when setting, deleting or serializing cookies");
|
|
2923
|
+
}
|
|
2924
|
+
}
|
|
2925
|
+
function generate_cookie_key(domain, path, name) {
|
|
2926
|
+
return `${domain || ""}${path}?${encodeURIComponent(name)}`;
|
|
2927
|
+
}
|
|
2928
|
+
function get_cookies(request, url) {
|
|
2929
|
+
const header = request.headers.get("cookie") ?? "";
|
|
2930
|
+
const initial_cookies = parse(header, { decode: (value) => value });
|
|
2931
|
+
let normalized_url;
|
|
2932
|
+
const new_cookies = /* @__PURE__ */ new Map();
|
|
2933
|
+
const defaults = {
|
|
2934
|
+
httpOnly: true,
|
|
2935
|
+
sameSite: "lax",
|
|
2936
|
+
secure: url.hostname === "localhost" && url.protocol === "http:" ? false : true
|
|
2937
|
+
};
|
|
2938
|
+
const cookies = {
|
|
2939
|
+
// The JSDoc param annotations appearing below for get, set and delete
|
|
2940
|
+
// are necessary to expose the `cookie` library types to
|
|
2941
|
+
// typescript users. `@type {import('@sveltejs/kit').Cookies}` above is not
|
|
2942
|
+
// sufficient to do so.
|
|
2943
|
+
/**
|
|
2944
|
+
* @param {string} name
|
|
2945
|
+
* @param {import('cookie').CookieParseOptions} [opts]
|
|
2946
|
+
*/
|
|
2947
|
+
get(name, opts) {
|
|
2948
|
+
const best_match = Array.from(new_cookies.values()).filter((c) => {
|
|
2949
|
+
return c.name === name && domain_matches(url.hostname, c.options.domain) && path_matches(url.pathname, c.options.path);
|
|
2950
|
+
}).sort((a, b) => b.options.path.length - a.options.path.length)[0];
|
|
2951
|
+
if (best_match) {
|
|
2952
|
+
return best_match.options.maxAge === 0 ? void 0 : best_match.value;
|
|
2953
|
+
}
|
|
2954
|
+
const req_cookies = parse(header, { decode: opts?.decode });
|
|
2955
|
+
const cookie = req_cookies[name];
|
|
2956
|
+
return cookie;
|
|
2957
|
+
},
|
|
2958
|
+
/**
|
|
2959
|
+
* @param {import('cookie').CookieParseOptions} [opts]
|
|
2960
|
+
*/
|
|
2961
|
+
getAll(opts) {
|
|
2962
|
+
const cookies2 = parse(header, { decode: opts?.decode });
|
|
2963
|
+
const lookup = /* @__PURE__ */ new Map();
|
|
2964
|
+
for (const c of new_cookies.values()) {
|
|
2965
|
+
if (domain_matches(url.hostname, c.options.domain) && path_matches(url.pathname, c.options.path)) {
|
|
2966
|
+
const existing = lookup.get(c.name);
|
|
2967
|
+
if (!existing || c.options.path.length > existing.options.path.length) {
|
|
2968
|
+
lookup.set(c.name, c);
|
|
2969
|
+
}
|
|
2970
|
+
}
|
|
2971
|
+
}
|
|
2972
|
+
for (const c of lookup.values()) {
|
|
2973
|
+
cookies2[c.name] = c.value;
|
|
2974
|
+
}
|
|
2975
|
+
return Object.entries(cookies2).map(([name, value]) => ({ name, value }));
|
|
2976
|
+
},
|
|
2977
|
+
/**
|
|
2978
|
+
* @param {string} name
|
|
2979
|
+
* @param {string} value
|
|
2980
|
+
* @param {import('./page/types.js').Cookie['options']} options
|
|
2981
|
+
*/
|
|
2982
|
+
set(name, value, options2) {
|
|
2983
|
+
const illegal_characters = name.match(INVALID_COOKIE_CHARACTER_REGEX);
|
|
2984
|
+
if (illegal_characters) {
|
|
2985
|
+
console.warn(
|
|
2986
|
+
`The cookie name "${name}" will be invalid in SvelteKit 3.0 as it contains ${illegal_characters.join(
|
|
2987
|
+
" and "
|
|
2988
|
+
)}. See RFC 2616 for more details https://datatracker.ietf.org/doc/html/rfc2616#section-2.2`
|
|
2989
|
+
);
|
|
2990
|
+
}
|
|
2991
|
+
validate_options(options2);
|
|
2992
|
+
set_internal(name, value, { ...defaults, ...options2 });
|
|
2993
|
+
},
|
|
2994
|
+
/**
|
|
2995
|
+
* @param {string} name
|
|
2996
|
+
* @param {import('./page/types.js').Cookie['options']} options
|
|
2997
|
+
*/
|
|
2998
|
+
delete(name, options2) {
|
|
2999
|
+
validate_options(options2);
|
|
3000
|
+
cookies.set(name, "", { ...options2, maxAge: 0 });
|
|
3001
|
+
},
|
|
3002
|
+
/**
|
|
3003
|
+
* @param {string} name
|
|
3004
|
+
* @param {string} value
|
|
3005
|
+
* @param {import('./page/types.js').Cookie['options']} options
|
|
3006
|
+
*/
|
|
3007
|
+
serialize(name, value, options2) {
|
|
3008
|
+
validate_options(options2);
|
|
3009
|
+
let path = options2.path;
|
|
3010
|
+
if (!options2.domain || options2.domain === url.hostname) {
|
|
3011
|
+
if (!normalized_url) {
|
|
3012
|
+
throw new Error("Cannot serialize cookies until after the route is determined");
|
|
3013
|
+
}
|
|
3014
|
+
path = resolve(normalized_url, path);
|
|
3015
|
+
}
|
|
3016
|
+
return serialize(name, value, { ...defaults, ...options2, path });
|
|
3017
|
+
}
|
|
3018
|
+
};
|
|
3019
|
+
function get_cookie_header(destination, header2) {
|
|
3020
|
+
const combined_cookies = {
|
|
3021
|
+
// cookies sent by the user agent have lowest precedence
|
|
3022
|
+
...initial_cookies
|
|
3023
|
+
};
|
|
3024
|
+
for (const cookie of new_cookies.values()) {
|
|
3025
|
+
if (!domain_matches(destination.hostname, cookie.options.domain)) continue;
|
|
3026
|
+
if (!path_matches(destination.pathname, cookie.options.path)) continue;
|
|
3027
|
+
const encoder = cookie.options.encode || encodeURIComponent;
|
|
3028
|
+
combined_cookies[cookie.name] = encoder(cookie.value);
|
|
3029
|
+
}
|
|
3030
|
+
if (header2) {
|
|
3031
|
+
const parsed = parse(header2, { decode: (value) => value });
|
|
3032
|
+
for (const name in parsed) {
|
|
3033
|
+
combined_cookies[name] = parsed[name];
|
|
3034
|
+
}
|
|
3035
|
+
}
|
|
3036
|
+
return Object.entries(combined_cookies).map(([name, value]) => `${name}=${value}`).join("; ");
|
|
3037
|
+
}
|
|
3038
|
+
const internal_queue = [];
|
|
3039
|
+
function set_internal(name, value, options2) {
|
|
3040
|
+
if (!normalized_url) {
|
|
3041
|
+
internal_queue.push(() => set_internal(name, value, options2));
|
|
3042
|
+
return;
|
|
3043
|
+
}
|
|
3044
|
+
let path = options2.path;
|
|
3045
|
+
if (!options2.domain || options2.domain === url.hostname) {
|
|
3046
|
+
path = resolve(normalized_url, path);
|
|
3047
|
+
}
|
|
3048
|
+
const cookie_key = generate_cookie_key(options2.domain, path, name);
|
|
3049
|
+
const cookie = { name, value, options: { ...options2, path } };
|
|
3050
|
+
new_cookies.set(cookie_key, cookie);
|
|
3051
|
+
}
|
|
3052
|
+
function set_trailing_slash(trailing_slash) {
|
|
3053
|
+
normalized_url = normalize_path(url.pathname, trailing_slash);
|
|
3054
|
+
internal_queue.forEach((fn) => fn());
|
|
3055
|
+
}
|
|
3056
|
+
return { cookies, new_cookies, get_cookie_header, set_internal, set_trailing_slash };
|
|
3057
|
+
}
|
|
3058
|
+
function domain_matches(hostname, constraint) {
|
|
3059
|
+
if (!constraint) return true;
|
|
3060
|
+
const normalized = constraint[0] === "." ? constraint.slice(1) : constraint;
|
|
3061
|
+
if (hostname === normalized) return true;
|
|
3062
|
+
return hostname.endsWith("." + normalized);
|
|
3063
|
+
}
|
|
3064
|
+
function path_matches(path, constraint) {
|
|
3065
|
+
if (!constraint) return true;
|
|
3066
|
+
const normalized = constraint.endsWith("/") ? constraint.slice(0, -1) : constraint;
|
|
3067
|
+
if (path === normalized) return true;
|
|
3068
|
+
return path.startsWith(normalized + "/");
|
|
3069
|
+
}
|
|
3070
|
+
function add_cookies_to_headers(headers2, cookies) {
|
|
3071
|
+
for (const new_cookie of cookies) {
|
|
3072
|
+
const { name, value, options: options2 } = new_cookie;
|
|
3073
|
+
headers2.append("set-cookie", serialize(name, value, options2));
|
|
3074
|
+
if (options2.path.endsWith(".html")) {
|
|
3075
|
+
const path = add_data_suffix(options2.path);
|
|
3076
|
+
headers2.append("set-cookie", serialize(name, value, { ...options2, path }));
|
|
3077
|
+
}
|
|
3078
|
+
}
|
|
3079
|
+
}
|
|
3080
|
+
function create_fetch({ event, options: options2, manifest, state, get_cookie_header, set_internal }) {
|
|
3081
|
+
const server_fetch = async (info, init2) => {
|
|
3082
|
+
const original_request = normalize_fetch_input(info, init2, event.url);
|
|
3083
|
+
let mode = (info instanceof Request ? info.mode : init2?.mode) ?? "cors";
|
|
3084
|
+
let credentials = (info instanceof Request ? info.credentials : init2?.credentials) ?? "same-origin";
|
|
3085
|
+
return options2.hooks.handleFetch({
|
|
3086
|
+
event,
|
|
3087
|
+
request: original_request,
|
|
3088
|
+
fetch: async (info2, init3) => {
|
|
3089
|
+
const request = normalize_fetch_input(info2, init3, event.url);
|
|
3090
|
+
const url = new URL(request.url);
|
|
3091
|
+
if (!request.headers.has("origin")) {
|
|
3092
|
+
request.headers.set("origin", event.url.origin);
|
|
3093
|
+
}
|
|
3094
|
+
if (info2 !== original_request) {
|
|
3095
|
+
mode = (info2 instanceof Request ? info2.mode : init3?.mode) ?? "cors";
|
|
3096
|
+
credentials = (info2 instanceof Request ? info2.credentials : init3?.credentials) ?? "same-origin";
|
|
3097
|
+
}
|
|
3098
|
+
if ((request.method === "GET" || request.method === "HEAD") && (mode === "no-cors" && url.origin !== event.url.origin || url.origin === event.url.origin)) {
|
|
3099
|
+
request.headers.delete("origin");
|
|
3100
|
+
}
|
|
3101
|
+
if (url.origin !== event.url.origin) {
|
|
3102
|
+
if (`.${url.hostname}`.endsWith(`.${event.url.hostname}`) && credentials !== "omit") {
|
|
3103
|
+
const cookie = get_cookie_header(url, request.headers.get("cookie"));
|
|
3104
|
+
if (cookie) request.headers.set("cookie", cookie);
|
|
3105
|
+
}
|
|
3106
|
+
return fetch(request);
|
|
3107
|
+
}
|
|
3108
|
+
const prefix = assets || base;
|
|
3109
|
+
const decoded = decodeURIComponent(url.pathname);
|
|
3110
|
+
const filename = (decoded.startsWith(prefix) ? decoded.slice(prefix.length) : decoded).slice(1);
|
|
3111
|
+
const filename_html = `${filename}/index.html`;
|
|
3112
|
+
const is_asset = manifest.assets.has(filename) || filename in manifest._.server_assets;
|
|
3113
|
+
const is_asset_html = manifest.assets.has(filename_html) || filename_html in manifest._.server_assets;
|
|
3114
|
+
if (is_asset || is_asset_html) {
|
|
3115
|
+
const file = is_asset ? filename : filename_html;
|
|
3116
|
+
if (state.read) {
|
|
3117
|
+
const type = is_asset ? manifest.mimeTypes[filename.slice(filename.lastIndexOf("."))] : "text/html";
|
|
3118
|
+
return new Response(state.read(file), {
|
|
3119
|
+
headers: type ? { "content-type": type } : {}
|
|
3120
|
+
});
|
|
3121
|
+
} else if (read_implementation && file in manifest._.server_assets) {
|
|
3122
|
+
const length = manifest._.server_assets[file];
|
|
3123
|
+
const type = manifest.mimeTypes[file.slice(file.lastIndexOf("."))];
|
|
3124
|
+
return new Response(read_implementation(file), {
|
|
3125
|
+
headers: {
|
|
3126
|
+
"Content-Length": "" + length,
|
|
3127
|
+
"Content-Type": type
|
|
3128
|
+
}
|
|
3129
|
+
});
|
|
3130
|
+
}
|
|
3131
|
+
return await fetch(request);
|
|
3132
|
+
}
|
|
3133
|
+
if (has_prerendered_path(manifest, base + decoded)) {
|
|
3134
|
+
return await fetch(request);
|
|
3135
|
+
}
|
|
3136
|
+
if (credentials !== "omit") {
|
|
3137
|
+
const cookie = get_cookie_header(url, request.headers.get("cookie"));
|
|
3138
|
+
if (cookie) {
|
|
3139
|
+
request.headers.set("cookie", cookie);
|
|
3140
|
+
}
|
|
3141
|
+
const authorization = event.request.headers.get("authorization");
|
|
3142
|
+
if (authorization && !request.headers.has("authorization")) {
|
|
3143
|
+
request.headers.set("authorization", authorization);
|
|
3144
|
+
}
|
|
3145
|
+
}
|
|
3146
|
+
if (!request.headers.has("accept")) {
|
|
3147
|
+
request.headers.set("accept", "*/*");
|
|
3148
|
+
}
|
|
3149
|
+
if (!request.headers.has("accept-language")) {
|
|
3150
|
+
request.headers.set(
|
|
3151
|
+
"accept-language",
|
|
3152
|
+
/** @type {string} */
|
|
3153
|
+
event.request.headers.get("accept-language")
|
|
3154
|
+
);
|
|
3155
|
+
}
|
|
3156
|
+
const response = await internal_fetch(request, options2, manifest, state);
|
|
3157
|
+
const set_cookie = response.headers.get("set-cookie");
|
|
3158
|
+
if (set_cookie) {
|
|
3159
|
+
for (const str of set_cookie_parser.splitCookiesString(set_cookie)) {
|
|
3160
|
+
const { name, value, ...options3 } = set_cookie_parser.parseString(str, {
|
|
3161
|
+
decodeValues: false
|
|
3162
|
+
});
|
|
3163
|
+
const path = options3.path ?? (url.pathname.split("/").slice(0, -1).join("/") || "/");
|
|
3164
|
+
set_internal(name, value, {
|
|
3165
|
+
path,
|
|
3166
|
+
encode: (value2) => value2,
|
|
3167
|
+
.../** @type {import('cookie').CookieSerializeOptions} */
|
|
3168
|
+
options3
|
|
3169
|
+
});
|
|
3170
|
+
}
|
|
3171
|
+
}
|
|
3172
|
+
return response;
|
|
3173
|
+
}
|
|
3174
|
+
});
|
|
3175
|
+
};
|
|
3176
|
+
return (input, init2) => {
|
|
3177
|
+
const response = server_fetch(input, init2);
|
|
3178
|
+
response.catch(() => {
|
|
3179
|
+
});
|
|
3180
|
+
return response;
|
|
3181
|
+
};
|
|
3182
|
+
}
|
|
3183
|
+
function normalize_fetch_input(info, init2, url) {
|
|
3184
|
+
if (info instanceof Request) {
|
|
3185
|
+
return info;
|
|
3186
|
+
}
|
|
3187
|
+
return new Request(typeof info === "string" ? new URL(info, url) : info, init2);
|
|
3188
|
+
}
|
|
3189
|
+
async function internal_fetch(request, options2, manifest, state) {
|
|
3190
|
+
if (request.signal) {
|
|
3191
|
+
if (request.signal.aborted) {
|
|
3192
|
+
throw new DOMException("The operation was aborted.", "AbortError");
|
|
3193
|
+
}
|
|
3194
|
+
let remove_abort_listener = () => {
|
|
3195
|
+
};
|
|
3196
|
+
const abort_promise = new Promise((_, reject) => {
|
|
3197
|
+
const on_abort = () => {
|
|
3198
|
+
reject(new DOMException("The operation was aborted.", "AbortError"));
|
|
3199
|
+
};
|
|
3200
|
+
request.signal.addEventListener("abort", on_abort, { once: true });
|
|
3201
|
+
remove_abort_listener = () => request.signal.removeEventListener("abort", on_abort);
|
|
3202
|
+
});
|
|
3203
|
+
const result = await Promise.race([
|
|
3204
|
+
respond(request, options2, manifest, {
|
|
3205
|
+
...state,
|
|
3206
|
+
depth: state.depth + 1
|
|
3207
|
+
}),
|
|
3208
|
+
abort_promise
|
|
3209
|
+
]);
|
|
3210
|
+
remove_abort_listener();
|
|
3211
|
+
return result;
|
|
3212
|
+
} else {
|
|
3213
|
+
return await respond(request, options2, manifest, {
|
|
3214
|
+
...state,
|
|
3215
|
+
depth: state.depth + 1
|
|
3216
|
+
});
|
|
3217
|
+
}
|
|
3218
|
+
}
|
|
3219
|
+
let body;
|
|
3220
|
+
let etag;
|
|
3221
|
+
let headers;
|
|
3222
|
+
function get_public_env(request) {
|
|
3223
|
+
body ??= `export const env=${JSON.stringify(public_env)}`;
|
|
3224
|
+
etag ??= `W/${Date.now()}`;
|
|
3225
|
+
headers ??= new Headers({
|
|
3226
|
+
"content-type": "application/javascript; charset=utf-8",
|
|
3227
|
+
etag
|
|
3228
|
+
});
|
|
3229
|
+
if (request.headers.get("if-none-match") === etag) {
|
|
3230
|
+
return new Response(void 0, { status: 304, headers });
|
|
3231
|
+
}
|
|
3232
|
+
return new Response(body, { headers });
|
|
3233
|
+
}
|
|
3234
|
+
const default_transform = ({ html }) => html;
|
|
3235
|
+
const default_filter = () => false;
|
|
3236
|
+
const default_preload = ({ type }) => type === "js" || type === "css";
|
|
3237
|
+
const page_methods = /* @__PURE__ */ new Set(["GET", "HEAD", "POST"]);
|
|
3238
|
+
const allowed_page_methods = /* @__PURE__ */ new Set(["GET", "HEAD", "OPTIONS"]);
|
|
3239
|
+
let warned_on_devtools_json_request = false;
|
|
3240
|
+
const respond = propagate_context(internal_respond);
|
|
3241
|
+
async function internal_respond(request, options2, manifest, state) {
|
|
3242
|
+
const url = new URL(request.url);
|
|
3243
|
+
const is_route_resolution_request = has_resolution_suffix(url.pathname);
|
|
3244
|
+
const is_data_request = has_data_suffix(url.pathname);
|
|
3245
|
+
const remote_id = get_remote_id(url);
|
|
3246
|
+
{
|
|
3247
|
+
const request_origin = request.headers.get("origin");
|
|
3248
|
+
if (remote_id) {
|
|
3249
|
+
if (request.method !== "GET" && request_origin !== url.origin) {
|
|
3250
|
+
const message = "Cross-site remote requests are forbidden";
|
|
3251
|
+
return json({ message }, { status: 403 });
|
|
3252
|
+
}
|
|
3253
|
+
} else if (options2.csrf_check_origin) {
|
|
3254
|
+
const forbidden = is_form_content_type(request) && (request.method === "POST" || request.method === "PUT" || request.method === "PATCH" || request.method === "DELETE") && request_origin !== url.origin && (!request_origin || !options2.csrf_trusted_origins.includes(request_origin));
|
|
3255
|
+
if (forbidden) {
|
|
3256
|
+
const message = `Cross-site ${request.method} form submissions are forbidden`;
|
|
3257
|
+
const opts = { status: 403 };
|
|
3258
|
+
if (request.headers.get("accept") === "application/json") {
|
|
3259
|
+
return json({ message }, opts);
|
|
3260
|
+
}
|
|
3261
|
+
return text(message, opts);
|
|
3262
|
+
}
|
|
3263
|
+
}
|
|
3264
|
+
}
|
|
3265
|
+
if (options2.hash_routing && url.pathname !== base + "/" && url.pathname !== "/[fallback]") {
|
|
3266
|
+
return text("Not found", { status: 404 });
|
|
3267
|
+
}
|
|
3268
|
+
let invalidated_data_nodes;
|
|
3269
|
+
if (is_route_resolution_request) {
|
|
3270
|
+
url.pathname = strip_resolution_suffix(url.pathname);
|
|
3271
|
+
} else if (is_data_request) {
|
|
3272
|
+
url.pathname = strip_data_suffix(url.pathname) + (url.searchParams.get(TRAILING_SLASH_PARAM) === "1" ? "/" : "") || "/";
|
|
3273
|
+
url.searchParams.delete(TRAILING_SLASH_PARAM);
|
|
3274
|
+
invalidated_data_nodes = url.searchParams.get(INVALIDATED_PARAM)?.split("").map((node) => node === "1");
|
|
3275
|
+
url.searchParams.delete(INVALIDATED_PARAM);
|
|
3276
|
+
} else if (remote_id) {
|
|
3277
|
+
url.pathname = request.headers.get("x-sveltekit-pathname") ?? base;
|
|
3278
|
+
url.search = request.headers.get("x-sveltekit-search") ?? "";
|
|
3279
|
+
}
|
|
3280
|
+
const headers2 = {};
|
|
3281
|
+
const { cookies, new_cookies, get_cookie_header, set_internal, set_trailing_slash } = get_cookies(
|
|
3282
|
+
request,
|
|
3283
|
+
url
|
|
3284
|
+
);
|
|
3285
|
+
const event_state = {
|
|
3286
|
+
prerendering: state.prerendering,
|
|
3287
|
+
transport: options2.hooks.transport,
|
|
3288
|
+
handleValidationError: options2.hooks.handleValidationError,
|
|
3289
|
+
tracing: {
|
|
3290
|
+
record_span
|
|
3291
|
+
},
|
|
3292
|
+
is_in_remote_function: false
|
|
3293
|
+
};
|
|
3294
|
+
const event = {
|
|
3295
|
+
cookies,
|
|
3296
|
+
// @ts-expect-error `fetch` needs to be created after the `event` itself
|
|
3297
|
+
fetch: null,
|
|
3298
|
+
getClientAddress: state.getClientAddress || (() => {
|
|
3299
|
+
throw new Error(
|
|
3300
|
+
`${"@sveltejs/adapter-node"} does not specify getClientAddress. Please raise an issue`
|
|
3301
|
+
);
|
|
3302
|
+
}),
|
|
3303
|
+
locals: {},
|
|
3304
|
+
params: {},
|
|
3305
|
+
platform: state.platform,
|
|
3306
|
+
request,
|
|
3307
|
+
route: { id: null },
|
|
3308
|
+
setHeaders: (new_headers) => {
|
|
3309
|
+
for (const key2 in new_headers) {
|
|
3310
|
+
const lower = key2.toLowerCase();
|
|
3311
|
+
const value = new_headers[key2];
|
|
3312
|
+
if (lower === "set-cookie") {
|
|
3313
|
+
throw new Error(
|
|
3314
|
+
"Use `event.cookies.set(name, value, options)` instead of `event.setHeaders` to set cookies"
|
|
3315
|
+
);
|
|
3316
|
+
} else if (lower in headers2) {
|
|
3317
|
+
if (lower === "server-timing") {
|
|
3318
|
+
headers2[lower] += ", " + value;
|
|
3319
|
+
} else {
|
|
3320
|
+
throw new Error(`"${key2}" header is already set`);
|
|
3321
|
+
}
|
|
3322
|
+
} else {
|
|
3323
|
+
headers2[lower] = value;
|
|
3324
|
+
if (state.prerendering && lower === "cache-control") {
|
|
3325
|
+
state.prerendering.cache = /** @type {string} */
|
|
3326
|
+
value;
|
|
3327
|
+
}
|
|
3328
|
+
}
|
|
3329
|
+
}
|
|
3330
|
+
},
|
|
3331
|
+
url,
|
|
3332
|
+
isDataRequest: is_data_request,
|
|
3333
|
+
isSubRequest: state.depth > 0,
|
|
3334
|
+
isRemoteRequest: !!remote_id
|
|
3335
|
+
};
|
|
3336
|
+
event.fetch = create_fetch({
|
|
3337
|
+
event,
|
|
3338
|
+
options: options2,
|
|
3339
|
+
manifest,
|
|
3340
|
+
state,
|
|
3341
|
+
get_cookie_header,
|
|
3342
|
+
set_internal
|
|
3343
|
+
});
|
|
3344
|
+
if (state.emulator?.platform) {
|
|
3345
|
+
event.platform = await state.emulator.platform({
|
|
3346
|
+
config: {},
|
|
3347
|
+
prerender: !!state.prerendering?.fallback
|
|
3348
|
+
});
|
|
3349
|
+
}
|
|
3350
|
+
let resolved_path = url.pathname;
|
|
3351
|
+
if (!remote_id) {
|
|
3352
|
+
const prerendering_reroute_state = state.prerendering?.inside_reroute;
|
|
3353
|
+
try {
|
|
3354
|
+
if (state.prerendering) state.prerendering.inside_reroute = true;
|
|
3355
|
+
resolved_path = await options2.hooks.reroute({ url: new URL(url), fetch: event.fetch }) ?? url.pathname;
|
|
3356
|
+
} catch {
|
|
3357
|
+
return text("Internal Server Error", {
|
|
3358
|
+
status: 500
|
|
3359
|
+
});
|
|
3360
|
+
} finally {
|
|
3361
|
+
if (state.prerendering) state.prerendering.inside_reroute = prerendering_reroute_state;
|
|
3362
|
+
}
|
|
3363
|
+
}
|
|
3364
|
+
try {
|
|
3365
|
+
resolved_path = decode_pathname(resolved_path);
|
|
3366
|
+
} catch {
|
|
3367
|
+
return text("Malformed URI", { status: 400 });
|
|
3368
|
+
}
|
|
3369
|
+
if (
|
|
3370
|
+
// the resolved path has been decoded so it should be compared to the decoded url pathname
|
|
3371
|
+
resolved_path !== decode_pathname(url.pathname) && !state.prerendering?.fallback && has_prerendered_path(manifest, resolved_path)
|
|
3372
|
+
) {
|
|
3373
|
+
const url2 = new URL(request.url);
|
|
3374
|
+
url2.pathname = is_data_request ? add_data_suffix(resolved_path) : is_route_resolution_request ? add_resolution_suffix(resolved_path) : resolved_path;
|
|
3375
|
+
try {
|
|
3376
|
+
const response = await fetch(url2, request);
|
|
3377
|
+
const headers22 = new Headers(response.headers);
|
|
3378
|
+
if (headers22.has("content-encoding")) {
|
|
3379
|
+
headers22.delete("content-encoding");
|
|
3380
|
+
headers22.delete("content-length");
|
|
3381
|
+
}
|
|
3382
|
+
return new Response(response.body, {
|
|
3383
|
+
headers: headers22,
|
|
3384
|
+
status: response.status,
|
|
3385
|
+
statusText: response.statusText
|
|
3386
|
+
});
|
|
3387
|
+
} catch (error2) {
|
|
3388
|
+
return await handle_fatal_error(event, event_state, options2, error2);
|
|
3389
|
+
}
|
|
3390
|
+
}
|
|
3391
|
+
let route = null;
|
|
3392
|
+
if (base && !state.prerendering?.fallback) {
|
|
3393
|
+
if (!resolved_path.startsWith(base)) {
|
|
3394
|
+
return text("Not found", { status: 404 });
|
|
3395
|
+
}
|
|
3396
|
+
resolved_path = resolved_path.slice(base.length) || "/";
|
|
3397
|
+
}
|
|
3398
|
+
if (is_route_resolution_request) {
|
|
3399
|
+
return resolve_route(resolved_path, new URL(request.url), manifest);
|
|
3400
|
+
}
|
|
3401
|
+
if (resolved_path === `/${app_dir}/env.js`) {
|
|
3402
|
+
return get_public_env(request);
|
|
3403
|
+
}
|
|
3404
|
+
if (!remote_id && resolved_path.startsWith(`/${app_dir}`)) {
|
|
3405
|
+
const headers22 = new Headers();
|
|
3406
|
+
headers22.set("cache-control", "public, max-age=0, must-revalidate");
|
|
3407
|
+
return text("Not found", { status: 404, headers: headers22 });
|
|
3408
|
+
}
|
|
3409
|
+
if (!state.prerendering?.fallback) {
|
|
3410
|
+
const matchers = await manifest._.matchers();
|
|
3411
|
+
for (const candidate of manifest._.routes) {
|
|
3412
|
+
const match = candidate.pattern.exec(resolved_path);
|
|
3413
|
+
if (!match) continue;
|
|
3414
|
+
const matched = exec(match, candidate.params, matchers);
|
|
3415
|
+
if (matched) {
|
|
3416
|
+
route = candidate;
|
|
3417
|
+
event.route = { id: route.id };
|
|
3418
|
+
event.params = decode_params(matched);
|
|
3419
|
+
break;
|
|
3420
|
+
}
|
|
3421
|
+
}
|
|
3422
|
+
}
|
|
3423
|
+
let resolve_opts = {
|
|
3424
|
+
transformPageChunk: default_transform,
|
|
3425
|
+
filterSerializedResponseHeaders: default_filter,
|
|
3426
|
+
preload: default_preload
|
|
3427
|
+
};
|
|
3428
|
+
let trailing_slash = "never";
|
|
3429
|
+
try {
|
|
3430
|
+
const page_nodes = route?.page ? new PageNodes(await load_page_nodes(route.page, manifest)) : void 0;
|
|
3431
|
+
if (route && !remote_id) {
|
|
3432
|
+
if (url.pathname === base || url.pathname === base + "/") {
|
|
3433
|
+
trailing_slash = "always";
|
|
3434
|
+
} else if (page_nodes) {
|
|
3435
|
+
if (BROWSER) ;
|
|
3436
|
+
trailing_slash = page_nodes.trailing_slash();
|
|
3437
|
+
} else if (route.endpoint) {
|
|
3438
|
+
const node = await route.endpoint();
|
|
3439
|
+
trailing_slash = node.trailingSlash ?? "never";
|
|
3440
|
+
if (BROWSER) ;
|
|
3441
|
+
}
|
|
3442
|
+
if (!is_data_request) {
|
|
3443
|
+
const normalized = normalize_path(url.pathname, trailing_slash);
|
|
3444
|
+
if (normalized !== url.pathname && !state.prerendering?.fallback) {
|
|
3445
|
+
return new Response(void 0, {
|
|
3446
|
+
status: 308,
|
|
3447
|
+
headers: {
|
|
3448
|
+
"x-sveltekit-normalize": "1",
|
|
3449
|
+
location: (
|
|
3450
|
+
// ensure paths starting with '//' are not treated as protocol-relative
|
|
3451
|
+
(normalized.startsWith("//") ? url.origin + normalized : normalized) + (url.search === "?" ? "" : url.search)
|
|
3452
|
+
)
|
|
3453
|
+
}
|
|
3454
|
+
});
|
|
3455
|
+
}
|
|
3456
|
+
}
|
|
3457
|
+
if (state.before_handle || state.emulator?.platform) {
|
|
3458
|
+
let config = {};
|
|
3459
|
+
let prerender = false;
|
|
3460
|
+
if (route.endpoint) {
|
|
3461
|
+
const node = await route.endpoint();
|
|
3462
|
+
config = node.config ?? config;
|
|
3463
|
+
prerender = node.prerender ?? prerender;
|
|
3464
|
+
} else if (page_nodes) {
|
|
3465
|
+
config = page_nodes.get_config() ?? config;
|
|
3466
|
+
prerender = page_nodes.prerender();
|
|
3467
|
+
}
|
|
3468
|
+
if (state.before_handle) {
|
|
3469
|
+
state.before_handle(event, config, prerender);
|
|
3470
|
+
}
|
|
3471
|
+
if (state.emulator?.platform) {
|
|
3472
|
+
event.platform = await state.emulator.platform({ config, prerender });
|
|
3473
|
+
}
|
|
3474
|
+
}
|
|
3475
|
+
}
|
|
3476
|
+
set_trailing_slash(trailing_slash);
|
|
3477
|
+
if (state.prerendering && !state.prerendering.fallback && !state.prerendering.inside_reroute) {
|
|
3478
|
+
disable_search(url);
|
|
3479
|
+
}
|
|
3480
|
+
const response = await record_span({
|
|
3481
|
+
name: "sveltekit.handle.root",
|
|
3482
|
+
attributes: {
|
|
3483
|
+
"http.route": event.route.id || "unknown",
|
|
3484
|
+
"http.method": event.request.method,
|
|
3485
|
+
"http.url": event.url.href,
|
|
3486
|
+
"sveltekit.is_data_request": is_data_request,
|
|
3487
|
+
"sveltekit.is_sub_request": event.isSubRequest
|
|
3488
|
+
},
|
|
3489
|
+
fn: async (root_span) => {
|
|
3490
|
+
const traced_event = {
|
|
3491
|
+
...event,
|
|
3492
|
+
tracing: {
|
|
3493
|
+
enabled: false,
|
|
3494
|
+
root: root_span,
|
|
3495
|
+
current: root_span
|
|
3496
|
+
}
|
|
3497
|
+
};
|
|
3498
|
+
return await with_request_store(
|
|
3499
|
+
{ event: traced_event, state: event_state },
|
|
3500
|
+
() => options2.hooks.handle({
|
|
3501
|
+
event: traced_event,
|
|
3502
|
+
resolve: (event2, opts) => {
|
|
3503
|
+
return record_span({
|
|
3504
|
+
name: "sveltekit.resolve",
|
|
3505
|
+
attributes: {
|
|
3506
|
+
"http.route": event2.route.id || "unknown"
|
|
3507
|
+
},
|
|
3508
|
+
fn: (resolve_span) => {
|
|
3509
|
+
return with_request_store(
|
|
3510
|
+
null,
|
|
3511
|
+
() => resolve2(merge_tracing(event2, resolve_span), page_nodes, opts).then(
|
|
3512
|
+
(response2) => {
|
|
3513
|
+
for (const key2 in headers2) {
|
|
3514
|
+
const value = headers2[key2];
|
|
3515
|
+
response2.headers.set(
|
|
3516
|
+
key2,
|
|
3517
|
+
/** @type {string} */
|
|
3518
|
+
value
|
|
3519
|
+
);
|
|
3520
|
+
}
|
|
3521
|
+
add_cookies_to_headers(response2.headers, new_cookies.values());
|
|
3522
|
+
if (state.prerendering && event2.route.id !== null) {
|
|
3523
|
+
response2.headers.set("x-sveltekit-routeid", encodeURI(event2.route.id));
|
|
3524
|
+
}
|
|
3525
|
+
resolve_span.setAttributes({
|
|
3526
|
+
"http.response.status_code": response2.status,
|
|
3527
|
+
"http.response.body.size": response2.headers.get("content-length") || "unknown"
|
|
3528
|
+
});
|
|
3529
|
+
return response2;
|
|
3530
|
+
}
|
|
3531
|
+
)
|
|
3532
|
+
);
|
|
3533
|
+
}
|
|
3534
|
+
});
|
|
3535
|
+
}
|
|
3536
|
+
})
|
|
3537
|
+
);
|
|
3538
|
+
}
|
|
3539
|
+
});
|
|
3540
|
+
if (response.status === 200 && response.headers.has("etag")) {
|
|
3541
|
+
let if_none_match_value = request.headers.get("if-none-match");
|
|
3542
|
+
if (if_none_match_value?.startsWith('W/"')) {
|
|
3543
|
+
if_none_match_value = if_none_match_value.substring(2);
|
|
3544
|
+
}
|
|
3545
|
+
const etag2 = (
|
|
3546
|
+
/** @type {string} */
|
|
3547
|
+
response.headers.get("etag")
|
|
3548
|
+
);
|
|
3549
|
+
if (if_none_match_value === etag2) {
|
|
3550
|
+
const headers22 = new Headers({ etag: etag2 });
|
|
3551
|
+
for (const key2 of [
|
|
3552
|
+
"cache-control",
|
|
3553
|
+
"content-location",
|
|
3554
|
+
"date",
|
|
3555
|
+
"expires",
|
|
3556
|
+
"vary",
|
|
3557
|
+
"set-cookie"
|
|
3558
|
+
]) {
|
|
3559
|
+
const value = response.headers.get(key2);
|
|
3560
|
+
if (value) headers22.set(key2, value);
|
|
3561
|
+
}
|
|
3562
|
+
return new Response(void 0, {
|
|
3563
|
+
status: 304,
|
|
3564
|
+
headers: headers22
|
|
3565
|
+
});
|
|
3566
|
+
}
|
|
3567
|
+
}
|
|
3568
|
+
if (is_data_request && response.status >= 300 && response.status <= 308) {
|
|
3569
|
+
const location = response.headers.get("location");
|
|
3570
|
+
if (location) {
|
|
3571
|
+
return redirect_json_response(new Redirect(
|
|
3572
|
+
/** @type {any} */
|
|
3573
|
+
response.status,
|
|
3574
|
+
location
|
|
3575
|
+
));
|
|
3576
|
+
}
|
|
3577
|
+
}
|
|
3578
|
+
return response;
|
|
3579
|
+
} catch (e) {
|
|
3580
|
+
if (e instanceof Redirect) {
|
|
3581
|
+
const response = is_data_request || remote_id ? redirect_json_response(e) : route?.page && is_action_json_request(event) ? action_json_redirect(e) : redirect_response(e.status, e.location);
|
|
3582
|
+
add_cookies_to_headers(response.headers, new_cookies.values());
|
|
3583
|
+
return response;
|
|
3584
|
+
}
|
|
3585
|
+
return await handle_fatal_error(event, event_state, options2, e);
|
|
3586
|
+
}
|
|
3587
|
+
async function resolve2(event2, page_nodes, opts) {
|
|
3588
|
+
try {
|
|
3589
|
+
if (opts) {
|
|
3590
|
+
resolve_opts = {
|
|
3591
|
+
transformPageChunk: opts.transformPageChunk || default_transform,
|
|
3592
|
+
filterSerializedResponseHeaders: opts.filterSerializedResponseHeaders || default_filter,
|
|
3593
|
+
preload: opts.preload || default_preload
|
|
3594
|
+
};
|
|
3595
|
+
}
|
|
3596
|
+
if (options2.hash_routing || state.prerendering?.fallback) {
|
|
3597
|
+
return await render_response({
|
|
3598
|
+
event: event2,
|
|
3599
|
+
event_state,
|
|
3600
|
+
options: options2,
|
|
3601
|
+
manifest,
|
|
3602
|
+
state,
|
|
3603
|
+
page_config: { ssr: false, csr: true },
|
|
3604
|
+
status: 200,
|
|
3605
|
+
error: null,
|
|
3606
|
+
branch: [],
|
|
3607
|
+
fetched: [],
|
|
3608
|
+
resolve_opts,
|
|
3609
|
+
data_serializer: server_data_serializer(event2, event_state, options2)
|
|
3610
|
+
});
|
|
3611
|
+
}
|
|
3612
|
+
if (remote_id) {
|
|
3613
|
+
return await handle_remote_call(event2, event_state, options2, manifest, remote_id);
|
|
3614
|
+
}
|
|
3615
|
+
if (route) {
|
|
3616
|
+
const method = (
|
|
3617
|
+
/** @type {import('types').HttpMethod} */
|
|
3618
|
+
event2.request.method
|
|
3619
|
+
);
|
|
3620
|
+
let response2;
|
|
3621
|
+
if (is_data_request) {
|
|
3622
|
+
response2 = await render_data(
|
|
3623
|
+
event2,
|
|
3624
|
+
event_state,
|
|
3625
|
+
route,
|
|
3626
|
+
options2,
|
|
3627
|
+
manifest,
|
|
3628
|
+
state,
|
|
3629
|
+
invalidated_data_nodes,
|
|
3630
|
+
trailing_slash
|
|
3631
|
+
);
|
|
3632
|
+
} else if (route.endpoint && (!route.page || is_endpoint_request(event2))) {
|
|
3633
|
+
response2 = await render_endpoint(event2, event_state, await route.endpoint(), state);
|
|
3634
|
+
} else if (route.page) {
|
|
3635
|
+
if (!page_nodes) {
|
|
3636
|
+
throw new Error("page_nodes not found. This should never happen");
|
|
3637
|
+
} else if (page_methods.has(method)) {
|
|
3638
|
+
response2 = await render_page(
|
|
3639
|
+
event2,
|
|
3640
|
+
event_state,
|
|
3641
|
+
route.page,
|
|
3642
|
+
options2,
|
|
3643
|
+
manifest,
|
|
3644
|
+
state,
|
|
3645
|
+
page_nodes,
|
|
3646
|
+
resolve_opts
|
|
3647
|
+
);
|
|
3648
|
+
} else {
|
|
3649
|
+
const allowed_methods2 = new Set(allowed_page_methods);
|
|
3650
|
+
const node = await manifest._.nodes[route.page.leaf]();
|
|
3651
|
+
if (node?.server?.actions) {
|
|
3652
|
+
allowed_methods2.add("POST");
|
|
3653
|
+
}
|
|
3654
|
+
if (method === "OPTIONS") {
|
|
3655
|
+
response2 = new Response(null, {
|
|
3656
|
+
status: 204,
|
|
3657
|
+
headers: {
|
|
3658
|
+
allow: Array.from(allowed_methods2.values()).join(", ")
|
|
3659
|
+
}
|
|
3660
|
+
});
|
|
3661
|
+
} else {
|
|
3662
|
+
const mod = [...allowed_methods2].reduce(
|
|
3663
|
+
(acc, curr) => {
|
|
3664
|
+
acc[curr] = true;
|
|
3665
|
+
return acc;
|
|
3666
|
+
},
|
|
3667
|
+
/** @type {Record<string, any>} */
|
|
3668
|
+
{}
|
|
3669
|
+
);
|
|
3670
|
+
response2 = method_not_allowed(mod, method);
|
|
3671
|
+
}
|
|
3672
|
+
}
|
|
3673
|
+
} else {
|
|
3674
|
+
throw new Error("Route is neither page nor endpoint. This should never happen");
|
|
3675
|
+
}
|
|
3676
|
+
if (request.method === "GET" && route.page && route.endpoint) {
|
|
3677
|
+
const vary = response2.headers.get("vary")?.split(",")?.map((v) => v.trim().toLowerCase());
|
|
3678
|
+
if (!(vary?.includes("accept") || vary?.includes("*"))) {
|
|
3679
|
+
response2 = new Response(response2.body, {
|
|
3680
|
+
status: response2.status,
|
|
3681
|
+
statusText: response2.statusText,
|
|
3682
|
+
headers: new Headers(response2.headers)
|
|
3683
|
+
});
|
|
3684
|
+
response2.headers.append("Vary", "Accept");
|
|
3685
|
+
}
|
|
3686
|
+
}
|
|
3687
|
+
return response2;
|
|
3688
|
+
}
|
|
3689
|
+
if (state.error && event2.isSubRequest) {
|
|
3690
|
+
const headers22 = new Headers(request.headers);
|
|
3691
|
+
headers22.set("x-sveltekit-error", "true");
|
|
3692
|
+
return await fetch(request, { headers: headers22 });
|
|
3693
|
+
}
|
|
3694
|
+
if (state.error) {
|
|
3695
|
+
return text("Internal Server Error", {
|
|
3696
|
+
status: 500
|
|
3697
|
+
});
|
|
3698
|
+
}
|
|
3699
|
+
if (state.depth === 0) {
|
|
3700
|
+
if (BROWSER && event2.url.pathname === "/.well-known/appspecific/com.chrome.devtools.json") ;
|
|
3701
|
+
return await respond_with_error({
|
|
3702
|
+
event: event2,
|
|
3703
|
+
event_state,
|
|
3704
|
+
options: options2,
|
|
3705
|
+
manifest,
|
|
3706
|
+
state,
|
|
3707
|
+
status: 404,
|
|
3708
|
+
error: new SvelteKitError(404, "Not Found", `Not found: ${event2.url.pathname}`),
|
|
3709
|
+
resolve_opts
|
|
3710
|
+
});
|
|
3711
|
+
}
|
|
3712
|
+
if (state.prerendering) {
|
|
3713
|
+
return text("not found", { status: 404 });
|
|
3714
|
+
}
|
|
3715
|
+
const response = await fetch(request);
|
|
3716
|
+
return new Response(response.body, response);
|
|
3717
|
+
} catch (e) {
|
|
3718
|
+
return await handle_fatal_error(event2, event_state, options2, e);
|
|
3719
|
+
} finally {
|
|
3720
|
+
event2.cookies.set = () => {
|
|
3721
|
+
throw new Error("Cannot use `cookies.set(...)` after the response has been generated");
|
|
3722
|
+
};
|
|
3723
|
+
event2.setHeaders = () => {
|
|
3724
|
+
throw new Error("Cannot use `setHeaders(...)` after the response has been generated");
|
|
3725
|
+
};
|
|
3726
|
+
}
|
|
3727
|
+
}
|
|
3728
|
+
}
|
|
3729
|
+
function load_page_nodes(page, manifest) {
|
|
3730
|
+
return Promise.all([
|
|
3731
|
+
// we use == here rather than === because [undefined] serializes as "[null]"
|
|
3732
|
+
...page.layouts.map((n) => n == void 0 ? n : manifest._.nodes[n]()),
|
|
3733
|
+
manifest._.nodes[page.leaf]()
|
|
3734
|
+
]);
|
|
3735
|
+
}
|
|
3736
|
+
function propagate_context(fn) {
|
|
3737
|
+
return async (req, ...rest) => {
|
|
3738
|
+
{
|
|
3739
|
+
return fn(req, ...rest);
|
|
3740
|
+
}
|
|
3741
|
+
};
|
|
3742
|
+
}
|
|
3743
|
+
function filter_env(env, allowed, disallowed) {
|
|
3744
|
+
return Object.fromEntries(
|
|
3745
|
+
Object.entries(env).filter(
|
|
3746
|
+
([k]) => k.startsWith(allowed) && (disallowed === "" || !k.startsWith(disallowed))
|
|
3747
|
+
)
|
|
3748
|
+
);
|
|
3749
|
+
}
|
|
3750
|
+
function set_app(value) {
|
|
3751
|
+
}
|
|
3752
|
+
let init_promise;
|
|
3753
|
+
let current = null;
|
|
3754
|
+
class Server {
|
|
3755
|
+
/** @type {import('types').SSROptions} */
|
|
3756
|
+
#options;
|
|
3757
|
+
/** @type {import('@sveltejs/kit').SSRManifest} */
|
|
3758
|
+
#manifest;
|
|
3759
|
+
/** @param {import('@sveltejs/kit').SSRManifest} manifest */
|
|
3760
|
+
constructor(manifest) {
|
|
3761
|
+
this.#options = options;
|
|
3762
|
+
this.#manifest = manifest;
|
|
3763
|
+
if (IN_WEBCONTAINER) {
|
|
3764
|
+
const respond2 = this.respond.bind(this);
|
|
3765
|
+
this.respond = async (...args) => {
|
|
3766
|
+
const { promise, resolve: resolve2 } = (
|
|
3767
|
+
/** @type {PromiseWithResolvers<void>} */
|
|
3768
|
+
with_resolvers()
|
|
3769
|
+
);
|
|
3770
|
+
const previous = current;
|
|
3771
|
+
current = promise;
|
|
3772
|
+
await previous;
|
|
3773
|
+
return respond2(...args).finally(resolve2);
|
|
3774
|
+
};
|
|
3775
|
+
}
|
|
3776
|
+
}
|
|
3777
|
+
/**
|
|
3778
|
+
* @param {import('@sveltejs/kit').ServerInitOptions} opts
|
|
3779
|
+
*/
|
|
3780
|
+
async init({ env, read }) {
|
|
3781
|
+
const { env_public_prefix, env_private_prefix } = this.#options;
|
|
3782
|
+
set_private_env(filter_env(env, env_private_prefix, env_public_prefix));
|
|
3783
|
+
set_public_env(filter_env(env, env_public_prefix, env_private_prefix));
|
|
3784
|
+
if (read) {
|
|
3785
|
+
const wrapped_read = (file) => {
|
|
3786
|
+
const result = read(file);
|
|
3787
|
+
if (result instanceof ReadableStream) {
|
|
3788
|
+
return result;
|
|
3789
|
+
} else {
|
|
3790
|
+
return new ReadableStream({
|
|
3791
|
+
async start(controller) {
|
|
3792
|
+
try {
|
|
3793
|
+
const stream = await Promise.resolve(result);
|
|
3794
|
+
if (!stream) {
|
|
3795
|
+
controller.close();
|
|
3796
|
+
return;
|
|
3797
|
+
}
|
|
3798
|
+
const reader = stream.getReader();
|
|
3799
|
+
while (true) {
|
|
3800
|
+
const { done, value } = await reader.read();
|
|
3801
|
+
if (done) break;
|
|
3802
|
+
controller.enqueue(value);
|
|
3803
|
+
}
|
|
3804
|
+
controller.close();
|
|
3805
|
+
} catch (error2) {
|
|
3806
|
+
controller.error(error2);
|
|
3807
|
+
}
|
|
3808
|
+
}
|
|
3809
|
+
});
|
|
3810
|
+
}
|
|
3811
|
+
};
|
|
3812
|
+
set_read_implementation(wrapped_read);
|
|
3813
|
+
}
|
|
3814
|
+
await (init_promise ??= (async () => {
|
|
3815
|
+
try {
|
|
3816
|
+
const module = await get_hooks();
|
|
3817
|
+
this.#options.hooks = {
|
|
3818
|
+
handle: module.handle || (({ event, resolve: resolve2 }) => resolve2(event)),
|
|
3819
|
+
handleError: module.handleError || (({ status, error: error2, event }) => {
|
|
3820
|
+
const error_message = format_server_error(
|
|
3821
|
+
status,
|
|
3822
|
+
/** @type {Error} */
|
|
3823
|
+
error2,
|
|
3824
|
+
event
|
|
3825
|
+
);
|
|
3826
|
+
console.error(error_message);
|
|
3827
|
+
}),
|
|
3828
|
+
handleFetch: module.handleFetch || (({ request, fetch: fetch2 }) => fetch2(request)),
|
|
3829
|
+
handleValidationError: module.handleValidationError || (({ issues }) => {
|
|
3830
|
+
console.error("Remote function schema validation failed:", issues);
|
|
3831
|
+
return { message: "Bad Request" };
|
|
3832
|
+
}),
|
|
3833
|
+
reroute: module.reroute || (() => {
|
|
3834
|
+
}),
|
|
3835
|
+
transport: module.transport || {}
|
|
3836
|
+
};
|
|
3837
|
+
set_app({
|
|
3838
|
+
decoders: module.transport ? Object.fromEntries(Object.entries(module.transport).map(([k, v]) => [k, v.decode])) : {}
|
|
3839
|
+
});
|
|
3840
|
+
if (module.init) {
|
|
3841
|
+
await module.init();
|
|
3842
|
+
}
|
|
3843
|
+
} catch (e) {
|
|
3844
|
+
{
|
|
3845
|
+
throw e;
|
|
3846
|
+
}
|
|
3847
|
+
}
|
|
3848
|
+
})());
|
|
3849
|
+
}
|
|
3850
|
+
/**
|
|
3851
|
+
* @param {Request} request
|
|
3852
|
+
* @param {import('types').RequestOptions} options
|
|
3853
|
+
*/
|
|
3854
|
+
async respond(request, options2) {
|
|
3855
|
+
return respond(request, this.#options, this.#manifest, {
|
|
3856
|
+
...options2,
|
|
3857
|
+
error: false,
|
|
3858
|
+
depth: 0
|
|
3859
|
+
});
|
|
3860
|
+
}
|
|
3861
|
+
}
|
|
3862
|
+
export {
|
|
3863
|
+
Server
|
|
3864
|
+
};
|