@sanity/client 7.26.1 → 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 (128) 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 -347
  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 -6758
  16. package/dist/index.js +2822 -2848
  17. package/dist/index.js.map +1 -1
  18. package/dist/{index.d.cts → index.node.d.ts} +4291 -5363
  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 -7179
  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 -5295
  43. package/dist/types-CfGzbXrl.d.ts +108 -0
  44. package/package.json +69 -146
  45. package/src/SanityClient.ts +82 -117
  46. package/src/agent/actions/AgentActionsClient.ts +12 -12
  47. package/src/agent/actions/generate.ts +20 -3
  48. package/src/agent/actions/patch.ts +21 -4
  49. package/src/agent/actions/prompt.ts +17 -4
  50. package/src/agent/actions/transform.ts +21 -4
  51. package/src/agent/actions/translate.ts +21 -4
  52. package/src/assets/AssetsClient.ts +71 -23
  53. package/src/csm/createEditUrl.ts +1 -1
  54. package/src/csm/draftUtils.ts +0 -1
  55. package/src/csm/index.ts +2 -2
  56. package/src/csm/studioPath.ts +2 -1
  57. package/src/csm/types.ts +5 -1
  58. package/src/data/dataMethods.ts +801 -349
  59. package/src/data/eventsource.ts +13 -10
  60. package/src/data/listen.ts +16 -22
  61. package/src/data/live.ts +44 -27
  62. package/src/data/resolveEventSourceFetch.ts +96 -0
  63. package/src/datasets/DatasetsClient.ts +58 -41
  64. package/src/defineCreateClient.ts +35 -23
  65. package/src/http/browserMiddleware.ts +7 -1
  66. package/src/http/browserUpload.ts +162 -0
  67. package/src/http/errors.ts +60 -6
  68. package/src/http/nodeMiddleware.ts +94 -30
  69. package/src/http/request.ts +310 -87
  70. package/src/http/requestOptions.ts +131 -15
  71. package/src/{index.browser.ts → index.node.ts} +9 -4
  72. package/src/index.ts +4 -3
  73. package/src/mediaLibrary/MediaLibraryVideoClient.ts +26 -11
  74. package/src/projects/ProjectsClient.ts +18 -16
  75. package/src/releases/ReleasesClient.ts +34 -31
  76. package/src/stega/index.ts +1 -2
  77. package/src/stega/stegaEncodeSourceMap.ts +5 -0
  78. package/src/stega/types.ts +0 -1
  79. package/src/types.ts +110 -96
  80. package/src/users/UsersClient.ts +10 -14
  81. package/src/util/shareReplayLatest.ts +1 -1
  82. package/src/warnings.ts +6 -1
  83. package/dist/_chunks-cjs/config.cjs +0 -206
  84. package/dist/_chunks-cjs/config.cjs.map +0 -1
  85. package/dist/_chunks-cjs/isRecord.cjs +0 -6
  86. package/dist/_chunks-cjs/isRecord.cjs.map +0 -1
  87. package/dist/_chunks-cjs/resolveEditInfo.cjs +0 -334
  88. package/dist/_chunks-cjs/resolveEditInfo.cjs.map +0 -1
  89. package/dist/_chunks-cjs/stegaClean.cjs +0 -46
  90. package/dist/_chunks-cjs/stegaClean.cjs.map +0 -1
  91. package/dist/_chunks-cjs/stegaEncodeSourceMap.cjs +0 -388
  92. package/dist/_chunks-cjs/stegaEncodeSourceMap.cjs.map +0 -1
  93. package/dist/_chunks-es/config.js +0 -207
  94. package/dist/_chunks-es/config.js.map +0 -1
  95. package/dist/_chunks-es/isRecord.js +0 -7
  96. package/dist/_chunks-es/isRecord.js.map +0 -1
  97. package/dist/_chunks-es/resolveEditInfo.js +0 -335
  98. package/dist/_chunks-es/resolveEditInfo.js.map +0 -1
  99. package/dist/_chunks-es/stegaClean.js +0 -47
  100. package/dist/_chunks-es/stegaClean.js.map +0 -1
  101. package/dist/_chunks-es/stegaEncodeSourceMap.js +0 -389
  102. package/dist/_chunks-es/stegaEncodeSourceMap.js.map +0 -1
  103. package/dist/csm.cjs +0 -99
  104. package/dist/csm.cjs.map +0 -1
  105. package/dist/csm.d.cts +0 -403
  106. package/dist/index.browser.cjs +0 -3106
  107. package/dist/index.browser.cjs.map +0 -1
  108. package/dist/index.browser.d.ts +0 -6841
  109. package/dist/index.browser.js +0 -3082
  110. package/dist/index.browser.js.map +0 -1
  111. package/dist/index.cjs +0 -2947
  112. package/dist/index.cjs.map +0 -1
  113. package/dist/media-library.cjs +0 -20
  114. package/dist/media-library.cjs.map +0 -1
  115. package/dist/media-library.d.cts +0 -117
  116. package/dist/stega.browser.cjs +0 -29
  117. package/dist/stega.browser.cjs.map +0 -1
  118. package/dist/stega.browser.d.cts +0 -7242
  119. package/dist/stega.browser.d.ts +0 -7242
  120. package/dist/stega.browser.js +0 -24
  121. package/dist/stega.browser.js.map +0 -1
  122. package/dist/stega.cjs +0 -29
  123. package/dist/stega.cjs.map +0 -1
  124. package/dist/stega.d.cts +0 -7242
  125. package/src/data/eventsourcePolyfill.ts +0 -7
  126. package/umd/.gitkeep +0 -1
  127. package/umd/sanityClient.js +0 -6536
  128. package/umd/sanityClient.min.js +0 -6
