@sparkvault/sdk-js 11.2.0 → 11.2.2

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.d.ts CHANGED
@@ -2370,7 +2370,11 @@ interface UploadIngotOptions {
2370
2370
  file: File | Blob;
2371
2371
  /** Optional name (defaults to file name) */
2372
2372
  name?: string;
2373
- /** Content type (auto-detected from the file if not provided) */
2373
+ /**
2374
+ * Content type (the file's own `type` if not provided). A file of no type is
2375
+ * sent with none, and Core stores the type the registry lists for the name's
2376
+ * extension, else `application/octet-stream`.
2377
+ */
2374
2378
  contentType?: string;
2375
2379
  /** Slash-delimited folder path (find-or-created from root). */
2376
2380
  folder?: string;
@@ -2418,7 +2422,11 @@ interface ReplaceIngotOptions {
2418
2422
  name?: string;
2419
2423
  /** Vault-keyed plaintext HMAC (43-char base64url) for the NEW content. */
2420
2424
  contentHmac?: string;
2421
- /** Content type (auto-detected from the file if not provided) */
2425
+ /**
2426
+ * Content type (the file's own `type` if not provided). A file of no type
2427
+ * keeps the type the ingot stores, which Core reads from the name by its
2428
+ * extension only when it is `application/octet-stream` or unparsable.
2429
+ */
2422
2430
  contentType?: string;
2423
2431
  /** Progress callback for the Forge/TUS transfer */
2424
2432
  onProgress?: (bytesUploaded: number, bytesTotal: number) => void;
@@ -2464,9 +2472,15 @@ interface FolderContents {
2464
2472
  }
2465
2473
  /** Options for search. */
2466
2474
  interface SearchIngotsOptions {
2467
- /** Free-text query */
2475
+ /** The beginning of the ingot's name, in any case: a prefix, never a substring or a fuzzy match. */
2468
2476
  q?: string;
2469
- /** File type filter */
2477
+ /**
2478
+ * The MIME type to match, in lowercase: a family (`image`, `video`,
2479
+ * `audio`, `text`, `application`, ...), which every type under it matches,
2480
+ * or an exact type (`application/pdf`), which matches that type whatever
2481
+ * its parameters. A well-formed value no ingot carries matches none; the
2482
+ * server refuses a value that is neither.
2483
+ */
2470
2484
  fileType?: string;
2471
2485
  /** Scope the search to one folder (whole vault when omitted) */
2472
2486
  folderId?: string;
package/dist/index.mjs CHANGED
@@ -27,8 +27,9 @@ function isTransientHttpStatus(status) {
27
27
 
28
28
  /**
29
29
  * The upload publication contract between Forge and Core's activation, and
30
- * the facts of a transfer token both services spell: its shape, and Core's
31
- * revocation of an upload's token.
30
+ * the facts of a transfer token both services spell: its shape, the
31
+ * publication it is bound to (a content version, and the one an ingot row
32
+ * names), and Core's revocation of an upload's token.
32
33
  *
33
34
  * Forge stamps UPLOAD_PUBLICATION_PROTOCOL on every upload session it creates
34
35
  * and on the final state it hands Core's activation (POST
@@ -16314,10 +16315,9 @@ class IngotsModule {
16314
16315
  throw new ValidationError('Provide folder or folderId, not both');
16315
16316
  }
16316
16317
  const name = options.name ?? getBlobName(options.file);
16317
- const contentType = options.contentType ?? options.file.type ?? 'application/octet-stream';
16318
16318
  const created = await this.requestUploadSession(vault, {
16319
16319
  name,
16320
- content_type: contentType,
16320
+ content_type: sentContentType(options),
16321
16321
  size_bytes: options.file.size,
16322
16322
  contentHmac: options.contentHmac,
16323
16323
  folder: options.folder,
@@ -16339,10 +16339,11 @@ class IngotsModule {
16339
16339
  const vaultId = requireVaultId(vault);
16340
16340
  const id = requireResourceId(ingotId, 'ingotId');
16341
16341
  const name = options.name ?? getBlobName(options.file);
16342
- const contentType = options.contentType ?? options.file.type ?? 'application/octet-stream';
16342
+ const contentType = sentContentType(options);
16343
16343
  const response = await this.http.put(apiPath `/v1/vaults/${vaultId}/ingots/${id}`, {
16344
16344
  name,
16345
- content_type: contentType,
16345
+ // Omitted, Core keeps the ingot's stored type (ReplaceIngotOptions.contentType).
16346
+ ...(contentType !== undefined && { content_type: contentType }),
16346
16347
  size_bytes: options.file.size,
16347
16348
  ...(options.contentHmac && { content_hmac: options.contentHmac }),
16348
16349
  }, { vat: vault.vatToken }).catch((error) => {
@@ -16622,7 +16623,8 @@ class IngotsModule {
16622
16623
  async requestUploadSession(vault, body) {
16623
16624
  const payload = {
16624
16625
  name: body.name,
16625
- content_type: body.content_type ?? 'application/octet-stream',
16626
+ // Omitted, Core types the file by its name's extension.
16627
+ ...(body.content_type !== undefined && { content_type: body.content_type }),
16626
16628
  size_bytes: body.size_bytes,
16627
16629
  };
16628
16630
  // folder_path (find-or-create) and folder_id (existing folder) are
@@ -16680,6 +16682,15 @@ function getBlobName(file) {
16680
16682
  }
16681
16683
  return 'unnamed';
16682
16684
  }
16685
+ /**
16686
+ * The type an upload or replacement sends: the caller's, else the file's own.
16687
+ * A Blob of no type reports '', so such a file is sent with none, which Core
16688
+ * reads as a create typed by its name and a replacement that keeps the
16689
+ * ingot's stored type.
16690
+ */
16691
+ function sentContentType(options) {
16692
+ return options.contentType ?? (options.file.type || undefined);
16693
+ }
16683
16694
  function mapIngot(wire) {
16684
16695
  return {
16685
16696
  id: wire.ingot_id,
@@ -17416,7 +17427,7 @@ class SparkVault {
17416
17427
  }
17417
17428
  /** Get the SDK version */
17418
17429
  static get version() {
17419
- return '11.2.0';
17430
+ return '11.2.2';
17420
17431
  }
17421
17432
  }
17422
17433
  if (typeof window !== 'undefined') {