@readme/httpsnippet 6.2.1 → 7.0.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.
Files changed (494) hide show
  1. package/dist/chunk-XPUGYZ4Y.mjs +3485 -0
  2. package/dist/chunk-XPUGYZ4Y.mjs.map +1 -0
  3. package/dist/index-acc66e3d.d.ts +167 -0
  4. package/dist/index.d.mts +4 -0
  5. package/dist/index.d.ts +4 -95
  6. package/dist/index.js +3777 -261
  7. package/dist/index.js.map +1 -0
  8. package/dist/index.mjs +299 -0
  9. package/dist/index.mjs.map +1 -0
  10. package/dist/targets/targets.d.mts +4 -0
  11. package/dist/targets/targets.d.ts +4 -53
  12. package/dist/targets/targets.js +3476 -113
  13. package/dist/targets/targets.js.map +1 -0
  14. package/dist/targets/targets.mjs +3 -0
  15. package/dist/targets/targets.mjs.map +1 -0
  16. package/package.json +30 -14
  17. package/dist/helpers/code-builder.d.ts +0 -49
  18. package/dist/helpers/code-builder.js +0 -91
  19. package/dist/helpers/escape.d.ts +0 -46
  20. package/dist/helpers/escape.js +0 -101
  21. package/dist/helpers/form-data.d.ts +0 -30
  22. package/dist/helpers/form-data.js +0 -157
  23. package/dist/helpers/headers.d.ts +0 -18
  24. package/dist/helpers/headers.js +0 -33
  25. package/dist/helpers/reducer.d.ts +0 -5
  26. package/dist/helpers/reducer.js +0 -19
  27. package/dist/helpers/shell.d.ts +0 -6
  28. package/dist/helpers/shell.js +0 -20
  29. package/dist/helpers/utils.d.ts +0 -6
  30. package/dist/helpers/utils.js +0 -21
  31. package/dist/targets/c/libcurl/client.d.ts +0 -2
  32. package/dist/targets/c/libcurl/client.js +0 -45
  33. package/dist/targets/c/target.d.ts +0 -2
  34. package/dist/targets/c/target.js +0 -16
  35. package/dist/targets/clojure/clj_http/client.d.ts +0 -11
  36. package/dist/targets/clojure/clj_http/client.js +0 -178
  37. package/dist/targets/clojure/target.d.ts +0 -2
  38. package/dist/targets/clojure/target.js +0 -15
  39. package/dist/targets/csharp/httpclient/client.d.ts +0 -2
  40. package/dist/targets/csharp/httpclient/client.js +0 -163
  41. package/dist/targets/csharp/restsharp/client.d.ts +0 -2
  42. package/dist/targets/csharp/restsharp/client.js +0 -92
  43. package/dist/targets/csharp/target.d.ts +0 -2
  44. package/dist/targets/csharp/target.js +0 -18
  45. package/dist/targets/go/native/client.d.ts +0 -17
  46. package/dist/targets/go/native/client.js +0 -103
  47. package/dist/targets/go/target.d.ts +0 -2
  48. package/dist/targets/go/target.js +0 -16
  49. package/dist/targets/http/http1.1/client.d.ts +0 -23
  50. package/dist/targets/http/http1.1/client.js +0 -69
  51. package/dist/targets/http/target.d.ts +0 -2
  52. package/dist/targets/http/target.js +0 -15
  53. package/dist/targets/java/asynchttp/client.d.ts +0 -11
  54. package/dist/targets/java/asynchttp/client.js +0 -45
  55. package/dist/targets/java/nethttp/client.d.ts +0 -14
  56. package/dist/targets/java/nethttp/client.js +0 -44
  57. package/dist/targets/java/okhttp/client.d.ts +0 -11
  58. package/dist/targets/java/okhttp/client.js +0 -71
  59. package/dist/targets/java/target.d.ts +0 -2
  60. package/dist/targets/java/target.js +0 -21
  61. package/dist/targets/java/unirest/client.d.ts +0 -11
  62. package/dist/targets/java/unirest/client.js +0 -45
  63. package/dist/targets/javascript/axios/client.d.ts +0 -11
  64. package/dist/targets/javascript/axios/client.js +0 -92
  65. package/dist/targets/javascript/axios/fixtures/application-form-encoded.d.ts +0 -1
  66. package/dist/targets/javascript/axios/fixtures/application-form-encoded.js +0 -23
  67. package/dist/targets/javascript/axios/fixtures/application-json.d.ts +0 -1
  68. package/dist/targets/javascript/axios/fixtures/application-json.js +0 -27
  69. package/dist/targets/javascript/axios/fixtures/cookies.d.ts +0 -1
  70. package/dist/targets/javascript/axios/fixtures/cookies.js +0 -19
  71. package/dist/targets/javascript/axios/fixtures/custom-method.d.ts +0 -1
  72. package/dist/targets/javascript/axios/fixtures/custom-method.js +0 -15
  73. package/dist/targets/javascript/axios/fixtures/full.d.ts +0 -1
  74. package/dist/targets/javascript/axios/fixtures/full.js +0 -27
  75. package/dist/targets/javascript/axios/fixtures/headers.d.ts +0 -1
  76. package/dist/targets/javascript/axios/fixtures/headers.js +0 -24
  77. package/dist/targets/javascript/axios/fixtures/http-insecure.d.ts +0 -1
  78. package/dist/targets/javascript/axios/fixtures/http-insecure.js +0 -15
  79. package/dist/targets/javascript/axios/fixtures/jsonObj-multiline.d.ts +0 -1
  80. package/dist/targets/javascript/axios/fixtures/jsonObj-multiline.js +0 -20
  81. package/dist/targets/javascript/axios/fixtures/jsonObj-null-value.d.ts +0 -1
  82. package/dist/targets/javascript/axios/fixtures/jsonObj-null-value.js +0 -20
  83. package/dist/targets/javascript/axios/fixtures/multipart-data.d.ts +0 -1
  84. package/dist/targets/javascript/axios/fixtures/multipart-data.js +0 -23
  85. package/dist/targets/javascript/axios/fixtures/multipart-file.d.ts +0 -1
  86. package/dist/targets/javascript/axios/fixtures/multipart-file.js +0 -22
  87. package/dist/targets/javascript/axios/fixtures/multipart-form-data-no-params.d.ts +0 -1
  88. package/dist/targets/javascript/axios/fixtures/multipart-form-data-no-params.js +0 -19
  89. package/dist/targets/javascript/axios/fixtures/multipart-form-data.d.ts +0 -1
  90. package/dist/targets/javascript/axios/fixtures/multipart-form-data.js +0 -22
  91. package/dist/targets/javascript/axios/fixtures/nested.d.ts +0 -1
  92. package/dist/targets/javascript/axios/fixtures/nested.js +0 -19
  93. package/dist/targets/javascript/axios/fixtures/postdata-malformed.d.ts +0 -1
  94. package/dist/targets/javascript/axios/fixtures/postdata-malformed.js +0 -19
  95. package/dist/targets/javascript/axios/fixtures/query-encoded.d.ts +0 -1
  96. package/dist/targets/javascript/axios/fixtures/query-encoded.js +0 -22
  97. package/dist/targets/javascript/axios/fixtures/query.d.ts +0 -1
  98. package/dist/targets/javascript/axios/fixtures/query.js +0 -19
  99. package/dist/targets/javascript/axios/fixtures/short.d.ts +0 -1
  100. package/dist/targets/javascript/axios/fixtures/short.js +0 -15
  101. package/dist/targets/javascript/axios/fixtures/text-plain.d.ts +0 -1
  102. package/dist/targets/javascript/axios/fixtures/text-plain.js +0 -20
  103. package/dist/targets/javascript/fetch/client.d.ts +0 -15
  104. package/dist/targets/javascript/fetch/client.js +0 -106
  105. package/dist/targets/javascript/fetch/fixtures/application-form-encoded.d.ts +0 -8
  106. package/dist/targets/javascript/fetch/fixtures/application-form-encoded.js +0 -10
  107. package/dist/targets/javascript/fetch/fixtures/application-json.d.ts +0 -7
  108. package/dist/targets/javascript/fetch/fixtures/application-json.js +0 -17
  109. package/dist/targets/javascript/fetch/fixtures/cookies.d.ts +0 -6
  110. package/dist/targets/javascript/fetch/fixtures/cookies.js +0 -6
  111. package/dist/targets/javascript/fetch/fixtures/custom-method.d.ts +0 -3
  112. package/dist/targets/javascript/fetch/fixtures/custom-method.js +0 -6
  113. package/dist/targets/javascript/fetch/fixtures/full.d.ts +0 -10
  114. package/dist/targets/javascript/fetch/fixtures/full.js +0 -14
  115. package/dist/targets/javascript/fetch/fixtures/headers.d.ts +0 -9
  116. package/dist/targets/javascript/fetch/fixtures/headers.js +0 -14
  117. package/dist/targets/javascript/fetch/fixtures/http-insecure.d.ts +0 -3
  118. package/dist/targets/javascript/fetch/fixtures/http-insecure.js +0 -6
  119. package/dist/targets/javascript/fetch/fixtures/jsonObj-multiline.d.ts +0 -7
  120. package/dist/targets/javascript/fetch/fixtures/jsonObj-multiline.js +0 -10
  121. package/dist/targets/javascript/fetch/fixtures/jsonObj-null-value.d.ts +0 -7
  122. package/dist/targets/javascript/fetch/fixtures/jsonObj-null-value.js +0 -10
  123. package/dist/targets/javascript/fetch/fixtures/multipart-data.d.ts +0 -4
  124. package/dist/targets/javascript/fetch/fixtures/multipart-data.js +0 -10
  125. package/dist/targets/javascript/fetch/fixtures/multipart-file.d.ts +0 -4
  126. package/dist/targets/javascript/fetch/fixtures/multipart-file.js +0 -9
  127. package/dist/targets/javascript/fetch/fixtures/multipart-form-data-no-params.d.ts +0 -6
  128. package/dist/targets/javascript/fetch/fixtures/multipart-form-data-no-params.js +0 -6
  129. package/dist/targets/javascript/fetch/fixtures/multipart-form-data.d.ts +0 -4
  130. package/dist/targets/javascript/fetch/fixtures/multipart-form-data.js +0 -9
  131. package/dist/targets/javascript/fetch/fixtures/nested.d.ts +0 -3
  132. package/dist/targets/javascript/fetch/fixtures/nested.js +0 -6
  133. package/dist/targets/javascript/fetch/fixtures/postdata-malformed.d.ts +0 -6
  134. package/dist/targets/javascript/fetch/fixtures/postdata-malformed.js +0 -6
  135. package/dist/targets/javascript/fetch/fixtures/query-encoded.d.ts +0 -3
  136. package/dist/targets/javascript/fetch/fixtures/query-encoded.js +0 -6
  137. package/dist/targets/javascript/fetch/fixtures/query.d.ts +0 -3
  138. package/dist/targets/javascript/fetch/fixtures/query.js +0 -6
  139. package/dist/targets/javascript/fetch/fixtures/short.d.ts +0 -3
  140. package/dist/targets/javascript/fetch/fixtures/short.js +0 -6
  141. package/dist/targets/javascript/fetch/fixtures/text-plain.d.ts +0 -7
  142. package/dist/targets/javascript/fetch/fixtures/text-plain.js +0 -6
  143. package/dist/targets/javascript/jquery/client.d.ts +0 -11
  144. package/dist/targets/javascript/jquery/client.js +0 -84
  145. package/dist/targets/javascript/jquery/fixtures/application-form-encoded.d.ts +0 -13
  146. package/dist/targets/javascript/jquery/fixtures/application-form-encoded.js +0 -17
  147. package/dist/targets/javascript/jquery/fixtures/application-json.d.ts +0 -11
  148. package/dist/targets/javascript/jquery/fixtures/application-json.js +0 -15
  149. package/dist/targets/javascript/jquery/fixtures/cookies.d.ts +0 -9
  150. package/dist/targets/javascript/jquery/fixtures/cookies.js +0 -13
  151. package/dist/targets/javascript/jquery/fixtures/custom-method.d.ts +0 -7
  152. package/dist/targets/javascript/jquery/fixtures/custom-method.js +0 -11
  153. package/dist/targets/javascript/jquery/fixtures/full.d.ts +0 -14
  154. package/dist/targets/javascript/jquery/fixtures/full.js +0 -18
  155. package/dist/targets/javascript/jquery/fixtures/headers.d.ts +0 -12
  156. package/dist/targets/javascript/jquery/fixtures/headers.js +0 -16
  157. package/dist/targets/javascript/jquery/fixtures/http-insecure.d.ts +0 -7
  158. package/dist/targets/javascript/jquery/fixtures/http-insecure.js +0 -11
  159. package/dist/targets/javascript/jquery/fixtures/jsonObj-multiline.d.ts +0 -11
  160. package/dist/targets/javascript/jquery/fixtures/jsonObj-multiline.js +0 -15
  161. package/dist/targets/javascript/jquery/fixtures/jsonObj-null-value.d.ts +0 -11
  162. package/dist/targets/javascript/jquery/fixtures/jsonObj-null-value.js +0 -15
  163. package/dist/targets/javascript/jquery/fixtures/multipart-data.d.ts +0 -12
  164. package/dist/targets/javascript/jquery/fixtures/multipart-data.js +0 -18
  165. package/dist/targets/javascript/jquery/fixtures/multipart-file.d.ts +0 -12
  166. package/dist/targets/javascript/jquery/fixtures/multipart-file.js +0 -17
  167. package/dist/targets/javascript/jquery/fixtures/multipart-form-data-no-params.d.ts +0 -9
  168. package/dist/targets/javascript/jquery/fixtures/multipart-form-data-no-params.js +0 -13
  169. package/dist/targets/javascript/jquery/fixtures/multipart-form-data.d.ts +0 -12
  170. package/dist/targets/javascript/jquery/fixtures/multipart-form-data.js +0 -17
  171. package/dist/targets/javascript/jquery/fixtures/nested.d.ts +0 -7
  172. package/dist/targets/javascript/jquery/fixtures/nested.js +0 -11
  173. package/dist/targets/javascript/jquery/fixtures/postdata-malformed.d.ts +0 -9
  174. package/dist/targets/javascript/jquery/fixtures/postdata-malformed.js +0 -13
  175. package/dist/targets/javascript/jquery/fixtures/query-encoded.d.ts +0 -7
  176. package/dist/targets/javascript/jquery/fixtures/query-encoded.js +0 -11
  177. package/dist/targets/javascript/jquery/fixtures/query.d.ts +0 -7
  178. package/dist/targets/javascript/jquery/fixtures/query.js +0 -11
  179. package/dist/targets/javascript/jquery/fixtures/short.d.ts +0 -7
  180. package/dist/targets/javascript/jquery/fixtures/short.js +0 -11
  181. package/dist/targets/javascript/jquery/fixtures/text-plain.d.ts +0 -10
  182. package/dist/targets/javascript/jquery/fixtures/text-plain.js +0 -14
  183. package/dist/targets/javascript/target.d.ts +0 -2
  184. package/dist/targets/javascript/target.js +0 -21
  185. package/dist/targets/javascript/xhr/client.d.ts +0 -14
  186. package/dist/targets/javascript/xhr/client.js +0 -83
  187. package/dist/targets/javascript/xhr/fixtures/application-form-encoded.d.ts +0 -2
  188. package/dist/targets/javascript/xhr/fixtures/application-form-encoded.js +0 -12
  189. package/dist/targets/javascript/xhr/fixtures/application-json.d.ts +0 -2
  190. package/dist/targets/javascript/xhr/fixtures/application-json.js +0 -31
  191. package/dist/targets/javascript/xhr/fixtures/cookies.d.ts +0 -2
  192. package/dist/targets/javascript/xhr/fixtures/cookies.js +0 -12
  193. package/dist/targets/javascript/xhr/fixtures/cors.d.ts +0 -2
  194. package/dist/targets/javascript/xhr/fixtures/cors.js +0 -10
  195. package/dist/targets/javascript/xhr/fixtures/custom-method.d.ts +0 -2
  196. package/dist/targets/javascript/xhr/fixtures/custom-method.js +0 -11
  197. package/dist/targets/javascript/xhr/fixtures/full.d.ts +0 -2
  198. package/dist/targets/javascript/xhr/fixtures/full.js +0 -14
  199. package/dist/targets/javascript/xhr/fixtures/headers.d.ts +0 -2
  200. package/dist/targets/javascript/xhr/fixtures/headers.js +0 -15
  201. package/dist/targets/javascript/xhr/fixtures/http-insecure.d.ts +0 -2
  202. package/dist/targets/javascript/xhr/fixtures/http-insecure.js +0 -11
  203. package/dist/targets/javascript/xhr/fixtures/jsonObj-multiline.d.ts +0 -2
  204. package/dist/targets/javascript/xhr/fixtures/jsonObj-multiline.js +0 -14
  205. package/dist/targets/javascript/xhr/fixtures/jsonObj-null-value.d.ts +0 -2
  206. package/dist/targets/javascript/xhr/fixtures/jsonObj-null-value.js +0 -14
  207. package/dist/targets/javascript/xhr/fixtures/multipart-data.d.ts +0 -2
  208. package/dist/targets/javascript/xhr/fixtures/multipart-data.js +0 -13
  209. package/dist/targets/javascript/xhr/fixtures/multipart-file.d.ts +0 -2
  210. package/dist/targets/javascript/xhr/fixtures/multipart-file.js +0 -12
  211. package/dist/targets/javascript/xhr/fixtures/multipart-form-data-no-params.d.ts +0 -1
  212. package/dist/targets/javascript/xhr/fixtures/multipart-form-data-no-params.js +0 -11
  213. package/dist/targets/javascript/xhr/fixtures/multipart-form-data.d.ts +0 -2
  214. package/dist/targets/javascript/xhr/fixtures/multipart-form-data.js +0 -12
  215. package/dist/targets/javascript/xhr/fixtures/nested.d.ts +0 -2
  216. package/dist/targets/javascript/xhr/fixtures/nested.js +0 -11
  217. package/dist/targets/javascript/xhr/fixtures/postdata-malformed.d.ts +0 -2
  218. package/dist/targets/javascript/xhr/fixtures/postdata-malformed.js +0 -12
  219. package/dist/targets/javascript/xhr/fixtures/query-encoded.d.ts +0 -2
  220. package/dist/targets/javascript/xhr/fixtures/query-encoded.js +0 -11
  221. package/dist/targets/javascript/xhr/fixtures/query.d.ts +0 -2
  222. package/dist/targets/javascript/xhr/fixtures/query.js +0 -11
  223. package/dist/targets/javascript/xhr/fixtures/short.d.ts +0 -2
  224. package/dist/targets/javascript/xhr/fixtures/short.js +0 -11
  225. package/dist/targets/javascript/xhr/fixtures/text-plain.d.ts +0 -2
  226. package/dist/targets/javascript/xhr/fixtures/text-plain.js +0 -12
  227. package/dist/targets/json/native/client.d.ts +0 -2
  228. package/dist/targets/json/native/client.js +0 -56
  229. package/dist/targets/json/target.d.ts +0 -2
  230. package/dist/targets/json/target.js +0 -15
  231. package/dist/targets/kotlin/okhttp/client.d.ts +0 -11
  232. package/dist/targets/kotlin/okhttp/client.js +0 -71
  233. package/dist/targets/kotlin/target.d.ts +0 -2
  234. package/dist/targets/kotlin/target.js +0 -15
  235. package/dist/targets/node/axios/client.d.ts +0 -11
  236. package/dist/targets/node/axios/client.js +0 -78
  237. package/dist/targets/node/axios/fixtures/application-form-encoded.d.ts +0 -1
  238. package/dist/targets/node/axios/fixtures/application-form-encoded.js +0 -20
  239. package/dist/targets/node/axios/fixtures/application-json.d.ts +0 -1
  240. package/dist/targets/node/axios/fixtures/application-json.js +0 -23
  241. package/dist/targets/node/axios/fixtures/cookies.d.ts +0 -1
  242. package/dist/targets/node/axios/fixtures/cookies.js +0 -15
  243. package/dist/targets/node/axios/fixtures/custom-method.d.ts +0 -1
  244. package/dist/targets/node/axios/fixtures/custom-method.js +0 -11
  245. package/dist/targets/node/axios/fixtures/full.d.ts +0 -1
  246. package/dist/targets/node/axios/fixtures/full.js +0 -23
  247. package/dist/targets/node/axios/fixtures/headers.d.ts +0 -1
  248. package/dist/targets/node/axios/fixtures/headers.js +0 -20
  249. package/dist/targets/node/axios/fixtures/http-insecure.d.ts +0 -1
  250. package/dist/targets/node/axios/fixtures/http-insecure.js +0 -11
  251. package/dist/targets/node/axios/fixtures/jsonObj-multiline.d.ts +0 -1
  252. package/dist/targets/node/axios/fixtures/jsonObj-multiline.js +0 -16
  253. package/dist/targets/node/axios/fixtures/jsonObj-null-value.d.ts +0 -1
  254. package/dist/targets/node/axios/fixtures/jsonObj-null-value.js +0 -16
  255. package/dist/targets/node/axios/fixtures/multipart-data.d.ts +0 -1
  256. package/dist/targets/node/axios/fixtures/multipart-data.js +0 -16
  257. package/dist/targets/node/axios/fixtures/multipart-file.d.ts +0 -1
  258. package/dist/targets/node/axios/fixtures/multipart-file.js +0 -16
  259. package/dist/targets/node/axios/fixtures/multipart-form-data-no-params.d.ts +0 -1
  260. package/dist/targets/node/axios/fixtures/multipart-form-data-no-params.js +0 -15
  261. package/dist/targets/node/axios/fixtures/multipart-form-data.d.ts +0 -1
  262. package/dist/targets/node/axios/fixtures/multipart-form-data.js +0 -16
  263. package/dist/targets/node/axios/fixtures/nested.d.ts +0 -1
  264. package/dist/targets/node/axios/fixtures/nested.js +0 -14
  265. package/dist/targets/node/axios/fixtures/postdata-malformed.d.ts +0 -1
  266. package/dist/targets/node/axios/fixtures/postdata-malformed.js +0 -15
  267. package/dist/targets/node/axios/fixtures/query-encoded.d.ts +0 -1
  268. package/dist/targets/node/axios/fixtures/query-encoded.js +0 -14
  269. package/dist/targets/node/axios/fixtures/query.d.ts +0 -1
  270. package/dist/targets/node/axios/fixtures/query.js +0 -14
  271. package/dist/targets/node/axios/fixtures/short.d.ts +0 -1
  272. package/dist/targets/node/axios/fixtures/short.js +0 -11
  273. package/dist/targets/node/axios/fixtures/text-plain.d.ts +0 -1
  274. package/dist/targets/node/axios/fixtures/text-plain.js +0 -16
  275. package/dist/targets/node/fetch/client.d.ts +0 -11
  276. package/dist/targets/node/fetch/client.js +0 -140
  277. package/dist/targets/node/fetch/fixtures/application-form-encoded.d.ts +0 -1
  278. package/dist/targets/node/fetch/fixtures/application-form-encoded.js +0 -16
  279. package/dist/targets/node/fetch/fixtures/application-json.d.ts +0 -1
  280. package/dist/targets/node/fetch/fixtures/application-json.js +0 -19
  281. package/dist/targets/node/fetch/fixtures/cookies.d.ts +0 -1
  282. package/dist/targets/node/fetch/fixtures/cookies.js +0 -8
  283. package/dist/targets/node/fetch/fixtures/custom-method.d.ts +0 -1
  284. package/dist/targets/node/fetch/fixtures/custom-method.js +0 -8
  285. package/dist/targets/node/fetch/fixtures/full.d.ts +0 -1
  286. package/dist/targets/node/fetch/fixtures/full.js +0 -19
  287. package/dist/targets/node/fetch/fixtures/headers.d.ts +0 -1
  288. package/dist/targets/node/fetch/fixtures/headers.js +0 -16
  289. package/dist/targets/node/fetch/fixtures/http-insecure.d.ts +0 -1
  290. package/dist/targets/node/fetch/fixtures/http-insecure.js +0 -8
  291. package/dist/targets/node/fetch/fixtures/jsonObj-multiline.d.ts +0 -1
  292. package/dist/targets/node/fetch/fixtures/jsonObj-multiline.js +0 -12
  293. package/dist/targets/node/fetch/fixtures/jsonObj-null-value.d.ts +0 -1
  294. package/dist/targets/node/fetch/fixtures/jsonObj-null-value.js +0 -12
  295. package/dist/targets/node/fetch/fixtures/multipart-data.d.ts +0 -1
  296. package/dist/targets/node/fetch/fixtures/multipart-data.js +0 -14
  297. package/dist/targets/node/fetch/fixtures/multipart-file.d.ts +0 -1
  298. package/dist/targets/node/fetch/fixtures/multipart-file.js +0 -13
  299. package/dist/targets/node/fetch/fixtures/multipart-form-data-no-params.d.ts +0 -1
  300. package/dist/targets/node/fetch/fixtures/multipart-form-data-no-params.js +0 -8
  301. package/dist/targets/node/fetch/fixtures/multipart-form-data.d.ts +0 -1
  302. package/dist/targets/node/fetch/fixtures/multipart-form-data.js +0 -12
  303. package/dist/targets/node/fetch/fixtures/nested.d.ts +0 -1
  304. package/dist/targets/node/fetch/fixtures/nested.js +0 -8
  305. package/dist/targets/node/fetch/fixtures/postdata-malformed.d.ts +0 -1
  306. package/dist/targets/node/fetch/fixtures/postdata-malformed.js +0 -8
  307. package/dist/targets/node/fetch/fixtures/query-encoded.d.ts +0 -1
  308. package/dist/targets/node/fetch/fixtures/query-encoded.js +0 -8
  309. package/dist/targets/node/fetch/fixtures/query.d.ts +0 -1
  310. package/dist/targets/node/fetch/fixtures/query.js +0 -8
  311. package/dist/targets/node/fetch/fixtures/short.d.ts +0 -1
  312. package/dist/targets/node/fetch/fixtures/short.js +0 -8
  313. package/dist/targets/node/fetch/fixtures/text-plain.d.ts +0 -1
  314. package/dist/targets/node/fetch/fixtures/text-plain.js +0 -8
  315. package/dist/targets/node/native/client.d.ts +0 -11
  316. package/dist/targets/node/native/client.js +0 -72
  317. package/dist/targets/node/native/fixtures/application-form-encoded.d.ts +0 -1
  318. package/dist/targets/node/native/fixtures/application-form-encoded.js +0 -24
  319. package/dist/targets/node/native/fixtures/application-json.d.ts +0 -1
  320. package/dist/targets/node/native/fixtures/application-json.js +0 -30
  321. package/dist/targets/node/native/fixtures/cookies.d.ts +0 -1
  322. package/dist/targets/node/native/fixtures/cookies.js +0 -22
  323. package/dist/targets/node/native/fixtures/custom-method.d.ts +0 -1
  324. package/dist/targets/node/native/fixtures/custom-method.js +0 -20
  325. package/dist/targets/node/native/fixtures/full.d.ts +0 -1
  326. package/dist/targets/node/native/fixtures/full.js +0 -26
  327. package/dist/targets/node/native/fixtures/headers.d.ts +0 -1
  328. package/dist/targets/node/native/fixtures/headers.js +0 -25
  329. package/dist/targets/node/native/fixtures/http-insecure.d.ts +0 -1
  330. package/dist/targets/node/native/fixtures/http-insecure.js +0 -20
  331. package/dist/targets/node/native/fixtures/jsonObj-multiline.d.ts +0 -1
  332. package/dist/targets/node/native/fixtures/jsonObj-multiline.js +0 -23
  333. package/dist/targets/node/native/fixtures/jsonObj-null-value.d.ts +0 -1
  334. package/dist/targets/node/native/fixtures/jsonObj-null-value.js +0 -23
  335. package/dist/targets/node/native/fixtures/multipart-data.d.ts +0 -1
  336. package/dist/targets/node/native/fixtures/multipart-data.js +0 -23
  337. package/dist/targets/node/native/fixtures/multipart-file.d.ts +0 -1
  338. package/dist/targets/node/native/fixtures/multipart-file.js +0 -23
  339. package/dist/targets/node/native/fixtures/multipart-form-data-no-params.d.ts +0 -1
  340. package/dist/targets/node/native/fixtures/multipart-form-data-no-params.js +0 -22
  341. package/dist/targets/node/native/fixtures/multipart-form-data.d.ts +0 -1
  342. package/dist/targets/node/native/fixtures/multipart-form-data.js +0 -23
  343. package/dist/targets/node/native/fixtures/nested.d.ts +0 -1
  344. package/dist/targets/node/native/fixtures/nested.js +0 -20
  345. package/dist/targets/node/native/fixtures/postdata-malformed.d.ts +0 -1
  346. package/dist/targets/node/native/fixtures/postdata-malformed.js +0 -22
  347. package/dist/targets/node/native/fixtures/query-encoded.d.ts +0 -1
  348. package/dist/targets/node/native/fixtures/query-encoded.js +0 -20
  349. package/dist/targets/node/native/fixtures/query.d.ts +0 -1
  350. package/dist/targets/node/native/fixtures/query.js +0 -20
  351. package/dist/targets/node/native/fixtures/short.d.ts +0 -1
  352. package/dist/targets/node/native/fixtures/short.js +0 -20
  353. package/dist/targets/node/native/fixtures/text-plain.d.ts +0 -1
  354. package/dist/targets/node/native/fixtures/text-plain.js +0 -23
  355. package/dist/targets/node/request/client.d.ts +0 -11
  356. package/dist/targets/node/request/client.js +0 -107
  357. package/dist/targets/node/request/fixtures/application-form-encoded.d.ts +0 -1
  358. package/dist/targets/node/request/fixtures/application-form-encoded.js +0 -13
  359. package/dist/targets/node/request/fixtures/application-json.d.ts +0 -1
  360. package/dist/targets/node/request/fixtures/application-json.js +0 -21
  361. package/dist/targets/node/request/fixtures/cookies.d.ts +0 -1
  362. package/dist/targets/node/request/fixtures/cookies.js +0 -11
  363. package/dist/targets/node/request/fixtures/custom-method.d.ts +0 -1
  364. package/dist/targets/node/request/fixtures/custom-method.js +0 -8
  365. package/dist/targets/node/request/fixtures/full.d.ts +0 -1
  366. package/dist/targets/node/request/fixtures/full.js +0 -20
  367. package/dist/targets/node/request/fixtures/headers.d.ts +0 -1
  368. package/dist/targets/node/request/fixtures/headers.js +0 -17
  369. package/dist/targets/node/request/fixtures/http-insecure.d.ts +0 -1
  370. package/dist/targets/node/request/fixtures/http-insecure.js +0 -8
  371. package/dist/targets/node/request/fixtures/jsonObj-multiline.d.ts +0 -1
  372. package/dist/targets/node/request/fixtures/jsonObj-multiline.js +0 -14
  373. package/dist/targets/node/request/fixtures/jsonObj-null-value.d.ts +0 -1
  374. package/dist/targets/node/request/fixtures/jsonObj-null-value.js +0 -14
  375. package/dist/targets/node/request/fixtures/multipart-data.d.ts +0 -1
  376. package/dist/targets/node/request/fixtures/multipart-data.js +0 -20
  377. package/dist/targets/node/request/fixtures/multipart-file.d.ts +0 -1
  378. package/dist/targets/node/request/fixtures/multipart-file.js +0 -19
  379. package/dist/targets/node/request/fixtures/multipart-form-data-no-params.d.ts +0 -1
  380. package/dist/targets/node/request/fixtures/multipart-form-data-no-params.js +0 -12
  381. package/dist/targets/node/request/fixtures/multipart-form-data.d.ts +0 -1
  382. package/dist/targets/node/request/fixtures/multipart-form-data.js +0 -13
  383. package/dist/targets/node/request/fixtures/nested.d.ts +0 -1
  384. package/dist/targets/node/request/fixtures/nested.js +0 -11
  385. package/dist/targets/node/request/fixtures/postdata-malformed.d.ts +0 -1
  386. package/dist/targets/node/request/fixtures/postdata-malformed.js +0 -12
  387. package/dist/targets/node/request/fixtures/query-encoded.d.ts +0 -1
  388. package/dist/targets/node/request/fixtures/query-encoded.js +0 -11
  389. package/dist/targets/node/request/fixtures/query.d.ts +0 -1
  390. package/dist/targets/node/request/fixtures/query.js +0 -11
  391. package/dist/targets/node/request/fixtures/short.d.ts +0 -1
  392. package/dist/targets/node/request/fixtures/short.js +0 -8
  393. package/dist/targets/node/request/fixtures/text-plain.d.ts +0 -1
  394. package/dist/targets/node/request/fixtures/text-plain.js +0 -13
  395. package/dist/targets/node/target.d.ts +0 -2
  396. package/dist/targets/node/target.js +0 -24
  397. package/dist/targets/node/unirest/client.d.ts +0 -11
  398. package/dist/targets/node/unirest/client.js +0 -110
  399. package/dist/targets/node/unirest/fixtures/application-form-encoded.d.ts +0 -1
  400. package/dist/targets/node/unirest/fixtures/application-form-encoded.js +0 -15
  401. package/dist/targets/node/unirest/fixtures/application-json.d.ts +0 -1
  402. package/dist/targets/node/unirest/fixtures/application-json.js +0 -32
  403. package/dist/targets/node/unirest/fixtures/cookies.d.ts +0 -1
  404. package/dist/targets/node/unirest/fixtures/cookies.js +0 -12
  405. package/dist/targets/node/unirest/fixtures/custom-method.d.ts +0 -1
  406. package/dist/targets/node/unirest/fixtures/custom-method.js +0 -8
  407. package/dist/targets/node/unirest/fixtures/full.d.ts +0 -1
  408. package/dist/targets/node/unirest/fixtures/full.js +0 -27
  409. package/dist/targets/node/unirest/fixtures/headers.d.ts +0 -1
  410. package/dist/targets/node/unirest/fixtures/headers.js +0 -14
  411. package/dist/targets/node/unirest/fixtures/http-insecure.d.ts +0 -1
  412. package/dist/targets/node/unirest/fixtures/http-insecure.js +0 -8
  413. package/dist/targets/node/unirest/fixtures/jsonObj-multiline.d.ts +0 -1
  414. package/dist/targets/node/unirest/fixtures/jsonObj-multiline.js +0 -15
  415. package/dist/targets/node/unirest/fixtures/jsonObj-null-value.d.ts +0 -1
  416. package/dist/targets/node/unirest/fixtures/jsonObj-null-value.js +0 -15
  417. package/dist/targets/node/unirest/fixtures/multipart-data.d.ts +0 -1
  418. package/dist/targets/node/unirest/fixtures/multipart-data.js +0 -20
  419. package/dist/targets/node/unirest/fixtures/multipart-file.d.ts +0 -1
  420. package/dist/targets/node/unirest/fixtures/multipart-file.js +0 -18
  421. package/dist/targets/node/unirest/fixtures/multipart-form-data-no-params.d.ts +0 -1
  422. package/dist/targets/node/unirest/fixtures/multipart-form-data-no-params.js +0 -11
  423. package/dist/targets/node/unirest/fixtures/multipart-form-data.d.ts +0 -1
  424. package/dist/targets/node/unirest/fixtures/multipart-form-data.js +0 -16
  425. package/dist/targets/node/unirest/fixtures/nested.d.ts +0 -1
  426. package/dist/targets/node/unirest/fixtures/nested.js +0 -13
  427. package/dist/targets/node/unirest/fixtures/postdata-malformed.d.ts +0 -1
  428. package/dist/targets/node/unirest/fixtures/postdata-malformed.js +0 -11
  429. package/dist/targets/node/unirest/fixtures/query-encoded.d.ts +0 -1
  430. package/dist/targets/node/unirest/fixtures/query-encoded.js +0 -12
  431. package/dist/targets/node/unirest/fixtures/query.d.ts +0 -1
  432. package/dist/targets/node/unirest/fixtures/query.js +0 -16
  433. package/dist/targets/node/unirest/fixtures/short.d.ts +0 -1
  434. package/dist/targets/node/unirest/fixtures/short.js +0 -8
  435. package/dist/targets/node/unirest/fixtures/text-plain.d.ts +0 -1
  436. package/dist/targets/node/unirest/fixtures/text-plain.js +0 -12
  437. package/dist/targets/objc/helpers.d.ts +0 -26
  438. package/dist/targets/objc/helpers.js +0 -59
  439. package/dist/targets/objc/nsurlsession/client.d.ts +0 -15
  440. package/dist/targets/objc/nsurlsession/client.js +0 -143
  441. package/dist/targets/objc/target.d.ts +0 -2
  442. package/dist/targets/objc/target.js +0 -15
  443. package/dist/targets/ocaml/cohttp/client.d.ts +0 -11
  444. package/dist/targets/ocaml/cohttp/client.js +0 -64
  445. package/dist/targets/ocaml/target.d.ts +0 -2
  446. package/dist/targets/ocaml/target.js +0 -15
  447. package/dist/targets/php/curl/client.d.ts +0 -19
  448. package/dist/targets/php/curl/client.js +0 -122
  449. package/dist/targets/php/guzzle/client.d.ts +0 -17
  450. package/dist/targets/php/guzzle/client.js +0 -119
  451. package/dist/targets/php/helpers.d.ts +0 -2
  452. package/dist/targets/php/helpers.js +0 -66
  453. package/dist/targets/php/http1/client.d.ts +0 -16
  454. package/dist/targets/php/http1/client.js +0 -76
  455. package/dist/targets/php/http2/client.d.ts +0 -16
  456. package/dist/targets/php/http2/client.js +0 -115
  457. package/dist/targets/php/target.d.ts +0 -2
  458. package/dist/targets/php/target.js +0 -22
  459. package/dist/targets/powershell/common.d.ts +0 -3
  460. package/dist/targets/powershell/common.js +0 -50
  461. package/dist/targets/powershell/restmethod/client.d.ts +0 -2
  462. package/dist/targets/powershell/restmethod/client.js +0 -13
  463. package/dist/targets/powershell/target.d.ts +0 -2
  464. package/dist/targets/powershell/target.js +0 -17
  465. package/dist/targets/powershell/webrequest/client.d.ts +0 -2
  466. package/dist/targets/powershell/webrequest/client.js +0 -13
  467. package/dist/targets/python/helpers.d.ts +0 -8
  468. package/dist/targets/python/helpers.js +0 -64
  469. package/dist/targets/python/requests/client.d.ts +0 -14
  470. package/dist/targets/python/requests/client.js +0 -162
  471. package/dist/targets/python/target.d.ts +0 -2
  472. package/dist/targets/python/target.js +0 -16
  473. package/dist/targets/r/httr/client.d.ts +0 -11
  474. package/dist/targets/r/httr/client.js +0 -130
  475. package/dist/targets/r/target.d.ts +0 -2
  476. package/dist/targets/r/target.js +0 -15
  477. package/dist/targets/ruby/native/client.d.ts +0 -2
  478. package/dist/targets/ruby/native/client.js +0 -67
  479. package/dist/targets/ruby/target.d.ts +0 -2
  480. package/dist/targets/ruby/target.js +0 -15
  481. package/dist/targets/shell/curl/client.d.ts +0 -19
  482. package/dist/targets/shell/curl/client.js +0 -166
  483. package/dist/targets/shell/httpie/client.d.ts +0 -24
  484. package/dist/targets/shell/httpie/client.js +0 -102
  485. package/dist/targets/shell/target.d.ts +0 -2
  486. package/dist/targets/shell/target.js +0 -20
  487. package/dist/targets/shell/wget/client.d.ts +0 -16
  488. package/dist/targets/shell/wget/client.js +0 -46
  489. package/dist/targets/swift/helpers.d.ts +0 -16
  490. package/dist/targets/swift/helpers.js +0 -80
  491. package/dist/targets/swift/nsurlsession/client.d.ts +0 -15
  492. package/dist/targets/swift/nsurlsession/client.js +0 -148
  493. package/dist/targets/swift/target.d.ts +0 -2
  494. package/dist/targets/swift/target.js +0 -15
