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 CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "rajt",
3
3
  "description": "A serverless bundler layer, fully typed for AWS Lambda (Node.js and LLRT) and Cloudflare Workers.",
4
- "version": "0.0.37",
4
+ "version": "0.0.38",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
7
7
  "exports": {
@@ -32,16 +32,16 @@ export class Ability {
32
32
  return path == '/'
33
33
  ? 'index'
34
34
  : path.normalize('NFD')
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()
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() {
@@ -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 (rule.endsWith('.*')) {
58
- const prefix = rule.slice(0, -2)
59
- return ability.startsWith(`${prefix}.`) || ability === prefix
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
  }