@readme/httpsnippet 10.0.4 → 10.1.0
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/README.md +2 -2
- package/dist/{chunk-CSDAGXA2.js → chunk-452Q5GGQ.js} +60 -265
- package/dist/chunk-452Q5GGQ.js.map +1 -0
- package/dist/chunk-KT7MO6Z4.js +1 -1
- package/dist/chunk-KT7MO6Z4.js.map +1 -1
- package/dist/chunk-Y7NI4MMY.js +1 -1
- package/dist/chunk-Y7NI4MMY.js.map +1 -1
- package/dist/helpers/code-builder.cjs +1 -1
- package/dist/helpers/code-builder.cjs.map +1 -1
- package/dist/helpers/code-builder.js +1 -1
- package/dist/helpers/code-builder.js.map +1 -1
- package/dist/helpers/reducer.cjs +1 -1
- package/dist/helpers/reducer.cjs.map +1 -1
- package/dist/helpers/reducer.js +1 -1
- package/dist/helpers/reducer.js.map +1 -1
- package/dist/{index-BTuTGf5t.d.ts → index-Bi-oJSCB.d.ts} +6 -6
- package/dist/{index-C-fCLOHv.d.cts → index-CM3ebXTM.d.cts} +6 -6
- package/dist/index.cjs +101 -306
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +3 -3
- package/dist/index.js.map +1 -1
- package/dist/targets/index.cjs +60 -265
- package/dist/targets/index.cjs.map +1 -1
- package/dist/targets/index.d.cts +1 -1
- package/dist/targets/index.d.ts +1 -1
- package/dist/targets/index.js +2 -2
- package/dist/targets/index.js.map +1 -1
- package/package.json +4 -6
- package/dist/chunk-CSDAGXA2.js.map +0 -1
package/dist/targets/index.cjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var stringifyObject7 = require('stringify-object');
|
|
4
4
|
|
|
5
5
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
6
6
|
|
|
7
|
-
var
|
|
7
|
+
var stringifyObject7__default = /*#__PURE__*/_interopDefault(stringifyObject7);
|
|
8
8
|
|
|
9
9
|
// src/helpers/code-builder.ts
|
|
10
10
|
var DEFAULT_INDENTATION_CHARACTER = "";
|
|
@@ -529,8 +529,7 @@ var restsharp = {
|
|
|
529
529
|
});
|
|
530
530
|
switch (postData.mimeType) {
|
|
531
531
|
case "multipart/form-data":
|
|
532
|
-
if (!postData.params)
|
|
533
|
-
break;
|
|
532
|
+
if (!postData.params) break;
|
|
534
533
|
postData.params.forEach((param) => {
|
|
535
534
|
if (param.fileName) {
|
|
536
535
|
push(`request.AddFile("${param.name}", "${param.fileName}");`);
|
|
@@ -540,22 +539,19 @@ var restsharp = {
|
|
|
540
539
|
});
|
|
541
540
|
break;
|
|
542
541
|
case "application/x-www-form-urlencoded":
|
|
543
|
-
if (!postData.params)
|
|
544
|
-
break;
|
|
542
|
+
if (!postData.params) break;
|
|
545
543
|
postData.params.forEach((param) => {
|
|
546
544
|
push(`request.AddParameter("${param.name}", "${param.value}");`);
|
|
547
545
|
});
|
|
548
546
|
break;
|
|
549
547
|
case "application/json": {
|
|
550
|
-
if (!postData.text)
|
|
551
|
-
break;
|
|
548
|
+
if (!postData.text) break;
|
|
552
549
|
const text = JSON.stringify(postData.text);
|
|
553
550
|
push(`request.AddJsonBody(${text}, false);`);
|
|
554
551
|
break;
|
|
555
552
|
}
|
|
556
553
|
default:
|
|
557
|
-
if (!postData.text)
|
|
558
|
-
break;
|
|
554
|
+
if (!postData.text) break;
|
|
559
555
|
push(`request.AddStringBody("${postData.text}", "${postData.mimeType}");`);
|
|
560
556
|
}
|
|
561
557
|
push(`var response = await client.${title(method)}Async(request);
|
|
@@ -963,7 +959,7 @@ var axios = {
|
|
|
963
959
|
requestOptions.data = postData.text;
|
|
964
960
|
}
|
|
965
961
|
}
|
|
966
|
-
const optionString =
|
|
962
|
+
const optionString = stringifyObject7__default.default(requestOptions, {
|
|
967
963
|
indent: " ",
|
|
968
964
|
inlineCharacterLimit: 80
|
|
969
965
|
}).replace('"[form]"', "form");
|
|
@@ -971,12 +967,8 @@ var axios = {
|
|
|
971
967
|
blank();
|
|
972
968
|
push("axios");
|
|
973
969
|
push(".request(options)", 1);
|
|
974
|
-
push(".then(
|
|
975
|
-
push("console.
|
|
976
|
-
push("})", 1);
|
|
977
|
-
push(".catch(function (error) {", 1);
|
|
978
|
-
push("console.error(error);", 2);
|
|
979
|
-
push("});", 1);
|
|
970
|
+
push(".then(res => console.log(res.data))", 1);
|
|
971
|
+
push(".catch(err => console.error(err));", 1);
|
|
980
972
|
return join();
|
|
981
973
|
}
|
|
982
974
|
};
|
|
@@ -1036,7 +1028,7 @@ var fetch = {
|
|
|
1036
1028
|
delete options.headers;
|
|
1037
1029
|
}
|
|
1038
1030
|
push(
|
|
1039
|
-
`const options = ${
|
|
1031
|
+
`const options = ${stringifyObject7__default.default(options, {
|
|
1040
1032
|
indent: opts.indent,
|
|
1041
1033
|
inlineCharacterLimit: 80,
|
|
1042
1034
|
// The Fetch API body only accepts string parameters, but stringified JSON can be difficult
|
|
@@ -1060,8 +1052,8 @@ var fetch = {
|
|
|
1060
1052
|
blank();
|
|
1061
1053
|
}
|
|
1062
1054
|
push(`fetch('${fullUrl}', options)`);
|
|
1063
|
-
push(".then(
|
|
1064
|
-
push(".then(
|
|
1055
|
+
push(".then(res => res.json())", 1);
|
|
1056
|
+
push(".then(res => console.log(res))", 1);
|
|
1065
1057
|
push(".catch(err => console.error(err));", 1);
|
|
1066
1058
|
return join();
|
|
1067
1059
|
}
|
|
@@ -1122,11 +1114,11 @@ var jquery = {
|
|
|
1122
1114
|
settings.data = postData.text;
|
|
1123
1115
|
}
|
|
1124
1116
|
}
|
|
1125
|
-
const stringifiedSettings =
|
|
1117
|
+
const stringifiedSettings = stringifyObject7__default.default(settings, { indent: opts.indent }).replace("'[form]'", "form");
|
|
1126
1118
|
push(`const settings = ${stringifiedSettings};`);
|
|
1127
1119
|
blank();
|
|
1128
|
-
push("$.ajax(settings).done(
|
|
1129
|
-
push("console.log(
|
|
1120
|
+
push("$.ajax(settings).done(res => {");
|
|
1121
|
+
push("console.log(res);", 1);
|
|
1130
1122
|
push("});");
|
|
1131
1123
|
return join();
|
|
1132
1124
|
}
|
|
@@ -1149,7 +1141,7 @@ var xhr = {
|
|
|
1149
1141
|
switch (postData.mimeType) {
|
|
1150
1142
|
case "application/json":
|
|
1151
1143
|
push(
|
|
1152
|
-
`const data = JSON.stringify(${
|
|
1144
|
+
`const data = JSON.stringify(${stringifyObject7__default.default(postData.jsonObj, {
|
|
1153
1145
|
indent: opts.indent
|
|
1154
1146
|
})});`
|
|
1155
1147
|
);
|
|
@@ -1203,7 +1195,7 @@ var javascript = {
|
|
|
1203
1195
|
info: {
|
|
1204
1196
|
key: "javascript",
|
|
1205
1197
|
title: "JavaScript",
|
|
1206
|
-
default: "
|
|
1198
|
+
default: "fetch"
|
|
1207
1199
|
},
|
|
1208
1200
|
clientsById: {
|
|
1209
1201
|
xhr,
|
|
@@ -1342,7 +1334,7 @@ var axios2 = {
|
|
|
1342
1334
|
title: "Axios",
|
|
1343
1335
|
link: "https://github.com/axios/axios",
|
|
1344
1336
|
description: "Promise based HTTP client for the browser and node.js",
|
|
1345
|
-
extname: ".
|
|
1337
|
+
extname: ".js",
|
|
1346
1338
|
installation: "npm install axios --save"
|
|
1347
1339
|
},
|
|
1348
1340
|
convert: ({ method, fullUrl, allHeaders, postData }, options) => {
|
|
@@ -1351,7 +1343,8 @@ var axios2 = {
|
|
|
1351
1343
|
...options
|
|
1352
1344
|
};
|
|
1353
1345
|
const { blank, join, push, addPostProcessor } = new CodeBuilder({ indent: opts.indent });
|
|
1354
|
-
push("
|
|
1346
|
+
push("import axios from 'axios';");
|
|
1347
|
+
blank();
|
|
1355
1348
|
const reqOpts = {
|
|
1356
1349
|
method,
|
|
1357
1350
|
url: fullUrl
|
|
@@ -1362,8 +1355,6 @@ var axios2 = {
|
|
|
1362
1355
|
switch (postData.mimeType) {
|
|
1363
1356
|
case "application/x-www-form-urlencoded":
|
|
1364
1357
|
if (postData.params) {
|
|
1365
|
-
push("const { URLSearchParams } = require('url');");
|
|
1366
|
-
blank();
|
|
1367
1358
|
push("const encodedParams = new URLSearchParams();");
|
|
1368
1359
|
postData.params.forEach((param) => {
|
|
1369
1360
|
push(`encodedParams.set('${param.name}', '${param.value}');`);
|
|
@@ -1374,39 +1365,32 @@ var axios2 = {
|
|
|
1374
1365
|
}
|
|
1375
1366
|
break;
|
|
1376
1367
|
case "application/json":
|
|
1377
|
-
blank();
|
|
1378
1368
|
if (postData.jsonObj) {
|
|
1379
1369
|
reqOpts.data = postData.jsonObj;
|
|
1380
1370
|
}
|
|
1381
1371
|
break;
|
|
1382
1372
|
default:
|
|
1383
|
-
blank();
|
|
1384
1373
|
if (postData.text) {
|
|
1385
1374
|
reqOpts.data = postData.text;
|
|
1386
1375
|
}
|
|
1387
1376
|
}
|
|
1388
|
-
const stringifiedOptions =
|
|
1377
|
+
const stringifiedOptions = stringifyObject7__default.default(reqOpts, { indent: " ", inlineCharacterLimit: 80 });
|
|
1389
1378
|
push(`const options = ${stringifiedOptions};`);
|
|
1390
1379
|
blank();
|
|
1391
1380
|
push("axios");
|
|
1392
1381
|
push(".request(options)", 1);
|
|
1393
|
-
push(".then(
|
|
1394
|
-
push("console.
|
|
1395
|
-
push("})", 1);
|
|
1396
|
-
push(".catch(function (error) {", 1);
|
|
1397
|
-
push("console.error(error);", 2);
|
|
1398
|
-
push("});", 1);
|
|
1382
|
+
push(".then(res => console.log(res.data))", 1);
|
|
1383
|
+
push(".catch(err => console.error(err));", 1);
|
|
1399
1384
|
return join();
|
|
1400
1385
|
}
|
|
1401
1386
|
};
|
|
1402
1387
|
var fetch2 = {
|
|
1403
1388
|
info: {
|
|
1404
1389
|
key: "fetch",
|
|
1405
|
-
title: "
|
|
1406
|
-
link: "https://
|
|
1407
|
-
description: "
|
|
1408
|
-
extname: ".
|
|
1409
|
-
installation: "npm install node-fetch@2 --save"
|
|
1390
|
+
title: "fetch",
|
|
1391
|
+
link: "https://nodejs.org/docs/latest/api/globals.html#fetch",
|
|
1392
|
+
description: "Perform asynchronous HTTP requests with the Fetch API",
|
|
1393
|
+
extname: ".js"
|
|
1410
1394
|
},
|
|
1411
1395
|
convert: ({ method, fullUrl, postData, headersObj, cookies }, options) => {
|
|
1412
1396
|
const opts = {
|
|
@@ -1415,7 +1399,6 @@ var fetch2 = {
|
|
|
1415
1399
|
};
|
|
1416
1400
|
let includeFS = false;
|
|
1417
1401
|
const { blank, push, join, unshift } = new CodeBuilder({ indent: opts.indent });
|
|
1418
|
-
push("const fetch = require('node-fetch');");
|
|
1419
1402
|
const url = fullUrl;
|
|
1420
1403
|
const reqOpts = {
|
|
1421
1404
|
method
|
|
@@ -1425,13 +1408,12 @@ var fetch2 = {
|
|
|
1425
1408
|
}
|
|
1426
1409
|
switch (postData.mimeType) {
|
|
1427
1410
|
case "application/x-www-form-urlencoded":
|
|
1428
|
-
unshift("const { URLSearchParams } = require('url');");
|
|
1429
1411
|
push("const encodedParams = new URLSearchParams();");
|
|
1430
|
-
blank();
|
|
1431
1412
|
postData.params?.forEach((param) => {
|
|
1432
1413
|
push(`encodedParams.set('${param.name}', '${param.value}');`);
|
|
1433
1414
|
});
|
|
1434
1415
|
reqOpts.body = "encodedParams";
|
|
1416
|
+
blank();
|
|
1435
1417
|
break;
|
|
1436
1418
|
case "application/json":
|
|
1437
1419
|
if (postData.jsonObj) {
|
|
@@ -1446,9 +1428,7 @@ var fetch2 = {
|
|
|
1446
1428
|
if (contentTypeHeader) {
|
|
1447
1429
|
delete headersObj[contentTypeHeader];
|
|
1448
1430
|
}
|
|
1449
|
-
unshift("const FormData = require('form-data');");
|
|
1450
1431
|
push("const formData = new FormData();");
|
|
1451
|
-
blank();
|
|
1452
1432
|
postData.params.forEach((param) => {
|
|
1453
1433
|
if (!param.fileName && !param.fileName && !param.contentType) {
|
|
1454
1434
|
push(`formData.append('${param.name}', '${param.value}');`);
|
|
@@ -1456,9 +1436,13 @@ var fetch2 = {
|
|
|
1456
1436
|
}
|
|
1457
1437
|
if (param.fileName) {
|
|
1458
1438
|
includeFS = true;
|
|
1459
|
-
push(
|
|
1439
|
+
push(
|
|
1440
|
+
`formData.append('${param.name}', await new Response(fs.createReadStream('${param.fileName}')).blob());`
|
|
1441
|
+
);
|
|
1460
1442
|
}
|
|
1461
1443
|
});
|
|
1444
|
+
reqOpts.body = "formData";
|
|
1445
|
+
blank();
|
|
1462
1446
|
break;
|
|
1463
1447
|
default:
|
|
1464
1448
|
if (postData.text) {
|
|
@@ -1474,12 +1458,11 @@ var fetch2 = {
|
|
|
1474
1458
|
reqOpts.headers.cookie = cookiesString;
|
|
1475
1459
|
}
|
|
1476
1460
|
}
|
|
1477
|
-
blank();
|
|
1478
1461
|
push(`const url = '${url}';`);
|
|
1479
1462
|
if (reqOpts.headers && !Object.keys(reqOpts.headers).length) {
|
|
1480
1463
|
delete reqOpts.headers;
|
|
1481
1464
|
}
|
|
1482
|
-
const stringifiedOptions =
|
|
1465
|
+
const stringifiedOptions = stringifyObject7__default.default(reqOpts, {
|
|
1483
1466
|
indent: " ",
|
|
1484
1467
|
inlineCharacterLimit: 80,
|
|
1485
1468
|
// The Fetch API body only accepts string parameters, but stringified JSON can be difficult to
|
|
@@ -1495,17 +1478,13 @@ var fetch2 = {
|
|
|
1495
1478
|
push(`const options = ${stringifiedOptions};`);
|
|
1496
1479
|
blank();
|
|
1497
1480
|
if (includeFS) {
|
|
1498
|
-
unshift("
|
|
1499
|
-
}
|
|
1500
|
-
if (postData.params && postData.mimeType === "multipart/form-data") {
|
|
1501
|
-
push("options.body = formData;");
|
|
1502
|
-
blank();
|
|
1481
|
+
unshift("import fs from 'fs';\n");
|
|
1503
1482
|
}
|
|
1504
1483
|
push("fetch(url, options)");
|
|
1505
1484
|
push(".then(res => res.json())", 1);
|
|
1506
1485
|
push(".then(json => console.log(json))", 1);
|
|
1507
|
-
push(".catch(err => console.error(
|
|
1508
|
-
return join().replace(/'encodedParams'/, "encodedParams").replace(/
|
|
1486
|
+
push(".catch(err => console.error(err));", 1);
|
|
1487
|
+
return join().replace(/'encodedParams'/, "encodedParams").replace(/'formData'/, "formData");
|
|
1509
1488
|
}
|
|
1510
1489
|
};
|
|
1511
1490
|
var native3 = {
|
|
@@ -1528,7 +1507,7 @@ var native3 = {
|
|
|
1528
1507
|
};
|
|
1529
1508
|
push(`const http = require('${uriObj.protocol?.replace(":", "")}');`);
|
|
1530
1509
|
blank();
|
|
1531
|
-
push(`const options = ${
|
|
1510
|
+
push(`const options = ${stringifyObject7__default.default(reqOpts, { indent })};`);
|
|
1532
1511
|
blank();
|
|
1533
1512
|
push("const req = http.request(options, function (res) {");
|
|
1534
1513
|
push("const chunks = [];", 1);
|
|
@@ -1548,7 +1527,7 @@ var native3 = {
|
|
|
1548
1527
|
if (postData.paramsObj) {
|
|
1549
1528
|
unshift("const qs = require('querystring');");
|
|
1550
1529
|
push(
|
|
1551
|
-
`req.write(qs.stringify(${
|
|
1530
|
+
`req.write(qs.stringify(${stringifyObject7__default.default(postData.paramsObj, {
|
|
1552
1531
|
indent: " ",
|
|
1553
1532
|
inlineCharacterLimit: 80
|
|
1554
1533
|
})}));`
|
|
@@ -1558,7 +1537,7 @@ var native3 = {
|
|
|
1558
1537
|
case "application/json":
|
|
1559
1538
|
if (postData.jsonObj) {
|
|
1560
1539
|
push(
|
|
1561
|
-
`req.write(JSON.stringify(${
|
|
1540
|
+
`req.write(JSON.stringify(${stringifyObject7__default.default(postData.jsonObj, {
|
|
1562
1541
|
indent: " ",
|
|
1563
1542
|
inlineCharacterLimit: 80
|
|
1564
1543
|
})}));`
|
|
@@ -1567,208 +1546,24 @@ var native3 = {
|
|
|
1567
1546
|
break;
|
|
1568
1547
|
default:
|
|
1569
1548
|
if (postData.text) {
|
|
1570
|
-
push(`req.write(${
|
|
1549
|
+
push(`req.write(${stringifyObject7__default.default(postData.text, { indent })});`);
|
|
1571
1550
|
}
|
|
1572
1551
|
}
|
|
1573
1552
|
push("req.end();");
|
|
1574
1553
|
return join();
|
|
1575
1554
|
}
|
|
1576
1555
|
};
|
|
1577
|
-
var request = {
|
|
1578
|
-
info: {
|
|
1579
|
-
key: "request",
|
|
1580
|
-
title: "Request",
|
|
1581
|
-
link: "https://github.com/request/request",
|
|
1582
|
-
description: "Simplified HTTP request client",
|
|
1583
|
-
extname: ".cjs",
|
|
1584
|
-
installation: "npm install request --save"
|
|
1585
|
-
},
|
|
1586
|
-
convert: ({ method, url, fullUrl, postData, headersObj, cookies }, options) => {
|
|
1587
|
-
const opts = {
|
|
1588
|
-
indent: " ",
|
|
1589
|
-
...options
|
|
1590
|
-
};
|
|
1591
|
-
let includeFS = false;
|
|
1592
|
-
const { push, blank, join, unshift, addPostProcessor } = new CodeBuilder({ indent: opts.indent });
|
|
1593
|
-
push("const request = require('request');");
|
|
1594
|
-
blank();
|
|
1595
|
-
const reqOpts = {
|
|
1596
|
-
method,
|
|
1597
|
-
url: fullUrl
|
|
1598
|
-
};
|
|
1599
|
-
if (Object.keys(headersObj).length) {
|
|
1600
|
-
reqOpts.headers = headersObj;
|
|
1601
|
-
}
|
|
1602
|
-
switch (postData.mimeType) {
|
|
1603
|
-
case "application/x-www-form-urlencoded":
|
|
1604
|
-
reqOpts.form = postData.paramsObj;
|
|
1605
|
-
break;
|
|
1606
|
-
case "application/json":
|
|
1607
|
-
if (postData.jsonObj) {
|
|
1608
|
-
reqOpts.body = postData.jsonObj;
|
|
1609
|
-
reqOpts.json = true;
|
|
1610
|
-
}
|
|
1611
|
-
break;
|
|
1612
|
-
case "multipart/form-data":
|
|
1613
|
-
if (!postData.params) {
|
|
1614
|
-
break;
|
|
1615
|
-
}
|
|
1616
|
-
reqOpts.formData = {};
|
|
1617
|
-
postData.params.forEach((param) => {
|
|
1618
|
-
if (!param.fileName && !param.fileName && !param.contentType) {
|
|
1619
|
-
reqOpts.formData[param.name] = param.value;
|
|
1620
|
-
return;
|
|
1621
|
-
}
|
|
1622
|
-
let attachment = {};
|
|
1623
|
-
if (param.fileName) {
|
|
1624
|
-
includeFS = true;
|
|
1625
|
-
attachment = {
|
|
1626
|
-
value: `fs.createReadStream(${param.fileName})`,
|
|
1627
|
-
options: {
|
|
1628
|
-
filename: param.fileName,
|
|
1629
|
-
contentType: param.contentType ? param.contentType : null
|
|
1630
|
-
}
|
|
1631
|
-
};
|
|
1632
|
-
} else if (param.value) {
|
|
1633
|
-
attachment.value = param.value;
|
|
1634
|
-
}
|
|
1635
|
-
reqOpts.formData[param.name] = attachment;
|
|
1636
|
-
});
|
|
1637
|
-
addPostProcessor((code) => code.replace(/'fs\.createReadStream\((.*)\)'/, "fs.createReadStream('$1')"));
|
|
1638
|
-
break;
|
|
1639
|
-
default:
|
|
1640
|
-
if (postData.text) {
|
|
1641
|
-
reqOpts.body = postData.text;
|
|
1642
|
-
}
|
|
1643
|
-
}
|
|
1644
|
-
if (cookies.length) {
|
|
1645
|
-
reqOpts.jar = "JAR";
|
|
1646
|
-
push("const jar = request.jar();");
|
|
1647
|
-
cookies.forEach(({ name, value }) => {
|
|
1648
|
-
push(`jar.setCookie(request.cookie('${encodeURIComponent(name)}=${encodeURIComponent(value)}'), '${url}');`);
|
|
1649
|
-
});
|
|
1650
|
-
blank();
|
|
1651
|
-
addPostProcessor((code) => code.replace(/'JAR'/, "jar"));
|
|
1652
|
-
}
|
|
1653
|
-
if (includeFS) {
|
|
1654
|
-
unshift("const fs = require('fs');");
|
|
1655
|
-
}
|
|
1656
|
-
push(`const options = ${stringifyObject9__default.default(reqOpts, { indent: " ", inlineCharacterLimit: 80 })};`);
|
|
1657
|
-
blank();
|
|
1658
|
-
push("request(options, function (error, response, body) {");
|
|
1659
|
-
push("if (error) throw new Error(error);", 1);
|
|
1660
|
-
blank();
|
|
1661
|
-
push("console.log(body);", 1);
|
|
1662
|
-
push("});");
|
|
1663
|
-
return join();
|
|
1664
|
-
}
|
|
1665
|
-
};
|
|
1666
|
-
var unirest2 = {
|
|
1667
|
-
info: {
|
|
1668
|
-
key: "unirest",
|
|
1669
|
-
title: "Unirest",
|
|
1670
|
-
link: "http://unirest.io/nodejs.html",
|
|
1671
|
-
description: "Lightweight HTTP Request Client Library",
|
|
1672
|
-
extname: ".cjs"
|
|
1673
|
-
},
|
|
1674
|
-
convert: ({ method, url, cookies, queryObj, postData, headersObj }, options) => {
|
|
1675
|
-
const opts = {
|
|
1676
|
-
indent: " ",
|
|
1677
|
-
...options
|
|
1678
|
-
};
|
|
1679
|
-
let includeFS = false;
|
|
1680
|
-
const { addPostProcessor, blank, join, push, unshift } = new CodeBuilder({
|
|
1681
|
-
indent: opts.indent
|
|
1682
|
-
});
|
|
1683
|
-
push("const unirest = require('unirest');");
|
|
1684
|
-
blank();
|
|
1685
|
-
push(`const req = unirest('${method}', '${url}');`);
|
|
1686
|
-
blank();
|
|
1687
|
-
if (cookies.length) {
|
|
1688
|
-
push("const CookieJar = unirest.jar();");
|
|
1689
|
-
cookies.forEach((cookie) => {
|
|
1690
|
-
push(`CookieJar.add('${encodeURIComponent(cookie.name)}=${encodeURIComponent(cookie.value)}', '${url}');`);
|
|
1691
|
-
});
|
|
1692
|
-
push("req.jar(CookieJar);");
|
|
1693
|
-
blank();
|
|
1694
|
-
}
|
|
1695
|
-
if (Object.keys(queryObj).length) {
|
|
1696
|
-
push(`req.query(${stringifyObject9__default.default(queryObj, { indent: opts.indent })});`);
|
|
1697
|
-
blank();
|
|
1698
|
-
}
|
|
1699
|
-
if (Object.keys(headersObj).length) {
|
|
1700
|
-
push(`req.headers(${stringifyObject9__default.default(headersObj, { indent: opts.indent })});`);
|
|
1701
|
-
blank();
|
|
1702
|
-
}
|
|
1703
|
-
switch (postData.mimeType) {
|
|
1704
|
-
case "application/x-www-form-urlencoded":
|
|
1705
|
-
if (postData.paramsObj) {
|
|
1706
|
-
push(`req.form(${stringifyObject9__default.default(postData.paramsObj, { indent: opts.indent })});`);
|
|
1707
|
-
blank();
|
|
1708
|
-
}
|
|
1709
|
-
break;
|
|
1710
|
-
case "application/json":
|
|
1711
|
-
if (postData.jsonObj) {
|
|
1712
|
-
push("req.type('json');");
|
|
1713
|
-
push(`req.send(${stringifyObject9__default.default(postData.jsonObj, { indent: opts.indent })});`);
|
|
1714
|
-
blank();
|
|
1715
|
-
}
|
|
1716
|
-
break;
|
|
1717
|
-
case "multipart/form-data": {
|
|
1718
|
-
if (!postData.params) {
|
|
1719
|
-
break;
|
|
1720
|
-
}
|
|
1721
|
-
const multipart = [];
|
|
1722
|
-
postData.params.forEach((param) => {
|
|
1723
|
-
const part = {};
|
|
1724
|
-
if (param.fileName && !param.value) {
|
|
1725
|
-
includeFS = true;
|
|
1726
|
-
part.body = `fs.createReadStream('${param.fileName}')`;
|
|
1727
|
-
addPostProcessor((code) => code.replace(/'fs\.createReadStream\(\\'(.+)\\'\)'/, "fs.createReadStream('$1')"));
|
|
1728
|
-
} else if (param.value) {
|
|
1729
|
-
part.body = param.value;
|
|
1730
|
-
}
|
|
1731
|
-
if (part.body) {
|
|
1732
|
-
if (param.contentType) {
|
|
1733
|
-
part["content-type"] = param.contentType;
|
|
1734
|
-
}
|
|
1735
|
-
multipart.push(part);
|
|
1736
|
-
}
|
|
1737
|
-
});
|
|
1738
|
-
push(`req.multipart(${stringifyObject9__default.default(multipart, { indent: opts.indent })});`);
|
|
1739
|
-
blank();
|
|
1740
|
-
break;
|
|
1741
|
-
}
|
|
1742
|
-
default:
|
|
1743
|
-
if (postData.text) {
|
|
1744
|
-
push(`req.send(${stringifyObject9__default.default(postData.text, { indent: opts.indent })});`);
|
|
1745
|
-
blank();
|
|
1746
|
-
}
|
|
1747
|
-
}
|
|
1748
|
-
if (includeFS) {
|
|
1749
|
-
unshift("const fs = require('fs');");
|
|
1750
|
-
}
|
|
1751
|
-
push("req.end(function (res) {");
|
|
1752
|
-
push("if (res.error) throw new Error(res.error);", 1);
|
|
1753
|
-
blank();
|
|
1754
|
-
push("console.log(res.body);", 1);
|
|
1755
|
-
push("});");
|
|
1756
|
-
return join();
|
|
1757
|
-
}
|
|
1758
|
-
};
|
|
1759
1556
|
|
|
1760
1557
|
// src/targets/node/target.ts
|
|
1761
1558
|
var node = {
|
|
1762
1559
|
info: {
|
|
1763
1560
|
key: "node",
|
|
1764
1561
|
title: "Node.js",
|
|
1765
|
-
default: "
|
|
1562
|
+
default: "fetch",
|
|
1766
1563
|
cli: "node %s"
|
|
1767
1564
|
},
|
|
1768
1565
|
clientsById: {
|
|
1769
1566
|
native: native3,
|
|
1770
|
-
request,
|
|
1771
|
-
unirest: unirest2,
|
|
1772
1567
|
axios: axios2,
|
|
1773
1568
|
fetch: fetch2
|
|
1774
1569
|
}
|
|
@@ -2719,22 +2514,22 @@ var requests = {
|
|
|
2719
2514
|
push("}");
|
|
2720
2515
|
blank();
|
|
2721
2516
|
}
|
|
2722
|
-
let
|
|
2517
|
+
let request = builtInMethods.includes(method) ? `response = requests.${method.toLowerCase()}(url` : `response = requests.request("${method}", url`;
|
|
2723
2518
|
if (hasPayload) {
|
|
2724
2519
|
if (jsonPayload) {
|
|
2725
|
-
|
|
2520
|
+
request += ", json=payload";
|
|
2726
2521
|
} else {
|
|
2727
|
-
|
|
2522
|
+
request += ", data=payload";
|
|
2728
2523
|
}
|
|
2729
2524
|
}
|
|
2730
2525
|
if (hasFiles) {
|
|
2731
|
-
|
|
2526
|
+
request += ", files=files";
|
|
2732
2527
|
}
|
|
2733
2528
|
if (headerCount > 0) {
|
|
2734
|
-
|
|
2529
|
+
request += ", headers=headers";
|
|
2735
2530
|
}
|
|
2736
|
-
|
|
2737
|
-
push(
|
|
2531
|
+
request += ")";
|
|
2532
|
+
push(request);
|
|
2738
2533
|
blank();
|
|
2739
2534
|
push("print(response.text)");
|
|
2740
2535
|
return join();
|
|
@@ -2819,22 +2614,22 @@ var httr = {
|
|
|
2819
2614
|
const setContentType = `content_type("${escapeForDoubleQuotes(postData.mimeType)}")`;
|
|
2820
2615
|
const otherHeaders = Object.entries(allHeaders).filter(([key]) => !["cookie", "accept", "content-type"].includes(key.toLowerCase())).map(([key, value]) => `'${key}' = '${escapeForSingleQuotes(value)}'`).join(", ");
|
|
2821
2616
|
const setHeaders = otherHeaders ? `add_headers(${otherHeaders})` : void 0;
|
|
2822
|
-
let
|
|
2617
|
+
let request = `response <- VERB("${method}", url`;
|
|
2823
2618
|
if (payload) {
|
|
2824
|
-
|
|
2619
|
+
request += ", body = payload";
|
|
2825
2620
|
}
|
|
2826
2621
|
if (queryString.length) {
|
|
2827
|
-
|
|
2622
|
+
request += ", query = queryString";
|
|
2828
2623
|
}
|
|
2829
2624
|
const headerAdditions = [setHeaders, setContentType, setAccept, setCookies].filter((x) => !!x).join(", ");
|
|
2830
2625
|
if (headerAdditions) {
|
|
2831
|
-
|
|
2626
|
+
request += `, ${headerAdditions}`;
|
|
2832
2627
|
}
|
|
2833
2628
|
if (postData.text || postData.jsonObj || postData.params) {
|
|
2834
|
-
|
|
2629
|
+
request += ", encode = encode";
|
|
2835
2630
|
}
|
|
2836
|
-
|
|
2837
|
-
push(
|
|
2631
|
+
request += ")";
|
|
2632
|
+
push(request);
|
|
2838
2633
|
blank();
|
|
2839
2634
|
push('content(response, "text")');
|
|
2840
2635
|
return join();
|
|
@@ -3318,7 +3113,7 @@ var urlsession = {
|
|
|
3318
3113
|
break;
|
|
3319
3114
|
case "application/json":
|
|
3320
3115
|
if (postData.jsonObj) {
|
|
3321
|
-
push(`${literalDeclaration("parameters", postData.jsonObj, opts)} as [String : Any]`);
|
|
3116
|
+
push(`${literalDeclaration("parameters", postData.jsonObj, opts)} as [String : Any?]`);
|
|
3322
3117
|
blank();
|
|
3323
3118
|
push("let postData = try JSONSerialization.data(withJSONObject: parameters, options: [])");
|
|
3324
3119
|
blank();
|
|
@@ -3335,7 +3130,7 @@ var urlsession = {
|
|
|
3335
3130
|
push('body += "--\\(boundary)\\r\\n"', 1);
|
|
3336
3131
|
push('body += "Content-Disposition:form-data; name=\\"\\(paramName)\\""', 1);
|
|
3337
3132
|
push('if let filename = param["fileName"] {', 1);
|
|
3338
|
-
push('let contentType = param["
|
|
3133
|
+
push('let contentType = param["contentType"]!', 2);
|
|
3339
3134
|
push("let fileContent = try String(contentsOfFile: filename, encoding: .utf8)", 2);
|
|
3340
3135
|
push('body += "; filename=\\"\\(filename)\\"\\r\\n"', 2);
|
|
3341
3136
|
push('body += "Content-Type: \\(contentType)\\r\\n\\r\\n"', 2);
|
|
@@ -3388,7 +3183,7 @@ var urlsession = {
|
|
|
3388
3183
|
push("request.httpBody = postData");
|
|
3389
3184
|
}
|
|
3390
3185
|
blank();
|
|
3391
|
-
push("let (data,
|
|
3186
|
+
push("let (data, _) = try await URLSession.shared.data(for: request)");
|
|
3392
3187
|
push("print(String(decoding: data, as: UTF8.self))");
|
|
3393
3188
|
return join();
|
|
3394
3189
|
}
|
|
@@ -3525,5 +3320,5 @@ exports.addTargetClient = addTargetClient;
|
|
|
3525
3320
|
exports.isClient = isClient;
|
|
3526
3321
|
exports.isTarget = isTarget;
|
|
3527
3322
|
exports.targets = targets;
|
|
3528
|
-
//# sourceMappingURL=
|
|
3323
|
+
//# sourceMappingURL=index.cjs.map
|
|
3529
3324
|
//# sourceMappingURL=index.cjs.map
|