Guard the content field against empty strings so adding it in the UI without a value no longer sends content: "" to the API, which is not valid ProseMirror content. This matches the existing defaultApproverIds guard. Also expose title, classification, and document type on the update operation. Like content, these edit the current draft version, creating one from the latest published version when none exists. Signed-off-by: Sacha Al Himdani <sacha@probo.com>
179 lines
5.5 KiB
TypeScript
179 lines
5.5 KiB
TypeScript
// 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: ['update'],
|
|
},
|
|
},
|
|
default: '',
|
|
description: 'The ID of the document to update',
|
|
required: true,
|
|
},
|
|
{
|
|
displayName: 'Update Fields',
|
|
name: 'updateFields',
|
|
type: 'collection',
|
|
placeholder: 'Add Field',
|
|
default: {},
|
|
displayOptions: {
|
|
show: {
|
|
resource: ['document'],
|
|
operation: ['update'],
|
|
},
|
|
},
|
|
options: [
|
|
{
|
|
displayName: 'Classification',
|
|
name: 'classification',
|
|
type: 'options',
|
|
options: [
|
|
{ name: 'Confidential', value: 'CONFIDENTIAL' },
|
|
{ name: 'Internal', value: 'INTERNAL' },
|
|
{ name: 'Public', value: 'PUBLIC' },
|
|
{ name: 'Secret', value: 'SECRET' },
|
|
],
|
|
default: 'INTERNAL',
|
|
description: 'The classification of the document. Updating it edits the current draft version, creating one from the latest published version if none exists.',
|
|
},
|
|
{
|
|
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: 'Default Approver IDs',
|
|
name: 'defaultApproverIds',
|
|
type: 'string',
|
|
default: '',
|
|
description: 'Comma-separated list of default approver profile IDs',
|
|
},
|
|
{
|
|
displayName: 'Document Type',
|
|
name: 'documentType',
|
|
type: 'options',
|
|
options: [
|
|
{ name: 'Governance', value: 'GOVERNANCE' },
|
|
{ name: 'Other', value: 'OTHER' },
|
|
{ name: 'Plan', value: 'PLAN' },
|
|
{ name: 'Policy', value: 'POLICY' },
|
|
{ name: 'Procedure', value: 'PROCEDURE' },
|
|
{ name: 'Record', value: 'RECORD' },
|
|
{ name: 'Register', value: 'REGISTER' },
|
|
{ name: 'Report', value: 'REPORT' },
|
|
{ name: 'Template', value: 'TEMPLATE' },
|
|
],
|
|
default: 'POLICY',
|
|
description: 'The type of the document. Updating it edits the current draft version, creating one from the latest published version if none exists.',
|
|
},
|
|
{
|
|
displayName: 'Title',
|
|
name: 'title',
|
|
type: 'string',
|
|
default: '',
|
|
description: 'The title of the document. Updating it edits the current draft version, creating one from the latest published version if none exists.',
|
|
},
|
|
{
|
|
displayName: 'Trust Center Visibility',
|
|
name: 'trustCenterVisibility',
|
|
type: 'options',
|
|
options: [
|
|
{ name: 'None', value: 'NONE' },
|
|
{ name: 'Private', value: 'PRIVATE' },
|
|
{ name: 'Public', value: 'PUBLIC' },
|
|
],
|
|
default: 'NONE',
|
|
description: 'The trust center visibility of the document',
|
|
},
|
|
],
|
|
},
|
|
];
|
|
|
|
export async function execute(
|
|
this: IExecuteFunctions,
|
|
itemIndex: number,
|
|
): Promise<INodeExecutionData> {
|
|
const documentId = this.getNodeParameter('documentId', itemIndex) as string;
|
|
const updateFields = this.getNodeParameter('updateFields', itemIndex, {}) as {
|
|
title?: string;
|
|
content?: string;
|
|
classification?: string;
|
|
documentType?: string;
|
|
trustCenterVisibility?: string;
|
|
defaultApproverIds?: string;
|
|
};
|
|
|
|
const query = `
|
|
mutation UpdateDocument($input: UpdateDocumentInput!) {
|
|
updateDocument(input: $input) {
|
|
document {
|
|
id
|
|
status
|
|
trustCenterVisibility
|
|
currentPublishedMajor
|
|
currentPublishedMinor
|
|
archivedAt
|
|
createdAt
|
|
updatedAt
|
|
}
|
|
documentVersion {
|
|
id
|
|
title
|
|
major
|
|
minor
|
|
status
|
|
content
|
|
changelog
|
|
classification
|
|
documentType
|
|
publishedAt
|
|
createdAt
|
|
updatedAt
|
|
}
|
|
}
|
|
}
|
|
`;
|
|
|
|
const input: Record<string, unknown> = { id: documentId };
|
|
if (updateFields.title !== undefined && updateFields.title !== '') input.title = updateFields.title;
|
|
if (updateFields.content !== undefined && updateFields.content !== '') input.content = updateFields.content;
|
|
if (updateFields.classification !== undefined) input.classification = updateFields.classification;
|
|
if (updateFields.documentType !== undefined) input.documentType = updateFields.documentType;
|
|
if (updateFields.trustCenterVisibility !== undefined) input.trustCenterVisibility = updateFields.trustCenterVisibility;
|
|
if (updateFields.defaultApproverIds !== undefined && updateFields.defaultApproverIds !== '') {
|
|
input.defaultApproverIds = updateFields.defaultApproverIds.split(',').map(id => id.trim()).filter(Boolean);
|
|
}
|
|
|
|
const responseData = await proboApiRequest.call(this, query, { input });
|
|
|
|
return {
|
|
json: responseData,
|
|
pairedItem: { item: itemIndex },
|
|
};
|
|
}
|