@nauth-toolkit/client 0.1.86 → 0.1.88

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/dist/index.d.mts CHANGED
@@ -100,7 +100,7 @@ interface AuthResponse {
100
100
  challengeName?: AuthChallenge;
101
101
  session?: string;
102
102
  challengeParameters?: Record<string, unknown>;
103
- userSub?: string;
103
+ sub?: string;
104
104
  }
105
105
  /**
106
106
  * Minimal user information returned inside auth responses.
@@ -147,7 +147,6 @@ interface LoginRequest {
147
147
  * Logout request payload.
148
148
  */
149
149
  interface LogoutRequest {
150
- sub?: string;
151
150
  forgetMe?: boolean;
152
151
  }
153
152
  /**
@@ -159,7 +158,6 @@ interface LogoutAllRequest {
159
158
  * Default: false (devices remain trusted)
160
159
  */
161
160
  forgetDevices?: boolean;
162
- sub?: string;
163
161
  }
164
162
  /**
165
163
  * Resend code request payload.
@@ -262,7 +260,7 @@ interface UpdateProfileRequest {
262
260
  * Change password request.
263
261
  */
264
262
  interface ChangePasswordRequest {
265
- currentPassword: string;
263
+ oldPassword: string;
266
264
  newPassword: string;
267
265
  }
268
266
  /**
@@ -296,12 +294,11 @@ interface ConfirmForgotPasswordResponse {
296
294
  mustChangePassword: boolean;
297
295
  }
298
296
  /**
299
- * Reset password with code/token request (generic for both admin-initiated and user-initiated resets).
297
+ * Reset password with code request (generic for both admin-initiated and user-initiated resets).
300
298
  */
301
299
  interface ResetPasswordWithCodeRequest {
302
300
  identifier: string;
303
- code?: string;
304
- token?: string;
301
+ code: string;
305
302
  newPassword: string;
306
303
  }
307
304
  /**
@@ -557,7 +554,6 @@ interface NAuthEndpoints {
557
554
  getChallengeData: string;
558
555
  profile: string;
559
556
  changePassword: string;
560
- requestPasswordChange: string;
561
557
  forgotPassword: string;
562
558
  confirmForgotPassword: string;
563
559
  confirmAdminResetPassword: string;
@@ -568,7 +564,6 @@ interface NAuthEndpoints {
568
564
  mfaRemove: string;
569
565
  mfaPreferred: string;
570
566
  mfaBackupCodes: string;
571
- mfaExemption: string;
572
567
  socialLinked: string;
573
568
  socialLink: string;
574
569
  socialUnlink: string;
@@ -1452,37 +1447,37 @@ declare class NAuthClient {
1452
1447
  */
1453
1448
  confirmForgotPassword(identifier: string, code: string, newPassword: string): Promise<ConfirmForgotPasswordResponse>;
1454
1449
  /**
1455
- * Reset password with code or token (works for both admin-initiated and user-initiated resets).
1450
+ * Reset password with verification code (works for both admin-initiated and user-initiated resets).
1456
1451
  *
1457
- * Accepts either:
1458
- * - code: Short numeric code from email/SMS (6-10 digits)
1459
- * - token: Long hex token from reset link (64 chars)
1452
+ * NOTE:
1453
+ * - Links (when provided by the backend email provider) include the same verification code as a query param
1454
+ * (e.g., `...?code=123456`) so consumer apps stay code-only and consistent.
1460
1455
  *
1461
1456
  * WHY: Generic method that works for both admin-initiated (adminResetPassword) and
1462
1457
  * user-initiated (forgotPassword) password resets. Uses same backend endpoint.
1463
1458
  *
1464
1459
  * @param identifier - User identifier (email, username, phone)
1465
- * @param codeOrToken - Verification code OR token from link (one required)
1460
+ * @param code - Verification code from email/SMS (6-10 digits)
1466
1461
  * @param newPassword - New password
1467
1462
  * @returns Success response
1468
1463
  * @throws {NAuthClientError} When reset fails
1469
1464
  *
1470
1465
  * @example
1471
1466
  * ```typescript
1472
- * // With code from email
1473
1467
  * await client.resetPasswordWithCode('user@example.com', '123456', 'NewPass123!');
1474
- *
1475
- * // With token from link
1476
- * await client.resetPasswordWithCode('user@example.com', '64-char-token', 'NewPass123!');
1477
1468
  * ```
1478
1469
  */