@@ -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 {
6
6
  HttpRequest,
@@ -42,12 +42,12 @@ export class ObservableMediaLibraryVideoClient {
42
42
  )
43
43
  }
44
44
 
45
- const uri = buildVideoPlaybackInfoUrl(instanceId, effectiveLibraryId)
45
+ const url = buildVideoPlaybackInfoUrl(instanceId, effectiveLibraryId)
46
46
  const queryParams = buildQueryParams(options)
47
47
 
48
- return _request<VideoPlaybackInfo>(this.#client, this.#httpRequest, {
48
+ return _requestObservable<VideoPlaybackInfo>(this.#client, this.#httpRequest, {
49
49
  method: 'GET',
50
- uri,
50
+ url,
51
51
  query: queryParams,
52
52
  })
53
53
  }
@@ -72,12 +72,27 @@ export class MediaLibraryVideoClient {
72
72
  assetIdentifier: MediaLibraryAssetInstanceIdentifier,
73
73
  options: MediaLibraryPlaybackInfoOptions = {},
74
74
  ): Promise<VideoPlaybackInfo> {
75
- return lastValueFrom(
76
- new ObservableMediaLibraryVideoClient(
77
- this.#client.observable,
78
- this.#httpRequest,
79
- ).getPlaybackInfo(assetIdentifier, options),
80
- )
75
+ const config = this.#client.config()
76
+ const resource = config.resource || config['~experimental_resource']
77
+ const configMediaLibraryId = resource?.id
78
+
79
+ const {instanceId, libraryId} = parseAssetInstanceId(assetIdentifier)
80
+ const effectiveLibraryId = libraryId || configMediaLibraryId
81
+
82
+ if (!effectiveLibraryId) {
83
+ throw new Error(
84
+ 'Could not determine Media Library ID - you need to provide a valid Media Library ID in the client config or a Media Library GDR',
85
+ )
86
+ }
87
+
88
+ const url = buildVideoPlaybackInfoUrl(instanceId, effectiveLibraryId)
89
+ const queryParams = buildQueryParams(options)
90
+
91
+ return _request<VideoPlaybackInfo>(this.#client, this.#httpRequest, {
92
+ method: 'GET',
93
+ url,
94
+ query: queryParams,
95
+ })
81
96
  }
82
97
  }
83
98
 
@@ -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 {HttpRequest, SanityProject} from '../types'
6
6
 
@@ -37,7 +37,7 @@ export class ObservableProjectsClient {
37
37
  options?: T,
38
38
  ): Observable<Omit<SanityProject, OmittedProjectFields<T>>[]> {
39
39
  const query: Record<string, string> = {}
40
- const uri = '/projects'
40
+ const url = '/projects'
41
41
  if (options?.includeMembers === false) {
42
42
  query.includeMembers = 'false'
43
43
  }
@@ -51,9 +51,10 @@ export class ObservableProjectsClient {
51
51
  query.onlyExplicitMembership = 'true'
52
52
  }
53
53
 
54
- return _request<SanityProject[]>(this.#client, this.#httpRequest, {uri, query}) as Observable<
55
- Omit<SanityProject, OmittedProjectFields<T>>[]
56
- >
54
+ return _requestObservable<SanityProject[]>(this.#client, this.#httpRequest, {
55
+ url,
56
+ query,
57
+ }) as Observable<Omit<SanityProject, OmittedProjectFields<T>>[]>
57
58
  }
