@xberg-io/sdk 0.7.0 → 0.8.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
@@ -1,5 +1,4 @@
1
1
  import createOpenApiClient from "openapi-fetch";
2
-
3
2
  //#region src/errors.ts
4
3
  var XbergError = class extends Error {
5
4
  status;
@@ -109,7 +108,6 @@ function parseRetryAfter(value) {
109
108
  if (Number.isNaN(parsed)) return;
110
109
  return Math.max(0, Math.ceil((parsed - Date.now()) / 1e3));
111
110
  }
112
-
113
111
  //#endregion
114
112
  //#region src/_internal.ts
115
113
  /**
@@ -121,7 +119,6 @@ function parseRetryAfter(value) {
121
119
  * because they appear in public client signatures.
122
120
  */
123
121
  const DEFAULT_RETRY_BACKOFF_CAP_MS = 3e4;
124
- const DEFAULT_BACKOFF_FACTOR = 2;
125
122
  /**
126
123
  * Caps an event-stream frame. The frames this endpoint sends are a few hundred
127
124
  * bytes; the cap exists so a server that never closes a frame cannot grow this
@@ -172,7 +169,7 @@ function buildQueryString(params) {
172
169
  }
173
170
  function nextBackoffInterval(current, strategy) {
174
171
  if (strategy === "constant") return current;
175
- return Math.min(current * DEFAULT_BACKOFF_FACTOR, DEFAULT_RETRY_BACKOFF_CAP_MS);
172
+ return Math.min(current * 2, DEFAULT_RETRY_BACKOFF_CAP_MS);
176
173
  }
177
174
  function parseRetryAfterHeader(value) {
178
175
  if (value === null) return;
@@ -256,7 +253,7 @@ var EventStreamDecoder = class {
256
253
  for (;;) {
257
254
  const boundary = this.nextLineBoundary();
258
255
  if (boundary === void 0) {
259
- if (this.buffer.length > MAX_EVENT_STREAM_FRAME_BYTES) throw new XbergError(`Crawl event stream sent a line longer than ${MAX_EVENT_STREAM_FRAME_BYTES} bytes`, {
256
+ if (this.buffer.length > 1048576) throw new XbergError(`Crawl event stream sent a line longer than ${MAX_EVENT_STREAM_FRAME_BYTES} bytes`, {
260
257
  status: 0,
261
258
  body: null
262
259
  });
@@ -300,7 +297,7 @@ var EventStreamDecoder = class {
300
297
  if (value.startsWith(" ")) value = value.slice(1);
301
298
  if (field === "data") {
302
299
  this.size += value.length + 1;
303
- if (this.size > MAX_EVENT_STREAM_FRAME_BYTES) throw new XbergError(`Crawl event frame exceeded ${MAX_EVENT_STREAM_FRAME_BYTES} bytes before the stream closed it`, {
300
+ if (this.size > 1048576) throw new XbergError(`Crawl event frame exceeded ${MAX_EVENT_STREAM_FRAME_BYTES} bytes before the stream closed it`, {
304
301
  status: 0,
305
302
  body: null
306
303
  });
@@ -324,7 +321,6 @@ function encodePathSegment(value) {
324
321
  });
325
322
  return encodeURIComponent(value);
326
323
  }
327
-
328
324
  //#endregion
329
325
  //#region src/types.ts
330
326
  /**
@@ -342,15 +338,6 @@ const TERMINAL_JOB_STATUSES = [
342
338
  * "completed but check warnings" result from a hard failure.
343
339
  */
344
340
  const SUCCESS_JOB_STATUSES = ["completed", "partial_success"];
345
-
346
- //#endregion
347
- //#region src/version.ts
348
- /**
349
- * Package version, synced from the repo-root `VERSION` file by
350
- * `scripts/sync-versions.py`. Used to build the `User-Agent` header. ~keep
351
- */
352
- const VERSION = "0.7.0";
353
-
354
341
  //#endregion
355
342
  //#region src/client.ts
356
343
  /**
@@ -372,10 +359,10 @@ const VERSION = "0.7.0";
372
359
  * and defaults to `baseUrl`. The backend methods use that origin and an optional
373
360
  * separate `controlPlaneToken`; existing Pro methods retain their data-plane routing.
374
361
  */
375
- const USER_AGENT = `xberg-io-sdk-typescript/${VERSION}`;
362
+ const USER_AGENT = `xberg-io-sdk-typescript/0.8.0`;
376
363
  const DEFAULT_TIMEOUT_MS = 3e4;
377
364
  const DEFAULT_POLL_INTERVAL_MS = 1e3;
378
- const DEFAULT_WAIT_TIMEOUT_MS = 5 * 6e4;
365
+ const DEFAULT_WAIT_TIMEOUT_MS = 3e5;
379
366
  const DEFAULT_RETRY_STATUSES = [
380
367
  429,
381
368
  502,
@@ -401,7 +388,7 @@ const OCTET_STREAM_MEDIA_TYPE = "application/octet-stream";
401
388
  /** Media type of the crawl-event stream, sent as `Accept` and served as `Content-Type`. */
402
389
  const EVENT_STREAM_MEDIA_TYPE = "text/event-stream";
403
390
  /** The `kind` values `CrawlEventV1` declares. A frame carrying anything else is rejected. */
404
- const CRAWL_EVENT_KINDS = new Set([
391
+ const CRAWL_EVENT_KINDS = /* @__PURE__ */ new Set([
405
392
  "page",
406
393
  "discovered",
407
394
  "complete",
@@ -460,6 +447,14 @@ var XbergClient = class {
460
447
  async getAuthConfig() {
461
448
  return await this.backendRequest("GET", `/auth/config`, { backendPublic: true });
462
449
  }
450
+ /** Enterprise backend `GET /auth/profile`. */
451
+ async getUserProfile() {
452
+ return await this.backendRequest("GET", "/auth/profile");
453
+ }
454
+ /** Enterprise backend `PATCH /auth/profile`. */
455
+ async updateUserProfile(body) {
456
+ return await this.backendRequest("PATCH", "/auth/profile", { json: body });
457
+ }
463
458
  /** Enterprise backend `POST /auth/login`. */
464
459
  async backendLogin(body) {
465
460
  return await this.backendRequest("POST", `/auth/login`, {
@@ -762,9 +757,9 @@ var XbergClient = class {
762
757
  };
763
758
  });
764
759
  }
765
- /** Fetch the current state of a job. */
760
+ /** Fetch a tagged extraction or crawl job record (`GET /v1/jobs/{id}`). */
766
761
  async getJob(jobId) {
767
- return await this.requestJson("GET", `${JOBS_PATH}/${encodePathSegment(jobId)}`);
762
+ return parseJobResponse(await this.requestJson("GET", `${JOBS_PATH}/${encodePathSegment(jobId)}`));
768
763
  }
769
764
  /**
770
765
  * Fetch a job's stored result document (`GET /v1/jobs/{id}/result`).
@@ -804,6 +799,10 @@ var XbergClient = class {
804
799
  let interval = initialInterval;
805
800
  for (;;) {
806
801
  const job = await this.getJob(jobId);
802
+ if (job.job_type !== "extraction") throw new ValidationError("expected extraction job, received crawl job", {
803
+ status: 200,
804
+ body: job
805
+ });
807
806
  if (TERMINAL_JOB_STATUSES.includes(job.status)) {
808
807
  if (SUCCESS_JOB_STATUSES.includes(job.status)) return job;
809
808
  throw new XbergError(`Job ${jobId} ended with status ${job.status}`, {
@@ -818,7 +817,7 @@ var XbergClient = class {
818
817
  });
819
818
  const delay = Math.min(interval, remaining);
820
819
  await this.sleep(delay);
821
- if (backoff === "exponential") interval = Math.min(interval * DEFAULT_BACKOFF_FACTOR, DEFAULT_RETRY_BACKOFF_CAP_MS);
820
+ if (backoff === "exponential") interval = Math.min(interval * 2, DEFAULT_RETRY_BACKOFF_CAP_MS);
822
821
  }
823
822
  }
824
823
  /** Wait for many jobs in parallel. */
@@ -1545,6 +1544,22 @@ var XbergClient = class {
1545
1544
  }
1546
1545
  }
1547
1546
  };
1547
+ function parseJobResponse(payload) {
1548
+ if (typeof payload !== "object" || payload === null || Array.isArray(payload)) throw new ValidationError("unexpected job response shape", {
1549
+ status: 200,
1550
+ body: payload
1551
+ });
1552
+ const record = payload;
1553
+ if (!("job_type" in record) && typeof record["filename"] === "string") return {
1554
+ ...record,
1555
+ job_type: "extraction"
1556
+ };
1557
+ if (record["job_type"] === "extraction" || record["job_type"] === "crawl") return record;
1558
+ throw new ValidationError("unexpected job_type", {
1559
+ status: 200,
1560
+ body: payload
1561
+ });
1562
+ }
1548
1563
  /**
1549
1564
  * Pair a diff response's status code with its body to build the
1550
1565
  * {@link DiffResult} union `diff`/`getDiffJob` return. `202` is the only
@@ -1707,7 +1722,7 @@ function prepareDocumentLineage(filenames, ids) {
1707
1722
  }
1708
1723
  return fields;
1709
1724
  }
1710
-
1711
1725
  //#endregion
1712
1726
  export { AuthError, NotFoundError, RateLimitError, SUCCESS_JOB_STATUSES, ServerError, TERMINAL_JOB_STATUSES, TimeoutError, ValidationError, XbergClient, XbergError, createClient };
1727
+
1713
1728
  //# sourceMappingURL=index.js.map