@piyushdoorwar/yamlet 1.1.1 → 1.1.3

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 (2) hide show
  1. package/dist/yamlet.js +26 -9
  2. package/package.json +1 -1
package/dist/yamlet.js CHANGED
@@ -9,7 +9,19 @@ import { existsSync, promises as fs } from "node:fs";
9
9
  import { STATUS_CODES } from "node:http";
10
10
  import path from "node:path";
11
11
  import { performance } from "node:perf_hooks";
12
- import { Agent, FormData, request as request2 } from "undici";
12
+ import { FormData, request as request2 } from "undici";
13
+
14
+ // core/src/agents.ts
15
+ import { Agent } from "undici";
16
+ var ATTEMPT_TIMEOUT_MS = 2500;
17
+ var standard;
18
+ var insecure;
19
+ function defaultAgent() {
20
+ return standard ??= new Agent({ autoSelectFamily: true, autoSelectFamilyAttemptTimeout: ATTEMPT_TIMEOUT_MS });
21
+ }
22
+ function insecureAgent() {
23
+ return insecure ??= new Agent({ autoSelectFamily: true, autoSelectFamilyAttemptTimeout: ATTEMPT_TIMEOUT_MS, connect: { rejectUnauthorized: false } });
24
+ }
13
25
 
14
26
  // core/src/cookieJar.ts
15
27
  function parseSetCookie(header) {
@@ -271,7 +283,13 @@ function newCollection(partial = {}) {
271
283
  function newEnvironment(partial = {}) {
272
284
  return { id: newId(), name: "New Environment", variables: [], ...partial };
273
285
  }
274
- var YAMLET_USER_AGENT = "Yamlet/1.0.0";
286
+ var yamletVersion = "dev";
287
+ function setYamletVersion(version) {
288
+ yamletVersion = version.trim().replace(/^v(?=\d)/, "") || "dev";
289
+ }
290
+ function yamletUserAgent() {
291
+ return `Yamlet/${yamletVersion}`;
292
+ }
275
293
 
276
294
  // core/src/oauth2.ts
277
295
  import { request } from "undici";
@@ -319,7 +337,7 @@ async function requestToken(cfg, resolve2, form, opts = {}) {
319
337
  method: "POST",
320
338
  headers,
321
339
  body: body.toString(),
322
- dispatcher: opts.dispatcher,
340
+ dispatcher: opts.dispatcher ?? defaultAgent(),
323
341
  signal: opts.signal
324
342
  });
325
343
  const text = await res.body.text();
@@ -750,7 +768,7 @@ function buildRequest(request3, opts) {
750
768
  );
751
769
  const query = (request3.queryParams ?? []).filter((p) => p.enabled !== false && p.key?.trim()).map((p) => ({ key: r(p.key), value: r(p.value) }));
752
770
  url = appendQuery(url, query);
753
- const headers = [{ key: "User-Agent", value: YAMLET_USER_AGENT, enabled: true }];
771
+ const headers = [{ key: "User-Agent", value: yamletUserAgent(), enabled: true }];
754
772
  for (const h of request3.headers ?? []) {
755
773
  if (h.enabled === false || !h.key?.trim()) continue;
756
774
  const key = r(h.key).trim();
@@ -1455,8 +1473,6 @@ ${opts.script}
1455
1473
 
1456
1474
  // core/src/requestExecutor.ts
1457
1475
  var MAX_REDIRECTS = 10;
1458
- var insecure;
1459
- var insecureAgent = () => insecure ??= new Agent({ connect: { rejectUnauthorized: false } });
1460
1476
  var NETWORK_HINTS = {
1461
1477
  ENOTFOUND: "host name could not be resolved",
1462
1478
  EAI_AGAIN: "DNS lookup timed out",
@@ -1673,7 +1689,7 @@ function errorResponse(base, message) {
1673
1689
  async function scriptSend(spec, input, dispatcher) {
1674
1690
  const base = emptyResponse(spec.method, spec.url);
1675
1691
  try {
1676
- const headers = spec.headers.some((h) => h.key.toLowerCase() === "user-agent") ? spec.headers : [{ key: "User-Agent", value: YAMLET_USER_AGENT, enabled: true }, ...spec.headers];
1692
+ const headers = spec.headers.some((h) => h.key.toLowerCase() === "user-agent") ? spec.headers : [{ key: "User-Agent", value: yamletUserAgent(), enabled: true }, ...spec.headers];
1677
1693
  const ex = await exchange({ url: spec.url, method: spec.method, headers, body: spec.body, dispatcher, signal: input.signal, followRedirects: true, jar: input.cookieJar });
1678
1694
  const contentType = headerValue(ex.headers, "content-type") ?? "";
1679
1695
  const textual = isTextual(contentType, ex.bytes);
@@ -1709,7 +1725,7 @@ async function execute(input) {
1709
1725
  const tests = [];
1710
1726
  const logs = [];
1711
1727
  const settings = { ...defaultSettings(), ...req.settings };
1712
- const dispatcher = input.dispatcher ?? (settings.skipSslVerification ? insecureAgent() : void 0);
1728
+ const dispatcher = input.dispatcher ?? (settings.skipSslVerification ? insecureAgent() : defaultAgent());
1713
1729
  const scriptBase = {
1714
1730
  request: req,
1715
1731
  variables: vars,
@@ -3341,7 +3357,8 @@ function ensureUniqueIds(ws, rel) {
3341
3357
  }
3342
3358
 
3343
3359
  // cli/src/index.ts
3344
- var VERSION = true ? "0.0.0-dev" : "0.0.0-dev";
3360
+ var VERSION = true ? "1.1.3" : "0.0.0-dev";
3361
+ setYamletVersion(VERSION);
3345
3362
  var CliError = class extends Error {
3346
3363
  };
3347
3364
  var USAGE = `Yamlet CLI: run Yamlet API collections headlessly.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@piyushdoorwar/yamlet",
3
- "version": "1.1.1",
3
+ "version": "1.1.3",
4
4
  "description": "Run Yamlet API collections (Git-friendly YAML) from the command line or CI.",
5
5
  "type": "module",
6
6
  "bin": {