@sanity/sdk 2.19.0 → 2.20.1

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 (62) hide show
  1. package/dist/_exports/_internal.d.ts +2 -2
  2. package/dist/_exports/_internal.js +196 -22
  3. package/dist/_exports/_internal.js.map +1 -1
  4. package/dist/authStore-CWTAuieY.js +1072 -0
  5. package/dist/authStore-CWTAuieY.js.map +1 -0
  6. package/dist/clientStore-CMzJ7XhZ.js +168 -0
  7. package/dist/clientStore-CMzJ7XhZ.js.map +1 -0
  8. package/dist/createGroqSearchFilter-B0NdA-EP.js +1222 -0
  9. package/dist/createGroqSearchFilter-B0NdA-EP.js.map +1 -0
  10. package/dist/getEnv-76AjZd_f.js +178 -0
  11. package/dist/getEnv-76AjZd_f.js.map +1 -0
  12. package/dist/index.d.ts +2 -2105
  13. package/dist/index.js +4140 -3870
  14. package/dist/index.js.map +1 -1
  15. package/dist/rolldown-runtime-vyAXikos.js +9 -0
  16. package/dist/telemetryManager-w-AMXtmz.js +127 -0
  17. package/dist/telemetryManager-w-AMXtmz.js.map +1 -0
  18. package/dist/utils-BMwA8Kg9.d.ts +3334 -0
  19. package/dist/utils-BMwA8Kg9.d.ts.map +1 -0
  20. package/dist/version-ByqNiWrK.js +9 -0
  21. package/dist/version-ByqNiWrK.js.map +1 -0
  22. package/package.json +12 -20
  23. package/src/_exports/_internal.ts +1 -0
  24. package/src/_exports/index.ts +30 -0
  25. package/src/comments/addonDatasetStore.test.ts +215 -0
  26. package/src/comments/addonDatasetStore.ts +249 -0
  27. package/src/comments/buildCommentThreads.test.ts +83 -0
  28. package/src/comments/buildCommentThreads.ts +54 -0
  29. package/src/comments/commentActions.test.ts +540 -0
  30. package/src/comments/commentActions.ts +555 -0
  31. package/src/comments/commentFieldPath.test.ts +40 -0
  32. package/src/comments/commentFieldPath.ts +44 -0
  33. package/src/comments/commentsConstants.ts +80 -0
  34. package/src/comments/commentsStore.test.ts +419 -0
  35. package/src/comments/commentsStore.ts +483 -0
  36. package/src/comments/normalizeComment.test.ts +116 -0
  37. package/src/comments/normalizeComment.ts +45 -0
  38. package/src/comments/observeComments.test.ts +193 -0
  39. package/src/comments/observeComments.ts +113 -0
  40. package/src/comments/reducers.test.ts +277 -0
  41. package/src/comments/reducers.ts +316 -0
  42. package/src/comments/types.ts +249 -0
  43. package/src/comments/weakenReferences.test.ts +47 -0
  44. package/src/comments/weakenReferences.ts +29 -0
  45. package/src/document/documentConstants.ts +8 -0
  46. package/src/document/documentStore.test.ts +98 -1
  47. package/src/document/documentStore.ts +36 -5
  48. package/src/document/patchOperations.test.ts +27 -0
  49. package/src/document/patchOperations.ts +10 -1
  50. package/src/document/permissions.test.ts +3 -1
  51. package/src/document/reducers.test.ts +133 -0
  52. package/src/document/reducers.ts +18 -3
  53. package/src/projection/projectionStore.test.ts +0 -8
  54. package/dist/_chunks-dts/createGroqSearchFilter.d.ts +0 -923
  55. package/dist/_chunks-dts/createGroqSearchFilter.d.ts.map +0 -1
  56. package/dist/_chunks-es/_internal.js +0 -134
  57. package/dist/_chunks-es/_internal.js.map +0 -1
  58. package/dist/_chunks-es/createGroqSearchFilter.js +0 -1590
  59. package/dist/_chunks-es/createGroqSearchFilter.js.map +0 -1
  60. package/dist/_chunks-es/telemetryManager.js +0 -93
  61. package/dist/_chunks-es/telemetryManager.js.map +0 -1
  62. package/dist/index.d.ts.map +0 -1
