@sanity/sdk 2.3.0 → 2.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.
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as _sanity_client12 from "@sanity/client";
2
- import { ClientConfig, ClientPerspective, ListenEvent, ResponseQueryOptions, SanityClient, SanityDocument as SanityDocument$1, SanityProject as SanityProject$1, StackablePerspective } from "@sanity/client";
2
+ import { ClientConfig, ClientError, ClientPerspective, ListenEvent, ResponseQueryOptions, SanityClient, SanityDocument as SanityDocument$1, SanityProject as SanityProject$1, StackablePerspective } from "@sanity/client";
3
3
  import { Observable, Subject } from "rxjs";
4
4
  import { CurrentUser, CurrentUser as CurrentUser$1, Mutation, PatchOperations, Role, SanityDocument, SanityDocument as SanityDocument$2, SanityDocumentLike } from "@sanity/types";
5
5
  import * as _sanity_comlink3 from "@sanity/comlink";
@@ -9,17 +9,6 @@ import { SanityDocument as SanityDocument$3, SanityProjectionResult, SanityQuery
9
9
  import { ExprNode } from "groq-js";
10
10
  import { CanvasResource, MediaResource, StudioResource } from "@sanity/message-protocol";
11
11
  import { getIndexForKey, getPathDepth, joinPaths, jsonMatch, slicePath, stringifyPath } from "@sanity/json-match";
12
- /**
13
- * Represents the various states the authentication type can be in.
14
- *
15
- * @public
16
- */
17
- declare enum AuthStateType {
18
- LOGGED_IN = "logged-in",
19
- LOGGING_IN = "logging-in",
20
- ERROR = "error",
21
- LOGGED_OUT = "logged-out",
22
- }
23
12
  /**
24
13
  * Configuration for an authentication provider
25
14
  * @public
@@ -150,6 +139,39 @@ interface SanityConfig extends DatasetHandle, PerspectiveHandle {
150
139
  enabled: boolean;
151
140
  };
152
141
  }
142
+ declare const SOURCE_ID = "__sanity_internal_sourceId";
143
+ /**
144
+ * A document source can be used for querying.
145
+ *
146
+ * @beta
147
+ * @see datasetSource Construct a document source for a given projectId and dataset.
148
+ * @see mediaLibrarySource Construct a document source for a mediaLibraryId.
149
+ * @see canvasSource Construct a document source for a canvasId.
150
+ */
151
+ type DocumentSource = {
152
+ [SOURCE_ID]: ['media-library', string] | ['canvas', string] | {
153
+ projectId: string;
154
+ dataset: string;
155
+ };
156
+ };
157
+ /**
158
+ * Returns a document source for a projectId and dataset.
159
+ *
160
+ * @beta
161
+ */
162
+ declare function datasetSource(projectId: string, dataset: string): DocumentSource;
163
+ /**
164
+ * Returns a document source for a Media Library.
165
+ *
166
+ * @beta
167
+ */
168
+ declare function mediaLibrarySource(id: string): DocumentSource;
169
+ /**
170
+ * Returns a document source for a Canvas.
171
+ *
172
+ * @beta
173
+ */
174
+ declare function canvasSource(id: string): DocumentSource;
153
175
  /**
154
176
  * Represents a Sanity.io resource instance with its own configuration and lifecycle
155
177
  * @remarks Instances form a hierarchy through parent/child relationships
@@ -211,6 +233,77 @@ interface SanityInstance {
211
233
  * @public
212
234
  */
213
235
  declare function createSanityInstance(config?: SanityConfig): SanityInstance;
236
+ /** @alpha */
237
+ type AgentGenerateOptions = Parameters<SanityClient['observable']['agent']['action']['generate']>[0];
238
+ /** @alpha */
239
+ type AgentTransformOptions = Parameters<SanityClient['observable']['agent']['action']['transform']>[0];
240
+ /** @alpha */
241
+ type AgentTranslateOptions = Parameters<SanityClient['observable']['agent']['action']['translate']>[0];
242
+ /** @alpha */
243
+ type AgentPromptOptions = Parameters<SanityClient['agent']['action']['prompt']>[0];
244
+ /** @alpha */
245
+ type AgentPatchOptions = Parameters<SanityClient['agent']['action']['patch']>[0];
246
+ /** @alpha */
247
+ type AgentGenerateResult = Awaited<ReturnType<SanityClient['observable']['agent']['action']['generate']>>;
248
+ /** @alpha */
249
+ type AgentTransformResult = Awaited<ReturnType<SanityClient['observable']['agent']['action']['transform']>>;
250
+ /** @alpha */
251
+ type AgentTranslateResult = Awaited<ReturnType<SanityClient['observable']['agent']['action']['translate']>>;
252
+ /** @alpha */
253
+ type AgentPromptResult = Awaited<ReturnType<SanityClient['agent']['action']['prompt']>>;
254
+ /** @alpha */
255
+ type AgentPatchResult = Awaited<ReturnType<SanityClient['agent']['action']['patch']>>;
256
+ /**
257
+ * Generates a new document using the agent.
258
+ * @param instance - The Sanity instance.
259
+ * @param options - The options for the agent generate action. See the [Agent Actions API](https://www.sanity.io/docs/agent-actions/introduction) for more details.
260
+ * @returns An Observable emitting the result of the agent generate action.
261
+ * @alpha
262
+ */
263
+ declare function agentGenerate(instance: SanityInstance, options: AgentGenerateOptions): AgentGenerateResult;
264
+ /**
265
+ * Transforms a document using the agent.
266
+ * @param instance - The Sanity instance.
267
+ * @param options - The options for the agent transform action. See the [Agent Actions API](https://www.sanity.io/docs/agent-actions/introduction) for more details.
268
+ * @returns An Observable emitting the result of the agent transform action.
269
+ * @alpha
270
+ */
271
+ declare function agentTransform(instance: SanityInstance, options: AgentTransformOptions): AgentTransformResult;
272
+ /**
273
+ * Translates a document using the agent.
274
+ * @param instance - The Sanity instance.
275
+ * @param options - The options for the agent translate action. See the [Agent Actions API](https://www.sanity.io/docs/agent-actions/introduction) for more details.
276
+ * @returns An Observable emitting the result of the agent translate action.
277
+ * @alpha
278
+ */
279
+ declare function agentTranslate(instance: SanityInstance, options: AgentTranslateOptions): AgentTranslateResult;
280
+ /**
281
+ * Prompts the agent using the same instruction template format as the other actions, but returns text or json instead of acting on a document.
282
+ * @param instance - The Sanity instance.
283
+ * @param options - The options for the agent prompt action. See the [Agent Actions API](https://www.sanity.io/docs/agent-actions/introduction) for more details.
284
+ * @returns An Observable emitting the result of the agent prompt action.
285
+ * @alpha
286
+ */
287
+ declare function agentPrompt(instance: SanityInstance, options: AgentPromptOptions): Observable<AgentPromptResult>;
288
+ /**
289
+ * Patches a document using the agent.
290
+ * @param instance - The Sanity instance.
291
+ * @param options - The options for the agent patch action. See the [Agent Actions API](https://www.sanity.io/docs/agent-actions/introduction) for more details.
292
+ * @returns An Observable emitting the result of the agent patch action.
293
+ * @alpha
294
+ */
295
+ declare function agentPatch(instance: SanityInstance, options: AgentPatchOptions): Observable<AgentPatchResult>;
296
+ /**
297
+ * Represents the various states the authentication type can be in.
298
+ *
299
+ * @public
300
+ */
301
+ declare enum AuthStateType {
302
+ LOGGED_IN = "logged-in",
303
+ LOGGING_IN = "logging-in",
304
+ ERROR = "error",
305
+ LOGGED_OUT = "logged-out",
306
+ }
214
307
  /**
215
308
  * Represents a store action that has been bound to a specific store instance
216
309
  */
@@ -288,6 +381,10 @@ interface DashboardContext {
288
381
  env?: string;
289
382
  orgId?: string;
290
383
  }
384
+ /**
385
+ * The method of authentication used.
386
+ * @internal
387
+ */
291
388
  type AuthMethodOptions = 'localstorage' | 'cookie' | undefined;
292
389
  /**
293
390
  * @public
@@ -370,6 +467,24 @@ declare const handleAuthCallback: BoundStoreAction<AuthStoreState, [locationHref
370
467
  * @public
371
468
  */
372
469
  declare const logout: BoundStoreAction<AuthStoreState, [], Promise<void>>;
470
+ /** @internal */
471
+ type ApiErrorBody = {
472
+ error?: {
473
+ type?: string;
474
+ description?: string;
475
+ };
476
+ type?: string;
477
+ description?: string;
478
+ message?: string;
479
+ };
480
+ /** @internal Extracts the structured API error body from a ClientError, if present. */
481
+ declare function getClientErrorApiBody(error: ClientError): ApiErrorBody | undefined;
482
+ /** @internal Returns the error type string from an API error body, if available. */
483
+ declare function getClientErrorApiType(error: ClientError): string | undefined;
484
+ /** @internal Returns the error description string from an API error body, if available. */
485
+ declare function getClientErrorApiDescription(error: ClientError): string | undefined;
486
+ /** @internal True if the error represents a projectUserNotFoundError. */
487
+ declare function isProjectUserNotFoundClientError(error: ClientError): boolean;
373
488
  type AllowedClientConfigKey = 'useCdn' | 'token' | 'perspective' | 'apiHost' | 'proxy' | 'withCredentials' | 'timeout' | 'maxRetries' | 'dataset' | 'projectId' | 'requestTagPrefix' | 'useProjectHostname';
374
489
  /**
375
490
  * States tracked by the client store
@@ -411,6 +526,10 @@ interface ClientOptions extends Pick<ClientConfig, AllowedClientConfigKey> {
411
526
  * @internal
412
527
  */
413
528
  '~experimental_resource'?: ClientConfig['~experimental_resource'];
529
+ /**
530
+ * @internal
531
+ */
532
+ 'source'?: DocumentSource;
414
533
  }
