@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.
- package/README.md +5 -377
- package/dist/browserUpload-CQgx9YYo.js +86 -0
- package/dist/browserUpload-CQgx9YYo.js.map +1 -0
- package/dist/browserUpload-icWlVP15.js +86 -0
- package/dist/browserUpload-icWlVP15.js.map +1 -0
- package/dist/config-a8VajuEY.js +126 -0
- package/dist/config-a8VajuEY.js.map +1 -0
- package/dist/csm.d.ts +122 -347
- package/dist/csm.js +79 -91
- package/dist/csm.js.map +1 -1
- package/dist/dist-C9ExSk2R.js +73 -0
- package/dist/dist-C9ExSk2R.js.map +1 -0
- package/dist/dist-Z8cIRxoB.js +69 -0
- package/dist/dist-Z8cIRxoB.js.map +1 -0
- package/dist/index.d.ts +107 -6758
- package/dist/index.js +2822 -2848
- package/dist/index.js.map +1 -1
- package/dist/{index.d.cts → index.node.d.ts} +4291 -5363
- package/dist/index.node.js +3131 -0
- package/dist/index.node.js.map +1 -0
- package/dist/isRecord-Kfmt-nk-.js +7 -0
- package/dist/isRecord-Kfmt-nk-.js.map +1 -0
- package/dist/media-library.d.ts +9 -100
- package/dist/media-library.js +36 -14
- package/dist/media-library.js.map +1 -1
- package/dist/request-CJxcN16k.js +372 -0
- package/dist/request-CJxcN16k.js.map +1 -0
- package/dist/request-k7VS_NnC.js +354 -0
- package/dist/request-k7VS_NnC.js.map +1 -0
- package/dist/resolveEditInfo-sq7yF78q.js +325 -0
- package/dist/resolveEditInfo-sq7yF78q.js.map +1 -0
- package/dist/rolldown-runtime-vyAXikos.js +9 -0
- package/dist/stega.d.ts +78 -7179
- package/dist/stega.js +27 -20
- package/dist/stega.js.map +1 -1
- package/dist/stegaClean-C18wLWau.js +21 -0
- package/dist/stegaClean-C18wLWau.js.map +1 -0
- package/dist/stegaEncodeSourceMap-B2fGArSf.js +163 -0
- package/dist/stegaEncodeSourceMap-B2fGArSf.js.map +1 -0
- package/dist/stegaEncodeSourceMap-DkoIlutY.js +367 -0
- package/dist/stegaEncodeSourceMap-DkoIlutY.js.map +1 -0
- package/dist/{index.browser.d.cts → types-CUxZSgB2.d.ts} +3956 -5295
- package/dist/types-CfGzbXrl.d.ts +108 -0
- package/package.json +69 -146
- package/src/SanityClient.ts +82 -117
- package/src/agent/actions/AgentActionsClient.ts +12 -12
- package/src/agent/actions/generate.ts +20 -3
- package/src/agent/actions/patch.ts +21 -4
- package/src/agent/actions/prompt.ts +17 -4
- package/src/agent/actions/transform.ts +21 -4
- package/src/agent/actions/translate.ts +21 -4
- package/src/assets/AssetsClient.ts +71 -23
- package/src/csm/createEditUrl.ts +1 -1
- package/src/csm/draftUtils.ts +0 -1
- package/src/csm/index.ts +2 -2
- package/src/csm/studioPath.ts +2 -1
- package/src/csm/types.ts +5 -1
- package/src/data/dataMethods.ts +801 -349
- package/src/data/eventsource.ts +13 -10
- package/src/data/listen.ts +16 -22
- package/src/data/live.ts +44 -27
- package/src/data/resolveEventSourceFetch.ts +96 -0
- package/src/datasets/DatasetsClient.ts +58 -41
- package/src/defineCreateClient.ts +35 -23
- package/src/http/browserMiddleware.ts +7 -1
- package/src/http/browserUpload.ts +162 -0
- package/src/http/errors.ts +60 -6
- package/src/http/nodeMiddleware.ts +94 -30
- package/src/http/request.ts +310 -87
- package/src/http/requestOptions.ts +131 -15
- package/src/{index.browser.ts → index.node.ts} +9 -4
- package/src/index.ts +4 -3
- package/src/mediaLibrary/MediaLibraryVideoClient.ts +26 -11
- package/src/projects/ProjectsClient.ts +18 -16
- package/src/releases/ReleasesClient.ts +34 -31
- package/src/stega/index.ts +1 -2
- package/src/stega/stegaEncodeSourceMap.ts +5 -0
- package/src/stega/types.ts +0 -1
- package/src/types.ts +110 -96
- package/src/users/UsersClient.ts +10 -14
- package/src/util/shareReplayLatest.ts +1 -1
- package/src/warnings.ts +6 -1
- package/dist/_chunks-cjs/config.cjs +0 -206
- package/dist/_chunks-cjs/config.cjs.map +0 -1
- package/dist/_chunks-cjs/isRecord.cjs +0 -6
- package/dist/_chunks-cjs/isRecord.cjs.map +0 -1
- package/dist/_chunks-cjs/resolveEditInfo.cjs +0 -334
- package/dist/_chunks-cjs/resolveEditInfo.cjs.map +0 -1
- package/dist/_chunks-cjs/stegaClean.cjs +0 -46
- package/dist/_chunks-cjs/stegaClean.cjs.map +0 -1
- package/dist/_chunks-cjs/stegaEncodeSourceMap.cjs +0 -388
- package/dist/_chunks-cjs/stegaEncodeSourceMap.cjs.map +0 -1
- package/dist/_chunks-es/config.js +0 -207
- package/dist/_chunks-es/config.js.map +0 -1
- package/dist/_chunks-es/isRecord.js +0 -7
- package/dist/_chunks-es/isRecord.js.map +0 -1
- package/dist/_chunks-es/resolveEditInfo.js +0 -335
- package/dist/_chunks-es/resolveEditInfo.js.map +0 -1
- package/dist/_chunks-es/stegaClean.js +0 -47
- package/dist/_chunks-es/stegaClean.js.map +0 -1
- package/dist/_chunks-es/stegaEncodeSourceMap.js +0 -389
- package/dist/_chunks-es/stegaEncodeSourceMap.js.map +0 -1
- package/dist/csm.cjs +0 -99
- package/dist/csm.cjs.map +0 -1
- package/dist/csm.d.cts +0 -403
- package/dist/index.browser.cjs +0 -3106
- package/dist/index.browser.cjs.map +0 -1
- package/dist/index.browser.d.ts +0 -6841
- package/dist/index.browser.js +0 -3082
- package/dist/index.browser.js.map +0 -1
- package/dist/index.cjs +0 -2947
- package/dist/index.cjs.map +0 -1
- package/dist/media-library.cjs +0 -20
- package/dist/media-library.cjs.map +0 -1
- package/dist/media-library.d.cts +0 -117
- package/dist/stega.browser.cjs +0 -29
- package/dist/stega.browser.cjs.map +0 -1
- package/dist/stega.browser.d.cts +0 -7242
- package/dist/stega.browser.d.ts +0 -7242
- package/dist/stega.browser.js +0 -24
- package/dist/stega.browser.js.map +0 -1
- package/dist/stega.cjs +0 -29
- package/dist/stega.cjs.map +0 -1
- package/dist/stega.d.cts +0 -7242
- package/src/data/eventsourcePolyfill.ts +0 -7
- package/umd/.gitkeep +0 -1
- package/umd/sanityClient.js +0 -6536
- 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 {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
|
-
//
|
|
104
|
+
// oxlint-disable-next-line no-unused-vars
|
|
105
105
|
interface PromptJsonResponse<T extends Record<string, Any> = Record<string, Any>> {
|
|
106
106
|
/**
|
|
107
107
|
*
|
|
@@ -125,15 +125,28 @@ export type PromptRequest<T extends Record<string, Any> = Record<string, Any>> =
|
|
|
125
125
|
) &
|
|
126
126
|
PromptRequestBase
|
|
127
127
|
|
|
128
|
-
export function
|
|
128
|
+
export function _promptObservable<const DocumentShape extends Record<string, Any>>(
|
|
129
129
|
client: SanityClient | ObservableSanityClient,
|
|
130
130
|
httpRequest: HttpRequest,
|
|
131
131
|
request: PromptRequest<DocumentShape>,
|
|
132
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> {
|
|
133
146
|
const dataset = hasDataset(client.config())
|
|
134
147
|
return _request(client, httpRequest, {
|
|
135
148
|
method: 'POST',
|
|
136
|
-
|
|
149
|
+
url: `/agent/action/prompt/${dataset}`,
|
|
137
150
|
body: request,
|
|
138
151
|
})
|
|
139
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
|
-
//
|
|
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
|
|
|
@@ -325,7 +325,7 @@ export type TransformDocument<T extends Record<string, Any> = Record<string, Any
|
|
|
325
325
|
| TransformDocumentSync<T>
|
|
326
326
|
| TransformDocumentAsync
|
|
327
327
|
|
|
328
|
-
export function
|
|
328
|
+
export function _transformObservable<DocumentShape extends Record<string, Any>>(
|
|
329
329
|
client: SanityClient | ObservableSanityClient,
|
|
330
330
|
httpRequest: HttpRequest,
|
|
331
331
|
request: TransformDocument<DocumentShape>,
|
|
@@ -333,11 +333,28 @@ export function _transform<DocumentShape extends Record<string, Any>>(
|
|
|
333
333
|
(typeof request)['async'] extends true
|
|
334
334
|
? {_id: string}
|
|
335
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
|
|
336
353
|
> {
|
|
337
354
|
const dataset = hasDataset(client.config())
|
|
338
355
|
return _request(client, httpRequest, {
|
|
339
356
|
method: 'POST',
|
|
340
|
-
|
|
357
|
+
url: `/agent/action/transform/${dataset}`,
|
|
341
358
|
body: request,
|
|
342
359
|
})
|
|
343
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
|
-
//
|
|
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
|
|
|
@@ -150,7 +150,7 @@ export type TranslateDocument<T extends Record<string, Any> = Record<string, Any
|
|
|
150
150
|
| TranslateDocumentSync<T>
|
|
151
151
|
| TranslateDocumentAsync
|
|
152
152
|
|
|
153
|
-
export function
|
|
153
|
+
export function _translateObservable<DocumentShape extends Record<string, Any>>(
|
|
154
154
|
client: SanityClient | ObservableSanityClient,
|
|
155
155
|
httpRequest: HttpRequest,
|
|
156
156
|
request: TranslateDocument<DocumentShape>,
|
|
@@ -158,11 +158,28 @@ export function _translate<DocumentShape extends Record<string, Any>>(
|
|
|
158
158
|
(typeof request)['async'] extends true
|
|
159
159
|
? {_id: string}
|
|
160
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
|
|
161
178
|
> {
|
|
162
179
|
const dataset = hasDataset(client.config())
|
|
163
180
|
return _request(client, httpRequest, {
|
|
164
181
|
method: 'POST',
|
|
165
|
-
|
|
182
|
+
url: `/agent/action/translate/${dataset}`,
|
|
166
183
|
body: request,
|
|
167
184
|
})
|
|
168
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 {
|
|
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<
|
|
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<
|
|
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<
|
|
65
|
+
): Observable<UploadEvent<{document: SanityAssetDocument | SanityImageAssetDocument}>>
|
|
65
66
|
upload(
|
|
66
67
|
assetType: 'file' | 'image',
|
|
67
68
|
body: UploadBody,
|
|
68
69
|
options?: UploadClientConfig,
|
|
69
|
-
): Observable<
|
|
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
|
-
|
|
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:
|
|
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
|
-
|
|
138
|
+
_httpRequest: HttpRequest,
|
|
141
139
|
assetType: 'image' | 'file',
|
|
142
140
|
body: UploadBody,
|
|
143
141
|
opts: UploadClientConfig = {},
|
|
144
|
-
): Observable<
|
|
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
|
-
|
|
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
|
-
|
|
188
|
-
headers
|
|
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 {
|
package/src/csm/createEditUrl.ts
CHANGED
|
@@ -36,7 +36,7 @@ export function createEditUrl(options: CreateEditUrlOptions): `${StudioBaseUrl}$
|
|
|
36
36
|
? studioPath.toString(jsonPathToStudioPath(path))
|
|
37
37
|
: path
|
|
38
38
|
|
|
39
|
-
//
|
|
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,
|
package/src/csm/draftUtils.ts
CHANGED
|
@@ -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
package/src/csm/studioPath.ts
CHANGED
|
@@ -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
|
|
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
|
@@ -39,7 +39,11 @@ export type ContentSourceMapParsedPath = (
|
|
|
39
39
|
)[]
|
|
40
40
|
|
|
41
41
|
/** @alpha */
|
|
42
|
-
export type StudioBaseUrl =
|
|
42
|
+
export type StudioBaseUrl =
|
|
43
|
+
| `/${string}`
|
|
44
|
+
| `${string}.sanity.studio`
|
|
45
|
+
| `https://${string}`
|
|
46
|
+
| (string & {})
|
|
43
47
|
|
|
44
48
|
/** @alpha */
|
|
45
49
|
export type StudioBaseRoute = {baseUrl: StudioBaseUrl; workspace?: string; tool?: string}
|