@sanity/client 8.3.0 → 8.5.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 +80 -4
- package/dist/{browserUpload-2tz6Sdqp.js → browserUpload-C7PwCs-C.js} +6 -9
- package/dist/browserUpload-C7PwCs-C.js.map +1 -0
- package/dist/{browserUpload-CwpNx7Vl.js → browserUpload-D-2Rmfjo.js} +6 -9
- package/dist/browserUpload-D-2Rmfjo.js.map +1 -0
- package/dist/{config-3wiPP-sZ.js → config-CgJ16jET.js} +4 -2
- package/dist/config-CgJ16jET.js.map +1 -0
- package/dist/csm.js +1 -1
- package/dist/{dist-C9ExSk2R.js → dist-C5K_YcEU.js} +3 -2
- package/dist/{dist-C9ExSk2R.js.map → dist-C5K_YcEU.js.map} +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1111 -80
- package/dist/index.js.map +1 -1
- package/dist/index.node.d.ts +3561 -53
- package/dist/index.node.js +983 -30
- package/dist/index.node.js.map +1 -1
- package/dist/media-library.d.ts +1 -1
- package/dist/rolldown-runtime-4YWMqDIC.js +9 -0
- package/dist/stega.js +2 -2
- package/dist/{dist-Z8cIRxoB.js → stegaClean-YZRATV86.js} +19 -2
- package/dist/stegaClean-YZRATV86.js.map +1 -0
- package/dist/{stegaEncodeSourceMap-DbM2fTN4.js → stegaEncodeSourceMap-CO1HKnm2.js} +2 -2
- package/dist/{stegaEncodeSourceMap-DbM2fTN4.js.map → stegaEncodeSourceMap-CO1HKnm2.js.map} +1 -1
- package/dist/{stegaEncodeSourceMap-YR3NQ3iz.js → stegaEncodeSourceMap-Dj29aWKG.js} +2 -2
- package/dist/{stegaEncodeSourceMap-YR3NQ3iz.js.map → stegaEncodeSourceMap-Dj29aWKG.js.map} +1 -1
- package/dist/{types-0x2hPfhJ.d.ts → types-CtHEe8SF.d.ts} +3562 -54
- package/package.json +18 -15
- package/src/SanityClient.ts +183 -9
- package/src/agent/actions/AgentActionsClient.ts +8 -2
- package/src/assets/AssetsClient.ts +13 -2
- package/src/config.ts +1 -0
- package/src/context/ContextClient.ts +1006 -0
- package/src/context/openapi.json +5345 -0
- package/src/context/reads.ts +206 -0
- package/src/context/store.ts +100 -0
- package/src/context/types.gen.ts +2428 -0
- package/src/context/types.ts +228 -0
- package/src/data/dataMethods.ts +4 -1
- package/src/data/live.ts +1 -0
- package/src/datasets/DatasetsClient.ts +8 -2
- package/src/defineCreateClient.ts +1 -0
- package/src/http/browserUpload.ts +0 -12
- package/src/mediaLibrary/MediaLibraryVideoClient.ts +8 -2
- package/src/projects/ProjectsClient.ts +8 -2
- package/src/releases/ReleasesClient.ts +8 -2
- package/src/types.ts +68 -4
- package/src/users/UsersClient.ts +8 -2
- package/src/validators.ts +1 -0
- package/dist/browserUpload-2tz6Sdqp.js.map +0 -1
- package/dist/browserUpload-CwpNx7Vl.js.map +0 -1
- package/dist/config-3wiPP-sZ.js.map +0 -1
- package/dist/dist-Z8cIRxoB.js.map +0 -1
- package/dist/stegaClean-C18wLWau.js +0 -21
- package/dist/stegaClean-C18wLWau.js.map +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sanity/client",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.5.0",
|
|
4
4
|
"description": "Client for retrieving, creating and patching data from Sanity.io",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"api",
|
|
@@ -49,38 +49,39 @@
|
|
|
49
49
|
"./package.json": "./package.json"
|
|
50
50
|
},
|
|
51
51
|
"dependencies": {
|
|
52
|
-
"eventsource": "^5.1.
|
|
53
|
-
"get-it": "^9.5.
|
|
52
|
+
"eventsource": "^5.1.1",
|
|
53
|
+
"get-it": "^9.5.2",
|
|
54
54
|
"obug": "^2.1.4",
|
|
55
55
|
"rxjs": "^7.8.2"
|
|
56
56
|
},
|
|
57
57
|
"devDependencies": {
|
|
58
58
|
"@changesets/cli": "^2.31.1",
|
|
59
|
-
"@cloudflare/vitest-pool-workers": "^0.
|
|
59
|
+
"@cloudflare/vitest-pool-workers": "^0.22.0",
|
|
60
60
|
"@edge-runtime/types": "^4.0.0",
|
|
61
61
|
"@edge-runtime/vm": "^5.0.0",
|
|
62
|
-
"@sanity/pkg-utils": "^12.
|
|
62
|
+
"@sanity/pkg-utils": "^12.3.3",
|
|
63
63
|
"@types/json-diff": "^1.0.3",
|
|
64
64
|
"@types/node": "^22.20.1",
|
|
65
65
|
"@types/react": "^19.2.18",
|
|
66
66
|
"@vercel/stega": "1.1.0",
|
|
67
|
-
"@vitest/browser": "^4.1.
|
|
68
|
-
"@vitest/browser-playwright": "^4.1.
|
|
69
|
-
"@vitest/coverage-v8": "^4.1.
|
|
67
|
+
"@vitest/browser": "^4.1.11",
|
|
68
|
+
"@vitest/browser-playwright": "^4.1.11",
|
|
69
|
+
"@vitest/coverage-v8": "^4.1.11",
|
|
70
70
|
"eventsource-encoder": "^1.0.2",
|
|
71
|
-
"happy-dom": "^20.11.
|
|
71
|
+
"happy-dom": "^20.11.12",
|
|
72
72
|
"json-diff": "^1.0.6",
|
|
73
|
-
"knip": "^6.32.
|
|
73
|
+
"knip": "^6.32.3",
|
|
74
74
|
"ls-engines": "^0.10.1",
|
|
75
|
-
"next": "^16.3.
|
|
76
|
-
"oxfmt": "^0.
|
|
77
|
-
"oxlint": "^1.
|
|
75
|
+
"next": "^16.3.3",
|
|
76
|
+
"oxfmt": "^0.65.0",
|
|
77
|
+
"oxlint": "^1.80.0",
|
|
78
78
|
"oxlint-tsgolint": "^7.0.2001",
|
|
79
79
|
"pkg-pr-new": "^0.0.88",
|
|
80
80
|
"playwright": "^1.62.1",
|
|
81
|
+
"rolldown": "^1.2.6",
|
|
81
82
|
"typescript": "7.0.2",
|
|
82
83
|
"undici": "^7.29.0",
|
|
83
|
-
"vitest": "^4.1.
|
|
84
|
+
"vitest": "^4.1.11"
|
|
84
85
|
},
|
|
85
86
|
"browserslist": "extends @sanity/browserslist-config",
|
|
86
87
|
"engines": {
|
|
@@ -92,6 +93,7 @@
|
|
|
92
93
|
"scripts": {
|
|
93
94
|
"build": "pkg build --strict && pkg --strict",
|
|
94
95
|
"coverage": "vitest run --coverage",
|
|
96
|
+
"docs:build": "pnpm --filter @sanity/client-docs exec typedoc --options ../../typedoc.json",
|
|
95
97
|
"lint": "oxlint",
|
|
96
98
|
"release": "changeset publish",
|
|
97
99
|
"test": "vitest",
|
|
@@ -113,6 +115,7 @@
|
|
|
113
115
|
"format": "oxfmt",
|
|
114
116
|
"format:check": "oxfmt --check",
|
|
115
117
|
"knip": "knip",
|
|
116
|
-
"typecheck": "tsc --noEmit"
|
|
118
|
+
"typecheck": "tsc --noEmit",
|
|
119
|
+
"generate:context": "node scripts/prune-context-spec.mjs src/context/openapi.json .tmp/context-openapi.pruned.json && pnpm --package=typescript@5.9.3 --package=openapi-typescript@7.13.0 dlx openapi-typescript .tmp/context-openapi.pruned.json -o src/context/types.gen.ts && oxfmt src/context/openapi.json src/context/types.gen.ts"
|
|
117
120
|
}
|
|
118
121
|
}
|
package/src/SanityClient.ts
CHANGED
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
ObservableCollaborationCommentsClient,
|
|
9
9
|
} from './collaboration/CollaborationCommentsClient'
|
|
10
10
|
import {defaultConfig, initConfig} from './config'
|
|
11
|
+
import {ContextClient, ObservableContextClient} from './context/ContextClient'
|
|
11
12
|
import * as dataMethods from './data/dataMethods'
|
|
12
13
|
import {_listen} from './data/listen'
|
|
13
14
|
import {LiveClient} from './data/live'
|
|
@@ -77,15 +78,52 @@ export type {
|
|
|
77
78
|
|
|
78
79
|
/** @public */
|
|
79
80
|
export class ObservableSanityClient {
|
|
81
|
+
/**
|
|
82
|
+
* Upload, fetch and delete assets (images and files) in the configured dataset
|
|
83
|
+
*
|
|
84
|
+
* @category Assets
|
|
85
|
+
*/
|
|
80
86
|
assets: ObservableAssetsClient
|
|
87
|
+
/**
|
|
88
|
+
* Create, list, edit and delete datasets in the configured project
|
|
89
|
+
*
|
|
90
|
+
* @category Projects & Datasets
|
|
91
|
+
*/
|
|
81
92
|
datasets: ObservableDatasetsClient
|
|
93
|
+
/**
|
|
94
|
+
* Subscribe to live content updates through the Live Content API
|
|
95
|
+
*
|
|
96
|
+
* @category Real-time
|
|
97
|
+
*/
|
|
82
98
|
live: LiveClient
|
|
99
|
+
/**
|
|
100
|
+
* Interact with Media Library assets
|
|
101
|
+
*
|
|
102
|
+
* @category Assets
|
|
103
|
+
*/
|
|
83
104
|
mediaLibrary: {
|
|
105
|
+
/** Upload and manage Media Library video assets */
|
|
84
106
|
video: ObservableMediaLibraryVideoClient
|
|
85
107
|
}
|
|
108
|
+
/**
|
|
109
|
+
* Fetch information about the projects the authenticated user has access to
|
|
110
|
+
*
|
|
111
|
+
* @category Projects & Datasets
|
|
112
|
+
*/
|
|
86
113
|
projects: ObservableProjectsClient
|
|
114
|
+
/**
|
|
115
|
+
* Fetch information about users in the configured project
|
|
116
|
+
*
|
|
117
|
+
* @category Projects & Datasets
|
|
118
|
+
*/
|
|
87
119
|
users: ObservableUsersClient
|
|
120
|
+
/**
|
|
121
|
+
* Run Agent Actions - AI-powered operations to generate, transform, translate, prompt and patch documents
|
|
122
|
+
*
|
|
123
|
+
* @category Agent Actions
|
|
124
|
+
*/
|
|
88
125
|
agent: {
|
|
126
|
+
/** Run individual Agent Action operations */
|
|
89
127
|
action: ObservableAgentsActionClient
|
|
90
128
|
}
|
|
91
129
|
collaboration: {
|
|
@@ -93,16 +131,22 @@ export class ObservableSanityClient {
|
|
|
93
131
|
comments: ObservableCollaborationCommentsClient
|
|
94
132
|
}
|
|
95
133
|
functions: ObservableFunctionsClient
|
|
96
|
-
releases: ObservableReleasesClient
|
|
97
|
-
|
|
98
134
|
/**
|
|
99
|
-
*
|
|
135
|
+
* Create and manage content releases and their scheduled publishing
|
|
136
|
+
*
|
|
137
|
+
* @category Releases
|
|
100
138
|
*/
|
|
139
|
+
releases: ObservableReleasesClient
|
|
140
|
+
/** @beta */
|
|
141
|
+
context: ObservableContextClient
|
|
142
|
+
|
|
101
143
|
#clientConfig: InitializedClientConfig
|
|
102
144
|
#httpRequest: HttpRequest
|
|
103
145
|
|
|
104
146
|
/**
|
|
105
|
-
*
|
|
147
|
+
* Listen to document changes matching a GROQ query, delivered as server-sent events
|
|
148
|
+
*
|
|
149
|
+
* @category Real-time
|
|
106
150
|
*/
|
|
107
151
|
listen = _listen
|
|
108
152
|
|
|
@@ -127,10 +171,13 @@ export class ObservableSanityClient {
|
|
|
127
171
|
}
|
|
128
172
|
this.functions = new ObservableFunctionsClient(this, this.#httpRequest)
|
|
129
173
|
this.releases = new ObservableReleasesClient(this, this.#httpRequest)
|
|
174
|
+
this.context = new ObservableContextClient(this, this.#httpRequest)
|
|
130
175
|
}
|
|
131
176
|
|
|
132
177
|
/**
|
|
133
178
|
* Clone the client - returns a new instance
|
|
179
|
+
*
|
|
180
|
+
* @category Configuration
|
|
134
181
|
*/
|
|
135
182
|
clone(): ObservableSanityClient {
|
|
136
183
|
return new ObservableSanityClient(this.#httpRequest, this.config())
|
|
@@ -138,6 +185,8 @@ export class ObservableSanityClient {
|
|
|
138
185
|
|
|
139
186
|
/**
|
|
140
187
|
* Returns the current client configuration
|
|
188
|
+
*
|
|
189
|
+
* @category Configuration
|
|
141
190
|
*/
|
|
142
191
|
config(): InitializedClientConfig
|
|
143
192
|
/**
|
|
@@ -162,6 +211,8 @@ export class ObservableSanityClient {
|
|
|
162
211
|
/**
|
|
163
212
|
* Clone the client with a new (partial) configuration.
|
|
164
213
|
*
|
|
214
|
+
* @category Configuration
|
|
215
|
+
*
|
|
165
216
|
* @param newConfig - New client configuration properties, shallowly merged with existing configuration
|
|
166
217
|
*/
|
|
167
218
|
withConfig(newConfig?: Partial<ClientConfig>): ObservableSanityClient {
|
|
@@ -181,6 +232,8 @@ export class ObservableSanityClient {
|
|
|
181
232
|
/**
|
|
182
233
|
* Perform a GROQ-query against the configured dataset.
|
|
183
234
|
*
|
|
235
|
+
* @category Querying
|
|
236
|
+
*
|
|
184
237
|
* @param query - GROQ-query to perform
|
|
185
238
|
*/
|
|
186
239
|
fetch<
|
|
@@ -254,6 +307,8 @@ export class ObservableSanityClient {
|
|
|
254
307
|
/**
|
|
255
308
|
* Fetch a single document with the given ID.
|
|
256
309
|
*
|
|
310
|
+
* @category Querying
|
|
311
|
+
*
|
|
257
312
|
* @param id - Document ID to fetch
|
|
258
313
|
* @param options - Request options
|
|
259
314
|
*/
|
|
@@ -313,6 +368,8 @@ export class ObservableSanityClient {
|
|
|
313
368
|
* The order/position of documents is preserved based on the original array of IDs.
|
|
314
369
|
* If any of the documents are missing, they will be replaced by a `null` entry in the returned array
|
|
315
370
|
*
|
|
371
|
+
* @category Querying
|
|
372
|
+
*
|
|
316
373
|
* @param ids - Document IDs to fetch
|
|
317
374
|
* @param options - Request options
|
|
318
375
|
*/
|
|
@@ -327,6 +384,8 @@ export class ObservableSanityClient {
|
|
|
327
384
|
* Convenient and bandwidth efficient method of checking wether a set of document IDs exists.
|
|
328
385
|
* Returns a set of the IDs that exist.
|
|
329
386
|
*
|
|
387
|
+
* @category Querying
|
|
388
|
+
*
|
|
330
389
|
* @param ids - Document IDs to check
|
|
331
390
|
* @param options - Request options
|
|
332
391
|
*/
|
|
@@ -341,6 +400,8 @@ export class ObservableSanityClient {
|
|
|
341
400
|
* Create a document. Requires a `_type` property. If no `_id` is provided, it will be generated by the database.
|
|
342
401
|
* Returns an observable that resolves to the created document.
|
|
343
402
|
*
|
|
403
|
+
* @category Mutations
|
|
404
|
+
*
|
|
344
405
|
* @param document - Document to create
|
|
345
406
|
* @param options - Mutation options
|
|
346
407
|
*/
|
|
@@ -410,6 +471,8 @@ export class ObservableSanityClient {
|
|
|
410
471
|
* Create a document if no document with the same ID already exists.
|
|
411
472
|
* Returns an observable that resolves to the created document.
|
|
412
473
|
*
|
|
474
|
+
* @category Mutations
|
|
475
|
+
*
|
|
413
476
|
* @param document - Document to create
|
|
414
477
|
* @param options - Mutation options
|
|
415
478
|
*/
|
|
@@ -479,6 +542,8 @@ export class ObservableSanityClient {
|
|
|
479
542
|
* Create a document if it does not exist, or replace a document with the same document ID
|
|
480
543
|
* Returns an observable that resolves to the created document.
|
|
481
544
|
*
|
|
545
|
+
* @category Mutations
|
|
546
|
+
*
|
|
482
547
|
* @param document - Document to either create or replace
|
|
483
548
|
* @param options - Mutation options
|
|
484
549
|
*/
|
|
@@ -687,6 +752,8 @@ export class ObservableSanityClient {
|
|
|
687
752
|
* Deletes a document with the given document ID.
|
|
688
753
|
* Returns an observable that resolves to the deleted document.
|
|
689
754
|
*
|
|
755
|
+
* @category Mutations
|
|
756
|
+
*
|
|
690
757
|
* @param id - Document ID to delete
|
|
691
758
|
* @param options - Options for the mutation
|
|
692
759
|
*/
|
|
@@ -807,6 +874,8 @@ export class ObservableSanityClient {
|
|
|
807
874
|
* * Discarding a version with no `releaseId` will discard the draft version of the published document.
|
|
808
875
|
* * If the draft or release version does not exist, any error will throw.
|
|
809
876
|
*
|
|
877
|
+
* @category Versions
|
|
878
|
+
*
|
|
810
879
|
* @param params - Version action parameters:
|
|
811
880
|
* - `releaseId` - The ID of the release to discard the document from.
|
|
812
881
|
* - `publishedId` - The published ID of the document to discard.
|
|
@@ -854,6 +923,8 @@ export class ObservableSanityClient {
|
|
|
854
923
|
* * Replacing a version with no `releaseId` will replace the draft version of the published document.
|
|
855
924
|
* * At least one of the **version** or **published** documents must exist.
|
|
856
925
|
*
|
|
926
|
+
* @category Versions
|
|
927
|
+
*
|
|
857
928
|
* @param params - Version action parameters:
|
|
858
929
|
* - `document` - The new document to replace the version with.
|
|
859
930
|
* - `releaseId` - The ID of the release where the document version is replaced.
|
|
@@ -960,6 +1031,8 @@ export class ObservableSanityClient {
|
|
|
960
1031
|
* @remarks
|
|
961
1032
|
* * If the published document does not exist, an error will be thrown.
|
|
962
1033
|
*
|
|
1034
|
+
* @category Versions
|
|
1035
|
+
*
|
|
963
1036
|
* @param params - Version action parameters:
|
|
964
1037
|
* - `releaseId` - The ID of the release to unpublish the document from.
|
|
965
1038
|
* - `publishedId` - The published ID of the document to unpublish.
|
|
@@ -991,6 +1064,8 @@ export class ObservableSanityClient {
|
|
|
991
1064
|
* Perform mutation operations against the configured dataset
|
|
992
1065
|
* Returns an observable that resolves to the first mutated document.
|
|
993
1066
|
*
|
|
1067
|
+
* @category Mutations
|
|
1068
|
+
*
|
|
994
1069
|
* @param operations - Mutation operations to execute
|
|
995
1070
|
* @param options - Mutation options
|
|
996
1071
|
*/
|
|
@@ -1059,6 +1134,8 @@ export class ObservableSanityClient {
|
|
|
1059
1134
|
/**
|
|
1060
1135
|
* Create a new buildable patch of operations to perform
|
|
1061
1136
|
*
|
|
1137
|
+
* @category Mutations
|
|
1138
|
+
*
|
|
1062
1139
|
* @param documentId - Document ID to patch
|
|
1063
1140
|
* @param operations - Optional object of patch operations to initialize the patch instance with
|
|
1064
1141
|
* @returns Patch instance - call `.commit()` to perform the operations defined
|
|
@@ -1097,6 +1174,8 @@ export class ObservableSanityClient {
|
|
|
1097
1174
|
/**
|
|
1098
1175
|
* Create a new transaction of mutations
|
|
1099
1176
|
*
|
|
1177
|
+
* @category Mutations
|
|
1178
|
+
*
|
|
1100
1179
|
* @param operations - Optional array of mutation operations to initialize the transaction instance with
|
|
1101
1180
|
*/
|
|
1102
1181
|
transaction<R extends Record<string, Any> = Record<string, Any>>(
|
|
@@ -1108,6 +1187,8 @@ export class ObservableSanityClient {
|
|
|
1108
1187
|
/**
|
|
1109
1188
|
* Perform action operations against the configured dataset
|
|
1110
1189
|
*
|
|
1190
|
+
* @category Mutations
|
|
1191
|
+
*
|
|
1111
1192
|
* @param operations - Action operation(s) to execute
|
|
1112
1193
|
* @param options - Action options
|
|
1113
1194
|
*/
|
|
@@ -1121,6 +1202,8 @@ export class ObservableSanityClient {
|
|
|
1121
1202
|
/**
|
|
1122
1203
|
* Perform an HTTP request against the Sanity API
|
|
1123
1204
|
*
|
|
1205
|
+
* @category HTTP
|
|
1206
|
+
*
|
|
1124
1207
|
* @param options - Request options
|
|
1125
1208
|
*/
|
|
1126
1209
|
request<R = Any>(options: RawRequestOptions): Observable<R> {
|
|
@@ -1130,6 +1213,8 @@ export class ObservableSanityClient {
|
|
|
1130
1213
|
/**
|
|
1131
1214
|
* Get a Sanity API URL for the URI provided
|
|
1132
1215
|
*
|
|
1216
|
+
* @category HTTP
|
|
1217
|
+
*
|
|
1133
1218
|
* @param uri - URI/path to build URL for
|
|
1134
1219
|
* @param canUseCdn - Whether or not to allow using the API CDN for this route
|
|
1135
1220
|
*/
|
|
@@ -1140,6 +1225,8 @@ export class ObservableSanityClient {
|
|
|
1140
1225
|
/**
|
|
1141
1226
|
* Get a Sanity API URL for the data operation and path provided
|
|
1142
1227
|
*
|
|
1228
|
+
* @category HTTP
|
|
1229
|
+
*
|
|
1143
1230
|
* @param operation - Data operation (eg `query`, `mutate`, `listen` or similar)
|
|
1144
1231
|
* @param path - Path to append after the operation
|
|
1145
1232
|
*/
|
|
@@ -1150,15 +1237,52 @@ export class ObservableSanityClient {
|
|
|
1150
1237
|
|
|
1151
1238
|
/** @public */
|
|
1152
1239
|
export class SanityClient {
|
|
1240
|
+
/**
|
|
1241
|
+
* Upload, fetch and delete assets (images and files) in the configured dataset
|
|
1242
|
+
*
|
|
1243
|
+
* @category Assets
|
|
1244
|
+
*/
|
|
1153
1245
|
assets: AssetsClient
|
|
1246
|
+
/**
|
|
1247
|
+
* Create, list, edit and delete datasets in the configured project
|
|
1248
|
+
*
|
|
1249
|
+
* @category Projects & Datasets
|
|
1250
|
+
*/
|
|
1154
1251
|
datasets: DatasetsClient
|
|
1252
|
+
/**
|
|
1253
|
+
* Subscribe to live content updates through the Live Content API
|
|
1254
|
+
*
|
|
1255
|
+
* @category Real-time
|
|
1256
|
+
*/
|
|
1155
1257
|
live: LiveClient
|
|
1258
|
+
/**
|
|
1259
|
+
* Interact with Media Library assets
|
|
1260
|
+
*
|
|
1261
|
+
* @category Assets
|
|
1262
|
+
*/
|
|
1156
1263
|
mediaLibrary: {
|
|
1264
|
+
/** Upload and manage Media Library video assets */
|
|
1157
1265
|
video: MediaLibraryVideoClient
|
|
1158
1266
|
}
|
|
1267
|
+
/**
|
|
1268
|
+
* Fetch information about the projects the authenticated user has access to
|
|
1269
|
+
*
|
|
1270
|
+
* @category Projects & Datasets
|
|
1271
|
+
*/
|
|
1159
1272
|
projects: ProjectsClient
|
|
1273
|
+
/**
|
|
1274
|
+
* Fetch information about users in the configured project
|
|
1275
|
+
*
|
|
1276
|
+
* @category Projects & Datasets
|
|
1277
|
+
*/
|
|
1160
1278
|
users: UsersClient
|
|
1279
|
+
/**
|
|
1280
|
+
* Run Agent Actions - AI-powered operations to generate, transform, translate, prompt and patch documents
|
|
1281
|
+
*
|
|
1282
|
+
* @category Agent Actions
|
|
1283
|
+
*/
|
|
1161
1284
|
agent: {
|
|
1285
|
+
/** Run individual Agent Action operations */
|
|
1162
1286
|
action: AgentActionsClient
|
|
1163
1287
|
}
|
|
1164
1288
|
collaboration: {
|
|
@@ -1166,21 +1290,29 @@ export class SanityClient {
|
|
|
1166
1290
|
comments: CollaborationCommentsClient
|
|
1167
1291
|
}
|
|
1168
1292
|
functions: FunctionsClient
|
|
1293
|
+
/**
|
|
1294
|
+
* Create and manage content releases and their scheduled publishing
|
|
1295
|
+
*
|
|
1296
|
+
* @category Releases
|
|
1297
|
+
*/
|
|
1169
1298
|
releases: ReleasesClient
|
|
1299
|
+
/** @beta */
|
|
1300
|
+
context: ContextClient
|
|
1170
1301
|
|
|
1171
1302
|
/**
|
|
1172
1303
|
* Observable version of the Sanity client, with the same configuration as the promise-based one
|
|
1304
|
+
*
|
|
1305
|
+
* @category Configuration
|
|
1173
1306
|
*/
|
|
1174
1307
|
observable: ObservableSanityClient
|
|
1175
1308
|
|
|
1176
|
-
/**
|
|
1177
|
-
* Private properties
|
|
1178
|
-
*/
|
|
1179
1309
|
#clientConfig: InitializedClientConfig
|
|
1180
1310
|
#httpRequest: HttpRequest
|
|
1181
1311
|
|
|
1182
1312
|
/**
|
|
1183
|
-
*
|
|
1313
|
+
* Listen to document changes matching a GROQ query, delivered as server-sent events
|
|
1314
|
+
*
|
|
1315
|
+
* @category Real-time
|
|
1184
1316
|
*/
|
|
1185
1317
|
listen = _listen
|
|
1186
1318
|
|
|
@@ -1205,12 +1337,15 @@ export class SanityClient {
|
|
|
1205
1337
|
}
|
|
1206
1338
|
this.functions = new FunctionsClient(this, this.#httpRequest)
|
|
1207
1339
|
this.releases = new ReleasesClient(this, this.#httpRequest)
|
|
1340
|
+
this.context = new ContextClient(this, this.#httpRequest)
|
|
1208
1341
|
|
|
1209
1342
|
this.observable = new ObservableSanityClient(httpRequest, config)
|
|
1210
1343
|
}
|
|
1211
1344
|
|
|
1212
1345
|
/**
|
|
1213
1346
|
* Clone the client - returns a new instance
|
|
1347
|
+
*
|
|
1348
|
+
* @category Configuration
|
|
1214
1349
|
*/
|
|
1215
1350
|
clone(): SanityClient {
|
|
1216
1351
|
return new SanityClient(this.#httpRequest, this.config())
|
|
@@ -1218,6 +1353,8 @@ export class SanityClient {
|
|
|
1218
1353
|
|
|
1219
1354
|
/**
|
|
1220
1355
|
* Returns the current client configuration
|
|
1356
|
+
*
|
|
1357
|
+
* @category Configuration
|
|
1221
1358
|
*/
|
|
1222
1359
|
config(): InitializedClientConfig
|
|
1223
1360
|
/**
|
|
@@ -1246,6 +1383,8 @@ export class SanityClient {
|
|
|
1246
1383
|
/**
|
|
1247
1384
|
* Clone the client with a new (partial) configuration.
|
|
1248
1385
|
*
|
|
1386
|
+
* @category Configuration
|
|
1387
|
+
*
|
|
1249
1388
|
* @param newConfig - New client configuration properties, shallowly merged with existing configuration
|
|
1250
1389
|
*/
|
|
1251
1390
|
withConfig(newConfig?: Partial<ClientConfig>): SanityClient {
|
|
@@ -1265,6 +1404,8 @@ export class SanityClient {
|
|
|
1265
1404
|
/**
|
|
1266
1405
|
* Perform a GROQ-query against the configured dataset.
|
|
1267
1406
|
*
|
|
1407
|
+
* @category Querying
|
|
1408
|
+
*
|
|
1268
1409
|
* @param query - GROQ-query to perform
|
|
1269
1410
|
*/
|
|
1270
1411
|
fetch<
|
|
@@ -1338,6 +1479,8 @@ export class SanityClient {
|
|
|
1338
1479
|
/**
|
|
1339
1480
|
* Fetch a single document with the given ID.
|
|
1340
1481
|
*
|
|
1482
|
+
* @category Querying
|
|
1483
|
+
*
|
|
1341
1484
|
* @param id - Document ID to fetch
|
|
1342
1485
|
* @param options - Request options
|
|
1343
1486
|
*/
|
|
@@ -1397,6 +1540,8 @@ export class SanityClient {
|
|
|
1397
1540
|
* The order/position of documents is preserved based on the original array of IDs.
|
|
1398
1541
|
* If any of the documents are missing, they will be replaced by a `null` entry in the returned array
|
|
1399
1542
|
*
|
|
1543
|
+
* @category Querying
|
|
1544
|
+
*
|
|
1400
1545
|
* @param ids - Document IDs to fetch
|
|
1401
1546
|
* @param options - Request options
|
|
1402
1547
|
*/
|
|
@@ -1411,6 +1556,8 @@ export class SanityClient {
|
|
|
1411
1556
|
* Convenient and bandwidth efficient method of checking wether a set of document IDs exists.
|
|
1412
1557
|
* Returns a set of the IDs that exist.
|
|
1413
1558
|
*
|
|
1559
|
+
* @category Querying
|
|
1560
|
+
*
|
|
1414
1561
|
* @param ids - Document IDs to check
|
|
1415
1562
|
* @param options - Request options
|
|
1416
1563
|
*/
|
|
@@ -1425,6 +1572,8 @@ export class SanityClient {
|
|
|
1425
1572
|
* Create a document. Requires a `_type` property. If no `_id` is provided, it will be generated by the database.
|
|
1426
1573
|
* Returns a promise that resolves to the created document.
|
|
1427
1574
|
*
|
|
1575
|
+
* @category Mutations
|
|
1576
|
+
*
|
|
1428
1577
|
* @param document - Document to create
|
|
1429
1578
|
* @param options - Mutation options
|
|
1430
1579
|
*/
|
|
@@ -1494,6 +1643,8 @@ export class SanityClient {
|
|
|
1494
1643
|
* Create a document if no document with the same ID already exists.
|
|
1495
1644
|
* Returns a promise that resolves to the created document.
|
|
1496
1645
|
*
|
|
1646
|
+
* @category Mutations
|
|
1647
|
+
*
|
|
1497
1648
|
* @param document - Document to create
|
|
1498
1649
|
* @param options - Mutation options
|
|
1499
1650
|
*/
|
|
@@ -1563,6 +1714,8 @@ export class SanityClient {
|
|
|
1563
1714
|
* Create a document if it does not exist, or replace a document with the same document ID
|
|
1564
1715
|
* Returns a promise that resolves to the created document.
|
|
1565
1716
|
*
|
|
1717
|
+
* @category Mutations
|
|
1718
|
+
*
|
|
1566
1719
|
* @param document - Document to either create or replace
|
|
1567
1720
|
* @param options - Mutation options
|
|
1568
1721
|
*/
|
|
@@ -1759,6 +1912,8 @@ export class SanityClient {
|
|
|
1759
1912
|
* Deletes a document with the given document ID.
|
|
1760
1913
|
* Returns a promise that resolves to the deleted document.
|
|
1761
1914
|
*
|
|
1915
|
+
* @category Mutations
|
|
1916
|
+
*
|
|
1762
1917
|
* @param id - Document ID to delete
|
|
1763
1918
|
* @param options - Options for the mutation
|
|
1764
1919
|
*/
|
|
@@ -1879,6 +2034,8 @@ export class SanityClient {
|
|
|
1879
2034
|
* * Discarding a version with no `releaseId` will discard the draft version of the published document.
|
|
1880
2035
|
* * If the draft or release version does not exist, any error will throw.
|
|
1881
2036
|
*
|
|
2037
|
+
* @category Versions
|
|
2038
|
+
*
|
|
1882
2039
|
* @param params - Version action parameters:
|
|
1883
2040
|
* - `releaseId` - The ID of the release to discard the document from.
|
|
1884
2041
|
* - `publishedId` - The published ID of the document to discard.
|
|
@@ -1920,6 +2077,8 @@ export class SanityClient {
|
|
|
1920
2077
|
* * Replacing a version with no `releaseId` will replace the draft version of the published document.
|
|
1921
2078
|
* * At least one of the **version** or **published** documents must exist.
|
|
1922
2079
|
*
|
|
2080
|
+
* @category Versions
|
|
2081
|
+
*
|
|
1923
2082
|
* @param params - Version action parameters:
|
|
1924
2083
|
* - `document` - The new document to replace the version with.
|
|
1925
2084
|
* - `releaseId` - The ID of the release where the document version is replaced.
|
|
@@ -1973,7 +2132,6 @@ export class SanityClient {
|
|
|
1973
2132
|
* // }
|
|
1974
2133
|
* ```
|
|
1975
2134
|
*/
|
|
1976
|
-
|
|
1977
2135
|
replaceVersion<R extends Record<string, Any>>(
|
|
1978
2136
|
args: {
|
|
1979
2137
|
document: SanityDocumentStub<R>
|
|
@@ -2022,6 +2180,8 @@ export class SanityClient {
|
|
|
2022
2180
|
* @remarks
|
|
2023
2181
|
* * If the published document does not exist, an error will be thrown.
|
|
2024
2182
|
*
|
|
2183
|
+
* @category Versions
|
|
2184
|
+
*
|
|
2025
2185
|
* @param params - Version action parameters:
|
|
2026
2186
|
* - `releaseId` - The ID of the release to unpublish the document from.
|
|
2027
2187
|
* - `publishedId` - The published ID of the document to unpublish.
|
|
@@ -2047,6 +2207,8 @@ export class SanityClient {
|
|
|
2047
2207
|
* Perform mutation operations against the configured dataset
|
|
2048
2208
|
* Returns a promise that resolves to the first mutated document.
|
|
2049
2209
|
*
|
|
2210
|
+
* @category Mutations
|
|
2211
|
+
*
|
|
2050
2212
|
* @param operations - Mutation operations to execute
|
|
2051
2213
|
* @param options - Mutation options
|
|
2052
2214
|
*/
|
|
@@ -2115,6 +2277,8 @@ export class SanityClient {
|
|
|
2115
2277
|
/**
|
|
2116
2278
|
* Create a new buildable patch of operations to perform
|
|
2117
2279
|
*
|
|
2280
|
+
* @category Mutations
|
|
2281
|
+
*
|
|
2118
2282
|
* @param documentId - Document ID to patch
|
|
2119
2283
|
* @param operations - Optional object of patch operations to initialize the patch instance with
|
|
2120
2284
|
* @returns Patch instance - call `.commit()` to perform the operations defined
|
|
@@ -2153,6 +2317,8 @@ export class SanityClient {
|
|
|
2153
2317
|
/**
|
|
2154
2318
|
* Create a new transaction of mutations
|
|
2155
2319
|
*
|
|
2320
|
+
* @category Mutations
|
|
2321
|
+
*
|
|
2156
2322
|
* @param operations - Optional array of mutation operations to initialize the transaction instance with
|
|
2157
2323
|
*/
|
|
2158
2324
|
transaction<R extends Record<string, Any> = Record<string, Any>>(
|
|
@@ -2165,6 +2331,8 @@ export class SanityClient {
|
|
|
2165
2331
|
* Perform action operations against the configured dataset
|
|
2166
2332
|
* Returns a promise that resolves to the transaction result
|
|
2167
2333
|
*
|
|
2334
|
+
* @category Mutations
|
|
2335
|
+
*
|
|
2168
2336
|
* @param operations - Action operation(s) to execute
|
|
2169
2337
|
* @param options - Action options
|
|
2170
2338
|
*/
|
|
@@ -2179,6 +2347,8 @@ export class SanityClient {
|
|
|
2179
2347
|
* Perform a request against the Sanity API
|
|
2180
2348
|
* NOTE: Only use this for Sanity API endpoints, not for your own APIs!
|
|
2181
2349
|
*
|
|
2350
|
+
* @category HTTP
|
|
2351
|
+
*
|
|
2182
2352
|
* @param options - Request options
|
|
2183
2353
|
* @returns Promise resolving to the response body
|
|
2184
2354
|
*/
|
|
@@ -2203,6 +2373,8 @@ export class SanityClient {
|
|
|
2203
2373
|
/**
|
|
2204
2374
|
* Get a Sanity API URL for the URI provided
|
|
2205
2375
|
*
|
|
2376
|
+
* @category HTTP
|
|
2377
|
+
*
|
|
2206
2378
|
* @param uri - URI/path to build URL for
|
|
2207
2379
|
* @param canUseCdn - Whether or not to allow using the API CDN for this route
|
|
2208
2380
|
*/
|
|
@@ -2213,6 +2385,8 @@ export class SanityClient {
|
|
|
2213
2385
|
/**
|
|
2214
2386
|
* Get a Sanity API URL for the data operation and path provided
|
|
2215
2387
|
*
|
|
2388
|
+
* @category HTTP
|
|
2389
|
+
*
|
|
2216
2390
|
* @param operation - Data operation (eg `query`, `mutate`, `listen` or similar)
|
|
2217
2391
|
* @param path - Path to append after the operation
|
|
2218
2392
|
*/
|
|
@@ -8,7 +8,10 @@ import {_prompt, type PromptRequest} from './prompt'
|
|
|
8
8
|
import {_transform, _transformObservable, type TransformDocument} from './transform'
|
|
9
9
|
import {_translate, _translateObservable, type TranslateDocument} from './translate'
|
|
10
10
|
|
|
11
|
-
/**
|
|
11
|
+
/**
|
|
12
|
+
* @public
|
|
13
|
+
* @inline
|
|
14
|
+
*/
|
|
12
15
|
export class ObservableAgentsActionClient {
|
|
13
16
|
#client: ObservableSanityClient
|
|
14
17
|
#httpRequest: HttpRequest
|
|
@@ -60,7 +63,10 @@ export class ObservableAgentsActionClient {
|
|
|
60
63
|
}
|
|
61
64
|
}
|
|
62
65
|
|
|
63
|
-
/**
|
|
66
|
+
/**
|
|
67
|
+
* @public
|
|
68
|
+
* @inline
|
|
69
|
+
*/
|
|
64
70
|
export class AgentActionsClient {
|
|
65
71
|
#client: SanityClient
|
|
66
72
|
#httpRequest: HttpRequest
|
|
@@ -18,7 +18,10 @@ import type {
|
|
|
18
18
|
} from '../types'
|
|
19
19
|
import * as validators from '../validators'
|
|
20
20
|
|
|
21
|
-
/**
|
|
21
|
+
/**
|
|
22
|
+
* @internal
|
|
23
|
+
* @inline
|
|
24
|
+
*/
|
|
22
25
|
export class ObservableAssetsClient {
|
|
23
26
|
#client: ObservableSanityClient
|
|
24
27
|
#httpRequest: HttpRequest
|
|
@@ -78,7 +81,10 @@ export class ObservableAssetsClient {
|
|
|
78
81
|
}
|
|
79
82
|
}
|
|
80
83
|
|
|
81
|
-
/**
|
|
84
|
+
/**
|
|
85
|
+
* @internal
|
|
86
|
+
* @inline
|
|
87
|
+
*/
|
|
82
88
|
export class AssetsClient {
|
|
83
89
|
#client: SanityClient
|
|
84
90
|
#httpRequest: HttpRequest
|
|
@@ -303,6 +309,11 @@ function buildAssetUploadUrl(config: InitializedClientConfig, assetType: 'image'
|
|
|
303
309
|
case 'canvas': {
|
|
304
310
|
return `/canvases/${id}/assets/${assetTypeEndpoint}`
|
|
305
311
|
}
|
|
312
|
+
case 'knowledge-base': {
|
|
313
|
+
throw new Error(
|
|
314
|
+
'Assets are not supported for knowledge-base resources. Use `client.context.imports` to add content instead.',
|
|
315
|
+
)
|
|
316
|
+
}
|
|
306
317
|
case 'media-library': {
|
|
307
318
|
return `/media-libraries/${id}/upload`
|
|
308
319
|
}
|
package/src/config.ts
CHANGED
|
@@ -62,6 +62,7 @@ export const initConfig = (
|
|
|
62
62
|
const newConfig = {
|
|
63
63
|
...defaultConfig,
|
|
64
64
|
...specifiedConfig,
|
|
65
|
+
apiHost: specifiedConfig.apiHost ?? defaultConfig.apiHost,
|
|
65
66
|
} as InitializedClientConfig
|
|
66
67
|
|
|
67
68
|
// Normalize resource configuration - prefer `resource` over deprecated `~experimental_resource`
|