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