@assembly-js/app-foundation 0.0.10-rc.1 → 0.0.10
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/bin/check-token-usage.mjs +29 -3
- package/package.json +1 -1
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
// Fails the build if any page reads the session token from `searchParams
|
|
3
|
-
//
|
|
4
|
-
//
|
|
2
|
+
// Fails the build if any page reads the session token from `searchParams` —
|
|
3
|
+
// except in a legacy (pre-bearer) app, where it's the only identity path and
|
|
4
|
+
// this is a warning instead. Dependency-free on purpose: it runs inside the
|
|
5
|
+
// generated app's sandbox before any deps beyond Node exist.
|
|
5
6
|
//
|
|
6
7
|
// Auth is cookie-borne in the bearer model: the foundation middleware exchanges
|
|
7
8
|
// the first-load `?token=` for an HttpOnly bearer cookie exactly once, and
|
|
@@ -10,12 +11,25 @@
|
|
|
10
11
|
// renders its auth-rejection state to everyone after any client-side navigation
|
|
11
12
|
// (`router.push`, `<Link>`), which drops query params. Fetch per-user data via
|
|
12
13
|
// server actions (useServerAction) or authFetch route handlers instead.
|
|
14
|
+
//
|
|
15
|
+
// A legacy app (cloned before the bearer model existed) has no bearer cookie to
|
|
16
|
+
// exchange into — URL-token auth is its only identity path, so the same pattern
|
|
17
|
+
// is expected there, not a bug. Severity is decided by probing two marker files
|
|
18
|
+
// from the checkout root, mirroring ProbeFoundationAuthVersionFromGithub in
|
|
19
|
+
// logic_build.go (mintBearerProbePath / packageWorldProbePath): mint-bearer.ts
|
|
20
|
+
// present -> bearer-capable, fatal; absent + assembly.ts present -> legacy, warn
|
|
21
|
+
// and exit 0; neither present -> package-world app (bearer-capable via
|
|
22
|
+
// @assembly-js/app-foundation in node_modules), fatal as today.
|
|
13
23
|
import { readFileSync, readdirSync, existsSync } from 'node:fs';
|
|
14
24
|
import { join, relative, sep } from 'node:path';
|
|
15
25
|
|
|
16
26
|
const ROOT = process.cwd();
|
|
17
27
|
const APP_DIR = join(ROOT, 'app');
|
|
18
28
|
|
|
29
|
+
// Mirrors mintBearerProbePath / packageWorldProbePath in logic_build.go.
|
|
30
|
+
const MINT_BEARER_PROBE_PATH = 'lib/mint-bearer.ts';
|
|
31
|
+
const PACKAGE_WORLD_PROBE_PATH = 'lib/assembly.ts';
|
|
32
|
+
|
|
19
33
|
function pageFiles(dir) {
|
|
20
34
|
const out = [];
|
|
21
35
|
for (const entry of readdirSync(dir, { withFileTypes: true })) {
|
|
@@ -114,11 +128,23 @@ for (const file of pageFiles(APP_DIR)) {
|
|
|
114
128
|
}
|
|
115
129
|
|
|
116
130
|
if (violations.length > 0) {
|
|
131
|
+
const isLegacy =
|
|
132
|
+
!existsSync(join(ROOT, MINT_BEARER_PROBE_PATH)) && existsSync(join(ROOT, PACKAGE_WORLD_PROBE_PATH));
|
|
133
|
+
|
|
117
134
|
console.error('');
|
|
118
135
|
console.error('A page reads the session token from searchParams:');
|
|
119
136
|
console.error('');
|
|
120
137
|
for (const v of violations) console.error(' - ' + v);
|
|
121
138
|
console.error('');
|
|
139
|
+
|
|
140
|
+
if (isLegacy) {
|
|
141
|
+
console.error('This is a pre-bearer app, so this is a warning, not a build failure:');
|
|
142
|
+
console.error('URL-token auth is its only identity path. Because client-side navigation');
|
|
143
|
+
console.error('(router.push, <Link>) drops query params, any page reading');
|
|
144
|
+
console.error('searchParams.token must thread the token through its outgoing hrefs.');
|
|
145
|
+
process.exit(0);
|
|
146
|
+
}
|
|
147
|
+
|
|
122
148
|
console.error('Auth is in the bearer cookie, not the URL — no page, not even a surface');
|
|
123
149
|
console.error('entry page, should read searchParams.token. getAssembly() and');
|
|
124
150
|
console.error('getSessionIdentity() read the bearer cookie; fetch per-user data via');
|