@coffre/ui 0.8.2 → 0.10.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 (92) hide show
  1. package/dist/chunks/{audit-sentence-C_wMpAqr.js → audit-sentence-Bjhg00cn.js} +73 -6
  2. package/dist/chunks/audit-sentence-Bjhg00cn.js.map +1 -0
  3. package/dist/chunks/{connected-apps-Bn5rEoV2.js → connected-apps-CZI7xxUq.js} +2 -2
  4. package/dist/chunks/{connected-apps-Bn5rEoV2.js.map → connected-apps-CZI7xxUq.js.map} +1 -1
  5. package/dist/chunks/{delete-place-CQCDHkne.js → delete-place-D3UQGl3b.js} +3 -3
  6. package/dist/chunks/{delete-place-CQCDHkne.js.map → delete-place-D3UQGl3b.js.map} +1 -1
  7. package/dist/chunks/{directory-BQNOdze_.js → directory-CyHmxYP-.js} +9 -7
  8. package/dist/chunks/directory-CyHmxYP-.js.map +1 -0
  9. package/dist/chunks/{grants-CJIBrkod.js → grants-CEIdNqJU.js} +4 -4
  10. package/dist/chunks/{grants-CJIBrkod.js.map → grants-CEIdNqJU.js.map} +1 -1
  11. package/dist/chunks/{offboarding-CrgwaetA.js → offboarding-CvGgTmHi.js} +2 -2
  12. package/dist/chunks/{offboarding-CrgwaetA.js.map → offboarding-CvGgTmHi.js.map} +1 -1
  13. package/dist/chunks/{personal-tokens-B8rkT-DI.js → personal-tokens-BX97oX4a.js} +2 -2
  14. package/dist/chunks/{personal-tokens-B8rkT-DI.js.map → personal-tokens-BX97oX4a.js.map} +1 -1
  15. package/dist/chunks/{principal-page-Cv5PheS9.js → principal-page-Bp2O8kIW.js} +92 -76
  16. package/dist/chunks/principal-page-Bp2O8kIW.js.map +1 -0
  17. package/dist/chunks/{project-page-BI--vjt3.js → project-page-CUXV4FDR.js} +2 -2
  18. package/dist/chunks/{project-page-BI--vjt3.js.map → project-page-CUXV4FDR.js.map} +1 -1
  19. package/dist/chunks/protected-YYW3U-Sq.js +22 -0
  20. package/dist/chunks/protected-YYW3U-Sq.js.map +1 -0
  21. package/dist/chunks/{queries-epz4MIuW.js → queries-DEOPOpsT.js} +27 -3
  22. package/dist/chunks/queries-DEOPOpsT.js.map +1 -0
  23. package/dist/chunks/{references-DImfw0cz.js → references-DsXkt064.js} +3 -3
  24. package/dist/chunks/{references-DImfw0cz.js.map → references-DsXkt064.js.map} +1 -1
  25. package/dist/chunks/{role-field-C1KhNaIR.js → role-field-CCUeZd1a.js} +8 -5
  26. package/dist/chunks/role-field-CCUeZd1a.js.map +1 -0
  27. package/dist/chunks/{use-action-BB-RcHo1.js → use-action-COW-XFw8.js} +2 -2
  28. package/dist/chunks/{use-action-BB-RcHo1.js.map → use-action-COW-XFw8.js.map} +1 -1
  29. package/dist/chunks/{use-change-CQyDpCqw.js → use-change-hfqE7baE.js} +231 -66
  30. package/dist/chunks/use-change-hfqE7baE.js.map +1 -0
  31. package/dist/chunks/use-roles-C_Tj5wBH.js +224 -0
  32. package/dist/chunks/use-roles-C_Tj5wBH.js.map +1 -0
  33. package/dist/chunks/{use-shell-C_NmvCt_.js → use-shell-DBLG80kk.js} +2 -2
  34. package/dist/chunks/{use-shell-C_NmvCt_.js.map → use-shell-DBLG80kk.js.map} +1 -1
  35. package/dist/index.d.ts +9 -3
  36. package/dist/index.js +25 -11
  37. package/dist/index.js.map +1 -1
  38. package/dist/pages/account.js +6 -6
  39. package/dist/pages/audit.js +2 -2
  40. package/dist/pages/environment.js +306 -96
  41. package/dist/pages/environment.js.map +1 -1
  42. package/dist/pages/login.js +1 -1
  43. package/dist/pages/project-access.js +78 -45
  44. package/dist/pages/project-access.js.map +1 -1
  45. package/dist/pages/project-environments.js +77 -28
  46. package/dist/pages/project-environments.js.map +1 -1
  47. package/dist/pages/project-settings.js +6 -6
  48. package/dist/pages/project.js +1 -1
  49. package/dist/pages/projects.js +23 -11
  50. package/dist/pages/projects.js.map +1 -1
  51. package/dist/pages/service-account.js +19 -12
  52. package/dist/pages/service-account.js.map +1 -1
  53. package/dist/pages/service-accounts.js +4 -4
  54. package/dist/pages/settings.js +580 -8
  55. package/dist/pages/settings.js.map +1 -1
  56. package/dist/pages/unregistered.js +1 -1
  57. package/dist/pages/user.js +5 -5
  58. package/dist/pages/users.js +4 -4
  59. package/package.json +3 -3
  60. package/src/components/directory.tsx +5 -2
  61. package/src/components/grants.tsx +1 -1
  62. package/src/components/principal-page.tsx +38 -23
  63. package/src/components/protected.tsx +17 -0
  64. package/src/components/role-editor.tsx +582 -0
  65. package/src/components/role-field.tsx +7 -3
  66. package/src/components/scope-picker.tsx +19 -9
  67. package/src/components/shell.tsx +7 -1
  68. package/src/lib/access-plan.ts +35 -36
  69. package/src/lib/audit-sentences.ts +75 -6
  70. package/src/lib/changes.ts +48 -6
  71. package/src/lib/project-access.ts +4 -78
  72. package/src/lib/queries.ts +16 -0
  73. package/src/lib/roles.ts +201 -0
  74. package/src/lib/row-reads.ts +12 -0
  75. package/src/lib/secret-edit-batch.ts +162 -26
  76. package/src/lib/sensitivity.ts +50 -0
  77. package/src/lib/service-setup.ts +20 -8
  78. package/src/lib/use-roles.ts +17 -0
  79. package/src/pages/environment.tsx +295 -61
  80. package/src/pages/project-access.tsx +49 -19
  81. package/src/pages/project-environments.tsx +62 -3
  82. package/src/pages/projects.tsx +3 -1
  83. package/src/pages/settings.tsx +2 -0
  84. package/src/parity.ts +41 -4
  85. package/src/shared/models.ts +2 -9
  86. package/src/styles/globals.css +329 -4
  87. package/dist/chunks/audit-sentence-C_wMpAqr.js.map +0 -1
  88. package/dist/chunks/directory-BQNOdze_.js.map +0 -1
  89. package/dist/chunks/principal-page-Cv5PheS9.js.map +0 -1
  90. package/dist/chunks/queries-epz4MIuW.js.map +0 -1
  91. package/dist/chunks/role-field-C1KhNaIR.js.map +0 -1
  92. package/dist/chunks/use-change-CQyDpCqw.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"use-action-BB-RcHo1.js","names":[],"sources":["../../src/lib/use-action.ts"],"sourcesContent":["import { useQueryClient, type QueryKey } from '@tanstack/react-query';\nimport { useState } from 'react';\n\nimport { failureMessage } from './coffre';\nimport { refresh } from './queries';\n\n/**\n * Run a change against the API, then refetch what it touched. A failed call\n * leaves the page as it was and says why, in `error`.\n *\n * Each change names what it touches (`affects` in `lib/queries.ts`), and\n * those queries are refetched before the change counts as done: at once where\n * they are on screen, such as the sidebar's project tree, and on next use\n * where they are not. So your own change always shows, and nothing else is\n * asked for again.\n */\nexport function useAction() {\n const queryClient = useQueryClient();\n const [pending, setPending] = useState(false);\n const [error, setError] = useState<string | null>(null);\n\n async function run<T>(\n fn: () => Promise<T>,\n {\n affects,\n onSuccess,\n }: {\n affects: QueryKey[] | ((result: T) => QueryKey[]);\n // `unknown` rather than `void`, so a one-expression callback can end in\n // `toast.success(...)` -- which returns an id -- without a block body.\n onSuccess?: (result: T) => unknown;\n },\n ): Promise<void> {\n setPending(true);\n let result: T;\n try {\n result = await fn();\n } catch (failure) {\n setError(failureMessage(failure));\n setPending(false);\n return;\n }\n\n setError(null);\n try {\n await refresh(queryClient, typeof affects === 'function' ? affects(result) : affects);\n await onSuccess?.(result);\n } catch {\n setError('The change was saved, but the page could not refresh. Reload before you retry.');\n }\n setPending(false);\n }\n\n return { pending, error, setError, run };\n}\n"],"mappings":";;;;;;;;;;;;;;;AAgBA,SAAgB,YAAY;CAC1B,MAAM,cAAc,eAAe;CACnC,MAAM,CAAC,SAAS,cAAc,SAAS,KAAK;CAC5C,MAAM,CAAC,OAAO,YAAY,SAAwB,IAAI;CAEtD,eAAe,IACb,IACA,EACE,SACA,aAOa;EACf,WAAW,IAAI;EACf,IAAI;EACJ,IAAI;GACF,SAAS,MAAM,GAAG;EACpB,SAAS,SAAS;GAChB,SAAS,eAAe,OAAO,CAAC;GAChC,WAAW,KAAK;GAChB;EACF;EAEA,SAAS,IAAI;EACb,IAAI;GACF,MAAM,QAAQ,aAAa,OAAO,YAAY,aAAa,QAAQ,MAAM,IAAI,OAAO;GACpF,MAAM,YAAY,MAAM;EAC1B,QAAQ;GACN,SAAS,gFAAgF;EAC3F;EACA,WAAW,KAAK;CAClB;CAEA,OAAO;EAAE;EAAS;EAAO;EAAU;CAAI;AACzC"}
