@sanity/client 7.26.2 → 8.0.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 (130) hide show
  1. package/README.md +5 -377
  2. package/dist/browserUpload-CQgx9YYo.js +86 -0
  3. package/dist/browserUpload-CQgx9YYo.js.map +1 -0
  4. package/dist/browserUpload-icWlVP15.js +86 -0
  5. package/dist/browserUpload-icWlVP15.js.map +1 -0
  6. package/dist/config-a8VajuEY.js +126 -0
  7. package/dist/config-a8VajuEY.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 +107 -6723
  16. package/dist/index.js +2822 -2847
  17. package/dist/index.js.map +1 -1
  18. package/dist/{index.d.cts → index.node.d.ts} +4291 -5328
  19. package/dist/index.node.js +3131 -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-CJxcN16k.js +372 -0
  27. package/dist/request-CJxcN16k.js.map +1 -0
  28. package/dist/request-k7VS_NnC.js +354 -0
  29. package/dist/request-k7VS_NnC.js.map +1 -0
  30. package/dist/resolveEditInfo-sq7yF78q.js +325 -0
  31. package/dist/resolveEditInfo-sq7yF78q.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-B2fGArSf.js +163 -0
  39. package/dist/stegaEncodeSourceMap-B2fGArSf.js.map +1 -0
  40. package/dist/stegaEncodeSourceMap-DkoIlutY.js +367 -0
  41. package/dist/stegaEncodeSourceMap-DkoIlutY.js.map +1 -0
  42. package/dist/{index.browser.d.cts → types-CUxZSgB2.d.ts} +3956 -5256
  43. package/dist/types-CfGzbXrl.d.ts +108 -0
  44. package/package.json +64 -141
  45. package/src/SanityClient.ts +82 -117
  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 +71 -23
  54. package/src/csm/applySourceDocuments.ts +3 -1
  55. package/src/csm/createEditUrl.ts +1 -1
  56. package/src/csm/draftUtils.ts +0 -1
  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 +801 -349
  61. package/src/data/eventsource.ts +13 -10
  62. package/src/data/listen.ts +18 -23
  63. package/src/data/live.ts +44 -27
  64. package/src/data/resolveEventSourceFetch.ts +96 -0
  65. package/src/datasets/DatasetsClient.ts +58 -41
  66. package/src/defineCreateClient.ts +35 -23
  67. package/src/http/browserMiddleware.ts +7 -1
  68. package/src/http/browserUpload.ts +162 -0
  69. package/src/http/errors.ts +60 -6
  70. package/src/http/nodeMiddleware.ts +94 -30
  71. package/src/http/request.ts +310 -87
  72. package/src/http/requestOptions.ts +131 -15
  73. package/src/{index.browser.ts → index.node.ts} +9 -4
  74. package/src/index.ts +4 -3
  75. package/src/mediaLibrary/MediaLibraryVideoClient.ts +26 -11
  76. package/src/projects/ProjectsClient.ts +18 -16
  77. package/src/releases/ReleasesClient.ts +38 -33
  78. package/src/stega/index.ts +1 -2
  79. package/src/stega/stegaEncodeSourceMap.ts +5 -0
  80. package/src/stega/types.ts +2 -2
  81. package/src/types.ts +148 -105
  82. package/src/users/UsersClient.ts +10 -14
  83. package/src/util/shareReplayLatest.ts +1 -1
  84. package/src/warnings.ts +6 -1
  85. package/dist/_chunks-cjs/config.cjs +0 -206
  86. package/dist/_chunks-cjs/config.cjs.map +0 -1
  87. package/dist/_chunks-cjs/isRecord.cjs +0 -6
  88. package/dist/_chunks-cjs/isRecord.cjs.map +0 -1
  89. package/dist/_chunks-cjs/resolveEditInfo.cjs +0 -334
  90. package/dist/_chunks-cjs/resolveEditInfo.cjs.map +0 -1
  91. package/dist/_chunks-cjs/stegaClean.cjs +0 -46
  92. package/dist/_chunks-cjs/stegaClean.cjs.map +0 -1
  93. package/dist/_chunks-cjs/stegaEncodeSourceMap.cjs +0 -388
  94. package/dist/_chunks-cjs/stegaEncodeSourceMap.cjs.map +0 -1
  95. package/dist/_chunks-es/config.js +0 -207
  96. package/dist/_chunks-es/config.js.map +0 -1
  97. package/dist/_chunks-es/isRecord.js +0 -7
  98. package/dist/_chunks-es/isRecord.js.map +0 -1
  99. package/dist/_chunks-es/resolveEditInfo.js +0 -335
  100. package/dist/_chunks-es/resolveEditInfo.js.map +0 -1
  101. package/dist/_chunks-es/stegaClean.js +0 -47
  102. package/dist/_chunks-es/stegaClean.js.map +0 -1
  103. package/dist/_chunks-es/stegaEncodeSourceMap.js +0 -389
  104. package/dist/_chunks-es/stegaEncodeSourceMap.js.map +0 -1
  105. package/dist/csm.cjs +0 -99
  106. package/dist/csm.cjs.map +0 -1
  107. package/dist/csm.d.cts +0 -391
  108. package/dist/index.browser.cjs +0 -3106
  109. package/dist/index.browser.cjs.map +0 -1
  110. package/dist/index.browser.d.ts +0 -6802
  111. package/dist/index.browser.js +0 -3082
  112. package/dist/index.browser.js.map +0 -1
  113. package/dist/index.cjs +0 -2946
  114. package/dist/index.cjs.map +0 -1
  115. package/dist/media-library.cjs +0 -20
  116. package/dist/media-library.cjs.map +0 -1
  117. package/dist/media-library.d.cts +0 -117
  118. package/dist/stega.browser.cjs +0 -29
  119. package/dist/stega.browser.cjs.map +0 -1
  120. package/dist/stega.browser.d.cts +0 -7200
  121. package/dist/stega.browser.d.ts +0 -7200
  122. package/dist/stega.browser.js +0 -24
  123. package/dist/stega.browser.js.map +0 -1
  124. package/dist/stega.cjs +0 -29
  125. package/dist/stega.cjs.map +0 -1
  126. package/dist/stega.d.cts +0 -7200
  127. package/src/data/eventsourcePolyfill.ts +0 -7
  128. package/umd/.gitkeep +0 -1
  129. package/umd/sanityClient.js +0 -6543
  130. package/umd/sanityClient.min.js +0 -6
