@sanity/sdk 2.4.0 → 2.6.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 (57) hide show
  1. package/dist/index.d.ts +346 -110
  2. package/dist/index.js +428 -136
  3. package/dist/index.js.map +1 -1
  4. package/package.json +10 -9
  5. package/src/_exports/index.ts +15 -3
  6. package/src/auth/authStore.test.ts +13 -13
  7. package/src/auth/refreshStampedToken.test.ts +16 -16
  8. package/src/auth/subscribeToStateAndFetchCurrentUser.test.ts +6 -6
  9. package/src/auth/subscribeToStorageEventsAndSetToken.test.ts +4 -4
  10. package/src/client/clientStore.test.ts +45 -43
  11. package/src/client/clientStore.ts +23 -9
  12. package/src/comlink/controller/actions/destroyController.test.ts +2 -2
  13. package/src/comlink/controller/actions/getOrCreateChannel.test.ts +6 -6
  14. package/src/comlink/controller/actions/getOrCreateController.test.ts +5 -5
  15. package/src/comlink/controller/actions/getOrCreateController.ts +1 -1
  16. package/src/comlink/controller/actions/releaseChannel.test.ts +3 -2
  17. package/src/comlink/controller/comlinkControllerStore.test.ts +4 -4
  18. package/src/comlink/node/actions/getOrCreateNode.test.ts +7 -7
  19. package/src/comlink/node/actions/releaseNode.test.ts +2 -2
  20. package/src/comlink/node/comlinkNodeStore.test.ts +4 -3
  21. package/src/config/loggingConfig.ts +149 -0
  22. package/src/config/sanityConfig.ts +47 -23
  23. package/src/document/actions.ts +11 -7
  24. package/src/document/applyDocumentActions.test.ts +9 -6
  25. package/src/document/applyDocumentActions.ts +9 -49
  26. package/src/document/documentStore.test.ts +128 -115
  27. package/src/document/documentStore.ts +40 -10
  28. package/src/document/permissions.test.ts +9 -9
  29. package/src/document/permissions.ts +17 -7
  30. package/src/document/processActions.test.ts +248 -0
  31. package/src/document/processActions.ts +173 -0
  32. package/src/document/reducers.ts +13 -6
  33. package/src/presence/presenceStore.ts +13 -7
  34. package/src/preview/previewStore.test.ts +10 -2
  35. package/src/preview/previewStore.ts +2 -1
  36. package/src/preview/subscribeToStateAndFetchBatches.test.ts +8 -5
  37. package/src/preview/subscribeToStateAndFetchBatches.ts +9 -3
  38. package/src/projection/projectionStore.test.ts +18 -2
  39. package/src/projection/projectionStore.ts +2 -1
  40. package/src/projection/subscribeToStateAndFetchBatches.test.ts +6 -5
  41. package/src/projection/subscribeToStateAndFetchBatches.ts +9 -3
  42. package/src/query/queryStore.ts +3 -1
  43. package/src/releases/getPerspectiveState.ts +2 -2
  44. package/src/releases/releasesStore.ts +10 -4
  45. package/src/store/createActionBinder.test.ts +8 -6
  46. package/src/store/createActionBinder.ts +54 -28
  47. package/src/store/createSanityInstance.test.ts +85 -1
  48. package/src/store/createSanityInstance.ts +53 -4
  49. package/src/store/createStateSourceAction.test.ts +12 -11
  50. package/src/store/createStateSourceAction.ts +6 -6
  51. package/src/store/createStoreInstance.test.ts +29 -16
  52. package/src/store/createStoreInstance.ts +6 -5
  53. package/src/store/defineStore.test.ts +1 -1
  54. package/src/store/defineStore.ts +12 -7
  55. package/src/utils/logger-usage-example.md +141 -0
  56. package/src/utils/logger.test.ts +757 -0
  57. package/src/utils/logger.ts +537 -0
