n8n/packages/nodes-base/nodes/Venafi/Datacenter/VenafiTlsProtectDatacenterTrigger.node.ts
Iván Ovejero b03e358a12
refactor: Integrate consistent-type-imports in nodes-base (no-changelog) (#5267)
* 👕 Enable `consistent-type-imports` for nodes-base

* 👕 Apply to nodes-base

*  Undo unrelated changes

* 🚚 Move to `.eslintrc.js` in nodes-base

*  Revert "Enable `consistent-type-imports` for nodes-base"

This reverts commit 529ad72b05.

* 👕 Fix severity
2023-01-27 12:22:44 +01:00

80 lines
1.7 KiB
TypeScript
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import type { IPollFunctions } from 'n8n-core';
import type {
IDataObject,
INodeExecutionData,
INodeType,
INodeTypeDescription,
} from 'n8n-workflow';
import moment from 'moment';
import { venafiApiRequest } from './GenericFunctions';
export class VenafiTlsProtectDatacenterTrigger implements INodeType {
description: INodeTypeDescription = {
displayName: 'Venafi TLS Protect Datacenter Trigger',
name: 'venafiTlsProtectDatacenterTrigger',
icon: 'file:../venafi.svg',
group: ['trigger'],
version: 1,
subtitle: '={{$parameter["triggerOn"]}}',
description: 'Starts the workflow when Venafi events occur',
defaults: {
name: 'Venafi TLS Protect Datacenter',
},
credentials: [
{
name: 'venafiTlsProtectDatacenterApi',
required: true,
},
],
polling: true,
inputs: [],
outputs: ['main'],
properties: [
{
displayName: 'Trigger On',
name: 'triggerOn',
type: 'options',
options: [
{
name: 'Certificate Expired',
value: 'certificateExpired',
},
],
required: true,
default: 'certificateExpired',
},
],
};
async poll(this: IPollFunctions): Promise<INodeExecutionData[][] | null> {
const webhookData = this.getWorkflowStaticData('node');
const qs: IDataObject = {};
const now = moment().format();
qs.ValidToGreater = webhookData.lastTimeChecked || now;
qs.ValidToLess = now;
const { Certificates: certificates } = await venafiApiRequest.call(
this,
'GET',
'/vedsdk/certificates',
{},
qs,
);
webhookData.lastTimeChecked = qs.ValidToLess;
if (Array.isArray(certificates) && certificates.length !== 0) {
return [this.helpers.returnJsonArray(certificates)];
}
return null;
}
}