@via-profit/ability 1.0.3 → 2.0.0-rc.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +155 -310
- package/assets/ability-01.drawio.png +0 -0
- package/build/playground.js +910 -0
- package/build/playground.js.map +1 -0
- package/dist/AbilityCode.d.ts +7 -0
- package/dist/AbilityCompare.d.ts +6 -0
- package/dist/AbilityCondition.d.ts +12 -0
- package/dist/AbilityError.d.ts +9 -0
- package/dist/AbilityMatch.d.ts +7 -0
- package/dist/AbilityParser.d.ts +33 -0
- package/dist/AbilityPolicy.d.ts +42 -50
- package/dist/AbilityPolicyEffect.d.ts +6 -0
- package/dist/AbilityPolicyResult.d.ts +6 -0
- package/dist/AbilityResolver.d.ts +30 -0
- package/dist/AbilityRule.d.ts +27 -94
- package/dist/AbilityRuleSet.d.ts +44 -0
- package/dist/index.d.ts +9 -3
- package/dist/index.js +631 -356
- package/dist/playground.d.ts +26 -0
- package/package.json +4 -2
- package/dist/AbilityService.d.ts +0 -74
- package/dist/AbilityStatement.d.ts +0 -98
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"playground.js","mappings":";;;;;;;;;;;;;AAAA,MAAa,WAAW;IACf,IAAI,CAAI;IAEf,YAAY,IAAO;QACjB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;IAEM,OAAO,CAAC,WAAkC;QAC/C,OAAO,WAAW,KAAK,IAAI,IAAI,IAAI,CAAC,IAAI,KAAK,WAAW,CAAC,IAAI,CAAC;IAChE,CAAC;IAEM,UAAU,CAAC,WAAkC;QAClD,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;IACpC,CAAC;CACF;AAdD,kCAcC;AAED,qBAAe,WAAW,CAAC;;;;;;;;;;;;;;;;;AChB3B,wGAAwC;AAExC,MAAa,cAAe,SAAQ,qBAAW;IACtC,MAAM,CAAC,EAAE,GAAG,IAAI,cAAc,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AAC,CACH,CAAC;IACF,GAAG,CAAC,GAAG,EAAE,CAAC;AACZ,CAAC,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,WAAW,EAAE,GAAG,EAAE;IACpC,OAAO,CAAC,KAAK,CAAC,yCAAyC,CAAC,CAAC;AAC3D,CAAC,CAAC,CAAC;;;;;;;;;;;ACpCH;;;;;;;;;;;;;;;;UCAA;UACA;;UAEA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;;UAEA;UACA;;UAEA;UACA;UACA;;;;UEtBA;UACA;UACA;UACA","sources":["webpack://@via-profit/ability/./src/AbilityCode.ts","webpack://@via-profit/ability/./src/AbilityCompare.ts","webpack://@via-profit/ability/./src/AbilityCondition.ts","webpack://@via-profit/ability/./src/AbilityError.ts","webpack://@via-profit/ability/./src/AbilityMatch.ts","webpack://@via-profit/ability/./src/AbilityParser.ts","webpack://@via-profit/ability/./src/AbilityPolicy.ts","webpack://@via-profit/ability/./src/AbilityPolicyEffect.ts","webpack://@via-profit/ability/./src/AbilityResolver.ts","webpack://@via-profit/ability/./src/AbilityRule.ts","webpack://@via-profit/ability/./src/AbilityRuleSet.ts","webpack://@via-profit/ability/./src/playground.ts","webpack://@via-profit/ability/external node-commonjs \"node:http\"","webpack://@via-profit/ability/webpack/bootstrap","webpack://@via-profit/ability/webpack/before-startup","webpack://@via-profit/ability/webpack/startup","webpack://@via-profit/ability/webpack/after-startup"],"sourcesContent":["export class AbilityCode<T extends string | number | undefined = number> {\n public code: T;\n\n constructor(code: T) {\n this.code = code;\n }\n\n public isEqual(compareWith: AbilityCode<T> | null): boolean {\n return compareWith !== null && this.code === compareWith.code;\n }\n\n public isNotEqual(compareWith: AbilityCode<T> | null): boolean {\n return !this.isEqual(compareWith);\n }\n}\n\nexport default AbilityCode;","import AbilityCode from './AbilityCode';\n\nexport class AbilityCompare extends AbilityCode {\n public static OR = new AbilityCompare(0);\n public static AND = new AbilityCompare(1);\n}\n\nexport default AbilityCompare;\n","import AbilityCode from './AbilityCode';\n\nexport class AbilityCondition extends AbilityCode<string> {\n public static EQUAL = new AbilityCondition('=');\n public static NOT_EQUAL = new AbilityCondition('<>');\n public static MORE_THAN = new AbilityCondition('>');\n public static LESS_THAN = new AbilityCondition('<');\n public static LESS_OR_EQUAL = new AbilityCondition('<=');\n public static MORE_OR_EQUAL = new AbilityCondition('>=');\n public static IN = new AbilityCondition('in');\n public static NOT_IN = new AbilityCondition('not in');\n}\n\nexport default AbilityCondition;\n","export class AbilityError extends Error {\n constructor(message: string) {\n super(message);\n }\n}\n\nexport class AbilityParserError extends Error {\n constructor(message: string) {\n super(message);\n }\n}\n\nexport class PermissionError extends Error {\n constructor(message: string) {\n super(message);\n }\n}\n","import AbilityCode from './AbilityCode';\n\nexport class AbilityMatch extends AbilityCode{\n public static PENDING = new AbilityMatch(2);\n public static MATCH = new AbilityMatch(1);\n public static MISMATCH = new AbilityMatch(0);\n}\n\nexport default AbilityMatch;","import { AbilityParserError } from './AbilityError';\nimport AbilityPolicy from './AbilityPolicy';\nimport AbilityCondition from './AbilityCondition';\n\ntype FieldValidateConfig = [string, 'string' | 'number' | 'array', boolean][];\n\n\nexport class AbilityParser {\n\n /**\n * Validates the configuration object based on the provided field validation configurations.\n * @param config - The configuration object to validate.\n * @param fields - An array of field validation configurations.\n * @throws {AbilityParserError} If a required field is missing or if a field has an incorrect type.\n */\n public static validateConfig(config: Record<string, any>, fields: FieldValidateConfig): void | never {\n fields.forEach(([field, type, isRequired]) => {\n const value = config[field as keyof typeof config];\n if (isRequired) {\n if (typeof value === 'undefined') {\n throw new AbilityParserError(`Missing required field [${field}]`);\n }\n }\n\n switch (type) {\n case 'array':\n if (typeof value !== 'object' || !Array.isArray(value)) {\n throw new AbilityParserError(`Field [${field}] must be an type of [${type}], bit got [${typeof value}]`);\n }\n break;\n\n default:\n if (typeof value !== type && typeof value !== 'undefined') {\n throw new AbilityParserError(`Field [${field}] must be a type of [${type}], bit got [${typeof value}]`);\n }\n break;\n }\n\n\n });\n }\n\n /**\n * Prepares and validates the configuration object or JSON string.\n * @param configOrJson - The configuration object or JSON string to validate.\n * @param fields - An array of field validation configurations.\n * @returns The validated configuration object.\n */\n public static prepareAndValidateConfig<T>(configOrJson: string | unknown, fields: FieldValidateConfig): T {\n const config = typeof configOrJson === 'string'\n ? (JSON.parse(configOrJson))\n : configOrJson;\n\n AbilityParser.validateConfig(config, fields);\n\n return config;\n }\n\n /*\n *\n * readonly ['order.update']: {\n * readonly user: {\n * readonly roles: readonly string[];\n * readonly department: string;\n * };\n * readonly order: {\n * readonly estimatedArrivalAt: number;\n * readonly status: string;\n * }\n * }\n *\n * */\n\n /**\n * Sets a value in a nested object structure based on a dot/bracket notation path.\n * @param object - The target object to modify.\n * @param path - The path to the property in dot/bracket notation.\n * @param value - The value to set at the specified path.\n */\n public static setValueDotValue(\n object: Record<string, any>,\n path: string,\n value: string | number | boolean\n ): void {\n const way = path.replace(/\\[/g, '.').replace(/\\]/g, '').split('.');\n const last = way.pop();\n\n if (!last) {\n throw new AbilityParserError(`Invalid path provided on a [${path}]`);\n }\n\n way.reduce((o, k, i, kk) => {\n if (!o[k]) {\n o[k] = isFinite(Number(kk[i + 1])) ? [] : {};\n }\n return o[k];\n }, object)[last] = value;\n }\n\n /**\n * Generates TypeScript type definitions based on the provided policies.\n * @param policies - An array of AbilityPolicy instances.\n * @param outPath - The output path for the generated type definitions.\n * @returns A record containing the generated type definitions.\n */\n public static generateTypeDefs(policies: readonly AbilityPolicy[], outPath: string) {\n const record: Record<string, any> = {};\n\n policies.forEach(policy => {\n policy.ruleSet.forEach(ruleSet => {\n ruleSet.rules.forEach(rule => {\n const [leftFieldPath, condition, rightFiledPath] = rule.matches;\n let value: string = 'any';\n\n switch (true) {\n case condition.isEqual(AbilityCondition.NOT_EQUAL):\n case condition.isEqual(AbilityCondition.EQUAL):\n value = typeof rightFiledPath;\n break;\n\n case condition.isEqual(AbilityCondition.IN):\n case condition.isEqual(AbilityCondition.NOT_IN):\n value = `${typeof rightFiledPath}[]`;\n break;\n\n case condition.isEqual(AbilityCondition.MORE_OR_EQUAL):\n case condition.isEqual(AbilityCondition.MORE_THAN):\n case condition.isEqual(AbilityCondition.LESS_OR_EQUAL):\n case condition.isEqual(AbilityCondition.LESS_THAN):\n value = 'number';\n break;\n }\n AbilityParser.setValueDotValue(record, leftFieldPath, value);\n });\n });\n });\n\n console.log(JSON.stringify(record));\n\n return record;\n }\n\n}\n\nexport default AbilityParser;","import AbilityRule, { AbilityRuleConfig } from './AbilityRule';\nimport AbilityRuleSet, { AbilityRuleSetConfig } from './AbilityRuleSet';\nimport AbilityMatch from './AbilityMatch';\nimport AbilityCompare from './AbilityCompare';\nimport AbilityPolicyEffect from './AbilityPolicyEffect';\nimport AbilityParser from './AbilityParser';\n\nexport type AbilityPolicyConfig = {\n readonly action: string;\n readonly effect: number;\n readonly compareMethod: number;\n readonly ruleSet: (AbilityRuleConfig | AbilityRuleSetConfig)[];\n readonly id?: string;\n readonly name?: string;\n};\n\nexport class AbilityPolicy<Resources extends object = object> {\n public matchState: AbilityMatch = AbilityMatch.PENDING;\n /**\n * List of rules\n */\n public ruleSet: AbilityRuleSet[] = [];\n\n /**\n * Policy effect\n */\n public effect: AbilityPolicyEffect;\n\n /**\n * Rules compare method.\\\n * For the «and» method the rule will be permitted if all\\\n * rules will be returns «permit» status and for the «or» - if\\\n * one of the rules returns as «permit»\n */\n public compareMethod: AbilityCompare = AbilityCompare.AND;\n\n /**\n * Policy name\n */\n public name: string | symbol;\n\n /**\n * Policy ID\n */\n public id: string | symbol;\n\n /**\n * Soon\n */\n public action: string;\n\n public constructor(params: {\n action: string;\n effect: AbilityPolicyEffect;\n name?: string | symbol;\n id?: string | symbol;\n }) {\n const { name, id, action, effect } = params;\n this.name = name || Symbol('name');\n this.id = id || Symbol('id');\n this.action = action;\n this.effect = effect;\n }\n\n\n /**\n * Add rule set to the policy\n * @param ruleSet - The rule set to add\n */\n public addRuleSet(ruleSet: AbilityRuleSet): this {\n this.ruleSet.push(ruleSet);\n\n return this;\n }\n\n /**\n * Add rule to the policy\n * @param rule - The rule to add\n */\n public addRule(rule: AbilityRule<Resources>): this {\n this.addRuleSet(\n new AbilityRuleSet({\n name: rule.name,\n }).addRule(rule, AbilityCompare.AND),\n );\n\n return this;\n }\n\n\n /**\n * Check if the policy is matched\n * @param resource - The resource to check\n */\n public check(resource: Resources): AbilityMatch {\n this.matchState = AbilityMatch.MISMATCH;\n\n /**\n * If policy contain a rules\n */\n if (this.ruleSet.length) {\n const ruleCheckStates: AbilityMatch[] = [];\n this.ruleSet.forEach(rule => {\n const ruleCheckState = rule.check(resource);\n ruleCheckStates.push(ruleCheckState);\n });\n\n if (AbilityCompare.AND.isEqual(this.compareMethod)) {\n if (ruleCheckStates.every(ruleState => AbilityMatch.MATCH.isEqual(ruleState))) {\n this.matchState = AbilityMatch.MATCH;\n }\n }\n\n if (AbilityCompare.OR.isEqual(this.compareMethod)) {\n if (ruleCheckStates.some(ruleState => AbilityMatch.MATCH.isEqual(ruleState))) {\n this.matchState = AbilityMatch.MATCH;\n }\n }\n }\n\n return this.matchState;\n }\n\n\n\n\n /**\n * Parse the config JSON format to Policy class instance\n */\n public static parse<Resources extends object = object>(\n configOrJson: AbilityPolicyConfig | string,\n ): AbilityPolicy<Resources> {\n\n\n const config = AbilityParser.prepareAndValidateConfig<AbilityPolicyConfig>(configOrJson, [\n ['id', 'string', false],\n ['name', 'string', true],\n ['action', 'string', true],\n ['effect', 'number', true],\n ['compareMethod', 'number', true],\n ['ruleSet', 'array', true],\n ]);\n\n const { id, name, ruleSet, compareMethod, action, effect } = config;\n\n // Create the empty policy\n const policy = new AbilityPolicy<Resources>({\n name,\n id,\n action,\n effect: new AbilityPolicyEffect(effect),\n });\n\n policy.compareMethod = new AbilityCompare(compareMethod);\n\n ruleSet.forEach(ruleOrRuleSet => {\n // is ruleset\n if ('rules' in ruleOrRuleSet) {\n policy.addRuleSet(AbilityRuleSet.parse(ruleOrRuleSet));\n }\n\n // is simple rule\n if (!('rules' in ruleOrRuleSet)) {\n policy.addRule(AbilityRule.parse(ruleOrRuleSet));\n }\n });\n\n return policy;\n }\n\n public export(): AbilityPolicyConfig {\n return {\n id: this.id.toString(),\n name: this.name.toString(),\n compareMethod: this.compareMethod.code,\n ruleSet: this.ruleSet.map(rule => rule.export()),\n action: this.action,\n effect: this.effect.code,\n };\n }\n}\n\nexport default AbilityPolicy;\n","import AbilityCode from './AbilityCode';\n\nexport class AbilityPolicyEffect extends AbilityCode{\n public static DENY = new AbilityPolicyEffect(0);\n public static PERMIT = new AbilityPolicyEffect(1);\n}\n\nexport default AbilityPolicyEffect;","import AbilityPolicy from './AbilityPolicy';\nimport AbilityPolicyEffect from './AbilityPolicyEffect';\nimport AbilityMatch from './AbilityMatch';\nimport { PermissionError } from './AbilityError';\n\nexport class AbilityResolver<Resources extends object = object> {\n policies: readonly AbilityPolicy<Resources>[];\n\n public constructor(policies: readonly AbilityPolicy<Resources>[]) {\n this.policies = policies;\n }\n\n /**\n * Resolve policy for the resource and action\n *\n @param action - Action\n * @param resource - Resource\n */\n public resolve<Action extends keyof Resources>(\n action: Action,\n resource: Resources[Action],\n ): this {\n const filteredPolicies: AbilityPolicy[] = this.policies.filter(policy => {\n return AbilityResolver.isInActionContain(policy.action, String(action));\n });\n\n filteredPolicies.map(policy => policy.check(resource as object));\n\n this.policies = filteredPolicies;\n\n return this;\n }\n\n public enforce<Action extends keyof Resources>(\n action: Action,\n resource: Resources[Action],\n ): void | never {\n const resolver = this.resolve(action, resource);\n if (resolver) {\n if (resolver.isDeny()) {\n throw new PermissionError(\n ['Permission denied', resolver.getPolicy()?.name?.toString()].join('. '),\n );\n }\n }\n }\n\n /**\n * Get the last effect of the policy\n *\n * @returns {AbilityPolicyEffect | null}\n */\n public getEffect(): AbilityPolicyEffect | null {\n const effects = this.policies.reduce<AbilityPolicyEffect[]>((collect, policy, _index) => {\n if (policy.matchState.isEqual(AbilityMatch.MATCH)) {\n return collect.concat(policy.effect);\n }\n return collect;\n }, []);\n\n if (effects.length) {\n return effects[effects.length - 1];\n }\n\n return null;\n }\n\n public isPermit() {\n const effect = this.getEffect();\n\n return effect !== null && effect.isEqual(AbilityPolicyEffect.PERMIT);\n }\n\n public isDeny() {\n const effect = this.getEffect();\n\n return effect !== null && effect.isEqual(AbilityPolicyEffect.DENY);\n }\n\n public getPolicy(): AbilityPolicy<Resources> | null {\n const lastPolicy = this.policies.length ? this.policies[this.policies.length - 1] : null;\n\n return lastPolicy && lastPolicy.matchState.isEqual(AbilityMatch.MATCH) ? lastPolicy : null;\n }\n\n /**\n * Check if the action is contained in another action\n * @param actionA - The first action to check\n * @param actionB - The second action to check\n */\n public static isInActionContain(actionA: string, actionB: string) {\n const actionAArray = String(actionA).split('.');\n const actionBArray = String(actionB).split('.');\n\n const a = actionAArray.length >= actionBArray.length ? actionAArray : actionBArray;\n const b = actionBArray.length >= actionAArray.length ? actionBArray : actionAArray;\n\n return a\n .reduce<boolean[]>((acc, chunk, index) => {\n const iterationRes = chunk === b[index] || b[index] === '*' || chunk === '*';\n\n return acc.concat(iterationRes);\n }, [])\n .every(Boolean);\n }\n}\n\nexport default AbilityResolver;\n","import AbilityMatch from './AbilityMatch';\nimport AbilityCondition from './AbilityCondition';\nimport AbilityParser from './AbilityParser';\n\nexport type AbilityRuleMatches = [string, AbilityCondition, string | number | boolean];\n\nexport type AbilityRuleConfig = {\n readonly name?: string | symbol;\n readonly matches: [string, string, string | number | boolean];\n};\n\nexport class AbilityRule<Resources extends object = object> {\n public matches: AbilityRuleMatches;\n public name: string | symbol;\n public state: AbilityMatch = AbilityMatch.PENDING;\n\n public constructor(params: { matches: AbilityRuleMatches; name?: string | symbol }) {\n const { name, matches } = params;\n this.name = name || Symbol('name');\n this.matches = matches;\n }\n\n /**\n * Check if the rule is matched\n * @param resource - The resource to check\n */\n public check(resource: Resources | null): AbilityMatch {\n const [_subjectPathName, condition, _staticValueOrPathName] = this.matches;\n\n let is: boolean = false;\n\n const [valueS, valueO] = this.extractValues(resource);\n\n if (AbilityCondition.LESS_THAN.isEqual(condition)) {\n is = Number(valueS) < Number(valueO);\n }\n\n if (AbilityCondition.LESS_OR_EQUAL.isEqual(condition)) {\n is = Number(valueS) <= Number(valueO);\n }\n\n if (AbilityCondition.MORE_THAN.isEqual(condition)) {\n is = Number(valueS) > Number(valueO);\n }\n\n if (AbilityCondition.MORE_OR_EQUAL.isEqual(condition)) {\n is = Number(valueS) >= Number(valueO);\n }\n\n if (AbilityCondition.EQUAL.isEqual(condition)) {\n is = valueS === valueO;\n }\n\n if (AbilityCondition.NOT_EQUAL.isEqual(condition)) {\n is = valueS !== valueO;\n }\n\n if (AbilityCondition.IN.isEqual(condition)) {\n // [<some>] and [<some>]\n if (Array.isArray(valueS) && Array.isArray(valueO)) {\n is = valueS.some(v => valueO.find(v1 => v1 === v));\n }\n // <some> and [<some>]\n if ((typeof valueS === 'string' || typeof valueS === 'number') && Array.isArray(valueO)) {\n is = valueO.includes(valueS);\n }\n // [<some>] and <some>\n if ((typeof valueO === 'string' || typeof valueO === 'number') && Array.isArray(valueS)) {\n is = valueS.includes(valueO);\n }\n }\n\n if (AbilityCondition.NOT_IN.isEqual(condition)) {\n // [<some>] and [<some>]\n if (Array.isArray(valueS) && Array.isArray(valueO)) {\n is = !valueS.some(v => valueO.find(v1 => v1 === v));\n }\n // <some> and [<some>]\n if ((typeof valueS === 'string' || typeof valueS === 'number') && Array.isArray(valueO)) {\n is = !valueO.includes(valueS);\n }\n // [<some>] and <some>\n if ((typeof valueO === 'string' || typeof valueO === 'number') && Array.isArray(valueS)) {\n is = !valueS.includes(valueO);\n }\n }\n\n this.state = is ? AbilityMatch.MATCH : AbilityMatch.MISMATCH;\n\n return this.state;\n }\n\n /**\n * Extract values from the resource\n * @param resource - The resource to extract values from\n */\n public extractValues(\n resource: Resources | null,\n ): [\n string | number | boolean | (string | number)[] | null | undefined,\n string | number | boolean | (string | number)[] | null | undefined,\n ] {\n const [subjectPathName, _condition, staticValueOrPathName] = this.matches;\n let leftSideValue;\n let rightSideValue;\n\n if (resource === null || typeof resource === 'undefined') {\n return [NaN, NaN];\n }\n\n const isPath = (str: unknown): str is string => {\n return typeof str === 'string' && str.match(/\\./g) !== null;\n };\n\n if (isPath(subjectPathName)) {\n leftSideValue = this.getDotNotationValue<number | boolean | string | (string | number)[]>(\n resource,\n subjectPathName,\n );\n }\n if (isPath(staticValueOrPathName)) {\n rightSideValue = this.getDotNotationValue<number | boolean | string | (string | number)[]>(\n resource,\n staticValueOrPathName,\n );\n } else {\n rightSideValue = staticValueOrPathName as number | boolean | string | (string | number)[];\n }\n\n return [leftSideValue, rightSideValue];\n }\n\n /**\n * Get the value of the object by dot notation\n * @param resource - The object to get the value from\n * @param desc - The dot notation string\n */\n public getDotNotationValue<T = unknown>(resource: unknown, desc: string): T | undefined {\n const arr = desc.split('.');\n\n while (arr.length && resource) {\n const comp = arr.shift() || '';\n const match = new RegExp('(.+)\\\\[([0-9]*)\\\\]').exec(comp);\n\n if (match !== null && match.length == 3) {\n const arrayData = {\n arrName: match[1],\n arrIndex: match[2],\n };\n\n if (resource[arrayData.arrName as keyof typeof resource] !== undefined) {\n resource = resource[arrayData.arrName as keyof typeof resource][arrayData.arrIndex];\n } else {\n resource = undefined;\n }\n } else {\n resource = resource[comp as keyof typeof resource];\n }\n }\n\n return resource as T;\n }\n\n public static parse<Resources extends object>(\n configOrJson: AbilityRuleConfig | string,\n ): AbilityRule<Resources> {\n const config = AbilityParser.prepareAndValidateConfig<AbilityRuleConfig>(configOrJson, [\n ['id', 'string', false],\n ['name', 'string', true],\n ['matches', 'array', true],\n ]);\n\n const { name, matches } = config;\n const [leftField, condition, rightField] = matches;\n\n return new AbilityRule<Resources>({\n name,\n matches: [leftField, new AbilityCondition(condition), rightField],\n });\n }\n\n /**\n * Export the rule to config object\n */\n public export(): AbilityRuleConfig {\n const [leftField, condition, rightField] = this.matches;\n\n return {\n name: this.name,\n matches: [leftField, condition.code, rightField],\n };\n }\n}\n\nexport default AbilityRule;\n","import AbilityRule, { AbilityRuleConfig } from './AbilityRule';\nimport AbilityCompare from './AbilityCompare';\nimport AbilityMatch from './AbilityMatch';\nimport AbilityParser from './AbilityParser';\n\nexport type AbilityRuleSetConfig = {\n readonly id?: string | symbol;\n readonly name: string;\n readonly compareMethod: number;\n readonly rules: AbilityRuleConfig[];\n};\n\nexport class AbilityRuleSet<Resources extends object = object> {\n public state: AbilityMatch = AbilityMatch.PENDING;\n /**\n * List of rules\n */\n public rules: AbilityRule[] = [];\n\n /**\n * Rules compare method.\\\n * For the «and» method the rule will be permitted if all\\\n * rules will be returns «permit» status and for the «or» - if\\\n * one of the rules returns as «permit»\n */\n public compareMethod: AbilityCompare = AbilityCompare.AND;\n\n /**\n * Group name\n */\n public name: string | symbol;\n\n /**\n * Group ID\n */\n public id: string | symbol;\n\n public constructor(params?: { name?: string | symbol; id?: string | symbol }) {\n const { name, id } = params || {};\n\n this.name = name || Symbol('name');\n this.id = id || Symbol('id');\n }\n\n public addRule(rule: AbilityRule, compareMethod: AbilityCompare): this {\n this.rules.push(rule);\n this.compareMethod = compareMethod;\n\n return this;\n }\n\n public addRules(rules: AbilityRule[], compareMethod: AbilityCompare): this {\n rules.forEach(rule => this.addRule(rule, compareMethod));\n\n return this;\n }\n\n public check(resources: Resources | null): AbilityMatch {\n this.state = AbilityMatch.MISMATCH;\n\n if (!this.rules.length) {\n return this.state;\n }\n\n const ruleCheckStates = this.rules.reduce<AbilityMatch[]>((collect, rule) => {\n return collect.concat(rule.check(resources));\n }, []);\n\n if (AbilityCompare.AND.isEqual(this.compareMethod)) {\n if (ruleCheckStates.every(ruleState => AbilityMatch.MATCH.isEqual(ruleState))) {\n this.state = AbilityMatch.MATCH;\n }\n }\n\n if (AbilityCompare.OR.isEqual(this.compareMethod)) {\n if (ruleCheckStates.some(ruleState => AbilityMatch.MATCH.isEqual(ruleState))) {\n this.state = AbilityMatch.MATCH;\n }\n }\n\n return this.state;\n }\n\n\n /**\n * Parse the config JSON format to Group class instance\n */\n public static parse<Resource extends object = object>(\n configOrJson: AbilityRuleSetConfig | string,\n ): AbilityRuleSet<Resource> {\n\n const config = AbilityParser.prepareAndValidateConfig<AbilityRuleSetConfig>(configOrJson, [\n ['id', 'string', false],\n ['name', 'string', true],\n ['compareMethod', 'number', true],\n ['rules', 'array', true],\n ]);\n\n const { id, name, rules, compareMethod } = config;\n\n const ruleSet = new AbilityRuleSet<Resource>({\n name,\n id,\n });\n\n ruleSet.compareMethod = new AbilityCompare(compareMethod);\n\n // Adding rules if exists\n if (rules && rules.length > 0) {\n const abilityRules = rules.map(ruleConfig => AbilityRule.parse(ruleConfig));\n\n ruleSet.addRules(abilityRules, ruleSet.compareMethod);\n }\n\n return ruleSet;\n }\n\n public export(): AbilityRuleSetConfig {\n return {\n id: this.id.toString(),\n name: this.name.toString(),\n compareMethod: this.compareMethod.code,\n rules: this.rules.map(rule => rule.export()),\n };\n }\n}\n\nexport default AbilityRuleSet;\n","import http from 'node:http';\nimport AbilityPolicy, { AbilityPolicyConfig } from './AbilityPolicy';\nimport AbilityResolver from '~/AbilityResolver';\n\nimport policies from './policies.json';\n\nconst server = http.createServer();\n\nserver.on('request', (_req, res) => {\n new AbilityResolver<Resources>(\n policies.map(p => {\n return AbilityPolicy.parse(p as AbilityPolicyConfig);\n }),\n ).enforce('account.read', {\n account: {\n id: '1',\n roles: ['managers'],\n },\n resource: {\n id: '1',\n },\n });\n\n res.statusCode = 200;\n res.setHeader('content-type', 'application/json');\n\n res.write(\n JSON.stringify({\n status: 'Done',\n }),\n );\n res.end();\n});\n\nserver.listen(8080, 'localhost', () => {\n console.debug('server started at http://localhost:8080');\n});\n\nexport type Resources = {\n readonly ['account.read']: {\n readonly account: {\n readonly id: string;\n readonly roles: readonly string[];\n };\n readonly resource: {\n readonly id: string;\n };\n };\n readonly ['access.auth']: {\n readonly token: {\n readonly type: string;\n readonly id: string;\n };\n };\n readonly ['order.update']: {\n readonly account: {\n readonly roles: readonly string[];\n readonly department: string;\n };\n readonly order: {\n readonly status: string;\n };\n };\n};\n","module.exports = require(\"node:http\");","// The module cache\nvar __webpack_module_cache__ = {};\n\n// The require function\nfunction __webpack_require__(moduleId) {\n\t// Check if module is in cache\n\tvar cachedModule = __webpack_module_cache__[moduleId];\n\tif (cachedModule !== undefined) {\n\t\treturn cachedModule.exports;\n\t}\n\t// Create a new module (and put it into the cache)\n\tvar module = __webpack_module_cache__[moduleId] = {\n\t\t// no module.id needed\n\t\t// no module.loaded needed\n\t\texports: {}\n\t};\n\n\t// Execute the module function\n\t__webpack_modules__[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n\t// Return the exports of the module\n\treturn module.exports;\n}\n\n","","// startup\n// Load entry module and return exports\n// This entry module is referenced by other modules so it can't be inlined\nvar __webpack_exports__ = __webpack_require__(\"./src/playground.ts\");\n",""],"names":[],"sourceRoot":""}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import AbilityCode from './AbilityCode';
|
|
2
|
+
export declare class AbilityCondition extends AbilityCode<string> {
|
|
3
|
+
static EQUAL: AbilityCondition;
|
|
4
|
+
static NOT_EQUAL: AbilityCondition;
|
|
5
|
+
static MORE_THAN: AbilityCondition;
|
|
6
|
+
static LESS_THAN: AbilityCondition;
|
|
7
|
+
static LESS_OR_EQUAL: AbilityCondition;
|
|
8
|
+
static MORE_OR_EQUAL: AbilityCondition;
|
|
9
|
+
static IN: AbilityCondition;
|
|
10
|
+
static NOT_IN: AbilityCondition;
|
|
11
|
+
}
|
|
12
|
+
export default AbilityCondition;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare class AbilityError extends Error {
|
|
2
|
+
constructor(message: string);
|
|
3
|
+
}
|
|
4
|
+
export declare class AbilityParserError extends Error {
|
|
5
|
+
constructor(message: string);
|
|
6
|
+
}
|
|
7
|
+
export declare class PermissionError extends Error {
|
|
8
|
+
constructor(message: string);
|
|
9
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import AbilityPolicy from './AbilityPolicy';
|
|
2
|
+
type FieldValidateConfig = [string, 'string' | 'number' | 'array', boolean][];
|
|
3
|
+
export declare class AbilityParser {
|
|
4
|
+
/**
|
|
5
|
+
* Validates the configuration object based on the provided field validation configurations.
|
|
6
|
+
* @param config - The configuration object to validate.
|
|
7
|
+
* @param fields - An array of field validation configurations.
|
|
8
|
+
* @throws {AbilityParserError} If a required field is missing or if a field has an incorrect type.
|
|
9
|
+
*/
|
|
10
|
+
static validateConfig(config: Record<string, any>, fields: FieldValidateConfig): void | never;
|
|
11
|
+
/**
|
|
12
|
+
* Prepares and validates the configuration object or JSON string.
|
|
13
|
+
* @param configOrJson - The configuration object or JSON string to validate.
|
|
14
|
+
* @param fields - An array of field validation configurations.
|
|
15
|
+
* @returns The validated configuration object.
|
|
16
|
+
*/
|
|
17
|
+
static prepareAndValidateConfig<T>(configOrJson: string | unknown, fields: FieldValidateConfig): T;
|
|
18
|
+
/**
|
|
19
|
+
* Sets a value in a nested object structure based on a dot/bracket notation path.
|
|
20
|
+
* @param object - The target object to modify.
|
|
21
|
+
* @param path - The path to the property in dot/bracket notation.
|
|
22
|
+
* @param value - The value to set at the specified path.
|
|
23
|
+
*/
|
|
24
|
+
static setValueDotValue(object: Record<string, any>, path: string, value: string | number | boolean): void;
|
|
25
|
+
/**
|
|
26
|
+
* Generates TypeScript type definitions based on the provided policies.
|
|
27
|
+
* @param policies - An array of AbilityPolicy instances.
|
|
28
|
+
* @param outPath - The output path for the generated type definitions.
|
|
29
|
+
* @returns A record containing the generated type definitions.
|
|
30
|
+
*/
|
|
31
|
+
static generateTypeDefs(policies: readonly AbilityPolicy[], outPath: string): Record<string, any>;
|
|
32
|
+
}
|
|
33
|
+
export default AbilityParser;
|
package/dist/AbilityPolicy.d.ts
CHANGED
|
@@ -1,78 +1,70 @@
|
|
|
1
|
-
import AbilityRule, {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
* one of the entities returns as «permit»
|
|
7
|
-
*/
|
|
8
|
-
export type AbilityCompareMethod = 'or' | 'and';
|
|
9
|
-
export type AbilityPolicyResult = {
|
|
10
|
-
readonly permission: AbilityRuleStatus;
|
|
11
|
-
readonly deniedRules: readonly AbilityRule[];
|
|
12
|
-
readonly deniedPolicies: readonly AbilityPolicy[];
|
|
13
|
-
};
|
|
1
|
+
import AbilityRule, { AbilityRuleConfig } from './AbilityRule';
|
|
2
|
+
import AbilityRuleSet, { AbilityRuleSetConfig } from './AbilityRuleSet';
|
|
3
|
+
import AbilityMatch from './AbilityMatch';
|
|
4
|
+
import AbilityCompare from './AbilityCompare';
|
|
5
|
+
import AbilityPolicyEffect from './AbilityPolicyEffect';
|
|
14
6
|
export type AbilityPolicyConfig = {
|
|
7
|
+
readonly action: string;
|
|
8
|
+
readonly effect: number;
|
|
9
|
+
readonly compareMethod: number;
|
|
10
|
+
readonly ruleSet: (AbilityRuleConfig | AbilityRuleSetConfig)[];
|
|
15
11
|
readonly id?: string;
|
|
16
12
|
readonly name?: string;
|
|
17
|
-
readonly description?: string;
|
|
18
|
-
readonly rulesCompareMethod?: AbilityCompareMethod;
|
|
19
|
-
readonly policiesCompareMethod?: AbilityCompareMethod;
|
|
20
|
-
readonly rules?: AbilityRuleConfig[] | null;
|
|
21
|
-
readonly policies?: AbilityPolicyConfig[] | null;
|
|
22
13
|
};
|
|
23
|
-
export declare class AbilityPolicy<
|
|
14
|
+
export declare class AbilityPolicy<Resources extends object = object> {
|
|
15
|
+
matchState: AbilityMatch;
|
|
24
16
|
/**
|
|
25
17
|
* List of rules
|
|
26
18
|
*/
|
|
27
|
-
|
|
19
|
+
ruleSet: AbilityRuleSet[];
|
|
28
20
|
/**
|
|
29
|
-
*
|
|
21
|
+
* Policy effect
|
|
30
22
|
*/
|
|
31
|
-
|
|
23
|
+
effect: AbilityPolicyEffect;
|
|
32
24
|
/**
|
|
33
25
|
* Rules compare method.\
|
|
34
26
|
* For the «and» method the rule will be permitted if all\
|
|
35
27
|
* rules will be returns «permit» status and for the «or» - if\
|
|
36
28
|
* one of the rules returns as «permit»
|
|
37
29
|
*/
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Policies compare method.\
|
|
41
|
-
* For the «and» method the policy will be permitted if all\
|
|
42
|
-
* policies will be returns «permit» status and for the «or» - if\
|
|
43
|
-
* one of the policies returns as «permit»
|
|
44
|
-
*/
|
|
45
|
-
policiesCompareMethod: AbilityCompareMethod;
|
|
30
|
+
compareMethod: AbilityCompare;
|
|
46
31
|
/**
|
|
47
32
|
* Policy name
|
|
48
33
|
*/
|
|
49
34
|
name: string | symbol;
|
|
50
|
-
/**
|
|
51
|
-
* Policy description
|
|
52
|
-
*/
|
|
53
|
-
description: string | null;
|
|
54
35
|
/**
|
|
55
36
|
* Policy ID
|
|
56
37
|
*/
|
|
57
38
|
id: string | symbol;
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
39
|
+
/**
|
|
40
|
+
* Soon
|
|
41
|
+
*/
|
|
42
|
+
action: string;
|
|
43
|
+
constructor(params: {
|
|
44
|
+
action: string;
|
|
45
|
+
effect: AbilityPolicyEffect;
|
|
46
|
+
name?: string | symbol;
|
|
47
|
+
id?: string | symbol;
|
|
48
|
+
});
|
|
49
|
+
/**
|
|
50
|
+
* Add rule set to the policy
|
|
51
|
+
* @param ruleSet - The rule set to add
|
|
52
|
+
*/
|
|
53
|
+
addRuleSet(ruleSet: AbilityRuleSet): this;
|
|
54
|
+
/**
|
|
55
|
+
* Add rule to the policy
|
|
56
|
+
* @param rule - The rule to add
|
|
57
|
+
*/
|
|
58
|
+
addRule(rule: AbilityRule<Resources>): this;
|
|
59
|
+
/**
|
|
60
|
+
* Check if the policy is matched
|
|
61
|
+
* @param resource - The resource to check
|
|
62
|
+
*/
|
|
63
|
+
check(resource: Resources): AbilityMatch;
|
|
72
64
|
/**
|
|
73
65
|
* Parse the config JSON format to Policy class instance
|
|
74
66
|
*/
|
|
75
|
-
static parse<
|
|
76
|
-
|
|
67
|
+
static parse<Resources extends object = object>(configOrJson: AbilityPolicyConfig | string): AbilityPolicy<Resources>;
|
|
68
|
+
export(): AbilityPolicyConfig;
|
|
77
69
|
}
|
|
78
70
|
export default AbilityPolicy;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import AbilityPolicy from './AbilityPolicy';
|
|
2
|
+
import AbilityPolicyEffect from './AbilityPolicyEffect';
|
|
3
|
+
export declare class AbilityResolver<Resources extends object = object> {
|
|
4
|
+
policies: readonly AbilityPolicy<Resources>[];
|
|
5
|
+
constructor(policies: readonly AbilityPolicy<Resources>[]);
|
|
6
|
+
/**
|
|
7
|
+
* Resolve policy for the resource and action
|
|
8
|
+
*
|
|
9
|
+
@param action - Action
|
|
10
|
+
* @param resource - Resource
|
|
11
|
+
*/
|
|
12
|
+
resolve<Action extends keyof Resources>(action: Action, resource: Resources[Action]): this;
|
|
13
|
+
enforce<Action extends keyof Resources>(action: Action, resource: Resources[Action]): void | never;
|
|
14
|
+
/**
|
|
15
|
+
* Get the last effect of the policy
|
|
16
|
+
*
|
|
17
|
+
* @returns {AbilityPolicyEffect | null}
|
|
18
|
+
*/
|
|
19
|
+
getEffect(): AbilityPolicyEffect | null;
|
|
20
|
+
isPermit(): boolean;
|
|
21
|
+
isDeny(): boolean;
|
|
22
|
+
getPolicy(): AbilityPolicy<Resources> | null;
|
|
23
|
+
/**
|
|
24
|
+
* Check if the action is contained in another action
|
|
25
|
+
* @param actionA - The first action to check
|
|
26
|
+
* @param actionB - The second action to check
|
|
27
|
+
*/
|
|
28
|
+
static isInActionContain(actionA: string, actionB: string): boolean;
|
|
29
|
+
}
|
|
30
|
+
export default AbilityResolver;
|
package/dist/AbilityRule.d.ts
CHANGED
|
@@ -1,108 +1,41 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export type AbilityRuleMatches = [
|
|
4
|
-
`${SubjectPrefix}${string}`,
|
|
5
|
-
AbilityCondition,
|
|
6
|
-
string | number | boolean
|
|
7
|
-
];
|
|
8
|
-
export type AbilityCondition = '=' | '<>' | '>' | '<' | '<=' | '>=' | 'in';
|
|
1
|
+
import AbilityMatch from './AbilityMatch';
|
|
2
|
+
import AbilityCondition from './AbilityCondition';
|
|
3
|
+
export type AbilityRuleMatches = [string, AbilityCondition, string | number | boolean];
|
|
9
4
|
export type AbilityRuleConfig = {
|
|
10
5
|
readonly name?: string | symbol;
|
|
11
|
-
readonly
|
|
12
|
-
readonly matches: AbilityRuleMatches;
|
|
6
|
+
readonly matches: [string, string, string | number | boolean];
|
|
13
7
|
};
|
|
14
|
-
export declare class AbilityRule<
|
|
8
|
+
export declare class AbilityRule<Resources extends object = object> {
|
|
15
9
|
matches: AbilityRuleMatches;
|
|
16
10
|
name: string | symbol;
|
|
17
|
-
|
|
11
|
+
state: AbilityMatch;
|
|
12
|
+
constructor(params: {
|
|
13
|
+
matches: AbilityRuleMatches;
|
|
14
|
+
name?: string | symbol;
|
|
15
|
+
});
|
|
18
16
|
/**
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
* @param ruleName {string} - The rule name
|
|
22
|
-
* @param effect {AbilityRuleStatus} - Return value
|
|
23
|
-
* @param matches {AbilityRuleMatches} - The matching rule he matching rule can be on of the format:
|
|
24
|
-
* \
|
|
25
|
-
* For example, be compared two's data\
|
|
26
|
-
* \
|
|
27
|
-
* _The subject_
|
|
28
|
-
* ```json
|
|
29
|
-
* {"userID": "1", "userDepartament": "NBC"}
|
|
30
|
-
* ```
|
|
31
|
-
* and _The resource_
|
|
32
|
-
* ```json
|
|
33
|
-
* {"departamentID": "154", "departamentName": "NBC"}
|
|
34
|
-
* ```
|
|
35
|
-
* \
|
|
36
|
-
* Now we can make the matching rule:
|
|
37
|
-
* ```json
|
|
38
|
-
* ["subject.userDepartament", "=", "resource.departamentName"]
|
|
39
|
-
* ```
|
|
40
|
-
*
|
|
41
|
-
* \
|
|
42
|
-
* **Example 2.**\
|
|
43
|
-
* In this case will be compared resource and string:
|
|
44
|
-
* \
|
|
45
|
-
* _The subject_
|
|
46
|
-
* ```json
|
|
47
|
-
* {"userID": "1", "userDepartament": "NBC"}
|
|
48
|
-
* ```
|
|
49
|
-
* and _The resource_ will be «undefined».\
|
|
50
|
-
* Now we can make the matching rule:
|
|
51
|
-
* ```json
|
|
52
|
-
* ["subject.userDepartament", "=", "NBC"]
|
|
53
|
-
* ```
|
|
54
|
-
* \
|
|
55
|
-
* **Example 3.**\
|
|
56
|
-
* In this case will be compared resource and array of string:\
|
|
57
|
-
* \
|
|
58
|
-
* _The subject_
|
|
59
|
-
* ```json
|
|
60
|
-
* {"userID": "1", "userDepartament": "NBC"}
|
|
61
|
-
* ```
|
|
62
|
-
* and _The resource_
|
|
63
|
-
* ```json
|
|
64
|
-
* ["FOX", "NBC", "AONE"]
|
|
65
|
-
* ```
|
|
66
|
-
* \
|
|
67
|
-
* Now we can make the matching rule:
|
|
68
|
-
* ```json
|
|
69
|
-
* ["subject.userDepartament", "=", "resource"]
|
|
70
|
-
* ```
|
|
71
|
-
* **Note: In this rule whe set the resource field as the «resource» string.\
|
|
72
|
-
* This means that we will compare the entire resource as a whole,\
|
|
73
|
-
* and not search for it by field name.**
|
|
74
|
-
* \
|
|
75
|
-
* **Example 4.**\
|
|
76
|
-
* In this case will be compared resource and array of string:\
|
|
77
|
-
* \
|
|
78
|
-
* _The subject_
|
|
79
|
-
* ```json
|
|
80
|
-
* {"user": {"account": {"roles": ["admin", "viewer"]}}}
|
|
81
|
-
* ```
|
|
82
|
-
* and _The resource_
|
|
83
|
-
* ```json
|
|
84
|
-
* undefined
|
|
85
|
-
* ```
|
|
86
|
-
* \
|
|
87
|
-
* Now we can make the matching rule:
|
|
88
|
-
* ```json
|
|
89
|
-
* ["subject.user.account.roles", "in", "admin"]
|
|
17
|
+
* Check if the rule is matched
|
|
18
|
+
* @param resource - The resource to check
|
|
90
19
|
*/
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
extractValues(sub: unknown, res?: unknown | undefined, env?: unknown | undefined): [
|
|
20
|
+
check(resource: Resources | null): AbilityMatch;
|
|
21
|
+
/**
|
|
22
|
+
* Extract values from the resource
|
|
23
|
+
* @param resource - The resource to extract values from
|
|
24
|
+
*/
|
|
25
|
+
extractValues(resource: Resources | null): [
|
|
98
26
|
string | number | boolean | (string | number)[] | null | undefined,
|
|
99
27
|
string | number | boolean | (string | number)[] | null | undefined
|
|
100
28
|
];
|
|
101
|
-
getDotNotationValue(resource: unknown, desc: string): unknown;
|
|
102
29
|
/**
|
|
103
|
-
*
|
|
104
|
-
*
|
|
30
|
+
* Get the value of the object by dot notation
|
|
31
|
+
* @param resource - The object to get the value from
|
|
32
|
+
* @param desc - The dot notation string
|
|
33
|
+
*/
|
|
34
|
+
getDotNotationValue<T = unknown>(resource: unknown, desc: string): T | undefined;
|
|
35
|
+
static parse<Resources extends object>(configOrJson: AbilityRuleConfig | string): AbilityRule<Resources>;
|
|
36
|
+
/**
|
|
37
|
+
* Export the rule to config object
|
|
105
38
|
*/
|
|
106
|
-
|
|
39
|
+
export(): AbilityRuleConfig;
|
|
107
40
|
}
|
|
108
41
|
export default AbilityRule;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import AbilityRule, { AbilityRuleConfig } from './AbilityRule';
|
|
2
|
+
import AbilityCompare from './AbilityCompare';
|
|
3
|
+
import AbilityMatch from './AbilityMatch';
|
|
4
|
+
export type AbilityRuleSetConfig = {
|
|
5
|
+
readonly id?: string | symbol;
|
|
6
|
+
readonly name: string;
|
|
7
|
+
readonly compareMethod: number;
|
|
8
|
+
readonly rules: AbilityRuleConfig[];
|
|
9
|
+
};
|
|
10
|
+
export declare class AbilityRuleSet<Resources extends object = object> {
|
|
11
|
+
state: AbilityMatch;
|
|
12
|
+
/**
|
|
13
|
+
* List of rules
|
|
14
|
+
*/
|
|
15
|
+
rules: AbilityRule[];
|
|
16
|
+
/**
|
|
17
|
+
* Rules compare method.\
|
|
18
|
+
* For the «and» method the rule will be permitted if all\
|
|
19
|
+
* rules will be returns «permit» status and for the «or» - if\
|
|
20
|
+
* one of the rules returns as «permit»
|
|
21
|
+
*/
|
|
22
|
+
compareMethod: AbilityCompare;
|
|
23
|
+
/**
|
|
24
|
+
* Group name
|
|
25
|
+
*/
|
|
26
|
+
name: string | symbol;
|
|
27
|
+
/**
|
|
28
|
+
* Group ID
|
|
29
|
+
*/
|
|
30
|
+
id: string | symbol;
|
|
31
|
+
constructor(params?: {
|
|
32
|
+
name?: string | symbol;
|
|
33
|
+
id?: string | symbol;
|
|
34
|
+
});
|
|
35
|
+
addRule(rule: AbilityRule, compareMethod: AbilityCompare): this;
|
|
36
|
+
addRules(rules: AbilityRule[], compareMethod: AbilityCompare): this;
|
|
37
|
+
check(resources: Resources | null): AbilityMatch;
|
|
38
|
+
/**
|
|
39
|
+
* Parse the config JSON format to Group class instance
|
|
40
|
+
*/
|
|
41
|
+
static parse<Resource extends object = object>(configOrJson: AbilityRuleSetConfig | string): AbilityRuleSet<Resource>;
|
|
42
|
+
export(): AbilityRuleSetConfig;
|
|
43
|
+
}
|
|
44
|
+
export default AbilityRuleSet;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
export * from './AbilityCode';
|
|
2
|
+
export * from './AbilityCompare';
|
|
3
|
+
export * from './AbilityCondition';
|
|
4
|
+
export * from './AbilityError';
|
|
5
|
+
export * from './AbilityMatch';
|
|
6
|
+
export * from './AbilityParser';
|
|
2
7
|
export * from './AbilityPolicy';
|
|
3
|
-
export * from './
|
|
8
|
+
export * from './AbilityPolicyEffect';
|
|
9
|
+
export * from './AbilityResolver';
|
|
4
10
|
export * from './AbilityRule';
|
|
5
|
-
export
|
|
11
|
+
export * from './AbilityRuleSet';
|