create-ailk 0.38.0 → 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.
Files changed (135) hide show
  1. package/dist/add-route.js +1 -1
  2. package/dist/derive-architecture.js +3 -1
  3. package/dist/remove-module.js +18 -14
  4. package/dist/routes.d.ts +29 -2
  5. package/dist/routes.js +269 -23
  6. package/dist/site-manifest.js +6 -4
  7. package/dist/site-roster.d.ts +11 -3
  8. package/dist/site-roster.js +42 -22
  9. package/dist/surfaces.d.ts +11 -3
  10. package/dist/surfaces.js +69 -22
  11. package/dist/sync-routes.js +22 -5
  12. package/dist/template-record.js +3 -1
  13. package/dist/topology.d.ts +11 -0
  14. package/dist/topology.js +253 -3
  15. package/package.json +3 -3
  16. package/templates/apps/web/CLAUDE.md +26 -4
  17. package/templates/apps/web/__tests__/__mocks__/next-intl-server.ts +5 -1
  18. package/templates/apps/web/__tests__/__mocks__/next-intl.ts +5 -1
  19. package/templates/apps/web/__tests__/auth/seam.test.ts +34 -0
  20. package/templates/apps/web/account.config.tsx +2 -3
  21. package/templates/apps/web/app/[locale]/(authed)/account/connect/__tests__/page.test.tsx +1 -1
  22. package/templates/apps/web/app/[locale]/(authed)/account/connect/page.tsx +1 -1
  23. package/templates/apps/web/app/[locale]/(authed)/signed-out-gate.generated.tsx +1 -1
  24. package/templates/apps/web/app/[locale]/layout.tsx +1 -1
  25. package/templates/apps/web/auth.config.tsx +107 -0
  26. package/templates/apps/web/auth.ts +2 -1
  27. package/templates/apps/web/i18n/request.ts +9 -2
  28. package/templates/apps/web/jest.config.cjs +4 -0
  29. package/templates/apps/web/lib/__tests__/fixtures/site-topology.ts +3 -0
  30. package/templates/apps/web/lib/__tests__/server-api.test.ts +1 -1
  31. package/templates/apps/web/lib/server-api.ts +1 -1
  32. package/templates/apps/web/lib/topology.generated.ts +5 -0
  33. package/templates/apps/web/messages/en.json +0 -152
  34. package/templates/apps/web/middleware.ts +12 -25
  35. package/templates/apps/web/next.config.mjs +8 -0
  36. package/templates/apps/web/package.json +1 -0
  37. package/templates/apps/web/types/messages.d.ts +6 -1
  38. package/versions.json +49 -48
  39. package/templates/apps/web/app/[locale]/(auth)/__tests__/auth-pages.test.tsx +0 -322
  40. package/templates/apps/web/app/[locale]/(auth)/__tests__/password-reset.test.tsx +0 -554
  41. package/templates/apps/web/app/[locale]/(auth)/consent/__tests__/consent-actions.test.ts +0 -56
  42. package/templates/apps/web/app/[locale]/(auth)/consent/__tests__/page.test.tsx +0 -164
  43. package/templates/apps/web/app/[locale]/(auth)/consent/consent-form.tsx +0 -132
  44. package/templates/apps/web/app/[locale]/(auth)/consent/consent.actions.ts +0 -51
  45. package/templates/apps/web/app/[locale]/(auth)/consent/page.tsx +0 -144
  46. package/templates/apps/web/app/[locale]/(auth)/forgot-password/forgot-password-card.tsx +0 -101
  47. package/templates/apps/web/app/[locale]/(auth)/forgot-password/page.tsx +0 -111
  48. package/templates/apps/web/app/[locale]/(auth)/layout.tsx +0 -81
  49. package/templates/apps/web/app/[locale]/(auth)/legal-footnote.tsx +0 -35
  50. package/templates/apps/web/app/[locale]/(auth)/reset-password/__tests__/return.test.tsx +0 -179
  51. package/templates/apps/web/app/[locale]/(auth)/reset-password/page.tsx +0 -157
  52. package/templates/apps/web/app/[locale]/(auth)/reset-password/reset-password-card.tsx +0 -126
  53. package/templates/apps/web/app/[locale]/(auth)/sign-in/__tests__/next-path.test.ts +0 -54
  54. package/templates/apps/web/app/[locale]/(auth)/sign-in/__tests__/page.test.tsx +0 -628
  55. package/templates/apps/web/app/[locale]/(auth)/sign-in/__tests__/remembered-method.test.ts +0 -43
  56. package/templates/apps/web/app/[locale]/(auth)/sign-in/__tests__/sign-in-card.test.tsx +0 -266
  57. package/templates/apps/web/app/[locale]/(auth)/sign-in/next-path.ts +0 -20
  58. package/templates/apps/web/app/[locale]/(auth)/sign-in/page.tsx +0 -234
  59. package/templates/apps/web/app/[locale]/(auth)/sign-in/remembered-method.ts +0 -37
  60. package/templates/apps/web/app/[locale]/(auth)/sign-in/sign-in-card.tsx +0 -323
  61. package/templates/apps/web/app/[locale]/(auth)/sign-in/sign-in-text.ts +0 -93
  62. package/templates/apps/web/app/[locale]/(auth)/sign-up/__tests__/page.test.tsx +0 -301
  63. package/templates/apps/web/app/[locale]/(auth)/sign-up/__tests__/sign-up-card.test.tsx +0 -309
  64. package/templates/apps/web/app/[locale]/(auth)/sign-up/page.tsx +0 -201
  65. package/templates/apps/web/app/[locale]/(auth)/sign-up/sign-up-card.tsx +0 -366
  66. package/templates/apps/web/app/[locale]/(auth)/use-auth-card-flow.ts +0 -116
  67. package/templates/apps/web/app/[locale]/(auth)/verify-email/__tests__/actions.test.ts +0 -94
  68. package/templates/apps/web/app/[locale]/(auth)/verify-email/actions.ts +0 -77
  69. package/templates/apps/web/app/[locale]/(auth)/verify-email/page.tsx +0 -154
  70. package/templates/apps/web/app/[locale]/(authed)/account/appointments/[slug]/page.tsx +0 -3
  71. package/templates/apps/web/app/[locale]/(authed)/account/appointments/page.tsx +0 -3
  72. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/[pieceId]/page.tsx +0 -3
  73. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/[pieceId]/versions/[version]/file/route.ts +0 -2
  74. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/page.tsx +0 -3
  75. package/templates/apps/web/app/[locale]/(authed)/account/billing/page.tsx +0 -12
  76. package/templates/apps/web/app/[locale]/(authed)/account/general/page.tsx +0 -12
  77. package/templates/apps/web/app/[locale]/(authed)/account/inbox/[kind]/[id]/page.tsx +0 -12
  78. package/templates/apps/web/app/[locale]/(authed)/account/inbox/message/[id]/file/route.ts +0 -2
  79. package/templates/apps/web/app/[locale]/(authed)/account/inbox/thread/page.tsx +0 -12
  80. package/templates/apps/web/app/[locale]/(authed)/account/invitations/[invitationId]/page.tsx +0 -3
  81. package/templates/apps/web/app/[locale]/(authed)/account/layout.tsx +0 -10
  82. package/templates/apps/web/app/[locale]/(authed)/account/notifications/page.tsx +0 -3
  83. package/templates/apps/web/app/[locale]/(authed)/account/onboarding/page.tsx +0 -3
  84. package/templates/apps/web/app/[locale]/(authed)/account/page.tsx +0 -12
  85. package/templates/apps/web/app/[locale]/(authed)/account/privacy/export/route.ts +0 -2
  86. package/templates/apps/web/app/[locale]/(authed)/account/privacy/page.tsx +0 -3
  87. package/templates/apps/web/app/[locale]/(authed)/account/security/page.tsx +0 -3
  88. package/templates/apps/web/app/[locale]/(authed)/account/settings/page.tsx +0 -2
  89. package/templates/apps/web/app/[locale]/(authed)/account/support/page.tsx +0 -3
  90. package/templates/apps/web/app/api/auth/[...all]/route.ts +0 -16
  91. package/templates/apps/web/app/api/auth/hub/__tests__/continuation.test.ts +0 -143
  92. package/templates/apps/web/app/api/auth/hub/__tests__/entry-routes.test.ts +0 -749
  93. package/templates/apps/web/app/api/auth/hub/authorize/__tests__/route.test.ts +0 -964
  94. package/templates/apps/web/app/api/auth/hub/authorize/route.ts +0 -390
  95. package/templates/apps/web/app/api/auth/hub/continuation.ts +0 -127
  96. package/templates/apps/web/app/api/auth/hub/continue/[ref]/__tests__/route.test.ts +0 -188
  97. package/templates/apps/web/app/api/auth/hub/continue/[ref]/route.ts +0 -53
  98. package/templates/apps/web/app/api/auth/hub/email/route.ts +0 -111
  99. package/templates/apps/web/app/api/auth/hub/entry-shared.ts +0 -163
  100. package/templates/apps/web/app/api/auth/hub/password/__tests__/return.test.ts +0 -86
  101. package/templates/apps/web/app/api/auth/hub/password/__tests__/route.test.ts +0 -368
  102. package/templates/apps/web/app/api/auth/hub/password/return.ts +0 -86
  103. package/templates/apps/web/app/api/auth/hub/password/route.ts +0 -171
  104. package/templates/apps/web/app/api/auth/hub/purchase/route.ts +0 -230
  105. package/templates/apps/web/app/api/auth/hub/purchase-link/route.ts +0 -174
  106. package/templates/apps/web/app/api/auth/hub/sign-up/route.ts +0 -60
  107. package/templates/apps/web/app/api/auth/hub/sign-up-evidence.ts +0 -97
  108. package/templates/apps/web/app/api/auth/mcp/__tests__/continuation.test.ts +0 -92
  109. package/templates/apps/web/app/api/auth/mcp/continuation.ts +0 -89
  110. package/templates/apps/web/app/api/auth/mcp/continue/[ref]/__tests__/route.test.ts +0 -59
  111. package/templates/apps/web/app/api/auth/mcp/continue/[ref]/route.ts +0 -41
  112. package/templates/apps/web/app/api/hub-session/__tests__/routes.test.ts +0 -1166
  113. package/templates/apps/web/app/api/hub-session/callback/route.ts +0 -134
  114. package/templates/apps/web/app/api/hub-session/email/route.ts +0 -125
  115. package/templates/apps/web/app/api/hub-session/one-tap/nonce/route.ts +0 -49
  116. package/templates/apps/web/app/api/hub-session/one-tap/route.ts +0 -106
  117. package/templates/apps/web/app/api/hub-session/open/route.ts +0 -111
  118. package/templates/apps/web/app/api/hub-session/password/return/route.ts +0 -69
  119. package/templates/apps/web/app/api/hub-session/password/route.ts +0 -106
  120. package/templates/apps/web/app/api/hub-session/sign-in/route.ts +0 -91
  121. package/templates/apps/web/app/api/hub-session/sign-out/route.ts +0 -54
  122. package/templates/apps/web/components/sign-out-trigger.tsx +0 -62
  123. package/templates/apps/web/lib/__tests__/auth-routes.test.ts +0 -140
  124. package/templates/apps/web/lib/auth-routes.ts +0 -125
  125. package/templates/apps/web/lib/hub-session/__tests__/hub-session.test.ts +0 -433
  126. package/templates/apps/web/lib/hub-session/__tests__/spoke-sign-in.test.tsx +0 -332
  127. package/templates/apps/web/lib/hub-session/config.ts +0 -110
  128. package/templates/apps/web/lib/hub-session/entry.ts +0 -238
  129. package/templates/apps/web/lib/hub-session/index.ts +0 -21
  130. package/templates/apps/web/lib/hub-session/one-tap.tsx +0 -148
  131. package/templates/apps/web/lib/hub-session/reseal.ts +0 -90
  132. package/templates/apps/web/lib/hub-session/seal.ts +0 -86
  133. package/templates/apps/web/lib/hub-session/session.ts +0 -298
  134. package/templates/apps/web/lib/hub-session/spoke-sign-in.tsx +0 -277
  135. package/templates/apps/web/lib/next-path.ts +0 -35
