@sparkvault/sdk-js 15.7.1 → 15.9.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
@@ -5948,14 +5948,14 @@ class ErrorView {
5948
5948
  /** The design system's values for {@link DS_TOKEN_SOURCES}. */
5949
5949
  const DS = Object.freeze({
5950
5950
  white: '#ffffff',
5951
- slate50: '#f8fafc',
5952
- slate100: '#f1f5f9',
5953
- slate200: '#e2e8f0',
5954
- slate300: '#cbd5e1',
5955
- slate500: '#64748b',
5956
- slate600: '#475569',
5957
- slate900: '#0f172a',
5958
- slate950: '#030712',
5951
+ slate50: '#f7fafb',
5952
+ slate100: '#f0f5f7',
5953
+ slate200: '#e0e9ed',
5954
+ slate300: '#c9d6dc',
5955
+ slate500: '#5e757f',
5956
+ slate600: '#425761',
5957
+ slate900: '#0d1a20',
5958
+ slate950: '#030a0e',
5959
5959
  action: '#216bde',
5960
5960
  actionHover: '#0d5bcd',
5961
5961
  actionBg: '#eef4fe',
@@ -5965,20 +5965,20 @@ const DS = Object.freeze({
5965
5965
  success500: '#2ec26b',
5966
5966
  error: '#b02b27',
5967
5967
  error500: '#e6443d',
5968
- errorBg: '#fee2e2',
5969
- errorText: '#991b1b',
5968
+ errorBg: '#ffeae7',
5969
+ errorText: '#94221f',
5970
5970
  warning: '#8a5600',
5971
5971
  warning500: '#e6ad00',
5972
- infoBg: '#dbeafe',
5972
+ infoBg: '#e0f2ff',
5973
5973
  info500: '#4383eb',
5974
- modalOverlay: 'rgba(15, 23, 42, 0.6)',
5974
+ modalOverlay: 'rgba(13, 26, 32, 0.6)',
5975
5975
  darkText: 'rgba(255,255,255,0.92)',
5976
5976
  darkTextMuted: 'rgba(255,255,255,0.62)',
5977
5977
  darkHairline: 'rgba(255,255,255,0.10)',
5978
5978
  darkCard: 'rgba(255,255,255,0.05)',
5979
5979
  shadowSm: '0 1px 2px 0 rgba(0, 0, 0, 0.05)',
5980
5980
  shadowMd: '0 4px 6px -1px rgba(0, 0, 0, 0.1)',
5981
- shadowPopover: '0 8px 24px rgba(15, 23, 42, 0.12)',
5981
+ shadowPopover: '0 8px 24px rgba(13, 26, 32, 0.12)',
5982
5982
  });
5983
5983
  /**
5984
5984
  * A design-system color at an opacity.
@@ -8530,7 +8530,7 @@ function getStyles(options) {
8530
8530
 
8531
8531
  /* Press = visual compression via an inset shadow, never scale. */
8532
8532
  .sv-btn:active:not(:disabled) {
8533
- box-shadow: inset 0 1px 2px rgba(15, 23, 42, 0.2);
8533
+ box-shadow: inset 0 1px 2px ${withAlpha(DS.slate900, 0.2)};
8534
8534
  }
8535
8535
 
8536
8536
  /* Primary Button */
@@ -9158,7 +9158,7 @@ function getStyles(options) {
9158
9158
 
9159
9159
  .sv-not-activated-badge-svg {
9160
9160
  display: block;
9161
- filter: drop-shadow(0 8px 18px rgba(15, 23, 42, 0.08));
9161
+ filter: drop-shadow(0 8px 18px ${withAlpha(DS.slate900, 0.08)});
9162
9162
  }
9163
9163
 
9164
9164
  .sv-not-activated-title {
@@ -21230,6 +21230,495 @@ class HelpDeskModule {
21230
21230
  }
21231
21231
  }
21232
21232
 
21233
+ /** Browser-safe bounds and type references shared by the API, SDK and console. */
21234
+
21235
+ const STRUCTURED_TYPE_LIMITS = Object.freeze({
21236
+ maxVersions: 50,
21237
+ maxSchemaBytes: 32768,
21238
+ maxCatalogBytes: 262144,
21239
+ maxFields: 100,
21240
+ maxDepth: 8,
21241
+ maxNodes: 256,
21242
+ maxTransforms: 100,
21243
+ maxNameLength: 64,
21244
+ maxEnumValues: 100
21245
+ });
21246
+
21247
+ /** A reference to an immutable schema version; names and rules remain encrypted. */
21248
+ function normalizeStructuredTypePin(type) {
21249
+ if (type === null || type === undefined) return null;
21250
+ if (typeof type !== 'object' || Array.isArray(type) ||
21251
+ Object.keys(type).length !== 2 || !Object.hasOwn(type, 'type_id') || !Object.hasOwn(type, 'version') ||
21252
+ !isResourceIdOf('ingot', type.type_id) || !Number.isSafeInteger(type.version) ||
21253
+ type.version < 1 || type.version > STRUCTURED_TYPE_LIMITS.maxVersions) {
21254
+ throw new TypeError('type must contain a type_id and an immutable version number');
21255
+ }
21256
+ return { type_id: type.type_id, version: type.version };
21257
+ }
21258
+
21259
+ /** The portable value contract shared by Structured Ingots and its clients. */
21260
+ const STRUCTURED_INGOT_LIMITS = Object.freeze({
21261
+ maxKeys: 10000,
21262
+ maxKeyLength: 256,
21263
+ maxValueBytes: 1024 * 1024,
21264
+ maxRecordBytes: 1024 * 1024,
21265
+ maxDepth: 32,
21266
+ maxNodes: 100000
21267
+ });
21268
+
21269
+ const encoder = new TextEncoder();
21270
+ const bytes = (value) => encoder.encode(value).length;
21271
+ const isMap = (value) => value !== null && typeof value === 'object' &&
21272
+ (Object.getPrototypeOf(value) === Object.prototype || Object.getPrototypeOf(value) === null);
21273
+
21274
+ class StructuredValueError extends Error {
21275
+ constructor(message, details = null) {
21276
+ super(message);
21277
+ this.name = 'StructuredValueError';
21278
+ this.details = details;
21279
+ }
21280
+ }
21281
+
21282
+ /** Names belong in caller-only details, never an error message sent to logs. */
21283
+ function refuse(message, key) {
21284
+ const details = key === undefined ? null : { key };
21285
+ throw new StructuredValueError(message, details);
21286
+ }
21287
+
21288
+ function checkText(value, key) {
21289
+ // The SDK also supports runtimes predating String.prototype.isWellFormed.
21290
+ if (/[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:^|[^\uD800-\uDBFF])[\uDC00-\uDFFF]/.test(value)) {
21291
+ refuse('Text must contain valid Unicode characters', key);
21292
+ }
21293
+ }
21294
+
21295
+ function checkFieldName(value, key) {
21296
+ checkText(value, key);
21297
+ // MessagePack refuses this map key on decode. Refuse it before writing so a
21298
+ // successful create can never produce an object that cannot be read back.
21299
+ if (value === '__proto__') refuse('A field name is reserved by the storage format', key);
21300
+ }
21301
+
21302
+ /** The same field-name contract applies to object keys and PATCH deletions. */
21303
+ function validateStructuredKey(key) {
21304
+ if (typeof key !== 'string') refuse('Key must be a string');
21305
+ if (!key.length) refuse('Key cannot be empty');
21306
+ if (key.length > STRUCTURED_INGOT_LIMITS.maxKeyLength) refuse(`Key exceeds maximum length of ${STRUCTURED_INGOT_LIMITS.maxKeyLength} characters`, key);
21307
+ checkFieldName(key, key);
21308
+ // eslint-disable-next-line no-control-regex -- these control characters are precisely the invalid input being refused
21309
+ if (/[\x00-\x08\x0B\x0C\x0E-\x1F]/.test(key)) refuse('Key contains invalid control characters', key);
21310
+ }
21311
+
21312
+ /**
21313
+ * Validate an ordinary JSON object before serialization or schema transforms.
21314
+ * Internal callers may also store binary values; public JSON clients opt out.
21315
+ * Counts escaped UTF-8 JSON bytes (binary as base64), including nested values.
21316
+ * Traversal is bounded before serialization can allocate an unbounded buffer.
21317
+ */
21318
+ function validateStructuredData(data, { allowBinary = true } = {}) {
21319
+ if (!isMap(data)) refuse('Data must be a non-null object');
21320
+ const rootKeys = Object.keys(data);
21321
+ if (rootKeys.length > STRUCTURED_INGOT_LIMITS.maxKeys) refuse(`Maximum ${STRUCTURED_INGOT_LIMITS.maxKeys} keys exceeded`);
21322
+ let nodes = 0;
21323
+ const ancestors = new Set();
21324
+ const sizeOf = (value, depth, key) => {
21325
+ if (++nodes > STRUCTURED_INGOT_LIMITS.maxNodes) refuse('Object contains too many nested values', key);
21326
+ if (depth > STRUCTURED_INGOT_LIMITS.maxDepth) refuse(`Object exceeds maximum nesting depth of ${STRUCTURED_INGOT_LIMITS.maxDepth}`, key);
21327
+ if (value === null) return 4;
21328
+ if (typeof value === 'boolean') return value ? 4 : 5;
21329
+ if (typeof value === 'number') {
21330
+ if (!Number.isFinite(value)) refuse('Numbers must be finite', key);
21331
+ return JSON.stringify(value).length;
21332
+ }
21333
+ if (typeof value === 'string') {
21334
+ checkText(value, key);
21335
+ if (value.length > STRUCTURED_INGOT_LIMITS.maxValueBytes || bytes(value) > STRUCTURED_INGOT_LIMITS.maxValueBytes) {
21336
+ refuse(`A key's value exceeds maximum size of ${STRUCTURED_INGOT_LIMITS.maxValueBytes} bytes`, key);
21337
+ }
21338
+ return bytes(JSON.stringify(value));
21339
+ }
21340
+ if (value instanceof Uint8Array && allowBinary) {
21341
+ if (value.byteLength > STRUCTURED_INGOT_LIMITS.maxValueBytes) refuse(`A key's value exceeds maximum size of ${STRUCTURED_INGOT_LIMITS.maxValueBytes} bytes`, key);
21342
+ return 2 + Math.ceil(value.byteLength / 3) * 4;
21343
+ }
21344
+ if (value === undefined) refuse("A key's value cannot be undefined", key);
21345
+ if (!Array.isArray(value) && !isMap(value)) refuse('Values must be JSON strings, finite numbers, booleans, null, arrays or plain objects', key);
21346
+ if (ancestors.has(value)) refuse('Values cannot contain circular references', key);
21347
+ ancestors.add(value);
21348
+ let size = 2;
21349
+ let count = 0;
21350
+ const entries = Array.isArray(value) ? value.entries() : Object.entries(value);
21351
+ for (const [name, child] of entries) {
21352
+ if (++count > STRUCTURED_INGOT_LIMITS.maxNodes) refuse('Object contains too many nested values', key);
21353
+ if (count > 1) size += 1;
21354
+ if (!Array.isArray(value)) {
21355
+ checkFieldName(name, key);
21356
+ size += bytes(JSON.stringify(name)) + 1;
21357
+ }
21358
+ size += sizeOf(child, depth + 1, key);
21359
+ if (size > STRUCTURED_INGOT_LIMITS.maxValueBytes) refuse(`A key's value exceeds maximum size of ${STRUCTURED_INGOT_LIMITS.maxValueBytes} bytes`, key);
21360
+ }
21361
+ ancestors.delete(value);
21362
+ return size;
21363
+ };
21364
+ let total = 2;
21365
+ for (const [index, key] of rootKeys.entries()) {
21366
+ validateStructuredKey(key);
21367
+ const valueBytes = sizeOf(data[key], 1, key);
21368
+ if (valueBytes > STRUCTURED_INGOT_LIMITS.maxValueBytes) refuse(`A key's value exceeds maximum size of ${STRUCTURED_INGOT_LIMITS.maxValueBytes} bytes`, key);
21369
+ total += (index ? 1 : 0) + bytes(JSON.stringify(key)) + 1 + valueBytes;
21370
+ if (total > STRUCTURED_INGOT_LIMITS.maxRecordBytes) refuse(`Object exceeds maximum size of ${STRUCTURED_INGOT_LIMITS.maxRecordBytes} bytes`);
21371
+ }
21372
+ return total;
21373
+ }
21374
+
21375
+ function requireVault(vault) {
21376
+ if (!isResourceIdOf('vault', vault?.id) || typeof vault?.vatToken !== 'string' || !vault.vatToken) {
21377
+ throw new ValidationError('An unsealed vault with its Vault Access Token is required');
21378
+ }
21379
+ return vault.id;
21380
+ }
21381
+ function requireRef(ref) {
21382
+ if (isResourceIdOf('ingot', ref) || (typeof ref === 'string' && ref.startsWith(':') && ref.length > 1))
21383
+ return ref;
21384
+ throw new ValidationError('ref must be an ingot ID or a :name reference');
21385
+ }
21386
+ function integer(value, field, minimum, maximum) {
21387
+ if (!Number.isSafeInteger(value) || value < minimum || value > maximum)
21388
+ throw new ValidationError(`${field} must be a whole number from ${minimum} to ${maximum}`);
21389
+ return value;
21390
+ }
21391
+ function expectedVersion(value) { return integer(value, 'expectedVersion', 1, 0xFFFFFFFF); }
21392
+ function keysQuery(keys) {
21393
+ if (keys === undefined)
21394
+ return undefined;
21395
+ if (!Array.isArray(keys) || keys.length > 100 || keys.some((key) => typeof key !== 'string' || !key.length || key.length > 256)) {
21396
+ throw new ValidationError('keys must contain at most 100 non-empty field names');
21397
+ }
21398
+ return JSON.stringify(keys);
21399
+ }
21400
+ function pageQuery(options) {
21401
+ if (options.limit !== undefined)
21402
+ integer(options.limit, 'limit', 1, 200);
21403
+ if (options.cursor !== undefined && (typeof options.cursor !== 'string' || !options.cursor.length || options.cursor.length > 8192)) {
21404
+ throw new ValidationError('cursor must be a non-empty continuation token');
21405
+ }
21406
+ return { limit: options.limit, cursor: options.cursor };
21407
+ }
21408
+ function page(wire, items) {
21409
+ const cursor = wire.next_cursor ?? null;
21410
+ if ((wire.has_more && (typeof cursor !== 'string' || !cursor)) || (!wire.has_more && cursor !== null)) {
21411
+ throw new SparkVaultError('The server returned an inconsistent continuation', 'invalid_response');
21412
+ }
21413
+ return { items, count: wire.count, nextCursor: cursor, hasMore: wire.has_more };
21414
+ }
21415
+ function wirePin(pin) {
21416
+ if (pin === undefined || pin === null)
21417
+ return pin;
21418
+ try {
21419
+ return normalizeStructuredTypePin({ type_id: pin.typeId, version: pin.version });
21420
+ }
21421
+ catch {
21422
+ throw new ValidationError('type must name an immutable Structured Ingot type version');
21423
+ }
21424
+ }
21425
+ function readPin(pin) {
21426
+ return pin ? { typeId: pin.type_id, version: pin.version } : null;
21427
+ }
21428
+ function validateValues(data) {
21429
+ try {
21430
+ validateStructuredData(data, { allowBinary: false });
21431
+ }
21432
+ catch (error) {
21433
+ if (error instanceof StructuredValueError)
21434
+ throw new ValidationError(error.message, error.details ?? undefined);
21435
+ throw error;
21436
+ }
21437
+ }
21438
+ function validateBinaryPaths(paths) {
21439
+ if (paths === undefined)
21440
+ return;
21441
+ if (!Array.isArray(paths) || paths.length > 10000 || paths.some((path) => !Array.isArray(path) || !path.length || path.length > 32 ||
21442
+ path.some((part) => typeof part !== 'string' && !(Number.isSafeInteger(part) && part >= 0)))) {
21443
+ throw new ValidationError('binaryPaths must contain field paths made of strings and non-negative array indexes');
21444
+ }
21445
+ }
21446
+ function idempotencyHeaders(key) {
21447
+ if (key === undefined)
21448
+ return undefined;
21449
+ if (typeof key !== 'string' || !/^[\x20-\x7E]{8,128}$/.test(key))
21450
+ throw new ValidationError('idempotencyKey must contain 8–128 printable ASCII characters');
21451
+ return { 'Idempotency-Key': key };
21452
+ }
21453
+ /** Empty pages are legitimate; a repeated cursor is never drained forever. */
21454
+ async function* iteratePages(read, options = {}) {
21455
+ const maxPages = integer(options.maxPages ?? 10000, 'maxPages', 1, 100000);
21456
+ pageQuery(options);
21457
+ const seen = new Set();
21458
+ let cursor = options.cursor;
21459
+ if (cursor)
21460
+ seen.add(cursor);
21461
+ for (let count = 0; count < maxPages; count++) {
21462
+ const current = await read({ limit: options.limit, cursor });
21463
+ if (current.nextCursor && seen.has(current.nextCursor))
21464
+ throw new SparkVaultError('The server repeated a continuation token', 'invalid_response');
21465
+ for (const item of current.items)
21466
+ yield item;
21467
+ if (!current.hasMore)
21468
+ return;
21469
+ cursor = current.nextCursor;
21470
+ seen.add(cursor);
21471
+ }
21472
+ throw new ValidationError('Iteration reached maxPages; resume explicitly with the page API');
21473
+ }
21474
+
21475
+ function definition(wire) {
21476
+ return { typeId: wire.type_id, name: wire.name, version: wire.version, latestVersion: wire.latest_version,
21477
+ archived: wire.archived, schema: wire.schema, transforms: wire.transforms,
21478
+ createdAt: wire.created_at, updatedAt: wire.updated_at };
21479
+ }
21480
+ /** Definitions live inside the same encrypted vault as the records they validate. */
21481
+ class StructuredIngotTypesModule {
21482
+ constructor(http) {
21483
+ this.http = http;
21484
+ }
21485
+ async list(vault, options = {}) {
21486
+ const id = requireVault(vault);
21487
+ const { data } = await this.http.get(apiPath `/v1/products/structured-ingots/${id}/types`, { vat: vault.vatToken, query: pageQuery(options) });
21488
+ return page(data, data.types.map((type) => ({ typeId: type.type_id, name: type.name, createdAt: type.created_at, updatedAt: type.updated_at })));
21489
+ }
21490
+ iterate(vault, options = {}) {
21491
+ return iteratePages((pageOptions) => this.list(vault, pageOptions), options);
21492
+ }
21493
+ async get(vault, typeId, options = {}) {
21494
+ const id = requireVault(vault);
21495
+ const type = wirePin({ typeId, version: options.version ?? 1 }).type_id;
21496
+ const { data } = await this.http.get(apiPath `/v1/products/structured-ingots/${id}/types/${type}`, { vat: vault.vatToken, query: { version: options.version } });
21497
+ return definition(data);
21498
+ }
21499
+ async create(vault, options) {
21500
+ const id = requireVault(vault);
21501
+ validateValues(options.schema);
21502
+ const { data } = await this.http.post(apiPath `/v1/products/structured-ingots/${id}/types`, { name: options.name, schema: options.schema, transforms: options.transforms ?? [] }, { vat: vault.vatToken, headers: idempotencyHeaders(options.idempotencyKey) });
21503
+ return { ...definition(data), created: data.created, ...(data.replayed === undefined ? {} : { replayed: data.replayed }) };
21504
+ }
21505
+ async publish(vault, typeId, options) {
21506
+ const id = requireVault(vault);
21507
+ const type = wirePin({ typeId, version: options.expectedVersion }).type_id;
21508
+ integer(options.expectedVersion, 'expectedVersion', 1, STRUCTURED_TYPE_LIMITS.maxVersions);
21509
+ validateValues(options.schema);
21510
+ 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 });
21511
+ return definition(data);
21512
+ }
21513
+ async archive(vault, typeId) {
21514
+ const id = requireVault(vault);
21515
+ const type = wirePin({ typeId, version: 1 }).type_id;
21516
+ await this.http.delete(apiPath `/v1/products/structured-ingots/${id}/types/${type}`, { vat: vault.vatToken });
21517
+ return { typeId: type, archived: true };
21518
+ }
21519
+ }
21520
+
21521
+ function mutation(wire) {
21522
+ return { id: wire.ingot_id, version: wire.version, keyCount: wire.key_count, type: readPin(wire.type),
21523
+ ...(wire.created_at === undefined ? {} : { createdAt: wire.created_at }),
21524
+ ...(wire.updated_at === undefined ? {} : { updatedAt: wire.updated_at }),
21525
+ ...(wire.created === undefined ? {} : { created: wire.created }),
21526
+ ...(wire.replayed === undefined ? {} : { replayed: wire.replayed }) };
21527
+ }
21528
+ function activityQuery(options) {
21529
+ if (options.period !== undefined && options.period !== '24h' && options.period !== '7d') {
21530
+ throw new ValidationError('period must be 24h or 7d');
21531
+ }
21532
+ return { period: options.period };
21533
+ }
21534
+ function activityTotals(wire) {
21535
+ return { requests: wire.requests, reads: wire.reads, writes: wire.writes, errors: wire.errors, conflicts: wire.conflicts,
21536
+ averageLatencyMs: wire.average_latency_ms, p95UpperBoundMs: wire.p95_upper_bound_ms, p95Overflow: wire.p95_overflow };
21537
+ }
21538
+ function activity(wire) {
21539
+ return { period: wire.period, interval: wire.interval, asOf: wire.as_of, windowStart: wire.window_start, windowEnd: wire.window_end,
21540
+ totals: activityTotals(wire.totals), series: wire.series.map((bucket) => ({ start: bucket.start, end: bucket.end, ...activityTotals(bucket) })) };
21541
+ }
21542
+ /** Typed record operations using the caller's existing account and vault session. */
21543
+ class StructuredIngotsModule {
21544
+ constructor(http) {
21545
+ this.http = http;
21546
+ this.types = new StructuredIngotTypesModule(http);
21547
+ }
21548
+ /** Approximate account activity; requires an account credential, not a scoped service key. */
21549
+ async activity(options = {}) {
21550
+ const { data } = await this.http.get(apiPath `/v1/products/structured-ingots/activity`, { query: { ...activityQuery(options) } });
21551
+ return { scope: data.scope, ...activity(data) };
21552
+ }
21553
+ /** Approximate operational counters for one authorized, unsealed vault. */
21554
+ async vaultActivity(vault, options = {}) {
21555
+ const id = requireVault(vault);
21556
+ const { data } = await this.http.get(apiPath `/v1/products/structured-ingots/${id}/activity`, { vat: vault.vatToken, query: { ...activityQuery(options) } });
21557
+ return { ...activity(data), vaultId: data.vault_id, objectCount: data.object_count, vaultStorageBytes: data.vault_storage_bytes };
21558
+ }
21559
+ async get(vault, ref, options = {}) {
21560
+ const id = requireVault(vault);
21561
+ const record = requireRef(ref);
21562
+ const { data } = await this.http.get(apiPath `/v1/products/structured-ingots/${id}/${record}`, { vat: vault.vatToken, query: { delivery: 'inline', keys_json: keysQuery(options.keys) } });
21563
+ // A legacy server's Spark references must never pass for application data.
21564
+ if (data.inline !== true)
21565
+ throw new SparkVaultError('This server did not return a typed record response', 'invalid_response');
21566
+ return { id: data.ingot_id, name: data.name, version: data.version, keyCount: data.key_count,
21567
+ values: data.values, missingKeys: data.missing_keys, type: readPin(data.type),
21568
+ binaryPaths: data.binary_paths ?? data.binary_keys?.map((key) => [key]) ?? [],
21569
+ createdAt: data.created_at, updatedAt: data.updated_at };
21570
+ }
21571
+ async list(vault, options = {}) {
21572
+ const id = requireVault(vault);
21573
+ const { data } = await this.http.get(apiPath `/v1/products/structured-ingots/${id}`, { vat: vault.vatToken, query: pageQuery(options) });
21574
+ return page(data, data.ingots.map((record) => ({ id: record.ingot_id, name: record.name, sizeBytes: record.size_bytes,
21575
+ createdAt: record.created_at, updatedAt: record.updated_at ?? null })));
21576
+ }
21577
+ iterate(vault, options = {}) {
21578
+ return iteratePages((pageOptions) => this.list(vault, pageOptions), options);
21579
+ }
21580
+ /** Names use the server's documented Unicode caseless matching rules. */
21581
+ async create(vault, options) {
21582
+ const id = requireVault(vault);
21583
+ validateValues(options.data);
21584
+ validateBinaryPaths(options.binaryPaths);
21585
+ const { data } = await this.http.post(apiPath `/v1/products/structured-ingots/${id}`, { name: options.name, data: options.data, type: wirePin(options.type), binary_paths: options.binaryPaths }, { vat: vault.vatToken, headers: idempotencyHeaders(options.idempotencyKey) });
21586
+ return mutation(data);
21587
+ }
21588
+ async patch(vault, ref, options) {
21589
+ const id = requireVault(vault);
21590
+ const record = requireRef(ref);
21591
+ expectedVersion(options.expectedVersion);
21592
+ if (options.set !== undefined)
21593
+ validateValues(options.set);
21594
+ if (options.delete !== undefined && (!Array.isArray(options.delete) || options.delete.some((key) => typeof key !== 'string' || !key.length))) {
21595
+ throw new ValidationError('delete must contain non-empty field names');
21596
+ }
21597
+ 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 });
21599
+ return mutation(data);
21600
+ }
21601
+ async delete(vault, ref) {
21602
+ const id = requireVault(vault);
21603
+ const record = requireRef(ref);
21604
+ await this.http.delete(apiPath `/v1/products/structured-ingots/${id}/${record}`, { vat: vault.vatToken });
21605
+ }
21606
+ async history(vault, ref) {
21607
+ const id = requireVault(vault);
21608
+ const record = requireRef(ref);
21609
+ 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
+ })) };
21613
+ }
21614
+ async restore(vault, ref, versionId, options) {
21615
+ const id = requireVault(vault);
21616
+ 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 });
21621
+ return mutation(data);
21622
+ }
21623
+ /** Bounded parallel reads with independent, ordered success/error outcomes. */
21624
+ async batchGet(vault, refs, options = {}) {
21625
+ requireVault(vault);
21626
+ if (!Array.isArray(refs) || refs.length > 100)
21627
+ throw new ValidationError('batchGet accepts at most 100 references');
21628
+ refs.forEach(requireRef);
21629
+ keysQuery(options.keys);
21630
+ const concurrency = integer(options.concurrency ?? 4, 'concurrency', 1, 8);
21631
+ // Keep the validated work bounded even if the caller reuses its arrays.
21632
+ const input = refs.slice();
21633
+ const keys = options.keys?.slice();
21634
+ const results = new Array(input.length);
21635
+ let next = 0;
21636
+ await Promise.all(Array.from({ length: Math.min(concurrency, input.length) }, async () => {
21637
+ while (next < input.length) {
21638
+ const index = next++;
21639
+ const ref = input[index];
21640
+ try {
21641
+ results[index] = { ref, ok: true, value: await this.get(vault, ref, { keys }) };
21642
+ }
21643
+ catch (error) {
21644
+ results[index] = { ref, ok: false, error };
21645
+ }
21646
+ }
21647
+ }));
21648
+ return results;
21649
+ }
21650
+ /** Sequential record reads, not a transactionally consistent vault snapshot. */
21651
+ async *exportRecords(vault, options = {}) {
21652
+ // Bound repeated schema reads without retaining every customer definition.
21653
+ const definitions = new Map();
21654
+ for await (const item of this.iterate(vault, options)) {
21655
+ try {
21656
+ const record = await this.get(vault, item.id);
21657
+ let type = null;
21658
+ if (record.type) {
21659
+ const key = `${record.type.typeId}:${record.type.version}`;
21660
+ type = definitions.get(key) ?? null;
21661
+ if (!type) {
21662
+ const pinned = await this.types.get(vault, record.type.typeId, { version: record.type.version });
21663
+ type = { name: pinned.name, schema: pinned.schema, transforms: pinned.transforms, source: record.type };
21664
+ if (definitions.size >= 32)
21665
+ definitions.delete(definitions.keys().next().value);
21666
+ definitions.set(key, type);
21667
+ }
21668
+ }
21669
+ yield { ok: true, record: { format: 'sparkvault-structured-ingot', formatVersion: 1,
21670
+ name: record.name, data: record.values, binaryPaths: record.binaryPaths,
21671
+ // Consumers may edit exported records; never expose the shared cache.
21672
+ type: type ? JSON.parse(JSON.stringify(type)) : null,
21673
+ source: { id: record.id, version: record.version } } };
21674
+ }
21675
+ catch (error) {
21676
+ yield { ok: false, id: item.id, error };
21677
+ }
21678
+ }
21679
+ }
21680
+ /** Imports create records. Existing names fail; typed imports need explicit mapping. */
21681
+ async *importRecords(vault, records, options = {}) {
21682
+ requireVault(vault);
21683
+ let index = 0;
21684
+ for await (const record of records) {
21685
+ const name = typeof record?.name === 'string' ? record.name : null;
21686
+ try {
21687
+ if (!record || record.format !== 'sparkvault-structured-ingot' || record.formatVersion !== 1 ||
21688
+ !Object.prototype.hasOwnProperty.call(record, 'type') || !Array.isArray(record.binaryPaths) || !name) {
21689
+ throw new ValidationError('Unsupported portable Structured Ingot record');
21690
+ }
21691
+ // Validate before invoking customer mapping code or making any request.
21692
+ validateValues(record.data);
21693
+ validateBinaryPaths(record.binaryPaths);
21694
+ let type = null;
21695
+ if (record.type !== null) {
21696
+ if (!record.type || !options.mapType)
21697
+ throw new ValidationError('Typed imports require an explicit destination type mapping');
21698
+ if (!record.type.source)
21699
+ throw new ValidationError('Typed imports require the original type version');
21700
+ wirePin(record.type.source);
21701
+ validateValues(record.type.schema);
21702
+ if (typeof record.type.name !== 'string' || !record.type.name || !Array.isArray(record.type.transforms)) {
21703
+ throw new ValidationError('Typed imports require the full pinned type definition');
21704
+ }
21705
+ type = await options.mapType(record.type);
21706
+ if (!type)
21707
+ throw new ValidationError('Typed imports cannot silently remove their type');
21708
+ wirePin(type);
21709
+ }
21710
+ const value = await this.create(vault, { name, data: record.data, binaryPaths: record.binaryPaths, type,
21711
+ idempotencyKey: options.idempotencyKey?.(record) });
21712
+ yield { index, name, ok: true, value };
21713
+ }
21714
+ catch (error) {
21715
+ yield { index, name, ok: false, error };
21716
+ }
21717
+ index++;
21718
+ }
21719
+ }
21720
+ }
21721
+
21233
21722
  /**
21234
21723
  * Products Module
21235
21724
  *
@@ -21246,6 +21735,7 @@ class ProductsModule {
21246
21735
  this.identity = new IdentityModule(config);
21247
21736
  this.notify = new NotifyProductModule(http);
21248
21737
  this.helpDesk = new HelpDeskModule(config);
21738
+ this.structuredIngots = new StructuredIngotsModule(http);
21249
21739
  }
21250
21740
  }
21251
21741
 
@@ -21295,6 +21785,9 @@ function unsealRequestBody(key, ttlSeconds) {
21295
21785
  return ttlSeconds === undefined ? { [field]: trimmed } : { [field]: trimmed, ttl_seconds: ttlSeconds };
21296
21786
  }
21297
21787
 
21788
+ /** Maximum previous publications retained for each structured object. */
21789
+ const MAX_STRUCTURED_INGOT_VERSIONS = 50;
21790
+
21298
21791
  /**
21299
21792
  * Upload Widget Chrome
21300
21793
  *
@@ -24039,6 +24532,8 @@ class VaultsModule {
24039
24532
  createdAt: v.created_at,
24040
24533
  ingotCount: v.ingot_count,
24041
24534
  storageBytes: v.storage_bytes,
24535
+ ...(v.structured_ingot_version_limit === undefined ? {} : { structuredIngotVersionLimit: v.structured_ingot_version_limit }),
24536
+ ...(v.structured_ingots_enabled === undefined ? {} : { structuredIngotsEnabled: v.structured_ingots_enabled }),
24042
24537
  ...mapLifecycle(v),
24043
24538
  })),
24044
24539
  nextCursor: response.data.next_cursor,
@@ -24075,6 +24570,20 @@ class VaultsModule {
24075
24570
  defaults: { idleSeconds: value.reseal_defaults.idle_seconds, maxSeconds: value.reseal_defaults.max_seconds },
24076
24571
  };
24077
24572
  }
24573
+ /**
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.
24577
+ */
24578
+ async updateStructuredIngotSettings(vaultId, settings) {
24579
+ const id = requireResourceId(vaultId, 'vaultId');
24580
+ 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}`);
24583
+ }
24584
+ const response = await this.http.put(apiPath `/v1/vaults/${id}/structured-ingot-settings`, { version_limit: limit });
24585
+ return { vaultId: response.data.vault_id, versionLimit: response.data.version_limit };
24586
+ }
24078
24587
  /**
24079
24588
  * Rename a vault.
24080
24589
  *
@@ -24346,6 +24855,8 @@ function mapVaultDetail(v) {
24346
24855
  ...mapLifecycle(v),
24347
24856
  ingotCount: v.ingot_count ?? 0,
24348
24857
  storageBytes: v.storage_bytes ?? 0,
24858
+ ...(v.structured_ingot_version_limit === undefined ? {} : { structuredIngotVersionLimit: v.structured_ingot_version_limit }),
24859
+ ...(v.structured_ingots_enabled === undefined ? {} : { structuredIngotsEnabled: v.structured_ingots_enabled }),
24349
24860
  createdAt: v.created_at,
24350
24861
  lastUnsealedAt: v.last_unsealed_at ?? null,
24351
24862
  unsealCount: v.unseal_count ?? 0,
@@ -24386,8 +24897,8 @@ function mapUploadSettings(wire) {
24386
24897
  * Sparks Module
24387
24898
  *
24388
24899
  * Create, read, share, and delete ephemeral secrets, sealed server-side under
24389
- * platform-held keys and read once. Sparks are account-scoped — no vault or
24390
- * VAT is involved.
24900
+ * platform-held keys and read once. Ordinary Sparks are account-scoped;
24901
+ * values derived from Structured Ingots require the source vault's VAT.
24391
24902
  */
24392
24903
  class SparksModule {
24393
24904
  constructor(http) {
@@ -24416,14 +24927,15 @@ class SparksModule {
24416
24927
  /**
24417
24928
  * Read (and burn) a spark. Reading is destructive — the spark can be read
24418
24929
  * exactly once.
24930
+ * Supply the source vault's VAT for a Structured Ingots field Spark.
24419
24931
  *
24420
24932
  * @example
24421
24933
  * const spark = await sv.sparks.get('spk_abc');
24422
24934
  * console.log(spark.payload);
24423
24935
  */
24424
- async get(sparkId) {
24936
+ async get(sparkId, vat) {
24425
24937
  const id = requireResourceId(sparkId, 'sparkId');
24426
- const response = await this.http.get(apiPath `/v1/sparks/${id}`);
24938
+ const response = await this.http.get(apiPath `/v1/sparks/${id}`, vat ? { vat } : undefined);
24427
24939
  const data = response.data;
24428
24940
  return {
24429
24941
  id: data.spark_id,
@@ -25137,7 +25649,7 @@ class SparkVault {
25137
25649
  }
25138
25650
  /** Get the SDK version */
25139
25651
  static get version() {
25140
- return '15.7.1';
25652
+ return '15.9.0';
25141
25653
  }
25142
25654
  }
25143
25655
  if (typeof window !== 'undefined') {
@@ -25147,5 +25659,5 @@ if (typeof window !== 'undefined') {
25147
25659
  window.SparkVault = instance ?? SparkVault;
25148
25660
  }
25149
25661
 
25150
- 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, TimeoutError, UnauthorizedError, UsageCreditFundingReviewError, UsageCreditsExhaustedError, UserCancelledError, ValidationError, VaultsModule, buildNotifyPresetSend, SparkVault as default, fetchDownload, isReceivedUploadFailure, logger, setDebugMode };
25662
+ 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 };
25151
25663
  //# sourceMappingURL=index.mjs.map