@sparkvault/sdk-js 15.9.0 → 15.10.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.
@@ -0,0 +1,4 @@
1
+ import type { IngotHistory, IngotHistoryResponse } from './types';
2
+ /** Core files and Structured Ingots expose the same retained publication metadata. */
3
+ export declare function mapIngotHistory(data: IngotHistoryResponse): IngotHistory;
4
+ export declare function requireVersionId(value: unknown): string;
@@ -11,7 +11,7 @@
11
11
  */
12
12
  import { type ResolvedConfig } from '../config';
13
13
  import { HttpClient } from '../http';
14
- import type { UnsealedVault, Ingot, IngotUpload, UploadEnd, CreatedIngot, IngotDownloadLink, DownloadIngotOptions, CreateUploadOptions, UploadIngotOptions, SendUploadOptions, ResumeUploadOptions, UploadSession, ReplaceIngotOptions, ListIngotsOptions, ListContentsOptions, FolderContents, SearchIngotsOptions, IngotPage, IngotSharingConfig, UpdateIngotSharingOptions, IngotInvitation, IngotAccessLogPage, AccessLogsOptions, HashCheckResponse } from './types';
14
+ import type { UnsealedVault, Ingot, IngotUpload, UploadEnd, CreatedIngot, IngotDownloadLink, IngotDownload, IngotHistory, IngotVersionDownloadLink, DeleteIngotOptions, DownloadIngotOptions, CreateUploadOptions, UploadIngotOptions, SendUploadOptions, ResumeUploadOptions, UploadSession, ReplaceIngotOptions, ListIngotsOptions, ListContentsOptions, FolderContents, SearchIngotsOptions, IngotPage, IngotSharingConfig, UpdateIngotSharingOptions, IngotInvitation, IngotAccessLogPage, AccessLogsOptions, HashCheckResponse } from './types';
15
15
  export declare class IngotsModule {
16
16
  private readonly config;
17
17
  private readonly http;
@@ -184,7 +184,10 @@ export declare class IngotsModule {
184
184
  * before the replacement is staged where there is no XMLHttpRequest.
185
185
  *
186
186
  * @example
187
- * await sv.ingots.replace(unsealed, 'ing_abc', { file: updatedFile });
187
+ * const original = await sv.ingots.downloadWithRevision(unsealed, 'ing_abc');
188
+ * await sv.ingots.replace(unsealed, 'ing_abc', {
189
+ * file: updatedFile, expectedRevision: original.revision,
190
+ * });
188
191
  */
189
192
  replace(vault: UnsealedVault, ingotId: string, options: ReplaceIngotOptions): Promise<CreatedIngot>;
190
193
  /**
@@ -206,9 +209,11 @@ export declare class IngotsModule {
206
209
  * Delete an ingot.
207
210
  *
208
211
  * @example
209
- * await sv.ingots.delete(unsealed, 'ing_abc');
212
+ * const original = await sv.ingots.get(unsealed, 'ing_abc');
213
+ * if (!original.revision) throw new Error('This server does not support guarded deletion');
214
+ * await sv.ingots.delete(unsealed, original.id, { expectedRevision: original.revision });
210
215
  */
211
- delete(vault: UnsealedVault, ingotId: string): Promise<void>;
216
+ delete(vault: UnsealedVault, ingotId: string, options?: DeleteIngotOptions): Promise<void>;
212
217
  /**
213
218
  * Get ingot metadata.
214
219
  *
@@ -255,6 +260,12 @@ export declare class IngotsModule {
255
260
  * } while (pageToken);
256
261
  */
257
262
  listContents(vault: UnsealedVault, options?: ListContentsOptions): Promise<FolderContents>;
263
+ /** List previous publications of a file, newest first. Structured objects use their product's history method. */
264
+ listVersions(vault: UnsealedVault, ingotId: string): Promise<IngotHistory>;
265
+ /** Mint a one-use link to a retained file publication; use downloadVersion to verify the served bytes. */
266
+ createVersionDownloadLink(vault: UnsealedVault, ingotId: string, versionId: string): Promise<IngotVersionDownloadLink>;
267
+ /** Download a retained file publication; never substitutes the current bytes if history is unavailable. */
268
+ downloadVersion(vault: UnsealedVault, ingotId: string, versionId: string): Promise<Blob>;
258
269
  /**
259
270
  * Create a signed download link for an ingot (discrete primitive).
260
271
  *
@@ -299,6 +310,12 @@ export declare class IngotsModule {
299
310
  * link.click();
300
311
  */
301
312
  download(vault: UnsealedVault, ingotId: string, options?: DownloadIngotOptions): Promise<Blob>;
313
+ /**
314
+ * Download bytes with their identity-bound revision. Use the returned revision
315
+ * for replace/delete preconditions; the link's earlier metadata may already
316
+ * have been superseded when Forge begins serving the bytes.
317
+ */
318
+ downloadWithRevision(vault: UnsealedVault, ingotId: string, options?: DownloadIngotOptions): Promise<IngotDownload>;
302
319
  /**
303
320
  * Get an ingot's sharing configuration.
304
321
  *
@@ -368,4 +385,4 @@ export { NAME_CONFLICT_POLICIES } from './types';
368
385
  export { fetchDownload } from './fetch-download';
369
386
  export { isReceivedUploadFailure } from '../vaults/upload/api';
370
387
  export type { FetchDownloadOptions, FetchedDownload } from './fetch-download';
371
- export type { NameConflictPolicy, UnsealedVault, Ingot, IngotUpload, UploadEnd, CreatedIngot, IngotDownloadLink, DownloadIngotOptions, CreateUploadOptions, UploadIngotOptions, SendUploadOptions, ResumeUploadOptions, UploadSession, ReplaceIngotOptions, ListIngotsOptions, ListContentsOptions, FolderContents, SearchIngotsOptions, IngotPage, IngotSharingConfig, UpdateIngotSharingOptions, IngotInvite, IngotInvitation, IngotAccessLog, IngotAccessLogPage, AccessLogsOptions, HashCheckResponse, } from './types';
388
+ export type { NameConflictPolicy, UnsealedVault, Ingot, IngotUpload, UploadEnd, CreatedIngot, IngotDownloadLink, IngotDownload, IngotVersion, IngotHistory, IngotVersionDownloadLink, DeleteIngotOptions, DownloadIngotOptions, CreateUploadOptions, UploadIngotOptions, SendUploadOptions, ResumeUploadOptions, UploadSession, ReplaceIngotOptions, ListIngotsOptions, ListContentsOptions, FolderContents, SearchIngotsOptions, IngotPage, IngotSharingConfig, UpdateIngotSharingOptions, IngotInvite, IngotInvitation, IngotAccessLog, IngotAccessLogPage, AccessLogsOptions, HashCheckResponse, } from './types';
@@ -0,0 +1,4 @@
1
+ /** Validate an opaque server revision without interpreting it as a credential. */
2
+ export declare function expectedRevision(value: unknown): string | undefined;
3
+ /** Older servers omit the revision; never invent a precondition from metadata. */
4
+ export declare function readRevision(value: unknown): string | undefined;
@@ -69,6 +69,8 @@ export interface Ingot {
69
69
  contentHmac: string | null;
70
70
  /** Opaque published-content revision; null for legacy/unpublished content. */
71
71
  contentVersion: string | null;
72
+ /** Object identity and publication together; absent on older servers. */
73
+ revision?: string;
72
74
  }
73
75
  /** The discrete primitive returned by createUpload — a Forge TUS session. */
74
76
  export interface IngotUpload {
@@ -131,6 +133,8 @@ export interface DownloadIngotOptions {
131
133
  export interface IngotDownloadLink {
132
134
  /** Opaque published-content revision; null for legacy content. */
133
135
  contentVersion: string | null;
136
+ /** Revision observed when the link was minted, not necessarily the bytes it later serves. */
137
+ revision?: string;
134
138
  /** Short-lived signed Forge download URL */
135
139
  downloadUrl: string;
136
140
  /** Ingot ID */
@@ -142,6 +146,41 @@ export interface IngotDownloadLink {
142
146
  /** Content type (MIME) */
143
147
  contentType: string;
144
148
  }
149
+ /** Downloaded bytes and the revision they belong to, for guarded read-modify-write. */
150
+ export interface IngotDownload {
151
+ blob: Blob;
152
+ revision: string;
153
+ }
154
+ /** One retained publication; current content is not included in version history. */
155
+ export interface IngotVersion {
156
+ versionId: string;
157
+ publishedAt: number;
158
+ sizeBytes: number;
159
+ /** Absent for publications retained before MIME metadata was recorded. */
160
+ contentType?: string;
161
+ }
162
+ export interface IngotHistory {
163
+ id: string;
164
+ /** Maximum previous versions retained on the next successful content change. */
165
+ versionLimit: number;
166
+ /** Retained publications, newest first. */
167
+ versions: IngotVersion[];
168
+ }
169
+ /** A one-use download link bound to a retained publication. */
170
+ export interface IngotVersionDownloadLink {
171
+ id: string;
172
+ downloadUrl: string;
173
+ size: number;
174
+ contentVersion: string;
175
+ revision?: string;
176
+ expiresAt: number;
177
+ name?: string;
178
+ contentType?: string;
179
+ }
180
+ export interface DeleteIngotOptions {
181
+ /** Delete only this object publication. Omitted preserves unconditional deletion. */
182
+ expectedRevision?: string;
183
+ }
145
184
  /** Options for the createUpload primitive. */
146
185
  export interface CreateUploadOptions {
147
186
  /** Unsealed vault the ingot belongs to */
@@ -215,6 +254,8 @@ export type ResumeUploadOptions = Omit<SendUploadOptions, 'onSessionCreated'>;
215
254
  export interface ReplaceIngotOptions {
216
255
  /** File or Blob to upload as the new content */
217
256
  file: File | Blob;
257
+ /** Replace only the object publication read; stale or recreated targets return 412. */
258
+ expectedRevision?: string;
218
259
  /** Optional new name (defaults to file name) */
219
260
  name?: string;
220
261
  /** Vault-keyed plaintext HMAC (43-char base64url) for the NEW content. */
@@ -409,6 +450,7 @@ export interface IngotWire {
409
450
  folder_id?: string | null;
410
451
  content_hmac?: string | null;
411
452
  content_version?: string | null;
453
+ revision?: string;
412
454
  }
413
455
  /** One hash-check hit: this HMAC exists on an active ingot in the vault. */
414
456
  export interface HashCheckMatch {
@@ -459,12 +501,33 @@ export interface ListContentsResponse {
459
501
  }
460
502
  export interface DownloadIngotResponse {
461
503
  content_version?: string | null;
504
+ revision?: string;
462
505
  download_url: string;
463
506
  ingot_id: string;
464
507
  name: string;
465
508
  size_bytes: number;
466
509
  content_type: string;
467
510
  }
511
+ export interface IngotHistoryResponse {
512
+ ingot_id: string;
513
+ version_limit: number;
514
+ versions: Array<{
515
+ version_id: string;
516
+ published_at: number;
517
+ size_bytes: number;
518
+ content_type?: string;
519
+ }>;
520
+ }
521
+ export interface IngotVersionDownloadResponse {
522
+ ingot_id: string;
523
+ download_url: string;
524
+ size_bytes: number;
525
+ content_version: string;
526
+ revision?: string;
527
+ expires_at: number;
528
+ name?: string;
529
+ content_type?: string;
530
+ }
468
531
  /** A sharing answer (apps/api/src/ingots/sharing.js formatSharingConfig). */
469
532
  export interface IngotSharingConfigResponse {
470
533
  ingot_id: string;
@@ -1,7 +1,7 @@
1
1
  import { HttpClient } from '../../http';
2
2
  import type { UnsealedVault } from '../../vaults/types';
3
3
  import { StructuredIngotTypesModule } from './types-client';
4
- import type { BatchGetStructuredIngotsOptions, CreateStructuredIngotOptions, GetStructuredIngotOptions, ImportStructuredIngotsOptions, PatchStructuredIngotOptions, PortableStructuredIngot, StructuredExportOutcome, StructuredImportOutcome, StructuredIngot, StructuredIngotHistory, StructuredIngotMutation, StructuredIngotSummary, StructuredIterateOptions, StructuredPage, StructuredPageOptions, StructuredReadOutcome, StructuredValues, StructuredAccountActivity, StructuredActivityOptions, StructuredVaultActivity } from './types';
4
+ import type { BatchGetStructuredIngotsOptions, CreateStructuredIngotOptions, DeleteStructuredIngotOptions, GetStructuredIngotOptions, ImportStructuredIngotsOptions, PatchStructuredIngotOptions, PortableStructuredIngot, StructuredExportOutcome, StructuredImportOutcome, StructuredIngot, StructuredIngotHistory, StructuredIngotMutation, StructuredIngotSummary, StructuredIterateOptions, StructuredPage, StructuredPageOptions, StructuredReadOutcome, StructuredValues, RestoreStructuredIngotOptions, StructuredAccountActivity, StructuredActivityOptions, StructuredVaultActivity } from './types';
5
5
  /** Typed record operations using the caller's existing account and vault session. */
6
6
  export declare class StructuredIngotsModule {
7
7
  private readonly http;
@@ -17,11 +17,9 @@ export declare class StructuredIngotsModule {
17
17
  /** Names use the server's documented Unicode caseless matching rules. */
18
18
  create<T extends object = StructuredValues>(vault: UnsealedVault, options: CreateStructuredIngotOptions<T>): Promise<StructuredIngotMutation>;
19
19
  patch<T extends object = StructuredValues>(vault: UnsealedVault, ref: string, options: PatchStructuredIngotOptions<T>): Promise<StructuredIngotMutation>;
20
- delete(vault: UnsealedVault, ref: string): Promise<void>;
20
+ delete(vault: UnsealedVault, ref: string, options?: DeleteStructuredIngotOptions): Promise<void>;
21
21
  history(vault: UnsealedVault, ref: string): Promise<StructuredIngotHistory>;
22
- restore(vault: UnsealedVault, ref: string, versionId: string, options: {
23
- expectedVersion: number;
24
- }): Promise<StructuredIngotMutation>;
22
+ restore(vault: UnsealedVault, ref: string, versionId: string, options: RestoreStructuredIngotOptions): Promise<StructuredIngotMutation>;
25
23
  /** Bounded parallel reads with independent, ordered success/error outcomes. */
26
24
  batchGet<T extends object = StructuredValues>(vault: UnsealedVault, refs: string[], options?: BatchGetStructuredIngotsOptions): Promise<StructuredReadOutcome<T>[]>;
27
25
  /** Sequential record reads, not a transactionally consistent vault snapshot. */
@@ -1,3 +1,4 @@
1
+ import type { IngotHistory, IngotVersion } from '../../ingots/types';
1
2
  /** JSON values travel without implicit coercion. Binary leaves use explicit paths. */
2
3
  export type StructuredJsonValue = null | boolean | number | string | StructuredJsonValue[] | {
3
4
  [key: string]: StructuredJsonValue;
@@ -25,6 +26,8 @@ export interface StructuredPage<T> {
25
26
  export interface StructuredIngotSummary {
26
27
  id: string;
27
28
  name: string;
29
+ /** Publication observed by the metadata page; absent when the server cannot supply it. */
30
+ revision?: string;
28
31
  sizeBytes: number;
29
32
  createdAt: number;
30
33
  updatedAt: number | null;
@@ -33,6 +36,8 @@ export interface StructuredIngot<T extends object = StructuredValues> {
33
36
  id: string;
34
37
  name: string;
35
38
  version: number;
39
+ /** Identity-bound content revision from the bytes read; absent on older servers. */
40
+ revision?: string;
36
41
  keyCount: number;
37
42
  values: T;
38
43
  missingKeys: string[];
@@ -45,6 +50,8 @@ export interface StructuredIngot<T extends object = StructuredValues> {
45
50
  export interface StructuredIngotMutation {
46
51
  id: string;
47
52
  version: number;
53
+ /** The publication this operation committed; absent on older servers/creation receipts. */
54
+ revision?: string;
48
55
  keyCount: number;
49
56
  type: StructuredTypePin | null;
50
57
  createdAt?: number;
@@ -64,25 +71,29 @@ export interface CreateStructuredIngotOptions<T extends object = StructuredValue
64
71
  /** 8–128 printable ASCII characters; bound to this name and semantic payload. */
65
72
  idempotencyKey?: string;
66
73
  }
67
- export interface PatchStructuredIngotOptions<T extends object = StructuredValues> {
74
+ /** Prefer the opaque revision: it also rejects deletion and recreation under the same name. */
75
+ export type StructuredIngotPrecondition = {
76
+ expectedRevision: string;
77
+ expectedVersion?: number;
78
+ } | {
79
+ expectedRevision?: undefined;
68
80
  expectedVersion: number;
81
+ };
82
+ export type PatchStructuredIngotOptions<T extends object = StructuredValues> = StructuredIngotPrecondition & {
69
83
  set?: Partial<T>;
70
84
  delete?: string[];
71
85
  /** Omitted preserves the current type; null explicitly removes it. */
72
86
  type?: StructuredTypePin | null;
73
87
  /** Paths are relative to the `set` object. */
74
88
  binaryPaths?: StructuredBinaryPath[];
89
+ };
90
+ export type RestoreStructuredIngotOptions = StructuredIngotPrecondition;
91
+ export interface DeleteStructuredIngotOptions {
92
+ /** Delete only this object publication. Omitted preserves unconditional deletion. */
93
+ expectedRevision?: string;
75
94
  }
76
- export interface StructuredIngotVersion {
77
- versionId: string;
78
- publishedAt: number;
79
- sizeBytes: number;
80
- }
81
- export interface StructuredIngotHistory {
82
- id: string;
83
- versionLimit: number;
84
- versions: StructuredIngotVersion[];
85
- }
95
+ export type StructuredIngotVersion = IngotVersion;
96
+ export type StructuredIngotHistory = IngotHistory;
86
97
  export type StructuredActivityPeriod = '24h' | '7d';
87
98
  export interface StructuredActivityOptions {
88
99
  period?: StructuredActivityPeriod;
@@ -212,6 +223,7 @@ export interface StructuredIngotSummaryWire {
212
223
  size_bytes: number;
213
224
  created_at: number;
214
225
  updated_at?: number | null;
226
+ revision?: string | null;
215
227
  }
216
228
  export interface StructuredIngotWire<T extends object = StructuredValues> {
217
229
  ingot_id: string;
@@ -220,6 +232,7 @@ export interface StructuredIngotWire<T extends object = StructuredValues> {
220
232
  key_count: number;
221
233
  values: T;
222
234
  missing_keys: string[];
235
+ revision?: string;
223
236
  binary_paths?: StructuredBinaryPath[];
224
237
  binary_keys?: string[];
225
238
  type?: StructuredTypePinWire | null;
@@ -232,6 +245,7 @@ export interface StructuredMutationWire {
232
245
  version: number;
233
246
  key_count: number;
234
247
  type?: StructuredTypePinWire | null;
248
+ revision?: string;
235
249
  created_at?: number;
236
250
  updated_at?: number;
237
251
  created?: boolean;
@@ -1,9 +1,13 @@
1
1
  import type { UnsealedVault } from '../../vaults/types';
2
- import type { StructuredBinaryPath, StructuredPageOptions, StructuredPageWire, StructuredPage, StructuredTypePin, StructuredTypePinWire } from './types';
2
+ import type { StructuredBinaryPath, StructuredIngotPrecondition, StructuredPageOptions, StructuredPageWire, StructuredPage, StructuredTypePin, StructuredTypePinWire } from './types';
3
3
  export declare function requireVault(vault: UnsealedVault): string;
4
4
  export declare function requireRef(ref: string): string;
5
5
  export declare function integer(value: number, field: string, minimum: number, maximum: number): number;
6
6
  export declare function expectedVersion(value: number): number;
7
+ export declare function mutationPrecondition(options: StructuredIngotPrecondition): {
8
+ expected_revision?: string;
9
+ expected_version?: number;
10
+ };
7
11
  export declare function keysQuery(keys: string[] | undefined): string | undefined;
8
12
  export declare function pageQuery(options: StructuredPageOptions): {
9
13
  limit?: number;