@mintlify/msft-sdk 1.1.61 → 1.1.63

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 (234) hide show
  1. package/dist/api-playground/ApiPlayground/Response/DownloadFileButton.js +6 -5
  2. package/dist/api-playground/ApiPlayground/Response/ResponseBody/CodeResponseContent.js +13 -12
  3. package/dist/api-playground/ApiPlayground/Response/ResponsePlaceholder.js +8 -7
  4. package/dist/api-playground/ApiPlayground/Response/ResponseTable.js +3 -2
  5. package/dist/api-playground/ApiPlayground/Response/ResponseTopbar.js +9 -8
  6. package/dist/api-playground/ApiPlayground/Response/index.js +4 -3
  7. package/dist/api-playground/ApiPlayground/components/AdditionalPropertyButton.js +42 -21
  8. package/dist/api-playground/ApiPlayground/components/ParamFieldWrapper.js +13 -9
  9. package/dist/api-playground/ApiPlayground/components/PlaygroundModalWrapper.js +6 -5
  10. package/dist/api-playground/ApiPlayground/components/SendPill.js +3 -2
  11. package/dist/api-playground/ApiPlayground/components/TypeDropdown.js +6 -5
  12. package/dist/api-playground/EndpointFields/ParamFields/ExampleDescription.js +3 -2
  13. package/dist/api-playground/EndpointFields/components/Description.js +6 -5
  14. package/dist/api-playground/EndpointFields/components/OptionDropdown.js +9 -8
  15. package/dist/api-playground/EndpointFields/components/SectionHeading.js +8 -7
  16. package/dist/api-playground-2/ApiExamples.js +19 -20
  17. package/dist/api-playground-2/ApiFields.js +20 -247
  18. package/dist/api-playground-2/EndpointHeader.js +59 -47
  19. package/dist/api-playground-2/OperationPage.js +70 -66
  20. package/dist/api-playground-2/Playground.js +67 -83
  21. package/dist/api-playground-2/SchemaPage.js +22 -9
  22. package/dist/api-playground-2/components/EndpointFields/Body.js +40 -0
  23. package/dist/api-playground-2/components/EndpointFields/Parameters.js +90 -0
  24. package/dist/api-playground-2/components/EndpointFields/Response.js +146 -0
  25. package/dist/api-playground-2/components/EndpointFields/Security.js +88 -0
  26. package/dist/api-playground-2/components/EndpointFields/fields/ArrayParamField.js +93 -0
  27. package/dist/api-playground-2/components/EndpointFields/fields/Enum.js +29 -11
  28. package/dist/api-playground-2/components/EndpointFields/fields/ObjectParamField.js +145 -0
  29. package/dist/api-playground-2/components/EndpointFields/fields/PrimitiveParamField.js +60 -48
  30. package/dist/api-playground-2/components/EndpointFields/fields/SchemaField.js +230 -0
  31. package/dist/api-playground-2/components/Example/GeneratedRequestExample.js +93 -89
  32. package/dist/api-playground-2/components/Example/GeneratedResponseExample.js +18 -17
  33. package/dist/api-playground-2/components/Example/RequestExample.js +92 -93
  34. package/dist/api-playground-2/components/Example/ResponseExample.js +19 -15
  35. package/dist/api-playground-2/components/Request/ParameterSection.js +20 -18
  36. package/dist/api-playground-2/components/Request/SecuritySection.js +53 -43
  37. package/dist/api-playground-2/components/Request/inputs/ArrayInput.js +89 -40
  38. package/dist/api-playground-2/components/Request/inputs/DifferentiatedInput.js +12 -12
  39. package/dist/api-playground-2/components/Request/inputs/FileInput.js +16 -15
  40. package/dist/api-playground-2/components/Request/inputs/InputContainer.js +76 -57
  41. package/dist/api-playground-2/components/Request/inputs/NumberInput.js +10 -9
  42. package/dist/api-playground-2/components/Request/inputs/ObjectInput.js +98 -80
  43. package/dist/api-playground-2/components/Request/inputs/OneOfInput.js +55 -47
  44. package/dist/api-playground-2/components/Request/inputs/SelectInput.js +18 -17
  45. package/dist/api-playground-2/components/Request/inputs/StringInput.js +19 -18
  46. package/dist/api-playground-2/components/Request/inputs/TextInput.js +12 -11
  47. package/dist/api-playground-2/components/SendPillWrapper.js +35 -0
  48. package/dist/api-playground-2/contexts/ApiPlaygroundContext.js +3 -5
  49. package/dist/api-playground-2/generators/createCookies.js +23 -0
  50. package/dist/api-playground-2/generators/createHeaders.js +53 -36
  51. package/dist/api-playground-2/generators/createQueryString.js +30 -0
  52. package/dist/api-playground-2/generators/generateAuthPlaceholder.js +14 -0
  53. package/dist/api-playground-2/generators/generateInteractiveCodeSample.js +27 -25
  54. package/dist/api-playground-2/generators/generateRequest.js +47 -51
  55. package/dist/api-playground-2/generators/generateResponseExampleMap.js +15 -11
  56. package/dist/api-playground-2/generators/generateSnippet.js +1 -1
  57. package/dist/api-playground-2/generators/generateSnippetMap.js +13 -11
  58. package/dist/api-playground-2/hooks/useCopyPathWithInputs.js +11 -11
  59. package/dist/api-playground-2/hooks/useInitializeInputs.js +185 -88
  60. package/dist/api-playground-2/hooks/usePlaygroundInputsStore.js +70 -25
  61. package/dist/api-playground-2/hooks/useSelectedBaseUrl.js +13 -0
  62. package/dist/api-playground-2/hooks/useSelectedExample.js +10 -0
  63. package/dist/api-playground-2/hooks/useSelectedRequestBodyContentType.js +12 -0
  64. package/dist/api-playground-2/hooks/useSelectedResponseContentType.js +12 -0
  65. package/dist/api-playground-2/hooks/useSelectedSecurityOption.js +31 -0
  66. package/dist/api-playground-2/hooks/useSendPlaygroundRequest.js +114 -101
  67. package/dist/api-playground-2/schemaGraph/addApiReferenceDataFromMdxAndDocsConfig.js +23 -32
  68. package/dist/api-playground-2/schemaGraph/addTypeLabelsToSchema.js +50 -0
  69. package/dist/api-playground-2/schemaGraph/addUniqueKeysToSchema.js +40 -24
  70. package/dist/api-playground-2/schemaGraph/getExampleBodyInputs.js +94 -0
  71. package/dist/api-playground-2/schemaGraph/getSchemaGraphOperationData.js +56 -50
  72. package/dist/api-playground-2/schemaGraph/processExamples.js +117 -52
  73. package/dist/api-playground-2/schemaGraph/processSchema.js +10 -0
  74. package/dist/api-playground-2/schemaGraph/processSecurityOptions.js +58 -28
  75. package/dist/api-playground-2/schemaGraph/reduceCompositions.js +220 -181
  76. package/dist/api-playground-2/schemaGraph/resolveOperationWithDependencies.js +128 -89
  77. package/dist/api-playground-2/schemaGraph/resolveSchemaWithDependencies.js +15 -16
  78. package/dist/api-playground-2/schemaGraph/sortSchemaByRequired.js +14 -12
  79. package/dist/api-playground-2/schemaGraph/utils.js +185 -147
  80. package/dist/common/guards.js +11 -19
  81. package/dist/components/Api/Expandable.js +10 -9
  82. package/dist/components/Api/Param.js +11 -13
  83. package/dist/components/Api/dropdown-menu.js +10 -9
  84. package/dist/components/content-components/code-group.js +4 -4
  85. package/dist/contexts/EndpointLocationContext.js +3 -3
  86. package/dist/hooks/useApiParamFieldOption.js +10 -0
  87. package/dist/hooks/useEndpoint.js +3 -3
  88. package/dist/hooks/useKeyboardShortcut.js +13 -13
  89. package/dist/hooks/useSendPlaygroundRequest.js +14 -146
  90. package/dist/httpsnippet/src/helpers/code-builder.js +27 -0
  91. package/dist/httpsnippet/src/helpers/escape.js +11 -0
  92. package/dist/httpsnippet/src/helpers/headers.js +13 -0
  93. package/dist/httpsnippet/src/helpers/reducer.js +7 -0
  94. package/dist/httpsnippet/src/helpers/shell.js +5 -0
  95. package/dist/httpsnippet/src/helpers/url-format.js +35 -0
  96. package/dist/httpsnippet/src/helpers/url-parse.js +76 -0
  97. package/dist/httpsnippet/src/index.js +157 -0
  98. package/dist/httpsnippet/src/targets/c/libcurl/client.js +22 -0
  99. package/dist/httpsnippet/src/targets/c/target.js +15 -0
  100. package/dist/httpsnippet/src/targets/clojure/clj_http/client.js +120 -0
  101. package/dist/httpsnippet/src/targets/clojure/target.js +14 -0
  102. package/dist/httpsnippet/src/targets/csharp/httpclient/client.js +76 -0
  103. package/dist/httpsnippet/src/targets/csharp/restsharp/client.js +63 -0
  104. package/dist/httpsnippet/src/targets/csharp/target.js +17 -0
  105. package/dist/httpsnippet/src/targets/go/native/client.js +24 -0
  106. package/dist/httpsnippet/src/targets/go/target.js +15 -0
  107. package/dist/httpsnippet/src/targets/http/http1.1/client.js +34 -0
  108. package/dist/httpsnippet/src/targets/http/target.js +14 -0
  109. package/dist/httpsnippet/src/targets/index.js +43 -0
  110. package/dist/httpsnippet/src/targets/java/asynchttp/client.js +23 -0
  111. package/dist/httpsnippet/src/targets/java/nethttp/client.js +28 -0
  112. package/dist/httpsnippet/src/targets/java/okhttp/client.js +23 -0
  113. package/dist/httpsnippet/src/targets/java/target.js +20 -0
  114. package/dist/httpsnippet/src/targets/java/unirest/client.js +23 -0
  115. package/dist/httpsnippet/src/targets/javascript/axios/client.js +50 -0
  116. package/dist/httpsnippet/src/targets/javascript/fetch/client.js +61 -0
  117. package/dist/httpsnippet/src/targets/javascript/jquery/client.js +51 -0
  118. package/dist/httpsnippet/src/targets/javascript/target.js +20 -0
  119. package/dist/httpsnippet/src/targets/javascript/xhr/client.js +49 -0
  120. package/dist/httpsnippet/src/targets/json/native/client.js +39 -0
  121. package/dist/httpsnippet/src/targets/json/target.js +14 -0
  122. package/dist/httpsnippet/src/targets/kotlin/okhttp/client.js +23 -0
  123. package/dist/httpsnippet/src/targets/kotlin/target.js +14 -0
  124. package/dist/httpsnippet/src/targets/node/axios/client.js +40 -0
  125. package/dist/httpsnippet/src/targets/node/fetch/client.js +68 -0
  126. package/dist/httpsnippet/src/targets/node/native/client.js +45 -0
  127. package/dist/httpsnippet/src/targets/node/target.js +19 -0
  128. package/dist/httpsnippet/src/targets/objc/helpers.js +27 -0
  129. package/dist/httpsnippet/src/targets/objc/nsurlsession/client.js +63 -0
  130. package/dist/httpsnippet/src/targets/objc/target.js +14 -0
  131. package/dist/httpsnippet/src/targets/ocaml/cohttp/client.js +32 -0
  132. package/dist/httpsnippet/src/targets/ocaml/target.js +14 -0
  133. package/dist/httpsnippet/src/targets/php/curl/client.js +85 -0
  134. package/dist/httpsnippet/src/targets/php/guzzle/client.js +57 -0
  135. package/dist/httpsnippet/src/targets/php/helpers.js +65 -0
  136. package/dist/httpsnippet/src/targets/php/http1/client.js +28 -0
  137. package/dist/httpsnippet/src/targets/php/http2/client.js +55 -0
  138. package/dist/httpsnippet/src/targets/php/target.js +21 -0
  139. package/dist/httpsnippet/src/targets/powershell/common.js +19 -0
  140. package/dist/httpsnippet/src/targets/powershell/restmethod/client.js +14 -0
  141. package/dist/httpsnippet/src/targets/powershell/target.js +16 -0
  142. package/dist/httpsnippet/src/targets/powershell/webrequest/client.js +14 -0
  143. package/dist/httpsnippet/src/targets/python/helpers.js +33 -0
  144. package/dist/httpsnippet/src/targets/python/requests/client.js +74 -0
  145. package/dist/httpsnippet/src/targets/python/target.js +15 -0
  146. package/dist/httpsnippet/src/targets/r/httr/client.js +46 -0
  147. package/dist/httpsnippet/src/targets/r/target.js +14 -0
  148. package/dist/httpsnippet/src/targets/ruby/native/client.js +37 -0
  149. package/dist/httpsnippet/src/targets/ruby/target.js +14 -0
  150. package/dist/httpsnippet/src/targets/shell/curl/client.js +92 -0
  151. package/dist/httpsnippet/src/targets/shell/httpie/client.js +56 -0
  152. package/dist/httpsnippet/src/targets/shell/target.js +19 -0
  153. package/dist/httpsnippet/src/targets/shell/wget/client.js +30 -0
  154. package/dist/httpsnippet/src/targets/swift/helpers.js +38 -0
  155. package/dist/httpsnippet/src/targets/swift/target.js +14 -0
  156. package/dist/httpsnippet/src/targets/swift/urlsession/client.js +59 -0
  157. package/dist/index.d.ts +65 -58
  158. package/dist/index.js +109 -111
  159. package/dist/openapi/generateTypeStringFromSchema.js +2 -31
  160. package/dist/styles.css +1 -1
  161. package/package.json +17 -4
  162. package/dist/api-playground/ApiPlayground/Request/BodySection.js +0 -64
  163. package/dist/api-playground/ApiPlayground/Request/ParameterSection.js +0 -32
  164. package/dist/api-playground/ApiPlayground/Request/PlaygroundModal.js +0 -201
  165. package/dist/api-playground/ApiPlayground/Request/SecuritySection.js +0 -146
  166. package/dist/api-playground/ApiPlayground/Request/ServerSection.js +0 -30
  167. package/dist/api-playground/ApiPlayground/Request/index.js +0 -43
  168. package/dist/api-playground/ApiPlayground/Request/inputs/ArrayInput.js +0 -93
  169. package/dist/api-playground/ApiPlayground/Request/inputs/DifferentiatedInput.js +0 -90
  170. package/dist/api-playground/ApiPlayground/Request/inputs/FileInput.js +0 -62
  171. package/dist/api-playground/ApiPlayground/Request/inputs/NullInput.js +0 -33
  172. package/dist/api-playground/ApiPlayground/Request/inputs/NumberInput.js +0 -61
  173. package/dist/api-playground/ApiPlayground/Request/inputs/ObjectChildren.js +0 -109
  174. package/dist/api-playground/ApiPlayground/Request/inputs/ObjectInput.js +0 -87
  175. package/dist/api-playground/ApiPlayground/Request/inputs/RecursiveInput.js +0 -61
  176. package/dist/api-playground/ApiPlayground/Request/inputs/SelectInput.js +0 -54
  177. package/dist/api-playground/ApiPlayground/Request/inputs/StringInput.js +0 -67
  178. package/dist/api-playground/ApiPlayground/Request/inputs/TextInput.js +0 -44
  179. package/dist/api-playground/ApiPlayground/components/EndpointsMenu.js +0 -42
  180. package/dist/api-playground/ApiPlayground/components/EndpointsMenuLink.js +0 -43
  181. package/dist/api-playground/ApiPlayground/components/EndpointsMenuSearch.js +0 -38
  182. package/dist/api-playground/ApiPlayground/components/InputContainer.js +0 -128
  183. package/dist/api-playground/ApiPlayground/components/InputSectionContainer.js +0 -59
  184. package/dist/api-playground/ApiPlayground/components/PathHeader.js +0 -162
  185. package/dist/api-playground/ApiPlayground/components/TrashButton.js +0 -26
  186. package/dist/api-playground/ApiPlayground/index.js +0 -67
  187. package/dist/api-playground/EndpointFields/ParamFields/PrimitiveParamField/Enum.js +0 -19
  188. package/dist/api-playground/EndpointFields/ParamFields/PrimitiveParamField/NumberMetadata.js +0 -18
  189. package/dist/api-playground/EndpointFields/ParamFields/PrimitiveParamField/StringMetadata.js +0 -28
  190. package/dist/api-playground/EndpointFields/ParamFields/PrimitiveParamField/index.js +0 -5
  191. package/dist/api-playground/EndpointFields/ParamFields/RecursiveParamField.js +0 -13
  192. package/dist/api-playground/EndpointFields/index.js +0 -7
  193. package/dist/api-playground-2/components/EndpointFields/EndpointSecurity.js +0 -87
  194. package/dist/api-playground-2/components/EndpointFields/fields/SimpleArrayParamField.js +0 -89
  195. package/dist/api-playground-2/components/EndpointFields/fields/SimpleObjectParamField.js +0 -121
  196. package/dist/api-playground-2/components/EndpointFields/fields/SimplePrimitiveParamField.js +0 -74
  197. package/dist/api-playground-2/components/EndpointFields/fields/SimpleSchemaField.js +0 -252
  198. package/dist/common/potentiallyParseOpenApiString.js +0 -24
  199. package/dist/common/replaceSlashIndex.js +0 -6
  200. package/dist/common/slugToTitle.js +0 -10
  201. package/dist/constants/prism-languages.js +0 -19
  202. package/dist/contexts/ApiPlaygroundInputsContext.js +0 -17
  203. package/dist/contexts/MDXContentContext.js +0 -17
  204. package/dist/hooks/useApiPlaygroundInputs.js +0 -6
  205. package/dist/hooks/useApiPlaygroundPrefillExamples.js +0 -39
  206. package/dist/hooks/useBaseUrlOptions.js +0 -18
  207. package/dist/hooks/useComponentSchemas.js +0 -9
  208. package/dist/hooks/useGenerateNextAdditionalProperties.js +0 -11
  209. package/dist/hooks/useGenerateNextItems.js +0 -11
  210. package/dist/hooks/useGenerateNextProperties.js +0 -11
  211. package/dist/hooks/useMDXContent.js +0 -6
  212. package/dist/hooks/useMDXContentController/useApiPlaygroundInputs.js +0 -9
  213. package/dist/hooks/useMDXContentController/useMDXContentCallbacks/useSetApiBaseIndexCallback.js +0 -15
  214. package/dist/hooks/useMDXContentController/useMDXContentCallbacks/useSetApiPlaygroundInputsCallback.js +0 -15
  215. package/dist/hooks/usePlaygroundSchemaOptions.js +0 -42
  216. package/dist/hooks/usePrefilledInputs/index.js +0 -65
  217. package/dist/hooks/usePrefilledInputs/storedServerVariables.js +0 -29
  218. package/dist/hooks/useSecurityOption.js +0 -10
  219. package/dist/hooks/useSetDefaultValue.js +0 -63
  220. package/dist/openapi/filterEnums.js +0 -20
  221. package/dist/openapi/generateNextAdditionalProperties.js +0 -7
  222. package/dist/openapi/generateNextItems.js +0 -7
  223. package/dist/openapi/generateNextProperties.js +0 -23
  224. package/dist/openapi/generateOptionLabels.js +0 -20
  225. package/dist/openapi/generateSimpleLabels.js +0 -4
  226. package/dist/openapi/getAuthFilteredSchemaArray.js +0 -18
  227. package/dist/paths/isEqualIgnoringLeadingSlash.js +0 -21
  228. package/dist/paths/optionallyRemoveLeadingSlash.js +0 -6
  229. package/dist/paths/optionallyRemoveTrailingSlash.js +0 -6
  230. package/dist/utils/api-playground/defaults.js +0 -15
  231. package/dist/utils/api-playground/paramFieldDefaults.js +0 -10
  232. package/dist/utils/api-reference/getFilteredSecurityOptions.js +0 -4
  233. package/dist/utils/api-reference/getNextPropertiesByType.js +0 -5
  234. package/dist/utils/flattenObject.js +0 -10
