@scalar/snippetz 0.5.3 → 0.5.4
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.d.ts.map +1 -1
- package/dist/clients/index.js +1 -1
- package/dist/clients/index.js.map +2 -2
- package/dist/httpsnippet-lite/esm/targets/c/libcurl/client.js +1 -1
- package/dist/httpsnippet-lite/esm/targets/c/libcurl/client.js.map +1 -1
- package/dist/libs/http.d.ts +27 -0
- package/dist/libs/http.d.ts.map +1 -0
- package/dist/libs/http.js +46 -0
- package/dist/libs/http.js.map +7 -0
- package/dist/{utils/objectToString.d.ts → libs/javascript.d.ts} +2 -2
- package/dist/libs/javascript.d.ts.map +1 -0
- package/dist/{utils/objectToString.js → libs/javascript.js} +7 -5
- package/dist/libs/javascript.js.map +7 -0
- package/dist/libs/php.d.ts +17 -0
- package/dist/libs/php.d.ts.map +1 -0
- package/dist/libs/php.js +57 -0
- package/dist/libs/php.js.map +7 -0
- package/dist/libs/rust.d.ts +23 -0
- package/dist/libs/rust.d.ts.map +1 -0
- package/dist/libs/rust.js +39 -0
- package/dist/libs/rust.js.map +7 -0
- package/dist/libs/shell.d.ts +15 -0
- package/dist/libs/shell.d.ts.map +1 -0
- package/dist/libs/shell.js +5 -0
- package/dist/libs/shell.js.map +7 -0
- package/dist/plugins/c/libcurl/libcurl.d.ts.map +1 -1
- package/dist/plugins/c/libcurl/libcurl.js.map +2 -2
- package/dist/plugins/csharp/httpclient/httpclient.js +1 -1
- package/dist/plugins/csharp/httpclient/httpclient.js.map +1 -1
- package/dist/plugins/js/axios/axios.d.ts.map +1 -1
- package/dist/plugins/js/axios/axios.js.map +2 -2
- package/dist/plugins/js/fetch/fetch.d.ts.map +1 -1
- package/dist/plugins/js/fetch/fetch.js +6 -6
- package/dist/plugins/js/fetch/fetch.js.map +2 -2
- package/dist/plugins/js/ofetch/ofetch.d.ts.map +1 -1
- package/dist/plugins/js/ofetch/ofetch.js +1 -1
- package/dist/plugins/js/ofetch/ofetch.js.map +2 -2
- package/dist/plugins/node/axios/axios.d.ts.map +1 -1
- package/dist/plugins/node/axios/axios.js.map +2 -2
- package/dist/plugins/node/fetch/fetch.d.ts.map +1 -1
- package/dist/plugins/node/fetch/fetch.js +6 -6
- package/dist/plugins/node/fetch/fetch.js.map +2 -2
- package/dist/plugins/node/ofetch/ofetch.d.ts.map +1 -1
- package/dist/plugins/node/ofetch/ofetch.js +1 -1
- package/dist/plugins/node/ofetch/ofetch.js.map +2 -2
- package/dist/plugins/node/undici/undici.d.ts.map +1 -1
- package/dist/plugins/node/undici/undici.js +3 -3
- package/dist/plugins/node/undici/undici.js.map +2 -2
- package/dist/plugins/php/curl/curl.d.ts.map +1 -1
- package/dist/plugins/php/curl/curl.js +3 -36
- package/dist/plugins/php/curl/curl.js.map +2 -2
- package/dist/plugins/php/guzzle/guzzle.d.ts.map +1 -1
- package/dist/plugins/php/guzzle/guzzle.js +5 -39
- package/dist/plugins/php/guzzle/guzzle.js.map +2 -2
- package/dist/plugins/rust/reqwest/reqwest.d.ts.map +1 -1
- package/dist/plugins/rust/reqwest/reqwest.js +19 -72
- package/dist/plugins/rust/reqwest/reqwest.js.map +2 -2
- package/dist/plugins/shell/curl/curl.d.ts.map +1 -1
- package/dist/plugins/shell/curl/curl.js +26 -11
- package/dist/plugins/shell/curl/curl.js.map +2 -2
- package/dist/utils/convertWithHttpSnippetLite.d.ts.map +1 -1
- package/dist/utils/convertWithHttpSnippetLite.js.map +2 -2
- package/dist/utils/index.d.ts +0 -2
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +0 -2
- package/dist/utils/index.js.map +2 -2
- package/package.json +3 -3
- package/dist/plugins/rust/rustString.d.ts +0 -9
- package/dist/plugins/rust/rustString.d.ts.map +0 -1
- package/dist/plugins/rust/rustString.js +0 -10
- package/dist/plugins/rust/rustString.js.map +0 -7
- package/dist/utils/create-search-params.d.ts +0 -4
- package/dist/utils/create-search-params.d.ts.map +0 -1
- package/dist/utils/create-search-params.js +0 -11
- package/dist/utils/create-search-params.js.map +0 -7
- package/dist/utils/needsQuotes.d.ts +0 -7
- package/dist/utils/needsQuotes.d.ts.map +0 -1
- package/dist/utils/needsQuotes.js +0 -7
- package/dist/utils/needsQuotes.js.map +0 -7
- package/dist/utils/objectToString.d.ts.map +0 -1
- package/dist/utils/objectToString.js.map +0 -7
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { Raw, objectToString } from "../../../libs/javascript.js";
|
|
2
|
+
import { createSearchParams } from "../../../libs/http.js";
|
|
3
3
|
const jsFetch = {
|
|
4
4
|
target: "js",
|
|
5
5
|
client: "fetch",
|
|
@@ -37,8 +37,8 @@ const jsFetch = {
|
|
|
37
37
|
const { mimeType, text, params } = normalizedRequest.postData;
|
|
38
38
|
if (mimeType === "application/json" && text) {
|
|
39
39
|
try {
|
|
40
|
-
options.body = new
|
|
41
|
-
} catch
|
|
40
|
+
options.body = new Raw(`JSON.stringify(${objectToString(JSON.parse(text))})`);
|
|
41
|
+
} catch {
|
|
42
42
|
options.body = text;
|
|
43
43
|
}
|
|
44
44
|
} else if (mimeType === "multipart/form-data" && params) {
|
|
@@ -53,10 +53,10 @@ const jsFetch = {
|
|
|
53
53
|
}
|
|
54
54
|
});
|
|
55
55
|
prefix += "\n";
|
|
56
|
-
options.body = new
|
|
56
|
+
options.body = new Raw("formData");
|
|
57
57
|
} else if (mimeType === "application/x-www-form-urlencoded" && params) {
|
|
58
58
|
const form = Object.fromEntries(params.map((p) => [p.name, p.value]));
|
|
59
|
-
options.body = new
|
|
59
|
+
options.body = new Raw(`new URLSearchParams(${objectToString(form)})`);
|
|
60
60
|
} else {
|
|
61
61
|
options.body = normalizedRequest.postData.text;
|
|
62
62
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/plugins/js/fetch/fetch.ts"],
|
|
4
|
-
"sourcesContent": ["import {
|
|
5
|
-
"mappings": "
|
|
4
|
+
"sourcesContent": ["import type { Plugin } from '@scalar/types/snippetz'\n\nimport { Raw, objectToString } from '@/libs/javascript'\nimport { createSearchParams } from '@/libs/http'\n\n/**\n * js/fetch\n */\nexport const jsFetch: Plugin = {\n target: 'js',\n client: 'fetch',\n title: 'Fetch',\n generate(request) {\n // Defaults\n const normalizedRequest = {\n method: 'GET',\n ...request,\n }\n\n let prefix = ''\n\n // Normalization\n normalizedRequest.method = normalizedRequest.method.toUpperCase()\n\n // Reset fetch defaults\n const options: Record<string, any> = {\n method: normalizedRequest.method === 'GET' ? undefined : normalizedRequest.method,\n }\n\n // Query\n const searchParams = createSearchParams(normalizedRequest.queryString)\n const queryString = searchParams.size ? `?${searchParams.toString()}` : ''\n\n // Headers\n if (normalizedRequest.headers?.length) {\n options.headers = {}\n\n normalizedRequest.headers.forEach((header) => {\n options.headers![header.name] = header.value\n })\n }\n\n // Cookies\n if (normalizedRequest.cookies?.length) {\n options.headers = options.headers || {}\n\n normalizedRequest.cookies.forEach((cookie) => {\n options.headers!['Set-Cookie'] = options.headers!['Set-Cookie']\n ? `${options.headers!['Set-Cookie']}; ${cookie.name}=${cookie.value}`\n : `${cookie.name}=${cookie.value}`\n })\n }\n\n // Remove undefined keys\n Object.keys(options).forEach((key) => {\n if (options[key] === undefined) {\n delete options[key]\n }\n })\n\n // Add body\n if (normalizedRequest.postData) {\n const { mimeType, text, params } = normalizedRequest.postData\n\n if (mimeType === 'application/json' && text) {\n try {\n options.body = new Raw(`JSON.stringify(${objectToString(JSON.parse(text))})`)\n } catch {\n options.body = text\n }\n } else if (mimeType === 'multipart/form-data' && params) {\n prefix = 'const formData = new FormData()\\n'\n params.forEach((param) => {\n if (param.fileName !== undefined) {\n prefix += `formData.append('${param.name}', new Blob([]), '${param.fileName}')\\n`\n } else if (param.value !== undefined) {\n prefix += `formData.append('${param.name}', '${param.value}')\\n`\n }\n })\n prefix += '\\n'\n options.body = new Raw('formData')\n } else if (mimeType === 'application/x-www-form-urlencoded' && params) {\n const form = Object.fromEntries(params.map((p) => [p.name, p.value]))\n options.body = new Raw(`new URLSearchParams(${objectToString(form)})`)\n } else {\n options.body = normalizedRequest.postData.text\n }\n }\n\n // Transform to JSON\n const jsonOptions = Object.keys(options).length ? `, ${objectToString(options)}` : ''\n\n // Code Template\n return `${prefix}fetch('${normalizedRequest.url}${queryString}'${jsonOptions})`\n },\n}\n"],
|
|
5
|
+
"mappings": "AAEA,SAAS,KAAK,sBAAsB;AACpC,SAAS,0BAA0B;AAK5B,MAAM,UAAkB;AAAA,EAC7B,QAAQ;AAAA,EACR,QAAQ;AAAA,EACR,OAAO;AAAA,EACP,SAAS,SAAS;AAEhB,UAAM,oBAAoB;AAAA,MACxB,QAAQ;AAAA,MACR,GAAG;AAAA,IACL;AAEA,QAAI,SAAS;AAGb,sBAAkB,SAAS,kBAAkB,OAAO,YAAY;AAGhE,UAAM,UAA+B;AAAA,MACnC,QAAQ,kBAAkB,WAAW,QAAQ,SAAY,kBAAkB;AAAA,IAC7E;AAGA,UAAM,eAAe,mBAAmB,kBAAkB,WAAW;AACrE,UAAM,cAAc,aAAa,OAAO,IAAI,aAAa,SAAS,CAAC,KAAK;AAGxE,QAAI,kBAAkB,SAAS,QAAQ;AACrC,cAAQ,UAAU,CAAC;AAEnB,wBAAkB,QAAQ,QAAQ,CAAC,WAAW;AAC5C,gBAAQ,QAAS,OAAO,IAAI,IAAI,OAAO;AAAA,MACzC,CAAC;AAAA,IACH;AAGA,QAAI,kBAAkB,SAAS,QAAQ;AACrC,cAAQ,UAAU,QAAQ,WAAW,CAAC;AAEtC,wBAAkB,QAAQ,QAAQ,CAAC,WAAW;AAC5C,gBAAQ,QAAS,YAAY,IAAI,QAAQ,QAAS,YAAY,IAC1D,GAAG,QAAQ,QAAS,YAAY,CAAC,KAAK,OAAO,IAAI,IAAI,OAAO,KAAK,KACjE,GAAG,OAAO,IAAI,IAAI,OAAO,KAA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6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ofetch.d.ts","sourceRoot":"","sources":["../../../../src/plugins/js/ofetch/ofetch.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ofetch.d.ts","sourceRoot":"","sources":["../../../../src/plugins/js/ofetch/ofetch.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAA;AAIpD;;GAEG;AACH,eAAO,MAAM,QAAQ,EAAE,MAsEtB,CAAA"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/plugins/js/ofetch/ofetch.ts"],
|
|
4
|
-
"sourcesContent": ["import {
|
|
5
|
-
"mappings": "
|
|
4
|
+
"sourcesContent": ["import type { Plugin } from '@scalar/types/snippetz'\n\nimport { objectToString } from '@/libs/javascript'\n\n/**\n * js/ofetch\n */\nexport const jsOfetch: Plugin = {\n target: 'js',\n client: 'ofetch',\n title: 'ofetch',\n generate(request) {\n // Defaults\n const normalizedRequest = {\n method: 'GET',\n ...request,\n }\n\n // Normalization\n normalizedRequest.method = normalizedRequest.method.toUpperCase()\n\n // Reset fetch defaults\n const options: Record<string, any> = {\n method: normalizedRequest.method === 'GET' ? undefined : normalizedRequest.method,\n }\n\n // Query\n if (normalizedRequest.queryString?.length) {\n options.query = Object.fromEntries(normalizedRequest.queryString.map((q) => [q.name, q.value]))\n }\n\n // Headers\n if (normalizedRequest.headers?.length) {\n options.headers = {}\n\n normalizedRequest.headers.forEach((header) => {\n options.headers![header.name] = header.value\n })\n }\n\n // Cookies\n if (normalizedRequest.cookies?.length) {\n options.headers = options.headers || {}\n\n normalizedRequest.cookies.forEach((cookie) => {\n options.headers!['Set-Cookie'] = options.headers!['Set-Cookie']\n ? `${options.headers!['Set-Cookie']}; ${cookie.name}=${cookie.value}`\n : `${cookie.name}=${cookie.value}`\n })\n }\n\n // Remove undefined keys\n Object.keys(options).forEach((key) => {\n if (options[key] === undefined) {\n delete options[key]\n }\n })\n\n // Add body\n if (normalizedRequest.postData) {\n // Plain text\n options.body = normalizedRequest.postData.text\n\n // JSON\n if (normalizedRequest.postData.mimeType === 'application/json') {\n options.body = JSON.parse(options.body)\n }\n }\n\n // Transform to JSON\n const jsonOptions = Object.keys(options).length ? `, ${objectToString(options)}` : ''\n\n // Code Template\n return `import { ofetch } from 'ofetch'\n\nofetch('${normalizedRequest.url}'${jsonOptions})`\n },\n}\n"],
|
|
5
|
+
"mappings": "AAEA,SAAS,sBAAsB;AAKxB,MAAM,WAAmB;AAAA,EAC9B,QAAQ;AAAA,EACR,QAAQ;AAAA,EACR,OAAO;AAAA,EACP,SAAS,SAAS;AAEhB,UAAM,oBAAoB;AAAA,MACxB,QAAQ;AAAA,MACR,GAAG;AAAA,IACL;AAGA,sBAAkB,SAAS,kBAAkB,OAAO,YAAY;AAGhE,UAAM,UAA+B;AAAA,MACnC,QAAQ,kBAAkB,WAAW,QAAQ,SAAY,kBAAkB;AAAA,IAC7E;AAGA,QAAI,kBAAkB,aAAa,QAAQ;AACzC,cAAQ,QAAQ,OAAO,YAAY,kBAAkB,YAAY,IAAI,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC;AAAA,IAChG;AAGA,QAAI,kBAAkB,SAAS,QAAQ;AACrC,cAAQ,UAAU,CAAC;AAEnB,wBAAkB,QAAQ,QAAQ,CAAC,WAAW;AAC5C,gBAAQ,QAAS,OAAO,IAAI,IAAI,OAAO;AAAA,MACzC,CAAC;AAAA,IACH;AAGA,QAAI,kBAAkB,SAAS,QAAQ;AACrC,cAAQ,UAAU,QAAQ,WAAW,CAAC;AAEtC,wBAAkB,QAAQ,QAAQ,CAAC,WAAW;AAC5C,gBAAQ,QAAS,YAAY,IAAI,QAAQ,QAAS,YAAY,IAC1D,GAAG,QAAQ,QAAS,YAAY,CAAC,KAAK,OAAO,IAAI,IAAI,OAAO,KAAK,KACjE,GAAG,OAAO,IAAI,IAAI,OAAO,KAAK;AAAA,MACpC,CAAC;AAAA,IACH;AAGA,WAAO,KAAK,OAAO,EAAE,QAAQ,CAAC,QAAQ;AACpC,UAAI,QAAQ,GAAG,MAAM,QAAW;AAC9B,eAAO,QAAQ,GAAG;AAAA,MACpB;AAAA,IACF,CAAC;AAGD,QAAI,kBAAkB,UAAU;AAE9B,cAAQ,OAAO,kBAAkB,SAAS;AAG1C,UAAI,kBAAkB,SAAS,aAAa,oBAAoB;AAC9D,gBAAQ,OAAO,KAAK,MAAM,QAAQ,IAAI;AAAA,MACxC;AAAA,IACF;AAGA,UAAM,cAAc,OAAO,KAAK,OAAO,EAAE,SAAS,KAAK,eAAe,OAAO,CAAC,KAAK;AAGnF,WAAO;AAAA;AAAA,UAED,kBAAkB,GAAG,IAAI,WAAW;AAAA,EAC5C;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"axios.d.ts","sourceRoot":"","sources":["../../../../src/plugins/node/axios/axios.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"axios.d.ts","sourceRoot":"","sources":["../../../../src/plugins/node/axios/axios.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAA;AAKpD;;GAEG;AACH,eAAO,MAAM,SAAS,EAAE,MAQvB,CAAA"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/plugins/node/axios/axios.ts"],
|
|
4
|
-
"sourcesContent": ["import { axios } from '@/httpsnippet-lite/esm/targets/node/axios/client'\nimport { convertWithHttpSnippetLite } from '@/utils/convertWithHttpSnippetLite'\
|
|
5
|
-
"mappings": "
|
|
4
|
+
"sourcesContent": ["import type { Plugin } from '@scalar/types/snippetz'\n\nimport { axios } from '@/httpsnippet-lite/esm/targets/node/axios/client'\nimport { convertWithHttpSnippetLite } from '@/utils/convertWithHttpSnippetLite'\n\n/**\n * node/axios\n */\nexport const nodeAxios: Plugin = {\n target: 'node',\n client: 'axios',\n title: 'Axios',\n generate(request) {\n // TODO: Write an own converter\n return convertWithHttpSnippetLite(axios, request)\n },\n}\n"],
|
|
5
|
+
"mappings": "AAEA,SAAS,aAAa;AACtB,SAAS,kCAAkC;AAKpC,MAAM,YAAoB;AAAA,EAC/B,QAAQ;AAAA,EACR,QAAQ;AAAA,EACR,OAAO;AAAA,EACP,SAAS,SAAS;AAEhB,WAAO,2BAA2B,OAAO,OAAO;AAAA,EAClD;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetch.d.ts","sourceRoot":"","sources":["../../../../src/plugins/node/fetch/fetch.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"fetch.d.ts","sourceRoot":"","sources":["../../../../src/plugins/node/fetch/fetch.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAA;AAKpD;;GAEG;AACH,eAAO,MAAM,SAAS,EAAE,MA4FvB,CAAA"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { Raw, objectToString } from "../../../libs/javascript.js";
|
|
2
|
+
import { createSearchParams } from "../../../libs/http.js";
|
|
3
3
|
const nodeFetch = {
|
|
4
4
|
target: "node",
|
|
5
5
|
client: "fetch",
|
|
@@ -38,8 +38,8 @@ const nodeFetch = {
|
|
|
38
38
|
let hasFsImport = false;
|
|
39
39
|
if (mimeType === "application/json" && text) {
|
|
40
40
|
try {
|
|
41
|
-
options.body = new
|
|
42
|
-
} catch
|
|
41
|
+
options.body = new Raw(`JSON.stringify(${objectToString(JSON.parse(text))})`);
|
|
42
|
+
} catch {
|
|
43
43
|
options.body = text;
|
|
44
44
|
}
|
|
45
45
|
} else if (mimeType === "multipart/form-data" && params) {
|
|
@@ -60,10 +60,10 @@ ${prefix}`;
|
|
|
60
60
|
}
|
|
61
61
|
});
|
|
62
62
|
prefix += "\n";
|
|
63
|
-
options.body = new
|
|
63
|
+
options.body = new Raw("formData");
|
|
64
64
|
} else if (mimeType === "application/x-www-form-urlencoded" && params) {
|
|
65
65
|
const form = Object.fromEntries(params.map((p) => [p.name, p.value]));
|
|
66
|
-
options.body = new
|
|
66
|
+
options.body = new Raw(`new URLSearchParams(${objectToString(form)})`);
|
|
67
67
|
} else {
|
|
68
68
|
options.body = normalizedRequest.postData.text;
|
|
69
69
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/plugins/node/fetch/fetch.ts"],
|
|
4
|
-
"sourcesContent": ["import {
|
|
5
|
-
"mappings": "
|
|
4
|
+
"sourcesContent": ["import type { Plugin } from '@scalar/types/snippetz'\n\nimport { Raw, objectToString } from '@/libs/javascript'\nimport { createSearchParams } from '@/libs/http'\n\n/**\n * node/fetch\n */\nexport const nodeFetch: Plugin = {\n target: 'node',\n client: 'fetch',\n title: 'Fetch',\n generate(request) {\n // Defaults\n const normalizedRequest = {\n method: 'GET',\n ...request,\n }\n\n let prefix = ''\n\n // Normalization\n normalizedRequest.method = normalizedRequest.method.toUpperCase()\n\n // Reset fetch defaults\n const options: Record<string, any> = {\n method: normalizedRequest.method === 'GET' ? undefined : normalizedRequest.method,\n }\n\n // Query\n const searchParams = createSearchParams(normalizedRequest.queryString)\n const queryString = searchParams.size ? `?${searchParams.toString()}` : ''\n\n // Headers\n if (normalizedRequest.headers?.length) {\n options.headers = {}\n\n normalizedRequest.headers.forEach((header) => {\n options.headers![header.name] = header.value\n })\n }\n\n // Cookies\n if (normalizedRequest.cookies?.length) {\n options.headers = options.headers || {}\n\n normalizedRequest.cookies.forEach((cookie) => {\n options.headers!['Set-Cookie'] = options.headers!['Set-Cookie']\n ? `${options.headers!['Set-Cookie']}; ${cookie.name}=${cookie.value}`\n : `${cookie.name}=${cookie.value}`\n })\n }\n\n // Remove undefined keys\n Object.keys(options).forEach((key) => {\n if (options[key] === undefined) {\n delete options[key]\n }\n })\n\n // Add body\n if (normalizedRequest.postData) {\n const { mimeType, text, params } = normalizedRequest.postData\n let hasFsImport = false\n\n if (mimeType === 'application/json' && text) {\n try {\n options.body = new Raw(`JSON.stringify(${objectToString(JSON.parse(text))})`)\n } catch {\n options.body = text\n }\n } else if (mimeType === 'multipart/form-data' && params) {\n prefix = 'const formData = new FormData()\\n'\n params.forEach((param) => {\n if (param.fileName !== undefined) {\n if (!hasFsImport) {\n prefix = `import fs from 'node:fs'\\n\\n${prefix}`\n hasFsImport = true\n }\n prefix += `formData.append('${param.name}', new Blob([fs.readFileSync('${param.fileName}')]), '${param.fileName}')\\n`\n } else if (param.value !== undefined) {\n prefix += `formData.append('${param.name}', '${param.value}')\\n`\n }\n })\n prefix += '\\n'\n options.body = new Raw('formData')\n } else if (mimeType === 'application/x-www-form-urlencoded' && params) {\n const form = Object.fromEntries(params.map((p) => [p.name, p.value]))\n options.body = new Raw(`new URLSearchParams(${objectToString(form)})`)\n } else {\n options.body = normalizedRequest.postData.text\n }\n }\n\n // Transform to JSON\n const jsonOptions = Object.keys(options).length ? `, ${objectToString(options)}` : ''\n\n // Code Template\n return `${prefix}fetch('${normalizedRequest.url}${queryString}'${jsonOptions})`\n },\n}\n"],
|
|
5
|
+
"mappings": "AAEA,SAAS,KAAK,sBAAsB;AACpC,SAAS,0BAA0B;AAK5B,MAAM,YAAoB;AAAA,EAC/B,QAAQ;AAAA,EACR,QAAQ;AAAA,EACR,OAAO;AAAA,EACP,SAAS,SAAS;AAEhB,UAAM,oBAAoB;AAAA,MACxB,QAAQ;AAAA,MACR,GAAG;AAAA,IACL;AAEA,QAAI,SAAS;AAGb,sBAAkB,SAAS,kBAAkB,OAAO,YAAY;AAGhE,UAAM,UAA+B;AAAA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AA,EAA+B,MAAM;AAC9C,4BAAc;AAAA,YAChB;AACA,sBAAU,oBAAoB,MAAM,IAAI,iCAAiC,MAAM,QAAQ,UAAU,MAAM,QAAQ;AAAA;AAAA,UACjH,WAAW,MAAM,UAAU,QAAW;AACpC,sBAAU,oBAAoB,MAAM,IAAI,OAAO,MAAM,KAAK;AAAA;AAAA,UAC5D;AAAA,QACF,CAAC;AACD,kBAAU;AACV,gBAAQ,OAAO,IAAI,IAAI,UAAU;AAAA,MACnC,WAAW,aAAa,uCAAuC,QAAQ;AACrE,cAAM,OAAO,OAAO,YAAY,OAAO,IAAI,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC;AACpE,gBAAQ,OAAO,IAAI,IAAI,uBAAuB,eAAe,IAAI,CAAC,GAAG;AAAA,MACvE,OAAO;AACL,gBAAQ,OAAO,kBAAkB,SAAS;AAAA,MAC5C;AAAA,IACF;AAGA,UAAM,cAAc,OAAO,KAAK,OAAO,EAAE,SAAS,KAAK,eAAe,OAAO,CAAC,KAAK;AAGnF,WAAO,GAAG,MAAM,UAAU,kBAAkB,GAAG,GAAG,WAAW,IAAI,WAAW;AAAA,EAC9E;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ofetch.d.ts","sourceRoot":"","sources":["../../../../src/plugins/node/ofetch/ofetch.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ofetch.d.ts","sourceRoot":"","sources":["../../../../src/plugins/node/ofetch/ofetch.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAA;AAIpD;;GAEG;AACH,eAAO,MAAM,UAAU,EAAE,MAsExB,CAAA"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/plugins/node/ofetch/ofetch.ts"],
|
|
4
|
-
"sourcesContent": ["import {
|
|
5
|
-
"mappings": "
|
|
4
|
+
"sourcesContent": ["import type { Plugin } from '@scalar/types/snippetz'\n\nimport { objectToString } from '@/libs/javascript'\n\n/**\n * node/ofetch\n */\nexport const nodeOfetch: Plugin = {\n target: 'node',\n client: 'ofetch',\n title: 'ofetch',\n generate(request) {\n // Defaults\n const normalizedRequest = {\n method: 'GET',\n ...request,\n }\n\n // Normalization\n normalizedRequest.method = normalizedRequest.method.toUpperCase()\n\n // Reset fetch defaults\n const options: Record<string, any> = {\n method: normalizedRequest.method === 'GET' ? undefined : normalizedRequest.method,\n }\n\n // Query\n if (normalizedRequest.queryString?.length) {\n options.query = Object.fromEntries(normalizedRequest.queryString.map((q) => [q.name, q.value]))\n }\n\n // Headers\n if (normalizedRequest.headers?.length) {\n options.headers = {}\n\n normalizedRequest.headers.forEach((header) => {\n options.headers![header.name] = header.value\n })\n }\n\n // Cookies\n if (normalizedRequest.cookies?.length) {\n options.headers = options.headers || {}\n\n normalizedRequest.cookies.forEach((cookie) => {\n options.headers!['Set-Cookie'] = options.headers!['Set-Cookie']\n ? `${options.headers!['Set-Cookie']}; ${cookie.name}=${cookie.value}`\n : `${cookie.name}=${cookie.value}`\n })\n }\n\n // Remove undefined keys\n Object.keys(options).forEach((key) => {\n if (options[key] === undefined) {\n delete options[key]\n }\n })\n\n // Add body\n if (normalizedRequest.postData) {\n // Plain text\n options.body = normalizedRequest.postData.text\n\n // JSON\n if (normalizedRequest.postData.mimeType === 'application/json') {\n options.body = JSON.parse(options.body)\n }\n }\n\n // Transform to JSON\n const jsonOptions = Object.keys(options).length ? `, ${objectToString(options)}` : ''\n\n // Code Template\n return `import { ofetch } from 'ofetch'\n\nofetch('${normalizedRequest.url}'${jsonOptions})`\n },\n}\n"],
|
|
5
|
+
"mappings": "AAEA,SAAS,sBAAsB;AAKxB,MAAM,aAAqB;AAAA,EAChC,QAAQ;AAAA,EACR,QAAQ;AAAA,EACR,OAAO;AAAA,EACP,SAAS,SAAS;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K;AAGnF,WAAO;AAAA;AAAA,UAED,kBAAkB,GAAG,IAAI,WAAW;AAAA,EAC5C;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"undici.d.ts","sourceRoot":"","sources":["../../../../src/plugins/node/undici/undici.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"undici.d.ts","sourceRoot":"","sources":["../../../../src/plugins/node/undici/undici.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAA;AAKpD;;GAEG;AACH,eAAO,MAAM,UAAU,EAAE,MAqExB,CAAA"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { Raw, objectToString } from "../../../libs/javascript.js";
|
|
2
|
+
import { createSearchParams } from "../../../libs/http.js";
|
|
3
3
|
const nodeUndici = {
|
|
4
4
|
target: "node",
|
|
5
5
|
client: "undici",
|
|
@@ -35,7 +35,7 @@ const nodeUndici = {
|
|
|
35
35
|
if (normalizedRequest.postData) {
|
|
36
36
|
options.body = normalizedRequest.postData.text;
|
|
37
37
|
if (normalizedRequest.postData.mimeType === "application/json") {
|
|
38
|
-
options.body = new
|
|
38
|
+
options.body = new Raw(`JSON.stringify(${objectToString(JSON.parse(options.body))})`);
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
41
|
const jsonOptions = Object.keys(options).length ? `, ${objectToString(options)}` : "";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/plugins/node/undici/undici.ts"],
|
|
4
|
-
"sourcesContent": ["import {
|
|
5
|
-
"mappings": "
|
|
4
|
+
"sourcesContent": ["import type { Plugin } from '@scalar/types/snippetz'\n\nimport { Raw, objectToString } from '@/libs/javascript'\nimport { createSearchParams } from '@/libs/http'\n\n/**\n * node/undici\n */\nexport const nodeUndici: Plugin = {\n target: 'node',\n client: 'undici',\n title: 'undici',\n generate(request) {\n // Defaults\n const normalizedRequest = {\n method: 'GET',\n ...request,\n }\n\n // Normalization\n normalizedRequest.method = normalizedRequest.method.toUpperCase()\n\n // Reset undici defaults\n const options: Record<string, any> = {\n method: normalizedRequest.method === 'GET' ? undefined : normalizedRequest.method,\n }\n\n // Query\n const searchParams = createSearchParams(normalizedRequest.queryString)\n const queryString = searchParams.size ? `?${searchParams.toString()}` : ''\n\n // Headers\n if (normalizedRequest.headers?.length) {\n options.headers = {}\n\n normalizedRequest.headers.forEach((header) => {\n options.headers![header.name] = header.value\n })\n }\n\n // Cookies\n if (normalizedRequest.cookies?.length) {\n options.headers = options.headers || {}\n\n normalizedRequest.cookies.forEach((cookie) => {\n options.headers!['Set-Cookie'] = options.headers!['Set-Cookie']\n ? `${options.headers!['Set-Cookie']}; ${cookie.name}=${cookie.value}`\n : `${cookie.name}=${cookie.value}`\n })\n }\n\n // Remove undefined keys\n Object.keys(options).forEach((key) => {\n if (options[key] === undefined) {\n delete options[key]\n }\n })\n\n // Add body\n if (normalizedRequest.postData) {\n // Plain text\n options.body = normalizedRequest.postData.text\n\n // JSON\n if (normalizedRequest.postData.mimeType === 'application/json') {\n options.body = new Raw(`JSON.stringify(${objectToString(JSON.parse(options.body))})`)\n }\n }\n\n // Transform to JSON\n const jsonOptions = Object.keys(options).length ? `, ${objectToString(options)}` : ''\n\n // Code Template\n return `import { request } from 'undici'\n\nconst { statusCode, body } = await request('${normalizedRequest.url}${queryString}'${jsonOptions})`\n },\n}\n"],
|
|
5
|
+
"mappings": "AAEA,SAAS,KAAK,sBAAsB;AACpC,SAAS,0BAA0B;AAK5B,MAAM,aAAqB;AAAA,EAChC,QAAQ;AAAA,EACR,QAAQ;AAAA,EACR,OAAO;AAAA,EACP,SAAS,SAAS;AAEhB,UAAM,oBAAoB;AAAA,MACxB,QAAQ;AAAA,MACR,GAAG;AAAA,IACL;AAGA,sBAAkB,SAAS,kBA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
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"curl.d.ts","sourceRoot":"","sources":["../../../../src/plugins/php/curl/curl.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAA;
|
|
1
|
+
{"version":3,"file":"curl.d.ts","sourceRoot":"","sources":["../../../../src/plugins/php/curl/curl.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAA;AAIpD;;GAEG;AACH,eAAO,MAAM,OAAO,EAAE,MAkIrB,CAAA"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { objectToString } from "../../../libs/php.js";
|
|
1
2
|
const phpCurl = {
|
|
2
3
|
target: "php",
|
|
3
4
|
client: "curl",
|
|
@@ -44,7 +45,7 @@ const phpCurl = {
|
|
|
44
45
|
if (normalizedRequest.postData.text) {
|
|
45
46
|
try {
|
|
46
47
|
const jsonData = JSON.parse(normalizedRequest.postData.text);
|
|
47
|
-
const phpArray =
|
|
48
|
+
const phpArray = objectToString(jsonData);
|
|
48
49
|
parts.push(`curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode(${phpArray}));`);
|
|
49
50
|
} catch {
|
|
50
51
|
parts.push(`curl_setopt($ch, CURLOPT_POSTFIELDS, '${normalizedRequest.postData.text}');`);
|
|
@@ -75,7 +76,7 @@ const phpCurl = {
|
|
|
75
76
|
} else if (normalizedRequest.postData.text) {
|
|
76
77
|
try {
|
|
77
78
|
const jsonData = JSON.parse(normalizedRequest.postData.text);
|
|
78
|
-
const phpArray =
|
|
79
|
+
const phpArray = objectToString(jsonData);
|
|
79
80
|
parts.push(`curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode(${phpArray}));`);
|
|
80
81
|
} catch {
|
|
81
82
|
parts.push(`curl_setopt($ch, CURLOPT_POSTFIELDS, '${normalizedRequest.postData.text}');`);
|
|
@@ -89,40 +90,6 @@ const phpCurl = {
|
|
|
89
90
|
return parts.join("\n").replace(/\n\n\n/g, "\n\n");
|
|
90
91
|
}
|
|
91
92
|
};
|
|
92
|
-
function indent(level) {
|
|
93
|
-
return " ".repeat(level * 2);
|
|
94
|
-
}
|
|
95
|
-
function convertToPhpArray(data, indentLevel = 0) {
|
|
96
|
-
if (data === null || data === void 0) {
|
|
97
|
-
return "null";
|
|
98
|
-
}
|
|
99
|
-
if (typeof data === "string") {
|
|
100
|
-
return `'${data.replace(/'/g, "\\'")}'`;
|
|
101
|
-
}
|
|
102
|
-
if (typeof data === "number" || typeof data === "boolean") {
|
|
103
|
-
return String(data);
|
|
104
|
-
}
|
|
105
|
-
if (Array.isArray(data)) {
|
|
106
|
-
if (data.length === 0) {
|
|
107
|
-
return "[]";
|
|
108
|
-
}
|
|
109
|
-
const items = data.map((item) => convertToPhpArray(item, indentLevel + 1)).join(",\n" + indent(indentLevel + 1));
|
|
110
|
-
return `[
|
|
111
|
-
${indent(indentLevel + 1)}${items}
|
|
112
|
-
${indent(indentLevel)}]`;
|
|
113
|
-
}
|
|
114
|
-
if (typeof data === "object") {
|
|
115
|
-
const entries = Object.entries(data);
|
|
116
|
-
if (entries.length === 0) {
|
|
117
|
-
return "[]";
|
|
118
|
-
}
|
|
119
|
-
const items = entries.map(([key, value]) => `'${key}' => ${convertToPhpArray(value, indentLevel + 1)}`).join(",\n" + indent(indentLevel + 1));
|
|
120
|
-
return `[
|
|
121
|
-
${indent(indentLevel + 1)}${items}
|
|
122
|
-
${indent(indentLevel)}]`;
|
|
123
|
-
}
|
|
124
|
-
return "null";
|
|
125
|
-
}
|
|
126
93
|
export {
|
|
127
94
|
phpCurl
|
|
128
95
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/plugins/php/curl/curl.ts"],
|
|
4
|
-
"sourcesContent": ["import type { Plugin } from '@scalar/types/snippetz'\n\n/**\n * php/curl\n */\nexport const phpCurl: Plugin = {\n target: 'php',\n client: 'curl',\n title: 'cURL',\n generate(request, configuration) {\n // Defaults\n const normalizedRequest = {\n method: 'GET',\n ...request,\n }\n\n // Normalization\n normalizedRequest.method = normalizedRequest.method.toUpperCase()\n\n // Build PHP cURL code parts\n const parts: string[] = []\n\n // Initialize cURL\n // URL (with query parameters)\n const queryString = normalizedRequest.queryString?.length\n ? '?' +\n normalizedRequest.queryString\n .map((param) => {\n const encodedName = encodeURIComponent(param.name)\n const encodedValue = encodeURIComponent(param.value)\n return `${encodedName}=${encodedValue}`\n })\n .join('&')\n : ''\n const url = `${normalizedRequest.url}${queryString}`\n parts.push(`$ch = curl_init(\"${url}\");`)\n parts.push('')\n\n // Method\n if (normalizedRequest.method === 'POST') {\n parts.push('curl_setopt($ch, CURLOPT_POST, true);')\n }\n\n // Basic Auth\n if (configuration?.auth?.username && configuration?.auth?.password) {\n parts.push(`curl_setopt($ch, CURLOPT_USERPWD, '${configuration.auth.username}:${configuration.auth.password}');`)\n }\n\n // Headers\n if (normalizedRequest.headers?.length) {\n const headerStrings = normalizedRequest.headers.map((header) => `'${header.name}: ${header.value}'`)\n parts.push(`curl_setopt($ch, CURLOPT_HTTPHEADER, [${headerStrings.join(', ')}]);`)\n\n // Add encoding option if Accept-Encoding header includes compression\n const acceptEncoding = normalizedRequest.headers.find((header) => header.name.toLowerCase() === 'accept-encoding')\n if (acceptEncoding && /gzip|deflate/.test(acceptEncoding.value)) {\n parts.push(\"curl_setopt($ch, CURLOPT_ENCODING, '');\")\n }\n }\n\n // Cookies\n if (normalizedRequest.cookies?.length) {\n const cookieString = normalizedRequest.cookies\n .map((cookie) => {\n const encodedName = encodeURIComponent(cookie.name)\n const encodedValue = encodeURIComponent(cookie.value)\n return `${encodedName}=${encodedValue}`\n })\n .join('; ')\n parts.push(`curl_setopt($ch, CURLOPT_COOKIE, '${cookieString}');`)\n }\n\n // Body\n if (normalizedRequest.postData) {\n if (normalizedRequest.postData.mimeType === 'application/json') {\n // Convert JSON to PHP array syntax\n if (normalizedRequest.postData.text) {\n try {\n const jsonData = JSON.parse(normalizedRequest.postData.text)\n const phpArray =
|
|
5
|
-
"mappings": "
|
|
4
|
+
"sourcesContent": ["import type { Plugin } from '@scalar/types/snippetz'\n\nimport { objectToString } from '@/libs/php'\n\n/**\n * php/curl\n */\nexport const phpCurl: Plugin = {\n target: 'php',\n client: 'curl',\n title: 'cURL',\n generate(request, configuration) {\n // Defaults\n const normalizedRequest = {\n method: 'GET',\n ...request,\n }\n\n // Normalization\n normalizedRequest.method = normalizedRequest.method.toUpperCase()\n\n // Build PHP cURL code parts\n const parts: string[] = []\n\n // Initialize cURL\n // URL (with query parameters)\n const queryString = normalizedRequest.queryString?.length\n ? '?' +\n normalizedRequest.queryString\n .map((param) => {\n const encodedName = encodeURIComponent(param.name)\n const encodedValue = encodeURIComponent(param.value)\n return `${encodedName}=${encodedValue}`\n })\n .join('&')\n : ''\n const url = `${normalizedRequest.url}${queryString}`\n parts.push(`$ch = curl_init(\"${url}\");`)\n parts.push('')\n\n // Method\n if (normalizedRequest.method === 'POST') {\n parts.push('curl_setopt($ch, CURLOPT_POST, true);')\n }\n\n // Basic Auth\n if (configuration?.auth?.username && configuration?.auth?.password) {\n parts.push(`curl_setopt($ch, CURLOPT_USERPWD, '${configuration.auth.username}:${configuration.auth.password}');`)\n }\n\n // Headers\n if (normalizedRequest.headers?.length) {\n const headerStrings = normalizedRequest.headers.map((header) => `'${header.name}: ${header.value}'`)\n parts.push(`curl_setopt($ch, CURLOPT_HTTPHEADER, [${headerStrings.join(', ')}]);`)\n\n // Add encoding option if Accept-Encoding header includes compression\n const acceptEncoding = normalizedRequest.headers.find((header) => header.name.toLowerCase() === 'accept-encoding')\n if (acceptEncoding && /gzip|deflate/.test(acceptEncoding.value)) {\n parts.push(\"curl_setopt($ch, CURLOPT_ENCODING, '');\")\n }\n }\n\n // Cookies\n if (normalizedRequest.cookies?.length) {\n const cookieString = normalizedRequest.cookies\n .map((cookie) => {\n const encodedName = encodeURIComponent(cookie.name)\n const encodedValue = encodeURIComponent(cookie.value)\n return `${encodedName}=${encodedValue}`\n })\n .join('; ')\n parts.push(`curl_setopt($ch, CURLOPT_COOKIE, '${cookieString}');`)\n }\n\n // Body\n if (normalizedRequest.postData) {\n if (normalizedRequest.postData.mimeType === 'application/json') {\n // Convert JSON to PHP array syntax\n if (normalizedRequest.postData.text) {\n try {\n const jsonData = JSON.parse(normalizedRequest.postData.text)\n const phpArray = objectToString(jsonData)\n parts.push(`curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode(${phpArray}));`)\n } catch {\n parts.push(`curl_setopt($ch, CURLOPT_POSTFIELDS, '${normalizedRequest.postData.text}');`)\n }\n }\n } else if (normalizedRequest.postData.mimeType === 'multipart/form-data' && normalizedRequest.postData.params) {\n // Handle multipart form data\n const formData = normalizedRequest.postData.params.reduce((acc, param) => {\n if (param.fileName !== undefined) {\n acc.push(`'${param.name}' => '@${param.fileName}'`)\n } else if (param.value !== undefined) {\n acc.push(`'${param.name}' => '${param.value}'`)\n }\n return acc\n }, [] as string[])\n\n parts.push(`curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: multipart/form-data']);`)\n parts.push(`curl_setopt($ch, CURLOPT_POSTFIELDS, [${formData.join(', ')}]);`)\n } else if (\n normalizedRequest.postData.mimeType === 'application/x-www-form-urlencoded' &&\n normalizedRequest.postData.params\n ) {\n // Handle URL-encoded form data\n const formData = normalizedRequest.postData.params\n .map((param) => {\n const encodedName = encodeURIComponent(param.name)\n const encodedValue = param.value ? encodeURIComponent(param.value) : ''\n return `${encodedName}=${encodedValue}`\n })\n .join('&')\n parts.push(`curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/x-www-form-urlencoded']);`)\n parts.push(`curl_setopt($ch, CURLOPT_POSTFIELDS, '${formData}');`)\n } else if (normalizedRequest.postData.mimeType === 'application/octet-stream') {\n parts.push(`curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/octet-stream']);`)\n parts.push(`curl_setopt($ch, CURLOPT_POSTFIELDS, '${normalizedRequest.postData.text || ''}');`)\n } else if (normalizedRequest.postData.text) {\n // Try to parse as JSON and convert to PHP array, otherwise use raw text\n try {\n const jsonData = JSON.parse(normalizedRequest.postData.text)\n const phpArray = objectToString(jsonData)\n parts.push(`curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode(${phpArray}));`)\n } catch {\n parts.push(`curl_setopt($ch, CURLOPT_POSTFIELDS, '${normalizedRequest.postData.text}');`)\n }\n }\n }\n\n // Execute and close\n parts.push('')\n parts.push('curl_exec($ch);')\n parts.push('')\n parts.push('curl_close($ch);')\n\n return parts.join('\\n').replace(/\\n\\n\\n/g, '\\n\\n')\n },\n}\n"],
|
|
5
|
+
"mappings": "AAEA,SAAS,sBAAsB;AAKxB,MAAM,UAAkB;AAAA,EAC7B,QAAQ;AAAA,EACR,QAAQ;AAAA,EACR,OAAO;AAAA,EACP,SAAS,SAAS,eAAe;AAE/B,UAAM,oBAAoB;AAAA,MACxB,QAAQ;AAAA,MACR,GAAG;AAAA,IACL;AAGA,sBAAkB,SAAS,kBAAkB,OAAO,YAAY;AAGhE,UAAM,QAAkB,CAAC;AAIzB,UAAM,cAAc,kBAAkB,aAAa,SAC/C,MACA,kBAAkB,YACf,IAAI,CAAC,UAAU;AACd,YAAM,cAAc,mBAAmB,MAAM,IAAI;AACjD,YAAM,eAAe,mBAAmB,MAAM,KAAK;AACnD,aAAO,GAAG,WAAW,IAAI,YAAY;AAAA,IACvC,CAAC,EACA,KAAK,GAAG,IACX;AACJ,UAAM,MAAM,GAAG,kBAAkB,GAAG,GAAG,WAAW;AAClD,UAAM,KAAK,oBAAoB,GAAG,KAAK;AACvC,UAAM,KAAK,EAAE;AAGb,QAAI,kBAAkB,WAAW,QAAQ;AACvC,YAAM,KAAK,uCAAuC;AAAA,IACpD;AAGA,QAAI,eAAe,MAAM,YAAY,eAAe,MAAM,UAAU;AAClE,YAAM,KAA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AA,EACnD;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"guzzle.d.ts","sourceRoot":"","sources":["../../../../src/plugins/php/guzzle/guzzle.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAA;
|
|
1
|
+
{"version":3,"file":"guzzle.d.ts","sourceRoot":"","sources":["../../../../src/plugins/php/guzzle/guzzle.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAA;AAIpD;;GAEG;AACH,eAAO,MAAM,SAAS,EAAE,MA6GvB,CAAA"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Raw, objectToString } from "../../../libs/php.js";
|
|
1
2
|
const phpGuzzle = {
|
|
2
3
|
target: "php",
|
|
3
4
|
client: "guzzle",
|
|
@@ -43,19 +44,19 @@ const phpGuzzle = {
|
|
|
43
44
|
if (request.postData.mimeType === "application/json") {
|
|
44
45
|
try {
|
|
45
46
|
options.json = JSON.parse(request.postData.text || "{}");
|
|
46
|
-
} catch (
|
|
47
|
+
} catch (_e) {
|
|
47
48
|
options.body = request.postData.text;
|
|
48
49
|
}
|
|
49
50
|
} else if (request.postData.mimeType === "multipart/form-data") {
|
|
50
51
|
if (request.postData.params) {
|
|
51
52
|
options.multipart = request.postData.params.map((param) => ({
|
|
52
53
|
name: param.name,
|
|
53
|
-
contents: param.fileName ? `fopen('${param.fileName}', 'r')` : param.value || ""
|
|
54
|
+
contents: param.fileName ? new Raw(`fopen('${param.fileName}', 'r')`) : param.value || ""
|
|
54
55
|
}));
|
|
55
56
|
} else if (request.postData.text) {
|
|
56
57
|
try {
|
|
57
58
|
options.form_params = JSON.parse(request.postData.text);
|
|
58
|
-
} catch (
|
|
59
|
+
} catch (_e) {
|
|
59
60
|
options.body = request.postData.text;
|
|
60
61
|
}
|
|
61
62
|
}
|
|
@@ -76,7 +77,7 @@ const phpGuzzle = {
|
|
|
76
77
|
}
|
|
77
78
|
let code = "$client = new GuzzleHttp\\Client();\n\n";
|
|
78
79
|
if (Object.keys(options).length > 0) {
|
|
79
|
-
const formattedOptions =
|
|
80
|
+
const formattedOptions = objectToString(options);
|
|
80
81
|
code += `$response = $client->request('${method}', '${url}', ${formattedOptions});`;
|
|
81
82
|
} else {
|
|
82
83
|
code += `$response = $client->request('${method}', '${url}');`;
|
|
@@ -84,41 +85,6 @@ const phpGuzzle = {
|
|
|
84
85
|
return code;
|
|
85
86
|
}
|
|
86
87
|
};
|
|
87
|
-
function formatOptionsArray(options, indent = 0) {
|
|
88
|
-
if (Object.keys(options).length === 0) return "[]";
|
|
89
|
-
const spaces = " ".repeat(4);
|
|
90
|
-
let result = "[\n";
|
|
91
|
-
for (const [key, value] of Object.entries(options)) {
|
|
92
|
-
const formattedValue = formatValue(value, indent + 1);
|
|
93
|
-
result += `${spaces.repeat(indent + 1)}'${key}' => ${formattedValue},
|
|
94
|
-
`;
|
|
95
|
-
}
|
|
96
|
-
result += `${spaces.repeat(indent)}]`;
|
|
97
|
-
return result;
|
|
98
|
-
}
|
|
99
|
-
function formatValue(value, indent) {
|
|
100
|
-
if (value === null) return "null";
|
|
101
|
-
if (typeof value === "boolean") return value ? "true" : "false";
|
|
102
|
-
if (typeof value === "string" && value.startsWith("fopen(")) return value;
|
|
103
|
-
if (typeof value === "string") return `'${value}'`;
|
|
104
|
-
if (typeof value === "number") return value.toString();
|
|
105
|
-
if (Array.isArray(value)) {
|
|
106
|
-
if (value.length === 0) return "[]";
|
|
107
|
-
const spaces = " ".repeat(4);
|
|
108
|
-
let result = "[\n";
|
|
109
|
-
value.forEach((item) => {
|
|
110
|
-
const formattedItem = formatValue(item, indent + 1);
|
|
111
|
-
result += `${spaces.repeat(indent + 1)}${formattedItem},
|
|
112
|
-
`;
|
|
113
|
-
});
|
|
114
|
-
result += `${spaces.repeat(indent)}]`;
|
|
115
|
-
return result;
|
|
116
|
-
}
|
|
117
|
-
if (typeof value === "object") {
|
|
118
|
-
return formatOptionsArray(value, indent);
|
|
119
|
-
}
|
|
120
|
-
return `'${value}'`;
|
|
121
|
-
}
|
|
122
88
|
export {
|
|
123
89
|
phpGuzzle
|
|
124
90
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/plugins/php/guzzle/guzzle.ts"],
|
|
4
|
-
"sourcesContent": ["import type { Plugin } from '@scalar/types/snippetz'\n\n/**\n * php/guzzle\n */\nexport const phpGuzzle: Plugin = {\n target: 'php',\n client: 'guzzle',\n title: 'Guzzle',\n generate(request, configuration) {\n if (!request) {\n return ''\n }\n\n const options: Record<string, any> = {}\n const method = (request.method || 'GET').toUpperCase()\n const url = request.url || ''\n\n // Handle headers\n if (request.headers && Array.isArray(request.headers) && request.headers.length > 0) {\n const headers: Record<string, any> = {}\n request.headers.forEach((header) => {\n if (headers[header.name] === undefined) {\n headers[header.name] = header.value\n } else if (Array.isArray(headers[header.name])) {\n headers[header.name].push(header.value)\n } else {\n headers[header.name] = [headers[header.name], header.value]\n }\n })\n options.headers = headers\n }\n\n // Handle query parameters\n if (request.queryString && request.queryString.length > 0) {\n const query: Record<string, string> = {}\n request.queryString.forEach((param) => {\n query[param.name] = param.value\n })\n options.query = query\n }\n\n // Handle cookies\n if (request.cookies && request.cookies.length > 0) {\n const cookies: Record<string, string> = {}\n request.cookies.forEach((cookie) => {\n cookies[cookie.name] = cookie.value\n })\n options.cookies = cookies\n }\n\n // Handle authentication\n if (configuration?.auth?.username && configuration.auth.password) {\n options.auth = [configuration.auth.username, configuration.auth.password]\n }\n\n // Handle request body\n if (request.postData) {\n if (request.postData.mimeType === 'application/json') {\n try {\n options.json = JSON.parse(request.postData.text || '{}')\n } catch (
|
|
5
|
-
"mappings": "
|
|
4
|
+
"sourcesContent": ["import type { Plugin } from '@scalar/types/snippetz'\n\nimport { Raw, objectToString } from '@/libs/php'\n\n/**\n * php/guzzle\n */\nexport const phpGuzzle: Plugin = {\n target: 'php',\n client: 'guzzle',\n title: 'Guzzle',\n generate(request, configuration) {\n if (!request) {\n return ''\n }\n\n const options: Record<string, any> = {}\n const method = (request.method || 'GET').toUpperCase()\n const url = request.url || ''\n\n // Handle headers\n if (request.headers && Array.isArray(request.headers) && request.headers.length > 0) {\n const headers: Record<string, any> = {}\n request.headers.forEach((header) => {\n if (headers[header.name] === undefined) {\n headers[header.name] = header.value\n } else if (Array.isArray(headers[header.name])) {\n headers[header.name].push(header.value)\n } else {\n headers[header.name] = [headers[header.name], header.value]\n }\n })\n options.headers = headers\n }\n\n // Handle query parameters\n if (request.queryString && request.queryString.length > 0) {\n const query: Record<string, string> = {}\n request.queryString.forEach((param) => {\n query[param.name] = param.value\n })\n options.query = query\n }\n\n // Handle cookies\n if (request.cookies && request.cookies.length > 0) {\n const cookies: Record<string, string> = {}\n request.cookies.forEach((cookie) => {\n cookies[cookie.name] = cookie.value\n })\n options.cookies = cookies\n }\n\n // Handle authentication\n if (configuration?.auth?.username && configuration.auth.password) {\n options.auth = [configuration.auth.username, configuration.auth.password]\n }\n\n // Handle request body\n if (request.postData) {\n if (request.postData.mimeType === 'application/json') {\n try {\n options.json = JSON.parse(request.postData.text || '{}')\n } catch (_e) {\n // If JSON parsing fails, use the raw text\n options.body = request.postData.text\n }\n } else if (request.postData.mimeType === 'multipart/form-data') {\n if (request.postData.params) {\n options.multipart = request.postData.params.map((param) => ({\n name: param.name,\n contents: param.fileName ? new Raw(`fopen('${param.fileName}', 'r')`) : param.value || '',\n }))\n } else if (request.postData.text) {\n try {\n options.form_params = JSON.parse(request.postData.text)\n } catch (_e) {\n options.body = request.postData.text\n }\n }\n } else if (request.postData.mimeType === 'application/x-www-form-urlencoded') {\n if (request.postData.params) {\n const formParams: Record<string, string> = {}\n request.postData.params.forEach((param) => {\n formParams[param.name] = param.value || ''\n })\n options.form_params = formParams\n }\n } else {\n // For other mime types (like application/octet-stream), use the raw body\n options.body = request.postData.text\n }\n }\n\n // Handle compressed responses\n if (\n request.headers &&\n Array.isArray(request.headers) &&\n request.headers.some((h) => h.name === 'Accept-Encoding' && h.value.includes('gzip'))\n ) {\n options.decode_content = true\n }\n\n // Generate the PHP code\n let code = '$client = new GuzzleHttp\\\\Client();\\n\\n'\n\n if (Object.keys(options).length > 0) {\n // Format the options array with proper indentation\n const formattedOptions = objectToString(options)\n code += `$response = $client->request('${method}', '${url}', ${formattedOptions});`\n } else {\n code += `$response = $client->request('${method}', '${url}');`\n }\n\n return code\n },\n}\n"],
|
|
5
|
+
"mappings": "AAEA,SAAS,KAAK,sBAAsB;AAK7B,MAAM,YAAoB;AAAA,EAC/B,QAAQ;AAAA,EACR,QAAQ;AAAA,EACR,OAAO;AAAA,EACP,SAAS,SAAS,eAAe;AAC/B,QAAI,CAAC,SAAS;AACZ,aAAO;AAAA,IACT;AAEA,UAAM,UAA+B,CAAC;AACtC,UAAM,UAAU,QAAQ,UAAU,OAAO,YAAY;AACrD,UAAM,MAAM,QAAQ,OAAO;AAG3B,QAAI,QAAQ,WAAW,MAAM,QAAQ,QAAQ,OAAO,KAAK,QAAQ,QAAQ,SAAS,GAAG;AACnF,YAAM,UAA+B,CAAC;AACtC,cAAQ,QAAQ,QAAQ,CAAC,WAAW;AAClC,YAAI,QAAQ,OAAO,IAAI,MAAM,QAAW;AACtC,kBAAQ,OAAO,IAAI,IAAI,OAAO;AAAA,QAChC,WAAW,MAAM,QAAQ,QAAQ,OAAO,IAAI,CAAC,GAAG;AAC9C,kBAAQ,OAAO,IAAI,EAAE,KAAK,OAAO,KAAK;AAAA,QACxC,OAAO;AACL,kBAAQ,OAAO,IAAI,IAAI,CAAC,QAAQ,OAAO,IAAI,GAAG,OAAO,KAAK;AAAA,QAC5D;AAAA,MACF,CAAC;AACD,cAAQ,UAAU;AAAA,IACpB;AAGA,QAAI,QAAQ,eAAe,QAAQ,YAAY,SAAS,GAAG;AACzD,YAAM,QAAgC,CAA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OAAO,QAAQ,CAAC,UAAU;AACzC,uBAAW,MAAM,IAAI,IAAI,MAAM,SAAS;AAAA,UAC1C,CAAC;AACD,kBAAQ,cAAc;AAAA,QACxB;AAAA,MACF,OAAO;AAEL,gBAAQ,OAAO,QAAQ,SAAS;AAAA,MAClC;AAAA,IACF;AAGA,QACE,QAAQ,WACR,MAAM,QAAQ,QAAQ,OAAO,KAC7B,QAAQ,QAAQ,KAAK,CAAC,MAAM,EAAE,SAAS,qBAAqB,EAAE,MAAM,SAAS,MAAM,CAAC,GACpF;AACA,cAAQ,iBAAiB;AAAA,IAC3B;AAGA,QAAI,OAAO;AAEX,QAAI,OAAO,KAAK,OAAO,EAAE,SAAS,GAAG;AAEnC,YAAM,mBAAmB,eAAe,OAAO;AAC/C,cAAQ,iCAAiC,MAAM,OAAO,GAAG,MAAM,gBAAgB;AAAA,IACjF,OAAO;AACL,cAAQ,iCAAiC,MAAM,OAAO,GAAG;AAAA,IAC3D;AAEA,WAAO;AAAA,EACT;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reqwest.d.ts","sourceRoot":"","sources":["../../../../src/plugins/rust/reqwest/reqwest.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAA;
|
|
1
|
+
{"version":3,"file":"reqwest.d.ts","sourceRoot":"","sources":["../../../../src/plugins/rust/reqwest/reqwest.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAA;AAKpD;;GAEG;AACH,eAAO,MAAM,WAAW,EAAE,MAwCzB,CAAA"}
|