@scalar/snippetz 0.6.15 → 0.6.17
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.
|
@@ -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;AAIpD;;GAEG;AACH,eAAO,MAAM,OAAO,EAAE,
|
|
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,MAyJrB,CAAA"}
|
|
@@ -24,10 +24,21 @@ const phpCurl = {
|
|
|
24
24
|
if (configuration?.auth?.username && configuration?.auth?.password) {
|
|
25
25
|
parts.push(`curl_setopt($ch, CURLOPT_USERPWD, '${configuration.auth.username}:${configuration.auth.password}');`);
|
|
26
26
|
}
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
const allHeaders = [...normalizedRequest.headers || []];
|
|
28
|
+
const hasContentType = () => allHeaders.some((h) => h.name.toLowerCase() === "content-type");
|
|
29
|
+
if (normalizedRequest.postData) {
|
|
30
|
+
if (normalizedRequest.postData.mimeType === "multipart/form-data" && normalizedRequest.postData.params && !hasContentType()) {
|
|
31
|
+
allHeaders.push({ name: "Content-Type", value: "multipart/form-data" });
|
|
32
|
+
} else if (normalizedRequest.postData.mimeType === "application/x-www-form-urlencoded" && normalizedRequest.postData.params && !hasContentType()) {
|
|
33
|
+
allHeaders.push({ name: "Content-Type", value: "application/x-www-form-urlencoded" });
|
|
34
|
+
} else if (normalizedRequest.postData.mimeType === "application/octet-stream" && !hasContentType()) {
|
|
35
|
+
allHeaders.push({ name: "Content-Type", value: "application/octet-stream" });
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
if (allHeaders.length) {
|
|
39
|
+
const headerStrings = allHeaders.map((header) => `'${header.name}: ${header.value}'`);
|
|
29
40
|
parts.push(`curl_setopt($ch, CURLOPT_HTTPHEADER, [${headerStrings.join(", ")}]);`);
|
|
30
|
-
const acceptEncoding =
|
|
41
|
+
const acceptEncoding = allHeaders.find((header) => header.name.toLowerCase() === "accept-encoding");
|
|
31
42
|
if (acceptEncoding && /gzip|deflate/.test(acceptEncoding.value)) {
|
|
32
43
|
parts.push("curl_setopt($ch, CURLOPT_ENCODING, '');");
|
|
33
44
|
}
|
|
@@ -60,7 +71,6 @@ const phpCurl = {
|
|
|
60
71
|
}
|
|
61
72
|
return acc;
|
|
62
73
|
}, []);
|
|
63
|
-
parts.push(`curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: multipart/form-data']);`);
|
|
64
74
|
parts.push(`curl_setopt($ch, CURLOPT_POSTFIELDS, [${formData.join(", ")}]);`);
|
|
65
75
|
} else if (normalizedRequest.postData.mimeType === "application/x-www-form-urlencoded" && normalizedRequest.postData.params) {
|
|
66
76
|
const formData = normalizedRequest.postData.params.map((param) => {
|
|
@@ -68,10 +78,8 @@ const phpCurl = {
|
|
|
68
78
|
const encodedValue = param.value ? encodeURIComponent(param.value) : "";
|
|
69
79
|
return `${encodedName}=${encodedValue}`;
|
|
70
80
|
}).join("&");
|
|
71
|
-
parts.push(`curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/x-www-form-urlencoded']);`);
|
|
72
81
|
parts.push(`curl_setopt($ch, CURLOPT_POSTFIELDS, '${formData}');`);
|
|
73
82
|
} else if (normalizedRequest.postData.mimeType === "application/octet-stream") {
|
|
74
|
-
parts.push(`curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/octet-stream']);`);
|
|
75
83
|
parts.push(`curl_setopt($ch, CURLOPT_POSTFIELDS, '${normalizedRequest.postData.text || ""}');`);
|
|
76
84
|
} else if (normalizedRequest.postData.text) {
|
|
77
85
|
try {
|
|
@@ -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\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 //
|
|
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,KAAK,sCAAsC,cAAc,KAAK,QAAQ,IAAI,cAAc,KAAK,QAAQ,KAAK;AAAA,IAClH;
|
|
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 // Collect all headers to emit once, avoiding duplicate CURLOPT_HTTPHEADER calls.\n // Body processing may add a Content-Type header, so we determine it first.\n const allHeaders: Array<{ name: string; value: string }> = [...(normalizedRequest.headers || [])]\n\n // Helper to add Content-Type header if not already present\n const hasContentType = () => allHeaders.some((h) => h.name.toLowerCase() === 'content-type')\n\n // Determine Content-Type from body before emitting headers\n if (normalizedRequest.postData) {\n if (\n normalizedRequest.postData.mimeType === 'multipart/form-data' &&\n normalizedRequest.postData.params &&\n !hasContentType()\n ) {\n allHeaders.push({ name: 'Content-Type', value: 'multipart/form-data' })\n } else if (\n normalizedRequest.postData.mimeType === 'application/x-www-form-urlencoded' &&\n normalizedRequest.postData.params &&\n !hasContentType()\n ) {\n allHeaders.push({ name: 'Content-Type', value: 'application/x-www-form-urlencoded' })\n } else if (normalizedRequest.postData.mimeType === 'application/octet-stream' && !hasContentType()) {\n allHeaders.push({ name: 'Content-Type', value: 'application/octet-stream' })\n }\n }\n\n // Emit all headers once\n if (allHeaders.length) {\n const headerStrings = allHeaders.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 = allHeaders.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_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_POSTFIELDS, '${formData}');`)\n } else if (normalizedRequest.postData.mimeType === '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": "AAE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D;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"url": "git+https://github.com/scalar/scalar.git",
|
|
10
10
|
"directory": "packages/snippetz"
|
|
11
11
|
},
|
|
12
|
-
"version": "0.6.
|
|
12
|
+
"version": "0.6.17",
|
|
13
13
|
"engines": {
|
|
14
14
|
"node": ">=20"
|
|
15
15
|
},
|
|
@@ -230,7 +230,7 @@
|
|
|
230
230
|
"dependencies": {
|
|
231
231
|
"js-base64": "^3.7.8",
|
|
232
232
|
"stringify-object": "^6.0.0",
|
|
233
|
-
"@scalar/types": "0.6.
|
|
233
|
+
"@scalar/types": "0.6.8"
|
|
234
234
|
},
|
|
235
235
|
"devDependencies": {
|
|
236
236
|
"@types/stringify-object": "^4.0.5",
|