Files
probo/packages/n8n-node/nodes/Probo/actions/document/getAllSignatures.operation.ts
Émile Ré eecf8a1d97 Make profile state filters multi-value
Address PR review feedback on the profile-state split: SAML sign-in now
activates a pending profile, deactivation counts owners against the
profile's own organization to close a last-owner bypass, the migration
leaves historical activated_at/deactivated_at NULL rather than
fabricating timestamps, and pending members are no longer rendered with
the deactivated (faded) styling.

Drop the single-value state filter in favor of the multi-value states
across the profile and signatory surfaces. Remove ProfileFilter.state
(only states[] remains) and convert the signatures profileState filter
to profileStates. Turn the console people filter, the CLI
"user list --state" flag, and the n8n listUsers and getAllSignatures
state inputs into multi-select controls, where an empty selection means
all states.

Signed-off-by: Émile Ré <emile@probo.com>
2026-07-30 09:19:42 +02:00

183 lines
5.0 KiB
TypeScript

// Copyright (c) 2025-2026 Probo Inc <hello@probo.com>.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
import type { INodeProperties, IExecuteFunctions, INodeExecutionData, IDataObject } from 'n8n-workflow';
import { proboApiRequestAllItems } from '../../GenericFunctions';
export const description: INodeProperties[] = [
{
displayName: 'Document Version ID',
name: 'documentVersionId',
type: 'string',
displayOptions: {
show: {
resource: ['document'],
operation: ['getAllSignatures'],
},
},
default: '',
description: 'The ID of the document version',
required: true,
},
{
displayName: 'Return All',
name: 'returnAll',
type: 'boolean',
displayOptions: {
show: {
resource: ['document'],
operation: ['getAllSignatures'],
},
},
default: false,
description: 'Whether to return all results or only up to a given limit',
},
{
displayName: 'Limit',
name: 'limit',
type: 'number',
displayOptions: {
show: {
resource: ['document'],
operation: ['getAllSignatures'],
returnAll: [false],
},
},
typeOptions: {
minValue: 1,
},
default: 50,
description: 'Max number of results to return',
},
{
displayName: 'Filters',
name: 'filters',
type: 'collection',
placeholder: 'Add Filter',
default: {},
displayOptions: {
show: {
resource: ['document'],
operation: ['getAllSignatures'],
},
},
options: [
{
displayName: 'States',
name: 'states',
type: 'multiOptions',
default: [],
description: 'Filter by signature state',
options: [
{ name: 'Requested', value: 'REQUESTED' },
{ name: 'Signed', value: 'SIGNED' },
],
},
{
displayName: 'Active Contract',
name: 'activeContract',
type: 'boolean',
default: false,
description: 'Whether to filter by active contract status',
},
{
displayName: 'Profile States',
name: 'state',
type: 'multiOptions',
default: [],
description: 'Filter by signatory profile states',
options: [
{ name: 'Pending', value: 'PENDING' },
{ name: 'Active', value: 'ACTIVE' },
{ name: 'Deactivated', value: 'DEACTIVATED' },
],
},
],
},
];
export async function execute(
this: IExecuteFunctions,
itemIndex: number,
): Promise<INodeExecutionData> {
const documentVersionId = this.getNodeParameter('documentVersionId', itemIndex) as string;
const returnAll = this.getNodeParameter('returnAll', itemIndex) as boolean;
const limit = this.getNodeParameter('limit', itemIndex, 50) as number;
const filters = this.getNodeParameter('filters', itemIndex, {}) as IDataObject;
const filter: IDataObject = {};
if ((filters.states as string[])?.length) filter.states = filters.states;
if (filters.activeContract !== undefined) filter.activeContract = filters.activeContract;
if ((filters.state as string[])?.length) filter.profileStates = filters.state;
const hasFilter = Object.keys(filter).length > 0;
const query = `
query GetDocumentVersionSignatures($documentVersionId: ID!, $first: Int, $after: CursorKey${hasFilter ? ', $filter: DocumentVersionSignatureFilter' : ''}) {
node(id: $documentVersionId) {
... on DocumentVersion {
signatures(first: $first, after: $after${hasFilter ? ', filter: $filter' : ''}) {
edges {
node {
id
state
signedAt
requestedAt
createdAt
updatedAt
signedBy {
id
fullName
emailAddress
}
}
}
pageInfo {
hasNextPage
endCursor
}
}
}
}
}
`;
const variables: IDataObject = { documentVersionId };
if (hasFilter) variables.filter = filter;
const signatures = await proboApiRequestAllItems.call(
this,
query,
variables,
(response) => {
const data = response?.data as IDataObject | undefined;
const node = data?.node as IDataObject | undefined;
return node?.signatures as IDataObject | undefined;
},
returnAll,
limit,
);
return {
json: { signatures },
pairedItem: { item: itemIndex },
};
}