package/dist/index.d.ts CHANGED
@@ -101,16 +101,32 @@ interface PerspectiveHandle {
101
101
  */
102
102
  interface DatasetHandle<TDataset extends string = string, TProjectId extends string = string> extends ProjectHandle<TProjectId>, PerspectiveHandle {
103
103
  dataset?: TDataset;
104
+ /**
105
+ * @beta
106
+ * The name of the source to use for this operation.
107
+ */
108
+ sourceName?: string;
109
+ /**
110
+ * @beta
111
+ * Explicit source object to use for this operation.
112
+ */
113
+ source?: DocumentSource;
104
114
  }
105
115
  /**
106
116
  * Identifies a specific document type within a Sanity dataset and project.
107
117
  * Includes `projectId`, `dataset`, and `documentType`.
108
- * Optionally includes a `documentId`, useful for referencing a specific document type context, potentially without a specific document ID.
118
+ * Optionally includes a `documentId` and `liveEdit` flag.
109
119
  * @public
110
120
  */
111
121
  interface DocumentTypeHandle<TDocumentType extends string = string, TDataset extends string = string, TProjectId extends string = string> extends DatasetHandle<TDataset, TProjectId> {
112
122
  documentId?: string;
113
123
  documentType: TDocumentType;
124
+ /**
125
+ * Indicates whether this document uses liveEdit mode.
126
+ * When `true`, the document does not use the draft/published model and edits are applied directly to the document.
127
+ * @see https://www.sanity.io/docs/content-lake/drafts#ca0663a8f002
128
+ */
129
+ liveEdit?: boolean;
114
130
  }
115
131
  /**
116
132
  * Uniquely identifies a specific document within a Sanity dataset and project.
@@ -138,40 +154,50 @@ interface SanityConfig extends DatasetHandle, PerspectiveHandle {
138
154
  studioMode?: {
139
155
  enabled: boolean;
140
156
  };
157
+ /**
158
+ * @beta
159
+ * A list of named sources to use for this instance.
160
+ */
161
+ sources?: Record<string, DocumentSource>;
141
162
  }
142
- declare const SOURCE_ID = "__sanity_internal_sourceId";
143
163
  /**
144
164
  * A document source can be used for querying.
165
+ * This will soon be the default way to identify where you are querying from.
145
166
  *
146
167
  * @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
- };
168
+ */
169
+ type DocumentSource = DatasetSource | MediaLibrarySource | CanvasSource;
170
+ /**
171
+ * @beta
172
+ */
173
+ type DatasetSource = {
174
+ projectId: string;
175
+ dataset: string;
156
176
  };
157
177
  /**
158
- * Returns a document source for a projectId and dataset.
159
- *
160
178
  * @beta
161
179
  */
162
- declare function datasetSource(projectId: string, dataset: string): DocumentSource;
180
+ type MediaLibrarySource = {
181
+ mediaLibraryId: string;
182
+ };
163
183
  /**
164
- * Returns a document source for a Media Library.
165
- *
166
184
  * @beta
167
185
  */
168
- declare function mediaLibrarySource(id: string): DocumentSource;
186
+ type CanvasSource = {
187
+ canvasId: string;
188
+ };
189
+ /**
190
+ * @beta
191
+ */
192
+ declare function isDatasetSource(source: DocumentSource): source is DatasetSource;
193
+ /**
194
+ * @beta
195
+ */
196
+ declare function isMediaLibrarySource(source: DocumentSource): source is MediaLibrarySource;
169
197
  /**
170
- * Returns a document source for a Canvas.
171
- *
172
198
  * @beta
173
199
  */
174
- declare function canvasSource(id: string): DocumentSource;
200
+ declare function isCanvasSource(source: DocumentSource): source is CanvasSource;
175
201
  /**
176
202
  * Represents a Sanity.io resource instance with its own configuration and lifecycle
177
203
  * @remarks Instances form a hierarchy through parent/child relationships
@@ -308,29 +334,6 @@ declare enum AuthStateType {
308
334
  * Represents a store action that has been bound to a specific store instance
309
335
  */
310
336
  type BoundStoreAction<_TState, TParams extends unknown[], TReturn> = (instance: SanityInstance, ...params: TParams) => TReturn;
