@sanity/sdk 2.5.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 +429 -27
- package/dist/index.js +657 -266
- package/dist/index.js.map +1 -1
- package/package.json +4 -3
- package/src/_exports/index.ts +18 -3
- 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/client/clientStore.test.ts +45 -43
- package/src/client/clientStore.ts +23 -9
- package/src/config/loggingConfig.ts +149 -0
- package/src/config/sanityConfig.ts +82 -22
- 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 +33 -11
- 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 +102 -13
- package/src/store/createSanityInstance.test.ts +85 -1
- package/src/store/createSanityInstance.ts +55 -4
- package/src/utils/logger-usage-example.md +141 -0
- package/src/utils/logger.test.ts +757 -0
- package/src/utils/logger.ts +537 -0
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,6 +137,11 @@ interface PerspectiveHandle {
|
|
|
101
137
|
*/
|
|
102
138
|
interface DatasetHandle<TDataset extends string = string, TProjectId extends string = string> extends ProjectHandle<TProjectId>, PerspectiveHandle {
|
|
103
139
|
dataset?: TDataset;
|
|
140
|
+
/**
|
|
141
|
+
* @beta
|
|
142
|
+
* Explicit source object to use for this operation.
|
|
143
|
+
*/
|
|
144
|
+
source?: DocumentSource;
|
|
104
145
|
}
|
|
105
146
|
/**
|
|
106
147
|
* Identifies a specific document type within a Sanity dataset and project.
|
|
@@ -138,46 +179,67 @@ interface SanityConfig extends DatasetHandle, PerspectiveHandle {
|
|
|
138
179
|
*/
|
|
139
180
|
auth?: AuthConfig;
|
|
140
181
|
/**
|
|
141
|
-
* Studio
|
|
142
|
-
*
|
|
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.).
|
|
143
195
|
*/
|
|
144
196
|
studioMode?: {
|
|
145
197
|
enabled: boolean;
|
|
146
198
|
};
|
|
199
|
+
/**
|
|
200
|
+
* @beta
|
|
201
|
+
* A list of named sources to use for this instance.
|
|
202
|
+
*/
|
|
203
|
+
sources?: Record<string, DocumentSource>;
|
|
147
204
|
}
|
|
148
|
-
declare const SOURCE_ID = "__sanity_internal_sourceId";
|
|
149
205
|
/**
|
|
150
206
|
* A document source can be used for querying.
|
|
207
|
+
* This will soon be the default way to identify where you are querying from.
|
|
151
208
|
*
|
|
152
209
|
* @beta
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
};
|
|
210
|
+
*/
|
|
211
|
+
type DocumentSource = DatasetSource | MediaLibrarySource | CanvasSource;
|
|
212
|
+
/**
|
|
213
|
+
* @beta
|
|
214
|
+
*/
|
|
215
|
+
type DatasetSource = {
|
|
216
|
+
projectId: string;
|
|
217
|
+
dataset: string;
|
|
162
218
|
};
|
|
163
219
|
/**
|
|
164
|
-
* Returns a document source for a projectId and dataset.
|
|
165
|
-
*
|
|
166
220
|
* @beta
|
|
167
221
|
*/
|
|
168
|
-
|
|
222
|
+
type MediaLibrarySource = {
|
|
223
|
+
mediaLibraryId: string;
|
|
224
|
+
};
|
|
169
225
|
/**
|
|
170
|
-
* Returns a document source for a Media Library.
|
|
171
|
-
*
|
|
172
226
|
* @beta
|
|
173
227
|
*/
|
|
174
|
-
|
|
228
|
+
type CanvasSource = {
|
|
229
|
+
canvasId: string;
|
|
230
|
+
};
|
|
231
|
+
/**
|
|
232
|
+
* @beta
|
|
233
|
+
*/
|
|
234
|
+
declare function isDatasetSource(source: DocumentSource): source is DatasetSource;
|
|
235
|
+
/**
|
|
236
|
+
* @beta
|
|
237
|
+
*/
|
|
238
|
+
declare function isMediaLibrarySource(source: DocumentSource): source is MediaLibrarySource;
|
|
175
239
|
/**
|
|
176
|
-
* Returns a document source for a Canvas.
|
|
177
|
-
*
|
|
178
240
|
* @beta
|
|
179
241
|
*/
|
|
180
|
-
declare function
|
|
242
|
+
declare function isCanvasSource(source: DocumentSource): source is CanvasSource;
|
|
181
243
|
/**
|
|
182
244
|
* Represents a Sanity.io resource instance with its own configuration and lifecycle
|
|
183
245
|
* @remarks Instances form a hierarchy through parent/child relationships
|
|
@@ -299,6 +361,14 @@ declare function agentPrompt(instance: SanityInstance, options: AgentPromptOptio
|
|
|
299
361
|
* @alpha
|
|
300
362
|
*/
|
|
301
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;
|
|
302
372
|
/**
|
|
303
373
|
* Represents the various states the authentication type can be in.
|
|
304
374
|
*
|
|
@@ -310,6 +380,64 @@ declare enum AuthStateType {
|
|
|
310
380
|
ERROR = "error",
|
|
311
381
|
LOGGED_OUT = "logged-out",
|
|
312
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;
|
|
313
441
|
/**
|
|
314
442
|
* Represents a store action that has been bound to a specific store instance
|
|
315
443
|
*/
|
|
@@ -675,6 +803,277 @@ declare function createProjectHandle<TProjectId extends string = string>(handle:
|
|
|
675
803
|
* @public
|
|
676
804
|
*/
|
|
677
805
|
declare function createDatasetHandle<TDataset extends string = string, TProjectId extends string = string>(handle: DatasetHandle<TDataset, TProjectId>): DatasetHandle<TDataset, TProjectId>;
|
|
806
|
+
/**
|
|
807
|
+
* Logging infrastructure for the Sanity SDK
|
|
808
|
+
*
|
|
809
|
+
* Provides multi-level, namespace-based logging for both SDK users and maintainers.
|
|
810
|
+
* In production builds, all logging can be stripped via tree-shaking.
|
|
811
|
+
*
|
|
812
|
+
* @example SDK User
|
|
813
|
+
* ```ts
|
|
814
|
+
* import {configureLogging} from '@sanity/sdk'
|
|
815
|
+
*
|
|
816
|
+
* configureLogging({
|
|
817
|
+
* level: 'info',
|
|
818
|
+
* namespaces: ['auth', 'document']
|
|
819
|
+
* })
|
|
820
|
+
* ```
|
|
821
|
+
*
|
|
822
|
+
* @example SDK Maintainer
|
|
823
|
+
* ```ts
|
|
824
|
+
* configureLogging({
|
|
825
|
+
* level: 'trace',
|
|
826
|
+
* namespaces: ['*'],
|
|
827
|
+
* internal: true
|
|
828
|
+
* })
|
|
829
|
+
* ```
|
|
830
|
+
*/
|
|
831
|
+
/**
|
|
832
|
+
* Log levels in order of verbosity (least to most)
|
|
833
|
+
* - error: Critical failures that prevent operation
|
|
834
|
+
* - warn: Issues that may cause problems but don't stop execution
|
|
835
|
+
* - info: High-level informational messages (SDK user level)
|
|
836
|
+
* - debug: Detailed debugging information (maintainer level)
|
|
837
|
+
* - trace: Very detailed tracing (maintainer level, includes RxJS streams)
|
|
838
|
+
* @public
|
|
839
|
+
*/
|
|
840
|
+
type LogLevel = 'error' | 'warn' | 'info' | 'debug' | 'trace';
|
|
841
|
+
/**
|
|
842
|
+
* Log namespaces organize logs by functional domain
|
|
843
|
+
*
|
|
844
|
+
* @remarks
|
|
845
|
+
* This is an extensible string type. As logging is added to more modules,
|
|
846
|
+
* additional namespaces will be recognized. Currently implemented namespaces
|
|
847
|
+
* will be documented as they are added.
|
|
848
|
+
* @internal
|
|
849
|
+
*/
|
|
850
|
+
type LogNamespace = string;
|
|
851
|
+
/**
|
|
852
|
+
* Configuration for the logging system
|
|
853
|
+
* @public
|
|
854
|
+
*/
|
|
855
|
+
interface LoggerConfig {
|
|
856
|
+
/**
|
|
857
|
+
* Minimum log level to output
|
|
858
|
+
* @defaultValue 'warn'
|
|
859
|
+
*/
|
|
860
|
+
level?: LogLevel;
|
|
861
|
+
/**
|
|
862
|
+
* Namespaces to enable. Use ['*'] for all namespaces
|
|
863
|
+
* @defaultValue []
|
|
864
|
+
* @remarks
|
|
865
|
+
* Available namespaces depend on which modules have logging integrated.
|
|
866
|
+
* Check the SDK documentation for the current list of instrumented modules.
|
|
867
|
+
* @example ['auth', 'document']
|
|
868
|
+
*/
|
|
869
|
+
namespaces?: string[];
|
|
870
|
+
/**
|
|
871
|
+
* Enable internal/maintainer-level logging
|
|
872
|
+
* Shows RxJS streams, store internals, etc.
|
|
873
|
+
* @defaultValue false
|
|
874
|
+
*/
|
|
875
|
+
internal?: boolean;
|
|
876
|
+
/**
|
|
877
|
+
* Custom log handler (for testing or custom output)
|
|
878
|
+
* @defaultValue console methods
|
|
879
|
+
*/
|
|
880
|
+
handler?: LogHandler;
|
|
881
|
+
/**
|
|
882
|
+
* Enable timestamps in log output
|
|
883
|
+
* @defaultValue true
|
|
884
|
+
*/
|
|
885
|
+
timestamps?: boolean;
|
|
886
|
+
/**
|
|
887
|
+
* Enable in production builds
|
|
888
|
+
* @defaultValue false
|
|
889
|
+
*/
|
|
890
|
+
enableInProduction?: boolean;
|
|
891
|
+
}
|
|
892
|
+
/**
|
|
893
|
+
* Custom log handler interface
|
|
894
|
+
*
|
|
895
|
+
* @internal
|
|
896
|
+
*/
|
|
897
|
+
interface LogHandler {
|
|
898
|
+
error: (message: string, context?: LogContext) => void;
|
|
899
|
+
warn: (message: string, context?: LogContext) => void;
|
|
900
|
+
info: (message: string, context?: LogContext) => void;
|
|
901
|
+
debug: (message: string, context?: LogContext) => void;
|
|
902
|
+
trace: (message: string, context?: LogContext) => void;
|
|
903
|
+
}
|
|
904
|
+
/**
|
|
905
|
+
* Context object attached to log messages
|
|
906
|
+
*
|
|
907
|
+
* This interface allows you to attach arbitrary contextual data to log messages.
|
|
908
|
+
* The index signature `[key: string]: unknown` enables you to add any custom
|
|
909
|
+
* properties relevant to your log entry (e.g., `userId`, `documentId`, `action`, etc.).
|
|
910
|
+
*
|
|
911
|
+
* **Sensitive data sanitization:**
|
|
912
|
+
* Top-level keys containing sensitive names (`token`, `password`, `secret`, `apiKey`,
|
|
913
|
+
* `authorization`) are automatically redacted to `[REDACTED]` in log output.
|
|
914
|
+
*
|
|
915
|
+
* @example
|
|
916
|
+
* ```ts
|
|
917
|
+
* logger.info('User logged in', {
|
|
918
|
+
* userId: '123', // Custom context
|
|
919
|
+
* action: 'login', // Custom context
|
|
920
|
+
* token: 'secret' // Will be redacted to [REDACTED]
|
|
921
|
+
* })
|
|
922
|
+
* ```
|
|
923
|
+
*
|
|
924
|
+
* @internal
|
|
925
|
+
*/
|
|
926
|
+
interface LogContext {
|
|
927
|
+
/**
|
|
928
|
+
* Custom context properties that provide additional information about the log entry.
|
|
929
|
+
* Any key-value pairs can be added here (e.g., userId, documentId, requestId, etc.).
|
|
930
|
+
* Keys with sensitive names (token, password, secret, apiKey, authorization) are
|
|
931
|
+
* automatically sanitized.
|
|
932
|
+
*/
|
|
933
|
+
[key: string]: unknown;
|
|
934
|
+
/** Error object if logging an error */
|
|
935
|
+
error?: Error | unknown;
|
|
936
|
+
/** Duration in milliseconds for timed operations */
|
|
937
|
+
duration?: number;
|
|
938
|
+
/** Stack trace for debugging */
|
|
939
|
+
stack?: string;
|
|
940
|
+
/** Instance context (automatically added when available) */
|
|
941
|
+
instanceContext?: InstanceContext;
|
|
942
|
+
}
|
|
943
|
+
/**
|
|
944
|
+
* Instance context information automatically added to logs
|
|
945
|
+
* @internal
|
|
946
|
+
*/
|
|
947
|
+
interface InstanceContext {
|
|
948
|
+
/** Unique instance ID */
|
|
949
|
+
instanceId?: string;
|
|
950
|
+
/** Project ID */
|
|
951
|
+
projectId?: string;
|
|
952
|
+
/** Dataset name */
|
|
953
|
+
dataset?: string;
|
|
954
|
+
}
|
|
955
|
+
/**
|
|
956
|
+
* Logger instance for a specific namespace
|
|
957
|
+
* @internal
|
|
958
|
+
*/
|
|
959
|
+
interface Logger {
|
|
960
|
+
readonly namespace: string;
|
|
961
|
+
error: (message: string, context?: LogContext) => void;
|
|
962
|
+
warn: (message: string, context?: LogContext) => void;
|
|
963
|
+
info: (message: string, context?: LogContext) => void;
|
|
964
|
+
debug: (message: string, context?: LogContext) => void;
|
|
965
|
+
trace: (message: string, context?: LogContext) => void;
|
|
966
|
+
/** Check if a log level is enabled (for performance-sensitive code) */
|
|
967
|
+
isLevelEnabled: (level: LogLevel) => boolean;
|
|
968
|
+
/** Create a child logger with extended context */
|
|
969
|
+
child: (context: LogContext) => Logger;
|
|
970
|
+
/** Get the instance context if available */
|
|
971
|
+
getInstanceContext: () => InstanceContext | undefined;
|
|
972
|
+
}
|
|
973
|
+
/**
|
|
974
|
+
* Configure logging for the Sanity SDK
|
|
975
|
+
*
|
|
976
|
+
* This function allows you to control what logs are output by the SDK,
|
|
977
|
+
* making it easier to debug issues in development or production.
|
|
978
|
+
*
|
|
979
|
+
* @remarks
|
|
980
|
+
* **Zero-Config via Environment Variable (Recommended):**
|
|
981
|
+
*
|
|
982
|
+
* The SDK automatically reads the `DEBUG` environment variable, making it
|
|
983
|
+
* easy to enable logging without code changes:
|
|
984
|
+
*
|
|
985
|
+
* ```bash
|
|
986
|
+
* # Enable all SDK logging at debug level
|
|
987
|
+
* DEBUG=sanity:* npm start
|
|
988
|
+
*
|
|
989
|
+
* # Enable specific namespaces
|
|
990
|
+
* DEBUG=sanity:auth,sanity:document npm start
|
|
991
|
+
*
|
|
992
|
+
* # Enable trace level for all namespaces
|
|
993
|
+
* DEBUG=sanity:trace:* npm start
|
|
994
|
+
*
|
|
995
|
+
* # Enable internal/maintainer logs
|
|
996
|
+
* DEBUG=sanity:*:internal npm start
|
|
997
|
+
* ```
|
|
998
|
+
*
|
|
999
|
+
* This matches the pattern used by Sanity CLI and Studio, making it familiar
|
|
1000
|
+
* and easy for support teams to help troubleshoot issues.
|
|
1001
|
+
*
|
|
1002
|
+
* **Programmatic Configuration (Advanced):**
|
|
1003
|
+
*
|
|
1004
|
+
* For more control (custom handlers, dynamic configuration), call this function
|
|
1005
|
+
* explicitly. Programmatic configuration overrides environment variables.
|
|
1006
|
+
*
|
|
1007
|
+
* **For Application Developers:**
|
|
1008
|
+
* Use `info`, `warn`, or `error` levels to see high-level SDK activity
|
|
1009
|
+
* without being overwhelmed by internal details.
|
|
1010
|
+
*
|
|
1011
|
+
* **For SDK Maintainers:**
|
|
1012
|
+
* Use `debug` or `trace` levels with `internal: true` to see detailed
|
|
1013
|
+
* information about store operations, RxJS streams, and state transitions.
|
|
1014
|
+
*
|
|
1015
|
+
* **Instance Context:**
|
|
1016
|
+
* Logs automatically include instance information (projectId, dataset, instanceId)
|
|
1017
|
+
* when available, making it easier to debug multi-instance scenarios:
|
|
1018
|
+
* ```
|
|
1019
|
+
* [INFO] [auth] [project:abc] [dataset:production] User logged in
|
|
1020
|
+
* ```
|
|
1021
|
+
*
|
|
1022
|
+
* **Available Namespaces:**
|
|
1023
|
+
* - `sdk` - SDK initialization, configuration, and lifecycle
|
|
1024
|
+
* - `auth` - Authentication and authorization (when instrumented in the future)
|
|
1025
|
+
* - And more as logging is added to modules
|
|
1026
|
+
*
|
|
1027
|
+
* @example Zero-config via environment variable (recommended for debugging)
|
|
1028
|
+
* ```bash
|
|
1029
|
+
* # Just set DEBUG and run your app - no code changes needed!
|
|
1030
|
+
* DEBUG=sanity:* npm start
|
|
1031
|
+
* ```
|
|
1032
|
+
*
|
|
1033
|
+
* @example Programmatic configuration (application developer)
|
|
1034
|
+
* ```ts
|
|
1035
|
+
* import {configureLogging} from '@sanity/sdk'
|
|
1036
|
+
*
|
|
1037
|
+
* // Log warnings and errors for auth and document operations
|
|
1038
|
+
* configureLogging({
|
|
1039
|
+
* level: 'warn',
|
|
1040
|
+
* namespaces: ['auth', 'document']
|
|
1041
|
+
* })
|
|
1042
|
+
* ```
|
|
1043
|
+
*
|
|
1044
|
+
* @example Programmatic configuration (SDK maintainer)
|
|
1045
|
+
* ```ts
|
|
1046
|
+
* import {configureLogging} from '@sanity/sdk'
|
|
1047
|
+
*
|
|
1048
|
+
* // Enable all logs including internal traces
|
|
1049
|
+
* configureLogging({
|
|
1050
|
+
* level: 'trace',
|
|
1051
|
+
* namespaces: ['*'],
|
|
1052
|
+
* internal: true
|
|
1053
|
+
* })
|
|
1054
|
+
* ```
|
|
1055
|
+
*
|
|
1056
|
+
* @example Custom handler (for testing)
|
|
1057
|
+
* ```ts
|
|
1058
|
+
* import {configureLogging} from '@sanity/sdk'
|
|
1059
|
+
*
|
|
1060
|
+
* const logs: string[] = []
|
|
1061
|
+
* configureLogging({
|
|
1062
|
+
* level: 'info',
|
|
1063
|
+
* namespaces: ['*'],
|
|
1064
|
+
* handler: {
|
|
1065
|
+
* error: (msg) => logs.push(msg),
|
|
1066
|
+
* warn: (msg) => logs.push(msg),
|
|
1067
|
+
* info: (msg) => logs.push(msg),
|
|
1068
|
+
* debug: (msg) => logs.push(msg),
|
|
1069
|
+
* trace: (msg) => logs.push(msg),
|
|
1070
|
+
* }
|
|
1071
|
+
* })
|
|
1072
|
+
* ```
|
|
1073
|
+
*
|
|
1074
|
+
* @public
|
|
1075
|
+
*/
|
|
1076
|
+
declare function configureLogging(config: LoggerConfig): void;
|
|
678
1077
|
/** @public */
|
|
679
1078
|
declare const getDatasetsState: BoundStoreAction<FetcherStoreState<[options?: ProjectHandle<string> | undefined], _sanity_client12.DatasetsResponse>, [options?: ProjectHandle<string> | undefined], StateSource<_sanity_client12.DatasetsResponse | undefined>>;
|
|
680
1079
|
/** @public */
|
|
@@ -1574,7 +1973,6 @@ declare const resolveProjects: BoundStoreAction<FetcherStoreState<[options?: {
|
|
|
1574
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> {
|
|
1575
1974
|
query: TQuery;
|
|
1576
1975
|
params?: Record<string, unknown>;
|
|
1577
|
-
source?: DocumentSource;
|
|
1578
1976
|
}
|
|
1579
1977
|
/**
|
|
1580
1978
|
* @beta
|
|
@@ -1651,6 +2049,13 @@ declare const getActiveReleasesState: BoundStoreAction<ReleasesStoreState, [((ob
|
|
|
1651
2049
|
projectId?: string;
|
|
1652
2050
|
dataset?: string;
|
|
1653
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>>;
|
|
1654
2059
|
/**
|
|
1655
2060
|
* Provides a subscribable state source for a "perspective" for the Sanity client,
|
|
1656
2061
|
* which is used to fetch documents as though certain Content Releases are active.
|
|
@@ -1663,10 +2068,7 @@ declare const getActiveReleasesState: BoundStoreAction<ReleasesStoreState, [((ob
|
|
|
1663
2068
|
*
|
|
1664
2069
|
* @public
|
|
1665
2070
|
*/
|
|
1666
|
-
declare const getPerspectiveState:
|
|
1667
|
-
projectId?: string;
|
|
1668
|
-
dataset?: string;
|
|
1669
|
-
}) | undefined], StateSource<string[] | "raw" | "previewDrafts" | "published" | "drafts" | undefined>>;
|
|
2071
|
+
declare const getPerspectiveState: BoundGetPerspectiveState;
|
|
1670
2072
|
/** @internal */
|
|
1671
2073
|
declare const getUsersKey: (instance: SanityInstance, {
|
|
1672
2074
|
resourceType,
|
|
@@ -1938,4 +2340,4 @@ declare const CORE_SDK_VERSION: {};
|
|
|
1938
2340
|
* @public
|
|
1939
2341
|
*/
|
|
1940
2342
|
type SanityProject = SanityProject$1;
|
|
1941
|
-
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,
|
|
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 };
|