@aikidosec/firewall
Version:
Zen by Aikido is an embedded Application Firewall that autonomously protects Node.js apps against common and critical attacks, provides rate limiting, detects malicious traffic (including bots), and more.
32 lines (31 loc) • 898 B
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.mergeApiAuthTypes = mergeApiAuthTypes;
/**
* Merge two APIAuthType arrays into one, without duplicates.
* Can return undefined if both parameters are not an array.
*/
function mergeApiAuthTypes(existing, newAuth) {
if (!Array.isArray(newAuth) || newAuth.length === 0) {
return existing;
}
if (!Array.isArray(existing) || existing.length === 0) {
return newAuth;
}
const result = [...existing];
for (const auth of newAuth) {
if (!result.find((a) => isEqualAPIAuthType(a, auth))) {
result.push(auth);
}
}
return result;
}
/**
* Compare two APIAuthType objects for equality.
*/
function isEqualAPIAuthType(a, b) {
return (a.type === b.type &&
a.in === b.in &&
a.name === b.name &&
a.scheme === b.scheme);
}
;