@mintlify/msft-sdk 1.1.60 → 1.1.62

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 (73) hide show
  1. package/dist/api-playground-2/components/Example/GeneratedRequestExample.js +54 -54
  2. package/dist/api-playground-2/generators/generateSnippet.js +30 -183
  3. package/dist/components/content-components/code-block.js +36 -35
  4. package/dist/components/content-components/code-snippets.js +12 -10
  5. package/dist/httpsnippet/src/helpers/code-builder.js +27 -0
  6. package/dist/httpsnippet/src/helpers/escape.js +11 -0
  7. package/dist/httpsnippet/src/helpers/headers.js +13 -0
  8. package/dist/httpsnippet/src/helpers/reducer.js +7 -0
  9. package/dist/httpsnippet/src/helpers/shell.js +5 -0
  10. package/dist/httpsnippet/src/helpers/url-format.js +35 -0
  11. package/dist/httpsnippet/src/helpers/url-parse.js +76 -0
  12. package/dist/httpsnippet/src/index.js +157 -0
  13. package/dist/httpsnippet/src/targets/c/libcurl/client.js +22 -0
  14. package/dist/httpsnippet/src/targets/c/target.js +15 -0
  15. package/dist/httpsnippet/src/targets/clojure/clj_http/client.js +120 -0
  16. package/dist/httpsnippet/src/targets/clojure/target.js +14 -0
  17. package/dist/httpsnippet/src/targets/csharp/httpclient/client.js +76 -0
  18. package/dist/httpsnippet/src/targets/csharp/restsharp/client.js +63 -0
  19. package/dist/httpsnippet/src/targets/csharp/target.js +17 -0
  20. package/dist/httpsnippet/src/targets/go/native/client.js +24 -0
  21. package/dist/httpsnippet/src/targets/go/target.js +15 -0
  22. package/dist/httpsnippet/src/targets/http/http1.1/client.js +34 -0
  23. package/dist/httpsnippet/src/targets/http/target.js +14 -0
  24. package/dist/httpsnippet/src/targets/index.js +43 -0
  25. package/dist/httpsnippet/src/targets/java/asynchttp/client.js +23 -0
  26. package/dist/httpsnippet/src/targets/java/nethttp/client.js +28 -0
  27. package/dist/httpsnippet/src/targets/java/okhttp/client.js +23 -0
  28. package/dist/httpsnippet/src/targets/java/target.js +20 -0
  29. package/dist/httpsnippet/src/targets/java/unirest/client.js +23 -0
  30. package/dist/httpsnippet/src/targets/javascript/axios/client.js +50 -0
  31. package/dist/httpsnippet/src/targets/javascript/fetch/client.js +61 -0
  32. package/dist/httpsnippet/src/targets/javascript/jquery/client.js +51 -0
  33. package/dist/httpsnippet/src/targets/javascript/target.js +20 -0
  34. package/dist/httpsnippet/src/targets/javascript/xhr/client.js +49 -0
  35. package/dist/httpsnippet/src/targets/json/native/client.js +39 -0
  36. package/dist/httpsnippet/src/targets/json/target.js +14 -0
  37. package/dist/httpsnippet/src/targets/kotlin/okhttp/client.js +23 -0
  38. package/dist/httpsnippet/src/targets/kotlin/target.js +14 -0
  39. package/dist/httpsnippet/src/targets/node/axios/client.js +40 -0
  40. package/dist/httpsnippet/src/targets/node/fetch/client.js +68 -0
  41. package/dist/httpsnippet/src/targets/node/native/client.js +45 -0
  42. package/dist/httpsnippet/src/targets/node/target.js +19 -0
  43. package/dist/httpsnippet/src/targets/objc/helpers.js +27 -0
  44. package/dist/httpsnippet/src/targets/objc/nsurlsession/client.js +63 -0
  45. package/dist/httpsnippet/src/targets/objc/target.js +14 -0
  46. package/dist/httpsnippet/src/targets/ocaml/cohttp/client.js +32 -0
  47. package/dist/httpsnippet/src/targets/ocaml/target.js +14 -0
  48. package/dist/httpsnippet/src/targets/php/curl/client.js +85 -0
  49. package/dist/httpsnippet/src/targets/php/guzzle/client.js +57 -0
  50. package/dist/httpsnippet/src/targets/php/helpers.js +65 -0
  51. package/dist/httpsnippet/src/targets/php/http1/client.js +28 -0
  52. package/dist/httpsnippet/src/targets/php/http2/client.js +55 -0
  53. package/dist/httpsnippet/src/targets/php/target.js +21 -0
  54. package/dist/httpsnippet/src/targets/powershell/common.js +19 -0
  55. package/dist/httpsnippet/src/targets/powershell/restmethod/client.js +14 -0
  56. package/dist/httpsnippet/src/targets/powershell/target.js +16 -0
  57. package/dist/httpsnippet/src/targets/powershell/webrequest/client.js +14 -0
  58. package/dist/httpsnippet/src/targets/python/helpers.js +33 -0
  59. package/dist/httpsnippet/src/targets/python/requests/client.js +74 -0
  60. package/dist/httpsnippet/src/targets/python/target.js +15 -0
  61. package/dist/httpsnippet/src/targets/r/httr/client.js +46 -0
  62. package/dist/httpsnippet/src/targets/r/target.js +14 -0
  63. package/dist/httpsnippet/src/targets/ruby/native/client.js +37 -0
  64. package/dist/httpsnippet/src/targets/ruby/target.js +14 -0
  65. package/dist/httpsnippet/src/targets/shell/curl/client.js +92 -0
  66. package/dist/httpsnippet/src/targets/shell/httpie/client.js +56 -0
  67. package/dist/httpsnippet/src/targets/shell/target.js +19 -0
  68. package/dist/httpsnippet/src/targets/shell/wget/client.js +30 -0
  69. package/dist/httpsnippet/src/targets/swift/helpers.js +38 -0
  70. package/dist/httpsnippet/src/targets/swift/target.js +14 -0
  71. package/dist/httpsnippet/src/targets/swift/urlsession/client.js +59 -0
  72. package/dist/index.d.ts +2 -1
  73. package/package.json +17 -3
