@via-profit/ability 2.0.0-rc.8 → 2.1.0

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.
@@ -1 +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;IAEM,MAAM,CAAC,WAAW,CAA4B,OAAwB;QAC3E,IAAI,IAAI,GAAuB,IAAI,CAAC;QAEpC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE;YACjC,IAAI,MAAM,KAAK,OAAO,EAAE,CAAC;gBACvB,IAAI,GAAG,IAAI,CAAC,MAA2B,CAAgB,CAAC;YAC1D,CAAC;QACH,CAAC,CAAC,CAAC;QAEH,IAAI,CAAC,IAAI,EAAE,CAAC;YACV,MAAM,IAAI,KAAK,CACb,+BAA+B,OAAO,4CAA4C,CACnF,CAAC;QACJ,CAAC;QAED,OAAO,IAAI,IAAI,CAAE,IAAoB,CAAC,IAAI,CAAmB,CAAC;IAChE,CAAC;CACF;AAhCD,kCAgCC;AAED,qBAAe,WAAW,CAAC;;;;;;;;;;;;;;;;;AClC3B,wGAAwC;AAIxC,MAAa,cAAe,SAAQ,qBAAsC;IACjE,MAAM,CAAC,GAAG,GAAG,IAAI,cAAc,CAAC,KAAK,CAAC,CAAC;IACvC,MAAM,CAAC,EAAE,GAAG,IAAI,cAAc,CAAC,IAAI,CAAC,CAAC;;AAF9C,wCAGC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AC;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;;;;;;;;;;;ACzGH;;;;;;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/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 public static fromLiteral<T extends string | number>(literal: string | number): AbilityCode<T> {\n let Code: AbilityCode | null = null;\n\n Object.keys(this).forEach(member => {\n if (member === literal) {\n Code = this[member as keyof typeof this] as AbilityCode;\n }\n });\n\n if (!Code) {\n throw new Error(\n `Mismatch error. The literal ${literal} can not be find as a member of this class`,\n );\n }\n\n return new this((Code as AbilityCode).code) as AbilityCode<T>;\n }\n}\n\nexport default AbilityCode;\n","import AbilityCode from './AbilityCode';\n\nexport type AbilityCompareVariantType = 'and' | 'or'\n\nexport class AbilityCompare extends AbilityCode<AbilityCompareVariantType> {\n public static and = new AbilityCompare('and');\n public static or = new AbilityCompare('or');\n}\n\nexport default AbilityCompare;\n","import AbilityCode from './AbilityCode';\n\nexport type AbilityConditionVariantType = '=' | '<>' | '>' | '<' | '>=' | '<=' | 'in' | 'not in';\n\nexport class AbilityCondition extends AbilityCode<AbilityConditionVariantType> {\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 type AbilityMatchVariantType = 'pending' | 'match' | 'mismatch';\n\nexport class AbilityMatch extends AbilityCode<AbilityMatchVariantType>{\n public static pending = new AbilityMatch('pending');\n public static match = new AbilityMatch('match');\n public static mismatch = new AbilityMatch('mismatch');\n}\n\nexport default AbilityMatch;","import AbilityRuleSet, { AbilityRuleSetConfig } from './AbilityRuleSet';\nimport AbilityMatch from './AbilityMatch';\nimport AbilityCompare, { AbilityCompareVariantType } from './AbilityCompare';\nimport AbilityPolicyEffect, { AbilityPolicyEffectVariantType } from './AbilityPolicyEffect';\n\nexport type AbilityPolicyConfig = {\n readonly action: string;\n readonly effect: AbilityPolicyEffectVariantType;\n readonly compareMethod: AbilityCompareVariantType;\n readonly ruleSet: 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;\n\n /**\n * Policy ID\n */\n public id: string;\n\n /**\n * Soon\n */\n public action: string;\n\n public constructor(params: {\n id: string;\n name: string;\n action: string;\n effect: AbilityPolicyEffect;\n }) {\n const { name, id, action, effect } = params;\n this.name = name;\n this.id = id;\n this.action = action;\n this.effect = effect;\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 * Check if the policy is matched\n * @param resources - The resource to check\n */\n public check(resources: Resources): AbilityMatch {\n this.matchState = AbilityMatch.mismatch;\n\n if (!this.ruleSet.length) {\n return this.matchState;\n }\n\n const rulesetCheckStates = this.ruleSet.reduce<AbilityMatch[]>((collect, ruleSet) => {\n return collect.concat(ruleSet.check(resources));\n }, []);\n\n if (AbilityCompare.and.isEqual(this.compareMethod)) {\n if (rulesetCheckStates.every(ruleState => AbilityMatch.match.isEqual(ruleState))) {\n this.matchState = AbilityMatch.match;\n }\n }\n\n if (AbilityCompare.or.isEqual(this.compareMethod)) {\n if (rulesetCheckStates.some(ruleState => AbilityMatch.match.isEqual(ruleState))) {\n this.matchState = AbilityMatch.match;\n }\n }\n\n return this.matchState;\n }\n\n /**\n * Parse the config JSON format to Policy class instance\n */\n public static parse<Resources extends object = object>(\n config: AbilityPolicyConfig,\n ): AbilityPolicy<Resources> {\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 = AbilityCompare.fromLiteral(compareMethod);\n\n ruleSet.forEach(ruleSetConfig => {\n policy.addRuleSet(AbilityRuleSet.parse(ruleSetConfig));\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.toString() as AbilityPolicyConfig['compareMethod'],\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 type AbilityPolicyEffectVariantType = 'deny' | 'permit';\n\nexport class AbilityPolicyEffect extends AbilityCode<AbilityPolicyEffectVariantType> {\n public static deny = new AbilityPolicyEffect('deny');\n public static permit = new AbilityPolicyEffect('permit');\n}\n\nexport default AbilityPolicyEffect;\n","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(\n policyOrListOfPolicies: readonly AbilityPolicy<Resources>[] | AbilityPolicy<Resources>,\n ) {\n this.policies = Array.isArray(policyOrListOfPolicies)\n ? policyOrListOfPolicies\n : [policyOrListOfPolicies];\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 resolver.getMatchedPolicy()?.name?.toString() || 'Unknown permission error',\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 getMatchedPolicy(): AbilityPolicy<Resources> | null {\n const matchedPolicies = this.policies.filter(policy => policy.matchState.isEqual(AbilityMatch.match));\n\n const lastPolicy = matchedPolicies.length ? matchedPolicies[matchedPolicies.length - 1] : null;\n\n return 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 const c = a\n .reduce<boolean[]>((acc, chunk, index) => {\n const iterationRes = chunk === b[index] || b[index] === '*' || chunk === '*';\n\n return acc.concat(iterationRes);\n }, [])\n\n return c.every(Boolean);\n }\n}\n\nexport default AbilityResolver;\n","import AbilityMatch from './AbilityMatch';\nimport AbilityCondition, { AbilityConditionVariantType } from './AbilityCondition';\n\nexport type AbilityRuleConfig = {\n readonly id: string;\n readonly name: string;\n\n /**\n * Subject key path like a 'user.name'\n */\n readonly subject: string;\n /**\n * Resource key path like a 'user.name' or value\n */\n readonly resource: string | number | boolean | (string | number)[];\n\n readonly condition: AbilityConditionVariantType;\n};\n\nexport class AbilityRule<Resources extends object = object> {\n /**\n * Subject key path like a 'user.name'\n */\n public subject: string;\n /**\n * Resource key path like a 'user.name' or value\n */\n public resource: string | number | boolean | (string | number)[];\n\n public condition: AbilityCondition;\n public name: string;\n public id: string;\n public state: AbilityMatch = AbilityMatch.pending;\n\n public constructor(params: AbilityRuleConfig) {\n const { id, name, subject, resource, condition } = params;\n this.id = id;\n this.name = name;\n this.subject = subject;\n this.resource = resource;\n this.condition = new AbilityCondition(condition);\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 let is: boolean = false;\n\n const [valueS, valueO] = this.extractValues(resource);\n\n if (AbilityCondition.LESS_THAN.isEqual(this.condition)) {\n is = Number(valueS) < Number(valueO);\n }\n\n if (AbilityCondition.LESS_OR_EQUAL.isEqual(this.condition)) {\n is = Number(valueS) <= Number(valueO);\n }\n\n if (AbilityCondition.MORE_THAN.isEqual(this.condition)) {\n is = Number(valueS) > Number(valueO);\n }\n\n if (AbilityCondition.MORE_OR_EQUAL.isEqual(this.condition)) {\n is = Number(valueS) >= Number(valueO);\n }\n\n if (AbilityCondition.EQUAL.isEqual(this.condition)) {\n is = valueS === valueO;\n }\n\n if (AbilityCondition.NOT_EQUAL.isEqual(this.condition)) {\n is = valueS !== valueO;\n }\n\n if (AbilityCondition.IN.isEqual(this.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(this.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 resourceData\n * @param resourceData - The resourceData to extract values from\n */\n public extractValues(\n resourceData: Resources | null,\n ): [\n string | number | boolean | (string | number)[] | null | undefined,\n string | number | boolean | (string | number)[] | null | undefined,\n ] {\n let leftSideValue;\n let rightSideValue;\n\n if (resourceData === null || typeof resourceData === '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(this.subject)) {\n leftSideValue = this.getDotNotationValue<number | boolean | string | (string | number)[]>(\n resourceData,\n this.subject,\n );\n } else {\n leftSideValue = this.subject;\n }\n if (isPath(this.resource)) {\n rightSideValue = this.getDotNotationValue<number | boolean | string | (string | number)[]>(\n resourceData,\n this.resource,\n );\n } else {\n rightSideValue = this.resource 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 config: AbilityRuleConfig,\n ): AbilityRule<Resources> {\n const { id, name, subject, resource, condition } = config;\n\n return new AbilityRule<Resources>({\n id,\n name,\n subject,\n resource,\n condition,\n });\n }\n\n /**\n * Export the rule to config object\n */\n public export(): AbilityRuleConfig {\n return {\n id: this.id,\n name: this.name,\n subject: this.subject,\n resource: this.resource,\n condition: this.condition.code,\n };\n }\n}\n\nexport default AbilityRule;\n","import AbilityRule, { AbilityRuleConfig } from './AbilityRule';\nimport AbilityCompare, { AbilityCompareVariantType } from './AbilityCompare';\nimport AbilityMatch from './AbilityMatch';\n\nexport type AbilityRuleSetConfig = {\n readonly id: string;\n readonly name: string;\n readonly compareMethod: AbilityCompareVariantType;\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;\n\n /**\n * Group ID\n */\n public id: string;\n\n public constructor(params: Pick<AbilityRuleSetConfig, 'id' | 'name' | 'compareMethod'>) {\n const { name, id, compareMethod } = params;\n\n this.name = name;\n this.id = id;\n this.compareMethod = AbilityCompare.fromLiteral<AbilityCompareVariantType>(compareMethod);\n // this.compareMethod = new AbilityCompare(compareMethod);\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 * Parse the config JSON format to Group class instance\n */\n public static parse<Resource extends object = object>(\n config: AbilityRuleSetConfig,\n ): AbilityRuleSet<Resource> {\n const { id, name, rules, compareMethod } = config;\n\n const ruleSet = new AbilityRuleSet<Resource>({\n compareMethod,\n name,\n id,\n });\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.toString() as AbilityRuleSetConfig['compareMethod'],\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\nconst server = http.createServer();\n\nserver.on('request', (_req, res) => {\n type Resources = {\n ['order.status']: {\n readonly account: {\n readonly roles: readonly string[];\n };\n readonly order: {\n readonly status: string;\n };\n readonly feature: {\n readonly status: string;\n };\n };\n };\n\n\n const config: AbilityPolicyConfig[] = [\n {\n id: 'bb758c1b-1015-4894-ba25-d23156e063cf',\n name: 'Status hui',\n action: 'order.status',\n effect: 'deny',\n compareMethod: 'and',\n ruleSet: [\n {\n id: '9cc009e5-0aa9-453a-a668-cb3f418ced92',\n name: 'Не администратор',\n compareMethod: 'and',\n rules: [\n {\n id: '4093cd50-e54f-4062-8053-2d3b5966fad3',\n name: 'Нет роли администраторв',\n subject: 'account.roles',\n resource: 'administrator',\n condition: '<>',\n },\n ],\n },\n ]\n },\n {\n id: 'bb758c1b-1015-4894-ba25-d23156e063cf',\n name: 'Status hui 1',\n action: 'order.status',\n effect: 'permit',\n compareMethod: 'and',\n ruleSet: [\n {\n id: '2f8f9d71-860b-4fa6-b395-9331f1f0848e',\n name: 'Rule set',\n compareMethod: 'and',\n rules: [\n {\n id: 'a3c7d66f-5c2d-4a24-83bc-03b0a2d9c32b',\n name: 'Rule 1',\n subject: 'order.status',\n resource: 'не обработан',\n condition: '=',\n },\n {\n id: 'a3c7d66f-5c2d-4a24-83bc-03b0a2d9c32b',\n name: 'Rule 2',\n subject: 'feature.status',\n resource: 'отменен',\n condition: '=',\n },\n ],\n },\n ],\n },\n ];\n\n const policies = config.map(cfg => AbilityPolicy.parse<Resources>(cfg));\n const result = new AbilityResolver(policies).resolve('order.status', {\n account: {\n roles: ['user', 'couch'],\n },\n order: {\n status: 'не обработан',\n },\n feature: {\n status: 'отменен',\n // status: 'завершен'\n },\n });\n\n res.statusCode = 200;\n res.setHeader('content-type', 'application/json');\n\n res.write(\n JSON.stringify({\n status: result.isDeny() ? 'deny' : 'permit',\n }),\n );\n res.end();\n});\n\nserver.listen(8081, '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 } | null;\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 } | null;\n };\n readonly ['order.update']: {\n readonly account: {\n readonly roles: readonly string[];\n readonly department: string;\n } | null;\n readonly order: {\n readonly status: string;\n } | null;\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":""}
1
+ {"version":3,"file":"playground.js","mappings":";;;;;;;;;;;;;AAAA,MAAa,WAAW;IAGf,KAAK,CAAO;IAEnB,YAAY,IAAU;QACpB,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;IACpB,CAAC;IAED,IAAW,IAAI;QACb,OAAO,IAAI,CAAC,KAAK,CAAC;IACpB,CAAC;IAEM,OAAO,CAAC,WAAqC;QAClD,OAAO,WAAW,KAAK,IAAI,IAAI,IAAI,CAAC,IAAI,KAAK,WAAW,CAAC,IAAI,CAAC;IAChE,CAAC;IAEM,UAAU,CAAC,WAAqC;QACrD,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;IACpC,CAAC;CACF;AApBD,kCAoBC;AAED,qBAAe,WAAW,CAAC;;;;;;;;;;;;;;;;;ACtB3B,wGAAwC;AACxC,0FAAoD;AAapD,MAAa,gBAAiB,SAAQ,qBAAqC;IAClE,MAAM,CAAC,KAAK,GAAG,IAAI,gBAAgB,CAAC,GAAG,CAAC,CAAC;IACzC,MAAM,CAAC,SAAS,GAAG,IAAI,gBAAgB,CAAC,IAAI,CAAC,CAAC;IAC9C,MAAM,CAAC,SAAS,GAAG,IAA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C,CAAC;;;;;;;;;;;AC7GH;;;;;;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/AbilityCondition.ts","webpack://@via-profit/ability/./src/AbilityError.ts","webpack://@via-profit/ability/./src/AbilityMatch.ts","webpack://@via-profit/ability/./src/AbilityRule.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<\n Code extends string | number,\n> {\n public _code: Code;\n\n constructor(code: Code) {\n this._code = code;\n }\n\n public get code(): Code {\n return this._code;\n }\n\n public isEqual(compareWith: AbilityCode<Code> | null): boolean {\n return compareWith !== null && this.code === compareWith.code;\n }\n\n public isNotEqual(compareWith: AbilityCode<Code> | null): boolean {\n return !this.isEqual(compareWith);\n }\n}\n\nexport default AbilityCode;\n","import AbilityCode from './AbilityCode';\nimport { AbilityParserError } from '~/AbilityError';\n\nexport type AbilityConditionCodeType = '=' | '<>' | '>' | '<' | '>=' | '<=' | 'in' | 'not in';\nexport type AbilityConditionLiteralType =\n | 'equal'\n | 'not_equal'\n | 'more_than'\n | 'less_than'\n | 'less_or_equal'\n | 'more_or_equal'\n | 'in'\n | 'not_in';\n\nexport class AbilityCondition extends AbilityCode<AbilityConditionCodeType> {\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 public static fromLiteral(literal: AbilityConditionLiteralType): AbilityCondition {\n const code = AbilityCondition[literal]?.code || null;\n if (code === null) {\n throw new AbilityParserError(`Literal ${literal} does not found in AbilityCondition class`);\n }\n\n return new AbilityCondition(code);\n }\n\n public get literal() {\n const literal = Object.keys(AbilityCondition).find(member => {\n const val = AbilityCondition[member as keyof typeof AbilityCondition] as AbilityCondition;\n return val.code === this.code;\n }) as AbilityConditionLiteralType;\n\n if (typeof literal === 'undefined') {\n throw new Error(`Literal value does not found in class AbilityCondition`);\n }\n\n return literal;\n }\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 type AbilityMatchCodeType = 'pending' | 'match' | 'mismatch';\n\nexport class AbilityMatch extends AbilityCode<AbilityMatchCodeType>{\n public static pending = new AbilityMatch('pending');\n public static match = new AbilityMatch('match');\n public static mismatch = new AbilityMatch('mismatch');\n}\n\nexport default AbilityMatch;","import AbilityMatch from './AbilityMatch';\nimport AbilityCondition, { AbilityConditionCodeType } from './AbilityCondition';\n\nexport type AbilityRuleConfig = {\n readonly id: string;\n readonly name: string;\n\n /**\n * Subject key path like a 'user.name'\n */\n readonly subject: string;\n /**\n * Resource key path like a 'user.name' or value\n */\n readonly resource: string | number | boolean | (string | number)[];\n\n readonly condition: AbilityConditionCodeType;\n};\n\nexport type AbilityRuleConstructorProps = Omit<AbilityRuleConfig, 'condition'> & {\n readonly condition: AbilityCondition;\n};\n\nexport class AbilityRule<Resources extends object = object> {\n /**\n * Subject key path like a 'user.name'\n */\n public subject: string;\n /**\n * Resource key path like a 'user.name' or value\n */\n public resource: string | number | boolean | (string | number)[];\n\n public condition: AbilityCondition;\n public name: string;\n public id: string;\n public state: AbilityMatch = AbilityMatch.pending;\n\n public constructor(params: AbilityRuleConstructorProps) {\n const { id, name, subject, resource, condition } = params;\n this.id = id;\n this.name = name;\n this.subject = subject;\n this.resource = resource;\n this.condition = condition;\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 let is: boolean = false;\n\n const [valueS, valueO] = this.extractValues(resource);\n\n if (AbilityCondition.less_than.isEqual(this.condition)) {\n is = Number(valueS) < Number(valueO);\n }\n\n if (AbilityCondition.less_or_equal.isEqual(this.condition)) {\n is = Number(valueS) <= Number(valueO);\n }\n\n if (AbilityCondition.more_than.isEqual(this.condition)) {\n is = Number(valueS) > Number(valueO);\n }\n\n if (AbilityCondition.more_or_equal.isEqual(this.condition)) {\n is = Number(valueS) >= Number(valueO);\n }\n\n if (AbilityCondition.equal.isEqual(this.condition)) {\n is = valueS === valueO;\n }\n\n if (AbilityCondition.not_equal.isEqual(this.condition)) {\n is = valueS !== valueO;\n }\n\n if (AbilityCondition.in.isEqual(this.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(this.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 resourceData\n * @param resourceData - The resourceData to extract values from\n */\n public extractValues(\n resourceData: Resources | null,\n ): [\n string | number | boolean | (string | number)[] | null | undefined,\n string | number | boolean | (string | number)[] | null | undefined,\n ] {\n let leftSideValue;\n let rightSideValue;\n\n if (resourceData === null || typeof resourceData === '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(this.subject)) {\n leftSideValue = this.getDotNotationValue<number | boolean | string | (string | number)[]>(\n resourceData,\n this.subject,\n );\n } else {\n leftSideValue = this.subject;\n }\n if (isPath(this.resource)) {\n rightSideValue = this.getDotNotationValue<number | boolean | string | (string | number)[]>(\n resourceData,\n this.resource,\n );\n } else {\n rightSideValue = this.resource 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>(config: AbilityRuleConfig): AbilityRule<Resources> {\n const { id, name, subject, resource, condition } = config;\n\n return new AbilityRule<Resources>({\n id,\n name,\n subject,\n resource,\n condition: new AbilityCondition(condition),\n });\n }\n\n /**\n * Export the rule to config object\n */\n public export(): AbilityRuleConfig {\n return {\n id: this.id,\n name: this.name,\n subject: this.subject,\n resource: this.resource,\n condition: this.condition.code,\n };\n }\n}\n\nexport default AbilityRule;\n","import http from 'node:http';\nimport { AbilityPolicyConfig } from './AbilityPolicy';\nimport AbilityCondition from '~/AbilityCondition';\nimport AbilityRule from './AbilityRule';\nimport AbilityMatch from './AbilityMatch';\n\nconst server = http.createServer();\n\nserver.on('request', (_req, res) => {\n type Resources = {\n ['order.status']: {\n readonly account: {\n readonly roles: readonly string[];\n };\n readonly order: {\n readonly status: string;\n };\n readonly feature: {\n readonly status: string;\n };\n };\n };\n\n const config: AbilityPolicyConfig[] = [\n {\n id: 'bb758c1b-1015-4894-ba25-d23156e063cf',\n name: 'Status hui',\n action: 'order.status',\n effect: 'deny',\n compareMethod: 'and',\n ruleSet: [\n {\n id: '9cc009e5-0aa9-453a-a668-cb3f418ced92',\n name: 'Не администратор',\n compareMethod: 'and',\n rules: [\n {\n id: '4093cd50-e54f-4062-8053-2d3b5966fad3',\n name: 'Нет роли администраторв',\n subject: 'account.roles',\n resource: 'administrator',\n condition: '<>',\n },\n ],\n },\n ],\n },\n {\n id: 'bb758c1b-1015-4894-ba25-d23156e063cf',\n name: 'Status hui 1',\n action: 'order.status',\n effect: 'permit',\n compareMethod: 'and',\n ruleSet: [\n {\n id: '2f8f9d71-860b-4fa6-b395-9331f1f0848e',\n name: 'Rule set',\n compareMethod: 'and',\n rules: [\n {\n id: 'a3c7d66f-5c2d-4a24-83bc-03b0a2d9c32b',\n name: 'Rule 1',\n subject: 'order.status',\n resource: 'не обработан',\n condition: '=',\n },\n {\n id: 'a3c7d66f-5c2d-4a24-83bc-03b0a2d9c32b',\n name: 'Rule 2',\n subject: 'feature.status',\n resource: 'отменен',\n condition: '=',\n },\n ],\n },\n ],\n },\n ];\n\n const rule = new AbilityRule({\n id: '<rule-id>',\n name: 'Пользователь является владельцем заказа',\n condition: AbilityCondition.equal,\n subject: 'user.id',\n resource: 'order.owner',\n });\n\n const matchState = rule.check({\n user: { id: '1' },\n order: { owner: '1' },\n });\n\n const is = matchState.isEqual(AbilityMatch.match); // true\n\n\n\n res.statusCode = 200;\n res.setHeader('content-type', 'application/json');\n\n res.write(\n JSON.stringify({\n status: 'ok',\n }),\n );\n res.end();\n});\n\nserver.listen(8081, 'localhost', () => {\n console.debug('server started at http://localhost:8081');\n});\n\nexport type Resources = {\n readonly ['account.read']: {\n readonly account: {\n readonly id: string;\n readonly roles: readonly string[];\n } | null;\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 } | null;\n };\n readonly ['order.update']: {\n readonly account: {\n readonly roles: readonly string[];\n readonly department: string;\n } | null;\n readonly order: {\n readonly status: string;\n } | null;\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":""}
@@ -1,8 +1,8 @@
1
- export declare class AbilityCode<T extends string | number | undefined = number> {
2
- code: T;
3
- constructor(code: T);
4
- isEqual(compareWith: AbilityCode<T> | null): boolean;
5
- isNotEqual(compareWith: AbilityCode<T> | null): boolean;
6
- static fromLiteral<T extends string | number>(literal: string | number): AbilityCode<T>;
1
+ export declare class AbilityCode<Code extends string | number> {
2
+ _code: Code;
3
+ constructor(code: Code);
4
+ get code(): Code;
5
+ isEqual(compareWith: AbilityCode<Code> | null): boolean;
6
+ isNotEqual(compareWith: AbilityCode<Code> | null): boolean;
7
7
  }
8
8
  export default AbilityCode;
@@ -1,6 +1,6 @@
1
1
  import AbilityCode from './AbilityCode';
2
- export type AbilityCompareVariantType = 'and' | 'or';
3
- export declare class AbilityCompare extends AbilityCode<AbilityCompareVariantType> {
2
+ export type AbilityCompareCodeType = 'and' | 'or';
3
+ export declare class AbilityCompare extends AbilityCode<AbilityCompareCodeType> {
4
4
  static and: AbilityCompare;
5
5
  static or: AbilityCompare;
6
6
  }
@@ -1,13 +1,16 @@
1
1
  import AbilityCode from './AbilityCode';
2
- export type AbilityConditionVariantType = '=' | '<>' | '>' | '<' | '>=' | '<=' | 'in' | 'not in';
3
- export declare class AbilityCondition extends AbilityCode<AbilityConditionVariantType> {
4
- static EQUAL: AbilityCondition;
5
- static NOT_EQUAL: AbilityCondition;
6
- static MORE_THAN: AbilityCondition;
7
- static LESS_THAN: AbilityCondition;
8
- static LESS_OR_EQUAL: AbilityCondition;
9
- static MORE_OR_EQUAL: AbilityCondition;
10
- static IN: AbilityCondition;
11
- static NOT_IN: AbilityCondition;
2
+ export type AbilityConditionCodeType = '=' | '<>' | '>' | '<' | '>=' | '<=' | 'in' | 'not in';
3
+ export type AbilityConditionLiteralType = 'equal' | 'not_equal' | 'more_than' | 'less_than' | 'less_or_equal' | 'more_or_equal' | 'in' | 'not_in';
4
+ export declare class AbilityCondition extends AbilityCode<AbilityConditionCodeType> {
5
+ static equal: AbilityCondition;
6
+ static not_equal: AbilityCondition;
7
+ static more_than: AbilityCondition;
8
+ static less_than: AbilityCondition;
9
+ static less_or_equal: AbilityCondition;
10
+ static more_or_equal: AbilityCondition;
11
+ static in: AbilityCondition;
12
+ static not_in: AbilityCondition;
13
+ static fromLiteral(literal: AbilityConditionLiteralType): AbilityCondition;
14
+ get literal(): AbilityConditionLiteralType;
12
15
  }
13
16
  export default AbilityCondition;
@@ -4,6 +4,3 @@ export declare class AbilityError extends Error {
4
4
  export declare class AbilityParserError extends Error {
5
5
  constructor(message: string);
6
6
  }
7
- export declare class PermissionError extends Error {
8
- constructor(message: string);
9
- }
@@ -1,6 +1,6 @@
1
1
  import AbilityCode from './AbilityCode';
2
- export type AbilityMatchVariantType = 'pending' | 'match' | 'mismatch';
3
- export declare class AbilityMatch extends AbilityCode<AbilityMatchVariantType> {
2
+ export type AbilityMatchCodeType = 'pending' | 'match' | 'mismatch';
3
+ export declare class AbilityMatch extends AbilityCode<AbilityMatchCodeType> {
4
4
  static pending: AbilityMatch;
5
5
  static match: AbilityMatch;
6
6
  static mismatch: AbilityMatch;
@@ -1,15 +1,21 @@
1
1
  import AbilityRuleSet, { AbilityRuleSetConfig } from './AbilityRuleSet';
2
2
  import AbilityMatch from './AbilityMatch';
3
- import AbilityCompare, { AbilityCompareVariantType } from './AbilityCompare';
4
- import AbilityPolicyEffect, { AbilityPolicyEffectVariantType } from './AbilityPolicyEffect';
3
+ import AbilityCompare, { AbilityCompareCodeType } from './AbilityCompare';
4
+ import AbilityPolicyEffect, { AbilityPolicyEffectCodeType } from './AbilityPolicyEffect';
5
5
  export type AbilityPolicyConfig = {
6
6
  readonly action: string;
7
- readonly effect: AbilityPolicyEffectVariantType;
8
- readonly compareMethod: AbilityCompareVariantType;
9
- readonly ruleSet: AbilityRuleSetConfig[];
7
+ readonly effect: AbilityPolicyEffectCodeType;
8
+ readonly compareMethod: AbilityCompareCodeType;
9
+ readonly ruleSet: readonly AbilityRuleSetConfig[];
10
10
  readonly id: string;
11
11
  readonly name: string;
12
12
  };
13
+ export type AbilityPolicyConstructorProps = {
14
+ id: string;
15
+ name: string;
16
+ action: string;
17
+ effect: AbilityPolicyEffect;
18
+ };
13
19
  export declare class AbilityPolicy<Resources extends object = object> {
14
20
  matchState: AbilityMatch;
15
21
  /**
@@ -39,12 +45,7 @@ export declare class AbilityPolicy<Resources extends object = object> {
39
45
  * Soon
40
46
  */
41
47
  action: string;
42
- constructor(params: {
43
- id: string;
44
- name: string;
45
- action: string;
46
- effect: AbilityPolicyEffect;
47
- });
48
+ constructor(params: AbilityPolicyConstructorProps);
48
49
  /**
49
50
  * Add rule set to the policy
50
51
  * @param ruleSet - The rule set to add
@@ -1,6 +1,6 @@
1
1
  import AbilityCode from './AbilityCode';
2
- export type AbilityPolicyEffectVariantType = 'deny' | 'permit';
3
- export declare class AbilityPolicyEffect extends AbilityCode<AbilityPolicyEffectVariantType> {
2
+ export type AbilityPolicyEffectCodeType = 'deny' | 'permit';
3
+ export declare class AbilityPolicyEffect extends AbilityCode<AbilityPolicyEffectCodeType> {
4
4
  static deny: AbilityPolicyEffect;
5
5
  static permit: AbilityPolicyEffect;
6
6
  }
@@ -1,5 +1,5 @@
1
1
  import AbilityMatch from './AbilityMatch';
2
- import AbilityCondition, { AbilityConditionVariantType } from './AbilityCondition';
2
+ import AbilityCondition, { AbilityConditionCodeType } from './AbilityCondition';
3
3
  export type AbilityRuleConfig = {
4
4
  readonly id: string;
5
5
  readonly name: string;
@@ -11,8 +11,14 @@ export type AbilityRuleConfig = {
11
11
  * Resource key path like a 'user.name' or value
12
12
  */
13
13
  readonly resource: string | number | boolean | (string | number)[];
14
- readonly condition: AbilityConditionVariantType;
14
+ readonly condition: AbilityConditionCodeType;
15
15
  };
16
+ export type AbilityRuleConstructorProps = Omit<AbilityRuleConfig, 'condition'> & {
17
+ readonly condition: AbilityCondition;
18
+ };
19
+ /**
20
+ * Represents a rule that defines a condition to be checked against a subject and resource.
21
+ */
16
22
  export declare class AbilityRule<Resources extends object = object> {
17
23
  /**
18
24
  * Subject key path like a 'user.name'
@@ -26,7 +32,16 @@ export declare class AbilityRule<Resources extends object = object> {
26
32
  name: string;
27
33
  id: string;
28
34
  state: AbilityMatch;
29
- constructor(params: AbilityRuleConfig);
35
+ /**
36
+ * Creates an instance of AbilityRule.
37
+ * @param {string} options.id - The unique identifier of the rule.
38
+ * @param {string} options.name - The name of the rule.
39
+ * @param {AbilityCondition} options.condition - The condition to evaluate.
40
+ * @param {string} options.subject - The subject of the rule.
41
+ * @param {string} options.resource - The resource to compare against.
42
+ * @param params
43
+ */
44
+ constructor(params: AbilityRuleConstructorProps);
30
45
  /**
31
46
  * Check if the rule is matched
32
47
  * @param resource - The resource to check
@@ -1,11 +1,16 @@
1
1
  import AbilityRule, { AbilityRuleConfig } from './AbilityRule';
2
- import AbilityCompare, { AbilityCompareVariantType } from './AbilityCompare';
2
+ import AbilityCompare, { AbilityCompareCodeType } from './AbilityCompare';
3
3
  import AbilityMatch from './AbilityMatch';
4
4
  export type AbilityRuleSetConfig = {
5
5
  readonly id: string;
6
6
  readonly name: string;
7
- readonly compareMethod: AbilityCompareVariantType;
8
- readonly rules: AbilityRuleConfig[];
7
+ readonly compareMethod: AbilityCompareCodeType;
8
+ readonly rules: readonly AbilityRuleConfig[];
9
+ };
10
+ export type AbilityRuleSetConstructorProps = {
11
+ readonly id: string;
12
+ readonly name: string;
13
+ readonly compareMethod: AbilityCompare;
9
14
  };
10
15
  export declare class AbilityRuleSet<Resources extends object = object> {
11
16
  state: AbilityMatch;
@@ -28,9 +33,9 @@ export declare class AbilityRuleSet<Resources extends object = object> {
28
33
  * Group ID
29
34
  */
30
35
  id: string;
31
- constructor(params: Pick<AbilityRuleSetConfig, 'id' | 'name' | 'compareMethod'>);
32
- addRule(rule: AbilityRule, compareMethod: AbilityCompare): this;
33
- addRules(rules: AbilityRule[], compareMethod: AbilityCompare): this;
36
+ constructor(params: AbilityRuleSetConstructorProps);
37
+ addRule(rule: AbilityRule): this;
38
+ addRules(rules: AbilityRule[]): this;
34
39
  check(resources: Resources | null): AbilityMatch;
35
40
  /**
36
41
  * Parse the config JSON format to Group class instance
package/dist/index.js CHANGED
@@ -9,9 +9,12 @@
9
9
  Object.defineProperty(exports, "__esModule", ({ value: true }));
10
10
  exports.AbilityCode = void 0;
11
11
  class AbilityCode {
12
- code;
12
+ _code;
13
13
  constructor(code) {
14
- this.code = code;
14
+ this._code = code;
15
+ }
16
+ get code() {
17
+ return this._code;
15
18
  }
16
19
  isEqual(compareWith) {
17
20
  return compareWith !== null && this.code === compareWith.code;
@@ -19,18 +22,6 @@ class AbilityCode {
19
22
  isNotEqual(compareWith) {
20
23
  return !this.isEqual(compareWith);
21
24
  }
22
- static fromLiteral(literal) {
23
- let Code = null;
24
- Object.keys(this).forEach(member => {
25
- if (member === literal) {
26
- Code = this[member];
27
- }
28
- });
29
- if (!Code) {
30
- throw new Error(`Mismatch error. The literal ${literal} can not be find as a member of this class`);
31
- }
32
- return new this(Code.code);
33
- }
34
25
  }
35
26
  exports.AbilityCode = AbilityCode;
36
27
  exports["default"] = AbilityCode;
@@ -68,15 +59,33 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
68
59
  Object.defineProperty(exports, "__esModule", ({ value: true }));
69
60
  exports.AbilityCondition = void 0;
70
61
  const AbilityCode_1 = __importDefault(__webpack_require__(19));
62
+ const AbilityError_1 = __webpack_require__(122);
71
63
  class AbilityCondition extends AbilityCode_1.default {
72
- static EQUAL = new AbilityCondition('=');
73
- static NOT_EQUAL = new AbilityCondition('<>');
74
- static MORE_THAN = new AbilityCondition('>');
75
- static LESS_THAN = new AbilityCondition('<');
76
- static LESS_OR_EQUAL = new AbilityCondition('<=');
77
- static MORE_OR_EQUAL = new AbilityCondition('>=');
78
- static IN = new AbilityCondition('in');
79
- static NOT_IN = new AbilityCondition('not in');
64
+ static equal = new AbilityCondition('=');
65
+ static not_equal = new AbilityCondition('<>');
66
+ static more_than = new AbilityCondition('>');
67
+ static less_than = new AbilityCondition('<');
68
+ static less_or_equal = new AbilityCondition('<=');
69
+ static more_or_equal = new AbilityCondition('>=');
70
+ static in = new AbilityCondition('in');
71
+ static not_in = new AbilityCondition('not in');
72
+ static fromLiteral(literal) {
73
+ const code = AbilityCondition[literal]?.code || null;
74
+ if (code === null) {
75
+ throw new AbilityError_1.AbilityParserError(`Literal ${literal} does not found in AbilityCondition class`);
76
+ }
77
+ return new AbilityCondition(code);
78
+ }
79
+ get literal() {
80
+ const literal = Object.keys(AbilityCondition).find(member => {
81
+ const val = AbilityCondition[member];
82
+ return val.code === this.code;
83
+ });
84
+ if (typeof literal === 'undefined') {
85
+ throw new Error(`Literal value does not found in class AbilityCondition`);
86
+ }
87
+ return literal;
88
+ }
80
89
  }
81
90
  exports.AbilityCondition = AbilityCondition;
82
91
  exports["default"] = AbilityCondition;
@@ -89,7 +98,7 @@ exports["default"] = AbilityCondition;
89
98
 
90
99
 
91
100
  Object.defineProperty(exports, "__esModule", ({ value: true }));
92
- exports.PermissionError = exports.AbilityParserError = exports.AbilityError = void 0;
101
+ exports.AbilityParserError = exports.AbilityError = void 0;
93
102
  class AbilityError extends Error {
94
103
  constructor(message) {
95
104
  super(message);
@@ -102,12 +111,6 @@ class AbilityParserError extends Error {
102
111
  }
103
112
  }
104
113
  exports.AbilityParserError = AbilityParserError;
105
- class PermissionError extends Error {
106
- constructor(message) {
107
- super(message);
108
- }
109
- }
110
- exports.PermissionError = PermissionError;
111
114
 
112
115
 
113
116
  /***/ }),
@@ -191,18 +194,18 @@ class AbilityParser {
191
194
  ruleSet.rules.forEach(rule => {
192
195
  let value = 'any';
193
196
  switch (true) {
194
- case rule.condition.isEqual(AbilityCondition_1.default.NOT_EQUAL):
195
- case rule.condition.isEqual(AbilityCondition_1.default.EQUAL):
197
+ case rule.condition.isEqual(AbilityCondition_1.default.not_equal):
198
+ case rule.condition.isEqual(AbilityCondition_1.default.equal):
196
199
  value = typeof rule.resource;
197
200
  break;
198
- case rule.condition.isEqual(AbilityCondition_1.default.IN):
199
- case rule.condition.isEqual(AbilityCondition_1.default.NOT_IN):
201
+ case rule.condition.isEqual(AbilityCondition_1.default.in):
202
+ case rule.condition.isEqual(AbilityCondition_1.default.not_in):
200
203
  value = `${typeof rule.resource}[]`;
201
204
  break;
202
- case rule.condition.isEqual(AbilityCondition_1.default.MORE_OR_EQUAL):
203
- case rule.condition.isEqual(AbilityCondition_1.default.MORE_THAN):
204
- case rule.condition.isEqual(AbilityCondition_1.default.LESS_OR_EQUAL):
205
- case rule.condition.isEqual(AbilityCondition_1.default.LESS_THAN):
205
+ case rule.condition.isEqual(AbilityCondition_1.default.more_or_equal):
206
+ case rule.condition.isEqual(AbilityCondition_1.default.more_than):
207
+ case rule.condition.isEqual(AbilityCondition_1.default.less_or_equal):
208
+ case rule.condition.isEqual(AbilityCondition_1.default.less_than):
206
209
  value = 'number';
207
210
  break;
208
211
  }
@@ -313,7 +316,7 @@ class AbilityPolicy {
313
316
  action,
314
317
  effect: new AbilityPolicyEffect_1.default(effect),
315
318
  });
316
- policy.compareMethod = AbilityCompare_1.default.fromLiteral(compareMethod);
319
+ policy.compareMethod = new AbilityCompare_1.default(compareMethod);
317
320
  ruleSet.forEach(ruleSetConfig => {
318
321
  policy.addRuleSet(AbilityRuleSet_1.default.parse(ruleSetConfig));
319
322
  });
@@ -391,10 +394,8 @@ class AbilityResolver {
391
394
  }
392
395
  enforce(action, resource) {
393
396
  const resolver = this.resolve(action, resource);
394
- if (resolver) {
395
- if (resolver.isDeny()) {
396
- throw new AbilityError_1.PermissionError(resolver.getMatchedPolicy()?.name?.toString() || 'Unknown permission error');
397
- }
397
+ if (resolver.isDeny()) {
398
+ throw new AbilityError_1.AbilityError(resolver.getMatchedPolicy()?.name?.toString() || 'Unknown permission error');
398
399
  }
399
400
  }
400
401
  /**
@@ -437,8 +438,7 @@ class AbilityResolver {
437
438
  const actionBArray = String(actionB).split('.');
438
439
  const a = actionAArray.length >= actionBArray.length ? actionAArray : actionBArray;
439
440
  const b = actionBArray.length <= actionAArray.length ? actionBArray : actionAArray;
440
- const c = a
441
- .reduce((acc, chunk, index) => {
441
+ const c = a.reduce((acc, chunk, index) => {
442
442
  const iterationRes = chunk === b[index] || b[index] === '*' || chunk === '*';
443
443
  return acc.concat(iterationRes);
444
444
  }, []);
@@ -462,6 +462,9 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
462
462
  exports.AbilityRule = void 0;
463
463
  const AbilityMatch_1 = __importDefault(__webpack_require__(909));
464
464
  const AbilityCondition_1 = __importDefault(__webpack_require__(261));
465
+ /**
466
+ * Represents a rule that defines a condition to be checked against a subject and resource.
467
+ */
465
468
  class AbilityRule {
466
469
  /**
467
470
  * Subject key path like a 'user.name'
@@ -475,13 +478,22 @@ class AbilityRule {
475
478
  name;
476
479
  id;
477
480
  state = AbilityMatch_1.default.pending;
481
+ /**
482
+ * Creates an instance of AbilityRule.
483
+ * @param {string} options.id - The unique identifier of the rule.
484
+ * @param {string} options.name - The name of the rule.
485
+ * @param {AbilityCondition} options.condition - The condition to evaluate.
486
+ * @param {string} options.subject - The subject of the rule.
487
+ * @param {string} options.resource - The resource to compare against.
488
+ * @param params
489
+ */
478
490
  constructor(params) {
479
491
  const { id, name, subject, resource, condition } = params;
480
492
  this.id = id;
481
493
  this.name = name;
482
494
  this.subject = subject;
483
495
  this.resource = resource;
484
- this.condition = new AbilityCondition_1.default(condition);
496
+ this.condition = condition;
485
497
  }
486
498
  /**
487
499
  * Check if the rule is matched
@@ -490,25 +502,25 @@ class AbilityRule {
490
502
  check(resource) {
491
503
  let is = false;
492
504
  const [valueS, valueO] = this.extractValues(resource);
493
- if (AbilityCondition_1.default.LESS_THAN.isEqual(this.condition)) {
505
+ if (AbilityCondition_1.default.less_than.isEqual(this.condition)) {
494
506
  is = Number(valueS) < Number(valueO);
495
507
  }
496
- if (AbilityCondition_1.default.LESS_OR_EQUAL.isEqual(this.condition)) {
508
+ if (AbilityCondition_1.default.less_or_equal.isEqual(this.condition)) {
497
509
  is = Number(valueS) <= Number(valueO);
498
510
  }
499
- if (AbilityCondition_1.default.MORE_THAN.isEqual(this.condition)) {
511
+ if (AbilityCondition_1.default.more_than.isEqual(this.condition)) {
500
512
  is = Number(valueS) > Number(valueO);
501
513
  }
502
- if (AbilityCondition_1.default.MORE_OR_EQUAL.isEqual(this.condition)) {
514
+ if (AbilityCondition_1.default.more_or_equal.isEqual(this.condition)) {
503
515
  is = Number(valueS) >= Number(valueO);
504
516
  }
505
- if (AbilityCondition_1.default.EQUAL.isEqual(this.condition)) {
517
+ if (AbilityCondition_1.default.equal.isEqual(this.condition)) {
506
518
  is = valueS === valueO;
507
519
  }
508
- if (AbilityCondition_1.default.NOT_EQUAL.isEqual(this.condition)) {
520
+ if (AbilityCondition_1.default.not_equal.isEqual(this.condition)) {
509
521
  is = valueS !== valueO;
510
522
  }
511
- if (AbilityCondition_1.default.IN.isEqual(this.condition)) {
523
+ if (AbilityCondition_1.default.in.isEqual(this.condition)) {
512
524
  // [<some>] and [<some>]
513
525
  if (Array.isArray(valueS) && Array.isArray(valueO)) {
514
526
  is = valueS.some(v => valueO.find(v1 => v1 === v));
@@ -522,7 +534,7 @@ class AbilityRule {
522
534
  is = valueS.includes(valueO);
523
535
  }
524
536
  }
525
- if (AbilityCondition_1.default.NOT_IN.isEqual(this.condition)) {
537
+ if (AbilityCondition_1.default.not_in.isEqual(this.condition)) {
526
538
  // [<some>] and [<some>]
527
539
  if (Array.isArray(valueS) && Array.isArray(valueO)) {
528
540
  is = !valueS.some(v => valueO.find(v1 => v1 === v));
@@ -601,7 +613,7 @@ class AbilityRule {
601
613
  name,
602
614
  subject,
603
615
  resource,
604
- condition,
616
+ condition: new AbilityCondition_1.default(condition),
605
617
  });
606
618
  }
607
619
  /**
@@ -660,16 +672,14 @@ class AbilityRuleSet {
660
672
  const { name, id, compareMethod } = params;
661
673
  this.name = name;
662
674
  this.id = id;
663
- this.compareMethod = AbilityCompare_1.default.fromLiteral(compareMethod);
664
- // this.compareMethod = new AbilityCompare(compareMethod);
675
+ this.compareMethod = compareMethod;
665
676
  }
666
- addRule(rule, compareMethod) {
677
+ addRule(rule) {
667
678
  this.rules.push(rule);
668
- this.compareMethod = compareMethod;
669
679
  return this;
670
680
  }
671
- addRules(rules, compareMethod) {
672
- rules.forEach(rule => this.addRule(rule, compareMethod));
681
+ addRules(rules) {
682
+ rules.forEach(rule => this.addRule(rule));
673
683
  return this;
674
684
  }
675
685
  check(resources) {
@@ -698,14 +708,14 @@ class AbilityRuleSet {
698
708
  static parse(config) {
699
709
  const { id, name, rules, compareMethod } = config;
700
710
  const ruleSet = new AbilityRuleSet({
701
- compareMethod,
711
+ compareMethod: new AbilityCompare_1.default(compareMethod),
702
712
  name,
703
713
  id,
704
714
  });
705
715
  // Adding rules if exists
706
716
  if (rules && rules.length > 0) {
707
717
  const abilityRules = rules.map(ruleConfig => AbilityRule_1.default.parse(ruleConfig));
708
- ruleSet.addRules(abilityRules, ruleSet.compareMethod);
718
+ ruleSet.addRules(abilityRules);
709
719
  }
710
720
  return ruleSet;
711
721
  }