@sanity/client 7.26.2 → 8.1.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.
Files changed (133) hide show
  1. package/README.md +63 -341
  2. package/dist/browserUpload-2tz6Sdqp.js +87 -0
  3. package/dist/browserUpload-2tz6Sdqp.js.map +1 -0
  4. package/dist/browserUpload-CwpNx7Vl.js +87 -0
  5. package/dist/browserUpload-CwpNx7Vl.js.map +1 -0
  6. package/dist/config-3wiPP-sZ.js +126 -0
  7. package/dist/config-3wiPP-sZ.js.map +1 -0
  8. package/dist/csm.d.ts +122 -335
  9. package/dist/csm.js +79 -91
  10. package/dist/csm.js.map +1 -1
  11. package/dist/dist-C9ExSk2R.js +73 -0
  12. package/dist/dist-C9ExSk2R.js.map +1 -0
  13. package/dist/dist-Z8cIRxoB.js +69 -0
  14. package/dist/dist-Z8cIRxoB.js.map +1 -0
  15. package/dist/index.d.ts +112 -6722
  16. package/dist/index.js +2950 -2848
  17. package/dist/index.js.map +1 -1
  18. package/dist/{index.d.cts → index.node.d.ts} +4529 -5322
  19. package/dist/index.node.js +3264 -0
  20. package/dist/index.node.js.map +1 -0
  21. package/dist/isRecord-Kfmt-nk-.js +7 -0
  22. package/dist/isRecord-Kfmt-nk-.js.map +1 -0
  23. package/dist/media-library.d.ts +9 -100
  24. package/dist/media-library.js +36 -14
  25. package/dist/media-library.js.map +1 -1
  26. package/dist/request-BhMuKj0D.js +373 -0
  27. package/dist/request-BhMuKj0D.js.map +1 -0
  28. package/dist/request-SnMg7nUX.js +355 -0
  29. package/dist/request-SnMg7nUX.js.map +1 -0
  30. package/dist/resolveEditInfo-Cz-smq3a.js +339 -0
  31. package/dist/resolveEditInfo-Cz-smq3a.js.map +1 -0
  32. package/dist/rolldown-runtime-vyAXikos.js +9 -0
  33. package/dist/stega.d.ts +78 -7137
  34. package/dist/stega.js +27 -20
  35. package/dist/stega.js.map +1 -1
  36. package/dist/stegaClean-C18wLWau.js +21 -0
  37. package/dist/stegaClean-C18wLWau.js.map +1 -0
  38. package/dist/stegaEncodeSourceMap-DbM2fTN4.js +373 -0
  39. package/dist/stegaEncodeSourceMap-DbM2fTN4.js.map +1 -0
  40. package/dist/stegaEncodeSourceMap-YR3NQ3iz.js +163 -0
  41. package/dist/stegaEncodeSourceMap-YR3NQ3iz.js.map +1 -0
  42. package/dist/{index.browser.d.cts → types-BODIEY7F.d.ts} +4196 -5258
  43. package/dist/types-CfGzbXrl.d.ts +108 -0
  44. package/package.json +80 -142
  45. package/src/SanityClient.ts +101 -137
  46. package/src/agent/actions/AgentActionsClient.ts +12 -12
  47. package/src/agent/actions/commonTypes.ts +2 -1
  48. package/src/agent/actions/generate.ts +26 -6
  49. package/src/agent/actions/patch.ts +27 -7
  50. package/src/agent/actions/prompt.ts +19 -5
  51. package/src/agent/actions/transform.ts +23 -5
  52. package/src/agent/actions/translate.ts +23 -5
  53. package/src/assets/AssetsClient.ts +121 -24
  54. package/src/csm/applySourceDocuments.ts +5 -5
  55. package/src/csm/createEditUrl.ts +1 -1
  56. package/src/csm/draftUtils.ts +23 -5
  57. package/src/csm/index.ts +2 -2
  58. package/src/csm/studioPath.ts +2 -1
  59. package/src/csm/types.ts +8 -2
  60. package/src/data/dataMethods.ts +784 -349
  61. package/src/data/eventsource.ts +82 -49
  62. package/src/data/listen.ts +18 -23
  63. package/src/data/live.ts +60 -35
  64. package/src/data/resolveEventSourceFetch.ts +104 -0
  65. package/src/datasets/DatasetsClient.ts +58 -41
  66. package/src/defineCreateClient.ts +38 -22
  67. package/src/functions/FunctionsClient.ts +66 -0
  68. package/src/functions/invoke.ts +176 -0
  69. package/src/http/browserMiddleware.ts +7 -1
  70. package/src/http/browserUpload.ts +163 -0
  71. package/src/http/errors.ts +61 -6
  72. package/src/http/nodeMiddleware.ts +94 -30
  73. package/src/http/request.ts +304 -87
  74. package/src/http/requestOptions.ts +131 -15
  75. package/src/{index.browser.ts → index.node.ts} +9 -4
  76. package/src/index.ts +4 -3
  77. package/src/mediaLibrary/MediaLibraryVideoClient.ts +27 -12
  78. package/src/projects/ProjectsClient.ts +18 -16
  79. package/src/releases/ReleasesClient.ts +38 -33
  80. package/src/stega/index.ts +1 -2
  81. package/src/stega/stegaEncodeSourceMap.ts +5 -0
  82. package/src/stega/types.ts +2 -2
  83. package/src/types.ts +328 -103
  84. package/src/users/UsersClient.ts +10 -14
  85. package/src/util/shareReplayLatest.ts +1 -1
  86. package/src/validators.ts +1 -1
  87. package/src/warnings.ts +13 -2
  88. package/dist/_chunks-cjs/config.cjs +0 -206
  89. package/dist/_chunks-cjs/config.cjs.map +0 -1
  90. package/dist/_chunks-cjs/isRecord.cjs +0 -6
  91. package/dist/_chunks-cjs/isRecord.cjs.map +0 -1
  92. package/dist/_chunks-cjs/resolveEditInfo.cjs +0 -334
  93. package/dist/_chunks-cjs/resolveEditInfo.cjs.map +0 -1
  94. package/dist/_chunks-cjs/stegaClean.cjs +0 -46
  95. package/dist/_chunks-cjs/stegaClean.cjs.map +0 -1
  96. package/dist/_chunks-cjs/stegaEncodeSourceMap.cjs +0 -388
  97. package/dist/_chunks-cjs/stegaEncodeSourceMap.cjs.map +0 -1
  98. package/dist/_chunks-es/config.js +0 -207
  99. package/dist/_chunks-es/config.js.map +0 -1
  100. package/dist/_chunks-es/isRecord.js +0 -7
  101. package/dist/_chunks-es/isRecord.js.map +0 -1
  102. package/dist/_chunks-es/resolveEditInfo.js +0 -335
  103. package/dist/_chunks-es/resolveEditInfo.js.map +0 -1
  104. package/dist/_chunks-es/stegaClean.js +0 -47
  105. package/dist/_chunks-es/stegaClean.js.map +0 -1
  106. package/dist/_chunks-es/stegaEncodeSourceMap.js +0 -389
  107. package/dist/_chunks-es/stegaEncodeSourceMap.js.map +0 -1
  108. package/dist/csm.cjs +0 -99
  109. package/dist/csm.cjs.map +0 -1
  110. package/dist/csm.d.cts +0 -391
  111. package/dist/index.browser.cjs +0 -3106
  112. package/dist/index.browser.cjs.map +0 -1
  113. package/dist/index.browser.d.ts +0 -6802
  114. package/dist/index.browser.js +0 -3082
  115. package/dist/index.browser.js.map +0 -1
  116. package/dist/index.cjs +0 -2946
  117. package/dist/index.cjs.map +0 -1
  118. package/dist/media-library.cjs +0 -20
  119. package/dist/media-library.cjs.map +0 -1
  120. package/dist/media-library.d.cts +0 -117
  121. package/dist/stega.browser.cjs +0 -29
  122. package/dist/stega.browser.cjs.map +0 -1
  123. package/dist/stega.browser.d.cts +0 -7200
  124. package/dist/stega.browser.d.ts +0 -7200
  125. package/dist/stega.browser.js +0 -24
  126. package/dist/stega.browser.js.map +0 -1
  127. package/dist/stega.cjs +0 -29
  128. package/dist/stega.cjs.map +0 -1
  129. package/dist/stega.d.cts +0 -7200
  130. package/src/data/eventsourcePolyfill.ts +0 -7
  131. package/umd/.gitkeep +0 -1
  132. package/umd/sanityClient.js +0 -6543
  133. package/umd/sanityClient.min.js +0 -6
