@sanity/sdk 3.0.0-rc.0 → 3.0.0-rc.2
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/README.md +12 -0
- package/dist/_exports/_internal.d.ts +163 -0
- package/dist/_exports/_internal.d.ts.map +1 -0
- package/dist/_exports/_internal.js +332 -0
- package/dist/_exports/_internal.js.map +1 -0
- package/dist/_exports/agent.d.ts +65 -0
- package/dist/_exports/agent.d.ts.map +1 -0
- package/dist/_exports/agent.js +71 -0
- package/dist/_exports/agent.js.map +1 -0
- package/dist/_exports/comlink.d.ts +118 -0
- package/dist/_exports/comlink.d.ts.map +1 -0
- package/dist/_exports/comlink.js +69 -0
- package/dist/_exports/comlink.js.map +1 -0
- package/dist/authStore-CtE9bLHW.js +754 -0
- package/dist/authStore-CtE9bLHW.js.map +1 -0
- package/dist/authStore-DKFX8fn7.d.ts +3179 -0
- package/dist/authStore-DKFX8fn7.d.ts.map +1 -0
- package/dist/clientStore-BtE2-q2i.js +90 -0
- package/dist/clientStore-BtE2-q2i.js.map +1 -0
- package/dist/createSanityInstance-DUI1bGIg.d.ts +278 -0
- package/dist/createSanityInstance-DUI1bGIg.d.ts.map +1 -0
- package/dist/createStateSourceAction-BOKtqFNm.js +300 -0
- package/dist/createStateSourceAction-BOKtqFNm.js.map +1 -0
- package/dist/getEnv-D5RGkQLu.js +8 -0
- package/dist/getEnv-D5RGkQLu.js.map +1 -0
- package/dist/getNodeState-CR3__B2D.js +67 -0
- package/dist/getNodeState-CR3__B2D.js.map +1 -0
- package/dist/index.d.ts +3 -2332
- package/dist/index.js +4171 -4332
- package/dist/index.js.map +1 -1
- package/dist/logger-DAtJb5RQ.js +173 -0
- package/dist/logger-DAtJb5RQ.js.map +1 -0
- package/dist/object-CxXlSVg7.js +83 -0
- package/dist/object-CxXlSVg7.js.map +1 -0
- package/dist/queryStore-DPf9sN3V.js +1346 -0
- package/dist/queryStore-DPf9sN3V.js.map +1 -0
- package/dist/rolldown-runtime-vyAXikos.js +9 -0
- package/dist/setCleanupTimeout-BiM6q1KF.js +31 -0
- package/dist/setCleanupTimeout-BiM6q1KF.js.map +1 -0
- package/dist/telemetryManager-Dq_qCkeI.js +127 -0
- package/dist/telemetryManager-Dq_qCkeI.js.map +1 -0
- package/dist/version-BChjsi4u.js +9 -0
- package/dist/version-BChjsi4u.js.map +1 -0
- package/package.json +47 -52
- package/src/_exports/_internal.ts +27 -0
- package/src/_exports/agent.ts +19 -0
- package/src/_exports/comlink.ts +16 -0
- package/src/_exports/index.ts +125 -64
- 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 +88 -0
- package/src/applications/applications.test.ts +130 -0
- package/src/applications/applications.ts +367 -0
- package/src/auth/authLogger.ts +30 -0
- package/src/auth/authStore.test.ts +194 -13
- package/src/auth/authStore.ts +58 -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/comments/addonDatasetStore.test.ts +215 -0
- package/src/comments/addonDatasetStore.ts +249 -0
- package/src/comments/buildCommentThreads.test.ts +83 -0
- package/src/comments/buildCommentThreads.ts +54 -0
- package/src/comments/commentActions.test.ts +540 -0
- package/src/comments/commentActions.ts +555 -0
- package/src/comments/commentFieldPath.test.ts +40 -0
- package/src/comments/commentFieldPath.ts +44 -0
- package/src/comments/commentsConstants.ts +80 -0
- package/src/comments/commentsStore.test.ts +419 -0
- package/src/comments/commentsStore.ts +483 -0
- package/src/comments/normalizeComment.test.ts +116 -0
- package/src/comments/normalizeComment.ts +45 -0
- package/src/comments/observeComments.test.ts +193 -0
- package/src/comments/observeComments.ts +113 -0
- package/src/comments/reducers.test.ts +277 -0
- package/src/comments/reducers.ts +316 -0
- package/src/comments/types.ts +249 -0
- package/src/comments/weakenReferences.test.ts +47 -0
- package/src/comments/weakenReferences.ts +29 -0
- package/src/config/__tests__/handles.test.ts +18 -12
- package/src/config/handles.ts +25 -7
- package/src/config/sanityConfig.ts +40 -82
- 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 +35 -13
- package/src/document/applyDocumentActions.ts +30 -9
- package/src/document/documentConstants.ts +15 -0
- package/src/document/documentStore.concurrency.test.ts +1306 -0
- package/src/document/documentStore.test.ts +753 -273
- package/src/document/documentStore.ts +197 -75
- 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 +76 -2
- package/src/document/patchOperations.ts +60 -1
- package/src/document/permissions.test.ts +107 -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 +772 -64
- package/src/document/reducers.ts +205 -51
- 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.test.ts +46 -0
- package/src/document/util.ts +50 -0
- package/src/favorites/favorites.test.ts +5 -6
- package/src/installations/installations.test-d.ts +73 -0
- package/src/installations/installations.test.ts +62 -0
- package/src/installations/installations.ts +206 -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 +201 -9
- package/src/presence/bifurTransport.ts +98 -14
- package/src/presence/paths.test.ts +70 -0
- package/src/presence/paths.ts +41 -0
- package/src/presence/presenceStore.test.ts +915 -24
- package/src/presence/presenceStore.ts +576 -104
- package/src/presence/types.ts +175 -3
- package/src/preview/previewProjectionUtils.test.ts +9 -22
- package/src/preview/previewProjectionUtils.ts +7 -3
- package/src/preview/types.ts +0 -15
- 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 -9
- 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/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 +85 -69
- 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 +109 -90
- package/src/store/createActionBinder.ts +36 -28
- package/src/store/createSanityInstance.test.ts +15 -13
- package/src/store/createSanityInstance.ts +14 -2
- package/src/store/createStateSourceAction.test.ts +64 -2
- package/src/store/createStateSourceAction.ts +38 -43
- 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 +3 -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
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import {DocumentId, getDraftId, getVersionId} from '@sanity/id-utils'
|
|
2
|
+
import {type Mutation} from '@sanity/types'
|
|
3
|
+
|
|
4
|
+
import {isReleasePerspective} from '../../releases/utils/isReleasePerspective'
|
|
5
|
+
import {type DiscardDocumentAction} from '../actions'
|
|
6
|
+
import {getId, processMutations} from '../processMutations'
|
|
7
|
+
import {
|
|
8
|
+
ActionError,
|
|
9
|
+
type ActionHandlerContext,
|
|
10
|
+
type ActionHandlerResult,
|
|
11
|
+
checkGrant,
|
|
12
|
+
PermissionActionError,
|
|
13
|
+
} from './shared'
|
|
14
|
+
|
|
15
|
+
export function handleDiscard(
|
|
16
|
+
action: DiscardDocumentAction,
|
|
17
|
+
ctx: ActionHandlerContext,
|
|
18
|
+
): ActionHandlerResult {
|
|
19
|
+
const {transactionId, timestamp, grants, identity, outgoingActions, outgoingMutations} = ctx
|
|
20
|
+
let {base, working} = ctx
|
|
21
|
+
|
|
22
|
+
const documentId = getId(action.documentId)
|
|
23
|
+
|
|
24
|
+
if (action.liveEdit) {
|
|
25
|
+
throw new ActionError({
|
|
26
|
+
documentId,
|
|
27
|
+
transactionId,
|
|
28
|
+
message: `Cannot discard changes for liveEdit document "${documentId}". LiveEdit documents do not support drafts.`,
|
|
29
|
+
})
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// draft/published or version logic
|
|
33
|
+
const versionId = isReleasePerspective(action.perspective)
|
|
34
|
+
? getVersionId(DocumentId(documentId), action.perspective.releaseName)
|
|
35
|
+
: getDraftId(DocumentId(documentId))
|
|
36
|
+
const mutations: Mutation[] = [{delete: {id: versionId}}]
|
|
37
|
+
|
|
38
|
+
if (!working[versionId]) {
|
|
39
|
+
throw new ActionError({
|
|
40
|
+
documentId,
|
|
41
|
+
transactionId,
|
|
42
|
+
message: `There is no draft or version available to discard for document "${documentId}".`,
|
|
43
|
+
})
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (!checkGrant(grants.update, working[versionId], identity)) {
|
|
47
|
+
throw new PermissionActionError({
|
|
48
|
+
documentId,
|
|
49
|
+
transactionId,
|
|
50
|
+
message: `You do not have permission to discard changes for document "${documentId}".`,
|
|
51
|
+
})
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
base = processMutations({documents: base, transactionId, mutations, timestamp})
|
|
55
|
+
working = processMutations({documents: working, transactionId, mutations, timestamp})
|
|
56
|
+
|
|
57
|
+
outgoingMutations.push(...mutations)
|
|
58
|
+
outgoingActions.push({
|
|
59
|
+
actionType: 'sanity.action.document.version.discard',
|
|
60
|
+
versionId,
|
|
61
|
+
})
|
|
62
|
+
return {base, working}
|
|
63
|
+
}
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import {diffValue} from '@sanity/diff-patch'
|
|
2
|
+
import {DocumentId, getDraftId, getPublishedId, getVersionId} from '@sanity/id-utils'
|
|
3
|
+
import {type Mutation, type PatchOperations, type SanityDocument} from '@sanity/types'
|
|
4
|
+
|
|
5
|
+
import {isReleasePerspective} from '../../releases/utils/isReleasePerspective'
|
|
6
|
+
import {type EditDocumentAction} from '../actions'
|
|
7
|
+
import {getId} from '../processMutations'
|
|
8
|
+
import {
|
|
9
|
+
ActionError,
|
|
10
|
+
type ActionHandlerContext,
|
|
11
|
+
type ActionHandlerResult,
|
|
12
|
+
applySingleDocPatch,
|
|
13
|
+
checkGrant,
|
|
14
|
+
createMutationApplier,
|
|
15
|
+
PermissionActionError,
|
|
16
|
+
preserveNumericOperations,
|
|
17
|
+
} from './shared'
|
|
18
|
+
|
|
19
|
+
export function handleEdit(
|
|
20
|
+
action: EditDocumentAction,
|
|
21
|
+
ctx: ActionHandlerContext,
|
|
22
|
+
): ActionHandlerResult {
|
|
23
|
+
const {transactionId, timestamp, grants, identity, outgoingActions, outgoingMutations} = ctx
|
|
24
|
+
let {base, working} = ctx
|
|
25
|
+
|
|
26
|
+
const documentId = getId(action.documentId)
|
|
27
|
+
|
|
28
|
+
if (action.liveEdit) {
|
|
29
|
+
const result = applySingleDocPatch({
|
|
30
|
+
base,
|
|
31
|
+
working,
|
|
32
|
+
documentId,
|
|
33
|
+
patches: action.patches,
|
|
34
|
+
transactionId,
|
|
35
|
+
timestamp,
|
|
36
|
+
grants,
|
|
37
|
+
identity,
|
|
38
|
+
preserveOperations: action.preserveOperations,
|
|
39
|
+
})
|
|
40
|
+
// liveEdit documents use the mutation endpoint directly -- we don't send actions
|
|
41
|
+
outgoingMutations.push(...result.workingMutations)
|
|
42
|
+
return {base: result.base, working: result.working}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const versionId = isReleasePerspective(action.perspective)
|
|
46
|
+
? getVersionId(DocumentId(documentId), action.perspective.releaseName)
|
|
47
|
+
: undefined
|
|
48
|
+
const draftId = getDraftId(DocumentId(documentId))
|
|
49
|
+
const publishedId = getPublishedId(DocumentId(documentId))
|
|
50
|
+
const patchDocumentId = isReleasePerspective(action.perspective) ? versionId! : draftId
|
|
51
|
+
const userPatches = action.patches?.map((patch) => ({
|
|
52
|
+
patch: {id: patchDocumentId, ...patch},
|
|
53
|
+
}))
|
|
54
|
+
|
|
55
|
+
// skip this action if there are no associated patches
|
|
56
|
+
if (!userPatches?.length) return {base, working}
|
|
57
|
+
|
|
58
|
+
if (isReleasePerspective(action.perspective)) {
|
|
59
|
+
if (!working[versionId!] && !base[versionId!]) {
|
|
60
|
+
throw new ActionError({
|
|
61
|
+
documentId,
|
|
62
|
+
transactionId,
|
|
63
|
+
message: `This document does not exist in the release. Please create it or add it to the release first.`,
|
|
64
|
+
})
|
|
65
|
+
}
|
|
66
|
+
} else if (
|
|
67
|
+
(!working[draftId] && !working[publishedId]) ||
|
|
68
|
+
(!base[draftId] && !base[publishedId])
|
|
69
|
+
) {
|
|
70
|
+
throw new ActionError({
|
|
71
|
+
documentId,
|
|
72
|
+
transactionId,
|
|
73
|
+
message: `Cannot edit document because it does not exist in draft or published form.`,
|
|
74
|
+
})
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const applyMutations = createMutationApplier({
|
|
78
|
+
documentId,
|
|
79
|
+
transactionId,
|
|
80
|
+
timestamp,
|
|
81
|
+
preserveOperations: action.preserveOperations,
|
|
82
|
+
})
|
|
83
|
+
|
|
84
|
+
const baseMutations: Mutation[] = []
|
|
85
|
+
// don't create a draft from the published version in a release perspective
|
|
86
|
+
if (!isReleasePerspective(action.perspective) && !base[draftId] && base[publishedId]) {
|
|
87
|
+
// otherwise make a draft from the published version
|
|
88
|
+
baseMutations.push({create: {...base[publishedId], _id: draftId}})
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// the above statement and guards should make this never be null or undefined
|
|
92
|
+
const baseBefore = base[patchDocumentId] ?? base[publishedId]
|
|
93
|
+
if (userPatches) {
|
|
94
|
+
baseMutations.push(...userPatches)
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
base = applyMutations(base, baseMutations, 'base')
|
|
98
|
+
// this one will always be defined because a patch mutation will never
|
|
99
|
+
// delete an input document
|
|
100
|
+
const baseAfter = base[patchDocumentId] as SanityDocument
|
|
101
|
+
// when the caller asked us to preserve their operations, forward their
|
|
102
|
+
// patches verbatim instead of re-deriving them from a snapshot diff. this
|
|
103
|
+
// keeps keyed array operations addressable so concurrent edits from other
|
|
104
|
+
// clients interleave instead of being overwritten. otherwise, diff the
|
|
105
|
+
// snapshots but swap back any `inc`/`dec` the diff collapsed into a `set`,
|
|
106
|
+
// so concurrent increments accumulate instead of last-write-winning
|
|
107
|
+
const patches = action.preserveOperations
|
|
108
|
+
? (action.patches ?? [])
|
|
109
|
+
: preserveNumericOperations(
|
|
110
|
+
baseBefore,
|
|
111
|
+
action.patches,
|
|
112
|
+
diffValue(baseBefore, baseAfter) as PatchOperations[],
|
|
113
|
+
)
|
|
114
|
+
|
|
115
|
+
const workingMutations: Mutation[] = []
|
|
116
|
+
if (!isReleasePerspective(action.perspective) && !working[draftId] && working[publishedId]) {
|
|
117
|
+
const newDraftFromPublished = {...working[publishedId], _id: draftId}
|
|
118
|
+
|
|
119
|
+
if (!checkGrant(grants.create, newDraftFromPublished, identity)) {
|
|
120
|
+
throw new PermissionActionError({
|
|
121
|
+
documentId,
|
|
122
|
+
transactionId,
|
|
123
|
+
message: `You do not have permission to create a draft for editing this document.`,
|
|
124
|
+
})
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
workingMutations.push({create: newDraftFromPublished})
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// the first if statement should make this never be null or undefined
|
|
131
|
+
const workingBefore = working[patchDocumentId] ?? working[publishedId]
|
|
132
|
+
if (!checkGrant(grants.update, workingBefore!, identity)) {
|
|
133
|
+
throw new PermissionActionError({
|
|
134
|
+
documentId,
|
|
135
|
+
transactionId,
|
|
136
|
+
message: `You do not have permission to edit document "${documentId}".`,
|
|
137
|
+
})
|
|
138
|
+
}
|
|
139
|
+
workingMutations.push(...patches.map((patch) => ({patch: {id: patchDocumentId, ...patch}})))
|
|
140
|
+
|
|
141
|
+
working = applyMutations(working, workingMutations, 'working')
|
|
142
|
+
|
|
143
|
+
outgoingMutations.push(...workingMutations)
|
|
144
|
+
outgoingActions.push(
|
|
145
|
+
...patches.map((patch) => ({
|
|
146
|
+
actionType: 'sanity.action.document.edit' as const,
|
|
147
|
+
draftId: patchDocumentId,
|
|
148
|
+
publishedId,
|
|
149
|
+
patch: patch as PatchOperations,
|
|
150
|
+
})),
|
|
151
|
+
)
|
|
152
|
+
|
|
153
|
+
return {base, working}
|
|
154
|
+
}
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
import {type Mutation} from '@sanity/types'
|
|
2
|
+
import {type ExprNode} from 'groq-js'
|
|
3
|
+
|
|
4
|
+
import {type Action, type DocumentAction} from '../actions'
|
|
5
|
+
import {type Grant} from '../permissions'
|
|
6
|
+
import {type DocumentSet} from '../processMutations'
|
|
7
|
+
import {type HttpAction} from '../reducers'
|
|
8
|
+
import {handleCreate} from './create'
|
|
9
|
+
import {handleDelete} from './delete'
|
|
10
|
+
import {handleDiscard} from './discard'
|
|
11
|
+
import {handleEdit} from './edit'
|
|
12
|
+
import {handlePublish} from './publish'
|
|
13
|
+
import {handleReleaseArchive, handleReleaseUnarchive} from './releaseArchive'
|
|
14
|
+
import {handleReleaseCreate} from './releaseCreate'
|
|
15
|
+
import {handleReleaseDelete} from './releaseDelete'
|
|
16
|
+
import {handleReleaseEdit} from './releaseEdit'
|
|
17
|
+
import {handleReleasePublish} from './releasePublish'
|
|
18
|
+
import {handleReleaseSchedule, handleReleaseUnschedule} from './releaseSchedule'
|
|
19
|
+
import {isReleaseAction} from './releaseUtil'
|
|
20
|
+
import {
|
|
21
|
+
ActionError,
|
|
22
|
+
type ActionHandlerContext,
|
|
23
|
+
type ActionHandlerResult,
|
|
24
|
+
PermissionActionError,
|
|
25
|
+
} from './shared'
|
|
26
|
+
import {handleUnpublish} from './unpublish'
|
|
27
|
+
|
|
28
|
+
export {ActionError, PermissionActionError}
|
|
29
|
+
|
|
30
|
+
interface ProcessActionsOptions {
|
|
31
|
+
/**
|
|
32
|
+
* The ID of this transaction. This will become the resulting `_rev` for all
|
|
33
|
+
* documents affected by changes derived from the current set of actions.
|
|
34
|
+
*/
|
|
35
|
+
transactionId: string
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* The actions to apply to the given documents
|
|
39
|
+
*/
|
|
40
|
+
actions: Action[]
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* The set of documents these actions were intended to be applied to. These
|
|
44
|
+
* set of documents should be captured right before a queued action is
|
|
45
|
+
* applied.
|
|
46
|
+
*/
|
|
47
|
+
base: DocumentSet
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* The current "working" set of documents. A patch will be created by applying
|
|
51
|
+
* the actions to the base. This patch will then be applied to the working
|
|
52
|
+
* set for conflict resolution. Initially, this value should match the base
|
|
53
|
+
* set.
|
|
54
|
+
*/
|
|
55
|
+
working: DocumentSet
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* The timestamp to use for `_updateAt` and other similar timestamps for this
|
|
59
|
+
* transaction
|
|
60
|
+
*/
|
|
61
|
+
timestamp: string
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* the lookup with pre-parsed GROQ expressions
|
|
65
|
+
*/
|
|
66
|
+
grants: Record<Grant, ExprNode>
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* The current user's ID, passed to GROQ as the value of `identity()` when
|
|
70
|
+
* evaluating ACL filters. Optional because the user may not have loaded yet;
|
|
71
|
+
* filters that reference `identity()` will evaluate to null in that case.
|
|
72
|
+
*/
|
|
73
|
+
identity?: string
|
|
74
|
+
|
|
75
|
+
// // TODO: implement initial values from the schema?
|
|
76
|
+
// initialValues?: {[TDocumentType in string]?: {_type: string}}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
interface ProcessActionsResult {
|
|
80
|
+
/**
|
|
81
|
+
* The resulting document set after the actions have been applied. This is
|
|
82
|
+
* derived from the working documents.
|
|
83
|
+
*/
|
|
84
|
+
working: DocumentSet
|
|
85
|
+
/**
|
|
86
|
+
* The document set before the actions have been applied. This is simply the
|
|
87
|
+
* input of the `working` document set.
|
|
88
|
+
*/
|
|
89
|
+
previous: DocumentSet
|
|
90
|
+
/**
|
|
91
|
+
* The outgoing action that were collected when applying the actions. These
|
|
92
|
+
* are sent to the Actions HTTP API
|
|
93
|
+
*/
|
|
94
|
+
outgoingActions: HttpAction[]
|
|
95
|
+
/**
|
|
96
|
+
* The outgoing mutations that were collected when applying the actions. These
|
|
97
|
+
* are here for debugging purposes.
|
|
98
|
+
*/
|
|
99
|
+
outgoingMutations: Mutation[]
|
|
100
|
+
/**
|
|
101
|
+
* The previous revisions of the given documents before the actions were applied.
|
|
102
|
+
*/
|
|
103
|
+
previousRevs: {[TDocumentId in string]?: string}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Applies the given set of actions to the working set of documents and converts
|
|
108
|
+
* high-level actions into lower-level outgoing mutations/actions that respect
|
|
109
|
+
* the current state of the working documents.
|
|
110
|
+
*
|
|
111
|
+
* Supports a "base" and "working" set of documents to allow actions to be
|
|
112
|
+
* applied on top of a different working set of documents in a 3-way merge
|
|
113
|
+
*
|
|
114
|
+
* Actions are applied to the base set of documents first. The difference
|
|
115
|
+
* between the base before and after is used to create a patch. This patch is
|
|
116
|
+
* then applied to the working set of documents and is set as the outgoing patch
|
|
117
|
+
* sent to the server.
|
|
118
|
+
*/
|
|
119
|
+
export function processActions({
|
|
120
|
+
actions,
|
|
121
|
+
transactionId,
|
|
122
|
+
working: initialWorking,
|
|
123
|
+
base: initialBase,
|
|
124
|
+
timestamp,
|
|
125
|
+
grants,
|
|
126
|
+
identity,
|
|
127
|
+
}: ProcessActionsOptions): ProcessActionsResult {
|
|
128
|
+
let base: DocumentSet = {...initialBase}
|
|
129
|
+
let working: DocumentSet = {...initialWorking}
|
|
130
|
+
|
|
131
|
+
const outgoingActions: HttpAction[] = []
|
|
132
|
+
const outgoingMutations: Mutation[] = []
|
|
133
|
+
|
|
134
|
+
// liveEdit document actions go to the mutations API, since the actions API
|
|
135
|
+
// requires a draft+published pair. Mixing them with anything else in the same
|
|
136
|
+
// transaction would silently lose atomicity for the non-liveEdit operations,
|
|
137
|
+
// so require users to split the transaction.
|
|
138
|
+
// (Note that the reducers already does this for us -- you'd have to try hard to mix them.)
|
|
139
|
+
const liveEditAction = actions.find((action) => !isReleaseAction(action) && action.liveEdit) as
|
|
140
|
+
| DocumentAction
|
|
141
|
+
| undefined
|
|
142
|
+
const otherAction = actions.find((action) => isReleaseAction(action) || !action.liveEdit)
|
|
143
|
+
if (liveEditAction && otherAction) {
|
|
144
|
+
throw new ActionError({
|
|
145
|
+
documentId: liveEditAction.documentId!,
|
|
146
|
+
transactionId,
|
|
147
|
+
message:
|
|
148
|
+
'Cannot combine liveEdit document actions with other actions in the same transaction. Submit them as separate transactions.',
|
|
149
|
+
})
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
for (const action of actions) {
|
|
153
|
+
const result = dispatch(action, {
|
|
154
|
+
base,
|
|
155
|
+
working,
|
|
156
|
+
transactionId,
|
|
157
|
+
timestamp,
|
|
158
|
+
grants,
|
|
159
|
+
identity,
|
|
160
|
+
outgoingActions,
|
|
161
|
+
outgoingMutations,
|
|
162
|
+
})
|
|
163
|
+
base = result.base
|
|
164
|
+
working = result.working
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
const previousRevs = Object.fromEntries(
|
|
168
|
+
Object.entries(initialWorking).map(([id, doc]) => [id, doc?._rev]),
|
|
169
|
+
)
|
|
170
|
+
|
|
171
|
+
return {
|
|
172
|
+
working,
|
|
173
|
+
outgoingActions,
|
|
174
|
+
outgoingMutations,
|
|
175
|
+
previous: initialWorking,
|
|
176
|
+
previousRevs,
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
function dispatch(action: Action, ctx: ActionHandlerContext): ActionHandlerResult {
|
|
181
|
+
switch (action.type) {
|
|
182
|
+
case 'document.create':
|
|
183
|
+
return handleCreate(action, ctx)
|
|
184
|
+
case 'document.delete':
|
|
185
|
+
return handleDelete(action, ctx)
|
|
186
|
+
case 'document.discard':
|
|
187
|
+
return handleDiscard(action, ctx)
|
|
188
|
+
case 'document.edit':
|
|
189
|
+
return handleEdit(action, ctx)
|
|
190
|
+
case 'document.publish':
|
|
191
|
+
return handlePublish(action, ctx)
|
|
192
|
+
case 'document.unpublish':
|
|
193
|
+
return handleUnpublish(action, ctx)
|
|
194
|
+
case 'release.create':
|
|
195
|
+
return handleReleaseCreate(action, ctx)
|
|
196
|
+
case 'release.edit':
|
|
197
|
+
return handleReleaseEdit(action, ctx)
|
|
198
|
+
case 'release.publish':
|
|
199
|
+
return handleReleasePublish(action, ctx)
|
|
200
|
+
case 'release.schedule':
|
|
201
|
+
return handleReleaseSchedule(action, ctx)
|
|
202
|
+
case 'release.unschedule':
|
|
203
|
+
return handleReleaseUnschedule(action, ctx)
|
|
204
|
+
case 'release.archive':
|
|
205
|
+
return handleReleaseArchive(action, ctx)
|
|
206
|
+
case 'release.unarchive':
|
|
207
|
+
return handleReleaseUnarchive(action, ctx)
|
|
208
|
+
case 'release.delete':
|
|
209
|
+
return handleReleaseDelete(action, ctx)
|
|
210
|
+
default:
|
|
211
|
+
throw new Error(
|
|
212
|
+
`Unknown action type: "${
|
|
213
|
+
// @ts-expect-error invalid input
|
|
214
|
+
action.type
|
|
215
|
+
}". Please contact support if this issue persists.`,
|
|
216
|
+
)
|
|
217
|
+
}
|
|
218
|
+
}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import {DocumentId, getDraftId, getPublishedId} from '@sanity/id-utils'
|
|
2
|
+
import {type Mutation, type Reference, type SanityDocument} from '@sanity/types'
|
|
3
|
+
|
|
4
|
+
import {isReleasePerspective} from '../../releases/utils/isReleasePerspective'
|
|
5
|
+
import {isDeepEqual} from '../../utils/object'
|
|
6
|
+
import {type PublishDocumentAction} from '../actions'
|
|
7
|
+
import {getId, processMutations} from '../processMutations'
|
|
8
|
+
import {
|
|
9
|
+
ActionError,
|
|
10
|
+
type ActionHandlerContext,
|
|
11
|
+
type ActionHandlerResult,
|
|
12
|
+
checkGrant,
|
|
13
|
+
PermissionActionError,
|
|
14
|
+
} from './shared'
|
|
15
|
+
|
|
16
|
+
export function handlePublish(
|
|
17
|
+
action: PublishDocumentAction,
|
|
18
|
+
ctx: ActionHandlerContext,
|
|
19
|
+
): ActionHandlerResult {
|
|
20
|
+
const {transactionId, timestamp, grants, identity, outgoingActions, outgoingMutations} = ctx
|
|
21
|
+
let {base, working} = ctx
|
|
22
|
+
|
|
23
|
+
const documentId = getId(action.documentId)
|
|
24
|
+
|
|
25
|
+
if (action.liveEdit || isReleasePerspective(action.perspective)) {
|
|
26
|
+
throw new ActionError({
|
|
27
|
+
documentId,
|
|
28
|
+
transactionId,
|
|
29
|
+
message: `Cannot publish this document. Publishing is not supported for liveEdit or version (release) documents.`,
|
|
30
|
+
})
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// Standard draft/published logic
|
|
34
|
+
const draftId = getDraftId(DocumentId(documentId))
|
|
35
|
+
const publishedId = getPublishedId(DocumentId(documentId))
|
|
36
|
+
|
|
37
|
+
const workingDraft = working[draftId]
|
|
38
|
+
const baseDraft = base[draftId]
|
|
39
|
+
if (!workingDraft || !baseDraft) {
|
|
40
|
+
throw new ActionError({
|
|
41
|
+
documentId,
|
|
42
|
+
transactionId,
|
|
43
|
+
message: `Cannot publish because no draft version was found for document "${documentId}".`,
|
|
44
|
+
})
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// Before proceeding, verify that the working draft is identical to the base draft.
|
|
48
|
+
// TODO: is it enough just to check for the _rev or nah?
|
|
49
|
+
if (!isDeepEqual(workingDraft, baseDraft)) {
|
|
50
|
+
throw new ActionError({
|
|
51
|
+
documentId,
|
|
52
|
+
transactionId,
|
|
53
|
+
message: `Publish aborted: The document has changed elsewhere. Please try again.`,
|
|
54
|
+
})
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const newPublishedFromDraft = {...strengthenOnPublish(workingDraft), _id: publishedId}
|
|
58
|
+
|
|
59
|
+
const mutations: Mutation[] = [{delete: {id: draftId}}, {createOrReplace: newPublishedFromDraft}]
|
|
60
|
+
|
|
61
|
+
if (working[draftId] && !checkGrant(grants.update, working[draftId], identity)) {
|
|
62
|
+
throw new PermissionActionError({
|
|
63
|
+
documentId,
|
|
64
|
+
transactionId,
|
|
65
|
+
message: `Publish failed: You do not have permission to update the draft for "${documentId}".`,
|
|
66
|
+
})
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
if (working[publishedId] && !checkGrant(grants.update, newPublishedFromDraft, identity)) {
|
|
70
|
+
throw new PermissionActionError({
|
|
71
|
+
documentId,
|
|
72
|
+
transactionId,
|
|
73
|
+
message: `Publish failed: You do not have permission to update the published version of "${documentId}".`,
|
|
74
|
+
})
|
|
75
|
+
} else if (!working[publishedId] && !checkGrant(grants.create, newPublishedFromDraft, identity)) {
|
|
76
|
+
throw new PermissionActionError({
|
|
77
|
+
documentId,
|
|
78
|
+
transactionId,
|
|
79
|
+
message: `Publish failed: You do not have permission to publish a new version of "${documentId}".`,
|
|
80
|
+
})
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
base = processMutations({documents: base, transactionId, mutations, timestamp})
|
|
84
|
+
working = processMutations({documents: working, transactionId, mutations, timestamp})
|
|
85
|
+
|
|
86
|
+
outgoingMutations.push(...mutations)
|
|
87
|
+
outgoingActions.push({
|
|
88
|
+
actionType: 'sanity.action.document.publish',
|
|
89
|
+
draftId,
|
|
90
|
+
publishedId,
|
|
91
|
+
})
|
|
92
|
+
return {base, working}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function strengthenOnPublish(draft: SanityDocument): SanityDocument {
|
|
96
|
+
const isStrengthenReference = (
|
|
97
|
+
value: object,
|
|
98
|
+
): value is Reference & Required<Pick<Reference, '_strengthenOnPublish'>> =>
|
|
99
|
+
'_strengthenOnPublish' in value
|
|
100
|
+
|
|
101
|
+
function strengthen(value: unknown): unknown {
|
|
102
|
+
if (typeof value !== 'object' || !value) return value
|
|
103
|
+
|
|
104
|
+
if (isStrengthenReference(value)) {
|
|
105
|
+
const {_strengthenOnPublish, _weak, ...rest} = value
|
|
106
|
+
return {
|
|
107
|
+
...rest,
|
|
108
|
+
...(_strengthenOnPublish.weak && {_weak: true}),
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
if (Array.isArray(value)) {
|
|
113
|
+
return value.map(strengthen)
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
return Object.fromEntries(Object.entries(value).map(([k, v]) => [k, strengthen(v)]))
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
return strengthen(draft) as SanityDocument
|
|
120
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import {type ArchiveReleaseAction, type UnarchiveReleaseAction} from '../actions'
|
|
2
|
+
import {getReleaseDocumentId} from './releaseUtil'
|
|
3
|
+
import {
|
|
4
|
+
ActionError,
|
|
5
|
+
type ActionHandlerContext,
|
|
6
|
+
type ActionHandlerResult,
|
|
7
|
+
checkGrant,
|
|
8
|
+
PermissionActionError,
|
|
9
|
+
} from './shared'
|
|
10
|
+
|
|
11
|
+
export function handleReleaseArchive(
|
|
12
|
+
action: ArchiveReleaseAction,
|
|
13
|
+
ctx: ActionHandlerContext,
|
|
14
|
+
): ActionHandlerResult {
|
|
15
|
+
const {base, working, grants, outgoingActions, transactionId, identity} = ctx
|
|
16
|
+
|
|
17
|
+
const releaseDocumentId = getReleaseDocumentId(action.releaseId)
|
|
18
|
+
const existing = working[releaseDocumentId] ?? base[releaseDocumentId]
|
|
19
|
+
if (!existing) {
|
|
20
|
+
throw new ActionError({
|
|
21
|
+
documentId: releaseDocumentId,
|
|
22
|
+
transactionId,
|
|
23
|
+
message: `Cannot archive release "${action.releaseId}" because it does not exist.`,
|
|
24
|
+
})
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
if (!checkGrant(grants.update, existing, identity)) {
|
|
28
|
+
throw new PermissionActionError({
|
|
29
|
+
documentId: releaseDocumentId,
|
|
30
|
+
transactionId,
|
|
31
|
+
message: `You do not have permission to archive release "${action.releaseId}".`,
|
|
32
|
+
})
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// Archiving deletes every version document in the release server-side.
|
|
36
|
+
// Although technically we could search through the document store for all related
|
|
37
|
+
// version documents, for now it's simpler to just let the server handle it.
|
|
38
|
+
// (Those local documents will be eventually updated by the listener.)
|
|
39
|
+
outgoingActions.push({
|
|
40
|
+
actionType: 'sanity.action.release.archive',
|
|
41
|
+
releaseId: action.releaseId,
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
return {base, working}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function handleReleaseUnarchive(
|
|
48
|
+
action: UnarchiveReleaseAction,
|
|
49
|
+
ctx: ActionHandlerContext,
|
|
50
|
+
): ActionHandlerResult {
|
|
51
|
+
const {base, working, grants, outgoingActions, transactionId, identity} = ctx
|
|
52
|
+
|
|
53
|
+
const releaseDocumentId = getReleaseDocumentId(action.releaseId)
|
|
54
|
+
const existing = working[releaseDocumentId] ?? base[releaseDocumentId]
|
|
55
|
+
if (!existing) {
|
|
56
|
+
throw new ActionError({
|
|
57
|
+
documentId: releaseDocumentId,
|
|
58
|
+
transactionId,
|
|
59
|
+
message: `Cannot unarchive release "${action.releaseId}" because it does not exist.`,
|
|
60
|
+
})
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
if (!checkGrant(grants.update, existing, identity)) {
|
|
64
|
+
throw new PermissionActionError({
|
|
65
|
+
documentId: releaseDocumentId,
|
|
66
|
+
transactionId,
|
|
67
|
+
message: `You do not have permission to unarchive release "${action.releaseId}".`,
|
|
68
|
+
})
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
outgoingActions.push({
|
|
72
|
+
actionType: 'sanity.action.release.unarchive',
|
|
73
|
+
releaseId: action.releaseId,
|
|
74
|
+
})
|
|
75
|
+
|
|
76
|
+
return {base, working}
|
|
77
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import {type Mutation, type SanityDocument} from '@sanity/types'
|
|
2
|
+
|
|
3
|
+
import {type CreateReleaseAction} from '../actions'
|
|
4
|
+
import {processMutations} from '../processMutations'
|
|
5
|
+
import {getReleaseDocumentId} from './releaseUtil'
|
|
6
|
+
import {
|
|
7
|
+
ActionError,
|
|
8
|
+
type ActionHandlerContext,
|
|
9
|
+
type ActionHandlerResult,
|
|
10
|
+
checkGrant,
|
|
11
|
+
PermissionActionError,
|
|
12
|
+
} from './shared'
|
|
13
|
+
|
|
14
|
+
export function handleReleaseCreate(
|
|
15
|
+
action: CreateReleaseAction,
|
|
16
|
+
ctx: ActionHandlerContext,
|
|
17
|
+
): ActionHandlerResult {
|
|
18
|
+
const {transactionId, timestamp, grants, outgoingActions, outgoingMutations, identity} = ctx
|
|
19
|
+
let {base, working} = ctx
|
|
20
|
+
|
|
21
|
+
const releaseDocumentId = getReleaseDocumentId(action.releaseId)
|
|
22
|
+
|
|
23
|
+
if (working[releaseDocumentId] || base[releaseDocumentId]) {
|
|
24
|
+
throw new ActionError({
|
|
25
|
+
documentId: releaseDocumentId,
|
|
26
|
+
transactionId,
|
|
27
|
+
message: `A release with id "${action.releaseId}" already exists.`,
|
|
28
|
+
})
|
|
29
|
+
}
|
|
30
|
+
// Optimistic local release doc
|
|
31
|
+
const releaseDoc = {
|
|
32
|
+
_id: releaseDocumentId,
|
|
33
|
+
_type: 'system.release',
|
|
34
|
+
name: action.releaseId,
|
|
35
|
+
state: 'active',
|
|
36
|
+
metadata: action.metadata,
|
|
37
|
+
}
|
|
38
|
+
const mutations: Mutation[] = [{create: releaseDoc}]
|
|
39
|
+
|
|
40
|
+
base = processMutations({documents: base, transactionId, mutations, timestamp})
|
|
41
|
+
working = processMutations({documents: working, transactionId, mutations, timestamp})
|
|
42
|
+
|
|
43
|
+
if (!checkGrant(grants.create, working[releaseDocumentId] as SanityDocument, identity)) {
|
|
44
|
+
throw new PermissionActionError({
|
|
45
|
+
documentId: releaseDocumentId,
|
|
46
|
+
transactionId,
|
|
47
|
+
message: `You do not have permission to create release "${action.releaseId}".`,
|
|
48
|
+
})
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
outgoingMutations.push(...mutations)
|
|
52
|
+
outgoingActions.push({
|
|
53
|
+
actionType: 'sanity.action.release.create',
|
|
54
|
+
releaseId: action.releaseId,
|
|
55
|
+
metadata: action.metadata,
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
return {base, working}
|
|
59
|
+
}
|