@sparkvault/sdk-mobile 10.2.1 → 10.3.0

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/src/ingots.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { CONTENT_CONFLICT_REASONS } from './app-sdk/content-conflict.js';
2
2
  import { readForgeTransferUrl } from './app-sdk/forge-url.js';
3
3
  import { INGOT_ACCESS_EVENT_TYPES, readIngotAccess } from './app-sdk/ingot-access-log.js';
4
- import { classifyTransferResponse } from './app-sdk/transfer-retry.js';
4
+ import { RETRY_AFTER_HEADER, thumbnailBusyWaitMs } from './app-sdk/transfer-retry.js';
5
5
  import { givenUpUploadId } from './app-sdk/upload-publication.js';
6
6
  import type { ResolvedMobileConfig } from './config.js';
7
7
  import {
@@ -217,6 +217,8 @@ export interface DownloadToFileOptions {
217
217
  vaultId: string;
218
218
  ingotId: string;
219
219
  vat: string;
220
+ /** False for automatic display/prefetch; explicit downloads count by default. */
221
+ countAsActivity?: boolean;
220
222
  fileUri: string;
221
223
  expectedSizeBytes?: number;
222
224
  /** Revision from the current metadata read, when available. */
@@ -337,6 +339,8 @@ export interface CreateDownloadLinkOptions {
337
339
  vaultId: string;
338
340
  ingotId: string;
339
341
  vat: string;
342
+ /** False for automatic display/prefetch; explicit downloads count by default. */
343
+ countAsActivity?: boolean;
340
344
  }
341
345
 
342
346
  export interface CreateDownloadLinkResult {
@@ -345,17 +349,6 @@ export interface CreateDownloadLinkResult {
345
349
  downloadUrl: string;
346
350
  }
347
351
 
348
- /** How long a thumbnail download waits out a busy Forge whose answer names no Retry-After. */
349
- const THUMBNAIL_BUSY_DEFAULT_WAIT_MS = 2000;
350
-
351
- /**
352
- * The longest a thumbnail download waits out a busy Forge, whatever its
353
- * Retry-After asks: Forge's busy answer asks 5 s
354
- * (apps/forge/src/routes/thumbnail.js), and no thumbnail is worth a longer
355
- * wait (the web's cap, apps/web/src/services/ThumbnailService.js).
356
- */
357
- const THUMBNAIL_BUSY_MAX_WAIT_MS = 5000;
358
-
359
352
  /** The most ids one thumbnail-links call asks for: Core's page. */
360
353
  export const THUMBNAIL_LINKS_MAX = 50;
361
354
 
@@ -488,17 +481,6 @@ function headerOf(headers: Record<string, string> | undefined, name: string): st
488
481
  return Object.entries(headers ?? {}).find(([header]) => header.toLowerCase() === wanted)?.[1];
489
482
  }
490
483
 
491
- /**
492
- * How long a thumbnail download waits out a busy Forge before its one retry:
493
- * the answer's Retry-After, read by the transfer policy's one parser, at most
494
- * THUMBNAIL_BUSY_MAX_WAIT_MS; THUMBNAIL_BUSY_DEFAULT_WAIT_MS when it names
495
- * none that parses.
496
- */
497
- function busyWaitOf(headers: Record<string, string> | undefined): number {
498
- const { retryAfterMs } = classifyTransferResponse({ status: 503, headers: (name) => headerOf(headers, name) ?? null });
499
- return Math.min(retryAfterMs ?? THUMBNAIL_BUSY_DEFAULT_WAIT_MS, THUMBNAIL_BUSY_MAX_WAIT_MS);
500
- }
501
-
502
484
  /**
503
485
  * The body length a response declared (`Content-Length`), or undefined when
504
486
  * it declared none, or something that is not a non-negative whole number.
@@ -962,7 +944,7 @@ export class MobileIngotsClient {
962
944
  const response = await this.http
963
945
  .post<{ download_url?: string; content_version?: string | null }>(
964
946
  apiPath`/vaults/${vaultId}/ingots/${ingotId}/download`,
965
- undefined,
947
+ options.countAsActivity === undefined ? undefined : { count_as_activity: options.countAsActivity },
966
948
  { vat }
967
949
  )
968
950
  .catch((err: unknown) => {
@@ -1013,9 +995,10 @@ export class MobileIngotsClient {
1013
995
  /**
1014
996
  * Download one thumbnail to a file (Forge's GET /thumbnail). A busy Forge
1015
997
  * (503) hands its single-use token back, so the same URL is tried once more
1016
- * once the wait its answer asks has passed (busyWaitOf); an abort ends that
1017
- * wait at once, with no retry. Anything else that is not the thumbnail
1018
- * leaves no file and answers false: the grid shows the photo's original.
998
+ * once the platform's one thumbnail wait has passed (thumbnailBusyWaitMs,
999
+ * from the answer's Retry-After); an abort ends that wait at once, with no
1000
+ * retry. Anything else that is not the thumbnail leaves no file and answers
1001
+ * false: the grid shows the photo's original.
1019
1002
  *
1020
1003
  * @returns true when the thumbnail landed at fileUri
1021
1004
  */
@@ -1047,7 +1030,7 @@ export class MobileIngotsClient {
1047
1030
  await this.deleteFileIfPresent(fileDownloader, fileUri);
1048
1031
  if (status !== 503 || attempt === 2) return false;
1049
1032
  try {
1050
- await this.delay(busyWaitOf(result?.headers), abortSignal);
1033
+ await this.delay(thumbnailBusyWaitMs(headerOf(result?.headers, RETRY_AFTER_HEADER)), abortSignal);
1051
1034
  } catch {
1052
1035
  // The wait rejects only for an abort: a caller that has gone gets no retry.
1053
1036
  return false;
@@ -1087,7 +1070,8 @@ export class MobileIngotsClient {
1087
1070
  try {
1088
1071
  // Fresh signed URL on every attempt — server URLs are short-lived,
1089
1072
  // and retrying with a stale URL would just fail again.
1090
- const { downloadUrl } = await this.createDownloadLink({ vaultId, ingotId, vat });
1073
+ const { downloadUrl } = await this.createDownloadLink({ vaultId, ingotId, vat,
1074
+ ...(options.countAsActivity === undefined ? {} : { countAsActivity: options.countAsActivity }) });
1091
1075
  const result = await fileDownloader.download(downloadUrl, fileUri, {
1092
1076
  timeoutMs: options.timeoutMs ?? this.config.fileTransferTimeoutMs,
1093
1077
  abortSignal,
package/src/types.ts CHANGED
@@ -594,6 +594,21 @@ export interface Vault {
594
594
  created_at: number;
595
595
  last_unsealed_at?: number;
596
596
  unseal_count?: number;
597
+ /** Null inherits the system default; zero disables inactivity resealing. */
598
+ reseal_idle_seconds?: number | null;
599
+ /** Null inherits the system default; never more than 24 hours. */
600
+ reseal_max_seconds?: number | null;
601
+ reseal_defaults?: { idle_seconds: number; max_seconds: number };
602
+ }
603
+
604
+ export interface VaultResealSettings {
605
+ reseal_idle_seconds: number | null;
606
+ reseal_max_seconds: number | null;
607
+ }
608
+
609
+ export interface VaultResealSettingsResponse extends VaultResealSettings {
610
+ vault_id: string;
611
+ reseal_defaults: { idle_seconds: number; max_seconds: number };
597
612
  }
598
613
 
599
614
  /** The vault's deletion schedule: a company admin can cancel it until `deletion_scheduled_for`. */
@@ -669,6 +684,18 @@ export interface UnsealVaultResponse {
669
684
  issued_at: number;
670
685
  expires_at: number;
671
686
  ttl_seconds: number;
687
+ hard_expires_at?: number;
688
+ idle_timeout_seconds?: number;
689
+ can_extend?: boolean;
690
+ }
691
+
692
+ export interface ExtendVaultSessionResponse {
693
+ vault_id: string;
694
+ expires_at: number;
695
+ hard_expires_at: number;
696
+ idle_timeout_seconds: number;
697
+ ttl_seconds: number;
698
+ can_extend: boolean;
672
699
  }
673
700
 
674
701
  /** One page of GET /v1/vaults. */
package/src/vaults.ts CHANGED
@@ -23,6 +23,9 @@ import type {
23
23
  VaultSharingConfig,
24
24
  VaultSharingOptions,
25
25
  VaultThumbnails,
26
+ VaultResealSettings,
27
+ VaultResealSettingsResponse,
28
+ ExtendVaultSessionResponse,
26
29
  } from './types.js';
27
30
  import { validateVaultId } from './validation.js';
28
31
  import { base64EncodeUtf8 } from './encoding.js';
@@ -79,6 +82,13 @@ export class MobileVaultsClient {
79
82
  return response.data;
80
83
  }
81
84
 
85
+ /** Set this vault's reseal times (organization admins); applies on the next unseal. */
86
+ async updateResealSettings(vaultId: string, settings: VaultResealSettings): Promise<VaultResealSettingsResponse> {
87
+ validateVaultId(vaultId);
88
+ const response = await this.http.put<VaultResealSettingsResponse>(apiPath`/vaults/${vaultId}/reseal-settings`, settings);
89
+ return response.data;
90
+ }
91
+
82
92
  /**
83
93
  * Schedule deletion in seven days and lock the vault immediately. Requires the vault's exact name as
84
94
  * confirmation (case-sensitive). Answers the schedule, or, for a vault whose irreversible cleanup has
@@ -119,6 +129,13 @@ export class MobileVaultsClient {
119
129
  return response.data;
120
130
  }
121
131
 
132
+ /** Explicitly extend the held session's inactivity window, within its original hard maximum. */
133
+ async extendSession(vaultId: string, vat: string): Promise<ExtendVaultSessionResponse> {
134
+ validateVaultId(vaultId);
135
+ const response = await this.http.post<ExtendVaultSessionResponse>(apiPath`/vaults/${vaultId}/session/extend`, undefined, { vat });
136
+ return response.data;
137
+ }
138
+
122
139
  /**
123
140
  * Seal the vault: end every session of it, so every VAT minted for it stops
124
141
  * working, whoever holds it. To end only the caller's own session, use