@sanity/client 6.22.2 → 6.22.3-canary.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/README.md +43 -1
- package/dist/_chunks-cjs/resolveEditInfo.cjs.map +1 -1
- package/dist/_chunks-cjs/stegaEncodeSourceMap.cjs.map +1 -1
- package/dist/_chunks-es/resolveEditInfo.js.map +1 -1
- package/dist/_chunks-es/stegaEncodeSourceMap.js.map +1 -1
- package/dist/csm.cjs.map +1 -1
- package/dist/csm.js.map +1 -1
- package/dist/index.browser.cjs +26 -0
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.d.cts +12 -0
- package/dist/index.browser.d.ts +12 -0
- package/dist/index.browser.js +26 -0
- package/dist/index.browser.js.map +1 -1
- package/dist/index.cjs +27 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +12 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +27 -1
- package/dist/index.js.map +1 -1
- package/package.json +20 -19
- package/src/data/live.ts +18 -0
- package/src/defineCreateClient.ts +1 -1
- package/src/http/errors.ts +28 -0
- package/src/stega/types.ts +1 -0
- package/src/types.ts +1 -0
- package/umd/sanityClient.js +1091 -1052
- package/umd/sanityClient.min.js +2 -2
package/dist/index.cjs
CHANGED
|
@@ -76,6 +76,19 @@ function httpErrorMessage(res) {
|
|
|
76
76
|
function stringifyBody(body, res) {
|
|
77
77
|
return (res.headers["content-type"] || "").toLowerCase().indexOf("application/json") !== -1 ? JSON.stringify(body, null, 2) : body;
|
|
78
78
|
}
|
|
79
|
+
class CorsOriginError extends Error {
|
|
80
|
+
projectId;
|
|
81
|
+
addOriginUrl;
|
|
82
|
+
constructor({ projectId: projectId2 }) {
|
|
83
|
+
super("CorsOriginError"), this.name = "CorsOriginError", this.projectId = projectId2;
|
|
84
|
+
const url = new URL(`https://sanity.io/manage/project/${projectId2}/api`);
|
|
85
|
+
if (typeof location < "u") {
|
|
86
|
+
const { origin } = location;
|
|
87
|
+
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}`;
|
|
88
|
+
} else
|
|
89
|
+
this.message = `The current origin is not allowed to connect to the Live Content API. Change your configuration here: ${url}`;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
79
92
|
const httpError = {
|
|
80
93
|
onResponse: (res) => {
|
|
81
94
|
if (res.statusCode >= 500)
|
|
@@ -949,6 +962,7 @@ class LiveClient {
|
|
|
949
962
|
tag: _tag
|
|
950
963
|
} = {}) {
|
|
951
964
|
const {
|
|
965
|
+
projectId: projectId2,
|
|
952
966
|
apiVersion: _apiVersion,
|
|
953
967
|
token,
|
|
954
968
|
withCredentials,
|
|
@@ -999,6 +1013,17 @@ class LiveClient {
|
|
|
999
1013
|
const EventSourceImplementation = typeof EventSource > "u" || esOptions.headers || esOptions.withCredentials ? (await import("@sanity/eventsource")).default : EventSource;
|
|
1000
1014
|
if (unsubscribed)
|
|
1001
1015
|
return;
|
|
1016
|
+
try {
|
|
1017
|
+
if (await fetch(url, {
|
|
1018
|
+
method: "OPTIONS",
|
|
1019
|
+
mode: "cors",
|
|
1020
|
+
credentials: esOptions.withCredentials ? "include" : "omit",
|
|
1021
|
+
headers: esOptions.headers
|
|
1022
|
+
}), unsubscribed)
|
|
1023
|
+
return;
|
|
1024
|
+
} catch {
|
|
1025
|
+
throw new CorsOriginError({ projectId: projectId2 });
|
|
1026
|
+
}
|
|
1002
1027
|
const evs = new EventSourceImplementation(url.toString(), esOptions);
|
|
1003
1028
|
evs.addEventListener("error", onError);
|
|
1004
1029
|
for (const type of listenFor)
|
|
@@ -1543,7 +1568,7 @@ function defineDeprecatedCreateClient(createClient2) {
|
|
|
1543
1568
|
return printNoDefaultExport(), createClient2(config);
|
|
1544
1569
|
};
|
|
1545
1570
|
}
|
|
1546
|
-
var name = "@sanity/client", version = "6.22.
|
|
1571
|
+
var name = "@sanity/client", version = "6.22.3-canary.1";
|
|
1547
1572
|
const middleware = [
|
|
1548
1573
|
middleware$1.debug({ verbose: !0, namespace: "sanity:client" }),
|
|
1549
1574
|
middleware$1.headers({ "User-Agent": `${name} ${version}` }),
|
|
@@ -1576,6 +1601,7 @@ Object.defineProperty(exports, "unstable__environment", {
|
|
|
1576
1601
|
exports.BasePatch = BasePatch;
|
|
1577
1602
|
exports.BaseTransaction = BaseTransaction;
|
|
1578
1603
|
exports.ClientError = ClientError;
|
|
1604
|
+
exports.CorsOriginError = CorsOriginError;
|
|
1579
1605
|
exports.ObservablePatch = ObservablePatch;
|
|
1580
1606
|
exports.ObservableSanityClient = ObservableSanityClient;
|
|
1581
1607
|
exports.ObservableTransaction = ObservableTransaction;
|