@c9up/warden 0.1.20 → 0.1.22

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.
Files changed (46) hide show
  1. package/dist/AuthManager.d.ts +0 -3
  2. package/dist/AuthManager.d.ts.map +1 -1
  3. package/dist/AuthManager.js +21 -21
  4. package/dist/AuthManager.js.map +1 -1
  5. package/dist/AuthRateLimiter.d.ts +1 -6
  6. package/dist/AuthRateLimiter.d.ts.map +1 -1
  7. package/dist/AuthRateLimiter.js +31 -31
  8. package/dist/AuthRateLimiter.js.map +1 -1
  9. package/dist/RefreshTokenStore.d.ts +1 -1
  10. package/dist/RefreshTokenStore.d.ts.map +1 -1
  11. package/dist/RefreshTokenStore.js +9 -9
  12. package/dist/RefreshTokenStore.js.map +1 -1
  13. package/dist/TokenBlacklist.d.ts +1 -1
  14. package/dist/TokenBlacklist.d.ts.map +1 -1
  15. package/dist/TokenBlacklist.js +6 -6
  16. package/dist/TokenBlacklist.js.map +1 -1
  17. package/dist/augmentations.d.ts +0 -1
  18. package/dist/augmentations.d.ts.map +1 -1
  19. package/dist/bouncer/AuthorizationResponse.d.ts +6 -0
  20. package/dist/bouncer/AuthorizationResponse.d.ts.map +1 -1
  21. package/dist/bouncer/AuthorizationResponse.js +6 -0
  22. package/dist/bouncer/AuthorizationResponse.js.map +1 -1
  23. package/dist/native/generated.d.ts +8 -0
  24. package/dist/native/generated.d.ts.map +1 -0
  25. package/dist/native/generated.js +7 -0
  26. package/dist/native/generated.js.map +1 -0
  27. package/dist/native.d.ts +8 -9
  28. package/dist/native.d.ts.map +1 -1
  29. package/dist/native.js.map +1 -1
  30. package/dist/rights/MemoryRightsStore.d.ts +1 -6
  31. package/dist/rights/MemoryRightsStore.d.ts.map +1 -1
  32. package/dist/rights/MemoryRightsStore.js +10 -10
  33. package/dist/rights/MemoryRightsStore.js.map +1 -1
  34. package/index.win32-x64-msvc.node +0 -0
  35. package/package.json +3 -2
  36. package/scripts/build-napi-types.mjs +68 -0
  37. package/scripts/generate-napi-types.mjs +153 -0
  38. package/src/AuthManager.ts +21 -21
  39. package/src/AuthRateLimiter.ts +29 -29
  40. package/src/RefreshTokenStore.ts +9 -9
  41. package/src/TokenBlacklist.ts +6 -6
  42. package/src/augmentations.ts +0 -2
  43. package/src/bouncer/AuthorizationResponse.ts +6 -0
  44. package/src/native/generated.ts +23 -0
  45. package/src/native.ts +8 -9
  46. package/src/rights/MemoryRightsStore.ts +10 -10
