@sanity/client 7.11.2-audience-decide.0 → 7.11.2-audience-decide.2
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 +107 -16
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.js +107 -16
- package/dist/index.browser.js.map +1 -1
- package/dist/index.cjs +108 -17
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +108 -17
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/SanityClient.ts +26 -0
- package/src/data/dataMethods.ts +118 -14
- package/src/data/decideResponseProcessor.ts +3 -0
- package/umd/sanityClient.js +107 -16
- package/umd/sanityClient.min.js +2 -2
package/dist/index.cjs
CHANGED
|
@@ -702,6 +702,7 @@ function processObjectRecursively(obj, decideParameters) {
|
|
|
702
702
|
function processDecideFields(data, decideParameters) {
|
|
703
703
|
if (!decideParameters || !decideParameters.audience)
|
|
704
704
|
return data;
|
|
705
|
+
console.log("Starting decide field processing with parameters:", decideParameters);
|
|
705
706
|
try {
|
|
706
707
|
return processObjectRecursively(data, decideParameters);
|
|
707
708
|
} catch (error) {
|
|
@@ -729,10 +730,25 @@ const encodeQueryString = ({
|
|
|
729
730
|
skipCrossDatasetReferenceValidation: options.skipCrossDatasetReferenceValidation
|
|
730
731
|
}), isResponse = (event) => event.type === "response", getBody = (event) => event.body, indexBy = (docs, attr) => docs.reduce((indexed, doc) => (indexed[attr(doc)] = doc, indexed), /* @__PURE__ */ Object.create(null)), getQuerySizeLimit = 11264;
|
|
731
732
|
function _fetch(client, httpRequest, _stega, query, _params = {}, options = {}) {
|
|
733
|
+
console.log("_fetch called with:", {
|
|
734
|
+
query: query.substring(0, 100) + (query.length > 100 ? "..." : ""),
|
|
735
|
+
params: _params,
|
|
736
|
+
options: {
|
|
737
|
+
...options,
|
|
738
|
+
decideParameters: options.decideParameters
|
|
739
|
+
},
|
|
740
|
+
stegaEnabled: _stega?.enabled
|
|
741
|
+
});
|
|
732
742
|
const stega = "stega" in options ? {
|
|
733
743
|
..._stega || {},
|
|
734
744
|
...typeof options.stega == "boolean" ? { enabled: options.stega } : options.stega || {}
|
|
735
|
-
} : _stega, params = stega.enabled ? stegaClean.stegaClean(_params) : _params, mapResponse = options.filterResponse === !1 ? (res) => res : (res) => res.result, processDecideResponse = (response) =>
|
|
745
|
+
} : _stega, params = stega.enabled ? stegaClean.stegaClean(_params) : _params, mapResponse = options.filterResponse === !1 ? (res) => res : (res) => res.result, processDecideResponse = (response) => (console.log("inside processDecideResponse:", {
|
|
746
|
+
audience: options.decideParameters?.audience,
|
|
747
|
+
decideParameters: options.decideParameters?.audience
|
|
748
|
+
}), options.decideParameters && options.decideParameters.audience ? (console.log("Processing response with decideParameters:", {
|
|
749
|
+
audience: options.decideParameters.audience,
|
|
750
|
+
decideParameters: options.decideParameters
|
|
751
|
+
}), processDecideFields(response, options.decideParameters)) : response), { cache, next, ...opts } = {
|
|
736
752
|
// Opt out of setting a `signal` on an internal `fetch` if one isn't provided.
|
|
737
753
|
// This is necessary in React Server Components to avoid opting out of Request Memoization.
|
|
738
754
|
useAbortSignal: typeof options.signal < "u",
|
|
@@ -902,6 +918,18 @@ function _action(client, httpRequest, actions, options) {
|
|
|
902
918
|
);
|
|
903
919
|
}
|
|
904
920
|
function _dataRequest(client, httpRequest, endpoint, body, options = {}) {
|
|
921
|
+
console.log("_dataRequest called with:", {
|
|
922
|
+
endpoint,
|
|
923
|
+
body: endpoint === "query" ? {
|
|
924
|
+
query: body.query?.substring(0, 100) + (body.query?.length > 100 ? "..." : ""),
|
|
925
|
+
params: body.params
|
|
926
|
+
} : body,
|
|
927
|
+
options: {
|
|
928
|
+
...options,
|
|
929
|
+
decideParameters: options.decideParameters,
|
|
930
|
+
perspective: options.perspective
|
|
931
|
+
}
|
|
932
|
+
});
|
|
905
933
|
const isMutation = endpoint === "mutate", isAction = endpoint === "actions", isQuery2 = endpoint === "query", strQuery = isMutation || isAction ? "" : encodeQueryString(body), useGet = !isMutation && !isAction && strQuery.length < getQuerySizeLimit, stringQuery = useGet ? strQuery : "", returnFirst = options.returnFirst, { timeout, token, tag, headers, returnQuery, lastLiveEventId, cacheMode } = options, uri = _getDataUrl(client, endpoint, stringQuery), reqOptions = {
|
|
906
934
|
method: useGet ? "GET" : "POST",
|
|
907
935
|
uri,
|
|
@@ -924,7 +952,15 @@ function _dataRequest(client, httpRequest, endpoint, body, options = {}) {
|
|
|
924
952
|
useAbortSignal: options.useAbortSignal,
|
|
925
953
|
useCdn: options.useCdn
|
|
926
954
|
};
|
|
927
|
-
return
|
|
955
|
+
return console.log("_dataRequest calling _requestObservable with reqOptions:", {
|
|
956
|
+
...reqOptions,
|
|
957
|
+
decideParameters: reqOptions.decideParameters,
|
|
958
|
+
perspective: reqOptions.perspective,
|
|
959
|
+
body: useGet ? void 0 : endpoint === "query" ? {
|
|
960
|
+
query: body.query?.substring(0, 100) + (body.query?.length > 100 ? "..." : ""),
|
|
961
|
+
params: body.params
|
|
962
|
+
} : body
|
|
963
|
+
}), _requestObservable(client, httpRequest, reqOptions).pipe(
|
|
928
964
|
operators.filter(isResponse),
|
|
929
965
|
operators.map(getBody),
|
|
930
966
|
operators.map((res) => {
|
|
@@ -948,7 +984,16 @@ function _create(client, httpRequest, doc, op, options = {}) {
|
|
|
948
984
|
}
|
|
949
985
|
const hasDataConfig = (client) => client.config().dataset !== void 0 && client.config().projectId !== void 0 || client.config()["~experimental_resource"] !== void 0, isQuery = (client, uri) => hasDataConfig(client) && uri.startsWith(_getDataUrl(client, "query")), isMutate = (client, uri) => hasDataConfig(client) && uri.startsWith(_getDataUrl(client, "mutate")), isDoc = (client, uri) => hasDataConfig(client) && uri.startsWith(_getDataUrl(client, "doc", "")), isListener = (client, uri) => hasDataConfig(client) && uri.startsWith(_getDataUrl(client, "listen")), isHistory = (client, uri) => hasDataConfig(client) && uri.startsWith(_getDataUrl(client, "history", "")), isData = (client, uri) => uri.startsWith("/data/") || isQuery(client, uri) || isMutate(client, uri) || isDoc(client, uri) || isListener(client, uri) || isHistory(client, uri);
|
|
950
986
|
function _requestObservable(client, httpRequest, options) {
|
|
951
|
-
const uri = options.url || options.uri, config$1 = client.config()
|
|
987
|
+
const uri = options.url || options.uri, config$1 = client.config();
|
|
988
|
+
console.log("_requestObservable called with options:", {
|
|
989
|
+
uri,
|
|
990
|
+
method: options.method,
|
|
991
|
+
decideParameters: options.decideParameters,
|
|
992
|
+
perspective: options.perspective,
|
|
993
|
+
query: options.query,
|
|
994
|
+
configDecideParameters: config$1.decideParameters
|
|
995
|
+
});
|
|
996
|
+
const canUseCdn = typeof options.canUseCdn > "u" ? ["GET", "HEAD"].indexOf(options.method || "GET") >= 0 && isData(client, uri) : options.canUseCdn;
|
|
952
997
|
let useCdn = (options.useCdn ?? config$1.useCdn) && canUseCdn;
|
|
953
998
|
const tag = options.tag && config$1.requestTagPrefix ? [config$1.requestTagPrefix, options.tag].join(".") : options.tag || config$1.requestTagPrefix;
|
|
954
999
|
if (tag && options.tag !== null && (options.query = { tag: config.requestTag(tag), ...options.query }), ["GET", "HEAD", "POST"].indexOf(options.method || "GET") >= 0 && isQuery(client, uri)) {
|
|
@@ -961,20 +1006,46 @@ function _requestObservable(client, httpRequest, options) {
|
|
|
961
1006
|
}, (Array.isArray(perspectiveOption) && perspectiveOption.length > 0 || // previewDrafts was renamed to drafts, but keep for backwards compat
|
|
962
1007
|
perspectiveOption === "previewDrafts" || perspectiveOption === "drafts") && useCdn && (useCdn = !1, config.printCdnPreviewDraftsWarning()));
|
|
963
1008
|
const decideParametersOption = options.decideParameters || config$1.decideParameters;
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
1009
|
+
if (console.log("Processing decideParameters:", {
|
|
1010
|
+
optionsDecideParameters: options.decideParameters,
|
|
1011
|
+
configDecideParameters: config$1.decideParameters,
|
|
1012
|
+
finalDecideParametersOption: decideParametersOption
|
|
1013
|
+
}), decideParametersOption && typeof decideParametersOption == "object") {
|
|
1014
|
+
console.log("DecideParameters received, transforming to query params:", decideParametersOption);
|
|
1015
|
+
const decideQueryParams = Object.keys(decideParametersOption).reduce(
|
|
967
1016
|
(acc, key) => (acc[`decide.${key}`] = decideParametersOption[key], acc),
|
|
968
1017
|
{}
|
|
969
|
-
)
|
|
970
|
-
|
|
1018
|
+
);
|
|
1019
|
+
console.log("DecideParameters transformed to query params:", decideQueryParams);
|
|
1020
|
+
const oldQuery = options.query;
|
|
1021
|
+
options.query = {
|
|
1022
|
+
...options.query,
|
|
1023
|
+
...decideQueryParams
|
|
1024
|
+
}, console.log("Updated query object:", {
|
|
1025
|
+
oldQuery,
|
|
1026
|
+
newQuery: options.query
|
|
1027
|
+
});
|
|
1028
|
+
} else
|
|
1029
|
+
console.log("No decideParameters to process or invalid format");
|
|
1030
|
+
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 });
|
|
971
1031
|
}
|
|
972
|
-
const
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
1032
|
+
const finalOptions = Object.assign({}, options, {
|
|
1033
|
+
url: _getUrl(client, uri, useCdn)
|
|
1034
|
+
});
|
|
1035
|
+
console.log("Final options before requestOptions call:", {
|
|
1036
|
+
url: finalOptions.url,
|
|
1037
|
+
decideParameters: finalOptions.decideParameters,
|
|
1038
|
+
query: finalOptions.query,
|
|
1039
|
+
method: finalOptions.method
|
|
1040
|
+
});
|
|
1041
|
+
const reqOptions = requestOptions(config$1, finalOptions);
|
|
1042
|
+
console.log("Final reqOptions from requestOptions:", {
|
|
1043
|
+
method: reqOptions.method,
|
|
1044
|
+
headers: reqOptions.headers,
|
|
1045
|
+
query: reqOptions.query
|
|
1046
|
+
// Note: URL is handled separately in the HTTP request
|
|
1047
|
+
});
|
|
1048
|
+
const request = new rxjs.Observable(
|
|
978
1049
|
(subscriber) => httpRequest(reqOptions, config$1.requester).subscribe(subscriber)
|
|
979
1050
|
);
|
|
980
1051
|
return options.signal ? request.pipe(_withAbortSignal(options.signal)) : request;
|
|
@@ -2194,7 +2265,17 @@ class ObservableSanityClient {
|
|
|
2194
2265
|
});
|
|
2195
2266
|
}
|
|
2196
2267
|
fetch(query, params, options) {
|
|
2197
|
-
return
|
|
2268
|
+
return console.log("ObservableSanityClient.fetch called with:", {
|
|
2269
|
+
query: query.substring(0, 100) + (query.length > 100 ? "..." : ""),
|
|
2270
|
+
params,
|
|
2271
|
+
options: {
|
|
2272
|
+
...options,
|
|
2273
|
+
decideParameters: options?.decideParameters
|
|
2274
|
+
},
|
|
2275
|
+
clientConfig: {
|
|
2276
|
+
decideParameters: this.#clientConfig.decideParameters
|
|
2277
|
+
}
|
|
2278
|
+
}), _fetch(
|
|
2198
2279
|
this,
|
|
2199
2280
|
this.#httpRequest,
|
|
2200
2281
|
this.#clientConfig.stega,
|
|
@@ -2458,7 +2539,17 @@ class SanityClient {
|
|
|
2458
2539
|
});
|
|
2459
2540
|
}
|
|
2460
2541
|
fetch(query, params, options) {
|
|
2461
|
-
return
|
|
2542
|
+
return console.log("SanityClient.fetch called with:", {
|
|
2543
|
+
query: query.substring(0, 100) + (query.length > 100 ? "..." : ""),
|
|
2544
|
+
params,
|
|
2545
|
+
options: {
|
|
2546
|
+
...options,
|
|
2547
|
+
decideParameters: options?.decideParameters
|
|
2548
|
+
},
|
|
2549
|
+
clientConfig: {
|
|
2550
|
+
decideParameters: this.#clientConfig.decideParameters
|
|
2551
|
+
}
|
|
2552
|
+
}), rxjs.lastValueFrom(
|
|
2462
2553
|
_fetch(
|
|
2463
2554
|
this,
|
|
2464
2555
|
this.#httpRequest,
|
|
@@ -2718,7 +2809,7 @@ function defineDeprecatedCreateClient(createClient2) {
|
|
|
2718
2809
|
return config.printNoDefaultExport(), createClient2(config$1);
|
|
2719
2810
|
};
|
|
2720
2811
|
}
|
|
2721
|
-
var name = "@sanity/client", version = "7.11.2-audience-decide.
|
|
2812
|
+
var name = "@sanity/client", version = "7.11.2-audience-decide.2";
|
|
2722
2813
|
const middleware = [
|
|
2723
2814
|
middleware$1.debug({ verbose: !0, namespace: "sanity:client" }),
|
|
2724
2815
|
middleware$1.headers({ "User-Agent": `${name} ${version}` }),
|