@coffre/ui 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +8 -2
- package/dist/client/.assetsignore +2 -0
- package/dist/client/_coffre/assets/account-C3Zo1l5A.js +1 -0
- package/dist/client/_coffre/assets/account-C4bNbeO7.js +2 -0
- package/dist/client/_coffre/assets/affordances-DiuJIiR2.js +1 -0
- package/dist/client/_coffre/assets/audit-1xLyuxGz.js +2 -0
- package/dist/client/_coffre/assets/audit-Dab2GuRj.js +1 -0
- package/dist/client/_coffre/assets/auth.device-BfCfeBWe.js +2 -0
- package/dist/client/_coffre/assets/auth.device-D2pCLF-X.js +1 -0
- package/dist/client/_coffre/assets/coffre-C7qL3HGR.js +1 -0
- package/dist/client/_coffre/assets/directory-C2Ou4SQv.js +1 -0
- package/dist/client/_coffre/assets/globals-Dgq4Jy0x.css +1 -0
- package/dist/client/_coffre/assets/grants-fqTtJ-aW.js +1 -0
- package/dist/client/_coffre/assets/index-BpGwbjmM.js +12 -0
- package/dist/client/_coffre/assets/inter-cyrillic-ext-opsz-normal-CfYZpDVp.woff2 +0 -0
- package/dist/client/_coffre/assets/inter-cyrillic-opsz-normal-BFQXbQ-f.woff2 +0 -0
- package/dist/client/_coffre/assets/inter-greek-ext-opsz-normal-BmPQvyvo.woff2 +0 -0
- package/dist/client/_coffre/assets/inter-greek-opsz-normal-BM0NlUE_.woff2 +0 -0
- package/dist/client/_coffre/assets/inter-latin-ext-opsz-normal-DpK-iCPk.woff2 +0 -0
- package/dist/client/_coffre/assets/inter-latin-opsz-normal-BwkfbSeq.woff2 +0 -0
- package/dist/client/_coffre/assets/inter-vietnamese-opsz-normal-Ci9T9ieq.woff2 +0 -0
- package/dist/client/_coffre/assets/jetbrains-mono-cyrillic-ext-wght-normal-EocZY2iu.woff2 +0 -0
- package/dist/client/_coffre/assets/jetbrains-mono-cyrillic-wght-normal-D73BlboJ.woff2 +0 -0
- package/dist/client/_coffre/assets/jetbrains-mono-greek-wght-normal-Bw9x6K1M.woff2 +0 -0
- package/dist/client/_coffre/assets/jetbrains-mono-latin-ext-wght-normal-DBQx-q_a.woff2 +0 -0
- package/dist/client/_coffre/assets/jetbrains-mono-latin-wght-normal-B9CIFXIH.woff2 +0 -0
- package/dist/client/_coffre/assets/jetbrains-mono-vietnamese-wght-normal-Bt-aOZkq.woff2 +0 -0
- package/dist/client/_coffre/assets/login-CR9CBXlw.js +2 -0
- package/dist/client/_coffre/assets/login-DZizFxa4.js +1 -0
- package/dist/client/_coffre/assets/offboarding-DOLJQcXU.js +1 -0
- package/dist/client/_coffre/assets/page-BxW2MwaX.js +1 -0
- package/dist/client/_coffre/assets/preload-helper-BHuP8_FL.js +46 -0
- package/dist/client/_coffre/assets/principal-page-xnBZVURr.js +1 -0
- package/dist/client/_coffre/assets/project-environments-CfIH5kFM.js +1 -0
- package/dist/client/_coffre/assets/projects._project._environment-CrWjQmIA.js +2 -0
- package/dist/client/_coffre/assets/projects._project._environment-CwRVG9Ne.js +3 -0
- package/dist/client/_coffre/assets/projects._project.index-CCDEuE-z.js +2 -0
- package/dist/client/_coffre/assets/projects._project.index-DCJsmnD7.js +1 -0
- package/dist/client/_coffre/assets/projects.index-B8eV8JIn.js +1 -0
- package/dist/client/_coffre/assets/projects.index-BNEC7Oz8.js +2 -0
- package/dist/client/_coffre/assets/settings-2BPsenNM.js +2 -0
- package/dist/client/_coffre/assets/settings-BrS0-wEt.js +1 -0
- package/dist/client/_coffre/assets/signin-errors-CroZWZgm.js +1 -0
- package/dist/client/_coffre/assets/tokens._token-B3-YwuKp.js +2 -0
- package/dist/client/_coffre/assets/tokens._token-D_hsbHx6.js +1 -0
- package/dist/client/_coffre/assets/tokens.index-BdKE2Jv8.js +2 -0
- package/dist/client/_coffre/assets/tokens.index-XvA4XRxh.js +1 -0
- package/dist/client/_coffre/assets/unregistered-CTRMtBIy.js +1 -0
- package/dist/client/_coffre/assets/use-action-DgAf-tiX.js +1 -0
- package/dist/client/_coffre/assets/users._user-BFPXcJ4y.js +2 -0
- package/dist/client/_coffre/assets/users._user-DEtMeSoh.js +1 -0
- package/dist/client/_coffre/assets/users.index-B03beUHq.js +1 -0
- package/dist/client/_coffre/assets/users.index-D8hwzM6P.js +2 -0
- package/dist/client/_coffre/assets/validation-9Cl_XS-l.js +1 -0
- package/dist/index.d.ts +19 -0
- package/dist/server/.vite/manifest.json +572 -0
- package/dist/server/_coffre/assets/_tanstack-start-manifest_v-B6CZDfrB.js +133 -0
- package/dist/server/_coffre/assets/account-B71_b5xc.js +296 -0
- package/dist/server/_coffre/assets/account-BoO6ZqMc.js +176 -0
- package/dist/server/_coffre/assets/affordances-BNaXjMOb.js +46 -0
- package/dist/server/_coffre/assets/async-local-storage-C0cwgkEr.js +3107 -0
- package/dist/server/_coffre/assets/audit-CwRFnSAY.js +74 -0
- package/dist/server/_coffre/assets/audit-t1sYjtrf.js +964 -0
- package/dist/server/_coffre/assets/auth.device-1IcJ475s.js +208 -0
- package/dist/server/_coffre/assets/auth.device-CJwZYYtn.js +29 -0
- package/dist/server/_coffre/assets/coffre-1hxT2E_U.js +278 -0
- package/dist/server/_coffre/assets/directory-wm_JQUfk.js +396 -0
- package/dist/server/_coffre/assets/empty-plugin-adapters-Cq4--YW-.js +5 -0
- package/dist/server/_coffre/assets/globals-Dgq4Jy0x.css +1 -0
- package/dist/server/_coffre/assets/grants-BmhEY1vz.js +243 -0
- package/dist/server/_coffre/assets/inter-cyrillic-ext-opsz-normal-CfYZpDVp.woff2 +0 -0
- package/dist/server/_coffre/assets/inter-cyrillic-opsz-normal-BFQXbQ-f.woff2 +0 -0
- package/dist/server/_coffre/assets/inter-greek-ext-opsz-normal-BmPQvyvo.woff2 +0 -0
- package/dist/server/_coffre/assets/inter-greek-opsz-normal-BM0NlUE_.woff2 +0 -0
- package/dist/server/_coffre/assets/inter-latin-ext-opsz-normal-DpK-iCPk.woff2 +0 -0
- package/dist/server/_coffre/assets/inter-latin-opsz-normal-BwkfbSeq.woff2 +0 -0
- package/dist/server/_coffre/assets/inter-vietnamese-opsz-normal-Ci9T9ieq.woff2 +0 -0
- package/dist/server/_coffre/assets/jetbrains-mono-cyrillic-ext-wght-normal-EocZY2iu.woff2 +0 -0
- package/dist/server/_coffre/assets/jetbrains-mono-cyrillic-wght-normal-D73BlboJ.woff2 +0 -0
- package/dist/server/_coffre/assets/jetbrains-mono-greek-wght-normal-Bw9x6K1M.woff2 +0 -0
- package/dist/server/_coffre/assets/jetbrains-mono-latin-ext-wght-normal-DBQx-q_a.woff2 +0 -0
- package/dist/server/_coffre/assets/jetbrains-mono-latin-wght-normal-B9CIFXIH.woff2 +0 -0
- package/dist/server/_coffre/assets/jetbrains-mono-vietnamese-wght-normal-Bt-aOZkq.woff2 +0 -0
- package/dist/server/_coffre/assets/login-B5O5LPXV.js +100 -0
- package/dist/server/_coffre/assets/login-Bvc4gp0X.js +22 -0
- package/dist/server/_coffre/assets/offboarding-CvSilnSm.js +330 -0
- package/dist/server/_coffre/assets/page-BjXk0Ehu.js +2003 -0
- package/dist/server/_coffre/assets/principal-page-DkwNGzM2.js +617 -0
- package/dist/server/_coffre/assets/project-environments-lEzFHUt4.js +9 -0
- package/dist/server/_coffre/assets/projects._project._environment-7grhqlgq.js +2227 -0
- package/dist/server/_coffre/assets/projects._project._environment-ByEf6pmz.js +55 -0
- package/dist/server/_coffre/assets/projects._project.index-B1bjowP-.js +932 -0
- package/dist/server/_coffre/assets/projects._project.index-DU8wtoHD.js +22 -0
- package/dist/server/_coffre/assets/projects.index-B0DoHbCz.js +280 -0
- package/dist/server/_coffre/assets/projects.index-kMDA6pMy.js +54 -0
- package/dist/server/_coffre/assets/react-dom-qCTiwGGR.js +1352 -0
- package/dist/server/_coffre/assets/router-ChU_CwCX.js +2028 -0
- package/dist/server/_coffre/assets/settings-CM9-h7in.js +18 -0
- package/dist/server/_coffre/assets/settings-Cg5qOGij.js +60 -0
- package/dist/server/_coffre/assets/signin-errors-BEFlVDbQ.js +28 -0
- package/dist/server/_coffre/assets/start-DR3rN0St.js +4 -0
- package/dist/server/_coffre/assets/tokens._token-CCpaPMAk.js +268 -0
- package/dist/server/_coffre/assets/tokens._token-Di4OZdAA.js +18 -0
- package/dist/server/_coffre/assets/tokens.index-Do3OHR31.js +34 -0
- package/dist/server/_coffre/assets/tokens.index-tDKq4AFh.js +10 -0
- package/dist/server/_coffre/assets/ui-BNzhIAQP.js +15710 -0
- package/dist/server/_coffre/assets/unregistered-BqaWYFJK.js +51 -0
- package/dist/server/_coffre/assets/use-action-BkJXC5JM.js +953 -0
- package/dist/server/_coffre/assets/useStore-DWGPqzXR.js +892 -0
- package/dist/server/_coffre/assets/users._user-BenYva93.js +15 -0
- package/dist/server/_coffre/assets/users._user-Cp039Va-.js +10 -0
- package/dist/server/_coffre/assets/users.index-BrzG1Ecq.js +10 -0
- package/dist/server/_coffre/assets/users.index-DQ_45DQl.js +34 -0
- package/dist/server/_coffre/assets/validation-BQtqPe2V.js +27 -0
- package/dist/server/index.js +13910 -0
- package/package.json +58 -3
- package/src/components/affordances.ts +80 -0
- package/src/components/agentation.tsx +34 -0
- package/src/components/command-palette.tsx +271 -0
- package/src/components/directory.tsx +448 -0
- package/src/components/grants.tsx +204 -0
- package/src/components/icons.tsx +283 -0
- package/src/components/offboarding.tsx +286 -0
- package/src/components/page.tsx +128 -0
- package/src/components/principal-page.tsx +549 -0
- package/src/components/principal-picker.tsx +168 -0
- package/src/components/principal.tsx +53 -0
- package/src/components/route-states.tsx +60 -0
- package/src/components/service-tokens.tsx +212 -0
- package/src/components/shell.tsx +641 -0
- package/src/components/syncs.tsx +581 -0
- package/src/components/theme.tsx +141 -0
- package/src/components/tile.tsx +22 -0
- package/src/components/ui.tsx +440 -0
- package/src/entry.ts +19 -0
- package/src/lib/access-plan.ts +201 -0
- package/src/lib/audit-sentences.ts +468 -0
- package/src/lib/capabilities.ts +45 -0
- package/src/lib/coffre.ts +57 -0
- package/src/lib/project-access.ts +95 -0
- package/src/lib/project-environments.ts +23 -0
- package/src/lib/reveal.ts +21 -0
- package/src/lib/secret-edit-batch.ts +181 -0
- package/src/lib/signin-errors.ts +33 -0
- package/src/lib/use-action.ts +50 -0
- package/src/lib/validation.ts +27 -0
- package/src/routeTree.gen.ts +367 -0
- package/src/router.tsx +84 -0
- package/src/routes/__root.tsx +192 -0
- package/src/routes/access.tsx +11 -0
- package/src/routes/account.tsx +359 -0
- package/src/routes/audit.tsx +545 -0
- package/src/routes/auth.device.tsx +200 -0
- package/src/routes/index.tsx +15 -0
- package/src/routes/login.tsx +129 -0
- package/src/routes/projects.$project.$environment.tsx +1659 -0
- package/src/routes/projects.$project.index.tsx +917 -0
- package/src/routes/projects.index.tsx +353 -0
- package/src/routes/settings.tsx +72 -0
- package/src/routes/tokens.$token.tsx +35 -0
- package/src/routes/tokens.index.tsx +37 -0
- package/src/routes/unregistered.tsx +59 -0
- package/src/routes/users.$user.tsx +13 -0
- package/src/routes/users.index.tsx +37 -0
- package/src/shared/models.ts +55 -0
- package/src/styles/globals.css +4118 -0
- package/src/types.ts +21 -0
|
@@ -0,0 +1,2227 @@
|
|
|
1
|
+
import { C as require_react, E as __toESM, i as useRouter, o as require_jsx_runtime } from "./useStore-DWGPqzXR.js";
|
|
2
|
+
import { E as Link, a as ErrorLine, c as Spinner, d as Toggletip, h as dropdown_menu_exports, i as EmptyState, l as Timestamp, n as ConfirmDialog, o as Modal, p as breakAfterUnderscores, r as CopyButton, s as Notice, t as ConfirmButton, u as Tip } from "./ui-BNzhIAQP.js";
|
|
3
|
+
import { B as RotateBack, C as Key, D as Lock, F as Pause, I as Pencil, J as SyncMark, L as Play, N as MoreHorizontal, R as Plus, V as Search, X as Upload, Y as Terminal, _ as EyeOff, b as Hash, c as AlertTriangle, et as X, g as Eye, i as PageHeader, l as Archive, m as Clock, n as ClosedDoor, q as Sync, s as AlertCircle, t as Card, tt as useLoaderData, x as History } from "./page-BjXk0Ehu.js";
|
|
4
|
+
import { c as CoffreError, d as firstMissing, f as initialValues, l as configFromForm, m as planImport, n as failureMessage, o as uiResult, p as isAsked, s as useCoffre, t as Refusal } from "./coffre-1hxT2E_U.js";
|
|
5
|
+
import { r as toast, t as useAction } from "./use-action-BkJXC5JM.js";
|
|
6
|
+
import { i as SecretReadOnly, o as canRevealSecrets } from "./affordances-BNaXjMOb.js";
|
|
7
|
+
import { t as Route } from "./projects._project._environment-ByEf6pmz.js";
|
|
8
|
+
import { t as secretKeyProblem } from "./validation-BQtqPe2V.js";
|
|
9
|
+
//#region ../core/dist/dotenv.js
|
|
10
|
+
var KEY_RE = /^[A-Za-z_][A-Za-z0-9_]{0,127}$/;
|
|
11
|
+
function parseDotenv(input) {
|
|
12
|
+
const entries = [];
|
|
13
|
+
const problems = [];
|
|
14
|
+
const seen = /* @__PURE__ */ new Set();
|
|
15
|
+
const lines = input.split(/\r\n|\n|\r/);
|
|
16
|
+
for (let index = 0; index < lines.length; index++) {
|
|
17
|
+
const lineNumber = index + 1;
|
|
18
|
+
const trimmed = lines[index].trim();
|
|
19
|
+
if (trimmed === "" || trimmed.startsWith("#")) continue;
|
|
20
|
+
const withoutExport = trimmed.startsWith("export ") ? trimmed.slice(7).trim() : trimmed;
|
|
21
|
+
const equals = withoutExport.indexOf("=");
|
|
22
|
+
if (equals === -1) {
|
|
23
|
+
problems.push({
|
|
24
|
+
line: lineNumber,
|
|
25
|
+
text: trimmed,
|
|
26
|
+
reason: "no \"=\" on this line"
|
|
27
|
+
});
|
|
28
|
+
continue;
|
|
29
|
+
}
|
|
30
|
+
const key = withoutExport.slice(0, equals).trim();
|
|
31
|
+
if (!KEY_RE.test(key)) {
|
|
32
|
+
problems.push({
|
|
33
|
+
line: lineNumber,
|
|
34
|
+
text: key,
|
|
35
|
+
reason: "key must match ^[A-Za-z_][A-Za-z0-9_]*$"
|
|
36
|
+
});
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
39
|
+
let rest = withoutExport.slice(equals + 1).trim();
|
|
40
|
+
let value;
|
|
41
|
+
if (rest.startsWith("\"")) {
|
|
42
|
+
const closing = findClosingQuote(rest, "\"");
|
|
43
|
+
if (closing === -1) {
|
|
44
|
+
problems.push({
|
|
45
|
+
line: lineNumber,
|
|
46
|
+
text: key,
|
|
47
|
+
reason: "unterminated double quote (multi-line values are not supported)"
|
|
48
|
+
});
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
51
|
+
value = unescapeDoubleQuoted(rest.slice(1, closing));
|
|
52
|
+
if (trailingIsSignificant(rest.slice(closing + 1))) {
|
|
53
|
+
problems.push({
|
|
54
|
+
line: lineNumber,
|
|
55
|
+
text: key,
|
|
56
|
+
reason: "unexpected text after the closing quote"
|
|
57
|
+
});
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
} else if (rest.startsWith("'")) {
|
|
61
|
+
const closing = rest.indexOf("'", 1);
|
|
62
|
+
if (closing === -1) {
|
|
63
|
+
problems.push({
|
|
64
|
+
line: lineNumber,
|
|
65
|
+
text: key,
|
|
66
|
+
reason: "unterminated single quote (multi-line values are not supported)"
|
|
67
|
+
});
|
|
68
|
+
continue;
|
|
69
|
+
}
|
|
70
|
+
value = rest.slice(1, closing);
|
|
71
|
+
if (trailingIsSignificant(rest.slice(closing + 1))) {
|
|
72
|
+
problems.push({
|
|
73
|
+
line: lineNumber,
|
|
74
|
+
text: key,
|
|
75
|
+
reason: "unexpected text after the closing quote"
|
|
76
|
+
});
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
} else {
|
|
80
|
+
const comment = rest.indexOf(" #");
|
|
81
|
+
if (comment !== -1) rest = rest.slice(0, comment);
|
|
82
|
+
value = rest.trim();
|
|
83
|
+
}
|
|
84
|
+
if (value.includes("\0")) {
|
|
85
|
+
problems.push({
|
|
86
|
+
line: lineNumber,
|
|
87
|
+
text: key,
|
|
88
|
+
reason: "value contains a NUL byte, which cannot be passed in an environment"
|
|
89
|
+
});
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
if (seen.has(key)) {
|
|
93
|
+
problems.push({
|
|
94
|
+
line: lineNumber,
|
|
95
|
+
text: key,
|
|
96
|
+
reason: "duplicate key in this file"
|
|
97
|
+
});
|
|
98
|
+
continue;
|
|
99
|
+
}
|
|
100
|
+
seen.add(key);
|
|
101
|
+
entries.push({
|
|
102
|
+
key,
|
|
103
|
+
value,
|
|
104
|
+
line: lineNumber
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
return {
|
|
108
|
+
entries,
|
|
109
|
+
problems
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
/** True when what follows a closing quote is neither whitespace nor a comment. */
|
|
113
|
+
function trailingIsSignificant(rest) {
|
|
114
|
+
const trimmed = rest.trim();
|
|
115
|
+
return trimmed !== "" && !trimmed.startsWith("#");
|
|
116
|
+
}
|
|
117
|
+
function findClosingQuote(text, quote) {
|
|
118
|
+
for (let index = 1; index < text.length; index++) {
|
|
119
|
+
if (text[index] === "\\") {
|
|
120
|
+
index++;
|
|
121
|
+
continue;
|
|
122
|
+
}
|
|
123
|
+
if (text[index] === quote) return index;
|
|
124
|
+
}
|
|
125
|
+
return -1;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Expand escapes inside a double-quoted value.
|
|
129
|
+
*
|
|
130
|
+
* Deliberately minimal: only the escapes that are necessary. `\n` and `\r`
|
|
131
|
+
* because multi-line values (PEM keys) cannot otherwise be expressed on one
|
|
132
|
+
* line, and `\\` `\"` `\'` because quoting needs them.
|
|
133
|
+
*
|
|
134
|
+
* EVERYTHING ELSE IS PRESERVED VERBATIM, backslash included. The obvious
|
|
135
|
+
* implementation -- returning the character and dropping the backslash for
|
|
136
|
+
* unknown escapes -- silently mangles credentials: `"C:\path\to\file"` came
|
|
137
|
+
* out as `C:path<TAB>ofile`, and `"\d+\w"` as `d+w`. A secrets store that
|
|
138
|
+
* quietly rewrites what you gave it is worse than one that refuses.
|
|
139
|
+
*
|
|
140
|
+
* A value that should contain no interpretation at all belongs in single
|
|
141
|
+
* quotes, which are literal.
|
|
142
|
+
*/
|
|
143
|
+
function unescapeDoubleQuoted(text) {
|
|
144
|
+
return text.replace(/\\(.)/g, (match, character) => {
|
|
145
|
+
switch (character) {
|
|
146
|
+
case "n": return "\n";
|
|
147
|
+
case "r": return "\r";
|
|
148
|
+
case "\\":
|
|
149
|
+
case "\"":
|
|
150
|
+
case "'": return character;
|
|
151
|
+
default: return match;
|
|
152
|
+
}
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
//#endregion
|
|
156
|
+
//#region src/lib/secret-edit-batch.ts
|
|
157
|
+
var import_react = /* @__PURE__ */ __toESM(require_react(), 1);
|
|
158
|
+
function secretChangeFor(changes, key) {
|
|
159
|
+
return Object.hasOwn(changes, key) ? changes[key] : void 0;
|
|
160
|
+
}
|
|
161
|
+
/** Return true when one save would give two pending edits the same target. */
|
|
162
|
+
function hasSecretEditConflict(active, drafts, changes) {
|
|
163
|
+
const finalActiveKeys = active.filter((entry) => !secretChangeFor(changes, entry.key)?.archived).map((entry) => secretChangeFor(changes, entry.key)?.key.trim() ?? entry.key);
|
|
164
|
+
if (new Set(finalActiveKeys).size !== finalActiveKeys.length) return true;
|
|
165
|
+
const draftKeys = drafts.map((draft) => draft.key.trim());
|
|
166
|
+
if (new Set(draftKeys).size !== draftKeys.length) return true;
|
|
167
|
+
const valueEditTargets = new Set(active.flatMap((entry) => {
|
|
168
|
+
const change = secretChangeFor(changes, entry.key);
|
|
169
|
+
return change !== void 0 && !change.archived && change.value !== null ? [change.key.trim()] : [];
|
|
170
|
+
}));
|
|
171
|
+
if (draftKeys.some((key) => valueEditTargets.has(key))) return true;
|
|
172
|
+
const archivedKeys = new Set(active.filter((entry) => secretChangeFor(changes, entry.key)?.archived).map((entry) => entry.key));
|
|
173
|
+
return draftKeys.some((key) => archivedKeys.has(key));
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Save every pending edit: renames first, one call each, then everything else
|
|
177
|
+
* as one merge patch.
|
|
178
|
+
*
|
|
179
|
+
* The patch is a single transaction, so values, new keys and archives land
|
|
180
|
+
* together or not at all. Renames cannot join it: a merge patch names keys and
|
|
181
|
+
* has no way to move one with its history. A failed rename therefore stops the
|
|
182
|
+
* save before the patch. The renames before it stay done, and every other edit
|
|
183
|
+
* is kept for the retry, a value following its key to the new name.
|
|
184
|
+
*/
|
|
185
|
+
async function applySecretEditBatch({ active, drafts, changes, operations }) {
|
|
186
|
+
const remainingChanges = { ...changes };
|
|
187
|
+
const plan = planEdits(active, drafts, changes);
|
|
188
|
+
if (plan instanceof Error) return {
|
|
189
|
+
applied: 0,
|
|
190
|
+
drafts: [...drafts],
|
|
191
|
+
changes: remainingChanges,
|
|
192
|
+
error: plan
|
|
193
|
+
};
|
|
194
|
+
let applied = 0;
|
|
195
|
+
const patch = Object.create(null);
|
|
196
|
+
try {
|
|
197
|
+
for (const { sourceKey, change } of plan) {
|
|
198
|
+
if (change.archived) {
|
|
199
|
+
patch[sourceKey] = null;
|
|
200
|
+
continue;
|
|
201
|
+
}
|
|
202
|
+
const key = change.key.trim();
|
|
203
|
+
if (key !== sourceKey) {
|
|
204
|
+
await operations.rename(sourceKey, key);
|
|
205
|
+
delete remainingChanges[sourceKey];
|
|
206
|
+
applied += 1;
|
|
207
|
+
if (change.value !== null) remainingChanges[key] = {
|
|
208
|
+
key,
|
|
209
|
+
value: change.value,
|
|
210
|
+
archived: false
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
if (change.value !== null) patch[key] = change.value;
|
|
214
|
+
}
|
|
215
|
+
for (const draft of drafts) patch[draft.key.trim()] = draft.value;
|
|
216
|
+
const written = Object.keys(patch).length;
|
|
217
|
+
if (written > 0) await operations.write({ ...patch });
|
|
218
|
+
return {
|
|
219
|
+
applied: applied + written,
|
|
220
|
+
drafts: [],
|
|
221
|
+
changes: {},
|
|
222
|
+
error: null
|
|
223
|
+
};
|
|
224
|
+
} catch (error) {
|
|
225
|
+
return {
|
|
226
|
+
applied,
|
|
227
|
+
drafts: [...drafts],
|
|
228
|
+
changes: remainingChanges,
|
|
229
|
+
error
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* Put dependent renames in an order that frees each destination first.
|
|
235
|
+
* Cycles and archive-then-restore plans fail before the first mutation.
|
|
236
|
+
*/
|
|
237
|
+
function planEdits(active, drafts, changes) {
|
|
238
|
+
const activeKeys = new Set(active.map((entry) => entry.key));
|
|
239
|
+
const archivedKeys = new Set(active.filter((entry) => secretChangeFor(changes, entry.key)?.archived).map((entry) => entry.key));
|
|
240
|
+
const restoredByDraft = drafts.find((draft) => archivedKeys.has(draft.key.trim()));
|
|
241
|
+
if (restoredByDraft) return /* @__PURE__ */ new Error(`${restoredByDraft.key.trim()}: cannot archive and write the same key in one save`);
|
|
242
|
+
const renames = /* @__PURE__ */ new Map();
|
|
243
|
+
const otherEdits = [];
|
|
244
|
+
for (const entry of active) {
|
|
245
|
+
const change = secretChangeFor(changes, entry.key);
|
|
246
|
+
if (change === void 0) continue;
|
|
247
|
+
if (!change.archived && change.key.trim() !== entry.key) renames.set(entry.key, change);
|
|
248
|
+
else otherEdits.push({
|
|
249
|
+
sourceKey: entry.key,
|
|
250
|
+
change
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
for (const [sourceKey, change] of renames) {
|
|
254
|
+
const destination = change.key.trim();
|
|
255
|
+
if (activeKeys.has(destination) && !renames.has(destination)) return /* @__PURE__ */ new Error(`${sourceKey}: ${destination} is already in use`);
|
|
256
|
+
}
|
|
257
|
+
const orderedRenames = [];
|
|
258
|
+
const freedKeys = /* @__PURE__ */ new Set();
|
|
259
|
+
while (renames.size > 0) {
|
|
260
|
+
const ready = [...renames].find(([, change]) => {
|
|
261
|
+
const destination = change.key.trim();
|
|
262
|
+
return !activeKeys.has(destination) || freedKeys.has(destination);
|
|
263
|
+
});
|
|
264
|
+
if (!ready) return /* @__PURE__ */ new Error("Secret renames contain a cycle. Save them in separate steps.");
|
|
265
|
+
const [sourceKey, change] = ready;
|
|
266
|
+
renames.delete(sourceKey);
|
|
267
|
+
freedKeys.add(sourceKey);
|
|
268
|
+
orderedRenames.push({
|
|
269
|
+
sourceKey,
|
|
270
|
+
change
|
|
271
|
+
});
|
|
272
|
+
}
|
|
273
|
+
return [...orderedRenames, ...otherEdits];
|
|
274
|
+
}
|
|
275
|
+
//#endregion
|
|
276
|
+
//#region src/lib/reveal.ts
|
|
277
|
+
function revealIsCurrent(reveal, currentVersion) {
|
|
278
|
+
return reveal !== null && reveal.version === currentVersion;
|
|
279
|
+
}
|
|
280
|
+
//#endregion
|
|
281
|
+
//#region src/components/syncs.tsx
|
|
282
|
+
var import_jsx_runtime = require_jsx_runtime();
|
|
283
|
+
/** How often the card refreshes while a run is in flight. */
|
|
284
|
+
var RUNNING_POLL_MS = 2e3;
|
|
285
|
+
/** How long a new sync's toast waits for its first push to end. */
|
|
286
|
+
var FIRST_RUN_WAIT_MS = 6e4;
|
|
287
|
+
/**
|
|
288
|
+
* Where this environment's secrets are pushed.
|
|
289
|
+
*
|
|
290
|
+
* Hidden from people who can neither see a sync nor add one; everyone who can
|
|
291
|
+
* write a secret sees them, since saving one sends it on.
|
|
292
|
+
*/
|
|
293
|
+
function Syncs({ project, environment, result, canRun }) {
|
|
294
|
+
const router = useRouter();
|
|
295
|
+
const running = result.ok && result.syncs.some((sync) => sync.running);
|
|
296
|
+
(0, import_react.useEffect)(() => {
|
|
297
|
+
if (!running) return;
|
|
298
|
+
const timer = setInterval(() => void router.invalidate(), RUNNING_POLL_MS);
|
|
299
|
+
return () => clearInterval(timer);
|
|
300
|
+
}, [running, router]);
|
|
301
|
+
if (result.ok && result.syncs.length === 0 && !result.canManage) return null;
|
|
302
|
+
const canManage = result.ok && result.canManage;
|
|
303
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Card, {
|
|
304
|
+
labelledBy: "syncs",
|
|
305
|
+
title: "Syncs",
|
|
306
|
+
description: "Destinations these secrets are pushed to. A change goes out when it is saved, and every hour coffre checks each destination and repairs what drifted.",
|
|
307
|
+
actions: canManage ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(AddSync, {
|
|
308
|
+
project,
|
|
309
|
+
environment
|
|
310
|
+
}) : void 0,
|
|
311
|
+
children: !result.ok ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
|
|
312
|
+
className: "card-body",
|
|
313
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ErrorLine, { error: result.error })
|
|
314
|
+
}) : result.syncs.length === 0 ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(EmptyState, {
|
|
315
|
+
title: "Not synced anywhere",
|
|
316
|
+
children: [
|
|
317
|
+
"Push these secrets where your code runs, such as GitHub Actions or Vercel, and keep them current there. Anything else can read them with ",
|
|
318
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("code", { children: "coffre run" }),
|
|
319
|
+
"."
|
|
320
|
+
]
|
|
321
|
+
}) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
|
|
322
|
+
className: "dt-wrap",
|
|
323
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("table", {
|
|
324
|
+
className: "dt syncs stacks",
|
|
325
|
+
children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("thead", { children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("tr", { children: [
|
|
326
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("th", { children: "Destination" }),
|
|
327
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("th", {
|
|
328
|
+
className: "col-shrink",
|
|
329
|
+
children: "Status"
|
|
330
|
+
}),
|
|
331
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("th", {
|
|
332
|
+
className: "col-shrink col-hide-narrow",
|
|
333
|
+
children: "Token"
|
|
334
|
+
}),
|
|
335
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("th", {
|
|
336
|
+
className: "col-actions",
|
|
337
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
|
|
338
|
+
className: "visually-hidden",
|
|
339
|
+
children: "Actions"
|
|
340
|
+
})
|
|
341
|
+
})
|
|
342
|
+
] }) }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("tbody", { children: result.syncs.map((sync) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(SyncRow, {
|
|
343
|
+
sync,
|
|
344
|
+
canRun,
|
|
345
|
+
canManage
|
|
346
|
+
}, sync.id)) })]
|
|
347
|
+
})
|
|
348
|
+
})
|
|
349
|
+
});
|
|
350
|
+
}
|
|
351
|
+
function SyncRow({ sync, canRun, canManage }) {
|
|
352
|
+
const [removing, setRemoving] = (0, import_react.useState)(false);
|
|
353
|
+
const coffre = useCoffre();
|
|
354
|
+
const pushing = useAction();
|
|
355
|
+
const managing = useAction();
|
|
356
|
+
const pending = pushing.pending || managing.pending;
|
|
357
|
+
const error = pushing.error ?? managing.error;
|
|
358
|
+
function runNow() {
|
|
359
|
+
pushing.run(() => coffre.syncs.run(sync.id), (result) => announce(sync, result.outcome));
|
|
360
|
+
}
|
|
361
|
+
function setPaused(paused) {
|
|
362
|
+
managing.run(() => coffre.syncs.update(sync.id, { paused }), () => toast.success(paused ? `Paused ${sync.destination}` : `Resumed ${sync.destination}`, { action: {
|
|
363
|
+
label: "Undo",
|
|
364
|
+
onClick: () => setPaused(!paused)
|
|
365
|
+
} }));
|
|
366
|
+
}
|
|
367
|
+
const shownError = error ?? (sync.offered ? sync.lastError : null);
|
|
368
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("tr", {
|
|
369
|
+
className: shownError !== null && !sync.running ? "has-error" : void 0,
|
|
370
|
+
children: [
|
|
371
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("td", {
|
|
372
|
+
className: "col-destination",
|
|
373
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", {
|
|
374
|
+
className: "cell-account",
|
|
375
|
+
children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(SyncMark, {
|
|
376
|
+
brand: sync.brand,
|
|
377
|
+
size: 15
|
|
378
|
+
}), /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", {
|
|
379
|
+
className: "cell-stack",
|
|
380
|
+
children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: sync.providerLabel }), sync.offered ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("small", {
|
|
381
|
+
className: "mono",
|
|
382
|
+
children: sync.destination
|
|
383
|
+
}) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)("small", { children: "No longer offered by this deployment" })]
|
|
384
|
+
})]
|
|
385
|
+
})
|
|
386
|
+
}),
|
|
387
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("td", {
|
|
388
|
+
className: "nowrap col-status",
|
|
389
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", {
|
|
390
|
+
className: "cell-stack",
|
|
391
|
+
children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(SyncState, { sync }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("small", { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Counts, { sync }) })]
|
|
392
|
+
})
|
|
393
|
+
}),
|
|
394
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("td", {
|
|
395
|
+
className: "col-shrink col-hide-narrow cell-mono cell-muted",
|
|
396
|
+
children: sync.credential
|
|
397
|
+
}),
|
|
398
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("td", {
|
|
399
|
+
className: "col-actions",
|
|
400
|
+
children: [/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
|
|
401
|
+
className: "acts",
|
|
402
|
+
children: [canRun && !sync.paused && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("button", {
|
|
403
|
+
className: "act",
|
|
404
|
+
onClick: runNow,
|
|
405
|
+
disabled: pending || sync.running || !sync.offered,
|
|
406
|
+
title: sync.offered ? void 0 : "This deployment no longer offers this provider",
|
|
407
|
+
children: [pushing.pending ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Spinner, { size: 13 }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Sync, { size: 13 }), "Run now"]
|
|
408
|
+
}), canManage && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(dropdown_menu_exports.Root, { children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(dropdown_menu_exports.Trigger, {
|
|
409
|
+
asChild: true,
|
|
410
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", {
|
|
411
|
+
className: "act act-icon act-quiet",
|
|
412
|
+
"aria-label": `More for ${sync.destination}`,
|
|
413
|
+
disabled: pending,
|
|
414
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(MoreHorizontal, { size: 16 })
|
|
415
|
+
})
|
|
416
|
+
}), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(dropdown_menu_exports.Portal, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(dropdown_menu_exports.Content, {
|
|
417
|
+
className: "menu",
|
|
418
|
+
sideOffset: 6,
|
|
419
|
+
align: "end",
|
|
420
|
+
children: [
|
|
421
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(dropdown_menu_exports.Item, {
|
|
422
|
+
className: "menu-item",
|
|
423
|
+
onSelect: () => setPaused(!sync.paused),
|
|
424
|
+
children: [sync.paused ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Play, { size: 14 }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Pause, { size: 14 }), sync.paused ? "Resume" : "Pause"]
|
|
425
|
+
}),
|
|
426
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(dropdown_menu_exports.Separator, { className: "menu-sep" }),
|
|
427
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(dropdown_menu_exports.Item, {
|
|
428
|
+
className: "menu-item menu-item-danger",
|
|
429
|
+
onSelect: () => setRemoving(true),
|
|
430
|
+
children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(X, { size: 14 }), "Remove"]
|
|
431
|
+
})
|
|
432
|
+
]
|
|
433
|
+
}) })] })]
|
|
434
|
+
}), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ConfirmDialog, {
|
|
435
|
+
open: removing,
|
|
436
|
+
onOpenChange: setRemoving,
|
|
437
|
+
title: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
|
|
438
|
+
"Stop syncing to ",
|
|
439
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
|
|
440
|
+
className: "mono",
|
|
441
|
+
children: sync.destination
|
|
442
|
+
}),
|
|
443
|
+
"?"
|
|
444
|
+
] }),
|
|
445
|
+
body: `Nothing more is pushed to ${sync.providerLabel}. Keys coffre already pushed stay there; remove them at ${sync.providerLabel} if they should go too.`,
|
|
446
|
+
confirmLabel: "Remove sync",
|
|
447
|
+
onConfirm: () => managing.run(() => coffre.syncs.remove(sync.id), () => toast.success(`No longer syncing to ${sync.destination}`))
|
|
448
|
+
})]
|
|
449
|
+
})
|
|
450
|
+
]
|
|
451
|
+
}), shownError !== null && !sync.running && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("tr", {
|
|
452
|
+
className: "row-error",
|
|
453
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("td", {
|
|
454
|
+
colSpan: 4,
|
|
455
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ErrorLine, { error: shownError })
|
|
456
|
+
})
|
|
457
|
+
})] });
|
|
458
|
+
}
|
|
459
|
+
/** One tag for the state that matters most right now. */
|
|
460
|
+
function SyncState({ sync }) {
|
|
461
|
+
if (!sync.offered) return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
|
|
462
|
+
className: "tag tag-outline",
|
|
463
|
+
children: "Unavailable"
|
|
464
|
+
});
|
|
465
|
+
if (sync.running) return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", {
|
|
466
|
+
className: "tag tag-blue",
|
|
467
|
+
children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Spinner, { size: 11 }), "Pushing"]
|
|
468
|
+
});
|
|
469
|
+
if (sync.paused) return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
|
|
470
|
+
className: "tag tag-outline",
|
|
471
|
+
children: "Paused"
|
|
472
|
+
});
|
|
473
|
+
if (sync.lastStatus === "failed") return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
|
|
474
|
+
className: "tag tag-red",
|
|
475
|
+
children: "Failed"
|
|
476
|
+
});
|
|
477
|
+
if (sync.pending > 0) return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", {
|
|
478
|
+
className: "tag tag-amber",
|
|
479
|
+
children: [sync.pending, " pending"]
|
|
480
|
+
});
|
|
481
|
+
if (sync.lastStatus === "partial") return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
|
|
482
|
+
className: "tag tag-amber",
|
|
483
|
+
children: "Partial"
|
|
484
|
+
});
|
|
485
|
+
if (sync.lastRunAt === null) return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
|
|
486
|
+
className: "tag",
|
|
487
|
+
children: "Not run yet"
|
|
488
|
+
});
|
|
489
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
|
|
490
|
+
className: "tag tag-green",
|
|
491
|
+
children: "In sync"
|
|
492
|
+
});
|
|
493
|
+
}
|
|
494
|
+
function Counts({ sync }) {
|
|
495
|
+
const skipped = sync.skipped.length;
|
|
496
|
+
const parts = [];
|
|
497
|
+
if (sync.synced > 0 || sync.pending === 0) parts.push(`${sync.synced} synced`);
|
|
498
|
+
if (sync.pending > 0) parts.push(`${sync.pending} pending`);
|
|
499
|
+
if (skipped > 0) parts.push(/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Toggletip, {
|
|
500
|
+
label: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("ul", {
|
|
501
|
+
style: {
|
|
502
|
+
margin: 0,
|
|
503
|
+
paddingLeft: "1rem"
|
|
504
|
+
},
|
|
505
|
+
children: sync.skipped.map((entry) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("li", { children: [
|
|
506
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
|
|
507
|
+
className: "mono",
|
|
508
|
+
children: entry.key
|
|
509
|
+
}),
|
|
510
|
+
": ",
|
|
511
|
+
entry.reason
|
|
512
|
+
] }, entry.key))
|
|
513
|
+
}),
|
|
514
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("button", {
|
|
515
|
+
type: "button",
|
|
516
|
+
className: "tag tag-amber tag-button",
|
|
517
|
+
children: [
|
|
518
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(AlertTriangle, { size: 11 }),
|
|
519
|
+
skipped,
|
|
520
|
+
" skipped"
|
|
521
|
+
]
|
|
522
|
+
})
|
|
523
|
+
}));
|
|
524
|
+
if (sync.lastRunAt !== null) parts.push(/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Timestamp, {
|
|
525
|
+
iso: sync.lastRunAt,
|
|
526
|
+
display: "relative"
|
|
527
|
+
}));
|
|
528
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children: parts.map((part, index) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_react.Fragment, { children: [index > 0 && " · ", part] }, index)) });
|
|
529
|
+
}
|
|
530
|
+
function announce(sync, outcome) {
|
|
531
|
+
if (outcome.status === "busy") {
|
|
532
|
+
toast("A run is already under way", { description: "Its result appears here when it ends." });
|
|
533
|
+
return;
|
|
534
|
+
}
|
|
535
|
+
const changed = outcome.upserted.length + outcome.deleted.length;
|
|
536
|
+
if (outcome.status === "failed") toast.error(`Could not sync to ${sync.destination}`, { description: outcome.error ?? void 0 });
|
|
537
|
+
else if (outcome.status === "partial") toast.warning(`${outcome.failed.length} of ${changed + outcome.failed.length} changes failed`, { description: outcome.failed[0]?.message });
|
|
538
|
+
else if (changed === 0) toast.success(`${sync.destination} was already current`);
|
|
539
|
+
else {
|
|
540
|
+
const parts = [outcome.upserted.length > 0 && `pushed ${outcome.upserted.length}`, outcome.deleted.length > 0 && `removed ${outcome.deleted.length}`].filter(Boolean);
|
|
541
|
+
toast.success(`${capitalize(parts.join(", "))} to ${sync.destination}`);
|
|
542
|
+
}
|
|
543
|
+
}
|
|
544
|
+
/**
|
|
545
|
+
* A new sync pushes in the background once it is made. Say so while it does,
|
|
546
|
+
* then say how it went: a green toast beside a row already marked Failed
|
|
547
|
+
* would be telling two stories.
|
|
548
|
+
*/
|
|
549
|
+
async function followFirstRun(coffre, path, sync, refresh) {
|
|
550
|
+
const id = toast.loading(`Pushing to ${sync.destination}`, { description: "The first push is under way." });
|
|
551
|
+
const deadline = Date.now() + FIRST_RUN_WAIT_MS;
|
|
552
|
+
while (Date.now() < deadline) {
|
|
553
|
+
await new Promise((resolve) => setTimeout(resolve, RUNNING_POLL_MS));
|
|
554
|
+
const listed = await uiResult(() => coffre.syncs.list(path));
|
|
555
|
+
const now = listed.ok ? listed.syncs.find((other) => other.id === sync.id) : void 0;
|
|
556
|
+
if (now === void 0 || now.running || now.lastRunAt === null) continue;
|
|
557
|
+
await refresh();
|
|
558
|
+
if (now.lastStatus === "failed") toast.error(`Could not sync to ${sync.destination}`, {
|
|
559
|
+
id,
|
|
560
|
+
description: now.lastError ?? void 0
|
|
561
|
+
});
|
|
562
|
+
else if (now.lastStatus === "partial") toast.warning(`Synced to ${sync.destination}, but not every key`, {
|
|
563
|
+
id,
|
|
564
|
+
description: now.lastError ?? void 0
|
|
565
|
+
});
|
|
566
|
+
else toast.success(`Synced to ${sync.destination}`, {
|
|
567
|
+
id,
|
|
568
|
+
description: `${now.synced} ${now.synced === 1 ? "key is" : "keys are"} there now.`
|
|
569
|
+
});
|
|
570
|
+
return;
|
|
571
|
+
}
|
|
572
|
+
await refresh();
|
|
573
|
+
toast(`Still pushing to ${sync.destination}`, {
|
|
574
|
+
id,
|
|
575
|
+
description: "Its result appears in the list when it ends."
|
|
576
|
+
});
|
|
577
|
+
}
|
|
578
|
+
function capitalize(text) {
|
|
579
|
+
return text.charAt(0).toUpperCase() + text.slice(1);
|
|
580
|
+
}
|
|
581
|
+
function AddSync({ project, environment }) {
|
|
582
|
+
const [open, setOpen] = (0, import_react.useState)(false);
|
|
583
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("button", {
|
|
584
|
+
className: "btn btn-sm",
|
|
585
|
+
onClick: () => setOpen(true),
|
|
586
|
+
children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Plus, { size: 14 }), "Add sync"]
|
|
587
|
+
}), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Modal, {
|
|
588
|
+
open,
|
|
589
|
+
onOpenChange: setOpen,
|
|
590
|
+
title: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: ["Sync ", /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", {
|
|
591
|
+
className: "mono",
|
|
592
|
+
children: [
|
|
593
|
+
project,
|
|
594
|
+
"/",
|
|
595
|
+
environment
|
|
596
|
+
]
|
|
597
|
+
})] }),
|
|
598
|
+
description: "Every key in this environment is pushed to the destination and kept current. coffre only ever removes keys it pushed itself.",
|
|
599
|
+
wide: true,
|
|
600
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(SyncProviders, { children: (providers) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(AddSyncForm, {
|
|
601
|
+
project,
|
|
602
|
+
environment,
|
|
603
|
+
providers,
|
|
604
|
+
onDone: () => setOpen(false)
|
|
605
|
+
}) })
|
|
606
|
+
})] });
|
|
607
|
+
}
|
|
608
|
+
/** Where this instance can sync to, as the deployment lists it. */
|
|
609
|
+
function SyncProviders({ children }) {
|
|
610
|
+
const coffre = useCoffre();
|
|
611
|
+
const [offered, setOffered] = (0, import_react.useState)(null);
|
|
612
|
+
(0, import_react.useEffect)(() => {
|
|
613
|
+
let live = true;
|
|
614
|
+
uiResult(() => coffre.syncs.providers()).then((result) => {
|
|
615
|
+
if (live) setOffered(result);
|
|
616
|
+
});
|
|
617
|
+
return () => {
|
|
618
|
+
live = false;
|
|
619
|
+
};
|
|
620
|
+
}, [coffre]);
|
|
621
|
+
if (offered === null) return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("p", {
|
|
622
|
+
className: "picker-empty sync-providers-state",
|
|
623
|
+
children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Spinner, { size: 13 }), "Loading where coffre can sync to…"]
|
|
624
|
+
});
|
|
625
|
+
if (!offered.ok) return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
|
|
626
|
+
className: "sync-providers-state",
|
|
627
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ErrorLine, { error: offered.error })
|
|
628
|
+
});
|
|
629
|
+
if (offered.providers.length === 0) return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("p", {
|
|
630
|
+
className: "picker-empty sync-providers-state",
|
|
631
|
+
children: [
|
|
632
|
+
"This instance offers nowhere to sync to. Whoever runs coffre lists the providers in its",
|
|
633
|
+
" ",
|
|
634
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
|
|
635
|
+
className: "mono",
|
|
636
|
+
children: "syncs"
|
|
637
|
+
}),
|
|
638
|
+
" settings."
|
|
639
|
+
]
|
|
640
|
+
});
|
|
641
|
+
return children(offered.providers);
|
|
642
|
+
}
|
|
643
|
+
function AddSyncForm({ project, environment, providers, onDone }) {
|
|
644
|
+
const [provider, setProvider] = (0, import_react.useState)(providers[0]);
|
|
645
|
+
const [values, setValues] = (0, import_react.useState)(() => initialValues(providers[0]));
|
|
646
|
+
const [credential, setCredential] = (0, import_react.useState)("");
|
|
647
|
+
const coffre = useCoffre();
|
|
648
|
+
const router = useRouter();
|
|
649
|
+
const { pending, error, setError, run } = useAction();
|
|
650
|
+
const missing = firstMissing(provider, values);
|
|
651
|
+
function pick(next) {
|
|
652
|
+
setProvider(next);
|
|
653
|
+
setValues(initialValues(next));
|
|
654
|
+
setError(null);
|
|
655
|
+
}
|
|
656
|
+
function set(name, value) {
|
|
657
|
+
setValues((current) => ({
|
|
658
|
+
...current,
|
|
659
|
+
[name]: value
|
|
660
|
+
}));
|
|
661
|
+
}
|
|
662
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("form", {
|
|
663
|
+
className: "form",
|
|
664
|
+
style: { marginTop: "1.25rem" },
|
|
665
|
+
onSubmit: (event) => {
|
|
666
|
+
event.preventDefault();
|
|
667
|
+
run(() => coffre.syncs.add(`${project}/${environment}`, {
|
|
668
|
+
provider: provider.id,
|
|
669
|
+
config: configFromForm(provider, values),
|
|
670
|
+
credential: credential.trim()
|
|
671
|
+
}), (sync) => {
|
|
672
|
+
onDone();
|
|
673
|
+
followFirstRun(coffre, `${project}/${environment}`, sync, () => router.invalidate());
|
|
674
|
+
});
|
|
675
|
+
},
|
|
676
|
+
children: [
|
|
677
|
+
providers.length > 1 && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
|
|
678
|
+
className: "choice-grid sync-providers",
|
|
679
|
+
role: "group",
|
|
680
|
+
"aria-label": "Destination",
|
|
681
|
+
children: providers.map((option) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("button", {
|
|
682
|
+
type: "button",
|
|
683
|
+
className: "choice",
|
|
684
|
+
"aria-pressed": option.id === provider.id,
|
|
685
|
+
onClick: () => pick(option),
|
|
686
|
+
children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(SyncMark, { brand: option.brand }), option.label]
|
|
687
|
+
}, option.id))
|
|
688
|
+
}),
|
|
689
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
|
|
690
|
+
className: "form-row",
|
|
691
|
+
children: provider.fields.map((field) => {
|
|
692
|
+
if (!isAsked(field, values)) return null;
|
|
693
|
+
if (field.type === "text") return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("label", {
|
|
694
|
+
className: "field",
|
|
695
|
+
children: [
|
|
696
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", {
|
|
697
|
+
className: "label",
|
|
698
|
+
children: [field.label, field.optional === true && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
|
|
699
|
+
className: "hint",
|
|
700
|
+
children: " (optional)"
|
|
701
|
+
})]
|
|
702
|
+
}),
|
|
703
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("input", {
|
|
704
|
+
className: "input input-mono",
|
|
705
|
+
value: values[field.name],
|
|
706
|
+
placeholder: field.placeholder,
|
|
707
|
+
spellCheck: false,
|
|
708
|
+
autoComplete: "off",
|
|
709
|
+
onChange: (event) => set(field.name, event.target.value)
|
|
710
|
+
}),
|
|
711
|
+
field.hint !== void 0 && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
|
|
712
|
+
className: "hint",
|
|
713
|
+
children: field.hint
|
|
714
|
+
})
|
|
715
|
+
]
|
|
716
|
+
}, `${provider.id}.${field.name}`);
|
|
717
|
+
const picked = values[field.name];
|
|
718
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
|
|
719
|
+
className: "field field-options",
|
|
720
|
+
role: "group",
|
|
721
|
+
"aria-label": field.label,
|
|
722
|
+
children: [
|
|
723
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
|
|
724
|
+
className: "label",
|
|
725
|
+
children: field.label
|
|
726
|
+
}),
|
|
727
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
|
|
728
|
+
className: "segmented",
|
|
729
|
+
children: field.options.map((option) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", {
|
|
730
|
+
type: "button",
|
|
731
|
+
"aria-pressed": picked.includes(option.value),
|
|
732
|
+
onClick: () => set(field.name, !field.multiple ? [option.value] : picked.includes(option.value) ? picked.filter((value) => value !== option.value) : [...picked, option.value]),
|
|
733
|
+
children: option.label
|
|
734
|
+
}, option.value))
|
|
735
|
+
}),
|
|
736
|
+
field.hint !== void 0 && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
|
|
737
|
+
className: "hint",
|
|
738
|
+
children: field.hint
|
|
739
|
+
})
|
|
740
|
+
]
|
|
741
|
+
}, `${provider.id}.${field.name}`);
|
|
742
|
+
})
|
|
743
|
+
}),
|
|
744
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("label", {
|
|
745
|
+
className: "field",
|
|
746
|
+
children: [
|
|
747
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
|
|
748
|
+
className: "label",
|
|
749
|
+
children: "Token"
|
|
750
|
+
}),
|
|
751
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("input", {
|
|
752
|
+
className: "input input-mono",
|
|
753
|
+
value: credential,
|
|
754
|
+
placeholder: provider.credential.placeholder,
|
|
755
|
+
spellCheck: false,
|
|
756
|
+
autoComplete: "off",
|
|
757
|
+
onChange: (event) => setCredential(event.target.value)
|
|
758
|
+
}),
|
|
759
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", {
|
|
760
|
+
className: "hint",
|
|
761
|
+
children: [
|
|
762
|
+
"The secret that holds it, as ",
|
|
763
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("code", { children: "project/environment/KEY" }),
|
|
764
|
+
". An environment of its own, such as ",
|
|
765
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("code", { children: "ops/sync" }),
|
|
766
|
+
", keeps it from everyone who reads these secrets. You need read access to it."
|
|
767
|
+
]
|
|
768
|
+
})
|
|
769
|
+
]
|
|
770
|
+
}),
|
|
771
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Notice, {
|
|
772
|
+
tone: "info",
|
|
773
|
+
children: provider.credential.hint
|
|
774
|
+
}),
|
|
775
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(ErrorLine, { error }),
|
|
776
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
|
|
777
|
+
className: "dialog-actions",
|
|
778
|
+
children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", {
|
|
779
|
+
className: "btn",
|
|
780
|
+
type: "button",
|
|
781
|
+
onClick: onDone,
|
|
782
|
+
children: "Cancel"
|
|
783
|
+
}), /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("button", {
|
|
784
|
+
className: "btn btn-primary",
|
|
785
|
+
type: "submit",
|
|
786
|
+
disabled: pending || missing !== null || credential.trim() === "",
|
|
787
|
+
title: missing !== null ? `${missing} is required` : void 0,
|
|
788
|
+
children: [pending && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Spinner, {}), "Start syncing"]
|
|
789
|
+
})]
|
|
790
|
+
})
|
|
791
|
+
]
|
|
792
|
+
});
|
|
793
|
+
}
|
|
794
|
+
//#endregion
|
|
795
|
+
//#region src/routes/projects.$project.$environment.tsx?tsr-split=component
|
|
796
|
+
/**
|
|
797
|
+
* How long a revealed value stays on screen.
|
|
798
|
+
*
|
|
799
|
+
* A revealed secret is live credential material sitting in a browser tab that
|
|
800
|
+
* may well be shared on a call. Hiding it again costs nothing -- the read is
|
|
801
|
+
* already logged, and re-revealing writes a second, honest audit row.
|
|
802
|
+
*/
|
|
803
|
+
var REVEAL_TTL_SECONDS = 45;
|
|
804
|
+
function EnvironmentPage() {
|
|
805
|
+
const { keys: result, syncs } = Route.useLoaderData();
|
|
806
|
+
const { project, environment } = Route.useParams();
|
|
807
|
+
if (!result.ok) return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ClosedDoor, {
|
|
808
|
+
icon: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Lock, { size: 18 }),
|
|
809
|
+
label: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", {
|
|
810
|
+
className: "mono",
|
|
811
|
+
children: [
|
|
812
|
+
project,
|
|
813
|
+
"/",
|
|
814
|
+
environment
|
|
815
|
+
]
|
|
816
|
+
}),
|
|
817
|
+
title: "This environment is closed to you",
|
|
818
|
+
actions: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Link, {
|
|
819
|
+
className: "btn",
|
|
820
|
+
to: "/projects/$project",
|
|
821
|
+
params: { project },
|
|
822
|
+
children: ["Back to ", project]
|
|
823
|
+
}),
|
|
824
|
+
children: result.error
|
|
825
|
+
});
|
|
826
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(EnvironmentLedger, {
|
|
827
|
+
project,
|
|
828
|
+
environment,
|
|
829
|
+
permissions: result.permissions,
|
|
830
|
+
keys: result.keys,
|
|
831
|
+
syncs
|
|
832
|
+
}, `${project}/${environment}`);
|
|
833
|
+
}
|
|
834
|
+
function EnvironmentLedger({ project, environment, permissions, keys, syncs }) {
|
|
835
|
+
const router = useRouter();
|
|
836
|
+
const coffre = useCoffre();
|
|
837
|
+
const place = `${project}/${environment}`;
|
|
838
|
+
const [drafts, setDrafts] = (0, import_react.useState)([]);
|
|
839
|
+
const [changes, setChanges] = (0, import_react.useState)({});
|
|
840
|
+
const [editing, setEditing] = (0, import_react.useState)(() => /* @__PURE__ */ new Set());
|
|
841
|
+
const [saving, setSaving] = (0, import_react.useState)(false);
|
|
842
|
+
const [saveError, setSaveError] = (0, import_react.useState)(null);
|
|
843
|
+
const [query, setQuery] = (0, import_react.useState)(Route.useSearch().filter ?? "");
|
|
844
|
+
const nextDraftId = (0, import_react.useRef)(0);
|
|
845
|
+
const canWrite = permissions.includes("secret.write");
|
|
846
|
+
const canArchive = permissions.includes("secret.archive");
|
|
847
|
+
const canReveal = canRevealSecrets(permissions);
|
|
848
|
+
const active = keys.filter((entry) => !entry.archived);
|
|
849
|
+
const archived = keys.filter((entry) => entry.archived);
|
|
850
|
+
const existing = new Set(keys.map((entry) => entry.key));
|
|
851
|
+
const changedEntries = active.filter((entry) => secretChangeFor(changes, entry.key) !== void 0);
|
|
852
|
+
const hasConflict = hasSecretEditConflict(active, drafts, changes);
|
|
853
|
+
const pendingNames = [...drafts.map((row) => row.key.trim()), ...changedEntries.flatMap((entry) => {
|
|
854
|
+
const change = secretChangeFor(changes, entry.key);
|
|
855
|
+
return change === void 0 || change.archived ? [] : [change.key.trim()];
|
|
856
|
+
})];
|
|
857
|
+
const unnamed = pendingNames.some((name) => name === "");
|
|
858
|
+
const invalid = pendingNames.some((name) => name !== "" && secretKeyProblem(name) !== null);
|
|
859
|
+
const pendingCount = drafts.length + changedEntries.length;
|
|
860
|
+
const ready = pendingCount > 0 && !unnamed && !invalid && !hasConflict;
|
|
861
|
+
function patchChange(entry, patch) {
|
|
862
|
+
setChanges((current) => {
|
|
863
|
+
const next = {
|
|
864
|
+
...secretChangeFor(current, entry.key) ?? {
|
|
865
|
+
key: entry.key,
|
|
866
|
+
value: null,
|
|
867
|
+
archived: false
|
|
868
|
+
},
|
|
869
|
+
...patch
|
|
870
|
+
};
|
|
871
|
+
if (next.key !== entry.key || next.value !== null || next.archived) return {
|
|
872
|
+
...current,
|
|
873
|
+
[entry.key]: next
|
|
874
|
+
};
|
|
875
|
+
const { [entry.key]: _, ...rest } = current;
|
|
876
|
+
return rest;
|
|
877
|
+
});
|
|
878
|
+
}
|
|
879
|
+
function dropChange(key) {
|
|
880
|
+
setChanges((current) => {
|
|
881
|
+
const { [key]: _, ...rest } = current;
|
|
882
|
+
return rest;
|
|
883
|
+
});
|
|
884
|
+
setEditing((current) => {
|
|
885
|
+
const next = new Set(current);
|
|
886
|
+
next.delete(key);
|
|
887
|
+
return next;
|
|
888
|
+
});
|
|
889
|
+
}
|
|
890
|
+
function addDraft() {
|
|
891
|
+
setDrafts((rows) => [{
|
|
892
|
+
id: nextDraftId.current++,
|
|
893
|
+
key: "",
|
|
894
|
+
value: ""
|
|
895
|
+
}, ...rows]);
|
|
896
|
+
}
|
|
897
|
+
function discardAll() {
|
|
898
|
+
setDrafts([]);
|
|
899
|
+
setChanges({});
|
|
900
|
+
setEditing(/* @__PURE__ */ new Set());
|
|
901
|
+
setSaveError(null);
|
|
902
|
+
}
|
|
903
|
+
/**
|
|
904
|
+
* Write every pending edit: renames one by one, then the rest as one patch
|
|
905
|
+
* that lands whole or not at all (see `applySecretEditBatch`). Whatever did
|
|
906
|
+
* not land stays pending, so pressing save again retries exactly that.
|
|
907
|
+
*/
|
|
908
|
+
async function saveChanges() {
|
|
909
|
+
if (!ready || saving) return;
|
|
910
|
+
setSaving(true);
|
|
911
|
+
setSaveError(null);
|
|
912
|
+
const outcome = await applySecretEditBatch({
|
|
913
|
+
active,
|
|
914
|
+
drafts,
|
|
915
|
+
changes,
|
|
916
|
+
operations: {
|
|
917
|
+
rename: async (key, nextKey) => {
|
|
918
|
+
try {
|
|
919
|
+
await coffre.secrets.rename(`${place}/${key}`, nextKey);
|
|
920
|
+
} catch (error) {
|
|
921
|
+
throw new Refusal(`${key}: ${failureMessage(error)}`);
|
|
922
|
+
}
|
|
923
|
+
},
|
|
924
|
+
write: async (patch) => {
|
|
925
|
+
try {
|
|
926
|
+
await coffre.secrets.set(place, patch);
|
|
927
|
+
} catch (error) {
|
|
928
|
+
throw new Refusal(failureMessage(error));
|
|
929
|
+
}
|
|
930
|
+
}
|
|
931
|
+
}
|
|
932
|
+
});
|
|
933
|
+
setDrafts(outcome.drafts);
|
|
934
|
+
setChanges(outcome.changes);
|
|
935
|
+
setEditing(/* @__PURE__ */ new Set());
|
|
936
|
+
if (outcome.applied > 0) try {
|
|
937
|
+
await router.invalidate();
|
|
938
|
+
} catch {
|
|
939
|
+
setSaveError("Saved, but the page could not refresh. Reload before you retry.");
|
|
940
|
+
setSaving(false);
|
|
941
|
+
return;
|
|
942
|
+
}
|
|
943
|
+
if (outcome.error === null) toast.success(`Saved ${pendingCount} change${pendingCount === 1 ? "" : "s"}`);
|
|
944
|
+
else {
|
|
945
|
+
const message = outcome.error instanceof Error ? outcome.error.message : "The request could not be sent.";
|
|
946
|
+
setSaveError(outcome.applied === 0 ? message : `${message} The renames before it were saved; nothing else was, and the rest is ready to retry.`);
|
|
947
|
+
}
|
|
948
|
+
setSaving(false);
|
|
949
|
+
}
|
|
950
|
+
const saveRef = (0, import_react.useRef)(saveChanges);
|
|
951
|
+
saveRef.current = saveChanges;
|
|
952
|
+
(0, import_react.useEffect)(() => {
|
|
953
|
+
if (pendingCount === 0) return;
|
|
954
|
+
function onKeyDown(event) {
|
|
955
|
+
if (event.key === "Enter" && (event.metaKey || event.ctrlKey)) {
|
|
956
|
+
event.preventDefault();
|
|
957
|
+
saveRef.current();
|
|
958
|
+
}
|
|
959
|
+
}
|
|
960
|
+
document.addEventListener("keydown", onKeyDown);
|
|
961
|
+
return () => document.removeEventListener("keydown", onKeyDown);
|
|
962
|
+
}, [pendingCount]);
|
|
963
|
+
const pending = [...drafts.map((draft) => ({
|
|
964
|
+
key: draft.key.trim() || "unnamed",
|
|
965
|
+
what: existing.has(draft.key.trim()) ? "new version" : "added"
|
|
966
|
+
})), ...changedEntries.map((entry) => {
|
|
967
|
+
const change = secretChangeFor(changes, entry.key);
|
|
968
|
+
if (change.archived) return {
|
|
969
|
+
key: entry.key,
|
|
970
|
+
what: "archived"
|
|
971
|
+
};
|
|
972
|
+
const renamed = change.key.trim() !== entry.key;
|
|
973
|
+
if (renamed && change.value !== null) return {
|
|
974
|
+
key: entry.key,
|
|
975
|
+
what: `→ ${change.key.trim()}, new value`
|
|
976
|
+
};
|
|
977
|
+
if (renamed) return {
|
|
978
|
+
key: entry.key,
|
|
979
|
+
what: `→ ${change.key.trim()}`
|
|
980
|
+
};
|
|
981
|
+
return {
|
|
982
|
+
key: entry.key,
|
|
983
|
+
what: "new value"
|
|
984
|
+
};
|
|
985
|
+
})];
|
|
986
|
+
const problem = unnamed ? null : hasConflict ? "Two pending edits would end up with the same name. Secret names are unique in an environment." : invalid ? "Names are letters, digits and underscores, and cannot start with a digit." : null;
|
|
987
|
+
const needle = query.trim().toLowerCase();
|
|
988
|
+
const listed = needle === "" ? active : active.filter((entry) => entry.key.toLowerCase().includes(needle));
|
|
989
|
+
const columns = 6;
|
|
990
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
|
|
991
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(PageHeader, {
|
|
992
|
+
tile: project,
|
|
993
|
+
title: environment,
|
|
994
|
+
aside: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(EnvironmentName, {
|
|
995
|
+
project,
|
|
996
|
+
environment
|
|
997
|
+
}),
|
|
998
|
+
actions: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [canWrite && canReveal && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ImportEnv, {
|
|
999
|
+
project,
|
|
1000
|
+
environment
|
|
1001
|
+
}), canWrite && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("button", {
|
|
1002
|
+
className: "btn btn-primary",
|
|
1003
|
+
onClick: addDraft,
|
|
1004
|
+
disabled: saving,
|
|
1005
|
+
children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Plus, { size: 14 }), "New secret"]
|
|
1006
|
+
})] })
|
|
1007
|
+
}),
|
|
1008
|
+
(active.length > 0 || drafts.length > 0) && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
|
|
1009
|
+
className: "toolbar",
|
|
1010
|
+
children: [/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("label", {
|
|
1011
|
+
className: "filter input-group",
|
|
1012
|
+
children: [
|
|
1013
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
|
|
1014
|
+
className: "visually-hidden",
|
|
1015
|
+
children: "Filter secrets by name"
|
|
1016
|
+
}),
|
|
1017
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Search, {
|
|
1018
|
+
size: 14,
|
|
1019
|
+
className: "input-icon"
|
|
1020
|
+
}),
|
|
1021
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("input", {
|
|
1022
|
+
className: "input",
|
|
1023
|
+
type: "search",
|
|
1024
|
+
placeholder: "Filter by name…",
|
|
1025
|
+
spellCheck: false,
|
|
1026
|
+
autoComplete: "off",
|
|
1027
|
+
value: query,
|
|
1028
|
+
onChange: (event) => setQuery(event.target.value)
|
|
1029
|
+
})
|
|
1030
|
+
]
|
|
1031
|
+
}), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
|
|
1032
|
+
className: "toolbar-meta",
|
|
1033
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", {
|
|
1034
|
+
className: "th",
|
|
1035
|
+
title: "Run a process with these secrets in its environment",
|
|
1036
|
+
children: [
|
|
1037
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Terminal, { size: 14 }),
|
|
1038
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("code", { children: [
|
|
1039
|
+
"coffre run ",
|
|
1040
|
+
project,
|
|
1041
|
+
"/",
|
|
1042
|
+
environment,
|
|
1043
|
+
" -- …"
|
|
1044
|
+
] }),
|
|
1045
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(CopyButton, {
|
|
1046
|
+
value: `coffre run ${project}/${environment} -- `,
|
|
1047
|
+
label: "Copy command"
|
|
1048
|
+
})
|
|
1049
|
+
]
|
|
1050
|
+
})
|
|
1051
|
+
})]
|
|
1052
|
+
}),
|
|
1053
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("section", {
|
|
1054
|
+
className: "card",
|
|
1055
|
+
"aria-label": "Secrets",
|
|
1056
|
+
children: active.length === 0 && drafts.length === 0 ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(EmptyState, {
|
|
1057
|
+
title: "No secrets yet",
|
|
1058
|
+
actions: canWrite ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("button", {
|
|
1059
|
+
className: "btn btn-primary",
|
|
1060
|
+
onClick: addDraft,
|
|
1061
|
+
children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Plus, { size: 14 }), "New secret"]
|
|
1062
|
+
}), canReveal && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ImportEnv, {
|
|
1063
|
+
project,
|
|
1064
|
+
environment
|
|
1065
|
+
})] }) : void 0,
|
|
1066
|
+
children: canWrite ? "Add them one by one, or import an existing .env file. Nothing is written until you save, or until you have seen the import plan." : "Nothing has been written to this environment, and adding the first secret needs secret.write."
|
|
1067
|
+
}) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
|
|
1068
|
+
className: "dt-wrap",
|
|
1069
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("table", {
|
|
1070
|
+
className: "dt secrets stacks",
|
|
1071
|
+
children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("thead", { children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("tr", { children: [
|
|
1072
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("th", {
|
|
1073
|
+
className: "n",
|
|
1074
|
+
children: "#"
|
|
1075
|
+
}),
|
|
1076
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("th", {
|
|
1077
|
+
className: "col-key",
|
|
1078
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", {
|
|
1079
|
+
className: "th",
|
|
1080
|
+
children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Key, { size: 14 }), "Key"]
|
|
1081
|
+
})
|
|
1082
|
+
}),
|
|
1083
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("th", { children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", {
|
|
1084
|
+
className: "th",
|
|
1085
|
+
children: [
|
|
1086
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Lock, { size: 14 }),
|
|
1087
|
+
"Value",
|
|
1088
|
+
!canReveal && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
|
|
1089
|
+
className: "th-note",
|
|
1090
|
+
children: "hidden from you"
|
|
1091
|
+
})
|
|
1092
|
+
]
|
|
1093
|
+
}) }),
|
|
1094
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("th", {
|
|
1095
|
+
className: "col-version",
|
|
1096
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", {
|
|
1097
|
+
className: "th",
|
|
1098
|
+
children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Hash, { size: 14 }), "Version"]
|
|
1099
|
+
})
|
|
1100
|
+
}),
|
|
1101
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("th", {
|
|
1102
|
+
className: "col-written col-hide-narrow",
|
|
1103
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", {
|
|
1104
|
+
className: "th",
|
|
1105
|
+
children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Clock, { size: 14 }), "Last written"]
|
|
1106
|
+
})
|
|
1107
|
+
}),
|
|
1108
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("th", {
|
|
1109
|
+
className: "col-actions",
|
|
1110
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
|
|
1111
|
+
className: "visually-hidden",
|
|
1112
|
+
children: "Actions"
|
|
1113
|
+
})
|
|
1114
|
+
})
|
|
1115
|
+
] }) }), /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("tbody", { children: [
|
|
1116
|
+
drafts.map((draft) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DraftRow, {
|
|
1117
|
+
draft,
|
|
1118
|
+
existingVersion: keys.find((entry) => entry.key === draft.key.trim())?.version ?? null,
|
|
1119
|
+
disabled: saving,
|
|
1120
|
+
onChange: (patch) => setDrafts((rows) => rows.map((row) => row.id === draft.id ? {
|
|
1121
|
+
...row,
|
|
1122
|
+
...patch
|
|
1123
|
+
} : row)),
|
|
1124
|
+
onRemove: () => setDrafts((rows) => rows.filter((row) => row.id !== draft.id))
|
|
1125
|
+
}, draft.id)),
|
|
1126
|
+
listed.map((entry) => {
|
|
1127
|
+
const change = secretChangeFor(changes, entry.key);
|
|
1128
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(SecretRow, {
|
|
1129
|
+
number: active.indexOf(entry) + 1,
|
|
1130
|
+
project,
|
|
1131
|
+
environment,
|
|
1132
|
+
entry,
|
|
1133
|
+
change: change ?? {
|
|
1134
|
+
key: entry.key,
|
|
1135
|
+
value: null,
|
|
1136
|
+
archived: false
|
|
1137
|
+
},
|
|
1138
|
+
editing: change?.archived !== true && (editing.has(entry.key) || change !== void 0),
|
|
1139
|
+
canWrite,
|
|
1140
|
+
canArchive,
|
|
1141
|
+
canReveal,
|
|
1142
|
+
disabled: saving,
|
|
1143
|
+
columns,
|
|
1144
|
+
onEdit: () => setEditing((current) => new Set(current).add(entry.key)),
|
|
1145
|
+
onPatch: (patch) => patchChange(entry, patch),
|
|
1146
|
+
onUndo: () => dropChange(entry.key),
|
|
1147
|
+
onMarkArchive: () => {
|
|
1148
|
+
setEditing((current) => {
|
|
1149
|
+
const next = new Set(current);
|
|
1150
|
+
next.delete(entry.key);
|
|
1151
|
+
return next;
|
|
1152
|
+
});
|
|
1153
|
+
setChanges((current) => ({
|
|
1154
|
+
...current,
|
|
1155
|
+
[entry.key]: {
|
|
1156
|
+
key: entry.key,
|
|
1157
|
+
value: null,
|
|
1158
|
+
archived: true
|
|
1159
|
+
}
|
|
1160
|
+
}));
|
|
1161
|
+
}
|
|
1162
|
+
}, entry.key);
|
|
1163
|
+
}),
|
|
1164
|
+
listed.length === 0 && active.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("tr", { children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("td", {
|
|
1165
|
+
colSpan: columns,
|
|
1166
|
+
className: "cell-muted",
|
|
1167
|
+
style: { padding: "1rem" },
|
|
1168
|
+
children: [
|
|
1169
|
+
"No secret name contains “",
|
|
1170
|
+
query.trim(),
|
|
1171
|
+
"”."
|
|
1172
|
+
]
|
|
1173
|
+
}) })
|
|
1174
|
+
] })]
|
|
1175
|
+
})
|
|
1176
|
+
})
|
|
1177
|
+
}),
|
|
1178
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Syncs, {
|
|
1179
|
+
project,
|
|
1180
|
+
environment,
|
|
1181
|
+
result: syncs,
|
|
1182
|
+
canRun: canWrite || permissions.includes("environment.manage")
|
|
1183
|
+
}),
|
|
1184
|
+
archived.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Card, {
|
|
1185
|
+
labelledBy: "archived-secrets",
|
|
1186
|
+
title: "Archived",
|
|
1187
|
+
description: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
|
|
1188
|
+
"Retired, so no longer served or injected by ",
|
|
1189
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("code", { children: "coffre run" }),
|
|
1190
|
+
". Their history and audit trail are intact, and restoring is immediate."
|
|
1191
|
+
] }),
|
|
1192
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
|
|
1193
|
+
className: "dt-wrap",
|
|
1194
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("table", {
|
|
1195
|
+
className: "dt secrets secrets-archived stacks",
|
|
1196
|
+
children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("thead", { children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("tr", { children: [
|
|
1197
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("th", {
|
|
1198
|
+
className: "n",
|
|
1199
|
+
children: "#"
|
|
1200
|
+
}),
|
|
1201
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("th", {
|
|
1202
|
+
className: "col-key",
|
|
1203
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", {
|
|
1204
|
+
className: "th",
|
|
1205
|
+
children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Key, { size: 14 }), "Key"]
|
|
1206
|
+
})
|
|
1207
|
+
}),
|
|
1208
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("th", {
|
|
1209
|
+
className: "col-version",
|
|
1210
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", {
|
|
1211
|
+
className: "th",
|
|
1212
|
+
children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Hash, { size: 14 }), "Version"]
|
|
1213
|
+
})
|
|
1214
|
+
}),
|
|
1215
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("th", {
|
|
1216
|
+
className: "col-written col-hide-narrow",
|
|
1217
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", {
|
|
1218
|
+
className: "th",
|
|
1219
|
+
children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Clock, { size: 14 }), "Last written"]
|
|
1220
|
+
})
|
|
1221
|
+
}),
|
|
1222
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("th", {
|
|
1223
|
+
className: "col-actions",
|
|
1224
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
|
|
1225
|
+
className: "visually-hidden",
|
|
1226
|
+
children: "Actions"
|
|
1227
|
+
})
|
|
1228
|
+
})
|
|
1229
|
+
] }) }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("tbody", { children: archived.map((entry, index) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ArchivedRow, {
|
|
1230
|
+
number: index + 1,
|
|
1231
|
+
project,
|
|
1232
|
+
environment,
|
|
1233
|
+
entry,
|
|
1234
|
+
canArchive,
|
|
1235
|
+
canReveal
|
|
1236
|
+
}, entry.key)) })]
|
|
1237
|
+
})
|
|
1238
|
+
})
|
|
1239
|
+
}),
|
|
1240
|
+
pendingCount > 0 && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
|
|
1241
|
+
className: "savebar",
|
|
1242
|
+
role: "region",
|
|
1243
|
+
"aria-label": "Unsaved changes",
|
|
1244
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
|
|
1245
|
+
className: "savebar-inner",
|
|
1246
|
+
children: [
|
|
1247
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", {
|
|
1248
|
+
className: "savebar-count",
|
|
1249
|
+
children: [
|
|
1250
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
|
|
1251
|
+
className: "dot",
|
|
1252
|
+
"aria-hidden": true
|
|
1253
|
+
}),
|
|
1254
|
+
pendingCount,
|
|
1255
|
+
" unsaved change",
|
|
1256
|
+
pendingCount === 1 ? "" : "s"
|
|
1257
|
+
]
|
|
1258
|
+
}),
|
|
1259
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", {
|
|
1260
|
+
className: "savebar-summary",
|
|
1261
|
+
children: [pending.slice(0, 3).map((item, index) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", { children: [
|
|
1262
|
+
index > 0 && " · ",
|
|
1263
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
|
|
1264
|
+
className: "mono",
|
|
1265
|
+
children: item.key
|
|
1266
|
+
}),
|
|
1267
|
+
" ",
|
|
1268
|
+
item.what
|
|
1269
|
+
] }, `${item.key}:${index}`)), pending.length > 3 && ` · and ${pending.length - 3} more`]
|
|
1270
|
+
}),
|
|
1271
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
|
|
1272
|
+
className: "savebar-actions",
|
|
1273
|
+
children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", {
|
|
1274
|
+
className: "btn btn-sm",
|
|
1275
|
+
onClick: discardAll,
|
|
1276
|
+
disabled: saving,
|
|
1277
|
+
children: "Discard"
|
|
1278
|
+
}), /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("button", {
|
|
1279
|
+
className: "btn btn-sm btn-primary",
|
|
1280
|
+
onClick: () => void saveChanges(),
|
|
1281
|
+
disabled: saving || !ready,
|
|
1282
|
+
title: "Save (⌘ Enter or Ctrl Enter)",
|
|
1283
|
+
"aria-keyshortcuts": "Meta+Enter Control+Enter",
|
|
1284
|
+
children: [
|
|
1285
|
+
saving && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Spinner, { size: 13 }),
|
|
1286
|
+
"Save ",
|
|
1287
|
+
pendingCount === 1 ? "change" : `${pendingCount} changes`
|
|
1288
|
+
]
|
|
1289
|
+
})]
|
|
1290
|
+
}),
|
|
1291
|
+
(saveError ?? problem) !== null && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("p", {
|
|
1292
|
+
className: "savebar-error",
|
|
1293
|
+
role: "alert",
|
|
1294
|
+
children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(AlertCircle, { size: 14 }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: saveError ?? problem })]
|
|
1295
|
+
})
|
|
1296
|
+
]
|
|
1297
|
+
})
|
|
1298
|
+
})
|
|
1299
|
+
] });
|
|
1300
|
+
}
|
|
1301
|
+
/** The display name sits beside the slug; it comes from the shell's project tree. */
|
|
1302
|
+
function EnvironmentName({ project, environment }) {
|
|
1303
|
+
const { projects } = useLoaderData({ from: "__root__" });
|
|
1304
|
+
const name = projects.find((entry) => entry.slug === project)?.environments.find((entry) => entry.slug === environment)?.name;
|
|
1305
|
+
return name === void 0 ? null : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children: name });
|
|
1306
|
+
}
|
|
1307
|
+
/**
|
|
1308
|
+
* A text field whose contents are masked until asked, for secret values.
|
|
1309
|
+
*
|
|
1310
|
+
* Where the browser supports it, the mask is CSS on a text input rather than
|
|
1311
|
+
* `type="password"`: password fields invite password managers to offer to
|
|
1312
|
+
* save or fill them, and a secret being typed into coffre is neither.
|
|
1313
|
+
*/
|
|
1314
|
+
function MaskedInput({ masked, className = "", ...props }) {
|
|
1315
|
+
const [cssMask, setCssMask] = (0, import_react.useState)(false);
|
|
1316
|
+
(0, import_react.useEffect)(() => {
|
|
1317
|
+
setCssMask(typeof CSS !== "undefined" && CSS.supports("-webkit-text-security", "disc"));
|
|
1318
|
+
}, []);
|
|
1319
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("input", {
|
|
1320
|
+
...props,
|
|
1321
|
+
type: masked && !cssMask ? "password" : "text",
|
|
1322
|
+
className: `${className}${masked && cssMask ? " is-masked" : ""}`,
|
|
1323
|
+
autoComplete: "off",
|
|
1324
|
+
spellCheck: false,
|
|
1325
|
+
"data-1p-ignore": true,
|
|
1326
|
+
"data-lpignore": "true",
|
|
1327
|
+
"data-bwignore": true
|
|
1328
|
+
});
|
|
1329
|
+
}
|
|
1330
|
+
function ValueField({ label, value, onChange, placeholder, disabled, autoFocus, onEscape }) {
|
|
1331
|
+
const [shown, setShown] = (0, import_react.useState)(false);
|
|
1332
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
|
|
1333
|
+
className: "input-group",
|
|
1334
|
+
children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(MaskedInput, {
|
|
1335
|
+
className: "input input-mono",
|
|
1336
|
+
masked: !shown,
|
|
1337
|
+
"aria-label": label,
|
|
1338
|
+
placeholder,
|
|
1339
|
+
value,
|
|
1340
|
+
disabled,
|
|
1341
|
+
autoFocus,
|
|
1342
|
+
onChange: (event) => onChange(event.target.value),
|
|
1343
|
+
onKeyDown: (event) => {
|
|
1344
|
+
if (event.key === "Escape" && onEscape !== void 0) onEscape();
|
|
1345
|
+
}
|
|
1346
|
+
}), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", {
|
|
1347
|
+
type: "button",
|
|
1348
|
+
className: "btn btn-quiet btn-sm btn-icon input-addon",
|
|
1349
|
+
"aria-label": shown ? "Mask the value" : "Show the value",
|
|
1350
|
+
"aria-pressed": shown,
|
|
1351
|
+
onClick: () => setShown((current) => !current),
|
|
1352
|
+
children: shown ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(EyeOff, { size: 14 }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Eye, { size: 14 })
|
|
1353
|
+
})]
|
|
1354
|
+
});
|
|
1355
|
+
}
|
|
1356
|
+
function useSecondsLeft(reveal) {
|
|
1357
|
+
const [now, setNow] = (0, import_react.useState)(() => Date.now());
|
|
1358
|
+
(0, import_react.useEffect)(() => {
|
|
1359
|
+
if (reveal === null) return;
|
|
1360
|
+
setNow(Date.now());
|
|
1361
|
+
const tick = setInterval(() => setNow(Date.now()), 1e3);
|
|
1362
|
+
return () => clearInterval(tick);
|
|
1363
|
+
}, [reveal]);
|
|
1364
|
+
if (reveal === null) return 0;
|
|
1365
|
+
return Math.max(0, Math.ceil(REVEAL_TTL_SECONDS - (now - reveal.at) / 1e3));
|
|
1366
|
+
}
|
|
1367
|
+
function SecretRow({ number, project, environment, entry, change, editing, canWrite, canArchive, canReveal, disabled, columns, onEdit, onPatch, onUndo, onMarkArchive }) {
|
|
1368
|
+
const [reveal, setReveal] = (0, import_react.useState)(null);
|
|
1369
|
+
const coffre = useCoffre();
|
|
1370
|
+
const [revealing, setRevealing] = (0, import_react.useState)(false);
|
|
1371
|
+
const [historyOpen, setHistoryOpen] = (0, import_react.useState)(false);
|
|
1372
|
+
const [error, setError] = (0, import_react.useState)(null);
|
|
1373
|
+
const [base, setBase] = (0, import_react.useState)(null);
|
|
1374
|
+
const shown = revealIsCurrent(reveal, entry.version) ? reveal : null;
|
|
1375
|
+
(0, import_react.useEffect)(() => {
|
|
1376
|
+
if (reveal !== null && !revealIsCurrent(reveal, entry.version)) setReveal(null);
|
|
1377
|
+
}, [reveal, entry.version]);
|
|
1378
|
+
(0, import_react.useEffect)(() => {
|
|
1379
|
+
if (reveal === null) return;
|
|
1380
|
+
const timer = setTimeout(() => setReveal(null), REVEAL_TTL_SECONDS * 1e3);
|
|
1381
|
+
return () => clearTimeout(timer);
|
|
1382
|
+
}, [reveal]);
|
|
1383
|
+
const secondsLeft = useSecondsLeft(shown);
|
|
1384
|
+
const editBase = editing && revealIsCurrent(base, entry.version) ? base : null;
|
|
1385
|
+
(0, import_react.useEffect)(() => {
|
|
1386
|
+
if (!editing) setBase(null);
|
|
1387
|
+
}, [editing]);
|
|
1388
|
+
async function readValue() {
|
|
1389
|
+
if (shown !== null) return shown.value;
|
|
1390
|
+
setRevealing(true);
|
|
1391
|
+
try {
|
|
1392
|
+
const { values } = await coffre.secrets.reveal(`${project}/${environment}/${entry.key}`);
|
|
1393
|
+
const value = values[entry.key];
|
|
1394
|
+
setError(null);
|
|
1395
|
+
setReveal({
|
|
1396
|
+
value,
|
|
1397
|
+
version: entry.version,
|
|
1398
|
+
at: Date.now()
|
|
1399
|
+
});
|
|
1400
|
+
return value;
|
|
1401
|
+
} catch (failure) {
|
|
1402
|
+
setError(failure instanceof CoffreError ? failureMessage(failure) : "The request could not be sent. Nothing was read.");
|
|
1403
|
+
return null;
|
|
1404
|
+
} finally {
|
|
1405
|
+
setRevealing(false);
|
|
1406
|
+
}
|
|
1407
|
+
}
|
|
1408
|
+
function toggleReveal() {
|
|
1409
|
+
if (shown !== null) setReveal(null);
|
|
1410
|
+
else readValue();
|
|
1411
|
+
}
|
|
1412
|
+
const leaving = change.archived;
|
|
1413
|
+
const renamed = change.key !== entry.key;
|
|
1414
|
+
const valueChanged = change.value !== null;
|
|
1415
|
+
const keyProblem = editing ? secretKeyProblem(change.key.trim()) : null;
|
|
1416
|
+
const state = leaving ? " is-leaving" : editing && (renamed || valueChanged) ? " is-changed" : shown !== null ? " is-revealed" : "";
|
|
1417
|
+
const version = entry.version ?? 0;
|
|
1418
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
|
|
1419
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("tr", {
|
|
1420
|
+
className: `secret-row${state}`,
|
|
1421
|
+
children: [
|
|
1422
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("td", {
|
|
1423
|
+
className: "n",
|
|
1424
|
+
children: number
|
|
1425
|
+
}),
|
|
1426
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("td", {
|
|
1427
|
+
className: "cell-key",
|
|
1428
|
+
"data-label": "Key",
|
|
1429
|
+
children: editing && canWrite ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
|
|
1430
|
+
className: "edit-stack",
|
|
1431
|
+
children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("input", {
|
|
1432
|
+
className: "input input-mono",
|
|
1433
|
+
"aria-label": `Name for ${entry.key}`,
|
|
1434
|
+
"aria-invalid": keyProblem !== null,
|
|
1435
|
+
spellCheck: false,
|
|
1436
|
+
autoComplete: "off",
|
|
1437
|
+
value: change.key,
|
|
1438
|
+
disabled,
|
|
1439
|
+
onChange: (event) => onPatch({ key: event.target.value }),
|
|
1440
|
+
onKeyDown: (event) => {
|
|
1441
|
+
if (event.key === "Escape") onUndo();
|
|
1442
|
+
}
|
|
1443
|
+
}), (keyProblem !== null || renamed) && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
|
|
1444
|
+
className: `edit-note${keyProblem !== null ? " edit-note-error" : ""}`,
|
|
1445
|
+
children: keyProblem ?? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: ["Renamed from ", /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
|
|
1446
|
+
className: "mono",
|
|
1447
|
+
children: entry.key
|
|
1448
|
+
})] })
|
|
1449
|
+
})]
|
|
1450
|
+
}) : /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
|
|
1451
|
+
className: "key-cell",
|
|
1452
|
+
children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: breakAfterUnderscores(entry.key) }), leaving && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
|
|
1453
|
+
className: "tag tag-red",
|
|
1454
|
+
children: "will be archived"
|
|
1455
|
+
})]
|
|
1456
|
+
})
|
|
1457
|
+
}),
|
|
1458
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("td", {
|
|
1459
|
+
"data-label": "Value",
|
|
1460
|
+
children: editing && canWrite ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
|
|
1461
|
+
className: "edit-stack",
|
|
1462
|
+
children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(ValueField, {
|
|
1463
|
+
label: `New value for ${entry.key}`,
|
|
1464
|
+
value: change.value ?? editBase?.value ?? "",
|
|
1465
|
+
placeholder: "New value",
|
|
1466
|
+
disabled,
|
|
1467
|
+
autoFocus: true,
|
|
1468
|
+
onChange: (value) => onPatch({ value: value === (editBase?.value ?? "") ? null : value }),
|
|
1469
|
+
onEscape: onUndo
|
|
1470
|
+
}), /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", {
|
|
1471
|
+
className: "edit-note",
|
|
1472
|
+
children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: valueChanged ? `Saving appends v${version + 1}; v${version} stays restorable.` : editBase !== null ? `This is v${version}. Change it to append v${version + 1}.` : `Nothing is decrypted to edit. Left empty, v${version} stays current.` }), canReveal && !valueChanged && editBase === null && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("button", {
|
|
1473
|
+
type: "button",
|
|
1474
|
+
className: "act",
|
|
1475
|
+
disabled: revealing,
|
|
1476
|
+
onClick: async () => {
|
|
1477
|
+
const value = await readValue();
|
|
1478
|
+
if (value !== null) setBase({
|
|
1479
|
+
value,
|
|
1480
|
+
version: entry.version,
|
|
1481
|
+
at: Date.now()
|
|
1482
|
+
});
|
|
1483
|
+
},
|
|
1484
|
+
children: [revealing && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Spinner, { size: 12 }), "Start from current value"]
|
|
1485
|
+
})]
|
|
1486
|
+
})]
|
|
1487
|
+
}) : shown !== null && !leaving ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
|
|
1488
|
+
className: "revealed",
|
|
1489
|
+
style: { ["--reveal-ttl"]: `${REVEAL_TTL_SECONDS}s` },
|
|
1490
|
+
children: [
|
|
1491
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
|
|
1492
|
+
className: "revealed-value",
|
|
1493
|
+
children: shown.value === "" ? "(empty)" : shown.value
|
|
1494
|
+
}),
|
|
1495
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", {
|
|
1496
|
+
className: "revealed-note",
|
|
1497
|
+
children: [
|
|
1498
|
+
"Hides in ",
|
|
1499
|
+
secondsLeft,
|
|
1500
|
+
"s"
|
|
1501
|
+
]
|
|
1502
|
+
}),
|
|
1503
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
|
|
1504
|
+
className: "revealed-meter",
|
|
1505
|
+
"aria-hidden": true
|
|
1506
|
+
})
|
|
1507
|
+
]
|
|
1508
|
+
}) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
|
|
1509
|
+
className: "mask",
|
|
1510
|
+
"aria-label": "Hidden",
|
|
1511
|
+
children: "••••••••••••"
|
|
1512
|
+
})
|
|
1513
|
+
}),
|
|
1514
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("td", {
|
|
1515
|
+
className: "col-version",
|
|
1516
|
+
"data-label": "Version",
|
|
1517
|
+
children: editing && valueChanged ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", {
|
|
1518
|
+
className: "version-shift",
|
|
1519
|
+
children: [
|
|
1520
|
+
"v",
|
|
1521
|
+
version,
|
|
1522
|
+
" → ",
|
|
1523
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("b", { children: ["v", version + 1] })
|
|
1524
|
+
]
|
|
1525
|
+
}) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
|
|
1526
|
+
className: "version-shift",
|
|
1527
|
+
children: entry.version === null ? "—" : `v${entry.version}`
|
|
1528
|
+
})
|
|
1529
|
+
}),
|
|
1530
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("td", {
|
|
1531
|
+
className: "col-written col-hide-narrow",
|
|
1532
|
+
"data-label": "Last written",
|
|
1533
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Written, { entry })
|
|
1534
|
+
}),
|
|
1535
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("td", {
|
|
1536
|
+
className: "col-actions",
|
|
1537
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
|
|
1538
|
+
className: "acts",
|
|
1539
|
+
children: leaving ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Tip, {
|
|
1540
|
+
label: "Keep",
|
|
1541
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", {
|
|
1542
|
+
className: "act act-icon act-quiet",
|
|
1543
|
+
onClick: onUndo,
|
|
1544
|
+
disabled,
|
|
1545
|
+
"aria-label": `Keep ${entry.key}`,
|
|
1546
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(RotateBack, { size: 14 })
|
|
1547
|
+
})
|
|
1548
|
+
}) : editing ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Tip, {
|
|
1549
|
+
label: renamed || valueChanged ? "Undo changes" : "Cancel",
|
|
1550
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", {
|
|
1551
|
+
className: "act act-icon act-quiet",
|
|
1552
|
+
onClick: onUndo,
|
|
1553
|
+
disabled,
|
|
1554
|
+
"aria-label": `${renamed || valueChanged ? "Undo changes to" : "Stop editing"} ${entry.key}`,
|
|
1555
|
+
children: renamed || valueChanged ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(RotateBack, { size: 14 }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(X, { size: 15 })
|
|
1556
|
+
})
|
|
1557
|
+
}) : /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
|
|
1558
|
+
shown !== null && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(CopyButton, {
|
|
1559
|
+
variant: "act",
|
|
1560
|
+
value: shown.value,
|
|
1561
|
+
label: `Copy ${entry.key}`
|
|
1562
|
+
}),
|
|
1563
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(SecretReadOnly, {
|
|
1564
|
+
canReveal,
|
|
1565
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Tip, {
|
|
1566
|
+
label: shown === null ? "Reveal" : "Hide",
|
|
1567
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", {
|
|
1568
|
+
className: "act act-icon act-accent",
|
|
1569
|
+
onClick: toggleReveal,
|
|
1570
|
+
disabled: revealing,
|
|
1571
|
+
"aria-label": `${shown === null ? "Reveal" : "Hide"} ${entry.key}`,
|
|
1572
|
+
children: revealing ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Spinner, { size: 13 }) : shown === null ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Eye, { size: 15 }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(EyeOff, { size: 15 })
|
|
1573
|
+
})
|
|
1574
|
+
})
|
|
1575
|
+
}),
|
|
1576
|
+
canWrite && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Tip, {
|
|
1577
|
+
label: "Edit",
|
|
1578
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", {
|
|
1579
|
+
className: "act act-icon",
|
|
1580
|
+
onClick: () => {
|
|
1581
|
+
if (shown !== null) setBase(shown);
|
|
1582
|
+
setReveal(null);
|
|
1583
|
+
onEdit();
|
|
1584
|
+
},
|
|
1585
|
+
disabled,
|
|
1586
|
+
"aria-label": `Edit ${entry.key}`,
|
|
1587
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Pencil, { size: 14 })
|
|
1588
|
+
})
|
|
1589
|
+
}),
|
|
1590
|
+
(canReveal || canArchive) && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(dropdown_menu_exports.Root, { children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(dropdown_menu_exports.Trigger, {
|
|
1591
|
+
asChild: true,
|
|
1592
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", {
|
|
1593
|
+
className: "act act-icon act-quiet",
|
|
1594
|
+
"aria-label": `More for ${entry.key}`,
|
|
1595
|
+
disabled,
|
|
1596
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(MoreHorizontal, { size: 16 })
|
|
1597
|
+
})
|
|
1598
|
+
}), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(dropdown_menu_exports.Portal, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(dropdown_menu_exports.Content, {
|
|
1599
|
+
className: "menu",
|
|
1600
|
+
sideOffset: 6,
|
|
1601
|
+
align: "end",
|
|
1602
|
+
children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(SecretReadOnly, {
|
|
1603
|
+
canReveal,
|
|
1604
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(dropdown_menu_exports.Item, {
|
|
1605
|
+
className: "menu-item",
|
|
1606
|
+
onSelect: () => setHistoryOpen((open) => !open),
|
|
1607
|
+
children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(History, { size: 14 }), historyOpen ? "Hide history" : "Version history"]
|
|
1608
|
+
})
|
|
1609
|
+
}), canArchive && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [canReveal && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(dropdown_menu_exports.Separator, { className: "menu-sep" }), /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(dropdown_menu_exports.Item, {
|
|
1610
|
+
className: "menu-item menu-item-danger",
|
|
1611
|
+
onSelect: () => {
|
|
1612
|
+
setReveal(null);
|
|
1613
|
+
onMarkArchive();
|
|
1614
|
+
},
|
|
1615
|
+
children: [
|
|
1616
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Archive, { size: 14 }),
|
|
1617
|
+
"Archive",
|
|
1618
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
|
|
1619
|
+
className: "menu-hint",
|
|
1620
|
+
children: "on save"
|
|
1621
|
+
})
|
|
1622
|
+
]
|
|
1623
|
+
})] })]
|
|
1624
|
+
}) })] })
|
|
1625
|
+
] })
|
|
1626
|
+
})
|
|
1627
|
+
})
|
|
1628
|
+
]
|
|
1629
|
+
}),
|
|
1630
|
+
historyOpen && canReveal && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("tr", {
|
|
1631
|
+
className: "detail-row",
|
|
1632
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("td", {
|
|
1633
|
+
colSpan: columns,
|
|
1634
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(VersionHistory, {
|
|
1635
|
+
project,
|
|
1636
|
+
environment,
|
|
1637
|
+
secretKey: entry.key,
|
|
1638
|
+
currentVersion: entry.version,
|
|
1639
|
+
canWrite,
|
|
1640
|
+
onClose: () => setHistoryOpen(false),
|
|
1641
|
+
onRolledBack: () => setReveal(null)
|
|
1642
|
+
})
|
|
1643
|
+
})
|
|
1644
|
+
}),
|
|
1645
|
+
error !== null && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("tr", {
|
|
1646
|
+
className: "row-error",
|
|
1647
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("td", {
|
|
1648
|
+
colSpan: columns,
|
|
1649
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ErrorLine, { error })
|
|
1650
|
+
})
|
|
1651
|
+
})
|
|
1652
|
+
] });
|
|
1653
|
+
}
|
|
1654
|
+
/**
|
|
1655
|
+
* Who wrote the current version and how long ago, on one line: the local part
|
|
1656
|
+
* of the email is enough to recognise a colleague, and the full address and
|
|
1657
|
+
* the exact time are a hover away.
|
|
1658
|
+
*/
|
|
1659
|
+
function Written({ entry }) {
|
|
1660
|
+
if (entry.updatedBy === null && entry.updatedAt === null) return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
|
|
1661
|
+
className: "cell-muted",
|
|
1662
|
+
children: "—"
|
|
1663
|
+
});
|
|
1664
|
+
const by = entry.updatedBy ?? "unknown";
|
|
1665
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", {
|
|
1666
|
+
className: "written",
|
|
1667
|
+
children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
|
|
1668
|
+
className: "written-by",
|
|
1669
|
+
title: by,
|
|
1670
|
+
children: by.split("@")[0]
|
|
1671
|
+
}), entry.updatedAt !== null && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
|
|
1672
|
+
className: "cell-muted",
|
|
1673
|
+
"aria-hidden": true,
|
|
1674
|
+
children: "·"
|
|
1675
|
+
}), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
|
|
1676
|
+
className: "cell-muted",
|
|
1677
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Timestamp, {
|
|
1678
|
+
iso: entry.updatedAt,
|
|
1679
|
+
display: "relative"
|
|
1680
|
+
})
|
|
1681
|
+
})] })]
|
|
1682
|
+
});
|
|
1683
|
+
}
|
|
1684
|
+
/**
|
|
1685
|
+
* A secret being typed, sitting in the table where it will end up.
|
|
1686
|
+
*
|
|
1687
|
+
* This replaced a separate "Add a secret" form. The form made you look away
|
|
1688
|
+
* from the list to add to it, and only ever accepted one key at a time; a row
|
|
1689
|
+
* in place accepts as many as you want to queue.
|
|
1690
|
+
*/
|
|
1691
|
+
function DraftRow({ draft, existingVersion, disabled, onChange, onRemove }) {
|
|
1692
|
+
const [touched, setTouched] = (0, import_react.useState)(false);
|
|
1693
|
+
const trimmed = draft.key.trim();
|
|
1694
|
+
const keyProblem = trimmed === "" ? touched ? "Give it a name." : null : secretKeyProblem(trimmed);
|
|
1695
|
+
const isNewVersion = trimmed !== "" && existingVersion !== null;
|
|
1696
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("tr", {
|
|
1697
|
+
className: "secret-row is-draft",
|
|
1698
|
+
children: [
|
|
1699
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("td", {
|
|
1700
|
+
className: "n",
|
|
1701
|
+
"aria-label": "New",
|
|
1702
|
+
children: "+"
|
|
1703
|
+
}),
|
|
1704
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("td", {
|
|
1705
|
+
className: "cell-key",
|
|
1706
|
+
"data-label": "New secret",
|
|
1707
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
|
|
1708
|
+
className: "edit-stack",
|
|
1709
|
+
children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("input", {
|
|
1710
|
+
className: "input input-mono",
|
|
1711
|
+
autoFocus: true,
|
|
1712
|
+
"aria-label": "Name of the new secret",
|
|
1713
|
+
"aria-invalid": keyProblem !== null,
|
|
1714
|
+
placeholder: "NAME_OF_SECRET",
|
|
1715
|
+
spellCheck: false,
|
|
1716
|
+
autoComplete: "off",
|
|
1717
|
+
value: draft.key,
|
|
1718
|
+
disabled,
|
|
1719
|
+
onBlur: () => setTouched(true),
|
|
1720
|
+
onChange: (event) => onChange({ key: event.target.value }),
|
|
1721
|
+
onKeyDown: (event) => {
|
|
1722
|
+
if (event.key === "Escape") onRemove();
|
|
1723
|
+
}
|
|
1724
|
+
}), (keyProblem !== null || isNewVersion) && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
|
|
1725
|
+
className: `edit-note${keyProblem !== null ? " edit-note-error" : ""}`,
|
|
1726
|
+
children: keyProblem ?? "This name already exists here. Saving appends a new version to it rather than creating a second secret."
|
|
1727
|
+
})]
|
|
1728
|
+
})
|
|
1729
|
+
}),
|
|
1730
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("td", {
|
|
1731
|
+
"data-label": "Value",
|
|
1732
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
|
|
1733
|
+
className: "edit-stack",
|
|
1734
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ValueField, {
|
|
1735
|
+
label: `Value for ${trimmed === "" ? "the new secret" : trimmed}`,
|
|
1736
|
+
value: draft.value,
|
|
1737
|
+
placeholder: "Value",
|
|
1738
|
+
disabled,
|
|
1739
|
+
onChange: (value) => onChange({ value }),
|
|
1740
|
+
onEscape: onRemove
|
|
1741
|
+
})
|
|
1742
|
+
})
|
|
1743
|
+
}),
|
|
1744
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("td", {
|
|
1745
|
+
className: "col-version",
|
|
1746
|
+
"data-label": "Version",
|
|
1747
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
|
|
1748
|
+
className: "version-shift",
|
|
1749
|
+
children: isNewVersion ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
|
|
1750
|
+
"v",
|
|
1751
|
+
existingVersion,
|
|
1752
|
+
" → ",
|
|
1753
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("b", { children: ["v", existingVersion + 1] })
|
|
1754
|
+
] }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)("b", { children: "new" })
|
|
1755
|
+
})
|
|
1756
|
+
}),
|
|
1757
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("td", {
|
|
1758
|
+
className: "col-written col-hide-narrow",
|
|
1759
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
|
|
1760
|
+
className: "cell-muted",
|
|
1761
|
+
children: "—"
|
|
1762
|
+
})
|
|
1763
|
+
}),
|
|
1764
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("td", {
|
|
1765
|
+
className: "col-actions",
|
|
1766
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
|
|
1767
|
+
className: "acts",
|
|
1768
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Tip, {
|
|
1769
|
+
label: "Remove",
|
|
1770
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", {
|
|
1771
|
+
className: "act act-icon act-quiet",
|
|
1772
|
+
onClick: onRemove,
|
|
1773
|
+
disabled,
|
|
1774
|
+
"aria-label": trimmed === "" ? "Remove this new secret" : `Remove new secret ${trimmed}`,
|
|
1775
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(X, { size: 15 })
|
|
1776
|
+
})
|
|
1777
|
+
})
|
|
1778
|
+
})
|
|
1779
|
+
})
|
|
1780
|
+
]
|
|
1781
|
+
});
|
|
1782
|
+
}
|
|
1783
|
+
function ArchivedRow({ number, project, environment, entry, canArchive, canReveal }) {
|
|
1784
|
+
const [historyOpen, setHistoryOpen] = (0, import_react.useState)(false);
|
|
1785
|
+
const coffre = useCoffre();
|
|
1786
|
+
const { pending, error, run } = useAction();
|
|
1787
|
+
function setArchived(archived) {
|
|
1788
|
+
run(() => coffre.secrets.update(`${project}/${environment}/${entry.key}`, { archived }), () => toast.success(archived ? `${entry.key} archived` : `${entry.key} restored`, { action: {
|
|
1789
|
+
label: "Undo",
|
|
1790
|
+
onClick: () => setArchived(!archived)
|
|
1791
|
+
} }));
|
|
1792
|
+
}
|
|
1793
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
|
|
1794
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("tr", {
|
|
1795
|
+
className: "secret-row is-archived",
|
|
1796
|
+
children: [
|
|
1797
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("td", {
|
|
1798
|
+
className: "n",
|
|
1799
|
+
children: number
|
|
1800
|
+
}),
|
|
1801
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("td", {
|
|
1802
|
+
className: "cell-key",
|
|
1803
|
+
"data-label": "Key",
|
|
1804
|
+
children: breakAfterUnderscores(entry.key)
|
|
1805
|
+
}),
|
|
1806
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("td", {
|
|
1807
|
+
className: "col-version",
|
|
1808
|
+
"data-label": "Version",
|
|
1809
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
|
|
1810
|
+
className: "version-shift",
|
|
1811
|
+
children: entry.version === null ? "—" : `v${entry.version}`
|
|
1812
|
+
})
|
|
1813
|
+
}),
|
|
1814
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("td", {
|
|
1815
|
+
className: "col-written col-hide-narrow",
|
|
1816
|
+
"data-label": "Last written",
|
|
1817
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Written, { entry })
|
|
1818
|
+
}),
|
|
1819
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("td", {
|
|
1820
|
+
className: "col-actions",
|
|
1821
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
|
|
1822
|
+
className: "acts",
|
|
1823
|
+
children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(SecretReadOnly, {
|
|
1824
|
+
canReveal,
|
|
1825
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Tip, {
|
|
1826
|
+
label: historyOpen ? "Hide history" : "Version history",
|
|
1827
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", {
|
|
1828
|
+
className: "act act-icon act-quiet",
|
|
1829
|
+
onClick: () => setHistoryOpen((open) => !open),
|
|
1830
|
+
"aria-label": `${historyOpen ? "Hide history of" : "Version history of"} ${entry.key}`,
|
|
1831
|
+
"aria-expanded": historyOpen,
|
|
1832
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(History, { size: 15 })
|
|
1833
|
+
})
|
|
1834
|
+
})
|
|
1835
|
+
}), canArchive && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Tip, {
|
|
1836
|
+
label: "Restore",
|
|
1837
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", {
|
|
1838
|
+
className: "act act-icon",
|
|
1839
|
+
onClick: () => setArchived(false),
|
|
1840
|
+
disabled: pending,
|
|
1841
|
+
"aria-label": `Restore ${entry.key}`,
|
|
1842
|
+
children: pending ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Spinner, { size: 13 }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(RotateBack, { size: 14 })
|
|
1843
|
+
})
|
|
1844
|
+
})]
|
|
1845
|
+
})
|
|
1846
|
+
})
|
|
1847
|
+
]
|
|
1848
|
+
}),
|
|
1849
|
+
historyOpen && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("tr", {
|
|
1850
|
+
className: "detail-row",
|
|
1851
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("td", {
|
|
1852
|
+
colSpan: 5,
|
|
1853
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(VersionHistory, {
|
|
1854
|
+
project,
|
|
1855
|
+
environment,
|
|
1856
|
+
secretKey: entry.key,
|
|
1857
|
+
currentVersion: entry.version,
|
|
1858
|
+
canWrite: false,
|
|
1859
|
+
onClose: () => setHistoryOpen(false),
|
|
1860
|
+
onRolledBack: () => void 0
|
|
1861
|
+
})
|
|
1862
|
+
})
|
|
1863
|
+
}),
|
|
1864
|
+
error !== null && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("tr", {
|
|
1865
|
+
className: "row-error",
|
|
1866
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("td", {
|
|
1867
|
+
colSpan: 5,
|
|
1868
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ErrorLine, { error })
|
|
1869
|
+
})
|
|
1870
|
+
})
|
|
1871
|
+
] });
|
|
1872
|
+
}
|
|
1873
|
+
function VersionHistory({ project, environment, secretKey, currentVersion, canWrite, onClose, onRolledBack }) {
|
|
1874
|
+
const [versions, setVersions] = (0, import_react.useState)(null);
|
|
1875
|
+
const [loadError, setLoadError] = (0, import_react.useState)(null);
|
|
1876
|
+
const coffre = useCoffre();
|
|
1877
|
+
const { pending, error, run } = useAction();
|
|
1878
|
+
(0, import_react.useEffect)(() => {
|
|
1879
|
+
let cancelled = false;
|
|
1880
|
+
coffre.secrets.history(`${project}/${environment}/${secretKey}`).then((result) => {
|
|
1881
|
+
if (cancelled) return;
|
|
1882
|
+
setVersions(result.versions);
|
|
1883
|
+
setLoadError(null);
|
|
1884
|
+
}).catch((failure) => {
|
|
1885
|
+
if (cancelled) return;
|
|
1886
|
+
setLoadError(failure instanceof CoffreError ? failureMessage(failure) : "The version history could not be loaded.");
|
|
1887
|
+
});
|
|
1888
|
+
return () => {
|
|
1889
|
+
cancelled = true;
|
|
1890
|
+
};
|
|
1891
|
+
}, [
|
|
1892
|
+
coffre,
|
|
1893
|
+
project,
|
|
1894
|
+
environment,
|
|
1895
|
+
secretKey,
|
|
1896
|
+
currentVersion
|
|
1897
|
+
]);
|
|
1898
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
|
|
1899
|
+
className: "history",
|
|
1900
|
+
children: [
|
|
1901
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
|
|
1902
|
+
className: "history-head",
|
|
1903
|
+
children: [/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", {
|
|
1904
|
+
className: "history-title th",
|
|
1905
|
+
children: [
|
|
1906
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(History, { size: 14 }),
|
|
1907
|
+
"Versions of ",
|
|
1908
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
|
|
1909
|
+
className: "mono",
|
|
1910
|
+
children: secretKey
|
|
1911
|
+
})
|
|
1912
|
+
]
|
|
1913
|
+
}), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", {
|
|
1914
|
+
className: "act",
|
|
1915
|
+
onClick: onClose,
|
|
1916
|
+
children: "Close"
|
|
1917
|
+
})]
|
|
1918
|
+
}),
|
|
1919
|
+
loadError !== null ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
|
|
1920
|
+
className: "history-body",
|
|
1921
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ErrorLine, { error: loadError })
|
|
1922
|
+
}) : versions === null ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("p", {
|
|
1923
|
+
className: "hint history-body",
|
|
1924
|
+
children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Spinner, { size: 13 }), " Loading versions…"]
|
|
1925
|
+
}) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
|
|
1926
|
+
className: "dt-wrap",
|
|
1927
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("table", {
|
|
1928
|
+
className: "dt",
|
|
1929
|
+
children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("thead", { children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("tr", { children: [
|
|
1930
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("th", {
|
|
1931
|
+
className: "col-shrink",
|
|
1932
|
+
children: "Version"
|
|
1933
|
+
}),
|
|
1934
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("th", {
|
|
1935
|
+
className: "col-shrink",
|
|
1936
|
+
children: "Written (UTC)"
|
|
1937
|
+
}),
|
|
1938
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("th", { children: "By" }),
|
|
1939
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("th", {
|
|
1940
|
+
className: "col-shrink",
|
|
1941
|
+
children: "Key id"
|
|
1942
|
+
}),
|
|
1943
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("th", {
|
|
1944
|
+
className: "col-actions",
|
|
1945
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
|
|
1946
|
+
className: "visually-hidden",
|
|
1947
|
+
children: "Actions"
|
|
1948
|
+
})
|
|
1949
|
+
})
|
|
1950
|
+
] }) }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("tbody", { children: versions.map((version) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("tr", { children: [
|
|
1951
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("td", {
|
|
1952
|
+
className: "cell-mono nowrap",
|
|
1953
|
+
children: [
|
|
1954
|
+
"v",
|
|
1955
|
+
version.version,
|
|
1956
|
+
" ",
|
|
1957
|
+
version.current && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
|
|
1958
|
+
className: "tag tag-blue",
|
|
1959
|
+
children: "current"
|
|
1960
|
+
})
|
|
1961
|
+
]
|
|
1962
|
+
}),
|
|
1963
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("td", {
|
|
1964
|
+
className: "nowrap",
|
|
1965
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Timestamp, { iso: version.createdAt })
|
|
1966
|
+
}),
|
|
1967
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("td", { children: version.createdBy }),
|
|
1968
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("td", {
|
|
1969
|
+
className: "cell-mono cell-muted nowrap",
|
|
1970
|
+
children: version.kek
|
|
1971
|
+
}),
|
|
1972
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("td", {
|
|
1973
|
+
className: "col-actions",
|
|
1974
|
+
children: canWrite && !version.current && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ConfirmButton, {
|
|
1975
|
+
trigger: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("button", {
|
|
1976
|
+
className: "act",
|
|
1977
|
+
disabled: pending,
|
|
1978
|
+
children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(RotateBack, { size: 13 }), "Roll back"]
|
|
1979
|
+
}),
|
|
1980
|
+
title: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
|
|
1981
|
+
"Roll ",
|
|
1982
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
|
|
1983
|
+
className: "mono",
|
|
1984
|
+
children: secretKey
|
|
1985
|
+
}),
|
|
1986
|
+
" back to v",
|
|
1987
|
+
version.version,
|
|
1988
|
+
"?"
|
|
1989
|
+
] }),
|
|
1990
|
+
body: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
|
|
1991
|
+
"The current pointer moves to v",
|
|
1992
|
+
version.version,
|
|
1993
|
+
". Nothing is copied or deleted, every version stays readable, and the next write continues the numbering forward. Anything reading",
|
|
1994
|
+
" ",
|
|
1995
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", {
|
|
1996
|
+
className: "mono",
|
|
1997
|
+
children: [
|
|
1998
|
+
project,
|
|
1999
|
+
"/",
|
|
2000
|
+
environment
|
|
2001
|
+
]
|
|
2002
|
+
}),
|
|
2003
|
+
" ",
|
|
2004
|
+
"picks up the change immediately."
|
|
2005
|
+
] }),
|
|
2006
|
+
confirmLabel: `Roll back to v${version.version}`,
|
|
2007
|
+
destructive: false,
|
|
2008
|
+
onConfirm: () => run(() => coffre.secrets.restore(`${project}/${environment}/${secretKey}`, version.version), () => {
|
|
2009
|
+
onRolledBack();
|
|
2010
|
+
toast.success(`${secretKey} rolled back to v${version.version}`);
|
|
2011
|
+
})
|
|
2012
|
+
})
|
|
2013
|
+
})
|
|
2014
|
+
] }, version.version)) })]
|
|
2015
|
+
})
|
|
2016
|
+
}),
|
|
2017
|
+
error !== null && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
|
|
2018
|
+
className: "history-body",
|
|
2019
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ErrorLine, { error })
|
|
2020
|
+
}),
|
|
2021
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", {
|
|
2022
|
+
className: "history-note",
|
|
2023
|
+
children: "Metadata only. Listing versions decrypts nothing."
|
|
2024
|
+
})
|
|
2025
|
+
]
|
|
2026
|
+
});
|
|
2027
|
+
}
|
|
2028
|
+
var PLAN_TAG = {
|
|
2029
|
+
added: "tag tag-green",
|
|
2030
|
+
changed: "tag tag-blue",
|
|
2031
|
+
unchanged: "tag"
|
|
2032
|
+
};
|
|
2033
|
+
/** Plan a .env import against what is stored, with a dry run of the write. */
|
|
2034
|
+
async function planEnv(coffre, path, content) {
|
|
2035
|
+
const parsed = parseDotenv(content);
|
|
2036
|
+
if (parsed.entries.length === 0) return {
|
|
2037
|
+
plan: [],
|
|
2038
|
+
changes: {},
|
|
2039
|
+
problems: parsed.problems
|
|
2040
|
+
};
|
|
2041
|
+
return {
|
|
2042
|
+
...await planImport(coffre, path, parsed.entries),
|
|
2043
|
+
problems: parsed.problems
|
|
2044
|
+
};
|
|
2045
|
+
}
|
|
2046
|
+
/**
|
|
2047
|
+
* Bulk import from a .env file.
|
|
2048
|
+
*
|
|
2049
|
+
* Always previews first, with a dry run of the write: the server compares
|
|
2050
|
+
* the file against the current values and answers per key, so no value
|
|
2051
|
+
* reaches this page. Comparing is still reading -- it needs secret.read as
|
|
2052
|
+
* well as secret.write, and the values it opens are logged as reads. Writing
|
|
2053
|
+
* then sends exactly the changes the preview showed, in one patch.
|
|
2054
|
+
*/
|
|
2055
|
+
function ImportEnv({ project, environment }) {
|
|
2056
|
+
const [content, setContent] = (0, import_react.useState)("");
|
|
2057
|
+
const [plan, setPlan] = (0, import_react.useState)(null);
|
|
2058
|
+
const [problems, setProblems] = (0, import_react.useState)([]);
|
|
2059
|
+
const [open, setOpen] = (0, import_react.useState)(false);
|
|
2060
|
+
const coffre = useCoffre();
|
|
2061
|
+
const { pending, error, setError, run } = useAction();
|
|
2062
|
+
const path = `${project}/${environment}`;
|
|
2063
|
+
function preview() {
|
|
2064
|
+
run(() => planEnv(coffre, path, content), (result) => {
|
|
2065
|
+
setProblems(result.problems);
|
|
2066
|
+
setPlan({
|
|
2067
|
+
entries: result.plan,
|
|
2068
|
+
changes: result.changes
|
|
2069
|
+
});
|
|
2070
|
+
});
|
|
2071
|
+
}
|
|
2072
|
+
function apply() {
|
|
2073
|
+
if (plan === null) return;
|
|
2074
|
+
const written = Object.keys(plan.changes).length;
|
|
2075
|
+
run(() => coffre.secrets.set(path, plan.changes), () => {
|
|
2076
|
+
toast.success(`Imported ${written} change${written === 1 ? "" : "s"}`);
|
|
2077
|
+
close();
|
|
2078
|
+
});
|
|
2079
|
+
}
|
|
2080
|
+
function close() {
|
|
2081
|
+
setOpen(false);
|
|
2082
|
+
setPlan(null);
|
|
2083
|
+
setContent("");
|
|
2084
|
+
setProblems([]);
|
|
2085
|
+
setError(null);
|
|
2086
|
+
}
|
|
2087
|
+
const changes = plan?.entries.filter((entry) => entry.action !== "unchanged") ?? [];
|
|
2088
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("button", {
|
|
2089
|
+
className: "btn",
|
|
2090
|
+
onClick: () => setOpen(true),
|
|
2091
|
+
children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Upload, { size: 14 }), "Import .env"]
|
|
2092
|
+
}), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Modal, {
|
|
2093
|
+
open,
|
|
2094
|
+
onOpenChange: (next) => next ? setOpen(true) : close(),
|
|
2095
|
+
title: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
|
|
2096
|
+
"Import into",
|
|
2097
|
+
" ",
|
|
2098
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", {
|
|
2099
|
+
className: "mono",
|
|
2100
|
+
children: [
|
|
2101
|
+
project,
|
|
2102
|
+
"/",
|
|
2103
|
+
environment
|
|
2104
|
+
]
|
|
2105
|
+
})
|
|
2106
|
+
] }),
|
|
2107
|
+
wide: true,
|
|
2108
|
+
description: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children: "Paste a .env file. It is read by the CLI’s own parser, so this page and the CLI cannot disagree about what it means, and malformed lines are reported rather than guessed at. coffre compares it with the current values without sending any to this page." }),
|
|
2109
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
|
|
2110
|
+
className: "form",
|
|
2111
|
+
style: { marginTop: "1.25rem" },
|
|
2112
|
+
children: [
|
|
2113
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("label", {
|
|
2114
|
+
className: "field",
|
|
2115
|
+
children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
|
|
2116
|
+
className: "label",
|
|
2117
|
+
children: "File contents"
|
|
2118
|
+
}), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("textarea", {
|
|
2119
|
+
className: "textarea",
|
|
2120
|
+
autoFocus: true,
|
|
2121
|
+
spellCheck: false,
|
|
2122
|
+
placeholder: "DATABASE_URL=postgres://…\nSTRIPE_KEY=\"sk_live_…\"",
|
|
2123
|
+
value: content,
|
|
2124
|
+
onChange: (event) => {
|
|
2125
|
+
setContent(event.target.value);
|
|
2126
|
+
setPlan(null);
|
|
2127
|
+
setProblems([]);
|
|
2128
|
+
}
|
|
2129
|
+
})]
|
|
2130
|
+
}),
|
|
2131
|
+
plan !== null && plan.entries.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
|
|
2132
|
+
className: "card dt-wrap",
|
|
2133
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("table", {
|
|
2134
|
+
className: "dt",
|
|
2135
|
+
children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("thead", { children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("tr", { children: [
|
|
2136
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("th", { children: "Key" }),
|
|
2137
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("th", {
|
|
2138
|
+
className: "col-shrink",
|
|
2139
|
+
children: "Plan"
|
|
2140
|
+
}),
|
|
2141
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("th", {
|
|
2142
|
+
className: "col-shrink",
|
|
2143
|
+
children: "Current"
|
|
2144
|
+
})
|
|
2145
|
+
] }) }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("tbody", { children: plan.entries.map((entry) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("tr", { children: [
|
|
2146
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("td", {
|
|
2147
|
+
className: "cell-key",
|
|
2148
|
+
children: breakAfterUnderscores(entry.key)
|
|
2149
|
+
}),
|
|
2150
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("td", {
|
|
2151
|
+
className: "col-shrink",
|
|
2152
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
|
|
2153
|
+
className: PLAN_TAG[entry.action],
|
|
2154
|
+
children: entry.action
|
|
2155
|
+
})
|
|
2156
|
+
}),
|
|
2157
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("td", {
|
|
2158
|
+
className: "col-shrink cell-mono cell-muted",
|
|
2159
|
+
children: entry.version === null ? "—" : `v${entry.version}`
|
|
2160
|
+
})
|
|
2161
|
+
] }, entry.key)) })]
|
|
2162
|
+
})
|
|
2163
|
+
}),
|
|
2164
|
+
plan !== null && plan.entries.length > 0 && changes.length === 0 && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Notice, {
|
|
2165
|
+
tone: "good",
|
|
2166
|
+
children: "Every key already has this value. There is nothing to write."
|
|
2167
|
+
}),
|
|
2168
|
+
problems.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Notice, {
|
|
2169
|
+
tone: "bad",
|
|
2170
|
+
children: [/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("strong", { children: [
|
|
2171
|
+
problems.length,
|
|
2172
|
+
" line",
|
|
2173
|
+
problems.length === 1 ? "" : "s",
|
|
2174
|
+
" could not be parsed"
|
|
2175
|
+
] }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("ul", {
|
|
2176
|
+
style: {
|
|
2177
|
+
margin: "0.375rem 0 0",
|
|
2178
|
+
paddingLeft: "1.1rem"
|
|
2179
|
+
},
|
|
2180
|
+
children: problems.map((problem) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("li", { children: [
|
|
2181
|
+
"Line ",
|
|
2182
|
+
problem.line,
|
|
2183
|
+
": ",
|
|
2184
|
+
problem.reason,
|
|
2185
|
+
" ",
|
|
2186
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", {
|
|
2187
|
+
className: "mono",
|
|
2188
|
+
children: [
|
|
2189
|
+
"(",
|
|
2190
|
+
problem.text,
|
|
2191
|
+
")"
|
|
2192
|
+
]
|
|
2193
|
+
})
|
|
2194
|
+
] }, problem.line))
|
|
2195
|
+
})]
|
|
2196
|
+
}),
|
|
2197
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(ErrorLine, { error }),
|
|
2198
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
|
|
2199
|
+
className: "dialog-actions",
|
|
2200
|
+
children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", {
|
|
2201
|
+
className: "btn",
|
|
2202
|
+
onClick: close,
|
|
2203
|
+
children: "Cancel"
|
|
2204
|
+
}), plan === null ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("button", {
|
|
2205
|
+
className: "btn btn-primary",
|
|
2206
|
+
disabled: pending || content.trim() === "",
|
|
2207
|
+
onClick: preview,
|
|
2208
|
+
children: [pending && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Spinner, {}), "Preview changes"]
|
|
2209
|
+
}) : /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("button", {
|
|
2210
|
+
className: "btn btn-primary",
|
|
2211
|
+
disabled: pending || changes.length === 0,
|
|
2212
|
+
onClick: apply,
|
|
2213
|
+
children: [
|
|
2214
|
+
pending && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Spinner, {}),
|
|
2215
|
+
"Write ",
|
|
2216
|
+
changes.length,
|
|
2217
|
+
" change",
|
|
2218
|
+
changes.length === 1 ? "" : "s"
|
|
2219
|
+
]
|
|
2220
|
+
})]
|
|
2221
|
+
})
|
|
2222
|
+
]
|
|
2223
|
+
})
|
|
2224
|
+
})] });
|
|
2225
|
+
}
|
|
2226
|
+
//#endregion
|
|
2227
|
+
export { EnvironmentPage as component };
|