@@ -0,0 +1,3485 @@
1
+ import stringifyObject9 from 'stringify-object';
2
+
3
+ // src/helpers/code-builder.ts
4
+ var DEFAULT_INDENTATION_CHARACTER = "";
5
+ var DEFAULT_LINE_JOIN = "\n";
6
+ var CodeBuilder = class {
7
+ /**
8
+ * Helper object to format and aggragate lines of code.
9
+ * Lines are aggregated in a `code` array, and need to be joined to obtain a proper code snippet.
10
+ */
11
+ constructor({ indent, join } = {}) {
12
+ this.postProcessors = [];
13
+ this.code = [];
14
+ this.indentationCharacter = DEFAULT_INDENTATION_CHARACTER;
15
+ this.lineJoin = DEFAULT_LINE_JOIN;
16
+ /**
17
+ * Add given indentation level to given line of code
18
+ */
19
+ this.indentLine = (line, indentationLevel = 0) => {
20
+ const indent = this.indentationCharacter.repeat(indentationLevel);
21
+ return `${indent}${line}`;
22
+ };
23
+ /**
24
+ * Add the line at the beginning of the current lines
25
+ */
26
+ this.unshift = (line, indentationLevel) => {
27
+ const newLine = this.indentLine(line, indentationLevel);
28
+ this.code.unshift(newLine);
29
+ };
30
+ /**
31
+ * Add the line at the end of the current lines
32
+ */
33
+ this.push = (line, indentationLevel) => {
34
+ const newLine = this.indentLine(line, indentationLevel);
35
+ this.code.push(newLine);
36
+ };
37
+ /**
38
+ * Add an empty line at the end of current lines
39
+ */
40
+ this.blank = () => {
41
+ this.code.push("");
42
+ };
43
+ /**
44
+ * Concatenate all current lines using the given lineJoin, then apply any replacers that may have been added
45
+ */
46
+ this.join = () => {
47
+ const unreplacedCode = this.code.join(this.lineJoin);
48
+ const replacedOutput = this.postProcessors.reduce((accumulator, replacer) => replacer(accumulator), unreplacedCode);
49
+ return replacedOutput;
50
+ };
51
+ /**
52
+ * Often when writing modules you may wish to add a literal tag or bit of metadata that you wish to transform after other processing as a final step.
53
+ * To do so, you can provide a PostProcessor function and it will be run automatically for you when you call `join()` later on.
54
+ */
55
+ this.addPostProcessor = (postProcessor) => {
56
+ this.postProcessors = [...this.postProcessors, postProcessor];
57
+ };
58
+ this.indentationCharacter = indent || DEFAULT_INDENTATION_CHARACTER;
59
+ this.lineJoin = join ?? DEFAULT_LINE_JOIN;
60
+ }
61
+ };
62
+
63
+ // src/helpers/escape.ts
64
+ function escapeString(rawValue, options = {}) {
65
+ const { delimiter = '"', escapeChar = "\\", escapeNewlines = true } = options;
66
+ const stringValue = rawValue.toString();
67
+ return [...stringValue].map((c2) => {
68
+ if (c2 === "\b") {
69
+ return `${escapeChar}b`;
70
+ } else if (c2 === " ") {
71
+ return `${escapeChar}t`;
72
+ } else if (c2 === "\n") {
73
+ if (escapeNewlines) {
74
+ return `${escapeChar}n`;
75
+ }
76
+ return c2;
77
+ } else if (c2 === "\f") {
78
+ return `${escapeChar}f`;
79
+ } else if (c2 === "\r") {
80
+ if (escapeNewlines) {
81
+ return `${escapeChar}r`;
82
+ }
83
+ return c2;
84
+ } else if (c2 === escapeChar) {
85
+ return escapeChar + escapeChar;
86
+ } else if (c2 === delimiter) {
87
+ return escapeChar + delimiter;
88
+ } else if (c2 < " " || c2 > "~") {
89
+ return JSON.stringify(c2).slice(1, -1);
90
+ }
91
+ return c2;
92
+ }).join("");
93
+ }
94
+ var escapeForSingleQuotes = (value) => escapeString(value, { delimiter: "'" });
95
+ var escapeForDoubleQuotes = (value) => escapeString(value, { delimiter: '"' });
96
+
97
+ // src/targets/c/libcurl/client.ts
98
+ var libcurl = {
99
+ info: {
100
+ key: "libcurl",
101
+ title: "Libcurl",
102
+ link: "http://curl.haxx.se/libcurl",
103
+ description: "Simple REST and HTTP API Client for C"
104
+ },
105
+ convert: ({ method, fullUrl, headersObj, allHeaders, postData }) => {
106
+ const { push, blank, join } = new CodeBuilder();
107
+ push("CURL *hnd = curl_easy_init();");
108
+ blank();
109
+ push(`curl_easy_setopt(hnd, CURLOPT_CUSTOMREQUEST, "${method.toUpperCase()}");`);
110
+ push("curl_easy_setopt(hnd, CURLOPT_WRITEDATA, stdout);");
111
+ push(`curl_easy_setopt(hnd, CURLOPT_URL, "${fullUrl}");`);
112
+ const headers = Object.keys(headersObj);
113
+ if (headers.length) {
114
+ blank();
115
+ push("struct curl_slist *headers = NULL;");
116
+ headers.forEach((header) => {
117
+ push(`headers = curl_slist_append(headers, "${header}: ${escapeForDoubleQuotes(headersObj[header])}");`);
118
+ });
119
+ push("curl_easy_setopt(hnd, CURLOPT_HTTPHEADER, headers);");
120
+ }
121
+ if (allHeaders.cookie) {
122
+ blank();
123
+ push(`curl_easy_setopt(hnd, CURLOPT_COOKIE, "${allHeaders.cookie}");`);
124
+ }
125
+ if (postData.text) {
126
+ blank();
127
+ push(`curl_easy_setopt(hnd, CURLOPT_POSTFIELDS, ${JSON.stringify(postData.text)});`);
128
+ }
129
+ blank();
130
+ push("CURLcode ret = curl_easy_perform(hnd);");
131
+ return join();
132
+ }
133
+ };
134
+
135
+ // src/targets/c/target.ts
136
+ var c = {
137
+ info: {
138
+ key: "c",
139
+ title: "C",
140
+ extname: ".c",
141
+ default: "libcurl",
142
+ cli: "c"
143
+ },
144
+ clientsById: {
145
+ libcurl
146
+ }
147
+ };
148
+
149
+ // src/helpers/headers.ts
150
+ var getHeaderName = (headers, name) => Object.keys(headers).find((header) => header.toLowerCase() === name.toLowerCase());
151
+ var getHeader = (headers, name) => {
152
+ const headerName = getHeaderName(headers, name);
153
+ if (!headerName) {
154
+ return void 0;
155
+ }
156
+ return headers[headerName];
157
+ };
158
+ var hasHeader = (headers, name) => Boolean(getHeaderName(headers, name));
159
+ var isMimeTypeJSON = (mimeType) => ["application/json", "application/x-json", "text/json", "text/x-json", "+json"].some(
160
+ (type) => mimeType.indexOf(type) > -1
161
+ );
162
+
163
+ // src/targets/clojure/clj_http/client.ts
164
+ var Keyword = class {
165
+ constructor(name) {
166
+ this.name = "";
167
+ this.toString = () => `:${this.name}`;
168
+ this.name = name;
169
+ }
170
+ };
171
+ var File = class {
172
+ constructor(path) {
173
+ this.path = "";
174
+ this.toString = () => `(clojure.java.io/file "${this.path}")`;
175
+ this.path = path;
176
+ }
177
+ };
178
+ var jsType = (input) => {
179
+ if (input === void 0) {
180
+ return null;
181
+ }
182
+ if (input === null) {
183
+ return "null";
184
+ }
185
+ return input.constructor.name.toLowerCase();
186
+ };
187
+ var objEmpty = (input) => {
188
+ if (input === void 0) {
189
+ return true;
190
+ } else if (jsType(input) === "object") {
191
+ return Object.keys(input).length === 0;
192
+ }
193
+ return false;
194
+ };
195
+ var filterEmpty = (input) => {
196
+ Object.keys(input).filter((x) => objEmpty(input[x])).forEach((x) => {
197
+ delete input[x];
198
+ });
199
+ return input;
200
+ };
201
+ var padBlock = (padSize, input) => {
202
+ const padding = " ".repeat(padSize);
203
+ return input.replace(/\n/g, `
204
+ ${padding}`);
205
+ };
206
+ var jsToEdn = (js) => {
207
+ switch (jsType(js)) {
208
+ case "string":
209
+ return `"${js.replace(/"/g, '\\"')}"`;
210
+ case "file":
211
+ return js.toString();
212
+ case "keyword":
213
+ return js.toString();
214
+ case "null":
215
+ return "nil";
216
+ case "regexp":
217
+ return `#"${js.source}"`;
218
+ case "object": {
219
+ const obj = Object.keys(js).reduce((accumulator, key) => {
220
+ const val = padBlock(key.length + 2, jsToEdn(js[key]));
221
+ return `${accumulator}:${key} ${val}
222
+ `;
223
+ }, "").trim();
224
+ return `{${padBlock(1, obj)}}`;
225
+ }
226
+ case "array": {
227
+ const arr = js.reduce((accumulator, value) => `${accumulator} ${jsToEdn(value)}`, "").trim();
228
+ return `[${padBlock(1, arr)}]`;
229
+ }
230
+ default:
231
+ return js.toString();
232
+ }
233
+ };
234
+ var clj_http = {
235
+ info: {
236
+ key: "clj_http",
237
+ title: "clj-http",
238
+ link: "https://github.com/dakrone/clj-http",
239
+ description: "An idiomatic clojure http client wrapping the apache client."
240
+ },
241
+ convert: ({ queryObj, method, postData, url, allHeaders }, options) => {
242
+ const { push, join } = new CodeBuilder({ indent: options?.indent });
243
+ const methods = ["get", "post", "put", "delete", "patch", "head", "options"];
244
+ method = method.toLowerCase();
245
+ if (!methods.includes(method)) {
246
+ push("Method not supported");
247
+ return join();
248
+ }
249
+ const params2 = {
250
+ headers: allHeaders,
251
+ "query-params": queryObj
252
+ };
253
+ switch (postData.mimeType) {
254
+ case "application/json":
255
+ {
256
+ params2["content-type"] = new Keyword("json");
257
+ params2["form-params"] = postData.jsonObj;
258
+ const header = getHeaderName(params2.headers, "content-type");
259
+ if (header) {
260
+ delete params2.headers[header];
261
+ }
262
+ }
263
+ break;
264
+ case "application/x-www-form-urlencoded":
265
+ {
266
+ params2["form-params"] = postData.paramsObj;
267
+ const header = getHeaderName(params2.headers, "content-type");
268
+ if (header) {
269
+ delete params2.headers[header];
270
+ }
271
+ }
272
+ break;
273
+ case "text/plain":
274
+ {
275
+ params2.body = postData.text;
276
+ const header = getHeaderName(params2.headers, "content-type");
277
+ if (header) {
278
+ delete params2.headers[header];
279
+ }
280
+ }
281
+ break;
282
+ case "multipart/form-data": {
283
+ if (postData.params) {
284
+ params2.multipart = postData.params.map((param) => {
285
+ if (param.fileName && !param.value) {
286
+ return {
287
+ name: param.name,
288
+ content: new File(param.fileName)
289
+ };
290
+ }
291
+ return {
292
+ name: param.name,
293
+ content: param.value
294
+ };
295
+ });
296
+ const header = getHeaderName(params2.headers, "content-type");
297
+ if (header) {
298
+ delete params2.headers[header];
299
+ }
300
+ }
301
+ break;
302
+ }
303
+ }
304
+ switch (getHeader(params2.headers, "accept")) {
305
+ case "application/json":
306
+ {
307
+ params2.accept = new Keyword("json");
308
+ const header = getHeaderName(params2.headers, "accept");
309
+ if (header) {
310
+ delete params2.headers[header];
311
+ }
312
+ }
313
+ break;
314
+ }
315
+ push("(require '[clj-http.client :as client])\n");
316
+ if (objEmpty(filterEmpty(params2))) {
317
+ push(`(client/${method} "${url}")`);
318
+ } else {
319
+ const padding = 11 + method.length + url.length;
320
+ const formattedParams = padBlock(padding, jsToEdn(filterEmpty(params2)));
321
+ push(`(client/${method} "${url}" ${formattedParams})`);
322
+ }
323
+ return join();
324
+ }
325
+ };
326
+
327
+ // src/targets/clojure/target.ts
328
+ var clojure = {
329
+ info: {
330
+ key: "clojure",
331
+ title: "Clojure",
332
+ extname: ".clj",
333
+ default: "clj_http"
334
+ },
335
+ clientsById: {
336
+ clj_http
337
+ }
338
+ };
339
+
340
+ // src/targets/csharp/httpclient/client.ts
341
+ var getDecompressionMethods = (allHeaders) => {
342
+ let acceptEncodings = getHeader(allHeaders, "accept-encoding");
343
+ if (!acceptEncodings) {
344
+ return [];
345
+ }
346
+ const supportedMethods2 = {
347
+ gzip: "DecompressionMethods.GZip",
348
+ deflate: "DecompressionMethods.Deflate"
349
+ };
350
+ const methods = [];
351
+ if (typeof acceptEncodings === "string") {
352
+ acceptEncodings = [acceptEncodings];
353
+ }
354
+ acceptEncodings.forEach((acceptEncoding) => {
355
+ acceptEncoding.split(",").forEach((encoding) => {
356
+ const match = /\s*([^;\s]+)/.exec(encoding);
357
+ if (match) {
358
+ const method = supportedMethods2[match[1]];
359
+ if (method) {
360
+ methods.push(method);
361
+ }
362
+ }
363
+ });
364
+ });
365
+ return methods;
366
+ };
367
+ var httpclient = {
368
+ info: {
369
+ key: "httpclient",
370
+ title: "HttpClient",
371
+ link: "https://docs.microsoft.com/en-us/dotnet/api/system.net.http.httpclient",
372
+ description: ".NET Standard HTTP Client"
373
+ },
374
+ convert: ({ allHeaders, postData, method, fullUrl }, options) => {
375
+ const opts = {
376
+ indent: " ",
377
+ ...options
378
+ };
379
+ const { push, join } = new CodeBuilder({ indent: opts.indent });
380
+ push("using System.Net.Http.Headers;");
381
+ let clienthandler = "";
382
+ const cookies = Boolean(allHeaders.cookie);
383
+ const decompressionMethods = getDecompressionMethods(allHeaders);
384
+ if (cookies || decompressionMethods.length) {
385
+ clienthandler = "clientHandler";
386
+ push("var clientHandler = new HttpClientHandler");
387
+ push("{");
388
+ if (cookies) {
389
+ push("UseCookies = false,", 1);
390
+ }
391
+ if (decompressionMethods.length) {
392
+ push(`AutomaticDecompression = ${decompressionMethods.join(" | ")},`, 1);
393
+ }
394
+ push("};");
395
+ }
396
+ push(`var client = new HttpClient(${clienthandler});`);
397
+ push("var request = new HttpRequestMessage");
398
+ push("{");
399
+ const methods = ["GET", "POST", "PUT", "DELETE", "PATCH", "HEAD", "OPTIONS", "TRACE"];
400
+ method = method.toUpperCase();
401
+ if (method && methods.includes(method)) {
402
+ method = `HttpMethod.${method[0]}${method.substring(1).toLowerCase()}`;
403
+ } else {
404
+ method = `new HttpMethod("${method}")`;
405
+ }
406
+ push(`Method = ${method},`, 1);
407
+ push(`RequestUri = new Uri("${fullUrl}"),`, 1);
408
+ const headers = Object.keys(allHeaders).filter((header) => {
409
+ switch (header.toLowerCase()) {
410
+ case "content-type":
411
+ case "content-length":
412
+ case "accept-encoding":
413
+ return false;
414
+ default:
415
+ return true;
416
+ }
417
+ });
418
+ if (headers.length) {
419
+ push("Headers =", 1);
420
+ push("{", 1);
421
+ headers.forEach((key) => {
422
+ push(`{ "${key}", "${escapeForDoubleQuotes(allHeaders[key])}" },`, 2);
423
+ });
424
+ push("},", 1);
425
+ }
426
+ if (postData.text) {
427
+ const contentType = postData.mimeType;
428
+ switch (contentType) {
429
+ case "application/x-www-form-urlencoded":
430
+ push("Content = new FormUrlEncodedContent(new Dictionary<string, string>", 1);
431
+ push("{", 1);
432
+ postData.params?.forEach((param) => {
433
+ push(`{ "${param.name}", "${param.value}" },`, 2);
434
+ });
435
+ push("}),", 1);
436
+ break;
437
+ case "multipart/form-data":
438
+ push("Content = new MultipartFormDataContent", 1);
439
+ push("{", 1);
440
+ postData.params?.forEach((param) => {
441
+ push(`new StringContent(${JSON.stringify(param.value || "")})`, 2);
442
+ push("{", 2);
443
+ push("Headers =", 3);
444
+ push("{", 3);
445
+ if (param.contentType) {
446
+ push(`ContentType = new MediaTypeHeaderValue("${param.contentType}"),`, 4);
447
+ }
448
+ push('ContentDisposition = new ContentDispositionHeaderValue("form-data")', 4);
449
+ push("{", 4);
450
+ push(`Name = "${param.name}",`, 5);
451
+ if (param.fileName) {
452
+ push(`FileName = "${param.fileName}",`, 5);
453
+ }
454
+ push("}", 4);
455
+ push("}", 3);
456
+ push("},", 2);
457
+ });
458
+ push("},", 1);
459
+ break;
460
+ default:
461
+ push(`Content = new StringContent(${JSON.stringify(postData.text || "")})`, 1);
462
+ push("{", 1);
463
+ push("Headers =", 2);
464
+ push("{", 2);
465
+ push(`ContentType = new MediaTypeHeaderValue("${contentType}")`, 3);
466
+ push("}", 2);
467
+ push("}", 1);
468
+ break;
469
+ }
470
+ }
471
+ push("};");
472
+ push("using (var response = await client.SendAsync(request))");
473
+ push("{");
474
+ push("response.EnsureSuccessStatusCode();", 1);
475
+ push("var body = await response.Content.ReadAsStringAsync();", 1);
476
+ push("Console.WriteLine(body);", 1);
477
+ push("}");
478
+ return join();
479
+ }
480
+ };
481
+
482
+ // src/targets/csharp/restsharp/client.ts
483
+ function title(s) {
484
+ return s[0].toUpperCase() + s.slice(1).toLowerCase();
485
+ }
486
+ var restsharp = {
487
+ info: {
488
+ key: "restsharp",
489
+ title: "RestSharp",
490
+ link: "http://restsharp.org/",
491
+ description: "Simple REST and HTTP API Client for .NET"
492
+ },
493
+ convert: ({ method, fullUrl, headersObj, cookies, postData, uriObj }) => {
494
+ const { push, join } = new CodeBuilder();
495
+ const isSupportedMethod = ["GET", "POST", "PUT", "DELETE", "PATCH", "HEAD", "OPTIONS"].includes(
496
+ method.toUpperCase()
497
+ );
498
+ if (!isSupportedMethod) {
499
+ return "Method not supported";
500
+ }
501
+ push("using RestSharp;\n\n");
502
+ push(`var options = new RestClientOptions("${fullUrl}");`);
503
+ push("var client = new RestClient(options);");
504
+ push('var request = new RestRequest("");');
505
+ const isMultipart = postData.mimeType && postData.mimeType === "multipart/form-data";
506
+ if (isMultipart) {
507
+ push("request.AlwaysMultipartFormData = true;");
508
+ }
509
+ Object.keys(headersObj).forEach((key) => {
510
+ if (postData.mimeType && key.toLowerCase() === "content-type" && postData.text) {
511
+ if (isMultipart && postData.boundary) {
512
+ push(`request.FormBoundary = "${postData.boundary}";`);
513
+ }
514
+ return;
515
+ }
516
+ push(`request.AddHeader("${key}", "${escapeForDoubleQuotes(headersObj[key])}");`);
517
+ });
518
+ cookies.forEach(({ name, value }) => {
519
+ push(`request.AddCookie("${name}", "${escapeForDoubleQuotes(value)}", "${uriObj.pathname}", "${uriObj.host}");`);
520
+ });
521
+ switch (postData.mimeType) {
522
+ case "multipart/form-data":
523
+ if (!postData.params)
524
+ break;
525
+ postData.params.forEach((param) => {
526
+ if (param.fileName) {
527
+ push(`request.AddFile("${param.name}", "${param.fileName}");`);
528
+ } else {
529
+ push(`request.AddParameter("${param.name}", "${param.value}");`);
530
+ }
531
+ });
532
+ break;
533
+ case "application/x-www-form-urlencoded":
534
+ if (!postData.params)
535
+ break;
536
+ postData.params.forEach((param) => {
537
+ push(`request.AddParameter("${param.name}", "${param.value}");`);
538
+ });
539
+ break;
540
+ case "application/json": {
541
+ if (!postData.text)
542
+ break;
543
+ const text = JSON.stringify(postData.text);
544
+ push(`request.AddJsonBody(${text}, false);`);
545
+ break;
546
+ }
547
+ default:
548
+ if (!postData.text)
549
+ break;
550
+ push(`request.AddStringBody("${postData.text}", "${postData.mimeType}");`);
551
+ }
552
+ push(`var response = await client.${title(method)}Async(request);
553
+ `);
554
+ push('Console.WriteLine("{0}", response.Content);\n');
555
+ return join();
556
+ }
557
+ };
558
+
559
+ // src/targets/csharp/target.ts
560
+ var csharp = {
561
+ info: {
562
+ key: "csharp",
563
+ title: "C#",
564
+ extname: ".cs",
565
+ default: "restsharp",
566
+ cli: "dotnet"
567
+ },
568
+ clientsById: {
569
+ httpclient,
570
+ restsharp
571
+ }
572
+ };
573
+
574
+ // src/targets/go/native/client.ts
575
+ var native = {
576
+ info: {
577
+ key: "native",
578
+ title: "NewRequest",
579
+ link: "http://golang.org/pkg/net/http/#NewRequest",
580
+ description: "Golang HTTP client request"
581
+ },
582
+ convert: ({ postData, method, allHeaders, fullUrl }, options = {}) => {
583
+ const { blank, push, join } = new CodeBuilder({ indent: " " });
584
+ const { showBoilerplate = true, checkErrors = false, printBody = true, timeout = -1 } = options;
585
+ const errorPlaceholder = checkErrors ? "err" : "_";
586
+ const indent = showBoilerplate ? 1 : 0;
587
+ const errorCheck = () => {
588
+ if (checkErrors) {
589
+ push("if err != nil {", indent);
590
+ push("panic(err)", indent + 1);
591
+ push("}", indent);
592
+ }
593
+ };
594
+ if (showBoilerplate) {
595
+ push("package main");
596
+ blank();
597
+ push("import (");
598
+ push('"fmt"', indent);
599
+ if (timeout > 0) {
600
+ push('"time"', indent);
601
+ }
602
+ if (postData.text) {
603
+ push('"strings"', indent);
604
+ }
605
+ push('"net/http"', indent);
606
+ if (printBody) {
607
+ push('"io"', indent);
608
+ }
609
+ push(")");
610
+ blank();
611
+ push("func main() {");
612
+ blank();
613
+ }
614
+ const hasTimeout = timeout > 0;
615
+ const hasClient = hasTimeout;
616
+ const client = hasClient ? "client" : "http.DefaultClient";
617
+ if (hasClient) {
618
+ push("client := http.Client{", indent);
619
+ if (hasTimeout) {
620
+ push(`Timeout: time.Duration(${timeout} * time.Second),`, indent + 1);
621
+ }
622
+ push("}", indent);
623
+ blank();
624
+ }
625
+ push(`url := "${fullUrl}"`, indent);
626
+ blank();
627
+ if (postData.text) {
628
+ push(`payload := strings.NewReader(${JSON.stringify(postData.text)})`, indent);
629
+ blank();
630
+ push(`req, ${errorPlaceholder} := http.NewRequest("${method}", url, payload)`, indent);
631
+ blank();
632
+ } else {
633
+ push(`req, ${errorPlaceholder} := http.NewRequest("${method}", url, nil)`, indent);
634
+ blank();
635
+ }
636
+ errorCheck();
637
+ if (Object.keys(allHeaders).length) {
638
+ Object.keys(allHeaders).forEach((key) => {
639
+ push(`req.Header.Add("${key}", "${escapeForDoubleQuotes(allHeaders[key])}")`, indent);
640
+ });
641
+ blank();
642
+ }
643
+ push(`res, ${errorPlaceholder} := ${client}.Do(req)`, indent);
644
+ errorCheck();
645
+ if (printBody) {
646
+ blank();
647
+ push("defer res.Body.Close()", indent);
648
+ push(`body, ${errorPlaceholder} := io.ReadAll(res.Body)`, indent);
649
+ errorCheck();
650
+ }
651
+ blank();
652
+ if (printBody) {
653
+ push("fmt.Println(string(body))", indent);
654
+ }
655
+ if (showBoilerplate) {
656
+ blank();
657
+ push("}");
658
+ }
659
+ return join();
660
+ }
661
+ };
662
+
663
+ // src/targets/go/target.ts
664
+ var go = {
665
+ info: {
666
+ key: "go",
667
+ title: "Go",
668
+ extname: ".go",
669
+ default: "native",
670
+ cli: "go"
671
+ },
672
+ clientsById: {
673
+ native
674
+ }
675
+ };
676
+
677
+ // src/targets/http/http1.1/client.ts
678
+ var CRLF = "\r\n";
679
+ var http11 = {
680
+ info: {
681
+ key: "http1.1",
682
+ title: "HTTP/1.1",
683
+ link: "https://tools.ietf.org/html/rfc7230",
684
+ description: "HTTP/1.1 request string in accordance with RFC 7230"
685
+ },
686
+ convert: ({ method, fullUrl, uriObj, httpVersion, allHeaders, postData }, options) => {
687
+ const opts = {
688
+ absoluteURI: false,
689
+ autoContentLength: true,
690
+ autoHost: true,
691
+ ...options
692
+ };
693
+ const { blank, push, join } = new CodeBuilder({ indent: "", join: CRLF });
694
+ const requestUrl = opts.absoluteURI ? fullUrl : uriObj.path;
695
+ push(`${method} ${requestUrl} ${httpVersion}`);
696
+ const headerKeys = Object.keys(allHeaders);
697
+ headerKeys.forEach((key) => {
698
+ const keyCapitalized = key.toLowerCase().replace(/(^|-)(\w)/g, (input) => input.toUpperCase());
699
+ push(`${keyCapitalized}: ${allHeaders[key]}`);
700
+ });
701
+ if (opts.autoHost && !headerKeys.includes("host")) {
702
+ push(`Host: ${uriObj.host}`);
703
+ }
704
+ if (opts.autoContentLength && postData.text && !headerKeys.includes("content-length")) {
705
+ const length = Buffer.byteLength(postData.text, "ascii").toString();
706
+ push(`Content-Length: ${length}`);
707
+ }
708
+ blank();
709
+ const headerSection = join();
710
+ const messageBody = postData.text || "";
711
+ return `${headerSection}${CRLF}${messageBody}`;
712
+ }
713
+ };
714
+
715
+ // src/targets/http/target.ts
716
+ var http = {
717
+ info: {
718
+ key: "http",
719
+ title: "HTTP",
720
+ extname: null,
721
+ default: "1.1"
722
+ },
723
+ clientsById: {
724
+ "http1.1": http11
725
+ }
726
+ };
727
+
728
+ // src/targets/java/asynchttp/client.ts
729
+ var asynchttp = {
730
+ info: {
731
+ key: "asynchttp",
732
+ title: "AsyncHttp",
733
+ link: "https://github.com/AsyncHttpClient/async-http-client",
734
+ description: "Asynchronous Http and WebSocket Client library for Java"
735
+ },
736
+ convert: ({ method, allHeaders, postData, fullUrl }, options) => {
737
+ const opts = {
738
+ indent: " ",
739
+ ...options
740
+ };
741
+ const { blank, push, join } = new CodeBuilder({ indent: opts.indent });
742
+ push("AsyncHttpClient client = new DefaultAsyncHttpClient();");
743
+ push(`client.prepare("${method.toUpperCase()}", "${fullUrl}")`);
744
+ Object.keys(allHeaders).forEach((key) => {
745
+ push(`.setHeader("${key}", "${escapeForDoubleQuotes(allHeaders[key])}")`, 1);
746
+ });
747
+ if (postData.text) {
748
+ push(`.setBody(${JSON.stringify(postData.text)})`, 1);
749
+ }
750
+ push(".execute()", 1);
751
+ push(".toCompletableFuture()", 1);
752
+ push(".thenAccept(System.out::println)", 1);
753
+ push(".join();", 1);
754
+ blank();
755
+ push("client.close();");
756
+ return join();
757
+ }
758
+ };
759
+
760
+ // src/targets/java/nethttp/client.ts
761
+ var nethttp = {
762
+ info: {
763
+ key: "nethttp",
764
+ title: "java.net.http",
765
+ link: "https://openjdk.java.net/groups/net/httpclient/intro.html",
766
+ description: "Java Standardized HTTP Client API"
767
+ },
768
+ convert: ({ allHeaders, fullUrl, method, postData }, options) => {
769
+ const opts = {
770
+ indent: " ",
771
+ ...options
772
+ };
773
+ const { push, join } = new CodeBuilder({ indent: opts.indent });
774
+ push("HttpRequest request = HttpRequest.newBuilder()");
775
+ push(`.uri(URI.create("${fullUrl}"))`, 2);
776
+ Object.keys(allHeaders).forEach((key) => {
777
+ push(`.header("${key}", "${escapeForDoubleQuotes(allHeaders[key])}")`, 2);
778
+ });
779
+ if (postData.text) {
780
+ push(
781
+ `.method("${method.toUpperCase()}", HttpRequest.BodyPublishers.ofString(${JSON.stringify(postData.text)}))`,
782
+ 2
783
+ );
784
+ } else {
785
+ push(`.method("${method.toUpperCase()}", HttpRequest.BodyPublishers.noBody())`, 2);
786
+ }
787
+ push(".build();", 2);
788
+ push(
789
+ "HttpResponse<String> response = HttpClient.newHttpClient().send(request, HttpResponse.BodyHandlers.ofString());"
790
+ );
791
+ push("System.out.println(response.body());");
792
+ return join();
793
+ }
794
+ };
795
+
796
+ // src/targets/java/okhttp/client.ts
797
+ var okhttp = {
798
+ info: {
799
+ key: "okhttp",
800
+ title: "OkHttp",
801
+ link: "http://square.github.io/okhttp/",
802
+ description: "An HTTP Request Client Library"
803
+ },
804
+ convert: ({ postData, method, fullUrl, allHeaders }, options) => {
805
+ const opts = {
806
+ indent: " ",
807
+ ...options
808
+ };
809
+ const { push, blank, join } = new CodeBuilder({ indent: opts.indent });
810
+ const methods = ["GET", "POST", "PUT", "DELETE", "PATCH", "HEAD"];
811
+ const methodsWithBody = ["POST", "PUT", "DELETE", "PATCH"];
812
+ push("OkHttpClient client = new OkHttpClient();");
813
+ blank();
814
+ if (postData.text) {
815
+ if (postData.boundary) {
816
+ push(`MediaType mediaType = MediaType.parse("${postData.mimeType}; boundary=${postData.boundary}");`);
817
+ } else {
818
+ push(`MediaType mediaType = MediaType.parse("${postData.mimeType}");`);
819
+ }
820
+ push(`RequestBody body = RequestBody.create(mediaType, ${JSON.stringify(postData.text)});`);
821
+ }
822
+ push("Request request = new Request.Builder()");
823
+ push(`.url("${fullUrl}")`, 1);
824
+ if (!methods.includes(method.toUpperCase())) {
825
+ if (postData.text) {
826
+ push(`.method("${method.toUpperCase()}", body)`, 1);
827
+ } else {
828
+ push(`.method("${method.toUpperCase()}", null)`, 1);
829
+ }
830
+ } else if (methodsWithBody.includes(method.toUpperCase())) {
831
+ if (postData.text) {
832
+ push(`.${method.toLowerCase()}(body)`, 1);
833
+ } else {
834
+ push(`.${method.toLowerCase()}(null)`, 1);
835
+ }
836
+ } else {
837
+ push(`.${method.toLowerCase()}()`, 1);
838
+ }
839
+ Object.keys(allHeaders).forEach((key) => {
840
+ push(`.addHeader("${key}", "${escapeForDoubleQuotes(allHeaders[key])}")`, 1);
841
+ });
842
+ push(".build();", 1);
843
+ blank();
844
+ push("Response response = client.newCall(request).execute();");
845
+ return join();
846
+ }
847
+ };
848
+
849
+ // src/targets/java/unirest/client.ts
850
+ var unirest = {
851
+ info: {
852
+ key: "unirest",
853
+ title: "Unirest",
854
+ link: "http://unirest.io/java.html",
855
+ description: "Lightweight HTTP Request Client Library"
856
+ },
857
+ convert: ({ method, allHeaders, postData, fullUrl }, options) => {
858
+ const opts = {
859
+ indent: " ",
860
+ ...options
861
+ };
862
+ const { join, push } = new CodeBuilder({ indent: opts.indent });
863
+ const methods = ["GET", "POST", "PUT", "DELETE", "PATCH", "HEAD", "OPTIONS"];
864
+ if (!methods.includes(method.toUpperCase())) {
865
+ push(`HttpResponse<String> response = Unirest.customMethod("${method.toUpperCase()}","${fullUrl}")`);
866
+ } else {
867
+ push(`HttpResponse<String> response = Unirest.${method.toLowerCase()}("${fullUrl}")`);
868
+ }
869
+ Object.keys(allHeaders).forEach((key) => {
870
+ push(`.header("${key}", "${escapeForDoubleQuotes(allHeaders[key])}")`, 1);
871
+ });
872
+ if (postData.text) {
873
+ push(`.body(${JSON.stringify(postData.text)})`, 1);
874
+ }
875
+ push(".asString();", 1);
876
+ return join();
877
+ }
878
+ };
879
+
880
+ // src/targets/java/target.ts
881
+ var java = {
882
+ info: {
883
+ key: "java",
884
+ title: "Java",
885
+ extname: ".java",
886
+ default: "unirest"
887
+ },
888
+ clientsById: {
889
+ asynchttp,
890
+ nethttp,
891
+ okhttp,
892
+ unirest
893
+ }
894
+ };
895
+ var axios = {
896
+ info: {
897
+ key: "axios",
898
+ title: "Axios",
899
+ link: "https://github.com/axios/axios",
900
+ description: "Promise based HTTP client for the browser and node.js"
901
+ },
902
+ convert: ({ allHeaders, method, url, queryObj, postData }, options) => {
903
+ const opts = {
904
+ indent: " ",
905
+ ...options
906
+ };
907
+ const { blank, push, join, addPostProcessor } = new CodeBuilder({ indent: opts.indent });
908
+ push("import axios from 'axios';");
909
+ blank();
910
+ const requestOptions = {
911
+ method,
912
+ url
913
+ };
914
+ if (Object.keys(queryObj).length) {
915
+ requestOptions.params = queryObj;
916
+ }
917
+ if (Object.keys(allHeaders).length) {
918
+ requestOptions.headers = allHeaders;
919
+ }
920
+ switch (postData.mimeType) {
921
+ case "application/x-www-form-urlencoded":
922
+ if (postData.params) {
923
+ push("const encodedParams = new URLSearchParams();");
924
+ postData.params.forEach((param) => {
925
+ push(`encodedParams.set('${param.name}', '${param.value}');`);
926
+ });
927
+ blank();
928
+ requestOptions.data = "encodedParams,";
929
+ addPostProcessor((code) => code.replace(/'encodedParams,'/, "encodedParams,"));
930
+ }
931
+ break;
932
+ case "application/json":
933
+ if (postData.jsonObj) {
934
+ requestOptions.data = postData.jsonObj;
935
+ }
936
+ break;
937
+ case "multipart/form-data":
938
+ if (!postData.params) {
939
+ break;
940
+ }
941
+ push("const form = new FormData();");
942
+ postData.params.forEach((param) => {
943
+ push(`form.append('${param.name}', '${param.value || param.fileName || ""}');`);
944
+ });
945
+ blank();
946
+ requestOptions.data = "[form]";
947
+ break;
948
+ default:
949
+ if (postData.text) {
950
+ requestOptions.data = postData.text;
951
+ }
952
+ }
953
+ const optionString = stringifyObject9(requestOptions, {
954
+ indent: " ",
955
+ inlineCharacterLimit: 80
956
+ }).replace('"[form]"', "form");
957
+ push(`const options = ${optionString};`);
958
+ blank();
959
+ push("axios");
960
+ push(".request(options)", 1);
961
+ push(".then(function (response) {", 1);
962
+ push("console.log(response.data);", 2);
963
+ push("})", 1);
964
+ push(".catch(function (error) {", 1);
965
+ push("console.error(error);", 2);
966
+ push("});", 1);
967
+ return join();
968
+ }
969
+ };
970
+ var fetch = {
971
+ info: {
972
+ key: "fetch",
973
+ title: "fetch",
974
+ link: "https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch",
975
+ description: "Perform asynchronous HTTP requests with the Fetch API"
976
+ },
977
+ convert: ({ method, allHeaders, postData, fullUrl }, inputOpts) => {
978
+ const opts = {
979
+ indent: " ",
980
+ credentials: null,
981
+ ...inputOpts
982
+ };
983
+ const { blank, join, push } = new CodeBuilder({ indent: opts.indent });
984
+ const options = {
985
+ method
986
+ };
987
+ if (Object.keys(allHeaders).length) {
988
+ options.headers = allHeaders;
989
+ }
990
+ if (opts.credentials !== null) {
991
+ options.credentials = opts.credentials;
992
+ }
993
+ switch (postData.mimeType) {
994
+ case "application/x-www-form-urlencoded":
995
+ options.body = postData.paramsObj ? postData.paramsObj : postData.text;
996
+ break;
997
+ case "application/json":
998
+ if (postData.jsonObj) {
999
+ options.body = postData.jsonObj;
1000
+ }
1001
+ break;
1002
+ case "multipart/form-data":
1003
+ if (!postData.params) {
1004
+ break;
1005
+ }
1006
+ const contentTypeHeader = getHeaderName(allHeaders, "content-type");
1007
+ if (contentTypeHeader) {
1008
+ delete allHeaders[contentTypeHeader];
1009
+ }
1010
+ push("const form = new FormData();");
1011
+ postData.params.forEach((param) => {
1012
+ push(`form.append('${param.name}', '${param.value || param.fileName || ""}');`);
1013
+ });
1014
+ blank();
1015
+ break;
1016
+ default:
1017
+ if (postData.text) {
1018
+ options.body = postData.text;
1019
+ }
1020
+ }
1021
+ if (options.headers && !Object.keys(options.headers).length) {
1022
+ delete options.headers;
1023
+ }
1024
+ push(
1025
+ `const options = ${stringifyObject9(options, {
1026
+ indent: opts.indent,
1027
+ inlineCharacterLimit: 80,
1028
+ // The Fetch API body only accepts string parameters, but stringified JSON can be difficult
1029
+ // to read, so we keep the object as a literal and use this transform function to wrap the
1030
+ // literal in a `JSON.stringify` call.
1031
+ transform: (object, property, originalResult) => {
1032
+ if (property === "body") {
1033
+ if (postData.mimeType === "application/x-www-form-urlencoded") {
1034
+ return `new URLSearchParams(${originalResult})`;
1035
+ } else if (postData.mimeType === "application/json") {
1036
+ return `JSON.stringify(${originalResult})`;
1037
+ }
1038
+ }
1039
+ return originalResult;
1040
+ }
1041
+ })};`
1042
+ );
1043
+ blank();
1044
+ if (postData.params && postData.mimeType === "multipart/form-data") {
1045
+ push("options.body = form;");
1046
+ blank();
1047
+ }
1048
+ push(`fetch('${fullUrl}', options)`);
1049
+ push(".then(response => response.json())", 1);
1050
+ push(".then(response => console.log(response))", 1);
1051
+ push(".catch(err => console.error(err));", 1);
1052
+ return join();
1053
+ }
1054
+ };
1055
+ var jquery = {
1056
+ info: {
1057
+ key: "jquery",
1058
+ title: "jQuery",
1059
+ link: "http://api.jquery.com/jquery.ajax/",
1060
+ description: "Perform an asynchronous HTTP (Ajax) requests with jQuery"
1061
+ },
1062
+ convert: ({ fullUrl, method, allHeaders, postData }, options) => {
1063
+ const opts = {
1064
+ indent: " ",
1065
+ ...options
1066
+ };
1067
+ const { blank, push, join } = new CodeBuilder({ indent: opts.indent });
1068
+ const settings = {
1069
+ async: true,
1070
+ crossDomain: true,
1071
+ url: fullUrl,
1072
+ method,
1073
+ headers: allHeaders
1074
+ };
1075
+ switch (postData.mimeType) {
1076
+ case "application/x-www-form-urlencoded":
1077
+ settings.data = postData.paramsObj ? postData.paramsObj : postData.text;
1078
+ break;
1079
+ case "application/json":
1080
+ settings.processData = false;
1081
+ settings.data = postData.text;
1082
+ break;
1083
+ case "multipart/form-data":
1084
+ if (!postData.params) {
1085
+ break;
1086
+ }
1087
+ push("const form = new FormData();");
1088
+ postData.params.forEach((param) => {
1089
+ push(`form.append('${param.name}', '${param.value || param.fileName || ""}');`);
1090
+ });
1091
+ settings.processData = false;
1092
+ settings.contentType = false;
1093
+ settings.mimeType = "multipart/form-data";
1094
+ settings.data = "[form]";
1095
+ if (hasHeader(allHeaders, "content-type")) {
1096
+ if (getHeader(allHeaders, "content-type")?.includes("boundary")) {
1097
+ const headerName = getHeaderName(allHeaders, "content-type");
1098
+ if (headerName) {
1099
+ delete settings.headers[headerName];
1100
+ }
1101
+ }
1102
+ }
1103
+ blank();
1104
+ break;
1105
+ default:
1106
+ if (postData.text) {
1107
+ settings.data = postData.text;
1108
+ }
1109
+ }
1110
+ const stringifiedSettings = stringifyObject9(settings, { indent: opts.indent }).replace("'[form]'", "form");
1111
+ push(`const settings = ${stringifiedSettings};`);
1112
+ blank();
1113
+ push("$.ajax(settings).done(function (response) {");
1114
+ push("console.log(response);", 1);
1115
+ push("});");
1116
+ return join();
1117
+ }
1118
+ };
1119
+ var xhr = {
1120
+ info: {
1121
+ key: "xhr",
1122
+ title: "XMLHttpRequest",
1123
+ link: "https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest",
1124
+ description: "W3C Standard API that provides scripted client functionality"
1125
+ },
1126
+ convert: ({ postData, allHeaders, method, fullUrl }, options) => {
1127
+ const opts = {
1128
+ indent: " ",
1129
+ cors: true,
1130
+ ...options
1131
+ };
1132
+ const { blank, push, join } = new CodeBuilder({ indent: opts.indent });
1133
+ switch (postData.mimeType) {
1134
+ case "application/json":
1135
+ push(
1136
+ `const data = JSON.stringify(${stringifyObject9(postData.jsonObj, {
1137
+ indent: opts.indent
1138
+ })});`
1139
+ );
1140
+ blank();
1141
+ break;
1142
+ case "multipart/form-data":
1143
+ if (!postData.params) {
1144
+ break;
1145
+ }
1146
+ push("const data = new FormData();");
1147
+ postData.params.forEach((param) => {
1148
+ push(`data.append('${param.name}', '${param.value || param.fileName || ""}');`);
1149
+ });
1150
+ if (hasHeader(allHeaders, "content-type")) {
1151
+ if (getHeader(allHeaders, "content-type")?.includes("boundary")) {
1152
+ const headerName = getHeaderName(allHeaders, "content-type");
1153
+ if (headerName) {
1154
+ delete allHeaders[headerName];
1155
+ }
1156
+ }
1157
+ }
1158
+ blank();
1159
+ break;
1160
+ default:
1161
+ push(`const data = ${postData.text ? `'${postData.text}'` : "null"};`);
1162
+ blank();
1163
+ }
1164
+ push("const xhr = new XMLHttpRequest();");
1165
+ if (opts.cors) {
1166
+ push("xhr.withCredentials = true;");
1167
+ }
1168
+ blank();
1169
+ push("xhr.addEventListener('readystatechange', function () {");
1170
+ push("if (this.readyState === this.DONE) {", 1);
1171
+ push("console.log(this.responseText);", 2);
1172
+ push("}", 1);
1173
+ push("});");
1174
+ blank();
1175
+ push(`xhr.open('${method}', '${fullUrl}');`);
1176
+ Object.keys(allHeaders).forEach((key) => {
1177
+ push(`xhr.setRequestHeader('${key}', '${escapeForSingleQuotes(allHeaders[key])}');`);
1178
+ });
1179
+ blank();
1180
+ push("xhr.send(data);");
1181
+ return join();
1182
+ }
1183
+ };
1184
+
1185
+ // src/targets/javascript/target.ts
1186
+ var javascript = {
1187
+ info: {
1188
+ key: "javascript",
1189
+ title: "JavaScript",
1190
+ extname: ".js",
1191
+ default: "xhr"
1192
+ },
1193
+ clientsById: {
1194
+ xhr,
1195
+ axios,
1196
+ fetch,
1197
+ jquery
1198
+ }
1199
+ };
1200
+
1201
+ // src/targets/json/native/client.ts
1202
+ var native2 = {
1203
+ info: {
1204
+ key: "native",
1205
+ title: "Native JSON",
1206
+ link: "https://www.json.org/json-en.html",
1207
+ description: "A JSON represetation of any HAR payload."
1208
+ },
1209
+ convert: ({ postData }, inputOpts) => {
1210
+ const opts = {
1211
+ indent: " ",
1212
+ ...inputOpts
1213
+ };
1214
+ let payload = "";
1215
+ switch (postData.mimeType) {
1216
+ case "application/x-www-form-urlencoded":
1217
+ payload = postData.paramsObj ? postData.paramsObj : postData.text;
1218
+ break;
1219
+ case "application/json":
1220
+ if (postData.jsonObj) {
1221
+ payload = postData.jsonObj;
1222
+ }
1223
+ break;
1224
+ case "multipart/form-data":
1225
+ if (!postData.params) {
1226
+ break;
1227
+ }
1228
+ const multipartPayload = {};
1229
+ postData.params.forEach((param) => {
1230
+ multipartPayload[param.name] = param.value;
1231
+ });
1232
+ payload = multipartPayload;
1233
+ break;
1234
+ default:
1235
+ if (postData.text) {
1236
+ payload = postData.text;
1237
+ }
1238
+ }
1239
+ if (typeof payload === "undefined" || payload === "") {
1240
+ return "No JSON body";
1241
+ }
1242
+ return JSON.stringify(payload, null, opts.indent);
1243
+ }
1244
+ };
1245
+
1246
+ // src/targets/json/target.ts
1247
+ var json = {
1248
+ info: {
1249
+ key: "json",
1250
+ title: "JSON",
1251
+ extname: ".json",
1252
+ default: "native"
1253
+ },
1254
+ clientsById: {
1255
+ native: native2
1256
+ }
1257
+ };
1258
+
1259
+ // src/targets/kotlin/okhttp/client.ts
1260
+ var okhttp2 = {
1261
+ info: {
1262
+ key: "okhttp",
1263
+ title: "OkHttp",
1264
+ link: "http://square.github.io/okhttp/",
1265
+ description: "An HTTP Request Client Library"
1266
+ },
1267
+ convert: ({ postData, fullUrl, method, allHeaders }, options) => {
1268
+ const opts = {
1269
+ indent: " ",
1270
+ ...options
1271
+ };
1272
+ const { blank, join, push } = new CodeBuilder({ indent: opts.indent });
1273
+ const methods = ["GET", "POST", "PUT", "DELETE", "PATCH", "HEAD"];
1274
+ const methodsWithBody = ["POST", "PUT", "DELETE", "PATCH"];
1275
+ push("val client = OkHttpClient()");
1276
+ blank();
1277
+ if (postData.text) {
1278
+ if (postData.boundary) {
1279
+ push(`val mediaType = MediaType.parse("${postData.mimeType}; boundary=${postData.boundary}")`);
1280
+ } else {
1281
+ push(`val mediaType = MediaType.parse("${postData.mimeType}")`);
1282
+ }
1283
+ push(`val body = RequestBody.create(mediaType, ${JSON.stringify(postData.text)})`);
1284
+ }
1285
+ push("val request = Request.Builder()");
1286
+ push(`.url("${fullUrl}")`, 1);
1287
+ if (!methods.includes(method.toUpperCase())) {
1288
+ if (postData.text) {
1289
+ push(`.method("${method.toUpperCase()}", body)`, 1);
1290
+ } else {
1291
+ push(`.method("${method.toUpperCase()}", null)`, 1);
1292
+ }
1293
+ } else if (methodsWithBody.includes(method.toUpperCase())) {
1294
+ if (postData.text) {
1295
+ push(`.${method.toLowerCase()}(body)`, 1);
1296
+ } else {
1297
+ push(`.${method.toLowerCase()}(null)`, 1);
1298
+ }
1299
+ } else {
1300
+ push(`.${method.toLowerCase()}()`, 1);
1301
+ }
1302
+ Object.keys(allHeaders).forEach((key) => {
1303
+ push(`.addHeader("${key}", "${escapeForDoubleQuotes(allHeaders[key])}")`, 1);
1304
+ });
1305
+ push(".build()", 1);
1306
+ blank();
1307
+ push("val response = client.newCall(request).execute()");
1308
+ return join();
1309
+ }
1310
+ };
1311
+
1312
+ // src/targets/kotlin/target.ts
1313
+ var kotlin = {
1314
+ info: {
1315
+ key: "kotlin",
1316
+ title: "Kotlin",
1317
+ extname: ".kt",
1318
+ default: "okhttp"
1319
+ },
1320
+ clientsById: {
1321
+ okhttp: okhttp2
1322
+ }
1323
+ };
1324
+ var axios2 = {
1325
+ info: {
1326
+ key: "axios",
1327
+ title: "Axios",
1328
+ link: "https://github.com/axios/axios",
1329
+ description: "Promise based HTTP client for the browser and node.js"
1330
+ },
1331
+ convert: ({ method, fullUrl, allHeaders, postData }, options) => {
1332
+ const opts = {
1333
+ indent: " ",
1334
+ ...options
1335
+ };
1336
+ const { blank, join, push, addPostProcessor } = new CodeBuilder({ indent: opts.indent });
1337
+ push("const axios = require('axios');");
1338
+ const reqOpts = {
1339
+ method,
1340
+ url: fullUrl
1341
+ };
1342
+ if (Object.keys(allHeaders).length) {
1343
+ reqOpts.headers = allHeaders;
1344
+ }
1345
+ switch (postData.mimeType) {
1346
+ case "application/x-www-form-urlencoded":
1347
+ if (postData.params) {
1348
+ push("const { URLSearchParams } = require('url');");
1349
+ blank();
1350
+ push("const encodedParams = new URLSearchParams();");
1351
+ postData.params.forEach((param) => {
1352
+ push(`encodedParams.set('${param.name}', '${param.value}');`);
1353
+ });
1354
+ blank();
1355
+ reqOpts.data = "encodedParams,";
1356
+ addPostProcessor((code) => code.replace(/'encodedParams,'/, "encodedParams,"));
1357
+ }
1358
+ break;
1359
+ case "application/json":
1360
+ blank();
1361
+ if (postData.jsonObj) {
1362
+ reqOpts.data = postData.jsonObj;
1363
+ }
1364
+ break;
1365
+ default:
1366
+ blank();
1367
+ if (postData.text) {
1368
+ reqOpts.data = postData.text;
1369
+ }
1370
+ }
1371
+ const stringifiedOptions = stringifyObject9(reqOpts, { indent: " ", inlineCharacterLimit: 80 });
1372
+ push(`const options = ${stringifiedOptions};`);
1373
+ blank();
1374
+ push("axios");
1375
+ push(".request(options)", 1);
1376
+ push(".then(function (response) {", 1);
1377
+ push("console.log(response.data);", 2);
1378
+ push("})", 1);
1379
+ push(".catch(function (error) {", 1);
1380
+ push("console.error(error);", 2);
1381
+ push("});", 1);
1382
+ return join();
1383
+ }
1384
+ };
1385
+ var fetch2 = {
1386
+ info: {
1387
+ key: "fetch",
1388
+ title: "Fetch",
1389
+ link: "https://github.com/bitinn/node-fetch",
1390
+ description: "Simplified HTTP node-fetch client"
1391
+ },
1392
+ convert: ({ method, fullUrl, postData, headersObj, cookies }, options) => {
1393
+ const opts = {
1394
+ indent: " ",
1395
+ ...options
1396
+ };
1397
+ let includeFS = false;
1398
+ const { blank, push, join, unshift } = new CodeBuilder({ indent: opts.indent });
1399
+ push("const fetch = require('node-fetch');");
1400
+ const url = fullUrl;
1401
+ const reqOpts = {
1402
+ method
1403
+ };
1404
+ if (Object.keys(headersObj).length) {
1405
+ reqOpts.headers = headersObj;
1406
+ }
1407
+ switch (postData.mimeType) {
1408
+ case "application/x-www-form-urlencoded":
1409
+ unshift("const { URLSearchParams } = require('url');");
1410
+ push("const encodedParams = new URLSearchParams();");
1411
+ blank();
1412
+ postData.params?.forEach((param) => {
1413
+ push(`encodedParams.set('${param.name}', '${param.value}');`);
1414
+ });
1415
+ reqOpts.body = "encodedParams";
1416
+ break;
1417
+ case "application/json":
1418
+ if (postData.jsonObj) {
1419
+ reqOpts.body = postData.jsonObj;
1420
+ }
1421
+ break;
1422
+ case "multipart/form-data":
1423
+ if (!postData.params) {
1424
+ break;
1425
+ }
1426
+ const contentTypeHeader = getHeaderName(headersObj, "content-type");
1427
+ if (contentTypeHeader) {
1428
+ delete headersObj[contentTypeHeader];
1429
+ }
1430
+ unshift("const FormData = require('form-data');");
1431
+ push("const formData = new FormData();");
1432
+ blank();
1433
+ postData.params.forEach((param) => {
1434
+ if (!param.fileName && !param.fileName && !param.contentType) {
1435
+ push(`formData.append('${param.name}', '${param.value}');`);
1436
+ return;
1437
+ }
1438
+ if (param.fileName) {
1439
+ includeFS = true;
1440
+ push(`formData.append('${param.name}', fs.createReadStream('${param.fileName}'));`);
1441
+ }
1442
+ });
1443
+ break;
1444
+ default:
1445
+ if (postData.text) {
1446
+ reqOpts.body = postData.text;
1447
+ }
1448
+ }
1449
+ if (cookies.length) {
1450
+ const cookiesString = cookies.map(({ name, value }) => `${encodeURIComponent(name)}=${encodeURIComponent(value)}`).join("; ");
1451
+ if (reqOpts.headers) {
1452
+ reqOpts.headers.cookie = cookiesString;
1453
+ } else {
1454
+ reqOpts.headers = {};
1455
+ reqOpts.headers.cookie = cookiesString;
1456
+ }
1457
+ }
1458
+ blank();
1459
+ push(`const url = '${url}';`);
1460
+ if (reqOpts.headers && !Object.keys(reqOpts.headers).length) {
1461
+ delete reqOpts.headers;
1462
+ }
1463
+ const stringifiedOptions = stringifyObject9(reqOpts, {
1464
+ indent: " ",
1465
+ inlineCharacterLimit: 80,
1466
+ // The Fetch API body only accepts string parameters, but stringified JSON can be difficult to
1467
+ // read, so we keep the object as a literal and use this transform function to wrap the literal
1468
+ // in a `JSON.stringify` call.
1469
+ transform: (object, property, originalResult) => {
1470
+ if (property === "body" && postData.mimeType === "application/json") {
1471
+ return `JSON.stringify(${originalResult})`;
1472
+ }
1473
+ return originalResult;
1474
+ }
1475
+ });
1476
+ push(`const options = ${stringifiedOptions};`);
1477
+ blank();
1478
+ if (includeFS) {
1479
+ unshift("const fs = require('fs');");
1480
+ }
1481
+ if (postData.params && postData.mimeType === "multipart/form-data") {
1482
+ push("options.body = formData;");
1483
+ blank();
1484
+ }
1485
+ push("fetch(url, options)");
1486
+ push(".then(res => res.json())", 1);
1487
+ push(".then(json => console.log(json))", 1);
1488
+ push(".catch(err => console.error('error:' + err));", 1);
1489
+ return join().replace(/'encodedParams'/, "encodedParams").replace(/"fs\.createReadStream\(\\"(.+)\\"\)"/, 'fs.createReadStream("$1")');
1490
+ }
1491
+ };
1492
+ var native3 = {
1493
+ info: {
1494
+ key: "native",
1495
+ title: "HTTP",
1496
+ link: "http://nodejs.org/api/http.html#http_http_request_options_callback",
1497
+ description: "Node.js native HTTP interface"
1498
+ },
1499
+ convert: ({ uriObj, method, allHeaders, postData }, options = {}) => {
1500
+ const { indent = " " } = options;
1501
+ const { blank, join, push, unshift } = new CodeBuilder({ indent });
1502
+ const reqOpts = {
1503
+ method,
1504
+ hostname: uriObj.hostname,
1505
+ port: uriObj.port,
1506
+ path: uriObj.path,
1507
+ headers: allHeaders
1508
+ };
1509
+ push(`const http = require('${uriObj.protocol?.replace(":", "")}');`);
1510
+ blank();
1511
+ push(`const options = ${stringifyObject9(reqOpts, { indent })};`);
1512
+ blank();
1513
+ push("const req = http.request(options, function (res) {");
1514
+ push("const chunks = [];", 1);
1515
+ blank();
1516
+ push("res.on('data', function (chunk) {", 1);
1517
+ push("chunks.push(chunk);", 2);
1518
+ push("});", 1);
1519
+ blank();
1520
+ push("res.on('end', function () {", 1);
1521
+ push("const body = Buffer.concat(chunks);", 2);
1522
+ push("console.log(body.toString());", 2);
1523
+ push("});", 1);
1524
+ push("});");
1525
+ blank();
1526
+ switch (postData.mimeType) {
1527
+ case "application/x-www-form-urlencoded":
1528
+ if (postData.paramsObj) {
1529
+ unshift("const qs = require('querystring');");
1530
+ push(
1531
+ `req.write(qs.stringify(${stringifyObject9(postData.paramsObj, {
1532
+ indent: " ",
1533
+ inlineCharacterLimit: 80
1534
+ })}));`
1535
+ );
1536
+ }
1537
+ break;
1538
+ case "application/json":
1539
+ if (postData.jsonObj) {
1540
+ push(
1541
+ `req.write(JSON.stringify(${stringifyObject9(postData.jsonObj, {
1542
+ indent: " ",
1543
+ inlineCharacterLimit: 80
1544
+ })}));`
1545
+ );
1546
+ }
1547
+ break;
1548
+ default:
1549
+ if (postData.text) {
1550
+ push(`req.write(${stringifyObject9(postData.text, { indent })});`);
1551
+ }
1552
+ }
1553
+ push("req.end();");
1554
+ return join();
1555
+ }
1556
+ };
1557
+ var request = {
1558
+ info: {
1559
+ key: "request",
1560
+ title: "Request",
1561
+ link: "https://github.com/request/request",
1562
+ description: "Simplified HTTP request client"
1563
+ },
1564
+ convert: ({ method, url, fullUrl, postData, headersObj, cookies }, options) => {
1565
+ const opts = {
1566
+ indent: " ",
1567
+ ...options
1568
+ };
1569
+ let includeFS = false;
1570
+ const { push, blank, join, unshift, addPostProcessor } = new CodeBuilder({ indent: opts.indent });
1571
+ push("const request = require('request');");
1572
+ blank();
1573
+ const reqOpts = {
1574
+ method,
1575
+ url: fullUrl
1576
+ };
1577
+ if (Object.keys(headersObj).length) {
1578
+ reqOpts.headers = headersObj;
1579
+ }
1580
+ switch (postData.mimeType) {
1581
+ case "application/x-www-form-urlencoded":
1582
+ reqOpts.form = postData.paramsObj;
1583
+ break;
1584
+ case "application/json":
1585
+ if (postData.jsonObj) {
1586
+ reqOpts.body = postData.jsonObj;
1587
+ reqOpts.json = true;
1588
+ }
1589
+ break;
1590
+ case "multipart/form-data":
1591
+ if (!postData.params) {
1592
+ break;
1593
+ }
1594
+ reqOpts.formData = {};
1595
+ postData.params.forEach((param) => {
1596
+ if (!param.fileName && !param.fileName && !param.contentType) {
1597
+ reqOpts.formData[param.name] = param.value;
1598
+ return;
1599
+ }
1600
+ let attachment = {};
1601
+ if (param.fileName) {
1602
+ includeFS = true;
1603
+ attachment = {
1604
+ value: `fs.createReadStream(${param.fileName})`,
1605
+ options: {
1606
+ filename: param.fileName,
1607
+ contentType: param.contentType ? param.contentType : null
1608
+ }
1609
+ };
1610
+ } else if (param.value) {
1611
+ attachment.value = param.value;
1612
+ }
1613
+ reqOpts.formData[param.name] = attachment;
1614
+ });
1615
+ addPostProcessor((code) => code.replace(/'fs\.createReadStream\((.*)\)'/, "fs.createReadStream('$1')"));
1616
+ break;
1617
+ default:
1618
+ if (postData.text) {
1619
+ reqOpts.body = postData.text;
1620
+ }
1621
+ }
1622
+ if (cookies.length) {
1623
+ reqOpts.jar = "JAR";
1624
+ push("const jar = request.jar();");
1625
+ cookies.forEach(({ name, value }) => {
1626
+ push(`jar.setCookie(request.cookie('${encodeURIComponent(name)}=${encodeURIComponent(value)}'), '${url}');`);
1627
+ });
1628
+ blank();
1629
+ addPostProcessor((code) => code.replace(/'JAR'/, "jar"));
1630
+ }
1631
+ if (includeFS) {
1632
+ unshift("const fs = require('fs');");
1633
+ }
1634
+ push(`const options = ${stringifyObject9(reqOpts, { indent: " ", inlineCharacterLimit: 80 })};`);
1635
+ blank();
1636
+ push("request(options, function (error, response, body) {");
1637
+ push("if (error) throw new Error(error);", 1);
1638
+ blank();
1639
+ push("console.log(body);", 1);
1640
+ push("});");
1641
+ return join();
1642
+ }
1643
+ };
1644
+ var unirest2 = {
1645
+ info: {
1646
+ key: "unirest",
1647
+ title: "Unirest",
1648
+ link: "http://unirest.io/nodejs.html",
1649
+ description: "Lightweight HTTP Request Client Library"
1650
+ },
1651
+ convert: ({ method, url, cookies, queryObj, postData, headersObj }, options) => {
1652
+ const opts = {
1653
+ indent: " ",
1654
+ ...options
1655
+ };
1656
+ let includeFS = false;
1657
+ const { addPostProcessor, blank, join, push, unshift } = new CodeBuilder({
1658
+ indent: opts.indent
1659
+ });
1660
+ push("const unirest = require('unirest');");
1661
+ blank();
1662
+ push(`const req = unirest('${method}', '${url}');`);
1663
+ blank();
1664
+ if (cookies.length) {
1665
+ push("const CookieJar = unirest.jar();");
1666
+ cookies.forEach((cookie) => {
1667
+ push(`CookieJar.add('${encodeURIComponent(cookie.name)}=${encodeURIComponent(cookie.value)}', '${url}');`);
1668
+ });
1669
+ push("req.jar(CookieJar);");
1670
+ blank();
1671
+ }
1672
+ if (Object.keys(queryObj).length) {
1673
+ push(`req.query(${stringifyObject9(queryObj, { indent: opts.indent })});`);
1674
+ blank();
1675
+ }
1676
+ if (Object.keys(headersObj).length) {
1677
+ push(`req.headers(${stringifyObject9(headersObj, { indent: opts.indent })});`);
1678
+ blank();
1679
+ }
1680
+ switch (postData.mimeType) {
1681
+ case "application/x-www-form-urlencoded":
1682
+ if (postData.paramsObj) {
1683
+ push(`req.form(${stringifyObject9(postData.paramsObj, { indent: opts.indent })});`);
1684
+ blank();
1685
+ }
1686
+ break;
1687
+ case "application/json":
1688
+ if (postData.jsonObj) {
1689
+ push("req.type('json');");
1690
+ push(`req.send(${stringifyObject9(postData.jsonObj, { indent: opts.indent })});`);
1691
+ blank();
1692
+ }
1693
+ break;
1694
+ case "multipart/form-data": {
1695
+ if (!postData.params) {
1696
+ break;
1697
+ }
1698
+ const multipart = [];
1699
+ postData.params.forEach((param) => {
1700
+ const part = {};
1701
+ if (param.fileName && !param.value) {
1702
+ includeFS = true;
1703
+ part.body = `fs.createReadStream('${param.fileName}')`;
1704
+ addPostProcessor((code) => code.replace(/'fs\.createReadStream\(\\'(.+)\\'\)'/, "fs.createReadStream('$1')"));
1705
+ } else if (param.value) {
1706
+ part.body = param.value;
1707
+ }
1708
+ if (part.body) {
1709
+ if (param.contentType) {
1710
+ part["content-type"] = param.contentType;
1711
+ }
1712
+ multipart.push(part);
1713
+ }
1714
+ });
1715
+ push(`req.multipart(${stringifyObject9(multipart, { indent: opts.indent })});`);
1716
+ blank();
1717
+ break;
1718
+ }
1719
+ default:
1720
+ if (postData.text) {
1721
+ push(`req.send(${stringifyObject9(postData.text, { indent: opts.indent })});`);
1722
+ blank();
1723
+ }
1724
+ }
1725
+ if (includeFS) {
1726
+ unshift("const fs = require('fs');");
1727
+ }
1728
+ push("req.end(function (res) {");
1729
+ push("if (res.error) throw new Error(res.error);", 1);
1730
+ blank();
1731
+ push("console.log(res.body);", 1);
1732
+ push("});");
1733
+ return join();
1734
+ }
1735
+ };
1736
+
1737
+ // src/targets/node/target.ts
1738
+ var node = {
1739
+ info: {
1740
+ key: "node",
1741
+ title: "Node.js",
1742
+ extname: ".js",
1743
+ default: "native",
1744
+ cli: "node %s"
1745
+ },
1746
+ clientsById: {
1747
+ native: native3,
1748
+ request,
1749
+ unirest: unirest2,
1750
+ axios: axios2,
1751
+ fetch: fetch2
1752
+ }
1753
+ };
1754
+
1755
+ // src/targets/objc/helpers.ts
1756
+ var nsDeclaration = (nsClass, name, parameters, indent) => {
1757
+ const opening = `${nsClass} *${name} = `;
1758
+ const literal = literalRepresentation(parameters, indent ? opening.length : void 0);
1759
+ return `${opening}${literal};`;
1760
+ };
1761
+ var literalRepresentation = (value, indentation) => {
1762
+ const join = indentation === void 0 ? ", " : `,
1763
+ ${" ".repeat(indentation)}`;
1764
+ switch (Object.prototype.toString.call(value)) {
1765
+ case "[object Number]":
1766
+ return `@${value}`;
1767
+ case "[object Array]": {
1768
+ const valuesRepresentation = value.map((val) => literalRepresentation(val));
1769
+ return `@[ ${valuesRepresentation.join(join)} ]`;
1770
+ }
1771
+ case "[object Object]": {
1772
+ const keyValuePairs = [];
1773
+ Object.keys(value).forEach((key) => {
1774
+ keyValuePairs.push(`@"${key}": ${literalRepresentation(value[key])}`);
1775
+ });
1776
+ return `@{ ${keyValuePairs.join(join)} }`;
1777
+ }
1778
+ case "[object Boolean]":
1779
+ return value ? "@YES" : "@NO";
1780
+ default:
1781
+ if (value === null || value === void 0) {
1782
+ return "";
1783
+ }
1784
+ return `@"${value.toString().replace(/"/g, '\\"')}"`;
1785
+ }
1786
+ };
1787
+
1788
+ // src/targets/objc/nsurlsession/client.ts
1789
+ var nsurlsession = {
1790
+ info: {
1791
+ key: "nsurlsession",
1792
+ title: "NSURLSession",
1793
+ link: "https://developer.apple.com/library/mac/documentation/Foundation/Reference/NSURLSession_class/index.html",
1794
+ description: "Foundation's NSURLSession request"
1795
+ },
1796
+ convert: ({ allHeaders, postData, method, fullUrl }, options) => {
1797
+ const opts = {
1798
+ indent: " ",
1799
+ pretty: true,
1800
+ timeout: 10,
1801
+ ...options
1802
+ };
1803
+ const { push, join, blank } = new CodeBuilder({ indent: opts.indent });
1804
+ const req = {
1805
+ hasHeaders: false,
1806
+ hasBody: false
1807
+ };
1808
+ push("#import <Foundation/Foundation.h>");
1809
+ if (Object.keys(allHeaders).length) {
1810
+ req.hasHeaders = true;
1811
+ blank();
1812
+ push(nsDeclaration("NSDictionary", "headers", allHeaders, opts.pretty));
1813
+ }
1814
+ if (postData.text || postData.jsonObj || postData.params) {
1815
+ req.hasBody = true;
1816
+ switch (postData.mimeType) {
1817
+ case "application/x-www-form-urlencoded":
1818
+ if (postData.params?.length) {
1819
+ blank();
1820
+ const [head, ...tail] = postData.params;
1821
+ push(
1822
+ `NSMutableData *postData = [[NSMutableData alloc] initWithData:[@"${head.name}=${head.value}" dataUsingEncoding:NSUTF8StringEncoding]];`
1823
+ );
1824
+ tail.forEach(({ name, value }) => {
1825
+ push(`[postData appendData:[@"&${name}=${value}" dataUsingEncoding:NSUTF8StringEncoding]];`);
1826
+ });
1827
+ } else {
1828
+ req.hasBody = false;
1829
+ }
1830
+ break;
1831
+ case "application/json":
1832
+ if (postData.jsonObj) {
1833
+ push(nsDeclaration("NSDictionary", "parameters", postData.jsonObj, opts.pretty));
1834
+ blank();
1835
+ push("NSData *postData = [NSJSONSerialization dataWithJSONObject:parameters options:0 error:nil];");
1836
+ }
1837
+ break;
1838
+ case "multipart/form-data":
1839
+ push(nsDeclaration("NSArray", "parameters", postData.params || [], opts.pretty));
1840
+ push(`NSString *boundary = @"${postData.boundary}";`);
1841
+ blank();
1842
+ push("NSError *error;");
1843
+ push("NSMutableString *body = [NSMutableString string];");
1844
+ push("for (NSDictionary *param in parameters) {");
1845
+ push('[body appendFormat:@"--%@\\r\\n", boundary];', 1);
1846
+ push('if (param[@"fileName"]) {', 1);
1847
+ push(
1848
+ '[body appendFormat:@"Content-Disposition:form-data; name=\\"%@\\"; filename=\\"%@\\"\\r\\n", param[@"name"], param[@"fileName"]];',
1849
+ 2
1850
+ );
1851
+ push('[body appendFormat:@"Content-Type: %@\\r\\n\\r\\n", param[@"contentType"]];', 2);
1852
+ push(
1853
+ '[body appendFormat:@"%@", [NSString stringWithContentsOfFile:param[@"fileName"] encoding:NSUTF8StringEncoding error:&error]];',
1854
+ 2
1855
+ );
1856
+ push("if (error) {", 2);
1857
+ push('NSLog(@"%@", error);', 3);
1858
+ push("}", 2);
1859
+ push("} else {", 1);
1860
+ push('[body appendFormat:@"Content-Disposition:form-data; name=\\"%@\\"\\r\\n\\r\\n", param[@"name"]];', 2);
1861
+ push('[body appendFormat:@"%@", param[@"value"]];', 2);
1862
+ push("}", 1);
1863
+ push("}");
1864
+ push('[body appendFormat:@"\\r\\n--%@--\\r\\n", boundary];');
1865
+ push("NSData *postData = [body dataUsingEncoding:NSUTF8StringEncoding];");
1866
+ break;
1867
+ default:
1868
+ blank();
1869
+ push(
1870
+ `NSData *postData = [[NSData alloc] initWithData:[@"${postData.text}" dataUsingEncoding:NSUTF8StringEncoding]];`
1871
+ );
1872
+ }
1873
+ }
1874
+ blank();
1875
+ push(`NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"${fullUrl}"]`);
1876
+ push(" cachePolicy:NSURLRequestUseProtocolCachePolicy");
1877
+ push(` timeoutInterval:${opts.timeout.toFixed(1)}];`);
1878
+ push(`[request setHTTPMethod:@"${method}"];`);
1879
+ if (req.hasHeaders) {
1880
+ push("[request setAllHTTPHeaderFields:headers];");
1881
+ }
1882
+ if (req.hasBody) {
1883
+ push("[request setHTTPBody:postData];");
1884
+ }
1885
+ blank();
1886
+ push("NSURLSession *session = [NSURLSession sharedSession];");
1887
+ push("NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request");
1888
+ push(
1889
+ " completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {"
1890
+ );
1891
+ push(" if (error) {", 1);
1892
+ push(' NSLog(@"%@", error);', 2);
1893
+ push(" } else {", 1);
1894
+ push(
1895
+ " NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *) response;",
1896
+ 2
1897
+ );
1898
+ push(' NSLog(@"%@", httpResponse);', 2);
1899
+ push(" }", 1);
1900
+ push(" }];");
1901
+ push("[dataTask resume];");
1902
+ return join();
1903
+ }
1904
+ };
1905
+
1906
+ // src/targets/objc/target.ts
1907
+ var objc = {
1908
+ info: {
1909
+ key: "objc",
1910
+ title: "Objective-C",
1911
+ extname: ".m",
1912
+ default: "nsurlsession"
1913
+ },
1914
+ clientsById: {
1915
+ nsurlsession
1916
+ }
1917
+ };
1918
+
1919
+ // src/targets/ocaml/cohttp/client.ts
1920
+ var cohttp = {
1921
+ info: {
1922
+ key: "cohttp",
1923
+ title: "CoHTTP",
1924
+ link: "https://github.com/mirage/ocaml-cohttp",
1925
+ description: "Cohttp is a very lightweight HTTP server using Lwt or Async for OCaml"
1926
+ },
1927
+ convert: ({ fullUrl, allHeaders, postData, method }, options) => {
1928
+ const opts = {
1929
+ indent: " ",
1930
+ ...options
1931
+ };
1932
+ const methods = ["get", "post", "head", "delete", "patch", "put", "options"];
1933
+ const { push, blank, join } = new CodeBuilder({ indent: opts.indent });
1934
+ push("open Cohttp_lwt_unix");
1935
+ push("open Cohttp");
1936
+ push("open Lwt");
1937
+ blank();
1938
+ push(`let uri = Uri.of_string "${fullUrl}" in`);
1939
+ const headers = Object.keys(allHeaders);
1940
+ if (headers.length === 1) {
1941
+ push(
1942
+ `let headers = Header.add (Header.init ()) "${headers[0]}" "${escapeForDoubleQuotes(
1943
+ allHeaders[headers[0]]
1944
+ )}" in`
1945
+ );
1946
+ } else if (headers.length > 1) {
1947
+ push("let headers = Header.add_list (Header.init ()) [");
1948
+ headers.forEach((key) => {
1949
+ push(`("${key}", "${escapeForDoubleQuotes(allHeaders[key])}");`, 1);
1950
+ });
1951
+ push("] in");
1952
+ }
1953
+ if (postData.text) {
1954
+ push(`let body = Cohttp_lwt_body.of_string ${JSON.stringify(postData.text)} in`);
1955
+ }
1956
+ blank();
1957
+ const h = headers.length ? "~headers " : "";
1958
+ const b = postData.text ? "~body " : "";
1959
+ const m = methods.includes(method.toLowerCase()) ? `\`${method.toUpperCase()}` : `(Code.method_of_string "${method}")`;
1960
+ push(`Client.call ${h}${b}${m} uri`);
1961
+ push(">>= fun (res, body_stream) ->");
1962
+ push("(* Do stuff with the result *)", 1);
1963
+ return join();
1964
+ }
1965
+ };
1966
+
1967
+ // src/targets/ocaml/target.ts
1968
+ var ocaml = {
1969
+ info: {
1970
+ key: "ocaml",
1971
+ title: "OCaml",
1972
+ extname: ".ml",
1973
+ default: "cohttp"
1974
+ },
1975
+ clientsById: {
1976
+ cohttp
1977
+ }
1978
+ };
1979
+
1980
+ // src/targets/php/helpers.ts
1981
+ var convertType = (obj, indent, lastIndent) => {
1982
+ lastIndent = lastIndent || "";
1983
+ indent = indent || "";
1984
+ switch (Object.prototype.toString.call(obj)) {
1985
+ case "[object Boolean]":
1986
+ return obj;
1987
+ case "[object Null]":
1988
+ return "null";
1989
+ case "[object Undefined]":
1990
+ return "null";
1991
+ case "[object String]":
1992
+ return `'${escapeString(obj, { delimiter: "'", escapeNewlines: false })}'`;
1993
+ case "[object Number]":
1994
+ return obj.toString();
1995
+ case "[object Array]": {
1996
+ const contents = obj.map((item) => convertType(item, `${indent}${indent}`, indent)).join(`,
1997
+ ${indent}`);
1998
+ return `[
1999
+ ${indent}${contents}
2000
+ ${lastIndent}]`;
2001
+ }
2002
+ case "[object Object]": {
2003
+ const result = [];
2004
+ for (const i in obj) {
2005
+ if (Object.prototype.hasOwnProperty.call(obj, i)) {
2006
+ result.push(`${convertType(i, indent)} => ${convertType(obj[i], `${indent}${indent}`, indent)}`);
2007
+ }
2008
+ }
2009
+ return `[
2010
+ ${indent}${result.join(`,
2011
+ ${indent}`)}
2012
+ ${lastIndent}]`;
2013
+ }
2014
+ default:
2015
+ return "null";
2016
+ }
2017
+ };
2018
+ var supportedMethods = [
2019
+ "ACL",
2020
+ "BASELINE_CONTROL",
2021
+ "CHECKIN",
2022
+ "CHECKOUT",
2023
+ "CONNECT",
2024
+ "COPY",
2025
+ "DELETE",
2026
+ "GET",
2027
+ "HEAD",
2028
+ "LABEL",
2029
+ "LOCK",
2030
+ "MERGE",
2031
+ "MKACTIVITY",
2032
+ "MKCOL",
2033
+ "MKWORKSPACE",
2034
+ "MOVE",
2035
+ "OPTIONS",
2036
+ "POST",
2037
+ "PROPFIND",
2038
+ "PROPPATCH",
2039
+ "PUT",
2040
+ "REPORT",
2041
+ "TRACE",
2042
+ "UNCHECKOUT",
2043
+ "UNLOCK",
2044
+ "UPDATE",
2045
+ "VERSION_CONTROL"
2046
+ ];
2047
+
2048
+ // src/targets/php/curl/client.ts
2049
+ var curl = {
2050
+ info: {
2051
+ key: "curl",
2052
+ title: "cURL",
2053
+ link: "http://php.net/manual/en/book.curl.php",
2054
+ description: "PHP with ext-curl"
2055
+ },
2056
+ convert: ({ uriObj, postData, fullUrl, method, httpVersion, cookies, headersObj }, options = {}) => {
2057
+ const {
2058
+ closingTag = false,
2059
+ indent = " ",
2060
+ maxRedirects = 10,
2061
+ namedErrors = false,
2062
+ noTags = false,
2063
+ shortTags = false,
2064
+ timeout = 30
2065
+ } = options;
2066
+ const { push, blank, join } = new CodeBuilder({ indent });
2067
+ if (!noTags) {
2068
+ push(shortTags ? "<?" : "<?php");
2069
+ blank();
2070
+ }
2071
+ push("$curl = curl_init();");
2072
+ blank();
2073
+ const curlOptions = [
2074
+ {
2075
+ escape: true,
2076
+ name: "CURLOPT_PORT",
2077
+ value: uriObj.port
2078
+ },
2079
+ {
2080
+ escape: true,
2081
+ name: "CURLOPT_URL",
2082
+ value: fullUrl
2083
+ },
2084
+ {
2085
+ escape: false,
2086
+ name: "CURLOPT_RETURNTRANSFER",
2087
+ value: "true"
2088
+ },
2089
+ {
2090
+ escape: true,
2091
+ name: "CURLOPT_ENCODING",
2092
+ value: ""
2093
+ },
2094
+ {
2095
+ escape: false,
2096
+ name: "CURLOPT_MAXREDIRS",
2097
+ value: maxRedirects
2098
+ },
2099
+ {
2100
+ escape: false,
2101
+ name: "CURLOPT_TIMEOUT",
2102
+ value: timeout
2103
+ },
2104
+ {
2105
+ escape: false,
2106
+ name: "CURLOPT_HTTP_VERSION",
2107
+ value: httpVersion === "HTTP/1.0" ? "CURL_HTTP_VERSION_1_0" : "CURL_HTTP_VERSION_1_1"
2108
+ },
2109
+ {
2110
+ escape: true,
2111
+ name: "CURLOPT_CUSTOMREQUEST",
2112
+ value: method
2113
+ },
2114
+ {
2115
+ escape: !postData.jsonObj,
2116
+ name: "CURLOPT_POSTFIELDS",
2117
+ value: postData ? postData.jsonObj ? `json_encode(${convertType(postData.jsonObj, indent.repeat(2), indent)})` : postData.text : void 0
2118
+ }
2119
+ ];
2120
+ push("curl_setopt_array($curl, [");
2121
+ const curlopts = new CodeBuilder({ indent, join: `
2122
+ ${indent}` });
2123
+ curlOptions.forEach(({ value, name, escape: escape2 }) => {
2124
+ if (value !== null && value !== void 0) {
2125
+ curlopts.push(`${name} => ${escape2 ? JSON.stringify(value) : value},`);
2126
+ }
2127
+ });
2128
+ const curlCookies = cookies.map((cookie) => `${encodeURIComponent(cookie.name)}=${encodeURIComponent(cookie.value)}`);
2129
+ if (curlCookies.length) {
2130
+ curlopts.push(`CURLOPT_COOKIE => "${curlCookies.join("; ")}",`);
2131
+ }
2132
+ const headers = Object.keys(headersObj).sort().map((key) => `"${key}: ${escapeForDoubleQuotes(headersObj[key])}"`);
2133
+ if (headers.length) {
2134
+ curlopts.push("CURLOPT_HTTPHEADER => [");
2135
+ curlopts.push(headers.join(`,
2136
+ ${indent}${indent}`), 1);
2137
+ curlopts.push("],");
2138
+ }
2139
+ push(curlopts.join(), 1);
2140
+ push("]);");
2141
+ blank();
2142
+ push("$response = curl_exec($curl);");
2143
+ push("$err = curl_error($curl);");
2144
+ blank();
2145
+ push("curl_close($curl);");
2146
+ blank();
2147
+ push("if ($err) {");
2148
+ if (namedErrors) {
2149
+ push('echo array_flip(get_defined_constants(true)["curl"])[$err];', 1);
2150
+ } else {
2151
+ push('echo "cURL Error #:" . $err;', 1);
2152
+ }
2153
+ push("} else {");
2154
+ push("echo $response;", 1);
2155
+ push("}");
2156
+ if (!noTags && closingTag) {
2157
+ blank();
2158
+ push("?>");
2159
+ }
2160
+ return join();
2161
+ }
2162
+ };
2163
+
2164
+ // src/targets/php/guzzle/client.ts
2165
+ var guzzle = {
2166
+ info: {
2167
+ key: "guzzle",
2168
+ title: "Guzzle",
2169
+ link: "http://docs.guzzlephp.org/en/stable/",
2170
+ description: "PHP with Guzzle"
2171
+ },
2172
+ convert: ({ postData, fullUrl, method, cookies, headersObj }, options) => {
2173
+ const opts = {
2174
+ closingTag: false,
2175
+ indent: " ",
2176
+ noTags: false,
2177
+ shortTags: false,
2178
+ ...options
2179
+ };
2180
+ const { push, blank, join } = new CodeBuilder({ indent: opts.indent });
2181
+ const { code: requestCode, push: requestPush, join: requestJoin } = new CodeBuilder({ indent: opts.indent });
2182
+ if (!opts.noTags) {
2183
+ push(opts.shortTags ? "<?" : "<?php");
2184
+ }
2185
+ push("require_once('vendor/autoload.php');");
2186
+ blank();
2187
+ switch (postData.mimeType) {
2188
+ case "application/x-www-form-urlencoded":
2189
+ requestPush(`'form_params' => ${convertType(postData.paramsObj, opts.indent + opts.indent, opts.indent)},`, 1);
2190
+ break;
2191
+ case "multipart/form-data": {
2192
+ const fields = [];
2193
+ if (postData.params) {
2194
+ postData.params.forEach((param) => {
2195
+ if (param.fileName) {
2196
+ const field = {
2197
+ name: param.name,
2198
+ filename: param.fileName,
2199
+ contents: param.value
2200
+ };
2201
+ if (param.contentType) {
2202
+ field.headers = { "Content-Type": param.contentType };
2203
+ }
2204
+ fields.push(field);
2205
+ } else if (param.value) {
2206
+ fields.push({
2207
+ name: param.name,
2208
+ contents: param.value
2209
+ });
2210
+ }
2211
+ });
2212
+ }
2213
+ if (fields.length) {
2214
+ requestPush(`'multipart' => ${convertType(fields, opts.indent + opts.indent, opts.indent)}`, 1);
2215
+ if (hasHeader(headersObj, "content-type")) {
2216
+ if (getHeader(headersObj, "content-type")?.indexOf("boundary")) {
2217
+ const headerName = getHeaderName(headersObj, "content-type");
2218
+ if (headerName) {
2219
+ delete headersObj[headerName];
2220
+ }
2221
+ }
2222
+ }
2223
+ }
2224
+ break;
2225
+ }
2226
+ default:
2227
+ if (postData.text) {
2228
+ requestPush(`'body' => ${convertType(postData.text)},`, 1);
2229
+ }
2230
+ }
2231
+ const headers = Object.keys(headersObj).sort().map(function(key) {
2232
+ return `${opts.indent}${opts.indent}'${key}' => '${escapeForSingleQuotes(headersObj[key])}',`;
2233
+ });
2234
+ const cookieString = cookies.map((cookie) => `${encodeURIComponent(cookie.name)}=${encodeURIComponent(cookie.value)}`).join("; ");
2235
+ if (cookieString.length) {
2236
+ headers.push(`${opts.indent}${opts.indent}'cookie' => '${escapeForSingleQuotes(cookieString)}',`);
2237
+ }
2238
+ if (headers.length) {
2239
+ requestPush("'headers' => [", 1);
2240
+ requestPush(headers.join("\n"));
2241
+ requestPush("],", 1);
2242
+ }
2243
+ push("$client = new \\GuzzleHttp\\Client();");
2244
+ blank();
2245
+ if (requestCode.length) {
2246
+ push(`$response = $client->request('${method}', '${fullUrl}', [`);
2247
+ push(requestJoin());
2248
+ push("]);");
2249
+ } else {
2250
+ push(`$response = $client->request('${method}', '${fullUrl}');`);
2251
+ }
2252
+ blank();
2253
+ push("echo $response->getBody();");
2254
+ if (!opts.noTags && opts.closingTag) {
2255
+ blank();
2256
+ push("?>");
2257
+ }
2258
+ return join();
2259
+ }
2260
+ };
2261
+
2262
+ // src/targets/php/http1/client.ts
2263
+ var http1 = {
2264
+ info: {
2265
+ key: "http1",
2266
+ title: "HTTP v1",
2267
+ link: "http://php.net/manual/en/book.http.php",
2268
+ description: "PHP with pecl/http v1"
2269
+ },
2270
+ convert: ({ method, url, postData, queryObj, headersObj, cookiesObj }, options = {}) => {
2271
+ const { closingTag = false, indent = " ", noTags = false, shortTags = false } = options;
2272
+ const { push, blank, join } = new CodeBuilder({ indent });
2273
+ if (!noTags) {
2274
+ push(shortTags ? "<?" : "<?php");
2275
+ blank();
2276
+ }
2277
+ if (!supportedMethods.includes(method.toUpperCase())) {
2278
+ push(`HttpRequest::methodRegister('${method}');`);
2279
+ }
2280
+ push("$request = new HttpRequest();");
2281
+ push(`$request->setUrl(${convertType(url)});`);
2282
+ if (supportedMethods.includes(method.toUpperCase())) {
2283
+ push(`$request->setMethod(HTTP_METH_${method.toUpperCase()});`);
2284
+ } else {
2285
+ push(`$request->setMethod(HttpRequest::HTTP_METH_${method.toUpperCase()});`);
2286
+ }
2287
+ blank();
2288
+ if (Object.keys(queryObj).length) {
2289
+ push(`$request->setQueryData(${convertType(queryObj, indent)});`);
2290
+ blank();
2291
+ }
2292
+ if (Object.keys(headersObj).length) {
2293
+ push(`$request->setHeaders(${convertType(headersObj, indent)});`);
2294
+ blank();
2295
+ }
2296
+ if (Object.keys(cookiesObj).length) {
2297
+ push(`$request->setCookies(${convertType(cookiesObj, indent)});`);
2298
+ blank();
2299
+ }
2300
+ switch (postData.mimeType) {
2301
+ case "application/x-www-form-urlencoded":
2302
+ push(`$request->setContentType(${convertType(postData.mimeType)});`);
2303
+ push(`$request->setPostFields(${convertType(postData.paramsObj, indent)});`);
2304
+ blank();
2305
+ break;
2306
+ case "application/json":
2307
+ push(`$request->setContentType(${convertType(postData.mimeType)});`);
2308
+ push(`$request->setBody(json_encode(${convertType(postData.jsonObj, indent)}));`);
2309
+ blank();
2310
+ break;
2311
+ default:
2312
+ if (postData.text) {
2313
+ push(`$request->setBody(${convertType(postData.text)});`);
2314
+ blank();
2315
+ }
2316
+ }
2317
+ push("try {");
2318
+ push("$response = $request->send();", 1);
2319
+ blank();
2320
+ push("echo $response->getBody();", 1);
2321
+ push("} catch (HttpException $ex) {");
2322
+ push("echo $ex;", 1);
2323
+ push("}");
2324
+ if (!noTags && closingTag) {
2325
+ blank();
2326
+ push("?>");
2327
+ }
2328
+ return join();
2329
+ }
2330
+ };
2331
+
2332
+ // src/targets/php/http2/client.ts
2333
+ var http2 = {
2334
+ info: {
2335
+ key: "http2",
2336
+ title: "HTTP v2",
2337
+ link: "http://devel-m6w6.rhcloud.com/mdref/http",
2338
+ description: "PHP with pecl/http v2"
2339
+ },
2340
+ convert: ({ postData, headersObj, method, queryObj, cookiesObj, url }, options = {}) => {
2341
+ const { closingTag = false, indent = " ", noTags = false, shortTags = false } = options;
2342
+ const { push, blank, join } = new CodeBuilder({ indent });
2343
+ let hasBody = false;
2344
+ if (!noTags) {
2345
+ push(shortTags ? "<?" : "<?php");
2346
+ blank();
2347
+ }
2348
+ push("$client = new http\\Client;");
2349
+ push("$request = new http\\Client\\Request;");
2350
+ blank();
2351
+ switch (postData.mimeType) {
2352
+ case "application/x-www-form-urlencoded":
2353
+ push("$body = new http\\Message\\Body;");
2354
+ push(`$body->append(new http\\QueryString(${convertType(postData.paramsObj, indent)}));`);
2355
+ blank();
2356
+ hasBody = true;
2357
+ break;
2358
+ case "multipart/form-data": {
2359
+ if (!postData.params) {
2360
+ break;
2361
+ }
2362
+ const files = [];
2363
+ const fields = {};
2364
+ postData.params.forEach(({ name, fileName, value, contentType }) => {
2365
+ if (fileName) {
2366
+ files.push({
2367
+ name,
2368
+ type: contentType,
2369
+ file: fileName,
2370
+ data: value
2371
+ });
2372
+ return;
2373
+ }
2374
+ if (value) {
2375
+ fields[name] = value;
2376
+ }
2377
+ });
2378
+ const field = Object.keys(fields).length ? convertType(fields, indent) : "null";
2379
+ const formValue = files.length ? convertType(files, indent) : "null";
2380
+ push("$body = new http\\Message\\Body;");
2381
+ push(`$body->addForm(${field}, ${formValue});`);
2382
+ if (hasHeader(headersObj, "content-type")) {
2383
+ if (getHeader(headersObj, "content-type")?.indexOf("boundary")) {
2384
+ const headerName = getHeaderName(headersObj, "content-type");
2385
+ if (headerName) {
2386
+ delete headersObj[headerName];
2387
+ }
2388
+ }
2389
+ }
2390
+ blank();
2391
+ hasBody = true;
2392
+ break;
2393
+ }
2394
+ case "application/json":
2395
+ push("$body = new http\\Message\\Body;");
2396
+ push(`$body->append(json_encode(${convertType(postData.jsonObj, indent)}));`);
2397
+ hasBody = true;
2398
+ break;
2399
+ default:
2400
+ if (postData.text) {
2401
+ push("$body = new http\\Message\\Body;");
2402
+ push(`$body->append(${convertType(postData.text)});`);
2403
+ blank();
2404
+ hasBody = true;
2405
+ }
2406
+ }
2407
+ push(`$request->setRequestUrl(${convertType(url)});`);
2408
+ push(`$request->setRequestMethod(${convertType(method)});`);
2409
+ if (hasBody) {
2410
+ push("$request->setBody($body);");
2411
+ blank();
2412
+ }
2413
+ if (Object.keys(queryObj).length) {
2414
+ push(`$request->setQuery(new http\\QueryString(${convertType(queryObj, indent)}));`);
2415
+ blank();
2416
+ }
2417
+ if (Object.keys(headersObj).length) {
2418
+ push(`$request->setHeaders(${convertType(headersObj, indent)});`);
2419
+ blank();
2420
+ }
2421
+ if (Object.keys(cookiesObj).length) {
2422
+ blank();
2423
+ push(`$client->setCookies(${convertType(cookiesObj, indent)});`);
2424
+ blank();
2425
+ }
2426
+ push("$client->enqueue($request)->send();");
2427
+ push("$response = $client->getResponse();");
2428
+ blank();
2429
+ push("echo $response->getBody();");
2430
+ if (!noTags && closingTag) {
2431
+ blank();
2432
+ push("?>");
2433
+ }
2434
+ return join();
2435
+ }
2436
+ };
2437
+
2438
+ // src/targets/php/target.ts
2439
+ var php = {
2440
+ info: {
2441
+ key: "php",
2442
+ title: "PHP",
2443
+ extname: ".php",
2444
+ default: "curl",
2445
+ cli: "php %s"
2446
+ },
2447
+ clientsById: {
2448
+ curl,
2449
+ guzzle,
2450
+ http1,
2451
+ http2
2452
+ }
2453
+ };
2454
+
2455
+ // src/targets/powershell/common.ts
2456
+ var generatePowershellConvert = (command) => {
2457
+ const convert = ({ method, headersObj, cookies, uriObj, fullUrl, postData, allHeaders }) => {
2458
+ const { push, join } = new CodeBuilder();
2459
+ const methods = ["GET", "POST", "PUT", "DELETE", "PATCH", "HEAD", "OPTIONS"];
2460
+ if (!methods.includes(method.toUpperCase())) {
2461
+ return "Method not supported";
2462
+ }
2463
+ const commandOptions = [];
2464
+ const headers = Object.keys(headersObj);
2465
+ if (headers.length) {
2466
+ push("$headers=@{}");
2467
+ headers.forEach((key) => {
2468
+ if (key !== "connection") {
2469
+ push(`$headers.Add("${key}", "${escapeString(headersObj[key], { escapeChar: "`" })}")`);
2470
+ }
2471
+ });
2472
+ commandOptions.push("-Headers $headers");
2473
+ }
2474
+ if (cookies.length) {
2475
+ push("$session = New-Object Microsoft.PowerShell.Commands.WebRequestSession");
2476
+ cookies.forEach((cookie) => {
2477
+ push("$cookie = New-Object System.Net.Cookie");
2478
+ push(`$cookie.Name = '${cookie.name}'`);
2479
+ push(`$cookie.Value = '${cookie.value}'`);
2480
+ push(`$cookie.Domain = '${uriObj.host}'`);
2481
+ push("$session.Cookies.Add($cookie)");
2482
+ });
2483
+ commandOptions.push("-WebSession $session");
2484
+ }
2485
+ if (postData.text) {
2486
+ commandOptions.push(
2487
+ `-ContentType '${escapeString(getHeader(allHeaders, "content-type"), { delimiter: "'", escapeChar: "`" })}'`
2488
+ );
2489
+ commandOptions.push(`-Body '${postData.text}'`);
2490
+ }
2491
+ push(`$response = ${command} -Uri '${fullUrl}' -Method ${method} ${commandOptions.join(" ")}`.trim());
2492
+ return join();
2493
+ };
2494
+ return convert;
2495
+ };
2496
+
2497
+ // src/targets/powershell/restmethod/client.ts
2498
+ var restmethod = {
2499
+ info: {
2500
+ key: "restmethod",
2501
+ title: "Invoke-RestMethod",
2502
+ link: "https://docs.microsoft.com/en-us/powershell/module/Microsoft.PowerShell.Utility/Invoke-RestMethod",
2503
+ description: "Powershell Invoke-RestMethod client"
2504
+ },
2505
+ convert: generatePowershellConvert("Invoke-RestMethod")
2506
+ };
2507
+
2508
+ // src/targets/powershell/webrequest/client.ts
2509
+ var webrequest = {
2510
+ info: {
2511
+ key: "webrequest",
2512
+ title: "Invoke-WebRequest",
2513
+ link: "https://docs.microsoft.com/en-us/powershell/module/Microsoft.PowerShell.Utility/Invoke-WebRequest",
2514
+ description: "Powershell Invoke-WebRequest client"
2515
+ },
2516
+ convert: generatePowershellConvert("Invoke-WebRequest")
2517
+ };
2518
+
2519
+ // src/targets/powershell/target.ts
2520
+ var powershell = {
2521
+ info: {
2522
+ key: "powershell",
2523
+ title: "Powershell",
2524
+ extname: ".ps1",
2525
+ default: "webrequest"
2526
+ },
2527
+ clientsById: {
2528
+ webrequest,
2529
+ restmethod
2530
+ }
2531
+ };
2532
+
2533
+ // src/targets/python/helpers.ts
2534
+ function concatValues(concatType, values, pretty, indentation, indentLevel) {
2535
+ const currentIndent = indentation.repeat(indentLevel);
2536
+ const closingBraceIndent = indentation.repeat(indentLevel - 1);
2537
+ const join = pretty ? `,
2538
+ ${currentIndent}` : ", ";
2539
+ const openingBrace = concatType === "object" ? "{" : "[";
2540
+ const closingBrace = concatType === "object" ? "}" : "]";
2541
+ if (pretty) {
2542
+ return `${openingBrace}
2543
+ ${currentIndent}${values.join(join)}
2544
+ ${closingBraceIndent}${closingBrace}`;
2545
+ }
2546
+ if (concatType === "object" && values.length > 0) {
2547
+ return `${openingBrace} ${values.join(join)} ${closingBrace}`;
2548
+ }
2549
+ return `${openingBrace}${values.join(join)}${closingBrace}`;
2550
+ }
2551
+ var literalRepresentation2 = (value, opts, indentLevel) => {
2552
+ indentLevel = indentLevel === void 0 ? 1 : indentLevel + 1;
2553
+ switch (Object.prototype.toString.call(value)) {
2554
+ case "[object Number]":
2555
+ return value;
2556
+ case "[object Array]": {
2557
+ let pretty = false;
2558
+ const valuesRepresentation = value.map((v) => {
2559
+ if (Object.prototype.toString.call(v) === "[object Object]") {
2560
+ pretty = Object.keys(v).length > 1;
2561
+ }
2562
+ return literalRepresentation2(v, opts, indentLevel);
2563
+ });
2564
+ return concatValues("array", valuesRepresentation, pretty, opts.indent, indentLevel);
2565
+ }
2566
+ case "[object Object]": {
2567
+ const keyValuePairs = [];
2568
+ for (const key in value) {
2569
+ keyValuePairs.push(`"${key}": ${literalRepresentation2(value[key], opts, indentLevel)}`);
2570
+ }
2571
+ return concatValues("object", keyValuePairs, opts.pretty && keyValuePairs.length > 1, opts.indent, indentLevel);
2572
+ }
2573
+ case "[object Null]":
2574
+ return "None";
2575
+ case "[object Boolean]":
2576
+ return value ? "True" : "False";
2577
+ default:
2578
+ if (value === null || value === void 0) {
2579
+ return "";
2580
+ }
2581
+ return `"${value.toString().replace(/"/g, '\\"')}"`;
2582
+ }
2583
+ };
2584
+
2585
+ // src/targets/python/requests/client.ts
2586
+ var builtInMethods = ["HEAD", "GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS"];
2587
+ var requests = {
2588
+ info: {
2589
+ key: "requests",
2590
+ title: "Requests",
2591
+ link: "http://docs.python-requests.org/en/latest/api/#requests.request",
2592
+ description: "Requests HTTP library"
2593
+ },
2594
+ convert: ({ fullUrl, postData, allHeaders, method }, options) => {
2595
+ const opts = {
2596
+ indent: " ",
2597
+ pretty: true,
2598
+ ...options
2599
+ };
2600
+ const { push, blank, join, addPostProcessor } = new CodeBuilder({ indent: opts.indent });
2601
+ push("import requests");
2602
+ blank();
2603
+ push(`url = "${fullUrl}"`);
2604
+ blank();
2605
+ const headers = allHeaders;
2606
+ let payload = {};
2607
+ const files = {};
2608
+ let hasFiles = false;
2609
+ let hasPayload = false;
2610
+ let jsonPayload = false;
2611
+ switch (postData.mimeType) {
2612
+ case "application/json":
2613
+ if (postData.jsonObj) {
2614
+ push(`payload = ${literalRepresentation2(postData.jsonObj, opts)}`);
2615
+ jsonPayload = true;
2616
+ hasPayload = true;
2617
+ }
2618
+ break;
2619
+ case "multipart/form-data":
2620
+ if (!postData.params) {
2621
+ break;
2622
+ }
2623
+ payload = {};
2624
+ postData.params.forEach((p) => {
2625
+ if (p.fileName) {
2626
+ if (p.contentType) {
2627
+ files[p.name] = `('${p.fileName}', open('${p.fileName}', 'rb'), '${p.contentType}')`;
2628
+ } else {
2629
+ files[p.name] = `('${p.fileName}', open('${p.fileName}', 'rb'))`;
2630
+ }
2631
+ hasFiles = true;
2632
+ } else {
2633
+ payload[p.name] = p.value;
2634
+ hasPayload = true;
2635
+ }
2636
+ });
2637
+ if (hasFiles) {
2638
+ push(`files = ${literalRepresentation2(files, opts)}`);
2639
+ if (hasPayload) {
2640
+ push(`payload = ${literalRepresentation2(payload, opts)}`);
2641
+ }
2642
+ const headerName = getHeaderName(headers, "content-type");
2643
+ if (headerName) {
2644
+ delete headers[headerName];
2645
+ }
2646
+ } else {
2647
+ const nonFilePayload = JSON.stringify(postData.text);
2648
+ if (nonFilePayload) {
2649
+ push(`payload = ${nonFilePayload}`);
2650
+ hasPayload = true;
2651
+ }
2652
+ }
2653
+ addPostProcessor(
2654
+ (code) => code.replace(/"\('(.+)', open\('(.+)', 'rb'\)\)"/g, '("$1", open("$2", "rb"))').replace(/"\('(.+)', open\('(.+)', 'rb'\), '(.+)'\)"/g, '("$1", open("$2", "rb"), "$3")')
2655
+ );
2656
+ break;
2657
+ default: {
2658
+ if (postData.mimeType === "application/x-www-form-urlencoded" && postData.paramsObj) {
2659
+ push(`payload = ${literalRepresentation2(postData.paramsObj, opts)}`);
2660
+ hasPayload = true;
2661
+ break;
2662
+ }
2663
+ const stringPayload = JSON.stringify(postData.text);
2664
+ if (stringPayload) {
2665
+ push(`payload = ${stringPayload}`);
2666
+ hasPayload = true;
2667
+ }
2668
+ }
2669
+ }
2670
+ const headerCount = Object.keys(headers).length;
2671
+ if (headerCount === 0 && (hasPayload || hasFiles)) {
2672
+ blank();
2673
+ } else if (headerCount === 1) {
2674
+ Object.keys(headers).forEach((header) => {
2675
+ push(`headers = {"${header}": "${escapeForDoubleQuotes(headers[header])}"}`);
2676
+ blank();
2677
+ });
2678
+ } else if (headerCount > 1) {
2679
+ let count = 1;
2680
+ push("headers = {");
2681
+ Object.keys(headers).forEach((header) => {
2682
+ if (count !== headerCount) {
2683
+ push(`"${header}": "${escapeForDoubleQuotes(headers[header])}",`, 1);
2684
+ } else {
2685
+ push(`"${header}": "${escapeForDoubleQuotes(headers[header])}"`, 1);
2686
+ }
2687
+ count += 1;
2688
+ });
2689
+ push("}");
2690
+ blank();
2691
+ }
2692
+ let request2 = builtInMethods.includes(method) ? `response = requests.${method.toLowerCase()}(url` : `response = requests.request("${method}", url`;
2693
+ if (hasPayload) {
2694
+ if (jsonPayload) {
2695
+ request2 += ", json=payload";
2696
+ } else {
2697
+ request2 += ", data=payload";
2698
+ }
2699
+ }
2700
+ if (hasFiles) {
2701
+ request2 += ", files=files";
2702
+ }
2703
+ if (headerCount > 0) {
2704
+ request2 += ", headers=headers";
2705
+ }
2706
+ request2 += ")";
2707
+ push(request2);
2708
+ blank();
2709
+ push("print(response.text)");
2710
+ return join();
2711
+ }
2712
+ };
2713
+
2714
+ // src/targets/python/target.ts
2715
+ var python = {
2716
+ info: {
2717
+ key: "python",
2718
+ title: "Python",
2719
+ extname: ".py",
2720
+ default: "requests",
2721
+ cli: "python3 %s"
2722
+ },
2723
+ clientsById: {
2724
+ requests
2725
+ }
2726
+ };
2727
+
2728
+ // src/targets/r/httr/client.ts
2729
+ var httr = {
2730
+ info: {
2731
+ key: "httr",
2732
+ title: "httr",
2733
+ link: "https://cran.r-project.org/web/packages/httr/vignettes/quickstart.html",
2734
+ description: "httr: Tools for Working with URLs and HTTP"
2735
+ },
2736
+ convert: ({ url, queryObj, queryString, postData, allHeaders, method }) => {
2737
+ const { push, blank, join } = new CodeBuilder();
2738
+ push("library(httr)");
2739
+ blank();
2740
+ push(`url <- "${url}"`);
2741
+ blank();
2742
+ const qs = queryObj;
2743
+ delete queryObj.key;
2744
+ const queryCount = Object.keys(qs).length;
2745
+ if (queryString.length === 1) {
2746
+ push(`queryString <- list(${Object.keys(qs)} = "${Object.values(qs).toString()}")`);
2747
+ blank();
2748
+ } else if (queryString.length > 1) {
2749
+ push("queryString <- list(");
2750
+ Object.keys(qs).forEach((query, i) => {
2751
+ if (i !== queryCount - 1) {
2752
+ push(` ${query} = "${qs[query].toString()}",`);
2753
+ } else {
2754
+ push(` ${query} = "${qs[query].toString()}"`);
2755
+ }
2756
+ });
2757
+ push(")");
2758
+ blank();
2759
+ }
2760
+ const payload = JSON.stringify(postData.text);
2761
+ if (payload) {
2762
+ push(`payload <- ${payload}`);
2763
+ blank();
2764
+ }
2765
+ if (postData.text || postData.jsonObj || postData.params) {
2766
+ switch (postData.mimeType) {
2767
+ case "application/x-www-form-urlencoded":
2768
+ push('encode <- "form"');
2769
+ blank();
2770
+ break;
2771
+ case "application/json":
2772
+ push('encode <- "json"');
2773
+ blank();
2774
+ break;
2775
+ case "multipart/form-data":
2776
+ push('encode <- "multipart"');
2777
+ blank();
2778
+ break;
2779
+ default:
2780
+ push('encode <- "raw"');
2781
+ blank();
2782
+ break;
2783
+ }
2784
+ }
2785
+ const cookieHeader = getHeader(allHeaders, "cookie");
2786
+ const acceptHeader = getHeader(allHeaders, "accept");
2787
+ const setCookies = cookieHeader ? `set_cookies(\`${String(cookieHeader).replace(/;/g, '", `').replace(/` /g, "`").replace(/[=]/g, '` = "')}")` : void 0;
2788
+ const setAccept = acceptHeader ? `accept("${escapeForDoubleQuotes(acceptHeader)}")` : void 0;
2789
+ const setContentType = `content_type("${escapeForDoubleQuotes(postData.mimeType)}")`;
2790
+ const otherHeaders = Object.entries(allHeaders).filter(([key]) => !["cookie", "accept", "content-type"].includes(key.toLowerCase())).map(([key, value]) => `'${key}' = '${escapeForSingleQuotes(value)}'`).join(", ");
2791
+ const setHeaders = otherHeaders ? `add_headers(${otherHeaders})` : void 0;
2792
+ let request2 = `response <- VERB("${method}", url`;
2793
+ if (payload) {
2794
+ request2 += ", body = payload";
2795
+ }
2796
+ if (queryString.length) {
2797
+ request2 += ", query = queryString";
2798
+ }
2799
+ const headerAdditions = [setHeaders, setContentType, setAccept, setCookies].filter((x) => !!x).join(", ");
2800
+ if (headerAdditions) {
2801
+ request2 += `, ${headerAdditions}`;
2802
+ }
2803
+ if (postData.text || postData.jsonObj || postData.params) {
2804
+ request2 += ", encode = encode";
2805
+ }
2806
+ request2 += ")";
2807
+ push(request2);
2808
+ blank();
2809
+ push('content(response, "text")');
2810
+ return join();
2811
+ }
2812
+ };
2813
+
2814
+ // src/targets/r/target.ts
2815
+ var r = {
2816
+ info: {
2817
+ key: "r",
2818
+ title: "R",
2819
+ extname: ".r",
2820
+ default: "httr"
2821
+ },
2822
+ clientsById: {
2823
+ httr
2824
+ }
2825
+ };
2826
+
2827
+ // src/targets/ruby/native/client.ts
2828
+ var native4 = {
2829
+ info: {
2830
+ key: "native",
2831
+ title: "net::http",
2832
+ link: "http://ruby-doc.org/stdlib-2.2.1/libdoc/net/http/rdoc/Net/HTTP.html",
2833
+ description: "Ruby HTTP client"
2834
+ },
2835
+ convert: ({ uriObj, method: rawMethod, fullUrl, postData, allHeaders }) => {
2836
+ const { push, blank, join } = new CodeBuilder();
2837
+ push("require 'uri'");
2838
+ push("require 'net/http'");
2839
+ blank();
2840
+ const method = rawMethod.toUpperCase();
2841
+ const methods = [
2842
+ "GET",
2843
+ "POST",
2844
+ "HEAD",
2845
+ "DELETE",
2846
+ "PATCH",
2847
+ "PUT",
2848
+ "OPTIONS",
2849
+ "COPY",
2850
+ "LOCK",
2851
+ "UNLOCK",
2852
+ "MOVE",
2853
+ "TRACE"
2854
+ ];
2855
+ const capMethod = method.charAt(0) + method.substring(1).toLowerCase();
2856
+ if (!methods.includes(method)) {
2857
+ push(`class Net::HTTP::${capMethod} < Net::HTTPRequest`);
2858
+ push(` METHOD = '${method.toUpperCase()}'`);
2859
+ push(` REQUEST_HAS_BODY = '${postData.text ? "true" : "false"}'`);
2860
+ push(" RESPONSE_HAS_BODY = true");
2861
+ push("end");
2862
+ blank();
2863
+ }
2864
+ push(`url = URI("${fullUrl}")`);
2865
+ blank();
2866
+ push("http = Net::HTTP.new(url.host, url.port)");
2867
+ if (uriObj.protocol === "https:") {
2868
+ push("http.use_ssl = true");
2869
+ }
2870
+ blank();
2871
+ push(`request = Net::HTTP::${capMethod}.new(url)`);
2872
+ const headers = Object.keys(allHeaders);
2873
+ if (headers.length) {
2874
+ headers.forEach((key) => {
2875
+ push(`request["${key}"] = '${escapeForSingleQuotes(allHeaders[key])}'`);
2876
+ });
2877
+ }
2878
+ if (postData.text) {
2879
+ push(`request.body = ${JSON.stringify(postData.text)}`);
2880
+ }
2881
+ blank();
2882
+ push("response = http.request(request)");
2883
+ push("puts response.read_body");
2884
+ return join();
2885
+ }
2886
+ };
2887
+
2888
+ // src/targets/ruby/target.ts
2889
+ var ruby = {
2890
+ info: {
2891
+ key: "ruby",
2892
+ title: "Ruby",
2893
+ extname: ".rb",
2894
+ default: "native"
2895
+ },
2896
+ clientsById: {
2897
+ native: native4
2898
+ }
2899
+ };
2900
+
2901
+ // src/helpers/shell.ts
2902
+ var quote = (value = "") => {
2903
+ const safe = /^[a-z0-9-_/.@%^=:]+$/i;
2904
+ const isShellSafe = safe.test(value);
2905
+ if (isShellSafe) {
2906
+ return value;
2907
+ }
2908
+ return `'${value.replace(/'/g, "'\\''")}'`;
2909
+ };
2910
+ var escape = (value) => value.replace(/\r/g, "\\r").replace(/\n/g, "\\n");
2911
+
2912
+ // src/targets/shell/curl/client.ts
2913
+ var params = {
2914
+ "http1.0": "0",
2915
+ "url ": "",
2916
+ cookie: "b",
2917
+ data: "d",
2918
+ form: "F",
2919
+ globoff: "g",
2920
+ header: "H",
2921
+ insecure: "k",
2922
+ request: "X"
2923
+ };
2924
+ var getArg = (short) => (longName) => {
2925
+ if (short) {
2926
+ const shortName = params[longName];
2927
+ if (!shortName) {
2928
+ return "";
2929
+ }
2930
+ return `-${shortName}`;
2931
+ }
2932
+ return `--${longName}`;
2933
+ };
2934
+ var curl2 = {
2935
+ info: {
2936
+ key: "curl",
2937
+ title: "cURL",
2938
+ link: "http://curl.haxx.se/",
2939
+ description: "cURL is a command line tool and library for transferring data with URL syntax"
2940
+ },
2941
+ convert: ({ fullUrl, method, httpVersion, headersObj, allHeaders, postData }, options = {}) => {
2942
+ const { indent = " ", short = false, binary = false, globOff = false } = options;
2943
+ const indentJSON = " ";
2944
+ const { push, join } = new CodeBuilder({
2945
+ ...typeof indent === "string" ? { indent } : {},
2946
+ join: indent !== false ? ` \\
2947
+ ${indent}` : " "
2948
+ });
2949
+ const arg = getArg(short);
2950
+ let formattedUrl = quote(fullUrl);
2951
+ push(`curl ${arg("request")} ${method}`);
2952
+ if (globOff) {
2953
+ formattedUrl = unescape(formattedUrl);
2954
+ push(arg("globoff"));
2955
+ }
2956
+ push(`${arg("url ")}${formattedUrl}`);
2957
+ if (httpVersion === "HTTP/1.0") {
2958
+ push(arg("http1.0"));
2959
+ }
2960
+ if (getHeader(allHeaders, "accept-encoding")) {
2961
+ push("--compressed");
2962
+ }
2963
+ if (postData.mimeType === "multipart/form-data") {
2964
+ const contentTypeHeaderName = getHeaderName(headersObj, "content-type");
2965
+ if (contentTypeHeaderName) {
2966
+ const contentTypeHeader = headersObj[contentTypeHeaderName];
2967
+ if (contentTypeHeaderName && contentTypeHeader) {
2968
+ const noBoundary = String(contentTypeHeader).replace(/; boundary.+?(?=(;|$))/, "");
2969
+ headersObj[contentTypeHeaderName] = noBoundary;
2970
+ allHeaders[contentTypeHeaderName] = noBoundary;
2971
+ }
2972
+ }
2973
+ }
2974
+ Object.keys(headersObj).sort().forEach((key) => {
2975
+ const header = `${key}: ${headersObj[key]}`;
2976
+ push(`${arg("header")} ${quote(header)}`);
2977
+ });
2978
+ if (allHeaders.cookie) {
2979
+ push(`${arg("cookie")} ${quote(allHeaders.cookie)}`);
2980
+ }
2981
+ switch (postData.mimeType) {
2982
+ case "multipart/form-data":
2983
+ postData.params?.forEach((param) => {
2984
+ let post = "";
2985
+ if (param.fileName) {
2986
+ post = `${param.name}=@${param.fileName}`;
2987
+ } else {
2988
+ post = `${param.name}=${param.value}`;
2989
+ }
2990
+ push(`${arg("form")} ${quote(post)}`);
2991
+ });
2992
+ break;
2993
+ case "application/x-www-form-urlencoded":
2994
+ if (postData.params) {
2995
+ postData.params.forEach((param) => {
2996
+ const unencoded = param.name;
2997
+ const encoded = encodeURIComponent(param.name);
2998
+ const needsEncoding = encoded !== unencoded;
2999
+ const name = needsEncoding ? encoded : unencoded;
3000
+ const flag = binary ? "--data-binary" : `--data${needsEncoding ? "-urlencode" : ""}`;
3001
+ push(`${flag} ${quote(`${name}=${param.value}`)}`);
3002
+ });
3003
+ } else {
3004
+ push(`${binary ? "--data-binary" : arg("data")} ${quote(postData.text)}`);
3005
+ }
3006
+ break;
3007
+ default:
3008
+ if (!postData.text) {
3009
+ break;
3010
+ }
3011
+ let builtPayload = false;
3012
+ if (isMimeTypeJSON(postData.mimeType)) {
3013
+ if (postData.text.length > 20) {
3014
+ try {
3015
+ const jsonPayload = JSON.parse(postData.text);
3016
+ builtPayload = true;
3017
+ if (postData.text.indexOf("'") > 0) {
3018
+ push(
3019
+ `${binary ? "--data-binary" : arg("data")} @- <<EOF
3020
+ ${JSON.stringify(
3021
+ jsonPayload,
3022
+ null,
3023
+ indentJSON
3024
+ )}
3025
+ EOF`
3026
+ );
3027
+ } else {
3028
+ push(
3029
+ `${binary ? "--data-binary" : arg("data")} '
3030
+ ${JSON.stringify(jsonPayload, null, indentJSON)}
3031
+ '`
3032
+ );
3033
+ }
3034
+ } catch (err) {
3035
+ }
3036
+ }
3037
+ }
3038
+ if (!builtPayload) {
3039
+ push(`${binary ? "--data-binary" : arg("data")} ${quote(postData.text)}`);
3040
+ }
3041
+ }
3042
+ return join();
3043
+ }
3044
+ };
3045
+
3046
+ // src/targets/shell/httpie/client.ts
3047
+ var httpie = {
3048
+ info: {
3049
+ key: "httpie",
3050
+ title: "HTTPie",
3051
+ link: "http://httpie.org/",
3052
+ description: "a CLI, cURL-like tool for humans"
3053
+ },
3054
+ convert: ({ allHeaders, postData, queryObj, fullUrl, method, url }, options) => {
3055
+ const opts = {
3056
+ body: false,
3057
+ cert: false,
3058
+ headers: false,
3059
+ indent: " ",
3060
+ pretty: false,
3061
+ print: false,
3062
+ queryParams: false,
3063
+ short: false,
3064
+ style: false,
3065
+ timeout: false,
3066
+ verbose: false,
3067
+ verify: false,
3068
+ ...options
3069
+ };
3070
+ const { push, join, unshift } = new CodeBuilder({
3071
+ indent: opts.indent,
3072
+ // @ts-expect-error SEEMS LEGIT
3073
+ join: opts.indent !== false ? ` \\
3074
+ ${opts.indent}` : " "
3075
+ });
3076
+ let raw = false;
3077
+ const flags = [];
3078
+ if (opts.headers) {
3079
+ flags.push(opts.short ? "-h" : "--headers");
3080
+ }
3081
+ if (opts.body) {
3082
+ flags.push(opts.short ? "-b" : "--body");
3083
+ }
3084
+ if (opts.verbose) {
3085
+ flags.push(opts.short ? "-v" : "--verbose");
3086
+ }
3087
+ if (opts.print) {
3088
+ flags.push(`${opts.short ? "-p" : "--print"}=${opts.print}`);
3089
+ }
3090
+ if (opts.verify) {
3091
+ flags.push(`--verify=${opts.verify}`);
3092
+ }
3093
+ if (opts.cert) {
3094
+ flags.push(`--cert=${opts.cert}`);
3095
+ }
3096
+ if (opts.pretty) {
3097
+ flags.push(`--pretty=${opts.pretty}`);
3098
+ }
3099
+ if (opts.style) {
3100
+ flags.push(`--style=${opts.style}`);
3101
+ }
3102
+ if (opts.timeout) {
3103
+ flags.push(`--timeout=${opts.timeout}`);
3104
+ }
3105
+ if (opts.queryParams) {
3106
+ Object.keys(queryObj).forEach((name) => {
3107
+ const value = queryObj[name];
3108
+ if (Array.isArray(value)) {
3109
+ value.forEach((val) => {
3110
+ push(`${name}==${quote(val)}`);
3111
+ });
3112
+ } else {
3113
+ push(`${name}==${quote(value)}`);
3114
+ }
3115
+ });
3116
+ }
3117
+ Object.keys(allHeaders).sort().forEach((key) => {
3118
+ push(`${key}:${quote(allHeaders[key])}`);
3119
+ });
3120
+ if (postData.mimeType === "application/x-www-form-urlencoded") {
3121
+ if (postData.params && postData.params.length) {
3122
+ flags.push(opts.short ? "-f" : "--form");
3123
+ postData.params.forEach((param) => {
3124
+ push(`${param.name}=${quote(param.value)}`);
3125
+ });
3126
+ }
3127
+ } else {
3128
+ raw = true;
3129
+ }
3130
+ const cliFlags = flags.length ? `${flags.join(" ")} ` : "";
3131
+ url = quote(opts.queryParams ? url : fullUrl);
3132
+ unshift(`http ${cliFlags}${method} ${url}`);
3133
+ if (raw && postData.text) {
3134
+ const postDataText = quote(postData.text);
3135
+ unshift(`echo ${postDataText} | `);
3136
+ }
3137
+ return join();
3138
+ }
3139
+ };
3140
+
3141
+ // src/targets/shell/wget/client.ts
3142
+ var wget = {
3143
+ info: {
3144
+ key: "wget",
3145
+ title: "Wget",
3146
+ link: "https://www.gnu.org/software/wget/",
3147
+ description: "a free software package for retrieving files using HTTP, HTTPS"
3148
+ },
3149
+ convert: ({ method, postData, allHeaders, fullUrl }, options) => {
3150
+ const opts = {
3151
+ indent: " ",
3152
+ short: false,
3153
+ verbose: false,
3154
+ ...options
3155
+ };
3156
+ const { push, join } = new CodeBuilder({
3157
+ ...typeof opts.indent === "string" ? { indent: opts.indent } : {},
3158
+ join: opts.indent !== false ? ` \\
3159
+ ${opts.indent}` : " "
3160
+ });
3161
+ if (opts.verbose) {
3162
+ push(`wget ${opts.short ? "-v" : "--verbose"}`);
3163
+ } else {
3164
+ push(`wget ${opts.short ? "-q" : "--quiet"}`);
3165
+ }
3166
+ push(`--method ${quote(method)}`);
3167
+ Object.keys(allHeaders).forEach((key) => {
3168
+ const header = `${key}: ${allHeaders[key]}`;
3169
+ push(`--header ${quote(header)}`);
3170
+ });
3171
+ if (postData.text) {
3172
+ push(`--body-data ${escape(quote(postData.text))}`);
3173
+ }
3174
+ push(opts.short ? "-O" : "--output-document");
3175
+ push(`- ${quote(fullUrl)}`);
3176
+ return join();
3177
+ }
3178
+ };
3179
+
3180
+ // src/targets/shell/target.ts
3181
+ var shell = {
3182
+ info: {
3183
+ key: "shell",
3184
+ title: "Shell",
3185
+ extname: ".sh",
3186
+ default: "curl",
3187
+ cli: "%s"
3188
+ },
3189
+ clientsById: {
3190
+ curl: curl2,
3191
+ httpie,
3192
+ wget
3193
+ }
3194
+ };
3195
+
3196
+ // src/targets/swift/helpers.ts
3197
+ var buildString = (length, str) => str.repeat(length);
3198
+ var concatArray = (arr, pretty, indentation, indentLevel) => {
3199
+ const currentIndent = buildString(indentLevel, indentation);
3200
+ const closingBraceIndent = buildString(indentLevel - 1, indentation);
3201
+ const join = pretty ? `,
3202
+ ${currentIndent}` : ", ";
3203
+ if (pretty) {
3204
+ return `[
3205
+ ${currentIndent}${arr.join(join)}
3206
+ ${closingBraceIndent}]`;
3207
+ }
3208
+ return `[${arr.join(join)}]`;
3209
+ };
3210
+ var literalDeclaration = (name, parameters, opts) => `let ${name} = ${literalRepresentation3(parameters, opts)}`;
3211
+ var literalRepresentation3 = (value, opts, indentLevel) => {
3212
+ indentLevel = indentLevel === void 0 ? 1 : indentLevel + 1;
3213
+ switch (Object.prototype.toString.call(value)) {
3214
+ case "[object Number]":
3215
+ return value;
3216
+ case "[object Array]": {
3217
+ let pretty = false;
3218
+ const valuesRepresentation = value.map((v) => {
3219
+ if (Object.prototype.toString.call(v) === "[object Object]") {
3220
+ pretty = Object.keys(v).length > 1;
3221
+ }
3222
+ return literalRepresentation3(v, opts, indentLevel);
3223
+ });
3224
+ return concatArray(valuesRepresentation, pretty, opts.indent, indentLevel);
3225
+ }
3226
+ case "[object Object]": {
3227
+ const keyValuePairs = [];
3228
+ for (const key in value) {
3229
+ keyValuePairs.push(`"${key}": ${literalRepresentation3(value[key], opts, indentLevel)}`);
3230
+ }
3231
+ return concatArray(
3232
+ keyValuePairs,
3233
+ // @ts-expect-error needs better types
3234
+ opts.pretty && keyValuePairs.length > 1,
3235
+ // @ts-expect-error needs better types
3236
+ opts.indent,
3237
+ indentLevel
3238
+ );
3239
+ }
3240
+ case "[object Boolean]":
3241
+ return value.toString();
3242
+ default:
3243
+ if (value === null || value === void 0) {
3244
+ return "";
3245
+ }
3246
+ return `"${value.toString().replace(/"/g, '\\"')}"`;
3247
+ }
3248
+ };
3249
+
3250
+ // src/targets/swift/nsurlsession/client.ts
3251
+ var nsurlsession2 = {
3252
+ info: {
3253
+ key: "nsurlsession",
3254
+ title: "NSURLSession",
3255
+ link: "https://developer.apple.com/library/mac/documentation/Foundation/Reference/NSURLSession_class/index.html",
3256
+ description: "Foundation's NSURLSession request"
3257
+ },
3258
+ convert: ({ allHeaders, postData, fullUrl, method }, options) => {
3259
+ const opts = {
3260
+ indent: " ",
3261
+ pretty: true,
3262
+ timeout: "10",
3263
+ ...options
3264
+ };
3265
+ const { push, blank, join } = new CodeBuilder({ indent: opts.indent });
3266
+ const req = {
3267
+ hasHeaders: false,
3268
+ hasBody: false
3269
+ };
3270
+ push("import Foundation");
3271
+ if (Object.keys(allHeaders).length) {
3272
+ req.hasHeaders = true;
3273
+ blank();
3274
+ push(literalDeclaration("headers", allHeaders, opts));
3275
+ }
3276
+ if (postData.text || postData.jsonObj || postData.params) {
3277
+ req.hasBody = true;
3278
+ switch (postData.mimeType) {
3279
+ case "application/x-www-form-urlencoded":
3280
+ blank();
3281
+ if (postData.params?.length) {
3282
+ const [head, ...tail] = postData.params;
3283
+ push(`let postData = NSMutableData(data: "${head.name}=${head.value}".data(using: String.Encoding.utf8)!)`);
3284
+ tail.forEach(({ name, value }) => {
3285
+ push(`postData.append("&${name}=${value}".data(using: String.Encoding.utf8)!)`);
3286
+ });
3287
+ } else {
3288
+ req.hasBody = false;
3289
+ }
3290
+ break;
3291
+ case "application/json":
3292
+ if (postData.jsonObj) {
3293
+ push(`${literalDeclaration("parameters", postData.jsonObj, opts)} as [String : Any]`);
3294
+ blank();
3295
+ push("let postData = JSONSerialization.data(withJSONObject: parameters, options: [])");
3296
+ }
3297
+ break;
3298
+ case "multipart/form-data":
3299
+ push(literalDeclaration("parameters", postData.params, opts));
3300
+ blank();
3301
+ push(`let boundary = "${postData.boundary}"`);
3302
+ blank();
3303
+ push('var body = ""');
3304
+ push("var error: NSError? = nil");
3305
+ push("for param in parameters {");
3306
+ push('let paramName = param["name"]!', 1);
3307
+ push('body += "--\\(boundary)\\r\\n"', 1);
3308
+ push('body += "Content-Disposition:form-data; name=\\"\\(paramName)\\""', 1);
3309
+ push('if let filename = param["fileName"] {', 1);
3310
+ push('let contentType = param["content-type"]!', 2);
3311
+ push("let fileContent = String(contentsOfFile: filename, encoding: String.Encoding.utf8)", 2);
3312
+ push("if (error != nil) {", 2);
3313
+ push("print(error as Any)", 3);
3314
+ push("}", 2);
3315
+ push('body += "; filename=\\"\\(filename)\\"\\r\\n"', 2);
3316
+ push('body += "Content-Type: \\(contentType)\\r\\n\\r\\n"', 2);
3317
+ push("body += fileContent", 2);
3318
+ push('} else if let paramValue = param["value"] {', 1);
3319
+ push('body += "\\r\\n\\r\\n\\(paramValue)"', 2);
3320
+ push("}", 1);
3321
+ push("}");
3322
+ break;
3323
+ default:
3324
+ blank();
3325
+ push(`let postData = NSData(data: "${postData.text}".data(using: String.Encoding.utf8)!)`);
3326
+ }
3327
+ }
3328
+ blank();
3329
+ push(`let request = NSMutableURLRequest(url: NSURL(string: "${fullUrl}")! as URL,`);
3330
+ push(" cachePolicy: .useProtocolCachePolicy,");
3331
+ push(
3332
+ // @ts-expect-error needs better types
3333
+ ` timeoutInterval: ${parseInt(opts.timeout, 10).toFixed(1)})`
3334
+ );
3335
+ push(`request.httpMethod = "${method}"`);
3336
+ if (req.hasHeaders) {
3337
+ push("request.allHTTPHeaderFields = headers");
3338
+ }
3339
+ if (req.hasBody) {
3340
+ push("request.httpBody = postData as Data");
3341
+ }
3342
+ blank();
3343
+ push("let session = URLSession.shared");
3344
+ push(
3345
+ "let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in"
3346
+ );
3347
+ push("if (error != nil) {", 1);
3348
+ push("print(error as Any)", 2);
3349
+ push("} else {", 1);
3350
+ push("let httpResponse = response as? HTTPURLResponse", 2);
3351
+ push("print(httpResponse)", 2);
3352
+ push("}", 1);
3353
+ push("})");
3354
+ blank();
3355
+ push("dataTask.resume()");
3356
+ return join();
3357
+ }
3358
+ };
3359
+
3360
+ // src/targets/swift/target.ts
3361
+ var swift = {
3362
+ info: {
3363
+ key: "swift",
3364
+ title: "Swift",
3365
+ extname: ".swift",
3366
+ default: "nsurlsession"
3367
+ },
3368
+ clientsById: {
3369
+ nsurlsession: nsurlsession2
3370
+ }
3371
+ };
3372
+
3373
+ // src/targets/targets.ts
3374
+ var targets = {
3375
+ c,
3376
+ clojure,
3377
+ csharp,
3378
+ go,
3379
+ http,
3380
+ java,
3381
+ javascript,
3382
+ json,
3383
+ kotlin,
3384
+ node,
3385
+ objc,
3386
+ ocaml,
3387
+ php,
3388
+ powershell,
3389
+ python,
3390
+ r,
3391
+ ruby,
3392
+ shell,
3393
+ swift
3394
+ };
3395
+ var isTarget = (target) => {
3396
+ if (typeof target !== "object" || target === null || Array.isArray(target)) {
3397
+ const got = target === null ? "null" : Array.isArray(target) ? "array" : typeof target;
3398
+ throw new Error(`you tried to add a target which is not an object, got type: "${got}"`);
3399
+ }
3400
+ if (!Object.prototype.hasOwnProperty.call(target, "info")) {
3401
+ throw new Error("targets must contain an `info` object");
3402
+ }
3403
+ if (!Object.prototype.hasOwnProperty.call(target.info, "key")) {
3404
+ throw new Error("targets must have an `info` object with the property `key`");
3405
+ }
3406
+ if (!target.info.key) {
3407
+ throw new Error("target key must be a unique string");
3408
+ }
3409
+ if (Object.prototype.hasOwnProperty.call(targets, target.info.key)) {
3410
+ throw new Error(`a target already exists with this key, \`${target.info.key}\``);
3411
+ }
3412
+ if (!Object.prototype.hasOwnProperty.call(target.info, "title")) {
3413
+ throw new Error("targets must have an `info` object with the property `title`");
3414
+ }
3415
+ if (!target.info.title) {
3416
+ throw new Error("target title must be a non-zero-length string");
3417
+ }
3418
+ if (!Object.prototype.hasOwnProperty.call(target.info, "extname")) {
3419
+ throw new Error("targets must have an `info` object with the property `extname`");
3420
+ }
3421
+ if (!Object.prototype.hasOwnProperty.call(target, "clientsById") || !target.clientsById || Object.keys(target.clientsById).length === 0) {
3422
+ throw new Error(
3423
+ `No clients provided in target ${target.info.key}. You must provide the property \`clientsById\` containg your clients.`
3424
+ );
3425
+ }
3426
+ if (!Object.prototype.hasOwnProperty.call(target.info, "default")) {
3427
+ throw new Error("targets must have an `info` object with the property `default`");
3428
+ }
3429
+ if (!Object.prototype.hasOwnProperty.call(target.clientsById, target.info.default)) {
3430
+ throw new Error(
3431
+ `target ${target.info.key} is configured with a default client ${target.info.default}, but no such client was found in the property \`clientsById\` (found ${JSON.stringify(
3432
+ Object.keys(target.clientsById)
3433
+ )})`
3434
+ );
3435
+ }
3436
+ Object.values(target.clientsById).forEach(isClient);
3437
+ return true;
3438
+ };
3439
+ var addTarget = (target) => {
3440
+ if (!isTarget(target)) ;
3441
+ targets[target.info.key] = target;
3442
+ };
3443
+ var isClient = (client) => {
3444
+ if (!client) {
3445
+ throw new Error("clients must be objects");
3446
+ }
3447
+ if (!Object.prototype.hasOwnProperty.call(client, "info")) {
3448
+ throw new Error("targets client must contain an `info` object");
3449
+ }
3450
+ if (!Object.prototype.hasOwnProperty.call(client.info, "key")) {
3451
+ throw new Error("targets client must have an `info` object with property `key`");
3452
+ }
3453
+ if (!client.info.key) {
3454
+ throw new Error("client.info.key must contain an identifier unique to this target");
3455
+ }
3456
+ if (!Object.prototype.hasOwnProperty.call(client.info, "title")) {
3457
+ throw new Error("targets client must have an `info` object with property `title`");
3458
+ }
3459
+ if (!Object.prototype.hasOwnProperty.call(client.info, "description")) {
3460
+ throw new Error("targets client must have an `info` object with property `description`");
3461
+ }
3462
+ if (!Object.prototype.hasOwnProperty.call(client.info, "link")) {
3463
+ throw new Error("targets client must have an `info` object with property `link`");
3464
+ }
3465
+ if (!Object.prototype.hasOwnProperty.call(client, "convert") || typeof client.convert !== "function") {
3466
+ throw new Error("targets client must have a `convert` property containing a conversion function");
3467
+ }
3468
+ return true;
3469
+ };
3470
+ var addTargetClient = (targetId, client) => {
3471
+ if (!isClient(client)) ;
3472
+ if (!Object.prototype.hasOwnProperty.call(targets, targetId)) {
3473
+ throw new Error(`Sorry, but no ${targetId} target exists to add clients to`);
3474
+ }
3475
+ if (Object.prototype.hasOwnProperty.call(targets[targetId], client.info.key)) {
3476
+ throw new Error(
3477
+ `the target ${targetId} already has a client with the key ${client.info.key}, please use a different key`
3478
+ );
3479
+ }
3480
+ targets[targetId].clientsById[client.info.key] = client;
3481
+ };
3482
+
3483
+ export { addTarget, addTargetClient, getHeaderName, isClient, isTarget, targets };
3484
+ //# sourceMappingURL=out.js.map
3485
+ //# sourceMappingURL=chunk-XPUGYZ4Y.mjs.map