package/dist/topology.js CHANGED
@@ -484,6 +484,23 @@ export async function loadSpokeBilling(): Promise<SpokeBilling | null> {
484
484
  return { read: readSpokeBilling, portalUrl: spokeBillingPortalUrl };
485
485
  }`;
486
486
  }
487
+ /**
488
+ * `loadAuth` (#11257 D5): the one way `@working-theory/auth` reaches the
489
+ * site's Better Auth instance, through `auth.config.tsx`. The hub render
490
+ * loads `auth.ts` only when it is called, and the assignment to
491
+ * `AuthInstance` is where `typeof auth` is checked against what the package
492
+ * calls; a spoke has no `auth.ts`, so its renders resolve `null`.
493
+ */
494
+ function authLoader(topology) {
495
+ if (topology === "hub") {
496
+ return `export function loadAuth(): Promise<AuthInstance | null> {
497
+ return import("../auth").then((m) => m.auth);
498
+ }`;
499
+ }
500
+ return `export function loadAuth(): Promise<AuthInstance | null> {
501
+ return Promise.resolve(null);
502
+ }`;
503
+ }
487
504
  /**
488
505
  * `apps/web/lib/topology.generated.ts` for `topology` (D5) and, on a spoke,
489
506
  * its sign-in mode (#7894 D8). The hub render loads `auth.ts` only when a
@@ -500,6 +517,7 @@ export function renderWebSeam(topology, signIn = "off", opts = {}) {
500
517
  }
501
518
  if (topology === "hub") {
502
519
  return `${WEB_SEAM_HEADER}
