@tinycloud/cli 1.3.0-beta.25 → 1.3.0-beta.27

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/index.js CHANGED
@@ -1666,6 +1666,19 @@ var init_delegation_expiry = __esm({
1666
1666
  }
1667
1667
  });
1668
1668
 
1669
+ // src/lib/retry-policy.ts
1670
+ function cliRetryPolicy() {
1671
+ return process.env.TINYCLOUD_RETRY === "0" ? { retryPolicy: { maxAttempts: 1 } } : {};
1672
+ }
1673
+ function applyNoRetryFlag(opts) {
1674
+ if (opts.retry === false) process.env.TINYCLOUD_RETRY = "0";
1675
+ }
1676
+ var init_retry_policy = __esm({
1677
+ "src/lib/retry-policy.ts"() {
1678
+ "use strict";
1679
+ }
1680
+ });
1681
+
1669
1682
  // src/lib/replication-log.ts
1670
1683
  import { CLI_NAME as CLI_NAME7 } from "@tinycloud/operations/cli-name";
1671
1684
  import { appendFileSync, chmodSync, mkdirSync, renameSync, statSync, writeFileSync } from "fs";
@@ -5336,12 +5349,15 @@ CREATE TABLE IF NOT EXISTS grant_install (
5336
5349
  }
5337
5350
  #storeGrantPolicy(g, policy, existing) {
5338
5351
  const installedAt = existing?.installedAt ?? policy.at;
5352
+ const keepExisting = existing !== null && existing.consentDeadline < policy.consentDeadline;
5353
+ const consentDeadline = keepExisting ? existing.consentDeadline : policy.consentDeadline;
5354
+ const consentAnchor = keepExisting ? existing.consentAnchor : policy.consentAnchor;
5339
5355
  const effectiveExpiresAt = Math.min(
5340
5356
  g.expiresAt === null ? Infinity : g.expiresAt * 1e3,
5341
5357
  installedAt + policy.ttlMs,
5342
- policy.consentDeadline
5358
+ consentDeadline
5343
5359
  );
5344
- if (!Number.isSafeInteger(installedAt) || installedAt < 0 || !Number.isSafeInteger(effectiveExpiresAt) || effectiveExpiresAt < 0 || !Number.isSafeInteger(policy.consentDeadline) || policy.consentDeadline < 0 || !Number.isSafeInteger(policy.consentAnchor.at) || policy.consentAnchor.at < 0 || !Number.isSafeInteger(policy.ttlMs) || policy.ttlMs <= 0) {
5360
+ if (!Number.isSafeInteger(installedAt) || installedAt < 0 || !Number.isSafeInteger(effectiveExpiresAt) || effectiveExpiresAt < 0 || !Number.isSafeInteger(consentDeadline) || consentDeadline < 0 || !Number.isSafeInteger(consentAnchor.at) || consentAnchor.at < 0 || !Number.isSafeInteger(policy.ttlMs) || policy.ttlMs <= 0) {
5345
5361
  throw new ReplicaError3(ReplicaErrorCode3.GRANT_EXPIRED, "The replica grant has no finite effective expiry.");
5346
5362
  }
5347
5363
  this.#db.run(
@@ -5353,11 +5369,11 @@ CREATE TABLE IF NOT EXISTS grant_install (
5353
5369
  g.cid,
5354
5370
  installedAt,
5355
5371
  effectiveExpiresAt,
5356
- policy.consentDeadline,
5357
- policy.consentAnchor.at,
5358
- policy.consentAnchor.source
5372
+ consentDeadline,
5373
+ consentAnchor.at,
5374
+ consentAnchor.source
5359
5375
  );
5360
- return { installedAt, effectiveExpiresAt, consentDeadline: policy.consentDeadline, consentAnchor: policy.consentAnchor };
5376
+ return { installedAt, effectiveExpiresAt, consentDeadline, consentAnchor };
5361
5377
  }
