2023-09-19 03:16:35 -07:00
|
|
|
import type {
|
|
|
|
INodeExecutionData,
|
|
|
|
IExecuteFunctions,
|
|
|
|
INodeProperties,
|
|
|
|
IDataObject,
|
|
|
|
INode,
|
|
|
|
} from 'n8n-workflow';
|
|
|
|
import { NodeOperationError } from 'n8n-workflow';
|
|
|
|
|
|
|
|
import { updateDisplayOptions } from '../../../utils/utilities';
|
|
|
|
import { parseJsonParameter, composeReturnItem, resolveRawData } from './helpers/utils';
|
|
|
|
import type { SetNodeOptions } from './helpers/interfaces';
|
|
|
|
|
|
|
|
const properties: INodeProperties[] = [
|
|
|
|
{
|
|
|
|
displayName: 'JSON Output',
|
|
|
|
name: 'jsonOutput',
|
2023-12-29 01:49:27 -08:00
|
|
|
type: 'json',
|
2023-09-19 03:16:35 -07:00
|
|
|
typeOptions: {
|
|
|
|
rows: 5,
|
|
|
|
},
|
2024-01-04 08:23:24 -08:00
|
|
|
default: '{\n "my_field_1": "value",\n "my_field_2": 1\n}\n',
|
2023-09-19 03:16:35 -07:00
|
|
|
validateType: 'object',
|
|
|
|
ignoreValidationDuringExecution: true,
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
const displayOptions = {
|
|
|
|
show: {
|
|
|
|
mode: ['raw'],
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
export const description = updateDisplayOptions(displayOptions, properties);
|
|
|
|
|
|
|
|
export async function execute(
|
|
|
|
this: IExecuteFunctions,
|
|
|
|
item: INodeExecutionData,
|
|
|
|
i: number,
|
|
|
|
options: SetNodeOptions,
|
|
|
|
rawData: IDataObject,
|
|
|
|
node: INode,
|
|
|
|
) {
|
|
|
|
try {
|
|
|
|
let newData: IDataObject;
|
|
|
|
if (rawData.jsonOutput === undefined) {
|
|
|
|
const json = this.getNodeParameter('jsonOutput', i) as string;
|
|
|
|
newData = parseJsonParameter(json, node, i);
|
|
|
|
} else {
|
|
|
|
newData = parseJsonParameter(
|
|
|
|
resolveRawData.call(this, rawData.jsonOutput as string, i),
|
|
|
|
node,
|
|
|
|
i,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return composeReturnItem.call(this, i, item, newData, options);
|
|
|
|
} catch (error) {
|
|
|
|
if (this.continueOnFail()) {
|
2023-10-10 08:36:20 -07:00
|
|
|
return { json: { error: (error as Error).message }, pairedItem: { item: i } };
|
2023-09-19 03:16:35 -07:00
|
|
|
}
|
|
|
|
throw new NodeOperationError(node, error as Error, {
|
|
|
|
itemIndex: i,
|
|
|
|
description: error.description,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|