1
+ {"version":3,"file":"use-action-COW-XFw8.js","names":[],"sources":["../../src/lib/use-action.ts"],"sourcesContent":["import { useQueryClient, type QueryKey } from '@tanstack/react-query';\nimport { useState } from 'react';\n\nimport { failureMessage } from './coffre';\nimport { refresh } from './queries';\n\n/**\n * Run a change against the API, then refetch what it touched. A failed call\n * leaves the page as it was and says why, in `error`.\n *\n * Each change names what it touches (`affects` in `lib/queries.ts`), and\n * those queries are refetched before the change counts as done: at once where\n * they are on screen, such as the sidebar's project tree, and on next use\n * where they are not. So your own change always shows, and nothing else is\n * asked for again.\n */\nexport function useAction() {\n const queryClient = useQueryClient();\n const [pending, setPending] = useState(false);\n const [error, setError] = useState<string | null>(null);\n\n async function run<T>(\n fn: () => Promise<T>,\n {\n affects,\n onSuccess,\n }: {\n affects: QueryKey[] | ((result: T) => QueryKey[]);\n // `unknown` rather than `void`, so a one-expression callback can end in\n // `toast.success(...)` -- which returns an id -- without a block body.\n onSuccess?: (result: T) => unknown;\n },\n ): Promise<void> {\n setPending(true);\n let result: T;\n try {\n result = await fn();\n } catch (failure) {\n setError(failureMessage(failure));\n setPending(false);\n return;\n }\n\n setError(null);\n try {\n await refresh(queryClient, typeof affects === 'function' ? affects(result) : affects);\n await onSuccess?.(result);\n } catch {\n setError('The change was saved, but the page could not refresh. Reload before you retry.');\n }\n setPending(false);\n }\n\n return { pending, error, setError, run };\n}\n"],"mappings":";;;;;;;;;;;;;;;AAgBA,SAAgB,YAAY;CAC1B,MAAM,cAAc,eAAe;CACnC,MAAM,CAAC,SAAS,cAAc,SAAS,KAAK;CAC5C,MAAM,CAAC,OAAO,YAAY,SAAwB,IAAI;CAEtD,eAAe,IACb,IACA,EACE,SACA,aAOa;EACf,WAAW,IAAI;EACf,IAAI;EACJ,IAAI;GACF,SAAS,MAAM,GAAG;EACpB,SAAS,SAAS;GAChB,SAAS,eAAe,OAAO,CAAC;GAChC,WAAW,KAAK;GAChB;EACF;EAEA,SAAS,IAAI;EACb,IAAI;GACF,MAAM,QAAQ,aAAa,OAAO,YAAY,aAAa,QAAQ,MAAM,IAAI,OAAO;GACpF,MAAM,YAAY,MAAM;EAC1B,QAAQ;GACN,SAAS,gFAAgF;EAC3F;EACA,WAAW,KAAK;CAClB;CAEA,OAAO;EAAE;EAAS;EAAO;EAAU;CAAI;AACzC"}
@@ -1,48 +1,15 @@
1
- import { i as keys, t as affects, y as refresh } from "./queries-epz4MIuW.js";
1
+ import { i as keys, t as affects, y as refresh } from "./queries-DEOPOpsT.js";
2
2
  import { a as Refusal, o as failureMessage, s as memberRef } from "./page-JTORvh-N.js";
