@sanity/sdk 3.0.0-rc.0 → 3.0.0-rc.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 (197) hide show
  1. package/dist/_chunks-dts/createGroqSearchFilter.d.ts +1147 -0
  2. package/dist/_chunks-dts/createGroqSearchFilter.d.ts.map +1 -0
  3. package/dist/_chunks-es/_internal.js +134 -0
  4. package/dist/_chunks-es/_internal.js.map +1 -0
  5. package/dist/_chunks-es/createGroqSearchFilter.js +1864 -0
  6. package/dist/_chunks-es/createGroqSearchFilter.js.map +1 -0
  7. package/dist/_chunks-es/telemetryManager.js +93 -0
  8. package/dist/_chunks-es/telemetryManager.js.map +1 -0
  9. package/dist/_exports/_internal.d.ts +95 -0
  10. package/dist/_exports/_internal.d.ts.map +1 -0
  11. package/dist/_exports/_internal.js +24 -0
  12. package/dist/_exports/_internal.js.map +1 -0
  13. package/dist/index.d.ts +1079 -1076
  14. package/dist/index.d.ts.map +1 -0
  15. package/dist/index.js +1967 -2302
  16. package/dist/index.js.map +1 -1
  17. package/package.json +48 -47
  18. package/src/_exports/_internal.ts +26 -0
  19. package/src/_exports/index.ts +120 -11
  20. package/src/access/checkPermissions.test.ts +55 -0
  21. package/src/access/checkPermissions.ts +54 -0
  22. package/src/agent/agentActions.test.ts +16 -60
  23. package/src/agent/agentActions.ts +25 -38
  24. package/src/applications/applications.test-d.ts +83 -0
  25. package/src/applications/applications.test.ts +130 -0
  26. package/src/applications/applications.ts +364 -0
  27. package/src/applications/userApplications.test.ts +126 -0
  28. package/src/applications/userApplications.ts +261 -0
  29. package/src/auth/authLogger.ts +30 -0
  30. package/src/auth/authMode.test.ts +25 -0
  31. package/src/auth/authMode.ts +6 -3
  32. package/src/auth/authStore.test.ts +194 -13
  33. package/src/auth/authStore.ts +59 -26
  34. package/src/auth/getOrganizationVerificationState.test.ts +18 -17
  35. package/src/auth/getOrganizationVerificationState.ts +4 -4
  36. package/src/auth/handleAuthCallback.test.ts +35 -1
  37. package/src/auth/handleAuthCallback.ts +25 -6
  38. package/src/auth/logout.test.ts +75 -2
  39. package/src/auth/logout.ts +23 -4
  40. package/src/auth/refreshStampedToken.test.ts +219 -469
  41. package/src/auth/refreshStampedToken.ts +79 -195
  42. package/src/auth/studioAuth.ts +1 -1
  43. package/src/auth/studioModeAuth.ts +2 -1
  44. package/src/auth/subscribeToStateAndFetchCurrentUser.test.ts +146 -13
  45. package/src/auth/subscribeToStateAndFetchCurrentUser.ts +37 -6
  46. package/src/auth/subscribeToStorageEventsAndSetToken.test.ts +2 -0
  47. package/src/client/clientStore.test.ts +62 -37
  48. package/src/client/clientStore.ts +45 -75
  49. package/src/client/liveEvents.test.ts +151 -0
  50. package/src/client/liveEvents.ts +107 -0
  51. package/src/comlink/controller/actions/destroyController.test.ts +4 -1
  52. package/src/comlink/controller/actions/getOrCreateChannel.test.ts +4 -1
  53. package/src/comlink/controller/actions/getOrCreateChannel.ts +2 -2
  54. package/src/comlink/controller/actions/getOrCreateController.test.ts +4 -1
  55. package/src/comlink/controller/actions/releaseChannel.test.ts +1 -1
  56. package/src/comlink/controller/comlinkControllerStore.test.ts +4 -1
  57. package/src/comlink/node/actions/getOrCreateNode.test.ts +9 -3
  58. package/src/comlink/node/actions/getOrCreateNode.ts +2 -2
  59. package/src/comlink/node/actions/releaseNode.test.ts +7 -4
  60. package/src/comlink/node/comlinkNodeStore.test.ts +2 -2
  61. package/src/comlink/node/getNodeState.test.ts +1 -1
  62. package/src/comlink/node/getNodeState.ts +2 -1
  63. package/src/config/__tests__/handles.test.ts +18 -12
  64. package/src/config/handles.ts +25 -7
  65. package/src/config/sanityConfig.ts +109 -79
  66. package/src/datasets/datasets.test.ts +2 -2
  67. package/src/datasets/datasets.ts +10 -4
  68. package/src/document/actions.test.ts +115 -33
  69. package/src/document/actions.ts +212 -15
  70. package/src/document/applyDocumentActions.test.ts +38 -12
  71. package/src/document/applyDocumentActions.ts +30 -9
  72. package/src/document/documentConstants.ts +7 -0
  73. package/src/document/documentStore.concurrency.test.ts +1306 -0
  74. package/src/document/documentStore.test.ts +673 -278
  75. package/src/document/documentStore.ts +162 -71
  76. package/src/document/events.test.ts +57 -2
  77. package/src/document/events.ts +82 -26
  78. package/src/document/listen.test.ts +56 -0
  79. package/src/document/listen.ts +74 -21
  80. package/src/document/listenerEventOperators.test.ts +311 -0
  81. package/src/document/listenerEventOperators.ts +217 -0
  82. package/src/document/patchOperations.test.ts +49 -2
  83. package/src/document/patchOperations.ts +50 -0
  84. package/src/document/permissions.test.ts +105 -60
  85. package/src/document/permissions.ts +44 -19
  86. package/src/document/processActions/create.ts +138 -0
  87. package/src/document/processActions/delete.ts +100 -0
  88. package/src/document/processActions/discard.ts +63 -0
  89. package/src/document/processActions/edit.ts +154 -0
  90. package/src/document/processActions/processActions.ts +218 -0
  91. package/src/document/processActions/publish.ts +120 -0
  92. package/src/document/processActions/releaseArchive.ts +77 -0
  93. package/src/document/processActions/releaseCreate.ts +59 -0
  94. package/src/document/processActions/releaseDelete.ts +65 -0
  95. package/src/document/processActions/releaseEdit.ts +37 -0
  96. package/src/document/processActions/releasePublish.ts +45 -0
  97. package/src/document/processActions/releaseSchedule.ts +87 -0
  98. package/src/document/processActions/releaseUtil.ts +31 -0
  99. package/src/document/processActions/shared.ts +308 -0
  100. package/src/document/processActions/unpublish.ts +85 -0
  101. package/src/document/processActions.test.ts +1129 -121
  102. package/src/document/reducers.test.ts +639 -64
  103. package/src/document/reducers.ts +187 -48
  104. package/src/document/resourceRules.test.ts +178 -0
  105. package/src/document/resourceRules.ts +117 -0
  106. package/src/document/sharedListener.test.ts +16 -14
  107. package/src/document/sharedListener.ts +24 -8
  108. package/src/document/util.ts +14 -0
  109. package/src/favorites/favorites.test.ts +5 -6
  110. package/src/installations/installations.test-d.ts +68 -0
  111. package/src/installations/installations.test.ts +62 -0
  112. package/src/installations/installations.ts +202 -0
  113. package/src/organization/organization.test-d.ts +36 -0
  114. package/src/organization/organization.test.ts +138 -0
  115. package/src/organization/organization.ts +138 -0
  116. package/src/organizations/organizations.test-d.ts +56 -0
  117. package/src/organizations/organizations.test.ts +150 -0
  118. package/src/organizations/organizations.ts +107 -0
  119. package/src/presence/bifurTransport.test.ts +46 -6
  120. package/src/presence/bifurTransport.ts +19 -2
  121. package/src/presence/presenceStore.test.ts +94 -23
  122. package/src/presence/presenceStore.ts +85 -29
  123. package/src/preview/getPreviewState.test.ts +137 -0
  124. package/src/preview/getPreviewState.ts +69 -0
  125. package/src/preview/previewProjectionUtils.test.ts +9 -22
  126. package/src/preview/previewProjectionUtils.ts +7 -3
  127. package/src/preview/resolvePreview.test.ts +64 -0
  128. package/src/preview/resolvePreview.ts +43 -0
  129. package/src/preview/types.ts +10 -0
  130. package/src/project/project.test-d.ts +37 -0
  131. package/src/project/project.test.ts +157 -12
  132. package/src/project/project.ts +138 -25
  133. package/src/projection/getProjectionState.test.ts +18 -20
  134. package/src/projection/getProjectionState.ts +23 -3
  135. package/src/projection/projectionQuery.ts +5 -5
  136. package/src/projection/projectionStore.test.ts +1 -1
  137. package/src/projection/resolveProjection.test.ts +1 -2
  138. package/src/projection/resolveProjection.ts +16 -0
  139. package/src/projection/subscribeToStateAndFetchBatches.test.ts +1 -1
  140. package/src/projection/subscribeToStateAndFetchBatches.ts +32 -23
  141. package/src/projection/types.ts +8 -0
  142. package/src/projects/projects.test-d.ts +32 -0
  143. package/src/projects/projects.test.ts +108 -42
  144. package/src/projects/projects.ts +63 -27
  145. package/src/query/queryStore.test.ts +259 -123
  146. package/src/query/queryStore.ts +78 -63
  147. package/src/query/reducers.test.ts +0 -42
  148. package/src/query/reducers.ts +2 -18
  149. package/src/releases/getPerspectiveState.test.ts +17 -23
  150. package/src/releases/getPerspectiveState.ts +8 -20
  151. package/src/releases/observeReleases.test.ts +127 -0
  152. package/src/releases/observeReleases.ts +102 -0
  153. package/src/releases/releasesStore.test.ts +100 -53
  154. package/src/releases/releasesStore.ts +69 -44
  155. package/src/releases/utils/sortReleases.test.ts +38 -2
  156. package/src/releases/utils/sortReleases.ts +15 -10
  157. package/src/store/createActionBinder.test.ts +87 -90
  158. package/src/store/createActionBinder.ts +79 -25
  159. package/src/store/createSanityInstance.test.ts +83 -13
  160. package/src/store/createSanityInstance.ts +77 -2
  161. package/src/store/createStateSourceAction.test.ts +64 -2
  162. package/src/store/createStateSourceAction.ts +39 -44
  163. package/src/store/createStoreInstance.test.ts +4 -2
  164. package/src/store/fetcherStore.test-d.ts +121 -0
  165. package/src/store/fetcherStore.test.ts +299 -0
  166. package/src/store/fetcherStore.ts +801 -0
  167. package/src/telemetry/environment.test.ts +119 -0
  168. package/src/telemetry/environment.ts +92 -0
  169. package/src/telemetry/events.ts +42 -0
  170. package/src/telemetry/initTelemetry.test.ts +432 -0
  171. package/src/telemetry/initTelemetry.ts +218 -0
  172. package/src/telemetry/telemetryManager.test.ts +327 -0
  173. package/src/telemetry/telemetryManager.ts +199 -0
  174. package/src/users/reducers.test.ts +6 -1
  175. package/src/users/reducers.ts +5 -6
  176. package/src/users/types.ts +4 -4
  177. package/src/users/usersStore.test.ts +16 -12
  178. package/src/users/usersStore.ts +5 -1
  179. package/src/utils/buildQuery.test.ts +14 -0
  180. package/src/utils/buildQuery.ts +17 -0
  181. package/src/utils/createFetcherStore.test.ts +7 -5
  182. package/src/utils/createFetcherStore.ts +8 -5
  183. package/src/utils/getStagingApiHost.test.ts +21 -0
  184. package/src/utils/getStagingApiHost.ts +14 -0
  185. package/src/utils/ids.test.ts +1 -29
  186. package/src/utils/ids.ts +0 -10
  187. package/src/utils/includeShape.ts +36 -0
  188. package/src/utils/isImportError.test.ts +72 -0
  189. package/src/utils/isImportError.ts +34 -0
  190. package/src/utils/logger.test.ts +12 -0
  191. package/src/utils/logger.ts +8 -3
  192. package/src/utils/object.test.ts +95 -0
  193. package/src/utils/object.ts +142 -0
  194. package/src/utils/setCleanupTimeout.ts +37 -0
  195. package/src/document/processActions.ts +0 -707
  196. package/src/utils/defineIntent.test.ts +0 -477
  197. package/src/utils/defineIntent.ts +0 -244
