@mintlify/msft-sdk 1.1.61 → 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.
- package/dist/api-playground-2/generators/generateSnippet.js +1 -1
- package/dist/httpsnippet/src/helpers/code-builder.js +27 -0
- package/dist/httpsnippet/src/helpers/escape.js +11 -0
- package/dist/httpsnippet/src/helpers/headers.js +13 -0
- package/dist/httpsnippet/src/helpers/reducer.js +7 -0
- package/dist/httpsnippet/src/helpers/shell.js +5 -0
- package/dist/httpsnippet/src/helpers/url-format.js +35 -0
- package/dist/httpsnippet/src/helpers/url-parse.js +76 -0
- package/dist/httpsnippet/src/index.js +157 -0
- package/dist/httpsnippet/src/targets/c/libcurl/client.js +22 -0
- package/dist/httpsnippet/src/targets/c/target.js +15 -0
- package/dist/httpsnippet/src/targets/clojure/clj_http/client.js +120 -0
- package/dist/httpsnippet/src/targets/clojure/target.js +14 -0
- package/dist/httpsnippet/src/targets/csharp/httpclient/client.js +76 -0
- package/dist/httpsnippet/src/targets/csharp/restsharp/client.js +63 -0
- package/dist/httpsnippet/src/targets/csharp/target.js +17 -0
- package/dist/httpsnippet/src/targets/go/native/client.js +24 -0
- package/dist/httpsnippet/src/targets/go/target.js +15 -0
- package/dist/httpsnippet/src/targets/http/http1.1/client.js +34 -0
- package/dist/httpsnippet/src/targets/http/target.js +14 -0
- package/dist/httpsnippet/src/targets/index.js +43 -0
- package/dist/httpsnippet/src/targets/java/asynchttp/client.js +23 -0
- package/dist/httpsnippet/src/targets/java/nethttp/client.js +28 -0
- package/dist/httpsnippet/src/targets/java/okhttp/client.js +23 -0
- package/dist/httpsnippet/src/targets/java/target.js +20 -0
- package/dist/httpsnippet/src/targets/java/unirest/client.js +23 -0
- package/dist/httpsnippet/src/targets/javascript/axios/client.js +50 -0
- package/dist/httpsnippet/src/targets/javascript/fetch/client.js +61 -0
- package/dist/httpsnippet/src/targets/javascript/jquery/client.js +51 -0
- package/dist/httpsnippet/src/targets/javascript/target.js +20 -0
- package/dist/httpsnippet/src/targets/javascript/xhr/client.js +49 -0
- package/dist/httpsnippet/src/targets/json/native/client.js +39 -0
- package/dist/httpsnippet/src/targets/json/target.js +14 -0
- package/dist/httpsnippet/src/targets/kotlin/okhttp/client.js +23 -0
- package/dist/httpsnippet/src/targets/kotlin/target.js +14 -0
- package/dist/httpsnippet/src/targets/node/axios/client.js +40 -0
- package/dist/httpsnippet/src/targets/node/fetch/client.js +68 -0
- package/dist/httpsnippet/src/targets/node/native/client.js +45 -0
- package/dist/httpsnippet/src/targets/node/target.js +19 -0
- package/dist/httpsnippet/src/targets/objc/helpers.js +27 -0
- package/dist/httpsnippet/src/targets/objc/nsurlsession/client.js +63 -0
- package/dist/httpsnippet/src/targets/objc/target.js +14 -0
- package/dist/httpsnippet/src/targets/ocaml/cohttp/client.js +32 -0
- package/dist/httpsnippet/src/targets/ocaml/target.js +14 -0
- package/dist/httpsnippet/src/targets/php/curl/client.js +85 -0
- package/dist/httpsnippet/src/targets/php/guzzle/client.js +57 -0
- package/dist/httpsnippet/src/targets/php/helpers.js +65 -0
- package/dist/httpsnippet/src/targets/php/http1/client.js +28 -0
- package/dist/httpsnippet/src/targets/php/http2/client.js +55 -0
- package/dist/httpsnippet/src/targets/php/target.js +21 -0
- package/dist/httpsnippet/src/targets/powershell/common.js +19 -0
- package/dist/httpsnippet/src/targets/powershell/restmethod/client.js +14 -0
- package/dist/httpsnippet/src/targets/powershell/target.js +16 -0
- package/dist/httpsnippet/src/targets/powershell/webrequest/client.js +14 -0
- package/dist/httpsnippet/src/targets/python/helpers.js +33 -0
- package/dist/httpsnippet/src/targets/python/requests/client.js +74 -0
- package/dist/httpsnippet/src/targets/python/target.js +15 -0
- package/dist/httpsnippet/src/targets/r/httr/client.js +46 -0
- package/dist/httpsnippet/src/targets/r/target.js +14 -0
- package/dist/httpsnippet/src/targets/ruby/native/client.js +37 -0
- package/dist/httpsnippet/src/targets/ruby/target.js +14 -0
- package/dist/httpsnippet/src/targets/shell/curl/client.js +92 -0
- package/dist/httpsnippet/src/targets/shell/httpie/client.js +56 -0
- package/dist/httpsnippet/src/targets/shell/target.js +19 -0
- package/dist/httpsnippet/src/targets/shell/wget/client.js +30 -0
- package/dist/httpsnippet/src/targets/swift/helpers.js +38 -0
- package/dist/httpsnippet/src/targets/swift/target.js +14 -0
- package/dist/httpsnippet/src/targets/swift/urlsession/client.js +59 -0
- package/package.json +17 -4
|
@@ -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,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,85 @@
|
|
|
1
|
+
import { CodeBuilder as p } from "../../../helpers/code-builder.js";
|
|
2
|
+
import { escapeForDoubleQuotes as j } from "../../../helpers/escape.js";
|
|
3
|
+
import { convertType as v } from "../helpers.js";
|
|
4
|
+
const N = {
|
|
5
|
+
info: {
|
|
6
|
+
key: "curl",
|
|
7
|
+
title: "cURL",
|
|
8
|
+
link: "http://php.net/manual/en/book.curl.php",
|
|
9
|
+
description: "PHP with ext-curl",
|
|
10
|
+
extname: ".php"
|
|
11
|
+
},
|
|
12
|
+
convert: ({ uriObj: i, postData: c, fullUrl: T, method: R, httpVersion: _, cookies: O, headersObj: l }, m = {}) => {
|
|
13
|
+
const {
|
|
14
|
+
closingTag: f = !1,
|
|
15
|
+
indent: n = " ",
|
|
16
|
+
maxRedirects: U = 10,
|
|
17
|
+
namedErrors: $ = !1,
|
|
18
|
+
noTags: t = !1,
|
|
19
|
+
shortTags: C = !1,
|
|
20
|
+
timeout: P = 30
|
|
21
|
+
} = m, { push: e, blank: o, join: h } = new p({ indent: n });
|
|
22
|
+
t || (e(C ? "<?" : "<?php"), o()), e("$curl = curl_init();"), o();
|
|
23
|
+
const E = [
|
|
24
|
+
{
|
|
25
|
+
escape: !0,
|
|
26
|
+
name: "CURLOPT_PORT",
|
|
27
|
+
value: i.port
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
escape: !0,
|
|
31
|
+
name: "CURLOPT_URL",
|
|
32
|
+
value: T
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
escape: !1,
|
|
36
|
+
name: "CURLOPT_RETURNTRANSFER",
|
|
37
|
+
value: "true"
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
escape: !0,
|
|
41
|
+
name: "CURLOPT_ENCODING",
|
|
42
|
+
value: ""
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
escape: !1,
|
|
46
|
+
name: "CURLOPT_MAXREDIRS",
|
|
47
|
+
value: U
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
escape: !1,
|
|
51
|
+
name: "CURLOPT_TIMEOUT",
|
|
52
|
+
value: P
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
escape: !1,
|
|
56
|
+
name: "CURLOPT_HTTP_VERSION",
|
|
57
|
+
value: _ === "HTTP/1.0" ? "CURL_HTTP_VERSION_1_0" : "CURL_HTTP_VERSION_1_1"
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
escape: !0,
|
|
61
|
+
name: "CURLOPT_CUSTOMREQUEST",
|
|
62
|
+
value: R
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
escape: !c.jsonObj,
|
|
66
|
+
name: "CURLOPT_POSTFIELDS",
|
|
67
|
+
value: c ? c.jsonObj ? `json_encode(${v(c.jsonObj, n.repeat(2), n)})` : c.text : void 0
|
|
68
|
+
}
|
|
69
|
+
];
|
|
70
|
+
e("curl_setopt_array($curl, [");
|
|
71
|
+
const s = new p({ indent: n, join: `
|
|
72
|
+
${n}` });
|
|
73
|
+
E.forEach(({ value: r, name: L, escape: d }) => {
|
|
74
|
+
r != null && s.push(`${L} => ${d ? JSON.stringify(r) : r},`);
|
|
75
|
+
});
|
|
76
|
+
const a = O.map((r) => `${encodeURIComponent(r.name)}=${encodeURIComponent(r.value)}`);
|
|
77
|
+
a.length && s.push(`CURLOPT_COOKIE => "${a.join("; ")}",`);
|
|
78
|
+
const u = Object.keys(l).sort().map((r) => `"${r}: ${j(l[r])}"`);
|
|
79
|
+
return u.length && (s.push("CURLOPT_HTTPHEADER => ["), s.push(u.join(`,
|
|
80
|
+
${n}${n}`), 1), s.push("],")), e(s.join(), 1), e("]);"), o(), e("$response = curl_exec($curl);"), e("$err = curl_error($curl);"), o(), e("curl_close($curl);"), o(), e("if ($err) {"), e($ ? 'echo array_flip(get_defined_constants(true)["curl"])[$err];' : 'echo "cURL Error #:" . $err;', 1), e("} else {"), e("echo $response;", 1), e("}"), !t && f && (o(), e("?>")), h();
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
export {
|
|
84
|
+
N as curl
|
|
85
|
+
};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { CodeBuilder as g } from "../../../helpers/code-builder.js";
|
|
2
|
+
import { escapeForSingleQuotes as $ } from "../../../helpers/escape.js";
|
|
3
|
+
import { hasHeader as q, getHeader as v, getHeaderName as k } from "../../../helpers/headers.js";
|
|
4
|
+
import { convertType as d } from "../helpers.js";
|
|
5
|
+
const b = {
|
|
6
|
+
info: {
|
|
7
|
+
key: "guzzle",
|
|
8
|
+
title: "Guzzle",
|
|
9
|
+
link: "http://docs.guzzlephp.org/en/stable/",
|
|
10
|
+
description: "PHP with Guzzle",
|
|
11
|
+
extname: ".php",
|
|
12
|
+
installation: () => "composer require guzzlehttp/guzzle"
|
|
13
|
+
},
|
|
14
|
+
convert: ({ postData: i, fullUrl: p, method: u, cookies: h, headersObj: s }, z) => {
|
|
15
|
+
var f;
|
|
16
|
+
const e = {
|
|
17
|
+
closingTag: !1,
|
|
18
|
+
indent: " ",
|
|
19
|
+
noTags: !1,
|
|
20
|
+
shortTags: !1,
|
|
21
|
+
...z
|
|
22
|
+
}, { push: o, blank: r, join: y } = new g({ indent: e.indent }), { code: T, push: l, join: w } = new g({ indent: e.indent });
|
|
23
|
+
switch (e.noTags || o(e.shortTags ? "<?" : "<?php"), o("require_once('vendor/autoload.php');"), r(), i.mimeType) {
|
|
24
|
+
case "application/x-www-form-urlencoded":
|
|
25
|
+
l(`'form_params' => ${d(i.paramsObj, e.indent + e.indent, e.indent)},`, 1);
|
|
26
|
+
break;
|
|
27
|
+
case "multipart/form-data": {
|
|
28
|
+
const t = [];
|
|
29
|
+
if (i.params && i.params.forEach((n) => {
|
|
30
|
+
if (n.fileName) {
|
|
31
|
+
const m = {
|
|
32
|
+
name: n.name,
|
|
33
|
+
filename: n.fileName,
|
|
34
|
+
contents: n.value
|
|
35
|
+
};
|
|
36
|
+
n.contentType && (m.headers = { "Content-Type": n.contentType }), t.push(m);
|
|
37
|
+
} else n.value && t.push({
|
|
38
|
+
name: n.name,
|
|
39
|
+
contents: n.value
|
|
40
|
+
});
|
|
41
|
+
}), t.length && (l(`'multipart' => ${d(t, e.indent + e.indent, e.indent)}`, 1), q(s, "content-type") && (f = v(s, "content-type")) != null && f.indexOf("boundary"))) {
|
|
42
|
+
const n = k(s, "content-type");
|
|
43
|
+
n && delete s[n];
|
|
44
|
+
}
|
|
45
|
+
break;
|
|
46
|
+
}
|
|
47
|
+
default:
|
|
48
|
+
i.text && l(`'body' => ${d(i.text)},`, 1);
|
|
49
|
+
}
|
|
50
|
+
const c = Object.keys(s).sort().map((t) => `${e.indent}${e.indent}'${t}' => '${$(s[t])}',`), a = h.map((t) => `${encodeURIComponent(t.name)}=${encodeURIComponent(t.value)}`).join("; ");
|
|
51
|
+
return a.length && c.push(`${e.indent}${e.indent}'cookie' => '${$(a)}',`), c.length && (l("'headers' => [", 1), l(c.join(`
|
|
52
|
+
`)), l("],", 1)), o("$client = new \\GuzzleHttp\\Client();"), r(), T.length ? (o(`$response = $client->request('${u}', '${p}', [`), o(w()), o("]);")) : o(`$response = $client->request('${u}', '${p}');`), r(), o("echo $response->getBody();"), !e.noTags && e.closingTag && (r(), o("?>")), y();
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
export {
|
|
56
|
+
b as guzzle
|
|
57
|
+
};
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { escapeString as s } from "../../helpers/escape.js";
|
|
2
|
+
const O = (e, r, t) => {
|
|
3
|
+
switch (t = t || "", r = r || "", Object.prototype.toString.call(e)) {
|
|
4
|
+
case "[object Boolean]":
|
|
5
|
+
return e;
|
|
6
|
+
case "[object Null]":
|
|
7
|
+
return "null";
|
|
8
|
+
case "[object Undefined]":
|
|
9
|
+
return "null";
|
|
10
|
+
case "[object String]":
|
|
11
|
+
return `'${s(e, { delimiter: "'", escapeNewlines: !1 })}'`;
|
|
12
|
+
case "[object Number]":
|
|
13
|
+
return e.toString();
|
|
14
|
+
case "[object Array]": {
|
|
15
|
+
const o = e.map((c) => O(c, `${r}${r}`, r)).join(`,
|
|
16
|
+
${r}`);
|
|
17
|
+
return `[
|
|
18
|
+
${r}${o}
|
|
19
|
+
${t}]`;
|
|
20
|
+
}
|
|
21
|
+
case "[object Object]": {
|
|
22
|
+
const o = [];
|
|
23
|
+
for (const c in e)
|
|
24
|
+
Object.prototype.hasOwnProperty.call(e, c) && o.push(`${O(c, r)} => ${O(e[c], `${r}${r}`, r)}`);
|
|
25
|
+
return `[
|
|
26
|
+
${r}${o.join(`,
|
|
27
|
+
${r}`)}
|
|
28
|
+
${t}]`;
|
|
29
|
+
}
|
|
30
|
+
default:
|
|
31
|
+
return "null";
|
|
32
|
+
}
|
|
33
|
+
}, C = [
|
|
34
|
+
"ACL",
|
|
35
|
+
"BASELINE_CONTROL",
|
|
36
|
+
"CHECKIN",
|
|
37
|
+
"CHECKOUT",
|
|
38
|
+
"CONNECT",
|
|
39
|
+
"COPY",
|
|
40
|
+
"DELETE",
|
|
41
|
+
"GET",
|
|
42
|
+
"HEAD",
|
|
43
|
+
"LABEL",
|
|
44
|
+
"LOCK",
|
|
45
|
+
"MERGE",
|
|
46
|
+
"MKACTIVITY",
|
|
47
|
+
"MKCOL",
|
|
48
|
+
"MKWORKSPACE",
|
|
49
|
+
"MOVE",
|
|
50
|
+
"OPTIONS",
|
|
51
|
+
"POST",
|
|
52
|
+
"PROPFIND",
|
|
53
|
+
"PROPPATCH",
|
|
54
|
+
"PUT",
|
|
55
|
+
"REPORT",
|
|
56
|
+
"TRACE",
|
|
57
|
+
"UNCHECKOUT",
|
|
58
|
+
"UNLOCK",
|
|
59
|
+
"UPDATE",
|
|
60
|
+
"VERSION_CONTROL"
|
|
61
|
+
];
|
|
62
|
+
export {
|
|
63
|
+
O as convertType,
|
|
64
|
+
C as supportedMethods
|
|
65
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { CodeBuilder as f } from "../../../helpers/code-builder.js";
|
|
2
|
+
import { supportedMethods as c, convertType as s } from "../helpers.js";
|
|
3
|
+
const m = {
|
|
4
|
+
info: {
|
|
5
|
+
key: "http1",
|
|
6
|
+
title: "HTTP v1",
|
|
7
|
+
link: "http://php.net/manual/en/book.http.php",
|
|
8
|
+
description: "PHP with pecl/http v1",
|
|
9
|
+
extname: ".php"
|
|
10
|
+
},
|
|
11
|
+
convert: ({ method: r, url: l, postData: n, queryObj: o, headersObj: i, cookiesObj: $ }, h = {}) => {
|
|
12
|
+
const { closingTag: T = !1, indent: p = " ", noTags: u = !1, shortTags: a = !1 } = h, { push: e, blank: t, join: d } = new f({ indent: p });
|
|
13
|
+
switch (u || (e(a ? "<?" : "<?php"), t()), c.includes(r.toUpperCase()) || e(`HttpRequest::methodRegister('${r}');`), e("$request = new HttpRequest();"), e(`$request->setUrl(${s(l)});`), c.includes(r.toUpperCase()) ? e(`$request->setMethod(HTTP_METH_${r.toUpperCase()});`) : e(`$request->setMethod(HttpRequest::HTTP_METH_${r.toUpperCase()});`), t(), Object.keys(o).length && (e(`$request->setQueryData(${s(o, p)});`), t()), Object.keys(i).length && (e(`$request->setHeaders(${s(i, p)});`), t()), Object.keys($).length && (e(`$request->setCookies(${s($, p)});`), t()), n.mimeType) {
|
|
14
|
+
case "application/x-www-form-urlencoded":
|
|
15
|
+
e(`$request->setContentType(${s(n.mimeType)});`), e(`$request->setPostFields(${s(n.paramsObj, p)});`), t();
|
|
16
|
+
break;
|
|
17
|
+
case "application/json":
|
|
18
|
+
e(`$request->setContentType(${s(n.mimeType)});`), e(`$request->setBody(json_encode(${s(n.jsonObj, p)}));`), t();
|
|
19
|
+
break;
|
|
20
|
+
default:
|
|
21
|
+
n.text && (e(`$request->setBody(${s(n.text)});`), t());
|
|
22
|
+
}
|
|
23
|
+
return e("try {"), e("$response = $request->send();", 1), t(), e("echo $response->getBody();", 1), e("} catch (HttpException $ex) {"), e("echo $ex;", 1), e("}"), !u && T && (t(), e("?>")), d();
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
export {
|
|
27
|
+
m as http1
|
|
28
|
+
};
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { CodeBuilder as x } from "../../../helpers/code-builder.js";
|
|
2
|
+
import { hasHeader as H, getHeader as M, getHeaderName as C } from "../../../helpers/headers.js";
|
|
3
|
+
import { convertType as n } from "../helpers.js";
|
|
4
|
+
const P = {
|
|
5
|
+
info: {
|
|
6
|
+
key: "http2",
|
|
7
|
+
title: "HTTP v2",
|
|
8
|
+
link: "http://devel-m6w6.rhcloud.com/mdref/http",
|
|
9
|
+
description: "PHP with pecl/http v2",
|
|
10
|
+
extname: ".php"
|
|
11
|
+
},
|
|
12
|
+
convert: ({ postData: o, headersObj: r, method: h, queryObj: $, cookiesObj: a, url: m }, g = {}) => {
|
|
13
|
+
var y;
|
|
14
|
+
const { closingTag: w = !1, indent: s = " ", noTags: f = !1, shortTags: b = !1 } = g, { push: e, blank: t, join: k } = new x({ indent: s });
|
|
15
|
+
let i = !1;
|
|
16
|
+
switch (f || (e(b ? "<?" : "<?php"), t()), e("$client = new http\\Client;"), e("$request = new http\\Client\\Request;"), t(), o.mimeType) {
|
|
17
|
+
case "application/x-www-form-urlencoded":
|
|
18
|
+
e("$body = new http\\Message\\Body;"), e(`$body->append(new http\\QueryString(${n(o.paramsObj, s)}));`), t(), i = !0;
|
|
19
|
+
break;
|
|
20
|
+
case "multipart/form-data": {
|
|
21
|
+
if (!o.params)
|
|
22
|
+
break;
|
|
23
|
+
const d = [], l = {};
|
|
24
|
+
o.params.forEach(({ name: p, fileName: u, value: c, contentType: T }) => {
|
|
25
|
+
if (u) {
|
|
26
|
+
d.push({
|
|
27
|
+
name: p,
|
|
28
|
+
type: T,
|
|
29
|
+
file: u,
|
|
30
|
+
data: c
|
|
31
|
+
});
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
c && (l[p] = c);
|
|
35
|
+
});
|
|
36
|
+
const q = Object.keys(l).length ? n(l, s) : "null", B = d.length ? n(d, s) : "null";
|
|
37
|
+
if (e("$body = new http\\Message\\Body;"), e(`$body->addForm(${q}, ${B});`), H(r, "content-type") && (y = M(r, "content-type")) != null && y.indexOf("boundary")) {
|
|
38
|
+
const p = C(r, "content-type");
|
|
39
|
+
p && delete r[p];
|
|
40
|
+
}
|
|
41
|
+
t(), i = !0;
|
|
42
|
+
break;
|
|
43
|
+
}
|
|
44
|
+
case "application/json":
|
|
45
|
+
e("$body = new http\\Message\\Body;"), e(`$body->append(json_encode(${n(o.jsonObj, s)}));`), i = !0;
|
|
46
|
+
break;
|
|
47
|
+
default:
|
|
48
|
+
o.text && (e("$body = new http\\Message\\Body;"), e(`$body->append(${n(o.text)});`), t(), i = !0);
|
|
49
|
+
}
|
|
50
|
+
return e(`$request->setRequestUrl(${n(m)});`), e(`$request->setRequestMethod(${n(h)});`), i && (e("$request->setBody($body);"), t()), Object.keys($).length && (e(`$request->setQuery(new http\\QueryString(${n($, s)}));`), t()), Object.keys(r).length && (e(`$request->setHeaders(${n(r, s)});`), t()), Object.keys(a).length && (t(), e(`$client->setCookies(${n(a, s)});`), t()), e("$client->enqueue($request)->send();"), e("$response = $client->getResponse();"), t(), e("echo $response->getBody();"), !f && w && (t(), e("?>")), k();
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
export {
|
|
54
|
+
P as http2
|
|
55
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { curl as t } from "./curl/client.js";
|
|
2
|
+
import { guzzle as p } from "./guzzle/client.js";
|
|
3
|
+
import { http1 as o } from "./http1/client.js";
|
|
4
|
+
import { http2 as r } from "./http2/client.js";
|
|
5
|
+
const f = {
|
|
6
|
+
info: {
|
|
7
|
+
key: "php",
|
|
8
|
+
title: "PHP",
|
|
9
|
+
default: "curl",
|
|
10
|
+
cli: "php %s"
|
|
11
|
+
},
|
|
12
|
+
clientsById: {
|
|
13
|
+
curl: t,
|
|
14
|
+
guzzle: p,
|
|
15
|
+
http1: o,
|
|
16
|
+
http2: r
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
export {
|
|
20
|
+
f as php
|
|
21
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { CodeBuilder as u } from "../../helpers/code-builder.js";
|
|
2
|
+
import { escapeString as $ } from "../../helpers/escape.js";
|
|
3
|
+
import { getHeader as f } from "../../helpers/headers.js";
|
|
4
|
+
const O = (d) => ({ method: s, headersObj: n, cookies: r, uriObj: h, fullUrl: a, postData: i, allHeaders: p }) => {
|
|
5
|
+
const { push: e, join: m } = new u();
|
|
6
|
+
if (!["GET", "POST", "PUT", "DELETE", "PATCH", "HEAD", "OPTIONS"].includes(s.toUpperCase()))
|
|
7
|
+
return "Method not supported";
|
|
8
|
+
const t = [], c = Object.keys(n);
|
|
9
|
+
return c.length && (e("$headers=@{}"), c.forEach((o) => {
|
|
10
|
+
o !== "connection" && e(`$headers.Add("${o}", "${$(n[o], { escapeChar: "`" })}")`);
|
|
11
|
+
}), t.push("-Headers $headers")), r.length && (e("$session = New-Object Microsoft.PowerShell.Commands.WebRequestSession"), r.forEach((o) => {
|
|
12
|
+
e("$cookie = New-Object System.Net.Cookie"), e(`$cookie.Name = '${o.name}'`), e(`$cookie.Value = '${o.value}'`), e(`$cookie.Domain = '${h.host}'`), e("$session.Cookies.Add($cookie)");
|
|
13
|
+
}), t.push("-WebSession $session")), i.text && (t.push(
|
|
14
|
+
`-ContentType '${$(f(p, "content-type"), { delimiter: "'", escapeChar: "`" })}'`
|
|
15
|
+
), t.push(`-Body '${i.text}'`)), e(`$response = ${d} -Uri '${a}' -Method ${s} ${t.join(" ")}`.trim()), m();
|
|
16
|
+
};
|
|
17
|
+
export {
|
|
18
|
+
O as generatePowershellConvert
|
|
19
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { generatePowershellConvert as e } from "../common.js";
|
|
2
|
+
const t = {
|
|
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
|
+
extname: ".ps1"
|
|
9
|
+
},
|
|
10
|
+
convert: e("Invoke-RestMethod")
|
|
11
|
+
};
|
|
12
|
+
export {
|
|
13
|
+
t as restmethod
|
|
14
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { restmethod as e } from "./restmethod/client.js";
|
|
2
|
+
import { webrequest as t } from "./webrequest/client.js";
|
|
3
|
+
const l = {
|
|
4
|
+
info: {
|
|
5
|
+
key: "powershell",
|
|
6
|
+
title: "Powershell",
|
|
7
|
+
default: "webrequest"
|
|
8
|
+
},
|
|
9
|
+
clientsById: {
|
|
10
|
+
webrequest: t,
|
|
11
|
+
restmethod: e
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
export {
|
|
15
|
+
l as powershell
|
|
16
|
+
};
|