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

33 lines 1.09 kB
import { defaultPolicyEvaluator, IAM, JSONFileAdapter } from '../index.js'; import { writeFileSync } from 'fs'; import { join } from 'path'; const data = { users: [ { id: 'u1', roleIds: ['r1'], policyIds: [] }, ], roles: [ { id: 'r1', name: 'reader', policyIds: ['p1'] }, ], policies: [ { id: 'p1', name: 'AllowRead', statements: [ { effect: 'Allow', actions: ['read'], resources: ['doc:1'] }, ], }, ], }; const jsonPath = join(__dirname, 'iam-data.json'); writeFileSync(jsonPath, JSON.stringify(data, null, 2)); const adapter = new JSONFileAdapter({ filePath: jsonPath, }); const iam = new IAM({ storage: adapter, evaluatorFunc: defaultPolicyEvaluator }); async function main() { const user = { id: 'u1', roleIds: ['r1'], policyIds: [] }; const result = await iam.can({ user, action: 'read', resource: 'doc:1' }); console.log('JSONFileAdapter: Decision:', result.decision); } main().catch(console.error); //# sourceMappingURL=json-adapter-example.js.map