2024-07-29 05:58:03 -07:00
|
|
|
import type {
|
|
|
|
INodeExecutionData,
|
|
|
|
MultiPartFormData,
|
|
|
|
IDataObject,
|
|
|
|
IWebhookFunctions,
|
2024-10-17 06:59:53 -07:00
|
|
|
FormFieldsParameter,
|
|
|
|
NodeTypeAndVersion,
|
|
|
|
} from 'n8n-workflow';
|
|
|
|
import {
|
|
|
|
FORM_NODE_TYPE,
|
|
|
|
FORM_TRIGGER_NODE_TYPE,
|
|
|
|
NodeOperationError,
|
|
|
|
WAIT_NODE_TYPE,
|
|
|
|
jsonParse,
|
2024-06-06 03:12:52 -07:00
|
|
|
} from 'n8n-workflow';
|
2024-07-29 05:58:03 -07:00
|
|
|
|
2024-10-17 06:59:53 -07:00
|
|
|
import type { FormTriggerData, FormTriggerInput } from './interfaces';
|
|
|
|
import { FORM_TRIGGER_AUTHENTICATION_PROPERTY } from './interfaces';
|
|
|
|
|
2024-08-29 06:55:53 -07:00
|
|
|
import { WebhookAuthorizationError } from '../Webhook/error';
|
|
|
|
import { validateWebhookAuthentication } from '../Webhook/utils';
|
2024-10-17 06:59:53 -07:00
|
|
|
|
|
|
|
import { DateTime } from 'luxon';
|
|
|
|
import isbot from 'isbot';
|
|
|
|
import type { Response } from 'express';
|
|
|
|
import { getResolvables } from '../../utils/utilities';
|
2023-10-16 21:09:30 -07:00
|
|
|
|
2024-07-29 05:58:03 -07:00
|
|
|
export function prepareFormData({
|
|
|
|
formTitle,
|
|
|
|
formDescription,
|
|
|
|
formSubmittedText,
|
|
|
|
redirectUrl,
|
|
|
|
formFields,
|
|
|
|
testRun,
|
|
|
|
query,
|
|
|
|
instanceId,
|
|
|
|
useResponseData,
|
2024-04-19 01:26:19 -07:00
|
|
|
appendAttribution = true,
|
2024-10-17 06:59:53 -07:00
|
|
|
buttonLabel,
|
2024-07-29 05:58:03 -07:00
|
|
|
}: {
|
|
|
|
formTitle: string;
|
|
|
|
formDescription: string;
|
|
|
|
formSubmittedText: string | undefined;
|
|
|
|
redirectUrl: string | undefined;
|
2024-10-17 06:59:53 -07:00
|
|
|
formFields: FormFieldsParameter;
|
2024-07-29 05:58:03 -07:00
|
|
|
testRun: boolean;
|
|
|
|
query: IDataObject;
|
|
|
|
instanceId?: string;
|
|
|
|
useResponseData?: boolean;
|
|
|
|
appendAttribution?: boolean;
|
2024-10-17 06:59:53 -07:00
|
|
|
buttonLabel?: string;
|
2024-07-29 05:58:03 -07:00
|
|
|
}) {
|
2023-10-16 21:09:30 -07:00
|
|
|
const validForm = formFields.length > 0;
|
|
|
|
const utm_campaign = instanceId ? `&utm_campaign=${instanceId}` : '';
|
|
|
|
const n8nWebsiteLink = `https://n8n.io/?utm_source=n8n-internal&utm_medium=form-trigger${utm_campaign}`;
|
|
|
|
|
|
|
|
if (formSubmittedText === undefined) {
|
|
|
|
formSubmittedText = 'Your response has been recorded';
|
|
|
|
}
|
|
|
|
|
|
|
|
const formData: FormTriggerData = {
|
|
|
|
testRun,
|
|
|
|
validForm,
|
|
|
|
formTitle,
|
|
|
|
formDescription,
|
|
|
|
formSubmittedText,
|
|
|
|
n8nWebsiteLink,
|
|
|
|
formFields: [],
|
2023-12-13 07:00:51 -08:00
|
|
|
useResponseData,
|
2024-04-19 01:26:19 -07:00
|
|
|
appendAttribution,
|
2024-10-17 06:59:53 -07:00
|
|
|
buttonLabel,
|
2023-10-16 21:09:30 -07:00
|
|
|
};
|
|
|
|
|
2023-12-13 07:00:51 -08:00
|
|
|
if (redirectUrl) {
|
|
|
|
if (!redirectUrl.includes('://')) {
|
|
|
|
redirectUrl = `http://${redirectUrl}`;
|
|
|
|
}
|
|
|
|
formData.redirectUrl = redirectUrl;
|
|
|
|
}
|
|
|
|
|
2023-10-16 21:09:30 -07:00
|
|
|
if (!validForm) {
|
|
|
|
return formData;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (const [index, field] of formFields.entries()) {
|
2024-07-29 05:58:03 -07:00
|
|
|
const { fieldType, requiredField, multiselect, placeholder } = field;
|
2023-10-16 21:09:30 -07:00
|
|
|
|
|
|
|
const input: IDataObject = {
|
|
|
|
id: `field-${index}`,
|
|
|
|
errorId: `error-field-${index}`,
|
|
|
|
label: field.fieldLabel,
|
|
|
|
inputRequired: requiredField ? 'form-required' : '',
|
2024-07-29 05:58:03 -07:00
|
|
|
defaultValue: query[field.fieldLabel] ?? '',
|
|
|
|
placeholder,
|
2023-10-16 21:09:30 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
if (multiselect) {
|
|
|
|
input.isMultiSelect = true;
|
|
|
|
input.multiSelectOptions =
|
|
|
|
field.fieldOptions?.values.map((e, i) => ({
|
2024-10-02 07:58:47 -07:00
|
|
|
id: `option${i}_${input.id}`,
|
2023-10-16 21:09:30 -07:00
|
|
|
label: e.option,
|
|
|
|
})) ?? [];
|
2024-07-29 05:58:03 -07:00
|
|
|
} else if (fieldType === 'file') {
|
|
|
|
input.isFileInput = true;
|
|
|
|
input.acceptFileTypes = field.acceptFileTypes;
|
|
|
|
input.multipleFiles = field.multipleFiles ? 'multiple' : '';
|
2023-10-16 21:09:30 -07:00
|
|
|
} else if (fieldType === 'dropdown') {
|
|
|
|
input.isSelect = true;
|
|
|
|
const fieldOptions = field.fieldOptions?.values ?? [];
|
|
|
|
input.selectOptions = fieldOptions.map((e) => e.option);
|
2023-11-01 05:23:28 -07:00
|
|
|
} else if (fieldType === 'textarea') {
|
|
|
|
input.isTextarea = true;
|
2023-10-16 21:09:30 -07:00
|
|
|
} else {
|
|
|
|
input.isInput = true;
|
2024-07-29 05:58:03 -07:00
|
|
|
input.type = fieldType as 'text' | 'number' | 'date' | 'email';
|
2023-10-16 21:09:30 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
formData.formFields.push(input as FormTriggerInput);
|
|
|
|
}
|
|
|
|
|
|
|
|
return formData;
|
2024-07-29 05:58:03 -07:00
|
|
|
}
|
2023-12-13 07:00:51 -08:00
|
|
|
|
2024-06-06 03:12:52 -07:00
|
|
|
const checkResponseModeConfiguration = (context: IWebhookFunctions) => {
|
|
|
|
const responseMode = context.getNodeParameter('responseMode', 'onReceived') as string;
|
|
|
|
const connectedNodes = context.getChildNodes(context.getNode().name);
|
|
|
|
|
|
|
|
const isRespondToWebhookConnected = connectedNodes.some(
|
|
|
|
(node) => node.type === 'n8n-nodes-base.respondToWebhook',
|
|
|
|
);
|
|
|
|
|
|
|
|
if (!isRespondToWebhookConnected && responseMode === 'responseNode') {
|
|
|
|
throw new NodeOperationError(
|
|
|
|
context.getNode(),
|
|
|
|
new Error('No Respond to Webhook node found in the workflow'),
|
|
|
|
{
|
|
|
|
description:
|
|
|
|
'Insert a Respond to Webhook node to your workflow to respond to the form submission or choose another option for the “Respond When” parameter',
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isRespondToWebhookConnected && responseMode !== 'responseNode') {
|
|
|
|
throw new NodeOperationError(
|
|
|
|
context.getNode(),
|
|
|
|
new Error(`${context.getNode().name} node not correctly configured`),
|
|
|
|
{
|
|
|
|
description:
|
|
|
|
'Set the “Respond When” parameter to “Using Respond to Webhook Node” or remove the Respond to Webhook node',
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2024-10-17 06:59:53 -07:00
|
|
|
export async function prepareFormReturnItem(
|
|
|
|
context: IWebhookFunctions,
|
|
|
|
formFields: FormFieldsParameter,
|
|
|
|
mode: 'test' | 'production',
|
|
|
|
useWorkflowTimezone: boolean = false,
|
|
|
|
) {
|
|
|
|
const bodyData = (context.getBodyData().data as IDataObject) ?? {};
|
|
|
|
const files = (context.getBodyData().files as IDataObject) ?? {};
|
|
|
|
|
|
|
|
const returnItem: INodeExecutionData = {
|
|
|
|
json: {},
|
|
|
|
};
|
|
|
|
if (files && Object.keys(files).length) {
|
|
|
|
returnItem.binary = {};
|
|
|
|
}
|
|
|
|
|
|
|
|
for (const key of Object.keys(files)) {
|
|
|
|
const processFiles: MultiPartFormData.File[] = [];
|
|
|
|
let multiFile = false;
|
|
|
|
const filesInput = files[key] as MultiPartFormData.File[] | MultiPartFormData.File;
|
|
|
|
|
|
|
|
if (Array.isArray(filesInput)) {
|
|
|
|
bodyData[key] = filesInput.map((file) => ({
|
|
|
|
filename: file.originalFilename,
|
|
|
|
mimetype: file.mimetype,
|
|
|
|
size: file.size,
|
|
|
|
}));
|
|
|
|
processFiles.push(...filesInput);
|
|
|
|
multiFile = true;
|
|
|
|
} else {
|
|
|
|
bodyData[key] = {
|
|
|
|
filename: filesInput.originalFilename,
|
|
|
|
mimetype: filesInput.mimetype,
|
|
|
|
size: filesInput.size,
|
|
|
|
};
|
|
|
|
processFiles.push(filesInput);
|
|
|
|
}
|
|
|
|
|
|
|
|
const entryIndex = Number(key.replace(/field-/g, ''));
|
|
|
|
const fieldLabel = isNaN(entryIndex) ? key : formFields[entryIndex].fieldLabel;
|
|
|
|
|
|
|
|
let fileCount = 0;
|
|
|
|
for (const file of processFiles) {
|
|
|
|
let binaryPropertyName = fieldLabel.replace(/\W/g, '_');
|
|
|
|
|
|
|
|
if (multiFile) {
|
|
|
|
binaryPropertyName += `_${fileCount++}`;
|
|
|
|
}
|
|
|
|
|
|
|
|
returnItem.binary![binaryPropertyName] = await context.nodeHelpers.copyBinaryFile(
|
|
|
|
file.filepath,
|
|
|
|
file.originalFilename ?? file.newFilename,
|
|
|
|
file.mimetype,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (const [index, field] of formFields.entries()) {
|
|
|
|
const key = `field-${index}`;
|
|
|
|
let value = bodyData[key] ?? null;
|
|
|
|
|
|
|
|
if (value === null) {
|
|
|
|
returnItem.json[field.fieldLabel] = null;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (field.fieldType === 'number') {
|
|
|
|
value = Number(value);
|
|
|
|
}
|
|
|
|
if (field.fieldType === 'text') {
|
|
|
|
value = String(value).trim();
|
|
|
|
}
|
|
|
|
if (field.multiselect && typeof value === 'string') {
|
|
|
|
value = jsonParse(value);
|
|
|
|
}
|
|
|
|
if (field.fieldType === 'date' && value && field.formatDate !== '') {
|
|
|
|
value = DateTime.fromFormat(String(value), 'yyyy-mm-dd').toFormat(field.formatDate as string);
|
|
|
|
}
|
|
|
|
if (field.fieldType === 'file' && field.multipleFiles && !Array.isArray(value)) {
|
|
|
|
value = [value];
|
|
|
|
}
|
|
|
|
|
|
|
|
returnItem.json[field.fieldLabel] = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
const timezone = useWorkflowTimezone ? context.getTimezone() : 'UTC';
|
|
|
|
returnItem.json.submittedAt = DateTime.now().setZone(timezone).toISO();
|
|
|
|
|
|
|
|
returnItem.json.formMode = mode;
|
|
|
|
|
|
|
|
const workflowStaticData = context.getWorkflowStaticData('node');
|
|
|
|
if (
|
|
|
|
Object.keys(workflowStaticData || {}).length &&
|
|
|
|
context.getNode().type === FORM_TRIGGER_NODE_TYPE
|
|
|
|
) {
|
|
|
|
returnItem.json.formQueryParameters = workflowStaticData;
|
|
|
|
}
|
|
|
|
|
|
|
|
return returnItem;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function renderForm({
|
|
|
|
context,
|
|
|
|
res,
|
|
|
|
formTitle,
|
|
|
|
formDescription,
|
|
|
|
formFields,
|
|
|
|
responseMode,
|
|
|
|
mode,
|
|
|
|
formSubmittedText,
|
|
|
|
redirectUrl,
|
|
|
|
appendAttribution,
|
|
|
|
buttonLabel,
|
|
|
|
}: {
|
|
|
|
context: IWebhookFunctions;
|
|
|
|
res: Response;
|
|
|
|
formTitle: string;
|
|
|
|
formDescription: string;
|
|
|
|
formFields: FormFieldsParameter;
|
|
|
|
responseMode: string;
|
|
|
|
mode: 'test' | 'production';
|
|
|
|
formSubmittedText?: string;
|
|
|
|
redirectUrl?: string;
|
|
|
|
appendAttribution?: boolean;
|
|
|
|
buttonLabel?: string;
|
|
|
|
}) {
|
|
|
|
formDescription = (formDescription || '').replace(/\\n/g, '\n').replace(/<br>/g, '\n');
|
|
|
|
const instanceId = context.getInstanceId();
|
|
|
|
|
|
|
|
const useResponseData = responseMode === 'responseNode';
|
|
|
|
|
|
|
|
let query: IDataObject = {};
|
|
|
|
|
|
|
|
if (context.getNode().type === FORM_TRIGGER_NODE_TYPE) {
|
|
|
|
query = context.getRequestObject().query as IDataObject;
|
|
|
|
const workflowStaticData = context.getWorkflowStaticData('node');
|
|
|
|
for (const key of Object.keys(query)) {
|
|
|
|
workflowStaticData[key] = query[key];
|
|
|
|
}
|
|
|
|
} else if (context.getNode().type === FORM_NODE_TYPE) {
|
|
|
|
const parentNodes = context.getParentNodes(context.getNode().name);
|
|
|
|
const trigger = parentNodes.find(
|
|
|
|
(node) => node.type === FORM_TRIGGER_NODE_TYPE,
|
|
|
|
) as NodeTypeAndVersion;
|
|
|
|
try {
|
|
|
|
const triggerQueryParameters = context.evaluateExpression(
|
|
|
|
`{{ $('${trigger?.name}').first().json.formQueryParameters }}`,
|
|
|
|
) as IDataObject;
|
|
|
|
|
|
|
|
if (triggerQueryParameters) {
|
|
|
|
query = triggerQueryParameters;
|
|
|
|
}
|
|
|
|
} catch (error) {}
|
|
|
|
}
|
|
|
|
|
|
|
|
const data = prepareFormData({
|
|
|
|
formTitle,
|
|
|
|
formDescription,
|
|
|
|
formSubmittedText,
|
|
|
|
redirectUrl,
|
|
|
|
formFields,
|
|
|
|
testRun: mode === 'test',
|
|
|
|
query,
|
|
|
|
instanceId,
|
|
|
|
useResponseData,
|
|
|
|
appendAttribution,
|
|
|
|
buttonLabel,
|
|
|
|
});
|
|
|
|
|
|
|
|
res.render('form-trigger', data);
|
|
|
|
}
|
|
|
|
|
2024-07-30 05:43:05 -07:00
|
|
|
export async function formWebhook(
|
|
|
|
context: IWebhookFunctions,
|
|
|
|
authProperty = FORM_TRIGGER_AUTHENTICATION_PROPERTY,
|
|
|
|
) {
|
|
|
|
const node = context.getNode();
|
2024-07-29 05:58:03 -07:00
|
|
|
const options = context.getNodeParameter('options', {}) as {
|
|
|
|
ignoreBots?: boolean;
|
|
|
|
respondWithOptions?: {
|
|
|
|
values: {
|
|
|
|
respondWith: 'text' | 'redirect';
|
|
|
|
formSubmittedText: string;
|
|
|
|
redirectUrl: string;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
formSubmittedText?: string;
|
|
|
|
useWorkflowTimezone?: boolean;
|
|
|
|
appendAttribution?: boolean;
|
2024-10-17 06:59:53 -07:00
|
|
|
buttonLabel?: string;
|
2024-07-29 05:58:03 -07:00
|
|
|
};
|
|
|
|
const res = context.getResponseObject();
|
|
|
|
const req = context.getRequestObject();
|
|
|
|
|
|
|
|
try {
|
2024-07-30 05:43:05 -07:00
|
|
|
if (options.ignoreBots && isbot(req.headers['user-agent'])) {
|
2024-07-29 05:58:03 -07:00
|
|
|
throw new WebhookAuthorizationError(403);
|
2024-07-30 05:43:05 -07:00
|
|
|
}
|
2024-08-12 23:34:55 -07:00
|
|
|
if (node.typeVersion > 1) {
|
|
|
|
await validateWebhookAuthentication(context, authProperty);
|
|
|
|
}
|
2024-07-29 05:58:03 -07:00
|
|
|
} catch (error) {
|
|
|
|
if (error instanceof WebhookAuthorizationError) {
|
2024-08-15 04:03:16 -07:00
|
|
|
res.setHeader('WWW-Authenticate', 'Basic realm="Enter credentials"');
|
|
|
|
res.status(401).send();
|
2024-07-29 05:58:03 -07:00
|
|
|
return { noWebhookResponse: true };
|
|
|
|
}
|
|
|
|
throw error;
|
|
|
|
}
|
|
|
|
|
2023-12-13 07:00:51 -08:00
|
|
|
const mode = context.getMode() === 'manual' ? 'test' : 'production';
|
2024-10-17 06:59:53 -07:00
|
|
|
const formFields = context.getNodeParameter('formFields.values', []) as FormFieldsParameter;
|
2023-12-13 07:00:51 -08:00
|
|
|
const method = context.getRequestObject().method;
|
|
|
|
|
2024-06-06 03:12:52 -07:00
|
|
|
checkResponseModeConfiguration(context);
|
|
|
|
|
2023-12-13 07:00:51 -08:00
|
|
|
//Show the form on GET request
|
|
|
|
if (method === 'GET') {
|
|
|
|
const formTitle = context.getNodeParameter('formTitle', '') as string;
|
2024-10-17 06:59:53 -07:00
|
|
|
const formDescription = context.getNodeParameter('formDescription', '') as string;
|
2023-12-13 07:00:51 -08:00
|
|
|
const responseMode = context.getNodeParameter('responseMode', '') as string;
|
|
|
|
|
|
|
|
let formSubmittedText;
|
|
|
|
let redirectUrl;
|
2024-04-19 01:26:19 -07:00
|
|
|
let appendAttribution = true;
|
2023-12-13 07:00:51 -08:00
|
|
|
|
|
|
|
if (options.respondWithOptions) {
|
|
|
|
const values = (options.respondWithOptions as IDataObject).values as IDataObject;
|
|
|
|
if (values.respondWith === 'text') {
|
|
|
|
formSubmittedText = values.formSubmittedText as string;
|
|
|
|
}
|
|
|
|
if (values.respondWith === 'redirect') {
|
|
|
|
redirectUrl = values.redirectUrl as string;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
formSubmittedText = options.formSubmittedText as string;
|
|
|
|
}
|
|
|
|
|
2024-04-19 01:26:19 -07:00
|
|
|
if (options.appendAttribution === false) {
|
|
|
|
appendAttribution = false;
|
|
|
|
}
|
|
|
|
|
2024-10-17 06:59:53 -07:00
|
|
|
let buttonLabel = 'Submit';
|
|
|
|
|
|
|
|
if (options.buttonLabel) {
|
|
|
|
buttonLabel = options.buttonLabel;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!redirectUrl && node.type !== FORM_TRIGGER_NODE_TYPE) {
|
|
|
|
const connectedNodes = context.getChildNodes(context.getNode().name);
|
|
|
|
const hasNextPage = connectedNodes.some(
|
|
|
|
(n) => n.type === FORM_NODE_TYPE || n.type === WAIT_NODE_TYPE,
|
|
|
|
);
|
2023-12-13 07:00:51 -08:00
|
|
|
|
2024-10-17 06:59:53 -07:00
|
|
|
if (hasNextPage) {
|
|
|
|
redirectUrl = context.evaluateExpression('{{ $execution.resumeFormUrl }}') as string;
|
|
|
|
}
|
|
|
|
}
|
2024-07-29 05:58:03 -07:00
|
|
|
|
2024-10-17 06:59:53 -07:00
|
|
|
renderForm({
|
|
|
|
context,
|
|
|
|
res,
|
2023-12-13 07:00:51 -08:00
|
|
|
formTitle,
|
|
|
|
formDescription,
|
2024-10-17 06:59:53 -07:00
|
|
|
formFields,
|
|
|
|
responseMode,
|
|
|
|
mode,
|
2023-12-13 07:00:51 -08:00
|
|
|
formSubmittedText,
|
|
|
|
redirectUrl,
|
2024-04-19 01:26:19 -07:00
|
|
|
appendAttribution,
|
2024-10-17 06:59:53 -07:00
|
|
|
buttonLabel,
|
2024-07-29 05:58:03 -07:00
|
|
|
});
|
2023-12-13 07:00:51 -08:00
|
|
|
|
|
|
|
return {
|
|
|
|
noWebhookResponse: true,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2024-10-17 06:59:53 -07:00
|
|
|
let { useWorkflowTimezone } = options;
|
2024-07-29 05:58:03 -07:00
|
|
|
|
2024-10-17 06:59:53 -07:00
|
|
|
if (useWorkflowTimezone === undefined && node.typeVersion > 2) {
|
|
|
|
useWorkflowTimezone = true;
|
2024-07-29 05:58:03 -07:00
|
|
|
}
|
|
|
|
|
2024-10-17 06:59:53 -07:00
|
|
|
const returnItem = await prepareFormReturnItem(context, formFields, mode, useWorkflowTimezone);
|
2024-07-29 05:58:03 -07:00
|
|
|
|
2024-10-17 06:59:53 -07:00
|
|
|
return {
|
|
|
|
webhookResponse: { status: 200 },
|
|
|
|
workflowData: [[returnItem]],
|
|
|
|
};
|
|
|
|
}
|
2024-07-29 05:58:03 -07:00
|
|
|
|
2024-10-17 06:59:53 -07:00
|
|
|
export function resolveRawData(context: IWebhookFunctions, rawData: string) {
|
|
|
|
const resolvables = getResolvables(rawData);
|
|
|
|
let returnData: string = rawData;
|
2024-07-29 05:58:03 -07:00
|
|
|
|
2024-10-17 06:59:53 -07:00
|
|
|
if (returnData.startsWith('=')) {
|
|
|
|
returnData = returnData.replace(/^=+/, '');
|
|
|
|
} else {
|
|
|
|
return returnData;
|
2024-07-29 05:58:03 -07:00
|
|
|
}
|
2023-12-13 07:00:51 -08:00
|
|
|
|
2024-10-17 06:59:53 -07:00
|
|
|
if (resolvables.length) {
|
|
|
|
for (const resolvable of resolvables) {
|
|
|
|
const resolvedValue = context.evaluateExpression(`${resolvable}`);
|
2023-12-13 07:00:51 -08:00
|
|
|
|
2024-10-17 06:59:53 -07:00
|
|
|
if (typeof resolvedValue === 'object' && resolvedValue !== null) {
|
|
|
|
returnData = returnData.replace(resolvable, JSON.stringify(resolvedValue));
|
|
|
|
} else {
|
|
|
|
returnData = returnData.replace(resolvable, resolvedValue as string);
|
|
|
|
}
|
2024-07-29 05:58:03 -07:00
|
|
|
}
|
|
|
|
}
|
2024-10-17 06:59:53 -07:00
|
|
|
return returnData;
|
2023-12-13 07:00:51 -08:00
|
|
|
}
|