sedum-cli 0.1.0-alpha.18 → 0.1.0-alpha.21
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 +65 -0
- package/dist/{affected-selection-DAQPGKOZ.js → affected-selection-NTBVWIK5.js} +10 -50
- package/dist/auth-command-TSTYIWGX.js +634 -0
- package/dist/chunk-CGDXQY2Y.js +208 -0
- package/dist/{chunk-SI2F6MBN.js → chunk-DXNJ3PGB.js} +44 -18
- package/dist/{chunk-FG46OUHT.js → chunk-FOGLJA3Z.js} +4 -2
- package/dist/{chunk-KZF4NZ6M.js → chunk-J7CLCLHW.js} +267 -354
- package/dist/chunk-JYWNBHN7.js +109 -0
- package/dist/chunk-NIUOM3FA.js +50 -0
- package/dist/{chunk-EPXLY5Q4.js → chunk-PX6PJ7U2.js} +291 -174
- package/dist/{chunk-6ILFLNDI.js → chunk-QVCT63FH.js} +1 -1
- package/dist/cli.js +10 -3
- package/dist/cloud-command-YYQ47FTU.js +329 -0
- package/dist/cloud-upload-IGNNU5WX.js +243 -0
- package/dist/{doctor-command-7IBKI5YO.js → doctor-command-OFMURNPN.js} +5 -2
- package/dist/{explore-command-QZCKFDYM.js → explore-command-KMS6UAPM.js} +3 -2
- package/dist/index.d.ts +21 -0
- package/dist/index.js +5 -3
- package/dist/{init-command-MBTLGU5J.js → init-command-IXR3YUQW.js} +3 -2
- package/dist/{run-command-P55TKTX3.js → run-command-6UTIJAHU.js} +39 -22
- package/package.json +6 -5
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
// src/auth-api.ts
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
var AuthError = class extends Error {
|
|
4
|
+
};
|
|
5
|
+
function cloudOrigin(value) {
|
|
6
|
+
try {
|
|
7
|
+
const url = new URL(value);
|
|
8
|
+
if ([url.username, url.password, url.search, url.hash].some(Boolean))
|
|
9
|
+
throw new Error();
|
|
10
|
+
if (!["/", ""].includes(url.pathname)) throw new Error();
|
|
11
|
+
if (!secureProtocol(url)) throw new Error();
|
|
12
|
+
return url.origin;
|
|
13
|
+
} catch {
|
|
14
|
+
throw new AuthError(
|
|
15
|
+
"Cloud URL must be an HTTPS origin (HTTP is allowed only on loopback), without credentials, path, query or fragment."
|
|
16
|
+
);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
function secureProtocol(url) {
|
|
20
|
+
if (url.protocol === "https:") return true;
|
|
21
|
+
return url.protocol === "http:" && ["localhost", "127.0.0.1", "[::1]"].includes(url.hostname);
|
|
22
|
+
}
|
|
23
|
+
var tokensSchema = z.object({
|
|
24
|
+
token_type: z.literal("Bearer"),
|
|
25
|
+
access_token: z.string().min(1),
|
|
26
|
+
refresh_token: z.string().min(1),
|
|
27
|
+
expires_in: z.number().positive().finite()
|
|
28
|
+
});
|
|
29
|
+
var membershipSchema = z.object({
|
|
30
|
+
user: z.object({
|
|
31
|
+
id: z.string(),
|
|
32
|
+
name: z.string().nullable(),
|
|
33
|
+
email: z.string().nullable()
|
|
34
|
+
}),
|
|
35
|
+
organizations: z.array(
|
|
36
|
+
z.object({
|
|
37
|
+
id: z.string(),
|
|
38
|
+
name: z.string(),
|
|
39
|
+
role: z.string(),
|
|
40
|
+
projects: z.array(z.object({ id: z.string(), name: z.string() }))
|
|
41
|
+
})
|
|
42
|
+
)
|
|
43
|
+
});
|
|
44
|
+
async function request(origin, endpoint, signal, options = {}) {
|
|
45
|
+
try {
|
|
46
|
+
const response = await fetch(`${origin}${endpoint}`, {
|
|
47
|
+
redirect: "error",
|
|
48
|
+
signal: AbortSignal.any([signal, AbortSignal.timeout(15e3)]),
|
|
49
|
+
...requestOptions(options)
|
|
50
|
+
});
|
|
51
|
+
const body = await responseBody(response, endpoint);
|
|
52
|
+
return {
|
|
53
|
+
ok: response.ok,
|
|
54
|
+
status: response.status,
|
|
55
|
+
body,
|
|
56
|
+
retryMs: retryDelay(response.headers.get("retry-after"))
|
|
57
|
+
};
|
|
58
|
+
} catch {
|
|
59
|
+
throw new AuthError(
|
|
60
|
+
signal.aborted ? "Authentication cancelled." : "Cloud request failed or timed out. Check the instance URL and connection; redirects are not allowed."
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
async function responseBody(response, endpoint) {
|
|
65
|
+
const readBody = response.ok && endpoint !== "/api/oauth/revoke" || response.status === 400 && endpoint === "/api/oauth/token";
|
|
66
|
+
if (readBody) return response.json();
|
|
67
|
+
await response.body?.cancel().catch(() => {
|
|
68
|
+
});
|
|
69
|
+
return {};
|
|
70
|
+
}
|
|
71
|
+
function requestOptions({
|
|
72
|
+
form,
|
|
73
|
+
access
|
|
74
|
+
}) {
|
|
75
|
+
const headers = {};
|
|
76
|
+
if (access) headers.authorization = `Bearer ${access}`;
|
|
77
|
+
if (!form) return { method: "GET", headers };
|
|
78
|
+
headers["content-type"] = "application/x-www-form-urlencoded";
|
|
79
|
+
return {
|
|
80
|
+
method: "POST",
|
|
81
|
+
headers,
|
|
82
|
+
body: new URLSearchParams({ client_id: "sedum-cli", ...form })
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
function retryDelay(retry) {
|
|
86
|
+
if (!retry) return 0;
|
|
87
|
+
const delay = /^\d+$/.test(retry) ? Number(retry) * 1e3 : Math.max(0, Date.parse(retry) - Date.now());
|
|
88
|
+
return Number.isFinite(delay) ? delay : 0;
|
|
89
|
+
}
|
|
90
|
+
function parse(schema, value) {
|
|
91
|
+
const result = schema.safeParse(value);
|
|
92
|
+
if (!result.success)
|
|
93
|
+
throw new AuthError("Cloud returned an invalid authentication response.");
|
|
94
|
+
return result.data;
|
|
95
|
+
}
|
|
96
|
+
function tokenResult(body) {
|
|
97
|
+
const tokens = parse(tokensSchema, body);
|
|
98
|
+
return { ...tokens, expiresAt: Date.now() + tokens.expires_in * 1e3 };
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export {
|
|
102
|
+
AuthError,
|
|
103
|
+
cloudOrigin,
|
|
104
|
+
tokensSchema,
|
|
105
|
+
membershipSchema,
|
|
106
|
+
request,
|
|
107
|
+
parse,
|
|
108
|
+
tokenResult
|
|
109
|
+
};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
// src/affected-git-read.ts
|
|
2
|
+
import { spawn } from "child_process";
|
|
3
|
+
import { isUtf8 } from "buffer";
|
|
4
|
+
var MAX_DIFF_BYTES = 16 * 1024 * 1024;
|
|
5
|
+
var AffectedSelectionError = class extends Error {
|
|
6
|
+
};
|
|
7
|
+
function gitRead(cwd, args, signal, limit = MAX_DIFF_BYTES) {
|
|
8
|
+
return new Promise((resolve, reject) => {
|
|
9
|
+
const child = spawn("git", args, {
|
|
10
|
+
cwd,
|
|
11
|
+
stdio: ["ignore", "pipe", "ignore"],
|
|
12
|
+
env: { ...process.env, GIT_OPTIONAL_LOCKS: "0" },
|
|
13
|
+
...signal ? { signal } : {}
|
|
14
|
+
});
|
|
15
|
+
const buffers = [];
|
|
16
|
+
let bytes = 0;
|
|
17
|
+
let exceeded = false;
|
|
18
|
+
child.stdout.on("data", (buffer) => {
|
|
19
|
+
bytes += buffer.length;
|
|
20
|
+
if (bytes > limit) {
|
|
21
|
+
exceeded = true;
|
|
22
|
+
child.kill();
|
|
23
|
+
} else buffers.push(buffer);
|
|
24
|
+
});
|
|
25
|
+
child.on("error", reject);
|
|
26
|
+
child.on("close", (code) => {
|
|
27
|
+
if (exceeded)
|
|
28
|
+
reject(
|
|
29
|
+
new AffectedSelectionError(
|
|
30
|
+
"Retained Git input exceeds the 16 MiB guard. Run the full suite; input was not truncated."
|
|
31
|
+
)
|
|
32
|
+
);
|
|
33
|
+
else if (code !== 0) reject(new Error("Git read failed"));
|
|
34
|
+
else resolve(Buffer.concat(buffers));
|
|
35
|
+
});
|
|
36
|
+
}).then(decodeGitOutput);
|
|
37
|
+
}
|
|
38
|
+
function decodeGitOutput(output) {
|
|
39
|
+
if (!isUtf8(output))
|
|
40
|
+
throw new AffectedSelectionError(
|
|
41
|
+
"Git input is not valid UTF-8. Run the full suite."
|
|
42
|
+
);
|
|
43
|
+
return output.toString("utf8");
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export {
|
|
47
|
+
MAX_DIFF_BYTES,
|
|
48
|
+
AffectedSelectionError,
|
|
49
|
+
gitRead
|
|
50
|
+
};
|