@sanity/client 7.5.0 → 7.7.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/README.md +7 -0
- package/dist/index.browser.cjs +17 -7
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.d.cts +104 -2
- package/dist/index.browser.d.ts +104 -2
- package/dist/index.browser.js +17 -7
- package/dist/index.browser.js.map +1 -1
- package/dist/index.cjs +18 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +104 -2
- package/dist/index.d.ts +104 -2
- package/dist/index.js +18 -7
- package/dist/index.js.map +1 -1
- package/dist/stega.browser.d.cts +104 -2
- package/dist/stega.browser.d.ts +104 -2
- package/dist/stega.d.cts +104 -2
- package/dist/stega.d.ts +104 -2
- package/package.json +1 -1
- package/src/agent/actions/transform.ts +32 -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 +44 -0
- package/umd/sanityClient.js +17 -7
- package/umd/sanityClient.min.js +2 -2
package/README.md
CHANGED
|
@@ -2138,6 +2138,13 @@ For example:
|
|
|
2138
2138
|
- `target: {path: ['wrapper', 'title'], operation: {type: 'image-description', sourcePath: ['array', {_key: 'abc'}, 'image'] }`
|
|
2139
2139
|
- `target: {path: ['wrapper'], include: ['portableTextField'], operation: {type: 'image-description', sourcePath: ['image', 'asset'] }, instruction: 'Use formatting and headings to describe the image in great detail' }`
|
|
2140
2140
|
|
|
2141
|
+
|
|
2142
|
+
###### Targeting images outside the document (URL)
|
|
2143
|
+
If the source image is available on a https URL outside the target document, it is possible to get a description for it using `imageUrl`.
|
|
2144
|
+
|
|
2145
|
+
Example:
|
|
2146
|
+
- `target: {path: ['description'], operation: operation: {type: 'image-description', imageUrL: 'https://www.sanity.io/static/images/favicons/android-icon-192x192.png?v=2' }`
|
|
2147
|
+
|
|
2141
2148
|
##### Example: Field-based transformation
|
|
2142
2149
|
|
|
2143
2150
|
```ts
|
package/dist/index.browser.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 (!stegaClean.isRecord(error))
|
|
94
|
+
return !1;
|
|
95
|
+
const response = error.response;
|
|
96
|
+
return !(typeof error.statusCode != "number" || typeof error.message != "string" || !stegaClean.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(config = {}) {
|
|
199
|
+
const seen = {}, shouldIgnoreWarning = (message) => config.ignoreWarnings === void 0 ? !1 : (Array.isArray(config.ignoreWarnings) ? config.ignoreWarnings : [config.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(envMiddleware2) {
|
|
209
|
+
function defineHttpRequest(envMiddleware2, config = {}) {
|
|
204
210
|
return getIt.getIt([
|
|
205
211
|
middleware.retry({ shouldRetry }),
|
|
206
212
|
...envMiddleware2,
|
|
207
|
-
printWarnings(),
|
|
213
|
+
printWarnings(config),
|
|
208
214
|
middleware.jsonRequest(),
|
|
209
215
|
middleware.jsonResponse(),
|
|
210
216
|
middleware.progress(),
|
|
@@ -294,7 +300,7 @@ const VALID_ASSET_TYPES = ["image", "file"], VALID_INSERT_LOCATIONS = ["before",
|
|
|
294
300
|
}, resourceGuard = (service, config) => {
|
|
295
301
|
if (config["~experimental_resource"])
|
|
296
302
|
throw new Error(`\`${service}\` does not support resource-based operations`);
|
|
297
|
-
};
|
|
303
|
+
}, EXPERIMENTAL_API_WARNING = "This is an experimental API version";
|
|
298
304
|
function once(fn) {
|
|
299
305
|
let didCall = !1, returnValue;
|
|
300
306
|
return (...args) => (didCall || (returnValue = fn(...args), didCall = !0), returnValue);
|
|
@@ -2677,7 +2683,9 @@ class SanityClient {
|
|
|
2677
2683
|
}
|
|
2678
2684
|
function defineCreateClientExports(envMiddleware2, ClassConstructor) {
|
|
2679
2685
|
return { requester: defineHttpRequest(envMiddleware2), createClient: (config) => {
|
|
2680
|
-
const clientRequester = defineHttpRequest(envMiddleware2
|
|
2686
|
+
const clientRequester = defineHttpRequest(envMiddleware2, {
|
|
2687
|
+
ignoreWarnings: config.ignoreWarnings
|
|
2688
|
+
});
|
|
2681
2689
|
return new ClassConstructor(
|
|
2682
2690
|
(options, requester2) => (requester2 || clientRequester)({
|
|
2683
2691
|
maxRedirects: 0,
|
|
@@ -2715,6 +2723,7 @@ exports.ClientError = ClientError;
|
|
|
2715
2723
|
exports.ConnectionFailedError = ConnectionFailedError;
|
|
2716
2724
|
exports.CorsOriginError = CorsOriginError;
|
|
2717
2725
|
exports.DisconnectError = DisconnectError;
|
|
2726
|
+
exports.EXPERIMENTAL_API_WARNING = EXPERIMENTAL_API_WARNING;
|
|
2718
2727
|
exports.MessageError = MessageError;
|
|
2719
2728
|
exports.MessageParseError = MessageParseError;
|
|
2720
2729
|
exports.ObservablePatch = ObservablePatch;
|
|
@@ -2728,6 +2737,7 @@ exports.connectEventSource = connectEventSource;
|
|
|
2728
2737
|
exports.createClient = createClient;
|
|
2729
2738
|
exports.default = deprecatedCreateClient;
|
|
2730
2739
|
exports.formatQueryParseError = formatQueryParseError;
|
|
2740
|
+
exports.isHttpError = isHttpError;
|
|
2731
2741
|
exports.isQueryParseError = isQueryParseError;
|
|
2732
2742
|
exports.requester = requester;
|
|
2733
2743
|
exports.validateApiPerspective = validateApiPerspective;
|