@wwchen/stack 0.6.3 → 0.7.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 +9 -8
- package/blocks/env.example +1 -2
- package/dist/auth/better-auth/index.d.ts +2 -316
- package/dist/auth/better-auth/index.js +2 -237
- package/dist/auth/index.d.ts +2 -58
- package/dist/auth/index.js +2 -120
- package/dist/auth/proxy.d.ts +2 -14
- package/dist/auth/proxy.js +2 -50
- package/dist/cli/context.d.ts +6 -3
- package/dist/cli/context.js +3 -0
- package/dist/cli/db.d.ts +3 -0
- package/dist/cli/db.js +26 -0
- package/dist/cli/index.js +14 -3
- package/dist/cli/migrate-suite.d.ts +2 -0
- package/dist/cli/migrate-suite.js +787 -0
- 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 +3 -9
- package/dist/connections/providers.d.ts +1 -3
- package/dist/connections/table.d.ts +2 -3
- 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/schema-changes.d.ts +13 -0
- package/dist/db/schema-changes.js +99 -0
- 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/guards.d.ts +3 -10
- package/dist/http/guards.js +4 -12
- package/dist/jobs/index.d.ts +2 -9
- package/dist/jobs/index.js +2 -9
- package/dist/mail/index.d.ts +4 -45
- package/dist/mail/index.js +4 -97
- package/dist/next/api.d.ts +7 -19
- 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 +15 -9
- package/dist/auth/better-auth/tables.d.ts +0 -628
- package/dist/auth/better-auth/tables.js +0 -76
- package/dist/auth/better-auth/users.d.ts +0 -27
- package/dist/auth/better-auth/users.js +0 -128
- package/dist/auth/safe-next.d.ts +0 -17
- package/dist/auth/safe-next.js +0 -36
- package/dist/auth/types.d.ts +0 -47
- package/dist/auth/types.js +0 -5
- package/dist/http/client-ip.d.ts +0 -12
- package/dist/http/client-ip.js +0 -28
- package/dist/http/rate-limit.d.ts +0 -34
- package/dist/http/rate-limit.js +0 -79
package/dist/mail/index.d.ts
CHANGED
|
@@ -1,45 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
*
|
|
3
|
-
|
|
4
|
-
|
|
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.
|
|
8
|
-
*/
|
|
9
|
-
export type Mail = {
|
|
10
|
-
to: string;
|
|
11
|
-
subject: string;
|
|
12
|
-
text: string;
|
|
13
|
-
};
|
|
14
|
-
export type Mailer = {
|
|
15
|
-
send(m: Mail): Promise<void>;
|
|
16
|
-
};
|
|
17
|
-
export type MailerOptions = {
|
|
18
|
-
mode: "resend";
|
|
19
|
-
apiKey: string;
|
|
20
|
-
from: string;
|
|
21
|
-
fetch?: typeof fetch;
|
|
22
|
-
} | {
|
|
23
|
-
mode: "sink";
|
|
24
|
-
sinkPath: string;
|
|
25
|
-
};
|
|
26
|
-
export declare function createMailer(opts: MailerOptions): Mailer;
|
|
27
|
-
/**
|
|
28
|
-
* Production sends through Resend; every other environment uses the sink.
|
|
29
|
-
*
|
|
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.
|
|
35
|
-
*/
|
|
36
|
-
export declare function mailerFromEnv(env: {
|
|
37
|
-
NODE_ENV: string;
|
|
38
|
-
RESEND_API_KEY?: string | undefined;
|
|
39
|
-
EMAIL_FROM?: string | undefined;
|
|
40
|
-
MAGIC_LINK_SINK_PATH: string;
|
|
41
|
-
}): Mailer;
|
|
42
|
-
/** How many links the sink holds now; take it before the request that should add one. */
|
|
43
|
-
export declare function countSinkLines(sinkPath: string): number;
|
|
44
|
-
/** The first link after line `afterLine` (a count from `countSinkLines`), polling until `timeoutMs`. */
|
|
45
|
-
export declare function waitForMagicLink(sinkPath: string, afterLine: number, timeoutMs?: number): Promise<string>;
|
|
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;
|
package/dist/mail/index.js
CHANGED
|
@@ -1,97 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const { sinkPath } = opts;
|
|
6
|
-
return {
|
|
7
|
-
async send(m) {
|
|
8
|
-
const url = m.text.match(/https?:\/\/\S+/)?.[0];
|
|
9
|
-
if (url)
|
|
10
|
-
appendFileSync(sinkPath, `${url}\n`, "utf8");
|
|
11
|
-
},
|
|
12
|
-
};
|
|
13
|
-
}
|
|
14
|
-
const { apiKey, from } = opts;
|
|
15
|
-
const doFetch = opts.fetch ?? fetch;
|
|
16
|
-
return {
|
|
17
|
-
async send(m) {
|
|
18
|
-
const response = await doFetch(RESEND_ENDPOINT, {
|
|
19
|
-
method: "POST",
|
|
20
|
-
headers: {
|
|
21
|
-
authorization: `Bearer ${apiKey}`,
|
|
22
|
-
"content-type": "application/json",
|
|
23
|
-
},
|
|
24
|
-
body: JSON.stringify({ from, to: m.to, subject: m.subject, text: m.text }),
|
|
25
|
-
// A hung Resend must not hold the sign-in request open.
|
|
26
|
-
signal: AbortSignal.timeout(10_000),
|
|
27
|
-
});
|
|
28
|
-
if (!response.ok) {
|
|
29
|
-
throw new Error(`Resend refused the message: ${response.status}${await refusalReason(response)}`);
|
|
30
|
-
}
|
|
31
|
-
},
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* Production sends through Resend; every other environment uses the sink.
|
|
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.
|
|
42
|
-
*/
|
|
43
|
-
export function mailerFromEnv(env) {
|
|
44
|
-
if (env.NODE_ENV !== "production") {
|
|
45
|
-
return createMailer({ mode: "sink", sinkPath: env.MAGIC_LINK_SINK_PATH });
|
|
46
|
-
}
|
|
47
|
-
const { RESEND_API_KEY: apiKey, EMAIL_FROM: from } = env;
|
|
48
|
-
if (!apiKey || !from) {
|
|
49
|
-
const missing = apiKey ? "EMAIL_FROM" : "RESEND_API_KEY";
|
|
50
|
-
return {
|
|
51
|
-
async send() {
|
|
52
|
-
throw new Error(`${missing} is required in production`);
|
|
53
|
-
},
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
return createMailer({ mode: "resend", apiKey, from });
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
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.
|
|
61
|
-
*/
|
|
62
|
-
async function refusalReason(response) {
|
|
63
|
-
try {
|
|
64
|
-
const body = await response.json();
|
|
65
|
-
if (typeof body !== "object" || body === null)
|
|
66
|
-
return "";
|
|
67
|
-
const { name, message } = body;
|
|
68
|
-
if (typeof name !== "string" || typeof message !== "string")
|
|
69
|
-
return "";
|
|
70
|
-
const redacted = message.replace(/[^\s()<>@,;:"]+@[^\s()<>@,;:"]+/g, "[email]").slice(0, 300);
|
|
71
|
-
return ` ${name}: ${redacted}`;
|
|
72
|
-
}
|
|
73
|
-
catch {
|
|
74
|
-
return "";
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
function sinkLines(sinkPath) {
|
|
78
|
-
if (!existsSync(sinkPath))
|
|
79
|
-
return [];
|
|
80
|
-
return readFileSync(sinkPath, "utf8").split("\n").filter(Boolean);
|
|
81
|
-
}
|
|
82
|
-
/** How many links the sink holds now; take it before the request that should add one. */
|
|
83
|
-
export function countSinkLines(sinkPath) {
|
|
84
|
-
return sinkLines(sinkPath).length;
|
|
85
|
-
}
|
|
86
|
-
/** The first link after line `afterLine` (a count from `countSinkLines`), polling until `timeoutMs`. */
|
|
87
|
-
export async function waitForMagicLink(sinkPath, afterLine, timeoutMs = 10_000) {
|
|
88
|
-
const deadline = Date.now() + timeoutMs;
|
|
89
|
-
for (;;) {
|
|
90
|
-
const line = sinkLines(sinkPath)[afterLine];
|
|
91
|
-
if (line)
|
|
92
|
-
return line;
|
|
93
|
-
if (Date.now() >= deadline)
|
|
94
|
-
throw new Error(`No magic link reached ${sinkPath}`);
|
|
95
|
-
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
96
|
-
}
|
|
97
|
-
}
|
|
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;
|
package/dist/next/api.d.ts
CHANGED
|
@@ -1,16 +1,10 @@
|
|
|
1
|
-
import type { StackAuth } from "
|
|
2
|
-
import type { Session } from "../auth/types.ts";
|
|
1
|
+
import type { Session, StackAuth } from "@wwchen/stack-auth";
|
|
3
2
|
/**
|
|
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.
|
|
3
|
+
* 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
4
|
*
|
|
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.
|
|
5
|
+
* 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
6
|
*
|
|
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.
|
|
7
|
+
* `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
8
|
*/
|
|
15
9
|
/** An error a route throws on purpose: its message is written for the caller and is sent as is. */
|
|
16
10
|
export declare class ApiError extends Error {
|
|
@@ -33,16 +27,13 @@ export declare class NotFoundError extends ApiError {
|
|
|
33
27
|
constructor(message?: string);
|
|
34
28
|
}
|
|
35
29
|
/**
|
|
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.
|
|
30
|
+
* 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
31
|
*/
|
|
39
32
|
export declare class PathIdError extends NotFoundError {
|
|
40
33
|
constructor();
|
|
41
34
|
}
|
|
42
35
|
/**
|
|
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.
|
|
36
|
+
* 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
37
|
*/
|
|
47
38
|
export declare function requirePathId(value: string): string;
|
|
48
39
|
export declare function apiError(status: number, code: string, message: string, details?: {
|
|
@@ -54,10 +45,7 @@ export type BodySchema<T> = {
|
|
|
54
45
|
parse(input: unknown): T;
|
|
55
46
|
};
|
|
56
47
|
/**
|
|
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.
|
|
48
|
+
* 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
49
|
*/
|
|
62
50
|
export declare function readJson(req: Request): Promise<unknown>;
|
|
63
51
|
export declare function readJson<T>(req: Request, schema: BodySchema<T>): Promise<T>;
|
package/dist/next/api.js
CHANGED
|
@@ -1,16 +1,11 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import { hasNoBody, isJsonRequest, isMutation, isSameOrigin } from "../http/guards.js";
|
|
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 class ApiError extends Error {
|
|
@@ -35,8 +30,7 @@ export class NotFoundError extends ApiError {
|
|
|
35
30
|
}
|
|
36
31
|
}
|
|
37
32
|
/**
|
|
38
|
-
* A path id that is not a uuid: the same 404 a missing row gets, but told apart from one so a
|
|
39
|
-
* route that surfaces its own not-found message never surfaces this one.
|
|
33
|
+
* 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.
|
|
40
34
|
*/
|
|
41
35
|
export class PathIdError extends NotFoundError {
|
|
42
36
|
constructor() {
|
|
@@ -45,9 +39,7 @@ export class PathIdError extends NotFoundError {
|
|
|
45
39
|
}
|
|
46
40
|
}
|
|
47
41
|
/**
|
|
48
|
-
* A path id, or a `PathIdError` for the wrapper to answer. Anything that is not a uuid cannot name
|
|
49
|
-
* a row, so it is the same 404 a missing row gets, answered before the query: Postgres would
|
|
50
|
-
* otherwise reject the cast and turn a typo'd URL into a 500.
|
|
42
|
+
* 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.
|
|
51
43
|
*/
|
|
52
44
|
export function requirePathId(value) {
|
|
53
45
|
if (!z.uuid().safeParse(value).success)
|
|
@@ -99,8 +91,7 @@ export function apiHandler(opts, fn) {
|
|
|
99
91
|
return apiError(404, "not_found", "Not found.");
|
|
100
92
|
}
|
|
101
93
|
if (isMutation(req)) {
|
|
102
|
-
// JSON only, so a cross-site form post can't reach a handler; a request with no body at
|
|
103
|
-
// all (a plain `DELETE`) has nothing to be JSON, and a form always sends a Content-Type.
|
|
94
|
+
// JSON only, so a cross-site form post can't reach a handler; a request with no body at all (a plain `DELETE`) has nothing to be JSON, and a form always sends a Content-Type.
|
|
104
95
|
if (!isJsonRequest(req) && !hasNoBody(req)) {
|
|
105
96
|
return apiError(415, "unsupported_media_type", "Send application/json.");
|
|
106
97
|
}
|
package/dist/next/config.js
CHANGED
|
@@ -2,8 +2,7 @@ import { isProductionEnv } from "../env/index.js";
|
|
|
2
2
|
/**
|
|
3
3
|
* `next.config.ts`: `export default withStack({ ...the app's own config })`.
|
|
4
4
|
*
|
|
5
|
-
* Sentry (or any monitor) is initialised at runtime from `instrumentation.ts`, not through a
|
|
6
|
-
* build-time config wrapper, so there is nothing to compose here.
|
|
5
|
+
* Sentry (or any monitor) is initialised at runtime from `instrumentation.ts`, not through a build-time config wrapper, so there is nothing to compose here.
|
|
7
6
|
*/
|
|
8
7
|
const securityHeaders = [
|
|
9
8
|
{ key: "X-Content-Type-Options", value: "nosniff" },
|
|
@@ -15,51 +14,31 @@ const securityHeaders = [
|
|
|
15
14
|
/**
|
|
16
15
|
* **The Content-Security-Policy, production only.**
|
|
17
16
|
*
|
|
18
|
-
* Turbopack's dev server needs `'unsafe-eval'` and a websocket for HMR that a production policy
|
|
19
|
-
* must not carry, and a half-right CSP breaks the dev loop. So the header is added to production
|
|
20
|
-
* builds only, and a claim about it can only be checked against a production build
|
|
21
|
-
* (`pnpm build && pnpm start`): an e2e suite running against `pnpm dev` never sees it.
|
|
17
|
+
* Turbopack's dev server needs `'unsafe-eval'` and a websocket for HMR that a production policy must not carry, and a half-right CSP breaks the dev loop. So the header is added to production builds only, and a claim about it can only be checked against a production build (`pnpm build && pnpm start`): an e2e suite running against `pnpm dev` never sees it.
|
|
22
18
|
*
|
|
23
|
-
* `process.env.NODE_ENV` is read through `isProductionEnv` rather than an app's validated env
|
|
24
|
-
* because this file is Next's own config: the framework evaluates it before any application module
|
|
25
|
-
* loads, and importing validated config would make a build depend on a boot.
|
|
19
|
+
* `process.env.NODE_ENV` is read through `isProductionEnv` rather than an app's validated env because this file is Next's own config: the framework evaluates it before any application module loads, and importing validated config would make a build depend on a boot.
|
|
26
20
|
*/
|
|
27
21
|
function contentSecurityPolicy(connectSrc) {
|
|
28
22
|
return [
|
|
29
23
|
// Nothing loads from anywhere but this origin unless a directive below says so.
|
|
30
24
|
"default-src 'self'",
|
|
31
25
|
/**
|
|
32
|
-
* `'unsafe-inline'`, and the reason is structural rather than lazy: Next's App Router ships the
|
|
33
|
-
* flight payload and its hydration bootstrap as INLINE `<script>` tags, and a policy living in
|
|
34
|
-
* `next.config.ts` is a static header: it cannot carry the per-request nonce those tags would
|
|
35
|
-
* need. With `script-src 'self'` alone the page server-renders and the console fills with
|
|
36
|
-
* "Executing inline script violates...", which means no hydration and dead client components.
|
|
26
|
+
* `'unsafe-inline'`, and the reason is structural rather than lazy: Next's App Router ships the flight payload and its hydration bootstrap as INLINE `<script>` tags, and a policy living in `next.config.ts` is a static header: it cannot carry the per-request nonce those tags would need. With `script-src 'self'` alone the page server-renders and the console fills with "Executing inline script violates...", which means no hydration and dead client components.
|
|
37
27
|
*
|
|
38
|
-
* A nonce-based policy is strictly better: generate one per request in `src/proxy.ts`, pass it
|
|
39
|
-
* on the request headers, and Next stamps its own scripts with it. That moves the CSP out of
|
|
40
|
-
* this file and puts per-request work in the one file that guards every page, so it is a
|
|
41
|
-
* decision for the app rather than a default here.
|
|
28
|
+
* A nonce-based policy is strictly better: generate one per request in `src/proxy.ts`, pass it on the request headers, and Next stamps its own scripts with it. That moves the CSP out of this file and puts per-request work in the one file that guards every page, so it is a decision for the app rather than a default here.
|
|
42
29
|
*
|
|
43
|
-
* What this still buys: no script from another origin can load, `eval` is refused (no
|
|
44
|
-
* `'unsafe-eval'`), and the directives below close framing, base-tag and form-action
|
|
45
|
-
* redirection. Strictly better than no CSP.
|
|
30
|
+
* What this still buys: no script from another origin can load, `eval` is refused (no `'unsafe-eval'`), and the directives below close framing, base-tag and form-action redirection. Strictly better than no CSP.
|
|
46
31
|
*/
|
|
47
32
|
"script-src 'self' 'unsafe-inline'",
|
|
48
33
|
/**
|
|
49
|
-
* `'unsafe-inline'` here is a correctness requirement, not a convenience. Under `style-src
|
|
50
|
-
* 'self'` a browser keeps a `style="..."` attribute and refuses to apply it, so any component
|
|
51
|
-
* that sets a width or transform inline renders as if the style were absent (a meter drawn at
|
|
52
|
-
* full width is a worse failure than a missing header).
|
|
34
|
+
* `'unsafe-inline'` here is a correctness requirement, not a convenience. Under `style-src 'self'` a browser keeps a `style="..."` attribute and refuses to apply it, so any component that sets a width or transform inline renders as if the style were absent (a meter drawn at full width is a worse failure than a missing header).
|
|
53
35
|
*
|
|
54
|
-
* `style-src-attr 'unsafe-inline'` with a strict `style-src` would be tighter, and is
|
|
55
|
-
* deliberately not used: where a browser does not support `style-src-attr` it falls back to
|
|
56
|
-
* `style-src`, and the failure mode of guessing wrong is the one above.
|
|
36
|
+
* `style-src-attr 'unsafe-inline'` with a strict `style-src` would be tighter, and is deliberately not used: where a browser does not support `style-src-attr` it falls back to `style-src`, and the failure mode of guessing wrong is the one above.
|
|
57
37
|
*/
|
|
58
38
|
"style-src 'self' 'unsafe-inline'",
|
|
59
39
|
// `data:` is for the favicon and inline icons; remote images are an app decision.
|
|
60
40
|
"img-src 'self' data:",
|
|
61
|
-
// `next/font` downloads fonts AT BUILD TIME and serves them from /_next/static, so the running
|
|
62
|
-
// app never reaches a font CDN and this stays 'self'.
|
|
41
|
+
// `next/font` downloads fonts AT BUILD TIME and serves them from /_next/static, so the running app never reaches a font CDN and this stays 'self'.
|
|
63
42
|
"font-src 'self'",
|
|
64
43
|
// Same-origin fetches only, plus whatever origins the app lists in `cspConnectSrc`.
|
|
65
44
|
["connect-src 'self'", ...connectSrc].join(" "),
|
|
@@ -87,8 +66,7 @@ export function withStack(appConfig = {}, opts = {}) {
|
|
|
87
66
|
reactStrictMode: true,
|
|
88
67
|
...appConfig,
|
|
89
68
|
poweredByHeader: false,
|
|
90
|
-
// The health route checks the migrations folder at runtime. Vercel bundles only traced files,
|
|
91
|
-
// so without this the read fails and migrations always report "unknown".
|
|
69
|
+
// The health route checks the migrations folder at runtime. Vercel bundles only traced files, so without this the read fails and migrations always report "unknown".
|
|
92
70
|
outputFileTracingIncludes: {
|
|
93
71
|
...appConfig.outputFileTracingIncludes,
|
|
94
72
|
"/api/health": ["./drizzle/**"],
|
package/dist/next/cron.d.ts
CHANGED
|
@@ -1,11 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* A scheduled job's route, called by Vercel Cron with `Authorization: Bearer $CRON_SECRET`.
|
|
3
|
-
* `CRON_SECRET` triggers scheduled jobs and nothing else: with none configured every request is
|
|
4
|
-
* refused (an empty bearer is not accepted), and the response is whatever `fn` returned, which
|
|
5
|
-
* must be counts. No row data, no ids, no messages.
|
|
2
|
+
* A scheduled job's route, called by Vercel Cron with `Authorization: Bearer $CRON_SECRET`. `CRON_SECRET` triggers scheduled jobs and nothing else: with none configured every request is refused (an empty bearer is not accepted), and the response is whatever `fn` returned, which must be counts. No row data, no ids, no messages.
|
|
6
3
|
*
|
|
7
|
-
* A job that returns `alerting: true` answers 500 with the same counts, so an uptime monitor calling
|
|
8
|
-
* it alerts: a multi-person job sets it while someone's failure is new (`@wwchen/stack/jobs`).
|
|
4
|
+
* A job that returns `alerting: true` answers 500 with the same counts, so an uptime monitor calling it alerts: a multi-person job sets it while someone's failure is new (`@wwchen/stack/jobs`).
|
|
9
5
|
*
|
|
10
6
|
* `export const GET = cronRoute(tick, { secret: env.CRON_SECRET })`.
|
|
11
7
|
*/
|
package/dist/next/cron.js
CHANGED
|
@@ -1,21 +1,16 @@
|
|
|
1
1
|
import { bearerMatches } from "../http/guards.js";
|
|
2
2
|
import { apiError } from "./api.js";
|
|
3
3
|
/**
|
|
4
|
-
* A scheduled job's route, called by Vercel Cron with `Authorization: Bearer $CRON_SECRET`.
|
|
5
|
-
* `CRON_SECRET` triggers scheduled jobs and nothing else: with none configured every request is
|
|
6
|
-
* refused (an empty bearer is not accepted), and the response is whatever `fn` returned, which
|
|
7
|
-
* must be counts. No row data, no ids, no messages.
|
|
4
|
+
* A scheduled job's route, called by Vercel Cron with `Authorization: Bearer $CRON_SECRET`. `CRON_SECRET` triggers scheduled jobs and nothing else: with none configured every request is refused (an empty bearer is not accepted), and the response is whatever `fn` returned, which must be counts. No row data, no ids, no messages.
|
|
8
5
|
*
|
|
9
|
-
* A job that returns `alerting: true` answers 500 with the same counts, so an uptime monitor calling
|
|
10
|
-
* it alerts: a multi-person job sets it while someone's failure is new (`@wwchen/stack/jobs`).
|
|
6
|
+
* A job that returns `alerting: true` answers 500 with the same counts, so an uptime monitor calling it alerts: a multi-person job sets it while someone's failure is new (`@wwchen/stack/jobs`).
|
|
11
7
|
*
|
|
12
8
|
* `export const GET = cronRoute(tick, { secret: env.CRON_SECRET })`.
|
|
13
9
|
*/
|
|
14
10
|
export function cronRoute(fn, opts) {
|
|
15
11
|
return async (req) => {
|
|
16
12
|
if (!bearerMatches(req, opts.secret)) {
|
|
17
|
-
// A refused call writes nothing anywhere, so without this line a missing or wrong secret
|
|
18
|
-
// looks exactly like a cron that never fired. Never logs what was presented.
|
|
13
|
+
// A refused call writes nothing anywhere, so without this line a missing or wrong secret looks exactly like a cron that never fired. Never logs what was presented.
|
|
19
14
|
console.warn(JSON.stringify({
|
|
20
15
|
level: "warn",
|
|
21
16
|
msg: "cron refused",
|
package/dist/next/health.d.ts
CHANGED
|
@@ -1,15 +1,10 @@
|
|
|
1
1
|
import type { NodePgDatabase } from "drizzle-orm/node-postgres";
|
|
2
2
|
/**
|
|
3
|
-
* Liveness, deliberately not readiness. The status is ALWAYS 200 while the process can answer: a
|
|
4
|
-
* database blip must not make an uptime check report a healthy web process as down.
|
|
3
|
+
* Liveness, deliberately not readiness. The status is ALWAYS 200 while the process can answer: a database blip must not make an uptime check report a healthy web process as down.
|
|
5
4
|
*
|
|
6
|
-
* Without the token the answer is `{ ok: true }` and the database is never touched, so an
|
|
7
|
-
* anonymous caller cannot make the app query it. With `Authorization: Bearer $HEALTH_TOKEN` it
|
|
8
|
-
* also reports `db` and `migrations`. `HEALTH_TOKEN` is its own secret, never `CRON_SECRET`.
|
|
5
|
+
* Without the token the answer is `{ ok: true }` and the database is never touched, so an anonymous caller cannot make the app query it. With `Authorization: Bearer $HEALTH_TOKEN` it also reports `db` and `migrations`. `HEALTH_TOKEN` is its own secret, never `CRON_SECRET`.
|
|
9
6
|
*
|
|
10
|
-
* `export const GET = healthRoute({ db, token: env.HEALTH_TOKEN })`, with `dynamic =
|
|
11
|
-
* "force-dynamic"`. `withStack` traces `./drizzle/**` into this route so the migrations folder
|
|
12
|
-
* exists in a deployment.
|
|
7
|
+
* `export const GET = healthRoute({ db, token: env.HEALTH_TOKEN })`, with `dynamic = "force-dynamic"`. `withStack` traces `./drizzle/**` into this route so the migrations folder exists in a deployment.
|
|
13
8
|
*/
|
|
14
9
|
export declare function healthRoute(opts: {
|
|
15
10
|
db?: NodePgDatabase<any>;
|
package/dist/next/health.js
CHANGED
|
@@ -3,16 +3,11 @@ import { sql } from "drizzle-orm";
|
|
|
3
3
|
import { migrationStatus } from "../db/migration-status.js";
|
|
4
4
|
import { bearerMatches } from "../http/guards.js";
|
|
5
5
|
/**
|
|
6
|
-
* Liveness, deliberately not readiness. The status is ALWAYS 200 while the process can answer: a
|
|
7
|
-
* database blip must not make an uptime check report a healthy web process as down.
|
|
6
|
+
* Liveness, deliberately not readiness. The status is ALWAYS 200 while the process can answer: a database blip must not make an uptime check report a healthy web process as down.
|
|
8
7
|
*
|
|
9
|
-
* Without the token the answer is `{ ok: true }` and the database is never touched, so an
|
|
10
|
-
* anonymous caller cannot make the app query it. With `Authorization: Bearer $HEALTH_TOKEN` it
|
|
11
|
-
* also reports `db` and `migrations`. `HEALTH_TOKEN` is its own secret, never `CRON_SECRET`.
|
|
8
|
+
* Without the token the answer is `{ ok: true }` and the database is never touched, so an anonymous caller cannot make the app query it. With `Authorization: Bearer $HEALTH_TOKEN` it also reports `db` and `migrations`. `HEALTH_TOKEN` is its own secret, never `CRON_SECRET`.
|
|
12
9
|
*
|
|
13
|
-
* `export const GET = healthRoute({ db, token: env.HEALTH_TOKEN })`, with `dynamic =
|
|
14
|
-
* "force-dynamic"`. `withStack` traces `./drizzle/**` into this route so the migrations folder
|
|
15
|
-
* exists in a deployment.
|
|
10
|
+
* `export const GET = healthRoute({ db, token: env.HEALTH_TOKEN })`, with `dynamic = "force-dynamic"`. `withStack` traces `./drizzle/**` into this route so the migrations folder exists in a deployment.
|
|
16
11
|
*/
|
|
17
12
|
export function healthRoute(opts) {
|
|
18
13
|
const migrationsFolder = opts.migrationsFolder ?? path.join(process.cwd(), "drizzle");
|
package/dist/testing/next.d.ts
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Runs `fn` inside a real Next request scope in its server-action phase — what Next sets up around
|
|
3
|
-
* a `"use server"` function — so `headers()` reads `headers` and `cookies().set()` works. Returns
|
|
4
|
-
* the `Set-Cookie` lines the scope would send, which is how a test sees what Better Auth's
|
|
5
|
-
* `nextCookies()` wrote. Built from Next's own internals (next is pinned exactly).
|
|
2
|
+
* Runs `fn` inside a real Next request scope in its server-action phase — what Next sets up around a `"use server"` function — so `headers()` reads `headers` and `cookies().set()` works. Returns the `Set-Cookie` lines the scope would send, which is how a test sees what Better Auth's `nextCookies()` wrote. Built from Next's own internals (next is pinned exactly).
|
|
6
3
|
*
|
|
7
4
|
* `redirect()` and `notFound()` throw as they do in Next; `thrownBy` reads where they pointed.
|
|
8
5
|
*/
|
package/dist/testing/next.js
CHANGED
|
@@ -1,14 +1,9 @@
|
|
|
1
|
-
// `@wwchen/stack/testing/next`: test helpers, for a stack app's tests and the package's own. Not
|
|
2
|
-
// for app code. Built on Next's internals, which move with the exact `next` the stack pins, so they
|
|
3
|
-
// ship here and an app takes a fix with the stack rather than keeping a copy.
|
|
1
|
+
// `@wwchen/stack/testing/next`: test helpers, for a stack app's tests and the package's own. Not for app code. Built on Next's internals, which move with the exact `next` the stack pins, so they ship here and an app takes a fix with the stack rather than keeping a copy.
|
|
4
2
|
import { workAsyncStorage } from "next/dist/server/app-render/work-async-storage.external.js";
|
|
5
3
|
import { workUnitAsyncStorage } from "next/dist/server/app-render/work-unit-async-storage.external.js";
|
|
6
4
|
import { createRequestStoreForAPI } from "next/dist/server/async-storage/request-store.js";
|
|
7
5
|
/**
|
|
8
|
-
* Runs `fn` inside a real Next request scope in its server-action phase — what Next sets up around
|
|
9
|
-
* a `"use server"` function — so `headers()` reads `headers` and `cookies().set()` works. Returns
|
|
10
|
-
* the `Set-Cookie` lines the scope would send, which is how a test sees what Better Auth's
|
|
11
|
-
* `nextCookies()` wrote. Built from Next's own internals (next is pinned exactly).
|
|
6
|
+
* Runs `fn` inside a real Next request scope in its server-action phase — what Next sets up around a `"use server"` function — so `headers()` reads `headers` and `cookies().set()` works. Returns the `Set-Cookie` lines the scope would send, which is how a test sees what Better Auth's `nextCookies()` wrote. Built from Next's own internals (next is pinned exactly).
|
|
12
7
|
*
|
|
13
8
|
* `redirect()` and `notFound()` throw as they do in Next; `thrownBy` reads where they pointed.
|
|
14
9
|
*/
|
package/dist/ui/app.css
CHANGED
|
@@ -1,13 +1,9 @@
|
|
|
1
1
|
/*
|
|
2
|
-
* The bridge onto LDS (`@lew-ds/lds`, imported in globals.css): the only place the package adjusts
|
|
3
|
-
* it. Each rule says which gap it fills.
|
|
2
|
+
* The bridge onto LDS (`@lew-ds/lds`, imported in globals.css): the only place the package adjusts it. Each rule says which gap it fills.
|
|
4
3
|
*/
|
|
5
4
|
|
|
6
5
|
/*
|
|
7
|
-
* Fonts. The product theme names 'Inter', which LDS does not ship as a file. An app that loads
|
|
8
|
-
* Inter through `next/font` exposes it as `--font-inter` under a generated family name, so the
|
|
9
|
-
* theme's font roles point there; without it they fall back to the system font.
|
|
10
|
-
* `--th-mono` stays the theme's ui-monospace.
|
|
6
|
+
* Fonts. The product theme names 'Inter', which LDS does not ship as a file. An app that loads Inter through `next/font` exposes it as `--font-inter` under a generated family name, so the theme's font roles point there; without it they fall back to the system font. `--th-mono` stays the theme's ui-monospace.
|
|
11
7
|
*/
|
|
12
8
|
.theme-product {
|
|
13
9
|
--th-display: var(--font-inter, Inter), system-ui, sans-serif;
|
|
@@ -16,9 +12,7 @@
|
|
|
16
12
|
}
|
|
17
13
|
|
|
18
14
|
/*
|
|
19
|
-
* Two roles LDS spells only inside a component, given a name so a layout utility can use them: the
|
|
20
|
-
* soft tint (`.emph-soft`'s fill and ink, for a selected nav item) and the error ink (an
|
|
21
|
-
* `lds-field__error`'s colour on the red ramp).
|
|
15
|
+
* Two roles LDS spells only inside a component, given a name so a layout utility can use them: the soft tint (`.emph-soft`'s fill and ink, for a selected nav item) and the error ink (an `lds-field__error`'s colour on the red ramp).
|
|
22
16
|
*/
|
|
23
17
|
:root {
|
|
24
18
|
--app-tint: var(--c-100);
|
|
@@ -33,19 +27,14 @@
|
|
|
33
27
|
}
|
|
34
28
|
|
|
35
29
|
/*
|
|
36
|
-
* Tooltip line breaks. LDS's bubble collapses whitespace, so a label listing several items, one to
|
|
37
|
-
* a line, would run together. `pre-line` keeps the label's newlines and still wraps long lines; a
|
|
38
|
-
* label without one reads as before.
|
|
30
|
+
* Tooltip line breaks. LDS's bubble collapses whitespace, so a label listing several items, one to a line, would run together. `pre-line` keeps the label's newlines and still wraps long lines; a label without one reads as before.
|
|
39
31
|
*/
|
|
40
32
|
.lds-tooltip__bubble {
|
|
41
33
|
white-space: pre-line;
|
|
42
34
|
}
|
|
43
35
|
|
|
44
36
|
/*
|
|
45
|
-
* No zoom on focus. iOS Safari zooms the page into any field whose text is under 16px and leaves
|
|
46
|
-
* it zoomed after; LDS's fields take the 13px body. On a touch screen they take 16px, so focusing a
|
|
47
|
-
* field leaves the page where it was. Pinch zoom stays: the viewport is never locked
|
|
48
|
-
* (`maximum-scale` would break the 200% zoom rule). A desktop keeps LDS's size.
|
|
37
|
+
* No zoom on focus. iOS Safari zooms the page into any field whose text is under 16px and leaves it zoomed after; LDS's fields take the 13px body. On a touch screen they take 16px, so focusing a field leaves the page where it was. Pinch zoom stays: the viewport is never locked (`maximum-scale` would break the 200% zoom rule). A desktop keeps LDS's size.
|
|
49
38
|
*/
|
|
50
39
|
@media (pointer: coarse) {
|
|
51
40
|
.lds-field input,
|
package/dist/ui/globals.css
CHANGED
|
@@ -1,19 +1,12 @@
|
|
|
1
1
|
/*
|
|
2
|
-
* The design system is LDS (Lew Design System), product theme: the `@lew-ds/lds` package.
|
|
3
|
-
* LDS paints components through its own class names (`lds-btn`, `lds-tag`, `lds-table`, …), which
|
|
4
|
-
* `@lew-ds/lds-react`'s components emit. Tailwind is kept for LAYOUT, and every colour, radius
|
|
5
|
-
* and shadow utility below resolves to an LDS role, so there is one palette, not two.
|
|
2
|
+
* The design system is LDS (Lew Design System), product theme: the `@lew-ds/lds` package. LDS paints components through its own class names (`lds-btn`, `lds-tag`, `lds-table`, …), which `@lew-ds/lds-react`'s components emit. Tailwind is kept for LAYOUT, and every colour, radius and shadow utility below resolves to an LDS role, so there is one palette, not two.
|
|
6
3
|
*
|
|
7
4
|
* Import this file FIRST in the app's stylesheet, then Tailwind:
|
|
8
5
|
*
|
|
9
6
|
* @import "@wwchen/stack/ui/globals.css";
|
|
10
7
|
* @import "tailwindcss";
|
|
11
8
|
*
|
|
12
|
-
* The layer order below must be the first `@layer` statement Tailwind's own sees: LDS sits after
|
|
13
|
-
* Tailwind's preflight (so it styles bare buttons and links) and before `components` and
|
|
14
|
-
* `utilities` (so a layout utility on an LDS element still wins). LDS's root tokens therefore also
|
|
15
|
-
* win over any Tailwind default that shares their name (`--radius-lg`, `--shadow-sm`,
|
|
16
|
-
* `--leading-tight`): LDS is the system.
|
|
9
|
+
* The layer order below must be the first `@layer` statement Tailwind's own sees: LDS sits after Tailwind's preflight (so it styles bare buttons and links) and before `components` and `utilities` (so a layout utility on an LDS element still wins). LDS's root tokens therefore also win over any Tailwind default that shares their name (`--radius-lg`, `--shadow-sm`, `--leading-tight`): LDS is the system.
|
|
17
10
|
*/
|
|
18
11
|
@layer theme, base, lds, components, utilities;
|
|
19
12
|
|
|
@@ -23,15 +16,12 @@
|
|
|
23
16
|
@import "./app.css" layer(lds);
|
|
24
17
|
|
|
25
18
|
/*
|
|
26
|
-
* Dark mode is LDS's `mode-dark` class, which the SERVER writes onto <html> from the theme cookie
|
|
27
|
-
* beside `theme-product` (see `htmlClassName`): never a media query and never a client-side flip,
|
|
28
|
-
* so the first response is already correct.
|
|
19
|
+
* Dark mode is LDS's `mode-dark` class, which the SERVER writes onto <html> from the theme cookie beside `theme-product` (see `htmlClassName`): never a media query and never a client-side flip, so the first response is already correct.
|
|
29
20
|
*/
|
|
30
21
|
@custom-variant dark (&:where(.mode-dark, .mode-dark *));
|
|
31
22
|
|
|
32
23
|
/*
|
|
33
|
-
* `inline`: each utility emits the LDS variable itself (`color: var(--text)`), so it re-resolves
|
|
34
|
-
* wherever an LDS emphasis or mode class re-points the role, the way LDS's own components do.
|
|
24
|
+
* `inline`: each utility emits the LDS variable itself (`color: var(--text)`), so it re-resolves wherever an LDS emphasis or mode class re-points the role, the way LDS's own components do.
|
|
35
25
|
*/
|
|
36
26
|
@theme inline {
|
|
37
27
|
/* ---- surfaces, borders and text: LDS's object-colour roles ---- */
|
|
@@ -108,9 +98,7 @@
|
|
|
108
98
|
|
|
109
99
|
@layer base {
|
|
110
100
|
/*
|
|
111
|
-
* The root stays 14px (LDS's size-3): every rem-based utility (the container widths) is measured
|
|
112
|
-
* from it, and LDS's own sizes are px. Text takes LDS's 13px body from the `text-copy` on <body>,
|
|
113
|
-
* not from here.
|
|
101
|
+
* The root stays 14px (LDS's size-3): every rem-based utility (the container widths) is measured from it, and LDS's own sizes are px. Text takes LDS's 13px body from the `text-copy` on <body>, not from here.
|
|
114
102
|
*/
|
|
115
103
|
html {
|
|
116
104
|
font-size: var(--size-3);
|
|
@@ -135,9 +123,7 @@
|
|
|
135
123
|
}
|
|
136
124
|
|
|
137
125
|
/*
|
|
138
|
-
* Reduced motion, deliberately OUTSIDE every layer: unlayered CSS wins over `@layer utilities`
|
|
139
|
-
* whatever the specificity, so this needs no `!important` to switch off a `duration-*` utility. It
|
|
140
|
-
* covers LDS's own hover, focus and press transitions too.
|
|
126
|
+
* Reduced motion, deliberately OUTSIDE every layer: unlayered CSS wins over `@layer utilities` whatever the specificity, so this needs no `!important` to switch off a `duration-*` utility. It covers LDS's own hover, focus and press transitions too.
|
|
141
127
|
*/
|
|
142
128
|
@media (prefers-reduced-motion: reduce) {
|
|
143
129
|
[class*="duration-"],
|
package/dist/ui/icons.d.ts
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The page's icon sprite holds the app's icons plus what LDS's components draw on their own. A
|
|
3
|
-
* glyph a component names but the sprite lacks renders as nothing, with no error anywhere, so this
|
|
4
|
-
* reads every glyph name the app's source hands an LDS component and checks it is in the sprite.
|
|
2
|
+
* The page's icon sprite holds the app's icons plus what LDS's components draw on their own. A glyph a component names but the sprite lacks renders as nothing, with no error anywhere, so this reads every glyph name the app's source hands an LDS component and checks it is in the sprite.
|
|
5
3
|
*/
|
|
6
4
|
export interface IconReport {
|
|
7
5
|
/** Named in source, in neither the app's icons nor LDS's component icons. */
|
package/dist/ui/icons.js
CHANGED
|
@@ -14,9 +14,7 @@ const IMPORTS_LDS = /from "(?:@wwchen\/stack\/ui|@lew-ds\/lds-react)"/;
|
|
|
14
14
|
/** An icon named as data: `icon: "home"` (or `iconStart`/`iconEnd`) in an object literal. */
|
|
15
15
|
const ICON_DATA = /\b(?:icon|iconStart|iconEnd):\s*"([^"]+)"/g;
|
|
16
16
|
/**
|
|
17
|
-
* Whether the file renders an LDS component, however it imports it: an app's own re-export
|
|
18
|
-
* (`@/components/ui/lds`) is as much LDS as `@wwchen/stack/ui`. A file that does is where a glyph
|
|
19
|
-
* listed as data (`{ href: "/", icon: "home" }`, handed on as `<Icon name={view.icon} />`) is drawn.
|
|
17
|
+
* Whether the file renders an LDS component, however it imports it: an app's own re-export (`@/components/ui/lds`) is as much LDS as `@wwchen/stack/ui`. A file that does is where a glyph listed as data (`{ href: "/", icon: "home" }`, handed on as `<Icon name={view.icon} />`) is drawn.
|
|
20
18
|
*/
|
|
21
19
|
function rendersLds(text) {
|
|
22
20
|
for (const tag of text.matchAll(/<([A-Z]\w*)/g)) {
|
|
@@ -37,8 +35,7 @@ function braced(text, open) {
|
|
|
37
35
|
return text.slice(open + 1);
|
|
38
36
|
}
|
|
39
37
|
/**
|
|
40
|
-
* Whether the tag opened at `from` is still open at `to`: no `>` outside braces and quotes between
|
|
41
|
-
* them. A `=>` or `>` inside a `{…}` value or a string does not close it.
|
|
38
|
+
* Whether the tag opened at `from` is still open at `to`: no `>` outside braces and quotes between them. A `=>` or `>` inside a `{…}` value or a string does not close it.
|
|
42
39
|
*/
|
|
43
40
|
function tagOpenAt(text, from, to) {
|
|
44
41
|
let depth = 0;
|
|
@@ -70,11 +67,7 @@ function enclosingTag(text, at) {
|
|
|
70
67
|
return undefined;
|
|
71
68
|
}
|
|
72
69
|
/**
|
|
73
|
-
* Every glyph name a JSX source hands an LDS component: a literal (`iconStart="edit"`) or any
|
|
74
|
-
* string in an expression (`iconStart={open ? "chevron-up" : "chevron-down"}`), except an
|
|
75
|
-
* attribute value nested inside it (`type="button"` on an element passed as the icon). Also an
|
|
76
|
-
* `icon: "…"` in an object literal (a SegmentedControl option, a nav's list of views), in a file
|
|
77
|
-
* that imports LDS or renders an LDS component.
|
|
70
|
+
* Every glyph name a JSX source hands an LDS component: a literal (`iconStart="edit"`) or any string in an expression (`iconStart={open ? "chevron-up" : "chevron-down"}`), except an attribute value nested inside it (`type="button"` on an element passed as the icon). Also an `icon: "…"` in an object literal (a SegmentedControl option, a nav's list of views), in a file that imports LDS or renders an LDS component.
|
|
78
71
|
*/
|
|
79
72
|
function glyphNamesIn(text) {
|
|
80
73
|
const found = [];
|