@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
package/dist/server/api.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Checks } from '../core/checks.ts';
|
|
2
|
-
import type
|
|
3
|
-
import { type Review } from '../core/review/service.ts';
|
|
2
|
+
import { type Person, type Scope } from '../core/review/model.ts';
|
|
3
|
+
import { type HostScope, type Review } from '../core/review/service.ts';
|
|
4
4
|
import { type HostLookup } from './hosts.ts';
|
|
5
5
|
import { type Gate, type GateKeys } from './session.ts';
|
|
6
6
|
export declare const API_PATH = "/api/review";
|
|
@@ -10,9 +10,9 @@ export type ApiContext = {
|
|
|
10
10
|
actor: Person | null;
|
|
11
11
|
scope: Scope;
|
|
12
12
|
};
|
|
13
|
-
export declare
|
|
14
|
-
/** The person a request's signed cookie names, while they may still sign in,
|
|
15
|
-
export declare function actorFrom(request: Request, review: Review, gate: Gate,
|
|
13
|
+
export declare const handleReview: (request: Request, ctx: ApiContext) => Promise<Response>;
|
|
14
|
+
/** The person a request's signed cookie names, while they may still sign in, where `at` is: a client's scope, or the studio's host. */
|
|
15
|
+
export declare function actorFrom(request: Request, review: Review, gate: Gate, at: HostScope): Promise<Person | null>;
|
|
16
16
|
/** A studio site's review service and gate keys, or why it has none. */
|
|
17
17
|
export type Deployed = {
|
|
18
18
|
review: Review;
|
|
@@ -21,17 +21,16 @@ export type Deployed = {
|
|
|
21
21
|
error: string;
|
|
22
22
|
};
|
|
23
23
|
/**
|
|
24
|
-
* A studio site's review service:
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
* gets
|
|
24
|
+
* A studio site's review service: the store its env names (chooseStore:
|
|
25
|
+
* Upstash or Postgres, never a guess between them), Jev for triage when its
|
|
26
|
+
* key is set and `checks` is given. `now` is the clock, so the gate and the
|
|
27
|
+
* service it asks run on one (the gate's tests move it). Without the gate's
|
|
28
|
+
* secret or one store, the cause goes to the site's log and a visitor gets
|
|
29
|
+
* SITE_NOT_SET_UP.
|
|
29
30
|
*/
|
|
30
31
|
export declare function studioReview(env: Record<string, string | undefined>, checks?: Checks | null, now?: () => Date): Deployed;
|
|
31
32
|
/**
|
|
32
33
|
* A studio site's review function: the host's client is the scope, and the
|
|
33
|
-
* gate's client, of every op
|
|
34
|
-
* looked up (S5), so a caller signed out, or signed in for another client,
|
|
35
|
-
* gets one answer whatever project the request names.
|
|
34
|
+
* gate's client, of every op; the studio's own host has the studio hub's.
|
|
36
35
|
*/
|
|
37
36
|
export declare function studioHandler(request: Request, checks: Checks | null, hosts: HostLookup): Promise<Response>;
|
package/dist/server/api.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { SLUG } from '../core/feature.js';
|
|
2
2
|
import { hostName, isProjectSlug } from '../core/prototype.js';
|
|
3
|
-
import {
|
|
3
|
+
import { isAdded, STUDIO_SITE, } from '../core/review/model.js';
|
|
4
|
+
import { createReview, NO_PROJECT, ReviewError, } from '../core/review/service.js';
|
|
4
5
|
import { jevTriager } from '../core/review/triage.js';
|
|
5
6
|
import { hostOf } from './hosts.js';
|
|
6
|
-
import { clearedCookie, PERSON_COOKIE, readCookie, readGate, readPersonToken, sameOrigin, } from './session.js';
|
|
7
|
-
import {
|
|
7
|
+
import { clearedCookie, PERSON_COOKIE, readCookie, readGate, readPersonToken, sameOrigin, studioGate, } from './session.js';
|
|
8
|
+
import { chooseStore } from './stores/index.js';
|
|
8
9
|
export const API_PATH = '/api/review';
|
|
9
10
|
const MAX_BODY_BYTES = 64 * 1024;
|
|
10
11
|
const STORE_DOWN = 'The review store did not answer. Try again.';
|
|
@@ -62,25 +63,21 @@ async function query(op, params, { review, actor, scope }) {
|
|
|
62
63
|
return undefined;
|
|
63
64
|
}
|
|
64
65
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
link: `/invite/${r.token}`,
|
|
68
|
-
});
|
|
66
|
+
/** A link as a client's host answers it: at its own root, where its gate answers it. */
|
|
67
|
+
const link = (r) => ({ person: visible(r.person), link: `/invite/${r.token}` });
|
|
69
68
|
/** Studio's commands over people, their links and how long they keep access. */
|
|
70
|
-
async function peopleCommand(op, b, { review, actor,
|
|
69
|
+
async function peopleCommand(op, b, { review, actor, at, link }) {
|
|
71
70
|
switch (op) {
|
|
72
71
|
case 'people.add':
|
|
73
|
-
return link(await review.addPerson(
|
|
72
|
+
return link(await review.addPerson(at, actor, { name: b.name, team: b.team, kind: b.kind, access: b.access }));
|
|
74
73
|
case 'people.link':
|
|
75
|
-
return link(await review.newLink(
|
|
74
|
+
return link(await review.newLink(at, actor, str(b.id)));
|
|
76
75
|
case 'people.signOut':
|
|
77
|
-
return link(await review.signOutEverywhere(
|
|
76
|
+
return link(await review.signOutEverywhere(at, actor, str(b.id)));
|
|
78
77
|
case 'people.revoke':
|
|
79
|
-
return { person: visible(await review.revoke(
|
|
78
|
+
return { person: visible(await review.revoke(at, actor, str(b.id))) };
|
|
80
79
|
case 'people.access':
|
|
81
|
-
return { person: visible(await review.setAccess(
|
|
82
|
-
case 'access.set':
|
|
83
|
-
return { access: await review.setDefaultAccess(scope, actor, b.access) };
|
|
80
|
+
return { person: visible(await review.setAccess(at, actor, str(b.id), b.access)) };
|
|
84
81
|
default:
|
|
85
82
|
return undefined;
|
|
86
83
|
}
|
|
@@ -97,9 +94,11 @@ const PROJECT_COMMANDS = [
|
|
|
97
94
|
'control.audience',
|
|
98
95
|
];
|
|
99
96
|
async function command(op, b, ctx) {
|
|
100
|
-
if (!PROJECT_COMMANDS.includes(op))
|
|
101
|
-
return peopleCommand(op, b, ctx);
|
|
102
97
|
const { review, actor } = ctx;
|
|
98
|
+
if (op === 'access.set')
|
|
99
|
+
return { access: await review.setDefaultAccess(ctx.scope, actor, b.access) };
|
|
100
|
+
if (!PROJECT_COMMANDS.includes(op))
|
|
101
|
+
return peopleCommand(op, b, { review, actor, at: ctx.scope, link });
|
|
103
102
|
const scope = projectScope(ctx.scope);
|
|
104
103
|
const at = () => ({ prototype: prototypeOf(b.prototype), id: str(b.id) });
|
|
105
104
|
switch (op) {
|
|
@@ -163,11 +162,11 @@ async function readJson(request) {
|
|
|
163
162
|
return null;
|
|
164
163
|
}
|
|
165
164
|
}
|
|
166
|
-
|
|
165
|
+
async function answer(request, ops) {
|
|
167
166
|
try {
|
|
168
167
|
if (request.method === 'GET') {
|
|
169
168
|
const params = new URL(request.url).searchParams;
|
|
170
|
-
const result = await query(params.get('op') ?? '', params
|
|
169
|
+
const result = await ops.query(params.get('op') ?? '', params);
|
|
171
170
|
return result === undefined ? json(400, { error: 'Unknown query.' }) : json(200, result);
|
|
172
171
|
}
|
|
173
172
|
if (request.method === 'POST') {
|
|
@@ -177,7 +176,7 @@ export async function handleReview(request, ctx) {
|
|
|
177
176
|
const body = await readJson(request);
|
|
178
177
|
if (!body)
|
|
179
178
|
return json(400, { error: `Send a JSON object of ${MAX_BODY_BYTES / 1024} KB or less.` });
|
|
180
|
-
const result = await command(str(body.op), body
|
|
179
|
+
const result = await ops.command(str(body.op), body);
|
|
181
180
|
return result === undefined ? json(400, { error: 'Unknown command.' }) : json(200, result);
|
|
182
181
|
}
|
|
183
182
|
return new Response('Method not allowed', { status: 405, headers: { allow: 'GET, POST' } });
|
|
@@ -189,39 +188,121 @@ export async function handleReview(request, ctx) {
|
|
|
189
188
|
return json(503, { error: STORE_DOWN }, { 'retry-after': '30' });
|
|
190
189
|
}
|
|
191
190
|
}
|
|
192
|
-
/** The
|
|
193
|
-
|
|
191
|
+
/** The review API on a client's host, or in dev: every op in the context's scope. */
|
|
192
|
+
const clientOps = (ctx) => ({
|
|
193
|
+
query: (op, params) => query(op, params, ctx),
|
|
194
|
+
command: (op, body) => command(op, body, ctx),
|
|
195
|
+
});
|
|
196
|
+
export const handleReview = (request, ctx) => answer(request, clientOps(ctx));
|
|
197
|
+
/**
|
|
198
|
+
* What the studio hub shows of a client: its name and host, whether it is
|
|
199
|
+
* still being added, and each project with whether it has a build to open.
|
|
200
|
+
*/
|
|
201
|
+
const studioListed = ({ client, projects }) => ({
|
|
202
|
+
slug: client.slug,
|
|
203
|
+
name: client.name,
|
|
204
|
+
host: client.host,
|
|
205
|
+
waiting: !isAdded(client),
|
|
206
|
+
projects: projects.map((p) => ({ slug: p.slug, name: p.name, built: p.build !== null })),
|
|
207
|
+
});
|
|
208
|
+
/** The ops on people the studio's own host answers, the review panel's People ops. */
|
|
209
|
+
const PEOPLE_COMMANDS = [
|
|
210
|
+
'people.add',
|
|
211
|
+
'people.link',
|
|
212
|
+
'people.signOut',
|
|
213
|
+
'people.revoke',
|
|
214
|
+
'people.access',
|
|
215
|
+
];
|
|
216
|
+
/**
|
|
217
|
+
* The review API on the studio's own host, for a Studio person signed in
|
|
218
|
+
* there (`host`): who they are, every client with its projects, and the
|
|
219
|
+
* people. A people op names the client it is for with `client`, checked
|
|
220
|
+
* against the store as a handoff checks it (studioClient): an unknown,
|
|
221
|
+
* waiting or archived client answers as an unknown one. Without `client` it
|
|
222
|
+
* is the studio's own people. A link comes back whole, on the host it signs
|
|
223
|
+
* in on: a Client's on their client's host, a Studio person's on this one.
|
|
224
|
+
* No client's host has any of this: there `clients` is an unknown query, and
|
|
225
|
+
* a `client` parameter is never read (S10).
|
|
226
|
+
*/
|
|
227
|
+
const studioOps = (review, actor, host) => {
|
|
228
|
+
const where = async (client) => {
|
|
229
|
+
if (client === undefined || client === null)
|
|
230
|
+
return { at: STUDIO_SITE, host };
|
|
231
|
+
const c = await review.studioClient(actor, client);
|
|
232
|
+
return { at: { client: c.slug }, host: c.host };
|
|
233
|
+
};
|
|
234
|
+
const people = async (client) => {
|
|
235
|
+
const w = await where(client);
|
|
236
|
+
return {
|
|
237
|
+
review,
|
|
238
|
+
actor,
|
|
239
|
+
at: w.at,
|
|
240
|
+
link: (r) => ({
|
|
241
|
+
person: visible(r.person),
|
|
242
|
+
link: `https://${r.person.client === null ? host : w.host}/invite/${r.token}`,
|
|
243
|
+
}),
|
|
244
|
+
};
|
|
245
|
+
};
|
|
246
|
+
return {
|
|
247
|
+
async query(op, params) {
|
|
248
|
+
if (op === 'me')
|
|
249
|
+
return { person: visible(actor), client: STUDIO_SITE };
|
|
250
|
+
if (op === 'clients') {
|
|
251
|
+
const all = await review.listClients(actor);
|
|
252
|
+
return { clients: all.filter((c) => c.client.archivedAt === null).map(studioListed) };
|
|
253
|
+
}
|
|
254
|
+
if (op !== 'people' && op !== 'access')
|
|
255
|
+
return undefined;
|
|
256
|
+
const { at } = await where(params.get('client'));
|
|
257
|
+
if (op === 'access')
|
|
258
|
+
return {
|
|
259
|
+
access: at === STUDIO_SITE ? await review.studioAccess(actor) : await review.defaultAccess(at, actor),
|
|
260
|
+
};
|
|
261
|
+
// A client's section lists its own people; the Studio people have a section of their own.
|
|
262
|
+
const listed = await review.listPeople(at, actor);
|
|
263
|
+
return { people: listed.filter((p) => at === STUDIO_SITE || p.client !== null).map(visible) };
|
|
264
|
+
},
|
|
265
|
+
async command(op, body) {
|
|
266
|
+
return PEOPLE_COMMANDS.includes(op) ? peopleCommand(op, body, await people(body.client)) : undefined;
|
|
267
|
+
},
|
|
268
|
+
};
|
|
269
|
+
};
|
|
270
|
+
/** The person a request's signed cookie names, while they may still sign in, where `at` is: a client's scope, or the studio's host. */
|
|
271
|
+
export async function actorFrom(request, review, gate, at) {
|
|
194
272
|
const claim = await readPersonToken(gate, readCookie(request, PERSON_COOKIE));
|
|
195
|
-
return claim ? review.sessionPerson(
|
|
273
|
+
return claim ? review.sessionPerson(at, claim.id, claim.epoch) : null;
|
|
196
274
|
}
|
|
197
275
|
/** What a studio site says when it is not set up: every client host sees it, so it names no command, studio or client. */
|
|
198
276
|
const SITE_NOT_SET_UP = 'This site is not set up yet.';
|
|
199
277
|
/**
|
|
200
|
-
* A studio site's review service:
|
|
201
|
-
*
|
|
202
|
-
*
|
|
203
|
-
*
|
|
204
|
-
* gets
|
|
278
|
+
* A studio site's review service: the store its env names (chooseStore:
|
|
279
|
+
* Upstash or Postgres, never a guess between them), Jev for triage when its
|
|
280
|
+
* key is set and `checks` is given. `now` is the clock, so the gate and the
|
|
281
|
+
* service it asks run on one (the gate's tests move it). Without the gate's
|
|
282
|
+
* secret or one store, the cause goes to the site's log and a visitor gets
|
|
283
|
+
* SITE_NOT_SET_UP.
|
|
205
284
|
*/
|
|
206
285
|
export function studioReview(env, checks = null, now) {
|
|
207
286
|
const keys = readGate(env);
|
|
208
|
-
const store =
|
|
209
|
-
if (!keys || !store) {
|
|
210
|
-
|
|
287
|
+
const store = chooseStore(env);
|
|
288
|
+
if (!keys || !store || 'error' in store) {
|
|
289
|
+
const why = !store ? 'The review store is not configured.' : 'error' in store ? store.error : '';
|
|
290
|
+
console.error('[studio]', keys ? why : 'GATE_SECRET is missing or short.');
|
|
211
291
|
return { error: SITE_NOT_SET_UP };
|
|
212
292
|
}
|
|
213
293
|
return {
|
|
214
294
|
keys,
|
|
215
|
-
review: createReview(
|
|
295
|
+
review: createReview(store.open(), {
|
|
216
296
|
triage: jevTriager(env.TYPESAFE_API_KEY ?? '', checks),
|
|
217
297
|
...(now ? { now } : {}),
|
|
218
298
|
}),
|
|
219
299
|
};
|
|
220
300
|
}
|
|
221
|
-
/**
|
|
222
|
-
async function
|
|
301
|
+
/** A studio request's host and what it serves, from one host lookup: a client, the studio's own host, or null. */
|
|
302
|
+
async function hostSite(request, review, hosts) {
|
|
223
303
|
const host = hostName(hostOf(request));
|
|
224
|
-
|
|
304
|
+
const site = host ? await hosts(host, (h) => review.siteOfHost(h)) : null;
|
|
305
|
+
return host && site ? { host, site } : null;
|
|
225
306
|
}
|
|
226
307
|
/**
|
|
227
308
|
* The scope a signed-in studio request runs in: the host's client, and the
|
|
@@ -241,34 +322,42 @@ async function studioScope(request, review, client) {
|
|
|
241
322
|
}
|
|
242
323
|
/** The gate's answer to no session, in JSON: it names no client (S10), and clears a cookie that does not hold. */
|
|
243
324
|
const signedOut = (request) => json(401, { error: 'Sign in with the link the studio sent you.' }, readCookie(request, PERSON_COOKIE) === undefined ? {} : { 'set-cookie': clearedCookie(PERSON_COOKIE) });
|
|
325
|
+
/**
|
|
326
|
+
* The ops a request on a known host may run, or the answer that ends it: on
|
|
327
|
+
* the studio's own host the studio hub's alone (studioOps), for a Studio
|
|
328
|
+
* person signed in there; on a client's host every op in the client's scope.
|
|
329
|
+
* The session is read before any project is looked up (S5), so a caller
|
|
330
|
+
* signed out, or signed in for another client, gets one answer whatever
|
|
331
|
+
* project the request names.
|
|
332
|
+
*/
|
|
333
|
+
async function opsFor(request, { review, keys }, { host, site }) {
|
|
334
|
+
if (site === STUDIO_SITE) {
|
|
335
|
+
const actor = await actorFrom(request, review, studioGate(keys), STUDIO_SITE);
|
|
336
|
+
return actor ? studioOps(review, actor, host) : signedOut(request);
|
|
337
|
+
}
|
|
338
|
+
const client = site.slug;
|
|
339
|
+
const actor = await actorFrom(request, review, { ...keys, client, since: site.createdAt }, { client });
|
|
340
|
+
if (!actor)
|
|
341
|
+
return signedOut(request);
|
|
342
|
+
const scope = await studioScope(request, review, client);
|
|
343
|
+
return scope ? clientOps({ review, actor, scope }) : json(404, { error: 'Not found.' });
|
|
344
|
+
}
|
|
244
345
|
/**
|
|
245
346
|
* A studio site's review function: the host's client is the scope, and the
|
|
246
|
-
* gate's client, of every op
|
|
247
|
-
* looked up (S5), so a caller signed out, or signed in for another client,
|
|
248
|
-
* gets one answer whatever project the request names.
|
|
347
|
+
* gate's client, of every op; the studio's own host has the studio hub's.
|
|
249
348
|
*/
|
|
250
349
|
export async function studioHandler(request, checks, hosts) {
|
|
251
350
|
const setup = studioReview(process.env, checks);
|
|
252
351
|
if ('error' in setup)
|
|
253
352
|
return json(503, { error: setup.error });
|
|
254
|
-
let
|
|
353
|
+
let ops;
|
|
255
354
|
try {
|
|
256
|
-
const found = await
|
|
257
|
-
|
|
258
|
-
return json(404, { error: 'Not found.' });
|
|
259
|
-
const client = found.slug;
|
|
260
|
-
const gate = { ...setup.keys, client, since: found.createdAt };
|
|
261
|
-
const actor = await actorFrom(request, setup.review, gate, { client });
|
|
262
|
-
if (!actor)
|
|
263
|
-
return signedOut(request);
|
|
264
|
-
const scope = await studioScope(request, setup.review, client);
|
|
265
|
-
if (!scope)
|
|
266
|
-
return json(404, { error: 'Not found.' });
|
|
267
|
-
ctx = { review: setup.review, actor, scope };
|
|
355
|
+
const found = await hostSite(request, setup.review, hosts);
|
|
356
|
+
ops = found ? await opsFor(request, setup, found) : json(404, { error: 'Not found.' });
|
|
268
357
|
}
|
|
269
358
|
catch (error) {
|
|
270
359
|
console.error('[review]', error);
|
|
271
360
|
return json(503, { error: STORE_DOWN }, { 'retry-after': '30' });
|
|
272
361
|
}
|
|
273
|
-
return
|
|
362
|
+
return ops instanceof Response ? ops : answer(request, ops);
|
|
274
363
|
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { GATE_FONT, type Route } from '../core/prototype.ts';
|
|
2
|
+
import { type Client, type Person, type PersonKind, type Project, type Scope } from '../core/review/model.ts';
|
|
3
|
+
import { type Review } from '../core/review/service.ts';
|
|
4
|
+
import { type HostLookup } from './hosts.ts';
|
|
5
|
+
import { type Gate } from './session.ts';
|
|
6
|
+
export declare const DEFAULT_SITE_NAME = "Prototypes";
|
|
7
|
+
/**
|
|
8
|
+
* What the gate decides for one request, for a host's adapter to carry out:
|
|
9
|
+
* a Response the gate made itself (a gate page, a refusal, a redirect), or
|
|
10
|
+
* the request let through, on to what the site serves at its own path
|
|
11
|
+
* (`next`) or to another URL of the site (`rewrite`, a function), each with
|
|
12
|
+
* the headers to add to the answer.
|
|
13
|
+
*/
|
|
14
|
+
export type Decision = Response | {
|
|
15
|
+
pass: 'next';
|
|
16
|
+
headers?: Record<string, string>;
|
|
17
|
+
} | {
|
|
18
|
+
pass: 'rewrite';
|
|
19
|
+
to: URL;
|
|
20
|
+
headers: Record<string, string>;
|
|
21
|
+
};
|
|
22
|
+
export { GATE_FONT };
|
|
23
|
+
export declare function gatePreview(page: string | null, siteName?: string): Promise<{
|
|
24
|
+
html: string;
|
|
25
|
+
csp: string;
|
|
26
|
+
}>;
|
|
27
|
+
export declare const isRead: (request: Request) => boolean;
|
|
28
|
+
type Extra = {
|
|
29
|
+
cookie?: string;
|
|
30
|
+
allow?: string;
|
|
31
|
+
referrer?: 'no-referrer' | 'same-origin';
|
|
32
|
+
/** Seconds, on a 503 that passes (a store that did not answer), so the review panel retries instead of switching off. */
|
|
33
|
+
retryAfter?: number;
|
|
34
|
+
};
|
|
35
|
+
export declare const plain: (request: Request, status: number, text: string, extra?: Extra) => Response;
|
|
36
|
+
/** One answer for a prototype a Client may not have, whether it is internal or not there at all. */
|
|
37
|
+
export declare const notFound: (request: Request) => Response;
|
|
38
|
+
/** The store did not answer: a 503 that passes, so it says when to try again. */
|
|
39
|
+
export declare const storeDown: (request: Request) => Response;
|
|
40
|
+
/** One request at one moment: `at` is the gate's clock, so freshness is tested without waiting. */
|
|
41
|
+
export type Ctx = {
|
|
42
|
+
siteName: string;
|
|
43
|
+
request: Request;
|
|
44
|
+
at: Date;
|
|
45
|
+
};
|
|
46
|
+
export type ProxyOptions = {
|
|
47
|
+
/** The gate pages' title, the same on every client's host. */
|
|
48
|
+
siteName?: string;
|
|
49
|
+
/** The gate's clock; tests move it instead of waiting. */
|
|
50
|
+
now?: () => Date;
|
|
51
|
+
};
|
|
52
|
+
/** Who a request's host is: its client, and the gate and the client's scope built from that one lookup. */
|
|
53
|
+
export type Place = {
|
|
54
|
+
client: Client;
|
|
55
|
+
gate: Gate;
|
|
56
|
+
scope: Scope;
|
|
57
|
+
};
|
|
58
|
+
/** A request on a studio site that names a known client. */
|
|
59
|
+
export type Found = {
|
|
60
|
+
review: Review;
|
|
61
|
+
place: Place;
|
|
62
|
+
route: Route;
|
|
63
|
+
};
|
|
64
|
+
/** Why a studio request ends before it is served; `refuse` answers each one the same wherever it is met. */
|
|
65
|
+
export type Refusal = {
|
|
66
|
+
refused: 'not-found';
|
|
67
|
+
} | {
|
|
68
|
+
refused: 'store-down';
|
|
69
|
+
} | {
|
|
70
|
+
refused: 'unavailable';
|
|
71
|
+
error: string;
|
|
72
|
+
} | {
|
|
73
|
+
refused: 'signed-out';
|
|
74
|
+
stale: boolean;
|
|
75
|
+
};
|
|
76
|
+
/**
|
|
77
|
+
* The client `pathname` is asked of on the request's host, or why there is
|
|
78
|
+
* none: an unknown host is the plain 404, and so is the studio's own host,
|
|
79
|
+
* which serves no client's anything.
|
|
80
|
+
*/
|
|
81
|
+
export declare function findPlace(request: Request, pathname: string, hosts: HostLookup, at: Date): Promise<Found | Refusal>;
|
|
82
|
+
/** A request that may go on: who asks, the person to re-issue a cookie for, and the project it is for. */
|
|
83
|
+
export type Admitted = Found & {
|
|
84
|
+
kind: PersonKind;
|
|
85
|
+
current: Person | null;
|
|
86
|
+
project: Project | null;
|
|
87
|
+
};
|
|
88
|
+
/**
|
|
89
|
+
* The checks every studio request passes, in the gate and again in the files
|
|
90
|
+
* function: a session signed to this host's client (asked of the store again
|
|
91
|
+
* once its stamp is stale), then the boundary.
|
|
92
|
+
*/
|
|
93
|
+
export declare function admit(found: Found, request: Request, at: Date): Promise<Admitted | Refusal>;
|
|
94
|
+
/** The answer for a refusal: the same from the gate and from the files function. */
|
|
95
|
+
export declare function refuse(ctx: Ctx, refusal: Refusal): Promise<Response> | Response;
|
|
96
|
+
/** The gate a host's adapter runs on every request (vercel/proxy.ts on Vercel). Its sign-in page names no client (S10). */
|
|
97
|
+
export declare function createGate({ siteName, now }?: ProxyOptions): (request: Request) => Promise<Decision>;
|