@sanity/client 5.4.2-dev.0 → 5.4.3-dev.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 +41 -20
- package/dist/index.browser.cjs +47 -15
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.js +48 -16
- package/dist/index.browser.js.map +1 -1
- package/dist/index.cjs +48 -18
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +20 -4
- package/dist/index.js +48 -18
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
- package/src/SanityClient.ts +7 -4
- package/src/config.ts +2 -1
- package/src/data/dataMethods.ts +9 -8
- package/src/http/nodeMiddleware.ts +1 -2
- package/src/http/request.ts +42 -2
- package/src/index.browser.ts +9 -2
- package/src/index.ts +9 -2
- package/src/types.ts +15 -0
- package/src/warnings.ts +4 -5
- package/umd/sanityClient.js +93 -32
- package/umd/sanityClient.min.js +3 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sanity/client",
|
|
3
|
-
"version": "5.4.
|
|
3
|
+
"version": "5.4.3-dev.0",
|
|
4
4
|
"description": "Client for retrieving, creating and patching data from Sanity.io",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"sanity",
|
|
@@ -104,23 +104,23 @@
|
|
|
104
104
|
"@types/node": "^18.15.10",
|
|
105
105
|
"@typescript-eslint/eslint-plugin": "^5.57.0",
|
|
106
106
|
"@typescript-eslint/parser": "^5.57.0",
|
|
107
|
-
"@vitest/coverage-c8": "^0.
|
|
107
|
+
"@vitest/coverage-c8": "^0.30.0",
|
|
108
108
|
"eslint": "^8.36.0",
|
|
109
109
|
"eslint-config-prettier": "^8.8.0",
|
|
110
110
|
"eslint-plugin-prettier": "^4.2.1",
|
|
111
111
|
"eslint-plugin-simple-import-sort": "^10.0.0",
|
|
112
112
|
"faucet": "^0.0.4",
|
|
113
|
-
"happy-dom": "^
|
|
113
|
+
"happy-dom": "^9.0.0",
|
|
114
114
|
"ls-engines": "^0.9.0",
|
|
115
115
|
"nock": "^13.3.0",
|
|
116
116
|
"prettier": "^2.8.7",
|
|
117
117
|
"prettier-plugin-packagejson": "^2.4.3",
|
|
118
|
-
"rimraf": "^
|
|
118
|
+
"rimraf": "^5.0.0",
|
|
119
119
|
"rollup": "^3.20.2",
|
|
120
120
|
"sse-channel": "^4.0.0",
|
|
121
121
|
"terser": "^5.16.8",
|
|
122
122
|
"typescript": "^5.0.2",
|
|
123
|
-
"vitest": "^0.
|
|
123
|
+
"vitest": "^0.30.0",
|
|
124
124
|
"vitest-github-actions-reporter": "^0.10.0"
|
|
125
125
|
},
|
|
126
126
|
"engines": {
|
package/src/SanityClient.ts
CHANGED
|
@@ -1210,22 +1210,25 @@ export class SanityClient {
|
|
|
1210
1210
|
}
|
|
1211
1211
|
|
|
1212
1212
|
/**
|
|
1213
|
-
*
|
|
1213
|
+
* Perform a request against the Sanity API
|
|
1214
|
+
* NOTE: Only use this for Sanity API endpoints, not for your own APIs!
|
|
1214
1215
|
*
|
|
1215
|
-
* @deprecated Use your own request library!
|
|
1216
1216
|
* @param options - Request options
|
|
1217
|
+
* @returns Promise resolving to the response body
|
|
1217
1218
|
*/
|
|
1218
1219
|
request<R = Any>(options: RawRequestOptions): Promise<R> {
|
|
1219
1220
|
return lastValueFrom(dataMethods._request<R>(this, this.#httpRequest, options))
|
|
1220
1221
|
}
|
|
1221
1222
|
|
|
1222
1223
|
/**
|
|
1223
|
-
*
|
|
1224
|
+
* Perform an HTTP request a `/data` sub-endpoint
|
|
1225
|
+
* NOTE: Considered internal, thus marked as deprecated. Use `request` instead.
|
|
1224
1226
|
*
|
|
1225
|
-
* @deprecated Use your own
|
|
1227
|
+
* @deprecated - Use `request()` or your own HTTP library instead
|
|
1226
1228
|
* @param endpoint - Endpoint to hit (mutate, query etc)
|
|
1227
1229
|
* @param body - Request body
|
|
1228
1230
|
* @param options - Request options
|
|
1231
|
+
* @internal
|
|
1229
1232
|
*/
|
|
1230
1233
|
dataRequest(endpoint: string, body: unknown, options?: BaseMutationOptions): Promise<Any> {
|
|
1231
1234
|
return lastValueFrom(dataMethods._dataRequest(this, this.#httpRequest, endpoint, body, options))
|
package/src/config.ts
CHANGED
|
@@ -75,7 +75,8 @@ export const initConfig = (
|
|
|
75
75
|
|
|
76
76
|
newConfig.apiVersion = `${newConfig.apiVersion}`.replace(/^v/, '')
|
|
77
77
|
newConfig.isDefaultApi = newConfig.apiHost === defaultConfig.apiHost
|
|
78
|
-
|
|
78
|
+
// If `useCdn` is undefined, we treat it as `true`
|
|
79
|
+
newConfig.useCdn = newConfig.useCdn !== false && !newConfig.withCredentials
|
|
79
80
|
|
|
80
81
|
validateApiVersion(newConfig.apiVersion)
|
|
81
82
|
|
package/src/data/dataMethods.ts
CHANGED
|
@@ -177,16 +177,17 @@ export function _mutate<R extends Record<string, Any>>(
|
|
|
177
177
|
): Observable<
|
|
178
178
|
SanityDocument<R> | SanityDocument<R>[] | SingleMutationResult | MultipleMutationResult
|
|
179
179
|
> {
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
180
|
+
let mut: Mutation | Mutation[]
|
|
181
|
+
if (mutations instanceof Patch || mutations instanceof ObservablePatch) {
|
|
182
|
+
mut = {patch: mutations.serialize()}
|
|
183
|
+
} else if (mutations instanceof Transaction || mutations instanceof ObservableTransaction) {
|
|
184
|
+
mut = mutations.serialize()
|
|
185
|
+
} else {
|
|
186
|
+
mut = mutations
|
|
187
|
+
}
|
|
187
188
|
|
|
188
189
|
const muts = Array.isArray(mut) ? mut : [mut]
|
|
189
|
-
const transactionId = options &&
|
|
190
|
+
const transactionId = (options && options.transactionId) || undefined
|
|
190
191
|
return _dataRequest(client, httpRequest, 'mutate', {mutations: muts, transactionId}, options)
|
|
191
192
|
}
|
|
192
193
|
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import {debug, headers
|
|
1
|
+
import {debug, headers} from 'get-it/middleware'
|
|
2
2
|
|
|
3
3
|
import {name, version} from '../../package.json'
|
|
4
4
|
|
|
5
5
|
const middleware = [
|
|
6
6
|
debug({verbose: true, namespace: 'sanity:client'}),
|
|
7
7
|
headers({'User-Agent': `${name} ${version}`}),
|
|
8
|
-
retry({maxRetries: 3}),
|
|
9
8
|
]
|
|
10
9
|
|
|
11
10
|
export default middleware
|
package/src/http/request.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {getIt, type Middlewares} from 'get-it'
|
|
2
|
-
import {jsonRequest, jsonResponse, observable, progress} from 'get-it/middleware'
|
|
2
|
+
import {jsonRequest, jsonResponse, observable, progress, retry} from 'get-it/middleware'
|
|
3
3
|
import {Observable} from 'rxjs'
|
|
4
4
|
|
|
5
5
|
import type {Any, HttpRequest, RequestOptions} from '../types'
|
|
@@ -27,8 +27,22 @@ const printWarnings = {
|
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
/** @internal */
|
|
30
|
-
export function defineHttpRequest(
|
|
30
|
+
export function defineHttpRequest(
|
|
31
|
+
envMiddleware: Middlewares,
|
|
32
|
+
{
|
|
33
|
+
maxRetries = 5,
|
|
34
|
+
retryDelay,
|
|
35
|
+
}: {maxRetries?: number; retryDelay?: (attemptNumber: number) => number}
|
|
36
|
+
): HttpRequest {
|
|
31
37
|
const request = getIt([
|
|
38
|
+
maxRetries > 0
|
|
39
|
+
? retry({
|
|
40
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
41
|
+
retryDelay: retryDelay as any, // This option is typed incorrectly in get-it.
|
|
42
|
+
maxRetries,
|
|
43
|
+
shouldRetry,
|
|
44
|
+
})
|
|
45
|
+
: {},
|
|
32
46
|
...envMiddleware,
|
|
33
47
|
printWarnings,
|
|
34
48
|
jsonRequest(),
|
|
@@ -46,3 +60,29 @@ export function defineHttpRequest(envMiddleware: Middlewares): HttpRequest {
|
|
|
46
60
|
|
|
47
61
|
return httpRequest
|
|
48
62
|
}
|
|
63
|
+
|
|
64
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
65
|
+
function shouldRetry(err: any, attempt: number, options: any) {
|
|
66
|
+
// By default `retry.shouldRetry` doesn't retry on server errors so we add our own logic.
|
|
67
|
+
|
|
68
|
+
const isSafe = options.method === 'GET' || options.method === 'HEAD'
|
|
69
|
+
const isQuery = options.uri.startsWith('/data/query')
|
|
70
|
+
const isRetriableResponse =
|
|
71
|
+
err.response &&
|
|
72
|
+
(err.response.statusCode === 429 ||
|
|
73
|
+
err.response.statusCode === 502 ||
|
|
74
|
+
err.response.statusCode === 503)
|
|
75
|
+
|
|
76
|
+
// We retry the following errors:
|
|
77
|
+
// - 429 means that the request was rate limited. It's a bit difficult
|
|
78
|
+
// to know exactly how long it makes sense to wait and/or how many
|
|
79
|
+
// attempts we should retry, but the backoff should alleviate the
|
|
80
|
+
// additional load.
|
|
81
|
+
// - 502/503 can occur when certain components struggle to talk to their
|
|
82
|
+
// upstream dependencies. This is most likely a temporary problem
|
|
83
|
+
// and retrying makes sense.
|
|
84
|
+
|
|
85
|
+
if ((isSafe || isQuery) && isRetriableResponse) return true
|
|
86
|
+
|
|
87
|
+
return retry.shouldRetry(err, attempt, options)
|
|
88
|
+
}
|
package/src/index.browser.ts
CHANGED
|
@@ -11,12 +11,19 @@ export * from './SanityClient'
|
|
|
11
11
|
export * from './types'
|
|
12
12
|
|
|
13
13
|
// Set the http client to use for requests, and its environment specific middleware
|
|
14
|
-
const httpRequest = defineHttpRequest(envMiddleware)
|
|
14
|
+
const httpRequest = defineHttpRequest(envMiddleware, {})
|
|
15
15
|
/** @public */
|
|
16
16
|
export const requester = httpRequest.defaultRequester
|
|
17
17
|
|
|
18
18
|
/** @public */
|
|
19
|
-
export const createClient = (config: ClientConfig) =>
|
|
19
|
+
export const createClient = (config: ClientConfig) =>
|
|
20
|
+
new SanityClient(
|
|
21
|
+
defineHttpRequest(envMiddleware, {
|
|
22
|
+
maxRetries: config.maxRetries,
|
|
23
|
+
retryDelay: config.retryDelay,
|
|
24
|
+
}),
|
|
25
|
+
config
|
|
26
|
+
)
|
|
20
27
|
|
|
21
28
|
/**
|
|
22
29
|
* @public
|
package/src/index.ts
CHANGED
|
@@ -11,12 +11,19 @@ export * from './SanityClient'
|
|
|
11
11
|
export * from './types'
|
|
12
12
|
|
|
13
13
|
// Set the http client to use for requests, and its environment specific middleware
|
|
14
|
-
const httpRequest = defineHttpRequest(envMiddleware)
|
|
14
|
+
const httpRequest = defineHttpRequest(envMiddleware, {})
|
|
15
15
|
/** @public */
|
|
16
16
|
export const requester = httpRequest.defaultRequester
|
|
17
17
|
|
|
18
18
|
/** @public */
|
|
19
|
-
export const createClient = (config: ClientConfig) =>
|
|
19
|
+
export const createClient = (config: ClientConfig) =>
|
|
20
|
+
new SanityClient(
|
|
21
|
+
defineHttpRequest(envMiddleware, {
|
|
22
|
+
maxRetries: config.maxRetries,
|
|
23
|
+
retryDelay: config.retryDelay,
|
|
24
|
+
}),
|
|
25
|
+
config
|
|
26
|
+
)
|
|
20
27
|
|
|
21
28
|
/**
|
|
22
29
|
* @public
|
package/src/types.ts
CHANGED
|
@@ -31,6 +31,7 @@ export interface RequestOptions {
|
|
|
31
31
|
export interface ClientConfig {
|
|
32
32
|
projectId?: string
|
|
33
33
|
dataset?: string
|
|
34
|
+
/** @defaultValue true */
|
|
34
35
|
useCdn?: boolean
|
|
35
36
|
token?: string
|
|
36
37
|
apiHost?: string
|
|
@@ -42,6 +43,19 @@ export interface ClientConfig {
|
|
|
42
43
|
allowReconfigure?: boolean
|
|
43
44
|
timeout?: number
|
|
44
45
|
|
|
46
|
+
/** Number of retries for requests. Defaults to 5. */
|
|
47
|
+
maxRetries?: number
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* The amount of time, in milliseconds, to wait before retrying, given an attemptNumber (starting at 0).
|
|
51
|
+
*
|
|
52
|
+
* Defaults to exponential back-off, starting at 100ms, doubling for each attempt, together with random
|
|
53
|
+
* jitter between 0 and 100 milliseconds. More specifically the following algorithm is used:
|
|
54
|
+
*
|
|
55
|
+
* Delay = 100 * 2^attemptNumber + randomNumberBetween0and100
|
|
56
|
+
*/
|
|
57
|
+
retryDelay?: (attemptNumber: number) => number
|
|
58
|
+
|
|
45
59
|
/**
|
|
46
60
|
* @deprecated Don't use
|
|
47
61
|
*/
|
|
@@ -534,6 +548,7 @@ export type BaseMutationOptions = RequestOptions & {
|
|
|
534
548
|
dryRun?: boolean
|
|
535
549
|
autoGenerateArrayKeys?: boolean
|
|
536
550
|
skipCrossDatasetReferenceValidation?: boolean
|
|
551
|
+
transactionId?: string
|
|
537
552
|
}
|
|
538
553
|
|
|
539
554
|
/** @internal */
|
package/src/warnings.ts
CHANGED
|
@@ -7,10 +7,9 @@ const createWarningPrinter = (message: string[]) =>
|
|
|
7
7
|
once((...args: Any[]) => console.warn(message.join(' '), ...args))
|
|
8
8
|
|
|
9
9
|
export const printCdnWarning = createWarningPrinter([
|
|
10
|
-
|
|
11
|
-
`
|
|
12
|
-
|
|
13
|
-
'the client.',
|
|
10
|
+
`Since you haven't set a value for \`useCdn\`, we will deliver content using our`,
|
|
11
|
+
`global, edge-cached API-CDN. If you wish to have content delivered faster, set`,
|
|
12
|
+
`\`useCdn: false\` to use the Live API. Note: You may incur higher costs using the live API.`,
|
|
14
13
|
])
|
|
15
14
|
|
|
16
15
|
export const printBrowserTokenWarning = createWarningPrinter([
|
|
@@ -26,5 +25,5 @@ export const printNoApiVersionSpecifiedWarning = createWarningPrinter([
|
|
|
26
25
|
])
|
|
27
26
|
|
|
28
27
|
export const printNoDefaultExport = createWarningPrinter([
|
|
29
|
-
'The default export of @sanity/client has been deprecated. Use the named export `createClient` instead',
|
|
28
|
+
'The default export of @sanity/client has been deprecated. Use the named export `createClient` instead.',
|
|
30
29
|
])
|
package/umd/sanityClient.js
CHANGED
|
@@ -4,21 +4,6 @@
|
|
|
4
4
|
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.SanityClient = {}));
|
|
5
5
|
})(this, (function (exports) { 'use strict';
|
|
6
6
|
|
|
7
|
-
function _mergeNamespaces(n, m) {
|
|
8
|
-
m.forEach(function (e) {
|
|
9
|
-
e && typeof e !== 'string' && !Array.isArray(e) && Object.keys(e).forEach(function (k) {
|
|
10
|
-
if (k !== 'default' && !(k in n)) {
|
|
11
|
-
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
12
|
-
Object.defineProperty(n, k, d.get ? d : {
|
|
13
|
-
enumerable: true,
|
|
14
|
-
get: function () { return e[k]; }
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
|
-
});
|
|
18
|
-
});
|
|
19
|
-
return Object.freeze(n);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
7
|
const isReactNative = typeof navigator === "undefined" ? false : navigator.product === "ReactNative";
|
|
23
8
|
const defaultOptions$1 = {
|
|
24
9
|
timeout: isReactNative ? 6e4 : 12e4
|
|
@@ -1372,6 +1357,50 @@
|
|
|
1372
1357
|
cancel
|
|
1373
1358
|
};
|
|
1374
1359
|
};
|
|
1360
|
+
var defaultShouldRetry = (err, attempt, options) => {
|
|
1361
|
+
if (options.method !== "GET" && options.method !== "HEAD") {
|
|
1362
|
+
return false;
|
|
1363
|
+
}
|
|
1364
|
+
return err.isNetworkError || false;
|
|
1365
|
+
};
|
|
1366
|
+
const isStream = stream => stream !== null && typeof stream === "object" && typeof stream.pipe === "function";
|
|
1367
|
+
var sharedRetry = opts => {
|
|
1368
|
+
const maxRetries = opts.maxRetries || 5;
|
|
1369
|
+
const retryDelay = opts.retryDelay || getRetryDelay;
|
|
1370
|
+
const allowRetry = opts.shouldRetry;
|
|
1371
|
+
return {
|
|
1372
|
+
onError: (err, context) => {
|
|
1373
|
+
const options = context.options;
|
|
1374
|
+
const max = options.maxRetries || maxRetries;
|
|
1375
|
+
const shouldRetry = options.shouldRetry || allowRetry;
|
|
1376
|
+
const attemptNumber = options.attemptNumber || 0;
|
|
1377
|
+
if (isStream(options.body)) {
|
|
1378
|
+
return err;
|
|
1379
|
+
}
|
|
1380
|
+
if (!shouldRetry(err, attemptNumber, options) || attemptNumber >= max) {
|
|
1381
|
+
return err;
|
|
1382
|
+
}
|
|
1383
|
+
const newContext = Object.assign({}, context, {
|
|
1384
|
+
options: Object.assign({}, options, {
|
|
1385
|
+
attemptNumber: attemptNumber + 1
|
|
1386
|
+
})
|
|
1387
|
+
});
|
|
1388
|
+
setTimeout(() => context.channels.request.publish(newContext), retryDelay(attemptNumber));
|
|
1389
|
+
return null;
|
|
1390
|
+
}
|
|
1391
|
+
};
|
|
1392
|
+
};
|
|
1393
|
+
function getRetryDelay(attemptNum) {
|
|
1394
|
+
return 100 * Math.pow(2, attemptNum) + Math.random() * 100;
|
|
1395
|
+
}
|
|
1396
|
+
const retry = function () {
|
|
1397
|
+
let opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
1398
|
+
return sharedRetry({
|
|
1399
|
+
shouldRetry: defaultShouldRetry,
|
|
1400
|
+
...opts
|
|
1401
|
+
});
|
|
1402
|
+
};
|
|
1403
|
+
retry.shouldRetry = defaultShouldRetry;
|
|
1375
1404
|
|
|
1376
1405
|
/******************************************************************************
|
|
1377
1406
|
Copyright (c) Microsoft Corporation.
|
|
@@ -2140,8 +2169,18 @@
|
|
|
2140
2169
|
return res;
|
|
2141
2170
|
}
|
|
2142
2171
|
};
|
|
2143
|
-
function defineHttpRequest(envMiddleware) {
|
|
2144
|
-
|
|
2172
|
+
function defineHttpRequest(envMiddleware, _ref) {
|
|
2173
|
+
let {
|
|
2174
|
+
maxRetries = 5,
|
|
2175
|
+
retryDelay
|
|
2176
|
+
} = _ref;
|
|
2177
|
+
const request = getIt([maxRetries > 0 ? retry({
|
|
2178
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
2179
|
+
retryDelay,
|
|
2180
|
+
// This option is typed incorrectly in get-it.
|
|
2181
|
+
maxRetries,
|
|
2182
|
+
shouldRetry
|
|
2183
|
+
}) : {}, ...envMiddleware, printWarnings, jsonRequest(), jsonResponse(), progress(), httpError, observable$1({
|
|
2145
2184
|
implementation: Observable
|
|
2146
2185
|
})]);
|
|
2147
2186
|
function httpRequest(options) {
|
|
@@ -2154,6 +2193,13 @@
|
|
|
2154
2193
|
httpRequest.defaultRequester = request;
|
|
2155
2194
|
return httpRequest;
|
|
2156
2195
|
}
|
|
2196
|
+
function shouldRetry(err, attempt, options) {
|
|
2197
|
+
const isSafe = options.method === "GET" || options.method === "HEAD";
|
|
2198
|
+
const isQuery = options.uri.startsWith("/data/query");
|
|
2199
|
+
const isRetriableResponse = err.response && (err.response.statusCode === 429 || err.response.statusCode === 502 || err.response.statusCode === 503);
|
|
2200
|
+
if ((isSafe || isQuery) && isRetriableResponse) return true;
|
|
2201
|
+
return retry.shouldRetry(err, attempt, options);
|
|
2202
|
+
}
|
|
2157
2203
|
const projectHeader = "X-Sanity-Project-ID";
|
|
2158
2204
|
function requestOptions(config) {
|
|
2159
2205
|
let overrides = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
@@ -2250,12 +2296,12 @@
|
|
|
2250
2296
|
}
|
|
2251
2297
|
return tag;
|
|
2252
2298
|
};
|
|
2253
|
-
const encodeQueryString =
|
|
2299
|
+
const encodeQueryString = _ref2 => {
|
|
2254
2300
|
let {
|
|
2255
2301
|
query,
|
|
2256
2302
|
params = {},
|
|
2257
2303
|
options = {}
|
|
2258
|
-
} =
|
|
2304
|
+
} = _ref2;
|
|
2259
2305
|
const searchParams = new URLSearchParams();
|
|
2260
2306
|
const {
|
|
2261
2307
|
tag,
|
|
@@ -2777,9 +2823,18 @@
|
|
|
2777
2823
|
}, options);
|
|
2778
2824
|
}
|
|
2779
2825
|
function _mutate(client, httpRequest, mutations, options) {
|
|
2780
|
-
|
|
2826
|
+
let mut;
|
|
2827
|
+
if (mutations instanceof Patch || mutations instanceof ObservablePatch) {
|
|
2828
|
+
mut = {
|
|
2829
|
+
patch: mutations.serialize()
|
|
2830
|
+
};
|
|
2831
|
+
} else if (mutations instanceof Transaction || mutations instanceof ObservableTransaction) {
|
|
2832
|
+
mut = mutations.serialize();
|
|
2833
|
+
} else {
|
|
2834
|
+
mut = mutations;
|
|
2835
|
+
}
|
|
2781
2836
|
const muts = Array.isArray(mut) ? mut : [mut];
|
|
2782
|
-
const transactionId = options && options.transactionId;
|
|
2837
|
+
const transactionId = options && options.transactionId || void 0;
|
|
2783
2838
|
return _dataRequest(client, httpRequest, "mutate", {
|
|
2784
2839
|
mutations: muts,
|
|
2785
2840
|
transactionId
|
|
@@ -3037,10 +3092,10 @@
|
|
|
3037
3092
|
}
|
|
3038
3093
|
return console.warn(message.join(" "), ...args);
|
|
3039
3094
|
});
|
|
3040
|
-
const printCdnWarning = createWarningPrinter(["
|
|
3095
|
+
const printCdnWarning = createWarningPrinter(["Since you haven't set a value for `useCdn`, we will deliver content using our", "global, edge-cached API-CDN. If you wish to have content delivered faster, set", "`useCdn: false` to use the Live API. Note: You may incur higher costs using the live API."]);
|
|
3041
3096
|
const printBrowserTokenWarning = createWarningPrinter(["You have configured Sanity client to use a token in the browser. This may cause unintentional security issues.", "See ".concat(generateHelpUrl("js-client-browser-token"), " for more information and how to hide this warning.")]);
|
|
3042
3097
|
const printNoApiVersionSpecifiedWarning = createWarningPrinter(["Using the Sanity client without specifying an API version is deprecated.", "See ".concat(generateHelpUrl("js-client-api-version"))]);
|
|
3043
|
-
const printNoDefaultExport = createWarningPrinter(["The default export of @sanity/client has been deprecated. Use the named export `createClient` instead"]);
|
|
3098
|
+
const printNoDefaultExport = createWarningPrinter(["The default export of @sanity/client has been deprecated. Use the named export `createClient` instead."]);
|
|
3044
3099
|
const defaultCdnHost = "apicdn.sanity.io";
|
|
3045
3100
|
const defaultConfig = {
|
|
3046
3101
|
apiHost: "https://api.sanity.io",
|
|
@@ -3091,7 +3146,7 @@
|
|
|
3091
3146
|
}
|
|
3092
3147
|
newConfig.apiVersion = "".concat(newConfig.apiVersion).replace(/^v/, "");
|
|
3093
3148
|
newConfig.isDefaultApi = newConfig.apiHost === defaultConfig.apiHost;
|
|
3094
|
-
newConfig.useCdn =
|
|
3149
|
+
newConfig.useCdn = newConfig.useCdn !== false && !newConfig.withCredentials;
|
|
3095
3150
|
validateApiVersion(newConfig.apiVersion);
|
|
3096
3151
|
const hostParts = newConfig.apiHost.split("://", 2);
|
|
3097
3152
|
const protocol = hostParts[0];
|
|
@@ -3768,21 +3823,24 @@
|
|
|
3768
3823
|
return new Transaction(operations, this);
|
|
3769
3824
|
}
|
|
3770
3825
|
/**
|
|
3771
|
-
*
|
|
3826
|
+
* Perform a request against the Sanity API
|
|
3827
|
+
* NOTE: Only use this for Sanity API endpoints, not for your own APIs!
|
|
3772
3828
|
*
|
|
3773
|
-
* @deprecated Use your own request library!
|
|
3774
3829
|
* @param options - Request options
|
|
3830
|
+
* @returns Promise resolving to the response body
|
|
3775
3831
|
*/
|
|
3776
3832
|
request(options) {
|
|
3777
3833
|
return lastValueFrom(_request(this, __privateGet(this, _httpRequest2), options));
|
|
3778
3834
|
}
|
|
3779
3835
|
/**
|
|
3780
|
-
*
|
|
3836
|
+
* Perform an HTTP request a `/data` sub-endpoint
|
|
3837
|
+
* NOTE: Considered internal, thus marked as deprecated. Use `request` instead.
|
|
3781
3838
|
*
|
|
3782
|
-
* @deprecated Use your own
|
|
3839
|
+
* @deprecated - Use `request()` or your own HTTP library instead
|
|
3783
3840
|
* @param endpoint - Endpoint to hit (mutate, query etc)
|
|
3784
3841
|
* @param body - Request body
|
|
3785
3842
|
* @param options - Request options
|
|
3843
|
+
* @internal
|
|
3786
3844
|
*/
|
|
3787
3845
|
dataRequest(endpoint, body, options) {
|
|
3788
3846
|
return lastValueFrom(_dataRequest(this, __privateGet(this, _httpRequest2), endpoint, body, options));
|
|
@@ -3809,9 +3867,12 @@
|
|
|
3809
3867
|
let SanityClient = _SanityClient;
|
|
3810
3868
|
_clientConfig2 = new WeakMap();
|
|
3811
3869
|
_httpRequest2 = new WeakMap();
|
|
3812
|
-
const httpRequest = defineHttpRequest(envMiddleware);
|
|
3870
|
+
const httpRequest = defineHttpRequest(envMiddleware, {});
|
|
3813
3871
|
const requester = httpRequest.defaultRequester;
|
|
3814
|
-
const createClient = config => new SanityClient(
|
|
3872
|
+
const createClient = config => new SanityClient(defineHttpRequest(envMiddleware, {
|
|
3873
|
+
maxRetries: config.maxRetries,
|
|
3874
|
+
retryDelay: config.retryDelay
|
|
3875
|
+
}), config);
|
|
3815
3876
|
function deprecatedCreateClient(config) {
|
|
3816
3877
|
printNoDefaultExport();
|
|
3817
3878
|
return new SanityClient(httpRequest, config);
|
|
@@ -4869,10 +4930,10 @@
|
|
|
4869
4930
|
|
|
4870
4931
|
var browser = eventsourceExports.EventSourcePolyfill;
|
|
4871
4932
|
|
|
4872
|
-
var browser$1 = /*#__PURE__*/
|
|
4933
|
+
var browser$1 = /*#__PURE__*/Object.freeze({
|
|
4873
4934
|
__proto__: null,
|
|
4874
4935
|
default: browser
|
|
4875
|
-
}
|
|
4936
|
+
});
|
|
4876
4937
|
|
|
4877
4938
|
exports.BasePatch = BasePatch;
|
|
4878
4939
|
exports.BaseTransaction = BaseTransaction;
|