1479
- resetPasswordWithCode(identifier: string, codeOrToken: string, newPassword: string): Promise<ResetPasswordWithCodeResponse>;
1480
- /**
1481
- * Request password change (must change on next login).
1482
- */
1483
- requestPasswordChange(): Promise<void>;
1470
+ resetPasswordWithCode(identifier: string, code: string, newPassword: string): Promise<ResetPasswordWithCodeResponse>;
1484
1471
  /**
1485
- * Get MFA status.
1472
+ * Get MFA status for current user.
1473
+ *
1474
+ * @returns Promise of MFA status
1475
+ *
1476
+ * @example
1477
+ * ```typescript
1478
+ * const status = await this.client.getMfaStatus();
1479
+ * console.log('MFA enabled:', status.enabled);
1480
+ * ```
1486
1481
  */
1487
1482
  getMfaStatus(): Promise<MFAStatus>;
1488
1483
  /**
@@ -1519,9 +1514,10 @@ declare class NAuthClient {
1519
1514
  */
1520
1515
  generateBackupCodes(): Promise<string[]>;
1521
1516
  /**
1522
- * Set MFA exemption (admin/test scenarios).
1517
+ * ============================================================================
1518
+ * Event System
1519
+ * ============================================================================
1523
1520
  */
1524
- setMfaExemption(exempt: boolean, reason?: string): Promise<void>;
1525
1521
  /**
1526
1522
  * Subscribe to authentication events.
1527
1523
  *
@@ -1638,26 +1634,22 @@ declare class NAuthClient {
1638
1634
  trusted: boolean;
1639
1635
  }>;
1640
1636
  /**
1641
- * Get paginated audit history for the current user.
1642
- *
1643
- * Returns authentication and security events with full audit details including:
1644
- * - Event type (login, logout, MFA, etc.)
1645
- * - Event status (success, failure, suspicious)
1646
- * - Device information, location, risk factors
1637
+ * Get authentication audit history for current user.
1647
1638
  *
1648
- * @param params - Query parameters for filtering and pagination
1649
- * @returns Paginated audit history response
1639
+ * @param params - Optional query parameters (page, limit, eventType, etc.)
1640
+ * @returns Paginated audit history
1650
1641
  *
1651
1642
  * @example
1652
1643
  * ```typescript
1653
1644
  * const history = await client.getAuditHistory({
1654
1645
  * page: 1,
1655
1646
  * limit: 20,
1656
- * eventType: 'LOGIN_SUCCESS'
1647
+ * eventTypes: ['LOGIN_SUCCESS'],
1648
+ * eventStatus: ['FAILURE'],
1657
1649
  * });
1658
1650
  * ```
1659
1651
  */
1660
- getAuditHistory(params?: Record<string, string | number | boolean>): Promise<AuditHistoryResponse>;
1652
+ getAuditHistory(params?: Record<string, string | number | boolean | Array<string | number | boolean>>): Promise<AuditHistoryResponse>;
1661
1653
  /**
1662
1654
  * Initialize client by hydrating state from storage.
1663
1655
  * Call this on app startup to restore auth state.
package/dist/index.d.ts CHANGED
@@ -100,7 +100,7 @@ interface AuthResponse {
100
100
  challengeName?: AuthChallenge;
101
101
  session?: string;
102
102
  challengeParameters?: Record<string, unknown>;
103
- userSub?: string;
103
+ sub?: string;
104
104
  }
105
105
  /**
106
106
  * Minimal user information returned inside auth responses.
@@ -147,7 +147,6 @@ interface LoginRequest {
147
147
  * Logout request payload.
148
148
  */
149
149
  interface LogoutRequest {
150
- sub?: string;
151
150
  forgetMe?: boolean;
152
151
  }
153
152
  /**
@@ -159,7 +158,6 @@ interface LogoutAllRequest {
159
158
  * Default: false (devices remain trusted)
160
159
  */
161
160
  forgetDevices?: boolean;
162
- sub?: string;
163
161
  }
164
162
  /**
165
163
  * Resend code request payload.
@@ -262,7 +260,7 @@ interface UpdateProfileRequest {
262
260
  * Change password request.
263
261
  */
264
262
  interface ChangePasswordRequest {
265
- currentPassword: string;
263
+ oldPassword: string;
266
264
  newPassword: string;
267
265
  }
268
266
  /**
@@ -296,12 +294,11 @@ interface ConfirmForgotPasswordResponse {
296
294
  mustChangePassword: boolean;
297
295
  }
298
296
  /**
299
- * Reset password with code/token request (generic for both admin-initiated and user-initiated resets).
297
+ * Reset password with code request (generic for both admin-initiated and user-initiated resets).
300
298
  */