3
3
  import { o as announce } from "./row-state-BsIHspy4.js";
4
4
  import { useCallback } from "react";
5
- import { EVERYWHERE, ROLES, unscoped } from "@coffre/core/access";
5
+ import { EVERYWHERE, unscoped } from "@coffre/core/access";
6
6
  import { useMutation, useMutationState, useQueryClient } from "@tanstack/react-query";
7
7
  import { regenerateWrite } from "@coffre/core/recipe";
8
8
  //#region src/lib/project-access.ts
9
- function projectAccessOptions(environments) {
10
- const options = [{
11
- value: "owner:",
12
- role: "owner",
13
- environmentSlug: null,
14
- label: ROLES.owner.name
15
- }];
16
- for (const role of ["viewer", "developer"]) options.push({
17
- value: `${role}:`,
18
- role,
19
- environmentSlug: null,
20
- label: `${ROLES[role].name}: all`
21
- });
22
- for (const environment of environments) {
23
- if (environment.details === null || environment.details.archivedAt !== null) continue;
24
- for (const role of ["viewer", "developer"]) options.push({
25
- value: `${role}:${environment.slug}`,
26
- role,
27
- environmentSlug: environment.slug,
28
- label: `${ROLES[role].name}: ${environment.slug}`
29
- });
30
- }
31
- return options;
32
- }
33
- function parseProjectAccess(value) {
34
- const [role, environmentSlug = ""] = value.split(":", 2);
35
- if (role !== "owner" && role !== "viewer" && role !== "developer") throw new Error("unknown project access level");
36
- return {
37
- role,
38
- environmentSlug: environmentSlug || null
39
- };
40
- }
41
- /** "Owner", "Viewer: all" or "Developer: prod": a grant by its role's name, and where. */
9
+ /** "Owner", "Viewer: all" or "Developer: prod": a grant by its role's name, as the instance names it, and where. */
42
10
  function projectAccessLabel(grant) {
43
- const name = Object.hasOwn(ROLES, grant.role) ? ROLES[grant.role].name : grant.roleName;
44
- if (grant.role === "owner") return name;
45
- return `${name}: ${grant.environmentSlug ?? "all"}`;
11
+ if (grant.role === "owner") return grant.roleName;
12
+ return `${grant.roleName}: ${grant.environmentSlug ?? "all"}`;
46
13
  }
