@xberg-io/sdk 0.4.0 → 0.6.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 +15 -10
- package/dist/index.d.ts +16792 -8280
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +559 -147
- package/dist/index.js.map +1 -1
- package/package.json +7 -7
package/dist/index.js
CHANGED
|
@@ -194,7 +194,7 @@ function toBlob(file) {
|
|
|
194
194
|
filename: "upload.bin"
|
|
195
195
|
};
|
|
196
196
|
if (file instanceof Uint8Array) return {
|
|
197
|
-
blob: new Blob([
|
|
197
|
+
blob: new Blob([blobBytes(file)], { type: "application/octet-stream" }),
|
|
198
198
|
filename: "upload.bin"
|
|
199
199
|
};
|
|
200
200
|
const wrapper = file;
|
|
@@ -205,10 +205,13 @@ function toBlob(file) {
|
|
|
205
205
|
filename: name
|
|
206
206
|
};
|
|
207
207
|
return {
|
|
208
|
-
blob: new Blob([
|
|
208
|
+
blob: new Blob([blobBytes(wrapper.data)], { type: mimeType }),
|
|
209
209
|
filename: name
|
|
210
210
|
};
|
|
211
211
|
}
|
|
212
|
+
function blobBytes(bytes) {
|
|
213
|
+
return bytes.buffer instanceof ArrayBuffer ? new Uint8Array(bytes.buffer, bytes.byteOffset, bytes.byteLength) : new Uint8Array(bytes);
|
|
214
|
+
}
|
|
212
215
|
function guessMimeType(filename) {
|
|
213
216
|
const lower = filename.toLowerCase();
|
|
214
217
|
if (lower.endsWith(".csv")) return "text/csv";
|
|
@@ -314,6 +317,14 @@ var EventStreamDecoder = class {
|
|
|
314
317
|
return payload;
|
|
315
318
|
}
|
|
316
319
|
};
|
|
320
|
+
/** Encode a path identifier without allowing the HTTP client to change its route. */
|
|
321
|
+
function encodePathSegment(value) {
|
|
322
|
+
if (value === "." || value === "..") throw new XbergError("Path identifiers must not be '.' or '..'", {
|
|
323
|
+
status: 400,
|
|
324
|
+
body: null
|
|
325
|
+
});
|
|
326
|
+
return encodeURIComponent(value);
|
|
327
|
+
}
|
|
317
328
|
|
|
318
329
|
//#endregion
|
|
319
330
|
//#region src/types.ts
|
|
@@ -339,7 +350,7 @@ const SUCCESS_JOB_STATUSES = ["completed", "partial_success"];
|
|
|
339
350
|
* Package version, synced from the repo-root `VERSION` file by
|
|
340
351
|
* `scripts/sync-versions.py`. Used to build the `User-Agent` header. ~keep
|
|
341
352
|
*/
|
|
342
|
-
const VERSION = "0.
|
|
353
|
+
const VERSION = "0.6.0";
|
|
343
354
|
|
|
344
355
|
//#endregion
|
|
345
356
|
//#region src/client.ts
|
|
@@ -360,8 +371,8 @@ const VERSION = "0.4.0";
|
|
|
360
371
|
* Enterprise splits into two binaries — the data plane `baseUrl` addresses and a
|
|
361
372
|
* control plane (projects, API keys, integrations) on its own origin — while Pro
|
|
362
373
|
* serves both from one. `controlPlaneBaseUrl` records the origin of the second
|
|
363
|
-
* and defaults to `baseUrl
|
|
364
|
-
*
|
|
374
|
+
* and defaults to `baseUrl`. The backend methods use that origin and an optional
|
|
375
|
+
* separate `controlPlaneToken`; existing Pro methods retain their data-plane routing.
|
|
365
376
|
*/
|
|
366
377
|
const USER_AGENT = `xberg-io-sdk-typescript/${VERSION}`;
|
|
367
378
|
const DEFAULT_TIMEOUT_MS = 3e4;
|
|
@@ -375,12 +386,10 @@ const DEFAULT_RETRY_STATUSES = [
|
|
|
375
386
|
];
|
|
376
387
|
const DEFAULT_RETRY_BACKOFF_BASE_MS = 200;
|
|
377
388
|
/**
|
|
378
|
-
*
|
|
379
|
-
*
|
|
380
|
-
* (hyphen). The request and response schemas are identical.
|
|
389
|
+
* ~keep `saved-presets` is an OpenAPI *tag* name, not a route: both specs serve
|
|
390
|
+
* `/v1/saved_presets`, so there is no per-tier spelling to select between.
|
|
381
391
|
*/
|
|
382
|
-
const
|
|
383
|
-
const SAVED_PRESETS_PATH_PRO = "/v1/saved-presets";
|
|
392
|
+
const SAVED_PRESETS_PATH = "/v1/saved_presets";
|
|
384
393
|
const AUTO_TUNE_PATH = "/v1/auto-tune";
|
|
385
394
|
const TUNING_PROFILES_PATH = "/v1/tuning-profiles";
|
|
386
395
|
const ENRICH_PATH = "/v1/enrich";
|
|
@@ -388,6 +397,9 @@ const EXTRACTIONS_PATH = "/v1/extractions";
|
|
|
388
397
|
const DOCUMENTS_PATH = "/v1/documents";
|
|
389
398
|
const JOBS_PATH = "/v1/jobs";
|
|
390
399
|
const CRAWL_JOBS_PATH = "/v1/crawl-jobs";
|
|
400
|
+
const WEBHOOKS_PATH = "/v1/webhooks";
|
|
401
|
+
/** Media type of a raw upload body, and the fallback when a submitted file declares none. */
|
|
402
|
+
const OCTET_STREAM_MEDIA_TYPE = "application/octet-stream";
|
|
391
403
|
/** Media type of the crawl-event stream, sent as `Accept` and served as `Content-Type`. */
|
|
392
404
|
const EVENT_STREAM_MEDIA_TYPE = "text/event-stream";
|
|
393
405
|
/** The `kind` values `CrawlEventV1` declares. A frame carrying anything else is rejected. */
|
|
@@ -403,11 +415,10 @@ const CRAWL_EVENT_KINDS = new Set([
|
|
|
403
415
|
var XbergClient = class {
|
|
404
416
|
baseUrl;
|
|
405
417
|
/**
|
|
406
|
-
* Origin
|
|
407
|
-
* unless overridden. No request is routed there yet — see
|
|
408
|
-
* {@link XbergClientOptions.controlPlaneBaseUrl}.
|
|
418
|
+
* Origin used by the Enterprise backend methods. Defaults to `baseUrl`.
|
|
409
419
|
*/
|
|
410
420
|
controlPlaneBaseUrl;
|
|
421
|
+
controlPlaneToken;
|
|
411
422
|
headers;
|
|
412
423
|
fetchImpl;
|
|
413
424
|
timeoutMs;
|
|
@@ -425,6 +436,7 @@ var XbergClient = class {
|
|
|
425
436
|
if (options.target !== void 0) this.target = options.target;
|
|
426
437
|
this.baseUrl = resolveBaseUrl(options.baseUrl, options.target);
|
|
427
438
|
this.controlPlaneBaseUrl = resolveControlPlaneBaseUrl(options.controlPlaneBaseUrl, this.baseUrl);
|
|
439
|
+
this.controlPlaneToken = options.controlPlaneToken ?? options.apiKey;
|
|
428
440
|
this.fetchImpl = options.fetch ?? fetch;
|
|
429
441
|
this.timeoutMs = options.timeoutMs ?? DEFAULT_TIMEOUT_MS;
|
|
430
442
|
this.retries = options.retries ?? 0;
|
|
@@ -442,6 +454,260 @@ var XbergClient = class {
|
|
|
442
454
|
fetch: this.fetchImpl
|
|
443
455
|
});
|
|
444
456
|
}
|
|
457
|
+
/** Enterprise backend `DELETE /auth/account`. */
|
|
458
|
+
async deleteAccount() {
|
|
459
|
+
return await this.backendRequest("DELETE", `/auth/account`);
|
|
460
|
+
}
|
|
461
|
+
/** Enterprise backend `GET /auth/config`. */
|
|
462
|
+
async getAuthConfig() {
|
|
463
|
+
return await this.backendRequest("GET", `/auth/config`, { backendPublic: true });
|
|
464
|
+
}
|
|
465
|
+
/** Enterprise backend `POST /auth/login`. */
|
|
466
|
+
async backendLogin(body) {
|
|
467
|
+
return await this.backendRequest("POST", `/auth/login`, {
|
|
468
|
+
json: body,
|
|
469
|
+
backendPublic: true
|
|
470
|
+
});
|
|
471
|
+
}
|
|
472
|
+
/** Enterprise backend `GET /healthz`. */
|
|
473
|
+
async healthz() {
|
|
474
|
+
return await this.backendRequest("GET", `/healthz`, { backendPublic: true });
|
|
475
|
+
}
|
|
476
|
+
/** Enterprise backend `GET /readyz`. */
|
|
477
|
+
async readyz() {
|
|
478
|
+
return await this.backendRequest("GET", `/readyz`, { backendPublic: true });
|
|
479
|
+
}
|
|
480
|
+
/** Enterprise backend `POST /v1/invitations/accept`. */
|
|
481
|
+
async acceptInvitation(body) {
|
|
482
|
+
return await this.backendRequest("POST", `/v1/invitations/accept`, { json: body });
|
|
483
|
+
}
|
|
484
|
+
/** Enterprise backend `GET /v1/oauth/callback`. */
|
|
485
|
+
async oauthCallback(params) {
|
|
486
|
+
const response = await this.requestWithRetry("GET", "/v1/oauth/callback", {
|
|
487
|
+
controlPlane: true,
|
|
488
|
+
backendPublic: true,
|
|
489
|
+
acceptRedirect: true,
|
|
490
|
+
params: {
|
|
491
|
+
code: params.code,
|
|
492
|
+
state: params.state
|
|
493
|
+
}
|
|
494
|
+
});
|
|
495
|
+
const location = response.headers.get("location");
|
|
496
|
+
await response.body?.cancel();
|
|
497
|
+
if (response.status !== 303 || location === null || location.length === 0) throw new XbergError("OAuth callback did not return a 303 Location", {
|
|
498
|
+
status: response.status,
|
|
499
|
+
body: null
|
|
500
|
+
});
|
|
501
|
+
return location;
|
|
502
|
+
}
|
|
503
|
+
/** Enterprise backend `GET /v1/projects`. */
|
|
504
|
+
async backendListProjects(params = {}) {
|
|
505
|
+
return await this.backendRequest("GET", `/v1/projects`, { params: {
|
|
506
|
+
limit: params.limit,
|
|
507
|
+
offset: params.offset
|
|
508
|
+
} });
|
|
509
|
+
}
|
|
510
|
+
/** Enterprise backend `POST /v1/projects`. */
|
|
511
|
+
async backendCreateProject(body) {
|
|
512
|
+
return await this.backendRequest("POST", `/v1/projects`, { json: body });
|
|
513
|
+
}
|
|
514
|
+
/** Enterprise backend `GET /v1/projects/{id}`. */
|
|
515
|
+
async getProject(projectId) {
|
|
516
|
+
return await this.backendRequest("GET", `/v1/projects/${encodePathSegment(projectId)}`);
|
|
517
|
+
}
|
|
518
|
+
/** Enterprise backend `DELETE /v1/projects/{id}`. */
|
|
519
|
+
async deleteProject(projectId, params = {}) {
|
|
520
|
+
return await this.backendRequest("DELETE", `/v1/projects/${encodePathSegment(projectId)}`, { params: { erase: params.erase === void 0 ? void 0 : String(params.erase) } });
|
|
521
|
+
}
|
|
522
|
+
/** Enterprise backend `PATCH /v1/projects/{id}`. */
|
|
523
|
+
async updateProject(projectId, body) {
|
|
524
|
+
return await this.backendRequest("PATCH", `/v1/projects/${encodePathSegment(projectId)}`, { json: body });
|
|
525
|
+
}
|
|
526
|
+
/** Enterprise backend `GET /v1/projects/{id}/analytics`. */
|
|
527
|
+
async getAnalytics(projectId, params) {
|
|
528
|
+
return await this.backendRequest("GET", `/v1/projects/${encodePathSegment(projectId)}/analytics`, { params: {
|
|
529
|
+
start_date: params.startDate,
|
|
530
|
+
end_date: params.endDate
|
|
531
|
+
} });
|
|
532
|
+
}
|
|
533
|
+
/** Enterprise backend `GET /v1/projects/{id}/api-keys`. */
|
|
534
|
+
async backendListApiKeys(projectId, params = {}) {
|
|
535
|
+
return await this.backendRequest("GET", `/v1/projects/${encodePathSegment(projectId)}/api-keys`, { params: {
|
|
536
|
+
limit: params.limit,
|
|
537
|
+
offset: params.offset
|
|
538
|
+
} });
|
|
539
|
+
}
|
|
540
|
+
/** Enterprise backend `POST /v1/projects/{id}/api-keys`. */
|
|
541
|
+
async backendCreateApiKey(projectId, body) {
|
|
542
|
+
return await this.backendRequest("POST", `/v1/projects/${encodePathSegment(projectId)}/api-keys`, { json: body });
|
|
543
|
+
}
|
|
544
|
+
/** Enterprise backend `DELETE /v1/projects/{id}/api-keys/{key_id}`. */
|
|
545
|
+
async backendRevokeApiKey(projectId, apiKeyId) {
|
|
546
|
+
return await this.backendRequest("DELETE", `/v1/projects/${encodePathSegment(projectId)}/api-keys/${encodePathSegment(apiKeyId)}`);
|
|
547
|
+
}
|
|
548
|
+
/** Enterprise backend `POST /v1/projects/{id}/api-keys/{key_id}/regenerate`. */
|
|
549
|
+
async regenerateApiKey(projectId, apiKeyId) {
|
|
550
|
+
return await this.backendRequest("POST", `/v1/projects/${encodePathSegment(projectId)}/api-keys/${encodePathSegment(apiKeyId)}/regenerate`);
|
|
551
|
+
}
|
|
552
|
+
/** Enterprise backend `GET /v1/projects/{id}/audit`. */
|
|
553
|
+
async listProjectAudit(projectId, params = {}) {
|
|
554
|
+
return await this.backendRequest("GET", `/v1/projects/${encodePathSegment(projectId)}/audit`, { params: {
|
|
555
|
+
action: params.action,
|
|
556
|
+
limit: params.limit,
|
|
557
|
+
offset: params.offset
|
|
558
|
+
} });
|
|
559
|
+
}
|
|
560
|
+
/** Enterprise backend `GET /v1/projects/{id}/billing`. */
|
|
561
|
+
async getBilling(projectId) {
|
|
562
|
+
return await this.backendRequest("GET", `/v1/projects/${encodePathSegment(projectId)}/billing`);
|
|
563
|
+
}
|
|
564
|
+
/** Enterprise backend `POST /v1/projects/{id}/billing/checkout`. */
|
|
565
|
+
async createCheckout(projectId) {
|
|
566
|
+
return await this.backendRequest("POST", `/v1/projects/${encodePathSegment(projectId)}/billing/checkout`);
|
|
567
|
+
}
|
|
568
|
+
/** Enterprise backend `POST /v1/projects/{id}/billing/portal`. */
|
|
569
|
+
async createPortal(projectId) {
|
|
570
|
+
return await this.backendRequest("POST", `/v1/projects/${encodePathSegment(projectId)}/billing/portal`);
|
|
571
|
+
}
|
|
572
|
+
/** Enterprise backend `GET /v1/projects/{id}/integrations`. */
|
|
573
|
+
async backendListIntegrations(projectId, params = {}) {
|
|
574
|
+
return await this.backendRequest("GET", `/v1/projects/${encodePathSegment(projectId)}/integrations`, { params: {
|
|
575
|
+
limit: params.limit,
|
|
576
|
+
offset: params.offset
|
|
577
|
+
} });
|
|
578
|
+
}
|
|
579
|
+
/** Enterprise backend `POST /v1/projects/{id}/integrations`. */
|
|
580
|
+
async backendCreateIntegration(projectId, body) {
|
|
581
|
+
return await this.backendRequest("POST", `/v1/projects/${encodePathSegment(projectId)}/integrations`, { json: body });
|
|
582
|
+
}
|
|
583
|
+
/** Enterprise backend `GET /v1/projects/{id}/integrations/{iid}`. */
|
|
584
|
+
async backendGetIntegration(projectId, integrationId) {
|
|
585
|
+
return await this.backendRequest("GET", `/v1/projects/${encodePathSegment(projectId)}/integrations/${encodePathSegment(integrationId)}`);
|
|
586
|
+
}
|
|
587
|
+
/** Enterprise backend `DELETE /v1/projects/{id}/integrations/{iid}`. */
|
|
588
|
+
async backendDeleteIntegration(projectId, integrationId) {
|
|
589
|
+
return await this.backendRequest("DELETE", `/v1/projects/${encodePathSegment(projectId)}/integrations/${encodePathSegment(integrationId)}`);
|
|
590
|
+
}
|
|
591
|
+
/** Enterprise backend `POST /v1/projects/{id}/integrations/{iid}/connect`. */
|
|
592
|
+
async oauthConnect(projectId, integrationId) {
|
|
593
|
+
return await this.backendRequest("POST", `/v1/projects/${encodePathSegment(projectId)}/integrations/${encodePathSegment(integrationId)}/connect`);
|
|
594
|
+
}
|
|
595
|
+
/** Enterprise backend `POST /v1/projects/{id}/integrations/{iid}/disconnect`. */
|
|
596
|
+
async backendDisconnectIntegration(projectId, integrationId) {
|
|
597
|
+
return await this.backendRequest("POST", `/v1/projects/${encodePathSegment(projectId)}/integrations/${encodePathSegment(integrationId)}/disconnect`);
|
|
598
|
+
}
|
|
599
|
+
/** Enterprise backend `GET /v1/projects/{id}/integrations/{iid}/documents`. */
|
|
600
|
+
async backendListIntegrationDocuments(projectId, integrationId, params = {}) {
|
|
601
|
+
return await this.backendRequest("GET", `/v1/projects/${encodePathSegment(projectId)}/integrations/${encodePathSegment(integrationId)}/documents`, { params: {
|
|
602
|
+
mime_types: params.mimeTypes,
|
|
603
|
+
folder_id: params.folderId,
|
|
604
|
+
limit: params.limit,
|
|
605
|
+
offset: params.offset
|
|
606
|
+
} });
|
|
607
|
+
}
|
|
608
|
+
/** Enterprise backend `GET /v1/projects/{id}/integrations/{iid}/documents/{doc_id}`. */
|
|
609
|
+
async backendFetchIntegrationDocument(projectId, integrationId, documentId) {
|
|
610
|
+
return await this.requestBytes("GET", `/v1/projects/${encodePathSegment(projectId)}/integrations/${encodePathSegment(integrationId)}/documents/${encodePathSegment(documentId)}`, { controlPlane: true });
|
|
611
|
+
}
|
|
612
|
+
/** Enterprise backend `GET /v1/projects/{id}/invitations`. */
|
|
613
|
+
async listInvitations(projectId, params = {}) {
|
|
614
|
+
return await this.backendRequest("GET", `/v1/projects/${encodePathSegment(projectId)}/invitations`, { params: {
|
|
615
|
+
limit: params.limit,
|
|
616
|
+
offset: params.offset
|
|
617
|
+
} });
|
|
618
|
+
}
|
|
619
|
+
/** Enterprise backend `POST /v1/projects/{id}/invitations`. */
|
|
620
|
+
async inviteUser(projectId, body) {
|
|
621
|
+
return await this.backendRequest("POST", `/v1/projects/${encodePathSegment(projectId)}/invitations`, { json: body });
|
|
622
|
+
}
|
|
623
|
+
/** Enterprise backend `DELETE /v1/projects/{id}/invitations/{inv_id}`. */
|
|
624
|
+
async revokeInvitation(projectId, invitationId) {
|
|
625
|
+
return await this.backendRequest("DELETE", `/v1/projects/${encodePathSegment(projectId)}/invitations/${encodePathSegment(invitationId)}`);
|
|
626
|
+
}
|
|
627
|
+
/** Enterprise backend `POST /v1/projects/{id}/leave`. */
|
|
628
|
+
async leaveProject(projectId) {
|
|
629
|
+
return await this.backendRequest("POST", `/v1/projects/${encodePathSegment(projectId)}/leave`);
|
|
630
|
+
}
|
|
631
|
+
/** Enterprise backend `GET /v1/projects/{id}/members`. */
|
|
632
|
+
async listMembers(projectId, params = {}) {
|
|
633
|
+
return await this.backendRequest("GET", `/v1/projects/${encodePathSegment(projectId)}/members`, { params: {
|
|
634
|
+
limit: params.limit,
|
|
635
|
+
offset: params.offset
|
|
636
|
+
} });
|
|
637
|
+
}
|
|
638
|
+
/** Enterprise backend `DELETE /v1/projects/{id}/members/{user_id}`. */
|
|
639
|
+
async removeMember(projectId, userId) {
|
|
640
|
+
return await this.backendRequest("DELETE", `/v1/projects/${encodePathSegment(projectId)}/members/${encodePathSegment(userId)}`);
|
|
641
|
+
}
|
|
642
|
+
/** Enterprise backend `PATCH /v1/projects/{id}/members/{user_id}`. */
|
|
643
|
+
async updateMemberRole(projectId, userId, body) {
|
|
644
|
+
return await this.backendRequest("PATCH", `/v1/projects/${encodePathSegment(projectId)}/members/${encodePathSegment(userId)}`, { json: body });
|
|
645
|
+
}
|
|
646
|
+
/** Enterprise backend `GET /v1/projects/{id}/rag-config`. */
|
|
647
|
+
async backendGetRagConfig(projectId) {
|
|
648
|
+
return await this.backendRequest("GET", `/v1/projects/${encodePathSegment(projectId)}/rag-config`);
|
|
649
|
+
}
|
|
650
|
+
/** Enterprise backend `PUT /v1/projects/{id}/rag-config`. */
|
|
651
|
+
async backendSetRagConfig(projectId, body) {
|
|
652
|
+
return await this.backendRequest("PUT", `/v1/projects/${encodePathSegment(projectId)}/rag-config`, { json: body });
|
|
653
|
+
}
|
|
654
|
+
/** Enterprise backend `POST /v1/projects/{id}/sandbox/extract`. */
|
|
655
|
+
async sandboxExtract(projectId, params) {
|
|
656
|
+
return await this.backendRequest("POST", `/v1/projects/${encodePathSegment(projectId)}/sandbox/extract`, { body: sandboxForm(params) });
|
|
657
|
+
}
|
|
658
|
+
/** Enterprise backend `GET /v1/projects/{id}/usage`. */
|
|
659
|
+
async getUsage(projectId, params) {
|
|
660
|
+
return await this.backendRequest("GET", `/v1/projects/${encodePathSegment(projectId)}/usage`, { params: {
|
|
661
|
+
start_date: params.startDate,
|
|
662
|
+
end_date: params.endDate
|
|
663
|
+
} });
|
|
664
|
+
}
|
|
665
|
+
/** Enterprise backend `GET /v1/projects/{id}/webhooks`. */
|
|
666
|
+
async listWebhooks(projectId, params = {}) {
|
|
667
|
+
return await this.backendRequest("GET", `/v1/projects/${encodePathSegment(projectId)}/webhooks`, { params: {
|
|
668
|
+
limit: params.limit,
|
|
669
|
+
offset: params.offset
|
|
670
|
+
} });
|
|
671
|
+
}
|
|
672
|
+
/** Enterprise backend `POST /v1/projects/{id}/webhooks`. */
|
|
673
|
+
async createWebhook(projectId, body) {
|
|
674
|
+
return await this.backendRequest("POST", `/v1/projects/${encodePathSegment(projectId)}/webhooks`, { json: body });
|
|
675
|
+
}
|
|
676
|
+
/** Enterprise backend `DELETE /v1/projects/{id}/webhooks/{wh_id}`. */
|
|
677
|
+
async deleteWebhook(projectId, webhookId) {
|
|
678
|
+
return await this.backendRequest("DELETE", `/v1/projects/${encodePathSegment(projectId)}/webhooks/${encodePathSegment(webhookId)}`);
|
|
679
|
+
}
|
|
680
|
+
/** Enterprise backend `PATCH /v1/projects/{id}/webhooks/{wh_id}`. */
|
|
681
|
+
async updateWebhook(projectId, webhookId, body) {
|
|
682
|
+
return await this.backendRequest("PATCH", `/v1/projects/${encodePathSegment(projectId)}/webhooks/${encodePathSegment(webhookId)}`, { json: body });
|
|
683
|
+
}
|
|
684
|
+
/** Enterprise backend `GET /v1/projects/{id}/webhooks/{wh_id}/deliveries`. */
|
|
685
|
+
async listWebhookDeliveries(projectId, webhookId, params = {}) {
|
|
686
|
+
return await this.backendRequest("GET", `/v1/projects/${encodePathSegment(projectId)}/webhooks/${encodePathSegment(webhookId)}/deliveries`, { params: {
|
|
687
|
+
limit: params.limit,
|
|
688
|
+
offset: params.offset
|
|
689
|
+
} });
|
|
690
|
+
}
|
|
691
|
+
/** Enterprise backend `GET /v1/projects/{id}/webhooks/{wh_id}/deliveries/{delivery_id}`. */
|
|
692
|
+
async getWebhookDelivery(projectId, webhookId, deliveryId) {
|
|
693
|
+
return await this.backendRequest("GET", `/v1/projects/${encodePathSegment(projectId)}/webhooks/${encodePathSegment(webhookId)}/deliveries/${encodePathSegment(deliveryId)}`);
|
|
694
|
+
}
|
|
695
|
+
/** Enterprise backend `POST /v1/projects/{id}/webhooks/{wh_id}/deliveries/{delivery_id}/retry`. */
|
|
696
|
+
async retryWebhookDelivery(projectId, webhookId, deliveryId) {
|
|
697
|
+
return await this.backendRequest("POST", `/v1/projects/${encodePathSegment(projectId)}/webhooks/${encodePathSegment(webhookId)}/deliveries/${encodePathSegment(deliveryId)}/retry`);
|
|
698
|
+
}
|
|
699
|
+
/** Enterprise backend `POST /v1/projects/{id}/webhooks/{wh_id}/test`. */
|
|
700
|
+
async testWebhook(projectId, webhookId) {
|
|
701
|
+
return await this.backendRequest("POST", `/v1/projects/${encodePathSegment(projectId)}/webhooks/${encodePathSegment(webhookId)}/test`);
|
|
702
|
+
}
|
|
703
|
+
/** Enterprise backend `POST /v1/sandbox/public/extract`. */
|
|
704
|
+
async publicSandboxExtract(params) {
|
|
705
|
+
return await this.backendRequest("POST", `/v1/sandbox/public/extract`, {
|
|
706
|
+
body: sandboxForm(params),
|
|
707
|
+
...params.sandboxToken !== void 0 ? { sandboxToken: params.sandboxToken } : {},
|
|
708
|
+
backendPublic: true
|
|
709
|
+
});
|
|
710
|
+
}
|
|
445
711
|
/**
|
|
446
712
|
* Submit a single document for extraction. Returns the initial {@link Job}
|
|
447
713
|
* record (still pending — call `waitForJob` to await completion).
|
|
@@ -449,6 +715,7 @@ var XbergClient = class {
|
|
|
449
715
|
async extract(params) {
|
|
450
716
|
const jobs = await this.extractBatch({
|
|
451
717
|
files: [params.file],
|
|
718
|
+
...params.documentId !== void 0 ? { documentIds: [params.documentId] } : {},
|
|
452
719
|
...params.options !== void 0 ? { options: params.options } : {},
|
|
453
720
|
...params.webhook !== void 0 ? { webhook: params.webhook } : {},
|
|
454
721
|
...params.config !== void 0 ? { configs: [params.config] } : {}
|
|
@@ -469,20 +736,20 @@ var XbergClient = class {
|
|
|
469
736
|
status: 400,
|
|
470
737
|
body: null
|
|
471
738
|
});
|
|
739
|
+
const filenames = params.files.map(describeFile);
|
|
740
|
+
const documentIds = prepareDocumentLineage(filenames, params.documentIds);
|
|
741
|
+
if (documentIds.size > 0) await this.requireTier("enterprise", "extract document lineage");
|
|
472
742
|
const form = new FormData();
|
|
473
|
-
const
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
form.append("file", blob, filename);
|
|
477
|
-
filenames.push(filename);
|
|
478
|
-
}
|
|
743
|
+
for (const [filename, documentId] of documentIds) form.append(`document_id-${filename}`, documentId);
|
|
744
|
+
const parts = params.files.map(toBlob);
|
|
745
|
+
for (const { blob, filename } of parts) form.append("file", blob, filename);
|
|
479
746
|
if (params.options !== void 0) form.append("options", JSON.stringify(params.options));
|
|
480
747
|
if (params.webhook !== void 0) form.append("webhook", JSON.stringify(params.webhook));
|
|
481
748
|
appendPerFileConfigs(form, filenames, params.configs);
|
|
482
749
|
const body = await this.requestJson("POST", "/v1/extract", { body: form });
|
|
483
750
|
const jobIds = body.job_ids ?? [];
|
|
484
751
|
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
485
|
-
return
|
|
752
|
+
return parts.map(({ blob, filename }, index) => {
|
|
486
753
|
const id = jobIds[index];
|
|
487
754
|
if (id === void 0) throw new XbergError(`Server returned ${jobIds.length} job IDs for ${params.files.length} files`, {
|
|
488
755
|
status: 500,
|
|
@@ -490,7 +757,8 @@ var XbergClient = class {
|
|
|
490
757
|
});
|
|
491
758
|
return {
|
|
492
759
|
id,
|
|
493
|
-
filename
|
|
760
|
+
filename,
|
|
761
|
+
mime_type: blob.type.length > 0 ? blob.type : OCTET_STREAM_MEDIA_TYPE,
|
|
494
762
|
status: "pending",
|
|
495
763
|
created_at: now
|
|
496
764
|
};
|
|
@@ -498,7 +766,7 @@ var XbergClient = class {
|
|
|
498
766
|
}
|
|
499
767
|
/** Fetch the current state of a job. */
|
|
500
768
|
async getJob(jobId) {
|
|
501
|
-
return await this.requestJson("GET", `${JOBS_PATH}/${
|
|
769
|
+
return await this.requestJson("GET", `${JOBS_PATH}/${encodePathSegment(jobId)}`);
|
|
502
770
|
}
|
|
503
771
|
/**
|
|
504
772
|
* Fetch a job's stored result document (`GET /v1/jobs/{id}/result`).
|
|
@@ -508,7 +776,7 @@ var XbergClient = class {
|
|
|
508
776
|
* returns the job's metadata record.
|
|
509
777
|
*/
|
|
510
778
|
async getJobResult(jobId) {
|
|
511
|
-
return await this.requestJson("GET", `${JOBS_PATH}/${
|
|
779
|
+
return await this.requestJson("GET", `${JOBS_PATH}/${encodePathSegment(jobId)}/result`);
|
|
512
780
|
}
|
|
513
781
|
/** List jobs (paginated) via `GET /v1/jobs`. */
|
|
514
782
|
async listJobs(params = {}) {
|
|
@@ -523,7 +791,7 @@ var XbergClient = class {
|
|
|
523
791
|
* `204`.
|
|
524
792
|
*/
|
|
525
793
|
async cancelJob(jobId) {
|
|
526
|
-
await this.requestJson("DELETE", `${JOBS_PATH}/${
|
|
794
|
+
await this.requestJson("DELETE", `${JOBS_PATH}/${encodePathSegment(jobId)}`);
|
|
527
795
|
}
|
|
528
796
|
/**
|
|
529
797
|
* Poll {@link getJob} until the job reaches a terminal status. Throws
|
|
@@ -563,6 +831,7 @@ var XbergClient = class {
|
|
|
563
831
|
async extractAndWait(params) {
|
|
564
832
|
const extractParams = {
|
|
565
833
|
file: params.file,
|
|
834
|
+
...params.documentId !== void 0 ? { documentId: params.documentId } : {},
|
|
566
835
|
...params.options !== void 0 ? { options: params.options } : {},
|
|
567
836
|
...params.webhook !== void 0 ? { webhook: params.webhook } : {},
|
|
568
837
|
...params.config !== void 0 ? { config: params.config } : {}
|
|
@@ -589,7 +858,7 @@ var XbergClient = class {
|
|
|
589
858
|
}
|
|
590
859
|
/** Fetch one curated preset in full (`GET /v1/presets/{id}`). */
|
|
591
860
|
async getPreset(presetId) {
|
|
592
|
-
return await this.requestJson("GET", `/v1/presets/${
|
|
861
|
+
return await this.requestJson("GET", `/v1/presets/${encodePathSegment(presetId)}`);
|
|
593
862
|
}
|
|
594
863
|
/**
|
|
595
864
|
* Download a preset's bundled sample file
|
|
@@ -597,7 +866,7 @@ var XbergClient = class {
|
|
|
597
866
|
* JSON.
|
|
598
867
|
*/
|
|
599
868
|
async getPresetSample(presetId, name) {
|
|
600
|
-
const path = `/v1/presets/${
|
|
869
|
+
const path = `/v1/presets/${encodePathSegment(presetId)}/sample/${encodePathSegment(name)}`;
|
|
601
870
|
return await this.requestBytes("GET", path);
|
|
602
871
|
}
|
|
603
872
|
/** List RAG collections (`GET /v1/rag/collections`). */
|
|
@@ -610,15 +879,15 @@ var XbergClient = class {
|
|
|
610
879
|
}
|
|
611
880
|
/** Fetch a RAG collection (`GET /v1/rag/collections/{name}`). */
|
|
612
881
|
async getRagCollection(name) {
|
|
613
|
-
return await this.requestJson("GET", `/v1/rag/collections/${
|
|
882
|
+
return await this.requestJson("GET", `/v1/rag/collections/${encodePathSegment(name)}`);
|
|
614
883
|
}
|
|
615
884
|
/** Delete a RAG collection (`DELETE /v1/rag/collections/{name}`). The spec documents a 204 with no content. */
|
|
616
885
|
async deleteRagCollection(name) {
|
|
617
|
-
await this.requestJson("DELETE", `/v1/rag/collections/${
|
|
886
|
+
await this.requestJson("DELETE", `/v1/rag/collections/${encodePathSegment(name)}`);
|
|
618
887
|
}
|
|
619
888
|
/** Add documents to a RAG collection (`POST /v1/rag/collections/{name}/documents`). */
|
|
620
889
|
async addRagDocuments(name, body) {
|
|
621
|
-
return await this.requestJson("POST", `/v1/rag/collections/${
|
|
890
|
+
return await this.requestJson("POST", `/v1/rag/collections/${encodePathSegment(name)}/documents`, { json: body });
|
|
622
891
|
}
|
|
623
892
|
/**
|
|
624
893
|
* Delete documents from a RAG collection, by ID list or metadata filter
|
|
@@ -627,57 +896,59 @@ var XbergClient = class {
|
|
|
627
896
|
* many documents were removed.
|
|
628
897
|
*/
|
|
629
898
|
async deleteRagDocuments(name, body) {
|
|
630
|
-
return await this.requestJson("DELETE", `/v1/rag/collections/${
|
|
899
|
+
return await this.requestJson("DELETE", `/v1/rag/collections/${encodePathSegment(name)}/documents`, { json: body });
|
|
631
900
|
}
|
|
632
901
|
/** Reindex a RAG document (`POST /v1/rag/collections/{name}/documents/{id}/reindex`). */
|
|
633
902
|
async reindexRagDocument(name, documentId, body) {
|
|
634
|
-
const path = `/v1/rag/collections/${
|
|
903
|
+
const path = `/v1/rag/collections/${encodePathSegment(name)}/documents/${encodePathSegment(documentId)}/reindex`;
|
|
635
904
|
return await this.requestJson("POST", path, body !== void 0 ? { json: body } : {});
|
|
636
905
|
}
|
|
637
906
|
/** Retrieve chunks from a RAG collection (`POST /v1/rag/collections/{name}/retrieve`). */
|
|
638
907
|
async ragRetrieve(name, body) {
|
|
639
|
-
return await this.requestJson("POST", `/v1/rag/collections/${
|
|
908
|
+
return await this.requestJson("POST", `/v1/rag/collections/${encodePathSegment(name)}/retrieve`, { json: body });
|
|
640
909
|
}
|
|
641
910
|
/** Kick off an embedding migration (`POST /v1/rag/collections/{name}/migrate-embeddings`). */
|
|
642
911
|
async migrateRagEmbeddings(name, body) {
|
|
643
|
-
return await this.requestJson("POST", `/v1/rag/collections/${
|
|
912
|
+
return await this.requestJson("POST", `/v1/rag/collections/${encodePathSegment(name)}/migrate-embeddings`, { json: body });
|
|
644
913
|
}
|
|
645
914
|
/** Poll an embedding-migration job (`GET .../migrate-embeddings/{jobId}`). */
|
|
646
915
|
async getRagMigrationJob(name, jobId) {
|
|
647
|
-
const path = `/v1/rag/collections/${
|
|
916
|
+
const path = `/v1/rag/collections/${encodePathSegment(name)}/migrate-embeddings/${encodePathSegment(jobId)}`;
|
|
648
917
|
return await this.requestJson("GET", path);
|
|
649
918
|
}
|
|
650
919
|
/** Fetch a RAG job's status (`GET /v1/rag/jobs/{jobId}`). */
|
|
651
920
|
async getRagJob(jobId) {
|
|
652
|
-
return await this.requestJson("GET", `/v1/rag/jobs/${
|
|
921
|
+
return await this.requestJson("GET", `/v1/rag/jobs/${encodePathSegment(jobId)}`);
|
|
653
922
|
}
|
|
654
|
-
/**
|
|
923
|
+
/**
|
|
924
|
+
* List the managed embedding presets this server build ships
|
|
925
|
+
* (`GET /v1/rag/embedding-presets`), in the canonical backend order.
|
|
926
|
+
*/
|
|
927
|
+
async listManagedEmbeddingPresets() {
|
|
928
|
+
return await this.requestJson("GET", "/v1/rag/embedding-presets");
|
|
929
|
+
}
|
|
930
|
+
/** List the project's saved presets (`GET /v1/saved_presets`). */
|
|
655
931
|
async listSavedPresets(params = {}) {
|
|
656
|
-
|
|
657
|
-
return await this.requestJson("GET", path, { params: {
|
|
932
|
+
return await this.requestJson("GET", SAVED_PRESETS_PATH, { params: {
|
|
658
933
|
limit: params.limit,
|
|
659
934
|
offset: params.offset
|
|
660
935
|
} });
|
|
661
936
|
}
|
|
662
|
-
/** Create a saved preset (`POST /v1/saved_presets
|
|
937
|
+
/** Create a saved preset (`POST /v1/saved_presets`). */
|
|
663
938
|
async createSavedPreset(body) {
|
|
664
|
-
|
|
665
|
-
return await this.requestJson("POST", path, { json: body });
|
|
939
|
+
return await this.requestJson("POST", SAVED_PRESETS_PATH, { json: body });
|
|
666
940
|
}
|
|
667
|
-
/** Fetch one saved preset (`GET /v1/saved_presets/{
|
|
941
|
+
/** Fetch one saved preset (`GET /v1/saved_presets/{preset_id}`). */
|
|
668
942
|
async getSavedPreset(presetId) {
|
|
669
|
-
|
|
670
|
-
return await this.requestJson("GET", path);
|
|
943
|
+
return await this.requestJson("GET", this.savedPresetPath(presetId));
|
|
671
944
|
}
|
|
672
|
-
/** Update a saved preset (`PATCH /v1/saved_presets/{
|
|
945
|
+
/** Update a saved preset (`PATCH /v1/saved_presets/{preset_id}`). */
|
|
673
946
|
async updateSavedPreset(presetId, body) {
|
|
674
|
-
|
|
675
|
-
return await this.requestJson("PATCH", path, { json: body });
|
|
947
|
+
return await this.requestJson("PATCH", this.savedPresetPath(presetId), { json: body });
|
|
676
948
|
}
|
|
677
|
-
/** Delete a saved preset (`DELETE /v1/saved_presets/{
|
|
949
|
+
/** Delete a saved preset (`DELETE /v1/saved_presets/{preset_id}`). */
|
|
678
950
|
async deleteSavedPreset(presetId) {
|
|
679
|
-
|
|
680
|
-
await this.requestJson("DELETE", path);
|
|
951
|
+
await this.requestJson("DELETE", this.savedPresetPath(presetId));
|
|
681
952
|
}
|
|
682
953
|
/** List the project's auto-tune jobs (`GET /v1/auto-tune`). */
|
|
683
954
|
async listAutoTuneJobs(params = {}) {
|
|
@@ -715,6 +986,17 @@ var XbergClient = class {
|
|
|
715
986
|
async deleteAutoTuneJob(autoTuneJobId) {
|
|
716
987
|
await this.requestJson("DELETE", this.autoTunePath(autoTuneJobId));
|
|
717
988
|
}
|
|
989
|
+
/**
|
|
990
|
+
* Stop a running auto-tune job (`POST /v1/auto-tune/{id}/stop`).
|
|
991
|
+
*
|
|
992
|
+
* The run finishes the trial in flight and then completes with the partial
|
|
993
|
+
* leaderboard, so {@link getAutoTuneResult} still serves the best configuration
|
|
994
|
+
* the search found. Idempotent: a job that already reached a terminal state
|
|
995
|
+
* answers `204` and nothing changes.
|
|
996
|
+
*/
|
|
997
|
+
async stopAutoTuneJob(autoTuneJobId) {
|
|
998
|
+
await this.requestJson("POST", `${this.autoTunePath(autoTuneJobId)}/stop`);
|
|
999
|
+
}
|
|
718
1000
|
/** Promote an auto-tune result to a named tuning profile (`POST /v1/auto-tune/{id}/promote`). */
|
|
719
1001
|
async promoteAutoTuneProfile(autoTuneJobId, body) {
|
|
720
1002
|
return await this.requestJson("POST", `${this.autoTunePath(autoTuneJobId)}/promote`, { json: body });
|
|
@@ -738,6 +1020,69 @@ var XbergClient = class {
|
|
|
738
1020
|
async deleteTuningProfile(profileId) {
|
|
739
1021
|
await this.requestJson("DELETE", this.tuningProfilePath(profileId));
|
|
740
1022
|
}
|
|
1023
|
+
/**
|
|
1024
|
+
* Request presigned upload URLs (`POST /v1/uploads/presign`).
|
|
1025
|
+
*
|
|
1026
|
+
* The request body is typed off the Enterprise schema, whose `config` is a full
|
|
1027
|
+
* `ExtractionConfig`; Pro declares that field as an open object and accepts the
|
|
1028
|
+
* same payload.
|
|
1029
|
+
*/
|
|
1030
|
+
async presignUpload(body) {
|
|
1031
|
+
return await this.requestJson("POST", "/v1/uploads/presign", { json: body });
|
|
1032
|
+
}
|
|
1033
|
+
/** Confirm presigned uploads and start processing (`POST /v1/uploads/confirm`). */
|
|
1034
|
+
async confirmUpload(body) {
|
|
1035
|
+
return await this.requestJson("POST", "/v1/uploads/confirm", { json: body });
|
|
1036
|
+
}
|
|
1037
|
+
/** Fetch usage/metering data for a date window (`GET /v1/usage`). */
|
|
1038
|
+
async usage(params) {
|
|
1039
|
+
const init = params !== void 0 ? { params } : {};
|
|
1040
|
+
return await this.requestJson("GET", "/v1/usage", init);
|
|
1041
|
+
}
|
|
1042
|
+
/**
|
|
1043
|
+
* Download one rendered page of an extraction job
|
|
1044
|
+
* (`GET /v1/jobs/{job_id}/pages/{page_number}`). The response is a PNG image —
|
|
1045
|
+
* raw bytes, not JSON. `pageNumber` is 1-indexed.
|
|
1046
|
+
*/
|
|
1047
|
+
async getJobPage(jobId, pageNumber) {
|
|
1048
|
+
const path = `${JOBS_PATH}/${encodePathSegment(jobId)}/pages/${encodePathSegment(String(pageNumber))}`;
|
|
1049
|
+
return await this.requestBytes("GET", path);
|
|
1050
|
+
}
|
|
1051
|
+
/** Submit text for enrichment (`POST /v1/enrich`). */
|
|
1052
|
+
async submitEnrich(body) {
|
|
1053
|
+
return await this.requestJson("POST", ENRICH_PATH, { json: body });
|
|
1054
|
+
}
|
|
1055
|
+
/** Fetch an enrichment job's status (`GET /v1/enrich/{job_id}`). */
|
|
1056
|
+
async getEnrichStatus(jobId) {
|
|
1057
|
+
return await this.requestJson("GET", `${ENRICH_PATH}/${encodePathSegment(jobId)}`);
|
|
1058
|
+
}
|
|
1059
|
+
/**
|
|
1060
|
+
* Stream a crawl job's events (`GET /v1/crawl-jobs/{crawl_job_id}/events`,
|
|
1061
|
+
* Server-Sent Events).
|
|
1062
|
+
*
|
|
1063
|
+
* Returns an `AsyncIterable` of the `kind`-discriminated {@link CrawlEvent}
|
|
1064
|
+
* union; the server closes the stream after the `complete` event.
|
|
1065
|
+
*
|
|
1066
|
+
* ```ts
|
|
1067
|
+
* for await (const event of client.streamCrawlEvents(crawlJobId)) {
|
|
1068
|
+
* if (event.kind === "page") {
|
|
1069
|
+
* console.log(event.url, event.status_code);
|
|
1070
|
+
* }
|
|
1071
|
+
* }
|
|
1072
|
+
* ```
|
|
1073
|
+
*
|
|
1074
|
+
* Nothing is requested until iteration begins, and the response body is
|
|
1075
|
+
* cancelled when iteration ends: on `complete`, on `break`/`return` out of the
|
|
1076
|
+
* loop, on a thrown error, or when `options.signal` aborts. A stream is idle
|
|
1077
|
+
* between events by design, so unlike every other method here it carries no
|
|
1078
|
+
* request timeout and is not routed through the retry engine — a retried
|
|
1079
|
+
* subscription would redeliver every event the caller had already handled.
|
|
1080
|
+
*/
|
|
1081
|
+
streamCrawlEvents(crawlJobId, options = {}) {
|
|
1082
|
+
const path = `${CRAWL_JOBS_PATH}/${encodePathSegment(crawlJobId)}/events`;
|
|
1083
|
+
const open = () => this.openEventStream(path, options.signal);
|
|
1084
|
+
return { [Symbol.asyncIterator]: () => iterateCrawlEvents(open) };
|
|
1085
|
+
}
|
|
741
1086
|
/** Pro only: fetch the instance's accepted auth methods (`GET /auth/config`). */
|
|
742
1087
|
async authConfig() {
|
|
743
1088
|
await this.requireTier("pro", "authConfig");
|
|
@@ -748,15 +1093,42 @@ var XbergClient = class {
|
|
|
748
1093
|
await this.requireTier("pro", "login");
|
|
749
1094
|
return this.requestJson("POST", "/auth/login", { json: body });
|
|
750
1095
|
}
|
|
1096
|
+
/**
|
|
1097
|
+
* Pro only: read the running instance's license detail (`GET /v1/license`) —
|
|
1098
|
+
* licensee, plan, expiry, grace window and days remaining. Requires an admin
|
|
1099
|
+
* API key or an admin session.
|
|
1100
|
+
*/
|
|
1101
|
+
async getLicenseInfo() {
|
|
1102
|
+
await this.requireTier("pro", "getLicenseInfo");
|
|
1103
|
+
return this.requestJson("GET", "/v1/license");
|
|
1104
|
+
}
|
|
1105
|
+
/**
|
|
1106
|
+
* Pro only: upload a document's bytes against a presigned local capability
|
|
1107
|
+
* (`PUT /v1/uploads/local/{project_id}/{token}`).
|
|
1108
|
+
*
|
|
1109
|
+
* `projectId` and `token` come from the `upload_url` {@link presignUpload}
|
|
1110
|
+
* returns when the instance stages uploads locally. The capability is one-use,
|
|
1111
|
+
* expiring, and bounded by the size limit recorded when it was issued; the
|
|
1112
|
+
* body is sent as raw bytes.
|
|
1113
|
+
*/
|
|
1114
|
+
async putLocalUpload(projectId, token, file) {
|
|
1115
|
+
await this.requireTier("pro", "putLocalUpload");
|
|
1116
|
+
const { blob } = toBlob(file);
|
|
1117
|
+
const path = `/v1/uploads/local/${encodePathSegment(projectId)}/${encodePathSegment(token)}`;
|
|
1118
|
+
await this.requestJson("PUT", path, {
|
|
1119
|
+
body: new Uint8Array(await blob.arrayBuffer()),
|
|
1120
|
+
headers: { "Content-Type": OCTET_STREAM_MEDIA_TYPE }
|
|
1121
|
+
});
|
|
1122
|
+
}
|
|
751
1123
|
/** Pro only: fetch a project's RAG config (`GET /v1/projects/{projectId}/rag-config`). */
|
|
752
1124
|
async getRagConfig(projectId) {
|
|
753
1125
|
await this.requireTier("pro", "getRagConfig");
|
|
754
|
-
return this.requestJson("GET", `/v1/projects/${
|
|
1126
|
+
return this.requestJson("GET", `/v1/projects/${encodePathSegment(projectId)}/rag-config`);
|
|
755
1127
|
}
|
|
756
1128
|
/** Pro only: update a project's RAG config (`PUT /v1/projects/{projectId}/rag-config`). */
|
|
757
1129
|
async setRagConfig(projectId, body) {
|
|
758
1130
|
await this.requireTier("pro", "setRagConfig");
|
|
759
|
-
return this.requestJson("PUT", `/v1/projects/${
|
|
1131
|
+
return this.requestJson("PUT", `/v1/projects/${encodePathSegment(projectId)}/rag-config`, { json: body });
|
|
760
1132
|
}
|
|
761
1133
|
/** Pro only: list the caller's projects (`GET /v1/projects`). */
|
|
762
1134
|
async listProjects(params = {}) {
|
|
@@ -787,7 +1159,7 @@ var XbergClient = class {
|
|
|
787
1159
|
/** Pro only: revoke an API key (`DELETE /v1/projects/{projectId}/api-keys/{keyId}`). */
|
|
788
1160
|
async revokeApiKey(projectId, keyId) {
|
|
789
1161
|
await this.requireTier("pro", "revokeApiKey");
|
|
790
|
-
await this.requestJson("DELETE", `${this.projectPath(projectId)}/api-keys/${
|
|
1162
|
+
await this.requestJson("DELETE", `${this.projectPath(projectId)}/api-keys/${encodePathSegment(keyId)}`);
|
|
791
1163
|
}
|
|
792
1164
|
/** Pro only: list a project's integrations (`GET /v1/projects/{projectId}/integrations`). */
|
|
793
1165
|
async listIntegrations(projectId, params = {}) {
|
|
@@ -832,7 +1204,8 @@ var XbergClient = class {
|
|
|
832
1204
|
return this.requestJson("GET", `${this.integrationPath(projectId, integrationId)}/documents`, { params: {
|
|
833
1205
|
mime_types: params.mimeTypes,
|
|
834
1206
|
folder_id: params.folderId,
|
|
835
|
-
|
|
1207
|
+
limit: params.limit,
|
|
1208
|
+
offset: params.offset
|
|
836
1209
|
} });
|
|
837
1210
|
}
|
|
838
1211
|
/**
|
|
@@ -841,7 +1214,7 @@ var XbergClient = class {
|
|
|
841
1214
|
*/
|
|
842
1215
|
async fetchIntegrationDocument(projectId, integrationId, documentId) {
|
|
843
1216
|
await this.requireTier("pro", "fetchIntegrationDocument");
|
|
844
|
-
const path = `${this.integrationPath(projectId, integrationId)}/documents/${
|
|
1217
|
+
const path = `${this.integrationPath(projectId, integrationId)}/documents/${encodePathSegment(documentId)}`;
|
|
845
1218
|
return this.requestBytes("GET", path);
|
|
846
1219
|
}
|
|
847
1220
|
/**
|
|
@@ -891,7 +1264,7 @@ var XbergClient = class {
|
|
|
891
1264
|
*/
|
|
892
1265
|
async getDiffJob(documentId, diffJobId) {
|
|
893
1266
|
await this.requireTier("enterprise", "getDiffJob");
|
|
894
|
-
const path = `${this.documentPath(documentId)}/diff/${
|
|
1267
|
+
const path = `${this.documentPath(documentId)}/diff/${encodePathSegment(diffJobId)}`;
|
|
895
1268
|
const { status, body } = await this.requestJsonWithStatus("GET", path);
|
|
896
1269
|
return toDiffResult(status, body);
|
|
897
1270
|
}
|
|
@@ -905,100 +1278,57 @@ var XbergClient = class {
|
|
|
905
1278
|
} });
|
|
906
1279
|
}
|
|
907
1280
|
/**
|
|
908
|
-
* Enterprise only:
|
|
909
|
-
* (`GET /v1/
|
|
910
|
-
*
|
|
1281
|
+
* Enterprise only: list a webhook subscription's delivery attempts
|
|
1282
|
+
* (`GET /v1/webhooks/{webhook_id}/deliveries`). Metadata only — call
|
|
1283
|
+
* {@link getSubscriptionDelivery} for an attempt's payload previews.
|
|
1284
|
+
*
|
|
1285
|
+
* ~keep Distinct from {@link listWebhookDeliveries}, which reads the same
|
|
1286
|
+
* history through the control plane's project-scoped route.
|
|
911
1287
|
*/
|
|
912
|
-
async
|
|
913
|
-
await this.requireTier("enterprise", "
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
async submitEnrich(body) {
|
|
919
|
-
await this.requireTier("enterprise", "submitEnrich");
|
|
920
|
-
return this.requestJson("POST", ENRICH_PATH, { json: body });
|
|
921
|
-
}
|
|
922
|
-
/** Enterprise only: fetch an enrichment job's status (`GET /v1/enrich/{jobId}`). */
|
|
923
|
-
async getEnrichStatus(jobId) {
|
|
924
|
-
await this.requireTier("enterprise", "getEnrichStatus");
|
|
925
|
-
return this.requestJson("GET", `${ENRICH_PATH}/${encodeURIComponent(jobId)}`);
|
|
1288
|
+
async listSubscriptionDeliveries(webhookId, params = {}) {
|
|
1289
|
+
await this.requireTier("enterprise", "listSubscriptionDeliveries");
|
|
1290
|
+
return this.requestJson("GET", this.webhookDeliveriesPath(webhookId), { params: {
|
|
1291
|
+
limit: params.limit,
|
|
1292
|
+
offset: params.offset
|
|
1293
|
+
} });
|
|
926
1294
|
}
|
|
927
1295
|
/**
|
|
928
|
-
* Enterprise only:
|
|
929
|
-
* (`GET /v1/
|
|
930
|
-
*
|
|
931
|
-
* Returns an `AsyncIterable` of the `kind`-discriminated {@link CrawlEvent}
|
|
932
|
-
* union; the server closes the stream after the `complete` event.
|
|
933
|
-
*
|
|
934
|
-
* ```ts
|
|
935
|
-
* for await (const event of client.streamCrawlEvents(crawlJobId)) {
|
|
936
|
-
* if (event.kind === "page") {
|
|
937
|
-
* console.log(event.url, event.status_code);
|
|
938
|
-
* }
|
|
939
|
-
* }
|
|
940
|
-
* ```
|
|
941
|
-
*
|
|
942
|
-
* Nothing is requested — not even the `/healthz` tier probe — until
|
|
943
|
-
* iteration begins, and the response body is cancelled when iteration ends:
|
|
944
|
-
* on `complete`, on `break`/`return` out of the loop, on a thrown error, or
|
|
945
|
-
* when `options.signal` aborts. A stream is idle between events by design,
|
|
946
|
-
* so unlike every other method here it carries no request timeout and is not
|
|
947
|
-
* routed through the retry engine — a retried subscription would redeliver
|
|
948
|
-
* every event the caller had already handled.
|
|
1296
|
+
* Enterprise only: fetch one delivery attempt with its bounded request and
|
|
1297
|
+
* response previews (`GET /v1/webhooks/{webhook_id}/deliveries/{delivery_id}`).
|
|
1298
|
+
* The previews can carry project document content.
|
|
949
1299
|
*/
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
const
|
|
953
|
-
|
|
954
|
-
return this.openEventStream(path, options.signal);
|
|
955
|
-
};
|
|
956
|
-
return { [Symbol.asyncIterator]: () => iterateCrawlEvents(open) };
|
|
957
|
-
}
|
|
958
|
-
/** Enterprise only: request a presigned upload URL (`POST /v1/uploads/presign`). */
|
|
959
|
-
async presignUpload(body) {
|
|
960
|
-
await this.requireTier("enterprise", "presignUpload");
|
|
961
|
-
return this.requestJson("POST", "/v1/uploads/presign", { json: body });
|
|
962
|
-
}
|
|
963
|
-
/** Enterprise only: confirm a presigned upload (`POST /v1/uploads/confirm`). */
|
|
964
|
-
async confirmUpload(body) {
|
|
965
|
-
await this.requireTier("enterprise", "confirmUpload");
|
|
966
|
-
return this.requestJson("POST", "/v1/uploads/confirm", { json: body });
|
|
967
|
-
}
|
|
968
|
-
/** Enterprise only: fetch usage/metering data (`GET /v1/usage`). */
|
|
969
|
-
async usage(params) {
|
|
970
|
-
await this.requireTier("enterprise", "usage");
|
|
971
|
-
const init = params !== void 0 ? { params } : {};
|
|
972
|
-
return this.requestJson("GET", "/v1/usage", init);
|
|
1300
|
+
async getSubscriptionDelivery(webhookId, deliveryId) {
|
|
1301
|
+
await this.requireTier("enterprise", "getSubscriptionDelivery");
|
|
1302
|
+
const path = `${this.webhookDeliveriesPath(webhookId)}/${encodePathSegment(deliveryId)}`;
|
|
1303
|
+
return this.requestJson("GET", path);
|
|
973
1304
|
}
|
|
974
1305
|
/** Build `/v1/projects/{projectId}` with the id percent-encoded. */
|
|
975
1306
|
projectPath(projectId) {
|
|
976
|
-
return `/v1/projects/${
|
|
1307
|
+
return `/v1/projects/${encodePathSegment(projectId)}`;
|
|
977
1308
|
}
|
|
978
1309
|
/** Build `/v1/projects/{projectId}/integrations/{integrationId}`. */
|
|
979
1310
|
integrationPath(projectId, integrationId) {
|
|
980
|
-
return `${this.projectPath(projectId)}/integrations/${
|
|
1311
|
+
return `${this.projectPath(projectId)}/integrations/${encodePathSegment(integrationId)}`;
|
|
981
1312
|
}
|
|
982
1313
|
/** Build `/v1/documents/{documentId}` with the id percent-encoded. */
|
|
983
1314
|
documentPath(documentId) {
|
|
984
|
-
return `${DOCUMENTS_PATH}/${
|
|
1315
|
+
return `${DOCUMENTS_PATH}/${encodePathSegment(documentId)}`;
|
|
1316
|
+
}
|
|
1317
|
+
/** Build `/v1/saved_presets/{preset_id}` with the id percent-encoded. */
|
|
1318
|
+
savedPresetPath(presetId) {
|
|
1319
|
+
return `${SAVED_PRESETS_PATH}/${encodePathSegment(presetId)}`;
|
|
985
1320
|
}
|
|
986
1321
|
/** Build `/v1/auto-tune/{id}` with the id percent-encoded. */
|
|
987
1322
|
autoTunePath(autoTuneJobId) {
|
|
988
|
-
return `${AUTO_TUNE_PATH}/${
|
|
1323
|
+
return `${AUTO_TUNE_PATH}/${encodePathSegment(autoTuneJobId)}`;
|
|
989
1324
|
}
|
|
990
1325
|
/** Build `/v1/tuning-profiles/{id}` with the id percent-encoded. */
|
|
991
1326
|
tuningProfilePath(profileId) {
|
|
992
|
-
return `${TUNING_PROFILES_PATH}/${
|
|
1327
|
+
return `${TUNING_PROFILES_PATH}/${encodePathSegment(profileId)}`;
|
|
993
1328
|
}
|
|
994
|
-
/**
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
* `presetId` for the single-preset routes.
|
|
998
|
-
*/
|
|
999
|
-
async savedPresetsPath(presetId) {
|
|
1000
|
-
const base = await this.resolveTier() === "pro" ? SAVED_PRESETS_PATH_PRO : SAVED_PRESETS_PATH_ENTERPRISE;
|
|
1001
|
-
return presetId === void 0 ? base : `${base}/${encodeURIComponent(presetId)}`;
|
|
1329
|
+
/** Build `/v1/webhooks/{webhook_id}/deliveries` with the id percent-encoded. */
|
|
1330
|
+
webhookDeliveriesPath(webhookId) {
|
|
1331
|
+
return `${WEBHOOKS_PATH}/${encodePathSegment(webhookId)}/deliveries`;
|
|
1002
1332
|
}
|
|
1003
1333
|
/**
|
|
1004
1334
|
* Return the effective tier — an explicit `target` if set, else probed from
|
|
@@ -1042,6 +1372,28 @@ var XbergClient = class {
|
|
|
1042
1372
|
body: null
|
|
1043
1373
|
});
|
|
1044
1374
|
}
|
|
1375
|
+
backendRequest(method, path, init = {}) {
|
|
1376
|
+
return this.requestJson(method, path, {
|
|
1377
|
+
...init,
|
|
1378
|
+
controlPlane: true
|
|
1379
|
+
});
|
|
1380
|
+
}
|
|
1381
|
+
backendHeaders(init) {
|
|
1382
|
+
const headers = new Headers({
|
|
1383
|
+
...this.headers,
|
|
1384
|
+
...init.headers
|
|
1385
|
+
});
|
|
1386
|
+
for (const name of [
|
|
1387
|
+
"authorization",
|
|
1388
|
+
"proxy-authorization",
|
|
1389
|
+
"cookie",
|
|
1390
|
+
"x-api-key"
|
|
1391
|
+
]) headers.delete(name);
|
|
1392
|
+
const token = init.backendPublic ? init.sandboxToken : this.controlPlaneToken;
|
|
1393
|
+
if (token !== void 0 && token.length > 0) headers.set("Authorization", `Bearer ${token}`);
|
|
1394
|
+
if (init.body instanceof FormData || init.json !== void 0) headers.delete("content-type");
|
|
1395
|
+
return Object.fromEntries(headers);
|
|
1396
|
+
}
|
|
1045
1397
|
/** Issue a request, raise on non-2xx, and decode the JSON body (undefined for empty bodies). */
|
|
1046
1398
|
async requestJson(method, path, init = {}) {
|
|
1047
1399
|
const { body } = await this.requestJsonWithStatus(method, path, init);
|
|
@@ -1116,26 +1468,38 @@ var XbergClient = class {
|
|
|
1116
1468
|
* handling. Returns the raw (2xx) {@link Response}; non-2xx responses are
|
|
1117
1469
|
* mapped to a thrown {@link XbergError} subclass.
|
|
1118
1470
|
*/
|
|
1471
|
+
prepareRequest(method, init) {
|
|
1472
|
+
const headers = init.controlPlane ? this.backendHeaders(init) : {
|
|
1473
|
+
...this.headers,
|
|
1474
|
+
...init.headers
|
|
1475
|
+
};
|
|
1476
|
+
let body = init.body;
|
|
1477
|
+
if (init.json !== void 0) {
|
|
1478
|
+
headers["Content-Type"] = "application/json";
|
|
1479
|
+
body = JSON.stringify(init.json);
|
|
1480
|
+
}
|
|
1481
|
+
const requestInit = {
|
|
1482
|
+
method,
|
|
1483
|
+
headers,
|
|
1484
|
+
signal: AbortSignal.timeout(this.timeoutMs),
|
|
1485
|
+
...init.controlPlane ? {
|
|
1486
|
+
credentials: "omit",
|
|
1487
|
+
redirect: "manual"
|
|
1488
|
+
} : {}
|
|
1489
|
+
};
|
|
1490
|
+
if (body !== void 0) requestInit.body = body;
|
|
1491
|
+
return requestInit;
|
|
1492
|
+
}
|
|
1119
1493
|
async requestWithRetry(method, path, init = {}) {
|
|
1120
|
-
|
|
1494
|
+
if (init.controlPlane && (this.target ?? this.probedTier) === "pro") throw new XbergError("Enterprise backend methods are not available on the 'pro' tier", {
|
|
1495
|
+
status: 0,
|
|
1496
|
+
body: null
|
|
1497
|
+
});
|
|
1498
|
+
const url = `${init.controlPlane ? this.controlPlaneBaseUrl : this.baseUrl}${path}${buildQueryString(init.params)}`;
|
|
1121
1499
|
let attempt = 0;
|
|
1122
1500
|
let interval = DEFAULT_RETRY_BACKOFF_BASE_MS;
|
|
1123
1501
|
for (;;) {
|
|
1124
|
-
const
|
|
1125
|
-
...this.headers,
|
|
1126
|
-
...init.headers
|
|
1127
|
-
};
|
|
1128
|
-
let body = init.body;
|
|
1129
|
-
if (init.json !== void 0) {
|
|
1130
|
-
headers["Content-Type"] = "application/json";
|
|
1131
|
-
body = JSON.stringify(init.json);
|
|
1132
|
-
}
|
|
1133
|
-
const requestInit = {
|
|
1134
|
-
method,
|
|
1135
|
-
headers,
|
|
1136
|
-
signal: AbortSignal.timeout(this.timeoutMs)
|
|
1137
|
-
};
|
|
1138
|
-
if (body !== void 0) requestInit.body = body;
|
|
1502
|
+
const requestInit = this.prepareRequest(method, init);
|
|
1139
1503
|
let response;
|
|
1140
1504
|
try {
|
|
1141
1505
|
response = await this.fetchImpl(url, requestInit);
|
|
@@ -1146,13 +1510,17 @@ var XbergClient = class {
|
|
|
1146
1510
|
interval = nextBackoffInterval(interval, this.retryBackoff);
|
|
1147
1511
|
continue;
|
|
1148
1512
|
}
|
|
1513
|
+
if (init.controlPlane) throw new XbergError(`Network error contacting Enterprise control plane (${method} ${path})`, {
|
|
1514
|
+
status: 0,
|
|
1515
|
+
body: null
|
|
1516
|
+
});
|
|
1149
1517
|
throw new XbergError(`Network error contacting ${url}`, {
|
|
1150
1518
|
status: 0,
|
|
1151
1519
|
body: null,
|
|
1152
1520
|
cause
|
|
1153
1521
|
});
|
|
1154
1522
|
}
|
|
1155
|
-
if (response.ok) return response;
|
|
1523
|
+
if (response.ok || init.acceptRedirect && response.status === 303) return response;
|
|
1156
1524
|
if (this.retryOn.includes(response.status) && attempt < this.retries) {
|
|
1157
1525
|
attempt += 1;
|
|
1158
1526
|
const retryAfter = parseRetryAfterHeader(response.headers.get("retry-after"));
|
|
@@ -1297,6 +1665,50 @@ function createClient(options = {}) {
|
|
|
1297
1665
|
...options.fetch !== void 0 ? { fetch: options.fetch } : {}
|
|
1298
1666
|
});
|
|
1299
1667
|
}
|
|
1668
|
+
function sandboxForm(params) {
|
|
1669
|
+
if (params.file === void 0 && !(params.mode === "web" && params.url !== void 0 && params.url.length > 0)) throw new XbergError("Sandbox extraction requires a file or web mode with a URL", {
|
|
1670
|
+
status: 400,
|
|
1671
|
+
body: null
|
|
1672
|
+
});
|
|
1673
|
+
const form = new FormData();
|
|
1674
|
+
if (params.file !== void 0) {
|
|
1675
|
+
const { blob, filename } = toBlob(params.file);
|
|
1676
|
+
form.append("file", blob, filename);
|
|
1677
|
+
}
|
|
1678
|
+
for (const name of [
|
|
1679
|
+
"mode",
|
|
1680
|
+
"preset",
|
|
1681
|
+
"url"
|
|
1682
|
+
]) {
|
|
1683
|
+
const value = params[name];
|
|
1684
|
+
if (value !== void 0) form.append(name, value);
|
|
1685
|
+
}
|
|
1686
|
+
return form;
|
|
1687
|
+
}
|
|
1688
|
+
function prepareDocumentLineage(filenames, ids) {
|
|
1689
|
+
const fields = /* @__PURE__ */ new Map();
|
|
1690
|
+
if (ids === void 0) return fields;
|
|
1691
|
+
if (ids.length !== filenames.length) throw new XbergError("documentIds must contain one entry per file", {
|
|
1692
|
+
status: 400,
|
|
1693
|
+
body: null
|
|
1694
|
+
});
|
|
1695
|
+
const seen = /* @__PURE__ */ new Map();
|
|
1696
|
+
for (const [index, filename] of filenames.entries()) {
|
|
1697
|
+
const id = ids[index];
|
|
1698
|
+
if (id !== null && (typeof id !== "string" || !/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(id))) throw new XbergError("documentIds must contain UUID strings or null", {
|
|
1699
|
+
status: 400,
|
|
1700
|
+
body: null
|
|
1701
|
+
});
|
|
1702
|
+
const canonical = id === null ? null : id.toLowerCase();
|
|
1703
|
+
if (seen.has(filename) && seen.get(filename) !== canonical) throw new XbergError("Conflicting document IDs for the same filename", {
|
|
1704
|
+
status: 400,
|
|
1705
|
+
body: null
|
|
1706
|
+
});
|
|
1707
|
+
seen.set(filename, canonical);
|
|
1708
|
+
if (canonical !== null) fields.set(filename, canonical);
|
|
1709
|
+
}
|
|
1710
|
+
return fields;
|
|
1711
|
+
}
|
|
1300
1712
|
|
|
1301
1713
|
//#endregion
|
|
1302
1714
|
export { AuthError, NotFoundError, RateLimitError, SUCCESS_JOB_STATUSES, ServerError, TERMINAL_JOB_STATUSES, TimeoutError, ValidationError, XbergClient, XbergError, createClient };
|