@coffre/ui 0.9.0 → 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-JrQIUq6j.js → audit-sentence-Bjhg00cn.js} +73 -6
  2. package/dist/chunks/audit-sentence-Bjhg00cn.js.map +1 -0
  3. package/dist/chunks/{connected-apps-Dr8UgjK7.js → connected-apps-CZI7xxUq.js} +2 -2
  4. package/dist/chunks/{connected-apps-Dr8UgjK7.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-XcSbDRJv.js → directory-CyHmxYP-.js} +9 -7
  8. package/dist/chunks/directory-CyHmxYP-.js.map +1 -0
  9. package/dist/chunks/{grants-CmdZjKYU.js → grants-CEIdNqJU.js} +4 -4
  10. package/dist/chunks/{grants-CmdZjKYU.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-Dvl1FktE.js → personal-tokens-BX97oX4a.js} +2 -2
  14. package/dist/chunks/{personal-tokens-Dvl1FktE.js.map → personal-tokens-BX97oX4a.js.map} +1 -1
  15. package/dist/chunks/{principal-page-bOaEYWJB.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-BY6KPmnJ.js → use-change-hfqE7baE.js} +217 -100
  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 +8 -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 +251 -111
  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 -9
  70. package/src/lib/changes.ts +46 -8
  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 +147 -56
  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 +264 -101
  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 +322 -25
  87. package/dist/chunks/audit-sentence-JrQIUq6j.js.map +0 -1
  88. package/dist/chunks/directory-XcSbDRJv.js.map +0 -1
  89. package/dist/chunks/principal-page-bOaEYWJB.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-BY6KPmnJ.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,29 +78,93 @@ 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
  /**
116
- * What a value edit makes of a row's change: `value`, written `plain` or
117
- * not, from where the edit started (`from.start`, the row's plain value or
118
- * the secret it revealed, `from.plain`, whether the row is plain, and
119
- * `from.startedAt`, that version's id). Back where it started, it is no
120
- * change. The version it started from stays with the change from its first
121
- * edit on, so a remount of the row (a rename refused, then retried) never
122
- * loses it.
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' }
123
160
  */
124
- function valueEdit(change, from, value, plain) {
125
- const replaces = change.replaces ?? from.startedAt;
126
- if (value === from.start && plain === from.plain) return {
127
- value: null,
128
- plain: void 0,
129
- replaces
130
- };
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;
131
165
  return {
132
166
  value,
133
- plain,
134
- replaces,
135
- companion: void 0,
136
- recipe: void 0
167
+ sensitivity: value === null && next.sensitivity === level ? void 0 : next.sensitivity
137
168
  };
138
169
  }
139
170
  /**
@@ -150,27 +181,85 @@ function generationOf(key, edit) {
150
181
  }
151
182
  };
152
183
  }
153
- /** What a row writes under each key: its value, and its companion's beside it. */
154
- 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) {
155
220
  const generated = generationOf(key, edit);
156
- const plain = (each) => edit.replaces === void 0 ? {
221
+ const entry = (each, sensitivity) => generated === void 0 || sensitivity === "plain" ? {
157
222
  value: each,
158
- plain: true
223
+ sensitivity
159
224
  } : {
160
225
  value: each,
161
- plain: true,
162
- replaces: edit.replaces
226
+ generated,
227
+ sensitivity
163
228
  };
164
- const entry = (each) => generated !== void 0 ? {
165
- value: each,
166
- generated
167
- } : edit.plain === true ? plain(each) : each;
168
229
  const patch = Object.create(null);
169
- patch[key] = entry(value);
170
- 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));
171
251
  return patch;
172
252
  }
173
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
+ /**
174
263
  * The recipe each key a save writes will hold, by its name after the save:
175
264
  * what the list shows of it until it is read back.
176
265
  */
@@ -190,16 +279,15 @@ function generationsOf(active, drafts, changes) {
190
279
  return out;
191
280
  }
192
281
  /**
193
- * The value each key a save writes plain will show, by its name after the
194
- * save: what the list shows of it until it is read back.
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.
195
284
  */
196
- function plainValuesOf(active, drafts, changes) {
285
+ function levelsOf(active, drafts, changes) {
197
286
  const out = /* @__PURE__ */ new Map();
198
- for (const draft of drafts) if (draft.plain === true && draft.recipe === void 0) out.set(draft.key.trim(), draft.value);
199
- for (const entry of active) {
200
- const change = secretChangeFor(changes, entry.key);
201
- if (change !== void 0 && !change.archived && change.value !== null && change.plain === true && change.recipe === void 0) out.set(change.key.trim(), change.value);
202
- }
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
+ });
203
291
  return out;
204
292
  }
