@sanity/client 7.11.2-audience-decide.8 → 7.12.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 +12 -108
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.d.cts +4 -14
- package/dist/index.browser.d.ts +4 -14
- package/dist/index.browser.js +12 -108
- package/dist/index.browser.js.map +1 -1
- package/dist/index.cjs +22 -109
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -14
- package/dist/index.d.ts +4 -14
- package/dist/index.js +22 -109
- package/dist/index.js.map +1 -1
- package/dist/stega.browser.d.cts +4 -14
- package/dist/stega.browser.d.ts +4 -14
- package/dist/stega.d.cts +4 -14
- package/dist/stega.d.ts +4 -14
- package/package.json +1 -1
- package/src/SanityClient.ts +0 -26
- package/src/data/dataMethods.ts +9 -37
- package/src/defineCreateClient.ts +1 -0
- package/src/http/nodeMiddleware.ts +18 -1
- package/src/http/request.ts +5 -1
- package/src/types.ts +4 -16
- package/umd/sanityClient.js +12 -108
- package/umd/sanityClient.min.js +2 -2
- package/src/data/decideResponseProcessor.ts +0 -185
package/dist/stega.browser.d.cts
CHANGED
|
@@ -699,10 +699,6 @@ export declare interface ClientConfig {
|
|
|
699
699
|
* @defaultValue 'published'
|
|
700
700
|
*/
|
|
701
701
|
perspective?: ClientPerspective
|
|
702
|
-
/**
|
|
703
|
-
* Parameters to pass to Sanity Decide for personalisation
|
|
704
|
-
*/
|
|
705
|
-
decideParameters?: DecideParameters
|
|
706
702
|
apiHost?: string
|
|
707
703
|
/**
|
|
708
704
|
@remarks
|
|
@@ -784,6 +780,10 @@ export declare interface ClientConfig {
|
|
|
784
780
|
* Options for how, if enabled, Content Source Maps are encoded into query results using steganography
|
|
785
781
|
*/
|
|
786
782
|
stega?: StegaConfig | boolean
|
|
783
|
+
/**
|
|
784
|
+
* Lineage token for recursion control
|
|
785
|
+
*/
|
|
786
|
+
lineage?: string
|
|
787
787
|
}
|
|
788
788
|
|
|
789
789
|
declare type ClientConfigResource =
|
|
@@ -1230,12 +1230,6 @@ export declare type DatasetsResponse = {
|
|
|
1230
1230
|
tags: string[]
|
|
1231
1231
|
}[]
|
|
1232
1232
|
|
|
1233
|
-
/** @public */
|
|
1234
|
-
export declare interface DecideParameters {
|
|
1235
|
-
audience: string | string[]
|
|
1236
|
-
[key: string]: unknown
|
|
1237
|
-
}
|
|
1238
|
-
|
|
1239
1233
|
/**
|
|
1240
1234
|
* Deletes the published version of a document and optionally some (likely all known) draft versions.
|
|
1241
1235
|
* If any draft version exists that is not specified for deletion this is an error.
|
|
@@ -4321,8 +4315,6 @@ export declare interface QueryParams {
|
|
|
4321
4315
|
/** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
|
|
4322
4316
|
cache?: 'next' extends keyof RequestInit ? never : any
|
|
4323
4317
|
/** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
|
|
4324
|
-
decideParameters?: never
|
|
4325
|
-
/** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
|
|
4326
4318
|
filterResponse?: never
|
|
4327
4319
|
/** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
|
|
4328
4320
|
headers?: never
|
|
@@ -4835,7 +4827,6 @@ export declare interface RequestObservableOptions extends Omit<RequestOptions, '
|
|
|
4835
4827
|
returnQuery?: boolean
|
|
4836
4828
|
resultSourceMap?: boolean | 'withKeyArraySelector'
|
|
4837
4829
|
perspective?: ClientPerspective
|
|
4838
|
-
decideParameters?: DecideParameters
|
|
4839
4830
|
lastLiveEventId?: string
|
|
4840
4831
|
cacheMode?: 'noStale'
|
|
4841
4832
|
}
|
|
@@ -4871,7 +4862,6 @@ export declare interface ResponseEvent<T = unknown> {
|
|
|
4871
4862
|
/** @public */
|
|
4872
4863
|
export declare interface ResponseQueryOptions extends RequestOptions {
|
|
4873
4864
|
perspective?: ClientPerspective
|
|
4874
|
-
decideParameters?: DecideParameters
|
|
4875
4865
|
resultSourceMap?: boolean | 'withKeyArraySelector'
|
|
4876
4866
|
returnQuery?: boolean
|
|
4877
4867
|
useCdn?: boolean
|
package/dist/stega.browser.d.ts
CHANGED
|
@@ -699,10 +699,6 @@ export declare interface ClientConfig {
|
|
|
699
699
|
* @defaultValue 'published'
|
|
700
700
|
*/
|
|
701
701
|
perspective?: ClientPerspective
|
|
702
|
-
/**
|
|
703
|
-
* Parameters to pass to Sanity Decide for personalisation
|
|
704
|
-
*/
|
|
705
|
-
decideParameters?: DecideParameters
|
|
706
702
|
apiHost?: string
|
|
707
703
|
/**
|
|
708
704
|
@remarks
|
|
@@ -784,6 +780,10 @@ export declare interface ClientConfig {
|
|
|
784
780
|
* Options for how, if enabled, Content Source Maps are encoded into query results using steganography
|
|
785
781
|
*/
|
|
786
782
|
stega?: StegaConfig | boolean
|
|
783
|
+
/**
|
|
784
|
+
* Lineage token for recursion control
|
|
785
|
+
*/
|
|
786
|
+
lineage?: string
|
|
787
787
|
}
|
|
788
788
|
|
|
789
789
|
declare type ClientConfigResource =
|
|
@@ -1230,12 +1230,6 @@ export declare type DatasetsResponse = {
|
|
|
1230
1230
|
tags: string[]
|
|
1231
1231
|
}[]
|
|
1232
1232
|
|
|
1233
|
-
/** @public */
|
|
1234
|
-
export declare interface DecideParameters {
|
|
1235
|
-
audience: string | string[]
|
|
1236
|
-
[key: string]: unknown
|
|
1237
|
-
}
|
|
1238
|
-
|
|
1239
1233
|
/**
|
|
1240
1234
|
* Deletes the published version of a document and optionally some (likely all known) draft versions.
|
|
1241
1235
|
* If any draft version exists that is not specified for deletion this is an error.
|
|
@@ -4321,8 +4315,6 @@ export declare interface QueryParams {
|
|
|
4321
4315
|
/** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
|
|
4322
4316
|
cache?: 'next' extends keyof RequestInit ? never : any
|
|
4323
4317
|
/** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
|
|
4324
|
-
decideParameters?: never
|
|
4325
|
-
/** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
|
|
4326
4318
|
filterResponse?: never
|
|
4327
4319
|
/** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
|
|
4328
4320
|
headers?: never
|
|
@@ -4835,7 +4827,6 @@ export declare interface RequestObservableOptions extends Omit<RequestOptions, '
|
|
|
4835
4827
|
returnQuery?: boolean
|
|
4836
4828
|
resultSourceMap?: boolean | 'withKeyArraySelector'
|
|
4837
4829
|
perspective?: ClientPerspective
|
|
4838
|
-
decideParameters?: DecideParameters
|
|
4839
4830
|
lastLiveEventId?: string
|
|
4840
4831
|
cacheMode?: 'noStale'
|
|
4841
4832
|
}
|
|
@@ -4871,7 +4862,6 @@ export declare interface ResponseEvent<T = unknown> {
|
|
|
4871
4862
|
/** @public */
|
|
4872
4863
|
export declare interface ResponseQueryOptions extends RequestOptions {
|
|
4873
4864
|
perspective?: ClientPerspective
|
|
4874
|
-
decideParameters?: DecideParameters
|
|
4875
4865
|
resultSourceMap?: boolean | 'withKeyArraySelector'
|
|
4876
4866
|
returnQuery?: boolean
|
|
4877
4867
|
useCdn?: boolean
|
package/dist/stega.d.cts
CHANGED
|
@@ -699,10 +699,6 @@ export declare interface ClientConfig {
|
|
|
699
699
|
* @defaultValue 'published'
|
|
700
700
|
*/
|
|
701
701
|
perspective?: ClientPerspective
|
|
702
|
-
/**
|
|
703
|
-
* Parameters to pass to Sanity Decide for personalisation
|
|
704
|
-
*/
|
|
705
|
-
decideParameters?: DecideParameters
|
|
706
702
|
apiHost?: string
|
|
707
703
|
/**
|
|
708
704
|
@remarks
|
|
@@ -784,6 +780,10 @@ export declare interface ClientConfig {
|
|
|
784
780
|
* Options for how, if enabled, Content Source Maps are encoded into query results using steganography
|
|
785
781
|
*/
|
|
786
782
|
stega?: StegaConfig | boolean
|
|
783
|
+
/**
|
|
784
|
+
* Lineage token for recursion control
|
|
785
|
+
*/
|
|
786
|
+
lineage?: string
|
|
787
787
|
}
|
|
788
788
|
|
|
789
789
|
declare type ClientConfigResource =
|
|
@@ -1230,12 +1230,6 @@ export declare type DatasetsResponse = {
|
|
|
1230
1230
|
tags: string[]
|
|
1231
1231
|
}[]
|
|
1232
1232
|
|
|
1233
|
-
/** @public */
|
|
1234
|
-
export declare interface DecideParameters {
|
|
1235
|
-
audience: string | string[]
|
|
1236
|
-
[key: string]: unknown
|
|
1237
|
-
}
|
|
1238
|
-
|
|
1239
1233
|
/**
|
|
1240
1234
|
* Deletes the published version of a document and optionally some (likely all known) draft versions.
|
|
1241
1235
|
* If any draft version exists that is not specified for deletion this is an error.
|
|
@@ -4321,8 +4315,6 @@ export declare interface QueryParams {
|
|
|
4321
4315
|
/** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
|
|
4322
4316
|
cache?: 'next' extends keyof RequestInit ? never : any
|
|
4323
4317
|
/** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
|
|
4324
|
-
decideParameters?: never
|
|
4325
|
-
/** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
|
|
4326
4318
|
filterResponse?: never
|
|
4327
4319
|
/** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
|
|
4328
4320
|
headers?: never
|
|
@@ -4835,7 +4827,6 @@ export declare interface RequestObservableOptions extends Omit<RequestOptions, '
|
|
|
4835
4827
|
returnQuery?: boolean
|
|
4836
4828
|
resultSourceMap?: boolean | 'withKeyArraySelector'
|
|
4837
4829
|
perspective?: ClientPerspective
|
|
4838
|
-
decideParameters?: DecideParameters
|
|
4839
4830
|
lastLiveEventId?: string
|
|
4840
4831
|
cacheMode?: 'noStale'
|
|
4841
4832
|
}
|
|
@@ -4871,7 +4862,6 @@ export declare interface ResponseEvent<T = unknown> {
|
|
|
4871
4862
|
/** @public */
|
|
4872
4863
|
export declare interface ResponseQueryOptions extends RequestOptions {
|
|
4873
4864
|
perspective?: ClientPerspective
|
|
4874
|
-
decideParameters?: DecideParameters
|
|
4875
4865
|
resultSourceMap?: boolean | 'withKeyArraySelector'
|
|
4876
4866
|
returnQuery?: boolean
|
|
4877
4867
|
useCdn?: boolean
|
package/dist/stega.d.ts
CHANGED
|
@@ -699,10 +699,6 @@ export declare interface ClientConfig {
|
|
|
699
699
|
* @defaultValue 'published'
|
|
700
700
|
*/
|
|
701
701
|
perspective?: ClientPerspective
|
|
702
|
-
/**
|
|
703
|
-
* Parameters to pass to Sanity Decide for personalisation
|
|
704
|
-
*/
|
|
705
|
-
decideParameters?: DecideParameters
|
|
706
702
|
apiHost?: string
|
|
707
703
|
/**
|
|
708
704
|
@remarks
|
|
@@ -784,6 +780,10 @@ export declare interface ClientConfig {
|
|
|
784
780
|
* Options for how, if enabled, Content Source Maps are encoded into query results using steganography
|
|
785
781
|
*/
|
|
786
782
|
stega?: StegaConfig | boolean
|
|
783
|
+
/**
|
|
784
|
+
* Lineage token for recursion control
|
|
785
|
+
*/
|
|
786
|
+
lineage?: string
|
|
787
787
|
}
|
|
788
788
|
|
|
789
789
|
declare type ClientConfigResource =
|
|
@@ -1230,12 +1230,6 @@ export declare type DatasetsResponse = {
|
|
|
1230
1230
|
tags: string[]
|
|
1231
1231
|
}[]
|
|
1232
1232
|
|
|
1233
|
-
/** @public */
|
|
1234
|
-
export declare interface DecideParameters {
|
|
1235
|
-
audience: string | string[]
|
|
1236
|
-
[key: string]: unknown
|
|
1237
|
-
}
|
|
1238
|
-
|
|
1239
1233
|
/**
|
|
1240
1234
|
* Deletes the published version of a document and optionally some (likely all known) draft versions.
|
|
1241
1235
|
* If any draft version exists that is not specified for deletion this is an error.
|
|
@@ -4321,8 +4315,6 @@ export declare interface QueryParams {
|
|
|
4321
4315
|
/** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
|
|
4322
4316
|
cache?: 'next' extends keyof RequestInit ? never : any
|
|
4323
4317
|
/** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
|
|
4324
|
-
decideParameters?: never
|
|
4325
|
-
/** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
|
|
4326
4318
|
filterResponse?: never
|
|
4327
4319
|
/** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
|
|
4328
4320
|
headers?: never
|
|
@@ -4835,7 +4827,6 @@ export declare interface RequestObservableOptions extends Omit<RequestOptions, '
|
|
|
4835
4827
|
returnQuery?: boolean
|
|
4836
4828
|
resultSourceMap?: boolean | 'withKeyArraySelector'
|
|
4837
4829
|
perspective?: ClientPerspective
|
|
4838
|
-
decideParameters?: DecideParameters
|
|
4839
4830
|
lastLiveEventId?: string
|
|
4840
4831
|
cacheMode?: 'noStale'
|
|
4841
4832
|
}
|
|
@@ -4871,7 +4862,6 @@ export declare interface ResponseEvent<T = unknown> {
|
|
|
4871
4862
|
/** @public */
|
|
4872
4863
|
export declare interface ResponseQueryOptions extends RequestOptions {
|
|
4873
4864
|
perspective?: ClientPerspective
|
|
4874
|
-
decideParameters?: DecideParameters
|
|
4875
4865
|
resultSourceMap?: boolean | 'withKeyArraySelector'
|
|
4876
4866
|
returnQuery?: boolean
|
|
4877
4867
|
useCdn?: boolean
|
package/package.json
CHANGED
package/src/SanityClient.ts
CHANGED
|
@@ -225,19 +225,6 @@ export class ObservableSanityClient {
|
|
|
225
225
|
params?: Q,
|
|
226
226
|
options?: QueryOptions,
|
|
227
227
|
): Observable<RawQueryResponse<R> | R> {
|
|
228
|
-
// Log the public API call to track parameter flow
|
|
229
|
-
// eslint-disable-next-line no-console
|
|
230
|
-
console.log('[client-8] ObservableSanityClient.fetch called with:', {
|
|
231
|
-
query: query.substring(0, 100) + (query.length > 100 ? '...' : ''),
|
|
232
|
-
params,
|
|
233
|
-
options: {
|
|
234
|
-
...options,
|
|
235
|
-
decideParameters: options?.decideParameters,
|
|
236
|
-
},
|
|
237
|
-
clientConfig: {
|
|
238
|
-
decideParameters: this.#clientConfig.decideParameters,
|
|
239
|
-
},
|
|
240
|
-
})
|
|
241
228
|
return dataMethods._fetch<R, Q>(
|
|
242
229
|
this,
|
|
243
230
|
this.#httpRequest,
|
|
@@ -1285,19 +1272,6 @@ export class SanityClient {
|
|
|
1285
1272
|
params?: Q,
|
|
1286
1273
|
options?: QueryOptions,
|
|
1287
1274
|
): Promise<RawQueryResponse<ClientReturn<G, R>> | ClientReturn<G, R>> {
|
|
1288
|
-
// Log the public API call to track parameter flow
|
|
1289
|
-
// eslint-disable-next-line no-console
|
|
1290
|
-
console.log('[client-8] SanityClient.fetch called with:', {
|
|
1291
|
-
query: query.substring(0, 100) + (query.length > 100 ? '...' : ''),
|
|
1292
|
-
params,
|
|
1293
|
-
options: {
|
|
1294
|
-
...options,
|
|
1295
|
-
decideParameters: options?.decideParameters,
|
|
1296
|
-
},
|
|
1297
|
-
clientConfig: {
|
|
1298
|
-
decideParameters: this.#clientConfig.decideParameters,
|
|
1299
|
-
},
|
|
1300
|
-
})
|
|
1301
1275
|
return lastValueFrom(
|
|
1302
1276
|
dataMethods._fetch<ClientReturn<G, R>, Q>(
|
|
1303
1277
|
this,
|
package/src/data/dataMethods.ts
CHANGED
|
@@ -44,7 +44,6 @@ import {
|
|
|
44
44
|
printCreateVersionWithBaseIdWarning,
|
|
45
45
|
printPreviewDraftsDeprecationWarning,
|
|
46
46
|
} from '../warnings'
|
|
47
|
-
import {processDecideFields} from './decideResponseProcessor'
|
|
48
47
|
import {encodeQueryString} from './encodeQueryString'
|
|
49
48
|
import {ObservablePatch, Patch} from './patch'
|
|
50
49
|
import {ObservableTransaction, Transaction} from './transaction'
|
|
@@ -98,12 +97,6 @@ export function _fetch<R, Q>(
|
|
|
98
97
|
const mapResponse =
|
|
99
98
|
options.filterResponse === false ? (res: Any) => res : (res: Any) => res.result
|
|
100
99
|
|
|
101
|
-
// Helper function to apply decide processing to response data
|
|
102
|
-
const processDecideResponse = (response: Any): Any => {
|
|
103
|
-
const processedData = processDecideFields(response, options.decideParameters)
|
|
104
|
-
return processedData
|
|
105
|
-
}
|
|
106
|
-
|
|
107
100
|
const {cache, next, ...opts} = {
|
|
108
101
|
// Opt out of setting a `signal` on an internal `fetch` if one isn't provided.
|
|
109
102
|
// This is necessary in React Server Components to avoid opting out of Request Memoization.
|
|
@@ -121,7 +114,6 @@ export function _fetch<R, Q>(
|
|
|
121
114
|
: opts
|
|
122
115
|
|
|
123
116
|
const $request = _dataRequest(client, httpRequest, 'query', {query, params}, reqOpts)
|
|
124
|
-
|
|
125
117
|
return stega.enabled
|
|
126
118
|
? $request.pipe(
|
|
127
119
|
combineLatestWith(
|
|
@@ -136,20 +128,12 @@ export function _fetch<R, Q>(
|
|
|
136
128
|
Any,
|
|
137
129
|
(typeof import('../stega/stegaEncodeSourceMap'))['stegaEncodeSourceMap'],
|
|
138
130
|
]) => {
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
const result = stegaEncodeSourceMap(processedResult, res.resultSourceMap, stega)
|
|
142
|
-
const mappedResponse = mapResponse({...res, result})
|
|
143
|
-
return mappedResponse
|
|
131
|
+
const result = stegaEncodeSourceMap(res.result, res.resultSourceMap, stega)
|
|
132
|
+
return mapResponse({...res, result})
|
|
144
133
|
},
|
|
145
134
|
),
|
|
146
135
|
)
|
|
147
|
-
: $request.pipe(
|
|
148
|
-
map((res) => {
|
|
149
|
-
const mappedResponse = mapResponse(res)
|
|
150
|
-
return processDecideResponse(mappedResponse)
|
|
151
|
-
}),
|
|
152
|
-
)
|
|
136
|
+
: $request.pipe(map(mapResponse))
|
|
153
137
|
}
|
|
154
138
|
|
|
155
139
|
/** @internal */
|
|
@@ -520,7 +504,6 @@ export function _dataRequest(
|
|
|
520
504
|
tag,
|
|
521
505
|
returnQuery,
|
|
522
506
|
perspective: options.perspective,
|
|
523
|
-
decideParameters: options.decideParameters,
|
|
524
507
|
resultSourceMap: options.resultSourceMap,
|
|
525
508
|
lastLiveEventId: Array.isArray(lastLiveEventId) ? lastLiveEventId[0] : lastLiveEventId,
|
|
526
509
|
cacheMode: cacheMode,
|
|
@@ -531,7 +514,6 @@ export function _dataRequest(
|
|
|
531
514
|
useCdn: options.useCdn,
|
|
532
515
|
}
|
|
533
516
|
|
|
534
|
-
|
|
535
517
|
return _requestObservable(client, httpRequest, reqOptions).pipe(
|
|
536
518
|
filter(isResponse),
|
|
537
519
|
map(getBody),
|
|
@@ -615,7 +597,6 @@ export function _requestObservable<R>(
|
|
|
615
597
|
const uri = options.url || (options.uri as string)
|
|
616
598
|
const config = client.config()
|
|
617
599
|
|
|
618
|
-
|
|
619
600
|
// If the `canUseCdn`-option is not set we detect it automatically based on the method + URL.
|
|
620
601
|
// Only the /data endpoint is currently available through API-CDN.
|
|
621
602
|
const canUseCdn =
|
|
@@ -665,14 +646,6 @@ export function _requestObservable<R>(
|
|
|
665
646
|
}
|
|
666
647
|
}
|
|
667
648
|
|
|
668
|
-
// Process decideParameters - keep them available for response processing but don't send to HTTP
|
|
669
|
-
const decideParametersOption = options.decideParameters || config.decideParameters
|
|
670
|
-
|
|
671
|
-
if (decideParametersOption && typeof decideParametersOption === 'object') {
|
|
672
|
-
// Note: We intentionally do NOT add decideParameters to the query string
|
|
673
|
-
// They should only be used for response formatting, not sent as HTTP query params
|
|
674
|
-
}
|
|
675
|
-
|
|
676
649
|
if (options.lastLiveEventId) {
|
|
677
650
|
options.query = {...options.query, lastLiveEventId: options.lastLiveEventId}
|
|
678
651
|
}
|
|
@@ -686,13 +659,12 @@ export function _requestObservable<R>(
|
|
|
686
659
|
}
|
|
687
660
|
}
|
|
688
661
|
|
|
689
|
-
const
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
662
|
+
const reqOptions = requestOptions(
|
|
663
|
+
config,
|
|
664
|
+
Object.assign({}, options, {
|
|
665
|
+
url: _getUrl(client, uri, useCdn),
|
|
666
|
+
}),
|
|
667
|
+
) as RequestOptions
|
|
696
668
|
|
|
697
669
|
const request = new Observable<HttpRequestEvent<R>>((subscriber) =>
|
|
698
670
|
httpRequest(reqOptions, config.requester!).subscribe(subscriber),
|
|
@@ -1,11 +1,28 @@
|
|
|
1
|
+
import type {Middleware, RequestOptions} from 'get-it'
|
|
1
2
|
import {agent, debug, headers} from 'get-it/middleware'
|
|
2
3
|
|
|
3
4
|
import {name, version} from '../../package.json'
|
|
4
5
|
|
|
5
|
-
const middleware = [
|
|
6
|
+
const middleware: Middleware[] = [
|
|
6
7
|
debug({verbose: true, namespace: 'sanity:client'}),
|
|
7
8
|
headers({'User-Agent': `${name} ${version}`}),
|
|
8
9
|
|
|
10
|
+
// Lineage is used for recursion control/tracing and can be passed either through
|
|
11
|
+
// client constructor or through environent variable.
|
|
12
|
+
// Not used in browser environments.
|
|
13
|
+
{
|
|
14
|
+
processOptions(opts: RequestOptions & {lineage?: string}) {
|
|
15
|
+
const lineage =
|
|
16
|
+
(typeof process !== 'undefined' && process.env.X_SANITY_LINEAGE) || opts.lineage
|
|
17
|
+
|
|
18
|
+
if (lineage) {
|
|
19
|
+
opts.headers = opts.headers || {}
|
|
20
|
+
opts.headers['x-sanity-lineage'] = lineage
|
|
21
|
+
}
|
|
22
|
+
return opts
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
|
|
9
26
|
// Enable keep-alive, and in addition limit the number of sockets that can be opened.
|
|
10
27
|
// This avoids opening too many connections to the server if someone tries to execute
|
|
11
28
|
// a bunch of requests in parallel. It's recommended to have a concurrency limit
|
package/src/http/request.ts
CHANGED
|
@@ -58,10 +58,14 @@ function printWarnings(config: {ignoreWarnings?: string | RegExp | Array<string
|
|
|
58
58
|
}
|
|
59
59
|
}
|
|
60
60
|
|
|
61
|
+
type HttpRequestConfig = {
|
|
62
|
+
ignoreWarnings?: string | RegExp | Array<string | RegExp>
|
|
63
|
+
}
|
|
64
|
+
|
|
61
65
|
/** @internal */
|
|
62
66
|
export function defineHttpRequest(
|
|
63
67
|
envMiddleware: Middlewares,
|
|
64
|
-
config:
|
|
68
|
+
config: HttpRequestConfig = {},
|
|
65
69
|
): Requester {
|
|
66
70
|
return getIt([
|
|
67
71
|
retry({shouldRetry}),
|
package/src/types.ts
CHANGED
|
@@ -53,12 +53,6 @@ export type ClientPerspective =
|
|
|
53
53
|
| 'raw'
|
|
54
54
|
| StackablePerspective[]
|
|
55
55
|
|
|
56
|
-
/** @public */
|
|
57
|
-
export interface DecideParameters {
|
|
58
|
-
audience: string | string[]
|
|
59
|
-
[key: string]: unknown
|
|
60
|
-
}
|
|
61
|
-
|
|
62
56
|
type ClientConfigResource =
|
|
63
57
|
| {
|
|
64
58
|
type: 'canvas'
|
|
@@ -95,12 +89,6 @@ export interface ClientConfig {
|
|
|
95
89
|
* @defaultValue 'published'
|
|
96
90
|
*/
|
|
97
91
|
perspective?: ClientPerspective
|
|
98
|
-
|
|
99
|
-
/**
|
|
100
|
-
* Parameters to pass to Sanity Decide for personalisation
|
|
101
|
-
*/
|
|
102
|
-
decideParameters?: DecideParameters
|
|
103
|
-
|
|
104
92
|
apiHost?: string
|
|
105
93
|
|
|
106
94
|
/**
|
|
@@ -191,6 +179,10 @@ export interface ClientConfig {
|
|
|
191
179
|
* Options for how, if enabled, Content Source Maps are encoded into query results using steganography
|
|
192
180
|
*/
|
|
193
181
|
stega?: StegaConfig | boolean
|
|
182
|
+
/**
|
|
183
|
+
* Lineage token for recursion control
|
|
184
|
+
*/
|
|
185
|
+
lineage?: string
|
|
194
186
|
}
|
|
195
187
|
|
|
196
188
|
/** @public */
|
|
@@ -408,7 +400,6 @@ export interface RequestObservableOptions extends Omit<RequestOptions, 'url'> {
|
|
|
408
400
|
returnQuery?: boolean
|
|
409
401
|
resultSourceMap?: boolean | 'withKeyArraySelector'
|
|
410
402
|
perspective?: ClientPerspective
|
|
411
|
-
decideParameters?: DecideParameters
|
|
412
403
|
lastLiveEventId?: string
|
|
413
404
|
cacheMode?: 'noStale'
|
|
414
405
|
}
|
|
@@ -566,8 +557,6 @@ export interface QueryParams {
|
|
|
566
557
|
/** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
|
|
567
558
|
cache?: 'next' extends keyof RequestInit ? never : any
|
|
568
559
|
/** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
|
|
569
|
-
decideParameters?: never
|
|
570
|
-
/** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
|
|
571
560
|
filterResponse?: never
|
|
572
561
|
/** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
|
|
573
562
|
headers?: never
|
|
@@ -1246,7 +1235,6 @@ export interface ListenOptions {
|
|
|
1246
1235
|
/** @public */
|
|
1247
1236
|
export interface ResponseQueryOptions extends RequestOptions {
|
|
1248
1237
|
perspective?: ClientPerspective
|
|
1249
|
-
decideParameters?: DecideParameters
|
|
1250
1238
|
resultSourceMap?: boolean | 'withKeyArraySelector'
|
|
1251
1239
|
returnQuery?: boolean
|
|
1252
1240
|
useCdn?: boolean
|