@milesroxas/design-hub 0.9.0 → 0.11.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 +13 -11
- package/core/controls.test.ts +176 -0
- package/core/controls.ts +195 -0
- package/core/files.test.ts +76 -0
- package/core/files.ts +131 -0
- package/core/prototype.test.ts +124 -7
- package/core/prototype.ts +133 -24
- package/core/review/model.ts +144 -2
- package/core/review/policy.test.ts +79 -22
- package/core/review/policy.ts +36 -8
- package/core/review/service.test.ts +1525 -322
- package/core/review/service.ts +810 -183
- package/core/review/store.test.ts +91 -0
- package/core/review/store.ts +143 -26
- package/dist/core/controls.d.ts +55 -0
- package/dist/core/controls.js +174 -0
- package/dist/core/files.d.ts +39 -0
- package/dist/core/files.js +107 -0
- package/dist/core/prototype.d.ts +61 -12
- package/dist/core/prototype.js +105 -26
- package/dist/core/review/model.d.ts +87 -2
- package/dist/core/review/model.js +97 -1
- package/dist/core/review/policy.d.ts +11 -4
- package/dist/core/review/policy.js +14 -2
- package/dist/core/review/service.d.ts +222 -43
- package/dist/core/review/service.js +727 -182
- package/dist/core/review/store.d.ts +84 -24
- package/dist/core/review/store.js +66 -26
- package/dist/scripts/bootstrap.d.ts +4 -34
- package/dist/scripts/bootstrap.js +9 -244
- package/dist/scripts/cli.js +6 -0
- package/dist/scripts/client.d.ts +45 -0
- package/dist/scripts/client.js +320 -0
- package/dist/scripts/commands.js +6 -0
- package/dist/scripts/comments.d.ts +8 -26
- package/dist/scripts/comments.js +27 -14
- package/dist/scripts/guard.d.ts +11 -0
- package/dist/scripts/guard.js +44 -0
- package/dist/scripts/lib/builds.d.ts +40 -0
- package/dist/scripts/lib/builds.js +198 -0
- package/dist/scripts/lib/cli.js +3 -1
- package/dist/scripts/lib/deploy.d.ts +6 -90
- package/dist/scripts/lib/deploy.js +24 -137
- package/dist/scripts/lib/dns.d.ts +49 -0
- package/dist/scripts/lib/dns.js +141 -0
- package/dist/scripts/lib/fake-host.d.ts +168 -0
- package/dist/scripts/lib/fake-host.js +244 -0
- package/dist/scripts/lib/host.d.ts +87 -0
- package/dist/scripts/lib/host.js +362 -0
- package/dist/scripts/lib/linked.d.ts +51 -0
- package/dist/scripts/lib/linked.js +124 -0
- package/dist/scripts/lib/names.d.ts +35 -0
- package/dist/scripts/lib/names.js +77 -0
- package/dist/scripts/lib/review.d.ts +23 -2
- package/dist/scripts/lib/review.js +32 -15
- package/dist/scripts/lib/rules.d.ts +1 -0
- package/dist/scripts/lib/rules.js +1 -0
- package/dist/scripts/lib/studio-deps.d.ts +35 -0
- package/dist/scripts/lib/studio-deps.js +79 -0
- package/dist/scripts/lib/studios.d.ts +70 -0
- package/dist/scripts/lib/studios.js +187 -0
- package/dist/scripts/lib/update.d.ts +33 -0
- package/dist/scripts/lib/update.js +40 -0
- package/dist/scripts/lib/vercel.d.ts +1 -23
- package/dist/scripts/lib/vercel.js +6 -81
- package/dist/scripts/people.d.ts +7 -11
- package/dist/scripts/people.js +51 -46
- package/dist/scripts/preflight.d.ts +8 -1
- package/dist/scripts/preflight.js +36 -19
- package/dist/scripts/project.d.ts +86 -0
- package/dist/scripts/project.js +141 -0
- package/dist/scripts/share.d.ts +105 -30
- package/dist/scripts/share.js +82 -154
- package/dist/scripts/skills.d.ts +18 -2
- package/dist/scripts/skills.js +22 -3
- package/dist/scripts/studio.d.ts +75 -0
- package/dist/scripts/studio.js +401 -0
- package/dist/scripts/upgrade.d.ts +10 -2
- package/dist/scripts/upgrade.js +44 -14
- package/dist/server/api.d.ts +22 -11
- package/dist/server/api.js +125 -44
- package/dist/server/blob.d.ts +10 -0
- package/dist/server/blob.js +53 -0
- package/dist/server/checks.js +2 -2
- package/dist/server/dev.js +4 -4
- package/dist/server/env.d.ts +2 -0
- package/dist/server/env.js +9 -0
- package/dist/server/fake-upstash.js +52 -3
- package/dist/server/hosts.d.ts +11 -0
- package/dist/server/hosts.js +31 -0
- package/dist/server/local.d.ts +7 -1
- package/dist/server/local.js +10 -1
- package/dist/server/mark.d.ts +41 -0
- package/dist/server/mark.js +111 -0
- package/dist/server/session.d.ts +17 -9
- package/dist/server/session.js +22 -45
- package/dist/server/upstash.js +20 -0
- package/dist/vercel/files.d.ts +11 -0
- package/dist/vercel/files.js +68 -0
- package/dist/vercel/index.d.ts +4 -3
- package/dist/vercel/index.js +12 -8
- package/dist/vercel/proxy.d.ts +69 -4
- package/dist/vercel/proxy.js +171 -107
- package/dist/vite/plugin.d.ts +24 -1
- package/dist/vite/plugin.js +46 -2
- package/kit/Artboard.tsx +21 -8
- package/kit/Space.tsx +4 -3
- package/kit/Variants.tsx +193 -65
- package/kit/ViewTools.tsx +77 -11
- package/kit/audience.ts +85 -0
- package/kit/dials.css +59 -0
- package/kit/dials.tsx +272 -35
- package/kit/harness.css +34 -0
- package/kit/prefs.ts +23 -1
- package/package.json +3 -2
- package/shell/ClientViewNote.tsx +31 -3
- package/shell/Guide.tsx +11 -5
- package/shell/Index.tsx +32 -10
- package/shell/Notice.tsx +1 -1
- package/shell/controls.ts +26 -0
- package/shell/hub.ts +5 -1
- package/shell/main.tsx +33 -6
- package/shell/review/Review.tsx +2 -2
- package/shell/review/ThreadCard.tsx +5 -5
- package/shell/review/client.ts +28 -11
- package/shell/review/view.test.ts +19 -0
- package/shell/review/view.ts +25 -0
- package/shell/shell.css +8 -0
- package/shell/studio/ClientHub.tsx +98 -0
- package/shell/studio/hub.css +48 -0
- package/shell/studio/index.html +14 -0
- package/shell/studio/main.tsx +17 -0
- package/skills/miles-brand/SKILL.md +11 -1
- package/skills/miles-deploy/SKILL.md +121 -64
- package/skills/miles-design-hub/SKILL.md +11 -9
- package/skills/miles-prototype/SKILL.md +34 -1
- package/skills/miles-review/SKILL.md +5 -7
- package/skills/miles-worktrees/SKILL.md +3 -3
- package/templates/conductor/settings.toml +1 -1
- package/templates/studio/.env.example +9 -0
- package/templates/studio/.vercelignore +5 -0
- package/templates/studio/README.md +84 -0
- package/templates/studio/_gitignore +7 -0
- package/templates/studio/api/files.ts +4 -0
- package/templates/studio/api/review.ts +4 -0
- package/templates/studio/build.mjs +4 -0
- package/templates/studio/package.json +16 -0
- package/templates/studio/proxy.ts +4 -0
- package/templates/studio/studio.json +9 -0
- package/templates/studio/vercel.json +27 -0
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
// The files port: where a studio keeps every project's builds. A build is
|
|
2
|
+
// uploaded under `c/<client>/<project>/<build>/…`, and the studio site serves
|
|
3
|
+
// the one the project's record points at (`Project.build`). Production is a
|
|
4
|
+
// private Vercel Blob store (server/blob.ts); tests use the in-memory store
|
|
5
|
+
// below. Every path is built here, from checked parts, so no request can name
|
|
6
|
+
// a file outside its own client and project.
|
|
7
|
+
import { isClientSlug, isProjectSlug, isSegment } from './prototype.js';
|
|
8
|
+
/**
|
|
9
|
+
* A build's id: random, lower-case letters and digits, and never used twice
|
|
10
|
+
* for the life of the store, so a path never comes back with other bytes.
|
|
11
|
+
*/
|
|
12
|
+
const BUILD_ID = /^[a-z0-9]{16,64}$/;
|
|
13
|
+
export const isBuildId = (v) => typeof v === 'string' && BUILD_ID.test(v);
|
|
14
|
+
function checked(ok, what, v) {
|
|
15
|
+
// A bad part is a bug in the caller, never input to answer: fail closed before any store call.
|
|
16
|
+
if (!ok)
|
|
17
|
+
throw new Error(`Not a file path: ${what} is ${JSON.stringify(v)}.`);
|
|
18
|
+
}
|
|
19
|
+
/** A file inside a build, as a list of path segments, each one `isSegment`: the rule the studio gate reads a path by. */
|
|
20
|
+
const isFile = (segments) => segments.length > 0 && segments.every(isSegment);
|
|
21
|
+
/**
|
|
22
|
+
* Removes every file under a prefix, in the store's batches of 1,000, and
|
|
23
|
+
* says how many there were. Takes a prefix one of the functions below built,
|
|
24
|
+
* so it never reaches past its scope.
|
|
25
|
+
*/
|
|
26
|
+
export async function clearPrefix(files, prefix) {
|
|
27
|
+
const paths = await files.list(prefix);
|
|
28
|
+
await removeAll(files, paths);
|
|
29
|
+
return paths.length;
|
|
30
|
+
}
|
|
31
|
+
/** Removes these paths, in the store's batches of 1,000. */
|
|
32
|
+
export async function removeAll(files, paths) {
|
|
33
|
+
for (let i = 0; i < paths.length; i += 1000)
|
|
34
|
+
await files.remove(paths.slice(i, i + 1000));
|
|
35
|
+
}
|
|
36
|
+
/** Every file of one client, every project and build: what archiving the client removes. Ends in `/`. */
|
|
37
|
+
export function clientPrefix(client) {
|
|
38
|
+
checked(isClientSlug(client), 'client', client);
|
|
39
|
+
return `c/${client}/`;
|
|
40
|
+
}
|
|
41
|
+
/** Every build of one project, ending in `/`, so `c/acme/rebrand/` never lists `c/acme/rebrand-2/`. */
|
|
42
|
+
export function projectPrefix(scope) {
|
|
43
|
+
checked(isClientSlug(scope.client), 'client', scope.client);
|
|
44
|
+
checked(isProjectSlug(scope.project), 'project', scope.project);
|
|
45
|
+
return `c/${scope.client}/${scope.project}/`;
|
|
46
|
+
}
|
|
47
|
+
/** The folder of one build of a project, ending in `/`. */
|
|
48
|
+
export function buildPrefix(scope, build) {
|
|
49
|
+
const prefix = projectPrefix(scope);
|
|
50
|
+
checked(isBuildId(build), 'build', build);
|
|
51
|
+
return `${prefix}${build}/`;
|
|
52
|
+
}
|
|
53
|
+
/** One file of one build: `c/<client>/<project>/<build>/<file>`, with `file` given as its segments. */
|
|
54
|
+
export function filePath(scope, build, file) {
|
|
55
|
+
checked(isFile(file), 'file', file);
|
|
56
|
+
return `${buildPrefix(scope, build)}${file.join('/')}`;
|
|
57
|
+
}
|
|
58
|
+
const TYPES = {
|
|
59
|
+
html: 'text/html; charset=utf-8',
|
|
60
|
+
js: 'text/javascript; charset=utf-8',
|
|
61
|
+
mjs: 'text/javascript; charset=utf-8',
|
|
62
|
+
css: 'text/css; charset=utf-8',
|
|
63
|
+
json: 'application/json',
|
|
64
|
+
webmanifest: 'application/manifest+json',
|
|
65
|
+
map: 'application/json',
|
|
66
|
+
md: 'text/markdown; charset=utf-8',
|
|
67
|
+
txt: 'text/plain; charset=utf-8',
|
|
68
|
+
xml: 'application/xml',
|
|
69
|
+
pdf: 'application/pdf',
|
|
70
|
+
svg: 'image/svg+xml',
|
|
71
|
+
png: 'image/png',
|
|
72
|
+
jpg: 'image/jpeg',
|
|
73
|
+
jpeg: 'image/jpeg',
|
|
74
|
+
gif: 'image/gif',
|
|
75
|
+
webp: 'image/webp',
|
|
76
|
+
avif: 'image/avif',
|
|
77
|
+
ico: 'image/x-icon',
|
|
78
|
+
woff2: 'font/woff2',
|
|
79
|
+
woff: 'font/woff',
|
|
80
|
+
ttf: 'font/ttf',
|
|
81
|
+
otf: 'font/otf',
|
|
82
|
+
mp4: 'video/mp4',
|
|
83
|
+
webm: 'video/webm',
|
|
84
|
+
wasm: 'application/wasm',
|
|
85
|
+
};
|
|
86
|
+
/** The type a built file is stored with, from its extension. */
|
|
87
|
+
export function typeOf(path) {
|
|
88
|
+
const ext = path.match(/\.([a-z0-9]+)$/i)?.[1]?.toLowerCase() ?? '';
|
|
89
|
+
return Object.hasOwn(TYPES, ext) ? TYPES[ext] : 'application/octet-stream';
|
|
90
|
+
}
|
|
91
|
+
/** The files port in memory, for tests and for a studio run on one machine. */
|
|
92
|
+
export function memoryFiles() {
|
|
93
|
+
const files = new Map();
|
|
94
|
+
return {
|
|
95
|
+
put: async (path, body, type) => {
|
|
96
|
+
if (files.has(path))
|
|
97
|
+
throw new Error(`${path} exists; a build's paths are never overwritten.`);
|
|
98
|
+
files.set(path, { body, type });
|
|
99
|
+
},
|
|
100
|
+
get: async (path) => files.get(path) ?? null,
|
|
101
|
+
list: async (prefix) => [...files.keys()].filter((p) => p.startsWith(prefix)).sort(),
|
|
102
|
+
remove: async (paths) => {
|
|
103
|
+
for (const p of paths)
|
|
104
|
+
files.delete(p);
|
|
105
|
+
},
|
|
106
|
+
};
|
|
107
|
+
}
|
package/dist/core/prototype.d.ts
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
* the review API,
|
|
2
|
+
* Never a project's or a prototype's slug: every first path segment the gate
|
|
3
|
+
* answers itself (the link path, the review API, the gate's font, the built
|
|
4
|
+
* prototypes, the shared bundle, the walkthroughs, the hub's own top files).
|
|
4
5
|
*/
|
|
5
|
-
export declare const RESERVED: readonly ['
|
|
6
|
+
export declare const RESERVED: readonly ['invite', 'api', '_gate', '_p', 'assets', 'guide', 'index.html', 'favicon.svg'];
|
|
7
|
+
/** Never a client's slug: the studio's own host, and the names a host is often given. */
|
|
8
|
+
export declare const RESERVED_CLIENTS: readonly ['studio', 'www', 'api'];
|
|
6
9
|
/**
|
|
7
10
|
* Everything built from `prototypes/<slug>/` lands under `/_p/<slug>/`, and
|
|
8
11
|
* Studio's list of every slug at `/_p/all.js`. `_p` can never be a slug: SLUG
|
|
@@ -13,17 +16,63 @@ export declare const ALL_FILE = "_p/all.js";
|
|
|
13
16
|
export declare const entryFile: (slug: string) => string;
|
|
14
17
|
/** Whether `name` can be a prototype's folder: kebab-case and not one of the hub's own paths. */
|
|
15
18
|
export declare const isPrototypeSlug: (name: unknown) => name is string;
|
|
19
|
+
/** A project is a first path segment too, below its client's host, so it follows the prototype's rule. */
|
|
20
|
+
export declare const isProjectSlug: typeof isPrototypeSlug;
|
|
21
|
+
/** Whether `name` can be a client: kebab-case and not one of the studio's own host names. */
|
|
22
|
+
export declare const isClientSlug: (name: unknown) => name is string;
|
|
23
|
+
export declare const isSegment: (s: string) => boolean;
|
|
24
|
+
/** The one-time link path, matched on the path as sent, as the gate always has. */
|
|
25
|
+
export declare const LINK_PATH: RegExp;
|
|
26
|
+
/** What the gate pages load before sign-in, at the host root: the hub's face and the favicon. */
|
|
27
|
+
export declare const GATE_FONT = "/_gate/geist.woff2";
|
|
16
28
|
/**
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
* prototype slug; anything else (`_P`, `_p;x`, `_p.`, a full-width `_p`)
|
|
21
|
-
* belongs to `''`, refused like an internal prototype. A path under `/_p/`
|
|
22
|
-
* always belongs to one, so its name may be no slug at all (`all.js`), which
|
|
23
|
-
* no audience makes client-facing. A path that could mean more than one file
|
|
24
|
-
* belongs to `''` too.
|
|
29
|
+
* The host proof `client add` asks a new client's host for: the studio gate
|
|
30
|
+
* answers a GET of it with the proof's answer only when the store holds that
|
|
31
|
+
* ask for the host's client. Otherwise it is a hub path like any other.
|
|
25
32
|
*/
|
|
26
|
-
export declare
|
|
33
|
+
export declare const PROOF_PATH: RegExp;
|
|
34
|
+
export declare const proofPath: (ask: string) => string;
|
|
35
|
+
/**
|
|
36
|
+
* Where a request on a studio site goes:
|
|
37
|
+
*
|
|
38
|
+
* - `none`: nothing; the gate's plain 404, whoever asks.
|
|
39
|
+
* - `link`: `/invite/<token>`, at the host root only.
|
|
40
|
+
* - `asset`: the gate's font and the favicon, served before sign-in.
|
|
41
|
+
* - `hub`: the client's hub page and its own files (`/`, `/index.html`, `/assets/…`, `/_gate/…`).
|
|
42
|
+
* - `api`: a function at the root (`project` null), or a project's review API, `/<project>/api/review`.
|
|
43
|
+
* - `file`: a file of a project's build, as its segments ([] for the project's own page), and
|
|
44
|
+
* the prototype it belongs to (`prototypeOfParts`), read below the project.
|
|
45
|
+
*/
|
|
46
|
+
export type Where = {
|
|
47
|
+
kind: 'none';
|
|
48
|
+
} | {
|
|
49
|
+
kind: 'link';
|
|
50
|
+
token: string;
|
|
51
|
+
} | {
|
|
52
|
+
kind: 'asset';
|
|
53
|
+
} | {
|
|
54
|
+
kind: 'hub';
|
|
55
|
+
} | {
|
|
56
|
+
kind: 'api';
|
|
57
|
+
project: string | null;
|
|
58
|
+
} | {
|
|
59
|
+
kind: 'file';
|
|
60
|
+
project: string;
|
|
61
|
+
file: string[];
|
|
62
|
+
prototype: string | null;
|
|
63
|
+
};
|
|
64
|
+
/** Where a request goes, and the host it was sent to: lower case, no port, or '' when it is no host name. */
|
|
65
|
+
export type Route = {
|
|
66
|
+
host: string;
|
|
67
|
+
} & Where;
|
|
68
|
+
/** A host name as a lookup key: lower case, no port, no trailing dot; '' for anything that is not one. */
|
|
69
|
+
export declare function hostName(host: string): string;
|
|
70
|
+
/**
|
|
71
|
+
* The one place a studio site reads a request's path. It fails closed: a
|
|
72
|
+
* 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
|
|
73
|
+
* codename): this names the host, never the client.
|
|
74
|
+
*/
|
|
75
|
+
export declare function routeOf(host: string, pathname: string): Route;
|
|
27
76
|
/**
|
|
28
77
|
* Whether a built prototype's entry is there for this person, asked with a
|
|
29
78
|
* HEAD before it is imported. Not there: a 404 (the gate's answer for a
|
package/dist/core/prototype.js
CHANGED
|
@@ -3,10 +3,22 @@
|
|
|
3
3
|
// folder the hub lists is always a path the gate knows how to refuse.
|
|
4
4
|
import { SLUG } from './feature.js';
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
7
|
-
* the review API,
|
|
6
|
+
* Never a project's or a prototype's slug: every first path segment the gate
|
|
7
|
+
* answers itself (the link path, the review API, the gate's font, the built
|
|
8
|
+
* prototypes, the shared bundle, the walkthroughs, the hub's own top files).
|
|
8
9
|
*/
|
|
9
|
-
export const RESERVED = [
|
|
10
|
+
export const RESERVED = [
|
|
11
|
+
'invite',
|
|
12
|
+
'api',
|
|
13
|
+
'_gate',
|
|
14
|
+
'_p',
|
|
15
|
+
'assets',
|
|
16
|
+
'guide',
|
|
17
|
+
'index.html',
|
|
18
|
+
'favicon.svg',
|
|
19
|
+
];
|
|
20
|
+
/** Never a client's slug: the studio's own host, and the names a host is often given. */
|
|
21
|
+
export const RESERVED_CLIENTS = ['studio', 'www', 'api'];
|
|
10
22
|
/**
|
|
11
23
|
* Everything built from `prototypes/<slug>/` lands under `/_p/<slug>/`, and
|
|
12
24
|
* Studio's list of every slug at `/_p/all.js`. `_p` can never be a slug: SLUG
|
|
@@ -17,12 +29,27 @@ export const ALL_FILE = `${PROTOTYPE_DIR}/all.js`;
|
|
|
17
29
|
export const entryFile = (slug) => `${PROTOTYPE_DIR}/${slug}/entry.js`;
|
|
18
30
|
/** Whether `name` can be a prototype's folder: kebab-case and not one of the hub's own paths. */
|
|
19
31
|
export const isPrototypeSlug = (name) => typeof name === 'string' && SLUG.test(name) && !RESERVED.includes(name);
|
|
32
|
+
/** A project is a first path segment too, below its client's host, so it follows the prototype's rule. */
|
|
33
|
+
export const isProjectSlug = isPrototypeSlug;
|
|
34
|
+
/** Whether `name` can be a client: kebab-case and not one of the studio's own host names. */
|
|
35
|
+
export const isClientSlug = (name) => typeof name === 'string' && SLUG.test(name) && !RESERVED_CLIENTS.includes(name);
|
|
36
|
+
/**
|
|
37
|
+
* A path segment that names one file wherever it is read: the characters a
|
|
38
|
+
* URL path carries as they are (RFC 3986: ASCII letters and digits,
|
|
39
|
+
* `-._~!$&'()*+,;=:@`), letters, marks and digits of any script, and spaces
|
|
40
|
+
* inside a name. Never a control character, `%`, `?`, `#`, a backslash or a slash,
|
|
41
|
+
* which a URL parser drops, cuts at or rewrites (`.<tab>.` becomes `..`), and
|
|
42
|
+
* never `.` or `..`.
|
|
43
|
+
*/
|
|
44
|
+
const SEGMENT = /^(?! )[\w\p{L}\p{M}\p{N} .~!$&'()*+,;=:@-]+(?<! )$/u;
|
|
45
|
+
export const isSegment = (s) => SEGMENT.test(s) && s !== '.' && s !== '..';
|
|
20
46
|
/**
|
|
21
47
|
* A path's segments as a file server might read them, or null when the path
|
|
22
|
-
* could mean more than one file: it does not decode,
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
* guess how
|
|
48
|
+
* could mean more than one file: it does not decode, or a segment, decoded, is
|
|
49
|
+
* not `isSegment` (a `%` left after decoding, `%255F`, a backslash, a control
|
|
50
|
+
* character, `.`, `..`, or empty other than the last). The gate sends those
|
|
51
|
+
* nowhere, for anyone, rather than guess how a server resolves them. An
|
|
52
|
+
* encoded space or letter decodes and passes.
|
|
26
53
|
*/
|
|
27
54
|
function segments(pathname) {
|
|
28
55
|
let decoded;
|
|
@@ -32,40 +59,92 @@ function segments(pathname) {
|
|
|
32
59
|
catch {
|
|
33
60
|
return null;
|
|
34
61
|
}
|
|
35
|
-
if (/[%\\]/.test(decoded))
|
|
36
|
-
return null;
|
|
37
62
|
const parts = decoded.split('/').slice(1);
|
|
38
63
|
if (parts.at(-1) === '')
|
|
39
64
|
parts.pop();
|
|
40
|
-
return parts.
|
|
65
|
+
return parts.every(isSegment) ? parts : null;
|
|
41
66
|
}
|
|
42
67
|
/**
|
|
43
68
|
* The first path segments that are the hub's own, for anyone signed in: the
|
|
44
|
-
*
|
|
45
|
-
* the top (shell/index.html,
|
|
69
|
+
* walkthroughs, the review API, the shared bundle, the gate's font folder,
|
|
70
|
+
* and the files the hub serves at the top (shell/index.html,
|
|
71
|
+
* shell/public/favicon.svg). `invite` and `_p` are reserved too but are not
|
|
72
|
+
* the hub's: the gate answers a link itself, and `_p` is a prototype's.
|
|
46
73
|
*/
|
|
47
|
-
const HUB_ROOT = [
|
|
74
|
+
const HUB_ROOT = ['guide', 'api', 'assets', '_gate', 'index.html', 'favicon.svg'];
|
|
48
75
|
/**
|
|
49
|
-
* Which prototype a
|
|
50
|
-
*
|
|
51
|
-
* HUB_ROOT). The first segment
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
*
|
|
56
|
-
* belongs to `''` too.
|
|
76
|
+
* Which prototype a project's file belongs to, for the gate, from the path's
|
|
77
|
+
* segments below the project: null for a hub path (none, or a first segment
|
|
78
|
+
* in HUB_ROOT). The first segment must be one of those, `_p`, or a prototype
|
|
79
|
+
* slug; anything else (`_P`, `_p;x`, `_p.`, a full-width `_p`) belongs to
|
|
80
|
+
* `''`, refused like an internal prototype. A path under `_p/` always
|
|
81
|
+
* belongs to one, so its name may be no slug at all (`all.js`), which no
|
|
82
|
+
* audience makes client-facing.
|
|
57
83
|
*/
|
|
58
|
-
|
|
59
|
-
const parts = segments(pathname);
|
|
60
|
-
if (!parts)
|
|
61
|
-
return '';
|
|
62
|
-
const [first, second] = parts;
|
|
84
|
+
function prototypeOfParts([first, second]) {
|
|
63
85
|
if (first === undefined || HUB_ROOT.includes(first))
|
|
64
86
|
return null;
|
|
65
87
|
if (first === PROTOTYPE_DIR)
|
|
66
88
|
return second ?? '';
|
|
67
89
|
return isPrototypeSlug(first) ? first : '';
|
|
68
90
|
}
|
|
91
|
+
/** The one-time link path, matched on the path as sent, as the gate always has. */
|
|
92
|
+
export const LINK_PATH = /^\/invite\/([\w-]{20,100})\/?$/;
|
|
93
|
+
/** What the gate pages load before sign-in, at the host root: the hub's face and the favicon. */
|
|
94
|
+
export const GATE_FONT = '/_gate/geist.woff2';
|
|
95
|
+
const GATE_ASSETS = [GATE_FONT, '/favicon.svg'];
|
|
96
|
+
/**
|
|
97
|
+
* The host proof `client add` asks a new client's host for: the studio gate
|
|
98
|
+
* answers a GET of it with the proof's answer only when the store holds that
|
|
99
|
+
* ask for the host's client. Otherwise it is a hub path like any other.
|
|
100
|
+
*/
|
|
101
|
+
export const PROOF_PATH = /^\/_gate\/proof\/([\w-]{20,100})$/;
|
|
102
|
+
export const proofPath = (ask) => `/_gate/proof/${ask}`;
|
|
103
|
+
/**
|
|
104
|
+
* The studio site's functions, at a client host's root: the review API, and
|
|
105
|
+
* the files function the gate rewrites a project's files to. The gate passes
|
|
106
|
+
* them to anyone signed in; each checks the request again itself.
|
|
107
|
+
*/
|
|
108
|
+
const FUNCTIONS = ['review', 'files'];
|
|
109
|
+
/** A host name as a lookup key: lower case, no port, no trailing dot; '' for anything that is not one. */
|
|
110
|
+
export function hostName(host) {
|
|
111
|
+
const name = host.trim().toLowerCase().replace(/:\d+$/, '').replace(/\.$/, '');
|
|
112
|
+
return name.length <= 253 && /^[a-z0-9-]+(\.[a-z0-9-]+)+$/.test(name) ? name : '';
|
|
113
|
+
}
|
|
114
|
+
const ROOT_HUB = ['assets', '_gate', 'index.html'];
|
|
115
|
+
/** Below a project: its review API, or one of its build's files. */
|
|
116
|
+
function projectRoute(project, rest) {
|
|
117
|
+
if (rest[0] !== 'api')
|
|
118
|
+
return { kind: 'file', project, file: rest, prototype: prototypeOfParts(rest) };
|
|
119
|
+
return rest.length === 2 && rest[1] === 'review' ? { kind: 'api', project } : { kind: 'none' };
|
|
120
|
+
}
|
|
121
|
+
function where(pathname) {
|
|
122
|
+
const linked = pathname.match(LINK_PATH);
|
|
123
|
+
if (linked)
|
|
124
|
+
return { kind: 'link', token: linked[1] };
|
|
125
|
+
if (GATE_ASSETS.includes(pathname))
|
|
126
|
+
return { kind: 'asset' };
|
|
127
|
+
const parts = segments(pathname);
|
|
128
|
+
if (!parts)
|
|
129
|
+
return { kind: 'none' };
|
|
130
|
+
const [first, ...rest] = parts;
|
|
131
|
+
if (first === undefined || ROOT_HUB.includes(first))
|
|
132
|
+
return { kind: 'hub' };
|
|
133
|
+
if (first === 'api')
|
|
134
|
+
return rest.length === 1 && FUNCTIONS.includes(rest[0])
|
|
135
|
+
? { kind: 'api', project: null }
|
|
136
|
+
: { kind: 'none' };
|
|
137
|
+
return isProjectSlug(first) ? projectRoute(first, rest) : { kind: 'none' };
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* The one place a studio site reads a request's path. It fails closed: a
|
|
141
|
+
* 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
|
|
142
|
+
* codename): this names the host, never the client.
|
|
143
|
+
*/
|
|
144
|
+
export function routeOf(host, pathname) {
|
|
145
|
+
const name = hostName(host);
|
|
146
|
+
return { host: name, ...(name ? where(pathname) : { kind: 'none' }) };
|
|
147
|
+
}
|
|
69
148
|
/**
|
|
70
149
|
* Whether a built prototype's entry is there for this person, asked with a
|
|
71
150
|
* HEAD before it is imported. Not there: a 404 (the gate's answer for a
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type ControlKind } from '../controls.ts';
|
|
1
2
|
/** Which side a person is on: the studio that makes the work, or the client it is for. */
|
|
2
3
|
export declare const PERSON_KINDS: readonly ['studio', 'client'];
|
|
3
4
|
export type PersonKind = (typeof PERSON_KINDS)[number];
|
|
@@ -20,6 +21,11 @@ export declare const ACCESS: readonly ['3m', '6m', 'open'];
|
|
|
20
21
|
export type Access = (typeof ACCESS)[number];
|
|
21
22
|
/** The project default when none is set. */
|
|
22
23
|
export declare const DEFAULT_ACCESS: Access;
|
|
24
|
+
/**
|
|
25
|
+
* How long a studio site's instance keeps a host's answer (server/hosts.ts):
|
|
26
|
+
* archiving a client, or adding one, takes effect on every instance within it.
|
|
27
|
+
*/
|
|
28
|
+
export declare const HOST_SECONDS = 60;
|
|
23
29
|
/** When access given at `from` ends, as an ISO time, or null for open-ended. */
|
|
24
30
|
export declare function accessEnd(access: Access, from: Date): string | null;
|
|
25
31
|
export declare const LIMITS: {
|
|
@@ -38,6 +44,11 @@ export type Person = {
|
|
|
38
44
|
/** The group a person belongs to, shown beside their name: the studio, or the client's company. */
|
|
39
45
|
team: string;
|
|
40
46
|
kind: PersonKind;
|
|
47
|
+
/**
|
|
48
|
+
* The client a Client belongs to, or null for Studio, who works in every
|
|
49
|
+
* client. Never stored in the profile: it is where the person's records live.
|
|
50
|
+
*/
|
|
51
|
+
client: string | null;
|
|
41
52
|
/** Always null until email sign-in exists. */
|
|
42
53
|
email: string | null;
|
|
43
54
|
/** When their access ends (ISO time), or null for open-ended. Their sessions end with it. */
|
|
@@ -47,6 +58,58 @@ export type Person = {
|
|
|
47
58
|
/** Bumped on revoke and on sign out everywhere, which ends every session signed with the old one. */
|
|
48
59
|
epoch: number;
|
|
49
60
|
};
|
|
61
|
+
/**
|
|
62
|
+
* Where an op runs: one client, and one of its projects for anything about
|
|
63
|
+
* prototypes and comments. Every service method takes one, every store key is
|
|
64
|
+
* built from one (store.ts), and a Client acts only inside their own client.
|
|
65
|
+
*/
|
|
66
|
+
export type Scope = {
|
|
67
|
+
client: string;
|
|
68
|
+
project?: string;
|
|
69
|
+
};
|
|
70
|
+
/**
|
|
71
|
+
* The one client of this machine's own store, which `design-hub dev` and
|
|
72
|
+
* `--local` commands use (LOCAL_SCOPE in server/local.ts). It has no record
|
|
73
|
+
* and is never added or archived, so ops in it need none (`allow` in
|
|
74
|
+
* service.ts), and no studio may add a client by this name.
|
|
75
|
+
*/
|
|
76
|
+
export declare const LOCAL_CLIENT = "site";
|
|
77
|
+
/** A slug a studio's client can have: a client slug, and never the local store's. */
|
|
78
|
+
export declare const isStudioClient: (slug: unknown) => slug is string;
|
|
79
|
+
/** What a slug that cannot be a studio's client is told. */
|
|
80
|
+
export declare const STUDIO_CLIENT_SLUG = "slug: kebab-case, and not studio, www, api or site";
|
|
81
|
+
/**
|
|
82
|
+
* A client of the studio: one host (`<client>.<apex>`, or a codename below
|
|
83
|
+
* the apex), every project of it, its Client people. An archived client's
|
|
84
|
+
* host is the plain 404. `access` is its default access length, unused until
|
|
85
|
+
* clients set one. `provenAt` is when its host proved it is this studio's
|
|
86
|
+
* site (endProof in service.ts); until then the client is still being added
|
|
87
|
+
* (isAdded).
|
|
88
|
+
*/
|
|
89
|
+
export type Client = {
|
|
90
|
+
slug: string;
|
|
91
|
+
host: string;
|
|
92
|
+
name: string;
|
|
93
|
+
access: Access | null;
|
|
94
|
+
createdAt: string;
|
|
95
|
+
archivedAt: string | null;
|
|
96
|
+
provenAt: string | null;
|
|
97
|
+
};
|
|
98
|
+
/**
|
|
99
|
+
* Whether a client has finished being added: its host has proved it is this
|
|
100
|
+
* studio's site. A record with no such mark is still being added, whatever
|
|
101
|
+
* became of its proof, so nothing of a project and no sign-in link goes to
|
|
102
|
+
* its host, and `client add` with the same flags finishes it.
|
|
103
|
+
*/
|
|
104
|
+
export declare const isAdded: (client: Client) => boolean;
|
|
105
|
+
/** A project of one client, served at `/<slug>/` on its host from the build `build` points at, or not at all while it is null. */
|
|
106
|
+
export type Project = {
|
|
107
|
+
slug: string;
|
|
108
|
+
client: string;
|
|
109
|
+
name: string;
|
|
110
|
+
build: string | null;
|
|
111
|
+
createdAt: string;
|
|
112
|
+
};
|
|
50
113
|
/** A one-time sign-in link, stored under the hash of its token and deleted when used. */
|
|
51
114
|
export type Link = {
|
|
52
115
|
person: string;
|
|
@@ -116,8 +179,10 @@ export declare const threadLabel: (c: Pick<Comment, 'audience' | 'number'>) => s
|
|
|
116
179
|
* Client anything. A missing or broken number reads as 0, no number.
|
|
117
180
|
*/
|
|
118
181
|
export declare function readComment(json: string): Comment;
|
|
119
|
-
/**
|
|
120
|
-
export
|
|
182
|
+
/** What a person's profile record holds: everything but revocation, epoch and client, which live elsewhere. */
|
|
183
|
+
export type Profile = Omit<Person, 'revokedAt' | 'epoch' | 'client'>;
|
|
184
|
+
/** Whether a stored profile is well formed. */
|
|
185
|
+
export declare function isProfile(v: unknown): v is Profile;
|
|
121
186
|
/**
|
|
122
187
|
* Whether someone may sign in at `at`: not revoked, and an access end that is
|
|
123
188
|
* open (null) or a parseable time still ahead. An access end that does not
|
|
@@ -138,10 +203,30 @@ export type PersonInput = Pick<Person, 'name' | 'team' | 'kind'> & {
|
|
|
138
203
|
access: Access | null;
|
|
139
204
|
};
|
|
140
205
|
export declare function checkPersonInput(input: unknown): Checked<PersonInput>;
|
|
206
|
+
export type ClientInput = Pick<Client, 'slug' | 'host' | 'name'>;
|
|
207
|
+
/** A new client: a client slug, the host name it is served on (lower case), and its name. */
|
|
208
|
+
export declare function checkClientInput(input: unknown): Checked<ClientInput>;
|
|
209
|
+
export type ProjectInput = Pick<Project, 'slug' | 'name'>;
|
|
210
|
+
/** A new project: a project slug (never a path the gate answers itself) and its name. */
|
|
211
|
+
export declare function checkProjectInput(input: unknown): Checked<ProjectInput>;
|
|
212
|
+
/** A stored client, or null for anything that is not a well-formed one. */
|
|
213
|
+
export declare function readClient(json: string | null): Client | null;
|
|
214
|
+
/** A stored project, or null for anything that is not a well-formed one. */
|
|
215
|
+
export declare function readProject(json: string | null): Project | null;
|
|
141
216
|
/** A new thread's audience as asked: one of AUDIENCES, or null when none is given. */
|
|
142
217
|
export declare function checkAudience(input: unknown): Checked<Audience | null>;
|
|
143
218
|
/** A prototype's audience as Studio sets it: one of AUDIENCES, required. */
|
|
144
219
|
export declare function checkPrototypeAudience(input: unknown): Checked<Audience>;
|
|
220
|
+
/** One control's mark as Studio sets it: which kind, its id, and who it is for. */
|
|
221
|
+
export declare function checkControl(input: {
|
|
222
|
+
kind: unknown;
|
|
223
|
+
id: unknown;
|
|
224
|
+
audience: unknown;
|
|
225
|
+
}): Checked<{
|
|
226
|
+
kind: ControlKind;
|
|
227
|
+
id: string;
|
|
228
|
+
audience: Audience;
|
|
229
|
+
}>;
|
|
145
230
|
/** Whose view of the comments is asked for: a person kind, or null for the caller's own. */
|
|
146
231
|
export declare function checkViewAs(input: unknown): Checked<PersonKind | null>;
|
|
147
232
|
export declare function checkBody(body: unknown): Checked<string>;
|
|
@@ -3,7 +3,10 @@
|
|
|
3
3
|
// Pure: no I/O, no environment. Every limit and rule lives here once and is
|
|
4
4
|
// enforced by the service, whichever adapter (Vercel, Vite dev, the CLI)
|
|
5
5
|
// calls it.
|
|
6
|
+
import { CONTROL_KINDS, isControlId } from '../controls.js';
|
|
6
7
|
import { SLUG } from '../feature.js';
|
|
8
|
+
import { isBuildId } from '../files.js';
|
|
9
|
+
import { hostName, isClientSlug, isProjectSlug } from '../prototype.js';
|
|
7
10
|
/** Which side a person is on: the studio that makes the work, or the client it is for. */
|
|
8
11
|
export const PERSON_KINDS = ['studio', 'client'];
|
|
9
12
|
/**
|
|
@@ -22,6 +25,11 @@ export const LINK_DAYS = 14;
|
|
|
22
25
|
export const ACCESS = ['3m', '6m', 'open'];
|
|
23
26
|
/** The project default when none is set. */
|
|
24
27
|
export const DEFAULT_ACCESS = '3m';
|
|
28
|
+
/**
|
|
29
|
+
* How long a studio site's instance keeps a host's answer (server/hosts.ts):
|
|
30
|
+
* archiving a client, or adding one, takes effect on every instance within it.
|
|
31
|
+
*/
|
|
32
|
+
export const HOST_SECONDS = 60;
|
|
25
33
|
const ACCESS_MONTHS = { '3m': 3, '6m': 6 };
|
|
26
34
|
/** When access given at `from` ends, as an ISO time, or null for open-ended. */
|
|
27
35
|
export function accessEnd(access, from) {
|
|
@@ -46,6 +54,24 @@ export const LIMITS = {
|
|
|
46
54
|
states: 50,
|
|
47
55
|
stateName: 120,
|
|
48
56
|
};
|
|
57
|
+
/**
|
|
58
|
+
* The one client of this machine's own store, which `design-hub dev` and
|
|
59
|
+
* `--local` commands use (LOCAL_SCOPE in server/local.ts). It has no record
|
|
60
|
+
* and is never added or archived, so ops in it need none (`allow` in
|
|
61
|
+
* service.ts), and no studio may add a client by this name.
|
|
62
|
+
*/
|
|
63
|
+
export const LOCAL_CLIENT = 'site';
|
|
64
|
+
/** A slug a studio's client can have: a client slug, and never the local store's. */
|
|
65
|
+
export const isStudioClient = (slug) => isClientSlug(slug) && slug !== LOCAL_CLIENT;
|
|
66
|
+
/** What a slug that cannot be a studio's client is told. */
|
|
67
|
+
export const STUDIO_CLIENT_SLUG = 'slug: kebab-case, and not studio, www, api or site';
|
|
68
|
+
/**
|
|
69
|
+
* Whether a client has finished being added: its host has proved it is this
|
|
70
|
+
* studio's site. A record with no such mark is still being added, whatever
|
|
71
|
+
* became of its proof, so nothing of a project and no sign-in link goes to
|
|
72
|
+
* its host, and `client add` with the same flags finishes it.
|
|
73
|
+
*/
|
|
74
|
+
export const isAdded = (client) => client.provenAt !== null;
|
|
49
75
|
/**
|
|
50
76
|
* How a thread is named in words, for a screen reader and an agent: `I2` for internal thread 2,
|
|
51
77
|
* `2` for client-facing thread 2, '' for a thread stored before numbers. The pin, the card
|
|
@@ -76,7 +102,7 @@ const PROFILE_RULES = [
|
|
|
76
102
|
['accessEndsAt', isTextOrNull],
|
|
77
103
|
['createdAt', isText],
|
|
78
104
|
];
|
|
79
|
-
/** Whether a stored profile
|
|
105
|
+
/** Whether a stored profile is well formed. */
|
|
80
106
|
export function isProfile(v) {
|
|
81
107
|
if (!v || typeof v !== 'object' || Array.isArray(v))
|
|
82
108
|
return false;
|
|
@@ -132,6 +158,56 @@ export function checkPersonInput(input) {
|
|
|
132
158
|
? { ok: false, problems }
|
|
133
159
|
: { ok: true, value: { name, team, kind: kind, access: access } };
|
|
134
160
|
}
|
|
161
|
+
/** A new client: a client slug, the host name it is served on (lower case), and its name. */
|
|
162
|
+
export function checkClientInput(input) {
|
|
163
|
+
const i = (input ?? {});
|
|
164
|
+
const problems = [];
|
|
165
|
+
const name = text(i.name, 'name', LIMITS.name, problems);
|
|
166
|
+
if (!isStudioClient(i.slug))
|
|
167
|
+
problems.push(STUDIO_CLIENT_SLUG);
|
|
168
|
+
const host = typeof i.host === 'string' ? hostName(i.host) : '';
|
|
169
|
+
if (!host || host !== i.host)
|
|
170
|
+
problems.push('host: a host name in lower case, such as acme.example.com');
|
|
171
|
+
return problems.length
|
|
172
|
+
? { ok: false, problems }
|
|
173
|
+
: { ok: true, value: { slug: i.slug, host, name } };
|
|
174
|
+
}
|
|
175
|
+
/** A new project: a project slug (never a path the gate answers itself) and its name. */
|
|
176
|
+
export function checkProjectInput(input) {
|
|
177
|
+
const i = (input ?? {});
|
|
178
|
+
const problems = [];
|
|
179
|
+
const name = text(i.name, 'name', LIMITS.name, problems);
|
|
180
|
+
if (!isProjectSlug(i.slug))
|
|
181
|
+
problems.push('slug: kebab-case, and not a path the hub answers itself');
|
|
182
|
+
return problems.length ? { ok: false, problems } : { ok: true, value: { slug: i.slug, name } };
|
|
183
|
+
}
|
|
184
|
+
const isRecord = (v) => !!v && typeof v === 'object' && !Array.isArray(v);
|
|
185
|
+
/** A stored client, or null for anything that is not a well-formed one. */
|
|
186
|
+
export function readClient(json) {
|
|
187
|
+
const c = safeJson(json);
|
|
188
|
+
if (!isRecord(c) || !isClientSlug(c.slug) || typeof c.host !== 'string' || !isText(c.name))
|
|
189
|
+
return null;
|
|
190
|
+
if (!isText(c.createdAt) || !isTextOrNull(c.archivedAt) || !isTextOrNull(c.provenAt))
|
|
191
|
+
return null;
|
|
192
|
+
return c;
|
|
193
|
+
}
|
|
194
|
+
/** A stored project, or null for anything that is not a well-formed one. */
|
|
195
|
+
export function readProject(json) {
|
|
196
|
+
const p = safeJson(json);
|
|
197
|
+
if (!isRecord(p) || !isProjectSlug(p.slug) || !isClientSlug(p.client) || !isText(p.name))
|
|
198
|
+
return null;
|
|
199
|
+
if (!isText(p.createdAt) || !(p.build === null || isBuildId(p.build)))
|
|
200
|
+
return null;
|
|
201
|
+
return p;
|
|
202
|
+
}
|
|
203
|
+
function safeJson(json) {
|
|
204
|
+
try {
|
|
205
|
+
return json === null ? null : JSON.parse(json);
|
|
206
|
+
}
|
|
207
|
+
catch {
|
|
208
|
+
return null;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
135
211
|
/** A new thread's audience as asked: one of AUDIENCES, or null when none is given. */
|
|
136
212
|
export function checkAudience(input) {
|
|
137
213
|
if (input === undefined || input === null)
|
|
@@ -146,6 +222,26 @@ export function checkPrototypeAudience(input) {
|
|
|
146
222
|
? { ok: true, value: input }
|
|
147
223
|
: { ok: false, problems: [`audience: one of ${AUDIENCES.join(', ')}`] };
|
|
148
224
|
}
|
|
225
|
+
/** One control's mark as Studio sets it: which kind, its id, and who it is for. */
|
|
226
|
+
export function checkControl(input) {
|
|
227
|
+
const problems = [];
|
|
228
|
+
if (!CONTROL_KINDS.includes(input.kind))
|
|
229
|
+
problems.push(`kind: one of ${CONTROL_KINDS.join(', ')}`);
|
|
230
|
+
if (!isControlId(input.id))
|
|
231
|
+
problems.push('id: the control’s name, one line of at most 200 characters');
|
|
232
|
+
if (!AUDIENCES.includes(input.audience))
|
|
233
|
+
problems.push(`audience: one of ${AUDIENCES.join(', ')}`);
|
|
234
|
+
return problems.length
|
|
235
|
+
? { ok: false, problems }
|
|
236
|
+
: {
|
|
237
|
+
ok: true,
|
|
238
|
+
value: {
|
|
239
|
+
kind: input.kind,
|
|
240
|
+
id: input.id,
|
|
241
|
+
audience: input.audience,
|
|
242
|
+
},
|
|
243
|
+
};
|
|
244
|
+
}
|
|
149
245
|
/** Whose view of the comments is asked for: a person kind, or null for the caller's own. */
|
|
150
246
|
export function checkViewAs(input) {
|
|
151
247
|
if (input === undefined || input === null)
|
|
@@ -1,13 +1,20 @@
|
|
|
1
|
-
import type { Audience, Comment, Person, PersonKind } from './model.ts';
|
|
2
|
-
export type Action = 'read' | 'comment' | 'edit' | 'delete' | 'resolve' | 'triage' | 'people' | 'audience';
|
|
1
|
+
import type { Audience, Comment, Person, PersonKind, Scope } from './model.ts';
|
|
2
|
+
export type Action = 'read' | 'comment' | 'edit' | 'delete' | 'resolve' | 'triage' | 'people' | 'audience' | 'setup';
|
|
3
3
|
/** Only what the rules read, so the browser's signed-in person (no epoch) is checked by the same rules. */
|
|
4
|
-
type Actor = Pick<Person, 'id' | 'kind' | 'revokedAt'>;
|
|
4
|
+
type Actor = Pick<Person, 'id' | 'kind' | 'revokedAt' | 'client'>;
|
|
5
|
+
/**
|
|
6
|
+
* Whether an op in `scope` is the actor's at all: Studio works in every
|
|
7
|
+
* client, a Client only in their own. A person whose kind and client
|
|
8
|
+
* disagree (Studio with a client, a Client with none) is in no scope, and
|
|
9
|
+
* so is every op on a scope that names no client: it fails closed here.
|
|
10
|
+
*/
|
|
11
|
+
export declare function inScope(actor: Pick<Person, 'kind' | 'client'>, scope: Scope): boolean;
|
|
5
12
|
/**
|
|
6
13
|
* `root` is the thread acted on, `subject` the comment in it when that is a
|
|
7
14
|
* reply (edit or delete one); without `subject`, the root is the subject.
|
|
8
15
|
* Without a root, the action is on no thread: listing, or a new thread.
|
|
9
16
|
*/
|
|
10
|
-
export declare function can(actor: Actor | null, action: Action, root?: Comment, subject?: Comment): boolean;
|
|
17
|
+
export declare function can(actor: Actor | null, scope: Scope, action: Action, root?: Comment, subject?: Comment): boolean;
|
|
11
18
|
/**
|
|
12
19
|
* The view a person gets: their own kind, or a narrower one they ask for.
|
|
13
20
|
* Studio may look as a Client does (Client view); a Client asking for
|