@arkstack/auth 0.12.18 → 0.12.19

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 (2) hide show
  1. package/dist/index.d.ts +51 -50
  2. package/package.json +4 -4
package/dist/index.d.ts CHANGED
@@ -3,6 +3,7 @@ import { Exception } from "@arkstack/common";
3
3
  import { Request, RequestSource, Response, ResponseSource, Session } from "@arkstack/http";
4
4
  import * as _$otpauth from "otpauth";
5
5
  import { Model } from "@arkstack/database";
6
+ import { User as User$1 } from "@app/models/User";
6
7
 
7
8
  //#region src/Contracts/PersonalAccessToken.d.ts
8
9
  declare abstract class PersonalAccessToken extends Model {
@@ -40,17 +41,6 @@ declare class AuthSession extends Session {
40
41
  token(): Promise<PersonalAccessToken | null>;
41
42
  }
42
43
  //#endregion
43
- //#region src/Contracts/User.d.ts
44
- declare abstract class User extends Model {
45
- [key: string]: any;
46
- email: string;
47
- name: string;
48
- password: string;
49
- createdAt: Date;
50
- updatedAt: Date;
51
- protected static table?: string | undefined;
52
- }
53
- //#endregion
54
44
  //#region src/Contracts/AuthContract.d.ts
55
45
  /**
56
46
  * The Auth class provides methods for user authentication, including verifying
@@ -65,20 +55,20 @@ declare abstract class AuthContract {
65
55
  * @param req The HTTP request instance to be set.
66
56
  * @returns The Auth instance itself for method chaining.
67
57
  */
68
- abstract setRequest(req: Request<User> | RequestSource<User>): this;
58
+ abstract setRequest(req: Request<User$1> | RequestSource<User$1>): this;
69
59
  /**
70
60
  * Get the current HTTP request instance being processed, which may contain
71
61
  * user information and other request-specific data relevant to authentication operations.
72
62
  *
73
63
  * @returns The current HTTP request instance or undefined if not set.
74
64
  */
75
- abstract getRequest(): Request<User> | undefined;
65
+ abstract getRequest(): Request<User$1> | undefined;
76
66
  /**
77
67
  * Get the currently authenticated user
78
68
  *
79
69
  * @returns The currently authenticated user or null if not authenticated.
80
70
  */
81
- abstract user(): User | null;
71
+ abstract user(): User$1 | null;
82
72
  /**
83
73
  * Verify user credentials
84
74
  *
@@ -94,7 +84,7 @@ declare abstract class AuthContract {
94
84
  * @param password
95
85
  * @returns
96
86
  */
97
- abstract attempt(email: string, password: string): Promise<User>;
87
+ abstract attempt(email: string, password: string): Promise<User$1>;
98
88
  /**
99
89
  * Login a user and create a personal access token
100
90
  *
@@ -112,7 +102,7 @@ declare abstract class AuthContract {
112
102
  * @param expiresIn
113
103
  * @returns
114
104
  */
115
- abstract createTemporaryToken(user: User, purpose: string, expiresIn?: string): Promise<string>;
105
+ abstract createTemporaryToken(user: User$1, purpose: string, expiresIn?: string): Promise<string>;
116
106
  /**
117
107
  * Authorize a temporary token and return the associated user if the token is
118
108
  * valid and matches the expected purpose.
@@ -121,7 +111,7 @@ declare abstract class AuthContract {
121
111
  * @param purpose
122
112
  * @returns
123
113
  */
124
- abstract authorizeTemporaryToken(token: string, purpose: string): Promise<User>;
114
+ abstract authorizeTemporaryToken(token: string, purpose: string): Promise<User$1>;
125
115
  /**
126
116
  * Logout the currently authenticated user and delete all their personal access tokens
127
117
  *
@@ -147,14 +137,14 @@ declare abstract class AuthContract {
147
137
  * @param user
148
138
  * @returns
149
139
  */
150
- abstract create(user: User): Promise<PersonalAccessToken>;
140
+ abstract create(user: User$1): Promise<PersonalAccessToken>;
151
141
  /**
152
142
  * Authorize a token and return the associated user
153
143
  *
154
144
  * @param token
155
145
  * @returns
156
146
  */
157
- abstract authorizeToken(token: string): Promise<User>;
147
+ abstract authorizeToken(token: string): Promise<User$1>;
158
148
  }
