UNPKG

n8n

Version:

n8n Workflow Automation Tool

170 lines 8.81 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.workflowDetailsOutputSchema = exports.toNodeGroupSummary = exports.nodeGroupSchema = exports.successMessageOutputSchema = exports.columnNameSchema = exports.dataTableProjectIdSchema = exports.createLimitSchema = exports.dataTableSchema = exports.dataTableColumnSchema = exports.dataTableColumnTypeSchema = exports.workflowMetaSchema = exports.workflowSettingsSchema = exports.toTagSummary = exports.tagSchema = exports.connectionsSchema = exports.sanitizeNodeCredentials = exports.nodeSchema = exports.nodeCredentialSummarySchema = void 0; const zod_1 = __importDefault(require("zod")); exports.nodeCredentialSummarySchema = zod_1.default .object({ id: zod_1.default .string() .describe('The credential ID, used to reference this credential in write operations'), name: zod_1.default.string().describe('The credential name'), }) .describe('The credential assigned to this slot (id and name only, never secret data)'); exports.nodeSchema = zod_1.default .object({ name: zod_1.default.string(), type: zod_1.default.string(), credentials: zod_1.default .record(zod_1.default.string(), exports.nodeCredentialSummarySchema) .optional() .describe('Credentials assigned to the node, keyed by credential type (e.g. "slackApi"). Reuse these when adding nodes for the same service to this workflow.'), }) .passthrough(); const sanitizeNodeCredentials = ({ credentials, ...node }) => { const referenceable = []; for (const [type, cred] of Object.entries(credentials ?? {})) { if (!cred?.id) continue; referenceable.push([type, { id: cred.id, name: cred.name }]); } if (referenceable.length === 0) return node; return { ...node, credentials: Object.fromEntries(referenceable) }; }; exports.sanitizeNodeCredentials = sanitizeNodeCredentials; exports.connectionsSchema = zod_1.default .custom((_value) => true) .describe('The node connections, keyed by source node name'); exports.tagSchema = zod_1.default.object({ id: zod_1.default.string(), name: zod_1.default.string() }).passthrough(); const toTagSummary = (tags) => (tags ?? []).map((tag) => ({ id: tag.id, name: tag.name })); exports.toTagSummary = toTagSummary; exports.workflowSettingsSchema = zod_1.default .custom((_value) => true) .nullable(); exports.workflowMetaSchema = zod_1.default .custom((_value) => true) .nullable(); exports.dataTableColumnTypeSchema = zod_1.default .enum(['string', 'number', 'boolean', 'date']) .describe('The data type of the column'); exports.dataTableColumnSchema = zod_1.default.object({ id: zod_1.default.string().describe('The unique identifier of the column'), name: zod_1.default.string().describe('The name of the column'), type: exports.dataTableColumnTypeSchema, index: zod_1.default.number().int().describe('The position of the column in the table'), }); exports.dataTableSchema = zod_1.default.object({ id: zod_1.default.string().describe('Autogenerated unique identifier of the data table.'), name: zod_1.default.string().describe('The name of the data table'), projectId: zod_1.default.string().describe('The project this data table belongs to'), createdAt: zod_1.default.string().describe('Autogenerated ISO timestamp when the data table was created'), updatedAt: zod_1.default .string() .describe('Autogenerated ISO timestamp when the data table was last updated'), columns: zod_1.default.array(exports.dataTableColumnSchema).describe('The columns defined in this data table'), }); const createLimitSchema = (max) => zod_1.default .number() .int() .positive() .max(max) .optional() .describe(`Limit the number of results (max ${max})`); exports.createLimitSchema = createLimitSchema; exports.dataTableProjectIdSchema = zod_1.default .string() .describe('The project ID the data table belongs to'); exports.columnNameSchema = zod_1.default .string() .min(1) .max(63) .regex(/^[a-zA-Z][a-zA-Z0-9_]*$/) .describe('Column name. Must start with a letter, contain only letters, numbers, and underscores (max 63 chars)'); exports.successMessageOutputSchema = { success: zod_1.default.boolean().describe('Whether the operation succeeded'), message: zod_1.default.string().describe('Description of the result'), }; exports.nodeGroupSchema = zod_1.default .object({ id: zod_1.default.string(), name: zod_1.default.string(), nodeNames: zod_1.default .array(zod_1.default.string()) .describe('Names of the member nodes, matching the update_workflow group operations.'), description: zod_1.default.string().optional(), }) .describe('A named visual grouping of nodes'); const toNodeGroupSummary = (nodeGroups, nodes) => { const nameById = new Map(nodes.map((node) => [node.id, node.name])); return nodeGroups.map(({ id, name, nodeIds, description }) => ({ id, name, nodeNames: nodeIds.flatMap((nodeId) => nameById.get(nodeId) ?? []), ...(description !== undefined ? { description } : {}), })); }; exports.toNodeGroupSummary = toNodeGroupSummary; const FULL_DETAIL_ONLY_NOTE = "Only included when detailLevel is 'full'."; exports.workflowDetailsOutputSchema = zod_1.default.object({ workflow: zod_1.default .object({ id: zod_1.default.string(), name: zod_1.default.string().nullable(), active: zod_1.default.boolean(), isArchived: zod_1.default.boolean(), versionId: zod_1.default.string().describe('The current workflow version ID'), activeVersionId: zod_1.default .string() .nullable() .describe('The active workflow version ID, if available'), triggerCount: zod_1.default.number(), nodeCount: zod_1.default .number() .describe('Number of nodes in the workflow, reported even when detailLevel omits them'), createdAt: zod_1.default.string().nullable(), updatedAt: zod_1.default.string().nullable(), settings: exports.workflowSettingsSchema, connections: zod_1.default.record(zod_1.default.unknown()).optional().describe(FULL_DETAIL_ONLY_NOTE), nodes: zod_1.default.array(exports.nodeSchema).optional().describe(FULL_DETAIL_ONLY_NOTE), nodeGroups: zod_1.default .array(exports.nodeGroupSchema) .optional() .describe(`Node groups in the workflow. ${FULL_DETAIL_ONLY_NOTE}`), activeVersion: zod_1.default .discriminatedUnion('sameAsDraft', [ zod_1.default.object({ sameAsDraft: zod_1.default .literal(true) .describe('The published version is identical to the current draft — use the top-level nodes, connections and nodeGroups.'), }), zod_1.default.object({ sameAsDraft: zod_1.default.literal(false), nodes: zod_1.default.array(exports.nodeSchema), connections: zod_1.default.record(zod_1.default.unknown()), nodeGroups: zod_1.default.array(exports.nodeGroupSchema).describe('Node groups in the active version'), }), ]) .nullable() .optional() .describe(`Published (active) workflow graph. Null when the workflow has no published version. ${FULL_DETAIL_ONLY_NOTE}`), tags: zod_1.default.array(exports.tagSchema), meta: exports.workflowMetaSchema.optional().describe(FULL_DETAIL_ONLY_NOTE), parentFolderId: zod_1.default.string().nullable(), description: zod_1.default.string().optional().describe('The description of the workflow'), scopes: zod_1.default.array(zod_1.default.string()).describe('User permissions for this workflow'), canExecute: zod_1.default.boolean().describe('Whether the user has permission to execute this workflow'), }) .passthrough() .describe('Sanitized workflow data safe for MCP consumption'), triggerInfo: zod_1.default .string() .describe('Human-readable instructions describing how to trigger the workflow, based on the current draft (what manual executions run)'), activeVersionTriggerInfo: zod_1.default .string() .optional() .describe("Trigger info for the published (active) version, which production executions via execute_workflow run. Only present when it differs from the draft's triggerInfo."), }); //# sourceMappingURL=schemas.js.map