@run402/sdk 4.148.3 → 4.148.5
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.
|
@@ -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,EAIvB,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;
|
|
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,EAIvB,sBAAsB,EACtB,oBAAoB,EAUpB,iBAAiB,EAGjB,YAAY,EACZ,cAAc,EACd,aAAa,EACb,kBAAkB,EAClB,gBAAgB,EAChB,2BAA2B,EAC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PTS = 3;
|
|
45
44
|
const DEPLOY_COMMIT_RETRY_BASE_DELAY_MS = 1_000;
|
|
46
|
-
|
|
45
|
+
/** A content commit the gateway answered 202 is read back on this schedule. */
|
|
46
|
+
const CONTENT_COMMIT_POLL_INITIAL_MS = 1_000;
|
|
47
|
+
const CONTENT_COMMIT_POLL_MAX_MS = 10_000;
|
|
48
|
+
const CONTENT_COMMIT_POLL_TIMEOUT_MS = 60 * 60 * 1000;
|
|
49
|
+
/** The commit answers within 20 s (200 when done, else 202 with a poll) instead
|
|
50
|
+
* of holding the request for as long as a large promote takes (RFC 7240). */
|
|
51
|
+
const CONTENT_COMMIT_PREFER = "respond-async, wait=20";
|
|
47
52
|
const URL_REFRESH_AT_MS = 50 * 60 * 1000;
|
|
48
53
|
const SECRET_KEY_RE = /^[A-Z_][A-Z0-9_]{0,127}$/;
|
|
49
54
|
const APPLY_SAFE_RETRY_CODES = new Set([
|
|
@@ -1874,7 +1879,7 @@ async function uploadMissing(client, projectId, presence, byteReaders, emit) {
|
|
|
1874
1879
|
// Plan-level finalize — marks the plan committed in the deploy_plans
|
|
1875
1880
|
// table. Per-session promotion to CAS already happened in the loop
|
|
1876
1881
|
// above; this call is the plan-level idempotency anchor.
|
|
1877
|
-
await
|
|
1882
|
+
await commitContentPlan(client, planRes.plan_id, headers);
|
|
1878
1883
|
}
|
|
1879
1884
|
async function uploadCoreContent(client, projectId, byteReaders, emit) {
|
|
1880
1885
|
const entries = [...byteReaders.entries()].sort(([a], [b]) => a.localeCompare(b));
|
|
@@ -1904,27 +1909,67 @@ async function uploadCoreContent(client, projectId, byteReaders, emit) {
|
|
|
1904
1909
|
}
|
|
1905
1910
|
}
|
|
1906
1911
|
/**
|
|
1907
|
-
* Finalize a content plan
|
|
1908
|
-
*
|
|
1909
|
-
*
|
|
1910
|
-
*
|
|
1911
|
-
*
|
|
1912
|
+
* Finalize a content plan by following the gateway's answer. The gateway runs
|
|
1913
|
+
* one commit per plan, detached from the request, and with
|
|
1914
|
+
* `Prefer: respond-async, wait=20` answers its state within 20 s: 200
|
|
1915
|
+
* is done; 202 `committing` is followed by reading the plan (its `poll` next
|
|
1916
|
+
* action) until the commit is terminal; a read that says `pending` (the commit
|
|
1917
|
+
* never reached the gateway) is followed by the commit it names. A 502/503/504
|
|
1918
|
+
* or a dropped connection on the commit becomes a read of the plan, never a
|
|
1919
|
+
* second commit. `failed` and `expired` throw with the plan id.
|
|
1912
1920
|
*/
|
|
1913
|
-
async function
|
|
1914
|
-
|
|
1921
|
+
async function commitContentPlan(client, planId, headers) {
|
|
1922
|
+
const planPath = `/content/v1/plans/${encodeURIComponent(planId)}`;
|
|
1923
|
+
const postCommit = async () => {
|
|
1915
1924
|
try {
|
|
1916
|
-
await client.request(
|
|
1917
|
-
|
|
1925
|
+
return await client.request(`${planPath}/commit`, {
|
|
1926
|
+
method: "POST",
|
|
1927
|
+
headers: { ...headers, Prefer: CONTENT_COMMIT_PREFER },
|
|
1928
|
+
body: {},
|
|
1929
|
+
context: "committing content upload",
|
|
1930
|
+
});
|
|
1918
1931
|
}
|
|
1919
1932
|
catch (err) {
|
|
1920
|
-
if (
|
|
1921
|
-
return;
|
|
1922
|
-
|
|
1923
|
-
|
|
1924
|
-
|
|
1933
|
+
if (isTransientGatewayFailure(err))
|
|
1934
|
+
return null;
|
|
1935
|
+
throw err;
|
|
1936
|
+
}
|
|
1937
|
+
};
|
|
1938
|
+
const deadline = Date.now() + CONTENT_COMMIT_POLL_TIMEOUT_MS;
|
|
1939
|
+
let delay = CONTENT_COMMIT_POLL_INITIAL_MS;
|
|
1940
|
+
let state = await postCommit();
|
|
1941
|
+
for (;;) {
|
|
1942
|
+
const status = state?.status;
|
|
1943
|
+
if (state && status !== "committing" && status !== "pending") {
|
|
1944
|
+
if (status === "failed" || status === "expired")
|
|
1945
|
+
throw contentCommitStateError(planId, state);
|
|
1946
|
+
return;
|
|
1925
1947
|
}
|
|
1948
|
+
if (Date.now() >= deadline) {
|
|
1949
|
+
throw new Run402DeployError(`Content commit for plan ${planId} was still running after ${CONTENT_COMMIT_POLL_TIMEOUT_MS / 60_000} minutes; read GET ${planPath} for its state`, { code: "CONTENT_UPLOAD_FAILED", phase: "upload", retryable: true, planId, context: "committing content upload" });
|
|
1950
|
+
}
|
|
1951
|
+
if (status === "pending") {
|
|
1952
|
+
state = await postCommit();
|
|
1953
|
+
continue;
|
|
1954
|
+
}
|
|
1955
|
+
await sleep(delay);
|
|
1956
|
+
delay = Math.min(delay * 2, CONTENT_COMMIT_POLL_MAX_MS);
|
|
1957
|
+
state = await requestWithTransientRetry(() => client.request(planPath, { method: "GET", headers, context: "reading the content commit" }));
|
|
1926
1958
|
}
|
|
1927
1959
|
}
|
|
1960
|
+
function contentCommitStateError(planId, state) {
|
|
1961
|
+
const reason = state.status === "expired"
|
|
1962
|
+
? "the plan expired before it was committed"
|
|
1963
|
+
: `${state.error?.code ?? "failed"}: ${state.error?.message ?? "the commit failed"}`;
|
|
1964
|
+
return new Run402DeployError(`Content commit for plan ${planId} failed (${reason})`, {
|
|
1965
|
+
code: "CONTENT_UPLOAD_FAILED",
|
|
1966
|
+
phase: "upload",
|
|
1967
|
+
retryable: state.status === "failed" && state.error?.retryable === true,
|
|
1968
|
+
planId,
|
|
1969
|
+
body: state,
|
|
1970
|
+
context: "committing content upload",
|
|
1971
|
+
});
|
|
1972
|
+
}
|
|
1928
1973
|
/** Repeat a read or an idempotent request lost to a 502/503/504 or a dropped connection. */
|
|
1929
1974
|
async function requestWithTransientRetry(send) {
|
|
1930
1975
|
for (let attempt = 1;; attempt++) {
|
|
@@ -2082,7 +2127,8 @@ async function pollUntilReady(client, commit, diff, warnings, emit, projectId, s
|
|
|
2082
2127
|
operation_id: commit.operation_id,
|
|
2083
2128
|
urls: commit.urls,
|
|
2084
2129
|
diff,
|
|
2085
|
-
warnings:
|
|
2130
|
+
warnings: mergeWarningsByCode(warnings, commit.warnings),
|
|
2131
|
+
...commitSnapshotOutcome(commit),
|
|
2086
2132
|
...(commit.subdomain_bindings ? { subdomain_bindings: commit.subdomain_bindings } : {}),
|
|
2087
2133
|
...(commit.static_continuity ? { static_continuity: commit.static_continuity } : {}),
|
|
2088
2134
|
...(commit.edge ? { edge: commit.edge } : {}),
|
|
@@ -2096,9 +2142,25 @@ async function pollUntilReady(client, commit, diff, warnings, emit, projectId, s
|
|
|
2096
2142
|
}
|
|
2097
2143
|
const opHeaders = projectId ? await apikeyHeaders(client, projectId) : {};
|
|
2098
2144
|
const initialSnapshot = await client.request(`/apply/v1/operations/${encodeURIComponent(commit.operation_id)}`, { headers: opHeaders, context: "fetching deploy operation" });
|
|
2099
|
-
|
|
2145
|
+
// A deferred commit (schema_settling / activation_pending) already said
|
|
2146
|
+
// what happened to its pre-migration snapshot and which warnings it raised;
|
|
2147
|
+
// the operation snapshot repeats neither, so they ride across the poll.
|
|
2148
|
+
return await pollSnapshotUntilReady(client, initialSnapshot, diff, mergeWarningsByCode(warnings, commit.warnings), emit, projectId, sliceKinds, commitSnapshotOutcome(commit));
|
|
2149
|
+
}
|
|
2150
|
+
/** Later warnings replace earlier ones with the same code (plan → commit → snapshot). */
|
|
2151
|
+
function mergeWarningsByCode(earlier, later) {
|
|
2152
|
+
if (!later || later.length === 0)
|
|
2153
|
+
return [...earlier];
|
|
2154
|
+
return [...earlier.filter(w => !later.some(updated => updated.code === w.code)), ...later];
|
|
2155
|
+
}
|
|
2156
|
+
/** The commit's pre-migration snapshot outcome, as `DeployResult` carries it. */
|
|
2157
|
+
function commitSnapshotOutcome(commit) {
|
|
2158
|
+
return {
|
|
2159
|
+
...(commit.restore_point ? { restore_point: commit.restore_point } : {}),
|
|
2160
|
+
...(commit.snapshot_skipped_reason ? { snapshot_skipped_reason: commit.snapshot_skipped_reason } : {}),
|
|
2161
|
+
};
|
|
2100
2162
|
}
|
|
2101
|
-
async function pollSnapshotUntilReady(client, initial, diff, warnings, emit, projectId, sliceKinds = []) {
|
|
2163
|
+
async function pollSnapshotUntilReady(client, initial, diff, warnings, emit, projectId, sliceKinds = [], snapshotOutcome = {}) {
|
|
2102
2164
|
// Helper to spread slice_kinds onto every commit.phase / ready emit so
|
|
2103
2165
|
// agents grouping per-slice telemetry don't need to track the apply's
|
|
2104
2166
|
// spec separately. The low-level commit/upload helpers that pass no
|
|
@@ -2189,7 +2251,8 @@ async function pollSnapshotUntilReady(client, initial, diff, warnings, emit, pro
|
|
|
2189
2251
|
operation_id: snapshot.operation_id,
|
|
2190
2252
|
urls: snapshot.urls,
|
|
2191
2253
|
diff,
|
|
2192
|
-
warnings:
|
|
2254
|
+
warnings: mergeWarningsByCode(warnings, snapshot.warnings),
|
|
2255
|
+
...snapshotOutcome,
|
|
2193
2256
|
...(snapshot.subdomain_bindings ? { subdomain_bindings: snapshot.subdomain_bindings } : {}),
|
|
2194
2257
|
...(snapshot.static_continuity ? { static_continuity: snapshot.static_continuity } : {}),
|
|
2195
2258
|
...(snapshot.edge ? { edge: snapshot.edge } : {}),
|
|
@@ -4400,7 +4463,7 @@ async function uploadInlineCas(client, projectId, bytes, contentType) {
|
|
|
4400
4463
|
await uploadOne(client.fetch, session, bytes);
|
|
4401
4464
|
// v1.48 unified-apply: per-session /storage/v1/uploads/:id/complete is
|
|
4402
4465
|
// gone (404). The plan-level commit below promotes the session to CAS.
|
|
4403
|
-
await
|
|
4466
|
+
await commitContentPlan(client, planRes.plan_id, headers);
|
|
4404
4467
|
}
|
|
4405
4468
|
return { sha256, size: bytes.byteLength, contentType };
|
|
4406
4469
|
}
|