@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.browser.cjs
CHANGED
|
@@ -873,6 +873,7 @@ function processObjectRecursively(obj, decideParameters) {
|
|
|
873
873
|
function processDecideFields(data, decideParameters) {
|
|
874
874
|
if (!decideParameters || !decideParameters.audience)
|
|
875
875
|
return data;
|
|
876
|
+
console.log("Starting decide field processing with parameters:", decideParameters);
|
|
876
877
|
try {
|
|
877
878
|
return processObjectRecursively(data, decideParameters);
|
|
878
879
|
} catch (error) {
|
|
@@ -900,10 +901,25 @@ const encodeQueryString = ({
|
|
|
900
901
|
skipCrossDatasetReferenceValidation: options.skipCrossDatasetReferenceValidation
|
|
901
902
|
}), 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;
|
|
902
903
|
function _fetch(client, httpRequest, _stega, query, _params = {}, options = {}) {
|
|
904
|
+
console.log("_fetch called with:", {
|
|
905
|
+
query: query.substring(0, 100) + (query.length > 100 ? "..." : ""),
|
|
906
|
+
params: _params,
|
|
907
|
+
options: {
|
|
908
|
+
...options,
|
|
909
|
+
decideParameters: options.decideParameters
|
|
910
|
+
},
|
|
911
|
+
stegaEnabled: _stega?.enabled
|
|
912
|
+
});
|
|
903
913
|
const stega = "stega" in options ? {
|
|
904
914
|
..._stega || {},
|
|
905
915
|
...typeof options.stega == "boolean" ? { enabled: options.stega } : options.stega || {}
|
|
906
|
-
} : _stega, params = stega.enabled ? stegaClean.stegaClean(_params) : _params, mapResponse = options.filterResponse === !1 ? (res) => res : (res) => res.result, processDecideResponse = (response) =>
|
|
916
|
+
} : _stega, params = stega.enabled ? stegaClean.stegaClean(_params) : _params, mapResponse = options.filterResponse === !1 ? (res) => res : (res) => res.result, processDecideResponse = (response) => (console.log("inside processDecideResponse:", {
|
|
917
|
+
audience: options.decideParameters?.audience,
|
|
918
|
+
decideParameters: options.decideParameters?.audience
|
|
919
|
+
}), options.decideParameters && options.decideParameters.audience ? (console.log("Processing response with decideParameters:", {
|
|
920
|
+
audience: options.decideParameters.audience,
|
|
921
|
+
decideParameters: options.decideParameters
|
|
922
|
+
}), processDecideFields(response, options.decideParameters)) : response), { cache, next, ...opts } = {
|
|
907
923
|
// Opt out of setting a `signal` on an internal `fetch` if one isn't provided.
|
|
908
924
|
// This is necessary in React Server Components to avoid opting out of Request Memoization.
|
|
909
925
|
useAbortSignal: typeof options.signal < "u",
|
|
@@ -1073,6 +1089,18 @@ function _action(client, httpRequest, actions, options) {
|
|
|
1073
1089
|
);
|
|
1074
1090
|
}
|
|
1075
1091
|
function _dataRequest(client, httpRequest, endpoint, body, options = {}) {
|
|
1092
|
+
console.log("_dataRequest called with:", {
|
|
1093
|
+
endpoint,
|
|
1094
|
+
body: endpoint === "query" ? {
|
|
1095
|
+
query: body.query?.substring(0, 100) + (body.query?.length > 100 ? "..." : ""),
|
|
1096
|
+
params: body.params
|
|
1097
|
+
} : body,
|
|
1098
|
+
options: {
|
|
1099
|
+
...options,
|
|
1100
|
+
decideParameters: options.decideParameters,
|
|
1101
|
+
perspective: options.perspective
|
|
1102
|
+
}
|
|
1103
|
+
});
|
|
1076
1104
|
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 = {
|
|
1077
1105
|
method: useGet ? "GET" : "POST",
|
|
1078
1106
|
uri,
|
|
@@ -1095,7 +1123,15 @@ function _dataRequest(client, httpRequest, endpoint, body, options = {}) {
|
|
|
1095
1123
|
useAbortSignal: options.useAbortSignal,
|
|
1096
1124
|
useCdn: options.useCdn
|
|
1097
1125
|
};
|
|
1098
|
-
return
|
|
1126
|
+
return console.log("_dataRequest calling _requestObservable with reqOptions:", {
|
|
1127
|
+
...reqOptions,
|
|
1128
|
+
decideParameters: reqOptions.decideParameters,
|
|
1129
|
+
perspective: reqOptions.perspective,
|
|
1130
|
+
body: useGet ? void 0 : endpoint === "query" ? {
|
|
1131
|
+
query: body.query?.substring(0, 100) + (body.query?.length > 100 ? "..." : ""),
|
|
1132
|
+
params: body.params
|
|
1133
|
+
} : body
|
|
1134
|
+
}), _requestObservable(client, httpRequest, reqOptions).pipe(
|
|
1099
1135
|
operators.filter(isResponse),
|
|
1100
1136
|
operators.map(getBody),
|
|
1101
1137
|
operators.map((res) => {
|
|
@@ -1119,7 +1155,16 @@ function _create(client, httpRequest, doc, op, options = {}) {
|
|
|
1119
1155
|
}
|
|
1120
1156
|
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);
|
|
1121
1157
|
function _requestObservable(client, httpRequest, options) {
|
|
1122
|
-
const uri = options.url || options.uri, config = client.config()
|
|
1158
|
+
const uri = options.url || options.uri, config = client.config();
|
|
1159
|
+
console.log("_requestObservable called with options:", {
|
|
1160
|
+
uri,
|
|
1161
|
+
method: options.method,
|
|
1162
|
+
decideParameters: options.decideParameters,
|
|
1163
|
+
perspective: options.perspective,
|
|
1164
|
+
query: options.query,
|
|
1165
|
+
configDecideParameters: config.decideParameters
|
|
1166
|
+
});
|
|
1167
|
+
const canUseCdn = typeof options.canUseCdn > "u" ? ["GET", "HEAD"].indexOf(options.method || "GET") >= 0 && isData(client, uri) : options.canUseCdn;
|
|
1123
1168
|
let useCdn = (options.useCdn ?? config.useCdn) && canUseCdn;
|
|
1124
1169
|
const tag = options.tag && config.requestTagPrefix ? [config.requestTagPrefix, options.tag].join(".") : options.tag || config.requestTagPrefix;
|
|
1125
1170
|
if (tag && options.tag !== null && (options.query = { tag: requestTag(tag), ...options.query }), ["GET", "HEAD", "POST"].indexOf(options.method || "GET") >= 0 && isQuery(client, uri)) {
|
|
@@ -1132,20 +1177,46 @@ function _requestObservable(client, httpRequest, options) {
|
|
|
1132
1177
|
}, (Array.isArray(perspectiveOption) && perspectiveOption.length > 0 || // previewDrafts was renamed to drafts, but keep for backwards compat
|
|
1133
1178
|
perspectiveOption === "previewDrafts" || perspectiveOption === "drafts") && useCdn && (useCdn = !1, printCdnPreviewDraftsWarning()));
|
|
1134
1179
|
const decideParametersOption = options.decideParameters || config.decideParameters;
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1180
|
+
if (console.log("Processing decideParameters:", {
|
|
1181
|
+
optionsDecideParameters: options.decideParameters,
|
|
1182
|
+
configDecideParameters: config.decideParameters,
|
|
1183
|
+
finalDecideParametersOption: decideParametersOption
|
|
1184
|
+
}), decideParametersOption && typeof decideParametersOption == "object") {
|
|
1185
|
+
console.log("DecideParameters received, transforming to query params:", decideParametersOption);
|
|
1186
|
+
const decideQueryParams = Object.keys(decideParametersOption).reduce(
|
|
1138
1187
|
(acc, key) => (acc[`decide.${key}`] = decideParametersOption[key], acc),
|
|
1139
1188
|
{}
|
|
1140
|
-
)
|
|
1141
|
-
|
|
1189
|
+
);
|
|
1190
|
+
console.log("DecideParameters transformed to query params:", decideQueryParams);
|
|
1191
|
+
const oldQuery = options.query;
|
|
1192
|
+
options.query = {
|
|
1193
|
+
...options.query,
|
|
1194
|
+
...decideQueryParams
|
|
1195
|
+
}, console.log("Updated query object:", {
|
|
1196
|
+
oldQuery,
|
|
1197
|
+
newQuery: options.query
|
|
1198
|
+
});
|
|
1199
|
+
} else
|
|
1200
|
+
console.log("No decideParameters to process or invalid format");
|
|
1201
|
+
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 });
|
|
1142
1202
|
}
|
|
1143
|
-
const
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1203
|
+
const finalOptions = Object.assign({}, options, {
|
|
1204
|
+
url: _getUrl(client, uri, useCdn)
|
|
1205
|
+
});
|
|
1206
|
+
console.log("Final options before requestOptions call:", {
|
|
1207
|
+
url: finalOptions.url,
|
|
1208
|
+
decideParameters: finalOptions.decideParameters,
|
|
1209
|
+
query: finalOptions.query,
|
|
1210
|
+
method: finalOptions.method
|
|
1211
|
+
});
|
|
1212
|
+
const reqOptions = requestOptions(config, finalOptions);
|
|
1213
|
+
console.log("Final reqOptions from requestOptions:", {
|
|
1214
|
+
method: reqOptions.method,
|
|
1215
|
+
headers: reqOptions.headers,
|
|
1216
|
+
query: reqOptions.query
|
|
1217
|
+
// Note: URL is handled separately in the HTTP request
|
|
1218
|
+
});
|
|
1219
|
+
const request = new rxjs.Observable(
|
|
1149
1220
|
(subscriber) => httpRequest(reqOptions, config.requester).subscribe(subscriber)
|
|
1150
1221
|
);
|
|
1151
1222
|
return options.signal ? request.pipe(_withAbortSignal(options.signal)) : request;
|
|
@@ -2365,7 +2436,17 @@ class ObservableSanityClient {
|
|
|
2365
2436
|
});
|
|
2366
2437
|
}
|
|
2367
2438
|
fetch(query, params, options) {
|
|
2368
|
-
return
|
|
2439
|
+
return console.log("ObservableSanityClient.fetch called with:", {
|
|
2440
|
+
query: query.substring(0, 100) + (query.length > 100 ? "..." : ""),
|
|
2441
|
+
params,
|
|
2442
|
+
options: {
|
|
2443
|
+
...options,
|
|
2444
|
+
decideParameters: options?.decideParameters
|
|
2445
|
+
},
|
|
2446
|
+
clientConfig: {
|
|
2447
|
+
decideParameters: this.#clientConfig.decideParameters
|
|
2448
|
+
}
|
|
2449
|
+
}), _fetch(
|
|
2369
2450
|
this,
|
|
2370
2451
|
this.#httpRequest,
|
|
2371
2452
|
this.#clientConfig.stega,
|
|
@@ -2629,7 +2710,17 @@ class SanityClient {
|
|
|
2629
2710
|
});
|
|
2630
2711
|
}
|
|
2631
2712
|
fetch(query, params, options) {
|
|
2632
|
-
return
|
|
2713
|
+
return console.log("SanityClient.fetch called with:", {
|
|
2714
|
+
query: query.substring(0, 100) + (query.length > 100 ? "..." : ""),
|
|
2715
|
+
params,
|
|
2716
|
+
options: {
|
|
2717
|
+
...options,
|
|
2718
|
+
decideParameters: options?.decideParameters
|
|
2719
|
+
},
|
|
2720
|
+
clientConfig: {
|
|
2721
|
+
decideParameters: this.#clientConfig.decideParameters
|
|
2722
|
+
}
|
|
2723
|
+
}), rxjs.lastValueFrom(
|
|
2633
2724
|
_fetch(
|
|
2634
2725
|
this,
|
|
2635
2726
|
this.#httpRequest,
|