47
14
  /**
48
15
  * The Access tab's rows, project by project: a row per grant, and a project
@@ -111,8 +78,96 @@ function regenerateWaits(key, generated, busy) {
111
78
  return [key, ...regeneratedKeys(key, generated)].some(busy);
112
79
  }
113
80
  //#endregion
81
+ //#region src/lib/sensitivity.ts
82
+ /**
83
+ * Who sees a key's value, loosest first: `plain`, whoever lists its
84
+ * environment; `secret`, the default, people whose role reads secrets;
85
+ * `sensitive`, no person, Owners included, while their apps use it through
86
+ * the credential proxy and service accounts read it. A key is made
87
+ * stricter with its value kept; looser only with its value typed again, so
88
+ * nobody shows a value by flipping it.
89
+ */
90
+ var SENSITIVITIES = [
91
+ "plain",
92
+ "secret",
93
+ "sensitive"
94
+ ];
95
+ /** Each level as the page names it, and who it lets see the value. */
96
+ var LEVELS = {
97
+ plain: {
98
+ label: "Plain",
99
+ hint: "Visible to anyone who can see this environment"
100
+ },
101
+ secret: {
102
+ label: "Secret",
103
+ hint: "Visible to people whose role can read secrets"
104
+ },
105
+ sensitive: {
106
+ label: "Sensitive",
107
+ hint: "Never shown to anyone, Owners included. Used through the proxy or by services"
108
+ }
109
+ };
110
+ /** The levels in your personal config, `dev@me`, whose values nobody else sees, whatever their level. */
111
+ var PERSONAL_LEVELS = {
112
+ plain: {
113
+ label: "Plain",
114
+ hint: "Visible to you alone, as it is"
115
+ },
116
+ secret: {
117
+ label: "Secret",
118
+ hint: "Visible to you alone, when you reveal it"
119
+ },
120
+ sensitive: {
121
+ label: "Sensitive",
122
+ hint: "Never shown, you included. Your app uses it through the proxy"
123
+ }
124
+ };
125
+ /** Each level as a page names it, in your personal config or elsewhere. */
126
+ function levelsIn(personal) {
127
+ return personal ? PERSONAL_LEVELS : LEVELS;
128
+ }
129
+ /** Whether `a` lets fewer people see a value than `b`. */
130
+ function stricter(a, b) {
131
+ return SENSITIVITIES.indexOf(a) > SENSITIVITIES.indexOf(b);
132
+ }
133
+ /** A key's own value, which a mark makes stricter in place: not a reference's, nor one a fork inherits. */
134
+ function markable(entry) {
135
+ return entry.sensitivity !== null && entry.reference === null && (entry.parent === null || entry.parent.state === "overridden");
136
+ }
137
+ /**
138
+ * Whether a change of who sees a key waits for its value typed: looser
139
+ * than the key is, or where it has no value of its own to mark.
140
+ */
141
+ function waitsForValue(entry, change) {
142
+ if (change === void 0 || change.archived || change.value !== null || change.sensitivity === void 0) return false;
143
+ return !markable(entry) || stricter(entry.sensitivity, change.sensitivity);
144
+ }
145
+ //#endregion
114
146
  //#region src/lib/secret-edit-batch.ts
