@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.
package/dist/index.mjs CHANGED
@@ -13268,6 +13268,47 @@ function readIngotAccess(entry) {
13268
13268
  };
13269
13269
  }
13270
13270
 
13271
+ /**
13272
+ * Opaque optimistic-concurrency identity for one publication of one ingot.
13273
+ * A legacy publication has no content marker, but still names its immutable
13274
+ * ingot id: deleting and recreating a logical name never reuses its revision.
13275
+ * This is a precondition, not a credential or a content digest.
13276
+ */
13277
+
13278
+ const INGOT_REVISION_MAX_LENGTH = 4096;
13279
+ const MAX_CONTENT_VERSION_LENGTH = 256;
13280
+
13281
+ /** @returns {string} A portable, canonical revision for the actual publication. */
13282
+ function formatIngotRevision(ingotId, contentVersion) {
13283
+ if (!isResourceIdOf('ingot', ingotId) ||
13284
+ (contentVersion !== null && (typeof contentVersion !== 'string' || !contentVersion.length || contentVersion.length > MAX_CONTENT_VERSION_LENGTH))) {
13285
+ throw new TypeError('An ingot revision requires an ingot id and its content version');
13286
+ }
13287
+ try {
13288
+ return `ir1:${ingotId}:${contentVersion === null ? '' : encodeURIComponent(contentVersion)}`;
13289
+ } catch {
13290
+ throw new TypeError('An ingot revision requires a valid content version');
13291
+ }
13292
+ }
13293
+
13294
+ /** @returns {{ ingotId: string, contentVersion: string|null }} */
13295
+ function parseIngotRevision(revision) {
13296
+ if (typeof revision !== 'string' || revision.length > INGOT_REVISION_MAX_LENGTH) {
13297
+ throw new TypeError('revision must be an opaque ingot revision returned by the server');
13298
+ }
13299
+ const parts = revision.split(':');
13300
+ if (parts.length !== 3 || parts[0] !== 'ir1') {
13301
+ throw new TypeError('revision must be an opaque ingot revision returned by the server');
13302
+ }
13303
+ try {
13304
+ const contentVersion = parts[2] === '' ? null : decodeURIComponent(parts[2]);
13305
+ if (formatIngotRevision(parts[1], contentVersion) !== revision) throw new TypeError();
13306
+ return { ingotId: parts[1], contentVersion };
13307
+ } catch {
13308
+ throw new TypeError('revision must be an opaque ingot revision returned by the server');
13309
+ }
13310
+ }
13311
+
13271
13312
  /**
13272
13313
  * SparkVault Debug Logger
13273
13314
  *
@@ -13669,6 +13710,11 @@ async function attemptWith(source, state, options) {
13669
13710
  assertDownloadUrl(link, options.isAllowedHost);
13670
13711
  }
13671
13712
  catch (error) {
13713
+ // A successful HTTP response that failed local validation is an answer,
13714
+ // not a lost connection. Retrying cannot make its publication safe to use.
13715
+ if (error instanceof SparkVaultError && error.code === 'invalid_response') {
13716
+ return { ok: false, error, outcome: FINAL };
13717
+ }
13672
13718
  if (!(error instanceof SparkVaultError) || typeof error.statusCode !== 'number') {
13673
13719
  return { ok: false, error, outcome: UNANSWERED };
13674
13720
  }
@@ -13735,6 +13781,12 @@ async function attemptDownload(link, state, options) {
13735
13781
  const outcome = classifyTransferResponse({ status: response.status, headers: (name) => response.headers.get(name) });
13736
13782
  return { ok: false, error: await refusedDownloadError(response, outcome, controller), outcome };
13737
13783
  }
13784
+ // Every response contributes bytes, including a 206 continuation. Never
13785
+ // let a resumed response bypass the caller's publication precondition.
13786
+ const contentVersion = response.headers.get('x-content-version') || null;
13787
+ if (expectedContentVersion && contentVersion && contentVersion !== expectedContentVersion) {
13788
+ return { ok: false, error: new SparkVaultError(CONTENT_CHANGED_MESSAGE, 'content_changed'), outcome: FINAL };
13789
+ }
13738
13790
  if (resume && response.status === 206) {
13739
13791
  const continued = continuation(response, resume);
13740
13792
  if (continued instanceof SparkVaultError)
@@ -13743,10 +13795,6 @@ async function attemptDownload(link, state, options) {
13743
13795
  }
13744
13796
  else {
13745
13797
  received.discard();
13746
- const contentVersion = response.headers.get('x-content-version') || null;
13747
- if (expectedContentVersion && contentVersion && contentVersion !== expectedContentVersion) {
13748
- return { ok: false, error: new SparkVaultError(CONTENT_CHANGED_MESSAGE, 'content_changed'), outcome: FINAL };
13749
- }
13750
13798
  held = {
13751
13799
  contentType: response.headers.get('content-type') ?? '',
13752
13800
  contentVersion,
@@ -13853,7 +13901,9 @@ function resumeValidator(headers) {
13853
13901
  */
