@wwchen/stack 0.6.3 → 0.6.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/blocks/env.example +1 -2
- package/dist/auth/better-auth/index.d.ts +6 -17
- package/dist/auth/better-auth/index.js +11 -33
- package/dist/auth/better-auth/tables.js +5 -14
- package/dist/auth/better-auth/users.d.ts +2 -7
- package/dist/auth/better-auth/users.js +3 -9
- package/dist/auth/index.d.ts +6 -17
- package/dist/auth/index.js +5 -19
- package/dist/auth/proxy.d.ts +1 -3
- package/dist/auth/proxy.js +6 -19
- package/dist/auth/safe-next.d.ts +2 -8
- package/dist/auth/safe-next.js +2 -8
- package/dist/auth/types.d.ts +1 -2
- package/dist/auth/types.js +1 -2
- package/dist/cli/context.d.ts +1 -3
- package/dist/cli/index.js +1 -2
- package/dist/cli/neon.d.ts +11 -44
- package/dist/cli/neon.js +15 -56
- package/dist/cli/sync-blocks.d.ts +1 -3
- package/dist/cli/sync-blocks.js +2 -6
- package/dist/cli/vercel-build.js +5 -16
- package/dist/configs/vitest.js +3 -7
- package/dist/connections/index.d.ts +2 -8
- package/dist/connections/index.js +2 -8
- package/dist/connections/providers.d.ts +1 -3
- package/dist/connections/table.d.ts +1 -2
- package/dist/connections/table.js +1 -2
- package/dist/db/explaining-pool.d.ts +1 -6
- package/dist/db/explaining-pool.js +3 -10
- package/dist/db/index.d.ts +1 -3
- package/dist/db/index.js +5 -13
- package/dist/db/migration-status.d.ts +1 -4
- package/dist/db/migration-status.js +1 -4
- package/dist/db/ssl.d.ts +1 -5
- package/dist/db/ssl.js +1 -5
- package/dist/db/target.d.ts +2 -9
- package/dist/db/target.js +2 -9
- package/dist/db/testing/index.d.ts +3 -7
- package/dist/db/testing/index.js +3 -7
- package/dist/db/testing/isolate.js +1 -2
- package/dist/db/testing/pglite.d.ts +2 -6
- package/dist/db/testing/pglite.js +2 -6
- package/dist/env/define-env.d.ts +3 -9
- package/dist/env/define-env.js +6 -16
- package/dist/env/load-env-file.d.ts +4 -9
- package/dist/env/load-env-file.js +5 -11
- package/dist/env/stack-env.d.ts +1 -3
- package/dist/env/stack-env.js +3 -7
- package/dist/env/testing.d.ts +1 -3
- package/dist/env/testing.js +2 -5
- package/dist/http/client-ip.d.ts +2 -8
- package/dist/http/client-ip.js +3 -10
- package/dist/http/guards.d.ts +3 -10
- package/dist/http/guards.js +4 -12
- package/dist/http/rate-limit.d.ts +4 -10
- package/dist/http/rate-limit.js +7 -19
- package/dist/jobs/index.d.ts +2 -9
- package/dist/jobs/index.js +2 -9
- package/dist/mail/index.d.ts +2 -9
- package/dist/mail/index.js +2 -7
- package/dist/next/api.d.ts +6 -17
- package/dist/next/api.js +6 -15
- package/dist/next/config.js +10 -32
- package/dist/next/cron.d.ts +2 -6
- package/dist/next/cron.js +3 -8
- package/dist/next/health.d.ts +3 -8
- package/dist/next/health.js +3 -8
- package/dist/testing/next.d.ts +1 -4
- package/dist/testing/next.js +2 -7
- package/dist/ui/app.css +5 -16
- package/dist/ui/globals.css +6 -20
- package/dist/ui/icons.d.ts +1 -3
- package/dist/ui/icons.js +3 -10
- package/dist/ui/index.d.ts +4 -12
- package/dist/ui/index.js +4 -12
- package/dist/ui/theme.d.ts +3 -9
- package/dist/ui/theme.js +3 -9
- package/package.json +1 -1
|
@@ -2,13 +2,9 @@ import { createRequire } from "node:module";
|
|
|
2
2
|
import { createServer } from "node:net";
|
|
3
3
|
import { join } from "node:path";
|
|
4
4
|
/**
|
|
5
|
-
* PGlite served over the Postgres wire protocol, so the app's `pg` pool talks to it like any other
|
|
6
|
-
* Postgres. Used by the test helper and a template's dev server.
|
|
5
|
+
* PGlite served over the Postgres wire protocol, so the app's `pg` pool talks to it like any other Postgres. Used by the test helper and a template's dev server.
|
|
7
6
|
*
|
|
8
|
-
* `1` because pglite-socket serialises every connection onto PGlite's single session: with more,
|
|
9
|
-
* one connection's open transaction blocks the others and there is no per-connection isolation.
|
|
10
|
-
* At the limit a second connection is refused outright, so a pool pointed at this server must use
|
|
11
|
-
* `max: PGLITE_MAX_CONNECTIONS` and nothing may open another pool against it.
|
|
7
|
+
* `1` because pglite-socket serialises every connection onto PGlite's single session: with more, one connection's open transaction blocks the others and there is no per-connection isolation. At the limit a second connection is refused outright, so a pool pointed at this server must use `max: PGLITE_MAX_CONNECTIONS` and nothing may open another pool against it.
|
|
12
8
|
*/
|
|
13
9
|
export const PGLITE_MAX_CONNECTIONS = 1;
|
|
14
10
|
async function freePort(host) {
|
package/dist/env/define-env.d.ts
CHANGED
|
@@ -5,9 +5,7 @@ export interface EnvProblem {
|
|
|
5
5
|
problem: string;
|
|
6
6
|
}
|
|
7
7
|
/**
|
|
8
|
-
* Thrown by `defineEnv` with every problem found, not just the first. The message names each bad
|
|
9
|
-
* variable and says what is wrong with it; it never contains a variable's value, because values
|
|
10
|
-
* can be secrets.
|
|
8
|
+
* Thrown by `defineEnv` with every problem found, not just the first. The message names each bad variable and says what is wrong with it; it never contains a variable's value, because values can be secrets.
|
|
11
9
|
*/
|
|
12
10
|
export declare class ConfigError extends Error {
|
|
13
11
|
readonly problems: EnvProblem[];
|
|
@@ -24,12 +22,8 @@ export interface EnvSpec<S extends z.ZodRawShape> {
|
|
|
24
22
|
* Validates `source` (default `process.env`, the only place the package reads it) against `schema`.
|
|
25
23
|
*
|
|
26
24
|
* - Blank values are absent; `<NAME>_FILE` is read when `<NAME>` is unset (both set is an error).
|
|
27
|
-
* - Production requirements are checked against the resolved value before defaults apply, so a
|
|
28
|
-
*
|
|
29
|
-
* - During a Next build (`NEXT_PHASE=phase-production-build`) or with `SKIP_ENV_VALIDATION=1`, a
|
|
30
|
-
* build is not a boot: production requirements, groups and a missing `DATABASE_URL` are not
|
|
31
|
-
* enforced (a placeholder stands in), but defaults still apply. With `NODE_ENV=production`,
|
|
32
|
-
* `SKIP_ENV_VALIDATION` is ignored outside the build phase.
|
|
25
|
+
* - Production requirements are checked against the resolved value before defaults apply, so a development default can never satisfy one.
|
|
26
|
+
* - During a Next build (`NEXT_PHASE=phase-production-build`) or with `SKIP_ENV_VALIDATION=1`, a build is not a boot: production requirements, groups and a missing `DATABASE_URL` are not enforced (a placeholder stands in), but defaults still apply. With `NODE_ENV=production`, `SKIP_ENV_VALIDATION` is ignored outside the build phase.
|
|
33
27
|
* - When the schema has `APP_URL` and it is unset, it is derived on Vercel: from VERCEL_PROJECT_PRODUCTION_URL in production, from VERCEL_BRANCH_URL / VERCEL_URL on a preview, so apps that extend the stack schema get it for free.
|
|
34
28
|
* - Throws one `ConfigError` listing every problem.
|
|
35
29
|
*/
|
package/dist/env/define-env.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import { readFileSync } from "node:fs";
|
|
2
2
|
import { z } from "zod";
|
|
3
3
|
/**
|
|
4
|
-
* Thrown by `defineEnv` with every problem found, not just the first. The message names each bad
|
|
5
|
-
* variable and says what is wrong with it; it never contains a variable's value, because values
|
|
6
|
-
* can be secrets.
|
|
4
|
+
* Thrown by `defineEnv` with every problem found, not just the first. The message names each bad variable and says what is wrong with it; it never contains a variable's value, because values can be secrets.
|
|
7
5
|
*/
|
|
8
6
|
export class ConfigError extends Error {
|
|
9
7
|
problems;
|
|
@@ -20,8 +18,7 @@ const BUILD_PLACEHOLDER_DATABASE_URL = "postgres://unused:unused@127.0.0.1:1/unu
|
|
|
20
18
|
const TRAILING_NEWLINES = /[\r\n]+$/;
|
|
21
19
|
const isBlank = (value) => value === undefined || value.trim() === "";
|
|
22
20
|
/**
|
|
23
|
-
* Resolves one variable: the plain name, else the contents of `<NAME>_FILE`. Blank counts as
|
|
24
|
-
* absent, because `KEY=` in a `.env` file means "not set". Both set is a mistake.
|
|
21
|
+
* Resolves one variable: the plain name, else the contents of `<NAME>_FILE`. Blank counts as absent, because `KEY=` in a `.env` file means "not set". Both set is a mistake.
|
|
25
22
|
*/
|
|
26
23
|
function resolve(name, source, problems) {
|
|
27
24
|
const direct = isBlank(source[name]) ? undefined : source[name];
|
|
@@ -68,12 +65,8 @@ function withVercelAppUrl(source) {
|
|
|
68
65
|
* Validates `source` (default `process.env`, the only place the package reads it) against `schema`.
|
|
69
66
|
*
|
|
70
67
|
* - Blank values are absent; `<NAME>_FILE` is read when `<NAME>` is unset (both set is an error).
|
|
71
|
-
* - Production requirements are checked against the resolved value before defaults apply, so a
|
|
72
|
-
*
|
|
73
|
-
* - During a Next build (`NEXT_PHASE=phase-production-build`) or with `SKIP_ENV_VALIDATION=1`, a
|
|
74
|
-
* build is not a boot: production requirements, groups and a missing `DATABASE_URL` are not
|
|
75
|
-
* enforced (a placeholder stands in), but defaults still apply. With `NODE_ENV=production`,
|
|
76
|
-
* `SKIP_ENV_VALIDATION` is ignored outside the build phase.
|
|
68
|
+
* - Production requirements are checked against the resolved value before defaults apply, so a development default can never satisfy one.
|
|
69
|
+
* - During a Next build (`NEXT_PHASE=phase-production-build`) or with `SKIP_ENV_VALIDATION=1`, a build is not a boot: production requirements, groups and a missing `DATABASE_URL` are not enforced (a placeholder stands in), but defaults still apply. With `NODE_ENV=production`, `SKIP_ENV_VALIDATION` is ignored outside the build phase.
|
|
77
70
|
* - When the schema has `APP_URL` and it is unset, it is derived on Vercel: from VERCEL_PROJECT_PRODUCTION_URL in production, from VERCEL_BRANCH_URL / VERCEL_URL on a preview, so apps that extend the stack schema get it for free.
|
|
78
71
|
* - Throws one `ConfigError` listing every problem.
|
|
79
72
|
*/
|
|
@@ -84,17 +77,14 @@ export function defineEnv(spec, rawSource = process.env) {
|
|
|
84
77
|
for (const name of Object.keys(spec.schema)) {
|
|
85
78
|
resolved[name] = resolve(name, source, problems);
|
|
86
79
|
}
|
|
87
|
-
// SKIP_ENV_VALIDATION is for builds and tooling. A production server that inherited it would
|
|
88
|
-
// boot on development defaults (a public BETTER_AUTH_SECRET), so production honours it only in
|
|
89
|
-
// the build phase.
|
|
80
|
+
// SKIP_ENV_VALIDATION is for builds and tooling. A production server that inherited it would boot on development defaults (a public BETTER_AUTH_SECRET), so production honours it only in the build phase.
|
|
90
81
|
const building = source.NEXT_PHASE === "phase-production-build";
|
|
91
82
|
const skipValidation = building || (source.SKIP_ENV_VALIDATION === "1" && source.NODE_ENV !== "production");
|
|
92
83
|
if (skipValidation && "DATABASE_URL" in spec.schema) {
|
|
93
84
|
resolved.DATABASE_URL ??= BUILD_PLACEHOLDER_DATABASE_URL;
|
|
94
85
|
}
|
|
95
86
|
const parsed = z.object(spec.schema).safeParse(resolved);
|
|
96
|
-
// One problem per variable: a bad `_FILE` also leaves its plain name unset, and a missing
|
|
97
|
-
// production secret may also fail the schema.
|
|
87
|
+
// One problem per variable: a bad `_FILE` also leaves its plain name unset, and a missing production secret may also fail the schema.
|
|
98
88
|
const reported = new Set(problems.flatMap((p) => [p.variable, p.variable.replace(/_FILE$/, "")]));
|
|
99
89
|
if (!parsed.success) {
|
|
100
90
|
for (const issue of parsed.error.issues) {
|
|
@@ -1,15 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Zero-dependency `.env` loader for every entry point Next.js does not boot (drizzle config,
|
|
3
|
-
* test setup, scripts). Rules:
|
|
2
|
+
* Zero-dependency `.env` loader for every entry point Next.js does not boot (drizzle config, test setup, scripts). Rules:
|
|
4
3
|
*
|
|
5
|
-
* - never overrides a variable that is already set: real process env always wins, which is what
|
|
6
|
-
*
|
|
7
|
-
* - never throws when the file is absent, since production supplies real env vars. A file named
|
|
8
|
-
* with `ENV_FILE` is different: the command asked for that file, so a missing one throws rather
|
|
9
|
-
* than surfacing later as some unrelated variable being unset;
|
|
4
|
+
* - never overrides a variable that is already set: real process env always wins, which is what makes this safe on Vercel and in CI;
|
|
5
|
+
* - never throws when the file is absent, since production supplies real env vars. A file named with `ENV_FILE` is different: the command asked for that file, so a missing one throws rather than surfacing later as some unrelated variable being unset;
|
|
10
6
|
* - no interpolation, no `export` keyword handling. Keep `.env` boring.
|
|
11
7
|
*
|
|
12
|
-
* With no `path`, the file is `target.ENV_FILE` if set, else `.env`. A `path` passed explicitly
|
|
13
|
-
* that does not exist is skipped silently; only `ENV_FILE` is treated as an explicit request.
|
|
8
|
+
* With no `path`, the file is `target.ENV_FILE` if set, else `.env`. A `path` passed explicitly that does not exist is skipped silently; only `ENV_FILE` is treated as an explicit request.
|
|
14
9
|
*/
|
|
15
10
|
export declare function loadEnvFile(path?: string, target?: Record<string, string | undefined>): void;
|
|
@@ -1,17 +1,12 @@
|
|
|
1
1
|
import { readFileSync } from "node:fs";
|
|
2
2
|
/**
|
|
3
|
-
* Zero-dependency `.env` loader for every entry point Next.js does not boot (drizzle config,
|
|
4
|
-
* test setup, scripts). Rules:
|
|
3
|
+
* Zero-dependency `.env` loader for every entry point Next.js does not boot (drizzle config, test setup, scripts). Rules:
|
|
5
4
|
*
|
|
6
|
-
* - never overrides a variable that is already set: real process env always wins, which is what
|
|
7
|
-
*
|
|
8
|
-
* - never throws when the file is absent, since production supplies real env vars. A file named
|
|
9
|
-
* with `ENV_FILE` is different: the command asked for that file, so a missing one throws rather
|
|
10
|
-
* than surfacing later as some unrelated variable being unset;
|
|
5
|
+
* - never overrides a variable that is already set: real process env always wins, which is what makes this safe on Vercel and in CI;
|
|
6
|
+
* - never throws when the file is absent, since production supplies real env vars. A file named with `ENV_FILE` is different: the command asked for that file, so a missing one throws rather than surfacing later as some unrelated variable being unset;
|
|
11
7
|
* - no interpolation, no `export` keyword handling. Keep `.env` boring.
|
|
12
8
|
*
|
|
13
|
-
* With no `path`, the file is `target.ENV_FILE` if set, else `.env`. A `path` passed explicitly
|
|
14
|
-
* that does not exist is skipped silently; only `ENV_FILE` is treated as an explicit request.
|
|
9
|
+
* With no `path`, the file is `target.ENV_FILE` if set, else `.env`. A `path` passed explicitly that does not exist is skipped silently; only `ENV_FILE` is treated as an explicit request.
|
|
15
10
|
*/
|
|
16
11
|
export function loadEnvFile(path, target = process.env) {
|
|
17
12
|
const envFile = target.ENV_FILE?.trim() ? target.ENV_FILE : undefined;
|
|
@@ -23,8 +18,7 @@ export function loadEnvFile(path, target = process.env) {
|
|
|
23
18
|
contents = readFileSync(/* turbopackIgnore: true */ file, "utf8");
|
|
24
19
|
}
|
|
25
20
|
catch (error) {
|
|
26
|
-
// Only "not there" is expected (production and CI have no .env); EACCES, EISDIR and the like
|
|
27
|
-
// are real problems and must not look like an absent file.
|
|
21
|
+
// Only "not there" is expected (production and CI have no .env); EACCES, EISDIR and the like are real problems and must not look like an absent file.
|
|
28
22
|
if (error.code !== "ENOENT")
|
|
29
23
|
throw error;
|
|
30
24
|
if (named !== undefined) {
|
package/dist/env/stack-env.d.ts
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import { type EnvSource } from "./define-env.ts";
|
|
3
3
|
/**
|
|
4
|
-
* The variables every stack app shares. Apps extend it:
|
|
5
|
-
* `defineEnv({ schema: { ...stackEnvSchema, MY_VAR: z.string() }, ... })`.
|
|
6
|
-
* Blank values are treated as absent by `defineEnv`, so no field needs its own preprocessing.
|
|
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.
|
|
7
5
|
*/
|
|
8
6
|
export declare const stackEnvSchema: {
|
|
9
7
|
NODE_ENV: z.ZodDefault<z.ZodEnum<{
|
package/dist/env/stack-env.js
CHANGED
|
@@ -2,13 +2,10 @@ import { z } from "zod";
|
|
|
2
2
|
import { defineEnv } from "./define-env.js";
|
|
3
3
|
const count = (fallback) => z.coerce.number().int().positive().default(fallback);
|
|
4
4
|
/**
|
|
5
|
-
* The variables every stack app shares. Apps extend it:
|
|
6
|
-
* `defineEnv({ schema: { ...stackEnvSchema, MY_VAR: z.string() }, ... })`.
|
|
7
|
-
* Blank values are treated as absent by `defineEnv`, so no field needs its own preprocessing.
|
|
5
|
+
* 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.
|
|
8
6
|
*/
|
|
9
7
|
export const stackEnvSchema = {
|
|
10
|
-
// Set by tooling, never by `.env`: next dev/build set it, Vitest sets `test`, Vercel's runtime
|
|
11
|
-
// sets `production`.
|
|
8
|
+
// Set by tooling, never by `.env`: next dev/build set it, Vitest sets `test`, Vercel's runtime sets `production`.
|
|
12
9
|
NODE_ENV: z.enum(["development", "test", "production"]).default("development"),
|
|
13
10
|
APP_URL: z.string().default("http://localhost:3000"),
|
|
14
11
|
DATABASE_URL: z.string().min(1),
|
|
@@ -22,8 +19,7 @@ export const stackEnvSchema = {
|
|
|
22
19
|
EMAIL_FROM: z.string().default("App <no-reply@example.invalid>"),
|
|
23
20
|
MAGIC_LINK_SINK_PATH: z.string().default(".magic-links.log"),
|
|
24
21
|
CRON_SECRET: z.string().optional(),
|
|
25
|
-
// Encrypts connected-account tokens (`@wwchen/stack/connections`): 32 bytes, base64
|
|
26
|
-
// (`openssl rand -base64 32`). Keep it forever: a new key makes every stored token unreadable.
|
|
22
|
+
// Encrypts connected-account tokens (`@wwchen/stack/connections`): 32 bytes, base64 (`openssl rand -base64 32`). Keep it forever: a new key makes every stored token unreadable.
|
|
27
23
|
TOKEN_ENCRYPTION_KEY: z
|
|
28
24
|
.string()
|
|
29
25
|
.refine((v) => Buffer.from(v, "base64").length === 32, {
|
package/dist/env/testing.d.ts
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
/** `TEST_DATABASE_URL`: a real Postgres server for test databases (a CI job's service); else PGlite. */
|
|
2
2
|
export declare function testDatabaseUrl(source?: Record<string, string | undefined>): string | undefined;
|
|
3
3
|
/**
|
|
4
|
-
* Points DATABASE_URL at a closed port before anything loads `.env`: an env loader never overrides
|
|
5
|
-
* a variable that is already set, so `.env`, which may name a real, remote database, cannot reach a
|
|
6
|
-
* test. A test that needs a database starts its own.
|
|
4
|
+
* Points DATABASE_URL at a closed port before anything loads `.env`: an env loader never overrides a variable that is already set, so `.env`, which may name a real, remote database, cannot reach a test. A test that needs a database starts its own.
|
|
7
5
|
*/
|
|
8
6
|
export declare function isolateTestEnv(target?: Record<string, string | undefined>): void;
|
package/dist/env/testing.js
CHANGED
|
@@ -1,14 +1,11 @@
|
|
|
1
|
-
// The environment the test helpers (`@wwchen/stack/db/testing`) read and write, kept here so that
|
|
2
|
-
// src/env/ stays the one place in the package that touches `process.env`.
|
|
1
|
+
// The environment the test helpers (`@wwchen/stack/db/testing`) read and write, kept here so that src/env/ stays the one place in the package that touches `process.env`.
|
|
3
2
|
/** `TEST_DATABASE_URL`: a real Postgres server for test databases (a CI job's service); else PGlite. */
|
|
4
3
|
export function testDatabaseUrl(source = process.env) {
|
|
5
4
|
const url = source.TEST_DATABASE_URL?.trim();
|
|
6
5
|
return url ? url : undefined;
|
|
7
6
|
}
|
|
8
7
|
/**
|
|
9
|
-
* Points DATABASE_URL at a closed port before anything loads `.env`: an env loader never overrides
|
|
10
|
-
* a variable that is already set, so `.env`, which may name a real, remote database, cannot reach a
|
|
11
|
-
* test. A test that needs a database starts its own.
|
|
8
|
+
* Points DATABASE_URL at a closed port before anything loads `.env`: an env loader never overrides a variable that is already set, so `.env`, which may name a real, remote database, cannot reach a test. A test that needs a database starts its own.
|
|
12
9
|
*/
|
|
13
10
|
export function isolateTestEnv(target = process.env) {
|
|
14
11
|
target.DATABASE_URL = "postgres://unused:unused@127.0.0.1:1/unused";
|
package/dist/http/client-ip.d.ts
CHANGED
|
@@ -1,12 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Who the caller is, read from standard forwarded headers in this one place. No vendor-specific
|
|
3
|
-
* header (Cloudflare's, Vercel's) is read: the proxy in front of the app is infrastructure, and
|
|
4
|
-
* `X-Forwarded-For` already carries the value.
|
|
2
|
+
* Who the caller is, read from standard forwarded headers in this one place. No vendor-specific header (Cloudflare's, Vercel's) is read: the proxy in front of the app is infrastructure, and `X-Forwarded-For` already carries the value.
|
|
5
3
|
*
|
|
6
|
-
* The client is the first entry a trusted proxy did not add: with `hops` trusted proxies in front,
|
|
7
|
-
* the Nth-from-last entry in `X-Forwarded-For`. Trusting the *first* entry instead is the classic
|
|
8
|
-
* spoof — a caller can send any `X-Forwarded-For` they like, and only the entries the proxies
|
|
9
|
-
* themselves appended can be believed. Hence counting from the right. Vercel terminates the chain
|
|
10
|
-
* itself, so `hops` is 0 there.
|
|
4
|
+
* The client is the first entry a trusted proxy did not add: with `hops` trusted proxies in front, the Nth-from-last entry in `X-Forwarded-For`. Trusting the *first* entry instead is the classic spoof — a caller can send any `X-Forwarded-For` they like, and only the entries the proxies themselves appended can be believed. Hence counting from the right. Vercel terminates the chain itself, so `hops` is 0 there.
|
|
11
5
|
*/
|
|
12
6
|
export declare function clientIp(headers: Headers, hops: number): string | null;
|
package/dist/http/client-ip.js
CHANGED
|
@@ -1,13 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Who the caller is, read from standard forwarded headers in this one place. No vendor-specific
|
|
3
|
-
* header (Cloudflare's, Vercel's) is read: the proxy in front of the app is infrastructure, and
|
|
4
|
-
* `X-Forwarded-For` already carries the value.
|
|
2
|
+
* Who the caller is, read from standard forwarded headers in this one place. No vendor-specific header (Cloudflare's, Vercel's) is read: the proxy in front of the app is infrastructure, and `X-Forwarded-For` already carries the value.
|
|
5
3
|
*
|
|
6
|
-
* The client is the first entry a trusted proxy did not add: with `hops` trusted proxies in front,
|
|
7
|
-
* the Nth-from-last entry in `X-Forwarded-For`. Trusting the *first* entry instead is the classic
|
|
8
|
-
* spoof — a caller can send any `X-Forwarded-For` they like, and only the entries the proxies
|
|
9
|
-
* themselves appended can be believed. Hence counting from the right. Vercel terminates the chain
|
|
10
|
-
* itself, so `hops` is 0 there.
|
|
4
|
+
* The client is the first entry a trusted proxy did not add: with `hops` trusted proxies in front, the Nth-from-last entry in `X-Forwarded-For`. Trusting the *first* entry instead is the classic spoof — a caller can send any `X-Forwarded-For` they like, and only the entries the proxies themselves appended can be believed. Hence counting from the right. Vercel terminates the chain itself, so `hops` is 0 there.
|
|
11
5
|
*/
|
|
12
6
|
export function clientIp(headers, hops) {
|
|
13
7
|
const forwarded = headers.get("x-forwarded-for");
|
|
@@ -17,8 +11,7 @@ export function clientIp(headers, hops) {
|
|
|
17
11
|
.map((entry) => entry.trim())
|
|
18
12
|
.filter((entry) => entry.length > 0);
|
|
19
13
|
if (entries.length > 0) {
|
|
20
|
-
// Clamped: a request that arrived with fewer hops than configured is not a reason to return
|
|
21
|
-
// nothing, and the left-most entry is the best remaining guess.
|
|
14
|
+
// Clamped: a request that arrived with fewer hops than configured is not a reason to return nothing, and the left-most entry is the best remaining guess.
|
|
22
15
|
const index = Math.max(entries.length - 1 - hops, 0);
|
|
23
16
|
return entries[index];
|
|
24
17
|
}
|
package/dist/http/guards.d.ts
CHANGED
|
@@ -3,21 +3,14 @@ export declare function isMutation(request: Request): boolean;
|
|
|
3
3
|
/** `application/json`, with or without parameters (`; charset=utf-8`). */
|
|
4
4
|
export declare function isJsonRequest(request: Request): boolean;
|
|
5
5
|
/**
|
|
6
|
-
* A request that carries no body: no `Content-Type`, and no `Content-Length` (or `0`) and no chunked
|
|
7
|
-
* transfer. `fetch(url, { method: "DELETE" })` sends exactly that. A browser form always sends a
|
|
8
|
-
* `Content-Type`, so a body-less request can never be a cross-site form post.
|
|
6
|
+
* A request that carries no body: no `Content-Type`, and no `Content-Length` (or `0`) and no chunked transfer. `fetch(url, { method: "DELETE" })` sends exactly that. A browser form always sends a `Content-Type`, so a body-less request can never be a cross-site form post.
|
|
9
7
|
*/
|
|
10
8
|
export declare function hasNoBody(request: Request): boolean;
|
|
11
9
|
/**
|
|
12
|
-
* Whether a mutation came from this app's own pages. Browsers attach `Origin` to every cross-origin
|
|
13
|
-
* and every non-GET request, so it is compared with the host the request was addressed to (the
|
|
14
|
-
* host, not the scheme: a proxy that ends TLS makes the scheme the app sees untrue). Without
|
|
15
|
-
* `Origin`, `Sec-Fetch-Site` decides. A request with neither is not from a browser page, and a
|
|
16
|
-
* session cookie must not ride on it, so it is refused.
|
|
10
|
+
* Whether a mutation came from this app's own pages. Browsers attach `Origin` to every cross-origin and every non-GET request, so it is compared with the host the request was addressed to (the host, not the scheme: a proxy that ends TLS makes the scheme the app sees untrue). Without `Origin`, `Sec-Fetch-Site` decides. A request with neither is not from a browser page, and a session cookie must not ride on it, so it is refused.
|
|
17
11
|
*/
|
|
18
12
|
export declare function isSameOrigin(request: Request): boolean;
|
|
19
13
|
/**
|
|
20
|
-
* Whether `Authorization` is `Bearer <secret>`. An unset or empty secret matches nothing, so
|
|
21
|
-
* `Bearer undefined` is never accepted. The comparison is constant-time.
|
|
14
|
+
* Whether `Authorization` is `Bearer <secret>`. An unset or empty secret matches nothing, so `Bearer undefined` is never accepted. The comparison is constant-time.
|
|
22
15
|
*/
|
|
23
16
|
export declare function bearerMatches(request: Request, secret: string | undefined): boolean;
|
package/dist/http/guards.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { timingSafeEqual } from "node:crypto";
|
|
2
2
|
/**
|
|
3
|
-
* Request guards shared by the API wrapper, the cron route and the health route. Pure functions of
|
|
4
|
-
* a `Request`: none reads the environment or the database.
|
|
3
|
+
* Request guards shared by the API wrapper, the cron route and the health route. Pure functions of a `Request`: none reads the environment or the database.
|
|
5
4
|
*/
|
|
6
5
|
const SAFE_METHODS = new Set(["GET", "HEAD", "OPTIONS"]);
|
|
7
6
|
/** A method that can change state: everything but GET, HEAD and OPTIONS. */
|
|
@@ -14,9 +13,7 @@ export function isJsonRequest(request) {
|
|
|
14
13
|
return type === "application/json";
|
|
15
14
|
}
|
|
16
15
|
/**
|
|
17
|
-
* A request that carries no body: no `Content-Type`, and no `Content-Length` (or `0`) and no chunked
|
|
18
|
-
* transfer. `fetch(url, { method: "DELETE" })` sends exactly that. A browser form always sends a
|
|
19
|
-
* `Content-Type`, so a body-less request can never be a cross-site form post.
|
|
16
|
+
* A request that carries no body: no `Content-Type`, and no `Content-Length` (or `0`) and no chunked transfer. `fetch(url, { method: "DELETE" })` sends exactly that. A browser form always sends a `Content-Type`, so a body-less request can never be a cross-site form post.
|
|
20
17
|
*/
|
|
21
18
|
export function hasNoBody(request) {
|
|
22
19
|
if (request.headers.get("content-type") !== null)
|
|
@@ -42,11 +39,7 @@ function servedHost(request) {
|
|
|
42
39
|
return forwarded || request.headers.get("host") || new URL(request.url).host;
|
|
43
40
|
}
|
|
44
41
|
/**
|
|
45
|
-
* Whether a mutation came from this app's own pages. Browsers attach `Origin` to every cross-origin
|
|
46
|
-
* and every non-GET request, so it is compared with the host the request was addressed to (the
|
|
47
|
-
* host, not the scheme: a proxy that ends TLS makes the scheme the app sees untrue). Without
|
|
48
|
-
* `Origin`, `Sec-Fetch-Site` decides. A request with neither is not from a browser page, and a
|
|
49
|
-
* session cookie must not ride on it, so it is refused.
|
|
42
|
+
* Whether a mutation came from this app's own pages. Browsers attach `Origin` to every cross-origin and every non-GET request, so it is compared with the host the request was addressed to (the host, not the scheme: a proxy that ends TLS makes the scheme the app sees untrue). Without `Origin`, `Sec-Fetch-Site` decides. A request with neither is not from a browser page, and a session cookie must not ride on it, so it is refused.
|
|
50
43
|
*/
|
|
51
44
|
export function isSameOrigin(request) {
|
|
52
45
|
const origin = request.headers.get("origin");
|
|
@@ -55,8 +48,7 @@ export function isSameOrigin(request) {
|
|
|
55
48
|
return request.headers.get("sec-fetch-site") === "same-origin";
|
|
56
49
|
}
|
|
57
50
|
/**
|
|
58
|
-
* Whether `Authorization` is `Bearer <secret>`. An unset or empty secret matches nothing, so
|
|
59
|
-
* `Bearer undefined` is never accepted. The comparison is constant-time.
|
|
51
|
+
* Whether `Authorization` is `Bearer <secret>`. An unset or empty secret matches nothing, so `Bearer undefined` is never accepted. The comparison is constant-time.
|
|
60
52
|
*/
|
|
61
53
|
export function bearerMatches(request, secret) {
|
|
62
54
|
if (!secret)
|
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Past this many buckets, a new one first sweeps out every expired bucket. A caller can invent
|
|
3
|
-
* paths (every `/api/auth/<anything>` is counted), so the store must not only grow; a live bucket
|
|
4
|
-
* is never swept, so sweeping cannot hand anyone a fresh budget.
|
|
2
|
+
* Past this many buckets, a new one first sweeps out every expired bucket. A caller can invent paths (every `/api/auth/<anything>` is counted), so the store must not only grow; a live bucket is never swept, so sweeping cannot hand anyone a fresh budget.
|
|
5
3
|
*/
|
|
6
4
|
export declare const RATE_LIMIT_SWEEP_AT = 10000;
|
|
7
5
|
/**
|
|
8
|
-
* A sweep walks the whole store, and past the cap with every bucket live it frees nothing, so the
|
|
9
|
-
* next request would walk it again: at most one sweep per interval keeps that off every request.
|
|
6
|
+
* A sweep walks the whole store, and past the cap with every bucket live it frees nothing, so the next request would walk it again: at most one sweep per interval keeps that off every request.
|
|
10
7
|
*/
|
|
11
8
|
export declare const RATE_LIMIT_SWEEP_INTERVAL_MS: number;
|
|
12
9
|
export declare function rateLimitStoreSize(): number;
|
|
@@ -24,11 +21,8 @@ export type RateLimitInput = {
|
|
|
24
21
|
now?: number;
|
|
25
22
|
};
|
|
26
23
|
/**
|
|
27
|
-
* Answers a **429 with `Retry-After`** when this caller has used up `limit` on `path` within the
|
|
28
|
-
* hour, and null — meaning "carry on" — every other time.
|
|
24
|
+
* Answers a **429 with `Retry-After`** when this caller has used up `limit` on `path` within the hour, and null — meaning "carry on" — every other time.
|
|
29
25
|
*
|
|
30
|
-
* Returning a Response rather than throwing keeps the decision at the edge: the caller writes
|
|
31
|
-
* `const limited = rateLimit(...); if (limited) return limited;`. The body is the
|
|
32
|
-
* `{ error: { code, message } }` envelope every API error uses.
|
|
26
|
+
* Returning a Response rather than throwing keeps the decision at the edge: the caller writes `const limited = rateLimit(...); if (limited) return limited;`. The body is the `{ error: { code, message } }` envelope every API error uses.
|
|
33
27
|
*/
|
|
34
28
|
export declare function rateLimit(input: RateLimitInput): Response | null;
|
package/dist/http/rate-limit.js
CHANGED
|
@@ -2,28 +2,21 @@ import { clientIp } from "./client-ip.js";
|
|
|
2
2
|
/**
|
|
3
3
|
* How often a caller may knock: a fixed hourly budget per client address per path.
|
|
4
4
|
*
|
|
5
|
-
* This is the stack's own limiter, independent of Better Auth's internal one, because sign-in runs
|
|
6
|
-
* in-process from server actions that no route limit sees. The app sets the budget; an infinite
|
|
7
|
-
* budget turns the limiter off and allocates nothing (development and tests then need no store).
|
|
5
|
+
* This is the stack's own limiter, independent of Better Auth's internal one, because sign-in runs in-process from server actions that no route limit sees. The app sets the budget; an infinite budget turns the limiter off and allocates nothing (development and tests then need no store).
|
|
8
6
|
*/
|
|
9
7
|
const WINDOW_MS = 60 * 60 * 1000;
|
|
10
8
|
/**
|
|
11
9
|
* Created lazily, so a process that never limits never allocates it.
|
|
12
10
|
*
|
|
13
|
-
* An in-process counter is correct for exactly **one** app instance: each serverless instance
|
|
14
|
-
* counts separately. That is tolerable for invite-only sign-in; scaling out for real means moving
|
|
15
|
-
* this to a shared store.
|
|
11
|
+
* An in-process counter is correct for exactly **one** app instance: each serverless instance counts separately. That is tolerable for invite-only sign-in; scaling out for real means moving this to a shared store.
|
|
16
12
|
*/
|
|
17
13
|
let buckets = null;
|
|
18
14
|
/**
|
|
19
|
-
* Past this many buckets, a new one first sweeps out every expired bucket. A caller can invent
|
|
20
|
-
* paths (every `/api/auth/<anything>` is counted), so the store must not only grow; a live bucket
|
|
21
|
-
* is never swept, so sweeping cannot hand anyone a fresh budget.
|
|
15
|
+
* Past this many buckets, a new one first sweeps out every expired bucket. A caller can invent paths (every `/api/auth/<anything>` is counted), so the store must not only grow; a live bucket is never swept, so sweeping cannot hand anyone a fresh budget.
|
|
22
16
|
*/
|
|
23
17
|
export const RATE_LIMIT_SWEEP_AT = 10_000;
|
|
24
18
|
/**
|
|
25
|
-
* A sweep walks the whole store, and past the cap with every bucket live it frees nothing, so the
|
|
26
|
-
* next request would walk it again: at most one sweep per interval keeps that off every request.
|
|
19
|
+
* A sweep walks the whole store, and past the cap with every bucket live it frees nothing, so the next request would walk it again: at most one sweep per interval keeps that off every request.
|
|
27
20
|
*/
|
|
28
21
|
export const RATE_LIMIT_SWEEP_INTERVAL_MS = 60 * 1000;
|
|
29
22
|
let lastSweep = Number.NEGATIVE_INFINITY;
|
|
@@ -44,12 +37,9 @@ export function resetRateLimits() {
|
|
|
44
37
|
lastSweep = Number.NEGATIVE_INFINITY;
|
|
45
38
|
}
|
|
46
39
|
/**
|
|
47
|
-
* Answers a **429 with `Retry-After`** when this caller has used up `limit` on `path` within the
|
|
48
|
-
* hour, and null — meaning "carry on" — every other time.
|
|
40
|
+
* Answers a **429 with `Retry-After`** when this caller has used up `limit` on `path` within the hour, and null — meaning "carry on" — every other time.
|
|
49
41
|
*
|
|
50
|
-
* Returning a Response rather than throwing keeps the decision at the edge: the caller writes
|
|
51
|
-
* `const limited = rateLimit(...); if (limited) return limited;`. The body is the
|
|
52
|
-
* `{ error: { code, message } }` envelope every API error uses.
|
|
42
|
+
* Returning a Response rather than throwing keeps the decision at the edge: the caller writes `const limited = rateLimit(...); if (limited) return limited;`. The body is the `{ error: { code, message } }` envelope every API error uses.
|
|
53
43
|
*/
|
|
54
44
|
export function rateLimit(input) {
|
|
55
45
|
if (!Number.isFinite(input.limit))
|
|
@@ -58,9 +48,7 @@ export function rateLimit(input) {
|
|
|
58
48
|
const now = input.now ?? Date.now();
|
|
59
49
|
buckets ??= new Map();
|
|
60
50
|
/**
|
|
61
|
-
* **One bucket per caller PER PATH, not per caller for the whole auth surface.** Following a
|
|
62
|
-
* magic link is a GET under the same prefix as asking for one; a shared bucket would let
|
|
63
|
-
* requesting ten links and clicking them lock the caller out for an hour.
|
|
51
|
+
* **One bucket per caller PER PATH, not per caller for the whole auth surface.** Following a magic link is a GET under the same prefix as asking for one; a shared bucket would let requesting ten links and clicking them lock the caller out for an hour.
|
|
64
52
|
*/
|
|
65
53
|
const key = `${caller}:${input.path}`;
|
|
66
54
|
const bucket = buckets.get(key);
|
package/dist/jobs/index.d.ts
CHANGED
|
@@ -1,12 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Helpers for scheduled jobs that work for many people (one run does the work for everyone).
|
|
3
3
|
*
|
|
4
|
-
* **Alert on new failures only.** An uptime monitor that calls the job alerts when it answers 500.
|
|
5
|
-
* If every failure answered 500, one person whose runs keep failing would hold the monitor down for
|
|
6
|
-
* good, and the next person to break would raise no alert. So a failure counts as *new* for its
|
|
7
|
-
* first `ALERT_FOR_HOURS` (24h) and the job answers 500 only while someone's failure is new
|
|
8
|
-
* (`cronRoute` does that when the job returns `alerting: true`). The person stays marked failing in
|
|
9
|
-
* the app until fixed; the monitor recovers and is free to alert on the next streak.
|
|
4
|
+
* **Alert on new failures only.** An uptime monitor that calls the job alerts when it answers 500. If every failure answered 500, one person whose runs keep failing would hold the monitor down for good, and the next person to break would raise no alert. So a failure counts as *new* for its first `ALERT_FOR_HOURS` (24h) and the job answers 500 only while someone's failure is new (`cronRoute` does that when the job returns `alerting: true`). The person stays marked failing in the app until fixed; the monitor recovers and is free to alert on the next streak.
|
|
10
5
|
*/
|
|
11
6
|
export declare const ALERT_FOR_HOURS = 24;
|
|
12
7
|
type Timestamp = string | Date;
|
|
@@ -17,9 +12,7 @@ export type RunOutcome = {
|
|
|
17
12
|
failingSince?: Timestamp | null;
|
|
18
13
|
};
|
|
19
14
|
/**
|
|
20
|
-
* When `run`'s failure streak began: the previous run's streak start when that one failed too,
|
|
21
|
-
* otherwise `run` itself. Null for a successful run. `previous` is the person's run before this
|
|
22
|
-
* one.
|
|
15
|
+
* When `run`'s failure streak began: the previous run's streak start when that one failed too, otherwise `run` itself. Null for a successful run. `previous` is the person's run before this one.
|
|
23
16
|
*/
|
|
24
17
|
export declare function failingSince(run: {
|
|
25
18
|
ok: boolean;
|
package/dist/jobs/index.js
CHANGED
|
@@ -1,20 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Helpers for scheduled jobs that work for many people (one run does the work for everyone).
|
|
3
3
|
*
|
|
4
|
-
* **Alert on new failures only.** An uptime monitor that calls the job alerts when it answers 500.
|
|
5
|
-
* If every failure answered 500, one person whose runs keep failing would hold the monitor down for
|
|
6
|
-
* good, and the next person to break would raise no alert. So a failure counts as *new* for its
|
|
7
|
-
* first `ALERT_FOR_HOURS` (24h) and the job answers 500 only while someone's failure is new
|
|
8
|
-
* (`cronRoute` does that when the job returns `alerting: true`). The person stays marked failing in
|
|
9
|
-
* the app until fixed; the monitor recovers and is free to alert on the next streak.
|
|
4
|
+
* **Alert on new failures only.** An uptime monitor that calls the job alerts when it answers 500. If every failure answered 500, one person whose runs keep failing would hold the monitor down for good, and the next person to break would raise no alert. So a failure counts as *new* for its first `ALERT_FOR_HOURS` (24h) and the job answers 500 only while someone's failure is new (`cronRoute` does that when the job returns `alerting: true`). The person stays marked failing in the app until fixed; the monitor recovers and is free to alert on the next streak.
|
|
10
5
|
*/
|
|
11
6
|
export const ALERT_FOR_HOURS = 24;
|
|
12
7
|
const ms = (t) => (typeof t === "string" ? Date.parse(t) : t.getTime());
|
|
13
8
|
const iso = (t) => (typeof t === "string" ? t : t.toISOString());
|
|
14
9
|
/**
|
|
15
|
-
* When `run`'s failure streak began: the previous run's streak start when that one failed too,
|
|
16
|
-
* otherwise `run` itself. Null for a successful run. `previous` is the person's run before this
|
|
17
|
-
* one.
|
|
10
|
+
* When `run`'s failure streak began: the previous run's streak start when that one failed too, otherwise `run` itself. Null for a successful run. `previous` is the person's run before this one.
|
|
18
11
|
*/
|
|
19
12
|
export function failingSince(run, previous) {
|
|
20
13
|
if (run.ok)
|
package/dist/mail/index.d.ts
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* The one way an app sends mail, and sign-in is the only mail it sends.
|
|
3
3
|
*
|
|
4
|
-
* Production posts to Resend's HTTP API with `fetch` — no SDK, one request. Everywhere else nothing
|
|
5
|
-
* is sent: the first URL in the text is appended, one per line, to the sink file, which is what
|
|
6
|
-
* lets development, the tests and e2e sign in with no mail account and no network. The sink never
|
|
7
|
-
* holds the body or the address.
|
|
4
|
+
* Production posts to Resend's HTTP API with `fetch` — no SDK, one request. Everywhere else nothing is sent: the first URL in the text is appended, one per line, to the sink file, which is what lets development, the tests and e2e sign in with no mail account and no network. The sink never holds the body or the address.
|
|
8
5
|
*/
|
|
9
6
|
export type Mail = {
|
|
10
7
|
to: string;
|
|
@@ -27,11 +24,7 @@ export declare function createMailer(opts: MailerOptions): Mailer;
|
|
|
27
24
|
/**
|
|
28
25
|
* Production sends through Resend; every other environment uses the sink.
|
|
29
26
|
*
|
|
30
|
-
* A production run without `RESEND_API_KEY` or `EMAIL_FROM` gets a mailer that refuses every send,
|
|
31
|
-
* naming the missing variable, rather than a throw here: `next build` evaluates the app's mail
|
|
32
|
-
* module with `NODE_ENV=production` and no secrets (a build skips env validation), and must not
|
|
33
|
-
* fail on it. A booted production app never gets this far without them: the stack's env requires
|
|
34
|
-
* both in production.
|
|
27
|
+
* A production run without `RESEND_API_KEY` or `EMAIL_FROM` gets a mailer that refuses every send, naming the missing variable, rather than a throw here: `next build` evaluates the app's mail module with `NODE_ENV=production` and no secrets (a build skips env validation), and must not fail on it. A booted production app never gets this far without them: the stack's env requires both in production.
|
|
35
28
|
*/
|
|
36
29
|
export declare function mailerFromEnv(env: {
|
|
37
30
|
NODE_ENV: string;
|
package/dist/mail/index.js
CHANGED
|
@@ -34,11 +34,7 @@ export function createMailer(opts) {
|
|
|
34
34
|
/**
|
|
35
35
|
* Production sends through Resend; every other environment uses the sink.
|
|
36
36
|
*
|
|
37
|
-
* A production run without `RESEND_API_KEY` or `EMAIL_FROM` gets a mailer that refuses every send,
|
|
38
|
-
* naming the missing variable, rather than a throw here: `next build` evaluates the app's mail
|
|
39
|
-
* module with `NODE_ENV=production` and no secrets (a build skips env validation), and must not
|
|
40
|
-
* fail on it. A booted production app never gets this far without them: the stack's env requires
|
|
41
|
-
* both in production.
|
|
37
|
+
* A production run without `RESEND_API_KEY` or `EMAIL_FROM` gets a mailer that refuses every send, naming the missing variable, rather than a throw here: `next build` evaluates the app's mail module with `NODE_ENV=production` and no secrets (a build skips env validation), and must not fail on it. A booted production app never gets this far without them: the stack's env requires both in production.
|
|
42
38
|
*/
|
|
43
39
|
export function mailerFromEnv(env) {
|
|
44
40
|
if (env.NODE_ENV !== "production") {
|
|
@@ -56,8 +52,7 @@ export function mailerFromEnv(env) {
|
|
|
56
52
|
return createMailer({ mode: "resend", apiKey, from });
|
|
57
53
|
}
|
|
58
54
|
/**
|
|
59
|
-
* Resend's `{ name, message }` as " name: message", or "" for any other body. The caller logs it,
|
|
60
|
-
* and Resend's message can echo the recipient, so every email address in it is redacted.
|
|
55
|
+
* Resend's `{ name, message }` as " name: message", or "" for any other body. The caller logs it, and Resend's message can echo the recipient, so every email address in it is redacted.
|
|
61
56
|
*/
|
|
62
57
|
async function refusalReason(response) {
|
|
63
58
|
try {
|
package/dist/next/api.d.ts
CHANGED
|
@@ -1,16 +1,11 @@
|
|
|
1
1
|
import type { StackAuth } from "../auth/index.ts";
|
|
2
2
|
import type { Session } from "../auth/types.ts";
|
|
3
3
|
/**
|
|
4
|
-
* The shell every API route runs in: session, admin check, the request guards, the handler, and
|
|
5
|
-
* the envelope for whatever it throws. Written once so route files cannot drift on it.
|
|
4
|
+
* The shell every API route runs in: session, admin check, the request guards, the handler, and the envelope for whatever it throws. Written once so route files cannot drift on it.
|
|
6
5
|
*
|
|
7
|
-
* Every failure answers `{ error: { code, message } }`. An `ApiError` is answered as it says; that
|
|
8
|
-
* is how `readJson` reports the request body (400 `invalid_json`, 422 `invalid_input`). Anything
|
|
9
|
-
* else is a bug, even a SyntaxError or a ZodError from the route's own code, and becomes a 500 with
|
|
10
|
-
* a fixed message: what was thrown is logged for the operator and never sent to the caller.
|
|
6
|
+
* Every failure answers `{ error: { code, message } }`. An `ApiError` is answered as it says; that is how `readJson` reports the request body (400 `invalid_json`, 422 `invalid_input`). Anything else is a bug, even a SyntaxError or a ZodError from the route's own code, and becomes a 500 with a fixed message: what was thrown is logged for the operator and never sent to the caller.
|
|
11
7
|
*
|
|
12
|
-
* `CRON_SECRET` and `HEALTH_TOKEN` are never read here. This wrapper accepts a session and nothing
|
|
13
|
-
* else, so neither secret opens an API route.
|
|
8
|
+
* `CRON_SECRET` and `HEALTH_TOKEN` are never read here. This wrapper accepts a session and nothing else, so neither secret opens an API route.
|
|
14
9
|
*/
|
|
15
10
|
/** An error a route throws on purpose: its message is written for the caller and is sent as is. */
|
|
16
11
|
export declare class ApiError extends Error {
|
|
@@ -33,16 +28,13 @@ export declare class NotFoundError extends ApiError {
|
|
|
33
28
|
constructor(message?: string);
|
|
34
29
|
}
|
|
35
30
|
/**
|
|
36
|
-
* A path id that is not a uuid: the same 404 a missing row gets, but told apart from one so a
|
|
37
|
-
* route that surfaces its own not-found message never surfaces this one.
|
|
31
|
+
* A path id that is not a uuid: the same 404 a missing row gets, but told apart from one so a route that surfaces its own not-found message never surfaces this one.
|
|
38
32
|
*/
|
|
39
33
|
export declare class PathIdError extends NotFoundError {
|
|
40
34
|
constructor();
|
|
41
35
|
}
|
|
42
36
|
/**
|
|
43
|
-
* A path id, or a `PathIdError` for the wrapper to answer. Anything that is not a uuid cannot name
|
|
44
|
-
* a row, so it is the same 404 a missing row gets, answered before the query: Postgres would
|
|
45
|
-
* otherwise reject the cast and turn a typo'd URL into a 500.
|
|
37
|
+
* A path id, or a `PathIdError` for the wrapper to answer. Anything that is not a uuid cannot name a row, so it is the same 404 a missing row gets, answered before the query: Postgres would otherwise reject the cast and turn a typo'd URL into a 500.
|
|
46
38
|
*/
|
|
47
39
|
export declare function requirePathId(value: string): string;
|
|
48
40
|
export declare function apiError(status: number, code: string, message: string, details?: {
|
|
@@ -54,10 +46,7 @@ export type BodySchema<T> = {
|
|
|
54
46
|
parse(input: unknown): T;
|
|
55
47
|
};
|
|
56
48
|
/**
|
|
57
|
-
* The request's JSON body, parsed by `schema` when one is given. A body that is not JSON throws a
|
|
58
|
-
* 400 `invalid_json`; one the schema rejects, a 422 `invalid_input` whose `details` list each
|
|
59
|
-
* issue's path and message (never the input's values). Both are `ApiError`s for `apiHandler` to
|
|
60
|
-
* answer. Anything else thrown, by the schema's own transforms for one, passes through as a bug.
|
|
49
|
+
* The request's JSON body, parsed by `schema` when one is given. A body that is not JSON throws a 400 `invalid_json`; one the schema rejects, a 422 `invalid_input` whose `details` list each issue's path and message (never the input's values). Both are `ApiError`s for `apiHandler` to answer. Anything else thrown, by the schema's own transforms for one, passes through as a bug.
|
|
61
50
|
*/
|
|
62
51
|
export declare function readJson(req: Request): Promise<unknown>;
|
|
63
52
|
export declare function readJson<T>(req: Request, schema: BodySchema<T>): Promise<T>;
|