just-bash 2.13.0 → 2.13.1
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 +300 -314
- package/dist/bin/chunks/{chunk-3YMCKZTY.js → chunk-FBJJY4ZV.js} +1 -1
- package/dist/bin/chunks/chunk-LIYVQA3X.js +2 -0
- package/dist/bin/chunks/{chunk-N6KA6G3Q.js → chunk-TKTKRRAL.js} +1 -1
- package/dist/bin/chunks/curl-SRTMGOVV.js +26 -0
- package/dist/bin/chunks/{flag-coverage-IRM4GISL.js → flag-coverage-A4G6STMS.js} +1 -1
- package/dist/bin/chunks/{js-exec-YGYYZEEQ.js → js-exec-JORCTVUT.js} +1 -1
- package/dist/bin/chunks/js-exec-worker.js +1 -0
- package/dist/bin/{shell/chunks/python3-WO3WFGMS.js → chunks/python3-PF7AHNQM.js} +1 -1
- package/dist/bin/chunks/time-DDS6JJ23.js +2 -0
- package/dist/bin/chunks/worker.js +1 -0
- package/dist/bin/just-bash.js +178 -178
- package/dist/bin/shell/chunks/{chunk-3YMCKZTY.js → chunk-FBJJY4ZV.js} +1 -1
- package/dist/bin/shell/chunks/chunk-LIYVQA3X.js +2 -0
- package/dist/bin/shell/chunks/{chunk-N6KA6G3Q.js → chunk-TKTKRRAL.js} +1 -1
- package/dist/bin/shell/chunks/curl-SRTMGOVV.js +26 -0
- package/dist/bin/shell/chunks/{flag-coverage-IRM4GISL.js → flag-coverage-A4G6STMS.js} +1 -1
- package/dist/bin/shell/chunks/{js-exec-VYG74FQ3.js → js-exec-B6QNYHUL.js} +1 -1
- package/dist/bin/{chunks/python3-EIXZW3LO.js → shell/chunks/python3-J7DP4JBQ.js} +1 -1
- package/dist/bin/shell/chunks/time-DDS6JJ23.js +2 -0
- package/dist/bin/shell/shell.js +180 -180
- package/dist/bundle/browser.js +485 -485
- package/dist/bundle/chunks/chunk-CWQS3NFK.js +1 -0
- package/dist/bundle/chunks/{chunk-JCMONG3T.js → chunk-F5CMUULS.js} +1 -1
- package/dist/bundle/chunks/{chunk-MJWMXCEJ.js → chunk-H2WXJGD7.js} +1 -1
- package/dist/bundle/chunks/curl-COE4TZE6.js +25 -0
- package/dist/bundle/chunks/{flag-coverage-SPT2DN2I.js → flag-coverage-G2R7PMYU.js} +1 -1
- package/dist/bundle/chunks/{js-exec-R2LSP7M4.js → js-exec-YJSMH5AG.js} +1 -1
- package/dist/bundle/chunks/js-exec-worker.js +1 -0
- package/dist/bundle/chunks/{python3-DH2SBOI3.js → python3-6HF56IYI.js} +1 -1
- package/dist/bundle/chunks/{time-FABCOJJU.js → time-YG5BMRIQ.js} +1 -1
- package/dist/bundle/chunks/worker.js +1 -0
- package/dist/bundle/index.cjs +657 -657
- package/dist/bundle/index.js +118 -118
- package/dist/commands/curl/types.d.ts +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/network/allow-list.d.ts +5 -3
- package/dist/network/fetch.d.ts +1 -1
- package/dist/network/index.d.ts +1 -1
- package/dist/network/types.d.ts +32 -1
- package/package.json +2 -2
- package/dist/bin/chunks/chunk-QZNF3Y3J.js +0 -2
- package/dist/bin/chunks/curl-B64SIJOD.js +0 -26
- package/dist/bin/chunks/time-VSKBXRQH.js +0 -2
- package/dist/bin/shell/chunks/chunk-QZNF3Y3J.js +0 -2
- package/dist/bin/shell/chunks/curl-B64SIJOD.js +0 -26
- package/dist/bin/shell/chunks/time-VSKBXRQH.js +0 -2
- package/dist/bundle/chunks/chunk-RH6GWZAJ.js +0 -1
- package/dist/bundle/chunks/curl-FCIO57JJ.js +0 -25
package/dist/index.d.cts
CHANGED
|
@@ -10,7 +10,7 @@ export type { BufferEncoding, CpOptions, DirectoryEntry, FileContent, FileEntry,
|
|
|
10
10
|
export { MountableFs, type MountableFsOptions, type MountConfig, } from "./fs/mountable-fs/index.js";
|
|
11
11
|
export { OverlayFs, type OverlayFsOptions } from "./fs/overlay-fs/index.js";
|
|
12
12
|
export { ReadWriteFs, type ReadWriteFsOptions, } from "./fs/read-write-fs/index.js";
|
|
13
|
-
export type { NetworkConfig, SecureFetch } from "./network/index.js";
|
|
13
|
+
export type { AllowedUrl, AllowedUrlEntry, NetworkConfig, RequestTransform, SecureFetch, } from "./network/index.js";
|
|
14
14
|
export { NetworkAccessDeniedError, RedirectNotAllowedError, TooManyRedirectsError, } from "./network/index.js";
|
|
15
15
|
export { parse } from "./parser/parser.js";
|
|
16
16
|
export type { CommandFinished as SandboxCommandFinished, OutputMessage, SandboxOptions, WriteFilesInput, } from "./sandbox/index.js";
|
package/dist/index.d.ts
CHANGED
|
@@ -10,7 +10,7 @@ export type { BufferEncoding, CpOptions, DirectoryEntry, FileContent, FileEntry,
|
|
|
10
10
|
export { MountableFs, type MountableFsOptions, type MountConfig, } from "./fs/mountable-fs/index.js";
|
|
11
11
|
export { OverlayFs, type OverlayFsOptions } from "./fs/overlay-fs/index.js";
|
|
12
12
|
export { ReadWriteFs, type ReadWriteFsOptions, } from "./fs/read-write-fs/index.js";
|
|
13
|
-
export type { NetworkConfig, SecureFetch } from "./network/index.js";
|
|
13
|
+
export type { AllowedUrl, AllowedUrlEntry, NetworkConfig, RequestTransform, SecureFetch, } from "./network/index.js";
|
|
14
14
|
export { NetworkAccessDeniedError, RedirectNotAllowedError, TooManyRedirectsError, } from "./network/index.js";
|
|
15
15
|
export { parse } from "./parser/parser.js";
|
|
16
16
|
export type { CommandFinished as SandboxCommandFinished, OutputMessage, SandboxOptions, WriteFilesInput, } from "./sandbox/index.js";
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
* This module provides URL allow-list matching that is enforced at the fetch layer,
|
|
5
5
|
* independent of any parsing or user input manipulation.
|
|
6
6
|
*/
|
|
7
|
+
import type { AllowedUrlEntry } from "./types.js";
|
|
7
8
|
/**
|
|
8
9
|
* Parses a URL string into its components.
|
|
9
10
|
* Returns null if the URL is invalid.
|
|
@@ -39,10 +40,10 @@ export declare function matchesAllowListEntry(url: string, allowedEntry: string)
|
|
|
39
40
|
* Checks if a URL is allowed by any entry in the allow-list.
|
|
40
41
|
*
|
|
41
42
|
* @param url The URL to check
|
|
42
|
-
* @param allowedUrlPrefixes The list of allowed URL prefixes
|
|
43
|
+
* @param allowedUrlPrefixes The list of allowed URL prefixes (strings or objects)
|
|
43
44
|
* @returns true if the URL is allowed
|
|
44
45
|
*/
|
|
45
|
-
export declare function isUrlAllowed(url: string, allowedUrlPrefixes:
|
|
46
|
+
export declare function isUrlAllowed(url: string, allowedUrlPrefixes: AllowedUrlEntry[]): boolean;
|
|
46
47
|
/**
|
|
47
48
|
* Check if a hostname is a private/loopback IP address.
|
|
48
49
|
* Only checks the string format — does not perform DNS resolution.
|
|
@@ -51,6 +52,7 @@ export declare function isPrivateIp(hostname: string): boolean;
|
|
|
51
52
|
/**
|
|
52
53
|
* Validates an allow-list configuration.
|
|
53
54
|
* Each entry must be a full origin (scheme + host), optionally followed by a path prefix.
|
|
55
|
+
* Accepts both plain strings and AllowedUrl objects.
|
|
54
56
|
* Returns an array of error messages for invalid entries.
|
|
55
57
|
*/
|
|
56
|
-
export declare function validateAllowList(allowedUrlPrefixes:
|
|
58
|
+
export declare function validateAllowList(allowedUrlPrefixes: AllowedUrlEntry[]): string[];
|
package/dist/network/fetch.d.ts
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
import { type FetchResult, type NetworkConfig } from "./types.js";
|
|
10
10
|
export interface SecureFetchOptions {
|
|
11
11
|
method?: string;
|
|
12
|
-
headers?: Record<string, string>;
|
|
12
|
+
headers?: Headers | Record<string, string>;
|
|
13
13
|
body?: string;
|
|
14
14
|
followRedirects?: boolean;
|
|
15
15
|
/** Override timeout for this request (capped at global timeout) */
|
package/dist/network/index.d.ts
CHANGED
|
@@ -4,4 +4,4 @@
|
|
|
4
4
|
* Provides secure network access with URL allow-list enforcement.
|
|
5
5
|
*/
|
|
6
6
|
export { createSecureFetch, type SecureFetch, type SecureFetchOptions, } from "./fetch.js";
|
|
7
|
-
export { type FetchResult, type HttpMethod, NetworkAccessDeniedError, type NetworkConfig, RedirectNotAllowedError, TooManyRedirectsError, } from "./types.js";
|
|
7
|
+
export { type AllowedUrl, type AllowedUrlEntry, type FetchResult, type HttpMethod, NetworkAccessDeniedError, type NetworkConfig, RedirectNotAllowedError, type RequestTransform, TooManyRedirectsError, } from "./types.js";
|
package/dist/network/types.d.ts
CHANGED
|
@@ -15,6 +15,26 @@ export interface DnsLookupResult {
|
|
|
15
15
|
* HTTP methods that can be allowed
|
|
16
16
|
*/
|
|
17
17
|
export type HttpMethod = "GET" | "HEAD" | "POST" | "PUT" | "DELETE" | "PATCH" | "OPTIONS";
|
|
18
|
+
/**
|
|
19
|
+
* Header transform applied at the fetch boundary.
|
|
20
|
+
* Headers specified here override any user-supplied headers with the same name.
|
|
21
|
+
*/
|
|
22
|
+
export interface RequestTransform {
|
|
23
|
+
headers: Record<string, string>;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* An allowed URL entry with optional header transforms.
|
|
27
|
+
* Transforms are applied at the fetch boundary so secrets never enter the sandbox.
|
|
28
|
+
*/
|
|
29
|
+
export interface AllowedUrl {
|
|
30
|
+
url: string;
|
|
31
|
+
transform?: RequestTransform[];
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* An entry in the allowedUrlPrefixes list: either a plain URL string or
|
|
35
|
+
* an object with a URL and optional transforms.
|
|
36
|
+
*/
|
|
37
|
+
export type AllowedUrlEntry = string | AllowedUrl;
|
|
18
38
|
/**
|
|
19
39
|
* Configuration for network access
|
|
20
40
|
*/
|
|
@@ -25,6 +45,17 @@ export interface NetworkConfig {
|
|
|
25
45
|
* - An origin: "https://api.example.com" - allows all paths on this origin
|
|
26
46
|
* - An origin + path prefix: "https://api.example.com/v1/" - allows only paths starting with /v1/
|
|
27
47
|
*
|
|
48
|
+
* Entries can be plain strings or objects with transforms for credentials brokering:
|
|
49
|
+
* ```
|
|
50
|
+
* allowedUrlPrefixes: [
|
|
51
|
+
* "https://other-api.com",
|
|
52
|
+
* {
|
|
53
|
+
* url: "https://ai-gateway.vercel.sh",
|
|
54
|
+
* transform: [{ headers: { "Authorization": "Bearer secret" } }],
|
|
55
|
+
* },
|
|
56
|
+
* ]
|
|
57
|
+
* ```
|
|
58
|
+
*
|
|
28
59
|
* The check is performed on the full URL, so "https://api.example.com/v1" will allow:
|
|
29
60
|
* - https://api.example.com/v1
|
|
30
61
|
* - https://api.example.com/v1/users
|
|
@@ -36,7 +67,7 @@ export interface NetworkConfig {
|
|
|
36
67
|
*
|
|
37
68
|
* Invalid entries (missing scheme, missing host, relative paths) will throw an error.
|
|
38
69
|
*/
|
|
39
|
-
allowedUrlPrefixes?:
|
|
70
|
+
allowedUrlPrefixes?: AllowedUrlEntry[];
|
|
40
71
|
/**
|
|
41
72
|
* List of allowed HTTP methods. Defaults to ["GET", "HEAD"] for safety.
|
|
42
73
|
* dangerouslyAllowFullInternetAccess to enables all methods.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "just-bash",
|
|
3
|
-
"version": "2.13.
|
|
3
|
+
"version": "2.13.1",
|
|
4
4
|
"description": "A simulated bash environment with virtual filesystem",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -100,7 +100,7 @@
|
|
|
100
100
|
"build:worker": "esbuild src/commands/python3/worker.ts --bundle --platform=node --format=esm --outfile=src/commands/python3/worker.js --external:../../../vendor/cpython-emscripten/* && cp src/commands/python3/worker.js dist/commands/python3/worker.js && mkdir -p dist/bin/chunks && cp src/commands/python3/worker.js dist/bin/chunks/worker.js && mkdir -p dist/bundle/chunks && cp src/commands/python3/worker.js dist/bundle/chunks/worker.js && esbuild src/commands/js-exec/worker.ts --bundle --platform=node --format=esm --outfile=src/commands/js-exec/worker.js --external:quickjs-emscripten && cp src/commands/js-exec/worker.js dist/commands/js-exec/worker.js && cp src/commands/js-exec/worker.js dist/bin/chunks/js-exec-worker.js && cp src/commands/js-exec/worker.js dist/bundle/chunks/js-exec-worker.js",
|
|
101
101
|
"build:lib": "esbuild dist/index.js --bundle --splitting --platform=node --format=esm --minify --outdir=dist/bundle --chunk-names=chunks/[name]-[hash] --external:diff --external:minimatch --external:sprintf-js --external:turndown --external:sql.js --external:quickjs-emscripten --external:@mongodb-js/zstd --external:node-liblzma --external:compressjs",
|
|
102
102
|
"build:lib:cjs": "esbuild dist/index.js --bundle --platform=node --format=cjs --minify --outfile=dist/bundle/index.cjs --external:diff --external:minimatch --external:sprintf-js --external:turndown --external:sql.js --external:quickjs-emscripten --external:@mongodb-js/zstd --external:node-liblzma --external:compressjs",
|
|
103
|
-
"build:browser": "esbuild dist/browser.js --bundle --platform=browser --format=esm --minify --outfile=dist/bundle/browser.js --external:diff --external:minimatch --external:sprintf-js --external:turndown --external:node
|
|
103
|
+
"build:browser": "esbuild dist/browser.js --bundle --platform=browser --format=esm --minify --outfile=dist/bundle/browser.js --external:diff --external:minimatch --external:sprintf-js --external:turndown --external:node:zlib --external:@mongodb-js/zstd --external:node-liblzma --external:compressjs --define:__BROWSER__=true --alias:node:dns=./src/shims/browser-unsupported.js",
|
|
104
104
|
"build:cli": "esbuild dist/cli/just-bash.js --bundle --splitting --platform=node --format=esm --minify --outdir=dist/bin --entry-names=[name] --chunk-names=chunks/[name]-[hash] --banner:js='#!/usr/bin/env node' --external:sql.js --external:quickjs-emscripten --external:@mongodb-js/zstd --external:node-liblzma --external:compressjs",
|
|
105
105
|
"build:shell": "esbuild dist/cli/shell.js --bundle --splitting --platform=node --format=esm --minify --outdir=dist/bin/shell --entry-names=[name] --chunk-names=chunks/[name]-[hash] --banner:js='#!/usr/bin/env node' --external:sql.js --external:quickjs-emscripten --external:@mongodb-js/zstd --external:node-liblzma --external:compressjs",
|
|
106
106
|
"validate": "pnpm lint && pnpm knip && pnpm typecheck && pnpm build && pnpm check:worker-sync && pnpm test:run && pnpm test:wasm && pnpm test:dist && pnpm test:examples",
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import{g as w}from"./chunk-V7ZOPVQS.js";import{a as b}from"./chunk-4VDEBYW7.js";import{a as y,b as T,c as d}from"./chunk-GTNBSMZR.js";import"./chunk-KGOUQS5A.js";function f(s){let t=s.indexOf("=");if(t>=0){let a=s.slice(0,t),r=s.slice(t+1);return a?`${encodeURIComponent(a)}=${encodeURIComponent(r)}`:encodeURIComponent(r)}return encodeURIComponent(s)}function c(s){let t=s.indexOf("=");if(t<0)return null;let a=s.slice(0,t),r=s.slice(t+1),e,i,o=r.match(/;type=([^;]+)$/);o&&(i=o[1],r=r.slice(0,-o[0].length));let n=r.match(/;filename=([^;]+)/);return n&&(e=n[1],r=r.replace(n[0],"")),(r.startsWith("@")||r.startsWith("<"))&&(e=e??r.slice(1).split("/").pop()),{name:a,value:r,filename:e,contentType:i}}function O(s,t){let a=`----CurlFormBoundary${Date.now().toString(36)}`,r=[];for(let e of s){let i=e.value;if(i.startsWith("@")||i.startsWith("<")){let n=i.slice(1);i=t.get(n)??""}let o=`--${a}\r
|
|
3
|
-
`;e.filename?(o+=`Content-Disposition: form-data; name="${e.name}"; filename="${e.filename}"\r
|
|
4
|
-
`,e.contentType&&(o+=`Content-Type: ${e.contentType}\r
|
|
5
|
-
`)):o+=`Content-Disposition: form-data; name="${e.name}"\r
|
|
6
|
-
`,o+=`\r
|
|
7
|
-
${i}\r
|
|
8
|
-
`,r.push(o)}return r.push(`--${a}--\r
|
|
9
|
-
`),{body:r.join(""),boundary:a}}var v={name:"curl",summary:"transfer a URL",usage:"curl [OPTIONS] URL",options:["-X, --request METHOD HTTP method (GET, POST, PUT, DELETE, etc.)","-H, --header HEADER Add header (can be used multiple times)","-d, --data DATA HTTP POST data"," --data-raw DATA HTTP POST data (no @ interpretation)"," --data-binary DATA HTTP POST binary data"," --data-urlencode DATA URL-encode and POST data","-F, --form NAME=VALUE Multipart form data","-u, --user USER:PASS HTTP authentication","-A, --user-agent STR Set User-Agent header","-e, --referer URL Set Referer header","-b, --cookie DATA Send cookies (name=value or @file)","-c, --cookie-jar FILE Save cookies to file","-T, --upload-file FILE Upload file (PUT)","-o, --output FILE Write output to file","-O, --remote-name Write to file named from URL","-I, --head Show headers only (HEAD request)","-i, --include Include response headers in output","-s, --silent Silent mode (no progress)","-S, --show-error Show errors even when silent","-f, --fail Fail silently on HTTP errors (no output)","-L, --location Follow redirects (default)"," --max-redirs NUM Maximum redirects (default: 20)","-m, --max-time SECS Maximum time for request"," --connect-timeout SECS Connection timeout","-w, --write-out FMT Output format after completion","-v, --verbose Verbose output"," --help Display this help and exit","","Note: Network access must be configured via BashEnv network option."," curl is not available by default for security reasons."]};function F(s){let t={method:"GET",headers:Object.create(null),dataBinary:!1,formFields:[],useRemoteName:!1,headOnly:!1,includeHeaders:!1,silent:!1,showError:!1,failSilently:!1,followRedirects:!0,verbose:!1},a=!1;for(let r=0;r<s.length;r++){let e=s[r];if(e==="-X"||e==="--request")t.method=s[++r]??"GET";else if(e.startsWith("-X"))t.method=e.slice(2);else if(e.startsWith("--request="))t.method=e.slice(10);else if(e==="-H"||e==="--header"){let i=s[++r];if(i){let o=i.indexOf(":");if(o>0){let n=i.slice(0,o).trim(),l=i.slice(o+1).trim();t.headers[n]=l}}}else if(e.startsWith("--header=")){let i=e.slice(9),o=i.indexOf(":");if(o>0){let n=i.slice(0,o).trim(),l=i.slice(o+1).trim();t.headers[n]=l}}else if(e==="-d"||e==="--data"||e==="--data-raw")t.data=s[++r]??"",a=!0;else if(e.startsWith("-d"))t.data=e.slice(2),a=!0;else if(e.startsWith("--data="))t.data=e.slice(7),a=!0;else if(e.startsWith("--data-raw="))t.data=e.slice(11),a=!0;else if(e==="--data-binary")t.data=s[++r]??"",t.dataBinary=!0,a=!0;else if(e.startsWith("--data-binary="))t.data=e.slice(14),t.dataBinary=!0,a=!0;else if(e==="--data-urlencode"){let i=s[++r]??"";t.data=(t.data?`${t.data}&`:"")+f(i),a=!0}else if(e.startsWith("--data-urlencode=")){let i=e.slice(17);t.data=(t.data?`${t.data}&`:"")+f(i),a=!0}else if(e==="-F"||e==="--form"){let i=s[++r]??"",o=c(i);o&&t.formFields.push(o),a=!0}else if(e.startsWith("--form=")){let i=e.slice(7),o=c(i);o&&t.formFields.push(o),a=!0}else if(e==="-u"||e==="--user")t.user=s[++r];else if(e.startsWith("-u"))t.user=e.slice(2);else if(e.startsWith("--user="))t.user=e.slice(7);else if(e==="-A"||e==="--user-agent")t.headers["User-Agent"]=s[++r]??"";else if(e.startsWith("-A"))t.headers["User-Agent"]=e.slice(2);else if(e.startsWith("--user-agent="))t.headers["User-Agent"]=e.slice(13);else if(e==="-e"||e==="--referer")t.headers.Referer=s[++r]??"";else if(e.startsWith("-e"))t.headers.Referer=e.slice(2);else if(e.startsWith("--referer="))t.headers.Referer=e.slice(10);else if(e==="-b"||e==="--cookie")t.headers.Cookie=s[++r]??"";else if(e.startsWith("-b"))t.headers.Cookie=e.slice(2);else if(e.startsWith("--cookie="))t.headers.Cookie=e.slice(9);else if(e==="-c"||e==="--cookie-jar")t.cookieJar=s[++r];else if(e.startsWith("--cookie-jar="))t.cookieJar=e.slice(13);else if(e==="-T"||e==="--upload-file")t.uploadFile=s[++r],t.method==="GET"&&(t.method="PUT");else if(e.startsWith("--upload-file="))t.uploadFile=e.slice(14),t.method==="GET"&&(t.method="PUT");else if(e==="-m"||e==="--max-time"){let i=parseFloat(s[++r]??"0");!Number.isNaN(i)&&i>0&&(t.timeoutMs=i*1e3)}else if(e.startsWith("--max-time=")){let i=parseFloat(e.slice(11));!Number.isNaN(i)&&i>0&&(t.timeoutMs=i*1e3)}else if(e==="--connect-timeout"){let i=parseFloat(s[++r]??"0");!Number.isNaN(i)&&i>0&&t.timeoutMs===void 0&&(t.timeoutMs=i*1e3)}else if(e.startsWith("--connect-timeout=")){let i=parseFloat(e.slice(18));!Number.isNaN(i)&&i>0&&t.timeoutMs===void 0&&(t.timeoutMs=i*1e3)}else if(e==="-o"||e==="--output")t.outputFile=s[++r];else if(e.startsWith("--output="))t.outputFile=e.slice(9);else if(e==="-O"||e==="--remote-name")t.useRemoteName=!0;else if(e==="-I"||e==="--head")t.headOnly=!0,t.method="HEAD";else if(e==="-i"||e==="--include")t.includeHeaders=!0;else if(e==="-s"||e==="--silent")t.silent=!0;else if(e==="-S"||e==="--show-error")t.showError=!0;else if(e==="-f"||e==="--fail")t.failSilently=!0;else if(e==="-L"||e==="--location")t.followRedirects=!0;else if(e==="--max-redirs")r++;else if(!e.startsWith("--max-redirs="))if(e==="-w"||e==="--write-out")t.writeOut=s[++r];else if(e.startsWith("--write-out="))t.writeOut=e.slice(12);else if(e==="-v"||e==="--verbose")t.verbose=!0;else{if(e.startsWith("--")&&e!=="--")return d("curl",e);if(e.startsWith("-")&&e!=="-")for(let i of e.slice(1))switch(i){case"s":t.silent=!0;break;case"S":t.showError=!0;break;case"f":t.failSilently=!0;break;case"L":t.followRedirects=!0;break;case"I":t.headOnly=!0,t.method="HEAD";break;case"i":t.includeHeaders=!0;break;case"O":t.useRemoteName=!0;break;case"v":t.verbose=!0;break;default:return d("curl",`-${i}`)}else e.startsWith("-")||(t.url=e)}}return a&&t.method==="GET"&&(t.method="POST"),t}function m(s){return Object.entries(s).map(([t,a])=>`${t}: ${a}`).join(`\r
|
|
10
|
-
`)}function W(s){try{return new URL(s).pathname.split("/").pop()||"index.html"}catch{return"index.html"}}function h(s,t){let a=s;return a=a.replace(/%\{http_code\}/g,String(t.status)),a=a.replace(/%\{content_type\}/g,t.headers["content-type"]||""),a=a.replace(/%\{url_effective\}/g,t.url),a=a.replace(/%\{size_download\}/g,String(t.bodyLength)),a=a.replace(/\\n/g,`
|
|
11
|
-
`),a}async function P(s,t){if(s.uploadFile){let a=t.fs.resolvePath(t.cwd,s.uploadFile);return{body:await t.fs.readFile(a)}}if(s.formFields.length>0){let a=new Map;for(let i of s.formFields)if(i.value.startsWith("@")||i.value.startsWith("<")){let o=t.fs.resolvePath(t.cwd,i.value.slice(1));try{let n=await t.fs.readFile(o);a.set(i.value.slice(1),n)}catch{a.set(i.value.slice(1),"")}}let{body:r,boundary:e}=O(s.formFields,a);return{body:r,contentType:`multipart/form-data; boundary=${e}`}}return s.data!==void 0?{body:s.data}:{}}function S(s,t){let a=w(s.headers??{});if(s.user){let r=Buffer.from(s.user).toString("base64");a.Authorization=`Basic ${r}`}return t&&!a["Content-Type"]&&(a["Content-Type"]=t),a}async function E(s,t,a){if(!s.cookieJar)return;let r=t["set-cookie"];if(!r)return;let e=a.fs.resolvePath(a.cwd,s.cookieJar);await a.fs.writeFile(e,r)}function k(s,t,a){let r="";if(s.verbose){r+=`> ${s.method} ${a}
|
|
12
|
-
`;for(let[e,i]of Object.entries(s.headers))r+=`> ${e}: ${i}
|
|
13
|
-
`;r+=`>
|
|
14
|
-
`,r+=`< HTTP/1.1 ${t.status} ${t.statusText}
|
|
15
|
-
`;for(let[e,i]of Object.entries(t.headers))r+=`< ${e}: ${i}
|
|
16
|
-
`;r+=`<
|
|
17
|
-
`}return s.includeHeaders&&!s.verbose&&(r+=`HTTP/1.1 ${t.status} ${t.statusText}\r
|
|
18
|
-
`,r+=m(t.headers),r+=`\r
|
|
19
|
-
\r
|
|
20
|
-
`),s.headOnly?s.includeHeaders||s.verbose||(r+=`HTTP/1.1 ${t.status} ${t.statusText}\r
|
|
21
|
-
`,r+=m(t.headers),r+=`\r
|
|
22
|
-
`):r+=t.body,s.writeOut&&(r+=h(s.writeOut,{status:t.status,headers:t.headers,url:t.url,bodyLength:t.body.length})),r}var B={name:"curl",async execute(s,t){if(T(s))return y(v);let a=F(s);if("exitCode"in a)return a;let r=a;if(!r.url)return{stdout:"",stderr:`curl: no URL specified
|
|
23
|
-
`,exitCode:2};if(!t.fetch)return{stdout:"",stderr:`curl: internal error: fetch not available
|
|
24
|
-
`,exitCode:1};let e=r.url;e.match(/^https?:\/\//)||(e=`https://${e}`);try{let{body:i,contentType:o}=await P(r,t),n=S(r,o),l=await t.fetch(e,{method:r.method,headers:Object.keys(n).length>0?n:void 0,body:i,followRedirects:r.followRedirects,timeoutMs:r.timeoutMs});if(await E(r,l.headers,t),r.failSilently&&l.status>=400)return{stdout:"",stderr:r.showError||!r.silent?`curl: (22) The requested URL returned error: ${l.status}
|
|
25
|
-
`:"",exitCode:22};let u=k(r,l,e);if(r.outputFile||r.useRemoteName){let p=r.outputFile||W(e),$=t.fs.resolvePath(t.cwd,p);await t.fs.writeFile($,r.headOnly?"":l.body),r.verbose||(u=""),r.writeOut&&(u=h(r.writeOut,{status:l.status,headers:l.headers,url:l.url,bodyLength:l.body.length}))}return{stdout:u,stderr:"",exitCode:0}}catch(i){let o=b(i),n=1;return o.includes("Network access denied")?n=7:o.includes("HTTP method")&&o.includes("not allowed")?n=3:o.includes("Redirect target not in allow-list")||o.includes("Too many redirects")?n=47:o.includes("aborted")&&(n=28),{stdout:"",stderr:!r.silent||r.showError?`curl: (${n}) ${o}
|
|
26
|
-
`:"",exitCode:n}}}};export{B as curlCommand};
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import{g as w}from"./chunk-V7ZOPVQS.js";import{a as b}from"./chunk-4VDEBYW7.js";import{a as y,b as T,c as d}from"./chunk-GTNBSMZR.js";import"./chunk-KGOUQS5A.js";function f(s){let t=s.indexOf("=");if(t>=0){let a=s.slice(0,t),r=s.slice(t+1);return a?`${encodeURIComponent(a)}=${encodeURIComponent(r)}`:encodeURIComponent(r)}return encodeURIComponent(s)}function c(s){let t=s.indexOf("=");if(t<0)return null;let a=s.slice(0,t),r=s.slice(t+1),e,i,o=r.match(/;type=([^;]+)$/);o&&(i=o[1],r=r.slice(0,-o[0].length));let n=r.match(/;filename=([^;]+)/);return n&&(e=n[1],r=r.replace(n[0],"")),(r.startsWith("@")||r.startsWith("<"))&&(e=e??r.slice(1).split("/").pop()),{name:a,value:r,filename:e,contentType:i}}function O(s,t){let a=`----CurlFormBoundary${Date.now().toString(36)}`,r=[];for(let e of s){let i=e.value;if(i.startsWith("@")||i.startsWith("<")){let n=i.slice(1);i=t.get(n)??""}let o=`--${a}\r
|
|
3
|
-
`;e.filename?(o+=`Content-Disposition: form-data; name="${e.name}"; filename="${e.filename}"\r
|
|
4
|
-
`,e.contentType&&(o+=`Content-Type: ${e.contentType}\r
|
|
5
|
-
`)):o+=`Content-Disposition: form-data; name="${e.name}"\r
|
|
6
|
-
`,o+=`\r
|
|
7
|
-
${i}\r
|
|
8
|
-
`,r.push(o)}return r.push(`--${a}--\r
|
|
9
|
-
`),{body:r.join(""),boundary:a}}var v={name:"curl",summary:"transfer a URL",usage:"curl [OPTIONS] URL",options:["-X, --request METHOD HTTP method (GET, POST, PUT, DELETE, etc.)","-H, --header HEADER Add header (can be used multiple times)","-d, --data DATA HTTP POST data"," --data-raw DATA HTTP POST data (no @ interpretation)"," --data-binary DATA HTTP POST binary data"," --data-urlencode DATA URL-encode and POST data","-F, --form NAME=VALUE Multipart form data","-u, --user USER:PASS HTTP authentication","-A, --user-agent STR Set User-Agent header","-e, --referer URL Set Referer header","-b, --cookie DATA Send cookies (name=value or @file)","-c, --cookie-jar FILE Save cookies to file","-T, --upload-file FILE Upload file (PUT)","-o, --output FILE Write output to file","-O, --remote-name Write to file named from URL","-I, --head Show headers only (HEAD request)","-i, --include Include response headers in output","-s, --silent Silent mode (no progress)","-S, --show-error Show errors even when silent","-f, --fail Fail silently on HTTP errors (no output)","-L, --location Follow redirects (default)"," --max-redirs NUM Maximum redirects (default: 20)","-m, --max-time SECS Maximum time for request"," --connect-timeout SECS Connection timeout","-w, --write-out FMT Output format after completion","-v, --verbose Verbose output"," --help Display this help and exit","","Note: Network access must be configured via BashEnv network option."," curl is not available by default for security reasons."]};function F(s){let t={method:"GET",headers:Object.create(null),dataBinary:!1,formFields:[],useRemoteName:!1,headOnly:!1,includeHeaders:!1,silent:!1,showError:!1,failSilently:!1,followRedirects:!0,verbose:!1},a=!1;for(let r=0;r<s.length;r++){let e=s[r];if(e==="-X"||e==="--request")t.method=s[++r]??"GET";else if(e.startsWith("-X"))t.method=e.slice(2);else if(e.startsWith("--request="))t.method=e.slice(10);else if(e==="-H"||e==="--header"){let i=s[++r];if(i){let o=i.indexOf(":");if(o>0){let n=i.slice(0,o).trim(),l=i.slice(o+1).trim();t.headers[n]=l}}}else if(e.startsWith("--header=")){let i=e.slice(9),o=i.indexOf(":");if(o>0){let n=i.slice(0,o).trim(),l=i.slice(o+1).trim();t.headers[n]=l}}else if(e==="-d"||e==="--data"||e==="--data-raw")t.data=s[++r]??"",a=!0;else if(e.startsWith("-d"))t.data=e.slice(2),a=!0;else if(e.startsWith("--data="))t.data=e.slice(7),a=!0;else if(e.startsWith("--data-raw="))t.data=e.slice(11),a=!0;else if(e==="--data-binary")t.data=s[++r]??"",t.dataBinary=!0,a=!0;else if(e.startsWith("--data-binary="))t.data=e.slice(14),t.dataBinary=!0,a=!0;else if(e==="--data-urlencode"){let i=s[++r]??"";t.data=(t.data?`${t.data}&`:"")+f(i),a=!0}else if(e.startsWith("--data-urlencode=")){let i=e.slice(17);t.data=(t.data?`${t.data}&`:"")+f(i),a=!0}else if(e==="-F"||e==="--form"){let i=s[++r]??"",o=c(i);o&&t.formFields.push(o),a=!0}else if(e.startsWith("--form=")){let i=e.slice(7),o=c(i);o&&t.formFields.push(o),a=!0}else if(e==="-u"||e==="--user")t.user=s[++r];else if(e.startsWith("-u"))t.user=e.slice(2);else if(e.startsWith("--user="))t.user=e.slice(7);else if(e==="-A"||e==="--user-agent")t.headers["User-Agent"]=s[++r]??"";else if(e.startsWith("-A"))t.headers["User-Agent"]=e.slice(2);else if(e.startsWith("--user-agent="))t.headers["User-Agent"]=e.slice(13);else if(e==="-e"||e==="--referer")t.headers.Referer=s[++r]??"";else if(e.startsWith("-e"))t.headers.Referer=e.slice(2);else if(e.startsWith("--referer="))t.headers.Referer=e.slice(10);else if(e==="-b"||e==="--cookie")t.headers.Cookie=s[++r]??"";else if(e.startsWith("-b"))t.headers.Cookie=e.slice(2);else if(e.startsWith("--cookie="))t.headers.Cookie=e.slice(9);else if(e==="-c"||e==="--cookie-jar")t.cookieJar=s[++r];else if(e.startsWith("--cookie-jar="))t.cookieJar=e.slice(13);else if(e==="-T"||e==="--upload-file")t.uploadFile=s[++r],t.method==="GET"&&(t.method="PUT");else if(e.startsWith("--upload-file="))t.uploadFile=e.slice(14),t.method==="GET"&&(t.method="PUT");else if(e==="-m"||e==="--max-time"){let i=parseFloat(s[++r]??"0");!Number.isNaN(i)&&i>0&&(t.timeoutMs=i*1e3)}else if(e.startsWith("--max-time=")){let i=parseFloat(e.slice(11));!Number.isNaN(i)&&i>0&&(t.timeoutMs=i*1e3)}else if(e==="--connect-timeout"){let i=parseFloat(s[++r]??"0");!Number.isNaN(i)&&i>0&&t.timeoutMs===void 0&&(t.timeoutMs=i*1e3)}else if(e.startsWith("--connect-timeout=")){let i=parseFloat(e.slice(18));!Number.isNaN(i)&&i>0&&t.timeoutMs===void 0&&(t.timeoutMs=i*1e3)}else if(e==="-o"||e==="--output")t.outputFile=s[++r];else if(e.startsWith("--output="))t.outputFile=e.slice(9);else if(e==="-O"||e==="--remote-name")t.useRemoteName=!0;else if(e==="-I"||e==="--head")t.headOnly=!0,t.method="HEAD";else if(e==="-i"||e==="--include")t.includeHeaders=!0;else if(e==="-s"||e==="--silent")t.silent=!0;else if(e==="-S"||e==="--show-error")t.showError=!0;else if(e==="-f"||e==="--fail")t.failSilently=!0;else if(e==="-L"||e==="--location")t.followRedirects=!0;else if(e==="--max-redirs")r++;else if(!e.startsWith("--max-redirs="))if(e==="-w"||e==="--write-out")t.writeOut=s[++r];else if(e.startsWith("--write-out="))t.writeOut=e.slice(12);else if(e==="-v"||e==="--verbose")t.verbose=!0;else{if(e.startsWith("--")&&e!=="--")return d("curl",e);if(e.startsWith("-")&&e!=="-")for(let i of e.slice(1))switch(i){case"s":t.silent=!0;break;case"S":t.showError=!0;break;case"f":t.failSilently=!0;break;case"L":t.followRedirects=!0;break;case"I":t.headOnly=!0,t.method="HEAD";break;case"i":t.includeHeaders=!0;break;case"O":t.useRemoteName=!0;break;case"v":t.verbose=!0;break;default:return d("curl",`-${i}`)}else e.startsWith("-")||(t.url=e)}}return a&&t.method==="GET"&&(t.method="POST"),t}function m(s){return Object.entries(s).map(([t,a])=>`${t}: ${a}`).join(`\r
|
|
10
|
-
`)}function W(s){try{return new URL(s).pathname.split("/").pop()||"index.html"}catch{return"index.html"}}function h(s,t){let a=s;return a=a.replace(/%\{http_code\}/g,String(t.status)),a=a.replace(/%\{content_type\}/g,t.headers["content-type"]||""),a=a.replace(/%\{url_effective\}/g,t.url),a=a.replace(/%\{size_download\}/g,String(t.bodyLength)),a=a.replace(/\\n/g,`
|
|
11
|
-
`),a}async function P(s,t){if(s.uploadFile){let a=t.fs.resolvePath(t.cwd,s.uploadFile);return{body:await t.fs.readFile(a)}}if(s.formFields.length>0){let a=new Map;for(let i of s.formFields)if(i.value.startsWith("@")||i.value.startsWith("<")){let o=t.fs.resolvePath(t.cwd,i.value.slice(1));try{let n=await t.fs.readFile(o);a.set(i.value.slice(1),n)}catch{a.set(i.value.slice(1),"")}}let{body:r,boundary:e}=O(s.formFields,a);return{body:r,contentType:`multipart/form-data; boundary=${e}`}}return s.data!==void 0?{body:s.data}:{}}function S(s,t){let a=w(s.headers??{});if(s.user){let r=Buffer.from(s.user).toString("base64");a.Authorization=`Basic ${r}`}return t&&!a["Content-Type"]&&(a["Content-Type"]=t),a}async function E(s,t,a){if(!s.cookieJar)return;let r=t["set-cookie"];if(!r)return;let e=a.fs.resolvePath(a.cwd,s.cookieJar);await a.fs.writeFile(e,r)}function k(s,t,a){let r="";if(s.verbose){r+=`> ${s.method} ${a}
|
|
12
|
-
`;for(let[e,i]of Object.entries(s.headers))r+=`> ${e}: ${i}
|
|
13
|
-
`;r+=`>
|
|
14
|
-
`,r+=`< HTTP/1.1 ${t.status} ${t.statusText}
|
|
15
|
-
`;for(let[e,i]of Object.entries(t.headers))r+=`< ${e}: ${i}
|
|
16
|
-
`;r+=`<
|
|
17
|
-
`}return s.includeHeaders&&!s.verbose&&(r+=`HTTP/1.1 ${t.status} ${t.statusText}\r
|
|
18
|
-
`,r+=m(t.headers),r+=`\r
|
|
19
|
-
\r
|
|
20
|
-
`),s.headOnly?s.includeHeaders||s.verbose||(r+=`HTTP/1.1 ${t.status} ${t.statusText}\r
|
|
21
|
-
`,r+=m(t.headers),r+=`\r
|
|
22
|
-
`):r+=t.body,s.writeOut&&(r+=h(s.writeOut,{status:t.status,headers:t.headers,url:t.url,bodyLength:t.body.length})),r}var B={name:"curl",async execute(s,t){if(T(s))return y(v);let a=F(s);if("exitCode"in a)return a;let r=a;if(!r.url)return{stdout:"",stderr:`curl: no URL specified
|
|
23
|
-
`,exitCode:2};if(!t.fetch)return{stdout:"",stderr:`curl: internal error: fetch not available
|
|
24
|
-
`,exitCode:1};let e=r.url;e.match(/^https?:\/\//)||(e=`https://${e}`);try{let{body:i,contentType:o}=await P(r,t),n=S(r,o),l=await t.fetch(e,{method:r.method,headers:Object.keys(n).length>0?n:void 0,body:i,followRedirects:r.followRedirects,timeoutMs:r.timeoutMs});if(await E(r,l.headers,t),r.failSilently&&l.status>=400)return{stdout:"",stderr:r.showError||!r.silent?`curl: (22) The requested URL returned error: ${l.status}
|
|
25
|
-
`:"",exitCode:22};let u=k(r,l,e);if(r.outputFile||r.useRemoteName){let p=r.outputFile||W(e),$=t.fs.resolvePath(t.cwd,p);await t.fs.writeFile($,r.headOnly?"":l.body),r.verbose||(u=""),r.writeOut&&(u=h(r.writeOut,{status:l.status,headers:l.headers,url:l.url,bodyLength:l.body.length}))}return{stdout:u,stderr:"",exitCode:0}}catch(i){let o=b(i),n=1;return o.includes("Network access denied")?n=7:o.includes("HTTP method")&&o.includes("not allowed")?n=3:o.includes("Redirect target not in allow-list")||o.includes("Too many redirects")?n=47:o.includes("aborted")&&(n=28),{stdout:"",stderr:!r.silent||r.showError?`curl: (${n}) ${o}
|
|
26
|
-
`:"",exitCode:n}}}};export{B as curlCommand};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
var r=globalThis.SharedArrayBuffer,o=globalThis.Atomics,e=performance.now.bind(performance);export{r as a,o as b,e as c};
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import{g as w}from"./chunk-7TSDKFEO.js";import{a as b}from"./chunk-44UOCSGV.js";import{a as y,b as T,c as d}from"./chunk-74CEPOFO.js";import"./chunk-DXB73IDG.js";function f(s){let t=s.indexOf("=");if(t>=0){let a=s.slice(0,t),r=s.slice(t+1);return a?`${encodeURIComponent(a)}=${encodeURIComponent(r)}`:encodeURIComponent(r)}return encodeURIComponent(s)}function c(s){let t=s.indexOf("=");if(t<0)return null;let a=s.slice(0,t),r=s.slice(t+1),e,i,o=r.match(/;type=([^;]+)$/);o&&(i=o[1],r=r.slice(0,-o[0].length));let n=r.match(/;filename=([^;]+)/);return n&&(e=n[1],r=r.replace(n[0],"")),(r.startsWith("@")||r.startsWith("<"))&&(e=e??r.slice(1).split("/").pop()),{name:a,value:r,filename:e,contentType:i}}function O(s,t){let a=`----CurlFormBoundary${Date.now().toString(36)}`,r=[];for(let e of s){let i=e.value;if(i.startsWith("@")||i.startsWith("<")){let n=i.slice(1);i=t.get(n)??""}let o=`--${a}\r
|
|
2
|
-
`;e.filename?(o+=`Content-Disposition: form-data; name="${e.name}"; filename="${e.filename}"\r
|
|
3
|
-
`,e.contentType&&(o+=`Content-Type: ${e.contentType}\r
|
|
4
|
-
`)):o+=`Content-Disposition: form-data; name="${e.name}"\r
|
|
5
|
-
`,o+=`\r
|
|
6
|
-
${i}\r
|
|
7
|
-
`,r.push(o)}return r.push(`--${a}--\r
|
|
8
|
-
`),{body:r.join(""),boundary:a}}var v={name:"curl",summary:"transfer a URL",usage:"curl [OPTIONS] URL",options:["-X, --request METHOD HTTP method (GET, POST, PUT, DELETE, etc.)","-H, --header HEADER Add header (can be used multiple times)","-d, --data DATA HTTP POST data"," --data-raw DATA HTTP POST data (no @ interpretation)"," --data-binary DATA HTTP POST binary data"," --data-urlencode DATA URL-encode and POST data","-F, --form NAME=VALUE Multipart form data","-u, --user USER:PASS HTTP authentication","-A, --user-agent STR Set User-Agent header","-e, --referer URL Set Referer header","-b, --cookie DATA Send cookies (name=value or @file)","-c, --cookie-jar FILE Save cookies to file","-T, --upload-file FILE Upload file (PUT)","-o, --output FILE Write output to file","-O, --remote-name Write to file named from URL","-I, --head Show headers only (HEAD request)","-i, --include Include response headers in output","-s, --silent Silent mode (no progress)","-S, --show-error Show errors even when silent","-f, --fail Fail silently on HTTP errors (no output)","-L, --location Follow redirects (default)"," --max-redirs NUM Maximum redirects (default: 20)","-m, --max-time SECS Maximum time for request"," --connect-timeout SECS Connection timeout","-w, --write-out FMT Output format after completion","-v, --verbose Verbose output"," --help Display this help and exit","","Note: Network access must be configured via BashEnv network option."," curl is not available by default for security reasons."]};function F(s){let t={method:"GET",headers:Object.create(null),dataBinary:!1,formFields:[],useRemoteName:!1,headOnly:!1,includeHeaders:!1,silent:!1,showError:!1,failSilently:!1,followRedirects:!0,verbose:!1},a=!1;for(let r=0;r<s.length;r++){let e=s[r];if(e==="-X"||e==="--request")t.method=s[++r]??"GET";else if(e.startsWith("-X"))t.method=e.slice(2);else if(e.startsWith("--request="))t.method=e.slice(10);else if(e==="-H"||e==="--header"){let i=s[++r];if(i){let o=i.indexOf(":");if(o>0){let n=i.slice(0,o).trim(),l=i.slice(o+1).trim();t.headers[n]=l}}}else if(e.startsWith("--header=")){let i=e.slice(9),o=i.indexOf(":");if(o>0){let n=i.slice(0,o).trim(),l=i.slice(o+1).trim();t.headers[n]=l}}else if(e==="-d"||e==="--data"||e==="--data-raw")t.data=s[++r]??"",a=!0;else if(e.startsWith("-d"))t.data=e.slice(2),a=!0;else if(e.startsWith("--data="))t.data=e.slice(7),a=!0;else if(e.startsWith("--data-raw="))t.data=e.slice(11),a=!0;else if(e==="--data-binary")t.data=s[++r]??"",t.dataBinary=!0,a=!0;else if(e.startsWith("--data-binary="))t.data=e.slice(14),t.dataBinary=!0,a=!0;else if(e==="--data-urlencode"){let i=s[++r]??"";t.data=(t.data?`${t.data}&`:"")+f(i),a=!0}else if(e.startsWith("--data-urlencode=")){let i=e.slice(17);t.data=(t.data?`${t.data}&`:"")+f(i),a=!0}else if(e==="-F"||e==="--form"){let i=s[++r]??"",o=c(i);o&&t.formFields.push(o),a=!0}else if(e.startsWith("--form=")){let i=e.slice(7),o=c(i);o&&t.formFields.push(o),a=!0}else if(e==="-u"||e==="--user")t.user=s[++r];else if(e.startsWith("-u"))t.user=e.slice(2);else if(e.startsWith("--user="))t.user=e.slice(7);else if(e==="-A"||e==="--user-agent")t.headers["User-Agent"]=s[++r]??"";else if(e.startsWith("-A"))t.headers["User-Agent"]=e.slice(2);else if(e.startsWith("--user-agent="))t.headers["User-Agent"]=e.slice(13);else if(e==="-e"||e==="--referer")t.headers.Referer=s[++r]??"";else if(e.startsWith("-e"))t.headers.Referer=e.slice(2);else if(e.startsWith("--referer="))t.headers.Referer=e.slice(10);else if(e==="-b"||e==="--cookie")t.headers.Cookie=s[++r]??"";else if(e.startsWith("-b"))t.headers.Cookie=e.slice(2);else if(e.startsWith("--cookie="))t.headers.Cookie=e.slice(9);else if(e==="-c"||e==="--cookie-jar")t.cookieJar=s[++r];else if(e.startsWith("--cookie-jar="))t.cookieJar=e.slice(13);else if(e==="-T"||e==="--upload-file")t.uploadFile=s[++r],t.method==="GET"&&(t.method="PUT");else if(e.startsWith("--upload-file="))t.uploadFile=e.slice(14),t.method==="GET"&&(t.method="PUT");else if(e==="-m"||e==="--max-time"){let i=parseFloat(s[++r]??"0");!Number.isNaN(i)&&i>0&&(t.timeoutMs=i*1e3)}else if(e.startsWith("--max-time=")){let i=parseFloat(e.slice(11));!Number.isNaN(i)&&i>0&&(t.timeoutMs=i*1e3)}else if(e==="--connect-timeout"){let i=parseFloat(s[++r]??"0");!Number.isNaN(i)&&i>0&&t.timeoutMs===void 0&&(t.timeoutMs=i*1e3)}else if(e.startsWith("--connect-timeout=")){let i=parseFloat(e.slice(18));!Number.isNaN(i)&&i>0&&t.timeoutMs===void 0&&(t.timeoutMs=i*1e3)}else if(e==="-o"||e==="--output")t.outputFile=s[++r];else if(e.startsWith("--output="))t.outputFile=e.slice(9);else if(e==="-O"||e==="--remote-name")t.useRemoteName=!0;else if(e==="-I"||e==="--head")t.headOnly=!0,t.method="HEAD";else if(e==="-i"||e==="--include")t.includeHeaders=!0;else if(e==="-s"||e==="--silent")t.silent=!0;else if(e==="-S"||e==="--show-error")t.showError=!0;else if(e==="-f"||e==="--fail")t.failSilently=!0;else if(e==="-L"||e==="--location")t.followRedirects=!0;else if(e==="--max-redirs")r++;else if(!e.startsWith("--max-redirs="))if(e==="-w"||e==="--write-out")t.writeOut=s[++r];else if(e.startsWith("--write-out="))t.writeOut=e.slice(12);else if(e==="-v"||e==="--verbose")t.verbose=!0;else{if(e.startsWith("--")&&e!=="--")return d("curl",e);if(e.startsWith("-")&&e!=="-")for(let i of e.slice(1))switch(i){case"s":t.silent=!0;break;case"S":t.showError=!0;break;case"f":t.failSilently=!0;break;case"L":t.followRedirects=!0;break;case"I":t.headOnly=!0,t.method="HEAD";break;case"i":t.includeHeaders=!0;break;case"O":t.useRemoteName=!0;break;case"v":t.verbose=!0;break;default:return d("curl",`-${i}`)}else e.startsWith("-")||(t.url=e)}}return a&&t.method==="GET"&&(t.method="POST"),t}function m(s){return Object.entries(s).map(([t,a])=>`${t}: ${a}`).join(`\r
|
|
9
|
-
`)}function W(s){try{return new URL(s).pathname.split("/").pop()||"index.html"}catch{return"index.html"}}function h(s,t){let a=s;return a=a.replace(/%\{http_code\}/g,String(t.status)),a=a.replace(/%\{content_type\}/g,t.headers["content-type"]||""),a=a.replace(/%\{url_effective\}/g,t.url),a=a.replace(/%\{size_download\}/g,String(t.bodyLength)),a=a.replace(/\\n/g,`
|
|
10
|
-
`),a}async function P(s,t){if(s.uploadFile){let a=t.fs.resolvePath(t.cwd,s.uploadFile);return{body:await t.fs.readFile(a)}}if(s.formFields.length>0){let a=new Map;for(let i of s.formFields)if(i.value.startsWith("@")||i.value.startsWith("<")){let o=t.fs.resolvePath(t.cwd,i.value.slice(1));try{let n=await t.fs.readFile(o);a.set(i.value.slice(1),n)}catch{a.set(i.value.slice(1),"")}}let{body:r,boundary:e}=O(s.formFields,a);return{body:r,contentType:`multipart/form-data; boundary=${e}`}}return s.data!==void 0?{body:s.data}:{}}function S(s,t){let a=w(s.headers??{});if(s.user){let r=Buffer.from(s.user).toString("base64");a.Authorization=`Basic ${r}`}return t&&!a["Content-Type"]&&(a["Content-Type"]=t),a}async function E(s,t,a){if(!s.cookieJar)return;let r=t["set-cookie"];if(!r)return;let e=a.fs.resolvePath(a.cwd,s.cookieJar);await a.fs.writeFile(e,r)}function k(s,t,a){let r="";if(s.verbose){r+=`> ${s.method} ${a}
|
|
11
|
-
`;for(let[e,i]of Object.entries(s.headers))r+=`> ${e}: ${i}
|
|
12
|
-
`;r+=`>
|
|
13
|
-
`,r+=`< HTTP/1.1 ${t.status} ${t.statusText}
|
|
14
|
-
`;for(let[e,i]of Object.entries(t.headers))r+=`< ${e}: ${i}
|
|
15
|
-
`;r+=`<
|
|
16
|
-
`}return s.includeHeaders&&!s.verbose&&(r+=`HTTP/1.1 ${t.status} ${t.statusText}\r
|
|
17
|
-
`,r+=m(t.headers),r+=`\r
|
|
18
|
-
\r
|
|
19
|
-
`),s.headOnly?s.includeHeaders||s.verbose||(r+=`HTTP/1.1 ${t.status} ${t.statusText}\r
|
|
20
|
-
`,r+=m(t.headers),r+=`\r
|
|
21
|
-
`):r+=t.body,s.writeOut&&(r+=h(s.writeOut,{status:t.status,headers:t.headers,url:t.url,bodyLength:t.body.length})),r}var B={name:"curl",async execute(s,t){if(T(s))return y(v);let a=F(s);if("exitCode"in a)return a;let r=a;if(!r.url)return{stdout:"",stderr:`curl: no URL specified
|
|
22
|
-
`,exitCode:2};if(!t.fetch)return{stdout:"",stderr:`curl: internal error: fetch not available
|
|
23
|
-
`,exitCode:1};let e=r.url;e.match(/^https?:\/\//)||(e=`https://${e}`);try{let{body:i,contentType:o}=await P(r,t),n=S(r,o),l=await t.fetch(e,{method:r.method,headers:Object.keys(n).length>0?n:void 0,body:i,followRedirects:r.followRedirects,timeoutMs:r.timeoutMs});if(await E(r,l.headers,t),r.failSilently&&l.status>=400)return{stdout:"",stderr:r.showError||!r.silent?`curl: (22) The requested URL returned error: ${l.status}
|
|
24
|
-
`:"",exitCode:22};let u=k(r,l,e);if(r.outputFile||r.useRemoteName){let p=r.outputFile||W(e),$=t.fs.resolvePath(t.cwd,p);await t.fs.writeFile($,r.headOnly?"":l.body),r.verbose||(u=""),r.writeOut&&(u=h(r.writeOut,{status:l.status,headers:l.headers,url:l.url,bodyLength:l.body.length}))}return{stdout:u,stderr:"",exitCode:0}}catch(i){let o=b(i),n=1;return o.includes("Network access denied")?n=7:o.includes("HTTP method")&&o.includes("not allowed")?n=3:o.includes("Redirect target not in allow-list")||o.includes("Too many redirects")?n=47:o.includes("aborted")&&(n=28),{stdout:"",stderr:!r.silent||r.showError?`curl: (${n}) ${o}
|
|
25
|
-
`:"",exitCode:n}}}};export{B as curlCommand};
|