@sanity/client 6.22.3-canary.0 → 6.22.3
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/index.browser.cjs +26 -0
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.d.cts +7 -0
- package/dist/index.browser.d.ts +7 -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 +7 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +27 -1
- package/dist/index.js.map +1 -1
- package/package.json +8 -6
- package/src/data/live.ts +18 -0
- package/src/defineCreateClient.ts +1 -1
- package/src/http/errors.ts +23 -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.d.cts
CHANGED
|
@@ -484,6 +484,13 @@ export declare interface ContentSourceMapValueMapping {
|
|
|
484
484
|
source: ContentSourceMapSource
|
|
485
485
|
}
|
|
486
486
|
|
|
487
|
+
/** @public */
|
|
488
|
+
export declare class CorsOriginError extends Error {
|
|
489
|
+
projectId: string
|
|
490
|
+
addOriginUrl?: URL
|
|
491
|
+
constructor({projectId}: {projectId: string})
|
|
492
|
+
}
|
|
493
|
+
|
|
487
494
|
/**
|
|
488
495
|
* Creates a new draft document. The published version of the document must not already exist.
|
|
489
496
|
* If the draft version of the document already exists the action will fail by default, but
|
package/dist/index.d.ts
CHANGED
|
@@ -484,6 +484,13 @@ export declare interface ContentSourceMapValueMapping {
|
|
|
484
484
|
source: ContentSourceMapSource
|
|
485
485
|
}
|
|
486
486
|
|
|
487
|
+
/** @public */
|
|
488
|
+
export declare class CorsOriginError extends Error {
|
|
489
|
+
projectId: string
|
|
490
|
+
addOriginUrl?: URL
|
|
491
|
+
constructor({projectId}: {projectId: string})
|
|
492
|
+
}
|
|
493
|
+
|
|
487
494
|
/**
|
|
488
495
|
* Creates a new draft document. The published version of the document must not already exist.
|
|
489
496
|
* If the draft version of the document already exists the action will fail by default, but
|
package/dist/index.js
CHANGED
|
@@ -60,6 +60,19 @@ function httpErrorMessage(res) {
|
|
|
60
60
|
function stringifyBody(body, res) {
|
|
61
61
|
return (res.headers["content-type"] || "").toLowerCase().indexOf("application/json") !== -1 ? JSON.stringify(body, null, 2) : body;
|
|
62
62
|
}
|
|
63
|
+
class CorsOriginError extends Error {
|
|
64
|
+
projectId;
|
|
65
|
+
addOriginUrl;
|
|
66
|
+
constructor({ projectId: projectId2 }) {
|
|
67
|
+
super("CorsOriginError"), this.name = "CorsOriginError", this.projectId = projectId2;
|
|
68
|
+
const url = new URL(`https://sanity.io/manage/project/${projectId2}/api`);
|
|
69
|
+
if (typeof location < "u") {
|
|
70
|
+
const { origin } = location;
|
|
71
|
+
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}`;
|
|
72
|
+
} else
|
|
73
|
+
this.message = `The current origin is not allowed to connect to the Live Content API. Change your configuration here: ${url}`;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
63
76
|
const httpError = {
|
|
64
77
|
onResponse: (res) => {
|
|
65
78
|
if (res.statusCode >= 500)
|
|
@@ -931,6 +944,7 @@ class LiveClient {
|
|
|
931
944
|
tag: _tag
|
|
932
945
|
} = {}) {
|
|
933
946
|
const {
|
|
947
|
+
projectId: projectId2,
|
|
934
948
|
apiVersion: _apiVersion,
|
|
935
949
|
token,
|
|
936
950
|
withCredentials,
|
|
@@ -981,6 +995,17 @@ class LiveClient {
|
|
|
981
995
|
const EventSourceImplementation = typeof EventSource > "u" || esOptions.headers || esOptions.withCredentials ? (await import("@sanity/eventsource")).default : EventSource;
|
|
982
996
|
if (unsubscribed)
|
|
983
997
|
return;
|
|
998
|
+
try {
|
|
999
|
+
if (await fetch(url, {
|
|
1000
|
+
method: "OPTIONS",
|
|
1001
|
+
mode: "cors",
|
|
1002
|
+
credentials: esOptions.withCredentials ? "include" : "omit",
|
|
1003
|
+
headers: esOptions.headers
|
|
1004
|
+
}), unsubscribed)
|
|
1005
|
+
return;
|
|
1006
|
+
} catch {
|
|
1007
|
+
throw new CorsOriginError({ projectId: projectId2 });
|
|
1008
|
+
}
|
|
984
1009
|
const evs = new EventSourceImplementation(url.toString(), esOptions);
|
|
985
1010
|
evs.addEventListener("error", onError);
|
|
986
1011
|
for (const type of listenFor)
|
|
@@ -1525,7 +1550,7 @@ function defineDeprecatedCreateClient(createClient2) {
|
|
|
1525
1550
|
return printNoDefaultExport(), createClient2(config);
|
|
1526
1551
|
};
|
|
1527
1552
|
}
|
|
1528
|
-
var name = "@sanity/client", version = "6.22.3
|
|
1553
|
+
var name = "@sanity/client", version = "6.22.3";
|
|
1529
1554
|
const middleware = [
|
|
1530
1555
|
debug({ verbose: !0, namespace: "sanity:client" }),
|
|
1531
1556
|
headers({ "User-Agent": `${name} ${version}` }),
|
|
@@ -1547,6 +1572,7 @@ export {
|
|
|
1547
1572
|
BasePatch,
|
|
1548
1573
|
BaseTransaction,
|
|
1549
1574
|
ClientError,
|
|
1575
|
+
CorsOriginError,
|
|
1550
1576
|
ObservablePatch,
|
|
1551
1577
|
ObservableSanityClient,
|
|
1552
1578
|
ObservableTransaction,
|