@xberg-io/sdk 0.12.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/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.12.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;
@@ -692,18 +692,6 @@ var XbergClient = class {
692
692
  offset: params.offset
693
693
  } });
694
694
  }
695
- /** Enterprise backend `GET /v1/projects/{id}/billing`. */
696
- async getBilling(projectId) {
697
- return await this.backendRequest("GET", `/v1/projects/${encodePathSegment(projectId)}/billing`);
698
- }
699
- /** Enterprise backend `POST /v1/projects/{id}/billing/checkout`. */
700
- async createCheckout(projectId) {
701
- return await this.backendRequest("POST", `/v1/projects/${encodePathSegment(projectId)}/billing/checkout`);
702
- }
703
- /** Enterprise backend `POST /v1/projects/{id}/billing/portal`. */
704
- async createPortal(projectId) {
705
- return await this.backendRequest("POST", `/v1/projects/${encodePathSegment(projectId)}/billing/portal`);
706
- }
707
695
  /** Enterprise backend `GET /v1/projects/{id}/integrations`. */
708
696
  async backendListIntegrations(projectId, params = {}) {
709
697
  return await this.backendRequest("GET", `/v1/projects/${encodePathSegment(projectId)}/integrations`, { params: {
@@ -983,26 +971,40 @@ var XbergClient = class {
983
971
  if (params.options !== void 0) form.append("options", JSON.stringify(params.options));
984
972
  if (params.webhook !== void 0) form.append("webhook", JSON.stringify(params.webhook));
985
973
  appendPerFileConfigs(form, filenames, params.configs);
986
- const body = await this.requestJson("POST", "/v1/extract", {
974
+ return pendingJobs(parts, await this.requestJson("POST", "/v1/extract", {
987
975
  body: form,
988
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
989
990
  });
990
- const jobIds = body.job_ids ?? [];
991
- const now = (/* @__PURE__ */ new Date()).toISOString();
992
- return parts.map(({ blob, filename }, index) => {
993
- const id = jobIds[index];
994
- if (id === void 0) throw new XbergError(`Server returned ${jobIds.length} job IDs for ${params.files.length} files`, {
995
- status: 500,
996
- body
997
- });
998
- return {
999
- id,
1000
- filename,
1001
- mime_type: blob.type.length > 0 ? blob.type : OCTET_STREAM_MEDIA_TYPE,
1002
- status: "pending",
1003
- created_at: now
1004
- };
991
+ if (params.files.length === 0) throw new XbergError("extractKeyed called with no files", {
992
+ status: 400,
993
+ body: null
1005
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
+ }));
1006
1008
  }
1007
1009
  /** Fetch a tagged extraction or crawl job record (`GET /v1/jobs/{id}`). */
1008
1010
  async getJob(jobId, scope = {}) {
@@ -2279,6 +2281,30 @@ var XbergClient = class {
2279
2281
  }
2280
2282
  }
2281
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
+ }
2282
2308
  /** The `If-Match` header a room write sends: the room version, quoted as an entity tag. */
2283
2309
  function ifMatch(version) {
2284
2310
  if (!Number.isSafeInteger(version) || version < 0) throw new ValidationError(`Room version must be a non-negative integer, got ${String(version)}`, {