@sanity/client 7.0.1-canary.2 → 7.1.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.
@@ -17,91 +17,7 @@ import type {
17
17
  import * as validators from '../validators'
18
18
 
19
19
  /** @internal */
20
- export interface ObservableAssetsClientType {
21
- /**
22
- * Uploads a file asset to the configured dataset
23
- *
24
- * @param assetType - Asset type (file)
25
- * @param body - Asset content - can be a browser File instance, a Blob, a Node.js Buffer instance or a Node.js ReadableStream.
26
- * @param options - Options to use for the upload
27
- */
28
- upload(
29
- assetType: 'file',
30
- body: UploadBody,
31
- options?: UploadClientConfig,
32
- ): Observable<HttpRequestEvent<{document: SanityAssetDocument}>>
33
-
34
- /**
35
- * Uploads an image asset to the configured dataset
36
- *
37
- * @param assetType - Asset type (image)
38
- * @param body - Asset content - can be a browser File instance, a Blob, a Node.js Buffer instance or a Node.js ReadableStream.
39
- * @param options - Options to use for the upload
40
- */
41
- upload(
42
- assetType: 'image',
43
- body: UploadBody,
44
- options?: UploadClientConfig,
45
- ): Observable<HttpRequestEvent<{document: SanityImageAssetDocument}>>
46
-
47
- /**
48
- * Uploads a file or an image asset to the configured dataset
49
- *
50
- * @param assetType - Asset type (file/image)
51
- * @param body - Asset content - can be a browser File instance, a Blob, a Node.js Buffer instance or a Node.js ReadableStream.
52
- * @param options - Options to use for the upload
53
- */
54
- upload(
55
- assetType: 'file' | 'image',
56
- body: UploadBody,
57
- options?: UploadClientConfig,
58
- ): Observable<HttpRequestEvent<{document: SanityAssetDocument | SanityImageAssetDocument}>>
59
- }
60
-
61
- /** @internal */
62
- export interface AssetsClientType {
63
- /**
64
- * Uploads a file asset to the configured dataset
65
- *
66
- * @param assetType - Asset type (file)
67
- * @param body - Asset content - can be a browser File instance, a Blob, a Node.js Buffer instance or a Node.js ReadableStream.
68
- * @param options - Options to use for the upload
69
- */
70
- upload(
71
- assetType: 'file',
72
- body: UploadBody,
73
- options?: UploadClientConfig,
74
- ): Promise<SanityAssetDocument>
75
-
76
- /**
77
- * Uploads an image asset to the configured dataset
78
- *
79
- * @param assetType - Asset type (image)
80
- * @param body - Asset content - can be a browser File instance, a Blob, a Node.js Buffer instance or a Node.js ReadableStream.
81
- * @param options - Options to use for the upload
82
- */
83
- upload(
84
- assetType: 'image',
85
- body: UploadBody,
86
- options?: UploadClientConfig,
87
- ): Promise<SanityImageAssetDocument>
88
-
89
- /**
90
- * Uploads a file or an image asset to the configured dataset
91
- *
92
- * @param assetType - Asset type (file/image)
93
- * @param body - Asset content - can be a browser File instance, a Blob, a Node.js Buffer instance or a Node.js ReadableStream.
94
- * @param options - Options to use for the upload
95
- */
96
- upload(
97
- assetType: 'file' | 'image',
98
- body: UploadBody,
99
- options?: UploadClientConfig,
100
- ): Promise<SanityAssetDocument | SanityImageAssetDocument>
101
- }
102
-
103
- /** @internal */
104
- export class ObservableAssetsClient implements ObservableAssetsClientType {
20
+ export class ObservableAssetsClient {
105
21
  #client: ObservableSanityClient
106
22
  #httpRequest: HttpRequest
107
23
  constructor(client: ObservableSanityClient, httpRequest: HttpRequest) {
@@ -156,7 +72,7 @@ export class ObservableAssetsClient implements ObservableAssetsClientType {
156
72
  }
157
73
 
158
74
  /** @internal */
159
- export class AssetsClient implements AssetsClientType {
75
+ export class AssetsClient {
160
76
  #client: SanityClient
161
77
  #httpRequest: HttpRequest
162
78
  constructor(client: SanityClient, httpRequest: HttpRequest) {
@@ -549,7 +549,7 @@ const isDomExceptionSupported = Boolean(globalThis.DOMException)
549
549
 
550
550
  /**
551
551
  * @internal
552
- * @param signal
552
+ * @param signal - The abort signal to use.
553
553
  * Original source copied from https://github.com/sindresorhus/ky/blob/740732c78aad97e9aec199e9871bdbf0ae29b805/source/errors/DOMException.ts
554
554
  * TODO: When targeting Node.js 18, use `signal.throwIfAborted()` (https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal/throwIfAborted)
555
555
  */
@@ -253,7 +253,7 @@ export class Transaction extends BaseTransaction {
253
253
  return this._add({patch: patch.serialize()})
254
254
  }
255
255
 
256
- /**
256
+ /*
257
257
  * transaction.patch(
258
258
  * {query: "*[_type == 'person' && points >= $threshold]", params: { threshold: 100 }},
259
259
  * {dec: { points: 100 }, inc: { bonuses: 1 }}
@@ -6,69 +6,7 @@ import type {DatasetAclMode, DatasetResponse, DatasetsResponse, HttpRequest} fro
6
6
  import * as validate from '../validators'
7
7
 
8
8
  /** @internal */
9
- export interface ObservableDatasetsClientType {
10
- /**
11
- * Create a new dataset with the given name
12
- *
13
- * @param name - Name of the dataset to create
14
- * @param options - Options for the dataset
15
- */
16
- create(name: string, options?: {aclMode?: DatasetAclMode}): Observable<DatasetResponse>
17
-
18
- /**
19
- * Edit a dataset with the given name
20
- *
21
- * @param name - Name of the dataset to edit
22
- * @param options - New options for the dataset
23
- */
24
- edit(name: string, options?: {aclMode?: DatasetAclMode}): Observable<DatasetResponse>
25
-
26
- /**
27
- * Delete a dataset with the given name
28
- *
29
- * @param name - Name of the dataset to delete
30
- */
31
- delete(name: string): Observable<{deleted: true}>
32
-
33
- /**
34
- * Fetch a list of datasets for the configured project
35
- */
36
- list(): Observable<DatasetsResponse>
37
- }
38
-
39
- /** @internal */
40
- export interface DatasetsClientType {
41
- /**
42
- * Create a new dataset with the given name
43
- *
44
- * @param name - Name of the dataset to create
45
- * @param options - Options for the dataset
46
- */
47
- create(name: string, options?: {aclMode?: DatasetAclMode}): Promise<DatasetResponse>
48
-
49
- /**
50
- * Edit a dataset with the given name
51
- *
52
- * @param name - Name of the dataset to edit
53
- * @param options - New options for the dataset
54
- */
55
- edit(name: string, options?: {aclMode?: DatasetAclMode}): Promise<DatasetResponse>
56
-
57
- /**
58
- * Delete a dataset with the given name
59
- *
60
- * @param name - Name of the dataset to delete
61
- */
62
- delete(name: string): Promise<{deleted: true}>
63
-
64
- /**
65
- * Fetch a list of datasets for the configured project
66
- */
67
- list(): Promise<DatasetsResponse>
68
- }
69
-
70
- /** @internal */
71
- export class ObservableDatasetsClient implements ObservableDatasetsClientType {
9
+ export class ObservableDatasetsClient {
72
10
  #client: ObservableSanityClient
73
11
  #httpRequest: HttpRequest
74
12
  constructor(client: ObservableSanityClient, httpRequest: HttpRequest) {
@@ -117,7 +55,7 @@ export class ObservableDatasetsClient implements ObservableDatasetsClientType {
117
55
  }
118
56
 
119
57
  /** @internal */
120
- export class DatasetsClient implements DatasetsClientType {
58
+ export class DatasetsClient {
121
59
  #client: SanityClient
122
60
  #httpRequest: HttpRequest
123
61
  constructor(client: SanityClient, httpRequest: HttpRequest) {
@@ -6,49 +6,7 @@ import type {HttpRequest, SanityProject} from '../types'
6
6
  import * as validate from '../validators'
7
7
 
8
8
  /** @internal */
9
- export interface ObservableProjectsClientType {
10
- /**
11
- * Fetch a list of projects the authenticated user has access to.
12
- *
13
- * @param options - Options for the list request
14
- * @param options.includeMembers - Whether to include members in the response (default: true)
15
- */
16
- list(options?: {includeMembers?: true}): Observable<SanityProject[]>
17
- list(options?: {includeMembers?: false}): Observable<Omit<SanityProject, 'members'>[]>
18
- list(options?: {
19
- includeMembers?: boolean
20
- }): Observable<SanityProject[] | Omit<SanityProject, 'members'>[]>
21
-
22
- /**
23
- * Fetch a project by project ID
24
- *
25
- * @param projectId - ID of the project to fetch
26
- */
27
- getById(projectId: string): Observable<SanityProject>
28
- }
29
-
30
- /** @internal */
31
- export interface ProjectsClientType {
32
- /**
33
- * Fetch a list of projects the authenticated user has access to.
34
- *
35
- * @param options - Options for the list request
36
- * @param options.includeMembers - Whether to include members in the response (default: true)
37
- */
38
- list(options?: {includeMembers?: true}): Promise<SanityProject[]>
39
- list(options?: {includeMembers?: false}): Promise<Omit<SanityProject, 'members'>[]>
40
- list(options?: {includeMembers?: boolean}): Promise<SanityProject[]>
41
-
42
- /**
43
- * Fetch a project by project ID
44
- *
45
- * @param projectId - ID of the project to fetch
46
- */
47
- getById(projectId: string): Promise<SanityProject>
48
- }
49
-
50
- /** @internal */
51
- export class ObservableProjectsClient implements ObservableProjectsClientType {
9
+ export class ObservableProjectsClient {
52
10
  #client: ObservableSanityClient
53
11
  #httpRequest: HttpRequest
54
12
  constructor(client: ObservableSanityClient, httpRequest: HttpRequest) {
@@ -60,7 +18,7 @@ export class ObservableProjectsClient implements ObservableProjectsClientType {
60
18
  * Fetch a list of projects the authenticated user has access to.
61
19
  *
62
20
  * @param options - Options for the list request
63
- * @param options.includeMembers - Whether to include members in the response (default: true)
21
+ * - `includeMembers` - Whether to include members in the response (default: true)
64
22
  */
65
23
  list(options?: {includeMembers?: true}): Observable<SanityProject[]>
66
24
  list(options?: {includeMembers?: false}): Observable<Omit<SanityProject, 'members'>[]>
@@ -84,7 +42,7 @@ export class ObservableProjectsClient implements ObservableProjectsClientType {
84
42
  }
85
43
 
86
44
  /** @internal */
87
- export class ProjectsClient implements ProjectsClientType {
45
+ export class ProjectsClient {
88
46
  #client: SanityClient
89
47
  #httpRequest: HttpRequest
90
48
  constructor(client: SanityClient, httpRequest: HttpRequest) {
@@ -96,7 +54,7 @@ export class ProjectsClient implements ProjectsClientType {
96
54
  * Fetch a list of projects the authenticated user has access to.
97
55
  *
98
56
  * @param options - Options for the list request
99
- * @param options.includeMembers - Whether to include members in the response (default: true)
57
+ * - `includeMembers` - Whether to include members in the response (default: true)
100
58
  */
101
59
  list(options?: {includeMembers?: true}): Promise<SanityProject[]>
102
60
  list(options?: {includeMembers?: false}): Promise<Omit<SanityProject, 'members'>[]>
package/src/types.ts CHANGED
@@ -963,7 +963,7 @@ export interface ListenOptions {
963
963
  */
964
964
  includePreviousRevision?: boolean
965
965
 
966
- /**
966
+ /*
967
967
  * Whether to include events for drafts and versions. As of API Version >= v2025-02-19, only events
968
968
  * for published documents will be included by default (see {@link https://www.sanity.io/changelog/676aaa9d-2da6-44fb-abe5-580f28047c10|Changelog})
969
969
  * If you need events from drafts and versions, set this to `true`.
@@ -1372,6 +1372,35 @@ export type ClientReturn<
1372
1372
  Fallback = Any,
1373
1373
  > = GroqString extends keyof SanityQueries ? SanityQueries[GroqString] : Fallback
1374
1374
 
1375
+ export type {
1376
+ AgentActionParam,
1377
+ AgentActionParams,
1378
+ AgentActionPath,
1379
+ AgentActionPathSegment,
1380
+ AgentActionTarget,
1381
+ ConstantAgentActionParam,
1382
+ DocumentAgentActionParam,
1383
+ FieldAgentActionParam,
1384
+ GroqAgentActionParam,
1385
+ } from './agent/actions/commonTypes'
1386
+ export type {
1387
+ GenerateInstruction,
1388
+ GenerateOperation,
1389
+ GenerateTarget,
1390
+ GenerateTargetDocument,
1391
+ GenerateTargetInclude,
1392
+ } from './agent/actions/generate'
1393
+ export type {
1394
+ TransformDocument,
1395
+ TransformTarget,
1396
+ TransformTargetDocument,
1397
+ TransformTargetInclude,
1398
+ } from './agent/actions/transform'
1399
+ export type {
1400
+ TranslateDocument,
1401
+ TranslateTarget,
1402
+ TranslateTargetInclude,
1403
+ } from './agent/actions/translate'
1375
1404
  export type {
1376
1405
  ContentSourceMapParsedPath,
1377
1406
  ContentSourceMapParsedPathKeyedSegment,
@@ -4,30 +4,8 @@ import {_request} from '../data/dataMethods'
4
4
  import type {ObservableSanityClient, SanityClient} from '../SanityClient'
5
5
  import type {CurrentSanityUser, HttpRequest, SanityUser} from '../types'
6
6
 
7
- /** @internal */
8
- export interface ObservableUsersClientType {
9
- /**
10
- * Fetch a user by user ID
11
- *
12
- * @param id - User ID of the user to fetch. If `me` is provided, a minimal response including the users role is returned.
13
- */
14
- getById<T extends 'me' | string>(
15
- id: T,
16
- ): Observable<T extends 'me' ? CurrentSanityUser : SanityUser>
17
- }
18
-
19
- /** @internal */
20
- export interface UsersClientType {
21
- /**
22
- * Fetch a user by user ID
23
- *
24
- * @param id - User ID of the user to fetch. If `me` is provided, a minimal response including the users role is returned.
25
- */
26
- getById<T extends 'me' | string>(id: T): Promise<T extends 'me' ? CurrentSanityUser : SanityUser>
27
- }
28
-
29
7
  /** @public */
30
- export class ObservableUsersClient implements ObservableUsersClientType {
8
+ export class ObservableUsersClient {
31
9
  #client: ObservableSanityClient
32
10
  #httpRequest: HttpRequest
33
11
  constructor(client: ObservableSanityClient, httpRequest: HttpRequest) {
@@ -52,7 +30,7 @@ export class ObservableUsersClient implements ObservableUsersClientType {
52
30
  }
53
31
 
54
32
  /** @public */
55
- export class UsersClient implements UsersClientType {
33
+ export class UsersClient {
56
34
  #client: SanityClient
57
35
  #httpRequest: HttpRequest
58
36
  constructor(client: SanityClient, httpRequest: HttpRequest) {
@@ -2871,6 +2871,86 @@ ${selectionOpts}`);
2871
2871
  throw new Error(`Unsupported resource type: ${type.toString()}`);
2872
2872
  }
2873
2873
  };
2874
+ function _generate(client, httpRequest, request) {
2875
+ const dataset2 = hasDataset(client.config());
2876
+ return _request(client, httpRequest, {
2877
+ method: "POST",
2878
+ uri: `/agent/action/generate/${dataset2}`,
2879
+ body: request
2880
+ });
2881
+ }
2882
+ function _transform(client, httpRequest, request) {
2883
+ const dataset2 = hasDataset(client.config());
2884
+ return _request(client, httpRequest, {
2885
+ method: "POST",
2886
+ uri: `/agent/action/transform/${dataset2}`,
2887
+ body: request
2888
+ });
2889
+ }
2890
+ function _translate(client, httpRequest, request) {
2891
+ const dataset2 = hasDataset(client.config());
2892
+ return _request(client, httpRequest, {
2893
+ method: "POST",
2894
+ uri: `/agent/action/translate/${dataset2}`,
2895
+ body: request
2896
+ });
2897
+ }
2898
+ class ObservableAgentsActionClient {
2899
+ #client;
2900
+ #httpRequest;
2901
+ constructor(client, httpRequest) {
2902
+ this.#client = client, this.#httpRequest = httpRequest;
2903
+ }
2904
+ /**
2905
+ * Run an instruction to generate content in a target document.
2906
+ * @param request - instruction request
2907
+ */
2908
+ generate(request) {
2909
+ return _generate(this.#client, this.#httpRequest, request);
2910
+ }
2911
+ /**
2912
+ * Transform a target document based on a source.
2913
+ * @param request - translation request
2914
+ */
2915
+ transform(request) {
2916
+ return _transform(this.#client, this.#httpRequest, request);
2917
+ }
2918
+ /**
2919
+ * Translate a target document based on a source.
2920
+ * @param request - translation request
2921
+ */
2922
+ translate(request) {
2923
+ return _translate(this.#client, this.#httpRequest, request);
2924
+ }
2925
+ }
2926
+ class AgentActionsClient {
2927
+ #client;
2928
+ #httpRequest;
2929
+ constructor(client, httpRequest) {
2930
+ this.#client = client, this.#httpRequest = httpRequest;
2931
+ }
2932
+ /**
2933
+ * Run an instruction to generate content in a target document.
2934
+ * @param request - instruction request
2935
+ */
2936
+ generate(request) {
2937
+ return lastValueFrom(_generate(this.#client, this.#httpRequest, request));
2938
+ }
2939
+ /**
2940
+ * Transform a target document based on a source.
2941
+ * @param request - translation request
2942
+ */
2943
+ transform(request) {
2944
+ return lastValueFrom(_transform(this.#client, this.#httpRequest, request));
2945
+ }
2946
+ /**
2947
+ * Translate a target document based on a source.
2948
+ * @param request - translation request
2949
+ */
2950
+ translate(request) {
2951
+ return lastValueFrom(_translate(this.#client, this.#httpRequest, request));
2952
+ }
2953
+ }
2874
2954
  class ObservableAssetsClient {
2875
2955
  #client;
2876
2956
  #httpRequest;
@@ -3291,11 +3371,20 @@ ${selectionOpts}`);
3291
3371
  live;
3292
3372
  projects;
3293
3373
  users;
3374
+ agent;
3375
+ /**
3376
+ * Private properties
3377
+ */
3294
3378
  #clientConfig;
3295
3379
  #httpRequest;
3380
+ /**
3381
+ * Instance properties
3382
+ */
3296
3383
  listen = _listen;
3297
3384
  constructor(httpRequest, config = defaultConfig) {
3298
- this.config(config), this.#httpRequest = httpRequest, this.assets = new ObservableAssetsClient(this, this.#httpRequest), this.datasets = new ObservableDatasetsClient(this, this.#httpRequest), this.live = new LiveClient(this), this.projects = new ObservableProjectsClient(this, this.#httpRequest), this.users = new ObservableUsersClient(this, this.#httpRequest);
3385
+ this.config(config), this.#httpRequest = httpRequest, this.assets = new ObservableAssetsClient(this, this.#httpRequest), this.datasets = new ObservableDatasetsClient(this, this.#httpRequest), this.live = new LiveClient(this), this.projects = new ObservableProjectsClient(this, this.#httpRequest), this.users = new ObservableUsersClient(this, this.#httpRequest), this.agent = {
3386
+ action: new ObservableAgentsActionClient(this, this.#httpRequest)
3387
+ };
3299
3388
  }
3300
3389
  /**
3301
3390
  * Clone the client - returns a new instance
@@ -3434,15 +3523,24 @@ ${selectionOpts}`);
3434
3523
  live;
3435
3524
  projects;
3436
3525
  users;
3526
+ agent;
3437
3527
  /**
3438
3528
  * Observable version of the Sanity client, with the same configuration as the promise-based one
3439
3529
  */
3440
3530
  observable;
3531
+ /**
3532
+ * Private properties
3533
+ */
3441
3534
  #clientConfig;
3442
3535
  #httpRequest;
3536
+ /**
3537
+ * Instance properties
3538
+ */
3443
3539
  listen = _listen;
3444
3540
  constructor(httpRequest, config = defaultConfig) {
3445
- this.config(config), this.#httpRequest = httpRequest, this.assets = new AssetsClient(this, this.#httpRequest), this.datasets = new DatasetsClient(this, this.#httpRequest), this.live = new LiveClient(this), this.projects = new ProjectsClient(this, this.#httpRequest), this.users = new UsersClient(this, this.#httpRequest), this.observable = new ObservableSanityClient(httpRequest, config);
3541
+ this.config(config), this.#httpRequest = httpRequest, this.assets = new AssetsClient(this, this.#httpRequest), this.datasets = new DatasetsClient(this, this.#httpRequest), this.live = new LiveClient(this), this.projects = new ProjectsClient(this, this.#httpRequest), this.users = new UsersClient(this, this.#httpRequest), this.agent = {
3542
+ action: new AgentActionsClient(this, this.#httpRequest)
3543
+ }, this.observable = new ObservableSanityClient(httpRequest, config);
3446
3544
  }
3447
3545
  /**
3448
3546
  * Clone the client - returns a new instance
@@ -3536,8 +3634,8 @@ ${selectionOpts}`);
3536
3634
  * @param operations - Optional object of patch operations to initialize the patch instance with
3537
3635
  * @returns Patch instance - call `.commit()` to perform the operations defined
3538
3636
  */
3539
- patch(selection, operations) {
3540
- return new Patch(selection, operations, this);
3637
+ patch(documentId, operations) {
3638
+ return new Patch(documentId, operations, this);
3541
3639
  }
3542
3640
  /**
3543
3641
  * Create a new transaction of mutations