@@ -0,0 +1,34 @@
1
+ import { CodeBuilder as m } from "../../../helpers/code-builder.js";
2
+ const i = `\r
3
+ `, y = {
4
+ info: {
5
+ key: "http1.1",
6
+ title: "HTTP/1.1",
7
+ link: "https://tools.ietf.org/html/rfc7230",
8
+ description: "HTTP/1.1 request string in accordance with RFC 7230",
9
+ extname: null
10
+ },
11
+ convert: ({ method: h, fullUrl: a, uriObj: c, httpVersion: l, allHeaders: r, postData: n }, u) => {
12
+ const o = {
13
+ absoluteURI: !1,
14
+ autoContentLength: !0,
15
+ autoHost: !0,
16
+ ...u
17
+ }, { blank: g, push: t, join: p } = new m({ indent: "", join: i }), d = o.absoluteURI ? a : c.path;
18
+ t(`${h} ${d} ${l}`);
19
+ const s = Object.keys(r);
20
+ if (s.forEach((e) => {
21
+ const C = e.toLowerCase().replace(/(^|-)(\w)/g, (L) => L.toUpperCase());
22
+ t(`${C}: ${r[e]}`);
23
+ }), o.autoHost && !s.includes("host") && t(`Host: ${c.host}`), o.autoContentLength && n.text && !s.includes("content-length")) {
24
+ const e = Buffer.byteLength(n.text, "ascii").toString();
25
+ t(`Content-Length: ${e}`);
26
+ }
27
+ g();
28
+ const f = p(), $ = n.text || "";
29
+ return `${f}${i}${$}`;
30
+ }
31
+ };
32
+ export {
33
+ y as http11
34
+ };
@@ -0,0 +1,14 @@
1
+ import { http11 as t } from "./http1.1/client.js";
2
+ const e = {
3
+ info: {
4
+ key: "http",
5
+ title: "HTTP",
6
+ default: "http1.1"
7
+ },
8
+ clientsById: {
9
+ "http1.1": t
10
+ }
11
+ };
12
+ export {
13
+ e as http
14
+ };
@@ -0,0 +1,43 @@
1
+ import { c as o } from "./c/target.js";
2
+ import { clojure as r } from "./clojure/target.js";
3
+ import { csharp as m } from "./csharp/target.js";
4
+ import { go as t } from "./go/target.js";
5
+ import { http as p } from "./http/target.js";
6
+ import { java as i } from "./java/target.js";
7
+ import { javascript as f } from "./javascript/target.js";
8
+ import { json as s } from "./json/target.js";
9
+ import { kotlin as a } from "./kotlin/target.js";
10
+ import { node as c } from "./node/target.js";
11
+ import { objc as e } from "./objc/target.js";
12
+ import { ocaml as l } from "./ocaml/target.js";
13
+ import { php as h } from "./php/target.js";
14
+ import { powershell as j } from "./powershell/target.js";
15
+ import { python as n } from "./python/target.js";
16
+ import { r as b } from "./r/target.js";
17
+ import { ruby as g } from "./ruby/target.js";
18
+ import { shell as u } from "./shell/target.js";
19
+ import { swift as v } from "./swift/target.js";
20
+ const M = {
21
+ c: o,
22
+ clojure: r,
23
+ csharp: m,
24
+ go: t,
25
+ http: p,
26
+ java: i,
27
+ javascript: f,
28
+ json: s,
29
+ kotlin: a,
30
+ node: c,
31
+ objc: e,
32
+ ocaml: l,
33
+ php: h,
34
+ powershell: j,
35
+ python: n,
36
+ r: b,
37
+ ruby: g,
38
+ shell: u,
39
+ swift: v
40
+ };
41
+ export {
42
+ M as targets
43
+ };
@@ -0,0 +1,23 @@
1
+ import { CodeBuilder as a } from "../../../helpers/code-builder.js";
2
+ import { escapeForDoubleQuotes as y } from "../../../helpers/escape.js";
3
+ const d = {
4
+ info: {
5
+ key: "asynchttp",
6
+ title: "AsyncHttp",
7
+ link: "https://github.com/AsyncHttpClient/async-http-client",
8
+ description: "Asynchronous Http and WebSocket Client library for Java",
9
+ extname: ".java"
10
+ },
11
+ convert: ({ method: i, allHeaders: e, postData: n, fullUrl: c }, s) => {
12
+ const p = {
13
+ indent: " ",
14
+ ...s
15
+ }, { blank: r, push: t, join: l } = new a({ indent: p.indent });
16
+ return t("AsyncHttpClient client = new DefaultAsyncHttpClient();"), t(`client.prepare("${i.toUpperCase()}", "${c}")`), Object.keys(e).forEach((o) => {
17
+ t(`.setHeader("${o}", "${y(e[o])}")`, 1);
18
+ }), n.text && t(`.setBody(${JSON.stringify(n.text)})`, 1), t(".execute()", 1), t(".toCompletableFuture()", 1), t(".thenAccept(System.out::println)", 1), t(".join();", 1), r(), t("client.close();"), l();
19
+ }
20
+ };
21
+ export {
22
+ d as asynchttp
23
+ };
@@ -0,0 +1,28 @@
1
+ import { CodeBuilder as u } from "../../../helpers/code-builder.js";
2
+ import { escapeForDoubleQuotes as a } from "../../../helpers/escape.js";
3
+ const c = {
4
+ info: {
5
+ key: "nethttp",
6
+ title: "java.net.http",
7
+ link: "https://openjdk.java.net/groups/net/httpclient/intro.html",
8
+ description: "Java Standardized HTTP Client API",
9
+ extname: ".java"
10
+ },
11
+ convert: ({ allHeaders: e, fullUrl: r, method: n, postData: o }, i) => {
12
+ const p = {
13
+ indent: " ",
14
+ ...i
15
+ }, { push: t, join: d } = new u({ indent: p.indent });
16
+ return t("HttpRequest request = HttpRequest.newBuilder()"), t(`.uri(URI.create("${r}"))`, 2), Object.keys(e).forEach((s) => {
17
+ t(`.header("${s}", "${a(e[s])}")`, 2);
18
+ }), o.text ? t(
19
+ `.method("${n.toUpperCase()}", HttpRequest.BodyPublishers.ofString(${JSON.stringify(o.text)}))`,
20
+ 2
21
+ ) : t(`.method("${n.toUpperCase()}", HttpRequest.BodyPublishers.noBody())`, 2), t(".build();", 2), t(
22
+ "HttpResponse<String> response = HttpClient.newHttpClient().send(request, HttpResponse.BodyHandlers.ofString());"
23
+ ), t("System.out.println(response.body());"), d();
24
+ }
25
+ };
26
+ export {
27
+ c as nethttp
28
+ };
@@ -0,0 +1,23 @@
1
+ import { CodeBuilder as T } from "../../../helpers/code-builder.js";
2
+ import { escapeForDoubleQuotes as c } 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: ".java"
10
+ },
11
+ convert: ({ postData: t, method: i, fullUrl: s, allHeaders: n }, p) => {
12
+ const d = {
13
+ indent: " ",
14
+ ...p
15
+ }, { push: e, blank: o, join: u } = new T({ indent: d.indent }), l = ["GET", "POST", "PUT", "DELETE", "PATCH", "HEAD"], y = ["POST", "PUT", "DELETE", "PATCH"];
16
+ return e("OkHttpClient client = new OkHttpClient();"), o(), t.text && (t.boundary ? e(`MediaType mediaType = MediaType.parse("${t.mimeType}; boundary=${t.boundary}");`) : e(`MediaType mediaType = MediaType.parse("${t.mimeType}");`), e(`RequestBody body = RequestBody.create(mediaType, ${JSON.stringify(t.text)});`)), e("Request request = new Request.Builder()"), e(`.url("${s}")`, 1), l.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}", "${c(n[r])}")`, 1);
18
+ }), e(".build();", 1), o(), e("Response response = client.newCall(request).execute();"), u();
19
+ }
20
+ };
21
+ export {
22
+ b as okhttp
23
+ };
@@ -0,0 +1,20 @@
1
+ import { asynchttp as t } from "./asynchttp/client.js";
2
+ import { nethttp as o } from "./nethttp/client.js";
3
+ import { okhttp as r } from "./okhttp/client.js";
4
+ import { unirest as i } from "./unirest/client.js";
5
+ const n = {
6
+ info: {
7
+ key: "java",
8
+ title: "Java",
9
+ default: "unirest"
10
+ },
11
+ clientsById: {
12
+ asynchttp: t,
13
+ nethttp: o,
14
+ okhttp: r,
15
+ unirest: i
16
+ }
17
+ };
18
+ export {
19
+ n as java
20
+ };
@@ -0,0 +1,23 @@
1
+ import { CodeBuilder as u } from "../../../helpers/code-builder.js";
2
+ import { escapeForDoubleQuotes as a } from "../../../helpers/escape.js";
3
+ const m = {
4
+ info: {
5
+ key: "unirest",
6
+ title: "Unirest",
7
+ link: "http://unirest.io/java.html",
8
+ description: "Lightweight HTTP Request Client Library",
9
+ extname: ".java"
10
+ },
11
+ convert: ({ method: t, allHeaders: n, postData: s, fullUrl: i }, r) => {
12
+ const p = {
13
+ indent: " ",
14
+ ...r
15
+ }, { join: c, push: e } = new u({ indent: p.indent });
16
+ return ["GET", "POST", "PUT", "DELETE", "PATCH", "HEAD", "OPTIONS"].includes(t.toUpperCase()) ? e(`HttpResponse<String> response = Unirest.${t.toLowerCase()}("${i}")`) : e(`HttpResponse<String> response = Unirest.customMethod("${t.toUpperCase()}","${i}")`), Object.keys(n).forEach((o) => {
17
+ e(`.header("${o}", "${a(n[o])}")`, 1);
18
+ }), s.text && e(`.body(${JSON.stringify(s.text)})`, 1), e(".asString();", 1), c();
19
+ }
20
+ };
21
+ export {
22
+ m as unirest
23
+ };
@@ -0,0 +1,50 @@
1
+ import h from "stringify-object";
2
+ import { CodeBuilder as x } from "../../../helpers/code-builder.js";
3
+ const u = {
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: ({ allHeaders: s, method: t, url: c, queryObj: i, postData: o }, m) => {
13
+ const d = {
14
+ indent: " ",
15
+ ...m
16
+ }, { blank: a, push: e, join: f, addPostProcessor: l } = new x({ indent: d.indent });
17
+ e("import axios from 'axios';"), a();
18
+ const r = {
19
+ method: t,
20
+ url: c
21
+ };
22
+ switch (Object.keys(i).length && (r.params = i), Object.keys(s).length && (r.headers = s), o.mimeType) {
23
+ case "application/x-www-form-urlencoded":
24
+ o.params && (e("const encodedParams = new URLSearchParams();"), o.params.forEach((n) => {
25
+ e(`encodedParams.set('${n.name}', '${n.value}');`);
26
+ }), a(), r.data = "encodedParams,", l((n) => n.replace(/'encodedParams,'/, "encodedParams,")));
27
+ break;
28
+ case "application/json":
29
+ o.jsonObj && (r.data = o.jsonObj);
30
+ break;
31
+ case "multipart/form-data":
32
+ if (!o.params)
33
+ break;
34
+ e("const form = new FormData();"), o.params.forEach((n) => {
35
+ e(`form.append('${n.name}', '${n.value || n.fileName || ""}');`);
36
+ }), a(), r.data = "[form]";
37
+ break;
38
+ default:
39
+ o.text && (r.data = o.text);
40
+ }
41
+ const p = h(r, {
42
+ indent: " ",
43
+ inlineCharacterLimit: 80
44
+ }).replace('"[form]"', "form");
45
+ return e(`const options = ${p};`), a(), e("axios"), e(".request(options)", 1), e(".then(res => console.log(res.data))", 1), e(".catch(err => console.error(err));", 1), f();
46
+ }
47
+ };
48
+ export {
49
+ u as axios
50
+ };
@@ -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
+ };