create-ailk 0.37.1 → 0.39.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +129 -0
- package/component-catalog.json +44 -6
- package/component-catalog.md +6 -5
- package/dist/add-module.js +16 -1
- package/dist/add-route.d.ts +2 -2
- package/dist/add-route.js +19 -12
- package/dist/cli.js +52 -0
- package/dist/declined-routes.d.ts +13 -0
- package/dist/declined-routes.js +74 -0
- package/dist/derive-architecture.d.ts +0 -6
- package/dist/derive-architecture.js +12 -16
- package/dist/index.d.ts +1 -0
- package/dist/index.js +3 -0
- package/dist/language-import.d.ts +93 -0
- package/dist/language-import.js +270 -43
- package/dist/lib/import-mdx.js +1 -1
- package/dist/lib/scaffold-render-sweep.d.ts +6 -3
- package/dist/lib/scaffold-render-sweep.js +8 -4
- package/dist/migrate-content.d.ts +6 -2
- package/dist/migrate-content.js +62 -5
- package/dist/module-architecture.js +139 -103
- package/dist/paid-sections.d.ts +13 -0
- package/dist/paid-sections.js +35 -5
- package/dist/programmatic.js +6 -16
- package/dist/remove-module.js +73 -2
- package/dist/routes.d.ts +130 -0
- package/dist/routes.js +954 -0
- package/dist/site-manifest.js +6 -4
- package/dist/site-roster.d.ts +11 -2
- package/dist/site-roster.js +63 -21
- package/dist/spoke-checkout.d.ts +28 -27
- package/dist/spoke-checkout.js +71 -102
- package/dist/surfaces.d.ts +26 -0
- package/dist/surfaces.js +105 -293
- package/dist/sync-routes.d.ts +14 -1
- package/dist/sync-routes.js +108 -10
- package/dist/template-record.js +3 -1
- package/dist/topology.d.ts +26 -1
- package/dist/topology.js +273 -7
- package/dist/update.d.ts +17 -2
- package/dist/update.js +480 -77
- package/package.json +3 -3
- package/templates/README.md +1 -1
- package/templates/apps/mcp/CLAUDE.md +5 -3
- package/templates/apps/web/CLAUDE.md +87 -23
- package/templates/apps/web/__tests__/__mocks__/next-intl-server.ts +5 -1
- package/templates/apps/web/__tests__/__mocks__/next-intl.ts +5 -1
- package/templates/apps/web/__tests__/auth/seam.test.ts +34 -0
- package/templates/apps/web/account.config.tsx +100 -0
- package/templates/apps/web/app/[locale]/(authed)/account/connect/__tests__/page.test.tsx +1 -1
- package/templates/apps/web/app/[locale]/(authed)/account/connect/page.tsx +2 -2
- package/templates/apps/web/app/[locale]/(authed)/signed-out-gate.generated.tsx +1 -1
- package/templates/apps/web/app/[locale]/layout.tsx +46 -29
- package/templates/apps/web/app/apple-icon.tsx +72 -0
- package/templates/apps/web/app/llms.txt/__tests__/site-listing.test.ts +22 -12
- package/templates/apps/web/app/og/__tests__/__snapshots__/card.test.tsx.snap +3 -0
- package/templates/apps/web/app/og/__tests__/card.test.tsx +129 -0
- package/templates/apps/web/app/og/__tests__/route.test.ts +3 -4
- package/templates/apps/web/app/og/route.tsx +155 -72
- package/templates/apps/web/app/sitemap.xml/__tests__/site-listing.test.ts +12 -0
- package/templates/apps/web/auth.config.tsx +107 -0
- package/templates/apps/web/auth.ts +2 -1
- package/templates/apps/web/i18n/request.ts +51 -1
- package/templates/apps/web/jest.config.cjs +17 -1
- package/templates/apps/web/lib/__tests__/auth-phone.test.ts +11 -0
- package/templates/apps/web/lib/__tests__/fixtures/site-topology.ts +73 -0
- package/templates/apps/web/lib/__tests__/nav-label-keys.test.ts +14 -0
- package/templates/apps/web/lib/__tests__/profile-back-link.test.ts +148 -61
- package/templates/apps/web/lib/__tests__/served-pages.test.ts +77 -0
- package/templates/apps/web/lib/__tests__/server-api.test.ts +37 -5
- package/templates/apps/web/lib/__tests__/structured-data.test.tsx +26 -13
- package/templates/apps/web/lib/listings.tsx +2 -2
- package/templates/apps/web/lib/nav-label-keys.ts +16 -2
- package/templates/apps/web/lib/paid-section-contracts.ts +35 -6
- package/templates/apps/web/lib/paid-sections.generated.ts +8 -0
- package/templates/apps/web/lib/profile-back-link.ts +105 -32
- package/templates/apps/web/lib/served-pages.ts +95 -0
- package/templates/apps/web/lib/server-api.ts +1 -1
- package/templates/apps/web/lib/site-brand.tsx +3 -5
- package/templates/apps/web/lib/topology.generated.ts +5 -0
- package/templates/apps/web/messages/en.json +8 -836
- package/templates/apps/web/middleware.ts +15 -26
- package/templates/apps/web/next.config.mjs +35 -0
- package/templates/apps/web/package.json +2 -0
- package/templates/apps/web/types/messages.d.ts +6 -1
- package/templates/customizations.yaml +9 -0
- package/templates/package.json +3 -1
- package/templates/tools/lint-architecture.ts +164 -11
- package/versions.json +49 -47
- package/templates/apps/web/app/[locale]/(auth)/__tests__/auth-pages.test.tsx +0 -322
- package/templates/apps/web/app/[locale]/(auth)/__tests__/password-reset.test.tsx +0 -554
- package/templates/apps/web/app/[locale]/(auth)/consent/__tests__/consent-actions.test.ts +0 -56
- package/templates/apps/web/app/[locale]/(auth)/consent/__tests__/page.test.tsx +0 -164
- package/templates/apps/web/app/[locale]/(auth)/consent/consent-form.tsx +0 -132
- package/templates/apps/web/app/[locale]/(auth)/consent/consent.actions.ts +0 -51
- package/templates/apps/web/app/[locale]/(auth)/consent/page.tsx +0 -144
- package/templates/apps/web/app/[locale]/(auth)/forgot-password/forgot-password-card.tsx +0 -101
- package/templates/apps/web/app/[locale]/(auth)/forgot-password/page.tsx +0 -111
- package/templates/apps/web/app/[locale]/(auth)/layout.tsx +0 -81
- package/templates/apps/web/app/[locale]/(auth)/legal-footnote.tsx +0 -35
- package/templates/apps/web/app/[locale]/(auth)/reset-password/__tests__/return.test.tsx +0 -179
- package/templates/apps/web/app/[locale]/(auth)/reset-password/page.tsx +0 -157
- package/templates/apps/web/app/[locale]/(auth)/reset-password/reset-password-card.tsx +0 -126
- package/templates/apps/web/app/[locale]/(auth)/sign-in/__tests__/next-path.test.ts +0 -54
- package/templates/apps/web/app/[locale]/(auth)/sign-in/__tests__/page.test.tsx +0 -628
- package/templates/apps/web/app/[locale]/(auth)/sign-in/__tests__/remembered-method.test.ts +0 -43
- package/templates/apps/web/app/[locale]/(auth)/sign-in/__tests__/sign-in-card.test.tsx +0 -266
- package/templates/apps/web/app/[locale]/(auth)/sign-in/next-path.ts +0 -20
- package/templates/apps/web/app/[locale]/(auth)/sign-in/page.tsx +0 -234
- package/templates/apps/web/app/[locale]/(auth)/sign-in/remembered-method.ts +0 -37
- package/templates/apps/web/app/[locale]/(auth)/sign-in/sign-in-card.tsx +0 -323
- package/templates/apps/web/app/[locale]/(auth)/sign-in/sign-in-text.ts +0 -93
- package/templates/apps/web/app/[locale]/(auth)/sign-up/__tests__/page.test.tsx +0 -301
- package/templates/apps/web/app/[locale]/(auth)/sign-up/__tests__/sign-up-card.test.tsx +0 -309
- package/templates/apps/web/app/[locale]/(auth)/sign-up/page.tsx +0 -201
- package/templates/apps/web/app/[locale]/(auth)/sign-up/sign-up-card.tsx +0 -366
- package/templates/apps/web/app/[locale]/(auth)/use-auth-card-flow.ts +0 -116
- package/templates/apps/web/app/[locale]/(auth)/verify-email/__tests__/actions.test.ts +0 -94
- package/templates/apps/web/app/[locale]/(auth)/verify-email/actions.ts +0 -77
- package/templates/apps/web/app/[locale]/(auth)/verify-email/page.tsx +0 -154
- package/templates/apps/web/app/[locale]/(authed)/account/__tests__/account-frame-sign-out.test.tsx +0 -175
- package/templates/apps/web/app/[locale]/(authed)/account/__tests__/agreements-prompt.test.tsx +0 -301
- package/templates/apps/web/app/[locale]/(authed)/account/__tests__/billing.test.tsx +0 -515
- package/templates/apps/web/app/[locale]/(authed)/account/__tests__/general.test.tsx +0 -883
- package/templates/apps/web/app/[locale]/(authed)/account/__tests__/hub-mode.test.tsx +0 -758
- package/templates/apps/web/app/[locale]/(authed)/account/__tests__/item.test.tsx +0 -264
- package/templates/apps/web/app/[locale]/(authed)/account/__tests__/layout-sign-out.test.tsx +0 -167
- package/templates/apps/web/app/[locale]/(authed)/account/__tests__/layout.test.tsx +0 -730
- package/templates/apps/web/app/[locale]/(authed)/account/__tests__/new-menu.test.tsx +0 -355
- package/templates/apps/web/app/[locale]/(authed)/account/__tests__/new-popups.test.tsx +0 -97
- package/templates/apps/web/app/[locale]/(authed)/account/__tests__/notifications.test.tsx +0 -375
- package/templates/apps/web/app/[locale]/(authed)/account/__tests__/onboarding.test.tsx +0 -323
- package/templates/apps/web/app/[locale]/(authed)/account/__tests__/page.test.tsx +0 -1208
- package/templates/apps/web/app/[locale]/(authed)/account/__tests__/popups.test.tsx +0 -418
- package/templates/apps/web/app/[locale]/(authed)/account/__tests__/privacy.test.tsx +0 -462
- package/templates/apps/web/app/[locale]/(authed)/account/__tests__/rich-translator.ts +0 -63
- package/templates/apps/web/app/[locale]/(authed)/account/__tests__/security.test.tsx +0 -406
- package/templates/apps/web/app/[locale]/(authed)/account/__tests__/settings.test.tsx +0 -93
- package/templates/apps/web/app/[locale]/(authed)/account/__tests__/support.test.tsx +0 -208
- package/templates/apps/web/app/[locale]/(authed)/account/__tests__/thread.test.tsx +0 -340
- package/templates/apps/web/app/[locale]/(authed)/account/account-data.ts +0 -182
- package/templates/apps/web/app/[locale]/(authed)/account/account-frame.tsx +0 -353
- package/templates/apps/web/app/[locale]/(authed)/account/actions.ts +0 -57
- package/templates/apps/web/app/[locale]/(authed)/account/agreements-actions.ts +0 -58
- package/templates/apps/web/app/[locale]/(authed)/account/agreements-gate.ts +0 -61
- package/templates/apps/web/app/[locale]/(authed)/account/agreements-prompt.tsx +0 -184
- package/templates/apps/web/app/[locale]/(authed)/account/appointments/[slug]/page.tsx +0 -161
- package/templates/apps/web/app/[locale]/(authed)/account/appointments/__tests__/page.test.tsx +0 -426
- package/templates/apps/web/app/[locale]/(authed)/account/appointments/appointments-data.ts +0 -76
- package/templates/apps/web/app/[locale]/(authed)/account/appointments/page.tsx +0 -139
- package/templates/apps/web/app/[locale]/(authed)/account/artifacts/[pieceId]/page.tsx +0 -406
- package/templates/apps/web/app/[locale]/(authed)/account/artifacts/[pieceId]/pay-form.tsx +0 -65
- package/templates/apps/web/app/[locale]/(authed)/account/artifacts/[pieceId]/review-form.tsx +0 -172
- package/templates/apps/web/app/[locale]/(authed)/account/artifacts/[pieceId]/versions/[version]/file/route.ts +0 -190
- package/templates/apps/web/app/[locale]/(authed)/account/artifacts/__tests__/file-route.test.ts +0 -333
- package/templates/apps/web/app/[locale]/(authed)/account/artifacts/__tests__/page.test.tsx +0 -936
- package/templates/apps/web/app/[locale]/(authed)/account/artifacts/__tests__/pay.test.tsx +0 -193
- package/templates/apps/web/app/[locale]/(authed)/account/artifacts/__tests__/review.test.tsx +0 -476
- package/templates/apps/web/app/[locale]/(authed)/account/artifacts/artifact-actions.ts +0 -184
- package/templates/apps/web/app/[locale]/(authed)/account/artifacts/artifact-data.ts +0 -197
- package/templates/apps/web/app/[locale]/(authed)/account/artifacts/page.tsx +0 -182
- package/templates/apps/web/app/[locale]/(authed)/account/billing/__tests__/offerings.test.ts +0 -99
- package/templates/apps/web/app/[locale]/(authed)/account/billing/offerings.ts +0 -123
- package/templates/apps/web/app/[locale]/(authed)/account/billing/page.tsx +0 -424
- package/templates/apps/web/app/[locale]/(authed)/account/billing-source.ts +0 -303
- package/templates/apps/web/app/[locale]/(authed)/account/components/request-quote.tsx +0 -274
- package/templates/apps/web/app/[locale]/(authed)/account/error-row.tsx +0 -35
- package/templates/apps/web/app/[locale]/(authed)/account/for-you-labels.ts +0 -36
- package/templates/apps/web/app/[locale]/(authed)/account/general/__tests__/phone-verification.test.tsx +0 -215
- package/templates/apps/web/app/[locale]/(authed)/account/general/__tests__/seam-imports.test.ts +0 -65
- package/templates/apps/web/app/[locale]/(authed)/account/general/account-name.ts +0 -36
- package/templates/apps/web/app/[locale]/(authed)/account/general/billing-anchor.tsx +0 -27
- package/templates/apps/web/app/[locale]/(authed)/account/general/contact-actions.ts +0 -149
- package/templates/apps/web/app/[locale]/(authed)/account/general/contact-details.tsx +0 -42
- package/templates/apps/web/app/[locale]/(authed)/account/general/deletion-request.tsx +0 -132
- package/templates/apps/web/app/[locale]/(authed)/account/general/page.tsx +0 -218
- package/templates/apps/web/app/[locale]/(authed)/account/general/phone-actions.ts +0 -122
- package/templates/apps/web/app/[locale]/(authed)/account/general/phone-verification.tsx +0 -215
- package/templates/apps/web/app/[locale]/(authed)/account/general/photo-actions.ts +0 -73
- package/templates/apps/web/app/[locale]/(authed)/account/general/profile-form.tsx +0 -107
- package/templates/apps/web/app/[locale]/(authed)/account/general/profile-source.ts +0 -87
- package/templates/apps/web/app/[locale]/(authed)/account/inbox/[kind]/[id]/page.tsx +0 -119
- package/templates/apps/web/app/[locale]/(authed)/account/inbox/message/[id]/file/__tests__/route.test.ts +0 -215
- package/templates/apps/web/app/[locale]/(authed)/account/inbox/message/[id]/file/route.ts +0 -80
- package/templates/apps/web/app/[locale]/(authed)/account/inbox/thread/member-thread-composer.tsx +0 -43
- package/templates/apps/web/app/[locale]/(authed)/account/inbox/thread/page.tsx +0 -125
- package/templates/apps/web/app/[locale]/(authed)/account/inbox/thread/thread-data.ts +0 -88
- package/templates/apps/web/app/[locale]/(authed)/account/inbox/thread/thread-write.ts +0 -31
- package/templates/apps/web/app/[locale]/(authed)/account/invitations/[invitationId]/__tests__/invitation-id.test.ts +0 -35
- package/templates/apps/web/app/[locale]/(authed)/account/invitations/[invitationId]/__tests__/page.test.tsx +0 -266
- package/templates/apps/web/app/[locale]/(authed)/account/invitations/[invitationId]/actions.ts +0 -116
- package/templates/apps/web/app/[locale]/(authed)/account/invitations/[invitationId]/invitation-id.ts +0 -12
- package/templates/apps/web/app/[locale]/(authed)/account/invitations/[invitationId]/page.tsx +0 -154
- package/templates/apps/web/app/[locale]/(authed)/account/layout.tsx +0 -152
- package/templates/apps/web/app/[locale]/(authed)/account/new-actions.ts +0 -219
- package/templates/apps/web/app/[locale]/(authed)/account/new-menu.tsx +0 -365
- package/templates/apps/web/app/[locale]/(authed)/account/new-popups.tsx +0 -86
- package/templates/apps/web/app/[locale]/(authed)/account/notifications/page.tsx +0 -143
- package/templates/apps/web/app/[locale]/(authed)/account/onboarding/actions.ts +0 -120
- package/templates/apps/web/app/[locale]/(authed)/account/onboarding/onboarding-form.tsx +0 -322
- package/templates/apps/web/app/[locale]/(authed)/account/onboarding/page.tsx +0 -126
- package/templates/apps/web/app/[locale]/(authed)/account/page.tsx +0 -306
- package/templates/apps/web/app/[locale]/(authed)/account/privacy/__tests__/export-route.test.ts +0 -173
- package/templates/apps/web/app/[locale]/(authed)/account/privacy/actions.ts +0 -103
- package/templates/apps/web/app/[locale]/(authed)/account/privacy/export/route.ts +0 -102
- package/templates/apps/web/app/[locale]/(authed)/account/privacy/page.tsx +0 -240
- package/templates/apps/web/app/[locale]/(authed)/account/profile-actions.ts +0 -116
- package/templates/apps/web/app/[locale]/(authed)/account/retry-button.tsx +0 -27
- package/templates/apps/web/app/[locale]/(authed)/account/security/__tests__/hub-variant.test.tsx +0 -258
- package/templates/apps/web/app/[locale]/(authed)/account/security/page.tsx +0 -131
- package/templates/apps/web/app/[locale]/(authed)/account/security/security-panel.tsx +0 -130
- package/templates/apps/web/app/[locale]/(authed)/account/security/security-source.ts +0 -92
- package/templates/apps/web/app/[locale]/(authed)/account/settings/page.tsx +0 -24
- package/templates/apps/web/app/[locale]/(authed)/account/settings-frame.tsx +0 -121
- package/templates/apps/web/app/[locale]/(authed)/account/sign-in-method.ts +0 -37
- package/templates/apps/web/app/[locale]/(authed)/account/support/page.tsx +0 -60
- package/templates/apps/web/app/[locale]/(authed)/account/support/support-form.tsx +0 -98
- package/templates/apps/web/app/[locale]/(authed)/account/support-actions.ts +0 -100
- package/templates/apps/web/app/[locale]/checkout/__tests__/pages.test.tsx +0 -139
- package/templates/apps/web/app/[locale]/checkout/__tests__/thank-you-account.test.tsx +0 -146
- package/templates/apps/web/app/[locale]/checkout/thank-you/page.tsx +0 -114
- package/templates/apps/web/app/[locale]/checkout/unavailable/page.tsx +0 -51
- package/templates/apps/web/app/[locale]/flows/[slug]/FlowStepperClient.tsx +0 -614
- package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/FlowStepperClient.count.test.tsx +0 -43
- package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/FlowStepperClient.deliverable.test.tsx +0 -214
- package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/FlowStepperClient.ending.test.tsx +0 -197
- package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/FlowStepperClient.invite.test.tsx +0 -286
- package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/FlowStepperClient.permalink.test.tsx +0 -520
- package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/FlowStepperClient.test.tsx +0 -376
- package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/FlowStepperClient.thanks-by-tier.test.tsx +0 -306
- package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/account-invite.actions.test.ts +0 -69
- package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/flow.actions.test.ts +0 -398
- package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/magnet-page.test.tsx +0 -704
- package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/save.actions.test.ts +0 -173
- package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/two-route-tool.test.tsx +0 -141
- package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/verify.test.tsx +0 -249
- package/templates/apps/web/app/[locale]/flows/[slug]/account-invite.actions.ts +0 -35
- package/templates/apps/web/app/[locale]/flows/[slug]/email-moment.ts +0 -92
- package/templates/apps/web/app/[locale]/flows/[slug]/flow.actions.ts +0 -177
- package/templates/apps/web/app/[locale]/flows/[slug]/magnet-page.tsx +0 -472
- package/templates/apps/web/app/[locale]/flows/[slug]/page.tsx +0 -48
- package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/LevelChart.tsx +0 -100
- package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/ResultsCard.tsx +0 -99
- package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/ResultsClient.tsx +0 -820
- package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/ResultsEmailStep.tsx +0 -203
- package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/__tests__/ResultsClient.no-commerce.test.tsx +0 -194
- package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/__tests__/ResultsClient.report.test.tsx +0 -284
- package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/__tests__/by-result.test.tsx +0 -302
- package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/__tests__/cards.test.tsx +0 -402
- package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/__tests__/landing.test.tsx +0 -293
- package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/__tests__/page.test.tsx +0 -485
- package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/__tests__/score.test.tsx +0 -231
- package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/checkout-seam.ts +0 -74
- package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/meeting-seam.ts +0 -36
- package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/page.tsx +0 -420
- package/templates/apps/web/app/[locale]/flows/[slug]/save.actions.ts +0 -85
- package/templates/apps/web/app/[locale]/flows/[slug]/served-flow.ts +0 -91
- package/templates/apps/web/app/[locale]/flows/[slug]/start/page.tsx +0 -32
- package/templates/apps/web/app/[locale]/flows/[slug]/verify/page.tsx +0 -153
- package/templates/apps/web/app/[locale]/flows/[slug]/verify.actions.ts +0 -151
- package/templates/apps/web/app/[locale]/meet/confirmed/BookingHandOff.tsx +0 -128
- package/templates/apps/web/app/[locale]/meet/confirmed/__tests__/BookingHandOff.test.tsx +0 -126
- package/templates/apps/web/app/[locale]/purchase/__tests__/cancel.test.tsx +0 -162
- package/templates/apps/web/app/[locale]/purchase/__tests__/module-scope.test.ts +0 -68
- package/templates/apps/web/app/[locale]/purchase/__tests__/success.test.tsx +0 -411
- package/templates/apps/web/app/[locale]/purchase/cancel/page.tsx +0 -115
- package/templates/apps/web/app/[locale]/purchase/success/page.tsx +0 -348
- package/templates/apps/web/app/api/auth/[...all]/route.ts +0 -16
- package/templates/apps/web/app/api/auth/hub/__tests__/continuation.test.ts +0 -143
- package/templates/apps/web/app/api/auth/hub/__tests__/entry-routes.test.ts +0 -749
- package/templates/apps/web/app/api/auth/hub/authorize/__tests__/route.test.ts +0 -964
- package/templates/apps/web/app/api/auth/hub/authorize/route.ts +0 -390
- package/templates/apps/web/app/api/auth/hub/continuation.ts +0 -127
- package/templates/apps/web/app/api/auth/hub/continue/[ref]/__tests__/route.test.ts +0 -188
- package/templates/apps/web/app/api/auth/hub/continue/[ref]/route.ts +0 -53
- package/templates/apps/web/app/api/auth/hub/email/route.ts +0 -111
- package/templates/apps/web/app/api/auth/hub/entry-shared.ts +0 -163
- package/templates/apps/web/app/api/auth/hub/password/__tests__/return.test.ts +0 -86
- package/templates/apps/web/app/api/auth/hub/password/__tests__/route.test.ts +0 -368
- package/templates/apps/web/app/api/auth/hub/password/return.ts +0 -86
- package/templates/apps/web/app/api/auth/hub/password/route.ts +0 -171
- package/templates/apps/web/app/api/auth/hub/purchase/route.ts +0 -230
- package/templates/apps/web/app/api/auth/hub/purchase-link/route.ts +0 -174
- package/templates/apps/web/app/api/auth/hub/sign-up/route.ts +0 -60
- package/templates/apps/web/app/api/auth/hub/sign-up-evidence.ts +0 -97
- package/templates/apps/web/app/api/auth/mcp/__tests__/continuation.test.ts +0 -92
- package/templates/apps/web/app/api/auth/mcp/continuation.ts +0 -89
- package/templates/apps/web/app/api/auth/mcp/continue/[ref]/__tests__/route.test.ts +0 -59
- package/templates/apps/web/app/api/auth/mcp/continue/[ref]/route.ts +0 -41
- package/templates/apps/web/app/api/hub-session/__tests__/routes.test.ts +0 -1166
- package/templates/apps/web/app/api/hub-session/callback/route.ts +0 -134
- package/templates/apps/web/app/api/hub-session/email/route.ts +0 -125
- package/templates/apps/web/app/api/hub-session/one-tap/nonce/route.ts +0 -49
- package/templates/apps/web/app/api/hub-session/one-tap/route.ts +0 -106
- package/templates/apps/web/app/api/hub-session/open/route.ts +0 -111
- package/templates/apps/web/app/api/hub-session/password/return/route.ts +0 -69
- package/templates/apps/web/app/api/hub-session/password/route.ts +0 -106
- package/templates/apps/web/app/api/hub-session/sign-in/route.ts +0 -91
- package/templates/apps/web/app/api/hub-session/sign-out/route.ts +0 -54
- package/templates/apps/web/components/sign-out-trigger.tsx +0 -62
- package/templates/apps/web/lib/__tests__/account-config.test.ts +0 -704
- package/templates/apps/web/lib/__tests__/auth-routes.test.ts +0 -140
- package/templates/apps/web/lib/account-config.ts +0 -678
- package/templates/apps/web/lib/auth-routes.ts +0 -125
- package/templates/apps/web/lib/checkout-config.ts +0 -16
- package/templates/apps/web/lib/hub-session/__tests__/hub-session.test.ts +0 -433
- package/templates/apps/web/lib/hub-session/__tests__/spoke-sign-in.test.tsx +0 -332
- package/templates/apps/web/lib/hub-session/config.ts +0 -110
- package/templates/apps/web/lib/hub-session/entry.ts +0 -238
- package/templates/apps/web/lib/hub-session/index.ts +0 -21
- package/templates/apps/web/lib/hub-session/one-tap.tsx +0 -148
- package/templates/apps/web/lib/hub-session/reseal.ts +0 -90
- package/templates/apps/web/lib/hub-session/seal.ts +0 -86
- package/templates/apps/web/lib/hub-session/session.ts +0 -298
- package/templates/apps/web/lib/hub-session/spoke-sign-in.tsx +0 -277
- package/templates/apps/web/lib/next-path.ts +0 -35
- package/templates/apps/web/src/lib/__tests__/commerce-sections.test.ts +0 -57
- package/templates/apps/web/src/lib/commerce-sections.ts +0 -55
|
@@ -1,134 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Finish a sign-in through the hub (#7894 D2, D7) — `GET /api/hub-session/callback?code=…&state=…`.
|
|
3
|
-
*
|
|
4
|
-
* The URI an operator registers on the hub (`spokes sign-in-client
|
|
5
|
-
* --redirect-uri <site>/api/hub-session/callback`). It reads and clears the
|
|
6
|
-
* flow cookie, checks the returned `state` against it in constant time, and
|
|
7
|
-
* exchanges the code, the PKCE verifier and the client secret at the hub API
|
|
8
|
-
* (the api-client adds this site's spoke key; the hub requires both). On
|
|
9
|
-
* success the credential and its person are sealed into the session cookie,
|
|
10
|
-
* whose `Max-Age` is the credential's own lifetime, and the visitor lands on
|
|
11
|
-
* the flow cookie's `next` — never on a value from this request's query.
|
|
12
|
-
*
|
|
13
|
-
* Every other outcome — no flow cookie, an expired one, a state mismatch, an
|
|
14
|
-
* `error` from the hub, a failed exchange — lands on the site's home
|
|
15
|
-
* (#11095 D4; `/account` would redirect straight back into the sign-in, a
|
|
16
|
-
* loop) after BURNING any code it received
|
|
17
|
-
* (`hubSignIn.revoke({ code })`, best-effort): a code this route cannot
|
|
18
|
-
* complete must not stay live for someone else to complete (SEC-7894-4).
|
|
19
|
-
* The log line names the reason only — never the query string, a code, a
|
|
20
|
-
* state or a credential.
|
|
21
|
-
*/
|
|
22
|
-
import { timingSafeEqual } from "node:crypto";
|
|
23
|
-
|
|
24
|
-
import { hubSignIn } from "@working-theory/api-client";
|
|
25
|
-
import { hubAuthorizationCodeSchema } from "@working-theory/validation";
|
|
26
|
-
|
|
27
|
-
import {
|
|
28
|
-
type HubSessionConfig,
|
|
29
|
-
hubSessionConfig,
|
|
30
|
-
} from "../../../../lib/hub-session/config";
|
|
31
|
-
import { unseal } from "../../../../lib/hub-session/seal";
|
|
32
|
-
import {
|
|
33
|
-
HUB_SESSION_HOME_PATH,
|
|
34
|
-
cookieHeader,
|
|
35
|
-
flowCookieName,
|
|
36
|
-
hubNextPath,
|
|
37
|
-
readCookie,
|
|
38
|
-
seeOther,
|
|
39
|
-
sessionCookieFor,
|
|
40
|
-
} from "../../../../lib/hub-session/session";
|
|
41
|
-
import { SIGN_IN_PROVIDER } from "../../../../lib/topology.generated";
|
|
42
|
-
|
|
43
|
-
/** What the sign-in route sealed into the flow cookie. */
|
|
44
|
-
interface FlowPayload {
|
|
45
|
-
v: 1;
|
|
46
|
-
state: string;
|
|
47
|
-
verifier: string;
|
|
48
|
-
next: string;
|
|
49
|
-
expiresAt: number;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
function isFlow(value: unknown): value is FlowPayload {
|
|
53
|
-
if (typeof value !== "object" || value === null) return false;
|
|
54
|
-
const v = value as Record<string, unknown>;
|
|
55
|
-
return (
|
|
56
|
-
v["v"] === 1 &&
|
|
57
|
-
typeof v["state"] === "string" &&
|
|
58
|
-
typeof v["verifier"] === "string" &&
|
|
59
|
-
typeof v["next"] === "string" &&
|
|
60
|
-
typeof v["expiresAt"] === "number"
|
|
61
|
-
);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
function sameState(a: string, b: string): boolean {
|
|
65
|
-
const x = Buffer.from(a, "utf8");
|
|
66
|
-
const y = Buffer.from(b, "utf8");
|
|
67
|
-
return x.length === y.length && timingSafeEqual(x, y);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
/** Burn a code this route cannot complete. Best-effort: a failure is logged, never thrown. */
|
|
71
|
-
async function burn(config: HubSessionConfig, code: string | null): Promise<void> {
|
|
72
|
-
if (code === null || !hubAuthorizationCodeSchema.safeParse(code).success) {
|
|
73
|
-
return;
|
|
74
|
-
}
|
|
75
|
-
try {
|
|
76
|
-
await hubSignIn.revoke(
|
|
77
|
-
{ clientId: config.clientId, clientSecret: config.clientSecret },
|
|
78
|
-
{ code },
|
|
79
|
-
);
|
|
80
|
-
} catch (err) {
|
|
81
|
-
console.error(
|
|
82
|
-
`[hub-session] code burn failed errName=${err instanceof Error ? err.name : "unknown"}`,
|
|
83
|
-
);
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
// platform-decisions-waiver: api-versioning — sign-in redirect endpoint, not a versioned API contract (spec 7894 §7)
|
|
88
|
-
export async function GET(request: Request): Promise<Response> {
|
|
89
|
-
if (SIGN_IN_PROVIDER !== "hub") return new Response(null, { status: 404 });
|
|
90
|
-
const config = hubSessionConfig();
|
|
91
|
-
if (config === null) return seeOther(HUB_SESSION_HOME_PATH);
|
|
92
|
-
|
|
93
|
-
const params = new URL(request.url).searchParams;
|
|
94
|
-
const code = params.get("code");
|
|
95
|
-
const flowName = flowCookieName(config);
|
|
96
|
-
const clearFlow = cookieHeader(flowName, "", 0, config);
|
|
97
|
-
|
|
98
|
-
const refuse = async (reason: string): Promise<Response> => {
|
|
99
|
-
await burn(config, code);
|
|
100
|
-
console.warn(`[hub-session] sign-in not completed reason=${reason}`);
|
|
101
|
-
return seeOther(HUB_SESSION_HOME_PATH, [clearFlow]);
|
|
102
|
-
};
|
|
103
|
-
|
|
104
|
-
const sealed = readCookie(request.headers.get("cookie"), flowName);
|
|
105
|
-
const flow =
|
|
106
|
-
sealed === undefined
|
|
107
|
-
? null
|
|
108
|
-
: unseal(sealed, config.sessionSecret, "flow", flowName);
|
|
109
|
-
if (!isFlow(flow)) return refuse("no_flow");
|
|
110
|
-
if (flow.expiresAt <= Date.now()) return refuse("flow_expired");
|
|
111
|
-
const state = params.get("state");
|
|
112
|
-
if (state === null || !sameState(state, flow.state)) {
|
|
113
|
-
return refuse("state_mismatch");
|
|
114
|
-
}
|
|
115
|
-
if (params.has("error")) return refuse("hub_error");
|
|
116
|
-
if (code === null) return refuse("no_code");
|
|
117
|
-
|
|
118
|
-
let exchanged: Awaited<ReturnType<typeof hubSignIn.exchange>>;
|
|
119
|
-
try {
|
|
120
|
-
exchanged = await hubSignIn.exchange(
|
|
121
|
-
{ clientId: config.clientId, clientSecret: config.clientSecret },
|
|
122
|
-
{ code, redirectUri: config.redirectUri, codeVerifier: flow.verifier },
|
|
123
|
-
);
|
|
124
|
-
} catch {
|
|
125
|
-
return refuse("exchange_failed");
|
|
126
|
-
}
|
|
127
|
-
if (!exchanged.ok) return refuse(`exchange_status_${exchanged.status}`);
|
|
128
|
-
|
|
129
|
-
// The cookie's lifetime is the credential's: a malformed answer from the
|
|
130
|
-
// hub must never yield a session that does not expire (#11096 D6).
|
|
131
|
-
const session = sessionCookieFor(config, exchanged.body);
|
|
132
|
-
if (session === null) return refuse("token_response_invalid");
|
|
133
|
-
return seeOther(hubNextPath(flow.next), [clearFlow, session]);
|
|
134
|
-
}
|
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The spoke's own sign-in form, posted (#11096 D2) — `POST /api/hub-session/email`.
|
|
3
|
-
*
|
|
4
|
-
* The signed-out `/account` of a spoke that signs in through its hub is the
|
|
5
|
-
* spoke's own form (`lib/hub-session/spoke-sign-in.tsx`): one email field, the
|
|
6
|
-
* hub's sign-up agreements, Continue with Google. Its email lands here as a
|
|
7
|
-
* native form POST; this route starts a flow and asks the hub web, server to
|
|
8
|
-
* server, to mail the hub's magic link for it. Using the link signs the person
|
|
9
|
-
* in on the hub and comes back through the callback, with no hub page shown.
|
|
10
|
-
*
|
|
11
|
-
* 1. 404 unless `SIGN_IN_PROVIDER` is `"hub"`; not configured → 303
|
|
12
|
-
* `/account?error=unavailable`.
|
|
13
|
-
* 2. Same-origin only (`Sec-Fetch-Site`, `Origin`), else 403.
|
|
14
|
-
* 3. 10 posts per visitor per 10 minutes, then the bot check; a refusal is
|
|
15
|
-
* 303 `/account?error=unavailable`.
|
|
16
|
-
* 4. The form is `spokeEmailFormSchema`: one `email`, an optional `next`,
|
|
17
|
-
* zero or more ticked `agreements`. Any other field — a `password` among
|
|
18
|
-
* them (D5) — or a repeated `email` or `next` is 400.
|
|
19
|
-
* 5. A flow starts as `GET /api/hub-session/sign-in` starts one.
|
|
20
|
-
* 6. The hub web's `POST /api/auth/hub/email` gets the authorize keys, the
|
|
21
|
-
* email, the locale and — only when one was ticked — the agreements.
|
|
22
|
-
* 7. 202 → 303 `/account?sent=1` with the flow cookie; `agreements_required`
|
|
23
|
-
* → `/account?error=agreements`; anything else → `?error=unavailable`.
|
|
24
|
-
* Only the 202 sets a cookie.
|
|
25
|
-
*
|
|
26
|
-
* The answer never says whether the address has an account. Nothing here logs
|
|
27
|
-
* the email, the agreements or the flow.
|
|
28
|
-
*/
|
|
29
|
-
import { spokeEmailFormSchema } from "@working-theory/validation";
|
|
30
|
-
|
|
31
|
-
import { runBotCheck } from "../../../../lib/bot-check";
|
|
32
|
-
import { hubSessionConfig } from "../../../../lib/hub-session/config";
|
|
33
|
-
import {
|
|
34
|
-
accountPath,
|
|
35
|
-
hubError,
|
|
36
|
-
localeOfPath,
|
|
37
|
-
postToHub,
|
|
38
|
-
readFormFields,
|
|
39
|
-
} from "../../../../lib/hub-session/entry";
|
|
40
|
-
import {
|
|
41
|
-
hubNextPath,
|
|
42
|
-
isSameOrigin,
|
|
43
|
-
seeOther,
|
|
44
|
-
startHubFlow,
|
|
45
|
-
} from "../../../../lib/hub-session/session";
|
|
46
|
-
import { SIGN_IN_PROVIDER } from "../../../../lib/topology.generated";
|
|
47
|
-
import { takeVisitorLimit } from "../../../../src/lib/rate-limit";
|
|
48
|
-
|
|
49
|
-
/** The hub web's email route (D2). */
|
|
50
|
-
const HUB_EMAIL_PATH = "/api/auth/hub/email";
|
|
51
|
-
|
|
52
|
-
/** The per-visitor budget for this route. */
|
|
53
|
-
const VISITOR_LIMIT = 10;
|
|
54
|
-
const VISITOR_WINDOW_MS = 10 * 60_000;
|
|
55
|
-
|
|
56
|
-
/** The fields the form may carry, and which of them may repeat. */
|
|
57
|
-
const SINGLE_FIELDS = new Set(["email", "next"]);
|
|
58
|
-
const AGREEMENTS_FIELD = "agreements";
|
|
59
|
-
|
|
60
|
-
/** The form as `spokeEmailFormSchema` reads it, or `null` for a refused shape. */
|
|
61
|
-
function formBody(fields: Map<string, string[]>): Record<string, unknown> | null {
|
|
62
|
-
const body: Record<string, unknown> = {};
|
|
63
|
-
for (const [name, values] of fields) {
|
|
64
|
-
if (name === AGREEMENTS_FIELD) {
|
|
65
|
-
body[name] = values;
|
|
66
|
-
} else if (SINGLE_FIELDS.has(name)) {
|
|
67
|
-
if (values.length !== 1) return null;
|
|
68
|
-
body[name] = values[0];
|
|
69
|
-
} else {
|
|
70
|
-
// An unknown field (a password among them) is refused, never dropped.
|
|
71
|
-
return null;
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
return body;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
function badRequest(): Response {
|
|
78
|
-
return new Response(null, { status: 400, headers: { "Cache-Control": "no-store" } });
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
// platform-decisions-waiver: api-versioning — sign-in form endpoint, not a versioned API contract (spec 11096 §6)
|
|
82
|
-
export async function POST(request: Request): Promise<Response> {
|
|
83
|
-
if (SIGN_IN_PROVIDER !== "hub") return new Response(null, { status: 404 });
|
|
84
|
-
const config = hubSessionConfig();
|
|
85
|
-
if (config === null) return seeOther(accountPath("en", "error=unavailable"));
|
|
86
|
-
if (!isSameOrigin(request, config.siteOrigin)) {
|
|
87
|
-
return new Response(null, { status: 403 });
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
if (!takeVisitorLimit("hub-session-email", request.headers, VISITOR_LIMIT, VISITOR_WINDOW_MS).allowed) {
|
|
91
|
-
return seeOther(accountPath("en", "error=unavailable"));
|
|
92
|
-
}
|
|
93
|
-
const bot = await runBotCheck({ source: "hub-session", target: "email", scope: "write" });
|
|
94
|
-
if (bot !== "pass") return seeOther(accountPath("en", "error=unavailable"));
|
|
95
|
-
|
|
96
|
-
const fields = await readFormFields(request);
|
|
97
|
-
const raw = fields === null ? null : formBody(fields);
|
|
98
|
-
const parsed = raw === null ? null : spokeEmailFormSchema.safeParse(raw);
|
|
99
|
-
if (parsed === null || !parsed.success) return badRequest();
|
|
100
|
-
const next = hubNextPath(parsed.data.next);
|
|
101
|
-
const locale = localeOfPath(next);
|
|
102
|
-
|
|
103
|
-
const flow = startHubFlow(config, next);
|
|
104
|
-
const answer = await postToHub(config, HUB_EMAIL_PATH, {
|
|
105
|
-
client_id: config.clientId,
|
|
106
|
-
redirect_uri: config.redirectUri,
|
|
107
|
-
state: flow.state,
|
|
108
|
-
code_challenge: flow.challenge,
|
|
109
|
-
code_challenge_method: "S256",
|
|
110
|
-
email: parsed.data.email,
|
|
111
|
-
locale,
|
|
112
|
-
...(parsed.data.agreements ? { agreements: parsed.data.agreements } : {}),
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
if (answer?.status === 202) {
|
|
116
|
-
return seeOther(accountPath(locale, "sent=1"), [flow.cookie]);
|
|
117
|
-
}
|
|
118
|
-
if (answer?.status === 400 && hubError(answer) === "agreements_required") {
|
|
119
|
-
return seeOther(accountPath(locale, "error=agreements"));
|
|
120
|
-
}
|
|
121
|
-
console.warn(
|
|
122
|
-
`[hub-session] email entry not sent status=${answer === null ? "unreachable" : answer.status}`,
|
|
123
|
-
);
|
|
124
|
-
return seeOther(accountPath(locale, "error=unavailable"));
|
|
125
|
-
}
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* One Tap's nonce (#11096 D10) — `POST /api/hub-session/one-tap/nonce`.
|
|
3
|
-
*
|
|
4
|
-
* Before the spoke's sign-in page asks Google for a One Tap credential, it
|
|
5
|
-
* asks here for a nonce: 32 random bytes, answered to the page and sealed
|
|
6
|
-
* into a 300 s `HttpOnly` cookie. Google signs the nonce into the ID token,
|
|
7
|
-
* and `POST /api/hub-session/one-tap` hands the hub the cookie's copy, so a
|
|
8
|
-
* token minted for another page or another visitor does not verify.
|
|
9
|
-
*
|
|
10
|
-
* 404 unless this is a hub-sign-in spoke with `AILK_HUB_ONE_TAP=on`; 403
|
|
11
|
-
* unless same-origin. Nothing here logs the nonce.
|
|
12
|
-
*/
|
|
13
|
-
import { randomBytes } from "node:crypto";
|
|
14
|
-
|
|
15
|
-
import { hubSessionConfig } from "../../../../../lib/hub-session/config";
|
|
16
|
-
import { seal } from "../../../../../lib/hub-session/seal";
|
|
17
|
-
import {
|
|
18
|
-
ONE_TAP_NONCE_TTL_SECONDS,
|
|
19
|
-
cookieHeader,
|
|
20
|
-
isSameOrigin,
|
|
21
|
-
oneTapCookieName,
|
|
22
|
-
} from "../../../../../lib/hub-session/session";
|
|
23
|
-
import { SIGN_IN_PROVIDER } from "../../../../../lib/topology.generated";
|
|
24
|
-
|
|
25
|
-
// platform-decisions-waiver: api-versioning — sign-in step, not a versioned API contract (spec 11096 §6)
|
|
26
|
-
export function POST(request: Request): Response {
|
|
27
|
-
const config = SIGN_IN_PROVIDER === "hub" ? hubSessionConfig() : null;
|
|
28
|
-
if (config === null || !config.oneTap) return new Response(null, { status: 404 });
|
|
29
|
-
if (!isSameOrigin(request, config.siteOrigin)) {
|
|
30
|
-
return new Response(null, { status: 403 });
|
|
31
|
-
}
|
|
32
|
-
const nonce = randomBytes(32).toString("base64url");
|
|
33
|
-
const name = oneTapCookieName(config);
|
|
34
|
-
const sealed = seal(
|
|
35
|
-
{ v: 1, nonce, expiresAt: Date.now() + ONE_TAP_NONCE_TTL_SECONDS * 1000 },
|
|
36
|
-
config.sessionSecret,
|
|
37
|
-
"flow",
|
|
38
|
-
name,
|
|
39
|
-
);
|
|
40
|
-
return Response.json(
|
|
41
|
-
{ nonce },
|
|
42
|
-
{
|
|
43
|
-
headers: {
|
|
44
|
-
"Cache-Control": "no-store",
|
|
45
|
-
"Set-Cookie": cookieHeader(name, sealed, ONE_TAP_NONCE_TTL_SECONDS, config),
|
|
46
|
-
},
|
|
47
|
-
},
|
|
48
|
-
);
|
|
49
|
-
}
|
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Google One Tap for a returning person (#11096 D10) — `POST /api/hub-session/one-tap`.
|
|
3
|
-
*
|
|
4
|
-
* The spoke's `OneTap` island posts Google's ID token here as
|
|
5
|
-
* `{ credential }`. This route reads and clears the nonce cookie the nonce
|
|
6
|
-
* route set, and forwards the token, that nonce and this site's own origin to
|
|
7
|
-
* the hub API's `POST /v1/hub-sign-in/google`, authenticated as this spoke's
|
|
8
|
-
* client. The hub verifies the token against Google's keys and mints the
|
|
9
|
-
* credential the code exchange mints; this route seals it into the session
|
|
10
|
-
* cookie (`sessionCookieFor`) and answers `{ ok: true }`. The page then
|
|
11
|
-
* navigates to `next` on this site. No hub page and no Google page is shown.
|
|
12
|
-
*
|
|
13
|
-
* - 404 unless this is a hub-sign-in spoke with `AILK_HUB_ONE_TAP=on`;
|
|
14
|
-
* - 403 unless same-origin;
|
|
15
|
-
* - 400 for a body other than `spokeOneTapBodySchema` (a `password` field
|
|
16
|
-
* among them, D5) or with no live nonce cookie — no hub call;
|
|
17
|
-
* - 401 `{ ok: false }` for every hub refusal, so the page leaves the form
|
|
18
|
-
* as it is.
|
|
19
|
-
*
|
|
20
|
-
* Nothing here logs the token, the nonce or the credential.
|
|
21
|
-
*/
|
|
22
|
-
import { hubSignIn } from "@working-theory/api-client";
|
|
23
|
-
import { spokeOneTapBodySchema } from "@working-theory/validation";
|
|
24
|
-
|
|
25
|
-
import { hubSessionConfig } from "../../../../lib/hub-session/config";
|
|
26
|
-
import { readBodyText } from "../../../../lib/hub-session/entry";
|
|
27
|
-
import { unseal } from "../../../../lib/hub-session/seal";
|
|
28
|
-
import {
|
|
29
|
-
cookieHeader,
|
|
30
|
-
isSameOrigin,
|
|
31
|
-
oneTapCookieName,
|
|
32
|
-
readCookie,
|
|
33
|
-
sessionCookieFor,
|
|
34
|
-
} from "../../../../lib/hub-session/session";
|
|
35
|
-
import { SIGN_IN_PROVIDER } from "../../../../lib/topology.generated";
|
|
36
|
-
import { takeVisitorLimit } from "../../../../src/lib/rate-limit";
|
|
37
|
-
|
|
38
|
-
const VISITOR_LIMIT = 10;
|
|
39
|
-
const VISITOR_WINDOW_MS = 10 * 60_000;
|
|
40
|
-
|
|
41
|
-
function answer(status: number, ok: boolean, setCookies: readonly string[]): Response {
|
|
42
|
-
const headers = new Headers({ "Cache-Control": "no-store" });
|
|
43
|
-
for (const value of setCookies) headers.append("Set-Cookie", value);
|
|
44
|
-
return Response.json({ ok }, { status, headers });
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
/** `text` as JSON, or `null` when there is none or it does not parse. */
|
|
48
|
-
function parseJson(text: string | null): unknown {
|
|
49
|
-
if (text === null) return null;
|
|
50
|
-
try {
|
|
51
|
-
return JSON.parse(text) as unknown;
|
|
52
|
-
} catch {
|
|
53
|
-
return null;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/** The nonce the cookie seals, or `null` — absent, unreadable or expired. */
|
|
58
|
-
function sealedNonce(value: unknown): string | null {
|
|
59
|
-
if (typeof value !== "object" || value === null) return null;
|
|
60
|
-
const v = value as Record<string, unknown>;
|
|
61
|
-
if (v["v"] !== 1 || typeof v["nonce"] !== "string") return null;
|
|
62
|
-
if (typeof v["expiresAt"] !== "number" || v["expiresAt"] <= Date.now()) return null;
|
|
63
|
-
return v["nonce"];
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
// platform-decisions-waiver: api-versioning — sign-in step, not a versioned API contract (spec 11096 §6)
|
|
67
|
-
export async function POST(request: Request): Promise<Response> {
|
|
68
|
-
const config = SIGN_IN_PROVIDER === "hub" ? hubSessionConfig() : null;
|
|
69
|
-
if (config === null || !config.oneTap) return new Response(null, { status: 404 });
|
|
70
|
-
if (!isSameOrigin(request, config.siteOrigin)) {
|
|
71
|
-
return new Response(null, { status: 403 });
|
|
72
|
-
}
|
|
73
|
-
if (!takeVisitorLimit("hub-session-one-tap", request.headers, VISITOR_LIMIT, VISITOR_WINDOW_MS).allowed) {
|
|
74
|
-
return answer(429, false, []);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
// The nonce is single use: cleared on every answer from here on.
|
|
78
|
-
const name = oneTapCookieName(config);
|
|
79
|
-
const clearNonce = cookieHeader(name, "", 0, config);
|
|
80
|
-
const sealed = readCookie(request.headers.get("cookie"), name);
|
|
81
|
-
const nonce =
|
|
82
|
-
sealed === undefined ? null : sealedNonce(unseal(sealed, config.sessionSecret, "flow", name));
|
|
83
|
-
|
|
84
|
-
const body = spokeOneTapBodySchema.safeParse(parseJson(await readBodyText(request)));
|
|
85
|
-
if (!body.success || nonce === null) return answer(400, false, [clearNonce]);
|
|
86
|
-
|
|
87
|
-
let res: Awaited<ReturnType<typeof hubSignIn.google>>;
|
|
88
|
-
try {
|
|
89
|
-
res = await hubSignIn.google(
|
|
90
|
-
{ clientId: config.clientId, clientSecret: config.clientSecret },
|
|
91
|
-
{ idToken: body.data.credential, nonce, origin: config.siteOrigin },
|
|
92
|
-
);
|
|
93
|
-
} catch (err) {
|
|
94
|
-
console.error(
|
|
95
|
-
`[hub-session] one tap failed errName=${err instanceof Error ? err.name : "unknown"}`,
|
|
96
|
-
);
|
|
97
|
-
return answer(401, false, [clearNonce]);
|
|
98
|
-
}
|
|
99
|
-
if (!res.ok) {
|
|
100
|
-
console.warn(`[hub-session] one tap refused status=${res.status}`);
|
|
101
|
-
return answer(401, false, [clearNonce]);
|
|
102
|
-
}
|
|
103
|
-
const session = sessionCookieFor(config, res.body);
|
|
104
|
-
if (session === null) return answer(401, false, [clearNonce]);
|
|
105
|
-
return answer(200, true, [clearNonce, session]);
|
|
106
|
-
}
|
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* "Open my account" from a purchase link (#11096 D9) — `POST /api/hub-session/open`.
|
|
3
|
-
*
|
|
4
|
-
* After a paid Checkout Session the hub mails the buyer one link to this
|
|
5
|
-
* spoke's `/account?claim=<claim>`. That page's GET changes nothing (a mail
|
|
6
|
-
* scanner that follows the link creates no account, SEC-11096-3): it shows
|
|
7
|
-
* the agreements and one "Open my account" button, whose form posts the
|
|
8
|
-
* claim here. This route starts a flow and spends the claim at the hub web's
|
|
9
|
-
* `POST /api/auth/hub/purchase`, server to server, as this spoke's client.
|
|
10
|
-
*
|
|
11
|
-
* - 200 `{ verifyUrl }` on the hub's own origin → 303 there, with the flow
|
|
12
|
-
* cookie: the hub's verify creates the account, and the redirects land on
|
|
13
|
-
* `/account` signed in;
|
|
14
|
-
* - 409 `account_exists` → 303 `/account?error=exists` (the form asks for
|
|
15
|
-
* the email instead: a claim never signs an existing account in);
|
|
16
|
-
* - anything else → 303 `/account?error=claim`.
|
|
17
|
-
*
|
|
18
|
-
* The checks in front are the email route's (D2 steps 1–3); the body is
|
|
19
|
-
* `spokeOpenFormSchema`, the one `claim` field. Nothing here logs the claim.
|
|
20
|
-
*/
|
|
21
|
-
import { hubPurchaseResponseSchema, spokeOpenFormSchema } from "@working-theory/validation";
|
|
22
|
-
|
|
23
|
-
import { runBotCheck } from "../../../../lib/bot-check";
|
|
24
|
-
import { hubSessionConfig } from "../../../../lib/hub-session/config";
|
|
25
|
-
import {
|
|
26
|
-
accountPath,
|
|
27
|
-
hubError,
|
|
28
|
-
postToHub,
|
|
29
|
-
readFormFields,
|
|
30
|
-
} from "../../../../lib/hub-session/entry";
|
|
31
|
-
import {
|
|
32
|
-
HUB_SESSION_FALLBACK_PATH,
|
|
33
|
-
isSameOrigin,
|
|
34
|
-
seeOther,
|
|
35
|
-
startHubFlow,
|
|
36
|
-
} from "../../../../lib/hub-session/session";
|
|
37
|
-
import { SIGN_IN_PROVIDER } from "../../../../lib/topology.generated";
|
|
38
|
-
import { takeVisitorLimit } from "../../../../src/lib/rate-limit";
|
|
39
|
-
|
|
40
|
-
/** The hub web's claim-spending route (D9). */
|
|
41
|
-
const HUB_PURCHASE_PATH = "/api/auth/hub/purchase";
|
|
42
|
-
|
|
43
|
-
const VISITOR_LIMIT = 10;
|
|
44
|
-
const VISITOR_WINDOW_MS = 10 * 60_000;
|
|
45
|
-
|
|
46
|
-
/** The one `claim` field, or `null` for any other shape. */
|
|
47
|
-
function formBody(fields: Map<string, string[]>): Record<string, unknown> | null {
|
|
48
|
-
const body: Record<string, unknown> = {};
|
|
49
|
-
for (const [name, values] of fields) {
|
|
50
|
-
if (values.length !== 1) return null;
|
|
51
|
-
body[name] = values[0];
|
|
52
|
-
}
|
|
53
|
-
return body;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
/** `raw` when it is a URL on `hubOrigin`, else `null`. */
|
|
57
|
-
function hubUrl(raw: string, hubOrigin: string): string | null {
|
|
58
|
-
try {
|
|
59
|
-
const url = new URL(raw);
|
|
60
|
-
return url.origin === hubOrigin ? url.toString() : null;
|
|
61
|
-
} catch {
|
|
62
|
-
return null;
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
// platform-decisions-waiver: api-versioning — sign-in form endpoint, not a versioned API contract (spec 11096 §6)
|
|
67
|
-
export async function POST(request: Request): Promise<Response> {
|
|
68
|
-
if (SIGN_IN_PROVIDER !== "hub") return new Response(null, { status: 404 });
|
|
69
|
-
const config = hubSessionConfig();
|
|
70
|
-
if (config === null) return seeOther(accountPath("en", "error=unavailable"));
|
|
71
|
-
if (!isSameOrigin(request, config.siteOrigin)) {
|
|
72
|
-
return new Response(null, { status: 403 });
|
|
73
|
-
}
|
|
74
|
-
const refused = seeOther(accountPath("en", "error=claim"));
|
|
75
|
-
if (!takeVisitorLimit("hub-session-open", request.headers, VISITOR_LIMIT, VISITOR_WINDOW_MS).allowed) {
|
|
76
|
-
return refused;
|
|
77
|
-
}
|
|
78
|
-
if ((await runBotCheck({ source: "hub-session", target: "open", scope: "write" })) !== "pass") {
|
|
79
|
-
return refused;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
const fields = await readFormFields(request);
|
|
83
|
-
const raw = fields === null ? null : formBody(fields);
|
|
84
|
-
const parsed = raw === null ? null : spokeOpenFormSchema.safeParse(raw);
|
|
85
|
-
if (parsed === null || !parsed.success) {
|
|
86
|
-
return new Response(null, { status: 400, headers: { "Cache-Control": "no-store" } });
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
const flow = startHubFlow(config, HUB_SESSION_FALLBACK_PATH);
|
|
90
|
-
const answer = await postToHub(config, HUB_PURCHASE_PATH, {
|
|
91
|
-
claim: parsed.data.claim,
|
|
92
|
-
client_id: config.clientId,
|
|
93
|
-
redirect_uri: config.redirectUri,
|
|
94
|
-
state: flow.state,
|
|
95
|
-
code_challenge: flow.challenge,
|
|
96
|
-
code_challenge_method: "S256",
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
if (answer?.status === 200) {
|
|
100
|
-
const body = hubPurchaseResponseSchema.safeParse(answer.body);
|
|
101
|
-
const verifyUrl = body.success ? hubUrl(body.data.verifyUrl, config.hubOrigin) : null;
|
|
102
|
-
if (verifyUrl !== null) return seeOther(verifyUrl, [flow.cookie]);
|
|
103
|
-
}
|
|
104
|
-
if (answer?.status === 409 && hubError(answer) === "account_exists") {
|
|
105
|
-
return seeOther(accountPath("en", "error=exists"));
|
|
106
|
-
}
|
|
107
|
-
console.warn(
|
|
108
|
-
`[hub-session] purchase claim not opened status=${answer === null ? "unreachable" : answer.status} reason=${hubError(answer) ?? "none"}`,
|
|
109
|
-
);
|
|
110
|
-
return refused;
|
|
111
|
-
}
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Where the hub's set-password page returns a spoke's person (#11162) —
|
|
3
|
-
* `GET /api/hub-session/password/return?next=<path>`.
|
|
4
|
-
*
|
|
5
|
-
* Saving a password on the hub ends every session and every spoke
|
|
6
|
-
* credential the person held (`onPasswordReset`, SEC-7894-5) — the Security
|
|
7
|
-
* tab's own copy says so. The sealed cookie this spoke keeps therefore
|
|
8
|
-
* names a credential the hub no longer honours, and a page that read it as
|
|
9
|
-
* signed in would fail closed on the hub's refusal instead of showing the
|
|
10
|
-
* tab. So the hub's page lands here first:
|
|
11
|
-
*
|
|
12
|
-
* 1. 404 unless `SIGN_IN_PROVIDER` is `"hub"`; not configured → 303 home.
|
|
13
|
-
* 2. `next` is the sanitized same-origin page path (`hubNextPath`), else
|
|
14
|
-
* `/account`.
|
|
15
|
-
* 3. With a session cookie, the hub is asked once whether the credential
|
|
16
|
-
* still stands (`GET /v1/hub-sign-in/me`). A 401 — the one status the
|
|
17
|
-
* hub answers a credential it no longer honours — clears the cookie, so
|
|
18
|
-
* the gate on `next` shows this spoke's own sign-in form and the person
|
|
19
|
-
* comes back to the tab with a fresh credential; a credential the hub
|
|
20
|
-
* still honours, no cookie, or a hub that cannot answer (a limit, an
|
|
21
|
-
* outage, a thrown read) leaves the cookie as it is.
|
|
22
|
-
* 4. 303 to `next`, always.
|
|
23
|
-
*
|
|
24
|
-
* A GET, reachable cross-site: it changes nothing an attacker could not
|
|
25
|
-
* already cause — the one write is to drop a cookie the hub has ALREADY
|
|
26
|
-
* refused, and no credential is revoked here. Nothing is logged but a
|
|
27
|
-
* status; the credential never is.
|
|
28
|
-
*/
|
|
29
|
-
import { hubSignIn } from "@working-theory/api-client";
|
|
30
|
-
|
|
31
|
-
import { hubSessionConfig } from "../../../../../lib/hub-session/config";
|
|
32
|
-
import {
|
|
33
|
-
cookieHeader,
|
|
34
|
-
HUB_SESSION_HOME_PATH,
|
|
35
|
-
hubNextPath,
|
|
36
|
-
readHubSessionPayload,
|
|
37
|
-
seeOther,
|
|
38
|
-
sessionCookieName,
|
|
39
|
-
} from "../../../../../lib/hub-session/session";
|
|
40
|
-
import { SIGN_IN_PROVIDER } from "../../../../../lib/topology.generated";
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* Whether the hub still honours the credential: `false` only on its 401,
|
|
44
|
-
* `null` when it could not answer — any other status, or a thrown read.
|
|
45
|
-
*/
|
|
46
|
-
async function credentialStands(accessToken: string): Promise<boolean | null> {
|
|
47
|
-
try {
|
|
48
|
-
const res = await hubSignIn.me({ headers: { authorization: `Bearer ${accessToken}` } });
|
|
49
|
-
if (res.ok) return true;
|
|
50
|
-
return res.status === 401 ? false : null;
|
|
51
|
-
} catch {
|
|
52
|
-
return null;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
// platform-decisions-waiver: api-versioning — a sign-in step of the spoke's own form, not a versioned API contract (spec 11096 §6)
|
|
57
|
-
export async function GET(request: Request): Promise<Response> {
|
|
58
|
-
if (SIGN_IN_PROVIDER !== "hub") return new Response(null, { status: 404 });
|
|
59
|
-
const config = hubSessionConfig();
|
|
60
|
-
if (config === null) return seeOther(HUB_SESSION_HOME_PATH);
|
|
61
|
-
|
|
62
|
-
const next = hubNextPath(new URL(request.url).searchParams.get("next"));
|
|
63
|
-
const session = readHubSessionPayload(request.headers);
|
|
64
|
-
if (session === null) return seeOther(next);
|
|
65
|
-
|
|
66
|
-
const stands = await credentialStands(session.accessToken);
|
|
67
|
-
if (stands !== false) return seeOther(next);
|
|
68
|
-
return seeOther(next, [cookieHeader(sessionCookieName(config), "", 0, config)]);
|
|
69
|
-
}
|