UNPKG

n8n-nodes-mautic-advanced

Version:

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

54 lines (53 loc) 2.14 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports._getTrackedOAuthRequestCountForTests = exports._getOAuthRequestQueueSizeForTests = exports.waitForTrackedCredentialRequests = exports.runTrackedCredentialRequest = exports.runWithCredentialLock = void 0; const oauthRequestQueue = new Map(); const oauthInFlightRequests = new Map(); async function runWithCredentialLock(key, fn) { const previous = oauthRequestQueue.get(key) ?? Promise.resolve(); const run = (async () => { await previous.catch(() => undefined); return await fn(); })(); const tail = run.then(() => undefined, () => undefined); oauthRequestQueue.set(key, tail); try { return await run; } finally { if (oauthRequestQueue.get(key) === tail) { oauthRequestQueue.delete(key); } } } exports.runWithCredentialLock = runWithCredentialLock; async function runTrackedCredentialRequest(key, fn) { const run = Promise.resolve().then(fn); const tracker = run.then(() => undefined, () => undefined); const requests = oauthInFlightRequests.get(key) ?? new Set(); requests.add(tracker); oauthInFlightRequests.set(key, requests); try { return await run; } finally { requests.delete(tracker); if (requests.size === 0) { oauthInFlightRequests.delete(key); } } } exports.runTrackedCredentialRequest = runTrackedCredentialRequest; async function waitForTrackedCredentialRequests(key) { const requests = Array.from(oauthInFlightRequests.get(key) ?? []); await Promise.all(requests.map(async (request) => await request.catch(() => undefined))); } exports.waitForTrackedCredentialRequests = waitForTrackedCredentialRequests; function _getOAuthRequestQueueSizeForTests() { return oauthRequestQueue.size; } exports._getOAuthRequestQueueSizeForTests = _getOAuthRequestQueueSizeForTests; function _getTrackedOAuthRequestCountForTests(key) { return oauthInFlightRequests.get(key)?.size ?? 0; } exports._getTrackedOAuthRequestCountForTests = _getTrackedOAuthRequestCountForTests;