58
59
 
59
60
  /**
@@ -62,7 +63,9 @@ export class ObservableProjectsClient {
62
63
  * @param projectId - ID of the project to fetch
63
64
  */
64
65
  getById(projectId: string): Observable<SanityProject> {
65
- return _request<SanityProject>(this.#client, this.#httpRequest, {uri: `/projects/${projectId}`})
66
+ return _requestObservable<SanityProject>(this.#client, this.#httpRequest, {
67
+ url: `/projects/${projectId}`,
68
+ })
66
69
  }
67
70
  }
68
71
 
@@ -88,7 +91,7 @@ export class ProjectsClient {
88
91
  options?: T,
89
92
  ): Promise<Omit<SanityProject, OmittedProjectFields<T>>[]> {
90
93
  const query: Record<string, string> = {}
91
- const uri = '/projects'
94
+ const url = '/projects'
92
95
  if (options?.includeMembers === false) {
93
96
  query.includeMembers = 'false'
94
97
  }
@@ -101,11 +104,10 @@ export class ProjectsClient {
101
104
  if (options?.onlyExplicitMembership) {
102
105
  query.onlyExplicitMembership = 'true'
103
106
  }
104
- return lastValueFrom(
105
- _request<SanityProject[]>(this.#client, this.#httpRequest, {uri, query}) as Observable<
106
- Omit<SanityProject, OmittedProjectFields<T>>[]
107
- >,
108
- )
107
+ return _request<SanityProject[]>(this.#client, this.#httpRequest, {
108
+ url,
109
+ query,
110
+ }) as Promise<Omit<SanityProject, OmittedProjectFields<T>>[]>
109
111
  }
110
112
 
111
113
  /**
@@ -114,8 +116,8 @@ export class ProjectsClient {
114
116
  * @param projectId - ID of the project to fetch
115
117
  */
116
118
  getById(projectId: string): Promise<SanityProject> {
117
- return lastValueFrom(
118
- _request<SanityProject>(this.#client, this.#httpRequest, {uri: `/projects/${projectId}`}),
119
- )
119
+ return _request<SanityProject>(this.#client, this.#httpRequest, {
120
+ url: `/projects/${projectId}`,
121
+ })
120
122
  }
121
123
  }
@@ -1,6 +1,13 @@
1
- import {lastValueFrom, map, Observable} from 'rxjs'
2
-
3
- import {_action, _getDocument, _getReleaseDocuments} from '../data/dataMethods'
1
+ import {map, Observable} from 'rxjs'
2
+
3
+ import {
4
+ _action,
5
+ _actionObservable,
6
+ _getDocument,
7
+ _getDocumentObservable,
8
+ _getReleaseDocuments,
9
+ _getReleaseDocumentsObservable,
10
+ } from '../data/dataMethods'
4
11
  import type {ObservableSanityClient, SanityClient} from '../SanityClient'
