@relyio/sdk 0.15.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.
- package/CHANGELOG.md +53 -0
- package/dist/chunk-7BZW6XYJ.cjs +433 -0
- package/dist/chunk-CQHEG7QA.js +411 -0
- package/dist/{chunk-PCFTJLEP.js → chunk-DIZY6CKM.js} +2 -2
- package/dist/{chunk-X4KSS7PP.cjs → chunk-GHYB6IZK.cjs} +2 -2
- package/dist/{chunk-PXA5ONIU.js → chunk-NIUOPIIB.js} +384 -549
- package/dist/{chunk-3BHDGUNS.cjs → chunk-RLLZUFDB.cjs} +421 -582
- package/dist/client/index.cjs +4 -3
- package/dist/client/index.d.cts +3 -4
- package/dist/client/index.d.ts +3 -4
- package/dist/client/index.js +2 -1
- package/dist/{define-content-type-Ds5rCAYl.d.ts → define-content-type-CAWSlgn0.d.ts} +528 -79
- package/dist/{define-content-type-B2gQZkTy.d.cts → define-content-type-LkI0rS2W.d.cts} +528 -79
- package/dist/{define-schema-CxpIYFFR.d.ts → define-schema-Dxu3RoHV.d.ts} +1 -1
- package/dist/{define-schema-Cm_5y3ei.d.cts → define-schema-wlsJOrnY.d.cts} +1 -1
- package/dist/{index-DQ7eTUPQ.d.ts → index-BH8JksfG.d.ts} +447 -179
- package/dist/{index-Db3_tmYf.d.ts → index-CGtYxUuh.d.ts} +1 -1
- package/dist/{index-DY64WjZM.d.cts → index-CcHmRALk.d.cts} +1 -1
- package/dist/{index-F0UuHpRj.d.cts → index-D80MXUkf.d.cts} +447 -179
- package/dist/index.cjs +96 -71
- package/dist/index.d.cts +26 -16
- package/dist/index.d.ts +26 -16
- package/dist/index.js +4 -3
- package/dist/markdown/index.cjs +10 -2
- package/dist/markdown/index.d.cts +12 -3
- package/dist/markdown/index.d.ts +12 -3
- package/dist/markdown/index.js +10 -2
- package/dist/preview/index.cjs +29 -0
- package/dist/preview/index.d.cts +117 -0
- package/dist/preview/index.d.ts +117 -0
- package/dist/preview/index.js +4 -0
- package/dist/rich-text/index.d.cts +2 -2
- package/dist/rich-text/index.d.ts +2 -2
- package/dist/schema/index.cjs +33 -33
- package/dist/schema/index.d.cts +3 -3
- package/dist/schema/index.d.ts +3 -3
- package/dist/schema/index.js +1 -1
- package/dist/types/index.d.cts +1 -1
- package/dist/types/index.d.ts +1 -1
- package/package.json +9 -3
|
@@ -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
|
|
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
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
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
|
|
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
|
|
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,
|
|
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
|
|
1275
|
+
return JSON.parse(text);
|
|
1524
1276
|
} catch {
|
|
1525
|
-
return
|
|
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:
|
|
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
|
}
|
|
@@ -1755,7 +1566,7 @@ function writeDocumentTerms(query, options, clientLocale) {
|
|
|
1755
1566
|
query.include = options.include.join(",");
|
|
1756
1567
|
}
|
|
1757
1568
|
writeLocale(query, options.locale ?? clientLocale);
|
|
1758
|
-
if (typeof options.fresh === "string") query[FRESH_PARAMETER] = options.fresh;
|
|
1569
|
+
if (typeof options.fresh === "string") query[chunk7BZW6XYJ_cjs.FRESH_PARAMETER] = options.fresh;
|
|
1759
1570
|
}
|
|
1760
1571
|
chunkMWMSFIWN_cjs.__name(writeDocumentTerms, "writeDocumentTerms");
|
|
1761
1572
|
function writeLocale(query, locale) {
|
|
@@ -1773,6 +1584,10 @@ function writeLocale(query, locale) {
|
|
|
1773
1584
|
query.locales = locale.join(",");
|
|
1774
1585
|
}
|
|
1775
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");
|
|
1776
1591
|
function readHeaders(options) {
|
|
1777
1592
|
const headers = {};
|
|
1778
1593
|
if (options.dataset !== void 0) headers[DATASET_HEADER] = options.dataset;
|
|
@@ -1826,7 +1641,8 @@ var _EntryHandle = class _EntryHandle {
|
|
|
1826
1641
|
{
|
|
1827
1642
|
path: { contentType: this.typeName },
|
|
1828
1643
|
query: listQuery(options, this.clientLocale()),
|
|
1829
|
-
headers: readHeaders(options)
|
|
1644
|
+
headers: readHeaders(options),
|
|
1645
|
+
...signalOf(options)
|
|
1830
1646
|
}
|
|
1831
1647
|
);
|
|
1832
1648
|
return response.body;
|
|
@@ -1881,7 +1697,8 @@ var _EntryHandle = class _EntryHandle {
|
|
|
1881
1697
|
return await this.httpClient.fetchPayload("/v1/{contentType}/{id}", "get", {
|
|
1882
1698
|
path: { contentType: this.typeName, id: idOrSlug },
|
|
1883
1699
|
query: entryQuery(options, this.clientLocale()),
|
|
1884
|
-
headers: readHeaders(options)
|
|
1700
|
+
headers: readHeaders(options),
|
|
1701
|
+
...signalOf(options)
|
|
1885
1702
|
});
|
|
1886
1703
|
} catch (error) {
|
|
1887
1704
|
if (isMissingEntry(error)) return null;
|
|
@@ -1948,7 +1765,7 @@ var _ContentClient = class _ContentClient extends EntryHandle {
|
|
|
1948
1765
|
* Versions are numbered per locale, so this is one locale's timeline: `locale` defaults to the
|
|
1949
1766
|
* client's own, else the schema default; no fallback is applied, and a locale
|
|
1950
1767
|
* with no history returns an empty array rather than another locale's rows. Every row names the
|
|
1951
|
-
* locale it belongs to
|
|
1768
|
+
* locale it belongs to, and holds that locale's fields under `fields`.
|
|
1952
1769
|
*/
|
|
1953
1770
|
async versions(id, options) {
|
|
1954
1771
|
const locale = callLocale(options?.locale, this.clientLocale());
|
|
@@ -1969,6 +1786,9 @@ var _ContentClient = class _ContentClient extends EntryHandle {
|
|
|
1969
1786
|
* There is no `null`: a version the locale does not have, an entry that is not there, a type the
|
|
1970
1787
|
* schema does not declare and a dataset with no schema all throw `ResourceNotFoundError`, its
|
|
1971
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}).
|
|
1972
1792
|
*/
|
|
1973
1793
|
async version(id, options) {
|
|
1974
1794
|
const locale = callLocale(options.locale, this.clientLocale());
|
|
@@ -2024,7 +1844,8 @@ var _ContentClient = class _ContentClient extends EntryHandle {
|
|
|
2024
1844
|
const response = await this.httpClient.send("/v1/{contentType}/{id}/children", "get", {
|
|
2025
1845
|
path: { contentType: this.typeName, id },
|
|
2026
1846
|
query: childrenQuery(options, this.clientLocale()),
|
|
2027
|
-
headers: readHeaders(options)
|
|
1847
|
+
headers: readHeaders(options),
|
|
1848
|
+
...signalOf(options)
|
|
2028
1849
|
});
|
|
2029
1850
|
return response.body;
|
|
2030
1851
|
}
|
|
@@ -2558,7 +2379,7 @@ var _AssetUploadBuilder = class _AssetUploadBuilder {
|
|
|
2558
2379
|
}
|
|
2559
2380
|
const total = this.file.size;
|
|
2560
2381
|
this.emitProgress(0, total);
|
|
2561
|
-
const uploadResponse = await
|
|
2382
|
+
const uploadResponse = await HttpClient.transfer(this.httpClient, presigned.uploadUrl, {
|
|
2562
2383
|
method: presigned.method,
|
|
2563
2384
|
headers: presigned.headers,
|
|
2564
2385
|
body: this.file
|
|
@@ -2625,7 +2446,10 @@ var _AssetUploadBuilder = class _AssetUploadBuilder {
|
|
|
2625
2446
|
for (let attempt = 0; attempt <= this._maxPartRetries; attempt += 1) {
|
|
2626
2447
|
try {
|
|
2627
2448
|
const { url } = await fileBuilder.signPart({ ...target, partNumber });
|
|
2628
|
-
const response = await
|
|
2449
|
+
const response = await HttpClient.transfer(this.httpClient, url, {
|
|
2450
|
+
method: "PUT",
|
|
2451
|
+
body: blob
|
|
2452
|
+
});
|
|
2629
2453
|
if (!response.ok) {
|
|
2630
2454
|
const retriable = response.status >= 500 || response.status === 408 || response.status === 429;
|
|
2631
2455
|
if (!retriable) {
|
|
@@ -2810,7 +2634,8 @@ var _SingletonClient = class _SingletonClient extends DocumentHandle {
|
|
|
2810
2634
|
return await this.httpClient.fetchPayload("/v1/singletons/{key}", "get", {
|
|
2811
2635
|
path: { key: this.name },
|
|
2812
2636
|
query: documentQuery(options, this.clientLocale()),
|
|
2813
|
-
headers: readHeaders(options)
|
|
2637
|
+
headers: readHeaders(options),
|
|
2638
|
+
...signalOf(options)
|
|
2814
2639
|
});
|
|
2815
2640
|
} catch (error) {
|
|
2816
2641
|
if (isMissingEntry(error)) return null;
|
|
@@ -2833,14 +2658,10 @@ var _SingletonClient = class _SingletonClient extends DocumentHandle {
|
|
|
2833
2658
|
return this.httpClient.fetchPayload("/v1/singletons/{key}/versions", "get", { path: { key: this.name }, query });
|
|
2834
2659
|
}
|
|
2835
2660
|
readVersion(versionNumber, query) {
|
|
2836
|
-
return this.httpClient.fetchPayload(
|
|
2837
|
-
|
|
2838
|
-
|
|
2839
|
-
|
|
2840
|
-
path: { key: this.name, versionNumber },
|
|
2841
|
-
query
|
|
2842
|
-
}
|
|
2843
|
-
);
|
|
2661
|
+
return this.httpClient.fetchPayload("/v1/singletons/{key}/versions/{versionNumber}", "get", {
|
|
2662
|
+
path: { key: this.name, versionNumber },
|
|
2663
|
+
query
|
|
2664
|
+
});
|
|
2844
2665
|
}
|
|
2845
2666
|
};
|
|
2846
2667
|
chunkMWMSFIWN_cjs.__name(_SingletonClient, "SingletonClient");
|
|
@@ -2873,7 +2694,8 @@ var _SettingsClient = class _SettingsClient extends DocumentHandle {
|
|
|
2873
2694
|
{
|
|
2874
2695
|
path: { groupId: this.name },
|
|
2875
2696
|
query: documentQuery(options, this.clientLocale()),
|
|
2876
|
-
headers: readHeaders(options)
|
|
2697
|
+
headers: readHeaders(options),
|
|
2698
|
+
...signalOf(options)
|
|
2877
2699
|
}
|
|
2878
2700
|
);
|
|
2879
2701
|
}
|
|
@@ -2924,7 +2746,7 @@ var SettingsClient = _SettingsClient;
|
|
|
2924
2746
|
|
|
2925
2747
|
// src/changes/changes.ts
|
|
2926
2748
|
var CHANGES_POLL_TIMEOUT_MS = 25e3 + 5e3;
|
|
2927
|
-
var
|
|
2749
|
+
var EXPIRED_REASONS2 = {
|
|
2928
2750
|
retention: "retention",
|
|
2929
2751
|
"dataset-replaced": "dataset-replaced",
|
|
2930
2752
|
"ahead-of-head": "ahead-of-head",
|
|
@@ -2944,7 +2766,7 @@ var _ChangesExpiredError = class _ChangesExpiredError extends ResourceExpiredErr
|
|
|
2944
2766
|
*/
|
|
2945
2767
|
chunkMWMSFIWN_cjs.__publicField(this, "fresh");
|
|
2946
2768
|
this.name = "ChangesExpiredError";
|
|
2947
|
-
this.reason = expiredReasonOf(
|
|
2769
|
+
this.reason = expiredReasonOf(context?.reason);
|
|
2948
2770
|
this.fresh = fresh;
|
|
2949
2771
|
}
|
|
2950
2772
|
/** The base class rebuilds from its four arguments, which would drop the position resynced to. */
|
|
@@ -2974,16 +2796,16 @@ var _ChangesExpiredError = class _ChangesExpiredError extends ResourceExpiredErr
|
|
|
2974
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.`,
|
|
2975
2797
|
410,
|
|
2976
2798
|
void 0,
|
|
2977
|
-
{ transport: "live-edge" },
|
|
2799
|
+
{ transport: "live-edge", reason },
|
|
2978
2800
|
cursor
|
|
2979
2801
|
);
|
|
2980
2802
|
}
|
|
2981
2803
|
};
|
|
2982
2804
|
chunkMWMSFIWN_cjs.__name(_ChangesExpiredError, "ChangesExpiredError");
|
|
2983
2805
|
var ChangesExpiredError = _ChangesExpiredError;
|
|
2984
|
-
function expiredReasonOf(
|
|
2985
|
-
for (const reason of Object.values(
|
|
2986
|
-
if (
|
|
2806
|
+
function expiredReasonOf(named) {
|
|
2807
|
+
for (const reason of Object.values(EXPIRED_REASONS2)) {
|
|
2808
|
+
if (named === reason) return reason;
|
|
2987
2809
|
}
|
|
2988
2810
|
return "unknown";
|
|
2989
2811
|
}
|
|
@@ -3063,10 +2885,6 @@ async function pollOnce(http, since, options) {
|
|
|
3063
2885
|
}
|
|
3064
2886
|
chunkMWMSFIWN_cjs.__name(pollOnce, "pollOnce");
|
|
3065
2887
|
|
|
3066
|
-
// src/config/key-kind.ts
|
|
3067
|
-
var PUBLISHABLE_KEY_PREFIX = "rly_pub_";
|
|
3068
|
-
var isPublishableKey = /* @__PURE__ */ chunkMWMSFIWN_cjs.__name((apiKey) => apiKey?.startsWith(PUBLISHABLE_KEY_PREFIX) === true, "isPublishableKey");
|
|
3069
|
-
|
|
3070
2888
|
// src/errors/live-errors.ts
|
|
3071
2889
|
var _LiveEdgeError = class _LiveEdgeError extends SDKError {
|
|
3072
2890
|
constructor(message, end, retry, options = {}) {
|
|
@@ -3082,19 +2900,6 @@ var _LiveEdgeError = class _LiveEdgeError extends SDKError {
|
|
|
3082
2900
|
this.retryable = retry !== "stop";
|
|
3083
2901
|
this.retryAfterMs = options.retryAfterMs;
|
|
3084
2902
|
}
|
|
3085
|
-
/**
|
|
3086
|
-
* The base class rebuilds an error through its own four-argument constructor, which this class
|
|
3087
|
-
* does not have; rebuilt that way, `end` would be a string and `retry` a number.
|
|
3088
|
-
*/
|
|
3089
|
-
withContext(context) {
|
|
3090
|
-
const rebuilt = new _LiveEdgeError(this.message, this.end, this.retry, {
|
|
3091
|
-
...this.statusCode === void 0 ? {} : { statusCode: this.statusCode },
|
|
3092
|
-
...this.cause === void 0 ? {} : { cause: this.cause },
|
|
3093
|
-
...this.retryAfterMs === void 0 ? {} : { retryAfterMs: this.retryAfterMs },
|
|
3094
|
-
context: { ...this.context, ...context }
|
|
3095
|
-
});
|
|
3096
|
-
return rebuilt;
|
|
3097
|
-
}
|
|
3098
2903
|
getUserMessage() {
|
|
3099
2904
|
return this.message;
|
|
3100
2905
|
}
|
|
@@ -3114,8 +2919,8 @@ var HTTP_SCHEME_OF = {
|
|
|
3114
2919
|
};
|
|
3115
2920
|
function liveEdgeAddress(config) {
|
|
3116
2921
|
if (config.liveUrl !== void 0) return readLiveUrl(config.liveUrl);
|
|
3117
|
-
const
|
|
3118
|
-
const edge =
|
|
2922
|
+
const derived2 = originOf(config.baseUrl);
|
|
2923
|
+
const edge = derived2 === void 0 ? void 0 : LIVE_EDGE_OF_API[derived2];
|
|
3119
2924
|
if (edge !== void 0) return { ok: true, url: new URL(edge) };
|
|
3120
2925
|
return {
|
|
3121
2926
|
ok: false,
|
|
@@ -3154,7 +2959,7 @@ chunkMWMSFIWN_cjs.__name(originOf, "originOf");
|
|
|
3154
2959
|
|
|
3155
2960
|
// src/changes/live-edge.ts
|
|
3156
2961
|
var LIVE_KEEPALIVE_INTERVAL_MS = 3e4;
|
|
3157
|
-
var LIVE_SOCKET_OPEN_TIMEOUT_MS = VISITOR_POLL_INTERVAL_MS;
|
|
2962
|
+
var LIVE_SOCKET_OPEN_TIMEOUT_MS = chunk7BZW6XYJ_cjs.VISITOR_POLL_INTERVAL_MS;
|
|
3158
2963
|
var LIVE_POLLS_BEFORE_SOCKET = 4;
|
|
3159
2964
|
async function* subscribeLiveEdge(client, options = {}) {
|
|
3160
2965
|
const { signal } = options;
|
|
@@ -3224,12 +3029,12 @@ async function* followSocket(socket, reach, options) {
|
|
|
3224
3029
|
return "unopened";
|
|
3225
3030
|
}
|
|
3226
3031
|
case "message": {
|
|
3227
|
-
if (event.data === VISITOR_KEEPALIVE.response) continue;
|
|
3228
|
-
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;
|
|
3229
3034
|
if (frame === null)
|
|
3230
3035
|
throw unreadable(`a frame the wire does not declare: ${sample(event.data)}`);
|
|
3231
3036
|
switch (frame.type) {
|
|
3232
|
-
case VISITOR_FRAMES.opened: {
|
|
3037
|
+
case chunk7BZW6XYJ_cjs.VISITOR_FRAMES.opened: {
|
|
3233
3038
|
caughtUp = true;
|
|
3234
3039
|
inbox.caughtUp();
|
|
3235
3040
|
reach.position = frame.cursor;
|
|
@@ -3237,7 +3042,7 @@ async function* followSocket(socket, reach, options) {
|
|
|
3237
3042
|
options.reached?.(frame.cursor);
|
|
3238
3043
|
continue;
|
|
3239
3044
|
}
|
|
3240
|
-
case VISITOR_FRAMES.changes: {
|
|
3045
|
+
case chunk7BZW6XYJ_cjs.VISITOR_FRAMES.changes: {
|
|
3241
3046
|
const prior = reach.position;
|
|
3242
3047
|
if (prior === void 0) throw unreadable("changes before the socket had a position");
|
|
3243
3048
|
for (const change of changesOf(frame.changes, frame.cursor, prior)) {
|
|
@@ -3248,7 +3053,7 @@ async function* followSocket(socket, reach, options) {
|
|
|
3248
3053
|
if (frame.changes.length === 0) options.reached?.(frame.cursor);
|
|
3249
3054
|
continue;
|
|
3250
3055
|
}
|
|
3251
|
-
case VISITOR_FRAMES.resync: {
|
|
3056
|
+
case chunk7BZW6XYJ_cjs.VISITOR_FRAMES.resync: {
|
|
3252
3057
|
await expire(frame.reason, frame.cursor, options);
|
|
3253
3058
|
if (isAborted(signal)) return "aborted";
|
|
3254
3059
|
reach.position = frame.cursor;
|
|
@@ -3320,7 +3125,7 @@ function socketInbox(socket, signal) {
|
|
|
3320
3125
|
return;
|
|
3321
3126
|
}
|
|
3322
3127
|
heard = false;
|
|
3323
|
-
if (socket.readyState === SOCKET_OPEN) socket.send(VISITOR_KEEPALIVE.request);
|
|
3128
|
+
if (socket.readyState === SOCKET_OPEN) socket.send(chunk7BZW6XYJ_cjs.VISITOR_KEEPALIVE.request);
|
|
3324
3129
|
}, LIVE_KEEPALIVE_INTERVAL_MS);
|
|
3325
3130
|
},
|
|
3326
3131
|
caughtUp() {
|
|
@@ -3356,28 +3161,27 @@ var AFTER_A_CLOSE = {
|
|
|
3356
3161
|
"back-off": "Retrying after a back-off of at least a minute, without polling, which the same admission refuses."
|
|
3357
3162
|
};
|
|
3358
3163
|
function closeRetryOf(code) {
|
|
3359
|
-
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];
|
|
3360
3165
|
return code < 4e3 ? "retry" : "stop";
|
|
3361
3166
|
}
|
|
3362
3167
|
chunkMWMSFIWN_cjs.__name(closeRetryOf, "closeRetryOf");
|
|
3363
3168
|
var CLOSE_MEANING = {
|
|
3364
|
-
[VISITOR_CLOSE_CODES.requestInvalid]: "the edge could not read the request \u2014 a malformed cursor or filter",
|
|
3365
|
-
[VISITOR_CLOSE_CODES.keyRefused]: "the key is not a publishable key the edge accepts \u2014 unknown, revoked or expired",
|
|
3366
|
-
[VISITOR_CLOSE_CODES.originRefused]: "this page\u2019s origin is not on the publishable key\u2019s allowed origins",
|
|
3367
|
-
[VISITOR_CLOSE_CODES.datasetRefused]: "`dataset` names no dataset the key reaches",
|
|
3368
|
-
|
|
3369
|
-
|
|
3370
|
-
[VISITOR_CLOSE_CODES.
|
|
3371
|
-
[VISITOR_CLOSE_CODES.
|
|
3372
|
-
[VISITOR_CLOSE_CODES.addressLimitReached]: "this address holds as many live connections to the project as one address may",
|
|
3373
|
-
[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"
|
|
3374
3177
|
};
|
|
3375
3178
|
async function* followPolls(client, request, reach, options) {
|
|
3376
3179
|
const { signal } = options;
|
|
3180
|
+
let starting = reach.position === void 0;
|
|
3377
3181
|
for (let poll = 0; poll < LIVE_POLLS_BEFORE_SOCKET; poll += 1) {
|
|
3378
3182
|
if (isAborted(signal)) return "aborted";
|
|
3379
3183
|
const answer = await pollOnce2(client, request, reach.position, signal);
|
|
3380
|
-
if (answer === void 0) return "aborted";
|
|
3184
|
+
if (answer === void 0 || isAborted(signal)) return "aborted";
|
|
3381
3185
|
options.opened?.();
|
|
3382
3186
|
if (answer.kind === "resync") {
|
|
3383
3187
|
await expire(answer.reason, answer.cursor, options);
|
|
@@ -3394,9 +3198,10 @@ async function* followPolls(client, request, reach, options) {
|
|
|
3394
3198
|
if (isAborted(signal)) return "aborted";
|
|
3395
3199
|
}
|
|
3396
3200
|
reach.position = answer.cursor;
|
|
3397
|
-
if (
|
|
3201
|
+
if (starting) options.reached?.(answer.cursor);
|
|
3398
3202
|
}
|
|
3399
|
-
|
|
3203
|
+
starting = false;
|
|
3204
|
+
await sleep(chunk7BZW6XYJ_cjs.VISITOR_POLL_INTERVAL_MS, signal);
|
|
3400
3205
|
}
|
|
3401
3206
|
return isAborted(signal) ? "aborted" : "socket";
|
|
3402
3207
|
}
|
|
@@ -3438,7 +3243,7 @@ async function pollOnce2(client, request, since, signal) {
|
|
|
3438
3243
|
}
|
|
3439
3244
|
const body = parseJson(text);
|
|
3440
3245
|
if (!response.ok) throw refusedPoll(response, body, context);
|
|
3441
|
-
const answer = readVisitorPollAnswer(isRecord(body) ? body["data"] : void 0);
|
|
3246
|
+
const answer = chunk7BZW6XYJ_cjs.readVisitorPollAnswer(isRecord(body) ? body["data"] : void 0);
|
|
3442
3247
|
if (answer === null)
|
|
3443
3248
|
throw unreadable(`a poll answer the wire does not declare: ${sample(text)}`);
|
|
3444
3249
|
return answer;
|
|
@@ -3458,13 +3263,13 @@ function refusedPoll(response, body, context) {
|
|
|
3458
3263
|
{ ...context, method: "GET" }
|
|
3459
3264
|
);
|
|
3460
3265
|
const refusal = readError(body);
|
|
3461
|
-
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;
|
|
3462
3267
|
const code = refusal.code;
|
|
3463
3268
|
const retryAfterMs = parseRetryAfterMs(headerValue(headers, "Retry-After"), Date.now());
|
|
3464
3269
|
return new LiveEdgeError(
|
|
3465
3270
|
`The live edge refused a poll (${code}): ${refusal.messages[0] ?? mapped.message}`,
|
|
3466
3271
|
{ kind: "refused", code },
|
|
3467
|
-
VISITOR_POLL_RETRY[code],
|
|
3272
|
+
chunk7BZW6XYJ_cjs.VISITOR_POLL_RETRY[code],
|
|
3468
3273
|
{
|
|
3469
3274
|
statusCode: response.status,
|
|
3470
3275
|
cause: mapped,
|
|
@@ -3492,17 +3297,17 @@ function edgeRequest(client, filter) {
|
|
|
3492
3297
|
chunkMWMSFIWN_cjs.__name(edgeRequest, "edgeRequest");
|
|
3493
3298
|
function edgeUrl(request, since, transport, clientId) {
|
|
3494
3299
|
const url = new URL(request.base.href);
|
|
3495
|
-
url.pathname = `${url.pathname.replace(/\/+$/, "")}${VISITOR_LIVE_PATH}`;
|
|
3300
|
+
url.pathname = `${url.pathname.replace(/\/+$/, "")}${chunk7BZW6XYJ_cjs.VISITOR_LIVE_PATH}`;
|
|
3496
3301
|
if (transport === "socket") url.protocol = url.protocol === "http:" ? "ws:" : "wss:";
|
|
3497
3302
|
const query = new URLSearchParams();
|
|
3498
|
-
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);
|
|
3499
3304
|
if (request.dataset !== void 0 && request.dataset !== "") {
|
|
3500
|
-
query.set(VISITOR_QUERY.dataset, request.dataset);
|
|
3305
|
+
query.set(chunk7BZW6XYJ_cjs.VISITOR_QUERY.dataset, request.dataset);
|
|
3501
3306
|
}
|
|
3502
|
-
if (since !== void 0) query.set(VISITOR_QUERY.since, since);
|
|
3503
|
-
if (request.types !== void 0) query.set(VISITOR_QUERY.types, request.types.join(","));
|
|
3504
|
-
if (request.ids !== void 0) query.set(VISITOR_QUERY.ids, request.ids.join(","));
|
|
3505
|
-
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);
|
|
3506
3311
|
url.search = query.toString();
|
|
3507
3312
|
return url.href;
|
|
3508
3313
|
}
|
|
@@ -3587,8 +3392,9 @@ chunkMWMSFIWN_cjs.__name(given, "given");
|
|
|
3587
3392
|
function transportOf(options) {
|
|
3588
3393
|
const headers = readHeaders(options);
|
|
3589
3394
|
return {
|
|
3395
|
+
...signalOf(options),
|
|
3590
3396
|
...headers === void 0 ? {} : { headers },
|
|
3591
|
-
...typeof options.fresh === "string" ? { query: { [FRESH_PARAMETER]: options.fresh } } : {}
|
|
3397
|
+
...typeof options.fresh === "string" ? { query: { [chunk7BZW6XYJ_cjs.FRESH_PARAMETER]: options.fresh } } : {}
|
|
3592
3398
|
};
|
|
3593
3399
|
}
|
|
3594
3400
|
chunkMWMSFIWN_cjs.__name(transportOf, "transportOf");
|
|
@@ -3664,7 +3470,7 @@ chunkMWMSFIWN_cjs.__name(runSimilar, "runSimilar");
|
|
|
3664
3470
|
// src/batch/batch-operations.ts
|
|
3665
3471
|
var VERBS = ["create", "update", "replace", "delete", "singleton"];
|
|
3666
3472
|
async function runBatch(http, operations, options, clientLocale) {
|
|
3667
|
-
const { atomic, dryRun, stopOnError, returnData, dataset } = options;
|
|
3473
|
+
const { atomic, dryRun, stopOnError, returnData, dataset, signal } = options;
|
|
3668
3474
|
const runOptions = {
|
|
3669
3475
|
...atomic === void 0 ? {} : { atomic },
|
|
3670
3476
|
...dryRun === void 0 ? {} : { dryRun },
|
|
@@ -3677,7 +3483,8 @@ async function runBatch(http, operations, options, clientLocale) {
|
|
|
3677
3483
|
operations: operations.map((operation, index) => operationOf(operation, index, clientLocale)),
|
|
3678
3484
|
...Object.keys(runOptions).length === 0 ? {} : { options: runOptions }
|
|
3679
3485
|
},
|
|
3680
|
-
...headers === void 0 ? {} : { headers }
|
|
3486
|
+
...headers === void 0 ? {} : { headers },
|
|
3487
|
+
...signalOf({ signal })
|
|
3681
3488
|
});
|
|
3682
3489
|
return response.body;
|
|
3683
3490
|
}
|
|
@@ -3757,7 +3564,7 @@ async function runAdhocQuery(http, query, clientLocale) {
|
|
|
3757
3564
|
const order = sort === void 0 ? [] : Object.entries(sort).flatMap(
|
|
3758
3565
|
([field, direction]) => direction === void 0 ? [] : [{ [field]: direction }]
|
|
3759
3566
|
);
|
|
3760
|
-
const
|
|
3567
|
+
const fetch = {
|
|
3761
3568
|
contentType: query.from,
|
|
3762
3569
|
...where === void 0 || Object.keys(where).length === 0 ? {} : { where },
|
|
3763
3570
|
...include === void 0 || include.length === 0 ? {} : { include: [...include] },
|
|
@@ -3765,14 +3572,14 @@ async function runAdhocQuery(http, query, clientLocale) {
|
|
|
3765
3572
|
...limit === void 0 ? {} : { limit },
|
|
3766
3573
|
...page === void 0 ? {} : { offset: offsetOf(page, limit) }
|
|
3767
3574
|
};
|
|
3768
|
-
const
|
|
3769
|
-
|
|
3770
|
-
|
|
3771
|
-
|
|
3772
|
-
};
|
|
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 };
|
|
3773
3580
|
const body = {
|
|
3774
3581
|
query: {
|
|
3775
|
-
fetch
|
|
3582
|
+
fetch,
|
|
3776
3583
|
...aggregate === void 0 ? {} : { aggregate },
|
|
3777
3584
|
...select === void 0 || select.length === 0 ? {} : { select: Object.fromEntries(select.map((field) => [field, field])) },
|
|
3778
3585
|
...fullText === void 0 ? {} : { fullText }
|
|
@@ -3782,8 +3589,9 @@ async function runAdhocQuery(http, query, clientLocale) {
|
|
|
3782
3589
|
const headers = readHeaders(query);
|
|
3783
3590
|
const response = await http.send("/v1/query", "post", {
|
|
3784
3591
|
body,
|
|
3592
|
+
...Object.keys(terms).length === 0 ? {} : { query: terms },
|
|
3785
3593
|
...headers === void 0 ? {} : { headers },
|
|
3786
|
-
...
|
|
3594
|
+
...signalOf(query)
|
|
3787
3595
|
});
|
|
3788
3596
|
return response.body;
|
|
3789
3597
|
}
|
|
@@ -3800,6 +3608,9 @@ function offsetOf(page, limit) {
|
|
|
3800
3608
|
chunkMWMSFIWN_cjs.__name(offsetOf, "offsetOf");
|
|
3801
3609
|
async function runNamedQuery(http, name, options, clientLocale) {
|
|
3802
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;
|
|
3803
3614
|
const headers = readHeaders(options);
|
|
3804
3615
|
const response = await http.send(
|
|
3805
3616
|
"/v1/queries/{name}",
|
|
@@ -3807,8 +3618,9 @@ async function runNamedQuery(http, name, options, clientLocale) {
|
|
|
3807
3618
|
{
|
|
3808
3619
|
path: { name },
|
|
3809
3620
|
body: options.params === void 0 ? {} : { params: options.params },
|
|
3810
|
-
...
|
|
3811
|
-
...headers === void 0 ? {} : { headers }
|
|
3621
|
+
...Object.keys(terms).length === 0 ? {} : { query: terms },
|
|
3622
|
+
...headers === void 0 ? {} : { headers },
|
|
3623
|
+
...signalOf(options)
|
|
3812
3624
|
}
|
|
3813
3625
|
);
|
|
3814
3626
|
return response.body;
|
|
@@ -3916,6 +3728,17 @@ function resolveDevOverride(dev) {
|
|
|
3916
3728
|
}
|
|
3917
3729
|
chunkMWMSFIWN_cjs.__name(resolveDevOverride, "resolveDevOverride");
|
|
3918
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
|
+
|
|
3919
3742
|
// src/config/types.ts
|
|
3920
3743
|
var DEFAULT_CONFIG = {
|
|
3921
3744
|
baseUrl: "https://api.relyio.com",
|
|
@@ -3937,12 +3760,6 @@ var DEFAULT_CONFIG = {
|
|
|
3937
3760
|
// 50MB
|
|
3938
3761
|
strategies: ["memory", "stale-while-revalidate"]
|
|
3939
3762
|
},
|
|
3940
|
-
realtime: {
|
|
3941
|
-
enabled: true,
|
|
3942
|
-
maxReconnectAttempts: 10,
|
|
3943
|
-
reconnectDelay: 1e3,
|
|
3944
|
-
heartbeatInterval: 3e4
|
|
3945
|
-
},
|
|
3946
3763
|
debug: {
|
|
3947
3764
|
enabled: false,
|
|
3948
3765
|
logRequests: false,
|
|
@@ -3994,7 +3811,7 @@ chunkMWMSFIWN_cjs.__name(withoutKeyHeader, "withoutKeyHeader");
|
|
|
3994
3811
|
function withHandshake(configured) {
|
|
3995
3812
|
const dev = resolveDevOverride(configured.dev);
|
|
3996
3813
|
const merged = withDefaults(
|
|
3997
|
-
configured,
|
|
3814
|
+
withPreview(configured),
|
|
3998
3815
|
dev.state === "active" ? { apiKey: dev.apiKey, dataset: dev.sandbox.datasetId } : {},
|
|
3999
3816
|
DEFAULT_CONFIG
|
|
4000
3817
|
);
|
|
@@ -4019,6 +3836,22 @@ function withHandshake(configured) {
|
|
|
4019
3836
|
return { config: merged, sandbox: sandboxStateOf(dev), configured };
|
|
4020
3837
|
}
|
|
4021
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");
|
|
4022
3855
|
function withDefaults(base, given2, defaults) {
|
|
4023
3856
|
const merged = new Map(Object.entries(base));
|
|
4024
3857
|
const givenValues = new Map(Object.entries(given2 ?? {}));
|
|
@@ -4085,7 +3918,7 @@ var _TypedRelyIOClient = class _TypedRelyIOClient {
|
|
|
4085
3918
|
this.config = resolved.config;
|
|
4086
3919
|
this.configured = resolved.configured;
|
|
4087
3920
|
this._sandbox = resolved.sandbox;
|
|
4088
|
-
this.httpClient = new
|
|
3921
|
+
this.httpClient = new ControlledHttpClient(this.config);
|
|
4089
3922
|
}
|
|
4090
3923
|
// ============================================================================
|
|
4091
3924
|
// CORE CLIENTS
|
|
@@ -4110,14 +3943,16 @@ var _TypedRelyIOClient = class _TypedRelyIOClient {
|
|
|
4110
3943
|
/**
|
|
4111
3944
|
* Run a query in one call (REL-2421, REL-2409 Q22):
|
|
4112
3945
|
*
|
|
4113
|
-
* - `query({ from, … })` runs one inline, with `list`'s
|
|
4114
|
-
*
|
|
4115
|
-
* 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);
|
|
4116
3950
|
* - `query(name, { params, … })` runs the saved query the schema declares under `name`, its
|
|
4117
|
-
* `params` typed from that declaration.
|
|
3951
|
+
* `params` typed from that declaration. It answers the API's body,
|
|
3952
|
+
* `{ data: { result, metadata } }`.
|
|
4118
3953
|
*
|
|
4119
|
-
*
|
|
4120
|
-
*
|
|
3954
|
+
* See {@link QueryCall}. Every query is sent in the client's locale as it is then, unless it names
|
|
3955
|
+
* its own.
|
|
4121
3956
|
*/
|
|
4122
3957
|
get query() {
|
|
4123
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");
|
|
@@ -4302,7 +4137,7 @@ var _TypedRelyIOClient = class _TypedRelyIOClient {
|
|
|
4302
4137
|
* edge's URL. On a server, follow `changes()` with it instead.
|
|
4303
4138
|
*/
|
|
4304
4139
|
liveChanges(options = {}) {
|
|
4305
|
-
const { apiKey, dataset, baseUrl, liveUrl, fetch
|
|
4140
|
+
const { apiKey, dataset, baseUrl, liveUrl, fetch, webSocket, timeout } = this.getConfig();
|
|
4306
4141
|
this._liveClientId ?? (this._liveClientId = randomClientId());
|
|
4307
4142
|
return subscribeLiveEdge(
|
|
4308
4143
|
{
|
|
@@ -4310,7 +4145,7 @@ var _TypedRelyIOClient = class _TypedRelyIOClient {
|
|
|
4310
4145
|
dataset,
|
|
4311
4146
|
baseUrl,
|
|
4312
4147
|
liveUrl,
|
|
4313
|
-
fetch
|
|
4148
|
+
fetch,
|
|
4314
4149
|
webSocket,
|
|
4315
4150
|
timeout,
|
|
4316
4151
|
clientId: this._liveClientId
|
|
@@ -4419,9 +4254,9 @@ var _TypedRelyIOClient = class _TypedRelyIOClient {
|
|
|
4419
4254
|
* - an option you name replaces the value the client holds;
|
|
4420
4255
|
* - an option left out, or given as `undefined`, keeps the value the client holds;
|
|
4421
4256
|
* - an option with no default given as `null` is cleared — `locale`, `dataset`, `apiKey`, `dev`,
|
|
4422
|
-
* `fetch`, `browser.onCorsError`, `
|
|
4257
|
+
* `fetch`, `browser.onCorsError`, `debug.logger` — so the client runs as though
|
|
4423
4258
|
* it had never been given one. An option with a default takes no `null`;
|
|
4424
|
-
* - a bag of options you name — `browser`, `cache`, `
|
|
4259
|
+
* - a bag of options you name — `browser`, `cache`, `debug` — keeps every field of it
|
|
4425
4260
|
* you do not name, so `updateConfig({ browser: { includeCredentials: true } })` keeps a
|
|
4426
4261
|
* configured `onCorsError`;
|
|
4427
4262
|
* - `headers` is laid over the headers the client sends, a name matched without regard to case: a
|
|
@@ -4605,6 +4440,7 @@ exports.BaseValidationError = BaseValidationError;
|
|
|
4605
4440
|
exports.ChangesExpiredError = ChangesExpiredError;
|
|
4606
4441
|
exports.ConnectionError = ConnectionError;
|
|
4607
4442
|
exports.ContentClient = ContentClient;
|
|
4443
|
+
exports.DefaultRetryPolicy = DefaultRetryPolicy;
|
|
4608
4444
|
exports.ErrorMapper = ErrorMapper;
|
|
4609
4445
|
exports.FileUploadError = FileUploadError;
|
|
4610
4446
|
exports.FileValidationError = FileValidationError;
|
|
@@ -4617,6 +4453,7 @@ exports.LiveEdgeError = LiveEdgeError;
|
|
|
4617
4453
|
exports.MethodNotAllowedError = MethodNotAllowedError;
|
|
4618
4454
|
exports.MissingApiKeyError = MissingApiKeyError;
|
|
4619
4455
|
exports.NetworkError = NetworkError;
|
|
4456
|
+
exports.PREVIEW_KEY_PREFIX = PREVIEW_KEY_PREFIX;
|
|
4620
4457
|
exports.PUBLISHABLE_KEY_PREFIX = PUBLISHABLE_KEY_PREFIX;
|
|
4621
4458
|
exports.PayloadTooLargeError = PayloadTooLargeError;
|
|
4622
4459
|
exports.PlanFeatureUnavailableError = PlanFeatureUnavailableError;
|
|
@@ -4635,18 +4472,20 @@ exports.TransactionRolledBackError = TransactionRolledBackError;
|
|
|
4635
4472
|
exports.TypedRelyIOClient = TypedRelyIOClient;
|
|
4636
4473
|
exports.UnknownContractError = UnknownContractError;
|
|
4637
4474
|
exports.UsageQuotaExceededError = UsageQuotaExceededError;
|
|
4638
|
-
exports.VISITOR_ADMISSION_RETRY_AFTER_SECONDS = VISITOR_ADMISSION_RETRY_AFTER_SECONDS;
|
|
4639
4475
|
exports.ValidationError = ValidationError;
|
|
4640
4476
|
exports.createClient = createClient;
|
|
4641
4477
|
exports.isAborted = isAborted;
|
|
4642
4478
|
exports.isAssetEntry = isAssetEntry;
|
|
4643
4479
|
exports.isMissingEntry = isMissingEntry;
|
|
4480
|
+
exports.isPreviewKey = isPreviewKey;
|
|
4644
4481
|
exports.isPublishableKey = isPublishableKey;
|
|
4482
|
+
exports.isReplaySafe = isReplaySafe;
|
|
4645
4483
|
exports.isResourceNotFound = isResourceNotFound;
|
|
4646
4484
|
exports.matchRoute = matchRoute;
|
|
4485
|
+
exports.retryPolicyFor = retryPolicyFor;
|
|
4647
4486
|
exports.serviceInstructedDelayMs = serviceInstructedDelayMs;
|
|
4648
4487
|
exports.sleep = sleep;
|
|
4649
4488
|
exports.validateFile = validateFile;
|
|
4650
4489
|
exports.versionCheckOf = versionCheckOf;
|
|
4651
|
-
//# sourceMappingURL=chunk-
|
|
4652
|
-
//# sourceMappingURL=chunk-
|
|
4490
|
+
//# sourceMappingURL=chunk-RLLZUFDB.cjs.map
|
|
4491
|
+
//# sourceMappingURL=chunk-RLLZUFDB.cjs.map
|