Drop n8n createDraftVersion, add body to update
Remove the createDraftVersion document operation from the n8n node and instead expose the document body on the update operation. Updating the body edits the current draft version, or creates one from the latest published version when none exists, so a dedicated draft-creation operation is redundant. Also correct the content field help text across the document operations: the API expects a ProseMirror document JSON string, not markdown. Signed-off-by: Sacha Al Himdani <sacha@probo.com>
This commit is contained in:
@@ -103,7 +103,7 @@ export const description: INodeProperties[] = [
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
default: '',
|
default: '',
|
||||||
description: 'The content of the document in markdown format',
|
description: 'The content of the document as a ProseMirror document JSON string',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
displayName: 'Additional Fields',
|
displayName: 'Additional Fields',
|
||||||
|
|||||||
@@ -1,70 +0,0 @@
|
|||||||
// Copyright (c) 2025-2026 Probo Inc <hello@probo.com>.
|
|
||||||
//
|
|
||||||
// Permission to use, copy, modify, and/or distribute this software for any
|
|
||||||
// purpose with or without fee is hereby granted, provided that the above
|
|
||||||
// copyright notice and this permission notice appear in all copies.
|
|
||||||
//
|
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
||||||
// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
||||||
// AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
||||||
// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
||||||
// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
||||||
// OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
||||||
// PERFORMANCE OF THIS SOFTWARE.
|
|
||||||
|
|
||||||
import type { INodeProperties, IExecuteFunctions, INodeExecutionData } from 'n8n-workflow';
|
|
||||||
import { proboApiRequest } from '../../GenericFunctions';
|
|
||||||
|
|
||||||
export const description: INodeProperties[] = [
|
|
||||||
{
|
|
||||||
displayName: 'Document ID',
|
|
||||||
name: 'documentId',
|
|
||||||
type: 'string',
|
|
||||||
displayOptions: {
|
|
||||||
show: {
|
|
||||||
resource: ['document'],
|
|
||||||
operation: ['createDraftVersion'],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
default: '',
|
|
||||||
description: 'The ID of the document',
|
|
||||||
required: true,
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
export async function execute(
|
|
||||||
this: IExecuteFunctions,
|
|
||||||
itemIndex: number,
|
|
||||||
): Promise<INodeExecutionData> {
|
|
||||||
const documentId = this.getNodeParameter('documentId', itemIndex) as string;
|
|
||||||
|
|
||||||
const query = `
|
|
||||||
mutation CreateDraftDocumentVersion($input: CreateDraftDocumentVersionInput!) {
|
|
||||||
createDraftDocumentVersion(input: $input) {
|
|
||||||
documentVersionEdge {
|
|
||||||
node {
|
|
||||||
id
|
|
||||||
title
|
|
||||||
major
|
|
||||||
minor
|
|
||||||
status
|
|
||||||
content
|
|
||||||
changelog
|
|
||||||
classification
|
|
||||||
documentType
|
|
||||||
publishedAt
|
|
||||||
createdAt
|
|
||||||
updatedAt
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
`;
|
|
||||||
|
|
||||||
const responseData = await proboApiRequest.call(this, query, { input: { documentID: documentId } });
|
|
||||||
|
|
||||||
return {
|
|
||||||
json: responseData,
|
|
||||||
pairedItem: { item: itemIndex },
|
|
||||||
};
|
|
||||||
}
|
|
||||||
@@ -23,7 +23,6 @@ import * as unarchiveOp from './unarchive.operation';
|
|||||||
import * as getVersionOp from './getVersion.operation';
|
import * as getVersionOp from './getVersion.operation';
|
||||||
import * as getLatestPublishedVersionIdOp from './getLatestPublishedVersionId.operation';
|
import * as getLatestPublishedVersionIdOp from './getLatestPublishedVersionId.operation';
|
||||||
import * as getAllVersionsOp from './getAllVersions.operation';
|
import * as getAllVersionsOp from './getAllVersions.operation';
|
||||||
import * as createDraftVersionOp from './createDraftVersion.operation';
|
|
||||||
import * as updateVersionOp from './updateVersion.operation';
|
import * as updateVersionOp from './updateVersion.operation';
|
||||||
import * as deleteDraftVersionOp from './deleteDraftVersion.operation';
|
import * as deleteDraftVersionOp from './deleteDraftVersion.operation';
|
||||||
import * as publishOp from './publish.operation';
|
import * as publishOp from './publish.operation';
|
||||||
@@ -67,12 +66,6 @@ export const description: INodeProperties[] = [
|
|||||||
description: 'Create a new document',
|
description: 'Create a new document',
|
||||||
action: 'Create a document',
|
action: 'Create a document',
|
||||||
},
|
},
|
||||||
{
|
|
||||||
name: 'Create Draft Version',
|
|
||||||
value: 'createDraftVersion',
|
|
||||||
description: 'Create a new draft version from the latest published version',
|
|
||||||
action: 'Create a draft document version',
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
name: 'Delete',
|
name: 'Delete',
|
||||||
value: 'delete',
|
value: 'delete',
|
||||||
@@ -200,7 +193,6 @@ export const description: INodeProperties[] = [
|
|||||||
...getVersionOp.description,
|
...getVersionOp.description,
|
||||||
...getLatestPublishedVersionIdOp.description,
|
...getLatestPublishedVersionIdOp.description,
|
||||||
...getAllVersionsOp.description,
|
...getAllVersionsOp.description,
|
||||||
...createDraftVersionOp.description,
|
|
||||||
...updateVersionOp.description,
|
...updateVersionOp.description,
|
||||||
...deleteDraftVersionOp.description,
|
...deleteDraftVersionOp.description,
|
||||||
...publishOp.description,
|
...publishOp.description,
|
||||||
@@ -226,7 +218,6 @@ export {
|
|||||||
getVersionOp as getVersion,
|
getVersionOp as getVersion,
|
||||||
getLatestPublishedVersionIdOp as getLatestPublishedVersionId,
|
getLatestPublishedVersionIdOp as getLatestPublishedVersionId,
|
||||||
getAllVersionsOp as getAllVersions,
|
getAllVersionsOp as getAllVersions,
|
||||||
createDraftVersionOp as createDraftVersion,
|
|
||||||
updateVersionOp as updateVersion,
|
updateVersionOp as updateVersion,
|
||||||
deleteDraftVersionOp as deleteDraftVersion,
|
deleteDraftVersionOp as deleteDraftVersion,
|
||||||
publishOp as publish,
|
publishOp as publish,
|
||||||
|
|||||||
@@ -43,6 +43,16 @@ export const description: INodeProperties[] = [
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
options: [
|
options: [
|
||||||
|
{
|
||||||
|
displayName: 'Content',
|
||||||
|
name: 'content',
|
||||||
|
type: 'string',
|
||||||
|
typeOptions: {
|
||||||
|
rows: 6,
|
||||||
|
},
|
||||||
|
default: '',
|
||||||
|
description: 'The body of the document as a ProseMirror document JSON string. Updating it edits the current draft version, creating one from the latest published version if none exists.',
|
||||||
|
},
|
||||||
{
|
{
|
||||||
displayName: 'Trust Center Visibility',
|
displayName: 'Trust Center Visibility',
|
||||||
name: 'trustCenterVisibility',
|
name: 'trustCenterVisibility',
|
||||||
@@ -72,6 +82,7 @@ export async function execute(
|
|||||||
): Promise<INodeExecutionData> {
|
): Promise<INodeExecutionData> {
|
||||||
const documentId = this.getNodeParameter('documentId', itemIndex) as string;
|
const documentId = this.getNodeParameter('documentId', itemIndex) as string;
|
||||||
const updateFields = this.getNodeParameter('updateFields', itemIndex, {}) as {
|
const updateFields = this.getNodeParameter('updateFields', itemIndex, {}) as {
|
||||||
|
content?: string;
|
||||||
trustCenterVisibility?: string;
|
trustCenterVisibility?: string;
|
||||||
defaultApproverIds?: string;
|
defaultApproverIds?: string;
|
||||||
};
|
};
|
||||||
@@ -89,11 +100,26 @@ export async function execute(
|
|||||||
createdAt
|
createdAt
|
||||||
updatedAt
|
updatedAt
|
||||||
}
|
}
|
||||||
|
documentVersion {
|
||||||
|
id
|
||||||
|
title
|
||||||
|
major
|
||||||
|
minor
|
||||||
|
status
|
||||||
|
content
|
||||||
|
changelog
|
||||||
|
classification
|
||||||
|
documentType
|
||||||
|
publishedAt
|
||||||
|
createdAt
|
||||||
|
updatedAt
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const input: Record<string, unknown> = { id: documentId };
|
const input: Record<string, unknown> = { id: documentId };
|
||||||
|
if (updateFields.content !== undefined) input.content = updateFields.content;
|
||||||
if (updateFields.trustCenterVisibility !== undefined) input.trustCenterVisibility = updateFields.trustCenterVisibility;
|
if (updateFields.trustCenterVisibility !== undefined) input.trustCenterVisibility = updateFields.trustCenterVisibility;
|
||||||
if (updateFields.defaultApproverIds !== undefined && updateFields.defaultApproverIds !== '') {
|
if (updateFields.defaultApproverIds !== undefined && updateFields.defaultApproverIds !== '') {
|
||||||
input.defaultApproverIds = updateFields.defaultApproverIds.split(',').map(id => id.trim()).filter(Boolean);
|
input.defaultApproverIds = updateFields.defaultApproverIds.split(',').map(id => id.trim()).filter(Boolean);
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ export const description: INodeProperties[] = [
|
|||||||
rows: 6,
|
rows: 6,
|
||||||
},
|
},
|
||||||
default: '',
|
default: '',
|
||||||
description: 'The content of the document in markdown format',
|
description: 'The content of the document as a ProseMirror document JSON string',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
displayName: 'Classification',
|
displayName: 'Classification',
|
||||||
|
|||||||
Reference in New Issue
Block a user