@milesroxas/design-hub 0.6.2 → 0.8.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 +16 -6
- package/core/review/model.ts +124 -6
- package/core/review/policy.test.ts +103 -24
- package/core/review/policy.ts +43 -7
- package/core/review/service.test.ts +569 -33
- package/core/review/service.ts +272 -76
- package/core/review/store.ts +24 -4
- package/dist/core/review/model.d.ts +59 -4
- package/dist/core/review/model.js +98 -4
- package/dist/core/review/policy.d.ts +21 -2
- package/dist/core/review/policy.js +34 -2
- package/dist/core/review/service.d.ts +39 -11
- package/dist/core/review/service.js +237 -77
- package/dist/core/review/store.d.ts +17 -4
- package/dist/core/review/store.js +21 -3
- package/dist/scripts/bootstrap.d.ts +16 -14
- package/dist/scripts/bootstrap.js +56 -39
- package/dist/scripts/comments.d.ts +10 -2
- package/dist/scripts/comments.js +18 -7
- package/dist/scripts/lib/deploy.d.ts +12 -4
- package/dist/scripts/lib/deploy.js +47 -13
- package/dist/scripts/lib/vercel.d.ts +8 -2
- package/dist/scripts/lib/vercel.js +23 -9
- package/dist/scripts/people.d.ts +13 -26
- package/dist/scripts/people.js +68 -35
- package/dist/scripts/preflight.js +2 -2
- package/dist/scripts/share.d.ts +2 -3
- package/dist/scripts/share.js +18 -10
- package/dist/server/api.d.ts +6 -2
- package/dist/server/api.js +65 -24
- package/dist/server/fake-upstash.js +3 -2
- package/dist/server/local.js +2 -0
- package/dist/server/session.d.ts +25 -10
- package/dist/server/session.js +69 -52
- package/dist/server/upstash.js +4 -3
- package/dist/vercel/proxy.d.ts +5 -3
- package/dist/vercel/proxy.js +183 -157
- package/dist/vite/plugin.js +5 -5
- package/kit/prefs.ts +19 -2
- package/package.json +2 -2
- package/shell/review/Bar.tsx +97 -4
- package/shell/review/People.tsx +178 -45
- package/shell/review/Pins.tsx +39 -24
- package/shell/review/Review.tsx +113 -29
- package/shell/review/ThreadCard.tsx +25 -13
- package/shell/review/client.ts +64 -23
- package/shell/review/review.css +16 -2
- package/shell/review/view.test.ts +73 -1
- package/shell/review/view.ts +49 -3
- package/skills/miles-deploy/SKILL.md +44 -16
- package/skills/miles-design-hub/SKILL.md +5 -5
- package/skills/miles-new-feature/SKILL.md +1 -1
- package/skills/miles-review/SKILL.md +10 -6
- package/skills/miles-worktrees/SKILL.md +1 -1
- package/templates/conductor/settings.toml +1 -1
- package/templates/guide.md +1 -1
package/dist/scripts/people.js
CHANGED
|
@@ -1,36 +1,43 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
/// <reference types="node" />
|
|
3
3
|
// The people who comment on the deployed prototypes. The first Studio person
|
|
4
|
-
// is
|
|
5
|
-
|
|
4
|
+
// is added from here; after that, Studio adds people from the People tab.
|
|
5
|
+
// Each person signs in with a one-time link: it signs in one device, then
|
|
6
|
+
// stops working, so a second device needs a new link.
|
|
7
|
+
import { ACCESS, PERSON_KINDS } from '../core/review/model.js';
|
|
6
8
|
import { CliError } from './lib/cli.js';
|
|
7
9
|
import { cliActor, cliReview } from './lib/review.js';
|
|
8
10
|
export const spec = {
|
|
9
11
|
name: 'people',
|
|
10
|
-
summary: 'List
|
|
12
|
+
summary: 'List or add the people who comment on the deployed prototypes, give them sign-in links, sign them out, revoke them, and set how long they keep access.',
|
|
11
13
|
positionals: [
|
|
12
14
|
{
|
|
13
15
|
name: 'action',
|
|
14
|
-
description: 'list (default): everyone
|
|
16
|
+
description: 'list (default): everyone. add: a new person and their link. link <id>: another one-time link, for another device. sign-out <id>: ends every session and unused link, and gives one new link. revoke <id>: ends their access everywhere. access [id]: with an id and --access, sets that person’s access from now; without an id, reads the project default, or sets it with --access.',
|
|
15
17
|
},
|
|
16
|
-
{ name: 'id', description: 'The person, for
|
|
18
|
+
{ name: 'id', description: 'The person, for link, sign-out, revoke and access' },
|
|
17
19
|
],
|
|
18
20
|
flags: {
|
|
19
|
-
name: { type: 'string', description: 'For
|
|
20
|
-
team: { type: 'string', description: "For
|
|
21
|
+
name: { type: 'string', description: 'For add: their name as it shows on comments.' },
|
|
22
|
+
team: { type: 'string', description: "For add: the studio, or the client's company." },
|
|
21
23
|
kind: {
|
|
22
24
|
type: 'string',
|
|
23
25
|
default: 'client',
|
|
24
26
|
choices: PERSON_KINDS,
|
|
25
|
-
description: 'client comments, replies and resolves any thread; studio also deletes any comment, sorts and
|
|
27
|
+
description: 'client comments, replies and resolves any thread; studio also deletes any comment, sorts and manages people.',
|
|
26
28
|
},
|
|
27
|
-
|
|
29
|
+
access: {
|
|
30
|
+
type: 'string',
|
|
31
|
+
choices: ACCESS,
|
|
32
|
+
description: 'How long they keep access: 3m, 6m or open. For add, absent means the project default for a client and open for studio.',
|
|
33
|
+
},
|
|
34
|
+
site: { type: 'string', description: 'The deployed URL, so the link prints whole.' },
|
|
28
35
|
local: {
|
|
29
36
|
type: 'boolean',
|
|
30
37
|
description: 'Use the local dev store even when the deployed one is configured.',
|
|
31
38
|
},
|
|
32
39
|
},
|
|
33
|
-
output: '{ ok, store, people } or { ok, store, person, link }',
|
|
40
|
+
output: '{ ok, store, people } or { ok, store, person, link } or { ok, store, person } or { ok, store, access }',
|
|
34
41
|
};
|
|
35
42
|
const linkFor = (token, site) => {
|
|
36
43
|
const path = `/invite/${token}`;
|
|
@@ -43,31 +50,57 @@ const linkFor = (token, site) => {
|
|
|
43
50
|
throw new CliError('--site takes a URL.', { got: site });
|
|
44
51
|
}
|
|
45
52
|
};
|
|
53
|
+
const strip = ({ epoch: _e, ...rest }) => rest;
|
|
54
|
+
function needId(action, id) {
|
|
55
|
+
if (!id)
|
|
56
|
+
throw new CliError(`Name the person: pnpm people ${action} <id>.`, { fix: 'pnpm people lists ids.' });
|
|
57
|
+
return id;
|
|
58
|
+
}
|
|
59
|
+
const withLink = (r, site) => ({
|
|
60
|
+
person: strip(r.person),
|
|
61
|
+
...linkFor(r.token, site),
|
|
62
|
+
});
|
|
63
|
+
/** One person's access with an id, else the project default: read it, or set it with --access. */
|
|
64
|
+
async function access({ review, actor, flags, id }) {
|
|
65
|
+
if (id) {
|
|
66
|
+
if (!flags.access)
|
|
67
|
+
throw new CliError('Say how long: pnpm people access <id> --access 3m|6m|open.');
|
|
68
|
+
return { person: strip(await review.setAccess(actor, id, flags.access)) };
|
|
69
|
+
}
|
|
70
|
+
return {
|
|
71
|
+
access: flags.access
|
|
72
|
+
? await review.setDefaultAccess(actor, flags.access)
|
|
73
|
+
: await review.defaultAccess(actor),
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
const ACTIONS = {
|
|
77
|
+
list: async ({ review, actor }) => ({ people: (await review.listPeople(actor)).map(strip) }),
|
|
78
|
+
add: async ({ review, actor, flags }) => withLink(await review.addPerson(actor, {
|
|
79
|
+
name: flags.name,
|
|
80
|
+
team: flags.team,
|
|
81
|
+
kind: flags.kind,
|
|
82
|
+
access: flags.access,
|
|
83
|
+
}), flags.site),
|
|
84
|
+
link: async ({ review, actor, flags, id }) => withLink(await review.newLink(actor, needId('link', id)), flags.site),
|
|
85
|
+
'sign-out': async ({ review, actor, flags, id }) => withLink(await review.signOutEverywhere(actor, needId('sign-out', id)), flags.site),
|
|
86
|
+
revoke: async ({ review, actor, id }) => ({
|
|
87
|
+
person: strip(await review.revoke(actor, needId('revoke', id))),
|
|
88
|
+
}),
|
|
89
|
+
access,
|
|
90
|
+
};
|
|
46
91
|
export async function main({ positionals: [action = 'list', id], flags }) {
|
|
92
|
+
const run = Object.hasOwn(ACTIONS, action) ? ACTIONS[action] : undefined;
|
|
93
|
+
if (!run)
|
|
94
|
+
throw new CliError(`Unknown action ${action}.`, { fix: 'list, add, link, sign-out, revoke or access' });
|
|
95
|
+
if (flags.local && flags.site)
|
|
96
|
+
throw new CliError('--local and --site do not go together: a local link opens nothing on the deployed site.', {
|
|
97
|
+
fix: 'Drop --site for a local link, or drop --local to use the deployed store.',
|
|
98
|
+
});
|
|
47
99
|
const { review, store } = cliReview(flags.local);
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
const { person, token } = await review.invite(actor, {
|
|
55
|
-
name: flags.name,
|
|
56
|
-
team: flags.team,
|
|
57
|
-
kind: flags.kind,
|
|
58
|
-
});
|
|
59
|
-
return { store, person: strip(person), ...linkFor(token, flags.site) };
|
|
60
|
-
}
|
|
61
|
-
case 'reissue':
|
|
62
|
-
case 'revoke': {
|
|
63
|
-
if (!id)
|
|
64
|
-
throw new CliError(`Name the person: pnpm people ${action} <id>.`, { fix: 'pnpm people lists ids.' });
|
|
65
|
-
if (action === 'revoke')
|
|
66
|
-
return { store, person: strip(await review.revoke(actor, id)) };
|
|
67
|
-
const { person, token } = await review.reissue(actor, id);
|
|
68
|
-
return { store, person: strip(person), ...linkFor(token, flags.site) };
|
|
69
|
-
}
|
|
70
|
-
default:
|
|
71
|
-
throw new CliError(`Unknown action ${action}.`, { fix: 'list, invite, reissue or revoke' });
|
|
72
|
-
}
|
|
100
|
+
// A link made in the local store opens nothing on the deployed site, so never print one under its URL.
|
|
101
|
+
if (flags.site && store === 'local')
|
|
102
|
+
throw new CliError('--site names the deployed site, but its store is not configured here.', {
|
|
103
|
+
fix: 'KV_REST_API_URL and KV_REST_API_TOKEN are missing from .env: pnpm bootstrap --vercel <project> --review puts them there. For a local link, pass --local without --site.',
|
|
104
|
+
});
|
|
105
|
+
return { store, ...(await run({ review, actor: cliActor(), flags, id })) };
|
|
73
106
|
}
|
|
@@ -183,7 +183,7 @@ function gate() {
|
|
|
183
183
|
step: 'gate',
|
|
184
184
|
ok: true,
|
|
185
185
|
skipped: 'not linked to Vercel yet',
|
|
186
|
-
fix: 'design-hub bootstrap --vercel <project>',
|
|
186
|
+
fix: 'design-hub bootstrap --vercel <project> --review',
|
|
187
187
|
};
|
|
188
188
|
const missing = gateEnvMissing(ROOT);
|
|
189
189
|
if (missing === null)
|
|
@@ -193,7 +193,7 @@ function gate() {
|
|
|
193
193
|
step: 'gate',
|
|
194
194
|
ok: false,
|
|
195
195
|
detail: { missing },
|
|
196
|
-
fix: '
|
|
196
|
+
fix: 'pnpm bootstrap --vercel <project> --review sets GATE_SECRET and adds the review store, which keeps the people and their links: without it nobody can sign in.',
|
|
197
197
|
}
|
|
198
198
|
: { step: 'gate', ok: true };
|
|
199
199
|
}
|
package/dist/scripts/share.d.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { type Args } from './lib/cli.ts';
|
|
3
3
|
export declare const spec: {
|
|
4
4
|
readonly name: 'share';
|
|
5
|
-
readonly summary: 'Pre-flight, deploy to production, wait for the build, and check the live URL shows the
|
|
5
|
+
readonly summary: 'Pre-flight, deploy to production, wait for the build, and check the live URL shows the sign-in page. Returns the share details.';
|
|
6
6
|
readonly flags: {
|
|
7
7
|
readonly skip: {
|
|
8
8
|
readonly type: 'list';
|
|
@@ -13,7 +13,7 @@ export declare const spec: {
|
|
|
13
13
|
readonly description: 'Upload this folder with the Vercel CLI even when the project deploys on push.';
|
|
14
14
|
};
|
|
15
15
|
};
|
|
16
|
-
readonly output: '{ ok, via, deployment, url, gate, share: { url,
|
|
16
|
+
readonly output: '{ ok, via, deployment, url, gate, share: { url, open: [{ title, path, guide? }] }, review, next } or { ok: false, stage, ... }';
|
|
17
17
|
};
|
|
18
18
|
export declare function main({ flags }: Args<typeof spec>): Promise<{
|
|
19
19
|
ok: boolean;
|
|
@@ -42,7 +42,6 @@ export declare function main({ flags }: Args<typeof spec>): Promise<{
|
|
|
42
42
|
} | {
|
|
43
43
|
share: {
|
|
44
44
|
url: string;
|
|
45
|
-
password: string;
|
|
46
45
|
open: {
|
|
47
46
|
title: string;
|
|
48
47
|
path: string;
|
package/dist/scripts/share.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// One command from a passing project to a link that works: the pre-flight,
|
|
4
4
|
// the deploy (a push when the Vercel project is connected to the repo, an
|
|
5
5
|
// upload otherwise), the wait for the build, and a signed-out request that
|
|
6
|
-
// must come back as the
|
|
6
|
+
// must come back as the sign-in page. It ends with what the handover needs.
|
|
7
7
|
import { spawnSync } from 'node:child_process';
|
|
8
8
|
import { existsSync } from 'node:fs';
|
|
9
9
|
import { join } from 'node:path';
|
|
@@ -12,12 +12,12 @@ import { readEnv } from '../server/env.js';
|
|
|
12
12
|
import { DOCS, ROOT } from '../server/paths.js';
|
|
13
13
|
import { prototypes } from './lib/catalog.js';
|
|
14
14
|
import { CliError } from './lib/cli.js';
|
|
15
|
-
import { GATE_REQUEST, gateVerdict, gitConnected, nextStep, plan, productionUrl, } from './lib/deploy.js';
|
|
15
|
+
import { GATE_REQUEST, gateVerdict, gitConnected, nextStep, PROBE_LINK, plan, productionUrl, storeVerdict, } from './lib/deploy.js';
|
|
16
16
|
import { linkedOrg, linkedProject, projectInfo, STORE_ENV, vercel, whoami } from './lib/vercel.js';
|
|
17
17
|
import * as preflight from './preflight.js';
|
|
18
18
|
export const spec = {
|
|
19
19
|
name: 'share',
|
|
20
|
-
summary: 'Pre-flight, deploy to production, wait for the build, and check the live URL shows the
|
|
20
|
+
summary: 'Pre-flight, deploy to production, wait for the build, and check the live URL shows the sign-in page. Returns the share details.',
|
|
21
21
|
flags: {
|
|
22
22
|
skip: {
|
|
23
23
|
type: 'list',
|
|
@@ -28,7 +28,7 @@ export const spec = {
|
|
|
28
28
|
description: 'Upload this folder with the Vercel CLI even when the project deploys on push.',
|
|
29
29
|
},
|
|
30
30
|
},
|
|
31
|
-
output: '{ ok, via, deployment, url, gate, share: { url,
|
|
31
|
+
output: '{ ok, via, deployment, url, gate, share: { url, open: [{ title, path, guide? }] }, review, next } or { ok: false, stage, ... }',
|
|
32
32
|
};
|
|
33
33
|
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
34
34
|
function git(args) {
|
|
@@ -82,16 +82,23 @@ function viaCli() {
|
|
|
82
82
|
throw new CliError('vercel deploy --prod failed.', { stderr: out.stderr.trim().slice(-600) });
|
|
83
83
|
return url;
|
|
84
84
|
}
|
|
85
|
-
/**
|
|
85
|
+
/**
|
|
86
|
+
* Signed-out requests as a browser makes them: the home page must answer with
|
|
87
|
+
* the sign-in page, and a link no store holds with 404, which proves the store
|
|
88
|
+
* that keeps people's links is wired.
|
|
89
|
+
*/
|
|
86
90
|
async function smoke(url) {
|
|
87
91
|
try {
|
|
88
92
|
const res = await fetch(`${url}/`, GATE_REQUEST);
|
|
89
|
-
|
|
93
|
+
const gate = gateVerdict({
|
|
90
94
|
status: res.status,
|
|
91
95
|
location: res.headers.get('location'),
|
|
92
96
|
robots: res.headers.get('x-robots-tag'),
|
|
93
97
|
body: await res.text(),
|
|
94
98
|
});
|
|
99
|
+
if (!gate.ok)
|
|
100
|
+
return gate;
|
|
101
|
+
return storeVerdict((await fetch(`${url}${PROBE_LINK}`, GATE_REQUEST)).status);
|
|
95
102
|
}
|
|
96
103
|
catch (error) {
|
|
97
104
|
return {
|
|
@@ -122,7 +129,7 @@ function target() {
|
|
|
122
129
|
const project = linkedProject(ROOT);
|
|
123
130
|
if (!project)
|
|
124
131
|
throw new CliError('This folder is not linked to a Vercel project.', {
|
|
125
|
-
fix: 'design-hub bootstrap --vercel <project> --team <team>',
|
|
132
|
+
fix: 'design-hub bootstrap --vercel <project> --team <team> --review',
|
|
126
133
|
});
|
|
127
134
|
return { project, scope: linkedOrg(ROOT) };
|
|
128
135
|
}
|
|
@@ -149,15 +156,16 @@ async function deploy(route, project, scope) {
|
|
|
149
156
|
return { via: 'git', deployment: await viaGit(project, scope, route.branch) };
|
|
150
157
|
return { via: 'cli', deployment: viaCli() };
|
|
151
158
|
}
|
|
159
|
+
/** People sign in with their own one-time links, so the handover carries no secret, only who to add. */
|
|
152
160
|
function handover(url) {
|
|
153
161
|
const env = readEnv(ROOT);
|
|
154
162
|
const review = STORE_ENV.every((n) => env[n]) ? 'on' : 'off';
|
|
155
163
|
return {
|
|
156
|
-
share: { url,
|
|
164
|
+
share: { url, open: opens() },
|
|
157
165
|
review,
|
|
158
166
|
next: review === 'on'
|
|
159
|
-
? `
|
|
160
|
-
: '
|
|
167
|
+
? `Add each person with pnpm people add --name "<name>" --team "<team>" --site ${url} (--kind studio for the studio), and send each person their own link with the handover (miles-deploy). A link signs in one device, then stops working. Never send GATE_SECRET.`
|
|
168
|
+
: 'Nobody can sign in without the review store: run design-hub bootstrap --vercel <project> --review, then share again. Never send GATE_SECRET.',
|
|
161
169
|
};
|
|
162
170
|
}
|
|
163
171
|
export async function main({ flags }) {
|
package/dist/server/api.d.ts
CHANGED
|
@@ -16,7 +16,11 @@ export type Deployed = {
|
|
|
16
16
|
} | {
|
|
17
17
|
error: string;
|
|
18
18
|
};
|
|
19
|
-
/**
|
|
20
|
-
|
|
19
|
+
/**
|
|
20
|
+
* The review service as deployed: Upstash for the store, Jev for triage when
|
|
21
|
+
* its key is set and `checks` is given. `now` is the clock, so the gate and
|
|
22
|
+
* the service it asks run on one (the gate's tests move it).
|
|
23
|
+
*/
|
|
24
|
+
export declare function deployedReview(env: Record<string, string | undefined>, checks?: Checks | null, now?: () => Date): Deployed;
|
|
21
25
|
/** The Vercel function's whole body; `checks` is the project's checks.json, bundled by its api/review.ts. */
|
|
22
26
|
export declare function deployedHandler(request: Request, checks: Checks | null): Promise<Response>;
|
package/dist/server/api.js
CHANGED
|
@@ -5,15 +5,16 @@ import { PERSON_COOKIE, readCookie, readGate, readPersonToken, sameOrigin } from
|
|
|
5
5
|
import { storeConfig, upstashKV } from './upstash.js';
|
|
6
6
|
export const API_PATH = '/api/review';
|
|
7
7
|
const MAX_BODY_BYTES = 64 * 1024;
|
|
8
|
+
const STORE_DOWN = 'The review store did not answer. Try again.';
|
|
8
9
|
const STATUS = {
|
|
9
10
|
unauthorized: 401,
|
|
10
11
|
forbidden: 403,
|
|
11
12
|
not_found: 404,
|
|
12
13
|
invalid: 422,
|
|
13
14
|
};
|
|
14
|
-
const json = (status, body) => new Response(JSON.stringify(body), {
|
|
15
|
+
const json = (status, body, extra = {}) => new Response(JSON.stringify(body), {
|
|
15
16
|
status,
|
|
16
|
-
headers: { 'content-type': 'application/json; charset=utf-8', 'cache-control': 'no-store' },
|
|
17
|
+
headers: { 'content-type': 'application/json; charset=utf-8', 'cache-control': 'no-store', ...extra },
|
|
17
18
|
});
|
|
18
19
|
/** What the browser may see of a person: everything but the session epoch. */
|
|
19
20
|
const visible = ({ epoch: _epoch, ...p }) => p;
|
|
@@ -29,22 +30,54 @@ async function query(op, params, { review, actor }) {
|
|
|
29
30
|
case 'me':
|
|
30
31
|
return { person: actor ? visible(actor) : null };
|
|
31
32
|
case 'comments':
|
|
32
|
-
|
|
33
|
+
// viewAs=client is Studio's Client view; the service checks the value and never widens a Client's view.
|
|
34
|
+
return {
|
|
35
|
+
comments: await review.listComments(actor, prototypeOf(params.get('prototype')), params.get('viewAs') ?? undefined),
|
|
36
|
+
};
|
|
33
37
|
case 'people':
|
|
34
38
|
return { people: (await review.listPeople(actor)).map(visible) };
|
|
39
|
+
case 'access':
|
|
40
|
+
return { access: await review.defaultAccess(actor) };
|
|
35
41
|
default:
|
|
36
42
|
return undefined;
|
|
37
43
|
}
|
|
38
44
|
}
|
|
39
|
-
|
|
45
|
+
const link = (r) => ({
|
|
46
|
+
person: visible(r.person),
|
|
47
|
+
link: `/invite/${r.token}`,
|
|
48
|
+
});
|
|
49
|
+
/** Studio's commands over people, their links and how long they keep access. */
|
|
50
|
+
async function peopleCommand(op, b, { review, actor }) {
|
|
51
|
+
switch (op) {
|
|
52
|
+
case 'people.add':
|
|
53
|
+
return link(await review.addPerson(actor, { name: b.name, team: b.team, kind: b.kind, access: b.access }));
|
|
54
|
+
case 'people.link':
|
|
55
|
+
return link(await review.newLink(actor, str(b.id)));
|
|
56
|
+
case 'people.signOut':
|
|
57
|
+
return link(await review.signOutEverywhere(actor, str(b.id)));
|
|
58
|
+
case 'people.revoke':
|
|
59
|
+
return { person: visible(await review.revoke(actor, str(b.id))) };
|
|
60
|
+
case 'people.access':
|
|
61
|
+
return { person: visible(await review.setAccess(actor, str(b.id), b.access)) };
|
|
62
|
+
case 'access.set':
|
|
63
|
+
return { access: await review.setDefaultAccess(actor, b.access) };
|
|
64
|
+
default:
|
|
65
|
+
return undefined;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
async function command(op, b, ctx) {
|
|
69
|
+
const { review, actor } = ctx;
|
|
40
70
|
const at = () => ({ prototype: prototypeOf(b.prototype), id: str(b.id) });
|
|
41
|
-
const link = (r) => ({
|
|
42
|
-
person: visible(r.person),
|
|
43
|
-
link: `/invite/${r.token}`,
|
|
44
|
-
});
|
|
45
71
|
switch (op) {
|
|
46
72
|
case 'comment.add':
|
|
47
|
-
return {
|
|
73
|
+
return {
|
|
74
|
+
comment: await review.add(actor, {
|
|
75
|
+
body: b.body,
|
|
76
|
+
anchor: b.anchor,
|
|
77
|
+
states: b.states,
|
|
78
|
+
audience: b.audience,
|
|
79
|
+
}),
|
|
80
|
+
};
|
|
48
81
|
case 'comment.reply':
|
|
49
82
|
return {
|
|
50
83
|
comment: await review.reply(actor, {
|
|
@@ -61,14 +94,8 @@ async function command(op, b, { review, actor }) {
|
|
|
61
94
|
return { comment: await review.resolve(actor, { ...at(), resolved: b.resolved === true }) };
|
|
62
95
|
case 'comment.triage':
|
|
63
96
|
return { comment: await review.retriage(actor, { ...at(), triage: b.triage, states: b.states }) };
|
|
64
|
-
case 'people.invite':
|
|
65
|
-
return link(await review.invite(actor, { name: b.name, team: b.team, kind: b.kind }));
|
|
66
|
-
case 'people.reissue':
|
|
67
|
-
return link(await review.reissue(actor, str(b.id)));
|
|
68
|
-
case 'people.revoke':
|
|
69
|
-
return { person: visible(await review.revoke(actor, str(b.id))) };
|
|
70
97
|
default:
|
|
71
|
-
return
|
|
98
|
+
return peopleCommand(op, b, ctx);
|
|
72
99
|
}
|
|
73
100
|
}
|
|
74
101
|
async function readJson(request) {
|
|
@@ -110,7 +137,7 @@ export async function handleReview(request, ctx) {
|
|
|
110
137
|
if (error instanceof ReviewError)
|
|
111
138
|
return json(STATUS[error.code], { error: error.message, problems: error.problems });
|
|
112
139
|
console.error('[review]', error);
|
|
113
|
-
return json(
|
|
140
|
+
return json(503, { error: STORE_DOWN }, { 'retry-after': '30' });
|
|
114
141
|
}
|
|
115
142
|
}
|
|
116
143
|
/** The person a request's signed cookie names, while they may still sign in. */
|
|
@@ -118,8 +145,12 @@ export async function actorFrom(request, review, gate) {
|
|
|
118
145
|
const claim = await readPersonToken(gate, readCookie(request, PERSON_COOKIE));
|
|
119
146
|
return claim ? review.sessionPerson(claim.id, claim.epoch) : null;
|
|
120
147
|
}
|
|
121
|
-
/**
|
|
122
|
-
|
|
148
|
+
/**
|
|
149
|
+
* The review service as deployed: Upstash for the store, Jev for triage when
|
|
150
|
+
* its key is set and `checks` is given. `now` is the clock, so the gate and
|
|
151
|
+
* the service it asks run on one (the gate's tests move it).
|
|
152
|
+
*/
|
|
153
|
+
export function deployedReview(env, checks = null, now) {
|
|
123
154
|
const gate = readGate(env);
|
|
124
155
|
if (!gate)
|
|
125
156
|
return { error: 'The prototype gate is not configured.' };
|
|
@@ -128,7 +159,10 @@ export function deployedReview(env, checks = null) {
|
|
|
128
159
|
return { error: 'Review is not set up on this site: pnpm bootstrap --vercel <project> --review.' };
|
|
129
160
|
return {
|
|
130
161
|
gate,
|
|
131
|
-
review: createReview(upstashKV(store), {
|
|
162
|
+
review: createReview(upstashKV(store), {
|
|
163
|
+
triage: jevTriager(env.TYPESAFE_API_KEY ?? '', checks),
|
|
164
|
+
...(now ? { now } : {}),
|
|
165
|
+
}),
|
|
132
166
|
};
|
|
133
167
|
}
|
|
134
168
|
/** The Vercel function's whole body; `checks` is the project's checks.json, bundled by its api/review.ts. */
|
|
@@ -136,8 +170,15 @@ export async function deployedHandler(request, checks) {
|
|
|
136
170
|
const setup = deployedReview(process.env, checks);
|
|
137
171
|
if ('error' in setup)
|
|
138
172
|
return json(503, { error: setup.error });
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
actor
|
|
142
|
-
}
|
|
173
|
+
let actor;
|
|
174
|
+
try {
|
|
175
|
+
actor = await actorFrom(request, setup.review, setup.gate);
|
|
176
|
+
}
|
|
177
|
+
catch (error) {
|
|
178
|
+
// The store is down: say so in JSON, as every other answer here is, so the panel can retry.
|
|
179
|
+
console.error('[review]', error);
|
|
180
|
+
// Retry-After tells the panel this passes, unlike a 503 for a site with no store.
|
|
181
|
+
return json(503, { error: STORE_DOWN }, { 'retry-after': '30' });
|
|
182
|
+
}
|
|
183
|
+
return handleReview(request, { review: setup.review, actor });
|
|
143
184
|
}
|
|
@@ -12,8 +12,9 @@ export function fakeUpstash() {
|
|
|
12
12
|
await kv.hset(key, a, b);
|
|
13
13
|
return 1;
|
|
14
14
|
case 'HDEL':
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
return kv.hdel(key, a);
|
|
16
|
+
case 'HINCRBY':
|
|
17
|
+
return kv.hincrby(key, a, Number(b));
|
|
17
18
|
case 'HGETALL':
|
|
18
19
|
return Object.entries(await kv.hgetall(key)).flat();
|
|
19
20
|
case 'SADD':
|
package/dist/server/local.js
CHANGED
package/dist/server/session.d.ts
CHANGED
|
@@ -1,22 +1,37 @@
|
|
|
1
|
-
export declare const GATE_COOKIE = "__Host-hub_gate";
|
|
2
1
|
export declare const PERSON_COOKIE = "__Host-hub_person";
|
|
2
|
+
/** How long the store's last yes is trusted before the gate asks again. */
|
|
3
|
+
export declare const CHECK_SECONDS: number;
|
|
4
|
+
/**
|
|
5
|
+
* `site` is the review store's URL. It is signed into every token, so two
|
|
6
|
+
* projects that share one GATE_SECRET (a copied folder keeps its .env) never
|
|
7
|
+
* accept each other's cookies. Empty without a store, when nobody can sign in anyway.
|
|
8
|
+
*/
|
|
3
9
|
export type Gate = {
|
|
4
|
-
password: string;
|
|
5
10
|
secret: string;
|
|
11
|
+
site: string;
|
|
6
12
|
};
|
|
7
|
-
/** The gate's settings, or null when
|
|
13
|
+
/** The gate's settings, or null when GATE_SECRET is missing or short (the gate then fails closed). */
|
|
8
14
|
export declare function readGate(env: Record<string, string | undefined>): Gate | null;
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
15
|
+
/**
|
|
16
|
+
* How long a session started at `at` lasts, in seconds: to the access end,
|
|
17
|
+
* capped at 400 days, and 0 for an access end that has passed or does not parse.
|
|
18
|
+
*/
|
|
19
|
+
export declare function sessionSeconds(endsAt: string | null, at?: Date): number;
|
|
12
20
|
export type PersonClaim = {
|
|
13
21
|
id: string;
|
|
14
22
|
epoch: number;
|
|
15
23
|
};
|
|
16
|
-
export
|
|
17
|
-
|
|
18
|
-
|
|
24
|
+
export type SessionClaim = PersonClaim & {
|
|
25
|
+
checkedAt: number;
|
|
26
|
+
};
|
|
27
|
+
/** A token for someone the store said yes to at `at`, lasting to their access end. */
|
|
28
|
+
export declare function issuePersonToken(gate: Gate, claim: PersonClaim, endsAt: string | null, at?: Date): Promise<string>;
|
|
29
|
+
/** The person a token names when its signature and expiry hold; the caller decides whether to ask the store. */
|
|
30
|
+
export declare function readPersonToken(gate: Gate, token: string | undefined, at?: Date): Promise<SessionClaim | null>;
|
|
31
|
+
/** Whether the store's yes in this claim is recent enough to trust without asking again. */
|
|
32
|
+
export declare function isFresh(claim: SessionClaim, at?: Date): boolean;
|
|
19
33
|
export declare function readCookie(request: Request, name: string): string | undefined;
|
|
20
|
-
|
|
34
|
+
/** A session cookie that lasts `seconds`: sessionSeconds of the same access end as its token. */
|
|
35
|
+
export declare const sessionCookie: (name: string, value: string, seconds: number) => string;
|
|
21
36
|
export declare const clearedCookie: (name: string) => string;
|
|
22
37
|
export declare function sameOrigin(request: Request): boolean;
|