159
149
  //#endregion
160
150
  //#region src/Auth.d.ts
@@ -166,9 +156,9 @@ declare abstract class AuthContract {
166
156
  */
167
157
  declare class Auth extends AuthContract {
168
158
  #private;
169
- protected static req?: Request<User>;
159
+ protected static req?: Request<User$1>;
170
160
  private configuredSecret?;
171
- constructor(secret?: string, req?: Request<User> | RequestSource<User>);
161
+ constructor(secret?: string, req?: Request<User$1> | RequestSource<User$1>);
172
162
  /**
173
163
  * Create a new instance of the Auth class with an optional secret for JWT
174
164
  * signing and verification.
@@ -183,27 +173,27 @@ declare class Auth extends AuthContract {
183
173
  * @param req The HTTP request instance to be set.
184
174
  * @returns The Auth class itself for method chaining.
185
175
  */
186
- static setRequest(req: Request<User> | RequestSource<User>): typeof Auth;
176
+ static setRequest(req: Request<User$1> | RequestSource<User$1>): typeof Auth;
187
177
  /**
188
178
  * Set the current HTTP request instance being processed.
189
179
  *
190
180
  * @param req The HTTP request instance to be set.
191
181
  * @returns The Auth instance itself for method chaining.
192
182
  */
193
- setRequest(req: Request<User> | RequestSource<User>): this;
183
+ setRequest(req: Request<User$1> | RequestSource<User$1>): this;
194
184
  /**
195
185
  * Get the current HTTP request instance being processed, which may contain
196
186
  * user information and other request-specific data relevant to authentication operations.
197
187
  *
198
188
  * @returns The current HTTP request instance or undefined if not set.
199
189
  */
200
- getRequest(): Request<User> | undefined;
190
+ getRequest(): Request<User$1> | undefined;
201
191
  /**
202
192
  * Get the currently authenticated user
203
193
  *
204
194
  * @returns The currently authenticated user or null if not authenticated.
205
195
  */
206
- user(): User | null;
196
+ user(): User$1 | null;
207
197
  /**
208
198
  * Verify user credentials
209
199
  *
@@ -219,7 +209,7 @@ declare class Auth extends AuthContract {
219
209
  * @param password
220
210
  * @returns
221
211
  */
222
- attempt(email: string, password: string): Promise<User>;
212
+ attempt(email: string, password: string): Promise<User$1>;
223
213
  /**
224
214
  * Login a user and create a personal access token
225
215
  *
@@ -237,7 +227,7 @@ declare class Auth extends AuthContract {
237
227
  * @param expiresIn
238
228
  * @returns
239
229
  */
240
- createTemporaryToken(user: User, purpose: string, expiresIn?: string): Promise<string>;
230
+ createTemporaryToken(user: User$1, purpose: string, expiresIn?: string): Promise<string>;
241
231
  /**
242
232
  * Authorize a temporary token and return the associated user if the token is
243
233
  * valid and matches the expected purpose.
@@ -246,7 +236,7 @@ declare class Auth extends AuthContract {
246
236
  * @param purpose
247
237
  * @returns
248
238
  */
249
- authorizeTemporaryToken(token: string, purpose: string): Promise<User>;
239
+ authorizeTemporaryToken(token: string, purpose: string): Promise<User$1>;
250
240
  /**
251
241
  * Logout the currently authenticated user and delete all their personal access tokens
252
242
  *
@@ -272,7 +262,7 @@ declare class Auth extends AuthContract {
272
262
  * @param user
273
263
  * @returns
274
264
  */
275
- create(user: User): Promise<PersonalAccessToken>;
265
+ create(user: User$1): Promise<PersonalAccessToken>;
276
266
  /**
277
267
  * Create or replace the personal access token for the same user and device
278
268
  * while keeping a single active session record for that device.
@@ -288,7 +278,7 @@ declare class Auth extends AuthContract {
288
278
  * @param token
289
279
  * @returns
290
280
  */
291
- authorizeToken(token: string): Promise<User>;
281
+ authorizeToken(token: string): Promise<User$1>;
292
282
  /**
293
283
  * Create a JWT token
294
284
  *
@@ -467,7 +457,7 @@ declare class TwoFactor {
467
457
  * @param user
468
458
  * @returns
469
459
  */
470
- static getLabel(user: User): string;
460
+ static getLabel(user: User$1): string;
471
461
  /**
472
462
  * Create the per-user TOTP instance for setup and verification.
473
463
  *
@@ -475,7 +465,7 @@ declare class TwoFactor {
475
465
  * @param secret
476
466
  * @returns
477
467
  */
478
- static getTotp(user: User, secret: string): _$otpauth.TOTP;
468
+ static getTotp(user: User$1, secret: string): _$otpauth.TOTP;
479
469
  /**
480
470
  * Generate a new shared secret for authenticator-based 2FA.
481
471
  *
@@ -489,7 +479,7 @@ declare class TwoFactor {
489
479
  * @param secret Optional existing secret to use for the setup.
490
480
  * @returns An object containing the secret and the OTPAuth URL.
491
481
  */
492
- static createSetup(user: User, secret?: string): TwoFactorSetup;
482
+ static createSetup(user: User$1, secret?: string): TwoFactorSetup;
493
483
  /**
494
484
  * Verify a 6-digit authenticator code for a user.
495
485
  *
@@ -498,44 +488,44 @@ declare class TwoFactor {
498
488
  * @param code The 6-digit code to verify.
499
489
  * @returns True if the code is valid, false otherwise.
500
490
  */
501
- static verifyCode(user: User, secret: string, code: string): boolean;
502
- static getMethod(userId: User['id']): Promise<TwoFactorMethod | null>;
503
- static setMethod(userId: User['id'], method: TwoFactorMethod): Promise<void>;
491
+ static verifyCode(user: User$1, secret: string, code: string): boolean;
492
+ static getMethod(userId: User$1['id']): Promise<TwoFactorMethod | null>;
493
+ static setMethod(userId: User$1['id'], method: TwoFactorMethod): Promise<void>;
504
494
  /**
505
495
  * Read the setup secret stored for a user.
506
496
  *
507
497
  * @param userId The ID of the user.
508
498
  * @returns The stored secret, or null if not found.
509
499
  */
510
- static getSecret(userId: User['id']): Promise<string | null>;
500
+ static getSecret(userId: User$1['id']): Promise<string | null>;
511
501
  /**
512
502
  * Store the setup secret for a user.
513
503
  *
514
504
  * @param userId The ID of the user.
515
505
  * @param secret The secret to store.
516
506
  */
517
- static setSecret(userId: User['id'], secret: string): Promise<void>;
518
- static clearSecret(userId: User['id']): Promise<void>;
507
+ static setSecret(userId: User$1['id'], secret: string): Promise<void>;
508
+ static clearSecret(userId: User$1['id']): Promise<void>;
519
509
  /**
520
510
  * Read the timestamp indicating whether 2FA is enabled.
521
511
  *
522
512
  * @param userId The ID of the user.
523
513
  * @returns The timestamp when 2FA was enabled, or null if not enabled.
524
514
  */
525
- static getEnabledAt(userId: User['id']): Promise<string | null>;
515
+ static getEnabledAt(userId: User$1['id']): Promise<string | null>;
526
516
  /**
527
517
  * Persist the timestamp marking 2FA as enabled.
528
518
  *
529
519
  * @param userId The ID of the user.
530
520
  * @param enabledAt The timestamp to store.
531
521
  */
532
- static setEnabledAt(userId: User['id'], enabledAt?: string | Date): Promise<void>;
522
+ static setEnabledAt(userId: User$1['id'], enabledAt?: string | Date): Promise<void>;
533
523
  /**
534
524
  * Remove all persisted 2FA state for a user.
535
525
  *
536
526
  * @param userId The ID of the user.
537
527
  */
538
- static clear(userId: User['id']): Promise<void>;
528
+ static clear(userId: User$1['id']): Promise<void>;
539
529
  /**
540
530
  * Generate one-time recovery codes shown when 2FA is enabled.
541
531
  *
@@ -555,14 +545,14 @@ declare class TwoFactor {
555
545
  * @param userId The ID of the user.
556
546
  * @returns An array of recovery-code hashes.
557
547
  */
558
- static readRecoveryCodeHashes(userId: User['id']): Promise<string[]>;
548
+ static readRecoveryCodeHashes(userId: User$1['id']): Promise<string[]>;
559
549
  /**
560
550
  * Persist recovery-code hashes on the user's dedicated 2FA record.
561
551
  *
562
552
  * @param userId
563
553
  * @param hashes
564
554
  */
565
- static writeRecoveryCodeHashes(userId: User['id'], hashes: string[]): Promise<void>;
555
+ static writeRecoveryCodeHashes(userId: User$1['id'], hashes: string[]): Promise<void>;
566
556
  /**
567
557
  * Consume a valid recovery code and invalidate it immediately.
568
558
  *
@@ -570,14 +560,14 @@ declare class TwoFactor {
570
560
  * @param recoveryCode The recovery code to consume.
571
561
  * @returns True if the recovery code was valid and consumed, false otherwise.
572
562
  */
573
- static consumeRecoveryCode(userId: User['id'], recoveryCode: string): Promise<boolean>;
563
+ static consumeRecoveryCode(userId: User$1['id'], recoveryCode: string): Promise<boolean>;
574
564
  /**
575
565
  * Return the public 2FA status payload for a user.
576
566
  *
577
567
  * @param userId The ID of the user.
578
568
  * @returns An object containing the 2FA status and recovery codes remaining.
579
569
  */
580
- static readStatus(userId: User['id']): Promise<TwoFactorStatus>;
570
+ static readStatus(userId: User$1['id']): Promise<TwoFactorStatus>;
581
571
  static createSmsCode(): string;
582
572
  /**
583
573
  * Issue a new SMS code for the given user and send it via SMS for the specified purpose.
@@ -585,8 +575,8 @@ declare class TwoFactor {
585
575
  * @param user
586
576
  * @param purpose
587
577
  */
588
- static issueSmsCode(user: User, purpose: SmsCodePurpose): Promise<IssuedSmsCode>;
589
- static clearSmsCode(userId: User['id']): Promise<void>;
578
+ static issueSmsCode(user: User$1, purpose: SmsCodePurpose): Promise<IssuedSmsCode>;
579
+ static clearSmsCode(userId: User$1['id']): Promise<void>;
590
580
  /**
591
581
  * Verify a submitted SMS code for a user and purpose, consuming the code if valid.
592
582
  *
@@ -595,13 +585,24 @@ declare class TwoFactor {
595
585
  * @param purpose
596
586
  * @returns
597
587
  */
598
- static verifySmsCode(userId: User['id'], code: string, purpose: SmsCodePurpose): Promise<boolean>;
588
+ static verifySmsCode(userId: User$1['id'], code: string, purpose: SmsCodePurpose): Promise<boolean>;
589
+ }
590
+ //#endregion
591
+ //#region src/Contracts/User.d.ts
592
+ declare abstract class User extends Model {
593
+ [key: string]: any;
594
+ email: string;
595
+ name: string;
596
+ password: string;
597
+ createdAt: Date;
598
+ updatedAt: Date;
599
+ protected static table?: string | undefined;
599
600
  }
600
601
  //#endregion
601
602
  //#region src/Contracts/UserTwoFactor.d.ts
602
603
  declare abstract class UserTwoFactor extends Model {
603
604
  [key: string]: any;
604
- userId: User['id'];
605
+ userId: User$1['id'];
605
606
  method: TwoFactorMethod | null;
606
607
  secretCiphertext: string | null;
607
608
  smsCodeHash: string | null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arkstack/auth",
3
- "version": "0.12.18",
3
+ "version": "0.12.19",
4
4
  "type": "module",
5
5
  "description": "Authentication module for Arkstack, providing core authentication and identity features.",
6
6
  "homepage": "https://arkstack.toneflix.net/guide/auth",
@@ -38,12 +38,12 @@
38
38
  "jose": "^6.2.3",
39
39
  "otpauth": "^9.5.1",
40
40
  "ua-parser-js": "^2.0.9",
41
- "@arkstack/common": "^0.12.18",
42
- "@arkstack/http": "^0.12.18"
41
+ "@arkstack/common": "^0.12.19",
42
+ "@arkstack/http": "^0.12.19"
43
43
  },
44
44
  "peerDependencies": {
45
45
  "@h3ravel/support": "^0.15.11",
46
- "@arkstack/database": "^0.12.18"
46
+ "@arkstack/database": "^0.12.19"
47
47
  },
48
48
  "scripts": {
49
49
  "build": "tsdown --config-loader unrun",