@scalar/snippetz 0.7.4 → 0.7.6
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/dist/clients/index.js +168 -169
- package/dist/httpsnippet-lite/helpers/code-builder.js +86 -74
- package/dist/httpsnippet-lite/helpers/escape.js +69 -44
- package/dist/httpsnippet-lite/helpers/headers.js +17 -14
- package/dist/httpsnippet-lite/helpers/reducer.js +1 -1
- package/dist/httpsnippet-lite/helpers/shell.js +13 -13
- package/dist/httpsnippet-lite/helpers/snippet-request.js +1 -1
- package/dist/httpsnippet-lite/helpers/url.js +4 -8
- package/dist/httpsnippet-lite/targets/c/libcurl/client.js +69 -67
- package/dist/httpsnippet-lite/targets/clojure/clj_http/client.js +165 -154
- package/dist/httpsnippet-lite/targets/csharp/restsharp/client.js +35 -38
- package/dist/httpsnippet-lite/targets/go/native/client.js +151 -147
- package/dist/httpsnippet-lite/targets/java/asynchttp/client.js +32 -35
- package/dist/httpsnippet-lite/targets/java/nethttp/client.js +40 -39
- package/dist/httpsnippet-lite/targets/java/okhttp/client.js +83 -73
- package/dist/httpsnippet-lite/targets/java/unirest/client.js +41 -34
- package/dist/httpsnippet-lite/targets/javascript/axios/client.js +81 -76
- package/dist/httpsnippet-lite/targets/javascript/jquery/client.js +77 -71
- package/dist/httpsnippet-lite/targets/javascript/xhr/client.js +73 -71
- package/dist/httpsnippet-lite/targets/kotlin/okhttp/client.js +83 -73
- package/dist/httpsnippet-lite/targets/node/axios/client.js +74 -69
- package/dist/httpsnippet-lite/targets/objc/helpers.js +52 -33
- package/dist/httpsnippet-lite/targets/objc/nsurlsession/client.js +123 -121
- package/dist/httpsnippet-lite/targets/ocaml/cohttp/client.js +60 -49
- package/dist/httpsnippet-lite/targets/powershell/common.js +46 -56
- package/dist/httpsnippet-lite/targets/powershell/restmethod/client.js +9 -13
- package/dist/httpsnippet-lite/targets/powershell/webrequest/client.js +9 -13
- package/dist/httpsnippet-lite/targets/python/python3/client.js +85 -68
- package/dist/httpsnippet-lite/targets/r/httr/client.js +114 -95
- package/dist/httpsnippet-lite/targets/ruby/native/client.js +66 -70
- package/dist/httpsnippet-lite/targets/shell/httpie/client.js +121 -107
- package/dist/httpsnippet-lite/targets/shell/wget/client.js +48 -43
- package/dist/httpsnippet-lite/targets/swift/helpers.js +62 -44
- package/dist/httpsnippet-lite/targets/swift/nsurlsession/client.js +126 -112
- package/dist/httpsnippet-lite/targets/target.js +1 -1
- package/dist/index.js +2 -9
- package/dist/libs/http.js +68 -56
- package/dist/libs/javascript.js +77 -60
- package/dist/libs/php.js +59 -49
- package/dist/libs/rust.js +60 -33
- package/dist/libs/shell.js +14 -5
- package/dist/plugins/c/libcurl/index.js +1 -5
- package/dist/plugins/c/libcurl/libcurl.js +13 -13
- package/dist/plugins/clojure/clj_http/clj_http.js +13 -13
- package/dist/plugins/clojure/clj_http/index.js +1 -5
- package/dist/plugins/csharp/httpclient/httpclient.js +206 -150
- package/dist/plugins/csharp/httpclient/index.js +1 -5
- package/dist/plugins/csharp/restsharp/index.js +1 -5
- package/dist/plugins/csharp/restsharp/restsharp.js +13 -13
- package/dist/plugins/dart/http/http.js +95 -93
- package/dist/plugins/dart/http/index.js +1 -5
- package/dist/plugins/fsharp/httpclient/httpclient.js +169 -122
- package/dist/plugins/fsharp/httpclient/index.js +1 -5
- package/dist/plugins/go/native/index.js +1 -5
- package/dist/plugins/go/native/native.js +13 -13
- package/dist/plugins/http/http11/http11.d.ts.map +1 -1
- package/dist/plugins/http/http11/http11.js +104 -85
- package/dist/plugins/http/http11/index.js +1 -5
- package/dist/plugins/java/asynchttp/asynchttp.js +13 -13
- package/dist/plugins/java/asynchttp/index.js +1 -5
- package/dist/plugins/java/nethttp/index.js +1 -5
- package/dist/plugins/java/nethttp/nethttp.js +13 -13
- package/dist/plugins/java/okhttp/index.js +1 -5
- package/dist/plugins/java/okhttp/okhttp.js +13 -13
- package/dist/plugins/java/unirest/index.js +1 -5
- package/dist/plugins/java/unirest/unirest.js +13 -13
- package/dist/plugins/js/axios/axios.js +13 -13
- package/dist/plugins/js/axios/index.js +1 -5
- package/dist/plugins/js/fetch/fetch.js +82 -68
- package/dist/plugins/js/fetch/index.js +1 -5
- package/dist/plugins/js/jquery/index.js +1 -5
- package/dist/plugins/js/jquery/jquery.js +13 -13
- package/dist/plugins/js/ofetch/index.js +1 -5
- package/dist/plugins/js/ofetch/ofetch.js +61 -48
- package/dist/plugins/js/xhr/index.js +1 -5
- package/dist/plugins/js/xhr/xhr.js +13 -13
- package/dist/plugins/kotlin/okhttp/index.js +1 -5
- package/dist/plugins/kotlin/okhttp/okhttp.js +13 -13
- package/dist/plugins/node/axios/axios.js +13 -13
- package/dist/plugins/node/axios/index.js +1 -5
- package/dist/plugins/node/fetch/fetch.js +86 -74
- package/dist/plugins/node/fetch/index.js +1 -5
- package/dist/plugins/node/ofetch/index.js +1 -5
- package/dist/plugins/node/ofetch/ofetch.js +61 -48
- package/dist/plugins/node/undici/index.js +1 -5
- package/dist/plugins/node/undici/undici.js +60 -47
- package/dist/plugins/objc/nsurlsession/index.js +1 -5
- package/dist/plugins/objc/nsurlsession/nsurlsession.js +13 -13
- package/dist/plugins/ocaml/cohttp/cohttp.js +13 -13
- package/dist/plugins/ocaml/cohttp/index.js +1 -5
- package/dist/plugins/php/curl/curl.js +143 -101
- package/dist/plugins/php/curl/index.js +1 -5
- package/dist/plugins/php/guzzle/guzzle.d.ts.map +1 -1
- package/dist/plugins/php/guzzle/guzzle.js +109 -83
- package/dist/plugins/php/guzzle/index.js +1 -5
- package/dist/plugins/powershell/restmethod/index.js +1 -5
- package/dist/plugins/powershell/restmethod/restmethod.js +13 -13
- package/dist/plugins/powershell/webrequest/index.js +1 -5
- package/dist/plugins/powershell/webrequest/webrequest.js +13 -13
- package/dist/plugins/python/httpx/async.js +17 -15
- package/dist/plugins/python/httpx/index.js +2 -7
- package/dist/plugins/python/httpx/sync.js +11 -12
- package/dist/plugins/python/python3/index.js +1 -5
- package/dist/plugins/python/python3/python3.js +13 -13
- package/dist/plugins/python/requests/index.js +1 -5
- package/dist/plugins/python/requests/requests.js +11 -12
- package/dist/plugins/python/requestsLike.d.ts.map +1 -1
- package/dist/plugins/python/requestsLike.js +145 -112
- package/dist/plugins/r/httr/httr.js +13 -13
- package/dist/plugins/r/httr/index.js +1 -5
- package/dist/plugins/ruby/native/index.js +1 -5
- package/dist/plugins/ruby/native/native.js +13 -13
- package/dist/plugins/rust/reqwest/index.js +1 -5
- package/dist/plugins/rust/reqwest/reqwest.js +126 -83
- package/dist/plugins/shell/curl/curl.d.ts.map +1 -1
- package/dist/plugins/shell/curl/curl.js +129 -97
- package/dist/plugins/shell/curl/index.js +1 -5
- package/dist/plugins/shell/httpie/httpie.js +13 -13
- package/dist/plugins/shell/httpie/index.js +1 -5
- package/dist/plugins/shell/wget/index.js +1 -5
- package/dist/plugins/shell/wget/wget.js +13 -13
- package/dist/plugins/swift/nsurlsession/index.js +1 -5
- package/dist/plugins/swift/nsurlsession/nsurlsession.js +13 -13
- package/dist/snippetz.js +25 -28
- package/dist/utils/convertWithHttpSnippetLite.js +100 -96
- package/dist/utils/index.js +1 -5
- package/package.json +8 -12
- package/dist/clients/index.js.map +0 -7
- package/dist/httpsnippet-lite/helpers/code-builder.js.map +0 -7
- package/dist/httpsnippet-lite/helpers/escape.js.map +0 -7
- package/dist/httpsnippet-lite/helpers/headers.js.map +0 -7
- package/dist/httpsnippet-lite/helpers/reducer.js.map +0 -7
- package/dist/httpsnippet-lite/helpers/shell.js.map +0 -7
- package/dist/httpsnippet-lite/helpers/snippet-request.js.map +0 -7
- package/dist/httpsnippet-lite/helpers/url.js.map +0 -7
- package/dist/httpsnippet-lite/targets/c/libcurl/client.js.map +0 -7
- package/dist/httpsnippet-lite/targets/clojure/clj_http/client.js.map +0 -7
- package/dist/httpsnippet-lite/targets/csharp/restsharp/client.js.map +0 -7
- package/dist/httpsnippet-lite/targets/go/native/client.js.map +0 -7
- package/dist/httpsnippet-lite/targets/java/asynchttp/client.js.map +0 -7
- package/dist/httpsnippet-lite/targets/java/nethttp/client.js.map +0 -7
- package/dist/httpsnippet-lite/targets/java/okhttp/client.js.map +0 -7
- package/dist/httpsnippet-lite/targets/java/unirest/client.js.map +0 -7
- package/dist/httpsnippet-lite/targets/javascript/axios/client.js.map +0 -7
- package/dist/httpsnippet-lite/targets/javascript/jquery/client.js.map +0 -7
- package/dist/httpsnippet-lite/targets/javascript/xhr/client.js.map +0 -7
- package/dist/httpsnippet-lite/targets/kotlin/okhttp/client.js.map +0 -7
- package/dist/httpsnippet-lite/targets/node/axios/client.js.map +0 -7
- package/dist/httpsnippet-lite/targets/objc/helpers.js.map +0 -7
- package/dist/httpsnippet-lite/targets/objc/nsurlsession/client.js.map +0 -7
- package/dist/httpsnippet-lite/targets/ocaml/cohttp/client.js.map +0 -7
- package/dist/httpsnippet-lite/targets/powershell/common.js.map +0 -7
- package/dist/httpsnippet-lite/targets/powershell/restmethod/client.js.map +0 -7
- package/dist/httpsnippet-lite/targets/powershell/webrequest/client.js.map +0 -7
- package/dist/httpsnippet-lite/targets/python/python3/client.js.map +0 -7
- package/dist/httpsnippet-lite/targets/r/httr/client.js.map +0 -7
- package/dist/httpsnippet-lite/targets/ruby/native/client.js.map +0 -7
- package/dist/httpsnippet-lite/targets/shell/httpie/client.js.map +0 -7
- package/dist/httpsnippet-lite/targets/shell/wget/client.js.map +0 -7
- package/dist/httpsnippet-lite/targets/swift/helpers.js.map +0 -7
- package/dist/httpsnippet-lite/targets/swift/nsurlsession/client.js.map +0 -7
- package/dist/httpsnippet-lite/targets/target.js.map +0 -7
- package/dist/index.js.map +0 -7
- package/dist/libs/http.js.map +0 -7
- package/dist/libs/javascript.js.map +0 -7
- package/dist/libs/php.js.map +0 -7
- package/dist/libs/rust.js.map +0 -7
- package/dist/libs/shell.js.map +0 -7
- package/dist/plugins/c/libcurl/index.js.map +0 -7
- package/dist/plugins/c/libcurl/libcurl.js.map +0 -7
- package/dist/plugins/clojure/clj_http/clj_http.js.map +0 -7
- package/dist/plugins/clojure/clj_http/index.js.map +0 -7
- package/dist/plugins/csharp/httpclient/httpclient.js.map +0 -7
- package/dist/plugins/csharp/httpclient/index.js.map +0 -7
- package/dist/plugins/csharp/restsharp/index.js.map +0 -7
- package/dist/plugins/csharp/restsharp/restsharp.js.map +0 -7
- package/dist/plugins/dart/http/http.js.map +0 -7
- package/dist/plugins/dart/http/index.js.map +0 -7
- package/dist/plugins/fsharp/httpclient/httpclient.js.map +0 -7
- package/dist/plugins/fsharp/httpclient/index.js.map +0 -7
- package/dist/plugins/go/native/index.js.map +0 -7
- package/dist/plugins/go/native/native.js.map +0 -7
- package/dist/plugins/http/http11/http11.js.map +0 -7
- package/dist/plugins/http/http11/index.js.map +0 -7
- package/dist/plugins/java/asynchttp/asynchttp.js.map +0 -7
- package/dist/plugins/java/asynchttp/index.js.map +0 -7
- package/dist/plugins/java/nethttp/index.js.map +0 -7
- package/dist/plugins/java/nethttp/nethttp.js.map +0 -7
- package/dist/plugins/java/okhttp/index.js.map +0 -7
- package/dist/plugins/java/okhttp/okhttp.js.map +0 -7
- package/dist/plugins/java/unirest/index.js.map +0 -7
- package/dist/plugins/java/unirest/unirest.js.map +0 -7
- package/dist/plugins/js/axios/axios.js.map +0 -7
- package/dist/plugins/js/axios/index.js.map +0 -7
- package/dist/plugins/js/fetch/fetch.js.map +0 -7
- package/dist/plugins/js/fetch/index.js.map +0 -7
- package/dist/plugins/js/jquery/index.js.map +0 -7
- package/dist/plugins/js/jquery/jquery.js.map +0 -7
- package/dist/plugins/js/ofetch/index.js.map +0 -7
- package/dist/plugins/js/ofetch/ofetch.js.map +0 -7
- package/dist/plugins/js/xhr/index.js.map +0 -7
- package/dist/plugins/js/xhr/xhr.js.map +0 -7
- package/dist/plugins/kotlin/okhttp/index.js.map +0 -7
- package/dist/plugins/kotlin/okhttp/okhttp.js.map +0 -7
- package/dist/plugins/node/axios/axios.js.map +0 -7
- package/dist/plugins/node/axios/index.js.map +0 -7
- package/dist/plugins/node/fetch/fetch.js.map +0 -7
- package/dist/plugins/node/fetch/index.js.map +0 -7
- package/dist/plugins/node/ofetch/index.js.map +0 -7
- package/dist/plugins/node/ofetch/ofetch.js.map +0 -7
- package/dist/plugins/node/undici/index.js.map +0 -7
- package/dist/plugins/node/undici/undici.js.map +0 -7
- package/dist/plugins/objc/nsurlsession/index.js.map +0 -7
- package/dist/plugins/objc/nsurlsession/nsurlsession.js.map +0 -7
- package/dist/plugins/ocaml/cohttp/cohttp.js.map +0 -7
- package/dist/plugins/ocaml/cohttp/index.js.map +0 -7
- package/dist/plugins/php/curl/curl.js.map +0 -7
- package/dist/plugins/php/curl/index.js.map +0 -7
- package/dist/plugins/php/guzzle/guzzle.js.map +0 -7
- package/dist/plugins/php/guzzle/index.js.map +0 -7
- package/dist/plugins/powershell/restmethod/index.js.map +0 -7
- package/dist/plugins/powershell/restmethod/restmethod.js.map +0 -7
- package/dist/plugins/powershell/webrequest/index.js.map +0 -7
- package/dist/plugins/powershell/webrequest/webrequest.js.map +0 -7
- package/dist/plugins/python/httpx/async.js.map +0 -7
- package/dist/plugins/python/httpx/index.js.map +0 -7
- package/dist/plugins/python/httpx/sync.js.map +0 -7
- package/dist/plugins/python/python3/index.js.map +0 -7
- package/dist/plugins/python/python3/python3.js.map +0 -7
- package/dist/plugins/python/requests/index.js.map +0 -7
- package/dist/plugins/python/requests/requests.js.map +0 -7
- package/dist/plugins/python/requestsLike.js.map +0 -7
- package/dist/plugins/r/httr/httr.js.map +0 -7
- package/dist/plugins/r/httr/index.js.map +0 -7
- package/dist/plugins/ruby/native/index.js.map +0 -7
- package/dist/plugins/ruby/native/native.js.map +0 -7
- package/dist/plugins/rust/reqwest/index.js.map +0 -7
- package/dist/plugins/rust/reqwest/reqwest.js.map +0 -7
- package/dist/plugins/shell/curl/curl.js.map +0 -7
- package/dist/plugins/shell/curl/index.js.map +0 -7
- package/dist/plugins/shell/httpie/httpie.js.map +0 -7
- package/dist/plugins/shell/httpie/index.js.map +0 -7
- package/dist/plugins/shell/wget/index.js.map +0 -7
- package/dist/plugins/shell/wget/wget.js.map +0 -7
- package/dist/plugins/swift/nsurlsession/index.js.map +0 -7
- package/dist/plugins/swift/nsurlsession/nsurlsession.js.map +0 -7
- package/dist/snippetz.js.map +0 -7
- package/dist/utils/convertWithHttpSnippetLite.js.map +0 -7
- package/dist/utils/index.js.map +0 -7
|
@@ -1,100 +1,132 @@
|
|
|
1
|
-
import { escapeSingleQuotes } from
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
}
|
|
39
|
-
if (normalizedRequest.cookies?.length) {
|
|
40
|
-
const cookieString = normalizedRequest.cookies.map((cookie) => {
|
|
41
|
-
const encodedName = encodeURIComponent(cookie.name);
|
|
42
|
-
const encodedValue = encodeURIComponent(cookie.value);
|
|
43
|
-
return `${encodedName}=${encodedValue}`;
|
|
44
|
-
}).join("; ");
|
|
45
|
-
const escapedCookieString = escapeSingleQuotes(cookieString);
|
|
46
|
-
parts.push(`--cookie '${escapedCookieString}'`);
|
|
47
|
-
}
|
|
48
|
-
if (normalizedRequest.postData) {
|
|
49
|
-
if (normalizedRequest.postData.mimeType === "application/json") {
|
|
50
|
-
if (normalizedRequest.postData.text) {
|
|
51
|
-
try {
|
|
52
|
-
const jsonData = JSON.parse(normalizedRequest.postData.text);
|
|
53
|
-
const prettyJson = JSON.stringify(jsonData, null, 2);
|
|
54
|
-
const escapedJson = escapeSingleQuotes(prettyJson);
|
|
55
|
-
parts.push(`--data '${escapedJson}'`);
|
|
56
|
-
} catch {
|
|
57
|
-
const escapedText = escapeSingleQuotes(normalizedRequest.postData.text ?? "");
|
|
58
|
-
parts.push(`--data '${escapedText}'`);
|
|
59
|
-
}
|
|
1
|
+
import { escapeSingleQuotes } from '../../../libs/shell.js';
|
|
2
|
+
/**
|
|
3
|
+
* shell/curl
|
|
4
|
+
*/
|
|
5
|
+
export const shellCurl = {
|
|
6
|
+
target: 'shell',
|
|
7
|
+
client: 'curl',
|
|
8
|
+
title: 'Curl',
|
|
9
|
+
generate(request, configuration) {
|
|
10
|
+
// Defaults
|
|
11
|
+
const normalizedRequest = {
|
|
12
|
+
method: 'GET',
|
|
13
|
+
...request,
|
|
14
|
+
};
|
|
15
|
+
// Normalization
|
|
16
|
+
normalizedRequest.method = normalizedRequest.method.toUpperCase();
|
|
17
|
+
// Build curl command parts
|
|
18
|
+
const parts = ['curl'];
|
|
19
|
+
// URL (quote if has query parameters or special characters)
|
|
20
|
+
const queryString = normalizedRequest.queryString?.length
|
|
21
|
+
? '?' +
|
|
22
|
+
normalizedRequest.queryString
|
|
23
|
+
.map((param) => {
|
|
24
|
+
// Ensure both name and value are fully URI encoded
|
|
25
|
+
const encodedName = encodeURIComponent(param.name);
|
|
26
|
+
const encodedValue = encodeURIComponent(param.value);
|
|
27
|
+
return `${encodedName}=${encodedValue}`;
|
|
28
|
+
})
|
|
29
|
+
.join('&')
|
|
30
|
+
: '';
|
|
31
|
+
const url = `${normalizedRequest.url}${queryString}`;
|
|
32
|
+
const hasSpecialChars = /[\s<>[\]{}|\\^%$]/.test(url);
|
|
33
|
+
const urlPart = queryString || hasSpecialChars ? `'${url}'` : url;
|
|
34
|
+
parts[0] = `curl ${urlPart}`;
|
|
35
|
+
// Method
|
|
36
|
+
if (normalizedRequest.method !== 'GET') {
|
|
37
|
+
parts.push(`--request ${normalizedRequest.method}`);
|
|
60
38
|
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
normalizedRequest.postData.params.forEach((param) => {
|
|
66
|
-
const escapedValue = escapeSingleQuotes(param.value ?? "");
|
|
67
|
-
const encodedName = encodeURIComponent(param.name);
|
|
68
|
-
const escapedName = escapeSingleQuotes(encodedName);
|
|
69
|
-
parts.push(`--data-urlencode '${escapedName}=${escapedValue}'`);
|
|
70
|
-
});
|
|
71
|
-
} else if (normalizedRequest.postData.mimeType === "multipart/form-data" && normalizedRequest.postData.params) {
|
|
72
|
-
normalizedRequest.postData.params.forEach((param) => {
|
|
73
|
-
const escapedName = escapeSingleQuotes(param.name);
|
|
74
|
-
if (param.fileName !== void 0) {
|
|
75
|
-
const escapedFileName = escapeSingleQuotes(param.fileName);
|
|
76
|
-
parts.push(`--form '${escapedName}=@${escapedFileName}'`);
|
|
77
|
-
} else {
|
|
78
|
-
const escapedValue = escapeSingleQuotes(param.value ?? "");
|
|
79
|
-
parts.push(`--form '${escapedName}=${escapedValue}'`);
|
|
80
|
-
}
|
|
81
|
-
});
|
|
82
|
-
} else {
|
|
83
|
-
try {
|
|
84
|
-
const jsonData = JSON.parse(normalizedRequest.postData.text ?? "");
|
|
85
|
-
const prettyJson = JSON.stringify(jsonData, null, 2);
|
|
86
|
-
const escapedJson = escapeSingleQuotes(prettyJson);
|
|
87
|
-
parts.push(`--data '${escapedJson}'`);
|
|
88
|
-
} catch {
|
|
89
|
-
const escapedText = escapeSingleQuotes(normalizedRequest.postData.text ?? "");
|
|
90
|
-
parts.push(`--data '${escapedText}'`);
|
|
39
|
+
// Basic Auth
|
|
40
|
+
if (configuration?.auth?.username && configuration?.auth?.password) {
|
|
41
|
+
const authValue = escapeSingleQuotes(`${configuration.auth.username}:${configuration.auth.password}`);
|
|
42
|
+
parts.push(`--user '${authValue}'`);
|
|
91
43
|
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
};
|
|
97
|
-
|
|
98
|
-
|
|
44
|
+
// Headers
|
|
45
|
+
if (normalizedRequest.headers?.length) {
|
|
46
|
+
normalizedRequest.headers.forEach((header) => {
|
|
47
|
+
const headerValue = escapeSingleQuotes(`${header.name}: ${header.value}`);
|
|
48
|
+
parts.push(`--header '${headerValue}'`);
|
|
49
|
+
});
|
|
50
|
+
// Add compressed flag if Accept-Encoding header includes compression
|
|
51
|
+
const acceptEncoding = normalizedRequest.headers.find((header) => header.name.toLowerCase() === 'accept-encoding');
|
|
52
|
+
if (acceptEncoding && /gzip|deflate/.test(acceptEncoding.value)) {
|
|
53
|
+
parts.push('--compressed');
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
// Cookies
|
|
57
|
+
if (normalizedRequest.cookies?.length) {
|
|
58
|
+
const cookieString = normalizedRequest.cookies
|
|
59
|
+
.map((cookie) => {
|
|
60
|
+
// Encode both cookie name and value to handle special characters
|
|
61
|
+
const encodedName = encodeURIComponent(cookie.name);
|
|
62
|
+
const encodedValue = encodeURIComponent(cookie.value);
|
|
63
|
+
return `${encodedName}=${encodedValue}`;
|
|
64
|
+
})
|
|
65
|
+
.join('; ');
|
|
66
|
+
const escapedCookieString = escapeSingleQuotes(cookieString);
|
|
67
|
+
parts.push(`--cookie '${escapedCookieString}'`);
|
|
68
|
+
}
|
|
69
|
+
// Body
|
|
70
|
+
if (normalizedRequest.postData) {
|
|
71
|
+
if (normalizedRequest.postData.mimeType === 'application/json') {
|
|
72
|
+
// Pretty print JSON data
|
|
73
|
+
if (normalizedRequest.postData.text) {
|
|
74
|
+
try {
|
|
75
|
+
const jsonData = JSON.parse(normalizedRequest.postData.text);
|
|
76
|
+
const prettyJson = JSON.stringify(jsonData, null, 2);
|
|
77
|
+
const escapedJson = escapeSingleQuotes(prettyJson);
|
|
78
|
+
parts.push(`--data '${escapedJson}'`);
|
|
79
|
+
}
|
|
80
|
+
catch {
|
|
81
|
+
// If JSON parsing fails, use the original text
|
|
82
|
+
const escapedText = escapeSingleQuotes(normalizedRequest.postData.text ?? '');
|
|
83
|
+
parts.push(`--data '${escapedText}'`);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
else if (normalizedRequest.postData.mimeType === 'application/octet-stream') {
|
|
88
|
+
const escapedText = escapeSingleQuotes(normalizedRequest.postData.text ?? '');
|
|
89
|
+
parts.push(`--data-binary '${escapedText}'`);
|
|
90
|
+
}
|
|
91
|
+
else if (normalizedRequest.postData.mimeType === 'application/x-www-form-urlencoded' &&
|
|
92
|
+
normalizedRequest.postData.params) {
|
|
93
|
+
// Handle URL-encoded form data
|
|
94
|
+
normalizedRequest.postData.params.forEach((param) => {
|
|
95
|
+
const escapedValue = escapeSingleQuotes(param.value ?? '');
|
|
96
|
+
const encodedName = encodeURIComponent(param.name);
|
|
97
|
+
const escapedName = escapeSingleQuotes(encodedName);
|
|
98
|
+
parts.push(`--data-urlencode '${escapedName}=${escapedValue}'`);
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
else if (normalizedRequest.postData.mimeType === 'multipart/form-data' && normalizedRequest.postData.params) {
|
|
102
|
+
// Handle multipart form data
|
|
103
|
+
normalizedRequest.postData.params.forEach((param) => {
|
|
104
|
+
const escapedName = escapeSingleQuotes(param.name);
|
|
105
|
+
const multipartValueSuffix = param.contentType ? `;type=${param.contentType}` : '';
|
|
106
|
+
if (param.fileName !== undefined) {
|
|
107
|
+
const escapedFileName = escapeSingleQuotes(`${param.fileName}${multipartValueSuffix}`);
|
|
108
|
+
parts.push(`--form '${escapedName}=@${escapedFileName}'`);
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
const escapedValue = escapeSingleQuotes(`${param.value ?? ''}${multipartValueSuffix}`);
|
|
112
|
+
parts.push(`--form '${escapedName}=${escapedValue}'`);
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
else {
|
|
117
|
+
// Try to parse and pretty print if it's JSON, otherwise use raw text
|
|
118
|
+
try {
|
|
119
|
+
const jsonData = JSON.parse(normalizedRequest.postData.text ?? '');
|
|
120
|
+
const prettyJson = JSON.stringify(jsonData, null, 2);
|
|
121
|
+
const escapedJson = escapeSingleQuotes(prettyJson);
|
|
122
|
+
parts.push(`--data '${escapedJson}'`);
|
|
123
|
+
}
|
|
124
|
+
catch {
|
|
125
|
+
const escapedText = escapeSingleQuotes(normalizedRequest.postData.text ?? '');
|
|
126
|
+
parts.push(`--data '${escapedText}'`);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
return parts.join(' \\\n ');
|
|
131
|
+
},
|
|
99
132
|
};
|
|
100
|
-
//# sourceMappingURL=curl.js.map
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { httpie } from
|
|
2
|
-
import { convertWithHttpSnippetLite } from
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
import { httpie } from '../../../httpsnippet-lite/targets/shell/httpie/client.js';
|
|
2
|
+
import { convertWithHttpSnippetLite } from '../../../utils/convertWithHttpSnippetLite.js';
|
|
3
|
+
/**
|
|
4
|
+
* shell/httpie
|
|
5
|
+
*/
|
|
6
|
+
export const shellHttpie = {
|
|
7
|
+
target: 'shell',
|
|
8
|
+
client: 'httpie',
|
|
9
|
+
title: 'HTTPie',
|
|
10
|
+
generate(request) {
|
|
11
|
+
// TODO: Write an own converter
|
|
12
|
+
return convertWithHttpSnippetLite(httpie, request);
|
|
13
|
+
},
|
|
10
14
|
};
|
|
11
|
-
export {
|
|
12
|
-
shellHttpie
|
|
13
|
-
};
|
|
14
|
-
//# sourceMappingURL=httpie.js.map
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { wget } from
|
|
2
|
-
import { convertWithHttpSnippetLite } from
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
import { wget } from '../../../httpsnippet-lite/targets/shell/wget/client.js';
|
|
2
|
+
import { convertWithHttpSnippetLite } from '../../../utils/convertWithHttpSnippetLite.js';
|
|
3
|
+
/**
|
|
4
|
+
* shell/wget
|
|
5
|
+
*/
|
|
6
|
+
export const shellWget = {
|
|
7
|
+
target: 'shell',
|
|
8
|
+
client: 'wget',
|
|
9
|
+
title: 'Wget',
|
|
10
|
+
generate(request) {
|
|
11
|
+
// TODO: Write an own converter
|
|
12
|
+
return convertWithHttpSnippetLite(wget, request);
|
|
13
|
+
},
|
|
10
14
|
};
|
|
11
|
-
export {
|
|
12
|
-
shellWget
|
|
13
|
-
};
|
|
14
|
-
//# sourceMappingURL=wget.js.map
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { nsurlsession } from
|
|
2
|
-
import { convertWithHttpSnippetLite } from
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
import { nsurlsession } from '../../../httpsnippet-lite/targets/swift/nsurlsession/client.js';
|
|
2
|
+
import { convertWithHttpSnippetLite } from '../../../utils/convertWithHttpSnippetLite.js';
|
|
3
|
+
/**
|
|
4
|
+
* swift/nsurlsession
|
|
5
|
+
*/
|
|
6
|
+
export const swiftNsurlsession = {
|
|
7
|
+
target: 'swift',
|
|
8
|
+
client: 'nsurlsession',
|
|
9
|
+
title: 'NSURLSession',
|
|
10
|
+
generate(request) {
|
|
11
|
+
// TODO: Write an own converter
|
|
12
|
+
return convertWithHttpSnippetLite(nsurlsession, request);
|
|
13
|
+
},
|
|
10
14
|
};
|
|
11
|
-
export {
|
|
12
|
-
swiftNsurlsession
|
|
13
|
-
};
|
|
14
|
-
//# sourceMappingURL=nsurlsession.js.map
|
package/dist/snippetz.js
CHANGED
|
@@ -1,30 +1,27 @@
|
|
|
1
|
-
import { clients } from
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
return findPlugin(target, client)?.generate(request);
|
|
9
|
-
},
|
|
10
|
-
clients() {
|
|
11
|
-
return clients;
|
|
12
|
-
},
|
|
13
|
-
plugins() {
|
|
14
|
-
return clients.flatMap(
|
|
15
|
-
({ key, clients: clients2 }) => clients2.map((plugin) => ({
|
|
16
|
-
target: key,
|
|
17
|
-
client: plugin.client
|
|
18
|
-
}))
|
|
19
|
-
);
|
|
20
|
-
},
|
|
21
|
-
findPlugin,
|
|
22
|
-
hasPlugin(target, client) {
|
|
23
|
-
return Boolean(findPlugin(target, client));
|
|
1
|
+
import { clients } from './clients/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* Generate code examples for HAR requests
|
|
4
|
+
*/
|
|
5
|
+
export function snippetz() {
|
|
6
|
+
function findPlugin(target, client) {
|
|
7
|
+
return clients.find(({ key }) => key === target)?.clients.find((plugin) => plugin.client === client);
|
|
24
8
|
}
|
|
25
|
-
|
|
9
|
+
return {
|
|
10
|
+
print(target, client, request) {
|
|
11
|
+
return findPlugin(target, client)?.generate(request);
|
|
12
|
+
},
|
|
13
|
+
clients() {
|
|
14
|
+
return clients;
|
|
15
|
+
},
|
|
16
|
+
plugins() {
|
|
17
|
+
return clients.flatMap(({ key, clients }) => clients.map((plugin) => ({
|
|
18
|
+
target: key,
|
|
19
|
+
client: plugin.client,
|
|
20
|
+
})));
|
|
21
|
+
},
|
|
22
|
+
findPlugin,
|
|
23
|
+
hasPlugin(target, client) {
|
|
24
|
+
return Boolean(findPlugin(target, client));
|
|
25
|
+
},
|
|
26
|
+
};
|
|
26
27
|
}
|
|
27
|
-
export {
|
|
28
|
-
snippetz
|
|
29
|
-
};
|
|
30
|
-
//# sourceMappingURL=snippetz.js.map
|
|
@@ -1,98 +1,102 @@
|
|
|
1
|
-
import { reduceQueryParams } from
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
1
|
+
import { reduceQueryParams } from '../libs/http.js';
|
|
2
|
+
/**
|
|
3
|
+
* Takes a httpsnippet-lite client and converts the given request to a code example with it.
|
|
4
|
+
*
|
|
5
|
+
* @deprecated This a temporary wrapper around httpsnippet-lite. Let's write all the generators ourselves instead.
|
|
6
|
+
*/
|
|
7
|
+
export function convertWithHttpSnippetLite(
|
|
8
|
+
// Couldn't find the proper type, there was always a mismatch.
|
|
9
|
+
client, request) {
|
|
10
|
+
const urlObject = new URL(request?.url ?? '');
|
|
11
|
+
// If it's just the domain, omit the trailing slash
|
|
12
|
+
const url = urlObject.pathname === '/' ? urlObject.origin : urlObject.toString();
|
|
13
|
+
const harRequest = {
|
|
14
|
+
method: request?.method ?? 'GET',
|
|
15
|
+
url,
|
|
16
|
+
httpVersion: 'HTTP/1.1',
|
|
17
|
+
cookies: [], // Cookies are handled through headers
|
|
18
|
+
headers: request?.headers ?? [],
|
|
19
|
+
headersSize: -1,
|
|
20
|
+
bodySize: -1,
|
|
21
|
+
queryString: Array.from(urlObject.searchParams.entries()).map(([name, value]) => ({
|
|
22
|
+
name,
|
|
23
|
+
value,
|
|
24
|
+
})),
|
|
25
|
+
postData: request?.postData,
|
|
26
|
+
};
|
|
27
|
+
const allHeaders = (harRequest?.headers ?? []).reduce((acc, header) => ({
|
|
28
|
+
...acc,
|
|
29
|
+
[header.name]: header.value,
|
|
30
|
+
}), {});
|
|
31
|
+
const queryObj = reduceQueryParams(harRequest.queryString);
|
|
32
|
+
const cookiesObj = (harRequest.cookies ?? []).reduce((acc, cookie) => ({
|
|
33
|
+
...acc,
|
|
34
|
+
[cookie.name]: cookie.value,
|
|
35
|
+
}), {});
|
|
36
|
+
const parsedUrl = new URL(harRequest.url);
|
|
37
|
+
const uriObj = {
|
|
38
|
+
protocol: parsedUrl.protocol,
|
|
39
|
+
hostname: parsedUrl.hostname,
|
|
40
|
+
host: parsedUrl.hostname,
|
|
41
|
+
port: parsedUrl.port,
|
|
42
|
+
pathname: parsedUrl.pathname
|
|
43
|
+
.split('/')
|
|
44
|
+
.map((segment) => encodeURIComponent(decodeURIComponent(segment)))
|
|
45
|
+
.join('/') + parsedUrl.search,
|
|
46
|
+
path: parsedUrl.pathname
|
|
47
|
+
.split('/')
|
|
48
|
+
.map((segment) => encodeURIComponent(decodeURIComponent(segment)))
|
|
49
|
+
.join('/') + parsedUrl.search,
|
|
50
|
+
search: parsedUrl.search,
|
|
51
|
+
hash: parsedUrl.hash,
|
|
52
|
+
href: parsedUrl.href,
|
|
53
|
+
origin: parsedUrl.origin,
|
|
54
|
+
password: parsedUrl.password,
|
|
55
|
+
searchParams: parsedUrl.searchParams,
|
|
56
|
+
username: parsedUrl.username,
|
|
57
|
+
toString: parsedUrl.toString,
|
|
58
|
+
toJSON: () => parsedUrl.toJSON(),
|
|
59
|
+
};
|
|
60
|
+
const convertRequest = {
|
|
61
|
+
url: harRequest.url,
|
|
62
|
+
uriObj,
|
|
63
|
+
method: harRequest.method?.toLocaleUpperCase() ?? 'GET',
|
|
64
|
+
httpVersion: harRequest.httpVersion,
|
|
65
|
+
cookies: harRequest.cookies ?? [],
|
|
66
|
+
headers: harRequest.headers ?? [],
|
|
67
|
+
headersSize: harRequest.headersSize ?? 0,
|
|
68
|
+
headersObj: allHeaders ?? {},
|
|
69
|
+
bodySize: harRequest.bodySize ?? 0,
|
|
70
|
+
queryString: harRequest.queryString ?? [],
|
|
71
|
+
postData: harRequest.postData
|
|
72
|
+
? {
|
|
73
|
+
mimeType: harRequest.postData.mimeType ?? 'application/json',
|
|
74
|
+
text: harRequest.postData.text ?? '',
|
|
75
|
+
params: harRequest.postData.params ?? [],
|
|
76
|
+
paramsObj: harRequest.postData.params?.reduce((acc, param) => {
|
|
77
|
+
if (param.name && param.value !== undefined) {
|
|
78
|
+
acc[param.name] = param.value;
|
|
79
|
+
}
|
|
80
|
+
return acc;
|
|
81
|
+
}, {}) ?? {},
|
|
82
|
+
}
|
|
83
|
+
: undefined,
|
|
84
|
+
allHeaders: allHeaders ?? {},
|
|
85
|
+
fullUrl: harRequest.url,
|
|
86
|
+
queryObj: queryObj ?? {},
|
|
87
|
+
cookiesObj: cookiesObj ?? {},
|
|
88
|
+
};
|
|
89
|
+
// If the request is a JSON request, parse the text as JSON
|
|
90
|
+
if (convertRequest.postData?.mimeType === 'application/json' && convertRequest.postData.text) {
|
|
91
|
+
try {
|
|
92
|
+
convertRequest.postData.jsonObj = JSON.parse(convertRequest.postData.text);
|
|
93
|
+
}
|
|
94
|
+
catch (error) {
|
|
95
|
+
console.error('Error parsing JSON:', error);
|
|
96
|
+
}
|
|
88
97
|
}
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
return "";
|
|
98
|
+
if (typeof client.convert === 'function') {
|
|
99
|
+
return client.convert(convertRequest);
|
|
100
|
+
}
|
|
101
|
+
return '';
|
|
94
102
|
}
|
|
95
|
-
export {
|
|
96
|
-
convertWithHttpSnippetLite
|
|
97
|
-
};
|
|
98
|
-
//# sourceMappingURL=convertWithHttpSnippetLite.js.map
|
package/dist/utils/index.js
CHANGED