@sanity/cli 7.12.1 → 7.13.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 +88 -0
- package/dist/actions/api/constants.js +13 -0
- package/dist/actions/api/constants.js.map +1 -0
- package/dist/actions/api/distillApiRoutes.js +106 -0
- package/dist/actions/api/distillApiRoutes.js.map +1 -0
- package/dist/actions/api/errors.js +18 -0
- package/dist/actions/api/errors.js.map +1 -0
- package/dist/actions/api/parseFields.js +183 -0
- package/dist/actions/api/parseFields.js.map +1 -0
- package/dist/actions/api/resolveEndpoint.js +159 -0
- package/dist/actions/api/resolveEndpoint.js.map +1 -0
- package/dist/actions/api/types.js +10 -0
- package/dist/actions/api/types.js.map +1 -0
- package/dist/actions/build/buildApp.js +3 -1
- package/dist/actions/build/buildApp.js.map +1 -1
- package/dist/actions/build/buildStudio.js +104 -13
- package/dist/actions/build/buildStudio.js.map +1 -1
- package/dist/actions/build/eventListenerFactory.js +70 -0
- package/dist/actions/build/eventListenerFactory.js.map +1 -0
- package/dist/actions/dev/servers/startStudioDevServer.js +5 -1
- package/dist/actions/dev/servers/startStudioDevServer.js.map +1 -1
- package/dist/commands/api.js +294 -0
- package/dist/commands/api.js.map +1 -0
- package/dist/generated/apiRoutes.js +401 -0
- package/dist/generated/apiRoutes.js.map +1 -0
- package/dist/services/api.js +116 -0
- package/dist/services/api.js.map +1 -0
- package/oclif.manifest.json +709 -528
- package/package.json +9 -7
|
@@ -0,0 +1,401 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* GENERATED FILE - DO NOT EDIT
|
|
3
|
+
*
|
|
4
|
+
* Routing manifest for `sanity api`, distilled from the published OpenAPI
|
|
5
|
+
* specifications at https://www.sanity.io/docs/api/openapi
|
|
6
|
+
*
|
|
7
|
+
* Regenerate with: pnpm generate:api-routes
|
|
8
|
+
*/ export const apiRoutes = [
|
|
9
|
+
{
|
|
10
|
+
defaultApiVersion: 'v2025-07-11',
|
|
11
|
+
host: 'global',
|
|
12
|
+
pathPatterns: [
|
|
13
|
+
'access/invites/me',
|
|
14
|
+
'access/organization/{resourceId}/users/roles/default',
|
|
15
|
+
'access/requests/me',
|
|
16
|
+
'access/robots/me',
|
|
17
|
+
'access/robots/me/rotate',
|
|
18
|
+
'access/{resourceType}/{resourceId}/invites',
|
|
19
|
+
'access/{resourceType}/{resourceId}/invites/token/{inviteToken}',
|
|
20
|
+
'access/{resourceType}/{resourceId}/invites/token/{inviteToken}/accept',
|
|
21
|
+
'access/{resourceType}/{resourceId}/invites/{inviteId}',
|
|
22
|
+
'access/{resourceType}/{resourceId}/permissions',
|
|
23
|
+
'access/{resourceType}/{resourceId}/permissions/{permissionName}',
|
|
24
|
+
'access/{resourceType}/{resourceId}/requests',
|
|
25
|
+
'access/{resourceType}/{resourceId}/requests/{requestId}/accept',
|
|
26
|
+
'access/{resourceType}/{resourceId}/requests/{requestId}/decline',
|
|
27
|
+
'access/{resourceType}/{resourceId}/robots',
|
|
28
|
+
'access/{resourceType}/{resourceId}/robots/{robotId}',
|
|
29
|
+
'access/{resourceType}/{resourceId}/roles',
|
|
30
|
+
'access/{resourceType}/{resourceId}/roles/{roleName}',
|
|
31
|
+
'access/{resourceType}/{resourceId}/user-permissions/me',
|
|
32
|
+
'access/{resourceType}/{resourceId}/user-permissions/me/check',
|
|
33
|
+
'access/{resourceType}/{resourceId}/users',
|
|
34
|
+
'access/{resourceType}/{resourceId}/users/me',
|
|
35
|
+
'access/{resourceType}/{resourceId}/users/{sanityUserId}',
|
|
36
|
+
'access/{resourceType}/{resourceId}/users/{sanityUserId}/roles',
|
|
37
|
+
'access/{resourceType}/{resourceId}/users/{sanityUserId}/roles/{roleName}'
|
|
38
|
+
],
|
|
39
|
+
slug: 'access-api',
|
|
40
|
+
title: 'Access API reference'
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
defaultApiVersion: 'v2025-02-19',
|
|
44
|
+
host: 'project',
|
|
45
|
+
pathPatterns: [
|
|
46
|
+
'data/actions/{dataset}'
|
|
47
|
+
],
|
|
48
|
+
slug: 'actions',
|
|
49
|
+
title: 'Actions API reference'
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
defaultApiVersion: 'v2021-02-01',
|
|
53
|
+
host: 'global',
|
|
54
|
+
pathPatterns: [
|
|
55
|
+
'activity',
|
|
56
|
+
'activity/export/csv'
|
|
57
|
+
],
|
|
58
|
+
slug: 'activity-log',
|
|
59
|
+
title: 'Activity Log API Reference'
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
defaultApiVersion: 'vX',
|
|
63
|
+
host: 'project',
|
|
64
|
+
pathPatterns: [
|
|
65
|
+
'agent/action/generate/{dataset}',
|
|
66
|
+
'agent/action/patch/{dataset}',
|
|
67
|
+
'agent/action/prompt/{dataset}',
|
|
68
|
+
'agent/action/transform/{dataset}',
|
|
69
|
+
'agent/action/translate/{dataset}'
|
|
70
|
+
],
|
|
71
|
+
slug: 'agent-actions',
|
|
72
|
+
title: 'Agent Actions'
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
host: 'global',
|
|
76
|
+
pathPatterns: [
|
|
77
|
+
'applications',
|
|
78
|
+
'applications/{applicationId}',
|
|
79
|
+
'applications/{applicationId}/access',
|
|
80
|
+
'applications/{applicationId}/deployments',
|
|
81
|
+
'applications/{applicationId}/installations',
|
|
82
|
+
'applications/{applicationId}/interfaces',
|
|
83
|
+
'applications/{applicationId}/workspaces',
|
|
84
|
+
'deploy',
|
|
85
|
+
'deploy/quickstart',
|
|
86
|
+
'installations',
|
|
87
|
+
'installations/{installationId}',
|
|
88
|
+
'installations/{installationId}/access',
|
|
89
|
+
'installations/{installationId}/configs',
|
|
90
|
+
'installations/{installationId}/configs/{configId}',
|
|
91
|
+
'installations/{installationId}/interfaces',
|
|
92
|
+
'projects/{projectId}/user-applications',
|
|
93
|
+
'projects/{projectId}/user-applications/{userApplicationId}',
|
|
94
|
+
'projects/{projectId}/user-applications/{userApplicationId}/config/{configKey}',
|
|
95
|
+
'projects/{projectId}/user-applications/{userApplicationId}/deployments',
|
|
96
|
+
'studiohosts/{appHost}/availability',
|
|
97
|
+
'user-applications',
|
|
98
|
+
'user-applications/auto-update-version/{userApplicationId}',
|
|
99
|
+
'user-applications/resolve/application',
|
|
100
|
+
'user-applications/resolve/project',
|
|
101
|
+
'user-applications/workspaces',
|
|
102
|
+
'user-applications/{userApplicationId}',
|
|
103
|
+
'user-applications/{userApplicationId}/applicationData',
|
|
104
|
+
'user-applications/{userApplicationId}/config/{configKey}',
|
|
105
|
+
'user-applications/{userApplicationId}/deployments',
|
|
106
|
+
'user-applications/{userApplicationId}/workspaces'
|
|
107
|
+
],
|
|
108
|
+
slug: 'applications-api',
|
|
109
|
+
title: 'Applications API Reference'
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
host: 'project',
|
|
113
|
+
pathPatterns: [
|
|
114
|
+
'applications',
|
|
115
|
+
'applications/{applicationId}',
|
|
116
|
+
'applications/{applicationId}/access',
|
|
117
|
+
'applications/{applicationId}/deployments',
|
|
118
|
+
'applications/{applicationId}/installations',
|
|
119
|
+
'applications/{applicationId}/interfaces',
|
|
120
|
+
'applications/{applicationId}/workspaces',
|
|
121
|
+
'deploy',
|
|
122
|
+
'deploy/quickstart',
|
|
123
|
+
'installations',
|
|
124
|
+
'installations/{installationId}',
|
|
125
|
+
'installations/{installationId}/access',
|
|
126
|
+
'installations/{installationId}/configs',
|
|
127
|
+
'installations/{installationId}/configs/{configId}',
|
|
128
|
+
'installations/{installationId}/interfaces',
|
|
129
|
+
'projects/{projectId}/user-applications',
|
|
130
|
+
'projects/{projectId}/user-applications/{userApplicationId}',
|
|
131
|
+
'projects/{projectId}/user-applications/{userApplicationId}/config/{configKey}',
|
|
132
|
+
'projects/{projectId}/user-applications/{userApplicationId}/deployments',
|
|
133
|
+
'studiohosts/{appHost}/availability',
|
|
134
|
+
'user-applications',
|
|
135
|
+
'user-applications/auto-update-version/{userApplicationId}',
|
|
136
|
+
'user-applications/resolve/application',
|
|
137
|
+
'user-applications/resolve/project',
|
|
138
|
+
'user-applications/workspaces',
|
|
139
|
+
'user-applications/{userApplicationId}',
|
|
140
|
+
'user-applications/{userApplicationId}/applicationData',
|
|
141
|
+
'user-applications/{userApplicationId}/config/{configKey}',
|
|
142
|
+
'user-applications/{userApplicationId}/deployments',
|
|
143
|
+
'user-applications/{userApplicationId}/workspaces'
|
|
144
|
+
],
|
|
145
|
+
slug: 'applications-api',
|
|
146
|
+
title: 'Applications API Reference'
|
|
147
|
+
},
|
|
148
|
+
{
|
|
149
|
+
defaultApiVersion: 'v2024-06-24',
|
|
150
|
+
host: 'project',
|
|
151
|
+
pathPatterns: [
|
|
152
|
+
'assets/files/{dataset}',
|
|
153
|
+
'assets/images/{dataset}',
|
|
154
|
+
'assets/media-library-link/{dataset}'
|
|
155
|
+
],
|
|
156
|
+
slug: 'assets',
|
|
157
|
+
title: 'Assets API reference'
|
|
158
|
+
},
|
|
159
|
+
{
|
|
160
|
+
defaultApiVersion: 'v2025-02-19',
|
|
161
|
+
host: 'global',
|
|
162
|
+
pathPatterns: [
|
|
163
|
+
'projects/{projectId}/datasets/{datasetName}/backups',
|
|
164
|
+
'projects/{projectId}/datasets/{datasetName}/backups/{backupId}',
|
|
165
|
+
'projects/{projectId}/datasets/{datasetName}/settings/backups'
|
|
166
|
+
],
|
|
167
|
+
slug: 'backups',
|
|
168
|
+
title: 'Backups API reference'
|
|
169
|
+
},
|
|
170
|
+
{
|
|
171
|
+
defaultApiVersion: 'vX',
|
|
172
|
+
host: 'global',
|
|
173
|
+
pathPatterns: [
|
|
174
|
+
'agent/prompt',
|
|
175
|
+
'agent/{organizationId}/threads/{threadId}'
|
|
176
|
+
],
|
|
177
|
+
slug: 'content-agent',
|
|
178
|
+
title: 'Content Agent API reference'
|
|
179
|
+
},
|
|
180
|
+
{
|
|
181
|
+
defaultApiVersion: 'v2025-02-19',
|
|
182
|
+
host: 'global',
|
|
183
|
+
pathPatterns: [
|
|
184
|
+
'projects/{projectId}/datasets/{dataset}/copy'
|
|
185
|
+
],
|
|
186
|
+
slug: 'copy',
|
|
187
|
+
title: 'Copy API reference'
|
|
188
|
+
},
|
|
189
|
+
{
|
|
190
|
+
defaultApiVersion: 'v2025-02-19',
|
|
191
|
+
host: 'project',
|
|
192
|
+
pathPatterns: [
|
|
193
|
+
'data/doc/{dataset}/{documentId}'
|
|
194
|
+
],
|
|
195
|
+
slug: 'doc',
|
|
196
|
+
title: 'Doc API reference'
|
|
197
|
+
},
|
|
198
|
+
{
|
|
199
|
+
defaultApiVersion: 'vX',
|
|
200
|
+
host: 'project',
|
|
201
|
+
pathPatterns: [
|
|
202
|
+
'embeddings-index/query/{dataset}/{indexName}',
|
|
203
|
+
'embeddings-index/{dataset}',
|
|
204
|
+
'embeddings-index/{dataset}/{indexName}'
|
|
205
|
+
],
|
|
206
|
+
slug: 'embeddings-index',
|
|
207
|
+
title: 'Embeddings Index API reference'
|
|
208
|
+
},
|
|
209
|
+
{
|
|
210
|
+
defaultApiVersion: 'v2021-03-25',
|
|
211
|
+
host: 'project',
|
|
212
|
+
pathPatterns: [
|
|
213
|
+
'data/export/{dataset}'
|
|
214
|
+
],
|
|
215
|
+
slug: 'export',
|
|
216
|
+
title: 'Export API reference'
|
|
217
|
+
},
|
|
218
|
+
{
|
|
219
|
+
defaultApiVersion: 'v2025-02-19',
|
|
220
|
+
host: 'project',
|
|
221
|
+
pathPatterns: [
|
|
222
|
+
'data/history/{dataset}/documents/{documentId}',
|
|
223
|
+
'data/history/{dataset}/transactions',
|
|
224
|
+
'data/history/{dataset}/transactions/{documentIds}'
|
|
225
|
+
],
|
|
226
|
+
slug: 'history',
|
|
227
|
+
title: 'History API reference'
|
|
228
|
+
},
|
|
229
|
+
{
|
|
230
|
+
defaultApiVersion: 'v2021-06-07',
|
|
231
|
+
host: 'global',
|
|
232
|
+
pathPatterns: [
|
|
233
|
+
'jobs/{jobId}',
|
|
234
|
+
'jobs/{jobId}/listen'
|
|
235
|
+
],
|
|
236
|
+
slug: 'jobs',
|
|
237
|
+
title: 'Jobs API reference'
|
|
238
|
+
},
|
|
239
|
+
{
|
|
240
|
+
defaultApiVersion: 'v2025-02-19',
|
|
241
|
+
host: 'project',
|
|
242
|
+
pathPatterns: [
|
|
243
|
+
'data/listen/{dataset}'
|
|
244
|
+
],
|
|
245
|
+
slug: 'listen',
|
|
246
|
+
title: 'Listen API reference'
|
|
247
|
+
},
|
|
248
|
+
{
|
|
249
|
+
defaultApiVersion: 'v2025-02-19',
|
|
250
|
+
host: 'project',
|
|
251
|
+
pathPatterns: [
|
|
252
|
+
'data/live/events/{dataset}'
|
|
253
|
+
],
|
|
254
|
+
slug: 'live',
|
|
255
|
+
title: 'Live Content API reference'
|
|
256
|
+
},
|
|
257
|
+
{
|
|
258
|
+
defaultApiVersion: 'v2025-02-19',
|
|
259
|
+
host: 'global',
|
|
260
|
+
pathPatterns: [
|
|
261
|
+
'media-libraries/{libraryId}/mutate',
|
|
262
|
+
'media-libraries/{libraryId}/query',
|
|
263
|
+
'media-libraries/{libraryId}/references/documents/{assetId}/to',
|
|
264
|
+
'media-libraries/{libraryId}/refsearch',
|
|
265
|
+
'media-libraries/{libraryId}/signing-keys',
|
|
266
|
+
'media-libraries/{libraryId}/signing-keys/{keyId}',
|
|
267
|
+
'media-libraries/{libraryId}/upload',
|
|
268
|
+
'media-libraries/{libraryId}/video/{videoId}/playback-info',
|
|
269
|
+
'media-libraries/{libraryId}/video/{videoId}/playback/{type}',
|
|
270
|
+
'media-libraries/{libraryId}/video/{videoId}/renditions/{name}',
|
|
271
|
+
'media-libraries/{libraryId}/video/{videoId}/subtitles',
|
|
272
|
+
'media-libraries/{libraryId}/video/{videoId}/subtitles/upload',
|
|
273
|
+
'media-libraries/{libraryId}/video/{videoId}/subtitles/{subtitleId}'
|
|
274
|
+
],
|
|
275
|
+
slug: 'media-library',
|
|
276
|
+
title: 'Media Library API reference'
|
|
277
|
+
},
|
|
278
|
+
{
|
|
279
|
+
defaultApiVersion: 'v2025-02-19',
|
|
280
|
+
host: 'project',
|
|
281
|
+
pathPatterns: [
|
|
282
|
+
'media-libraries/{libraryId}/mutate',
|
|
283
|
+
'media-libraries/{libraryId}/query',
|
|
284
|
+
'media-libraries/{libraryId}/references/documents/{assetId}/to',
|
|
285
|
+
'media-libraries/{libraryId}/refsearch',
|
|
286
|
+
'media-libraries/{libraryId}/signing-keys',
|
|
287
|
+
'media-libraries/{libraryId}/signing-keys/{keyId}',
|
|
288
|
+
'media-libraries/{libraryId}/upload',
|
|
289
|
+
'media-libraries/{libraryId}/video/{videoId}/playback-info',
|
|
290
|
+
'media-libraries/{libraryId}/video/{videoId}/playback/{type}',
|
|
291
|
+
'media-libraries/{libraryId}/video/{videoId}/renditions/{name}',
|
|
292
|
+
'media-libraries/{libraryId}/video/{videoId}/subtitles',
|
|
293
|
+
'media-libraries/{libraryId}/video/{videoId}/subtitles/upload',
|
|
294
|
+
'media-libraries/{libraryId}/video/{videoId}/subtitles/{subtitleId}'
|
|
295
|
+
],
|
|
296
|
+
slug: 'media-library',
|
|
297
|
+
title: 'Media Library API reference'
|
|
298
|
+
},
|
|
299
|
+
{
|
|
300
|
+
defaultApiVersion: 'v2025-02-19',
|
|
301
|
+
host: 'project',
|
|
302
|
+
pathPatterns: [
|
|
303
|
+
'data/mutate/{dataset}'
|
|
304
|
+
],
|
|
305
|
+
slug: 'mutation',
|
|
306
|
+
title: 'Mutation API reference'
|
|
307
|
+
},
|
|
308
|
+
{
|
|
309
|
+
defaultApiVersion: 'v2021-06-07',
|
|
310
|
+
host: 'global',
|
|
311
|
+
pathPatterns: [
|
|
312
|
+
'projects',
|
|
313
|
+
'projects/{projectId}',
|
|
314
|
+
'projects/{projectId}/cors',
|
|
315
|
+
'projects/{projectId}/cors/{id}',
|
|
316
|
+
'projects/{projectId}/datasets',
|
|
317
|
+
'projects/{projectId}/datasets/{datasetName}/tags/{tagIdentifier}',
|
|
318
|
+
'projects/{projectId}/datasets/{name}',
|
|
319
|
+
'projects/{projectId}/datasets/{name}/copy',
|
|
320
|
+
'projects/{projectId}/datasets/{name}/settings/embeddings',
|
|
321
|
+
'projects/{projectId}/datasets/{name}/tags',
|
|
322
|
+
'projects/{projectId}/features',
|
|
323
|
+
'projects/{projectId}/permissions',
|
|
324
|
+
'projects/{projectId}/tags',
|
|
325
|
+
'projects/{projectId}/tags/{tagIdentifier}',
|
|
326
|
+
'projects/{projectId}/tokens',
|
|
327
|
+
'projects/{projectId}/tokens/{tokenId}',
|
|
328
|
+
'projects/{projectId}/users/{userId}'
|
|
329
|
+
],
|
|
330
|
+
slug: 'projects-api',
|
|
331
|
+
title: 'Projects API reference'
|
|
332
|
+
},
|
|
333
|
+
{
|
|
334
|
+
defaultApiVersion: 'v2025-02-19',
|
|
335
|
+
host: 'project',
|
|
336
|
+
pathPatterns: [
|
|
337
|
+
'data/query/{dataset}'
|
|
338
|
+
],
|
|
339
|
+
slug: 'query',
|
|
340
|
+
title: 'Query API reference'
|
|
341
|
+
},
|
|
342
|
+
{
|
|
343
|
+
defaultApiVersion: 'v2021-10-04',
|
|
344
|
+
host: 'global',
|
|
345
|
+
pathPatterns: [
|
|
346
|
+
'organizations/{organizationId}/acl',
|
|
347
|
+
'organizations/{organizationId}/acl/{sanityUserId}',
|
|
348
|
+
'organizations/{organizationId}/grants',
|
|
349
|
+
'organizations/{organizationId}/providers/{providerId}/projects/{projectId}/role-mappings',
|
|
350
|
+
'projects/{projectId}/acl',
|
|
351
|
+
'projects/{projectId}/acl/{userId}',
|
|
352
|
+
'projects/{projectId}/datasets/{datasetName}/acl',
|
|
353
|
+
'projects/{projectId}/datasets/{datasetName}/grants',
|
|
354
|
+
'projects/{projectId}/grants',
|
|
355
|
+
'projects/{projectId}/permissionResourceSchemas',
|
|
356
|
+
'projects/{projectId}/roles',
|
|
357
|
+
'projects/{projectId}/roles/{roleName}'
|
|
358
|
+
],
|
|
359
|
+
slug: 'roles',
|
|
360
|
+
title: 'Roles API reference'
|
|
361
|
+
},
|
|
362
|
+
{
|
|
363
|
+
defaultApiVersion: 'v2022-04-01',
|
|
364
|
+
host: 'project',
|
|
365
|
+
pathPatterns: [
|
|
366
|
+
'publish/{projectId}/{dataset}',
|
|
367
|
+
'schedules/{projectId}/{dataset}',
|
|
368
|
+
'schedules/{projectId}/{dataset}/{scheduleId}',
|
|
369
|
+
'schedules/{projectId}/{dataset}/{scheduleId}/publish',
|
|
370
|
+
'unpublish/{projectId}/{dataset}'
|
|
371
|
+
],
|
|
372
|
+
slug: 'scheduling',
|
|
373
|
+
title: 'Scheduling API reference'
|
|
374
|
+
},
|
|
375
|
+
{
|
|
376
|
+
defaultApiVersion: 'v2026-04-27',
|
|
377
|
+
host: 'global',
|
|
378
|
+
pathPatterns: [
|
|
379
|
+
'organizations/{organizationId}/attribute-definitions',
|
|
380
|
+
'organizations/{organizationId}/attribute-definitions/{key}',
|
|
381
|
+
'organizations/{organizationId}/users/me/attributes',
|
|
382
|
+
'organizations/{organizationId}/users/{sanityUserId}/attributes'
|
|
383
|
+
],
|
|
384
|
+
slug: 'user-attributes',
|
|
385
|
+
title: 'User attributes API reference'
|
|
386
|
+
},
|
|
387
|
+
{
|
|
388
|
+
defaultApiVersion: 'v2025-02-19',
|
|
389
|
+
host: 'project',
|
|
390
|
+
pathPatterns: [
|
|
391
|
+
'hooks/projects/{projectId}',
|
|
392
|
+
'hooks/projects/{projectId}/{id}',
|
|
393
|
+
'hooks/projects/{projectId}/{id}/attempts',
|
|
394
|
+
'hooks/{id}/messages'
|
|
395
|
+
],
|
|
396
|
+
slug: 'webhooks',
|
|
397
|
+
title: 'Webhooks API reference'
|
|
398
|
+
}
|
|
399
|
+
];
|
|
400
|
+
|
|
401
|
+
//# sourceMappingURL=apiRoutes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/generated/apiRoutes.ts"],"sourcesContent":["/**\n * GENERATED FILE - DO NOT EDIT\n *\n * Routing manifest for `sanity api`, distilled from the published OpenAPI\n * specifications at https://www.sanity.io/docs/api/openapi\n *\n * Regenerate with: pnpm generate:api-routes\n */\nimport {type ApiRouteEntry} from '../actions/api/types.js'\n\nexport const apiRoutes: ApiRouteEntry[] = [\n {\n defaultApiVersion: 'v2025-07-11',\n host: 'global',\n pathPatterns: [\n 'access/invites/me',\n 'access/organization/{resourceId}/users/roles/default',\n 'access/requests/me',\n 'access/robots/me',\n 'access/robots/me/rotate',\n 'access/{resourceType}/{resourceId}/invites',\n 'access/{resourceType}/{resourceId}/invites/token/{inviteToken}',\n 'access/{resourceType}/{resourceId}/invites/token/{inviteToken}/accept',\n 'access/{resourceType}/{resourceId}/invites/{inviteId}',\n 'access/{resourceType}/{resourceId}/permissions',\n 'access/{resourceType}/{resourceId}/permissions/{permissionName}',\n 'access/{resourceType}/{resourceId}/requests',\n 'access/{resourceType}/{resourceId}/requests/{requestId}/accept',\n 'access/{resourceType}/{resourceId}/requests/{requestId}/decline',\n 'access/{resourceType}/{resourceId}/robots',\n 'access/{resourceType}/{resourceId}/robots/{robotId}',\n 'access/{resourceType}/{resourceId}/roles',\n 'access/{resourceType}/{resourceId}/roles/{roleName}',\n 'access/{resourceType}/{resourceId}/user-permissions/me',\n 'access/{resourceType}/{resourceId}/user-permissions/me/check',\n 'access/{resourceType}/{resourceId}/users',\n 'access/{resourceType}/{resourceId}/users/me',\n 'access/{resourceType}/{resourceId}/users/{sanityUserId}',\n 'access/{resourceType}/{resourceId}/users/{sanityUserId}/roles',\n 'access/{resourceType}/{resourceId}/users/{sanityUserId}/roles/{roleName}'\n ],\n slug: 'access-api',\n title: 'Access API reference'\n },\n {\n defaultApiVersion: 'v2025-02-19',\n host: 'project',\n pathPatterns: [\n 'data/actions/{dataset}'\n ],\n slug: 'actions',\n title: 'Actions API reference'\n },\n {\n defaultApiVersion: 'v2021-02-01',\n host: 'global',\n pathPatterns: [\n 'activity',\n 'activity/export/csv'\n ],\n slug: 'activity-log',\n title: 'Activity Log API Reference'\n },\n {\n defaultApiVersion: 'vX',\n host: 'project',\n pathPatterns: [\n 'agent/action/generate/{dataset}',\n 'agent/action/patch/{dataset}',\n 'agent/action/prompt/{dataset}',\n 'agent/action/transform/{dataset}',\n 'agent/action/translate/{dataset}'\n ],\n slug: 'agent-actions',\n title: 'Agent Actions'\n },\n {\n host: 'global',\n pathPatterns: [\n 'applications',\n 'applications/{applicationId}',\n 'applications/{applicationId}/access',\n 'applications/{applicationId}/deployments',\n 'applications/{applicationId}/installations',\n 'applications/{applicationId}/interfaces',\n 'applications/{applicationId}/workspaces',\n 'deploy',\n 'deploy/quickstart',\n 'installations',\n 'installations/{installationId}',\n 'installations/{installationId}/access',\n 'installations/{installationId}/configs',\n 'installations/{installationId}/configs/{configId}',\n 'installations/{installationId}/interfaces',\n 'projects/{projectId}/user-applications',\n 'projects/{projectId}/user-applications/{userApplicationId}',\n 'projects/{projectId}/user-applications/{userApplicationId}/config/{configKey}',\n 'projects/{projectId}/user-applications/{userApplicationId}/deployments',\n 'studiohosts/{appHost}/availability',\n 'user-applications',\n 'user-applications/auto-update-version/{userApplicationId}',\n 'user-applications/resolve/application',\n 'user-applications/resolve/project',\n 'user-applications/workspaces',\n 'user-applications/{userApplicationId}',\n 'user-applications/{userApplicationId}/applicationData',\n 'user-applications/{userApplicationId}/config/{configKey}',\n 'user-applications/{userApplicationId}/deployments',\n 'user-applications/{userApplicationId}/workspaces'\n ],\n slug: 'applications-api',\n title: 'Applications API Reference'\n },\n {\n host: 'project',\n pathPatterns: [\n 'applications',\n 'applications/{applicationId}',\n 'applications/{applicationId}/access',\n 'applications/{applicationId}/deployments',\n 'applications/{applicationId}/installations',\n 'applications/{applicationId}/interfaces',\n 'applications/{applicationId}/workspaces',\n 'deploy',\n 'deploy/quickstart',\n 'installations',\n 'installations/{installationId}',\n 'installations/{installationId}/access',\n 'installations/{installationId}/configs',\n 'installations/{installationId}/configs/{configId}',\n 'installations/{installationId}/interfaces',\n 'projects/{projectId}/user-applications',\n 'projects/{projectId}/user-applications/{userApplicationId}',\n 'projects/{projectId}/user-applications/{userApplicationId}/config/{configKey}',\n 'projects/{projectId}/user-applications/{userApplicationId}/deployments',\n 'studiohosts/{appHost}/availability',\n 'user-applications',\n 'user-applications/auto-update-version/{userApplicationId}',\n 'user-applications/resolve/application',\n 'user-applications/resolve/project',\n 'user-applications/workspaces',\n 'user-applications/{userApplicationId}',\n 'user-applications/{userApplicationId}/applicationData',\n 'user-applications/{userApplicationId}/config/{configKey}',\n 'user-applications/{userApplicationId}/deployments',\n 'user-applications/{userApplicationId}/workspaces'\n ],\n slug: 'applications-api',\n title: 'Applications API Reference'\n },\n {\n defaultApiVersion: 'v2024-06-24',\n host: 'project',\n pathPatterns: [\n 'assets/files/{dataset}',\n 'assets/images/{dataset}',\n 'assets/media-library-link/{dataset}'\n ],\n slug: 'assets',\n title: 'Assets API reference'\n },\n {\n defaultApiVersion: 'v2025-02-19',\n host: 'global',\n pathPatterns: [\n 'projects/{projectId}/datasets/{datasetName}/backups',\n 'projects/{projectId}/datasets/{datasetName}/backups/{backupId}',\n 'projects/{projectId}/datasets/{datasetName}/settings/backups'\n ],\n slug: 'backups',\n title: 'Backups API reference'\n },\n {\n defaultApiVersion: 'vX',\n host: 'global',\n pathPatterns: [\n 'agent/prompt',\n 'agent/{organizationId}/threads/{threadId}'\n ],\n slug: 'content-agent',\n title: 'Content Agent API reference'\n },\n {\n defaultApiVersion: 'v2025-02-19',\n host: 'global',\n pathPatterns: [\n 'projects/{projectId}/datasets/{dataset}/copy'\n ],\n slug: 'copy',\n title: 'Copy API reference'\n },\n {\n defaultApiVersion: 'v2025-02-19',\n host: 'project',\n pathPatterns: [\n 'data/doc/{dataset}/{documentId}'\n ],\n slug: 'doc',\n title: 'Doc API reference'\n },\n {\n defaultApiVersion: 'vX',\n host: 'project',\n pathPatterns: [\n 'embeddings-index/query/{dataset}/{indexName}',\n 'embeddings-index/{dataset}',\n 'embeddings-index/{dataset}/{indexName}'\n ],\n slug: 'embeddings-index',\n title: 'Embeddings Index API reference'\n },\n {\n defaultApiVersion: 'v2021-03-25',\n host: 'project',\n pathPatterns: [\n 'data/export/{dataset}'\n ],\n slug: 'export',\n title: 'Export API reference'\n },\n {\n defaultApiVersion: 'v2025-02-19',\n host: 'project',\n pathPatterns: [\n 'data/history/{dataset}/documents/{documentId}',\n 'data/history/{dataset}/transactions',\n 'data/history/{dataset}/transactions/{documentIds}'\n ],\n slug: 'history',\n title: 'History API reference'\n },\n {\n defaultApiVersion: 'v2021-06-07',\n host: 'global',\n pathPatterns: [\n 'jobs/{jobId}',\n 'jobs/{jobId}/listen'\n ],\n slug: 'jobs',\n title: 'Jobs API reference'\n },\n {\n defaultApiVersion: 'v2025-02-19',\n host: 'project',\n pathPatterns: [\n 'data/listen/{dataset}'\n ],\n slug: 'listen',\n title: 'Listen API reference'\n },\n {\n defaultApiVersion: 'v2025-02-19',\n host: 'project',\n pathPatterns: [\n 'data/live/events/{dataset}'\n ],\n slug: 'live',\n title: 'Live Content API reference'\n },\n {\n defaultApiVersion: 'v2025-02-19',\n host: 'global',\n pathPatterns: [\n 'media-libraries/{libraryId}/mutate',\n 'media-libraries/{libraryId}/query',\n 'media-libraries/{libraryId}/references/documents/{assetId}/to',\n 'media-libraries/{libraryId}/refsearch',\n 'media-libraries/{libraryId}/signing-keys',\n 'media-libraries/{libraryId}/signing-keys/{keyId}',\n 'media-libraries/{libraryId}/upload',\n 'media-libraries/{libraryId}/video/{videoId}/playback-info',\n 'media-libraries/{libraryId}/video/{videoId}/playback/{type}',\n 'media-libraries/{libraryId}/video/{videoId}/renditions/{name}',\n 'media-libraries/{libraryId}/video/{videoId}/subtitles',\n 'media-libraries/{libraryId}/video/{videoId}/subtitles/upload',\n 'media-libraries/{libraryId}/video/{videoId}/subtitles/{subtitleId}'\n ],\n slug: 'media-library',\n title: 'Media Library API reference'\n },\n {\n defaultApiVersion: 'v2025-02-19',\n host: 'project',\n pathPatterns: [\n 'media-libraries/{libraryId}/mutate',\n 'media-libraries/{libraryId}/query',\n 'media-libraries/{libraryId}/references/documents/{assetId}/to',\n 'media-libraries/{libraryId}/refsearch',\n 'media-libraries/{libraryId}/signing-keys',\n 'media-libraries/{libraryId}/signing-keys/{keyId}',\n 'media-libraries/{libraryId}/upload',\n 'media-libraries/{libraryId}/video/{videoId}/playback-info',\n 'media-libraries/{libraryId}/video/{videoId}/playback/{type}',\n 'media-libraries/{libraryId}/video/{videoId}/renditions/{name}',\n 'media-libraries/{libraryId}/video/{videoId}/subtitles',\n 'media-libraries/{libraryId}/video/{videoId}/subtitles/upload',\n 'media-libraries/{libraryId}/video/{videoId}/subtitles/{subtitleId}'\n ],\n slug: 'media-library',\n title: 'Media Library API reference'\n },\n {\n defaultApiVersion: 'v2025-02-19',\n host: 'project',\n pathPatterns: [\n 'data/mutate/{dataset}'\n ],\n slug: 'mutation',\n title: 'Mutation API reference'\n },\n {\n defaultApiVersion: 'v2021-06-07',\n host: 'global',\n pathPatterns: [\n 'projects',\n 'projects/{projectId}',\n 'projects/{projectId}/cors',\n 'projects/{projectId}/cors/{id}',\n 'projects/{projectId}/datasets',\n 'projects/{projectId}/datasets/{datasetName}/tags/{tagIdentifier}',\n 'projects/{projectId}/datasets/{name}',\n 'projects/{projectId}/datasets/{name}/copy',\n 'projects/{projectId}/datasets/{name}/settings/embeddings',\n 'projects/{projectId}/datasets/{name}/tags',\n 'projects/{projectId}/features',\n 'projects/{projectId}/permissions',\n 'projects/{projectId}/tags',\n 'projects/{projectId}/tags/{tagIdentifier}',\n 'projects/{projectId}/tokens',\n 'projects/{projectId}/tokens/{tokenId}',\n 'projects/{projectId}/users/{userId}'\n ],\n slug: 'projects-api',\n title: 'Projects API reference'\n },\n {\n defaultApiVersion: 'v2025-02-19',\n host: 'project',\n pathPatterns: [\n 'data/query/{dataset}'\n ],\n slug: 'query',\n title: 'Query API reference'\n },\n {\n defaultApiVersion: 'v2021-10-04',\n host: 'global',\n pathPatterns: [\n 'organizations/{organizationId}/acl',\n 'organizations/{organizationId}/acl/{sanityUserId}',\n 'organizations/{organizationId}/grants',\n 'organizations/{organizationId}/providers/{providerId}/projects/{projectId}/role-mappings',\n 'projects/{projectId}/acl',\n 'projects/{projectId}/acl/{userId}',\n 'projects/{projectId}/datasets/{datasetName}/acl',\n 'projects/{projectId}/datasets/{datasetName}/grants',\n 'projects/{projectId}/grants',\n 'projects/{projectId}/permissionResourceSchemas',\n 'projects/{projectId}/roles',\n 'projects/{projectId}/roles/{roleName}'\n ],\n slug: 'roles',\n title: 'Roles API reference'\n },\n {\n defaultApiVersion: 'v2022-04-01',\n host: 'project',\n pathPatterns: [\n 'publish/{projectId}/{dataset}',\n 'schedules/{projectId}/{dataset}',\n 'schedules/{projectId}/{dataset}/{scheduleId}',\n 'schedules/{projectId}/{dataset}/{scheduleId}/publish',\n 'unpublish/{projectId}/{dataset}'\n ],\n slug: 'scheduling',\n title: 'Scheduling API reference'\n },\n {\n defaultApiVersion: 'v2026-04-27',\n host: 'global',\n pathPatterns: [\n 'organizations/{organizationId}/attribute-definitions',\n 'organizations/{organizationId}/attribute-definitions/{key}',\n 'organizations/{organizationId}/users/me/attributes',\n 'organizations/{organizationId}/users/{sanityUserId}/attributes'\n ],\n slug: 'user-attributes',\n title: 'User attributes API reference'\n },\n {\n defaultApiVersion: 'v2025-02-19',\n host: 'project',\n pathPatterns: [\n 'hooks/projects/{projectId}',\n 'hooks/projects/{projectId}/{id}',\n 'hooks/projects/{projectId}/{id}/attempts',\n 'hooks/{id}/messages'\n ],\n slug: 'webhooks',\n title: 'Webhooks API reference'\n }\n]\n"],"names":["apiRoutes","defaultApiVersion","host","pathPatterns","slug","title"],"mappings":"AAAA;;;;;;;CAOC,GAGD,OAAO,MAAMA,YAA6B;IACxC;QACEC,mBAAmB;QACnBC,MAAM;QACNC,cAAc;YACZ;YACA;YACA;YACA;YACA;YACA;YACA;YACA;YACA;YACA;YACA;YACA;YACA;YACA;YACA;YACA;YACA;YACA;YACA;YACA;YACA;YACA;YACA;YACA;YACA;SACD;QACDC,MAAM;QACNC,OAAO;IACT;IACA;QACEJ,mBAAmB;QACnBC,MAAM;QACNC,cAAc;YACZ;SACD;QACDC,MAAM;QACNC,OAAO;IACT;IACA;QACEJ,mBAAmB;QACnBC,MAAM;QACNC,cAAc;YACZ;YACA;SACD;QACDC,MAAM;QACNC,OAAO;IACT;IACA;QACEJ,mBAAmB;QACnBC,MAAM;QACNC,cAAc;YACZ;YACA;YACA;YACA;YACA;SACD;QACDC,MAAM;QACNC,OAAO;IACT;IACA;QACEH,MAAM;QACNC,cAAc;YACZ;YACA;YACA;YACA;YACA;YACA;YACA;YACA;YACA;YACA;YACA;YACA;YACA;YACA;YACA;YACA;YACA;YACA;YACA;YACA;YACA;YACA;YACA;YACA;YACA;YACA;YACA;YACA;YACA;YACA;SACD;QACDC,MAAM;QACNC,OAAO;IACT;IACA;QACEH,MAAM;QACNC,cAAc;YACZ;YACA;YACA;YACA;YACA;YACA;YACA;YACA;YACA;YACA;YACA;YACA;YACA;YACA;YACA;YACA;YACA;YACA;YACA;YACA;YACA;YACA;YACA;YACA;YACA;YACA;YACA;YACA;YACA;YACA;SACD;QACDC,MAAM;QACNC,OAAO;IACT;IACA;QACEJ,mBAAmB;QACnBC,MAAM;QACNC,cAAc;YACZ;YACA;YACA;SACD;QACDC,MAAM;QACNC,OAAO;IACT;IACA;QACEJ,mBAAmB;QACnBC,MAAM;QACNC,cAAc;YACZ;YACA;YACA;SACD;QACDC,MAAM;QACNC,OAAO;IACT;IACA;QACEJ,mBAAmB;QACnBC,MAAM;QACNC,cAAc;YACZ;YACA;SACD;QACDC,MAAM;QACNC,OAAO;IACT;IACA;QACEJ,mBAAmB;QACnBC,MAAM;QACNC,cAAc;YACZ;SACD;QACDC,MAAM;QACNC,OAAO;IACT;IACA;QACEJ,mBAAmB;QACnBC,MAAM;QACNC,cAAc;YACZ;SACD;QACDC,MAAM;QACNC,OAAO;IACT;IACA;QACEJ,mBAAmB;QACnBC,MAAM;QACNC,cAAc;YACZ;YACA;YACA;SACD;QACDC,MAAM;QACNC,OAAO;IACT;IACA;QACEJ,mBAAmB;QACnBC,MAAM;QACNC,cAAc;YACZ;SACD;QACDC,MAAM;QACNC,OAAO;IACT;IACA;QACEJ,mBAAmB;QACnBC,MAAM;QACNC,cAAc;YACZ;YACA;YACA;SACD;QACDC,MAAM;QACNC,OAAO;IACT;IACA;QACEJ,mBAAmB;QACnBC,MAAM;QACNC,cAAc;YACZ;YACA;SACD;QACDC,MAAM;QACNC,OAAO;IACT;IACA;QACEJ,mBAAmB;QACnBC,MAAM;QACNC,cAAc;YACZ;SACD;QACDC,MAAM;QACNC,OAAO;IACT;IACA;QACEJ,mBAAmB;QACnBC,MAAM;QACNC,cAAc;YACZ;SACD;QACDC,MAAM;QACNC,OAAO;IACT;IACA;QACEJ,mBAAmB;QACnBC,MAAM;QACNC,cAAc;YACZ;YACA;YACA;YACA;YACA;YACA;YACA;YACA;YACA;YACA;YACA;YACA;YACA;SACD;QACDC,MAAM;QACNC,OAAO;IACT;IACA;QACEJ,mBAAmB;QACnBC,MAAM;QACNC,cAAc;YACZ;YACA;YACA;YACA;YACA;YACA;YACA;YACA;YACA;YACA;YACA;YACA;YACA;SACD;QACDC,MAAM;QACNC,OAAO;IACT;IACA;QACEJ,mBAAmB;QACnBC,MAAM;QACNC,cAAc;YACZ;SACD;QACDC,MAAM;QACNC,OAAO;IACT;IACA;QACEJ,mBAAmB;QACnBC,MAAM;QACNC,cAAc;YACZ;YACA;YACA;YACA;YACA;YACA;YACA;YACA;YACA;YACA;YACA;YACA;YACA;YACA;YACA;YACA;YACA;SACD;QACDC,MAAM;QACNC,OAAO;IACT;IACA;QACEJ,mBAAmB;QACnBC,MAAM;QACNC,cAAc;YACZ;SACD;QACDC,MAAM;QACNC,OAAO;IACT;IACA;QACEJ,mBAAmB;QACnBC,MAAM;QACNC,cAAc;YACZ;YACA;YACA;YACA;YACA;YACA;YACA;YACA;YACA;YACA;YACA;YACA;SACD;QACDC,MAAM;QACNC,OAAO;IACT;IACA;QACEJ,mBAAmB;QACnBC,MAAM;QACNC,cAAc;YACZ;YACA;YACA;YACA;YACA;SACD;QACDC,MAAM;QACNC,OAAO;IACT;IACA;QACEJ,mBAAmB;QACnBC,MAAM;QACNC,cAAc;YACZ;YACA;YACA;YACA;SACD;QACDC,MAAM;QACNC,OAAO;IACT;IACA;QACEJ,mBAAmB;QACnBC,MAAM;QACNC,cAAc;YACZ;YACA;YACA;YACA;SACD;QACDC,MAAM;QACNC,OAAO;IACT;CACD,CAAA"}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { getCliToken, getGlobalCliClient, getProjectCliClient } from '@sanity/cli-core';
|
|
2
|
+
import { createRequester } from '@sanity/cli-core/request';
|
|
3
|
+
const API_REQUEST_TAG = 'sanity.cli.api';
|
|
4
|
+
/**
|
|
5
|
+
* Perform an authenticated raw HTTP request against a Sanity API.
|
|
6
|
+
*
|
|
7
|
+
* URL construction and token resolution reuse the standard CLI client
|
|
8
|
+
* factories; the request itself uses a bare requester so the response
|
|
9
|
+
* (status, headers, non-JSON bodies) can be passed through unfiltered.
|
|
10
|
+
*/ export async function performApiRequest(options) {
|
|
11
|
+
const { body, headers = {}, method, query = {}, resolved, token: providedToken, unauthenticated = false } = options;
|
|
12
|
+
const { token, url } = await resolveRequestTarget(resolved, unauthenticated, providedToken);
|
|
13
|
+
// Header names are case-insensitive - keyed lowercase so a user-provided
|
|
14
|
+
// header (eg `-H 'authorization: ...'`) replaces the default regardless of
|
|
15
|
+
// how either side is cased.
|
|
16
|
+
const requestHeaders = {};
|
|
17
|
+
if (token) requestHeaders.authorization = `Bearer ${token}`;
|
|
18
|
+
let requestBody;
|
|
19
|
+
if (typeof body === 'string' || Buffer.isBuffer(body)) {
|
|
20
|
+
// Raw bodies (--input) pass through without a default Content-Type - the
|
|
21
|
+
// caller knows the media type, we don't (gh api behaves the same way)
|
|
22
|
+
requestBody = body;
|
|
23
|
+
} else if (body !== undefined) {
|
|
24
|
+
requestBody = JSON.stringify(body);
|
|
25
|
+
requestHeaders['content-type'] = 'application/json';
|
|
26
|
+
}
|
|
27
|
+
for (const [key, value] of Object.entries(headers)){
|
|
28
|
+
requestHeaders[key.toLowerCase()] = value;
|
|
29
|
+
}
|
|
30
|
+
const request = createRequester({
|
|
31
|
+
middleware: {
|
|
32
|
+
httpErrors: false,
|
|
33
|
+
promise: {
|
|
34
|
+
onlyBody: false
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
const mergedQuery = {
|
|
39
|
+
...resolved.query,
|
|
40
|
+
...query
|
|
41
|
+
};
|
|
42
|
+
const response = await request({
|
|
43
|
+
...requestBody === undefined ? {} : {
|
|
44
|
+
body: requestBody
|
|
45
|
+
},
|
|
46
|
+
headers: requestHeaders,
|
|
47
|
+
method,
|
|
48
|
+
query: {
|
|
49
|
+
tag: API_REQUEST_TAG,
|
|
50
|
+
...mergedQuery
|
|
51
|
+
},
|
|
52
|
+
url
|
|
53
|
+
});
|
|
54
|
+
const rawBody = typeof response.body === 'string' ? response.body : String(response.body ?? '');
|
|
55
|
+
const parsed = parseBody(rawBody, response.headers['content-type']);
|
|
56
|
+
return {
|
|
57
|
+
body: parsed.body,
|
|
58
|
+
headers: response.headers,
|
|
59
|
+
jsonBody: parsed.jsonBody,
|
|
60
|
+
rawBody,
|
|
61
|
+
statusCode: response.statusCode,
|
|
62
|
+
statusMessage: response.statusMessage,
|
|
63
|
+
url: response.url
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
async function resolveRequestTarget(resolved, unauthenticated, providedToken) {
|
|
67
|
+
if (resolved.kind === 'url') {
|
|
68
|
+
const token = unauthenticated ? undefined : providedToken || await getCliToken();
|
|
69
|
+
if (!token && !unauthenticated) {
|
|
70
|
+
throw new Error('You must login first - run "sanity login"');
|
|
71
|
+
}
|
|
72
|
+
return {
|
|
73
|
+
token,
|
|
74
|
+
url: resolved.url
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
// The client factories handle token resolution, staging/production API
|
|
78
|
+
// hosts and the project subdomain - we only use them to build the URL.
|
|
79
|
+
const client = resolved.host === 'project' ? await getProjectCliClient({
|
|
80
|
+
apiVersion: resolved.apiVersion,
|
|
81
|
+
projectId: resolved.projectId,
|
|
82
|
+
requireUser: !unauthenticated,
|
|
83
|
+
token: providedToken
|
|
84
|
+
}) : await getGlobalCliClient({
|
|
85
|
+
apiVersion: resolved.apiVersion,
|
|
86
|
+
requireUser: !unauthenticated,
|
|
87
|
+
token: providedToken,
|
|
88
|
+
unauthenticated
|
|
89
|
+
});
|
|
90
|
+
const token = unauthenticated ? undefined : client.config().token ?? undefined;
|
|
91
|
+
return {
|
|
92
|
+
token,
|
|
93
|
+
url: client.getUrl(resolved.path)
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
function parseBody(rawBody, contentType) {
|
|
97
|
+
if (rawBody === '' || !contentType || !/\bjson\b/.test(contentType)) {
|
|
98
|
+
return {
|
|
99
|
+
body: rawBody,
|
|
100
|
+
jsonBody: false
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
try {
|
|
104
|
+
return {
|
|
105
|
+
body: JSON.parse(rawBody),
|
|
106
|
+
jsonBody: true
|
|
107
|
+
};
|
|
108
|
+
} catch {
|
|
109
|
+
return {
|
|
110
|
+
body: rawBody,
|
|
111
|
+
jsonBody: false
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
//# sourceMappingURL=api.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/services/api.ts"],"sourcesContent":["import {getCliToken, getGlobalCliClient, getProjectCliClient} from '@sanity/cli-core'\nimport {createRequester} from '@sanity/cli-core/request'\n\nimport {type ResolvedEndpoint} from '../actions/api/resolveEndpoint.js'\n\nconst API_REQUEST_TAG = 'sanity.cli.api'\n\n/**\n * Options for {@link performApiRequest}.\n */\nexport interface PerformApiRequestOptions {\n /** HTTP method (upper case). */\n method: string\n\n /** The resolved request target. */\n resolved: ResolvedEndpoint\n\n /** Request body: objects are JSON-serialized; strings and raw byte buffers are sent verbatim. */\n body?: Buffer | string | unknown\n\n /** Extra request headers. A user-provided `Authorization` header wins over the CLI token. */\n headers?: Record<string, string>\n\n /** Extra query parameters, merged with those from the endpoint argument. */\n query?: Record<string, string | string[]>\n\n /** Explicit API token, used instead of the logged-in user's token. */\n token?: string\n\n /** Send the request without an authorization token. */\n unauthenticated?: boolean\n}\n\n/**\n * The full HTTP response of an API request. Non-2xx responses are returned,\n * not thrown - the command decides how to surface them.\n */\nexport interface ApiResponse {\n /** Parsed JSON body for JSON responses, raw text otherwise. */\n body: unknown\n\n headers: Record<string, string>\n\n /** Whether `body` was parsed from a JSON response. */\n jsonBody: boolean\n\n /** The raw response body text. */\n rawBody: string\n\n statusCode: number\n\n url: string\n\n statusMessage?: string\n}\n\n/**\n * Perform an authenticated raw HTTP request against a Sanity API.\n *\n * URL construction and token resolution reuse the standard CLI client\n * factories; the request itself uses a bare requester so the response\n * (status, headers, non-JSON bodies) can be passed through unfiltered.\n */\nexport async function performApiRequest(options: PerformApiRequestOptions): Promise<ApiResponse> {\n const {\n body,\n headers = {},\n method,\n query = {},\n resolved,\n token: providedToken,\n unauthenticated = false,\n } = options\n\n const {token, url} = await resolveRequestTarget(resolved, unauthenticated, providedToken)\n\n // Header names are case-insensitive - keyed lowercase so a user-provided\n // header (eg `-H 'authorization: ...'`) replaces the default regardless of\n // how either side is cased.\n const requestHeaders: Record<string, string> = {}\n if (token) requestHeaders.authorization = `Bearer ${token}`\n\n let requestBody: Buffer | string | undefined\n if (typeof body === 'string' || Buffer.isBuffer(body)) {\n // Raw bodies (--input) pass through without a default Content-Type - the\n // caller knows the media type, we don't (gh api behaves the same way)\n requestBody = body\n } else if (body !== undefined) {\n requestBody = JSON.stringify(body)\n requestHeaders['content-type'] = 'application/json'\n }\n\n for (const [key, value] of Object.entries(headers)) {\n requestHeaders[key.toLowerCase()] = value\n }\n\n const request = createRequester({\n middleware: {httpErrors: false, promise: {onlyBody: false}},\n })\n\n const mergedQuery = {...resolved.query, ...query}\n\n const response = await request({\n ...(requestBody === undefined ? {} : {body: requestBody}),\n headers: requestHeaders,\n method,\n query: {tag: API_REQUEST_TAG, ...mergedQuery},\n url,\n })\n\n const rawBody = typeof response.body === 'string' ? response.body : String(response.body ?? '')\n const parsed = parseBody(rawBody, response.headers['content-type'])\n\n return {\n body: parsed.body,\n headers: response.headers,\n jsonBody: parsed.jsonBody,\n rawBody,\n statusCode: response.statusCode,\n statusMessage: response.statusMessage,\n url: response.url,\n }\n}\n\nasync function resolveRequestTarget(\n resolved: ResolvedEndpoint,\n unauthenticated: boolean,\n providedToken?: string,\n): Promise<{token?: string; url: string}> {\n if (resolved.kind === 'url') {\n const token = unauthenticated ? undefined : providedToken || (await getCliToken())\n if (!token && !unauthenticated) {\n throw new Error('You must login first - run \"sanity login\"')\n }\n return {token, url: resolved.url}\n }\n\n // The client factories handle token resolution, staging/production API\n // hosts and the project subdomain - we only use them to build the URL.\n const client =\n resolved.host === 'project'\n ? await getProjectCliClient({\n apiVersion: resolved.apiVersion,\n projectId: resolved.projectId as string,\n requireUser: !unauthenticated,\n token: providedToken,\n })\n : await getGlobalCliClient({\n apiVersion: resolved.apiVersion,\n requireUser: !unauthenticated,\n token: providedToken,\n unauthenticated,\n })\n\n const token = unauthenticated ? undefined : (client.config().token ?? undefined)\n\n return {token, url: client.getUrl(resolved.path)}\n}\n\nfunction parseBody(\n rawBody: string,\n contentType: string | undefined,\n): {body: unknown; jsonBody: boolean} {\n if (rawBody === '' || !contentType || !/\\bjson\\b/.test(contentType)) {\n return {body: rawBody, jsonBody: false}\n }\n try {\n return {body: JSON.parse(rawBody), jsonBody: true}\n } catch {\n return {body: rawBody, jsonBody: false}\n }\n}\n"],"names":["getCliToken","getGlobalCliClient","getProjectCliClient","createRequester","API_REQUEST_TAG","performApiRequest","options","body","headers","method","query","resolved","token","providedToken","unauthenticated","url","resolveRequestTarget","requestHeaders","authorization","requestBody","Buffer","isBuffer","undefined","JSON","stringify","key","value","Object","entries","toLowerCase","request","middleware","httpErrors","promise","onlyBody","mergedQuery","response","tag","rawBody","String","parsed","parseBody","jsonBody","statusCode","statusMessage","kind","Error","client","host","apiVersion","projectId","requireUser","config","getUrl","path","contentType","test","parse"],"mappings":"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"}
|