@coffre/ui 0.6.1 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (119) hide show
  1. package/dist/chunks/{audit-sentence-CUUMshIp.js → audit-sentence-C1_gRxWW.js} +91 -26
  2. package/dist/chunks/audit-sentence-C1_gRxWW.js.map +1 -0
  3. package/dist/chunks/{connected-apps-DTpatjge.js → connected-apps-Bn5rEoV2.js} +4 -4
  4. package/dist/chunks/{connected-apps-DTpatjge.js.map → connected-apps-Bn5rEoV2.js.map} +1 -1
  5. package/dist/chunks/{delete-place-SOOYVt6A.js → delete-place-CQCDHkne.js} +4 -4
  6. package/dist/chunks/{delete-place-SOOYVt6A.js.map → delete-place-CQCDHkne.js.map} +1 -1
  7. package/dist/chunks/{directory-DrtdKny2.js → directory-BQNOdze_.js} +22 -19
  8. package/dist/chunks/directory-BQNOdze_.js.map +1 -0
  9. package/dist/chunks/{folders-hR2Lnk0k.js → folders-Dw240WMJ.js} +2 -2
  10. package/dist/chunks/{folders-hR2Lnk0k.js.map → folders-Dw240WMJ.js.map} +1 -1
  11. package/dist/chunks/{grants-DDBui9YD.js → grants-CJIBrkod.js} +5 -5
  12. package/dist/chunks/{grants-DDBui9YD.js.map → grants-CJIBrkod.js.map} +1 -1
  13. package/dist/chunks/multi-combobox-CsIXihuc.js +99 -0
  14. package/dist/chunks/multi-combobox-CsIXihuc.js.map +1 -0
  15. package/dist/chunks/{offboarding-C7ECW5o0.js → offboarding-CrgwaetA.js} +4 -4
  16. package/dist/chunks/offboarding-CrgwaetA.js.map +1 -0
  17. package/dist/chunks/personal-tokens-B8rkT-DI.js +138 -0
  18. package/dist/chunks/personal-tokens-B8rkT-DI.js.map +1 -0
  19. package/dist/chunks/{principal-page-CB6dAABC.js → principal-page-DDmmV1KQ.js} +37 -27
  20. package/dist/chunks/principal-page-DDmmV1KQ.js.map +1 -0
  21. package/dist/chunks/{project-page-BHNUvr2L.js → project-page-BI--vjt3.js} +2 -2
  22. package/dist/chunks/{project-page-BHNUvr2L.js.map → project-page-BI--vjt3.js.map} +1 -1
  23. package/dist/chunks/{queries-DgQo3mC-.js → queries-epz4MIuW.js} +103 -18
  24. package/dist/chunks/queries-epz4MIuW.js.map +1 -0
  25. package/dist/chunks/{references-BQc35Q9g.js → references-DImfw0cz.js} +4 -4
  26. package/dist/chunks/{references-BQc35Q9g.js.map → references-DImfw0cz.js.map} +1 -1
  27. package/dist/chunks/{role-field-BfWRCqzl.js → role-field-C1KhNaIR.js} +2 -2
  28. package/dist/chunks/{role-field-BfWRCqzl.js.map → role-field-C1KhNaIR.js.map} +1 -1
  29. package/dist/chunks/{row-state-Zf3kZVhd.js → row-state-BsIHspy4.js} +2 -2
  30. package/dist/chunks/{row-state-Zf3kZVhd.js.map → row-state-BsIHspy4.js.map} +1 -1
  31. package/dist/chunks/{theme-B6-V9JvY.js → theme-3b4DnCow.js} +2 -2
  32. package/dist/chunks/{theme-B6-V9JvY.js.map → theme-3b4DnCow.js.map} +1 -1
  33. package/dist/chunks/{ui-Br-dNUTc.js → ui-2kwXXfrX.js} +95 -22
  34. package/dist/chunks/ui-2kwXXfrX.js.map +1 -0
  35. package/dist/chunks/{use-action-DthL5hL8.js → use-action-BB-RcHo1.js} +2 -2
  36. package/dist/chunks/{use-action-DthL5hL8.js.map → use-action-BB-RcHo1.js.map} +1 -1
  37. package/dist/chunks/{use-change-By4cG8bT.js → use-change-CQyDpCqw.js} +323 -31
  38. package/dist/chunks/use-change-CQyDpCqw.js.map +1 -0
  39. package/dist/chunks/{use-shell-D6kjSPls.js → use-shell-C_NmvCt_.js} +2 -2
  40. package/dist/chunks/{use-shell-D6kjSPls.js.map → use-shell-C_NmvCt_.js.map} +1 -1
  41. package/dist/index.d.ts +46 -164
  42. package/dist/index.js +143 -129
  43. package/dist/index.js.map +1 -1
  44. package/dist/pages/account.d.ts +1 -1
  45. package/dist/pages/account.js +29 -12
  46. package/dist/pages/account.js.map +1 -1
  47. package/dist/pages/approval.js +1 -1
  48. package/dist/pages/audit.js +96 -90
  49. package/dist/pages/audit.js.map +1 -1
  50. package/dist/pages/device-login.js +1 -1
  51. package/dist/pages/environment.js +949 -412
  52. package/dist/pages/environment.js.map +1 -1
  53. package/dist/pages/login.js +2 -2
  54. package/dist/pages/oauth-authorize.js +1 -1
  55. package/dist/pages/project-access.js +9 -9
  56. package/dist/pages/project-access.js.map +1 -1
  57. package/dist/pages/project-environments.js +112 -64
  58. package/dist/pages/project-environments.js.map +1 -1
  59. package/dist/pages/project-settings.d.ts +1 -1
  60. package/dist/pages/project-settings.js +54 -75
  61. package/dist/pages/project-settings.js.map +1 -1
  62. package/dist/pages/project.js +3 -7
  63. package/dist/pages/project.js.map +1 -1
  64. package/dist/pages/projects.js +50 -77
  65. package/dist/pages/projects.js.map +1 -1
  66. package/dist/pages/service-account.js +284 -160
  67. package/dist/pages/service-account.js.map +1 -1
  68. package/dist/pages/service-accounts.js +4 -4
  69. package/dist/pages/settings.js +5 -5
  70. package/dist/pages/unregistered.js +1 -1
  71. package/dist/pages/user.js +5 -5
  72. package/dist/pages/users.js +4 -4
  73. package/package.json +3 -3
  74. package/src/components/actions-log.tsx +3 -2
  75. package/src/components/command-palette.tsx +4 -5
  76. package/src/components/directory.tsx +7 -14
  77. package/src/components/generate-value.tsx +15 -7
  78. package/src/components/missing.tsx +63 -67
  79. package/src/components/offboarding.tsx +1 -1
  80. package/src/components/personal-tokens.tsx +131 -0
  81. package/src/components/principal-page.tsx +30 -17
  82. package/src/components/regenerate.tsx +72 -0
  83. package/src/components/service-tokens.tsx +5 -14
  84. package/src/components/shell.tsx +79 -75
  85. package/src/components/trusted-workloads.tsx +179 -19
  86. package/src/components/ui.tsx +35 -25
  87. package/src/lib/audit-sentences.ts +100 -12
  88. package/src/lib/bindings.ts +41 -3
  89. package/src/lib/changes.ts +215 -29
  90. package/src/lib/clipboard.ts +40 -0
  91. package/src/lib/copy-attempts.ts +103 -0
  92. package/src/lib/dismissal.ts +24 -0
  93. package/src/lib/generate.ts +3 -146
  94. package/src/lib/optimistic.ts +3 -1
  95. package/src/lib/queries.ts +121 -17
  96. package/src/lib/recipes.ts +63 -0
  97. package/src/lib/reveal.ts +7 -1
  98. package/src/lib/row-reads.ts +64 -0
  99. package/src/lib/secret-edit-batch.ts +64 -5
  100. package/src/options.ts +43 -51
  101. package/src/pages/account.tsx +27 -5
  102. package/src/pages/audit.tsx +38 -31
  103. package/src/pages/environment.tsx +655 -121
  104. package/src/pages/project-access.tsx +1 -1
  105. package/src/pages/project-environments.tsx +92 -45
  106. package/src/pages/project-settings.tsx +9 -20
  107. package/src/pages/project.tsx +1 -5
  108. package/src/pages/projects.tsx +13 -28
  109. package/src/parity.ts +20 -4
  110. package/src/styles/globals.css +143 -131
  111. package/dist/chunks/audit-sentence-CUUMshIp.js.map +0 -1
  112. package/dist/chunks/directory-DrtdKny2.js.map +0 -1
  113. package/dist/chunks/offboarding-C7ECW5o0.js.map +0 -1
  114. package/dist/chunks/principal-page-CB6dAABC.js.map +0 -1
  115. package/dist/chunks/project-environments-lEzFHUt4.js +0 -11
  116. package/dist/chunks/project-environments-lEzFHUt4.js.map +0 -1
  117. package/dist/chunks/queries-DgQo3mC-.js.map +0 -1
  118. package/dist/chunks/ui-Br-dNUTc.js.map +0 -1
  119. package/dist/chunks/use-change-By4cG8bT.js.map +0 -1
