run402 4.158.1 → 4.159.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "run402",
3
- "version": "4.158.1",
3
+ "version": "4.159.0",
4
4
  "description": "CLI for Run402 — full-stack backend infrastructure for AI agents: Postgres, auth, storage, serverless functions and atomic deploys. Paid with x402/MPP. Includes $0.03 image generation.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -1 +1 @@
1
- {"version":3,"file":"deploy.d.ts","sourceRoot":"","sources":["../../src/namespaces/deploy.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAGH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAwB3C,OAAO,KAAK,EACV,YAAY,EACZ,sBAAsB,EAQtB,WAAW,EACX,oBAAoB,EAEpB,iBAAiB,EACjB,kBAAkB,EAClB,eAAe,EACf,YAAY,EACZ,oBAAoB,EACpB,qBAAqB,EACrB,mBAAmB,EACnB,wBAAwB,EACxB,uBAAuB,EAOvB,sBAAsB,EACtB,oBAAoB,EAUpB,iBAAiB,EAGjB,YAAY,EACZ,cAAc,EACd,aAAa,EACb,kBAAkB,EAClB,gBAAgB,EAChB,2BAA2B,EAC3B,uBAAuB,EACvB,WAAW,EACX,oBAAoB,EACpB,mBAAmB,EACnB,kBAAkB,EAGlB,YAAY,EAEb,MAAM,mBAAmB,CAAC;AAwH3B,qBAAa,MAAM;IACL,OAAO,CAAC,QAAQ,CAAC,MAAM;IAAnC,YAA6B,MAAM,EAAE,MAAM,EAAI;IAE/C;;;;OAIG;IACG,KAAK,CAAC,IAAI,EAAE,WAAW,EAAE,IAAI,GAAE,YAAiB,GAAG,OAAO,CAAC,YAAY,CAAC,CAiD7E;IAED;;;OAGG;IACH,KAAK,CAAC,IAAI,EAAE,WAAW,EAAE,IAAI,GAAE,YAAiB,GAAG,OAAO,C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A;KAAE,GACxB,OAAO,CAAC,mBAAmB,CAAC,CAuB9B;IAED;;;;OAIG;IACG,gBAAgB,CACpB,WAAW,EAAE,MAAM,EACnB,IAAI,EAAE,wBAAwB,GAC7B,OAAO,CAAC,uBAAuB,CAAC,CAkClC;IAED;;;;OAIG;IACG,UAAU,CAAC,IAAI,EAAE,2BAA2B,GAAG,OAAO,CAAC,gBAAgB,CAAC,CA2B7E;IAED;;;;OAIG;IACG,gBAAgB,CACpB,IAAI,EAAE,uBAAuB,GAC5B,OAAO,CAAC,sBAAsB,CAAC,CAmBjC;IAED;;;;OAIG;IACG,IAAI,CAAC,IAAI,EAAE,kBAAkB,GAAG,OAAO,CAAC,oBAAoB,CAAC,CA6BlE;IAED;;;;OAIG;IACG,OAAO,CAAC,IAAI,EAAE,oBAAoB,GAAG,OAAO,CAAC,qBAAqB,CAAC,CAUxE;CACF;AA42DD;;;;;GAKG;AACH,MAAM,WAAW,UAAU;IACzB,IAAI,OAAO,CAAC,UAAU,CAAC,CAAC;IACxB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;;iEAG6D;IAC7D,KAAK,CAAC,EAAE,SAAS,GAAG,OAAO,GAAG,OAAO,CAAC;CACvC;AA8qFD,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAKrD"}
@@ -88,30 +88,6 @@ const STATIC_ACTIVATION_FAILURE_CODES = new Set([
88
88
  "FUNCTION_SCHEDULE_LIMIT_EXCEEDED",
89
89
  "TIER_LIMIT_EXCEEDED",
90
90
  ]);
91
- const STATIC_FUNCTION_LIMITS_BY_TIER = {
92
- prototype: {
93
- maxTimeoutSeconds: 10,
94
- maxMemoryMb: 128,
95
- maxSsrMemoryMb: 128,
96
- maxScheduledFunctions: 1,
97
- minCronIntervalMinutes: 15,
98
- },
99
- hobby: {
100
- maxTimeoutSeconds: 30,
101
- maxMemoryMb: 256,
102
- maxSsrMemoryMb: 256,
103
- maxScheduledFunctions: 3,
104
- minCronIntervalMinutes: 5,
105
- },
106
- team: {
107
- maxTimeoutSeconds: 60,
108
- maxMemoryMb: 512,
109
- // An SSR-class function (the Astro `ssr` function) may use one vCPU.
110
- maxSsrMemoryMb: 1769,
111
- maxScheduledFunctions: 10,
112
- minCronIntervalMinutes: 1,
113
- },
114
- };
115
91
  const MANIFEST_CONTENT_TYPE = "application/vnd.run402.deploy-manifest+json";
116
92
  const TERMINAL_STATUSES = ["ready", "failed"];
117
93
  const SUCCESS_STATUS = "ready";
@@ -1260,8 +1236,6 @@ async function planInternal(client, spec, idempotencyKey, opts = {}) {
1260
1236
  const { normalized, byteReaders } = await normalizeReleaseSpec(client, spec, {
1261
1237
  inlineMigrationSql: isCore,
1262
1238
  });
1263
- if (!isCore)
1264
- await preflightTierFunctionLimits(client, normalized, ciCredentials);
1265
1239
  const wireSpec = isCore ? releaseSpecToCoreSpec(normalized) : releaseSpecToWire(normalized);
1266
1240
  // The gateway expects { spec, manifest_ref?, idempotency_key? }. Cloud
1267
1241
  // receives the legacy snake_case apply wire shape; Core receives the
@@ -1346,389 +1320,6 @@ function requiredPlanToWire(plan) {
1346
1320
  wire.plan_fingerprint = plan.planFingerprint;
1347
1321
  return wire;
1348
1322
  }
1349
- async function preflightTierFunctionLimits(client, spec, ciCredentials) {
1350
- if (ciCredentials)
1351
- return;
1352
- if (!hasFunctionTierPreflightInputs(spec.functions))
1353
- return;
1354
- const limits = await readTierFunctionLimits(client, spec.project_id);
1355
- if (!limits)
1356
- return;
1357
- const entries = collectFunctionPreflightEntries(spec.functions);
1358
- for (const entry of entries) {
1359
- const timeout = entry.fn.config?.timeoutSeconds;
1360
- if (timeout !== undefined &&
1361
- limits.maxTimeoutSeconds &&
1362
- timeout > limits.maxTimeoutSeconds.value) {
1363
- throw tierLimitError(`Function ${entry.name} timeoutSeconds ${timeout} exceeds the ${limits.tier} tier maximum of ${limits.maxTimeoutSeconds.value}.`, `${entry.fieldPrefix}.config.timeoutSeconds`, timeout, limits, limits.maxTimeoutSeconds, {
1364
- tier_max: limits.maxTimeoutSeconds.value,
1365
- max_function_timeout_seconds: limits.maxTimeoutSeconds.value,
1366
- });
1367
- }
1368
- const memory = entry.fn.config?.memoryMb;
1369
- // An SSR-class function has its own cap. With no class declared the
1370
- // function keeps its stored one, which only the gateway knows.
1371
- const memoryLimit = entry.fn.class === "ssr"
1372
- ? limits.maxSsrMemoryMb ?? limits.maxMemoryMb
1373
- : entry.fn.class === undefined
1374
- ? largerLimit(limits.maxMemoryMb, limits.maxSsrMemoryMb)
1375
- : limits.maxMemoryMb;
1376
- if (memory !== undefined &&
1377
- memoryLimit &&
1378
- memory > memoryLimit.value) {
1379
- throw tierLimitError(`Function ${entry.name} memoryMb ${memory} exceeds the ${limits.tier} tier maximum of ${memoryLimit.value}.`, `${entry.fieldPrefix}.config.memoryMb`, memory, limits, memoryLimit, {
1380
- tier_max: memoryLimit.value,
1381
- max_function_memory_mb: memoryLimit.value,
1382
- });
1383
- }
1384
- for (const trigger of scheduleTriggersForFunction(entry.fn)) {
1385
- if (!limits.minCronIntervalMinutes)
1386
- continue;
1387
- const intervalMinutes = estimateCronMinimumIntervalMinutes(trigger.cron);
1388
- if (intervalMinutes !== null &&
1389
- intervalMinutes < limits.minCronIntervalMinutes.value) {
1390
- const triggerLabel = trigger.id ? `trigger ${trigger.id}` : "schedule trigger";
1391
- throw tierLimitError(`Function ${entry.name} ${triggerLabel} runs every ${intervalMinutes} minute(s), below the ${limits.tier} tier minimum interval of ${limits.minCronIntervalMinutes.value} minutes.`, `${entry.fieldPrefix}.${trigger.fieldSuffix}`, trigger.cron, limits, limits.minCronIntervalMinutes, {
1392
- interval_minutes: intervalMinutes,
1393
- min_interval_minutes: limits.minCronIntervalMinutes.value,
1394
- min_cron_interval_minutes: limits.minCronIntervalMinutes.value,
1395
- });
1396
- }
1397
- }
1398
- }
1399
- if (limits.maxScheduledFunctions) {
1400
- const lowerBound = countScheduledFunctionsInSetEntries(spec.functions);
1401
- if (lowerBound > limits.maxScheduledFunctions.value) {
1402
- throw scheduledCountTierLimitError(lowerBound, limits, limits.maxScheduledFunctions, "manifest");
1403
- }
1404
- const desired = await computeDesiredScheduledFunctionCount(client, spec);
1405
- if (desired && desired.count > limits.maxScheduledFunctions.value) {
1406
- throw scheduledCountTierLimitError(desired.count, limits, limits.maxScheduledFunctions, desired.source);
1407
- }
1408
- }
1409
- }
1410
- function largerLimit(a, b) {
1411
- if (!a)
1412
- return b;
1413
- if (!b)
1414
- return a;
1415
- return b.value > a.value ? b : a;
1416
- }
1417
- function hasFunctionTierPreflightInputs(functions) {
1418
- if (!functions)
1419
- return false;
1420
- return collectFunctionPreflightEntries(functions).some((entry) => (entry.fn.config?.timeoutSeconds !== undefined ||
1421
- entry.fn.config?.memoryMb !== undefined ||
1422
- scheduleTriggersForFunction(entry.fn).length > 0));
1423
- }
1424
- function collectFunctionPreflightEntries(functions) {
1425
- if (!functions)
1426
- return [];
1427
- const entries = [];
1428
- for (const [name, fn] of Object.entries(functions.replace ?? {})) {
1429
- entries.push({ name, fn, fieldPrefix: `functions.${name}` });
1430
- }
1431
- for (const [name, fn] of Object.entries(functions.patch?.set ?? {})) {
1432
- entries.push({ name, fn, fieldPrefix: `functions.${name}` });
1433
- }
1434
- return entries;
1435
- }
1436
- /**
1437
- * The function caps of the tier the deploy is judged by: the tier of the
1438
- * organization that owns the project. `/tiers/v1/status` describes the
1439
- * wallet's own organization, so its caps count only when the project's tier
1440
- * is the same; otherwise the static table for the project's tier applies.
1441
- * When the project cannot be read, the wallet's own tier is used.
1442
- */
1443
- async function readTierFunctionLimits(client, projectId) {
1444
- let status;
1445
- try {
1446
- status = await client.request("/tiers/v1/status", {
1447
- context: "checking tier status for deploy preflight",
1448
- });
1449
- }
1450
- catch {
1451
- return null;
1452
- }
1453
- const projectTier = await readProjectTier(client, projectId);
1454
- let walletTier;
1455
- if (projectTier && projectTier.toLowerCase() !== String(status.tier ?? "").toLowerCase()) {
1456
- walletTier = typeof status.tier === "string" ? status.tier : "";
1457
- status = { tier: projectTier };
1458
- }
1459
- if (typeof status.tier !== "string" || status.tier.length === 0) {
1460
- return null;
1461
- }
1462
- const tierKey = status.tier.toLowerCase();
1463
- const fallback = STATIC_FUNCTION_LIMITS_BY_TIER[tierKey];
1464
- const limits = { tier: status.tier };
1465
- if (walletTier !== undefined)
1466
- limits.walletTier = walletTier;
1467
- limits.maxTimeoutSeconds = tierStatusLimitOrFallback(status, [
1468
- "max_function_timeout_seconds",
1469
- "max_timeout_seconds",
1470
- "timeout_seconds_max",
1471
- "function_timeout_seconds_max",
1472
- ], fallback?.maxTimeoutSeconds);
1473
- limits.maxMemoryMb = tierStatusLimitOrFallback(status, [
1474
- "max_function_memory_mb",
1475
- "max_memory_mb",
1476
- "memory_mb_max",
1477
- "function_memory_mb_max",
1478
- ], fallback?.maxMemoryMb);
1479
- // tier status names no SSR memory cap, so it comes from the static table.
1480
- if (fallback)
1481
- limits.maxSsrMemoryMb = { value: fallback.maxSsrMemoryMb, source: "local_static_fallback" };
1482
- limits.maxScheduledFunctions = tierStatusLimitOrFallback(status, [
1483
- "max_scheduled_functions",
1484
- "scheduled_functions_limit",
1485
- "scheduled_function_limit",
1486
- "max_function_schedules",
1487
- ], fallback?.maxScheduledFunctions);
1488
- limits.minCronIntervalMinutes = tierStatusLimitOrFallback(status, [
1489
- "min_cron_interval_minutes",
1490
- "minimum_cron_interval_minutes",
1491
- "min_schedule_interval_minutes",
1492
- "min_scheduled_function_interval_minutes",
1493
- ], fallback?.minCronIntervalMinutes);
1494
- limits.currentScheduledFunctions = tierStatusLimit(status, [
1495
- "current_scheduled_functions",
1496
- "current_scheduled_function_count",
1497
- "scheduled_function_count",
1498
- "scheduled_functions",
1499
- ]);
1500
- return hasAnyTierFunctionLimit(limits) ? limits : null;
1501
- }
1502
- async function readProjectTier(client, projectId) {
1503
- try {
1504
- const project = await client.request(`/projects/v1/${encodeURIComponent(projectId)}`, {
1505
- method: "GET",
1506
- context: "checking the project's tier for deploy preflight",
1507
- });
1508
- return typeof project.tier === "string" && project.tier.length > 0 ? project.tier : null;
1509
- }
1510
- catch {
1511
- return null;
1512
- }
1513
- }
1514
- function tierStatusLimitOrFallback(status, keys, fallback) {
1515
- return tierStatusLimit(status, keys) ?? (fallback === undefined
1516
- ? undefined
1517
- : { value: fallback, source: "local_static_fallback" });
1518
- }
1519
- function tierStatusLimit(status, keys) {
1520
- const limits = objectField(status, "limits");
1521
- const containers = [
1522
- objectField(status, "function_limits"),
1523
- objectField(limits, "functions"),
1524
- objectField(limits, "function_limits"),
1525
- objectField(status, "pool_usage"),
1526
- status,
1527
- ];
1528
- for (const container of containers) {
1529
- if (!container || typeof container !== "object" || Array.isArray(container))
1530
- continue;
1531
- const obj = container;
1532
- for (const key of keys) {
1533
- const value = obj[key];
1534
- if (typeof value === "number" && Number.isFinite(value) && value >= 0) {
1535
- return { value, source: "tier_status" };
1536
- }
1537
- }
1538
- }
1539
- return undefined;
1540
- }
1541
- function hasAnyTierFunctionLimit(limits) {
1542
- return Boolean(limits.maxTimeoutSeconds ||
1543
- limits.maxMemoryMb ||
1544
- limits.maxScheduledFunctions ||
1545
- limits.minCronIntervalMinutes ||
1546
- limits.currentScheduledFunctions);
1547
- }
1548
- async function computeDesiredScheduledFunctionCount(client, spec) {
1549
- const functions = spec.functions;
1550
- if (!functions)
1551
- return null;
1552
- const replaceScheduled = scheduledFunctionNames(functions.replace);
1553
- if (replaceScheduled) {
1554
- applyScheduledFunctionPatch(replaceScheduled, functions.patch);
1555
- return { count: replaceScheduled.size, source: "manifest" };
1556
- }
1557
- if (!functions.patch)
1558
- return null;
1559
- const activeScheduled = await readActiveScheduledFunctionNames(client, spec.project_id);
1560
- if (!activeScheduled)
1561
- return null;
1562
- applyScheduledFunctionPatch(activeScheduled, functions.patch);
1563
- return { count: activeScheduled.size, source: "active_release_inventory" };
1564
- }
1565
- function countScheduledFunctionsInSetEntries(functions) {
1566
- if (!functions)
1567
- return 0;
1568
- let count = 0;
1569
- for (const fn of Object.values(functions.replace ?? {})) {
1570
- count += scheduleTriggersForFunction(fn).length;
1571
- }
1572
- for (const fn of Object.values(functions.patch?.set ?? {})) {
1573
- count += scheduleTriggersForFunction(fn).length;
1574
- }
1575
- return count;
1576
- }
1577
- function scheduledFunctionNames(functions) {
1578
- if (!functions)
1579
- return null;
1580
- const scheduled = new Set();
1581
- for (const [name, fn] of Object.entries(functions)) {
1582
- if (scheduleTriggersForFunction(fn).length > 0)
1583
- scheduled.add(name);
1584
- }
1585
- return scheduled;
1586
- }
1587
- function applyScheduledFunctionPatch(scheduled, patch) {
1588
- for (const name of patch?.delete ?? []) {
1589
- scheduled.delete(name);
1590
- }
1591
- for (const [name, fn] of Object.entries(patch?.set ?? {})) {
1592
- if (scheduleTriggersForFunction(fn).length > 0)
1593
- scheduled.add(name);
1594
- }
1595
- }
1596
- async function readActiveScheduledFunctionNames(client, projectId) {
1597
- let inventory;
1598
- try {
1599
- inventory = await client.request(appendQuery("/apply/v1/releases/active", { site_limit: 1 }), {
1600
- headers: await apikeyHeaders(client, projectId),
1601
- context: "fetching active release inventory for deploy preflight",
1602
- });
1603
- }
1604
- catch {
1605
- return null;
1606
- }
1607
- const scheduled = new Set();
1608
- for (const fn of inventory.functions ?? []) {
1609
- if (scheduleTriggersForFunction(fn).length > 0)
1610
- scheduled.add(fn.name);
1611
- }
1612
- return scheduled;
1613
- }
1614
- function scheduleTriggersForFunction(fn) {
1615
- return (fn.triggers ?? [])
1616
- .map((trigger, index) => ({ trigger, index }))
1617
- .filter((entry) => entry.trigger.type === "schedule")
1618
- .map(({ trigger, index }) => ({
1619
- ...trigger,
1620
- fieldSuffix: `triggers[${index}].cron`,
1621
- }));
1622
- }
1623
- function scheduledCountTierLimitError(count, limits, limit, countSource) {
1624
- return tierLimitError(`Deploy would have ${count} scheduled function(s), exceeding the ${limits.tier} tier maximum of ${limit.value}.`, "functions.scheduled_count", count, limits, limit, {
1625
- tier_max: limit.value,
1626
- max_scheduled_functions: limit.value,
1627
- count_source: countSource,
1628
- });
1629
- }
1630
- function tierLimitError(message, field, value, limits, limit, extraDetails) {
1631
- const hint = limits.walletTier !== undefined
1632
- ? `The project's organization is on the ${limits.tier} tier (your wallet's own organization ${limits.walletTier ? `is on ${limits.walletTier}` : "has no tier"}), and a deploy is held to the limits of the organization that owns the project. Lower the function setting or upgrade that organization's tier.`
1633
- : limit.source === "local_static_fallback"
1634
- ? "Tier limits came from the SDK's static fallback because /tiers/v1/status did not expose function caps. Run `run402 tier status` to refresh, lower the function setting, upgrade the tier, or retry and let gateway validation decide if this seems stale."
1635
- : "Lower the function setting or upgrade the tier before deploying.";
1636
- const details = {
1637
- field,
1638
- value,
1639
- tier: limits.tier,
1640
- limit_source: limit.source,
1641
- ...extraDetails,
1642
- };
1643
- const body = {
1644
- code: "BAD_FIELD",
1645
- category: "deploy",
1646
- message,
1647
- retryable: false,
1648
- details,
1649
- hint,
1650
- };
1651
- return new Run402DeployError(message, {
1652
- code: "BAD_FIELD",
1653
- phase: "validate",
1654
- resource: field,
1655
- retryable: false,
1656
- body,
1657
- context: "validating deploy tier limits",
1658
- });
1659
- }
1660
- function estimateCronMinimumIntervalMinutes(expression) {
1661
- const parts = expression.trim().split(/\s+/);
1662
- if (parts.length !== 5)
1663
- return null;
1664
- const minutes = expandCronNumberField(parts[0], 0, 59);
1665
- const hours = expandCronNumberField(parts[1], 0, 23);
1666
- if (!minutes || !hours || minutes.length === 0 || hours.length === 0)
1667
- return null;
1668
- const occurrences = [];
1669
- for (const hour of hours) {
1670
- for (const minute of minutes) {
1671
- occurrences.push(hour * 60 + minute);
1672
- }
1673
- }
1674
- occurrences.sort((a, b) => a - b);
1675
- if (occurrences.length <= 1)
1676
- return 24 * 60;
1677
- let minGap = Number.POSITIVE_INFINITY;
1678
- for (let i = 1; i < occurrences.length; i += 1) {
1679
- minGap = Math.min(minGap, occurrences[i] - occurrences[i - 1]);
1680
- }
1681
- minGap = Math.min(minGap, 24 * 60 - occurrences[occurrences.length - 1] + occurrences[0]);
1682
- return Number.isFinite(minGap) ? minGap : null;
1683
- }
1684
- function expandCronNumberField(field, min, max) {
1685
- const values = new Set();
1686
- for (const part of field.split(",")) {
1687
- const expanded = expandCronNumberPart(part.trim(), min, max);
1688
- if (!expanded)
1689
- return null;
1690
- for (const value of expanded)
1691
- values.add(value);
1692
- }
1693
- return [...values].sort((a, b) => a - b);
1694
- }
1695
- function expandCronNumberPart(part, min, max) {
1696
- if (!part)
1697
- return null;
1698
- const [rangePart, stepPart] = part.split("/");
1699
- if (part.split("/").length > 2)
1700
- return null;
1701
- const step = stepPart === undefined ? 1 : Number(stepPart);
1702
- if (!Number.isSafeInteger(step) || step < 1)
1703
- return null;
1704
- let start;
1705
- let end;
1706
- if (rangePart === "*") {
1707
- start = min;
1708
- end = max;
1709
- }
1710
- else if (rangePart?.includes("-")) {
1711
- const [rawStart, rawEnd] = rangePart.split("-");
1712
- start = Number(rawStart);
1713
- end = Number(rawEnd);
1714
- }
1715
- else {
1716
- start = Number(rangePart);
1717
- end = stepPart === undefined ? start : max;
1718
- }
1719
- if (!Number.isSafeInteger(start) ||
1720
- !Number.isSafeInteger(end) ||
1721
- start < min ||
1722
- end > max ||
1723
- start > end) {
1724
- return null;
1725
- }
1726
- const values = [];
1727
- for (let value = start; value <= end; value += step) {
1728
- values.push(value);
1729
- }
1730
- return values;
1731
- }
1732
1323
  async function commitInternal(client, planId, idempotencyKey, project, requiredPlan, vault, operationId, noSnapshot) {
1733
1324
  const tries = { attempts: 0 };
1734
1325
  try {
@@ -4810,7 +4401,7 @@ function translateDeployError(err, phase, planId, operationId) {
4810
4401
  : null;
4811
4402
  const gw = body && typeof body === "object" ? extractGatewayError(body) : null;
4812
4403
  if (gw) {
4813
- return translateGatewayError(gw, phase, planId, operationId);
4404
+ return translateGatewayError(gw, phase, planId, operationId, err.status);
4814
4405
  }
4815
4406
  return new Run402DeployError(err.message, {
4816
4407
  code: "INTERNAL_ERROR",
@@ -4835,7 +4426,7 @@ function translateDeployError(err, phase, planId, operationId) {
4835
4426
  : null;
4836
4427
  const gw = body ? extractGatewayError(body) : null;
4837
4428
  if (gw) {
4838
- return translateGatewayError(gw, phase, planId, operationId);
4429
+ return translateGatewayError(gw, phase, planId, operationId, err.status);
4839
4430
  }
4840
4431
  return new Run402DeployError(err.message, {
4841
4432
  code: "PROJECT_HAS_PENDING_TRANSFER",
@@ -5037,7 +4628,9 @@ function arrayField(obj, key) {
5037
4628
  const value = obj && typeof obj === "object" ? obj[key] : undefined;
5038
4629
  return Array.isArray(value) ? value : undefined;
5039
4630
  }
5040
- function translateGatewayError(gw, phase, planId, operationId) {
4631
+ function translateGatewayError(gw, phase, planId, operationId,
4632
+ /** The HTTP status of the response that carried the error, when one did. */
4633
+ status) {
5041
4634
  if (!gw) {
5042
4635
  return new Run402DeployError("Deploy failed without a structured error", {
5043
4636
  code: "INTERNAL_ERROR",
@@ -5077,6 +4670,7 @@ function translateGatewayError(gw, phase, planId, operationId) {
5077
4670
  fix,
5078
4671
  logs,
5079
4672
  rolledBack: gw.rolled_back ?? booleanField(details, "rolled_back") ?? false,
4673
+ ...(status !== undefined && status !== null ? { status } : {}),
5080
4674
  body,
5081
4675
  context: phase,
5082
4676
  });