@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/index.d.cts
CHANGED
|
@@ -706,10 +706,6 @@ export declare interface ClientConfig {
|
|
|
706
706
|
* @defaultValue 'published'
|
|
707
707
|
*/
|
|
708
708
|
perspective?: ClientPerspective
|
|
709
|
-
/**
|
|
710
|
-
* Parameters to pass to Sanity Decide for personalisation
|
|
711
|
-
*/
|
|
712
|
-
decideParameters?: DecideParameters
|
|
713
709
|
apiHost?: string
|
|
714
710
|
/**
|
|
715
711
|
@remarks
|
|
@@ -791,6 +787,10 @@ export declare interface ClientConfig {
|
|
|
791
787
|
* Options for how, if enabled, Content Source Maps are encoded into query results using steganography
|
|
792
788
|
*/
|
|
793
789
|
stega?: StegaConfig | boolean
|
|
790
|
+
/**
|
|
791
|
+
* Lineage token for recursion control
|
|
792
|
+
*/
|
|
793
|
+
lineage?: string
|
|
794
794
|
}
|
|
795
795
|
|
|
796
796
|
declare type ClientConfigResource =
|
|
@@ -1136,12 +1136,6 @@ export declare type DatasetsResponse = {
|
|
|
1136
1136
|
tags: string[]
|
|
1137
1137
|
}[]
|
|
1138
1138
|
|
|
1139
|
-
/** @public */
|
|
1140
|
-
export declare interface DecideParameters {
|
|
1141
|
-
audience: string | string[]
|
|
1142
|
-
[key: string]: unknown
|
|
1143
|
-
}
|
|
1144
|
-
|
|
1145
1139
|
/**
|
|
1146
1140
|
* Deletes the published version of a document and optionally some (likely all known) draft versions.
|
|
1147
1141
|
* If any draft version exists that is not specified for deletion this is an error.
|
|
@@ -4143,8 +4137,6 @@ export declare interface QueryParams {
|
|
|
4143
4137
|
/** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
|
|
4144
4138
|
cache?: 'next' extends keyof RequestInit ? never : any
|
|
4145
4139
|
/** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
|
|
4146
|
-
decideParameters?: never
|
|
4147
|
-
/** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
|
|
4148
4140
|
filterResponse?: never
|
|
4149
4141
|
/** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
|
|
4150
4142
|
headers?: never
|
|
@@ -4654,7 +4646,6 @@ export declare interface RequestObservableOptions extends Omit<RequestOptions, '
|
|
|
4654
4646
|
returnQuery?: boolean
|
|
4655
4647
|
resultSourceMap?: boolean | 'withKeyArraySelector'
|
|
4656
4648
|
perspective?: ClientPerspective
|
|
4657
|
-
decideParameters?: DecideParameters
|
|
4658
4649
|
lastLiveEventId?: string
|
|
4659
4650
|
cacheMode?: 'noStale'
|
|
4660
4651
|
}
|
|
@@ -4687,7 +4678,6 @@ export declare interface ResponseEvent<T = unknown> {
|
|
|
4687
4678
|
/** @public */
|
|
4688
4679
|
export declare interface ResponseQueryOptions extends RequestOptions {
|
|
4689
4680
|
perspective?: ClientPerspective
|
|
4690
|
-
decideParameters?: DecideParameters
|
|
4691
4681
|
resultSourceMap?: boolean | 'withKeyArraySelector'
|
|
4692
4682
|
returnQuery?: boolean
|
|
4693
4683
|
useCdn?: boolean
|
package/dist/index.d.ts
CHANGED
|
@@ -706,10 +706,6 @@ export declare interface ClientConfig {
|
|
|
706
706
|
* @defaultValue 'published'
|
|
707
707
|
*/
|
|
708
708
|
perspective?: ClientPerspective
|
|
709
|
-
/**
|
|
710
|
-
* Parameters to pass to Sanity Decide for personalisation
|
|
711
|
-
*/
|
|
712
|
-
decideParameters?: DecideParameters
|
|
713
709
|
apiHost?: string
|
|
714
710
|
/**
|
|
715
711
|
@remarks
|
|
@@ -791,6 +787,10 @@ export declare interface ClientConfig {
|
|
|
791
787
|
* Options for how, if enabled, Content Source Maps are encoded into query results using steganography
|
|
792
788
|
*/
|
|
793
789
|
stega?: StegaConfig | boolean
|
|
790
|
+
/**
|
|
791
|
+
* Lineage token for recursion control
|
|
792
|
+
*/
|
|
793
|
+
lineage?: string
|
|
794
794
|
}
|
|
795
795
|
|
|
796
796
|
declare type ClientConfigResource =
|
|
@@ -1136,12 +1136,6 @@ export declare type DatasetsResponse = {
|
|
|
1136
1136
|
tags: string[]
|
|
1137
1137
|
}[]
|
|
1138
1138
|
|
|
1139
|
-
/** @public */
|
|
1140
|
-
export declare interface DecideParameters {
|
|
1141
|
-
audience: string | string[]
|
|
1142
|
-
[key: string]: unknown
|
|
1143
|
-
}
|
|
1144
|
-
|
|
1145
1139
|
/**
|
|
1146
1140
|
* Deletes the published version of a document and optionally some (likely all known) draft versions.
|
|
1147
1141
|
* If any draft version exists that is not specified for deletion this is an error.
|
|
@@ -4143,8 +4137,6 @@ export declare interface QueryParams {
|
|
|
4143
4137
|
/** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
|
|
4144
4138
|
cache?: 'next' extends keyof RequestInit ? never : any
|
|
4145
4139
|
/** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
|
|
4146
|
-
decideParameters?: never
|
|
4147
|
-
/** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
|
|
4148
4140
|
filterResponse?: never
|
|
4149
4141
|
/** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
|
|
4150
4142
|
headers?: never
|
|
@@ -4654,7 +4646,6 @@ export declare interface RequestObservableOptions extends Omit<RequestOptions, '
|
|
|
4654
4646
|
returnQuery?: boolean
|
|
4655
4647
|
resultSourceMap?: boolean | 'withKeyArraySelector'
|
|
4656
4648
|
perspective?: ClientPerspective
|
|
4657
|
-
decideParameters?: DecideParameters
|
|
4658
4649
|
lastLiveEventId?: string
|
|
4659
4650
|
cacheMode?: 'noStale'
|
|
4660
4651
|
}
|
|
@@ -4687,7 +4678,6 @@ export declare interface ResponseEvent<T = unknown> {
|
|
|
4687
4678
|
/** @public */
|
|
4688
4679
|
export declare interface ResponseQueryOptions extends RequestOptions {
|
|
4689
4680
|
perspective?: ClientPerspective
|
|
4690
|
-
decideParameters?: DecideParameters
|
|
4691
4681
|
resultSourceMap?: boolean | 'withKeyArraySelector'
|
|
4692
4682
|
returnQuery?: boolean
|
|
4693
4683
|
useCdn?: boolean
|
package/dist/index.js
CHANGED
|
@@ -670,80 +670,6 @@ function requestOptions(config, overrides = {}) {
|
|
|
670
670
|
fetch: typeof overrides.fetch == "object" && typeof config.fetch == "object" ? { ...config.fetch, ...overrides.fetch } : overrides.fetch || config.fetch
|
|
671
671
|
});
|
|
672
672
|
}
|
|
673
|
-
function isDecideField(value) {
|
|
674
|
-
return value != null && typeof value == "object" && !Array.isArray(value) && "default" in value && "conditions" in value && Array.isArray(value.conditions);
|
|
675
|
-
}
|
|
676
|
-
function resolveDecideField(field, decideParameters) {
|
|
677
|
-
console.log("[client-8] resolveDecideField: starting resolution:", {
|
|
678
|
-
field: {
|
|
679
|
-
default: field.default,
|
|
680
|
-
conditionsCount: field.conditions.length,
|
|
681
|
-
conditions: field.conditions.map((c, i) => ({
|
|
682
|
-
index: i,
|
|
683
|
-
audience: c.audience,
|
|
684
|
-
value: c.value
|
|
685
|
-
}))
|
|
686
|
-
},
|
|
687
|
-
decideParameters
|
|
688
|
-
});
|
|
689
|
-
const audience = decideParameters?.audience;
|
|
690
|
-
if (console.log("[client-8] resolveDecideField: audience processing:", {
|
|
691
|
-
audience,
|
|
692
|
-
audienceType: typeof audience,
|
|
693
|
-
isArray: Array.isArray(audience),
|
|
694
|
-
isEmpty: Array.isArray(audience) ? audience.length === 0 : audience === "",
|
|
695
|
-
isUndefined: audience === void 0,
|
|
696
|
-
isNull: audience === null
|
|
697
|
-
}), !audience || Array.isArray(audience) && audience.length === 0 || audience === "")
|
|
698
|
-
return console.log(
|
|
699
|
-
"[client-8] resolveDecideField: no valid audience, returning default:",
|
|
700
|
-
field.default
|
|
701
|
-
), field.default;
|
|
702
|
-
console.log("[client-8] resolveDecideField: searching for matching condition...");
|
|
703
|
-
const matchingCondition = field.conditions.find((condition, index) => {
|
|
704
|
-
const isMatch = Array.isArray(audience) ? audience.includes(condition.audience) : condition.audience === audience;
|
|
705
|
-
return console.log(`[client-8] resolveDecideField: checking condition ${index}:`, {
|
|
706
|
-
conditionAudience: condition.audience,
|
|
707
|
-
conditionValue: condition.value,
|
|
708
|
-
searchAudience: audience,
|
|
709
|
-
isArraySearch: Array.isArray(audience),
|
|
710
|
-
isMatch
|
|
711
|
-
}), isMatch;
|
|
712
|
-
}), resolvedValue = matchingCondition ? matchingCondition.value : field.default;
|
|
713
|
-
return console.log("[client-8] resolveDecideField: resolution complete:", {
|
|
714
|
-
matchingCondition: matchingCondition ? {
|
|
715
|
-
audience: matchingCondition.audience,
|
|
716
|
-
value: matchingCondition.value
|
|
717
|
-
} : null,
|
|
718
|
-
resolvedValue,
|
|
719
|
-
usedDefault: !matchingCondition
|
|
720
|
-
}), resolvedValue;
|
|
721
|
-
}
|
|
722
|
-
function processObjectRecursively(obj, decideParameters, depth = 0, path = "root") {
|
|
723
|
-
return obj == null || typeof obj != "object" ? obj : Array.isArray(obj) ? obj.map(
|
|
724
|
-
(item, index) => processObjectRecursively(item, decideParameters, depth + 1, `${path}[${index}]`)
|
|
725
|
-
) : Object.entries(obj).reduce((processed, [key, value]) => {
|
|
726
|
-
const currentPath = `${path}.${key}`, isDecide = isDecideField(value);
|
|
727
|
-
try {
|
|
728
|
-
isDecide ? (console.log(`[client-8] DECIDE FIELD FOUND: Key: '${key}'`), processed[key] = resolveDecideField(value, decideParameters)) : processed[key] = processObjectRecursively(value, decideParameters, depth + 1, currentPath);
|
|
729
|
-
} catch {
|
|
730
|
-
processed[key] = value;
|
|
731
|
-
}
|
|
732
|
-
return processed;
|
|
733
|
-
}, {});
|
|
734
|
-
}
|
|
735
|
-
function processDecideFields(data, decideParameters) {
|
|
736
|
-
console.log("[client-8] === DECIDE FIELD PROCESSING START ===");
|
|
737
|
-
try {
|
|
738
|
-
const result = processObjectRecursively(data, decideParameters);
|
|
739
|
-
return console.log("[client-8] === DECIDE FIELD PROCESSING END ==="), result;
|
|
740
|
-
} catch (error) {
|
|
741
|
-
return console.warn(
|
|
742
|
-
"[client-8] processDecideFields: processing failed, returning original data:",
|
|
743
|
-
error
|
|
744
|
-
), data;
|
|
745
|
-
}
|
|
746
|
-
}
|
|
747
673
|
const encodeQueryString = ({
|
|
748
674
|
query,
|
|
749
675
|
params = {},
|
|
@@ -768,7 +694,7 @@ function _fetch(client, httpRequest, _stega, query, _params = {}, options = {})
|
|
|
768
694
|
const stega = "stega" in options ? {
|
|
769
695
|
..._stega || {},
|
|
770
696
|
...typeof options.stega == "boolean" ? { enabled: options.stega } : options.stega || {}
|
|
771
|
-
} : _stega, params = stega.enabled ? stegaClean(_params) : _params, mapResponse = options.filterResponse === !1 ? (res) => res : (res) => res.result,
|
|
697
|
+
} : _stega, params = stega.enabled ? stegaClean(_params) : _params, mapResponse = options.filterResponse === !1 ? (res) => res : (res) => res.result, { cache, next, ...opts } = {
|
|
772
698
|
// Opt out of setting a `signal` on an internal `fetch` if one isn't provided.
|
|
773
699
|
// This is necessary in React Server Components to avoid opting out of Request Memoization.
|
|
774
700
|
useAbortSignal: typeof options.signal < "u",
|
|
@@ -791,16 +717,11 @@ function _fetch(client, httpRequest, _stega, query, _params = {}, options = {})
|
|
|
791
717
|
),
|
|
792
718
|
map(
|
|
793
719
|
([res, stegaEncodeSourceMap]) => {
|
|
794
|
-
const
|
|
720
|
+
const result = stegaEncodeSourceMap(res.result, res.resultSourceMap, stega);
|
|
795
721
|
return mapResponse({ ...res, result });
|
|
796
722
|
}
|
|
797
723
|
)
|
|
798
|
-
) : $request.pipe(
|
|
799
|
-
map((res) => {
|
|
800
|
-
const mappedResponse = mapResponse(res);
|
|
801
|
-
return processDecideResponse(mappedResponse);
|
|
802
|
-
})
|
|
803
|
-
);
|
|
724
|
+
) : $request.pipe(map(mapResponse));
|
|
804
725
|
}
|
|
805
726
|
function _getDocument(client, httpRequest, id, opts = {}) {
|
|
806
727
|
const docId = (() => {
|
|
@@ -953,7 +874,6 @@ function _dataRequest(client, httpRequest, endpoint, body, options = {}) {
|
|
|
953
874
|
tag,
|
|
954
875
|
returnQuery,
|
|
955
876
|
perspective: options.perspective,
|
|
956
|
-
decideParameters: options.decideParameters,
|
|
957
877
|
resultSourceMap: options.resultSourceMap,
|
|
958
878
|
lastLiveEventId: Array.isArray(lastLiveEventId) ? lastLiveEventId[0] : lastLiveEventId,
|
|
959
879
|
cacheMode,
|
|
@@ -1000,9 +920,12 @@ function _requestObservable(client, httpRequest, options) {
|
|
|
1000
920
|
}, (Array.isArray(perspectiveOption) && perspectiveOption.length > 0 || // previewDrafts was renamed to drafts, but keep for backwards compat
|
|
1001
921
|
perspectiveOption === "previewDrafts" || perspectiveOption === "drafts") && 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 });
|
|
1002
922
|
}
|
|
1003
|
-
const
|
|
1004
|
-
|
|
1005
|
-
|
|
923
|
+
const reqOptions = requestOptions(
|
|
924
|
+
config,
|
|
925
|
+
Object.assign({}, options, {
|
|
926
|
+
url: _getUrl(client, uri, useCdn)
|
|
927
|
+
})
|
|
928
|
+
), request = new Observable(
|
|
1006
929
|
(subscriber) => httpRequest(reqOptions, config.requester).subscribe(subscriber)
|
|
1007
930
|
);
|
|
1008
931
|
return options.signal ? request.pipe(_withAbortSignal(options.signal)) : request;
|
|
@@ -2222,17 +2145,7 @@ class ObservableSanityClient {
|
|
|
2222
2145
|
});
|
|
2223
2146
|
}
|
|
2224
2147
|
fetch(query, params, options) {
|
|
2225
|
-
return
|
|
2226
|
-
query: query.substring(0, 100) + (query.length > 100 ? "..." : ""),
|
|
2227
|
-
params,
|
|
2228
|
-
options: {
|
|
2229
|
-
...options,
|
|
2230
|
-
decideParameters: options?.decideParameters
|
|
2231
|
-
},
|
|
2232
|
-
clientConfig: {
|
|
2233
|
-
decideParameters: this.#clientConfig.decideParameters
|
|
2234
|
-
}
|
|
2235
|
-
}), _fetch(
|
|
2148
|
+
return _fetch(
|
|
2236
2149
|
this,
|
|
2237
2150
|
this.#httpRequest,
|
|
2238
2151
|
this.#clientConfig.stega,
|
|
@@ -2496,17 +2409,7 @@ class SanityClient {
|
|
|
2496
2409
|
});
|
|
2497
2410
|
}
|
|
2498
2411
|
fetch(query, params, options) {
|
|
2499
|
-
return
|
|
2500
|
-
query: query.substring(0, 100) + (query.length > 100 ? "..." : ""),
|
|
2501
|
-
params,
|
|
2502
|
-
options: {
|
|
2503
|
-
...options,
|
|
2504
|
-
decideParameters: options?.decideParameters
|
|
2505
|
-
},
|
|
2506
|
-
clientConfig: {
|
|
2507
|
-
decideParameters: this.#clientConfig.decideParameters
|
|
2508
|
-
}
|
|
2509
|
-
}), lastValueFrom(
|
|
2412
|
+
return lastValueFrom(
|
|
2510
2413
|
_fetch(
|
|
2511
2414
|
this,
|
|
2512
2415
|
this.#httpRequest,
|
|
@@ -2755,6 +2658,7 @@ function defineCreateClientExports(envMiddleware, ClassConstructor) {
|
|
|
2755
2658
|
maxRedirects: 0,
|
|
2756
2659
|
maxRetries: config.maxRetries,
|
|
2757
2660
|
retryDelay: config.retryDelay,
|
|
2661
|
+
lineage: config.lineage,
|
|
2758
2662
|
...options
|
|
2759
2663
|
}),
|
|
2760
2664
|
config
|
|
@@ -2766,10 +2670,19 @@ function defineDeprecatedCreateClient(createClient2) {
|
|
|
2766
2670
|
return printNoDefaultExport(), createClient2(config);
|
|
2767
2671
|
};
|
|
2768
2672
|
}
|
|
2769
|
-
var name = "@sanity/client", version = "7.
|
|
2673
|
+
var name = "@sanity/client", version = "7.12.0";
|
|
2770
2674
|
const middleware = [
|
|
2771
2675
|
debug({ verbose: !0, namespace: "sanity:client" }),
|
|
2772
2676
|
headers({ "User-Agent": `${name} ${version}` }),
|
|
2677
|
+
// Lineage is used for recursion control/tracing and can be passed either through
|
|
2678
|
+
// client constructor or through environent variable.
|
|
2679
|
+
// Not used in browser environments.
|
|
2680
|
+
{
|
|
2681
|
+
processOptions(opts) {
|
|
2682
|
+
const lineage = typeof process < "u" && process.env.X_SANITY_LINEAGE || opts.lineage;
|
|
2683
|
+
return lineage && (opts.headers = opts.headers || {}, opts.headers["x-sanity-lineage"] = lineage), opts;
|
|
2684
|
+
}
|
|
2685
|
+
},
|
|
2773
2686
|
// Enable keep-alive, and in addition limit the number of sockets that can be opened.
|
|
2774
2687
|
// This avoids opening too many connections to the server if someone tries to execute
|
|
2775
2688
|
// a bunch of requests in parallel. It's recommended to have a concurrency limit
|