@sanity/client 7.6.0 → 7.8.0
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/_chunks-cjs/config.cjs +3 -0
- package/dist/_chunks-cjs/config.cjs.map +1 -1
- package/dist/_chunks-es/config.js +3 -0
- package/dist/_chunks-es/config.js.map +1 -1
- package/dist/index.browser.cjs +63 -10
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.d.cts +115 -24
- package/dist/index.browser.d.ts +115 -24
- package/dist/index.browser.js +63 -10
- package/dist/index.browser.js.map +1 -1
- package/dist/index.cjs +62 -10
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +115 -24
- package/dist/index.d.ts +115 -24
- package/dist/index.js +63 -11
- package/dist/index.js.map +1 -1
- package/dist/stega.browser.d.cts +115 -24
- package/dist/stega.browser.d.ts +115 -24
- package/dist/stega.d.cts +115 -24
- package/dist/stega.d.ts +115 -24
- package/package.json +1 -1
- package/src/SanityClient.ts +61 -21
- package/src/data/dataMethods.ts +39 -2
- package/src/defineCreateClient.ts +5 -1
- package/src/http/errors.ts +53 -0
- package/src/http/request.ts +31 -3
- package/src/types.ts +62 -5
- package/src/warnings.ts +4 -0
- package/umd/sanityClient.js +63 -10
- package/umd/sanityClient.min.js +2 -2
package/umd/sanityClient.js
CHANGED
|
@@ -2049,6 +2049,12 @@
|
|
|
2049
2049
|
};
|
|
2050
2050
|
}
|
|
2051
2051
|
const MAX_ITEMS_IN_ERROR_MESSAGE = 5;
|
|
2052
|
+
function isHttpError(error) {
|
|
2053
|
+
if (!isRecord(error))
|
|
2054
|
+
return false;
|
|
2055
|
+
const response = error.response;
|
|
2056
|
+
return !(typeof error.statusCode != "number" || typeof error.message != "string" || !isRecord(response) || typeof response.body > "u" || typeof response.url != "string" || typeof response.method != "string" || typeof response.headers != "object" || typeof response.statusCode != "number");
|
|
2057
|
+
}
|
|
2052
2058
|
class ClientError extends Error {
|
|
2053
2059
|
response;
|
|
2054
2060
|
statusCode = 400;
|
|
@@ -2149,22 +2155,22 @@ ${codeFrame(query, { start, end }, description)}${withTag}`;
|
|
|
2149
2155
|
return res;
|
|
2150
2156
|
}
|
|
2151
2157
|
};
|
|
2152
|
-
function printWarnings() {
|
|
2153
|
-
const seen = {};
|
|
2158
|
+
function printWarnings(config = {}) {
|
|
2159
|
+
const seen = {}, shouldIgnoreWarning = (message) => config.ignoreWarnings === void 0 ? false : (Array.isArray(config.ignoreWarnings) ? config.ignoreWarnings : [config.ignoreWarnings]).some((pattern) => typeof pattern == "string" ? message.includes(pattern) : pattern instanceof RegExp ? pattern.test(message) : false);
|
|
2154
2160
|
return {
|
|
2155
2161
|
onResponse: (res) => {
|
|
2156
2162
|
const warn = res.headers["x-sanity-warning"], warnings = Array.isArray(warn) ? warn : [warn];
|
|
2157
2163
|
for (const msg of warnings)
|
|
2158
|
-
!msg || seen[msg] || (seen[msg] = true, console.warn(msg));
|
|
2164
|
+
!msg || seen[msg] || shouldIgnoreWarning(msg) || (seen[msg] = true, console.warn(msg));
|
|
2159
2165
|
return res;
|
|
2160
2166
|
}
|
|
2161
2167
|
};
|
|
2162
2168
|
}
|
|
2163
|
-
function defineHttpRequest(envMiddleware2) {
|
|
2169
|
+
function defineHttpRequest(envMiddleware2, config = {}) {
|
|
2164
2170
|
return p$1([
|
|
2165
2171
|
P({ shouldRetry }),
|
|
2166
2172
|
...envMiddleware2,
|
|
2167
|
-
printWarnings(),
|
|
2173
|
+
printWarnings(config),
|
|
2168
2174
|
x(),
|
|
2169
2175
|
E$1(),
|
|
2170
2176
|
S$1(),
|
|
@@ -2254,7 +2260,7 @@ ${codeFrame(query, { start, end }, description)}${withTag}`;
|
|
|
2254
2260
|
}, resourceGuard = (service, config) => {
|
|
2255
2261
|
if (config["~experimental_resource"])
|
|
2256
2262
|
throw new Error(`\`${service}\` does not support resource-based operations`);
|
|
2257
|
-
};
|
|
2263
|
+
}, EXPERIMENTAL_API_WARNING = "This is an experimental API version";
|
|
2258
2264
|
function once(fn) {
|
|
2259
2265
|
let didCall = false, returnValue;
|
|
2260
2266
|
return (...args) => (didCall || (returnValue = fn(...args), didCall = true), returnValue);
|
|
@@ -2287,6 +2293,8 @@ ${codeFrame(query, { start, end }, description)}${withTag}`;
|
|
|
2287
2293
|
`See ${generateHelpUrl("js-client-api-version")}`
|
|
2288
2294
|
]), printNoDefaultExport = createWarningPrinter([
|
|
2289
2295
|
"The default export of @sanity/client has been deprecated. Use the named export `createClient` instead."
|
|
2296
|
+
]), printCreateVersionWithBaseIdWarning = createWarningPrinter([
|
|
2297
|
+
"You have called `createVersion()` with a defined `document`. The recommended approach is to provide a `baseId` and `releaseId` instead."
|
|
2290
2298
|
]), defaultCdnHost = "apicdn.sanity.io", defaultConfig = {
|
|
2291
2299
|
apiHost: "https://api.sanity.io",
|
|
2292
2300
|
apiVersion: "1",
|
|
@@ -2922,12 +2930,27 @@ ${selectionOpts}`);
|
|
|
2922
2930
|
return requireDocumentId("createOrReplace", doc), _create(client, httpRequest, doc, "createOrReplace", options);
|
|
2923
2931
|
}
|
|
2924
2932
|
function _createVersion(client, httpRequest, doc, publishedId, options) {
|
|
2925
|
-
return requireDocumentId("createVersion", doc), requireDocumentType("createVersion", doc), _action(client, httpRequest, {
|
|
2933
|
+
return requireDocumentId("createVersion", doc), requireDocumentType("createVersion", doc), printCreateVersionWithBaseIdWarning(), _action(client, httpRequest, {
|
|
2926
2934
|
actionType: "sanity.action.document.version.create",
|
|
2927
2935
|
publishedId,
|
|
2928
2936
|
document: doc
|
|
2929
2937
|
}, options);
|
|
2930
2938
|
}
|
|
2939
|
+
function _createVersionFromBase(client, httpRequest, publishedId, baseId, releaseId, ifBaseRevisionId, options) {
|
|
2940
|
+
if (!baseId)
|
|
2941
|
+
throw new Error("`createVersion()` requires `baseId` when no `document` is provided");
|
|
2942
|
+
if (!publishedId)
|
|
2943
|
+
throw new Error("`createVersion()` requires `publishedId` when `baseId` is provided");
|
|
2944
|
+
validateDocumentId("createVersion", baseId), validateDocumentId("createVersion", publishedId);
|
|
2945
|
+
const createVersionAction = {
|
|
2946
|
+
actionType: "sanity.action.document.version.create",
|
|
2947
|
+
publishedId,
|
|
2948
|
+
baseId,
|
|
2949
|
+
versionId: releaseId ? getVersionId(publishedId, releaseId) : getDraftId(publishedId),
|
|
2950
|
+
ifBaseRevisionId
|
|
2951
|
+
};
|
|
2952
|
+
return _action(client, httpRequest, createVersionAction, options);
|
|
2953
|
+
}
|
|
2931
2954
|
function _delete(client, httpRequest, selection, options) {
|
|
2932
2955
|
return _dataRequest(
|
|
2933
2956
|
client,
|
|
@@ -4213,8 +4236,20 @@ ${selectionOpts}`);
|
|
|
4213
4236
|
createVersion({
|
|
4214
4237
|
document,
|
|
4215
4238
|
publishedId,
|
|
4216
|
-
releaseId
|
|
4239
|
+
releaseId,
|
|
4240
|
+
baseId,
|
|
4241
|
+
ifBaseRevisionId
|
|
4217
4242
|
}, options) {
|
|
4243
|
+
if (!document)
|
|
4244
|
+
return _createVersionFromBase(
|
|
4245
|
+
this,
|
|
4246
|
+
this.#httpRequest,
|
|
4247
|
+
publishedId,
|
|
4248
|
+
baseId,
|
|
4249
|
+
releaseId,
|
|
4250
|
+
ifBaseRevisionId,
|
|
4251
|
+
options
|
|
4252
|
+
);
|
|
4218
4253
|
const documentVersionId = deriveDocumentVersionId("createVersion", {
|
|
4219
4254
|
document,
|
|
4220
4255
|
publishedId,
|
|
@@ -4465,8 +4500,22 @@ ${selectionOpts}`);
|
|
|
4465
4500
|
createVersion({
|
|
4466
4501
|
document,
|
|
4467
4502
|
publishedId,
|
|
4468
|
-
releaseId
|
|
4503
|
+
releaseId,
|
|
4504
|
+
baseId,
|
|
4505
|
+
ifBaseRevisionId
|
|
4469
4506
|
}, options) {
|
|
4507
|
+
if (!document)
|
|
4508
|
+
return firstValueFrom(
|
|
4509
|
+
_createVersionFromBase(
|
|
4510
|
+
this,
|
|
4511
|
+
this.#httpRequest,
|
|
4512
|
+
publishedId,
|
|
4513
|
+
baseId,
|
|
4514
|
+
releaseId,
|
|
4515
|
+
ifBaseRevisionId,
|
|
4516
|
+
options
|
|
4517
|
+
)
|
|
4518
|
+
);
|
|
4470
4519
|
const documentVersionId = deriveDocumentVersionId("createVersion", {
|
|
4471
4520
|
document,
|
|
4472
4521
|
publishedId,
|
|
@@ -4635,7 +4684,9 @@ ${selectionOpts}`);
|
|
|
4635
4684
|
}
|
|
4636
4685
|
function defineCreateClientExports(envMiddleware2, ClassConstructor) {
|
|
4637
4686
|
return { requester: defineHttpRequest(envMiddleware2), createClient: (config) => {
|
|
4638
|
-
const clientRequester = defineHttpRequest(envMiddleware2
|
|
4687
|
+
const clientRequester = defineHttpRequest(envMiddleware2, {
|
|
4688
|
+
ignoreWarnings: config.ignoreWarnings
|
|
4689
|
+
});
|
|
4639
4690
|
return new ClassConstructor(
|
|
4640
4691
|
(options, requester2) => (requester2 || clientRequester)({
|
|
4641
4692
|
maxRedirects: 0,
|
|
@@ -6095,6 +6146,7 @@ ${selectionOpts}`);
|
|
|
6095
6146
|
exports.ConnectionFailedError = ConnectionFailedError;
|
|
6096
6147
|
exports.CorsOriginError = CorsOriginError;
|
|
6097
6148
|
exports.DisconnectError = DisconnectError;
|
|
6149
|
+
exports.EXPERIMENTAL_API_WARNING = EXPERIMENTAL_API_WARNING;
|
|
6098
6150
|
exports.MessageError = MessageError;
|
|
6099
6151
|
exports.MessageParseError = MessageParseError;
|
|
6100
6152
|
exports.ObservablePatch = ObservablePatch;
|
|
@@ -6108,6 +6160,7 @@ ${selectionOpts}`);
|
|
|
6108
6160
|
exports.createClient = createClient;
|
|
6109
6161
|
exports.default = deprecatedCreateClient;
|
|
6110
6162
|
exports.formatQueryParseError = formatQueryParseError;
|
|
6163
|
+
exports.isHttpError = isHttpError;
|
|
6111
6164
|
exports.isQueryParseError = isQueryParseError;
|
|
6112
6165
|
exports.requester = requester;
|
|
6113
6166
|
exports.unstable__adapter = c$2;
|