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