@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.d.cts
CHANGED
|
@@ -1046,9 +1046,9 @@ export declare interface ContentSourceMapValueMapping {
|
|
|
1046
1046
|
|
|
1047
1047
|
/** @public */
|
|
1048
1048
|
export declare class CorsOriginError extends Error {
|
|
1049
|
-
projectId
|
|
1049
|
+
projectId?: string
|
|
1050
1050
|
addOriginUrl?: URL
|
|
1051
|
-
constructor({projectId}
|
|
1051
|
+
constructor({projectId, credentials}?: {projectId?: string; credentials?: boolean})
|
|
1052
1052
|
}
|
|
1053
1053
|
|
|
1054
1054
|
/**
|
package/dist/index.browser.d.ts
CHANGED
|
@@ -1046,9 +1046,9 @@ export declare interface ContentSourceMapValueMapping {
|
|
|
1046
1046
|
|
|
1047
1047
|
/** @public */
|
|
1048
1048
|
export declare class CorsOriginError extends Error {
|
|
1049
|
-
projectId
|
|
1049
|
+
projectId?: string
|
|
1050
1050
|
addOriginUrl?: URL
|
|
1051
|
-
constructor({projectId}
|
|
1051
|
+
constructor({projectId, credentials}?: {projectId?: string; credentials?: boolean})
|
|
1052
1052
|
}
|
|
1053
1053
|
|
|
1054
1054
|
/**
|
package/dist/index.browser.js
CHANGED
|
@@ -174,14 +174,11 @@ function sliceWithEllipsis(str, max) {
|
|
|
174
174
|
class CorsOriginError extends Error {
|
|
175
175
|
projectId;
|
|
176
176
|
addOriginUrl;
|
|
177
|
-
constructor({ projectId: projectId2 }) {
|
|
178
|
-
super("CorsOriginError"), this.name = "CorsOriginError", this.projectId = projectId2
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
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}`;
|
|
183
|
-
} else
|
|
184
|
-
this.message = `The current origin is not allowed to connect to the Live Content API. Change your configuration here: ${url}`;
|
|
177
|
+
constructor({ projectId: projectId2, credentials } = {}) {
|
|
178
|
+
if (super("CorsOriginError"), this.name = "CorsOriginError", this.projectId = projectId2, projectId2 && typeof location < "u") {
|
|
179
|
+
const url = new URL(`https://sanity.io/manage/project/${projectId2}/api`), { origin } = location;
|
|
180
|
+
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}`;
|
|
181
|
+
} 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.";
|
|
185
182
|
}
|
|
186
183
|
}
|
|
187
184
|
const httpError = {
|
|
@@ -1498,19 +1495,14 @@ class LiveClient {
|
|
|
1498
1495
|
"welcome",
|
|
1499
1496
|
"reconnect",
|
|
1500
1497
|
"goaway"
|
|
1501
|
-
]), checkCors =
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
headers: esOptions.headers
|
|
1506
|
-
}).pipe(
|
|
1507
|
-
catchError(() => {
|
|
1508
|
-
throw new CorsOriginError({ projectId: projectId2 });
|
|
1509
|
-
})
|
|
1498
|
+
]), checkCors = checkCorsObservable(
|
|
1499
|
+
new URL(this.#client.getUrl("/check/cors", !1)),
|
|
1500
|
+
projectId2,
|
|
1501
|
+
esOptions.withCredentials === !0
|
|
1510
1502
|
), observable2 = events.pipe(
|
|
1511
1503
|
reconnectOnConnectionFailure(),
|
|
1512
1504
|
mergeMap((event) => event.type === "reconnect" ? checkCors.pipe(mergeMap(() => of(event))) : of(event)),
|
|
1513
|
-
catchError((err) => checkCors.pipe(
|
|
1505
|
+
catchError((err) => err instanceof CorsOriginError ? throwError(() => err) : checkCors.pipe(
|
|
1514
1506
|
mergeMap(() => {
|
|
1515
1507
|
throw err;
|
|
1516
1508
|
})
|
|
@@ -1531,17 +1523,27 @@ class LiveClient {
|
|
|
1531
1523
|
return eventsCache.set(key, observable2), observable2;
|
|
1532
1524
|
}
|
|
1533
1525
|
}
|
|
1534
|
-
function
|
|
1526
|
+
function checkCorsObservable(url, projectId2, requireCredentials) {
|
|
1535
1527
|
return new Observable((observer) => {
|
|
1536
|
-
const controller = new AbortController(), signal = controller
|
|
1537
|
-
return fetch(url, {
|
|
1538
|
-
(response)
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
(
|
|
1542
|
-
|
|
1528
|
+
const controller = new AbortController(), { signal } = controller;
|
|
1529
|
+
return fetch(url, { method: "GET", mode: "cors", credentials: "omit", signal }).then((response) => {
|
|
1530
|
+
if (!(signal.aborted || !response.ok))
|
|
1531
|
+
return response.json();
|
|
1532
|
+
}).then((body) => {
|
|
1533
|
+
if (!signal.aborted) {
|
|
1534
|
+
if (requireCredentials && body?.result?.withCredentials === !1) {
|
|
1535
|
+
observer.error(new CorsOriginError({ projectId: projectId2, credentials: !0 }));
|
|
1536
|
+
return;
|
|
1537
|
+
}
|
|
1538
|
+
if (body?.result?.allowed === !1) {
|
|
1539
|
+
observer.error(new CorsOriginError({ projectId: projectId2, credentials: requireCredentials }));
|
|
1540
|
+
return;
|
|
1541
|
+
}
|
|
1542
|
+
observer.next(), observer.complete();
|
|
1543
1543
|
}
|
|
1544
|
-
)
|
|
1544
|
+
}).catch(() => {
|
|
1545
|
+
signal.aborted || observer.closed || (observer.next(), observer.complete());
|
|
1546
|
+
}), () => controller.abort();
|
|
1545
1547
|
});
|
|
1546
1548
|
}
|
|
1547
1549
|
const eventsCache = /* @__PURE__ */ new Map();
|