@coffre/ui 0.15.0 → 0.16.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.
Files changed (139) hide show
  1. package/dist/audit-sentences.d.ts +56 -0
  2. package/dist/audit-sentences.js +886 -0
  3. package/dist/audit-sentences.js.map +1 -0
  4. package/dist/chunks/audit-sentence-C8NnAdjF.js +48 -0
  5. package/dist/chunks/audit-sentence-C8NnAdjF.js.map +1 -0
  6. package/dist/chunks/{connected-apps-CGUQlFMx.js → connected-apps-6sMSgQ9U.js} +5 -5
  7. package/dist/chunks/{connected-apps-CGUQlFMx.js.map → connected-apps-6sMSgQ9U.js.map} +1 -1
  8. package/dist/chunks/{delete-place-CswZ-meh.js → delete-place-T469tSN9.js} +5 -5
  9. package/dist/chunks/{delete-place-CswZ-meh.js.map → delete-place-T469tSN9.js.map} +1 -1
  10. package/dist/chunks/{directory-DrswWQLT.js → directory-B_gVf7UL.js} +18 -17
  11. package/dist/chunks/directory-B_gVf7UL.js.map +1 -0
  12. package/dist/chunks/{folders-A6sbR_PG.js → folders-CVYauIDz.js} +3 -3
  13. package/dist/chunks/{folders-A6sbR_PG.js.map → folders-CVYauIDz.js.map} +1 -1
  14. package/dist/chunks/{grants-C0cb2oii.js → grants-Dn_EW2XW.js} +8 -8
  15. package/dist/chunks/grants-Dn_EW2XW.js.map +1 -0
  16. package/dist/chunks/{multi-combobox-B3SEv1gq.js → multi-combobox-fbBRzi9z.js} +3 -3
  17. package/dist/chunks/{multi-combobox-B3SEv1gq.js.map → multi-combobox-fbBRzi9z.js.map} +1 -1
  18. package/dist/chunks/{offboarding-C1jbG_dk.js → offboarding-CXM464J_.js} +81 -80
  19. package/dist/chunks/offboarding-CXM464J_.js.map +1 -0
  20. package/dist/chunks/{page-CfhC9Hp1.js → page-Cb0ZjGda.js} +7 -12
  21. package/dist/chunks/page-Cb0ZjGda.js.map +1 -0
  22. package/dist/chunks/{personal-tokens-xC9wulhg.js → personal-tokens-CSHMlRHy.js} +7 -7
  23. package/dist/chunks/personal-tokens-CSHMlRHy.js.map +1 -0
  24. package/dist/chunks/{principal-CI17XK13.js → principal-BKJxbAtE.js} +2 -2
  25. package/dist/chunks/{principal-CI17XK13.js.map → principal-BKJxbAtE.js.map} +1 -1
  26. package/dist/chunks/{principal-page-CdSeftGD.js → principal-page-COPmTDVW.js} +132 -19
  27. package/dist/chunks/principal-page-COPmTDVW.js.map +1 -0
  28. package/dist/chunks/{project-page-CHxjBE97.js → project-page-g5_n46Nz.js} +3 -3
  29. package/dist/chunks/{project-page-CHxjBE97.js.map → project-page-g5_n46Nz.js.map} +1 -1
  30. package/dist/chunks/protected-DEWeOrmI.js +77 -0
  31. package/dist/chunks/protected-DEWeOrmI.js.map +1 -0
  32. package/dist/chunks/{queries-D1JuimTu.js → queries-D4_o-bz3.js} +22 -155
  33. package/dist/chunks/queries-D4_o-bz3.js.map +1 -0
  34. package/dist/chunks/{references-D5llUGQL.js → references-wTh_DT0M.js} +27 -23
  35. package/dist/chunks/references-wTh_DT0M.js.map +1 -0
  36. package/dist/chunks/{role-field-CoCv8wse.js → role-field-BiP09qfN.js} +5 -5
  37. package/dist/chunks/role-field-BiP09qfN.js.map +1 -0
  38. package/dist/chunks/{row-state-CYH7kZHl.js → row-state-CYhtmUkc.js} +3 -3
  39. package/dist/chunks/{row-state-CYH7kZHl.js.map → row-state-CYhtmUkc.js.map} +1 -1
  40. package/dist/chunks/{signin-errors-TlQmQe0t.js → signin-errors-BMnox7XD.js} +5 -19
  41. package/dist/chunks/signin-errors-BMnox7XD.js.map +1 -0
  42. package/dist/chunks/{theme-rF44Wbmm.js → theme-imSolE1q.js} +3 -3
  43. package/dist/chunks/{theme-rF44Wbmm.js.map → theme-imSolE1q.js.map} +1 -1
  44. package/dist/chunks/{ui-CGdORVzW.js → ui-Q_Eczt7m.js} +7 -3
  45. package/dist/chunks/{ui-CGdORVzW.js.map → ui-Q_Eczt7m.js.map} +1 -1
  46. package/dist/chunks/{use-action-BxrHTBZw.js → use-action-BfnN-De2.js} +3 -3
  47. package/dist/chunks/{use-action-BxrHTBZw.js.map → use-action-BfnN-De2.js.map} +1 -1
  48. package/dist/chunks/{use-change-BorW2R6C.js → use-change-Cc0X4sF3.js} +6 -4
  49. package/dist/chunks/use-change-Cc0X4sF3.js.map +1 -0
  50. package/dist/chunks/{use-roles-BZnJ9Cq0.js → use-roles-stcv2QFj.js} +13 -56
  51. package/dist/chunks/use-roles-stcv2QFj.js.map +1 -0
  52. package/dist/chunks/{use-shell-CPskgi1k.js → use-shell-DMhLa2sh.js} +3 -3
  53. package/dist/chunks/{use-shell-CPskgi1k.js.map → use-shell-DMhLa2sh.js.map} +1 -1
  54. package/dist/index.d.ts +23 -55
  55. package/dist/index.js +12 -31
  56. package/dist/index.js.map +1 -1
  57. package/dist/pages/account.js +12 -12
  58. package/dist/pages/account.js.map +1 -1
  59. package/dist/pages/approval.js +2 -2
  60. package/dist/pages/audit.js +173 -196
  61. package/dist/pages/audit.js.map +1 -1
  62. package/dist/pages/device-login.js +2 -2
  63. package/dist/pages/environment.js +445 -252
  64. package/dist/pages/environment.js.map +1 -1
  65. package/dist/pages/login.js +6 -15
  66. package/dist/pages/login.js.map +1 -1
  67. package/dist/pages/oauth-authorize.js +2 -2
  68. package/dist/pages/project-access.js +11 -11
  69. package/dist/pages/project-environments.js +359 -28
  70. package/dist/pages/project-environments.js.map +1 -1
  71. package/dist/pages/project-settings.js +8 -8
  72. package/dist/pages/project.js +3 -3
  73. package/dist/pages/projects.js +8 -8
  74. package/dist/pages/service-account.js +19 -16
  75. package/dist/pages/service-account.js.map +1 -1
  76. package/dist/pages/service-accounts.js +6 -7
  77. package/dist/pages/service-accounts.js.map +1 -1
  78. package/dist/pages/settings.d.ts +1 -6
  79. package/dist/pages/settings.js +155 -286
  80. package/dist/pages/settings.js.map +1 -1
  81. package/dist/pages/unregistered.js +2 -2
  82. package/dist/pages/user.js +7 -8
  83. package/dist/pages/user.js.map +1 -1
  84. package/dist/pages/users.js +6 -7
  85. package/dist/pages/users.js.map +1 -1
  86. package/package.json +8 -3
  87. package/src/components/actions-log.tsx +8 -61
  88. package/src/components/directory.tsx +10 -9
  89. package/src/components/grants.tsx +2 -2
  90. package/src/components/icons.tsx +0 -2
  91. package/src/components/offboarding.tsx +9 -16
  92. package/src/components/page.tsx +2 -3
  93. package/src/components/personal-tokens.tsx +5 -2
  94. package/src/components/principal-page.tsx +5 -4
  95. package/src/components/protected.tsx +39 -52
  96. package/src/components/references.tsx +18 -7
  97. package/src/components/role-editor.tsx +68 -99
  98. package/src/components/role-field.tsx +1 -1
  99. package/src/components/trusted-workloads.tsx +6 -5
  100. package/src/components/ui.tsx +5 -0
  101. package/src/lib/audit-proofs.ts +51 -0
  102. package/src/lib/audit-sentences.ts +490 -529
  103. package/src/lib/bindings.ts +6 -0
  104. package/src/lib/changes.ts +3 -1
  105. package/src/lib/coffre.ts +2 -2
  106. package/src/lib/queries.ts +19 -168
  107. package/src/lib/reveal.ts +32 -5
  108. package/src/lib/roles.ts +10 -36
  109. package/src/lib/row-reads.ts +2 -2
  110. package/src/lib/signin-errors.ts +5 -33
  111. package/src/options.ts +3 -19
  112. package/src/pages/account.tsx +1 -1
  113. package/src/pages/audit.tsx +151 -228
  114. package/src/pages/environment.tsx +373 -247
  115. package/src/pages/login.tsx +2 -4
  116. package/src/pages/project-environments.tsx +322 -20
  117. package/src/pages/service-accounts.tsx +1 -1
  118. package/src/pages/settings.tsx +49 -134
  119. package/src/pages/user.tsx +2 -2
  120. package/src/pages/users.tsx +1 -1
  121. package/src/parity.ts +11 -20
  122. package/src/styles/globals.css +107 -273
  123. package/dist/chunks/actions-log-DupYCEyV.js +0 -1134
  124. package/dist/chunks/actions-log-DupYCEyV.js.map +0 -1
  125. package/dist/chunks/directory-DrswWQLT.js.map +0 -1
  126. package/dist/chunks/environment-actions-8rL9Cw6X.js +0 -576
  127. package/dist/chunks/environment-actions-8rL9Cw6X.js.map +0 -1
  128. package/dist/chunks/grants-C0cb2oii.js.map +0 -1
  129. package/dist/chunks/offboarding-C1jbG_dk.js.map +0 -1
  130. package/dist/chunks/page-CfhC9Hp1.js.map +0 -1
  131. package/dist/chunks/personal-tokens-xC9wulhg.js.map +0 -1
  132. package/dist/chunks/principal-page-CdSeftGD.js.map +0 -1
  133. package/dist/chunks/queries-D1JuimTu.js.map +0 -1
  134. package/dist/chunks/references-D5llUGQL.js.map +0 -1
  135. package/dist/chunks/role-field-CoCv8wse.js.map +0 -1
  136. package/dist/chunks/signin-errors-TlQmQe0t.js.map +0 -1
  137. package/dist/chunks/use-change-BorW2R6C.js.map +0 -1
  138. package/dist/chunks/use-roles-BZnJ9Cq0.js.map +0 -1
  139. package/src/components/environment-actions.tsx +0 -508