311
- /**
312
- * Creates an action binder function that uses the provided key function
313
- * to determine how store instances are shared between Sanity instances
314
- *
315
- * @param keyFn - Function that generates a key from a Sanity config
316
- * @returns A function that binds store actions to Sanity instances
317
- *
318
- * @remarks
319
- * Action binders determine how store instances are shared across multiple
320
- * Sanity instances. The key function determines which instances share state.
321
- *
322
- * @example
323
- * ```ts
324
- * // Create a custom binder that uses a tenant ID for isolation
325
- * const bindActionByTenant = createActionBinder(config => config.tenantId || 'default')
326
- *
327
- * // Use the custom binder with a store definition
328
- * const getTenantUsers = bindActionByTenant(
329
- * userStore,
330
- * ({state}) => state.get().users
331
- * )
332
- * ```
333
- */
334
337
  /**
335
338
  * Represents the various states the authentication can be in.
336
339
  *
@@ -414,10 +417,6 @@ declare const getCurrentUserState: BoundStoreAction<AuthStoreState, [], StateSou
414
417
  * @public
415
418
  */
416
419
  declare const getTokenState: BoundStoreAction<AuthStoreState, [], StateSource<string | null>>;
417
- /**
418
- * @internal
419
- */
420
-
421
420
  /**
422
421
  * @public
423
422
  */