301
299
  interface ResetPasswordWithCodeRequest {
302
300
  identifier: string;
303
- code?: string;
304
- token?: string;
301
+ code: string;
305
302
  newPassword: string;
306
303
  }
307
304
  /**
@@ -557,7 +554,6 @@ interface NAuthEndpoints {
557
554
  getChallengeData: string;
558
555
  profile: string;
559
556
  changePassword: string;
560
- requestPasswordChange: string;
561
557
  forgotPassword: string;
562
558
  confirmForgotPassword: string;
563
559
  confirmAdminResetPassword: string;
@@ -568,7 +564,6 @@ interface NAuthEndpoints {
568
564
  mfaRemove: string;
569
565
  mfaPreferred: string;
570
566
  mfaBackupCodes: string;
571
- mfaExemption: string;
572
567
  socialLinked: string;
573
568
  socialLink: string;
574
569
  socialUnlink: string;
@@ -1452,37 +1447,37 @@ declare class NAuthClient {
1452
1447
  */
1453
1448
  confirmForgotPassword(identifier: string, code: string, newPassword: string): Promise<ConfirmForgotPasswordResponse>;
1454
1449
  /**
1455
- * Reset password with code or token (works for both admin-initiated and user-initiated resets).
1450
+ * Reset password with verification code (works for both admin-initiated and user-initiated resets).
1456
1451
  *
1457
- * Accepts either:
1458
- * - code: Short numeric code from email/SMS (6-10 digits)
1459
- * - token: Long hex token from reset link (64 chars)
1452
+ * NOTE:
1453
+ * - Links (when provided by the backend email provider) include the same verification code as a query param
1454
+ * (e.g., `...?code=123456`) so consumer apps stay code-only and consistent.
1460
1455
  *
1461
1456
  * WHY: Generic method that works for both admin-initiated (adminResetPassword) and
1462
1457
  * user-initiated (forgotPassword) password resets. Uses same backend endpoint.
1463
1458
  *
1464
1459
  * @param identifier - User identifier (email, username, phone)
1465
- * @param codeOrToken - Verification code OR token from link (one required)
1460
+ * @param code - Verification code from email/SMS (6-10 digits)
1466
1461
  * @param newPassword - New password
1467
1462
  * @returns Success response
1468
1463
  * @throws {NAuthClientError} When reset fails
1469
1464
  *
1470
1465
  * @example
1471
1466
  * ```typescript
1472
- * // With code from email
1473
1467
  * await client.resetPasswordWithCode('user@example.com', '123456', 'NewPass123!');
1474
- *
1475
- * // With token from link
1476
- * await client.resetPasswordWithCode('user@example.com', '64-char-token', 'NewPass123!');
1477
1468
  * ```
1478
1469
  */
1479
- resetPasswordWithCode(identifier: string, codeOrToken: string, newPassword: string): Promise<ResetPasswordWithCodeResponse>;
1480
- /**
1481
- * Request password change (must change on next login).
1482
- */
1483
- requestPasswordChange(): Promise<void>;
1470
+ resetPasswordWithCode(identifier: string, code: string, newPassword: string): Promise<ResetPasswordWithCodeResponse>;
1484
1471
  /**
1485
- * Get MFA status.
1472
+ * Get MFA status for current user.
1473
+ *
1474
+ * @returns Promise of MFA status
1475
+ *
1476
+ * @example
1477
+ * ```typescript
1478
+ * const status = await this.client.getMfaStatus();
1479
+ * console.log('MFA enabled:', status.enabled);
1480
+ * ```
1486
1481
  */
1487
1482
  getMfaStatus(): Promise<MFAStatus>;
1488
1483
  /**
@@ -1519,9 +1514,10 @@ declare class NAuthClient {
1519
1514
  */
1520
1515
  generateBackupCodes(): Promise<string[]>;
1521
1516
  /**
1522
- * Set MFA exemption (admin/test scenarios).
1517
+ * ============================================================================
1518
+ * Event System
1519
+ * ============================================================================
1523
1520
  */