415
534
  /**
416
535
  * Retrieves a Sanity client instance configured with the provided options.
@@ -592,6 +711,12 @@ declare const resolveDatasets: BoundStoreAction<FetcherStoreState<[options?: Pro
592
711
  */
593
712
  interface CreateDocumentAction<TDocumentType extends string = string, TDataset extends string = string, TProjectId extends string = string> extends DocumentTypeHandle<TDocumentType, TDataset, TProjectId> {
594
713
  type: 'document.create';
714
+ /**
715
+ * Optional initial field values for the document.
716
+ * These values will be set when the document is created.
717
+ * System fields (_id, _type, _rev, _createdAt, _updatedAt) are omitted as they are set automatically.
718
+ */
719
+ initialValue?: Partial<Omit<SanityDocument$3<TDocumentType, `${TProjectId}.${TDataset}`>, '_id' | '_type' | '_rev' | '_createdAt' | '_updatedAt'>>;
595
720
  }
596
721
  /**
597
722
  * Represents an action to delete an existing document.
@@ -642,10 +767,11 @@ type DocumentAction<TDocumentType extends string = string, TDataset extends stri
642
767
  /**
643
768
  * Creates a `CreateDocumentAction` object.
644
769
  * @param doc - A handle identifying the document type, dataset, and project. An optional `documentId` can be provided.
770
+ * @param initialValue - Optional initial field values for the document. (System fields are omitted as they are set automatically.)
645
771
  * @returns A `CreateDocumentAction` object ready for dispatch.
646
772
  * @beta
647
773
  */