@@ -0,0 +1,61 @@
1
+ import a from "stringify-object";
2
+ import { CodeBuilder as p } from "../../../helpers/code-builder.js";
3
+ import { getHeaderName as b } from "../../../helpers/headers.js";
4
+ const w = {
5
+ info: {
6
+ key: "fetch",
7
+ title: "fetch",
8
+ link: "https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch",
9
+ description: "Perform asynchronous HTTP requests with the Fetch API",
10
+ extname: ".js"
11
+ },
12
+ convert: ({ method: f, allHeaders: i, postData: e, fullUrl: d }, h) => {
13
+ const o = {
14
+ indent: " ",
15
+ credentials: null,
16
+ ...h
17
+ }, { blank: c, join: l, push: r } = new p({ indent: o.indent }), n = {
18
+ method: f
19
+ };
20
+ switch (Object.keys(i).length && (n.headers = i), o.credentials !== null && (n.credentials = o.credentials), e.mimeType) {
21
+ case "application/x-www-form-urlencoded":
22
+ n.body = e.paramsObj ? e.paramsObj : e.text;
23
+ break;
24
+ case "application/json":
25
+ e.jsonObj && (n.body = e.jsonObj);
26
+ break;
27
+ case "multipart/form-data": {
28
+ if (!e.params)
29
+ break;
30
+ const s = b(i, "content-type");
31
+ s && delete i[s], r("const form = new FormData();"), e.params.forEach((t) => {
32
+ r(`form.append('${t.name}', '${t.value || t.fileName || ""}');`);
33
+ }), c();
34
+ break;
35
+ }
36
+ default:
37
+ e.text && (n.body = e.text);
38
+ }
39
+ return n.headers && !Object.keys(n.headers).length && delete n.headers, r(
40
+ `const options = ${a(n, {
41
+ indent: o.indent,
42
+ inlineCharacterLimit: 80,
43
+ // The Fetch API body only accepts string parameters, but stringified JSON can be difficult
44
+ // to read, so we keep the object as a literal and use this transform function to wrap the
45
+ // literal in a `JSON.stringify` call.
46
+ transform: (s, t, m) => {
47
+ if (t === "body") {
48
+ if (e.mimeType === "application/x-www-form-urlencoded")
49
+ return `new URLSearchParams(${m})`;
50
+ if (e.mimeType === "application/json")
51
+ return `JSON.stringify(${m})`;
52
+ }
53
+ return m;
54
+ }
55
+ })};`
56
+ ), c(), e.params && e.mimeType === "multipart/form-data" && (r("options.body = form;"), c()), r(`fetch('${d}', options)`), r(".then(res => res.json())", 1), r(".then(res => console.log(res))", 1), r(".catch(err => console.error(err));", 1), l();
57
+ }
58
+ };
59
+ export {
60
+ w as fetch
61
+ };
@@ -0,0 +1,51 @@
1
+ import p from "stringify-object";
2
+ import { CodeBuilder as y } from "../../../helpers/code-builder.js";
3
+ import { hasHeader as j, getHeader as l, getHeaderName as h } from "../../../helpers/headers.js";
4
+ const k = {
5
+ info: {
6
+ key: "jquery",
7
+ title: "jQuery",
8
+ link: "http://api.jquery.com/jquery.ajax/",
9
+ description: "Perform an asynchronous HTTP (Ajax) requests with jQuery",
10
+ extname: ".js"
11
+ },
12
+ convert: ({ fullUrl: c, method: m, allHeaders: a, postData: t }, d) => {
13
+ var s;
14
+ const o = {
15
+ indent: " ",
16
+ ...d
17
+ }, { blank: i, push: n, join: f } = new y({ indent: o.indent }), e = {
18
+ async: !0,
19
+ crossDomain: !0,
20
+ url: c,
21
+ method: m,
22
+ headers: a
23
+ };
24
+ switch (t.mimeType) {
25
+ case "application/x-www-form-urlencoded":
26
+ e.data = t.paramsObj ? t.paramsObj : t.text;
27
+ break;
28
+ case "application/json":
29
+ e.processData = !1, e.data = t.text;
30
+ break;
31
+ case "multipart/form-data":
32
+ if (!t.params)
33
+ break;
34
+ if (n("const form = new FormData();"), t.params.forEach((r) => {
35
+ n(`form.append('${r.name}', '${r.value || r.fileName || ""}');`);
36
+ }), e.processData = !1, e.contentType = !1, e.mimeType = "multipart/form-data", e.data = "[form]", j(a, "content-type") && (s = l(a, "content-type")) != null && s.includes("boundary")) {
37
+ const r = h(a, "content-type");
38
+ r && delete e.headers[r];
39
+ }
40
+ i();
41
+ break;
42
+ default:
43
+ t.text && (e.data = t.text);
44
+ }
45
+ const u = p(e, { indent: o.indent }).replace("'[form]'", "form");
46
+ return n(`const settings = ${u};`), i(), n("$.ajax(settings).done(res => {"), n("console.log(res);", 1), n("});"), f();
47
+ }
48
+ };
49
+ export {
50
+ k as jquery
51
+ };
@@ -0,0 +1,20 @@
1
+ import { axios as t } from "./axios/client.js";
2
+ import { fetch as r } from "./fetch/client.js";
3
+ import { jquery as o } from "./jquery/client.js";
4
+ import { xhr as i } from "./xhr/client.js";
5
+ const p = {
6
+ info: {
7
+ key: "javascript",
8
+ title: "JavaScript",
9
+ default: "fetch"
10
+ },
11
+ clientsById: {
12
+ xhr: i,
13
+ axios: t,
14
+ fetch: r,
15
+ jquery: o
16
+ }
17
+ };
18
+ export {
19
+ p as javascript
20
+ };
@@ -0,0 +1,49 @@
1
+ import h from "stringify-object";
2
+ import { CodeBuilder as f } from "../../../helpers/code-builder.js";
3
+ import { escapeForSingleQuotes as m } from "../../../helpers/escape.js";
4
+ import { hasHeader as u, getHeader as x, getHeaderName as l } from "../../../helpers/headers.js";
5
+ const j = {
6
+ info: {
7
+ key: "xhr",
8
+ title: "XMLHttpRequest",
9
+ link: "https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest",
10
+ description: "W3C Standard API that provides scripted client functionality",
11
+ extname: ".js"
12
+ },
13
+ convert: ({ postData: n, allHeaders: r, method: a, fullUrl: c }, d) => {
14
+ var s;
15
+ const o = {
16
+ indent: " ",
17
+ cors: !0,
18
+ ...d
19
+ }, { blank: i, push: e, join: p } = new f({ indent: o.indent });
20
+ switch (n.mimeType) {
21
+ case "application/json":
22
+ e(
23
+ `const data = JSON.stringify(${h(n.jsonObj, {
24
+ indent: o.indent
25
+ })});`
26
+ ), i();
27
+ break;
28
+ case "multipart/form-data":
29
+ if (!n.params)
30
+ break;
31
+ if (e("const data = new FormData();"), n.params.forEach((t) => {
32
+ e(`data.append('${t.name}', '${t.value || t.fileName || ""}');`);
33
+ }), u(r, "content-type") && (s = x(r, "content-type")) != null && s.includes("boundary")) {
34
+ const t = l(r, "content-type");
35
+ t && delete r[t];
36
+ }
37
+ i();
38
+ break;
39
+ default:
40
+ e(`const data = ${n.text ? `'${n.text}'` : "null"};`), i();
41
+ }
42
+ return e("const xhr = new XMLHttpRequest();"), o.cors && e("xhr.withCredentials = true;"), i(), e("xhr.addEventListener('readystatechange', function () {"), e("if (this.readyState === this.DONE) {", 1), e("console.log(this.responseText);", 2), e("}", 1), e("});"), i(), e(`xhr.open('${a}', '${c}');`), Object.keys(r).forEach((t) => {
43
+ e(`xhr.setRequestHeader('${t}', '${m(r[t])}');`);
44
+ }), i(), e("xhr.send(data);"), p();
45
+ }
46
+ };
47
+ export {
48
+ j as xhr
49
+ };
@@ -0,0 +1,39 @@
1
+ const a = {
2
+ info: {
3
+ key: "native",
4
+ title: "Native JSON",
5
+ link: "https://www.json.org/json-en.html",
6
+ description: "A JSON represetation of any HAR payload.",
7
+ extname: ".json"
8
+ },
9
+ convert: ({ postData: e }, t) => {
10
+ const o = {
11
+ indent: " ",
12
+ ...t
13
+ };
14
+ let n = "";
15
+ switch (e.mimeType) {
16
+ case "application/x-www-form-urlencoded":
17
+ n = e.paramsObj ? e.paramsObj : e.text;
18
+ break;
19
+ case "application/json":
20
+ e.jsonObj && (n = e.jsonObj);
21
+ break;
22
+ case "multipart/form-data": {
23
+ if (!e.params)
24
+ break;
25
+ const i = {};
26
+ e.params.forEach((r) => {
27
+ i[r.name] = r.value;
28
+ }), n = i;
29
+ break;
30
+ }
31
+ default:
32
+ e.text && (n = e.text);
33
+ }
34
+ return typeof n > "u" || n === "" ? "No JSON body" : JSON.stringify(n, null, o.indent);
35
+ }
36
+ };
37
+ export {
38
+ a as native
39
+ };
@@ -0,0 +1,14 @@
1
+ import { native as t } from "./native/client.js";
2
+ const n = {
3
+ info: {
4
+ key: "json",
5
+ title: "JSON",
6
+ default: "native"
7
+ },
8
+ clientsById: {
9
+ native: t
10
+ }
11
+ };
12
+ export {
13
+ n as json
14
+ };
@@ -0,0 +1,23 @@
1
+ import { CodeBuilder as T } from "../../../helpers/code-builder.js";
2
+ import { escapeForDoubleQuotes as a } from "../../../helpers/escape.js";
3
+ const b = {
4
+ info: {
5
+ key: "okhttp",
6
+ title: "OkHttp",
7
+ link: "http://square.github.io/okhttp/",
8
+ description: "An HTTP Request Client Library",
9
+ extname: ".kt"
10
+ },
11
+ convert: ({ postData: t, fullUrl: s, method: i, allHeaders: n }, l) => {
12
+ const p = {
13
+ indent: " ",
14
+ ...l
15
+ }, { blank: o, join: d, push: e } = new T({ indent: p.indent }), u = ["GET", "POST", "PUT", "DELETE", "PATCH", "HEAD"], y = ["POST", "PUT", "DELETE", "PATCH"];
16
+ return e("val client = OkHttpClient()"), o(), t.text && (t.boundary ? e(`val mediaType = MediaType.parse("${t.mimeType}; boundary=${t.boundary}")`) : e(`val mediaType = MediaType.parse("${t.mimeType}")`), e(`val body = RequestBody.create(mediaType, ${JSON.stringify(t.text)})`)), e("val request = Request.Builder()"), e(`.url("${s}")`, 1), u.includes(i.toUpperCase()) ? y.includes(i.toUpperCase()) ? t.text ? e(`.${i.toLowerCase()}(body)`, 1) : e(`.${i.toLowerCase()}(null)`, 1) : e(`.${i.toLowerCase()}()`, 1) : t.text ? e(`.method("${i.toUpperCase()}", body)`, 1) : e(`.method("${i.toUpperCase()}", null)`, 1), Object.keys(n).forEach((r) => {
17
+ e(`.addHeader("${r}", "${a(n[r])}")`, 1);
18
+ }), e(".build()", 1), o(), e("val response = client.newCall(request).execute()"), d();
19
+ }
20
+ };
21
+ export {
22
+ b as okhttp
23
+ };
@@ -0,0 +1,14 @@
1
+ import { okhttp as t } from "./okhttp/client.js";
2
+ const i = {
3
+ info: {
4
+ key: "kotlin",
5
+ title: "Kotlin",
6
+ default: "okhttp"
7
+ },
8
+ clientsById: {
9
+ okhttp: t
10
+ }
11
+ };
12
+ export {
13
+ i as kotlin
14
+ };
@@ -0,0 +1,40 @@
1
+ import p from "stringify-object";
2
+ import { CodeBuilder as x } from "../../../helpers/code-builder.js";
3
+ const j = {
4
+ info: {
5
+ key: "axios",
6
+ title: "Axios",
7
+ link: "https://github.com/axios/axios",
8
+ description: "Promise based HTTP client for the browser and node.js",
9
+ extname: ".js",
10
+ installation: () => "npm install axios --save"
11
+ },
12
+ convert: ({ method: t, fullUrl: a, allHeaders: r, postData: o }, c) => {
13
+ const d = {
14
+ indent: " ",
15
+ ...c
16
+ }, { blank: i, join: m, push: e, addPostProcessor: l } = new x({ indent: d.indent });
17
+ e("import axios from 'axios';"), i();
18
+ const n = {
19
+ method: t,
20
+ url: a
21
+ };
22
+ switch (Object.keys(r).length && (n.headers = r), o.mimeType) {
23
+ case "application/x-www-form-urlencoded":
24
+ o.params && (e("const encodedParams = new URLSearchParams();"), o.params.forEach((s) => {
25
+ e(`encodedParams.set('${s.name}', '${s.value}');`);
26
+ }), i(), n.data = "encodedParams,", l((s) => s.replace(/'encodedParams,'/, "encodedParams,")));
27
+ break;
28
+ case "application/json":
29
+ o.jsonObj && (n.data = o.jsonObj);
30
+ break;
31
+ default:
32
+ o.text && (n.data = o.text);
33
+ }
34
+ const f = p(n, { indent: " ", inlineCharacterLimit: 80 });
35
+ return e(`const options = ${f};`), i(), e("axios"), e(".request(options)", 1), e(".then(res => console.log(res.data))", 1), e(".catch(err => console.error(err));", 1), m();
36
+ }
37
+ };
38
+ export {
39
+ j as axios
40
+ };
@@ -0,0 +1,68 @@
1
+ import k from "stringify-object";
2
+ import { CodeBuilder as $ } from "../../../helpers/code-builder.js";
3
+ import { getHeaderName as g } from "../../../helpers/headers.js";
4
+ const T = {
5
+ info: {
6
+ key: "fetch",
7
+ title: "fetch",
8
+ link: "https://nodejs.org/docs/latest/api/globals.html#fetch",
9
+ description: "Perform asynchronous HTTP requests with the Fetch API",
10
+ extname: ".js"
11
+ },
12
+ convert: ({ method: m, fullUrl: l, postData: o, headersObj: s, cookies: a }, h) => {
13
+ var d;
14
+ const p = {
15
+ indent: " ",
16
+ ...h
17
+ };
18
+ let f = !1;
19
+ const { blank: c, push: t, join: u, unshift: b } = new $({ indent: p.indent }), y = l, e = {
20
+ method: m
21
+ };
22
+ switch (Object.keys(s).length && (e.headers = s), o.mimeType) {
23
+ case "application/x-www-form-urlencoded":
24
+ t("const encodedParams = new URLSearchParams();"), (d = o.params) == null || d.forEach((r) => {
25
+ t(`encodedParams.set('${r.name}', '${r.value}');`);
26
+ }), e.body = "encodedParams", c();
27
+ break;
28
+ case "application/json":
29
+ o.jsonObj && (e.body = o.jsonObj);
30
+ break;
31
+ case "multipart/form-data": {
32
+ if (!o.params)
33
+ break;
34
+ const r = g(s, "content-type");
35
+ r && delete s[r], t("const formData = new FormData();"), o.params.forEach((n) => {
36
+ if (!n.fileName && !n.fileName && !n.contentType) {
37
+ t(`formData.append('${n.name}', '${n.value}');`);
38
+ return;
39
+ }
40
+ n.fileName && (f = !0, t(
41
+ `formData.append('${n.name}', await new Response(fs.createReadStream('${n.fileName}')).blob());`
42
+ ));
43
+ }), e.body = "formData", c();
44
+ break;
45
+ }
46
+ default:
47
+ o.text && (e.body = o.text);
48
+ }
49
+ if (a.length) {
50
+ const r = a.map(({ name: n, value: i }) => `${encodeURIComponent(n)}=${encodeURIComponent(i)}`).join("; ");
51
+ e.headers || (e.headers = {}), e.headers.cookie = r;
52
+ }
53
+ t(`const url = '${y}';`), e.headers && !Object.keys(e.headers).length && delete e.headers;
54
+ const j = k(e, {
55
+ indent: " ",
56
+ inlineCharacterLimit: 80,
57
+ // The Fetch API body only accepts string parameters, but stringified JSON can be difficult to
58
+ // read, so we keep the object as a literal and use this transform function to wrap the literal
59
+ // in a `JSON.stringify` call.
60
+ transform: (r, n, i) => n === "body" && o.mimeType === "application/json" ? `JSON.stringify(${i})` : i
61
+ });
62
+ return t(`const options = ${j};`), c(), f && b(`import fs from 'fs';
63
+ `), t("fetch(url, options)"), t(".then(res => res.json())", 1), t(".then(json => console.log(json))", 1), t(".catch(err => console.error(err));", 1), u().replace(/'encodedParams'/, "encodedParams").replace(/'formData'/, "formData");
64
+ }
65
+ };
66
+ export {
67
+ T as fetch
68
+ };
@@ -0,0 +1,45 @@
1
+ import o from "stringify-object";
2
+ import { CodeBuilder as d } from "../../../helpers/code-builder.js";
3
+ const q = {
4
+ info: {
5
+ key: "native",
6
+ title: "HTTP",
7
+ link: "http://nodejs.org/api/http.html#http_http_request_options_callback",
8
+ description: "Node.js native HTTP interface",
9
+ extname: ".cjs"
10
+ },
11
+ convert: ({ uriObj: i, method: c, allHeaders: p, postData: n }, a = {}) => {
12
+ var s;
13
+ const { indent: r = " " } = a, { blank: t, join: h, push: e, unshift: f } = new d({ indent: r }), u = {
14
+ method: c,
15
+ hostname: i.hostname,
16
+ port: i.port,
17
+ path: i.path,
18
+ headers: p
19
+ };
20
+ switch (e(`const http = require('${(s = i.protocol) == null ? void 0 : s.replace(":", "")}');`), t(), e(`const options = ${o(u, { indent: r })};`), t(), e("const req = http.request(options, function (res) {"), e("const chunks = [];", 1), t(), e("res.on('data', function (chunk) {", 1), e("chunks.push(chunk);", 2), e("});", 1), t(), e("res.on('end', function () {", 1), e("const body = Buffer.concat(chunks);", 2), e("console.log(body.toString());", 2), e("});", 1), e("});"), t(), n.mimeType) {
21
+ case "application/x-www-form-urlencoded":
22
+ n.paramsObj && (f("const qs = require('querystring');"), e(
23
+ `req.write(qs.stringify(${o(n.paramsObj, {
24
+ indent: " ",
25
+ inlineCharacterLimit: 80
26
+ })}));`
27
+ ));
28
+ break;
29
+ case "application/json":
30
+ n.jsonObj && e(
31
+ `req.write(JSON.stringify(${o(n.jsonObj, {
32
+ indent: " ",
33
+ inlineCharacterLimit: 80
34
+ })}));`
35
+ );
36
+ break;
37
+ default:
38
+ n.text && e(`req.write(${o(n.text, { indent: r })});`);
39
+ }
40
+ return e("req.end();"), h();
41
+ }
42
+ };
43
+ export {
44
+ q as native
45
+ };
@@ -0,0 +1,19 @@
1
+ import { axios as o } from "./axios/client.js";
2
+ import { fetch as e } from "./fetch/client.js";
3
+ import { native as t } from "./native/client.js";
4
+ const r = {
5
+ info: {
6
+ key: "node",
7
+ title: "Node.js",
8
+ default: "fetch",
9
+ cli: "node %s"
10
+ },
11
+ clientsById: {
12
+ native: t,
13
+ axios: o,
14
+ fetch: e
15
+ }
16
+ };
17
+ export {
18
+ r as node
19
+ };
@@ -0,0 +1,27 @@
1
+ const i = (t, n, o, r) => {
2
+ const e = `${t} *${n} = `, s = c(o, r ? e.length : void 0);
3
+ return `${e}${s};`;
4
+ }, c = (t, n) => {
5
+ const o = n === void 0 ? ", " : `,
6
+ ${" ".repeat(n)}`;
7
+ switch (Object.prototype.toString.call(t)) {
8
+ case "[object Number]":
9
+ return `@${t}`;
10
+ case "[object Array]":
11
+ return `@[ ${t.map((e) => c(e)).join(o)} ]`;
12
+ case "[object Object]": {
13
+ const r = [];
14
+ return Object.keys(t).forEach((e) => {
15
+ r.push(`@"${e}": ${c(t[e])}`);
16
+ }), `@{ ${r.join(o)} }`;
17
+ }
18
+ case "[object Boolean]":
19
+ return t ? "@YES" : "@NO";
20
+ default:
21
+ return t == null ? "" : `@"${t.toString().replace(/"/g, '\\"')}"`;
22
+ }
23
+ };
24
+ export {
25
+ c as literalRepresentation,
26
+ i as nsDeclaration
27
+ };
@@ -0,0 +1,63 @@
1
+ import { CodeBuilder as y } from "../../../helpers/code-builder.js";
2
+ import { nsDeclaration as o } from "../helpers.js";
3
+ const b = {
4
+ info: {
5
+ key: "nsurlsession",
6
+ title: "NSURLSession",
7
+ link: "https://developer.apple.com/library/mac/documentation/Foundation/Reference/NSURLSession_class/index.html",
8
+ description: "Foundation's NSURLSession request",
9
+ extname: ".m"
10
+ },
11
+ convert: ({ allHeaders: s, postData: a, method: p, fullUrl: S }, m) => {
12
+ var i;
13
+ const n = {
14
+ indent: " ",
15
+ pretty: !0,
16
+ timeout: 10,
17
+ ...m
18
+ }, { push: e, join: l, blank: t } = new y({ indent: n.indent }), r = {
19
+ hasHeaders: !1,
20
+ hasBody: !1
21
+ };
22
+ if (e("#import <Foundation/Foundation.h>"), Object.keys(s).length && (r.hasHeaders = !0, t(), e(o("NSDictionary", "headers", s, n.pretty))), a.text || a.jsonObj || a.params)
23
+ switch (r.hasBody = !0, a.mimeType) {
24
+ case "application/x-www-form-urlencoded":
25
+ if ((i = a.params) != null && i.length) {
26
+ t();
27
+ const [d, ...c] = a.params;
28
+ e(
29
+ `NSMutableData *postData = [[NSMutableData alloc] initWithData:[@"${d.name}=${d.value}" dataUsingEncoding:NSUTF8StringEncoding]];`
30
+ ), c.forEach(({ name: N, value: u }) => {
31
+ e(`[postData appendData:[@"&${N}=${u}" dataUsingEncoding:NSUTF8StringEncoding]];`);
32
+ });
33
+ } else
34
+ r.hasBody = !1;
35
+ break;
36
+ case "application/json":
37
+ a.jsonObj && (e(o("NSDictionary", "parameters", a.jsonObj, n.pretty)), t(), e("NSData *postData = [NSJSONSerialization dataWithJSONObject:parameters options:0 error:nil];"));
38
+ break;
39
+ case "multipart/form-data":
40
+ e(o("NSArray", "parameters", a.params || [], n.pretty)), e(`NSString *boundary = @"${a.boundary}";`), t(), e("NSError *error;"), e("NSMutableString *body = [NSMutableString string];"), e("for (NSDictionary *param in parameters) {"), e('[body appendFormat:@"--%@\\r\\n", boundary];', 1), e('if (param[@"fileName"]) {', 1), e(
41
+ '[body appendFormat:@"Content-Disposition:form-data; name=\\"%@\\"; filename=\\"%@\\"\\r\\n", param[@"name"], param[@"fileName"]];',
42
+ 2
43
+ ), e('[body appendFormat:@"Content-Type: %@\\r\\n\\r\\n", param[@"contentType"]];', 2), e(
44
+ '[body appendFormat:@"%@", [NSString stringWithContentsOfFile:param[@"fileName"] encoding:NSUTF8StringEncoding error:&error]];',
45
+ 2
46
+ ), e("if (error) {", 2), e('NSLog(@"%@", error);', 3), e("}", 2), e("} else {", 1), e('[body appendFormat:@"Content-Disposition:form-data; name=\\"%@\\"\\r\\n\\r\\n", param[@"name"]];', 2), e('[body appendFormat:@"%@", param[@"value"]];', 2), e("}", 1), e("}"), e('[body appendFormat:@"\\r\\n--%@--\\r\\n", boundary];'), e("NSData *postData = [body dataUsingEncoding:NSUTF8StringEncoding];");
47
+ break;
48
+ default:
49
+ t(), e(
50
+ `NSData *postData = [[NSData alloc] initWithData:[@"${a.text}" dataUsingEncoding:NSUTF8StringEncoding]];`
51
+ );
52
+ }
53
+ return t(), e(`NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"${S}"]`), e(" cachePolicy:NSURLRequestUseProtocolCachePolicy"), e(` timeoutInterval:${n.timeout.toFixed(1)}];`), e(`[request setHTTPMethod:@"${p}"];`), r.hasHeaders && e("[request setAllHTTPHeaderFields:headers];"), r.hasBody && e("[request setHTTPBody:postData];"), t(), e("NSURLSession *session = [NSURLSession sharedSession];"), e("NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request"), e(
54
+ " completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {"
55
+ ), e(" if (error) {", 1), e(' NSLog(@"%@", error);', 2), e(" } else {", 1), e(
56
+ " NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *) response;",
57
+ 2
58
+ ), e(' NSLog(@"%@", httpResponse);', 2), e(" }", 1), e(" }];"), e("[dataTask resume];"), l();
59
+ }
60
+ };
61
+ export {
62
+ b as nsurlsession
63
+ };
@@ -0,0 +1,14 @@
1
+ import { nsurlsession as s } from "./nsurlsession/client.js";
2
+ const o = {
3
+ info: {
4
+ key: "objc",
5
+ title: "Objective-C",
6
+ default: "nsurlsession"
7
+ },
8
+ clientsById: {
9
+ nsurlsession: s
10
+ }
11
+ };
12
+ export {
13
+ o as objc
14
+ };
@@ -0,0 +1,32 @@
1
+ import { CodeBuilder as m } from "../../../helpers/code-builder.js";
2
+ import { escapeForDoubleQuotes as h } from "../../../helpers/escape.js";
3
+ const _ = {
4
+ info: {
5
+ key: "cohttp",
6
+ title: "CoHTTP",
7
+ link: "https://github.com/mirage/ocaml-cohttp",
8
+ description: "Cohttp is a very lightweight HTTP server using Lwt or Async for OCaml",
9
+ extname: ".ml",
10
+ installation: () => "opam install cohttp-lwt-unix cohttp-async"
11
+ },
12
+ convert: ({ fullUrl: l, allHeaders: o, postData: n, method: i }, c) => {
13
+ const p = {
14
+ indent: " ",
15
+ ...c
16
+ }, d = ["get", "post", "head", "delete", "patch", "put", "options"], { push: t, blank: s, join: a } = new m({ indent: p.indent });
17
+ t("open Cohttp_lwt_unix"), t("open Cohttp"), t("open Lwt"), s(), t(`let uri = Uri.of_string "${l}" in`);
18
+ const e = Object.keys(o);
19
+ e.length === 1 ? t(
20
+ `let headers = Header.add (Header.init ()) "${e[0]}" "${h(
21
+ o[e[0]]
22
+ )}" in`
23
+ ) : e.length > 1 && (t("let headers = Header.add_list (Header.init ()) ["), e.forEach((r) => {
24
+ t(`("${r}", "${h(o[r])}");`, 1);
25
+ }), t("] in")), n.text && t(`let body = Cohttp_lwt_body.of_string ${JSON.stringify(n.text)} in`), s();
26
+ const u = e.length ? "~headers " : "", f = n.text ? "~body " : "", g = d.includes(i.toLowerCase()) ? `\`${i.toUpperCase()}` : `(Code.method_of_string "${i}")`;
27
+ return t(`Client.call ${u}${f}${g} uri`), t(">>= fun (res, body_stream) ->"), t("(* Do stuff with the result *)", 1), a();
28
+ }
29
+ };
30
+ export {
31
+ _ as cohttp
32
+ };
@@ -0,0 +1,14 @@
1
+ import { cohttp as t } from "./cohttp/client.js";
2
+ const c = {
3
+ info: {
4
+ key: "ocaml",
5
+ title: "OCaml",
6
+ default: "cohttp"
7
+ },
8
+ clientsById: {
9
+ cohttp: t
10
+ }
11
+ };
12
+ export {
13
+ c as ocaml
14
+ };