@mantiq/auth 0.5.15 → 0.5.17

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,6 +1,6 @@
1
1
  {
2
2
  "name": "@mantiq/auth",
3
- "version": "0.5.15",
3
+ "version": "0.5.17",
4
4
  "description": "Session & token auth, guards, providers",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -1,6 +1,14 @@
1
1
  import type { Authenticatable } from './contracts/Authenticatable.ts'
2
2
  import { applyHasApiTokens } from './HasApiTokens.ts'
3
3
 
4
+ /** Minimum interface a base class must have for the mixin to work. */
5
+ interface ModelLike {
6
+ getAttribute(key: string): any
7
+ setAttribute(key: string, value: any): any
8
+ toObject(): Record<string, any>
9
+ getKey(): string | number
10
+ }
11
+
4
12
  // Accept both abstract and concrete constructors
5
13
  type AbstractConstructor<T = any> = abstract new (...args: any[]) => T
6
14
 
@@ -31,14 +39,14 @@ interface TokenMethods {
31
39
  * static override hidden = ['password', 'remember_token']
32
40
  * }
33
41
  */
34
- export function AuthenticatableModel<T extends AbstractConstructor>(Base: T) {
42
+ export function AuthenticatableModel<T extends AbstractConstructor<ModelLike>>(Base: T) {
35
43
  abstract class AuthModel extends Base implements Authenticatable {
36
44
  getAuthIdentifierName(): string { return 'id' }
37
- getAuthIdentifier(): string | number { return (this as any).getAttribute('id') }
45
+ getAuthIdentifier(): string | number { return this.getAttribute('id') }
38
46
  getAuthPasswordName(): string { return 'password' }
39
- getAuthPassword(): string { return (this as any).getAttribute('password') as string }
40
- getRememberToken(): string | null { return ((this as any).getAttribute('remember_token') as string) ?? null }
41
- setRememberToken(token: string | null): void { (this as any).setAttribute('remember_token', token) }
47
+ getAuthPassword(): string { return this.getAttribute('password') as string }
48
+ getRememberToken(): string | null { return (this.getAttribute('remember_token') as string) ?? null }
49
+ setRememberToken(token: string | null): void { this.setAttribute('remember_token', token) }
42
50
  getRememberTokenName(): string { return 'remember_token' }
43
51
 
44
52
  declare createToken: TokenMethods['createToken']
@@ -26,4 +26,18 @@ export interface Authenticatable {
26
26
 
27
27
  /** Return the column name for the remember token (e.g. 'remember_token'). */
28
28
  getRememberTokenName(): string
29
+
30
+ // ── Model methods (available on all Authenticatable models) ──────────
31
+
32
+ /** Get an attribute value by key. */
33
+ getAttribute(key: string): any
34
+
35
+ /** Set an attribute value by key. */
36
+ setAttribute(key: string, value: any): this
37
+
38
+ /** Convert the model to a plain object (respects hidden fields). */
39
+ toObject(): Record<string, any>
40
+
41
+ /** Get the primary key value. */
42
+ getKey(): string | number
29
43
  }