@@ -1,923 +0,0 @@
1
- import { ClientConfig, ClientError, ClientPerspective, ResponseQueryOptions, SanityClient, StackablePerspective } from "@sanity/client";
2
- import { CurrentUser } from "@sanity/types";
3
- import { Observable } from "rxjs";
4
- import "zustand/middleware";
5
- import { SanityQueryResult } from "groq";
6
- /**
7
- * Configuration for an authentication provider
8
- * @public
9
- */
10
- interface AuthProvider {
11
- /**
12
- * Unique identifier for the auth provider (e.g., 'google', 'github')
13
- */
14
- name: string;
15
- /**
16
- * Display name for the auth provider in the UI
17
- */
18
- title: string;
19
- /**
20
- * Complete authentication URL including callback and token parameters
21
- */
22
- url: string;
23
- /**
24
- * Optional URL for direct sign-up flow
25
- */
26
- signUpUrl?: string;
27
- }
28
- /**
29
- * Configuration options for creating an auth store.
30
- *
31
- * @public
32
- */
33
- interface AuthConfig {
34
- /**
35
- * The initial location href to use when handling auth callbacks.
36
- * Defaults to the current window location if available.
37
- */
38
- initialLocationHref?: string;
39
- /**
40
- * Factory function to create a SanityClient instance.
41
- * Defaults to the standard Sanity client factory if not provided.
42
- */
43
- clientFactory?: (config: ClientConfig) => SanityClient;
44
- /**
45
- * Custom authentication providers to use instead of or in addition to the default ones.
46
- * Can be an array of providers or a function that takes the default providers and returns
47
- * a modified array or a Promise resolving to one.
48
- */
49
- providers?: AuthProvider[] | ((prev: AuthProvider[]) => AuthProvider[] | Promise<AuthProvider[]>);
50
- /**
51
- * The API hostname for requests. Usually leave this undefined, but it can be set
52
- * if using a custom domain or CNAME for the API endpoint.
53
- */
54
- apiHost?: string;
55
- /**
56
- * Storage implementation to persist authentication state.
57
- * Defaults to `localStorage` if available.
58
- */
59
- storageArea?: Storage;
60
- /**
61
- * A callback URL for your application.
62
- * If none is provided, the auth API will redirect back to the current location (`location.href`).
63
- * When handling callbacks, this URL's pathname is checked to ensure it matches the callback.
64
- */
65
- callbackUrl?: string;
66
- /**
67
- * A static authentication token to use instead of handling the OAuth flow.
68
- * When provided, the auth store will remain in a logged-in state with this token,
69
- * ignoring any storage or callback handling.
70
- */
71
- token?: string;
72
- }
73
- /**
74
- * A minimal Observable-compatible interface for subscribing to token changes.
75
- * Any object with a `subscribe` method that follows this contract will work,
76
- * including RxJS Observables. This avoids coupling the SDK to a specific
77
- * reactive library.
78
- *
79
- * @public
80
- */
81
- interface TokenSource {
82
- /** Subscribe to token emissions. Emits `null` when logged out. */
83
- subscribe(observer: {
84
- next: (token: string | null) => void;
85
- }): {
86
- unsubscribe(): void;
87
- };
88
- }
89
- /**
90
- * Studio-specific configuration for the SDK.
91
- * When present, the SDK operates in studio mode and derives auth from the
92
- * provided token source instead of discovering tokens independently.
93
- *
94
- * @public
95
- */
96
- interface StudioConfig {
97
- /**
98
- * Whether the Studio has already determined the user is authenticated.
99
- * When `true` and the token source emits `null`, the SDK infers
100
- * cookie-based auth is in use rather than transitioning to logged-out.
101
- */
102
- authenticated?: boolean;
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
- }
115
- /**
116
- * Represents the minimal configuration required to identify a Sanity project.
117
- * @public
118
- */
119
- interface ProjectHandle<TProjectId extends string = string> {
120
- projectId?: TProjectId;
121
- }
122
- /**
123
- * @public
124
- */
125
- type ReleasePerspective = {
126
- releaseName: string;
127
- excludedPerspectives?: StackablePerspective[];
128
- };
129
- /**
130
- * @public
131
- */
132
- interface PerspectiveHandle {
133
- perspective?: ClientPerspective | ReleasePerspective;
134
- }
135
- /**
136
- * @public
137
- */
138
- interface DatasetHandle<TDataset extends string = string, TProjectId extends string = string> extends ProjectHandle<TProjectId>, PerspectiveHandle {
139
- dataset?: TDataset;
140
- /**
141
- * @beta
142
- * Explicit resource object to use for this operation.
143
- */
144
- resource?: DocumentResource;
145
- /**
146
- * @deprecated Use `resource` instead.
147
- * @beta
148
- */
149
- source?: DocumentResource;
150
- }
151
- /**
152
- * Identifies a specific document type within a Sanity dataset and project.
153
- * Includes `projectId`, `dataset`, and `documentType`.
154
- * Optionally includes a `documentId` and `liveEdit` flag.
155
- * @public
156
- */
157
- interface DocumentTypeHandle<TDocumentType extends string = string, TDataset extends string = string, TProjectId extends string = string> extends DatasetHandle<TDataset, TProjectId> {
158
- documentId?: string;
159
- documentType: TDocumentType;
160
- /**
161
- * Indicates whether this document uses liveEdit mode.
162
- * When `true`, the document does not use the draft/published model and edits are applied directly to the document.
163
- * @see https://www.sanity.io/docs/content-lake/drafts#ca0663a8f002
164
- */
165
- liveEdit?: boolean;
166
- }
167
- /**
168
- * Uniquely identifies a specific document within a Sanity dataset and project.
169
- * Includes `projectId`, `dataset`, `documentType`, and the required `documentId`.
170
- * Commonly used by document-related hooks and components to reference a document without fetching its full content initially.
171
- * @public
172
- */
173
- interface DocumentHandle<TDocumentType extends string = string, TDataset extends string = string, TProjectId extends string = string> extends DocumentTypeHandle<TDocumentType, TDataset, TProjectId> {
174
- documentId: string;
175
- }
176
- /**
177
- * Identifies a release within a Sanity dataset and project. `releaseId` is the
178
- * `name` parameter on the release document (e.g. `{name: 'r41035a4'}`).
179
- * The underlying release document ID is `_.releases.<releaseId>`.
180
- * It's also the `id` parameter sent to the Actions API.
181
- * (This type doesn't need to have ProjectId / Dataset generics since it's always the same shape)
182
- * @beta
183
- */
184
- interface ReleaseHandle extends DatasetHandle {
185
- releaseId: string;
186
- }
187
- /**
188
- * Represents the complete configuration for a Sanity SDK instance
189
- * @public
190
- */
191
- interface SanityConfig extends DatasetHandle, PerspectiveHandle {
192
- /**
193
- * Authentication configuration for the instance
194
- */
195
- auth?: AuthConfig;
196
- /**
197
- * Studio configuration provided by a Sanity Studio workspace.
198
- * When present, the SDK operates in studio mode and derives auth from the
199
- * workspace's reactive token source — no manual configuration needed.
200
- *
201
- * @remarks Typically set automatically by `SanityApp` when it detects an
202
- * `SDKStudioContext` provider. Can also be set explicitly for programmatic use.
203
- */
204
- studio?: StudioConfig;
205
- /**
206
- * Studio mode configuration for use of the SDK in a Sanity Studio.
207
- * @remarks Controls whether studio mode features are enabled.
208
- * @deprecated Use `studio` instead, which provides richer integration
209
- * with the Studio's workspace (auth token sync, etc.).
210
- */
211
- studioMode?: {
212
- enabled: boolean;
213
- };
214
- /**
215
- * @beta
216
- * A list of named resources to use for this instance.
217
- */
218
- resources?: Record<string, DocumentResource>;
219
- /**
220
- * @deprecated Use `resources` instead.
221
- * @beta
222
- */
223
- sources?: Record<string, DocumentResource>;
224
- }
225
- /**
226
- * A document resource can be used for querying.
227
- * This will soon be the default way to identify where you are querying from.
228
- *
229
- * @beta
230
- */
231
- type DocumentResource = DatasetResource | MediaLibraryResource | CanvasResource;
232
- /**
233
- * @beta
234
- */
235
- type DatasetResource = {
236
- projectId: string;
237
- dataset: string;
238
- };
239
- /**
240
- * @beta
241
- */
242
- type MediaLibraryResource = {
243
- mediaLibraryId: string;
244
- };
245
- /**
246
- * @beta
247
- */
248
- type CanvasResource = {
249
- canvasId: string;
250
- };
251
- /**
252
- * @beta
253
- */
254
- declare function isDatasetResource(resource: DocumentResource): resource is DatasetResource;
255
- /**
256
- * @beta
257
- */
258
- declare function isMediaLibraryResource(resource: DocumentResource): resource is MediaLibraryResource;
259
- /**
260
- * @beta
261
- */
262
- declare function isCanvasResource(resource: DocumentResource): resource is CanvasResource;
263
- /**
264
- * @deprecated Use `DocumentResource` instead.
265
- * @beta
266
- */
267
- type DocumentSource = DocumentResource;
268
- /**
269
- * @deprecated Use `DatasetResource` instead.
270
- * @beta
271
- */
272
- type DatasetSource = DatasetResource;
273
- /**
274
- * @deprecated Use `MediaLibraryResource` instead.
275
- * @beta
276
- */
277
- type MediaLibrarySource = MediaLibraryResource;
278
- /**
279
- * @deprecated Use `CanvasResource` instead.
280
- * @beta
281
- */
282
- type CanvasSource = CanvasResource;
283
- /**
284
- * @deprecated Use `isDatasetResource` instead.
285
- * @beta
286
- */
287
- declare function isDatasetSource(source: DocumentSource): source is DatasetSource;
288
- /**
289
- * @deprecated Use `isMediaLibraryResource` instead.
290
- * @beta
291
- */
292
- declare function isMediaLibrarySource(source: DocumentSource): source is MediaLibrarySource;
293
- /**
294
- * @deprecated Use `isCanvasResource` instead.
295
- * @beta
296
- */
297
- declare function isCanvasSource(source: DocumentSource): source is CanvasSource;
298
- /**
299
- * Returns `true` when the config indicates the SDK is running inside a Studio.
300
- * Checks the new `studio` field first, then falls back to the deprecated
301
- * `studioMode.enabled` for backwards compatibility.
302
- *
303
- * @internal
304
- */
305
- declare function isStudioConfig(config: SanityConfig): boolean;
306
- /**
307
- * Represents a Sanity.io resource instance with its own configuration and lifecycle
308
- *
309
- * @public
310
- */
311
- interface SanityInstance {
312
- /**
313
- * Unique identifier for this instance
314
- * @remarks Generated using crypto.randomUUID()
315
- */
316
- readonly instanceId: string;
317
- /**
318
- * Resolved configuration for this instance
319
- */
320
- readonly config: SanityConfig;
321
- /**
322
- * Checks if the instance has been disposed
323
- * @returns true if dispose() has been called
324
- */
325
- isDisposed(): boolean;
326
- /**
327
- * Disposes the instance and cleans up associated resources
328
- * @remarks Triggers all registered onDispose callbacks
329
- */
330
- dispose(): void;
331
- /**
332
- * Registers a callback to be invoked when the instance is disposed
333
- * @param cb - Callback to execute on disposal
334
- * @returns Function to unsubscribe the callback
335
- */
336
- onDispose(cb: () => void): () => void;
337
- /**
338
- * Gets the parent instance in the hierarchy
339
- * @returns Parent instance or undefined if this is the root
340
- * @deprecated The parent/child instance hierarchy is deprecated. Use a single SanityInstance instead.
341
- */
342
- getParent(): SanityInstance | undefined;
343
- /**
344
- * Creates a child instance with merged configuration
345
- * @param config - Configuration to merge with parent values
346
- * @deprecated The parent/child instance hierarchy is deprecated. Use a single SanityInstance instead.
347
- */
348
- createChild(config: SanityConfig): SanityInstance;
349
- /**
350
- * Traverses the instance hierarchy to find the first instance whose configuration
351
- * matches the given target config using a shallow comparison.
352
- * @param targetConfig - A partial configuration object containing key-value pairs to match.
353
- * @returns The first matching instance or undefined if no match is found.
354
- * @deprecated The parent/child instance hierarchy is deprecated. Use a single SanityInstance instead.
355
- */
356
- match(targetConfig: Partial<SanityConfig>): SanityInstance | undefined;
357
- }
358
- /**
359
- * Creates a new Sanity resource instance
360
- * @param config - Configuration for the instance (optional)
361
- * @returns A configured SanityInstance
362
- * @remarks When creating child instances, configurations are merged with parent values
363
- *
364
- * @public
365
- */
366
- declare function createSanityInstance(config?: SanityConfig): SanityInstance;
367
- /**
368
- * Represents a reactive store state container with multiple access patterns
369
- */
370
- interface StoreState<TState> {
371
- /**
372
- * Gets the current state value
373
- *
374
- * @remarks
375
- * This is a direct synchronous accessor that doesn't trigger subscriptions
376
- */
377
- get: () => TState;
378
- /**
379
- * Updates the store state
380
- * @param name - Action name for devtools tracking
381
- * @param updatedState - New state value or updater function
382
- *
383
- * @remarks
384
- * When providing a partial object, previous top-level keys not included in
385
- * the update will be preserved.
386
- */
387
- set: (name: string, updatedState: Partial<TState> | ((s: TState) => Partial<TState>)) => void;
388
- /**
389
- * Observable stream of state changes
390
- * @remarks
391
- * - Emits immediately with current state on subscription
392
- * - Shares underlying subscription between observers
393
- * - Only emits when state reference changes
394
- * - Completes when store is disposed
395
- */
396
- observable: Observable<TState>;
397
- }
398
- /**
399
- * Context object provided to store initialization functions
400
- */
401
- interface StoreContext<TState, TKey = unknown> {
402
- /**
403
- * Sanity instance associated with this store
404
- *
405
- * @remarks
406
- * Provides access to the Sanity configuration and instance lifecycle methods
407
- */
408
- instance: SanityInstance;
409
- /**
410
- * Reactive store state management utilities
411
- *
412
- * @remarks
413
- * Contains methods for getting/setting state and observing changes
414
- */
415
- state: StoreState<TState>;
416
- /**
417
- * The key used to instantiate the store.
418
- */
419
- key: TKey;
420
- }
421
- /**
422
- * Defines a store action that operates on a specific state type
423
- */
424
- type StoreAction<TState, TParams extends unknown[], TReturn, TKey = unknown> = (context: StoreContext<TState, TKey>, ...params: TParams) => TReturn;
425
- /**
426
- * Represents a store action that has been bound to a specific store instance
427
- */
428
- type BoundStoreAction<_TState, TParams extends unknown[], TReturn> = (instance: SanityInstance, ...params: TParams) => TReturn;
429
- /**
430
- * Represents the various states the authentication type can be in.
431
- *
432
- * @public
433
- */
434
- declare enum AuthStateType {
435
- LOGGED_IN = "logged-in",
436
- LOGGING_IN = "logging-in",
437
- ERROR = "error",
438
- LOGGED_OUT = "logged-out"
439
- }
440
- /**
441
- * Represents the various states the authentication can be in.
442
- *
443
- * @public
444
- */
445
- type AuthState = LoggedInAuthState | LoggedOutAuthState | LoggingInAuthState | ErrorAuthState;
446
- /**
447
- * Logged-in state from the auth state.
448
- * @public
449
- */
450
- type LoggedInAuthState = {
451
- type: AuthStateType.LOGGED_IN;
452
- token: string;
453
- currentUser: CurrentUser | null;
454
- lastTokenRefresh?: number;
455
- };
456
- /**
457
- * Logged-out state from the auth state.
458
- * @public
459
- */
460
- type LoggedOutAuthState = {
461
- type: AuthStateType.LOGGED_OUT;
462
- isDestroyingSession: boolean;
463
- };
464
- /**
465
- * Logging-in state from the auth state.
466
- * @public
467
- */
468
- type LoggingInAuthState = {
469
- type: AuthStateType.LOGGING_IN;
470
- isExchangingToken: boolean;
471
- };
472
- /**
473
- * Error state from the auth state.
474
- * @public
475
- */
476
- type ErrorAuthState = {
477
- type: AuthStateType.ERROR;
478
- error: unknown;
479
- };
480
- /**
481
- * Represents the various states the authentication can be in.
482
- *
483
- * @public
484
- */
485
- interface DashboardContext {
486
- mode?: string;
487
- env?: string;
488
- orgId?: string;
489
- }
490
- /**
491
- * The method of authentication used.
492
- * @internal
493
- */
494
- type AuthMethodOptions = 'localstorage' | 'cookie' | undefined;
495
- /**
496
- * @public
497
- */
498
- interface AuthStoreState {
499
- authState: AuthState;
500
- providers?: AuthProvider[];
501
- options: {
502
- initialLocationHref: string;
503
- clientFactory: (config: ClientConfig) => SanityClient;
504
- customProviders: AuthConfig['providers'];
505
- storageKey: string;
506
- storageArea: Storage | undefined;
507
- apiHost: string | undefined;
508
- loginUrl: string;
509
- callbackUrl: string | undefined;
510
- providedToken: string | undefined;
511
- authMethod: AuthMethodOptions;
512
- };
513
- dashboardContext?: DashboardContext;
514
- }
515
- /**
516
- * @public
517
- */
518
- declare const getCurrentUserState: BoundStoreAction<AuthStoreState, [], import("../_exports").StateSource<CurrentUser | null>>;
519
- /**
520
- * @public
521
- */
522
- declare const getTokenState: BoundStoreAction<AuthStoreState, [], import("../_exports").StateSource<string | null>>;
523
- /**
524
- * @public
525
- */
526
- declare const getLoginUrlState: BoundStoreAction<AuthStoreState, [], import("../_exports").StateSource<string>>;
527
- /**
528
- * @public
529
- */
530
- declare const getAuthState: BoundStoreAction<AuthStoreState, [], import("../_exports").StateSource<AuthState>>;
531
- /**
532
- * @public
533
- */
534
- declare const getDashboardOrganizationId: BoundStoreAction<AuthStoreState, [], import("../_exports").StateSource<string | undefined>>;
535
- /**
536
- * Returns a state source indicating if the SDK is running within a dashboard context.
537
- * @public
538
- */
539
- declare const getIsInDashboardState: BoundStoreAction<AuthStoreState, [], import("../_exports").StateSource<boolean>>;
540
- /**
541
- * Action to explicitly set the authentication token.
542
- * Used internally by the Comlink token refresh.
543
- * @internal
544
- */
545
- declare const setAuthToken: BoundStoreAction<AuthStoreState, [token: string | null], void>;
546
- /** @internal */
547
- type ApiErrorBody = {
548
- error?: {
549
- type?: string;
550
- description?: string;
551
- };
552
- type?: string;
553
- description?: string;
554
- message?: string;
555
- };
556
- /** @internal Extracts the structured API error body from a ClientError, if present. */
557
- declare function getClientErrorApiBody(error: ClientError): ApiErrorBody | undefined;
558
- /** @internal Returns the error type string from an API error body, if available. */
559
- declare function getClientErrorApiType(error: ClientError): string | undefined;
560
- /** @internal Returns the error description string from an API error body, if available. */
561
- declare function getClientErrorApiDescription(error: ClientError): string | undefined;
562
- /** @internal True if the error represents a projectUserNotFoundError. */
563
- declare function isProjectUserNotFoundClientError(error: ClientError): boolean;
564
- /**
565
- * Generates a GROQ projection for preview data without requiring a schema.
566
- * Uses common field names to make educated guesses about which fields to use.
567
- *
568
- * @internal
569
- */
570
- declare const PREVIEW_PROJECTION: string;
571
- /**
572
- * @public
573
- * The result of a projection query
574
- */
575
- interface ProjectionValuePending<TValue extends object> {
576
- data: TValue | null;
577
- isPending: boolean;
578
- }
579
- /**
580
- * @public
581
- * @deprecated
582
- * Template literals are a bit too limited, so this type is deprecated.
583
- * Use `string` instead. Projection strings are validated at runtime.
584
- */
585
- type ValidProjection = string;
586
- interface DocumentStatus {
587
- lastEditedDraftAt?: string;
588
- lastEditedPublishedAt?: string;
589
- lastEditedVersionAt?: string;
590
- }
591
- /**
592
- *
593
- * @internal
594
- */
595
- interface PreviewQueryResult {
596
- _id: string;
597
- _type: string;
598
- _updatedAt: string;
599
- titleCandidates: Record<string, unknown>;
600
- subtitleCandidates: Record<string, unknown>;
601
- media?: PreviewMedia | null;
602
- _status?: DocumentStatus;
603
- }
604
- /**
605
- * Represents a media asset in a preview.
606
- *
607
- * @public
608
- */
609
- interface PreviewMedia {
610
- type: 'image-asset';
611
- _ref: string;
612
- url: string;
613
- }
614
- /**
615
- * Represents the set of values displayed as a preview for a given Sanity document.
616
- * This includes a primary title, a secondary subtitle, an optional piece of media associated
617
- * with the document, and the document's status.
618
- *
619
- * @public
620
- */
621
- interface PreviewValue {
622
- /**
623
- * The primary text displayed for the document preview.
624
- */
625
- title: string;
626
- /**
627
- * A secondary line of text providing additional context about the document.
628
- */
629
- subtitle?: string;
630
- /**
631
- * An optional piece of media representing the document within its preview.
632
- * Currently, only image assets are available.
633
- */
634
- media?: PreviewMedia | null;
635
- /**
636
- * The status of the document.
637
- */
638
- _status?: {
639
- /** The date of the last published edit */
640
- lastEditedPublishedAt?: string;
641
- /** The date of the last draft edit */
642
- lastEditedDraftAt?: string;
643
- };
644
- }
645
- /**
646
- * Represents the current state of a preview value along with a flag indicating whether
647
- * the preview data is still being fetched or is fully resolved.
648
- *
649
- * The tuple contains a preview value or null, and a boolean indicating if the data is
650
- * pending. A `true` value means a fetch is ongoing; `false` indicates that the
651
- * currently provided preview value is up-to-date.
652
- *
653
- * @public
654
- */
655
- type ValuePending<T> = {
656
- data: T | null;
657
- isPending: boolean;
658
- };
659
- /**
660
- * @public
661
- * @deprecated This interface is kept for backwards compatibility but is no longer used internally.
662
- * Preview state is now stored in the projection store.
663
- */
664
- interface PreviewStoreState {
665
- values: { [TDocumentId in string]?: ValuePending<PreviewValue>; };
666
- subscriptions: { [TDocumentId in string]?: { [TSubscriptionId in string]?: true; }; };
667
- }
668
- /**
669
- * Transforms a projection result (with titleCandidates, subtitleCandidates, media)
670
- * into a PreviewValue (with title, subtitle, media).
671
- *
672
- * @param projectionResult - The raw projection result from GROQ
673
- * @param instance - The Sanity instance to use for client configuration
674
- * @param resource - Data resource for the preview
675
- * @internal
676
- */
677
- declare function transformProjectionToPreview(instance: SanityInstance, projectionResult: PreviewQueryResult, resource?: DocumentResource): PreviewValue;
678
- /**
679
- * Represents a reactive state source that provides synchronized access to store data
680
- *
681
- * @remarks
682
- * Designed to work with React's useSyncExternalStore hook. Provides three ways to access data:
683
- * 1. `getCurrent()` for synchronous current value access
684
- * 2. `subscribe()` for imperative change notifications
685
- * 3. `observable` for reactive stream access
686
- *
687
- * @public
688
- */
689
- interface StateSource<T> {
690
- /**
691
- * Subscribes to state changes with optional callback
692
- * @param onStoreChanged - Called whenever relevant state changes occur
693
- * @returns Unsubscribe function to clean up the subscription
694
- */
695
- subscribe: (onStoreChanged?: () => void) => () => void;
696
- /**
697
- * Gets the current derived state value
698
- *
699
- * @remarks
700
- * Safe to call without subscription. Will always return the latest value
701
- * based on the current store state and selector parameters.
702
- */
703
- getCurrent: () => T;
704
- /**
705
- * Observable stream of state values
706
- *
707
- * @remarks
708
- * Shares a single underlying subscription between all observers. Emits:
709
- * - Immediately with current value on subscription
710
- * - On every relevant state change
711
- * - Errors if selector throws
712
- */
713
- observable: Observable<T>;
714
- }
715
- /**
716
- * Context passed to selectors when deriving state
717
- *
718
- * @remarks
719
- * Provides access to both the current state value and the Sanity instance,
720
- * allowing selectors to use configuration values when computing derived state.
721
- * The context is memoized for each state object and instance combination
722
- * to optimize performance and prevent unnecessary recalculations.
723
- *
724
- * @example
725
- * ```ts
726
- * // Using both state and instance in a selector (psuedo example)
727
- * const getUserByProjectId = createStateSourceAction(
728
- * ({ state, instance }: SelectorContext<UsersState>, options?: ProjectHandle) => {
729
- * const allUsers = state.users
730
- * const projectId = options?.projectId ?? instance.config.projectId
731
- * return allUsers.filter(user => user.projectId === projectId)
732
- * }
733
- * )
734
- * ```
735
- */
736
- interface SelectorContext<TState> {
737
- /**
738
- * The current state object from the store
739
- */
740
- state: TState;
741
- /**
742
- * The Sanity instance associated with this state
743
- */
744
- instance: SanityInstance;
745
- }
746
- /**
747
- * Function type for selecting derived state from store state and parameters
748
- * @public
749
- */
750
- type Selector<TState, TParams extends unknown[], TReturn> = (context: SelectorContext<TState>, ...params: TParams) => TReturn;
751
- /**
752
- * @beta
753
- */
754
- 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> {
755
- query: TQuery;
756
- params?: Record<string, unknown>;
757
- }
758
- /**
759
- * @beta
760
- */
761
- interface ResolveQueryOptions<TQuery extends string = string, TDataset extends string = string, TProjectId extends string = string> extends QueryOptions<TQuery, TDataset, TProjectId> {
762
- signal?: AbortSignal;
763
- }
764
- /** @beta */
765
- declare const getQueryKey: (options: QueryOptions) => string;
766
- /** @beta */
767
- declare const parseQueryKey: (key: string) => QueryOptions;
768
- /**
769
- * Returns the state source for a query.
770
- *
771
- * This function returns a state source that represents the current result of a GROQ query.
772
- * Subscribing to the state source will instruct the SDK to fetch the query (if not already fetched)
773
- * and will keep the query live using the Live content API (considering sync tags) to provide up-to-date results.
774
- * When the last subscriber is removed, the query state is automatically cleaned up from the store.
775
- *
776
- * Note: This functionality is for advanced users who want to build their own framework integrations.
777
- * Our SDK also provides a React integration (useQuery hook) for convenient usage.
778
- *
779
- * Note: Automatic cleanup can interfere with React Suspense because if a component suspends while being the only subscriber,
780
- * cleanup might occur unexpectedly. In such cases, consider using `resolveQuery` instead.
781
- *
782
- * @beta
783
- */
784
- declare function getQueryState<TQuery extends string = string, TDataset extends string = string, TProjectId extends string = string>(instance: SanityInstance, queryOptions: QueryOptions<TQuery, TDataset, TProjectId>): StateSource<SanityQueryResult<TQuery, `${TProjectId}.${TDataset}`> | undefined>;
785
- /** @beta */
786
- declare function getQueryState<TData>(instance: SanityInstance, queryOptions: QueryOptions): StateSource<TData | undefined>;
787
- /** @beta */
788
- declare function getQueryState(instance: SanityInstance, queryOptions: QueryOptions): StateSource<unknown>;
789
- /**
790
- * Resolves the result of a query without registering a lasting subscriber.
791
- *
792
- * This function fetches the result of a GROQ query and returns a promise that resolves with the query result.
793
- * It registers a temporary subscriber for the lifetime of the resolution (released shortly after the promise
794
- * settles), so the query state participates in normal cleanup even when no lasting subscriber ever attaches —
795
- * e.g. when a suspended component errors before committing. This makes it ideal for use with React Suspense,
796
- * where the returned promise is thrown to delay rendering until the query result becomes available.
797
- * Once the promise resolves, it is expected that a real subscriber will be added via `getQueryState` to manage ongoing updates.
798
- *
799
- * Additionally, an optional AbortSignal can be provided to cancel the query and immediately clear the associated state
800
- * if there are no other active subscribers.
801
- *
802
- * @beta
803
- */
804
- declare function resolveQuery<TQuery extends string = string, TDataset extends string = string, TProjectId extends string = string>(instance: SanityInstance, queryOptions: ResolveQueryOptions<TQuery, TDataset, TProjectId>): Promise<SanityQueryResult<TQuery, `${TProjectId}.${TDataset}`>>;
805
- /** @beta */
806
- declare function resolveQuery<TData>(instance: SanityInstance, queryOptions: ResolveQueryOptions): Promise<TData>;
807
- /**
808
- * @public
809
- */
810
- interface SanityUser {
811
- sanityUserId: string;
812
- profile: UserProfile;
813
- memberships: Membership[];
814
- }
815
- /**
816
- * @public
817
- */
818
- interface Membership {
819
- addedAt?: string;
820
- resourceType: string;
821
- resourceId: string;
822
- roleNames: Array<string>;
823
- lastSeenAt?: string | null;
824
- }
825
- /**
826
- * @public
827
- */
828
- interface UserProfile {
829
- id: string;
830
- displayName: string;
831
- email: string;
832
- familyName?: string;
833
- givenName?: string;
834
- middleName?: string | null;
835
- imageUrl?: string;
836
- provider: string;
837
- tosAcceptedAt?: string;
838
- createdAt: string;
839
- updatedAt?: string;
840
- isCurrentUser?: boolean;
841
- providerId?: string;
842
- }
843
- /**
844
- * @public
845
- */
846
- interface GetUsersOptions extends ProjectHandle {
847
- resourceType?: 'organization' | 'project';
848
- batchSize?: number;
849
- organizationId?: string;
850
- userId?: string;
851
- }
852
- /**
853
- * @public
854
- */
855
- interface UsersGroupState {
856
- subscriptions: string[];
857
- totalCount?: number;
858
- nextCursor?: string | null;
859
- lastLoadMoreRequest?: string;
860
- users?: SanityUser[];
861
- error?: unknown;
862
- }
863
- /**
864
- * @public
865
- */
866
- interface SanityUserResponse {
867
- data: SanityUser[];
868
- totalCount: number;
869
- nextCursor: string | null;
870
- }
871
- /**
872
- * @public
873
- */
874
- interface UsersStoreState {
875
- users: { [TUsersKey in string]?: UsersGroupState; };
876
- error?: unknown;
877
- }
878
- /**
879
- * @public
880
- */
881
- interface ResolveUsersOptions extends GetUsersOptions {
882
- signal?: AbortSignal;
883
- }
884
- /**
885
- * @public
886
- */
887
- interface GetUserOptions extends ProjectHandle {
888
- userId: string;
889
- resourceType?: 'organization' | 'project';
890
- organizationId?: string;
891
- }
892
- /**
893
- * @public
894
- */
895
- interface ResolveUserOptions extends GetUserOptions {
896
- signal?: AbortSignal;
897
- }
898
- /** @internal */
899
- declare const getUsersKey: (instance: SanityInstance, { resourceType, organizationId, batchSize, projectId, userId }?: GetUsersOptions) => string;
900
- /** @internal */
901
- declare const parseUsersKey: (key: string) => {
902
- batchSize: number;
903
- resourceType?: "organization" | "project";
904
- projectId?: string;
905
- organizationId?: string;
906
- userId?: string;
907
- };
908
- /**
909
- * Creates a GROQ search filter string (`[@] match text::query("...")`)
910
- * from a raw search query string.
911
- *
912
- * It applies wildcard ('*') logic to the last eligible token and escapes
913
- * double quotes within the search term.
914
- *
915
- * If the input query is empty or only whitespace, it returns an empty string.
916
- *
917
- * @param query - The raw input search string.
918
- * @returns The GROQ search filter string, or an empty string.
919
- * @internal
920
- */
921
- declare function createGroqSearchFilter(query: string): string;
922
- export { isStudioConfig as $, ApiErrorBody as A, LoggingInAuthState as B, PreviewQueryResult as C, isMediaLibrarySource as Ct, ProjectionValuePending as D, ValuePending as E, AuthState as F, getLoginUrlState as G, getCurrentUserState as H, AuthStoreState as I, AuthStateType as J, getTokenState as K, ErrorAuthState as L, getClientErrorApiDescription as M, getClientErrorApiType as N, ValidProjection as O, isProjectUserNotFoundClientError as P, createSanityInstance as Q, LoggedInAuthState as R, PreviewMedia as S, isMediaLibraryResource as St, PreviewValue as T, AuthProvider as Tt, getDashboardOrganizationId as U, getAuthState as V, getIsInDashboardState as W, StoreAction as X, BoundStoreAction as Y, SanityInstance as Z, parseQueryKey as _, TokenSource as _t, GetUsersOptions as a, DocumentHandle as at, StateSource as b, isDatasetResource as bt, ResolveUsersOptions as c, DocumentTypeHandle as ct, UserProfile as d, PerspectiveHandle as dt, CanvasResource as et, UsersGroupState as f, ProjectHandle as ft, getQueryState as g, StudioConfig as gt, getQueryKey as h, SanityConfig as ht, GetUserOptions as i, DatasetSource as it, getClientErrorApiBody as j, PREVIEW_PROJECTION as k, SanityUser as l, MediaLibraryResource as lt, QueryOptions as m, ReleasePerspective as mt, getUsersKey as n, DatasetHandle as nt, Membership as o, DocumentResource as ot, UsersStoreState as p, ReleaseHandle as pt, setAuthToken as q, parseUsersKey as r, DatasetResource as rt, ResolveUserOptions as s, DocumentSource as st, createGroqSearchFilter as t, CanvasSource as tt, SanityUserResponse as u, MediaLibrarySource as ut, resolveQuery as v, isCanvasResource as vt, PreviewStoreState as w, AuthConfig as wt, transformProjectionToPreview as x, isDatasetSource as xt, Selector as y, isCanvasSource as yt, LoggedOutAuthState as z };
923
- //# sourceMappingURL=createGroqSearchFilter.d.ts.map