diff --git a/packages/sanity/src/core/store/_legacy/document/document-pair/operations/unpublish.ts b/packages/sanity/src/core/store/_legacy/document/document-pair/operations/unpublish.ts index 232d070d8096..193870a0b0ff 100644 --- a/packages/sanity/src/core/store/_legacy/document/document-pair/operations/unpublish.ts +++ b/packages/sanity/src/core/store/_legacy/document/document-pair/operations/unpublish.ts @@ -1,5 +1,3 @@ -import {omit} from 'lodash' - import {isLiveEditEnabled} from '../utils/isLiveEditEnabled' import {type OperationImpl} from './types' @@ -12,24 +10,24 @@ export const unpublish: OperationImpl<[], DisabledReason> = { } return snapshots.published ? false : 'NOT_PUBLISHED' }, - execute: ({client, idPair, snapshots}) => { - let tx = client.observable.transaction().delete(idPair.publishedId) - - if (snapshots.published) { - tx = tx.createIfNotExists({ - ...omit(snapshots.published, '_updatedAt'), - _id: idPair.draftId, - _type: snapshots.published._type, - }) - } + execute: ({client: globalClient, idPair}) => { + const vXClient = globalClient.withConfig({apiVersion: 'X'}) + const {dataset} = globalClient.config() - return tx.commit({ + return vXClient.observable.request({ + url: `/data/actions/${dataset}`, + method: 'post', + query: {skipCrossDatasetReferenceValidation: 'true'}, tag: 'document.unpublish', - visibility: 'async', - // this disables referential integrity for cross-dataset references. we - // have this set because we warn against unpublishes in the `ConfirmDeleteDialog` - // UI. This operation is run when "unpublish anyway" is clicked - skipCrossDatasetReferenceValidation: true, + body: { + actions: [ + { + actionType: 'sanity.action.document.unpublish', + draftId: idPair.draftId, + publishedId: idPair.publishedId, + }, + ], + }, }) }, }