@sanity/client 6.23.0 → 6.24.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 +128 -114
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.d.cts +14 -1
- package/dist/index.browser.d.ts +14 -1
- package/dist/index.browser.js +129 -115
- package/dist/index.browser.js.map +1 -1
- package/dist/index.cjs +129 -115
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +14 -1
- package/dist/index.d.ts +14 -1
- package/dist/index.js +130 -116
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/config.ts +27 -2
- package/src/data/dataMethods.ts +10 -5
- package/src/defineCreateClient.ts +1 -0
- package/src/types.ts +9 -1
- package/umd/sanityClient.js +128 -114
- package/umd/sanityClient.min.js +2 -2
package/package.json
CHANGED
package/src/config.ts
CHANGED
|
@@ -28,9 +28,34 @@ function validateApiVersion(apiVersion: string) {
|
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
|
|
31
|
+
/**
|
|
32
|
+
* @internal - it may have breaking changes in any release
|
|
33
|
+
*/
|
|
34
|
+
export const validateApiPerspective = function validateApiPerspective(perspective: unknown) {
|
|
35
|
+
if (Array.isArray(perspective)) {
|
|
36
|
+
for (const perspectiveValue of perspective) {
|
|
37
|
+
if (perspectiveValue === 'published') {
|
|
38
|
+
continue
|
|
39
|
+
}
|
|
40
|
+
if (perspectiveValue === 'drafts') {
|
|
41
|
+
continue
|
|
42
|
+
}
|
|
43
|
+
if (
|
|
44
|
+
typeof perspectiveValue === 'string' &&
|
|
45
|
+
perspectiveValue.startsWith('r') &&
|
|
46
|
+
perspectiveValue !== 'raw'
|
|
47
|
+
) {
|
|
48
|
+
continue
|
|
49
|
+
}
|
|
50
|
+
throw new TypeError(
|
|
51
|
+
'Invalid API perspective value, expected `published`, `drafts` or a valid release identifier string',
|
|
52
|
+
)
|
|
53
|
+
}
|
|
54
|
+
return
|
|
55
|
+
}
|
|
32
56
|
switch (perspective as ClientPerspective) {
|
|
33
57
|
case 'previewDrafts':
|
|
58
|
+
case 'drafts':
|
|
34
59
|
case 'published':
|
|
35
60
|
case 'raw':
|
|
36
61
|
return
|
|
@@ -74,7 +99,7 @@ export const initConfig = (
|
|
|
74
99
|
throw new Error('Configuration must contain `projectId`')
|
|
75
100
|
}
|
|
76
101
|
|
|
77
|
-
if (typeof newConfig.perspective
|
|
102
|
+
if (typeof newConfig.perspective !== 'undefined') {
|
|
78
103
|
validateApiPerspective(newConfig.perspective)
|
|
79
104
|
}
|
|
80
105
|
|
package/src/data/dataMethods.ts
CHANGED
|
@@ -405,12 +405,17 @@ export function _requestObservable<R>(
|
|
|
405
405
|
if (resultSourceMap !== undefined && resultSourceMap !== false) {
|
|
406
406
|
options.query = {resultSourceMap, ...options.query}
|
|
407
407
|
}
|
|
408
|
-
const
|
|
409
|
-
if (typeof
|
|
410
|
-
validateApiPerspective(
|
|
411
|
-
options.query = {
|
|
408
|
+
const perspectiveOption = options.perspective || config.perspective
|
|
409
|
+
if (typeof perspectiveOption !== 'undefined') {
|
|
410
|
+
validateApiPerspective(perspectiveOption)
|
|
411
|
+
options.query = {
|
|
412
|
+
perspective: Array.isArray(perspectiveOption)
|
|
413
|
+
? perspectiveOption.join(',')
|
|
414
|
+
: perspectiveOption,
|
|
415
|
+
...options.query,
|
|
416
|
+
}
|
|
412
417
|
// If the perspective is set to `previewDrafts` we can't use the CDN, the API will throw
|
|
413
|
-
if (
|
|
418
|
+
if (perspectiveOption === 'previewDrafts' && useCdn) {
|
|
414
419
|
useCdn = false
|
|
415
420
|
printCdnPreviewDraftsWarning()
|
|
416
421
|
}
|
|
@@ -3,6 +3,7 @@ import type {Middlewares} from 'get-it'
|
|
|
3
3
|
import {defineHttpRequest} from './http/request'
|
|
4
4
|
import type {Any, ClientConfig, HttpRequest} from './types'
|
|
5
5
|
|
|
6
|
+
export {validateApiPerspective} from './config'
|
|
6
7
|
export * from './data/patch'
|
|
7
8
|
export * from './data/transaction'
|
|
8
9
|
export {ClientError, CorsOriginError, ServerError} from './http/errors'
|
package/src/types.ts
CHANGED
|
@@ -32,7 +32,15 @@ export interface RequestOptions {
|
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
/** @public */
|
|
35
|
-
export type
|
|
35
|
+
export type ReleaseId = `r${string}`
|
|
36
|
+
|
|
37
|
+
/** @public */
|
|
38
|
+
export type ClientPerspective =
|
|
39
|
+
| 'previewDrafts'
|
|
40
|
+
| 'published'
|
|
41
|
+
| 'drafts'
|
|
42
|
+
| 'raw'
|
|
43
|
+
| ('published' | 'drafts' | ReleaseId)[]
|
|
36
44
|
|
|
37
45
|
/** @public */
|
|
38
46
|
export interface ClientConfig {
|
package/umd/sanityClient.js
CHANGED
|
@@ -1178,22 +1178,9 @@
|
|
|
1178
1178
|
const isSafe = options.method === "GET" || options.method === "HEAD", isQuery = (options.uri || options.url).startsWith("/data/query"), isRetriableResponse = err.response && (err.response.statusCode === 429 || err.response.statusCode === 502 || err.response.statusCode === 503);
|
|
1179
1179
|
return (isSafe || isQuery) && isRetriableResponse ? !0 : _$1.shouldRetry(err, attempt, options);
|
|
1180
1180
|
}
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
if (Array.isArray(sel))
|
|
1185
|
-
return { query: "*[_id in $ids]", params: { ids: sel } };
|
|
1186
|
-
if (typeof sel == "object" && sel !== null && "query" in sel && typeof sel.query == "string")
|
|
1187
|
-
return "params" in sel && typeof sel.params == "object" && sel.params !== null ? { query: sel.query, params: sel.params } : { query: sel.query };
|
|
1188
|
-
const selectionOpts = [
|
|
1189
|
-
"* Document ID (<docId>)",
|
|
1190
|
-
"* Array of document IDs",
|
|
1191
|
-
"* Object containing `query`"
|
|
1192
|
-
].join(`
|
|
1193
|
-
`);
|
|
1194
|
-
throw new Error(`Unknown selection - must be one of:
|
|
1195
|
-
|
|
1196
|
-
${selectionOpts}`);
|
|
1181
|
+
const BASE_URL = "https://www.sanity.io/help/";
|
|
1182
|
+
function generateHelpUrl(slug) {
|
|
1183
|
+
return BASE_URL + slug;
|
|
1197
1184
|
}
|
|
1198
1185
|
const VALID_ASSET_TYPES = ["image", "file"], VALID_INSERT_LOCATIONS = ["before", "after", "replace"], dataset = (name) => {
|
|
1199
1186
|
if (!/^(~[a-z0-9]{1}[-\w]{0,63}|[a-z0-9]{1}[-\w]{0,63})$/.test(name))
|
|
@@ -1237,6 +1224,124 @@ ${selectionOpts}`);
|
|
|
1237
1224
|
);
|
|
1238
1225
|
return tag;
|
|
1239
1226
|
};
|
|
1227
|
+
function once(fn) {
|
|
1228
|
+
let didCall = !1, returnValue;
|
|
1229
|
+
return (...args) => (didCall || (returnValue = fn(...args), didCall = !0), returnValue);
|
|
1230
|
+
}
|
|
1231
|
+
const createWarningPrinter = (message) => (
|
|
1232
|
+
// eslint-disable-next-line no-console
|
|
1233
|
+
once((...args) => console.warn(message.join(" "), ...args))
|
|
1234
|
+
), printCdnAndWithCredentialsWarning = createWarningPrinter([
|
|
1235
|
+
"Because you set `withCredentials` to true, we will override your `useCdn`",
|
|
1236
|
+
"setting to be false since (cookie-based) credentials are never set on the CDN"
|
|
1237
|
+
]), printCdnWarning = createWarningPrinter([
|
|
1238
|
+
"Since you haven't set a value for `useCdn`, we will deliver content using our",
|
|
1239
|
+
"global, edge-cached API-CDN. If you wish to have content delivered faster, set",
|
|
1240
|
+
"`useCdn: false` to use the Live API. Note: You may incur higher costs using the live API."
|
|
1241
|
+
]), printCdnPreviewDraftsWarning = createWarningPrinter([
|
|
1242
|
+
"The Sanity client is configured with the `perspective` set to `previewDrafts`, which doesn't support the API-CDN.",
|
|
1243
|
+
"The Live API will be used instead. Set `useCdn: false` in your configuration to hide this warning."
|
|
1244
|
+
]), printBrowserTokenWarning = createWarningPrinter([
|
|
1245
|
+
"You have configured Sanity client to use a token in the browser. This may cause unintentional security issues.",
|
|
1246
|
+
`See ${generateHelpUrl(
|
|
1247
|
+
"js-client-browser-token"
|
|
1248
|
+
)} for more information and how to hide this warning.`
|
|
1249
|
+
]), printNoApiVersionSpecifiedWarning = createWarningPrinter([
|
|
1250
|
+
"Using the Sanity client without specifying an API version is deprecated.",
|
|
1251
|
+
`See ${generateHelpUrl("js-client-api-version")}`
|
|
1252
|
+
]), printNoDefaultExport = createWarningPrinter([
|
|
1253
|
+
"The default export of @sanity/client has been deprecated. Use the named export `createClient` instead."
|
|
1254
|
+
]), defaultCdnHost = "apicdn.sanity.io", defaultConfig = {
|
|
1255
|
+
apiHost: "https://api.sanity.io",
|
|
1256
|
+
apiVersion: "1",
|
|
1257
|
+
useProjectHostname: !0,
|
|
1258
|
+
stega: { enabled: !1 }
|
|
1259
|
+
}, LOCALHOSTS = ["localhost", "127.0.0.1", "0.0.0.0"], isLocal = (host) => LOCALHOSTS.indexOf(host) !== -1;
|
|
1260
|
+
function validateApiVersion(apiVersion) {
|
|
1261
|
+
if (apiVersion === "1" || apiVersion === "X")
|
|
1262
|
+
return;
|
|
1263
|
+
const apiDate = new Date(apiVersion);
|
|
1264
|
+
if (!(/^\d{4}-\d{2}-\d{2}$/.test(apiVersion) && apiDate instanceof Date && apiDate.getTime() > 0))
|
|
1265
|
+
throw new Error("Invalid API version string, expected `1` or date in format `YYYY-MM-DD`");
|
|
1266
|
+
}
|
|
1267
|
+
const validateApiPerspective = function(perspective) {
|
|
1268
|
+
if (Array.isArray(perspective)) {
|
|
1269
|
+
for (const perspectiveValue of perspective)
|
|
1270
|
+
if (perspectiveValue !== "published" && perspectiveValue !== "drafts" && !(typeof perspectiveValue == "string" && perspectiveValue.startsWith("r") && perspectiveValue !== "raw"))
|
|
1271
|
+
throw new TypeError(
|
|
1272
|
+
"Invalid API perspective value, expected `published`, `drafts` or a valid release identifier string"
|
|
1273
|
+
);
|
|
1274
|
+
return;
|
|
1275
|
+
}
|
|
1276
|
+
switch (perspective) {
|
|
1277
|
+
case "previewDrafts":
|
|
1278
|
+
case "drafts":
|
|
1279
|
+
case "published":
|
|
1280
|
+
case "raw":
|
|
1281
|
+
return;
|
|
1282
|
+
default:
|
|
1283
|
+
throw new TypeError(
|
|
1284
|
+
"Invalid API perspective string, expected `published`, `previewDrafts` or `raw`"
|
|
1285
|
+
);
|
|
1286
|
+
}
|
|
1287
|
+
}, initConfig = (config, prevConfig) => {
|
|
1288
|
+
const specifiedConfig = {
|
|
1289
|
+
...prevConfig,
|
|
1290
|
+
...config,
|
|
1291
|
+
stega: {
|
|
1292
|
+
...typeof prevConfig.stega == "boolean" ? { enabled: prevConfig.stega } : prevConfig.stega || defaultConfig.stega,
|
|
1293
|
+
...typeof config.stega == "boolean" ? { enabled: config.stega } : config.stega || {}
|
|
1294
|
+
}
|
|
1295
|
+
};
|
|
1296
|
+
specifiedConfig.apiVersion || printNoApiVersionSpecifiedWarning();
|
|
1297
|
+
const newConfig = {
|
|
1298
|
+
...defaultConfig,
|
|
1299
|
+
...specifiedConfig
|
|
1300
|
+
}, projectBased = newConfig.useProjectHostname;
|
|
1301
|
+
if (typeof Promise > "u") {
|
|
1302
|
+
const helpUrl = generateHelpUrl("js-client-promise-polyfill");
|
|
1303
|
+
throw new Error(`No native Promise-implementation found, polyfill needed - see ${helpUrl}`);
|
|
1304
|
+
}
|
|
1305
|
+
if (projectBased && !newConfig.projectId)
|
|
1306
|
+
throw new Error("Configuration must contain `projectId`");
|
|
1307
|
+
if (typeof newConfig.perspective < "u" && validateApiPerspective(newConfig.perspective), "encodeSourceMap" in newConfig)
|
|
1308
|
+
throw new Error(
|
|
1309
|
+
"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'?"
|
|
1310
|
+
);
|
|
1311
|
+
if ("encodeSourceMapAtPath" in newConfig)
|
|
1312
|
+
throw new Error(
|
|
1313
|
+
"It looks like you're using options meant for '@sanity/preview-kit/client'. 'encodeSourceMapAtPath' is not supported in '@sanity/client'. Did you mean 'stega.filter'?"
|
|
1314
|
+
);
|
|
1315
|
+
if (typeof newConfig.stega.enabled != "boolean")
|
|
1316
|
+
throw new Error(`stega.enabled must be a boolean, received ${newConfig.stega.enabled}`);
|
|
1317
|
+
if (newConfig.stega.enabled && newConfig.stega.studioUrl === void 0)
|
|
1318
|
+
throw new Error("stega.studioUrl must be defined when stega.enabled is true");
|
|
1319
|
+
if (newConfig.stega.enabled && typeof newConfig.stega.studioUrl != "string" && typeof newConfig.stega.studioUrl != "function")
|
|
1320
|
+
throw new Error(
|
|
1321
|
+
`stega.studioUrl must be a string or a function, received ${newConfig.stega.studioUrl}`
|
|
1322
|
+
);
|
|
1323
|
+
const isBrowser = typeof window < "u" && window.location && window.location.hostname, isLocalhost = isBrowser && isLocal(window.location.hostname);
|
|
1324
|
+
isBrowser && isLocalhost && newConfig.token && newConfig.ignoreBrowserTokenWarning !== !0 ? printBrowserTokenWarning() : typeof newConfig.useCdn > "u" && printCdnWarning(), projectBased && projectId(newConfig.projectId), newConfig.dataset && dataset(newConfig.dataset), "requestTagPrefix" in newConfig && (newConfig.requestTagPrefix = newConfig.requestTagPrefix ? requestTag(newConfig.requestTagPrefix).replace(/\.+$/, "") : void 0), newConfig.apiVersion = `${newConfig.apiVersion}`.replace(/^v/, ""), newConfig.isDefaultApi = newConfig.apiHost === defaultConfig.apiHost, newConfig.useCdn === !0 && newConfig.withCredentials && printCdnAndWithCredentialsWarning(), newConfig.useCdn = newConfig.useCdn !== !1 && !newConfig.withCredentials, validateApiVersion(newConfig.apiVersion);
|
|
1325
|
+
const hostParts = newConfig.apiHost.split("://", 2), protocol = hostParts[0], host = hostParts[1], cdnHost = newConfig.isDefaultApi ? defaultCdnHost : host;
|
|
1326
|
+
return newConfig.useProjectHostname ? (newConfig.url = `${protocol}://${newConfig.projectId}.${host}/v${newConfig.apiVersion}`, newConfig.cdnUrl = `${protocol}://${newConfig.projectId}.${cdnHost}/v${newConfig.apiVersion}`) : (newConfig.url = `${newConfig.apiHost}/v${newConfig.apiVersion}`, newConfig.cdnUrl = newConfig.url), newConfig;
|
|
1327
|
+
};
|
|
1328
|
+
function getSelection(sel) {
|
|
1329
|
+
if (typeof sel == "string")
|
|
1330
|
+
return { id: sel };
|
|
1331
|
+
if (Array.isArray(sel))
|
|
1332
|
+
return { query: "*[_id in $ids]", params: { ids: sel } };
|
|
1333
|
+
if (typeof sel == "object" && sel !== null && "query" in sel && typeof sel.query == "string")
|
|
1334
|
+
return "params" in sel && typeof sel.params == "object" && sel.params !== null ? { query: sel.query, params: sel.params } : { query: sel.query };
|
|
1335
|
+
const selectionOpts = [
|
|
1336
|
+
"* Document ID (<docId>)",
|
|
1337
|
+
"* Array of document IDs",
|
|
1338
|
+
"* Object containing `query`"
|
|
1339
|
+
].join(`
|
|
1340
|
+
`);
|
|
1341
|
+
throw new Error(`Unknown selection - must be one of:
|
|
1342
|
+
|
|
1343
|
+
${selectionOpts}`);
|
|
1344
|
+
}
|
|
1240
1345
|
class BasePatch {
|
|
1241
1346
|
selection;
|
|
1242
1347
|
operations;
|
|
@@ -1550,102 +1655,7 @@ ${selectionOpts}`);
|
|
|
1550
1655
|
return this._add({ patch: { id: patchOrDocumentId, ...patchOps } });
|
|
1551
1656
|
}
|
|
1552
1657
|
}
|
|
1553
|
-
const
|
|
1554
|
-
function generateHelpUrl(slug) {
|
|
1555
|
-
return BASE_URL + slug;
|
|
1556
|
-
}
|
|
1557
|
-
function once(fn) {
|
|
1558
|
-
let didCall = !1, returnValue;
|
|
1559
|
-
return (...args) => (didCall || (returnValue = fn(...args), didCall = !0), returnValue);
|
|
1560
|
-
}
|
|
1561
|
-
const createWarningPrinter = (message) => (
|
|
1562
|
-
// eslint-disable-next-line no-console
|
|
1563
|
-
once((...args) => console.warn(message.join(" "), ...args))
|
|
1564
|
-
), printCdnAndWithCredentialsWarning = createWarningPrinter([
|
|
1565
|
-
"Because you set `withCredentials` to true, we will override your `useCdn`",
|
|
1566
|
-
"setting to be false since (cookie-based) credentials are never set on the CDN"
|
|
1567
|
-
]), printCdnWarning = createWarningPrinter([
|
|
1568
|
-
"Since you haven't set a value for `useCdn`, we will deliver content using our",
|
|
1569
|
-
"global, edge-cached API-CDN. If you wish to have content delivered faster, set",
|
|
1570
|
-
"`useCdn: false` to use the Live API. Note: You may incur higher costs using the live API."
|
|
1571
|
-
]), printCdnPreviewDraftsWarning = createWarningPrinter([
|
|
1572
|
-
"The Sanity client is configured with the `perspective` set to `previewDrafts`, which doesn't support the API-CDN.",
|
|
1573
|
-
"The Live API will be used instead. Set `useCdn: false` in your configuration to hide this warning."
|
|
1574
|
-
]), printBrowserTokenWarning = createWarningPrinter([
|
|
1575
|
-
"You have configured Sanity client to use a token in the browser. This may cause unintentional security issues.",
|
|
1576
|
-
`See ${generateHelpUrl(
|
|
1577
|
-
"js-client-browser-token"
|
|
1578
|
-
)} for more information and how to hide this warning.`
|
|
1579
|
-
]), printNoApiVersionSpecifiedWarning = createWarningPrinter([
|
|
1580
|
-
"Using the Sanity client without specifying an API version is deprecated.",
|
|
1581
|
-
`See ${generateHelpUrl("js-client-api-version")}`
|
|
1582
|
-
]), printNoDefaultExport = createWarningPrinter([
|
|
1583
|
-
"The default export of @sanity/client has been deprecated. Use the named export `createClient` instead."
|
|
1584
|
-
]), defaultCdnHost = "apicdn.sanity.io", defaultConfig = {
|
|
1585
|
-
apiHost: "https://api.sanity.io",
|
|
1586
|
-
apiVersion: "1",
|
|
1587
|
-
useProjectHostname: !0,
|
|
1588
|
-
stega: { enabled: !1 }
|
|
1589
|
-
}, LOCALHOSTS = ["localhost", "127.0.0.1", "0.0.0.0"], isLocal = (host) => LOCALHOSTS.indexOf(host) !== -1;
|
|
1590
|
-
function validateApiVersion(apiVersion) {
|
|
1591
|
-
if (apiVersion === "1" || apiVersion === "X")
|
|
1592
|
-
return;
|
|
1593
|
-
const apiDate = new Date(apiVersion);
|
|
1594
|
-
if (!(/^\d{4}-\d{2}-\d{2}$/.test(apiVersion) && apiDate instanceof Date && apiDate.getTime() > 0))
|
|
1595
|
-
throw new Error("Invalid API version string, expected `1` or date in format `YYYY-MM-DD`");
|
|
1596
|
-
}
|
|
1597
|
-
const validateApiPerspective = function(perspective) {
|
|
1598
|
-
switch (perspective) {
|
|
1599
|
-
case "previewDrafts":
|
|
1600
|
-
case "published":
|
|
1601
|
-
case "raw":
|
|
1602
|
-
return;
|
|
1603
|
-
default:
|
|
1604
|
-
throw new TypeError(
|
|
1605
|
-
"Invalid API perspective string, expected `published`, `previewDrafts` or `raw`"
|
|
1606
|
-
);
|
|
1607
|
-
}
|
|
1608
|
-
}, initConfig = (config, prevConfig) => {
|
|
1609
|
-
const specifiedConfig = {
|
|
1610
|
-
...prevConfig,
|
|
1611
|
-
...config,
|
|
1612
|
-
stega: {
|
|
1613
|
-
...typeof prevConfig.stega == "boolean" ? { enabled: prevConfig.stega } : prevConfig.stega || defaultConfig.stega,
|
|
1614
|
-
...typeof config.stega == "boolean" ? { enabled: config.stega } : config.stega || {}
|
|
1615
|
-
}
|
|
1616
|
-
};
|
|
1617
|
-
specifiedConfig.apiVersion || printNoApiVersionSpecifiedWarning();
|
|
1618
|
-
const newConfig = {
|
|
1619
|
-
...defaultConfig,
|
|
1620
|
-
...specifiedConfig
|
|
1621
|
-
}, projectBased = newConfig.useProjectHostname;
|
|
1622
|
-
if (typeof Promise > "u") {
|
|
1623
|
-
const helpUrl = generateHelpUrl("js-client-promise-polyfill");
|
|
1624
|
-
throw new Error(`No native Promise-implementation found, polyfill needed - see ${helpUrl}`);
|
|
1625
|
-
}
|
|
1626
|
-
if (projectBased && !newConfig.projectId)
|
|
1627
|
-
throw new Error("Configuration must contain `projectId`");
|
|
1628
|
-
if (typeof newConfig.perspective == "string" && validateApiPerspective(newConfig.perspective), "encodeSourceMap" in newConfig)
|
|
1629
|
-
throw new Error(
|
|
1630
|
-
"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'?"
|
|
1631
|
-
);
|
|
1632
|
-
if ("encodeSourceMapAtPath" in newConfig)
|
|
1633
|
-
throw new Error(
|
|
1634
|
-
"It looks like you're using options meant for '@sanity/preview-kit/client'. 'encodeSourceMapAtPath' is not supported in '@sanity/client'. Did you mean 'stega.filter'?"
|
|
1635
|
-
);
|
|
1636
|
-
if (typeof newConfig.stega.enabled != "boolean")
|
|
1637
|
-
throw new Error(`stega.enabled must be a boolean, received ${newConfig.stega.enabled}`);
|
|
1638
|
-
if (newConfig.stega.enabled && newConfig.stega.studioUrl === void 0)
|
|
1639
|
-
throw new Error("stega.studioUrl must be defined when stega.enabled is true");
|
|
1640
|
-
if (newConfig.stega.enabled && typeof newConfig.stega.studioUrl != "string" && typeof newConfig.stega.studioUrl != "function")
|
|
1641
|
-
throw new Error(
|
|
1642
|
-
`stega.studioUrl must be a string or a function, received ${newConfig.stega.studioUrl}`
|
|
1643
|
-
);
|
|
1644
|
-
const isBrowser = typeof window < "u" && window.location && window.location.hostname, isLocalhost = isBrowser && isLocal(window.location.hostname);
|
|
1645
|
-
isBrowser && isLocalhost && newConfig.token && newConfig.ignoreBrowserTokenWarning !== !0 ? printBrowserTokenWarning() : typeof newConfig.useCdn > "u" && printCdnWarning(), projectBased && projectId(newConfig.projectId), newConfig.dataset && dataset(newConfig.dataset), "requestTagPrefix" in newConfig && (newConfig.requestTagPrefix = newConfig.requestTagPrefix ? requestTag(newConfig.requestTagPrefix).replace(/\.+$/, "") : void 0), newConfig.apiVersion = `${newConfig.apiVersion}`.replace(/^v/, ""), newConfig.isDefaultApi = newConfig.apiHost === defaultConfig.apiHost, newConfig.useCdn === !0 && newConfig.withCredentials && printCdnAndWithCredentialsWarning(), newConfig.useCdn = newConfig.useCdn !== !1 && !newConfig.withCredentials, validateApiVersion(newConfig.apiVersion);
|
|
1646
|
-
const hostParts = newConfig.apiHost.split("://", 2), protocol = hostParts[0], host = hostParts[1], cdnHost = newConfig.isDefaultApi ? defaultCdnHost : host;
|
|
1647
|
-
return newConfig.useProjectHostname ? (newConfig.url = `${protocol}://${newConfig.projectId}.${host}/v${newConfig.apiVersion}`, newConfig.cdnUrl = `${protocol}://${newConfig.projectId}.${cdnHost}/v${newConfig.apiVersion}`) : (newConfig.url = `${newConfig.apiHost}/v${newConfig.apiVersion}`, newConfig.cdnUrl = newConfig.url), newConfig;
|
|
1648
|
-
}, projectHeader = "X-Sanity-Project-ID";
|
|
1658
|
+
const projectHeader = "X-Sanity-Project-ID";
|
|
1649
1659
|
function requestOptions(config, overrides = {}) {
|
|
1650
1660
|
const headers = {}, token = overrides.token || config.token;
|
|
1651
1661
|
token && (headers.Authorization = `Bearer ${token}`), !overrides.useGlobalApi && !config.useProjectHostname && config.projectId && (headers[projectHeader] = config.projectId);
|
|
@@ -1821,8 +1831,11 @@ ${selectionOpts}`);
|
|
|
1821
1831
|
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) {
|
|
1822
1832
|
const resultSourceMap = options.resultSourceMap ?? config.resultSourceMap;
|
|
1823
1833
|
resultSourceMap !== void 0 && resultSourceMap !== !1 && (options.query = { resultSourceMap, ...options.query });
|
|
1824
|
-
const
|
|
1825
|
-
typeof
|
|
1834
|
+
const perspectiveOption = options.perspective || config.perspective;
|
|
1835
|
+
typeof perspectiveOption < "u" && (validateApiPerspective(perspectiveOption), options.query = {
|
|
1836
|
+
perspective: Array.isArray(perspectiveOption) ? perspectiveOption.join(",") : perspectiveOption,
|
|
1837
|
+
...options.query
|
|
1838
|
+
}, 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 });
|
|
1826
1839
|
}
|
|
1827
1840
|
const reqOptions = requestOptions(
|
|
1828
1841
|
config,
|
|
@@ -4061,6 +4074,7 @@ ${selectionOpts}`);
|
|
|
4061
4074
|
exports.requester = requester;
|
|
4062
4075
|
exports.unstable__adapter = l$1;
|
|
4063
4076
|
exports.unstable__environment = p$1;
|
|
4077
|
+
exports.validateApiPerspective = validateApiPerspective;
|
|
4064
4078
|
|
|
4065
4079
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4066
4080
|
|