@arbidocs/sdk 0.5.49 → 0.5.50

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
@@ -3513,8 +3513,8 @@ var ArbiWorkspaceSupersededError = class extends ArbiError {
3513
3513
  supersededBy;
3514
3514
  };
3515
3515
  var ArbiWorkspaceChangedError = class extends ArbiError {
3516
- constructor(workspaceId) {
3517
- super(`The workspace changed while reading ${workspaceId}`);
3516
+ constructor(workspaceId, doing = "reading") {
3517
+ super(`The workspace changed while ${doing} ${workspaceId}`);
3518
3518
  this.workspaceId = workspaceId;
3519
3519
  this.name = "ArbiWorkspaceChangedError";
3520
3520
  }
@@ -5281,6 +5281,7 @@ async function uploadFile(auth, fileData, fileName, options) {
5281
5281
  if (options?.configExtId) params.set("config_ext_id", options.configExtId);
5282
5282
  if (options?.wpType) params.set("wp_type", options.wpType);
5283
5283
  if (options?.versionOf) params.set("version_of", options.versionOf);
5284
+ if (options?.workspaceExtId) params.set("workspace_ext_id", options.workspaceExtId);
5284
5285
  if (options?.derivedFrom) {
5285
5286
  params.set("derived_from", options.derivedFrom.docId);
5286
5287
  params.set("derived_role", options.derivedFrom.role);
@@ -11512,11 +11513,25 @@ var Arbi = class {
11512
11513
  upload: (files, options) => uploadDocuments(this.requireClient(), files, options),
11513
11514
  /** Near-duplicate pairs at or above `threshold` (or one document's, `docId`). */
11514
11515
  similar: (options) => similarDocuments(this.requireClient(), options),
11516
+ /**
11517
+ * Upload one file to the workspace open NOW. A re-login or workspace re-open may run before it
11518
+ * is sent (or before its one retry); it still goes only to this workspace on this session: a
11519
+ * sign-out meanwhile aborts it, and a switch to another workspace refuses it
11520
+ * (`ArbiWorkspaceChangedError`) instead of sending it to the new one.
11521
+ */
11515
11522
  uploadFile: (fileData, fileName, options) => {
11516
- this.requireWorkspace();
11517
- return this.recovering(
11518
- () => uploadFile(this.getAuthHeaders(), fileData, fileName, options)
11519
- );
11523
+ const workspaceExtId = this.requireWorkspace();
11524
+ const signal = this.requireClient().auth.sessionSignal();
11525
+ return this.recovering(() => {
11526
+ signal.throwIfAborted();
11527
+ if (this.currentWorkspaceId !== workspaceExtId) {
11528
+ throw new ArbiWorkspaceChangedError(workspaceExtId, "uploading to");
11529
+ }
11530
+ return uploadFile({ ...this.getAuthHeaders(), signal }, fileData, fileName, {
11531
+ ...options,
11532
+ workspaceExtId
11533
+ });
11534
+ });
11520
11535
  },
11521
11536
  /** Download a document's original file — its current version, or `version`. */
11522
11537
  download: (docId, version) => this.recovering(() => downloadDocument(this.getAuthHeaders(), docId, version)),