@raybase/create 0.0.2 → 0.3.4
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/LICENSE +21 -0
- package/THIRD_PARTY_NOTICES.md +38 -0
- package/assets/apple-touch-icons/0.png +0 -0
- package/assets/apple-touch-icons/1.png +0 -0
- package/assets/apple-touch-icons/2.png +0 -0
- package/assets/apple-touch-icons/3.png +0 -0
- package/assets/apple-touch-icons/4.png +0 -0
- package/assets/apple-touch-icons/5.png +0 -0
- package/assets/apple-touch-icons/6.png +0 -0
- package/assets/apple-touch-icons/7.png +0 -0
- package/assets/apple-touch-icons/8.png +0 -0
- package/assets/apple-touch-icons/9.png +0 -0
- package/assets/apple-touch-icons/A.png +0 -0
- package/assets/apple-touch-icons/B.png +0 -0
- package/assets/apple-touch-icons/C.png +0 -0
- package/assets/apple-touch-icons/D.png +0 -0
- package/assets/apple-touch-icons/E.png +0 -0
- package/assets/apple-touch-icons/F.png +0 -0
- package/assets/apple-touch-icons/G.png +0 -0
- package/assets/apple-touch-icons/H.png +0 -0
- package/assets/apple-touch-icons/I.png +0 -0
- package/assets/apple-touch-icons/J.png +0 -0
- package/assets/apple-touch-icons/K.png +0 -0
- package/assets/apple-touch-icons/L.png +0 -0
- package/assets/apple-touch-icons/M.png +0 -0
- package/assets/apple-touch-icons/N.png +0 -0
- package/assets/apple-touch-icons/O.png +0 -0
- package/assets/apple-touch-icons/P.png +0 -0
- package/assets/apple-touch-icons/Q.png +0 -0
- package/assets/apple-touch-icons/R.png +0 -0
- package/assets/apple-touch-icons/S.png +0 -0
- package/assets/apple-touch-icons/T.png +0 -0
- package/assets/apple-touch-icons/U.png +0 -0
- package/assets/apple-touch-icons/V.png +0 -0
- package/assets/apple-touch-icons/W.png +0 -0
- package/assets/apple-touch-icons/X.png +0 -0
- package/assets/apple-touch-icons/Y.png +0 -0
- package/assets/apple-touch-icons/Z.png +0 -0
- package/assets/apple-touch-icons/default.png +0 -0
- package/dist/.source-hash +1 -0
- package/dist/index.d.ts +56 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2353 -0
- package/dist/index.js.map +1 -0
- package/dist/raybase-package-ranges.d.ts +11 -0
- package/dist/raybase-package-ranges.d.ts.map +1 -0
- package/dist/raybase-package-ranges.js +11 -0
- package/dist/raybase-package-ranges.js.map +1 -0
- package/dist/source-fetch.d.ts +91 -0
- package/dist/source-fetch.d.ts.map +1 -0
- package/dist/source-fetch.js +325 -0
- package/dist/source-fetch.js.map +1 -0
- package/dist/source-hash.d.ts +2 -0
- package/dist/source-hash.d.ts.map +1 -0
- package/dist/source-hash.js +23 -0
- package/dist/source-hash.js.map +1 -0
- package/dist/starter-description.d.ts +44 -0
- package/dist/starter-description.d.ts.map +1 -0
- package/dist/starter-description.js +273 -0
- package/dist/starter-description.js.map +1 -0
- package/dist/starter-source.d.ts +43 -0
- package/dist/starter-source.d.ts.map +1 -0
- package/dist/starter-source.js +156 -0
- package/dist/starter-source.js.map +1 -0
- package/dist/store-app-apply.d.ts +27 -0
- package/dist/store-app-apply.d.ts.map +1 -0
- package/dist/store-app-apply.js +100 -0
- package/dist/store-app-apply.js.map +1 -0
- package/dist/store-app-manifest.d.ts +86 -0
- package/dist/store-app-manifest.d.ts.map +1 -0
- package/dist/store-app-manifest.js +110 -0
- package/dist/store-app-manifest.js.map +1 -0
- package/dist/store-app-registry.d.ts +30 -0
- package/dist/store-app-registry.d.ts.map +1 -0
- package/dist/store-app-registry.js +232 -0
- package/dist/store-app-registry.js.map +1 -0
- package/models/recommended.json +42 -0
- package/modules/api/templates/react-router/app/api/operations.ts +8 -0
- package/modules/api/templates/tanstack-start/src/api/operations.ts +15 -0
- package/modules/docs/templates/astro-emdash/content/docs/getting-started.mdx +13 -0
- package/modules/docs/templates/astro-emdash/content/docs/index.mdx +13 -0
- package/modules/docs/templates/astro-emdash/content/docs/mcp.mdx +11 -0
- package/modules/docs/templates/astro-emdash/content/docs/meta.json +4 -0
- package/modules/docs/templates/astro-emdash/site/content/docs/getting-started.mdx +12 -0
- package/modules/docs/templates/astro-emdash/site/content/docs/index.mdx +12 -0
- package/modules/docs/templates/astro-emdash/site/content/docs/mcp.mdx +10 -0
- package/modules/docs/templates/astro-emdash/site/content/docs/meta.json +4 -0
- package/modules/docs/templates/astro-emdash/site/source.config.ts +10 -0
- package/modules/docs/templates/astro-emdash/site/src/docs/docs-assets.ts +1 -0
- package/modules/docs/templates/astro-emdash/site/src/docs/docs-client.tsx +22 -0
- package/modules/docs/templates/astro-emdash/site/src/docs/docs-data.ts +24 -0
- package/modules/docs/templates/astro-emdash/site/src/docs/docs-handler.tsx +105 -0
- package/modules/docs/templates/astro-emdash/site/src/docs/docs-layout.tsx +56 -0
- package/modules/docs/templates/astro-emdash/site/src/docs/docs-mdx.tsx +79 -0
- package/modules/docs/templates/astro-emdash/site/src/docs/docs-page-actions.tsx +146 -0
- package/modules/docs/templates/astro-emdash/site/src/docs/docs-page.tsx +70 -0
- package/modules/docs/templates/astro-emdash/site/src/docs/llm-text.ts +61 -0
- package/modules/docs/templates/astro-emdash/site/src/docs/source.ts +7 -0
- package/modules/docs/templates/astro-emdash/site/src/pages/docs/[...slug].ts +6 -0
- package/modules/docs/templates/astro-emdash/site/src/pages/docs/api/markdown.ts +4 -0
- package/modules/docs/templates/astro-emdash/site/src/pages/docs/api/search.ts +4 -0
- package/modules/docs/templates/astro-emdash/site/src/pages/llms.txt.ts +8 -0
- package/modules/docs/templates/astro-emdash/site/src/styles-docs.css +3 -0
- package/modules/docs/templates/astro-emdash/source.config.ts +10 -0
- package/modules/docs/templates/astro-emdash/src/docs/docs-assets.ts +1 -0
- package/modules/docs/templates/astro-emdash/src/docs/docs-client.tsx +22 -0
- package/modules/docs/templates/astro-emdash/src/docs/docs-data.ts +24 -0
- package/modules/docs/templates/astro-emdash/src/docs/docs-handler.tsx +105 -0
- package/modules/docs/templates/astro-emdash/src/docs/docs-layout.tsx +56 -0
- package/modules/docs/templates/astro-emdash/src/docs/docs-mdx.tsx +79 -0
- package/modules/docs/templates/astro-emdash/src/docs/docs-page-actions.tsx +146 -0
- package/modules/docs/templates/astro-emdash/src/docs/docs-page.tsx +70 -0
- package/modules/docs/templates/astro-emdash/src/docs/llm-text.ts +61 -0
- package/modules/docs/templates/astro-emdash/src/docs/source.ts +7 -0
- package/modules/docs/templates/astro-emdash/src/routes/docs/$.tsx +22 -0
- package/modules/docs/templates/astro-emdash/src/routes/docs/api/markdown.ts +12 -0
- package/modules/docs/templates/astro-emdash/src/routes/docs/api/search.ts +12 -0
- package/modules/docs/templates/astro-emdash/src/routes/docs.index.tsx +22 -0
- package/modules/docs/templates/astro-emdash/src/routes/docs.tsx +22 -0
- package/modules/docs/templates/astro-emdash/src/styles-docs.css +3 -0
- package/modules/docs/templates/react-router/app/components/mdx.tsx +79 -0
- package/modules/docs/templates/react-router/app/lib/layout.shared.tsx +54 -0
- package/modules/docs/templates/react-router/app/lib/source.ts +7 -0
- package/modules/docs/templates/react-router/app/routes/docs.$.tsx +49 -0
- package/modules/docs/templates/react-router/app/routes/docs.api.search.ts +10 -0
- package/modules/docs/templates/react-router/app/routes/docs.tsx +13 -0
- package/modules/docs/templates/react-router/content/docs/getting-started.mdx +8 -0
- package/modules/docs/templates/react-router/content/docs/index.mdx +8 -0
- package/modules/docs/templates/react-router/content/docs/mcp.mdx +121 -0
- package/modules/docs/templates/react-router/content/docs/meta.json +4 -0
- package/modules/docs/templates/react-router/source.config.ts +5 -0
- package/modules/docs/templates/tanstack-start/content/docs/getting-started.mdx +10 -0
- package/modules/docs/templates/tanstack-start/content/docs/index.mdx +8 -0
- package/modules/docs/templates/tanstack-start/content/docs/mcp.mdx +121 -0
- package/modules/docs/templates/tanstack-start/content/docs/meta.json +4 -0
- package/modules/docs/templates/tanstack-start/source.config.ts +10 -0
- package/modules/docs/templates/tanstack-start/src/docs/docs-assets.ts +1 -0
- package/modules/docs/templates/tanstack-start/src/docs/docs-client.tsx +22 -0
- package/modules/docs/templates/tanstack-start/src/docs/docs-data.ts +24 -0
- package/modules/docs/templates/tanstack-start/src/docs/docs-handler.tsx +105 -0
- package/modules/docs/templates/tanstack-start/src/docs/docs-layout.tsx +56 -0
- package/modules/docs/templates/tanstack-start/src/docs/docs-mdx.tsx +79 -0
- package/modules/docs/templates/tanstack-start/src/docs/docs-page-actions.tsx +146 -0
- package/modules/docs/templates/tanstack-start/src/docs/docs-page.tsx +70 -0
- package/modules/docs/templates/tanstack-start/src/docs/llm-text.ts +61 -0
- package/modules/docs/templates/tanstack-start/src/docs/source.ts +7 -0
- package/modules/docs/templates/tanstack-start/src/routes/docs/$.tsx +22 -0
- package/modules/docs/templates/tanstack-start/src/routes/docs/api/markdown.ts +12 -0
- package/modules/docs/templates/tanstack-start/src/routes/docs/api/search.ts +12 -0
- package/modules/docs/templates/tanstack-start/src/routes/docs.index.tsx +22 -0
- package/modules/docs/templates/tanstack-start/src/routes/docs.tsx +22 -0
- package/modules/docs/templates/tanstack-start/src/styles-docs.css +3 -0
- package/modules/guide/templates/astro-emdash/content/guide/capability-map.md +17 -0
- package/modules/guide/templates/astro-emdash/src/components/guide-widget.tsx +41 -0
- package/modules/guide/templates/astro-emdash/src/guide/actions.ts +8 -0
- package/modules/guide/templates/astro-emdash/src/guide/config.ts +21 -0
- package/modules/guide/templates/astro-emdash/src/guide/corpus.gen.ts +4 -0
- package/modules/guide/templates/astro-emdash/src/guide/corpus.manifest.json +72 -0
- package/modules/guide/templates/astro-emdash/src/guide/corpus.ts +4 -0
- package/modules/guide/templates/astro-emdash/src/guide/resources.json +4 -0
- package/modules/guide/templates/react-router/app/components/guide-widget.tsx +29 -0
- package/modules/guide/templates/react-router/app/guide/actions.ts +3 -0
- package/modules/guide/templates/react-router/app/guide/config.ts +21 -0
- package/modules/guide/templates/react-router/app/guide/corpus.gen.ts +4 -0
- package/modules/guide/templates/react-router/app/guide/corpus.manifest.json +22 -0
- package/modules/guide/templates/react-router/app/guide/corpus.ts +4 -0
- package/modules/guide/templates/react-router/app/guide/resources.json +4 -0
- package/modules/guide/templates/react-router/content/guide/capability-map.md +13 -0
- package/modules/guide/templates/tanstack-start/content/guide/capability-map.md +17 -0
- package/modules/guide/templates/tanstack-start/src/components/guide-widget.tsx +41 -0
- package/modules/guide/templates/tanstack-start/src/guide/actions.ts +17 -0
- package/modules/guide/templates/tanstack-start/src/guide/config.ts +21 -0
- package/modules/guide/templates/tanstack-start/src/guide/corpus.gen.ts +4 -0
- package/modules/guide/templates/tanstack-start/src/guide/corpus.manifest.json +22 -0
- package/modules/guide/templates/tanstack-start/src/guide/corpus.ts +4 -0
- package/modules/guide/templates/tanstack-start/src/guide/resources.json +4 -0
- package/modules/openai-subscription/templates/astro-emdash/.agents/skills/raybase-openai-subscription/SKILL.md +57 -0
- package/modules/openai-subscription/templates/astro-emdash/.agents/skills/raybase-openai-subscription/references/compatibility-and-testing.md +129 -0
- package/modules/openai-subscription/templates/astro-emdash/.agents/skills/raybase-openai-subscription/references/module-contract.md +133 -0
- package/modules/openai-subscription/templates/astro-emdash/.agents/skills/raybase-openai-subscription/references/structured-outputs.md +159 -0
- package/modules/openai-subscription/templates/astro-emdash/src/openai-subscription.ts +11 -0
- package/modules/openai-subscription/templates/react-router/.agents/skills/raybase-openai-subscription/SKILL.md +57 -0
- package/modules/openai-subscription/templates/react-router/.agents/skills/raybase-openai-subscription/references/compatibility-and-testing.md +129 -0
- package/modules/openai-subscription/templates/react-router/.agents/skills/raybase-openai-subscription/references/module-contract.md +133 -0
- package/modules/openai-subscription/templates/react-router/.agents/skills/raybase-openai-subscription/references/structured-outputs.md +159 -0
- package/modules/openai-subscription/templates/react-router/app/openai-subscription.ts +11 -0
- package/modules/openai-subscription/templates/tanstack-start/.agents/skills/raybase-openai-subscription/SKILL.md +57 -0
- package/modules/openai-subscription/templates/tanstack-start/.agents/skills/raybase-openai-subscription/references/compatibility-and-testing.md +129 -0
- package/modules/openai-subscription/templates/tanstack-start/.agents/skills/raybase-openai-subscription/references/module-contract.md +133 -0
- package/modules/openai-subscription/templates/tanstack-start/.agents/skills/raybase-openai-subscription/references/structured-outputs.md +159 -0
- package/modules/openai-subscription/templates/tanstack-start/src/openai-subscription.ts +11 -0
- package/package.json +34 -8
- package/skills/README.md +122 -0
- package/skills/raybase-actions/SKILL.md +223 -0
- package/skills/raybase-actions/references/action-patterns.md +190 -0
- package/skills/raybase-actions/references/adapting-actions.md +93 -0
- package/skills/raybase-actions/references/testing-actions.md +48 -0
- package/skills/raybase-agent-debugging/SKILL.md +230 -0
- package/skills/raybase-ai/SKILL.md +1310 -0
- package/skills/raybase-api/SKILL.md +45 -0
- package/skills/raybase-astro-emdash/SKILL.md +143 -0
- package/skills/raybase-astro-emdash-content-model/SKILL.md +217 -0
- package/skills/raybase-astro-emdash-content-model/references/LICENSE-emdash +9 -0
- package/skills/raybase-astro-emdash-content-model/references/emdash-collections.md +265 -0
- package/skills/raybase-astro-emdash-design/LICENSE-impeccable +60 -0
- package/skills/raybase-astro-emdash-design/SKILL.md +170 -0
- package/skills/raybase-astro-emdash-design/reference/color.md +91 -0
- package/skills/raybase-astro-emdash-design/reference/copy.md +73 -0
- package/skills/raybase-astro-emdash-design/reference/direction.md +115 -0
- package/skills/raybase-astro-emdash-design/reference/imagery.md +84 -0
- package/skills/raybase-astro-emdash-design/reference/layout.md +69 -0
- package/skills/raybase-astro-emdash-design/reference/motion.md +75 -0
- package/skills/raybase-astro-emdash-design/reference/polish.md +75 -0
- package/skills/raybase-astro-emdash-design/reference/typography.md +72 -0
- package/skills/raybase-astro-emdash-galley/SKILL.md +265 -0
- package/skills/raybase-astro-emdash-migration/SKILL.md +218 -0
- package/skills/raybase-astro-emdash-migration/references/inventory-and-conversion.md +242 -0
- package/skills/raybase-astro-emdash-security-review/SKILL.md +68 -0
- package/skills/raybase-astro-emdash-theme-selection/SKILL.md +216 -0
- package/skills/raybase-auth/SKILL.md +358 -0
- package/skills/raybase-background-jobs/SKILL.md +774 -0
- package/skills/raybase-building/SKILL.md +409 -0
- package/skills/raybase-building/references/interview-and-spec.md +87 -0
- package/skills/raybase-building/references/planning-docs.md +26 -0
- package/skills/raybase-building/references/schema-and-config.md +70 -0
- package/skills/raybase-changing-a-live-app/SKILL.md +119 -0
- package/skills/raybase-data-and-policies/SKILL.md +377 -0
- package/skills/raybase-deploy/SKILL.md +136 -0
- package/skills/raybase-docs-writing/SKILL.md +119 -0
- package/skills/raybase-guide/SKILL.md +235 -0
- package/skills/raybase-mcp/SKILL.md +309 -0
- package/skills/raybase-mcp/agents/openai.yaml +4 -0
- package/skills/raybase-notifications/SKILL.md +138 -0
- package/skills/raybase-pro-migration/SKILL.md +28 -0
- package/skills/raybase-react-router/SKILL.md +241 -0
- package/skills/raybase-react-router-design/LICENSE-impeccable +60 -0
- package/skills/raybase-react-router-design/SKILL.md +135 -0
- package/skills/raybase-react-router-design/reference/color.md +87 -0
- package/skills/raybase-react-router-design/reference/copy.md +83 -0
- package/skills/raybase-react-router-design/reference/delight.md +48 -0
- package/skills/raybase-react-router-design/reference/interaction.md +91 -0
- package/skills/raybase-react-router-design/reference/layout.md +82 -0
- package/skills/raybase-react-router-design/reference/motion.md +86 -0
- package/skills/raybase-react-router-design/reference/polish.md +79 -0
- package/skills/raybase-react-router-design/reference/typography.md +71 -0
- package/skills/raybase-react-router-security-review/LICENSE +22 -0
- package/skills/raybase-react-router-security-review/SKILL.md +190 -0
- package/skills/raybase-react-router-security-review/agents/openai.yaml +4 -0
- package/skills/raybase-react-router-security-review/references/api-security.md +519 -0
- package/skills/raybase-react-router-security-review/references/authentication.md +353 -0
- package/skills/raybase-react-router-security-review/references/authorization.md +372 -0
- package/skills/raybase-react-router-security-review/references/business-logic.md +443 -0
- package/skills/raybase-react-router-security-review/references/cryptography.md +329 -0
- package/skills/raybase-react-router-security-review/references/csrf.md +398 -0
- package/skills/raybase-react-router-security-review/references/data-protection.md +378 -0
- package/skills/raybase-react-router-security-review/references/deserialization.md +410 -0
- package/skills/raybase-react-router-security-review/references/error-handling.md +436 -0
- package/skills/raybase-react-router-security-review/references/file-security.md +457 -0
- package/skills/raybase-react-router-security-review/references/injection.md +259 -0
- package/skills/raybase-react-router-security-review/references/logging.md +433 -0
- package/skills/raybase-react-router-security-review/references/misconfiguration.md +435 -0
- package/skills/raybase-react-router-security-review/references/modern-threats.md +475 -0
- package/skills/raybase-react-router-security-review/references/raybase-react-router-security.md +235 -0
- package/skills/raybase-react-router-security-review/references/ssrf.md +413 -0
- package/skills/raybase-react-router-security-review/references/supply-chain.md +405 -0
- package/skills/raybase-react-router-security-review/references/xss.md +336 -0
- package/skills/raybase-realtime/SKILL.md +158 -0
- package/skills/raybase-realtime/agents/openai.yaml +4 -0
- package/skills/raybase-schema/SKILL.md +209 -0
- package/skills/raybase-search/SKILL.md +137 -0
- package/skills/raybase-search/agents/openai.yaml +4 -0
- package/skills/raybase-settings/SKILL.md +139 -0
- package/skills/raybase-settings/agents/openai.yaml +4 -0
- package/skills/raybase-tanstack-start/SKILL.md +166 -0
- package/skills/raybase-tanstack-start-design/LICENSE-impeccable +60 -0
- package/skills/raybase-tanstack-start-design/SKILL.md +140 -0
- package/skills/raybase-tanstack-start-design/reference/color.md +80 -0
- package/skills/raybase-tanstack-start-design/reference/copy.md +83 -0
- package/skills/raybase-tanstack-start-design/reference/delight.md +48 -0
- package/skills/raybase-tanstack-start-design/reference/interaction.md +91 -0
- package/skills/raybase-tanstack-start-design/reference/layout.md +82 -0
- package/skills/raybase-tanstack-start-design/reference/motion.md +86 -0
- package/skills/raybase-tanstack-start-design/reference/polish.md +79 -0
- package/skills/raybase-tanstack-start-design/reference/typography.md +71 -0
- package/skills/raybase-tanstack-start-security-review/LICENSE +22 -0
- package/skills/raybase-tanstack-start-security-review/SKILL.md +194 -0
- package/skills/raybase-tanstack-start-security-review/agents/openai.yaml +4 -0
- package/skills/raybase-tanstack-start-security-review/references/api-security.md +519 -0
- package/skills/raybase-tanstack-start-security-review/references/authentication.md +353 -0
- package/skills/raybase-tanstack-start-security-review/references/authorization.md +372 -0
- package/skills/raybase-tanstack-start-security-review/references/business-logic.md +443 -0
- package/skills/raybase-tanstack-start-security-review/references/cryptography.md +329 -0
- package/skills/raybase-tanstack-start-security-review/references/csrf.md +398 -0
- package/skills/raybase-tanstack-start-security-review/references/data-protection.md +378 -0
- package/skills/raybase-tanstack-start-security-review/references/deserialization.md +410 -0
- package/skills/raybase-tanstack-start-security-review/references/error-handling.md +436 -0
- package/skills/raybase-tanstack-start-security-review/references/file-security.md +457 -0
- package/skills/raybase-tanstack-start-security-review/references/injection.md +259 -0
- package/skills/raybase-tanstack-start-security-review/references/logging.md +433 -0
- package/skills/raybase-tanstack-start-security-review/references/misconfiguration.md +435 -0
- package/skills/raybase-tanstack-start-security-review/references/modern-threats.md +475 -0
- package/skills/raybase-tanstack-start-security-review/references/raybase-tanstack-security.md +208 -0
- package/skills/raybase-tanstack-start-security-review/references/ssrf.md +413 -0
- package/skills/raybase-tanstack-start-security-review/references/supply-chain.md +405 -0
- package/skills/raybase-tanstack-start-security-review/references/xss.md +336 -0
- package/skills-manifest.json +41 -0
- package/templates/astro-emdash/.dev.vars.example +7 -0
- package/templates/astro-emdash/AGENTS.md +122 -0
- package/templates/astro-emdash/DESIGN.md +90 -0
- package/templates/astro-emdash/components.json +21 -0
- package/templates/astro-emdash/content/docs/getting-started.mdx +20 -0
- package/templates/astro-emdash/content/docs/index.mdx +13 -0
- package/templates/astro-emdash/content/docs/mcp.mdx +11 -0
- package/templates/astro-emdash/content/docs/meta.json +4 -0
- package/templates/astro-emdash/content/docs/site-templates.mdx +62 -0
- package/templates/astro-emdash/dev/CODEBASE-MAP.md +46 -0
- package/templates/astro-emdash/dev/SPEC-OVERVIEW.md +15 -0
- package/templates/astro-emdash/dev/SPEC.md +84 -0
- package/templates/astro-emdash/dev/features/archive/.gitkeep +1 -0
- package/templates/astro-emdash/docs/theme-previews/base.svg +24 -0
- package/templates/astro-emdash/docs/theme-previews/steel.svg +24 -0
- package/templates/astro-emdash/docs/theme-previews/zen.svg +24 -0
- package/templates/astro-emdash/docs/themes.md +106 -0
- package/templates/astro-emdash/drizzle.config.ts +5 -0
- package/templates/astro-emdash/gitignore +11 -0
- package/templates/astro-emdash/migrations/app/meta/_journal.json +5 -0
- package/templates/astro-emdash/package.json +79 -0
- package/templates/astro-emdash/pnpm-workspace.yaml +71 -0
- package/templates/astro-emdash/public/_headers +4 -0
- package/templates/astro-emdash/site/astro.config.mjs +120 -0
- package/templates/astro-emdash/site/demo/README.md +72 -0
- package/templates/astro-emdash/site/demo/content/collection.json +43 -0
- package/templates/astro-emdash/site/demo/content/entries.json +120 -0
- package/templates/astro-emdash/site/demo/templates/demo-article-card/manifest.json +51 -0
- package/templates/astro-emdash/site/demo/templates/demo-article-card/sample-content.json +5 -0
- package/templates/astro-emdash/site/demo/templates/demo-article-card/template.liquid +48 -0
- package/templates/astro-emdash/site/demo/templates/demo-article-page/host.json +9 -0
- package/templates/astro-emdash/site/demo/templates/demo-article-page/manifest.json +38 -0
- package/templates/astro-emdash/site/demo/templates/demo-article-page/sample-content.json +34 -0
- package/templates/astro-emdash/site/demo/templates/demo-article-page/template.liquid +84 -0
- package/templates/astro-emdash/site/demo/templates/demo-articles-index/manifest.json +64 -0
- package/templates/astro-emdash/site/demo/templates/demo-articles-index/page.json +7 -0
- package/templates/astro-emdash/site/demo/templates/demo-articles-index/sample-content.json +24 -0
- package/templates/astro-emdash/site/demo/templates/demo-articles-index/template.liquid +100 -0
- package/templates/astro-emdash/site/demo/templates/demo-menu-nav/manifest.json +51 -0
- package/templates/astro-emdash/site/demo/templates/demo-menu-nav/sample-content.json +5 -0
- package/templates/astro-emdash/site/demo/templates/demo-menu-nav/template.liquid +70 -0
- package/templates/astro-emdash/site/gitignore +1 -0
- package/templates/astro-emdash/site/package.json +56 -0
- package/templates/astro-emdash/site/scripts/apply-site-templates.mjs +560 -0
- package/templates/astro-emdash/site/scripts/galley-demo.mjs +298 -0
- package/templates/astro-emdash/site/scripts/seed-galley-starter.mjs +360 -0
- package/templates/astro-emdash/site/scripts/site-origin.mjs +45 -0
- package/templates/astro-emdash/site/seed/seed.json +154 -0
- package/templates/astro-emdash/site/seed/templates/.gitkeep +1 -0
- package/templates/astro-emdash/site/src/components/RaybaseSignedInMenu.astro +163 -0
- package/templates/astro-emdash/site/src/components/blocks/RaybaseActionIsland.astro +41 -0
- package/templates/astro-emdash/site/src/content-door/raybase-routes.ts +738 -0
- package/templates/astro-emdash/site/src/content-door/resolve-page.ts +142 -0
- package/templates/astro-emdash/site/src/content-door/seed.ts +85 -0
- package/templates/astro-emdash/site/src/env.d.ts +12 -0
- package/templates/astro-emdash/site/src/layouts/SiteLayout.astro +68 -0
- package/templates/astro-emdash/site/src/lib/palettes.gen.ts +7 -0
- package/templates/astro-emdash/site/src/lib/site-motion.ts +169 -0
- package/templates/astro-emdash/site/src/lib/site-shell.ts +294 -0
- package/templates/astro-emdash/site/src/live.config.ts +8 -0
- package/templates/astro-emdash/site/src/middleware.ts +20 -0
- package/templates/astro-emdash/site/src/pages/[...slug].astro +113 -0
- package/templates/astro-emdash/site/src/pages/_raybase/handoff/consume.ts +6 -0
- package/templates/astro-emdash/site/src/pages/_raybase/islands/action.ts +8 -0
- package/templates/astro-emdash/site/src/pages/_raybase/sign-out/index.ts +6 -0
- package/templates/astro-emdash/site/src/styles/palette-fonts.gen.css +1 -0
- package/templates/astro-emdash/site/src/styles/palettes.gen.css +3 -0
- package/templates/astro-emdash/site/src/styles.css +607 -0
- package/templates/astro-emdash/site/tsconfig.json +12 -0
- package/templates/astro-emdash/site/wrangler.jsonc +34 -0
- package/templates/astro-emdash/source.config.ts +10 -0
- package/templates/astro-emdash/src/actions.ts +58 -0
- package/templates/astro-emdash/src/ai/agents.ts +20 -0
- package/templates/astro-emdash/src/ai/retrieval.ts +36 -0
- package/templates/astro-emdash/src/auth-door.ts +18 -0
- package/templates/astro-emdash/src/client.tsx +25 -0
- package/templates/astro-emdash/src/components/.gitkeep +1 -0
- package/templates/astro-emdash/src/components/account-menu.tsx +91 -0
- package/templates/astro-emdash/src/components/auth-shell.tsx +69 -0
- package/templates/astro-emdash/src/components/mode-toggle.tsx +32 -0
- package/templates/astro-emdash/src/components/search-command-palette.tsx +107 -0
- package/templates/astro-emdash/src/components/setup-token-page.tsx +196 -0
- package/templates/astro-emdash/src/components/ui/avatar.tsx +107 -0
- package/templates/astro-emdash/src/components/ui/badge.tsx +52 -0
- package/templates/astro-emdash/src/components/ui/button.tsx +69 -0
- package/templates/astro-emdash/src/components/ui/checkbox.tsx +29 -0
- package/templates/astro-emdash/src/components/ui/dialog.tsx +158 -0
- package/templates/astro-emdash/src/components/ui/dropdown-menu.tsx +303 -0
- package/templates/astro-emdash/src/components/ui/input.tsx +20 -0
- package/templates/astro-emdash/src/components/ui/label.tsx +20 -0
- package/templates/astro-emdash/src/components/ui/scroll-area.tsx +53 -0
- package/templates/astro-emdash/src/components/ui/select.tsx +215 -0
- package/templates/astro-emdash/src/components/ui/separator.tsx +23 -0
- package/templates/astro-emdash/src/components/ui/sheet.tsx +138 -0
- package/templates/astro-emdash/src/components/ui/sidebar.tsx +728 -0
- package/templates/astro-emdash/src/components/ui/skeleton.tsx +13 -0
- package/templates/astro-emdash/src/components/ui/textarea.tsx +18 -0
- package/templates/astro-emdash/src/components/ui/tooltip.tsx +66 -0
- package/templates/astro-emdash/src/db/migrations.gen.ts +6 -0
- package/templates/astro-emdash/src/db/schema.ts +6 -0
- package/templates/astro-emdash/src/db/seed.ts +16 -0
- package/templates/astro-emdash/src/db/storage.ts +32 -0
- package/templates/astro-emdash/src/docs/docs-assets.ts +1 -0
- package/templates/astro-emdash/src/docs/docs-client.tsx +22 -0
- package/templates/astro-emdash/src/docs/docs-data.ts +24 -0
- package/templates/astro-emdash/src/docs/docs-handler.tsx +105 -0
- package/templates/astro-emdash/src/docs/docs-layout.tsx +56 -0
- package/templates/astro-emdash/src/docs/docs-mdx.tsx +79 -0
- package/templates/astro-emdash/src/docs/docs-page-actions.tsx +146 -0
- package/templates/astro-emdash/src/docs/docs-page.tsx +70 -0
- package/templates/astro-emdash/src/docs/llm-text.ts +61 -0
- package/templates/astro-emdash/src/docs/source.ts +7 -0
- package/templates/astro-emdash/src/guide/corpus.gen.ts +4 -0
- package/templates/astro-emdash/src/guide/corpus.manifest.json +72 -0
- package/templates/astro-emdash/src/hooks/use-mobile.ts +19 -0
- package/templates/astro-emdash/src/jobs.example.ts +48 -0
- package/templates/astro-emdash/src/lib/account.ts +12 -0
- package/templates/astro-emdash/src/lib/auth-client.ts +181 -0
- package/templates/astro-emdash/src/lib/utils.ts +6 -0
- package/templates/astro-emdash/src/mcp-app.ts +57 -0
- package/templates/astro-emdash/src/notifications.example.ts +37 -0
- package/templates/astro-emdash/src/raybase.auth.ts +70 -0
- package/templates/astro-emdash/src/raybase.config.ts +49 -0
- package/templates/astro-emdash/src/raybase.server.ts +56 -0
- package/templates/astro-emdash/src/realtime.example.ts +18 -0
- package/templates/astro-emdash/src/router.tsx +19 -0
- package/templates/astro-emdash/src/routes/__root.tsx +56 -0
- package/templates/astro-emdash/src/routes/_app/admin.tsx +13 -0
- package/templates/astro-emdash/src/routes/_app/forgot-password.tsx +97 -0
- package/templates/astro-emdash/src/routes/_app/index.tsx +169 -0
- package/templates/astro-emdash/src/routes/_app/invite.$token.tsx +11 -0
- package/templates/astro-emdash/src/routes/_app/login.tsx +193 -0
- package/templates/astro-emdash/src/routes/_app/profile.tsx +98 -0
- package/templates/astro-emdash/src/routes/_app/reset-password.$token.tsx +15 -0
- package/templates/astro-emdash/src/routes/_app/reset-password.tsx +115 -0
- package/templates/astro-emdash/src/routes/_app/setup.$token.tsx +11 -0
- package/templates/astro-emdash/src/routes/_app/signup.tsx +141 -0
- package/templates/astro-emdash/src/routes/_app/verify-email.$token.tsx +15 -0
- package/templates/astro-emdash/src/routes/_app/verify-email.tsx +154 -0
- package/templates/astro-emdash/src/routes/_app.tsx +33 -0
- package/templates/astro-emdash/src/routes/admin/$.ts +20 -0
- package/templates/astro-emdash/src/routes/api/$.ts +19 -0
- package/templates/astro-emdash/src/routes/docs/$.tsx +22 -0
- package/templates/astro-emdash/src/routes/docs/api/markdown.ts +12 -0
- package/templates/astro-emdash/src/routes/docs/api/search.ts +12 -0
- package/templates/astro-emdash/src/routes/docs.index.tsx +22 -0
- package/templates/astro-emdash/src/routes/docs.tsx +22 -0
- package/templates/astro-emdash/src/search.ts +6 -0
- package/templates/astro-emdash/src/settings.ts +12 -0
- package/templates/astro-emdash/src/styles-docs.css +3 -0
- package/templates/astro-emdash/src/styles.css +101 -0
- package/templates/astro-emdash/src/themes/base.css +76 -0
- package/templates/astro-emdash/src/themes/carbon.css +76 -0
- package/templates/astro-emdash/src/themes/fonts.css +25 -0
- package/templates/astro-emdash/src/themes/sage.css +76 -0
- package/templates/astro-emdash/src/themes/sand.css +76 -0
- package/templates/astro-emdash/src/themes/slate.css +81 -0
- package/templates/astro-emdash/src/themes/ultra.css +76 -0
- package/templates/astro-emdash/src/themes/zen.css +76 -0
- package/templates/astro-emdash/src/worker-entry.ts +31 -0
- package/templates/astro-emdash/tests/raybase-patterns.test.ts +29 -0
- package/templates/astro-emdash/tsconfig.json +36 -0
- package/templates/astro-emdash/vite.config.ts +130 -0
- package/templates/astro-emdash/vitest.config.ts +8 -0
- package/templates/astro-emdash/wrangler.jsonc +112 -0
- package/templates/react-router/.dev.vars.example +5 -0
- package/templates/react-router/.editorconfig +15 -0
- package/templates/react-router/AGENTS.md +54 -0
- package/templates/react-router/README.md +52 -0
- package/templates/react-router/app/app.css +44 -0
- package/templates/react-router/app/components/mdx.tsx +79 -0
- package/templates/react-router/app/components/ui/button.tsx +45 -0
- package/templates/react-router/app/components/ui/card.tsx +87 -0
- package/templates/react-router/app/components/ui/separator.tsx +22 -0
- package/templates/react-router/app/db/migrations.gen.ts +6 -0
- package/templates/react-router/app/db/schema.ts +56 -0
- package/templates/react-router/app/db/seed.ts +14 -0
- package/templates/react-router/app/entry.server.tsx +41 -0
- package/templates/react-router/app/globals.d.ts +1 -0
- package/templates/react-router/app/lib/layout.shared.tsx +52 -0
- package/templates/react-router/app/lib/source.ts +7 -0
- package/templates/react-router/app/lib/utils.ts +6 -0
- package/templates/react-router/app/raybase.server.ts +65 -0
- package/templates/react-router/app/root.tsx +23 -0
- package/templates/react-router/app/routes/_index.tsx +53 -0
- package/templates/react-router/app/routes/docs.$.tsx +49 -0
- package/templates/react-router/app/routes/docs.api.search.ts +10 -0
- package/templates/react-router/app/routes/docs.tsx +13 -0
- package/templates/react-router/app/routes.ts +3 -0
- package/templates/react-router/components.json +22 -0
- package/templates/react-router/content/docs/getting-started.mdx +15 -0
- package/templates/react-router/content/docs/index.mdx +8 -0
- package/templates/react-router/content/docs/mcp.mdx +121 -0
- package/templates/react-router/content/docs/meta.json +4 -0
- package/templates/react-router/dev/CODEBASE-MAP.md +48 -0
- package/templates/react-router/dev/SPEC-OVERVIEW.md +35 -0
- package/templates/react-router/dev/SPEC.md +93 -0
- package/templates/react-router/dev/features/archive/.gitkeep +1 -0
- package/templates/react-router/drizzle.config.ts +5 -0
- package/templates/react-router/env.d.ts +53 -0
- package/templates/react-router/gitignore +23 -0
- package/templates/react-router/migrations/app/meta/_journal.json +1 -0
- package/templates/react-router/package.json +70 -0
- package/templates/react-router/public/_headers +4 -0
- package/templates/react-router/public/favicon.ico +0 -0
- package/templates/react-router/react-router.config.ts +9 -0
- package/templates/react-router/source.config.ts +5 -0
- package/templates/react-router/tests/raybase-patterns.test.ts +23 -0
- package/templates/react-router/tsconfig.json +27 -0
- package/templates/react-router/vite.config.ts +59 -0
- package/templates/react-router/vitest.config.ts +8 -0
- package/templates/react-router/workers/app.ts +40 -0
- package/templates/react-router/wrangler.jsonc +111 -0
- package/templates/tanstack-start/.dev.vars.example +5 -0
- package/templates/tanstack-start/AGENTS.md +95 -0
- package/templates/tanstack-start/DESIGN.md +65 -0
- package/templates/tanstack-start/components.json +21 -0
- package/templates/tanstack-start/content/docs/getting-started.mdx +65 -0
- package/templates/tanstack-start/content/docs/index.mdx +10 -0
- package/templates/tanstack-start/content/docs/mcp.mdx +122 -0
- package/templates/tanstack-start/content/docs/meta.json +4 -0
- package/templates/tanstack-start/dev/CODEBASE-MAP.md +84 -0
- package/templates/tanstack-start/dev/SPEC-OVERVIEW.md +46 -0
- package/templates/tanstack-start/dev/SPEC.md +213 -0
- package/templates/tanstack-start/dev/features/archive/.gitkeep +1 -0
- package/templates/tanstack-start/docs/theme-previews/base.svg +24 -0
- package/templates/tanstack-start/docs/theme-previews/steel.svg +24 -0
- package/templates/tanstack-start/docs/theme-previews/zen.svg +24 -0
- package/templates/tanstack-start/docs/themes.md +116 -0
- package/templates/tanstack-start/drizzle.config.ts +5 -0
- package/templates/tanstack-start/gitignore +11 -0
- package/templates/tanstack-start/migrations/app/0000_low_karen_page.sql +26 -0
- package/templates/tanstack-start/migrations/app/meta/0000_snapshot.json +196 -0
- package/templates/tanstack-start/migrations/app/meta/_journal.json +13 -0
- package/templates/tanstack-start/package.json +77 -0
- package/templates/tanstack-start/public/_headers +8 -0
- package/templates/tanstack-start/public/icons/app-icon-maskable.svg +1 -0
- package/templates/tanstack-start/public/icons/app-icon.svg +1 -0
- package/templates/tanstack-start/public/icons/apple-touch-icon.png +0 -0
- package/templates/tanstack-start/public/manifest.webmanifest +14 -0
- package/templates/tanstack-start/public/raybase-push-sw.js +32 -0
- package/templates/tanstack-start/source.config.ts +10 -0
- package/templates/tanstack-start/src/actions.ts +560 -0
- package/templates/tanstack-start/src/ai/agents.ts +78 -0
- package/templates/tanstack-start/src/ai/retrieval.ts +36 -0
- package/templates/tanstack-start/src/auth-door.ts +18 -0
- package/templates/tanstack-start/src/client.tsx +25 -0
- package/templates/tanstack-start/src/components/.gitkeep +1 -0
- package/templates/tanstack-start/src/components/account-menu.tsx +127 -0
- package/templates/tanstack-start/src/components/auth-shell.tsx +69 -0
- package/templates/tanstack-start/src/components/install-app.tsx +35 -0
- package/templates/tanstack-start/src/components/mode-toggle.tsx +32 -0
- package/templates/tanstack-start/src/components/search-command-palette.tsx +107 -0
- package/templates/tanstack-start/src/components/setup-token-page.tsx +197 -0
- package/templates/tanstack-start/src/components/ui/avatar.tsx +107 -0
- package/templates/tanstack-start/src/components/ui/badge.tsx +52 -0
- package/templates/tanstack-start/src/components/ui/button.tsx +69 -0
- package/templates/tanstack-start/src/components/ui/checkbox.tsx +29 -0
- package/templates/tanstack-start/src/components/ui/dialog.tsx +158 -0
- package/templates/tanstack-start/src/components/ui/dropdown-menu.tsx +303 -0
- package/templates/tanstack-start/src/components/ui/input.tsx +20 -0
- package/templates/tanstack-start/src/components/ui/label.tsx +20 -0
- package/templates/tanstack-start/src/components/ui/scroll-area.tsx +53 -0
- package/templates/tanstack-start/src/components/ui/select.tsx +215 -0
- package/templates/tanstack-start/src/components/ui/separator.tsx +23 -0
- package/templates/tanstack-start/src/components/ui/sheet.tsx +138 -0
- package/templates/tanstack-start/src/components/ui/sidebar.tsx +728 -0
- package/templates/tanstack-start/src/components/ui/skeleton.tsx +13 -0
- package/templates/tanstack-start/src/components/ui/textarea.tsx +18 -0
- package/templates/tanstack-start/src/components/ui/tooltip.tsx +66 -0
- package/templates/tanstack-start/src/db/migrations.gen.ts +6 -0
- package/templates/tanstack-start/src/db/schema.ts +90 -0
- package/templates/tanstack-start/src/db/seed.ts +106 -0
- package/templates/tanstack-start/src/db/storage.ts +32 -0
- package/templates/tanstack-start/src/docs/docs-assets.ts +1 -0
- package/templates/tanstack-start/src/docs/docs-client.tsx +22 -0
- package/templates/tanstack-start/src/docs/docs-data.ts +24 -0
- package/templates/tanstack-start/src/docs/docs-handler.tsx +105 -0
- package/templates/tanstack-start/src/docs/docs-layout.tsx +56 -0
- package/templates/tanstack-start/src/docs/docs-mdx.tsx +79 -0
- package/templates/tanstack-start/src/docs/docs-page-actions.tsx +146 -0
- package/templates/tanstack-start/src/docs/docs-page.tsx +70 -0
- package/templates/tanstack-start/src/docs/llm-text.ts +61 -0
- package/templates/tanstack-start/src/docs/source.ts +7 -0
- package/templates/tanstack-start/src/hooks/use-mobile.ts +19 -0
- package/templates/tanstack-start/src/hooks/use-pwa-install.ts +77 -0
- package/templates/tanstack-start/src/jobs.example.ts +56 -0
- package/templates/tanstack-start/src/lib/account.ts +13 -0
- package/templates/tanstack-start/src/lib/auth-client.ts +187 -0
- package/templates/tanstack-start/src/lib/push-client.ts +98 -0
- package/templates/tanstack-start/src/lib/utils.ts +6 -0
- package/templates/tanstack-start/src/mcp-app.ts +74 -0
- package/templates/tanstack-start/src/notifications.example.ts +37 -0
- package/templates/tanstack-start/src/raybase.auth.ts +86 -0
- package/templates/tanstack-start/src/raybase.config.ts +86 -0
- package/templates/tanstack-start/src/raybase.server.ts +155 -0
- package/templates/tanstack-start/src/realtime.example.ts +46 -0
- package/templates/tanstack-start/src/router.tsx +19 -0
- package/templates/tanstack-start/src/routes/__root.tsx +73 -0
- package/templates/tanstack-start/src/routes/_app/admin.tsx +13 -0
- package/templates/tanstack-start/src/routes/_app/forgot-password.tsx +97 -0
- package/templates/tanstack-start/src/routes/_app/index.tsx +1316 -0
- package/templates/tanstack-start/src/routes/_app/invite.$token.tsx +11 -0
- package/templates/tanstack-start/src/routes/_app/login.tsx +193 -0
- package/templates/tanstack-start/src/routes/_app/profile.tsx +98 -0
- package/templates/tanstack-start/src/routes/_app/reset-password.$token.tsx +16 -0
- package/templates/tanstack-start/src/routes/_app/reset-password.tsx +115 -0
- package/templates/tanstack-start/src/routes/_app/setup.$token.tsx +11 -0
- package/templates/tanstack-start/src/routes/_app/signup.tsx +141 -0
- package/templates/tanstack-start/src/routes/_app/verify-email.$token.tsx +15 -0
- package/templates/tanstack-start/src/routes/_app/verify-email.tsx +154 -0
- package/templates/tanstack-start/src/routes/_app.tsx +33 -0
- package/templates/tanstack-start/src/routes/admin/$.ts +20 -0
- package/templates/tanstack-start/src/routes/api/$.ts +19 -0
- package/templates/tanstack-start/src/routes/docs/$.tsx +22 -0
- package/templates/tanstack-start/src/routes/docs/api/markdown.ts +12 -0
- package/templates/tanstack-start/src/routes/docs/api/search.ts +12 -0
- package/templates/tanstack-start/src/routes/docs.index.tsx +22 -0
- package/templates/tanstack-start/src/routes/docs.tsx +22 -0
- package/templates/tanstack-start/src/search.ts +26 -0
- package/templates/tanstack-start/src/settings.ts +12 -0
- package/templates/tanstack-start/src/styles-docs.css +3 -0
- package/templates/tanstack-start/src/styles.css +73 -0
- package/templates/tanstack-start/src/themes/base.css +76 -0
- package/templates/tanstack-start/src/themes/carbon.css +76 -0
- package/templates/tanstack-start/src/themes/fonts.css +18 -0
- package/templates/tanstack-start/src/themes/sage.css +76 -0
- package/templates/tanstack-start/src/themes/sand.css +76 -0
- package/templates/tanstack-start/src/themes/slate.css +76 -0
- package/templates/tanstack-start/src/themes/ultra.css +76 -0
- package/templates/tanstack-start/src/themes/zen.css +76 -0
- package/templates/tanstack-start/src/worker-entry.ts +30 -0
- package/templates/tanstack-start/tests/raybase-patterns.test.ts +247 -0
- package/templates/tanstack-start/tsconfig.json +33 -0
- package/templates/tanstack-start/vite.config.ts +132 -0
- package/templates/tanstack-start/vitest.config.ts +8 -0
- package/templates/tanstack-start/wrangler.jsonc +112 -0
- package/README.md +0 -3
|
@@ -0,0 +1,738 @@
|
|
|
1
|
+
import type { APIContext } from "astro";
|
|
2
|
+
import { env as cloudflareEnv } from "cloudflare:workers";
|
|
3
|
+
import {
|
|
4
|
+
consumeHandoff,
|
|
5
|
+
requireHandoff,
|
|
6
|
+
serializeHandoffCookie,
|
|
7
|
+
verifyHandoff,
|
|
8
|
+
verifyHandoffToken,
|
|
9
|
+
type RaybaseHandoffPrincipal
|
|
10
|
+
} from "@raybase/core/handoff-consumer";
|
|
11
|
+
import { resolveRaybaseEmDashRole, type RaybaseEmDashAuthConfig } from "@raybase/emdash";
|
|
12
|
+
import { guardRaybaseEmDashSetup } from "@raybase/emdash/setup-guard";
|
|
13
|
+
|
|
14
|
+
export const allowedActions = new Set(["content.site_snapshot"]);
|
|
15
|
+
|
|
16
|
+
type RaybaseRouteContext = Pick<APIContext, "request" | "url">;
|
|
17
|
+
type RaybaseFullContext = APIContext & {
|
|
18
|
+
session?: {
|
|
19
|
+
set(key: "user", value: { id: string }): void | Promise<void>;
|
|
20
|
+
destroy(): void | Promise<void>;
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
type RaybaseDevSessionHandoffOk = {
|
|
24
|
+
ok: true;
|
|
25
|
+
spineSetCookies: string[];
|
|
26
|
+
token: string;
|
|
27
|
+
principal: RaybaseHandoffPrincipal;
|
|
28
|
+
};
|
|
29
|
+
type RaybaseDevSessionHandoffError = { ok: false; status: number; message: string };
|
|
30
|
+
type EmDashUserRow = {
|
|
31
|
+
id: string;
|
|
32
|
+
email: string;
|
|
33
|
+
name: string | null;
|
|
34
|
+
role: number;
|
|
35
|
+
email_verified?: number | null;
|
|
36
|
+
};
|
|
37
|
+
type EmDashDb = {
|
|
38
|
+
selectFrom(table: "users"): {
|
|
39
|
+
selectAll(): {
|
|
40
|
+
where(column: "email", operator: "=", value: string): {
|
|
41
|
+
executeTakeFirst(): Promise<EmDashUserRow | undefined>;
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
insertInto(table: "users"): {
|
|
46
|
+
values(value: Record<string, unknown>): {
|
|
47
|
+
execute(): Promise<unknown>;
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
updateTable(table: "users"): {
|
|
51
|
+
set(value: Record<string, unknown>): {
|
|
52
|
+
where(column: "id", operator: "=", value: string): {
|
|
53
|
+
execute(): Promise<unknown>;
|
|
54
|
+
};
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
export type RaybaseAccountSummary = {
|
|
60
|
+
id: string;
|
|
61
|
+
name: string;
|
|
62
|
+
email: string;
|
|
63
|
+
isOperator: boolean;
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
export type RaybaseLocalDevPersonaSummary = {
|
|
67
|
+
email: string;
|
|
68
|
+
name: string;
|
|
69
|
+
label: string;
|
|
70
|
+
role: string;
|
|
71
|
+
operatorAdmin: boolean;
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
export type RaybaseSiteMenuPosition = "bottom-right" | "bottom-left" | "top-right" | "top-left";
|
|
75
|
+
|
|
76
|
+
export type RaybaseSiteNavigation = {
|
|
77
|
+
account: RaybaseAccountSummary;
|
|
78
|
+
cmsHref: string;
|
|
79
|
+
profileHref: string;
|
|
80
|
+
adminHref: string;
|
|
81
|
+
signOutHref: string;
|
|
82
|
+
localDev: {
|
|
83
|
+
switchHref: string;
|
|
84
|
+
currentEmail: string;
|
|
85
|
+
personas: RaybaseLocalDevPersonaSummary[];
|
|
86
|
+
} | null;
|
|
87
|
+
position: RaybaseSiteMenuPosition;
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
export function envValue(key: string): string | undefined {
|
|
91
|
+
const runtimeValue = (cloudflareEnv as Record<string, unknown>)[key];
|
|
92
|
+
if (typeof runtimeValue === "string") return runtimeValue;
|
|
93
|
+
const viteValue = (import.meta.env as Record<string, unknown>)[key];
|
|
94
|
+
return typeof viteValue === "string" ? viteValue : undefined;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// Same rule as `safeHandoffPath` in @raybase/core/handoff-consumer. Control
|
|
98
|
+
// characters have to be refused, not just CR and LF: the WHATWG URL parser
|
|
99
|
+
// strips TAB/CR/LF before parsing, so a browser reads `/<TAB>//evil.com` as
|
|
100
|
+
// `//evil.com` and a naive prefix check hands out an open redirect.
|
|
101
|
+
const safePathPattern = /^\/(?!\/)[^\\\u0000-\u001f\u007f]*$/;
|
|
102
|
+
|
|
103
|
+
function safePath(value: string | null | undefined, fallback: string): string {
|
|
104
|
+
return typeof value === "string" && safePathPattern.test(value) ? value : fallback;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function spineUrl(): string {
|
|
108
|
+
return (envValue("RAYBASE_SPINE_URL") ?? envValue("PUBLIC_RAYBASE_SPINE_URL") ?? "http://127.0.0.1:3000").replace(/\/$/, "");
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function handoffResource(): string {
|
|
112
|
+
return envValue("RAYBASE_HANDOFF_RESOURCE") ?? "primary";
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// The consumer keeps the bare 401 in production (token internals are not an
|
|
116
|
+
// oracle); dev names the issuer mismatch, which otherwise presents as an
|
|
117
|
+
// opaque "invalid token" whose real cause is a spine that moved ports.
|
|
118
|
+
async function devInvalidTokenResponse(token: string): Promise<Response> {
|
|
119
|
+
const expected = spineUrl();
|
|
120
|
+
const issuer = decodeTokenIssuer(token);
|
|
121
|
+
let body: string;
|
|
122
|
+
if (issuer && issuer !== expected) {
|
|
123
|
+
body = `Invalid token: token issuer ${issuer} does not match this site's expected spine issuer ${expected}. The spine and site disagree on the spine origin — restart raybase dev (and any standalone site process) so both read the same resolved origin.`;
|
|
124
|
+
} else {
|
|
125
|
+
const reason = await verifyHandoffToken(token, handoffConfig()).then(
|
|
126
|
+
() => "the token verified on retry",
|
|
127
|
+
(error: unknown) => (error instanceof Error ? error.message : String(error))
|
|
128
|
+
);
|
|
129
|
+
body = `Invalid token: ${reason} (expected issuer ${expected}).`;
|
|
130
|
+
}
|
|
131
|
+
return new Response(body, {
|
|
132
|
+
status: 401,
|
|
133
|
+
headers: {
|
|
134
|
+
"cache-control": "no-store",
|
|
135
|
+
"referrer-policy": "no-referrer"
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
function decodeTokenIssuer(token: string): string | null {
|
|
141
|
+
try {
|
|
142
|
+
const part = token.split(".")[1];
|
|
143
|
+
if (!part) return null;
|
|
144
|
+
const payload = JSON.parse(atob(part.replace(/-/g, "+").replace(/_/g, "/"))) as { iss?: unknown };
|
|
145
|
+
return typeof payload.iss === "string" ? payload.iss : null;
|
|
146
|
+
} catch {
|
|
147
|
+
return null;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
function handoffConfig(): RaybaseEmDashAuthConfig {
|
|
152
|
+
return {
|
|
153
|
+
resource: handoffResource(),
|
|
154
|
+
// The spine is both the hub a stranger is bounced to and the issuer whose
|
|
155
|
+
// keys this site verifies with. A second issuer would be added here.
|
|
156
|
+
hub: spineUrl(),
|
|
157
|
+
// The CMS accepts one thing from the hub: an SSO handoff for an editor.
|
|
158
|
+
// Pinning the kinds means a pass minted for some other resource kind can
|
|
159
|
+
// never be replayed here even if it verifies.
|
|
160
|
+
issuers: [{ issuer: spineUrl(), jwks: envValue("RAYBASE_HANDOFF_JWKS_URL"), kinds: ["sso"] }],
|
|
161
|
+
returnTo: cmsReturnTo(),
|
|
162
|
+
roleMapping: {
|
|
163
|
+
owner: 50,
|
|
164
|
+
admin: 50,
|
|
165
|
+
"content-editor": 40,
|
|
166
|
+
user: 10
|
|
167
|
+
},
|
|
168
|
+
defaultRole: 10
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
function cmsReturnTo(): string {
|
|
173
|
+
// Keep this aligned with appConfig.handoff.resources[].returnTo in the Raybase spine config.
|
|
174
|
+
return safePath(envValue("RAYBASE_CMS_PATH") ?? envValue("RAYBASE_SITE_CMS_PATH"), "/_emdash/admin");
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
function menuPosition(): RaybaseSiteMenuPosition {
|
|
178
|
+
const value = envValue("RAYBASE_SITE_MENU_POSITION");
|
|
179
|
+
return value === "bottom-left" || value === "top-right" || value === "top-left" ? value : "bottom-right";
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
function spineHref(path: string): string {
|
|
183
|
+
return new URL(path, `${spineUrl()}/`).toString();
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
function setCookieValues(headers: Headers): string[] {
|
|
187
|
+
const getSetCookie = (headers as unknown as { getSetCookie?: () => string[] }).getSetCookie;
|
|
188
|
+
const values = getSetCookie ? getSetCookie.call(headers) : [];
|
|
189
|
+
if (values.length) return values;
|
|
190
|
+
const single = headers.get("set-cookie");
|
|
191
|
+
return single ? single.split(/,(?=\s*[^;,]+=)/).map((value) => value.trim()).filter(Boolean) : [];
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
function cookieHeaderWithSetCookie(request: Request, setCookies: string[]): string {
|
|
195
|
+
const pairs = new Map<string, string>();
|
|
196
|
+
for (const cookie of (request.headers.get("cookie") ?? "").split(";")) {
|
|
197
|
+
const pair = cookie.trim();
|
|
198
|
+
const eq = pair.indexOf("=");
|
|
199
|
+
if (eq > 0) pairs.set(pair.slice(0, eq), pair);
|
|
200
|
+
}
|
|
201
|
+
for (const cookie of setCookies) {
|
|
202
|
+
const pair = cookie.split(";")[0]?.trim();
|
|
203
|
+
const eq = pair?.indexOf("=") ?? -1;
|
|
204
|
+
if (pair && eq > 0) pairs.set(pair.slice(0, eq), pair);
|
|
205
|
+
}
|
|
206
|
+
return Array.from(pairs.values()).join("; ");
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
function forwardCookieHeaders(request: Request): Headers {
|
|
210
|
+
const headers = new Headers({ accept: "application/json" });
|
|
211
|
+
const cookie = request.headers.get("cookie");
|
|
212
|
+
if (cookie) headers.set("cookie", cookie);
|
|
213
|
+
return headers;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
function accountFromPayload(value: unknown): RaybaseAccountSummary | null {
|
|
217
|
+
if (!value || typeof value !== "object") return null;
|
|
218
|
+
const payload = value as Partial<RaybaseAccountSummary>;
|
|
219
|
+
if (
|
|
220
|
+
typeof payload.id !== "string" ||
|
|
221
|
+
typeof payload.name !== "string" ||
|
|
222
|
+
typeof payload.email !== "string" ||
|
|
223
|
+
typeof payload.isOperator !== "boolean"
|
|
224
|
+
) {
|
|
225
|
+
return null;
|
|
226
|
+
}
|
|
227
|
+
return {
|
|
228
|
+
id: payload.id,
|
|
229
|
+
name: payload.name,
|
|
230
|
+
email: payload.email,
|
|
231
|
+
isOperator: payload.isOperator
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
export async function loadRaybaseAccount(request: Request): Promise<RaybaseAccountSummary | null> {
|
|
236
|
+
const response = await fetch(spineHref("/api/account/me"), {
|
|
237
|
+
method: "GET",
|
|
238
|
+
headers: forwardCookieHeaders(request)
|
|
239
|
+
}).catch(() => null);
|
|
240
|
+
if (!response?.ok) return null;
|
|
241
|
+
return accountFromPayload(await response.json().catch(() => null));
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
function localDevPersonaFromPayload(value: unknown): RaybaseLocalDevPersonaSummary | null {
|
|
245
|
+
if (!value || typeof value !== "object") return null;
|
|
246
|
+
const payload = value as Partial<RaybaseLocalDevPersonaSummary>;
|
|
247
|
+
if (
|
|
248
|
+
typeof payload.email !== "string" ||
|
|
249
|
+
typeof payload.name !== "string" ||
|
|
250
|
+
typeof payload.label !== "string" ||
|
|
251
|
+
typeof payload.role !== "string" ||
|
|
252
|
+
typeof payload.operatorAdmin !== "boolean"
|
|
253
|
+
) {
|
|
254
|
+
return null;
|
|
255
|
+
}
|
|
256
|
+
return {
|
|
257
|
+
email: payload.email,
|
|
258
|
+
name: payload.name,
|
|
259
|
+
label: payload.label,
|
|
260
|
+
role: payload.role,
|
|
261
|
+
operatorAdmin: payload.operatorAdmin
|
|
262
|
+
};
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
async function loadRaybaseLocalDevPersonas(account: RaybaseAccountSummary): Promise<RaybaseSiteNavigation["localDev"]> {
|
|
266
|
+
if (!import.meta.env.DEV) return null;
|
|
267
|
+
const response = await fetch(spineHref("/api/auth/capabilities"), {
|
|
268
|
+
method: "GET",
|
|
269
|
+
headers: { accept: "application/json" }
|
|
270
|
+
}).catch(() => null);
|
|
271
|
+
if (!response?.ok) return null;
|
|
272
|
+
const payload = (await response.json().catch(() => null)) as { localDev?: { personas?: unknown[] } } | null;
|
|
273
|
+
const personas = Array.isArray(payload?.localDev?.personas)
|
|
274
|
+
? payload.localDev.personas.map(localDevPersonaFromPayload).filter((persona): persona is RaybaseLocalDevPersonaSummary => Boolean(persona))
|
|
275
|
+
: [];
|
|
276
|
+
if (!personas.length) return null;
|
|
277
|
+
return {
|
|
278
|
+
switchHref: "/_raybase/dev/session",
|
|
279
|
+
currentEmail: account.email,
|
|
280
|
+
personas
|
|
281
|
+
};
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
function accountFromHandoffPrincipal(principal: RaybaseHandoffPrincipal): RaybaseAccountSummary {
|
|
285
|
+
const email = principal.email || `${principal.sub}@raybase.local`;
|
|
286
|
+
const roles = principal.roles ?? [];
|
|
287
|
+
return {
|
|
288
|
+
id: principal.sub,
|
|
289
|
+
name: principal.name || email.split("@")[0] || "Raybase user",
|
|
290
|
+
email,
|
|
291
|
+
// A handoff carries app roles, not operator grants; the spine gives an
|
|
292
|
+
// owner the "owner" app role, so that is what the Admin link reads.
|
|
293
|
+
isOperator: roles.includes("owner") || roles.includes("admin")
|
|
294
|
+
};
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
function handoffCookieMaxAgeSeconds(principal: RaybaseHandoffPrincipal): number {
|
|
298
|
+
return Math.max(0, Math.floor(principal.exp - Date.now() / 1000));
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
function raybaseDevBootstrapGuardCookie(maxAgeSeconds?: number): string {
|
|
302
|
+
const attributes = ["raybase_dev_bootstrap=1", "Path=/", "HttpOnly", "SameSite=Strict"];
|
|
303
|
+
if (typeof maxAgeSeconds === "number") attributes.splice(2, 0, `Max-Age=${Math.max(0, Math.trunc(maxAgeSeconds))}`);
|
|
304
|
+
return attributes.join("; ");
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
function hasRaybaseDevBootstrapGuard(request: Request): boolean {
|
|
308
|
+
return /(?:^|;\s*)raybase_dev_bootstrap=/.test(request.headers.get("cookie") ?? "");
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
function isRaybaseDevBootstrapInternalPath(pathname: string): boolean {
|
|
312
|
+
return [
|
|
313
|
+
"/_raybase",
|
|
314
|
+
"/_emdash",
|
|
315
|
+
"/_astro",
|
|
316
|
+
"/_image",
|
|
317
|
+
"/api/",
|
|
318
|
+
"/.well-known/",
|
|
319
|
+
"/@",
|
|
320
|
+
"/node_modules/"
|
|
321
|
+
].some((prefix) => pathname.startsWith(prefix));
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
function wantsRaybaseDevBootstrapNavigation(request: Request): boolean {
|
|
325
|
+
const fetchMode = request.headers.get("sec-fetch-mode");
|
|
326
|
+
if (fetchMode && fetchMode !== "navigate") return false;
|
|
327
|
+
const fetchDest = request.headers.get("sec-fetch-dest");
|
|
328
|
+
if (fetchDest && fetchDest !== "document") return false;
|
|
329
|
+
return (request.headers.get("accept") ?? "").toLowerCase().includes("text/html");
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
function handleRaybaseDevCanonicalHostRedirect(url: URL): Response | null {
|
|
333
|
+
if (url.hostname !== "localhost") return null;
|
|
334
|
+
|
|
335
|
+
let canonicalOrigin: URL | null = null;
|
|
336
|
+
const configuredOrigin = envValue("RAYBASE_SITE_ORIGIN");
|
|
337
|
+
if (configuredOrigin) {
|
|
338
|
+
try {
|
|
339
|
+
canonicalOrigin = new URL(configuredOrigin);
|
|
340
|
+
} catch {
|
|
341
|
+
canonicalOrigin = null;
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
const canonicalHostname = canonicalOrigin?.hostname ?? "127.0.0.1";
|
|
346
|
+
if (canonicalHostname !== "127.0.0.1") return null;
|
|
347
|
+
|
|
348
|
+
const location = new URL(url);
|
|
349
|
+
location.protocol = canonicalOrigin?.protocol ?? url.protocol;
|
|
350
|
+
location.hostname = canonicalHostname;
|
|
351
|
+
location.port = canonicalOrigin ? canonicalOrigin.port : url.port;
|
|
352
|
+
|
|
353
|
+
return new Response(null, {
|
|
354
|
+
status: 302,
|
|
355
|
+
headers: {
|
|
356
|
+
"cache-control": "no-store",
|
|
357
|
+
location: location.toString()
|
|
358
|
+
}
|
|
359
|
+
});
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
function raybaseEmDashUserId(principal: RaybaseHandoffPrincipal): string {
|
|
363
|
+
return `raybase:${principal.resource}:${principal.sub}`;
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
function emdashDbFromContext(context: APIContext): EmDashDb | null {
|
|
367
|
+
return ((context.locals as { emdash?: { db?: EmDashDb } }).emdash?.db) ?? null;
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
function emdashAccountForPrincipal(principal: RaybaseHandoffPrincipal): { id: string; email: string; name: string; role: number } {
|
|
371
|
+
const account = accountFromHandoffPrincipal(principal);
|
|
372
|
+
return {
|
|
373
|
+
id: raybaseEmDashUserId(principal),
|
|
374
|
+
email: account.email,
|
|
375
|
+
name: account.name,
|
|
376
|
+
role: resolveRaybaseEmDashRole(principal, handoffConfig())
|
|
377
|
+
};
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
async function establishRaybaseEmDashDevSession(context: RaybaseFullContext, principal: RaybaseHandoffPrincipal): Promise<boolean> {
|
|
381
|
+
if (!import.meta.env.DEV) return true;
|
|
382
|
+
|
|
383
|
+
if (!context.session) return false;
|
|
384
|
+
const account = emdashAccountForPrincipal(principal);
|
|
385
|
+
await context.session.set("user", { id: account.id });
|
|
386
|
+
|
|
387
|
+
const db = emdashDbFromContext(context);
|
|
388
|
+
if (!db) return false;
|
|
389
|
+
|
|
390
|
+
const now = new Date().toISOString();
|
|
391
|
+
const existing = await db.selectFrom("users").selectAll().where("email", "=", account.email).executeTakeFirst();
|
|
392
|
+
|
|
393
|
+
if (!existing) {
|
|
394
|
+
await db.insertInto("users").values({
|
|
395
|
+
id: account.id,
|
|
396
|
+
email: account.email,
|
|
397
|
+
name: account.name,
|
|
398
|
+
role: account.role,
|
|
399
|
+
email_verified: 1,
|
|
400
|
+
created_at: now,
|
|
401
|
+
updated_at: now
|
|
402
|
+
}).execute();
|
|
403
|
+
return true;
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
const updates: Record<string, unknown> = {};
|
|
407
|
+
if (existing.name !== account.name) updates.name = account.name;
|
|
408
|
+
if (existing.role !== account.role) updates.role = account.role;
|
|
409
|
+
if (existing.email_verified !== 1) updates.email_verified = 1;
|
|
410
|
+
if (Object.keys(updates).length > 0) {
|
|
411
|
+
updates.updated_at = now;
|
|
412
|
+
await db.updateTable("users").set(updates).where("id", "=", existing.id).execute();
|
|
413
|
+
}
|
|
414
|
+
await context.session.set("user", { id: existing.id });
|
|
415
|
+
return true;
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
async function loadRaybaseHandoffAccount(request: Request): Promise<RaybaseAccountSummary | null> {
|
|
419
|
+
const principal = await verifyHandoff(request, handoffConfig());
|
|
420
|
+
return principal ? accountFromHandoffPrincipal(principal) : null;
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
async function performRaybaseDevSessionHandoff(
|
|
424
|
+
context: RaybaseFullContext,
|
|
425
|
+
options: { email?: string; returnTo: string }
|
|
426
|
+
): Promise<RaybaseDevSessionHandoffOk | RaybaseDevSessionHandoffError> {
|
|
427
|
+
const { request } = context;
|
|
428
|
+
const sessionResponse = await fetch(spineHref("/api/dev/session"), {
|
|
429
|
+
method: "POST",
|
|
430
|
+
headers: {
|
|
431
|
+
"content-type": "application/json",
|
|
432
|
+
origin: spineUrl()
|
|
433
|
+
},
|
|
434
|
+
body: JSON.stringify(options.email ? { email: options.email } : {})
|
|
435
|
+
}).catch(() => null);
|
|
436
|
+
const sessionBody = (await sessionResponse?.json().catch(() => ({}))) as { error?: string; message?: string };
|
|
437
|
+
if (!sessionResponse?.ok) {
|
|
438
|
+
return {
|
|
439
|
+
ok: false,
|
|
440
|
+
status: sessionResponse?.status ?? 502,
|
|
441
|
+
message: sessionBody?.message ?? sessionBody?.error ?? "Local dev session switch failed."
|
|
442
|
+
};
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
const spineSetCookies = setCookieValues(sessionResponse.headers);
|
|
446
|
+
const handoffResponse = await fetch(spineHref("/api/handoff/token"), {
|
|
447
|
+
method: "POST",
|
|
448
|
+
headers: {
|
|
449
|
+
"content-type": "application/json",
|
|
450
|
+
cookie: cookieHeaderWithSetCookie(request, spineSetCookies),
|
|
451
|
+
origin: spineUrl()
|
|
452
|
+
},
|
|
453
|
+
body: JSON.stringify({ resource: handoffResource(), returnTo: options.returnTo })
|
|
454
|
+
}).catch(() => null);
|
|
455
|
+
const handoffBody = (await handoffResponse?.json().catch(() => ({}))) as { token?: string; error?: string; message?: string };
|
|
456
|
+
if (!handoffResponse?.ok || !handoffBody.token) {
|
|
457
|
+
return {
|
|
458
|
+
ok: false,
|
|
459
|
+
status: handoffResponse?.status ?? 502,
|
|
460
|
+
message: handoffBody?.message ?? handoffBody?.error ?? "Handoff refresh failed."
|
|
461
|
+
};
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
let principal: RaybaseHandoffPrincipal;
|
|
465
|
+
try {
|
|
466
|
+
principal = await verifyHandoffToken(handoffBody.token, handoffConfig());
|
|
467
|
+
} catch {
|
|
468
|
+
return {
|
|
469
|
+
ok: false,
|
|
470
|
+
status: 502,
|
|
471
|
+
message: "Handoff refresh returned an invalid token."
|
|
472
|
+
};
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
await establishRaybaseEmDashDevSession(context, principal).catch(() => false);
|
|
476
|
+
|
|
477
|
+
return {
|
|
478
|
+
ok: true,
|
|
479
|
+
spineSetCookies,
|
|
480
|
+
token: handoffBody.token,
|
|
481
|
+
principal
|
|
482
|
+
};
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
export async function loadRaybaseSiteNavigation(request: Request): Promise<RaybaseSiteNavigation | null> {
|
|
486
|
+
const account = await loadRaybaseAccount(request);
|
|
487
|
+
if (account) {
|
|
488
|
+
return {
|
|
489
|
+
account,
|
|
490
|
+
// The CMS link points straight at the CMS: a visitor without a handoff
|
|
491
|
+
// cookie is bounced to the hub and sent back here by the consume route.
|
|
492
|
+
cmsHref: cmsReturnTo(),
|
|
493
|
+
profileHref: spineHref("/profile"),
|
|
494
|
+
adminHref: spineHref("/admin"),
|
|
495
|
+
signOutHref: "/_raybase/sign-out",
|
|
496
|
+
localDev: await loadRaybaseLocalDevPersonas(account),
|
|
497
|
+
position: menuPosition()
|
|
498
|
+
};
|
|
499
|
+
}
|
|
500
|
+
const handoffAccount = await loadRaybaseHandoffAccount(request);
|
|
501
|
+
if (!handoffAccount) return null;
|
|
502
|
+
return {
|
|
503
|
+
account: handoffAccount,
|
|
504
|
+
cmsHref: cmsReturnTo(),
|
|
505
|
+
profileHref: spineHref("/profile"),
|
|
506
|
+
adminHref: spineHref("/admin"),
|
|
507
|
+
signOutHref: "/_raybase/sign-out",
|
|
508
|
+
localDev: await loadRaybaseLocalDevPersonas(handoffAccount),
|
|
509
|
+
position: menuPosition()
|
|
510
|
+
};
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
export async function handleRaybaseHandoffConsume(context: RaybaseFullContext): Promise<Response> {
|
|
514
|
+
const response = await consumeHandoff(context.request, handoffConfig(), {
|
|
515
|
+
onPrincipal: async (principal) => {
|
|
516
|
+
const returnTo = safePath(context.url.searchParams.get("return"), cmsReturnTo());
|
|
517
|
+
const ready = await establishRaybaseEmDashDevSession(context, principal).catch(() => false);
|
|
518
|
+
// EmDash's session store and database reach this route through Astro
|
|
519
|
+
// locals, which are not populated for every request. When they are
|
|
520
|
+
// missing, finalize repeats the write on the next request instead of
|
|
521
|
+
// dropping the editor at a signed-out CMS.
|
|
522
|
+
if (import.meta.env.DEV && returnTo.startsWith("/_emdash") && !ready) {
|
|
523
|
+
return `/_raybase/handoff/finalize?return=${encodeURIComponent(returnTo)}`;
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
});
|
|
527
|
+
|
|
528
|
+
const token = context.url.searchParams.get("token");
|
|
529
|
+
if (!import.meta.env.DEV || response.status !== 401 || !token) return response;
|
|
530
|
+
// Consume refuses for two reasons. Only a bad token is worth the issuer
|
|
531
|
+
// diagnostic; a state mismatch means the bounce started somewhere else,
|
|
532
|
+
// which the message below would misdiagnose as port drift.
|
|
533
|
+
const refusal = ((await response.clone().json().catch(() => ({}))) as { error?: unknown }).error;
|
|
534
|
+
return refusal === "handoff_token_invalid" ? devInvalidTokenResponse(token) : response;
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
export async function handleRaybaseHandoffFinalize(context: RaybaseFullContext): Promise<Response> {
|
|
538
|
+
if (!import.meta.env.DEV) return new Response("Not found", { status: 404 });
|
|
539
|
+
|
|
540
|
+
const principal = await verifyHandoff(context.request, handoffConfig());
|
|
541
|
+
if (!principal) {
|
|
542
|
+
return new Response("No valid Raybase handoff token", {
|
|
543
|
+
status: 401,
|
|
544
|
+
headers: {
|
|
545
|
+
"cache-control": "no-store",
|
|
546
|
+
"referrer-policy": "no-referrer"
|
|
547
|
+
}
|
|
548
|
+
});
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
const returnTo = safePath(context.url.searchParams.get("return"), cmsReturnTo());
|
|
552
|
+
const ready = await establishRaybaseEmDashDevSession(context, principal).catch(() => false);
|
|
553
|
+
if (!ready) {
|
|
554
|
+
return new Response("EmDash dev session could not be initialized", {
|
|
555
|
+
status: 503,
|
|
556
|
+
headers: {
|
|
557
|
+
"cache-control": "no-store",
|
|
558
|
+
"referrer-policy": "no-referrer"
|
|
559
|
+
}
|
|
560
|
+
});
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
return new Response(null, {
|
|
564
|
+
status: 302,
|
|
565
|
+
headers: {
|
|
566
|
+
"cache-control": "no-store",
|
|
567
|
+
"referrer-policy": "no-referrer",
|
|
568
|
+
location: returnTo
|
|
569
|
+
}
|
|
570
|
+
});
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
export async function handleRaybaseEmDashSetupGuard({ request }: RaybaseRouteContext): Promise<Response | null> {
|
|
574
|
+
return guardRaybaseEmDashSetup(request, handoffConfig(), {
|
|
575
|
+
allowDevBypass: import.meta.env.DEV
|
|
576
|
+
});
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
// The CMS is the only private surface on this site. Everything else stays
|
|
580
|
+
// public, so the gate is mounted here and nowhere else.
|
|
581
|
+
export async function handleRaybaseEmDashAdminGuard({ request, url }: RaybaseRouteContext): Promise<Response | null> {
|
|
582
|
+
if (url.pathname !== "/_emdash/admin" && !url.pathname.startsWith("/_emdash/admin/")) return null;
|
|
583
|
+
return requireHandoff(request, handoffConfig());
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
async function devSessionRequestBody(request: Request): Promise<{ email: string; returnTo: string }> {
|
|
587
|
+
const contentType = request.headers.get("content-type") ?? "";
|
|
588
|
+
if (contentType.includes("application/json")) {
|
|
589
|
+
const body = (await request.clone().json().catch(() => ({}))) as { email?: unknown; returnTo?: unknown };
|
|
590
|
+
return {
|
|
591
|
+
email: typeof body.email === "string" ? body.email : "",
|
|
592
|
+
returnTo: safePath(typeof body.returnTo === "string" ? body.returnTo : null, "/")
|
|
593
|
+
};
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
const form = await request.clone().formData().catch(() => null);
|
|
597
|
+
return {
|
|
598
|
+
email: typeof form?.get("email") === "string" ? String(form.get("email")) : "",
|
|
599
|
+
returnTo: safePath(typeof form?.get("returnTo") === "string" ? String(form.get("returnTo")) : null, "/")
|
|
600
|
+
};
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
export async function handleRaybaseDevSession(context: RaybaseFullContext): Promise<Response> {
|
|
604
|
+
if (!import.meta.env.DEV) return new Response("Not found", { status: 404 });
|
|
605
|
+
|
|
606
|
+
const { request } = context;
|
|
607
|
+
const { email, returnTo } = await devSessionRequestBody(request);
|
|
608
|
+
if (!email) return new Response("Missing email", { status: 400, headers: { "cache-control": "no-store" } });
|
|
609
|
+
|
|
610
|
+
const handoff = await performRaybaseDevSessionHandoff(context, { email, returnTo });
|
|
611
|
+
if (!handoff.ok) return new Response(handoff.message, { status: handoff.status, headers: { "cache-control": "no-store" } });
|
|
612
|
+
|
|
613
|
+
const headers = new Headers({
|
|
614
|
+
"cache-control": "no-store",
|
|
615
|
+
"referrer-policy": "no-referrer",
|
|
616
|
+
location: returnTo
|
|
617
|
+
});
|
|
618
|
+
for (const cookie of handoff.spineSetCookies) headers.append("set-cookie", cookie);
|
|
619
|
+
headers.append(
|
|
620
|
+
"set-cookie",
|
|
621
|
+
serializeHandoffCookie(handoff.token, {
|
|
622
|
+
requestUrl: request.url,
|
|
623
|
+
maxAgeSeconds: handoffCookieMaxAgeSeconds(handoff.principal)
|
|
624
|
+
})
|
|
625
|
+
);
|
|
626
|
+
headers.append("set-cookie", raybaseDevBootstrapGuardCookie(0));
|
|
627
|
+
return new Response(null, { status: 303, headers });
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
export async function handleRaybaseDevAutoBootstrap(context: RaybaseFullContext): Promise<Response | null> {
|
|
631
|
+
if (!import.meta.env.DEV) return null;
|
|
632
|
+
if (context.request.method !== "GET") return null;
|
|
633
|
+
if (envValue("RAYBASE_DEV_AUTO_BOOTSTRAP") === "off") return null;
|
|
634
|
+
|
|
635
|
+
const url = new URL(context.request.url);
|
|
636
|
+
if (isRaybaseDevBootstrapInternalPath(url.pathname)) return null;
|
|
637
|
+
if (!wantsRaybaseDevBootstrapNavigation(context.request)) return null;
|
|
638
|
+
|
|
639
|
+
const canonicalRedirect = handleRaybaseDevCanonicalHostRedirect(url);
|
|
640
|
+
if (canonicalRedirect) return canonicalRedirect;
|
|
641
|
+
|
|
642
|
+
if (hasRaybaseDevBootstrapGuard(context.request)) return null;
|
|
643
|
+
if (await loadRaybaseHandoffAccount(context.request)) return null;
|
|
644
|
+
if (await loadRaybaseAccount(context.request)) return null;
|
|
645
|
+
|
|
646
|
+
const returnTo = url.pathname + url.search;
|
|
647
|
+
const handoff = await performRaybaseDevSessionHandoff(context, { returnTo });
|
|
648
|
+
if (!handoff.ok) return null;
|
|
649
|
+
|
|
650
|
+
const headers = new Headers({
|
|
651
|
+
"cache-control": "no-store",
|
|
652
|
+
"referrer-policy": "no-referrer",
|
|
653
|
+
location: returnTo
|
|
654
|
+
});
|
|
655
|
+
for (const cookie of handoff.spineSetCookies) headers.append("set-cookie", cookie);
|
|
656
|
+
headers.append(
|
|
657
|
+
"set-cookie",
|
|
658
|
+
serializeHandoffCookie(handoff.token, {
|
|
659
|
+
requestUrl: context.request.url,
|
|
660
|
+
maxAgeSeconds: handoffCookieMaxAgeSeconds(handoff.principal)
|
|
661
|
+
})
|
|
662
|
+
);
|
|
663
|
+
headers.append("set-cookie", raybaseDevBootstrapGuardCookie(60));
|
|
664
|
+
return new Response(null, { status: 302, headers });
|
|
665
|
+
}
|
|
666
|
+
|
|
667
|
+
// The forged `origin: spineUrl()` on the upstream call satisfies the spine's
|
|
668
|
+
// server-to-server CSRF check, so this route cannot borrow it for its own: an
|
|
669
|
+
// inbound sign-out POST has to prove it came from a page on this site first.
|
|
670
|
+
function isSameOriginRequest(request: Request): boolean {
|
|
671
|
+
const source = request.headers.get("origin") ?? request.headers.get("referer");
|
|
672
|
+
if (!source) return false;
|
|
673
|
+
try {
|
|
674
|
+
return new URL(source).host === new URL(request.url).host;
|
|
675
|
+
} catch {
|
|
676
|
+
return false;
|
|
677
|
+
}
|
|
678
|
+
}
|
|
679
|
+
|
|
680
|
+
export async function handleRaybaseSignOut(context: RaybaseRouteContext & Pick<RaybaseFullContext, "session">): Promise<Response> {
|
|
681
|
+
const { request } = context;
|
|
682
|
+
if (!isSameOriginRequest(request)) {
|
|
683
|
+
return new Response("Sign-out must be submitted from this site", {
|
|
684
|
+
status: 403,
|
|
685
|
+
headers: {
|
|
686
|
+
"cache-control": "no-store",
|
|
687
|
+
"content-type": "text/plain; charset=utf-8"
|
|
688
|
+
}
|
|
689
|
+
});
|
|
690
|
+
}
|
|
691
|
+
const logoutResponse = await fetch(spineHref("/api/auth/logout"), {
|
|
692
|
+
method: "POST",
|
|
693
|
+
headers: new Headers({
|
|
694
|
+
...Object.fromEntries(forwardCookieHeaders(request)),
|
|
695
|
+
"content-type": "application/json",
|
|
696
|
+
origin: spineUrl()
|
|
697
|
+
}),
|
|
698
|
+
body: "{}"
|
|
699
|
+
}).catch(() => null);
|
|
700
|
+
const headers = new Headers({
|
|
701
|
+
"cache-control": "no-store",
|
|
702
|
+
location: "/"
|
|
703
|
+
});
|
|
704
|
+
const setCookie = logoutResponse?.headers.get("set-cookie");
|
|
705
|
+
if (setCookie) headers.append("set-cookie", setCookie);
|
|
706
|
+
context.session?.destroy();
|
|
707
|
+
headers.append("set-cookie", serializeHandoffCookie("", { requestUrl: request.url, maxAgeSeconds: 0 }));
|
|
708
|
+
if (import.meta.env.DEV) headers.append("set-cookie", raybaseDevBootstrapGuardCookie());
|
|
709
|
+
return new Response(null, { status: 303, headers });
|
|
710
|
+
}
|
|
711
|
+
|
|
712
|
+
export async function handleRaybaseIslandAction({ request }: RaybaseRouteContext): Promise<Response> {
|
|
713
|
+
const contentLength = request.headers.get("content-length");
|
|
714
|
+
const contentLengthBytes = contentLength ? Number(contentLength) : 0;
|
|
715
|
+
if (Number.isFinite(contentLengthBytes) && contentLengthBytes > 64 * 1024) {
|
|
716
|
+
return Response.json({ error: "Request body is too large." }, { status: 413 });
|
|
717
|
+
}
|
|
718
|
+
|
|
719
|
+
const body = (await request.clone().json().catch(() => ({}))) as { action?: unknown; input?: unknown };
|
|
720
|
+
if (typeof body.action !== "string" || !allowedActions.has(body.action)) {
|
|
721
|
+
return Response.json({ error: "Action is not allowed." }, { status: 403 });
|
|
722
|
+
}
|
|
723
|
+
|
|
724
|
+
const response = await fetch(`${spineUrl()}/api/actions/${encodeURIComponent(body.action)}`, {
|
|
725
|
+
method: "POST",
|
|
726
|
+
headers: {
|
|
727
|
+
"content-type": "application/json"
|
|
728
|
+
},
|
|
729
|
+
body: JSON.stringify(body.input ?? {})
|
|
730
|
+
});
|
|
731
|
+
const payload = await response.json().catch(() => ({}));
|
|
732
|
+
return Response.json(payload, {
|
|
733
|
+
status: response.status,
|
|
734
|
+
headers: {
|
|
735
|
+
"cache-control": "no-store"
|
|
736
|
+
}
|
|
737
|
+
});
|
|
738
|
+
}
|