@absolutejs/auth 0.57.9 → 0.58.0

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.
@@ -312,6 +312,15 @@
312
312
  "@absolutejs/auth#memory"
313
313
  ],
314
314
  "required": true
315
+ },
316
+ "verificationProvider": {
317
+ "configPath": "verificationProvider",
318
+ "contract": "auth/verification-provider",
319
+ "description": "Provider-managed phone verification for MFA and future passwordless flows",
320
+ "known": [
321
+ "@absolutejs/auth-twilio"
322
+ ],
323
+ "required": false
315
324
  }
316
325
  },
317
326
  "wiring": [
@@ -1,6 +1,6 @@
1
1
  import { Elysia } from 'elysia';
2
2
  import { type MfaRouteProps } from './config';
3
- export declare const mfaChallenge: <UserType>({ authSessionStore, challengeRoute, cookieSecure, encryptionKey, getChallengeUser, getUserId, mfaStore, onMfaChallengeError, onMfaChallengeSuccess, onSendSmsCode, sessionDurationMs, smsCodeLength, smsCodeTtlMs, smsMaxAttempts, totpMaxAttempts }: MfaRouteProps<UserType>) => Elysia<"", {
3
+ export declare const mfaChallenge: <UserType>({ authSessionStore, challengeRoute, cookieSecure, encryptionKey, getChallengeUser, getUserId, mfaStore, onMfaChallengeError, onMfaChallengeSuccess, onSendSmsCode, verificationProvider, sessionDurationMs, smsCodeLength, smsCodeTtlMs, smsMaxAttempts, smsResendCooldownMs, totpMaxAttempts }: MfaRouteProps<UserType>) => Elysia<"", {
4
4
  decorator: {};
5
5
  store: {
6
6
  session: import("..").SessionRecord<UserType>;
@@ -30,7 +30,7 @@ export declare const mfaChallenge: <UserType>({ authSessionStore, challengeRoute
30
30
  query: unknown;
31
31
  headers: unknown;
32
32
  response: {
33
- 400: "SMS code required" | "No SMS code in progress";
33
+ 400: string;
34
34
  401: "SMS code expired" | "Too many attempts" | "No MFA challenge in progress" | "Invalid MFA code";
35
35
  200: {
36
36
  readonly status: "sent";
@@ -46,6 +46,8 @@ export declare const mfaChallenge: <UserType>({ authSessionStore, challengeRoute
46
46
  property?: string;
47
47
  expected?: string;
48
48
  };
49
+ 429: string;
50
+ 503: string;
49
51
  };
50
52
  };
51
53
  };
@@ -7,11 +7,14 @@ export declare const DEFAULT_MFA_SESSION_TTL_MS: number;
7
7
  export declare const DEFAULT_SMS_CODE_LENGTH = 6;
8
8
  export declare const DEFAULT_SMS_CODE_TTL_MS: number;
9
9
  export declare const DEFAULT_SMS_MAX_ATTEMPTS = 3;
10
+ export declare const DEFAULT_SMS_RESEND_COOLDOWN_MS: number;
10
11
  export declare const DEFAULT_TOTP_MAX_ATTEMPTS = 5;
11
12
  export type SmsCodeMessage = {
12
13
  code: string;
13
14
  expiresAt: number;
14
15
  phone: string;
16
+ purpose: 'mfa_challenge' | 'mfa_enrollment';
17
+ userId: string;
15
18
  };
16
19
  export type MfaConfig<UserType> = {
17
20
  mfaStore: MFAStore;
@@ -38,6 +41,8 @@ export type MfaConfig<UserType> = {
38
41
  smsCodeLength?: number;
39
42
  smsCodeTtlMs?: number;
40
43
  smsMaxAttempts?: number;
44
+ /** Minimum delay between code sends for the same enrollment. */
45
+ smsResendCooldownMs?: number;
41
46
  smsSetupRoute?: RouteString;
42
47
  smsVerifyRoute?: RouteString;
43
48
  totpMaxAttempts?: number;
@@ -47,4 +52,5 @@ export type MfaConfig<UserType> = {
47
52
  export type MfaRouteProps<UserType> = MfaConfig<UserType> & {
48
53
  authSessionStore?: AuthSessionStore<UserType>;
49
54
  cookieSecure?: boolean;
55
+ verificationProvider?: import('../verification/types').VerificationProvider;
50
56
  };
@@ -49,6 +49,21 @@ export declare const mfaEnrollmentsTable: import("drizzle-orm/pg-core").PgTableW
49
49
  identity: undefined;
50
50
  generated: undefined;
51
51
  }>;
52
+ sms_code_sent_at_ms: import("drizzle-orm/pg-core").PgBuildColumn<"auth_mfa_enrollments", import("drizzle-orm/pg-core").PgBigInt53Builder, {
53
+ name: string;
54
+ tableName: "auth_mfa_enrollments";
55
+ dataType: "number int53";
56
+ data: number;
57
+ driverParam: string | number;
58
+ notNull: false;
59
+ hasDefault: false;
60
+ isPrimaryKey: false;
61
+ isAutoincrement: false;
62
+ hasRuntimeDefault: false;
63
+ enumValues: undefined;
64
+ identity: undefined;
65
+ generated: undefined;
66
+ }>;
52
67
  sms_failed_attempts: import("drizzle-orm/pg-core").PgBuildColumn<"auth_mfa_enrollments", import("drizzle-orm/pg-core").SetHasDefault<import("drizzle-orm/pg-core").SetNotNull<import("drizzle-orm/pg-core").PgSmallIntBuilder>>, {
53
68
  name: string;
54
69
  tableName: "auth_mfa_enrollments";
@@ -94,6 +109,21 @@ export declare const mfaEnrollmentsTable: import("drizzle-orm/pg-core").PgTableW
94
109
  identity: undefined;
95
110
  generated: undefined;
96
111
  }>;
112
+ sms_pending_purpose: import("drizzle-orm/pg-core").PgBuildColumn<"auth_mfa_enrollments", import("drizzle-orm/pg-core").Set$Type<import("drizzle-orm/pg-core").PgTextBuilder<[string, ...string[]]>, import("..").VerificationPurpose | undefined>, {
113
+ name: string;
114
+ tableName: "auth_mfa_enrollments";
115
+ dataType: "string";
116
+ data: import("..").VerificationPurpose | undefined;
117
+ driverParam: string;
118
+ notNull: false;
119
+ hasDefault: false;
120
+ isPrimaryKey: false;
121
+ isAutoincrement: false;
122
+ hasRuntimeDefault: false;
123
+ enumValues: undefined;
124
+ identity: undefined;
125
+ generated: undefined;
126
+ }>;
97
127
  sms_phone: import("drizzle-orm/pg-core").PgBuildColumn<"auth_mfa_enrollments", import("drizzle-orm/pg-core").PgVarcharBuilder<[string, ...string[]]>, {
98
128
  name: string;
99
129
  tableName: "auth_mfa_enrollments";
@@ -109,6 +139,21 @@ export declare const mfaEnrollmentsTable: import("drizzle-orm/pg-core").PgTableW
109
139
  identity: undefined;
110
140
  generated: undefined;
111
141
  }>;
142
+ sms_provider_reference: import("drizzle-orm/pg-core").PgBuildColumn<"auth_mfa_enrollments", import("drizzle-orm/pg-core").PgTextBuilder<[string, ...string[]]>, {
143
+ name: string;
144
+ tableName: "auth_mfa_enrollments";
145
+ dataType: "string";
146
+ data: string;
147
+ driverParam: string;
148
+ notNull: false;
149
+ hasDefault: false;
150
+ isPrimaryKey: false;
151
+ isAutoincrement: false;
152
+ hasRuntimeDefault: false;
153
+ enumValues: undefined;
154
+ identity: undefined;
155
+ generated: undefined;
156
+ }>;
112
157
  sms_verified: import("drizzle-orm/pg-core").PgBuildColumn<"auth_mfa_enrollments", import("drizzle-orm/pg-core").SetHasDefault<import("drizzle-orm/pg-core").SetNotNull<import("drizzle-orm/pg-core").PgBooleanBuilder>>, {
113
158
  name: string;
114
159
  tableName: "auth_mfa_enrollments";
@@ -136,7 +136,7 @@ export declare const mfaRoutes: <UserType>(config: MfaRouteProps<UserType>) => E
136
136
  query: unknown;
137
137
  headers: unknown;
138
138
  response: {
139
- 400: "Phone must be in E.164 format";
139
+ 400: string;
140
140
  401: "Authentication required";
141
141
  501: "SMS MFA is not configured";
142
142
  200: {
@@ -151,6 +151,8 @@ export declare const mfaRoutes: <UserType>(config: MfaRouteProps<UserType>) => E
151
151
  property?: string;
152
152
  expected?: string;
153
153
  };
154
+ 429: string;
155
+ 503: string;
154
156
  };
155
157
  };
156
158
  };
@@ -164,7 +166,7 @@ export declare const mfaRoutes: <UserType>(config: MfaRouteProps<UserType>) => E
164
166
  query: unknown;
165
167
  headers: unknown;
166
168
  response: {
167
- 400: "No SMS enrollment in progress" | "SMS code expired" | "Invalid SMS code";
169
+ 400: string;
168
170
  401: "Authentication required";
169
171
  200: {
170
172
  readonly status: "enrolled";
@@ -178,7 +180,8 @@ export declare const mfaRoutes: <UserType>(config: MfaRouteProps<UserType>) => E
178
180
  property?: string;
179
181
  expected?: string;
180
182
  };
181
- 429: "Too many attempts";
183
+ 429: string;
184
+ 503: string;
182
185
  };
183
186
  };
184
187
  };
@@ -194,7 +197,7 @@ export declare const mfaRoutes: <UserType>(config: MfaRouteProps<UserType>) => E
194
197
  query: unknown;
195
198
  headers: unknown;
196
199
  response: {
197
- 400: "SMS code required" | "No SMS code in progress";
200
+ 400: string;
198
201
  401: "SMS code expired" | "Too many attempts" | "No MFA challenge in progress" | "Invalid MFA code";
199
202
  200: {
200
203
  readonly status: "sent";
@@ -210,6 +213,8 @@ export declare const mfaRoutes: <UserType>(config: MfaRouteProps<UserType>) => E
210
213
  property?: string;
211
214
  expected?: string;
212
215
  };
216
+ 429: string;
217
+ 503: string;
213
218
  };
214
219
  };
215
220
  };
package/dist/mfa/sms.d.ts CHANGED
@@ -1,16 +1,46 @@
1
1
  import { Elysia } from 'elysia';
2
+ import { type VerificationCheckInput, type VerificationProvider } from '../verification/types';
2
3
  import { type MfaRouteProps, type SmsCodeMessage } from './config';
3
4
  import type { MfaEnrollment, MFAStore } from './types';
5
+ export declare const checkWithVerificationProvider: (provider: VerificationProvider, input: VerificationCheckInput) => Promise<{
6
+ result: import("..").VerificationCheckResult;
7
+ readonly error?: undefined;
8
+ } | {
9
+ error: {
10
+ message: string;
11
+ status: "Too Many Requests";
12
+ } | {
13
+ message: string;
14
+ status: "Bad Request";
15
+ } | {
16
+ message: string;
17
+ status: "Service Unavailable";
18
+ };
19
+ result?: undefined;
20
+ }>;
4
21
  export declare const isE164Phone: (phone: string) => boolean;
5
- export declare const issueAndStoreSmsCode: ({ codeLength, enrollment, mfaStore, onSendSmsCode, ttlMs }: {
22
+ export declare const issueAndStoreSmsCode: ({ codeLength, enrollment, mfaStore, onSendSmsCode, purpose, verificationProvider, ttlMs, userId }: {
6
23
  codeLength: number;
7
24
  enrollment: MfaEnrollment;
8
25
  mfaStore: MFAStore;
9
26
  onSendSmsCode?: (message: SmsCodeMessage) => void | Promise<void>;
27
+ verificationProvider?: MfaRouteProps<unknown>["verificationProvider"];
28
+ userId: string;
29
+ purpose: "mfa_challenge" | "mfa_enrollment";
10
30
  ttlMs: number;
11
31
  }) => Promise<number | undefined>;
32
+ export declare const mapVerificationProviderError: (error: unknown) => {
33
+ message: string;
34
+ status: "Too Many Requests";
35
+ } | {
36
+ message: string;
37
+ status: "Bad Request";
38
+ } | {
39
+ message: string;
40
+ status: "Service Unavailable";
41
+ } | undefined;
12
42
  export declare const maskPhone: (phone: string) => string;
13
- export declare const mfaSmsRoutes: <UserType>({ authSessionStore, getUserId, mfaStore, onMfaEnrolled, onSendSmsCode, smsCodeLength, smsCodeTtlMs, smsMaxAttempts, smsSetupRoute, smsVerifyRoute }: MfaRouteProps<UserType>) => Elysia<"", {
43
+ export declare const mfaSmsRoutes: <UserType>({ authSessionStore, getUserId, mfaStore, onMfaEnrolled, onSendSmsCode, verificationProvider, smsCodeLength, smsCodeTtlMs, smsMaxAttempts, smsResendCooldownMs, smsSetupRoute, smsVerifyRoute }: MfaRouteProps<UserType>) => Elysia<"", {
14
44
  decorator: {};
15
45
  store: {
16
46
  session: import("..").SessionRecord<UserType>;
@@ -38,7 +68,7 @@ export declare const mfaSmsRoutes: <UserType>({ authSessionStore, getUserId, mfa
38
68
  query: unknown;
39
69
  headers: unknown;
40
70
  response: {
41
- 400: "Phone must be in E.164 format";
71
+ 400: string;
42
72
  401: "Authentication required";
43
73
  501: "SMS MFA is not configured";
44
74
  200: {
@@ -53,6 +83,8 @@ export declare const mfaSmsRoutes: <UserType>({ authSessionStore, getUserId, mfa
53
83
  property?: string;
54
84
  expected?: string;
55
85
  };
86
+ 429: string;
87
+ 503: string;
56
88
  };
57
89
  };
58
90
  };
@@ -66,7 +98,7 @@ export declare const mfaSmsRoutes: <UserType>({ authSessionStore, getUserId, mfa
66
98
  query: unknown;
67
99
  headers: unknown;
68
100
  response: {
69
- 400: "No SMS enrollment in progress" | "SMS code expired" | "Invalid SMS code";
101
+ 400: string;
70
102
  401: "Authentication required";
71
103
  200: {
72
104
  readonly status: "enrolled";
@@ -80,7 +112,8 @@ export declare const mfaSmsRoutes: <UserType>({ authSessionStore, getUserId, mfa
80
112
  property?: string;
81
113
  expected?: string;
82
114
  };
83
- 429: "Too many attempts";
115
+ 429: string;
116
+ 503: string;
84
117
  };
85
118
  };
86
119
  };
@@ -1,3 +1,4 @@
1
+ import type { VerificationPurpose } from '../verification/types';
1
2
  export type MfaFactorType = 'backup_codes' | 'sms' | 'totp';
2
3
  export type MfaEnrollment = {
3
4
  backupCodeHashes: string[];
@@ -6,6 +7,9 @@ export type MfaEnrollment = {
6
7
  smsFailedAttempts?: number;
7
8
  smsPendingCodeHash?: string;
8
9
  smsPendingCodeExpiresAt?: number;
10
+ smsPendingPurpose?: VerificationPurpose;
11
+ smsProviderReference?: string;
12
+ smsCodeSentAt?: number;
9
13
  smsPhone?: string;
10
14
  smsVerified: boolean;
11
15
  totpFailedAttempts?: number;
package/dist/server.d.ts CHANGED
@@ -18,6 +18,7 @@ export type { ScimConfig } from './scim/config';
18
18
  export type { ScimFilter, ScimGroup, ScimGroupInput, ScimTokenStore, ScimUser, ScimUserInput } from './scim/types';
19
19
  export { createPostgresScimTokenStore } from './scim/postgresScimTokenStore';
20
20
  export type { AuthSessionStore } from './session/types';
21
+ export { VerificationProviderError, type VerificationCheckInput, type VerificationCheckResult, type VerificationCheckStatus, type VerificationProvider, type VerificationProviderErrorKind, type VerificationPurpose, type VerificationStartInput, type VerificationStartResult } from './verification/types';
21
22
  export type { NodeSamlAdapterOptions } from './sso/nodeSamlAdapter';
22
23
  export { createNodeSamlAdapter } from './sso/nodeSamlAdapter';
23
24
  export type { SsoIdentity, SSOConfig } from './sso/config';