@coffre/ui 0.3.0 → 0.4.1
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/connected-apps-CUOyEZXR.js +146 -0
- package/dist/chunks/connected-apps-CUOyEZXR.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-CxxrnGUL.js} +177 -60
- package/dist/chunks/directory-CxxrnGUL.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-CXcmhujY.js +669 -0
- package/dist/chunks/grants-CXcmhujY.js.map +1 -0
- package/dist/chunks/offboarding-6eAduCsM.js +305 -0
- package/dist/chunks/offboarding-6eAduCsM.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-B9R2zPlp.js} +259 -251
- package/dist/chunks/principal-page-B9R2zPlp.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-CZdI2MJG.js} +75 -21
- package/dist/chunks/use-change-CZdI2MJG.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 +385 -31
- package/dist/index.js +188 -102
- package/dist/index.js.map +1 -1
- package/dist/pages/account.d.ts +2 -2
- package/dist/pages/account.js +174 -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/connected-apps.tsx +138 -0
- package/src/components/delete-place.tsx +180 -0
- package/src/components/directory.tsx +266 -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 +62 -34
- package/src/components/page.tsx +4 -1
- package/src/components/principal-page.tsx +154 -108
- 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 -3
- 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 +77 -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 -42
- package/src/pages/account.tsx +176 -133
- 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 +57 -10
- 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
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { useSuspenseQuery } from '@tanstack/react-query';
|
|
2
|
+
|
|
3
|
+
import { useCoffre } from './coffre';
|
|
4
|
+
import { projectOf, queries } from './queries';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The project one of its tabs shows, as its layout found it: the layout
|
|
8
|
+
* renders a tab only once the project is there for its visitor.
|
|
9
|
+
*/
|
|
10
|
+
export function useProject(slug: string) {
|
|
11
|
+
const found = projectOf(useSuspenseQuery(queries.projects(useCoffre())).data, slug);
|
|
12
|
+
if (!found.ok) throw new Error(`no project "${slug}" for this tab`);
|
|
13
|
+
return found;
|
|
14
|
+
}
|
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
|
+
}
|