115
147
  /**
148
+ * What an edit of a row's value, and of who sees it, makes of its change,
149
+ * from where it started: `from.start`, the value the editor opened on (''
150
+ * when it could not be read), and `from.level`, who sees the row's value
151
+ * now (null for none of its own: a secret is written). A value left as it
152
+ * opened writes nothing; its level changed alone is then a mark. Looser
153
+ * than the row, the field opens empty, as that takes the value typed again:
154
+ * a stored value is never made more visible by a flip. Back where it
155
+ * started, it is no change.
156
+ *
157
+ * secret 'sk_1', opened on 'sk_1': Sensitive -> { value: null, sensitivity: 'sensitive' }, a mark
158
+ * secret 'sk_1', opened on 'sk_1': Plain -> { value: null, sensitivity: 'plain' }, waiting for a value
159
+ * then 'sk_2' typed -> { value: 'sk_2', sensitivity: 'plain' }
160
+ */
161
+ function valueEdit(from, next) {
162
+ const level = from.level ?? "secret";
163
+ const opened = stricter(level, next.sensitivity) ? "" : from.start;
164
+ const value = next.value === opened ? null : next.value;
165
+ return {
166
+ value,
167
+ sensitivity: value === null && next.sensitivity === level ? void 0 : next.sensitivity
168
+ };
169
+ }
170
+ /**
116
171
  * How a row's generated value was made, as its write says it: its recipe,
117
172
  * and for a key pair the names both halves are saved under.
118
173
  */
@@ -126,19 +181,85 @@ function generationOf(key, edit) {
126
181
  }
127
182
  };
128
183
  }