5
12
  import type {
6
13
  ArchiveReleaseAction,
@@ -61,7 +68,7 @@ export class ObservableReleasesClient {
61
68
  {releaseId}: {releaseId: string},
62
69
  options?: {signal?: AbortSignal; tag?: string},
63
70
  ): Observable<ReleaseDocument | undefined> {
64
- return _getDocument<ReleaseDocument>(
71
+ return _getDocumentObservable<ReleaseDocument>(
65
72
  this.#client,
66
73
  this.#httpRequest,
67
74
  `_.releases.${releaseId}`,
@@ -140,7 +147,7 @@ export class ObservableReleasesClient {
140
147
  const {action, options} = createRelease(releaseOrOptions, maybeOptions)
141
148
  const {releaseId, metadata} = action
142
149
 
143
- return _action(this.#client, this.#httpRequest, action, options).pipe(
150
+ return _actionObservable(this.#client, this.#httpRequest, action, options).pipe(
144
151
  map((actionResult) => ({
145
152
  ...actionResult,
146
153
  releaseId,
@@ -172,7 +179,7 @@ export class ObservableReleasesClient {
172
179
  patch,
173
180
  }
174
181
 
175
- return _action(this.#client, this.#httpRequest, editAction, options)
182
+ return _actionObservable(this.#client, this.#httpRequest, editAction, options)
176
183
  }
177
184
 
178
185
  /**
@@ -202,7 +209,7 @@ export class ObservableReleasesClient {
202
209
  releaseId,
203
210
  }
204
211
 
205
- return _action(this.#client, this.#httpRequest, publishAction, options)
212
+ return _actionObservable(this.#client, this.#httpRequest, publishAction, options)
206
213
  }
207
214
 
208
215
  /**
@@ -229,7 +236,7 @@ export class ObservableReleasesClient {
229
236
  releaseId,
230
237
  }
231
238
 
232
- return _action(this.#client, this.#httpRequest, archiveAction, options)
239
+ return _actionObservable(this.#client, this.#httpRequest, archiveAction, options)
233
240
  }
234
241
 
235
242
  /**
@@ -254,7 +261,7 @@ export class ObservableReleasesClient {
254
261
  releaseId,
255
262
  }
256
263
 
257
- return _action(this.#client, this.#httpRequest, unarchiveAction, options)
264
+ return _actionObservable(this.#client, this.#httpRequest, unarchiveAction, options)
258
265
  }
259
266
 
260
267
  /**
@@ -283,7 +290,7 @@ export class ObservableReleasesClient {
283
290
  publishAt,
284
291
  }
285
292
 
286
- return _action(this.#client, this.#httpRequest, scheduleAction, options)
293
+ return _actionObservable(this.#client, this.#httpRequest, scheduleAction, options)
287
294
  }
288
295
 
289
296
  /**
@@ -310,7 +317,7 @@ export class ObservableReleasesClient {
310
317
  releaseId,
311
318
  }
312
319
 
313
- return _action(this.#client, this.#httpRequest, unscheduleAction, options)
320
+ return _actionObservable(this.#client, this.#httpRequest, unscheduleAction, options)
314
321
  }
315
322
 
316
323
  /**
@@ -335,7 +342,7 @@ export class ObservableReleasesClient {
335
342
  releaseId,
336
343
  }
337
344
 
338
- return _action(this.#client, this.#httpRequest, deleteAction, options)
345
+ return _actionObservable(this.#client, this.#httpRequest, deleteAction, options)
339
346
  }
340
347
 
341
348
  /**
@@ -354,7 +361,7 @@ export class ObservableReleasesClient {
354
361
  {releaseId}: {releaseId: string},
355
362
  options?: BaseMutationOptions,
356
363
  ): Observable<RawQueryResponse<SanityDocument[]>> {
357
- return _getReleaseDocuments(this.#client, this.#httpRequest, releaseId, options)
364
+ return _getReleaseDocumentsObservable(this.#client, this.#httpRequest, releaseId, options)
358
365
  }
359
366
  }
360
367
 
@@ -397,13 +404,11 @@ export class ReleasesClient {
397
404
  {releaseId}: {releaseId: string},
398
405
  options?: {signal?: AbortSignal; tag?: string},
399
406
  ): Promise<ReleaseDocument | undefined> {
400
- return lastValueFrom(
401
- _getDocument<ReleaseDocument>(
402
- this.#client,
403
- this.#httpRequest,
404
- `_.releases.${releaseId}`,
405
- options,
406
- ),
407
+ return _getDocument<ReleaseDocument>(
408
+ this.#client,
409
+ this.#httpRequest,
410
+ `_.releases.${releaseId}`,
411
+ options,
407
412
  )
408
413
  }
409
414
 
@@ -470,9 +475,7 @@ export class ReleasesClient {
470
475
  const {action, options} = createRelease(releaseOrOptions, maybeOptions)
471
476
  const {releaseId, metadata} = action
472
477
 
473
- const actionResult = await lastValueFrom(
474
- _action(this.#client, this.#httpRequest, action, options),
475
- )
478
+ const actionResult = await _action(this.#client, this.#httpRequest, action, options)
476
479
 
477
480
  return {...actionResult, releaseId, metadata}
478
481
  }
@@ -500,7 +503,7 @@ export class ReleasesClient {
500
503
  patch,
501
504
  }
502
505
 
503
- return lastValueFrom(_action(this.#client, this.#httpRequest, editAction, options))
506
+ return _action(this.#client, this.#httpRequest, editAction, options)
504
507
  }
505
508
 
506
509
  /**
@@ -530,7 +533,7 @@ export class ReleasesClient {
530
533
  releaseId,
531
534
  }
532
535
 
533
- return lastValueFrom(_action(this.#client, this.#httpRequest, publishAction, options))
536
+ return _action(this.#client, this.#httpRequest, publishAction, options)
534
537
  }
535
538
 
536
539
  /**
@@ -557,7 +560,7 @@ export class ReleasesClient {
557
560
  releaseId,
558
561
  }
559
562
 
560
- return lastValueFrom(_action(this.#client, this.#httpRequest, archiveAction, options))
563
+ return _action(this.#client, this.#httpRequest, archiveAction, options)
561
564
  }
562
565
 
563
566
  /**
@@ -582,7 +585,7 @@ export class ReleasesClient {
582
585
  releaseId,
583
586
  }
584
587
 
585
- return lastValueFrom(_action(this.#client, this.#httpRequest, unarchiveAction, options))
588
+ return _action(this.#client, this.#httpRequest, unarchiveAction, options)
586
589
  }
587
590
 
588
591
  /**
@@ -611,7 +614,7 @@ export class ReleasesClient {
611
614
  publishAt,
612
615
  }
613
616
 
614
- return lastValueFrom(_action(this.#client, this.#httpRequest, scheduleAction, options))
617
+ return _action(this.#client, this.#httpRequest, scheduleAction, options)
615
618
  }
616
619
 
617
620
  /**
@@ -638,7 +641,7 @@ export class ReleasesClient {
638
641
  releaseId,
639
642
  }
640
643
 
641
- return lastValueFrom(_action(this.#client, this.#httpRequest, unscheduleAction, options))
644
+ return _action(this.#client, this.#httpRequest, unscheduleAction, options)
642
645
  }
643
646
 
644
647
  /**
@@ -663,7 +666,7 @@ export class ReleasesClient {
663
666
  releaseId,
664
667
  }
665
668
 
666
- return lastValueFrom(_action(this.#client, this.#httpRequest, deleteAction, options))
669
+ return _action(this.#client, this.#httpRequest, deleteAction, options)
667
670
  }
668
671
 
669
672
  /**
@@ -682,6 +685,6 @@ export class ReleasesClient {
682
685
  {releaseId}: {releaseId: string},
683
686
  options?: BaseMutationOptions,
684
687
  ): Promise<RawQueryResponse<SanityDocument[]>> {
685
- return lastValueFrom(_getReleaseDocuments(this.#client, this.#httpRequest, releaseId, options))
688
+ return _getReleaseDocuments(this.#client, this.#httpRequest, releaseId, options)
686
689
  }
687
690
  }
@@ -6,10 +6,9 @@ import {
6
6
  SanityClient,
7
7
  } from '@sanity/client'
8
8
 
9
- export {encodeIntoResult} from './encodeIntoResult'
10
9
  export {type ClientReturnStega, stegaBrand, type StegaBranded, type StegaString} from './stegaBrand'
11
10
  export {stegaClean, type StegaCleaned, vercelStegaCleanAll} from './stegaClean'
12
- export {stegaEncodeSourceMap} from './stegaEncodeSourceMap'
11
+ export {encodeIntoResult, stegaEncodeSourceMap} from './stegaEncodeSourceMap'
13
12
  export * from './types'
14
13
 
15
14
  /**
@@ -5,6 +5,11 @@ import {jsonPathToStudioPath} from '../csm/jsonPath'
5
5
  import {resolveStudioBaseRoute} from '../csm/resolveEditInfo'
6
6
  import {reKeySegment, toString as studioPathToString} from '../csm/studioPath'
7
7
  import {encodeIntoResult} from './encodeIntoResult'
8
+ // Re-export so `encodeIntoResult` is a genuine export of this module - which
9
+ // forms its own output chunk via the dynamic import in `dataMethods`. Without
10
+ // this, rolldown absorbs `encodeIntoResult` into the chunk but omits it from
11
+ // the chunk's exports, breaking `@sanity/client/stega`'s re-export of it.
12
+ export {encodeIntoResult} from './encodeIntoResult'
8
13
  import {filterDefault} from './filterDefault'
9
14
  import {
10
15
  type ContentSourceMap,
@@ -1,4 +1,3 @@
1
- /* eslint-disable @typescript-eslint/no-empty-object-type */
2
1
  import type {ClientConfig, InitializedClientConfig, RawQueryResponse} from '@sanity/client'
3
2
  import type {
4
3
  ContentSourceMap,