520
+ import type { AuthInstance } from "${AUTH_PACKAGE}/site";
503
521
 
504
522
  export const TOPOLOGY: "hub" | "spoke" = "hub";
505
523
  ${unservedToolsExport("hub")}
@@ -512,6 +530,8 @@ export async function readSession(headers: Headers): Promise<SiteSession> {
512
530
  return auth.api.getSession({ headers });
513
531
  }
514
532
 
533
+ ${authLoader("hub")}
534
+
515
535
  ${ownAccountsReader("hub")}
516
536
 
517
537
  ${phoneStep("hub")}
@@ -526,7 +546,8 @@ ${spokeBillingLoader(false)}
526
546
  }
527
547
  if (signIn === "hub") {
528
548
  return `${WEB_SEAM_HEADER}
529
- import { readHubSession } from "./hub-session/session";
549
+ import type { AuthInstance } from "${AUTH_PACKAGE}/site";
550
+ import { readHubSession } from "${AUTH_PACKAGE}/hub-session";
530
551
 
531
552
  export const TOPOLOGY: "hub" | "spoke" = "spoke";
532
553
  ${unservedToolsExport("spoke")}
@@ -538,6 +559,8 @@ export function readSession(headers: Headers): Promise<SiteSession> {
538
559
  return readHubSession(headers);
539
560
  }
540
561
 
562
+ ${authLoader("spoke")}
563
+
541
564
  ${ownAccountsReader("spoke")}
542
565
 
543
566
  ${phoneStep("spoke")}
@@ -550,6 +573,7 @@ ${spokeBillingLoader(spokeBilling)}
550
573
  `;
551
574
  }
552
575
  return `${WEB_SEAM_HEADER}
576
+ import type { AuthInstance } from "${AUTH_PACKAGE}/site";
553
577
 
554
578
  export const TOPOLOGY: "hub" | "spoke" = "spoke";
555
579
  ${unservedToolsExport("spoke")}
@@ -562,6 +586,8 @@ export function readSession(headers: Headers): Promise<SiteSession> {
562
586
  return Promise.resolve(null);
563
587
  }
564
588
 
589
+ ${authLoader("spoke")}
590
+
565
591
  ${ownAccountsReader("spoke")}
566
592
 
567
593
  ${phoneStep("spoke")}
@@ -585,6 +611,8 @@ const AUTHED_GATE_SEAM_HEADER = `// signed-out-gate.generated.tsx — what the (
585
611
  * the reason `CONTENT_ADAPTERS_PACKAGE` below is.
586
612
  */
587
613
  const UI_PACKAGE = "@working-theory/ui";
614
+ /** The sign-in page package the seams read (#11257 D5, D9). */
615
+ const AUTH_PACKAGE = "@working-theory/auth";
588
616
  const WEB_I18N_PACKAGE = "@working-theory/web-i18n";
589
617
  const NEXT_INTL_SERVER = "next-intl/server";
590
618
  const NEXT_NAVIGATION = "next/navigation";
@@ -604,6 +632,7 @@ const AUTHED_GATE_PROPS = `export interface SignedOutGateProps {
604
632
  export function renderAuthedGateSeam(topology, signIn = "off") {
605
633
  if (topology === "hub") {
606
634
  return `${AUTHED_GATE_SEAM_HEADER}
635
+ import { isAccountPath } from "${AUTH_PACKAGE}/edge";
607
636
  import { localeHref } from "${UI_PACKAGE}";
608
637
  import { Button, Heading, Link, Text } from "${UI_PACKAGE}/primitives";
609
638
  import { readLocales } from "${WEB_I18N_PACKAGE}";
@@ -612,7 +641,6 @@ import { getTranslations } from "${NEXT_INTL_SERVER}";
612
641
  import type { ReactElement } from "${REACT_PACKAGE}";
613
642
 
614
643
  import { getActiveProviderIds } from "../../../lib/auth-env";
615
- import { isAccountPath } from "../../../lib/auth-routes";
616
644
 
617
645
  /** The methods a member signs in with on /sign-in's card. */
618
646
  const MEMBER_METHODS: readonly string[] = ["google", "github", "magic-link"];
