@sanity/sdk 2.6.0 → 2.7.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 +124 -13
- package/dist/index.js +468 -243
- package/dist/index.js.map +1 -1
- package/package.json +5 -4
- package/src/_exports/index.ts +3 -0
- package/src/auth/authMode.test.ts +56 -0
- package/src/auth/authMode.ts +71 -0
- package/src/auth/authStore.test.ts +85 -4
- package/src/auth/authStore.ts +63 -125
- package/src/auth/authStrategy.ts +39 -0
- package/src/auth/dashboardAuth.ts +132 -0
- package/src/auth/standaloneAuth.ts +109 -0
- package/src/auth/studioAuth.ts +217 -0
- package/src/auth/studioModeAuth.test.ts +43 -1
- package/src/auth/studioModeAuth.ts +10 -1
- package/src/auth/subscribeToStateAndFetchCurrentUser.ts +21 -6
- package/src/config/sanityConfig.ts +48 -7
- package/src/projection/getProjectionState.ts +6 -5
- package/src/projection/projectionQuery.test.ts +38 -55
- package/src/projection/projectionQuery.ts +27 -31
- package/src/projection/projectionStore.test.ts +4 -4
- package/src/projection/projectionStore.ts +3 -2
- package/src/projection/resolveProjection.ts +2 -2
- package/src/projection/statusQuery.test.ts +35 -0
- package/src/projection/statusQuery.ts +71 -0
- package/src/projection/subscribeToStateAndFetchBatches.test.ts +63 -50
- package/src/projection/subscribeToStateAndFetchBatches.ts +106 -27
- package/src/projection/types.ts +12 -0
- package/src/projection/util.ts +0 -1
- package/src/query/queryStore.test.ts +64 -0
- package/src/query/queryStore.ts +30 -10
- package/src/releases/getPerspectiveState.test.ts +17 -14
- package/src/releases/getPerspectiveState.ts +58 -38
- package/src/releases/releasesStore.test.ts +59 -61
- package/src/releases/releasesStore.ts +21 -35
- package/src/releases/utils/isReleasePerspective.ts +7 -0
- package/src/store/createActionBinder.test.ts +211 -1
- package/src/store/createActionBinder.ts +95 -17
- package/src/store/createSanityInstance.ts +3 -1
package/dist/index.d.ts
CHANGED
|
@@ -76,6 +76,42 @@ interface AuthConfig {
|
|
|
76
76
|
*/
|
|
77
77
|
token?: string;
|
|
78
78
|
}
|
|
79
|
+
/**
|
|
80
|
+
* A minimal Observable-compatible interface for subscribing to token changes.
|
|
81
|
+
* Any object with a `subscribe` method that follows this contract will work,
|
|
82
|
+
* including RxJS Observables. This avoids coupling the SDK to a specific
|
|
83
|
+
* reactive library.
|
|
84
|
+
*
|
|
85
|
+
* @public
|
|
86
|
+
*/
|
|
87
|
+
interface TokenSource {
|
|
88
|
+
/** Subscribe to token emissions. Emits `null` when logged out. */
|
|
89
|
+
subscribe(observer: {
|
|
90
|
+
next: (token: string | null) => void;
|
|
91
|
+
}): {
|
|
92
|
+
unsubscribe(): void;
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Studio-specific configuration for the SDK.
|
|
97
|
+
* When present, the SDK operates in studio mode and derives auth from the
|
|
98
|
+
* provided token source instead of discovering tokens independently.
|
|
99
|
+
*
|
|
100
|
+
* @public
|
|
101
|
+
*/
|
|
102
|
+
interface StudioConfig {
|
|
103
|
+
/** Reactive auth token source from the Studio's auth store. */
|
|
104
|
+
auth?: {
|
|
105
|
+
/**
|
|
106
|
+
* A reactive token source. The SDK subscribes and stays in sync — the
|
|
107
|
+
* Studio is the single authority for auth and handles token refresh.
|
|
108
|
+
*
|
|
109
|
+
* Optional because older Studios may not expose it. When absent, the
|
|
110
|
+
* SDK falls back to localStorage/cookie discovery.
|
|
111
|
+
*/
|
|
112
|
+
token?: TokenSource;
|
|
113
|
+
};
|
|
114
|
+
}
|
|
79
115
|
/**
|
|
80
116
|
* Represents the minimal configuration required to identify a Sanity project.
|
|
81
117
|
* @public
|
|
@@ -101,11 +137,6 @@ interface PerspectiveHandle {
|
|
|
101
137
|
*/
|
|
102
138
|
interface DatasetHandle<TDataset extends string = string, TProjectId extends string = string> extends ProjectHandle<TProjectId>, PerspectiveHandle {
|
|
103
139
|
dataset?: TDataset;
|
|
104
|
-
/**
|
|
105
|
-
* @beta
|
|
106
|
-
* The name of the source to use for this operation.
|
|
107
|
-
*/
|
|
108
|
-
sourceName?: string;
|
|
109
140
|
/**
|
|
110
141
|
* @beta
|
|
111
142
|
* Explicit source object to use for this operation.
|
|
@@ -148,8 +179,19 @@ interface SanityConfig extends DatasetHandle, PerspectiveHandle {
|
|
|
148
179
|
*/
|
|
149
180
|
auth?: AuthConfig;
|
|
150
181
|
/**
|
|
151
|
-
* Studio
|
|
152
|
-
*
|
|
182
|
+
* Studio configuration provided by a Sanity Studio workspace.
|
|
183
|
+
* When present, the SDK operates in studio mode and derives auth from the
|
|
184
|
+
* workspace's reactive token source — no manual configuration needed.
|
|
185
|
+
*
|
|
186
|
+
* @remarks Typically set automatically by `SanityApp` when it detects an
|
|
187
|
+
* `SDKStudioContext` provider. Can also be set explicitly for programmatic use.
|
|
188
|
+
*/
|
|
189
|
+
studio?: StudioConfig;
|
|
190
|
+
/**
|
|
191
|
+
* Studio mode configuration for use of the SDK in a Sanity Studio.
|
|
192
|
+
* @remarks Controls whether studio mode features are enabled.
|
|
193
|
+
* @deprecated Use `studio` instead, which provides richer integration
|
|
194
|
+
* with the Studio's workspace (auth token sync, etc.).
|
|
153
195
|
*/
|
|
154
196
|
studioMode?: {
|
|
155
197
|
enabled: boolean;
|
|
@@ -319,6 +361,14 @@ declare function agentPrompt(instance: SanityInstance, options: AgentPromptOptio
|
|
|
319
361
|
* @alpha
|
|
320
362
|
*/
|
|
321
363
|
declare function agentPatch(instance: SanityInstance, options: AgentPatchOptions): Observable<AgentPatchResult>;
|
|
364
|
+
/**
|
|
365
|
+
* Returns `true` when the config indicates the SDK is running inside a Studio.
|
|
366
|
+
* Checks the new `studio` field first, then falls back to the deprecated
|
|
367
|
+
* `studioMode.enabled` for backwards compatibility.
|
|
368
|
+
*
|
|
369
|
+
* @internal
|
|
370
|
+
*/
|
|
371
|
+
declare function isStudioConfig(config: SanityConfig): boolean;
|
|
322
372
|
/**
|
|
323
373
|
* Represents the various states the authentication type can be in.
|
|
324
374
|
*
|
|
@@ -330,6 +380,64 @@ declare enum AuthStateType {
|
|
|
330
380
|
ERROR = "error",
|
|
331
381
|
LOGGED_OUT = "logged-out",
|
|
332
382
|
}
|
|
383
|
+
/**
|
|
384
|
+
* Represents a reactive store state container with multiple access patterns
|
|
385
|
+
*/
|
|
386
|
+
interface StoreState<TState> {
|
|
387
|
+
/**
|
|
388
|
+
* Gets the current state value
|
|
389
|
+
*
|
|
390
|
+
* @remarks
|
|
391
|
+
* This is a direct synchronous accessor that doesn't trigger subscriptions
|
|
392
|
+
*/
|
|
393
|
+
get: () => TState;
|
|
394
|
+
/**
|
|
395
|
+
* Updates the store state
|
|
396
|
+
* @param name - Action name for devtools tracking
|
|
397
|
+
* @param updatedState - New state value or updater function
|
|
398
|
+
*
|
|
399
|
+
* @remarks
|
|
400
|
+
* When providing a partial object, previous top-level keys not included in
|
|
401
|
+
* the update will be preserved.
|
|
402
|
+
*/
|
|
403
|
+
set: (name: string, updatedState: Partial<TState> | ((s: TState) => Partial<TState>)) => void;
|
|
404
|
+
/**
|
|
405
|
+
* Observable stream of state changes
|
|
406
|
+
* @remarks
|
|
407
|
+
* - Emits immediately with current state on subscription
|
|
408
|
+
* - Shares underlying subscription between observers
|
|
409
|
+
* - Only emits when state reference changes
|
|
410
|
+
* - Completes when store is disposed
|
|
411
|
+
*/
|
|
412
|
+
observable: Observable<TState>;
|
|
413
|
+
}
|
|
414
|
+
/**
|
|
415
|
+
* Context object provided to store initialization functions
|
|
416
|
+
*/
|
|
417
|
+
interface StoreContext<TState, TKey = unknown> {
|
|
418
|
+
/**
|
|
419
|
+
* Sanity instance associated with this store
|
|
420
|
+
*
|
|
421
|
+
* @remarks
|
|
422
|
+
* Provides access to the Sanity configuration and instance lifecycle methods
|
|
423
|
+
*/
|
|
424
|
+
instance: SanityInstance;
|
|
425
|
+
/**
|
|
426
|
+
* Reactive store state management utilities
|
|
427
|
+
*
|
|
428
|
+
* @remarks
|
|
429
|
+
* Contains methods for getting/setting state and observing changes
|
|
430
|
+
*/
|
|
431
|
+
state: StoreState<TState>;
|
|
432
|
+
/**
|
|
433
|
+
* The key used to instantiate the store.
|
|
434
|
+
*/
|
|
435
|
+
key: TKey;
|
|
436
|
+
}
|
|
437
|
+
/**
|
|
438
|
+
* Defines a store action that operates on a specific state type
|
|
439
|
+
*/
|
|
440
|
+
type StoreAction<TState, TParams extends unknown[], TReturn, TKey = unknown> = (context: StoreContext<TState, TKey>, ...params: TParams) => TReturn;
|
|
333
441
|
/**
|
|
334
442
|
* Represents a store action that has been bound to a specific store instance
|
|
335
443
|
*/
|
|
@@ -1865,7 +1973,6 @@ declare const resolveProjects: BoundStoreAction<FetcherStoreState<[options?: {
|
|
|
1865
1973
|
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> {
|
|
1866
1974
|
query: TQuery;
|
|
1867
1975
|
params?: Record<string, unknown>;
|
|
1868
|
-
source?: DocumentSource;
|
|
1869
1976
|
}
|
|
1870
1977
|
/**
|
|
1871
1978
|
* @beta
|
|
@@ -1942,6 +2049,13 @@ declare const getActiveReleasesState: BoundStoreAction<ReleasesStoreState, [((ob
|
|
|
1942
2049
|
projectId?: string;
|
|
1943
2050
|
dataset?: string;
|
|
1944
2051
|
}) | undefined)?, ...unknown[]], StateSource<ReleaseDocument[] | undefined>>;
|
|
2052
|
+
declare const _getPerspectiveStateSelector: StoreAction<ReleasesStoreState, [_?: (PerspectiveHandle & {
|
|
2053
|
+
projectId?: string;
|
|
2054
|
+
dataset?: string;
|
|
2055
|
+
}) | undefined], StateSource<string[] | "previewDrafts" | "published" | "drafts" | "raw" | undefined>, unknown>;
|
|
2056
|
+
type OmitFirst<T extends unknown[]> = T extends [unknown, ...infer R] ? R : never;
|
|
2057
|
+
type SelectorParams = OmitFirst<Parameters<typeof _getPerspectiveStateSelector>>;
|
|
2058
|
+
type BoundGetPerspectiveState = BoundStoreAction<ReleasesStoreState, SelectorParams, ReturnType<typeof _getPerspectiveStateSelector>>;
|
|
1945
2059
|
/**
|
|
1946
2060
|
* Provides a subscribable state source for a "perspective" for the Sanity client,
|
|
1947
2061
|
* which is used to fetch documents as though certain Content Releases are active.
|
|
@@ -1954,10 +2068,7 @@ declare const getActiveReleasesState: BoundStoreAction<ReleasesStoreState, [((ob
|
|
|
1954
2068
|
*
|
|
1955
2069
|
* @public
|
|
1956
2070
|
*/
|
|
1957
|
-
declare const getPerspectiveState:
|
|
1958
|
-
projectId?: string;
|
|
1959
|
-
dataset?: string;
|
|
1960
|
-
}) | undefined], StateSource<string[] | "raw" | "previewDrafts" | "published" | "drafts" | undefined>>;
|
|
2071
|
+
declare const getPerspectiveState: BoundGetPerspectiveState;
|
|
1961
2072
|
/** @internal */
|
|
1962
2073
|
declare const getUsersKey: (instance: SanityInstance, {
|
|
1963
2074
|
resourceType,
|
|
@@ -2229,4 +2340,4 @@ declare const CORE_SDK_VERSION: {};
|
|
|
2229
2340
|
* @public
|
|
2230
2341
|
*/
|
|
2231
2342
|
type SanityProject = SanityProject$1;
|
|
2232
|
-
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 CanvasSource, type ClientOptions, type ClientStoreState as ClientState, type ComlinkControllerState, type ComlinkNodeState, type CreateDocumentAction, type CurrentUser, type DatasetHandle, type DatasetSource, 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 InstanceContext, type Intent, type IntentFilter, type JsonMatch, type LogContext, type LogLevel, type LogNamespace, type LoggedInAuthState, type LoggedOutAuthState, type Logger, type LoggerConfig, type LoggingInAuthState, type MediaLibrarySource, 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, configureLogging, createDatasetHandle, createDocument, createDocumentHandle, createDocumentTypeHandle, createGroqSearchFilter, createProjectHandle, createSanityInstance, 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, isCanvasSource, isDatasetSource, isMediaLibrarySource, isProjectUserNotFoundClientError, 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 };
|
|
2343
|
+
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 CanvasSource, type ClientOptions, type ClientStoreState as ClientState, type ComlinkControllerState, type ComlinkNodeState, type CreateDocumentAction, type CurrentUser, type DatasetHandle, type DatasetSource, 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 InstanceContext, type Intent, type IntentFilter, type JsonMatch, type LogContext, type LogLevel, type LogNamespace, type LoggedInAuthState, type LoggedOutAuthState, type Logger, type LoggerConfig, type LoggingInAuthState, type MediaLibrarySource, 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 StudioConfig, type TokenSource, 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, configureLogging, createDatasetHandle, createDocument, createDocumentHandle, createDocumentTypeHandle, createGroqSearchFilter, createProjectHandle, createSanityInstance, 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, isCanvasSource, isDatasetSource, isMediaLibrarySource, isProjectUserNotFoundClientError, isStudioConfig, 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 };
|