@@ -0,0 +1,886 @@
1
+ import { INSTANCE_ROLES, ROLES, isBuiltinRole, isInstanceRole, isScope, normalDefinition, scopeInWords } from "@coffre/core/access";
2
+ import { shownMember } from "@coffre/client";
3
+ //#region src/lib/audit-sentences.ts
4
+ /**
5
+ * The audit log in sentences: who did what, to what. One entry is one
6
+ * human action, named for it (`secret.read`, `access.grant`, …); a batch of
7
+ * them, one reveal of twelve secrets, shares an operation and reads as one
8
+ * line, "ran market/prod: 12 secrets".
9
+ *
10
+ * A sentence is parts rather than a string, so the page can make the people
11
+ * and places in it links. `plain` flattens it, for tests and titles.
12
+ */
13
+ var text = (value) => typeof value === "string" && value !== "" ? value : null;
14
+ var number = (value) => typeof value === "number" ? value : null;
15
+ var list = (value) => Array.isArray(value) ? value.filter((item) => text(item) !== null) : [];
16
+ /** An object of the detail's, or an empty one for anything else. */
17
+ function record(value) {
18
+ return typeof value === "object" && value !== null && !Array.isArray(value) ? value : {};
19
+ }
20
+ /** The entry's place, as deep as it goes. */
21
+ function place(entry) {
22
+ const path = [
23
+ entry.project,
24
+ entry.environment,
25
+ entry.key
26
+ ].filter((part) => part !== null);
27
+ return path.length === 0 ? ["coffre"] : [{ place: path.join("/") }];
28
+ }
29
+ function environmentOf(entry) {
30
+ return place({
31
+ ...entry,
32
+ key: null
33
+ });
34
+ }
35
+ /** A personal config's entry by the environment it is a config of, `market/dev`: its own slug is generated, and shown nowhere else. */
36
+ function asPersonal(entry) {
37
+ const of = text(entry.metadata.personal);
38
+ return of === null || entry.project === null ? [entry, []] : [{
39
+ ...entry,
40
+ environment: of
41
+ }, [", in their personal config"]];
42
+ }
43
+ /** The member an entry is about: its subject, or the member or principal its detail names. */
44
+ function subject(entry) {
45
+ const member = entry.subject ?? text(entry.metadata.member) ?? text(entry.metadata.principal);
46
+ return member === null ? ["someone"] : [{ member }];
47
+ }
48
+ /** An entry about its actor's own credential: the principal it names is who acted. */
49
+ function own(entry) {
50
+ const actor = who(entry);
51
+ return typeof actor !== "string" && text(entry.metadata.principal) === actor.member;
52
+ }
53
+ /** An MCP client, by the host its metadata document is at; one registered by its own request names none in the entry. */
54
+ function app(entry) {
55
+ return [text(entry.metadata.host) ?? "an MCP client"];
56
+ }
57
+ /** A tool's call: its name, and what it named. */
58
+ function tool(entry) {
59
+ const names = list(entry.metadata.names);
60
+ return [text(entry.metadata.tool) ?? "a tool", ...names.length === 0 ? [] : [` on ${names.join(", ")}`]];
61
+ }
62
+ /** Why the vault itself ended a connection, said after it. */
63
+ var DISCONNECTED = {
64
+ code_reused: ": its sign-in code was used twice",
65
+ refresh_reused: ": a refresh token it had replaced was used again"
66
+ };
67
+ function plural(count, one, many = `${one}s`) {
68
+ return `${count} ${count === 1 ? one : many}`;
69
+ }
70
+ /**
71
+ * The secrets a read or write was about: one entry as its secret, a batch as
72
+ * its environment and a count. The vault logs a read where it was asked, so
73
+ * a read through a reference is the reference's, "billing/prod/DATABASE_URL
74
+ * through a reference"; its own part of the entry names the source by id
75
+ * alone (`through`), which the page cannot say as a path.
76
+ */
77
+ function secrets(facts) {
78
+ const [entry, mine] = asPersonal(facts.entry);
79
+ const referred = (entry) => text(entry.metadata.through) !== null;
80
+ if (facts.batch.length === 1) return [
81
+ ...place(entry),
82
+ ...referred(entry) ? [" through a reference"] : [],
83
+ ...mine
84
+ ];
85
+ const held = facts.batch.filter(referred).length;
86
+ return [
87
+ ...environmentOf(entry),
88
+ ": ",
89
+ plural(facts.count, "secret"),
90
+ ...held === 0 ? [] : [`, ${held} through ${held === 1 ? "a reference" : "references"}`],
91
+ ...mine
92
+ ];
93
+ }
94
+ /** "OLD in market/prod", "OLD and STALE in market/prod", or "5 keys in market/prod". */
95
+ function keysIn(entry, keys) {
96
+ const [here, mine] = asPersonal(entry);
97
+ if (keys.length === 0) return [...environmentOf(here), ...mine];
98
+ return [
99
+ keys.length > 3 ? plural(keys.length, "key") : keys.length === 1 ? keys[0] : `${keys.slice(0, -1).join(", ")} and ${keys.at(-1)}`,
100
+ " in ",
101
+ ...environmentOf(here),
102
+ ...mine
103
+ ];
104
+ }
105
+ /** A folder renamed onto its own name: nothing moved. */
106
+ var sameFolder = ({ entry }) => entry.metadata.folder === entry.metadata.to;
107
+ /** " to the folder stripe", or " out of its folder". */
108
+ function intoFolder(folder) {
109
+ return [text(folder) === null ? " out of its folder" : ` to the folder ${text(folder)}`];
110
+ }
111
+ var READ_VERBS = {
112
+ reveal: "revealed",
113
+ run: "ran",
114
+ compare: "compared",
115
+ copy: "copied",
116
+ use: "used",
117
+ expose: "was given"
118
+ };
119
+ function written({ metadata: line }) {
120
+ if (text(line.refers) !== null) return "reference";
121
+ if (number(line.restored) !== null) return "restore";
122
+ if (text(line.was) !== null && number(line.kept) !== null) return "mark";
123
+ if (number(line.version) !== null) return line.made === true ? "add" : text(line.source) !== null ? "own" : "change";
124
+ if (line.reset === true) return "reset";
125
+ if (typeof line.archived === "boolean") return line.archived ? "archive" : "unarchive";
126
+ return "folder" in line ? "move" : "change";
127
+ }
128
+ var WRITTEN = {
129
+ reference: "made",
130
+ restore: "restored",
131
+ add: "added",
132
+ own: "gave a value of its own to",
133
+ mark: "marked",
134
+ change: "changed",
135
+ reset: "reset",
136
+ archive: "archived",
137
+ unarchive: "brought back",
138
+ move: "moved"
139
+ };
140
+ /** Who sees a value written: said where it is not a secret's. */
141
+ function nature(entry) {
142
+ return entry.metadata.nature === "plain" ? [", as a plain value, no secret"] : entry.metadata.nature === "sensitive" ? [", as a sensitive value, shown to nobody"] : [];
143
+ }
144
+ /** A project's or an environment's, as `place` names it: a personal config by what it is a config of. */
145
+ function placeWhat(kind) {
146
+ return ({ entry }) => {
147
+ if (kind === "project") return ["project ", ...place({
148
+ ...entry,
149
+ environment: null,
150
+ key: null
151
+ })];
152
+ const of = text(entry.metadata.personal);
153
+ if (of !== null && entry.project !== null) return ["a personal config of ", { place: `${entry.project}/${of}` }];
154
+ if (entry.metadata.personal === true) return [`a personal config, ${text(entry.metadata.path) ?? ""}`];
155
+ return ["environment ", ...environmentOf(entry)];
156
+ };
157
+ }
158
+ /** A re-slugging, said as one where the slug changed. */
159
+ function updated(kind) {
160
+ const renamed = ({ metadata }) => text(metadata.from) !== null && metadata.from !== metadata.slug;
161
+ return {
162
+ did: ({ entry }) => renamed(entry) ? "renamed" : "changed",
163
+ what: placeWhat(kind),
164
+ then: ({ entry }) => renamed(entry) ? [`, was ${text(entry.metadata.from)}`] : []
165
+ };
166
+ }
167
+ /** Archived, restored or deleted: a deleted one is named by its tombstone from then on, `market~deleted-2026-10-05`, as every entry about it is. */
168
+ var plainly = (kind, did) => ({
169
+ did,
170
+ what: placeWhat(kind)
171
+ });
172
+ /** An environment made: a fork names the one it inherits from, a copy the one it copied. */
173
+ function created(kind) {
174
+ return {
175
+ ...plainly(kind, "created"),
176
+ then: ({ entry }) => text(entry.metadata.inherits) !== null ? [`, inheriting from ${text(entry.metadata.inherits)}`] : text(entry.metadata.from) === null ? [] : [`, a copy of ${text(entry.metadata.from)}`]
177
+ };
178
+ }
179
+ /** A grant's lines (`changes`), the first said, the others counted. */
180
+ var changesOf = ({ metadata }) => Array.isArray(metadata.changes) ? metadata.changes.map(record) : [];
181
+ /**
182
+ * A grant's sentence, and a revocation's, from what changed: the action is the
183
+ * request's (a grant if it gives any role), and its lines only what changed, a
184
+ * role given (`role`) or taken (`role: null`), each at its own place, which the
185
+ * server names the entry for (`viewOf`).
186
+ */
187
+ var accessSentence = {
188
+ did: ({ entry }) => {
189
+ const [first] = changesOf(entry);
190
+ return first === void 0 ? "set" : first.role === null ? "took" : "gave";
191
+ },
192
+ what: ({ entry }) => {
193
+ const [first] = changesOf(entry);
194
+ if (first === void 0) return [
195
+ "the access of ",
196
+ ...subject(entry),
197
+ " on ",
198
+ ...environmentOf(entry)
199
+ ];
200
+ if (first.role !== null) return [
201
+ ...subject(entry),
202
+ ` ${text(first.role) ?? "a role"} on `,
203
+ ...environmentOf(entry)
204
+ ];
205
+ const role = text(first.was);
206
+ return [
207
+ ...role === null ? ["access to "] : [`${role} on `],
208
+ ...environmentOf(entry),
209
+ " from ",
210
+ ...subject(entry)
211
+ ];
212
+ },
213
+ then: ({ entry }) => {
214
+ const [first] = changesOf(entry);
215
+ if (first === void 0) return [];
216
+ return [
217
+ ...first.role === null ? [] : [...text(first.was) === null ? [] : [`, was ${text(first.was)}`], ...text(first.expiresAt) === null ? [] : [`, until ${text(first.expiresAt).slice(0, 10)}`]],
218
+ ...others(entry),
219
+ ...entry.metadata.admitted === "member.add" ? [", added to coffre with it"] : entry.metadata.admitted === "member.restore" ? [", brought back with it"] : []
220
+ ];
221
+ },
222
+ unchanged: ({ entry }) => changesOf(entry).length === 0
223
+ };
224
+ /** The changes after a grant's first: "on 2 other places" where each gave or took what the first did; else "2 other changes". */
225
+ function others(entry) {
226
+ const [first, ...rest] = changesOf(entry);
227
+ if (first === void 0 || rest.length === 0) return [];
228
+ return [rest.every((line) => [
229
+ "role",
230
+ "was",
231
+ "expiresAt"
232
+ ].every((field) => text(line[field]) === text(first[field]))) ? `, and on ${plural(rest.length, "other place")}` : `, and ${plural(rest.length, "other change")}`];
233
+ }
234
+ /** Who a revoked credential was: a token, or a session or handle ended. */
235
+ var REVOKED = {
236
+ personal: "revoked a personal token of",
237
+ service: "revoked a bearer token of",
238
+ handle: "ended a handle of",
239
+ cli: "ended a CLI session of",
240
+ browser: "ended a browser session of",
241
+ mcp: "disconnected an MCP app of"
242
+ };
243
+ /** A CLI sign-in's label, as its CLI named it: `, “laptop”`. */
244
+ var labelled = ({ entry }) => text(entry.metadata.label) === null ? [] : [`, “${text(entry.metadata.label)}”`];
245
+ /** A trust binding's keys replaced, rather than a binding made. */
246
+ var rekeyed = ({ entry }) => entry.metadata.reason === "keys_replaced";
247
+ /** The profiles whose tokens are CI runs'; every other binding trusts a workload. */
248
+ var CI_PROFILES = [
249
+ "github",
250
+ "github-reusable",
251
+ "github-reusable-organization",
252
+ "gitlab"
253
+ ];
254
+ /** Whom a binding trusts, by its profile: CI runs, a platform's workloads, or a custom issuer's tokens. */
255
+ function trusted({ metadata }) {
256
+ const profile = text(metadata.profile) ?? "custom";
257
+ if (CI_PROFILES.includes(profile)) return "CI runs";
258
+ return profile === "custom" ? `tokens from ${text(metadata.issuer) ?? "an issuer"}` : `${profile} workloads`;
259
+ }
260
+ /** What a freeze is on: the whole instance, a service account's workloads, a binding's or a session. */
261
+ function frozen({ entry }) {
262
+ const target = text(entry.metadata.target);
263
+ if (target === null) return ["workloads"];
264
+ if (target === "instance") return ["every workload"];
265
+ if (target.startsWith("token:")) return ["the workloads of ", { member: target }];
266
+ return [target.startsWith("binding:") ? "the workloads of a trust binding of " : "a workload session of ", ...subject(entry)];
267
+ }
268
+ /** A write that wrote no key: asked of keys as they were already (a nature they had, archived already, filed where they are). The entry records none of what was asked. */
269
+ var empty = ({ metadata }) => Array.isArray(metadata.keys) && metadata.keys.length === 0;
270
+ /** A write's sentence, and a loosening's: one key as what was done to it; a batch as what was done to every key, or as written. */
271
+ var writeSentence = {
272
+ did: ({ entry, batch }) => {
273
+ if (empty(entry)) return "wrote to";
274
+ const kinds = new Set(batch.map(written));
275
+ if (batch.length === 1 || kinds.size === 1 && !kinds.has("reference") && !kinds.has("own")) return WRITTEN[written(entry)];
276
+ return [...kinds].every((kind) => kind === "add" || kind === "change") ? "wrote" : "changed";
277
+ },
278
+ what: (facts) => empty(facts.entry) ? keysIn(facts.entry, []) : [...secrets(facts), ...facts.batch.length === 1 && written(facts.entry) === "reference" ? [" a reference"] : []],
279
+ then: ({ entry, batch }) => {
280
+ if (empty(entry)) return [];
281
+ const kind = written(entry);
282
+ const folder = entry.metadata.folder;
283
+ if (kind === "move" && batch.every((other) => written(other) === "move" && other.metadata.folder === folder)) return intoFolder(folder);
284
+ if (batch.length > 1) return [];
285
+ if (kind === "restore") return [` to version ${number(entry.metadata.restored)}`, ...entry.version === null ? [] : [`, now ${entry.version}`]];
286
+ if (kind === "mark") return [` ${text(entry.metadata.nature) ?? ""}, from ${text(entry.metadata.was) ?? ""}, its value kept`];
287
+ return kind === "add" || kind === "change" || kind === "own" ? [...(entry.version ?? 1) === 1 ? [] : [`, now version ${entry.version}`], ...nature(entry)] : [];
288
+ },
289
+ unchanged: ({ entry }) => empty(entry)
290
+ };
291
+ var TEMPLATES = {
292
+ "secret.read": {
293
+ did: ({ entry }) => READ_VERBS[text(entry.metadata.purpose) ?? "reveal"] ?? READ_VERBS.reveal,
294
+ what: secrets
295
+ },
296
+ "secret.write": writeSentence,
297
+ "secret.loosen": writeSentence,
298
+ "secret.rename": {
299
+ did: "renamed",
300
+ what: ({ entry }) => {
301
+ const [here, mine] = asPersonal(entry);
302
+ return [
303
+ ...place({
304
+ ...here,
305
+ key: text(entry.metadata.key) ?? entry.key
306
+ }),
307
+ ...text(entry.metadata.to) === null ? [] : [` to ${text(entry.metadata.to)}`],
308
+ ...mine
309
+ ];
310
+ },
311
+ then: ({ entry }) => {
312
+ const [own, ...rest] = changesOf(entry).map((line) => text(line.environment));
313
+ const forks = new Set(rest.filter((environment) => environment !== null && environment !== own)).size;
314
+ return forks === 0 ? [] : [`, and in ${plural(forks, "fork")}`];
315
+ },
316
+ unchanged: ({ entry }) => text(entry.metadata.to) === text(entry.metadata.key)
317
+ },
318
+ "secret.refile": {
319
+ did: "moved",
320
+ what: ({ entry }) => keysIn(entry, list(entry.metadata.keys)),
321
+ then: ({ entry }) => intoFolder(entry.metadata.to),
322
+ unchanged: sameFolder
323
+ },
324
+ "reference.break": {
325
+ did: "broke",
326
+ what: ({ entry }) => ["the reference ", ...place(entry)]
327
+ },
328
+ "missing.dismiss": {
329
+ did: ({ entry }) => list(entry.metadata.dismissed).length > 0 ? "dismissed" : list(entry.metadata.restored).length > 0 ? "restored" : "set which missing keys are dismissed in",
330
+ what: ({ entry }) => {
331
+ const dismissed = list(entry.metadata.dismissed);
332
+ const restored = list(entry.metadata.restored);
333
+ if (dismissed.length === 0 && restored.length === 0) return keysIn(entry, []);
334
+ return keysIn(entry, dismissed.length > 0 ? dismissed : restored);
335
+ },
336
+ then: ({ entry }) => {
337
+ const dismissed = list(entry.metadata.dismissed);
338
+ const restored = list(entry.metadata.restored);
339
+ if (dismissed.length === 0) return restored.length === 0 ? [] : [" to the missing keys"];
340
+ return [" as not needed", ...restored.length === 0 ? [] : [`, and restored ${restored.length > 3 ? plural(restored.length, "key") : restored.join(", ")} to the missing keys`]];
341
+ },
342
+ unchanged: ({ entry }) => list(entry.metadata.dismissed).length === 0 && list(entry.metadata.restored).length === 0
343
+ },
344
+ "project.create": created("project"),
345
+ "project.update": updated("project"),
346
+ "project.archive": plainly("project", "archived"),
347
+ "project.restore": plainly("project", "restored"),
348
+ "project.delete": plainly("project", "deleted"),
349
+ "project.move": {
350
+ ...plainly("project", "moved"),
351
+ then: ({ entry }) => intoFolder(entry.metadata.to),
352
+ unchanged: ({ entry }) => entry.metadata.from === entry.metadata.to
353
+ },
354
+ "folder.refile": {
355
+ did: ({ entry }) => text(entry.metadata.to) === null ? "emptied" : "renamed",
356
+ what: ({ entry }) => [text(entry.metadata.folder) === null ? "a folder" : `the folder ${text(entry.metadata.folder)}`],
357
+ then: ({ entry }) => [...text(entry.metadata.to) === null ? [] : [` to ${text(entry.metadata.to)}`], `, ${plural(list(entry.metadata.projects).length, "project")}`],
358
+ unchanged: sameFolder
359
+ },
360
+ "environment.create": created("environment"),
361
+ "environment.update": updated("environment"),
362
+ "environment.archive": plainly("environment", "archived"),
363
+ "environment.restore": plainly("environment", "restored"),
364
+ "environment.delete": plainly("environment", "deleted"),
365
+ "environment.protect": {
366
+ did: "protected",
367
+ what: ({ entry }) => environmentOf(entry)
368
+ },
369
+ "environment.unprotect": {
370
+ did: "unprotected",
371
+ what: ({ entry }) => environmentOf(entry)
372
+ },
373
+ "upstream.freeze": {
374
+ did: "froze the upstream credential",
375
+ what: ({ entry }) => [`${text(entry.metadata.upstream) ?? ""} in `, ...environmentOf(entry)]
376
+ },
377
+ "upstream.thaw": {
378
+ did: "unfroze the upstream credential",
379
+ what: ({ entry }) => [`${text(entry.metadata.upstream) ?? ""} in `, ...environmentOf(entry)]
380
+ },
381
+ "access.grant": accessSentence,
382
+ "access.revoke": accessSentence,
383
+ "member.add": {
384
+ did: "added",
385
+ what: ({ entry }) => [...subject(entry), ...asRole(entry)]
386
+ },
387
+ "member.restore": {
388
+ did: "brought back",
389
+ what: ({ entry }) => [...subject(entry), ...asRole(entry)]
390
+ },
391
+ "member.remove": {
392
+ did: "removed",
393
+ what: (facts) => subject(facts.entry),
394
+ then: ({ entry }) => Array.isArray(entry.metadata.revoked) && entry.metadata.revoked.length > 0 ? [`, who held ${plural(entry.metadata.revoked.length, "grant")}`] : []
395
+ },
396
+ "member.role": {
397
+ did: "made",
398
+ what: ({ entry }) => [
399
+ ...subject(entry),
400
+ ` ${article(roleName(text(entry.metadata.role) ?? "member") ?? "Member")}`,
401
+ ...scoped(entry)
402
+ ]
403
+ },
404
+ "settings.change": {
405
+ did: "set",
406
+ what: ({ entry }) => ["where people set up service accounts", ...setting(entry.metadata.serviceAccounts).map((words) => `: ${words}`)],
407
+ then: ({ entry }) => setting(entry.metadata.was).map((words) => `, was ${words}`)
408
+ },
409
+ "policy.change": {
410
+ did: ({ entry }) => policyOf(entry).verb,
411
+ what: ({ entry }) => policyOf(entry).what
412
+ },
413
+ "token.bind": {
414
+ did: (facts) => rekeyed(facts) ? "replaced the keys of" : `trusted ${trusted(facts.entry)} to sign in as`,
415
+ what: (facts) => [...rekeyed(facts) ? [`${plural(Array.isArray(facts.entry.metadata.bindings) ? facts.entry.metadata.bindings.length : 0, "trust binding")} of `] : [], ...subject(facts.entry)],
416
+ then: (facts) => rekeyed(facts) ? [] : [...inGitHubEnvironment(facts.entry), ...reaching(facts.entry)]
417
+ },
418
+ "token.unbind": {
419
+ did: "removed a trust binding of",
420
+ what: (facts) => subject(facts.entry)
421
+ },
422
+ "workload.freeze": {
423
+ did: "froze",
424
+ what: frozen,
425
+ then: ({ entry }) => text(entry.metadata.reason) === null ? [] : [`: ${text(entry.metadata.reason)}`]
426
+ },
427
+ "workload.unfreeze": {
428
+ did: "unfroze",
429
+ what: frozen
430
+ },
431
+ "mcp.connect": {
432
+ did: "connected",
433
+ what: ({ entry }) => app(entry)
434
+ },
435
+ "mcp.ask": {
436
+ did: "was asked by an MCP client for",
437
+ what: ({ entry }) => tool(entry)
438
+ },
439
+ "mcp.approve": {
440
+ did: "approved",
441
+ what: ({ entry }) => tool(entry)
442
+ },
443
+ "mcp.deny": {
444
+ did: "turned down",
445
+ what: ({ entry }) => tool(entry)
446
+ },
447
+ "mcp.disconnect": {
448
+ did: "disconnected",
449
+ what: ({ entry }) => [...app(entry), ...entry.actorType === "system" && text(entry.metadata.principal) !== null ? [" of ", ...subject(entry)] : []],
450
+ then: ({ entry }) => [DISCONNECTED[text(entry.metadata.reason) ?? ""] ?? ""]
451
+ },
452
+ "upkeep.expire": {
453
+ did: "removed what had lapsed",
454
+ what: () => []
455
+ },
456
+ "vault.adopt": {
457
+ did: ({ entry }) => entry.metadata.archive == null ? "started the log" : "took over the 0.14 database",
458
+ what: () => [],
459
+ then: ({ entry }) => number(record(entry.metadata.archive).seq) === null ? [] : [`, its log archived through entry ${number(record(entry.metadata.archive).seq)}`]
460
+ },
461
+ sign_in: {
462
+ did: ({ entry }) => entry.metadata.kind === "cli" ? "signed in to the CLI" : "signed in",
463
+ what: ({ entry }) => text(entry.metadata.provider) === null ? [] : [`with ${text(entry.metadata.provider)}`],
464
+ then: ({ entry }) => entry.metadata.owner === "made" ? [", made an Owner: the deployment names them one"] : entry.metadata.owner === "restored" ? [", brought back as an Owner: the deployment names them one"] : []
465
+ },
466
+ sign_out: {
467
+ did: "signed out",
468
+ what: () => []
469
+ },
470
+ "token.create": {
471
+ did: ({ entry }) => entry.metadata.kind === "handle" ? "made a handle" : entry.metadata.kind === "personal" ? "made a personal token" : "issued a bearer token to",
472
+ what: ({ entry }) => entry.metadata.kind === "handle" || entry.metadata.kind === "personal" ? [] : subject(entry),
473
+ then: ({ entry }) => reaching(entry)
474
+ },
475
+ "token.revoke": {
476
+ did: ({ entry }) => REVOKED[text(entry.metadata.kind) ?? ""] ?? "revoked a token of",
477
+ what: ({ entry }) => own(entry) ? ["their own"] : subject(entry)
478
+ },
479
+ "device.start": {
480
+ did: "was asked for a CLI sign-in",
481
+ what: () => [],
482
+ then: labelled
483
+ },
484
+ "device.approve": {
485
+ did: "approved a CLI sign-in",
486
+ what: () => [],
487
+ then: labelled
488
+ },
489
+ "device.deny": {
490
+ did: "turned down a CLI sign-in",
491
+ what: () => [],
492
+ then: labelled
493
+ },
494
+ "token.exchange": {
495
+ did: ({ entry }) => entry.metadata.kind === "workload" ? "started a workload session" : "signed in for a CI run",
496
+ what: () => []
497
+ },
498
+ "workload.renew": {
499
+ did: "renewed its workload session",
500
+ what: () => []
501
+ },
502
+ "oauth.register": {
503
+ did: "registered an MCP client",
504
+ what: () => []
505
+ },
506
+ "mcp.token": {
507
+ did: ({ entry }) => entry.metadata.grant === "refresh_token" ? "refreshed the tokens of" : "gave its first tokens to",
508
+ what: ({ entry }) => app(entry)
509
+ },
510
+ "account.link": {
511
+ did: "linked",
512
+ what: ({ entry }) => [`a ${text(entry.metadata.provider) ?? "sign-in"} account`]
513
+ },
514
+ "account.unlink": {
515
+ did: "unlinked",
516
+ what: ({ entry }) => [`a ${text(entry.metadata.provider) ?? "sign-in"} account`]
517
+ }
518
+ };
519
+ /** An instance role's name, from its slug; null for none it knows. */
520
+ function roleName(role) {
521
+ return isInstanceRole(role) ? INSTANCE_ROLES[role].name : null;
522
+ }
523
+ /**
524
+ * A `policy.change` entry, from its role, its `definition` and the one it
525
+ * replaced (`was`): a built-in role put back as it ships is a reset; one
526
+ * an Owner made, gone, a deletion; one that was not there, made.
527
+ *
528
+ * edited the Developer role made the Release manager role
529
+ * reset the Auditor instance role deleted the Release manager role
530
+ */
531
+ function policyOf(entry) {
532
+ const instance = entry.metadata.instance === true;
533
+ const id = text(entry.metadata.role);
534
+ const shipped = id === null ? null : instance ? isInstanceRole(id) ? INSTANCE_ROLES[id] : null : isBuiltinRole(id) ? ROLES[id] : null;
535
+ const definition = entry.metadata.definition === null ? null : record(entry.metadata.definition);
536
+ const name = text(definition?.name) ?? text(record(entry.metadata.was).name) ?? shipped?.name ?? id;
537
+ return {
538
+ verb: definition === null ? "deleted" : shipped !== null && JSON.stringify(definition) === JSON.stringify(normalDefinition(shipped)) ? "reset" : entry.metadata.was === null ? "made" : "edited",
539
+ what: [name === null ? "a role" : `the ${name} ${instance ? "instance role" : "role"}`]
540
+ };
541
+ }
542
+ function article(name) {
543
+ return `${/^[AEIOU]/.test(name) ? "an" : "a"} ${name}`;
544
+ }
545
+ /** Whether an entry's scope narrows the role; its projects are ids, which a sentence cannot name. */
546
+ function scoped(entry) {
547
+ const scope = entry.metadata.scope;
548
+ return scope == null || scope.projects === "all" && scope.environments === "all" ? [] : [", with a scope"];
549
+ }
550
+ /**
551
+ * What a token or binding reaches, its scope, each role with the places it
552
+ * holds, counted, as the log names them by id: `, reaching developer on 2 places`.
553
+ */
554
+ function reaching(entry, none = "") {
555
+ const scope = entry.metadata.scope;
556
+ if (!Array.isArray(scope)) return [];
557
+ if (scope.length === 0) return none === "" ? [] : [none];
558
+ const byRole = /* @__PURE__ */ new Map();
559
+ for (const grant of scope) {
560
+ const role = text(grant.role);
561
+ if (role !== null) byRole.set(role, (byRole.get(role) ?? 0) + 1);
562
+ }
563
+ return [`, reaching ${[...byRole].map(([role, count]) => `${role} on ${plural(count, "place")}`).join(", ")}`];
564
+ }
565
+ /** The GitHub environment a binding takes its runs from, when it names one. */
566
+ function inGitHubEnvironment(entry) {
567
+ const environment = text(entry.metadata.claims?.environment);
568
+ return environment === null || !String(entry.metadata.profile).startsWith("github") ? [] : [`, in GitHub environment ${environment}`];
569
+ }
570
+ /**
571
+ * The setting of where people set up service accounts, in words: its
572
+ * projects counted, as the log names them by id, its environments by name.
573
+ *
574
+ * All projects · all but prod 2 projects · dev only
575
+ */
576
+ function setting(scope) {
577
+ if (!isScope(scope)) return [];
578
+ const { projects } = scope;
579
+ return [scopeInWords(projects === "all" ? scope : {
580
+ ...scope,
581
+ projects: "only" in projects ? { only: [plural(projects.only.length, "project")] } : { except: [plural(projects.except.length, "project")] }
582
+ })];
583
+ }
584
+ /** The role a member is added or brought back with, said when it is more than Member. */
585
+ function asRole(entry) {
586
+ const role = roleName(text(entry.metadata.role) ?? "");
587
+ return role === null || role === "Member" ? [] : [` as ${article(role)}`, ...scoped(entry)];
588
+ }
589
+ /**
590
+ * A refused change in words, after "tried to": its kind alone. The vault
591
+ * logs a refusal once a minute per caller and action (D236), so one entry
592
+ * stands for every one refused them that minute, each asking its own key,
593
+ * kind or direction: none of those is the entry's to say.
594
+ */
595
+ var TRIED = {
596
+ "secret.read": "read secrets",
597
+ "secret.write": "write secrets",
598
+ "secret.loosen": "make a sensitive value secret in place",
599
+ "secret.rename": "rename a key",
600
+ "secret.refile": "move keys between folders",
601
+ "reference.break": "break a reference",
602
+ "missing.dismiss": "change which missing keys are dismissed",
603
+ "project.create": "create a project",
604
+ "project.update": "change a project",
605
+ "project.archive": "archive a project",
606
+ "project.restore": "restore a project",
607
+ "project.move": "move a project between folders",
608
+ "project.delete": "delete a project",
609
+ "folder.refile": "change a folder",
610
+ "environment.create": "create an environment",
611
+ "environment.update": "change an environment",
612
+ "environment.archive": "archive an environment",
613
+ "environment.restore": "restore an environment",
614
+ "environment.delete": "delete an environment",
615
+ "environment.protect": "protect an environment",
616
+ "environment.unprotect": "unprotect an environment",
617
+ "upstream.freeze": "freeze an upstream credential",
618
+ "upstream.thaw": "unfreeze an upstream credential",
619
+ "member.add": "change a membership",
620
+ "member.restore": "change a membership",
621
+ "member.role": "change a member's instance role",
622
+ "member.remove": "remove a member",
623
+ "access.grant": "change access",
624
+ "access.revoke": "take away access",
625
+ "policy.change": "change a role",
626
+ "settings.change": "change where people set up service accounts",
627
+ sign_in: "sign in",
628
+ sign_out: "sign out",
629
+ "token.create": "issue a credential",
630
+ "token.revoke": "end a credential",
631
+ "account.link": "link a sign-in account",
632
+ "account.unlink": "unlink a sign-in account",
633
+ "device.start": "start a CLI sign-in",
634
+ "device.approve": "approve a CLI sign-in",
635
+ "device.deny": "turn down a CLI sign-in",
636
+ "token.exchange": "start a session from a CI run or a workload",
637
+ "workload.renew": "renew a workload session",
638
+ "token.bind": "change a trust binding",
639
+ "token.unbind": "remove a trust binding",
640
+ "workload.freeze": "freeze workloads",
641
+ "workload.unfreeze": "unfreeze workloads",
642
+ "mcp.connect": "connect an MCP client",
643
+ "mcp.token": "get tokens for an MCP client",
644
+ "mcp.disconnect": "disconnect an MCP client",
645
+ "oauth.register": "register an MCP client",
646
+ "mcp.ask": "ask for a change through MCP",
647
+ "mcp.approve": "approve a change asked through MCP",
648
+ "mcp.deny": "turn down a change asked through MCP",
649
+ "upkeep.expire": "remove what had lapsed",
650
+ "vault.adopt": "take over the database"
651
+ };
652
+ /**
653
+ * A refused entry's sentence: what kind of change, where the entry's own
654
+ * rows put it (its project and environment, never a name the caller asked
655
+ * for), and why. "tried to rename a key at market/dev: no access".
656
+ */
657
+ function refusal(entry) {
658
+ return [
659
+ "tried to ",
660
+ Object.hasOwn(TRIED, entry.action) ? TRIED[entry.action] : entry.action,
661
+ ...entry.project === null ? [] : [" at ", { place: [entry.project, entry.environment].filter((part) => part !== null).join("/") }],
662
+ `: ${reasonInWords(entry.reason)}`
663
+ ];
664
+ }
665
+ /** Why something was refused, in words. Codes from the vault and the app. */
666
+ var REASONS = {
667
+ no_grant: "no grant",
668
+ bulk_limit: "bulk limit",
669
+ stand_ins: "people get placeholders",
670
+ sensitive: "the value is sensitive",
671
+ looser: "making it visible takes a new value",
672
+ not_owner: "only an Owner of the project does it in place",
673
+ inherited: "it is inherited",
674
+ expired: "grant expired",
675
+ removed: "removed from coffre",
676
+ not_a_member: "not a member",
677
+ not_registered: "not invited",
678
+ tampered: "their record was tampered with",
679
+ bad_claim: "the key did not match the secret",
680
+ deleted: "the place was deleted",
681
+ not_allowed: "not allowed",
682
+ root_admin: "root admins are set by the deployment",
683
+ last_owner: "they are the last Owner of the whole instance",
684
+ requires_instance_admin: "requires an admin or owner of the whole instance",
685
+ requires_instance_owner: "requires an instance owner",
686
+ own_role: "nobody changes their own role",
687
+ own_grant: "nobody grants themselves a role",
688
+ service_cannot_hold_role: "service accounts hold project grants only",
689
+ not_service_manager: "they hold less than the service account, or than they gave it",
690
+ unknown_environment: "no such environment",
691
+ unknown_secret: "no such secret",
692
+ no_value: "it holds no value",
693
+ unknown_project: "no such project",
694
+ not_archived: "it was not archived",
695
+ referenced: "references read it",
696
+ kms_unavailable: "KMS did not answer",
697
+ wrong_kek: "the vault's key is not the one that wrapped the data",
698
+ person_denied: "they said no",
699
+ too_many_connections: "too many connected apps",
700
+ unknown_connection: "no such connected app",
701
+ not_yours: "it was someone else's",
702
+ too_many_approvals: "too many changes waiting for approval",
703
+ request_state: "its retry did not match its call",
704
+ changed: "the change was not the one shown",
705
+ replaced: "what it replaces changed since it was shown",
706
+ unconfirmed: "what it replaces could not be read",
707
+ disconnected: "the app was disconnected",
708
+ personal_token: "only its person can, signed in as themselves",
709
+ beyond_holder: "more than they hold",
710
+ role_granted: "grants still name it"
711
+ };
712
+ /** What a missing permission meant, from the app's `missing_<permission>`. */
713
+ var MISSING = {
714
+ secret_read: "no grant to read it",
715
+ secret_write: "no grant to write",
716
+ secret_archive: "no grant to archive",
717
+ audit_read: "no grant to read the audit log",
718
+ environment_manage: "no grant to manage environments",
719
+ grant_manage: "no grant to manage access",
720
+ project_manage: "no grant to manage the project"
721
+ };
722
+ function reasonInWords(reason) {
723
+ if (reason === null) return "refused";
724
+ if (reason.startsWith("missing_")) return MISSING[reason.slice(8)] ?? "no grant";
725
+ return REASONS[reason] ?? reason.replace(/_/g, " ");
726
+ }
727
+ /** In a batch of mixed actions, the one its line says first: a write, then its reads, then the rest. */
728
+ var LEAD = [
729
+ "secret.write",
730
+ "secret.loosen",
731
+ "secret.read"
732
+ ];
733
+ function leadOf(batch) {
734
+ for (const action of LEAD) {
735
+ const found = batch.find((entry) => entry.action === action);
736
+ if (found !== void 0) return found;
737
+ }
738
+ return batch[0];
739
+ }
740
+ /**
741
+ * A read, logged once for every key it released, or a write, once for
742
+ * every key it wrote, as the entries it would be about one key each: its
743
+ * key and version, and its own part of the detail (`keys`: a read's
744
+ * `{ key, secret, version, through? }`, a write's line), such as the
745
+ * reference it went through. Any other entry as it is.
746
+ */
747
+ function perSecret(entry) {
748
+ const listed = entry.metadata.keys;
749
+ const released = entry.secrets ?? [{
750
+ key: entry.key,
751
+ version: entry.version
752
+ }];
753
+ if (![
754
+ "secret.read",
755
+ "secret.write",
756
+ "secret.loosen"
757
+ ].includes(entry.action) || !Array.isArray(listed) || released.length === 0 || listed.length !== released.length) return [entry];
758
+ return released.map(({ key, version }, i) => {
759
+ const own = listed[i];
760
+ return {
761
+ ...entry,
762
+ key,
763
+ version,
764
+ secrets: null,
765
+ metadata: {
766
+ ...entry.metadata,
767
+ keys: void 0,
768
+ ...typeof own === "object" && own !== null && !Array.isArray(own) ? own : {}
769
+ }
770
+ };
771
+ });
772
+ }
773
+ /**
774
+ * What a line says: one entry, or a batch that shares an operation. A batch
775
+ * of several actions says each, the lead's first ("revealed market/prod/API_KEY;
776
+ * approved show_secret_value"), and is refused only if each of them was.
777
+ */
778
+ function describe(batch) {
779
+ const said = [.../* @__PURE__ */ new Set([leadOf(batch).action, ...batch.map((entry) => entry.action)])].map((action) => describeAction(batch.filter((entry) => entry.action === action)));
780
+ return {
781
+ parts: said.flatMap((one, i) => i === 0 ? one.parts : ["; ", ...one.parts]),
782
+ refused: said.every((one) => one.refused)
783
+ };
784
+ }
785
+ /** A batch of one action in words. */
786
+ function describeAction(batch) {
787
+ const lead = perSecret(batch[0])[0];
788
+ const same = batch.flatMap(perSecret);
789
+ const allowed = same.filter((other) => other.decision !== "deny");
790
+ const denied = same.filter((other) => other.decision === "deny");
791
+ const refused = allowed.length === 0;
792
+ if (refused) return {
793
+ parts: refusal(lead),
794
+ refused
795
+ };
796
+ const entry = allowed[0];
797
+ const facts = {
798
+ entry,
799
+ batch: allowed,
800
+ count: new Set(allowed.map((other) => `${other.project}/${other.environment}/${other.key}`)).size
801
+ };
802
+ const template = Object.hasOwn(TEMPLATES, entry.action) ? TEMPLATES[entry.action] : void 0;
803
+ if (template === void 0) return {
804
+ parts: [
805
+ entry.action,
806
+ " ",
807
+ ...place(entry)
808
+ ],
809
+ refused
810
+ };
811
+ const what = template.what(facts);
812
+ const gap = what.length === 0 ? [] : [" "];
813
+ const partly = denied.length === 0 ? [] : [`, ${denied.length} refused: ${reasonInWords(denied[0].reason)}`];
814
+ const unchanged = entry.metadata.unchanged === true || template.unchanged?.(facts) === true ? [", unchanged"] : [];
815
+ const approved = text(entry.metadata.via) === null ? [] : [", approved through MCP"];
816
+ return {
817
+ parts: [
818
+ typeof template.did === "string" ? template.did : template.did(facts),
819
+ ...gap,
820
+ ...what,
821
+ ...template.then?.(facts) ?? [],
822
+ ...unchanged,
823
+ ...approved,
824
+ ...partly
825
+ ],
826
+ refused
827
+ };
828
+ }
829
+ /** Who acted, as a part: a member links to their page; coffre itself is text. */
830
+ function who(entry) {
831
+ if (entry.actorType === "user") return { member: `user:${entry.actorId}` };
832
+ if (entry.actorType === "service") return { member: `token:${entry.actorId}` };
833
+ return SYSTEM[entry.actorId] ?? entry.actorId;
834
+ }
835
+ var SYSTEM = {
836
+ scheduler: "the scheduler",
837
+ cron: "the scheduler",
838
+ vault: "the vault",
839
+ app: "coffre",
840
+ "coffre-key-rotation": "coffre"
841
+ };
842
+ /** Which components wrote the line, the vault first: "vault", "app", "vault, app". */
843
+ function decidedBy(batch) {
844
+ return ["vault", "app"].filter((author) => batch.some((entry) => entry.author === author)).join(", ");
845
+ }
846
+ /**
847
+ * Entries in the order the page shows them, newest first, each batch as one
848
+ * line at its newest entry. The server leaves detail out unless asked.
849
+ */
850
+ function lines(entries) {
851
+ const shown = [];
852
+ const batches = /* @__PURE__ */ new Map();
853
+ for (const entry of entries) {
854
+ const batch = entry.operationId === null ? void 0 : batches.get(entry.operationId);
855
+ if (batch !== void 0) {
856
+ batch.push(entry);
857
+ continue;
858
+ }
859
+ const fresh = [entry];
860
+ if (entry.operationId !== null) batches.set(entry.operationId, fresh);
861
+ shown.push(fresh);
862
+ }
863
+ return shown;
864
+ }
865
+ /** A sentence as text. */
866
+ function plain(parts) {
867
+ return parts.map((part) => typeof part === "string" ? part : "place" in part ? part.place : part.member.startsWith("user:") ? part.member.slice(5) : shownMember(part.member)).join("");
868
+ }
869
+ /**
870
+ * The CI run an entry was written for, as its issuer stated it at the
871
+ * exchange: `acme/api run 7001 at 3f2a9c1`, a GitLab pipeline, or the
872
+ * token's subject. Null for an entry no trust binding's credential wrote.
873
+ */
874
+ function runLabel(run) {
875
+ if (run === null) return null;
876
+ const { claims } = run;
877
+ const text = (name) => typeof claims[name] === "string" || typeof claims[name] === "number" ? String(claims[name]) : null;
878
+ const at = text("sha") === null ? "" : ` at ${text("sha").slice(0, 7)}`;
879
+ if (text("repository") !== null && text("run_id") !== null) return `${text("repository")} run ${text("run_id")}${at}`;
880
+ if (text("project_path") !== null && text("pipeline_id") !== null) return `${text("project_path")} pipeline ${text("pipeline_id")}${at}`;
881
+ return text("sub") === null ? "a CI run" : `CI run ${text("sub")}`;
882
+ }
883
+ //#endregion
884
+ export { decidedBy, describe, leadOf, lines, perSecret, plain, reasonInWords, runLabel, who };
885
+
886
+ //# sourceMappingURL=audit-sentences.js.map