@@ -448,10 +447,6 @@ declare const setAuthToken: BoundStoreAction<AuthStoreState, [token: string | nu
448
447
  interface OrgVerificationResult {
449
448
  error: string | null;
450
449
  }
451
- /**
452
- * Compares a project's actual organization ID with the expected organization ID.
453
- * @public
454
- */
455
450
  /**
456
451
  * Creates an observable that emits the organization verification state for a given instance.
457
452
  * It combines the dashboard organization ID (from auth context) with the
@@ -700,6 +695,277 @@ declare function createProjectHandle<TProjectId extends string = string>(handle:
700
695
  * @public
701
696
  */
702
697
  declare function createDatasetHandle<TDataset extends string = string, TProjectId extends string = string>(handle: DatasetHandle<TDataset, TProjectId>): DatasetHandle<TDataset, TProjectId>;
698
+ /**
699
+ * Logging infrastructure for the Sanity SDK
700
+ *
701
+ * Provides multi-level, namespace-based logging for both SDK users and maintainers.
702
+ * In production builds, all logging can be stripped via tree-shaking.
703
+ *
704
+ * @example SDK User
705
+ * ```ts
706
+ * import {configureLogging} from '@sanity/sdk'
707
+ *
708
+ * configureLogging({
709
+ * level: 'info',
710
+ * namespaces: ['auth', 'document']
711
+ * })
712
+ * ```
713
+ *
714
+ * @example SDK Maintainer
715
+ * ```ts
716
+ * configureLogging({
717
+ * level: 'trace',
718
+ * namespaces: ['*'],
719
+ * internal: true
720
+ * })
721
+ * ```
722
+ */
723
+ /**
724
+ * Log levels in order of verbosity (least to most)
725
+ * - error: Critical failures that prevent operation
726
+ * - warn: Issues that may cause problems but don't stop execution
727
+ * - info: High-level informational messages (SDK user level)
728
+ * - debug: Detailed debugging information (maintainer level)
729
+ * - trace: Very detailed tracing (maintainer level, includes RxJS streams)
730
+ * @public
731
+ */
732
+ type LogLevel = 'error' | 'warn' | 'info' | 'debug' | 'trace';
733
+ /**
734
+ * Log namespaces organize logs by functional domain
735
+ *
736
+ * @remarks
737
+ * This is an extensible string type. As logging is added to more modules,
738
+ * additional namespaces will be recognized. Currently implemented namespaces
739
+ * will be documented as they are added.
740
+ * @internal
741
+ */
742
+ type LogNamespace = string;
743
+ /**
744
+ * Configuration for the logging system
745
+ * @public
746
+ */
747
+ interface LoggerConfig {
748
+ /**
749
+ * Minimum log level to output
750
+ * @defaultValue 'warn'
751
+ */
752
+ level?: LogLevel;
753
+ /**
754
+ * Namespaces to enable. Use ['*'] for all namespaces
755
+ * @defaultValue []
756
+ * @remarks
757
+ * Available namespaces depend on which modules have logging integrated.
758
+ * Check the SDK documentation for the current list of instrumented modules.
759
+ * @example ['auth', 'document']
760
+ */
761
+ namespaces?: string[];
762
+ /**
763
+ * Enable internal/maintainer-level logging
764
+ * Shows RxJS streams, store internals, etc.
765
+ * @defaultValue false
766
+ */
767
+ internal?: boolean;
768
+ /**
769
+ * Custom log handler (for testing or custom output)
770
+ * @defaultValue console methods
771
+ */
772
+ handler?: LogHandler;
773
+ /**
774
+ * Enable timestamps in log output
775
+ * @defaultValue true
776
+ */
777
+ timestamps?: boolean;
778
+ /**
779
+ * Enable in production builds
780
+ * @defaultValue false
781
+ */
782
+ enableInProduction?: boolean;
783
+ }
784
+ /**
785
+ * Custom log handler interface
786
+ *
787
+ * @internal
788
+ */
789
+ interface LogHandler {
790
+ error: (message: string, context?: LogContext) => void;
791
+ warn: (message: string, context?: LogContext) => void;
792
+ info: (message: string, context?: LogContext) => void;
793
+ debug: (message: string, context?: LogContext) => void;
794
+ trace: (message: string, context?: LogContext) => void;
795
+ }
796
+ /**
797
+ * Context object attached to log messages
798
+ *
799
+ * This interface allows you to attach arbitrary contextual data to log messages.
800
+ * The index signature `[key: string]: unknown` enables you to add any custom
801
+ * properties relevant to your log entry (e.g., `userId`, `documentId`, `action`, etc.).
802
+ *
803
+ * **Sensitive data sanitization:**
804
+ * Top-level keys containing sensitive names (`token`, `password`, `secret`, `apiKey`,
805
+ * `authorization`) are automatically redacted to `[REDACTED]` in log output.
806
+ *
807
+ * @example
808
+ * ```ts
809
+ * logger.info('User logged in', {
810
+ * userId: '123', // Custom context
811
+ * action: 'login', // Custom context
812
+ * token: 'secret' // Will be redacted to [REDACTED]
813
+ * })
814
+ * ```
815
+ *
816
+ * @internal
817
+ */
818
+ interface LogContext {
819
+ /**
820
+ * Custom context properties that provide additional information about the log entry.
821
+ * Any key-value pairs can be added here (e.g., userId, documentId, requestId, etc.).
822
+ * Keys with sensitive names (token, password, secret, apiKey, authorization) are
823
+ * automatically sanitized.
824
+ */
825
+ [key: string]: unknown;
826
+ /** Error object if logging an error */
827
+ error?: Error | unknown;
828
+ /** Duration in milliseconds for timed operations */
829
+ duration?: number;
830
+ /** Stack trace for debugging */
831
+ stack?: string;
832
+ /** Instance context (automatically added when available) */
833
+ instanceContext?: InstanceContext;
834
+ }
835
+ /**
836
+ * Instance context information automatically added to logs
837
+ * @internal
838
+ */
839
+ interface InstanceContext {
840
+ /** Unique instance ID */
841
+ instanceId?: string;
842
+ /** Project ID */
843
+ projectId?: string;
844
+ /** Dataset name */
845
+ dataset?: string;
846
+ }
847
+ /**
848
+ * Logger instance for a specific namespace
849
+ * @internal
850
+ */
851
+ interface Logger {
852
+ readonly namespace: string;
853
+ error: (message: string, context?: LogContext) => void;
854
+ warn: (message: string, context?: LogContext) => void;
855
+ info: (message: string, context?: LogContext) => void;
856
+ debug: (message: string, context?: LogContext) => void;
857
+ trace: (message: string, context?: LogContext) => void;
858
+ /** Check if a log level is enabled (for performance-sensitive code) */
859
+ isLevelEnabled: (level: LogLevel) => boolean;
860
+ /** Create a child logger with extended context */
861
+ child: (context: LogContext) => Logger;
862
+ /** Get the instance context if available */
863
+ getInstanceContext: () => InstanceContext | undefined;
864
+ }
865
+ /**
866
+ * Configure logging for the Sanity SDK
867
+ *
868
+ * This function allows you to control what logs are output by the SDK,
869
+ * making it easier to debug issues in development or production.
870
+ *
871
+ * @remarks
872
+ * **Zero-Config via Environment Variable (Recommended):**
873
+ *
874
+ * The SDK automatically reads the `DEBUG` environment variable, making it
875
+ * easy to enable logging without code changes:
876
+ *
877
+ * ```bash
878
+ * # Enable all SDK logging at debug level
879
+ * DEBUG=sanity:* npm start
880
+ *
881
+ * # Enable specific namespaces
882
+ * DEBUG=sanity:auth,sanity:document npm start
883
+ *
884
+ * # Enable trace level for all namespaces
885
+ * DEBUG=sanity:trace:* npm start
886
+ *
887
+ * # Enable internal/maintainer logs
888
+ * DEBUG=sanity:*:internal npm start
889
+ * ```
890
+ *
891
+ * This matches the pattern used by Sanity CLI and Studio, making it familiar
892
+ * and easy for support teams to help troubleshoot issues.
893
+ *
894
+ * **Programmatic Configuration (Advanced):**
895
+ *
896
+ * For more control (custom handlers, dynamic configuration), call this function
897
+ * explicitly. Programmatic configuration overrides environment variables.
898
+ *
899
+ * **For Application Developers:**
900
+ * Use `info`, `warn`, or `error` levels to see high-level SDK activity
901
+ * without being overwhelmed by internal details.
902
+ *
903
+ * **For SDK Maintainers:**
904
+ * Use `debug` or `trace` levels with `internal: true` to see detailed
905
+ * information about store operations, RxJS streams, and state transitions.
906
+ *
907
+ * **Instance Context:**
908
+ * Logs automatically include instance information (projectId, dataset, instanceId)
909
+ * when available, making it easier to debug multi-instance scenarios:
910
+ * ```
911
+ * [INFO] [auth] [project:abc] [dataset:production] User logged in
912
+ * ```
913
+ *
914
+ * **Available Namespaces:**
915
+ * - `sdk` - SDK initialization, configuration, and lifecycle
916
+ * - `auth` - Authentication and authorization (when instrumented in the future)
917
+ * - And more as logging is added to modules
918
+ *
919
+ * @example Zero-config via environment variable (recommended for debugging)
920
+ * ```bash
921
+ * # Just set DEBUG and run your app - no code changes needed!
922
+ * DEBUG=sanity:* npm start
923
+ * ```
924
+ *
925
+ * @example Programmatic configuration (application developer)
926
+ * ```ts
927
+ * import {configureLogging} from '@sanity/sdk'
928
+ *
929
+ * // Log warnings and errors for auth and document operations
930
+ * configureLogging({
931
+ * level: 'warn',
932
+ * namespaces: ['auth', 'document']
933
+ * })
934
+ * ```
935
+ *
936
+ * @example Programmatic configuration (SDK maintainer)
937
+ * ```ts
938
+ * import {configureLogging} from '@sanity/sdk'
939
+ *
940
+ * // Enable all logs including internal traces
941
+ * configureLogging({
942
+ * level: 'trace',
943
+ * namespaces: ['*'],
944
+ * internal: true
945
+ * })
946
+ * ```
947
+ *
948
+ * @example Custom handler (for testing)
949
+ * ```ts
950
+ * import {configureLogging} from '@sanity/sdk'
951
+ *
952
+ * const logs: string[] = []
953
+ * configureLogging({
954
+ * level: 'info',
955
+ * namespaces: ['*'],
956
+ * handler: {
957
+ * error: (msg) => logs.push(msg),
958
+ * warn: (msg) => logs.push(msg),
959
+ * info: (msg) => logs.push(msg),
960
+ * debug: (msg) => logs.push(msg),
961
+ * trace: (msg) => logs.push(msg),
962
+ * }
963
+ * })
964
+ * ```
965
+ *
966
+ * @public
967
+ */
968
+ declare function configureLogging(config: LoggerConfig): void;
703
969
  /** @public */
704
970
  declare const getDatasetsState: BoundStoreAction<FetcherStoreState<[options?: ProjectHandle<string> | undefined], _sanity_client12.DatasetsResponse>, [options?: ProjectHandle<string> | undefined], StateSource<_sanity_client12.DatasetsResponse | undefined>>;
705
971
  /** @public */
@@ -826,21 +1092,6 @@ declare function discardDocument<TDocumentType extends string = string, TDataset
826
1092
  * Documents that don't exist have a `null` value.
827
1093
  */
828
1094
  type DocumentSet<TDocument extends SanityDocument$2 = SanityDocument$2> = { [TDocumentId in string]?: TDocument | null };
829
- /**
830
- * Implements ID generation:
831
- *
832
- * A create mutation creates a new document. It takes the literal document
833
- * content as its argument. The rules for the new document's identifier are as
834
- * follows:
835
- *
836
- * - If the `_id` attribute is missing, then a new, random, unique ID is
837
- * generated.
838
- * - If the `_id` attribute is present but ends with `.`, then it is used as a
839
- * prefix for a new, random, unique ID.
840
- * - If the _id attribute is present, it is used as-is.
841
- *
842
- * [- source](https://www.sanity.io/docs/http-mutations#c732f27330a4)
843
- */
844
1095
  /** @beta */
845
1096
  interface ActionsResult<TDocument extends SanityDocument$3 = SanityDocument$3> {
846
1097
  transactionId: string;
@@ -856,6 +1107,10 @@ interface ActionsResult<TDocument extends SanityDocument$3 = SanityDocument$3> {
856
1107
  }
857
1108
  /** @beta */
858
1109
  interface ApplyDocumentActionsOptions {
1110
+ /**
1111
+ * List of actions to apply.
1112
+ */
1113
+ actions: DocumentAction[];
859
1114
  /**
860
1115
  * Optionally provide an ID to be used as this transaction ID
861
1116
  */
@@ -866,9 +1121,9 @@ interface ApplyDocumentActionsOptions {
866
1121
  disableBatching?: boolean;
867
1122
  }
868
1123
  /** @beta */
869
- declare function applyDocumentActions<TDocumentType extends string = string, TDataset extends string = string, TProjectId extends string = string>(instance: SanityInstance, action: DocumentAction<TDocumentType, TDataset, TProjectId> | DocumentAction<TDocumentType, TDataset, TProjectId>[], options?: ApplyDocumentActionsOptions): Promise<ActionsResult<SanityDocument$3<TDocumentType, `${TProjectId}.${TDataset}`>>>;
1124
+ declare function applyDocumentActions<TDocumentType extends string = string, TDataset extends string = string, TProjectId extends string = string>(instance: SanityInstance, options: ApplyDocumentActionsOptions): Promise<ActionsResult<SanityDocument$3<TDocumentType, `${TProjectId}.${TDataset}`>>>;
870
1125
  /** @beta */
871
- declare function applyDocumentActions(instance: SanityInstance, action: DocumentAction | DocumentAction[], options?: ApplyDocumentActionsOptions): Promise<ActionsResult>;
1126
+ declare function applyDocumentActions(instance: SanityInstance, options: ApplyDocumentActionsOptions): Promise<ActionsResult>;
872
1127
  /**
873
1128
  * Represents a reactive state source that provides synchronized access to store data
874
1129
  *
@@ -942,11 +1197,9 @@ interface SelectorContext<TState> {
942
1197
  * @public
943
1198
  */
944
1199
  type Selector<TState, TParams extends unknown[], TReturn> = (context: SelectorContext<TState>, ...params: TParams) => TReturn;
945
- /**
946
- * Configuration options for creating a state source action
947
- */
948
1200
  type ActionMap = {
949
1201
  create: 'sanity.action.document.version.create';
1202
+ createLiveEdit: 'sanity.action.document.create';
950
1203
  discard: 'sanity.action.document.version.discard';
951
1204
  unpublish: 'sanity.action.document.unpublish';
952
1205
  delete: 'sanity.action.document.delete';
@@ -961,6 +1214,10 @@ type HttpAction = {
961
1214
  actionType: ActionMap['create'];
962
1215
  publishedId: string;
963
1216
  attributes: SanityDocumentLike;
1217
+ } | {
1218
+ actionType: ActionMap['createLiveEdit'];
1219
+ publishedId: string;
1220
+ attributes: SanityDocumentLike;
964
1221
  } | {
965
1222
  actionType: ActionMap['discard'];
966
1223
  versionId: string;
@@ -1218,11 +1475,6 @@ TTail extends readonly (string | number)[] ? TTail : []> : never;
1218
1475
  * @beta
1219
1476
  */
1220
1477
  type JsonMatch<TDocument, TPath extends string> = DeepGet<TDocument, PathParts<TPath>>;
1221
- /**
1222
- * Recursively traverse a value. When an array is encountered, ensure that
1223
- * each object item has a _key property. Memoized such that sub-objects that
1224
- * have not changed aren't re-computed.
1225
- */
1226
1478
  interface SharedListener {
1227
1479
  events: Observable<ListenEvent<SanityDocument$1>>;
1228
1480
  dispose: () => void;
@@ -1291,10 +1543,13 @@ declare function resolveDocument<TDocumentType extends string = string, TDataset
1291
1543
  declare function resolveDocument<TData extends SanityDocument$3>(instance: SanityInstance, docHandle: DocumentHandle<string, string, string>): Promise<TData | null>;
1292
1544
  /** @beta */
1293
1545
  declare const getDocumentSyncStatus: BoundStoreAction<DocumentStoreState, [doc: DocumentHandle<string, string, string>], StateSource<boolean | undefined>>;
1546
+ type PermissionsStateOptions = {
1547
+ actions: DocumentAction[];
1548
+ };
1294
1549
  /** @beta */
1295
- declare const getPermissionsState: BoundStoreAction<DocumentStoreState, [DocumentAction | DocumentAction[]], StateSource<DocumentPermissionsResult | undefined>>;
1550
+ declare const getPermissionsState: BoundStoreAction<DocumentStoreState, [PermissionsStateOptions], StateSource<DocumentPermissionsResult | undefined>>;
1296
1551
  /** @beta */
1297
- declare const resolvePermissions: BoundStoreAction<DocumentStoreState, [actions: DocumentAction | DocumentAction[]], Promise<DocumentPermissionsResult>>;
1552
+ declare const resolvePermissions: BoundStoreAction<DocumentStoreState, [options: PermissionsStateOptions], Promise<DocumentPermissionsResult>>;
1298
1553
  /** @beta */
1299
1554
  declare const subscribeDocumentEvents: BoundStoreAction<DocumentStoreState, [eventHandler: (e: DocumentEvent) => void], () => void>;
1300
1555
  /**
@@ -1431,8 +1686,6 @@ interface UserPresence {
1431
1686
  locations: PresenceLocation[];
1432
1687
  sessionId: string;
1433
1688
  }
1434
- /** @public */
1435
-
1436
1689
  /** @public */
1437
1690
  type TransportEvent = RollCallEvent | StateEvent | DisconnectEvent;
1438
1691
  /** @public */
@@ -1456,7 +1709,6 @@ interface DisconnectEvent {
1456
1709
  sessionId: string;
1457
1710
  timestamp: string;
1458
1711
  }
1459
- /** @public */
1460
1712
  type PresenceStoreState = {
1461
1713
  locations: Map<string, {
1462
1714
  userId: string;
@@ -1467,7 +1719,10 @@ type PresenceStoreState = {
1467
1719
  /** @public */
1468
1720
 
1469
1721
  /** @public */
1470
- declare const getPresence: BoundStoreAction<PresenceStoreState, [], StateSource<UserPresence[]>>;
1722
+ declare const getPresence: BoundStoreAction<PresenceStoreState, [((object & {
1723
+ projectId?: string;
1724
+ dataset?: string;
1725
+ }) | undefined)?, ...unknown[]], StateSource<UserPresence[]>>;
1471
1726
  /**
1472
1727
  * Represents a media asset in a preview.
1473
1728
  *
@@ -1542,9 +1797,6 @@ declare function getPreviewState<TResult extends object>(instance: SanityInstanc
1542
1797
  * @beta
1543
1798
  */
1544
1799
  declare function getPreviewState(instance: SanityInstance, options: GetPreviewStateOptions): StateSource<ValuePending<PreviewValue>>;
1545
- /**
1546
- * @beta
1547
- */
1548
1800
  /**
1549
1801
  * @beta
1550
1802
  */
@@ -1587,9 +1839,6 @@ declare function getProjectionState<TData extends object>(instance: SanityInstan
1587
1839
  * @beta
1588
1840
  */
1589
1841
  declare function getProjectionState(instance: SanityInstance, options: ProjectionOptions): StateSource<ProjectionValuePending<Record<string, unknown>> | undefined>;
1590
- /**
1591
- * @beta
1592
- */
1593
1842
  /** @beta */
1594
1843
  declare function resolveProjection<TProjection extends string = string, TDocumentType extends string = string, TDataset extends string = string, TProjectId extends string = string>(instance: SanityInstance, options: ProjectionOptions<TProjection, TDocumentType, TDataset, TProjectId>): Promise<ProjectionValuePending<SanityProjectionResult<TProjection, TDocumentType, `${TProjectId}.${TDataset}`>>>;
1595
1844
  /** @beta */
@@ -1689,7 +1938,10 @@ interface ReleasesStoreState {
1689
1938
  * Get the active releases from the store.
1690
1939
  * @internal
1691
1940
  */
1692
- declare const getActiveReleasesState: BoundStoreAction<ReleasesStoreState, [], StateSource<ReleaseDocument[] | undefined>>;
1941
+ declare const getActiveReleasesState: BoundStoreAction<ReleasesStoreState, [((object & {
1942
+ projectId?: string;
1943
+ dataset?: string;
1944
+ }) | undefined)?, ...unknown[]], StateSource<ReleaseDocument[] | undefined>>;
1693
1945
  /**
1694
1946
  * Provides a subscribable state source for a "perspective" for the Sanity client,
1695
1947
  * which is used to fetch documents as though certain Content Releases are active.
@@ -1702,7 +1954,10 @@ declare const getActiveReleasesState: BoundStoreAction<ReleasesStoreState, [], S
1702
1954
  *
1703
1955
  * @public
1704
1956
  */
1705
- declare const getPerspectiveState: BoundStoreAction<ReleasesStoreState, [options?: PerspectiveHandle | undefined], StateSource<string[] | "raw" | "previewDrafts" | "published" | "drafts" | undefined>>;
1957
+ declare const getPerspectiveState: BoundStoreAction<ReleasesStoreState, [_?: (PerspectiveHandle & {
1958
+ projectId?: string;
1959
+ dataset?: string;
1960
+ }) | undefined], StateSource<string[] | "raw" | "previewDrafts" | "published" | "drafts" | undefined>>;
1706
1961
  /** @internal */
1707
1962
  declare const getUsersKey: (instance: SanityInstance, {
1708
1963
  resourceType,
@@ -1807,25 +2062,6 @@ interface FetcherStore<TParams extends unknown[], TData> {
1807
2062
  getState: BoundStoreAction<FetcherStoreState<TParams, TData>, TParams, StateSource<TData | undefined>>;
1808
2063
  resolveState: BoundStoreAction<FetcherStoreState<TParams, TData>, TParams, Promise<TData>>;
1809
2064
  }
1810
- /**
1811
- * Creates a store from a function that returns an observable that fetches data
1812
- * that supports parameterized state caching.
1813
- *
1814
- * This function creates a resource store keyed by parameter values (using the
1815
- * provided `getKey` function) and returns a state source (via `getState`)
1816
- * that components can subscribe to. When a new subscription is added, and if
1817
- * enough time has passed since the last fetch (controlled by
1818
- * `fetchThrottleInternal`), it invokes the observable factory (via
1819
- * `getObservable`) to fetch fresh data. The data is stored in state and can be
1820
- * accessed reactively.
1821
- *
1822
- * Additionally, the store provides a `resolveState` function that returns a
1823
- * Promise resolving with the next non-undefined value from the state source.
1824
- *
1825
- * State expiration is implemented: after the last subscription for a key is
1826
- * removed, its state is cleared after `stateExpirationDelay` ms, causing
1827
- * components to suspend until fresh data is fetched.
1828
- */
1829
2065
  /**
1830
2066
  * Creates a GROQ search filter string (`[@] match text::query("...")`)
1831
2067
  * from a raw search query string.
@@ -1993,4 +2229,4 @@ declare const CORE_SDK_VERSION: {};
1993
2229
  * @public
1994
2230
  */
1995
2231
  type SanityProject = SanityProject$1;
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 };
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 };