@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.
Files changed (51) hide show
  1. package/README.md +4 -4
  2. package/core/review/service.test.ts +39 -38
  3. package/core/review/store.ts +2 -2
  4. package/core/review/suite-kv.ts +17 -0
  5. package/dist/core/review/store.js +2 -2
  6. package/dist/core/review/suite-kv.d.ts +7 -0
  7. package/dist/core/review/suite-kv.js +12 -0
  8. package/dist/scripts/client.js +3 -3
  9. package/dist/scripts/lib/cli.js +5 -0
  10. package/dist/scripts/lib/fake-host.d.ts +1 -2
  11. package/dist/scripts/lib/fake-host.js +20 -9
  12. package/dist/scripts/lib/host.d.ts +13 -25
  13. package/dist/scripts/lib/host.js +15 -324
  14. package/dist/scripts/lib/studio-deps.d.ts +16 -0
  15. package/dist/scripts/lib/studio-deps.js +41 -16
  16. package/dist/scripts/lib/studios.d.ts +14 -4
  17. package/dist/scripts/lib/studios.js +23 -5
  18. package/dist/scripts/lib/vercel-host.d.ts +17 -0
  19. package/dist/scripts/lib/vercel-host.js +410 -0
  20. package/dist/scripts/share.js +3 -2
  21. package/dist/scripts/studio.d.ts +8 -2
  22. package/dist/scripts/studio.js +38 -14
  23. package/dist/server/api.d.ts +6 -5
  24. package/dist/server/api.js +12 -10
  25. package/dist/server/gate.d.ts +97 -0
  26. package/dist/server/gate.js +537 -0
  27. package/dist/server/mark.d.ts +17 -0
  28. package/dist/server/mark.js +46 -1
  29. package/dist/server/session.d.ts +2 -1
  30. package/dist/server/session.js +2 -2
  31. package/dist/server/stores/backends.d.ts +22 -0
  32. package/dist/server/stores/backends.js +96 -0
  33. package/dist/server/{fake-upstash.js → stores/fake-upstash.js} +1 -1
  34. package/dist/server/stores/index.d.ts +41 -0
  35. package/dist/server/stores/index.js +63 -0
  36. package/dist/server/stores/pglite.d.ts +16 -0
  37. package/dist/server/stores/pglite.js +98 -0
  38. package/dist/server/stores/postgres.d.ts +63 -0
  39. package/dist/server/stores/postgres.js +153 -0
  40. package/dist/server/{upstash.d.ts → stores/upstash.d.ts} +1 -1
  41. package/dist/vercel/files.js +1 -1
  42. package/dist/vercel/proxy.d.ts +6 -82
  43. package/dist/vercel/proxy.js +18 -525
  44. package/dist/vite/plugin.js +1 -1
  45. package/package.json +3 -1
  46. package/skills/miles-deploy/SKILL.md +2 -1
  47. package/templates/studio/.env.example +3 -0
  48. package/templates/studio/README.md +13 -0
  49. package/templates/studio/package.json +1 -1
  50. /package/dist/server/{fake-upstash.d.ts → stores/fake-upstash.d.ts} +0 -0
  51. /package/dist/server/{upstash.js → stores/upstash.js} +0 -0
@@ -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 { storeConfig, upstashKV } from './upstash.js';
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: Upstash for the store, Jev for triage
279
- * when its key is set and `checks` is given. `now` is the clock, so the gate
280
- * and the service it asks run on one (the gate's tests move it). Without the
281
- * gate's secret or the store, the cause goes to the site's log and a visitor
282
- * gets SITE_NOT_SET_UP.
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 = storeConfig(env);
287
- if (!keys || !store) {
288
- console.error('[studio]', keys ? 'The review store is not configured.' : 'GATE_SECRET is missing or short.');
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(upstashKV(store), {
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>;