@sanity/client
Advanced tools
Comparing version 6.23.0 to 6.24.0-canary.0
{ | ||
"name": "@sanity/client", | ||
"version": "6.23.0", | ||
"version": "6.24.0-canary.0", | ||
"description": "Client for retrieving, creating and patching data from Sanity.io", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -31,5 +31,27 @@ import {generateHelpUrl} from './generateHelpUrl' | ||
export const validateApiPerspective = function validateApiPerspective(perspective: string) { | ||
export const validateApiPerspective = function validateApiPerspective(perspective: unknown) { | ||
if (Array.isArray(perspective)) { | ||
for (const perspectiveValue of perspective) { | ||
if (perspectiveValue === 'published') { | ||
continue | ||
} | ||
if (perspectiveValue === 'drafts') { | ||
continue | ||
} | ||
if ( | ||
typeof perspectiveValue === 'string' && | ||
perspectiveValue.startsWith('r') && | ||
perspectiveValue !== 'raw' | ||
) { | ||
continue | ||
} | ||
throw new TypeError( | ||
'Invalid API perspective value, expected `published`, `drafts` or a valid release identifier string', | ||
) | ||
} | ||
return | ||
} | ||
switch (perspective as ClientPerspective) { | ||
case 'previewDrafts': | ||
case 'drafts': | ||
case 'published': | ||
@@ -78,3 +100,3 @@ case 'raw': | ||
if (typeof newConfig.perspective === 'string') { | ||
if (typeof newConfig.perspective !== 'undefined') { | ||
validateApiPerspective(newConfig.perspective) | ||
@@ -81,0 +103,0 @@ } |
@@ -408,8 +408,13 @@ import {from, type MonoTypeOperatorFunction, Observable} from 'rxjs' | ||
} | ||
const perspective = options.perspective || config.perspective | ||
if (typeof perspective === 'string' && perspective !== 'raw') { | ||
validateApiPerspective(perspective) | ||
options.query = {perspective, ...options.query} | ||
const perspectiveOption = options.perspective || config.perspective | ||
if (typeof perspectiveOption !== 'undefined') { | ||
validateApiPerspective(perspectiveOption) | ||
options.query = { | ||
perspective: Array.isArray(perspectiveOption) | ||
? perspectiveOption.join(',') | ||
: perspectiveOption, | ||
...options.query, | ||
} | ||
// If the perspective is set to `previewDrafts` we can't use the CDN, the API will throw | ||
if (perspective === 'previewDrafts' && useCdn) { | ||
if (perspectiveOption === 'previewDrafts' && useCdn) { | ||
useCdn = false | ||
@@ -416,0 +421,0 @@ printCdnPreviewDraftsWarning() |
@@ -35,5 +35,13 @@ // deno-lint-ignore-file no-empty-interface | ||
/** @public */ | ||
export type ClientPerspective = 'previewDrafts' | 'published' | 'raw' | ||
export type ReleaseId = `r${string}` | ||
/** @public */ | ||
export type ClientPerspective = | ||
| 'previewDrafts' | ||
| 'published' | ||
| 'drafts' | ||
| 'raw' | ||
| ('published' | 'drafts' | ReleaseId)[] | ||
/** @public */ | ||
export interface ClientConfig { | ||
@@ -40,0 +48,0 @@ projectId?: string |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
2213256
25215
1