@milesroxas/design-hub 0.12.0 → 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 +4 -4
- package/core/review/service.test.ts +39 -38
- package/core/review/store.ts +2 -2
- package/core/review/suite-kv.ts +17 -0
- 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.js +3 -3
- package/dist/scripts/lib/cli.js +5 -0
- package/dist/scripts/lib/fake-host.d.ts +1 -2
- package/dist/scripts/lib/fake-host.js +20 -9
- 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 +14 -4
- package/dist/scripts/lib/studios.js +23 -5
- package/dist/scripts/lib/vercel-host.d.ts +17 -0
- package/dist/scripts/lib/vercel-host.js +410 -0
- package/dist/scripts/share.js +3 -2
- package/dist/scripts/studio.d.ts +8 -2
- package/dist/scripts/studio.js +38 -14
- package/dist/server/api.d.ts +6 -5
- package/dist/server/api.js +12 -10
- package/dist/server/gate.d.ts +97 -0
- package/dist/server/gate.js +537 -0
- package/dist/server/mark.d.ts +17 -0
- package/dist/server/mark.js +46 -1
- package/dist/server/session.d.ts +2 -1
- package/dist/server/session.js +2 -2
- 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 -82
- package/dist/vercel/proxy.js +18 -525
- package/dist/vite/plugin.js +1 -1
- package/package.json +3 -1
- package/skills/miles-deploy/SKILL.md +2 -1
- package/templates/studio/.env.example +3 -0
- package/templates/studio/README.md +13 -0
- 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.js
CHANGED
|
@@ -5,7 +5,7 @@ import { createReview, NO_PROJECT, ReviewError, } from '../core/review/service.j
|
|
|
5
5
|
import { jevTriager } from '../core/review/triage.js';
|
|
6
6
|
import { hostOf } from './hosts.js';
|
|
7
7
|
import { clearedCookie, PERSON_COOKIE, readCookie, readGate, readPersonToken, sameOrigin, studioGate, } from './session.js';
|
|
8
|
-
import {
|
|
8
|
+
import { chooseStore } from './stores/index.js';
|
|
9
9
|
export const API_PATH = '/api/review';
|
|
10
10
|
const MAX_BODY_BYTES = 64 * 1024;
|
|
11
11
|
const STORE_DOWN = 'The review store did not answer. Try again.';
|
|
@@ -275,22 +275,24 @@ export async function actorFrom(request, review, gate, at) {
|
|
|
275
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. */
|
|
276
276
|
const SITE_NOT_SET_UP = 'This site is not set up yet.';
|
|
277
277
|
/**
|
|
278
|
-
* A studio site's review service:
|
|
279
|
-
*
|
|
280
|
-
*
|
|
281
|
-
*
|
|
282
|
-
* 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.
|
|
283
284
|
*/
|
|
284
285
|
export function studioReview(env, checks = null, now) {
|
|
285
286
|
const keys = readGate(env);
|
|
286
|
-
const store =
|
|
287
|
-
if (!keys || !store) {
|
|
288
|
-
|
|
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.');
|
|
289
291
|
return { error: SITE_NOT_SET_UP };
|
|
290
292
|
}
|
|
291
293
|
return {
|
|
292
294
|
keys,
|
|
293
|
-
review: createReview(
|
|
295
|
+
review: createReview(store.open(), {
|
|
294
296
|
triage: jevTriager(env.TYPESAFE_API_KEY ?? '', checks),
|
|
295
297
|
...(now ? { now } : {}),
|
|
296
298
|
}),
|
|
@@ -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>;
|