@sanity/client 7.22.0 → 7.22.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 +29 -27
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.d.cts +2 -2
- package/dist/index.browser.d.ts +2 -2
- package/dist/index.browser.js +29 -27
- package/dist/index.browser.js.map +1 -1
- package/dist/index.cjs +30 -28
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +30 -28
- package/dist/index.js.map +1 -1
- package/dist/stega.browser.d.cts +2 -2
- package/dist/stega.browser.d.ts +2 -2
- package/dist/stega.d.cts +2 -2
- package/dist/stega.d.ts +2 -2
- package/package.json +1 -1
- package/src/data/live.ts +95 -24
- package/src/http/errors.ts +15 -5
- package/umd/sanityClient.js +29 -27
- package/umd/sanityClient.min.js +2 -2
package/dist/index.cjs
CHANGED
|
@@ -188,14 +188,11 @@ function sliceWithEllipsis(str, max) {
|
|
|
188
188
|
class CorsOriginError extends Error {
|
|
189
189
|
projectId;
|
|
190
190
|
addOriginUrl;
|
|
191
|
-
constructor({ projectId }) {
|
|
192
|
-
super("CorsOriginError"), this.name = "CorsOriginError", this.projectId = projectId
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
url.searchParams.set("cors", "add"), url.searchParams.set("origin", origin), this.addOriginUrl = url, this.message = `The current origin is not allowed to connect to the Live Content API. Add it here: ${url}`;
|
|
197
|
-
} else
|
|
198
|
-
this.message = `The current origin is not allowed to connect to the Live Content API. Change your configuration here: ${url}`;
|
|
191
|
+
constructor({ projectId, credentials } = {}) {
|
|
192
|
+
if (super("CorsOriginError"), this.name = "CorsOriginError", this.projectId = projectId, projectId && typeof location < "u") {
|
|
193
|
+
const url = new URL(`https://sanity.io/manage/project/${projectId}/api`), { origin } = location;
|
|
194
|
+
url.searchParams.set("cors", "add"), url.searchParams.set("origin", origin), credentials && url.searchParams.set("credentials", ""), this.addOriginUrl = url, this.message = `The current origin is not allowed to connect to the Live Content API. Add it here: ${url}`;
|
|
195
|
+
} else projectId ? this.message = `The current origin is not allowed to connect to the Live Content API. Change your configuration here: https://sanity.io/manage/project/${projectId}/api` : this.message = "The current origin is not allowed to connect to the Live Content API.";
|
|
199
196
|
}
|
|
200
197
|
}
|
|
201
198
|
const httpError = {
|
|
@@ -1330,19 +1327,14 @@ class LiveClient {
|
|
|
1330
1327
|
"welcome",
|
|
1331
1328
|
"reconnect",
|
|
1332
1329
|
"goaway"
|
|
1333
|
-
]), checkCors =
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
headers: esOptions.headers
|
|
1338
|
-
}).pipe(
|
|
1339
|
-
rxjs.catchError(() => {
|
|
1340
|
-
throw new CorsOriginError({ projectId });
|
|
1341
|
-
})
|
|
1330
|
+
]), checkCors = checkCorsObservable(
|
|
1331
|
+
new URL(this.#client.getUrl("/check/cors", !1)),
|
|
1332
|
+
projectId,
|
|
1333
|
+
esOptions.withCredentials === !0
|
|
1342
1334
|
), observable = events.pipe(
|
|
1343
1335
|
reconnectOnConnectionFailure(),
|
|
1344
1336
|
rxjs.mergeMap((event) => event.type === "reconnect" ? checkCors.pipe(rxjs.mergeMap(() => rxjs.of(event))) : rxjs.of(event)),
|
|
1345
|
-
rxjs.catchError((err) => checkCors.pipe(
|
|
1337
|
+
rxjs.catchError((err) => err instanceof CorsOriginError ? rxjs.throwError(() => err) : checkCors.pipe(
|
|
1346
1338
|
rxjs.mergeMap(() => {
|
|
1347
1339
|
throw err;
|
|
1348
1340
|
})
|
|
@@ -1363,17 +1355,27 @@ class LiveClient {
|
|
|
1363
1355
|
return eventsCache.set(key, observable), observable;
|
|
1364
1356
|
}
|
|
1365
1357
|
}
|
|
1366
|
-
function
|
|
1358
|
+
function checkCorsObservable(url, projectId, requireCredentials) {
|
|
1367
1359
|
return new rxjs.Observable((observer) => {
|
|
1368
|
-
const controller = new AbortController(), signal = controller
|
|
1369
|
-
return fetch(url, {
|
|
1370
|
-
(response)
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
(
|
|
1374
|
-
|
|
1360
|
+
const controller = new AbortController(), { signal } = controller;
|
|
1361
|
+
return fetch(url, { method: "GET", mode: "cors", credentials: "omit", signal }).then((response) => {
|
|
1362
|
+
if (!(signal.aborted || !response.ok))
|
|
1363
|
+
return response.json();
|
|
1364
|
+
}).then((body) => {
|
|
1365
|
+
if (!signal.aborted) {
|
|
1366
|
+
if (requireCredentials && body?.result?.withCredentials === !1) {
|
|
1367
|
+
observer.error(new CorsOriginError({ projectId, credentials: !0 }));
|
|
1368
|
+
return;
|
|
1369
|
+
}
|
|
1370
|
+
if (body?.result?.allowed === !1) {
|
|
1371
|
+
observer.error(new CorsOriginError({ projectId, credentials: requireCredentials }));
|
|
1372
|
+
return;
|
|
1373
|
+
}
|
|
1374
|
+
observer.next(), observer.complete();
|
|
1375
1375
|
}
|
|
1376
|
-
)
|
|
1376
|
+
}).catch(() => {
|
|
1377
|
+
signal.aborted || observer.closed || (observer.next(), observer.complete());
|
|
1378
|
+
}), () => controller.abort();
|
|
1377
1379
|
});
|
|
1378
1380
|
}
|
|
1379
1381
|
const eventsCache = /* @__PURE__ */ new Map();
|
|
@@ -2800,7 +2802,7 @@ function defineDeprecatedCreateClient(createClient2) {
|
|
|
2800
2802
|
return config.printNoDefaultExport(), createClient2(config$1);
|
|
2801
2803
|
};
|
|
2802
2804
|
}
|
|
2803
|
-
var name = "@sanity/client", version = "7.22.
|
|
2805
|
+
var name = "@sanity/client", version = "7.22.1";
|
|
2804
2806
|
const middleware = [
|
|
2805
2807
|
middleware$1.debug({ verbose: !0, namespace: "sanity:client" }),
|
|
2806
2808
|
middleware$1.headers({ "User-Agent": `${name} ${version}` }),
|