@arbidocs/sdk 0.5.68 → 0.5.69

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.
@@ -1432,12 +1432,15 @@ declare function updateDocuments(arbi: ArbiClient, documents: DocUpdateRequest$1
1432
1432
  title?: string | null | undefined;
1433
1433
  } | null | undefined;
1434
1434
  }[]>;
1435
- /**
1436
- * Kick off a URL-based document ingestion. The active workspace is resolved
1437
- * server-side from the open session — there is no ``workspace_ext_id`` query
1438
- * param on this endpoint.
1439
- */
1440
- declare function uploadUrl(arbi: ArbiClient, urls: string[], shared?: boolean, configExtId?: string | null): Promise<{
1435
+ /** Where a URL ingestion goes and how. */
1436
+ interface UploadUrlOptions {
1437
+ /** The workspace the documents are made in (its key must be on the session). */
1438
+ workspaceExtId: string;
1439
+ shared?: boolean;
1440
+ configExtId?: string | null;
1441
+ }
1442
+ /** Kick off a URL-based document ingestion into `options.workspaceExtId`. */
1443
+ declare function uploadUrl(arbi: ArbiClient, urls: string[], options: UploadUrlOptions): Promise<{
1441
1444
  doc_ext_ids?: string[] | undefined;
1442
1445
  version?: number | null | undefined;
1443
1446
  batch_id?: string | null | undefined;
@@ -1548,12 +1551,11 @@ interface UploadDirectOptions {
1548
1551
  */
1549
1552
  onBytesProgress?: (progress: DirectUploadProgress) => void;
1550
1553
  /**
1551
- * Runs each of the two server requests (init, commit). `upload-init` and `upload-commit` name no
1552
- * workspace yet (they act on the session's open one), so a caller that encrypts with a workspace's
1553
- * key passes a guard that refuses to send, or to keep the answer, unless that workspace is the
1554
- * one open (`Arbi.documents.uploadDirect` does: `readInWorkspace`).
1554
+ * The workspace whose key the files are encrypted with: `upload-init` reserves the rows in it and
1555
+ * `upload-commit` commits them there (its key must be on the session), whatever workspace the
1556
+ * session has open meanwhile.
1555
1557
  */
1556
- inWorkspace?: <T>(send: () => Promise<T>) => Promise<T>;
1558
+ workspaceExtId: string;
1557
1559
  }
1558
1560
  interface DirectUploadProgress {
1559
1561
  fileIndex: number;
@@ -1624,7 +1626,7 @@ declare function presignedPut(url: string, body: Uint8Array, onProgress?: (loade
1624
1626
  * callers that want to upload files from disk should use the wrapper in
1625
1627
  * ``documents-node`` which reads ``fs`` into the ``data`` field.
1626
1628
  */
1627
- declare function uploadDocumentsDirect(arbi: DirectUploadClient, workspaceKey: Uint8Array, files: DirectUploadFile[], options?: UploadDirectOptions): Promise<UploadDirectResult>;
1629
+ declare function uploadDocumentsDirect(arbi: DirectUploadClient, workspaceKey: Uint8Array, files: DirectUploadFile[], options: UploadDirectOptions): Promise<UploadDirectResult>;
1628
1630
 
1629
1631
  type documents_DirectUploadClient = DirectUploadClient;
1630
1632
  type documents_DirectUploadFile = DirectUploadFile;
@@ -1642,6 +1644,7 @@ type documents_UploadDirectResult = UploadDirectResult;
1642
1644
  type documents_UploadDocumentsOptions = UploadDocumentsOptions;
1643
1645
  type documents_UploadOptions = UploadOptions;
1644
1646
  type documents_UploadResult = UploadResult;
1647
+ type documents_UploadUrlOptions = UploadUrlOptions;
1645
1648
  declare const documents_deleteDocuments: typeof deleteDocuments;
1646
1649
  declare const documents_downloadDocument: typeof downloadDocument;
1647
1650
  declare const documents_finaliseTranslation: typeof finaliseTranslation;
@@ -1662,7 +1665,7 @@ declare const documents_uploadDocumentsDirect: typeof uploadDocumentsDirect;
1662
1665
  declare const documents_uploadFiles: typeof uploadFiles;
1663
1666
  declare const documents_uploadUrl: typeof uploadUrl;
1664
1667
  declare namespace documents {
1665
- export { type documents_DirectUploadClient as DirectUploadClient, type documents_DirectUploadFile as DirectUploadFile, type documents_DirectUploadProgress as DirectUploadProgress, type documents_DocumentListFields as DocumentListFields, type documents_DocumentListOrder as DocumentListOrder, type documents_ListAllOptions as ListAllOptions, type documents_ListPaginatedOptions as ListPaginatedOptions, documents_MAX_PAGES as MAX_PAGES, documents_SUPPORTED_EXTENSIONS as SUPPORTED_EXTENSIONS, type documents_SkippedFile as SkippedFile, type documents_UploadBatchResult as UploadBatchResult, type documents_UploadDirectOptions as UploadDirectOptions, type documents_UploadDirectResult as UploadDirectResult, type documents_UploadDocumentsOptions as UploadDocumentsOptions, type documents_UploadOptions as UploadOptions, type documents_UploadResult as UploadResult, documents_deleteDocuments as deleteDocuments, documents_downloadDocument as downloadDocument, documents_finaliseTranslation as finaliseTranslation, documents_getDocuments as getDocuments, documents_getParsedContent as getParsedContent, documents_getThumbnails as getThumbnails, documents_listAll as listAll, documents_listDocuments as listDocuments, documents_listPaginated as listPaginated, documents_listVersions as listVersions, documents_mimeFromName as mimeFromName, documents_presignedPut as presignedPut, documents_sanitizeFolderPath as sanitizeFolderPath, documents_similarDocuments as similarDocuments, documents_updateDocuments as updateDocuments, documents_uploadDocuments as uploadDocuments, documents_uploadDocumentsDirect as uploadDocumentsDirect, uploadFile$1 as uploadFile, documents_uploadFiles as uploadFiles, documents_uploadUrl as uploadUrl };
1668
+ export { type documents_DirectUploadClient as DirectUploadClient, type documents_DirectUploadFile as DirectUploadFile, type documents_DirectUploadProgress as DirectUploadProgress, type documents_DocumentListFields as DocumentListFields, type documents_DocumentListOrder as DocumentListOrder, type documents_ListAllOptions as ListAllOptions, type documents_ListPaginatedOptions as ListPaginatedOptions, documents_MAX_PAGES as MAX_PAGES, documents_SUPPORTED_EXTENSIONS as SUPPORTED_EXTENSIONS, type documents_SkippedFile as SkippedFile, type documents_UploadBatchResult as UploadBatchResult, type documents_UploadDirectOptions as UploadDirectOptions, type documents_UploadDirectResult as UploadDirectResult, type documents_UploadDocumentsOptions as UploadDocumentsOptions, type documents_UploadOptions as UploadOptions, type documents_UploadResult as UploadResult, type documents_UploadUrlOptions as UploadUrlOptions, documents_deleteDocuments as deleteDocuments, documents_downloadDocument as downloadDocument, documents_finaliseTranslation as finaliseTranslation, documents_getDocuments as getDocuments, documents_getParsedContent as getParsedContent, documents_getThumbnails as getThumbnails, documents_listAll as listAll, documents_listDocuments as listDocuments, documents_listPaginated as listPaginated, documents_listVersions as listVersions, documents_mimeFromName as mimeFromName, documents_presignedPut as presignedPut, documents_sanitizeFolderPath as sanitizeFolderPath, documents_similarDocuments as similarDocuments, documents_updateDocuments as updateDocuments, documents_uploadDocuments as uploadDocuments, documents_uploadDocumentsDirect as uploadDocumentsDirect, uploadFile$1 as uploadFile, documents_uploadFiles as uploadFiles, documents_uploadUrl as uploadUrl };
1666
1669
  }
1667
1670
 
1668
1671
  /**
@@ -8345,6 +8348,8 @@ declare class Arbi {
8345
8348
  * `undefined` only when no workspace is known here (the server's open one then applies, as before).
8346
8349
  */
8347
8350
  private targetWorkspace;
8351
+ /** {@link targetWorkspace} for a call that cannot go without one: throws when none is known. */
8352
+ private requireTargetWorkspace;
8348
8353
  /**
8349
8354
  * Make a workspace the CURRENT one: decrypt its key, open it on the server (which makes it the
8350
8355
  * session's active workspace) and record it in the session. This is navigation: only the host's
@@ -10901,7 +10906,9 @@ declare class Arbi {
10901
10906
  title?: string | null | undefined;
10902
10907
  } | null | undefined;
10903
10908
  }[]>;
10909
+ /** Make documents from web addresses in the current workspace, or `options.workspaceId`. */
10904
10910
  uploadUrl: (urls: string[], options?: {
10911
+ workspaceId?: string;
10905
10912
  shared?: boolean;
10906
10913
  configExtId?: string | null;
10907
10914
  }) => Promise<{
@@ -10914,8 +10921,9 @@ declare class Arbi {
10914
10921
  }[] | undefined;
10915
10922
  }>;
10916
10923
  /**
10917
- * Upload files in one request (the open workspace, or `options.workspaceExtId`): folder, tag,
10918
- * sharing, config, a new version of a document.
10924
+ * Upload files in one request into the current workspace, or `options.workspaceExtId`: folder,
10925
+ * tag, sharing, config, a new version of a document. The request names the workspace either
10926
+ * way, so a switch while it is in flight cannot move it.
10919
10927
  */
10920
10928
  upload: (files: Array<Blob | File>, options?: UploadDocumentsOptions) => Promise<UploadResult>;
10921
10929
  /** Near-duplicate pairs at or above `threshold` (or one document's, `docId`). */
@@ -10945,14 +10953,11 @@ declare class Arbi {
10945
10953
  uploadFile: (fileData: Blob, fileName: string, options?: UploadOptions) => Promise<UploadResult>;
10946
10954
  /**
10947
10955
  * Upload files straight to storage, encrypted here with `workspaceKey` (`uploadDocumentsDirect`),
10948
- * into `workspaceId`, which must be the workspace open NOW. `upload-init` and `upload-commit`
10949
- * name no workspace yet (they act on the session's open one), so each runs under
10950
- * `readInWorkspace`: it is not sent, or its answer not kept, unless `workspaceId` is open when
10951
- * it is sent and still when it returns. A switch refuses the upload
10952
- * (`ArbiWorkspaceChangedError`) instead of storing files encrypted with one workspace's key in
10953
- * another. For any other workspace use `upload` with `workspaceExtId`, which names it.
10956
+ * into `workspaceId`, whose key it must be. `upload-init` and `upload-commit` name that
10957
+ * workspace (made usable for this session first, not switched to), so a switch while the
10958
+ * upload runs cannot move the files into another workspace.
10954
10959
  */
10955
- uploadDirect: (workspaceId: string, workspaceKey: Uint8Array, files: DirectUploadFile[], options?: Omit<UploadDirectOptions, "inWorkspace">) => Promise<UploadDirectResult>;
10960
+ uploadDirect: (workspaceId: string, workspaceKey: Uint8Array, files: DirectUploadFile[], options?: Omit<UploadDirectOptions, "workspaceExtId">) => Promise<UploadDirectResult>;
10956
10961
  /** Download a document's original file — its current version, or `version`. */
10957
10962
  download: (docId: string, version?: number) => Promise<Response>;
10958
10963
  getParsedContent: (docId: string, stage: string, version?: number) => Promise<Record<string, unknown>>;
@@ -1432,12 +1432,15 @@ declare function updateDocuments(arbi: ArbiClient, documents: DocUpdateRequest$1
1432
1432
  title?: string | null | undefined;
1433
1433
  } | null | undefined;
1434
1434
  }[]>;
1435
- /**
1436
- * Kick off a URL-based document ingestion. The active workspace is resolved
1437
- * server-side from the open session — there is no ``workspace_ext_id`` query
1438
- * param on this endpoint.
1439
- */
1440
- declare function uploadUrl(arbi: ArbiClient, urls: string[], shared?: boolean, configExtId?: string | null): Promise<{
1435
+ /** Where a URL ingestion goes and how. */
1436
+ interface UploadUrlOptions {
1437
+ /** The workspace the documents are made in (its key must be on the session). */
1438
+ workspaceExtId: string;
1439
+ shared?: boolean;
1440
+ configExtId?: string | null;
1441
+ }
1442
+ /** Kick off a URL-based document ingestion into `options.workspaceExtId`. */
1443
+ declare function uploadUrl(arbi: ArbiClient, urls: string[], options: UploadUrlOptions): Promise<{
1441
1444
  doc_ext_ids?: string[] | undefined;
1442
1445
  version?: number | null | undefined;
1443
1446
  batch_id?: string | null | undefined;
@@ -1548,12 +1551,11 @@ interface UploadDirectOptions {
1548
1551
  */
1549
1552
  onBytesProgress?: (progress: DirectUploadProgress) => void;
1550
1553
  /**
1551
- * Runs each of the two server requests (init, commit). `upload-init` and `upload-commit` name no
1552
- * workspace yet (they act on the session's open one), so a caller that encrypts with a workspace's
1553
- * key passes a guard that refuses to send, or to keep the answer, unless that workspace is the
1554
- * one open (`Arbi.documents.uploadDirect` does: `readInWorkspace`).
1554
+ * The workspace whose key the files are encrypted with: `upload-init` reserves the rows in it and
1555
+ * `upload-commit` commits them there (its key must be on the session), whatever workspace the
1556
+ * session has open meanwhile.
1555
1557
  */
1556
- inWorkspace?: <T>(send: () => Promise<T>) => Promise<T>;
1558
+ workspaceExtId: string;
1557
1559
  }
1558
1560
  interface DirectUploadProgress {
1559
1561
  fileIndex: number;
@@ -1624,7 +1626,7 @@ declare function presignedPut(url: string, body: Uint8Array, onProgress?: (loade
1624
1626
  * callers that want to upload files from disk should use the wrapper in
1625
1627
  * ``documents-node`` which reads ``fs`` into the ``data`` field.
1626
1628
  */
1627
- declare function uploadDocumentsDirect(arbi: DirectUploadClient, workspaceKey: Uint8Array, files: DirectUploadFile[], options?: UploadDirectOptions): Promise<UploadDirectResult>;
1629
+ declare function uploadDocumentsDirect(arbi: DirectUploadClient, workspaceKey: Uint8Array, files: DirectUploadFile[], options: UploadDirectOptions): Promise<UploadDirectResult>;
1628
1630
 
1629
1631
  type documents_DirectUploadClient = DirectUploadClient;
1630
1632
  type documents_DirectUploadFile = DirectUploadFile;
@@ -1642,6 +1644,7 @@ type documents_UploadDirectResult = UploadDirectResult;
1642
1644
  type documents_UploadDocumentsOptions = UploadDocumentsOptions;
1643
1645
  type documents_UploadOptions = UploadOptions;
1644
1646
  type documents_UploadResult = UploadResult;
1647
+ type documents_UploadUrlOptions = UploadUrlOptions;
1645
1648
  declare const documents_deleteDocuments: typeof deleteDocuments;
1646
1649
  declare const documents_downloadDocument: typeof downloadDocument;
1647
1650
  declare const documents_finaliseTranslation: typeof finaliseTranslation;
@@ -1662,7 +1665,7 @@ declare const documents_uploadDocumentsDirect: typeof uploadDocumentsDirect;
1662
1665
  declare const documents_uploadFiles: typeof uploadFiles;
1663
1666
  declare const documents_uploadUrl: typeof uploadUrl;
1664
1667
  declare namespace documents {
1665
- export { type documents_DirectUploadClient as DirectUploadClient, type documents_DirectUploadFile as DirectUploadFile, type documents_DirectUploadProgress as DirectUploadProgress, type documents_DocumentListFields as DocumentListFields, type documents_DocumentListOrder as DocumentListOrder, type documents_ListAllOptions as ListAllOptions, type documents_ListPaginatedOptions as ListPaginatedOptions, documents_MAX_PAGES as MAX_PAGES, documents_SUPPORTED_EXTENSIONS as SUPPORTED_EXTENSIONS, type documents_SkippedFile as SkippedFile, type documents_UploadBatchResult as UploadBatchResult, type documents_UploadDirectOptions as UploadDirectOptions, type documents_UploadDirectResult as UploadDirectResult, type documents_UploadDocumentsOptions as UploadDocumentsOptions, type documents_UploadOptions as UploadOptions, type documents_UploadResult as UploadResult, documents_deleteDocuments as deleteDocuments, documents_downloadDocument as downloadDocument, documents_finaliseTranslation as finaliseTranslation, documents_getDocuments as getDocuments, documents_getParsedContent as getParsedContent, documents_getThumbnails as getThumbnails, documents_listAll as listAll, documents_listDocuments as listDocuments, documents_listPaginated as listPaginated, documents_listVersions as listVersions, documents_mimeFromName as mimeFromName, documents_presignedPut as presignedPut, documents_sanitizeFolderPath as sanitizeFolderPath, documents_similarDocuments as similarDocuments, documents_updateDocuments as updateDocuments, documents_uploadDocuments as uploadDocuments, documents_uploadDocumentsDirect as uploadDocumentsDirect, uploadFile$1 as uploadFile, documents_uploadFiles as uploadFiles, documents_uploadUrl as uploadUrl };
1668
+ export { type documents_DirectUploadClient as DirectUploadClient, type documents_DirectUploadFile as DirectUploadFile, type documents_DirectUploadProgress as DirectUploadProgress, type documents_DocumentListFields as DocumentListFields, type documents_DocumentListOrder as DocumentListOrder, type documents_ListAllOptions as ListAllOptions, type documents_ListPaginatedOptions as ListPaginatedOptions, documents_MAX_PAGES as MAX_PAGES, documents_SUPPORTED_EXTENSIONS as SUPPORTED_EXTENSIONS, type documents_SkippedFile as SkippedFile, type documents_UploadBatchResult as UploadBatchResult, type documents_UploadDirectOptions as UploadDirectOptions, type documents_UploadDirectResult as UploadDirectResult, type documents_UploadDocumentsOptions as UploadDocumentsOptions, type documents_UploadOptions as UploadOptions, type documents_UploadResult as UploadResult, type documents_UploadUrlOptions as UploadUrlOptions, documents_deleteDocuments as deleteDocuments, documents_downloadDocument as downloadDocument, documents_finaliseTranslation as finaliseTranslation, documents_getDocuments as getDocuments, documents_getParsedContent as getParsedContent, documents_getThumbnails as getThumbnails, documents_listAll as listAll, documents_listDocuments as listDocuments, documents_listPaginated as listPaginated, documents_listVersions as listVersions, documents_mimeFromName as mimeFromName, documents_presignedPut as presignedPut, documents_sanitizeFolderPath as sanitizeFolderPath, documents_similarDocuments as similarDocuments, documents_updateDocuments as updateDocuments, documents_uploadDocuments as uploadDocuments, documents_uploadDocumentsDirect as uploadDocumentsDirect, uploadFile$1 as uploadFile, documents_uploadFiles as uploadFiles, documents_uploadUrl as uploadUrl };
1666
1669
  }
1667
1670
 
1668
1671
  /**
@@ -8345,6 +8348,8 @@ declare class Arbi {
8345
8348
  * `undefined` only when no workspace is known here (the server's open one then applies, as before).
8346
8349
  */
8347
8350
  private targetWorkspace;
8351
+ /** {@link targetWorkspace} for a call that cannot go without one: throws when none is known. */
8352
+ private requireTargetWorkspace;
8348
8353
  /**
8349
8354
  * Make a workspace the CURRENT one: decrypt its key, open it on the server (which makes it the
8350
8355
  * session's active workspace) and record it in the session. This is navigation: only the host's
@@ -10901,7 +10906,9 @@ declare class Arbi {
10901
10906
  title?: string | null | undefined;
10902
10907
  } | null | undefined;
10903
10908
  }[]>;
10909
+ /** Make documents from web addresses in the current workspace, or `options.workspaceId`. */
10904
10910
  uploadUrl: (urls: string[], options?: {
10911
+ workspaceId?: string;
10905
10912
  shared?: boolean;
10906
10913
  configExtId?: string | null;
10907
10914
  }) => Promise<{
@@ -10914,8 +10921,9 @@ declare class Arbi {
10914
10921
  }[] | undefined;
10915
10922
  }>;
10916
10923
  /**
10917
- * Upload files in one request (the open workspace, or `options.workspaceExtId`): folder, tag,
10918
- * sharing, config, a new version of a document.
10924
+ * Upload files in one request into the current workspace, or `options.workspaceExtId`: folder,
10925
+ * tag, sharing, config, a new version of a document. The request names the workspace either
10926
+ * way, so a switch while it is in flight cannot move it.
10919
10927
  */
10920
10928
  upload: (files: Array<Blob | File>, options?: UploadDocumentsOptions) => Promise<UploadResult>;
10921
10929
  /** Near-duplicate pairs at or above `threshold` (or one document's, `docId`). */
@@ -10945,14 +10953,11 @@ declare class Arbi {
10945
10953
  uploadFile: (fileData: Blob, fileName: string, options?: UploadOptions) => Promise<UploadResult>;
10946
10954
  /**
10947
10955
  * Upload files straight to storage, encrypted here with `workspaceKey` (`uploadDocumentsDirect`),
10948
- * into `workspaceId`, which must be the workspace open NOW. `upload-init` and `upload-commit`
10949
- * name no workspace yet (they act on the session's open one), so each runs under
10950
- * `readInWorkspace`: it is not sent, or its answer not kept, unless `workspaceId` is open when
10951
- * it is sent and still when it returns. A switch refuses the upload
10952
- * (`ArbiWorkspaceChangedError`) instead of storing files encrypted with one workspace's key in
10953
- * another. For any other workspace use `upload` with `workspaceExtId`, which names it.
10956
+ * into `workspaceId`, whose key it must be. `upload-init` and `upload-commit` name that
10957
+ * workspace (made usable for this session first, not switched to), so a switch while the
10958
+ * upload runs cannot move the files into another workspace.
10954
10959
  */
10955
- uploadDirect: (workspaceId: string, workspaceKey: Uint8Array, files: DirectUploadFile[], options?: Omit<UploadDirectOptions, "inWorkspace">) => Promise<UploadDirectResult>;
10960
+ uploadDirect: (workspaceId: string, workspaceKey: Uint8Array, files: DirectUploadFile[], options?: Omit<UploadDirectOptions, "workspaceExtId">) => Promise<UploadDirectResult>;
10956
10961
  /** Download a document's original file — its current version, or `version`. */
10957
10962
  download: (docId: string, version?: number) => Promise<Response>;
10958
10963
  getParsedContent: (docId: string, stage: string, version?: number) => Promise<Record<string, unknown>>;
package/dist/browser.cjs CHANGED
@@ -5480,16 +5480,40 @@ async function updateDocuments(arbi, documents) {
5480
5480
  "Failed to update documents"
5481
5481
  );
5482
5482
  }
5483
- async function uploadUrl(arbi, urls, shared = false, configExtId) {
5484
- return requireData(
5483
+ async function uploadUrl(arbi, urls, options) {
5484
+ return requireUploadData(
5485
5485
  await arbi.fetch.POST("/v1/document/upload-url", {
5486
5486
  params: {
5487
- query: { urls, shared, ...configExtId ? { config_ext_id: configExtId } : {} }
5487
+ query: {
5488
+ urls,
5489
+ shared: options.shared ?? false,
5490
+ workspace_ext_id: options.workspaceExtId,
5491
+ ...options.configExtId ? { config_ext_id: options.configExtId } : {}
5492
+ }
5488
5493
  }
5489
5494
  }),
5490
5495
  "Failed to upload from URLs"
5491
5496
  );
5492
5497
  }
5498
+ var UPLOAD_WORKSPACE_CONFLICT_MESSAGES = {
5499
+ workspace_mismatch: "These files were prepared for another workspace, so they were not saved. Upload them again.",
5500
+ workspace_key_required: "The workspace couldn't be unlocked for this upload, so the files were not saved."
5501
+ };
5502
+ function requireUploadData(result, message) {
5503
+ const status = result.response?.status;
5504
+ const conflict = result.error && status === 409 ? workspaceConflictOf(result.error) : null;
5505
+ if (conflict) {
5506
+ throw new ArbiApiError(
5507
+ UPLOAD_WORKSPACE_CONFLICT_MESSAGES[conflict.code],
5508
+ result.error,
5509
+ status,
5510
+ {
5511
+ code: conflict.code
5512
+ }
5513
+ );
5514
+ }
5515
+ return requireData(result, message);
5516
+ }
5493
5517
  async function uploadDocuments(arbi, files, options = {}) {
5494
5518
  const query2 = {};
5495
5519
  if (options.shared !== void 0) query2.shared = options.shared;
@@ -5514,7 +5538,7 @@ async function uploadDocuments(arbi, files, options = {}) {
5514
5538
  return form;
5515
5539
  }
5516
5540
  });
5517
- return requireData(result, "Failed to upload documents");
5541
+ return requireUploadData(result, "Failed to upload documents");
5518
5542
  }
5519
5543
  async function similarDocuments(arbi, options = {}) {
5520
5544
  return requireData(
@@ -5671,6 +5695,9 @@ async function presignedPut(url, body, onProgress, headers) {
5671
5695
  }
5672
5696
  }
5673
5697
  async function uploadDocumentsDirect(arbi, workspaceKey, files, options) {
5698
+ if (!options?.workspaceExtId) {
5699
+ throw new ArbiError("uploadDocumentsDirect needs options.workspaceExtId (the key's workspace)");
5700
+ }
5674
5701
  if (files.length === 0) return { doc_ext_ids: [], skipped: [] };
5675
5702
  const SECRETBOX_ENVELOPE_OVERHEAD = 40;
5676
5703
  const declared = files.map((f2) => ({
@@ -5682,21 +5709,19 @@ async function uploadDocumentsDirect(arbi, workspaceKey, files, options) {
5682
5709
  }));
5683
5710
  const initBody = {
5684
5711
  files: declared,
5685
- shared: options?.shared !== false,
5686
- config_ext_id: options?.configExtId ?? null,
5712
+ shared: options.shared !== false,
5713
+ config_ext_id: options.configExtId ?? null,
5687
5714
  // Only sent when set, so a plain upload is accepted by any server version.
5688
- ...options?.versionOf ? { version_of: options.versionOf } : {},
5689
- wp_type: options?.wpType ?? null,
5690
- tag_ext_id: options?.tagExtId ?? null,
5691
- folder: options?.folder ? sanitizeFolderPath(options.folder) : null,
5692
- presign_expires_in: options?.presignExpiresIn ?? 3600
5715
+ ...options.versionOf ? { version_of: options.versionOf } : {},
5716
+ wp_type: options.wpType ?? null,
5717
+ tag_ext_id: options.tagExtId ?? null,
5718
+ folder: options.folder ? sanitizeFolderPath(options.folder) : null,
5719
+ presign_expires_in: options.presignExpiresIn ?? 3600
5693
5720
  };
5694
- const guarded = options?.inWorkspace ?? ((send) => send());
5695
- const initResult = await guarded(
5696
- async () => requireData(
5697
- await arbi.fetch.POST("/v1/document/upload-init", { body: initBody }),
5698
- "Failed to initialize direct upload"
5699
- )
5721
+ const query2 = { workspace_ext_id: options.workspaceExtId };
5722
+ const initResult = requireUploadData(
5723
+ await arbi.fetch.POST("/v1/document/upload-init", { params: { query: query2 }, body: initBody }),
5724
+ "Failed to initialize direct upload"
5700
5725
  );
5701
5726
  const items = initResult.items ?? [];
5702
5727
  const bytesByName = /* @__PURE__ */ new Map();
@@ -5730,7 +5755,7 @@ async function uploadDocumentsDirect(arbi, workspaceKey, files, options) {
5730
5755
  const total = ciphertext.length;
5731
5756
  try {
5732
5757
  await presignedPut(item.upload_url, ciphertext, (loaded, putTotal) => {
5733
- options?.onBytesProgress?.({
5758
+ options.onBytesProgress?.({
5734
5759
  fileIndex,
5735
5760
  fileName: item.file_name,
5736
5761
  loaded,
@@ -5742,7 +5767,7 @@ async function uploadDocumentsDirect(arbi, workspaceKey, files, options) {
5742
5767
  `Presigned PUT for ${item.doc_ext_id} failed: ${err instanceof Error ? err.message : String(err)}`
5743
5768
  );
5744
5769
  }
5745
- options?.onBytesProgress?.({
5770
+ options.onBytesProgress?.({
5746
5771
  fileIndex,
5747
5772
  fileName: item.file_name,
5748
5773
  loaded: total,
@@ -5753,16 +5778,15 @@ async function uploadDocumentsDirect(arbi, workspaceKey, files, options) {
5753
5778
  if (toCommit.length === 0) {
5754
5779
  return { doc_ext_ids: [], skipped };
5755
5780
  }
5756
- const commitResult = await guarded(
5757
- async () => requireData(
5758
- await arbi.fetch.POST("/v1/document/upload-commit", {
5759
- body: {
5760
- doc_ext_ids: toCommit,
5761
- tag_ext_id: options?.tagExtId ?? null
5762
- }
5763
- }),
5764
- "Failed to commit direct upload"
5765
- )
5781
+ const commitResult = requireUploadData(
5782
+ await arbi.fetch.POST("/v1/document/upload-commit", {
5783
+ params: { query: query2 },
5784
+ body: {
5785
+ doc_ext_ids: toCommit,
5786
+ tag_ext_id: options.tagExtId ?? null
5787
+ }
5788
+ }),
5789
+ "Failed to commit direct upload"
5766
5790
  );
5767
5791
  return {
5768
5792
  doc_ext_ids: commitResult.doc_ext_ids ?? [],
@@ -11213,6 +11237,10 @@ var Arbi = class {
11213
11237
  if (target) await this.openWorkspace(target);
11214
11238
  return target;
11215
11239
  }
11240
+ /** {@link targetWorkspace} for a call that cannot go without one: throws when none is known. */
11241
+ async requireTargetWorkspace(workspaceId) {
11242
+ return await this.targetWorkspace(workspaceId) ?? this.requireWorkspace();
11243
+ }
11216
11244
  /**
11217
11245
  * Make a workspace the CURRENT one: decrypt its key, open it on the server (which makes it the
11218
11246
  * session's active workspace) and record it in the session. This is navigation: only the host's
@@ -11826,20 +11854,23 @@ var Arbi = class {
11826
11854
  finaliseTranslation: (docId) => finaliseTranslation(this.requireClient(), docId),
11827
11855
  delete: (externalIds) => deleteDocuments(this.requireClient(), externalIds),
11828
11856
  update: (documents) => updateDocuments(this.requireClient(), documents),
11829
- uploadUrl: (urls, options) => {
11830
- this.requireWorkspace();
11831
- return uploadUrl(
11832
- this.requireClient(),
11833
- urls,
11834
- options?.shared,
11835
- options?.configExtId
11836
- );
11857
+ /** Make documents from web addresses in the current workspace, or `options.workspaceId`. */
11858
+ uploadUrl: async (urls, options) => {
11859
+ const { workspaceId, ...rest } = options ?? {};
11860
+ return uploadUrl(this.requireClient(), urls, {
11861
+ workspaceExtId: await this.requireTargetWorkspace(workspaceId),
11862
+ ...rest
11863
+ });
11837
11864
  },
11838
11865
  /**
11839
- * Upload files in one request (the open workspace, or `options.workspaceExtId`): folder, tag,
11840
- * sharing, config, a new version of a document.
11866
+ * Upload files in one request into the current workspace, or `options.workspaceExtId`: folder,
11867
+ * tag, sharing, config, a new version of a document. The request names the workspace either
11868
+ * way, so a switch while it is in flight cannot move it.
11841
11869
  */
11842
- upload: (files, options) => uploadDocuments(this.requireClient(), files, options),
11870
+ upload: async (files, options) => uploadDocuments(this.requireClient(), files, {
11871
+ ...options,
11872
+ workspaceExtId: await this.requireTargetWorkspace(options?.workspaceExtId ?? void 0)
11873
+ }),
11843
11874
  /** Near-duplicate pairs at or above `threshold` (or one document's, `docId`). */
11844
11875
  similar: (options) => similarDocuments(this.requireClient(), options),
11845
11876
  /**
@@ -11864,19 +11895,15 @@ var Arbi = class {
11864
11895
  },
11865
11896
  /**
11866
11897
  * Upload files straight to storage, encrypted here with `workspaceKey` (`uploadDocumentsDirect`),
11867
- * into `workspaceId`, which must be the workspace open NOW. `upload-init` and `upload-commit`
11868
- * name no workspace yet (they act on the session's open one), so each runs under
11869
- * `readInWorkspace`: it is not sent, or its answer not kept, unless `workspaceId` is open when
11870
- * it is sent and still when it returns. A switch refuses the upload
11871
- * (`ArbiWorkspaceChangedError`) instead of storing files encrypted with one workspace's key in
11872
- * another. For any other workspace use `upload` with `workspaceExtId`, which names it.
11898
+ * into `workspaceId`, whose key it must be. `upload-init` and `upload-commit` name that
11899
+ * workspace (made usable for this session first, not switched to), so a switch while the
11900
+ * upload runs cannot move the files into another workspace.
11873
11901
  */
11874
- uploadDirect: (workspaceId, workspaceKey, files, options) => {
11875
- if (this.currentWorkspaceId !== workspaceId)
11876
- return Promise.reject(new ArbiWorkspaceChangedError(workspaceId, "uploading to"));
11902
+ uploadDirect: async (workspaceId, workspaceKey, files, options) => {
11903
+ const workspaceExtId = await this.requireTargetWorkspace(workspaceId);
11877
11904
  return uploadDocumentsDirect(this.requireClient(), workspaceKey, files, {
11878
11905
  ...options,
11879
- inWorkspace: (send) => this.readInWorkspace(workspaceId, send)
11906
+ workspaceExtId
11880
11907
  });
11881
11908
  },
11882
11909
  /** Download a document's original file — its current version, or `version`. */