13854
13902
  function continuation(response, resume) {
13855
13903
  const etag = response.headers.get('etag');
13856
- if (etag !== null && etag.replace(/^W\//, '') !== resume.validator) {
13904
+ const contentVersion = response.headers.get('x-content-version');
13905
+ if ((etag !== null && etag.replace(/^W\//, '') !== resume.validator) ||
13906
+ (contentVersion && resume.held.contentVersion && contentVersion !== resume.held.contentVersion)) {
13857
13907
  return new SparkVaultError(CONTENT_CHANGED_MESSAGE, 'content_changed');
13858
13908
  }
13859
13909
  const range = CONTENT_RANGE.exec(response.headers.get('content-range') ?? '');
@@ -13989,6 +14039,51 @@ class ReceivedBytes {
13989
14039
  }
13990
14040
  }
13991
14041
 
14042
+ /** Validate an opaque server revision without interpreting it as a credential. */
14043
+ function expectedRevision(value) {
14044
+ if (value === undefined)
14045
+ return undefined;
14046
+ try {
14047
+ parseIngotRevision(value);
14048
+ return value;
14049
+ }
14050
+ catch {
14051
+ throw new ValidationError('expectedRevision must be a revision returned by an ingot read');
14052
+ }
14053
+ }
14054
+ /** Older servers omit the revision; never invent a precondition from metadata. */
14055
+ function readRevision(value) {
14056
+ if (value === undefined)
14057
+ return undefined;
14058
+ try {
14059
+ parseIngotRevision(value);
14060
+ return value;
14061
+ }
14062
+ catch {
14063
+ throw new SparkVaultError('The server returned an invalid ingot revision', 'invalid_response');
14064
+ }
14065
+ }
14066
+
14067
+ /** Core files and Structured Ingots expose the same retained publication metadata. */
14068
+ function mapIngotHistory(data) {
14069
+ return {
14070
+ id: data.ingot_id,
14071
+ versionLimit: data.version_limit,
14072
+ versions: data.versions.map(version => ({
14073
+ versionId: version.version_id,
14074
+ publishedAt: version.published_at,
14075
+ sizeBytes: version.size_bytes,
14076
+ ...(version.content_type === undefined ? {} : { contentType: version.content_type }),
14077
+ })),
14078
+ };
14079
+ }
14080
+ function requireVersionId(value) {
14081
+ if (typeof value !== 'string' || !/^[A-Za-z0-9:_-]{1,128}$/.test(value)) {
14082
+ throw new ValidationError('versionId must name a retained publication');
14083
+ }
14084
+ return value;
14085
+ }
14086
+
13992
14087
  /**
13993
14088
  * Folders Module
13994
14089
  *
@@ -15532,12 +15627,16 @@ class IngotsModule {
15532
15627
  * before the replacement is staged where there is no XMLHttpRequest.
15533
15628
  *
15534
15629
  * @example
15535
- * await sv.ingots.replace(unsealed, 'ing_abc', { file: updatedFile });
15630
+ * const original = await sv.ingots.downloadWithRevision(unsealed, 'ing_abc');
15631
+ * await sv.ingots.replace(unsealed, 'ing_abc', {
15632
+ * file: updatedFile, expectedRevision: original.revision,
15633
+ * });
15536
15634
  */
15537
15635
  async replace(vault, ingotId, options) {
15538
15636
  this.validateFile(options.file);
15539
15637
  const vaultId = requireVaultId(vault);
15540
15638
  const id = requireResourceId(ingotId, 'ingotId');
15639
+ const revision = expectedRevision(options.expectedRevision);
15541
15640
  const name = options.name ?? getBlobName(options.file);
15542
15641
  const contentType = sentContentType(options);
15543
15642
  assertBrowserTransfer();
@@ -15547,6 +15646,7 @@ class IngotsModule {
15547
15646
  ...(contentType !== undefined && { content_type: contentType }),
15548
15647
  size_bytes: options.file.size,
15549
15648
  ...(options.contentHmac && { content_hmac: options.contentHmac }),
15649
+ ...(revision === undefined ? {} : { expected_revision: revision }),
15550
15650
  }, { vat: vault.vatToken }).catch((error) => {
15551
15651
  throw stagingRefusalOf(error);
15552
15652
  });
@@ -15588,12 +15688,16 @@ class IngotsModule {
15588
15688
  * Delete an ingot.
15589
15689
  *
15590
15690
  * @example
15591
- * await sv.ingots.delete(unsealed, 'ing_abc');
15691
+ * const original = await sv.ingots.get(unsealed, 'ing_abc');
15692
+ * if (!original.revision) throw new Error('This server does not support guarded deletion');
15693
+ * await sv.ingots.delete(unsealed, original.id, { expectedRevision: original.revision });
15592
15694
  */
15593
- async delete(vault, ingotId) {
15695
+ async delete(vault, ingotId, options = {}) {
15594
15696
  const vaultId = requireVaultId(vault);
15595
15697
  const id = requireResourceId(ingotId, 'ingotId');
15596
- await this.http.delete(apiPath `/v1/vaults/${vaultId}/ingots/${id}`, { vat: vault.vatToken });
15698
+ await this.http.delete(apiPath `/v1/vaults/${vaultId}/ingots/${id}`, {
15699
+ vat: vault.vatToken, query: { expected_revision: expectedRevision(options.expectedRevision) },
15700
+ });
15597
15701
  }
15598
15702
  /**
15599
15703
  * Get ingot metadata.
@@ -15686,6 +15790,49 @@ class IngotsModule {
15686
15790
  });
15687
15791
  return mapFolderContents(response.data);
15688
15792
  }
15793
+ /** List previous publications of a file, newest first. Structured objects use their product's history method. */
15794
+ async listVersions(vault, ingotId) {
15795
+ const vaultId = requireVaultId(vault);
15796
+ const id = requireResourceId(ingotId, 'ingotId');
15797
+ const { data } = await this.http.get(apiPath `/v1/vaults/${vaultId}/ingots/${id}/versions`, { vat: vault.vatToken });
15798
+ return mapIngotHistory(data);
15799
+ }
15800
+ /** Mint a one-use link to a retained file publication; use downloadVersion to verify the served bytes. */
15801
+ async createVersionDownloadLink(vault, ingotId, versionId) {
15802
+ const vaultId = requireVaultId(vault);
15803
+ const id = requireResourceId(ingotId, 'ingotId');
15804
+ const version = requireVersionId(versionId);
15805
+ const { data } = await this.http.post(apiPath `/v1/vaults/${vaultId}/ingots/${id}/versions/${version}/download`, undefined, { vat: vault.vatToken });
15806
+ if (data.ingot_id !== id || data.content_version !== version) {
15807
+ throw new SparkVaultError('The server returned a different retained publication', 'invalid_response');
15808
+ }
15809
+ assertDownloadUrl(data.download_url, this.allowsTransferHost);
15810
+ return {
15811
+ id: data.ingot_id,
15812
+ downloadUrl: data.download_url,
15813
+ size: data.size_bytes,
15814
+ contentVersion: data.content_version,
15815
+ expiresAt: data.expires_at,
15816
+ ...(data.revision === undefined ? {} : { revision: readRevision(data.revision) }),
15817
+ ...(data.name === undefined ? {} : { name: data.name }),
15818
+ ...(data.content_type === undefined ? {} : { contentType: data.content_type }),
15819
+ };
15820
+ }
15821
+ /** Download a retained file publication; never substitutes the current bytes if history is unavailable. */
15822
+ async downloadVersion(vault, ingotId, versionId) {
15823
+ requireVaultId(vault);
15824
+ requireResourceId(ingotId, 'ingotId');
15825
+ const version = requireVersionId(versionId);
15826
+ const mint = async () => (await this.createVersionDownloadLink(vault, ingotId, version)).downloadUrl;
15827
+ const download = await fetchMintedDownload(mint, {
15828
+ isAllowedHost: this.allowsTransferHost, expectedContentVersion: version,
15829
+ });
15830
+ // Older transfer servers can omit the header; metadata from the mint is not proof of the bytes served.
15831
+ if (download.contentVersion !== version) {
15832
+ throw new SparkVaultError('The download did not identify the requested retained publication', 'invalid_response');
15833
+ }
15834
+ return download.blob;
15835
+ }
15689
15836
  /**
15690
15837
  * Create a signed download link for an ingot (discrete primitive).
15691
15838
  *
@@ -15713,6 +15860,7 @@ class IngotsModule {
15713
15860
  return {
15714
15861
  downloadUrl: response.data.download_url,
15715
15862
  contentVersion: response.data.content_version ?? null,
15863
+ ...(response.data.revision === undefined ? {} : { revision: readRevision(response.data.revision) }),
15716
15864
  id: response.data.ingot_id,
15717
15865
  name: response.data.name,
15718
15866
  size: response.data.size_bytes,
@@ -15746,8 +15894,19 @@ class IngotsModule {
15746
15894
  * link.click();
15747
15895
  */
15748
15896
  async download(vault, ingotId, options = {}) {
15897
+ return (await this.downloadWithRevision(vault, ingotId, options)).blob;
15898
+ }
15899
+ /**
15900
+ * Download bytes with their identity-bound revision. Use the returned revision
15901
+ * for replace/delete preconditions; the link's earlier metadata may already
15902
+ * have been superseded when Forge begins serving the bytes.
15903
+ */
15904
+ async downloadWithRevision(vault, ingotId, options = {}) {
15905
+ requireVaultId(vault);
15906
+ const id = requireResourceId(ingotId, 'ingotId');
15749
15907
  const mint = async () => (await this.createDownloadLink(vault, ingotId, options)).downloadUrl;
15750
- return (await fetchMintedDownload(mint, { isAllowedHost: this.allowsTransferHost })).blob;
15908
+ const download = await fetchMintedDownload(mint, { isAllowedHost: this.allowsTransferHost });
15909
+ return { blob: download.blob, revision: formatIngotRevision(id, download.contentVersion) };
15751
15910
  }
15752
15911
  /**
15753
15912
  * Get an ingot's sharing configuration.
@@ -15943,6 +16102,7 @@ function mapIngot(wire) {
15943
16102
  folderId: wire.folder_id ?? null,
15944
16103
  contentHmac: wire.content_hmac ?? null,
15945
16104
  contentVersion: wire.content_version ?? null,
16105
+ ...(wire.revision === undefined ? {} : { revision: readRevision(wire.revision) }),
15946
16106
  };
15947
16107
  }
15948
16108
  function mapFolderContents(wire) {
@@ -21389,6 +21549,16 @@ function integer(value, field, minimum, maximum) {
21389
21549
  return value;
21390
21550
  }
21391
21551
  function expectedVersion(value) { return integer(value, 'expectedVersion', 1, 0xFFFFFFFF); }
21552
+ function mutationPrecondition(options) {
21553
+ const revision = expectedRevision(options.expectedRevision);
21554
+ const version = options.expectedVersion;
21555
+ if (version !== undefined)
21556
+ expectedVersion(version);
21557
+ if (revision === undefined && version === undefined) {
21558
+ throw new ValidationError('expectedRevision or expectedVersion is required');
21559
+ }
21560
+ return { expected_revision: revision, expected_version: version };
21561
+ }
21392
21562
  function keysQuery(keys) {
21393
21563
  if (keys === undefined)
21394
21564
  return undefined;
@@ -21520,6 +21690,7 @@ class StructuredIngotTypesModule {
21520
21690
 
21521
21691
  function mutation(wire) {
21522
21692
  return { id: wire.ingot_id, version: wire.version, keyCount: wire.key_count, type: readPin(wire.type),
21693
+ ...(wire.revision === undefined ? {} : { revision: readRevision(wire.revision) }),
21523
21694
  ...(wire.created_at === undefined ? {} : { createdAt: wire.created_at }),
21524
21695
  ...(wire.updated_at === undefined ? {} : { updatedAt: wire.updated_at }),
21525
21696
  ...(wire.created === undefined ? {} : { created: wire.created }),
@@ -21564,6 +21735,7 @@ class StructuredIngotsModule {
21564
21735
  if (data.inline !== true)
21565
21736
  throw new SparkVaultError('This server did not return a typed record response', 'invalid_response');
21566
21737
  return { id: data.ingot_id, name: data.name, version: data.version, keyCount: data.key_count,
21738
+ ...(data.revision === undefined ? {} : { revision: readRevision(data.revision) }),
21567
21739
  values: data.values, missingKeys: data.missing_keys, type: readPin(data.type),
21568
21740
  binaryPaths: data.binary_paths ?? data.binary_keys?.map((key) => [key]) ?? [],
21569
21741
  createdAt: data.created_at, updatedAt: data.updated_at };
@@ -21572,6 +21744,7 @@ class StructuredIngotsModule {
21572
21744
  const id = requireVault(vault);
21573
21745
  const { data } = await this.http.get(apiPath `/v1/products/structured-ingots/${id}`, { vat: vault.vatToken, query: pageQuery(options) });
21574
21746
  return page(data, data.ingots.map((record) => ({ id: record.ingot_id, name: record.name, sizeBytes: record.size_bytes,
21747
+ ...(record.revision == null ? {} : { revision: readRevision(record.revision) }),
21575
21748
  createdAt: record.created_at, updatedAt: record.updated_at ?? null })));
21576
21749
  }
21577
21750
  iterate(vault, options = {}) {
@@ -21588,36 +21761,35 @@ class StructuredIngotsModule {
21588
21761
  async patch(vault, ref, options) {
21589
21762
  const id = requireVault(vault);
21590
21763
  const record = requireRef(ref);
21591
- expectedVersion(options.expectedVersion);
21764
+ const precondition = mutationPrecondition(options);
21592
21765
  if (options.set !== undefined)
21593
21766
  validateValues(options.set);
21594
21767
  if (options.delete !== undefined && (!Array.isArray(options.delete) || options.delete.some((key) => typeof key !== 'string' || !key.length))) {
21595
21768
  throw new ValidationError('delete must contain non-empty field names');
21596
21769
  }
21597
21770
  validateBinaryPaths(options.binaryPaths);
21598
- const { data } = await this.http.patch(apiPath `/v1/products/structured-ingots/${id}/${record}`, { expected_version: options.expectedVersion, set: options.set, delete: options.delete, type: wirePin(options.type), binary_paths: options.binaryPaths }, { vat: vault.vatToken });
21771
+ const { data } = await this.http.patch(apiPath `/v1/products/structured-ingots/${id}/${record}`, { ...precondition, set: options.set, delete: options.delete, type: wirePin(options.type), binary_paths: options.binaryPaths }, { vat: vault.vatToken });
21599
21772
  return mutation(data);
21600
21773
  }
21601
- async delete(vault, ref) {
21774
+ async delete(vault, ref, options = {}) {
21602
21775
  const id = requireVault(vault);
21603
21776
  const record = requireRef(ref);
21604
- await this.http.delete(apiPath `/v1/products/structured-ingots/${id}/${record}`, { vat: vault.vatToken });
21777
+ await this.http.delete(apiPath `/v1/products/structured-ingots/${id}/${record}`, {
21778
+ vat: vault.vatToken, query: { expected_revision: expectedRevision(options.expectedRevision) },
21779
+ });
21605
21780
  }
21606
21781
  async history(vault, ref) {
21607
21782
  const id = requireVault(vault);
21608
21783
  const record = requireRef(ref);
21609
21784
  const { data } = await this.http.get(apiPath `/v1/products/structured-ingots/${id}/${record}/versions`, { vat: vault.vatToken });
21610
- return { id: data.ingot_id, versionLimit: data.version_limit, versions: data.versions.map((version) => ({
21611
- versionId: version.version_id, publishedAt: version.published_at, sizeBytes: version.size_bytes,
21612
- })) };
21785
+ return mapIngotHistory(data);
21613
21786
  }
21614
21787
  async restore(vault, ref, versionId, options) {
21615
21788
  const id = requireVault(vault);
21616
21789
  const record = requireRef(ref);
21617
- expectedVersion(options.expectedVersion);
21618
- if (typeof versionId !== 'string' || !/^[A-Za-z0-9:_-]{1,128}$/.test(versionId))
21619
- throw new ValidationError('versionId must name a retained publication');
21620
- const { data } = await this.http.post(apiPath `/v1/products/structured-ingots/${id}/${record}/versions/${versionId}/restore`, { expected_version: options.expectedVersion }, { vat: vault.vatToken });
21790
+ const precondition = mutationPrecondition(options);
21791
+ requireVersionId(versionId);
21792
+ const { data } = await this.http.post(apiPath `/v1/products/structured-ingots/${id}/${record}/versions/${versionId}/restore`, precondition, { vat: vault.vatToken });
21621
21793
  return mutation(data);
21622
21794
  }
21623
21795
  /** Bounded parallel reads with independent, ordered success/error outcomes. */
@@ -21785,8 +21957,70 @@ function unsealRequestBody(key, ttlSeconds) {
21785
21957
  return ttlSeconds === undefined ? { [field]: trimmed } : { [field]: trimmed, ttl_seconds: ttlSeconds };
21786
21958
  }
21787
21959
 
21788
- /** Maximum previous publications retained for each structured object. */
21789
- const MAX_STRUCTURED_INGOT_VERSIONS = 50;
21960
+ /**
21961
+ * The apps that manage ingots, each by the id its ingots carry as `managed_by`:
21962
+ * the one statement of those ids, of the name each app goes by, of whether an
21963
+ * app manages a row (isManagedIngot), and of whose rows Core seals server-side
21964
+ * (isServerSealedIngot). Each app marks every ingot it creates
21965
+ * with its own (Structured Ingots also calls Core as it, since Core lets only
21966
+ * the internal invoker an ingot's `managed_by` names create or touch one);
21967
+ * Core, the console, the mobile app and the Slack app ask isManagedIngot of a
21968
+ * row, and the mobile app names the app on the row's sheet. An app's ingot is
21969
+ * the app's: Core's file routes act on it only for the app, the vault shares
21970
+ * it with no one, the app included, and no request files it in a folder
21971
+ * (docs/APPS.md → Managed Ingots).
21972
+ *
21973
+ * A value is stored on every ingot its app creates and never changes on the
21974
+ * row (`managed_by` is immutable), so an id here is never renamed: a new
21975
+ * value would leave every existing ingot naming one no app answers to.
21976
+ *
21977
+ * BROWSER-SAFE: data and pure functions, no imports.
21978
+ */
21979
+
21980
+ const MANAGED_BY = Object.freeze({
21981
+ /** A Structured Ingots record, Identity's directory profiles among them. */
21982
+ STRUCTURED_INGOTS: 'structured-ingots',
21983
+ /** An encrypted catalog of a Structured Ingots type's immutable definitions. */
21984
+ STRUCTURED_INGOT_TYPES: 'structured-ingot-types',
21985
+ /** A help desk message body, email original, attachment or requester export part. */
21986
+ HELP_DESK: 'product-help-desk',
21987
+ /** A Messaging message, compacted page or attachment. */
21988
+ MESSAGING: 'product-messaging'
21989
+ });
21990
+
21991
+ /** Each app's name, as UI copy names the product (docs/DESIGN.md → Voice & copy). */
21992
+ new Map([
21993
+ [MANAGED_BY.STRUCTURED_INGOTS, 'Structured Ingots'],
21994
+ [MANAGED_BY.STRUCTURED_INGOT_TYPES, 'Structured Ingots'],
21995
+ [MANAGED_BY.HELP_DESK, 'Secure Help Desk'],
21996
+ [MANAGED_BY.MESSAGING, 'Messaging']
21997
+ ]);
21998
+
21999
+ /**
22000
+ * The apps inside Core whose ingots Core writes server-side, sealing content
22001
+ * it is handed in one call (apps/api UnifiedIngotService.sealIngotContent):
22002
+ * each such ingot lies at the vault root, at an id its app derives from its
22003
+ * own keys, and holds no name claim. Every other ingot, a Structured Ingots
22004
+ * record's included, is created through Core's upload path and holds its name
22005
+ * by a claim.
22006
+ */
22007
+ new Set([MANAGED_BY.HELP_DESK, MANAGED_BY.MESSAGING]);
22008
+
22009
+ /** Maximum previous publications retained for each user file or object. */
22010
+ const MAX_INGOT_VERSIONS = 50;
22011
+
22012
+ /** Existing vaults retain only current content until retention is enabled. */
22013
+ function ingotVersionLimit(vault) {
22014
+ const limit = vault?.ingot_version_limit === undefined
22015
+ ? (vault?.structured_ingot_version_limit === undefined ? 0 : vault.structured_ingot_version_limit)
22016
+ : vault.ingot_version_limit;
22017
+ // Malformed stored settings must never silently disable retention and purge
22018
+ // history. Every writer uses the same bounded integer contract.
22019
+ if (!Number.isSafeInteger(limit) || limit < 0 || limit > MAX_INGOT_VERSIONS) {
22020
+ throw new RangeError('Invalid ingot version limit');
22021
+ }
22022
+ return limit;
22023
+ }
21790
22024
 
21791
22025
  /**
21792
22026
  * Upload Widget Chrome
@@ -24532,7 +24766,7 @@ class VaultsModule {
24532
24766
  createdAt: v.created_at,
24533
24767
  ingotCount: v.ingot_count,
24534
24768
  storageBytes: v.storage_bytes,
24535
- ...(v.structured_ingot_version_limit === undefined ? {} : { structuredIngotVersionLimit: v.structured_ingot_version_limit }),
24769
+ ...mapVersionHistory(v),
24536
24770
  ...(v.structured_ingots_enabled === undefined ? {} : { structuredIngotsEnabled: v.structured_ingots_enabled }),
24537
24771
  ...mapLifecycle(v),
24538
24772
  })),
@@ -24571,19 +24805,23 @@ class VaultsModule {
24571
24805
  };
24572
24806
  }
24573
24807
  /**
24574
- * Retain this many previous versions of each structured object (0–50).
24575
- * Interactive company administrators only. Applies on each object's next
24576
- * successful change; retained versions count toward storage usage.
24808
+ * Retain this many previous versions of each file or structured object (0–50,
24809
+ * default 0). Interactive company administrators only. Applies on each ingot's
24810
+ * next successful content change; retained versions count toward storage usage.
24577
24811
  */
24578
- async updateStructuredIngotSettings(vaultId, settings) {
24812
+ async updateVersionHistory(vaultId, settings) {
24579
24813
  const id = requireResourceId(vaultId, 'vaultId');
24580
24814
  const limit = settings?.versionLimit;
24581
- if (!Number.isSafeInteger(limit) || limit < 0 || limit > MAX_STRUCTURED_INGOT_VERSIONS) {
24582
- throw new ValidationError(`versionLimit must be a whole number from 0 to ${MAX_STRUCTURED_INGOT_VERSIONS}`);
24815
+ if (!Number.isSafeInteger(limit) || limit < 0 || limit > MAX_INGOT_VERSIONS) {
24816
+ throw new ValidationError(`versionLimit must be a whole number from 0 to ${MAX_INGOT_VERSIONS}`);
24583
24817
  }
24584
- const response = await this.http.put(apiPath `/v1/vaults/${id}/structured-ingot-settings`, { version_limit: limit });
24818
+ const response = await this.http.put(apiPath `/v1/vaults/${id}/version-history`, { version_limit: limit });
24585
24819
  return { vaultId: response.data.vault_id, versionLimit: response.data.version_limit };
24586
24820
  }
24821
+ /** @deprecated Use updateVersionHistory; retention applies to files and structured objects. */
24822
+ async updateStructuredIngotSettings(vaultId, settings) {
24823
+ return this.updateVersionHistory(vaultId, settings);
24824
+ }
24587
24825
  /**
24588
24826
  * Rename a vault.
24589
24827
  *
@@ -24847,6 +25085,12 @@ function mapLifecycle(v) {
24847
25085
  deletionScheduleId: v.deletion_schedule_id,
24848
25086
  };
24849
25087
  }
25088
+ function mapVersionHistory(v) {
25089
+ if (v.ingot_version_limit === undefined && v.structured_ingot_version_limit === undefined)
25090
+ return {};
25091
+ const limit = ingotVersionLimit(v);
25092
+ return { ingotVersionLimit: limit, structuredIngotVersionLimit: limit };
25093
+ }
24850
25094
  function mapVaultDetail(v) {
24851
25095
  return {
24852
25096
  id: v.vault_id,
@@ -24855,7 +25099,7 @@ function mapVaultDetail(v) {
24855
25099
  ...mapLifecycle(v),
24856
25100
  ingotCount: v.ingot_count ?? 0,
24857
25101
  storageBytes: v.storage_bytes ?? 0,
24858
- ...(v.structured_ingot_version_limit === undefined ? {} : { structuredIngotVersionLimit: v.structured_ingot_version_limit }),
25102
+ ...mapVersionHistory(v),
24859
25103
  ...(v.structured_ingots_enabled === undefined ? {} : { structuredIngotsEnabled: v.structured_ingots_enabled }),
24860
25104
  createdAt: v.created_at,
24861
25105
  lastUnsealedAt: v.last_unsealed_at ?? null,
@@ -25649,7 +25893,7 @@ class SparkVault {
25649
25893
  }
25650
25894
  /** Get the SDK version */
25651
25895
  static get version() {
25652
- return '15.9.0';
25896
+ return '15.10.0';
25653
25897
  }
25654
25898
  }
25655
25899
  if (typeof window !== 'undefined') {