@coffre/ui 0.2.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} +115 -56
- 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 +115 -95
- 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
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* A sentence is parts rather than a string, so the page can make the people
|
|
8
8
|
* and places in it links. `plain` flattens it, for tests and titles.
|
|
9
9
|
*/
|
|
10
|
-
import type
|
|
10
|
+
import { shownMember, type AuditEntryView } from '@coffre/client';
|
|
11
11
|
|
|
12
12
|
/** What a sentence is made from: an entry of the log, as `GET /api/audit` gives it. */
|
|
13
13
|
export type AuditEntry = Pick<
|
|
@@ -29,7 +29,11 @@ export type AuditEntry = Pick<
|
|
|
29
29
|
| 'metadata'
|
|
30
30
|
>;
|
|
31
31
|
|
|
32
|
-
/**
|
|
32
|
+
/**
|
|
33
|
+
* Text, a place (`market`, `market/prod`, `market/prod/KEY`), or a member,
|
|
34
|
+
* as the log stores it (`user:…`, `token:…`): `shownMember` says it as people
|
|
35
|
+
* read it, `service:…`, where it is shown.
|
|
36
|
+
*/
|
|
33
37
|
export type Part = string | { place: string } | { member: string };
|
|
34
38
|
|
|
35
39
|
export type Sentence = { parts: Part[]; refused: boolean };
|
|
@@ -78,31 +82,88 @@ function subject(entry: AuditEntry): Part[] {
|
|
|
78
82
|
return [{ member: `${entry.metadata.principalType === 'service' ? 'token' : 'user'}:${id}` }];
|
|
79
83
|
}
|
|
80
84
|
|
|
85
|
+
/** An MCP client, by the name it connected under. */
|
|
86
|
+
function app(entry: AuditEntry): Part[] {
|
|
87
|
+
return [text(entry.metadata.clientName) ?? 'an app'];
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** A tool's call: its name, and what it named. */
|
|
91
|
+
function tool(entry: AuditEntry): Part[] {
|
|
92
|
+
const names = Array.isArray(entry.metadata.names) ? entry.metadata.names.filter((name): name is string => typeof name === 'string') : [];
|
|
93
|
+
return [text(entry.metadata.tool) ?? 'a tool', ...(names.length === 0 ? [] : [` on ${names.join(', ')}`])];
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** The client a request came through, said after what it did: "via Claude". */
|
|
97
|
+
function via(entry: AuditEntry): Part[] {
|
|
98
|
+
const client = (entry.metadata.via as { clientName?: unknown } | undefined)?.clientName;
|
|
99
|
+
return typeof client === 'string' ? [` via ${client}`] : [];
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/** Why coffre itself ended a connection, said after it. */
|
|
103
|
+
const DISCONNECTED: Record<string, string> = {
|
|
104
|
+
code_reused: ': its sign-in code was used twice',
|
|
105
|
+
refresh_reused: ': a refresh token it had replaced was used again',
|
|
106
|
+
revocation_endpoint: ', at its own request',
|
|
107
|
+
superseded: ': a connection with more scopes replaced it',
|
|
108
|
+
};
|
|
109
|
+
|
|
81
110
|
function plural(count: number, one: string, many = `${one}s`): string {
|
|
82
111
|
return `${count} ${count === 1 ? one : many}`;
|
|
83
112
|
}
|
|
84
113
|
|
|
85
114
|
/** A batch reads as its environment and a count; one entry as its secret. */
|
|
115
|
+
/**
|
|
116
|
+
* The secrets a read or write was about. A read through a reference is a
|
|
117
|
+
* read of its source, "market/prod/DATABASE_URL through
|
|
118
|
+
* billing/prod/DATABASE_URL"; a run that read some that way is a run of
|
|
119
|
+
* the environment that holds them.
|
|
120
|
+
*/
|
|
86
121
|
function secrets(facts: Facts): Part[] {
|
|
87
|
-
|
|
88
|
-
|
|
122
|
+
const through = (entry: AuditEntry) => text((entry.metadata.via as { path?: unknown } | undefined)?.path);
|
|
123
|
+
if (facts.batch.length === 1) {
|
|
124
|
+
const held = through(facts.entry);
|
|
125
|
+
return held === null ? place(facts.entry) : [...place(facts.entry), ' through ', { place: held }];
|
|
126
|
+
}
|
|
127
|
+
const own = facts.batch.find((entry) => through(entry) === null);
|
|
128
|
+
const held = facts.batch.map(through).filter((path): path is string => path !== null);
|
|
129
|
+
const where = own !== undefined ? environmentOf(own) : [{ place: held[0]!.split('/').slice(0, 2).join('/') }];
|
|
130
|
+
return [
|
|
131
|
+
...where,
|
|
132
|
+
facts.refused ? ', ' : ': ',
|
|
133
|
+
plural(facts.count, 'secret'),
|
|
134
|
+
...(held.length === 0 ? [] : [`, ${held.length} through ${held.length === 1 ? 'a reference' : 'references'}`]),
|
|
135
|
+
];
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/** "market/prod/OLD", or "OLD and STALE in market/prod" for an archive of several keys refused. */
|
|
139
|
+
function archivedKeys(entry: AuditEntry): Part[] {
|
|
140
|
+
const keys = Array.isArray(entry.metadata.keys) ? entry.metadata.keys.filter((key): key is string => text(key) !== null) : [];
|
|
141
|
+
if (entry.key !== null || keys.length === 0) return place(entry);
|
|
142
|
+
return [keys.length === 1 ? keys[0]! : `${keys.slice(0, -1).join(', ')} and ${keys.at(-1)!}`, ' in ', ...environmentOf(entry)];
|
|
89
143
|
}
|
|
90
144
|
|
|
91
|
-
/** "
|
|
92
|
-
function
|
|
93
|
-
const
|
|
94
|
-
return
|
|
145
|
+
/** "SENTRY_DSN in market/dev", or "3 keys in market/dev" for a Dismiss all. */
|
|
146
|
+
function missingKeys(facts: Facts): Part[] {
|
|
147
|
+
const key = text(facts.entry.metadata.key);
|
|
148
|
+
return [facts.batch.length === 1 && key !== null ? key : plural(facts.count, 'key'), ' in ', ...environmentOf(facts.entry)];
|
|
95
149
|
}
|
|
96
150
|
|
|
97
|
-
|
|
98
|
-
|
|
151
|
+
/** "billing/prod/DATABASE_URL a reference to market/prod/DATABASE_URL", from either author's entry. */
|
|
152
|
+
function referenceTo(entry: AuditEntry): Part[] {
|
|
153
|
+
const holder = text(entry.metadata.subject);
|
|
154
|
+
const key = text(entry.metadata.key);
|
|
155
|
+
const source = text(entry.metadata.source) ?? text((entry.metadata.source as { path?: unknown } | undefined)?.path);
|
|
156
|
+
return [
|
|
157
|
+
...(holder !== null ? [{ place: holder }] : key !== null ? place(entry) : environmentOf(entry)),
|
|
158
|
+
...(source === null ? [] : [' a reference to ', { place: source }]),
|
|
159
|
+
];
|
|
99
160
|
}
|
|
100
161
|
|
|
101
162
|
const READ_VERBS: Record<string, [did: string, tried: string]> = {
|
|
102
163
|
reveal: ['revealed', 'reveal'],
|
|
103
164
|
run: ['ran', 'run'],
|
|
104
165
|
compare: ['compared', 'compare'],
|
|
105
|
-
|
|
166
|
+
copy: ['copied', 'copy'],
|
|
106
167
|
};
|
|
107
168
|
|
|
108
169
|
function readVerb({ entry }: Facts): [string, string] {
|
|
@@ -112,10 +173,18 @@ function readVerb({ entry }: Facts): [string, string] {
|
|
|
112
173
|
const placeTemplates = (kind: 'project' | 'environment'): Record<string, Template> => {
|
|
113
174
|
const what = (facts: Facts): Part[] => [`${kind} `, ...(kind === 'project' ? place({ ...facts.entry, environment: null, key: null }) : environmentOf(facts.entry))];
|
|
114
175
|
return {
|
|
115
|
-
[`${kind}.create`]: {
|
|
176
|
+
[`${kind}.create`]: {
|
|
177
|
+
did: 'created',
|
|
178
|
+
tried: 'create',
|
|
179
|
+
what,
|
|
180
|
+
// A fork names the environment it copied.
|
|
181
|
+
then: ({ entry }) => (text(entry.metadata.from) === null ? [] : [`, a fork of ${text(entry.metadata.from)}`]),
|
|
182
|
+
},
|
|
116
183
|
[`${kind}.update`]: { did: 'changed', tried: 'change', what },
|
|
117
184
|
[`${kind}.archive`]: { did: 'archived', tried: 'archive', what },
|
|
118
185
|
[`${kind}.restore`]: { did: 'restored', tried: 'restore', what },
|
|
186
|
+
// Named by its tombstone from then on, `market~deleted-2026-10-05`, as every entry about it is.
|
|
187
|
+
[`${kind}.delete`]: { did: 'deleted', tried: 'delete', what },
|
|
119
188
|
};
|
|
120
189
|
};
|
|
121
190
|
|
|
@@ -149,10 +218,42 @@ const TEMPLATES: Record<string, Template> = {
|
|
|
149
218
|
tried: 'rename',
|
|
150
219
|
what: ({ entry }) => [...place(entry), ...(text(entry.metadata.nextKey) === null ? [] : [` to ${text(entry.metadata.nextKey)}`])],
|
|
151
220
|
},
|
|
152
|
-
'secret.archive': { did: 'archived', tried: 'archive', what: (
|
|
221
|
+
'secret.archive': { did: 'archived', tried: 'archive', what: ({ entry }) => archivedKeys(entry) },
|
|
222
|
+
'missing.dismiss': {
|
|
223
|
+
did: 'dismissed',
|
|
224
|
+
tried: 'dismiss',
|
|
225
|
+
what: (facts) => missingKeys(facts),
|
|
226
|
+
then: () => [' as not needed'],
|
|
227
|
+
},
|
|
228
|
+
'missing.restore': { did: 'restored', tried: 'restore', what: (facts) => missingKeys(facts), then: () => [' to the missing keys'] },
|
|
229
|
+
'secret.reference': { did: 'made', tried: 'make', what: ({ entry }) => referenceTo(entry) },
|
|
230
|
+
'reference.create': { did: 'made', tried: 'make', what: ({ entry }) => referenceTo(entry) },
|
|
231
|
+
'reference.end': {
|
|
232
|
+
did: ({ entry }) => (entry.metadata.reason === 'replaced' ? 'gave a value of its own to' : entry.metadata.reason === 'abandoned' ? 'abandoned' : 'broke'),
|
|
233
|
+
tried: ({ entry }) => (entry.metadata.reason === 'replaced' ? 'replace' : entry.metadata.reason === 'abandoned' ? 'abandon' : 'break'),
|
|
234
|
+
what: ({ entry }) => {
|
|
235
|
+
const source = text((entry.metadata.source as { path?: unknown } | undefined)?.path);
|
|
236
|
+
const holder = text(entry.metadata.subject);
|
|
237
|
+
if (entry.metadata.reason === 'replaced') return [...(holder === null ? ['a reference'] : [{ place: holder }]), ...(source === null ? [] : [', no longer a reference to ', { place: source }])];
|
|
238
|
+
return ['the reference ', ...(holder === null ? [] : [{ place: holder }]), ...(source === null ? [] : [' to ', { place: source }])];
|
|
239
|
+
},
|
|
240
|
+
then: ({ entry }) => (entry.metadata.reason === 'abandoned' ? [', which its write never stored'] : []),
|
|
241
|
+
},
|
|
153
242
|
'secret.unarchive': { did: 'brought back', tried: 'bring back', what: (facts) => place(facts.entry) },
|
|
243
|
+
'secret.move': { did: 'moved', tried: 'move', what: (facts) => place(facts.entry), then: ({ entry }) => intoFolder(entry) },
|
|
154
244
|
...placeTemplates('project'),
|
|
245
|
+
'project.move': {
|
|
246
|
+
did: 'moved',
|
|
247
|
+
tried: 'move',
|
|
248
|
+
what: ({ entry }) => ['project ', ...place({ ...entry, environment: null, key: null })],
|
|
249
|
+
then: ({ entry }) => intoFolder(entry),
|
|
250
|
+
},
|
|
155
251
|
...placeTemplates('environment'),
|
|
252
|
+
'environment.fork': {
|
|
253
|
+
did: 'forked',
|
|
254
|
+
tried: 'fork',
|
|
255
|
+
what: ({ entry }) => [...environmentOf(entry), ...(text(entry.metadata.slug) === null ? [] : [` into ${text(entry.metadata.slug)}`])],
|
|
256
|
+
},
|
|
156
257
|
'access.grant': {
|
|
157
258
|
did: 'gave',
|
|
158
259
|
tried: 'give',
|
|
@@ -192,37 +293,6 @@ const TEMPLATES: Record<string, Template> = {
|
|
|
192
293
|
tried: ({ entry }) => (entry.metadata.owner === false ? 'take owner from' : 'make'),
|
|
193
294
|
what: ({ entry }) => [...subject(entry), ...(entry.metadata.owner === false ? [] : [' an owner'])],
|
|
194
295
|
},
|
|
195
|
-
'sync.create': {
|
|
196
|
-
did: 'set up a sync of',
|
|
197
|
-
tried: 'set up a sync of',
|
|
198
|
-
what: ({ entry }) => [...environmentOf(entry), toDestination(entry)],
|
|
199
|
-
},
|
|
200
|
-
'sync.update': {
|
|
201
|
-
did: ({ entry }) => (entry.metadata.paused === true ? 'paused the sync of' : entry.metadata.paused === false ? 'resumed the sync of' : 'changed the sync of'),
|
|
202
|
-
tried: 'change the sync of',
|
|
203
|
-
what: ({ entry }) => [...environmentOf(entry), toDestination(entry)],
|
|
204
|
-
},
|
|
205
|
-
'sync.delete': {
|
|
206
|
-
did: 'removed the sync of',
|
|
207
|
-
tried: 'remove the sync of',
|
|
208
|
-
what: ({ entry }) => [...environmentOf(entry), toDestination(entry)],
|
|
209
|
-
},
|
|
210
|
-
'sync.push': {
|
|
211
|
-
did: 'pushed',
|
|
212
|
-
tried: 'push',
|
|
213
|
-
what: (facts) =>
|
|
214
|
-
facts.batch.length === 1
|
|
215
|
-
? [...place(facts.entry), ` to ${destination(facts.entry)}`]
|
|
216
|
-
: [...environmentOf(facts.entry), ` to ${destination(facts.entry)}: ${plural(facts.count, 'secret')}`],
|
|
217
|
-
},
|
|
218
|
-
'sync.remove': {
|
|
219
|
-
did: 'removed',
|
|
220
|
-
tried: 'remove',
|
|
221
|
-
what: (facts) =>
|
|
222
|
-
facts.batch.length === 1
|
|
223
|
-
? [...place(facts.entry), ` from ${destination(facts.entry)}`]
|
|
224
|
-
: [plural(facts.count, 'secret'), ' of ', ...environmentOf(facts.entry), ` from ${destination(facts.entry)}`],
|
|
225
|
-
},
|
|
226
296
|
// A binding trusts CI runs to sign in as a service; removing one is its tombstone.
|
|
227
297
|
'token.bind': {
|
|
228
298
|
did: 'trusted CI runs to sign in as',
|
|
@@ -243,6 +313,20 @@ const TEMPLATES: Record<string, Template> = {
|
|
|
243
313
|
],
|
|
244
314
|
},
|
|
245
315
|
'key.rotate': { did: 'rotated its key', tried: 'rotate its key', what: () => [] },
|
|
316
|
+
// An MCP client a person connected, such as Claude: named as the consent page showed it.
|
|
317
|
+
'mcp.connect': { did: 'connected', tried: 'connect', what: ({ entry }) => app(entry) },
|
|
318
|
+
// A tool an MCP client called, by its name, and the places it named.
|
|
319
|
+
'mcp.call': { did: 'used', tried: 'use', what: ({ entry }) => tool(entry), then: ({ entry }) => via(entry) },
|
|
320
|
+
// A person's decision, on coffre's page, on a change an MCP client asked for; the change's own entries follow, via the client.
|
|
321
|
+
'mcp.approve': { did: 'approved', tried: 'approve', what: ({ entry }) => tool(entry), then: ({ entry }) => [` for ${text(entry.metadata.clientName) ?? 'an app'}`] },
|
|
322
|
+
'mcp.deny': { did: 'turned down', tried: 'turn down', what: ({ entry }) => tool(entry), then: ({ entry }) => [` for ${text(entry.metadata.clientName) ?? 'an app'}`] },
|
|
323
|
+
'mcp.view': { did: 'opened an approval', tried: 'open an approval', what: () => [] },
|
|
324
|
+
'mcp.disconnect': {
|
|
325
|
+
did: 'disconnected',
|
|
326
|
+
tried: 'disconnect',
|
|
327
|
+
what: ({ entry }) => [...app(entry), ...(entry.metadata.principalId === undefined ? [] : [' of ', ...subject(entry)])],
|
|
328
|
+
then: ({ entry }) => [DISCONNECTED[text(entry.metadata.reason) ?? ''] ?? ''],
|
|
329
|
+
},
|
|
246
330
|
|
|
247
331
|
// Detail, hidden unless asked for.
|
|
248
332
|
sign_in: {
|
|
@@ -251,10 +335,16 @@ const TEMPLATES: Record<string, Template> = {
|
|
|
251
335
|
what: ({ entry }) => (text(entry.metadata.provider) === null ? [] : [`with ${text(entry.metadata.provider)}`]),
|
|
252
336
|
},
|
|
253
337
|
sign_out: { did: 'signed out', tried: 'sign out', what: () => [] },
|
|
254
|
-
'token.create': { did: 'issued a token to', tried: 'issue a token to', what: (facts) => subject(facts.entry) },
|
|
255
|
-
'token.revoke': { did: 'revoked a token of', tried: 'revoke a token of', what: (facts) => subject(facts.entry) },
|
|
338
|
+
'token.create': { did: 'issued a bearer token to', tried: 'issue a bearer token to', what: (facts) => subject(facts.entry) },
|
|
339
|
+
'token.revoke': { did: 'revoked a bearer token of', tried: 'revoke a bearer token of', what: (facts) => subject(facts.entry) },
|
|
256
340
|
'device.approve': { did: 'approved a CLI sign-in', tried: 'approve a CLI sign-in', what: () => [] },
|
|
257
341
|
'device.deny': { did: 'turned down a CLI sign-in', tried: 'turn down a CLI sign-in', what: () => [] },
|
|
342
|
+
'mcp.read': { did: 'used', tried: 'use', what: ({ entry }) => tool(entry), then: ({ entry }) => via(entry) },
|
|
343
|
+
'mcp.token': {
|
|
344
|
+
did: ({ entry }) => (entry.metadata.grant === 'refresh_token' ? 'refreshed the tokens of' : 'gave its first tokens to'),
|
|
345
|
+
tried: 'give tokens to',
|
|
346
|
+
what: ({ entry }) => app(entry),
|
|
347
|
+
},
|
|
258
348
|
'account.link': {
|
|
259
349
|
did: 'linked',
|
|
260
350
|
tried: 'link',
|
|
@@ -273,11 +363,6 @@ const TEMPLATES: Record<string, Template> = {
|
|
|
273
363
|
tried: 'check',
|
|
274
364
|
what: ({ entry }) => [['the', text(entry.metadata.kekProvider) === 'local' ? null : text(entry.metadata.kekProvider), 'vault key', text(entry.metadata.kekId)].filter((word) => word !== null).join(' ')],
|
|
275
365
|
},
|
|
276
|
-
'sync.run': {
|
|
277
|
-
did: 'ran the sync of',
|
|
278
|
-
tried: 'run the sync of',
|
|
279
|
-
what: ({ entry }) => [...environmentOf(entry), toDestination(entry)],
|
|
280
|
-
},
|
|
281
366
|
'audit.heartbeat': { did: 'checked in', tried: 'check in', what: () => [] },
|
|
282
367
|
'audit.checkpoint': {
|
|
283
368
|
did: 'signed the log',
|
|
@@ -289,10 +374,18 @@ const TEMPLATES: Record<string, Template> = {
|
|
|
289
374
|
'secret.list': { did: 'listed', tried: 'list', what: ({ entry }) => environmentOf(entry) },
|
|
290
375
|
'secret.history': { did: 'read the history of', tried: 'read the history of', what: (facts) => place(facts.entry) },
|
|
291
376
|
'secret.update': { did: 'changed', tried: 'change', what: (facts) => place(facts.entry) },
|
|
292
|
-
'sync.list': { did: 'listed the syncs of', tried: 'list the syncs of', what: ({ entry }) => environmentOf(entry) },
|
|
293
377
|
};
|
|
294
378
|
|
|
379
|
+
/** " to the folder stripe", or " out of its folder". */
|
|
380
|
+
function intoFolder(entry: AuditEntry): Part[] {
|
|
381
|
+
const folder = text(entry.metadata.to);
|
|
382
|
+
return [folder === null ? ' out of its folder' : ` to the folder ${folder}`];
|
|
383
|
+
}
|
|
384
|
+
|
|
295
385
|
function placeOnly(entry: AuditEntry): Part[] {
|
|
386
|
+
// A grant on every project names no project: its place is a path in its payload, `*` or `*/dev`.
|
|
387
|
+
const everywhere = entry.project === null ? text(entry.metadata.place) : null;
|
|
388
|
+
if (everywhere !== null) return [everywhere === '*' ? 'every project' : `${everywhere.slice('*/'.length)} in every project`];
|
|
296
389
|
return place({ ...entry, key: null });
|
|
297
390
|
}
|
|
298
391
|
|
|
@@ -316,16 +409,24 @@ const REASONS: Record<string, string> = {
|
|
|
316
409
|
not_registered: 'not invited',
|
|
317
410
|
tampered: 'their record was tampered with',
|
|
318
411
|
bad_claim: 'the key did not match the secret',
|
|
412
|
+
deleted: 'the place was deleted',
|
|
319
413
|
not_allowed: 'not allowed',
|
|
320
414
|
root_admin: 'root admins are set by the deployment',
|
|
321
415
|
unknown_environment: 'no such environment',
|
|
322
416
|
unknown_secret: 'no such secret',
|
|
417
|
+
no_value: 'it holds no value',
|
|
323
418
|
unknown_project: 'no such project',
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
cannot_grant_sync: 'cannot grant the sync its reads',
|
|
419
|
+
not_archived: 'it was not archived',
|
|
420
|
+
referenced: 'references read it',
|
|
327
421
|
kms_unavailable: 'KMS did not answer',
|
|
328
422
|
wrong_kek: "the vault's key is not the one that wrapped the data",
|
|
423
|
+
person_denied: 'they said no',
|
|
424
|
+
too_many_connections: 'too many connected apps',
|
|
425
|
+
unknown_connection: 'no such connected app',
|
|
426
|
+
not_yours: "it was someone else's",
|
|
427
|
+
too_many_approvals: 'too many changes waiting for approval',
|
|
428
|
+
request_state: 'its retry did not match its call',
|
|
429
|
+
changed: 'the change was not the one shown',
|
|
329
430
|
};
|
|
330
431
|
|
|
331
432
|
/** What a missing permission meant, from the app's `missing_<permission>`. */
|
|
@@ -347,8 +448,8 @@ export function reasonInWords(reason: string | null): string {
|
|
|
347
448
|
|
|
348
449
|
// --- lines ----------------------------------------------------------------------
|
|
349
450
|
|
|
350
|
-
/** In a batch of mixed actions, the one the line is named for: a
|
|
351
|
-
const LEAD = ['
|
|
451
|
+
/** In a batch of mixed actions, the one the line is named for: a write, not its reads. */
|
|
452
|
+
const LEAD = ['secret.write', 'secret.read'];
|
|
352
453
|
|
|
353
454
|
export function leadOf(batch: AuditEntry[]): AuditEntry {
|
|
354
455
|
for (const action of LEAD) {
|
|
@@ -383,30 +484,13 @@ export function describe(batch: AuditEntry[]): Sentence {
|
|
|
383
484
|
return { parts: [say(template.did), ...gap, ...what, ...(template.then?.(facts) ?? []), ...partly], refused };
|
|
384
485
|
}
|
|
385
486
|
|
|
386
|
-
/**
|
|
387
|
-
|
|
388
|
-
* itself is text. A sync is named for where it pushes, which any entry of
|
|
389
|
-
* its batch may say.
|
|
390
|
-
*/
|
|
391
|
-
export function who(batch: Pick<AuditEntry, 'actorType' | 'actorId' | 'metadata'>[]): string | { member: string } {
|
|
392
|
-
const entry = batch[0]!;
|
|
487
|
+
/** Who acted, as a part: a member links to their page; coffre itself is text. */
|
|
488
|
+
export function who(entry: Pick<AuditEntry, 'actorType' | 'actorId'>): string | { member: string } {
|
|
393
489
|
if (entry.actorType === 'user') return { member: `user:${entry.actorId}` };
|
|
394
490
|
if (entry.actorType === 'service') return { member: `token:${entry.actorId}` };
|
|
395
|
-
if (entry.actorId.startsWith('sync:')) {
|
|
396
|
-
const id = batch.map((other) => text(other.metadata.provider)).find((provider) => provider !== null);
|
|
397
|
-
const provider = id === undefined ? undefined : (PROVIDERS[id!] ?? id!);
|
|
398
|
-
return provider === undefined ? 'a sync' : `sync to ${provider}`;
|
|
399
|
-
}
|
|
400
491
|
return SYSTEM[entry.actorId] ?? entry.actorId;
|
|
401
492
|
}
|
|
402
493
|
|
|
403
|
-
const PROVIDERS: Record<string, string> = {
|
|
404
|
-
'github-actions': 'GitHub',
|
|
405
|
-
vercel: 'Vercel',
|
|
406
|
-
railway: 'Railway',
|
|
407
|
-
'cloudflare-workers': 'Cloudflare',
|
|
408
|
-
};
|
|
409
|
-
|
|
410
494
|
const SYSTEM: Record<string, string> = {
|
|
411
495
|
scheduler: 'the scheduler',
|
|
412
496
|
cron: 'the scheduler',
|
|
@@ -443,7 +527,7 @@ export function lines<T extends AuditEntry>(entries: T[]): T[][] {
|
|
|
443
527
|
export function plain(parts: Part[]): string {
|
|
444
528
|
return parts
|
|
445
529
|
.map((part) =>
|
|
446
|
-
typeof part === 'string' ? part : 'place' in part ? part.place : part.member.startsWith('user:') ? part.member.slice(5) : part.member,
|
|
530
|
+
typeof part === 'string' ? part : 'place' in part ? part.place : part.member.startsWith('user:') ? part.member.slice(5) : shownMember(part.member),
|
|
447
531
|
)
|
|
448
532
|
.join('');
|
|
449
533
|
}
|
package/src/lib/changes.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { CoffreClient, IdentityRow, SecretKey, SessionRow } from '@coffre/client';
|
|
1
|
+
import type { CoffreClient, ConnectedApp, IdentityRow, SecretKey, SessionRow } from '@coffre/client';
|
|
2
2
|
import type { Role } from '@coffre/core/access';
|
|
3
3
|
import type { QueryKey } from '@tanstack/react-query';
|
|
4
4
|
|
|
@@ -42,8 +42,9 @@ const removing = (id: string): Target => ({ id, kind: 'removing' });
|
|
|
42
42
|
type Grants = ({ ok: true; grants: GrantRow[] } | Failure);
|
|
43
43
|
|
|
44
44
|
/** A grant's identity, before the server has given it an id: who, and where. */
|
|
45
|
-
export function grantId(grant: Pick<GrantRow, 'principalType' | 'principalId' | 'environmentSlug'>): string {
|
|
46
|
-
|
|
45
|
+
export function grantId(grant: Pick<GrantRow, 'principalType' | 'principalId' | 'environmentSlug'> & { scope?: GrantRow['scope'] }): string {
|
|
46
|
+
const everywhere = grant.scope === 'every-project' ? '*/' : '';
|
|
47
|
+
return `${memberRef(grant.principalType, grant.principalId)}@${everywhere}${grant.environmentSlug ?? ''}`;
|
|
47
48
|
}
|
|
48
49
|
|
|
49
50
|
export function grantsList(project: string) {
|
|
@@ -229,6 +230,19 @@ export function endSession(client: CoffreClient): Change<Sessions, SessionRow, S
|
|
|
229
230
|
};
|
|
230
231
|
}
|
|
231
232
|
|
|
233
|
+
type Apps = ({ ok: true; apps: ConnectedApp[] } | Failure);
|
|
234
|
+
|
|
235
|
+
export function disconnectApp(client: CoffreClient): Change<Apps, ConnectedApp, ConnectedApp, unknown> {
|
|
236
|
+
return {
|
|
237
|
+
list: listOf<ConnectedApp, Apps>(keys.apps, 'apps', (app) => app.id),
|
|
238
|
+
label: (app) => app.name,
|
|
239
|
+
targets: (app) => [removing(app.id)],
|
|
240
|
+
removing: { pending: 'Disconnecting…', done: 'disconnected', failed: 'Not disconnected.' },
|
|
241
|
+
affects: () => affects.apps(),
|
|
242
|
+
run: (app) => client.apps.disconnect(app.id),
|
|
243
|
+
};
|
|
244
|
+
}
|
|
245
|
+
|
|
232
246
|
type Identities = ({ ok: true; identities: IdentityRow[] } | Failure);
|
|
233
247
|
|
|
234
248
|
export function unlinkIdentity(client: CoffreClient): Change<Identities, IdentityRow, IdentityRow & { label: string }, unknown> {
|
|
@@ -259,6 +273,7 @@ export function createProject(client: CoffreClient): Change<Projects, ProjectSum
|
|
|
259
273
|
slug: vars.slug,
|
|
260
274
|
name: vars.name,
|
|
261
275
|
archivedAt: null,
|
|
276
|
+
folder: null,
|
|
262
277
|
// You become its owner.
|
|
263
278
|
permissions: ['project.manage', 'environment.manage', 'grant.manage'],
|
|
264
279
|
environments: [],
|
|
@@ -277,6 +292,18 @@ export function createProject(client: CoffreClient): Change<Projects, ProjectSum
|
|
|
277
292
|
type Environment = ProjectSummary['environments'][number];
|
|
278
293
|
|
|
279
294
|
/** One project's environments, held in the project list. */
|
|
295
|
+
/** File a project in a folder, or in none: shown at once, under its new heading. */
|
|
296
|
+
export function moveProject(client: CoffreClient): Change<Projects, ProjectSummary, { slug: string; folder: string | null }, unknown> {
|
|
297
|
+
return {
|
|
298
|
+
list: projectsList,
|
|
299
|
+
label: (vars) => `project ${vars.slug}`,
|
|
300
|
+
targets: (vars) => [saving(vars.slug)],
|
|
301
|
+
apply: (projects, vars) => projects.map((project) => (project.slug === vars.slug ? { ...project, folder: vars.folder } : project)),
|
|
302
|
+
affects: () => affects.places(),
|
|
303
|
+
run: (vars) => client.projects.update(vars.slug, { folder: vars.folder }),
|
|
304
|
+
};
|
|
305
|
+
}
|
|
306
|
+
|
|
280
307
|
export function environmentsList(project: string): ListShape<Projects, Environment> {
|
|
281
308
|
const environmentsOf = (data: Projects) =>
|
|
282
309
|
data.ok ? (data.projects.find((entry) => entry.slug === project)?.environments ?? []) : [];
|
|
@@ -296,7 +323,8 @@ export function environmentId(project: string, environment: string): string {
|
|
|
296
323
|
return `${project}/${environment}`;
|
|
297
324
|
}
|
|
298
325
|
|
|
299
|
-
|
|
326
|
+
/** A new environment, empty or, `from` a sibling, forked: each of its keys copied. */
|
|
327
|
+
export function createEnvironment(client: CoffreClient, project: string): Change<Projects, Environment, { slug: string; name: string; from?: string; references?: boolean }, void> {
|
|
300
328
|
return {
|
|
301
329
|
list: environmentsList(project),
|
|
302
330
|
label: (vars) => `environment ${vars.slug}`,
|
|
@@ -307,7 +335,11 @@ export function createEnvironment(client: CoffreClient, project: string): Change
|
|
|
307
335
|
],
|
|
308
336
|
affects: () => affects.places(),
|
|
309
337
|
run: async (vars) => {
|
|
310
|
-
const { created } = await client.environments.create(`${project}/${vars.slug}`, {
|
|
338
|
+
const { created } = await client.environments.create(`${project}/${vars.slug}`, {
|
|
339
|
+
name: vars.name,
|
|
340
|
+
...(vars.from === undefined ? {} : { from: vars.from }),
|
|
341
|
+
...(vars.references === true ? { references: true } : {}),
|
|
342
|
+
});
|
|
311
343
|
if (!created) throw new Refusal(`An environment named "${vars.slug}" already exists.`);
|
|
312
344
|
},
|
|
313
345
|
};
|
|
@@ -431,6 +463,10 @@ export function saveSecrets(
|
|
|
431
463
|
const now = new Date().toISOString();
|
|
432
464
|
const bumped = (entry: SecretKey | undefined, key: string): SecretKey => ({
|
|
433
465
|
key,
|
|
466
|
+
// A rename keeps its folder; a new secret is in none.
|
|
467
|
+
folder: entry?.folder ?? null,
|
|
468
|
+
// A value of its own: no longer a reference.
|
|
469
|
+
reference: null,
|
|
434
470
|
archived: false,
|
|
435
471
|
version: (entry?.version ?? 0) + 1,
|
|
436
472
|
updatedAt: now,
|
|
@@ -481,6 +517,21 @@ export function saveSecrets(
|
|
|
481
517
|
};
|
|
482
518
|
}
|
|
483
519
|
|
|
520
|
+
/** File a secret in a folder, or in none: shown at once, under its new heading. */
|
|
521
|
+
export function moveSecret(
|
|
522
|
+
client: CoffreClient,
|
|
523
|
+
place: { project: string; environment: string },
|
|
524
|
+
): Change<Secrets, SecretKey, { key: string; folder: string | null }, unknown> {
|
|
525
|
+
return {
|
|
526
|
+
list: secretsList(place),
|
|
527
|
+
label: (vars) => vars.key,
|
|
528
|
+
targets: (vars) => [saving(vars.key)],
|
|
529
|
+
apply: (entries, vars) => entries.map((entry) => (entry.key === vars.key ? { ...entry, folder: vars.folder } : entry)),
|
|
530
|
+
affects: () => affects.secrets(place),
|
|
531
|
+
run: (vars) => client.secrets.update(`${place.project}/${place.environment}/${vars.key}`, { folder: vars.folder }),
|
|
532
|
+
};
|
|
533
|
+
}
|
|
534
|
+
|
|
484
535
|
/** Restore an archived secret, from the Archived list. */
|
|
485
536
|
export function restoreSecret(
|
|
486
537
|
client: CoffreClient,
|
package/src/lib/coffre.ts
CHANGED
|
@@ -36,7 +36,8 @@ export function failureMessage(error: unknown): string {
|
|
|
36
36
|
}
|
|
37
37
|
if (error.status === 404) return 'Not found. It may have been renamed or archived.';
|
|
38
38
|
// A 400 or 409 carries a sentence written for the person, such as which
|
|
39
|
-
// field of a request is wrong
|
|
39
|
+
// field of a request is wrong, which names a service account as people
|
|
40
|
+
// do, service:<name>. Anything unexpected stays generic.
|
|
40
41
|
if (error.status === 400 || error.status === 409) return error.message;
|
|
41
42
|
return 'coffre is unavailable. Nothing was read or written.';
|
|
42
43
|
}
|
|
@@ -56,7 +57,7 @@ export async function uiResult<T extends object>(
|
|
|
56
57
|
}
|
|
57
58
|
}
|
|
58
59
|
|
|
59
|
-
/** How the API names a member: `user:ada@acme.example`, `token:ci-deploy
|
|
60
|
+
/** How the API names a member: `user:ada@acme.example`, `token:ci-deploy` (which people read as `service:ci-deploy`). */
|
|
60
61
|
export function memberRef(principalType: 'user' | 'service', principalId: string): string {
|
|
61
62
|
return `${principalType === 'user' ? 'user' : 'token'}:${principalId}`;
|
|
62
63
|
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { useEffect, useState } from 'react';
|
|
2
|
+
import { useNavigate } from '@tanstack/react-router';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* A notice that rides in the URL once, as a sign-in's `?error=` does: read
|
|
6
|
+
* as the page first renders, on the server, so it shows without JavaScript;
|
|
7
|
+
* then taken out of the address, the history entry replaced, so that a
|
|
8
|
+
* reload is a clean retry and a copied link carries no stale error. What was
|
|
9
|
+
* read stays shown until the page is left.
|
|
10
|
+
*
|
|
11
|
+
* Why the URL and not a one-time cookie: the URL is the one thing the server
|
|
12
|
+
* renders from, so nothing has to be set on the redirect, read by the
|
|
13
|
+
* render and cleared by exactly the right response, which streaming and the
|
|
14
|
+
* requests a page fires beside it make fragile. The cost: without
|
|
15
|
+
* JavaScript, a reload shows the notice again, and coffre's pages need
|
|
16
|
+
* JavaScript for everything else.
|
|
17
|
+
*/
|
|
18
|
+
export function useOneTime<T extends Record<string, unknown>, K extends keyof T & string>(search: T, names: readonly K[]): Pick<T, K> {
|
|
19
|
+
const [kept] = useState(() => Object.fromEntries(names.map((name) => [name, search[name]])) as Pick<T, K>);
|
|
20
|
+
const navigate = useNavigate();
|
|
21
|
+
const present = names.some((name) => search[name] !== undefined);
|
|
22
|
+
useEffect(() => {
|
|
23
|
+
if (!present) return;
|
|
24
|
+
void navigate({
|
|
25
|
+
to: '.',
|
|
26
|
+
search: (previous: Record<string, unknown>) => Object.fromEntries(Object.entries(previous).filter(([name]) => !(names as readonly string[]).includes(name))),
|
|
27
|
+
replace: true,
|
|
28
|
+
});
|
|
29
|
+
// Once, after hydration: later renders keep what was read.
|
|
30
|
+
}, []);
|
|
31
|
+
return kept;
|
|
32
|
+
}
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
+
import { ROLES, type Role } from '@coffre/core/access';
|
|
2
|
+
|
|
1
3
|
import type { GrantRow, ProjectSummary, RoleRow } from '../shared/models';
|
|
2
4
|
|
|
3
|
-
|
|
5
|
+
/** The roles the project's access picker offers, a product choice; others show by their names. */
|
|
6
|
+
export type ProjectAccessRole = Extract<Role, 'owner' | 'viewer' | 'developer'>;
|
|
4
7
|
|
|
5
8
|
export type ProjectAccessOption = {
|
|
6
9
|
value: string;
|
|
@@ -9,12 +12,6 @@ export type ProjectAccessOption = {
|
|
|
9
12
|
label: string;
|
|
10
13
|
};
|
|
11
14
|
|
|
12
|
-
const LEVEL_LABELS: Record<ProjectAccessRole, string> = {
|
|
13
|
-
owner: 'Owner',
|
|
14
|
-
viewer: 'Read',
|
|
15
|
-
developer: 'Write',
|
|
16
|
-
};
|
|
17
|
-
|
|
18
15
|
export function projectAccessOptions(
|
|
19
16
|
environments: ProjectSummary['environments'],
|
|
20
17
|
): ProjectAccessOption[] {
|
|
@@ -23,7 +20,7 @@ export function projectAccessOptions(
|
|
|
23
20
|
value: 'owner:',
|
|
24
21
|
role: 'owner',
|
|
25
22
|
environmentSlug: null,
|
|
26
|
-
label:
|
|
23
|
+
label: ROLES.owner.name,
|
|
27
24
|
},
|
|
28
25
|
];
|
|
29
26
|
|
|
@@ -32,7 +29,7 @@ export function projectAccessOptions(
|
|
|
32
29
|
value: `${role}:`,
|
|
33
30
|
role,
|
|
34
31
|
environmentSlug: null,
|
|
35
|
-
label: `${
|
|
32
|
+
label: `${ROLES[role].name}: all`,
|
|
36
33
|
});
|
|
37
34
|
}
|
|
38
35
|
|
|
@@ -43,7 +40,7 @@ export function projectAccessOptions(
|
|
|
43
40
|
value: `${role}:${environment.slug}`,
|
|
44
41
|
role,
|
|
45
42
|
environmentSlug: environment.slug,
|
|
46
|
-
label: `${
|
|
43
|
+
label: `${ROLES[role].name}: ${environment.slug}`,
|
|
47
44
|
});
|
|
48
45
|
}
|
|
49
46
|
}
|
|
@@ -62,22 +59,13 @@ export function parseProjectAccess(value: string): {
|
|
|
62
59
|
return { role, environmentSlug: environmentSlug || null };
|
|
63
60
|
}
|
|
64
61
|
|
|
62
|
+
/** "Owner", "Viewer: all" or "Developer: prod": a grant by its role's name, and where. */
|
|
65
63
|
export function projectAccessLabel(
|
|
66
64
|
grant: Pick<GrantRow, 'role' | 'roleName' | 'environmentSlug'>,
|
|
67
65
|
): string {
|
|
68
|
-
const
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
if (grant.role === 'owner') return 'Owner';
|
|
72
|
-
if (grant.role === 'viewer') {
|
|
73
|
-
return grant.environmentSlug === null ? 'Read: all' : `Read: ${scope}`;
|
|
74
|
-
}
|
|
75
|
-
if (grant.role === 'developer') {
|
|
76
|
-
return grant.environmentSlug === null ? 'Write: all' : `Write: ${scope}`;
|
|
77
|
-
}
|
|
78
|
-
// Specialised grants remain legible even though the common access controls
|
|
79
|
-
// use owner/read/write.
|
|
80
|
-
return `${grant.roleName}: ${scope}`;
|
|
66
|
+
const name = Object.hasOwn(ROLES, grant.role) ? ROLES[grant.role as Role].name : grant.roleName;
|
|
67
|
+
if (grant.role === 'owner') return name;
|
|
68
|
+
return `${name}: ${grant.environmentSlug ?? 'all'}`;
|
|
81
69
|
}
|
|
82
70
|
|
|
83
71
|
export function projectAccessRoles(
|
|
@@ -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
|
+
}
|