@sanity/client 8.2.0 → 8.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/README.md +2 -2
  2. package/dist/{browserUpload-2tz6Sdqp.js → browserUpload-C7PwCs-C.js} +6 -9
  3. package/dist/browserUpload-C7PwCs-C.js.map +1 -0
  4. package/dist/{browserUpload-CwpNx7Vl.js → browserUpload-D-2Rmfjo.js} +6 -9
  5. package/dist/browserUpload-D-2Rmfjo.js.map +1 -0
  6. package/dist/{config-3wiPP-sZ.js → config-CgJ16jET.js} +4 -2
  7. package/dist/config-CgJ16jET.js.map +1 -0
  8. package/dist/csm.js +1 -1
  9. package/dist/{dist-C9ExSk2R.js → dist-C5K_YcEU.js} +3 -2
  10. package/dist/{dist-C9ExSk2R.js.map → dist-C5K_YcEU.js.map} +1 -1
  11. package/dist/index.d.ts +2 -2
  12. package/dist/index.js +942 -115
  13. package/dist/index.js.map +1 -1
  14. package/dist/index.node.d.ts +3345 -16
  15. package/dist/index.node.js +865 -59
  16. package/dist/index.node.js.map +1 -1
  17. package/dist/media-library.d.ts +1 -1
  18. package/dist/rolldown-runtime-4YWMqDIC.js +9 -0
  19. package/dist/{stegaEncodeSourceMap-DbM2fTN4.js → stegaEncodeSourceMap-CO1HKnm2.js} +2 -2
  20. package/dist/{stegaEncodeSourceMap-DbM2fTN4.js.map → stegaEncodeSourceMap-CO1HKnm2.js.map} +1 -1
  21. package/dist/{types-nJhm5Nyq.d.ts → types-DiPF0ENT.d.ts} +3346 -17
  22. package/package.json +3 -3
  23. package/src/SanityClient.ts +7 -0
  24. package/src/assets/AssetsClient.ts +5 -0
  25. package/src/collaboration/types.ts +59 -8
  26. package/src/config.ts +1 -0
  27. package/src/context/ContextClient.ts +1006 -0
  28. package/src/context/openapi.json +5345 -0
  29. package/src/context/reads.ts +206 -0
  30. package/src/context/store.ts +100 -0
  31. package/src/context/types.gen.ts +2428 -0
  32. package/src/context/types.ts +228 -0
  33. package/src/data/dataMethods.ts +4 -1
  34. package/src/defineCreateClient.ts +1 -0
  35. package/src/functions/FunctionsClient.ts +52 -9
  36. package/src/functions/invoke.ts +47 -6
  37. package/src/http/browserUpload.ts +0 -12
  38. package/src/types.ts +29 -3
  39. package/src/util/createVersionId.ts +15 -5
  40. package/src/validators.ts +1 -0
  41. package/dist/browserUpload-2tz6Sdqp.js.map +0 -1
  42. package/dist/browserUpload-CwpNx7Vl.js.map +0 -1
  43. package/dist/config-3wiPP-sZ.js.map +0 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sanity/client",
3
- "version": "8.2.0",
3
+ "version": "8.4.0",
4
4
  "description": "Client for retrieving, creating and patching data from Sanity.io",
5
5
  "keywords": [
6
6
  "api",
@@ -51,7 +51,6 @@
51
51
  "dependencies": {
52
52
  "eventsource": "^5.1.0",
53
53
  "get-it": "^9.5.0",
54
- "nanoid": "^6.0.1",
55
54
  "obug": "^2.1.4",
56
55
  "rxjs": "^7.8.2"
57
56
  },
@@ -114,6 +113,7 @@
114
113
  "format": "oxfmt",
115
114
  "format:check": "oxfmt --check",
116
115
  "knip": "knip",
117
- "typecheck": "tsc --noEmit"
116
+ "typecheck": "tsc --noEmit",
117
+ "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"
118
118
  }
119
119
  }
@@ -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'
@@ -94,6 +95,8 @@ export class ObservableSanityClient {
94
95
  }
95
96
  functions: ObservableFunctionsClient
96
97
  releases: ObservableReleasesClient
98
+ /** @beta */
99
+ context: ObservableContextClient
97
100
 
98
101
  /**
99
102
  * Private properties
@@ -127,6 +130,7 @@ export class ObservableSanityClient {
127
130
  }
128
131
  this.functions = new ObservableFunctionsClient(this, this.#httpRequest)
129
132
  this.releases = new ObservableReleasesClient(this, this.#httpRequest)
133
+ this.context = new ObservableContextClient(this, this.#httpRequest)
130
134
  }
131
135
 
132
136
  /**
@@ -1167,6 +1171,8 @@ export class SanityClient {
1167
1171
  }
1168
1172
  functions: FunctionsClient
1169
1173
  releases: ReleasesClient
1174
+ /** @beta */
1175
+ context: ContextClient
1170
1176
 