5362
5378
  async installGatedGrant(g, policy) {
5363
5379
  return this.#guardedWrite("Installing the gated grant", () => {
@@ -6740,6 +6756,7 @@ async function storedSessionVerifiesLocally(profileName) {
6740
6756
  if (!session || typeof session.delegationCid !== "string" || typeof session.spaceId !== "string" || session.delegationHeader === null || typeof session.delegationHeader !== "object" || !("Authorization" in session.delegationHeader) || typeof session.delegationHeader.Authorization !== "string") return true;
6741
6757
  const key = await ProfileManager.getKey(profileName);
6742
6758
  const node = new TinyCloudNode({
6759
+ ...cliRetryPolicy(),
6743
6760
  host: profile.host ?? DEFAULT_HOST,
6744
6761
  ...local ? { privateKey: profile.privateKey } : {}
6745
6762
  });
@@ -6785,6 +6802,7 @@ async function createSDKInstance(ctx, options) {
6785
6802
  process.stderr.write("[replication] Enabled, but this profile has no configured prefixes; reads use the network.\n");
6786
6803
  }
6787
6804
  const node2 = new TinyCloudNode({
6805
+ ...cliRetryPolicy(),
6788
6806
  host: ctx.host,
6789
6807
  privateKey: effectivePrivateKey,
6790
6808
  ...replication2 ? { replication: replication2 } : {}
@@ -6825,6 +6843,7 @@ async function createSDKInstance(ctx, options) {
6825
6843
  process.stderr.write("[replication] Enabled, but this profile has no configured prefixes; reads use the network.\n");
6826
6844
  }
6827
6845
  const node = new TinyCloudNode({
6846
+ ...cliRetryPolicy(),
6828
6847
  host: ctx.host,
6829
6848
  privateKey: options?.privateKey,
6830
6849
  ...replication ? { replication } : {}
@@ -6988,6 +7007,7 @@ var init_sdk = __esm({
6988
7007
  init_session_expired();
6989
7008
  init_warnings();
6990
7009
  init_delegation_expiry();
7010
+ init_retry_policy();
6991
7011
  init_replication_config();
6992
7012
  init_replication_registry();
6993
7013
  init_logout_pending();
@@ -27631,6 +27651,7 @@ async function loadCourierEntry() {
27631
27651
  }
27632
27652
 
27633
27653
  // src/index.ts
27654
+ init_retry_policy();
27634
27655
  var { version } = JSON.parse(
27635
27656
  readFileSync2(new URL("../package.json", import.meta.url), "utf-8")
27636
27657
  );
@@ -27648,10 +27669,11 @@ function selectedShareProfile() {
27648
27669
  }
27649
27670
  return process.env.TC_PROFILE;
27650
27671
  }
27651
- program.name(CLI_NAME13).description("TinyCloud CLI \u2014 self-sovereign storage from the terminal").version(version).option("-p, --profile <name>", "Profile to use").option("-H, --host <url>", "TinyCloud node URL").option("-v, --verbose", "Enable verbose output").option("--no-cache", "Disable caching").option("-q, --quiet", "Suppress non-essential output").option("--json", "Force JSON output").option("--replication", "Enable read-through replication for this invocation").option("--no-replication", "Disable read-through replication for this invocation").option("--replication-debug", "Write replication diagnostics to stderr");
27672
+ program.name(CLI_NAME13).description("TinyCloud CLI \u2014 self-sovereign storage from the terminal").version(version).option("-p, --profile <name>", "Profile to use").option("-H, --host <url>", "TinyCloud node URL").option("-v, --verbose", "Enable verbose output").option("--no-cache", "Disable caching").option("-q, --quiet", "Suppress non-essential output").option("--json", "Force JSON output").option("--no-retry", "Do not retry node busy/timeout answers (monitors and probes); same as TINYCLOUD_RETRY=0").option("--replication", "Enable read-through replication for this invocation").option("--no-replication", "Disable read-through replication for this invocation").option("--replication-debug", "Write replication diagnostics to stderr");
27652
27673
  program.hook("preAction", async (thisCommand) => {
27653
27674
  const opts = thisCommand.optsWithGlobals();
27654
27675
  setJsonOutputRequested(opts.json === true);
27676
+ applyNoRetryFlag(opts);
27655
27677
  const parentName = thisCommand.parent?.name();
27656
27678
  const isShareCommand = parentName === "share" || thisCommand.name() === "share";
27657
27679
  if (!opts.quiet && !isShareCommand) {