@scalar/snippetz 0.9.29 → 0.9.31

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 (123) hide show
  1. package/dist/libs/browser-request.d.ts +14 -0
  2. package/dist/libs/browser-request.d.ts.map +1 -0
  3. package/dist/libs/browser-request.js +64 -0
  4. package/dist/libs/http.d.ts.map +1 -1
  5. package/dist/libs/java.d.ts +6 -0
  6. package/dist/libs/java.d.ts.map +1 -0
  7. package/dist/libs/java.js +21 -0
  8. package/dist/libs/julia.d.ts.map +1 -1
  9. package/dist/libs/julia.js +2 -1
  10. package/dist/libs/powershell.d.ts +4 -0
  11. package/dist/libs/powershell.d.ts.map +1 -0
  12. package/dist/libs/powershell.js +38 -0
  13. package/dist/libs/prepare-request.d.ts +21 -0
  14. package/dist/libs/prepare-request.d.ts.map +1 -0
  15. package/dist/libs/prepare-request.js +58 -0
  16. package/dist/plugins/clojure/clj_http/clj_http.d.ts.map +1 -1
  17. package/dist/plugins/clojure/clj_http/clj_http.js +2 -1
  18. package/dist/plugins/csharp/restsharp/restsharp.js +2 -2
  19. package/dist/plugins/dart/http/http.d.ts.map +1 -1
  20. package/dist/plugins/java/asynchttp/asynchttp.d.ts +1 -3
  21. package/dist/plugins/java/asynchttp/asynchttp.d.ts.map +1 -1
  22. package/dist/plugins/java/asynchttp/asynchttp.js +16 -8
  23. package/dist/plugins/java/nethttp/nethttp.d.ts +1 -3
  24. package/dist/plugins/java/nethttp/nethttp.d.ts.map +1 -1
  25. package/dist/plugins/java/nethttp/nethttp.js +17 -8
  26. package/dist/plugins/java/okhttp/okhttp.d.ts +1 -3
  27. package/dist/plugins/java/okhttp/okhttp.d.ts.map +1 -1
  28. package/dist/plugins/java/okhttp/okhttp.js +50 -8
  29. package/dist/plugins/java/unirest/unirest.d.ts +1 -3
  30. package/dist/plugins/java/unirest/unirest.d.ts.map +1 -1
  31. package/dist/plugins/java/unirest/unirest.js +13 -8
  32. package/dist/plugins/js/jquery/jquery.d.ts +1 -3
  33. package/dist/plugins/js/jquery/jquery.d.ts.map +1 -1
  34. package/dist/plugins/js/jquery/jquery.js +22 -8
  35. package/dist/plugins/js/xhr/xhr.d.ts +1 -3
  36. package/dist/plugins/js/xhr/xhr.d.ts.map +1 -1
  37. package/dist/plugins/js/xhr/xhr.js +13 -8
  38. package/dist/plugins/kotlin/okhttp/okhttp.d.ts.map +1 -1
  39. package/dist/plugins/kotlin/okhttp/okhttp.js +15 -9
  40. package/dist/plugins/ocaml/cohttp/cohttp.d.ts +1 -3
  41. package/dist/plugins/ocaml/cohttp/cohttp.d.ts.map +1 -1
  42. package/dist/plugins/ocaml/cohttp/cohttp.js +32 -8
  43. package/dist/plugins/php/laravel/laravel.d.ts.map +1 -1
  44. package/dist/plugins/php/laravel/laravel.js +2 -1
  45. package/dist/plugins/powershell/restmethod/restmethod.d.ts +1 -3
  46. package/dist/plugins/powershell/restmethod/restmethod.d.ts.map +1 -1
  47. package/dist/plugins/powershell/restmethod/restmethod.js +4 -8
  48. package/dist/plugins/powershell/webrequest/webrequest.d.ts +1 -3
  49. package/dist/plugins/powershell/webrequest/webrequest.d.ts.map +1 -1
  50. package/dist/plugins/powershell/webrequest/webrequest.js +4 -8
  51. package/dist/plugins/python/requestsLike.d.ts.map +1 -1
  52. package/dist/plugins/r/httr2/httr2.d.ts.map +1 -1
  53. package/dist/plugins/r/httr2/httr2.js +2 -1
  54. package/dist/plugins/shared/axios.d.ts.map +1 -1
  55. package/dist/plugins/shell/curl/curl.d.ts.map +1 -1
  56. package/dist/plugins/shell/curl/curl.js +12 -1
  57. package/dist/plugins/shell/httpie/httpie.d.ts +1 -3
  58. package/dist/plugins/shell/httpie/httpie.d.ts.map +1 -1
  59. package/dist/plugins/shell/httpie/httpie.js +34 -8
  60. package/package.json +3 -10
  61. package/dist/httpsnippet-lite/helpers/code-builder.d.ts +0 -51
  62. package/dist/httpsnippet-lite/helpers/code-builder.d.ts.map +0 -1
  63. package/dist/httpsnippet-lite/helpers/code-builder.js +0 -87
  64. package/dist/httpsnippet-lite/helpers/escape.d.ts +0 -48
  65. package/dist/httpsnippet-lite/helpers/escape.d.ts.map +0 -1
  66. package/dist/httpsnippet-lite/helpers/escape.js +0 -70
  67. package/dist/httpsnippet-lite/helpers/headers.d.ts +0 -15
  68. package/dist/httpsnippet-lite/helpers/headers.d.ts.map +0 -1
  69. package/dist/httpsnippet-lite/helpers/headers.js +0 -18
  70. package/dist/httpsnippet-lite/helpers/reducer.d.ts +0 -2
  71. package/dist/httpsnippet-lite/helpers/reducer.d.ts.map +0 -1
  72. package/dist/httpsnippet-lite/helpers/reducer.js +0 -1
  73. package/dist/httpsnippet-lite/helpers/shell.d.ts +0 -6
  74. package/dist/httpsnippet-lite/helpers/shell.d.ts.map +0 -1
  75. package/dist/httpsnippet-lite/helpers/shell.js +0 -13
  76. package/dist/httpsnippet-lite/helpers/snippet-request.d.ts +0 -33
  77. package/dist/httpsnippet-lite/helpers/snippet-request.d.ts.map +0 -1
  78. package/dist/httpsnippet-lite/helpers/snippet-request.js +0 -1
  79. package/dist/httpsnippet-lite/helpers/url.d.ts +0 -4
  80. package/dist/httpsnippet-lite/helpers/url.d.ts.map +0 -1
  81. package/dist/httpsnippet-lite/helpers/url.js +0 -5
  82. package/dist/httpsnippet-lite/targets/java/asynchttp/client.d.ts +0 -12
  83. package/dist/httpsnippet-lite/targets/java/asynchttp/client.d.ts.map +0 -1
  84. package/dist/httpsnippet-lite/targets/java/asynchttp/client.js +0 -33
  85. package/dist/httpsnippet-lite/targets/java/nethttp/client.d.ts +0 -3
  86. package/dist/httpsnippet-lite/targets/java/nethttp/client.d.ts.map +0 -1
  87. package/dist/httpsnippet-lite/targets/java/nethttp/client.js +0 -41
  88. package/dist/httpsnippet-lite/targets/java/okhttp/client.d.ts +0 -12
  89. package/dist/httpsnippet-lite/targets/java/okhttp/client.d.ts.map +0 -1
  90. package/dist/httpsnippet-lite/targets/java/okhttp/client.js +0 -87
  91. package/dist/httpsnippet-lite/targets/java/unirest/client.d.ts +0 -12
  92. package/dist/httpsnippet-lite/targets/java/unirest/client.d.ts.map +0 -1
  93. package/dist/httpsnippet-lite/targets/java/unirest/client.js +0 -42
  94. package/dist/httpsnippet-lite/targets/javascript/jquery/client.d.ts +0 -3
  95. package/dist/httpsnippet-lite/targets/javascript/jquery/client.d.ts.map +0 -1
  96. package/dist/httpsnippet-lite/targets/javascript/jquery/client.js +0 -80
  97. package/dist/httpsnippet-lite/targets/javascript/xhr/client.d.ts +0 -3
  98. package/dist/httpsnippet-lite/targets/javascript/xhr/client.d.ts.map +0 -1
  99. package/dist/httpsnippet-lite/targets/javascript/xhr/client.js +0 -78
  100. package/dist/httpsnippet-lite/targets/ocaml/cohttp/client.d.ts +0 -3
  101. package/dist/httpsnippet-lite/targets/ocaml/cohttp/client.d.ts.map +0 -1
  102. package/dist/httpsnippet-lite/targets/ocaml/cohttp/client.js +0 -61
  103. package/dist/httpsnippet-lite/targets/powershell/common.d.ts +0 -3
  104. package/dist/httpsnippet-lite/targets/powershell/common.d.ts.map +0 -1
  105. package/dist/httpsnippet-lite/targets/powershell/common.js +0 -48
  106. package/dist/httpsnippet-lite/targets/powershell/restmethod/client.d.ts +0 -3
  107. package/dist/httpsnippet-lite/targets/powershell/restmethod/client.d.ts.map +0 -1
  108. package/dist/httpsnippet-lite/targets/powershell/restmethod/client.js +0 -10
  109. package/dist/httpsnippet-lite/targets/powershell/webrequest/client.d.ts +0 -3
  110. package/dist/httpsnippet-lite/targets/powershell/webrequest/client.d.ts.map +0 -1
  111. package/dist/httpsnippet-lite/targets/powershell/webrequest/client.js +0 -10
  112. package/dist/httpsnippet-lite/targets/shell/httpie/client.d.ts +0 -12
  113. package/dist/httpsnippet-lite/targets/shell/httpie/client.d.ts.map +0 -1
  114. package/dist/httpsnippet-lite/targets/shell/httpie/client.js +0 -124
  115. package/dist/httpsnippet-lite/targets/target.d.ts +0 -19
  116. package/dist/httpsnippet-lite/targets/target.d.ts.map +0 -1
  117. package/dist/httpsnippet-lite/targets/target.js +0 -1
  118. package/dist/utils/convertWithHttpSnippetLite.d.ts +0 -8
  119. package/dist/utils/convertWithHttpSnippetLite.d.ts.map +0 -1
  120. package/dist/utils/convertWithHttpSnippetLite.js +0 -102
  121. package/dist/utils/index.d.ts +0 -2
  122. package/dist/utils/index.d.ts.map +0 -1
  123. package/dist/utils/index.js +0 -1
