@xberg-io/sdk 0.5.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/dist/index.js CHANGED
@@ -350,7 +350,7 @@ const SUCCESS_JOB_STATUSES = ["completed", "partial_success"];
350
350
  * Package version, synced from the repo-root `VERSION` file by
351
351
  * `scripts/sync-versions.py`. Used to build the `User-Agent` header. ~keep
352
352
  */
353
- const VERSION = "0.5.0";
353
+ const VERSION = "0.6.0";
354
354
 
355
355
  //#endregion
356
356
  //#region src/client.ts
@@ -386,12 +386,10 @@ const DEFAULT_RETRY_STATUSES = [
386
386
  ];
387
387
  const DEFAULT_RETRY_BACKOFF_BASE_MS = 200;
388
388
  /**
389
- * Saved presets are the one shared resource whose *path* differs per tier:
390
- * Enterprise serves `/v1/saved_presets` (underscore), Pro `/v1/saved-presets`
391
- * (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.
392
391
  */
393
- const SAVED_PRESETS_PATH_ENTERPRISE = "/v1/saved_presets";
394
- const SAVED_PRESETS_PATH_PRO = "/v1/saved-presets";
392
+ const SAVED_PRESETS_PATH = "/v1/saved_presets";
395
393
  const AUTO_TUNE_PATH = "/v1/auto-tune";
396
394
  const TUNING_PROFILES_PATH = "/v1/tuning-profiles";
397
395
  const ENRICH_PATH = "/v1/enrich";
@@ -399,6 +397,9 @@ const EXTRACTIONS_PATH = "/v1/extractions";
399
397
  const DOCUMENTS_PATH = "/v1/documents";
400
398
  const JOBS_PATH = "/v1/jobs";
401
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";
402
403
  /** Media type of the crawl-event stream, sent as `Accept` and served as `Content-Type`. */
403
404
  const EVENT_STREAM_MEDIA_TYPE = "text/event-stream";
404
405
  /** The `kind` values `CrawlEventV1` declares. A frame carrying anything else is rejected. */
@@ -600,7 +601,8 @@ var XbergClient = class {
600
601
  return await this.backendRequest("GET", `/v1/projects/${encodePathSegment(projectId)}/integrations/${encodePathSegment(integrationId)}/documents`, { params: {
601
602
  mime_types: params.mimeTypes,
602
603
  folder_id: params.folderId,
603
- max_results: params.maxResults
604
+ limit: params.limit,
605
+ offset: params.offset
604
606
  } });
605
607
  }
606
608
  /** Enterprise backend `GET /v1/projects/{id}/integrations/{iid}/documents/{doc_id}`. */
@@ -686,6 +688,10 @@ var XbergClient = class {
686
688
  offset: params.offset
687
689
  } });
688
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
+ }
689
695
  /** Enterprise backend `POST /v1/projects/{id}/webhooks/{wh_id}/deliveries/{delivery_id}/retry`. */