@@ -1,6 +1,6 @@
1
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 {
6
6
  AgentActionPath,
@@ -16,7 +16,7 @@ import type {AgentActionAsync, AgentActionSchema, AgentActionSync} from './commo
16
16
  /** @beta */
17
17
  export type PatchOperation = 'set' | 'append' | 'mixed' | 'unset'
18
18
 
19
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
19
+ // oxlint-disable-next-line typescript/no-explicit-any
20
20
  type AnyNonNullable = Exclude<any, null | undefined>
21
21
 
22
22
  /** @beta */
@@ -99,23 +99,26 @@ interface PatchTargetDocumentRequest<T extends Record<string, Any> = Record<stri
99
99
 
100
100
  /** @beta */
101
101
  export type PatchDocumentSync<T extends Record<string, Any> = Record<string, Any>> = (
102
- PatchExistingDocumentRequest | PatchTargetDocumentRequest<T>
102
+ | PatchExistingDocumentRequest
103
+ | PatchTargetDocumentRequest<T>
103
104
  ) &
104
105
  PatchRequestBase &
105
106
  AgentActionSync
106
107
 
107
108
  /** @beta */
108
109
  export type PatchDocumentAsync<T extends Record<string, Any> = Record<string, Any>> = (
109
- PatchExistingDocumentRequest | PatchTargetDocumentRequest<T>
110
+ | PatchExistingDocumentRequest
111
+ | PatchTargetDocumentRequest<T>
110
112
  ) &
111
113
  PatchRequestBase &
112
114
  AgentActionAsync
113
115
 
114
116
  /** @beta */
115
117
  export type PatchDocument<T extends Record<string, Any> = Record<string, Any>> =
116
- PatchDocumentSync<T> | PatchDocumentAsync<T>
118
+ | PatchDocumentSync<T>
119
+ | PatchDocumentAsync<T>
117
120
 
118
- export function _patch<DocumentShape extends Record<string, Any>>(
121
+ export function _patchObservable<DocumentShape extends Record<string, Any>>(
119
122
  client: SanityClient | ObservableSanityClient,
120
123
  httpRequest: HttpRequest,
121
124
  request: PatchDocument<DocumentShape>,
@@ -123,11 +126,28 @@ export function _patch<DocumentShape extends Record<string, Any>>(
123
126
  (typeof request)['async'] extends true
124
127
  ? {_id: string}
125
128
  : IdentifiedSanityDocumentStub & DocumentShape
129
+ > {
130
+ const dataset = hasDataset(client.config())
131
+ return _requestObservable(client, httpRequest, {
132
+ method: 'POST',
133
+ url: `/agent/action/patch/${dataset}`,
134
+ body: request,
135
+ })
136
+ }
137
+
138
+ export function _patch<DocumentShape extends Record<string, Any>>(
139
+ client: SanityClient | ObservableSanityClient,
140
+ httpRequest: HttpRequest,
141
+ request: PatchDocument<DocumentShape>,
142
+ ): Promise<
143
+ (typeof request)['async'] extends true
144
+ ? {_id: string}
145
+ : IdentifiedSanityDocumentStub & DocumentShape
126
146
  > {
127
147
  const dataset = hasDataset(client.config())
128
148
  return _request(client, httpRequest, {
129
149
  method: 'POST',
130
- uri: `/agent/action/patch/${dataset}`,
150
+ url: `/agent/action/patch/${dataset}`,
131
151
  body: request,
132
152
  })
133
153
  }
@@ -1,6 +1,6 @@
1
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 {AgentActionParams, Any, HttpRequest} from '../../types'
6
6
  import {hasDataset} from '../../validators'
@@ -101,7 +101,7 @@ export interface PromptRequestBase {
101
101
  * @beta
102
102
  */
103
103
  // need the unused generic here to allow for optional callsite casting
104
- // eslint-disable-next-line unused-imports/no-unused-vars
104
+ // oxlint-disable-next-line no-unused-vars
105
105
  interface PromptJsonResponse<T extends Record<string, Any> = Record<string, Any>> {
106
106
  /**
107
107
  *
@@ -120,19 +120,33 @@ interface PromptTextResponse {
120
120
 
121
121
  /** @beta */
122
122
  export type PromptRequest<T extends Record<string, Any> = Record<string, Any>> = (
123
- PromptTextResponse | PromptJsonResponse<T>
123
+ | PromptTextResponse
124
+ | PromptJsonResponse<T>
124
125
  ) &
125
126
  PromptRequestBase
126
127
 
127
- export function _prompt<const DocumentShape extends Record<string, Any>>(
128
+ export function _promptObservable<const DocumentShape extends Record<string, Any>>(
128
129
  client: SanityClient | ObservableSanityClient,
129
130
  httpRequest: HttpRequest,
130
131
  request: PromptRequest<DocumentShape>,
131
132
  ): Observable<(typeof request)['format'] extends 'json' ? DocumentShape : string> {
133
+ const dataset = hasDataset(client.config())
134
+ return _requestObservable(client, httpRequest, {
135
+ method: 'POST',
136
+ url: `/agent/action/prompt/${dataset}`,
137
+ body: request,
138
+ })
139
+ }
140
+
141
+ export function _prompt<const DocumentShape extends Record<string, Any>>(
142
+ client: SanityClient | ObservableSanityClient,
143
+ httpRequest: HttpRequest,
144
+ request: PromptRequest<DocumentShape>,
145
+ ): Promise<(typeof request)['format'] extends 'json' ? DocumentShape : string> {
132
146
  const dataset = hasDataset(client.config())
133
147
  return _request(client, httpRequest, {
134
148
  method: 'POST',
135
- uri: `/agent/action/prompt/${dataset}`,
149
+ url: `/agent/action/prompt/${dataset}`,
136
150
  body: request,
137
151
  })
138
152
  }
@@ -1,6 +1,6 @@
1
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 {
6
6
  AgentActionParams,
@@ -313,7 +313,7 @@ export interface TransformTarget extends AgentActionTarget {
313
313
 
314
314
  /** @beta */
315
315
  // need the generics to hold optional call-site response generics
316
- // eslint-disable-next-line unused-imports/no-unused-vars
316
+ // oxlint-disable-next-line no-unused-vars
317
317
  export type TransformDocumentSync<T extends Record<string, Any> = Record<string, Any>> =
318
318
  TransformRequestBase & AgentActionSync
319
319
 
@@ -322,9 +322,10 @@ export type TransformDocumentAsync = TransformRequestBase & AgentActionAsync
322
322
 
323
323
  /** @beta */
324
324
  export type TransformDocument<T extends Record<string, Any> = Record<string, Any>> =
325
- TransformDocumentSync<T> | TransformDocumentAsync
325
+ | TransformDocumentSync<T>
326
+ | TransformDocumentAsync
326
327
 
327
- export function _transform<DocumentShape extends Record<string, Any>>(
328
+ export function _transformObservable<DocumentShape extends Record<string, Any>>(
328
329
  client: SanityClient | ObservableSanityClient,
329
330
  httpRequest: HttpRequest,
330
331
  request: TransformDocument<DocumentShape>,
@@ -332,11 +333,28 @@ export function _transform<DocumentShape extends Record<string, Any>>(
332
333
  (typeof request)['async'] extends true
333
334
  ? {_id: string}
334
335
  : IdentifiedSanityDocumentStub & DocumentShape
336
+ > {
337
+ const dataset = hasDataset(client.config())
338
+ return _requestObservable(client, httpRequest, {
339
+ method: 'POST',
340
+ url: `/agent/action/transform/${dataset}`,
341
+ body: request,
342
+ })
343
+ }
344
+
345
+ export function _transform<DocumentShape extends Record<string, Any>>(
346
+ client: SanityClient | ObservableSanityClient,
347
+ httpRequest: HttpRequest,
348
+ request: TransformDocument<DocumentShape>,
349
+ ): Promise<
350
+ (typeof request)['async'] extends true
351
+ ? {_id: string}
352
+ : IdentifiedSanityDocumentStub & DocumentShape
335
353
  > {
336
354
  const dataset = hasDataset(client.config())
337
355
  return _request(client, httpRequest, {
338
356
  method: 'POST',
339
- uri: `/agent/action/transform/${dataset}`,
357
+ url: `/agent/action/transform/${dataset}`,
340
358
  body: request,
341
359
  })
342
360
  }
@@ -1,6 +1,6 @@
1
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 {
6
6
  AgentActionParams,
@@ -138,7 +138,7 @@ export interface TranslateTarget extends AgentActionTarget {
138
138
 
139
139
  /** @beta */
140
140
  // need the generics to hold optional call-site response generics
141
- // eslint-disable-next-line unused-imports/no-unused-vars
141
+ // oxlint-disable-next-line no-unused-vars
142
142
  export type TranslateDocumentSync<T extends Record<string, Any> = Record<string, Any>> =
143
143
  TranslateRequestBase & AgentActionSync
144
144
 
@@ -147,9 +147,10 @@ export type TranslateDocumentAsync = TranslateRequestBase & AgentActionAsync
147
147
 
148
148
  /** @beta */
149
149
  export type TranslateDocument<T extends Record<string, Any> = Record<string, Any>> =
150
- TranslateDocumentSync<T> | TranslateDocumentAsync
150
+ | TranslateDocumentSync<T>
151
+ | TranslateDocumentAsync
151
152
 
152
- export function _translate<DocumentShape extends Record<string, Any>>(
153
+ export function _translateObservable<DocumentShape extends Record<string, Any>>(
153
154
  client: SanityClient | ObservableSanityClient,
154
155
  httpRequest: HttpRequest,
155
156
  request: TranslateDocument<DocumentShape>,
@@ -157,11 +158,28 @@ export function _translate<DocumentShape extends Record<string, Any>>(
157
158
  (typeof request)['async'] extends true
158
159
  ? {_id: string}
159
160
  : IdentifiedSanityDocumentStub & DocumentShape
161
+ > {
162
+ const dataset = hasDataset(client.config())
163
+ return _requestObservable(client, httpRequest, {
164
+ method: 'POST',
165
+ url: `/agent/action/translate/${dataset}`,
166
+ body: request,
167
+ })
168
+ }
169
+
170
+ export function _translate<DocumentShape extends Record<string, Any>>(
171
+ client: SanityClient | ObservableSanityClient,
172
+ httpRequest: HttpRequest,
173
+ request: TranslateDocument<DocumentShape>,
174
+ ): Promise<
175
+ (typeof request)['async'] extends true
176
+ ? {_id: string}
177
+ : IdentifiedSanityDocumentStub & DocumentShape
160
178
  > {
161
179
  const dataset = hasDataset(client.config())
162
180
  return _request(client, httpRequest, {
163
181
  method: 'POST',
164
- uri: `/agent/action/translate/${dataset}`,
182
+ url: `/agent/action/translate/${dataset}`,
165
183
  body: request,
166
184
  })
167
185
  }
@@ -1,18 +1,19 @@
1
- import {lastValueFrom, type Observable} from 'rxjs'
2
- import {filter, map} from 'rxjs/operators'
1
+ import {defer, lastValueFrom, type Observable} from 'rxjs'
2
+ import {filter, map, mergeAll} from 'rxjs/operators'
3
3
 
4
- import {_requestObservable} from '../data/dataMethods'
4
+ import {_prepareRequest, _uploadObservable} from '../data/dataMethods'
5
+ import type {FetchRequest} from '../http/requestOptions'
5
6
  import type {ObservableSanityClient, SanityClient} from '../SanityClient'
6
7
  import type {
7
8
  Any,
8
9
  HttpRequest,
9
- HttpRequestEvent,
10
10
  InitializedClientConfig,
11
- ResponseEvent,
12
11
  SanityAssetDocument,
13
12
  SanityImageAssetDocument,
14
13
  UploadBody,
15
14
  UploadClientConfig,
15
+ UploadEvent,
16
+ UploadResponseEvent,
16
17
  } from '../types'
17
18
  import * as validators from '../validators'
18
19
 
@@ -36,7 +37,7 @@ export class ObservableAssetsClient {
36
37
  assetType: 'file',
37
38
  body: UploadBody,
38
39
  options?: UploadClientConfig,
39
- ): Observable<HttpRequestEvent<{document: SanityAssetDocument}>>
40
+ ): Observable<UploadEvent<{document: SanityAssetDocument}>>
40
41
 
41
42
  /**
42
43
  * Uploads an image asset to the configured dataset
@@ -49,7 +50,7 @@ export class ObservableAssetsClient {
49
50
  assetType: 'image',
50
51
  body: UploadBody,
51
52
  options?: UploadClientConfig,
52
- ): Observable<HttpRequestEvent<{document: SanityImageAssetDocument}>>
53
+ ): Observable<UploadEvent<{document: SanityImageAssetDocument}>>
53
54
  /**
54
55
  * Uploads a file or an image asset to the configured dataset
55
56
  *
@@ -61,12 +62,12 @@ export class ObservableAssetsClient {
61
62
  assetType: 'file' | 'image',
62
63
  body: UploadBody,
63
64
  options?: UploadClientConfig,
64
- ): Observable<HttpRequestEvent<{document: SanityAssetDocument | SanityImageAssetDocument}>>
65
+ ): Observable<UploadEvent<{document: SanityAssetDocument | SanityImageAssetDocument}>>
65
66
  upload(
66
67
  assetType: 'file' | 'image',
67
68
  body: UploadBody,
68
69
  options?: UploadClientConfig,
69
- ): Observable<HttpRequestEvent<{document: SanityAssetDocument | SanityImageAssetDocument}>> {
70
+ ): Observable<UploadEvent<{document: SanityAssetDocument | SanityImageAssetDocument}>> {
70
71
  return _upload(this.#client, this.#httpRequest, assetType, body, options)
71
72
  }
72
73
  }
@@ -121,27 +122,24 @@ export class AssetsClient {
121
122
  body: UploadBody,
122
123
  options?: UploadClientConfig,
123
124
  ): Promise<SanityAssetDocument | SanityImageAssetDocument> {
124
- const observable = _upload(this.#client, this.#httpRequest, assetType, body, options)
125
+ type Doc = {document: SanityAssetDocument | SanityImageAssetDocument}
126
+ const observable = _upload<Doc>(this.#client, this.#httpRequest, assetType, body, options)
125
127
  return lastValueFrom(
126
128
  observable.pipe(
127
- filter((event: Any) => event.type === 'response'),
128
- map(
129
- (event) =>
130
- (event as ResponseEvent<{document: SanityAssetDocument | SanityImageAssetDocument}>)
131
- .body.document,
132
- ),
129
+ filter((event): event is UploadResponseEvent<Doc> => event.type === 'response'),
130
+ map((event) => event.body.document),
133
131
  ),
134
132
  )
135
133
  }
136
134
  }
137
135
 
138
- function _upload(
136
+ function _upload<T = {document: SanityAssetDocument | SanityImageAssetDocument}>(
139
137
  client: SanityClient | ObservableSanityClient,
140
- httpRequest: HttpRequest,
138
+ _httpRequest: HttpRequest,
141
139
  assetType: 'image' | 'file',
142
140
  body: UploadBody,
143
141
  opts: UploadClientConfig = {},
144
- ): Observable<HttpRequestEvent<{document: SanityAssetDocument | SanityImageAssetDocument}>> {
142
+ ): Observable<UploadEvent<T>> {
145
143
  validators.validateAssetType(assetType)
146
144
 
147
145
  // If an empty array is given, explicitly set `none` to override API defaults
@@ -180,15 +178,65 @@ function _upload(
180
178
  query.sourceUrl = source.url
181
179
  }
182
180
 
183
- return _requestObservable(client, httpRequest, {
181
+ const headers: Record<string, string> = options.contentType
182
+ ? {'Content-Type': options.contentType}
183
+ : {}
184
+ const baseRequest = {
184
185
  tag,
185
186
  method: 'POST',
187
+ // Uploads have NO timeout unless the caller opts in — uploads can
188
+ // legitimately be slow. `0` translates to "disabled" at the request
189
+ // boundary, which also shields uploads from get-it's default timeout.
186
190
  timeout: options.timeout || 0,
187
- uri: buildAssetUploadUrl(config, assetType),
188
- headers: options.contentType ? {'Content-Type': options.contentType} : {},
191
+ url: buildAssetUploadUrl(config, assetType),
192
+ headers,
189
193
  query,
190
194
  body,
191
- })
195
+ }
196
+
197
+ // In browsers, run uploads through `XMLHttpRequest` so we can surface
198
+ // per-chunk upload progress events — fetch (and therefore get-it v9) has no
199
+ // equivalent hook. Outside the browser (Node, edge runtimes), we fall back
200
+ // to the regular fetch-based path which only emits the terminal `response`
201
+ // event.
202
+ if (typeof XMLHttpRequest !== 'undefined') {
203
+ return defer(async () => {
204
+ const {uploadWithProgress} = await import('../http/browserUpload')
205
+ // Build the request the same way the fetch path does, so the request
206
+ // tag (incl. `requestTagPrefix` and validation), auth/custom headers,
207
+ // credentials and timeout are identical across both upload transports.
208
+ // The XHR API needs the query baked into the URL, though.
209
+ const req = _prepareRequest(client, {...baseRequest})
210
+ return uploadWithProgress<T>({
211
+ url: appendQuery(req.url, req.query),
212
+ method: req.method ?? 'POST',
213
+ headers: req.headers,
214
+ body,
215
+ withCredentials: req.credentials === 'include',
216
+ // XHR only has a single total-deadline timer, so a structured
217
+ // get-it timeout collapses to its `total` component here.
218
+ timeout: typeof req.timeout === 'object' ? req.timeout.total : req.timeout,
219
+ signal: req.signal,
220
+ })
221
+ }).pipe(mergeAll())
222
+ }
223
+
224
+ return _uploadObservable<T>(client, baseRequest)
225
+ }
226
+
227
+ function appendQuery(url: string, query: FetchRequest['query']): string {
228
+ if (!query) return url
229
+ const params =
230
+ query instanceof URLSearchParams
231
+ ? query
232
+ : new URLSearchParams(
233
+ Object.entries(query).flatMap(([key, value]) =>
234
+ value === undefined || value === null ? [] : [[key, `${value}`]],
235
+ ),
236
+ )
237
+ const qs = params.toString()
238
+ if (!qs) return url
239
+ return url + (url.includes('?') ? '&' : '?') + qs
192
240
  }
193
241
 
194
242
  function buildAssetUploadUrl(config: InitializedClientConfig, assetType: 'image' | 'file'): string {
@@ -24,7 +24,9 @@ export function applySourceDocuments<Result = unknown>(
24
24
  getCachedDocument: (
25
25
  sourceDocument: ContentSourceMapDocuments[number],
26
26
  ) =>
27
- (Partial<SanityDocument> & Required<Pick<SanityDocument, '_id' | '_type'>>) | null | undefined,
27
+ | (Partial<SanityDocument> & Required<Pick<SanityDocument, '_id' | '_type'>>)
28
+ | null
29
+ | undefined,
28
30
  updateFn: ApplySourceDocumentsUpdateFunction,
29
31
  perspective: Exclude<ClientPerspective, 'raw'>,
30
32
  ): Result {
@@ -36,7 +36,7 @@ export function createEditUrl(options: CreateEditUrlOptions): `${StudioBaseUrl}$
36
36
  ? studioPath.toString(jsonPathToStudioPath(path))
37
37
  : path
38
38
 
39
- // eslint-disable-next-line no-warning-comments
39
+ // oxlint-disable-next-line no-warning-comments
40
40
  // @TODO Using searchParams as a temporary workaround until `@sanity/overlays` can decode state from the path reliably
41
41
  const searchParams = new URLSearchParams({
42
42
  baseUrl,
@@ -60,7 +60,6 @@ export function getVersionId(id: string, version: string): string {
60
60
  */
61
61
  export function getVersionFromId(id: string): string | undefined {
62
62
  if (!isVersionId(id)) return undefined
63
- // eslint-disable-next-line unused-imports/no-unused-vars
64
63
  const [_versionPrefix, versionId, ..._publishedId] = id.split(PATH_SEPARATOR)
65
64
 
66
65
  return versionId
package/src/csm/index.ts CHANGED
@@ -1,5 +1,5 @@
1
- import * as studioPath from './studioPath'
2
- export {studioPath}
1
+ /** @alpha */
2
+ export * as studioPath from './studioPath'
3
3
  export * from './applySourceDocuments'
4
4
  export {createEditUrl} from './createEditUrl'
5
5
  export {
@@ -45,6 +45,7 @@ export function isIndexTuple(segment: PathSegment): segment is IndexTuple {
45
45
  }
46
46
 
47
47
  /** @internal */
48
+ // oxlint-disable-next-line typescript/no-unnecessary-type-parameters -- caller-supplied return type; removing it breaks `get<Result>(...)` call sites
48
49
  export function get<Result = unknown, Fallback = unknown>(
49
50
  obj: unknown,
50
51
  path: Path | string,
@@ -55,7 +56,7 @@ export function get<Result = unknown, Fallback = unknown>(
55
56
  throw new Error('Path must be an array or a string')
56
57
  }
57
58
 
58
- let acc: unknown | undefined = obj
59
+ let acc: unknown = obj
59
60
  for (let i = 0; i < select.length; i++) {
60
61
  const segment = select[i]
61
62
  if (isIndexSegment(segment)) {
package/src/csm/types.ts CHANGED
@@ -33,11 +33,17 @@ export type ContentSourceMapParsedPathKeyedSegment = {_key: string; _index: numb
33
33
 
34
34
  /** @alpha */
35
35
  export type ContentSourceMapParsedPath = (
36
- string | number | ContentSourceMapParsedPathKeyedSegment
36
+ | string
37
+ | number
38
+ | ContentSourceMapParsedPathKeyedSegment
37
39
  )[]
38
40
 
39
41
  /** @alpha */
40
- export type StudioBaseUrl = `/${string}` | `${string}.sanity.studio` | `https://${string}` | string
42
+ export type StudioBaseUrl =
43
+ | `/${string}`
44
+ | `${string}.sanity.studio`
45
+ | `https://${string}`
46
+ | (string & {})
41
47
 
42
48
  /** @alpha */
43
49
  export type StudioBaseRoute = {baseUrl: StudioBaseUrl; workspace?: string; tool?: string}