1524
- setMfaExemption(exempt: boolean, reason?: string): Promise<void>;
1525
1521
  /**
1526
1522
  * Subscribe to authentication events.
1527
1523
  *
@@ -1638,26 +1634,22 @@ declare class NAuthClient {
1638
1634
  trusted: boolean;
1639
1635
  }>;
1640
1636
  /**
1641
- * Get paginated audit history for the current user.
1642
- *
1643
- * Returns authentication and security events with full audit details including:
1644
- * - Event type (login, logout, MFA, etc.)
1645
- * - Event status (success, failure, suspicious)
1646
- * - Device information, location, risk factors
1637
+ * Get authentication audit history for current user.
1647
1638
  *
1648
- * @param params - Query parameters for filtering and pagination
1649
- * @returns Paginated audit history response
1639
+ * @param params - Optional query parameters (page, limit, eventType, etc.)
1640
+ * @returns Paginated audit history
1650
1641
  *
1651
1642
  * @example
1652
1643
  * ```typescript
1653
1644
  * const history = await client.getAuditHistory({
1654
1645
  * page: 1,
1655
1646
  * limit: 20,
1656
- * eventType: 'LOGIN_SUCCESS'
1647
+ * eventTypes: ['LOGIN_SUCCESS'],
1648
+ * eventStatus: ['FAILURE'],
1657
1649
  * });
1658
1650
  * ```
1659
1651
  */
1660
- getAuditHistory(params?: Record<string, string | number | boolean>): Promise<AuditHistoryResponse>;
1652
+ getAuditHistory(params?: Record<string, string | number | boolean | Array<string | number | boolean>>): Promise<AuditHistoryResponse>;
1661
1653
  /**
1662
1654
  * Initialize client by hydrating state from storage.
1663
1655
  * Call this on app startup to restore auth state.
package/dist/index.mjs CHANGED
@@ -115,7 +115,6 @@ var defaultEndpoints = {
115
115
  getChallengeData: "/challenge/challenge-data",
116
116
  profile: "/profile",
117
117
  changePassword: "/change-password",
118
- requestPasswordChange: "/request-password-change",
119
118
  forgotPassword: "/forgot-password",
120
119
  confirmForgotPassword: "/forgot-password/confirm",
121
120
  confirmAdminResetPassword: "/admin/reset-password/confirm",
@@ -126,7 +125,6 @@ var defaultEndpoints = {
126
125
  mfaRemove: "/mfa/method",
127
126
  mfaPreferred: "/mfa/preferred-method",
128
127
  mfaBackupCodes: "/mfa/backup-codes/generate",
129
- mfaExemption: "/mfa/exemption",
130
128
  socialLinked: "/social/linked",
131
129
  socialLink: "/social/link",
132
130
  socialUnlink: "/social/unlink",
@@ -1026,7 +1024,7 @@ var NAuthClient = class {
1026
1024
  * Change user password.
1027
1025
  */
1028
1026
  async changePassword(oldPassword, newPassword) {
1029
- const payload = { currentPassword: oldPassword, newPassword };
1027
+ const payload = { oldPassword, newPassword };
1030
1028
  await this.post(this.config.endpoints.changePassword, payload, true);
1031
1029
  }
1032
1030
  /**
@@ -1046,35 +1044,30 @@ var NAuthClient = class {
1046
1044
  return result;
1047
1045
  }
1048
1046
  /**
1049
- * Reset password with code or token (works for both admin-initiated and user-initiated resets).
1047
+ * Reset password with verification code (works for both admin-initiated and user-initiated resets).
1050
1048
  *
1051
- * Accepts either:
1052
- * - code: Short numeric code from email/SMS (6-10 digits)
1053
- * - token: Long hex token from reset link (64 chars)
1049
+ * NOTE:
1050
+ * - Links (when provided by the backend email provider) include the same verification code as a query param
1051
+ * (e.g., `...?code=123456`) so consumer apps stay code-only and consistent.
1054
1052
  *
1055
1053
  * WHY: Generic method that works for both admin-initiated (adminResetPassword) and
1056
1054
  * user-initiated (forgotPassword) password resets. Uses same backend endpoint.
1057
1055
  *
1058
1056
  * @param identifier - User identifier (email, username, phone)
1059
- * @param codeOrToken - Verification code OR token from link (one required)
1057
+ * @param code - Verification code from email/SMS (6-10 digits)
1060
1058
  * @param newPassword - New password
1061
1059
  * @returns Success response
1062
1060
  * @throws {NAuthClientError} When reset fails
1063
1061
  *
1064
1062
  * @example
1065
1063
  * ```typescript
1066
- * // With code from email
1067
1064
  * await client.resetPasswordWithCode('user@example.com', '123456', 'NewPass123!');
1068
- *
1069
- * // With token from link
1070
- * await client.resetPasswordWithCode('user@example.com', '64-char-token', 'NewPass123!');
1071
1065
  * ```
1072
1066
  */
