@milesroxas/design-hub 0.11.1 → 0.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. package/README.md +4 -2
  2. package/core/prototype.test.ts +52 -0
  3. package/core/prototype.ts +59 -0
  4. package/core/review/model.ts +32 -3
  5. package/core/review/service.test.ts +240 -0
  6. package/core/review/service.ts +281 -50
  7. package/core/review/store.ts +10 -4
  8. package/dist/core/prototype.d.ts +50 -0
  9. package/dist/core/prototype.js +38 -0
  10. package/dist/core/review/model.d.ts +25 -1
  11. package/dist/core/review/model.js +18 -2
  12. package/dist/core/review/service.d.ts +98 -16
  13. package/dist/core/review/service.js +254 -45
  14. package/dist/core/review/store.d.ts +10 -4
  15. package/dist/scripts/client.d.ts +3 -3
  16. package/dist/scripts/client.js +52 -66
  17. package/dist/scripts/lib/dns.d.ts +32 -0
  18. package/dist/scripts/lib/dns.js +69 -1
  19. package/dist/scripts/lib/fake-host.d.ts +34 -9
  20. package/dist/scripts/lib/fake-host.js +7 -4
  21. package/dist/scripts/lib/review.d.ts +5 -2
  22. package/dist/scripts/lib/review.js +8 -2
  23. package/dist/scripts/lib/studios.d.ts +3 -1
  24. package/dist/scripts/lib/studios.js +2 -0
  25. package/dist/scripts/people.d.ts +8 -5
  26. package/dist/scripts/people.js +152 -41
  27. package/dist/scripts/share.js +1 -1
  28. package/dist/scripts/studio.d.ts +3 -3
  29. package/dist/scripts/studio.js +100 -10
  30. package/dist/server/api.d.ts +6 -8
  31. package/dist/server/api.js +129 -42
  32. package/dist/server/hosts.d.ts +3 -3
  33. package/dist/server/hosts.js +10 -10
  34. package/dist/server/session.d.ts +7 -0
  35. package/dist/server/session.js +8 -1
  36. package/dist/vercel/proxy.d.ts +7 -3
  37. package/dist/vercel/proxy.js +215 -49
  38. package/dist/vite/plugin.d.ts +6 -2
  39. package/dist/vite/plugin.js +21 -3
  40. package/package.json +1 -1
  41. package/shell/Index.tsx +29 -0
  42. package/shell/review/People.tsx +80 -61
  43. package/shell/review/Review.tsx +49 -1
  44. package/shell/review/ThreadCard.tsx +13 -1
  45. package/shell/review/client.ts +56 -22
  46. package/shell/review/review.css +1 -0
  47. package/shell/review/unsent.test.ts +63 -0
  48. package/shell/review/unsent.ts +64 -0
  49. package/shell/review/view.ts +22 -6
  50. package/shell/studio/ClientHub.tsx +9 -36
  51. package/shell/studio/StudioHub.tsx +293 -0
  52. package/shell/studio/hub.css +80 -5
  53. package/shell/studio/page.tsx +57 -0
  54. package/shell/studio/studio.html +14 -0
  55. package/shell/studio/studio.tsx +19 -0
  56. package/skills/miles-deploy/SKILL.md +16 -6
  57. package/skills/miles-design-hub/SKILL.md +3 -3
  58. package/skills/miles-review/SKILL.md +1 -1
  59. package/templates/studio/README.md +32 -13
  60. package/templates/studio/package.json +1 -1
