@sanity/client 6.28.0-resources.0 → 6.28.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 +5 -3
- package/dist/_chunks-cjs/config.cjs +2 -16
- package/dist/_chunks-cjs/config.cjs.map +1 -1
- package/dist/_chunks-es/config.js +2 -16
- package/dist/_chunks-es/config.js.map +1 -1
- package/dist/index.browser.cjs +10 -56
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.d.cts +16 -9
- package/dist/index.browser.d.ts +16 -9
- package/dist/index.browser.js +10 -56
- package/dist/index.browser.js.map +1 -1
- package/dist/index.cjs +9 -41
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +21 -10
- package/dist/index.d.ts +21 -10
- package/dist/index.js +9 -41
- package/dist/index.js.map +1 -1
- package/dist/stega.browser.d.cts +16 -9
- package/dist/stega.browser.d.ts +16 -9
- package/dist/stega.d.cts +16 -9
- package/dist/stega.d.ts +16 -9
- package/package.json +1 -1
- package/src/SanityClient.ts +2 -9
- package/src/assets/AssetsClient.ts +2 -6
- package/src/config.ts +0 -25
- package/src/data/dataMethods.ts +4 -39
- package/src/datasets/DatasetsClient.ts +0 -22
- package/src/index.ts +5 -1
- package/src/types.ts +18 -10
- package/umd/sanityClient.js +10 -56
- package/umd/sanityClient.min.js +2 -2
package/dist/stega.browser.d.cts
CHANGED
|
@@ -333,9 +333,18 @@ export declare interface ClientConfig {
|
|
|
333
333
|
/** @defaultValue true */
|
|
334
334
|
useCdn?: boolean
|
|
335
335
|
token?: string
|
|
336
|
-
/**
|
|
336
|
+
/**
|
|
337
|
+
* What perspective to use for the client. See {@link https://www.sanity.io/docs/perspectives|perspective documentation}
|
|
338
|
+
* @remarks
|
|
339
|
+
* As of API version `v2025-02-19`, the default perspective has changed from `raw` to `published`. {@link https://www.sanity.io/changelog/e93a2d5a-9cee-4801-829e-8d3394bfed85|Changelog}
|
|
340
|
+
* @defaultValue 'published'
|
|
341
|
+
*/
|
|
337
342
|
perspective?: ClientPerspective
|
|
338
343
|
apiHost?: string
|
|
344
|
+
/**
|
|
345
|
+
@remarks
|
|
346
|
+
* As of API version `v2025-02-19`, the default perspective has changed from `raw` to `published`. {@link https://www.sanity.io/changelog/e93a2d5a-9cee-4801-829e-8d3394bfed85|Changelog}
|
|
347
|
+
*/
|
|
339
348
|
apiVersion?: string
|
|
340
349
|
proxy?: string
|
|
341
350
|
/**
|
|
@@ -382,13 +391,6 @@ export declare interface ClientConfig {
|
|
|
382
391
|
* Options for how, if enabled, Content Source Maps are encoded into query results using steganography
|
|
383
392
|
*/
|
|
384
393
|
stega?: StegaConfig | boolean
|
|
385
|
-
/**
|
|
386
|
-
* @deprecated Don't use
|
|
387
|
-
*/
|
|
388
|
-
experimental_resource?: {
|
|
389
|
-
id: string
|
|
390
|
-
type: string
|
|
391
|
-
}
|
|
392
394
|
}
|
|
393
395
|
|
|
394
396
|
/** @public */
|
|
@@ -1131,7 +1133,12 @@ export declare interface ListenOptions {
|
|
|
1131
1133
|
*/
|
|
1132
1134
|
includePreviousRevision?: boolean
|
|
1133
1135
|
/**
|
|
1134
|
-
*
|
|
1136
|
+
* Whether to include events for drafts and versions. As of API Version >= v2025-02-19, only events
|
|
1137
|
+
* for published documents will be included by default (see {@link https://www.sanity.io/changelog/e93a2d5a-9cee-4801-829e-8d3394bfed85|Changelog})
|
|
1138
|
+
* If you need events from drafts and versions, set this to `true`.
|
|
1139
|
+
* Note: Keep in mind that additional document variants may be introduced in the future, so it's
|
|
1140
|
+
* recommended to respond to events in a way that's tolerant of potential future variants, e.g. by
|
|
1141
|
+
* explicitly checking whether the event is for a draft or a version.
|
|
1135
1142
|
* @defaultValue `false`
|
|
1136
1143
|
*/
|
|
1137
1144
|
includeAllVersions?: boolean
|
package/dist/stega.browser.d.ts
CHANGED
|
@@ -333,9 +333,18 @@ export declare interface ClientConfig {
|
|
|
333
333
|
/** @defaultValue true */
|
|
334
334
|
useCdn?: boolean
|
|
335
335
|
token?: string
|
|
336
|
-
/**
|
|
336
|
+
/**
|
|
337
|
+
* What perspective to use for the client. See {@link https://www.sanity.io/docs/perspectives|perspective documentation}
|
|
338
|
+
* @remarks
|
|
339
|
+
* As of API version `v2025-02-19`, the default perspective has changed from `raw` to `published`. {@link https://www.sanity.io/changelog/e93a2d5a-9cee-4801-829e-8d3394bfed85|Changelog}
|
|
340
|
+
* @defaultValue 'published'
|
|
341
|
+
*/
|
|
337
342
|
perspective?: ClientPerspective
|
|
338
343
|
apiHost?: string
|
|
344
|
+
/**
|
|
345
|
+
@remarks
|
|
346
|
+
* As of API version `v2025-02-19`, the default perspective has changed from `raw` to `published`. {@link https://www.sanity.io/changelog/e93a2d5a-9cee-4801-829e-8d3394bfed85|Changelog}
|
|
347
|
+
*/
|
|
339
348
|
apiVersion?: string
|
|
340
349
|
proxy?: string
|
|
341
350
|
/**
|
|
@@ -382,13 +391,6 @@ export declare interface ClientConfig {
|
|
|
382
391
|
* Options for how, if enabled, Content Source Maps are encoded into query results using steganography
|
|
383
392
|
*/
|
|
384
393
|
stega?: StegaConfig | boolean
|
|
385
|
-
/**
|
|
386
|
-
* @deprecated Don't use
|
|
387
|
-
*/
|
|
388
|
-
experimental_resource?: {
|
|
389
|
-
id: string
|
|
390
|
-
type: string
|
|
391
|
-
}
|
|
392
394
|
}
|
|
393
395
|
|
|
394
396
|
/** @public */
|
|
@@ -1131,7 +1133,12 @@ export declare interface ListenOptions {
|
|
|
1131
1133
|
*/
|
|
1132
1134
|
includePreviousRevision?: boolean
|
|
1133
1135
|
/**
|
|
1134
|
-
*
|
|
1136
|
+
* Whether to include events for drafts and versions. As of API Version >= v2025-02-19, only events
|
|
1137
|
+
* for published documents will be included by default (see {@link https://www.sanity.io/changelog/e93a2d5a-9cee-4801-829e-8d3394bfed85|Changelog})
|
|
1138
|
+
* If you need events from drafts and versions, set this to `true`.
|
|
1139
|
+
* Note: Keep in mind that additional document variants may be introduced in the future, so it's
|
|
1140
|
+
* recommended to respond to events in a way that's tolerant of potential future variants, e.g. by
|
|
1141
|
+
* explicitly checking whether the event is for a draft or a version.
|
|
1135
1142
|
* @defaultValue `false`
|
|
1136
1143
|
*/
|
|
1137
1144
|
includeAllVersions?: boolean
|
package/dist/stega.d.cts
CHANGED
|
@@ -333,9 +333,18 @@ export declare interface ClientConfig {
|
|
|
333
333
|
/** @defaultValue true */
|
|
334
334
|
useCdn?: boolean
|
|
335
335
|
token?: string
|
|
336
|
-
/**
|
|
336
|
+
/**
|
|
337
|
+
* What perspective to use for the client. See {@link https://www.sanity.io/docs/perspectives|perspective documentation}
|
|
338
|
+
* @remarks
|
|
339
|
+
* As of API version `v2025-02-19`, the default perspective has changed from `raw` to `published`. {@link https://www.sanity.io/changelog/e93a2d5a-9cee-4801-829e-8d3394bfed85|Changelog}
|
|
340
|
+
* @defaultValue 'published'
|
|
341
|
+
*/
|
|
337
342
|
perspective?: ClientPerspective
|
|
338
343
|
apiHost?: string
|
|
344
|
+
/**
|
|
345
|
+
@remarks
|
|
346
|
+
* As of API version `v2025-02-19`, the default perspective has changed from `raw` to `published`. {@link https://www.sanity.io/changelog/e93a2d5a-9cee-4801-829e-8d3394bfed85|Changelog}
|
|
347
|
+
*/
|
|
339
348
|
apiVersion?: string
|
|
340
349
|
proxy?: string
|
|
341
350
|
/**
|
|
@@ -382,13 +391,6 @@ export declare interface ClientConfig {
|
|
|
382
391
|
* Options for how, if enabled, Content Source Maps are encoded into query results using steganography
|
|
383
392
|
*/
|
|
384
393
|
stega?: StegaConfig | boolean
|
|
385
|
-
/**
|
|
386
|
-
* @deprecated Don't use
|
|
387
|
-
*/
|
|
388
|
-
experimental_resource?: {
|
|
389
|
-
id: string
|
|
390
|
-
type: string
|
|
391
|
-
}
|
|
392
394
|
}
|
|
393
395
|
|
|
394
396
|
/** @public */
|
|
@@ -1131,7 +1133,12 @@ export declare interface ListenOptions {
|
|
|
1131
1133
|
*/
|
|
1132
1134
|
includePreviousRevision?: boolean
|
|
1133
1135
|
/**
|
|
1134
|
-
*
|
|
1136
|
+
* Whether to include events for drafts and versions. As of API Version >= v2025-02-19, only events
|
|
1137
|
+
* for published documents will be included by default (see {@link https://www.sanity.io/changelog/e93a2d5a-9cee-4801-829e-8d3394bfed85|Changelog})
|
|
1138
|
+
* If you need events from drafts and versions, set this to `true`.
|
|
1139
|
+
* Note: Keep in mind that additional document variants may be introduced in the future, so it's
|
|
1140
|
+
* recommended to respond to events in a way that's tolerant of potential future variants, e.g. by
|
|
1141
|
+
* explicitly checking whether the event is for a draft or a version.
|
|
1135
1142
|
* @defaultValue `false`
|
|
1136
1143
|
*/
|
|
1137
1144
|
includeAllVersions?: boolean
|
package/dist/stega.d.ts
CHANGED
|
@@ -333,9 +333,18 @@ export declare interface ClientConfig {
|
|
|
333
333
|
/** @defaultValue true */
|
|
334
334
|
useCdn?: boolean
|
|
335
335
|
token?: string
|
|
336
|
-
/**
|
|
336
|
+
/**
|
|
337
|
+
* What perspective to use for the client. See {@link https://www.sanity.io/docs/perspectives|perspective documentation}
|
|
338
|
+
* @remarks
|
|
339
|
+
* As of API version `v2025-02-19`, the default perspective has changed from `raw` to `published`. {@link https://www.sanity.io/changelog/e93a2d5a-9cee-4801-829e-8d3394bfed85|Changelog}
|
|
340
|
+
* @defaultValue 'published'
|
|
341
|
+
*/
|
|
337
342
|
perspective?: ClientPerspective
|
|
338
343
|
apiHost?: string
|
|
344
|
+
/**
|
|
345
|
+
@remarks
|
|
346
|
+
* As of API version `v2025-02-19`, the default perspective has changed from `raw` to `published`. {@link https://www.sanity.io/changelog/e93a2d5a-9cee-4801-829e-8d3394bfed85|Changelog}
|
|
347
|
+
*/
|
|
339
348
|
apiVersion?: string
|
|
340
349
|
proxy?: string
|
|
341
350
|
/**
|
|
@@ -382,13 +391,6 @@ export declare interface ClientConfig {
|
|
|
382
391
|
* Options for how, if enabled, Content Source Maps are encoded into query results using steganography
|
|
383
392
|
*/
|
|
384
393
|
stega?: StegaConfig | boolean
|
|
385
|
-
/**
|
|
386
|
-
* @deprecated Don't use
|
|
387
|
-
*/
|
|
388
|
-
experimental_resource?: {
|
|
389
|
-
id: string
|
|
390
|
-
type: string
|
|
391
|
-
}
|
|
392
394
|
}
|
|
393
395
|
|
|
394
396
|
/** @public */
|
|
@@ -1131,7 +1133,12 @@ export declare interface ListenOptions {
|
|
|
1131
1133
|
*/
|
|
1132
1134
|
includePreviousRevision?: boolean
|
|
1133
1135
|
/**
|
|
1134
|
-
*
|
|
1136
|
+
* Whether to include events for drafts and versions. As of API Version >= v2025-02-19, only events
|
|
1137
|
+
* for published documents will be included by default (see {@link https://www.sanity.io/changelog/e93a2d5a-9cee-4801-829e-8d3394bfed85|Changelog})
|
|
1138
|
+
* If you need events from drafts and versions, set this to `true`.
|
|
1139
|
+
* Note: Keep in mind that additional document variants may be introduced in the future, so it's
|
|
1140
|
+
* recommended to respond to events in a way that's tolerant of potential future variants, e.g. by
|
|
1141
|
+
* explicitly checking whether the event is for a draft or a version.
|
|
1135
1142
|
* @defaultValue `false`
|
|
1136
1143
|
*/
|
|
1137
1144
|
includeAllVersions?: boolean
|
package/package.json
CHANGED
package/src/SanityClient.ts
CHANGED
|
@@ -7,11 +7,7 @@ import {_listen} from './data/listen'
|
|
|
7
7
|
import {LiveClient} from './data/live'
|
|
8
8
|
import {ObservablePatch, Patch} from './data/patch'
|
|
9
9
|
import {ObservableTransaction, Transaction} from './data/transaction'
|
|
10
|
-
import {
|
|
11
|
-
DatasetsClient,
|
|
12
|
-
ObservableDatasetsClient,
|
|
13
|
-
ThrowingDatasetsClient,
|
|
14
|
-
} from './datasets/DatasetsClient'
|
|
10
|
+
import {DatasetsClient, ObservableDatasetsClient} from './datasets/DatasetsClient'
|
|
15
11
|
import {ObservableProjectsClient, ProjectsClient} from './projects/ProjectsClient'
|
|
16
12
|
import type {
|
|
17
13
|
Action,
|
|
@@ -760,10 +756,7 @@ export class SanityClient {
|
|
|
760
756
|
this.#httpRequest = httpRequest
|
|
761
757
|
|
|
762
758
|
this.assets = new AssetsClient(this, this.#httpRequest)
|
|
763
|
-
this.datasets = this.#
|
|
764
|
-
? new ThrowingDatasetsClient(this, this.#httpRequest)
|
|
765
|
-
: new DatasetsClient(this, this.#httpRequest)
|
|
766
|
-
|
|
759
|
+
this.datasets = new DatasetsClient(this, this.#httpRequest)
|
|
767
760
|
this.live = new LiveClient(this)
|
|
768
761
|
this.projects = new ProjectsClient(this, this.#httpRequest)
|
|
769
762
|
this.users = new UsersClient(this, this.#httpRequest)
|
|
@@ -149,9 +149,7 @@ function _upload(
|
|
|
149
149
|
meta = ['none']
|
|
150
150
|
}
|
|
151
151
|
|
|
152
|
-
const
|
|
153
|
-
const resource = config.experimental_resource
|
|
154
|
-
const dataset = resource ? undefined : validators.hasDataset(config)
|
|
152
|
+
const dataset = validators.hasDataset(client.config())
|
|
155
153
|
const assetEndpoint = assetType === 'image' ? 'images' : 'files'
|
|
156
154
|
const options = optionsFromFile(opts, body)
|
|
157
155
|
const {tag, label, title, description, creditLine, filename, source} = options
|
|
@@ -172,9 +170,7 @@ function _upload(
|
|
|
172
170
|
tag,
|
|
173
171
|
method: 'POST',
|
|
174
172
|
timeout: options.timeout || 0,
|
|
175
|
-
uri:
|
|
176
|
-
? `/assets/${resource.type}/${resource.id}/${assetEndpoint}`
|
|
177
|
-
: `/assets/${assetEndpoint}/${dataset}`,
|
|
173
|
+
uri: `/assets/${assetEndpoint}/${dataset}`,
|
|
178
174
|
headers: options.contentType ? {'Content-Type': options.contentType} : {},
|
|
179
175
|
query,
|
|
180
176
|
body,
|
package/src/config.ts
CHANGED
|
@@ -78,25 +78,6 @@ export const initConfig = (
|
|
|
78
78
|
...defaultConfig,
|
|
79
79
|
...specifiedConfig,
|
|
80
80
|
} as InitializedClientConfig
|
|
81
|
-
|
|
82
|
-
const projectId = newConfig.projectId
|
|
83
|
-
|
|
84
|
-
//this "feature" is meant for internal Sanity use only. Do not use.
|
|
85
|
-
if (projectId?.startsWith('resource.')) {
|
|
86
|
-
const [, resourceType, resourceId] = projectId.split('.')
|
|
87
|
-
if (resourceType && resourceId) {
|
|
88
|
-
newConfig.experimental_resource = {
|
|
89
|
-
type: resourceType,
|
|
90
|
-
id: resourceId,
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
// resource oriented clients should not use project hostname in base url
|
|
95
|
-
const experimentalResource = newConfig.experimental_resource
|
|
96
|
-
if (experimentalResource) {
|
|
97
|
-
newConfig.useProjectHostname = false
|
|
98
|
-
}
|
|
99
|
-
|
|
100
81
|
const projectBased = newConfig.useProjectHostname
|
|
101
82
|
|
|
102
83
|
if (typeof Promise === 'undefined') {
|
|
@@ -187,11 +168,5 @@ export const initConfig = (
|
|
|
187
168
|
newConfig.cdnUrl = newConfig.url
|
|
188
169
|
}
|
|
189
170
|
|
|
190
|
-
if (experimentalResource) {
|
|
191
|
-
const resourceSuffix = `${experimentalResource.type}/${experimentalResource.id}`
|
|
192
|
-
newConfig.url = `${newConfig.url}/${resourceSuffix}`
|
|
193
|
-
newConfig.cdnUrl = `${newConfig.cdnUrl}/${resourceSuffix}`
|
|
194
|
-
}
|
|
195
|
-
|
|
196
171
|
return newConfig
|
|
197
172
|
}
|
package/src/data/dataMethods.ts
CHANGED
|
@@ -12,7 +12,6 @@ import type {
|
|
|
12
12
|
Any,
|
|
13
13
|
BaseActionOptions,
|
|
14
14
|
BaseMutationOptions,
|
|
15
|
-
ClientConfig,
|
|
16
15
|
FirstDocumentIdMutationOptions,
|
|
17
16
|
FirstDocumentMutationOptions,
|
|
18
17
|
HttpRequest,
|
|
@@ -39,8 +38,6 @@ import {encodeQueryString} from './encodeQueryString'
|
|
|
39
38
|
import {ObservablePatch, Patch} from './patch'
|
|
40
39
|
import {ObservableTransaction, Transaction} from './transaction'
|
|
41
40
|
|
|
42
|
-
type ExperimentalResourceConfig = Exclude<ClientConfig['experimental_resource'], undefined>
|
|
43
|
-
|
|
44
41
|
const excludeFalsey = (param: Any, defValue: Any) => {
|
|
45
42
|
const value = typeof param === 'undefined' ? defValue : param
|
|
46
43
|
return param === false ? undefined : value
|
|
@@ -370,24 +367,6 @@ export function _create<R extends Record<string, Any>>(
|
|
|
370
367
|
return _dataRequest(client, httpRequest, 'mutate', {mutations: [mutation]}, opts)
|
|
371
368
|
}
|
|
372
369
|
|
|
373
|
-
function _resourceBase(resource: ExperimentalResourceConfig) {
|
|
374
|
-
return `/${resource.type}/${resource.id}`
|
|
375
|
-
}
|
|
376
|
-
|
|
377
|
-
function isDataRequestUri(uri: string, resource?: ExperimentalResourceConfig) {
|
|
378
|
-
if (resource) {
|
|
379
|
-
return uri.indexOf(`/${_resourceBase(resource)}/data/`) === 0
|
|
380
|
-
}
|
|
381
|
-
return uri.indexOf('/data/') === 0
|
|
382
|
-
}
|
|
383
|
-
|
|
384
|
-
function isDataQueryRequestUri(uri: string, resource?: ExperimentalResourceConfig) {
|
|
385
|
-
if (resource) {
|
|
386
|
-
return uri.indexOf(`/${_resourceBase(resource)}/data/query`) === 0
|
|
387
|
-
}
|
|
388
|
-
return uri.indexOf('/data/query') === 0
|
|
389
|
-
}
|
|
390
|
-
|
|
391
370
|
/**
|
|
392
371
|
* @internal
|
|
393
372
|
*/
|
|
@@ -403,8 +382,7 @@ export function _requestObservable<R>(
|
|
|
403
382
|
// Only the /data endpoint is currently available through API-CDN.
|
|
404
383
|
const canUseCdn =
|
|
405
384
|
typeof options.canUseCdn === 'undefined'
|
|
406
|
-
? ['GET', 'HEAD'].indexOf(options.method || 'GET') >= 0 &&
|
|
407
|
-
isDataRequestUri(uri, config.experimental_resource)
|
|
385
|
+
? ['GET', 'HEAD'].indexOf(options.method || 'GET') >= 0 && uri.indexOf('/data/') === 0
|
|
408
386
|
: options.canUseCdn
|
|
409
387
|
|
|
410
388
|
let useCdn = (options.useCdn ?? config.useCdn) && canUseCdn
|
|
@@ -421,7 +399,7 @@ export function _requestObservable<R>(
|
|
|
421
399
|
// GROQ query-only parameters
|
|
422
400
|
if (
|
|
423
401
|
['GET', 'HEAD', 'POST'].indexOf(options.method || 'GET') >= 0 &&
|
|
424
|
-
|
|
402
|
+
uri.indexOf('/data/query/') === 0
|
|
425
403
|
) {
|
|
426
404
|
const resultSourceMap = options.resultSourceMap ?? config.resultSourceMap
|
|
427
405
|
if (resultSourceMap !== undefined && resultSourceMap !== false) {
|
|
@@ -504,12 +482,6 @@ export function _getDataUrl(
|
|
|
504
482
|
path?: string,
|
|
505
483
|
): string {
|
|
506
484
|
const config = client.config()
|
|
507
|
-
|
|
508
|
-
if (config.experimental_resource) {
|
|
509
|
-
const baseUri = `/${operation}`
|
|
510
|
-
const uri = path ? `${baseUri}/${path}` : baseUri
|
|
511
|
-
return uri.replace(/\/($|\?)/, '$1')
|
|
512
|
-
}
|
|
513
485
|
const catalog = validators.hasDataset(config)
|
|
514
486
|
const baseUri = `/${operation}/${catalog}`
|
|
515
487
|
const uri = path ? `${baseUri}/${path}` : baseUri
|
|
@@ -524,15 +496,8 @@ export function _getUrl(
|
|
|
524
496
|
uri: string,
|
|
525
497
|
canUseCdn = false,
|
|
526
498
|
): string {
|
|
527
|
-
const {url, cdnUrl
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
if (experimental_resource) {
|
|
531
|
-
if (uri.indexOf('/users') !== -1 || uri.indexOf('/assets') !== -1) {
|
|
532
|
-
base = base.replace(_resourceBase(experimental_resource), '')
|
|
533
|
-
}
|
|
534
|
-
}
|
|
535
|
-
|
|
499
|
+
const {url, cdnUrl} = client.config()
|
|
500
|
+
const base = canUseCdn ? cdnUrl : url
|
|
536
501
|
return `${base}/${uri.replace(/^\//, '')}`
|
|
537
502
|
}
|
|
538
503
|
|
|
@@ -106,28 +106,6 @@ export class DatasetsClient {
|
|
|
106
106
|
}
|
|
107
107
|
}
|
|
108
108
|
|
|
109
|
-
export class ThrowingDatasetsClient extends DatasetsClient {
|
|
110
|
-
constructor(client: SanityClient, httpRequest: HttpRequest) {
|
|
111
|
-
super(client, httpRequest)
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
create(): Promise<DatasetResponse> {
|
|
115
|
-
throw new Error('cannot create dataset with the current client configuration')
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
edit(): Promise<DatasetResponse> {
|
|
119
|
-
throw new Error('cannot edit dataset with the current client configuration')
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
delete(): Promise<{deleted: true}> {
|
|
123
|
-
throw new Error('cannot delete dataset with the current client configuration')
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
list(): Promise<DatasetsResponse> {
|
|
127
|
-
throw new Error('cannot list dataset with the current client configuration')
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
|
|
131
109
|
function _modify<R = unknown>(
|
|
132
110
|
client: SanityClient | ObservableSanityClient,
|
|
133
111
|
httpRequest: HttpRequest,
|
package/src/index.ts
CHANGED
|
@@ -9,7 +9,11 @@ const exp = defineCreateClientExports<SanityClient, ClientConfig>(envMiddleware,
|
|
|
9
9
|
/** @public */
|
|
10
10
|
export const requester = exp.requester
|
|
11
11
|
|
|
12
|
-
/**
|
|
12
|
+
/**
|
|
13
|
+
* @remarks
|
|
14
|
+
* As of API version `v2025-02-19`, the default perspective used by the client has changed from `raw` to `published`. {@link https://www.sanity.io/changelog/e93a2d5a-9cee-4801-829e-8d3394bfed85|Changelog}
|
|
15
|
+
* @public
|
|
16
|
+
*/
|
|
13
17
|
export const createClient = exp.createClient
|
|
14
18
|
|
|
15
19
|
/**
|
package/src/types.ts
CHANGED
|
@@ -60,9 +60,20 @@ export interface ClientConfig {
|
|
|
60
60
|
/** @defaultValue true */
|
|
61
61
|
useCdn?: boolean
|
|
62
62
|
token?: string
|
|
63
|
-
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* What perspective to use for the client. See {@link https://www.sanity.io/docs/perspectives|perspective documentation}
|
|
66
|
+
* @remarks
|
|
67
|
+
* As of API version `v2025-02-19`, the default perspective has changed from `raw` to `published`. {@link https://www.sanity.io/changelog/e93a2d5a-9cee-4801-829e-8d3394bfed85|Changelog}
|
|
68
|
+
* @defaultValue 'published'
|
|
69
|
+
*/
|
|
64
70
|
perspective?: ClientPerspective
|
|
65
71
|
apiHost?: string
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
@remarks
|
|
75
|
+
* As of API version `v2025-02-19`, the default perspective has changed from `raw` to `published`. {@link https://www.sanity.io/changelog/e93a2d5a-9cee-4801-829e-8d3394bfed85|Changelog}
|
|
76
|
+
*/
|
|
66
77
|
apiVersion?: string
|
|
67
78
|
proxy?: string
|
|
68
79
|
|
|
@@ -115,14 +126,6 @@ export interface ClientConfig {
|
|
|
115
126
|
* Options for how, if enabled, Content Source Maps are encoded into query results using steganography
|
|
116
127
|
*/
|
|
117
128
|
stega?: StegaConfig | boolean
|
|
118
|
-
|
|
119
|
-
/**
|
|
120
|
-
* @deprecated Don't use
|
|
121
|
-
*/
|
|
122
|
-
experimental_resource?: {
|
|
123
|
-
id: string
|
|
124
|
-
type: string
|
|
125
|
-
}
|
|
126
129
|
}
|
|
127
130
|
|
|
128
131
|
/** @public */
|
|
@@ -940,7 +943,12 @@ export interface ListenOptions {
|
|
|
940
943
|
includePreviousRevision?: boolean
|
|
941
944
|
|
|
942
945
|
/**
|
|
943
|
-
*
|
|
946
|
+
* Whether to include events for drafts and versions. As of API Version >= v2025-02-19, only events
|
|
947
|
+
* for published documents will be included by default (see {@link https://www.sanity.io/changelog/e93a2d5a-9cee-4801-829e-8d3394bfed85|Changelog})
|
|
948
|
+
* If you need events from drafts and versions, set this to `true`.
|
|
949
|
+
* Note: Keep in mind that additional document variants may be introduced in the future, so it's
|
|
950
|
+
* recommended to respond to events in a way that's tolerant of potential future variants, e.g. by
|
|
951
|
+
* explicitly checking whether the event is for a draft or a version.
|
|
944
952
|
* @defaultValue `false`
|
|
945
953
|
*/
|
|
946
954
|
includeAllVersions?: boolean
|
package/umd/sanityClient.js
CHANGED
|
@@ -2133,17 +2133,7 @@
|
|
|
2133
2133
|
const newConfig = {
|
|
2134
2134
|
...defaultConfig,
|
|
2135
2135
|
...specifiedConfig
|
|
2136
|
-
},
|
|
2137
|
-
if (projectId$1?.startsWith("resource.")) {
|
|
2138
|
-
const [, resourceType, resourceId] = projectId$1.split(".");
|
|
2139
|
-
resourceType && resourceId && (newConfig.experimental_resource = {
|
|
2140
|
-
type: resourceType,
|
|
2141
|
-
id: resourceId
|
|
2142
|
-
});
|
|
2143
|
-
}
|
|
2144
|
-
const experimentalResource = newConfig.experimental_resource;
|
|
2145
|
-
experimentalResource && (newConfig.useProjectHostname = false);
|
|
2146
|
-
const projectBased = newConfig.useProjectHostname;
|
|
2136
|
+
}, projectBased = newConfig.useProjectHostname;
|
|
2147
2137
|
if (typeof Promise > "u") {
|
|
2148
2138
|
const helpUrl = generateHelpUrl("js-client-promise-polyfill");
|
|
2149
2139
|
throw new Error(`No native Promise-implementation found, polyfill needed - see ${helpUrl}`);
|
|
@@ -2169,11 +2159,7 @@
|
|
|
2169
2159
|
const isBrowser = typeof window < "u" && window.location && window.location.hostname, isLocalhost = isBrowser && isLocal(window.location.hostname);
|
|
2170
2160
|
isBrowser && isLocalhost && newConfig.token && newConfig.ignoreBrowserTokenWarning !== true ? 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 === true && newConfig.withCredentials && printCdnAndWithCredentialsWarning(), newConfig.useCdn = newConfig.useCdn !== false && !newConfig.withCredentials, validateApiVersion(newConfig.apiVersion);
|
|
2171
2161
|
const hostParts = newConfig.apiHost.split("://", 2), protocol = hostParts[0], host = hostParts[1], cdnHost = newConfig.isDefaultApi ? defaultCdnHost : host;
|
|
2172
|
-
|
|
2173
|
-
const resourceSuffix = `${experimentalResource.type}/${experimentalResource.id}`;
|
|
2174
|
-
newConfig.url = `${newConfig.url}/${resourceSuffix}`, newConfig.cdnUrl = `${newConfig.cdnUrl}/${resourceSuffix}`;
|
|
2175
|
-
}
|
|
2176
|
-
return newConfig;
|
|
2162
|
+
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;
|
|
2177
2163
|
};
|
|
2178
2164
|
class ConnectionFailedError extends Error {
|
|
2179
2165
|
name = "ConnectionFailedError";
|
|
@@ -2784,20 +2770,11 @@ ${selectionOpts}`);
|
|
|
2784
2770
|
const mutation = { [op]: doc }, opts = Object.assign({ returnFirst: true, returnDocuments: true }, options);
|
|
2785
2771
|
return _dataRequest(client, httpRequest, "mutate", { mutations: [mutation] }, opts);
|
|
2786
2772
|
}
|
|
2787
|
-
function _resourceBase(resource) {
|
|
2788
|
-
return `/${resource.type}/${resource.id}`;
|
|
2789
|
-
}
|
|
2790
|
-
function isDataRequestUri(uri, resource) {
|
|
2791
|
-
return resource ? uri.indexOf(`/${_resourceBase(resource)}/data/`) === 0 : uri.indexOf("/data/") === 0;
|
|
2792
|
-
}
|
|
2793
|
-
function isDataQueryRequestUri(uri, resource) {
|
|
2794
|
-
return resource ? uri.indexOf(`/${_resourceBase(resource)}/data/query`) === 0 : uri.indexOf("/data/query") === 0;
|
|
2795
|
-
}
|
|
2796
2773
|
function _requestObservable(client, httpRequest, options) {
|
|
2797
|
-
const uri = options.url || options.uri, config = client.config(), canUseCdn = typeof options.canUseCdn > "u" ? ["GET", "HEAD"].indexOf(options.method || "GET") >= 0 &&
|
|
2774
|
+
const uri = options.url || options.uri, config = client.config(), canUseCdn = typeof options.canUseCdn > "u" ? ["GET", "HEAD"].indexOf(options.method || "GET") >= 0 && uri.indexOf("/data/") === 0 : options.canUseCdn;
|
|
2798
2775
|
let useCdn = (options.useCdn ?? config.useCdn) && canUseCdn;
|
|
2799
2776
|
const tag = options.tag && config.requestTagPrefix ? [config.requestTagPrefix, options.tag].join(".") : options.tag || config.requestTagPrefix;
|
|
2800
|
-
if (tag && options.tag !== null && (options.query = { tag: requestTag(tag), ...options.query }), ["GET", "HEAD", "POST"].indexOf(options.method || "GET") >= 0 &&
|
|
2777
|
+
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) {
|
|
2801
2778
|
const resultSourceMap = options.resultSourceMap ?? config.resultSourceMap;
|
|
2802
2779
|
resultSourceMap !== void 0 && resultSourceMap !== false && (options.query = { resultSourceMap, ...options.query });
|
|
2803
2780
|
const perspectiveOption = options.perspective || config.perspective;
|
|
@@ -2824,18 +2801,12 @@ ${selectionOpts}`);
|
|
|
2824
2801
|
);
|
|
2825
2802
|
}
|
|
2826
2803
|
function _getDataUrl(client, operation, path) {
|
|
2827
|
-
const config = client.config()
|
|
2828
|
-
if (config.experimental_resource) {
|
|
2829
|
-
const baseUri2 = `/${operation}`;
|
|
2830
|
-
return (path ? `${baseUri2}/${path}` : baseUri2).replace(/\/($|\?)/, "$1");
|
|
2831
|
-
}
|
|
2832
|
-
const catalog = hasDataset(config), baseUri = `/${operation}/${catalog}`;
|
|
2804
|
+
const config = client.config(), catalog = hasDataset(config), baseUri = `/${operation}/${catalog}`;
|
|
2833
2805
|
return `/data${path ? `${baseUri}/${path}` : baseUri}`.replace(/\/($|\?)/, "$1");
|
|
2834
2806
|
}
|
|
2835
2807
|
function _getUrl(client, uri, canUseCdn = false) {
|
|
2836
|
-
const { url, cdnUrl
|
|
2837
|
-
|
|
2838
|
-
return experimental_resource && (uri.indexOf("/users") !== -1 || uri.indexOf("/assets") !== -1) && (base = base.replace(_resourceBase(experimental_resource), "")), `${base}/${uri.replace(/^\//, "")}`;
|
|
2808
|
+
const { url, cdnUrl } = client.config();
|
|
2809
|
+
return `${canUseCdn ? cdnUrl : url}/${uri.replace(/^\//, "")}`;
|
|
2839
2810
|
}
|
|
2840
2811
|
function _withAbortSignal(signal) {
|
|
2841
2812
|
return (input) => new Observable((observer) => {
|
|
@@ -2889,7 +2860,7 @@ ${selectionOpts}`);
|
|
|
2889
2860
|
validateAssetType(assetType);
|
|
2890
2861
|
let meta = opts.extract || void 0;
|
|
2891
2862
|
meta && !meta.length && (meta = ["none"]);
|
|
2892
|
-
const
|
|
2863
|
+
const dataset2 = hasDataset(client.config()), assetEndpoint = assetType === "image" ? "images" : "files", options = optionsFromFile(opts, body), { tag, label, title, description, creditLine, filename, source } = options, query = {
|
|
2893
2864
|
label,
|
|
2894
2865
|
title,
|
|
2895
2866
|
description,
|
|
@@ -2901,7 +2872,7 @@ ${selectionOpts}`);
|
|
|
2901
2872
|
tag,
|
|
2902
2873
|
method: "POST",
|
|
2903
2874
|
timeout: options.timeout || 0,
|
|
2904
|
-
uri:
|
|
2875
|
+
uri: `/assets/${assetEndpoint}/${dataset2}`,
|
|
2905
2876
|
headers: options.contentType ? { "Content-Type": options.contentType } : {},
|
|
2906
2877
|
query,
|
|
2907
2878
|
body
|
|
@@ -3156,23 +3127,6 @@ ${selectionOpts}`);
|
|
|
3156
3127
|
);
|
|
3157
3128
|
}
|
|
3158
3129
|
}
|
|
3159
|
-
class ThrowingDatasetsClient extends DatasetsClient {
|
|
3160
|
-
constructor(client, httpRequest) {
|
|
3161
|
-
super(client, httpRequest);
|
|
3162
|
-
}
|
|
3163
|
-
create() {
|
|
3164
|
-
throw new Error("cannot create dataset with the current client configuration");
|
|
3165
|
-
}
|
|
3166
|
-
edit() {
|
|
3167
|
-
throw new Error("cannot edit dataset with the current client configuration");
|
|
3168
|
-
}
|
|
3169
|
-
delete() {
|
|
3170
|
-
throw new Error("cannot delete dataset with the current client configuration");
|
|
3171
|
-
}
|
|
3172
|
-
list() {
|
|
3173
|
-
throw new Error("cannot list dataset with the current client configuration");
|
|
3174
|
-
}
|
|
3175
|
-
}
|
|
3176
3130
|
function _modify(client, httpRequest, method, name, options) {
|
|
3177
3131
|
return dataset(name), _request(client, httpRequest, {
|
|
3178
3132
|
method,
|
|
@@ -3428,7 +3382,7 @@ ${selectionOpts}`);
|
|
|
3428
3382
|
*/
|
|
3429
3383
|
listen = _listen;
|
|
3430
3384
|
constructor(httpRequest, config = defaultConfig) {
|
|
3431
|
-
this.config(config), this.#httpRequest = httpRequest, this.assets = new AssetsClient(this, this.#httpRequest), this.datasets =
|
|
3385
|
+
this.config(config), this.#httpRequest = httpRequest, this.assets = new AssetsClient(this, this.#httpRequest), this.datasets = new DatasetsClient(this, this.#httpRequest), this.live = new LiveClient(this), this.projects = new ProjectsClient(this, this.#httpRequest), this.users = new UsersClient(this, this.#httpRequest), this.observable = new ObservableSanityClient(httpRequest, config);
|
|
3432
3386
|
}
|
|
3433
3387
|
/**
|
|
3434
3388
|
* Clone the client - returns a new instance
|