@@ -1,7 +1,7 @@
1
1
  import {type ChannelInput, type ChannelInstance} from '@sanity/comlink'
2
- import {isEqual} from 'lodash-es'
3
2
 
4
3
  import {type StoreContext} from '../../../store/defineStore'
4
+ import {isDeepEqual} from '../../../utils/object'
5
5
  import {type FrameMessage, type WindowMessage} from '../../types'
6
6
  import {type ComlinkControllerState} from '../comlinkControllerStore'
7
7
 
@@ -25,7 +25,7 @@ export const getOrCreateChannel = (
25
25
 
26
26
  // limit channels to one per name
27
27
  if (existing) {
28
- if (!isEqual(existing.options, options)) {
28
+ if (!isDeepEqual(existing.options, options)) {
29
29
  throw new Error(`Channel "${options.name}" already exists with different options`)
30
30
  }
31
31
 
@@ -21,7 +21,10 @@ describe('getOrCreateController', () => {
21
21
  let state: ReturnType<typeof createStoreState<ComlinkControllerState>>
22
22
 
23
23
  beforeEach(() => {
24
- instance = createSanityInstance()
24
+ instance = createSanityInstance({
25
+ projectId: 'test-project-id',
26
+ dataset: 'test-dataset',
27
+ })
25
28
 
26
29
  state = createStoreState<ComlinkControllerState>({
27
30
  controller: null,
@@ -29,7 +29,7 @@ describe('releaseChannel', () => {
29
29
  let releaseChannel: (inst: SanityInstance, channelName: string) => void
30
30
 
31
31
  beforeEach(() => {
32
- instance = createSanityInstance()
32
+ instance = createSanityInstance({projectId: 'test-project-id', dataset: 'test-dataset'})
33
33
  store = createStoreInstance(instance, key, comlinkControllerStore)
34
34
 
35
35
  const bind =
@@ -16,7 +16,10 @@ describe('comlinkControllerStore', () => {
16
16
  let instance: SanityInstance
17
17
  beforeEach(() => {
18
18
  vi.resetModules()
19
- instance = createSanityInstance()
19
+ instance = createSanityInstance({
20
+ projectId: 'test-project-id',
21
+ dataset: 'test-dataset',
22
+ })
20
23
  })
21
24
 
22
25
  afterEach(() => {
@@ -22,16 +22,22 @@ const nodeConfig = {
22
22
  }
23
23
 
24
24
  describe('getOrCreateNode', () => {
25
- const instance = createSanityInstance()
25
+ const instance = createSanityInstance({
26
+ projectId: 'test-project-id',
27
+ dataset: 'test-dataset',
28
+ })
26
29
  let state: ReturnType<typeof createStoreState<ComlinkNodeState>>
27
- let mockNode: Partial<Node<WindowMessage, FrameMessage>> & {
30
+ let mockNode: {
28
31
  start: ReturnType<typeof vi.fn>
29
32
  stop: ReturnType<typeof vi.fn>
33
+ onStatus: ReturnType<typeof vi.fn>
30
34
  }
31
35
 
32
36
  beforeEach(() => {
33
37
  mockNode = {start: vi.fn(), stop: vi.fn(), onStatus: vi.fn()}
34
- vi.mocked(comlink.createNode).mockReturnValue(mockNode as Node<WindowMessage, FrameMessage>)
38
+ vi.mocked(comlink.createNode).mockReturnValue(
39
+ mockNode as unknown as Node<WindowMessage, FrameMessage>,
40
+ )
35
41
  state = createStoreState<ComlinkNodeState>({nodes: new Map(), subscriptions: new Map()})
36
42
  vi.clearAllMocks()
37
43
  })
@@ -1,7 +1,7 @@
1
1
  import {createNode, type Node, type NodeInput} from '@sanity/comlink'
2
- import {isEqual} from 'lodash-es'
3
2
 
4
3
  import {type StoreContext} from '../../../store/defineStore'
4
+ import {isDeepEqual} from '../../../utils/object'
5
5
  import {type FrameMessage, type WindowMessage} from '../../types'
6
6
  import {type ComlinkNodeState} from '../comlinkNodeStore'
7
7
 
@@ -14,7 +14,7 @@ export const getOrCreateNode = (
14
14
 
15
15
  // limit nodes to one per name
16
16
  if (existing) {
17
- if (!isEqual(existing.options, options)) {
17
+ if (!isDeepEqual(existing.options, options)) {
18
18
  throw new Error(`Node "${options.name}" already exists with different options`)
19
19
  }
20
20
 
@@ -15,14 +15,17 @@ const nodeConfig = {
15
15
  describe('releaseNode', () => {
16
16
  let instance: SanityInstance
17
17
  let state: ReturnType<typeof createStoreState<ComlinkNodeState>>
18
- let mockNode: Partial<Node<WindowMessage, FrameMessage>> & {
18
+ let mockNode: {
19
19
  start: ReturnType<typeof vi.fn>
20
20
  stop: ReturnType<typeof vi.fn>
21
21
  onStatus: ReturnType<typeof vi.fn>
22
22
  }
23
23
 
24
24
  beforeEach(() => {
25
- instance = createSanityInstance()
25
+ instance = createSanityInstance({
26
+ projectId: 'test-project-id',
27
+ dataset: 'test-dataset',
28
+ })
26
29
  mockNode = {start: vi.fn(), stop: vi.fn(), onStatus: vi.fn()}
27
30
  state = createStoreState<ComlinkNodeState>({nodes: new Map(), subscriptions: new Map()})
28
31
  vi.clearAllMocks()
@@ -36,7 +39,7 @@ describe('releaseNode', () => {
36
39
  // Set up a node in the state
37
40
  const nodes = new Map()
38
41
  nodes.set('test-node', {
39
- node: mockNode as Node<WindowMessage, FrameMessage>,
42
+ node: mockNode as unknown as Node<WindowMessage, FrameMessage>,
40
43
  options: nodeConfig,
41
44
  })
42
45
  state.set('setup', {nodes})
@@ -55,7 +58,7 @@ describe('releaseNode', () => {
55
58
  const statusUnsub = vi.fn()
56
59
  const nodes = new Map()
57
60
  nodes.set('test-node', {
58
- node: mockNode as Node<WindowMessage, FrameMessage>,
61
+ node: mockNode as unknown as Node<WindowMessage, FrameMessage>,
59
62
  options: nodeConfig,
60
63
  statusUnsub,
61
64
  })
@@ -1,5 +1,5 @@
1
1
  import {type Node} from '@sanity/comlink'
2
- import {beforeEach, describe, expect, it, vi} from 'vitest'
2
+ import {beforeEach, describe, expect, it} from 'vitest'
3
3
 
4
4
  import {createSanityInstance, type SanityInstance} from '../../store/createSanityInstance'
5
5
  import {createStoreState} from '../../store/createStoreState'
@@ -10,7 +10,7 @@ describe('nodeStore', () => {
10
10
  let instance: SanityInstance
11
11
 
12
12
  beforeEach(() => {
13
- instance = createSanityInstance()
13
+ instance = createSanityInstance({projectId: 'test-project-id', dataset: 'test-dataset'})
14
14
  })
15
15
 
16
16
  it('should have correct initial state', () => {
@@ -23,7 +23,7 @@ describe('getNodeState', () => {
23
23
  let instance: ReturnType<typeof createSanityInstance>
24
24
 
25
25
  beforeEach(() => {
26
- instance = createSanityInstance()
26
+ instance = createSanityInstance({projectId: 'test', dataset: 'test'})
27
27
  })
28
28
 
29
29
  afterEach(() => {
@@ -3,6 +3,7 @@ import {createSelector} from 'reselect'
3
3
 
4
4
  import {bindActionGlobally} from '../../store/createActionBinder'
5
5
  import {createStateSourceAction, type SelectorContext} from '../../store/createStateSourceAction'
6
+ import {setCleanupTimeout} from '../../utils/setCleanupTimeout'
6
7
  import {type FrameMessage, type WindowMessage} from '../types'
7
8
  import {
8
9
  type ComlinkNodeState,
@@ -57,7 +58,7 @@ export const getNodeState = bindActionGlobally(
57
58
  subs.add(subscriberId)
58
59
 
59
60
  return () => {
60
- setTimeout(() => {
61
+ setCleanupTimeout(() => {
61
62
  const activeSubs = state.get().subscriptions.get(nodeName)
62
63
  if (activeSubs) {
63
64
  activeSubs.delete(subscriberId)
@@ -1,24 +1,30 @@
1
1
  import {describe, expect, it} from 'vitest'
2
2
 
3
- import {createDocumentHandle, createDocumentTypeHandle, createResourceHandle} from '../handles'
3
+ import {
4
+ createDatasetHandle,
5
+ createDocumentHandle,
6
+ createDocumentTypeHandle,
7
+ createProjectHandle,
8
+ } from '../handles'
4
9
 
5
10
  describe('handle creation functions', () => {
11
+ it('createProjectHandle returns input', () => {
12
+ const input = {projectId: 'test'}
13
+ expect(createProjectHandle(input)).toBe(input)
14
+ })
15
+
16
+ it('createDatasetHandle returns input', () => {
17
+ const input = {projectId: 'test', dataset: 'prod'}
18
+ expect(createDatasetHandle(input)).toBe(input)
19
+ })
20
+
6
21
  it('createDocumentTypeHandle returns input', () => {
7
- const input = {documentType: 'movie', resource: {projectId: 'p', dataset: 'd'}}
22
+ const input = {documentType: 'movie'}
8
23
  expect(createDocumentTypeHandle(input)).toBe(input)
9
24
  })
10
25
 
11
26
  it('createDocumentHandle returns input', () => {
12
- const input = {
13
- documentType: 'movie',
14
- documentId: '123',
15
- resource: {projectId: 'p', dataset: 'd'},
16
- }
27
+ const input = {documentType: 'movie', documentId: '123'}
17
28
  expect(createDocumentHandle(input)).toBe(input)
18
29
  })
19
-
20
- it('createResourceHandle returns input', () => {
21
- const input = {resource: {projectId: 'p', dataset: 'd'}}
22
- expect(createResourceHandle(input)).toBe(input)
23
- })
24
30
  })
@@ -1,4 +1,9 @@
1
- import {type DocumentHandle, type DocumentTypeHandle, type ResourceHandle} from './sanityConfig'
1
+ import {
2
+ type DatasetHandle,
3
+ type DocumentHandle,
4
+ type DocumentTypeHandle,
5
+ type ProjectHandle,
6
+ } from './sanityConfig'
2
7
 
3
8
  /**
4
9
  * Creates or validates a `DocumentHandle` object.
@@ -35,15 +40,28 @@ export function createDocumentTypeHandle<
35
40
  }
36
41
 
37
42
  /**
38
- * Creates or validates a `ResourceHandle` object.
39
- * Ensures the provided object conforms to the `ResourceHandle` interface.
40
- * @param handle - The object containing resource identification properties.
41
- * @returns The validated `ResourceHandle` object.
43
+ * Creates or validates a `ProjectHandle` object.
44
+ * Ensures the provided object conforms to the `ProjectHandle` interface.
45
+ * @param handle - The object containing project identification properties.
46
+ * @returns The validated `ProjectHandle` object.
42
47
  * @public
43
48
  */
44
- export function createResourceHandle<
49
+ export function createProjectHandle<TProjectId extends string = string>(
50
+ handle: ProjectHandle<TProjectId>,
51
+ ): ProjectHandle<TProjectId> {
52
+ return handle
53
+ }
54
+
55
+ /**
56
+ * Creates or validates a `DatasetHandle` object.
57
+ * Ensures the provided object conforms to the `DatasetHandle` interface.
58
+ * @param handle - The object containing dataset identification properties.
59
+ * @returns The validated `DatasetHandle` object.
60
+ * @public
61
+ */
62
+ export function createDatasetHandle<
45
63
  TDataset extends string = string,
46
64
  TProjectId extends string = string,
47
- >(handle: ResourceHandle<TProjectId, TDataset>): ResourceHandle<TProjectId, TDataset> {
65
+ >(handle: DatasetHandle<TDataset, TProjectId>): DatasetHandle<TDataset, TProjectId> {
48
66
  return handle
49
67
  }
@@ -40,12 +40,14 @@ export interface StudioConfig {
40
40
  */
41
41
  token?: TokenSource
42
42
  }
43
- /**
44
- * The project ID for this Studio workspace.
45
- * Used to derive the localStorage key for studio auth token discovery
46
- * (`__studio_auth_token_<projectId>`) and for project-specific API hostname requests.
47
- */
48
- projectId?: string
43
+ }
44
+
45
+ /**
46
+ * Represents the minimal configuration required to identify a Sanity project.
47
+ * @public
48
+ */
49
+ export interface ProjectHandle<TProjectId extends string = string> {
50
+ projectId?: TProjectId
49
51
  }
50
52
 
51
53
  /**
@@ -60,27 +62,25 @@ export type ReleasePerspective = {
60
62
  * @public
61
63
  */
62
64
  export interface PerspectiveHandle {
63
- /**
64
- * The perspective to use for this operation.
65
- * Note that the SDK stacks perspectives for you when querying.
66
- * The SDK automatically fetches all of your content releases, and orders them the way the Sanity Studio does: usually by scheduled date, with ASAP releases coming first.
67
- * @public
68
- */
69
- perspective?: Exclude<ClientPerspective, readonly unknown[]> | ReleasePerspective
65
+ perspective?: ClientPerspective | ReleasePerspective
70
66
  }
71
67
 
72
68
  /**
73
69
  * @public
74
70
  */
75
- export interface ResourceHandle<
76
- TProjectId extends string = string,
77
- TDataset extends string = string,
78
- > extends PerspectiveHandle {
71
+ export interface DatasetHandle<TDataset extends string = string, TProjectId extends string = string>
72
+ extends ProjectHandle<TProjectId>, PerspectiveHandle {
73
+ dataset?: TDataset
79
74
  /**
75
+ * @beta
80
76
  * Explicit resource object to use for this operation.
81
- * @public
82
77
  */
83
- resource: DocumentResource<TProjectId, TDataset>
78
+ resource?: DocumentResource
79
+ /**
80
+ * @deprecated Use `resource` instead.
81
+ * @beta
82
+ */
83
+ source?: DocumentResource
84
84
  }
85
85
 
86
86
  /**
@@ -93,7 +93,7 @@ export interface DocumentTypeHandle<
93
93
  TDocumentType extends string = string,
94
94
  TDataset extends string = string,
95
95
  TProjectId extends string = string,
96
- > extends ResourceHandle<TDataset, TProjectId> {
96
+ > extends DatasetHandle<TDataset, TProjectId> {
97
97
  documentId?: string
98
98
  documentType: TDocumentType
99
99
  /**
@@ -119,42 +119,22 @@ export interface DocumentHandle<
119
119
  }
120
120
 
121
121
  /**
122
- * The key used to identify the default resource in a resources map.
123
- * When no `resource` or `resourceName` is specified, the SDK resolves
124
- * the resource registered under this name.
125
- *
126
- * @public
122
+ * Identifies a release within a Sanity dataset and project. `releaseId` is the
123
+ * `name` parameter on the release document (e.g. `{name: 'r41035a4'}`).
124
+ * The underlying release document ID is `_.releases.<releaseId>`.
125
+ * It's also the `id` parameter sent to the Actions API.
126
+ * (This type doesn't need to have ProjectId / Dataset generics since it's always the same shape)
127
+ * @beta
127
128
  */
128
- export const DEFAULT_RESOURCE_NAME = 'default'
129
+ export interface ReleaseHandle extends DatasetHandle {
130
+ releaseId: string
131
+ }
129
132
 
130
133
  /**
131
- * Represents the complete configuration for a Sanity SDK instance.
132
- *
133
- * Most apps configure resources via the `resources` prop on `SanityApp`:
134
- *
135
- * @example Typical React usage
136
- * ```tsx
137
- * <SanityApp
138
- * resources={{ default: { projectId: 'abc123', dataset: 'production' } }}
139
- * fallback={<Loading />}
140
- * >
141
- * <App />
142
- * </SanityApp>
143
- * ```
144
- *
145
- * The `defaultResource` field is set automatically by the React layer from
146
- * `resources['default']`. It can also be set directly when using the core
147
- * SDK without React (e.g. in a Node.js script):
148
- *
149
- * @example Direct core usage (without React)
150
- * ```ts
151
- * const instance = createSanityInstance({
152
- * defaultResource: { projectId: 'abc123', dataset: 'production' },
153
- * })
154
- * ```
134
+ * Represents the complete configuration for a Sanity SDK instance
155
135
  * @public
156
136
  */
157
- export interface SanityConfig extends PerspectiveHandle {
137
+ export interface SanityConfig extends DatasetHandle, PerspectiveHandle {
158
138
  /**
159
139
  * Authentication configuration for the instance
160
140
  */
@@ -168,58 +148,61 @@ export interface SanityConfig extends PerspectiveHandle {
168
148
  * `SDKStudioContext` provider. Can also be set explicitly for programmatic use.
169
149
  */
170
150
  studio?: StudioConfig
151
+
171
152
  /**
172
- * The default document resource for this instance. Used by bound actions
173
- * when no explicit resource is provided.
174
- *
175
- * @public
153
+ * Studio mode configuration for use of the SDK in a Sanity Studio.
154
+ * @remarks Controls whether studio mode features are enabled.
155
+ * @deprecated Use `studio` instead, which provides richer integration
156
+ * with the Studio's workspace (auth token sync, etc.).
157
+ */
158
+ studioMode?: {
159
+ enabled: boolean
160
+ }
161
+
162
+ /**
163
+ * @beta
164
+ * A list of named resources to use for this instance.
165
+ */
166
+ resources?: Record<string, DocumentResource>
167
+ /**
168
+ * @deprecated Use `resources` instead.
169
+ * @beta
176
170
  */
177
- defaultResource?: DocumentResource
171
+ sources?: Record<string, DocumentResource>
178
172
  }
179
173
 
180
174
  /**
181
- * A document resource identifies where data is stored and queried from.
182
- * Can be a dataset (project + dataset pair), a media library, or a canvas.
175
+ * A document resource can be used for querying.
176
+ * This will soon be the default way to identify where you are querying from.
183
177
  *
184
- * @public
178
+ * @beta
185
179
  */
186
- export type DocumentResource<
187
- TProjectId extends string = string,
188
- TDataset extends string = string,
189
- > = DatasetResource<TProjectId, TDataset> | MediaLibraryResource | CanvasResource
180
+ export type DocumentResource = DatasetResource | MediaLibraryResource | CanvasResource
190
181
 
191
182
  /**
192
- * A resource that targets a specific project and dataset.
193
- * @public
183
+ * @beta
194
184
  */
195
- export type DatasetResource<
196
- TProjectId extends string = string,
197
- TDataset extends string = string,
198
- > = {projectId: TProjectId; dataset: TDataset}
185
+ export type DatasetResource = {projectId: string; dataset: string}
199
186
 
200
187
  /**
201
- * A resource that targets a media library.
202
- * @public
188
+ * @beta
203
189
  */
204
190
  export type MediaLibraryResource = {mediaLibraryId: string}
205
191
 
206
192
  /**
207
- * A resource that targets a canvas.
208
- * @public
193
+ * @beta
209
194
  */
210
195
  export type CanvasResource = {canvasId: string}
211
196
 
212
197
  /**
213
- * Type guard that checks whether a {@link DocumentResource} is a {@link DatasetResource}.
214
- * @public
198
+ * @beta
215
199
  */
216
200
  export function isDatasetResource(resource: DocumentResource): resource is DatasetResource {
217
201
  return 'projectId' in resource && 'dataset' in resource
218
202
  }
219
203
 
220
204
  /**
221
- * Type guard that checks whether a {@link DocumentResource} is a {@link MediaLibraryResource}.
222
- * @public
205
+ * @beta
223
206
  */
224
207
  export function isMediaLibraryResource(
225
208
  resource: DocumentResource,
@@ -228,9 +211,56 @@ export function isMediaLibraryResource(
228
211
  }
229
212
 
230
213
  /**
231
- * Type guard that checks whether a {@link DocumentResource} is a {@link CanvasResource}.
232
- * @public
214
+ * @beta
233
215
  */
234
216
  export function isCanvasResource(resource: DocumentResource): resource is CanvasResource {
235
217
  return 'canvasId' in resource
236
218
  }
219
+
220
+ /**
221
+ * @deprecated Use `DocumentResource` instead.
222
+ * @beta
223
+ */
224
+ export type DocumentSource = DocumentResource
225
+
226
+ /**
227
+ * @deprecated Use `DatasetResource` instead.
228
+ * @beta
229
+ */
230
+ export type DatasetSource = DatasetResource
231
+
232
+ /**
233
+ * @deprecated Use `MediaLibraryResource` instead.
234
+ * @beta
235
+ */
236
+ export type MediaLibrarySource = MediaLibraryResource
237
+
238
+ /**
239
+ * @deprecated Use `CanvasResource` instead.
240
+ * @beta
241
+ */
242
+ export type CanvasSource = CanvasResource
243
+
244
+ /**
245
+ * @deprecated Use `isDatasetResource` instead.
246
+ * @beta
247
+ */
248
+ export function isDatasetSource(source: DocumentSource): source is DatasetSource {
249
+ return isDatasetResource(source)
250
+ }
251
+
252
+ /**
253
+ * @deprecated Use `isMediaLibraryResource` instead.
254
+ * @beta
255
+ */
256
+ export function isMediaLibrarySource(source: DocumentSource): source is MediaLibrarySource {
257
+ return isMediaLibraryResource(source)
258
+ }
259
+
260
+ /**
261
+ * @deprecated Use `isCanvasResource` instead.
262
+ * @beta
263
+ */
264
+ export function isCanvasSource(source: DocumentSource): source is CanvasSource {
265
+ return isCanvasResource(source)
266
+ }
@@ -11,7 +11,7 @@ vi.mock('../client/clientStore')
11
11
 
12
12
  describe('datasets', () => {
13
13
  it('calls the `client.observable.datasets.list` method on the client and returns the result', async () => {
14
- const instance = createSanityInstance()
14
+ const instance = createSanityInstance({projectId: 'p', dataset: 'd'})
15
15
  const datasets = [{id: 'a'}, {id: 'b'}]
16
16
  const list = vi.fn().mockReturnValue(of(datasets))
17
17
 
@@ -25,7 +25,7 @@ describe('datasets', () => {
25
25
  observable: of(mockClient),
26
26
  } as StateSource<SanityClient>)
27
27
 
28
- const result = await resolveDatasets(instance, {projectId: 'p'})
28
+ const result = await resolveDatasets(instance)
29
29
  expect(result).toEqual(datasets)
30
30
  expect(list).toHaveBeenCalled()
31
31
  })
@@ -1,6 +1,7 @@
1
1
  import {switchMap} from 'rxjs'
2
2
 
3
3
  import {getClientState} from '../client/clientStore'
4
+ import {type ProjectHandle} from '../config/sanityConfig'
4
5
  import {createFetcherStore} from '../utils/createFetcherStore'
5
6
 
6
7
  const API_VERSION = 'v2025-02-19'
@@ -8,13 +9,18 @@ const API_VERSION = 'v2025-02-19'
8
9
  /** @public */
9
10
  export const datasets = createFetcherStore({
10
11
  name: 'Datasets',
11
- getKey: (_instance, options: {projectId: string}) => {
12
- return options.projectId
12
+ getKey: (instance, options?: ProjectHandle) => {
13
+ const projectId = options?.projectId ?? instance.config.projectId
14
+ if (!projectId) {
15
+ throw new Error('A projectId is required to use the project API.')
16
+ }
17
+ return projectId
13
18
  },
14
- fetcher: (instance) => (options: {projectId: string}) => {
19
+ fetcher: (instance) => (options?: ProjectHandle) => {
15
20
  return getClientState(instance, {
16
21
  apiVersion: API_VERSION,
17
- projectId: options.projectId,
22
+ // non-null assertion is fine because we check above
23
+ projectId: (options?.projectId ?? instance.config.projectId)!,
18
24
  useProjectHostname: true,
19
25
  }).observable.pipe(switchMap((client) => client.observable.datasets.list()))
20
26
  },