@scalar/snippetz 0.2.11 → 0.2.13

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 (42) hide show
  1. package/dist/httpsnippet-lite/esm/helpers/escape.js +7 -7
  2. package/dist/httpsnippet-lite/esm/helpers/url.d.ts.map +1 -1
  3. package/dist/httpsnippet-lite/esm/targets/javascript/fetch/client.d.ts.map +1 -1
  4. package/dist/httpsnippet-lite/esm/targets/node/fetch/client.d.ts.map +1 -1
  5. package/dist/httpsnippet-lite/esm/targets/php/guzzle/client.d.ts.map +1 -1
  6. package/dist/httpsnippet-lite/esm/targets/php/guzzle/client.js +2 -4
  7. package/dist/httpsnippet-lite/esm/targets/swift/nsurlsession/client.js +1 -1
  8. package/dist/index.js +1 -0
  9. package/dist/plugins/dart/http/http.d.ts.map +1 -1
  10. package/dist/plugins/dart/http/http.js +8 -10
  11. package/dist/plugins/http/http11/http11.d.ts.map +1 -1
  12. package/dist/plugins/http/http11/http11.js +94 -5
  13. package/dist/plugins/js/fetch/fetch.d.ts.map +1 -1
  14. package/dist/plugins/js/fetch/fetch.js +3 -9
  15. package/dist/plugins/js/ofetch/ofetch.d.ts.map +1 -1
  16. package/dist/plugins/js/ofetch/ofetch.js +3 -9
  17. package/dist/plugins/node/fetch/fetch.d.ts.map +1 -1
  18. package/dist/plugins/node/fetch/fetch.js +3 -9
  19. package/dist/plugins/node/ofetch/ofetch.d.ts.map +1 -1
  20. package/dist/plugins/node/ofetch/ofetch.js +3 -9
  21. package/dist/plugins/node/undici/undici.d.ts.map +1 -1
  22. package/dist/plugins/node/undici/undici.js +3 -9
  23. package/dist/plugins/shell/curl/curl.d.ts.map +1 -1
  24. package/dist/plugins/shell/curl/curl.js +2 -4
  25. package/dist/snippetz.d.ts.map +1 -1
  26. package/dist/snippetz.js +1 -3
  27. package/dist/types/index.d.ts +2 -37
  28. package/dist/types/index.d.ts.map +1 -1
  29. package/dist/types/index.js +41 -0
  30. package/dist/utils/convertWithHttpSnippetLite.d.ts.map +1 -1
  31. package/dist/utils/objectToString.d.ts.map +1 -1
  32. package/dist/utils/objectToString.js +2 -4
  33. package/package.json +6 -4
  34. package/dist/httpsnippet-lite/esm/httpsnippet.d.ts +0 -10
  35. package/dist/httpsnippet-lite/esm/httpsnippet.d.ts.map +0 -1
  36. package/dist/httpsnippet-lite/esm/targets/http/http1.1/client.d.ts +0 -22
  37. package/dist/httpsnippet-lite/esm/targets/http/http1.1/client.d.ts.map +0 -1
  38. package/dist/httpsnippet-lite/esm/targets/http/http1.1/client.js +0 -77
  39. package/dist/httpsnippet-lite/esm/targets/http/target.d.ts +0 -27
  40. package/dist/httpsnippet-lite/esm/targets/http/target.d.ts.map +0 -1
  41. package/dist/httpsnippet-lite/esm/targets/targets.d.ts +0 -731
  42. package/dist/httpsnippet-lite/esm/targets/targets.d.ts.map +0 -1
