@relyio/sdk 0.14.0 → 0.16.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.
Files changed (40) hide show
  1. package/CHANGELOG.md +59 -0
  2. package/dist/chunk-7BZW6XYJ.cjs +433 -0
  3. package/dist/chunk-CQHEG7QA.js +411 -0
  4. package/dist/{chunk-PCFTJLEP.js → chunk-DIZY6CKM.js} +2 -2
  5. package/dist/{chunk-X4KSS7PP.cjs → chunk-GHYB6IZK.cjs} +2 -2
  6. package/dist/{chunk-DBBZVZOS.js → chunk-NIUOPIIB.js} +413 -552
  7. package/dist/{chunk-GUPV2M3X.cjs → chunk-RLLZUFDB.cjs} +450 -585
  8. package/dist/client/index.cjs +4 -3
  9. package/dist/client/index.d.cts +3 -4
  10. package/dist/client/index.d.ts +3 -4
  11. package/dist/client/index.js +2 -1
  12. package/dist/{define-content-type-DOrZb_a_.d.ts → define-content-type-CAWSlgn0.d.ts} +579 -81
  13. package/dist/{define-content-type-BUZeWtpk.d.cts → define-content-type-LkI0rS2W.d.cts} +579 -81
  14. package/dist/{define-schema-5aHmsA8j.d.ts → define-schema-Dxu3RoHV.d.ts} +1 -1
  15. package/dist/{define-schema-nCfZeboB.d.cts → define-schema-wlsJOrnY.d.cts} +1 -1
  16. package/dist/{index-DOhFQbv7.d.ts → index-BH8JksfG.d.ts} +472 -179
  17. package/dist/{index-B97ZDj44.d.ts → index-CGtYxUuh.d.ts} +1 -1
  18. package/dist/{index-C-pcllqY.d.cts → index-CcHmRALk.d.cts} +1 -1
  19. package/dist/{index-DgVV5Nj7.d.cts → index-D80MXUkf.d.cts} +472 -179
  20. package/dist/index.cjs +96 -71
  21. package/dist/index.d.cts +26 -16
  22. package/dist/index.d.ts +26 -16
  23. package/dist/index.js +4 -3
  24. package/dist/markdown/index.cjs +10 -2
  25. package/dist/markdown/index.d.cts +12 -3
  26. package/dist/markdown/index.d.ts +12 -3
  27. package/dist/markdown/index.js +10 -2
  28. package/dist/preview/index.cjs +29 -0
  29. package/dist/preview/index.d.cts +117 -0
  30. package/dist/preview/index.d.ts +117 -0
  31. package/dist/preview/index.js +4 -0
  32. package/dist/rich-text/index.d.cts +2 -2
  33. package/dist/rich-text/index.d.ts +2 -2
  34. package/dist/schema/index.cjs +33 -33
  35. package/dist/schema/index.d.cts +3 -3
  36. package/dist/schema/index.d.ts +3 -3
  37. package/dist/schema/index.js +1 -1
  38. package/dist/types/index.d.cts +1 -1
  39. package/dist/types/index.d.ts +1 -1
  40. package/package.json +10 -4
@@ -1,11 +1,18 @@
1
1
  'use strict';
2
2
 
3
3
  var chunkLSRPMNPT_cjs = require('./chunk-LSRPMNPT.cjs');
4
+ var chunk7BZW6XYJ_cjs = require('./chunk-7BZW6XYJ.cjs');
4
5
  var chunkTZL374LS_cjs = require('./chunk-TZL374LS.cjs');
5
6
  var chunkMWMSFIWN_cjs = require('./chunk-MWMSFIWN.cjs');
6
7
 
7
8
  /* RelyIO SDK - Built with ❤️ by the RelyIO Team */
8
9
 
10
+ // src/config/key-kind.ts
11
+ var PUBLISHABLE_KEY_PREFIX = "rly_pub_";
12
+ var isPublishableKey = /* @__PURE__ */ chunkMWMSFIWN_cjs.__name((apiKey) => apiKey?.startsWith(PUBLISHABLE_KEY_PREFIX) === true, "isPublishableKey");
13
+ var PREVIEW_KEY_PREFIX = "rly_prev_";
14
+ var isPreviewKey = /* @__PURE__ */ chunkMWMSFIWN_cjs.__name((apiKey) => apiKey?.startsWith(PREVIEW_KEY_PREFIX) === true, "isPreviewKey");
15
+
9
16
  // src/errors/sdk-error.ts