129
- /** What a row writes under each key: its value, and its companion's beside it. */
130
- function rowPatch(key, value, edit) {
184
+ /** Who sees the value a row writes: a secret unless it says, and a generated one never plain. */
185
+ function levelOf(edit) {
186
+ return edit.sensitivity === "sensitive" || edit.sensitivity === "plain" && edit.recipe === void 0 ? edit.sensitivity : "secret";
187
+ }
188
+ /**
189
+ * Who sees each listed key's value now, by its name after the save: a
190
+ * renamed key keeps its level under its new name; an archived one is gone.
191
+ */
192
+ function levelsNow(active, changes) {
193
+ const out = /* @__PURE__ */ new Map();
194
+ for (const entry of active) {
195
+ const change = secretChangeFor(changes, entry.key);
196
+ if (change?.archived) continue;
197
+ out.set(change?.key.trim() ?? entry.key, entry.sensitivity ?? null);
198
+ }
199
+ return out;
200
+ }
201
+ /**
202
+ * Who sees the public key a pair writes: who the user chose, else who sees
203
+ * the key it writes over now, or a secret, as a generated value is never
204
+ * plain. A public key need not be hidden, so a sensitive private key does
205
+ * not make it sensitive.
206
+ *
207
+ * PRIVATE_KEY sensitive, PUBLIC_KEY secret -> PUBLIC_KEY written secret
208
+ * PRIVATE_KEY secret, PUBLIC_KEY sensitive -> PUBLIC_KEY written sensitive
209
+ * PUBLIC_KEY new -> secret
210
+ */
211
+ function companionLevel(companion, now) {
212
+ return companion.sensitivity ?? (now.get(companion.key.trim()) === "sensitive" ? "sensitive" : "secret");
213
+ }
214
+ /**
215
+ * What a row writes under each key: its value, and its companion's beside
216
+ * it, each saying who sees it, as every write does: over a sensitive key,
217
+ * one that said nothing would stay sensitive.
218
+ */
219
+ function rowPatch(key, value, edit, now) {
131
220
  const generated = generationOf(key, edit);
132
- const entry = (each) => generated === void 0 ? each : {
221
+ const entry = (each, sensitivity) => generated === void 0 || sensitivity === "plain" ? {
133
222
  value: each,
134
- generated
223
+ sensitivity
224
+ } : {
225
+ value: each,
226
+ generated,
227
+ sensitivity
135
228
  };
136
229
  const patch = Object.create(null);
137
- patch[key] = entry(value);
138
- if (edit.companion !== void 0) patch[edit.companion.key.trim()] = entry(edit.companion.value);
230
+ patch[key] = entry(value, levelOf(edit));
231
+ if (edit.companion !== void 0) patch[edit.companion.key.trim()] = entry(edit.companion.value, companionLevel(edit.companion, now));
232
+ return patch;
233
+ }
234
+ /**
235
+ * The one merge patch a save writes, by each key's name after its renames:
236
+ * every value with its companion, every mark and every archive. An edit
237
+ * whose key went from the list writes nothing.
238
+ */
239
+ function patchOf(active, drafts, changes) {
240
+ const now = levelsNow(active, changes);
241
+ const patch = Object.create(null);
242
+ for (const entry of active) {
243
+ const change = secretChangeFor(changes, entry.key);
244
+ if (change === void 0) continue;
245
+ const key = change.key.trim();
246
+ if (change.archived) patch[entry.key] = null;
247
+ else if (change.value !== null) Object.assign(patch, rowPatch(key, change.value, change, now));
248
+ else if (change.sensitivity !== void 0) patch[key] = { sensitivity: change.sensitivity };
249
+ }
250
+ for (const draft of drafts) Object.assign(patch, rowPatch(draft.key.trim(), draft.value, draft, now));
139
251
  return patch;
140
252
  }
141
253
  /**
254
+ * The keys a save makes sensitive, by their names after it: each it writes
255
+ * sensitive, a companion included, that was not sensitive before. Nobody
256
+ * sees them again, so the save asks first.
257
+ */
258
+ function madeSensitive(active, drafts, changes) {
259
+ const now = levelsNow(active, changes);
260
+ return Object.entries(patchOf(active, drafts, changes)).filter(([key, write]) => write !== null && write.sensitivity === "sensitive" && now.get(key) !== "sensitive").map(([key]) => key);
261
+ }
262
+ /**
142
263
  * The recipe each key a save writes will hold, by its name after the save:
143
264
  * what the list shows of it until it is read back.
144
265
  */
@@ -157,6 +278,18 @@ function generationsOf(active, drafts, changes) {
157
278
  }
158
279
  return out;
159
280
  }
281
+ /**
282
+ * Who sees each value a save writes, and a plain one's value, by its key's
283
+ * name after the save: what the list shows of it until it is read back.
284
+ */
285
+ function levelsOf(active, drafts, changes) {
286
+ const out = /* @__PURE__ */ new Map();
287
+ for (const [key, write] of Object.entries(patchOf(active, drafts, changes))) if (write !== null && "value" in write) out.set(key, {
288
+ sensitivity: write.sensitivity,
289
+ value: write.sensitivity === "plain" ? write.value : null
290
+ });
291
+ return out;
292
+ }
160
293
  function secretChangeFor(changes, key) {
161
294
  return Object.hasOwn(changes, key) ? changes[key] : void 0;
162
295
  }
@@ -179,7 +312,7 @@ function hasSecretEditConflict(active, drafts, changes) {
179
312
  if (new Set(draftKeys).size !== draftKeys.length) return true;
180
313
  const valueEditTargets = new Set(active.flatMap((entry) => {
181
314
  const change = secretChangeFor(changes, entry.key);
182
- return change !== void 0 && !change.archived && change.value !== null ? [change.key.trim()] : [];
315
+ return change !== void 0 && !change.archived && (change.value !== null || change.sensitivity !== void 0) ? [change.key.trim()] : [];
183
316
  }));
184
317
  if (draftKeys.some((key) => valueEditTargets.has(key))) return true;
185
318
  const archivedKeys = new Set(active.filter((entry) => secretChangeFor(changes, entry.key)?.archived).map((entry) => entry.key));
@@ -205,26 +338,19 @@ async function applySecretEditBatch({ active, drafts, changes, operations }) {
205
338
  error: plan
206
339
  };
207
340
  let applied = 0;
208
- const patch = Object.create(null);
341
+ const patch = patchOf(active, drafts, changes);
209
342
  try {
210
343
  for (const { sourceKey, change } of plan) {
211
- if (change.archived) {
212
- patch[sourceKey] = null;
213
- continue;
214
- }
215
344
  const key = change.key.trim();
216
- if (key !== sourceKey) {
217
- await operations.rename(sourceKey, key);
218
- delete remainingChanges[sourceKey];
219
- applied += 1;
220
- if (change.value !== null) remainingChanges[key] = {
221
- ...change,
222
- key
223
- };
224
- }
225
- if (change.value !== null) Object.assign(patch, rowPatch(key, change.value, change));
345
+ if (change.archived || key === sourceKey) continue;
346
+ await operations.rename(sourceKey, key);
347
+ delete remainingChanges[sourceKey];
348
+ applied += 1;
349
+ if (change.value !== null || change.sensitivity !== void 0) remainingChanges[key] = {
350
+ ...change,
351
+ key
352
+ };
226
353
  }
227
- for (const draft of drafts) Object.assign(patch, rowPatch(draft.key.trim(), draft.value, draft));
228
354
  const written = Object.keys(patch).length;
229
355
  if (written > 0) await operations.write({ ...patch });
230
356
  return {
@@ -350,7 +476,7 @@ function grantPlace(project, environmentSlug) {
350
476
  function grantAccess(client, project) {
351
477
  return {
352
478
  list: grantsList(project),
353
- label: (vars) => `${vars.roleName} for ${vars.principalId}`,
479
+ label: (vars) => `${projectAccessLabel(vars)} for ${vars.principalId}`,
354
480
  targets: (vars) => [saving(grantId(vars))],
355
481
  apply: (grants, vars) => {
356
482
  const row = {
@@ -613,6 +739,7 @@ function createEnvironment(client, project) {
613
739
  name: vars.slug,
614
740
  accessible: false,
615
741
  parent: vars.inherit === true ? vars.from ?? null : null,
742
+ protected: vars.from !== void 0 && environments.some((environment) => environment.slug === vars.from && environment.protected),
616
743
  personal: false,
617
744
  details: {
618
745
  archivedAt: null,
@@ -644,6 +771,26 @@ function renameEnvironment(client, project) {
644
771
  };
645
772
  }
646
773
  /**
774
+ * Protect an environment, or take its protection off (docs/design/roles.md):
775
+ * shown on its card at once, and the card says if the server refuses. Only
776
+ * an Owner of the whole instance unprotects one, which the page offers to
777
+ * them alone. What everyone holds there changes, so the roles' readers are
778
+ * refetched too.
779
+ */
780
+ function protectEnvironment(client, project) {
781
+ return {
782
+ list: environmentsList(project),
783
+ label: (vars) => `environment ${vars.slug}`,
784
+ targets: (vars) => [saving(environmentId(project, vars.slug))],
785
+ apply: (environments, vars) => environments.map((environment) => environment.slug === vars.slug ? {
786
+ ...environment,
787
+ protected: vars.protected
788
+ } : environment),
789
+ affects: () => [...affects.places(), ...affects.roles()],
790
+ run: (vars) => client.environments.protect(`${project}/${vars.slug}`, vars.protected)
791
+ };
792
+ }
793
+ /**
647
794
  * Archive an environment or bring it back. Archiving ends every read of it,
648
795
  * so it waits for the server, as a removal does; restoring shows at once.
649
796
  */
@@ -706,8 +853,10 @@ function saveSecrets(client, place, author) {
706
853
  apply: (entries, vars) => {
707
854
  const now = (/* @__PURE__ */ new Date()).toISOString();
708
855
  const generations = generationsOf(vars.active, vars.drafts, vars.changes);
856
+ const levels = levelsOf(vars.active, vars.drafts, vars.changes);
709
857
  const bumped = (entry, key) => {
710
858
  const inherited = entry?.parent != null && entry.parent.state !== "overridden" && entry.key === key;
859
+ const level = levels.get(key);
711
860
  return {
712
861
  key,
713
862
  folder: entry?.folder ?? null,
@@ -718,6 +867,9 @@ function saveSecrets(client, place, author) {
718
867
  updatedAt: now,
719
868
  updatedBy: author,
720
869
  generated: generations.get(key) ?? null,
870
+ value: level?.value ?? null,
871
+ sensitivity: level?.sensitivity ?? "secret",
872
+ readable: level?.value != null || (level?.sensitivity ?? "secret") === "secret" && !inherited && entry?.sensitivity === "secret" && entry.readable,
721
873
  parent: entry?.parent == null || entry.key !== key ? null : {
722
874
  ...entry.parent,
723
875
  state: "overridden",
@@ -732,10 +884,21 @@ function saveSecrets(client, place, author) {
732
884
  if (change === void 0 || change.archived) return entry;
733
885
  const key = change.key.trim();
734
886
  if (key !== entry.key) renames.set(entry.key, key);
735
- return change.value === null ? {
887
+ if (change.value !== null) return bumped(entry, key);
888
+ return change.sensitivity === void 0 ? {
736
889
  ...entry,
737
890
  key
738
- } : bumped(entry, key);
891
+ } : {
892
+ ...entry,
893
+ key,
894
+ version: (entry.version ?? 0) + 1,
895
+ versionId: null,
896
+ updatedAt: now,
897
+ updatedBy: author,
898
+ value: null,
899
+ sensitivity: change.sensitivity,
900
+ readable: false
901
+ };
739
902
  });
740
903
  next = renamePairs(next, renames);
741
904
  for (const draft of written(vars)) {
@@ -819,6 +982,8 @@ function regenerateSecret(client, place, author) {
819
982
  updatedAt: now,
820
983
  updatedBy: author,
821
984
  generated: vars.generated,
985
+ value: null,
986
+ sensitivity: entry.sensitivity === "sensitive" ? "sensitive" : "secret",
822
987
  parent: entry.parent == null ? null : {
823
988
  ...entry.parent,
824
989
  state: "overridden",
@@ -1143,6 +1308,6 @@ function useChangeStatus(list) {
1143
1308
  };
1144
1309
  }
1145
1310
  //#endregion
1146
- export { revokeCredential as A, regeneratedKeys as B, projectsList as C, renameEnvironment as D, removeMember as E, companionsOf as F, parseProjectAccess as H, hasSecretEditConflict as I, secretChangeFor as L, revokeMemberToken as M, saveSecrets as N, restoreMissing as O, unlinkIdentity as P, liveGeneration as R, moveSecret as S, removeBinding as T, projectAccessLabel as U, accessRows as V, projectAccessOptions as W, forkKey as _, UnsavedEdits as a, invite as b, changeRole as c, directoryList as d, disconnectApp as f, environmentId as g, endSession as h, changeOptions as i, revokeGrant as j, restoreSecret as k, createEnvironment as l, dismissMissing as m, useChangeStatus as n, archiveEnvironment as o, disconnectMemberApp as p, changeKey as r, archiveSecret as s, useChange as t, createProject as u, grantAccess as v, regenerateSecret as w, missingList as x, grantId as y, regenerateWaits as z };
1311
+ export { restoreSecret as A, valueEdit as B, projectsList as C, removeMember as D, removeBinding as E, unlinkIdentity as F, stricter as G, SENSITIVITIES as H, companionsOf as I, regenerateWaits as J, waitsForValue as K, hasSecretEditConflict as L, revokeGrant as M, revokeMemberToken as N, renameEnvironment as O, saveSecrets as P, madeSensitive as R, moveSecret as S, regenerateSecret as T, levelsIn as U, LEVELS as V, markable as W, accessRows as X, regeneratedKeys as Y, projectAccessLabel as Z, forkKey as _, UnsavedEdits as a, invite as b, changeRole as c, directoryList as d, disconnectApp as f, environmentId as g, endSession as h, changeOptions as i, revokeCredential as j, restoreMissing as k, createEnvironment as l, dismissMissing as m, useChangeStatus as n, archiveEnvironment as o, disconnectMemberApp as p, liveGeneration as q, changeKey as r, archiveSecret as s, useChange as t, createProject as u, grantAccess as v, protectEnvironment as w, missingList as x, grantId as y, secretChangeFor as z };
1147
1312
 
1148
- //# sourceMappingURL=use-change-CQyDpCqw.js.map
1313
+ //# sourceMappingURL=use-change-hfqE7baE.js.map