@go-labs-sg/gosh 0.10.0 → 0.11.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/README.md +10 -0
- package/dist/index.js +525 -233
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -41,6 +41,16 @@ bun add --global @go-labs-sg/gosh
|
|
|
41
41
|
gosh version
|
|
42
42
|
```
|
|
43
43
|
|
|
44
|
+
## Secure credential storage
|
|
45
|
+
|
|
46
|
+
`GO_LABS_CLI_CREDENTIAL_ACCOUNT` selects the native credential-store account for this CLI. The default is `default`, preserving existing production logins. The downloadable staging launcher sets it to `staging` so a staging login does not replace the production login; keep the same account value for login and subsequent commands. The launcher also sets `GO_LABS_CLI_SKIP_DOTENV=1`, which skips the CLI's explicit current-directory `.env` load while leaving normal production behavior unchanged.
|
|
47
|
+
|
|
48
|
+
Browser sessions use `Bun.secrets`: macOS Keychain, Windows Credential Manager, or Linux Secret Service. Linux requires libsecret, a reachable user D-Bus session, and an unlocked Secret Service collection. SSH and containers must provide those native prerequisites themselves; `--no-browser` only lets approval happen on another device. Denied D-Bus access is a host permissions/session issue, not something the CLI bypasses.
|
|
49
|
+
|
|
50
|
+
Before requesting approval, login verifies write/read/delete capability with a unique non-secret probe. Native operations have a 10-second process deadline and sanitized errors. Issued credentials are read back and verified; failed persistence attempts remote revocation and reports local and remote cleanup separately. There is no plaintext fallback or external credential-helper configuration.
|
|
51
|
+
|
|
52
|
+
See the [shared authentication contract](../../cli-auth/README.md) for recovery and verification limits.
|
|
53
|
+
|
|
44
54
|
## Authentication
|
|
45
55
|
|
|
46
56
|
```bash
|
package/dist/index.js
CHANGED
|
@@ -35,46 +35,46 @@ var __toESM = (mod, isNodeMode, target) => {
|
|
|
35
35
|
var __commonJS = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
|
|
36
36
|
var __require = import.meta.require;
|
|
37
37
|
|
|
38
|
-
// ../../../node_modules/.bun/dotenv@18.0.
|
|
38
|
+
// ../../../node_modules/.bun/dotenv@18.0.5/node_modules/dotenv/dist/index.cjs
|
|
39
39
|
var require_dist = __commonJS(function(exports, module) {
|
|
40
|
-
var
|
|
40
|
+
var I = (e, o) => () => {
|
|
41
41
|
try {
|
|
42
42
|
return o || e((o = { exports: {} }).exports, o), o.exports;
|
|
43
43
|
} catch (t) {
|
|
44
44
|
throw o = 0, t;
|
|
45
45
|
}
|
|
46
46
|
};
|
|
47
|
-
var
|
|
48
|
-
function
|
|
47
|
+
var S = I((xe, U) => {
|
|
48
|
+
function G(e) {
|
|
49
49
|
return typeof e == "string" ? !["false", "0", "no", "off", ""].includes(e.toLowerCase()) : !!e;
|
|
50
50
|
}
|
|
51
|
-
function
|
|
52
|
-
let
|
|
53
|
-
for (let
|
|
54
|
-
let
|
|
55
|
-
|
|
51
|
+
function X(e = process.env) {
|
|
52
|
+
let o = {};
|
|
53
|
+
for (let t of ["ENCODING", "PATH", "QUIET", "DEBUG", "OVERRIDE", "FAST"]) {
|
|
54
|
+
let n = e[`DOTENV_${t}`] != null ? e[`DOTENV_${t}`] : e[`DOTENV_CONFIG_${t}`];
|
|
55
|
+
n != null && (o[t.toLowerCase()] = t === "ENCODING" || t === "PATH" ? n : G(n));
|
|
56
56
|
}
|
|
57
|
-
return
|
|
57
|
+
return o;
|
|
58
58
|
}
|
|
59
|
-
|
|
59
|
+
U.exports = { parseBoolean: G, optionsFromEnv: X };
|
|
60
60
|
});
|
|
61
|
-
var
|
|
62
|
-
var
|
|
61
|
+
var N = I((ye, x) => {
|
|
62
|
+
var Y = __require("fs"), j = __require("path"), z = __require("os"), { URL: Z, fileURLToPath: ee } = __require("url"), { parseBoolean: k, optionsFromEnv: B } = S(), te = /(?:^|^)\s*(?:export\s+)?([\w.-]+)(?:\s*=\s*?|:\s+?)(\s*'(?:\\'|[^'])*'|\s*"(?:\\"|[^"])*"|\s*`(?:\\`|[^`])*`|[^#\r\n]+)?\s*(?:#.*)?(?:$|$)/mg, b = new Uint8Array(256);
|
|
63
63
|
for (let e = 48;e <= 57; e++)
|
|
64
|
-
|
|
64
|
+
b[e] = 1;
|
|
65
65
|
for (let e = 65;e <= 90; e++)
|
|
66
|
-
|
|
66
|
+
b[e] = 1;
|
|
67
67
|
for (let e = 97;e <= 122; e++)
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
function
|
|
68
|
+
b[e] = 1;
|
|
69
|
+
b[45] = 1;
|
|
70
|
+
b[46] = 1;
|
|
71
|
+
b[95] = 1;
|
|
72
|
+
function re(e) {
|
|
73
73
|
let o = {}, t = e.toString();
|
|
74
74
|
t = t.replace(/\r\n?/mg, `
|
|
75
75
|
`);
|
|
76
76
|
let n;
|
|
77
|
-
for (;(n =
|
|
77
|
+
for (;(n = te.exec(t)) != null; ) {
|
|
78
78
|
let r = n[1], s = n[2] || "";
|
|
79
79
|
s = s.trim();
|
|
80
80
|
let i = s[0];
|
|
@@ -83,192 +83,182 @@ var require_dist = __commonJS(function(exports, module) {
|
|
|
83
83
|
}
|
|
84
84
|
return o;
|
|
85
85
|
}
|
|
86
|
-
function
|
|
86
|
+
function w(e) {
|
|
87
|
+
return e <= 32 ? e === 32 || e >= 9 && e <= 13 : e >= 160 && (e === 160 || e === 5760 || e >= 8192 && e <= 8202 || e === 8232 || e === 8233 || e === 8239 || e === 8287 || e === 12288 || e === 65279);
|
|
88
|
+
}
|
|
89
|
+
function O(e) {
|
|
90
|
+
return e === 10 || e === 8232 || e === 8233;
|
|
91
|
+
}
|
|
92
|
+
function oe(e) {
|
|
87
93
|
let o = {}, t = typeof e == "string" ? e : e.toString();
|
|
88
94
|
t.indexOf("\r") !== -1 && (t = t.replace(/\r\n?/g, `
|
|
89
95
|
`));
|
|
90
96
|
let n = t.length, r = 0;
|
|
91
97
|
for (;r < n; ) {
|
|
92
98
|
let s = t.charCodeAt(r);
|
|
93
|
-
for (;r < n && (s
|
|
99
|
+
for (;r < n && w(s); )
|
|
94
100
|
r++, s = t.charCodeAt(r);
|
|
95
101
|
if (r >= n)
|
|
96
102
|
break;
|
|
97
103
|
if (s === 35) {
|
|
98
|
-
for (;r < n && t.charCodeAt(r)
|
|
104
|
+
for (;r < n && !O(t.charCodeAt(r)); )
|
|
99
105
|
r++;
|
|
100
106
|
continue;
|
|
101
107
|
}
|
|
108
|
+
let i = -1;
|
|
102
109
|
if (s === 101 && r + 6 < n && t.charCodeAt(r + 1) === 120 && t.charCodeAt(r + 2) === 112 && t.charCodeAt(r + 3) === 111 && t.charCodeAt(r + 4) === 114 && t.charCodeAt(r + 5) === 116) {
|
|
103
|
-
let
|
|
104
|
-
if (
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
110
|
+
let v = t.charCodeAt(r + 6);
|
|
111
|
+
if (w(v)) {
|
|
112
|
+
let u = r + 7;
|
|
113
|
+
for (;u < n && w(t.charCodeAt(u)); )
|
|
114
|
+
u++;
|
|
115
|
+
b[t.charCodeAt(u)] && (i = r + 6, r = u);
|
|
116
|
+
} else
|
|
108
117
|
s = t.charCodeAt(r);
|
|
109
118
|
}
|
|
110
|
-
let
|
|
111
|
-
for (;r < n && (
|
|
119
|
+
let l = r, d = 0;
|
|
120
|
+
for (;r < n && (d = t.charCodeAt(r), b[d]); )
|
|
112
121
|
r++;
|
|
113
|
-
if (r ===
|
|
114
|
-
for (;r < n && t.charCodeAt(r)
|
|
122
|
+
if (r === l) {
|
|
123
|
+
for (;r < n && !O(t.charCodeAt(r)); )
|
|
115
124
|
r++;
|
|
116
125
|
continue;
|
|
117
126
|
}
|
|
118
|
-
let
|
|
119
|
-
if (r >= n && (
|
|
127
|
+
let p = t.slice(l, r), f = r;
|
|
128
|
+
if (r >= n && (d = 0), w(d))
|
|
120
129
|
do
|
|
121
|
-
r++,
|
|
122
|
-
while (
|
|
123
|
-
if (
|
|
124
|
-
r++;
|
|
125
|
-
else if (l === 58 && r + 1 < n && (t.charCodeAt(r + 1) === 32 || t.charCodeAt(r + 1) === 9))
|
|
130
|
+
r++, d = r < n ? t.charCodeAt(r) : 0;
|
|
131
|
+
while (w(d));
|
|
132
|
+
if (d === 61)
|
|
126
133
|
r++;
|
|
134
|
+
else if (d === 58 && r === f && r + 1 < n && w(t.charCodeAt(r + 1)))
|
|
135
|
+
r += 2;
|
|
127
136
|
else {
|
|
128
|
-
for (;r < n && t.charCodeAt(r)
|
|
137
|
+
for (r = i === -1 ? f : i;r < n && !O(t.charCodeAt(r)); )
|
|
129
138
|
r++;
|
|
130
139
|
continue;
|
|
131
140
|
}
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
continue;
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
if (d === f)
|
|
141
|
+
let c = r, a = r;
|
|
142
|
+
for (;a < n && w(t.charCodeAt(a)); )
|
|
143
|
+
a++;
|
|
144
|
+
let g = t.charCodeAt(a), h, y = false;
|
|
145
|
+
if (g === 39 || g === 34 || g === 96) {
|
|
146
|
+
let v = t[a], u = t.indexOf(v, a + 1), m = -1, C = -1;
|
|
147
|
+
for (;u !== -1; ) {
|
|
148
|
+
let q = t.charCodeAt(u - 1) === 92, E = u + 1;
|
|
149
|
+
for (;E < n && !O(t.charCodeAt(E)) && w(t.charCodeAt(E)); )
|
|
150
|
+
E++;
|
|
151
|
+
if ((E === n || O(t.charCodeAt(E)) || t.charCodeAt(E) === 35) && (m = u, C = E), !q)
|
|
147
152
|
break;
|
|
148
|
-
|
|
153
|
+
u = t.indexOf(v, u + 1);
|
|
149
154
|
}
|
|
150
|
-
if (
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
let w = t.charCodeAt(p);
|
|
154
|
-
if (w === 35 || w === 10)
|
|
155
|
-
break;
|
|
156
|
-
p++;
|
|
157
|
-
}
|
|
158
|
-
let m = p;
|
|
159
|
-
for (;m > d; ) {
|
|
160
|
-
let w = t.charCodeAt(m - 1);
|
|
161
|
-
if (w === 32 || w === 9)
|
|
162
|
-
m--;
|
|
163
|
-
else
|
|
164
|
-
break;
|
|
165
|
-
}
|
|
166
|
-
if (u = t.slice(d, m), r = p, r < n && t.charCodeAt(r) === 35)
|
|
167
|
-
for (;r < n && t.charCodeAt(r) !== 10; )
|
|
168
|
-
r++;
|
|
169
|
-
} else {
|
|
170
|
-
for (u = t.slice(c, a), r = a + 1, f === 34 && u.indexOf("\\") !== -1 && (u = u.replace(/\\n/g, `
|
|
171
|
-
`).replace(/\\r/g, "\r"));r < n && ((s = t.charCodeAt(r)) === 32 || s === 9); )
|
|
172
|
-
r++;
|
|
173
|
-
if (r < n && t.charCodeAt(r) === 35)
|
|
174
|
-
for (;r < n && t.charCodeAt(r) !== 10; )
|
|
155
|
+
if (m !== -1) {
|
|
156
|
+
if (h = t.slice(a + 1, m), r = C, t.charCodeAt(r) === 35)
|
|
157
|
+
for (;r < n && !O(t.charCodeAt(r)); )
|
|
175
158
|
r++;
|
|
159
|
+
y = true;
|
|
176
160
|
}
|
|
177
|
-
} else {
|
|
178
|
-
let f = r, c = t.indexOf(`
|
|
179
|
-
`, r);
|
|
180
|
-
c === -1 && (c = n);
|
|
181
|
-
let a = t.indexOf("#", r);
|
|
182
|
-
(a === -1 || a > c) && (a = c);
|
|
183
|
-
let d = a;
|
|
184
|
-
for (;d > f; ) {
|
|
185
|
-
let p = t.charCodeAt(d - 1);
|
|
186
|
-
if (p === 32 || p === 9)
|
|
187
|
-
d--;
|
|
188
|
-
else
|
|
189
|
-
break;
|
|
190
|
-
}
|
|
191
|
-
u = f === d ? "" : t.slice(f, d), r = a === c ? a : c;
|
|
192
161
|
}
|
|
193
|
-
|
|
162
|
+
if (!y) {
|
|
163
|
+
let v = t.indexOf(`
|
|
164
|
+
`, c);
|
|
165
|
+
v === -1 && (v = n);
|
|
166
|
+
let u;
|
|
167
|
+
if (n < 4096)
|
|
168
|
+
u = t.indexOf("#", c), (u === -1 || u > v) && (u = v);
|
|
169
|
+
else
|
|
170
|
+
for (u = c;u < v && t.charCodeAt(u) !== 35; )
|
|
171
|
+
u++;
|
|
172
|
+
let m = c, C = u;
|
|
173
|
+
for (;m < C && w(t.charCodeAt(m)); )
|
|
174
|
+
m++;
|
|
175
|
+
for (;C > m && w(t.charCodeAt(C - 1)); )
|
|
176
|
+
C--;
|
|
177
|
+
let q = t.charCodeAt(m);
|
|
178
|
+
if (C - m >= 2 && (q === 39 || q === 34 || q === 96) && t.charCodeAt(C - 1) === q ? h = t.slice(m + 1, C - 1) : h = t.slice(m, C), r = u, u < v)
|
|
179
|
+
for (;r < n && !O(t.charCodeAt(r)); )
|
|
180
|
+
r++;
|
|
181
|
+
}
|
|
182
|
+
g === 34 && (y || a < r) && h.indexOf("\\") !== -1 && (h = h.replace(/\\n/g, `
|
|
183
|
+
`).replace(/\\r/g, "\r")), o[p] = h;
|
|
194
184
|
}
|
|
195
185
|
return o;
|
|
196
186
|
}
|
|
197
|
-
function
|
|
198
|
-
return o &&
|
|
187
|
+
function ne(e, o) {
|
|
188
|
+
return o && k(o.fast) ? oe(e) : re(e);
|
|
199
189
|
}
|
|
200
|
-
function
|
|
190
|
+
function T(e) {
|
|
201
191
|
console.log(`\u2506 ${e}`);
|
|
202
192
|
}
|
|
203
|
-
function
|
|
193
|
+
function se(e) {
|
|
204
194
|
console.error(`\u25C7 ${e}`);
|
|
205
195
|
}
|
|
206
|
-
function
|
|
207
|
-
return e[0] === "~" ?
|
|
196
|
+
function V(e) {
|
|
197
|
+
return e[0] === "~" ? j.join(z.homedir(), e.slice(1)) : e;
|
|
208
198
|
}
|
|
209
|
-
function
|
|
210
|
-
return { ...
|
|
199
|
+
function ie(e = {}) {
|
|
200
|
+
return { ...B(), ...e };
|
|
211
201
|
}
|
|
212
|
-
function
|
|
213
|
-
e =
|
|
214
|
-
let o =
|
|
202
|
+
function ce(e) {
|
|
203
|
+
e = ie(e);
|
|
204
|
+
let o = j.resolve(process.cwd(), ".env"), t = "utf8", n = process.env;
|
|
215
205
|
e && e.processEnv != null && (n = e.processEnv);
|
|
216
|
-
let r =
|
|
217
|
-
e && e.encoding ? t = e.encoding : r &&
|
|
218
|
-
let
|
|
206
|
+
let r = k(e && e.debug);
|
|
207
|
+
e && e.encoding ? t = e.encoding : r && T("no encoding is specified (UTF-8 is used by default)");
|
|
208
|
+
let s = [o];
|
|
219
209
|
if (e && e.path)
|
|
220
210
|
if (!Array.isArray(e.path))
|
|
221
|
-
|
|
211
|
+
s = [V(e.path)];
|
|
222
212
|
else {
|
|
223
|
-
|
|
213
|
+
s = [];
|
|
224
214
|
for (let c of e.path)
|
|
225
|
-
|
|
215
|
+
s.push(V(c));
|
|
226
216
|
}
|
|
227
|
-
let
|
|
228
|
-
for (let c of
|
|
217
|
+
let i, l = {}, d = { fast: e.fast };
|
|
218
|
+
for (let c of s)
|
|
229
219
|
try {
|
|
230
|
-
let a =
|
|
231
|
-
|
|
220
|
+
let a = A.parse(Y.readFileSync(c, { encoding: t }), d);
|
|
221
|
+
A.populate(l, a, e);
|
|
232
222
|
} catch (a) {
|
|
233
|
-
r &&
|
|
223
|
+
r && T(`failed to load ${c} ${a.message}`), i = a;
|
|
234
224
|
}
|
|
235
|
-
let
|
|
236
|
-
if (r || !
|
|
237
|
-
let c = Object.keys(
|
|
238
|
-
for (let
|
|
225
|
+
let p = A.populate(n, l, e), f = k(Object.prototype.hasOwnProperty.call(e, "quiet") ? e.quiet : B(n).quiet);
|
|
226
|
+
if (r || !f) {
|
|
227
|
+
let c = Object.keys(p).length, a = [];
|
|
228
|
+
for (let g of s)
|
|
239
229
|
try {
|
|
240
|
-
let
|
|
241
|
-
a.push(
|
|
242
|
-
} catch (
|
|
243
|
-
r &&
|
|
230
|
+
let h = j.relative(process.cwd(), g instanceof Z ? ee(g) : g);
|
|
231
|
+
a.push(h);
|
|
232
|
+
} catch (h) {
|
|
233
|
+
r && T(`failed to load ${g} ${h.message}`), i = h;
|
|
244
234
|
}
|
|
245
|
-
|
|
235
|
+
se(`injected env (${c}) from ${a.join(",")}`);
|
|
246
236
|
}
|
|
247
|
-
return
|
|
237
|
+
return i ? { parsed: l, error: i } : { parsed: l };
|
|
248
238
|
}
|
|
249
|
-
function
|
|
250
|
-
return
|
|
239
|
+
function ae(e) {
|
|
240
|
+
return A.configDotenv(e);
|
|
251
241
|
}
|
|
252
|
-
function
|
|
242
|
+
function le(e, o, t = {}) {
|
|
253
243
|
let n = !!(t && t.debug), r = !!(t && t.override), s = {};
|
|
254
244
|
if (e === null || typeof e != "object" || o === null || typeof o != "object") {
|
|
255
245
|
let i = new Error("OBJECT_REQUIRED: Please check the processEnv argument being passed to populate");
|
|
256
246
|
throw i.code = "OBJECT_REQUIRED", i;
|
|
257
247
|
}
|
|
258
248
|
for (let i of Object.keys(o))
|
|
259
|
-
Object.prototype.hasOwnProperty.call(e, i) ? (r === true && (e[i] = o[i], s[i] = o[i]), n &&
|
|
249
|
+
Object.prototype.hasOwnProperty.call(e, i) ? (r === true && (e[i] = o[i], s[i] = o[i]), n && T(r === true ? `"${i}" is already defined and WAS overwritten` : `"${i}" is already defined and was NOT overwritten`)) : (e[i] = o[i], s[i] = o[i]);
|
|
260
250
|
return s;
|
|
261
251
|
}
|
|
262
|
-
var
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
252
|
+
var A = { configDotenv: ce, config: ae, parse: ne, populate: le };
|
|
253
|
+
x.exports.configDotenv = A.configDotenv;
|
|
254
|
+
x.exports.config = A.config;
|
|
255
|
+
x.exports.parse = A.parse;
|
|
256
|
+
x.exports.populate = A.populate;
|
|
257
|
+
x.exports = A;
|
|
268
258
|
});
|
|
269
|
-
var
|
|
270
|
-
var
|
|
271
|
-
function
|
|
259
|
+
var M = I((Te, W) => {
|
|
260
|
+
var _ = __require("child_process"), fe = __require("fs"), L = __require("path");
|
|
261
|
+
function ue(e) {
|
|
272
262
|
let o = ['"'], t = 0;
|
|
273
263
|
for (let n of e) {
|
|
274
264
|
if (n === "\\") {
|
|
@@ -279,7 +269,7 @@ var require_dist = __commonJS(function(exports, module) {
|
|
|
279
269
|
}
|
|
280
270
|
return o.push("\\".repeat(t * 2), '"'), o.join("");
|
|
281
271
|
}
|
|
282
|
-
function
|
|
272
|
+
function H(e, o = 1) {
|
|
283
273
|
for (let t = 0;t < o; t++) {
|
|
284
274
|
let n = [];
|
|
285
275
|
for (let r of e) {
|
|
@@ -290,47 +280,47 @@ var require_dist = __commonJS(function(exports, module) {
|
|
|
290
280
|
}
|
|
291
281
|
return e;
|
|
292
282
|
}
|
|
293
|
-
function
|
|
283
|
+
function P(e, o) {
|
|
294
284
|
let t = Object.keys(e).reverse().find((n) => n.toUpperCase() === o);
|
|
295
285
|
return t === undefined ? undefined : e[t];
|
|
296
286
|
}
|
|
297
|
-
function
|
|
298
|
-
let n = (
|
|
287
|
+
function de(e, o, t) {
|
|
288
|
+
let n = (P(o, "PATHEXT") || ".COM;.EXE;.BAT;.CMD").split(";").filter(Boolean), s = n.some((l) => e.toLowerCase().endsWith(l.toLowerCase())) ? ["", ...n] : [...n, ""], i = /[\\/]/.test(e) ? [t] : [t, ...(P(o, "PATH") || "").split(";")];
|
|
299
289
|
for (let l of i)
|
|
300
|
-
for (let
|
|
301
|
-
let
|
|
290
|
+
for (let d of s) {
|
|
291
|
+
let p = L.resolve(t, l.replace(/^"|"$/g, ""), e + d);
|
|
302
292
|
try {
|
|
303
|
-
if (
|
|
304
|
-
return
|
|
293
|
+
if (fe.statSync(p).isFile())
|
|
294
|
+
return p;
|
|
305
295
|
} catch {}
|
|
306
296
|
}
|
|
307
297
|
}
|
|
308
|
-
function
|
|
298
|
+
function pe(e, o, t) {
|
|
309
299
|
if (process.platform !== "win32")
|
|
310
|
-
return
|
|
311
|
-
let n = t.env || process.env, r =
|
|
300
|
+
return _.spawn(e, o, t);
|
|
301
|
+
let n = t.env || process.env, r = de(e, n, t.cwd || process.cwd());
|
|
312
302
|
if (r && /\.(?:exe|com)$/i.test(r))
|
|
313
|
-
return
|
|
314
|
-
let s = /\.(?:bat|cmd)$/i.test(r || e), i = [
|
|
315
|
-
for (let
|
|
316
|
-
i.push(
|
|
303
|
+
return _.spawn(r, o, t);
|
|
304
|
+
let s = /\.(?:bat|cmd)$/i.test(r || e), i = [H(L.normalize(r || e))];
|
|
305
|
+
for (let d of o)
|
|
306
|
+
i.push(H(ue(d), s ? 2 : 1));
|
|
317
307
|
let l = i.join(" ");
|
|
318
|
-
return
|
|
308
|
+
return _.spawn(P(n, "COMSPEC") || "cmd.exe", ["/d", "/v:off", "/s", "/c", `"${l}"`], { ...t, windowsVerbatimArguments: true });
|
|
319
309
|
}
|
|
320
|
-
|
|
310
|
+
W.exports = pe;
|
|
321
311
|
});
|
|
322
|
-
var
|
|
323
|
-
var
|
|
324
|
-
function
|
|
312
|
+
var K = I(($e, F) => {
|
|
313
|
+
var he = __require("fs"), ge = __require("os"), Q = __require("path"), me = __require("child_process"), ve = M(), R = N(), { optionsFromEnv: Ce } = S();
|
|
314
|
+
function $() {
|
|
325
315
|
console.log(["Usage: dotenv run [--help] [-q|--quiet] [--debug] [--override] [--fast] [-f|--file <paths>] [--] <command> [args...]", "", "Run a command with environment variables from a .env file.", "Place dotenv options before the command; all following arguments go to the command.", "", "Options:", " -f, --file <paths> .env paths, comma-separated or repeated (default: .env)", " -q, --quiet suppress the injected env message", " --debug enable debug logging", " --override override existing environment variables", " --fast use the faster character-scanner parser", "", "Environment variables (DOTENV_CONFIG_* names remain as fallbacks):", " DOTENV_PATH, DOTENV_ENCODING, DOTENV_QUIET,", " DOTENV_DEBUG, DOTENV_OVERRIDE,", " DOTENV_FAST"].join(`
|
|
326
316
|
`));
|
|
327
317
|
}
|
|
328
|
-
function
|
|
318
|
+
function we(e) {
|
|
329
319
|
let o = [], t = false, n, r, s, i, l = -1;
|
|
330
|
-
for (let
|
|
331
|
-
let f = e[
|
|
320
|
+
for (let p = 0;p < e.length; p++) {
|
|
321
|
+
let f = e[p];
|
|
332
322
|
if (f === "--") {
|
|
333
|
-
l =
|
|
323
|
+
l = p + 1;
|
|
334
324
|
break;
|
|
335
325
|
}
|
|
336
326
|
if (f === "--help" || f === "-h")
|
|
@@ -352,70 +342,70 @@ var require_dist = __commonJS(function(exports, module) {
|
|
|
352
342
|
continue;
|
|
353
343
|
}
|
|
354
344
|
if (f === "-f" || f === "--file" || f.startsWith("-f=") || f.startsWith("--file=")) {
|
|
355
|
-
let c = f.indexOf("="), a = c === -1 ? f : f.slice(0, c),
|
|
356
|
-
if (!
|
|
345
|
+
let c = f.indexOf("="), a = c === -1 ? f : f.slice(0, c), g = c === -1 ? e[++p] : f.slice(c + 1);
|
|
346
|
+
if (!g || g === "--")
|
|
357
347
|
return { error: `${a} requires a path` };
|
|
358
|
-
let
|
|
359
|
-
if (
|
|
348
|
+
let h = g.split(",").map((y) => y.trim()).filter(Boolean);
|
|
349
|
+
if (h.length === 0)
|
|
360
350
|
return { error: `${a} requires a path` };
|
|
361
|
-
o.push(...
|
|
351
|
+
o.push(...h), t = true;
|
|
362
352
|
continue;
|
|
363
353
|
}
|
|
364
354
|
if (f.startsWith("-"))
|
|
365
355
|
return { error: `unknown option: ${f}` };
|
|
366
|
-
l =
|
|
356
|
+
l = p;
|
|
367
357
|
break;
|
|
368
358
|
}
|
|
369
|
-
let
|
|
370
|
-
return { paths: o, pathSet: t, quiet: n, debug: r, override: s, fast: i, command:
|
|
359
|
+
let d = l === -1 ? [] : e.slice(l);
|
|
360
|
+
return { paths: o, pathSet: t, quiet: n, debug: r, override: s, fast: i, command: d };
|
|
371
361
|
}
|
|
372
|
-
function
|
|
373
|
-
return e[0] === "~" ?
|
|
362
|
+
function Ae(e) {
|
|
363
|
+
return e[0] === "~" ? Q.join(ge.homedir(), e.slice(1)) : e;
|
|
374
364
|
}
|
|
375
|
-
function
|
|
376
|
-
let o =
|
|
365
|
+
function Ee(e) {
|
|
366
|
+
let o = Ce(), t = { encoding: o.encoding || "utf8", quiet: o.quiet === true, debug: o.debug === true, override: o.override === true, fast: o.fast === true, paths: [".env"], defaultPath: true };
|
|
377
367
|
return o.path != null && (t.paths = [o.path], t.defaultPath = false), e.pathSet && (t.paths = e.paths, t.defaultPath = false), e.quiet != null && (t.quiet = e.quiet), e.debug != null && (t.debug = e.debug), e.override != null && (t.override = e.override), e.fast != null && (t.fast = e.fast), t;
|
|
378
368
|
}
|
|
379
|
-
function
|
|
369
|
+
function be(e) {
|
|
380
370
|
let o = {}, t = [], n = { override: e.override, debug: e.debug };
|
|
381
371
|
for (let s of e.paths) {
|
|
382
|
-
let i =
|
|
372
|
+
let i = Q.resolve(process.cwd(), Ae(s));
|
|
383
373
|
try {
|
|
384
|
-
let l =
|
|
385
|
-
|
|
374
|
+
let l = R.parse(he.readFileSync(i, { encoding: e.encoding }), { fast: e.fast });
|
|
375
|
+
R.populate(o, l, n), t.push(s);
|
|
386
376
|
} catch (l) {
|
|
387
377
|
if (e.debug && console.log(`\u2506 failed to load ${s} ${l.message}`), !(e.defaultPath && l.code === "ENOENT"))
|
|
388
378
|
throw l;
|
|
389
379
|
}
|
|
390
380
|
}
|
|
391
|
-
return { injected:
|
|
381
|
+
return { injected: R.populate(process.env, o, n), loadedPaths: t };
|
|
392
382
|
}
|
|
393
|
-
function
|
|
383
|
+
function J(e) {
|
|
394
384
|
let o = e[0];
|
|
395
385
|
if (o === "--help" || o === "-h") {
|
|
396
|
-
|
|
386
|
+
$();
|
|
397
387
|
return;
|
|
398
388
|
}
|
|
399
389
|
if (o !== "run") {
|
|
400
|
-
|
|
390
|
+
$(), process.exitCode = 1;
|
|
401
391
|
return;
|
|
402
392
|
}
|
|
403
|
-
let t =
|
|
393
|
+
let t = we(e.slice(1));
|
|
404
394
|
if (t.help) {
|
|
405
|
-
|
|
395
|
+
$();
|
|
406
396
|
return;
|
|
407
397
|
}
|
|
408
398
|
if (t.error) {
|
|
409
|
-
console.error(`dotenv: ${t.error}`),
|
|
399
|
+
console.error(`dotenv: ${t.error}`), $(), process.exitCode = 1;
|
|
410
400
|
return;
|
|
411
401
|
}
|
|
412
402
|
if (t.command.length === 0) {
|
|
413
|
-
|
|
403
|
+
$(), process.exitCode = 1;
|
|
414
404
|
return;
|
|
415
405
|
}
|
|
416
|
-
let n =
|
|
406
|
+
let n = Ee(t);
|
|
417
407
|
try {
|
|
418
|
-
let c =
|
|
408
|
+
let c = be(n);
|
|
419
409
|
if (!n.quiet) {
|
|
420
410
|
let a = `\u25C7 injected env (${Object.keys(c.injected).length})`;
|
|
421
411
|
c.loadedPaths.length > 0 && (a += ` from ${c.loadedPaths.join(", ")}`), console.error(a);
|
|
@@ -424,11 +414,11 @@ var require_dist = __commonJS(function(exports, module) {
|
|
|
424
414
|
console.error(`dotenv: ${c.message}`), process.exitCode = 1;
|
|
425
415
|
return;
|
|
426
416
|
}
|
|
427
|
-
let r = !!process.stdin.isTTY, s = process.platform !== "win32" && !r, i =
|
|
428
|
-
function
|
|
417
|
+
let r = !!process.stdin.isTTY, s = process.platform !== "win32" && !r, i = ve(t.command[0], t.command.slice(1), { stdio: "inherit", detached: s }), l = new Map, d = 0;
|
|
418
|
+
function p(c) {
|
|
429
419
|
if (!(!i.pid || i.exitCode !== null || i.signalCode !== null)) {
|
|
430
420
|
if (process.platform === "win32") {
|
|
431
|
-
|
|
421
|
+
me.spawnSync("taskkill", ["/pid", String(i.pid), "/T", "/F"], { stdio: "ignore" });
|
|
432
422
|
return;
|
|
433
423
|
}
|
|
434
424
|
try {
|
|
@@ -446,14 +436,14 @@ var require_dist = __commonJS(function(exports, module) {
|
|
|
446
436
|
for (let c of ["SIGINT", "SIGTERM", "SIGHUP", "SIGQUIT"]) {
|
|
447
437
|
let a = () => {
|
|
448
438
|
if (c === "SIGINT") {
|
|
449
|
-
if (
|
|
439
|
+
if (d++, r && process.platform !== "win32" && d === 1)
|
|
450
440
|
return;
|
|
451
|
-
if (
|
|
452
|
-
|
|
441
|
+
if (d > 1) {
|
|
442
|
+
p(d === 2 ? "SIGTERM" : "SIGKILL");
|
|
453
443
|
return;
|
|
454
444
|
}
|
|
455
445
|
}
|
|
456
|
-
|
|
446
|
+
p(c);
|
|
457
447
|
};
|
|
458
448
|
l.set(c, a), process.on(c, a);
|
|
459
449
|
}
|
|
@@ -463,22 +453,24 @@ var require_dist = __commonJS(function(exports, module) {
|
|
|
463
453
|
f(), typeof c == "number" ? process.exit(c) : (setInterval(() => {}, 1000), process.kill(process.pid, a));
|
|
464
454
|
});
|
|
465
455
|
}
|
|
466
|
-
|
|
467
|
-
|
|
456
|
+
F.exports = J;
|
|
457
|
+
F === __require.main && J(process.argv.slice(2));
|
|
468
458
|
});
|
|
469
|
-
var
|
|
470
|
-
var
|
|
471
|
-
module.exports =
|
|
472
|
-
module.exports.config =
|
|
473
|
-
module.exports.configDotenv =
|
|
474
|
-
module.exports.parse =
|
|
475
|
-
module.exports.populate =
|
|
459
|
+
var D = N();
|
|
460
|
+
var Oe = K();
|
|
461
|
+
module.exports = D;
|
|
462
|
+
module.exports.config = D.config;
|
|
463
|
+
module.exports.configDotenv = D.configDotenv;
|
|
464
|
+
module.exports.parse = D.parse;
|
|
465
|
+
module.exports.populate = D.populate;
|
|
476
466
|
});
|
|
477
467
|
|
|
478
468
|
// src/load-env.ts
|
|
479
469
|
var import_dotenv = __toESM(require_dist(), 1);
|
|
480
470
|
import path from "path";
|
|
481
|
-
|
|
471
|
+
if (process.env.GO_LABS_CLI_SKIP_DOTENV !== "1") {
|
|
472
|
+
import_dotenv.config({ path: path.resolve(process.cwd(), ".env"), quiet: true });
|
|
473
|
+
}
|
|
482
474
|
|
|
483
475
|
// src/cli.ts
|
|
484
476
|
import { readFileSync } from "fs";
|
|
@@ -1496,6 +1488,8 @@ function datetime(args) {
|
|
|
1496
1488
|
}
|
|
1497
1489
|
var anyString = /^[\s\S]{0,}$/;
|
|
1498
1490
|
var number = /^-?\d+(?:\.\d+)?$/;
|
|
1491
|
+
var boolean = /^(?:true|false)$/i;
|
|
1492
|
+
var _null = /^null$/i;
|
|
1499
1493
|
var lowercase = /^[^A-Z]*$/;
|
|
1500
1494
|
var uppercase = /^[^a-z]*$/;
|
|
1501
1495
|
|
|
@@ -2377,6 +2371,43 @@ var $ZodNumberFormat = /* @__PURE__ */ $constructor("$ZodNumberFormat", (inst, d
|
|
|
2377
2371
|
$ZodCheckNumberFormat.init(inst, def);
|
|
2378
2372
|
$ZodNumber.init(inst, def);
|
|
2379
2373
|
});
|
|
2374
|
+
var $ZodBoolean = /* @__PURE__ */ $constructor("$ZodBoolean", (inst, def) => {
|
|
2375
|
+
$ZodType.init(inst, def);
|
|
2376
|
+
inst._zod.pattern = boolean;
|
|
2377
|
+
inst._zod.parse = (payload, _ctx) => {
|
|
2378
|
+
if (def.coerce)
|
|
2379
|
+
try {
|
|
2380
|
+
payload.value = Boolean(payload.value);
|
|
2381
|
+
} catch (_) {}
|
|
2382
|
+
const input = payload.value;
|
|
2383
|
+
if (typeof input === "boolean")
|
|
2384
|
+
return payload;
|
|
2385
|
+
payload.issues.push({
|
|
2386
|
+
expected: "boolean",
|
|
2387
|
+
code: "invalid_type",
|
|
2388
|
+
input,
|
|
2389
|
+
inst
|
|
2390
|
+
});
|
|
2391
|
+
return payload;
|
|
2392
|
+
};
|
|
2393
|
+
});
|
|
2394
|
+
var $ZodNull = /* @__PURE__ */ $constructor("$ZodNull", (inst, def) => {
|
|
2395
|
+
$ZodType.init(inst, def);
|
|
2396
|
+
inst._zod.pattern = _null;
|
|
2397
|
+
inst._zod.values = new Set([null]);
|
|
2398
|
+
inst._zod.parse = (payload, _ctx) => {
|
|
2399
|
+
const input = payload.value;
|
|
2400
|
+
if (input === null)
|
|
2401
|
+
return payload;
|
|
2402
|
+
payload.issues.push({
|
|
2403
|
+
expected: "null",
|
|
2404
|
+
code: "invalid_type",
|
|
2405
|
+
input,
|
|
2406
|
+
inst
|
|
2407
|
+
});
|
|
2408
|
+
return payload;
|
|
2409
|
+
};
|
|
2410
|
+
});
|
|
2380
2411
|
var $ZodUnknown = /* @__PURE__ */ $constructor("$ZodUnknown", (inst, def) => {
|
|
2381
2412
|
$ZodType.init(inst, def);
|
|
2382
2413
|
inst._zod.parse = (payload) => payload;
|
|
@@ -3914,6 +3945,18 @@ function _int(Class, params) {
|
|
|
3914
3945
|
...normalizeParams(params)
|
|
3915
3946
|
});
|
|
3916
3947
|
}
|
|
3948
|
+
function _boolean(Class, params) {
|
|
3949
|
+
return new Class({
|
|
3950
|
+
type: "boolean",
|
|
3951
|
+
...normalizeParams(params)
|
|
3952
|
+
});
|
|
3953
|
+
}
|
|
3954
|
+
function _null2(Class, params) {
|
|
3955
|
+
return new Class({
|
|
3956
|
+
type: "null",
|
|
3957
|
+
...normalizeParams(params)
|
|
3958
|
+
});
|
|
3959
|
+
}
|
|
3917
3960
|
function _unknown(Class) {
|
|
3918
3961
|
return new Class({
|
|
3919
3962
|
type: "unknown"
|
|
@@ -4796,6 +4839,18 @@ var numberProcessor = (schema, ctx, _json, params) => {
|
|
|
4796
4839
|
json.allOf = [...json.allOf ?? [], ...rest.map((m) => ({ multipleOf: m }))];
|
|
4797
4840
|
}
|
|
4798
4841
|
};
|
|
4842
|
+
var booleanProcessor = (_schema, _ctx, json, _params) => {
|
|
4843
|
+
json.type = "boolean";
|
|
4844
|
+
};
|
|
4845
|
+
var nullProcessor = (_schema, ctx, json, _params) => {
|
|
4846
|
+
if (ctx.target === "openapi-3.0") {
|
|
4847
|
+
json.type = "string";
|
|
4848
|
+
json.nullable = true;
|
|
4849
|
+
json.enum = [null];
|
|
4850
|
+
} else {
|
|
4851
|
+
json.type = "null";
|
|
4852
|
+
}
|
|
4853
|
+
};
|
|
4799
4854
|
var neverProcessor = (_schema, _ctx, json, _params) => {
|
|
4800
4855
|
json.not = {};
|
|
4801
4856
|
};
|
|
@@ -5590,6 +5645,22 @@ var ZodNumberFormat = /* @__PURE__ */ $constructor("ZodNumberFormat", (inst, def
|
|
|
5590
5645
|
function int(params) {
|
|
5591
5646
|
return _int(ZodNumberFormat, params);
|
|
5592
5647
|
}
|
|
5648
|
+
var ZodBoolean = /* @__PURE__ */ $constructor("ZodBoolean", (inst, def) => {
|
|
5649
|
+
$ZodBoolean.init(inst, def);
|
|
5650
|
+
ZodType.init(inst, def);
|
|
5651
|
+
inst._zod.processJSONSchema = (ctx, json, params) => booleanProcessor(inst, ctx, json, params);
|
|
5652
|
+
});
|
|
5653
|
+
function boolean2(params) {
|
|
5654
|
+
return _boolean(ZodBoolean, params);
|
|
5655
|
+
}
|
|
5656
|
+
var ZodNull = /* @__PURE__ */ $constructor("ZodNull", (inst, def) => {
|
|
5657
|
+
$ZodNull.init(inst, def);
|
|
5658
|
+
ZodType.init(inst, def);
|
|
5659
|
+
inst._zod.processJSONSchema = (ctx, json, params) => nullProcessor(inst, ctx, json, params);
|
|
5660
|
+
});
|
|
5661
|
+
function _null3(params) {
|
|
5662
|
+
return _null2(ZodNull, params);
|
|
5663
|
+
}
|
|
5593
5664
|
var ZodUnknown = /* @__PURE__ */ $constructor("ZodUnknown", (inst, def) => {
|
|
5594
5665
|
$ZodUnknown.init(inst, def);
|
|
5595
5666
|
ZodType.init(inst, def);
|
|
@@ -6008,6 +6079,9 @@ var storedCliCredentialsSchema = object({
|
|
|
6008
6079
|
session: cliSessionIdentitySchema
|
|
6009
6080
|
}).strict();
|
|
6010
6081
|
var cliProductSchema = _enum(cliProducts);
|
|
6082
|
+
// ../../cli-auth/src/client/secret-backend.ts
|
|
6083
|
+
import { execFile } from "child_process";
|
|
6084
|
+
|
|
6011
6085
|
// ../../cli-auth/src/client/runtime.ts
|
|
6012
6086
|
var MINIMUM_BUN_VERSION = [1, 4, 0];
|
|
6013
6087
|
var parseBunVersion = (version) => {
|
|
@@ -6033,27 +6107,145 @@ var assertBunRuntime = (runtime = globalThis.Bun) => {
|
|
|
6033
6107
|
}
|
|
6034
6108
|
};
|
|
6035
6109
|
|
|
6036
|
-
// ../../cli-auth/src/client/
|
|
6110
|
+
// ../../cli-auth/src/client/storage-error.ts
|
|
6111
|
+
var guidance = {
|
|
6112
|
+
"missing-library": "Install the runtime's native credential-store library and ensure your own native keyring/session is accessible and unlocked; Linux desktop storage requires libsecret AND an accessible, unlocked Secret Service.",
|
|
6113
|
+
"bus-unavailable": "The Linux user D-Bus session is absent or unreachable. --no-browser does not provide storage. Start or repair your own user session and native keyring before retrying.",
|
|
6114
|
+
"bus-denied": "Access to the Linux user bus was denied. Fix your own native keyring/session permissions or host policy; do not change bus/socket permissions or borrow another user's bus.",
|
|
6115
|
+
"service-unavailable": "The user bus is reachable but your own Secret Service is unavailable. Start or repair your own native keyring session; do not expose another user's store.",
|
|
6116
|
+
locked: "Unlock your own native credential collection/session before retrying. The CLI will not wait indefinitely for an unlock prompt.",
|
|
6117
|
+
timeout: "The native credential backend did not finish within 10 seconds and its process was terminated. Fix or unlock your own native keyring/session outside the CLI; the CLI will not bypass host permissions.",
|
|
6118
|
+
"invalid-response": "The native credential backend returned an invalid response. Check your own keyring/session and configuration; no credential output was disclosed.",
|
|
6119
|
+
"read-failed": "The native credential backend could not read credentials. Check your own keyring/session availability and permissions; this is not evidence that you are logged out.",
|
|
6120
|
+
"write-failed": "The native credential backend could not persist credentials. Check your own keyring/session write permissions and availability; no plaintext fallback is used.",
|
|
6121
|
+
"delete-failed": "The native credential backend could not delete its entry. Check your own keyring/session permissions and remove any non-secret preflight probe through that backend if necessary."
|
|
6122
|
+
};
|
|
6123
|
+
|
|
6037
6124
|
class CliCredentialStoreUnavailableError extends Error {
|
|
6038
6125
|
code = "CLI_CREDENTIAL_STORE_UNAVAILABLE";
|
|
6039
|
-
|
|
6040
|
-
|
|
6126
|
+
reason;
|
|
6127
|
+
constructor(product, reason = "read-failed") {
|
|
6128
|
+
super(`Secure credential storage is unavailable for the ${product} CLI [CLI_CREDENTIAL_STORE_UNAVAILABLE:${reason}]. ${guidance[reason]}`);
|
|
6041
6129
|
this.name = "CliCredentialStoreUnavailableError";
|
|
6042
|
-
|
|
6130
|
+
this.reason = reason;
|
|
6131
|
+
}
|
|
6132
|
+
}
|
|
6133
|
+
var classifyCredentialStoreFailure = (message, fallback) => {
|
|
6134
|
+
if (/libsecret.*(not found|not available|cannot open|load)|dlopen|shared (object|library).*not found/i.test(message))
|
|
6135
|
+
return "missing-library";
|
|
6136
|
+
if (/(d-?bus|user bus|session bus).*(denied|not permitted)|(?:denied|not permitted).*(d-?bus|user bus|session bus)/i.test(message))
|
|
6137
|
+
return "bus-denied";
|
|
6138
|
+
if (/locked|interaction.*not allowed|user.*cancel/i.test(message))
|
|
6139
|
+
return "locked";
|
|
6140
|
+
if (/ServiceUnknown|org\.freedesktop\.secrets.*(not provided|no owner|not available)|secret.?service.*(unavailable|not running)/i.test(message))
|
|
6141
|
+
return "service-unavailable";
|
|
6142
|
+
if (/d-?bus|user bus|session bus|autolaunch/i.test(message))
|
|
6143
|
+
return "bus-unavailable";
|
|
6144
|
+
return fallback;
|
|
6145
|
+
};
|
|
6146
|
+
|
|
6147
|
+
class CliCredentialPersistenceError extends Error {
|
|
6148
|
+
remoteRevoked;
|
|
6149
|
+
localRestored;
|
|
6150
|
+
phase;
|
|
6151
|
+
code = "CLI_CREDENTIAL_PERSISTENCE_FAILED";
|
|
6152
|
+
constructor(remoteRevoked, localRestored, phase) {
|
|
6153
|
+
super(`CLI credentials could not be saved after ${phase} [CLI_CREDENTIAL_PERSISTENCE_FAILED]. ${remoteRevoked ? "The newly issued session was revoked." : "Remote revocation could not be confirmed; revoke the session in the product's session management before retrying."} ${localRestored ? phase === "login" ? "The previous local credentials were preserved." : "The unusable rotated local credentials were removed; sign in again." : "Local cleanup could not be confirmed. Inspect your own native credential backend before retrying."}`);
|
|
6154
|
+
this.remoteRevoked = remoteRevoked;
|
|
6155
|
+
this.localRestored = localRestored;
|
|
6156
|
+
this.phase = phase;
|
|
6157
|
+
this.name = "CliCredentialPersistenceError";
|
|
6158
|
+
}
|
|
6159
|
+
}
|
|
6160
|
+
var getCliStorageError = (error) => {
|
|
6161
|
+
if (error instanceof CliCredentialStoreUnavailableError)
|
|
6162
|
+
return {
|
|
6163
|
+
code: error.code,
|
|
6164
|
+
message: error.message,
|
|
6165
|
+
details: { reason: error.reason }
|
|
6166
|
+
};
|
|
6167
|
+
if (error instanceof CliCredentialPersistenceError)
|
|
6168
|
+
return {
|
|
6169
|
+
code: error.code,
|
|
6170
|
+
message: error.message,
|
|
6171
|
+
details: {
|
|
6172
|
+
remoteRevoked: error.remoteRevoked,
|
|
6173
|
+
localRestored: error.localRestored,
|
|
6174
|
+
phase: error.phase
|
|
6175
|
+
}
|
|
6176
|
+
};
|
|
6177
|
+
return;
|
|
6178
|
+
};
|
|
6179
|
+
|
|
6180
|
+
// ../../cli-auth/src/client/secret-backend.ts
|
|
6181
|
+
var timeoutMs = 1e4;
|
|
6182
|
+
var maxBuffer = 64 * 1024;
|
|
6183
|
+
var runBackend = (product, executable, args, input, failure) => new Promise((resolve, reject) => {
|
|
6184
|
+
const child = execFile(executable, args, {
|
|
6185
|
+
timeout: timeoutMs,
|
|
6186
|
+
killSignal: "SIGKILL",
|
|
6187
|
+
maxBuffer,
|
|
6188
|
+
windowsHide: true
|
|
6189
|
+
}, (error, stdout, stderr) => {
|
|
6190
|
+
if (error) {
|
|
6191
|
+
const reason = error.code === "ERR_CHILD_PROCESS_STDIO_MAXBUFFER" ? "invalid-response" : error.killed ? "timeout" : classifyCredentialStoreFailure(`${stdout}
|
|
6192
|
+
${stderr}`, failure);
|
|
6193
|
+
reject(new CliCredentialStoreUnavailableError(product, reason));
|
|
6194
|
+
return;
|
|
6195
|
+
}
|
|
6196
|
+
resolve(stdout);
|
|
6197
|
+
});
|
|
6198
|
+
child.stdin?.on("error", () => {});
|
|
6199
|
+
child.stdin?.end(input);
|
|
6200
|
+
});
|
|
6201
|
+
var nativeWorker = `
|
|
6202
|
+
try {
|
|
6203
|
+
const { operation, input } = JSON.parse(await Bun.stdin.text());
|
|
6204
|
+
const value = await Bun.secrets[operation](input);
|
|
6205
|
+
process.stdout.write(JSON.stringify({ value: value ?? null }));
|
|
6206
|
+
} catch (error) {
|
|
6207
|
+
const message = error instanceof Error ? error.message : "Credential backend failed";
|
|
6208
|
+
// libsecret's bus transport errors can omit the D-Bus context.
|
|
6209
|
+
const context = process.platform === "linux" && /^Could not connect:/i.test(message) ? "D-Bus: " : "";
|
|
6210
|
+
process.stderr.write(context + message);
|
|
6211
|
+
process.exitCode = 1;
|
|
6043
6212
|
}
|
|
6044
|
-
|
|
6213
|
+
`;
|
|
6214
|
+
var nativeResponse = object({ value: union([string2(), boolean2(), _null3()]) }).strict();
|
|
6215
|
+
var createIsolatedBunSecrets = (product) => {
|
|
6216
|
+
const run = async (operation, input) => {
|
|
6217
|
+
assertBunRuntime();
|
|
6218
|
+
const output = await runBackend(product, process.execPath, ["--no-env-file", "--eval", nativeWorker], JSON.stringify({ operation, input }), operation === "set" ? "write-failed" : operation === "delete" ? "delete-failed" : "read-failed");
|
|
6219
|
+
try {
|
|
6220
|
+
return nativeResponse.parse(JSON.parse(output)).value;
|
|
6221
|
+
} catch {
|
|
6222
|
+
throw new CliCredentialStoreUnavailableError(product, "invalid-response");
|
|
6223
|
+
}
|
|
6224
|
+
};
|
|
6225
|
+
return {
|
|
6226
|
+
get: async (input) => {
|
|
6227
|
+
const value = await run("get", input);
|
|
6228
|
+
if (value === null || typeof value === "string")
|
|
6229
|
+
return value;
|
|
6230
|
+
throw new CliCredentialStoreUnavailableError(product, "invalid-response");
|
|
6231
|
+
},
|
|
6232
|
+
set: async (input) => {
|
|
6233
|
+
await run("set", input);
|
|
6234
|
+
},
|
|
6235
|
+
delete: async (input) => await run("delete", input) === true
|
|
6236
|
+
};
|
|
6237
|
+
};
|
|
6238
|
+
|
|
6239
|
+
// ../../cli-auth/src/client/credential-store.ts
|
|
6240
|
+
var runSecretOperation = async (product, operation, fallback = "read-failed") => {
|
|
6045
6241
|
try {
|
|
6046
6242
|
return await operation();
|
|
6047
6243
|
} catch (cause) {
|
|
6048
6244
|
if (cause instanceof CliCredentialStoreUnavailableError)
|
|
6049
6245
|
throw cause;
|
|
6050
|
-
throw new CliCredentialStoreUnavailableError(product,
|
|
6246
|
+
throw new CliCredentialStoreUnavailableError(product, classifyCredentialStoreFailure(cause instanceof Error ? cause.message : "", fallback));
|
|
6051
6247
|
}
|
|
6052
6248
|
};
|
|
6053
|
-
var defaultSecrets = () => {
|
|
6054
|
-
assertBunRuntime();
|
|
6055
|
-
return Bun.secrets;
|
|
6056
|
-
};
|
|
6057
6249
|
var refreshLockTimeoutMs = 5 * 60 * 1000;
|
|
6058
6250
|
var refreshLockRetryMs = 50;
|
|
6059
6251
|
var getCredentialLockDirectoryPath = () => {
|
|
@@ -6125,18 +6317,38 @@ var acquireRefreshLock = async (path) => {
|
|
|
6125
6317
|
}
|
|
6126
6318
|
throw new Error("Timed out waiting for another CLI process to refresh credentials. Retry the command.");
|
|
6127
6319
|
};
|
|
6320
|
+
var resolveCliCredentialAccount = (environment = process.env) => environment.GO_LABS_CLI_CREDENTIAL_ACCOUNT?.trim() || "default";
|
|
6128
6321
|
var createBunCredentialStore = ({
|
|
6129
|
-
account =
|
|
6322
|
+
account = resolveCliCredentialAccount(),
|
|
6130
6323
|
product,
|
|
6131
|
-
secrets =
|
|
6324
|
+
secrets = createIsolatedBunSecrets(product)
|
|
6132
6325
|
}) => {
|
|
6133
6326
|
const service = `go-labs-cli:${product}`;
|
|
6134
6327
|
return {
|
|
6328
|
+
preflight: async () => {
|
|
6329
|
+
const input = { name: `probe-${randomUUID()}`, service };
|
|
6330
|
+
const value = `go-labs-non-secret-probe:${randomUUID()}`;
|
|
6331
|
+
try {
|
|
6332
|
+
await runSecretOperation(product, () => secrets.set({ ...input, value }), "write-failed");
|
|
6333
|
+
if (await runSecretOperation(product, () => secrets.get(input)) !== value) {
|
|
6334
|
+
throw new CliCredentialStoreUnavailableError(product, "write-failed");
|
|
6335
|
+
}
|
|
6336
|
+
} catch (error) {
|
|
6337
|
+
await secrets.delete(input).catch(() => {
|
|
6338
|
+
return;
|
|
6339
|
+
});
|
|
6340
|
+
throw error;
|
|
6341
|
+
}
|
|
6342
|
+
await runSecretOperation(product, () => secrets.delete(input), "delete-failed");
|
|
6343
|
+
if (await runSecretOperation(product, () => secrets.get(input)) !== null) {
|
|
6344
|
+
throw new CliCredentialStoreUnavailableError(product, "delete-failed");
|
|
6345
|
+
}
|
|
6346
|
+
},
|
|
6135
6347
|
delete: async () => {
|
|
6136
|
-
await
|
|
6348
|
+
await runSecretOperation(product, () => secrets.delete({ name: account, service }), "delete-failed");
|
|
6137
6349
|
},
|
|
6138
6350
|
get: async () => {
|
|
6139
|
-
const value = await
|
|
6351
|
+
const value = await runSecretOperation(product, () => secrets.get({ name: account, service }));
|
|
6140
6352
|
if (value === null)
|
|
6141
6353
|
return null;
|
|
6142
6354
|
try {
|
|
@@ -6147,11 +6359,11 @@ var createBunCredentialStore = ({
|
|
|
6147
6359
|
},
|
|
6148
6360
|
set: async (credentials) => {
|
|
6149
6361
|
const parsed = storedCliCredentialsSchema.parse(credentials);
|
|
6150
|
-
await
|
|
6362
|
+
await runSecretOperation(product, () => secrets.set({
|
|
6151
6363
|
name: account,
|
|
6152
6364
|
service,
|
|
6153
6365
|
value: JSON.stringify(parsed)
|
|
6154
|
-
}));
|
|
6366
|
+
}), "write-failed");
|
|
6155
6367
|
},
|
|
6156
6368
|
withCredentialLock: async (operation) => {
|
|
6157
6369
|
const refreshLockPath = await getCredentialLockPath(product, account);
|
|
@@ -6172,6 +6384,7 @@ var createBunCredentialStore = ({
|
|
|
6172
6384
|
};
|
|
6173
6385
|
// ../../cli-auth/src/client/login.ts
|
|
6174
6386
|
import { hostname } from "os";
|
|
6387
|
+
import { isDeepStrictEqual } from "util";
|
|
6175
6388
|
var normalizeCliAuthIssuer = (value) => {
|
|
6176
6389
|
const url = new URL(value);
|
|
6177
6390
|
url.hash = "";
|
|
@@ -6234,12 +6447,15 @@ var openSystemBrowser = async (url) => {
|
|
|
6234
6447
|
"-NoProfile",
|
|
6235
6448
|
"-NonInteractive",
|
|
6236
6449
|
"-Command",
|
|
6237
|
-
"Start-Process -FilePath $
|
|
6238
|
-
url
|
|
6450
|
+
"Start-Process -FilePath $env:GO_LABS_CLI_VERIFICATION_URI -ErrorAction Stop"
|
|
6239
6451
|
] : ["xdg-open", url];
|
|
6240
6452
|
try {
|
|
6241
|
-
const
|
|
6242
|
-
|
|
6453
|
+
const browserProcess = Bun.spawn(command, {
|
|
6454
|
+
env: process.platform === "win32" ? { ...process.env, GO_LABS_CLI_VERIFICATION_URI: url } : process.env,
|
|
6455
|
+
stderr: "ignore",
|
|
6456
|
+
stdout: "ignore"
|
|
6457
|
+
});
|
|
6458
|
+
return await browserProcess.exited === 0;
|
|
6243
6459
|
} catch {
|
|
6244
6460
|
return false;
|
|
6245
6461
|
}
|
|
@@ -6257,6 +6473,8 @@ var loginWithBrowser = async ({
|
|
|
6257
6473
|
store
|
|
6258
6474
|
}) => {
|
|
6259
6475
|
const baseUrl = normalizeCliAuthIssuer(apiBaseUrl);
|
|
6476
|
+
if (store.preflight)
|
|
6477
|
+
await withCredentialLock(store, () => store.preflight?.() ?? Promise.resolve());
|
|
6260
6478
|
const pkce = createPkcePair();
|
|
6261
6479
|
const beginResponse = await postJson(fetchImplementation, `${baseUrl}/api/cli-auth/device`, {
|
|
6262
6480
|
clientName,
|
|
@@ -6284,7 +6502,19 @@ var loginWithBrowser = async ({
|
|
|
6284
6502
|
if (response.ok) {
|
|
6285
6503
|
const issued = tokenResponseSchema.parse(payload);
|
|
6286
6504
|
const credentials = toStoredCredentials(issued, baseUrl, now());
|
|
6287
|
-
|
|
6505
|
+
try {
|
|
6506
|
+
await withCredentialLock(store, () => persistIssuedCredentials({
|
|
6507
|
+
store,
|
|
6508
|
+
credentials,
|
|
6509
|
+
apiBaseUrl: baseUrl,
|
|
6510
|
+
fetch: fetchImplementation,
|
|
6511
|
+
phase: "login"
|
|
6512
|
+
}));
|
|
6513
|
+
} catch (error) {
|
|
6514
|
+
if (error instanceof CliCredentialPersistenceError)
|
|
6515
|
+
throw error;
|
|
6516
|
+
throw new CliCredentialPersistenceError(await revokeIssuedCredentials(fetchImplementation, baseUrl, credentials), false, "login");
|
|
6517
|
+
}
|
|
6288
6518
|
return credentials;
|
|
6289
6519
|
}
|
|
6290
6520
|
const error = deviceTokenErrorSchema.safeParse(payload);
|
|
@@ -6304,6 +6534,55 @@ var loginWithBrowser = async ({
|
|
|
6304
6534
|
}
|
|
6305
6535
|
throw new Error("CLI authentication expired. Run auth login again.");
|
|
6306
6536
|
};
|
|
6537
|
+
var revokeIssuedCredentials = async (fetchImplementation, apiBaseUrl, credentials) => {
|
|
6538
|
+
try {
|
|
6539
|
+
const response = await postJson(fetchImplementation, `${normalizeCliAuthIssuer(apiBaseUrl)}/api/cli-auth/revoke`, { refreshToken: credentials.refreshToken }, { signal: AbortSignal.timeout(refreshRequestTimeoutMs) });
|
|
6540
|
+
return response.ok;
|
|
6541
|
+
} catch {
|
|
6542
|
+
return false;
|
|
6543
|
+
}
|
|
6544
|
+
};
|
|
6545
|
+
var persistIssuedCredentials = async ({
|
|
6546
|
+
store,
|
|
6547
|
+
credentials,
|
|
6548
|
+
previous,
|
|
6549
|
+
apiBaseUrl,
|
|
6550
|
+
fetch: fetchImplementation,
|
|
6551
|
+
phase
|
|
6552
|
+
}) => {
|
|
6553
|
+
let prior = previous;
|
|
6554
|
+
try {
|
|
6555
|
+
if (phase === "login")
|
|
6556
|
+
prior = await store.get();
|
|
6557
|
+
await store.set(credentials);
|
|
6558
|
+
const saved = await store.get();
|
|
6559
|
+
if (!isDeepStrictEqual(saved, credentials))
|
|
6560
|
+
throw new Error("Credential write could not be verified");
|
|
6561
|
+
return;
|
|
6562
|
+
} catch {
|
|
6563
|
+
const remoteRevoked = await revokeIssuedCredentials(fetchImplementation, apiBaseUrl, credentials);
|
|
6564
|
+
let localRestored = false;
|
|
6565
|
+
try {
|
|
6566
|
+
const current = await store.get();
|
|
6567
|
+
if (phase === "login" && prior !== undefined) {
|
|
6568
|
+
if (isDeepStrictEqual(current, prior))
|
|
6569
|
+
localRestored = true;
|
|
6570
|
+
else if (current === null || current.refreshToken === credentials.refreshToken) {
|
|
6571
|
+
if (prior)
|
|
6572
|
+
await store.set(prior);
|
|
6573
|
+
else
|
|
6574
|
+
await store.delete();
|
|
6575
|
+
localRestored = isDeepStrictEqual(await store.get(), prior);
|
|
6576
|
+
}
|
|
6577
|
+
} else if (phase === "refresh" && (!current || current.refreshToken === credentials.refreshToken || current.refreshToken === prior?.refreshToken)) {
|
|
6578
|
+
if (current)
|
|
6579
|
+
await store.delete();
|
|
6580
|
+
localRestored = await store.get() === null;
|
|
6581
|
+
}
|
|
6582
|
+
} catch {}
|
|
6583
|
+
throw new CliCredentialPersistenceError(remoteRevoked, localRestored, phase);
|
|
6584
|
+
}
|
|
6585
|
+
};
|
|
6307
6586
|
var refreshes = new WeakMap;
|
|
6308
6587
|
var refreshRequestTimeoutMs = 30000;
|
|
6309
6588
|
var isInvalidGrantResponse = (payload) => {
|
|
@@ -6358,7 +6637,14 @@ var refreshAccessToken = async ({
|
|
|
6358
6637
|
throw new Error("Unable to refresh the CLI session because the API returned invalid credentials. Credentials were kept; retry the command.");
|
|
6359
6638
|
}
|
|
6360
6639
|
const stored = toStoredCredentials(issued, normalizeCliAuthIssuer(apiBaseUrl), now());
|
|
6361
|
-
await
|
|
6640
|
+
await persistIssuedCredentials({
|
|
6641
|
+
store,
|
|
6642
|
+
credentials: stored,
|
|
6643
|
+
previous: credentials,
|
|
6644
|
+
apiBaseUrl,
|
|
6645
|
+
fetch: fetchImplementation,
|
|
6646
|
+
phase: "refresh"
|
|
6647
|
+
});
|
|
6362
6648
|
return stored.accessToken;
|
|
6363
6649
|
};
|
|
6364
6650
|
var refreshWithCurrentCredentials = async ({
|
|
@@ -6641,6 +6927,9 @@ var sanitizeValue = (value, seen = new WeakSet) => {
|
|
|
6641
6927
|
]));
|
|
6642
6928
|
};
|
|
6643
6929
|
var normalizeError = (error) => {
|
|
6930
|
+
const storageError = getCliStorageError(error);
|
|
6931
|
+
if (storageError)
|
|
6932
|
+
return storageError;
|
|
6644
6933
|
if (error instanceof CliError) {
|
|
6645
6934
|
return {
|
|
6646
6935
|
code: error.code,
|
|
@@ -8038,7 +8327,10 @@ var runGoshCli = async (argv, dependencies) => {
|
|
|
8038
8327
|
command: "commands"
|
|
8039
8328
|
}, commandManifest);
|
|
8040
8329
|
}
|
|
8041
|
-
const credentialStore = dependencies.credentialStore ?? createBunCredentialStore({
|
|
8330
|
+
const credentialStore = dependencies.credentialStore ?? createBunCredentialStore({
|
|
8331
|
+
account: resolveCliCredentialAccount(dependencies.runtime.env),
|
|
8332
|
+
product: "gosh"
|
|
8333
|
+
});
|
|
8042
8334
|
if (first === "auth" && rest[0] === "login" && rest.length === 1) {
|
|
8043
8335
|
const credentials = await loginWithBrowser({
|
|
8044
8336
|
apiBaseUrl,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@go-labs-sg/gosh",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.0",
|
|
4
4
|
"description": "GOSH CLI for organizers and AI agents — manage organizations, events, teams, stations, missions, templates, and live operations through the GOSH API.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|