@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.browser.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: projectId2 }) {
|
|
192
|
-
super("CorsOriginError"), this.name = "CorsOriginError", this.projectId = projectId2
|
|
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: projectId2, credentials } = {}) {
|
|
192
|
+
if (super("CorsOriginError"), this.name = "CorsOriginError", this.projectId = projectId2, projectId2 && typeof location < "u") {
|
|
193
|
+
const url = new URL(`https://sanity.io/manage/project/${projectId2}/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 projectId2 ? this.message = `The current origin is not allowed to connect to the Live Content API. Change your configuration here: https://sanity.io/manage/project/${projectId2}/api` : this.message = "The current origin is not allowed to connect to the Live Content API.";
|
|
199
196
|
}
|
|
200
197
|
}
|
|
201
198
|
const httpError = {
|
|
@@ -1514,19 +1511,14 @@ class LiveClient {
|
|
|
1514
1511
|
"welcome",
|
|
1515
1512
|
"reconnect",
|
|
1516
1513
|
"goaway"
|
|
1517
|
-
]), checkCors =
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
headers: esOptions.headers
|
|
1522
|
-
}).pipe(
|
|
1523
|
-
rxjs.catchError(() => {
|
|
1524
|
-
throw new CorsOriginError({ projectId: projectId2 });
|
|
1525
|
-
})
|
|
1514
|
+
]), checkCors = checkCorsObservable(
|
|
1515
|
+
new URL(this.#client.getUrl("/check/cors", !1)),
|
|
1516
|
+
projectId2,
|
|
1517
|
+
esOptions.withCredentials === !0
|
|
1526
1518
|
), observable = events.pipe(
|
|
1527
1519
|
reconnectOnConnectionFailure(),
|
|
1528
1520
|
rxjs.mergeMap((event) => event.type === "reconnect" ? checkCors.pipe(rxjs.mergeMap(() => rxjs.of(event))) : rxjs.of(event)),
|
|
1529
|
-
rxjs.catchError((err) => checkCors.pipe(
|
|
1521
|
+
rxjs.catchError((err) => err instanceof CorsOriginError ? rxjs.throwError(() => err) : checkCors.pipe(
|
|
1530
1522
|
rxjs.mergeMap(() => {
|
|
1531
1523
|
throw err;
|
|
1532
1524
|
})
|
|
@@ -1547,17 +1539,27 @@ class LiveClient {
|
|
|
1547
1539
|
return eventsCache.set(key, observable), observable;
|
|
1548
1540
|
}
|
|
1549
1541
|
}
|
|
1550
|
-
function
|
|
1542
|
+
function checkCorsObservable(url, projectId2, requireCredentials) {
|
|
1551
1543
|
return new rxjs.Observable((observer) => {
|
|
1552
|
-
const controller = new AbortController(), signal = controller
|
|
1553
|
-
return fetch(url, {
|
|
1554
|
-
(response)
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
(
|
|
1558
|
-
|
|
1544
|
+
const controller = new AbortController(), { signal } = controller;
|
|
1545
|
+
return fetch(url, { method: "GET", mode: "cors", credentials: "omit", signal }).then((response) => {
|
|
1546
|
+
if (!(signal.aborted || !response.ok))
|
|
1547
|
+
return response.json();
|
|
1548
|
+
}).then((body) => {
|
|
1549
|
+
if (!signal.aborted) {
|
|
1550
|
+
if (requireCredentials && body?.result?.withCredentials === !1) {
|
|
1551
|
+
observer.error(new CorsOriginError({ projectId: projectId2, credentials: !0 }));
|
|
1552
|
+
return;
|
|
1553
|
+
}
|
|
1554
|
+
if (body?.result?.allowed === !1) {
|
|
1555
|
+
observer.error(new CorsOriginError({ projectId: projectId2, credentials: requireCredentials }));
|
|
1556
|
+
return;
|
|
1557
|
+
}
|
|
1558
|
+
observer.next(), observer.complete();
|
|
1559
1559
|
}
|
|
1560
|
-
)
|
|
1560
|
+
}).catch(() => {
|
|
1561
|
+
signal.aborted || observer.closed || (observer.next(), observer.complete());
|
|
1562
|
+
}), () => controller.abort();
|
|
1561
1563
|
});
|
|
1562
1564
|
}
|
|
1563
1565
|
const eventsCache = /* @__PURE__ */ new Map();
|