@wwchen/stack 0.7.0 → 0.8.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 CHANGED
@@ -11,10 +11,6 @@ Requires Node 24. The peer dependencies are exact pins: `next`, `react`, `react-
11
11
  | `@wwchen/stack/env` | `stackEnvSchema` and `stackEnv()`: the shared variables, validated; production requires `APP_URL` (derived on Vercel when unset), `DATABASE_URL`, `BETTER_AUTH_SECRET`, `RESEND_API_KEY`, `EMAIL_FROM`. `SKIP_ENV_VALIDATION=1` skips it in builds (never at production runtime). |
12
12
  | `@wwchen/stack/db` | the pooled client, `migrationStatus`, the dev-database guard that refuses production |
13
13
  | `@wwchen/stack/db/testing`, `/db/testing/isolate` | test databases: PGlite by default, a real Postgres when `TEST_DATABASE_URL` is set |
14
- | `@wwchen/stack/mail` | deprecated: re-exports [`@wwchen/stack-notify`](../notify); import that instead |
15
- | `@wwchen/stack/auth` | deprecated: re-exports [`@wwchen/stack-auth`](../auth); import that instead |
16
- | `@wwchen/stack/auth/better-auth` | deprecated: re-exports `@wwchen/stack-auth/better-auth`; import that instead |
17
- | `@wwchen/stack/auth/proxy` | deprecated: re-exports `@wwchen/stack-auth/proxy`; import that instead |
18
14
  | `@wwchen/stack/next` | `withStack(appConfig)` for `next.config.ts`, `apiHandler` and `readJson`, `cronRoute` (answers 500 when the job returns `alerting: true`) and `healthRoute` |
19
15
  | `@wwchen/stack/connections` | connected accounts (not sign-in): `connectionTable`, `createConnections` (start and callback route handlers, `token`, `list`, `connected`, `disconnect`), the `ConnectionProvider` type each app implements for its own services, AES-256-GCM token encryption under `TOKEN_ENCRYPTION_KEY` |
20
16
  | `@wwchen/stack/jobs` | multi-person scheduled jobs: `failingSince` and `isNewFailure` (alert on a failure's first 24 hours only), `mapLimit` |
@@ -23,7 +19,7 @@ Requires Node 24. The peer dependencies are exact pins: `next`, `react`, `react-
23
19
  | `@wwchen/stack/configs/tsconfig.next.json`, `/configs/biome.json`, `/configs/vitest` | shared tool configs, consumed with `extends` or an import |
24
20
  | `@wwchen/stack/testing/next` | tests only: `inServerAction` runs a function in a real Next server-action scope, `thrownBy` reads a `redirect()`/`notFound()` |
25
21
 
26
- The deprecated paths still work in this release; a later release removes them. They are deprecated in this documentation only: each re-exports its package with `export *`, which does not carry `@deprecated` to the names, so an editor does not strike them through. `stack migrate-suite` moves an app's imports off them. Sign-in never creates users: every user is added first (`stack user:create`), has an email, and the email is unique, trimmed and lower-cased.
22
+ Sign-in and mail are [`@wwchen/stack-auth`](../auth) and [`@wwchen/stack-notify`](../notify); the old paths (`@wwchen/stack/auth`, `/auth/better-auth`, `/auth/proxy`, `/mail`) are gone, and `stack migrate-suite` moves an app's imports off them. Sign-in never creates users: every user is added first (`stack user:create`), has an email, and the email is unique, trimmed and lower-cased.
27
23
 
28
24
  ### Connected accounts
29
25
 
@@ -62,7 +58,7 @@ The callback lands on `next` with `?connection=<provider>&result=<code>`, where
62
58
  | `stack user:create <email> [--admin] [--preview]` | adds a user through the app's `src/lib/auth.ts`; `--preview` adds your own email to the shared `preview` branch so you can sign in on a preview (`docs/runbook.md`, "Signing in on a preview") |
63
59
  | `stack user:role <email> <admin\|user> [--preview]` | changes a user's role through the app's `src/lib/auth.ts`; never leaves the app without an admin |
64
60
  | `stack sync-blocks [--check]` | refreshes the stack blocks in `AGENTS.md`, `CLAUDE.md`, `.gitignore`, `.env.example` |
