@sanity/client 6.23.0 → 6.24.0-canary.0
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 +15 -3
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.d.cts +9 -1
- package/dist/index.browser.d.ts +9 -1
- package/dist/index.browser.js +15 -3
- package/dist/index.browser.js.map +1 -1
- package/dist/index.cjs +16 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +9 -1
- package/dist/index.d.ts +9 -1
- package/dist/index.js +16 -4
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/config.ts +24 -2
- package/src/data/dataMethods.ts +10 -5
- package/src/types.ts +9 -1
- package/umd/sanityClient.js +15 -3
- package/umd/sanityClient.min.js +2 -2
package/dist/index.d.cts
CHANGED
|
@@ -390,7 +390,12 @@ export declare class ClientError extends Error {
|
|
|
390
390
|
}
|
|
391
391
|
|
|
392
392
|
/** @public */
|
|
393
|
-
export declare type ClientPerspective =
|
|
393
|
+
export declare type ClientPerspective =
|
|
394
|
+
| 'previewDrafts'
|
|
395
|
+
| 'published'
|
|
396
|
+
| 'drafts'
|
|
397
|
+
| 'raw'
|
|
398
|
+
| ('published' | 'drafts' | ReleaseId)[]
|
|
394
399
|
|
|
395
400
|
/** @public */
|
|
396
401
|
export declare type ClientReturn<
|
|
@@ -2116,6 +2121,9 @@ export declare type ReconnectEvent = {
|
|
|
2116
2121
|
type: 'reconnect'
|
|
2117
2122
|
}
|
|
2118
2123
|
|
|
2124
|
+
/** @public */
|
|
2125
|
+
export declare type ReleaseId = `r${string}`
|
|
2126
|
+
|
|
2119
2127
|
/**
|
|
2120
2128
|
* Replaces an existing draft document.
|
|
2121
2129
|
* At least one of the draft or published versions of the document must exist.
|
package/dist/index.d.ts
CHANGED
|
@@ -390,7 +390,12 @@ export declare class ClientError extends Error {
|
|
|
390
390
|
}
|
|
391
391
|
|
|
392
392
|
/** @public */
|
|
393
|
-
export declare type ClientPerspective =
|
|
393
|
+
export declare type ClientPerspective =
|
|
394
|
+
| 'previewDrafts'
|
|
395
|
+
| 'published'
|
|
396
|
+
| 'drafts'
|
|
397
|
+
| 'raw'
|
|
398
|
+
| ('published' | 'drafts' | ReleaseId)[]
|
|
394
399
|
|
|
395
400
|
/** @public */
|
|
396
401
|
export declare type ClientReturn<
|
|
@@ -2116,6 +2121,9 @@ export declare type ReconnectEvent = {
|
|
|
2116
2121
|
type: 'reconnect'
|
|
2117
2122
|
}
|
|
2118
2123
|
|
|
2124
|
+
/** @public */
|
|
2125
|
+
export declare type ReleaseId = `r${string}`
|
|
2126
|
+
|
|
2119
2127
|
/**
|
|
2120
2128
|
* Replaces an existing draft document.
|
|
2121
2129
|
* At least one of the draft or published versions of the document must exist.
|
package/dist/index.js
CHANGED
|
@@ -522,8 +522,17 @@ function validateApiVersion(apiVersion) {
|
|
|
522
522
|
throw new Error("Invalid API version string, expected `1` or date in format `YYYY-MM-DD`");
|
|
523
523
|
}
|
|
524
524
|
const validateApiPerspective = function(perspective) {
|
|
525
|
+
if (Array.isArray(perspective)) {
|
|
526
|
+
for (const perspectiveValue of perspective)
|
|
527
|
+
if (perspectiveValue !== "published" && perspectiveValue !== "drafts" && !(typeof perspectiveValue == "string" && perspectiveValue.startsWith("r") && perspectiveValue !== "raw"))
|
|
528
|
+
throw new TypeError(
|
|
529
|
+
"Invalid API perspective value, expected `published`, `drafts` or a valid release identifier string"
|
|
530
|
+
);
|
|
531
|
+
return;
|
|
532
|
+
}
|
|
525
533
|
switch (perspective) {
|
|
526
534
|
case "previewDrafts":
|
|
535
|
+
case "drafts":
|
|
527
536
|
case "published":
|
|
528
537
|
case "raw":
|
|
529
538
|
return;
|
|
@@ -552,7 +561,7 @@ const validateApiPerspective = function(perspective) {
|
|
|
552
561
|
}
|
|
553
562
|
if (projectBased && !newConfig.projectId)
|
|
554
563
|
throw new Error("Configuration must contain `projectId`");
|
|
555
|
-
if (typeof newConfig.perspective
|
|
564
|
+
if (typeof newConfig.perspective < "u" && validateApiPerspective(newConfig.perspective), "encodeSourceMap" in newConfig)
|
|
556
565
|
throw new Error(
|
|
557
566
|
"It looks like you're using options meant for '@sanity/preview-kit/client'. 'encodeSourceMap' is not supported in '@sanity/client'. Did you mean 'stega.enabled'?"
|
|
558
567
|
);
|
|
@@ -748,8 +757,11 @@ function _requestObservable(client, httpRequest, options) {
|
|
|
748
757
|
if (tag && options.tag !== null && (options.query = { tag: requestTag(tag), ...options.query }), ["GET", "HEAD", "POST"].indexOf(options.method || "GET") >= 0 && uri.indexOf("/data/query/") === 0) {
|
|
749
758
|
const resultSourceMap = options.resultSourceMap ?? config.resultSourceMap;
|
|
750
759
|
resultSourceMap !== void 0 && resultSourceMap !== !1 && (options.query = { resultSourceMap, ...options.query });
|
|
751
|
-
const
|
|
752
|
-
typeof
|
|
760
|
+
const perspectiveOption = options.perspective || config.perspective;
|
|
761
|
+
typeof perspectiveOption < "u" && (validateApiPerspective(perspectiveOption), options.query = {
|
|
762
|
+
perspective: Array.isArray(perspectiveOption) ? perspectiveOption.join(",") : perspectiveOption,
|
|
763
|
+
...options.query
|
|
764
|
+
}, perspectiveOption === "previewDrafts" && useCdn && (useCdn = !1, printCdnPreviewDraftsWarning())), options.lastLiveEventId && (options.query = { ...options.query, lastLiveEventId: options.lastLiveEventId }), options.returnQuery === !1 && (options.query = { returnQuery: "false", ...options.query }), useCdn && options.cacheMode == "noStale" && (options.query = { cacheMode: "noStale", ...options.query });
|
|
753
765
|
}
|
|
754
766
|
const reqOptions = requestOptions(
|
|
755
767
|
config,
|
|
@@ -1551,7 +1563,7 @@ function defineDeprecatedCreateClient(createClient2) {
|
|
|
1551
1563
|
return printNoDefaultExport(), createClient2(config);
|
|
1552
1564
|
};
|
|
1553
1565
|
}
|
|
1554
|
-
var name = "@sanity/client", version = "6.
|
|
1566
|
+
var name = "@sanity/client", version = "6.24.0-canary.0";
|
|
1555
1567
|
const middleware = [
|
|
1556
1568
|
debug({ verbose: !0, namespace: "sanity:client" }),
|
|
1557
1569
|
headers({ "User-Agent": `${name} ${version}` }),
|