10
17
  var _SDKError = class _SDKError extends Error {
11
18
  constructor(message, statusCode, cause, context) {
@@ -59,19 +66,84 @@ var _SDKError = class _SDKError extends Error {
59
66
  return this.code === errorType;
60
67
  }
61
68
  /**
62
- * Create a new error with additional context
69
+ * Create a copy of this error with additional context.
70
+ *
71
+ * The copy is made from this error's own properties, not by calling a constructor: subclasses
72
+ * declare constructors of their own (violations, a timeout, a feature, a failed index second),
73
+ * and no single argument order fits them all. Rebuilding through the base order put the status
74
+ * code in the subclass's second slot. Copying keeps every field, the subclass's own included, and
75
+ * the original `timestamp` and `stack`, since it is the same failure.
76
+ *
77
+ * `Object.create` runs no constructor, so a `#private` field would not survive the copy; none
78
+ * exist in this directory. `stack` is not an own property on V8 and is copied by hand below.
63
79
  */
64
80
  withContext(context) {
65
- const Constructor = this.constructor;
66
- return new Constructor(this.message, this.statusCode, this.cause, {
67
- ...this.context,
68
- ...context
81
+ return Object.create(Object.getPrototypeOf(this), {
82
+ ...Object.getOwnPropertyDescriptors(this),
83
+ stack: { value: this.stack, writable: true, enumerable: false, configurable: true },
84
+ context: {
85
+ value: { ...this.context, ...context },
86
+ writable: true,
87
+ enumerable: true,
88
+ configurable: true
89
+ }
69
90
  });
70
91
  }
71
92
  };
72
93
  chunkMWMSFIWN_cjs.__name(_SDKError, "SDKError");
73
94
  var SDKError = _SDKError;
74
95
 
96
+ // src/errors/content-errors.ts
97
+ var _ResourceNotFoundError = class _ResourceNotFoundError extends SDKError {
98
+ constructor(message = "Resource not found", statusCode = 404, cause, context) {
99
+ super(message, statusCode, cause, context);
100
+ chunkMWMSFIWN_cjs.__publicField(this, "code", "RESOURCE_NOT_FOUND");
101
+ chunkMWMSFIWN_cjs.__publicField(this, "retryable", false);
102
+ }
103
+ getUserMessage() {
104
+ const resourceType = this.context?.resourceType;
105
+ const resourceId = this.context?.resourceId;
106
+ if (resourceType != null && resourceId != null) {
107
+ return `${resourceType} with ID "${resourceId}" was not found.`;
108
+ }
109
+ return "The requested resource was not found.";
110
+ }
111
+ };
112
+ chunkMWMSFIWN_cjs.__name(_ResourceNotFoundError, "ResourceNotFoundError");
113
+ var ResourceNotFoundError = _ResourceNotFoundError;
114
+ var _ResourceConflictError = class _ResourceConflictError extends SDKError {
115
+ constructor(message = "Resource conflict", statusCode = 409, cause, context) {
116
+ super(message, statusCode, cause, context);
117
+ chunkMWMSFIWN_cjs.__publicField(this, "code", "RESOURCE_CONFLICT");
118
+ chunkMWMSFIWN_cjs.__publicField(this, "retryable", false);
119
+ }
120
+ getUserMessage() {
121
+ return "The resource could not be created or updated due to a conflict.";
122
+ }
123
+ };
124
+ chunkMWMSFIWN_cjs.__name(_ResourceConflictError, "ResourceConflictError");
125
+ var ResourceConflictError = _ResourceConflictError;
126
+ var _ResourceExpiredError = class _ResourceExpiredError extends SDKError {
127
+ constructor(message = "Resource has expired", statusCode = 410, cause, context) {
128
+ super(message, statusCode, cause, context);
129
+ chunkMWMSFIWN_cjs.__publicField(this, "code", "RESOURCE_EXPIRED");
130
+ chunkMWMSFIWN_cjs.__publicField(this, "retryable", false);
131
+ }
132
+ getUserMessage() {
133
+ return "The resource is no longer available.";
134
+ }
135
+ };
136
+ chunkMWMSFIWN_cjs.__name(_ResourceExpiredError, "ResourceExpiredError");
137
+ var ResourceExpiredError = _ResourceExpiredError;
138
+ function isResourceNotFound(error) {
139
+ return error instanceof ResourceNotFoundError;
140
+ }
141
+ chunkMWMSFIWN_cjs.__name(isResourceNotFound, "isResourceNotFound");
142
+ function isMissingEntry(error) {
143
+ return error instanceof ResourceNotFoundError && error.context?.resourceType === "entry";
144
+ }
145
+ chunkMWMSFIWN_cjs.__name(isMissingEntry, "isMissingEntry");
146
+
75
147
  // src/errors/contract-errors.ts
76
148
  var _MissingApiKeyError = class _MissingApiKeyError extends SDKError {
77
149
  constructor(message = "No API key was sent", context) {
@@ -184,7 +256,7 @@ var _TransactionRolledBackError = class _TransactionRolledBackError extends SDKE
184
256
  this.failedIndex = failedIndex;
185
257
  }
186
258
  getUserMessage() {
187
- return this.failedIndex === void 0 ? "The batch was rolled back; nothing was written." : `The batch was rolled back at operation ${this.failedIndex}; nothing was written.`;
259
+ return this.failedIndex === void 0 ? "The batch was rolled back; nothing was written." : `The batch was rolled back; nothing was written. This refusal is for operation ${this.failedIndex} of the batch, which is not necessarily the one that failed.`;
188
260
  }
189
261
  };
190
262
  chunkMWMSFIWN_cjs.__name(_TransactionRolledBackError, "TransactionRolledBackError");
@@ -258,57 +330,6 @@ var _InvalidApiKeyError = class _InvalidApiKeyError extends SDKError {
258
330
  chunkMWMSFIWN_cjs.__name(_InvalidApiKeyError, "InvalidApiKeyError");
259
331
  var InvalidApiKeyError = _InvalidApiKeyError;
260
332
 
261
- // src/errors/content-errors.ts
262
- var _ResourceNotFoundError = class _ResourceNotFoundError extends SDKError {
263
- constructor(message = "Resource not found", statusCode = 404, cause, context) {
264
- super(message, statusCode, cause, context);
265
- chunkMWMSFIWN_cjs.__publicField(this, "code", "RESOURCE_NOT_FOUND");
266
- chunkMWMSFIWN_cjs.__publicField(this, "retryable", false);
267
- }
268
- getUserMessage() {
269
- const resourceType = this.context?.resourceType;
270
- const resourceId = this.context?.resourceId;
271
- if (resourceType != null && resourceId != null) {
272
- return `${resourceType} with ID "${resourceId}" was not found.`;
273
- }
274
- return "The requested resource was not found.";
275
- }
276
- };
277
- chunkMWMSFIWN_cjs.__name(_ResourceNotFoundError, "ResourceNotFoundError");
278
- var ResourceNotFoundError = _ResourceNotFoundError;
279
- var _ResourceConflictError = class _ResourceConflictError extends SDKError {
280
- constructor(message = "Resource conflict", statusCode = 409, cause, context) {
281
- super(message, statusCode, cause, context);
282
- chunkMWMSFIWN_cjs.__publicField(this, "code", "RESOURCE_CONFLICT");
283
- chunkMWMSFIWN_cjs.__publicField(this, "retryable", false);
284
- }
285
- getUserMessage() {
286
- return "The resource could not be created or updated due to a conflict.";
287
- }
288
- };
289
- chunkMWMSFIWN_cjs.__name(_ResourceConflictError, "ResourceConflictError");
290
- var ResourceConflictError = _ResourceConflictError;
291
- var _ResourceExpiredError = class _ResourceExpiredError extends SDKError {
292
- constructor(message = "Resource has expired", statusCode = 410, cause, context) {
293
- super(message, statusCode, cause, context);
294
- chunkMWMSFIWN_cjs.__publicField(this, "code", "RESOURCE_EXPIRED");
295
- chunkMWMSFIWN_cjs.__publicField(this, "retryable", false);
296
- }
297
- getUserMessage() {
298
- return "The resource is no longer available.";
299
- }
300
- };
301
- chunkMWMSFIWN_cjs.__name(_ResourceExpiredError, "ResourceExpiredError");
302
- var ResourceExpiredError = _ResourceExpiredError;
303
- function isResourceNotFound(error) {
304
- return error instanceof ResourceNotFoundError;
305
- }
306
- chunkMWMSFIWN_cjs.__name(isResourceNotFound, "isResourceNotFound");
307
- function isMissingEntry(error) {
308
- return error instanceof ResourceNotFoundError && error.context?.resourceType === "entry";
309
- }
310
- chunkMWMSFIWN_cjs.__name(isMissingEntry, "isMissingEntry");
311
-
312
333
  // src/errors/network-errors.ts
313
334
  var _NetworkError = class _NetworkError extends SDKError {
314
335
  constructor(message = "Network request failed", statusCode, cause, context) {
@@ -416,229 +437,6 @@ var _InvalidPayloadError = class _InvalidPayloadError extends BaseValidationErro
416
437
  chunkMWMSFIWN_cjs.__name(_InvalidPayloadError, "InvalidPayloadError");
417
438
  var InvalidPayloadError = _InvalidPayloadError;
418
439
 
419
- // ../../platform/api-contract/dist/chunk-46347LG2.js
420
- function defineRoute(route) {
421
- if (route.kind === "raw" && route.standardShape === void 0) {
422
- throw new Error("kind 'raw' requires a named StandardShape");
423
- }
424
- if (route.kind === "raw" && route.success === 302 && !route.headers.some((header) => header.name === "Location")) {
425
- throw new Error("a raw route declaring success 302 must declare its 'Location' header");
426
- }
427
- if (route.kind === "stream" && route.stream === void 0) {
428
- throw new Error("kind 'stream' requires a StreamDeclaration");
429
- }
430
- if (route.kind === "collection" && route.page === void 0) {
431
- throw new Error("kind 'collection' requires a page dialect");
432
- }
433
- if (route.queues === true) {
434
- if (route.kind !== "object" && route.kind !== "empty") {
435
- throw new Error(
436
- `kind '${route.kind}' cannot declare \`queues\`: only an object or empty route answers 202 beside its own status`
437
- );
438
- }
439
- if (route.kind === "object" && route.success === 202) {
440
- throw new Error("a route whose own status is 202 cannot also declare `queues`");
441
- }
442
- }
443
- if ((route.kind === "object" || route.kind === "collection") && route.negotiated !== void 0) {
444
- refuseMismatchedAlternate(route, route.negotiated["text/event-stream"]);
445
- }
446
- return route;
447
- }
448
- chunkMWMSFIWN_cjs.__name(defineRoute, "defineRoute");
449
- function refuseMismatchedAlternate(route, stream) {
450
- if (stream.kind !== "stream") {
451
- throw new Error("a negotiated 'text/event-stream' alternate must be kind 'stream'");
452
- }
453
- if (stream.stream.mediaType !== "text/event-stream") {
454
- throw new Error(
455
- `a negotiated 'text/event-stream' alternate declares media type "${stream.stream.mediaType}"`
456
- );
457
- }
458
- const own = [...new Set(route.codes)].sort();
459
- const alternate = [...new Set(stream.codes)].sort();
460
- if (own.length !== alternate.length || own.some((code, index) => code !== alternate[index])) {
461
- throw new Error(
462
- `a negotiated alternate refuses with [${alternate.join(", ")}] while its route refuses with [${own.join(", ")}]; one route refuses with one set of codes on every transport`
463
- );
464
- }
465
- }
466
- chunkMWMSFIWN_cjs.__name(refuseMismatchedAlternate, "refuseMismatchedAlternate");
467
-
468
- // ../../platform/api-contract/dist/index.js
469
- var HEADER_RETRY_AFTER = { name: "Retry-After" };
470
- var HEADER_IF_MATCH = {
471
- name: "If-Match"};
472
- function entityTag(parts) {
473
- return `"${parts.entryUid}:${parts.locale}:${parts.version}:${parts.sharedVersion}"`;
474
- }
475
- chunkMWMSFIWN_cjs.__name(entityTag, "entityTag");
476
- var HEADER_IDEMPOTENCY_KEY = {
477
- name: "Idempotency-Key"};
478
- var FRESH_PARAMETER = "_fresh";
479
- var VISITOR_LIVE_PATH = "/visitor/changes";
480
- var VISITOR_QUERY = {
481
- /** The publishable key. */
482
- key: "key",
483
- /** A dataset id or name the key reaches; absent, the key's default dataset. */
484
- dataset: "dataset",
485
- /** The cursor to continue from; absent, the socket starts now. */
486
- since: "since",
487
- /** Comma-separated content types to keep; absent keeps every type. */
488
- types: "types",
489
- /** Comma-separated entry ids to keep; absent keeps every entry. */
490
- ids: "ids",
491
- /** The poll's client id. Required on a poll, and not read on a socket. */
492
- client: "client"
493
- };
494
- var VISITOR_CURSOR = /^[\w.~-]{1,256}$/;
495
- var VISITOR_POLL_INTERVAL_MS = 15e3;
496
- var VISITOR_KEEPALIVE = { request: "ping", response: "pong" };
497
- var VISITOR_FRAMES = {
498
- opened: "feed.opened",
499
- changes: "feed.changes",
500
- resync: "feed.resync"
501
- };
502
- defineRoute({
503
- kind: "object",
504
- headers: [HEADER_RETRY_AFTER],
505
- codes: [
506
- "REQUEST_INVALID",
507
- "MISSING_API_KEY",
508
- "INVALID_API_KEY",
509
- "ACCESS_DENIED",
510
- "METHOD_NOT_ALLOWED",
511
- "SERVICE_INDETERMINATE",
512
- "USAGE_QUOTA_EXCEEDED",
513
- "RATE_LIMIT_EXCEEDED"
514
- ]
515
- });
516
- var VISITOR_CLOSE_CODES = {
517
- /** A query the door cannot read: a malformed `since`, filter, `dataset` or `client`. */
518
- requestInvalid: 4400,
519
- /** No publishable key, or one that is unknown, revoked, expired, a secret key or a preview key. */
520
- keyRefused: 4401,
521
- /** The page's `Origin` is absent, or not on the key's allowed origins. */
522
- originRefused: 4403,
523
- /** `dataset` names nothing the key reaches. */
524
- datasetRefused: 4404,
525
- /** The key's scope, the project's counter or the feed could not be reached just now. */
526
- unavailable: 1013,
527
- /**
528
- * The project holds as many visitor connections as its plan allows — Starter's 100 — or its
529
- * Organization is suspended. As HTTP's 402: more needs a bigger plan, or visitors leaving.
530
- */
531
- allowanceReached: 4402,
532
- /** This client's address holds as many connections to the project as one address may. */
533
- addressLimitReached: 4429,
534
- /** The project is at its per-project safety ceiling — Pro's 50,000 — whatever it would pay for. */
535
- ceilingReached: 4503
536
- };
537
- var VISITOR_CLOSE_RETRY = {
538
- 4400: "stop",
539
- 4401: "stop",
540
- 4403: "stop",
541
- 4404: "stop",
542
- 1013: "retry",
543
- 4402: "back-off",
544
- 4429: "back-off",
545
- 4503: "back-off"
546
- };
547
- var VISITOR_POLL_RETRY = {
548
- REQUEST_INVALID: "stop",
549
- MISSING_API_KEY: "stop",
550
- INVALID_API_KEY: "stop",
551
- ACCESS_DENIED: "stop",
552
- METHOD_NOT_ALLOWED: "stop",
553
- SERVICE_INDETERMINATE: "retry",
554
- USAGE_QUOTA_EXCEEDED: "back-off",
555
- RATE_LIMIT_EXCEEDED: "back-off"
556
- };
557
- var VISITOR_ADMISSION_RETRY_AFTER_SECONDS = 60;
558
- function parseVisitorFrame(text) {
559
- let value;
560
- try {
561
- value = JSON.parse(text);
562
- } catch {
563
- return null;
564
- }
565
- if (!isRecord2(value) || !isCursor(value.cursor)) return null;
566
- switch (value.type) {
567
- case VISITOR_FRAMES.opened: {
568
- return hasOnly(value, ["type", "cursor"]) ? { type: VISITOR_FRAMES.opened, cursor: value.cursor } : null;
569
- }
570
- case VISITOR_FRAMES.changes: {
571
- const changes = hasOnly(value, ["type", "changes", "cursor"]) ? readVisitorChanges(value.changes) : null;
572
- return changes === null ? null : { type: VISITOR_FRAMES.changes, changes, cursor: value.cursor };
573
- }
574
- case VISITOR_FRAMES.resync: {
575
- return hasOnly(value, ["type", "reason", "cursor"]) && isResyncReason(value.reason) ? { type: VISITOR_FRAMES.resync, reason: value.reason, cursor: value.cursor } : null;
576
- }
577
- default: {
578
- return null;
579
- }
580
- }
581
- }
582
- chunkMWMSFIWN_cjs.__name(parseVisitorFrame, "parseVisitorFrame");
583
- function readVisitorPollAnswer(value) {
584
- if (!isRecord2(value) || !isCursor(value.cursor)) return null;
585
- if (value.kind === "resync") {
586
- return hasOnly(value, ["kind", "reason", "cursor"]) && isResyncReason(value.reason) ? { kind: "resync", reason: value.reason, cursor: value.cursor } : null;
587
- }
588
- if (value.kind !== "changes" || !hasOnly(value, ["kind", "changes", "cursor"])) return null;
589
- const changes = readVisitorChanges(value.changes);
590
- return changes === null ? null : { kind: "changes", changes, cursor: value.cursor };
591
- }
592
- chunkMWMSFIWN_cjs.__name(readVisitorPollAnswer, "readVisitorPollAnswer");
593
- var CHANGE_KINDS = /* @__PURE__ */ new Set([
594
- "published",
595
- "updated",
596
- "unpublished",
597
- "deleted"
598
- ]);
599
- var RESYNC_REASONS = /* @__PURE__ */ new Set([
600
- "retention",
601
- "dataset-replaced",
602
- "ahead-of-head",
603
- "foreign-cursor",
604
- "too-far-behind"
605
- ]);
606
- function isResyncReason(value) {
607
- return typeof value === "string" && RESYNC_REASONS.has(value);
608
- }
609
- chunkMWMSFIWN_cjs.__name(isResyncReason, "isResyncReason");
610
- function readVisitorChanges(value) {
611
- if (!Array.isArray(value)) return null;
612
- const changes = [];
613
- for (const item of value) {
614
- if (!isRecord2(item) || !hasOnly(item, ["entryId", "contentType", "locale", "kind"])) return null;
615
- const { entryId, contentType, locale, kind } = item;
616
- if (!isNonEmptyString2(entryId) || !isNonEmptyString2(contentType)) return null;
617
- if (locale !== null && typeof locale !== "string") return null;
618
- if (typeof kind !== "string" || !CHANGE_KINDS.has(kind)) return null;
619
- changes.push({ entryId, contentType, locale, kind });
620
- }
621
- return changes;
622
- }
623
- chunkMWMSFIWN_cjs.__name(readVisitorChanges, "readVisitorChanges");
624
- function isCursor(value) {
625
- return typeof value === "string" && VISITOR_CURSOR.test(value);
626
- }
627
- chunkMWMSFIWN_cjs.__name(isCursor, "isCursor");
628
- function isRecord2(value) {
629
- return typeof value === "object" && value !== null && !Array.isArray(value);
630
- }
631
- chunkMWMSFIWN_cjs.__name(isRecord2, "isRecord2");
632
- function isNonEmptyString2(value) {
633
- return typeof value === "string" && value.length > 0;
634
- }
635
- chunkMWMSFIWN_cjs.__name(isNonEmptyString2, "isNonEmptyString2");
636
- function hasOnly(value, keys) {
637
- const present = Object.keys(value);
638
- return present.length === keys.length && present.every((key) => keys.includes(key));
639
- }
640
- chunkMWMSFIWN_cjs.__name(hasOnly, "hasOnly");
641
-
642
440
  // ../../platform/api-contract/dist/client/index.js
643
441
  var _a;
644
442
  var ContractBodyError = (_a = class extends Error {
@@ -718,7 +516,7 @@ var _ErrorMapper = class _ErrorMapper {
718
516
  return new NetworkError(`HTTP ${status}: ${statusText}`.trim(), status, void 0, context);
719
517
  }
720
518
  const retryAfterMs = parseRetryAfterMs(
721
- headerValue(headers, HEADER_RETRY_AFTER.name),
519
+ headerValue(headers, chunk7BZW6XYJ_cjs.HEADER_RETRY_AFTER.name),
722
520
  Date.now()
723
521
  );
724
522
  return this.fromContractCode(refusal, status, context, retryAfterMs);
@@ -776,9 +574,13 @@ var _ErrorMapper = class _ErrorMapper {
776
574
  }
777
575
  case "RESOURCE_CONFLICT": {
778
576
  const expectedVersion = detailNumber(refusal, "expectedVersion");
779
- const guidance = expectedVersion === void 0 ? message : `${message.endsWith(".") ? message : `${message}.`} ${STALE_VERSION_GUIDANCE}`;
577
+ const blockage = blockageOf(refusal);
578
+ const guidance = blockage !== void 0 || expectedVersion === void 0 ? message : `${message.endsWith(".") ? message : `${message}.`} ${STALE_VERSION_GUIDANCE}`;
780
579
  return new ResourceConflictError(guidance, 409, void 0, {
781
580
  ...context,
581
+ // What stands in the way, as a declared kind a program switches on: `draft-exists`,
582
+ // `release-locked` or `slug-taken` from the Content API (REL-2446).
583
+ blockage,
782
584
  expectedVersion,
783
585
  actualVersion: detailNumber(refusal, "actualVersion"),
784
586
  // The shared fields' counter, which the `If-Match` tag carries beside the locale's and a
@@ -788,7 +590,10 @@ var _ErrorMapper = class _ErrorMapper {
788
590
  });
789
591
  }
790
592
  case "RESOURCE_EXPIRED": {
791
- return new ResourceExpiredError(message, 410, void 0, context);
593
+ return new ResourceExpiredError(message, 410, void 0, {
594
+ ...context,
595
+ reason: detailString(refusal, "reason")
596
+ });
792
597
  }
793
598
  case "REQUEST_TIMEOUT": {
794
599
  return new TimeoutError(message, void 0, status, void 0, context);
@@ -875,6 +680,15 @@ function detailNumber(refusal, key) {
875
680
  return typeof value === "number" ? value : void 0;
876
681
  }
877
682
  chunkMWMSFIWN_cjs.__name(detailNumber, "detailNumber");
683
+ function blockageOf(refusal) {
684
+ const blockage = detailBag(refusal)?.blockage;
685
+ if (typeof blockage !== "object" || blockage === null) return void 0;
686
+ const { kind, facts } = blockage;
687
+ if (typeof kind !== "string") return void 0;
688
+ const named = typeof facts === "object" && facts !== null && !Array.isArray(facts) ? facts : {};
689
+ return { kind, facts: named };
690
+ }
691
+ chunkMWMSFIWN_cjs.__name(blockageOf, "blockageOf");
878
692
  function violationsOf(refusal) {
879
693
  const issues = detailBag(refusal)?.issues;
880
694
  if (!Array.isArray(issues)) return [];
@@ -934,6 +748,7 @@ var DECLARED_PATHS = {
934
748
  "/v1/{contentType}/{id}/file/multipart/sign-part": true,
935
749
  "/v1/{contentType}/{id}/file/presign": true,
936
750
  "/v1/{contentType}/{id}/file/url": true,
751
+ "/v1/{contentType}/{id}/shared-versions/{versionNumber}/restore": true,
937
752
  "/v1/{contentType}/{id}/versions": true,
938
753
  "/v1/{contentType}/{id}/versions/{versionNumber}": true,
939
754
  "/v1/{contentType}/{id}/versions/{versionNumber}/restore": true,
@@ -1018,42 +833,6 @@ function readQuery(searchParams) {
1018
833
  }
1019
834
  chunkMWMSFIWN_cjs.__name(readQuery, "readQuery");
1020
835
 
1021
- // src/http/abortable-sleep.ts
1022
- function sleep(ms, signal) {
1023
- return new Promise((resolve) => {
1024
- if (isAborted(signal)) {
1025
- resolve();
1026
- return;
1027
- }
1028
- const done = /* @__PURE__ */ chunkMWMSFIWN_cjs.__name(() => {
1029
- clearTimeout(timer);
1030
- signal?.removeEventListener("abort", done);
1031
- resolve();
1032
- }, "done");
1033
- const timer = setTimeout(done, ms);
1034
- signal?.addEventListener("abort", done, { once: true });
1035
- });
1036
- }
1037
- chunkMWMSFIWN_cjs.__name(sleep, "sleep");
1038
- function isAborted(signal) {
1039
- return signal?.aborted === true;
1040
- }
1041
- chunkMWMSFIWN_cjs.__name(isAborted, "isAborted");
1042
-
1043
- // src/http/request-timeout.ts
1044
- var MAX_TIMER_DELAY_MS = 2147483647;
1045
- function isTimerDelay(value) {
1046
- return typeof value === "number" && value >= 1 && value <= MAX_TIMER_DELAY_MS;
1047
- }
1048
- chunkMWMSFIWN_cjs.__name(isTimerDelay, "isTimerDelay");
1049
- function assertRequestTimeout(timeout) {
1050
- if (isTimerDelay(timeout)) return;
1051
- throw new Error(
1052
- `timeout must be a number of milliseconds from 1 to ${MAX_TIMER_DELAY_MS} \u2014 a timer given 0, NaN, Infinity or more fires at once and ends every request \u2014 and got ${String(timeout)}`
1053
- );
1054
- }
1055
- chunkMWMSFIWN_cjs.__name(assertRequestTimeout, "assertRequestTimeout");
1056
-
1057
836
  // src/errors/instructed-delay.ts
1058
837
  function serviceInstructedDelayMs(error, nowMs) {
1059
838
  if (error instanceof ServiceIndeterminateError) {
@@ -1080,9 +859,20 @@ var IDEMPOTENT_METHODS = /* @__PURE__ */ new Set([
1080
859
  ]);
1081
860
  function isReplaySafe(request) {
1082
861
  if (IDEMPOTENT_METHODS.has(request.method.toUpperCase())) return true;
1083
- return headerValue(request.headers, HEADER_IDEMPOTENCY_KEY.name) !== void 0;
862
+ return headerValue(request.headers, chunk7BZW6XYJ_cjs.HEADER_IDEMPOTENCY_KEY.name) !== void 0;
1084
863
  }
1085
864
  chunkMWMSFIWN_cjs.__name(isReplaySafe, "isReplaySafe");
865
+ var UNREACHABLE_CODES = /* @__PURE__ */ new Set(["ECONNREFUSED", "ENOTFOUND"]);
866
+ function isUnreachableHost(error, depth = 0) {
867
+ if (depth > 4 || typeof error !== "object" || error === null) return false;
868
+ const { code, cause, errors } = error;
869
+ if (typeof code === "string" && UNREACHABLE_CODES.has(code)) return true;
870
+ if (Array.isArray(errors) && errors.length > 0) {
871
+ if (errors.every((one) => isUnreachableHost(one, depth + 1))) return true;
872
+ }
873
+ return isUnreachableHost(cause, depth + 1);
874
+ }
875
+ chunkMWMSFIWN_cjs.__name(isUnreachableHost, "isUnreachableHost");
1086
876
  var _DefaultRetryPolicy = class _DefaultRetryPolicy {
1087
877
  constructor(config) {
1088
878
  chunkMWMSFIWN_cjs.__publicField(this, "config");
@@ -1091,6 +881,7 @@ var _DefaultRetryPolicy = class _DefaultRetryPolicy {
1091
881
  shouldRetry(attempt, error, request) {
1092
882
  if (attempt >= this.config.maxAttempts) return false;
1093
883
  if (!ErrorMapper.isRetryable(error)) return false;
884
+ if (isUnreachableHost(error)) return false;
1094
885
  return isReplaySafe(request);
1095
886
  }
1096
887
  delayFor(attempt, error) {
@@ -1103,6 +894,86 @@ var _DefaultRetryPolicy = class _DefaultRetryPolicy {
1103
894
  };
1104
895
  chunkMWMSFIWN_cjs.__name(_DefaultRetryPolicy, "DefaultRetryPolicy");
1105
896
  var DefaultRetryPolicy = _DefaultRetryPolicy;
897
+ function retryPolicyFor(maxAttempts) {
898
+ return new DefaultRetryPolicy({
899
+ maxAttempts,
900
+ baseDelay: 1e3,
901
+ maxDelay: 1e4,
902
+ backoffFactor: 2,
903
+ jitter: true
904
+ });
905
+ }
906
+ chunkMWMSFIWN_cjs.__name(retryPolicyFor, "retryPolicyFor");
907
+
908
+ // src/config/preview-read.ts
909
+ var derived = /* @__PURE__ */ new Set();
910
+ var unknown = /* @__PURE__ */ new Map();
911
+ var announced = /* @__PURE__ */ new Set();
912
+ function noteDerivedPreview(dataset) {
913
+ derived.add(dataset);
914
+ }
915
+ chunkMWMSFIWN_cjs.__name(noteDerivedPreview, "noteDerivedPreview");
916
+ function isDerivedPreview(dataset) {
917
+ return derived.has(dataset);
918
+ }
919
+ chunkMWMSFIWN_cjs.__name(isDerivedPreview, "isDerivedPreview");
920
+ function isUnknownPreview(dataset) {
921
+ const since = unknown.get(dataset);
922
+ if (since === void 0) return false;
923
+ if (Date.now() - since < chunk7BZW6XYJ_cjs.UNKNOWN_PREVIEW_RECHECK_MS) return true;
924
+ unknown.delete(dataset);
925
+ return false;
926
+ }
927
+ chunkMWMSFIWN_cjs.__name(isUnknownPreview, "isUnknownPreview");
928
+ function rememberUnknownPreview(dataset) {
929
+ unknown.set(dataset, Date.now());
930
+ if (announced.has(dataset)) return;
931
+ announced.add(dataset);
932
+ console.info(
933
+ `[RelyIO] No preview dataset "${dataset}" exists for this deployment's branch \u2014 reading the key's default dataset instead, and asking again in a minute.`
934
+ );
935
+ }
936
+ chunkMWMSFIWN_cjs.__name(rememberUnknownPreview, "rememberUnknownPreview");
937
+ function answersUnknownDataset(error, dataset) {
938
+ return error instanceof ResourceNotFoundError && error.context?.resourceType === "dataset" && error.context.resourceId === dataset;
939
+ }
940
+ chunkMWMSFIWN_cjs.__name(answersUnknownDataset, "answersUnknownDataset");
941
+
942
+ // src/http/abortable-sleep.ts
943
+ function sleep(ms, signal) {
944
+ return new Promise((resolve) => {
945
+ if (isAborted(signal)) {
946
+ resolve();
947
+ return;
948
+ }
949
+ const done = /* @__PURE__ */ chunkMWMSFIWN_cjs.__name(() => {
950
+ clearTimeout(timer);
951
+ signal?.removeEventListener("abort", done);
952
+ resolve();
953
+ }, "done");
954
+ const timer = setTimeout(done, ms);
955
+ signal?.addEventListener("abort", done, { once: true });
956
+ });
957
+ }
958
+ chunkMWMSFIWN_cjs.__name(sleep, "sleep");
959
+ function isAborted(signal) {
960
+ return signal?.aborted === true;
961
+ }
962
+ chunkMWMSFIWN_cjs.__name(isAborted, "isAborted");
963
+
964
+ // src/http/request-timeout.ts
965
+ var MAX_TIMER_DELAY_MS = 2147483647;
966
+ function isTimerDelay(value) {
967
+ return typeof value === "number" && value >= 1 && value <= MAX_TIMER_DELAY_MS;
968
+ }
969
+ chunkMWMSFIWN_cjs.__name(isTimerDelay, "isTimerDelay");
970
+ function assertRequestTimeout(timeout) {
971
+ if (isTimerDelay(timeout)) return;
972
+ throw new Error(
973
+ `timeout must be a number of milliseconds from 1 to ${MAX_TIMER_DELAY_MS} \u2014 a timer given 0, NaN, Infinity or more fires at once and ends every request \u2014 and got ${String(timeout)}`
974
+ );
975
+ }
976
+ chunkMWMSFIWN_cjs.__name(assertRequestTimeout, "assertRequestTimeout");
1106
977
 
1107
978
  // src/http/http-client.ts
1108
979
  var _HttpClient = class _HttpClient {
@@ -1118,33 +989,6 @@ var _HttpClient = class _HttpClient {
1118
989
  this.connection = connectionFor(config);
1119
990
  this.announce();
1120
991
  }
1121
- /**
1122
- * A view of this client that sends every request through it with `headers` added — beneath the
1123
- * request's own, over this client's — and changes nothing else: its key, base URL, timeout,
1124
- * retries and `fetch` are this client's as they are when each request is sent, so a later
1125
- * `configure()` or `setApiKey()` on this client reaches the view, and one on the view reaches
1126
- * this client. `client.with({ dataset })` is one (REL-2417).
1127
- */
1128
- withHeaders(headers) {
1129
- const view = new _HttpClient(this.connection.config);
1130
- view.view = { client: this, headers: { ...headers } };
1131
- return view;
1132
- }
1133
- /**
1134
- * Run on `config` from now on: every later request — whoever holds this client — is sent to its
1135
- * `baseUrl`, with its headers, key and dataset, its timeout and retries, through its `fetch`, and
1136
- * logged by its `debug` options.
1137
- *
1138
- * The client's own `updateConfig()` calls this rather than building a second client, so a
1139
- * `content()` or other sub-client taken before the update sends through the update too. Anything
1140
- * set on this client since it was last configured — `setDefaultHeaders()`, `setBaseUrl()` — is
1141
- * replaced by what `config` says.
1142
- */
1143
- configure(config) {
1144
- if (this.view !== void 0) return this.view.client.configure(config);
1145
- this.connection = connectionFor(config);
1146
- this.announce();
1147
- }
1148
992
  announce() {
1149
993
  this.log("debug", "HttpClient initialized", {
1150
994
  baseUrl: this.connection.baseUrl,
@@ -1153,6 +997,20 @@ var _HttpClient = class _HttpClient {
1153
997
  environment: chunkTZL374LS_cjs.isBrowser() ? "browser" : "node"
1154
998
  });
1155
999
  }
1000
+ /**
1001
+ * Send bytes to an address that is not a RelyIO route — an asset upload's presigned `PUT` and its
1002
+ * multipart parts — through the client's configured `fetch`, so a wrapper that records, proxies or
1003
+ * forbids network access sees every request this client makes (REL-2671). Nothing else is added: no
1004
+ * key, no retry, no timeout, because the address belongs to the storage service, not to RelyIO.
1005
+ *
1006
+ * Static so the instances a customer holds stay `send` and `fetchPayload` (REL-3107). The `fetch`
1007
+ * is read per call, from the client a view sends through, like the requests are.
1008
+ */
1009
+ static transfer(client, url, init) {
1010
+ const owner = client.view?.client ?? client;
1011
+ const send = owner.connection.config.fetch ?? globalThis.fetch;
1012
+ return send(url, init);
1013
+ }
1156
1014
  /**
1157
1015
  * Call a route the committed document declares, and get back the body that
1158
1016
  * document says it serves.
@@ -1222,6 +1080,11 @@ var _HttpClient = class _HttpClient {
1222
1080
  if (config.method === "DELETE" && mergedConfig.headers) {
1223
1081
  mergedConfig.headers = layerHeaders(mergedConfig.headers, { "Content-Type": null });
1224
1082
  }
1083
+ let preview = derivedPreviewIn(mergedConfig.headers);
1084
+ if (preview !== void 0 && (isUnknownPreview(preview) || !isPreviewKey(headerValue(mergedConfig.headers, API_KEY_HEADER)))) {
1085
+ mergedConfig.headers = layerHeaders(mergedConfig.headers ?? {}, { [DATASET_HEADER]: null });
1086
+ preview = void 0;
1087
+ }
1225
1088
  for (let attempt = 1; ; attempt++) {
1226
1089
  try {
1227
1090
  const response = await this.makeRequest(mergedConfig.url, mergedConfig);
@@ -1250,6 +1113,10 @@ var _HttpClient = class _HttpClient {
1250
1113
  method: mergedConfig.method,
1251
1114
  attempt
1252
1115
  });
1116
+ if (preview !== void 0 && answersUnknownDataset(sdkError, preview)) {
1117
+ rememberUnknownPreview(preview);
1118
+ return this.request(config);
1119
+ }
1253
1120
  this.log("error", "Request failed after all retries", {
1254
1121
  error: sdkError.toJSON(),
1255
1122
  url: mergedConfig.url
@@ -1258,122 +1125,6 @@ var _HttpClient = class _HttpClient {
1258
1125
  }
1259
1126
  }
1260
1127
  }
1261
- /**
1262
- * Make a GET request
1263
- */
1264
- async get(url, params) {
1265
- return this.request({
1266
- method: "GET",
1267
- url,
1268
- params
1269
- });
1270
- }
1271
- /**
1272
- * Make a POST request
1273
- */
1274
- async post(url, data, params) {
1275
- return this.request({
1276
- method: "POST",
1277
- url,
1278
- body: data,
1279
- params
1280
- });
1281
- }
1282
- /**
1283
- * Make a PUT request
1284
- */
1285
- async put(url, data, params) {
1286
- return this.request({
1287
- method: "PUT",
1288
- url,
1289
- body: data,
1290
- params
1291
- });
1292
- }
1293
- /**
1294
- * Make a DELETE request
1295
- */
1296
- async delete(url, params) {
1297
- return this.request({
1298
- method: "DELETE",
1299
- url,
1300
- params
1301
- });
1302
- }
1303
- /**
1304
- * Make a PATCH request
1305
- */
1306
- async patch(url, data, params) {
1307
- return this.request({
1308
- method: "PATCH",
1309
- url,
1310
- body: data,
1311
- params
1312
- });
1313
- }
1314
- /**
1315
- * Add headers to every later request, each replacing any header of the same name — the name
1316
- * matched without regard to case — until the client is next configured.
1317
- */
1318
- setDefaultHeaders(headers) {
1319
- if (this.view !== void 0) return this.view.client.setDefaultHeaders(headers);
1320
- this.connection = {
1321
- ...this.connection,
1322
- defaultHeaders: layerHeaders(this.connection.defaultHeaders, headers)
1323
- };
1324
- }
1325
- /**
1326
- * Replace the key every later request sends as `X-API-Key`, and the `apiKey` the configuration
1327
- * reports.
1328
- *
1329
- * The key is read the way construction reads it (`presentKey`): an absent, empty or blank key is
1330
- * no key, so the header is dropped and the next request is refused with `MissingApiKeyError`
1331
- * before anything is sent. A key header of any other spelling — one given in `headers` — goes
1332
- * too, from the headers sent and from the headers the configuration reports, so the old key is
1333
- * never sent beside the new one.
1334
- *
1335
- * The configuration is the one the owning `TypedRelyIOClient` holds (it hands its own to the
1336
- * constructor), so its `getConfig().apiKey` — what a surface reads to decide a key's kind — is the
1337
- * key sent from here on.
1338
- *
1339
- * This replaced `setAuthToken`, which added `Authorization: Bearer` beside an `X-API-Key` it
1340
- * never touched: the API reads `X-API-Key` first, so the old key was the one used (REL-1385).
1341
- */
1342
- setApiKey(apiKey) {
1343
- if (this.view !== void 0) return this.view.client.setApiKey(apiKey);
1344
- const { config } = this.connection;
1345
- config.apiKey = apiKey;
1346
- config.headers = layerHeaders(config.headers, { [API_KEY_HEADER]: null });
1347
- this.connection = {
1348
- ...this.connection,
1349
- defaultHeaders: layerHeaders(this.connection.defaultHeaders, {
1350
- [API_KEY_HEADER]: presentKey(apiKey) ?? null
1351
- })
1352
- };
1353
- }
1354
- /**
1355
- * Get current default headers
1356
- */
1357
- getDefaultHeaders() {
1358
- if (this.view !== void 0) {
1359
- return layerHeaders(this.view.client.getDefaultHeaders(), this.view.headers);
1360
- }
1361
- return { ...this.connection.defaultHeaders };
1362
- }
1363
- /**
1364
- * Update base URL
1365
- */
1366
- setBaseUrl(baseUrl) {
1367
- if (this.view !== void 0) return this.view.client.setBaseUrl(baseUrl);
1368
- this.connection = { ...this.connection, baseUrl };
1369
- }
1370
- /**
1371
- * Get current base URL
1372
- */
1373
- getBaseUrl() {
1374
- if (this.view !== void 0) return this.view.client.getBaseUrl();
1375
- return this.connection.baseUrl;
1376
- }
1377
1128
  /**
1378
1129
  * One attempt.
1379
1130
  *
@@ -1519,10 +1270,11 @@ var _HttpClient = class _HttpClient {
1519
1270
  if (contentType.includes("text/")) {
1520
1271
  return await response.text();
1521
1272
  }
1273
+ const text = await response.text();
1522
1274
  try {
1523
- return await response.json();
1275
+ return JSON.parse(text);
1524
1276
  } catch {
1525
- return await response.text();
1277
+ return text;
1526
1278
  }
1527
1279
  }
1528
1280
  resolveUrl(url) {
@@ -1577,8 +1329,73 @@ var _HttpClient = class _HttpClient {
1577
1329
  };
1578
1330
  chunkMWMSFIWN_cjs.__name(_HttpClient, "HttpClient");
1579
1331
  var HttpClient = _HttpClient;
1332
+ var _ControlledHttpClient = class _ControlledHttpClient extends HttpClient {
1333
+ /**
1334
+ * A view of this client that sends every request through it with `headers` added — beneath the
1335
+ * request's own, over this client's — and changes nothing else: its key, base URL, timeout,
1336
+ * retries and `fetch` are this client's as they are when each request is sent, so a later
1337
+ * `configure()` or `setApiKey()` on this client reaches the view, and one on the view reaches
1338
+ * this client. `client.with({ dataset })` is one (REL-2417).
1339
+ */
1340
+ withHeaders(headers) {
1341
+ const view = new _ControlledHttpClient(this.connection.config);
1342
+ view.view = { client: this, headers: { ...headers } };
1343
+ return view;
1344
+ }
1345
+ /**
1346
+ * Run on `config` from now on: every later request — whoever holds this client — is sent to its
1347
+ * `baseUrl`, with its headers, key and dataset, its timeout and retries, through its `fetch`, and
1348
+ * logged by its `debug` options.
1349
+ *
1350
+ * The client's own `updateConfig()` calls this rather than building a second client, so a
1351
+ * `content()` or other sub-client taken before the update sends through the update too. Anything
1352
+ * set on this client since it was last configured — `setApiKey()` — is replaced by what `config`
1353
+ * says.
1354
+ */
1355
+ configure(config) {
1356
+ if (this.view !== void 0) return this.view.client.configure(config);
1357
+ this.connection = connectionFor(config);
1358
+ this.announce();
1359
+ }
1360
+ /**
1361
+ * Replace the key every later request sends as `X-API-Key`, and the `apiKey` the configuration
1362
+ * reports.
1363
+ *
1364
+ * The key is read the way construction reads it (`presentKey`): an absent, empty or blank key is
1365
+ * no key, so the header is dropped and the next request is refused with `MissingApiKeyError`
1366
+ * before anything is sent. A key header of any other spelling — one given in `headers` — goes
1367
+ * too, from the headers sent and from the headers the configuration reports, so the old key is
1368
+ * never sent beside the new one.
1369
+ *
1370
+ * The configuration is the one the owning `TypedRelyIOClient` holds (it hands its own to the
1371
+ * constructor), so its `getConfig().apiKey` — what a surface reads to decide a key's kind — is the
1372
+ * key sent from here on.
1373
+ *
1374
+ * This replaced `setAuthToken`, which added `Authorization: Bearer` beside an `X-API-Key` it
1375
+ * never touched: the API reads `X-API-Key` first, so the old key was the one used (REL-1385).
1376
+ */
1377
+ setApiKey(apiKey) {
1378
+ if (this.view !== void 0) return this.view.client.setApiKey(apiKey);
1379
+ const { config } = this.connection;
1380
+ config.apiKey = apiKey;
1381
+ config.headers = layerHeaders(config.headers, { [API_KEY_HEADER]: null });
1382
+ this.connection = {
1383
+ ...this.connection,
1384
+ defaultHeaders: layerHeaders(this.connection.defaultHeaders, {
1385
+ [API_KEY_HEADER]: presentKey(apiKey) ?? null
1386
+ })
1387
+ };
1388
+ }
1389
+ };
1390
+ chunkMWMSFIWN_cjs.__name(_ControlledHttpClient, "ControlledHttpClient");
1391
+ var ControlledHttpClient = _ControlledHttpClient;
1580
1392
  var API_KEY_HEADER = "X-API-Key";
1581
1393
  var DATASET_HEADER = "X-RelyIO-Dataset";
1394
+ function derivedPreviewIn(headers) {
1395
+ const dataset = headerValue(headers, DATASET_HEADER);
1396
+ return dataset !== void 0 && isDerivedPreview(dataset) ? dataset : void 0;
1397
+ }
1398
+ chunkMWMSFIWN_cjs.__name(derivedPreviewIn, "derivedPreviewIn");
1582
1399
  var BROWSER_CONTROLLED_HEADERS = /* @__PURE__ */ new Set([
1583
1400
  "user-agent",
1584
1401
  "referer",
@@ -1607,13 +1424,7 @@ function connectionFor(config) {
1607
1424
  // The policy, not a predicate over `(error, attempt)`: whether a request may be sent again is a
1608
1425
  // property of the **route** as much as of the refusal, and a callback that never sees the
1609
1426
  // request cannot express that.
1610
- retryPolicy: new DefaultRetryPolicy({
1611
- maxAttempts: config.retryAttempts,
1612
- baseDelay: 1e3,
1613
- maxDelay: 1e4,
1614
- backoffFactor: 2,
1615
- jitter: true
1616
- })
1427
+ retryPolicy: retryPolicyFor(config.retryAttempts)
1617
1428
  };
1618
1429
  }
1619
1430
  chunkMWMSFIWN_cjs.__name(connectionFor, "connectionFor");
@@ -1642,7 +1453,7 @@ chunkMWMSFIWN_cjs.__name(credentialsModeFor, "credentialsModeFor");
1642
1453
  // src/http/write-options.ts
1643
1454
  function versionCheckOf(entry) {
1644
1455
  const { id, locale, version, sharedVersion } = entry._metadata;
1645
- return { id, locale, ifMatch: entityTag({ entryUid: id, locale, version, sharedVersion }) };
1456
+ return { id, locale, ifMatch: chunk7BZW6XYJ_cjs.entityTag({ entryUid: id, locale, version, sharedVersion }) };
1646
1457
  }
1647
1458
  chunkMWMSFIWN_cjs.__name(versionCheckOf, "versionCheckOf");
1648
1459
  function mintIdempotencyKey() {
@@ -1654,11 +1465,11 @@ chunkMWMSFIWN_cjs.__name(mintIdempotencyKey, "mintIdempotencyKey");
1654
1465
  function writeHeaders(options) {
1655
1466
  const headers = {};
1656
1467
  if (options?.ifMatch !== void 0) {
1657
- headers[HEADER_IF_MATCH.name] = options.ifMatch;
1468
+ headers[chunk7BZW6XYJ_cjs.HEADER_IF_MATCH.name] = options.ifMatch;
1658
1469
  }
1659
1470
  const idempotencyKey = options?.idempotencyKey ?? mintIdempotencyKey();
1660
1471
  if (idempotencyKey !== void 0) {
1661
- headers[HEADER_IDEMPOTENCY_KEY.name] = idempotencyKey;
1472
+ headers[chunk7BZW6XYJ_cjs.HEADER_IDEMPOTENCY_KEY.name] = idempotencyKey;
1662
1473
  }
1663
1474
  return Object.keys(headers).length > 0 ? headers : void 0;
1664
1475
  }
@@ -1722,6 +1533,15 @@ function listQuery(options, clientLocale) {
1722
1533
  return query;
1723
1534
  }
1724
1535
  chunkMWMSFIWN_cjs.__name(listQuery, "listQuery");
1536
+ function childrenQuery(options, clientLocale) {
1537
+ const query = {};
1538
+ if (options.limit !== void 0) query.limit = options.limit;
1539
+ if (options.cursor !== void 0) query.cursor = options.cursor;
1540
+ if (options.page !== void 0) query.page = options.page;
1541
+ writeReadTerms(query, options, clientLocale);
1542
+ return query;
1543
+ }
1544
+ chunkMWMSFIWN_cjs.__name(childrenQuery, "childrenQuery");
1725
1545
  function entryQuery(options, clientLocale) {
1726
1546
  const query = {};
1727
1547
  writeReadTerms(query, options, clientLocale);
@@ -1746,7 +1566,7 @@ function writeDocumentTerms(query, options, clientLocale) {
1746
1566
  query.include = options.include.join(",");
1747
1567
  }
1748
1568
  writeLocale(query, options.locale ?? clientLocale);
1749
- if (typeof options.fresh === "string") query[FRESH_PARAMETER] = options.fresh;
1569
+ if (typeof options.fresh === "string") query[chunk7BZW6XYJ_cjs.FRESH_PARAMETER] = options.fresh;
1750
1570
  }
1751
1571
  chunkMWMSFIWN_cjs.__name(writeDocumentTerms, "writeDocumentTerms");
1752
1572
  function writeLocale(query, locale) {
@@ -1764,6 +1584,10 @@ function writeLocale(query, locale) {
1764
1584
  query.locales = locale.join(",");
1765
1585
  }
1766
1586
  chunkMWMSFIWN_cjs.__name(writeLocale, "writeLocale");
1587
+ function signalOf(options) {
1588
+ return options.signal === void 0 ? {} : { signal: options.signal };
1589
+ }
1590
+ chunkMWMSFIWN_cjs.__name(signalOf, "signalOf");
1767
1591
  function readHeaders(options) {
1768
1592
  const headers = {};
1769
1593
  if (options.dataset !== void 0) headers[DATASET_HEADER] = options.dataset;
@@ -1817,7 +1641,8 @@ var _EntryHandle = class _EntryHandle {
1817
1641
  {
1818
1642
  path: { contentType: this.typeName },
1819
1643
  query: listQuery(options, this.clientLocale()),
1820
- headers: readHeaders(options)
1644
+ headers: readHeaders(options),
1645
+ ...signalOf(options)
1821
1646
  }
1822
1647
  );
1823
1648
  return response.body;
@@ -1872,7 +1697,8 @@ var _EntryHandle = class _EntryHandle {
1872
1697
  return await this.httpClient.fetchPayload("/v1/{contentType}/{id}", "get", {
1873
1698
  path: { contentType: this.typeName, id: idOrSlug },
1874
1699
  query: entryQuery(options, this.clientLocale()),
1875
- headers: readHeaders(options)
1700
+ headers: readHeaders(options),
1701
+ ...signalOf(options)
1876
1702
  });
1877
1703
  } catch (error) {
1878
1704
  if (isMissingEntry(error)) return null;
@@ -1939,7 +1765,7 @@ var _ContentClient = class _ContentClient extends EntryHandle {
1939
1765
  * Versions are numbered per locale, so this is one locale's timeline: `locale` defaults to the
1940
1766
  * client's own, else the schema default; no fallback is applied, and a locale
1941
1767
  * with no history returns an empty array rather than another locale's rows. Every row names the
1942
- * locale it belongs to.
1768
+ * locale it belongs to, and holds that locale's fields under `fields`.
1943
1769
  */
1944
1770
  async versions(id, options) {
1945
1771
  const locale = callLocale(options?.locale, this.clientLocale());
@@ -1960,6 +1786,9 @@ var _ContentClient = class _ContentClient extends EntryHandle {
1960
1786
  * There is no `null`: a version the locale does not have, an entry that is not there, a type the
1961
1787
  * schema does not declare and a dataset with no schema all throw `ResourceNotFoundError`, its
1962
1788
  * `context.resourceType` naming which (REL-2409 Q12).
1789
+ *
1790
+ * It answers the version, not the entry: that locale's own fields as the version stored them, and
1791
+ * `_metadata` with `status: 'version'` ({@link ContentVersion}).
1963
1792
  */
1964
1793
  async version(id, options) {
1965
1794
  const locale = callLocale(options.locale, this.clientLocale());
@@ -1986,7 +1815,12 @@ var _ContentClient = class _ContentClient extends EntryHandle {
1986
1815
  });
1987
1816
  }
1988
1817
  /**
1989
- * The direct children of a hierarchical entry, each read as `get` reads an entry.
1818
+ * One page of the direct children of a hierarchical entry, each read as `get` reads an entry:
1819
+ * the API's own `{ data, page }`, as `list` answers it (REL-1864).
1820
+ *
1821
+ * Page by `cursor` — the `page.nextCursor` a page handed back — to reach every child, or by
1822
+ * `page` number; `limit` is the page size for both. `page.hasMore` says whether there are more,
1823
+ * and a parent with more children than a page has them on the next one.
1990
1824
  *
1991
1825
  * It takes `get`'s options — `include` (checked against the type), `locale` (a code, a list or
1992
1826
  * `'*'`), `dataset`, `fresh` and `children` — the terms its route declares as the entry route
@@ -1994,13 +1828,26 @@ var _ContentClient = class _ContentClient extends EntryHandle {
1994
1828
  * under each child is the `children` option.
1995
1829
  *
1996
1830
  * @param id - Parent entry ID
1831
+ *
1832
+ * @example
1833
+ * ```typescript
1834
+ * let page = await relyio.content('category').children('cat_1', { limit: 50 })
1835
+ * while (page.page.hasMore && page.page.nextCursor !== null) {
1836
+ * page = await relyio.content('category').children('cat_1', {
1837
+ * limit: 50,
1838
+ * cursor: page.page.nextCursor,
1839
+ * })
1840
+ * }
1841
+ * ```
1997
1842
  */
1998
1843
  async children(id, options = {}) {
1999
- return this.httpClient.fetchPayload("/v1/{contentType}/{id}/children", "get", {
1844
+ const response = await this.httpClient.send("/v1/{contentType}/{id}/children", "get", {
2000
1845
  path: { contentType: this.typeName, id },
2001
- query: entryQuery(options, this.clientLocale()),
2002
- headers: readHeaders(options)
1846
+ query: childrenQuery(options, this.clientLocale()),
1847
+ headers: readHeaders(options),
1848
+ ...signalOf(options)
2003
1849
  });
1850
+ return response.body;
2004
1851
  }
2005
1852
  };
2006
1853
  chunkMWMSFIWN_cjs.__name(_ContentClient, "ContentClient");
@@ -2532,7 +2379,7 @@ var _AssetUploadBuilder = class _AssetUploadBuilder {
2532
2379
  }
2533
2380
  const total = this.file.size;
2534
2381
  this.emitProgress(0, total);
2535
- const uploadResponse = await fetch(presigned.uploadUrl, {
2382
+ const uploadResponse = await HttpClient.transfer(this.httpClient, presigned.uploadUrl, {
2536
2383
  method: presigned.method,
2537
2384
  headers: presigned.headers,
2538
2385
  body: this.file
@@ -2599,7 +2446,10 @@ var _AssetUploadBuilder = class _AssetUploadBuilder {
2599
2446
  for (let attempt = 0; attempt <= this._maxPartRetries; attempt += 1) {
2600
2447
  try {
2601
2448
  const { url } = await fileBuilder.signPart({ ...target, partNumber });
2602
- const response = await fetch(url, { method: "PUT", body: blob });
2449
+ const response = await HttpClient.transfer(this.httpClient, url, {
2450
+ method: "PUT",
2451
+ body: blob
2452
+ });
2603
2453
  if (!response.ok) {
2604
2454
  const retriable = response.status >= 500 || response.status === 408 || response.status === 429;
2605
2455
  if (!retriable) {
@@ -2784,7 +2634,8 @@ var _SingletonClient = class _SingletonClient extends DocumentHandle {
2784
2634
  return await this.httpClient.fetchPayload("/v1/singletons/{key}", "get", {
2785
2635
  path: { key: this.name },
2786
2636
  query: documentQuery(options, this.clientLocale()),
2787
- headers: readHeaders(options)
2637
+ headers: readHeaders(options),
2638
+ ...signalOf(options)
2788
2639
  });
2789
2640
  } catch (error) {
2790
2641
  if (isMissingEntry(error)) return null;
@@ -2807,14 +2658,10 @@ var _SingletonClient = class _SingletonClient extends DocumentHandle {
2807
2658
  return this.httpClient.fetchPayload("/v1/singletons/{key}/versions", "get", { path: { key: this.name }, query });
2808
2659
  }
2809
2660
  readVersion(versionNumber, query) {
2810
- return this.httpClient.fetchPayload(
2811
- "/v1/singletons/{key}/versions/{versionNumber}",
2812
- "get",
2813
- {
2814
- path: { key: this.name, versionNumber },
2815
- query
2816
- }
2817
- );
2661
+ return this.httpClient.fetchPayload("/v1/singletons/{key}/versions/{versionNumber}", "get", {
2662
+ path: { key: this.name, versionNumber },
2663
+ query
2664
+ });
2818
2665
  }
2819
2666
  };
2820
2667
  chunkMWMSFIWN_cjs.__name(_SingletonClient, "SingletonClient");
@@ -2847,7 +2694,8 @@ var _SettingsClient = class _SettingsClient extends DocumentHandle {
2847
2694
  {
2848
2695
  path: { groupId: this.name },
2849
2696
  query: documentQuery(options, this.clientLocale()),
2850
- headers: readHeaders(options)
2697
+ headers: readHeaders(options),
2698
+ ...signalOf(options)
2851
2699
  }
2852
2700
  );
2853
2701
  }
@@ -2898,7 +2746,7 @@ var SettingsClient = _SettingsClient;
2898
2746
 
2899
2747
  // src/changes/changes.ts
2900
2748
  var CHANGES_POLL_TIMEOUT_MS = 25e3 + 5e3;
2901
- var EXPIRED_REASONS = {
2749
+ var EXPIRED_REASONS2 = {
2902
2750
  retention: "retention",
2903
2751
  "dataset-replaced": "dataset-replaced",
2904
2752
  "ahead-of-head": "ahead-of-head",
@@ -2918,7 +2766,7 @@ var _ChangesExpiredError = class _ChangesExpiredError extends ResourceExpiredErr
2918
2766
  */
2919
2767
  chunkMWMSFIWN_cjs.__publicField(this, "fresh");
2920
2768
  this.name = "ChangesExpiredError";
2921
- this.reason = expiredReasonOf(message);
2769
+ this.reason = expiredReasonOf(context?.reason);
2922
2770
  this.fresh = fresh;
2923
2771
  }
2924
2772
  /** The base class rebuilds from its four arguments, which would drop the position resynced to. */
@@ -2948,16 +2796,16 @@ var _ChangesExpiredError = class _ChangesExpiredError extends ResourceExpiredErr
2948
2796
  `The live edge cannot list the changes since this cursor (${reason}). Refetch everything derived from the feed; it continues from the position it sent.`,
2949
2797
  410,
2950
2798
  void 0,
2951
- { transport: "live-edge" },
2799
+ { transport: "live-edge", reason },
2952
2800
  cursor
2953
2801
  );
2954
2802
  }
2955
2803
  };
2956
2804
  chunkMWMSFIWN_cjs.__name(_ChangesExpiredError, "ChangesExpiredError");
2957
2805
  var ChangesExpiredError = _ChangesExpiredError;
2958
- function expiredReasonOf(message) {
2959
- for (const reason of Object.values(EXPIRED_REASONS)) {
2960
- if (message.includes(`(${reason})`)) return reason;
2806
+ function expiredReasonOf(named) {
2807
+ for (const reason of Object.values(EXPIRED_REASONS2)) {
2808
+ if (named === reason) return reason;
2961
2809
  }
2962
2810
  return "unknown";
2963
2811
  }
@@ -3037,10 +2885,6 @@ async function pollOnce(http, since, options) {
3037
2885
  }
3038
2886
  chunkMWMSFIWN_cjs.__name(pollOnce, "pollOnce");
3039
2887
 
3040
- // src/config/key-kind.ts
3041
- var PUBLISHABLE_KEY_PREFIX = "rly_pub_";
3042
- var isPublishableKey = /* @__PURE__ */ chunkMWMSFIWN_cjs.__name((apiKey) => apiKey?.startsWith(PUBLISHABLE_KEY_PREFIX) === true, "isPublishableKey");
3043
-
3044
2888
  // src/errors/live-errors.ts
3045
2889
  var _LiveEdgeError = class _LiveEdgeError extends SDKError {
3046
2890
  constructor(message, end, retry, options = {}) {
@@ -3056,19 +2900,6 @@ var _LiveEdgeError = class _LiveEdgeError extends SDKError {
3056
2900
  this.retryable = retry !== "stop";
3057
2901
  this.retryAfterMs = options.retryAfterMs;
3058
2902
  }
3059
- /**
3060
- * The base class rebuilds an error through its own four-argument constructor, which this class
3061
- * does not have; rebuilt that way, `end` would be a string and `retry` a number.
3062
- */
3063
- withContext(context) {
3064
- const rebuilt = new _LiveEdgeError(this.message, this.end, this.retry, {
3065
- ...this.statusCode === void 0 ? {} : { statusCode: this.statusCode },
3066
- ...this.cause === void 0 ? {} : { cause: this.cause },
3067
- ...this.retryAfterMs === void 0 ? {} : { retryAfterMs: this.retryAfterMs },
3068
- context: { ...this.context, ...context }
3069
- });
3070
- return rebuilt;
3071
- }
3072
2903
  getUserMessage() {
3073
2904
  return this.message;
3074
2905
  }
@@ -3088,8 +2919,8 @@ var HTTP_SCHEME_OF = {
3088
2919
  };
3089
2920
  function liveEdgeAddress(config) {
3090
2921
  if (config.liveUrl !== void 0) return readLiveUrl(config.liveUrl);
3091
- const derived = originOf(config.baseUrl);
3092
- const edge = derived === void 0 ? void 0 : LIVE_EDGE_OF_API[derived];
2922
+ const derived2 = originOf(config.baseUrl);
2923
+ const edge = derived2 === void 0 ? void 0 : LIVE_EDGE_OF_API[derived2];
3093
2924
  if (edge !== void 0) return { ok: true, url: new URL(edge) };
3094
2925
  return {
3095
2926
  ok: false,
@@ -3128,7 +2959,7 @@ chunkMWMSFIWN_cjs.__name(originOf, "originOf");
3128
2959
 
3129
2960
  // src/changes/live-edge.ts
3130
2961
  var LIVE_KEEPALIVE_INTERVAL_MS = 3e4;
3131
- var LIVE_SOCKET_OPEN_TIMEOUT_MS = VISITOR_POLL_INTERVAL_MS;
2962
+ var LIVE_SOCKET_OPEN_TIMEOUT_MS = chunk7BZW6XYJ_cjs.VISITOR_POLL_INTERVAL_MS;
3132
2963
  var LIVE_POLLS_BEFORE_SOCKET = 4;
3133
2964
  async function* subscribeLiveEdge(client, options = {}) {
3134
2965
  const { signal } = options;
@@ -3198,12 +3029,12 @@ async function* followSocket(socket, reach, options) {
3198
3029
  return "unopened";
3199
3030
  }
3200
3031
  case "message": {
3201
- if (event.data === VISITOR_KEEPALIVE.response) continue;
3202
- const frame = typeof event.data === "string" ? parseVisitorFrame(event.data) : null;
3032
+ if (event.data === chunk7BZW6XYJ_cjs.VISITOR_KEEPALIVE.response) continue;
3033
+ const frame = typeof event.data === "string" ? chunk7BZW6XYJ_cjs.parseVisitorFrame(event.data) : null;
3203
3034
  if (frame === null)
3204
3035
  throw unreadable(`a frame the wire does not declare: ${sample(event.data)}`);
3205
3036
  switch (frame.type) {
3206
- case VISITOR_FRAMES.opened: {
3037
+ case chunk7BZW6XYJ_cjs.VISITOR_FRAMES.opened: {
3207
3038
  caughtUp = true;
3208
3039
  inbox.caughtUp();
3209
3040
  reach.position = frame.cursor;
@@ -3211,7 +3042,7 @@ async function* followSocket(socket, reach, options) {
3211
3042
  options.reached?.(frame.cursor);
3212
3043
  continue;
3213
3044
  }
3214
- case VISITOR_FRAMES.changes: {
3045
+ case chunk7BZW6XYJ_cjs.VISITOR_FRAMES.changes: {
3215
3046
  const prior = reach.position;
3216
3047
  if (prior === void 0) throw unreadable("changes before the socket had a position");
3217
3048
  for (const change of changesOf(frame.changes, frame.cursor, prior)) {
@@ -3222,7 +3053,7 @@ async function* followSocket(socket, reach, options) {
3222
3053
  if (frame.changes.length === 0) options.reached?.(frame.cursor);
3223
3054
  continue;
3224
3055
  }
3225
- case VISITOR_FRAMES.resync: {
3056
+ case chunk7BZW6XYJ_cjs.VISITOR_FRAMES.resync: {
3226
3057
  await expire(frame.reason, frame.cursor, options);
3227
3058
  if (isAborted(signal)) return "aborted";
3228
3059
  reach.position = frame.cursor;
@@ -3294,7 +3125,7 @@ function socketInbox(socket, signal) {
3294
3125
  return;
3295
3126
  }
3296
3127
  heard = false;
3297
- if (socket.readyState === SOCKET_OPEN) socket.send(VISITOR_KEEPALIVE.request);
3128
+ if (socket.readyState === SOCKET_OPEN) socket.send(chunk7BZW6XYJ_cjs.VISITOR_KEEPALIVE.request);
3298
3129
  }, LIVE_KEEPALIVE_INTERVAL_MS);
3299
3130
  },
3300
3131
  caughtUp() {
@@ -3330,28 +3161,27 @@ var AFTER_A_CLOSE = {
3330
3161
  "back-off": "Retrying after a back-off of at least a minute, without polling, which the same admission refuses."
3331
3162
  };
3332
3163
  function closeRetryOf(code) {
3333
- if (hasOwn(VISITOR_CLOSE_RETRY, code)) return VISITOR_CLOSE_RETRY[code];
3164
+ if (hasOwn(chunk7BZW6XYJ_cjs.VISITOR_CLOSE_RETRY, code)) return chunk7BZW6XYJ_cjs.VISITOR_CLOSE_RETRY[code];
3334
3165
  return code < 4e3 ? "retry" : "stop";
3335
3166
  }
3336
3167
  chunkMWMSFIWN_cjs.__name(closeRetryOf, "closeRetryOf");
3337
3168
  var CLOSE_MEANING = {
3338
- [VISITOR_CLOSE_CODES.requestInvalid]: "the edge could not read the request \u2014 a malformed cursor or filter",
3339
- [VISITOR_CLOSE_CODES.keyRefused]: "the key is not a publishable key the edge accepts \u2014 unknown, revoked or expired",
3340
- [VISITOR_CLOSE_CODES.originRefused]: "this page\u2019s origin is not on the publishable key\u2019s allowed origins",
3341
- [VISITOR_CLOSE_CODES.datasetRefused]: "`dataset` names no dataset the key reaches",
3342
- // Also how the edge hands a connection on when the project's live objects move to another
3343
- // placement (reason `moved`, REL-1514): either way the same request succeeds again shortly.
3344
- [VISITOR_CLOSE_CODES.unavailable]: "the edge could not serve this connection just now \u2014 it could not reach what it needed, or it moved the project\u2019s live connections elsewhere",
3345
- [VISITOR_CLOSE_CODES.allowanceReached]: "the project holds as many live connections as its plan allows",
3346
- [VISITOR_CLOSE_CODES.addressLimitReached]: "this address holds as many live connections to the project as one address may",
3347
- [VISITOR_CLOSE_CODES.ceilingReached]: "the project is at its safety ceiling of live connections"
3169
+ [chunk7BZW6XYJ_cjs.VISITOR_CLOSE_CODES.requestInvalid]: "the edge could not read the request \u2014 a malformed cursor or filter",
3170
+ [chunk7BZW6XYJ_cjs.VISITOR_CLOSE_CODES.keyRefused]: "the key is not a publishable key the edge accepts \u2014 unknown, revoked or expired",
3171
+ [chunk7BZW6XYJ_cjs.VISITOR_CLOSE_CODES.originRefused]: "this page\u2019s origin is not on the publishable key\u2019s allowed origins",
3172
+ [chunk7BZW6XYJ_cjs.VISITOR_CLOSE_CODES.datasetRefused]: "`dataset` names no dataset the key reaches",
3173
+ [chunk7BZW6XYJ_cjs.VISITOR_CLOSE_CODES.unavailable]: "the edge could not serve this connection just now \u2014 it could not reach what it needed",
3174
+ [chunk7BZW6XYJ_cjs.VISITOR_CLOSE_CODES.allowanceReached]: "the project holds as many live connections as its plan allows",
3175
+ [chunk7BZW6XYJ_cjs.VISITOR_CLOSE_CODES.addressLimitReached]: "this address holds as many live connections to the project as one address may",
3176
+ [chunk7BZW6XYJ_cjs.VISITOR_CLOSE_CODES.ceilingReached]: "the project is at its safety ceiling of live connections"
3348
3177
  };
3349
3178
  async function* followPolls(client, request, reach, options) {
3350
3179
  const { signal } = options;
3180
+ let starting = reach.position === void 0;
3351
3181
  for (let poll = 0; poll < LIVE_POLLS_BEFORE_SOCKET; poll += 1) {
3352
3182
  if (isAborted(signal)) return "aborted";
3353
3183
  const answer = await pollOnce2(client, request, reach.position, signal);
3354
- if (answer === void 0) return "aborted";
3184
+ if (answer === void 0 || isAborted(signal)) return "aborted";
3355
3185
  options.opened?.();
3356
3186
  if (answer.kind === "resync") {
3357
3187
  await expire(answer.reason, answer.cursor, options);
@@ -3368,9 +3198,10 @@ async function* followPolls(client, request, reach, options) {
3368
3198
  if (isAborted(signal)) return "aborted";
3369
3199
  }
3370
3200
  reach.position = answer.cursor;
3371
- if (answer.changes.length === 0) options.reached?.(answer.cursor);
3201
+ if (starting) options.reached?.(answer.cursor);
3372
3202
  }
3373
- await sleep(VISITOR_POLL_INTERVAL_MS, signal);
3203
+ starting = false;
3204
+ await sleep(chunk7BZW6XYJ_cjs.VISITOR_POLL_INTERVAL_MS, signal);
3374
3205
  }
3375
3206
  return isAborted(signal) ? "aborted" : "socket";
3376
3207
  }
@@ -3412,7 +3243,7 @@ async function pollOnce2(client, request, since, signal) {
3412
3243
  }
3413
3244
  const body = parseJson(text);
3414
3245
  if (!response.ok) throw refusedPoll(response, body, context);
3415
- const answer = readVisitorPollAnswer(isRecord(body) ? body["data"] : void 0);
3246
+ const answer = chunk7BZW6XYJ_cjs.readVisitorPollAnswer(isRecord(body) ? body["data"] : void 0);
3416
3247
  if (answer === null)
3417
3248
  throw unreadable(`a poll answer the wire does not declare: ${sample(text)}`);
3418
3249
  return answer;
@@ -3432,13 +3263,13 @@ function refusedPoll(response, body, context) {
3432
3263
  { ...context, method: "GET" }
3433
3264
  );
3434
3265
  const refusal = readError(body);
3435
- if (refusal === void 0 || !hasOwn(VISITOR_POLL_RETRY, refusal.code)) return mapped;
3266
+ if (refusal === void 0 || !hasOwn(chunk7BZW6XYJ_cjs.VISITOR_POLL_RETRY, refusal.code)) return mapped;
3436
3267
  const code = refusal.code;
3437
3268
  const retryAfterMs = parseRetryAfterMs(headerValue(headers, "Retry-After"), Date.now());
3438
3269
  return new LiveEdgeError(
3439
3270
  `The live edge refused a poll (${code}): ${refusal.messages[0] ?? mapped.message}`,
3440
3271
  { kind: "refused", code },
3441
- VISITOR_POLL_RETRY[code],
3272
+ chunk7BZW6XYJ_cjs.VISITOR_POLL_RETRY[code],
3442
3273
  {
3443
3274
  statusCode: response.status,
3444
3275
  cause: mapped,
@@ -3466,17 +3297,17 @@ function edgeRequest(client, filter) {
3466
3297
  chunkMWMSFIWN_cjs.__name(edgeRequest, "edgeRequest");
3467
3298
  function edgeUrl(request, since, transport, clientId) {
3468
3299
  const url = new URL(request.base.href);
3469
- url.pathname = `${url.pathname.replace(/\/+$/, "")}${VISITOR_LIVE_PATH}`;
3300
+ url.pathname = `${url.pathname.replace(/\/+$/, "")}${chunk7BZW6XYJ_cjs.VISITOR_LIVE_PATH}`;
3470
3301
  if (transport === "socket") url.protocol = url.protocol === "http:" ? "ws:" : "wss:";
3471
3302
  const query = new URLSearchParams();
3472
- if (request.key !== void 0) query.set(VISITOR_QUERY.key, request.key);
3303
+ if (request.key !== void 0) query.set(chunk7BZW6XYJ_cjs.VISITOR_QUERY.key, request.key);
3473
3304
  if (request.dataset !== void 0 && request.dataset !== "") {
3474
- query.set(VISITOR_QUERY.dataset, request.dataset);
3305
+ query.set(chunk7BZW6XYJ_cjs.VISITOR_QUERY.dataset, request.dataset);
3475
3306
  }
3476
- if (since !== void 0) query.set(VISITOR_QUERY.since, since);
3477
- if (request.types !== void 0) query.set(VISITOR_QUERY.types, request.types.join(","));
3478
- if (request.ids !== void 0) query.set(VISITOR_QUERY.ids, request.ids.join(","));
3479
- if (transport === "poll" && clientId !== void 0) query.set(VISITOR_QUERY.client, clientId);
3307
+ if (since !== void 0) query.set(chunk7BZW6XYJ_cjs.VISITOR_QUERY.since, since);
3308
+ if (request.types !== void 0) query.set(chunk7BZW6XYJ_cjs.VISITOR_QUERY.types, request.types.join(","));
3309
+ if (request.ids !== void 0) query.set(chunk7BZW6XYJ_cjs.VISITOR_QUERY.ids, request.ids.join(","));
3310
+ if (transport === "poll" && clientId !== void 0) query.set(chunk7BZW6XYJ_cjs.VISITOR_QUERY.client, clientId);
3480
3311
  url.search = query.toString();
3481
3312
  return url.href;
3482
3313
  }
@@ -3561,8 +3392,9 @@ chunkMWMSFIWN_cjs.__name(given, "given");
3561
3392
  function transportOf(options) {
3562
3393
  const headers = readHeaders(options);
3563
3394
  return {
3395
+ ...signalOf(options),
3564
3396
  ...headers === void 0 ? {} : { headers },
3565
- ...typeof options.fresh === "string" ? { query: { [FRESH_PARAMETER]: options.fresh } } : {}
3397
+ ...typeof options.fresh === "string" ? { query: { [chunk7BZW6XYJ_cjs.FRESH_PARAMETER]: options.fresh } } : {}
3566
3398
  };
3567
3399
  }
3568
3400
  chunkMWMSFIWN_cjs.__name(transportOf, "transportOf");
@@ -3638,7 +3470,7 @@ chunkMWMSFIWN_cjs.__name(runSimilar, "runSimilar");
3638
3470
  // src/batch/batch-operations.ts
3639
3471
  var VERBS = ["create", "update", "replace", "delete", "singleton"];
3640
3472
  async function runBatch(http, operations, options, clientLocale) {
3641
- const { atomic, dryRun, stopOnError, returnData, dataset } = options;
3473
+ const { atomic, dryRun, stopOnError, returnData, dataset, signal } = options;
3642
3474
  const runOptions = {
3643
3475
  ...atomic === void 0 ? {} : { atomic },
3644
3476
  ...dryRun === void 0 ? {} : { dryRun },
@@ -3651,7 +3483,8 @@ async function runBatch(http, operations, options, clientLocale) {
3651
3483
  operations: operations.map((operation, index) => operationOf(operation, index, clientLocale)),
3652
3484
  ...Object.keys(runOptions).length === 0 ? {} : { options: runOptions }
3653
3485
  },
3654
- ...headers === void 0 ? {} : { headers }
3486
+ ...headers === void 0 ? {} : { headers },
3487
+ ...signalOf({ signal })
3655
3488
  });
3656
3489
  return response.body;
3657
3490
  }
@@ -3731,7 +3564,7 @@ async function runAdhocQuery(http, query, clientLocale) {
3731
3564
  const order = sort === void 0 ? [] : Object.entries(sort).flatMap(
3732
3565
  ([field, direction]) => direction === void 0 ? [] : [{ [field]: direction }]
3733
3566
  );
3734
- const fetch2 = {
3567
+ const fetch = {
3735
3568
  contentType: query.from,
3736
3569
  ...where === void 0 || Object.keys(where).length === 0 ? {} : { where },
3737
3570
  ...include === void 0 || include.length === 0 ? {} : { include: [...include] },
@@ -3739,14 +3572,14 @@ async function runAdhocQuery(http, query, clientLocale) {
3739
3572
  ...limit === void 0 ? {} : { limit },
3740
3573
  ...page === void 0 ? {} : { offset: offsetOf(page, limit) }
3741
3574
  };
3742
- const locale = query.locale ?? clientLocale;
3743
- const parameters = {
3744
- ...query.params,
3745
- ...locale === void 0 || locale === "" ? {} : { locale }
3746
- };
3575
+ const terms = {};
3576
+ if (query.cursor !== void 0) terms.cursor = query.cursor;
3577
+ writeLocale(terms, query.locale ?? clientLocale);
3578
+ if (typeof query.fresh === "string") terms[chunk7BZW6XYJ_cjs.FRESH_PARAMETER] = query.fresh;
3579
+ const parameters = { ...query.params };
3747
3580
  const body = {
3748
3581
  query: {
3749
- fetch: fetch2,
3582
+ fetch,
3750
3583
  ...aggregate === void 0 ? {} : { aggregate },
3751
3584
  ...select === void 0 || select.length === 0 ? {} : { select: Object.fromEntries(select.map((field) => [field, field])) },
3752
3585
  ...fullText === void 0 ? {} : { fullText }
@@ -3756,8 +3589,9 @@ async function runAdhocQuery(http, query, clientLocale) {
3756
3589
  const headers = readHeaders(query);
3757
3590
  const response = await http.send("/v1/query", "post", {
3758
3591
  body,
3592
+ ...Object.keys(terms).length === 0 ? {} : { query: terms },
3759
3593
  ...headers === void 0 ? {} : { headers },
3760
- ...typeof query.fresh === "string" ? { query: { [FRESH_PARAMETER]: query.fresh } } : {}
3594
+ ...signalOf(query)
3761
3595
  });
3762
3596
  return response.body;
3763
3597
  }
@@ -3774,6 +3608,9 @@ function offsetOf(page, limit) {
3774
3608
  chunkMWMSFIWN_cjs.__name(offsetOf, "offsetOf");
3775
3609
  async function runNamedQuery(http, name, options, clientLocale) {
3776
3610
  const locale = options.locale ?? clientLocale;
3611
+ const terms = {};
3612
+ if (locale !== void 0 && locale !== "") terms.locale = locale;
3613
+ if (typeof options.fresh === "string") terms[chunk7BZW6XYJ_cjs.FRESH_PARAMETER] = options.fresh;
3777
3614
  const headers = readHeaders(options);
3778
3615
  const response = await http.send(
3779
3616
  "/v1/queries/{name}",
@@ -3781,8 +3618,9 @@ async function runNamedQuery(http, name, options, clientLocale) {
3781
3618
  {
3782
3619
  path: { name },
3783
3620
  body: options.params === void 0 ? {} : { params: options.params },
3784
- ...locale === void 0 || locale === "" ? {} : { query: { locale } },
3785
- ...headers === void 0 ? {} : { headers }
3621
+ ...Object.keys(terms).length === 0 ? {} : { query: terms },
3622
+ ...headers === void 0 ? {} : { headers },
3623
+ ...signalOf(options)
3786
3624
  }
3787
3625
  );
3788
3626
  return response.body;
@@ -3890,6 +3728,17 @@ function resolveDevOverride(dev) {
3890
3728
  }
3891
3729
  chunkMWMSFIWN_cjs.__name(resolveDevOverride, "resolveDevOverride");
3892
3730
 
3731
+ // src/config/preview-environment.ts
3732
+ function readPreviewAtRequest() {
3733
+ const env = typeof process === "undefined" ? void 0 : process.env;
3734
+ return chunk7BZW6XYJ_cjs.previewAtRequest(isEnvironment(env) ? env : {});
3735
+ }
3736
+ chunkMWMSFIWN_cjs.__name(readPreviewAtRequest, "readPreviewAtRequest");
3737
+ function isEnvironment(value) {
3738
+ return typeof value === "object" && value !== null;
3739
+ }
3740
+ chunkMWMSFIWN_cjs.__name(isEnvironment, "isEnvironment");
3741
+
3893
3742
  // src/config/types.ts
3894
3743
  var DEFAULT_CONFIG = {
3895
3744
  baseUrl: "https://api.relyio.com",
@@ -3911,12 +3760,6 @@ var DEFAULT_CONFIG = {
3911
3760
  // 50MB
3912
3761
  strategies: ["memory", "stale-while-revalidate"]
3913
3762
  },
3914
- realtime: {
3915
- enabled: true,
3916
- maxReconnectAttempts: 10,
3917
- reconnectDelay: 1e3,
3918
- heartbeatInterval: 3e4
3919
- },
3920
3763
  debug: {
3921
3764
  enabled: false,
3922
3765
  logRequests: false,
@@ -3968,7 +3811,7 @@ chunkMWMSFIWN_cjs.__name(withoutKeyHeader, "withoutKeyHeader");
3968
3811
  function withHandshake(configured) {
3969
3812
  const dev = resolveDevOverride(configured.dev);
3970
3813
  const merged = withDefaults(
3971
- configured,
3814
+ withPreview(configured),
3972
3815
  dev.state === "active" ? { apiKey: dev.apiKey, dataset: dev.sandbox.datasetId } : {},
3973
3816
  DEFAULT_CONFIG
3974
3817
  );
@@ -3993,6 +3836,22 @@ function withHandshake(configured) {
3993
3836
  return { config: merged, sandbox: sandboxStateOf(dev), configured };
3994
3837
  }
3995
3838
  chunkMWMSFIWN_cjs.__name(withHandshake, "withHandshake");
3839
+ var previewNotified = false;
3840
+ function withPreview(configured) {
3841
+ if (configured.dataset !== void 0 || !isPreviewKey(configured.apiKey)) return configured;
3842
+ const preview = readPreviewAtRequest();
3843
+ if (preview.state !== "preview") return configured;
3844
+ const dataset = chunk7BZW6XYJ_cjs.previewDatasetSlug(preview.branch);
3845
+ noteDerivedPreview(dataset);
3846
+ if (!previewNotified) {
3847
+ previewNotified = true;
3848
+ console.info(
3849
+ `[RelyIO] ${preview.host} preview deployment of "${preview.branch}" \u2014 reading its preview dataset "${dataset}".`
3850
+ );
3851
+ }
3852
+ return { ...configured, dataset };
3853
+ }
3854
+ chunkMWMSFIWN_cjs.__name(withPreview, "withPreview");
3996
3855
  function withDefaults(base, given2, defaults) {
3997
3856
  const merged = new Map(Object.entries(base));
3998
3857
  const givenValues = new Map(Object.entries(given2 ?? {}));
@@ -4059,7 +3918,7 @@ var _TypedRelyIOClient = class _TypedRelyIOClient {
4059
3918
  this.config = resolved.config;
4060
3919
  this.configured = resolved.configured;
4061
3920
  this._sandbox = resolved.sandbox;
4062
- this.httpClient = new HttpClient(this.config);
3921
+ this.httpClient = new ControlledHttpClient(this.config);
4063
3922
  }
4064
3923
  // ============================================================================
4065
3924
  // CORE CLIENTS
@@ -4084,14 +3943,16 @@ var _TypedRelyIOClient = class _TypedRelyIOClient {
4084
3943
  /**
4085
3944
  * Run a query in one call (REL-2421, REL-2409 Q22):
4086
3945
  *
4087
- * - `query({ from, … })` runs one inline, with `list`'s option names — `where` (the query
4088
- * route's dialect), `include`, `select`, `sort`, `limit`, `page`, `locale`, `dataset`, `fresh` —
4089
- * plus `aggregate`, `params` and `fullText`;
3946
+ * - `query({ from, … })` runs one inline, with `list`'s options — `where`, `include`, `select`
3947
+ * (beside `include`), `sort`, `limit`, `cursor`, `page`, `locale` (a code, a list or `'*'`),
3948
+ * `dataset`, `fresh` — plus `aggregate`, `params` and `fullText`. It answers a list's envelope,
3949
+ * `{ data, page, meta }` (REL-2460);
4090
3950
  * - `query(name, { params, … })` runs the saved query the schema declares under `name`, its
4091
- * `params` typed from that declaration.
3951
+ * `params` typed from that declaration. It answers the API's body,
3952
+ * `{ data: { result, metadata } }`.
4092
3953
  *
4093
- * Both answer the API's body, `{ data: { result, metadata } }`. See {@link QueryCall}. Every query
4094
- * is sent in the client's locale as it is then, unless it names its own.
3954
+ * See {@link QueryCall}. Every query is sent in the client's locale as it is then, unless it names
3955
+ * its own.
4095
3956
  */
4096
3957
  get query() {
4097
3958
  const call = /* @__PURE__ */ chunkMWMSFIWN_cjs.__name((target, options = {}) => typeof target === "string" ? runNamedQuery(this.httpClient, target, options, this.currentLocale()) : runAdhocQuery(this.httpClient, target, this.currentLocale()), "call");
@@ -4276,7 +4137,7 @@ var _TypedRelyIOClient = class _TypedRelyIOClient {
4276
4137
  * edge's URL. On a server, follow `changes()` with it instead.
4277
4138
  */
4278
4139
  liveChanges(options = {}) {
4279
- const { apiKey, dataset, baseUrl, liveUrl, fetch: fetch2, webSocket, timeout } = this.getConfig();
4140
+ const { apiKey, dataset, baseUrl, liveUrl, fetch, webSocket, timeout } = this.getConfig();
4280
4141
  this._liveClientId ?? (this._liveClientId = randomClientId());
4281
4142
  return subscribeLiveEdge(
4282
4143
  {
@@ -4284,7 +4145,7 @@ var _TypedRelyIOClient = class _TypedRelyIOClient {
4284
4145
  dataset,
4285
4146
  baseUrl,
4286
4147
  liveUrl,
4287
- fetch: fetch2,
4148
+ fetch,
4288
4149
  webSocket,
4289
4150
  timeout,
4290
4151
  clientId: this._liveClientId
@@ -4393,9 +4254,9 @@ var _TypedRelyIOClient = class _TypedRelyIOClient {
4393
4254
  * - an option you name replaces the value the client holds;
4394
4255
  * - an option left out, or given as `undefined`, keeps the value the client holds;
4395
4256
  * - an option with no default given as `null` is cleared — `locale`, `dataset`, `apiKey`, `dev`,
4396
- * `fetch`, `browser.onCorsError`, `realtime.wsUrl`, `debug.logger` — so the client runs as though
4257
+ * `fetch`, `browser.onCorsError`, `debug.logger` — so the client runs as though
4397
4258
  * it had never been given one. An option with a default takes no `null`;
4398
- * - a bag of options you name — `browser`, `cache`, `realtime`, `debug` — keeps every field of it
4259
+ * - a bag of options you name — `browser`, `cache`, `debug` — keeps every field of it
4399
4260
  * you do not name, so `updateConfig({ browser: { includeCredentials: true } })` keeps a
4400
4261
  * configured `onCorsError`;
4401
4262
  * - `headers` is laid over the headers the client sends, a name matched without regard to case: a
@@ -4579,6 +4440,7 @@ exports.BaseValidationError = BaseValidationError;
4579
4440
  exports.ChangesExpiredError = ChangesExpiredError;
4580
4441
  exports.ConnectionError = ConnectionError;
4581
4442
  exports.ContentClient = ContentClient;
4443
+ exports.DefaultRetryPolicy = DefaultRetryPolicy;
4582
4444
  exports.ErrorMapper = ErrorMapper;
4583
4445
  exports.FileUploadError = FileUploadError;
4584
4446
  exports.FileValidationError = FileValidationError;
@@ -4591,6 +4453,7 @@ exports.LiveEdgeError = LiveEdgeError;
4591
4453
  exports.MethodNotAllowedError = MethodNotAllowedError;
4592
4454
  exports.MissingApiKeyError = MissingApiKeyError;
4593
4455
  exports.NetworkError = NetworkError;
4456
+ exports.PREVIEW_KEY_PREFIX = PREVIEW_KEY_PREFIX;
4594
4457
  exports.PUBLISHABLE_KEY_PREFIX = PUBLISHABLE_KEY_PREFIX;
4595
4458
  exports.PayloadTooLargeError = PayloadTooLargeError;
4596
4459
  exports.PlanFeatureUnavailableError = PlanFeatureUnavailableError;
@@ -4609,18 +4472,20 @@ exports.TransactionRolledBackError = TransactionRolledBackError;
4609
4472
  exports.TypedRelyIOClient = TypedRelyIOClient;
4610
4473
  exports.UnknownContractError = UnknownContractError;
4611
4474
  exports.UsageQuotaExceededError = UsageQuotaExceededError;
4612
- exports.VISITOR_ADMISSION_RETRY_AFTER_SECONDS = VISITOR_ADMISSION_RETRY_AFTER_SECONDS;
4613
4475
  exports.ValidationError = ValidationError;
4614
4476
  exports.createClient = createClient;
4615
4477
  exports.isAborted = isAborted;
4616
4478
  exports.isAssetEntry = isAssetEntry;
4617
4479
  exports.isMissingEntry = isMissingEntry;
4480
+ exports.isPreviewKey = isPreviewKey;
4618
4481
  exports.isPublishableKey = isPublishableKey;
4482
+ exports.isReplaySafe = isReplaySafe;
4619
4483
  exports.isResourceNotFound = isResourceNotFound;
4620
4484
  exports.matchRoute = matchRoute;
4485
+ exports.retryPolicyFor = retryPolicyFor;
4621
4486
  exports.serviceInstructedDelayMs = serviceInstructedDelayMs;
4622
4487
  exports.sleep = sleep;
4623
4488
  exports.validateFile = validateFile;
4624
4489
  exports.versionCheckOf = versionCheckOf;
4625
- //# sourceMappingURL=chunk-GUPV2M3X.cjs.map
4626
- //# sourceMappingURL=chunk-GUPV2M3X.cjs.map
4490
+ //# sourceMappingURL=chunk-RLLZUFDB.cjs.map
4491
+ //# sourceMappingURL=chunk-RLLZUFDB.cjs.map