@@ -678,7 +706,7 @@ export async function SignedOutGate({
678
706
  return `${AUTHED_GATE_SEAM_HEADER}
679
707
  import type { ReactElement } from "${REACT_PACKAGE}";
680
708
 
681
- import { SpokeSignIn } from "../../../lib/hub-session";
709
+ import { SpokeSignIn } from "${AUTH_PACKAGE}/hub-session";
682
710
 
683
711
  ${AUTHED_GATE_PROPS}
684
712
 
@@ -939,10 +967,231 @@ export function applySpokeTransforms(targetDir, opts) {
939
967
  writeFileSync(join(targetDir, AUTHED_GATE_SEAM_PATH), renderAuthedGateSeam("spoke", "hub"));
940
968
  }
941
969
  writeFileSync(join(targetDir, API_ORIGIN_SEAM_PATH), renderApiOriginSeam("spoke"));
970
+ // #11257 D4 — the sign-in package's seam, in its spoke shape (`hub: null`).
971
+ writeFileSync(join(targetDir, AUTH_CONFIG_PATH), renderAuthConfig("spoke"));
942
972
  if (opts.mcp) {
943
973
  writeFileSync(join(targetDir, MCP_SEAM_PATH), renderMcpSeam("spoke"));
944
974
  }
945
975
  }
976
+ /** The page-package config the sign-in package reads its services from (#11257 D4). */
977
+ export const AUTH_CONFIG_PATH = "apps/web/auth.config.tsx";
978
+ /**
979
+ * `apps/web/auth.config.tsx` for `topology` (#11257 D4): the hub render is
980
+ * this monorepo's file, byte for byte (`spoke-topology.test.ts` pins the
981
+ * two); the spoke render passes `hub: null` and imports none of the hub-only
982
+ * libs (`lib/auth-email.ts`, `lib/auth-secret.ts`, `lib/consent-policies.ts`).
983
+ * Neither imports `auth.ts`: Better Auth arrives through the topology seam's
984
+ * `loadAuth()`, so a spoke keeps the file and no closure removes it.
985
+ */
986
+ export function renderAuthConfig(topology) {
987
+ return (topology === "hub" ? AUTH_CONFIG_HUB : AUTH_CONFIG_SPOKE).join("\n");
988
+ }
989
+ const AUTH_CONFIG_HUB = [
990
+ "/**",
991
+ " * The site's sign-in configuration (#11257; ADR 0040 rule 4) — the one typed",
992
+ " * file through which this site customizes and serves `@working-theory/auth`.",
993
+ " *",
994
+ " * The default export is `defineAuthConfig({ … })`, which the generated",
995
+ " * `(auth)` layout file passes to the layout as `config`; it carries no",
996
+ " * extension point yet (rule 8), and a misspelled key fails `tsc`.",
997
+ " *",
998
+ " * The named export `site` is the runtime-services seam (`AuthSite`) the",
999
+ " * package's pages, actions and handlers read through",
1000
+ " * `@working-theory/auth/site` (aliased here by `next.config.mjs` and",
1001
+ " * `jest.config.cjs`). It never imports `./auth`: Better Auth arrives through",
1002
+ " * the generated topology seam's `loadAuth()` — a dynamic import on a hub,",
1003
+ " * `null` on a spoke — so a spoke keeps this file. A spoke's copy passes",
1004
+ " * `hub: null` and imports none of the hub-only libs.",
1005
+ " *",
1006
+ " * Every value the generated topology seam owns is read through on access,",
1007
+ " * never copied at load: a spoke's topology seam imports the package's",
1008
+ " * hub-session entry, which can load before this file finishes.",
1009
+ " */",
1010
+ "import { type AuthSite, defineAuthConfig } from \"@working-theory/auth\";",
1011
+ "",
1012
+ "import { browserApiOrigin } from \"./lib/api-origin.generated\";",
1013
+ "import {",
1014
+ " buildAuthEmailRequest,",
1015
+ " confirmSignUpEmail,",
1016
+ " makeSendAccountOpen,",
1017
+ " purchaseCapture,",
1018
+ "} from \"./lib/auth-email\";",
1019
+ "import {",
1020
+ " getActiveProviderIds,",
1021
+ " hasAnyProvider,",
1022
+ " isAuthRequired,",
1023
+ " isResetAvailable,",
1024
+ " isSignUpOpen,",
1025
+ " magicLinkSendConfigured,",
1026
+ " phoneVerificationConfigured,",
1027
+ " resetSendConfigured,",
1028
+ "} from \"./lib/auth-env\";",
1029
+ "import { resolveSecret } from \"./lib/auth-secret\";",
1030
+ "import { runBotCheck } from \"./lib/bot-check\";",
1031
+ "import { consentPoliciesFor } from \"./lib/consent-policies\";",
1032
+ "import { SITE_NAME } from \"./lib/site-brand\";",
1033
+ "import { siteLogo } from \"./lib/site-logo\";",
1034
+ "import {",
1035
+ " loadAuth,",
1036
+ " readSession,",
1037
+ " SIGN_IN_PROVIDER,",
1038
+ " SIGN_OUT_ENDPOINT,",
1039
+ " TOPOLOGY,",
1040
+ "} from \"./lib/topology.generated\";",
1041
+ "import {",
1042
+ " clientIpFromHeaders,",
1043
+ " takeVisitorLimit,",
1044
+ " UNKNOWN_VISITOR_FACTOR,",
1045
+ "} from \"./src/lib/rate-limit\";",
1046
+ "import { resolveBaseUrl } from \"./src/lib/routes\";",
1047
+ "",
1048
+ "export default defineAuthConfig({});",
1049
+ "",
1050
+ "export const site = {",
1051
+ " loadAuth: () => loadAuth(),",
1052
+ " env: {",
1053
+ " isAuthRequired: () => isAuthRequired(),",
1054
+ " isSignUpOpen: () => isSignUpOpen(),",
1055
+ " isResetAvailable: () => isResetAvailable(),",
1056
+ " getActiveProviderIds: () => getActiveProviderIds(),",
1057
+ " magicLinkSendConfigured: () => magicLinkSendConfigured(),",
1058
+ " hasAnyProvider: () => hasAnyProvider(),",
1059
+ " resetSendConfigured: () => resetSendConfigured(),",
1060
+ " phoneVerificationConfigured: () => phoneVerificationConfigured(),",
1061
+ " },",
1062
+ " siteLogo: () => siteLogo(),",
1063
+ " get siteName() {",
1064
+ " return SITE_NAME;",
1065
+ " },",
1066
+ " resolveBaseUrl: () => resolveBaseUrl(),",
1067
+ " browserApiOrigin: () => browserApiOrigin(),",
1068
+ " runBotCheck: (input) => runBotCheck(input),",
1069
+ " takeVisitorLimit: (scope, headers, limit, windowMs) =>",
1070
+ " takeVisitorLimit(scope, headers, limit, windowMs),",
1071
+ " clientIpFromHeaders: (headers) => clientIpFromHeaders(headers),",
1072
+ " get unknownVisitorFactor() {",
1073
+ " return UNKNOWN_VISITOR_FACTOR;",
1074
+ " },",
1075
+ " get topology() {",
1076
+ " return TOPOLOGY;",
1077
+ " },",
1078
+ " get signInProvider() {",
1079
+ " return SIGN_IN_PROVIDER;",
1080
+ " },",
1081
+ " get signOutEndpoint() {",
1082
+ " return SIGN_OUT_ENDPOINT;",
1083
+ " },",
1084
+ " readSession: (headers) => readSession(headers),",
1085
+ " hub: {",
1086
+ " resolveSecret: () => resolveSecret(),",
1087
+ " consentPoliciesFor: (locale) => consentPoliciesFor(locale),",
1088
+ " email: {",
1089
+ " confirmSignUpEmail: (nonce) => confirmSignUpEmail(nonce),",
1090
+ " makeSendAccountOpen: (deps) => makeSendAccountOpen(deps),",
1091
+ " buildAuthEmailRequest: (payload, secret) =>",
1092
+ " buildAuthEmailRequest(",
1093
+ " payload as Parameters<typeof buildAuthEmailRequest>[0],",
1094
+ " secret,",
1095
+ " ),",
1096
+ " purchaseCapture,",
1097
+ " },",
1098
+ " },",
1099
+ "} satisfies AuthSite;",
1100
+ "",
1101
+ ];
1102
+ const AUTH_CONFIG_SPOKE = [
1103
+ "/**",
1104
+ " * The site's sign-in configuration (#11257; ADR 0040 rule 4) — the one typed",
1105
+ " * file through which this site customizes and serves `@working-theory/auth`.",
1106
+ " *",
1107
+ " * The default export is `defineAuthConfig({ … })`, which the generated",
1108
+ " * `(auth)` layout file passes to the layout as `config`; it carries no",
1109
+ " * extension point yet (rule 8), and a misspelled key fails `tsc`.",
1110
+ " *",
1111
+ " * The named export `site` is the runtime-services seam (`AuthSite`) the",
1112
+ " * package's pages, actions and handlers read through",
1113
+ " * `@working-theory/auth/site` (aliased here by `next.config.mjs` and",
1114
+ " * `jest.config.cjs`). It never imports `./auth`: Better Auth arrives through",
1115
+ " * the generated topology seam's `loadAuth()` — a dynamic import on a hub,",
1116
+ " * `null` on a spoke — so a spoke keeps this file. A spoke's copy passes",
1117
+ " * `hub: null` and imports none of the hub-only libs.",
1118
+ " *",
1119
+ " * Every value the generated topology seam owns is read through on access,",
1120
+ " * never copied at load: a spoke's topology seam imports the package's",
1121
+ " * hub-session entry, which can load before this file finishes.",
1122
+ " */",
1123
+ "import { type AuthSite, defineAuthConfig } from \"@working-theory/auth\";",
1124
+ "",
1125
+ "import { browserApiOrigin } from \"./lib/api-origin.generated\";",
1126
+ "import {",
1127
+ " getActiveProviderIds,",
1128
+ " hasAnyProvider,",
1129
+ " isAuthRequired,",
1130
+ " isResetAvailable,",
1131
+ " isSignUpOpen,",
1132
+ " magicLinkSendConfigured,",
1133
+ " phoneVerificationConfigured,",
1134
+ " resetSendConfigured,",
1135
+ "} from \"./lib/auth-env\";",
1136
+ "import { runBotCheck } from \"./lib/bot-check\";",
1137
+ "import { SITE_NAME } from \"./lib/site-brand\";",
1138
+ "import { siteLogo } from \"./lib/site-logo\";",
1139
+ "import {",
1140
+ " loadAuth,",
1141
+ " readSession,",
1142
+ " SIGN_IN_PROVIDER,",
1143
+ " SIGN_OUT_ENDPOINT,",
1144
+ " TOPOLOGY,",
1145
+ "} from \"./lib/topology.generated\";",
1146
+ "import {",
1147
+ " clientIpFromHeaders,",
1148
+ " takeVisitorLimit,",
1149
+ " UNKNOWN_VISITOR_FACTOR,",
1150
+ "} from \"./src/lib/rate-limit\";",
1151
+ "import { resolveBaseUrl } from \"./src/lib/routes\";",
1152
+ "",
1153
+ "export default defineAuthConfig({});",
1154
+ "",
1155
+ "export const site = {",
1156
+ " loadAuth: () => loadAuth(),",
1157
+ " env: {",
1158
+ " isAuthRequired: () => isAuthRequired(),",
1159
+ " isSignUpOpen: () => isSignUpOpen(),",
1160
+ " isResetAvailable: () => isResetAvailable(),",
1161
+ " getActiveProviderIds: () => getActiveProviderIds(),",
1162
+ " magicLinkSendConfigured: () => magicLinkSendConfigured(),",
1163
+ " hasAnyProvider: () => hasAnyProvider(),",
1164
+ " resetSendConfigured: () => resetSendConfigured(),",
1165
+ " phoneVerificationConfigured: () => phoneVerificationConfigured(),",
1166
+ " },",
1167
+ " siteLogo: () => siteLogo(),",
1168
+ " get siteName() {",
1169
+ " return SITE_NAME;",
1170
+ " },",
1171
+ " resolveBaseUrl: () => resolveBaseUrl(),",
1172
+ " browserApiOrigin: () => browserApiOrigin(),",
1173
+ " runBotCheck: (input) => runBotCheck(input),",
1174
+ " takeVisitorLimit: (scope, headers, limit, windowMs) =>",
1175
+ " takeVisitorLimit(scope, headers, limit, windowMs),",
1176
+ " clientIpFromHeaders: (headers) => clientIpFromHeaders(headers),",
1177
+ " get unknownVisitorFactor() {",
1178
+ " return UNKNOWN_VISITOR_FACTOR;",
1179
+ " },",
1180
+ " get topology() {",
1181
+ " return TOPOLOGY;",
1182
+ " },",
1183
+ " get signInProvider() {",
1184
+ " return SIGN_IN_PROVIDER;",
1185
+ " },",
1186
+ " get signOutEndpoint() {",
1187
+ " return SIGN_OUT_ENDPOINT;",
1188
+ " },",
1189
+ " readSession: (headers) => readSession(headers),",
1190
+ " // A spoke mounts none of the hub's routes or (auth) pages (#11257 D4).",
1191
+ " hub: null,",
1192
+ "} satisfies AuthSite;",
1193
+ "",
1194
+ ];
946
1195
  /** The env var a spoke reaches its hub through. */
947
1196
  export const HUB_ORIGIN_ENV_VAR = "AILK_API_URL";
948
1197
  /** Env files `next start` loads for an app, highest precedence first. */
@@ -1052,6 +1301,7 @@ export function renderSpokeHardFloors(opts) {
1052
1301
  ' - "apps/web/app/[locale]/(authed)/**"',
1053
1302
  ' - "apps/web/lib/hub-session/**"',
1054
1303
  ' - "apps/web/app/api/hub-session/**"',
1304
+ ' - "apps/web/auth.config.tsx"',
1055
1305
  opts.signIn === "hub"
1056
1306
  ? " reason: sign-in paths — this spoke signs in through its hub; every change requires human review"
1057
1307
  : " reason: sign-in paths — absent on a spoke; their return requires human review",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-ailk",
3
- "version": "0.38.0",
3
+ "version": "0.39.0",
4
4
  "description": "Scaffolder for AI Launch Kit — `pnpm create ailk@latest <dir>` produces a starter repo consuming @working-theory/* from npm (per ADR 0007).",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -28,8 +28,8 @@
28
28
  "tar": "^7.5.21"
29
29
  },
30
30
  "devDependencies": {
31
- "@working-theory/schema": "0.62.0",
32
- "@working-theory/templates": "0.62.0"
31
+ "@working-theory/schema": "0.63.0",
32
+ "@working-theory/templates": "0.63.0"
33
33
  },
34
34
  "repository": {
35
35
  "type": "git",
@@ -68,6 +68,26 @@ Don't ship a page after one render. The expected per-page loop:
68
68
 
69
69
  ## The `(auth)` route group — which predicate an affordance keys on
70
70
 
71
+ **Where it lives (#11257, ADR 0040 phase 2).** The `(auth)` pages and their
72
+ actions, the spoke's hub-session client, the hub's `/api/auth` routes and the
73
+ spoke's `/api/hub-session` routes ship in `@working-theory/auth`
74
+ (`packages/auth/src/{pages,hub-session,api}/`), with their tests. This app's
75
+ `app/[locale]/(auth)/`, `app/api/auth/` and `app/api/hub-session/` hold only
76
+ the 25 route files `create-ailk routes --write` generates from the package's
77
+ `routes.json` — never hand-edited, pinned by `routes --check`. The package
78
+ reads the site through one typed file, `auth.config.tsx`: `defineAuthConfig({})`
79
+ (no extension point yet) and its `site` export, which answers the
80
+ `@working-theory/auth/site` seam (`next.config.mjs` and `jest.config.cjs`
81
+ alias it to that file). Better Auth reaches the package only through the
82
+ topology seam's `loadAuth()` — `auth.config.tsx` never imports `auth.ts` —
83
+ and an `/api/auth` route whose load is `null` answers 404 with no body.
84
+ `middleware.ts` keeps its header maps and calls `@working-theory/auth/edge`
85
+ for the auth half and the path predicates; that entry imports nothing. The
86
+ `auth`, `signIn`, `mcpConsent` and `spokeSignIn` strings ship in the package
87
+ (`authMessages`, merged by `i18n/request.ts`); a key in `messages/en.json` is
88
+ an override. The paths below name the package's files by their old
89
+ `lib/`/`app/` place; `lib/auth-env.ts` itself stays the site's.
90
+
71
91
  `lib/auth-env.ts` exports two reset predicates, and they are not
72
92
  interchangeable. Picking the wrong one is how this surface has broken twice
73
93
  (#6018, then #6061 — the follow-up #6068 documents the rule here so there is
@@ -171,7 +191,7 @@ both telemetry scrub lists.
171
191
 
172
192
  **A spoke's sign-in entry is the spoke's own form (#11096).** On a spoke
173
193
  that signs in through its hub, the gate seam renders
174
- `lib/hub-session/spoke-sign-in.tsx` (`SpokeSignIn`) for every signed-out
194
+ `@working-theory/auth/hub-session`'s `SpokeSignIn` for every signed-out
175
195
  `(authed)` path: one email field, the hub's sign-up agreements under "New
176
196
  here?" (read from the hub web's `GET /api/auth/hub/sign-up`, shared 60 s, each
177
197
  policy link the hub's) and Continue with Google — a native form, no password
@@ -219,7 +239,7 @@ server to server as the spoke's client: the hub API's
219
239
  a live grant of THIS client, and the hub web mints Better Auth's own
220
240
  `reset-password:<token>` row and mails the link through the signed relay, its
221
241
  `callbackURL` the hub's `/reset-password` carrying a sealed `?ref=` of the
222
- client's REGISTERED origin plus the Security path (`app/api/auth/hub/password/return.ts`).
242
+ client's REGISTERED origin plus the Security path (the package's `api/auth/hub/password/return.ts`).
223
243
  `resetSendConfigured()` is checked before that API call, which charges the
224
244
  send budgets. A completed reset ends every spoke credential
225
245
  (`onPasswordReset`), so the hub's page returns the person to the spoke's
@@ -452,7 +472,7 @@ Cal.com edit and the page.
452
472
  fallback title — its sections are never rendered here.
453
473
  - **Chrome.** `lib/modules.generated.ts`'s `SCHEDULING_PAGES` (written by
454
474
  create-ailk from `apps/web/package.json`, never copied by `update`) and
455
- `lib/auth-routes.ts`'s `isBookingPath` make the locale layout drop the
475
+ `@working-theory/auth/edge`'s `isBookingPath` make the locale layout drop the
456
476
  marketing shell on `/meet`, `/meet/<slug>` and `/private`; `/meet/confirmed`
457
477
  and a site without the module keep it. The consent banner stays.
458
478
  - **The CSP (D12).** `security-headers.config.ts` exports `SCHEDULING_CSP`
@@ -747,7 +767,9 @@ A list page whose frontmatter sets `navOnly: true` (valid on a registry list typ
747
767
  - Don't reach into `apps/api` or `apps/mcp` from `apps/web`. They're peer apps — talk via HTTP/MCP.
748
768
  - Don't commit images to `screenshots/` — only the `.gitkeep` is tracked.
749
769
 
750
- Last updated: 2026-11-10 — § Where the docs live: the docs and blog pages and their loaders ship in `@working-theory/ui-docs-blog`, this app holds their two generated route files and `docs-blog.config.tsx`, and the `docs` and `blog` strings ship in the package (#11254) — verified against `packages-paid/ui-docs-blog/{routes.json,src/config.ts,src/pages/}`, `docs-blog.config.tsx`, `lib/source.ts` and `i18n/request.ts`.
770
+ Last updated: 2026-11-10 — § The `(auth)` route group: sign-in, the hub session and the auth routes ship in `@working-theory/auth`, this app holds their 25 generated route files and `auth.config.tsx`, Better Auth reaches the package through `loadAuth()`, and the middleware's auth half is the package's edge entry (#11257) — verified against `packages/auth/{routes.json,src/site.ts,src/edge.ts}`, `auth.config.tsx`, `middleware.ts`, `lib/topology.generated.ts` and `i18n/request.ts`.
771
+
772
+ Prior: 2026-11-10 — § Where the docs live: the docs and blog pages and their loaders ship in `@working-theory/ui-docs-blog`, this app holds their two generated route files and `docs-blog.config.tsx`, and the `docs` and `blog` strings ship in the package (#11254) — verified against `packages-paid/ui-docs-blog/{routes.json,src/config.ts,src/pages/}`, `docs-blog.config.tsx`, `lib/source.ts` and `i18n/request.ts`.
751
773
 
752
774
  Prior: 2026-11-10 — § Spoke checkout: the checkout and purchase return pages ship in `@working-theory/ui-commerce`, this app holds their generated route files and `commerce.config.tsx`, the strings ship in the package, the stamp is bundle-delivered and stamped in place on a spoke, and the purchase pair is module-carried (#11253) — verified against `packages-paid/ui-commerce/{routes.json,src/config.ts,src/pages/}`, `commerce.config.tsx`, `i18n/request.ts` and create-ailk's `spoke-checkout.ts`.
753
775
 
@@ -15,9 +15,13 @@
15
15
  // `next-intl/server`, in any copy, lands here. Per-test `jest.mock(
16
16
  // "next-intl/server", …)` overrides still work — jest resolves the specifier
17
17
  // through the mapper first, so the override and the consumer agree.
18
+ import authMsgs from "@working-theory/auth/messages/en";
19
+
18
20
  import msgs from "../../messages/en.json";
19
21
 
20
- const catalog = msgs as unknown as Record<string, Record<string, string>>;
22
+ // The sign-in package's catalog is merged under this site's, as
23
+ // `i18n/request.ts` merges it (#11257 D12).
24
+ const catalog = { ...authMsgs, ...msgs } as unknown as Record<string, Record<string, string>>;
21
25
 
22
26
  // Handles both call forms used in apps/web routes:
23
27
  // getTranslations("namespace") — pre-migration routes
@@ -1,9 +1,13 @@
1
1
  // Canonical `next-intl` stand-in for this workspace's Jest runs.
2
2
  // Mapped rather than only `jest.mock()`d for the same reason as
3
3
  // ./next-intl-server.ts — see that file's header.
4
+ import authMsgs from "@working-theory/auth/messages/en";
5
+
4
6
  import msgs from "../../messages/en.json";
5
7
 
6
- const catalog = msgs as unknown as Record<string, Record<string, string>>;
8
+ // The sign-in package's catalog is merged under this site's, as
9
+ // `i18n/request.ts` merges it (#11257 D12).
10
+ const catalog = { ...authMsgs, ...msgs } as unknown as Record<string, Record<string, string>>;
7
11
 
8
12
  export const useTranslations =
9
13
  (namespace: string) =>
@@ -0,0 +1,34 @@
1
+ /**
2
+ * @jest-environment node
3
+ *
4
+ * The sign-in package's seam resolves to this site's `auth.config.tsx`, not
5
+ * to the package's stub (#11257 D4, SEC-11257-1, AC-5). A build or a suite
6
+ * that lost the alias would bind the stub, whose every read throws; this
7
+ * suite is the check that runs before any request, as
8
+ * `create-ailk routes --check` is for `next.config.mjs`. A template file:
9
+ * every site carries it, hub or spoke.
10
+ */
11
+ import { isSeamStub } from "@working-theory/auth";
12
+ import { site } from "@working-theory/auth/site";
13
+
14
+ import authConfig from "../../auth.config";
15
+
16
+ describe("@working-theory/auth/site is this site's auth.config.tsx (#11257 AC-5)", () => {
17
+ it("is not the package's stub", () => {
18
+ expect(isSeamStub(site)).toBe(false);
19
+ });
20
+
21
+ it("carries the site's Better Auth loader and its sign-in configuration", () => {
22
+ expect(typeof site.loadAuth).toBe("function");
23
+ expect(typeof site.env.resetSendConfigured).toBe("function");
24
+ });
25
+
26
+ it("binds the hub-only services exactly on a hub", () => {
27
+ expect(["hub", "spoke"]).toContain(site.topology);
28
+ expect(site.hub === null).toBe(site.topology === "spoke");
29
+ });
30
+
31
+ it("the default export is defineAuthConfig({})", () => {
32
+ expect(authConfig).toEqual({});
33
+ });
34
+ });
@@ -27,13 +27,12 @@
27
27
  */
28
28
  import { type AccountSite, defineAccountConfig } from "@working-theory/account";
29
29
  import { baseForYouSources, baseInboxKinds, baseNewActions } from "@working-theory/account/contributions";
30
+ import { hubSessionHubOrigin, resealHubSession } from "@working-theory/auth/hub-session";
30
31
  import { cookies } from "next/headers";
31
32
 
32
33
  import { getActiveProviderIds, resetSendConfigured } from "./lib/auth-env";
33
34
  import { consentPoliciesFor } from "./lib/consent-policies";
34
35
  import { consentVisitorHeader, readConsentVisitor } from "./lib/consent-visitor";
35
- import { hubSessionConfig } from "./lib/hub-session/config";
36
- import { resealHubSession } from "./lib/hub-session/reseal";
37
36
  import { formatMinorUnits, offeringsCheckoutHref } from "./lib/offerings-pricing";
38
37
  import { readShownOfferings } from "./lib/pricing-page";
39
38
  import { forwardedCookieInit } from "./lib/server-api";
@@ -88,7 +87,7 @@ export const site = {
88
87
  forwardedCookieInit,
89
88
  resealHubSession,
90
89
  activeProviderIds: getActiveProviderIds,
91
- hubOrigin: () => hubSessionConfig()?.hubOrigin ?? null,
90
+ hubOrigin: () => hubSessionHubOrigin(),
92
91
  resetSendConfigured,
93
92
  consentPoliciesFor,
94
93
  async consentVisitorHeaders() {
@@ -82,7 +82,7 @@ jest.mock("../../../../../../lib/topology.generated", () => {
82
82
  };
83
83
  });
84
84
 
85
- import { mintContinuation } from "../../../../../api/auth/hub/continuation";
85
+ import { mintContinuation } from "@working-theory/auth/testing";
86
86
  import Page, { generateMetadata } from "../page";
87
87
 
88
88
  const SPOKE_ORIGIN = "https://spoke.example.com";
@@ -21,6 +21,7 @@
21
21
 
22
22
  import { accountSession } from "@working-theory/account/account-data";
23
23
  import { hubSignIn } from "@working-theory/api-client";
24
+ import { openContinuation } from "@working-theory/auth/hub-continuation";
24
25
  import { localeHref } from "@working-theory/ui";
25
26
  import { Button, Heading, Input, Link, Text } from "@working-theory/ui/primitives";
26
27
  import { hubAuthorizeQuerySchema, type HubAuthorizeQuery } from "@working-theory/validation";
@@ -31,7 +32,6 @@ import type { ReactElement } from "react";
31
32
 
32
33
  import { resolveSecret } from "../../../../../auth";
33
34
  import { TOPOLOGY } from "../../../../../lib/topology.generated";
34
- import { openContinuation } from "../../../../api/auth/hub/continuation";
35
35
 
36
36
  /** The authorize route's POST — the one request that says yes. */
37
37
  const AUTHORIZE_PATH = "/api/auth/hub/authorize";
@@ -5,6 +5,7 @@
5
5
  // /sign-in (an account path with no sign-in method on says so in place); a
6
6
  // spoke that signs in through its hub (`--hub-sign-in`) redirects to its
7
7
  // hub-session sign-in route.
8
+ import { isAccountPath } from "@working-theory/auth/edge";
8
9
  import { localeHref } from "@working-theory/ui";
9
10
  import { Button, Heading, Link, Text } from "@working-theory/ui/primitives";
10
11
  import { readLocales } from "@working-theory/web-i18n";
@@ -13,7 +14,6 @@ import { getTranslations } from "next-intl/server";
13
14
  import type { ReactElement } from "react";
14
15
 
15
16
  import { getActiveProviderIds } from "../../../lib/auth-env";
16
- import { isAccountPath } from "../../../lib/auth-routes";
17
17
 
18
18
  /** The methods a member signs in with on /sign-in's card. */
19
19
  const MEMBER_METHODS: readonly string[] = ["google", "github", "magic-link"];
@@ -29,6 +29,7 @@ import { readFileSync } from "node:fs";
29
29
  import { join } from "node:path";
30
30
 
31
31
  import { Telemetry, VerificationMeta } from "@working-theory/analytics";
32
+ import { isAccountPath, isAuthPath, isBookingPath } from "@working-theory/auth/edge";
32
33
  import { slugFormTarget } from "@working-theory/page-renderer";
33
34
  import {
34
35
  SiteConsentSchema,
@@ -66,7 +67,6 @@ import type { ReactElement, ReactNode } from "react";
66
67
  import { parse as parseYaml } from "yaml";
67
68
 
68
69
  import { GoogleAnalytics } from "../../components/google-analytics";
69
- import { isAccountPath, isAuthPath, isBookingPath } from "../../lib/auth-routes";
70
70
  import { BOT_CLIENT_PROTECT, botCheckOn } from "../../lib/bot-check";
71
71
  import { isClosingFooterPath } from "../../lib/closing-footer-path";
72
72
  import { pageOptsIntoDeck } from "../../lib/deck-page";