@intentius/behold 0.32.0 → 0.33.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.
@@ -0,0 +1,78 @@
1
+ // node_modules/@intentius/chant/dist/cloud-lister/sigv4.js
2
+ import { createHash, createHmac } from "node:crypto";
3
+ var EMPTY_PAYLOAD_SHA256 = "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855";
4
+ function sha256Hex(data) {
5
+ return typeof data === "string" ? createHash("sha256").update(data, "utf8").digest("hex") : createHash("sha256").update(data).digest("hex");
6
+ }
7
+ function hmac(key, data) {
8
+ return createHmac("sha256", key).update(data, "utf8").digest();
9
+ }
10
+ function encodeRfc3986(value) {
11
+ return encodeURIComponent(value).replace(/[!'()*]/g, (c) => `%${c.charCodeAt(0).toString(16).toUpperCase()}`);
12
+ }
13
+ function amzDates(now) {
14
+ const iso = now.toISOString().replace(/[-:]/g, "").replace(/\.\d{3}/, "");
15
+ return { amzDate: iso, dateStamp: iso.slice(0, 8) };
16
+ }
17
+ function signingKey(secret, dateStamp, region, service) {
18
+ return hmac(hmac(hmac(hmac(`AWS4${secret}`, dateStamp), region), service), "aws4_request");
19
+ }
20
+ function canonicalQuery(url) {
21
+ const pairs = [];
22
+ url.searchParams.forEach((v, k) => pairs.push([encodeRfc3986(k), encodeRfc3986(v)]));
23
+ pairs.sort((a, b) => a[0] === b[0] ? a[1] < b[1] ? -1 : a[1] > b[1] ? 1 : 0 : a[0] < b[0] ? -1 : 1);
24
+ return pairs.map(([k, v]) => `${k}=${v}`).join("&");
25
+ }
26
+ function signV4(input) {
27
+ const url = new URL(input.url);
28
+ const { amzDate, dateStamp } = amzDates(input.now);
29
+ const payloadHash = input.payloadHash ?? (input.body.length === 0 ? EMPTY_PAYLOAD_SHA256 : sha256Hex(input.body));
30
+ const headers = {};
31
+ for (const [k, v] of Object.entries(input.headers))
32
+ headers[k.toLowerCase()] = v.trim().replace(/\s+/g, " ");
33
+ headers.host = url.host;
34
+ headers["x-amz-date"] = amzDate;
35
+ if (input.contentSha256)
36
+ headers["x-amz-content-sha256"] = payloadHash;
37
+ if (input.credentials.sessionToken)
38
+ headers["x-amz-security-token"] = input.credentials.sessionToken;
39
+ const unsigned = new Set([...input.unsignedHeaders ?? []].map((n) => n.toLowerCase()));
40
+ const names = Object.keys(headers).filter((n) => !unsigned.has(n)).sort();
41
+ const canonicalHeaders = names.map((n) => `${n}:${headers[n]}
42
+ `).join("");
43
+ const signedHeaders = names.join(";");
44
+ const canonicalRequest = [input.method.toUpperCase(), url.pathname || "/", canonicalQuery(url), canonicalHeaders, signedHeaders, payloadHash].join("\n");
45
+ const scope = `${dateStamp}/${input.region}/${input.service}/aws4_request`;
46
+ const stringToSign = ["AWS4-HMAC-SHA256", amzDate, scope, sha256Hex(canonicalRequest)].join("\n");
47
+ const signature = createHmac("sha256", signingKey(input.credentials.secretAccessKey, dateStamp, input.region, input.service)).update(stringToSign, "utf8").digest("hex");
48
+ headers.authorization = `AWS4-HMAC-SHA256 Credential=${input.credentials.accessKeyId}/${scope}, SignedHeaders=${signedHeaders}, Signature=${signature}`;
49
+ if (input.omitHost)
50
+ delete headers.host;
51
+ return headers;
52
+ }
53
+ function presignV4(input) {
54
+ const url = new URL(input.url);
55
+ const { amzDate, dateStamp } = amzDates(input.now);
56
+ const scope = `${dateStamp}/${input.region}/${input.service}/aws4_request`;
57
+ const params = {
58
+ ...Object.fromEntries(url.searchParams),
59
+ "X-Amz-Algorithm": "AWS4-HMAC-SHA256",
60
+ "X-Amz-Credential": `${input.credentials.accessKeyId}/${scope}`,
61
+ "X-Amz-Date": amzDate,
62
+ "X-Amz-Expires": String(input.seconds),
63
+ ...input.credentials.sessionToken ? { "X-Amz-Security-Token": input.credentials.sessionToken } : {},
64
+ "X-Amz-SignedHeaders": "host"
65
+ };
66
+ const query = Object.keys(params).sort().map((k) => `${encodeRfc3986(k)}=${encodeRfc3986(params[k])}`).join("&");
67
+ const canonical = ["GET", url.pathname, query, `host:${url.host}`, "", "host", "UNSIGNED-PAYLOAD"].join("\n");
68
+ const toSign = ["AWS4-HMAC-SHA256", amzDate, scope, sha256Hex(canonical)].join("\n");
69
+ const signature = createHmac("sha256", signingKey(input.credentials.secretAccessKey, dateStamp, input.region, input.service)).update(toSign).digest("hex");
70
+ return `${url.origin}${url.pathname}?${query}&X-Amz-Signature=${signature}`;
71
+ }
72
+
73
+ export {
74
+ sha256Hex,
75
+ encodeRfc3986,
76
+ signV4,
77
+ presignV4
78
+ };
@@ -0,0 +1,124 @@
1
+ // node_modules/@intentius/chant/dist/workspace/tree.js
2
+ import { execFileSync } from "node:child_process";
3
+ import { readdirSync, readFileSync, statSync } from "node:fs";
4
+ import { join } from "node:path";
5
+ function joinPath(...parts) {
6
+ return parts.filter((p) => p !== "" && p !== ".").join("/");
7
+ }
8
+ function workingTree(root) {
9
+ return {
10
+ label: "",
11
+ stat(path) {
12
+ try {
13
+ const s = statSync(join(root, path));
14
+ return s.isDirectory() ? "dir" : s.isFile() ? "file" : void 0;
15
+ } catch {
16
+ return void 0;
17
+ }
18
+ },
19
+ list(path) {
20
+ let dirents;
21
+ try {
22
+ dirents = readdirSync(join(root, path), { withFileTypes: true });
23
+ } catch {
24
+ return void 0;
25
+ }
26
+ const out = [];
27
+ for (const d of dirents) {
28
+ let type = d.isDirectory() ? "dir" : d.isFile() ? "file" : void 0;
29
+ if (!type && d.isSymbolicLink()) {
30
+ try {
31
+ const s = statSync(join(root, path, d.name));
32
+ type = s.isDirectory() ? "dir" : s.isFile() ? "file" : void 0;
33
+ } catch {
34
+ }
35
+ }
36
+ if (type)
37
+ out.push({ name: d.name, type });
38
+ }
39
+ return out;
40
+ },
41
+ read(path) {
42
+ return readFileSync(join(root, path), "utf-8");
43
+ },
44
+ bytes(path) {
45
+ return readFileSync(join(root, path));
46
+ }
47
+ };
48
+ }
49
+ function git(cwd, args) {
50
+ return execFileSync("git", args, { cwd, encoding: "utf-8", stdio: ["ignore", "pipe", "pipe"], maxBuffer: 512 * 1024 * 1024 });
51
+ }
52
+ function gitTop(cwd) {
53
+ try {
54
+ return git(cwd, ["rev-parse", "--show-toplevel"]).trim();
55
+ } catch {
56
+ return void 0;
57
+ }
58
+ }
59
+ function resolveCommit(top, rev) {
60
+ if (rev.startsWith("-"))
61
+ return void 0;
62
+ try {
63
+ return git(top, ["rev-parse", "--verify", "--quiet", `${rev}^{commit}`]).trim();
64
+ } catch {
65
+ return void 0;
66
+ }
67
+ }
68
+ function gitTree(top, commit, prefix = "") {
69
+ const entries = /* @__PURE__ */ new Map([["", "dir"]]);
70
+ const children = /* @__PURE__ */ new Map([["", []]]);
71
+ const out = git(top, ["ls-tree", "-r", "-t", "-z", "--full-tree", commit]);
72
+ for (const line of out.split("\0")) {
73
+ if (!line)
74
+ continue;
75
+ const tab = line.indexOf(" ");
76
+ const type = line.slice(0, tab).split(" ")[1];
77
+ const full = line.slice(tab + 1);
78
+ let path;
79
+ if (prefix === "")
80
+ path = full;
81
+ else if (full.startsWith(`${prefix}/`))
82
+ path = full.slice(prefix.length + 1);
83
+ else
84
+ continue;
85
+ const kind = type === "tree" ? "dir" : type === "blob" ? "file" : void 0;
86
+ if (!kind)
87
+ continue;
88
+ entries.set(path, kind);
89
+ const slash = path.lastIndexOf("/");
90
+ const parent = slash < 0 ? "" : path.slice(0, slash);
91
+ if (!children.has(parent))
92
+ children.set(parent, []);
93
+ children.get(parent).push({ name: path.slice(slash + 1), type: kind });
94
+ if (kind === "dir" && !children.has(path))
95
+ children.set(path, []);
96
+ }
97
+ return {
98
+ label: ` at ${commit.slice(0, 8)}`,
99
+ stat: (path) => entries.get(path),
100
+ list: (path) => entries.get(path) === "dir" ? [...children.get(path) ?? []] : void 0,
101
+ read(path) {
102
+ if (entries.get(path) !== "file")
103
+ throw new Error(`${path} is not a file${` at ${commit.slice(0, 8)}`}`);
104
+ return git(top, ["cat-file", "blob", `${commit}:${joinPath(prefix, path)}`]);
105
+ },
106
+ bytes(path) {
107
+ if (entries.get(path) !== "file")
108
+ throw new Error(`${path} is not a file${` at ${commit.slice(0, 8)}`}`);
109
+ return execFileSync("git", ["cat-file", "blob", `${commit}:${joinPath(prefix, path)}`], { cwd: top, stdio: ["ignore", "pipe", "pipe"], maxBuffer: 512 * 1024 * 1024 });
110
+ }
111
+ };
112
+ }
113
+ function skippedDir(name) {
114
+ return name === "node_modules" || name.startsWith(".");
115
+ }
116
+
117
+ export {
118
+ joinPath,
119
+ workingTree,
120
+ gitTop,
121
+ resolveCommit,
122
+ gitTree,
123
+ skippedDir
124
+ };