@nauth-toolkit/client 0.1.3
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/LICENSE +90 -0
- package/README.md +92 -0
- package/dist/angular/index.cjs +1958 -0
- package/dist/angular/index.cjs.map +1 -0
- package/dist/angular/index.d.mts +623 -0
- package/dist/angular/index.d.ts +623 -0
- package/dist/angular/index.mjs +1926 -0
- package/dist/angular/index.mjs.map +1 -0
- package/dist/index.cjs +1473 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.mts +638 -0
- package/dist/index.d.ts +638 -0
- package/dist/index.mjs +1433 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +62 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,638 @@
|
|
|
1
|
+
type MFADeviceMethod = 'sms' | 'email' | 'totp' | 'passkey';
|
|
2
|
+
type MFAMethod = MFADeviceMethod | 'backup';
|
|
3
|
+
type MFAChallengeMethod = 'passkey' | 'sms' | 'email' | 'totp' | 'backup';
|
|
4
|
+
interface MFAStatus {
|
|
5
|
+
enabled: boolean;
|
|
6
|
+
required: boolean;
|
|
7
|
+
methods: MFADeviceMethod[];
|
|
8
|
+
availableMethods: MFAMethod[];
|
|
9
|
+
hasBackupCodes: boolean;
|
|
10
|
+
preferredMethod?: MFADeviceMethod;
|
|
11
|
+
mfaExempt: boolean;
|
|
12
|
+
mfaExemptReason: string | null;
|
|
13
|
+
mfaExemptGrantedAt: string | Date | null;
|
|
14
|
+
}
|
|
15
|
+
interface MFADevice {
|
|
16
|
+
id: number;
|
|
17
|
+
type: MFADeviceMethod;
|
|
18
|
+
name: string;
|
|
19
|
+
isPrimary: boolean;
|
|
20
|
+
isActive: boolean;
|
|
21
|
+
createdAt: string | Date;
|
|
22
|
+
}
|
|
23
|
+
interface MFASetupData {
|
|
24
|
+
secret?: string;
|
|
25
|
+
qrCode?: string;
|
|
26
|
+
manualEntryKey?: string;
|
|
27
|
+
phone?: string;
|
|
28
|
+
challenge?: Record<string, unknown>;
|
|
29
|
+
[key: string]: unknown;
|
|
30
|
+
}
|
|
31
|
+
interface GetSetupDataResponse {
|
|
32
|
+
setupData: Record<string, unknown>;
|
|
33
|
+
}
|
|
34
|
+
interface GetChallengeDataResponse {
|
|
35
|
+
challengeData: Record<string, unknown>;
|
|
36
|
+
}
|
|
37
|
+
interface BackupCodesResponse {
|
|
38
|
+
codes: string[];
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
declare enum AuthChallenge {
|
|
42
|
+
VERIFY_EMAIL = "VERIFY_EMAIL",
|
|
43
|
+
VERIFY_PHONE = "VERIFY_PHONE",
|
|
44
|
+
MFA_REQUIRED = "MFA_REQUIRED",
|
|
45
|
+
MFA_SETUP_REQUIRED = "MFA_SETUP_REQUIRED",
|
|
46
|
+
FORCE_CHANGE_PASSWORD = "FORCE_CHANGE_PASSWORD"
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
interface AuthResponse {
|
|
50
|
+
user?: AuthUserSummary;
|
|
51
|
+
accessToken?: string;
|
|
52
|
+
refreshToken?: string;
|
|
53
|
+
accessTokenExpiresAt?: number;
|
|
54
|
+
refreshTokenExpiresAt?: number;
|
|
55
|
+
trusted?: boolean;
|
|
56
|
+
deviceToken?: string;
|
|
57
|
+
challengeName?: AuthChallenge;
|
|
58
|
+
session?: string;
|
|
59
|
+
challengeParameters?: Record<string, unknown>;
|
|
60
|
+
userSub?: string;
|
|
61
|
+
}
|
|
62
|
+
interface AuthUserSummary {
|
|
63
|
+
sub: string;
|
|
64
|
+
email: string;
|
|
65
|
+
firstName?: string | null;
|
|
66
|
+
lastName?: string | null;
|
|
67
|
+
phone?: string | null;
|
|
68
|
+
isEmailVerified: boolean;
|
|
69
|
+
isPhoneVerified?: boolean;
|
|
70
|
+
socialProviders?: string[] | null;
|
|
71
|
+
hasPasswordHash?: boolean;
|
|
72
|
+
}
|
|
73
|
+
interface TokenResponse {
|
|
74
|
+
accessToken: string;
|
|
75
|
+
refreshToken: string;
|
|
76
|
+
accessTokenExpiresAt: number;
|
|
77
|
+
refreshTokenExpiresAt: number;
|
|
78
|
+
}
|
|
79
|
+
interface SignupRequest {
|
|
80
|
+
email: string;
|
|
81
|
+
password: string;
|
|
82
|
+
firstName?: string;
|
|
83
|
+
lastName?: string;
|
|
84
|
+
phone?: string;
|
|
85
|
+
}
|
|
86
|
+
interface LoginRequest {
|
|
87
|
+
identifier: string;
|
|
88
|
+
password: string;
|
|
89
|
+
}
|
|
90
|
+
interface LogoutRequest {
|
|
91
|
+
sub?: string;
|
|
92
|
+
forgetMe?: boolean;
|
|
93
|
+
}
|
|
94
|
+
interface LogoutAllRequest {
|
|
95
|
+
forgetDevices?: boolean;
|
|
96
|
+
sub?: string;
|
|
97
|
+
}
|
|
98
|
+
interface ResendCodeRequest {
|
|
99
|
+
session: string;
|
|
100
|
+
}
|
|
101
|
+
interface GetSetupDataRequest {
|
|
102
|
+
session: string;
|
|
103
|
+
method: MFAMethod;
|
|
104
|
+
}
|
|
105
|
+
interface GetChallengeDataRequest {
|
|
106
|
+
session: string;
|
|
107
|
+
method: MFAChallengeMethod;
|
|
108
|
+
}
|
|
109
|
+
type ChallengeResponse = VerifyEmailResponse | VerifyPhoneCollectResponse | VerifyPhoneCodeResponse | MFACodeResponse | MFAPasskeyResponse | MFASetupResponse | ForceChangePasswordResponse;
|
|
110
|
+
interface BaseChallengeResponse {
|
|
111
|
+
session: string;
|
|
112
|
+
}
|
|
113
|
+
interface VerifyEmailResponse extends BaseChallengeResponse {
|
|
114
|
+
type: AuthChallenge.VERIFY_EMAIL;
|
|
115
|
+
code: string;
|
|
116
|
+
}
|
|
117
|
+
interface VerifyPhoneCollectResponse extends BaseChallengeResponse {
|
|
118
|
+
type: AuthChallenge.VERIFY_PHONE;
|
|
119
|
+
phone: string;
|
|
120
|
+
}
|
|
121
|
+
interface VerifyPhoneCodeResponse extends BaseChallengeResponse {
|
|
122
|
+
type: AuthChallenge.VERIFY_PHONE;
|
|
123
|
+
code: string;
|
|
124
|
+
}
|
|
125
|
+
interface MFACodeResponse extends BaseChallengeResponse {
|
|
126
|
+
type: AuthChallenge.MFA_REQUIRED;
|
|
127
|
+
method: MFAMethod;
|
|
128
|
+
code: string;
|
|
129
|
+
}
|
|
130
|
+
interface MFAPasskeyResponse extends BaseChallengeResponse {
|
|
131
|
+
type: AuthChallenge.MFA_REQUIRED;
|
|
132
|
+
method: 'passkey';
|
|
133
|
+
credential: Record<string, unknown>;
|
|
134
|
+
}
|
|
135
|
+
interface MFASetupResponse extends BaseChallengeResponse {
|
|
136
|
+
type: AuthChallenge.MFA_SETUP_REQUIRED;
|
|
137
|
+
method: MFAMethod;
|
|
138
|
+
setupData: Record<string, unknown>;
|
|
139
|
+
}
|
|
140
|
+
interface ForceChangePasswordResponse extends BaseChallengeResponse {
|
|
141
|
+
type: AuthChallenge.FORCE_CHANGE_PASSWORD;
|
|
142
|
+
newPassword: string;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
interface AuthUser {
|
|
146
|
+
sub: string;
|
|
147
|
+
email: string;
|
|
148
|
+
username?: string | null;
|
|
149
|
+
firstName?: string | null;
|
|
150
|
+
lastName?: string | null;
|
|
151
|
+
phone?: string | null;
|
|
152
|
+
isEmailVerified: boolean;
|
|
153
|
+
isPhoneVerified: boolean;
|
|
154
|
+
isActive?: boolean;
|
|
155
|
+
mfaEnabled?: boolean;
|
|
156
|
+
socialProviders?: string[] | null;
|
|
157
|
+
hasPasswordHash: boolean;
|
|
158
|
+
createdAt?: string | Date;
|
|
159
|
+
updatedAt?: string | Date;
|
|
160
|
+
}
|
|
161
|
+
interface UpdateProfileRequest {
|
|
162
|
+
firstName?: string;
|
|
163
|
+
lastName?: string;
|
|
164
|
+
email?: string;
|
|
165
|
+
phone?: string;
|
|
166
|
+
}
|
|
167
|
+
interface ChangePasswordRequest {
|
|
168
|
+
currentPassword: string;
|
|
169
|
+
newPassword: string;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
type SocialProvider = 'google' | 'apple' | 'facebook';
|
|
173
|
+
interface SocialAuthUrlRequest {
|
|
174
|
+
provider: SocialProvider;
|
|
175
|
+
state?: string;
|
|
176
|
+
}
|
|
177
|
+
interface SocialAuthUrlResponse {
|
|
178
|
+
url: string;
|
|
179
|
+
}
|
|
180
|
+
interface SocialCallbackRequest {
|
|
181
|
+
provider: SocialProvider;
|
|
182
|
+
code: string;
|
|
183
|
+
state: string;
|
|
184
|
+
}
|
|
185
|
+
interface LinkedAccountsResponse {
|
|
186
|
+
providers: SocialProvider[];
|
|
187
|
+
}
|
|
188
|
+
interface SocialVerifyRequest {
|
|
189
|
+
provider: SocialProvider;
|
|
190
|
+
idToken?: string;
|
|
191
|
+
accessToken?: string;
|
|
192
|
+
authorizationCode?: string;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
declare enum NAuthErrorCode {
|
|
196
|
+
AUTH_INVALID_CREDENTIALS = "AUTH_INVALID_CREDENTIALS",
|
|
197
|
+
AUTH_ACCOUNT_LOCKED = "AUTH_ACCOUNT_LOCKED",
|
|
198
|
+
AUTH_ACCOUNT_INACTIVE = "AUTH_ACCOUNT_INACTIVE",
|
|
199
|
+
AUTH_TOKEN_EXPIRED = "AUTH_TOKEN_EXPIRED",
|
|
200
|
+
AUTH_TOKEN_INVALID = "AUTH_TOKEN_INVALID",
|
|
201
|
+
AUTH_BEARER_NOT_ALLOWED = "AUTH_BEARER_NOT_ALLOWED",
|
|
202
|
+
AUTH_COOKIES_NOT_ALLOWED = "AUTH_COOKIES_NOT_ALLOWED",
|
|
203
|
+
AUTH_CSRF_TOKEN_INVALID = "AUTH_CSRF_TOKEN_INVALID",
|
|
204
|
+
AUTH_CSRF_TOKEN_MISSING = "AUTH_CSRF_TOKEN_MISSING",
|
|
205
|
+
AUTH_TOKEN_REUSE_DETECTED = "AUTH_TOKEN_REUSE_DETECTED",
|
|
206
|
+
AUTH_SESSION_NOT_FOUND = "AUTH_SESSION_NOT_FOUND",
|
|
207
|
+
AUTH_SESSION_EXPIRED = "AUTH_SESSION_EXPIRED",
|
|
208
|
+
SIGNUP_DISABLED = "SIGNUP_DISABLED",
|
|
209
|
+
SIGNUP_EMAIL_EXISTS = "SIGNUP_EMAIL_EXISTS",
|
|
210
|
+
SIGNUP_USERNAME_EXISTS = "SIGNUP_USERNAME_EXISTS",
|
|
211
|
+
SIGNUP_PHONE_EXISTS = "SIGNUP_PHONE_EXISTS",
|
|
212
|
+
SIGNUP_WEAK_PASSWORD = "SIGNUP_WEAK_PASSWORD",
|
|
213
|
+
SIGNUP_PHONE_REQUIRED = "SIGNUP_PHONE_REQUIRED",
|
|
214
|
+
SIGNUP_NOT_ALLOWED = "SIGNUP_NOT_ALLOWED",
|
|
215
|
+
VERIFY_CODE_INVALID = "VERIFY_CODE_INVALID",
|
|
216
|
+
VERIFY_CODE_EXPIRED = "VERIFY_CODE_EXPIRED",
|
|
217
|
+
VERIFY_TOO_MANY_ATTEMPTS = "VERIFY_TOO_MANY_ATTEMPTS",
|
|
218
|
+
VERIFY_ALREADY_VERIFIED = "VERIFY_ALREADY_VERIFIED",
|
|
219
|
+
MFA_SETUP_REQUIRED = "MFA_SETUP_REQUIRED",
|
|
220
|
+
RATE_LIMIT_SMS = "RATE_LIMIT_SMS",
|
|
221
|
+
RATE_LIMIT_EMAIL = "RATE_LIMIT_EMAIL",
|
|
222
|
+
RATE_LIMIT_LOGIN = "RATE_LIMIT_LOGIN",
|
|
223
|
+
RATE_LIMIT_RESEND = "RATE_LIMIT_RESEND",
|
|
224
|
+
SOCIAL_TOKEN_INVALID = "SOCIAL_TOKEN_INVALID",
|
|
225
|
+
SOCIAL_ACCOUNT_LINKED = "SOCIAL_ACCOUNT_LINKED",
|
|
226
|
+
SOCIAL_CONFIG_MISSING = "SOCIAL_CONFIG_MISSING",
|
|
227
|
+
SOCIAL_EMAIL_REQUIRED = "SOCIAL_EMAIL_REQUIRED",
|
|
228
|
+
SOCIAL_ACCOUNT_NOT_FOUND = "SOCIAL_ACCOUNT_NOT_FOUND",
|
|
229
|
+
CHALLENGE_EXPIRED = "CHALLENGE_EXPIRED",
|
|
230
|
+
CHALLENGE_INVALID = "CHALLENGE_INVALID",
|
|
231
|
+
CHALLENGE_TYPE_MISMATCH = "CHALLENGE_TYPE_MISMATCH",
|
|
232
|
+
CHALLENGE_MAX_ATTEMPTS = "CHALLENGE_MAX_ATTEMPTS",
|
|
233
|
+
CHALLENGE_ALREADY_COMPLETED = "CHALLENGE_ALREADY_COMPLETED",
|
|
234
|
+
VALIDATION_FAILED = "VALIDATION_FAILED",
|
|
235
|
+
VALIDATION_INVALID_PHONE = "VALIDATION_INVALID_PHONE",
|
|
236
|
+
VALIDATION_INVALID_EMAIL = "VALIDATION_INVALID_EMAIL",
|
|
237
|
+
VALIDATION_INVALID_PASSWORD = "VALIDATION_INVALID_PASSWORD",
|
|
238
|
+
PASSWORD_INCORRECT = "PASSWORD_INCORRECT",
|
|
239
|
+
PASSWORD_REUSED = "PASSWORD_REUSED",
|
|
240
|
+
PASSWORD_CHANGE_NOT_ALLOWED = "PASSWORD_CHANGE_NOT_ALLOWED",
|
|
241
|
+
SIGNIN_BLOCKED_HIGH_RISK = "SIGNIN_BLOCKED_HIGH_RISK",
|
|
242
|
+
RESOURCE_NOT_FOUND = "RESOURCE_NOT_FOUND",
|
|
243
|
+
FORBIDDEN = "FORBIDDEN",
|
|
244
|
+
INTERNAL_ERROR = "INTERNAL_ERROR",
|
|
245
|
+
SERVICE_UNAVAILABLE = "SERVICE_UNAVAILABLE"
|
|
246
|
+
}
|
|
247
|
+
interface NAuthError {
|
|
248
|
+
code: NAuthErrorCode;
|
|
249
|
+
message: string;
|
|
250
|
+
details?: Record<string, unknown>;
|
|
251
|
+
timestamp?: string;
|
|
252
|
+
statusCode?: number;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
interface NAuthStorageAdapter {
|
|
256
|
+
getItem(key: string): Promise<string | null>;
|
|
257
|
+
setItem(key: string, value: string): Promise<void>;
|
|
258
|
+
removeItem(key: string): Promise<void>;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
interface HttpRequest {
|
|
262
|
+
method: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
|
|
263
|
+
url: string;
|
|
264
|
+
headers?: Record<string, string>;
|
|
265
|
+
body?: unknown;
|
|
266
|
+
credentials?: 'include' | 'omit' | 'same-origin';
|
|
267
|
+
signal?: AbortSignal;
|
|
268
|
+
}
|
|
269
|
+
interface HttpResponse<T> {
|
|
270
|
+
data: T;
|
|
271
|
+
status: number;
|
|
272
|
+
headers: Record<string, string>;
|
|
273
|
+
}
|
|
274
|
+
interface HttpAdapter {
|
|
275
|
+
request<T>(config: HttpRequest): Promise<HttpResponse<T>>;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
type TokenDeliveryMode = 'json' | 'cookies';
|
|
279
|
+
interface NAuthEndpoints {
|
|
280
|
+
login: string;
|
|
281
|
+
signup: string;
|
|
282
|
+
logout: string;
|
|
283
|
+
logoutAll: string;
|
|
284
|
+
refresh: string;
|
|
285
|
+
respondChallenge: string;
|
|
286
|
+
resendCode: string;
|
|
287
|
+
getSetupData: string;
|
|
288
|
+
getChallengeData: string;
|
|
289
|
+
profile: string;
|
|
290
|
+
changePassword: string;
|
|
291
|
+
requestPasswordChange: string;
|
|
292
|
+
mfaStatus: string;
|
|
293
|
+
mfaDevices: string;
|
|
294
|
+
mfaSetupData: string;
|
|
295
|
+
mfaVerifySetup: string;
|
|
296
|
+
mfaRemove: string;
|
|
297
|
+
mfaPreferred: string;
|
|
298
|
+
mfaBackupCodes: string;
|
|
299
|
+
mfaExemption: string;
|
|
300
|
+
socialAuthUrl: string;
|
|
301
|
+
socialCallback: string;
|
|
302
|
+
socialLinked: string;
|
|
303
|
+
socialLink: string;
|
|
304
|
+
socialUnlink: string;
|
|
305
|
+
socialVerify: string;
|
|
306
|
+
trustDevice: string;
|
|
307
|
+
isTrustedDevice: string;
|
|
308
|
+
auditHistory: string;
|
|
309
|
+
updateProfile: string;
|
|
310
|
+
}
|
|
311
|
+
interface NAuthClientConfig {
|
|
312
|
+
baseUrl: string;
|
|
313
|
+
tokenDelivery: TokenDeliveryMode;
|
|
314
|
+
storage?: NAuthStorageAdapter;
|
|
315
|
+
csrf?: {
|
|
316
|
+
cookieName?: string;
|
|
317
|
+
headerName?: string;
|
|
318
|
+
};
|
|
319
|
+
endpoints?: Partial<NAuthEndpoints>;
|
|
320
|
+
deviceTrust?: {
|
|
321
|
+
headerName?: string;
|
|
322
|
+
storageKey?: string;
|
|
323
|
+
};
|
|
324
|
+
headers?: Record<string, string>;
|
|
325
|
+
timeout?: number;
|
|
326
|
+
redirects?: {
|
|
327
|
+
success?: string;
|
|
328
|
+
sessionExpired?: string;
|
|
329
|
+
oauthError?: string;
|
|
330
|
+
challengeBase?: string;
|
|
331
|
+
};
|
|
332
|
+
onSessionExpired?: () => void;
|
|
333
|
+
onTokenRefresh?: () => void;
|
|
334
|
+
onAuthStateChange?: (user: AuthUser | null) => void;
|
|
335
|
+
onError?: (error: NAuthError) => void;
|
|
336
|
+
debug?: boolean;
|
|
337
|
+
httpAdapter?: HttpAdapter;
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
declare enum AuthAuditEventType {
|
|
341
|
+
LOGIN_SUCCESS = "LOGIN_SUCCESS",
|
|
342
|
+
LOGIN_FAILED = "LOGIN_FAILED",
|
|
343
|
+
LOGOUT = "LOGOUT",
|
|
344
|
+
TOKEN_REFRESH = "TOKEN_REFRESH",
|
|
345
|
+
TOKEN_REVOKED = "TOKEN_REVOKED",
|
|
346
|
+
SIGNUP_SUCCESS = "SIGNUP_SUCCESS",
|
|
347
|
+
SIGNUP_FAILED = "SIGNUP_FAILED",
|
|
348
|
+
EMAIL_VERIFIED = "EMAIL_VERIFIED",
|
|
349
|
+
PHONE_VERIFIED = "PHONE_VERIFIED",
|
|
350
|
+
VERIFICATION_FAILED = "VERIFICATION_FAILED",
|
|
351
|
+
MFA_ENABLED = "MFA_ENABLED",
|
|
352
|
+
MFA_DISABLED = "MFA_DISABLED",
|
|
353
|
+
MFA_VERIFIED = "MFA_VERIFIED",
|
|
354
|
+
MFA_FAILED = "MFA_FAILED",
|
|
355
|
+
MFA_BACKUP_CODE_USED = "MFA_BACKUP_CODE_USED",
|
|
356
|
+
PASSWORD_CHANGED = "PASSWORD_CHANGED",
|
|
357
|
+
PASSWORD_RESET_REQUESTED = "PASSWORD_RESET_REQUESTED",
|
|
358
|
+
PASSWORD_RESET_COMPLETED = "PASSWORD_RESET_COMPLETED",
|
|
359
|
+
ACCOUNT_LOCKED = "ACCOUNT_LOCKED",
|
|
360
|
+
ACCOUNT_UNLOCKED = "ACCOUNT_UNLOCKED",
|
|
361
|
+
SUSPICIOUS_ACTIVITY = "SUSPICIOUS_ACTIVITY",
|
|
362
|
+
ADAPTIVE_MFA_TRIGGERED = "ADAPTIVE_MFA_TRIGGERED",
|
|
363
|
+
SOCIAL_LINK_SUCCESS = "SOCIAL_LINK_SUCCESS",
|
|
364
|
+
SOCIAL_LINK_FAILED = "SOCIAL_LINK_FAILED",
|
|
365
|
+
SOCIAL_UNLINK = "SOCIAL_UNLINK"
|
|
366
|
+
}
|
|
367
|
+
type AuthAuditEventStatus = 'SUCCESS' | 'FAILURE' | 'INFO' | 'SUSPICIOUS';
|
|
368
|
+
interface AuthAuditEvent {
|
|
369
|
+
id: number;
|
|
370
|
+
userId: number;
|
|
371
|
+
eventType: AuthAuditEventType;
|
|
372
|
+
eventStatus: AuthAuditEventStatus;
|
|
373
|
+
riskFactor?: number | null;
|
|
374
|
+
riskFactors?: string[] | null;
|
|
375
|
+
adaptiveMfaTriggered?: boolean | null;
|
|
376
|
+
ipAddress?: string | null;
|
|
377
|
+
ipCountry?: string | null;
|
|
378
|
+
ipCity?: string | null;
|
|
379
|
+
ipLatitude?: number | null;
|
|
380
|
+
ipLongitude?: number | null;
|
|
381
|
+
userAgent?: string | null;
|
|
382
|
+
platform?: string | null;
|
|
383
|
+
browser?: string | null;
|
|
384
|
+
deviceId?: string | null;
|
|
385
|
+
deviceName?: string | null;
|
|
386
|
+
deviceType?: string | null;
|
|
387
|
+
sessionId?: number | null;
|
|
388
|
+
challengeSessionId?: number | null;
|
|
389
|
+
authMethod?: string | null;
|
|
390
|
+
performedBy?: string | null;
|
|
391
|
+
reason?: string | null;
|
|
392
|
+
description?: string | null;
|
|
393
|
+
metadata?: Record<string, unknown> | null;
|
|
394
|
+
createdAt: string | Date;
|
|
395
|
+
}
|
|
396
|
+
interface AuditHistoryResponse {
|
|
397
|
+
data: AuthAuditEvent[];
|
|
398
|
+
total: number;
|
|
399
|
+
page: number;
|
|
400
|
+
limit: number;
|
|
401
|
+
totalPages: number;
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
declare class NAuthClientError extends Error implements NAuthError {
|
|
405
|
+
readonly code: NAuthErrorCode;
|
|
406
|
+
readonly details?: Record<string, unknown>;
|
|
407
|
+
readonly statusCode?: number;
|
|
408
|
+
readonly timestamp: string;
|
|
409
|
+
readonly isNetworkError: boolean;
|
|
410
|
+
constructor(code: NAuthErrorCode, message: string, options?: {
|
|
411
|
+
details?: Record<string, unknown>;
|
|
412
|
+
statusCode?: number;
|
|
413
|
+
timestamp?: string;
|
|
414
|
+
isNetworkError?: boolean;
|
|
415
|
+
});
|
|
416
|
+
isCode(code: NAuthErrorCode): boolean;
|
|
417
|
+
getDetails(): Record<string, unknown> | undefined;
|
|
418
|
+
getCode(): NAuthErrorCode;
|
|
419
|
+
toJSON(): {
|
|
420
|
+
code: string;
|
|
421
|
+
message: string;
|
|
422
|
+
timestamp: string;
|
|
423
|
+
details?: Record<string, unknown>;
|
|
424
|
+
statusCode?: number;
|
|
425
|
+
};
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
type AuthEventType = 'auth:login' | 'auth:signup' | 'auth:success' | 'auth:challenge' | 'auth:error' | 'auth:logout' | 'auth:refresh' | 'oauth:started' | 'oauth:callback' | 'oauth:completed' | 'oauth:error';
|
|
429
|
+
type AuthEvent = AuthLoginEvent | AuthSignupEvent | AuthSuccessEvent | AuthChallengeEvent | AuthErrorEvent | AuthLogoutEvent | AuthRefreshEvent | OAuthStartedEvent | OAuthCallbackEvent | OAuthCompletedEvent | OAuthErrorEvent;
|
|
430
|
+
interface AuthLoginEvent {
|
|
431
|
+
type: 'auth:login';
|
|
432
|
+
data: {
|
|
433
|
+
identifier: string;
|
|
434
|
+
};
|
|
435
|
+
timestamp: number;
|
|
436
|
+
}
|
|
437
|
+
interface AuthSignupEvent {
|
|
438
|
+
type: 'auth:signup';
|
|
439
|
+
data: {
|
|
440
|
+
email: string;
|
|
441
|
+
};
|
|
442
|
+
timestamp: number;
|
|
443
|
+
}
|
|
444
|
+
interface AuthSuccessEvent {
|
|
445
|
+
type: 'auth:success';
|
|
446
|
+
data: AuthResponse;
|
|
447
|
+
timestamp: number;
|
|
448
|
+
}
|
|
449
|
+
interface AuthChallengeEvent {
|
|
450
|
+
type: 'auth:challenge';
|
|
451
|
+
data: AuthResponse;
|
|
452
|
+
timestamp: number;
|
|
453
|
+
}
|
|
454
|
+
interface AuthErrorEvent {
|
|
455
|
+
type: 'auth:error';
|
|
456
|
+
data: NAuthClientError;
|
|
457
|
+
timestamp: number;
|
|
458
|
+
}
|
|
459
|
+
interface AuthLogoutEvent {
|
|
460
|
+
type: 'auth:logout';
|
|
461
|
+
data: {
|
|
462
|
+
forgetDevice?: boolean;
|
|
463
|
+
global?: boolean;
|
|
464
|
+
};
|
|
465
|
+
timestamp: number;
|
|
466
|
+
}
|
|
467
|
+
interface AuthRefreshEvent {
|
|
468
|
+
type: 'auth:refresh';
|
|
469
|
+
data: {
|
|
470
|
+
success: boolean;
|
|
471
|
+
};
|
|
472
|
+
timestamp: number;
|
|
473
|
+
}
|
|
474
|
+
interface OAuthStartedEvent {
|
|
475
|
+
type: 'oauth:started';
|
|
476
|
+
data: {
|
|
477
|
+
provider: string;
|
|
478
|
+
};
|
|
479
|
+
timestamp: number;
|
|
480
|
+
}
|
|
481
|
+
interface OAuthCallbackEvent {
|
|
482
|
+
type: 'oauth:callback';
|
|
483
|
+
data: {
|
|
484
|
+
provider: string;
|
|
485
|
+
};
|
|
486
|
+
timestamp: number;
|
|
487
|
+
}
|
|
488
|
+
interface OAuthCompletedEvent {
|
|
489
|
+
type: 'oauth:completed';
|
|
490
|
+
data: AuthResponse;
|
|
491
|
+
timestamp: number;
|
|
492
|
+
}
|
|
493
|
+
interface OAuthErrorEvent {
|
|
494
|
+
type: 'oauth:error';
|
|
495
|
+
data: NAuthClientError;
|
|
496
|
+
timestamp: number;
|
|
497
|
+
}
|
|
498
|
+
type AuthEventListener = (event: AuthEvent) => void;
|
|
499
|
+
declare class EventEmitter {
|
|
500
|
+
private listeners;
|
|
501
|
+
on(event: AuthEventType | '*', listener: AuthEventListener): () => void;
|
|
502
|
+
off(event: AuthEventType | '*', listener: AuthEventListener): void;
|
|
503
|
+
emit(event: AuthEvent): void;
|
|
504
|
+
clear(): void;
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
declare class NAuthClient {
|
|
508
|
+
private readonly config;
|
|
509
|
+
private readonly tokenManager;
|
|
510
|
+
private readonly eventEmitter;
|
|
511
|
+
private currentUser;
|
|
512
|
+
constructor(userConfig: NAuthClientConfig);
|
|
513
|
+
dispose(): void;
|
|
514
|
+
login(identifier: string, password: string): Promise<AuthResponse>;
|
|
515
|
+
signup(payload: SignupRequest): Promise<AuthResponse>;
|
|
516
|
+
refreshTokens(): Promise<TokenResponse>;
|
|
517
|
+
logout(forgetDevice?: boolean): Promise<void>;
|
|
518
|
+
logoutAll(forgetDevices?: boolean): Promise<{
|
|
519
|
+
revokedCount: number;
|
|
520
|
+
}>;
|
|
521
|
+
respondToChallenge(response: ChallengeResponse): Promise<AuthResponse>;
|
|
522
|
+
resendCode(session: string): Promise<{
|
|
523
|
+
destination: string;
|
|
524
|
+
}>;
|
|
525
|
+
getSetupData(session: string, method: GetSetupDataRequest['method']): Promise<GetSetupDataResponse>;
|
|
526
|
+
getChallengeData(session: string, method: GetChallengeDataRequest['method']): Promise<GetChallengeDataResponse>;
|
|
527
|
+
getProfile(): Promise<AuthUser>;
|
|
528
|
+
updateProfile(updates: UpdateProfileRequest): Promise<AuthUser>;
|
|
529
|
+
changePassword(oldPassword: string, newPassword: string): Promise<void>;
|
|
530
|
+
requestPasswordChange(): Promise<void>;
|
|
531
|
+
getMfaStatus(): Promise<MFAStatus>;
|
|
532
|
+
getMfaDevices(): Promise<unknown[]>;
|
|
533
|
+
setupMfaDevice(method: string): Promise<unknown>;
|
|
534
|
+
verifyMfaSetup(method: string, setupData: Record<string, unknown>, deviceName?: string): Promise<{
|
|
535
|
+
deviceId: number;
|
|
536
|
+
}>;
|
|
537
|
+
removeMfaDevice(method: string): Promise<{
|
|
538
|
+
message: string;
|
|
539
|
+
}>;
|
|
540
|
+
setPreferredMfaMethod(method: 'totp' | 'sms' | 'email' | 'passkey'): Promise<{
|
|
541
|
+
message: string;
|
|
542
|
+
}>;
|
|
543
|
+
generateBackupCodes(): Promise<string[]>;
|
|
544
|
+
setMfaExemption(exempt: boolean, reason?: string): Promise<void>;
|
|
545
|
+
on(event: AuthEventType | '*', listener: AuthEventListener): () => void;
|
|
546
|
+
off(event: AuthEventType | '*', listener: AuthEventListener): void;
|
|
547
|
+
loginWithSocial(provider: SocialProvider, _options?: {
|
|
548
|
+
redirectUri?: string;
|
|
549
|
+
}): Promise<void>;
|
|
550
|
+
handleOAuthCallback(urlOrParams?: string | URLSearchParams): Promise<AuthResponse | null>;
|
|
551
|
+
getSocialAuthUrl(request: SocialAuthUrlRequest): Promise<{
|
|
552
|
+
url: string;
|
|
553
|
+
}>;
|
|
554
|
+
handleSocialCallback(request: SocialCallbackRequest): Promise<AuthResponse>;
|
|
555
|
+
verifyNativeSocial(request: SocialVerifyRequest): Promise<AuthResponse>;
|
|
556
|
+
getLinkedAccounts(): Promise<LinkedAccountsResponse>;
|
|
557
|
+
linkSocialAccount(provider: string, code: string, state: string): Promise<{
|
|
558
|
+
message: string;
|
|
559
|
+
}>;
|
|
560
|
+
unlinkSocialAccount(provider: string): Promise<{
|
|
561
|
+
message: string;
|
|
562
|
+
}>;
|
|
563
|
+
trustDevice(): Promise<{
|
|
564
|
+
deviceToken: string;
|
|
565
|
+
}>;
|
|
566
|
+
isTrustedDevice(): Promise<{
|
|
567
|
+
trusted: boolean;
|
|
568
|
+
}>;
|
|
569
|
+
getAuditHistory(params?: Record<string, string | number | boolean>): Promise<AuditHistoryResponse>;
|
|
570
|
+
initialize(): Promise<void>;
|
|
571
|
+
isAuthenticated(): Promise<boolean>;
|
|
572
|
+
isAuthenticatedSync(): boolean;
|
|
573
|
+
getAccessToken(): Promise<string | null>;
|
|
574
|
+
getCurrentUser(): AuthUser | null;
|
|
575
|
+
getStoredChallenge(): Promise<AuthResponse | null>;
|
|
576
|
+
clearStoredChallenge(): Promise<void>;
|
|
577
|
+
private handleAuthResponse;
|
|
578
|
+
private persistChallenge;
|
|
579
|
+
private clearChallenge;
|
|
580
|
+
private setUser;
|
|
581
|
+
private clearAuthState;
|
|
582
|
+
private setDeviceToken;
|
|
583
|
+
private getTokenDeliveryMode;
|
|
584
|
+
private buildUrl;
|
|
585
|
+
private buildHeaders;
|
|
586
|
+
private getCsrfToken;
|
|
587
|
+
private get;
|
|
588
|
+
private post;
|
|
589
|
+
private put;
|
|
590
|
+
private delete;
|
|
591
|
+
private readonly handleStorageEvent;
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
type ResolvedNAuthClientConfig = Omit<NAuthClientConfig, 'endpoints' | 'storage' | 'tokenDelivery' | 'httpAdapter'> & {
|
|
595
|
+
tokenDelivery: TokenDeliveryMode;
|
|
596
|
+
endpoints: NAuthEndpoints;
|
|
597
|
+
storage: NAuthStorageAdapter;
|
|
598
|
+
httpAdapter: HttpAdapter;
|
|
599
|
+
csrf: {
|
|
600
|
+
cookieName: string;
|
|
601
|
+
headerName: string;
|
|
602
|
+
};
|
|
603
|
+
deviceTrust: {
|
|
604
|
+
headerName: string;
|
|
605
|
+
storageKey: string;
|
|
606
|
+
};
|
|
607
|
+
headers: Record<string, string>;
|
|
608
|
+
timeout: number;
|
|
609
|
+
};
|
|
610
|
+
declare const defaultEndpoints: NAuthEndpoints;
|
|
611
|
+
declare const resolveConfig: (config: NAuthClientConfig, defaultAdapter: HttpAdapter) => ResolvedNAuthClientConfig;
|
|
612
|
+
|
|
613
|
+
declare function requiresPhoneCollection(challenge: AuthResponse): boolean;
|
|
614
|
+
declare function getMaskedDestination(challenge: AuthResponse): string | null;
|
|
615
|
+
declare function getMFAMethod(challenge: AuthResponse): MFAMethod | undefined;
|
|
616
|
+
declare function getChallengeInstructions(challenge: AuthResponse): string | undefined;
|
|
617
|
+
declare function isOTPChallenge(challenge: AuthResponse): boolean;
|
|
618
|
+
|
|
619
|
+
declare class BrowserStorage implements NAuthStorageAdapter {
|
|
620
|
+
private readonly storage;
|
|
621
|
+
constructor(storage?: Storage);
|
|
622
|
+
getItem(key: string): Promise<string | null>;
|
|
623
|
+
setItem(key: string, value: string): Promise<void>;
|
|
624
|
+
removeItem(key: string): Promise<void>;
|
|
625
|
+
}
|
|
626
|
+
|
|
627
|
+
declare class InMemoryStorage implements NAuthStorageAdapter {
|
|
628
|
+
private readonly store;
|
|
629
|
+
getItem(key: string): Promise<string | null>;
|
|
630
|
+
setItem(key: string, value: string): Promise<void>;
|
|
631
|
+
removeItem(key: string): Promise<void>;
|
|
632
|
+
}
|
|
633
|
+
|
|
634
|
+
declare class FetchAdapter implements HttpAdapter {
|
|
635
|
+
request<T>(config: HttpRequest): Promise<HttpResponse<T>>;
|
|
636
|
+
}
|
|
637
|
+
|
|
638
|
+
export { type AuditHistoryResponse, type AuthAuditEvent, type AuthAuditEventStatus, AuthAuditEventType, AuthChallenge, type AuthChallengeEvent, type AuthErrorEvent, type AuthEvent, type AuthEventListener, type AuthEventType, type AuthLoginEvent, type AuthLogoutEvent, type AuthRefreshEvent, type AuthResponse, type AuthSignupEvent, type AuthSuccessEvent, type AuthUser, type AuthUserSummary, type BackupCodesResponse, type BaseChallengeResponse, BrowserStorage, type ChallengeResponse, type ChangePasswordRequest, EventEmitter, FetchAdapter, type ForceChangePasswordResponse, type GetChallengeDataRequest, type GetChallengeDataResponse, type GetSetupDataRequest, type GetSetupDataResponse, type HttpAdapter, type HttpRequest, type HttpResponse, InMemoryStorage, type LinkedAccountsResponse, type LoginRequest, type LogoutAllRequest, type LogoutRequest, type MFAChallengeMethod, type MFACodeResponse, type MFADevice, type MFADeviceMethod, type MFAMethod, type MFAPasskeyResponse, type MFASetupData, type MFASetupResponse, type MFAStatus, NAuthClient, type NAuthClientConfig, NAuthClientError, type NAuthEndpoints, type NAuthError, NAuthErrorCode, type NAuthStorageAdapter, type OAuthCallbackEvent, type OAuthCompletedEvent, type OAuthErrorEvent, type OAuthStartedEvent, type ResendCodeRequest, type ResolvedNAuthClientConfig, type SignupRequest, type SocialAuthUrlRequest, type SocialAuthUrlResponse, type SocialCallbackRequest, type SocialProvider, type SocialVerifyRequest, type TokenDeliveryMode, type TokenResponse, type UpdateProfileRequest, type VerifyEmailResponse, type VerifyPhoneCodeResponse, type VerifyPhoneCollectResponse, defaultEndpoints, getChallengeInstructions, getMFAMethod, getMaskedDestination, isOTPChallenge, requiresPhoneCollection, resolveConfig };
|