@sanity/client 5.4.2 → 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 +104 -26
- package/dist/index.browser.cjs +42 -13
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.js +43 -14
- package/dist/index.browser.js.map +1 -1
- package/dist/index.cjs +43 -16
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +70 -4
- package/dist/index.js +43 -16
- package/dist/index.js.map +1 -1
- package/package.json +6 -5
- package/src/SanityClient.ts +7 -4
- package/src/config.ts +2 -1
- package/src/data/dataMethods.ts +4 -0
- 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 +67 -0
- package/src/warnings.ts +4 -5
- package/umd/sanityClient.js +88 -30
- 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",
|
|
@@ -33,6 +33,7 @@
|
|
|
33
33
|
"import": "./dist/index.browser.js"
|
|
34
34
|
},
|
|
35
35
|
"deno": "./dist/index.browser.js",
|
|
36
|
+
"edge": "./dist/index.browser.js",
|
|
36
37
|
"edge-light": "./dist/index.browser.js",
|
|
37
38
|
"worker": "./dist/index.browser.js",
|
|
38
39
|
"source": "./src/index.ts",
|
|
@@ -103,23 +104,23 @@
|
|
|
103
104
|
"@types/node": "^18.15.10",
|
|
104
105
|
"@typescript-eslint/eslint-plugin": "^5.57.0",
|
|
105
106
|
"@typescript-eslint/parser": "^5.57.0",
|
|
106
|
-
"@vitest/coverage-c8": "^0.
|
|
107
|
+
"@vitest/coverage-c8": "^0.30.0",
|
|
107
108
|
"eslint": "^8.36.0",
|
|
108
109
|
"eslint-config-prettier": "^8.8.0",
|
|
109
110
|
"eslint-plugin-prettier": "^4.2.1",
|
|
110
111
|
"eslint-plugin-simple-import-sort": "^10.0.0",
|
|
111
112
|
"faucet": "^0.0.4",
|
|
112
|
-
"happy-dom": "^
|
|
113
|
+
"happy-dom": "^9.0.0",
|
|
113
114
|
"ls-engines": "^0.9.0",
|
|
114
115
|
"nock": "^13.3.0",
|
|
115
116
|
"prettier": "^2.8.7",
|
|
116
117
|
"prettier-plugin-packagejson": "^2.4.3",
|
|
117
|
-
"rimraf": "^
|
|
118
|
+
"rimraf": "^5.0.0",
|
|
118
119
|
"rollup": "^3.20.2",
|
|
119
120
|
"sse-channel": "^4.0.0",
|
|
120
121
|
"terser": "^5.16.8",
|
|
121
122
|
"typescript": "^5.0.2",
|
|
122
|
-
"vitest": "^0.
|
|
123
|
+
"vitest": "^0.30.0",
|
|
123
124
|
"vitest-github-actions-reporter": "^0.10.0"
|
|
124
125
|
},
|
|
125
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
|
@@ -302,6 +302,10 @@ export function _requestObservable<R>(
|
|
|
302
302
|
options.query = {tag: validate.requestTag(tag), ...options.query}
|
|
303
303
|
}
|
|
304
304
|
|
|
305
|
+
if (config.resultSourceMap) {
|
|
306
|
+
options.query = {resultSourceMap: true, ...options.query}
|
|
307
|
+
}
|
|
308
|
+
|
|
305
309
|
const reqOptions = requestOptions(
|
|
306
310
|
config,
|
|
307
311
|
Object.assign({}, options, {
|
|
@@ -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
|
*/
|
|
@@ -51,6 +65,8 @@ export interface ClientConfig {
|
|
|
51
65
|
* @deprecated Don't use
|
|
52
66
|
*/
|
|
53
67
|
requester?: Requester
|
|
68
|
+
|
|
69
|
+
resultSourceMap?: boolean
|
|
54
70
|
}
|
|
55
71
|
|
|
56
72
|
/** @public */
|
|
@@ -461,16 +477,67 @@ export type FilteredResponseQueryOptions = RequestOptions & {
|
|
|
461
477
|
filterResponse?: true
|
|
462
478
|
}
|
|
463
479
|
|
|
480
|
+
/**
|
|
481
|
+
* DocumentValueSource is a path to a value within a document
|
|
482
|
+
* @internal
|
|
483
|
+
*/
|
|
484
|
+
export type DocumentValueSource = {
|
|
485
|
+
type: 'documentValue'
|
|
486
|
+
|
|
487
|
+
// index location of the document
|
|
488
|
+
document: number
|
|
489
|
+
// index location of the path
|
|
490
|
+
path: number
|
|
491
|
+
}
|
|
492
|
+
/**
|
|
493
|
+
* When a value is not from a source, its a literal
|
|
494
|
+
* @internal
|
|
495
|
+
*/
|
|
496
|
+
export type LiteralSource = {
|
|
497
|
+
type: 'literal'
|
|
498
|
+
}
|
|
499
|
+
/**
|
|
500
|
+
* When a field source is unknown
|
|
501
|
+
* @internal
|
|
502
|
+
*/
|
|
503
|
+
export type UnknownSource = {
|
|
504
|
+
type: 'unknown'
|
|
505
|
+
}
|
|
506
|
+
/** @internal */
|
|
507
|
+
export type Source = DocumentValueSource | LiteralSource | UnknownSource
|
|
508
|
+
/**
|
|
509
|
+
* ValueMapping is a mapping when for value that is from a single source value
|
|
510
|
+
* It may refer to a field within a document or a literal value
|
|
511
|
+
* @internal
|
|
512
|
+
*/
|
|
513
|
+
export type ValueMapping = {
|
|
514
|
+
type: 'value'
|
|
515
|
+
|
|
516
|
+
// source of the value
|
|
517
|
+
source: Source
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
/** @internal */
|
|
521
|
+
export type Mapping = ValueMapping
|
|
522
|
+
|
|
464
523
|
/** @internal */
|
|
465
524
|
export type UnfilteredResponseQueryOptions = RequestOptions & {
|
|
466
525
|
filterResponse: false
|
|
467
526
|
}
|
|
468
527
|
|
|
528
|
+
/** @internal */
|
|
529
|
+
export type ContentSourceMapping = {
|
|
530
|
+
mappings: Record<string, Mapping>
|
|
531
|
+
documents: Array<SanityDocument>
|
|
532
|
+
paths: Array<string>
|
|
533
|
+
}
|
|
534
|
+
|
|
469
535
|
/** @internal */
|
|
470
536
|
export interface RawQueryResponse<R> {
|
|
471
537
|
q: string
|
|
472
538
|
ms: number
|
|
473
539
|
result: R
|
|
540
|
+
resultSourceMap: ContentSourceMapping
|
|
474
541
|
}
|
|
475
542
|
|
|
476
543
|
/** @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,
|
|
@@ -2864,6 +2910,12 @@
|
|
|
2864
2910
|
...options.query
|
|
2865
2911
|
};
|
|
2866
2912
|
}
|
|
2913
|
+
if (config.resultSourceMap) {
|
|
2914
|
+
options.query = {
|
|
2915
|
+
resultSourceMap: true,
|
|
2916
|
+
...options.query
|
|
2917
|
+
};
|
|
2918
|
+
}
|
|
2867
2919
|
const reqOptions = requestOptions(config, Object.assign({}, options, {
|
|
2868
2920
|
url: _getUrl(client, uri, useCdn)
|
|
2869
2921
|
}));
|
|
@@ -3040,10 +3092,10 @@
|
|
|
3040
3092
|
}
|
|
3041
3093
|
return console.warn(message.join(" "), ...args);
|
|
3042
3094
|
});
|
|
3043
|
-
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."]);
|
|
3044
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.")]);
|
|
3045
3097
|
const printNoApiVersionSpecifiedWarning = createWarningPrinter(["Using the Sanity client without specifying an API version is deprecated.", "See ".concat(generateHelpUrl("js-client-api-version"))]);
|
|
3046
|
-
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."]);
|
|
3047
3099
|
const defaultCdnHost = "apicdn.sanity.io";
|
|
3048
3100
|
const defaultConfig = {
|
|
3049
3101
|
apiHost: "https://api.sanity.io",
|
|
@@ -3094,7 +3146,7 @@
|
|
|
3094
3146
|
}
|
|
3095
3147
|
newConfig.apiVersion = "".concat(newConfig.apiVersion).replace(/^v/, "");
|
|
3096
3148
|
newConfig.isDefaultApi = newConfig.apiHost === defaultConfig.apiHost;
|
|
3097
|
-
newConfig.useCdn =
|
|
3149
|
+
newConfig.useCdn = newConfig.useCdn !== false && !newConfig.withCredentials;
|
|
3098
3150
|
validateApiVersion(newConfig.apiVersion);
|
|
3099
3151
|
const hostParts = newConfig.apiHost.split("://", 2);
|
|
3100
3152
|
const protocol = hostParts[0];
|
|
@@ -3771,21 +3823,24 @@
|
|
|
3771
3823
|
return new Transaction(operations, this);
|
|
3772
3824
|
}
|
|
3773
3825
|
/**
|
|
3774
|
-
*
|
|
3826
|
+
* Perform a request against the Sanity API
|
|
3827
|
+
* NOTE: Only use this for Sanity API endpoints, not for your own APIs!
|
|
3775
3828
|
*
|
|
3776
|
-
* @deprecated Use your own request library!
|
|
3777
3829
|
* @param options - Request options
|
|
3830
|
+
* @returns Promise resolving to the response body
|
|
3778
3831
|
*/
|
|
3779
3832
|
request(options) {
|
|
3780
3833
|
return lastValueFrom(_request(this, __privateGet(this, _httpRequest2), options));
|
|
3781
3834
|
}
|
|
3782
3835
|
/**
|
|
3783
|
-
*
|
|
3836
|
+
* Perform an HTTP request a `/data` sub-endpoint
|
|
3837
|
+
* NOTE: Considered internal, thus marked as deprecated. Use `request` instead.
|
|
3784
3838
|
*
|
|
3785
|
-
* @deprecated Use your own
|
|
3839
|
+
* @deprecated - Use `request()` or your own HTTP library instead
|
|
3786
3840
|
* @param endpoint - Endpoint to hit (mutate, query etc)
|
|
3787
3841
|
* @param body - Request body
|
|
3788
3842
|
* @param options - Request options
|
|
3843
|
+
* @internal
|
|
3789
3844
|
*/
|
|
3790
3845
|
dataRequest(endpoint, body, options) {
|
|
3791
3846
|
return lastValueFrom(_dataRequest(this, __privateGet(this, _httpRequest2), endpoint, body, options));
|
|
@@ -3812,9 +3867,12 @@
|
|
|
3812
3867
|
let SanityClient = _SanityClient;
|
|
3813
3868
|
_clientConfig2 = new WeakMap();
|
|
3814
3869
|
_httpRequest2 = new WeakMap();
|
|
3815
|
-
const httpRequest = defineHttpRequest(envMiddleware);
|
|
3870
|
+
const httpRequest = defineHttpRequest(envMiddleware, {});
|
|
3816
3871
|
const requester = httpRequest.defaultRequester;
|
|
3817
|
-
const createClient = config => new SanityClient(
|
|
3872
|
+
const createClient = config => new SanityClient(defineHttpRequest(envMiddleware, {
|
|
3873
|
+
maxRetries: config.maxRetries,
|
|
3874
|
+
retryDelay: config.retryDelay
|
|
3875
|
+
}), config);
|
|
3818
3876
|
function deprecatedCreateClient(config) {
|
|
3819
3877
|
printNoDefaultExport();
|
|
3820
3878
|
return new SanityClient(httpRequest, config);
|
|
@@ -4872,10 +4930,10 @@
|
|
|
4872
4930
|
|
|
4873
4931
|
var browser = eventsourceExports.EventSourcePolyfill;
|
|
4874
4932
|
|
|
4875
|
-
var browser$1 = /*#__PURE__*/
|
|
4933
|
+
var browser$1 = /*#__PURE__*/Object.freeze({
|
|
4876
4934
|
__proto__: null,
|
|
4877
4935
|
default: browser
|
|
4878
|
-
}
|
|
4936
|
+
});
|
|
4879
4937
|
|
|
4880
4938
|
exports.BasePatch = BasePatch;
|
|
4881
4939
|
exports.BaseTransaction = BaseTransaction;
|