n8n/packages/@n8n/node-engine-compatibility/src/guards.ts
Pierantonio Cangianiello 0f86167947
feat(engine): Prepare engine v2 for credential resolution (no-changelog) (#37876)
Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com>
2026-09-07 10:34:43 +00:00

40 lines
1.3 KiB
TypeScript

import type { INodeCredentials } from 'n8n-workflow';
import type { TriggerStepConfig, V1NodeStepConfig } from './types';
export const isRecord = (value: unknown): value is Record<string, unknown> =>
typeof value === 'object' && value !== null && !Array.isArray(value);
export function isTriggerStepConfig(config: unknown): config is TriggerStepConfig {
if (!isRecord(config)) return false;
return (
typeof config.nodeType === 'string' &&
config.nodeType.length > 0 &&
typeof config.typeVersion === 'number' &&
isRecord(config.parameters)
);
}
export function isV1NodeStepConfig(config: unknown): config is V1NodeStepConfig {
if (!isRecord(config)) return false;
return (
typeof config.nodeType === 'string' &&
config.nodeType.length > 0 &&
typeof config.typeVersion === 'number' &&
isRecord(config.parameters) &&
typeof config.continueOnFail === 'boolean' &&
(config.credentials === undefined || isNodeCredentials(config.credentials))
);
}
/** Every entry must have the shape of `INodeCredentialsDetails`, not only the outer map. */
function isNodeCredentials(value: unknown): value is INodeCredentials {
if (!isRecord(value)) return false;
return Object.values(value).every(
(details) =>
isRecord(details) &&
(typeof details.id === 'string' || details.id === null) &&
typeof details.name === 'string',
);
}