@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.js
CHANGED
|
@@ -859,6 +859,7 @@ function processObjectRecursively(obj, decideParameters) {
|
|
|
859
859
|
function processDecideFields(data, decideParameters) {
|
|
860
860
|
if (!decideParameters || !decideParameters.audience)
|
|
861
861
|
return data;
|
|
862
|
+
console.log("Starting decide field processing with parameters:", decideParameters);
|
|
862
863
|
try {
|
|
863
864
|
return processObjectRecursively(data, decideParameters);
|
|
864
865
|
} catch (error) {
|
|
@@ -886,10 +887,25 @@ const encodeQueryString = ({
|
|
|
886
887
|
skipCrossDatasetReferenceValidation: options.skipCrossDatasetReferenceValidation
|
|
887
888
|
}), 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;
|
|
888
889
|
function _fetch(client, httpRequest, _stega, query, _params = {}, options = {}) {
|
|
890
|
+
console.log("_fetch called with:", {
|
|
891
|
+
query: query.substring(0, 100) + (query.length > 100 ? "..." : ""),
|
|
892
|
+
params: _params,
|
|
893
|
+
options: {
|
|
894
|
+
...options,
|
|
895
|
+
decideParameters: options.decideParameters
|
|
896
|
+
},
|
|
897
|
+
stegaEnabled: _stega?.enabled
|
|
898
|
+
});
|
|
889
899
|
const stega = "stega" in options ? {
|
|
890
900
|
..._stega || {},
|
|
891
901
|
...typeof options.stega == "boolean" ? { enabled: options.stega } : options.stega || {}
|
|
892
|
-
} : _stega, params = stega.enabled ? stegaClean(_params) : _params, mapResponse = options.filterResponse === !1 ? (res) => res : (res) => res.result, processDecideResponse = (response) =>
|
|
902
|
+
} : _stega, params = stega.enabled ? stegaClean(_params) : _params, mapResponse = options.filterResponse === !1 ? (res) => res : (res) => res.result, processDecideResponse = (response) => (console.log("inside processDecideResponse:", {
|
|
903
|
+
audience: options.decideParameters?.audience,
|
|
904
|
+
decideParameters: options.decideParameters?.audience
|
|
905
|
+
}), options.decideParameters && options.decideParameters.audience ? (console.log("Processing response with decideParameters:", {
|
|
906
|
+
audience: options.decideParameters.audience,
|
|
907
|
+
decideParameters: options.decideParameters
|
|
908
|
+
}), processDecideFields(response, options.decideParameters)) : response), { cache, next, ...opts } = {
|
|
893
909
|
// Opt out of setting a `signal` on an internal `fetch` if one isn't provided.
|
|
894
910
|
// This is necessary in React Server Components to avoid opting out of Request Memoization.
|
|
895
911
|
useAbortSignal: typeof options.signal < "u",
|
|
@@ -1057,6 +1073,18 @@ function _action(client, httpRequest, actions, options) {
|
|
|
1057
1073
|
);
|
|
1058
1074
|
}
|
|
1059
1075
|
function _dataRequest(client, httpRequest, endpoint, body, options = {}) {
|
|
1076
|
+
console.log("_dataRequest called with:", {
|
|
1077
|
+
endpoint,
|
|
1078
|
+
body: endpoint === "query" ? {
|
|
1079
|
+
query: body.query?.substring(0, 100) + (body.query?.length > 100 ? "..." : ""),
|
|
1080
|
+
params: body.params
|
|
1081
|
+
} : body,
|
|
1082
|
+
options: {
|
|
1083
|
+
...options,
|
|
1084
|
+
decideParameters: options.decideParameters,
|
|
1085
|
+
perspective: options.perspective
|
|
1086
|
+
}
|
|
1087
|
+
});
|
|
1060
1088
|
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 = {
|
|
1061
1089
|
method: useGet ? "GET" : "POST",
|
|
1062
1090
|
uri,
|
|
@@ -1079,7 +1107,15 @@ function _dataRequest(client, httpRequest, endpoint, body, options = {}) {
|
|
|
1079
1107
|
useAbortSignal: options.useAbortSignal,
|
|
1080
1108
|
useCdn: options.useCdn
|
|
1081
1109
|
};
|
|
1082
|
-
return
|
|
1110
|
+
return console.log("_dataRequest calling _requestObservable with reqOptions:", {
|
|
1111
|
+
...reqOptions,
|
|
1112
|
+
decideParameters: reqOptions.decideParameters,
|
|
1113
|
+
perspective: reqOptions.perspective,
|
|
1114
|
+
body: useGet ? void 0 : endpoint === "query" ? {
|
|
1115
|
+
query: body.query?.substring(0, 100) + (body.query?.length > 100 ? "..." : ""),
|
|
1116
|
+
params: body.params
|
|
1117
|
+
} : body
|
|
1118
|
+
}), _requestObservable(client, httpRequest, reqOptions).pipe(
|
|
1083
1119
|
filter(isResponse),
|
|
1084
1120
|
map(getBody),
|
|
1085
1121
|
map((res) => {
|
|
@@ -1103,7 +1139,16 @@ function _create(client, httpRequest, doc, op, options = {}) {
|
|
|
1103
1139
|
}
|
|
1104
1140
|
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);
|
|
1105
1141
|
function _requestObservable(client, httpRequest, options) {
|
|
1106
|
-
const uri = options.url || options.uri, config = client.config()
|
|
1142
|
+
const uri = options.url || options.uri, config = client.config();
|
|
1143
|
+
console.log("_requestObservable called with options:", {
|
|
1144
|
+
uri,
|
|
1145
|
+
method: options.method,
|
|
1146
|
+
decideParameters: options.decideParameters,
|
|
1147
|
+
perspective: options.perspective,
|
|
1148
|
+
query: options.query,
|
|
1149
|
+
configDecideParameters: config.decideParameters
|
|
1150
|
+
});
|
|
1151
|
+
const canUseCdn = typeof options.canUseCdn > "u" ? ["GET", "HEAD"].indexOf(options.method || "GET") >= 0 && isData(client, uri) : options.canUseCdn;
|
|
1107
1152
|
let useCdn = (options.useCdn ?? config.useCdn) && canUseCdn;
|
|
1108
1153
|
const tag = options.tag && config.requestTagPrefix ? [config.requestTagPrefix, options.tag].join(".") : options.tag || config.requestTagPrefix;
|
|
1109
1154
|
if (tag && options.tag !== null && (options.query = { tag: requestTag(tag), ...options.query }), ["GET", "HEAD", "POST"].indexOf(options.method || "GET") >= 0 && isQuery(client, uri)) {
|
|
@@ -1116,20 +1161,46 @@ function _requestObservable(client, httpRequest, options) {
|
|
|
1116
1161
|
}, (Array.isArray(perspectiveOption) && perspectiveOption.length > 0 || // previewDrafts was renamed to drafts, but keep for backwards compat
|
|
1117
1162
|
perspectiveOption === "previewDrafts" || perspectiveOption === "drafts") && useCdn && (useCdn = !1, printCdnPreviewDraftsWarning()));
|
|
1118
1163
|
const decideParametersOption = options.decideParameters || config.decideParameters;
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1164
|
+
if (console.log("Processing decideParameters:", {
|
|
1165
|
+
optionsDecideParameters: options.decideParameters,
|
|
1166
|
+
configDecideParameters: config.decideParameters,
|
|
1167
|
+
finalDecideParametersOption: decideParametersOption
|
|
1168
|
+
}), decideParametersOption && typeof decideParametersOption == "object") {
|
|
1169
|
+
console.log("DecideParameters received, transforming to query params:", decideParametersOption);
|
|
1170
|
+
const decideQueryParams = Object.keys(decideParametersOption).reduce(
|
|
1122
1171
|
(acc, key) => (acc[`decide.${key}`] = decideParametersOption[key], acc),
|
|
1123
1172
|
{}
|
|
1124
|
-
)
|
|
1125
|
-
|
|
1173
|
+
);
|
|
1174
|
+
console.log("DecideParameters transformed to query params:", decideQueryParams);
|
|
1175
|
+
const oldQuery = options.query;
|
|
1176
|
+
options.query = {
|
|
1177
|
+
...options.query,
|
|
1178
|
+
...decideQueryParams
|
|
1179
|
+
}, console.log("Updated query object:", {
|
|
1180
|
+
oldQuery,
|
|
1181
|
+
newQuery: options.query
|
|
1182
|
+
});
|
|
1183
|
+
} else
|
|
1184
|
+
console.log("No decideParameters to process or invalid format");
|
|
1185
|
+
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 });
|
|
1126
1186
|
}
|
|
1127
|
-
const
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1187
|
+
const finalOptions = Object.assign({}, options, {
|
|
1188
|
+
url: _getUrl(client, uri, useCdn)
|
|
1189
|
+
});
|
|
1190
|
+
console.log("Final options before requestOptions call:", {
|
|
1191
|
+
url: finalOptions.url,
|
|
1192
|
+
decideParameters: finalOptions.decideParameters,
|
|
1193
|
+
query: finalOptions.query,
|
|
1194
|
+
method: finalOptions.method
|
|
1195
|
+
});
|
|
1196
|
+
const reqOptions = requestOptions(config, finalOptions);
|
|
1197
|
+
console.log("Final reqOptions from requestOptions:", {
|
|
1198
|
+
method: reqOptions.method,
|
|
1199
|
+
headers: reqOptions.headers,
|
|
1200
|
+
query: reqOptions.query
|
|
1201
|
+
// Note: URL is handled separately in the HTTP request
|
|
1202
|
+
});
|
|
1203
|
+
const request = new Observable(
|
|
1133
1204
|
(subscriber) => httpRequest(reqOptions, config.requester).subscribe(subscriber)
|
|
1134
1205
|
);
|
|
1135
1206
|
return options.signal ? request.pipe(_withAbortSignal(options.signal)) : request;
|
|
@@ -2349,7 +2420,17 @@ class ObservableSanityClient {
|
|
|
2349
2420
|
});
|
|
2350
2421
|
}
|
|
2351
2422
|
fetch(query, params, options) {
|
|
2352
|
-
return
|
|
2423
|
+
return console.log("ObservableSanityClient.fetch called with:", {
|
|
2424
|
+
query: query.substring(0, 100) + (query.length > 100 ? "..." : ""),
|
|
2425
|
+
params,
|
|
2426
|
+
options: {
|
|
2427
|
+
...options,
|
|
2428
|
+
decideParameters: options?.decideParameters
|
|
2429
|
+
},
|
|
2430
|
+
clientConfig: {
|
|
2431
|
+
decideParameters: this.#clientConfig.decideParameters
|
|
2432
|
+
}
|
|
2433
|
+
}), _fetch(
|
|
2353
2434
|
this,
|
|
2354
2435
|
this.#httpRequest,
|
|
2355
2436
|
this.#clientConfig.stega,
|
|
@@ -2613,7 +2694,17 @@ class SanityClient {
|
|
|
2613
2694
|
});
|
|
2614
2695
|
}
|
|
2615
2696
|
fetch(query, params, options) {
|
|
2616
|
-
return
|
|
2697
|
+
return console.log("SanityClient.fetch called with:", {
|
|
2698
|
+
query: query.substring(0, 100) + (query.length > 100 ? "..." : ""),
|
|
2699
|
+
params,
|
|
2700
|
+
options: {
|
|
2701
|
+
...options,
|
|
2702
|
+
decideParameters: options?.decideParameters
|
|
2703
|
+
},
|
|
2704
|
+
clientConfig: {
|
|
2705
|
+
decideParameters: this.#clientConfig.decideParameters
|
|
2706
|
+
}
|
|
2707
|
+
}), lastValueFrom(
|
|
2617
2708
|
_fetch(
|
|
2618
2709
|
this,
|
|
2619
2710
|
this.#httpRequest,
|