@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/core/prototype.js
CHANGED
|
@@ -100,6 +100,14 @@ const GATE_ASSETS = [GATE_FONT, '/favicon.svg'];
|
|
|
100
100
|
*/
|
|
101
101
|
export const PROOF_PATH = /^\/_gate\/proof\/([\w-]{20,100})$/;
|
|
102
102
|
export const proofPath = (ask) => `/_gate/proof/${ask}`;
|
|
103
|
+
/**
|
|
104
|
+
* A handoff's claim, on a client's host: the studio's host sends a Studio
|
|
105
|
+
* person here with a one-time token, and the gate signs them in on this host.
|
|
106
|
+
*/
|
|
107
|
+
const HANDOFF_PATH = /^\/_gate\/handoff\/([\w-]{20,100})$/;
|
|
108
|
+
export const handoffPath = (token) => `/_gate/handoff/${token}`;
|
|
109
|
+
/** Where the studio hub asks for a handoff, on the studio's own host: a POST of the client and the project. */
|
|
110
|
+
export const HANDOFF_START = '/_gate/handoff';
|
|
103
111
|
/**
|
|
104
112
|
* The studio site's functions, at a client host's root: the review API, and
|
|
105
113
|
* the files function the gate rewrites a project's files to. The gate passes
|
|
@@ -122,6 +130,9 @@ function where(pathname) {
|
|
|
122
130
|
const linked = pathname.match(LINK_PATH);
|
|
123
131
|
if (linked)
|
|
124
132
|
return { kind: 'link', token: linked[1] };
|
|
133
|
+
const handoff = pathname.match(HANDOFF_PATH);
|
|
134
|
+
if (handoff)
|
|
135
|
+
return { kind: 'handoff', token: handoff[1] };
|
|
125
136
|
if (GATE_ASSETS.includes(pathname))
|
|
126
137
|
return { kind: 'asset' };
|
|
127
138
|
const parts = segments(pathname);
|
|
@@ -136,6 +147,33 @@ function where(pathname) {
|
|
|
136
147
|
: { kind: 'none' };
|
|
137
148
|
return isProjectSlug(first) ? projectRoute(first, rest) : { kind: 'none' };
|
|
138
149
|
}
|
|
150
|
+
/**
|
|
151
|
+
* The studio hub's own files, which the studio site's build puts beside the
|
|
152
|
+
* client hub (studioConfig in vite/plugin.ts): its page, and its bundle under
|
|
153
|
+
* one folder. Neither is a path a client's host answers: `_studio` and
|
|
154
|
+
* `studio.html` are no project slug, so routeOf sends both nowhere.
|
|
155
|
+
*/
|
|
156
|
+
export const STUDIO_DIR = '_studio';
|
|
157
|
+
export const STUDIO_PAGE = '/studio.html';
|
|
158
|
+
/** The one place a request's path on the studio's own host is read. It fails closed, as routeOf does. */
|
|
159
|
+
export function studioRouteOf(pathname) {
|
|
160
|
+
const linked = pathname.match(LINK_PATH);
|
|
161
|
+
if (linked)
|
|
162
|
+
return { kind: 'link', token: linked[1] };
|
|
163
|
+
if (GATE_ASSETS.includes(pathname))
|
|
164
|
+
return { kind: 'asset' };
|
|
165
|
+
if (pathname === '/')
|
|
166
|
+
return { kind: 'page' };
|
|
167
|
+
if (pathname === '/api/review')
|
|
168
|
+
return { kind: 'api' };
|
|
169
|
+
if (pathname === HANDOFF_START)
|
|
170
|
+
return { kind: 'handoff' };
|
|
171
|
+
const proof = pathname.match(PROOF_PATH);
|
|
172
|
+
if (proof)
|
|
173
|
+
return { kind: 'proof', ask: proof[1] };
|
|
174
|
+
const parts = segments(pathname);
|
|
175
|
+
return parts && parts.length > 1 && parts[0] === STUDIO_DIR ? { kind: 'file' } : { kind: 'none' };
|
|
176
|
+
}
|
|
139
177
|
/**
|
|
140
178
|
* The one place a studio site reads a request's path. It fails closed: a
|
|
141
179
|
* path that could mean more than one file (`segments`) goes nowhere. Which client a host is, is the store's to say (a host may be a
|
|
@@ -26,6 +26,16 @@ export declare const DEFAULT_ACCESS: Access;
|
|
|
26
26
|
* archiving a client, or adding one, takes effect on every instance within it.
|
|
27
27
|
*/
|
|
28
28
|
export declare const HOST_SECONDS = 60;
|
|
29
|
+
/** How long a handoff lasts: Studio opens a client from the studio's host, and the client's host claims it within this. */
|
|
30
|
+
export declare const HANDOFF_SECONDS = 60;
|
|
31
|
+
/**
|
|
32
|
+
* The studio's own host (`studio.<apex>`): its entry in the store's `hosts`,
|
|
33
|
+
* in place of a client's slug, and the client a session on it is signed to.
|
|
34
|
+
* Never a client's slug (RESERVED_CLIENTS), so no client host is ever it.
|
|
35
|
+
*/
|
|
36
|
+
export declare const STUDIO_SITE = "studio";
|
|
37
|
+
/** What a studio site's host serves: one client, the studio's own host, or nothing. */
|
|
38
|
+
export type Site = Client | typeof STUDIO_SITE | null;
|
|
29
39
|
/** When access given at `from` ends, as an ISO time, or null for open-ended. */
|
|
30
40
|
export declare function accessEnd(access: Access, from: Date): string | null;
|
|
31
41
|
export declare const LIMITS: {
|
|
@@ -115,6 +125,18 @@ export type Link = {
|
|
|
115
125
|
person: string;
|
|
116
126
|
expiresAt: string;
|
|
117
127
|
};
|
|
128
|
+
/**
|
|
129
|
+
* A handoff: a Studio person, signed in on the studio's host, opening one
|
|
130
|
+
* client's hub (or one of its projects) on that client's host. Stored with
|
|
131
|
+
* the client under the hash of its token, deleted when its host claims it,
|
|
132
|
+
* good for HANDOFF_SECONDS. `project` is a project of the client with a
|
|
133
|
+
* build when it was made, or null for the client's hub.
|
|
134
|
+
*/
|
|
135
|
+
export type Handoff = {
|
|
136
|
+
person: string;
|
|
137
|
+
project: string | null;
|
|
138
|
+
expiresAt: string;
|
|
139
|
+
};
|
|
118
140
|
/** A comment's author as it was when they wrote it, so a revoked person's comments still read. */
|
|
119
141
|
export type Author = Pick<Person, 'id' | 'name' | 'team'>;
|
|
120
142
|
export type Anchor = {
|
|
@@ -30,6 +30,14 @@ export const DEFAULT_ACCESS = '3m';
|
|
|
30
30
|
* archiving a client, or adding one, takes effect on every instance within it.
|
|
31
31
|
*/
|
|
32
32
|
export const HOST_SECONDS = 60;
|
|
33
|
+
/** How long a handoff lasts: Studio opens a client from the studio's host, and the client's host claims it within this. */
|
|
34
|
+
export const HANDOFF_SECONDS = 60;
|
|
35
|
+
/**
|
|
36
|
+
* The studio's own host (`studio.<apex>`): its entry in the store's `hosts`,
|
|
37
|
+
* in place of a client's slug, and the client a session on it is signed to.
|
|
38
|
+
* Never a client's slug (RESERVED_CLIENTS), so no client host is ever it.
|
|
39
|
+
*/
|
|
40
|
+
export const STUDIO_SITE = 'studio';
|
|
33
41
|
const ACCESS_MONTHS = { '3m': 3, '6m': 6 };
|
|
34
42
|
/** When access given at `from` ends, as an ISO time, or null for open-ended. */
|
|
35
43
|
export function accessEnd(access, from) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type ControlKind, type Marks } from '../controls.ts';
|
|
2
|
-
import { type Access, type Audience, type Client, type Comment, type Person, type PersonKind, type Project, type Scope, type Triage } from './model.ts';
|
|
2
|
+
import { type Access, type Audience, type Client, type Comment, type Person, type PersonKind, type Project, type Scope, type Site, STUDIO_SITE, type Triage } from './model.ts';
|
|
3
3
|
import { type KV } from './store.ts';
|
|
4
4
|
export type ErrorCode = 'unauthorized' | 'forbidden' | 'not_found' | 'invalid';
|
|
5
5
|
export declare class ReviewError extends Error {
|
|
@@ -42,6 +42,11 @@ export type Archived = {
|
|
|
42
42
|
ownHost: boolean;
|
|
43
43
|
};
|
|
44
44
|
export declare const NO_PROJECT = "No such project.";
|
|
45
|
+
/**
|
|
46
|
+
* What a host the gate answers runs in: one client's scope, or the studio's
|
|
47
|
+
* own host (STUDIO_SITE), where only Studio people sign in.
|
|
48
|
+
*/
|
|
49
|
+
export type HostScope = Scope | typeof STUDIO_SITE;
|
|
45
50
|
/** A person and a new one-time link's token for them. */
|
|
46
51
|
type Issued = {
|
|
47
52
|
person: Person;
|
|
@@ -55,6 +60,80 @@ export declare function createReview(kv: KV, overrides?: Partial<Deps>): {
|
|
|
55
60
|
* records that disagree, so an unknown host is never a scope.
|
|
56
61
|
*/
|
|
57
62
|
clientOfHost(host: string): Promise<Client | null>;
|
|
63
|
+
/**
|
|
64
|
+
* What a host serves, asked by the gate and the studio's functions with
|
|
65
|
+
* no actor: a client (as clientOfHost), the studio's own host, or null.
|
|
66
|
+
*/
|
|
67
|
+
siteOfHost: (host: string) => Promise<Site>;
|
|
68
|
+
/**
|
|
69
|
+
* Whether the studio's own host has answered its proof (endStudioProof):
|
|
70
|
+
* from then on commands leave it be, and its owner has had a link there.
|
|
71
|
+
* Studio only.
|
|
72
|
+
*/
|
|
73
|
+
studioHostProven(actor: Person | null): Promise<boolean>;
|
|
74
|
+
/**
|
|
75
|
+
* A new proof for the studio's own host, in place of any before it, as
|
|
76
|
+
* startProof is for a client's: only the gate reading this store answers
|
|
77
|
+
* its ask there. Studio only.
|
|
78
|
+
*/
|
|
79
|
+
startStudioProof(actor: Person | null): Promise<{
|
|
80
|
+
ask: string;
|
|
81
|
+
answer: string;
|
|
82
|
+
}>;
|
|
83
|
+
/** Ends the studio host's proof once it answered, marking the host proven; the mark goes on first. Studio only. */
|
|
84
|
+
endStudioProof(actor: Person | null): Promise<void>;
|
|
85
|
+
/** The answer to the studio host's proof, asked by the gate on that host with no actor: null for any other ask. */
|
|
86
|
+
studioProofAnswer(ask: string): Promise<string | null>;
|
|
87
|
+
/**
|
|
88
|
+
* Makes `host` the studio's own host (`studio.<apex>`), where Studio
|
|
89
|
+
* signs in and sees every client. Refused for a host a client has, or
|
|
90
|
+
* one that is not a host name. Safe to run again. Studio only.
|
|
91
|
+
*/
|
|
92
|
+
setStudioHost(actor: Person | null, host: string): Promise<'added' | 'kept'>;
|
|
93
|
+
/**
|
|
94
|
+
* Every client record the studio has, by name, each with all its
|
|
95
|
+
* projects by name, archived ones too (an archive that stopped part way).
|
|
96
|
+
* The studio's own view, for its hub and `client list`. Studio only.
|
|
97
|
+
*/
|
|
98
|
+
listClients(actor: Person | null): Promise<{
|
|
99
|
+
client: Client;
|
|
100
|
+
projects: Project[];
|
|
101
|
+
}[]>;
|
|
102
|
+
/**
|
|
103
|
+
* The client an op on the studio's own host names, for its people: known,
|
|
104
|
+
* not archived and added, as a handoff checks it (openable). Anything
|
|
105
|
+
* else is not found, an unknown client's answer. Studio only.
|
|
106
|
+
*/
|
|
107
|
+
studioClient(actor: Person | null, slug: unknown): Promise<Client>;
|
|
108
|
+
/**
|
|
109
|
+
* A handoff: the actor, a Studio person signed in on the studio's host,
|
|
110
|
+
* opens one client's hub, or one of its projects with a build, on the
|
|
111
|
+
* client's host. Answers the host from the client's record and a new
|
|
112
|
+
* token, which the host claims once within HANDOFF_SECONDS (claimHandoff).
|
|
113
|
+
* A client archived, gone or still being added (no provenAt), a project
|
|
114
|
+
* it does not have or has not built, and a host that is no host name are
|
|
115
|
+
* all not found. The store keeps the token as its hash. Studio only.
|
|
116
|
+
*/
|
|
117
|
+
startHandoff(actor: Person | null, input: {
|
|
118
|
+
client: unknown;
|
|
119
|
+
project: unknown;
|
|
120
|
+
}): Promise<{
|
|
121
|
+
host: string;
|
|
122
|
+
token: string;
|
|
123
|
+
}>;
|
|
124
|
+
/**
|
|
125
|
+
* Claims a handoff on the scope's client's host, asked by the gate with
|
|
126
|
+
* no actor: the Studio person it was made for and the project to open
|
|
127
|
+
* (null for the client's hub), or null. Only a handoff made for this
|
|
128
|
+
* client is found; one past HANDOFF_SECONDS, one for a client no longer
|
|
129
|
+
* added, or a person who may no longer sign in is null. The delete is
|
|
130
|
+
* the claim, as useLink's, so of two requests with one token only one
|
|
131
|
+
* gets a person; every check comes before it.
|
|
132
|
+
*/
|
|
133
|
+
claimHandoff(scope: Scope, token: string): Promise<{
|
|
134
|
+
person: Person;
|
|
135
|
+
project: string | null;
|
|
136
|
+
} | null>;
|
|
58
137
|
/** One project of the scope's client, asked with no actor: null when the client has none by that name. */
|
|
59
138
|
projectOf: ({ client, project }: Scope) => Promise<Project | null>;
|
|
60
139
|
/** Every project of the scope's client that has a build to open, by name. */
|
|
@@ -159,25 +238,25 @@ export declare function createReview(kv: KV, overrides?: Partial<Deps>): {
|
|
|
159
238
|
}>;
|
|
160
239
|
/** Forgets builds of the scope's project, once their files are gone; never the live one. Studio only. */
|
|
161
240
|
forgetBuilds(scope: Scope, actor: Person | null, builds: string[]): Promise<void>;
|
|
162
|
-
/** The person a signed session names, if they still may sign in with it, here. */
|
|
163
|
-
sessionPerson(
|
|
164
|
-
/** The scope's Clients and every Studio person. */
|
|
165
|
-
listPeople(
|
|
241
|
+
/** The person a signed session names, if they still may sign in with it, here: in a client's scope, or Studio on the studio's host. */
|
|
242
|
+
sessionPerson(at: HostScope, id: string, epoch: number): Promise<Person | null>;
|
|
243
|
+
/** The scope's Clients and every Studio person; on the studio's own host, the Studio people alone. */
|
|
244
|
+
listPeople(at: HostScope, actor: Person | null): Promise<Person[]>;
|
|
166
245
|
/**
|
|
167
246
|
* A new person and their first link: a Client of the scope's client, or a
|
|
168
|
-
* Studio person
|
|
169
|
-
*
|
|
170
|
-
*
|
|
171
|
-
* client's name.
|
|
247
|
+
* Studio person; on the studio's own host, a Studio person only. Without
|
|
248
|
+
* an access length, a Client gets the default and Studio is open-ended.
|
|
249
|
+
* Without a team, a Studio person gets the studio's, which every Studio
|
|
250
|
+
* person carries, so the adder's; a Client gets their client's name.
|
|
172
251
|
*/
|
|
173
|
-
addPerson(
|
|
252
|
+
addPerson(at: HostScope, actor: Person | null, input: unknown): Promise<Issued>;
|
|
174
253
|
/** Another one-time link, for another device. Their sessions and other unused links stay. */
|
|
175
|
-
newLink(scope:
|
|
254
|
+
newLink(scope: HostScope, actor: Person | null, id: string): Promise<Issued>;
|
|
176
255
|
/** Ends every session they hold and every unused link, and gives one new link. */
|
|
177
|
-
signOutEverywhere(scope:
|
|
178
|
-
revoke(scope:
|
|
256
|
+
signOutEverywhere(scope: HostScope, actor: Person | null, id: string): Promise<Issued>;
|
|
257
|
+
revoke(scope: HostScope, actor: Person | null, id: string): Promise<Person>;
|
|
179
258
|
/** Sets one person's access length, counted from now. Their sessions follow at the gate's next check, within five minutes. */
|
|
180
|
-
setAccess(scope:
|
|
259
|
+
setAccess(scope: HostScope, actor: Person | null, id: string, access: unknown): Promise<Person>;
|
|
181
260
|
/** How long a new Client of the scope's client keeps access unless Studio says otherwise: the client's default, else the studio's. */
|
|
182
261
|
defaultAccess(scope: Scope, actor: Person | null): Promise<Access>;
|
|
183
262
|
/**
|
|
@@ -189,21 +268,22 @@ export declare function createReview(kv: KV, overrides?: Partial<Deps>): {
|
|
|
189
268
|
setDefaultAccess(scope: Scope, actor: Person | null, access: unknown): Promise<Access>;
|
|
190
269
|
/** A new Studio person, who works in every client. No link: each comes from newStudioLink, for one host. Studio only. */
|
|
191
270
|
addStudioPerson(actor: Person | null, input: unknown): Promise<Person>;
|
|
192
|
-
/** Another one-time link for a Studio person: it signs in one device, on whichever client host it is opened. Studio only. */
|
|
271
|
+
/** Another one-time link for a Studio person: it signs in one device, on the studio's host or whichever client host it is opened. Studio only. */
|
|
193
272
|
newStudioLink(actor: Person | null, id: string): Promise<Issued>;
|
|
194
273
|
/** The studio's default access length, what a client without its own gives. Studio only. */
|
|
195
274
|
studioAccess(actor: Person | null): Promise<Access>;
|
|
196
275
|
setStudioAccess(actor: Person | null, access: unknown): Promise<Access>;
|
|
197
276
|
/** Who a link signs in here, without using it: mail and chat previews open links too. */
|
|
198
|
-
peekLink(
|
|
277
|
+
peekLink(at: HostScope, token: string): Promise<Person | null>;
|
|
199
278
|
/**
|
|
200
279
|
* Uses a link up and returns who it signs in. The delete is the claim: of
|
|
201
280
|
* two requests with one token, only the one whose delete removed the link
|
|
202
281
|
* gets a person, so a link signs in one device at most. Who it signs in is
|
|
203
282
|
* read and checked first, so the delete is the last store call. Only a
|
|
204
|
-
* link of the scope's client, or a Studio person's, is found at all
|
|
283
|
+
* link of the scope's client, or a Studio person's, is found at all; on
|
|
284
|
+
* the studio's own host, only a Studio person's.
|
|
205
285
|
*/
|
|
206
|
-
useLink(
|
|
286
|
+
useLink(at: HostScope, token: string): Promise<Person | null>;
|
|
207
287
|
/**
|
|
208
288
|
* A prototype's comments as the actor's view sees them. `viewAs: 'client'`
|
|
209
289
|
* is Studio's Client view; it never widens a Client's.
|