@@ -19,31 +19,31 @@ function escapeString(rawValue, options = {}) {
19
19
  if (c === '\b') {
20
20
  return `${escapeChar}b`;
21
21
  }
22
- else if (c === '\t') {
22
+ if (c === '\t') {
23
23
  return `${escapeChar}t`;
24
24
  }
25
- else if (c === '\n') {
25
+ if (c === '\n') {
26
26
  if (escapeNewlines) {
27
27
  return `${escapeChar}n`;
28
28
  }
29
29
  return c; // Don't just continue, or this is caught by < \u0020
30
30
  }
31
- else if (c === '\f') {
31
+ if (c === '\f') {
32
32
  return `${escapeChar}f`;
33
33
  }
34
- else if (c === '\r') {
34
+ if (c === '\r') {
35
35
  if (escapeNewlines) {
36
36
  return `${escapeChar}r`;
37
37
  }
38
38
  return c; // Don't just continue, or this is caught by < \u0020
39
39
  }
40
- else if (c === escapeChar) {
40
+ if (c === escapeChar) {
41
41
  return escapeChar + escapeChar;
42
42
  }
43
- else if (c === delimiter) {
43
+ if (c === delimiter) {
44
44
  return escapeChar + delimiter;
45
45
  }
46
- else if (c < '\u0020' || c > '\u007E') {
46
+ if (c < '\u0020' || c > '\u007E') {
47
47
  // Delegate the trickier non-ASCII cases to the normal algorithm. Some of these
48
48
  // are escaped as \uXXXX, whilst others are represented literally. Since we're
49
49
  // using this primarily for header values that are generally (though not 100%
@@ -1 +1 @@
1
- {"version":3,"file":"url.d.ts","sourceRoot":"","sources":["../../../../src/httpsnippet-lite/esm/helpers/url.ts"],"names":[],"mappings":"AAEA,wBAAgB,cAAc,CAAC,GAAG,KAAA,mBAWjC;AACD,qBAAa,WAAY,SAAQ,GAAG;IAClC,IAAI,IAAI,WAEP;CACF"}
1
+ {"version":3,"file":"url.d.ts","sourceRoot":"","sources":["../../../../src/httpsnippet-lite/esm/helpers/url.ts"],"names":[],"mappings":"AAEA,wBAAgB,cAAc,CAAC,GAAG,KAAA,mBAUjC;AACD,qBAAa,WAAY,SAAQ,GAAG;IAClC,IAAI,IAAI,WAEP;CACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../../../../src/httpsnippet-lite/esm/targets/javascript/fetch/client.ts"],"names":[],"mappings":"AAgBA,eAAO,MAAM,KAAK;;;;;;;;;;;;;CA6FjB,CAAA"}
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../../../../src/httpsnippet-lite/esm/targets/javascript/fetch/client.ts"],"names":[],"mappings":"AAgBA,eAAO,MAAM,KAAK;;;;;;;;;;;;;CA8FjB,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../../../../src/httpsnippet-lite/esm/targets/node/fetch/client.ts"],"names":[],"mappings":"AAgBA,eAAO,MAAM,KAAK;;;;;;;;;;;;;;CA4HjB,CAAA"}
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../../../../src/httpsnippet-lite/esm/targets/node/fetch/client.ts"],"names":[],"mappings":"AAgBA,eAAO,MAAM,KAAK;;;;;;;;;;;;;;CA6HjB,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../../../../src/httpsnippet-lite/esm/targets/php/guzzle/client.ts"],"names":[],"mappings":"AAoBA,eAAO,MAAM,MAAM;;;;;;;;;;;;;;CA4HlB,CAAA"}
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../../../../src/httpsnippet-lite/esm/targets/php/guzzle/client.ts"],"names":[],"mappings":"AAoBA,eAAO,MAAM,MAAM;;;;;;;;;;;;;;CA0HlB,CAAA"}
@@ -43,7 +43,7 @@ const guzzle = {
43
43
  case 'multipart/form-data': {
44
44
  const fields = [];
45
45
  if (postData.params) {
46
- postData.params.forEach(function (param) {
46
+ postData.params.forEach((param) => {
47
47
  if (param.fileName) {
48
48
  const field = {
49
49
  name: param.name,
@@ -88,9 +88,7 @@ const guzzle = {
88
88
  // construct headers
89
89
  const headers = Object.keys(headersObj)
90
90
  .sort()
91
- .map(function (key) {
92
- return `${opts.indent}${opts.indent}'${key}' => '${escapeForSingleQuotes(headersObj[key])}',`;
93
- });
91
+ .map((key) => `${opts.indent}${opts.indent}'${key}' => '${escapeForSingleQuotes(headersObj[key])}',`);
94
92
  // construct cookies
95
93
  const cookieString = cookies
96
94
  .map((cookie) => `${encodeURIComponent(cookie.name)}=${encodeURIComponent(cookie.value)}`)
@@ -109,7 +109,7 @@ const nsurlsession = {
109
109
  push(' cachePolicy: .useProtocolCachePolicy,');
110
110
  push(
111
111
  // @ts-expect-error needs better types
112
- ` timeoutInterval: ${parseInt(opts.timeout, 10).toFixed(1)})`);
112
+ ` timeoutInterval: ${Number.parseInt(opts.timeout, 10).toFixed(1)})`);
113
113
  push(`request.httpMethod = "${method}"`);
114
114
  if (req.hasHeaders) {
115
115
  push('request.allHTTPHeaderFields = headers');
package/dist/index.js CHANGED
@@ -1 +1,2 @@
1
1
  export { snippetz } from './snippetz.js';
2
+ export { AVAILABLE_CLIENTS } from './types/index.js';
@@ -1 +1 @@
1
- {"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../../../src/plugins/dart/http/http.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAErC;;GAEG;AACH,eAAO,MAAM,QAAQ,EAAE,MA8HtB,CAAA"}
1
+ {"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../../../src/plugins/dart/http/http.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAErC;;GAEG;AACH,eAAO,MAAM,QAAQ,EAAE,MA4GtB,CAAA"}
@@ -36,15 +36,14 @@ const dartHttp = {
36
36
  const { username, password } = options.auth;
37
37
  if (username && password) {
38
38
  const credentials = `${username}:${password}`;
39
- headers['Authorization'] =
40
- `'Basic ' + base64Encode(utf8.encode('${credentials}'))`;
39
+ headers['Authorization'] = `'Basic ' + base64Encode(utf8.encode('${credentials}'))`;
41
40
  }
42
41
  }
43
42
  if (cookieHeader) {
44
43
  headers['Cookie'] = cookieString;
45
44
  }
46
45
  if (Object.keys(headers).length > 0) {
47
- code += ` final headers = <String,String>{\n`;
46
+ code += ' final headers = <String,String>{\n';
48
47
  for (const [key, value] of Object.entries(headers)) {
49
48
  if (value.includes('utf8.encode')) {
50
49
  code += ` '${key}': ${value},\n`;
@@ -53,7 +52,7 @@ const dartHttp = {
53
52
  code += ` '${key}': '${value}',\n`;
54
53
  }
55
54
  }
56
- code += ` };\n\n`;
55
+ code += ' };\n\n';
57
56
  }
58
57
  // Handle query string
59
58
  const queryString = normalizedRequest.queryString?.length
@@ -69,18 +68,17 @@ const dartHttp = {
69
68
  if (normalizedRequest.postData.mimeType === 'application/json') {
70
69
  body = ` final body = r'${normalizedRequest.postData.text}';\n\n`;
71
70
  }
72
- else if (normalizedRequest.postData.mimeType ===
73
- 'application/x-www-form-urlencoded') {
71
+ else if (normalizedRequest.postData.mimeType === 'application/x-www-form-urlencoded') {
74
72
  body = ` final body = '${normalizedRequest.postData.params?.map((param) => `${encodeURIComponent(param.name)}=${encodeURIComponent(param.value ?? '')}`).join('&') || ''}';\n\n`;
75
73
  }
76
74
  else if (normalizedRequest.postData.mimeType === 'multipart/form-data') {
77
- body = ` final body = <String,String>{\n`;
75
+ body = ' final body = <String,String>{\n';
78
76
  for (const param of normalizedRequest.postData.params || []) {
79
77
  const value = param.value || '';
80
78
  const fileName = param.fileName || '';
81
79
  body += ` '${param.name}': '${fileName || value}',\n`;
82
80
  }
83
- body += ` };\n\n`;
81
+ body += ' };\n\n';
84
82
  }
85
83
  else if (normalizedRequest.postData.mimeType === 'application/octet-stream') {
86
84
  body = ` final body = '${normalizedRequest.postData.text}';\n\n`;
@@ -94,8 +92,8 @@ const dartHttp = {
94
92
  const headersPart = Object.keys(headers).length > 0 ? ', headers: headers' : '';
95
93
  const bodyPart = body ? ', body: body' : '';
96
94
  code += ` final response = await http.${method}(Uri.parse('${url}')${headersPart}${bodyPart});\n`;
97
- code += ` print(response.body);\n`;
98
- code += `}`;
95
+ code += ' print(response.body);\n';
96
+ code += '}';
99
97
  return code;
100
98
  },
101
99
  };
@@ -1 +1 @@
1
- {"version":3,"file":"http11.d.ts","sourceRoot":"","sources":["../../../../src/plugins/http/http11/http11.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAGrC;;GAEG;AACH,eAAO,MAAM,UAAU,EAAE,MAQxB,CAAA"}
1
+ {"version":3,"file":"http11.d.ts","sourceRoot":"","sources":["../../../../src/plugins/http/http11/http11.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAErC;;GAEG;AACH,eAAO,MAAM,UAAU,EAAE,MAoHxB,CAAA"}
@@ -1,6 +1,3 @@
1
- import { http11 } from '../../../httpsnippet-lite/esm/targets/http/http1.1/client.js';
2
- import { convertWithHttpSnippetLite } from '../../../utils/convertWithHttpSnippetLite.js';
3
-
4
1
  /**
5
2
  * http/http1.1
6
3
  */
@@ -9,8 +6,100 @@ const httpHttp11 = {
9
6
  client: 'http1.1',
10
7
  title: 'HTTP/1.1',
11
8
  generate(request) {
12
- // TODO: Write an own converter
13
- return convertWithHttpSnippetLite(http11, request);
9
+ // Defaults
10
+ const normalizedRequest = {
11
+ method: 'GET',
12
+ headers: [],
13
+ queryString: [],
14
+ ...request,
15
+ };
16
+ // Normalize method
17
+ normalizedRequest.method = normalizedRequest.method.toUpperCase();
18
+ // Parse URL with error handling
19
+ let url;
20
+ let path;
21
+ try {
22
+ url = new URL(normalizedRequest.url || 'http://');
23
+ path = url.pathname + (url.search || '');
24
+ }
25
+ catch (_error) {
26
+ // Oops, got an invalid URL, use the provided URL directly.
27
+ path = normalizedRequest.url || '/';
28
+ }
29
+ const hostname = url?.hostname || 'UNKNOWN_HOSTNAME';
30
+ // Start building the request
31
+ let requestString = `${normalizedRequest.method} ${path} HTTP/1.1\r\n`;
32
+ // Handle query string parameters
33
+ if (normalizedRequest.queryString.length) {
34
+ const queryString = normalizedRequest.queryString
35
+ .map((param) => `${encodeURIComponent(param.name)}=${encodeURIComponent(param.value)}`)
36
+ .join('&');
37
+ // Append query string to the path
38
+ requestString = `${normalizedRequest.method} ${path}?${queryString} HTTP/1.1\r\n`;
39
+ }
40
+ // Store all headers
41
+ const headers = new Map();
42
+ // Host header
43
+ headers.set('Host', hostname);
44
+ // Passed headers
45
+ normalizedRequest.headers.forEach((header) => {
46
+ if (headers.has(header.name)) {
47
+ headers.set(header.name, `${headers.get(header.name)}, ${header.value}`);
48
+ }
49
+ else {
50
+ headers.set(header.name, header.value);
51
+ }
52
+ });
53
+ // Query string parameters
54
+ if (normalizedRequest.queryString.length) {
55
+ const queryString = normalizedRequest.queryString
56
+ .map((param) => `${encodeURIComponent(param.name)}=${encodeURIComponent(param.value)}`)
57
+ .join('&');
58
+ // Append query string to the path
59
+ requestString = `${normalizedRequest.method} ${path}?${queryString} HTTP/1.1\r\n`;
60
+ }
61
+ // Request body
62
+ let body = '';
63
+ if (normalizedRequest.postData) {
64
+ // Always set the Content-Type header based on postData.mimeType
65
+ if (normalizedRequest.postData.mimeType === 'application/json' && normalizedRequest.postData.text) {
66
+ headers.set('Content-Type', 'application/json');
67
+ body = normalizedRequest.postData.text;
68
+ }
69
+ else if (normalizedRequest.postData.mimeType === 'application/octet-stream' &&
70
+ normalizedRequest.postData.text) {
71
+ headers.set('Content-Type', 'application/octet-stream');
72
+ body = normalizedRequest.postData.text;
73
+ }
74
+ else if (normalizedRequest.postData.mimeType === 'application/x-www-form-urlencoded' &&
75
+ normalizedRequest.postData.params) {
76
+ const formData = normalizedRequest.postData.params
77
+ .map((param) => `${encodeURIComponent(param.name)}=${encodeURIComponent(param.value ?? '')}`)
78
+ .join('&');
79
+ headers.set('Content-Type', 'application/x-www-form-urlencoded');
80
+ body = formData;
81
+ }
82
+ else if (normalizedRequest.postData.mimeType === 'multipart/form-data' && normalizedRequest.postData.params) {
83
+ const boundary = '----WebKitFormBoundary7MA4YWxkTrZu0gW';
84
+ headers.set('Content-Type', `multipart/form-data; boundary=${boundary}`);
85
+ body =
86
+ normalizedRequest.postData.params
87
+ .map((param) => {
88
+ if (param.fileName) {
89
+ return `--${boundary}\r\nContent-Disposition: form-data; name="${param.name}"; filename="${param.fileName}"\r\n\r\n`;
90
+ }
91
+ return `--${boundary}\r\nContent-Disposition: form-data; name="${param.name}"\r\n\r\n${param.value}\r\n`;
92
+ })
93
+ .join('') + `--${boundary}--\r\n`;
94
+ }
95
+ }
96
+ // Add headers to requestString
97
+ headers.forEach((value, name) => {
98
+ requestString += `${name}: ${value}\r\n`;
99
+ });
100
+ // Add body to requestString
101
+ requestString += `\r\n${body}`;
102
+ return requestString;
14
103
  },
15
104
  };
16
105
 
@@ -1 +1 @@
1
- {"version":3,"file":"fetch.d.ts","sourceRoot":"","sources":["../../../../src/plugins/js/fetch/fetch.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAIrC;;GAEG;AACH,eAAO,MAAM,OAAO,EAAE,MA8ErB,CAAA"}
1
+ {"version":3,"file":"fetch.d.ts","sourceRoot":"","sources":["../../../../src/plugins/js/fetch/fetch.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAIrC;;GAEG;AACH,eAAO,MAAM,OAAO,EAAE,MAqErB,CAAA"}
@@ -18,14 +18,10 @@ const jsFetch = {
18
18
  normalizedRequest.method = normalizedRequest.method.toUpperCase();
19
19
  // Reset fetch defaults
20
20
  const options = {
21
- method: normalizedRequest.method === 'GET'
22
- ? undefined
23
- : normalizedRequest.method,
21
+ method: normalizedRequest.method === 'GET' ? undefined : normalizedRequest.method,
24
22
  };
25
23
  // Query
26
- const searchParams = new URLSearchParams(normalizedRequest.queryString
27
- ? arrayToObject(normalizedRequest.queryString)
28
- : undefined);
24
+ const searchParams = new URLSearchParams(normalizedRequest.queryString ? arrayToObject(normalizedRequest.queryString) : undefined);
29
25
  const queryString = searchParams.size ? `?${searchParams.toString()}` : '';
30
26
  // Headers
31
27
  if (normalizedRequest.headers?.length) {
@@ -59,9 +55,7 @@ const jsFetch = {
59
55
  }
60
56
  }
61
57
  // Transform to JSON
62
- const jsonOptions = Object.keys(options).length
63
- ? `, ${objectToString(options)}`
64
- : '';
58
+ const jsonOptions = Object.keys(options).length ? `, ${objectToString(options)}` : '';
65
59
  // Code Template
66
60
  return `fetch('${normalizedRequest.url}${queryString}'${jsonOptions})`;
67
61
  },
@@ -1 +1 @@
1
- {"version":3,"file":"ofetch.d.ts","sourceRoot":"","sources":["../../../../src/plugins/js/ofetch/ofetch.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAIrC;;GAEG;AACH,eAAO,MAAM,QAAQ,EAAE,MAoFtB,CAAA"}
1
+ {"version":3,"file":"ofetch.d.ts","sourceRoot":"","sources":["../../../../src/plugins/js/ofetch/ofetch.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAIrC;;GAEG;AACH,eAAO,MAAM,QAAQ,EAAE,MA6EtB,CAAA"}
@@ -18,14 +18,10 @@ const jsOfetch = {
18
18
  normalizedRequest.method = normalizedRequest.method.toUpperCase();
19
19
  // Reset fetch defaults
20
20
  const options = {
21
- method: normalizedRequest.method === 'GET'
22
- ? undefined
23
- : normalizedRequest.method,
21
+ method: normalizedRequest.method === 'GET' ? undefined : normalizedRequest.method,
24
22
  };
25
23
  // Query
26
- const searchParams = new URLSearchParams(normalizedRequest.queryString
27
- ? arrayToObject(normalizedRequest.queryString)
28
- : undefined);
24
+ const searchParams = new URLSearchParams(normalizedRequest.queryString ? arrayToObject(normalizedRequest.queryString) : undefined);
29
25
  if (searchParams.size) {
30
26
  options.query = {};
31
27
  searchParams.forEach((value, key) => {
@@ -64,9 +60,7 @@ const jsOfetch = {
64
60
  }
65
61
  }
66
62
  // Transform to JSON
67
- const jsonOptions = Object.keys(options).length
68
- ? `, ${objectToString(options)}`
69
- : '';
63
+ const jsonOptions = Object.keys(options).length ? `, ${objectToString(options)}` : '';
70
64
  // Code Template
71
65
  return `import { ofetch } from 'ofetch'
72
66
 
@@ -1 +1 @@
1
- {"version":3,"file":"fetch.d.ts","sourceRoot":"","sources":["../../../../src/plugins/node/fetch/fetch.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAIrC;;GAEG;AACH,eAAO,MAAM,SAAS,EAAE,MA8EvB,CAAA"}
1
+ {"version":3,"file":"fetch.d.ts","sourceRoot":"","sources":["../../../../src/plugins/node/fetch/fetch.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAIrC;;GAEG;AACH,eAAO,MAAM,SAAS,EAAE,MAqEvB,CAAA"}
@@ -18,14 +18,10 @@ const nodeFetch = {
18
18
  normalizedRequest.method = normalizedRequest.method.toUpperCase();
19
19
  // Reset fetch defaults
20
20
  const options = {
21
- method: normalizedRequest.method === 'GET'
22
- ? undefined
23
- : normalizedRequest.method,
21
+ method: normalizedRequest.method === 'GET' ? undefined : normalizedRequest.method,
24
22
  };
25
23
  // Query
26
- const searchParams = new URLSearchParams(normalizedRequest.queryString
27
- ? arrayToObject(normalizedRequest.queryString)
28
- : undefined);
24
+ const searchParams = new URLSearchParams(normalizedRequest.queryString ? arrayToObject(normalizedRequest.queryString) : undefined);
29
25
  const queryString = searchParams.size ? `?${searchParams.toString()}` : '';
30
26
  // Headers
31
27
  if (normalizedRequest.headers?.length) {
@@ -59,9 +55,7 @@ const nodeFetch = {
59
55
  }
60
56
  }
61
57
  // Transform to JSON
62
- const jsonOptions = Object.keys(options).length
63
- ? `, ${objectToString(options)}`
64
- : '';
58
+ const jsonOptions = Object.keys(options).length ? `, ${objectToString(options)}` : '';
65
59
  // Code Template
66
60
  return `fetch('${normalizedRequest.url}${queryString}'${jsonOptions})`;
67
61
  },
@@ -1 +1 @@
1
- {"version":3,"file":"ofetch.d.ts","sourceRoot":"","sources":["../../../../src/plugins/node/ofetch/ofetch.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAIrC;;GAEG;AACH,eAAO,MAAM,UAAU,EAAE,MAoFxB,CAAA"}
1
+ {"version":3,"file":"ofetch.d.ts","sourceRoot":"","sources":["../../../../src/plugins/node/ofetch/ofetch.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAIrC;;GAEG;AACH,eAAO,MAAM,UAAU,EAAE,MA6ExB,CAAA"}
@@ -18,14 +18,10 @@ const nodeOfetch = {
18
18
  normalizedRequest.method = normalizedRequest.method.toUpperCase();
19
19
  // Reset fetch defaults
20
20
  const options = {
21
- method: normalizedRequest.method === 'GET'
22
- ? undefined
23
- : normalizedRequest.method,
21
+ method: normalizedRequest.method === 'GET' ? undefined : normalizedRequest.method,
24
22
  };
25
23
  // Query
26
- const searchParams = new URLSearchParams(normalizedRequest.queryString
27
- ? arrayToObject(normalizedRequest.queryString)
28
- : undefined);
24
+ const searchParams = new URLSearchParams(normalizedRequest.queryString ? arrayToObject(normalizedRequest.queryString) : undefined);
29
25
  if (searchParams.size) {
30
26
  options.query = {};
31
27
  searchParams.forEach((value, key) => {
@@ -64,9 +60,7 @@ const nodeOfetch = {
64
60
  }
65
61
  }
66
62
  // Transform to JSON
67
- const jsonOptions = Object.keys(options).length
68
- ? `, ${objectToString(options)}`
69
- : '';
63
+ const jsonOptions = Object.keys(options).length ? `, ${objectToString(options)}` : '';
70
64
  // Code Template
71
65
  return `import { ofetch } from 'ofetch'
72
66
 
@@ -1 +1 @@
1
- {"version":3,"file":"undici.d.ts","sourceRoot":"","sources":["../../../../src/plugins/node/undici/undici.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAIrC;;GAEG;AACH,eAAO,MAAM,UAAU,EAAE,MAgFxB,CAAA"}
1
+ {"version":3,"file":"undici.d.ts","sourceRoot":"","sources":["../../../../src/plugins/node/undici/undici.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAIrC;;GAEG;AACH,eAAO,MAAM,UAAU,EAAE,MAuExB,CAAA"}
@@ -18,14 +18,10 @@ const nodeUndici = {
18
18
  normalizedRequest.method = normalizedRequest.method.toUpperCase();
19
19
  // Reset undici defaults
20
20
  const options = {
21
- method: normalizedRequest.method === 'GET'
22
- ? undefined
23
- : normalizedRequest.method,
21
+ method: normalizedRequest.method === 'GET' ? undefined : normalizedRequest.method,
24
22
  };
25
23
  // Query
26
- const searchParams = new URLSearchParams(normalizedRequest.queryString
27
- ? arrayToObject(normalizedRequest.queryString)
28
- : undefined);
24
+ const searchParams = new URLSearchParams(normalizedRequest.queryString ? arrayToObject(normalizedRequest.queryString) : undefined);
29
25
  const queryString = searchParams.size ? `?${searchParams.toString()}` : '';
30
26
  // Headers
31
27
  if (normalizedRequest.headers?.length) {
@@ -59,9 +55,7 @@ const nodeUndici = {
59
55
  }
60
56
  }
61
57
  // Transform to JSON
62
- const jsonOptions = Object.keys(options).length
63
- ? `, ${objectToString(options)}`
64
- : '';
58
+ const jsonOptions = Object.keys(options).length ? `, ${objectToString(options)}` : '';
65
59
  // Code Template
66
60
  return `import { request } from 'undici'
67
61
 
@@ -1 +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,SAAS,CAAA;AAErC;;GAEG;AACH,eAAO,MAAM,SAAS,EAAE,MAqHvB,CAAA"}
1
+ {"version":3,"file":"curl.d.ts","sourceRoot":"","sources":["../../../../src/plugins/shell/curl/curl.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAErC;;GAEG;AACH,eAAO,MAAM,SAAS,EAAE,MAyGvB,CAAA"}
@@ -75,16 +75,14 @@ const shellCurl = {
75
75
  else if (normalizedRequest.postData.mimeType === 'application/octet-stream') {
76
76
  parts.push(`--data-binary '${normalizedRequest.postData.text}'`);
77
77
  }
78
- else if (normalizedRequest.postData.mimeType ===
79
- 'application/x-www-form-urlencoded' &&
78
+ else if (normalizedRequest.postData.mimeType === 'application/x-www-form-urlencoded' &&
80
79
  normalizedRequest.postData.params) {
81
80
  // Handle URL-encoded form data
82
81
  normalizedRequest.postData.params.forEach((param) => {
83
82
  parts.push(`--data-urlencode '${encodeURIComponent(param.name)}=${param.value}'`);
84
83
  });
85
84
  }
86
- else if (normalizedRequest.postData.mimeType === 'multipart/form-data' &&
87
- normalizedRequest.postData.params) {
85
+ else if (normalizedRequest.postData.mimeType === 'multipart/form-data' && normalizedRequest.postData.params) {
88
86
  // Handle multipart form data
89
87
  normalizedRequest.postData.params.forEach((param) => {
90
88
  if (param.fileName !== undefined) {
@@ -1 +1 @@
1
- {"version":3,"file":"snippetz.d.ts","sourceRoot":"","sources":["../src/snippetz.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAE7D;;GAEG;AACH,wBAAgB,QAAQ;UAWd,CAAC,SAAS,QAAQ,UACd,CAAC,UACD,QAAQ,CAAC,CAAC,CAAC,WACV,OAAO,CAAC,UAAU,CAAC;;;;;;iBAbZ,CAAC,SAAS,QAAQ,UAC5B,CAAC,GAAG,MAAM,UACV,QAAQ,CAAC,CAAC,CAAC,GAAG,MAAM;cA2BlB,CAAC,SAAS,QAAQ,UAClB,CAAC,GAAG,MAAM,UACV,QAAQ,CAAC,CAAC,CAAC,GAAG,MAAM;EAKjC"}
1
+ {"version":3,"file":"snippetz.d.ts","sourceRoot":"","sources":["../src/snippetz.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAE7D;;GAEG;AACH,wBAAgB,QAAQ;UAMd,CAAC,SAAS,QAAQ,UAAU,CAAC,UAAU,QAAQ,CAAC,CAAC,CAAC,WAAW,OAAO,CAAC,UAAU,CAAC;;;;;;iBALpE,CAAC,SAAS,QAAQ,UAAU,CAAC,GAAG,MAAM,UAAU,QAAQ,CAAC,CAAC,CAAC,GAAG,MAAM;cAoB5E,CAAC,SAAS,QAAQ,UAAU,CAAC,GAAG,MAAM,UAAU,QAAQ,CAAC,CAAC,CAAC,GAAG,MAAM;EAIjF"}
package/dist/snippetz.js CHANGED
@@ -5,9 +5,7 @@ import { clients } from './clients.js';
5
5
  */
6
6
  function snippetz() {
7
7
  function findPlugin(target, client) {
8
- return clients
9
- .find(({ key }) => key === target)
10
- ?.clients.find((plugin) => plugin.client === client);
8
+ return clients.find(({ key }) => key === target)?.clients.find((plugin) => plugin.client === client);
11
9
  }
12
10
  return {
13
11
  print(target, client, request) {
@@ -3,43 +3,8 @@ export type { Request as HarRequest } from 'har-format';
3
3
  /**
4
4
  * List of available clients
5
5
  */
6
- export type AvailableClients = [
7
- 'c/libcurl',
8
- 'clojure/clj_http',
9
- 'csharp/httpclient',
10
- 'csharp/restsharp',
11
- 'go/native',
12
- 'http/http1.1',
13
- 'java/asynchttp',
14
- 'java/nethttp',
15
- 'java/okhttp',
16
- 'java/unirest',
17
- 'js/axios',
18
- 'js/fetch',
19
- 'js/jquery',
20
- 'js/ofetch',
21
- 'js/xhr',
22
- 'kotlin/okhttp',
23
- 'node/axios',
24
- 'node/fetch',
25
- 'node/ofetch',
26
- 'node/undici',
27
- 'objc/nsurlsession',
28
- 'ocaml/cohttp',
29
- 'php/curl',
30
- 'php/guzzle',
31
- 'powershell/restmethod',
32
- 'powershell/webrequest',
33
- 'python/python3',
34
- 'python/requests',
35
- 'r/httr',
36
- 'ruby/native',
37
- 'shell/curl',
38
- 'shell/httpie',
39
- 'shell/wget',
40
- 'swift/nsurlsession',
41
- 'dart/http'
42
- ];
6
+ export declare const AVAILABLE_CLIENTS: readonly ["c/libcurl", "clojure/clj_http", "csharp/httpclient", "csharp/restsharp", "go/native", "http/http1.1", "java/asynchttp", "java/nethttp", "java/okhttp", "java/unirest", "js/axios", "js/fetch", "js/jquery", "js/ofetch", "js/xhr", "kotlin/okhttp", "node/axios", "node/fetch", "node/ofetch", "node/undici", "objc/nsurlsession", "ocaml/cohttp", "php/curl", "php/guzzle", "powershell/restmethod", "powershell/webrequest", "python/python3", "python/requests", "r/httr", "ruby/native", "shell/curl", "shell/httpie", "shell/wget", "swift/nsurlsession", "dart/http"];
7
+ export type AvailableClients = typeof AVAILABLE_CLIENTS;
43
8
  /** Programming language */
44
9
  export type TargetId = AvailableClients[number] extends `${infer T}/${string}` ? T : never;
45
10
  /** Configuration for a target */
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,IAA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AAkB;AAClB,MAAM,MAAM,QAAQ,CAAC,CAAC,SAAS,MAAM,IAAI,CAAC,SAAS,QAAQ,GACvD,OAAO,CAAC,gBAAgB,CAAC,MAAM,CAAC,EAAE,GAAG,CAAC,IAAI,MAAM,EAAE,CAAC,SAAS,GAAG,CAAC,IAAI,MAAM,CAAC,EAAE,GAC3E,CAAC,GACD,KAAK,GACP,KAAK,CAAA;AAET,uCAAuC;AACvC,MAAM,MAAM,MAAM,GAAG;IACnB,mCAAmC;IACnC,MAAM,EAAE,QAAQ,CAAA;IAChB,oCAAoC;IACpC,MAAM,EAAE,QAAQ,CAAC,QAAQ,CAAC,CAAA;IAC1B,+BAA+B;IAC/B,KAAK,EAAE,MAAM,CAAA;IACb,8BAA8B;IAC9B,QAAQ,EAAE,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC,UAAU,CAAC,EAAE,aAAa,CAAC,EAAE,mBAAmB,KAAK,MAAM,CAAA;CACzF,CAAA;AAED;;GAEG;AACH,MAAM,MAAM,mBAAmB,GAAG;IAChC,mDAAmD;IACnD,IAAI,CAAC,EAAE;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAA;KAAE,CAAA;CAC9C,CAAA"}
@@ -1 +1,42 @@
1
+ /**
2
+ * List of available clients
3
+ */
4
+ const AVAILABLE_CLIENTS = [
5
+ 'c/libcurl',
6
+ 'clojure/clj_http',
7
+ 'csharp/httpclient',
8
+ 'csharp/restsharp',
9
+ 'go/native',
10
+ 'http/http1.1',
11
+ 'java/asynchttp',
12
+ 'java/nethttp',
13
+ 'java/okhttp',
14
+ 'java/unirest',
15
+ 'js/axios',
16
+ 'js/fetch',
17
+ 'js/jquery',
18
+ 'js/ofetch',
19
+ 'js/xhr',
20
+ 'kotlin/okhttp',
21
+ 'node/axios',
22
+ 'node/fetch',
23
+ 'node/ofetch',
24
+ 'node/undici',
25
+ 'objc/nsurlsession',
26
+ 'ocaml/cohttp',
27
+ 'php/curl',
28
+ 'php/guzzle',
29
+ 'powershell/restmethod',
30
+ 'powershell/webrequest',
31
+ 'python/python3',
32
+ 'python/requests',
33
+ 'r/httr',
34
+ 'ruby/native',
35
+ 'shell/curl',
36
+ 'shell/httpie',
37
+ 'shell/wget',
38
+ 'swift/nsurlsession',
39
+ 'dart/http',
40
+ ];
1
41
 
42
+ export { AVAILABLE_CLIENTS };
@@ -1 +1 @@
1
- {"version":3,"file":"convertWithHttpSnippetLite.d.ts","sourceRoot":"","sources":["../../src/utils/convertWithHttpSnippetLite.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AAEzC;;GAEG;AACH,wBAAgB,0BAA0B,CAExC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC/B,OAAO,CAAC,EAAE,OAAO,CAAC,UAAU,CAAC,GAC5B,MAAM,CAkHR"}
1
+ {"version":3,"file":"convertWithHttpSnippetLite.d.ts","sourceRoot":"","sources":["../../src/utils/convertWithHttpSnippetLite.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AAEzC;;GAEG;AACH,wBAAgB,0BAA0B,CAExC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC/B,OAAO,CAAC,EAAE,OAAO,CAAC,UAAU,CAAC,GAC5B,MAAM,CA+GR"}
@@ -1 +1 @@
1
- {"version":3,"file":"objectToString.d.ts","sourceRoot":"","sources":["../../src/utils/objectToString.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,SAAI,GAAG,MAAM,CAyD3E"}
1
+ {"version":3,"file":"objectToString.d.ts","sourceRoot":"","sources":["../../src/utils/objectToString.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,SAAI,GAAG,MAAM,CAoD3E"}
@@ -17,12 +17,10 @@ function objectToString(obj, indent = 0) {
17
17
  if (typeof item === 'string') {
18
18
  return `'${item}'`;
19
19
  }
20
- else if (item && typeof item === 'object') {
20
+ if (item && typeof item === 'object') {
21
21
  return objectToString(item, indent + 2);
22
22
  }
23
- else {
24
- return item;
25
- }
23
+ return item;
26
24
  })
27
25
  .join(`, ${innerIndentation}`);
28
26
  parts.push(`${innerIndentation}${formattedKey}: [${arrayString}]`);