@@ -15,6 +15,12 @@ export class AuthorizationResponse {
15
15
  /** i18n binding set via {@link t} (Adonis `AuthorizationResponse.t`). */
16
16
  translation?: { identifier: string; data?: Record<string, unknown> };
17
17
 
18
+ /**
19
+ * Private because a response is only ever built through allow() / deny(), so the pair stays consistent.
20
+ *
21
+ * `private` and not `#`: a private CONSTRUCTOR has no native form. It is the
22
+ * one place the keyword expresses something `#` cannot.
23
+ */
18
24
  private constructor(authorized: boolean, message?: string, status?: number) {
19
25
  this.authorized = authorized;
20
26
  this.message = message;
@@ -0,0 +1,23 @@
1
+ // GENERATED FROM THE RUST — do not edit.
2
+ //
3
+ // Produced by scripts/generate-napi-types.mjs from napi-derive's type-def
4
+ // output. Editing this file by hand puts it back where it started: a
5
+ // description that can disagree with the code it describes.
6
+
7
+ export declare function jwtSign(payload: string, secret: string): string;
8
+
9
+ export declare function jwtVerify(token: string, secret: string): string;
10
+
11
+ export declare function constantTimeEq(a: string, b: string): boolean;
12
+
13
+ export declare function hmacSign(data: string, secret: string): string;
14
+
15
+ export declare function hmacVerify(
16
+ data: string,
17
+ signature: string,
18
+ secret: string,
19
+ ): boolean;
20
+
21
+ export declare function randomBytes(len: number): string;
22
+
23
+ export declare function randomHex(len: number): string;
package/src/native.ts CHANGED
@@ -21,15 +21,14 @@ const platformMap: Record<string, string> = {
21
21
  "win32-x64": "win32-x64-msvc",
22
22
  };
23
23
 
24
- export interface NativeWarden {
25
- jwtSign(payload: string, secret: string): string;
26
- jwtVerify(token: string, secret: string): string;
27
- constantTimeEq(a: string, b: string): boolean;
28
- hmacSign(data: string, secret: string): string;
29
- hmacVerify(data: string, signature: string, secret: string): boolean;
30
- randomBytes(len: number): string;
31
- randomHex(len: number): string;
32
- }
24
+ /**
25
+ * The engine's surface, as the Rust declares it.
26
+ *
27
+ * Derived from `./native/generated.js` — written by `pnpm build:napi-types`
28
+ * from napi-derive's own `type-def` output — rather than restated here, where
29
+ * nothing would notice a `pub fn` gaining a parameter or changing its return.
30
+ */
31
+ export type NativeWarden = typeof import("./native/generated.js");
33
32
 
34
33
  let native: NativeWarden | undefined;
35
34
 
@@ -15,11 +15,11 @@ import { type RightsStore, type Scope, scopeKey } from "./types.js";
15
15
 
16
16
  export class MemoryRightsStore implements RightsStore {
17
17
  /** scopeKey → role → permissions */
18
- private readonly roleDefs = new Map<string, Map<string, Set<string>>>();
18
+ readonly #roleDefs = new Map<string, Map<string, Set<string>>>();
19
19
  /** scopeKey → userId → roles */
20
- private readonly userRoleMap = new Map<string, Map<string, Set<string>>>();
20
+ readonly #userRoleMap = new Map<string, Map<string, Set<string>>>();
21
21
  /** scopeKey → userId → directly granted permissions */
22
- private readonly userGrantMap = new Map<string, Map<string, Set<string>>>();
22
+ readonly #userGrantMap = new Map<string, Map<string, Set<string>>>();
23
23
 
24
24
  // — read contract —
25
25
 
@@ -27,15 +27,15 @@ export class MemoryRightsStore implements RightsStore {
27
27
  role: string,
28
28
  scope: Scope,
29
29
  ): Promise<readonly string[]> {
30
- return snapshot(this.roleDefs.get(scopeKey(scope))?.get(role));
30
+ return snapshot(this.#roleDefs.get(scopeKey(scope))?.get(role));
31
31
  }
32
32
 
33
33
  async userRoles(userId: string, scope: Scope): Promise<readonly string[]> {
34
- return snapshot(this.userRoleMap.get(scopeKey(scope))?.get(userId));
34
+ return snapshot(this.#userRoleMap.get(scopeKey(scope))?.get(userId));
35
35
  }
36
36
 
37
37
  async userGrants(userId: string, scope: Scope): Promise<readonly string[]> {
38
- return snapshot(this.userGrantMap.get(scopeKey(scope))?.get(userId));
38
+ return snapshot(this.#userGrantMap.get(scopeKey(scope))?.get(userId));
39
39
  }
40
40
 
41
41
  // — seeding (in-memory driver only; not part of RightsStore) —
@@ -45,24 +45,24 @@ export class MemoryRightsStore implements RightsStore {
45
45
  permissions: readonly string[],
46
46
  scope: Scope = "global",
47
47
  ): this {
48
- const set = bucket(this.roleDefs, scopeKey(scope), role);
48
+ const set = bucket(this.#roleDefs, scopeKey(scope), role);
49
49
  set.clear();
50
50
  for (const perm of permissions) set.add(perm);
51
51
  return this;
52
52
  }
53
53
 
54
54
  assignRole(userId: string, role: string, scope: Scope = "global"): this {
55
- bucket(this.userRoleMap, scopeKey(scope), userId).add(role);
55
+ bucket(this.#userRoleMap, scopeKey(scope), userId).add(role);
56
56
  return this;
57
57
  }
58
58
 
59
59
  grant(userId: string, permission: string, scope: Scope = "global"): this {
60
- bucket(this.userGrantMap, scopeKey(scope), userId).add(permission);
60
+ bucket(this.#userGrantMap, scopeKey(scope), userId).add(permission);
61
61
  return this;
62
62
  }
63
63
 
64
64
  revoke(userId: string, permission: string, scope: Scope = "global"): this {
65
- this.userGrantMap.get(scopeKey(scope))?.get(userId)?.delete(permission);
65
+ this.#userGrantMap.get(scopeKey(scope))?.get(userId)?.delete(permission);
66
66
  return this;
67
67
  }
68
68
  }