@sparkvault/sdk-js 15.9.1 → 15.11.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
@@ -13710,6 +13710,11 @@ async function attemptWith(source, state, options) {
13710
13710
  assertDownloadUrl(link, options.isAllowedHost);
13711
13711
  }
13712
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
+ }
13713
13718
  if (!(error instanceof SparkVaultError) || typeof error.statusCode !== 'number') {
13714
13719
  return { ok: false, error, outcome: UNANSWERED };
13715
13720
  }
@@ -13776,6 +13781,12 @@ async function attemptDownload(link, state, options) {
13776
13781
  const outcome = classifyTransferResponse({ status: response.status, headers: (name) => response.headers.get(name) });
13777
13782
  return { ok: false, error: await refusedDownloadError(response, outcome, controller), outcome };
13778
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
+ }
13779
13790
  if (resume && response.status === 206) {
13780
13791
  const continued = continuation(response, resume);
13781
13792
  if (continued instanceof SparkVaultError)
@@ -13784,10 +13795,6 @@ async function attemptDownload(link, state, options) {
13784
13795
  }
13785
13796
  else {
13786
13797
  received.discard();
13787
- const contentVersion = response.headers.get('x-content-version') || null;
13788
- if (expectedContentVersion && contentVersion && contentVersion !== expectedContentVersion) {
13789
- return { ok: false, error: new SparkVaultError(CONTENT_CHANGED_MESSAGE, 'content_changed'), outcome: FINAL };
13790
- }
13791
13798
  held = {
13792
13799
  contentType: response.headers.get('content-type') ?? '',
13793
13800
  contentVersion,
@@ -13894,7 +13901,9 @@ function resumeValidator(headers) {
13894
13901
  */
13895
13902
  function continuation(response, resume) {
13896
13903
  const etag = response.headers.get('etag');
13897
- 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)) {
13898
13907
  return new SparkVaultError(CONTENT_CHANGED_MESSAGE, 'content_changed');
13899
13908
  }
13900
13909
  const range = CONTENT_RANGE.exec(response.headers.get('content-range') ?? '');
@@ -14055,6 +14064,26 @@ function readRevision(value) {
14055
14064
  }
14056
14065
  }
14057
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
+
14058
14087
  /**
14059
14088
  * Folders Module
14060
14089
  *
@@ -15761,6 +15790,49 @@ class IngotsModule {
15761
15790
  });
15762
15791
  return mapFolderContents(response.data);
15763
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
+ }
15764
15836
  /**
15765
15837
  * Create a signed download link for an ingot (discrete primitive).
15766
15838
  *
@@ -21471,12 +21543,12 @@ function requireRef(ref) {
21471
21543
  return ref;
21472
21544
  throw new ValidationError('ref must be an ingot ID or a :name reference');
21473
21545
  }
21474
- function integer(value, field, minimum, maximum) {
21546
+ function integer$1(value, field, minimum, maximum) {
21475
21547
  if (!Number.isSafeInteger(value) || value < minimum || value > maximum)
21476
21548
  throw new ValidationError(`${field} must be a whole number from ${minimum} to ${maximum}`);
21477
21549
  return value;
21478
21550
  }
21479
- function expectedVersion(value) { return integer(value, 'expectedVersion', 1, 0xFFFFFFFF); }
21551
+ function expectedVersion(value) { return integer$1(value, 'expectedVersion', 1, 0xFFFFFFFF); }
21480
21552
  function mutationPrecondition(options) {
21481
21553
  const revision = expectedRevision(options.expectedRevision);
21482
21554
  const version = options.expectedVersion;
@@ -21497,7 +21569,7 @@ function keysQuery(keys) {
21497
21569
  }
21498
21570
  function pageQuery(options) {
21499
21571
  if (options.limit !== undefined)
21500
- integer(options.limit, 'limit', 1, 200);
21572
+ integer$1(options.limit, 'limit', 1, 200);
21501
21573
  if (options.cursor !== undefined && (typeof options.cursor !== 'string' || !options.cursor.length || options.cursor.length > 8192)) {
21502
21574
  throw new ValidationError('cursor must be a non-empty continuation token');
21503
21575
  }
@@ -21550,7 +21622,7 @@ function idempotencyHeaders(key) {
21550
21622
  }
21551
21623
  /** Empty pages are legitimate; a repeated cursor is never drained forever. */
21552
21624
  async function* iteratePages(read, options = {}) {
21553
- const maxPages = integer(options.maxPages ?? 10000, 'maxPages', 1, 100000);
21625
+ const maxPages = integer$1(options.maxPages ?? 10000, 'maxPages', 1, 100000);
21554
21626
  pageQuery(options);
21555
21627
  const seen = new Set();
21556
21628
  let cursor = options.cursor;
@@ -21603,7 +21675,7 @@ class StructuredIngotTypesModule {
21603
21675
  async publish(vault, typeId, options) {
21604
21676
  const id = requireVault(vault);
21605
21677
  const type = wirePin({ typeId, version: options.expectedVersion }).type_id;
21606
- integer(options.expectedVersion, 'expectedVersion', 1, STRUCTURED_TYPE_LIMITS.maxVersions);
21678
+ integer$1(options.expectedVersion, 'expectedVersion', 1, STRUCTURED_TYPE_LIMITS.maxVersions);
21607
21679
  validateValues(options.schema);
21608
21680
  const { data } = await this.http.post(apiPath `/v1/products/structured-ingots/${id}/types/${type}/versions`, { expected_version: options.expectedVersion, schema: options.schema, transforms: options.transforms ?? [] }, { vat: vault.vatToken });
21609
21681
  return definition(data);
@@ -21710,16 +21782,13 @@ class StructuredIngotsModule {
21710
21782
  const id = requireVault(vault);
21711
21783
  const record = requireRef(ref);
21712
21784
  const { data } = await this.http.get(apiPath `/v1/products/structured-ingots/${id}/${record}/versions`, { vat: vault.vatToken });
21713
- return { id: data.ingot_id, versionLimit: data.version_limit, versions: data.versions.map((version) => ({
21714
- versionId: version.version_id, publishedAt: version.published_at, sizeBytes: version.size_bytes,
21715
- })) };
21785
+ return mapIngotHistory(data);
21716
21786
  }
21717
21787
  async restore(vault, ref, versionId, options) {
21718
21788
  const id = requireVault(vault);
21719
21789
  const record = requireRef(ref);
21720
21790
  const precondition = mutationPrecondition(options);
21721
- if (typeof versionId !== 'string' || !/^[A-Za-z0-9:_-]{1,128}$/.test(versionId))
21722
- throw new ValidationError('versionId must name a retained publication');
21791
+ requireVersionId(versionId);
21723
21792
  const { data } = await this.http.post(apiPath `/v1/products/structured-ingots/${id}/${record}/versions/${versionId}/restore`, precondition, { vat: vault.vatToken });
21724
21793
  return mutation(data);
21725
21794
  }
@@ -21730,7 +21799,7 @@ class StructuredIngotsModule {
21730
21799
  throw new ValidationError('batchGet accepts at most 100 references');
21731
21800
  refs.forEach(requireRef);
21732
21801
  keysQuery(options.keys);
21733
- const concurrency = integer(options.concurrency ?? 4, 'concurrency', 1, 8);
21802
+ const concurrency = integer$1(options.concurrency ?? 4, 'concurrency', 1, 8);
21734
21803
  // Keep the validated work bounded even if the caller reuses its arrays.
21735
21804
  const input = refs.slice();
21736
21805
  const keys = options.keys?.slice();
@@ -21822,12 +21891,156 @@ class StructuredIngotsModule {
21822
21891
  }
21823
21892
  }
21824
21893
 
21894
+ function integer(value, field, minimum = 1) {
21895
+ if (!Number.isSafeInteger(value) || value < minimum) {
21896
+ throw new ValidationError(`${field} must be a ${minimum === 0 ? 'non-negative' : 'positive'} safe integer`, { field });
21897
+ }
21898
+ }
21899
+ function participant(wire) {
21900
+ return { svid: wire.svid, role: wire.role, addedAt: wire.added_at,
21901
+ ...(wire.identity === undefined ? {} : { identity: wire.identity }),
21902
+ ...(wire.opted_out === undefined ? {} : { optedOut: wire.opted_out }) };
21903
+ }
21904
+ function message(wire) {
21905
+ if (wire.recalled)
21906
+ return { messageId: wire.message_id, recalled: true };
21907
+ if (wire.unavailable)
21908
+ return { messageId: wire.message_id, unavailable: true };
21909
+ return { messageId: wire.message_id, schemaVersion: wire.schema_version, senderSvid: wire.sender_svid,
21910
+ senderIdentity: wire.sender_identity, ts: wire.ts, contentType: wire.content_type, content: wire.content,
21911
+ attachments: (wire.attachments ?? []).map((item) => ({ ingotId: item.ingot_id, name: item.name })) };
21912
+ }
21913
+ function receipt(wire) {
21914
+ return { accountId: wire.account_id, conversationId: wire.conversation_id, messageId: wire.message_id,
21915
+ senderSvid: wire.sender_svid, contentHash: wire.content_hash };
21916
+ }
21917
+ /** Stateless, authenticated business API for the pre-launch Messaging product. */
21918
+ class MessagingModule {
21919
+ constructor(http) {
21920
+ this.http = http;
21921
+ }
21922
+ /** Follow cursor even when a page contains fewer than limit conversations. */
21923
+ async getInbox(options = {}) {
21924
+ if (options.limit !== undefined)
21925
+ integer(options.limit, 'limit');
21926
+ // Core decodes the query's cursor once more before JSON.parse. Encode the
21927
+ // serialized key here; the shared transport applies the outer query encoding.
21928
+ const { data } = await this.http.get(apiPath `/v1/products/messaging/inbox`, {
21929
+ query: { limit: options.limit, cursor: options.cursor === undefined ? undefined : encodeURIComponent(JSON.stringify(options.cursor)) },
21930
+ });
21931
+ return { conversations: data.items.map((item) => ({ conversationId: item.conversation_id, accountId: item.account_id,
21932
+ lastActivityTs: item.last_activity_ts, lastMessageId: item.last_message_id, unreadCount: item.unread_count ?? 0,
21933
+ archived: item.archived === true, ...(item.last_read_id === undefined ? {} : { lastReadId: item.last_read_id }),
21934
+ ...(item.other_participants === undefined ? {} : { otherParticipants: item.other_participants }) })),
21935
+ ...(data.cursor == null ? {} : { cursor: data.cursor }) };
21936
+ }
21937
+ /** Create with business members; invite account-less recipients separately. */
21938
+ async createConversation(options = {}) {
21939
+ const { data } = await this.http.post(apiPath `/v1/products/messaging/conversations`, {
21940
+ participants: options.participants,
21941
+ settings: options.settings === undefined ? undefined : { audit_retention_seconds: options.settings.auditRetentionSeconds },
21942
+ });
21943
+ return { conversationId: data.conversation_id, vaultId: data.vault_id,
21944
+ participants: data.participants.map(participant), createdAt: data.created_at };
21945
+ }
21946
+ async getConversation(conversationId) {
21947
+ const { data } = await this.http.get(apiPath `/v1/products/messaging/conversations/${conversationId}`);
21948
+ return { conversationId: data.conversation_id, participants: data.participants.map(participant),
21949
+ committedThrough: data.committed_through, compactedThrough: data.compacted_through, createdAt: data.created_at,
21950
+ settings: data.settings.audit_retention_seconds === undefined ? {} : { auditRetentionSeconds: data.settings.audit_retention_seconds } };
21951
+ }
21952
+ /** Sends are never retried automatically: Core allocates a new id per send. */
21953
+ async send(conversationId, options) {
21954
+ if (typeof options?.content !== 'string' || !options.content.length)
21955
+ throw new ValidationError('content must be a non-empty string');
21956
+ const { data } = await this.http.post(apiPath `/v1/products/messaging/conversations/${conversationId}/messages`, {
21957
+ content: options.content, content_type: options.contentType,
21958
+ attachments: options.attachments?.map((item) => ({ ingot_id: item.ingotId, name: item.name })),
21959
+ });
21960
+ return { messageId: data.message_id, conversationId: data.conversation_id, ts: data.ts, ingotId: data.ingot_id,
21961
+ contentHash: data.content_hash, committedThrough: data.committed_through, status: data.status,
21962
+ receipt: { ...receipt(data.receipt), ts: data.receipt.ts } };
21963
+ }
21964
+ /** Fresh read each time, including recalls and newly resolved gaps at old ids. */
21965
+ async read(conversationId, options = {}) {
21966
+ if ((options.fromId === undefined) !== (options.toId === undefined))
21967
+ throw new ValidationError('fromId and toId must be supplied together');
21968
+ if (options.fromId !== undefined)
21969
+ integer(options.fromId, 'fromId');
21970
+ if (options.toId !== undefined)
21971
+ integer(options.toId, 'toId');
21972
+ if (options.fromId !== undefined && options.toId < options.fromId)
21973
+ throw new ValidationError('toId must be at least fromId');
21974
+ if (options.limit !== undefined)
21975
+ integer(options.limit, 'limit');
21976
+ const { data } = await this.http.get(apiPath `/v1/products/messaging/conversations/${conversationId}/messages`, {
21977
+ query: { from_id: options.fromId, to_id: options.toId, limit: options.limit },
21978
+ });
21979
+ return { messages: data.messages.map(message), committedThrough: data.committed_through, compactedThrough: data.compacted_through };
21980
+ }
21981
+ async markRead(conversationId, lastReadId) {
21982
+ integer(lastReadId, 'lastReadId', 0);
21983
+ await this.http.post(apiPath `/v1/products/messaging/conversations/${conversationId}/read`, { last_read_id: lastReadId });
21984
+ }
21985
+ async archive(conversationId, archived = true) {
21986
+ await this.http.put(apiPath `/v1/products/messaging/conversations/${conversationId}/archive`, { archived });
21987
+ }
21988
+ async invite(conversationId, identity) {
21989
+ if (!identity || !['email', 'phone'].includes(identity.type) || typeof identity.value !== 'string' || !identity.value.trim()) {
21990
+ throw new ValidationError('type (email|phone) and a non-empty value are required');
21991
+ }
21992
+ const { data } = await this.http.post(apiPath `/v1/products/messaging/conversations/${conversationId}/invites`, identity);
21993
+ return { svid: data.svid, accessUrl: data.access_url };
21994
+ }
21995
+ async addParticipant(conversationId, input) {
21996
+ const { data } = await this.http.post(apiPath `/v1/products/messaging/conversations/${conversationId}/participants`, input);
21997
+ return data.participants.map(participant);
21998
+ }
21999
+ async removeParticipant(conversationId, svid) {
22000
+ const { data } = await this.http.delete(apiPath `/v1/products/messaging/conversations/${conversationId}/participants/${svid}`);
22001
+ return data.participants.map(participant);
22002
+ }
22003
+ async recall(conversationId, messageId) {
22004
+ integer(messageId, 'messageId');
22005
+ await this.http.post(apiPath `/v1/products/messaging/conversations/${conversationId}/messages/${String(messageId)}/recall`);
22006
+ }
22007
+ async getReceipt(conversationId, messageId) {
22008
+ integer(messageId, 'messageId');
22009
+ const { data } = await this.http.get(apiPath `/v1/products/messaging/conversations/${conversationId}/messages/${String(messageId)}/receipt`);
22010
+ return { receiptToken: data.receipt_token, expiresAt: data.expires_at,
22011
+ receipt: { ...receipt(data.receipt), messageTs: data.receipt.message_ts } };
22012
+ }
22013
+ /** Owner-only; a closed conversation refuses new sends. */
22014
+ async close(conversationId, closed = true) {
22015
+ await this.http.put(apiPath `/v1/products/messaging/conversations/${conversationId}/close`, { closed });
22016
+ }
22017
+ /** Stores the caller's preference; Core currently does not gate sends on it. */
22018
+ async setOptOut(conversationId, optedOut) {
22019
+ await this.http.put(apiPath `/v1/products/messaging/conversations/${conversationId}/opt-out`, { opted_out: optedOut });
22020
+ }
22021
+ /** Owner-only; legal hold prevents recall, not account deletion. */
22022
+ async setLegalHold(conversationId, held) {
22023
+ await this.http.put(apiPath `/v1/products/messaging/conversations/${conversationId}/legal-hold`, { held });
22024
+ }
22025
+ /** Returns transfer metadata only; no account credential is sent to Forge. */
22026
+ async initiateAttachmentUpload(conversationId, options) {
22027
+ integer(options.sizeBytes, 'sizeBytes');
22028
+ const { data } = await this.http.post(apiPath `/v1/products/messaging/conversations/${conversationId}/attachments`, { size_bytes: options.sizeBytes, content_type: options.contentType });
22029
+ return { ingotId: data.ingot_id, forgeUrl: data.forge_url, expiresAt: data.expires_at, maxBytes: data.max_bytes };
22030
+ }
22031
+ async getAttachmentDownload(conversationId, ingotId) {
22032
+ const { data } = await this.http.get(apiPath `/v1/products/messaging/conversations/${conversationId}/attachments/${ingotId}/download`);
22033
+ return { ingotId: data.ingot_id, forgeUrl: data.forge_url, expiresAt: data.expires_at, sizeBytes: data.size_bytes, contentType: data.content_type };
22034
+ }
22035
+ }
22036
+
21825
22037
  /**
21826
22038
  * Products Module
21827
22039
  *
21828
22040
  * Namespace for SparkVault first-party products. Each product is a
21829
22041
  * self-contained surface (UI + API) the account can enable independently.
21830
- * Identity, Notify, and the customer-facing Help Desk attach here.
22042
+ * Identity, Notify, customer-facing Help Desk, Structured Ingots, and the
22043
+ * pre-launch Messaging business API attach here.
21831
22044
  */
21832
22045
  class ProductsModule {
21833
22046
  /**
@@ -21839,6 +22052,7 @@ class ProductsModule {
21839
22052
  this.notify = new NotifyProductModule(http);
21840
22053
  this.helpDesk = new HelpDeskModule(config);
21841
22054
  this.structuredIngots = new StructuredIngotsModule(http);
22055
+ this.messaging = new MessagingModule(http);
21842
22056
  }
21843
22057
  }
21844
22058
 
@@ -21888,8 +22102,70 @@ function unsealRequestBody(key, ttlSeconds) {
21888
22102
  return ttlSeconds === undefined ? { [field]: trimmed } : { [field]: trimmed, ttl_seconds: ttlSeconds };
21889
22103
  }
21890
22104
 
21891
- /** Maximum previous publications retained for each structured object. */
21892
- const MAX_STRUCTURED_INGOT_VERSIONS = 50;
22105
+ /**
22106
+ * The apps that manage ingots, each by the id its ingots carry as `managed_by`:
22107
+ * the one statement of those ids, of the name each app goes by, of whether an
22108
+ * app manages a row (isManagedIngot), and of whose rows Core seals server-side
22109
+ * (isServerSealedIngot). Each app marks every ingot it creates
22110
+ * with its own (Structured Ingots also calls Core as it, since Core lets only
22111
+ * the internal invoker an ingot's `managed_by` names create or touch one);
22112
+ * Core, the console, the mobile app and the Slack app ask isManagedIngot of a
22113
+ * row, and the mobile app names the app on the row's sheet. An app's ingot is
22114
+ * the app's: Core's file routes act on it only for the app, the vault shares
22115
+ * it with no one, the app included, and no request files it in a folder
22116
+ * (docs/APPS.md → Managed Ingots).
22117
+ *
22118
+ * A value is stored on every ingot its app creates and never changes on the
22119
+ * row (`managed_by` is immutable), so an id here is never renamed: a new
22120
+ * value would leave every existing ingot naming one no app answers to.
22121
+ *
22122
+ * BROWSER-SAFE: data and pure functions, no imports.
22123
+ */
22124
+
22125
+ const MANAGED_BY = Object.freeze({
22126
+ /** A Structured Ingots record, Identity's directory profiles among them. */
22127
+ STRUCTURED_INGOTS: 'structured-ingots',
22128
+ /** An encrypted catalog of a Structured Ingots type's immutable definitions. */
22129
+ STRUCTURED_INGOT_TYPES: 'structured-ingot-types',
22130
+ /** A help desk message body, email original, attachment or requester export part. */
22131
+ HELP_DESK: 'product-help-desk',
22132
+ /** A Messaging message, compacted page or attachment. */
22133
+ MESSAGING: 'product-messaging'
22134
+ });
22135
+
22136
+ /** Each app's name, as UI copy names the product (docs/DESIGN.md → Voice & copy). */
22137
+ new Map([
22138
+ [MANAGED_BY.STRUCTURED_INGOTS, 'Structured Ingots'],
22139
+ [MANAGED_BY.STRUCTURED_INGOT_TYPES, 'Structured Ingots'],
22140
+ [MANAGED_BY.HELP_DESK, 'Secure Help Desk'],
22141
+ [MANAGED_BY.MESSAGING, 'Messaging']
22142
+ ]);
22143
+
22144
+ /**
22145
+ * The apps inside Core whose ingots Core writes server-side, sealing content
22146
+ * it is handed in one call (apps/api UnifiedIngotService.sealIngotContent):
22147
+ * each such ingot lies at the vault root, at an id its app derives from its
22148
+ * own keys, and holds no name claim. Every other ingot, a Structured Ingots
22149
+ * record's included, is created through Core's upload path and holds its name
22150
+ * by a claim.
22151
+ */
22152
+ new Set([MANAGED_BY.HELP_DESK, MANAGED_BY.MESSAGING]);
22153
+
22154
+ /** Maximum previous publications retained for each user file or object. */
22155
+ const MAX_INGOT_VERSIONS = 50;
22156
+
22157
+ /** Existing vaults retain only current content until retention is enabled. */
22158
+ function ingotVersionLimit(vault) {
22159
+ const limit = vault?.ingot_version_limit === undefined
22160
+ ? (vault?.structured_ingot_version_limit === undefined ? 0 : vault.structured_ingot_version_limit)
22161
+ : vault.ingot_version_limit;
22162
+ // Malformed stored settings must never silently disable retention and purge
22163
+ // history. Every writer uses the same bounded integer contract.
22164
+ if (!Number.isSafeInteger(limit) || limit < 0 || limit > MAX_INGOT_VERSIONS) {
22165
+ throw new RangeError('Invalid ingot version limit');
22166
+ }
22167
+ return limit;
22168
+ }
21893
22169
 
21894
22170
  /**
21895
22171
  * Upload Widget Chrome
@@ -24635,7 +24911,7 @@ class VaultsModule {
24635
24911
  createdAt: v.created_at,
24636
24912
  ingotCount: v.ingot_count,
24637
24913
  storageBytes: v.storage_bytes,
24638
- ...(v.structured_ingot_version_limit === undefined ? {} : { structuredIngotVersionLimit: v.structured_ingot_version_limit }),
24914
+ ...mapVersionHistory(v),
24639
24915
  ...(v.structured_ingots_enabled === undefined ? {} : { structuredIngotsEnabled: v.structured_ingots_enabled }),
24640
24916
  ...mapLifecycle(v),
24641
24917
  })),
@@ -24674,19 +24950,23 @@ class VaultsModule {
24674
24950
  };
24675
24951
  }
24676
24952
  /**
24677
- * Retain this many previous versions of each structured object (0–50).
24678
- * Interactive company administrators only. Applies on each object's next
24679
- * successful change; retained versions count toward storage usage.
24953
+ * Retain this many previous versions of each file or structured object (0–50,
24954
+ * default 0). Interactive company administrators only. Applies on each ingot's
24955
+ * next successful content change; retained versions count toward storage usage.
24680
24956
  */
24681
- async updateStructuredIngotSettings(vaultId, settings) {
24957
+ async updateVersionHistory(vaultId, settings) {
24682
24958
  const id = requireResourceId(vaultId, 'vaultId');
24683
24959
  const limit = settings?.versionLimit;
24684
- if (!Number.isSafeInteger(limit) || limit < 0 || limit > MAX_STRUCTURED_INGOT_VERSIONS) {
24685
- throw new ValidationError(`versionLimit must be a whole number from 0 to ${MAX_STRUCTURED_INGOT_VERSIONS}`);
24960
+ if (!Number.isSafeInteger(limit) || limit < 0 || limit > MAX_INGOT_VERSIONS) {
24961
+ throw new ValidationError(`versionLimit must be a whole number from 0 to ${MAX_INGOT_VERSIONS}`);
24686
24962
  }
24687
- const response = await this.http.put(apiPath `/v1/vaults/${id}/structured-ingot-settings`, { version_limit: limit });
24963
+ const response = await this.http.put(apiPath `/v1/vaults/${id}/version-history`, { version_limit: limit });
24688
24964
  return { vaultId: response.data.vault_id, versionLimit: response.data.version_limit };
24689
24965
  }
24966
+ /** @deprecated Use updateVersionHistory; retention applies to files and structured objects. */
24967
+ async updateStructuredIngotSettings(vaultId, settings) {
24968
+ return this.updateVersionHistory(vaultId, settings);
24969
+ }
24690
24970
  /**
24691
24971
  * Rename a vault.
24692
24972
  *
@@ -24950,6 +25230,12 @@ function mapLifecycle(v) {
24950
25230
  deletionScheduleId: v.deletion_schedule_id,
24951
25231
  };
24952
25232
  }
25233
+ function mapVersionHistory(v) {
25234
+ if (v.ingot_version_limit === undefined && v.structured_ingot_version_limit === undefined)
25235
+ return {};
25236
+ const limit = ingotVersionLimit(v);
25237
+ return { ingotVersionLimit: limit, structuredIngotVersionLimit: limit };
25238
+ }
24953
25239
  function mapVaultDetail(v) {
24954
25240
  return {
24955
25241
  id: v.vault_id,
@@ -24958,7 +25244,7 @@ function mapVaultDetail(v) {
24958
25244
  ...mapLifecycle(v),
24959
25245
  ingotCount: v.ingot_count ?? 0,
24960
25246
  storageBytes: v.storage_bytes ?? 0,
24961
- ...(v.structured_ingot_version_limit === undefined ? {} : { structuredIngotVersionLimit: v.structured_ingot_version_limit }),
25247
+ ...mapVersionHistory(v),
24962
25248
  ...(v.structured_ingots_enabled === undefined ? {} : { structuredIngotsEnabled: v.structured_ingots_enabled }),
24963
25249
  createdAt: v.created_at,
24964
25250
  lastUnsealedAt: v.last_unsealed_at ?? null,
@@ -25752,7 +26038,7 @@ class SparkVault {
25752
26038
  }
25753
26039
  /** Get the SDK version */
25754
26040
  static get version() {
25755
- return '15.9.1';
26041
+ return '15.11.0';
25756
26042
  }
25757
26043
  }
25758
26044
  if (typeof window !== 'undefined') {
@@ -25762,5 +26048,5 @@ if (typeof window !== 'undefined') {
25762
26048
  window.SparkVault = instance ?? SparkVault;
25763
26049
  }
25764
26050
 
25765
- export { AuthenticationError, AuthorizationError, EntropyModule, FoldersModule, HelpDeskClient, HelpDeskModule, IdentityModule, IdentityProviderError, IngotsModule, NAME_CONFLICT_POLICIES, NOTIFY_PRESETS, NetworkError, NotifyModule, NotifyProductModule, NotifyProjectsModule, NotifySubscriptionRequiredError, PlanRequiredError, PopupBlockedError, ProductsModule, QuotaExceededError, SparkVault, SparkVaultError, SparksModule, StructuredIngotTypesModule, StructuredIngotsModule, TimeoutError, UnauthorizedError, UsageCreditFundingReviewError, UsageCreditsExhaustedError, UserCancelledError, ValidationError, VaultsModule, buildNotifyPresetSend, SparkVault as default, fetchDownload, isReceivedUploadFailure, logger, setDebugMode };
26051
+ export { AuthenticationError, AuthorizationError, EntropyModule, FoldersModule, HelpDeskClient, HelpDeskModule, IdentityModule, IdentityProviderError, IngotsModule, MessagingModule, NAME_CONFLICT_POLICIES, NOTIFY_PRESETS, NetworkError, NotifyModule, NotifyProductModule, NotifyProjectsModule, NotifySubscriptionRequiredError, PlanRequiredError, PopupBlockedError, ProductsModule, QuotaExceededError, SparkVault, SparkVaultError, SparksModule, StructuredIngotTypesModule, StructuredIngotsModule, TimeoutError, UnauthorizedError, UsageCreditFundingReviewError, UsageCreditsExhaustedError, UserCancelledError, ValidationError, VaultsModule, buildNotifyPresetSend, SparkVault as default, fetchDownload, isReceivedUploadFailure, logger, setDebugMode };
25766
26052
  //# sourceMappingURL=index.mjs.map