@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/dist/index.cjs CHANGED
@@ -2,11 +2,11 @@
2
2
 
3
3
  var url = require('url');
4
4
  var qs = require('qs');
5
- var stringifyObject9 = require('stringify-object');
5
+ var stringifyObject7 = require('stringify-object');
6
6
 
7
7
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
8
8
 
9
- var stringifyObject9__default = /*#__PURE__*/_interopDefault(stringifyObject9);
9
+ var stringifyObject7__default = /*#__PURE__*/_interopDefault(stringifyObject7);
10
10
 
11
11
  // src/index.ts
12
12
 
@@ -548,8 +548,7 @@ var restsharp = {
548
548
  });
549
549
  switch (postData.mimeType) {
550
550
  case "multipart/form-data":
551
- if (!postData.params)
552
- break;
551
+ if (!postData.params) break;
553
552
  postData.params.forEach((param) => {
554
553
  if (param.fileName) {
555
554
  push(`request.AddFile("${param.name}", "${param.fileName}");`);
@@ -559,22 +558,19 @@ var restsharp = {
559
558
  });
560
559
  break;
561
560
  case "application/x-www-form-urlencoded":
562
- if (!postData.params)
563
- break;
561
+ if (!postData.params) break;
564
562
  postData.params.forEach((param) => {
565
563
  push(`request.AddParameter("${param.name}", "${param.value}");`);
566
564
  });
567
565
  break;
568
566
  case "application/json": {
569
- if (!postData.text)
570
- break;
567
+ if (!postData.text) break;
571
568
  const text = JSON.stringify(postData.text);
572
569
  push(`request.AddJsonBody(${text}, false);`);
573
570
  break;
574
571
  }
575
572
  default:
576
- if (!postData.text)
577
- break;
573
+ if (!postData.text) break;
578
574
  push(`request.AddStringBody("${postData.text}", "${postData.mimeType}");`);
579
575
  }
580
576
  push(`var response = await client.${title(method)}Async(request);
@@ -982,7 +978,7 @@ var axios = {
982
978
  requestOptions.data = postData.text;
983
979
  }
984
980
  }
985
- const optionString = stringifyObject9__default.default(requestOptions, {
981
+ const optionString = stringifyObject7__default.default(requestOptions, {
986
982
  indent: " ",
987
983
  inlineCharacterLimit: 80
988
984
  }).replace('"[form]"', "form");
@@ -990,12 +986,8 @@ var axios = {
990
986
  blank();
991
987
  push("axios");
992
988
  push(".request(options)", 1);
993
- push(".then(function (response) {", 1);
994
- push("console.log(response.data);", 2);
995
- push("})", 1);
996
- push(".catch(function (error) {", 1);
997
- push("console.error(error);", 2);
998
- push("});", 1);
989
+ push(".then(res => console.log(res.data))", 1);
990
+ push(".catch(err => console.error(err));", 1);
999
991
  return join();
1000
992
  }
1001
993
  };
@@ -1055,7 +1047,7 @@ var fetch = {
1055
1047
  delete options.headers;
1056
1048
  }
1057
1049
  push(
1058
- `const options = ${stringifyObject9__default.default(options, {
1050
+ `const options = ${stringifyObject7__default.default(options, {
1059
1051
  indent: opts.indent,
1060
1052
  inlineCharacterLimit: 80,
1061
1053
  // The Fetch API body only accepts string parameters, but stringified JSON can be difficult
@@ -1079,8 +1071,8 @@ var fetch = {
1079
1071
  blank();
1080
1072
  }
1081
1073
  push(`fetch('${fullUrl}', options)`);
1082
- push(".then(response => response.json())", 1);
1083
- push(".then(response => console.log(response))", 1);
1074
+ push(".then(res => res.json())", 1);
1075
+ push(".then(res => console.log(res))", 1);
1084
1076
  push(".catch(err => console.error(err));", 1);
1085
1077
  return join();
1086
1078
  }
@@ -1141,11 +1133,11 @@ var jquery = {
1141
1133
  settings.data = postData.text;
1142
1134
  }
1143
1135
  }
1144
- const stringifiedSettings = stringifyObject9__default.default(settings, { indent: opts.indent }).replace("'[form]'", "form");
1136
+ const stringifiedSettings = stringifyObject7__default.default(settings, { indent: opts.indent }).replace("'[form]'", "form");
1145
1137
  push(`const settings = ${stringifiedSettings};`);
1146
1138
  blank();
1147
- push("$.ajax(settings).done(function (response) {");
1148
- push("console.log(response);", 1);
1139
+ push("$.ajax(settings).done(res => {");
1140
+ push("console.log(res);", 1);
1149
1141
  push("});");
1150
1142
  return join();
1151
1143
  }
@@ -1168,7 +1160,7 @@ var xhr = {
1168
1160
  switch (postData.mimeType) {
1169
1161
  case "application/json":
1170
1162
  push(
1171
- `const data = JSON.stringify(${stringifyObject9__default.default(postData.jsonObj, {
1163
+ `const data = JSON.stringify(${stringifyObject7__default.default(postData.jsonObj, {
1172
1164
  indent: opts.indent
1173
1165
  })});`
1174
1166
  );
@@ -1222,7 +1214,7 @@ var javascript = {
1222
1214
  info: {
1223
1215
  key: "javascript",
1224
1216
  title: "JavaScript",
1225
- default: "xhr"
1217
+ default: "fetch"
1226
1218
  },
1227
1219
  clientsById: {
1228
1220
  xhr,
@@ -1361,7 +1353,7 @@ var axios2 = {
1361
1353
  title: "Axios",
1362
1354
  link: "https://github.com/axios/axios",
1363
1355
  description: "Promise based HTTP client for the browser and node.js",
1364
- extname: ".cjs",
1356
+ extname: ".js",
1365
1357
  installation: "npm install axios --save"
1366
1358
  },
1367
1359
  convert: ({ method, fullUrl, allHeaders, postData }, options) => {
@@ -1370,7 +1362,8 @@ var axios2 = {
1370
1362
  ...options
1371
1363
  };
1372
1364
  const { blank, join, push, addPostProcessor } = new CodeBuilder({ indent: opts.indent });
1373
- push("const axios = require('axios');");
1365
+ push("import axios from 'axios';");
1366
+ blank();
1374
1367
  const reqOpts = {
1375
1368
  method,
1376
1369
  url: fullUrl
@@ -1381,8 +1374,6 @@ var axios2 = {
1381
1374
  switch (postData.mimeType) {
1382
1375
  case "application/x-www-form-urlencoded":
1383
1376
  if (postData.params) {
1384
- push("const { URLSearchParams } = require('url');");
1385
- blank();
1386
1377
  push("const encodedParams = new URLSearchParams();");
1387
1378
  postData.params.forEach((param) => {
1388
1379
  push(`encodedParams.set('${param.name}', '${param.value}');`);
@@ -1393,39 +1384,32 @@ var axios2 = {
1393
1384
  }
1394
1385
  break;
1395
1386
  case "application/json":
1396
- blank();
1397
1387
  if (postData.jsonObj) {
1398
1388
  reqOpts.data = postData.jsonObj;
1399
1389
  }
1400
1390
  break;
1401
1391
  default:
1402
- blank();
1403
1392
  if (postData.text) {
1404
1393
  reqOpts.data = postData.text;
1405
1394
  }
1406
1395
  }
1407
- const stringifiedOptions = stringifyObject9__default.default(reqOpts, { indent: " ", inlineCharacterLimit: 80 });
1396
+ const stringifiedOptions = stringifyObject7__default.default(reqOpts, { indent: " ", inlineCharacterLimit: 80 });
1408
1397
  push(`const options = ${stringifiedOptions};`);
1409
1398
  blank();
1410
1399
  push("axios");
1411
1400
  push(".request(options)", 1);
1412
- push(".then(function (response) {", 1);
1413
- push("console.log(response.data);", 2);
1414
- push("})", 1);
1415
- push(".catch(function (error) {", 1);
1416
- push("console.error(error);", 2);
1417
- push("});", 1);
1401
+ push(".then(res => console.log(res.data))", 1);
1402
+ push(".catch(err => console.error(err));", 1);
1418
1403
  return join();
1419
1404
  }
1420
1405
  };
1421
1406
  var fetch2 = {
1422
1407
  info: {
1423
1408
  key: "fetch",
1424
- title: "Fetch",
1425
- link: "https://github.com/bitinn/node-fetch",
1426
- description: "Simplified HTTP node-fetch client",
1427
- extname: ".cjs",
1428
- installation: "npm install node-fetch@2 --save"
1409
+ title: "fetch",
1410
+ link: "https://nodejs.org/docs/latest/api/globals.html#fetch",
1411
+ description: "Perform asynchronous HTTP requests with the Fetch API",
1412
+ extname: ".js"
1429
1413
  },
1430
1414
  convert: ({ method, fullUrl, postData, headersObj, cookies }, options) => {
1431
1415
  const opts = {
@@ -1434,7 +1418,6 @@ var fetch2 = {
1434
1418
  };
1435
1419
  let includeFS = false;
1436
1420
  const { blank, push, join, unshift } = new CodeBuilder({ indent: opts.indent });
1437
- push("const fetch = require('node-fetch');");
1438
1421
  const url = fullUrl;
1439
1422
  const reqOpts = {
1440
1423
  method
@@ -1444,13 +1427,12 @@ var fetch2 = {
1444
1427
  }
1445
1428
  switch (postData.mimeType) {
1446
1429
  case "application/x-www-form-urlencoded":
1447
- unshift("const { URLSearchParams } = require('url');");
1448
1430
  push("const encodedParams = new URLSearchParams();");
1449
- blank();
1450
1431
  postData.params?.forEach((param) => {
1451
1432
  push(`encodedParams.set('${param.name}', '${param.value}');`);
1452
1433
  });
1453
1434
  reqOpts.body = "encodedParams";
1435
+ blank();
1454
1436
  break;
1455
1437
  case "application/json":
1456
1438
  if (postData.jsonObj) {
@@ -1465,9 +1447,7 @@ var fetch2 = {
1465
1447
  if (contentTypeHeader) {
1466
1448
  delete headersObj[contentTypeHeader];
1467
1449
  }
1468
- unshift("const FormData = require('form-data');");
1469
1450
  push("const formData = new FormData();");
1470
- blank();
1471
1451
  postData.params.forEach((param) => {
1472
1452
  if (!param.fileName && !param.fileName && !param.contentType) {
1473
1453
  push(`formData.append('${param.name}', '${param.value}');`);
@@ -1475,9 +1455,13 @@ var fetch2 = {
1475
1455
  }
1476
1456
  if (param.fileName) {
1477
1457
  includeFS = true;
1478
- push(`formData.append('${param.name}', fs.createReadStream('${param.fileName}'));`);
1458
+ push(
1459
+ `formData.append('${param.name}', await new Response(fs.createReadStream('${param.fileName}')).blob());`
1460
+ );
1479
1461
  }
1480
1462
  });
1463
+ reqOpts.body = "formData";
1464
+ blank();
1481
1465
  break;
1482
1466
  default:
1483
1467
  if (postData.text) {
@@ -1493,12 +1477,11 @@ var fetch2 = {
1493
1477
  reqOpts.headers.cookie = cookiesString;
1494
1478
  }
1495
1479
  }
1496
- blank();
1497
1480
  push(`const url = '${url}';`);
1498
1481
  if (reqOpts.headers && !Object.keys(reqOpts.headers).length) {
1499
1482
  delete reqOpts.headers;
1500
1483
  }
1501
- const stringifiedOptions = stringifyObject9__default.default(reqOpts, {
1484
+ const stringifiedOptions = stringifyObject7__default.default(reqOpts, {
1502
1485
  indent: " ",
1503
1486
  inlineCharacterLimit: 80,
1504
1487
  // The Fetch API body only accepts string parameters, but stringified JSON can be difficult to
@@ -1514,17 +1497,13 @@ var fetch2 = {
1514
1497
  push(`const options = ${stringifiedOptions};`);
1515
1498
  blank();
1516
1499
  if (includeFS) {
1517
- unshift("const fs = require('fs');");
1518
- }
1519
- if (postData.params && postData.mimeType === "multipart/form-data") {
1520
- push("options.body = formData;");
1521
- blank();
1500
+ unshift("import fs from 'fs';\n");
1522
1501
  }
1523
1502
  push("fetch(url, options)");
1524
1503
  push(".then(res => res.json())", 1);
1525
1504
  push(".then(json => console.log(json))", 1);
1526
- push(".catch(err => console.error('error:' + err));", 1);
1527
- return join().replace(/'encodedParams'/, "encodedParams").replace(/"fs\.createReadStream\(\\"(.+)\\"\)"/, 'fs.createReadStream("$1")');
1505
+ push(".catch(err => console.error(err));", 1);
1506
+ return join().replace(/'encodedParams'/, "encodedParams").replace(/'formData'/, "formData");
1528
1507
  }
1529
1508
  };
1530
1509
  var native3 = {
@@ -1547,7 +1526,7 @@ var native3 = {
1547
1526
  };
1548
1527
  push(`const http = require('${uriObj.protocol?.replace(":", "")}');`);
1549
1528
  blank();
1550
- push(`const options = ${stringifyObject9__default.default(reqOpts, { indent })};`);
1529
+ push(`const options = ${stringifyObject7__default.default(reqOpts, { indent })};`);
1551
1530
  blank();
1552
1531
  push("const req = http.request(options, function (res) {");
1553
1532
  push("const chunks = [];", 1);
@@ -1567,7 +1546,7 @@ var native3 = {
1567
1546
  if (postData.paramsObj) {
1568
1547
  unshift("const qs = require('querystring');");
1569
1548
  push(
1570
- `req.write(qs.stringify(${stringifyObject9__default.default(postData.paramsObj, {
1549
+ `req.write(qs.stringify(${stringifyObject7__default.default(postData.paramsObj, {
1571
1550
  indent: " ",
1572
1551
  inlineCharacterLimit: 80
1573
1552
  })}));`
@@ -1577,7 +1556,7 @@ var native3 = {
1577
1556
  case "application/json":
1578
1557
  if (postData.jsonObj) {
1579
1558
  push(
1580
- `req.write(JSON.stringify(${stringifyObject9__default.default(postData.jsonObj, {
1559
+ `req.write(JSON.stringify(${stringifyObject7__default.default(postData.jsonObj, {
1581
1560
  indent: " ",
1582
1561
  inlineCharacterLimit: 80
1583
1562
  })}));`
@@ -1586,208 +1565,24 @@ var native3 = {
1586
1565
  break;
1587
1566
  default:
1588
1567
  if (postData.text) {
1589
- push(`req.write(${stringifyObject9__default.default(postData.text, { indent })});`);
1568
+ push(`req.write(${stringifyObject7__default.default(postData.text, { indent })});`);
1590
1569
  }
1591
1570
  }
1592
1571
  push("req.end();");
1593
1572
  return join();
1594
1573
  }
1595
1574
  };
1596
- var request = {
1597
- info: {
1598
- key: "request",
1599
- title: "Request",
1600
- link: "https://github.com/request/request",
1601
- description: "Simplified HTTP request client",
1602
- extname: ".cjs",
1603
- installation: "npm install request --save"
1604
- },
1605
- convert: ({ method, url, fullUrl, postData, headersObj, cookies }, options) => {
1606
- const opts = {
1607
- indent: " ",
1608
- ...options
1609
- };
1610
- let includeFS = false;
1611
- const { push, blank, join, unshift, addPostProcessor } = new CodeBuilder({ indent: opts.indent });
1612
- push("const request = require('request');");
1613
- blank();
1614
- const reqOpts = {
1615
- method,
1616
- url: fullUrl
1617
- };
1618
- if (Object.keys(headersObj).length) {
1619
- reqOpts.headers = headersObj;
1620
- }
1621
- switch (postData.mimeType) {
1622
- case "application/x-www-form-urlencoded":
1623
- reqOpts.form = postData.paramsObj;
1624
- break;
1625
- case "application/json":
1626
- if (postData.jsonObj) {
1627
- reqOpts.body = postData.jsonObj;
1628
- reqOpts.json = true;
1629
- }
1630
- break;
1631
- case "multipart/form-data":
1632
- if (!postData.params) {
1633
- break;
1634
- }
1635
- reqOpts.formData = {};
1636
- postData.params.forEach((param) => {
1637
- if (!param.fileName && !param.fileName && !param.contentType) {
1638
- reqOpts.formData[param.name] = param.value;
1639
- return;
1640
- }
1641
- let attachment = {};
1642
- if (param.fileName) {
1643
- includeFS = true;
1644
- attachment = {
1645
- value: `fs.createReadStream(${param.fileName})`,
1646
- options: {
1647
- filename: param.fileName,
1648
- contentType: param.contentType ? param.contentType : null
1649
- }
1650
- };
1651
- } else if (param.value) {
1652
- attachment.value = param.value;
1653
- }
1654
- reqOpts.formData[param.name] = attachment;
1655
- });
1656
- addPostProcessor((code) => code.replace(/'fs\.createReadStream\((.*)\)'/, "fs.createReadStream('$1')"));
1657
- break;
1658
- default:
1659
- if (postData.text) {
1660
- reqOpts.body = postData.text;
1661
- }
1662
- }
1663
- if (cookies.length) {
1664
- reqOpts.jar = "JAR";
1665
- push("const jar = request.jar();");
1666
- cookies.forEach(({ name, value }) => {
1667
- push(`jar.setCookie(request.cookie('${encodeURIComponent(name)}=${encodeURIComponent(value)}'), '${url}');`);
1668
- });
1669
- blank();
1670
- addPostProcessor((code) => code.replace(/'JAR'/, "jar"));
1671
- }
1672
- if (includeFS) {
1673
- unshift("const fs = require('fs');");
1674
- }
1675
- push(`const options = ${stringifyObject9__default.default(reqOpts, { indent: " ", inlineCharacterLimit: 80 })};`);
1676
- blank();
1677
- push("request(options, function (error, response, body) {");
1678
- push("if (error) throw new Error(error);", 1);
1679
- blank();
1680
- push("console.log(body);", 1);
1681
- push("});");
1682
- return join();
1683
- }
1684
- };
1685
- var unirest2 = {
1686
- info: {
1687
- key: "unirest",
1688
- title: "Unirest",
1689
- link: "http://unirest.io/nodejs.html",
1690
- description: "Lightweight HTTP Request Client Library",
1691
- extname: ".cjs"
1692
- },
1693
- convert: ({ method, url, cookies, queryObj, postData, headersObj }, options) => {
1694
- const opts = {
1695
- indent: " ",
1696
- ...options
1697
- };
1698
- let includeFS = false;
1699
- const { addPostProcessor, blank, join, push, unshift } = new CodeBuilder({
1700
- indent: opts.indent
1701
- });
1702
- push("const unirest = require('unirest');");
1703
- blank();
1704
- push(`const req = unirest('${method}', '${url}');`);
1705
- blank();
1706
- if (cookies.length) {
1707
- push("const CookieJar = unirest.jar();");
1708
- cookies.forEach((cookie) => {
1709
- push(`CookieJar.add('${encodeURIComponent(cookie.name)}=${encodeURIComponent(cookie.value)}', '${url}');`);
1710
- });
1711
- push("req.jar(CookieJar);");
1712
- blank();
1713
- }
1714
- if (Object.keys(queryObj).length) {
1715
- push(`req.query(${stringifyObject9__default.default(queryObj, { indent: opts.indent })});`);
1716
- blank();
1717
- }
1718
- if (Object.keys(headersObj).length) {
1719
- push(`req.headers(${stringifyObject9__default.default(headersObj, { indent: opts.indent })});`);
1720
- blank();
1721
- }
1722
- switch (postData.mimeType) {
1723
- case "application/x-www-form-urlencoded":
1724
- if (postData.paramsObj) {
1725
- push(`req.form(${stringifyObject9__default.default(postData.paramsObj, { indent: opts.indent })});`);
1726
- blank();
1727
- }
1728
- break;
1729
- case "application/json":
1730
- if (postData.jsonObj) {
1731
- push("req.type('json');");
1732
- push(`req.send(${stringifyObject9__default.default(postData.jsonObj, { indent: opts.indent })});`);
1733
- blank();
1734
- }
1735
- break;
1736
- case "multipart/form-data": {
1737
- if (!postData.params) {
1738
- break;
1739
- }
1740
- const multipart = [];
1741
- postData.params.forEach((param) => {
1742
- const part = {};
1743
- if (param.fileName && !param.value) {
1744
- includeFS = true;
1745
- part.body = `fs.createReadStream('${param.fileName}')`;
1746
- addPostProcessor((code) => code.replace(/'fs\.createReadStream\(\\'(.+)\\'\)'/, "fs.createReadStream('$1')"));
1747
- } else if (param.value) {
1748
- part.body = param.value;
1749
- }
1750
- if (part.body) {
1751
- if (param.contentType) {
1752
- part["content-type"] = param.contentType;
1753
- }
1754
- multipart.push(part);
1755
- }
1756
- });
1757
- push(`req.multipart(${stringifyObject9__default.default(multipart, { indent: opts.indent })});`);
1758
- blank();
1759
- break;
1760
- }
1761
- default:
1762
- if (postData.text) {
1763
- push(`req.send(${stringifyObject9__default.default(postData.text, { indent: opts.indent })});`);
1764
- blank();
1765
- }
1766
- }
1767
- if (includeFS) {
1768
- unshift("const fs = require('fs');");
1769
- }
1770
- push("req.end(function (res) {");
1771
- push("if (res.error) throw new Error(res.error);", 1);
1772
- blank();
1773
- push("console.log(res.body);", 1);
1774
- push("});");
1775
- return join();
1776
- }
1777
- };
1778
1575
 
1779
1576
  // src/targets/node/target.ts
1780
1577
  var node = {
1781
1578
  info: {
1782
1579
  key: "node",
1783
1580
  title: "Node.js",
1784
- default: "native",
1581
+ default: "fetch",
1785
1582
  cli: "node %s"
1786
1583
  },
1787
1584
  clientsById: {
1788
1585
  native: native3,
1789
- request,
1790
- unirest: unirest2,
1791
1586
  axios: axios2,
1792
1587
  fetch: fetch2
1793
1588
  }
@@ -2738,22 +2533,22 @@ var requests = {
2738
2533
  push("}");
2739
2534
  blank();
2740
2535
  }
2741
- let request2 = builtInMethods.includes(method) ? `response = requests.${method.toLowerCase()}(url` : `response = requests.request("${method}", url`;
2536
+ let request = builtInMethods.includes(method) ? `response = requests.${method.toLowerCase()}(url` : `response = requests.request("${method}", url`;
2742
2537
  if (hasPayload) {
2743
2538
  if (jsonPayload) {
2744
- request2 += ", json=payload";
2539
+ request += ", json=payload";
2745
2540
  } else {
2746
- request2 += ", data=payload";
2541
+ request += ", data=payload";
2747
2542
  }
2748
2543
  }
2749
2544
  if (hasFiles) {
2750
- request2 += ", files=files";
2545
+ request += ", files=files";
2751
2546
  }
2752
2547
  if (headerCount > 0) {
2753
- request2 += ", headers=headers";
2548
+ request += ", headers=headers";
2754
2549
  }
2755
- request2 += ")";
2756
- push(request2);
2550
+ request += ")";
2551
+ push(request);
2757
2552
  blank();
2758
2553
  push("print(response.text)");
2759
2554
  return join();
@@ -2838,22 +2633,22 @@ var httr = {
2838
2633
  const setContentType = `content_type("${escapeForDoubleQuotes(postData.mimeType)}")`;
2839
2634
  const otherHeaders = Object.entries(allHeaders).filter(([key]) => !["cookie", "accept", "content-type"].includes(key.toLowerCase())).map(([key, value]) => `'${key}' = '${escapeForSingleQuotes(value)}'`).join(", ");
2840
2635
  const setHeaders = otherHeaders ? `add_headers(${otherHeaders})` : void 0;
2841
- let request2 = `response <- VERB("${method}", url`;
2636
+ let request = `response <- VERB("${method}", url`;
2842
2637
  if (payload) {
2843
- request2 += ", body = payload";
2638
+ request += ", body = payload";
2844
2639
  }
2845
2640
  if (queryString.length) {
2846
- request2 += ", query = queryString";
2641
+ request += ", query = queryString";
2847
2642
  }
2848
2643
  const headerAdditions = [setHeaders, setContentType, setAccept, setCookies].filter((x) => !!x).join(", ");
2849
2644
  if (headerAdditions) {
2850
- request2 += `, ${headerAdditions}`;
2645
+ request += `, ${headerAdditions}`;
2851
2646
  }
2852
2647
  if (postData.text || postData.jsonObj || postData.params) {
2853
- request2 += ", encode = encode";
2648
+ request += ", encode = encode";
2854
2649
  }
2855
- request2 += ")";
2856
- push(request2);
2650
+ request += ")";
2651
+ push(request);
2857
2652
  blank();
2858
2653
  push('content(response, "text")');
2859
2654
  return join();
@@ -3337,7 +3132,7 @@ var urlsession = {
3337
3132
  break;
3338
3133
  case "application/json":
3339
3134
  if (postData.jsonObj) {
3340
- push(`${literalDeclaration("parameters", postData.jsonObj, opts)} as [String : Any]`);
3135
+ push(`${literalDeclaration("parameters", postData.jsonObj, opts)} as [String : Any?]`);
3341
3136
  blank();
3342
3137
  push("let postData = try JSONSerialization.data(withJSONObject: parameters, options: [])");
3343
3138
  blank();
@@ -3354,7 +3149,7 @@ var urlsession = {
3354
3149
  push('body += "--\\(boundary)\\r\\n"', 1);
3355
3150
  push('body += "Content-Disposition:form-data; name=\\"\\(paramName)\\""', 1);
3356
3151
  push('if let filename = param["fileName"] {', 1);
3357
- push('let contentType = param["content-type"]!', 2);
3152
+ push('let contentType = param["contentType"]!', 2);
3358
3153
  push("let fileContent = try String(contentsOfFile: filename, encoding: .utf8)", 2);
3359
3154
  push('body += "; filename=\\"\\(filename)\\"\\r\\n"', 2);
3360
3155
  push('body += "Content-Type: \\(contentType)\\r\\n\\r\\n"', 2);
@@ -3407,7 +3202,7 @@ var urlsession = {
3407
3202
  push("request.httpBody = postData");
3408
3203
  }
3409
3204
  blank();
3410
- push("let (data, response) = try await URLSession.shared.data(for: request)");
3205
+ push("let (data, _) = try await URLSession.shared.data(for: request)");
3411
3206
  push("print(String(decoding: data, as: UTF8.self))");
3412
3207
  return join();
3413
3208
  }
@@ -3578,7 +3373,7 @@ var HTTPSnippet = class {
3578
3373
  }
3579
3374
  init() {
3580
3375
  this.initCalled = true;
3581
- this.requests = this.entries.map(({ request: request2 }) => {
3376
+ this.requests = this.entries.map(({ request }) => {
3582
3377
  const req = {
3583
3378
  bodySize: 0,
3584
3379
  headersSize: 0,
@@ -3587,9 +3382,9 @@ var HTTPSnippet = class {
3587
3382
  httpVersion: "HTTP/1.1",
3588
3383
  queryString: [],
3589
3384
  postData: {
3590
- mimeType: request2.postData?.mimeType || "application/octet-stream"
3385
+ mimeType: request.postData?.mimeType || "application/octet-stream"
3591
3386
  },
3592
- ...request2
3387
+ ...request
3593
3388
  };
3594
3389
  if (req.postData && !req.postData.mimeType) {
3595
3390
  req.postData.mimeType = "application/octet-stream";
@@ -3599,7 +3394,7 @@ var HTTPSnippet = class {
3599
3394
  return this;
3600
3395
  }
3601
3396
  prepare(harRequest, options) {
3602
- const request2 = {
3397
+ const request = {
3603
3398
  ...harRequest,
3604
3399
  fullUrl: "",
3605
3400
  uriObj: {},
@@ -3608,21 +3403,21 @@ var HTTPSnippet = class {
3608
3403
  cookiesObj: {},
3609
3404
  allHeaders: {}
3610
3405
  };
3611
- if (request2.queryString && request2.queryString.length) {
3612
- request2.queryObj = request2.queryString.reduce(reducer, {});
3406
+ if (request.queryString && request.queryString.length) {
3407
+ request.queryObj = request.queryString.reduce(reducer, {});
3613
3408
  }
3614
- if (request2.headers && request2.headers.length) {
3409
+ if (request.headers && request.headers.length) {
3615
3410
  const http2VersionRegex = /^HTTP\/2/;
3616
- request2.headersObj = request2.headers.reduce((accumulator, { name, value }) => {
3617
- const headerName = http2VersionRegex.exec(request2.httpVersion) ? name.toLocaleLowerCase() : name;
3411
+ request.headersObj = request.headers.reduce((accumulator, { name, value }) => {
3412
+ const headerName = http2VersionRegex.exec(request.httpVersion) ? name.toLocaleLowerCase() : name;
3618
3413
  return {
3619
3414
  ...accumulator,
3620
3415
  [headerName]: value
3621
3416
  };
3622
3417
  }, {});
3623
3418
  }
3624
- if (request2.cookies && request2.cookies.length) {
3625
- request2.cookiesObj = request2.cookies.reduceRight(
3419
+ if (request.cookies && request.cookies.length) {
3420
+ request.cookiesObj = request.cookies.reduceRight(
3626
3421
  (accumulator, { name, value }) => ({
3627
3422
  ...accumulator,
3628
3423
  [name]: value
@@ -3630,30 +3425,30 @@ var HTTPSnippet = class {
3630
3425
  {}
3631
3426
  );
3632
3427
  }
3633
- const cookies = request2.cookies?.map(({ name, value }) => {
3428
+ const cookies = request.cookies?.map(({ name, value }) => {
3634
3429
  if (options.harIsAlreadyEncoded) {
3635
3430
  return `${name}=${value}`;
3636
3431
  }
3637
3432
  return `${encodeURIComponent(name)}=${encodeURIComponent(value)}`;
3638
3433
  });
3639
3434
  if (cookies?.length) {
3640
- request2.allHeaders.cookie = cookies.join("; ");
3435
+ request.allHeaders.cookie = cookies.join("; ");
3641
3436
  }
3642
- switch (request2.postData.mimeType) {
3437
+ switch (request.postData.mimeType) {
3643
3438
  case "multipart/mixed":
3644
3439
  case "multipart/related":
3645
3440
  case "multipart/form-data":
3646
3441
  case "multipart/alternative":
3647
- request2.postData.text = "";
3648
- request2.postData.mimeType = "multipart/form-data";
3649
- if (request2.postData?.params) {
3442
+ request.postData.text = "";
3443
+ request.postData.mimeType = "multipart/form-data";
3444
+ if (request.postData?.params) {
3650
3445
  const boundary = "---011000010111000001101001";
3651
3446
  const carriage = `${boundary}--`;
3652
3447
  const rn = "\r\n";
3653
3448
  const escape2 = (str) => str.replace(/\n/g, "%0A").replace(/\r/g, "%0D").replace(/"/g, "%22");
3654
3449
  const normalizeLinefeeds = (value) => value.replace(/\r?\n|\r/g, "\r\n");
3655
3450
  const payload = [`--${boundary}`];
3656
- request2.postData?.params.forEach((param, i) => {
3451
+ request.postData?.params.forEach((param, i) => {
3657
3452
  const name = param.name;
3658
3453
  const value = param.value || "";
3659
3454
  const filename = param.fileName || null;
@@ -3668,62 +3463,62 @@ var HTTPSnippet = class {
3668
3463
  }
3669
3464
  payload.push("");
3670
3465
  payload.push(normalizeLinefeeds(value));
3671
- if (i !== request2.postData.params.length - 1) {
3466
+ if (i !== request.postData.params.length - 1) {
3672
3467
  payload.push(`--${boundary}`);
3673
3468
  }
3674
3469
  });
3675
3470
  payload.push(`--${carriage}`);
3676
- request2.postData.boundary = boundary;
3677
- request2.postData.text = payload.join(rn);
3678
- const contentTypeHeader = getHeaderName(request2.headersObj, "content-type") || "content-type";
3679
- request2.headersObj[contentTypeHeader] = `multipart/form-data; boundary=${boundary}`;
3471
+ request.postData.boundary = boundary;
3472
+ request.postData.text = payload.join(rn);
3473
+ const contentTypeHeader = getHeaderName(request.headersObj, "content-type") || "content-type";
3474
+ request.headersObj[contentTypeHeader] = `multipart/form-data; boundary=${boundary}`;
3680
3475
  }
3681
3476
  break;
3682
3477
  case "application/x-www-form-urlencoded":
3683
- if (!request2.postData.params) {
3684
- request2.postData.text = "";
3478
+ if (!request.postData.params) {
3479
+ request.postData.text = "";
3685
3480
  } else {
3686
- request2.postData.paramsObj = request2.postData.params.reduce(reducer, {});
3687
- request2.postData.text = qs.stringify(request2.postData.paramsObj);
3481
+ request.postData.paramsObj = request.postData.params.reduce(reducer, {});
3482
+ request.postData.text = qs.stringify(request.postData.paramsObj);
3688
3483
  }
3689
3484
  break;
3690
3485
  case "text/json":
3691
3486
  case "text/x-json":
3692
3487
  case "application/json":
3693
3488
  case "application/x-json":
3694
- request2.postData.mimeType = "application/json";
3695
- if (request2.postData.text) {
3489
+ request.postData.mimeType = "application/json";
3490
+ if (request.postData.text) {
3696
3491
  try {
3697
- request2.postData.jsonObj = JSON.parse(request2.postData.text);
3492
+ request.postData.jsonObj = JSON.parse(request.postData.text);
3698
3493
  } catch (e) {
3699
- request2.postData.mimeType = "text/plain";
3494
+ request.postData.mimeType = "text/plain";
3700
3495
  }
3701
3496
  }
3702
3497
  break;
3703
3498
  }
3704
3499
  const allHeaders = {
3705
- ...request2.allHeaders,
3706
- ...request2.headersObj
3500
+ ...request.allHeaders,
3501
+ ...request.headersObj
3707
3502
  };
3708
- const urlWithParsedQuery = url.parse(request2.url, true, true);
3709
- request2.queryObj = {
3710
- ...request2.queryObj,
3503
+ const urlWithParsedQuery = url.parse(request.url, true, true);
3504
+ request.queryObj = {
3505
+ ...request.queryObj,
3711
3506
  ...urlWithParsedQuery.query
3712
3507
  };
3713
3508
  let search;
3714
3509
  if (options.harIsAlreadyEncoded) {
3715
- search = qs.stringify(request2.queryObj, {
3510
+ search = qs.stringify(request.queryObj, {
3716
3511
  encode: false,
3717
3512
  indices: false
3718
3513
  });
3719
3514
  } else {
3720
- search = qs.stringify(request2.queryObj, {
3515
+ search = qs.stringify(request.queryObj, {
3721
3516
  indices: false
3722
3517
  });
3723
3518
  }
3724
3519
  const uriObj = {
3725
3520
  ...urlWithParsedQuery,
3726
- query: request2.queryObj,
3521
+ query: request.queryObj,
3727
3522
  search,
3728
3523
  path: search ? `${urlWithParsedQuery.pathname}?${search}` : urlWithParsedQuery.pathname
3729
3524
  };
@@ -3737,7 +3532,7 @@ var HTTPSnippet = class {
3737
3532
  ...uriObj
3738
3533
  });
3739
3534
  return {
3740
- ...request2,
3535
+ ...request,
3741
3536
  allHeaders,
3742
3537
  fullUrl,
3743
3538
  url: url$1,
@@ -3756,7 +3551,7 @@ var HTTPSnippet = class {
3756
3551
  return false;
3757
3552
  }
3758
3553
  const { convert } = target.clientsById[clientId || target.info.default];
3759
- const results = this.requests.map((request2) => convert(request2, options));
3554
+ const results = this.requests.map((request) => convert(request, options));
3760
3555
  return results;
3761
3556
  }
3762
3557
  };
@@ -3768,5 +3563,5 @@ exports.addTarget = addTarget;
3768
3563
  exports.addTargetClient = addTargetClient;
3769
3564
  exports.availableTargets = availableTargets;
3770
3565
  exports.extname = extname;
3771
- //# sourceMappingURL=out.js.map
3566
+ //# sourceMappingURL=index.cjs.map
3772
3567
  //# sourceMappingURL=index.cjs.map