@xberg-io/sdk 0.8.0 → 0.8.1

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.js CHANGED
@@ -359,7 +359,7 @@ const SUCCESS_JOB_STATUSES = ["completed", "partial_success"];
359
359
  * and defaults to `baseUrl`. The backend methods use that origin and an optional
360
360
  * separate `controlPlaneToken`; existing Pro methods retain their data-plane routing.
361
361
  */
362
- const USER_AGENT = `xberg-io-sdk-typescript/0.8.0`;
362
+ const USER_AGENT = `xberg-io-sdk-typescript/0.8.1`;
363
363
  const DEFAULT_TIMEOUT_MS = 3e4;
364
364
  const DEFAULT_POLL_INTERVAL_MS = 1e3;
365
365
  const DEFAULT_WAIT_TIMEOUT_MS = 3e5;
@@ -708,6 +708,7 @@ var XbergClient = class {
708
708
  async extract(params) {
709
709
  const jobs = await this.extractBatch({
710
710
  files: [params.file],
711
+ ...params.projectId !== void 0 ? { projectId: params.projectId } : {},
711
712
  ...params.documentId !== void 0 ? { documentIds: [params.documentId] } : {},
712
713
  ...params.options !== void 0 ? { options: params.options } : {},
713
714
  ...params.webhook !== void 0 ? { webhook: params.webhook } : {},
@@ -732,6 +733,8 @@ var XbergClient = class {
732
733
  const filenames = params.files.map(describeFile);
733
734
  const documentIds = prepareDocumentLineage(filenames, params.documentIds);
734
735
  if (documentIds.size > 0) await this.requireTier("enterprise", "extract document lineage");
736
+ if (params.projectId !== void 0) await this.requireTier("pro", "projectId");
737
+ const projectHeader = Object.keys(this.headers).find((name) => name.toLowerCase() === "x-project-id") ?? "X-Project-ID";
735
738
  const form = new FormData();
736
739
  for (const [filename, documentId] of documentIds) form.append(`document_id-${filename}`, documentId);
737
740
  const parts = params.files.map(toBlob);
@@ -739,7 +742,10 @@ var XbergClient = class {
739
742
  if (params.options !== void 0) form.append("options", JSON.stringify(params.options));
740
743
  if (params.webhook !== void 0) form.append("webhook", JSON.stringify(params.webhook));
741
744
  appendPerFileConfigs(form, filenames, params.configs);
742
- const body = await this.requestJson("POST", "/v1/extract", { body: form });
745
+ const body = await this.requestJson("POST", "/v1/extract", {
746
+ body: form,
747
+ ...params.projectId !== void 0 ? { headers: { [projectHeader]: params.projectId } } : {}
748
+ });
743
749
  const jobIds = body.job_ids ?? [];
744
750
  const now = (/* @__PURE__ */ new Date()).toISOString();
745
751
  return parts.map(({ blob, filename }, index) => {
@@ -758,8 +764,8 @@ var XbergClient = class {
758
764
  });
759
765
  }
760
766
  /** Fetch a tagged extraction or crawl job record (`GET /v1/jobs/{id}`). */
761
- async getJob(jobId) {
762
- return parseJobResponse(await this.requestJson("GET", `${JOBS_PATH}/${encodePathSegment(jobId)}`));
767
+ async getJob(jobId, scope = {}) {
768
+ return parseJobResponse(await this.requestJson("GET", `${JOBS_PATH}/${encodePathSegment(jobId)}`, { params: await this.jobScope(scope) }));
763
769
  }
764
770
  /**
765
771
  * Fetch a job's stored result document (`GET /v1/jobs/{id}/result`).
@@ -768,12 +774,13 @@ var XbergClient = class {
768
774
  * extracted documents live in `results`. Distinct from {@link getJob}, which
769
775
  * returns the job's metadata record.
770
776
  */
771
- async getJobResult(jobId) {
772
- return await this.requestJson("GET", `${JOBS_PATH}/${encodePathSegment(jobId)}/result`);
777
+ async getJobResult(jobId, scope = {}) {
778
+ return await this.requestJson("GET", `${JOBS_PATH}/${encodePathSegment(jobId)}/result`, { params: await this.jobScope(scope) });
773
779
  }
774
780
  /** List jobs (paginated) via `GET /v1/jobs`. */
775
781
  async listJobs(params = {}) {
776
782
  return await this.requestJson("GET", JOBS_PATH, { params: {
783
+ ...await this.jobScope(params),
777
784
  limit: params.limit,
778
785
  offset: params.offset
779
786
  } });
@@ -783,8 +790,8 @@ var XbergClient = class {
783
790
  * cancellation and a job that already reached a terminal status answer
784
791
  * `204`.
785
792
  */
786
- async cancelJob(jobId) {
787
- await this.requestJson("DELETE", `${JOBS_PATH}/${encodePathSegment(jobId)}`);
793
+ async cancelJob(jobId, scope = {}) {
794
+ await this.requestJson("DELETE", `${JOBS_PATH}/${encodePathSegment(jobId)}`, { params: await this.jobScope(scope) });
788
795
  }
789
796
  /**
790
797
  * Poll {@link getJob} until the job reaches a terminal status. Throws
@@ -798,7 +805,7 @@ var XbergClient = class {
798
805
  const start = Date.now();
799
806
  let interval = initialInterval;
800
807
  for (;;) {
801
- const job = await this.getJob(jobId);
808
+ const job = await this.getJob(jobId, options);
802
809
  if (job.job_type !== "extraction") throw new ValidationError("expected extraction job, received crawl job", {
803
810
  status: 200,
804
811
  body: job
@@ -828,6 +835,7 @@ var XbergClient = class {
828
835
  async extractAndWait(params) {
829
836
  const extractParams = {
830
837
  file: params.file,
838
+ ...params.projectId !== void 0 ? { projectId: params.projectId } : {},
831
839
  ...params.documentId !== void 0 ? { documentId: params.documentId } : {},
832
840
  ...params.options !== void 0 ? { options: params.options } : {},
833
841
  ...params.webhook !== void 0 ? { webhook: params.webhook } : {},
@@ -835,6 +843,7 @@ var XbergClient = class {
835
843
  };
836
844
  const job = await this.extract(extractParams);
837
845
  const waitOptions = {
846
+ ...params.projectId !== void 0 ? { projectId: params.projectId } : {},
838
847
  ...params.timeoutMs !== void 0 ? { timeoutMs: params.timeoutMs } : {},
839
848
  ...params.pollIntervalMs !== void 0 ? { pollIntervalMs: params.pollIntervalMs } : {},
840
849
  ...params.backoff !== void 0 ? { backoff: params.backoff } : {}
@@ -1041,17 +1050,20 @@ var XbergClient = class {
1041
1050
  * (`GET /v1/jobs/{job_id}/pages/{page_number}`). The response is a PNG image —
1042
1051
  * raw bytes, not JSON. `pageNumber` is 1-indexed.
1043
1052
  */
1044
- async getJobPage(jobId, pageNumber) {
1053
+ async getJobPage(jobId, pageNumber, scope = {}) {
1045
1054
  const path = `${JOBS_PATH}/${encodePathSegment(jobId)}/pages/${encodePathSegment(String(pageNumber))}`;
1046
- return await this.requestBytes("GET", path);
1055
+ return await this.requestBytes("GET", path, { params: await this.jobScope(scope) });
1047
1056
  }
1048
1057
  /** Submit text for enrichment (`POST /v1/enrich`). */
1049
- async submitEnrich(body) {
1050
- return await this.requestJson("POST", ENRICH_PATH, { json: body });
1058
+ async submitEnrich(body, scope = {}) {
1059
+ return await this.requestJson("POST", ENRICH_PATH, {
1060
+ json: body,
1061
+ params: await this.jobScope(scope)
1062
+ });
1051
1063
  }
1052
1064
  /** Fetch an enrichment job's status (`GET /v1/enrich/{job_id}`). */
1053
- async getEnrichStatus(jobId) {
1054
- return await this.requestJson("GET", `${ENRICH_PATH}/${encodePathSegment(jobId)}`);
1065
+ async getEnrichStatus(jobId, scope = {}) {
1066
+ return await this.requestJson("GET", `${ENRICH_PATH}/${encodePathSegment(jobId)}`, { params: await this.jobScope(scope) });
1055
1067
  }
1056
1068
  /**
1057
1069
  * Stream a crawl job's events (`GET /v1/crawl-jobs/{crawl_job_id}/events`,
@@ -1077,9 +1089,17 @@ var XbergClient = class {
1077
1089
  */
1078
1090
  streamCrawlEvents(crawlJobId, options = {}) {
1079
1091
  const path = `${CRAWL_JOBS_PATH}/${encodePathSegment(crawlJobId)}/events`;
1080
- const open = () => this.openEventStream(path, options.signal);
1092
+ const open = async () => this.openEventStream(`${path}${buildQueryString(await this.jobScope(options))}`, options.signal);
1081
1093
  return { [Symbol.asyncIterator]: () => iterateCrawlEvents(open) };
1082
1094
  }
1095
+ /**
1096
+ * Pro liveness and coarse license/capability state (`GET /healthz`).
1097
+ * Use readiness checks to assess dependencies. ~keep
1098
+ */
1099
+ async proHealthz() {
1100
+ await this.requireTier("pro", "proHealthz");
1101
+ return this.requestJson("GET", "/healthz");
1102
+ }
1083
1103
  /** Pro only: fetch the instance's accepted auth methods (`GET /auth/config`). */
1084
1104
  async authConfig() {
1085
1105
  await this.requireTier("pro", "authConfig");
@@ -1176,6 +1196,16 @@ var XbergClient = class {
1176
1196
  await this.requireTier("pro", "getIntegration");
1177
1197
  return this.requestJson("GET", this.integrationPath(projectId, integrationId));
1178
1198
  }
1199
+ /** Pro only: read durable synchronization state for an integration. */
1200
+ async getIntegrationSync(projectId, integrationId) {
1201
+ await this.requireTier("pro", "getIntegrationSync");
1202
+ return this.requestJson("GET", `${this.integrationPath(projectId, integrationId)}/sync`);
1203
+ }
1204
+ /** Pro only: enable or disable durable synchronization for an integration. */
1205
+ async setIntegrationSync(projectId, integrationId, body) {
1206
+ await this.requireTier("pro", "setIntegrationSync");
1207
+ await this.requestJson("PUT", `${this.integrationPath(projectId, integrationId)}/sync`, { json: body });
1208
+ }
1179
1209
  /** Pro only: delete an integration (`DELETE .../integrations/{integrationId}`). */
1180
1210
  async deleteIntegration(projectId, integrationId) {
1181
1211
  await this.requireTier("pro", "deleteIntegration");
@@ -1299,6 +1329,10 @@ var XbergClient = class {
1299
1329
  const path = `${this.webhookDeliveriesPath(webhookId)}/${encodePathSegment(deliveryId)}`;
1300
1330
  return this.requestJson("GET", path);
1301
1331
  }
1332
+ async jobScope(scope) {
1333
+ if (scope.projectId !== void 0) await this.requireTier("pro", "projectId");
1334
+ return { project_id: scope.projectId };
1335
+ }
1302
1336
  /** Build `/v1/projects/{projectId}` with the id percent-encoded. */
1303
1337
  projectPath(projectId) {
1304
1338
  return `/v1/projects/${encodePathSegment(projectId)}`;
@@ -1526,21 +1560,7 @@ var XbergClient = class {
1526
1560
  interval = nextBackoffInterval(interval, this.retryBackoff);
1527
1561
  continue;
1528
1562
  }
1529
- try {
1530
- await raiseForStatus(response);
1531
- } catch (error) {
1532
- if (error instanceof RateLimitError && error.retryAfter !== void 0 && attempt < this.retries) {
1533
- attempt += 1;
1534
- await this.sleep(error.retryAfter * 1e3);
1535
- interval = nextBackoffInterval(interval, this.retryBackoff);
1536
- continue;
1537
- }
1538
- throw error;
1539
- }
1540
- throw new XbergError("Unreachable", {
1541
- status: response.status,
1542
- body: null
1543
- });
1563
+ throw await raiseForStatus(response);
1544
1564
  }
1545
1565
  }
1546
1566
  };