@scalar/snippetz 0.9.6 → 0.9.9
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,MAiKrB,CAAA"}
|
|
@@ -34,6 +34,9 @@ export const phpCurl = {
|
|
|
34
34
|
if (normalizedRequest.method === 'POST') {
|
|
35
35
|
parts.push('curl_setopt($ch, CURLOPT_POST, true);');
|
|
36
36
|
}
|
|
37
|
+
else if (normalizedRequest.method !== 'GET') {
|
|
38
|
+
parts.push(`curl_setopt($ch, CURLOPT_CUSTOMREQUEST, '${normalizedRequest.method}');`);
|
|
39
|
+
}
|
|
37
40
|
// Basic Auth
|
|
38
41
|
if (configuration?.auth?.username && configuration?.auth?.password) {
|
|
39
42
|
parts.push(`curl_setopt($ch, CURLOPT_USERPWD, '${configuration.auth.username}:${configuration.auth.password}');`);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"curl.d.ts","sourceRoot":"","sources":["../../../../src/plugins/shell/curl/curl.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"curl.d.ts","sourceRoot":"","sources":["../../../../src/plugins/shell/curl/curl.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAA;AAiBpD;;GAEG;AACH,eAAO,MAAM,SAAS,EAAE,MA8IvB,CAAA"}
|
|
@@ -1,4 +1,17 @@
|
|
|
1
|
+
import { parseMimeType } from '@scalar/helpers/http/mime-type';
|
|
1
2
|
import { escapeSingleQuotes } from '../../../libs/shell.js';
|
|
3
|
+
/**
|
|
4
|
+
* True for `application/json`, any RFC 6839 `+json` structured-syntax suffix
|
|
5
|
+
* (e.g. `application/vnd.api+json`), and parameterized variants
|
|
6
|
+
* (e.g. `application/json;charset=utf-8`). Case-insensitive.
|
|
7
|
+
*/
|
|
8
|
+
const isJsonContentType = (value) => {
|
|
9
|
+
if (!value) {
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
12
|
+
const { subtype } = parseMimeType(value);
|
|
13
|
+
return subtype === 'json' || subtype.endsWith('+json');
|
|
14
|
+
};
|
|
2
15
|
/**
|
|
3
16
|
* shell/curl
|
|
4
17
|
*/
|
|
@@ -66,7 +79,7 @@ export const shellCurl = {
|
|
|
66
79
|
}
|
|
67
80
|
// Body
|
|
68
81
|
if (normalizedRequest.postData) {
|
|
69
|
-
if (normalizedRequest.postData.mimeType
|
|
82
|
+
if (isJsonContentType(normalizedRequest.postData.mimeType)) {
|
|
70
83
|
// Pretty print JSON data
|
|
71
84
|
if (normalizedRequest.postData.text) {
|
|
72
85
|
try {
|
|
@@ -106,7 +119,20 @@ export const shellCurl = {
|
|
|
106
119
|
parts.push(`--form '${escapedName}=@${escapedFileName}'`);
|
|
107
120
|
}
|
|
108
121
|
else {
|
|
109
|
-
const
|
|
122
|
+
const rawValue = param.value ?? '';
|
|
123
|
+
// Pretty-print parts whose contentType is JSON so the snippet stays readable,
|
|
124
|
+
// mirroring what we already do for `--data` JSON bodies above.
|
|
125
|
+
const isJsonPart = isJsonContentType(param.contentType);
|
|
126
|
+
let displayValue = rawValue;
|
|
127
|
+
if (isJsonPart && rawValue) {
|
|
128
|
+
try {
|
|
129
|
+
displayValue = JSON.stringify(JSON.parse(rawValue), null, 2);
|
|
130
|
+
}
|
|
131
|
+
catch {
|
|
132
|
+
// Fall back to the raw value if it is not valid JSON.
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
const escapedValue = escapeSingleQuotes(`${displayValue}${multipartValueSuffix}`);
|
|
110
136
|
parts.push(`--form '${escapedName}=${escapedValue}'`);
|
|
111
137
|
}
|
|
112
138
|
});
|
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.9.
|
|
12
|
+
"version": "0.9.9",
|
|
13
13
|
"engines": {
|
|
14
14
|
"node": ">=22"
|
|
15
15
|
},
|
|
@@ -240,7 +240,8 @@
|
|
|
240
240
|
"dependencies": {
|
|
241
241
|
"js-base64": "^3.7.8",
|
|
242
242
|
"stringify-object": "^6.0.0",
|
|
243
|
-
"@scalar/
|
|
243
|
+
"@scalar/helpers": "0.8.0",
|
|
244
|
+
"@scalar/types": "0.12.0"
|
|
244
245
|
},
|
|
245
246
|
"devDependencies": {
|
|
246
247
|
"@types/stringify-object": "^4.0.5",
|