run402-mcp 4.158.2 → 4.159.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/docs/llms-sdk.txt +1 -1
- package/package.json +1 -1
- package/sdk/README.md +1 -1
- package/sdk/dist/namespaces/deploy.d.ts.map +1 -1
- package/sdk/dist/namespaces/deploy.js +29 -425
- package/sdk/dist/namespaces/deploy.js.map +1 -1
- package/sdk/dist/namespaces/tier.d.ts +0 -16
- package/sdk/dist/namespaces/tier.d.ts.map +1 -1
- package/sdk/dist/namespaces/tier.js.map +1 -1
package/dist/docs/llms-sdk.txt
CHANGED
|
@@ -1089,7 +1089,7 @@ The full type is exported as `ReleaseSpec` from `@run402/sdk` and `@run402/sdk/n
|
|
|
1089
1089
|
- Routes. `ReleaseRoutesSpec` is `undefined | null | { replace: RouteSpec[] }`. Omitted and `null` carry forward base routes; `{ replace: [] }` clears dynamic routes; `{ replace: [...] }` replaces the route table. `RouteSpec` is one entry: `{ pattern: string, methods?: RouteHttpMethod[], target: RouteTarget }`. Function targets are `{ type: "function", name: string }`; static route targets are `{ type: "static", file: string }` for exact method-aware static aliases, not ordinary clean URLs, rewrites, or redirects. Prefer `site.public_paths` for clean static URLs e.g. `/events -> events.html`; use static routes for cases like static `GET /login` plus function `POST /login`. Static targets require exact patterns only, methods `["GET"]` or `["GET","HEAD"]`, and a relative deployed asset path with no leading slash, wildcard, directory shorthand, query, or fragment. `methods` omitted means all supported methods for function routes; `methods: []` is invalid. Supported methods are exported as `ROUTE_HTTP_METHODS` and `RouteHttpMethod` (`GET`, `HEAD`, `POST`, `PUT`, `PATCH`, `DELETE`, `OPTIONS`). Function target names are materialized release function names.
|
|
1090
1090
|
- Strict validation is SDK-owned. `apply.plan/start/apply` reject unknown raw `ReleaseSpec` fields before normalization can drop them; only top-level `$schema` metadata is tolerated and stripped before the plan request. `project_id`, `subdomain`, `site.replcae`, `functions.replace.api.deps`, `functions.replace.api.config.schedule`, and similar typos are `Run402DeployError.code === "INVALID_SPEC"` before any hash/upload/plan request. Use `loadDeployManifest` / `normalizeDeployManifest` for CLI/MCP JSON that legitimately uses `project_id`, `{ path }`, base64 file entries, or migration `sql_path`.
|
|
1091
1091
|
- No-op specs fail locally. A spec with only `project` / `base`, or empty containers e.g. `site: {}`, `functions.patch.delete: []`, `secrets.require: []`, or `subdomains.set: []`, throws `Run402DeployError.code === "MANIFEST_EMPTY"` before any network call. Delete-only patches with non-empty `delete` arrays still count as deployable, and so does an explicit `site.replace: {}`: it takes the site's static files offline (the plan asks to confirm `ZERO_SITE_FILES_AFTER`, except for a release whose `ssr` function renders every path).
|
|
1092
|
-
- Tier
|
|
1092
|
+
- Tier limits are the gateway's answer. `apply.plan/start/apply` hold no tier cap and read no tier before the plan: `POST /apply/v1/plans` checks `config.timeoutSeconds` (by class), `config.memoryMb` (by class), each schedule trigger's cron interval, the scheduled-trigger count (the organization's other projects' schedule triggers plus the release's; a plan that adds none is never refused over it) and the code size, before anything is uploaded. A refusal throws `Run402DeployError` with `code === "TIER_LIMIT_EXCEEDED"`, `status: 403`, `fix` naming the tier, the cap that applied (`max_function_timeout_sec`, `max_function_memory_mb`, `min_schedule_interval_minutes`, `max_scheduled_functions`, `max_code_bytes`) and the value sent, and `nextActions`: an `edit_request` naming the field, then `renew_tier` below team. Current caps: prototype 10s / 128 MB / 1 scheduled trigger / 15 min, hobby 30s / 256 MB / 3 / 5 min, team 60s / 512 MB / 10 / 1 min; a run function (`class: "run"`) may take 300 s on team and an SSR function (`class: "ssr"`) 1,769 MB (prototype 128 MB, hobby 256 MB). The caps are those of the organization that owns the project.
|
|
1093
1093
|
- Plan warnings are structured. `PlanResponse.warnings` and `DeployResult.warnings` are `WarningEntry[]`; `apply()` emits `plan.warnings` and aborts before upload/commit when a warning requires confirmation unless broad `allowWarnings` is set or every blocking warning code is listed in `allowWarningCodes`. `MISSING_REQUIRED_SECRET` means set the affected keys with `r.secrets.set`, then retry. For `WILDCARD_ROUTE_EXCLUDES_MUTATION_METHODS`, add the mutation methods the function supports or omit methods for an API prefix; when the GET/HEAD final-wildcard function route is intentionally read-only, list the code in `allowWarningCodes` after inspecting all affected entries. `DESTRUCTIVE_SITE_BULK_REMOVAL` lists the counted removals in `affected`, and the SDK adds `details.removed_paths_summary` (heuristic: `pages`, `page_paths`, `content_hashed_build_assets`, `other`, `only_content_hashed_build_assets`, plus `by_top_level_dir` unless the gateway sends `counted_removed_by_dir`) so removals of pages are distinguishable from removed hashed bundles. The gateway already leaves out fingerprinted bundles the build replaces in the same directory (`details.replaced_fingerprinted`).
|
|
1094
1094
|
- A migration's undo is on the result. When a commit runs a new migration, `DeployResult.restore_point` is `{ snapshot_id, restore_url }`, the pre-migration snapshot to restore (`run402 snapshots restore <project_id> <snapshot_id>`); when the commit went on without one, `DeployResult.snapshot_skipped_reason` says why: `explicit_skip_requested`, `capture_size_limit_exceeded` (with an `AUTO_SNAPSHOT_SKIPPED_OVERSIZED` warning in `warnings`), or `migrations_unchanged` (every migration was already applied, so no migration SQL ran). The operation snapshot (`apply.status(operationId)`) repeats both once the snapshot phase has finished, so every path that ends in a ready operation carries them: a ready commit, a deferred or `running` one the SDK polls to ready, and `apply.resume(operationId)`. When the snapshot states the outcome, the SDK takes it over the one carried from the commit.
|
|
1095
1095
|
- Deploy summaries are derived SDK helpers. `summarizeDeployResult(result: DeployResult): DeploySummary` is exported from `@run402/sdk` and `@run402/sdk/node`. It makes no gateway calls and summarizes only current reliable `DeployResult.diff` / `DeployResult.warnings` data: site path counts, CAS new/reused bytes, functions, migrations, routes, secrets, subdomains, and warning counts. Missing buckets are omitted, not zero-filled. It intentionally has no timings, client-side duration estimates, server phase estimates, or function old/new code hash fields.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "run402-mcp",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.159.1",
|
|
4
4
|
"packageManager": "npm@11.19.0",
|
|
5
5
|
"mcpName": "com.run402/mcp",
|
|
6
6
|
"description": "MCP server 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.",
|
package/sdk/README.md
CHANGED
|
@@ -582,7 +582,7 @@ const resumed = await (await r.project(projectId)).apply.resume("op_...");
|
|
|
582
582
|
- **Per-resource semantics on the spec.** `site.replace` = "this is the whole site" (files absent are removed). `site.patch.put` / `patch.delete` are surgical updates. `site.public_paths` controls browser-visible static paths separately from backing release asset paths: explicit mode uses a complete map such as `{ "/events": { asset: "events.html", cache_class: "html" } }`, so `/events` serves `events.html` while `/events.html` is not public unless separately declared. Implicit mode restores filename-derived reachability and can widen access. A public-path-only site spec is deployable. `functions.replace` / `functions.patch.set` / `functions.patch.delete` mirror that. Secrets are value-free: set values first with `r.secrets.set(project, key, { value })`, then deploy with `secrets.require` and/or `secrets.delete`. `subdomains.set` / `subdomains.add` / `subdomains.remove` use their own shape. Top-level absence = leave untouched.
|
|
583
583
|
- **Same-origin web routes.** `routes` is `undefined | null | { replace: RouteSpec[] }`. Omit it or pass `null` to carry forward base routes, pass `{ replace: [] }` to clear routes, or pass route entries to replace the table. Function targets use `{ type: "function", name }`; exact static route targets use `{ type: "static", file }` with methods `["GET"]` or `["GET","HEAD"]`, no wildcard pattern, and a relative deployed asset path with no leading slash. `file` is not a public path, URL, CAS hash, rewrite, or redirect. Prefer `site.public_paths` for ordinary clean static URLs like `/events -> events.html`; use static route targets for method-aware aliases such as static `GET /login` plus function `POST /login`. Function routes may add fixed tenant x402 pricing: `pricing: { mode: "always", amount_usd_micros: 250000, pay_to: "org_default_payout", receipt: "on_fulfillment" }`; omitted `networks` means production mainnet only, and `"testnet"` must be opted in explicitly. Receipt intent requires `payment.fulfilled(response)` from `@run402/functions` after completed delivery on compatible hosts; Run402-hosted advertising remains gated until the interoperable delegated-signer carrier exists and never silently downgrades. Add `pricing.discovery: { description, service_name?, tags?, icon_url?, input?, output? }` on an exact one-method route to be listed in the x402 Bazaar after its first paid call (the gateway enforces the limits: 500-character description, 4 tags, 4096 bytes; the challenge also carries the `run402` tag and `extra.hosted_by`). Static aliases cannot be priced. Set the org payout wallet with `r.org(orgId).setPayoutWallet({ walletAddress })`; audit payments with `r.projects.listTenantPayments(projectId)` or scoped `r.project(id).projects.listTenantPayments()`. Routed browser ingress invokes Node 22 Fetch Request -> Response handlers; `req.url` is the full public URL on managed subdomains, deployment hosts, and verified custom domains. On priced routes, handlers should import `getRoutedPaymentContext` from `@run402/functions` and use `payment.paymentId` for idempotency. Direct `/functions/v1/:name` invocation remains API-key protected. Runtime route failure codes include `ROUTE_MANIFEST_LOAD_FAILED`, `ROUTED_INVOKE_WORKER_SECRET_MISSING`, `ROUTED_INVOKE_AUTH_FAILED`, `ROUTED_ROUTE_STALE`, `ROUTE_METHOD_NOT_ALLOWED`, `PAYOUT_WALLET_REQUIRED`, `PAYOUT_WALLET_AMBIGUOUS`, `PAYOUT_WALLET_UNRESOLVED`, `PAYMENT_PROOF_MISMATCH`, and `ROUTED_RESPONSE_TOO_LARGE`.
|
|
584
584
|
- **Strict spec validation happens before network calls.** Raw `ReleaseSpec` objects reject unknown fields (for example `project_id` or `subdomain`) instead of silently dropping them during normalization, and project/base-only or empty nested specs fail with `Run402DeployError.code === "MANIFEST_EMPTY"`. Use the Node manifest helpers when starting from CLI/MCP-style JSON.
|
|
585
|
-
- **Tier
|
|
585
|
+
- **Tier limits are the gateway's answer.** Apply holds no tier cap and reads no tier first: the plan refuses a function timeout, memory, schedule interval, scheduled-trigger count or code size above its tier cap before anything is uploaded, and apply throws it as `Run402DeployError` with `code === "TIER_LIMIT_EXCEEDED"`, `status: 403`, `fix` naming the cap that applied, and `nextActions` naming the edit.
|
|
586
586
|
- **Warnings are structured.** `DeployResult.warnings` contains `WarningEntry[]` (`code`, `severity`, `requires_confirmation`, `message`, optional `affected`/`details`/`confidence`); the type preserves legacy low/medium/high plan warnings and modern deploy-observability info/warn/high warnings. `apply()` emits `plan.warnings` and stops before upload/commit on confirmation-required warnings unless broad `allowWarnings` is set or every blocking code is listed in `allowWarningCodes`. For `MISSING_REQUIRED_SECRET`, set the affected keys with `r.secrets.set`, then retry.
|
|
587
587
|
- **Deploy summaries are SDK-owned convenience.** `summarizeDeployResult(result)` returns `DeploySummary` (`schema_version: "deploy-summary.v1"`) with a headline plus reliable current buckets for site path counts, CAS new/reused bytes, functions, migrations, routes, secrets, subdomains, and warning counts. It is derived from `DeployResult.diff` / `DeployResult.warnings`; it makes no extra gateway calls, omits sections the gateway did not return, and intentionally excludes timings, client-side duration estimates, and function old/new code hashes.
|
|
588
588
|
- **Safe release-race retries are SDK-owned.** `apply()` automatically re-plans and retries omitted/current-base specs when the gateway returns `BASE_RELEASE_CONFLICT` with `safe_to_retry: true`. Transient platform conditions marked `safe_to_retry: true` (`OPERATION_INTERRUPTED`, `IMAGE_ENCODE_TIMEOUT`, `TOO_MANY_ENCODES_QUEUED`, `PROJECT_WRITES_PAUSED`) re-apply the same way, for any base, with a longer backoff. Static activation/config failures reported from `activation_pending` throw immediately with gateway metadata preserved. The default retry budget is two retries after the initial attempt; pass `{ maxRetries: 0 }` to opt out.
|
|
@@ -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,EACh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,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,34 +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
|
-
maxRunTimeoutSeconds: 10,
|
|
95
|
-
maxMemoryMb: 128,
|
|
96
|
-
maxSsrMemoryMb: 128,
|
|
97
|
-
maxScheduledFunctions: 1,
|
|
98
|
-
minCronIntervalMinutes: 15,
|
|
99
|
-
},
|
|
100
|
-
hobby: {
|
|
101
|
-
maxTimeoutSeconds: 30,
|
|
102
|
-
maxRunTimeoutSeconds: 30,
|
|
103
|
-
maxMemoryMb: 256,
|
|
104
|
-
maxSsrMemoryMb: 256,
|
|
105
|
-
maxScheduledFunctions: 3,
|
|
106
|
-
minCronIntervalMinutes: 5,
|
|
107
|
-
},
|
|
108
|
-
team: {
|
|
109
|
-
maxTimeoutSeconds: 60,
|
|
110
|
-
// A run function (class "run"), which only function runs reach, may take five minutes.
|
|
111
|
-
maxRunTimeoutSeconds: 300,
|
|
112
|
-
maxMemoryMb: 512,
|
|
113
|
-
// An SSR-class function (the Astro `ssr` function) may use one vCPU.
|
|
114
|
-
maxSsrMemoryMb: 1769,
|
|
115
|
-
maxScheduledFunctions: 10,
|
|
116
|
-
minCronIntervalMinutes: 1,
|
|
117
|
-
},
|
|
118
|
-
};
|
|
119
91
|
const MANIFEST_CONTENT_TYPE = "application/vnd.run402.deploy-manifest+json";
|
|
120
92
|
const TERMINAL_STATUSES = ["ready", "failed"];
|
|
121
93
|
const SUCCESS_STATUS = "ready";
|
|
@@ -1264,8 +1236,6 @@ async function planInternal(client, spec, idempotencyKey, opts = {}) {
|
|
|
1264
1236
|
const { normalized, byteReaders } = await normalizeReleaseSpec(client, spec, {
|
|
1265
1237
|
inlineMigrationSql: isCore,
|
|
1266
1238
|
});
|
|
1267
|
-
if (!isCore)
|
|
1268
|
-
await preflightTierFunctionLimits(client, normalized, ciCredentials);
|
|
1269
1239
|
const wireSpec = isCore ? releaseSpecToCoreSpec(normalized) : releaseSpecToWire(normalized);
|
|
1270
1240
|
// The gateway expects { spec, manifest_ref?, idempotency_key? }. Cloud
|
|
1271
1241
|
// receives the legacy snake_case apply wire shape; Core receives the
|
|
@@ -1350,398 +1320,6 @@ function requiredPlanToWire(plan) {
|
|
|
1350
1320
|
wire.plan_fingerprint = plan.planFingerprint;
|
|
1351
1321
|
return wire;
|
|
1352
1322
|
}
|
|
1353
|
-
async function preflightTierFunctionLimits(client, spec, ciCredentials) {
|
|
1354
|
-
if (ciCredentials)
|
|
1355
|
-
return;
|
|
1356
|
-
if (!hasFunctionTierPreflightInputs(spec.functions))
|
|
1357
|
-
return;
|
|
1358
|
-
const limits = await readTierFunctionLimits(client, spec.project_id);
|
|
1359
|
-
if (!limits)
|
|
1360
|
-
return;
|
|
1361
|
-
const entries = collectFunctionPreflightEntries(spec.functions);
|
|
1362
|
-
for (const entry of entries) {
|
|
1363
|
-
const timeout = entry.fn.config?.timeoutSeconds;
|
|
1364
|
-
// A run function has its own timeout cap. With no class declared the
|
|
1365
|
-
// function keeps its stored one, which only the gateway knows.
|
|
1366
|
-
const timeoutLimit = entry.fn.class === "run"
|
|
1367
|
-
? limits.maxRunTimeoutSeconds ?? limits.maxTimeoutSeconds
|
|
1368
|
-
: entry.fn.class === undefined
|
|
1369
|
-
? largerLimit(limits.maxTimeoutSeconds, limits.maxRunTimeoutSeconds)
|
|
1370
|
-
: limits.maxTimeoutSeconds;
|
|
1371
|
-
if (timeout !== undefined &&
|
|
1372
|
-
timeoutLimit &&
|
|
1373
|
-
timeout > timeoutLimit.value) {
|
|
1374
|
-
throw tierLimitError(`Function ${entry.name} timeoutSeconds ${timeout} exceeds the ${limits.tier} tier maximum of ${timeoutLimit.value}.`, `${entry.fieldPrefix}.config.timeoutSeconds`, timeout, limits, timeoutLimit, {
|
|
1375
|
-
tier_max: timeoutLimit.value,
|
|
1376
|
-
max_function_timeout_seconds: timeoutLimit.value,
|
|
1377
|
-
});
|
|
1378
|
-
}
|
|
1379
|
-
const memory = entry.fn.config?.memoryMb;
|
|
1380
|
-
// An SSR-class function has its own cap. With no class declared the
|
|
1381
|
-
// function keeps its stored one, which only the gateway knows.
|
|
1382
|
-
const memoryLimit = entry.fn.class === "ssr"
|
|
1383
|
-
? limits.maxSsrMemoryMb ?? limits.maxMemoryMb
|
|
1384
|
-
: entry.fn.class === undefined
|
|
1385
|
-
? largerLimit(limits.maxMemoryMb, limits.maxSsrMemoryMb)
|
|
1386
|
-
: limits.maxMemoryMb;
|
|
1387
|
-
if (memory !== undefined &&
|
|
1388
|
-
memoryLimit &&
|
|
1389
|
-
memory > memoryLimit.value) {
|
|
1390
|
-
throw tierLimitError(`Function ${entry.name} memoryMb ${memory} exceeds the ${limits.tier} tier maximum of ${memoryLimit.value}.`, `${entry.fieldPrefix}.config.memoryMb`, memory, limits, memoryLimit, {
|
|
1391
|
-
tier_max: memoryLimit.value,
|
|
1392
|
-
max_function_memory_mb: memoryLimit.value,
|
|
1393
|
-
});
|
|
1394
|
-
}
|
|
1395
|
-
for (const trigger of scheduleTriggersForFunction(entry.fn)) {
|
|
1396
|
-
if (!limits.minCronIntervalMinutes)
|
|
1397
|
-
continue;
|
|
1398
|
-
const intervalMinutes = estimateCronMinimumIntervalMinutes(trigger.cron);
|
|
1399
|
-
if (intervalMinutes !== null &&
|
|
1400
|
-
intervalMinutes < limits.minCronIntervalMinutes.value) {
|
|
1401
|
-
const triggerLabel = trigger.id ? `trigger ${trigger.id}` : "schedule trigger";
|
|
1402
|
-
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, {
|
|
1403
|
-
interval_minutes: intervalMinutes,
|
|
1404
|
-
min_interval_minutes: limits.minCronIntervalMinutes.value,
|
|
1405
|
-
min_cron_interval_minutes: limits.minCronIntervalMinutes.value,
|
|
1406
|
-
});
|
|
1407
|
-
}
|
|
1408
|
-
}
|
|
1409
|
-
}
|
|
1410
|
-
if (limits.maxScheduledFunctions) {
|
|
1411
|
-
const lowerBound = countScheduledFunctionsInSetEntries(spec.functions);
|
|
1412
|
-
if (lowerBound > limits.maxScheduledFunctions.value) {
|
|
1413
|
-
throw scheduledCountTierLimitError(lowerBound, limits, limits.maxScheduledFunctions, "manifest");
|
|
1414
|
-
}
|
|
1415
|
-
const desired = await computeDesiredScheduledFunctionCount(client, spec);
|
|
1416
|
-
if (desired && desired.count > limits.maxScheduledFunctions.value) {
|
|
1417
|
-
throw scheduledCountTierLimitError(desired.count, limits, limits.maxScheduledFunctions, desired.source);
|
|
1418
|
-
}
|
|
1419
|
-
}
|
|
1420
|
-
}
|
|
1421
|
-
function largerLimit(a, b) {
|
|
1422
|
-
if (!a)
|
|
1423
|
-
return b;
|
|
1424
|
-
if (!b)
|
|
1425
|
-
return a;
|
|
1426
|
-
return b.value > a.value ? b : a;
|
|
1427
|
-
}
|
|
1428
|
-
function hasFunctionTierPreflightInputs(functions) {
|
|
1429
|
-
if (!functions)
|
|
1430
|
-
return false;
|
|
1431
|
-
return collectFunctionPreflightEntries(functions).some((entry) => (entry.fn.config?.timeoutSeconds !== undefined ||
|
|
1432
|
-
entry.fn.config?.memoryMb !== undefined ||
|
|
1433
|
-
scheduleTriggersForFunction(entry.fn).length > 0));
|
|
1434
|
-
}
|
|
1435
|
-
function collectFunctionPreflightEntries(functions) {
|
|
1436
|
-
if (!functions)
|
|
1437
|
-
return [];
|
|
1438
|
-
const entries = [];
|
|
1439
|
-
for (const [name, fn] of Object.entries(functions.replace ?? {})) {
|
|
1440
|
-
entries.push({ name, fn, fieldPrefix: `functions.${name}` });
|
|
1441
|
-
}
|
|
1442
|
-
for (const [name, fn] of Object.entries(functions.patch?.set ?? {})) {
|
|
1443
|
-
entries.push({ name, fn, fieldPrefix: `functions.${name}` });
|
|
1444
|
-
}
|
|
1445
|
-
return entries;
|
|
1446
|
-
}
|
|
1447
|
-
/**
|
|
1448
|
-
* The function caps of the tier the deploy is judged by: the tier of the
|
|
1449
|
-
* organization that owns the project. `/tiers/v1/status` describes the
|
|
1450
|
-
* wallet's own organization, so its caps count only when the project's tier
|
|
1451
|
-
* is the same; otherwise the static table for the project's tier applies.
|
|
1452
|
-
* When the project cannot be read, the wallet's own tier is used.
|
|
1453
|
-
*/
|
|
1454
|
-
async function readTierFunctionLimits(client, projectId) {
|
|
1455
|
-
let status;
|
|
1456
|
-
try {
|
|
1457
|
-
status = await client.request("/tiers/v1/status", {
|
|
1458
|
-
context: "checking tier status for deploy preflight",
|
|
1459
|
-
});
|
|
1460
|
-
}
|
|
1461
|
-
catch {
|
|
1462
|
-
return null;
|
|
1463
|
-
}
|
|
1464
|
-
const projectTier = await readProjectTier(client, projectId);
|
|
1465
|
-
let walletTier;
|
|
1466
|
-
if (projectTier && projectTier.toLowerCase() !== String(status.tier ?? "").toLowerCase()) {
|
|
1467
|
-
walletTier = typeof status.tier === "string" ? status.tier : "";
|
|
1468
|
-
status = { tier: projectTier };
|
|
1469
|
-
}
|
|
1470
|
-
if (typeof status.tier !== "string" || status.tier.length === 0) {
|
|
1471
|
-
return null;
|
|
1472
|
-
}
|
|
1473
|
-
const tierKey = status.tier.toLowerCase();
|
|
1474
|
-
const fallback = STATIC_FUNCTION_LIMITS_BY_TIER[tierKey];
|
|
1475
|
-
const limits = { tier: status.tier };
|
|
1476
|
-
if (walletTier !== undefined)
|
|
1477
|
-
limits.walletTier = walletTier;
|
|
1478
|
-
limits.maxTimeoutSeconds = tierStatusLimitOrFallback(status, [
|
|
1479
|
-
"max_function_timeout_seconds",
|
|
1480
|
-
"max_timeout_seconds",
|
|
1481
|
-
"timeout_seconds_max",
|
|
1482
|
-
"function_timeout_seconds_max",
|
|
1483
|
-
], fallback?.maxTimeoutSeconds);
|
|
1484
|
-
limits.maxMemoryMb = tierStatusLimitOrFallback(status, [
|
|
1485
|
-
"max_function_memory_mb",
|
|
1486
|
-
"max_memory_mb",
|
|
1487
|
-
"memory_mb_max",
|
|
1488
|
-
"function_memory_mb_max",
|
|
1489
|
-
], fallback?.maxMemoryMb);
|
|
1490
|
-
// tier status names no SSR memory cap or run timeout cap, so they come from the static table.
|
|
1491
|
-
if (fallback)
|
|
1492
|
-
limits.maxSsrMemoryMb = { value: fallback.maxSsrMemoryMb, source: "local_static_fallback" };
|
|
1493
|
-
if (fallback)
|
|
1494
|
-
limits.maxRunTimeoutSeconds = { value: fallback.maxRunTimeoutSeconds, source: "local_static_fallback" };
|
|
1495
|
-
limits.maxScheduledFunctions = tierStatusLimitOrFallback(status, [
|
|
1496
|
-
"max_scheduled_functions",
|
|
1497
|
-
"scheduled_functions_limit",
|
|
1498
|
-
"scheduled_function_limit",
|
|
1499
|
-
"max_function_schedules",
|
|
1500
|
-
], fallback?.maxScheduledFunctions);
|
|
1501
|
-
limits.minCronIntervalMinutes = tierStatusLimitOrFallback(status, [
|
|
1502
|
-
"min_cron_interval_minutes",
|
|
1503
|
-
"minimum_cron_interval_minutes",
|
|
1504
|
-
"min_schedule_interval_minutes",
|
|
1505
|
-
"min_scheduled_function_interval_minutes",
|
|
1506
|
-
], fallback?.minCronIntervalMinutes);
|
|
1507
|
-
limits.currentScheduledFunctions = tierStatusLimit(status, [
|
|
1508
|
-
"current_scheduled_functions",
|
|
1509
|
-
"current_scheduled_function_count",
|
|
1510
|
-
"scheduled_function_count",
|
|
1511
|
-
"scheduled_functions",
|
|
1512
|
-
]);
|
|
1513
|
-
return hasAnyTierFunctionLimit(limits) ? limits : null;
|
|
1514
|
-
}
|
|
1515
|
-
async function readProjectTier(client, projectId) {
|
|
1516
|
-
try {
|
|
1517
|
-
const project = await client.request(`/projects/v1/${encodeURIComponent(projectId)}`, {
|
|
1518
|
-
method: "GET",
|
|
1519
|
-
context: "checking the project's tier for deploy preflight",
|
|
1520
|
-
});
|
|
1521
|
-
return typeof project.tier === "string" && project.tier.length > 0 ? project.tier : null;
|
|
1522
|
-
}
|
|
1523
|
-
catch {
|
|
1524
|
-
return null;
|
|
1525
|
-
}
|
|
1526
|
-
}
|
|
1527
|
-
function tierStatusLimitOrFallback(status, keys, fallback) {
|
|
1528
|
-
return tierStatusLimit(status, keys) ?? (fallback === undefined
|
|
1529
|
-
? undefined
|
|
1530
|
-
: { value: fallback, source: "local_static_fallback" });
|
|
1531
|
-
}
|
|
1532
|
-
function tierStatusLimit(status, keys) {
|
|
1533
|
-
const limits = objectField(status, "limits");
|
|
1534
|
-
const containers = [
|
|
1535
|
-
objectField(status, "function_limits"),
|
|
1536
|
-
objectField(limits, "functions"),
|
|
1537
|
-
objectField(limits, "function_limits"),
|
|
1538
|
-
objectField(status, "pool_usage"),
|
|
1539
|
-
status,
|
|
1540
|
-
];
|
|
1541
|
-
for (const container of containers) {
|
|
1542
|
-
if (!container || typeof container !== "object" || Array.isArray(container))
|
|
1543
|
-
continue;
|
|
1544
|
-
const obj = container;
|
|
1545
|
-
for (const key of keys) {
|
|
1546
|
-
const value = obj[key];
|
|
1547
|
-
if (typeof value === "number" && Number.isFinite(value) && value >= 0) {
|
|
1548
|
-
return { value, source: "tier_status" };
|
|
1549
|
-
}
|
|
1550
|
-
}
|
|
1551
|
-
}
|
|
1552
|
-
return undefined;
|
|
1553
|
-
}
|
|
1554
|
-
function hasAnyTierFunctionLimit(limits) {
|
|
1555
|
-
return Boolean(limits.maxTimeoutSeconds ||
|
|
1556
|
-
limits.maxMemoryMb ||
|
|
1557
|
-
limits.maxScheduledFunctions ||
|
|
1558
|
-
limits.minCronIntervalMinutes ||
|
|
1559
|
-
limits.currentScheduledFunctions);
|
|
1560
|
-
}
|
|
1561
|
-
async function computeDesiredScheduledFunctionCount(client, spec) {
|
|
1562
|
-
const functions = spec.functions;
|
|
1563
|
-
if (!functions)
|
|
1564
|
-
return null;
|
|
1565
|
-
const replaceScheduled = scheduledFunctionNames(functions.replace);
|
|
1566
|
-
if (replaceScheduled) {
|
|
1567
|
-
applyScheduledFunctionPatch(replaceScheduled, functions.patch);
|
|
1568
|
-
return { count: replaceScheduled.size, source: "manifest" };
|
|
1569
|
-
}
|
|
1570
|
-
if (!functions.patch)
|
|
1571
|
-
return null;
|
|
1572
|
-
const activeScheduled = await readActiveScheduledFunctionNames(client, spec.project_id);
|
|
1573
|
-
if (!activeScheduled)
|
|
1574
|
-
return null;
|
|
1575
|
-
applyScheduledFunctionPatch(activeScheduled, functions.patch);
|
|
1576
|
-
return { count: activeScheduled.size, source: "active_release_inventory" };
|
|
1577
|
-
}
|
|
1578
|
-
function countScheduledFunctionsInSetEntries(functions) {
|
|
1579
|
-
if (!functions)
|
|
1580
|
-
return 0;
|
|
1581
|
-
let count = 0;
|
|
1582
|
-
for (const fn of Object.values(functions.replace ?? {})) {
|
|
1583
|
-
count += scheduleTriggersForFunction(fn).length;
|
|
1584
|
-
}
|
|
1585
|
-
for (const fn of Object.values(functions.patch?.set ?? {})) {
|
|
1586
|
-
count += scheduleTriggersForFunction(fn).length;
|
|
1587
|
-
}
|
|
1588
|
-
return count;
|
|
1589
|
-
}
|
|
1590
|
-
function scheduledFunctionNames(functions) {
|
|
1591
|
-
if (!functions)
|
|
1592
|
-
return null;
|
|
1593
|
-
const scheduled = new Set();
|
|
1594
|
-
for (const [name, fn] of Object.entries(functions)) {
|
|
1595
|
-
if (scheduleTriggersForFunction(fn).length > 0)
|
|
1596
|
-
scheduled.add(name);
|
|
1597
|
-
}
|
|
1598
|
-
return scheduled;
|
|
1599
|
-
}
|
|
1600
|
-
function applyScheduledFunctionPatch(scheduled, patch) {
|
|
1601
|
-
for (const name of patch?.delete ?? []) {
|
|
1602
|
-
scheduled.delete(name);
|
|
1603
|
-
}
|
|
1604
|
-
for (const [name, fn] of Object.entries(patch?.set ?? {})) {
|
|
1605
|
-
if (scheduleTriggersForFunction(fn).length > 0)
|
|
1606
|
-
scheduled.add(name);
|
|
1607
|
-
}
|
|
1608
|
-
}
|
|
1609
|
-
async function readActiveScheduledFunctionNames(client, projectId) {
|
|
1610
|
-
let inventory;
|
|
1611
|
-
try {
|
|
1612
|
-
inventory = await client.request(appendQuery("/apply/v1/releases/active", { site_limit: 1 }), {
|
|
1613
|
-
headers: await apikeyHeaders(client, projectId),
|
|
1614
|
-
context: "fetching active release inventory for deploy preflight",
|
|
1615
|
-
});
|
|
1616
|
-
}
|
|
1617
|
-
catch {
|
|
1618
|
-
return null;
|
|
1619
|
-
}
|
|
1620
|
-
const scheduled = new Set();
|
|
1621
|
-
for (const fn of inventory.functions ?? []) {
|
|
1622
|
-
if (scheduleTriggersForFunction(fn).length > 0)
|
|
1623
|
-
scheduled.add(fn.name);
|
|
1624
|
-
}
|
|
1625
|
-
return scheduled;
|
|
1626
|
-
}
|
|
1627
|
-
function scheduleTriggersForFunction(fn) {
|
|
1628
|
-
return (fn.triggers ?? [])
|
|
1629
|
-
.map((trigger, index) => ({ trigger, index }))
|
|
1630
|
-
.filter((entry) => entry.trigger.type === "schedule")
|
|
1631
|
-
.map(({ trigger, index }) => ({
|
|
1632
|
-
...trigger,
|
|
1633
|
-
fieldSuffix: `triggers[${index}].cron`,
|
|
1634
|
-
}));
|
|
1635
|
-
}
|
|
1636
|
-
function scheduledCountTierLimitError(count, limits, limit, countSource) {
|
|
1637
|
-
return tierLimitError(`Deploy would have ${count} scheduled function(s), exceeding the ${limits.tier} tier maximum of ${limit.value}.`, "functions.scheduled_count", count, limits, limit, {
|
|
1638
|
-
tier_max: limit.value,
|
|
1639
|
-
max_scheduled_functions: limit.value,
|
|
1640
|
-
count_source: countSource,
|
|
1641
|
-
});
|
|
1642
|
-
}
|
|
1643
|
-
function tierLimitError(message, field, value, limits, limit, extraDetails) {
|
|
1644
|
-
const hint = limits.walletTier !== undefined
|
|
1645
|
-
? `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.`
|
|
1646
|
-
: limit.source === "local_static_fallback"
|
|
1647
|
-
? "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."
|
|
1648
|
-
: "Lower the function setting or upgrade the tier before deploying.";
|
|
1649
|
-
const details = {
|
|
1650
|
-
field,
|
|
1651
|
-
value,
|
|
1652
|
-
tier: limits.tier,
|
|
1653
|
-
limit_source: limit.source,
|
|
1654
|
-
...extraDetails,
|
|
1655
|
-
};
|
|
1656
|
-
const body = {
|
|
1657
|
-
code: "BAD_FIELD",
|
|
1658
|
-
category: "deploy",
|
|
1659
|
-
message,
|
|
1660
|
-
retryable: false,
|
|
1661
|
-
details,
|
|
1662
|
-
hint,
|
|
1663
|
-
};
|
|
1664
|
-
return new Run402DeployError(message, {
|
|
1665
|
-
code: "BAD_FIELD",
|
|
1666
|
-
phase: "validate",
|
|
1667
|
-
resource: field,
|
|
1668
|
-
retryable: false,
|
|
1669
|
-
body,
|
|
1670
|
-
context: "validating deploy tier limits",
|
|
1671
|
-
});
|
|
1672
|
-
}
|
|
1673
|
-
function estimateCronMinimumIntervalMinutes(expression) {
|
|
1674
|
-
const parts = expression.trim().split(/\s+/);
|
|
1675
|
-
if (parts.length !== 5)
|
|
1676
|
-
return null;
|
|
1677
|
-
const minutes = expandCronNumberField(parts[0], 0, 59);
|
|
1678
|
-
const hours = expandCronNumberField(parts[1], 0, 23);
|
|
1679
|
-
if (!minutes || !hours || minutes.length === 0 || hours.length === 0)
|
|
1680
|
-
return null;
|
|
1681
|
-
const occurrences = [];
|
|
1682
|
-
for (const hour of hours) {
|
|
1683
|
-
for (const minute of minutes) {
|
|
1684
|
-
occurrences.push(hour * 60 + minute);
|
|
1685
|
-
}
|
|
1686
|
-
}
|
|
1687
|
-
occurrences.sort((a, b) => a - b);
|
|
1688
|
-
if (occurrences.length <= 1)
|
|
1689
|
-
return 24 * 60;
|
|
1690
|
-
let minGap = Number.POSITIVE_INFINITY;
|
|
1691
|
-
for (let i = 1; i < occurrences.length; i += 1) {
|
|
1692
|
-
minGap = Math.min(minGap, occurrences[i] - occurrences[i - 1]);
|
|
1693
|
-
}
|
|
1694
|
-
minGap = Math.min(minGap, 24 * 60 - occurrences[occurrences.length - 1] + occurrences[0]);
|
|
1695
|
-
return Number.isFinite(minGap) ? minGap : null;
|
|
1696
|
-
}
|
|
1697
|
-
function expandCronNumberField(field, min, max) {
|
|
1698
|
-
const values = new Set();
|
|
1699
|
-
for (const part of field.split(",")) {
|
|
1700
|
-
const expanded = expandCronNumberPart(part.trim(), min, max);
|
|
1701
|
-
if (!expanded)
|
|
1702
|
-
return null;
|
|
1703
|
-
for (const value of expanded)
|
|
1704
|
-
values.add(value);
|
|
1705
|
-
}
|
|
1706
|
-
return [...values].sort((a, b) => a - b);
|
|
1707
|
-
}
|
|
1708
|
-
function expandCronNumberPart(part, min, max) {
|
|
1709
|
-
if (!part)
|
|
1710
|
-
return null;
|
|
1711
|
-
const [rangePart, stepPart] = part.split("/");
|
|
1712
|
-
if (part.split("/").length > 2)
|
|
1713
|
-
return null;
|
|
1714
|
-
const step = stepPart === undefined ? 1 : Number(stepPart);
|
|
1715
|
-
if (!Number.isSafeInteger(step) || step < 1)
|
|
1716
|
-
return null;
|
|
1717
|
-
let start;
|
|
1718
|
-
let end;
|
|
1719
|
-
if (rangePart === "*") {
|
|
1720
|
-
start = min;
|
|
1721
|
-
end = max;
|
|
1722
|
-
}
|
|
1723
|
-
else if (rangePart?.includes("-")) {
|
|
1724
|
-
const [rawStart, rawEnd] = rangePart.split("-");
|
|
1725
|
-
start = Number(rawStart);
|
|
1726
|
-
end = Number(rawEnd);
|
|
1727
|
-
}
|
|
1728
|
-
else {
|
|
1729
|
-
start = Number(rangePart);
|
|
1730
|
-
end = stepPart === undefined ? start : max;
|
|
1731
|
-
}
|
|
1732
|
-
if (!Number.isSafeInteger(start) ||
|
|
1733
|
-
!Number.isSafeInteger(end) ||
|
|
1734
|
-
start < min ||
|
|
1735
|
-
end > max ||
|
|
1736
|
-
start > end) {
|
|
1737
|
-
return null;
|
|
1738
|
-
}
|
|
1739
|
-
const values = [];
|
|
1740
|
-
for (let value = start; value <= end; value += step) {
|
|
1741
|
-
values.push(value);
|
|
1742
|
-
}
|
|
1743
|
-
return values;
|
|
1744
|
-
}
|
|
1745
1323
|
async function commitInternal(client, planId, idempotencyKey, project, requiredPlan, vault, operationId, noSnapshot) {
|
|
1746
1324
|
const tries = { attempts: 0 };
|
|
1747
1325
|
try {
|
|
@@ -4823,7 +4401,7 @@ function translateDeployError(err, phase, planId, operationId) {
|
|
|
4823
4401
|
: null;
|
|
4824
4402
|
const gw = body && typeof body === "object" ? extractGatewayError(body) : null;
|
|
4825
4403
|
if (gw) {
|
|
4826
|
-
return translateGatewayError(gw, phase, planId, operationId);
|
|
4404
|
+
return translateGatewayError(gw, phase, planId, operationId, err.status);
|
|
4827
4405
|
}
|
|
4828
4406
|
return new Run402DeployError(err.message, {
|
|
4829
4407
|
code: "INTERNAL_ERROR",
|
|
@@ -4848,7 +4426,7 @@ function translateDeployError(err, phase, planId, operationId) {
|
|
|
4848
4426
|
: null;
|
|
4849
4427
|
const gw = body ? extractGatewayError(body) : null;
|
|
4850
4428
|
if (gw) {
|
|
4851
|
-
return translateGatewayError(gw, phase, planId, operationId);
|
|
4429
|
+
return translateGatewayError(gw, phase, planId, operationId, err.status);
|
|
4852
4430
|
}
|
|
4853
4431
|
return new Run402DeployError(err.message, {
|
|
4854
4432
|
code: "PROJECT_HAS_PENDING_TRANSFER",
|
|
@@ -4864,6 +4442,14 @@ function translateDeployError(err, phase, planId, operationId) {
|
|
|
4864
4442
|
if (isNoResponseError(err)) {
|
|
4865
4443
|
return noResponseDeployError(err, phase, planId, operationId);
|
|
4866
4444
|
}
|
|
4445
|
+
// The kernel throws every 401/403 as `Unauthorized`. One the deploy state
|
|
4446
|
+
// machine itself refused (a tier cap at plan, a CI route scope) names its
|
|
4447
|
+
// phase, so it stays a deploy error, with its fix, next actions and status;
|
|
4448
|
+
// an auth or lifecycle refusal names none and is re-thrown below.
|
|
4449
|
+
const refusal = deployRefusalOf(err);
|
|
4450
|
+
if (refusal) {
|
|
4451
|
+
return translateGatewayError(refusal, phase, planId, operationId, err.status);
|
|
4452
|
+
}
|
|
4867
4453
|
// Re-throw other Run402Error subclasses (PaymentRequired, Unauthorized, etc.)
|
|
4868
4454
|
// as-is — the consumer handles them at a different layer than
|
|
4869
4455
|
// deploy-state-machine errors.
|
|
@@ -5030,6 +4616,21 @@ function extractGatewayError(body) {
|
|
|
5030
4616
|
}
|
|
5031
4617
|
return null;
|
|
5032
4618
|
}
|
|
4619
|
+
/**
|
|
4620
|
+
* The gateway error of a 401/403 that a deploy phase refused, or null. The
|
|
4621
|
+
* check is structural (`kind`), so it holds across duplicate SDK copies.
|
|
4622
|
+
*/
|
|
4623
|
+
function deployRefusalOf(err) {
|
|
4624
|
+
if (!isRun402Error(err) || err.kind !== "unauthorized")
|
|
4625
|
+
return null;
|
|
4626
|
+
const body = err.body && typeof err.body === "object" && !Array.isArray(err.body)
|
|
4627
|
+
? err.body
|
|
4628
|
+
: null;
|
|
4629
|
+
if (!body)
|
|
4630
|
+
return null;
|
|
4631
|
+
const phase = stringField(body, "phase") ?? stringField(objectField(body, "details"), "phase");
|
|
4632
|
+
return phase ? extractGatewayError(body) : null;
|
|
4633
|
+
}
|
|
5033
4634
|
function stringField(obj, key) {
|
|
5034
4635
|
return obj && typeof obj === "object" && typeof obj[key] === "string"
|
|
5035
4636
|
? obj[key]
|
|
@@ -5050,7 +4651,9 @@ function arrayField(obj, key) {
|
|
|
5050
4651
|
const value = obj && typeof obj === "object" ? obj[key] : undefined;
|
|
5051
4652
|
return Array.isArray(value) ? value : undefined;
|
|
5052
4653
|
}
|
|
5053
|
-
function translateGatewayError(gw, phase, planId, operationId
|
|
4654
|
+
function translateGatewayError(gw, phase, planId, operationId,
|
|
4655
|
+
/** The HTTP status of the response that carried the error, when one did. */
|
|
4656
|
+
status) {
|
|
5054
4657
|
if (!gw) {
|
|
5055
4658
|
return new Run402DeployError("Deploy failed without a structured error", {
|
|
5056
4659
|
code: "INTERNAL_ERROR",
|
|
@@ -5090,6 +4693,7 @@ function translateGatewayError(gw, phase, planId, operationId) {
|
|
|
5090
4693
|
fix,
|
|
5091
4694
|
logs,
|
|
5092
4695
|
rolledBack: gw.rolled_back ?? booleanField(details, "rolled_back") ?? false,
|
|
4696
|
+
...(status !== undefined && status !== null ? { status } : {}),
|
|
5093
4697
|
body,
|
|
5094
4698
|
context: phase,
|
|
5095
4699
|
});
|