690
696
  async retryWebhookDelivery(projectId, webhookId, deliveryId) {
691
697
  return await this.backendRequest("POST", `/v1/projects/${encodePathSegment(projectId)}/webhooks/${encodePathSegment(webhookId)}/deliveries/${encodePathSegment(deliveryId)}/retry`);
@@ -735,17 +741,15 @@ var XbergClient = class {
735
741
  if (documentIds.size > 0) await this.requireTier("enterprise", "extract document lineage");
736
742
  const form = new FormData();
737
743
  for (const [filename, documentId] of documentIds) form.append(`document_id-${filename}`, documentId);
738
- for (const file of params.files) {
739
- const { blob, filename } = toBlob(file);
740
- form.append("file", blob, filename);
741
- }
744
+ const parts = params.files.map(toBlob);
745
+ for (const { blob, filename } of parts) form.append("file", blob, filename);
742
746
  if (params.options !== void 0) form.append("options", JSON.stringify(params.options));
743
747
  if (params.webhook !== void 0) form.append("webhook", JSON.stringify(params.webhook));
744
748
  appendPerFileConfigs(form, filenames, params.configs);
745
749
  const body = await this.requestJson("POST", "/v1/extract", { body: form });
746
750
  const jobIds = body.job_ids ?? [];
747
751
  const now = (/* @__PURE__ */ new Date()).toISOString();
748
- return params.files.map((file, index) => {
752
+ return parts.map(({ blob, filename }, index) => {
749
753
  const id = jobIds[index];
750
754
  if (id === void 0) throw new XbergError(`Server returned ${jobIds.length} job IDs for ${params.files.length} files`, {
751
755
  status: 500,
@@ -753,7 +757,8 @@ var XbergClient = class {
753
757
  });
754
758
  return {
755
759
  id,
756
- filename: describeFile(file),
760
+ filename,
761
+ mime_type: blob.type.length > 0 ? blob.type : OCTET_STREAM_MEDIA_TYPE,
757
762
  status: "pending",
758
763
  created_at: now
759
764
  };
@@ -915,33 +920,35 @@ var XbergClient = class {
915
920
  async getRagJob(jobId) {
916
921
  return await this.requestJson("GET", `/v1/rag/jobs/${encodePathSegment(jobId)}`);
917
922
  }
918
- /** List the project's saved presets (`GET /v1/saved_presets`, `/v1/saved-presets` on Pro). */
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`). */
919
931
  async listSavedPresets(params = {}) {
920
- const path = await this.savedPresetsPath();
921
- return await this.requestJson("GET", path, { params: {
932
+ return await this.requestJson("GET", SAVED_PRESETS_PATH, { params: {
922
933
  limit: params.limit,
923
934
  offset: params.offset
924
935
  } });
925
936
  }
926
- /** Create a saved preset (`POST /v1/saved_presets`, `/v1/saved-presets` on Pro). */
937
+ /** Create a saved preset (`POST /v1/saved_presets`). */
927
938
  async createSavedPreset(body) {
928
- const path = await this.savedPresetsPath();
929
- return await this.requestJson("POST", path, { json: body });
939
+ return await this.requestJson("POST", SAVED_PRESETS_PATH, { json: body });
930
940
  }
931
- /** Fetch one saved preset (`GET /v1/saved_presets/{presetId}`, `/v1/saved-presets/{id}` on Pro). */
941
+ /** Fetch one saved preset (`GET /v1/saved_presets/{preset_id}`). */
932
942
  async getSavedPreset(presetId) {
933
- const path = await this.savedPresetsPath(presetId);
934
- return await this.requestJson("GET", path);
943
+ return await this.requestJson("GET", this.savedPresetPath(presetId));
935
944
  }
936
- /** Update a saved preset (`PATCH /v1/saved_presets/{presetId}`, `/v1/saved-presets/{id}` on Pro). */
945
+ /** Update a saved preset (`PATCH /v1/saved_presets/{preset_id}`). */
937
946
  async updateSavedPreset(presetId, body) {
938
- const path = await this.savedPresetsPath(presetId);
939
- return await this.requestJson("PATCH", path, { json: body });
947
+ return await this.requestJson("PATCH", this.savedPresetPath(presetId), { json: body });
940
948
  }
941
- /** Delete a saved preset (`DELETE /v1/saved_presets/{presetId}`, `/v1/saved-presets/{id}` on Pro). */
949
+ /** Delete a saved preset (`DELETE /v1/saved_presets/{preset_id}`). */
942
950
  async deleteSavedPreset(presetId) {
943
- const path = await this.savedPresetsPath(presetId);
944
- await this.requestJson("DELETE", path);
951
+ await this.requestJson("DELETE", this.savedPresetPath(presetId));
945
952
  }
946
953
  /** List the project's auto-tune jobs (`GET /v1/auto-tune`). */
947
954
  async listAutoTuneJobs(params = {}) {
@@ -979,6 +986,17 @@ var XbergClient = class {
979
986
  async deleteAutoTuneJob(autoTuneJobId) {
980
987
  await this.requestJson("DELETE", this.autoTunePath(autoTuneJobId));
981
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
+ }
982
1000
  /** Promote an auto-tune result to a named tuning profile (`POST /v1/auto-tune/{id}/promote`). */
983
1001
  async promoteAutoTuneProfile(autoTuneJobId, body) {
984
1002
  return await this.requestJson("POST", `${this.autoTunePath(autoTuneJobId)}/promote`, { json: body });
@@ -1002,6 +1020,69 @@ var XbergClient = class {
1002
1020
  async deleteTuningProfile(profileId) {
1003
1021
  await this.requestJson("DELETE", this.tuningProfilePath(profileId));
1004
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
+ }
1005
1086
  /** Pro only: fetch the instance's accepted auth methods (`GET /auth/config`). */
1006
1087
  async authConfig() {
1007
1088
  await this.requireTier("pro", "authConfig");
@@ -1012,6 +1093,33 @@ var XbergClient = class {
1012
1093
  await this.requireTier("pro", "login");
1013
1094
  return this.requestJson("POST", "/auth/login", { json: body });
1014
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
+ }
1015
1123
  /** Pro only: fetch a project's RAG config (`GET /v1/projects/{projectId}/rag-config`). */
1016
1124
  async getRagConfig(projectId) {
1017
1125
  await this.requireTier("pro", "getRagConfig");
@@ -1096,7 +1204,8 @@ var XbergClient = class {
1096
1204
  return this.requestJson("GET", `${this.integrationPath(projectId, integrationId)}/documents`, { params: {
1097
1205
  mime_types: params.mimeTypes,
1098
1206
  folder_id: params.folderId,
1099
- max_results: params.maxResults
1207
+ limit: params.limit,
1208
+ offset: params.offset
1100
1209
  } });
1101
1210
  }
1102
1211
  /**
@@ -1169,71 +1278,29 @@ var XbergClient = class {
1169
1278
  } });
1170
1279
  }
1171
1280
  /**
1172
- * Enterprise only: download one rendered page of an extraction job
1173
- * (`GET /v1/jobs/{jobId}/pages/{pageNumber}`). The response is a PNG image —
1174
- * raw bytes, not JSON. `pageNumber` is 1-indexed.
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.
1175
1287
  */
1176
- async getJobPage(jobId, pageNumber) {
1177
- await this.requireTier("enterprise", "getJobPage");
1178
- const path = `${JOBS_PATH}/${encodePathSegment(jobId)}/pages/${encodePathSegment(String(pageNumber))}`;
1179
- return this.requestBytes("GET", path);
1180
- }
1181
- /** Enterprise only: submit text for enrichment (`POST /v1/enrich`). */
1182
- async submitEnrich(body) {
1183
- await this.requireTier("enterprise", "submitEnrich");
1184
- return this.requestJson("POST", ENRICH_PATH, { json: body });
1185
- }
1186
- /** Enterprise only: fetch an enrichment job's status (`GET /v1/enrich/{jobId}`). */
1187
- async getEnrichStatus(jobId) {
1188
- await this.requireTier("enterprise", "getEnrichStatus");
1189
- return this.requestJson("GET", `${ENRICH_PATH}/${encodePathSegment(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
+ } });
1190
1294
  }
1191
1295
  /**
1192
- * Enterprise only: stream a crawl job's events
1193
- * (`GET /v1/crawl-jobs/{crawlJobId}/events`, Server-Sent Events).
1194
- *
1195
- * Returns an `AsyncIterable` of the `kind`-discriminated {@link CrawlEvent}
1196
- * union; the server closes the stream after the `complete` event.
1197
- *
1198
- * ```ts
1199
- * for await (const event of client.streamCrawlEvents(crawlJobId)) {
1200
- * if (event.kind === "page") {
1201
- * console.log(event.url, event.status_code);
1202
- * }
1203
- * }
1204
- * ```
1205
- *
1206
- * Nothing is requested — not even the `/healthz` tier probe — until
1207
- * iteration begins, and the response body is cancelled when iteration ends:
1208
- * on `complete`, on `break`/`return` out of the loop, on a thrown error, or
1209
- * when `options.signal` aborts. A stream is idle between events by design,
1210
- * so unlike every other method here it carries no request timeout and is not
1211
- * routed through the retry engine — a retried subscription would redeliver
1212
- * 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.
1213
1299
  */
1214
- streamCrawlEvents(crawlJobId, options = {}) {
1215
- const path = `${CRAWL_JOBS_PATH}/${encodePathSegment(crawlJobId)}/events`;
1216
- const open = async () => {
1217
- await this.requireTier("enterprise", "streamCrawlEvents");
1218
- return this.openEventStream(path, options.signal);
1219
- };
1220
- return { [Symbol.asyncIterator]: () => iterateCrawlEvents(open) };
1221
- }
1222
- /** Enterprise only: request a presigned upload URL (`POST /v1/uploads/presign`). */
1223
- async presignUpload(body) {
1224
- await this.requireTier("enterprise", "presignUpload");
1225
- return this.requestJson("POST", "/v1/uploads/presign", { json: body });
1226
- }
1227
- /** Enterprise only: confirm a presigned upload (`POST /v1/uploads/confirm`). */
1228
- async confirmUpload(body) {
1229
- await this.requireTier("enterprise", "confirmUpload");
1230
- return this.requestJson("POST", "/v1/uploads/confirm", { json: body });
1231
- }
1232
- /** Enterprise only: fetch usage/metering data (`GET /v1/usage`). */
1233
- async usage(params) {
1234
- await this.requireTier("enterprise", "usage");
1235
- const init = params !== void 0 ? { params } : {};
1236
- 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);
1237
1304
  }
1238
1305
  /** Build `/v1/projects/{projectId}` with the id percent-encoded. */
1239
1306
  projectPath(projectId) {
@@ -1247,6 +1314,10 @@ var XbergClient = class {
1247
1314
  documentPath(documentId) {
1248
1315
  return `${DOCUMENTS_PATH}/${encodePathSegment(documentId)}`;
1249
1316
  }
1317
+ /** Build `/v1/saved_presets/{preset_id}` with the id percent-encoded. */
1318
+ savedPresetPath(presetId) {
1319
+ return `${SAVED_PRESETS_PATH}/${encodePathSegment(presetId)}`;
1320
+ }
1250
1321
  /** Build `/v1/auto-tune/{id}` with the id percent-encoded. */
1251
1322
  autoTunePath(autoTuneJobId) {
1252
1323
  return `${AUTO_TUNE_PATH}/${encodePathSegment(autoTuneJobId)}`;
@@ -1255,14 +1326,9 @@ var XbergClient = class {
1255
1326
  tuningProfilePath(profileId) {
1256
1327
  return `${TUNING_PROFILES_PATH}/${encodePathSegment(profileId)}`;
1257
1328
  }
1258
- /**
1259
- * Resolve the tier and render the saved-preset path in that tier's spelling:
1260
- * `/v1/saved-presets` on Pro, `/v1/saved_presets` everywhere else. Pass a
1261
- * `presetId` for the single-preset routes.
1262
- */
1263
- async savedPresetsPath(presetId) {
1264
- const base = await this.resolveTier() === "pro" ? SAVED_PRESETS_PATH_PRO : SAVED_PRESETS_PATH_ENTERPRISE;
1265
- return presetId === void 0 ? base : `${base}/${encodePathSegment(presetId)}`;
1329
+ /** Build `/v1/webhooks/{webhook_id}/deliveries` with the id percent-encoded. */
1330
+ webhookDeliveriesPath(webhookId) {
1331
+ return `${WEBHOOKS_PATH}/${encodePathSegment(webhookId)}/deliveries`;
1266
1332
  }
1267
1333
  /**
1268
1334
  * Return the effective tier — an explicit `target` if set, else probed from