@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.
Files changed (50) hide show
  1. package/README.md +3 -3
  2. package/dist/core/index.d.ts +1 -1
  3. package/dist/core/index.d.ts.map +1 -1
  4. package/dist/core/index.js +1 -1
  5. package/dist/core/types.d.ts +30 -5
  6. package/dist/core/types.d.ts.map +1 -1
  7. package/dist/core/types.test-d.d.ts +2 -0
  8. package/dist/core/types.test-d.d.ts.map +1 -0
  9. package/dist/core/utils/arrayToObject.d.ts +6 -1
  10. package/dist/core/utils/arrayToObject.d.ts.map +1 -1
  11. package/dist/core/utils/arrayToObject.js +6 -1
  12. package/dist/core/utils/needsQuotes.d.ts +7 -0
  13. package/dist/core/utils/needsQuotes.d.ts.map +1 -0
  14. package/dist/core/utils/needsQuotes.js +10 -0
  15. package/dist/core/utils/objectToString.d.ts +5 -0
  16. package/dist/core/utils/objectToString.d.ts.map +1 -1
  17. package/dist/core/utils/objectToString.js +7 -2
  18. package/dist/plugins/js/fetch/fetch.d.ts +5 -2
  19. package/dist/plugins/js/fetch/fetch.d.ts.map +1 -1
  20. package/dist/plugins/js/fetch/fetch.js +63 -59
  21. package/dist/plugins/js/fetch/index.js +1 -1
  22. package/dist/plugins/js/ofetch/index.js +1 -1
  23. package/dist/plugins/js/ofetch/ofetch.d.ts +5 -2
  24. package/dist/plugins/js/ofetch/ofetch.d.ts.map +1 -1
  25. package/dist/plugins/js/ofetch/ofetch.js +70 -64
  26. package/dist/plugins/node/fetch/fetch.d.ts +5 -2
  27. package/dist/plugins/node/fetch/fetch.d.ts.map +1 -1
  28. package/dist/plugins/node/fetch/fetch.js +63 -59
  29. package/dist/plugins/node/fetch/index.js +1 -1
  30. package/dist/plugins/node/ofetch/index.js +1 -1
  31. package/dist/plugins/node/ofetch/ofetch.d.ts +5 -2
  32. package/dist/plugins/node/ofetch/ofetch.d.ts.map +1 -1
  33. package/dist/plugins/node/ofetch/ofetch.js +70 -64
  34. package/dist/plugins/node/undici/index.js +1 -1
  35. package/dist/plugins/node/undici/undici.d.ts +5 -2
  36. package/dist/plugins/node/undici/undici.d.ts.map +1 -1
  37. package/dist/plugins/node/undici/undici.js +63 -59
  38. package/dist/plugins/shell/curl/curl.d.ts +6 -0
  39. package/dist/plugins/shell/curl/curl.d.ts.map +1 -0
  40. package/dist/plugins/shell/curl/curl.js +105 -0
  41. package/dist/plugins/shell/curl/index.d.ts +2 -0
  42. package/dist/plugins/shell/curl/index.d.ts.map +1 -0
  43. package/dist/plugins/shell/curl/index.js +1 -0
  44. package/dist/snippetz.d.ts +9 -12
  45. package/dist/snippetz.d.ts.map +1 -1
  46. package/dist/snippetz.js +22 -22
  47. package/package.json +7 -2
  48. package/dist/core/utils/isKeyNeedsQuotes.d.ts +0 -2
  49. package/dist/core/utils/isKeyNeedsQuotes.d.ts.map +0 -1
  50. 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
