@xberg-io/sdk 0.8.0 → 0.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.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.9.0`;
363
363
  const DEFAULT_TIMEOUT_MS = 3e4;
364
364
  const DEFAULT_POLL_INTERVAL_MS = 1e3;
365
365
  const DEFAULT_WAIT_TIMEOUT_MS = 3e5;
@@ -602,6 +602,14 @@ var XbergClient = class {
602
602
  async backendFetchIntegrationDocument(projectId, integrationId, documentId) {
603
603
  return await this.requestBytes("GET", `/v1/projects/${encodePathSegment(projectId)}/integrations/${encodePathSegment(integrationId)}/documents/${encodePathSegment(documentId)}`, { controlPlane: true });
604
604
  }
605
+ /** Enterprise backend `GET /v1/projects/{id}/integrations/{iid}/sync`. */
606
+ async backendGetIntegrationSync(projectId, integrationId) {
607
+ return await this.backendRequest("GET", `/v1/projects/${encodePathSegment(projectId)}/integrations/${encodePathSegment(integrationId)}/sync`);
608
+ }
609
+ /** Enterprise backend `PUT /v1/projects/{id}/integrations/{iid}/sync`. */
610
+ async backendSetIntegrationSync(projectId, integrationId, body) {
611
+ return await this.backendRequest("PUT", `/v1/projects/${encodePathSegment(projectId)}/integrations/${encodePathSegment(integrationId)}/sync`, { json: body });
612
+ }
605
613
  /** Enterprise backend `GET /v1/projects/{id}/invitations`. */
606
614
  async listInvitations(projectId, params = {}) {
607
615
  return await this.backendRequest("GET", `/v1/projects/${encodePathSegment(projectId)}/invitations`, { params: {
@@ -636,6 +644,10 @@ var XbergClient = class {
636
644
  async updateMemberRole(projectId, userId, body) {
637
645
  return await this.backendRequest("PATCH", `/v1/projects/${encodePathSegment(projectId)}/members/${encodePathSegment(userId)}`, { json: body });
638
646
  }
647
+ /** Enterprise backend `PATCH /v1/projects/{id}/members/{user_id}/custom-role`. */
648
+ async assignProjectRole(projectId, userId, body) {
649
+ return await this.backendRequest("PATCH", `/v1/projects/${encodePathSegment(projectId)}/members/${encodePathSegment(userId)}/custom-role`, { json: body });
650
+ }
639
651
  /** Enterprise backend `GET /v1/projects/{id}/rag-config`. */
640
652
  async backendGetRagConfig(projectId) {
641
653
  return await this.backendRequest("GET", `/v1/projects/${encodePathSegment(projectId)}/rag-config`);
@@ -644,10 +656,81 @@ var XbergClient = class {
644
656
  async backendSetRagConfig(projectId, body) {
645
657
  return await this.backendRequest("PUT", `/v1/projects/${encodePathSegment(projectId)}/rag-config`, { json: body });
646
658
  }
659
+ /** Enterprise backend `GET /v1/projects/{id}/roles`. */
660
+ async listProjectRoles(projectId, params = {}) {
661
+ return await this.backendRequest("GET", `/v1/projects/${encodePathSegment(projectId)}/roles`, { params: {
662
+ limit: params.limit,
663
+ offset: params.offset
664
+ } });
665
+ }
666
+ /** Enterprise backend `POST /v1/projects/{id}/roles`. */
667
+ async createProjectRole(projectId, body) {
668
+ return await this.backendRequest("POST", `/v1/projects/${encodePathSegment(projectId)}/roles`, { json: body });
669
+ }
670
+ /** Enterprise backend `GET /v1/projects/{id}/roles/{role_id}`. */
671
+ async getProjectRole(projectId, roleId) {
672
+ return await this.backendRequest("GET", `/v1/projects/${encodePathSegment(projectId)}/roles/${encodePathSegment(roleId)}`);
673
+ }
674
+ /** Enterprise backend `PATCH /v1/projects/{id}/roles/{role_id}`. */
675
+ async updateProjectRole(projectId, roleId, body) {
676
+ return await this.backendRequest("PATCH", `/v1/projects/${encodePathSegment(projectId)}/roles/${encodePathSegment(roleId)}`, { json: body });
677
+ }
678
+ /** Enterprise backend `DELETE /v1/projects/{id}/roles/{role_id}`. */
679
+ async deleteProjectRole(projectId, roleId) {
680
+ return await this.backendRequest("DELETE", `/v1/projects/${encodePathSegment(projectId)}/roles/${encodePathSegment(roleId)}`);
681
+ }
682
+ /** Enterprise backend `GET /v1/projects/{project_id}/saml/domains`. */
683
+ async listSamlDomains(projectId) {
684
+ return await this.backendRequest("GET", `/v1/projects/${encodePathSegment(projectId)}/saml/domains`);
685
+ }
686
+ /** Enterprise backend `POST /v1/projects/{project_id}/saml/domains`. */
687
+ async createSamlDomain(projectId, body) {
688
+ return await this.backendRequest("POST", `/v1/projects/${encodePathSegment(projectId)}/saml/domains`, { json: body });
689
+ }
690
+ /** Enterprise backend `POST /v1/projects/{project_id}/saml/domains/{domain}/verify`. */
691
+ async verifySamlDomain(projectId, domain) {
692
+ return await this.backendRequest("POST", `/v1/projects/${encodePathSegment(projectId)}/saml/domains/${encodePathSegment(domain)}/verify`);
693
+ }
694
+ /** Enterprise backend `GET /v1/projects/{project_id}/saml/providers`. */
695
+ async listSamlProviders(projectId) {
696
+ return await this.backendRequest("GET", `/v1/projects/${encodePathSegment(projectId)}/saml/providers`);
697
+ }
698
+ /** Enterprise backend `POST /v1/projects/{project_id}/saml/providers`. */
699
+ async createSamlProvider(projectId, body) {
700
+ return await this.backendRequest("POST", `/v1/projects/${encodePathSegment(projectId)}/saml/providers`, { json: body });
701
+ }
702
+ /** Enterprise backend `PUT /v1/projects/{project_id}/saml/providers/{provider_id}`. */
703
+ async updateSamlProvider(projectId, providerId, body) {
704
+ return await this.backendRequest("PUT", `/v1/projects/${encodePathSegment(projectId)}/saml/providers/${encodePathSegment(providerId)}`, { json: body });
705
+ }
706
+ /** Enterprise backend `DELETE /v1/projects/{project_id}/saml/providers/{provider_id}`. */
707
+ async deleteSamlProvider(projectId, providerId) {
708
+ return await this.backendRequest("DELETE", `/v1/projects/${encodePathSegment(projectId)}/saml/providers/${encodePathSegment(providerId)}`);
709
+ }
647
710
  /** Enterprise backend `POST /v1/projects/{id}/sandbox/extract`. */
648
711
  async sandboxExtract(projectId, params) {
649
712
  return await this.backendRequest("POST", `/v1/projects/${encodePathSegment(projectId)}/sandbox/extract`, { body: sandboxForm(params) });
650
713
  }
714
+ /** Enterprise backend `GET /v1/projects/{id}/scim/connections`. */
715
+ async listScimConnections(projectId) {
716
+ return await this.backendRequest("GET", `/v1/projects/${encodePathSegment(projectId)}/scim/connections`);
717
+ }
718
+ /** Enterprise backend `POST /v1/projects/{id}/scim/connections`. */
719
+ async createScimConnection(projectId, body) {
720
+ return await this.backendRequest("POST", `/v1/projects/${encodePathSegment(projectId)}/scim/connections`, { json: body });
721
+ }
722
+ /** Enterprise backend `GET /v1/projects/{id}/scim/connections/{connection_id}/groups`. */
723
+ async listScimAdminGroups(projectId, connectionId) {
724
+ return await this.backendRequest("GET", `/v1/projects/${encodePathSegment(projectId)}/scim/connections/${encodePathSegment(connectionId)}/groups`);
725
+ }
726
+ /** Enterprise backend `PUT /v1/projects/{id}/scim/connections/{connection_id}/groups/{group_id}/roles`. */
727
+ async replaceScimGroupRoles(projectId, connectionId, groupId, body) {
728
+ return await this.backendRequest("PUT", `/v1/projects/${encodePathSegment(projectId)}/scim/connections/${encodePathSegment(connectionId)}/groups/${encodePathSegment(groupId)}/roles`, { json: body });
729
+ }
730
+ /** Enterprise backend `POST /v1/projects/{id}/scim/connections/{connection_id}/rotate`. */
731
+ async rotateScimConnectionSecret(projectId, connectionId) {
732
+ return await this.backendRequest("POST", `/v1/projects/${encodePathSegment(projectId)}/scim/connections/${encodePathSegment(connectionId)}/rotate`);
733
+ }
651
734
  /** Enterprise backend `GET /v1/projects/{id}/usage`. */
652
735
  async getUsage(projectId, params) {
653
736
  return await this.backendRequest("GET", `/v1/projects/${encodePathSegment(projectId)}/usage`, { params: {
@@ -708,6 +791,7 @@ var XbergClient = class {
708
791
  async extract(params) {
709
792
  const jobs = await this.extractBatch({
710
793
  files: [params.file],
794
+ ...params.projectId !== void 0 ? { projectId: params.projectId } : {},
711
795
  ...params.documentId !== void 0 ? { documentIds: [params.documentId] } : {},
712
796
  ...params.options !== void 0 ? { options: params.options } : {},
713
797
  ...params.webhook !== void 0 ? { webhook: params.webhook } : {},
@@ -732,6 +816,8 @@ var XbergClient = class {
732
816
  const filenames = params.files.map(describeFile);
733
817
  const documentIds = prepareDocumentLineage(filenames, params.documentIds);
734
818
  if (documentIds.size > 0) await this.requireTier("enterprise", "extract document lineage");
819
+ if (params.projectId !== void 0) await this.requireTier("pro", "projectId");
820
+ const projectHeader = Object.keys(this.headers).find((name) => name.toLowerCase() === "x-project-id") ?? "X-Project-ID";
735
821
  const form = new FormData();
736
822
  for (const [filename, documentId] of documentIds) form.append(`document_id-${filename}`, documentId);
737
823
  const parts = params.files.map(toBlob);
@@ -739,7 +825,10 @@ var XbergClient = class {
739
825
  if (params.options !== void 0) form.append("options", JSON.stringify(params.options));
740
826
  if (params.webhook !== void 0) form.append("webhook", JSON.stringify(params.webhook));
741
827
  appendPerFileConfigs(form, filenames, params.configs);
742
- const body = await this.requestJson("POST", "/v1/extract", { body: form });
828
+ const body = await this.requestJson("POST", "/v1/extract", {
829
+ body: form,
830
+ ...params.projectId !== void 0 ? { headers: { [projectHeader]: params.projectId } } : {}
831
+ });
743
832
  const jobIds = body.job_ids ?? [];
744
833
  const now = (/* @__PURE__ */ new Date()).toISOString();
745
834
  return parts.map(({ blob, filename }, index) => {
@@ -758,8 +847,8 @@ var XbergClient = class {
758
847
  });
759
848
  }
760
849
  /** 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)}`));
