// Type definitions for node_acl 0.4.7 // Project: https://github.com/optimalbits/node_acl // Definitions by: Qubo // Definitions: https://github.com/borisyankov/DefinitelyTyped /// /// /// /// declare module "acl" { import http = require('http'); import Promise = require("bluebird"); type strings = string|string[]; type Value = string|number; type Values = Value|Value[]; type Action = () => any; type Callback = (err: Error) => any; type AnyCallback = (err: Error, obj: any) => any; type AllowedCallback = (err: Error, allowed: boolean) => any; type GetUserId = (req: http.ServerRequest, res: http.ServerResponse) => Value; interface AclStatic { new (backend: Backend, logger: Logger, options: Option): Acl; new (backend: Backend, logger: Logger): Acl; new (backend: Backend): Acl; memoryBackend: MemoryBackendStatic; } interface Logger { debug: (msg: string)=>any; } interface Acl { addUserRoles: (userId: Value, roles: strings, cb?: Callback) => Promise; removeUserRoles: (userId: Value, roles: strings, cb?: Callback) => Promise; userRoles: (userId: Value, cb?: (err: Error, roles: string[])=>any) => Promise; roleUsers: (role: Value, cb?: (err: Error, users: Values)=>any) => Promise; hasRole: (userId: Value, role: string, cb?: (err: Error, isInRole: boolean)=>any) => Promise; addRoleParents: (role: string, parents: Values, cb?: Callback) => Promise; removeRole: (role: string, cb?: Callback) => Promise; removeResource: (resource: string, cb?: Callback) => Promise; allow: { (roles: Values, resources: strings, permissions: strings, cb?: Callback): Promise; (aclSets: AclSet|AclSet[]): Promise; } removeAllow: (role: string, resources: strings, permissions: strings, cb?: Callback) => Promise; removePermissions: (role: string, resources: strings, permissions: strings, cb?: Function) => Promise; allowedPermissions: (userId: Value, resources: strings, cb?: AnyCallback) => Promise; isAllowed: (userId: Value, resources: strings, permissions: strings, cb?: AllowedCallback) => Promise; areAnyRolesAllowed: (roles: strings, resource: strings, permissions: strings, cb?: AllowedCallback) => Promise; whatResources: (roles: strings, permissions: strings, cb?: AnyCallback) => Promise; permittedResources: (roles: strings, permissions: strings, cb?: Function) => Promise; middleware: (numPathComponents: number, userId: Value|GetUserId, actions: strings) => Promise; } interface Option { buckets?: BucketsOption; } interface BucketsOption { meta?: string; parents?: string; permissions?: string; resources?: string; roles?: string; users?: string; } interface AclSet { roles: strings; allows: AclAllow[]; } interface AclAllow { resources: strings; permissions: strings; } interface MemoryBackend extends Backend { } interface MemoryBackendStatic { new(): MemoryBackend; } // // For internal use // interface Backend { begin: () => T; end: (transaction: T, cb?: Action) => void; clean: (cb?: Action) => void; get: (bucket: string, key: Value, cb?: Action) => void; union: (bucket: string, keys: Value[], cb?: Action) => void; add: (transaction: T, bucket: string, key: Value, values: Values) => void; del: (transaction: T, bucket: string, keys: Value[]) => void; remove: (transaction: T, bucket: string, key: Value, values: Values) => void; endAsync: Function; //TODO: Give more specific function signature getAsync: Function; cleanAsync: Function; unionAsync: Function; } interface Contract { (args: IArguments): Contract|NoOp; debug: boolean; fulfilled: boolean; args: any[]; checkedParams: string[]; params: (...types: string[]) => Contract|NoOp; end: () => void; } interface NoOp { params: (...types: string[]) => NoOp; end: () => void; } // for redis backend import redis = require('redis'); interface AclStatic { redisBackend: RedisBackendStatic; } interface RedisBackend extends Backend { } interface RedisBackendStatic { new(redis: redis.RedisClient, prefix: string): RedisBackend; new(redis: redis.RedisClient): RedisBackend; } // for mongodb backend import mongo = require('mongodb'); interface AclStatic { mongodbBackend: MongodbBackendStatic; } interface MongodbBackend extends Backend { } interface MongodbBackendStatic { new(db: mongo.Db, prefix: string, useSingle: boolean): MongodbBackend; new(db: mongo.Db, prefix: string): MongodbBackend; new(db: mongo.Db): MongodbBackend; } var _: AclStatic; export = _; }