@scalar/snippetz 0.2.4 → 0.2.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/README.md +3 -3
- package/dist/core/index.d.ts +1 -1
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +1 -1
- package/dist/core/types.d.ts +30 -5
- package/dist/core/types.d.ts.map +1 -1
- package/dist/core/types.test-d.d.ts +2 -0
- package/dist/core/types.test-d.d.ts.map +1 -0
- package/dist/core/utils/arrayToObject.d.ts +6 -1
- package/dist/core/utils/arrayToObject.d.ts.map +1 -1
- package/dist/core/utils/arrayToObject.js +6 -1
- package/dist/core/utils/needsQuotes.d.ts +7 -0
- package/dist/core/utils/needsQuotes.d.ts.map +1 -0
- package/dist/core/utils/needsQuotes.js +10 -0
- package/dist/core/utils/objectToString.d.ts +5 -0
- package/dist/core/utils/objectToString.d.ts.map +1 -1
- package/dist/core/utils/objectToString.js +7 -2
- package/dist/plugins/js/fetch/fetch.d.ts +5 -2
- package/dist/plugins/js/fetch/fetch.d.ts.map +1 -1
- package/dist/plugins/js/fetch/fetch.js +63 -59
- package/dist/plugins/js/fetch/index.js +1 -1
- package/dist/plugins/js/ofetch/index.js +1 -1
- package/dist/plugins/js/ofetch/ofetch.d.ts +5 -2
- package/dist/plugins/js/ofetch/ofetch.d.ts.map +1 -1
- package/dist/plugins/js/ofetch/ofetch.js +70 -64
- package/dist/plugins/node/fetch/fetch.d.ts +5 -2
- package/dist/plugins/node/fetch/fetch.d.ts.map +1 -1
- package/dist/plugins/node/fetch/fetch.js +63 -59
- package/dist/plugins/node/fetch/index.js +1 -1
- package/dist/plugins/node/ofetch/index.js +1 -1
- package/dist/plugins/node/ofetch/ofetch.d.ts +5 -2
- package/dist/plugins/node/ofetch/ofetch.d.ts.map +1 -1
- package/dist/plugins/node/ofetch/ofetch.js +70 -64
- package/dist/plugins/node/undici/index.js +1 -1
- package/dist/plugins/node/undici/undici.d.ts +5 -2
- package/dist/plugins/node/undici/undici.d.ts.map +1 -1
- package/dist/plugins/node/undici/undici.js +63 -59
- package/dist/plugins/shell/curl/curl.d.ts +6 -0
- package/dist/plugins/shell/curl/curl.d.ts.map +1 -0
- package/dist/plugins/shell/curl/curl.js +105 -0
- package/dist/plugins/shell/curl/index.d.ts +2 -0
- package/dist/plugins/shell/curl/index.d.ts.map +1 -0
- package/dist/plugins/shell/curl/index.js +1 -0
- package/dist/snippetz.d.ts +9 -12
- package/dist/snippetz.d.ts.map +1 -1
- package/dist/snippetz.js +22 -22
- package/package.json +7 -2
- package/dist/core/utils/isKeyNeedsQuotes.d.ts +0 -2
- package/dist/core/utils/isKeyNeedsQuotes.d.ts.map +0 -1
- package/dist/core/utils/isKeyNeedsQuotes.js +0 -5
|
@@ -1,65 +1,69 @@
|
|
|
1
1
|
import { arrayToObject } from '../../../core/utils/arrayToObject.js';
|
|
2
2
|
import { objectToString } from '../../../core/utils/objectToString.js';
|
|
3
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
|
-
// Remove undefined keys
|
|
38
|
-
Object.keys(options).forEach((key) => {
|
|
39
|
-
if (options[key] === undefined) {
|
|
40
|
-
delete options[key];
|
|
4
|
+
/**
|
|
5
|
+
* node/fetch
|
|
6
|
+
*/
|
|
7
|
+
const nodeFetch = {
|
|
8
|
+
target: 'node',
|
|
9
|
+
client: 'fetch',
|
|
10
|
+
generate(request) {
|
|
11
|
+
// Defaults
|
|
12
|
+
const normalizedRequest = {
|
|
13
|
+
method: 'GET',
|
|
14
|
+
...request,
|
|
15
|
+
};
|
|
16
|
+
// Normalization
|
|
17
|
+
normalizedRequest.method = normalizedRequest.method.toUpperCase();
|
|
18
|
+
// Reset fetch defaults
|
|
19
|
+
const options = {
|
|
20
|
+
method: normalizedRequest.method === 'GET'
|
|
21
|
+
? undefined
|
|
22
|
+
: normalizedRequest.method,
|
|
23
|
+
};
|
|
24
|
+
// Query
|
|
25
|
+
const searchParams = new URLSearchParams(normalizedRequest.queryString
|
|
26
|
+
? arrayToObject(normalizedRequest.queryString)
|
|
27
|
+
: undefined);
|
|
28
|
+
const queryString = searchParams.size ? `?${searchParams.toString()}` : '';
|
|
29
|
+
// Headers
|
|
30
|
+
if (normalizedRequest.headers?.length) {
|
|
31
|
+
options.headers = {};
|
|
32
|
+
normalizedRequest.headers.forEach((header) => {
|
|
33
|
+
options.headers[header.name] = header.value;
|
|
34
|
+
});
|
|
41
35
|
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
36
|
+
// Cookies
|
|
37
|
+
if (normalizedRequest.cookies?.length) {
|
|
38
|
+
options.headers = options.headers || {};
|
|
39
|
+
normalizedRequest.cookies.forEach((cookie) => {
|
|
40
|
+
options.headers['Set-Cookie'] = options.headers['Set-Cookie']
|
|
41
|
+
? `${options.headers['Set-Cookie']}; ${cookie.name}=${cookie.value}`
|
|
42
|
+
: `${cookie.name}=${cookie.value}`;
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
// Remove undefined keys
|
|
46
|
+
Object.keys(options).forEach((key) => {
|
|
47
|
+
if (options[key] === undefined) {
|
|
48
|
+
delete options[key];
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
// Add body
|
|
52
|
+
if (normalizedRequest.postData) {
|
|
53
|
+
// Plain text
|
|
54
|
+
options.body = normalizedRequest.postData.text;
|
|
55
|
+
// JSON
|
|
56
|
+
if (normalizedRequest.postData.mimeType === 'application/json') {
|
|
57
|
+
options.body = `JSON.stringify(${objectToString(JSON.parse(options.body))})`;
|
|
58
|
+
}
|
|
50
59
|
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
target: 'node',
|
|
60
|
-
client: 'fetch',
|
|
61
|
-
code,
|
|
62
|
-
};
|
|
63
|
-
}
|
|
60
|
+
// Transform to JSON
|
|
61
|
+
const jsonOptions = Object.keys(options).length
|
|
62
|
+
? `, ${objectToString(options)}`
|
|
63
|
+
: '';
|
|
64
|
+
// Code Template
|
|
65
|
+
return `fetch('${normalizedRequest.url}${queryString}'${jsonOptions})`;
|
|
66
|
+
},
|
|
67
|
+
};
|
|
64
68
|
|
|
65
|
-
export {
|
|
69
|
+
export { nodeFetch };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { nodeFetch } from './fetch.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { nodeOfetch } from './ofetch.js';
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
-
import { type
|
|
2
|
-
|
|
1
|
+
import { type Plugin } from '../../../core/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* node/ofetch
|
|
4
|
+
*/
|
|
5
|
+
export declare const nodeOfetch: Plugin;
|
|
3
6
|
//# sourceMappingURL=ofetch.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ofetch.d.ts","sourceRoot":"","sources":["../../../../src/plugins/node/ofetch/ofetch.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"ofetch.d.ts","sourceRoot":"","sources":["../../../../src/plugins/node/ofetch/ofetch.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,MAAM,EAAiC,MAAM,eAAe,CAAA;AAE1E;;GAEG;AACH,eAAO,MAAM,UAAU,EAAE,MAmFxB,CAAA"}
|
|
@@ -1,70 +1,76 @@
|
|
|
1
1
|
import { arrayToObject } from '../../../core/utils/arrayToObject.js';
|
|
2
2
|
import { objectToString } from '../../../core/utils/objectToString.js';
|
|
3
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
|
-
// Remove undefined keys
|
|
43
|
-
Object.keys(options).forEach((key) => {
|
|
44
|
-
if (options[key] === undefined) {
|
|
45
|
-
delete options[key];
|
|
4
|
+
/**
|
|
5
|
+
* node/ofetch
|
|
6
|
+
*/
|
|
7
|
+
const nodeOfetch = {
|
|
8
|
+
target: 'node',
|
|
9
|
+
client: 'ofetch',
|
|
10
|
+
generate(request) {
|
|
11
|
+
// Defaults
|
|
12
|
+
const normalizedRequest = {
|
|
13
|
+
method: 'GET',
|
|
14
|
+
...request,
|
|
15
|
+
};
|
|
16
|
+
// Normalization
|
|
17
|
+
normalizedRequest.method = normalizedRequest.method.toUpperCase();
|
|
18
|
+
// Reset fetch defaults
|
|
19
|
+
const options = {
|
|
20
|
+
method: normalizedRequest.method === 'GET'
|
|
21
|
+
? undefined
|
|
22
|
+
: normalizedRequest.method,
|
|
23
|
+
};
|
|
24
|
+
// Query
|
|
25
|
+
const searchParams = new URLSearchParams(normalizedRequest.queryString
|
|
26
|
+
? arrayToObject(normalizedRequest.queryString)
|
|
27
|
+
: undefined);
|
|
28
|
+
if (searchParams.size) {
|
|
29
|
+
options.query = {};
|
|
30
|
+
searchParams.forEach((value, key) => {
|
|
31
|
+
options.query[key] = value;
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
// Headers
|
|
35
|
+
if (normalizedRequest.headers?.length) {
|
|
36
|
+
options.headers = {};
|
|
37
|
+
normalizedRequest.headers.forEach((header) => {
|
|
38
|
+
options.headers[header.name] = header.value;
|
|
39
|
+
});
|
|
46
40
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
41
|
+
// Cookies
|
|
42
|
+
if (normalizedRequest.cookies?.length) {
|
|
43
|
+
options.headers = options.headers || {};
|
|
44
|
+
normalizedRequest.cookies.forEach((cookie) => {
|
|
45
|
+
options.headers['Set-Cookie'] = options.headers['Set-Cookie']
|
|
46
|
+
? `${options.headers['Set-Cookie']}; ${cookie.name}=${cookie.value}`
|
|
47
|
+
: `${cookie.name}=${cookie.value}`;
|
|
48
|
+
});
|
|
55
49
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
50
|
+
// Remove undefined keys
|
|
51
|
+
Object.keys(options).forEach((key) => {
|
|
52
|
+
if (options[key] === undefined) {
|
|
53
|
+
delete options[key];
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
// Add body
|
|
57
|
+
if (normalizedRequest.postData) {
|
|
58
|
+
// Plain text
|
|
59
|
+
options.body = normalizedRequest.postData.text;
|
|
60
|
+
// JSON
|
|
61
|
+
if (normalizedRequest.postData.mimeType === 'application/json') {
|
|
62
|
+
options.body = JSON.parse(options.body);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
// Transform to JSON
|
|
66
|
+
const jsonOptions = Object.keys(options).length
|
|
67
|
+
? `, ${objectToString(options)}`
|
|
68
|
+
: '';
|
|
69
|
+
// Code Template
|
|
70
|
+
return `import { ofetch } from 'ofetch'
|
|
71
|
+
|
|
72
|
+
ofetch('${normalizedRequest.url}'${jsonOptions})`;
|
|
73
|
+
},
|
|
74
|
+
};
|
|
69
75
|
|
|
70
|
-
export {
|
|
76
|
+
export { nodeOfetch };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { nodeUndici } from './undici.js';
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
-
import { type
|
|
2
|
-
|
|
1
|
+
import { type Plugin } from '../../../core/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* node/undici
|
|
4
|
+
*/
|
|
5
|
+
export declare const nodeUndici: Plugin;
|
|
3
6
|
//# sourceMappingURL=undici.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"undici.d.ts","sourceRoot":"","sources":["../../../../src/plugins/node/undici/undici.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"undici.d.ts","sourceRoot":"","sources":["../../../../src/plugins/node/undici/undici.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,MAAM,EAAiC,MAAM,eAAe,CAAA;AAE1E;;GAEG;AACH,eAAO,MAAM,UAAU,EAAE,MA+ExB,CAAA"}
|
|
@@ -1,67 +1,71 @@
|
|
|
1
1
|
import { arrayToObject } from '../../../core/utils/arrayToObject.js';
|
|
2
2
|
import { objectToString } from '../../../core/utils/objectToString.js';
|
|
3
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
|
-
// Remove undefined keys
|
|
38
|
-
Object.keys(options).forEach((key) => {
|
|
39
|
-
if (options[key] === undefined) {
|
|
40
|
-
delete options[key];
|
|
4
|
+
/**
|
|
5
|
+
* node/undici
|
|
6
|
+
*/
|
|
7
|
+
const nodeUndici = {
|
|
8
|
+
target: 'node',
|
|
9
|
+
client: 'undici',
|
|
10
|
+
generate(request) {
|
|
11
|
+
// Defaults
|
|
12
|
+
const normalizedRequest = {
|
|
13
|
+
method: 'GET',
|
|
14
|
+
...request,
|
|
15
|
+
};
|
|
16
|
+
// Normalization
|
|
17
|
+
normalizedRequest.method = normalizedRequest.method.toUpperCase();
|
|
18
|
+
// Reset undici defaults
|
|
19
|
+
const options = {
|
|
20
|
+
method: normalizedRequest.method === 'GET'
|
|
21
|
+
? undefined
|
|
22
|
+
: normalizedRequest.method,
|
|
23
|
+
};
|
|
24
|
+
// Query
|
|
25
|
+
const searchParams = new URLSearchParams(normalizedRequest.queryString
|
|
26
|
+
? arrayToObject(normalizedRequest.queryString)
|
|
27
|
+
: undefined);
|
|
28
|
+
const queryString = searchParams.size ? `?${searchParams.toString()}` : '';
|
|
29
|
+
// Headers
|
|
30
|
+
if (normalizedRequest.headers?.length) {
|
|
31
|
+
options.headers = {};
|
|
32
|
+
normalizedRequest.headers.forEach((header) => {
|
|
33
|
+
options.headers[header.name] = header.value;
|
|
34
|
+
});
|
|
41
35
|
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
36
|
+
// Cookies
|
|
37
|
+
if (normalizedRequest.cookies?.length) {
|
|
38
|
+
options.headers = options.headers || {};
|
|
39
|
+
normalizedRequest.cookies.forEach((cookie) => {
|
|
40
|
+
options.headers['Set-Cookie'] = options.headers['Set-Cookie']
|
|
41
|
+
? `${options.headers['Set-Cookie']}; ${cookie.name}=${cookie.value}`
|
|
42
|
+
: `${cookie.name}=${cookie.value}`;
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
// Remove undefined keys
|
|
46
|
+
Object.keys(options).forEach((key) => {
|
|
47
|
+
if (options[key] === undefined) {
|
|
48
|
+
delete options[key];
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
// Add body
|
|
52
|
+
if (normalizedRequest.postData) {
|
|
53
|
+
// Plain text
|
|
54
|
+
options.body = normalizedRequest.postData.text;
|
|
55
|
+
// JSON
|
|
56
|
+
if (normalizedRequest.postData.mimeType === 'application/json') {
|
|
57
|
+
options.body = `JSON.stringify(${objectToString(JSON.parse(options.body))})`;
|
|
58
|
+
}
|
|
50
59
|
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
const code = `import { request } from 'undici'
|
|
60
|
+
// Transform to JSON
|
|
61
|
+
const jsonOptions = Object.keys(options).length
|
|
62
|
+
? `, ${objectToString(options)}`
|
|
63
|
+
: '';
|
|
64
|
+
// Code Template
|
|
65
|
+
return `import { request } from 'undici'
|
|
58
66
|
|
|
59
67
|
const { statusCode, body } = await request('${normalizedRequest.url}${queryString}'${jsonOptions})`;
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
client: 'undici',
|
|
63
|
-
code,
|
|
64
|
-
};
|
|
65
|
-
}
|
|
68
|
+
},
|
|
69
|
+
};
|
|
66
70
|
|
|
67
|
-
export {
|
|
71
|
+
export { nodeUndici };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"curl.d.ts","sourceRoot":"","sources":["../../../../src/plugins/shell/curl/curl.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,eAAe,CAAA;AAE3C;;GAEG;AACH,eAAO,MAAM,SAAS,EAAE,MAoHvB,CAAA"}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* shell/curl
|
|
3
|
+
*/
|
|
4
|
+
const shellCurl = {
|
|
5
|
+
target: 'shell',
|
|
6
|
+
client: 'curl',
|
|
7
|
+
generate(request, configuration) {
|
|
8
|
+
// Defaults
|
|
9
|
+
const normalizedRequest = {
|
|
10
|
+
method: 'GET',
|
|
11
|
+
...request,
|
|
12
|
+
};
|
|
13
|
+
// Normalization
|
|
14
|
+
normalizedRequest.method = normalizedRequest.method.toUpperCase();
|
|
15
|
+
// Build curl command parts
|
|
16
|
+
const parts = ['curl'];
|
|
17
|
+
// URL (quote if has query parameters or special characters)
|
|
18
|
+
const queryString = normalizedRequest.queryString?.length
|
|
19
|
+
? '?' +
|
|
20
|
+
normalizedRequest.queryString
|
|
21
|
+
.map((param) => {
|
|
22
|
+
// Ensure both name and value are fully URI encoded
|
|
23
|
+
const encodedName = encodeURIComponent(param.name);
|
|
24
|
+
const encodedValue = encodeURIComponent(param.value);
|
|
25
|
+
return `${encodedName}=${encodedValue}`;
|
|
26
|
+
})
|
|
27
|
+
.join('&')
|
|
28
|
+
: '';
|
|
29
|
+
const url = `${normalizedRequest.url}${queryString}`;
|
|
30
|
+
const hasSpecialChars = /[\s<>[\]{}|\\^%]/.test(url);
|
|
31
|
+
const urlPart = queryString || hasSpecialChars ? `'${url}'` : url;
|
|
32
|
+
parts[0] = `curl ${urlPart}`;
|
|
33
|
+
// Method
|
|
34
|
+
if (normalizedRequest.method !== 'GET') {
|
|
35
|
+
parts.push(`--request ${normalizedRequest.method}`);
|
|
36
|
+
}
|
|
37
|
+
// Basic Auth
|
|
38
|
+
if (configuration?.auth?.username && configuration?.auth?.password) {
|
|
39
|
+
parts.push(`--user '${configuration.auth.username}:${configuration.auth.password}'`);
|
|
40
|
+
}
|
|
41
|
+
// Headers
|
|
42
|
+
if (normalizedRequest.headers?.length) {
|
|
43
|
+
normalizedRequest.headers.forEach((header) => {
|
|
44
|
+
parts.push(`--header '${header.name}: ${header.value}'`);
|
|
45
|
+
});
|
|
46
|
+
// Add compressed flag if Accept-Encoding header includes compression
|
|
47
|
+
const acceptEncoding = normalizedRequest.headers.find((header) => header.name.toLowerCase() === 'accept-encoding');
|
|
48
|
+
if (acceptEncoding && /gzip|deflate/.test(acceptEncoding.value)) {
|
|
49
|
+
parts.push('--compressed');
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
// Cookies
|
|
53
|
+
if (normalizedRequest.cookies?.length) {
|
|
54
|
+
const cookieString = normalizedRequest.cookies
|
|
55
|
+
.map((cookie) => {
|
|
56
|
+
// Encode both cookie name and value to handle special characters
|
|
57
|
+
const encodedName = encodeURIComponent(cookie.name);
|
|
58
|
+
const encodedValue = encodeURIComponent(cookie.value);
|
|
59
|
+
return `${encodedName}=${encodedValue}`;
|
|
60
|
+
})
|
|
61
|
+
.join('; ');
|
|
62
|
+
parts.push(`--cookie '${cookieString}'`);
|
|
63
|
+
}
|
|
64
|
+
// Body
|
|
65
|
+
if (normalizedRequest.postData) {
|
|
66
|
+
if (normalizedRequest.postData.mimeType === 'application/json') {
|
|
67
|
+
// Pretty print JSON data
|
|
68
|
+
if (normalizedRequest.postData.text) {
|
|
69
|
+
const jsonData = JSON.parse(normalizedRequest.postData.text);
|
|
70
|
+
const prettyJson = JSON.stringify(jsonData, null, 2);
|
|
71
|
+
parts.push(`--data '${prettyJson}'`);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
else if (normalizedRequest.postData.mimeType === 'application/octet-stream') {
|
|
75
|
+
parts.push(`--data-binary '${normalizedRequest.postData.text}'`);
|
|
76
|
+
}
|
|
77
|
+
else if (normalizedRequest.postData.mimeType ===
|
|
78
|
+
'application/x-www-form-urlencoded' &&
|
|
79
|
+
normalizedRequest.postData.params) {
|
|
80
|
+
// Handle URL-encoded form data
|
|
81
|
+
normalizedRequest.postData.params.forEach((param) => {
|
|
82
|
+
parts.push(`--data-urlencode '${encodeURIComponent(param.name)}=${param.value}'`);
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
else if (normalizedRequest.postData.mimeType === 'multipart/form-data' &&
|
|
86
|
+
normalizedRequest.postData.params) {
|
|
87
|
+
// Handle multipart form data
|
|
88
|
+
normalizedRequest.postData.params.forEach((param) => {
|
|
89
|
+
if (param.fileName !== undefined) {
|
|
90
|
+
parts.push(`--form '${param.name}=@${param.fileName}'`);
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
parts.push(`--form '${param.name}=${param.value}'`);
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
parts.push(`--data "${normalizedRequest.postData.text}"`);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return parts.join(' \\\n ');
|
|
102
|
+
},
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
export { shellCurl };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/plugins/shell/curl/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { shellCurl } from './curl.js';
|
package/dist/snippetz.d.ts
CHANGED
|
@@ -1,20 +1,17 @@
|
|
|
1
|
-
import type { ClientId, Request, TargetId } from './core/index.js';
|
|
2
|
-
import { undici } from './plugins/node/undici/index.js';
|
|
1
|
+
import type { ClientId, Plugin, Request, TargetId } from './core/index.js';
|
|
3
2
|
/**
|
|
4
3
|
* Generate code examples for HAR requests
|
|
5
4
|
*/
|
|
6
5
|
export declare function snippetz(): {
|
|
7
|
-
get(target: TargetId, client: ClientId
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
targets(): TargetId[];
|
|
12
|
-
clients(): ClientId[];
|
|
6
|
+
get(target: TargetId, client: ClientId<TargetId>): Plugin | undefined;
|
|
7
|
+
print<T extends TargetId>(target: T, client: ClientId<T>, request: Partial<Request>): string | undefined;
|
|
8
|
+
targets(): ("js" | "node" | "shell")[];
|
|
9
|
+
clients(): ("fetch" | "ofetch" | "undici" | "curl")[];
|
|
13
10
|
plugins(): {
|
|
14
|
-
target:
|
|
15
|
-
client:
|
|
11
|
+
target: "js" | "node" | "shell";
|
|
12
|
+
client: "fetch" | "ofetch" | "undici" | "curl";
|
|
16
13
|
}[];
|
|
17
|
-
findPlugin(target:
|
|
18
|
-
hasPlugin(target: string, client: string): boolean;
|
|
14
|
+
findPlugin<T extends TargetId>(target: T | string, client: ClientId<T> | string): Plugin | undefined;
|
|
15
|
+
hasPlugin<T extends TargetId>(target: T | string, client: ClientId<T> | string): boolean;
|
|
19
16
|
};
|
|
20
17
|
//# sourceMappingURL=snippetz.d.ts.map
|
package/dist/snippetz.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"snippetz.d.ts","sourceRoot":"","sources":["../src/snippetz.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,
|
|
1
|
+
{"version":3,"file":"snippetz.d.ts","sourceRoot":"","sources":["../src/snippetz.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAA;AAQjE;;GAEG;AACH,wBAAgB,QAAQ;gBAWR,QAAQ,UAAU,QAAQ,CAAC,QAAQ,CAAC;UAG1C,CAAC,SAAS,QAAQ,UACd,CAAC,UACD,QAAQ,CAAC,CAAC,CAAC,WACV,OAAO,CAAC,OAAO,CAAC;;;;;;;eAwBhB,CAAC,SAAS,QAAQ,UACnB,CAAC,GAAG,MAAM,UACV,QAAQ,CAAC,CAAC,CAAC,GAAG,MAAM;cAMpB,CAAC,SAAS,QAAQ,UAClB,CAAC,GAAG,MAAM,UACV,QAAQ,CAAC,CAAC,CAAC,GAAG,MAAM;EAKjC"}
|