@@ -1,10 +1,11 @@
1
- import { useEffect, useRef, useState, type ReactElement, type ReactNode } from 'react';
1
+ import { useEffect, useRef, useState, useSyncExternalStore, type ReactElement, type ReactNode } from 'react';
2
2
  import { AlertDialog } from '@base-ui/react/alert-dialog';
3
3
  import { Dialog } from '@base-ui/react/dialog';
4
4
  import { Menu } from '@base-ui/react/menu';
5
5
  import { Popover } from '@base-ui/react/popover';
6
6
  import { Tooltip } from '@base-ui/react/tooltip';
7
7
  import { AlertCircle, AlertTriangle, Check, Copy, Info, Loader, X } from './icons';
8
+ import { createCopier, type Copier } from '../lib/copy-attempts';
8
9
  import { usePreferences } from '../lib/preferences';
9
10
 
10
11
  /* -------------------------------------------------------------------------- */
@@ -240,47 +241,55 @@ export function breakAfterUnderscores(text: string): ReactNode {
240
241
  *
241
242
  * The glyph turns into a check, and screen readers hear "Copied", for 1.4s --
242
243
  * long enough to be noticed after the eye has moved on, short enough not to
243
- * look stuck.
244
+ * look stuck. A copy that fails says so the same way, in red, rather than
245
+ * leaving the click looking ignored.
246
+ *
247
+ * `value` is the text. A caller that must read it first (Copy on a hidden
248
+ * secret) passes the `copier` it owns instead, and `onCopy`, called inside the
249
+ * click so the clipboard write keeps its user gesture, which starts a copy on
250
+ * that copier. Copies do not lock the button: a click while one is out starts
251
+ * the next, and the latest one's ending is the one that shows. The copier's
252
+ * owner outlives the button, so a remount keeps the feedback of a copy in flight.
244
253
  */
245
254
  export function CopyButton({
246
- value,
247
255
  label = 'Copy',
248
256
  variant = 'icon',
257
+ ...source
249
258
  }: {
250
- value: string;
251
259
  label?: string;
252
260
  /** `act` sits among a table row's actions; `icon` anywhere else. */
253
261
  variant?: 'icon' | 'act';
254
- }) {
255
- const [copied, setCopied] = useState(false);
256
- const timer = useRef<ReturnType<typeof setTimeout> | null>(null);
257
-
258
- useEffect(() => () => {
259
- if (timer.current !== null) clearTimeout(timer.current);
260
- }, []);
261
-
262
- async function copy() {
263
- try {
264
- await navigator.clipboard.writeText(value);
265
- } catch {
266
- return; // Clipboard denied; say nothing rather than claim success.
267
- }
268
- setCopied(true);
269
- if (timer.current !== null) clearTimeout(timer.current);
270
- timer.current = setTimeout(() => setCopied(false), 1400);
262
+ } & ({ value: string; copier?: undefined; onCopy?: undefined } | { value?: undefined; copier: Copier; onCopy: () => void })) {
263
+ const [own] = useState(() => createCopier());
264
+ const copier = source.copier ?? own;
265
+ const state = useSyncExternalStore(copier.subscribe, copier.feedback, copier.feedback);
266
+
267
+ function copy() {
268
+ if (source.copier !== undefined) source.onCopy();
269
+ else void own.run(source.value);
271
270
  }
272
271
 
272
+ const text = state === 'copied' ? 'Copied' : state === 'failed' ? 'Copy failed' : label;
273
273
  return (
274
- <Tip label={copied ? 'Copied' : label}>
274
+ <Tip label={text}>
275
275
  <button
276
276
  type="button"
277
277
  className={variant === 'act' ? 'act act-icon' : 'btn btn-quiet btn-sm btn-icon'}
278
278
  aria-label={label}
279
+ aria-busy={state === 'pending'}
279
280
  onClick={copy}
280
281
  >
281
- {copied ? <Check size={14} className="copied" /> : <Copy size={14} />}
282
+ {state === 'pending' ? (
283
+ <Spinner size={13} />
284
+ ) : state === 'copied' ? (
285
+ <Check size={14} className="copied" />
286
+ ) : state === 'failed' ? (
287
+ <AlertCircle size={14} className="copy-failed" />
288
+ ) : (
289
+ <Copy size={14} />
290
+ )}
282
291
  <span className="visually-hidden" aria-live="polite">
283
- {copied ? 'Copied' : ''}
292
+ {state === 'copied' ? 'Copied' : state === 'failed' ? 'Copy failed' : ''}
284
293
  </span>
285
294
  </button>
286
295
  </Tip>
@@ -430,7 +439,8 @@ function relative(iso: string, now: number, style: 'long' | 'narrow' = 'long'):
430
439
  return formatter.format(Math.round(delta / divisor), unit);
431
440
  }
432
441
 
433
- function absolute(iso: string, precise: boolean): string {
442
+ /** A UTC time as the log writes it: `2026-10-17 08:45:13`, to the millisecond when `precise`. */
443
+ export function absolute(iso: string, precise: boolean): string {
434
444
  return iso.replace('T', ' ').replace('Z', '').slice(0, precise ? 23 : 19);
435
445
  }
436
446
 
@@ -26,6 +26,7 @@ export type AuditEntry = Pick<
26
26
  | 'environment'
27
27
  | 'key'
28
28
  | 'version'
29
+ | 'secrets'
29
30
  | 'operationId'
30
31
  | 'metadata'
31
32
  >;
@@ -42,7 +43,7 @@ export type Sentence = { parts: Part[]; refused: boolean };
42
43
  /** What one template needs: the line's leading entry, its batch, and how it was decided. */
43
44
  type Facts = {
44
45
  entry: AuditEntry;
45
- /** Every entry of the batch, the lead included. */
46
+ /** Every entry of the batch, the lead included, a read of several once per secret (`perSecret`). */
46
47
  batch: AuditEntry[];
47
48
  /** Secrets the batch was about. */
48
49
  count: number;
@@ -83,6 +84,17 @@ function subject(entry: AuditEntry): Part[] {
83
84
  return [{ member: `${entry.metadata.principalType === 'service' ? 'token' : 'user'}:${id}` }];
84
85
  }
85
86
 
87
+ /** Whether a token entry is about a personal token, which acts as its person, rather than a service account's. */
88
+ function personal(entry: AuditEntry): boolean {
89
+ return entry.metadata.kind === 'personal';
90
+ }
91
+
92
+ /** A personal token's label, as it was made: ` "cursor-agent"`. */
93
+ function labelled(entry: AuditEntry): Part[] {
94
+ const label = text(entry.metadata.label);
95
+ return label === null ? [] : [` “${label}”`];
96
+ }
97
+
86
98
  /** Why the vault made someone an Owner itself, said after it. */
87
99
  function owned(entry: AuditEntry): Part[] {
88
100
  return entry.metadata.reason === 'owners' ? [': the deployment names them one'] : [];
@@ -122,22 +134,34 @@ function plural(count: number, one: string, many = `${one}s`): string {
122
134
  * The secrets a read or write was about. A read through a reference is a
123
135
  * read of its source, "market/prod/DATABASE_URL through
124
136
  * billing/prod/DATABASE_URL"; a run that read some that way is a run of
125
- * the environment that holds them.
137
+ * the environment that holds them. A value a fork inherits is its parent's,
138
+ * read in the fork: "market/prod/STRIPE_KEY in market/prod-eu".
126
139
  */
127
140
  function secrets(facts: Facts): Part[] {
128
141
  const through = (entry: AuditEntry) => text((entry.metadata.via as { path?: unknown } | undefined)?.path);
142
+ // The fork a value was inherited in, by path: in its parent's project, which holds the reference a read went through.
143
+ const forkOf = (entry: AuditEntry) => {
144
+ const slug = text((entry.metadata.through as { slug?: unknown } | undefined)?.slug);
145
+ const project = through(entry)?.split('/')[0] ?? entry.project;
146
+ return slug === null || project === null ? null : `${project}/${slug}`;
147
+ };
129
148
  if (facts.batch.length === 1) {
130
- const held = through(facts.entry);
131
- return held === null ? place(facts.entry) : [...place(facts.entry), ' through ', { place: held }];
149
+ const [held, fork] = [through(facts.entry), forkOf(facts.entry)];
150
+ return [...place(facts.entry), ...(held === null ? [] : [' through ', { place: held }]), ...(fork === null ? [] : [' in ', { place: fork }])];
132
151
  }
133
- const own = facts.batch.find((entry) => through(entry) === null);
152
+ const fork = facts.batch.map(forkOf).find((path) => path !== null);
153
+ const own = facts.batch.find((entry) => through(entry) === null && forkOf(entry) === null);
134
154
  const held = facts.batch.map(through).filter((path): path is string => path !== null);
135
- const where = own !== undefined ? environmentOf(own) : [{ place: held[0]!.split('/').slice(0, 2).join('/') }];
155
+ const inherited = facts.batch.filter((entry) => forkOf(entry) !== null).length;
156
+ const where = fork !== undefined && fork !== null
157
+ ? [{ place: fork }]
158
+ : own !== undefined ? environmentOf(own) : [{ place: held[0]!.split('/').slice(0, 2).join('/') }];
136
159
  return [
137
160
  ...where,
138
161
  facts.refused ? ', ' : ': ',
139
162
  plural(facts.count, 'secret'),
140
163
  ...(held.length === 0 ? [] : [`, ${held.length} through ${held.length === 1 ? 'a reference' : 'references'}`]),
164
+ ...(inherited === 0 ? [] : [`, ${inherited} inherited`]),
141
165
  ];
142
166
  }
143
167
 
@@ -177,14 +201,29 @@ function readVerb({ entry }: Facts): [string, string] {
177
201
  }
178
202
 
179
203
  const placeTemplates = (kind: 'project' | 'environment'): Record<string, Template> => {
180
- const what = (facts: Facts): Part[] => [`${kind} `, ...(kind === 'project' ? place({ ...facts.entry, environment: null, key: null }) : environmentOf(facts.entry))];
204
+ // A personal config by what it is a config of, `market/dev`: its own slug is generated, and shown nowhere else.
205
+ const of = (entry: AuditEntry): string | null => {
206
+ const parent = text(entry.metadata.personal) ?? text(entry.metadata.with);
207
+ return parent === null || entry.project === null ? null : `${entry.project}/${parent}`;
208
+ };
209
+ const what = (facts: Facts): Part[] => {
210
+ const personal = kind === 'environment' ? of(facts.entry) : null;
211
+ if (personal !== null) return ['a personal config of ', { place: personal }];
212
+ if (kind === 'environment' && facts.entry.metadata.personal === true) return [`a personal config, ${text(facts.entry.metadata.path) ?? ''}`];
213
+ return [`${kind} `, ...(kind === 'project' ? place({ ...facts.entry, environment: null, key: null }) : environmentOf(facts.entry))];
214
+ };
181
215
  return {
182
216
  [`${kind}.create`]: {
183
217
  did: 'created',
184
218
  tried: 'create',
185
219
  what,
186
220
  // A fork names the environment it copied.
187
- then: ({ entry }) => (text(entry.metadata.from) === null ? [] : [`, a fork of ${text(entry.metadata.from)}`]),
221
+ then: ({ entry }) =>
222
+ text(entry.metadata.inherits) !== null
223
+ ? [`, inheriting from ${text(entry.metadata.inherits)}`]
224
+ : text(entry.metadata.from) === null
225
+ ? []
226
+ : [`, a fork of ${text(entry.metadata.from)}`],
188
227
  },
189
228
  [`${kind}.update`]: { did: 'changed', tried: 'change', what },
190
229
  [`${kind}.archive`]: { did: 'archived', tried: 'archive', what },
@@ -223,8 +262,17 @@ const TEMPLATES: Record<string, Template> = {
223
262
  did: 'renamed',
224
263
  tried: 'rename',
225
264
  what: ({ entry }) => [...place(entry), ...(text(entry.metadata.nextKey) === null ? [] : [` to ${text(entry.metadata.nextKey)}`])],
265
+ // In a fork, carried down from a rename in its parent.
266
+ then: ({ entry }) => (text(entry.metadata.parent) === null ? [] : [`, as ${text(entry.metadata.parent)} did`]),
226
267
  },
227
268
  'secret.archive': { did: 'archived', tried: 'archive', what: ({ entry }) => archivedKeys(entry) },
269
+ // In a fork: its own value set aside, kept, for its parent's.
270
+ 'secret.reset': {
271
+ did: 'reset',
272
+ tried: 'reset',
273
+ what: ({ entry }) => place(entry),
274
+ then: ({ entry }) => (text(entry.metadata.from) === null ? [] : [` to ${text(entry.metadata.from)}'s value`]),
275
+ },
228
276
  'missing.dismiss': {
229
277
  did: 'dismissed',
230
278
  tried: 'dismiss',
@@ -388,8 +436,24 @@ const TEMPLATES: Record<string, Template> = {
388
436
  what: ({ entry }) => (text(entry.metadata.provider) === null ? [] : [`with ${text(entry.metadata.provider)}`]),
389
437
  },
390
438
  sign_out: { did: 'signed out', tried: 'sign out', what: () => [] },
391
- 'token.create': { did: 'issued a bearer token to', tried: 'issue a bearer token to', what: (facts) => subject(facts.entry), then: ({ entry }) => reaching(entry) },
392
- 'token.revoke': { did: 'revoked a bearer token of', tried: 'revoke a bearer token of', what: (facts) => subject(facts.entry) },
439
+ // A personal token is its person's own, and named by its label; a bearer token is a service account's.
440
+ 'token.create': {
441
+ did: ({ entry }) => (personal(entry) ? 'made a personal token' : 'issued a bearer token to'),
442
+ tried: ({ entry }) => (personal(entry) ? 'make a personal token' : 'issue a bearer token to'),
443
+ what: ({ entry }) => (personal(entry) ? labelled(entry) : subject(entry)),
444
+ then: ({ entry }) => reaching(entry),
445
+ },
446
+ 'token.revoke': {
447
+ did: ({ entry }) => (personal(entry) ? 'revoked a personal token of' : 'revoked a bearer token of'),
448
+ tried: ({ entry }) => (personal(entry) ? 'revoke a personal token of' : 'revoke a bearer token of'),
449
+ what: (facts) => subject(facts.entry),
450
+ },
451
+ // A personal token refused a route only its person reaches: the route, as the API names it.
452
+ 'token.use': {
453
+ did: 'used a personal token for',
454
+ tried: 'use a personal token for',
455
+ what: ({ entry }) => [text(entry.metadata.route) ?? 'something'],
456
+ },
393
457
  'device.approve': { did: 'approved a CLI sign-in', tried: 'approve a CLI sign-in', what: () => [] },
394
458
  'device.deny': { did: 'turned down a CLI sign-in', tried: 'turn down a CLI sign-in', what: () => [] },
395
459
  'mcp.read': { did: 'used', tried: 'use', what: ({ entry }) => tool(entry), then: ({ entry }) => via(entry) },
@@ -555,6 +619,8 @@ const REASONS: Record<string, string> = {
555
619
  replaced: 'what it replaces changed since it was shown',
556
620
  unconfirmed: 'what it replaces could not be read',
557
621
  disconnected: 'the app was disconnected',
622
+ personal_token: 'only its person can, signed in as themselves',
623
+ beyond_holder: 'more than they hold',
558
624
  };
559
625
 
560
626
  /** What a missing permission meant, from the app's `missing_<permission>`. */
@@ -587,10 +653,32 @@ export function leadOf(batch: AuditEntry[]): AuditEntry {
587
653
  return batch[0]!;
588
654
  }
589
655
 
656
+ /**
657
+ * A read of several secrets, logged once for its place, as the entries it
658
+ * would be about one secret each: its key and version, and what its own
659
+ * part of the metadata says, such as the reference it went through. Any
660
+ * other entry as it is.
661
+ */
662
+ export function perSecret<T extends AuditEntry>(entry: T): T[] {
663
+ const listed = entry.metadata.secrets;
664
+ // One whose list was emptied or mangled, which verification would flag, still reads as itself.
665
+ if (entry.secrets === null || entry.secrets.length === 0 || !Array.isArray(listed)) return [entry];
666
+ return entry.secrets.map(({ key, version }, i) => {
667
+ const own = listed[i];
668
+ return {
669
+ ...entry,
670
+ key,
671
+ version,
672
+ secrets: null,
673
+ metadata: { ...entry.metadata, secrets: undefined, ...(typeof own === 'object' && own !== null && !Array.isArray(own) ? own : {}) },
674
+ };
675
+ });
676
+ }
677
+
590
678
  /** What a line says: one entry, or a batch that shares an operation. */
591
679
  export function describe(batch: AuditEntry[]): Sentence {
592
- const entry = leadOf(batch);
593
- const same = batch.filter((other) => other.action === entry.action);
680
+ const entry = perSecret(leadOf(batch))[0]!;
681
+ const same = batch.filter((other) => other.action === entry.action).flatMap(perSecret);
594
682
  const denied = same.filter((other) => other.decision === 'deny');
595
683
  const refused = denied.length === same.length;
596
684
  const facts: Facts = {
@@ -27,7 +27,16 @@ export function summary(binding: Pick<BindingView, 'profile' | 'issuer' | 'claim
27
27
  if (binding.profile === 'gitlab') {
28
28
  return { title: `GitLab project ${claims.project_id}`, detail: `${claimValues(binding.claims.pipeline_source).join(', ')} at ${claims.ref_type} ${claims.ref}` };
29
29
  }
30
- return { title: new URL(binding.issuer).host, detail: `sub ${claims.sub}` };
30
+ return { title: issuerName(binding.issuer), detail: `sub ${claims.sub}` };
31
+ }
32
+
33
+ /** An issuer as a title: its host, when it is a URL; a binding that carries its keys may name any string. */
34
+ function issuerName(issuer: string): string {
35
+ try {
36
+ return new URL(issuer).host || issuer;
37
+ } catch {
38
+ return issuer;
39
+ }
31
40
  }
32
41
 
33
42
  /**
@@ -80,6 +89,8 @@ export const EMPTY_FORM = {
80
89
  issuer: '',
81
90
  sub: '',
82
91
  extra: '',
92
+ // Its keys, a JWKS pasted, for an issuer coffre cannot fetch them from; empty, they are fetched.
93
+ jwks: '',
83
94
  };
84
95
 
85
96
  export type Form = typeof EMPTY_FORM;
@@ -176,7 +187,10 @@ export function lookupFailure(name: string, failure: unknown): GitHubLookup {
176
187
  * server checks the rest. A GitHub binding takes its IDs, and its
177
188
  * repository's name as GitHub spells it, from `found`, unless typed in.
178
189
  */
179
- export function bindingOf(form: Form, found: GitHubIds | null = null): { profile: BindingPlan['profile']; issuer: string | null; claims: BindingClaims } {
190
+ export function bindingOf(
191
+ form: Form,
192
+ found: GitHubIds | null = null,
193
+ ): { profile: BindingPlan['profile']; issuer: string | null; claims: BindingClaims; jwks?: KeySet } {
180
194
  const needed = (value: string, what: string) => {
181
195
  if (value.trim() === '') throw new Error(`${what} is needed`);
182
196
  return value.trim();
@@ -240,6 +254,30 @@ export function bindingOf(form: Form, found: GitHubIds | null = null): { profile
240
254
  if (at <= 0) throw new Error(`"${line}" is not <claim>=<value>`);
241
255
  claims[line.slice(0, at).trim()] = line.slice(at + 1).trim();
242
256
  }
243
- return { profile: 'custom', issuer: needed(form.issuer, 'The issuer'), claims };
257
+ const jwks = keySetOf(form.jwks);
258
+ return { profile: 'custom', issuer: needed(form.issuer, 'The issuer'), claims, ...(jwks === undefined ? {} : { jwks }) };
259
+ }
260
+
261
+ /** A JWKS, as the API takes it: each key the server checks. */
262
+ export type KeySet = { keys: Record<string, unknown>[] };
263
+
264
+ /** The key set pasted in a field, or undefined for none; throws a sentence when it is not one. */
265
+ export function keySetOf(text: string): KeySet | undefined {
266
+ if (text.trim() === '') return undefined;
267
+ let value: unknown;
268
+ try {
269
+ value = JSON.parse(text);
270
+ } catch {
271
+ throw new Error('The keys are not JSON: paste the issuer\'s key set, { "keys": [ … ] }');
272
+ }
273
+ const keys = (value as { keys?: unknown } | null)?.keys;
274
+ if (!Array.isArray(keys)) throw new Error('The keys are a key set, { "keys": [ … ] }, as kubectl get --raw /openid/v1/jwks prints it');
275
+ return { keys: keys as Record<string, unknown>[] };
276
+ }
277
+
278
+ /** Where a binding's keys come from, in a line: the URL coffre fetches, or the keys uploaded with it, by `kid` or thumbprint. */
279
+ export function keysOf(binding: Pick<BindingPlan, 'jwksUri' | 'keys'>): string {
280
+ if (binding.keys === null) return binding.jwksUri;
281
+ return `Uploaded: ${binding.keys.map((key) => `${key.kid ?? key.thumbprint} (${key.alg})`).join(', ')}`;
244
282
  }
245
283