azdo-cli 0.25.0-feature-devcontainer-caddy-proxy.943 → 0.25.0-feature-devcontainer-caddy-proxy.947

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/index.js +36 -13
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -406,23 +406,44 @@ var DEFAULT_FIELDS = [
406
406
  "System.AreaPath",
407
407
  "System.IterationPath"
408
408
  ];
409
- var ROUTED_API_HOSTS = {
410
- "dev.azure.com": "",
409
+ var ROUTED_API_HOSTS = /* @__PURE__ */ new Map([
410
+ ["dev.azure.com", ""],
411
411
  // "_vssps" cannot be an organization name, so it never clashes with /<org>/.
412
- "vssps.dev.azure.com": "/_vssps"
413
- };
412
+ ["vssps.dev.azure.com", "/_vssps"]
413
+ ]);
414
+ var LEGACY_ORG_HOST = /^([a-z0-9][a-z0-9-]*)\.visualstudio\.com$/i;
415
+ function readApiBase() {
416
+ const raw = process.env.AZDO_API_BASE_URL?.trim();
417
+ if (!raw) return null;
418
+ let base;
419
+ try {
420
+ base = new URL(raw);
421
+ } catch (err) {
422
+ throw new Error(`INVALID_CONFIG: AZDO_API_BASE_URL must be an absolute http(s) URL, got "${raw}"`, { cause: err });
423
+ }
424
+ if (base.protocol !== "http:" && base.protocol !== "https:") {
425
+ throw new Error(`INVALID_CONFIG: AZDO_API_BASE_URL must be an absolute http(s) URL, got "${raw}"`);
426
+ }
427
+ return base;
428
+ }
429
+ function proxiedPath(original) {
430
+ const prefix = ROUTED_API_HOSTS.get(original.hostname);
431
+ if (prefix !== void 0) return { prefix, pathname: original.pathname };
432
+ const legacy = LEGACY_ORG_HOST.exec(original.hostname);
433
+ if (legacy === null) return null;
434
+ const pathname = original.pathname.replace(/^\/DefaultCollection(?=\/)/i, "");
435
+ return { prefix: "", pathname: `/${legacy[1]}${pathname}` };
436
+ }
414
437
  function routeAzureDevOpsApiUrl(url) {
415
- const proxyBase = process.env.AZDO_API_BASE_URL?.trim();
416
- if (!proxyBase) return url;
438
+ const base = readApiBase();
439
+ if (base === null) return url;
417
440
  const original = new URL(url);
418
- const hostPrefix = ROUTED_API_HOSTS[original.hostname];
419
- if (hostPrefix === void 0 || !original.pathname.includes("/_apis/")) return url;
420
- const base = new URL(proxyBase);
421
- const basePath = base.pathname.replace(/\/$/, "");
441
+ const target = proxiedPath(original);
442
+ if (!target?.pathname.includes("/_apis/")) return url;
422
443
  original.protocol = base.protocol;
423
444
  original.hostname = base.hostname;
424
445
  original.port = base.port;
425
- original.pathname = `${basePath}${hostPrefix}${original.pathname}`;
446
+ original.pathname = `${base.pathname.replace(/\/$/, "")}${target.prefix}${target.pathname}`;
426
447
  return original.toString();
427
448
  }
428
449
  function authHeaders(credentialOrPat) {
@@ -437,9 +458,10 @@ function authHeaders(credentialOrPat) {
437
458
  return { Authorization: `Basic ${token}` };
438
459
  }
439
460
  async function fetchRaw(url, init) {
461
+ const routedUrl = routeAzureDevOpsApiUrl(url);
440
462
  let response;
441
463
  try {
442
- response = await fetch(routeAzureDevOpsApiUrl(url), init);
464
+ response = await fetch(routedUrl, init);
443
465
  } catch (err) {
444
466
  throw new Error(`NETWORK_ERROR: ${err instanceof Error ? err.message : String(err)}`, { cause: err });
445
467
  }
@@ -536,9 +558,10 @@ async function traceResponse(url, init, response) {
536
558
  return responseBody;
537
559
  }
538
560
  async function fetchWithErrors(url, init) {
561
+ const routedUrl = routeAzureDevOpsApiUrl(url);
539
562
  let response;
540
563
  try {
541
- response = await fetch(routeAzureDevOpsApiUrl(url), init);
564
+ response = await fetch(routedUrl, init);
542
565
  } catch (err) {
543
566
  throw new Error("NETWORK_ERROR", { cause: err });
544
567
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "azdo-cli",
3
- "version": "0.25.0-feature-devcontainer-caddy-proxy.943",
3
+ "version": "0.25.0-feature-devcontainer-caddy-proxy.947",
4
4
  "description": "Azure DevOps CLI tool",
5
5
  "type": "module",
6
6
  "bin": {