package/src/types.ts CHANGED
@@ -1,17 +1,30 @@
1
1
  // deno-lint-ignore-file no-empty-interface
2
- /* eslint-disable @typescript-eslint/no-empty-object-type */
3
2
 
4
- import type {Requester} from 'get-it'
3
+ import type {FetchFunction, RequestOptions as GetItRequestOptions} from 'get-it'
5
4
  import type {Observable} from 'rxjs'
6
5
 
7
- import type {SanityClient} from './SanityClient'
8
6
  import type {InitializedStegaConfig, StegaConfig} from './stega/types'
9
7
 
8
+ /**
9
+ * Low-level requester returned by `defineRequester(...).observable`.
10
+ * Surfaces as `client.config().requester` and as the named `requester`
11
+ * export.
12
+ *
13
+ * Defined locally rather than imported from `http/request` so api-extractor
14
+ * inlines it into the bundled `.d.ts` instead of emitting a relative import
15
+ * that doesn't survive into `dist/` ([#1290][]).
16
+ *
17
+ * [#1290]: https://github.com/sanity-io/client/issues/1290
18
+ *
19
+ * @public
20
+ */
21
+ export type Requester = (options: Any) => Observable<unknown>
22
+
10
23
  /**
11
24
  * Used to tag types that is set to `any` as a temporary measure, but should be replaced with proper typings in the future
12
25
  * @internal
13
26
  */