205
293
  function secretChangeFor(changes, key) {
@@ -224,7 +312,7 @@ function hasSecretEditConflict(active, drafts, changes) {
224
312
  if (new Set(draftKeys).size !== draftKeys.length) return true;
225
313
  const valueEditTargets = new Set(active.flatMap((entry) => {
226
314
  const change = secretChangeFor(changes, entry.key);
227
- 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()] : [];
228
316
  }));
229
317
  if (draftKeys.some((key) => valueEditTargets.has(key))) return true;
230
318
  const archivedKeys = new Set(active.filter((entry) => secretChangeFor(changes, entry.key)?.archived).map((entry) => entry.key));
@@ -250,26 +338,19 @@ async function applySecretEditBatch({ active, drafts, changes, operations }) {
250
338
  error: plan
251
339
  };
252
340
  let applied = 0;
253
- const patch = Object.create(null);
341
+ const patch = patchOf(active, drafts, changes);
254
342
  try {
255
343
  for (const { sourceKey, change } of plan) {
256
- if (change.archived) {
257
- patch[sourceKey] = null;
258
- continue;
259
- }
260
344
  const key = change.key.trim();
261
- if (key !== sourceKey) {
262
- await operations.rename(sourceKey, key);
263
- delete remainingChanges[sourceKey];
264
- applied += 1;
265
- if (change.value !== null) remainingChanges[key] = {
266
- ...change,
267
- key
268
- };
269
- }
270
- 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
+ };
271
353
  }
272
- for (const draft of drafts) Object.assign(patch, rowPatch(draft.key.trim(), draft.value, draft));
273
354
  const written = Object.keys(patch).length;
274
355
  if (written > 0) await operations.write({ ...patch });
275
356
  return {
@@ -395,7 +476,7 @@ function grantPlace(project, environmentSlug) {
395
476
  function grantAccess(client, project) {
396
477
  return {
397
478
  list: grantsList(project),
398
- label: (vars) => `${vars.roleName} for ${vars.principalId}`,
479
+ label: (vars) => `${projectAccessLabel(vars)} for ${vars.principalId}`,
399
480
  targets: (vars) => [saving(grantId(vars))],
400
481
  apply: (grants, vars) => {
401
482
  const row = {
@@ -658,6 +739,7 @@ function createEnvironment(client, project) {
658
739
  name: vars.slug,
659
740
  accessible: false,
660
741
  parent: vars.inherit === true ? vars.from ?? null : null,
742
+ protected: vars.from !== void 0 && environments.some((environment) => environment.slug === vars.from && environment.protected),
661
743
  personal: false,
662
744
  details: {
663
745
  archivedAt: null,
@@ -689,6 +771,26 @@ function renameEnvironment(client, project) {
689
771
  };
690
772
  }
691
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
+ /**
692
794
  * Archive an environment or bring it back. Archiving ends every read of it,
693
795
  * so it waits for the server, as a removal does; restoring shows at once.
694
796
  */
@@ -751,9 +853,10 @@ function saveSecrets(client, place, author) {
751
853
  apply: (entries, vars) => {
752
854
  const now = (/* @__PURE__ */ new Date()).toISOString();
753
855
  const generations = generationsOf(vars.active, vars.drafts, vars.changes);
754
- const plains = plainValuesOf(vars.active, vars.drafts, vars.changes);
856
+ const levels = levelsOf(vars.active, vars.drafts, vars.changes);
755
857
  const bumped = (entry, key) => {
756
858
  const inherited = entry?.parent != null && entry.parent.state !== "overridden" && entry.key === key;
859
+ const level = levels.get(key);
757
860
  return {
758
861
  key,
759
862
  folder: entry?.folder ?? null,
@@ -764,7 +867,9 @@ function saveSecrets(client, place, author) {
764
867
  updatedAt: now,
765
868
  updatedBy: author,
766
869
  generated: generations.get(key) ?? null,
767
- value: plains.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,
768
873
  parent: entry?.parent == null || entry.key !== key ? null : {
769
874
  ...entry.parent,
770
875
  state: "overridden",
@@ -779,10 +884,21 @@ function saveSecrets(client, place, author) {
779
884
  if (change === void 0 || change.archived) return entry;
780
885
  const key = change.key.trim();
781
886
  if (key !== entry.key) renames.set(entry.key, key);
782
- return change.value === null ? {
887
+ if (change.value !== null) return bumped(entry, key);
888
+ return change.sensitivity === void 0 ? {
783
889
  ...entry,
784
890
  key
785
- } : 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
+ };
786
902
  });
787
903
  next = renamePairs(next, renames);
788
904
  for (const draft of written(vars)) {
@@ -867,6 +983,7 @@ function regenerateSecret(client, place, author) {
867
983
  updatedBy: author,
868
984
  generated: vars.generated,
869
985
  value: null,
986
+ sensitivity: entry.sensitivity === "sensitive" ? "sensitive" : "secret",
870
987
  parent: entry.parent == null ? null : {
871
988
  ...entry.parent,
872
989
  state: "overridden",
@@ -1191,6 +1308,6 @@ function useChangeStatus(list) {
1191
1308
  };
1192
1309
  }
1193
1310
  //#endregion
1194
- export { revokeCredential as A, regenerateWaits as B, projectsList as C, renameEnvironment as D, removeMember as E, companionsOf as F, projectAccessOptions as G, accessRows as H, hasSecretEditConflict as I, secretChangeFor as L, revokeMemberToken as M, saveSecrets as N, restoreMissing as O, unlinkIdentity as P, valueEdit as R, moveSecret as S, removeBinding as T, parseProjectAccess as U, regeneratedKeys as V, projectAccessLabel 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, liveGeneration 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 };
1195
1312
 
1196
- //# sourceMappingURL=use-change-BY6KPmnJ.js.map
1313
+ //# sourceMappingURL=use-change-hfqE7baE.js.map