@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.
@@ -3052,6 +3052,16 @@ var init_delegation_expiry = __esm({
3052
3052
  }
3053
3053
  });
3054
3054
 
3055
+ // src/lib/retry-policy.ts
3056
+ function cliRetryPolicy() {
3057
+ return process.env.TINYCLOUD_RETRY === "0" ? { retryPolicy: { maxAttempts: 1 } } : {};
3058
+ }
3059
+ var init_retry_policy = __esm({
3060
+ "src/lib/retry-policy.ts"() {
3061
+ "use strict";
3062
+ }
3063
+ });
3064
+
3055
3065
  // src/lib/replication-log.ts
3056
3066
  import { CLI_NAME as CLI_NAME5 } from "@tinycloud/operations/cli-name";
3057
3067
  import { appendFileSync, chmodSync, mkdirSync, renameSync, statSync, writeFileSync } from "fs";
@@ -7647,12 +7657,15 @@ CREATE TABLE IF NOT EXISTS grant_install (
7647
7657
  }
7648
7658
  #storeGrantPolicy(g, policy, existing) {
7649
7659
  const installedAt = existing?.installedAt ?? policy.at;
7660
+ const keepExisting = existing !== null && existing.consentDeadline < policy.consentDeadline;
7661
+ const consentDeadline = keepExisting ? existing.consentDeadline : policy.consentDeadline;
7662
+ const consentAnchor = keepExisting ? existing.consentAnchor : policy.consentAnchor;
7650
7663
  const effectiveExpiresAt = Math.min(
7651
7664
  g.expiresAt === null ? Infinity : g.expiresAt * 1e3,
7652
7665
  installedAt + policy.ttlMs,
7653
- policy.consentDeadline
7666
+ consentDeadline
7654
7667
  );
7655
- 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) {
7668
+ 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) {
7656
7669
  throw new ReplicaError3(ReplicaErrorCode3.GRANT_EXPIRED, "The replica grant has no finite effective expiry.");
7657
7670
  }
7658
7671
  this.#db.run(
@@ -7664,11 +7677,11 @@ CREATE TABLE IF NOT EXISTS grant_install (
7664
7677
  g.cid,
7665
7678
  installedAt,
7666
7679
  effectiveExpiresAt,
7667
- policy.consentDeadline,
7668
- policy.consentAnchor.at,
7669
- policy.consentAnchor.source
7680
+ consentDeadline,
7681
+ consentAnchor.at,
7682
+ consentAnchor.source
7670
7683
  );
7671
- return { installedAt, effectiveExpiresAt, consentDeadline: policy.consentDeadline, consentAnchor: policy.consentAnchor };
7684
+ return { installedAt, effectiveExpiresAt, consentDeadline, consentAnchor };
7672
7685
  }
7673
7686
  async installGatedGrant(g, policy) {
7674
7687
  return this.#guardedWrite("Installing the gated grant", () => {
@@ -9081,6 +9094,7 @@ async function storedSessionVerifiesLocally(profileName2) {
9081
9094
  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;
9082
9095
  const key = await ProfileManager.getKey(profileName2);
9083
9096
  const node = new TinyCloudNode({
9097
+ ...cliRetryPolicy(),
9084
9098
  host: profile.host ?? DEFAULT_HOST,
9085
9099
  ...local ? { privateKey: profile.privateKey } : {}
9086
9100
  });
@@ -9126,6 +9140,7 @@ async function createSDKInstance(ctx, options) {
9126
9140
  process.stderr.write("[replication] Enabled, but this profile has no configured prefixes; reads use the network.\n");
9127
9141
  }
9128
9142
  const node2 = new TinyCloudNode({
9143
+ ...cliRetryPolicy(),
9129
9144
  host: ctx.host,
9130
9145
  privateKey: effectivePrivateKey,
9131
9146
  ...replication2 ? { replication: replication2 } : {}
@@ -9166,6 +9181,7 @@ async function createSDKInstance(ctx, options) {
9166
9181
  process.stderr.write("[replication] Enabled, but this profile has no configured prefixes; reads use the network.\n");
9167
9182
  }
9168
9183
  const node = new TinyCloudNode({
9184
+ ...cliRetryPolicy(),
9169
9185
  host: ctx.host,
9170
9186
  privateKey: options?.privateKey,
9171
9187
  ...replication ? { replication } : {}
@@ -9329,6 +9345,7 @@ var init_sdk = __esm({
9329
9345
  init_session_expired();
9330
9346
  init_warnings();
9331
9347
  init_delegation_expiry();
9348
+ init_retry_policy();
9332
9349
  init_replication_config();
9333
9350
  init_replication_registry();
9334
9351
  init_logout_pending();
@@ -15450,6 +15467,9 @@ async function kvHandle(node, spaceInput, profileName2) {
15450
15467
  const kv = spaceUri ? node.kvForSpace(spaceUri) : node.kv;
15451
15468
  return { kv, spaceUri };
15452
15469
  }
15470
+ function retryFields(retry) {
15471
+ return retry ? { attempts: retry.attempts, backoffMs: retry.backoffMs } : {};
15472
+ }
15453
15473
  function registerKvCommand(program) {
15454
15474
  const kv = program.command("kv").description("Key-value store operations");
15455
15475
  kv.command("get <key>").description("Get a value by key").option("--raw", "Output raw value (no JSON wrapping)").option("-o, --output <file>", "Write value to file").option("--space <name|uri>", "Target a non-primary space (short name or full URI)").action(async (key, options, cmd) => {
@@ -15487,7 +15507,8 @@ function registerKvCommand(program) {
15487
15507
  outputJson({
15488
15508
  key,
15489
15509
  data,
15490
- metadata
15510
+ metadata,
15511
+ ...retryFields(result.data.retry)
15491
15512
  });
15492
15513
  } else {
15493
15514
  const content = typeof data === "string" ? data : JSON.stringify(data);
@@ -15527,7 +15548,7 @@ function registerKvCommand(program) {
15527
15548
  if (!result.ok) {
15528
15549
  await throwKvError(result.error, spaceUri, ctx.profile);
15529
15550
  }
15530
- outputJson({ key, written: true });
15551
+ outputJson({ key, written: true, ...retryFields(result.data?.retry) });
15531
15552
  } catch (error) {
15532
15553
  return handleError(error);
15533
15554
  }
@@ -15543,7 +15564,7 @@ function registerKvCommand(program) {
15543
15564
  if (!result.ok) {
15544
15565
  await throwKvError(result.error, spaceUri, ctx.profile);
15545
15566
  }
15546
- outputJson({ key, deleted: true });
15567
+ outputJson({ key, deleted: true, ...retryFields(result.data?.retry) });
15547
15568
  } catch (error) {
15548
15569
  return handleError(error);
15549
15570
  }