@sparkvault/sdk-js 15.10.0 → 15.11.1

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.cjs CHANGED
@@ -21547,12 +21547,12 @@ function requireRef(ref) {
21547
21547
  return ref;
21548
21548
  throw new ValidationError('ref must be an ingot ID or a :name reference');
21549
21549
  }
21550
- function integer(value, field, minimum, maximum) {
21550
+ function integer$1(value, field, minimum, maximum) {
21551
21551
  if (!Number.isSafeInteger(value) || value < minimum || value > maximum)
21552
21552
  throw new ValidationError(`${field} must be a whole number from ${minimum} to ${maximum}`);
21553
21553
  return value;
21554
21554
  }
21555
- function expectedVersion(value) { return integer(value, 'expectedVersion', 1, 0xFFFFFFFF); }
21555
+ function expectedVersion(value) { return integer$1(value, 'expectedVersion', 1, 0xFFFFFFFF); }
21556
21556
  function mutationPrecondition(options) {
21557
21557
  const revision = expectedRevision(options.expectedRevision);
21558
21558
  const version = options.expectedVersion;
@@ -21573,7 +21573,7 @@ function keysQuery(keys) {
21573
21573
  }
21574
21574
  function pageQuery(options) {
21575
21575
  if (options.limit !== undefined)
21576
- integer(options.limit, 'limit', 1, 200);
21576
+ integer$1(options.limit, 'limit', 1, 200);
21577
21577
  if (options.cursor !== undefined && (typeof options.cursor !== 'string' || !options.cursor.length || options.cursor.length > 8192)) {
21578
21578
  throw new ValidationError('cursor must be a non-empty continuation token');
21579
21579
  }
@@ -21626,7 +21626,7 @@ function idempotencyHeaders(key) {
21626
21626
  }
21627
21627
  /** Empty pages are legitimate; a repeated cursor is never drained forever. */
21628
21628
  async function* iteratePages(read, options = {}) {
21629
- const maxPages = integer(options.maxPages ?? 10000, 'maxPages', 1, 100000);
21629
+ const maxPages = integer$1(options.maxPages ?? 10000, 'maxPages', 1, 100000);
21630
21630
  pageQuery(options);
21631
21631
  const seen = new Set();
21632
21632
  let cursor = options.cursor;
@@ -21679,7 +21679,7 @@ class StructuredIngotTypesModule {
21679
21679
  async publish(vault, typeId, options) {
21680
21680
  const id = requireVault(vault);
21681
21681
  const type = wirePin({ typeId, version: options.expectedVersion }).type_id;
21682
- integer(options.expectedVersion, 'expectedVersion', 1, STRUCTURED_TYPE_LIMITS.maxVersions);
21682
+ integer$1(options.expectedVersion, 'expectedVersion', 1, STRUCTURED_TYPE_LIMITS.maxVersions);
21683
21683
  validateValues(options.schema);
21684
21684
  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 });
21685
21685
  return definition(data);
@@ -21803,7 +21803,7 @@ class StructuredIngotsModule {
21803
21803
  throw new ValidationError('batchGet accepts at most 100 references');
21804
21804
  refs.forEach(requireRef);
21805
21805
  keysQuery(options.keys);
21806
- const concurrency = integer(options.concurrency ?? 4, 'concurrency', 1, 8);
21806
+ const concurrency = integer$1(options.concurrency ?? 4, 'concurrency', 1, 8);
21807
21807
  // Keep the validated work bounded even if the caller reuses its arrays.
21808
21808
  const input = refs.slice();
21809
21809
  const keys = options.keys?.slice();
@@ -21895,12 +21895,156 @@ class StructuredIngotsModule {
21895
21895
  }
21896
21896
  }
21897
21897
 
21898
+ function integer(value, field, minimum = 1) {
21899
+ if (!Number.isSafeInteger(value) || value < minimum) {
21900
+ throw new ValidationError(`${field} must be a ${minimum === 0 ? 'non-negative' : 'positive'} safe integer`, { field });
21901
+ }
21902
+ }
21903
+ function participant(wire) {
21904
+ return { svid: wire.svid, role: wire.role, addedAt: wire.added_at,
21905
+ ...(wire.identity === undefined ? {} : { identity: wire.identity }),
21906
+ ...(wire.opted_out === undefined ? {} : { optedOut: wire.opted_out }) };
21907
+ }
21908
+ function message(wire) {
21909
+ if (wire.recalled)
21910
+ return { messageId: wire.message_id, recalled: true };
21911
+ if (wire.unavailable)
21912
+ return { messageId: wire.message_id, unavailable: true };
21913
+ return { messageId: wire.message_id, schemaVersion: wire.schema_version, senderSvid: wire.sender_svid,
21914
+ senderIdentity: wire.sender_identity, ts: wire.ts, contentType: wire.content_type, content: wire.content,
21915
+ attachments: (wire.attachments ?? []).map((item) => ({ ingotId: item.ingot_id, name: item.name })) };
21916
+ }
21917
+ function receipt(wire) {
21918
+ return { accountId: wire.account_id, conversationId: wire.conversation_id, messageId: wire.message_id,
21919
+ senderSvid: wire.sender_svid, contentHash: wire.content_hash };
21920
+ }
21921
+ /** Stateless, authenticated business API for the pre-launch Messaging product. */
21922
+ class MessagingModule {
21923
+ constructor(http) {
21924
+ this.http = http;
21925
+ }
21926
+ /** Follow cursor even when a page contains fewer than limit conversations. */
21927
+ async getInbox(options = {}) {
21928
+ if (options.limit !== undefined)
21929
+ integer(options.limit, 'limit');
21930
+ // Core decodes the query's cursor once more before JSON.parse. Encode the
21931
+ // serialized key here; the shared transport applies the outer query encoding.
21932
+ const { data } = await this.http.get(apiPath `/v1/products/messaging/inbox`, {
21933
+ query: { limit: options.limit, cursor: options.cursor === undefined ? undefined : encodeURIComponent(JSON.stringify(options.cursor)) },
21934
+ });
21935
+ return { conversations: data.items.map((item) => ({ conversationId: item.conversation_id, accountId: item.account_id,
21936
+ lastActivityTs: item.last_activity_ts, lastMessageId: item.last_message_id, unreadCount: item.unread_count ?? 0,
21937
+ archived: item.archived === true, ...(item.last_read_id === undefined ? {} : { lastReadId: item.last_read_id }),
21938
+ ...(item.other_participants === undefined ? {} : { otherParticipants: item.other_participants }) })),
21939
+ ...(data.cursor == null ? {} : { cursor: data.cursor }) };
21940
+ }
21941
+ /** Create with business members; invite account-less recipients separately. */
21942
+ async createConversation(options = {}) {
21943
+ const { data } = await this.http.post(apiPath `/v1/products/messaging/conversations`, {
21944
+ participants: options.participants,
21945
+ settings: options.settings === undefined ? undefined : { audit_retention_seconds: options.settings.auditRetentionSeconds },
21946
+ });
21947
+ return { conversationId: data.conversation_id, vaultId: data.vault_id,
21948
+ participants: data.participants.map(participant), createdAt: data.created_at };
21949
+ }
21950
+ async getConversation(conversationId) {
21951
+ const { data } = await this.http.get(apiPath `/v1/products/messaging/conversations/${conversationId}`);
21952
+ return { conversationId: data.conversation_id, participants: data.participants.map(participant),
21953
+ committedThrough: data.committed_through, compactedThrough: data.compacted_through, createdAt: data.created_at,
21954
+ settings: data.settings.audit_retention_seconds === undefined ? {} : { auditRetentionSeconds: data.settings.audit_retention_seconds } };
21955
+ }
21956
+ /** Sends are never retried automatically: Core allocates a new id per send. */
21957
+ async send(conversationId, options) {
21958
+ if (typeof options?.content !== 'string' || !options.content.length)
21959
+ throw new ValidationError('content must be a non-empty string');
21960
+ const { data } = await this.http.post(apiPath `/v1/products/messaging/conversations/${conversationId}/messages`, {
21961
+ content: options.content, content_type: options.contentType,
21962
+ attachments: options.attachments?.map((item) => ({ ingot_id: item.ingotId, name: item.name })),
21963
+ });
21964
+ return { messageId: data.message_id, conversationId: data.conversation_id, ts: data.ts, ingotId: data.ingot_id,
21965
+ contentHash: data.content_hash, committedThrough: data.committed_through, status: data.status,
21966
+ receipt: { ...receipt(data.receipt), ts: data.receipt.ts } };
21967
+ }
21968
+ /** Fresh read each time, including recalls and newly resolved gaps at old ids. */
21969
+ async read(conversationId, options = {}) {
21970
+ if ((options.fromId === undefined) !== (options.toId === undefined))
21971
+ throw new ValidationError('fromId and toId must be supplied together');
21972
+ if (options.fromId !== undefined)
21973
+ integer(options.fromId, 'fromId');
21974
+ if (options.toId !== undefined)
21975
+ integer(options.toId, 'toId');
21976
+ if (options.fromId !== undefined && options.toId < options.fromId)
21977
+ throw new ValidationError('toId must be at least fromId');
21978
+ if (options.limit !== undefined)
21979
+ integer(options.limit, 'limit');
21980
+ const { data } = await this.http.get(apiPath `/v1/products/messaging/conversations/${conversationId}/messages`, {
21981
+ query: { from_id: options.fromId, to_id: options.toId, limit: options.limit },
21982
+ });
21983
+ return { messages: data.messages.map(message), committedThrough: data.committed_through, compactedThrough: data.compacted_through };
21984
+ }
21985
+ async markRead(conversationId, lastReadId) {
21986
+ integer(lastReadId, 'lastReadId', 0);
21987
+ await this.http.post(apiPath `/v1/products/messaging/conversations/${conversationId}/read`, { last_read_id: lastReadId });
21988
+ }
21989
+ async archive(conversationId, archived = true) {
21990
+ await this.http.put(apiPath `/v1/products/messaging/conversations/${conversationId}/archive`, { archived });
21991
+ }
21992
+ async invite(conversationId, identity) {
21993
+ if (!identity || !['email', 'phone'].includes(identity.type) || typeof identity.value !== 'string' || !identity.value.trim()) {
21994
+ throw new ValidationError('type (email|phone) and a non-empty value are required');
21995
+ }
21996
+ const { data } = await this.http.post(apiPath `/v1/products/messaging/conversations/${conversationId}/invites`, identity);
21997
+ return { svid: data.svid, accessUrl: data.access_url };
21998
+ }
21999
+ async addParticipant(conversationId, input) {
22000
+ const { data } = await this.http.post(apiPath `/v1/products/messaging/conversations/${conversationId}/participants`, input);
22001
+ return data.participants.map(participant);
22002
+ }
22003
+ async removeParticipant(conversationId, svid) {
22004
+ const { data } = await this.http.delete(apiPath `/v1/products/messaging/conversations/${conversationId}/participants/${svid}`);
22005
+ return data.participants.map(participant);
22006
+ }
22007
+ async recall(conversationId, messageId) {
22008
+ integer(messageId, 'messageId');
22009
+ await this.http.post(apiPath `/v1/products/messaging/conversations/${conversationId}/messages/${String(messageId)}/recall`);
22010
+ }
22011
+ async getReceipt(conversationId, messageId) {
22012
+ integer(messageId, 'messageId');
22013
+ const { data } = await this.http.get(apiPath `/v1/products/messaging/conversations/${conversationId}/messages/${String(messageId)}/receipt`);
22014
+ return { receiptToken: data.receipt_token, expiresAt: data.expires_at,
22015
+ receipt: { ...receipt(data.receipt), messageTs: data.receipt.message_ts } };
22016
+ }
22017
+ /** Owner-only; a closed conversation refuses new sends. */
22018
+ async close(conversationId, closed = true) {
22019
+ await this.http.put(apiPath `/v1/products/messaging/conversations/${conversationId}/close`, { closed });
22020
+ }
22021
+ /** Stores the caller's preference; Core currently does not gate sends on it. */
22022
+ async setOptOut(conversationId, optedOut) {
22023
+ await this.http.put(apiPath `/v1/products/messaging/conversations/${conversationId}/opt-out`, { opted_out: optedOut });
22024
+ }
22025
+ /** Owner-only; legal hold prevents recall, not account deletion. */
22026
+ async setLegalHold(conversationId, held) {
22027
+ await this.http.put(apiPath `/v1/products/messaging/conversations/${conversationId}/legal-hold`, { held });
22028
+ }
22029
+ /** Returns transfer metadata only; no account credential is sent to Forge. */
22030
+ async initiateAttachmentUpload(conversationId, options) {
22031
+ integer(options.sizeBytes, 'sizeBytes');
22032
+ const { data } = await this.http.post(apiPath `/v1/products/messaging/conversations/${conversationId}/attachments`, { size_bytes: options.sizeBytes, content_type: options.contentType });
22033
+ return { ingotId: data.ingot_id, forgeUrl: data.forge_url, expiresAt: data.expires_at, maxBytes: data.max_bytes };
22034
+ }
22035
+ async getAttachmentDownload(conversationId, ingotId) {
22036
+ const { data } = await this.http.get(apiPath `/v1/products/messaging/conversations/${conversationId}/attachments/${ingotId}/download`);
22037
+ return { ingotId: data.ingot_id, forgeUrl: data.forge_url, expiresAt: data.expires_at, sizeBytes: data.size_bytes, contentType: data.content_type };
22038
+ }
22039
+ }
22040
+
21898
22041
  /**
21899
22042
  * Products Module
21900
22043
  *
21901
22044
  * Namespace for SparkVault first-party products. Each product is a
21902
22045
  * self-contained surface (UI + API) the account can enable independently.
21903
- * Identity, Notify, and the customer-facing Help Desk attach here.
22046
+ * Identity, Notify, customer-facing Help Desk, Structured Ingots, and the
22047
+ * pre-launch Messaging business API attach here.
21904
22048
  */
21905
22049
  class ProductsModule {
21906
22050
  /**
@@ -21912,6 +22056,7 @@ class ProductsModule {
21912
22056
  this.notify = new NotifyProductModule(http);
21913
22057
  this.helpDesk = new HelpDeskModule(config);
21914
22058
  this.structuredIngots = new StructuredIngotsModule(http);
22059
+ this.messaging = new MessagingModule(http);
21915
22060
  }
21916
22061
  }
21917
22062
 
@@ -25897,7 +26042,7 @@ class SparkVault {
25897
26042
  }
25898
26043
  /** Get the SDK version */
25899
26044
  static get version() {
25900
- return '15.10.0';
26045
+ return '15.11.1';
25901
26046
  }
25902
26047
  }
25903
26048
  if (typeof window !== 'undefined') {
@@ -25916,6 +26061,7 @@ exports.HelpDeskModule = HelpDeskModule;
25916
26061
  exports.IdentityModule = IdentityModule;
25917
26062
  exports.IdentityProviderError = IdentityProviderError;
25918
26063
  exports.IngotsModule = IngotsModule;
26064
+ exports.MessagingModule = MessagingModule;
25919
26065
  exports.NAME_CONFLICT_POLICIES = NAME_CONFLICT_POLICIES;
25920
26066
  exports.NOTIFY_PRESETS = NOTIFY_PRESETS;
25921
26067
  exports.NetworkError = NetworkError;