@@ -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 = {
@@ -199,7 +221,9 @@ export type Checked<T> = {
199
221
  problems: string[];
200
222
  };
201
223
  export declare function checkAccess(input: unknown): Checked<Access>;
202
- export type PersonInput = Pick<Person, 'name' | 'team' | 'kind'> & {
224
+ /** `team` absent: the service fills it, the studio's name for Studio and the client's for a Client. */
225
+ export type PersonInput = Pick<Person, 'name' | 'kind'> & {
226
+ team?: string;
203
227
  access: Access | null;
204
228
  };
205
229
  export declare function checkPersonInput(input: unknown): Checked<PersonInput>;
@@ -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) {
@@ -145,7 +153,7 @@ export function checkPersonInput(input) {
145
153
  const i = (input ?? {});
146
154
  const problems = [];
147
155
  const name = text(i.name, 'name', LIMITS.name, problems);
148
- const team = text(i.team, 'team', LIMITS.team, problems);
156
+ const team = i.team === undefined ? undefined : text(i.team, 'team', LIMITS.team, problems);
149
157
  // Most people added are on the client's side; Studio is the deliberate choice.
150
158
  const kind = i.kind ?? 'client';
151
159
  if (!PERSON_KINDS.includes(kind))
@@ -156,7 +164,15 @@ export function checkPersonInput(input) {
156
164
  problems.push(ACCESS_PROBLEM);
157
165
  return problems.length
158
166
  ? { ok: false, problems }
159
- : { ok: true, value: { name, team, kind: kind, access: access } };
167
+ : {
168
+ ok: true,
169
+ value: {
170
+ name,
171
+ ...(team === undefined ? {} : { team }),
172
+ kind: kind,
173
+ access: access,
174
+ },
175
+ };
160
176
  }
161
177
  /** A new client: a client slug, the host name it is served on (lower case), and its name. */
162
178
  export function checkClientInput(input) {
@@ -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,23 +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(scope: Scope, id: string, epoch: number): Promise<Person | null>;
164
- /** The scope's Clients and every Studio person. */
165
- listPeople(scope: Scope, actor: Person | null): Promise<Person[]>;
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. Without an access length, a Client gets the default and
169
- * Studio is open-ended.
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.
170
251
  */
171
- addPerson(scope: Scope, actor: Person | null, input: unknown): Promise<Issued>;
252
+ addPerson(at: HostScope, actor: Person | null, input: unknown): Promise<Issued>;
172
253
  /** Another one-time link, for another device. Their sessions and other unused links stay. */
173
- newLink(scope: Scope, actor: Person | null, id: string): Promise<Issued>;
254
+ newLink(scope: HostScope, actor: Person | null, id: string): Promise<Issued>;
174
255
  /** Ends every session they hold and every unused link, and gives one new link. */
175
- signOutEverywhere(scope: Scope, actor: Person | null, id: string): Promise<Issued>;
176
- revoke(scope: Scope, actor: Person | null, id: string): Promise<Person>;
256
+ signOutEverywhere(scope: HostScope, actor: Person | null, id: string): Promise<Issued>;
257
+ revoke(scope: HostScope, actor: Person | null, id: string): Promise<Person>;
177
258
  /** Sets one person's access length, counted from now. Their sessions follow at the gate's next check, within five minutes. */
178
- setAccess(scope: Scope, actor: Person | null, id: string, access: unknown): Promise<Person>;
259
+ setAccess(scope: HostScope, actor: Person | null, id: string, access: unknown): Promise<Person>;
179
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. */
180
261
  defaultAccess(scope: Scope, actor: Person | null): Promise<Access>;
181
262
  /**
@@ -187,21 +268,22 @@ export declare function createReview(kv: KV, overrides?: Partial<Deps>): {
187
268
  setDefaultAccess(scope: Scope, actor: Person | null, access: unknown): Promise<Access>;
188
269
  /** A new Studio person, who works in every client. No link: each comes from newStudioLink, for one host. Studio only. */
189
270
  addStudioPerson(actor: Person | null, input: unknown): Promise<Person>;
190
- /** 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. */
191
272
  newStudioLink(actor: Person | null, id: string): Promise<Issued>;
192
273
  /** The studio's default access length, what a client without its own gives. Studio only. */
193
274
  studioAccess(actor: Person | null): Promise<Access>;
194
275
  setStudioAccess(actor: Person | null, access: unknown): Promise<Access>;
195
276
  /** Who a link signs in here, without using it: mail and chat previews open links too. */
196
- peekLink(scope: Scope, token: string): Promise<Person | null>;
277
+ peekLink(at: HostScope, token: string): Promise<Person | null>;
197
278
  /**
198
279
  * Uses a link up and returns who it signs in. The delete is the claim: of
199
280
  * two requests with one token, only the one whose delete removed the link
200
281
  * gets a person, so a link signs in one device at most. Who it signs in is
201
282
  * read and checked first, so the delete is the last store call. Only a
202
- * 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.
203
285
  */
204
- useLink(scope: Scope, token: string): Promise<Person | null>;
286
+ useLink(at: HostScope, token: string): Promise<Person | null>;
205
287
  /**
206
288
  * A prototype's comments as the actor's view sees them. `viewAs: 'client'`
207
289
  * is Studio's Client view; it never widens a Client's.