@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.js
CHANGED
|
@@ -690,6 +690,7 @@ function processObjectRecursively(obj, decideParameters) {
|
|
|
690
690
|
function processDecideFields(data, decideParameters) {
|
|
691
691
|
if (!decideParameters || !decideParameters.audience)
|
|
692
692
|
return data;
|
|
693
|
+
console.log("Starting decide field processing with parameters:", decideParameters);
|
|
693
694
|
try {
|
|
694
695
|
return processObjectRecursively(data, decideParameters);
|
|
695
696
|
} catch (error) {
|
|
@@ -717,10 +718,25 @@ const encodeQueryString = ({
|
|
|
717
718
|
skipCrossDatasetReferenceValidation: options.skipCrossDatasetReferenceValidation
|
|
718
719
|
}), 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;
|
|
719
720
|
function _fetch(client, httpRequest, _stega, query, _params = {}, options = {}) {
|
|
721
|
+
console.log("_fetch called with:", {
|
|
722
|
+
query: query.substring(0, 100) + (query.length > 100 ? "..." : ""),
|
|
723
|
+
params: _params,
|
|
724
|
+
options: {
|
|
725
|
+
...options,
|
|
726
|
+
decideParameters: options.decideParameters
|
|
727
|
+
},
|
|
728
|
+
stegaEnabled: _stega?.enabled
|
|
729
|
+
});
|
|
720
730
|
const stega = "stega" in options ? {
|
|
721
731
|
..._stega || {},
|
|
722
732
|
...typeof options.stega == "boolean" ? { enabled: options.stega } : options.stega || {}
|
|
723
|
-
} : _stega, params = stega.enabled ? stegaClean(_params) : _params, mapResponse = options.filterResponse === !1 ? (res) => res : (res) => res.result, processDecideResponse = (response) =>
|
|
733
|
+
} : _stega, params = stega.enabled ? stegaClean(_params) : _params, mapResponse = options.filterResponse === !1 ? (res) => res : (res) => res.result, processDecideResponse = (response) => (console.log("inside processDecideResponse:", {
|
|
734
|
+
audience: options.decideParameters?.audience,
|
|
735
|
+
decideParameters: options.decideParameters?.audience
|
|
736
|
+
}), options.decideParameters && options.decideParameters.audience ? (console.log("Processing response with decideParameters:", {
|
|
737
|
+
audience: options.decideParameters.audience,
|
|
738
|
+
decideParameters: options.decideParameters
|
|
739
|
+
}), processDecideFields(response, options.decideParameters)) : response), { cache, next, ...opts } = {
|
|
724
740
|
// Opt out of setting a `signal` on an internal `fetch` if one isn't provided.
|
|
725
741
|
// This is necessary in React Server Components to avoid opting out of Request Memoization.
|
|
726
742
|
useAbortSignal: typeof options.signal < "u",
|
|
@@ -888,6 +904,18 @@ function _action(client, httpRequest, actions, options) {
|
|
|
888
904
|
);
|
|
889
905
|
}
|
|
890
906
|
function _dataRequest(client, httpRequest, endpoint, body, options = {}) {
|
|
907
|
+
console.log("_dataRequest called with:", {
|
|
908
|
+
endpoint,
|
|
909
|
+
body: endpoint === "query" ? {
|
|
910
|
+
query: body.query?.substring(0, 100) + (body.query?.length > 100 ? "..." : ""),
|
|
911
|
+
params: body.params
|
|
912
|
+
} : body,
|
|
913
|
+
options: {
|
|
914
|
+
...options,
|
|
915
|
+
decideParameters: options.decideParameters,
|
|
916
|
+
perspective: options.perspective
|
|
917
|
+
}
|
|
918
|
+
});
|
|
891
919
|
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: headers2, returnQuery, lastLiveEventId, cacheMode } = options, uri = _getDataUrl(client, endpoint, stringQuery), reqOptions = {
|
|
892
920
|
method: useGet ? "GET" : "POST",
|
|
893
921
|
uri,
|
|
@@ -910,7 +938,15 @@ function _dataRequest(client, httpRequest, endpoint, body, options = {}) {
|
|
|
910
938
|
useAbortSignal: options.useAbortSignal,
|
|
911
939
|
useCdn: options.useCdn
|
|
912
940
|
};
|
|
913
|
-
return
|
|
941
|
+
return console.log("_dataRequest calling _requestObservable with reqOptions:", {
|
|
942
|
+
...reqOptions,
|
|
943
|
+
decideParameters: reqOptions.decideParameters,
|
|
944
|
+
perspective: reqOptions.perspective,
|
|
945
|
+
body: useGet ? void 0 : endpoint === "query" ? {
|
|
946
|
+
query: body.query?.substring(0, 100) + (body.query?.length > 100 ? "..." : ""),
|
|
947
|
+
params: body.params
|
|
948
|
+
} : body
|
|
949
|
+
}), _requestObservable(client, httpRequest, reqOptions).pipe(
|
|
914
950
|
filter(isResponse),
|
|
915
951
|
map(getBody),
|
|
916
952
|
map((res) => {
|
|
@@ -934,7 +970,16 @@ function _create(client, httpRequest, doc, op, options = {}) {
|
|
|
934
970
|
}
|
|
935
971
|
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);
|
|
936
972
|
function _requestObservable(client, httpRequest, options) {
|
|
937
|
-
const uri = options.url || options.uri, config = client.config()
|
|
973
|
+
const uri = options.url || options.uri, config = client.config();
|
|
974
|
+
console.log("_requestObservable called with options:", {
|
|
975
|
+
uri,
|
|
976
|
+
method: options.method,
|
|
977
|
+
decideParameters: options.decideParameters,
|
|
978
|
+
perspective: options.perspective,
|
|
979
|
+
query: options.query,
|
|
980
|
+
configDecideParameters: config.decideParameters
|
|
981
|
+
});
|
|
982
|
+
const canUseCdn = typeof options.canUseCdn > "u" ? ["GET", "HEAD"].indexOf(options.method || "GET") >= 0 && isData(client, uri) : options.canUseCdn;
|
|
938
983
|
let useCdn = (options.useCdn ?? config.useCdn) && canUseCdn;
|
|
939
984
|
const tag = options.tag && config.requestTagPrefix ? [config.requestTagPrefix, options.tag].join(".") : options.tag || config.requestTagPrefix;
|
|
940
985
|
if (tag && options.tag !== null && (options.query = { tag: requestTag(tag), ...options.query }), ["GET", "HEAD", "POST"].indexOf(options.method || "GET") >= 0 && isQuery(client, uri)) {
|
|
@@ -947,20 +992,46 @@ function _requestObservable(client, httpRequest, options) {
|
|
|
947
992
|
}, (Array.isArray(perspectiveOption) && perspectiveOption.length > 0 || // previewDrafts was renamed to drafts, but keep for backwards compat
|
|
948
993
|
perspectiveOption === "previewDrafts" || perspectiveOption === "drafts") && useCdn && (useCdn = !1, printCdnPreviewDraftsWarning()));
|
|
949
994
|
const decideParametersOption = options.decideParameters || config.decideParameters;
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
995
|
+
if (console.log("Processing decideParameters:", {
|
|
996
|
+
optionsDecideParameters: options.decideParameters,
|
|
997
|
+
configDecideParameters: config.decideParameters,
|
|
998
|
+
finalDecideParametersOption: decideParametersOption
|
|
999
|
+
}), decideParametersOption && typeof decideParametersOption == "object") {
|
|
1000
|
+
console.log("DecideParameters received, transforming to query params:", decideParametersOption);
|
|
1001
|
+
const decideQueryParams = Object.keys(decideParametersOption).reduce(
|
|
953
1002
|
(acc, key) => (acc[`decide.${key}`] = decideParametersOption[key], acc),
|
|
954
1003
|
{}
|
|
955
|
-
)
|
|
956
|
-
|
|
1004
|
+
);
|
|
1005
|
+
console.log("DecideParameters transformed to query params:", decideQueryParams);
|
|
1006
|
+
const oldQuery = options.query;
|
|
1007
|
+
options.query = {
|
|
1008
|
+
...options.query,
|
|
1009
|
+
...decideQueryParams
|
|
1010
|
+
}, console.log("Updated query object:", {
|
|
1011
|
+
oldQuery,
|
|
1012
|
+
newQuery: options.query
|
|
1013
|
+
});
|
|
1014
|
+
} else
|
|
1015
|
+
console.log("No decideParameters to process or invalid format");
|
|
1016
|
+
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 });
|
|
957
1017
|
}
|
|
958
|
-
const
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
1018
|
+
const finalOptions = Object.assign({}, options, {
|
|
1019
|
+
url: _getUrl(client, uri, useCdn)
|
|
1020
|
+
});
|
|
1021
|
+
console.log("Final options before requestOptions call:", {
|
|
1022
|
+
url: finalOptions.url,
|
|
1023
|
+
decideParameters: finalOptions.decideParameters,
|
|
1024
|
+
query: finalOptions.query,
|
|
1025
|
+
method: finalOptions.method
|
|
1026
|
+
});
|
|
1027
|
+
const reqOptions = requestOptions(config, finalOptions);
|
|
1028
|
+
console.log("Final reqOptions from requestOptions:", {
|
|
1029
|
+
method: reqOptions.method,
|
|
1030
|
+
headers: reqOptions.headers,
|
|
1031
|
+
query: reqOptions.query
|
|
1032
|
+
// Note: URL is handled separately in the HTTP request
|
|
1033
|
+
});
|
|
1034
|
+
const request = new Observable(
|
|
964
1035
|
(subscriber) => httpRequest(reqOptions, config.requester).subscribe(subscriber)
|
|
965
1036
|
);
|
|
966
1037
|
return options.signal ? request.pipe(_withAbortSignal(options.signal)) : request;
|
|
@@ -2180,7 +2251,17 @@ class ObservableSanityClient {
|
|
|
2180
2251
|
});
|
|
2181
2252
|
}
|
|
2182
2253
|
fetch(query, params, options) {
|
|
2183
|
-
return
|
|
2254
|
+
return console.log("ObservableSanityClient.fetch called with:", {
|
|
2255
|
+
query: query.substring(0, 100) + (query.length > 100 ? "..." : ""),
|
|
2256
|
+
params,
|
|
2257
|
+
options: {
|
|
2258
|
+
...options,
|
|
2259
|
+
decideParameters: options?.decideParameters
|
|
2260
|
+
},
|
|
2261
|
+
clientConfig: {
|
|
2262
|
+
decideParameters: this.#clientConfig.decideParameters
|
|
2263
|
+
}
|
|
2264
|
+
}), _fetch(
|
|
2184
2265
|
this,
|
|
2185
2266
|
this.#httpRequest,
|
|
2186
2267
|
this.#clientConfig.stega,
|
|
@@ -2444,7 +2525,17 @@ class SanityClient {
|
|
|
2444
2525
|
});
|
|
2445
2526
|
}
|
|
2446
2527
|
fetch(query, params, options) {
|
|
2447
|
-
return
|
|
2528
|
+
return console.log("SanityClient.fetch called with:", {
|
|
2529
|
+
query: query.substring(0, 100) + (query.length > 100 ? "..." : ""),
|
|
2530
|
+
params,
|
|
2531
|
+
options: {
|
|
2532
|
+
...options,
|
|
2533
|
+
decideParameters: options?.decideParameters
|
|
2534
|
+
},
|
|
2535
|
+
clientConfig: {
|
|
2536
|
+
decideParameters: this.#clientConfig.decideParameters
|
|
2537
|
+
}
|
|
2538
|
+
}), lastValueFrom(
|
|
2448
2539
|
_fetch(
|
|
2449
2540
|
this,
|
|
2450
2541
|
this.#httpRequest,
|
|
@@ -2704,7 +2795,7 @@ function defineDeprecatedCreateClient(createClient2) {
|
|
|
2704
2795
|
return printNoDefaultExport(), createClient2(config);
|
|
2705
2796
|
};
|
|
2706
2797
|
}
|
|
2707
|
-
var name = "@sanity/client", version = "7.11.2-audience-decide.
|
|
2798
|
+
var name = "@sanity/client", version = "7.11.2-audience-decide.2";
|
|
2708
2799
|
const middleware = [
|
|
2709
2800
|
debug({ verbose: !0, namespace: "sanity:client" }),
|
|
2710
2801
|
headers({ "User-Agent": `${name} ${version}` }),
|