@milesroxas/design-hub 0.11.2 → 0.13.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 +8 -6
- package/core/prototype.test.ts +52 -0
- package/core/prototype.ts +59 -0
- package/core/review/model.ts +20 -0
- package/core/review/service.test.ts +262 -37
- package/core/review/service.ts +276 -52
- package/core/review/store.ts +12 -6
- package/core/review/suite-kv.ts +17 -0
- package/dist/core/prototype.d.ts +50 -0
- package/dist/core/prototype.js +38 -0
- package/dist/core/review/model.d.ts +22 -0
- package/dist/core/review/model.js +8 -0
- package/dist/core/review/service.d.ts +98 -18
- package/dist/core/review/service.js +248 -46
- package/dist/core/review/store.d.ts +10 -4
- package/dist/core/review/store.js +2 -2
- package/dist/core/review/suite-kv.d.ts +7 -0
- package/dist/core/review/suite-kv.js +12 -0
- package/dist/scripts/client.d.ts +3 -3
- package/dist/scripts/client.js +55 -69
- package/dist/scripts/lib/cli.js +5 -0
- package/dist/scripts/lib/dns.d.ts +32 -0
- package/dist/scripts/lib/dns.js +69 -1
- package/dist/scripts/lib/fake-host.d.ts +35 -11
- package/dist/scripts/lib/fake-host.js +27 -13
- package/dist/scripts/lib/host.d.ts +13 -25
- package/dist/scripts/lib/host.js +15 -324
- package/dist/scripts/lib/studio-deps.d.ts +16 -0
- package/dist/scripts/lib/studio-deps.js +41 -16
- package/dist/scripts/lib/studios.d.ts +17 -5
- package/dist/scripts/lib/studios.js +25 -5
- package/dist/scripts/lib/vercel-host.d.ts +17 -0
- package/dist/scripts/lib/vercel-host.js +410 -0
- package/dist/scripts/people.d.ts +7 -4
- package/dist/scripts/people.js +147 -39
- package/dist/scripts/share.js +3 -2
- package/dist/scripts/studio.d.ts +10 -4
- package/dist/scripts/studio.js +136 -22
- package/dist/server/api.d.ts +12 -13
- package/dist/server/api.js +141 -52
- package/dist/server/gate.d.ts +97 -0
- package/dist/server/gate.js +537 -0
- package/dist/server/hosts.d.ts +3 -3
- package/dist/server/hosts.js +10 -10
- package/dist/server/mark.d.ts +17 -0
- package/dist/server/mark.js +46 -1
- package/dist/server/session.d.ts +9 -1
- package/dist/server/session.js +10 -3
- package/dist/server/stores/backends.d.ts +22 -0
- package/dist/server/stores/backends.js +96 -0
- package/dist/server/{fake-upstash.js → stores/fake-upstash.js} +1 -1
- package/dist/server/stores/index.d.ts +41 -0
- package/dist/server/stores/index.js +63 -0
- package/dist/server/stores/pglite.d.ts +16 -0
- package/dist/server/stores/pglite.js +98 -0
- package/dist/server/stores/postgres.d.ts +63 -0
- package/dist/server/stores/postgres.js +153 -0
- package/dist/server/{upstash.d.ts → stores/upstash.d.ts} +1 -1
- package/dist/vercel/files.js +1 -1
- package/dist/vercel/proxy.d.ts +6 -78
- package/dist/vercel/proxy.js +18 -359
- package/dist/vite/plugin.d.ts +6 -2
- package/dist/vite/plugin.js +22 -4
- package/package.json +3 -1
- package/shell/Index.tsx +29 -0
- package/shell/review/People.tsx +79 -49
- package/shell/review/Review.tsx +49 -1
- package/shell/review/ThreadCard.tsx +13 -1
- package/shell/review/client.ts +54 -21
- package/shell/review/review.css +1 -0
- package/shell/review/unsent.test.ts +63 -0
- package/shell/review/unsent.ts +64 -0
- package/shell/review/view.ts +22 -6
- package/shell/studio/ClientHub.tsx +9 -36
- package/shell/studio/StudioHub.tsx +293 -0
- package/shell/studio/hub.css +80 -5
- package/shell/studio/page.tsx +57 -0
- package/shell/studio/studio.html +14 -0
- package/shell/studio/studio.tsx +19 -0
- package/skills/miles-deploy/SKILL.md +17 -6
- package/skills/miles-design-hub/SKILL.md +3 -3
- package/skills/miles-review/SKILL.md +1 -1
- package/templates/studio/.env.example +3 -0
- package/templates/studio/README.md +45 -13
- package/templates/studio/package.json +1 -1
- /package/dist/server/{fake-upstash.d.ts → stores/fake-upstash.d.ts} +0 -0
- /package/dist/server/{upstash.js → stores/upstash.js} +0 -0
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
// The review store on Postgres: any Postgres by its connection string (Neon,
|
|
3
|
+
// Supabase, a server of your own), in one table `(key, field, value)`, the
|
|
4
|
+
// `KV` port's Redis shape kept as it is (core/review/store.ts). A hash is
|
|
5
|
+
// its key's rows; a set is its key's rows with each member a field and an
|
|
6
|
+
// empty value. No key is ever both (the service never mixes them).
|
|
7
|
+
//
|
|
8
|
+
// Every op is one statement, so each that is atomic on Upstash is atomic
|
|
9
|
+
// here with no transaction and no lock held between statements: `hdel` is a
|
|
10
|
+
// DELETE that answers its row count, `hsetnx` an INSERT … ON CONFLICT DO
|
|
11
|
+
// NOTHING that answers whether it inserted, `hincrby` an INSERT … ON
|
|
12
|
+
// CONFLICT DO UPDATE that adds to the stored value and answers the sum. A
|
|
13
|
+
// statement holds no session state and no named prepared statement, so it
|
|
14
|
+
// runs through a transaction-mode pooler (Neon's and Supabase's pooled URLs).
|
|
15
|
+
//
|
|
16
|
+
// The adapter runs its SQL through a Query, so the conformance suite runs
|
|
17
|
+
// the same statements on an embedded Postgres (server/stores/pglite.ts) and,
|
|
18
|
+
// with DESIGN_HUB_TEST_POSTGRES, on a real server through the driver.
|
|
19
|
+
import postgres from 'postgres';
|
|
20
|
+
/** The table a studio's store is, unless a test names its own. */
|
|
21
|
+
export const TABLE = 'design_hub_kv';
|
|
22
|
+
const IDENT = /^[a-z_][a-z0-9_]{0,62}$/;
|
|
23
|
+
function tableName(table) {
|
|
24
|
+
if (!IDENT.test(table))
|
|
25
|
+
throw new Error(`Not a table name: ${JSON.stringify(table)}.`);
|
|
26
|
+
return table;
|
|
27
|
+
}
|
|
28
|
+
/** The statements, by op: the adapter's whole SQL, in one place. `$t` is the table. */
|
|
29
|
+
export const STATEMENTS = {
|
|
30
|
+
hget: 'SELECT value FROM $t WHERE key = $1 AND field = $2',
|
|
31
|
+
hset: 'INSERT INTO $t (key, field, value) VALUES ($1, $2, $3) ON CONFLICT (key, field) DO UPDATE SET value = EXCLUDED.value',
|
|
32
|
+
hdel: 'DELETE FROM $t WHERE key = $1 AND field = $2',
|
|
33
|
+
hsetnx: 'INSERT INTO $t (key, field, value) VALUES ($1, $2, $3) ON CONFLICT (key, field) DO NOTHING RETURNING 1 AS won',
|
|
34
|
+
hgetall: 'SELECT field, value FROM $t WHERE key = $1',
|
|
35
|
+
// The row is locked by the conflict and the add made on its value as it is then, so two at once both add.
|
|
36
|
+
hincrby: 'INSERT INTO $t AS t (key, field, value) VALUES ($1, $2, ($3::bigint)::text) ON CONFLICT (key, field) DO UPDATE SET value = (t.value::bigint + $3::bigint)::text RETURNING value',
|
|
37
|
+
sadd: "INSERT INTO $t (key, field, value) VALUES ($1, $2, '') ON CONFLICT (key, field) DO NOTHING",
|
|
38
|
+
smembers: 'SELECT field FROM $t WHERE key = $1',
|
|
39
|
+
del: 'DELETE FROM $t WHERE key = $1',
|
|
40
|
+
delPrefix: "DELETE FROM $t WHERE key LIKE $1 ESCAPE '\\'",
|
|
41
|
+
};
|
|
42
|
+
/** The prefix as a LIKE pattern that matches only keys starting with its own text: `\`, `%` and `_` stand for themselves. */
|
|
43
|
+
export const likePrefix = (prefix) => `${prefix.replace(/[\\%_]/g, '\\$&')}%`;
|
|
44
|
+
/**
|
|
45
|
+
* Makes the table when it is not there, and closes it to every role but its
|
|
46
|
+
* owner: row level security on, with no policy. The owner, the role the
|
|
47
|
+
* adapter connects as, is not subject to it; any other role reads and writes
|
|
48
|
+
* nothing, whatever it was granted. That matters on Supabase, whose default
|
|
49
|
+
* grants give every new table in `public` to `anon` and serve it over the
|
|
50
|
+
* project's Data API to anyone with its anon key. Both steps hold for a table
|
|
51
|
+
* already there, so `studio deploy` closes one made before. Run by `studio
|
|
52
|
+
* create` and `studio deploy`, the setup path, never by a visitor's request:
|
|
53
|
+
* the gate and the functions only read and write rows.
|
|
54
|
+
*/
|
|
55
|
+
export async function createTable(query, table = TABLE) {
|
|
56
|
+
const t = tableName(table);
|
|
57
|
+
await query(`CREATE TABLE IF NOT EXISTS ${t} (key text NOT NULL, field text NOT NULL, value text NOT NULL, PRIMARY KEY (key, field))`, []);
|
|
58
|
+
await query(`ALTER TABLE ${t} ENABLE ROW LEVEL SECURITY`, []);
|
|
59
|
+
}
|
|
60
|
+
export function postgresKV(query, table = TABLE) {
|
|
61
|
+
const t = tableName(table);
|
|
62
|
+
const run = (op, params) => query(STATEMENTS[op].replace('$t', t), params);
|
|
63
|
+
return {
|
|
64
|
+
hget: async (key, field) => (await run('hget', [key, field])).rows[0]?.value ?? null,
|
|
65
|
+
hset: async (key, field, value) => {
|
|
66
|
+
await run('hset', [key, field, value]);
|
|
67
|
+
},
|
|
68
|
+
hdel: async (key, field) => (await run('hdel', [key, field])).count,
|
|
69
|
+
hsetnx: async (key, field, value) => (await run('hsetnx', [key, field, value])).rows.length === 1,
|
|
70
|
+
hgetall: async (key) => Object.fromEntries((await run('hgetall', [key])).rows.map((r) => [r.field, r.value])),
|
|
71
|
+
hincrby: async (key, field, by) => Number((await run('hincrby', [key, field, String(by)])).rows[0].value),
|
|
72
|
+
sadd: async (key, member) => {
|
|
73
|
+
await run('sadd', [key, member]);
|
|
74
|
+
},
|
|
75
|
+
smembers: async (key) => (await run('smembers', [key])).rows.map((r) => r.field),
|
|
76
|
+
del: async (key) => {
|
|
77
|
+
await run('del', [key]);
|
|
78
|
+
},
|
|
79
|
+
delPrefix: async (prefix) => {
|
|
80
|
+
await run('delPrefix', [likePrefix(prefix)]);
|
|
81
|
+
},
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
/** A connection string's parts: postgres:// or postgresql://, else null. */
|
|
85
|
+
function parse(url) {
|
|
86
|
+
try {
|
|
87
|
+
const parsed = new URL(url);
|
|
88
|
+
return /^postgres(ql)?:$/.test(parsed.protocol) && parsed.hostname ? parsed : null;
|
|
89
|
+
}
|
|
90
|
+
catch {
|
|
91
|
+
return null;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
export const isPostgresUrl = (url) => !!url && parse(url) !== null;
|
|
95
|
+
const LOCAL = new Set(['localhost', '127.0.0.1', '[::1]', '::1']);
|
|
96
|
+
/**
|
|
97
|
+
* Which database a connection string names, with no credential in it:
|
|
98
|
+
* `postgres://<host>:<port>/<database>`. The gate signs it into every token
|
|
99
|
+
* (server/session.ts), as it does Upstash's URL, so two studios with one
|
|
100
|
+
* GATE_SECRET never take each other's cookies.
|
|
101
|
+
*/
|
|
102
|
+
export function postgresSite(url) {
|
|
103
|
+
const u = parse(url);
|
|
104
|
+
if (!u)
|
|
105
|
+
return '';
|
|
106
|
+
const database = decodeURIComponent(u.pathname.slice(1)) || decodeURIComponent(u.username);
|
|
107
|
+
return `postgres://${u.hostname.toLowerCase()}:${u.port || '5432'}/${database}`;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* TLS for a connection: always for a host other than this machine, whatever
|
|
111
|
+
* the string says, verified against the system's authorities when its
|
|
112
|
+
* `sslmode` is verify-full or verify-ca, and otherwise encrypted unverified,
|
|
113
|
+
* as libpq does for `sslmode=require` (what Neon's and Supabase's strings
|
|
114
|
+
* say). This machine's own server is plain unless the string asks for TLS.
|
|
115
|
+
*/
|
|
116
|
+
export function tlsFor(url) {
|
|
117
|
+
const u = parse(url);
|
|
118
|
+
const mode = u?.searchParams.get('sslmode') ?? '';
|
|
119
|
+
if (mode === 'verify-full' || mode === 'verify-ca')
|
|
120
|
+
return 'verify-full';
|
|
121
|
+
if (u && LOCAL.has(u.hostname))
|
|
122
|
+
return mode === 'require' ? 'require' : false;
|
|
123
|
+
return 'require';
|
|
124
|
+
}
|
|
125
|
+
/** At most this many connections per instance, reused across requests. */
|
|
126
|
+
const POOL = 3;
|
|
127
|
+
/**
|
|
128
|
+
* A Query on the driver (postgres.js) for one connection string. The string's
|
|
129
|
+
* query parameters are dropped (the driver would send `channel_binding` and
|
|
130
|
+
* the like to the server as settings) and TLS set by tlsFor. Unnamed
|
|
131
|
+
* statements only (`prepare: false`), so a transaction-mode pooler can run
|
|
132
|
+
* each on any server connection; no type lookup on connect; no notices
|
|
133
|
+
* printed, since a command's stdout is its one JSON object.
|
|
134
|
+
*/
|
|
135
|
+
export function driverQuery(url) {
|
|
136
|
+
const u = parse(url);
|
|
137
|
+
if (!u)
|
|
138
|
+
throw new Error('Not a Postgres connection string.');
|
|
139
|
+
const sql = postgres(`${u.protocol}//${u.username}${u.password ? `:${u.password}` : ''}@${u.host}${u.pathname}`, {
|
|
140
|
+
ssl: tlsFor(url),
|
|
141
|
+
max: POOL,
|
|
142
|
+
idle_timeout: 20,
|
|
143
|
+
connect_timeout: 10,
|
|
144
|
+
prepare: false,
|
|
145
|
+
fetch_types: false,
|
|
146
|
+
onnotice: () => { },
|
|
147
|
+
});
|
|
148
|
+
const query = async (text, params) => {
|
|
149
|
+
const result = await sql.unsafe(text, params);
|
|
150
|
+
return { rows: [...result], count: result.count ?? 0 };
|
|
151
|
+
};
|
|
152
|
+
return Object.assign(query, { end: () => sql.end() });
|
|
153
|
+
}
|
package/dist/vercel/files.js
CHANGED
|
@@ -7,8 +7,8 @@
|
|
|
7
7
|
// `private, no-store` with no ETag, so every view reads it fresh.
|
|
8
8
|
import { filePath } from '../core/files.js';
|
|
9
9
|
import { blobFiles } from '../server/blob.js';
|
|
10
|
+
import { admit, DEFAULT_SITE_NAME, findPlace, isRead, notFound, plain, refuse, storeDown, } from '../server/gate.js';
|
|
10
11
|
import { hostCache } from '../server/hosts.js';
|
|
11
|
-
import { admit, DEFAULT_SITE_NAME, findPlace, isRead, notFound, plain, refuse, storeDown, } from './proxy.js';
|
|
12
12
|
/** A path's last segment names a file (`app.js`) rather than a page of the hub (`guide`, a prototype). */
|
|
13
13
|
const isFileName = (file) => (file.at(-1) ?? '').includes('.');
|
|
14
14
|
/**
|
package/dist/vercel/proxy.d.ts
CHANGED
|
@@ -1,78 +1,6 @@
|
|
|
1
|
-
import { GATE_FONT, type
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
export declare
|
|
7
|
-
export { GATE_FONT };
|
|
8
|
-
export declare function gatePreview(page: string | null, siteName?: string): Promise<{
|
|
9
|
-
html: string;
|
|
10
|
-
csp: string;
|
|
11
|
-
}>;
|
|
12
|
-
export declare const isRead: (request: Request) => boolean;
|
|
13
|
-
type Extra = {
|
|
14
|
-
cookie?: string;
|
|
15
|
-
allow?: string;
|
|
16
|
-
referrer?: 'no-referrer' | 'same-origin';
|
|
17
|
-
/** Seconds, on a 503 that passes (a store that did not answer), so the review panel retries instead of switching off. */
|
|
18
|
-
retryAfter?: number;
|
|
19
|
-
};
|
|
20
|
-
export declare const plain: (request: Request, status: number, text: string, extra?: Extra) => Response;
|
|
21
|
-
/** One answer for a prototype a Client may not have, whether it is internal or not there at all. */
|
|
22
|
-
export declare const notFound: (request: Request) => Response;
|
|
23
|
-
/** The store did not answer: a 503 that passes, so it says when to try again. */
|
|
24
|
-
export declare const storeDown: (request: Request) => Response;
|
|
25
|
-
/** One request at one moment: `at` is the gate's clock, so freshness is tested without waiting. */
|
|
26
|
-
export type Ctx = {
|
|
27
|
-
siteName: string;
|
|
28
|
-
request: Request;
|
|
29
|
-
at: Date;
|
|
30
|
-
};
|
|
31
|
-
export type ProxyOptions = {
|
|
32
|
-
/** The gate pages' title, the same on every client's host. */
|
|
33
|
-
siteName?: string;
|
|
34
|
-
/** The gate's clock; tests move it instead of waiting. */
|
|
35
|
-
now?: () => Date;
|
|
36
|
-
};
|
|
37
|
-
/** Who a request's host is: its client, and the gate and the client's scope built from that one lookup. */
|
|
38
|
-
export type Place = {
|
|
39
|
-
client: Client;
|
|
40
|
-
gate: Gate;
|
|
41
|
-
scope: Scope;
|
|
42
|
-
};
|
|
43
|
-
/** A request on a studio site that names a known client. */
|
|
44
|
-
export type Found = {
|
|
45
|
-
review: Review;
|
|
46
|
-
place: Place;
|
|
47
|
-
route: Route;
|
|
48
|
-
};
|
|
49
|
-
/** Why a studio request ends before it is served; `refuse` answers each one the same wherever it is met. */
|
|
50
|
-
export type Refusal = {
|
|
51
|
-
refused: 'not-found';
|
|
52
|
-
} | {
|
|
53
|
-
refused: 'store-down';
|
|
54
|
-
} | {
|
|
55
|
-
refused: 'unavailable';
|
|
56
|
-
error: string;
|
|
57
|
-
} | {
|
|
58
|
-
refused: 'signed-out';
|
|
59
|
-
stale: boolean;
|
|
60
|
-
};
|
|
61
|
-
/** The client `pathname` is asked of on the request's host, or why there is none: an unknown host is the plain 404. */
|
|
62
|
-
export declare function findPlace(request: Request, pathname: string, hosts: HostLookup, at: Date): Promise<Found | Refusal>;
|
|
63
|
-
/** A request that may go on: who asks, the person to re-issue a cookie for, and the project it is for. */
|
|
64
|
-
export type Admitted = Found & {
|
|
65
|
-
kind: PersonKind;
|
|
66
|
-
current: Person | null;
|
|
67
|
-
project: Project | null;
|
|
68
|
-
};
|
|
69
|
-
/**
|
|
70
|
-
* The checks every studio request passes, in the gate and again in the files
|
|
71
|
-
* function: a session signed to this host's client (asked of the store again
|
|
72
|
-
* once its stamp is stale), then the boundary.
|
|
73
|
-
*/
|
|
74
|
-
export declare function admit(found: Found, request: Request, at: Date): Promise<Admitted | Refusal>;
|
|
75
|
-
/** The answer for a refusal: the same from the gate and from the files function. */
|
|
76
|
-
export declare function refuse(ctx: Ctx, refusal: Refusal): Promise<Response> | Response;
|
|
77
|
-
/** The middleware a studio site's proxy.ts default-exports. Its sign-in page names no client (S10). */
|
|
78
|
-
export declare function createStudioProxy({ siteName, now, }?: ProxyOptions): (request: Request) => Promise<Response>;
|
|
1
|
+
import { type Decision, GATE_FONT, gatePreview, type ProxyOptions } from '../server/gate.ts';
|
|
2
|
+
export { GATE_FONT, gatePreview };
|
|
3
|
+
/** A gate's decision as Vercel's middleware answers it. */
|
|
4
|
+
export declare function onVercel(decision: Decision): Response;
|
|
5
|
+
/** The middleware a studio site's proxy.ts default-exports. */
|
|
6
|
+
export declare function createStudioProxy(options?: ProxyOptions): (request: Request) => Promise<Response>;
|
package/dist/vercel/proxy.js
CHANGED
|
@@ -1,364 +1,23 @@
|
|
|
1
1
|
// Vercel Routing Middleware (a studio site's proxy.ts, named in vercel.json
|
|
2
|
-
// as proxy.entrypoint): the gate
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
//
|
|
6
|
-
// GET /invite/<token> shows who the link is for, and uses nothing up, so
|
|
7
|
-
// a mail or chat preview that opens it costs nothing
|
|
8
|
-
// POST /invite/<token> uses the link up, sets the person's signed cookie
|
|
9
|
-
// (server/session.ts) and goes to the client's hub
|
|
10
|
-
//
|
|
11
|
-
// A used, expired or unknown link is 404. Every other path needs the cookie,
|
|
12
|
-
// signed to the host's client. It carries when the store last said yes;
|
|
13
|
-
// after CHECK_SECONDS (5 minutes) the gate asks the store again on the next
|
|
14
|
-
// request of any kind, so a revoke, a sign out everywhere or a changed access
|
|
15
|
-
// end reaches every request within minutes. A store that does not answer is
|
|
16
|
-
// 503, never a sign out. A Client asking for a prototype that is not
|
|
17
|
-
// client-facing, its page or any file built from it under
|
|
18
|
-
// /<project>/_p/<slug>/, gets 404. Without a session a page gets the sign-in
|
|
19
|
-
// page (401), which says what to do and has no form, and anything else a
|
|
20
|
-
// plain-text 401. Without GATE_SECRET or the store the gate fails closed (503).
|
|
2
|
+
// as proxy.entrypoint): the gate (server/gate.ts), with its decisions carried
|
|
3
|
+
// out the way Vercel's middleware does, `next()` to pass on and `rewrite()`
|
|
4
|
+
// to go on to a function. Everything the gate decides is in the gate; this
|
|
5
|
+
// file only says it in Vercel's words.
|
|
21
6
|
import { next, rewrite } from '@vercel/functions';
|
|
22
|
-
import {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
// inlined, never the project's brand. Geist (latin, variable) is the one
|
|
36
|
-
// font, preloaded so the first paint is already in it.
|
|
37
|
-
const CSS = `
|
|
38
|
-
@font-face{font-family:Geist;src:url(${GATE_FONT}) format("woff2");font-weight:100 900;font-style:normal;font-display:swap}
|
|
39
|
-
:root{color-scheme:light;--bg:oklch(.985 0 0);--surface:oklch(1 0 0);--ink:oklch(.205 0 0);--ink-3:oklch(.46 0 0);--brand:oklch(.205 0 0);--brand-hover:oklch(.3 0 0);--on-brand:oklch(.985 0 0);--ring:0 0 0 2px oklch(1 0 0),0 0 0 4px oklch(.556 0 0);--shadow:0 1px 2px 0 oklch(0 0 0/.05);--raised:0 0 0 1px oklch(0 0 0/.06),0 1px 2px oklch(0 0 0/.05),0 12px 24px -8px oklch(0 0 0/.1);--ease-out:cubic-bezier(.23,1,.32,1);--ease-press:cubic-bezier(.33,1,.68,1);--ease-hover:cubic-bezier(.25,.46,.45,.94)}
|
|
40
|
-
@media(prefers-color-scheme:dark){:root{color-scheme:dark;--bg:oklch(.145 0 0);--surface:oklch(.175 0 0);--ink:oklch(.985 0 0);--ink-3:oklch(.72 0 0);--brand:oklch(.985 0 0);--brand-hover:oklch(.87 0 0);--on-brand:oklch(.205 0 0);--ring:0 0 0 2px oklch(.175 0 0),0 0 0 4px oklch(.708 0 0);--shadow:0 0 #0000;--raised:0 0 0 1px oklch(1 0 0/.09)}}
|
|
41
|
-
*{box-sizing:border-box}
|
|
42
|
-
html{height:100%;-webkit-text-size-adjust:100%;-webkit-tap-highlight-color:transparent}
|
|
43
|
-
body{margin:0;min-height:100%;display:grid;place-items:center;padding:max(24px,env(safe-area-inset-top)) max(16px,env(safe-area-inset-right)) max(24px,env(safe-area-inset-bottom)) max(16px,env(safe-area-inset-left));background:var(--bg);color:var(--ink);font:14px/20px Geist,ui-sans-serif,system-ui,-apple-system,"Segoe UI",sans-serif;font-optical-sizing:auto;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale;text-rendering:optimizeLegibility}
|
|
44
|
-
.gate{width:100%;max-width:360px;padding:32px;background:var(--surface);border-radius:12px;box-shadow:var(--raised);transition:opacity 240ms var(--ease-out),transform 240ms var(--ease-out)}
|
|
45
|
-
@starting-style{.gate{opacity:0;transform:translateY(6px)}}
|
|
46
|
-
h1{margin:0 0 4px;font-size:20px;line-height:28px;font-weight:600;letter-spacing:-.02em;text-wrap:balance}
|
|
47
|
-
p{margin:0;color:var(--ink-3);text-wrap:pretty}
|
|
48
|
-
p+p{margin-top:8px}
|
|
49
|
-
strong{font-weight:500;color:var(--ink)}
|
|
50
|
-
form{margin:0}
|
|
51
|
-
.go{display:block;width:100%;height:44px;margin-top:24px;padding:0;border:0;border-radius:6px;background:var(--brand);color:var(--on-brand);font:inherit;font-weight:500;line-height:44px;text-align:center;text-decoration:none;cursor:pointer;touch-action:manipulation;-webkit-user-select:none;user-select:none;box-shadow:var(--shadow);transition:background-color 120ms var(--ease-hover),transform 160ms var(--ease-press)}
|
|
52
|
-
.go:focus-visible{outline:2px solid transparent;outline-offset:2px;box-shadow:var(--ring)}
|
|
53
|
-
.go:active{transform:scale(.97)}
|
|
54
|
-
@media(hover:hover) and (pointer:fine){.go:hover{background:var(--brand-hover)}}
|
|
55
|
-
@media(max-width:400px){.gate{padding:24px}}
|
|
56
|
-
@media(prefers-reduced-motion:reduce){.gate{transition:opacity 240ms var(--ease-out)}@starting-style{.gate{transform:none}}.go:active{transform:none}}
|
|
57
|
-
`;
|
|
58
|
-
function shell(siteName, page, body) {
|
|
59
|
-
return `<!doctype html>
|
|
60
|
-
<html lang="en">
|
|
61
|
-
<head>
|
|
62
|
-
<meta charset="utf-8">
|
|
63
|
-
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover">
|
|
64
|
-
<meta name="robots" content="noindex, nofollow">
|
|
65
|
-
<meta name="color-scheme" content="light dark">
|
|
66
|
-
<title>${escapeHtml(siteName)}</title>
|
|
67
|
-
<link rel="icon" type="image/svg+xml" href="/favicon.svg">
|
|
68
|
-
<link rel="preload" href="${GATE_FONT}" as="font" type="font/woff2" crossorigin>
|
|
69
|
-
<style>${CSS}</style>
|
|
70
|
-
</head>
|
|
71
|
-
<body>
|
|
72
|
-
<main class="gate" data-gate="${page}">
|
|
73
|
-
<h1>${escapeHtml(siteName)}</h1>
|
|
74
|
-
${body}
|
|
75
|
-
</main>
|
|
76
|
-
</body>
|
|
77
|
-
</html>
|
|
78
|
-
`;
|
|
79
|
-
}
|
|
80
|
-
const signInPage = (siteName) => shell(siteName, 'sign-in', `<p>To sign in, open the link the studio sent you. Each link signs in one device, then stops working.</p>
|
|
81
|
-
<p>For another device, or if your link has stopped working, ask the studio for a new one.</p>`);
|
|
82
|
-
// A GET shows who the link is for and a POST signs them in, so a mail
|
|
83
|
-
// scanner that opens every link never uses it up.
|
|
84
|
-
const linkPage = (siteName, person) => shell(siteName, 'link', `<p>This link signs in <strong>${escapeHtml(person.name)}</strong>, ${escapeHtml(person.team)}, on this device.</p>
|
|
85
|
-
<p>It works once. For another device, ask the studio for a new link.</p>
|
|
86
|
-
<form method="post"><button class="go" type="submit" autofocus>Continue</button></form>`);
|
|
87
|
-
// Someone who opens their link again on a device it already signed in gets
|
|
88
|
-
// here too, so the page offers the way in as well.
|
|
89
|
-
const usedPage = (siteName) => shell(siteName, 'used', `<p>This link has been used, has expired or was removed. Each link signs in one device, then stops working.</p>
|
|
90
|
-
<p>Ask the studio for a new one. If this device is already signed in, open the prototypes.</p>
|
|
91
|
-
<a class="go" href="/">Open the prototypes</a>`);
|
|
92
|
-
const SIGNED_OUT = 'Sign in with the link the studio sent you.';
|
|
93
|
-
const USED = 'This link has been used, has expired or was removed.';
|
|
94
|
-
const OPEN_IN_BROWSER = 'Open this link in a browser to sign in.';
|
|
95
|
-
const PREVIEWS = {
|
|
96
|
-
'sign-in': signInPage,
|
|
97
|
-
link: (siteName) => linkPage(siteName, { name: 'Rae Chen', team: 'Acme' }),
|
|
98
|
-
used: usedPage,
|
|
99
|
-
};
|
|
100
|
-
// `design-hub dev` has no gate; the Vite plugin serves this at /_gate/ (?page=link or ?page=used) so the pages can be reviewed.
|
|
101
|
-
export async function gatePreview(page, siteName = DEFAULT_SITE_NAME) {
|
|
102
|
-
// hasOwn, so ?page=__proto__ or toString never reaches Object.prototype.
|
|
103
|
-
const render = page !== null && Object.hasOwn(PREVIEWS, page) ? PREVIEWS[page] : signInPage;
|
|
104
|
-
return { html: render(siteName), csp: await csp() };
|
|
105
|
-
}
|
|
106
|
-
let cspPromise;
|
|
107
|
-
function csp() {
|
|
108
|
-
cspPromise ??= sha256(CSS).then((css) => `default-src 'none'; style-src 'sha256-${base64(css)}'; script-src 'none'; font-src 'self'; img-src 'self'; form-action 'self'; base-uri 'none'; frame-ancestors 'none'`);
|
|
109
|
-
return cspPromise;
|
|
110
|
-
}
|
|
111
|
-
const NO_STORE = 'no-store, max-age=0';
|
|
112
|
-
function wantsHtml(request) {
|
|
113
|
-
const dest = request.headers.get('sec-fetch-dest');
|
|
114
|
-
if (dest)
|
|
115
|
-
return dest === 'document' || dest === 'iframe';
|
|
116
|
-
return (request.headers.get('accept') ?? '').includes('text/html');
|
|
117
|
-
}
|
|
118
|
-
export const isRead = (request) => request.method === 'GET' || request.method === 'HEAD';
|
|
119
|
-
/**
|
|
120
|
-
* Every answer the gate makes itself carries these: never cached, never
|
|
121
|
-
* indexed, no referrer. The link page alone sends a same-origin referrer, so
|
|
122
|
-
* its Continue POST carries a real Origin: with no-referrer a browser sends
|
|
123
|
-
* `Origin: null`, which sameOrigin trusts only beside Sec-Fetch-Site, and
|
|
124
|
-
* older Safari sends no Sec-Fetch-Site.
|
|
125
|
-
*/
|
|
126
|
-
function gateHeaders(type, { cookie, allow, referrer = 'no-referrer', retryAfter }) {
|
|
127
|
-
const headers = new Headers({
|
|
128
|
-
'cache-control': NO_STORE,
|
|
129
|
-
'content-type': type,
|
|
130
|
-
'x-robots-tag': 'noindex, nofollow',
|
|
131
|
-
'referrer-policy': referrer,
|
|
132
|
-
});
|
|
133
|
-
if (cookie)
|
|
134
|
-
headers.append('set-cookie', cookie);
|
|
135
|
-
if (allow)
|
|
136
|
-
headers.set('allow', allow);
|
|
137
|
-
if (retryAfter)
|
|
138
|
-
headers.set('retry-after', String(retryAfter));
|
|
139
|
-
return headers;
|
|
140
|
-
}
|
|
141
|
-
export const plain = (request, status, text, extra = {}) => new Response(request.method === 'HEAD' ? null : text, {
|
|
142
|
-
status,
|
|
143
|
-
headers: gateHeaders('text/plain; charset=utf-8', extra),
|
|
144
|
-
});
|
|
145
|
-
/** A gate page for a browser, or `text` for anything else (a fetch, an asset, a preview bot). */
|
|
146
|
-
async function page(request, status, html, text, extra = {}) {
|
|
147
|
-
if (!wantsHtml(request))
|
|
148
|
-
return plain(request, status, text, extra);
|
|
149
|
-
const headers = gateHeaders('text/html; charset=utf-8', extra);
|
|
150
|
-
headers.set('content-security-policy', await csp());
|
|
151
|
-
return new Response(request.method === 'HEAD' ? null : html, { status, headers });
|
|
152
|
-
}
|
|
153
|
-
const unavailable = (request, error) => plain(request, 503, error);
|
|
154
|
-
/** One answer for a prototype a Client may not have, whether it is internal or not there at all. */
|
|
155
|
-
export const notFound = (request) => plain(request, 404, NOT_FOUND);
|
|
156
|
-
const NOT_FOUND = 'Not found.';
|
|
157
|
-
/** The store did not answer: a 503 that passes, so it says when to try again. */
|
|
158
|
-
export const storeDown = (request) => plain(request, 503, STORE_DOWN, { retryAfter: 30 });
|
|
159
|
-
const STORE_DOWN = 'The review store did not answer. Try again in a minute.';
|
|
160
|
-
/**
|
|
161
|
-
* A store call that can fail without signing anyone out: `undefined` when the
|
|
162
|
-
* store did not answer, so the caller answers 503 and leaves the cookie alone.
|
|
163
|
-
*/
|
|
164
|
-
async function ask(run) {
|
|
165
|
-
try {
|
|
166
|
-
return await run();
|
|
167
|
-
}
|
|
168
|
-
catch (error) {
|
|
169
|
-
console.error('[gate]', error);
|
|
170
|
-
return undefined;
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
async function showLink(ctx, review, scope, token) {
|
|
174
|
-
const { siteName, request } = ctx;
|
|
175
|
-
const person = await ask(() => review.peekLink(scope, token));
|
|
176
|
-
if (person === undefined)
|
|
177
|
-
return storeDown(request);
|
|
178
|
-
return person
|
|
179
|
-
? page(request, 200, linkPage(siteName, person), OPEN_IN_BROWSER, { referrer: 'same-origin' })
|
|
180
|
-
: page(request, 404, usedPage(siteName), USED);
|
|
181
|
-
}
|
|
182
|
-
/** The cookie for someone the store just said yes to, lasting to their access end. */
|
|
183
|
-
async function sessionFor(gate, person, at) {
|
|
184
|
-
const claim = { id: person.id, epoch: person.epoch, kind: person.kind };
|
|
185
|
-
const token = await issuePersonToken(gate, claim, person.accessEndsAt, at);
|
|
186
|
-
return sessionCookie(PERSON_COOKIE, token, sessionSeconds(person.accessEndsAt, at));
|
|
187
|
-
}
|
|
188
|
-
async function signInWithLink(ctx, { review, gate }, scope, token) {
|
|
189
|
-
const { siteName, request, at } = ctx;
|
|
190
|
-
const person = await ask(() => review.useLink(scope, token));
|
|
191
|
-
if (person === undefined)
|
|
192
|
-
return storeDown(request);
|
|
193
|
-
if (!person)
|
|
194
|
-
return page(request, 404, usedPage(siteName), USED);
|
|
195
|
-
const headers = gateHeaders('text/plain; charset=utf-8', { cookie: await sessionFor(gate, person, at) });
|
|
196
|
-
headers.set('location', '/');
|
|
197
|
-
return new Response(null, { status: 303, headers });
|
|
198
|
-
}
|
|
199
|
-
/** A one-time link in `scope`: shown on a read, used on a same-origin POST. */
|
|
200
|
-
async function link(ctx, setup, scope, token) {
|
|
201
|
-
const { request } = ctx;
|
|
202
|
-
if (request.method === 'POST' && !sameOrigin(request))
|
|
203
|
-
return plain(request, 403, 'Forbidden');
|
|
204
|
-
if (request.method !== 'POST' && !isRead(request))
|
|
205
|
-
return plain(request, 405, 'Method not allowed', { allow: 'GET, HEAD, POST' });
|
|
206
|
-
return request.method === 'POST'
|
|
207
|
-
? signInWithLink(ctx, setup, scope, token)
|
|
208
|
-
: showLink(ctx, setup.review, scope, token);
|
|
209
|
-
}
|
|
210
|
-
/**
|
|
211
|
-
* No session. A page gets the sign-in page, and anything else (an asset, a
|
|
212
|
-
* fetch, a POST to any path but a link) a plain 401: there is nothing to
|
|
213
|
-
* sign in with here. A cookie that was sent but does not hold is cleared.
|
|
214
|
-
*/
|
|
215
|
-
function signedOut({ siteName, request }, staleCookie) {
|
|
216
|
-
const extra = staleCookie ? { cookie: clearedCookie(PERSON_COOKIE) } : {};
|
|
217
|
-
if (!isRead(request))
|
|
218
|
-
return plain(request, 401, SIGNED_OUT, extra);
|
|
219
|
-
return page(request, 401, signInPage(siteName), SIGNED_OUT, extra);
|
|
220
|
-
}
|
|
221
|
-
const passHeaders = (cookie) => ({
|
|
222
|
-
'cache-control': 'private, no-store',
|
|
223
|
-
...(cookie ? { 'set-cookie': cookie } : {}),
|
|
224
|
-
});
|
|
225
|
-
/**
|
|
226
|
-
* Whether a prototype is open to a Client in `scope`: client-facing, asked of
|
|
227
|
-
* the store on every request, no cache. A name that is no prototype slug
|
|
228
|
-
* (`all.js`, or '' for a path that could mean more than one file) is never
|
|
229
|
-
* open, without asking. `undefined` when the store did not answer.
|
|
230
|
-
*/
|
|
231
|
-
async function prototypeOpen(review, scope, slug) {
|
|
232
|
-
if (!isPrototypeSlug(slug))
|
|
233
|
-
return false;
|
|
234
|
-
const audience = await ask(() => review.audienceOf(scope, slug));
|
|
235
|
-
return audience === undefined ? undefined : audience === 'client';
|
|
236
|
-
}
|
|
237
|
-
const NOT_THERE = { refused: 'not-found' };
|
|
238
|
-
const DOWN = { refused: 'store-down' };
|
|
239
|
-
/** The client `pathname` is asked of on the request's host, or why there is none: an unknown host is the plain 404. */
|
|
240
|
-
export async function findPlace(request, pathname, hosts, at) {
|
|
241
|
-
const setup = studioReview(process.env, null, () => at);
|
|
242
|
-
if ('error' in setup)
|
|
243
|
-
return { refused: 'unavailable', error: setup.error };
|
|
244
|
-
const route = routeOf(hostOf(request), pathname);
|
|
245
|
-
const client = route.host ? await ask(() => hosts(route.host, (h) => setup.review.clientOfHost(h))) : null;
|
|
246
|
-
if (client === undefined)
|
|
247
|
-
return DOWN;
|
|
248
|
-
if (!client)
|
|
249
|
-
return NOT_THERE;
|
|
250
|
-
const gate = { ...setup.keys, client: client.slug, since: client.createdAt };
|
|
251
|
-
const place = { client, gate, scope: { client: client.slug } };
|
|
252
|
-
return { review: setup.review, place, route };
|
|
253
|
-
}
|
|
254
|
-
/**
|
|
255
|
-
* The project a route names, when it is the client's, and for a Client, only
|
|
256
|
-
* a client-facing prototype's files. Every other answer is the plain 404, so
|
|
257
|
-
* another client's project, a project with no build (its files and its
|
|
258
|
-
* review API alike) and an internal prototype read the same as a path that
|
|
259
|
-
* is not there.
|
|
260
|
-
*/
|
|
261
|
-
async function boundary({ review, place, route }, kind) {
|
|
262
|
-
if (route.kind === 'none' || route.kind === 'link')
|
|
263
|
-
return NOT_THERE;
|
|
264
|
-
const named = route.kind === 'file' || route.kind === 'api' ? route.project : null;
|
|
265
|
-
if (named === null)
|
|
266
|
-
return null;
|
|
267
|
-
const scope = { client: place.client.slug, project: named };
|
|
268
|
-
const project = await ask(() => review.projectOf(scope));
|
|
269
|
-
if (project === undefined)
|
|
270
|
-
return DOWN;
|
|
271
|
-
if (!project || project.build === null)
|
|
272
|
-
return NOT_THERE;
|
|
273
|
-
if (route.kind !== 'file' || route.prototype === null || kind === 'studio')
|
|
274
|
-
return project;
|
|
275
|
-
const open = await prototypeOpen(review, scope, route.prototype);
|
|
276
|
-
return open === undefined ? DOWN : open ? project : NOT_THERE;
|
|
277
|
-
}
|
|
278
|
-
/**
|
|
279
|
-
* The checks every studio request passes, in the gate and again in the files
|
|
280
|
-
* function: a session signed to this host's client (asked of the store again
|
|
281
|
-
* once its stamp is stale), then the boundary.
|
|
282
|
-
*/
|
|
283
|
-
export async function admit(found, request, at) {
|
|
284
|
-
const cookie = readCookie(request, PERSON_COOKIE);
|
|
285
|
-
const claim = await readPersonToken(found.place.gate, cookie, at);
|
|
286
|
-
if (!claim)
|
|
287
|
-
return { refused: 'signed-out', stale: cookie !== undefined };
|
|
288
|
-
let current = null;
|
|
289
|
-
if (!isFresh(claim, at)) {
|
|
290
|
-
const asked = await ask(() => found.review.sessionPerson(found.place.scope, claim.id, claim.epoch));
|
|
291
|
-
if (asked === undefined)
|
|
292
|
-
return DOWN;
|
|
293
|
-
if (!asked)
|
|
294
|
-
return { refused: 'signed-out', stale: true };
|
|
295
|
-
current = asked;
|
|
296
|
-
}
|
|
297
|
-
const kind = current ? current.kind : claim.kind;
|
|
298
|
-
const project = await boundary(found, kind);
|
|
299
|
-
return project && 'refused' in project ? project : { ...found, kind, current, project };
|
|
300
|
-
}
|
|
301
|
-
/** The answer for a refusal: the same from the gate and from the files function. */
|
|
302
|
-
export function refuse(ctx, refusal) {
|
|
303
|
-
switch (refusal.refused) {
|
|
304
|
-
case 'not-found':
|
|
305
|
-
return notFound(ctx.request);
|
|
306
|
-
case 'store-down':
|
|
307
|
-
return storeDown(ctx.request);
|
|
308
|
-
case 'unavailable':
|
|
309
|
-
return unavailable(ctx.request, refusal.error);
|
|
310
|
-
case 'signed-out':
|
|
311
|
-
return signedOut(ctx, refusal.stale);
|
|
312
|
-
}
|
|
313
|
-
}
|
|
314
|
-
/**
|
|
315
|
-
* Where an admitted request goes on to: a project's file to the files
|
|
316
|
-
* function and its review API to the review function, each with the project
|
|
317
|
-
* the path named, and anything else on to the site's own files.
|
|
318
|
-
*/
|
|
319
|
-
function onward(url, route, cookie) {
|
|
320
|
-
const headers = passHeaders(cookie);
|
|
321
|
-
if (route.kind === 'file')
|
|
322
|
-
return rewrite(new URL(`/api/files?path=${encodeURIComponent(url.pathname)}`, url), { headers });
|
|
323
|
-
if (route.kind !== 'api' || route.project === null)
|
|
324
|
-
return next({ headers });
|
|
325
|
-
const to = new URL(`/api/review${url.search}`, url);
|
|
326
|
-
to.searchParams.set('project', route.project);
|
|
327
|
-
return rewrite(to, { headers });
|
|
328
|
-
}
|
|
329
|
-
/**
|
|
330
|
-
* The host proof `client add` asks a new client's host for (PROOF_PATH): its
|
|
331
|
-
* answer, on a GET whose ask the store holds for this host's client. Any
|
|
332
|
-
* other ask, method or store failure goes on as the hub path it is, so the
|
|
333
|
-
* path tells a caller without the ask nothing, and a host no client has
|
|
334
|
-
* never gets here (findPlace's plain 404).
|
|
335
|
-
*/
|
|
336
|
-
async function proven({ review, place, route }, request, pathname) {
|
|
337
|
-
const given = route.kind === 'hub' && request.method === 'GET' ? pathname.match(PROOF_PATH)?.[1] : undefined;
|
|
338
|
-
const answer = given ? await ask(() => review.proofAnswer(place.scope, given)) : null;
|
|
339
|
-
return answer ? plain(request, 200, answer) : null;
|
|
340
|
-
}
|
|
341
|
-
/** The middleware a studio site's proxy.ts default-exports. Its sign-in page names no client (S10). */
|
|
342
|
-
export function createStudioProxy({ siteName = DEFAULT_SITE_NAME, now = () => new Date(), } = {}) {
|
|
343
|
-
const hosts = hostCache(now);
|
|
7
|
+
import { createGate, GATE_FONT, gatePreview } from '../server/gate.js';
|
|
8
|
+
export { GATE_FONT, gatePreview };
|
|
9
|
+
/** A gate's decision as Vercel's middleware answers it. */
|
|
10
|
+
export function onVercel(decision) {
|
|
11
|
+
if (decision instanceof Response)
|
|
12
|
+
return decision;
|
|
13
|
+
if (decision.pass === 'rewrite')
|
|
14
|
+
return rewrite(decision.to, { headers: decision.headers });
|
|
15
|
+
return decision.headers ? next({ headers: decision.headers }) : next();
|
|
16
|
+
}
|
|
17
|
+
/** The middleware a studio site's proxy.ts default-exports. */
|
|
18
|
+
export function createStudioProxy(options = {}) {
|
|
19
|
+
const gate = createGate(options);
|
|
344
20
|
return async function proxy(request) {
|
|
345
|
-
|
|
346
|
-
const url = new URL(request.url);
|
|
347
|
-
const found = await findPlace(request, url.pathname, hosts, ctx.at);
|
|
348
|
-
if ('refused' in found)
|
|
349
|
-
return refuse(ctx, found);
|
|
350
|
-
const proof = await proven(found, request, url.pathname);
|
|
351
|
-
if (proof)
|
|
352
|
-
return proof;
|
|
353
|
-
const { route, place } = found;
|
|
354
|
-
if (route.kind === 'link')
|
|
355
|
-
return link(ctx, { review: found.review, gate: place.gate }, place.scope, route.token);
|
|
356
|
-
if (route.kind === 'asset' && isRead(request))
|
|
357
|
-
return next();
|
|
358
|
-
const admitted = await admit(found, request, ctx.at);
|
|
359
|
-
if ('refused' in admitted)
|
|
360
|
-
return refuse(ctx, admitted);
|
|
361
|
-
const cookie = admitted.current ? await sessionFor(place.gate, admitted.current, ctx.at) : undefined;
|
|
362
|
-
return onward(url, route, cookie);
|
|
21
|
+
return onVercel(await gate(request));
|
|
363
22
|
};
|
|
364
23
|
}
|
package/dist/vite/plugin.d.ts
CHANGED
|
@@ -31,8 +31,12 @@ export declare function buildHub(options: HubOptions & {
|
|
|
31
31
|
/**
|
|
32
32
|
* A studio site's build (its `build.mjs`): the client hub from
|
|
33
33
|
* `shell/studio/`, the gate's font at the host root where the gate pages ask
|
|
34
|
-
* for it, and the favicon
|
|
35
|
-
*
|
|
34
|
+
* for it, and the favicon; then, beside them, the studio hub
|
|
35
|
+
* (`shell/studio/studio.html`), its page at STUDIO_PAGE and its bundle
|
|
36
|
+
* below STUDIO_DIR, which only the studio's own host serves. `root` is the
|
|
37
|
+
* studio folder; it keeps no kit, so `@kit/*` is the package's.
|
|
36
38
|
*/
|
|
37
39
|
export declare function studioConfig(root: string): InlineConfig;
|
|
40
|
+
/** The studio hub's build, after studioConfig's into the same `dist/`: its own page and bundle, nothing shared with the client hub's. */
|
|
41
|
+
export declare function studioHubConfig(root: string): InlineConfig;
|
|
38
42
|
export declare const buildStudio: (root: string) => Promise<void>;
|