1171
1177
  /**
1172
1178
  * Observable version of the Sanity client, with the same configuration as the promise-based one
@@ -1205,6 +1211,7 @@ export class SanityClient {
1205
1211
  }
1206
1212
  this.functions = new FunctionsClient(this, this.#httpRequest)
1207
1213
  this.releases = new ReleasesClient(this, this.#httpRequest)
1214
+ this.context = new ContextClient(this, this.#httpRequest)
1208
1215
 
1209
1216
  this.observable = new ObservableSanityClient(httpRequest, config)
1210
1217
  }
@@ -303,6 +303,11 @@ function buildAssetUploadUrl(config: InitializedClientConfig, assetType: 'image'
303
303
  case 'canvas': {
304
304
  return `/canvases/${id}/assets/${assetTypeEndpoint}`
305
305
  }
306
+ case 'knowledge-base': {
307
+ throw new Error(
308
+ 'Assets are not supported for knowledge-base resources. Use `client.context.imports` to add content instead.',
309
+ )
310
+ }
306
311
  case 'media-library': {
307
312
  return `/media-libraries/${id}/upload`
308
313
  }
@@ -161,6 +161,18 @@ export interface CollaborationCommentRange {
161
161
  end: {_key: string; offset: number}
162
162
  }
163
163
 
164
+ /**
165
+ * Portable Text covering a comment `range`. Callers can send just the blocks
166
+ * from the `range` start `_key` through end `_key`, or the full field.
167
+ *
168
+ * @alpha
169
+ */
170
+ export type CollaborationCommentFieldValue = Array<{
171
+ _type: string
172
+ _key: string
173
+ [key: string]: Any
174
+ }>
175
+
164
176
  /**
165
177
  * Target for a top-level comment. Inline selections require both `path` and
166
178
  * `range`; field-level comments may set `path` alone.
@@ -169,6 +181,9 @@ export interface CollaborationCommentRange {
169
181
  * `target.path.field`, and `range` is resolved against the document into
170
182
  * `target.path.selection` and `contentSnapshot` rather than being stored.
171
183
  *
184
+ * An optional `fieldValue` is Portable Text covering the `range`. When set,
185
+ * the `range` is resolved from those blocks instead of from the live document.
186
+ *
172
187
  * @alpha
173
188
  */
174
189
  export type CollaborationCommentTarget = {
@@ -180,11 +195,17 @@ export type CollaborationCommentTarget = {
180
195
  /** Path to the field containing the inline comment selection */
181
196
  path: string
182
197
  range: CollaborationCommentRange
198
+ /**
199
+ * Portable Text covering the `range`. When set, the `range` is resolved
200
+ * from these blocks instead of from the live document.
201
+ */
202
+ fieldValue?: CollaborationCommentFieldValue
183
203
  }
184
204
  | {
185
205
  /** Path to the commented field */
186
206
  path?: string
187
207
  range?: never
208
+ fieldValue?: never
188
209
  }
189
210
  )
190
211
 
@@ -205,6 +226,19 @@ export type CollaborationCommentTarget = {
205
226
  * })
206
227
  * ```
207
228
  *
229
+ * #### Inline comment
230
+ * ```ts
231
+ * await client.collaboration.comments.create({
232
+ * message,
233
+ * target: {
234
+ * documentId: 'doc-1',
235
+ * documentType: 'article',
236
+ * path: 'body',
237
+ * range: {start: {_key: 'block-1', offset: 0}, end: {_key: 'block-1', offset: 5}},
238
+ * },
239
+ * })
240
+ * ```
241
+ *
208
242
  * #### Reply
209
243
  * ```ts
210
244
  * await client.collaboration.comments.create({
@@ -236,17 +270,34 @@ export type CollaborationCommentCreate = {
236
270
  /**
237
271
  * Fields that can be updated on an existing comment.
238
272
  *
273
+ * A `range` re-anchors the comment within the field it already targets.
274
+ * Pass `null` to remove the selection and leave a field-level comment.
275
+ * An optional `fieldValue` is Portable Text covering that `range`; when set,
276
+ * the `range` is resolved from those blocks instead of from the live document.
277
+ * `fieldValue` cannot be sent alone or together with `range: null`.
278
+ *
239
279
  * @alpha
240
280
  */
241
- export interface CollaborationCommentUpdate {
281
+ export type CollaborationCommentUpdate = {
242
282
  /** Replaces the current message */
243
283
  message?: CollaborationCommentMessage
244
284
  /** Cascades to the comment's replies */
245
285
  status?: CollaborationCommentStatus
246
- /**
247
- * Re-anchors the comment within the field and source document it already
248
- * targets. Pass `null` to remove the selection and leave a field-level
249
- * comment.
250
- */
251
- range?: CollaborationCommentRange | null
252
- }
286
+ } & (
287
+ | {
288
+ range: CollaborationCommentRange
289
+ /**
290
+ * Portable Text covering the `range`. When set, the `range` is resolved
291
+ * from these blocks instead of from the live document.
292
+ */
293
+ fieldValue?: CollaborationCommentFieldValue
294
+ }
295
+ | {
296
+ range: null
297
+ fieldValue?: never
298
+ }
299
+ | {
300
+ range?: undefined
301
+ fieldValue?: never
302
+ }
303
+ )
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`