UNPKG

@fajarnugraha37/nope-iam

Version:

A highly extensible, type-safe IAM-like access control library for Node.js, inspired by AWS IAM. Deny by default, allow by vibes and less patience for your bad access patterns. Supports policies, roles, decorators, adapters, and rich evaluation context be

41 lines 1.61 kB
export class ConditionOperatorRegistry { operators = {}; register(name, op) { this.operators[name] = op; } get(name) { return this.operators[name]; } all() { return { ...this.operators }; } } export const defaultConditionOperators = { eq: (key, value, context) => context[key] === value, ne: (key, value, context) => context[key] !== value, gt: (key, value, context) => typeof context[key] === 'number' && typeof value === 'number' && context[key] > value, lt: (key, value, context) => typeof context[key] === 'number' && typeof value === 'number' && context[key] < value, gte: (key, value, context) => typeof context[key] === 'number' && typeof value === 'number' && context[key] >= value, lte: (key, value, context) => typeof context[key] === 'number' && typeof value === 'number' && context[key] <= value, in: (key, value, context) => Array.isArray(value) && value.includes(context[key]), contains: (key, value, context) => { const v = context[key]; if (typeof v === 'string') return v.includes(String(value)); if (Array.isArray(v)) return v.includes(value); return false; }, regex: (key, value, context) => { try { const re = typeof value === 'string' ? new RegExp(value) : value; if (!(re instanceof RegExp)) return false; return typeof context[key] === 'string' && re.test(context[key]); } catch { return false; } }, }; //# sourceMappingURL=evaluator.js.map