@@ -1,78 +0,0 @@
1
- /**
2
- * @description
3
- * HTTP code snippet generator for native XMLHttpRequest
4
- *
5
- * @author
6
- * @AhmadNassri
7
- *
8
- * for any questions or issues regarding the generated code snippet, please open an issue mentioning the author.
9
- */
10
- import stringifyObject from 'stringify-object';
11
- import { CodeBuilder } from '../../../../httpsnippet-lite/helpers/code-builder.js';
12
- import { escapeForSingleQuotes } from '../../../../httpsnippet-lite/helpers/escape.js';
13
- import { getHeader, getHeaderName, hasHeader } from '../../../../httpsnippet-lite/helpers/headers.js';
14
- export const xhr = {
15
- info: {
16
- key: 'xhr',
17
- title: 'XMLHttpRequest',
18
- link: 'https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest',
19
- description: 'W3C Standard API that provides scripted client functionality',
20
- },
21
- convert: ({ postData, allHeaders, method, fullUrl }, options) => {
22
- let _a;
23
- const opts = {
24
- indent: ' ',
25
- cors: true,
26
- ...options,
27
- };
28
- const { blank, push, join } = new CodeBuilder({ indent: opts.indent });
29
- switch (postData === null || postData === void 0 ? void 0 : postData.mimeType) {
30
- case 'application/json':
31
- push(`const data = JSON.stringify(${stringifyObject(postData?.jsonObj, {
32
- indent: opts.indent,
33
- })});`);
34
- blank();
35
- break;
36
- case 'multipart/form-data':
37
- if (!postData?.params) {
38
- break;
39
- }
40
- push('const data = new FormData();');
41
- postData.params.forEach((param) => {
42
- push(`data.append('${param.name}', '${param.value || param.fileName || ''}');`);
43
- });
44
- // remove the contentType header
45
- if (hasHeader(allHeaders, 'content-type')) {
46
- if ((_a = getHeader(allHeaders, 'content-type')) === null || _a === void 0 ? void 0 : _a.includes('boundary')) {
47
- const headerName = getHeaderName(allHeaders, 'content-type');
48
- if (headerName) {
49
- delete allHeaders[headerName];
50
- }
51
- }
52
- }
53
- blank();
54
- break;
55
- default:
56
- push(`const data = ${(postData === null || postData === void 0 ? void 0 : postData.text) ? `'${postData.text}'` : 'null'};`);
57
- blank();
58
- }
59
- push('const xhr = new XMLHttpRequest();');
60
- if (opts.cors) {
61
- push('xhr.withCredentials = true;');
62
- }
63
- blank();
64
- push("xhr.addEventListener('readystatechange', function () {");
65
- push('if (this.readyState === this.DONE) {', 1);
66
- push('console.log(this.responseText);', 2);
67
- push('}', 1);
68
- push('});');
69
- blank();
70
- push(`xhr.open('${method}', '${fullUrl}');`);
71
- Object.keys(allHeaders).forEach((key) => {
72
- push(`xhr.setRequestHeader('${key}', '${escapeForSingleQuotes(allHeaders[key])}');`);
73
- });
74
- blank();
75
- push('xhr.send(data);');
76
- return join();
77
- },
78
- };
@@ -1,3 +0,0 @@
1
- import type { Client } from '../../../../httpsnippet-lite/targets/target.js';
2
- export declare const cohttp: Client;
3
- //# sourceMappingURL=client.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../../../src/httpsnippet-lite/targets/ocaml/cohttp/client.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mCAAmC,CAAA;AAE/D,eAAO,MAAM,MAAM,EAAE,MAkDpB,CAAA"}
@@ -1,61 +0,0 @@
1
- /**
2
- * @description
3
- * HTTP code snippet generator for OCaml using CoHTTP.
4
- *
5
- * @author
6
- * @SGrondin
7
- *
8
- * for any questions or issues regarding the generated code snippet, please open an issue mentioning the author.
9
- */
10
- import { CodeBuilder } from '../../../../httpsnippet-lite/helpers/code-builder.js';
11
- import { escapeForDoubleQuotes } from '../../../../httpsnippet-lite/helpers/escape.js';
12
- export const cohttp = {
13
- info: {
14
- key: 'cohttp',
15
- title: 'CoHTTP',
16
- link: 'https://github.com/mirage/ocaml-cohttp',
17
- description: 'Cohttp is a very lightweight HTTP server using Lwt or Async for OCaml',
18
- },
19
- convert: ({ fullUrl, allHeaders, postData, method }, options) => {
20
- const opts = {
21
- indent: ' ',
22
- ...options,
23
- };
24
- const methods = ['get', 'post', 'head', 'delete', 'patch', 'put', 'options'];
25
- const { push, blank, join } = new CodeBuilder({ indent: opts.indent });
26
- push('open Cohttp_lwt_unix');
27
- push('open Cohttp');
28
- push('open Lwt');
29
- blank();
30
- push(`let uri = Uri.of_string "${fullUrl}" in`);
31
- // Add headers, including the cookies
32
- const headers = Object.keys(allHeaders);
33
- if (headers.length === 1) {
34
- push(`let headers = Header.add (Header.init ()) "${headers[0]}" "${escapeForDoubleQuotes(allHeaders[headers[0]])}" in`);
35
- }
36
- else if (headers.length > 1) {
37
- push('let headers = Header.add_list (Header.init ()) [');
38
- headers.forEach((key) => {
39
- push(`("${key}", "${escapeForDoubleQuotes(allHeaders[key])}");`, 1);
40
- });
41
- push('] in');
42
- }
43
- // Add body
44
- if (postData === null || postData === void 0 ? void 0 : postData.text) {
45
- // Just text
46
- push(`let body = Cohttp_lwt_body.of_string ${JSON.stringify(postData.text)} in`);
47
- }
48
- // Do the request
49
- blank();
50
- const h = headers.length ? '~headers ' : '';
51
- const b = (postData === null || postData === void 0 ? void 0 : postData.text) ? '~body ' : '';
52
- const m = methods.includes(method.toLowerCase())
53
- ? `\`${method.toUpperCase()}`
54
- : `(Code.method_of_string "${method}")`;
55
- push(`Client.call ${h}${b}${m} uri`);
56
- // Catch result
57
- push('>>= fun (res, body_stream) ->');
58
- push('(* Do stuff with the result *)', 1);
59
- return join();
60
- },
61
- };
@@ -1,3 +0,0 @@
1
- import type { Converter } from '../../../httpsnippet-lite/targets/target.js';
2
- export declare const generatePowershellConvert: (command: string) => Converter<Record<string, any>>;
3
- //# sourceMappingURL=common.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../../../src/httpsnippet-lite/targets/powershell/common.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mCAAmC,CAAA;AAElE,eAAO,MAAM,yBAAyB,GAAI,SAAS,MAAM,KAAG,SAAS,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAsDxF,CAAA"}
@@ -1,48 +0,0 @@
1
- import { CodeBuilder } from '../../../httpsnippet-lite/helpers/code-builder.js';
2
- import { escapeString } from '../../../httpsnippet-lite/helpers/escape.js';
3
- import { getHeader } from '../../../httpsnippet-lite/helpers/headers.js';
4
- export const generatePowershellConvert = (command) => {
5
- const convert = ({ method, headersObj, cookies, uriObj, fullUrl, postData, allHeaders, }) => {
6
- const { push, join } = new CodeBuilder();
7
- const methods = ['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'HEAD', 'OPTIONS'];
8
- if (!methods.includes(method.toUpperCase())) {
9
- return 'Method not supported';
10
- }
11
- const commandOptions = [];
12
- // Add headers, including the cookies
13
- const headers = Object.keys(headersObj);
14
- // construct headers
15
- if (headers.length) {
16
- push('$headers=@{}');
17
- headers.forEach((key) => {
18
- if (key !== 'connection') {
19
- // Not allowed
20
- push(`$headers.Add("${key}", "${escapeString(headersObj[key], { escapeChar: '`' })}")`);
21
- }
22
- });
23
- commandOptions.push('-Headers $headers');
24
- }
25
- // construct cookies
26
- if (cookies.length) {
27
- push('$session = New-Object Microsoft.PowerShell.Commands.WebRequestSession');
28
- cookies.forEach((cookie) => {
29
- push('$cookie = New-Object System.Net.Cookie');
30
- push(`$cookie.Name = '${cookie.name}'`);
31
- push(`$cookie.Value = '${cookie.value}'`);
32
- push(`$cookie.Domain = '${uriObj.host}'`);
33
- push('$session.Cookies.Add($cookie)');
34
- });
35
- commandOptions.push('-WebSession $session');
36
- }
37
- if (postData === null || postData === void 0 ? void 0 : postData.text) {
38
- commandOptions.push(`-ContentType '${escapeString(getHeader(allHeaders, 'content-type'), {
39
- delimiter: "'",
40
- escapeChar: '`',
41
- })}'`);
42
- commandOptions.push(`-Body '${postData.text}'`);
43
- }
44
- push(`$response = ${command} -Uri '${fullUrl}' -Method ${method} ${commandOptions.join(' ')}`);
45
- return join();
46
- };
47
- return convert;
48
- };
@@ -1,3 +0,0 @@
1
- import type { Client } from '../../../../httpsnippet-lite/targets/target.js';
2
- export declare const restmethod: Client;
3
- //# sourceMappingURL=client.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../../../src/httpsnippet-lite/targets/powershell/restmethod/client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,sCAAsC,CAAA;AAIlE,eAAO,MAAM,UAAU,EAAE,MAQxB,CAAA"}
@@ -1,10 +0,0 @@
1
- import { generatePowershellConvert } from '../common.js';
2
- export const restmethod = {
3
- info: {
4
- key: 'restmethod',
5
- title: 'Invoke-RestMethod',
6
- link: 'https://docs.microsoft.com/en-us/powershell/module/Microsoft.PowerShell.Utility/Invoke-RestMethod',
7
- description: 'Powershell Invoke-RestMethod client',
8
- },
9
- convert: generatePowershellConvert('Invoke-RestMethod'),
10
- };
@@ -1,3 +0,0 @@
1
- import type { Client } from '../../../../httpsnippet-lite/targets/target.js';
2
- export declare const webrequest: Client;
3
- //# sourceMappingURL=client.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../../../src/httpsnippet-lite/targets/powershell/webrequest/client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,sCAAsC,CAAA;AAIlE,eAAO,MAAM,UAAU,EAAE,MAQxB,CAAA"}
@@ -1,10 +0,0 @@
1
- import { generatePowershellConvert } from '../common.js';
2
- export const webrequest = {
3
- info: {
4
- key: 'webrequest',
5
- title: 'Invoke-WebRequest',
6
- link: 'https://docs.microsoft.com/en-us/powershell/module/Microsoft.PowerShell.Utility/Invoke-WebRequest',
7
- description: 'Powershell Invoke-WebRequest client',
8
- },
9
- convert: generatePowershellConvert('Invoke-WebRequest'),
10
- };
@@ -1,12 +0,0 @@
1
- /**
2
- * @description
3
- * HTTP code snippet generator for the Shell using HTTPie.
4
- *
5
- * @author
6
- * @AhmadNassri
7
- *
8
- * for any questions or issues regarding the generated code snippet, please open an issue mentioning the author.
9
- */
10
- import type { Client } from '../../../../httpsnippet-lite/targets/target.js';
11
- export declare const httpie: Client;
12
- //# sourceMappingURL=client.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../../../src/httpsnippet-lite/targets/shell/httpie/client.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAIH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mCAAmC,CAAA;AAE/D,eAAO,MAAM,MAAM,EAAE,MA8GpB,CAAA"}
@@ -1,124 +0,0 @@
1
- /**
2
- * @description
3
- * HTTP code snippet generator for the Shell using HTTPie.
4
- *
5
- * @author
6
- * @AhmadNassri
7
- *
8
- * for any questions or issues regarding the generated code snippet, please open an issue mentioning the author.
9
- */
10
- import { CodeBuilder } from '../../../../httpsnippet-lite/helpers/code-builder.js';
11
- import { shellQuote } from '../../../../httpsnippet-lite/helpers/shell.js';
12
- export const httpie = {
13
- info: {
14
- key: 'httpie',
15
- title: 'HTTPie',
16
- link: 'http://httpie.org/',
17
- description: 'a CLI, cURL-like tool for humans',
18
- },
19
- convert: ({ allHeaders, postData, queryObj, fullUrl, method, url }, options) => {
20
- const opts = {
21
- body: false,
22
- cert: false,
23
- headers: false,
24
- indent: ' ',
25
- pretty: false,
26
- print: false,
27
- queryParams: false,
28
- short: false,
29
- style: false,
30
- timeout: false,
31
- verbose: false,
32
- verify: false,
33
- ...options,
34
- };
35
- const { push, join, unshift } = new CodeBuilder({
36
- indent: opts.indent,
37
- // @ts-expect-error SEEMS LEGIT
38
- join: opts.indent !== false ? ` \\\n${opts.indent}` : ' ',
39
- });
40
- let raw = false;
41
- const flags = [];
42
- if (opts.headers) {
43
- flags.push(opts.short ? '-h' : '--headers');
44
- }
45
- if (opts.body) {
46
- flags.push(opts.short ? '-b' : '--body');
47
- }
48
- if (opts.verbose) {
49
- flags.push(opts.short ? '-v' : '--verbose');
50
- }
51
- if (opts.print) {
52
- flags.push(`${opts.short ? '-p' : '--print'}=${opts.print}`);
53
- }
54
- if (opts.verify) {
55
- flags.push(`--verify=${opts.verify}`);
56
- }
57
- if (opts.cert) {
58
- flags.push(`--cert=${opts.cert}`);
59
- }
60
- if (opts.pretty) {
61
- flags.push(`--pretty=${opts.pretty}`);
62
- }
63
- if (opts.style) {
64
- flags.push(`--style=${opts.style}`);
65
- }
66
- if (opts.timeout) {
67
- flags.push(`--timeout=${opts.timeout}`);
68
- }
69
- // construct query params
70
- if (opts.queryParams) {
71
- Object.keys(queryObj).forEach((name) => {
72
- const value = queryObj[name];
73
- if (Array.isArray(value)) {
74
- value.forEach((val) => {
75
- push(`${name}==${shellQuote(val)}`);
76
- });
77
- }
78
- else {
79
- push(`${name}==${shellQuote(value)}`);
80
- }
81
- });
82
- }
83
- // construct headers
84
- Object.keys(allHeaders)
85
- .sort()
86
- .forEach((key) => {
87
- push(`${key}:${shellQuote(allHeaders[key])}`);
88
- });
89
- if ((postData === null || postData === void 0 ? void 0 : postData.mimeType) === 'application/x-www-form-urlencoded') {
90
- // construct post params
91
- if (postData.params?.length) {
92
- flags.push(opts.short ? '-f' : '--form');
93
- postData.params.forEach((param) => {
94
- push(`${param.name}=${shellQuote(param.value)}`);
95
- });
96
- }
97
- }
98
- else if ((postData === null || postData === void 0 ? void 0 : postData.mimeType) === 'multipart/form-data') {
99
- // construct multipart form data
100
- if (postData?.params?.length) {
101
- flags.push('--multipart');
102
- postData.params.forEach((param) => {
103
- if (param.fileName) {
104
- push(`${param.name}@${shellQuote(param.fileName)}`);
105
- }
106
- else {
107
- push(`${param.name}='${shellQuote(param.value)}'`);
108
- }
109
- });
110
- }
111
- }
112
- else {
113
- raw = true;
114
- }
115
- const cliFlags = flags.length ? `${flags.join(' ')} ` : '';
116
- url = shellQuote(opts.queryParams ? url : fullUrl);
117
- unshift(`http ${cliFlags}${method} ${url}`);
118
- if (raw && (postData === null || postData === void 0 ? void 0 : postData.text)) {
119
- const postDataText = shellQuote(postData.text);
120
- unshift(`echo ${postDataText} | `);
121
- }
122
- return join();
123
- },
124
- };
@@ -1,19 +0,0 @@
1
- import type { CodeBuilderOptions } from '../../httpsnippet-lite/helpers/code-builder.js';
2
- import type { SnippetRequest } from '../../httpsnippet-lite/helpers/snippet-request.js';
3
- type ClientId = string;
4
- type ClientInfo = {
5
- key: ClientId;
6
- title: string;
7
- link: string;
8
- description: string;
9
- };
10
- type SimpleMerge<Destination, Source> = {
11
- [Key in keyof Destination as Key extends keyof Source ? never : Key]: Destination[Key];
12
- } & Source;
13
- export type Converter<T extends Record<string, any>> = (request: SnippetRequest, options?: SimpleMerge<CodeBuilderOptions, T>) => string;
14
- export type Client<T extends Record<string, any> = Record<string, any>> = {
15
- info: ClientInfo;
16
- convert: Converter<T>;
17
- };
18
- export {};
19
- //# sourceMappingURL=target.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"target.d.ts","sourceRoot":"","sources":["../../../src/httpsnippet-lite/targets/target.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,yCAAyC,CAAA;AACjF,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,4CAA4C,CAAA;AA4BhF,KAAK,QAAQ,GAAG,MAAM,CAAA;AACtB,KAAK,UAAU,GAAG;IAChB,GAAG,EAAE,QAAQ,CAAA;IACb,KAAK,EAAE,MAAM,CAAA;IACb,IAAI,EAAE,MAAM,CAAA;IACZ,WAAW,EAAE,MAAM,CAAA;CACpB,CAAA;AAED,KAAK,WAAW,CAAC,WAAW,EAAE,MAAM,IAAI;KACrC,GAAG,IAAI,MAAM,WAAW,IAAI,GAAG,SAAS,MAAM,MAAM,GAAG,KAAK,GAAG,GAAG,GAAG,WAAW,CAAC,GAAG,CAAC;CACvF,GAAG,MAAM,CAAA;AAEV,MAAM,MAAM,SAAS,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,IAAI,CACrD,OAAO,EAAE,cAAc,EACvB,OAAO,CAAC,EAAE,WAAW,CAAC,kBAAkB,EAAE,CAAC,CAAC,KACzC,MAAM,CAAA;AAEX,MAAM,MAAM,MAAM,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,IAAI;IACxE,IAAI,EAAE,UAAU,CAAA;IAChB,OAAO,EAAE,SAAS,CAAC,CAAC,CAAC,CAAA;CACtB,CAAA"}
@@ -1 +0,0 @@
1
- export {};
@@ -1,8 +0,0 @@
1
- import type { HarRequest } from '@scalar/types/snippetz';
2
- /**
3
- * Takes a httpsnippet-lite client and converts the given request to a code example with it.
4
- *
5
- * @deprecated This a temporary wrapper around httpsnippet-lite. Let's write all the generators ourselves instead.
6
- */
7
- export declare function convertWithHttpSnippetLite(client: Record<string, unknown>, request?: Partial<HarRequest>): string;
8
- //# sourceMappingURL=convertWithHttpSnippetLite.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"convertWithHttpSnippetLite.d.ts","sourceRoot":"","sources":["../../src/utils/convertWithHttpSnippetLite.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAA;AAKxD;;;;GAIG;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,102 +0,0 @@
1
- import { reduceQueryParams } from '../libs/http.js';
2
- /**
3
- * Takes a httpsnippet-lite client and converts the given request to a code example with it.
4
- *
5
- * @deprecated This a temporary wrapper around httpsnippet-lite. Let's write all the generators ourselves instead.
6
- */
7
- export function convertWithHttpSnippetLite(
8
- // Couldn't find the proper type, there was always a mismatch.
9
- client, request) {
10
- const urlObject = new URL(request?.url ?? '');
11
- // If it's just the domain, omit the trailing slash
12
- const url = urlObject.pathname === '/' ? urlObject.origin : urlObject.toString();
13
- const harRequest = {
14
- method: request?.method ?? 'GET',
15
- url,
16
- httpVersion: 'HTTP/1.1',
17
- cookies: [], // Cookies are handled through headers
18
- headers: request?.headers ?? [],
19
- headersSize: -1,
20
- bodySize: -1,
21
- queryString: Array.from(urlObject.searchParams.entries()).map(([name, value]) => ({
22
- name,
23
- value,
24
- })),
25
- postData: request?.postData,
26
- };
27
- const allHeaders = (harRequest?.headers ?? []).reduce((acc, header) => ({
28
- ...acc,
29
- [header.name]: header.value,
30
- }), {});
31
- const queryObj = reduceQueryParams(harRequest.queryString);
32
- const cookiesObj = (harRequest.cookies ?? []).reduce((acc, cookie) => ({
33
- ...acc,
34
- [cookie.name]: cookie.value,
35
- }), {});
36
- const parsedUrl = new URL(harRequest.url);
37
- const uriObj = {
38
- protocol: parsedUrl.protocol,
39
- hostname: parsedUrl.hostname,
40
- host: parsedUrl.hostname,
41
- port: parsedUrl.port,
42
- pathname: parsedUrl.pathname
43
- .split('/')
44
- .map((segment) => encodeURIComponent(decodeURIComponent(segment)))
45
- .join('/') + parsedUrl.search,
46
- path: parsedUrl.pathname
47
- .split('/')
48
- .map((segment) => encodeURIComponent(decodeURIComponent(segment)))
49
- .join('/') + parsedUrl.search,
50
- search: parsedUrl.search,
51
- hash: parsedUrl.hash,
52
- href: parsedUrl.href,
53
- origin: parsedUrl.origin,
54
- password: parsedUrl.password,
55
- searchParams: parsedUrl.searchParams,
56
- username: parsedUrl.username,
57
- toString: parsedUrl.toString,
58
- toJSON: () => parsedUrl.toJSON(),
59
- };
60
- const convertRequest = {
61
- url: harRequest.url,
62
- uriObj,
63
- method: harRequest.method?.toLocaleUpperCase() ?? 'GET',
64
- httpVersion: harRequest.httpVersion,
65
- cookies: harRequest.cookies ?? [],
66
- headers: harRequest.headers ?? [],
67
- headersSize: harRequest.headersSize ?? 0,
68
- headersObj: allHeaders ?? {},
69
- bodySize: harRequest.bodySize ?? 0,
70
- queryString: harRequest.queryString ?? [],
71
- postData: harRequest.postData
72
- ? {
73
- mimeType: harRequest.postData.mimeType ?? 'application/json',
74
- text: harRequest.postData.text ?? '',
75
- params: harRequest.postData.params ?? [],
76
- paramsObj: harRequest.postData.params?.reduce((acc, param) => {
77
- if (param.name && param.value !== undefined) {
78
- acc[param.name] = param.value;
79
- }
80
- return acc;
81
- }, {}) ?? {},
82
- }
83
- : undefined,
84
- allHeaders: allHeaders ?? {},
85
- fullUrl: harRequest.url,
86
- queryObj: queryObj ?? {},
87
- cookiesObj: cookiesObj ?? {},
88
- };
89
- // If the request is a JSON request, parse the text as JSON
90
- if (convertRequest.postData?.mimeType === 'application/json' && convertRequest.postData.text) {
91
- try {
92
- convertRequest.postData.jsonObj = JSON.parse(convertRequest.postData.text);
93
- }
94
- catch (error) {
95
- console.error('Error parsing JSON:', error);
96
- }
97
- }
98
- if (typeof client.convert === 'function') {
99
- return client.convert(convertRequest);
100
- }
101
- return '';
102
- }
@@ -1,2 +0,0 @@
1
- export { convertWithHttpSnippetLite } from './convertWithHttpSnippetLite.js';
2
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,0BAA0B,EAAE,MAAM,8BAA8B,CAAA"}
@@ -1 +0,0 @@
1
- export { convertWithHttpSnippetLite } from './convertWithHttpSnippetLite.js';