@somewhere-cloud/cli 0.38.176 → 0.38.177

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/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.38.177
4
+
5
+ - Retry interrupted static uploads before completing a deploy.
6
+
3
7
  ## 0.38.176
4
8
 
5
9
  - Upload large static sites faster and show hashing and upload times with `deploy --timing`.
@@ -1299,9 +1299,9 @@ var require_timers = __commonJS({
1299
1299
  * before the specified function or code is executed.
1300
1300
  * @param {*} arg
1301
1301
  */
1302
- constructor(callback, delay2, arg) {
1302
+ constructor(callback, delay3, arg) {
1303
1303
  this._onTimeout = callback;
1304
- this._idleTimeout = delay2;
1304
+ this._idleTimeout = delay3;
1305
1305
  this._timerArg = arg;
1306
1306
  this.refresh();
1307
1307
  }
@@ -1346,8 +1346,8 @@ var require_timers = __commonJS({
1346
1346
  * when the timer expires.
1347
1347
  * @returns {NodeJS.Timeout|FastTimer}
1348
1348
  */
1349
- setTimeout(callback, delay2, arg) {
1350
- return delay2 <= RESOLUTION_MS ? setTimeout(callback, delay2, arg) : new FastTimer(callback, delay2, arg);
1349
+ setTimeout(callback, delay3, arg) {
1350
+ return delay3 <= RESOLUTION_MS ? setTimeout(callback, delay3, arg) : new FastTimer(callback, delay3, arg);
1351
1351
  },
1352
1352
  /**
1353
1353
  * The clearTimeout method cancels an instantiated Timer previously created
@@ -1373,8 +1373,8 @@ var require_timers = __commonJS({
1373
1373
  * when the timer expires.
1374
1374
  * @returns {FastTimer}
1375
1375
  */
1376
- setFastTimeout(callback, delay2, arg) {
1377
- return new FastTimer(callback, delay2, arg);
1376
+ setFastTimeout(callback, delay3, arg) {
1377
+ return new FastTimer(callback, delay3, arg);
1378
1378
  },
1379
1379
  /**
1380
1380
  * The clearTimeout method cancels an instantiated FastTimer previously
@@ -1400,8 +1400,8 @@ var require_timers = __commonJS({
1400
1400
  * @deprecated
1401
1401
  * @param {number} [delay=0] The delay in milliseconds to add to the now value.
1402
1402
  */
1403
- tick(delay2 = 0) {
1404
- fastNow += delay2 - RESOLUTION_MS + 1;
1403
+ tick(delay3 = 0) {
1404
+ fastNow += delay3 - RESOLUTION_MS + 1;
1405
1405
  onTick();
1406
1406
  onTick();
1407
1407
  },
@@ -9416,29 +9416,29 @@ var require_parser_h1 = __commonJS({
9416
9416
  this.updateBuffers();
9417
9417
  }
9418
9418
  }
9419
- setTimeout(delay2, type) {
9420
- if (delay2 !== this.timeoutValue || type & USE_FAST_TIMER ^ this.timeoutType & USE_FAST_TIMER) {
9419
+ setTimeout(delay3, type) {
9420
+ if (delay3 !== this.timeoutValue || type & USE_FAST_TIMER ^ this.timeoutType & USE_FAST_TIMER) {
9421
9421
  if (this.timeout) {
9422
9422
  timers.clearTimeout(this.timeout);
9423
9423
  this.timeout = null;
9424
9424
  }
9425
- if (delay2) {
9425
+ if (delay3) {
9426
9426
  if (type & USE_FAST_TIMER) {
9427
9427
  this.timeout = timers.setFastTimeout(
9428
9428
  onParserTimeout,
9429
- delay2,
9429
+ delay3,
9430
9430
  this.timeoutWeakRef
9431
9431
  );
9432
9432
  } else {
9433
9433
  this.timeout = setTimeout(
9434
9434
  onParserTimeout,
9435
- delay2,
9435
+ delay3,
9436
9436
  this.timeoutWeakRef
9437
9437
  );
9438
9438
  this.timeout?.unref();
9439
9439
  }
9440
9440
  }
9441
- this.timeoutValue = delay2;
9441
+ this.timeoutValue = delay3;
9442
9442
  } else if (this.timeout?.refresh) {
9443
9443
  this.timeout.refresh();
9444
9444
  }
@@ -11024,21 +11024,21 @@ var require_client_h1 = __commonJS({
11024
11024
  this.connection = "";
11025
11025
  this.maxResponseSize = client[kMaxResponseSize];
11026
11026
  }
11027
- setTimeout(delay2, type) {
11028
- if (delay2 !== this.timeoutValue || type & USE_FAST_TIMER ^ this.timeoutType & USE_FAST_TIMER) {
11027
+ setTimeout(delay3, type) {
11028
+ if (delay3 !== this.timeoutValue || type & USE_FAST_TIMER ^ this.timeoutType & USE_FAST_TIMER) {
11029
11029
  if (this.timeout) {
11030
11030
  timers.clearTimeout(this.timeout);
11031
11031
  this.timeout = null;
11032
11032
  }
11033
- if (delay2) {
11033
+ if (delay3) {
11034
11034
  if (type & USE_FAST_TIMER) {
11035
- this.timeout = timers.setFastTimeout(onParserTimeout, delay2, this.timeoutWeakRef);
11035
+ this.timeout = timers.setFastTimeout(onParserTimeout, delay3, this.timeoutWeakRef);
11036
11036
  } else {
11037
- this.timeout = setTimeout(onParserTimeout, delay2, this.timeoutWeakRef);
11037
+ this.timeout = setTimeout(onParserTimeout, delay3, this.timeoutWeakRef);
11038
11038
  this.timeout?.unref();
11039
11039
  }
11040
11040
  }
11041
- this.timeoutValue = delay2;
11041
+ this.timeoutValue = delay3;
11042
11042
  } else if (this.timeout) {
11043
11043
  if (this.timeout.refresh) {
11044
11044
  this.timeout.refresh();
@@ -19157,7 +19157,7 @@ var require_mock_utils = __commonJS({
19157
19157
  }
19158
19158
  __name(mockDispatch, "mockDispatch");
19159
19159
  function dispatchMockReply(mockDispatches, mockDispatch2, key, opts, handler, resolvedResponse) {
19160
- const { data: responseData, delay: delay2 } = mockDispatch2;
19160
+ const { data: responseData, delay: delay3 } = mockDispatch2;
19161
19161
  const response = resolvedResponse ?? responseData;
19162
19162
  if (response.error !== null) {
19163
19163
  deleteMockDispatch(mockDispatches, key);
@@ -19249,11 +19249,11 @@ var require_mock_utils = __commonJS({
19249
19249
  handleReply(dispatches, { ...responseDefaults, ...callbackResult });
19250
19250
  return;
19251
19251
  }
19252
- if (typeof delay2 === "number" && delay2 > 0) {
19252
+ if (typeof delay3 === "number" && delay3 > 0) {
19253
19253
  timer = setTimeout(() => {
19254
19254
  timer = null;
19255
19255
  handleReply(dispatches);
19256
- }, delay2);
19256
+ }, delay3);
19257
19257
  } else {
19258
19258
  handleReply(dispatches);
19259
19259
  }
@@ -63537,13 +63537,13 @@ var init_streamableHttp = __esm({
63537
63537
  this.onerror?.(new Error(`Maximum reconnection attempts (${maxRetries}) exceeded.`));
63538
63538
  return;
63539
63539
  }
63540
- const delay2 = this._getNextReconnectionDelay(attemptCount);
63540
+ const delay3 = this._getNextReconnectionDelay(attemptCount);
63541
63541
  this._reconnectionTimeout = setTimeout(() => {
63542
63542
  this._startOrAuthSse(options2).catch((error3) => {
63543
63543
  this.onerror?.(new Error(`Failed to reconnect SSE stream: ${error3 instanceof Error ? error3.message : String(error3)}`));
63544
63544
  this._scheduleReconnection(options2, attemptCount + 1);
63545
63545
  });
63546
- }, delay2);
63546
+ }, delay3);
63547
63547
  }
63548
63548
  _handleSseStream(stream, options2, isReconnectable) {
63549
63549
  if (!stream) {
@@ -78418,11 +78418,11 @@ async function awaitDeployChecks(client, checks, opts = {}) {
78418
78418
  const sleep5 = opts.sleep ?? ((ms2) => new Promise((r) => setTimeout(r, ms2)));
78419
78419
  const deadline = now2() + (opts.waitMs ?? TEST_CHECKS_WAIT_MS);
78420
78420
  let last = null;
78421
- let delay2 = opts.firstDelayMs ?? 0;
78421
+ let delay3 = opts.firstDelayMs ?? 0;
78422
78422
  let rateLimited = false;
78423
- for (let attempt = 0; now2() + delay2 <= deadline; attempt++) {
78424
- if (delay2)
78425
- await sleep5(delay2);
78423
+ for (let attempt = 0; now2() + delay3 <= deadline; attempt++) {
78424
+ if (delay3)
78425
+ await sleep5(delay3);
78426
78426
  let retryAfter = 0;
78427
78427
  try {
78428
78428
  const read = await client.call("GET", target.path, void 0, target.query, { timeoutMs: Math.max(1e3, deadline - now2()), onRetryAfter: /* @__PURE__ */ __name((ms2) => {
@@ -78441,7 +78441,7 @@ async function awaitDeployChecks(client, checks, opts = {}) {
78441
78441
  return null;
78442
78442
  rateLimited ||= retryAfter > 0;
78443
78443
  }
78444
- delay2 = Math.max(opts.pollMs ?? interactivePollDelay(attempt), retryAfter);
78444
+ delay3 = Math.max(opts.pollMs ?? interactivePollDelay(attempt), retryAfter);
78445
78445
  }
78446
78446
  return last ?? (rateLimited && opts.readStored ? { status: "unavailable", sentence: "The platform asked us to wait before reading the check again." } : null);
78447
78447
  }
@@ -78905,6 +78905,7 @@ var init_build_errors = __esm({
78905
78905
  // dist/lib/deploy-blobs.js
78906
78906
  import { createReadStream } from "node:fs";
78907
78907
  import { join as join23 } from "node:path";
78908
+ import { setTimeout as delay } from "node:timers/promises";
78908
78909
  async function uploadDeployBlobs(client, dir, projectId, paths, hashes) {
78909
78910
  const files = /* @__PURE__ */ new Map();
78910
78911
  for (const [path3, size] of paths) {
@@ -78914,49 +78915,101 @@ async function uploadDeployBlobs(client, dir, projectId, paths, hashes) {
78914
78915
  process.stderr.write(`Checking ${paths.size} static files...
78915
78916
  `);
78916
78917
  const checkStarted = performance.now();
78917
- const { missing } = await client.call("POST", "/deploy/blobs/check", {
78918
+ const { missing, upload_grant: grant } = await client.call("POST", "/deploy/blobs/check", {
78918
78919
  project_id: projectId,
78920
+ upload_grants: true,
78919
78921
  files: [...files.values()].map(({ sha256: sha2563, size }) => ({ sha256: sha2563, size }))
78920
78922
  }, void 0, { timeoutMs: LONG_CALL_TIMEOUT_MS });
78921
78923
  const checkMs = performance.now() - checkStarted;
78922
78924
  process.stderr.write(`Uploading ${missing.length} of ${files.size} distinct static files.
78923
78925
  `);
78924
78926
  const uploadStarted = performance.now();
78927
+ const queue = missing.map((sha2563) => {
78928
+ const file = files.get(sha2563);
78929
+ if (!file || grant && !grant.proofs[sha2563]) {
78930
+ throw new Error("The upload check returned an unexpected file or grant. Nothing was published.");
78931
+ }
78932
+ return file;
78933
+ });
78934
+ const query = new URLSearchParams({ project_id: grant?.project_id ?? projectId });
78935
+ const failures = [];
78925
78936
  let next = 0;
78926
- let failure2;
78927
- const query = new URLSearchParams({ project_id: projectId });
78928
- await Promise.all(Array.from({ length: Math.min(missing.length, PARALLEL_UPLOADS) }, async () => {
78929
- while (next < missing.length && !failure2) {
78930
- const file = files.get(missing[next++]);
78931
- if (!file)
78932
- throw new Error("The deploy returned an unknown file hash.");
78933
- try {
78934
- const response = await client.callStream("PUT", `/deploy/blobs/${file.sha256}?${query}`, () => createReadStream(join23(dir, file.path)), {
78935
- headers: { "Content-Type": "application/octet-stream", "Content-Length": String(file.size) },
78936
- replayableBody: true,
78937
- timeoutMs: LONG_CALL_TIMEOUT_MS
78937
+ let concurrency = grant ? GRANTED_PARALLEL_UPLOADS : LEGACY_PARALLEL_UPLOADS;
78938
+ let active = 0;
78939
+ let transientFailures = 0;
78940
+ let waiters = [];
78941
+ async function send(file) {
78942
+ while (active >= concurrency)
78943
+ await new Promise((resolve27) => waiters.push(resolve27));
78944
+ active++;
78945
+ try {
78946
+ const response = await client.callStream("PUT", `/deploy/blobs/${file.sha256}?${query}`, () => createReadStream(join23(dir, file.path)), {
78947
+ headers: {
78948
+ "Content-Type": "application/octet-stream",
78949
+ "Content-Length": String(file.size),
78950
+ ...grant ? { "x-sw-deploy-upload-grant": grant.proofs[file.sha256] } : {}
78951
+ },
78952
+ replayableBody: true,
78953
+ timeoutMs: LONG_CALL_TIMEOUT_MS
78954
+ });
78955
+ const answer = await response.json().catch(() => null);
78956
+ if (!response.ok || answer?.ok !== true) {
78957
+ throw new CliApiError(answer?.error ?? (response.ok ? "NETWORK_ERROR" : "BLOB_UPLOAD_FAILED"), answer?.message ?? `Upload returned HTTP ${response.status}.`, response.status, void 0, void 0, {
78958
+ retryAfterMs: Math.max(retryAfterMs(response.headers.get("retry-after")) ?? 0, answer?.retry_after_ms ?? 0)
78938
78959
  });
78939
- const answer = await response.json().catch(() => null);
78940
- if (!response.ok || answer?.ok !== true) {
78941
- throw new CliApiError(answer?.error ?? "BLOB_UPLOAD_FAILED", answer?.message ?? `Upload returned HTTP ${response.status}.`, response.status);
78960
+ }
78961
+ } finally {
78962
+ active--;
78963
+ const waiting = waiters;
78964
+ waiters = [];
78965
+ for (const wake of waiting)
78966
+ wake();
78967
+ }
78968
+ }
78969
+ __name(send, "send");
78970
+ await Promise.all(Array.from({ length: Math.min(queue.length, concurrency) }, async () => {
78971
+ while (next < queue.length && !failures.length) {
78972
+ const file = queue[next++];
78973
+ for (let attempt = 1; attempt <= UPLOAD_ATTEMPTS; attempt++) {
78974
+ try {
78975
+ await send(file);
78976
+ break;
78977
+ } catch (cause) {
78978
+ const error3 = cause instanceof CliApiError ? cause : new CliApiError("BLOB_UPLOAD_FAILED", String(cause), 0);
78979
+ const retryable = [429, 503].includes(error3.statusCode) || ["NETWORK_ERROR", "TIMEOUT", "SERVER_SLOW"].includes(error3.code);
78980
+ if (retryable && ++transientFailures >= 2 && concurrency > 4) {
78981
+ concurrency = Math.max(4, Math.floor(concurrency / 2));
78982
+ transientFailures = 0;
78983
+ }
78984
+ if (!retryable || attempt === UPLOAD_ATTEMPTS) {
78985
+ failures.push({ path: file.path, error: error3 });
78986
+ break;
78987
+ }
78988
+ await delay(Math.min(5e3, Math.max(200 * 2 ** (attempt - 1) + Math.random() * 100, error3.meta.retryAfterMs ?? 0)));
78942
78989
  }
78943
- } catch (cause) {
78944
- failure2 ??= new CliApiError(cause instanceof CliApiError ? cause.code : "BLOB_UPLOAD_FAILED", `Could not upload "${file.path}". ${cause instanceof Error ? cause.message : String(cause)}`, cause instanceof CliApiError ? cause.statusCode : 0);
78945
78990
  }
78946
78991
  }
78947
78992
  }));
78948
- if (failure2)
78949
- throw failure2;
78993
+ if (failures.length) {
78994
+ const { error: error3 } = failures[0];
78995
+ const detail = failures.map((failure2) => `"${failure2.path}": ${failure2.error.message}`).join("\n");
78996
+ const remaining = next < queue.length ? ` ${queue.length - next} more files were held back.` : "";
78997
+ throw new CliApiError(error3.code, `Could not upload static files. Nothing was published.${remaining}
78998
+ ${detail}`, error3.statusCode);
78999
+ }
78950
79000
  const uploadMs = performance.now() - uploadStarted;
78951
79001
  const blobFiles = Object.fromEntries([...paths.keys()].map((path3) => [path3, `sha256:${hashes[path3]}`]));
78952
79002
  return { blobFiles, checkMs, uploadMs };
78953
79003
  }
78954
- var PARALLEL_UPLOADS;
79004
+ var GRANTED_PARALLEL_UPLOADS, LEGACY_PARALLEL_UPLOADS, UPLOAD_ATTEMPTS;
78955
79005
  var init_deploy_blobs = __esm({
78956
79006
  "dist/lib/deploy-blobs.js"() {
78957
79007
  "use strict";
79008
+ init_poll_delay();
78958
79009
  init_client();
78959
- PARALLEL_UPLOADS = 32;
79010
+ GRANTED_PARALLEL_UPLOADS = 24;
79011
+ LEGACY_PARALLEL_UPLOADS = 8;
79012
+ UPLOAD_ATTEMPTS = 3;
78960
79013
  __name(uploadDeployBlobs, "uploadDeployBlobs");
78961
79014
  }
78962
79015
  });
@@ -85805,9 +85858,9 @@ function outcomeUnknown(err) {
85805
85858
  }
85806
85859
  async function recoverDeployOutcome(client, projectId, attemptId) {
85807
85860
  const query = { project_id: projectId, deploy_attempt_id: attemptId };
85808
- for (const delay2 of [0, 1e3, 2e3, 4e3, 8e3]) {
85809
- if (delay2)
85810
- await new Promise((resolve27) => setTimeout(resolve27, delay2));
85861
+ for (const delay3 of [0, 1e3, 2e3, 4e3, 8e3]) {
85862
+ if (delay3)
85863
+ await new Promise((resolve27) => setTimeout(resolve27, delay3));
85811
85864
  const status = await client.call("GET", "/deploy/status", void 0, query, { timeoutMs: 2e3, refresh: false }).catch(() => null);
85812
85865
  if (status?.deployment_outcome === "live" && status.verified === true && typeof status.release_id === "string" && status.release_id === status.active_release_id && status.project_id === projectId && typeof status.version === "number") {
85813
85866
  return { ...status, has_functions: status.has_functions === true };
@@ -90691,18 +90744,18 @@ async function waitForPreviewJob(client, jobId, timeoutSeconds, firstDelayMs = 0
90691
90744
  const startedAt = Date.now();
90692
90745
  const deadline = startedAt + timeoutSeconds * 1e3;
90693
90746
  let job;
90694
- let delay2 = firstDelayMs;
90747
+ let delay3 = firstDelayMs;
90695
90748
  for (; ; ) {
90696
90749
  const remaining = deadline - Date.now();
90697
- if (delay2 >= remaining) {
90750
+ if (delay3 >= remaining) {
90698
90751
  if (remaining > 0)
90699
90752
  await sleep2(remaining);
90700
90753
  if (job)
90701
90754
  return { job, timedOut: true };
90702
90755
  throw new Error("The wait expired before the platform returned the preview job status.");
90703
90756
  }
90704
- if (delay2)
90705
- await sleep2(delay2);
90757
+ if (delay3)
90758
+ await sleep2(delay3);
90706
90759
  let retryAfter = 0;
90707
90760
  try {
90708
90761
  job = await client.call("GET", `/preview-tools/jobs/${encodeURIComponent(jobId)}`, void 0, void 0, {
@@ -90717,7 +90770,7 @@ async function waitForPreviewJob(client, jobId, timeoutSeconds, firstDelayMs = 0
90717
90770
  throw error3;
90718
90771
  retryAfter = Math.max(retryAfter, error3.meta.retryAfterMs);
90719
90772
  }
90720
- delay2 = Math.max(jobPollDelay(Date.now() - startedAt), retryAfter);
90773
+ delay3 = Math.max(jobPollDelay(Date.now() - startedAt), retryAfter);
90721
90774
  }
90722
90775
  }
90723
90776
  var TERMINAL;
@@ -134413,16 +134466,16 @@ async function waitForJob(client, admitted, timeoutSeconds, firstDelayMs) {
134413
134466
  const startedAt = Date.now();
134414
134467
  const deadline = startedAt + timeoutSeconds * 1e3;
134415
134468
  let job = admitted;
134416
- let delay2 = firstDelayMs;
134469
+ let delay3 = firstDelayMs;
134417
134470
  for (; ; ) {
134418
134471
  const remaining = deadline - Date.now();
134419
- if (delay2 >= remaining) {
134472
+ if (delay3 >= remaining) {
134420
134473
  if (remaining > 0)
134421
134474
  await sleep4(remaining);
134422
134475
  return { job, timedOut: true };
134423
134476
  }
134424
- if (delay2)
134425
- await sleep4(delay2);
134477
+ if (delay3)
134478
+ await sleep4(delay3);
134426
134479
  let retryAfter;
134427
134480
  try {
134428
134481
  const view = jobView(await client.call("GET", path3, void 0, void 0, {
@@ -134439,7 +134492,7 @@ async function waitForJob(client, admitted, timeoutSeconds, firstDelayMs) {
134439
134492
  throw error3;
134440
134493
  retryAfter = Math.max(retryAfter ?? 0, hint ?? 0);
134441
134494
  }
134442
- delay2 = Math.max(jobPollDelay(Date.now() - startedAt), retryAfter ?? 0);
134495
+ delay3 = Math.max(jobPollDelay(Date.now() - startedAt), retryAfter ?? 0);
134443
134496
  }
134444
134497
  }
134445
134498
  function observedCronConfig(cron) {
@@ -136564,7 +136617,7 @@ var init_test_session = __esm({
136564
136617
  // dist/lib/prepared-actor-session.js
136565
136618
  import { createHash as createHash10 } from "node:crypto";
136566
136619
  import { closeSync as closeSync6, openSync as openSync6, rmSync as rmSync16 } from "node:fs";
136567
- import { setTimeout as delay } from "node:timers/promises";
136620
+ import { setTimeout as delay2 } from "node:timers/promises";
136568
136621
  async function preparedActorSession(root, target, name) {
136569
136622
  const read = /* @__PURE__ */ __name(() => preparedActorState(root, target, name), "read");
136570
136623
  const initial = read();
@@ -136583,7 +136636,7 @@ async function preparedActorSession(root, target, name) {
136583
136636
  const latest = read();
136584
136637
  if (!testAccessNeedsRefresh(latest.access))
136585
136638
  return latest.access;
136586
- await delay(100);
136639
+ await delay2(100);
136587
136640
  continue;
136588
136641
  }
136589
136642
  try {