648
- declare function createDocument<TDocumentType extends string = string, TDataset extends string = string, TProjectId extends string = string>(doc: DocumentTypeHandle<TDocumentType, TDataset, TProjectId>): CreateDocumentAction<TDocumentType, TDataset, TProjectId>;
774
+ declare function createDocument<TDocumentType extends string = string, TDataset extends string = string, TProjectId extends string = string>(doc: DocumentTypeHandle<TDocumentType, TDataset, TProjectId>, initialValue?: Partial<Omit<SanityDocument$3<TDocumentType, `${TProjectId}.${TDataset}`>, '_id' | '_type' | '_rev' | '_createdAt' | '_updatedAt'>>): CreateDocumentAction<TDocumentType, TDataset, TProjectId>;
649
775
  /**
650
776
  * Creates a `DeleteDocumentAction` object.
651
777
  * @param doc - A handle uniquely identifying the document to be deleted.
@@ -1490,6 +1616,7 @@ declare const resolveProjects: BoundStoreAction<FetcherStoreState<[options?: {
1490
1616
  interface QueryOptions<TQuery extends string = string, TDataset extends string = string, TProjectId extends string = string> extends Pick<ResponseQueryOptions, 'useCdn' | 'cache' | 'next' | 'cacheMode' | 'tag'>, DatasetHandle<TDataset, TProjectId> {
1491
1617
  query: TQuery;
1492
1618
  params?: Record<string, unknown>;
1619
+ source?: DocumentSource;
1493
1620
  }
1494
1621
  /**
1495
1622
  * @beta
@@ -1575,7 +1702,7 @@ declare const getActiveReleasesState: BoundStoreAction<ReleasesStoreState, [], S
1575
1702
  *
1576
1703
  * @public
1577
1704
  */
1578
- declare const getPerspectiveState: BoundStoreAction<ReleasesStoreState, [options?: PerspectiveHandle | undefined], StateSource<string[] | "previewDrafts" | "published" | "drafts" | "raw" | undefined>>;
1705
+ declare const getPerspectiveState: BoundStoreAction<ReleasesStoreState, [options?: PerspectiveHandle | undefined], StateSource<string[] | "raw" | "previewDrafts" | "published" | "drafts" | undefined>>;
1579
1706
  /** @internal */
