@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/dist/index.cjs
CHANGED
|
@@ -89,6 +89,12 @@ function columnToLine(column, lines) {
|
|
|
89
89
|
};
|
|
90
90
|
}
|
|
91
91
|
const MAX_ITEMS_IN_ERROR_MESSAGE = 5;
|
|
92
|
+
function isHttpError(error) {
|
|
93
|
+
if (!isRecord.isRecord(error))
|
|
94
|
+
return !1;
|
|
95
|
+
const response = error.response;
|
|
96
|
+
return !(typeof error.statusCode != "number" || typeof error.message != "string" || !isRecord.isRecord(response) || typeof response.body > "u" || typeof response.url != "string" || typeof response.method != "string" || typeof response.headers != "object" || typeof response.statusCode != "number");
|
|
97
|
+
}
|
|
92
98
|
class ClientError extends Error {
|
|
93
99
|
response;
|
|
94
100
|
statusCode = 400;
|
|
@@ -189,22 +195,22 @@ const httpError = {
|
|
|
189
195
|
return res;
|
|
190
196
|
}
|
|
191
197
|
};
|
|
192
|
-
function printWarnings() {
|
|
193
|
-
const seen = {};
|
|
198
|
+
function printWarnings(config2 = {}) {
|
|
199
|
+
const seen = {}, shouldIgnoreWarning = (message) => config2.ignoreWarnings === void 0 ? !1 : (Array.isArray(config2.ignoreWarnings) ? config2.ignoreWarnings : [config2.ignoreWarnings]).some((pattern) => typeof pattern == "string" ? message.includes(pattern) : pattern instanceof RegExp ? pattern.test(message) : !1);
|
|
194
200
|
return {
|
|
195
201
|
onResponse: (res) => {
|
|
196
202
|
const warn = res.headers["x-sanity-warning"], warnings = Array.isArray(warn) ? warn : [warn];
|
|
197
203
|
for (const msg of warnings)
|
|
198
|
-
!msg || seen[msg] || (seen[msg] = !0, console.warn(msg));
|
|
204
|
+
!msg || seen[msg] || shouldIgnoreWarning(msg) || (seen[msg] = !0, console.warn(msg));
|
|
199
205
|
return res;
|
|
200
206
|
}
|
|
201
207
|
};
|
|
202
208
|
}
|
|
203
|
-
function defineHttpRequest(envMiddleware) {
|
|
209
|
+
function defineHttpRequest(envMiddleware, config2 = {}) {
|
|
204
210
|
return getIt.getIt([
|
|
205
211
|
middleware$1.retry({ shouldRetry }),
|
|
206
212
|
...envMiddleware,
|
|
207
|
-
printWarnings(),
|
|
213
|
+
printWarnings(config2),
|
|
208
214
|
middleware$1.jsonRequest(),
|
|
209
215
|
middleware$1.jsonResponse(),
|
|
210
216
|
middleware$1.progress(),
|
|
@@ -217,6 +223,7 @@ function shouldRetry(err, attempt, options) {
|
|
|
217
223
|
const isSafe = options.method === "GET" || options.method === "HEAD", isQuery2 = (options.uri || options.url).startsWith("/data/query"), isRetriableResponse = err.response && (err.response.statusCode === 429 || err.response.statusCode === 502 || err.response.statusCode === 503);
|
|
218
224
|
return (isSafe || isQuery2) && isRetriableResponse ? !0 : middleware$1.retry.shouldRetry(err, attempt, options);
|
|
219
225
|
}
|
|
226
|
+
const EXPERIMENTAL_API_WARNING = "This is an experimental API version";
|
|
220
227
|
class ConnectionFailedError extends Error {
|
|
221
228
|
name = "ConnectionFailedError";
|
|
222
229
|
}
|
|
@@ -794,12 +801,27 @@ function _createOrReplace(client, httpRequest, doc, options) {
|
|
|
794
801
|
return config.requireDocumentId("createOrReplace", doc), _create(client, httpRequest, doc, "createOrReplace", options);
|
|
795
802
|
}
|
|
796
803
|
function _createVersion(client, httpRequest, doc, publishedId, options) {
|
|
797
|
-
return config.requireDocumentId("createVersion", doc), config.requireDocumentType("createVersion", doc), _action(client, httpRequest, {
|
|
804
|
+
return config.requireDocumentId("createVersion", doc), config.requireDocumentType("createVersion", doc), config.printCreateVersionWithBaseIdWarning(), _action(client, httpRequest, {
|
|
798
805
|
actionType: "sanity.action.document.version.create",
|
|
799
806
|
publishedId,
|
|
800
807
|
document: doc
|
|
801
808
|
}, options);
|
|
802
809
|
}
|
|
810
|
+
function _createVersionFromBase(client, httpRequest, publishedId, baseId, releaseId, ifBaseRevisionId, options) {
|
|
811
|
+
if (!baseId)
|
|
812
|
+
throw new Error("`createVersion()` requires `baseId` when no `document` is provided");
|
|
813
|
+
if (!publishedId)
|
|
814
|
+
throw new Error("`createVersion()` requires `publishedId` when `baseId` is provided");
|
|
815
|
+
config.validateDocumentId("createVersion", baseId), config.validateDocumentId("createVersion", publishedId);
|
|
816
|
+
const createVersionAction = {
|
|
817
|
+
actionType: "sanity.action.document.version.create",
|
|
818
|
+
publishedId,
|
|
819
|
+
baseId,
|
|
820
|
+
versionId: releaseId ? csm.getVersionId(publishedId, releaseId) : csm.getDraftId(publishedId),
|
|
821
|
+
ifBaseRevisionId
|
|
822
|
+
};
|
|
823
|
+
return _action(client, httpRequest, createVersionAction, options);
|
|
824
|
+
}
|
|
803
825
|
function _delete(client, httpRequest, selection, options) {
|
|
804
826
|
return _dataRequest(
|
|
805
827
|
client,
|
|
@@ -2085,8 +2107,20 @@ class ObservableSanityClient {
|
|
|
2085
2107
|
createVersion({
|
|
2086
2108
|
document,
|
|
2087
2109
|
publishedId,
|
|
2088
|
-
releaseId
|
|
2110
|
+
releaseId,
|
|
2111
|
+
baseId,
|
|
2112
|
+
ifBaseRevisionId
|
|
2089
2113
|
}, options) {
|
|
2114
|
+
if (!document)
|
|
2115
|
+
return _createVersionFromBase(
|
|
2116
|
+
this,
|
|
2117
|
+
this.#httpRequest,
|
|
2118
|
+
publishedId,
|
|
2119
|
+
baseId,
|
|
2120
|
+
releaseId,
|
|
2121
|
+
ifBaseRevisionId,
|
|
2122
|
+
options
|
|
2123
|
+
);
|
|
2090
2124
|
const documentVersionId = deriveDocumentVersionId("createVersion", {
|
|
2091
2125
|
document,
|
|
2092
2126
|
publishedId,
|
|
@@ -2337,8 +2371,22 @@ class SanityClient {
|
|
|
2337
2371
|
createVersion({
|
|
2338
2372
|
document,
|
|
2339
2373
|
publishedId,
|
|
2340
|
-
releaseId
|
|
2374
|
+
releaseId,
|
|
2375
|
+
baseId,
|
|
2376
|
+
ifBaseRevisionId
|
|
2341
2377
|
}, options) {
|
|
2378
|
+
if (!document)
|
|
2379
|
+
return rxjs.firstValueFrom(
|
|
2380
|
+
_createVersionFromBase(
|
|
2381
|
+
this,
|
|
2382
|
+
this.#httpRequest,
|
|
2383
|
+
publishedId,
|
|
2384
|
+
baseId,
|
|
2385
|
+
releaseId,
|
|
2386
|
+
ifBaseRevisionId,
|
|
2387
|
+
options
|
|
2388
|
+
)
|
|
2389
|
+
);
|
|
2342
2390
|
const documentVersionId = deriveDocumentVersionId("createVersion", {
|
|
2343
2391
|
document,
|
|
2344
2392
|
publishedId,
|
|
@@ -2507,7 +2555,9 @@ class SanityClient {
|
|
|
2507
2555
|
}
|
|
2508
2556
|
function defineCreateClientExports(envMiddleware, ClassConstructor) {
|
|
2509
2557
|
return { requester: defineHttpRequest(envMiddleware), createClient: (config2) => {
|
|
2510
|
-
const clientRequester = defineHttpRequest(envMiddleware
|
|
2558
|
+
const clientRequester = defineHttpRequest(envMiddleware, {
|
|
2559
|
+
ignoreWarnings: config2.ignoreWarnings
|
|
2560
|
+
});
|
|
2511
2561
|
return new ClassConstructor(
|
|
2512
2562
|
(options, requester2) => (requester2 || clientRequester)({
|
|
2513
2563
|
maxRedirects: 0,
|
|
@@ -2524,7 +2574,7 @@ function defineDeprecatedCreateClient(createClient2) {
|
|
|
2524
2574
|
return config.printNoDefaultExport(), createClient2(config$1);
|
|
2525
2575
|
};
|
|
2526
2576
|
}
|
|
2527
|
-
var name = "@sanity/client", version = "7.
|
|
2577
|
+
var name = "@sanity/client", version = "7.8.0";
|
|
2528
2578
|
const middleware = [
|
|
2529
2579
|
middleware$1.debug({ verbose: !0, namespace: "sanity:client" }),
|
|
2530
2580
|
middleware$1.headers({ "User-Agent": `${name} ${version}` }),
|
|
@@ -2562,6 +2612,7 @@ exports.ClientError = ClientError;
|
|
|
2562
2612
|
exports.ConnectionFailedError = ConnectionFailedError;
|
|
2563
2613
|
exports.CorsOriginError = CorsOriginError;
|
|
2564
2614
|
exports.DisconnectError = DisconnectError;
|
|
2615
|
+
exports.EXPERIMENTAL_API_WARNING = EXPERIMENTAL_API_WARNING;
|
|
2565
2616
|
exports.MessageError = MessageError;
|
|
2566
2617
|
exports.MessageParseError = MessageParseError;
|
|
2567
2618
|
exports.ObservablePatch = ObservablePatch;
|
|
@@ -2575,6 +2626,7 @@ exports.connectEventSource = connectEventSource;
|
|
|
2575
2626
|
exports.createClient = createClient;
|
|
2576
2627
|
exports.default = deprecatedCreateClient;
|
|
2577
2628
|
exports.formatQueryParseError = formatQueryParseError;
|
|
2629
|
+
exports.isHttpError = isHttpError;
|
|
2578
2630
|
exports.isQueryParseError = isQueryParseError;
|
|
2579
2631
|
exports.requester = requester;
|
|
2580
2632
|
//# sourceMappingURL=index.cjs.map
|