Files
probo/packages/n8n-node/nodes/Probo/actions/document/publish.operation.ts
Cursor Agent b721179974 Allow initial document minor publishing
Signed-off-by: Cursor Agent <cursoragent@cursor.com>

Co-authored-by: Bryan FRIMIN <bryan@frimin.fr>
2026-05-26 08:26:47 -07:00

140 lines
3.5 KiB
TypeScript

// Copyright (c) 2025-2026 Probo Inc <hello@getprobo.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: ['publish'],
},
},
default: '',
description: 'The ID of the document',
required: true,
},
{
displayName: 'Minor',
name: 'minor',
type: 'boolean',
displayOptions: {
show: {
resource: ['document'],
operation: ['publish'],
},
},
default: false,
description: 'Whether to publish as a minor version. Approvers are ignored when set.',
},
{
displayName: 'Approver IDs',
name: 'approverIds',
type: 'string',
displayOptions: {
show: {
resource: ['document'],
operation: ['publish'],
minor: [false],
},
},
default: '',
description: 'Comma-separated list of approver profile IDs. When provided, an approval is requested instead of publishing immediately.',
},
{
displayName: 'Changelog',
name: 'changelog',
type: 'string',
typeOptions: {
rows: 4,
},
displayOptions: {
show: {
resource: ['document'],
operation: ['publish'],
},
},
default: '',
description: 'The changelog for this version',
required: true,
},
];
export async function execute(
this: IExecuteFunctions,
itemIndex: number,
): Promise<INodeExecutionData> {
const documentId = this.getNodeParameter('documentId', itemIndex) as string;
const minor = this.getNodeParameter('minor', itemIndex, false) as boolean;
const approverIdsRaw = this.getNodeParameter('approverIds', itemIndex, '') as string;
const changelog = this.getNodeParameter('changelog', itemIndex) as string;
const query = `
mutation PublishDocument($input: PublishDocumentInput!) {
publishDocument(input: $input) {
document {
id
status
trustCenterVisibility
currentPublishedMajor
currentPublishedMinor
createdAt
updatedAt
}
documentVersion {
id
title
major
minor
status
content
changelog
classification
documentType
publishedAt
createdAt
updatedAt
}
approvalQuorum {
id
status
createdAt
updatedAt
}
}
}
`;
const input: Record<string, unknown> = { documentId, minor, changelog };
if (!minor && approverIdsRaw) {
const approverIds = approverIdsRaw
.split(',')
.map(id => id.trim())
.filter(Boolean);
if (approverIds.length > 0) input.approverIds = approverIds;
}
const responseData = await proboApiRequest.call(this, query, { input });
return {
json: responseData,
pairedItem: { item: itemIndex },
};
}