65
- | `stack migrate-suite [--expect <version>]` | moves the app onto `@wwchen/stack-auth` and `@wwchen/stack-notify`: adds them to `package.json` and the suite's packages to `pnpm-workspace.yaml`'s `minimumReleaseAgeExclude` (where the app has that list, or sets `minimumReleaseAge`), rewrites import and export specifiers of the old paths (and `vi.mock`-style module names), sorts the imports it touched with the app's Biome, and adds `rateLimit` to `src/db/schema.ts` and `src/lib/auth.ts` when they have the template's shape (otherwise prints the lines to write, and exits non-zero when the auth provider gets `authTables()`'s `rate_limit` table that the schema does not export, since sign-in would answer `unavailable`); changes nothing on an app already moved. `--expect` refuses unless the installed stack is that version |
61
+ | `stack migrate-suite [--expect <version>]` | moves the app onto `@wwchen/stack-auth` and `@wwchen/stack-notify`: adds them to `package.json` and the suite's packages to `pnpm-workspace.yaml`'s `minimumReleaseAgeExclude` (where the app has that list, or sets `minimumReleaseAge`), rewrites import and export specifiers of the old paths (and `vi.mock`-style module names), sorts the imports it touched with the app's Biome; changes nothing on an app already moved. `--expect` refuses unless the installed stack is that version |
66
62
 
67
63
  `NEON_PROJECT_ID` comes from the environment; nothing in the package names a project or domain.
68
64
 
package/blocks/AGENTS.md CHANGED
@@ -63,7 +63,7 @@ The design system is LDS (Lew Design System), product theme: `@lew-ds/lds`, `@le
63
63
  2. Never render free text from a URL; redirects carry short codes.
64
64
  3. Sign-in links are single-use and expire. OAuth `state` is signed and bound to the browser that started the flow.
65
65
  4. Sessions are HttpOnly, Secure (when https), SameSite=Lax. Mutations require JSON and a same-origin request.
66
- 5. Magic links are anti-enumeration, with hashed tokens and sign-in rate limits.
66
+ 5. Magic links are anti-enumeration, with hashed tokens.
67
67
  6. Connected-account tokens are encrypted at rest; Better Auth never stores third-party API tokens.
68
68
  7. Previews get their own secrets and no production third-party keys.
69
69
  8. Never write a deployment's domain in the repo. Name variables (`APP_URL`, `EMAIL_FROM`), never a host.
package/blocks/CLAUDE.md CHANGED
@@ -73,7 +73,7 @@ The design system is LDS (Lew Design System), product theme: `@lew-ds/lds`, `@le
73
73
  2. No free text from URLs is ever rendered; redirects carry short codes.
74
74
  3. Sign-in links are single-use and expire; OAuth `state` is signed and bound to the browser that started the flow.
75
75
  4. Sessions: HttpOnly, Secure (when https), SameSite=Lax; mutations require JSON and same-origin.
76
- 5. Anti-enumeration on magic links; hashed tokens; sign-in rate limits.
76
+ 5. Anti-enumeration on magic links; hashed tokens.
77
77
  6. Local tooling refuses the production database unless explicitly opted in.
78
78
  7. Connected-account tokens are encrypted at rest (AES-256-GCM); Better Auth never stores third-party API tokens.
79
79
  8. Other people's data stays out of dev and previews.
@@ -27,7 +27,5 @@ GOOGLE_CLIENT_ID=
27
27
  GOOGLE_CLIENT_SECRET=
28
28
  # Proxy hops to trust for the client IP (0 on Vercel)
29
29
  TRUSTED_PROXY_HOPS=
30
- # Sign-in attempts allowed per hour (default 10)
31
- AUTH_RATE_LIMIT_PER_HOUR=
32
30
  # Log level (default info)
33
31
  LOG_LEVEL=
@@ -1,8 +1,6 @@
1
- // `stack migrate-suite [--expect <version>]` — moves an app onto the suite's packages, as the installed stack knows them: adds the `@wwchen/stack-*` packages to package.json and to pnpm-workspace.yaml's release-age exemptions, moves imports of the stack's old paths to them, and exports and passes the auth package's `rate_limit` table where the schema and auth file have the template's shape. Copier runs it after `pnpm install`; it changes nothing on an app already moved.
1
+ // `stack migrate-suite [--expect <version>]` — moves an app onto the suite's packages, as the installed stack knows them: adds the `@wwchen/stack-*` packages to package.json and to pnpm-workspace.yaml's release-age exemptions, and moves imports of the stack's old paths to them. Copier runs it after `pnpm install`; it changes nothing on an app already moved.
2
2
  //
3
3
  // Imports are found with the TypeScript compiler API, never by searching text: a comment or a string that names an old path stays as it is. Every change is worked out before any file is written.
4
- //
5
- // It exits non-zero, after making every change it can, when the auth provider would get the `rate_limit` table from `authTables()` while the schema does not export it: drizzle-kit would never create the table and every sign-in would answer `unavailable`, so the upgrade must fail where someone sees it.
6
4
  import { existsSync, readdirSync, readFileSync, writeFileSync } from "node:fs";
7
5
  import { dirname, join, relative, sep } from "node:path";
8
6
  import { CliError, STACK_PACKAGE } from "./context.js";
@@ -27,12 +25,6 @@ const VI_MODULE_CALLS = new Set([
27
25
  ]);
28
26
  /** The one name `@wwchen/stack/mail` exports that lives in auth, not notify. */
29
27
  const MAGIC = "waitForMagicLink";
30
- const BETTER_AUTH = new Set(["@wwchen/stack/auth/better-auth", `${AUTH}/better-auth`]);
31
- const SCHEMA = "src/db/schema.ts";
32
- const AUTH_FILE = "src/lib/auth.ts";
33
- const SCHEMA_IMPORT = "../db/schema.ts";
34
- const TEMPLATE_TABLES = ["account", "appUser", "session", "verification"];
35
- const RATE_LIMIT = "rateLimit";
36
28
  const STACK_PACKAGE_NAME = "@wwchen/stack";
37
29
  const WORKSPACE = "pnpm-workspace.yaml";
38
30
  const RELEASE_AGE_EXCLUDE = "minimumReleaseAgeExclude";
@@ -57,11 +49,6 @@ export async function migrateSuite(cli, args) {
57
49
  writes.set(path, moved.text);
58
50
  }
59
51
  const moved = [...writes.keys()];
60
- const current = (path) => writes.get(path) ??
61
- (existsSync(join(cli.cwd, path)) ? readFileSync(join(cli.cwd, path), "utf8") : undefined);
62
- const tables = rateLimitEdits(ts, current(SCHEMA), current(AUTH_FILE), new Set(moved));
63
- for (const [path, text] of Object.entries(tables.writes))
64
- writes.set(path, text);
65
52
  const workspacePath = join(cli.cwd, WORKSPACE);
66
53
  const workspace = releaseAgeEdit(existsSync(workspacePath) ? readFileSync(workspacePath, "utf8") : undefined, suitePackages(packages.text));
67
54
  if (packages.added.length > 0)
@@ -82,7 +69,7 @@ export async function migrateSuite(cli, args) {
82
69
  if (moved.length > 0) {
83
70
  lines.push(`imports moved to the suite's packages in ${moved.length} ${moved.length === 1 ? "file" : "files"}:`, ...moved.sort().map((path) => ` ${path}`));
84
71
  }
85
- lines.push(...tables.done, ...tables.manual, ...notes);
72
+ lines.push(...notes);
86
73
  if (!sorted) {
87
74
  lines.push("Biome could not sort the imports of the files above; run `pnpm lint:fix`.");
88
75
  }
@@ -101,10 +88,7 @@ export async function migrateSuite(cli, args) {
101
88
  if (code !== 0)
102
89
  cli.error("migrate-suite: pnpm install failed; run it again in the app.");
103
90
  }
104
- if (tables.refusal === undefined)
105
- return code;
106
- cli.error(`migrate-suite: ${tables.refusal}`);
107
- return code === 0 ? 1 : code;
91
+ return code;
108
92
  }
109
93
  function parseArgs(args) {
110
94
  if (args.length === 0)
@@ -332,17 +316,6 @@ function applyEdits(text, edits) {
332
316
  return out;
333
317
  }
334
318
  const newlines = (text) => text.split("\n").length - 1;
335
- /** An edit made against the whole file, moved to apply to the slice of it that starts at `offset`. */
336
- const within = (edit, offset) => ({
337
- ...edit,
338
- start: edit.start - offset,
339
- end: edit.end - offset,
340
- });
341
- /** A statement's text with `edits` applied, for a line to print. */
342
- const statementWith = (sf, node, edits) => {
343
- const start = node.getStart(sf);
344
- return applyEdits(sf.text.slice(start, node.end), edits.map((edit) => within(edit, start)));
345
- };
346
319
  /** Moves every import and export specifier (static, dynamic, `import type`, `import x = require`) off the old paths. Comments and other strings are never changed; a string that is exactly an old path is pointed out. */
347
320
  function moveImports(ts, path, text) {
348
321
  const sf = parse(ts, path, text);
@@ -516,272 +489,3 @@ function splitMail(ts, sf, decl) {
516
489
  const notifyPart = applyEdits(original, [{ ...names, text: list(rest) }, specifier(NOTIFY)]);
517
490
  return { start, end: decl.end, text: `${authPart}\n${indent}${notifyPart}` };
518
491
  }
519
- /**
520
- * Adds `rateLimit` to the schema's `authTables()` export and to auth's `tables` and its import, each only when it has exactly the template's shape; otherwise the file is left as it is and the lines to write are given. Auth is edited only once the schema exports the table. A refusal when auth hands the provider an `authTables()` result, which carries the table, and the schema will not export it.
521
- */
522
- function rateLimitEdits(ts, schemaText, authText, moved) {
523
- const result = { writes: {}, done: [], manual: [] };
524
- const heldBack = (path) => `rateLimit is not added to it${moved.has(path) ? " (only its imports were moved)" : ""}`;
525
- if (schemaText === undefined)
526
- return result;
527
- const schema = schemaEdit(ts, schemaText);
528
- if (schema.kind === "edit") {
529
- result.writes[SCHEMA] = schema.text;
530
- result.done.push(`${SCHEMA}: exports rateLimit`);
531
- }
532
- else if (schema.kind === "manual") {
533
- result.manual.push(`${SCHEMA} does not have the template's shape, so ${heldBack(SCHEMA)}. Export the rate_limit table by hand, ${schema.replace ? "so this line reads" : "adding this line"}:`, ...schema.lines.map((line) => ` ${line}`));
534
- }
535
- if (authText === undefined)
536
- return result;
537
- const auth = authEdit(ts, authText);
538
- if (auth.kind === "has")
539
- return result;
540
- if (auth.kind === "carries") {
541
- if (schema.kind === "manual") {
542
- result.refusal = `${AUTH_FILE} gives betterAuthProvider the rate_limit table from authTables(), and ${SCHEMA} does not export it: every sign-in would answer \`unavailable\` until the table is exported and migrated. Make ${SCHEMA} read as printed above, run this command again, then \`pnpm exec stack db:upgrade\` and \`pnpm exec stack sync-blocks\`, and commit the migration with the rest. As a Copier task, this stopped \`copier update\` before it put back the app's own changes to the template's files, so commit nothing from this run: discard it (\`git reset --hard && git clean -fd\`), run \`copier update\` again with \`--skip-tasks\`, then \`pnpm install\` and the steps above.`;
543
- }
544
- return result;
545
- }
546
- if (auth.kind === "edit" && schema.kind !== "manual") {
547
- result.writes[AUTH_FILE] = auth.text;
548
- result.done.push(`${AUTH_FILE}: passes rateLimit to betterAuthProvider`);
549
- return result;
550
- }
551
- result.manual.push(auth.kind === "edit"
552
- ? `${AUTH_FILE} gets no rateLimit until ${SCHEMA} exports it${moved.has(AUTH_FILE) ? " (only its imports were moved)" : ""}. Then make these lines read:`
553
- : `${AUTH_FILE} does not have the template's shape, so ${heldBack(AUTH_FILE)}. Pass the rate_limit table to betterAuthProvider by hand, so these lines read:`, ...auth.lines.map((line) => ` ${line}`));
554
- return result;
555
- }
556
- /** The name a file binds an export of the better-auth entry to, if it imports it. */
557
- function importedFromBetterAuth(ts, sf, name) {
558
- for (const statement of sf.statements) {
559
- if (!ts.isImportDeclaration(statement) || !ts.isStringLiteral(statement.moduleSpecifier))
560
- continue;
561
- if (!BETTER_AUTH.has(statement.moduleSpecifier.text))
562
- continue;
563
- const bindings = statement.importClause?.namedBindings;
564
- if (!bindings || !ts.isNamedImports(bindings))
565
- continue;
566
- const element = bindings.elements.find((e) => (e.propertyName ?? e.name).text === name);
567
- if (element)
568
- return element.name.text;
569
- }
570
- return undefined;
571
- }
572
- /** Names the file's top level binds, and those it exports. */
573
- function topLevel(ts, sf) {
574
- const bound = new Set();
575
- const exported = new Set();
576
- const bind = (name, isExported) => {
577
- if (ts.isIdentifier(name)) {
578
- bound.add(name.text);
579
- if (isExported)
580
- exported.add(name.text);
581
- }
582
- else {
583
- for (const element of name.elements) {
584
- if (!ts.isOmittedExpression(element))
585
- bind(element.name, isExported);
586
- }
587
- }
588
- };
589
- for (const statement of sf.statements) {
590
- const isExported = ts.canHaveModifiers(statement) &&
591
- (ts.getModifiers(statement) ?? []).some((m) => m.kind === ts.SyntaxKind.ExportKeyword);
592
- if (ts.isImportDeclaration(statement)) {
593
- const clause = statement.importClause;
594
- if (clause?.name)
595
- bound.add(clause.name.text);
596
- const bindings = clause?.namedBindings;
597
- if (bindings && ts.isNamespaceImport(bindings))
598
- bound.add(bindings.name.text);
599
- if (bindings && ts.isNamedImports(bindings)) {
600
- for (const element of bindings.elements)
601
- bound.add(element.name.text);
602
- }
603
- }
604
- else if (ts.isVariableStatement(statement)) {
605
- for (const declaration of statement.declarationList.declarations) {
606
- bind(declaration.name, isExported);
607
- }
608
- }
609
- else if ((ts.isFunctionDeclaration(statement) || ts.isClassDeclaration(statement)) &&
610
- statement.name) {
611
- bind(statement.name, isExported);
612
- }
613
- else if (ts.isExportDeclaration(statement) &&
614
- statement.exportClause &&
615
- ts.isNamedExports(statement.exportClause)) {
616
- for (const element of statement.exportClause.elements)
617
- exported.add(element.name.text);
618
- }
619
- }
620
- return { bound, exported };
621
- }
622
- /** `, rateLimit` after the last element of a list. */
623
- const appendTo = (list) => {
624
- const last = list[list.length - 1];
625
- return { start: last.end, end: last.end, text: `, ${RATE_LIMIT}` };
626
- };
627
- const isTemplateNames = (names) => names.length === TEMPLATE_TABLES.length &&
628
- [...names].sort().every((name, i) => name === TEMPLATE_TABLES[i]);
629
- function schemaEdit(ts, text) {
630
- const sf = parse(ts, SCHEMA, text);
631
- const { bound, exported } = topLevel(ts, sf);
632
- if (exported.has(RATE_LIMIT))
633
- return { kind: "has" };
634
- const local = importedFromBetterAuth(ts, sf, "authTables");
635
- // Each `export const { … } = authTables(…)`.
636
- const exports = sf.statements.flatMap((statement) => {
637
- if (!ts.isVariableStatement(statement))
638
- return [];
639
- const declaration = statement.declarationList.declarations[0];
640
- const isExportedConst = (ts.getModifiers(statement) ?? []).some((m) => m.kind === ts.SyntaxKind.ExportKeyword) &&
641
- (statement.declarationList.flags & ts.NodeFlags.Const) !== 0 &&
642
- statement.declarationList.declarations.length === 1;
643
- if (!isExportedConst ||
644
- !declaration ||
645
- !ts.isObjectBindingPattern(declaration.name) ||
646
- !declaration.initializer ||
647
- !ts.isCallExpression(declaration.initializer) ||
648
- !ts.isIdentifier(declaration.initializer.expression) ||
649
- declaration.initializer.expression.text !== local) {
650
- return [];
651
- }
652
- return [{ statement, pattern: declaration.name }];
653
- });
654
- const only = exports.length === 1 ? exports[0] : undefined;
655
- if (only && !bound.has(RATE_LIMIT)) {
656
- const { elements } = only.pattern;
657
- const plain = elements.every((e) => !e.dotDotDotToken && !e.propertyName && !e.initializer && ts.isIdentifier(e.name));
658
- if (plain && isTemplateNames(elements.map((e) => e.name.text))) {
659
- return { kind: "edit", text: applyEdits(text, [appendTo(elements)]), lines: [] };
660
- }
661
- }
662
- if (only && only.pattern.elements.length > 0) {
663
- const line = statementWith(sf, only.statement, [appendTo(only.pattern.elements)]);
664
- return { kind: "manual", lines: [line], replace: true };
665
- }
666
- return {
667
- kind: "manual",
668
- lines: [
669
- ...(local ? [] : [`import { authTables } from "${AUTH}/better-auth";`]),
670
- `export const { ${RATE_LIMIT} } = ${local ?? "authTables"}();`,
671
- ],
672
- replace: false,
673
- };
674
- }
675
- function authEdit(ts, text) {
676
- const sf = parse(ts, AUTH_FILE, text);
677
- const provider = importedFromBetterAuth(ts, sf, "betterAuthProvider");
678
- const tablesFn = importedFromBetterAuth(ts, sf, "authTables");
679
- const calls = [];
680
- const visit = (node) => {
681
- if (ts.isCallExpression(node) &&
682
- ts.isIdentifier(node.expression) &&
683
- node.expression.text === provider) {
684
- calls.push(node);
685
- }
686
- ts.forEachChild(node, visit);
687
- };
688
- if (provider)
689
- visit(sf);
690
- const options = calls.length === 1 ? calls[0]?.arguments[0] : undefined;
691
- const tablesProps = options && ts.isObjectLiteralExpression(options)
692
- ? options.properties.filter((p) => p.name && ts.isIdentifier(p.name) && p.name.text === "tables")
693
- : [];
694
- const tables = tablesProps.length === 1 ? tablesProps[0] : undefined;
695
- const value = tables && ts.isPropertyAssignment(tables)
696
- ? tables.initializer
697
- : tables && ts.isShorthandPropertyAssignment(tables)
698
- ? tables.name
699
- : undefined;
700
- if (value && ts.isObjectLiteralExpression(value)) {
701
- const names = value.properties.map((p) => p.name && ts.isIdentifier(p.name) ? p.name.text : "");
702
- if (names.includes(RATE_LIMIT))
703
- return { kind: "has" };
704
- }
705
- if (value && tablesFn) {
706
- // Top-level `const x = authTables(…)`.
707
- const results = new Set(sf.statements.flatMap((s) => ts.isVariableStatement(s) && (s.declarationList.flags & ts.NodeFlags.Const) !== 0
708
- ? s.declarationList.declarations.flatMap((d) => ts.isIdentifier(d.name) && d.initializer && callsTables(ts, d.initializer, tablesFn)
709
- ? [d.name.text]
710
- : [])
711
- : []));
712
- const isResult = (node) => {
713
- const inner = unwrap(ts, node);
714
- return (callsTables(ts, inner, tablesFn) || (ts.isIdentifier(inner) && results.has(inner.text)));
715
- };
716
- const inner = unwrap(ts, value);
717
- if (isResult(inner) ||
718
- (ts.isObjectLiteralExpression(inner) &&
719
- inner.properties.some((p) => ts.isSpreadAssignment(p) && isResult(p.expression)))) {
720
- return { kind: "carries" };
721
- }
722
- }
723
- const imports = sf.statements.filter((s) => ts.isImportDeclaration(s) &&
724
- ts.isStringLiteral(s.moduleSpecifier) &&
725
- s.moduleSpecifier.text === SCHEMA_IMPORT &&
726
- !!s.importClause?.namedBindings &&
727
- ts.isNamedImports(s.importClause.namedBindings));
728
- const schemaImport = imports.length === 1 ? imports[0] : undefined;
729
- const elements = schemaImport?.importClause?.namedBindings
730
- ?.elements;
731
- const importEdit = () => {
732
- if (!elements || elements.length === 0)
733
- return undefined;
734
- // Sorted in, as the app's formatter keeps a named import.
735
- const after = elements.find((e) => e.name.text.toLowerCase() > RATE_LIMIT.toLowerCase());
736
- if (after) {
737
- const start = after.getStart(sf);
738
- return { start, end: start, text: `${RATE_LIMIT}, ` };
739
- }
740
- return appendTo(elements);
741
- };
742
- const importLine = () => {
743
- const edit = importEdit();
744
- if (!schemaImport || !edit)
745
- return `import { ${RATE_LIMIT} } from "${SCHEMA_IMPORT}";`;
746
- return statementWith(sf, schemaImport, [edit]);
747
- };
748
- const tablesLine = () => {
749
- if (value && ts.isObjectLiteralExpression(value) && value.properties.length > 0 && tables) {
750
- return `${statementWith(sf, tables, [appendTo(value.properties)])},`;
751
- }
752
- return value
753
- ? `tables: { ...${value.getText(sf)}, ${RATE_LIMIT} },`
754
- : `tables: { appUser, session, account, verification, ${RATE_LIMIT} },`;
755
- };
756
- const lines = [importLine(), tablesLine()];
757
- const isTemplate = value &&
758
- ts.isObjectLiteralExpression(value) &&
759
- value.properties.every((p) => ts.isShorthandPropertyAssignment(p) && !p.objectAssignmentInitializer) &&
760
- isTemplateNames(value.properties.map((p) => p.name.text)) &&
761
- !!schemaImport &&
762
- schemaImport.importClause?.phaseModifier === undefined &&
763
- TEMPLATE_TABLES.every((name) => elements?.some((e) => !e.propertyName && !e.isTypeOnly && e.name.text === name)) &&
764
- !topLevel(ts, sf).bound.has(RATE_LIMIT);
765
- if (!isTemplate || !value || !ts.isObjectLiteralExpression(value)) {
766
- return { kind: "manual", lines, replace: true };
767
- }
768
- const edits = [appendTo(value.properties), importEdit()];
769
- return { kind: "edit", text: applyEdits(text, edits), lines };
770
- }
771
- /** An expression without the parentheses, `as`, `satisfies` and `!` around it. */
772
- function unwrap(ts, node) {
773
- let at = node;
774
- while (ts.isParenthesizedExpression(at) ||
775
- ts.isAsExpression(at) ||
776
- ts.isSatisfiesExpression(at) ||
777
- ts.isNonNullExpression(at)) {
778
- at = at.expression;
779
- }
780
- return at;
781
- }
782
- const callsTables = (ts, node, tablesFn) => {
783
- const inner = unwrap(ts, node);
784
- return (ts.isCallExpression(inner) &&
785
- ts.isIdentifier(inner.expression) &&
786
- inner.expression.text === tablesFn);
787
- };
@@ -23,7 +23,6 @@ export declare const stackEnvSchema: {
23
23
  GOOGLE_CLIENT_ID: z.ZodOptional<z.ZodString>;
24
24
  GOOGLE_CLIENT_SECRET: z.ZodOptional<z.ZodString>;
25
25
  TRUSTED_PROXY_HOPS: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
26
- AUTH_RATE_LIMIT_PER_HOUR: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
27
26
  LOG_LEVEL: z.ZodDefault<z.ZodString>;
28
27
  };
29
28
  /** Required (raw, non-blank) when NODE_ENV is production. Spread it to extend. */
@@ -1,6 +1,5 @@
1
1
  import { z } from "zod";
2
2
  import { defineEnv } from "./define-env.js";
3
- const count = (fallback) => z.coerce.number().int().positive().default(fallback);
4
3
  /**
5
4
  * The variables every stack app shares. Apps extend it: `defineEnv({ schema: { ...stackEnvSchema, MY_VAR: z.string() }, ... })`. Blank values are treated as absent by `defineEnv`, so no field needs its own preprocessing.
6
5
  */
@@ -30,9 +29,8 @@ export const stackEnvSchema = {
30
29
  // Sign in with Google. Both or neither (group `google`).
31
30
  GOOGLE_CLIENT_ID: z.string().optional(),
32
31
  GOOGLE_CLIENT_SECRET: z.string().optional(),
33
- // 0 on Vercel, which terminates the proxy chain itself.
32
+ // For `clientIp`: 0 on Vercel, which terminates the proxy chain itself.
34
33
  TRUSTED_PROXY_HOPS: z.coerce.number().int().nonnegative().default(0),
35
- AUTH_RATE_LIMIT_PER_HOUR: count(10),
36
34
  LOG_LEVEL: z.string().default("info"),
37
35
  };
38
36
  /** Required (raw, non-blank) when NODE_ENV is production. Spread it to extend. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wwchen/stack",
3
- "version": "0.7.0",
3
+ "version": "0.8.0",
4
4
  "description": "Shared Next.js, Neon, Better Auth, Resend and lew-ds building blocks.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -41,22 +41,6 @@
41
41
  "types": "./dist/db/testing/isolate.d.ts",
42
42
  "default": "./dist/db/testing/isolate.js"
43
43
  },
44
- "./mail": {
45
- "types": "./dist/mail/index.d.ts",
46
- "default": "./dist/mail/index.js"
47
- },
48
- "./auth": {
49
- "types": "./dist/auth/index.d.ts",
50
- "default": "./dist/auth/index.js"
51
- },
52
- "./auth/better-auth": {
53
- "types": "./dist/auth/better-auth/index.d.ts",
54
- "default": "./dist/auth/better-auth/index.js"
55
- },
56
- "./auth/proxy": {
57
- "types": "./dist/auth/proxy.d.ts",
58
- "default": "./dist/auth/proxy.js"
59
- },
60
44
  "./connections": {
61
45
  "types": "./dist/connections/index.d.ts",
62
46
  "default": "./dist/connections/index.js"
@@ -97,8 +81,8 @@
97
81
  },
98
82
  "dependencies": {
99
83
  "@vercel/functions": "3.12.0",
100
- "@wwchen/stack-auth": "0.7.0",
101
- "@wwchen/stack-notify": "0.7.0",
84
+ "@wwchen/stack-auth": "0.8.0",
85
+ "@wwchen/stack-notify": "0.8.0",
102
86
  "pg": "8.23.1",
103
87
  "zod": "4.6.7"
104
88
  },
@@ -1,2 +0,0 @@
1
- /** @deprecated Import from `@wwchen/stack-auth/better-auth`. */
2
- export * from "@wwchen/stack-auth/better-auth";
@@ -1,2 +0,0 @@
1
- /** @deprecated Import from `@wwchen/stack-auth/better-auth`. */
2
- export * from "@wwchen/stack-auth/better-auth";
@@ -1,2 +0,0 @@
1
- /** @deprecated Import from `@wwchen/stack-auth`. */
2
- export * from "@wwchen/stack-auth";
@@ -1,2 +0,0 @@
1
- /** @deprecated Import from `@wwchen/stack-auth`. */
2
- export * from "@wwchen/stack-auth";
@@ -1,2 +0,0 @@
1
- /** @deprecated Import from `@wwchen/stack-auth/proxy`. */
2
- export * from "@wwchen/stack-auth/proxy";
@@ -1,2 +0,0 @@
1
- /** @deprecated Import from `@wwchen/stack-auth/proxy`. */
2
- export * from "@wwchen/stack-auth/proxy";
@@ -1,4 +0,0 @@
1
- import { waitForLink } from "@wwchen/stack-notify";
2
- export * from "@wwchen/stack-notify";
3
- /** @deprecated Use `waitForMagicLink` from `@wwchen/stack-auth`, or `waitForLink` for any other link. */
4
- export declare const waitForMagicLink: typeof waitForLink;
@@ -1,4 +0,0 @@
1
- import { waitForLink } from "@wwchen/stack-notify";
2
- export * from "@wwchen/stack-notify";
3
- /** @deprecated Use `waitForMagicLink` from `@wwchen/stack-auth`, or `waitForLink` for any other link. */
4
- export const waitForMagicLink = waitForLink;