@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.
- package/dist/_chunks-dts/createGroqSearchFilter.d.ts +1147 -0
- package/dist/_chunks-dts/createGroqSearchFilter.d.ts.map +1 -0
- package/dist/_chunks-es/_internal.js +134 -0
- package/dist/_chunks-es/_internal.js.map +1 -0
- package/dist/_chunks-es/createGroqSearchFilter.js +1864 -0
- package/dist/_chunks-es/createGroqSearchFilter.js.map +1 -0
- package/dist/_chunks-es/telemetryManager.js +93 -0
- package/dist/_chunks-es/telemetryManager.js.map +1 -0
- package/dist/_exports/_internal.d.ts +95 -0
- package/dist/_exports/_internal.d.ts.map +1 -0
- package/dist/_exports/_internal.js +24 -0
- package/dist/_exports/_internal.js.map +1 -0
- package/dist/index.d.ts +1079 -1076
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1967 -2302
- package/dist/index.js.map +1 -1
- package/package.json +48 -47
- package/src/_exports/_internal.ts +26 -0
- package/src/_exports/index.ts +120 -11
- package/src/access/checkPermissions.test.ts +55 -0
- package/src/access/checkPermissions.ts +54 -0
- package/src/agent/agentActions.test.ts +16 -60
- package/src/agent/agentActions.ts +25 -38
- package/src/applications/applications.test-d.ts +83 -0
- package/src/applications/applications.test.ts +130 -0
- package/src/applications/applications.ts +364 -0
- package/src/applications/userApplications.test.ts +126 -0
- package/src/applications/userApplications.ts +261 -0
- package/src/auth/authLogger.ts +30 -0
- package/src/auth/authMode.test.ts +25 -0
- package/src/auth/authMode.ts +6 -3
- package/src/auth/authStore.test.ts +194 -13
- package/src/auth/authStore.ts +59 -26
- package/src/auth/getOrganizationVerificationState.test.ts +18 -17
- package/src/auth/getOrganizationVerificationState.ts +4 -4
- package/src/auth/handleAuthCallback.test.ts +35 -1
- package/src/auth/handleAuthCallback.ts +25 -6
- package/src/auth/logout.test.ts +75 -2
- package/src/auth/logout.ts +23 -4
- package/src/auth/refreshStampedToken.test.ts +219 -469
- package/src/auth/refreshStampedToken.ts +79 -195
- package/src/auth/studioAuth.ts +1 -1
- package/src/auth/studioModeAuth.ts +2 -1
- package/src/auth/subscribeToStateAndFetchCurrentUser.test.ts +146 -13
- package/src/auth/subscribeToStateAndFetchCurrentUser.ts +37 -6
- package/src/auth/subscribeToStorageEventsAndSetToken.test.ts +2 -0
- package/src/client/clientStore.test.ts +62 -37
- package/src/client/clientStore.ts +45 -75
- package/src/client/liveEvents.test.ts +151 -0
- package/src/client/liveEvents.ts +107 -0
- package/src/comlink/controller/actions/destroyController.test.ts +4 -1
- package/src/comlink/controller/actions/getOrCreateChannel.test.ts +4 -1
- package/src/comlink/controller/actions/getOrCreateChannel.ts +2 -2
- package/src/comlink/controller/actions/getOrCreateController.test.ts +4 -1
- package/src/comlink/controller/actions/releaseChannel.test.ts +1 -1
- package/src/comlink/controller/comlinkControllerStore.test.ts +4 -1
- package/src/comlink/node/actions/getOrCreateNode.test.ts +9 -3
- package/src/comlink/node/actions/getOrCreateNode.ts +2 -2
- package/src/comlink/node/actions/releaseNode.test.ts +7 -4
- package/src/comlink/node/comlinkNodeStore.test.ts +2 -2
- package/src/comlink/node/getNodeState.test.ts +1 -1
- package/src/comlink/node/getNodeState.ts +2 -1
- package/src/config/__tests__/handles.test.ts +18 -12
- package/src/config/handles.ts +25 -7
- package/src/config/sanityConfig.ts +109 -79
- package/src/datasets/datasets.test.ts +2 -2
- package/src/datasets/datasets.ts +10 -4
- package/src/document/actions.test.ts +115 -33
- package/src/document/actions.ts +212 -15
- package/src/document/applyDocumentActions.test.ts +38 -12
- package/src/document/applyDocumentActions.ts +30 -9
- package/src/document/documentConstants.ts +7 -0
- package/src/document/documentStore.concurrency.test.ts +1306 -0
- package/src/document/documentStore.test.ts +673 -278
- package/src/document/documentStore.ts +162 -71
- package/src/document/events.test.ts +57 -2
- package/src/document/events.ts +82 -26
- package/src/document/listen.test.ts +56 -0
- package/src/document/listen.ts +74 -21
- package/src/document/listenerEventOperators.test.ts +311 -0
- package/src/document/listenerEventOperators.ts +217 -0
- package/src/document/patchOperations.test.ts +49 -2
- package/src/document/patchOperations.ts +50 -0
- package/src/document/permissions.test.ts +105 -60
- package/src/document/permissions.ts +44 -19
- package/src/document/processActions/create.ts +138 -0
- package/src/document/processActions/delete.ts +100 -0
- package/src/document/processActions/discard.ts +63 -0
- package/src/document/processActions/edit.ts +154 -0
- package/src/document/processActions/processActions.ts +218 -0
- package/src/document/processActions/publish.ts +120 -0
- package/src/document/processActions/releaseArchive.ts +77 -0
- package/src/document/processActions/releaseCreate.ts +59 -0
- package/src/document/processActions/releaseDelete.ts +65 -0
- package/src/document/processActions/releaseEdit.ts +37 -0
- package/src/document/processActions/releasePublish.ts +45 -0
- package/src/document/processActions/releaseSchedule.ts +87 -0
- package/src/document/processActions/releaseUtil.ts +31 -0
- package/src/document/processActions/shared.ts +308 -0
- package/src/document/processActions/unpublish.ts +85 -0
- package/src/document/processActions.test.ts +1129 -121
- package/src/document/reducers.test.ts +639 -64
- package/src/document/reducers.ts +187 -48
- package/src/document/resourceRules.test.ts +178 -0
- package/src/document/resourceRules.ts +117 -0
- package/src/document/sharedListener.test.ts +16 -14
- package/src/document/sharedListener.ts +24 -8
- package/src/document/util.ts +14 -0
- package/src/favorites/favorites.test.ts +5 -6
- package/src/installations/installations.test-d.ts +68 -0
- package/src/installations/installations.test.ts +62 -0
- package/src/installations/installations.ts +202 -0
- package/src/organization/organization.test-d.ts +36 -0
- package/src/organization/organization.test.ts +138 -0
- package/src/organization/organization.ts +138 -0
- package/src/organizations/organizations.test-d.ts +56 -0
- package/src/organizations/organizations.test.ts +150 -0
- package/src/organizations/organizations.ts +107 -0
- package/src/presence/bifurTransport.test.ts +46 -6
- package/src/presence/bifurTransport.ts +19 -2
- package/src/presence/presenceStore.test.ts +94 -23
- package/src/presence/presenceStore.ts +85 -29
- package/src/preview/getPreviewState.test.ts +137 -0
- package/src/preview/getPreviewState.ts +69 -0
- package/src/preview/previewProjectionUtils.test.ts +9 -22
- package/src/preview/previewProjectionUtils.ts +7 -3
- package/src/preview/resolvePreview.test.ts +64 -0
- package/src/preview/resolvePreview.ts +43 -0
- package/src/preview/types.ts +10 -0
- package/src/project/project.test-d.ts +37 -0
- package/src/project/project.test.ts +157 -12
- package/src/project/project.ts +138 -25
- package/src/projection/getProjectionState.test.ts +18 -20
- package/src/projection/getProjectionState.ts +23 -3
- package/src/projection/projectionQuery.ts +5 -5
- package/src/projection/projectionStore.test.ts +1 -1
- package/src/projection/resolveProjection.test.ts +1 -2
- package/src/projection/resolveProjection.ts +16 -0
- package/src/projection/subscribeToStateAndFetchBatches.test.ts +1 -1
- package/src/projection/subscribeToStateAndFetchBatches.ts +32 -23
- package/src/projection/types.ts +8 -0
- package/src/projects/projects.test-d.ts +32 -0
- package/src/projects/projects.test.ts +108 -42
- package/src/projects/projects.ts +63 -27
- package/src/query/queryStore.test.ts +259 -123
- package/src/query/queryStore.ts +78 -63
- package/src/query/reducers.test.ts +0 -42
- package/src/query/reducers.ts +2 -18
- package/src/releases/getPerspectiveState.test.ts +17 -23
- package/src/releases/getPerspectiveState.ts +8 -20
- package/src/releases/observeReleases.test.ts +127 -0
- package/src/releases/observeReleases.ts +102 -0
- package/src/releases/releasesStore.test.ts +100 -53
- package/src/releases/releasesStore.ts +69 -44
- package/src/releases/utils/sortReleases.test.ts +38 -2
- package/src/releases/utils/sortReleases.ts +15 -10
- package/src/store/createActionBinder.test.ts +87 -90
- package/src/store/createActionBinder.ts +79 -25
- package/src/store/createSanityInstance.test.ts +83 -13
- package/src/store/createSanityInstance.ts +77 -2
- package/src/store/createStateSourceAction.test.ts +64 -2
- package/src/store/createStateSourceAction.ts +39 -44
- package/src/store/createStoreInstance.test.ts +4 -2
- package/src/store/fetcherStore.test-d.ts +121 -0
- package/src/store/fetcherStore.test.ts +299 -0
- package/src/store/fetcherStore.ts +801 -0
- package/src/telemetry/environment.test.ts +119 -0
- package/src/telemetry/environment.ts +92 -0
- package/src/telemetry/events.ts +42 -0
- package/src/telemetry/initTelemetry.test.ts +432 -0
- package/src/telemetry/initTelemetry.ts +218 -0
- package/src/telemetry/telemetryManager.test.ts +327 -0
- package/src/telemetry/telemetryManager.ts +199 -0
- package/src/users/reducers.test.ts +6 -1
- package/src/users/reducers.ts +5 -6
- package/src/users/types.ts +4 -4
- package/src/users/usersStore.test.ts +16 -12
- package/src/users/usersStore.ts +5 -1
- package/src/utils/buildQuery.test.ts +14 -0
- package/src/utils/buildQuery.ts +17 -0
- package/src/utils/createFetcherStore.test.ts +7 -5
- package/src/utils/createFetcherStore.ts +8 -5
- package/src/utils/getStagingApiHost.test.ts +21 -0
- package/src/utils/getStagingApiHost.ts +14 -0
- package/src/utils/ids.test.ts +1 -29
- package/src/utils/ids.ts +0 -10
- package/src/utils/includeShape.ts +36 -0
- package/src/utils/isImportError.test.ts +72 -0
- package/src/utils/isImportError.ts +34 -0
- package/src/utils/logger.test.ts +12 -0
- package/src/utils/logger.ts +8 -3
- package/src/utils/object.test.ts +95 -0
- package/src/utils/object.ts +142 -0
- package/src/utils/setCleanupTimeout.ts +37 -0
- package/src/document/processActions.ts +0 -707
- package/src/utils/defineIntent.test.ts +0 -477
- package/src/utils/defineIntent.ts +0 -244
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
// applyDocumentActions.test.ts
|
|
2
1
|
import {type SanityDocument} from '@sanity/types'
|
|
3
2
|
import {Subject} from 'rxjs'
|
|
4
3
|
import {describe, expect, it} from 'vitest'
|
|
5
4
|
|
|
6
5
|
import {bindActionByResource} from '../store/createActionBinder'
|
|
7
6
|
import {createSanityInstance, type SanityInstance} from '../store/createSanityInstance'
|
|
8
|
-
import {} from '../store/createStateSourceAction'
|
|
9
7
|
import {createStoreState, type StoreState} from '../store/createStoreState'
|
|
10
8
|
import {type DocumentAction} from './actions'
|
|
11
9
|
import {type DocumentStoreState} from './documentStore'
|
|
@@ -47,7 +45,7 @@ describe('applyDocumentActions', () => {
|
|
|
47
45
|
events: eventsSubject,
|
|
48
46
|
}
|
|
49
47
|
state = createStoreState(initialState)
|
|
50
|
-
instance = createSanityInstance()
|
|
48
|
+
instance = createSanityInstance({projectId: 'p', dataset: 'd'})
|
|
51
49
|
const key = {name: 'p.d', resource: {projectId: 'p', dataset: 'd'}}
|
|
52
50
|
|
|
53
51
|
vi.mocked(bindActionByResource).mockImplementation(
|
|
@@ -69,7 +67,6 @@ describe('applyDocumentActions', () => {
|
|
|
69
67
|
documentId: 'doc1',
|
|
70
68
|
documentType: 'example',
|
|
71
69
|
patches: [{set: {foo: 'bar'}}],
|
|
72
|
-
resource: {projectId: 'p', dataset: 'd'},
|
|
73
70
|
}
|
|
74
71
|
|
|
75
72
|
// Call applyDocumentActions with a fixed transactionId for reproducibility.
|
|
@@ -128,7 +125,6 @@ describe('applyDocumentActions', () => {
|
|
|
128
125
|
documentId: 'doc1',
|
|
129
126
|
documentType: 'example',
|
|
130
127
|
patches: [{set: {foo: 'error'}}],
|
|
131
|
-
resource: {projectId: 'p', dataset: 'd'},
|
|
132
128
|
}
|
|
133
129
|
|
|
134
130
|
// Call applyDocumentActions with a fixed transactionId.
|
|
@@ -150,18 +146,23 @@ describe('applyDocumentActions', () => {
|
|
|
150
146
|
await expect(applyPromise).rejects.toThrow('Simulated error')
|
|
151
147
|
})
|
|
152
148
|
|
|
153
|
-
it('
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
149
|
+
it('matches parent instance via child when action projectId and dataset do not match child config', async () => {
|
|
150
|
+
// Create a parent instance
|
|
151
|
+
const parentInstance = createSanityInstance({projectId: 'p', dataset: 'd'})
|
|
152
|
+
// Create a child instance with different config
|
|
153
|
+
const childInstance = parentInstance.createChild({projectId: 'child-p', dataset: 'child-d'})
|
|
154
|
+
// Use the child instance in context
|
|
155
|
+
// Create an action that refers to the parent's configuration
|
|
157
156
|
const action: DocumentAction = {
|
|
158
157
|
type: 'document.edit',
|
|
159
158
|
documentId: 'doc1',
|
|
160
159
|
documentType: 'example',
|
|
161
160
|
patches: [{set: {foo: 'childTest'}}],
|
|
162
|
-
|
|
161
|
+
projectId: 'p',
|
|
162
|
+
dataset: 'd',
|
|
163
163
|
}
|
|
164
|
-
|
|
164
|
+
// Call applyDocumentActions with the context using childInstance, but with action requiring parent's config
|
|
165
|
+
const applyPromise = applyDocumentActions(childInstance, {
|
|
165
166
|
actions: [action],
|
|
166
167
|
transactionId: 'txn-child-match',
|
|
167
168
|
resource: {projectId: 'p', dataset: 'd'},
|
|
@@ -198,6 +199,31 @@ describe('applyDocumentActions', () => {
|
|
|
198
199
|
const submittedResult = await result.submitted()
|
|
199
200
|
expect(submittedResult).toEqual(acceptedResult)
|
|
200
201
|
|
|
201
|
-
|
|
202
|
+
childInstance.dispose()
|
|
203
|
+
parentInstance.dispose()
|
|
204
|
+
})
|
|
205
|
+
|
|
206
|
+
it('normalizes actions for the bound resource before queueing', async () => {
|
|
207
|
+
// A plain edit action with no `liveEdit` flag. Canvas forces liveEdit, so
|
|
208
|
+
// the queued action should come back with `liveEdit: true` — proving that
|
|
209
|
+
// `applyDocumentActions` runs `normalizeActionsForResource`.
|
|
210
|
+
const action: DocumentAction = {
|
|
211
|
+
type: 'document.edit',
|
|
212
|
+
documentId: 'doc1',
|
|
213
|
+
documentType: 'sanity.canvas.document',
|
|
214
|
+
patches: [{set: {foo: 'bar'}}],
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
// Don't await — we only need to inspect the synchronously-queued transaction.
|
|
218
|
+
applyDocumentActions(instance, {
|
|
219
|
+
actions: [action],
|
|
220
|
+
transactionId: 'txn-normalize',
|
|
221
|
+
resource: {canvasId: 'c'},
|
|
222
|
+
})
|
|
223
|
+
|
|
224
|
+
const queued = state.get().queued.find((t) => t.transactionId === 'txn-normalize')
|
|
225
|
+
expect(queued).toBeDefined()
|
|
226
|
+
const [queuedAction] = queued!.actions
|
|
227
|
+
expect(queuedAction).toMatchObject({type: 'document.edit', liveEdit: true})
|
|
202
228
|
})
|
|
203
229
|
})
|
|
@@ -1,15 +1,16 @@
|
|
|
1
|
-
import {type
|
|
2
|
-
import {type SanityDocument} from '@sanity/types'
|
|
1
|
+
import {type SanityDocument} from 'groq'
|
|
3
2
|
import {distinctUntilChanged, filter, first, firstValueFrom, map, race} from 'rxjs'
|
|
4
3
|
|
|
5
4
|
import {type DocumentResource} from '../config/sanityConfig'
|
|
6
5
|
import {bindActionByResource} from '../store/createActionBinder'
|
|
7
6
|
import {type SanityInstance} from '../store/createSanityInstance'
|
|
8
7
|
import {type StoreContext} from '../store/defineStore'
|
|
9
|
-
import {type
|
|
8
|
+
import {type Action} from './actions'
|
|
10
9
|
import {documentStore, type DocumentStoreState} from './documentStore'
|
|
10
|
+
import {type DocumentTransactionSubmissionResult} from './events'
|
|
11
11
|
import {type DocumentSet} from './processMutations'
|
|
12
12
|
import {type AppliedTransaction, type QueuedTransaction, queueTransaction} from './reducers'
|
|
13
|
+
import {normalizeActionsForResource} from './resourceRules'
|
|
13
14
|
|
|
14
15
|
/** @beta */
|
|
15
16
|
export interface ActionsResult<TDocument extends SanityDocument = SanityDocument> {
|
|
@@ -20,20 +21,21 @@ export interface ActionsResult<TDocument extends SanityDocument = SanityDocument
|
|
|
20
21
|
appeared: string[]
|
|
21
22
|
updated: string[]
|
|
22
23
|
disappeared: string[]
|
|
23
|
-
submitted: () =>
|
|
24
|
+
submitted: () => Promise<DocumentTransactionSubmissionResult>
|
|
24
25
|
}
|
|
25
26
|
|
|
26
27
|
/** @beta */
|
|
27
28
|
export interface ApplyDocumentActionsOptions {
|
|
28
29
|
/**
|
|
29
|
-
* List of actions to apply.
|
|
30
|
+
* List of actions to apply. Accepts both document actions and release
|
|
31
|
+
* lifecycle actions because they share the same transaction pipeline.
|
|
30
32
|
*/
|
|
31
|
-
actions:
|
|
33
|
+
actions: Action[]
|
|
32
34
|
|
|
33
35
|
/**
|
|
34
36
|
* The resource to which the documents being acted on belong.
|
|
35
37
|
*/
|
|
36
|
-
resource
|
|
38
|
+
resource?: DocumentResource
|
|
37
39
|
|
|
38
40
|
/**
|
|
39
41
|
* Optionally provide an ID to be used as this transaction ID
|
|
@@ -45,6 +47,15 @@ export interface ApplyDocumentActionsOptions {
|
|
|
45
47
|
disableBatching?: boolean
|
|
46
48
|
}
|
|
47
49
|
|
|
50
|
+
/** @beta */
|
|
51
|
+
export function applyDocumentActions<
|
|
52
|
+
TDocumentType extends string = string,
|
|
53
|
+
TDataset extends string = string,
|
|
54
|
+
TProjectId extends string = string,
|
|
55
|
+
>(
|
|
56
|
+
instance: SanityInstance,
|
|
57
|
+
options: ApplyDocumentActionsOptions,
|
|
58
|
+
): Promise<ActionsResult<SanityDocument<TDocumentType, `${TProjectId}.${TDataset}`>>>
|
|
48
59
|
/** @beta */
|
|
49
60
|
export function applyDocumentActions(
|
|
50
61
|
instance: SanityInstance,
|
|
@@ -63,13 +74,23 @@ const boundApplyDocumentActions = bindActionByResource(documentStore, _applyDocu
|
|
|
63
74
|
/** @internal */
|
|
64
75
|
async function _applyDocumentActions(
|
|
65
76
|
{state}: StoreContext<DocumentStoreState>,
|
|
66
|
-
{
|
|
77
|
+
{
|
|
78
|
+
actions,
|
|
79
|
+
resource,
|
|
80
|
+
transactionId = crypto.randomUUID(),
|
|
81
|
+
disableBatching,
|
|
82
|
+
}: ApplyDocumentActionsOptions,
|
|
67
83
|
): Promise<ActionsResult> {
|
|
68
84
|
const {events} = state.get()
|
|
69
85
|
|
|
86
|
+
// Rewrite edit actions to match the bound resource's editing model (e.g.
|
|
87
|
+
// forcing liveEdit for Canvas, stripping unsupported release perspectives).
|
|
88
|
+
// Non-edit and release actions pass through unchanged.
|
|
89
|
+
const normalizedActions = normalizeActionsForResource(actions, resource)
|
|
90
|
+
|
|
70
91
|
const transaction: QueuedTransaction = {
|
|
71
92
|
transactionId,
|
|
72
|
-
actions,
|
|
93
|
+
actions: normalizedActions,
|
|
73
94
|
...(disableBatching && {disableBatching}),
|
|
74
95
|
}
|
|
75
96
|
|
|
@@ -8,3 +8,10 @@
|
|
|
8
8
|
export const DOCUMENT_STATE_CLEAR_DELAY = 1000
|
|
9
9
|
export const INITIAL_OUTGOING_THROTTLE_TIME = 1000
|
|
10
10
|
export const API_VERSION = 'v2025-05-06'
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Base delay (ms) before retrying a document listener after an `OutOfSyncError`.
|
|
14
|
+
* Backoff doubles on each successive retry, capped at {@link OUT_OF_SYNC_RETRY_MAX_DELAY}.
|
|
15
|
+
*/
|
|
16
|
+
export const OUT_OF_SYNC_RETRY_BASE_DELAY = 500
|
|
17
|
+
export const OUT_OF_SYNC_RETRY_MAX_DELAY = 10_000
|