1073
- async resetPasswordWithCode(identifier, codeOrToken, newPassword) {
1074
- const isToken = codeOrToken.length > 10;
1067
+ async resetPasswordWithCode(identifier, code, newPassword) {
1075
1068
  const payload = {
1076
1069
  identifier,
1077
- ...isToken ? { token: codeOrToken } : { code: codeOrToken },
1070
+ code,
1078
1071
  newPassword
1079
1072
  };
1080
1073
  const result = await this.post(
@@ -1085,13 +1078,15 @@ var NAuthClient = class {
1085
1078
  return result;
1086
1079
  }
1087
1080
  /**
1088
- * Request password change (must change on next login).
1089
- */
1090
- async requestPasswordChange() {
1091
- await this.post(this.config.endpoints.requestPasswordChange, {}, true);
1092
- }
1093
- /**
1094
- * Get MFA status.
1081
+ * Get MFA status for current user.
1082
+ *
1083
+ * @returns Promise of MFA status
1084
+ *
1085
+ * @example
1086
+ * ```typescript
1087
+ * const status = await this.client.getMfaStatus();
1088
+ * console.log('MFA enabled:', status.enabled);
1089
+ * ```
1095
1090
  */
1096
1091
  async getMfaStatus() {
1097
1092
  return this.get(this.config.endpoints.mfaStatus, true);
@@ -1134,7 +1129,7 @@ var NAuthClient = class {
1134
1129
  * @returns Success message
1135
1130
  */
1136
1131
  async setPreferredMfaMethod(method) {
1137
- return this.post(this.config.endpoints.mfaPreferred, { method }, true);
1132
+ return this.post(this.config.endpoints.mfaPreferred, { methodType: method }, true);
1138
1133
  }
1139
1134
  /**
1140
1135
  * Generate backup codes.
@@ -1144,14 +1139,10 @@ var NAuthClient = class {
1144
1139
  return result.codes;
1145
1140
  }
1146
1141
  /**
1147
- * Set MFA exemption (admin/test scenarios).
1142
+ * ============================================================================
1143
+ * Event System
1144
+ * ============================================================================
1148
1145
  */
1149
- async setMfaExemption(exempt, reason) {
1150
- await this.post(this.config.endpoints.mfaExemption, { exempt, reason }, true);
1151
- }
1152
- // ============================================================================
1153
- // Event System
1154
- // ============================================================================
1155
1146
  /**
1156
1147
  * Subscribe to authentication events.
1157
1148
  *
@@ -1326,28 +1317,33 @@ var NAuthClient = class {
1326
1317
  return this.get(this.config.endpoints.isTrustedDevice, true);
1327
1318
  }
1328
1319
  /**
1329
- * Get paginated audit history for the current user.
1320
+ * Get authentication audit history for current user.
1330
1321
  *
1331
- * Returns authentication and security events with full audit details including:
1332
- * - Event type (login, logout, MFA, etc.)
1333
- * - Event status (success, failure, suspicious)
1334
- * - Device information, location, risk factors
1335
- *
1336
- * @param params - Query parameters for filtering and pagination
1337
- * @returns Paginated audit history response
1322
+ * @param params - Optional query parameters (page, limit, eventType, etc.)
1323
+ * @returns Paginated audit history
1338
1324
  *
1339
1325
  * @example
1340
1326
  * ```typescript
1341
1327
  * const history = await client.getAuditHistory({
1342
1328
  * page: 1,
1343
1329
  * limit: 20,
1344
- * eventType: 'LOGIN_SUCCESS'
1330
+ * eventTypes: ['LOGIN_SUCCESS'],
1331
+ * eventStatus: ['FAILURE'],
1345
1332
  * });
1346
1333
  * ```
1347
1334
  */
1348
1335
  async getAuditHistory(params) {
1349
- const entries = Object.entries(params ?? {}).map(([k, v]) => [k, String(v)]);
1350
- const query = entries.length > 0 ? `?${new URLSearchParams(entries).toString()}` : "";
1336
+ const searchParams = new URLSearchParams();
1337
+ for (const [key, rawValue] of Object.entries(params ?? {})) {
1338
+ if (Array.isArray(rawValue)) {
1339
+ for (const item of rawValue) {
1340
+ searchParams.append(key, String(item));
1341
+ }
1342
+ continue;
1343
+ }
1344
+ searchParams.append(key, String(rawValue));
1345
+ }
1346
+ const query = searchParams.toString() ? `?${searchParams.toString()}` : "";
1351
1347
  const path = `${this.config.endpoints.auditHistory}${query}`;
1352
1348
  return this.get(path, true);
1353
1349
  }