@readme/httpsnippet 10.1.1 → 11.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
 
@@ -516,7 +516,7 @@ var restsharp = {
516
516
  link: "http://restsharp.org/",
517
517
  description: "Simple REST and HTTP API Client for .NET",
518
518
  extname: ".cs",
519
- installation: "dotnet add package RestSharp"
519
+ installation: () => "dotnet add package RestSharp"
520
520
  },
521
521
  convert: ({ method, fullUrl, headersObj, cookies, postData, uriObj }) => {
522
522
  const { push, join } = new CodeBuilder();
@@ -925,7 +925,7 @@ var axios = {
925
925
  link: "https://github.com/axios/axios",
926
926
  description: "Promise based HTTP client for the browser and node.js",
927
927
  extname: ".js",
928
- installation: "npm install axios --save"
928
+ installation: () => "npm install axios --save"
929
929
  },
930
930
  convert: ({ allHeaders, method, url, queryObj, postData }, options) => {
931
931
  const opts = {
@@ -978,7 +978,7 @@ var axios = {
978
978
  requestOptions.data = postData.text;
979
979
  }
980
980
  }
981
- const optionString = stringifyObject9__default.default(requestOptions, {
981
+ const optionString = stringifyObject7__default.default(requestOptions, {
982
982
  indent: " ",
983
983
  inlineCharacterLimit: 80
984
984
  }).replace('"[form]"', "form");
@@ -986,12 +986,8 @@ var axios = {
986
986
  blank();
987
987
  push("axios");
988
988
  push(".request(options)", 1);
989
- push(".then(function (response) {", 1);
990
- push("console.log(response.data);", 2);
991
- push("})", 1);
992
- push(".catch(function (error) {", 1);
993
- push("console.error(error);", 2);
994
- push("});", 1);
989
+ push(".then(res => console.log(res.data))", 1);
990
+ push(".catch(err => console.error(err));", 1);
995
991
  return join();
996
992
  }
997
993
  };
@@ -1028,7 +1024,7 @@ var fetch = {
1028
1024
  options.body = postData.jsonObj;
1029
1025
  }
1030
1026
  break;
1031
- case "multipart/form-data":
1027
+ case "multipart/form-data": {
1032
1028
  if (!postData.params) {
1033
1029
  break;
1034
1030
  }
@@ -1042,6 +1038,7 @@ var fetch = {
1042
1038
  });
1043
1039
  blank();
1044
1040
  break;
1041
+ }
1045
1042
  default:
1046
1043
  if (postData.text) {
1047
1044
  options.body = postData.text;
@@ -1051,7 +1048,7 @@ var fetch = {
1051
1048
  delete options.headers;
1052
1049
  }
1053
1050
  push(
1054
- `const options = ${stringifyObject9__default.default(options, {
1051
+ `const options = ${stringifyObject7__default.default(options, {
1055
1052
  indent: opts.indent,
1056
1053
  inlineCharacterLimit: 80,
1057
1054
  // The Fetch API body only accepts string parameters, but stringified JSON can be difficult
@@ -1075,8 +1072,8 @@ var fetch = {
1075
1072
  blank();
1076
1073
  }
1077
1074
  push(`fetch('${fullUrl}', options)`);
1078
- push(".then(response => response.json())", 1);
1079
- push(".then(response => console.log(response))", 1);
1075
+ push(".then(res => res.json())", 1);
1076
+ push(".then(res => console.log(res))", 1);
1080
1077
  push(".catch(err => console.error(err));", 1);
1081
1078
  return join();
1082
1079
  }
@@ -1137,11 +1134,11 @@ var jquery = {
1137
1134
  settings.data = postData.text;
1138
1135
  }
1139
1136
  }
1140
- const stringifiedSettings = stringifyObject9__default.default(settings, { indent: opts.indent }).replace("'[form]'", "form");
1137
+ const stringifiedSettings = stringifyObject7__default.default(settings, { indent: opts.indent }).replace("'[form]'", "form");
1141
1138
  push(`const settings = ${stringifiedSettings};`);
1142
1139
  blank();
1143
- push("$.ajax(settings).done(function (response) {");
1144
- push("console.log(response);", 1);
1140
+ push("$.ajax(settings).done(res => {");
1141
+ push("console.log(res);", 1);
1145
1142
  push("});");
1146
1143
  return join();
1147
1144
  }
@@ -1164,7 +1161,7 @@ var xhr = {
1164
1161
  switch (postData.mimeType) {
1165
1162
  case "application/json":
1166
1163
  push(
1167
- `const data = JSON.stringify(${stringifyObject9__default.default(postData.jsonObj, {
1164
+ `const data = JSON.stringify(${stringifyObject7__default.default(postData.jsonObj, {
1168
1165
  indent: opts.indent
1169
1166
  })});`
1170
1167
  );
@@ -1218,7 +1215,7 @@ var javascript = {
1218
1215
  info: {
1219
1216
  key: "javascript",
1220
1217
  title: "JavaScript",
1221
- default: "xhr"
1218
+ default: "fetch"
1222
1219
  },
1223
1220
  clientsById: {
1224
1221
  xhr,
@@ -1252,7 +1249,7 @@ var native2 = {
1252
1249
  payload = postData.jsonObj;
1253
1250
  }
1254
1251
  break;
1255
- case "multipart/form-data":
1252
+ case "multipart/form-data": {
1256
1253
  if (!postData.params) {
1257
1254
  break;
1258
1255
  }
@@ -1262,6 +1259,7 @@ var native2 = {
1262
1259
  });
1263
1260
  payload = multipartPayload;
1264
1261
  break;
1262
+ }
1265
1263
  default:
1266
1264
  if (postData.text) {
1267
1265
  payload = postData.text;
@@ -1357,8 +1355,8 @@ var axios2 = {
1357
1355
  title: "Axios",
1358
1356
  link: "https://github.com/axios/axios",
1359
1357
  description: "Promise based HTTP client for the browser and node.js",
1360
- extname: ".cjs",
1361
- installation: "npm install axios --save"
1358
+ extname: ".js",
1359
+ installation: () => "npm install axios --save"
1362
1360
  },
1363
1361
  convert: ({ method, fullUrl, allHeaders, postData }, options) => {
1364
1362
  const opts = {
@@ -1366,7 +1364,8 @@ var axios2 = {
1366
1364
  ...options
1367
1365
  };
1368
1366
  const { blank, join, push, addPostProcessor } = new CodeBuilder({ indent: opts.indent });
1369
- push("const axios = require('axios');");
1367
+ push("import axios from 'axios';");
1368
+ blank();
1370
1369
  const reqOpts = {
1371
1370
  method,
1372
1371
  url: fullUrl
@@ -1377,8 +1376,6 @@ var axios2 = {
1377
1376
  switch (postData.mimeType) {
1378
1377
  case "application/x-www-form-urlencoded":
1379
1378
  if (postData.params) {
1380
- push("const { URLSearchParams } = require('url');");
1381
- blank();
1382
1379
  push("const encodedParams = new URLSearchParams();");
1383
1380
  postData.params.forEach((param) => {
1384
1381
  push(`encodedParams.set('${param.name}', '${param.value}');`);
@@ -1389,39 +1386,32 @@ var axios2 = {
1389
1386
  }
1390
1387
  break;
1391
1388
  case "application/json":
1392
- blank();
1393
1389
  if (postData.jsonObj) {
1394
1390
  reqOpts.data = postData.jsonObj;
1395
1391
  }
1396
1392
  break;
1397
1393
  default:
1398
- blank();
1399
1394
  if (postData.text) {
1400
1395
  reqOpts.data = postData.text;
1401
1396
  }
1402
1397
  }
1403
- const stringifiedOptions = stringifyObject9__default.default(reqOpts, { indent: " ", inlineCharacterLimit: 80 });
1398
+ const stringifiedOptions = stringifyObject7__default.default(reqOpts, { indent: " ", inlineCharacterLimit: 80 });
1404
1399
  push(`const options = ${stringifiedOptions};`);
1405
1400
  blank();
1406
1401
  push("axios");
1407
1402
  push(".request(options)", 1);
1408
- push(".then(function (response) {", 1);
1409
- push("console.log(response.data);", 2);
1410
- push("})", 1);
1411
- push(".catch(function (error) {", 1);
1412
- push("console.error(error);", 2);
1413
- push("});", 1);
1403
+ push(".then(res => console.log(res.data))", 1);
1404
+ push(".catch(err => console.error(err));", 1);
1414
1405
  return join();
1415
1406
  }
1416
1407
  };
1417
1408
  var fetch2 = {
1418
1409
  info: {
1419
1410
  key: "fetch",
1420
- title: "Fetch",
1421
- link: "https://github.com/bitinn/node-fetch",
1422
- description: "Simplified HTTP node-fetch client",
1423
- extname: ".cjs",
1424
- installation: "npm install node-fetch@2 --save"
1411
+ title: "fetch",
1412
+ link: "https://nodejs.org/docs/latest/api/globals.html#fetch",
1413
+ description: "Perform asynchronous HTTP requests with the Fetch API",
1414
+ extname: ".js"
1425
1415
  },
1426
1416
  convert: ({ method, fullUrl, postData, headersObj, cookies }, options) => {
1427
1417
  const opts = {
@@ -1430,7 +1420,6 @@ var fetch2 = {
1430
1420
  };
1431
1421
  let includeFS = false;
1432
1422
  const { blank, push, join, unshift } = new CodeBuilder({ indent: opts.indent });
1433
- push("const fetch = require('node-fetch');");
1434
1423
  const url = fullUrl;
1435
1424
  const reqOpts = {
1436
1425
  method
@@ -1440,20 +1429,19 @@ var fetch2 = {
1440
1429
  }
1441
1430
  switch (postData.mimeType) {
1442
1431
  case "application/x-www-form-urlencoded":
1443
- unshift("const { URLSearchParams } = require('url');");
1444
1432
  push("const encodedParams = new URLSearchParams();");
1445
- blank();
1446
1433
  postData.params?.forEach((param) => {
1447
1434
  push(`encodedParams.set('${param.name}', '${param.value}');`);
1448
1435
  });
1449
1436
  reqOpts.body = "encodedParams";
1437
+ blank();
1450
1438
  break;
1451
1439
  case "application/json":
1452
1440
  if (postData.jsonObj) {
1453
1441
  reqOpts.body = postData.jsonObj;
1454
1442
  }
1455
1443
  break;
1456
- case "multipart/form-data":
1444
+ case "multipart/form-data": {
1457
1445
  if (!postData.params) {
1458
1446
  break;
1459
1447
  }
@@ -1461,9 +1449,7 @@ var fetch2 = {
1461
1449
  if (contentTypeHeader) {
1462
1450
  delete headersObj[contentTypeHeader];
1463
1451
  }
1464
- unshift("const FormData = require('form-data');");
1465
1452
  push("const formData = new FormData();");
1466
- blank();
1467
1453
  postData.params.forEach((param) => {
1468
1454
  if (!param.fileName && !param.fileName && !param.contentType) {
1469
1455
  push(`formData.append('${param.name}', '${param.value}');`);
@@ -1471,10 +1457,15 @@ var fetch2 = {
1471
1457
  }
1472
1458
  if (param.fileName) {
1473
1459
  includeFS = true;
1474
- push(`formData.append('${param.name}', fs.createReadStream('${param.fileName}'));`);
1460
+ push(
1461
+ `formData.append('${param.name}', await new Response(fs.createReadStream('${param.fileName}')).blob());`
1462
+ );
1475
1463
  }
1476
1464
  });
1465
+ reqOpts.body = "formData";
1466
+ blank();
1477
1467
  break;
1468
+ }
1478
1469
  default:
1479
1470
  if (postData.text) {
1480
1471
  reqOpts.body = postData.text;
@@ -1489,12 +1480,11 @@ var fetch2 = {
1489
1480
  reqOpts.headers.cookie = cookiesString;
1490
1481
  }
1491
1482
  }
1492
- blank();
1493
1483
  push(`const url = '${url}';`);
1494
1484
  if (reqOpts.headers && !Object.keys(reqOpts.headers).length) {
1495
1485
  delete reqOpts.headers;
1496
1486
  }
1497
- const stringifiedOptions = stringifyObject9__default.default(reqOpts, {
1487
+ const stringifiedOptions = stringifyObject7__default.default(reqOpts, {
1498
1488
  indent: " ",
1499
1489
  inlineCharacterLimit: 80,
1500
1490
  // The Fetch API body only accepts string parameters, but stringified JSON can be difficult to
@@ -1510,17 +1500,13 @@ var fetch2 = {
1510
1500
  push(`const options = ${stringifiedOptions};`);
1511
1501
  blank();
1512
1502
  if (includeFS) {
1513
- unshift("const fs = require('fs');");
1514
- }
1515
- if (postData.params && postData.mimeType === "multipart/form-data") {
1516
- push("options.body = formData;");
1517
- blank();
1503
+ unshift("import fs from 'fs';\n");
1518
1504
  }
1519
1505
  push("fetch(url, options)");
1520
1506
  push(".then(res => res.json())", 1);
1521
1507
  push(".then(json => console.log(json))", 1);
1522
- push(".catch(err => console.error('error:' + err));", 1);
1523
- return join().replace(/'encodedParams'/, "encodedParams").replace(/"fs\.createReadStream\(\\"(.+)\\"\)"/, 'fs.createReadStream("$1")');
1508
+ push(".catch(err => console.error(err));", 1);
1509
+ return join().replace(/'encodedParams'/, "encodedParams").replace(/'formData'/, "formData");
1524
1510
  }
1525
1511
  };
1526
1512
  var native3 = {
@@ -1543,7 +1529,7 @@ var native3 = {
1543
1529
  };
1544
1530
  push(`const http = require('${uriObj.protocol?.replace(":", "")}');`);
1545
1531
  blank();
1546
- push(`const options = ${stringifyObject9__default.default(reqOpts, { indent })};`);
1532
+ push(`const options = ${stringifyObject7__default.default(reqOpts, { indent })};`);
1547
1533
  blank();
1548
1534
  push("const req = http.request(options, function (res) {");
1549
1535
  push("const chunks = [];", 1);
@@ -1563,7 +1549,7 @@ var native3 = {
1563
1549
  if (postData.paramsObj) {
1564
1550
  unshift("const qs = require('querystring');");
1565
1551
  push(
1566
- `req.write(qs.stringify(${stringifyObject9__default.default(postData.paramsObj, {
1552
+ `req.write(qs.stringify(${stringifyObject7__default.default(postData.paramsObj, {
1567
1553
  indent: " ",
1568
1554
  inlineCharacterLimit: 80
1569
1555
  })}));`
@@ -1573,7 +1559,7 @@ var native3 = {
1573
1559
  case "application/json":
1574
1560
  if (postData.jsonObj) {
1575
1561
  push(
1576
- `req.write(JSON.stringify(${stringifyObject9__default.default(postData.jsonObj, {
1562
+ `req.write(JSON.stringify(${stringifyObject7__default.default(postData.jsonObj, {
1577
1563
  indent: " ",
1578
1564
  inlineCharacterLimit: 80
1579
1565
  })}));`
@@ -1582,208 +1568,24 @@ var native3 = {
1582
1568
  break;
1583
1569
  default:
1584
1570
  if (postData.text) {
1585
- push(`req.write(${stringifyObject9__default.default(postData.text, { indent })});`);
1571
+ push(`req.write(${stringifyObject7__default.default(postData.text, { indent })});`);
1586
1572
  }
1587
1573
  }
1588
1574
  push("req.end();");
1589
1575
  return join();
1590
1576
  }
1591
1577
  };
1592
- var request = {
1593
- info: {
1594
- key: "request",
1595
- title: "Request",
1596
- link: "https://github.com/request/request",
1597
- description: "Simplified HTTP request client",
1598
- extname: ".cjs",
1599
- installation: "npm install request --save"
1600
- },
1601
- convert: ({ method, url, fullUrl, postData, headersObj, cookies }, options) => {
1602
- const opts = {
1603
- indent: " ",
1604
- ...options
1605
- };
1606
- let includeFS = false;
1607
- const { push, blank, join, unshift, addPostProcessor } = new CodeBuilder({ indent: opts.indent });
1608
- push("const request = require('request');");
1609
- blank();
1610
- const reqOpts = {
1611
- method,
1612
- url: fullUrl
1613
- };
1614
- if (Object.keys(headersObj).length) {
1615
- reqOpts.headers = headersObj;
1616
- }
1617
- switch (postData.mimeType) {
1618
- case "application/x-www-form-urlencoded":
1619
- reqOpts.form = postData.paramsObj;
1620
- break;
1621
- case "application/json":
1622
- if (postData.jsonObj) {
1623
- reqOpts.body = postData.jsonObj;
1624
- reqOpts.json = true;
1625
- }
1626
- break;
1627
- case "multipart/form-data":
1628
- if (!postData.params) {
1629
- break;
1630
- }
1631
- reqOpts.formData = {};
1632
- postData.params.forEach((param) => {
1633
- if (!param.fileName && !param.fileName && !param.contentType) {
1634
- reqOpts.formData[param.name] = param.value;
1635
- return;
1636
- }
1637
- let attachment = {};
1638
- if (param.fileName) {
1639
- includeFS = true;
1640
- attachment = {
1641
- value: `fs.createReadStream(${param.fileName})`,
1642
- options: {
1643
- filename: param.fileName,
1644
- contentType: param.contentType ? param.contentType : null
1645
- }
1646
- };
1647
- } else if (param.value) {
1648
- attachment.value = param.value;
1649
- }
1650
- reqOpts.formData[param.name] = attachment;
1651
- });
1652
- addPostProcessor((code) => code.replace(/'fs\.createReadStream\((.*)\)'/, "fs.createReadStream('$1')"));
1653
- break;
1654
- default:
1655
- if (postData.text) {
1656
- reqOpts.body = postData.text;
1657
- }
1658
- }
1659
- if (cookies.length) {
1660
- reqOpts.jar = "JAR";
1661
- push("const jar = request.jar();");
1662
- cookies.forEach(({ name, value }) => {
1663
- push(`jar.setCookie(request.cookie('${encodeURIComponent(name)}=${encodeURIComponent(value)}'), '${url}');`);
1664
- });
1665
- blank();
1666
- addPostProcessor((code) => code.replace(/'JAR'/, "jar"));
1667
- }
1668
- if (includeFS) {
1669
- unshift("const fs = require('fs');");
1670
- }
1671
- push(`const options = ${stringifyObject9__default.default(reqOpts, { indent: " ", inlineCharacterLimit: 80 })};`);
1672
- blank();
1673
- push("request(options, function (error, response, body) {");
1674
- push("if (error) throw new Error(error);", 1);
1675
- blank();
1676
- push("console.log(body);", 1);
1677
- push("});");
1678
- return join();
1679
- }
1680
- };
1681
- var unirest2 = {
1682
- info: {
1683
- key: "unirest",
1684
- title: "Unirest",
1685
- link: "http://unirest.io/nodejs.html",
1686
- description: "Lightweight HTTP Request Client Library",
1687
- extname: ".cjs"
1688
- },
1689
- convert: ({ method, url, cookies, queryObj, postData, headersObj }, options) => {
1690
- const opts = {
1691
- indent: " ",
1692
- ...options
1693
- };
1694
- let includeFS = false;
1695
- const { addPostProcessor, blank, join, push, unshift } = new CodeBuilder({
1696
- indent: opts.indent
1697
- });
1698
- push("const unirest = require('unirest');");
1699
- blank();
1700
- push(`const req = unirest('${method}', '${url}');`);
1701
- blank();
1702
- if (cookies.length) {
1703
- push("const CookieJar = unirest.jar();");
1704
- cookies.forEach((cookie) => {
1705
- push(`CookieJar.add('${encodeURIComponent(cookie.name)}=${encodeURIComponent(cookie.value)}', '${url}');`);
1706
- });
1707
- push("req.jar(CookieJar);");
1708
- blank();
1709
- }
1710
- if (Object.keys(queryObj).length) {
1711
- push(`req.query(${stringifyObject9__default.default(queryObj, { indent: opts.indent })});`);
1712
- blank();
1713
- }
1714
- if (Object.keys(headersObj).length) {
1715
- push(`req.headers(${stringifyObject9__default.default(headersObj, { indent: opts.indent })});`);
1716
- blank();
1717
- }
1718
- switch (postData.mimeType) {
1719
- case "application/x-www-form-urlencoded":
1720
- if (postData.paramsObj) {
1721
- push(`req.form(${stringifyObject9__default.default(postData.paramsObj, { indent: opts.indent })});`);
1722
- blank();
1723
- }
1724
- break;
1725
- case "application/json":
1726
- if (postData.jsonObj) {
1727
- push("req.type('json');");
1728
- push(`req.send(${stringifyObject9__default.default(postData.jsonObj, { indent: opts.indent })});`);
1729
- blank();
1730
- }
1731
- break;
1732
- case "multipart/form-data": {
1733
- if (!postData.params) {
1734
- break;
1735
- }
1736
- const multipart = [];
1737
- postData.params.forEach((param) => {
1738
- const part = {};
1739
- if (param.fileName && !param.value) {
1740
- includeFS = true;
1741
- part.body = `fs.createReadStream('${param.fileName}')`;
1742
- addPostProcessor((code) => code.replace(/'fs\.createReadStream\(\\'(.+)\\'\)'/, "fs.createReadStream('$1')"));
1743
- } else if (param.value) {
1744
- part.body = param.value;
1745
- }
1746
- if (part.body) {
1747
- if (param.contentType) {
1748
- part["content-type"] = param.contentType;
1749
- }
1750
- multipart.push(part);
1751
- }
1752
- });
1753
- push(`req.multipart(${stringifyObject9__default.default(multipart, { indent: opts.indent })});`);
1754
- blank();
1755
- break;
1756
- }
1757
- default:
1758
- if (postData.text) {
1759
- push(`req.send(${stringifyObject9__default.default(postData.text, { indent: opts.indent })});`);
1760
- blank();
1761
- }
1762
- }
1763
- if (includeFS) {
1764
- unshift("const fs = require('fs');");
1765
- }
1766
- push("req.end(function (res) {");
1767
- push("if (res.error) throw new Error(res.error);", 1);
1768
- blank();
1769
- push("console.log(res.body);", 1);
1770
- push("});");
1771
- return join();
1772
- }
1773
- };
1774
1578
 
1775
1579
  // src/targets/node/target.ts
1776
1580
  var node = {
1777
1581
  info: {
1778
1582
  key: "node",
1779
1583
  title: "Node.js",
1780
- default: "native",
1584
+ default: "fetch",
1781
1585
  cli: "node %s"
1782
1586
  },
1783
1587
  clientsById: {
1784
1588
  native: native3,
1785
- request,
1786
- unirest: unirest2,
1787
1589
  axios: axios2,
1788
1590
  fetch: fetch2
1789
1591
  }
@@ -1961,7 +1763,7 @@ var cohttp = {
1961
1763
  link: "https://github.com/mirage/ocaml-cohttp",
1962
1764
  description: "Cohttp is a very lightweight HTTP server using Lwt or Async for OCaml",
1963
1765
  extname: ".ml",
1964
- installation: "opam install cohttp-lwt-unix cohttp-async"
1766
+ installation: () => "opam install cohttp-lwt-unix cohttp-async"
1965
1767
  },
1966
1768
  convert: ({ fullUrl, allHeaders, postData, method }, options) => {
1967
1769
  const opts = {
@@ -2159,9 +1961,9 @@ var curl = {
2159
1961
  push("curl_setopt_array($curl, [");
2160
1962
  const curlopts = new CodeBuilder({ indent, join: `
2161
1963
  ${indent}` });
2162
- curlOptions.forEach(({ value, name, escape: escape2 }) => {
1964
+ curlOptions.forEach(({ value, name, escape: escape3 }) => {
2163
1965
  if (value !== null && value !== void 0) {
2164
- curlopts.push(`${name} => ${escape2 ? JSON.stringify(value) : value},`);
1966
+ curlopts.push(`${name} => ${escape3 ? JSON.stringify(value) : value},`);
2165
1967
  }
2166
1968
  });
2167
1969
  const curlCookies = cookies.map((cookie) => `${encodeURIComponent(cookie.name)}=${encodeURIComponent(cookie.value)}`);
@@ -2208,7 +2010,7 @@ var guzzle = {
2208
2010
  link: "http://docs.guzzlephp.org/en/stable/",
2209
2011
  description: "PHP with Guzzle",
2210
2012
  extname: ".php",
2211
- installation: "composer require guzzlehttp/guzzle"
2013
+ installation: () => "composer require guzzlehttp/guzzle"
2212
2014
  },
2213
2015
  convert: ({ postData, fullUrl, method, cookies, headersObj }, options) => {
2214
2016
  const opts = {
@@ -2269,9 +2071,7 @@ var guzzle = {
2269
2071
  requestPush(`'body' => ${convertType(postData.text)},`, 1);
2270
2072
  }
2271
2073
  }
2272
- const headers = Object.keys(headersObj).sort().map(function(key) {
2273
- return `${opts.indent}${opts.indent}'${key}' => '${escapeForSingleQuotes(headersObj[key])}',`;
2274
- });
2074
+ const headers = Object.keys(headersObj).sort().map((key) => `${opts.indent}${opts.indent}'${key}' => '${escapeForSingleQuotes(headersObj[key])}',`);
2275
2075
  const cookieString = cookies.map((cookie) => `${encodeURIComponent(cookie.name)}=${encodeURIComponent(cookie.value)}`).join("; ");
2276
2076
  if (cookieString.length) {
2277
2077
  headers.push(`${opts.indent}${opts.indent}'cookie' => '${escapeForSingleQuotes(cookieString)}',`);
@@ -2634,7 +2434,7 @@ var requests = {
2634
2434
  link: "http://docs.python-requests.org/en/latest/api/#requests.request",
2635
2435
  description: "Requests HTTP library",
2636
2436
  extname: ".py",
2637
- installation: "python -m pip install requests"
2437
+ installation: () => "python -m pip install requests"
2638
2438
  },
2639
2439
  convert: ({ fullUrl, postData, allHeaders, method }, options) => {
2640
2440
  const opts = {
@@ -2734,22 +2534,22 @@ var requests = {
2734
2534
  push("}");
2735
2535
  blank();
2736
2536
  }
2737
- let request2 = builtInMethods.includes(method) ? `response = requests.${method.toLowerCase()}(url` : `response = requests.request("${method}", url`;
2537
+ let request = builtInMethods.includes(method) ? `response = requests.${method.toLowerCase()}(url` : `response = requests.request("${method}", url`;
2738
2538
  if (hasPayload) {
2739
2539
  if (jsonPayload) {
2740
- request2 += ", json=payload";
2540
+ request += ", json=payload";
2741
2541
  } else {
2742
- request2 += ", data=payload";
2542
+ request += ", data=payload";
2743
2543
  }
2744
2544
  }
2745
2545
  if (hasFiles) {
2746
- request2 += ", files=files";
2546
+ request += ", files=files";
2747
2547
  }
2748
2548
  if (headerCount > 0) {
2749
- request2 += ", headers=headers";
2549
+ request += ", headers=headers";
2750
2550
  }
2751
- request2 += ")";
2752
- push(request2);
2551
+ request += ")";
2552
+ push(request);
2753
2553
  blank();
2754
2554
  push("print(response.text)");
2755
2555
  return join();
@@ -2834,22 +2634,22 @@ var httr = {
2834
2634
  const setContentType = `content_type("${escapeForDoubleQuotes(postData.mimeType)}")`;
2835
2635
  const otherHeaders = Object.entries(allHeaders).filter(([key]) => !["cookie", "accept", "content-type"].includes(key.toLowerCase())).map(([key, value]) => `'${key}' = '${escapeForSingleQuotes(value)}'`).join(", ");
2836
2636
  const setHeaders = otherHeaders ? `add_headers(${otherHeaders})` : void 0;
2837
- let request2 = `response <- VERB("${method}", url`;
2637
+ let request = `response <- VERB("${method}", url`;
2838
2638
  if (payload) {
2839
- request2 += ", body = payload";
2639
+ request += ", body = payload";
2840
2640
  }
2841
2641
  if (queryString.length) {
2842
- request2 += ", query = queryString";
2642
+ request += ", query = queryString";
2843
2643
  }
2844
2644
  const headerAdditions = [setHeaders, setContentType, setAccept, setCookies].filter((x) => !!x).join(", ");
2845
2645
  if (headerAdditions) {
2846
- request2 += `, ${headerAdditions}`;
2646
+ request += `, ${headerAdditions}`;
2847
2647
  }
2848
2648
  if (postData.text || postData.jsonObj || postData.params) {
2849
- request2 += ", encode = encode";
2649
+ request += ", encode = encode";
2850
2650
  }
2851
- request2 += ")";
2852
- push(request2);
2651
+ request += ")";
2652
+ push(request);
2853
2653
  blank();
2854
2654
  push('content(response, "text")');
2855
2655
  return join();
@@ -2951,7 +2751,7 @@ var quote = (value = "") => {
2951
2751
  }
2952
2752
  return `'${value.replace(/'/g, "'\\''")}'`;
2953
2753
  };
2954
- var escape = (value) => value.replace(/\r/g, "\\r").replace(/\n/g, "\\n");
2754
+ var escape2 = (value) => value.replace(/\r/g, "\\r").replace(/\n/g, "\\n");
2955
2755
 
2956
2756
  // src/targets/shell/curl/client.ts
2957
2757
  var params = {
@@ -3038,18 +2838,16 @@ ${indent}` : " "
3038
2838
  case "application/x-www-form-urlencoded":
3039
2839
  if (postData.params) {
3040
2840
  postData.params.forEach((param) => {
3041
- const unencoded = param.name;
3042
2841
  const encoded = encodeURIComponent(param.name);
3043
- const needsEncoding = encoded !== unencoded;
3044
- const name = needsEncoding ? encoded : unencoded;
3045
- const flag = binary ? "--data-binary" : needsEncoding ? "--data-urlencode" : arg("data");
2842
+ const name = encoded !== param.name ? encoded : param.name;
2843
+ const flag = binary ? "--data-binary" : "--data-urlencode";
3046
2844
  push(`${flag} ${quote(`${name}=${param.value}`)}`);
3047
2845
  });
3048
2846
  } else {
3049
2847
  push(`${binary ? "--data-binary" : arg("data")} ${quote(postData.text)}`);
3050
2848
  }
3051
2849
  break;
3052
- default:
2850
+ default: {
3053
2851
  if (!postData.text) {
3054
2852
  break;
3055
2853
  }
@@ -3076,13 +2874,14 @@ ${JSON.stringify(jsonPayload, null, indentJSON)}
3076
2874
  '`
3077
2875
  );
3078
2876
  }
3079
- } catch (err) {
2877
+ } catch {
3080
2878
  }
3081
2879
  }
3082
2880
  }
3083
2881
  if (!builtPayload) {
3084
2882
  push(`${binary ? "--data-binary" : arg("data")} ${quote(postData.text)}`);
3085
2883
  }
2884
+ }
3086
2885
  }
3087
2886
  return join();
3088
2887
  }
@@ -3096,7 +2895,7 @@ var httpie = {
3096
2895
  link: "http://httpie.org/",
3097
2896
  description: "a CLI, cURL-like tool for humans",
3098
2897
  extname: ".sh",
3099
- installation: "brew install httpie"
2898
+ installation: () => "brew install httpie"
3100
2899
  },
3101
2900
  convert: ({ allHeaders, postData, queryObj, fullUrl, method, url }, options) => {
3102
2901
  const opts = {
@@ -3165,7 +2964,7 @@ ${opts.indent}` : " "
3165
2964
  push(`${key}:${quote(allHeaders[key])}`);
3166
2965
  });
3167
2966
  if (postData.mimeType === "application/x-www-form-urlencoded") {
3168
- if (postData.params && postData.params.length) {
2967
+ if (postData.params?.length) {
3169
2968
  flags.push(opts.short ? "-f" : "--form");
3170
2969
  postData.params.forEach((param) => {
3171
2970
  push(`${param.name}=${quote(param.value)}`);
@@ -3217,7 +3016,7 @@ ${opts.indent}` : " "
3217
3016
  push(`--header ${quote(header)}`);
3218
3017
  });
3219
3018
  if (postData.text) {
3220
- push(`--body-data ${escape(quote(postData.text))}`);
3019
+ push(`--body-data ${escape2(quote(postData.text))}`);
3221
3020
  }
3222
3021
  push(opts.short ? "-O" : "--output-document");
3223
3022
  push(`- ${quote(fullUrl)}`);
@@ -3321,7 +3120,9 @@ var urlsession = {
3321
3120
  const parameters = postData.params.map((p) => `"${p.name}": "${p.value}"`);
3322
3121
  if (opts.pretty) {
3323
3122
  push("let parameters = [");
3324
- parameters.forEach((param) => push(`${param},`, 1));
3123
+ parameters.forEach((param) => {
3124
+ push(`${param},`, 1);
3125
+ });
3325
3126
  push("]");
3326
3127
  } else {
3327
3128
  push(`let parameters = [${parameters.join(", ")}]`);
@@ -3574,7 +3375,7 @@ var HTTPSnippet = class {
3574
3375
  }
3575
3376
  init() {
3576
3377
  this.initCalled = true;
3577
- this.requests = this.entries.map(({ request: request2 }) => {
3378
+ this.requests = this.entries.map(({ request }) => {
3578
3379
  const req = {
3579
3380
  bodySize: 0,
3580
3381
  headersSize: 0,
@@ -3583,9 +3384,9 @@ var HTTPSnippet = class {
3583
3384
  httpVersion: "HTTP/1.1",
3584
3385
  queryString: [],
3585
3386
  postData: {
3586
- mimeType: request2.postData?.mimeType || "application/octet-stream"
3387
+ mimeType: request.postData?.mimeType || "application/octet-stream"
3587
3388
  },
3588
- ...request2
3389
+ ...request
3589
3390
  };
3590
3391
  if (req.postData && !req.postData.mimeType) {
3591
3392
  req.postData.mimeType = "application/octet-stream";
@@ -3595,7 +3396,7 @@ var HTTPSnippet = class {
3595
3396
  return this;
3596
3397
  }
3597
3398
  prepare(harRequest, options) {
3598
- const request2 = {
3399
+ const request = {
3599
3400
  ...harRequest,
3600
3401
  fullUrl: "",
3601
3402
  uriObj: {},
@@ -3604,21 +3405,21 @@ var HTTPSnippet = class {
3604
3405
  cookiesObj: {},
3605
3406
  allHeaders: {}
3606
3407
  };
3607
- if (request2.queryString && request2.queryString.length) {
3608
- request2.queryObj = request2.queryString.reduce(reducer, {});
3408
+ if (request?.queryString.length) {
3409
+ request.queryObj = request.queryString.reduce(reducer, {});
3609
3410
  }
3610
- if (request2.headers && request2.headers.length) {
3411
+ if (request?.headers.length) {
3611
3412
  const http2VersionRegex = /^HTTP\/2/;
3612
- request2.headersObj = request2.headers.reduce((accumulator, { name, value }) => {
3613
- const headerName = http2VersionRegex.exec(request2.httpVersion) ? name.toLocaleLowerCase() : name;
3413
+ request.headersObj = request.headers.reduce((accumulator, { name, value }) => {
3414
+ const headerName = http2VersionRegex.exec(request.httpVersion) ? name.toLocaleLowerCase() : name;
3614
3415
  return {
3615
3416
  ...accumulator,
3616
3417
  [headerName]: value
3617
3418
  };
3618
3419
  }, {});
3619
3420
  }
3620
- if (request2.cookies && request2.cookies.length) {
3621
- request2.cookiesObj = request2.cookies.reduceRight(
3421
+ if (request?.cookies.length) {
3422
+ request.cookiesObj = request.cookies.reduceRight(
3622
3423
  (accumulator, { name, value }) => ({
3623
3424
  ...accumulator,
3624
3425
  [name]: value
@@ -3626,100 +3427,100 @@ var HTTPSnippet = class {
3626
3427
  {}
3627
3428
  );
3628
3429
  }
3629
- const cookies = request2.cookies?.map(({ name, value }) => {
3430
+ const cookies = request.cookies?.map(({ name, value }) => {
3630
3431
  if (options.harIsAlreadyEncoded) {
3631
3432
  return `${name}=${value}`;
3632
3433
  }
3633
3434
  return `${encodeURIComponent(name)}=${encodeURIComponent(value)}`;
3634
3435
  });
3635
3436
  if (cookies?.length) {
3636
- request2.allHeaders.cookie = cookies.join("; ");
3437
+ request.allHeaders.cookie = cookies.join("; ");
3637
3438
  }
3638
- switch (request2.postData.mimeType) {
3439
+ switch (request.postData.mimeType) {
3639
3440
  case "multipart/mixed":
3640
3441
  case "multipart/related":
3641
3442
  case "multipart/form-data":
3642
3443
  case "multipart/alternative":
3643
- request2.postData.text = "";
3644
- request2.postData.mimeType = "multipart/form-data";
3645
- if (request2.postData?.params) {
3444
+ request.postData.text = "";
3445
+ request.postData.mimeType = "multipart/form-data";
3446
+ if (request.postData?.params) {
3646
3447
  const boundary = "---011000010111000001101001";
3647
3448
  const carriage = `${boundary}--`;
3648
3449
  const rn = "\r\n";
3649
- const escape2 = (str) => str.replace(/\n/g, "%0A").replace(/\r/g, "%0D").replace(/"/g, "%22");
3450
+ const escapeStr = (str) => str.replace(/\n/g, "%0A").replace(/\r/g, "%0D").replace(/"/g, "%22");
3650
3451
  const normalizeLinefeeds = (value) => value.replace(/\r?\n|\r/g, "\r\n");
3651
3452
  const payload = [`--${boundary}`];
3652
- request2.postData?.params.forEach((param, i) => {
3453
+ request.postData?.params.forEach((param, i) => {
3653
3454
  const name = param.name;
3654
3455
  const value = param.value || "";
3655
3456
  const filename = param.fileName || null;
3656
3457
  const contentType = param.contentType || "application/octet-stream";
3657
3458
  if (filename) {
3658
3459
  payload.push(
3659
- `Content-Disposition: form-data; name="${escape2(normalizeLinefeeds(name))}"; filename="${filename}"`
3460
+ `Content-Disposition: form-data; name="${escapeStr(normalizeLinefeeds(name))}"; filename="${filename}"`
3660
3461
  );
3661
3462
  payload.push(`Content-Type: ${contentType}`);
3662
3463
  } else {
3663
- payload.push(`Content-Disposition: form-data; name="${escape2(normalizeLinefeeds(name))}"`);
3464
+ payload.push(`Content-Disposition: form-data; name="${escape(normalizeLinefeeds(name))}"`);
3664
3465
  }
3665
3466
  payload.push("");
3666
3467
  payload.push(normalizeLinefeeds(value));
3667
- if (i !== request2.postData.params.length - 1) {
3468
+ if (i !== request.postData.params.length - 1) {
3668
3469
  payload.push(`--${boundary}`);
3669
3470
  }
3670
3471
  });
3671
3472
  payload.push(`--${carriage}`);
3672
- request2.postData.boundary = boundary;
3673
- request2.postData.text = payload.join(rn);
3674
- const contentTypeHeader = getHeaderName(request2.headersObj, "content-type") || "content-type";
3675
- request2.headersObj[contentTypeHeader] = `multipart/form-data; boundary=${boundary}`;
3473
+ request.postData.boundary = boundary;
3474
+ request.postData.text = payload.join(rn);
3475
+ const contentTypeHeader = getHeaderName(request.headersObj, "content-type") || "content-type";
3476
+ request.headersObj[contentTypeHeader] = `multipart/form-data; boundary=${boundary}`;
3676
3477
  }
3677
3478
  break;
3678
3479
  case "application/x-www-form-urlencoded":
3679
- if (!request2.postData.params) {
3680
- request2.postData.text = "";
3480
+ if (!request.postData.params) {
3481
+ request.postData.text = "";
3681
3482
  } else {
3682
- request2.postData.paramsObj = request2.postData.params.reduce(reducer, {});
3683
- request2.postData.text = qs.stringify(request2.postData.paramsObj);
3483
+ request.postData.paramsObj = request.postData.params.reduce(reducer, {});
3484
+ request.postData.text = qs.stringify(request.postData.paramsObj);
3684
3485
  }
3685
3486
  break;
3686
3487
  case "text/json":
3687
3488
  case "text/x-json":
3688
3489
  case "application/json":
3689
3490
  case "application/x-json":
3690
- request2.postData.mimeType = "application/json";
3691
- if (request2.postData.text) {
3491
+ request.postData.mimeType = "application/json";
3492
+ if (request.postData.text) {
3692
3493
  try {
3693
- request2.postData.jsonObj = JSON.parse(request2.postData.text);
3694
- } catch (e) {
3695
- request2.postData.mimeType = "text/plain";
3494
+ request.postData.jsonObj = JSON.parse(request.postData.text);
3495
+ } catch {
3496
+ request.postData.mimeType = "text/plain";
3696
3497
  }
3697
3498
  }
3698
3499
  break;
3699
3500
  }
3700
3501
  const allHeaders = {
3701
- ...request2.allHeaders,
3702
- ...request2.headersObj
3502
+ ...request.allHeaders,
3503
+ ...request.headersObj
3703
3504
  };
3704
- const urlWithParsedQuery = url.parse(request2.url, true, true);
3705
- request2.queryObj = {
3706
- ...request2.queryObj,
3505
+ const urlWithParsedQuery = url.parse(request.url, true, true);
3506
+ request.queryObj = {
3507
+ ...request.queryObj,
3707
3508
  ...urlWithParsedQuery.query
3708
3509
  };
3709
3510
  let search;
3710
3511
  if (options.harIsAlreadyEncoded) {
3711
- search = qs.stringify(request2.queryObj, {
3512
+ search = qs.stringify(request.queryObj, {
3712
3513
  encode: false,
3713
3514
  indices: false
3714
3515
  });
3715
3516
  } else {
3716
- search = qs.stringify(request2.queryObj, {
3517
+ search = qs.stringify(request.queryObj, {
3717
3518
  indices: false
3718
3519
  });
3719
3520
  }
3720
3521
  const uriObj = {
3721
3522
  ...urlWithParsedQuery,
3722
- query: request2.queryObj,
3523
+ query: request.queryObj,
3723
3524
  search,
3724
3525
  path: search ? `${urlWithParsedQuery.pathname}?${search}` : urlWithParsedQuery.pathname
3725
3526
  };
@@ -3733,7 +3534,7 @@ var HTTPSnippet = class {
3733
3534
  ...uriObj
3734
3535
  });
3735
3536
  return {
3736
- ...request2,
3537
+ ...request,
3737
3538
  allHeaders,
3738
3539
  fullUrl,
3739
3540
  url: url$1,
@@ -3745,14 +3546,29 @@ var HTTPSnippet = class {
3745
3546
  this.init();
3746
3547
  }
3747
3548
  if (!options && clientId) {
3748
- options = clientId;
3549
+ options = { clientId };
3749
3550
  }
3750
3551
  const target = targets[targetId];
3751
3552
  if (!target) {
3752
- return false;
3553
+ return [false];
3753
3554
  }
3754
3555
  const { convert } = target.clientsById[clientId || target.info.default];
3755
- const results = this.requests.map((request2) => convert(request2, options));
3556
+ const results = this.requests.map((request) => convert(request, options));
3557
+ return results;
3558
+ }
3559
+ installation(targetId, clientId, options) {
3560
+ if (!this.initCalled) {
3561
+ this.init();
3562
+ }
3563
+ if (!options && clientId) {
3564
+ options = { clientId };
3565
+ }
3566
+ const target = targets[targetId];
3567
+ if (!target) {
3568
+ return [false];
3569
+ }
3570
+ const { info } = target.clientsById[clientId || target.info.default];
3571
+ const results = this.requests.map((request) => info?.installation ? info.installation(request, options) : false);
3756
3572
  return results;
3757
3573
  }
3758
3574
  };