1580
1707
  declare const getUsersKey: (instance: SanityInstance, {
1581
1708
  resourceType,
@@ -1605,7 +1732,7 @@ declare const parseUsersKey: (key: string) => {
1605
1732
  *
1606
1733
  * @beta
1607
1734
  */
1608
- declare const getUsersState: BoundStoreAction<UsersStoreState, [options?: GetUsersOptions], StateSource<{
1735
+ declare const getUsersState: BoundStoreAction<UsersStoreState, [options?: GetUsersOptions | undefined], StateSource<{
1609
1736
  data: SanityUser[];
1610
1737
  totalCount: number;
1611
1738
  hasMore: boolean;
@@ -1654,7 +1781,7 @@ declare const getUserState: BoundStoreAction<UsersStoreState, [GetUserOptions],
1654
1781
  /**
1655
1782
  * @beta
1656
1783
  */
1657
- declare const resolveUser: BoundStoreAction<UsersStoreState, [ResolveUserOptions], Promise<SanityUser | undefined>>;
1784
+ declare const resolveUser: BoundStoreAction<UsersStoreState, [ResolveUserOptions], Promise<SanityUser>>;
1658
1785
  interface StoreEntry<TParams extends unknown[], TData> {
1659
1786
  params: TParams;
1660
1787
  instance: SanityInstance;
@@ -1866,4 +1993,4 @@ declare const CORE_SDK_VERSION: {};
1866
1993
  * @public
1867
1994
  */
1868
1995
  type SanityProject = SanityProject$1;
1869
- export { type ActionErrorEvent, type ActionsResult, type ApplyDocumentActionsOptions, type AuthConfig, type AuthProvider, type AuthState, AuthStateType, type AuthStoreState, CORE_SDK_VERSION, type ClientOptions, type ClientStoreState as ClientState, type ComlinkControllerState, type ComlinkNodeState, type CreateDocumentAction, type CurrentUser, type DatasetHandle, type DeleteDocumentAction, type DiscardDocumentAction, type DisconnectEvent, type DocumentAction, type DocumentCreatedEvent, type DocumentDeletedEvent, type DocumentDiscardedEvent, type DocumentEditedEvent, type DocumentEvent, type DocumentHandle, type DocumentOptions, type DocumentPermissionsResult, type DocumentPublishedEvent, type DocumentTypeHandle, type DocumentUnpublishedEvent, type EditDocumentAction, type ErrorAuthState, type FavoriteStatusResponse, type FetcherStore, type FetcherStoreState, type FrameMessage, type GetPreviewStateOptions, type GetUserOptions, type GetUsersOptions, type Intent, type IntentFilter, type JsonMatch, type LoggedInAuthState, type LoggedOutAuthState, type LoggingInAuthState, type Membership, type NewTokenResponseMessage, type NodeState, type OrgVerificationResult, type PermissionDeniedReason, type PerspectiveHandle, type PresenceLocation, type PreviewStoreState, type PreviewValue, type ProjectHandle, type ProjectionValuePending, type PublishDocumentAction, type QueryOptions, type ReleaseDocument, type ReleasePerspective, type RequestNewTokenMessage, type ResolvePreviewOptions, type ResolveUserOptions, type ResolveUsersOptions, type Role, type RollCallEvent, type SanityConfig, type SanityDocument, type SanityInstance, SanityProject, type SanityUser, type SanityUserResponse, type Selector, type StateEvent, type StateSource, type TransactionAcceptedEvent, type TransactionRevertedEvent, type TransportEvent, type UnpublishDocumentAction, type UserPresence, type UserProfile, type UsersGroupState, type UsersStoreState, type ValidProjection, type ValuePending, type WindowMessage, applyDocumentActions, createDatasetHandle, createDocument, createDocumentHandle, createDocumentTypeHandle, createGroqSearchFilter, createProjectHandle, createSanityInstance, defineIntent, deleteDocument, destroyController, discardDocument, editDocument, getActiveReleasesState, getAuthState, getClient, getClientState, getCorsErrorProjectId, getCurrentUserState, getDashboardOrganizationId, getDatasetsState, getDocumentState, getDocumentSyncStatus, getFavoritesState, getIndexForKey, getIsInDashboardState, getLoginUrlState, getNodeState, getOrCreateChannel, getOrCreateController, getOrCreateNode, getPathDepth, getPermissionsState, getPerspectiveState, getPresence, getPreviewState, getProjectState, getProjectionState, getProjectsState, getQueryKey, getQueryState, getTokenState, getUserState, getUsersKey, getUsersState, handleAuthCallback, joinPaths, jsonMatch, loadMoreUsers, logout, observeOrganizationVerificationState, parseQueryKey, parseUsersKey, publishDocument, releaseChannel, releaseNode, resolveDatasets, resolveDocument, resolveFavoritesState, resolvePermissions, resolvePreview, resolveProject, resolveProjection, resolveProjects, resolveQuery, resolveUser, resolveUsers, setAuthToken, slicePath, stringifyPath, subscribeDocumentEvents, unpublishDocument };
1996
+ export { type ActionErrorEvent, type ActionsResult, type AgentGenerateOptions, type AgentGenerateResult, type AgentPatchOptions, type AgentPatchResult, type AgentPromptOptions, type AgentPromptResult, type AgentTransformOptions, type AgentTransformResult, type AgentTranslateOptions, type AgentTranslateResult, type ApiErrorBody, type ApplyDocumentActionsOptions, type AuthConfig, type AuthProvider, type AuthState, AuthStateType, type AuthStoreState, CORE_SDK_VERSION, type ClientOptions, type ClientStoreState as ClientState, type ComlinkControllerState, type ComlinkNodeState, type CreateDocumentAction, type CurrentUser, type DatasetHandle, type DeleteDocumentAction, type DiscardDocumentAction, type DisconnectEvent, type DocumentAction, type DocumentCreatedEvent, type DocumentDeletedEvent, type DocumentDiscardedEvent, type DocumentEditedEvent, type DocumentEvent, type DocumentHandle, type DocumentOptions, type DocumentPermissionsResult, type DocumentPublishedEvent, type DocumentSource, type DocumentTypeHandle, type DocumentUnpublishedEvent, type EditDocumentAction, type ErrorAuthState, type FavoriteStatusResponse, type FetcherStore, type FetcherStoreState, type FrameMessage, type GetPreviewStateOptions, type GetUserOptions, type GetUsersOptions, type Intent, type IntentFilter, type JsonMatch, type LoggedInAuthState, type LoggedOutAuthState, type LoggingInAuthState, type Membership, type NewTokenResponseMessage, type NodeState, type OrgVerificationResult, type PermissionDeniedReason, type PerspectiveHandle, type PresenceLocation, type PreviewStoreState, type PreviewValue, type ProjectHandle, type ProjectionValuePending, type PublishDocumentAction, type QueryOptions, type ReleaseDocument, type ReleasePerspective, type RequestNewTokenMessage, type ResolvePreviewOptions, type ResolveUserOptions, type ResolveUsersOptions, type Role, type RollCallEvent, type SanityConfig, type SanityDocument, type SanityInstance, SanityProject, type SanityUser, type SanityUserResponse, type Selector, type StateEvent, type StateSource, type TransactionAcceptedEvent, type TransactionRevertedEvent, type TransportEvent, type UnpublishDocumentAction, type UserPresence, type UserProfile, type UsersGroupState, type UsersStoreState, type ValidProjection, type ValuePending, type WindowMessage, agentGenerate, agentPatch, agentPrompt, agentTransform, agentTranslate, applyDocumentActions, canvasSource, createDatasetHandle, createDocument, createDocumentHandle, createDocumentTypeHandle, createGroqSearchFilter, createProjectHandle, createSanityInstance, datasetSource, defineIntent, deleteDocument, destroyController, discardDocument, editDocument, getActiveReleasesState, getAuthState, getClient, getClientErrorApiBody, getClientErrorApiDescription, getClientErrorApiType, getClientState, getCorsErrorProjectId, getCurrentUserState, getDashboardOrganizationId, getDatasetsState, getDocumentState, getDocumentSyncStatus, getFavoritesState, getIndexForKey, getIsInDashboardState, getLoginUrlState, getNodeState, getOrCreateChannel, getOrCreateController, getOrCreateNode, getPathDepth, getPermissionsState, getPerspectiveState, getPresence, getPreviewState, getProjectState, getProjectionState, getProjectsState, getQueryKey, getQueryState, getTokenState, getUserState, getUsersKey, getUsersState, handleAuthCallback, isProjectUserNotFoundClientError, joinPaths, jsonMatch, loadMoreUsers, logout, mediaLibrarySource, observeOrganizationVerificationState, parseQueryKey, parseUsersKey, publishDocument, releaseChannel, releaseNode, resolveDatasets, resolveDocument, resolveFavoritesState, resolvePermissions, resolvePreview, resolveProject, resolveProjection, resolveProjects, resolveQuery, resolveUser, resolveUsers, setAuthToken, slicePath, stringifyPath, subscribeDocumentEvents, unpublishDocument };