@xberg-io/sdk 0.11.0 → 0.13.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/README.md +2 -2
- package/dist/index.d.ts +3219 -1753
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +110 -31
- package/dist/index.js.map +1 -1
- package/package.json +6 -6
package/dist/index.js
CHANGED
|
@@ -473,7 +473,7 @@ const SUCCESS_JOB_STATUSES = ["completed", "partial_success"];
|
|
|
473
473
|
* and defaults to `baseUrl`. The backend methods use that origin and an optional
|
|
474
474
|
* separate `controlPlaneToken`; existing Pro methods retain their data-plane routing.
|
|
475
475
|
*/
|
|
476
|
-
const USER_AGENT = `xberg-io-sdk-typescript/0.
|
|
476
|
+
const USER_AGENT = `xberg-io-sdk-typescript/0.13.0`;
|
|
477
477
|
const DEFAULT_TIMEOUT_MS = 3e4;
|
|
478
478
|
const DEFAULT_POLL_INTERVAL_MS = 1e3;
|
|
479
479
|
const DEFAULT_WAIT_TIMEOUT_MS = 3e5;
|
|
@@ -672,6 +672,10 @@ var XbergClient = class {
|
|
|
672
672
|
async backendCreateApiKey(projectId, body) {
|
|
673
673
|
return await this.backendRequest("POST", `/v1/projects/${encodePathSegment(projectId)}/api-keys`, { json: body });
|
|
674
674
|
}
|
|
675
|
+
/** Enterprise backend: issue an API key restricted to a custom project role. */
|
|
676
|
+
async backendCreateRoleBoundApiKey(projectId, body) {
|
|
677
|
+
return await this.backendRequest("POST", `${this.projectPath(projectId)}/api-keys/role-bound`, { json: body });
|
|
678
|
+
}
|
|
675
679
|
/** Enterprise backend `DELETE /v1/projects/{id}/api-keys/{key_id}`. */
|
|
676
680
|
async backendRevokeApiKey(projectId, apiKeyId) {
|
|
677
681
|
return await this.backendRequest("DELETE", `/v1/projects/${encodePathSegment(projectId)}/api-keys/${encodePathSegment(apiKeyId)}`);
|
|
@@ -688,18 +692,6 @@ var XbergClient = class {
|
|
|
688
692
|
offset: params.offset
|
|
689
693
|
} });
|
|
690
694
|
}
|
|
691
|
-
/** Enterprise backend `GET /v1/projects/{id}/billing`. */
|
|
692
|
-
async getBilling(projectId) {
|
|
693
|
-
return await this.backendRequest("GET", `/v1/projects/${encodePathSegment(projectId)}/billing`);
|
|
694
|
-
}
|
|
695
|
-
/** Enterprise backend `POST /v1/projects/{id}/billing/checkout`. */
|
|
696
|
-
async createCheckout(projectId) {
|
|
697
|
-
return await this.backendRequest("POST", `/v1/projects/${encodePathSegment(projectId)}/billing/checkout`);
|
|
698
|
-
}
|
|
699
|
-
/** Enterprise backend `POST /v1/projects/{id}/billing/portal`. */
|
|
700
|
-
async createPortal(projectId) {
|
|
701
|
-
return await this.backendRequest("POST", `/v1/projects/${encodePathSegment(projectId)}/billing/portal`);
|
|
702
|
-
}
|
|
703
695
|
/** Enterprise backend `GET /v1/projects/{id}/integrations`. */
|
|
704
696
|
async backendListIntegrations(projectId, params = {}) {
|
|
705
697
|
return await this.backendRequest("GET", `/v1/projects/${encodePathSegment(projectId)}/integrations`, { params: {
|
|
@@ -839,11 +831,23 @@ var XbergClient = class {
|
|
|
839
831
|
}
|
|
840
832
|
/** Enterprise backend `PUT /v1/projects/{project_id}/saml/providers/{provider_id}`. */
|
|
841
833
|
async updateSamlProvider(projectId, providerId, body) {
|
|
842
|
-
return await this.backendRequest("PUT",
|
|
834
|
+
return await this.backendRequest("PUT", this.samlProviderPath(projectId, providerId), { json: body });
|
|
835
|
+
}
|
|
836
|
+
/** Enterprise backend: replace a SAML provider's attribute mapping. */
|
|
837
|
+
async updateSamlAttributeMapping(projectId, providerId, body) {
|
|
838
|
+
return await this.backendRequest("PATCH", `${this.samlProviderPath(projectId, providerId)}/attribute-mapping`, { json: body });
|
|
839
|
+
}
|
|
840
|
+
/** Enterprise backend: start a SAML test and return its browser redirect. */
|
|
841
|
+
async startSamlConnectionTest(projectId, providerId) {
|
|
842
|
+
return await this.backendRequest("POST", `${this.samlProviderPath(projectId, providerId)}/test`);
|
|
843
|
+
}
|
|
844
|
+
/** Enterprise backend: check the status of a SAML connection test. */
|
|
845
|
+
async getSamlConnectionTestStatus(projectId, providerId, testId) {
|
|
846
|
+
return await this.backendRequest("GET", `${this.samlProviderPath(projectId, providerId)}/test/${encodePathSegment(testId)}`);
|
|
843
847
|
}
|
|
844
848
|
/** Enterprise backend `DELETE /v1/projects/{project_id}/saml/providers/{provider_id}`. */
|
|
845
849
|
async deleteSamlProvider(projectId, providerId) {
|
|
846
|
-
return await this.backendRequest("DELETE",
|
|
850
|
+
return await this.backendRequest("DELETE", this.samlProviderPath(projectId, providerId));
|
|
847
851
|
}
|
|
848
852
|
/** Enterprise backend `POST /v1/projects/{id}/sandbox/extract`. */
|
|
849
853
|
async sandboxExtract(projectId, params) {
|
|
@@ -869,6 +873,10 @@ var XbergClient = class {
|
|
|
869
873
|
async rotateScimConnectionSecret(projectId, connectionId) {
|
|
870
874
|
return await this.backendRequest("POST", `/v1/projects/${encodePathSegment(projectId)}/scim/connections/${encodePathSegment(connectionId)}/rotate`);
|
|
871
875
|
}
|
|
876
|
+
/** Enterprise backend: revoke a SCIM connection. */
|
|
877
|
+
async revokeScimConnection(projectId, connectionId) {
|
|
878
|
+
return await this.backendRequest("POST", `${this.projectPath(projectId)}/scim/connections/${encodePathSegment(connectionId)}/revoke`);
|
|
879
|
+
}
|
|
872
880
|
/** Enterprise backend `GET /v1/projects/{id}/usage`. */
|
|
873
881
|
async getUsage(projectId, params) {
|
|
874
882
|
return await this.backendRequest("GET", `/v1/projects/${encodePathSegment(projectId)}/usage`, { params: {
|
|
@@ -963,26 +971,40 @@ var XbergClient = class {
|
|
|
963
971
|
if (params.options !== void 0) form.append("options", JSON.stringify(params.options));
|
|
964
972
|
if (params.webhook !== void 0) form.append("webhook", JSON.stringify(params.webhook));
|
|
965
973
|
appendPerFileConfigs(form, filenames, params.configs);
|
|
966
|
-
|
|
974
|
+
return pendingJobs(parts, await this.requestJson("POST", "/v1/extract", {
|
|
967
975
|
body: form,
|
|
968
976
|
...params.projectId !== void 0 ? { headers: { [projectHeader]: params.projectId } } : {}
|
|
977
|
+
}));
|
|
978
|
+
}
|
|
979
|
+
/**
|
|
980
|
+
* Submit one retryable inline batch to Pro's `POST /v1/extract/keyed`.
|
|
981
|
+
*
|
|
982
|
+
* Sends every file in a single multipart request with `idempotencyKey` as the
|
|
983
|
+
* `Idempotency-Key` header. Webhooks and document lineage are not accepted on
|
|
984
|
+
* this route. Returns one {@link Job} per file, in the same order.
|
|
985
|
+
*/
|
|
986
|
+
async extractKeyed(params) {
|
|
987
|
+
if (params.idempotencyKey.trim().length === 0) throw new ValidationError("extractKeyed requires a non-blank idempotencyKey", {
|
|
988
|
+
status: 0,
|
|
989
|
+
body: null
|
|
969
990
|
});
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
const id = jobIds[index];
|
|
974
|
-
if (id === void 0) throw new XbergError(`Server returned ${jobIds.length} job IDs for ${params.files.length} files`, {
|
|
975
|
-
status: 500,
|
|
976
|
-
body
|
|
977
|
-
});
|
|
978
|
-
return {
|
|
979
|
-
id,
|
|
980
|
-
filename,
|
|
981
|
-
mime_type: blob.type.length > 0 ? blob.type : OCTET_STREAM_MEDIA_TYPE,
|
|
982
|
-
status: "pending",
|
|
983
|
-
created_at: now
|
|
984
|
-
};
|
|
991
|
+
if (params.files.length === 0) throw new XbergError("extractKeyed called with no files", {
|
|
992
|
+
status: 400,
|
|
993
|
+
body: null
|
|
985
994
|
});
|
|
995
|
+
const filenames = params.files.map(describeFile);
|
|
996
|
+
await this.requireTier("pro", "extractKeyed");
|
|
997
|
+
const form = new FormData();
|
|
998
|
+
const parts = params.files.map(toBlob);
|
|
999
|
+
for (const { blob, filename } of parts) form.append("file", blob, filename);
|
|
1000
|
+
if (params.options !== void 0) form.append("options", JSON.stringify(params.options));
|
|
1001
|
+
appendPerFileConfigs(form, filenames, params.configs);
|
|
1002
|
+
const headers = { "Idempotency-Key": params.idempotencyKey };
|
|
1003
|
+
if (params.projectId !== void 0) headers[this.projectHeaderName()] = params.projectId;
|
|
1004
|
+
return pendingJobs(parts, await this.requestJson("POST", "/v1/extract/keyed", {
|
|
1005
|
+
body: form,
|
|
1006
|
+
headers
|
|
1007
|
+
}));
|
|
986
1008
|
}
|
|
987
1009
|
/** Fetch a tagged extraction or crawl job record (`GET /v1/jobs/{id}`). */
|
|
988
1010
|
async getJob(jobId, scope = {}) {
|
|
@@ -1112,6 +1134,18 @@ var XbergClient = class {
|
|
|
1112
1134
|
async deleteRagCollection(name) {
|
|
1113
1135
|
await this.requestJson("DELETE", `/v1/rag/collections/${encodePathSegment(name)}`);
|
|
1114
1136
|
}
|
|
1137
|
+
/** List the documents in a RAG collection, using the returned cursor for the next page. */
|
|
1138
|
+
async listRagDocuments(name, params = {}) {
|
|
1139
|
+
const { limit, cursor, projectId } = params;
|
|
1140
|
+
if (projectId !== void 0) await this.requireTier("pro", "projectId");
|
|
1141
|
+
return await this.requestJson("GET", `/v1/rag/collections/${encodePathSegment(name)}/documents`, {
|
|
1142
|
+
params: {
|
|
1143
|
+
limit,
|
|
1144
|
+
cursor
|
|
1145
|
+
},
|
|
1146
|
+
...projectId !== void 0 ? { headers: { [this.projectHeaderName()]: projectId } } : {}
|
|
1147
|
+
});
|
|
1148
|
+
}
|
|
1115
1149
|
/** Add documents to a RAG collection (`POST /v1/rag/collections/{name}/documents`). */
|
|
1116
1150
|
async addRagDocuments(name, body) {
|
|
1117
1151
|
return await this.requestJson("POST", `/v1/rag/collections/${encodePathSegment(name)}/documents`, { json: body });
|
|
@@ -1275,6 +1309,11 @@ var XbergClient = class {
|
|
|
1275
1309
|
const path = `${JOBS_PATH}/${encodePathSegment(jobId)}/pages/${encodePathSegment(String(pageNumber))}`;
|
|
1276
1310
|
return await this.requestBytes("GET", path, { params: await this.jobScope(scope) });
|
|
1277
1311
|
}
|
|
1312
|
+
/** Pro only: list the available rendered page numbers for an extraction job. */
|
|
1313
|
+
async getJobPageInventory(jobId, scope = {}) {
|
|
1314
|
+
await this.requireTier("pro", "getJobPageInventory");
|
|
1315
|
+
return await this.requestJson("GET", `${JOBS_PATH}/${encodePathSegment(jobId)}/pages`, { params: { project_id: scope.projectId } });
|
|
1316
|
+
}
|
|
1278
1317
|
/** Submit text for enrichment (`POST /v1/enrich`). */
|
|
1279
1318
|
async submitEnrich(body, scope = {}) {
|
|
1280
1319
|
return await this.requestJson("POST", ENRICH_PATH, {
|
|
@@ -1472,6 +1511,11 @@ var XbergClient = class {
|
|
|
1472
1511
|
await this.requireTier("pro", "setIntegrationSync");
|
|
1473
1512
|
await this.requestJson("PUT", `${this.integrationPath(projectId, integrationId)}/sync`, { json: body });
|
|
1474
1513
|
}
|
|
1514
|
+
/** Pro only: permanently bind an integration to a RAG collection in the same project. */
|
|
1515
|
+
async bindIntegrationRagTarget(projectId, integrationId, body) {
|
|
1516
|
+
await this.requireTier("pro", "bindIntegrationRagTarget");
|
|
1517
|
+
await this.requestJson("PUT", `${this.integrationPath(projectId, integrationId)}/sync/rag-target`, { json: body });
|
|
1518
|
+
}
|
|
1475
1519
|
/** Pro only: delete an integration (`DELETE .../integrations/{integrationId}`). */
|
|
1476
1520
|
async deleteIntegration(projectId, integrationId) {
|
|
1477
1521
|
await this.requireTier("pro", "deleteIntegration");
|
|
@@ -1799,6 +1843,14 @@ var XbergClient = class {
|
|
|
1799
1843
|
offset: params.offset
|
|
1800
1844
|
} });
|
|
1801
1845
|
}
|
|
1846
|
+
/** Enterprise only: update link access using the room's last observed version. */
|
|
1847
|
+
async setRoomLinkAccess(roomId, body, version) {
|
|
1848
|
+
await this.requireTier("enterprise", "setRoomLinkAccess");
|
|
1849
|
+
return this.requestJson("PUT", `${this.roomPath(roomId)}/links`, {
|
|
1850
|
+
json: body,
|
|
1851
|
+
headers: ifMatch(version)
|
|
1852
|
+
});
|
|
1853
|
+
}
|
|
1802
1854
|
/** Enterprise only: create a share link for a data room. */
|
|
1803
1855
|
async createRoomLink(roomId, body) {
|
|
1804
1856
|
await this.requireTier("enterprise", "createRoomLink");
|
|
@@ -1959,6 +2011,9 @@ var XbergClient = class {
|
|
|
1959
2011
|
integrationPath(projectId, integrationId) {
|
|
1960
2012
|
return `${this.projectPath(projectId)}/integrations/${encodePathSegment(integrationId)}`;
|
|
1961
2013
|
}
|
|
2014
|
+
samlProviderPath(projectId, providerId) {
|
|
2015
|
+
return `${this.projectPath(projectId)}/saml/providers/${encodePathSegment(providerId)}`;
|
|
2016
|
+
}
|
|
1962
2017
|
/** Build `/v1/documents/{documentId}` with the id percent-encoded. */
|
|
1963
2018
|
documentPath(documentId) {
|
|
1964
2019
|
return `${DOCUMENTS_PATH}/${encodePathSegment(documentId)}`;
|
|
@@ -2226,6 +2281,30 @@ var XbergClient = class {
|
|
|
2226
2281
|
}
|
|
2227
2282
|
}
|
|
2228
2283
|
};
|
|
2284
|
+
/**
|
|
2285
|
+
* Build the pending {@link Job} records for an extraction submission.
|
|
2286
|
+
*
|
|
2287
|
+
* Both extraction routes answer with job IDs alone, so the rest of each record is
|
|
2288
|
+
* synthesized from what was submitted; `mime_type` is the type the file was uploaded under.
|
|
2289
|
+
*/
|
|
2290
|
+
function pendingJobs(parts, body) {
|
|
2291
|
+
const jobIds = body.job_ids ?? [];
|
|
2292
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
2293
|
+
return parts.map(({ blob, filename }, index) => {
|
|
2294
|
+
const id = jobIds[index];
|
|
2295
|
+
if (id === void 0) throw new XbergError(`Server returned ${jobIds.length} job IDs for ${parts.length} files`, {
|
|
2296
|
+
status: 500,
|
|
2297
|
+
body
|
|
2298
|
+
});
|
|
2299
|
+
return {
|
|
2300
|
+
id,
|
|
2301
|
+
filename,
|
|
2302
|
+
mime_type: blob.type.length > 0 ? blob.type : OCTET_STREAM_MEDIA_TYPE,
|
|
2303
|
+
status: "pending",
|
|
2304
|
+
created_at: now
|
|
2305
|
+
};
|
|
2306
|
+
});
|
|
2307
|
+
}
|
|
2229
2308
|
/** The `If-Match` header a room write sends: the room version, quoted as an entity tag. */
|
|
2230
2309
|
function ifMatch(version) {
|
|
2231
2310
|
if (!Number.isSafeInteger(version) || version < 0) throw new ValidationError(`Room version must be a non-negative integer, got ${String(version)}`, {
|