- function fetch(request) {
5
- // Defaults
6
- const normalizedRequest = {
7
- method: 'GET',
8
- ...request,
9
- };
10
- // Normalization
11
- normalizedRequest.method = normalizedRequest.method.toUpperCase();
12
- // Reset fetch defaults
13
- const options = {
14
- method: normalizedRequest.method === 'GET' ? undefined : normalizedRequest.method,
15
- };
16
- // Query
17
- const searchParams = new URLSearchParams(normalizedRequest.queryString
18
- ? arrayToObject(normalizedRequest.queryString)
19
- : undefined);
20
- const queryString = searchParams.size ? `?${searchParams.toString()}` : '';
21
- // Headers
22
- if (normalizedRequest.headers?.length) {
23
- options.headers = {};
24
- normalizedRequest.headers.forEach((header) => {
25
- options.headers[header.name] = header.value;
26
- });
27
- }
28
- // Cookies
29
- if (normalizedRequest.cookies?.length) {
30
- options.headers = options.headers || {};
31
- normalizedRequest.cookies.forEach((cookie) => {
32
- options.headers['Set-Cookie'] = options.headers['Set-Cookie']
33
- ? `${options.headers['Set-Cookie']}; ${cookie.name}=${cookie.value}`
34
- : `${cookie.name}=${cookie.value}`;
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
- // Add body
44
- if (normalizedRequest.postData) {
45
- // Plain text
46
- options.body = normalizedRequest.postData.text;
47
- // JSON
48
- if (normalizedRequest.postData.mimeType === 'application/json') {
49
- options.body = `JSON.stringify(${objectToString(JSON.parse(options.body))})`;
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
- // Transform to JSON
53
- const jsonOptions = Object.keys(options).length
54
- ? `, ${objectToString(options)}`
55
- : '';
56
- // Code Template
57
- const code = `fetch('${normalizedRequest.url}${queryString}'${jsonOptions})`;
58
- return {
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 { fetch };
69
+ export { nodeFetch };
@@ -1 +1 @@
1
- export { fetch } from './fetch.js';
1
+ export { nodeFetch } from './fetch.js';
@@ -1 +1 @@
1
- export { ofetch } from './ofetch.js';
1
+ export { nodeOfetch } from './ofetch.js';
@@ -1,3 +1,6 @@
1
- import { type Request, type Source } from '../../../core/index.js';
2
- export declare function ofetch(request?: Partial<Request>): Source;
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,EACL,KAAK,OAAO,EACZ,KAAK,MAAM,EAGZ,MAAM,eAAe,CAAA;AAEtB,wBAAgB,MAAM,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC,OAAO,CAAC,GAAG,MAAM,CAiFzD"}
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
- function ofetch(request) {
5
- // Defaults
6
- const normalizedRequest = {
7
- method: 'GET',
8
- ...request,
9
- };
10
- // Normalization
11
- normalizedRequest.method = normalizedRequest.method.toUpperCase();
12
- // Reset fetch defaults
13
- const options = {
14
- method: normalizedRequest.method === 'GET' ? undefined : normalizedRequest.method,
15
- };
16
- // Query
17
- const searchParams = new URLSearchParams(normalizedRequest.queryString
18
- ? arrayToObject(normalizedRequest.queryString)
19
- : undefined);
20
- if (searchParams.size) {
21
- options.query = {};
22
- searchParams.forEach((value, key) => {
23
- options.query[key] = value;
24
- });
25
- }
26
- // Headers
27
- if (normalizedRequest.headers?.length) {
28
- options.headers = {};
29
- normalizedRequest.headers.forEach((header) => {
30
- options.headers[header.name] = header.value;
31
- });
32
- }
33
- // Cookies
34
- if (normalizedRequest.cookies?.length) {
35
- options.headers = options.headers || {};
36
- normalizedRequest.cookies.forEach((cookie) => {
37
- options.headers['Set-Cookie'] = options.headers['Set-Cookie']
38
- ? `${options.headers['Set-Cookie']}; ${cookie.name}=${cookie.value}`
39
- : `${cookie.name}=${cookie.value}`;
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
- // Add body
49
- if (normalizedRequest.postData) {
50
- // Plain text
51
- options.body = normalizedRequest.postData.text;
52
- // JSON
53
- if (normalizedRequest.postData.mimeType === 'application/json') {
54
- options.body = JSON.parse(options.body);
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
- // Transform to JSON
58
- const jsonOptions = Object.keys(options).length
59
- ? `, ${objectToString(options)}`
60
- : '';
61
- // Code Template
62
- const code = `ofetch('${normalizedRequest.url}'${jsonOptions})`;
63
- return {
64
- target: 'node',
65
- client: 'ofetch',
66
- code,
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 { ofetch };
76
+ export { nodeOfetch };
@@ -1 +1 @@
1
- export { undici } from './undici.js';
1
+ export { nodeUndici } from './undici.js';
@@ -1,3 +1,6 @@
1
- import { type Request, type Source } from '../../../core/index.js';
2
- export declare function undici(request?: Partial<Request>): Source;
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,EACL,KAAK,OAAO,EACZ,KAAK,MAAM,EAGZ,MAAM,eAAe,CAAA;AAEtB,wBAAgB,MAAM,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC,OAAO,CAAC,GAAG,MAAM,CA+EzD"}
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
- function undici(request) {
5
- // Defaults
6
- const normalizedRequest = {
7
- method: 'GET',
8
- ...request,
9
- };
10
- // Normalization
11
- normalizedRequest.method = normalizedRequest.method.toUpperCase();
12
- // Reset undici defaults
13
- const options = {
14
- method: normalizedRequest.method === 'GET' ? undefined : normalizedRequest.method,
15
- };
16
- // Query
17
- const searchParams = new URLSearchParams(normalizedRequest.queryString
18
- ? arrayToObject(normalizedRequest.queryString)
19
- : undefined);
20
- const queryString = searchParams.size ? `?${searchParams.toString()}` : '';
21
- // Headers
22
- if (normalizedRequest.headers?.length) {
23
- options.headers = {};
24
- normalizedRequest.headers.forEach((header) => {
25
- options.headers[header.name] = header.value;
26
- });
27
- }
28
- // Cookies
29
- if (normalizedRequest.cookies?.length) {
30
- options.headers = options.headers || {};
31
- normalizedRequest.cookies.forEach((cookie) => {
32
- options.headers['Set-Cookie'] = options.headers['Set-Cookie']
33
- ? `${options.headers['Set-Cookie']}; ${cookie.name}=${cookie.value}`
34
- : `${cookie.name}=${cookie.value}`;
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
- // Add body
44
- if (normalizedRequest.postData) {
45
- // Plain text
46
- options.body = normalizedRequest.postData.text;
47
- // JSON
48
- if (normalizedRequest.postData.mimeType === 'application/json') {
49
- options.body = `JSON.stringify(${objectToString(JSON.parse(options.body))})`;
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
- // Transform to JSON
53
- const jsonOptions = Object.keys(options).length
54
- ? `, ${objectToString(options)}`
55
- : '';
56
- // Code Template
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
- return {
61
- target: 'node',
62
- client: 'undici',
63
- code,
64
- };
65
- }
68
+ },
69
+ };
66
70
 
67
- export { undici };
71
+ export { nodeUndici };
@@ -0,0 +1,6 @@
1
+ import type { Plugin } from '../../../core/index.js';
2
+ /**
3
+ * shell/curl
4
+ */
5
+ export declare const shellCurl: Plugin;
6
+ //# sourceMappingURL=curl.d.ts.map
@@ -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,2 @@
1
+ export * from './curl.js';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -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';
@@ -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, request: Partial<Request>): import("./core/index.js").Source | {
8
- code: string;
9
- };
10
- print(target: TargetId, client: ClientId, request: Partial<Request>): string;
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: TargetId;
15
- client: ClientId;
11
+ target: "js" | "node" | "shell";
12
+ client: "fetch" | "ofetch" | "undici" | "curl";
16
13
  }[];
17
- findPlugin(target: TargetId, client: ClientId): typeof undici | undefined;
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
@@ -1 +1 @@
1
- {"version":3,"file":"snippetz.d.ts","sourceRoot":"","sources":["../src/snippetz.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAA;AAKzD,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAA;AAE9C;;GAEG;AACH,wBAAgB,QAAQ;gBAIR,QAAQ,UAAU,QAAQ,WAAW,OAAO,CAAC,OAAO,CAAC;;;kBAWnD,QAAQ,UAAU,QAAQ,WAAW,OAAO,CAAC,OAAO,CAAC;;;;;;;uBAyBhD,QAAQ,UAAU,QAAQ;sBAO3B,MAAM,UAAU,MAAM;EAI3C"}
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"}