14
- export type Any = any // eslint-disable-line @typescript-eslint/no-explicit-any
27
+ export type Any = any // oxlint-disable-line typescript/no-explicit-any
15
28
 
16
29
  declare global {
17
30
  // Declare empty stub interfaces for environments where "dom" lib is not included
@@ -33,6 +46,30 @@ export interface RequestOptions {
33
46
  signal?: AbortSignal
34
47
  }
35
48
 
49
+ /**
50
+ * The fully resolved request passed to a {@link RequestHandler}.
51
+ *
52
+ * @public
53
+ */
54
+ export type RequestHandlerOptions = GetItRequestOptions
55
+
56
+ /**
57
+ * Intercepts a client request around the normal HTTP pipeline.
58
+ *
59
+ * Call `next(request)` to execute the request. It resolves to the parsed
60
+ * response body and rejects with the same errors the client normally exposes,
61
+ * including {@link ClientError} and {@link ServerError}. A handler can modify
62
+ * the request, retry it by calling `next` again, or return a synthetic body.
63
+ *
64
+ * Browser asset uploads and server-sent event connections do not use this handler.
65
+ *
66
+ * @public
67
+ */
68
+ export type RequestHandler = (
69
+ request: RequestHandlerOptions,
70
+ next: (request: RequestHandlerOptions) => Promise<unknown>,
71
+ ) => Promise<unknown>
72
+
36
73
  /**
37
74
  * @public
38
75
  * @deprecated – The `r`-prefix is not required, use `string` instead
@@ -45,11 +82,15 @@ export type ReleaseId = `r${string}`
45
82
  type DeprecatedPreviewDrafts = 'previewDrafts'
46
83
 
47
84
  /** @public */
48
- export type StackablePerspective = ('published' | 'drafts' | string) & {}
85
+ export type StackablePerspective = 'published' | 'drafts' | (string & {})
49
86
 
50
87
  /** @public */
51
88
  export type ClientPerspective =
52
- DeprecatedPreviewDrafts | 'published' | 'drafts' | 'raw' | StackablePerspective[]
89
+ | DeprecatedPreviewDrafts
90
+ | 'published'
91
+ | 'drafts'
92
+ | 'raw'
93
+ | StackablePerspective[]
53
94
 
54
95
  /**
55
96
  * @public
@@ -130,6 +171,12 @@ export interface ClientConfig {
130
171
  * As of API version `v2025-02-19`, the default perspective has changed from `raw` to `published`. {@link https://www.sanity.io/changelog/676aaa9d-2da6-44fb-abe5-580f28047c10|Changelog}
131
172
  */
132
173
  apiVersion?: string
174
+ /**
175
+ * Route requests through an HTTP(S) proxy. Node.js only. Can be replaced
176
+ * on an existing client via `client.config({proxy})` or
177
+ * `client.withConfig({proxy})`. For environment-driven proxying, set
178
+ * `HTTP_PROXY`/`HTTPS_PROXY`/`NO_PROXY` before the process starts.
179
+ */
133
180
  proxy?: string
134
181
 
135
182
  /**
@@ -137,6 +184,20 @@ export interface ClientConfig {
137
184
  */
138
185
  requestTagPrefix?: string
139
186
 
187
+ /**
188
+ * Intercepts requests after the client has resolved their URL, headers, and
189
+ * transport options. The handler wraps the normal client pipeline, so errors
190
+ * from `next` are already converted to {@link ClientError} or
191
+ * {@link ServerError}.
192
+ *
193
+ * A handler supplied through `withConfig()` replaces the current handler.
194
+ * To compose handlers, read the current handler from `client.config()` and
195
+ * call it from the replacement.
196
+ *
197
+ * Browser asset uploads and server-sent event connections are not intercepted.
198
+ */
199
+ requestHandler?: RequestHandler
200
+
140
201
  /**
141
202
  * Optional default headers to include with all requests
142
203
  *
@@ -192,16 +253,33 @@ export interface ClientConfig {
192
253
  useProjectHostname?: boolean
193
254
 
194
255
  /**
195
- * @deprecated Don't use
256
+ * Resolves the fetch implementation every request (including EventSource
257
+ * connections) goes through. Defaults to the environment entry point's
258
+ * fetch — the Node entry supplies get-it's undici-backed fetch (resolved
259
+ * via the entry point instead of a direct import so `get-it/node`/`undici`
260
+ * stays out of the browser bundle), the browser entry leaves it unset (the
261
+ * global fetch IS the environment's fetch there). Receives the explicit
262
+ * `proxy` config, when set, as its argument.
263
+ *
264
+ * Supplying it in the client config replaces the transport wholesale —
265
+ * custom fetch variants, alternative undici configurations, or a mock
266
+ * (the test suite injects `get-it/mock` this way).
267
+ *
268
+ * Returns get-it's minimal `FetchFunction` contract rather than the full
269
+ * `typeof fetch` — that is what the environments actually provide, and
270
+ * every consumer (the transport, the EventSource fetch resolver) only
271
+ * needs that subset.
272
+ *
273
+ * @internal
196
274
  */
197
- requester?: Requester
275
+ resolveFetch?: (proxyUrl?: string) => FetchFunction
198
276
 
199
277
  /**
200
278
  * Adds a `resultSourceMap` key to the API response, with the type `ContentSourceMap`
201
279
  */
202
280
  resultSourceMap?: boolean | 'withKeyArraySelector'
203
281
  /**
204
- *@deprecated set `cache` and `next` options on `client.fetch` instead
282
+ * @deprecated set `cache` and `next` options on `client.fetch` instead
205
283
  */
206
284
  fetch?:
207
285
  | {
@@ -217,33 +295,15 @@ export interface ClientConfig {
217
295
  * Lineage token for recursion control
218
296
  */
219
297
  lineage?: string
220
-
221
298
  /**
222
- * A custom request handler that intercepts all HTTP requests made by the client.
223
- *
224
- * Useful for logging, adding custom headers, refreshing auth tokens, rate limiting, etc.
225
- *
226
- * When using `withConfig()`, the new handler **replaces** the previous one (it does not
227
- * wrap it). To compose handlers, you can chain them manually:
228
- *
229
- * ```ts
230
- * const parent = createClient({...config, _requestHandler: handlerA})
231
- * const child = parent.withConfig({
232
- * _requestHandler: (req, defaultRequester) =>
233
- * handlerB(req, (opts) => handlerA(opts, defaultRequester)),
234
- * })
235
- * ```
236
- *
237
- * Setting `_requestHandler` to `undefined` via `withConfig()` removes the handler.
238
- *
239
- * Note: This only applies to HTTP requests. Real-time listener connections
240
- * (`client.listen()`) use EventSource and are not intercepted by this handler.
241
- *
242
- * @internal
243
- * @deprecated Don't use outside of Sanity internals
244
- * @see {@link RequestHandler}
299
+ * ID of the blueprints stack that `functions.invoke()` resolves function
300
+ * names against. Function names are unique within a stack
301
+ */
302
+ stackId?: string
303
+ /**
304
+ * ID of the organization owning the blueprints stack
245
305
  */
246
- _requestHandler?: RequestHandler
306
+ organizationId?: string
247
307
  }
248
308
 
249
309
  /** @public */
@@ -270,6 +330,14 @@ export interface InitializedClientConfig extends ClientConfig {
270
330
  * The fully initialized stega config, can be used to check if stega is enabled
271
331
  */
272
332
  stega: InitializedStegaConfig
333
+ /**
334
+ * The resolved low-level requester for this client. Always populated by
335
+ * `createClient` so internal paths (e.g. the asset upload event stream) can
336
+ * reach the underlying transport.
337
+ *
338
+ * @internal
339
+ */
340
+ requester: Requester
273
341
  /**
274
342
  * Default headers to include with all requests
275
343
  *
@@ -280,7 +348,14 @@ export interface InitializedClientConfig extends ClientConfig {
280
348
 
281
349
  /** @public */
282
350
  export type AssetMetadataType =
283
- 'location' | 'exif' | 'image' | 'palette' | 'lqip' | 'blurhash' | 'thumbhash' | 'none'
351
+ | 'location'
352
+ | 'exif'
353
+ | 'image'
354
+ | 'palette'
355
+ | 'lqip'
356
+ | 'blurhash'
357
+ | 'thumbhash'
358
+ | 'none'
284
359
 
285
360
  /** @public */
286
361
  export interface UploadClientConfig {
@@ -300,7 +375,10 @@ export interface UploadClientConfig {
300
375
  filename?: string
301
376
 
302
377
  /**
303
- * Milliseconds to wait before timing the request out
378
+ * Milliseconds to wait before timing the request out.
379
+ *
380
+ * Unlike other requests, uploads have NO timeout unless one is explicitly
381
+ * set here — uploads can legitimately be slow, so timing out is opt-in.
304
382
  */
305
383
  timeout?: number
306
384
 
@@ -442,63 +520,56 @@ export interface ErrorProps {
442
520
  details: Any
443
521
  }
444
522
 
445
- /** @public */
523
+ /**
524
+ * The internal HTTP request abstraction used by the client. Resolves directly
525
+ * to the parsed response body as a Promise — middleware-level transport
526
+ * details (status codes, headers, progress events) are not exposed. The
527
+ * observable client surface wraps this in an Observable; the promise surface
528
+ * uses it directly.
529
+ *
530
+ * The body is typed as `unknown`; consumers narrow at their own boundary.
531
+ *
532
+ * @internal
533
+ */
446
534
  export type HttpRequest = {
447
- (options: RequestOptions, requester: Requester): ReturnType<Requester>
535
+ (options: Any, requestHandler?: RequestHandler): Promise<unknown>
448
536
  }
449
537
 
450
538
  /**
451
- * A function that intercepts HTTP requests made by the client.
452
- *
453
- * Receives the resolved request options, a `defaultRequester` function that
454
- * executes the request through the normal pipeline, and a `client` instance
455
- * without a `_requestHandler` (to avoid recursive interception).
456
- *
457
- * The consumer can:
458
- * - Modify request options before calling `defaultRequester`
459
- * - Transform the response stream (e.g. via `pipe`)
460
- * - Skip `defaultRequester` entirely and return a custom Observable
461
- * - Use `client` to make additional requests (e.g. refresh an auth token on 401)
462
- *
463
- * When set via `withConfig()`, the new handler **replaces** (not wraps) the previous one.
464
- *
465
- * Note: This only applies to HTTP requests. Real-time listener connections
466
- * (`client.listen()`) use EventSource and are not intercepted by this handler.
467
- *
468
- * @param request - The resolved request options including `url`
469
- * @param defaultRequester - Executes the request through the normal pipeline
470
- * @param client - A client instance with the same configuration but without a `_requestHandler`,
471
- * useful for making side requests (e.g. token refresh) without triggering the handler recursively
539
+ * Target URL for a request. Exactly one of `url` or the deprecated `uri` alias
540
+ * must be given.
472
541
  *
473
542
  * @internal
474
- * @deprecated Don't use outside of Sanity internals
475
543
  */
476
- export type RequestHandler = (
477
- request: RequestOptions & {url: string},
478
- defaultRequester: (options: RequestOptions & {url: string}) => Observable<HttpRequestEvent>,
479
- client: SanityClient,
480
- ) => Observable<HttpRequestEvent>
544
+ export type RequestUrlOptions =
545
+ | {url: string; uri?: never}
546
+ | {
547
+ /**
548
+ * @deprecated Use `url` instead. Support for `uri` will be removed in a future version.
549
+ */
550
+ uri: string
551
+ url?: never
552
+ }
481
553
 
482
554
  /** @internal */
483
- export interface RequestObservableOptions extends Omit<RequestOptions, 'url'> {
484
- url?: string
485
- uri?: string
486
- canUseCdn?: boolean
487
- useCdn?: boolean
488
- tag?: string
489
- returnQuery?: boolean
490
- resultSourceMap?: boolean | 'withKeyArraySelector'
491
- perspective?: ClientPerspective
492
- /**
493
- * @beta
494
- */
495
- variant?: ClientVariant
496
- lastLiveEventId?: string
497
- cacheMode?: 'noStale'
498
- }
555
+ export type RequestObservableOptions = RequestUrlOptions &
556
+ Omit<RequestOptions, 'url'> & {
557
+ canUseCdn?: boolean
558
+ useCdn?: boolean
559
+ tag?: string
560
+ returnQuery?: boolean
561
+ resultSourceMap?: boolean | 'withKeyArraySelector'
562
+ perspective?: ClientPerspective
563
+ /**
564
+ * @beta
565
+ */
566
+ variant?: ClientVariant
567
+ lastLiveEventId?: string
568
+ cacheMode?: 'noStale'
569
+ }
499
570
 
500
571
  /** @public */
501
- export interface ProgressEvent {
572
+ export interface UploadProgressEvent {
502
573
  type: 'progress'
503
574
  stage: 'upload' | 'download'
504
575
  percent: number
@@ -508,18 +579,20 @@ export interface ProgressEvent {
508
579
  }
509
580
 
510
581
  /** @public */
511
- export interface ResponseEvent<T = unknown> {
582
+ export interface UploadResponseEvent<T = unknown> {
512
583
  type: 'response'
513
584
  body: T
514
- url: string
515
- method: string
516
- statusCode: number
517
- statusMessage?: string
518
- headers: Record<string, string>
519
585
  }
520
586
 
521
- /** @public */
522
- export type HttpRequestEvent<T = unknown> = ResponseEvent<T> | ProgressEvent
587
+ /**
588
+ * Events emitted by `client.assets.upload()` when called via the observable
589
+ * API. Progress events are best-effort — they're only emitted when the
590
+ * environment supports tracking upload/download bytes (e.g. browsers via
591
+ * `XMLHttpRequest`). Other runtimes only emit the terminal `response` event.
592
+ *
593
+ * @public
594
+ */
595
+ export type UploadEvent<T = unknown> = UploadResponseEvent<T> | UploadProgressEvent
523
596
 
524
597
  /** @internal */
525
598
  export interface AuthProvider {
@@ -652,7 +725,9 @@ export type IdentifiedSanityDocumentStub<T extends Record<string, Any> = Record<
652
725
 
653
726
  /** @internal */
654
727
  export type InsertPatch =
655
- {before: string; items: Any[]} | {after: string; items: Any[]} | {replace: string; items: Any[]}
728
+ | {before: string; items: Any[]}
729
+ | {after: string; items: Any[]}
730
+ | {replace: string; items: Any[]}
656
731
 
657
732
  // Note: this is actually incorrect/invalid, but implemented as-is for backwards compatibility
658
733
  /** @internal */
@@ -669,7 +744,7 @@ export interface PatchOperations {
669
744
 
670
745
  /** @public */
671
746
  export interface QueryParams {
672
- /* eslint-disable @typescript-eslint/no-explicit-any */
747
+ /* oxlint-disable typescript/no-explicit-any */
673
748
  [key: string]: any
674
749
  /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
675
750
  body?: never
@@ -709,7 +784,7 @@ export interface QueryParams {
709
784
  lastLiveEventId?: never
710
785
  /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
711
786
  cacheMode?: never
712
- /* eslint-enable @typescript-eslint/no-explicit-any */
787
+ /* oxlint-enable typescript/no-explicit-any */
713
788
  }
714
789
 
715
790
  /**
@@ -722,7 +797,8 @@ export type QueryWithoutParams = Record<string, never> | undefined
722
797
  export type MutationSelectionQueryParams = {[key: string]: Any}
723
798
  /** @internal */
724
799
  export type MutationSelection =
725
- {query: string; params?: MutationSelectionQueryParams} | {id: string | string[]}
800
+ | {query: string; params?: MutationSelectionQueryParams}
801
+ | {id: string | string[]}
726
802
  /** @internal */
727
803
  export type PatchSelection = string | string[] | MutationSelection
728
804
  /** @internal */
@@ -748,9 +824,21 @@ export type ReleaseAction =
748
824
  | DeleteReleaseAction
749
825
  | ImportReleaseAction
750
826
 
827
+ /**
828
+ * @public
829
+ * @beta
830
+ */
831
+ export type VariantDefinitionAction =
832
+ | CreateVariantDefinitionAction
833
+ | EditVariantDefinitionAction
834
+ | DeleteVariantDefinitionAction
835
+
751
836
  /** @public */
752
837
  export type VersionAction =
753
- CreateVersionAction | DiscardVersionAction | ReplaceVersionAction | UnpublishVersionAction
838
+ | CreateVersionAction
839
+ | DiscardVersionAction
840
+ | ReplaceVersionAction
841
+ | UnpublishVersionAction
754
842
 
755
843
  /** @public */
756
844
  export type Action =
@@ -763,6 +851,7 @@ export type Action =
763
851
  | UnpublishAction
764
852
  | VersionAction
765
853
  | ReleaseAction
854
+ | VariantDefinitionAction
766
855
 
767
856
  /** @public */
768
857
  export type ImportReleaseAction =
@@ -920,6 +1009,88 @@ export interface UnpublishVersionAction {
920
1009
  publishedId: string
921
1010
  }
922
1011
 
1012
+ /**
1013
+ * Creates a new `system.variant` definition document.
1014
+ *
1015
+ * @public
1016
+ * @beta
1017
+ */
1018
+ export interface CreateVariantDefinitionAction {
1019
+ actionType: 'sanity.action.variant.definition.create'
1020
+
1021
+ /**
1022
+ * Name of the variant definition to create, as in
1023
+ * `_.variants.{variantName}`. Must be a bare name, not a full document ID.
1024
+ */
1025
+ variantId: string
1026
+
1027
+ /**
1028
+ * Conditions used to select this variant.
1029
+ */
1030
+ conditions?: ClientVariantConditions
1031
+
1032
+ /**
1033
+ * Selection priority. Higher values are preferred when multiple variants
1034
+ * match.
1035
+ *
1036
+ * Defaults to `0`.
1037
+ */
1038
+ priority?: number
1039
+
1040
+ metadata?: Record<string, Any>
1041
+ }
1042
+
1043
+ /**
1044
+ * Edits an existing variant definition.
1045
+ *
1046
+ * @public
1047
+ * @beta
1048
+ */
1049
+ export interface EditVariantDefinitionAction {
1050
+ actionType: 'sanity.action.variant.definition.edit'
1051
+
1052
+ /**
1053
+ * Name of the variant definition to edit, as in `_.variants.{variantName}`.
1054
+ * Must be a bare name, not a full document ID.
1055
+ */
1056
+ variantId: string
1057
+
1058
+ /**
1059
+ * Patch operations to apply.
1060
+ */
1061
+ patch: PatchOperations
1062
+
1063
+ /**
1064
+ * When set, the action fails unless the current revision of the variant
1065
+ * definition matches this value.
1066
+ */
1067
+ ifRevisionId?: string
1068
+ }
1069
+
1070
+ /**
1071
+ * Deletes a variant definition.
1072
+ *
1073
+ * Deletion fails if any document holds a strong reference to this variant.
1074
+ *
1075
+ * @public
1076
+ * @beta
1077
+ */
1078
+ export interface DeleteVariantDefinitionAction {
1079
+ actionType: 'sanity.action.variant.definition.delete'
1080
+
1081
+ /**
1082
+ * Name of the variant definition to delete, as in
1083
+ * `_.variants.{variantName}`. Must be a bare name, not a full document ID.
1084
+ */
1085
+ variantId: string
1086
+
1087
+ /**
1088
+ * When set, the action fails unless the current revision of the variant
1089
+ * definition matches this value.
1090
+ */
1091
+ ifRevisionId?: string
1092
+ }
1093
+
923
1094
  /**
924
1095
  * Creates a new draft document. The published version of the document must not already exist.
925
1096
  * If the draft version of the document already exists the action will fail by default, but
@@ -1296,7 +1467,12 @@ export type ResetEvent = {
1296
1467
 
1297
1468
  /** @public */
1298
1469
  export type ListenEvent<R extends Record<string, Any> = Record<string, Any>> =
1299
- MutationEvent<R> | ReconnectEvent | WelcomeBackEvent | ResetEvent | WelcomeEvent | OpenEvent
1470
+ | MutationEvent<R>
1471
+ | ReconnectEvent
1472
+ | WelcomeBackEvent
1473
+ | ResetEvent
1474
+ | WelcomeEvent
1475
+ | OpenEvent
1300
1476
 
1301
1477
  /** @public */
1302
1478
  export type ListenEventName =
@@ -1476,7 +1652,9 @@ export interface UnfilteredResponseWithoutQuery extends ResponseQueryOptions {
1476
1652
 
1477
1653
  /** @public */
1478
1654
  export type QueryOptions =
1479
- FilteredResponseQueryOptions | UnfilteredResponseQueryOptions | UnfilteredResponseWithoutQuery
1655
+ | FilteredResponseQueryOptions
1656
+ | UnfilteredResponseQueryOptions
1657
+ | UnfilteredResponseWithoutQuery
1480
1658
 
1481
1659
  /** @public */
1482
1660
  export interface RawQueryResponse<R> {
@@ -1595,11 +1773,10 @@ export interface MultipleActionResult {
1595
1773
  }
1596
1774
 
1597
1775
  /** @internal */
1598
- export interface RawRequestOptions {
1599
- url?: string
1600
- uri?: string
1776
+ export type RawRequestOptions = RequestUrlOptions & {
1601
1777
  method?: string
1602
1778
  token?: string
1779
+ /** @deprecated has no effect — response parsing is driven by the response `content-type` */
1603
1780
  json?: boolean
1604
1781
  tag?: string
1605
1782
  useGlobalApi?: boolean
@@ -1607,9 +1784,10 @@ export interface RawRequestOptions {
1607
1784
  query?: {[key: string]: string | string[]}
1608
1785
  headers?: {[key: string]: string}
1609
1786
  timeout?: number
1610
- proxy?: string
1611
1787
  body?: Any
1612
1788
  maxRedirects?: number
1789
+ /** Max retries for this request; `0` disables retries. Overrides the client-level maximum in both directions. */
1790
+ maxRetries?: number
1613
1791
  signal?: AbortSignal
1614
1792
  }
1615
1793
 
@@ -1805,7 +1983,8 @@ export interface ContentSourceMapRemoteDocument extends ContentSourceMapDocument
1805
1983
 
1806
1984
  /** @public */
1807
1985
  export type ContentSourceMapDocuments = (
1808
- ContentSourceMapDocument | ContentSourceMapRemoteDocument
1986
+ | ContentSourceMapDocument
1987
+ | ContentSourceMapRemoteDocument
1809
1988
  )[]
1810
1989
 
1811
1990
  /** @public */
@@ -1851,7 +2030,11 @@ export interface LiveEventGoAway {
1851
2030
  }
1852
2031
  /** @public */
1853
2032
  export type LiveEvent =
1854
- LiveEventRestart | LiveEventReconnect | LiveEventMessage | LiveEventWelcome | LiveEventGoAway
2033
+ | LiveEventRestart
2034
+ | LiveEventReconnect
2035
+ | LiveEventMessage
2036
+ | LiveEventWelcome
2037
+ | LiveEventGoAway
1855
2038
 
1856
2039
  /** @public */
1857
2040
  export interface SanityQueries {}
@@ -1895,6 +2078,7 @@ export type {
1895
2078
  TranslateTarget,
1896
2079
  TranslateTargetInclude,
1897
2080
  } from './agent/actions/translate'
2081
+ export type {InvokeFunctionEvent, InvokeFunctionRequest} from './functions/invoke'
1898
2082
  export type {
1899
2083
  ContentSourceMapParsedPath,
1900
2084
  ContentSourceMapParsedPathKeyedSegment,
@@ -2116,3 +2300,44 @@ export interface VideoPlaybackTokens {
2116
2300
 
2117
2301
  /** @public */
2118
2302
  export type MediaLibraryAssetInstanceIdentifier = string | SanityReference
2303
+
2304
+ /**
2305
+ * A single tracked version of a Media Library asset - one uploaded instance,
2306
+ * referencing the underlying (Content Lake shaped) asset document it wraps.
2307
+ *
2308
+ * @public
2309
+ */
2310
+ export interface MediaLibraryAssetVersion {
2311
+ _key: string
2312
+ _type: 'sanity.asset.version'
2313
+ title?: string
2314
+ instance: SanityReference
2315
+ }
2316
+
2317
+ /**
2318
+ * The document returned by the Media Library upload endpoint
2319
+ * (`POST /media-libraries/:id/upload`).
2320
+ *
2321
+ * This is _not_ the same shape as {@link SanityAssetDocument} /
2322
+ * {@link SanityImageAssetDocument}: a Media Library asset is a `sanity.asset`
2323
+ * document that tracks one or more uploaded versions, each pointing at its
2324
+ * own underlying Content Lake asset document via `currentVersion`/`versions`.
2325
+ *
2326
+ * Modelled directly on an observed API response. Fields whose full shape has
2327
+ * not been confirmed (`parent`, `rootDirectory`, `aspects`) are typed loosely
2328
+ * on purpose - widen them once their shape is confirmed.
2329
+ *
2330
+ * @public
2331
+ */
2332
+ export interface MediaLibraryAssetDocument {
2333
+ _id: string
2334
+ _type: 'sanity.asset'
2335
+ assetType: string
2336
+ title?: string
2337
+ cdnAccessPolicy?: string
2338
+ currentVersion: SanityReference
2339
+ versions: MediaLibraryAssetVersion[]
2340
+ aspects?: Record<string, Any>
2341
+ parent?: SanityReference | null
2342
+ rootDirectory?: Any
2343
+ }
@@ -1,6 +1,6 @@
1
- import {lastValueFrom, type Observable} from 'rxjs'
1
+ import {type Observable} from 'rxjs'
2
2
 
3
- import {_request} from '../data/dataMethods'
3
+ import {_request, _requestObservable} from '../data/dataMethods'
4
4
  import type {ObservableSanityClient, SanityClient} from '../SanityClient'
5
5
  import type {CurrentSanityUser, HttpRequest, SanityUser} from '../types'
6
6
 
@@ -18,13 +18,11 @@ export class ObservableUsersClient {
18
18
  *
19
19
  * @param id - User ID of the user to fetch. If `me` is provided, a minimal response including the users role is returned.
20
20
  */
21
- getById<T extends 'me' | string>(
22
- id: T,
23
- ): Observable<T extends 'me' ? CurrentSanityUser : SanityUser> {
24
- return _request<T extends 'me' ? CurrentSanityUser : SanityUser>(
21
+ getById<T extends string>(id: T): Observable<T extends 'me' ? CurrentSanityUser : SanityUser> {
22
+ return _requestObservable<T extends 'me' ? CurrentSanityUser : SanityUser>(
25
23
  this.#client,
26
24
  this.#httpRequest,
27
- {uri: `/users/${id}`},
25
+ {url: `/users/${id}`},
28
26
  )
29
27
  }
30
28
  }
@@ -43,13 +41,11 @@ export class UsersClient {
43
41
  *
44
42
  * @param id - User ID of the user to fetch. If `me` is provided, a minimal response including the users role is returned.
45
43
  */
46
- getById<T extends 'me' | string>(
47
- id: T,
48
- ): Promise<T extends 'me' ? CurrentSanityUser : SanityUser> {
49
- return lastValueFrom(
50
- _request<T extends 'me' ? CurrentSanityUser : SanityUser>(this.#client, this.#httpRequest, {
51
- uri: `/users/${id}`,
52
- }),
44
+ getById<T extends string>(id: T): Promise<T extends 'me' ? CurrentSanityUser : SanityUser> {
45
+ return _request<T extends 'me' ? CurrentSanityUser : SanityUser>(
46
+ this.#client,
47
+ this.#httpRequest,
48
+ {url: `/users/${id}`},
53
49
  )
54
50
  }
55
51
  }