@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.browser.d.cts
CHANGED
|
@@ -705,10 +705,6 @@ export declare interface ClientConfig {
|
|
|
705
705
|
* @defaultValue 'published'
|
|
706
706
|
*/
|
|
707
707
|
perspective?: ClientPerspective
|
|
708
|
-
/**
|
|
709
|
-
* Parameters to pass to Sanity Decide for personalisation
|
|
710
|
-
*/
|
|
711
|
-
decideParameters?: DecideParameters
|
|
712
708
|
apiHost?: string
|
|
713
709
|
/**
|
|
714
710
|
@remarks
|
|
@@ -790,6 +786,10 @@ export declare interface ClientConfig {
|
|
|
790
786
|
* Options for how, if enabled, Content Source Maps are encoded into query results using steganography
|
|
791
787
|
*/
|
|
792
788
|
stega?: StegaConfig | boolean
|
|
789
|
+
/**
|
|
790
|
+
* Lineage token for recursion control
|
|
791
|
+
*/
|
|
792
|
+
lineage?: string
|
|
793
793
|
}
|
|
794
794
|
|
|
795
795
|
declare type ClientConfigResource =
|
|
@@ -1139,12 +1139,6 @@ export declare type DatasetsResponse = {
|
|
|
1139
1139
|
tags: string[]
|
|
1140
1140
|
}[]
|
|
1141
1141
|
|
|
1142
|
-
/** @public */
|
|
1143
|
-
export declare interface DecideParameters {
|
|
1144
|
-
audience: string | string[]
|
|
1145
|
-
[key: string]: unknown
|
|
1146
|
-
}
|
|
1147
|
-
|
|
1148
1142
|
/**
|
|
1149
1143
|
* Deletes the published version of a document and optionally some (likely all known) draft versions.
|
|
1150
1144
|
* If any draft version exists that is not specified for deletion this is an error.
|
|
@@ -4151,8 +4145,6 @@ export declare interface QueryParams {
|
|
|
4151
4145
|
/** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
|
|
4152
4146
|
cache?: 'next' extends keyof RequestInit ? never : any
|
|
4153
4147
|
/** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
|
|
4154
|
-
decideParameters?: never
|
|
4155
|
-
/** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
|
|
4156
4148
|
filterResponse?: never
|
|
4157
4149
|
/** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
|
|
4158
4150
|
headers?: never
|
|
@@ -4662,7 +4654,6 @@ export declare interface RequestObservableOptions extends Omit<RequestOptions, '
|
|
|
4662
4654
|
returnQuery?: boolean
|
|
4663
4655
|
resultSourceMap?: boolean | 'withKeyArraySelector'
|
|
4664
4656
|
perspective?: ClientPerspective
|
|
4665
|
-
decideParameters?: DecideParameters
|
|
4666
4657
|
lastLiveEventId?: string
|
|
4667
4658
|
cacheMode?: 'noStale'
|
|
4668
4659
|
}
|
|
@@ -4695,7 +4686,6 @@ export declare interface ResponseEvent<T = unknown> {
|
|
|
4695
4686
|
/** @public */
|
|
4696
4687
|
export declare interface ResponseQueryOptions extends RequestOptions {
|
|
4697
4688
|
perspective?: ClientPerspective
|
|
4698
|
-
decideParameters?: DecideParameters
|
|
4699
4689
|
resultSourceMap?: boolean | 'withKeyArraySelector'
|
|
4700
4690
|
returnQuery?: boolean
|
|
4701
4691
|
useCdn?: boolean
|
package/dist/index.browser.d.ts
CHANGED
|
@@ -705,10 +705,6 @@ export declare interface ClientConfig {
|
|
|
705
705
|
* @defaultValue 'published'
|
|
706
706
|
*/
|
|
707
707
|
perspective?: ClientPerspective
|
|
708
|
-
/**
|
|
709
|
-
* Parameters to pass to Sanity Decide for personalisation
|
|
710
|
-
*/
|
|
711
|
-
decideParameters?: DecideParameters
|
|
712
708
|
apiHost?: string
|
|
713
709
|
/**
|
|
714
710
|
@remarks
|
|
@@ -790,6 +786,10 @@ export declare interface ClientConfig {
|
|
|
790
786
|
* Options for how, if enabled, Content Source Maps are encoded into query results using steganography
|
|
791
787
|
*/
|
|
792
788
|
stega?: StegaConfig | boolean
|
|
789
|
+
/**
|
|
790
|
+
* Lineage token for recursion control
|
|
791
|
+
*/
|
|
792
|
+
lineage?: string
|
|
793
793
|
}
|
|
794
794
|
|
|
795
795
|
declare type ClientConfigResource =
|
|
@@ -1139,12 +1139,6 @@ export declare type DatasetsResponse = {
|
|
|
1139
1139
|
tags: string[]
|
|
1140
1140
|
}[]
|
|
1141
1141
|
|
|
1142
|
-
/** @public */
|
|
1143
|
-
export declare interface DecideParameters {
|
|
1144
|
-
audience: string | string[]
|
|
1145
|
-
[key: string]: unknown
|
|
1146
|
-
}
|
|
1147
|
-
|
|
1148
1142
|
/**
|
|
1149
1143
|
* Deletes the published version of a document and optionally some (likely all known) draft versions.
|
|
1150
1144
|
* If any draft version exists that is not specified for deletion this is an error.
|
|
@@ -4151,8 +4145,6 @@ export declare interface QueryParams {
|
|
|
4151
4145
|
/** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
|
|
4152
4146
|
cache?: 'next' extends keyof RequestInit ? never : any
|
|
4153
4147
|
/** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
|
|
4154
|
-
decideParameters?: never
|
|
4155
|
-
/** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
|
|
4156
4148
|
filterResponse?: never
|
|
4157
4149
|
/** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
|
|
4158
4150
|
headers?: never
|
|
@@ -4662,7 +4654,6 @@ export declare interface RequestObservableOptions extends Omit<RequestOptions, '
|
|
|
4662
4654
|
returnQuery?: boolean
|
|
4663
4655
|
resultSourceMap?: boolean | 'withKeyArraySelector'
|
|
4664
4656
|
perspective?: ClientPerspective
|
|
4665
|
-
decideParameters?: DecideParameters
|
|
4666
4657
|
lastLiveEventId?: string
|
|
4667
4658
|
cacheMode?: 'noStale'
|
|
4668
4659
|
}
|
|
@@ -4695,7 +4686,6 @@ export declare interface ResponseEvent<T = unknown> {
|
|
|
4695
4686
|
/** @public */
|
|
4696
4687
|
export declare interface ResponseQueryOptions extends RequestOptions {
|
|
4697
4688
|
perspective?: ClientPerspective
|
|
4698
|
-
decideParameters?: DecideParameters
|
|
4699
4689
|
resultSourceMap?: boolean | 'withKeyArraySelector'
|
|
4700
4690
|
returnQuery?: boolean
|
|
4701
4691
|
useCdn?: boolean
|
package/dist/index.browser.js
CHANGED
|
@@ -839,80 +839,6 @@ function requestOptions(config, overrides = {}) {
|
|
|
839
839
|
fetch: typeof overrides.fetch == "object" && typeof config.fetch == "object" ? { ...config.fetch, ...overrides.fetch } : overrides.fetch || config.fetch
|
|
840
840
|
});
|
|
841
841
|
}
|
|
842
|
-
function isDecideField(value) {
|
|
843
|
-
return value != null && typeof value == "object" && !Array.isArray(value) && "default" in value && "conditions" in value && Array.isArray(value.conditions);
|
|
844
|
-
}
|
|
845
|
-
function resolveDecideField(field, decideParameters) {
|
|
846
|
-
console.log("[client-8] resolveDecideField: starting resolution:", {
|
|
847
|
-
field: {
|
|
848
|
-
default: field.default,
|
|
849
|
-
conditionsCount: field.conditions.length,
|
|
850
|
-
conditions: field.conditions.map((c, i) => ({
|
|
851
|
-
index: i,
|
|
852
|
-
audience: c.audience,
|
|
853
|
-
value: c.value
|
|
854
|
-
}))
|
|
855
|
-
},
|
|
856
|
-
decideParameters
|
|
857
|
-
});
|
|
858
|
-
const audience = decideParameters?.audience;
|
|
859
|
-
if (console.log("[client-8] resolveDecideField: audience processing:", {
|
|
860
|
-
audience,
|
|
861
|
-
audienceType: typeof audience,
|
|
862
|
-
isArray: Array.isArray(audience),
|
|
863
|
-
isEmpty: Array.isArray(audience) ? audience.length === 0 : audience === "",
|
|
864
|
-
isUndefined: audience === void 0,
|
|
865
|
-
isNull: audience === null
|
|
866
|
-
}), !audience || Array.isArray(audience) && audience.length === 0 || audience === "")
|
|
867
|
-
return console.log(
|
|
868
|
-
"[client-8] resolveDecideField: no valid audience, returning default:",
|
|
869
|
-
field.default
|
|
870
|
-
), field.default;
|
|
871
|
-
console.log("[client-8] resolveDecideField: searching for matching condition...");
|
|
872
|
-
const matchingCondition = field.conditions.find((condition, index) => {
|
|
873
|
-
const isMatch = Array.isArray(audience) ? audience.includes(condition.audience) : condition.audience === audience;
|
|
874
|
-
return console.log(`[client-8] resolveDecideField: checking condition ${index}:`, {
|
|
875
|
-
conditionAudience: condition.audience,
|
|
876
|
-
conditionValue: condition.value,
|
|
877
|
-
searchAudience: audience,
|
|
878
|
-
isArraySearch: Array.isArray(audience),
|
|
879
|
-
isMatch
|
|
880
|
-
}), isMatch;
|
|
881
|
-
}), resolvedValue = matchingCondition ? matchingCondition.value : field.default;
|
|
882
|
-
return console.log("[client-8] resolveDecideField: resolution complete:", {
|
|
883
|
-
matchingCondition: matchingCondition ? {
|
|
884
|
-
audience: matchingCondition.audience,
|
|
885
|
-
value: matchingCondition.value
|
|
886
|
-
} : null,
|
|
887
|
-
resolvedValue,
|
|
888
|
-
usedDefault: !matchingCondition
|
|
889
|
-
}), resolvedValue;
|
|
890
|
-
}
|
|
891
|
-
function processObjectRecursively(obj, decideParameters, depth = 0, path = "root") {
|
|
892
|
-
return obj == null || typeof obj != "object" ? obj : Array.isArray(obj) ? obj.map(
|
|
893
|
-
(item, index) => processObjectRecursively(item, decideParameters, depth + 1, `${path}[${index}]`)
|
|
894
|
-
) : Object.entries(obj).reduce((processed, [key, value]) => {
|
|
895
|
-
const currentPath = `${path}.${key}`, isDecide = isDecideField(value);
|
|
896
|
-
try {
|
|
897
|
-
isDecide ? (console.log(`[client-8] DECIDE FIELD FOUND: Key: '${key}'`), processed[key] = resolveDecideField(value, decideParameters)) : processed[key] = processObjectRecursively(value, decideParameters, depth + 1, currentPath);
|
|
898
|
-
} catch {
|
|
899
|
-
processed[key] = value;
|
|
900
|
-
}
|
|
901
|
-
return processed;
|
|
902
|
-
}, {});
|
|
903
|
-
}
|
|
904
|
-
function processDecideFields(data, decideParameters) {
|
|
905
|
-
console.log("[client-8] === DECIDE FIELD PROCESSING START ===");
|
|
906
|
-
try {
|
|
907
|
-
const result = processObjectRecursively(data, decideParameters);
|
|
908
|
-
return console.log("[client-8] === DECIDE FIELD PROCESSING END ==="), result;
|
|
909
|
-
} catch (error) {
|
|
910
|
-
return console.warn(
|
|
911
|
-
"[client-8] processDecideFields: processing failed, returning original data:",
|
|
912
|
-
error
|
|
913
|
-
), data;
|
|
914
|
-
}
|
|
915
|
-
}
|
|
916
842
|
const encodeQueryString = ({
|
|
917
843
|
query,
|
|
918
844
|
params = {},
|
|
@@ -937,7 +863,7 @@ function _fetch(client, httpRequest, _stega, query, _params = {}, options = {})
|
|
|
937
863
|
const stega = "stega" in options ? {
|
|
938
864
|
..._stega || {},
|
|
939
865
|
...typeof options.stega == "boolean" ? { enabled: options.stega } : options.stega || {}
|
|
940
|
-
} : _stega, params = stega.enabled ? stegaClean(_params) : _params, mapResponse = options.filterResponse === !1 ? (res) => res : (res) => res.result,
|
|
866
|
+
} : _stega, params = stega.enabled ? stegaClean(_params) : _params, mapResponse = options.filterResponse === !1 ? (res) => res : (res) => res.result, { cache, next, ...opts } = {
|
|
941
867
|
// Opt out of setting a `signal` on an internal `fetch` if one isn't provided.
|
|
942
868
|
// This is necessary in React Server Components to avoid opting out of Request Memoization.
|
|
943
869
|
useAbortSignal: typeof options.signal < "u",
|
|
@@ -960,16 +886,11 @@ function _fetch(client, httpRequest, _stega, query, _params = {}, options = {})
|
|
|
960
886
|
),
|
|
961
887
|
map(
|
|
962
888
|
([res, stegaEncodeSourceMap]) => {
|
|
963
|
-
const
|
|
889
|
+
const result = stegaEncodeSourceMap(res.result, res.resultSourceMap, stega);
|
|
964
890
|
return mapResponse({ ...res, result });
|
|
965
891
|
}
|
|
966
892
|
)
|
|
967
|
-
) : $request.pipe(
|
|
968
|
-
map((res) => {
|
|
969
|
-
const mappedResponse = mapResponse(res);
|
|
970
|
-
return processDecideResponse(mappedResponse);
|
|
971
|
-
})
|
|
972
|
-
);
|
|
893
|
+
) : $request.pipe(map(mapResponse));
|
|
973
894
|
}
|
|
974
895
|
function _getDocument(client, httpRequest, id, opts = {}) {
|
|
975
896
|
const docId = (() => {
|
|
@@ -1122,7 +1043,6 @@ function _dataRequest(client, httpRequest, endpoint, body, options = {}) {
|
|
|
1122
1043
|
tag,
|
|
1123
1044
|
returnQuery,
|
|
1124
1045
|
perspective: options.perspective,
|
|
1125
|
-
decideParameters: options.decideParameters,
|
|
1126
1046
|
resultSourceMap: options.resultSourceMap,
|
|
1127
1047
|
lastLiveEventId: Array.isArray(lastLiveEventId) ? lastLiveEventId[0] : lastLiveEventId,
|
|
1128
1048
|
cacheMode,
|
|
@@ -1169,9 +1089,12 @@ function _requestObservable(client, httpRequest, options) {
|
|
|
1169
1089
|
}, (Array.isArray(perspectiveOption) && perspectiveOption.length > 0 || // previewDrafts was renamed to drafts, but keep for backwards compat
|
|
1170
1090
|
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 });
|
|
1171
1091
|
}
|
|
1172
|
-
const
|
|
1173
|
-
|
|
1174
|
-
|
|
1092
|
+
const reqOptions = requestOptions(
|
|
1093
|
+
config,
|
|
1094
|
+
Object.assign({}, options, {
|
|
1095
|
+
url: _getUrl(client, uri, useCdn)
|
|
1096
|
+
})
|
|
1097
|
+
), request = new Observable(
|
|
1175
1098
|
(subscriber) => httpRequest(reqOptions, config.requester).subscribe(subscriber)
|
|
1176
1099
|
);
|
|
1177
1100
|
return options.signal ? request.pipe(_withAbortSignal(options.signal)) : request;
|
|
@@ -2391,17 +2314,7 @@ class ObservableSanityClient {
|
|
|
2391
2314
|
});
|
|
2392
2315
|
}
|
|
2393
2316
|
fetch(query, params, options) {
|
|
2394
|
-
return
|
|
2395
|
-
query: query.substring(0, 100) + (query.length > 100 ? "..." : ""),
|
|
2396
|
-
params,
|
|
2397
|
-
options: {
|
|
2398
|
-
...options,
|
|
2399
|
-
decideParameters: options?.decideParameters
|
|
2400
|
-
},
|
|
2401
|
-
clientConfig: {
|
|
2402
|
-
decideParameters: this.#clientConfig.decideParameters
|
|
2403
|
-
}
|
|
2404
|
-
}), _fetch(
|
|
2317
|
+
return _fetch(
|
|
2405
2318
|
this,
|
|
2406
2319
|
this.#httpRequest,
|
|
2407
2320
|
this.#clientConfig.stega,
|
|
@@ -2665,17 +2578,7 @@ class SanityClient {
|
|
|
2665
2578
|
});
|
|
2666
2579
|
}
|
|
2667
2580
|
fetch(query, params, options) {
|
|
2668
|
-
return
|
|
2669
|
-
query: query.substring(0, 100) + (query.length > 100 ? "..." : ""),
|
|
2670
|
-
params,
|
|
2671
|
-
options: {
|
|
2672
|
-
...options,
|
|
2673
|
-
decideParameters: options?.decideParameters
|
|
2674
|
-
},
|
|
2675
|
-
clientConfig: {
|
|
2676
|
-
decideParameters: this.#clientConfig.decideParameters
|
|
2677
|
-
}
|
|
2678
|
-
}), lastValueFrom(
|
|
2581
|
+
return lastValueFrom(
|
|
2679
2582
|
_fetch(
|
|
2680
2583
|
this,
|
|
2681
2584
|
this.#httpRequest,
|
|
@@ -2924,6 +2827,7 @@ function defineCreateClientExports(envMiddleware2, ClassConstructor) {
|
|
|
2924
2827
|
maxRedirects: 0,
|
|
2925
2828
|
maxRetries: config.maxRetries,
|
|
2926
2829
|
retryDelay: config.retryDelay,
|
|
2830
|
+
lineage: config.lineage,
|
|
2927
2831
|
...options
|
|
2928
2832
|
}),
|
|
2929
2833
|
config
|