@coffre/ui 0.3.0 → 0.4.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/dist/chunks/audit-sentence-BhHmvQX_.js +660 -0
- package/dist/chunks/audit-sentence-BhHmvQX_.js.map +1 -0
- package/dist/chunks/delete-place-CRX7ntE8.js +206 -0
- package/dist/chunks/delete-place-CRX7ntE8.js.map +1 -0
- package/dist/chunks/{directory-CSjWWUQ1.js → directory-zr3ek7Mc.js} +175 -60
- package/dist/chunks/directory-zr3ek7Mc.js.map +1 -0
- package/dist/chunks/folders-DoBmCwOi.js +207 -0
- package/dist/chunks/folders-DoBmCwOi.js.map +1 -0
- package/dist/chunks/grants-Cw1FyGID.js +669 -0
- package/dist/chunks/grants-Cw1FyGID.js.map +1 -0
- package/dist/chunks/offboarding-CE6d7um1.js +305 -0
- package/dist/chunks/offboarding-CE6d7um1.js.map +1 -0
- package/dist/chunks/one-time-DXEl9hbg.js +35 -0
- package/dist/chunks/one-time-DXEl9hbg.js.map +1 -0
- package/dist/chunks/page-DvsgZ2Hd.js +391 -0
- package/dist/chunks/page-DvsgZ2Hd.js.map +1 -0
- package/dist/chunks/principal-BIN-xwZw.js +42 -0
- package/dist/chunks/principal-BIN-xwZw.js.map +1 -0
- package/dist/chunks/{principal-page-D_91OA0l.js → principal-page-DhjO76GH.js} +245 -251
- package/dist/chunks/principal-page-DhjO76GH.js.map +1 -0
- package/dist/chunks/project-page-SRCtRe2g.js +17 -0
- package/dist/chunks/project-page-SRCtRe2g.js.map +1 -0
- package/dist/chunks/{queries-CQ81o4so.js → queries-DVR_i3rA.js} +132 -30
- package/dist/chunks/queries-DVR_i3rA.js.map +1 -0
- package/dist/chunks/references-B6pLT1uQ.js +343 -0
- package/dist/chunks/references-B6pLT1uQ.js.map +1 -0
- package/dist/chunks/{row-state-0PsrEzOL.js → row-state-DOPUsjQK.js} +3 -3
- package/dist/chunks/{row-state-0PsrEzOL.js.map → row-state-DOPUsjQK.js.map} +1 -1
- package/dist/chunks/signin-errors--ykMFuqN.js +57 -0
- package/dist/chunks/signin-errors--ykMFuqN.js.map +1 -0
- package/dist/chunks/tabs-BmwKfUeK.js +22 -0
- package/dist/chunks/tabs-BmwKfUeK.js.map +1 -0
- package/dist/chunks/{theme-B2vQolVR.js → theme-DJuz-xLM.js} +3 -3
- package/dist/chunks/{theme-B2vQolVR.js.map → theme-DJuz-xLM.js.map} +1 -1
- package/dist/chunks/{ui-DixXLQvQ.js → ui-DJje3gST.js} +6 -3
- package/dist/chunks/ui-DJje3gST.js.map +1 -0
- package/dist/chunks/{use-change-c6CeLRin.js → use-change-DUiGO19U.js} +52 -21
- package/dist/chunks/use-change-DUiGO19U.js.map +1 -0
- package/dist/chunks/{use-shell-jxd7Tzd-.js → use-shell-rNKfGjdj.js} +3 -3
- package/dist/chunks/{use-shell-jxd7Tzd-.js.map → use-shell-rNKfGjdj.js.map} +1 -1
- package/dist/chunks/validation-D312_NLf.js +87 -0
- package/dist/chunks/validation-D312_NLf.js.map +1 -0
- package/dist/index.d.ts +361 -27
- package/dist/index.js +188 -98
- package/dist/index.js.map +1 -1
- package/dist/pages/account.d.ts +2 -2
- package/dist/pages/account.js +297 -135
- package/dist/pages/account.js.map +1 -1
- package/dist/pages/approval.d.ts +9 -0
- package/dist/pages/approval.js +207 -0
- package/dist/pages/approval.js.map +1 -0
- package/dist/pages/audit.js +17 -542
- package/dist/pages/audit.js.map +1 -1
- package/dist/pages/device-login.js +2 -3
- package/dist/pages/device-login.js.map +1 -1
- package/dist/pages/environment.js +647 -257
- package/dist/pages/environment.js.map +1 -1
- package/dist/pages/login.js +18 -7
- package/dist/pages/login.js.map +1 -1
- package/dist/pages/oauth-authorize.d.ts +10 -0
- package/dist/pages/oauth-authorize.js +249 -0
- package/dist/pages/oauth-authorize.js.map +1 -0
- package/dist/pages/project-access.d.ts +6 -0
- package/dist/pages/project-access.js +370 -0
- package/dist/pages/project-access.js.map +1 -0
- package/dist/pages/project-environments.d.ts +4 -0
- package/dist/pages/project-environments.js +593 -0
- package/dist/pages/project-environments.js.map +1 -0
- package/dist/pages/project-settings.d.ts +4 -0
- package/dist/pages/project-settings.js +242 -0
- package/dist/pages/project-settings.js.map +1 -0
- package/dist/pages/project.d.ts +10 -2
- package/dist/pages/project.js +57 -934
- package/dist/pages/project.js.map +1 -1
- package/dist/pages/projects.js +53 -21
- package/dist/pages/projects.js.map +1 -1
- package/dist/pages/service-account.d.ts +10 -0
- package/dist/pages/{token.js → service-account.js} +112 -54
- package/dist/pages/service-account.js.map +1 -0
- package/dist/pages/service-accounts.d.ts +3 -0
- package/dist/pages/service-accounts.js +38 -0
- package/dist/pages/service-accounts.js.map +1 -0
- package/dist/pages/settings.d.ts +1 -0
- package/dist/pages/settings.js +104 -42
- package/dist/pages/settings.js.map +1 -1
- package/dist/pages/unregistered.js +2 -3
- package/dist/pages/unregistered.js.map +1 -1
- package/dist/pages/user.d.ts +6 -1
- package/dist/pages/user.js +18 -6
- package/dist/pages/user.js.map +1 -1
- package/dist/pages/users.js +6 -10
- package/dist/pages/users.js.map +1 -1
- package/package.json +3 -3
- package/src/components/actions-log.tsx +117 -0
- package/src/components/audit-sentence.tsx +55 -0
- package/src/components/command-palette.tsx +4 -4
- package/src/components/delete-place.tsx +180 -0
- package/src/components/directory.tsx +259 -110
- package/src/components/every-project.tsx +287 -0
- package/src/components/expiry-field.tsx +42 -0
- package/src/components/folders.tsx +219 -0
- package/src/components/grants.tsx +11 -4
- package/src/components/icons.tsx +2 -0
- package/src/components/missing.tsx +110 -0
- package/src/components/offboarding.tsx +61 -33
- package/src/components/page.tsx +4 -1
- package/src/components/principal-page.tsx +136 -106
- package/src/components/principal-picker.tsx +5 -5
- package/src/components/principal.tsx +4 -4
- package/src/components/references.tsx +323 -0
- package/src/components/service-tokens.tsx +112 -93
- package/src/components/shell.tsx +11 -32
- package/src/components/tabs.tsx +18 -0
- package/src/components/trusted-workloads.tsx +97 -79
- package/src/components/ui.tsx +8 -1
- package/src/index.ts +13 -2
- package/src/layout.tsx +2 -2
- package/src/lib/access-plan.ts +2 -2
- package/src/lib/audit-sentences.ts +161 -77
- package/src/lib/changes.ts +56 -5
- package/src/lib/coffre.ts +3 -2
- package/src/lib/one-time.ts +32 -0
- package/src/lib/project-access.ts +11 -23
- package/src/lib/project-page.ts +14 -0
- package/src/lib/queries.ts +126 -32
- package/src/lib/search.ts +25 -0
- package/src/lib/signin-errors.ts +45 -1
- package/src/lib/validation.ts +14 -0
- package/src/options.ts +187 -35
- package/src/pages/account.tsx +274 -129
- package/src/pages/approval.tsx +197 -0
- package/src/pages/audit.tsx +9 -61
- package/src/pages/environment.tsx +585 -286
- package/src/pages/login.tsx +8 -2
- package/src/pages/oauth-authorize.tsx +233 -0
- package/src/pages/project-access.tsx +219 -0
- package/src/pages/project-environments.tsx +582 -0
- package/src/pages/project-settings.tsx +259 -0
- package/src/pages/project.tsx +52 -879
- package/src/pages/projects.tsx +55 -18
- package/src/pages/service-account.tsx +50 -0
- package/src/pages/{tokens.tsx → service-accounts.tsx} +9 -6
- package/src/pages/settings.tsx +62 -8
- package/src/pages/user.tsx +16 -4
- package/src/pages/users.tsx +2 -2
- package/src/parity.ts +160 -0
- package/src/register.ts +58 -9
- package/src/router.tsx +4 -0
- package/src/shared/models.ts +6 -2
- package/src/styles/globals.css +536 -31
- package/dist/chunks/directory-CSjWWUQ1.js.map +0 -1
- package/dist/chunks/grants-saMQagmG.js +0 -160
- package/dist/chunks/grants-saMQagmG.js.map +0 -1
- package/dist/chunks/icons-D-PfAfnH.js +0 -203
- package/dist/chunks/icons-D-PfAfnH.js.map +0 -1
- package/dist/chunks/offboarding-C6l30DZR.js +0 -263
- package/dist/chunks/offboarding-C6l30DZR.js.map +0 -1
- package/dist/chunks/page-C5HcNqf2.js +0 -190
- package/dist/chunks/page-C5HcNqf2.js.map +0 -1
- package/dist/chunks/principal-page-D_91OA0l.js.map +0 -1
- package/dist/chunks/queries-CQ81o4so.js.map +0 -1
- package/dist/chunks/signin-errors-BEFlVDbQ.js +0 -30
- package/dist/chunks/signin-errors-BEFlVDbQ.js.map +0 -1
- package/dist/chunks/ui-DixXLQvQ.js.map +0 -1
- package/dist/chunks/use-action-CWsg_YWU.js +0 -49
- package/dist/chunks/use-action-CWsg_YWU.js.map +0 -1
- package/dist/chunks/use-change-c6CeLRin.js.map +0 -1
- package/dist/chunks/validation-BQtqPe2V.js +0 -29
- package/dist/chunks/validation-BQtqPe2V.js.map +0 -1
- package/dist/pages/token.d.ts +0 -3
- package/dist/pages/token.js.map +0 -1
- package/dist/pages/tokens.d.ts +0 -3
- package/dist/pages/tokens.js +0 -39
- package/dist/pages/tokens.js.map +0 -1
- package/dist/project-BqIy8gYR.d.ts +0 -5
- package/src/lib/instance.ts +0 -13
- package/src/pages/token.tsx +0 -34
package/src/lib/queries.ts
CHANGED
|
@@ -47,13 +47,17 @@ export const keys = {
|
|
|
47
47
|
projects: ['projects'],
|
|
48
48
|
grants: (project: string) => ['grants', project],
|
|
49
49
|
secrets: ({ project, environment }: Place) => ['secrets', project, environment],
|
|
50
|
+
references: (path: string) => ['references', path],
|
|
51
|
+
missing: ({ project, environment }: Place) => ['missing', project, environment],
|
|
50
52
|
directory: ['directory'],
|
|
51
53
|
report: (member: string) => ['report', member],
|
|
52
54
|
credentials: (member: string) => ['credentials', member],
|
|
53
55
|
bindings: (member: string) => ['bindings', member],
|
|
54
56
|
identities: ['identities'],
|
|
55
57
|
sessions: ['sessions'],
|
|
58
|
+
apps: ['apps'],
|
|
56
59
|
audit: ['audit'],
|
|
60
|
+
auditKeys: ['audit', 'keys'],
|
|
57
61
|
} satisfies Record<string, QueryKey | ((...args: never[]) => QueryKey)>;
|
|
58
62
|
|
|
59
63
|
/** One member's grants, as rows. */
|
|
@@ -66,7 +70,7 @@ function grantRows(members: Member[]): GrantRow[] {
|
|
|
66
70
|
role: grant.role,
|
|
67
71
|
roleName: grant.roleName,
|
|
68
72
|
permissions: grant.permissions,
|
|
69
|
-
scope: grant.environment === null ? ('project' as const) : ('environment' as const),
|
|
73
|
+
scope: grant.project === '*' ? ('every-project' as const) : grant.environment === null ? ('project' as const) : ('environment' as const),
|
|
70
74
|
environmentSlug: grant.environment,
|
|
71
75
|
expiresAt: grant.expiresAt,
|
|
72
76
|
})),
|
|
@@ -77,12 +81,13 @@ function listDirectory(client: CoffreClient) {
|
|
|
77
81
|
return uiResult(async () => {
|
|
78
82
|
const { members, removed } = await client.members.list();
|
|
79
83
|
const principals: DirectoryPrincipal[] = members.map(
|
|
80
|
-
({ principalType, principalId, instanceRole, isRootAdmin, tampered }) => ({
|
|
84
|
+
({ principalType, principalId, instanceRole, isRootAdmin, tampered, grants }) => ({
|
|
81
85
|
principalType,
|
|
82
86
|
principalId,
|
|
83
87
|
instanceRole,
|
|
84
88
|
isRootAdmin,
|
|
85
89
|
tampered,
|
|
90
|
+
grants: grants.map(({ project, environment }) => ({ project, environment })),
|
|
86
91
|
}),
|
|
87
92
|
);
|
|
88
93
|
return { principals, removed };
|
|
@@ -133,6 +138,20 @@ export const queries = {
|
|
|
133
138
|
queryFn: () => uiResult(() => client.secrets.list(`${place.project}/${place.environment}`)),
|
|
134
139
|
}),
|
|
135
140
|
|
|
141
|
+
/** What an environment lacks of its siblings' keys, those you read, and what its team dismissed. */
|
|
142
|
+
missing: (client: CoffreClient, place: Place) =>
|
|
143
|
+
queryOptions({
|
|
144
|
+
queryKey: keys.missing(place),
|
|
145
|
+
queryFn: () => uiResult(() => client.environments.missing(`${place.project}/${place.environment}`)),
|
|
146
|
+
}),
|
|
147
|
+
|
|
148
|
+
/** The live references into and out of a place, and who reads through them, for whoever manages its access. */
|
|
149
|
+
references: (client: CoffreClient, path: string) =>
|
|
150
|
+
queryOptions({
|
|
151
|
+
queryKey: keys.references(path),
|
|
152
|
+
queryFn: () => uiResult(() => client.references.list(path)),
|
|
153
|
+
}),
|
|
154
|
+
|
|
136
155
|
/**
|
|
137
156
|
* Everyone in the directory, and who was removed. The API shows grant
|
|
138
157
|
* managers the members of their projects; the directory pages stay the
|
|
@@ -182,8 +201,8 @@ export const queries = {
|
|
|
182
201
|
|
|
183
202
|
/**
|
|
184
203
|
* A token's trust bindings: the CI runs that may sign in as it. Null for
|
|
185
|
-
* anyone but an owner
|
|
186
|
-
*
|
|
204
|
+
* anyone but an owner, and where the deployment trusts no workloads
|
|
205
|
+
* (`features.workloads`), so there is nothing to ask.
|
|
187
206
|
*/
|
|
188
207
|
bindings: (client: CoffreClient, member: string, allowed: boolean) =>
|
|
189
208
|
queryOptions({
|
|
@@ -198,6 +217,20 @@ export const queries = {
|
|
|
198
217
|
/** Where you are signed in, under coffre's own sign-in. */
|
|
199
218
|
sessions: (client: CoffreClient) =>
|
|
200
219
|
queryOptions({ queryKey: keys.sessions, queryFn: () => uiResult(() => client.sessions.list()) }),
|
|
220
|
+
/** The MCP clients I connected, where the deployment serves MCP (`features.mcp`). */
|
|
221
|
+
apps: (client: CoffreClient) =>
|
|
222
|
+
queryOptions({ queryKey: keys.apps, queryFn: () => uiResult(() => client.apps.list()) }),
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* What the keys an operator keeps are checked against: the vault's ID and
|
|
226
|
+
* the app key's fingerprint, no secret. Null for anyone but owners and root
|
|
227
|
+
* admins, who alone may ask.
|
|
228
|
+
*/
|
|
229
|
+
auditKeys: (client: CoffreClient, allowed: boolean) =>
|
|
230
|
+
queryOptions({
|
|
231
|
+
queryKey: [...keys.auditKeys, { allowed }],
|
|
232
|
+
queryFn: () => (allowed ? uiResult(() => client.audit.keys()) : Promise.resolve(null)),
|
|
233
|
+
}),
|
|
201
234
|
|
|
202
235
|
/** A page of the log, as filtered: always read fresh. */
|
|
203
236
|
auditEntries: (client: CoffreClient, search: AuditSearch) =>
|
|
@@ -223,6 +256,20 @@ export const queries = {
|
|
|
223
256
|
*/
|
|
224
257
|
auditChain: (client: CoffreClient) =>
|
|
225
258
|
queryOptions({ queryKey: [...keys.audit, 'chain'], staleTime: 0, queryFn: () => verifyChain(client) }),
|
|
259
|
+
/** What deleting `market` or `market/prod` would take, asked afresh each time it is shown. */
|
|
260
|
+
deletion: (client: CoffreClient, path: string) =>
|
|
261
|
+
queryOptions({
|
|
262
|
+
queryKey: ['deletion', path],
|
|
263
|
+
staleTime: 0,
|
|
264
|
+
gcTime: 0,
|
|
265
|
+
queryFn: () =>
|
|
266
|
+
uiResult(async () => {
|
|
267
|
+
const { deletion } = path.includes('/')
|
|
268
|
+
? await client.environments.previewDelete(path)
|
|
269
|
+
: await client.projects.previewDelete(path);
|
|
270
|
+
return { deletion };
|
|
271
|
+
}),
|
|
272
|
+
}),
|
|
226
273
|
};
|
|
227
274
|
|
|
228
275
|
/**
|
|
@@ -280,10 +327,10 @@ export function shellOf(
|
|
|
280
327
|
projects: listed,
|
|
281
328
|
capabilities: deriveUiCapabilities(member, listed),
|
|
282
329
|
registrationRequired: me !== null && !me.registered,
|
|
283
|
-
/** The deployment's version and migrations: told to owners and root admins only. */
|
|
284
|
-
instance: member?.instance ?? null,
|
|
285
330
|
/** A member the vault refuses: their record failed its integrity check. */
|
|
286
331
|
accessTampered: me?.tampered === true,
|
|
332
|
+
/** What the deployment's configuration turns on: MCP clients, and CI runs signing in by their ID tokens. */
|
|
333
|
+
features: member?.features ?? { mcp: false, workloads: false },
|
|
287
334
|
};
|
|
288
335
|
}
|
|
289
336
|
|
|
@@ -325,33 +372,73 @@ export async function loadDirectory(queryClient: QueryClient, client: CoffreClie
|
|
|
325
372
|
return queryClient.fetchQuery(queries.directory(client, shell.capabilities.canManageGrants));
|
|
326
373
|
}
|
|
327
374
|
|
|
375
|
+
/** The instance's settings: the directory's counts, and what its keys are checked against. */
|
|
376
|
+
export async function loadSettings(queryClient: QueryClient, client: CoffreClient) {
|
|
377
|
+
const shell = await loadShell(queryClient, client);
|
|
378
|
+
await Promise.all([
|
|
379
|
+
loadDirectory(queryClient, client),
|
|
380
|
+
queryClient.fetchQuery(queries.auditKeys(client, shell.capabilities.canManageGrants)),
|
|
381
|
+
]);
|
|
382
|
+
}
|
|
383
|
+
|
|
328
384
|
/**
|
|
329
|
-
*
|
|
330
|
-
*
|
|
331
|
-
*
|
|
332
|
-
*
|
|
333
|
-
* where you do not hold grant.manage are skipped rather than asked: the
|
|
334
|
-
* refusal would land in the audit log as a denial in your name.
|
|
385
|
+
* The service accounts page: the directory, and each account's bindings and
|
|
386
|
+
* tokens, read here as its own page reads them, so the list shows how each
|
|
387
|
+
* signs in from the first paint and the browser asks for nothing that may be
|
|
388
|
+
* refused (a deployment that trusts no workloads answers bindings with one).
|
|
335
389
|
*/
|
|
336
|
-
export async function
|
|
337
|
-
queryClient
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
)
|
|
390
|
+
export async function loadServiceDirectory(queryClient: QueryClient, client: CoffreClient) {
|
|
391
|
+
const shell = await loadShell(queryClient, client);
|
|
392
|
+
const directory = await loadDirectory(queryClient, client);
|
|
393
|
+
const allowed = shell.capabilities.canManageGrants && shell.auth.signin !== null;
|
|
394
|
+
const trusts = shell.capabilities.canManageGrants && shell.features.workloads;
|
|
395
|
+
if (!directory.ok || !allowed) return directory;
|
|
396
|
+
await Promise.all(
|
|
397
|
+
directory.principals
|
|
398
|
+
.filter((principal) => principal.principalType === 'service')
|
|
399
|
+
.flatMap((principal) => {
|
|
400
|
+
const member = memberRef('service', principal.principalId);
|
|
401
|
+
return [
|
|
402
|
+
queryClient.fetchQuery(queries.credentials(client, member, allowed)),
|
|
403
|
+
queryClient.fetchQuery(queries.bindings(client, member, trusts)),
|
|
404
|
+
];
|
|
405
|
+
}),
|
|
406
|
+
);
|
|
407
|
+
return directory;
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
/** Who a user or service account is to the instance, its pages' header: null to anyone but an owner. */
|
|
411
|
+
export async function loadMember(queryClient: QueryClient, client: CoffreClient, member: string) {
|
|
412
|
+
const shell = await loadShell(queryClient, client);
|
|
413
|
+
return queryClient.fetchQuery(queries.report(client, member, shell.capabilities.canManageGrants));
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
export type MemberReport = Awaited<ReturnType<typeof loadMember>>;
|
|
417
|
+
|
|
418
|
+
/**
|
|
419
|
+
* What a user's or service account's Access tab reads: the grants of every
|
|
420
|
+
* project where you manage access. There is no "grants of this member"
|
|
421
|
+
* call, so each project you manage is asked for its grants and the tab
|
|
422
|
+
* keeps this member's. Projects where you do not hold grant.manage are
|
|
423
|
+
* skipped rather than asked: the refusal would land in the audit log as a
|
|
424
|
+
* denial in your name.
|
|
425
|
+
*/
|
|
426
|
+
export async function loadAccess(queryClient: QueryClient, client: CoffreClient) {
|
|
342
427
|
const shell = await loadShell(queryClient, client);
|
|
343
|
-
|
|
428
|
+
await Promise.all(managedProjects(shell.projects).map((project) => queryClient.fetchQuery(queries.grants(client, project.slug))));
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
/**
|
|
432
|
+
* How a service account's page lets it sign in: bearer tokens under
|
|
433
|
+
* coffre's own sign-in, trusted workloads where the deployment trusts them.
|
|
434
|
+
* Null where it shows neither: to anyone but an owner, and for an account
|
|
435
|
+
* that is not active, which can be issued nothing.
|
|
436
|
+
*/
|
|
437
|
+
export function signInWays(shell: Shell, report: MemberReport): { tokens: boolean; workloads: boolean } | null {
|
|
344
438
|
const owner = shell.capabilities.canManageGrants;
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
? queryClient.fetchQuery(queries.credentials(client, member, owner && shell.auth.signin !== null))
|
|
349
|
-
: null,
|
|
350
|
-
principalType === 'service'
|
|
351
|
-
? queryClient.fetchQuery(queries.bindings(client, member, owner && shell.auth.signin !== null))
|
|
352
|
-
: null,
|
|
353
|
-
...managedProjects(shell.projects).map((project) => queryClient.fetchQuery(queries.grants(client, project.slug))),
|
|
354
|
-
]);
|
|
439
|
+
const ways = { tokens: owner && shell.auth.signin !== null, workloads: owner && shell.features.workloads };
|
|
440
|
+
const active = report?.ok === true && report.report?.status === 'active';
|
|
441
|
+
return active && (ways.tokens || ways.workloads) ? ways : null;
|
|
355
442
|
}
|
|
356
443
|
|
|
357
444
|
export function managedProjects(projects: ProjectSummary[]): ProjectSummary[] {
|
|
@@ -366,7 +453,7 @@ export const affects = {
|
|
|
366
453
|
/** A project or environment made, renamed or archived: the tree, and where you hold access. */
|
|
367
454
|
places: (): QueryKey[] => [keys.projects, keys.me],
|
|
368
455
|
/** Secrets written, renamed, restored or archived: the environment and the counts. */
|
|
369
|
-
secrets: (place: Place): QueryKey[] => [keys.secrets(place), keys.projects],
|
|
456
|
+
secrets: (place: Place): QueryKey[] => [keys.secrets(place), keys.projects, ['references'], ['missing']],
|
|
370
457
|
/**
|
|
371
458
|
* Someone's access in a project changed: its grants, their report, and, as
|
|
372
459
|
* it may be your own, what you can see.
|
|
@@ -377,6 +464,12 @@ export const affects = {
|
|
|
377
464
|
keys.projects,
|
|
378
465
|
keys.me,
|
|
379
466
|
],
|
|
467
|
+
/**
|
|
468
|
+
* Someone's access on every project changed: every project's grants, which
|
|
469
|
+
* list it where it reaches, the list of them, their report, and what you
|
|
470
|
+
* can see, as it may be your own.
|
|
471
|
+
*/
|
|
472
|
+
everyProject: (member: string): QueryKey[] => [['grants'], keys.projects, keys.report(member), keys.me],
|
|
380
473
|
/** Someone let in: the directory. */
|
|
381
474
|
admission: (): QueryKey[] => [keys.directory],
|
|
382
475
|
/**
|
|
@@ -384,13 +477,14 @@ export const affects = {
|
|
|
384
477
|
* your own, what you can see and do.
|
|
385
478
|
*/
|
|
386
479
|
role: (member: string): QueryKey[] => [keys.directory, keys.report(member), keys.me, keys.projects],
|
|
387
|
-
/** Someone removed: the directory, their report, and every
|
|
388
|
-
removal: (member: string): QueryKey[] => [keys.directory, keys.report(member), ['grants']],
|
|
480
|
+
/** Someone removed: the directory, their report, and every grant, which removal ends, those on every project too. */
|
|
481
|
+
removal: (member: string): QueryKey[] => [keys.directory, keys.report(member), ['grants'], keys.projects],
|
|
389
482
|
credentials: (member: string): QueryKey[] => [keys.credentials(member)],
|
|
390
483
|
bindings: (member: string): QueryKey[] => [keys.bindings(member)],
|
|
391
484
|
/** Unlinking an account also ends the sessions it signed in. */
|
|
392
485
|
identities: (): QueryKey[] => [keys.identities, keys.sessions],
|
|
393
486
|
sessions: (): QueryKey[] => [keys.sessions],
|
|
487
|
+
apps: (): QueryKey[] => [keys.apps],
|
|
394
488
|
};
|
|
395
489
|
|
|
396
490
|
/**
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The router's search, every value a string as the URL has it. TanStack's
|
|
3
|
+
* default reads what looks like JSON or a number as such, so `state=1e5`
|
|
4
|
+
* would come back as `100000` and `code=0123` as `123`; the server's
|
|
5
|
+
* canonical redirect would then rewrite the URL. Here a page's
|
|
6
|
+
* `validateSearch` gets strings, and the URL comes back as it went.
|
|
7
|
+
*/
|
|
8
|
+
export function parseSearch(searchStr: string): Record<string, string> {
|
|
9
|
+
return Object.fromEntries(new URLSearchParams(searchStr));
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/** The inverse of `parseSearch`: each value that is set, as text. */
|
|
13
|
+
export function stringifySearch(search: Record<string, unknown>): string {
|
|
14
|
+
const query = new URLSearchParams();
|
|
15
|
+
for (const [name, value] of Object.entries(search)) {
|
|
16
|
+
if (value !== undefined) query.set(name, String(value));
|
|
17
|
+
}
|
|
18
|
+
const text = query.toString();
|
|
19
|
+
return text === '' ? '' : `?${text}`;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** The string values of a search, as a page that takes them as given reads them. */
|
|
23
|
+
export function stringsOf(search: Record<string, unknown>): Record<string, string> {
|
|
24
|
+
return Object.fromEntries(Object.entries(search).filter((entry): entry is [string, string] => typeof entry[1] === 'string'));
|
|
25
|
+
}
|
package/src/lib/signin-errors.ts
CHANGED
|
@@ -27,7 +27,51 @@ const MESSAGES: Record<string, string> = {
|
|
|
27
27
|
link_session: 'Your session changed while linking. Sign in again, then retry.',
|
|
28
28
|
};
|
|
29
29
|
|
|
30
|
-
|
|
30
|
+
/**
|
|
31
|
+
* Where an email already signs in, for `account_mismatch`: the providers by
|
|
32
|
+
* the label the sign-in page shows them under, and the one just tried. What
|
|
33
|
+
* the visitor may know: the provider has just verified the email is theirs.
|
|
34
|
+
*/
|
|
35
|
+
export type Already = { providers: readonly string[]; via?: string };
|
|
36
|
+
|
|
37
|
+
export function signinErrorMessage(code: string | undefined, already?: Already): string | null {
|
|
31
38
|
if (code === undefined) return null;
|
|
39
|
+
if (code === 'account_mismatch' && already !== undefined && already.providers.length > 0) return mismatch(already);
|
|
32
40
|
return MESSAGES[code] ?? 'The sign-in did not complete. Try again.';
|
|
33
41
|
}
|
|
42
|
+
|
|
43
|
+
/** "Your email already signs in with GitHub. Sign in with GitHub, then link this account from your account page." */
|
|
44
|
+
function mismatch({ providers, via }: Already): string {
|
|
45
|
+
const link = 'then link this account from your account page.';
|
|
46
|
+
// The same provider, another account of it: a second GitHub account, say.
|
|
47
|
+
if (providers.length === 1 && providers[0] === via) {
|
|
48
|
+
return `Your email already signs in with another ${via} account. Sign in with that one, ${link}`;
|
|
49
|
+
}
|
|
50
|
+
const named = providers.map((provider) => (provider === via ? `another ${provider} account` : provider));
|
|
51
|
+
const list = named.length < 3 ? named.join(' and ') : `${named.slice(0, -1).join(', ')} and ${named.at(-1)}`;
|
|
52
|
+
return named.length === 1
|
|
53
|
+
? `Your email already signs in with ${list}. Sign in with ${list}, ${link}`
|
|
54
|
+
: `Your email already signs in with ${list}. Sign in with one of them, ${link}`;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export type LoginSearch = { next?: string; error?: string; with?: string; via?: string };
|
|
58
|
+
|
|
59
|
+
/** A sign-in provider's id, as the instance configures it. */
|
|
60
|
+
const PROVIDER_ID = /^[a-z0-9_-]{1,40}$/;
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* `/login`'s search: where to resume after signing in, same-origin paths
|
|
64
|
+
* only, since an absolute URL accepted here would make the sign-in page an
|
|
65
|
+
* open redirect; and the sign-in's `error`, with account_mismatch's `with`
|
|
66
|
+
* and `via`, provider ids, shown once, then taken out of the URL.
|
|
67
|
+
*/
|
|
68
|
+
export function loginSearch(search: Record<string, unknown>): LoginSearch {
|
|
69
|
+
const out: LoginSearch = {};
|
|
70
|
+
const { next, error, via } = search;
|
|
71
|
+
if (typeof next === 'string' && next.startsWith('/') && !next.startsWith('//')) out.next = next;
|
|
72
|
+
if (typeof error === 'string' && /^[a-z_]{1,40}$/.test(error)) out.error = error;
|
|
73
|
+
const providers = typeof search.with === 'string' ? search.with.split(',').filter((id) => PROVIDER_ID.test(id)).slice(0, 8) : [];
|
|
74
|
+
if (providers.length > 0) out.with = providers.join(',');
|
|
75
|
+
if (typeof via === 'string' && PROVIDER_ID.test(via)) out.via = via;
|
|
76
|
+
return out;
|
|
77
|
+
}
|
package/src/lib/validation.ts
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
* bundle does not carry zod, and `test/validation.test.ts` holds the two in
|
|
8
8
|
* agreement.
|
|
9
9
|
*/
|
|
10
|
+
import { PROJECT_PAGES } from '@coffre/core/pages';
|
|
10
11
|
|
|
11
12
|
const SLUG = /^[a-z0-9][a-z0-9-]{0,62}$/;
|
|
12
13
|
const SECRET_KEY = /^[A-Za-z_][A-Za-z0-9_]{0,127}$/;
|
|
@@ -19,9 +20,22 @@ export function slugProblem(value: string): string | null {
|
|
|
19
20
|
return 'Lowercase letters, digits and dashes only.';
|
|
20
21
|
}
|
|
21
22
|
|
|
23
|
+
/** A slug, and not the name of a project's page, which sits where an environment's would. */
|
|
24
|
+
export function environmentSlugProblem(value: string): string | null {
|
|
25
|
+
if ((PROJECT_PAGES as readonly string[]).includes(value)) return 'Taken by a page of the project.';
|
|
26
|
+
return slugProblem(value);
|
|
27
|
+
}
|
|
28
|
+
|
|
22
29
|
export function secretKeyProblem(value: string): string | null {
|
|
23
30
|
if (SECRET_KEY.test(value)) return null;
|
|
24
31
|
if (value.length > 128) return 'At most 128 characters.';
|
|
25
32
|
if (/^[0-9]/.test(value)) return 'Cannot start with a digit.';
|
|
26
33
|
return 'Letters, digits and underscores only.';
|
|
27
34
|
}
|
|
35
|
+
|
|
36
|
+
export function folderProblem(value: string): string | null {
|
|
37
|
+
if (value.length > 64) return 'At most 64 characters.';
|
|
38
|
+
if (value !== value.trim()) return 'No space at either end.';
|
|
39
|
+
if (/[/\p{Cc}]/u.test(value)) return 'No slash.';
|
|
40
|
+
return null;
|
|
41
|
+
}
|
package/src/options.ts
CHANGED
|
@@ -17,12 +17,26 @@
|
|
|
17
17
|
// another path is one the links do not reach.
|
|
18
18
|
import { redirect, type ParsedLocation } from '@tanstack/react-router';
|
|
19
19
|
import type { QueryClient } from '@tanstack/react-query';
|
|
20
|
-
import type { CoffreClient } from '@coffre/client';
|
|
20
|
+
import type { CoffreClient, RouteInput } from '@coffre/client';
|
|
21
21
|
|
|
22
22
|
import { ShellLayout, SoloLayout } from './layout';
|
|
23
|
-
import { uiResult } from './lib/coffre';
|
|
24
|
-
import {
|
|
25
|
-
import
|
|
23
|
+
import { memberRef, uiResult } from './lib/coffre';
|
|
24
|
+
import { stringsOf } from './lib/search';
|
|
25
|
+
import {
|
|
26
|
+
loadAccess,
|
|
27
|
+
loadDirectory,
|
|
28
|
+
loadMember,
|
|
29
|
+
loadProject,
|
|
30
|
+
loadServiceDirectory,
|
|
31
|
+
loadSettings,
|
|
32
|
+
loadShell,
|
|
33
|
+
projectOf,
|
|
34
|
+
queries,
|
|
35
|
+
signInWays,
|
|
36
|
+
type AuditSearch,
|
|
37
|
+
} from './lib/queries';
|
|
38
|
+
import type { Permission } from './shared/models';
|
|
39
|
+
import { loginSearch } from './lib/signin-errors';
|
|
26
40
|
|
|
27
41
|
/**
|
|
28
42
|
* What coffre's routes read through the router: the API as the visitor
|
|
@@ -73,28 +87,85 @@ export const projects = {
|
|
|
73
87
|
},
|
|
74
88
|
};
|
|
75
89
|
|
|
76
|
-
/**
|
|
90
|
+
/**
|
|
91
|
+
* `/projects/$project`, the layout of a project's tabs: its header, and the
|
|
92
|
+
* tabs its visitor may open. Each tab is a page under it that reads its own.
|
|
93
|
+
*/
|
|
77
94
|
export const project = {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
95
|
+
loader: ({ context }: Loader<{ project: string }>) => {
|
|
96
|
+
const { coffre, queryClient } = coffreOf(context);
|
|
97
|
+
return queryClient.fetchQuery(queries.projects(coffre));
|
|
98
|
+
},
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
/** `/projects/$project/`, its environments, and who can open each when you manage its access. */
|
|
102
|
+
export const projectEnvironments = {
|
|
83
103
|
loader: ({ context, params }: Loader<{ project: string }>) => {
|
|
84
104
|
const { coffre, queryClient } = coffreOf(context);
|
|
85
105
|
return loadProject(queryClient, coffre, params.project);
|
|
86
106
|
},
|
|
87
107
|
};
|
|
88
108
|
|
|
109
|
+
/** `/projects/$project/users`: who holds access, and what others read of it through references. */
|
|
110
|
+
export const projectUsers = {
|
|
111
|
+
loader: async ({ context, params }: Loader<{ project: string }>) => {
|
|
112
|
+
const { coffre, queryClient } = coffreOf(context);
|
|
113
|
+
if (!(await projectTab(context, params.project, 'grant.manage'))) return;
|
|
114
|
+
await Promise.all([
|
|
115
|
+
queryClient.fetchQuery(queries.grants(coffre, params.project)),
|
|
116
|
+
queryClient.fetchQuery(queries.references(coffre, params.project)),
|
|
117
|
+
]);
|
|
118
|
+
},
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
/** `/projects/$project/service-accounts`. */
|
|
122
|
+
export const projectServiceAccounts = {
|
|
123
|
+
loader: async ({ context, params }: Loader<{ project: string }>) => {
|
|
124
|
+
const { coffre, queryClient } = coffreOf(context);
|
|
125
|
+
if (await projectTab(context, params.project, 'grant.manage')) await queryClient.fetchQuery(queries.grants(coffre, params.project));
|
|
126
|
+
},
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
/** `/projects/$project/settings`: the project itself, which its layout read. */
|
|
130
|
+
export const projectSettings = {
|
|
131
|
+
loader: async ({ context, params }: Loader<{ project: string }>) => {
|
|
132
|
+
await projectTab(context, params.project, 'project.manage');
|
|
133
|
+
},
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Whether a project's tab reads anything: not for a project its visitor
|
|
138
|
+
* cannot see, whose layout shows a closed door instead; and a tab they may
|
|
139
|
+
* not open sends them to the first, so a link someone shared still lands
|
|
140
|
+
* somewhere useful.
|
|
141
|
+
*/
|
|
142
|
+
async function projectTab(context: unknown, slug: string, permission: Permission): Promise<boolean> {
|
|
143
|
+
const { coffre, queryClient } = coffreOf(context);
|
|
144
|
+
const found = projectOf(await queryClient.fetchQuery(queries.projects(coffre)), slug);
|
|
145
|
+
if (!found.ok) return false;
|
|
146
|
+
if (!found.project.permissions.includes(permission)) throw redirect({ to: '/projects/$project', params: { project: slug } });
|
|
147
|
+
return true;
|
|
148
|
+
}
|
|
149
|
+
|
|
89
150
|
/** `/projects/$project/$environment`. */
|
|
90
151
|
export const environment = {
|
|
91
152
|
// `?filter=KEY` opens the ledger narrowed to matching keys, for links to one secret.
|
|
92
153
|
validateSearch: (search: Record<string, unknown>): { filter?: string } => ({
|
|
93
154
|
filter: typeof search.filter === 'string' && search.filter !== '' ? search.filter : undefined,
|
|
94
155
|
}),
|
|
95
|
-
loader: ({ context, params }: Loader<{ project: string; environment: string }>) => {
|
|
156
|
+
loader: async ({ context, params }: Loader<{ project: string; environment: string }>) => {
|
|
96
157
|
const { coffre, queryClient } = coffreOf(context);
|
|
97
|
-
|
|
158
|
+
const secrets = await queryClient.fetchQuery(queries.secrets(coffre, params));
|
|
159
|
+
// Then, for whoever reads it, the references that read its secrets from
|
|
160
|
+
// elsewhere and the keys it lacks, rendered with them. Asked only then,
|
|
161
|
+
// so a refused visit is one refusal in the log, not three.
|
|
162
|
+
if (secrets.ok) {
|
|
163
|
+
await Promise.all([
|
|
164
|
+
queryClient.fetchQuery(queries.references(coffre, `${params.project}/${params.environment}`)),
|
|
165
|
+
queryClient.fetchQuery(queries.missing(coffre, params)),
|
|
166
|
+
]);
|
|
167
|
+
}
|
|
168
|
+
return secrets;
|
|
98
169
|
},
|
|
99
170
|
};
|
|
100
171
|
|
|
@@ -104,7 +175,7 @@ export const audit = {
|
|
|
104
175
|
validateSearch: (search: Record<string, unknown>): AuditSearch => ({
|
|
105
176
|
decision: search.decision === 'deny' ? 'deny' : undefined,
|
|
106
177
|
actorId: typeof search.actorId === 'string' && search.actorId !== '' ? search.actorId : undefined,
|
|
107
|
-
detail: search.detail === '1'
|
|
178
|
+
detail: search.detail === '1' ? '1' : undefined,
|
|
108
179
|
}),
|
|
109
180
|
loaderDeps: ({ search }: { search: AuditSearch }) => search,
|
|
110
181
|
// The entries only: the verification is asked for once the page is up
|
|
@@ -130,38 +201,91 @@ export const users = {
|
|
|
130
201
|
},
|
|
131
202
|
};
|
|
132
203
|
|
|
133
|
-
/** `/users/$user
|
|
204
|
+
/** `/users/$user`, the layout of a user's tabs: who they are to the instance, for owners. */
|
|
134
205
|
export const user = {
|
|
135
206
|
loader: ({ context, params }: Loader<{ user: string }>) => {
|
|
136
207
|
const { coffre, queryClient } = coffreOf(context);
|
|
137
|
-
return
|
|
208
|
+
return loadMember(queryClient, coffre, memberRef('user', params.user));
|
|
138
209
|
},
|
|
139
210
|
};
|
|
140
211
|
|
|
141
|
-
/** `/
|
|
142
|
-
export const
|
|
212
|
+
/** `/users/$user/`, their access on every project where you manage it. */
|
|
213
|
+
export const userAccess = {
|
|
143
214
|
loader: ({ context }: Loader) => {
|
|
144
215
|
const { coffre, queryClient } = coffreOf(context);
|
|
145
|
-
return
|
|
216
|
+
return loadAccess(queryClient, coffre);
|
|
217
|
+
},
|
|
218
|
+
};
|
|
219
|
+
|
|
220
|
+
/** `/users/$user/activity`, for whoever reads the audit log; the others are sent to the first tab. */
|
|
221
|
+
export const userActivity = {
|
|
222
|
+
loader: async ({ context, params }: Loader<{ user: string }>) => {
|
|
223
|
+
const { coffre, queryClient } = coffreOf(context);
|
|
224
|
+
const shell = await loadShell(queryClient, coffre);
|
|
225
|
+
if (!shell.capabilities.canReadAudit) throw redirect({ to: '/users/$user', params });
|
|
226
|
+
},
|
|
227
|
+
};
|
|
228
|
+
|
|
229
|
+
/** `/service-accounts`. */
|
|
230
|
+
export const serviceAccounts = {
|
|
231
|
+
loader: ({ context }: Loader) => {
|
|
232
|
+
const { coffre, queryClient } = coffreOf(context);
|
|
233
|
+
return loadServiceDirectory(queryClient, coffre);
|
|
234
|
+
},
|
|
235
|
+
};
|
|
236
|
+
|
|
237
|
+
/** `/service-accounts/$account`, the layout of a service account's tabs: who it is to the instance, for owners. */
|
|
238
|
+
export const serviceAccount = {
|
|
239
|
+
loader: ({ context, params }: Loader<{ account: string }>) => {
|
|
240
|
+
const { coffre, queryClient } = coffreOf(context);
|
|
241
|
+
return loadMember(queryClient, coffre, memberRef('service', params.account));
|
|
242
|
+
},
|
|
243
|
+
};
|
|
244
|
+
|
|
245
|
+
/**
|
|
246
|
+
* `/service-accounts/$account/`, how it signs in: its trusted workloads and
|
|
247
|
+
* bearer tokens. Only an owner manages them, and only while it is active;
|
|
248
|
+
* anyone else is sent to its access.
|
|
249
|
+
*/
|
|
250
|
+
export const serviceAccountSignIn = {
|
|
251
|
+
loader: async ({ context, params }: Loader<{ account: string }>) => {
|
|
252
|
+
const { coffre, queryClient } = coffreOf(context);
|
|
253
|
+
const member = memberRef('service', params.account);
|
|
254
|
+
const [shell, report] = await Promise.all([loadShell(queryClient, coffre), loadMember(queryClient, coffre, member)]);
|
|
255
|
+
const ways = signInWays(shell, report);
|
|
256
|
+
if (ways === null) throw redirect({ to: '/service-accounts/$account/access', params });
|
|
257
|
+
await Promise.all([
|
|
258
|
+
queryClient.fetchQuery(queries.credentials(coffre, member, ways.tokens)),
|
|
259
|
+
queryClient.fetchQuery(queries.bindings(coffre, member, ways.workloads)),
|
|
260
|
+
]);
|
|
261
|
+
},
|
|
262
|
+
};
|
|
263
|
+
|
|
264
|
+
/** `/service-accounts/$account/access`. */
|
|
265
|
+
export const serviceAccountAccess = {
|
|
266
|
+
loader: ({ context }: Loader) => {
|
|
267
|
+
const { coffre, queryClient } = coffreOf(context);
|
|
268
|
+
return loadAccess(queryClient, coffre);
|
|
146
269
|
},
|
|
147
270
|
};
|
|
148
271
|
|
|
149
|
-
/** `/
|
|
150
|
-
export const
|
|
151
|
-
loader: ({ context, params }: Loader<{
|
|
272
|
+
/** `/service-accounts/$account/activity`, as a user's. */
|
|
273
|
+
export const serviceAccountActivity = {
|
|
274
|
+
loader: async ({ context, params }: Loader<{ account: string }>) => {
|
|
152
275
|
const { coffre, queryClient } = coffreOf(context);
|
|
153
|
-
|
|
276
|
+
const shell = await loadShell(queryClient, coffre);
|
|
277
|
+
if (!shell.capabilities.canReadAudit) throw redirect({ to: '/service-accounts/$account', params });
|
|
154
278
|
},
|
|
155
279
|
};
|
|
156
280
|
|
|
157
281
|
/** `/settings`. */
|
|
158
282
|
export const settings = {
|
|
159
|
-
// Instance facts come from the directory, which only
|
|
160
|
-
// Asking on everyone's behalf would write a refusal to the
|
|
161
|
-
// every user who opens the page, so
|
|
283
|
+
// Instance facts come from the directory and the key checks, which only
|
|
284
|
+
// owners may read. Asking on everyone's behalf would write a refusal to the
|
|
285
|
+
// audit log for every user who opens the page, so they are only asked for them.
|
|
162
286
|
loader: ({ context }: Loader) => {
|
|
163
287
|
const { coffre, queryClient } = coffreOf(context);
|
|
164
|
-
return
|
|
288
|
+
return loadSettings(queryClient, coffre);
|
|
165
289
|
},
|
|
166
290
|
};
|
|
167
291
|
|
|
@@ -191,15 +315,8 @@ export const account = {
|
|
|
191
315
|
|
|
192
316
|
/** `/login`. */
|
|
193
317
|
export const login = {
|
|
194
|
-
// Where to resume after signing in
|
|
195
|
-
|
|
196
|
-
validateSearch: (search: Record<string, unknown>): { next?: string; error?: string } => {
|
|
197
|
-
const out: { next?: string; error?: string } = {};
|
|
198
|
-
const { next, error } = search;
|
|
199
|
-
if (typeof next === 'string' && next.startsWith('/') && !next.startsWith('//')) out.next = next;
|
|
200
|
-
if (typeof error === 'string' && /^[a-z_]{1,40}$/.test(error)) out.error = error;
|
|
201
|
-
return out;
|
|
202
|
-
},
|
|
318
|
+
// Where to resume after signing in, and the sign-in's error, shown once (`loginSearch`).
|
|
319
|
+
validateSearch: loginSearch,
|
|
203
320
|
loader: async ({ context }: Loader) => {
|
|
204
321
|
const { coffre, queryClient } = coffreOf(context);
|
|
205
322
|
const shell = await loadShell(queryClient, coffre);
|
|
@@ -238,3 +355,38 @@ export const deviceLogin = {
|
|
|
238
355
|
return uiResult(() => coffre.deviceLogins.get(code));
|
|
239
356
|
},
|
|
240
357
|
};
|
|
358
|
+
|
|
359
|
+
/**
|
|
360
|
+
* `/approvals/$approval`: a change an MCP client asked for, which its person
|
|
361
|
+
* decides here. Its own read: the page shows what the change would do now.
|
|
362
|
+
*/
|
|
363
|
+
export const approval = {
|
|
364
|
+
loader: async ({ context, params, location }: Loader<{ approval: string }>) => {
|
|
365
|
+
const { coffre, queryClient } = coffreOf(context);
|
|
366
|
+
const shell = await loadShell(queryClient, coffre);
|
|
367
|
+
if (shell.registrationRequired) throw redirect({ to: '/unregistered' });
|
|
368
|
+
if (shell.principal === null) throw redirect({ to: '/login', search: { next: location.href } });
|
|
369
|
+
return uiResult(() => coffre.approvals.get(params.approval));
|
|
370
|
+
},
|
|
371
|
+
};
|
|
372
|
+
|
|
373
|
+
type AuthorizationSearch = RouteInput<'GET /oauth/authorizations'>;
|
|
374
|
+
|
|
375
|
+
/**
|
|
376
|
+
* `/oauth/authorize`: an MCP client asking to connect. Its parameters go to
|
|
377
|
+
* the API as sent, which says which it takes; the router keeps them strings,
|
|
378
|
+
* so a `state` of `1e5` goes back as `1e5`.
|
|
379
|
+
*/
|
|
380
|
+
export const oauthAuthorize = {
|
|
381
|
+
validateSearch: (search: Record<string, unknown>): AuthorizationSearch => stringsOf(search),
|
|
382
|
+
loaderDeps: ({ search }: { search: AuthorizationSearch }) => ({ request: search }),
|
|
383
|
+
// Its own read, as the device login's: every authorization is checked afresh.
|
|
384
|
+
loader: async ({ context, deps, location }: Loader & { deps: { request: AuthorizationSearch } }) => {
|
|
385
|
+
const { coffre, queryClient } = coffreOf(context);
|
|
386
|
+
const shell = await loadShell(queryClient, coffre);
|
|
387
|
+
if (shell.registrationRequired) throw redirect({ to: '/unregistered' });
|
|
388
|
+
if (shell.principal === null) throw redirect({ to: '/login', search: { next: location.href } });
|
|
389
|
+
const { request } = deps;
|
|
390
|
+
return { request, email: shell.principal.id, result: await uiResult(() => coffre.oauth.describe(request)) };
|
|
391
|
+
},
|
|
392
|
+
};
|