UNPKG

n8n-nodes-mautic-advanced

Version:

Enhanced n8n node for Mautic with comprehensive API coverage including tags, campaigns, categories, and advanced contact management

60 lines (59 loc) 2.02 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.OAUTH_REFRESH_ERROR_MESSAGE = exports.isInvalidGrantError = void 0; const INVALID_GRANT = 'invalid_grant'; function isRecord(value) { return typeof value === 'object' && value !== null; } function parseJsonString(value) { const trimmed = value.trim(); if (!trimmed || (!trimmed.startsWith('{') && !trimmed.startsWith('['))) { return undefined; } try { return JSON.parse(trimmed); } catch { return undefined; } } function valueContainsInvalidGrant(value, seen) { if (typeof value === 'string') { if (value.toLowerCase().includes(INVALID_GRANT)) { return true; } const parsed = parseJsonString(value); return parsed !== undefined && valueContainsInvalidGrant(parsed, seen); } if (!isRecord(value)) { return false; } if (seen.has(value)) { return false; } seen.add(value); const directFields = ['error', 'error_description', 'description', 'message']; for (const field of directFields) { if (valueContainsInvalidGrant(value[field], seen)) { return true; } } const nestedFields = ['response', 'body', 'data', 'cause']; for (const field of nestedFields) { const nested = value[field]; if (field === 'response' && isRecord(nested)) { if (valueContainsInvalidGrant(nested.body, seen)) { return true; } } if (valueContainsInvalidGrant(nested, seen)) { return true; } } return false; } function isInvalidGrantError(error) { return valueContainsInvalidGrant(error, new Set()); } exports.isInvalidGrantError = isInvalidGrantError; exports.OAUTH_REFRESH_ERROR_MESSAGE = 'OAuth token refresh failed for Mautic. A concurrent workflow may have already consumed the refresh token. Retry the workflow; if it persists, reconnect the Mautic OAuth2 credential.';