@sanity/client 7.11.2-audience-decide.1 → 7.11.2-audience-decide.3
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 +95 -25
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.js +95 -25
- package/dist/index.browser.js.map +1 -1
- package/dist/index.cjs +96 -26
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +96 -26
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/SanityClient.ts +26 -0
- package/src/data/dataMethods.ts +100 -23
- package/umd/sanityClient.js +95 -25
- package/umd/sanityClient.min.js +2 -2
package/dist/index.browser.cjs
CHANGED
|
@@ -901,13 +901,25 @@ const encodeQueryString = ({
|
|
|
901
901
|
skipCrossDatasetReferenceValidation: options.skipCrossDatasetReferenceValidation
|
|
902
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;
|
|
903
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
|
+
});
|
|
904
913
|
const stega = "stega" in options ? {
|
|
905
914
|
..._stega || {},
|
|
906
915
|
...typeof options.stega == "boolean" ? { enabled: options.stega } : options.stega || {}
|
|
907
|
-
} : _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:", {
|
|
908
920
|
audience: options.decideParameters.audience,
|
|
909
921
|
decideParameters: options.decideParameters
|
|
910
|
-
}), processDecideFields(response, options.decideParameters)) : response, { cache, next, ...opts } = {
|
|
922
|
+
}), processDecideFields(response, options.decideParameters)) : response), { cache, next, ...opts } = {
|
|
911
923
|
// Opt out of setting a `signal` on an internal `fetch` if one isn't provided.
|
|
912
924
|
// This is necessary in React Server Components to avoid opting out of Request Memoization.
|
|
913
925
|
useAbortSignal: typeof options.signal < "u",
|
|
@@ -1077,6 +1089,18 @@ function _action(client, httpRequest, actions, options) {
|
|
|
1077
1089
|
);
|
|
1078
1090
|
}
|
|
1079
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
|
+
});
|
|
1080
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 = {
|
|
1081
1105
|
method: useGet ? "GET" : "POST",
|
|
1082
1106
|
uri,
|
|
@@ -1099,7 +1123,15 @@ function _dataRequest(client, httpRequest, endpoint, body, options = {}) {
|
|
|
1099
1123
|
useAbortSignal: options.useAbortSignal,
|
|
1100
1124
|
useCdn: options.useCdn
|
|
1101
1125
|
};
|
|
1102
|
-
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(
|
|
1103
1135
|
operators.filter(isResponse),
|
|
1104
1136
|
operators.map(getBody),
|
|
1105
1137
|
operators.map((res) => {
|
|
@@ -1123,7 +1155,16 @@ function _create(client, httpRequest, doc, op, options = {}) {
|
|
|
1123
1155
|
}
|
|
1124
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);
|
|
1125
1157
|
function _requestObservable(client, httpRequest, options) {
|
|
1126
|
-
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;
|
|
1127
1168
|
let useCdn = (options.useCdn ?? config.useCdn) && canUseCdn;
|
|
1128
1169
|
const tag = options.tag && config.requestTagPrefix ? [config.requestTagPrefix, options.tag].join(".") : options.tag || config.requestTagPrefix;
|
|
1129
1170
|
if (tag && options.tag !== null && (options.query = { tag: requestTag(tag), ...options.query }), ["GET", "HEAD", "POST"].indexOf(options.method || "GET") >= 0 && isQuery(client, uri)) {
|
|
@@ -1136,25 +1177,34 @@ function _requestObservable(client, httpRequest, options) {
|
|
|
1136
1177
|
}, (Array.isArray(perspectiveOption) && perspectiveOption.length > 0 || // previewDrafts was renamed to drafts, but keep for backwards compat
|
|
1137
1178
|
perspectiveOption === "previewDrafts" || perspectiveOption === "drafts") && useCdn && (useCdn = !1, printCdnPreviewDraftsWarning()));
|
|
1138
1179
|
const decideParametersOption = options.decideParameters || config.decideParameters;
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1180
|
+
console.log("Processing decideParameters:", {
|
|
1181
|
+
optionsDecideParameters: options.decideParameters,
|
|
1182
|
+
configDecideParameters: config.decideParameters,
|
|
1183
|
+
finalDecideParametersOption: decideParametersOption
|
|
1184
|
+
}), decideParametersOption && typeof decideParametersOption == "object" ? (console.log(
|
|
1185
|
+
"DecideParameters received - keeping for response processing only:",
|
|
1186
|
+
decideParametersOption
|
|
1187
|
+
), console.log(
|
|
1188
|
+
"DecideParameters will be preserved for response processing but not sent in HTTP request"
|
|
1189
|
+
)) : console.log("No decideParameters to process or invalid format"), 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 });
|
|
1190
|
+
}
|
|
1191
|
+
const finalOptions = Object.assign({}, options, {
|
|
1192
|
+
url: _getUrl(client, uri, useCdn)
|
|
1193
|
+
});
|
|
1194
|
+
console.log("Final options before requestOptions call:", {
|
|
1195
|
+
url: finalOptions.url,
|
|
1196
|
+
decideParameters: finalOptions.decideParameters,
|
|
1197
|
+
query: finalOptions.query,
|
|
1198
|
+
method: finalOptions.method
|
|
1199
|
+
});
|
|
1200
|
+
const reqOptions = requestOptions(config, finalOptions);
|
|
1201
|
+
console.log("Final reqOptions from requestOptions:", {
|
|
1202
|
+
method: reqOptions.method,
|
|
1203
|
+
headers: reqOptions.headers,
|
|
1204
|
+
query: reqOptions.query
|
|
1205
|
+
// Note: URL is handled separately in the HTTP request
|
|
1206
|
+
});
|
|
1207
|
+
const request = new rxjs.Observable(
|
|
1158
1208
|
(subscriber) => httpRequest(reqOptions, config.requester).subscribe(subscriber)
|
|
1159
1209
|
);
|
|
1160
1210
|
return options.signal ? request.pipe(_withAbortSignal(options.signal)) : request;
|
|
@@ -2374,7 +2424,17 @@ class ObservableSanityClient {
|
|
|
2374
2424
|
});
|
|
2375
2425
|
}
|
|
2376
2426
|
fetch(query, params, options) {
|
|
2377
|
-
return
|
|
2427
|
+
return console.log("ObservableSanityClient.fetch called with:", {
|
|
2428
|
+
query: query.substring(0, 100) + (query.length > 100 ? "..." : ""),
|
|
2429
|
+
params,
|
|
2430
|
+
options: {
|
|
2431
|
+
...options,
|
|
2432
|
+
decideParameters: options?.decideParameters
|
|
2433
|
+
},
|
|
2434
|
+
clientConfig: {
|
|
2435
|
+
decideParameters: this.#clientConfig.decideParameters
|
|
2436
|
+
}
|
|
2437
|
+
}), _fetch(
|
|
2378
2438
|
this,
|
|
2379
2439
|
this.#httpRequest,
|
|
2380
2440
|
this.#clientConfig.stega,
|
|
@@ -2638,7 +2698,17 @@ class SanityClient {
|
|
|
2638
2698
|
});
|
|
2639
2699
|
}
|
|
2640
2700
|
fetch(query, params, options) {
|
|
2641
|
-
return
|
|
2701
|
+
return console.log("SanityClient.fetch called with:", {
|
|
2702
|
+
query: query.substring(0, 100) + (query.length > 100 ? "..." : ""),
|
|
2703
|
+
params,
|
|
2704
|
+
options: {
|
|
2705
|
+
...options,
|
|
2706
|
+
decideParameters: options?.decideParameters
|
|
2707
|
+
},
|
|
2708
|
+
clientConfig: {
|
|
2709
|
+
decideParameters: this.#clientConfig.decideParameters
|
|
2710
|
+
}
|
|
2711
|
+
}), rxjs.lastValueFrom(
|
|
2642
2712
|
_fetch(
|
|
2643
2713
|
this,
|
|
2644
2714
|
this.#httpRequest,
|