rajt 0.0.37 → 0.0.38
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/package.json +1 -1
- package/src/auth/ability.ts +10 -10
- package/src/auth/authnz.ts +11 -4
package/package.json
CHANGED
package/src/auth/ability.ts
CHANGED
|
@@ -32,16 +32,16 @@ export class Ability {
|
|
|
32
32
|
return path == '/'
|
|
33
33
|
? 'index'
|
|
34
34
|
: path.normalize('NFD')
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
35
|
+
.replace(/[\u0300-\u036f]/g, '')
|
|
36
|
+
.replace(/^\/*/, '')
|
|
37
|
+
.replace(/([a-z])([A-Z])/g, '$1-$2')
|
|
38
|
+
.replace(/[^a-zA-Z0-9/]|[\s\-.]/g, '_')
|
|
39
|
+
.replace(/_+/g, '_')
|
|
40
|
+
.replace(/\//g, '.')
|
|
41
|
+
.replace(/\._/g, '.')
|
|
42
|
+
.replace(/^[._-]+/, '')
|
|
43
|
+
.replace(/[._-]+$/, '')
|
|
44
|
+
.toLowerCase()
|
|
45
45
|
}
|
|
46
46
|
|
|
47
47
|
static get abilities() {
|
package/src/auth/authnz.ts
CHANGED
|
@@ -54,13 +54,20 @@ export class Authnz<T extends object> {
|
|
|
54
54
|
|
|
55
55
|
#match(rule: string, ability: string): boolean {
|
|
56
56
|
if (rule === ability) return true
|
|
57
|
-
if (
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
57
|
+
if (
|
|
58
|
+
this.#wildcardMatch(rule, ability, '_*')
|
|
59
|
+
|| this.#wildcardMatch(rule, ability, '-*')
|
|
60
|
+
|| this.#wildcardMatch(rule, ability, '.*')
|
|
61
|
+
) return true
|
|
62
|
+
|
|
61
63
|
return false
|
|
62
64
|
}
|
|
63
65
|
|
|
66
|
+
#wildcardMatch(rule: string, ability: string, suffix: string) {
|
|
67
|
+
return rule.endsWith(suffix)
|
|
68
|
+
&& (ability.startsWith(rule.slice(0, -2) + suffix[0]) || ability === rule.slice(0, -2))
|
|
69
|
+
}
|
|
70
|
+
|
|
64
71
|
get abilities() {
|
|
65
72
|
return this.#abilities
|
|
66
73
|
}
|