Skip to content

AI Agents & MCPs & AI Workflow Automation • (~400 MCP servers for AI agents) • AI Automation / AI Agent with MCPs • AI Workflows & AI Agents • MCPs for AI Agents

2.0 KB
Raw Blame
import { createAction, Property } from '@activepieces/pieces-framework';

import { robollyAuth } from '../../auth';
import { robollyAiProps } from '../../common/ai-props';
import { robollyApi } from '../../common/api';
import { robollyCreateHiddenRenderLinkOutputSchema } from '../../output-schemas';

const RESERVED_KEYS = ['template', 'sig'];

const formatOptions = [
	{ label: 'JPG', value: 'jpg' },
	{ label: 'PNG', value: 'png' },
	{ label: 'PDF', value: 'pdf' },
];

export const createHiddenRenderLinkAction = createAction({
	auth: robollyAuth,
	name: 'robolly_create_hidden_render_link',
	outputSchema: robollyCreateHiddenRenderLinkOutputSchema,
	displayName: 'Create Hidden Render Link',
	description: 'Builds a signed render link that looks like a static file URL.',
	audience: 'ai',
	classification: 'READ',
	aiMetadata: {
		description:
			'Builds a signed, static-looking render link for a template with the given element values, for embedding in public pages or emails. It sends no request; the template renders, and uses render credits, each time the link is opened. Use Render Template instead to render now and get the file URL.',
		idempotent: true,
	},
	props: {
		templateId: robollyAiProps.templateId({ required: true }),
		format: Property.StaticDropdown({
			displayName: 'Format',
			description: 'The output format.',
			required: true,
			defaultValue: 'jpg',
			options: { options: formatOptions },
		}),
		modifications: robollyAiProps.modifications({ required: false }),
	},
	async run({ auth, propsValue }) {
		const reservedKeys = Object.keys(propsValue.modifications ?? {}).filter((key) =>
			RESERVED_KEYS.includes(key),
		);
		if (reservedKeys.length > 0) {
			throw new Error(
				`"Modifications" can't include ${reservedKeys
					.map((key) => `"${key}"`)
					.join(' or ')}: the link sets the template from "Template ID" and signs itself.`,
			);
		}
		return robollyApi.createHiddenRenderLink({
			auth,
			templateId: propsValue.templateId,
			format: propsValue.format,
			modifications: propsValue.modifications,
		});
	},
});