@sanity/client 7.23.0 → 7.23.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.browser.cjs +18 -2
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.d.cts +17 -2
- package/dist/index.browser.d.ts +17 -2
- package/dist/index.browser.js +18 -2
- package/dist/index.browser.js.map +1 -1
- package/dist/index.cjs +19 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +17 -2
- package/dist/index.d.ts +17 -2
- package/dist/index.js +19 -3
- package/dist/index.js.map +1 -1
- package/dist/stega.browser.d.cts +17 -2
- package/dist/stega.browser.d.ts +17 -2
- package/dist/stega.d.cts +17 -2
- package/dist/stega.d.ts +17 -2
- package/package.json +1 -1
- package/src/data/eventsource.ts +28 -2
- package/src/data/reconnectOnConnectionFailure.ts +15 -1
- package/umd/sanityClient.js +18 -2
- package/umd/sanityClient.min.js +2 -2
package/dist/index.d.cts
CHANGED
|
@@ -907,11 +907,26 @@ export declare function connectEventSource<EventName extends string>(
|
|
|
907
907
|
|
|
908
908
|
/**
|
|
909
909
|
* @public
|
|
910
|
-
* Thrown
|
|
911
|
-
*
|
|
910
|
+
* Thrown when the EventSource connection could not be established, or was rejected by the server.
|
|
911
|
+
* Transient failures (network drops, 5xx, 408, 429) are reconnected internally and emitted as
|
|
912
|
+
* `reconnect` events; a permanent rejection (any other 4xx, eg an expired token) errors the
|
|
913
|
+
* stream with this class so consumers can react — check `status` for the rejection code.
|
|
912
914
|
*/
|
|
913
915
|
export declare class ConnectionFailedError extends Error {
|
|
914
916
|
readonly name = 'ConnectionFailedError'
|
|
917
|
+
/**
|
|
918
|
+
* HTTP status code of the rejected connection attempt, if known.
|
|
919
|
+
* Only set when the EventSource implementation exposes it — the polyfill used in
|
|
920
|
+
* Node.js and when custom headers (eg authorization) are required does, while
|
|
921
|
+
* native EventSource implementations (browser and Node.js) do not.
|
|
922
|
+
*/
|
|
923
|
+
readonly status?: number
|
|
924
|
+
constructor(
|
|
925
|
+
message?: string,
|
|
926
|
+
options?: ErrorOptions & {
|
|
927
|
+
status?: number
|
|
928
|
+
},
|
|
929
|
+
)
|
|
915
930
|
}
|
|
916
931
|
|
|
917
932
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -907,11 +907,26 @@ export declare function connectEventSource<EventName extends string>(
|
|
|
907
907
|
|
|
908
908
|
/**
|
|
909
909
|
* @public
|
|
910
|
-
* Thrown
|
|
911
|
-
*
|
|
910
|
+
* Thrown when the EventSource connection could not be established, or was rejected by the server.
|
|
911
|
+
* Transient failures (network drops, 5xx, 408, 429) are reconnected internally and emitted as
|
|
912
|
+
* `reconnect` events; a permanent rejection (any other 4xx, eg an expired token) errors the
|
|
913
|
+
* stream with this class so consumers can react — check `status` for the rejection code.
|
|
912
914
|
*/
|
|
913
915
|
export declare class ConnectionFailedError extends Error {
|
|
914
916
|
readonly name = 'ConnectionFailedError'
|
|
917
|
+
/**
|
|
918
|
+
* HTTP status code of the rejected connection attempt, if known.
|
|
919
|
+
* Only set when the EventSource implementation exposes it — the polyfill used in
|
|
920
|
+
* Node.js and when custom headers (eg authorization) are required does, while
|
|
921
|
+
* native EventSource implementations (browser and Node.js) do not.
|
|
922
|
+
*/
|
|
923
|
+
readonly status?: number
|
|
924
|
+
constructor(
|
|
925
|
+
message?: string,
|
|
926
|
+
options?: ErrorOptions & {
|
|
927
|
+
status?: number
|
|
928
|
+
},
|
|
929
|
+
)
|
|
915
930
|
}
|
|
916
931
|
|
|
917
932
|
/**
|
package/dist/index.js
CHANGED
|
@@ -223,6 +223,17 @@ function shouldRetry(err, attempt, options) {
|
|
|
223
223
|
const EXPERIMENTAL_API_WARNING = "This is an experimental API version";
|
|
224
224
|
class ConnectionFailedError extends Error {
|
|
225
225
|
name = "ConnectionFailedError";
|
|
226
|
+
/**
|
|
227
|
+
* HTTP status code of the rejected connection attempt, if known.
|
|
228
|
+
* Only set when the EventSource implementation exposes it — the polyfill used in
|
|
229
|
+
* Node.js and when custom headers (eg authorization) are required does, while
|
|
230
|
+
* native EventSource implementations (browser and Node.js) do not.
|
|
231
|
+
*/
|
|
232
|
+
status;
|
|
233
|
+
constructor(message, options = {}) {
|
|
234
|
+
const { status, ...errorOptions } = options;
|
|
235
|
+
super(message, errorOptions), this.status = status;
|
|
236
|
+
}
|
|
226
237
|
}
|
|
227
238
|
class DisconnectError extends Error {
|
|
228
239
|
name = "DisconnectError";
|
|
@@ -266,6 +277,11 @@ function connectWithESInstance(es, events) {
|
|
|
266
277
|
);
|
|
267
278
|
return;
|
|
268
279
|
}
|
|
280
|
+
const rawStatus = evt.status, status = typeof rawStatus == "number" ? rawStatus : void 0;
|
|
281
|
+
if (status !== void 0) {
|
|
282
|
+
observer.error(new ConnectionFailedError("EventSource connection failed", { status }));
|
|
283
|
+
return;
|
|
284
|
+
}
|
|
269
285
|
es.readyState === es.CLOSED ? observer.error(new ConnectionFailedError("EventSource connection failed")) : emitReconnect && observer.next({ type: "reconnect" });
|
|
270
286
|
}
|
|
271
287
|
function onOpen() {
|
|
@@ -1235,11 +1251,11 @@ var defaults = (obj, defaults2) => Object.keys(defaults2).concat(Object.keys(obj
|
|
|
1235
1251
|
const pick = (obj, props) => props.reduce((selection, prop) => (typeof obj[prop] > "u" || (selection[prop] = obj[prop]), selection), {}), eventSourcePolyfill = defer(() => import("@sanity/eventsource")).pipe(
|
|
1236
1252
|
map(({ default: EventSource2 }) => EventSource2),
|
|
1237
1253
|
shareReplay(1)
|
|
1238
|
-
);
|
|
1254
|
+
), RETRYABLE_STATUSES = /* @__PURE__ */ new Set([408, 429]);
|
|
1239
1255
|
function reconnectOnConnectionFailure() {
|
|
1240
1256
|
return function(source) {
|
|
1241
1257
|
return source.pipe(
|
|
1242
|
-
catchError((err, caught) => err instanceof ConnectionFailedError ? concat(of({ type: "reconnect" }), timer(1e3).pipe(mergeMap(() => caught))) : throwError(() => err))
|
|
1258
|
+
catchError((err, caught) => err instanceof ConnectionFailedError && (typeof err.status != "number" || err.status < 400 || err.status >= 500 || RETRYABLE_STATUSES.has(err.status)) ? concat(of({ type: "reconnect" }), timer(1e3).pipe(mergeMap(() => caught))) : throwError(() => err))
|
|
1243
1259
|
);
|
|
1244
1260
|
};
|
|
1245
1261
|
}
|
|
@@ -2838,7 +2854,7 @@ function defineDeprecatedCreateClient(createClient2) {
|
|
|
2838
2854
|
return printNoDefaultExport(), createClient2(config);
|
|
2839
2855
|
};
|
|
2840
2856
|
}
|
|
2841
|
-
var name = "@sanity/client", version = "7.23.
|
|
2857
|
+
var name = "@sanity/client", version = "7.23.1";
|
|
2842
2858
|
const middleware = [
|
|
2843
2859
|
debug({ verbose: !0, namespace: "sanity:client" }),
|
|
2844
2860
|
headers({ "User-Agent": `${name} ${version}` }),
|