850
+ async getJob(jobId, scope = {}) {
851
+ return parseJobResponse(await this.requestJson("GET", `${JOBS_PATH}/${encodePathSegment(jobId)}`, { params: await this.jobScope(scope) }));
763
852
  }
764
853
  /**
765
854
  * Fetch a job's stored result document (`GET /v1/jobs/{id}/result`).
@@ -768,12 +857,13 @@ var XbergClient = class {
768
857
  * extracted documents live in `results`. Distinct from {@link getJob}, which
769
858
  * returns the job's metadata record.
770
859
  */
771
- async getJobResult(jobId) {
772
- return await this.requestJson("GET", `${JOBS_PATH}/${encodePathSegment(jobId)}/result`);
860
+ async getJobResult(jobId, scope = {}) {
861
+ return await this.requestJson("GET", `${JOBS_PATH}/${encodePathSegment(jobId)}/result`, { params: await this.jobScope(scope) });
773
862
  }
774
863
  /** List jobs (paginated) via `GET /v1/jobs`. */
775
864
  async listJobs(params = {}) {
776
865
  return await this.requestJson("GET", JOBS_PATH, { params: {
866
+ ...await this.jobScope(params),
777
867
  limit: params.limit,
778
868
  offset: params.offset
779
869
  } });
@@ -783,8 +873,8 @@ var XbergClient = class {
783
873
  * cancellation and a job that already reached a terminal status answer
784
874
  * `204`.
785
875
  */
786
- async cancelJob(jobId) {
787
- await this.requestJson("DELETE", `${JOBS_PATH}/${encodePathSegment(jobId)}`);
876
+ async cancelJob(jobId, scope = {}) {
877
+ await this.requestJson("DELETE", `${JOBS_PATH}/${encodePathSegment(jobId)}`, { params: await this.jobScope(scope) });
788
878
  }
789
879
  /**
790
880
  * Poll {@link getJob} until the job reaches a terminal status. Throws
@@ -798,7 +888,7 @@ var XbergClient = class {
798
888
  const start = Date.now();
799
889
  let interval = initialInterval;
800
890
  for (;;) {
801
- const job = await this.getJob(jobId);
891
+ const job = await this.getJob(jobId, options);
802
892
  if (job.job_type !== "extraction") throw new ValidationError("expected extraction job, received crawl job", {
803
893
  status: 200,
804
894
  body: job
@@ -828,6 +918,7 @@ var XbergClient = class {
828
918
  async extractAndWait(params) {
829
919
  const extractParams = {
830
920
  file: params.file,
921
+ ...params.projectId !== void 0 ? { projectId: params.projectId } : {},
831
922
  ...params.documentId !== void 0 ? { documentId: params.documentId } : {},
832
923
  ...params.options !== void 0 ? { options: params.options } : {},
833
924
  ...params.webhook !== void 0 ? { webhook: params.webhook } : {},
@@ -835,6 +926,7 @@ var XbergClient = class {
835
926
  };
836
927
  const job = await this.extract(extractParams);
837
928
  const waitOptions = {
929
+ ...params.projectId !== void 0 ? { projectId: params.projectId } : {},
838
930
  ...params.timeoutMs !== void 0 ? { timeoutMs: params.timeoutMs } : {},
839
931
  ...params.pollIntervalMs !== void 0 ? { pollIntervalMs: params.pollIntervalMs } : {},
840
932
  ...params.backoff !== void 0 ? { backoff: params.backoff } : {}
@@ -1041,17 +1133,20 @@ var XbergClient = class {
1041
1133
  * (`GET /v1/jobs/{job_id}/pages/{page_number}`). The response is a PNG image —
1042
1134
  * raw bytes, not JSON. `pageNumber` is 1-indexed.
1043
1135
  */
1044
- async getJobPage(jobId, pageNumber) {
1136
+ async getJobPage(jobId, pageNumber, scope = {}) {
1045
1137
  const path = `${JOBS_PATH}/${encodePathSegment(jobId)}/pages/${encodePathSegment(String(pageNumber))}`;
1046
- return await this.requestBytes("GET", path);
1138
+ return await this.requestBytes("GET", path, { params: await this.jobScope(scope) });
1047
1139
  }
1048
1140
  /** Submit text for enrichment (`POST /v1/enrich`). */
1049
- async submitEnrich(body) {
1050
- return await this.requestJson("POST", ENRICH_PATH, { json: body });
1141
+ async submitEnrich(body, scope = {}) {
1142
+ return await this.requestJson("POST", ENRICH_PATH, {
1143
+ json: body,
1144
+ params: await this.jobScope(scope)
1145
+ });
1051
1146
  }
1052
1147
  /** 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)}`);
1148
+ async getEnrichStatus(jobId, scope = {}) {
1149
+ return await this.requestJson("GET", `${ENRICH_PATH}/${encodePathSegment(jobId)}`, { params: await this.jobScope(scope) });
1055
1150
  }
1056
1151
  /**
1057
1152
  * Stream a crawl job's events (`GET /v1/crawl-jobs/{crawl_job_id}/events`,
@@ -1077,9 +1172,17 @@ var XbergClient = class {
1077
1172
  */
1078
1173
  streamCrawlEvents(crawlJobId, options = {}) {
1079
1174
  const path = `${CRAWL_JOBS_PATH}/${encodePathSegment(crawlJobId)}/events`;
1080
- const open = () => this.openEventStream(path, options.signal);
1175
+ const open = async () => this.openEventStream(`${path}${buildQueryString(await this.jobScope(options))}`, options.signal);
1081
1176
  return { [Symbol.asyncIterator]: () => iterateCrawlEvents(open) };
1082
1177
  }
1178
+ /**
1179
+ * Pro liveness and coarse license/capability state (`GET /healthz`).
1180
+ * Use readiness checks to assess dependencies. ~keep
1181
+ */
1182
+ async proHealthz() {
1183
+ await this.requireTier("pro", "proHealthz");
1184
+ return this.requestJson("GET", "/healthz");
1185
+ }
1083
1186
  /** Pro only: fetch the instance's accepted auth methods (`GET /auth/config`). */
1084
1187
  async authConfig() {
1085
1188
  await this.requireTier("pro", "authConfig");
@@ -1176,6 +1279,16 @@ var XbergClient = class {
1176
1279
  await this.requireTier("pro", "getIntegration");
1177
1280
  return this.requestJson("GET", this.integrationPath(projectId, integrationId));
1178
1281
  }
1282
+ /** Pro only: read durable synchronization state for an integration. */
1283
+ async getIntegrationSync(projectId, integrationId) {
1284
+ await this.requireTier("pro", "getIntegrationSync");
1285
+ return this.requestJson("GET", `${this.integrationPath(projectId, integrationId)}/sync`);
1286
+ }
1287
+ /** Pro only: enable or disable durable synchronization for an integration. */
1288
+ async setIntegrationSync(projectId, integrationId, body) {
1289
+ await this.requireTier("pro", "setIntegrationSync");
1290
+ await this.requestJson("PUT", `${this.integrationPath(projectId, integrationId)}/sync`, { json: body });
1291
+ }
1179
1292
  /** Pro only: delete an integration (`DELETE .../integrations/{integrationId}`). */
1180
1293
  async deleteIntegration(projectId, integrationId) {
1181
1294
  await this.requireTier("pro", "deleteIntegration");
@@ -1299,6 +1412,10 @@ var XbergClient = class {
1299
1412
  const path = `${this.webhookDeliveriesPath(webhookId)}/${encodePathSegment(deliveryId)}`;
1300
1413
  return this.requestJson("GET", path);
1301
1414
  }
1415
+ async jobScope(scope) {
1416
+ if (scope.projectId !== void 0) await this.requireTier("pro", "projectId");
1417
+ return { project_id: scope.projectId };
1418
+ }
1302
1419
  /** Build `/v1/projects/{projectId}` with the id percent-encoded. */
1303
1420
  projectPath(projectId) {
1304
1421
  return `/v1/projects/${encodePathSegment(projectId)}`;
@@ -1526,21 +1643,7 @@ var XbergClient = class {
1526
1643
  interval = nextBackoffInterval(interval, this.retryBackoff);
1527
1644
  continue;
1528
1645
  }
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
- });
1646
+ throw await raiseForStatus(response);
1544
1647
  }
1545
1648
  }
1546
1649
  };