UNPKG

n8n

Version:

n8n Workflow Automation Tool

41 lines 1.59 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.extractAgentCredentialIds = extractAgentCredentialIds; const api_types_1 = require("@n8n/api-types"); const MANAGED_CREDENTIAL_IDS = new Set([api_types_1.MANAGED_CREDENTIAL_TOKEN, api_types_1.AI_GATEWAY_MANAGED_TAG]); function isRecord(value) { return typeof value === 'object' && value !== null && !Array.isArray(value); } function addCredentialId(value, credentialIds) { if (typeof value === 'string' && value !== '' && !MANAGED_CREDENTIAL_IDS.has(value)) { credentialIds.add(value); } } function collectCredentialIds(value, credentialIds) { if (Array.isArray(value)) { for (const entry of value) collectCredentialIds(entry, credentialIds); return; } if (!isRecord(value)) return; for (const [key, entry] of Object.entries(value)) { if (key === 'credential' || key === 'credentialId') { addCredentialId(entry, credentialIds); } else if (key === 'credentials' && isRecord(entry)) { for (const credentialReference of Object.values(entry)) { if (isRecord(credentialReference)) { addCredentialId(credentialReference.id, credentialIds); } } } collectCredentialIds(entry, credentialIds); } } function extractAgentCredentialIds(value) { const credentialIds = new Set(); collectCredentialIds(value, credentialIds); return credentialIds; } //# sourceMappingURL=extract-agent-credential-ids.js.map