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,368 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @jest-environment node
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* `POST /api/auth/hub/password` — the hub web's half of a spoke-hosted Set /
|
|
7
|
-
* Change password (#11162 AC-2).
|
|
8
|
-
*
|
|
9
|
-
* Better Auth's internal adapter (the `reset-password:<token>` row) and
|
|
10
|
-
* `@working-theory/api-client` (the hub API's client-and-credential check,
|
|
11
|
-
* the signed mail relay) are the external boundaries; both are doubles. The
|
|
12
|
-
* route's own decisions are under test: what it accepts, in what order it
|
|
13
|
-
* refuses, which person it mints for, where the mailed link lands, and what
|
|
14
|
-
* it never sends.
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
|
-
import { createHmac } from "node:crypto";
|
|
18
|
-
|
|
19
|
-
const mockSecret = "k".repeat(43);
|
|
20
|
-
const mockCreateVerificationValue = jest.fn();
|
|
21
|
-
const mockDeleteVerificationByIdentifier = jest.fn();
|
|
22
|
-
// eslint-disable-next-line no-restricted-syntax -- auth.ts is the Better Auth singleton (its adapter needs a live database); this stand-in for its internal adapter is the repo-standard double for that boundary (see ../../__tests__/entry-routes.test.ts).
|
|
23
|
-
jest.mock("../../../../../../auth", () => ({
|
|
24
|
-
__esModule: true,
|
|
25
|
-
auth: {
|
|
26
|
-
$context: Promise.resolve({
|
|
27
|
-
// The library's resolved base: the pinned origin plus `/api/auth`.
|
|
28
|
-
baseURL: "https://hub.example/api/auth",
|
|
29
|
-
internalAdapter: {
|
|
30
|
-
createVerificationValue: (...args: unknown[]) => mockCreateVerificationValue(...args),
|
|
31
|
-
deleteVerificationByIdentifier: (...args: unknown[]) =>
|
|
32
|
-
mockDeleteVerificationByIdentifier(...args),
|
|
33
|
-
},
|
|
34
|
-
}),
|
|
35
|
-
},
|
|
36
|
-
}));
|
|
37
|
-
|
|
38
|
-
// eslint-disable-next-line no-restricted-syntax -- #507: auth-secret.ts is a pure env read; pinned so the ref's seal is checkable here.
|
|
39
|
-
jest.mock("../../../../../../lib/auth-secret", () => ({
|
|
40
|
-
__esModule: true,
|
|
41
|
-
resolveSecret: () => mockSecret,
|
|
42
|
-
}));
|
|
43
|
-
|
|
44
|
-
const mockPassword = jest.fn();
|
|
45
|
-
const mockMailSend = jest.fn();
|
|
46
|
-
jest.mock("@working-theory/api-client", () => ({
|
|
47
|
-
__esModule: true,
|
|
48
|
-
hubSignIn: { password: (...args: unknown[]) => mockPassword(...args) },
|
|
49
|
-
authEmail: { send: (...args: unknown[]) => mockMailSend(...args) },
|
|
50
|
-
}));
|
|
51
|
-
|
|
52
|
-
const mockResetSendConfigured = jest.fn();
|
|
53
|
-
// eslint-disable-next-line no-restricted-syntax -- #507: auth-env.ts is a pure env-introspection module; the route reads one predicate of it.
|
|
54
|
-
jest.mock("../../../../../../lib/auth-env", () => ({
|
|
55
|
-
__esModule: true,
|
|
56
|
-
resetSendConfigured: () => mockResetSendConfigured(),
|
|
57
|
-
}));
|
|
58
|
-
|
|
59
|
-
import { __resetRefusedCallers } from "../../entry-shared";
|
|
60
|
-
import { SPOKE_RETURN_PATH, openSecurityReturn } from "../return";
|
|
61
|
-
import { POST } from "../route";
|
|
62
|
-
|
|
63
|
-
const HUB = "https://hub.example";
|
|
64
|
-
const SPOKE = "https://spoke.example";
|
|
65
|
-
const CALLBACK = `${SPOKE}/api/hub-session/callback`;
|
|
66
|
-
const BASIC = "Basic c3Bva2VfYWJjOnNlY3JldA==";
|
|
67
|
-
const SPOKE_KEY = "ailk_spk_spoke";
|
|
68
|
-
const CREDENTIAL = `ailk_hst_${"t".repeat(43)}`;
|
|
69
|
-
const RELAY_SECRET = "relay-secret";
|
|
70
|
-
const USER = {
|
|
71
|
-
id: "user_1",
|
|
72
|
-
name: "Pat",
|
|
73
|
-
email: "pat@example.com",
|
|
74
|
-
emailVerified: true,
|
|
75
|
-
createdAt: "2026-09-01T00:00:00.000Z",
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
const BODY = {
|
|
79
|
-
client_id: "spoke_abc",
|
|
80
|
-
redirect_uri: CALLBACK,
|
|
81
|
-
access_token: CREDENTIAL,
|
|
82
|
-
locale: "en",
|
|
83
|
-
return_path: "/account/security",
|
|
84
|
-
};
|
|
85
|
-
|
|
86
|
-
const CLIENT_HEADERS = { authorization: BASIC, "x-ailk-spoke-key": SPOKE_KEY };
|
|
87
|
-
|
|
88
|
-
/** Where a completed reset lands: the spoke's return route, the tab as `next`. */
|
|
89
|
-
function landing(origin: string, path: string): string {
|
|
90
|
-
return `${origin}${SPOKE_RETURN_PATH}?next=${encodeURIComponent(path)}`;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
function request(body: unknown, headers: Record<string, string> = CLIENT_HEADERS): Request {
|
|
94
|
-
return new Request(`${HUB}/api/auth/hub/password`, {
|
|
95
|
-
method: "POST",
|
|
96
|
-
headers: { "content-type": "application/json", ...headers },
|
|
97
|
-
body: typeof body === "string" ? body : JSON.stringify(body),
|
|
98
|
-
});
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
function apiAnswers(hasPassword: boolean): void {
|
|
102
|
-
mockPassword.mockResolvedValue({
|
|
103
|
-
ok: true,
|
|
104
|
-
status: 200,
|
|
105
|
-
body: { clientId: "spoke_abc", origin: SPOKE, user: USER, hasPassword },
|
|
106
|
-
});
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
/** The one mail the relay double received, parsed. */
|
|
110
|
-
function sentMail(): { body: Record<string, unknown>; headers: Record<string, string> } {
|
|
111
|
-
expect(mockMailSend).toHaveBeenCalledTimes(1);
|
|
112
|
-
const [rawBody, headers] = mockMailSend.mock.calls[0] as [string, Record<string, string>];
|
|
113
|
-
return { body: JSON.parse(rawBody) as Record<string, unknown>, headers };
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
/** The token the one minted row carries. */
|
|
117
|
-
function mintedToken(): string {
|
|
118
|
-
expect(mockCreateVerificationValue).toHaveBeenCalledTimes(1);
|
|
119
|
-
const [row] = mockCreateVerificationValue.mock.calls[0] as [{ identifier: string }];
|
|
120
|
-
return row.identifier.replace(/^reset-password:/, "");
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
const ORIGINAL_ENV = process.env;
|
|
124
|
-
|
|
125
|
-
beforeEach(() => {
|
|
126
|
-
jest.resetAllMocks();
|
|
127
|
-
__resetRefusedCallers();
|
|
128
|
-
process.env = {
|
|
129
|
-
...ORIGINAL_ENV,
|
|
130
|
-
// The bare origin, as every deployment sets it (`apps/web/.env.example`).
|
|
131
|
-
BETTER_AUTH_URL: HUB,
|
|
132
|
-
AUTH_EMAIL_WEBHOOK_SECRET: RELAY_SECRET,
|
|
133
|
-
NEXT_PUBLIC_ENABLED_LOCALES: "en,fr",
|
|
134
|
-
};
|
|
135
|
-
mockResetSendConfigured.mockReturnValue(true);
|
|
136
|
-
apiAnswers(false);
|
|
137
|
-
mockCreateVerificationValue.mockResolvedValue({});
|
|
138
|
-
mockDeleteVerificationByIdentifier.mockResolvedValue(undefined);
|
|
139
|
-
mockMailSend.mockResolvedValue({ ok: true, status: 202 });
|
|
140
|
-
jest.spyOn(console, "info").mockImplementation(() => undefined);
|
|
141
|
-
});
|
|
142
|
-
|
|
143
|
-
afterAll(() => {
|
|
144
|
-
process.env = ORIGINAL_ENV;
|
|
145
|
-
});
|
|
146
|
-
|
|
147
|
-
describe("the accepted request", () => {
|
|
148
|
-
it("asks the API's check with the spoke's two headers and the body's three keys, mints the person's reset row for an hour, and answers 202", async () => {
|
|
149
|
-
const before = Date.now();
|
|
150
|
-
const res = await POST(request(BODY));
|
|
151
|
-
|
|
152
|
-
expect(res.status).toBe(202);
|
|
153
|
-
expect(await res.json()).toEqual({ sent: true });
|
|
154
|
-
expect(res.headers.get("cache-control")).toBe("no-store");
|
|
155
|
-
expect(mockPassword).toHaveBeenCalledWith(
|
|
156
|
-
{ authorization: BASIC, spokeKey: SPOKE_KEY },
|
|
157
|
-
{ clientId: "spoke_abc", redirectUri: CALLBACK, accessToken: CREDENTIAL },
|
|
158
|
-
);
|
|
159
|
-
|
|
160
|
-
const [row] = mockCreateVerificationValue.mock.calls[0] as [
|
|
161
|
-
{ identifier: string; value: string; expiresAt: Date },
|
|
162
|
-
];
|
|
163
|
-
expect(row.identifier).toMatch(/^reset-password:[A-Za-z0-9_-]{32}$/);
|
|
164
|
-
expect(row.value).toBe(USER.id);
|
|
165
|
-
const ttl = row.expiresAt.getTime() - before;
|
|
166
|
-
expect(ttl).toBeGreaterThanOrEqual(3600_000 - 5_000);
|
|
167
|
-
expect(ttl).toBeLessThanOrEqual(3600_000 + 5_000);
|
|
168
|
-
});
|
|
169
|
-
|
|
170
|
-
it("mails the API's person — never a body address — Better Auth's own link under its /api/auth base, whose callback is the hub's reset page carrying a return to the spoke's Security tab", async () => {
|
|
171
|
-
await POST(request(BODY));
|
|
172
|
-
const token = mintedToken();
|
|
173
|
-
const { body, headers } = sentMail();
|
|
174
|
-
|
|
175
|
-
expect(body).toEqual({
|
|
176
|
-
kind: "password-reset",
|
|
177
|
-
userId: USER.id,
|
|
178
|
-
to: USER.email,
|
|
179
|
-
url: expect.stringContaining(`${HUB}/api/auth/reset-password/${token}?callbackURL=`),
|
|
180
|
-
expiresInMinutes: 60,
|
|
181
|
-
});
|
|
182
|
-
// The library's own route, never a page path on the bare origin.
|
|
183
|
-
expect(String(body.url).startsWith(`${HUB}/api/auth/reset-password/`)).toBe(true);
|
|
184
|
-
expect(String(body.url).startsWith(`${HUB}/reset-password/`)).toBe(false);
|
|
185
|
-
const callbackURL = new URL(decodeURIComponent(String(body.url).split("callbackURL=")[1] ?? ""));
|
|
186
|
-
expect(callbackURL.origin).toBe(HUB);
|
|
187
|
-
expect(callbackURL.pathname).toBe("/reset-password");
|
|
188
|
-
expect([...callbackURL.searchParams.keys()]).toEqual(["ref"]);
|
|
189
|
-
expect(openSecurityReturn(callbackURL.searchParams.get("ref") ?? "", mockSecret)).toBe(
|
|
190
|
-
landing(SPOKE, "/account/security"),
|
|
191
|
-
);
|
|
192
|
-
|
|
193
|
-
// Signed for the relay over the exact serialized body.
|
|
194
|
-
const expected = `sha256=${createHmac("sha256", RELAY_SECRET)
|
|
195
|
-
.update(`${headers["x-ailk-auth-email-timestamp"]}.${mockMailSend.mock.calls[0]?.[0]}`, "utf8")
|
|
196
|
-
.digest("hex")}`;
|
|
197
|
-
expect(headers["x-ailk-auth-email-signature"]).toBe(expected);
|
|
198
|
-
});
|
|
199
|
-
|
|
200
|
-
it("the return is the client's REGISTERED origin from the API, never the body's callback", async () => {
|
|
201
|
-
mockPassword.mockResolvedValue({
|
|
202
|
-
ok: true,
|
|
203
|
-
status: 200,
|
|
204
|
-
body: { clientId: "spoke_abc", origin: "https://registered.example", user: USER, hasPassword: true },
|
|
205
|
-
});
|
|
206
|
-
await POST(request(BODY));
|
|
207
|
-
const callbackURL = new URL(
|
|
208
|
-
decodeURIComponent(String(sentMail().body.url).split("callbackURL=")[1] ?? ""),
|
|
209
|
-
);
|
|
210
|
-
expect(openSecurityReturn(callbackURL.searchParams.get("ref") ?? "", mockSecret)).toBe(
|
|
211
|
-
landing("https://registered.example", "/account/security"),
|
|
212
|
-
);
|
|
213
|
-
});
|
|
214
|
-
|
|
215
|
-
it("renders the hub's page under the body's locale and returns to the locale's Security tab", async () => {
|
|
216
|
-
await POST(request({ ...BODY, locale: "fr", return_path: "/fr/account/security" }));
|
|
217
|
-
const callbackURL = new URL(
|
|
218
|
-
decodeURIComponent(String(sentMail().body.url).split("callbackURL=")[1] ?? ""),
|
|
219
|
-
);
|
|
220
|
-
expect(callbackURL.pathname).toBe("/fr/reset-password");
|
|
221
|
-
expect(openSecurityReturn(callbackURL.searchParams.get("ref") ?? "", mockSecret)).toBe(
|
|
222
|
-
landing(SPOKE, "/fr/account/security"),
|
|
223
|
-
);
|
|
224
|
-
});
|
|
225
|
-
|
|
226
|
-
it("a locale this hub does not enable renders the default page", async () => {
|
|
227
|
-
await POST(request({ ...BODY, locale: "de" }));
|
|
228
|
-
const callbackURL = new URL(
|
|
229
|
-
decodeURIComponent(String(sentMail().body.url).split("callbackURL=")[1] ?? ""),
|
|
230
|
-
);
|
|
231
|
-
expect(callbackURL.pathname).toBe("/reset-password");
|
|
232
|
-
});
|
|
233
|
-
});
|
|
234
|
-
|
|
235
|
-
describe("the body", () => {
|
|
236
|
-
it.each([
|
|
237
|
-
["an email (the person is the credential's)", { ...BODY, email: "eve@example.com" }],
|
|
238
|
-
["a password", { ...BODY, password: "hunter22" }],
|
|
239
|
-
["no credential", { ...BODY, access_token: undefined }],
|
|
240
|
-
["a credential of another shape", { ...BODY, access_token: "Bearer something" }],
|
|
241
|
-
["a return path off the Security tab", { ...BODY, return_path: "/account" }],
|
|
242
|
-
["a return path with a query", { ...BODY, return_path: "/account/security?x=1" }],
|
|
243
|
-
["a return path that is a URL", { ...BODY, return_path: "https://evil.example/account/security" }],
|
|
244
|
-
["a malformed locale", { ...BODY, locale: "english" }],
|
|
245
|
-
["a body that is not JSON", "client_id=spoke_abc"],
|
|
246
|
-
] as Array<[string, unknown]>)("%s → 400 invalid_request, no API call, nothing minted or sent", async (_label, body) => {
|
|
247
|
-
const res = await POST(request(body));
|
|
248
|
-
expect(res.status).toBe(400);
|
|
249
|
-
expect(await res.json()).toEqual({ error: "invalid_request" });
|
|
250
|
-
expect(mockPassword).not.toHaveBeenCalled();
|
|
251
|
-
expect(mockCreateVerificationValue).not.toHaveBeenCalled();
|
|
252
|
-
expect(mockMailSend).not.toHaveBeenCalled();
|
|
253
|
-
});
|
|
254
|
-
|
|
255
|
-
it("a body past 4 KB → 400", async () => {
|
|
256
|
-
const res = await POST(request({ ...BODY, pad: "x".repeat(5000) }));
|
|
257
|
-
expect(res.status).toBe(400);
|
|
258
|
-
expect(mockPassword).not.toHaveBeenCalled();
|
|
259
|
-
});
|
|
260
|
-
});
|
|
261
|
-
|
|
262
|
-
describe("the client", () => {
|
|
263
|
-
it.each([
|
|
264
|
-
["no Authorization", { "x-ailk-spoke-key": SPOKE_KEY }],
|
|
265
|
-
["no spoke key", { authorization: BASIC }],
|
|
266
|
-
["a Bearer Authorization", { authorization: `Bearer ${CREDENTIAL}`, "x-ailk-spoke-key": SPOKE_KEY }],
|
|
267
|
-
] as Array<[string, Record<string, string>]>)("%s → 401 invalid_client before any API call", async (_label, headers) => {
|
|
268
|
-
const res = await POST(request(BODY, headers));
|
|
269
|
-
expect(res.status).toBe(401);
|
|
270
|
-
expect(await res.json()).toEqual({ error: "invalid_client" });
|
|
271
|
-
expect(mockPassword).not.toHaveBeenCalled();
|
|
272
|
-
expect(mockMailSend).not.toHaveBeenCalled();
|
|
273
|
-
});
|
|
274
|
-
|
|
275
|
-
it.each([
|
|
276
|
-
[401, "invalid_client"],
|
|
277
|
-
[400, "invalid_grant"],
|
|
278
|
-
[400, "invalid_request"],
|
|
279
|
-
[429, "rate_limited"],
|
|
280
|
-
])("the API's %i %s is passed on, and nothing is minted or sent", async (status, code) => {
|
|
281
|
-
mockPassword.mockResolvedValue({
|
|
282
|
-
ok: false,
|
|
283
|
-
status,
|
|
284
|
-
body: { ok: false, error: { code, message: "refused" } },
|
|
285
|
-
});
|
|
286
|
-
const res = await POST(request(BODY));
|
|
287
|
-
expect(res.status).toBe(status);
|
|
288
|
-
expect(await res.json()).toEqual({ error: code });
|
|
289
|
-
expect(mockCreateVerificationValue).not.toHaveBeenCalled();
|
|
290
|
-
expect(mockMailSend).not.toHaveBeenCalled();
|
|
291
|
-
});
|
|
292
|
-
|
|
293
|
-
it("an API that cannot be reached → 503", async () => {
|
|
294
|
-
mockPassword.mockRejectedValue(new Error("network"));
|
|
295
|
-
const res = await POST(request(BODY));
|
|
296
|
-
expect(res.status).toBe(503);
|
|
297
|
-
expect(mockMailSend).not.toHaveBeenCalled();
|
|
298
|
-
});
|
|
299
|
-
|
|
300
|
-
it("ten API refusals of a caller's credentials → 429 before the eleventh API call", async () => {
|
|
301
|
-
mockPassword.mockResolvedValue({
|
|
302
|
-
ok: false,
|
|
303
|
-
status: 401,
|
|
304
|
-
body: { ok: false, error: { code: "invalid_client", message: "refused" } },
|
|
305
|
-
});
|
|
306
|
-
process.env.VERCEL = "1";
|
|
307
|
-
const headers = { ...CLIENT_HEADERS, "x-vercel-forwarded-for": "203.0.113.5" };
|
|
308
|
-
for (let i = 0; i < 10; i++) {
|
|
309
|
-
expect((await POST(request(BODY, headers))).status).toBe(401);
|
|
310
|
-
}
|
|
311
|
-
mockPassword.mockClear();
|
|
312
|
-
const res = await POST(request(BODY, headers));
|
|
313
|
-
expect(res.status).toBe(429);
|
|
314
|
-
expect(mockPassword).not.toHaveBeenCalled();
|
|
315
|
-
// Another caller is not.
|
|
316
|
-
const other = await POST(request(BODY, { ...CLIENT_HEADERS, "x-vercel-forwarded-for": "203.0.113.6" }));
|
|
317
|
-
expect(other.status).toBe(401);
|
|
318
|
-
});
|
|
319
|
-
});
|
|
320
|
-
|
|
321
|
-
describe("the hub", () => {
|
|
322
|
-
it("with no pinned origin → 503 before anything", async () => {
|
|
323
|
-
delete process.env.BETTER_AUTH_URL;
|
|
324
|
-
const res = await POST(request(BODY));
|
|
325
|
-
expect(res.status).toBe(503);
|
|
326
|
-
expect(mockPassword).not.toHaveBeenCalled();
|
|
327
|
-
});
|
|
328
|
-
|
|
329
|
-
it("that cannot complete a reset → 503 before the API check charges a budget; nothing minted or sent", async () => {
|
|
330
|
-
mockResetSendConfigured.mockReturnValue(false);
|
|
331
|
-
const res = await POST(request(BODY));
|
|
332
|
-
expect(res.status).toBe(503);
|
|
333
|
-
expect(mockPassword).not.toHaveBeenCalled();
|
|
334
|
-
expect(mockCreateVerificationValue).not.toHaveBeenCalled();
|
|
335
|
-
expect(mockMailSend).not.toHaveBeenCalled();
|
|
336
|
-
});
|
|
337
|
-
|
|
338
|
-
it("whose row cannot be written → 503, nothing sent", async () => {
|
|
339
|
-
mockCreateVerificationValue.mockRejectedValue(new Error("db"));
|
|
340
|
-
const res = await POST(request(BODY));
|
|
341
|
-
expect(res.status).toBe(503);
|
|
342
|
-
expect(mockMailSend).not.toHaveBeenCalled();
|
|
343
|
-
});
|
|
344
|
-
|
|
345
|
-
it.each([
|
|
346
|
-
["a relay refusal", () => mockMailSend.mockResolvedValue({ ok: false, status: 500 })],
|
|
347
|
-
["a relay throw", () => mockMailSend.mockRejectedValue(new Error("network"))],
|
|
348
|
-
])("%s → 503, and the unused row is dropped", async (_label, arrange) => {
|
|
349
|
-
arrange();
|
|
350
|
-
const res = await POST(request(BODY));
|
|
351
|
-
expect(res.status).toBe(503);
|
|
352
|
-
expect(mockDeleteVerificationByIdentifier).toHaveBeenCalledWith(`reset-password:${mintedToken()}`);
|
|
353
|
-
});
|
|
354
|
-
});
|
|
355
|
-
|
|
356
|
-
it("logs the outcome and nothing else — no address, credential, token or ref", async () => {
|
|
357
|
-
const info = jest.spyOn(console, "info").mockImplementation(() => undefined);
|
|
358
|
-
const warn = jest.spyOn(console, "warn").mockImplementation(() => undefined);
|
|
359
|
-
const error = jest.spyOn(console, "error").mockImplementation(() => undefined);
|
|
360
|
-
await POST(request(BODY));
|
|
361
|
-
const token = mintedToken();
|
|
362
|
-
const logged = [...info.mock.calls, ...warn.mock.calls, ...error.mock.calls].flat().join(" ");
|
|
363
|
-
expect(logged).toContain('"outcome":"sent"');
|
|
364
|
-
expect(logged).not.toContain(USER.email);
|
|
365
|
-
expect(logged).not.toContain(CREDENTIAL);
|
|
366
|
-
expect(logged).not.toContain(token);
|
|
367
|
-
expect(logged).not.toContain(SPOKE_KEY);
|
|
368
|
-
});
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Where the hub's set-password page returns a spoke's person (#11162).
|
|
3
|
-
*
|
|
4
|
-
* The link the hub mails for a spoke's Security tab lands on the hub's own
|
|
5
|
-
* `/reset-password` carrying `?ref=`: the spoke's REGISTERED origin (the
|
|
6
|
-
* hub API answered it from the client registry, never the spoke's request)
|
|
7
|
-
* and the Security tab's path, sealed under their own name so a continuation
|
|
8
|
-
* or a purchase claim never opens here and the reverse. The page opens the
|
|
9
|
-
* ref and sends a completed reset to the spoke's return route,
|
|
10
|
-
* `<origin>/api/hub-session/password/return?next=<path>`: saving a password
|
|
11
|
-
* ends every spoke credential (`onPasswordReset`), so the spoke drops its
|
|
12
|
-
* now-dead session there and the tab's gate shows the spoke's own sign-in,
|
|
13
|
-
* which brings the person back to the tab. A ref that does not open, or
|
|
14
|
-
* holds anything but an origin and a Security path, is ignored and the page
|
|
15
|
-
* falls back to the hub's sign-in — never to a URL it did not seal.
|
|
16
|
-
*
|
|
17
|
-
* The ref is opaque but not a secret: it carries only the two public facts.
|
|
18
|
-
* Nothing here logs one.
|
|
19
|
-
*/
|
|
20
|
-
import { spokeSecurityReturnPathSchema } from "@working-theory/validation";
|
|
21
|
-
|
|
22
|
-
import { mintContinuation, openContinuation } from "../continuation";
|
|
23
|
-
|
|
24
|
-
/** The name the return is sealed under — never `hub-continue` or `hub-purchase`. */
|
|
25
|
-
export const SECURITY_RETURN_NAME = "hub-security-return";
|
|
26
|
-
|
|
27
|
-
/** Better Auth's `resetPasswordTokenExpiresIn` on this hub (`auth.ts`): the link's life. */
|
|
28
|
-
export const RESET_TOKEN_TTL_SECONDS = 3600;
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* The ref outlives the link by the time a person may spend on the page, so a
|
|
32
|
-
* link used in its last minutes still returns home.
|
|
33
|
-
*/
|
|
34
|
-
export const SECURITY_RETURN_TTL_SECONDS = RESET_TOKEN_TTL_SECONDS + 600;
|
|
35
|
-
|
|
36
|
-
/** `origin` and `path` as a sealed return ref. */
|
|
37
|
-
export function mintSecurityReturn(
|
|
38
|
-
origin: string,
|
|
39
|
-
path: string,
|
|
40
|
-
secret: string,
|
|
41
|
-
now: number = Date.now(),
|
|
42
|
-
): string {
|
|
43
|
-
return mintContinuation(
|
|
44
|
-
new URLSearchParams({ o: origin, p: path }).toString(),
|
|
45
|
-
secret,
|
|
46
|
-
now,
|
|
47
|
-
SECURITY_RETURN_NAME,
|
|
48
|
-
SECURITY_RETURN_TTL_SECONDS,
|
|
49
|
-
);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
/** The spoke route a completed reset lands on, before the tab. */
|
|
53
|
-
export const SPOKE_RETURN_PATH = "/api/hub-session/password/return";
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* The absolute spoke URL a ref returns to — its return route carrying the
|
|
57
|
-
* Security path as `next` — or `null` when the ref does not open, has
|
|
58
|
-
* expired, or holds anything but an https (or loopback http) origin and a
|
|
59
|
-
* Security path.
|
|
60
|
-
*/
|
|
61
|
-
export function openSecurityReturn(
|
|
62
|
-
ref: string,
|
|
63
|
-
secret: string,
|
|
64
|
-
now: number = Date.now(),
|
|
65
|
-
): string | null {
|
|
66
|
-
const query = openContinuation(ref, secret, now, SECURITY_RETURN_NAME);
|
|
67
|
-
if (query === null) return null;
|
|
68
|
-
const params = new URLSearchParams(query);
|
|
69
|
-
const origin = params.get("o");
|
|
70
|
-
const path = params.get("p");
|
|
71
|
-
if (origin === null || path === null || [...params.keys()].length !== 2) return null;
|
|
72
|
-
if (!spokeSecurityReturnPathSchema.safeParse(path).success) return null;
|
|
73
|
-
let url: URL;
|
|
74
|
-
try {
|
|
75
|
-
url = new URL(origin);
|
|
76
|
-
} catch {
|
|
77
|
-
return null;
|
|
78
|
-
}
|
|
79
|
-
const loopback = url.hostname === "localhost" || url.hostname === "127.0.0.1";
|
|
80
|
-
if (url.origin !== origin || !(url.protocol === "https:" || (url.protocol === "http:" && loopback))) {
|
|
81
|
-
return null;
|
|
82
|
-
}
|
|
83
|
-
const landing = new URL(SPOKE_RETURN_PATH, origin);
|
|
84
|
-
landing.searchParams.set("next", path);
|
|
85
|
-
return landing.href;
|
|
86
|
-
}
|
|
@@ -1,171 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* `POST /api/auth/hub/password` — the hub web's half of a spoke-hosted Set /
|
|
3
|
-
* Change password (#11162).
|
|
4
|
-
*
|
|
5
|
-
* A spoke's server (never a browser) asks the hub to mail the person its
|
|
6
|
-
* Security tab signed in a link to set or change their one password. The
|
|
7
|
-
* person is named by their hub credential, never by an address in the body.
|
|
8
|
-
* In order:
|
|
9
|
-
*
|
|
10
|
-
* 1. `BETTER_AUTH_URL` pins the origin, else 503. Body ≤ 4 KB of JSON.
|
|
11
|
-
* 2. `hubPasswordEntryBodySchema` (`.strict()`): the client and its
|
|
12
|
-
* callback, the credential, the locale and the Security path to return
|
|
13
|
-
* to. Anything else — an `email` or a `password` among it — is 400.
|
|
14
|
-
* 3. A hub that cannot complete a reset (`resetSendConfigured()`) is 503
|
|
15
|
-
* here, before the API call — which charges the spoke's and the
|
|
16
|
-
* person's send budgets — and before anything is minted.
|
|
17
|
-
* 4. A caller refused ten times in ten minutes is 429 before any API call
|
|
18
|
-
* (`refusedCallerLimit`); a missing or non-`Basic` header is a refusal.
|
|
19
|
-
* The hub API's `POST /v1/hub-sign-in/password` authenticates the spoke
|
|
20
|
-
* with the `Authorization` and `x-ailk-spoke-key` it sent, as received,
|
|
21
|
-
* checks the callback is registered for it and the credential is a live
|
|
22
|
-
* grant of THIS client, and answers the person, their password state and
|
|
23
|
-
* the client's registered origin. A non-200 is passed on as its status
|
|
24
|
-
* with `{ error }`, and nothing is sent.
|
|
25
|
-
* 5. Better Auth's own `reset-password:<token>` row is written for the
|
|
26
|
-
* person (one hour, `resetPasswordTokenExpiresIn`), so the link is the
|
|
27
|
-
* one the hub's `/forgot-password` would mail and the hub's
|
|
28
|
-
* `/reset-password` page consumes it as any other. The credential's
|
|
29
|
-
* live session IS the person asking, so the anonymous-request guard
|
|
30
|
-
* `sendResetPassword` applies (#8431 D4) does not: a person with no
|
|
31
|
-
* password may set their first one from a spoke, as from the hub's tab.
|
|
32
|
-
* 6. The link's `callbackURL` is the hub's `/reset-password` under the
|
|
33
|
-
* body's locale carrying `?ref=`: the REGISTERED origin and the return
|
|
34
|
-
* path sealed (`./return.ts`), so a completed reset returns the person to
|
|
35
|
-
* the spoke's Security tab — never to a URL the spoke typed.
|
|
36
|
-
* 7. The `password-reset` email goes through the signed auth-email relay,
|
|
37
|
-
* as every reset mail does. A send that fails drops the row and is 503.
|
|
38
|
-
* 8. 202 `{ sent: true }`.
|
|
39
|
-
*
|
|
40
|
-
* Nothing here logs an email, a credential, a token or a ref — only the
|
|
41
|
-
* outcome. Under `app/api/auth`, a spoke removal seed, so no spoke carries it.
|
|
42
|
-
*/
|
|
43
|
-
import { randomBytes } from "node:crypto";
|
|
44
|
-
|
|
45
|
-
import { authEmail, hubSignIn } from "@working-theory/api-client";
|
|
46
|
-
import { hubPasswordEntryBodySchema } from "@working-theory/validation";
|
|
47
|
-
|
|
48
|
-
import { auth } from "../../../../../auth";
|
|
49
|
-
import { buildAuthEmailRequest } from "../../../../../lib/auth-email";
|
|
50
|
-
import { resetSendConfigured } from "../../../../../lib/auth-env";
|
|
51
|
-
import { resolveSecret } from "../../../../../lib/auth-secret";
|
|
52
|
-
import { localeOfPath } from "../../../../../lib/hub-session/entry";
|
|
53
|
-
import { pinnedOrigin } from "../continuation";
|
|
54
|
-
import {
|
|
55
|
-
apiErrorCode,
|
|
56
|
-
forwardedClientAuth,
|
|
57
|
-
json,
|
|
58
|
-
noteRefusedCaller,
|
|
59
|
-
parseJson,
|
|
60
|
-
readRawBody,
|
|
61
|
-
refusedCallerLimit,
|
|
62
|
-
refuse,
|
|
63
|
-
} from "../entry-shared";
|
|
64
|
-
|
|
65
|
-
import { RESET_TOKEN_TTL_SECONDS, mintSecurityReturn } from "./return";
|
|
66
|
-
|
|
67
|
-
const DEFAULT_LOCALE = "en";
|
|
68
|
-
|
|
69
|
-
function log(outcome: string): void {
|
|
70
|
-
console.info(`[hub-password-link] ${JSON.stringify({ outcome })}`);
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
// platform-decisions-waiver: api-versioning — a hub sign-in step, not a versioned API contract (spec 11096 § 6)
|
|
74
|
-
export async function POST(request: Request): Promise<Response> {
|
|
75
|
-
const origin = pinnedOrigin();
|
|
76
|
-
if (origin === null) return refuse(503, "temporarily_unavailable");
|
|
77
|
-
|
|
78
|
-
const raw = await readRawBody(request);
|
|
79
|
-
if (raw === null) return refuse(400, "invalid_request");
|
|
80
|
-
const parsed = hubPasswordEntryBodySchema.safeParse(parseJson(raw));
|
|
81
|
-
if (!parsed.success) return refuse(400, "invalid_request");
|
|
82
|
-
const body = parsed.data;
|
|
83
|
-
|
|
84
|
-
// Before the API call, which charges the spoke's and the person's budgets.
|
|
85
|
-
// The relay secret the signing below needs is one of its conjuncts.
|
|
86
|
-
if (!resetSendConfigured()) {
|
|
87
|
-
log("reset_not_configured");
|
|
88
|
-
return refuse(503, "temporarily_unavailable");
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
const limited = refusedCallerLimit(request);
|
|
92
|
-
if (limited !== null) return limited;
|
|
93
|
-
const client = forwardedClientAuth(request);
|
|
94
|
-
if (client === null) {
|
|
95
|
-
noteRefusedCaller(request);
|
|
96
|
-
return refuse(401, "invalid_client");
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
let checked: Awaited<ReturnType<typeof hubSignIn.password>>;
|
|
100
|
-
try {
|
|
101
|
-
checked = await hubSignIn.password(client, {
|
|
102
|
-
clientId: body.client_id,
|
|
103
|
-
redirectUri: body.redirect_uri,
|
|
104
|
-
accessToken: body.access_token,
|
|
105
|
-
});
|
|
106
|
-
} catch {
|
|
107
|
-
return refuse(503, "temporarily_unavailable");
|
|
108
|
-
}
|
|
109
|
-
if (!checked.ok) {
|
|
110
|
-
if (checked.status === 401 || checked.status === 403) noteRefusedCaller(request);
|
|
111
|
-
return refuse(checked.status, apiErrorCode(checked.body, "invalid_request"));
|
|
112
|
-
}
|
|
113
|
-
const { user, origin: spokeOrigin } = checked.body;
|
|
114
|
-
|
|
115
|
-
const token = randomBytes(24).toString("base64url");
|
|
116
|
-
const identifier = `reset-password:${token}`;
|
|
117
|
-
// Better Auth's own base URL — the pinned origin plus its `/api/auth` path,
|
|
118
|
-
// as the library resolves it; `BETTER_AUTH_URL` alone is the bare origin.
|
|
119
|
-
let baseURL: string;
|
|
120
|
-
try {
|
|
121
|
-
const context = await auth.$context;
|
|
122
|
-
baseURL = context.baseURL;
|
|
123
|
-
await context.internalAdapter.createVerificationValue({
|
|
124
|
-
identifier,
|
|
125
|
-
value: user.id,
|
|
126
|
-
expiresAt: new Date(Date.now() + RESET_TOKEN_TTL_SECONDS * 1000),
|
|
127
|
-
});
|
|
128
|
-
} catch {
|
|
129
|
-
log("mint_failed");
|
|
130
|
-
return refuse(503, "temporarily_unavailable");
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
const locale = localeOfPath(`/${body.locale}`);
|
|
134
|
-
const page = new URL(`${locale === DEFAULT_LOCALE ? "" : `/${locale}`}/reset-password`, origin);
|
|
135
|
-
page.searchParams.set("ref", mintSecurityReturn(spokeOrigin, body.return_path, resolveSecret()));
|
|
136
|
-
// Better Auth's own link shape: its `/reset-password/:token` consumes the
|
|
137
|
-
// token's hour and redirects to `callbackURL` with `?token=`.
|
|
138
|
-
const url = `${baseURL}/reset-password/${token}?callbackURL=${encodeURIComponent(page.href)}`;
|
|
139
|
-
|
|
140
|
-
const mail = buildAuthEmailRequest(
|
|
141
|
-
{
|
|
142
|
-
kind: "password-reset",
|
|
143
|
-
userId: user.id,
|
|
144
|
-
to: user.email,
|
|
145
|
-
url,
|
|
146
|
-
expiresInMinutes: RESET_TOKEN_TTL_SECONDS / 60,
|
|
147
|
-
},
|
|
148
|
-
process.env.AUTH_EMAIL_WEBHOOK_SECRET ?? "",
|
|
149
|
-
);
|
|
150
|
-
let sent: boolean;
|
|
151
|
-
try {
|
|
152
|
-
const result = (await authEmail.send(mail.rawBody, mail.headers)) as { ok: boolean } | undefined;
|
|
153
|
-
sent = result?.ok !== false;
|
|
154
|
-
} catch {
|
|
155
|
-
sent = false;
|
|
156
|
-
}
|
|
157
|
-
if (!sent) {
|
|
158
|
-
// Not sent: drop the row, so the unused token never waits out its hour.
|
|
159
|
-
try {
|
|
160
|
-
const { internalAdapter } = await auth.$context;
|
|
161
|
-
await internalAdapter.deleteVerificationByIdentifier(identifier);
|
|
162
|
-
} catch {
|
|
163
|
-
// The row expires on its own; the person asks again.
|
|
164
|
-
}
|
|
165
|
-
log("send_failed");
|
|
166
|
-
return refuse(503, "temporarily_unavailable");
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
log("sent");
|
|
170
|
-
return json(202, { sent: true });
|
|
171
|
-
}
|