@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.cjs CHANGED
@@ -155,7 +155,6 @@ var defaultEndpoints = {
155
155
  getChallengeData: "/challenge/challenge-data",
156
156
  profile: "/profile",
157
157
  changePassword: "/change-password",
158
- requestPasswordChange: "/request-password-change",
159
158
  forgotPassword: "/forgot-password",
160
159
  confirmForgotPassword: "/forgot-password/confirm",
161
160
  confirmAdminResetPassword: "/admin/reset-password/confirm",
@@ -166,7 +165,6 @@ var defaultEndpoints = {
166
165
  mfaRemove: "/mfa/method",
167
166
  mfaPreferred: "/mfa/preferred-method",
168
167
  mfaBackupCodes: "/mfa/backup-codes/generate",
169
- mfaExemption: "/mfa/exemption",
170
168
  socialLinked: "/social/linked",
171
169
  socialLink: "/social/link",
172
170
  socialUnlink: "/social/unlink",
@@ -1066,7 +1064,7 @@ var NAuthClient = class {
1066
1064
  * Change user password.
1067
1065
  */
1068
1066
  async changePassword(oldPassword, newPassword) {
1069
- const payload = { currentPassword: oldPassword, newPassword };
1067
+ const payload = { oldPassword, newPassword };
1070
1068
  await this.post(this.config.endpoints.changePassword, payload, true);
1071
1069
  }
1072
1070
  /**
@@ -1086,35 +1084,30 @@ var NAuthClient = class {
1086
1084
  return result;
1087
1085
  }
1088
1086
  /**
1089
- * Reset password with code or token (works for both admin-initiated and user-initiated resets).
1087
+ * Reset password with verification code (works for both admin-initiated and user-initiated resets).
1090
1088
  *
1091
- * Accepts either:
1092
- * - code: Short numeric code from email/SMS (6-10 digits)
1093
- * - token: Long hex token from reset link (64 chars)
1089
+ * NOTE:
1090
+ * - Links (when provided by the backend email provider) include the same verification code as a query param
1091
+ * (e.g., `...?code=123456`) so consumer apps stay code-only and consistent.
1094
1092
  *
1095
1093
  * WHY: Generic method that works for both admin-initiated (adminResetPassword) and
1096
1094
  * user-initiated (forgotPassword) password resets. Uses same backend endpoint.
1097
1095
  *
1098
1096
  * @param identifier - User identifier (email, username, phone)
1099
- * @param codeOrToken - Verification code OR token from link (one required)
1097
+ * @param code - Verification code from email/SMS (6-10 digits)
1100
1098
  * @param newPassword - New password
1101
1099
  * @returns Success response
1102
1100
  * @throws {NAuthClientError} When reset fails
1103
1101
  *
1104
1102
  * @example
1105
1103
  * ```typescript
1106
- * // With code from email
1107
1104
  * await client.resetPasswordWithCode('user@example.com', '123456', 'NewPass123!');
1108
- *
1109
- * // With token from link
1110
- * await client.resetPasswordWithCode('user@example.com', '64-char-token', 'NewPass123!');
1111
1105
  * ```
1112
1106
  */
1113
- async resetPasswordWithCode(identifier, codeOrToken, newPassword) {
1114
- const isToken = codeOrToken.length > 10;
1107
+ async resetPasswordWithCode(identifier, code, newPassword) {
1115
1108
  const payload = {
1116
1109
  identifier,
1117
- ...isToken ? { token: codeOrToken } : { code: codeOrToken },
1110
+ code,
1118
1111
  newPassword
1119
1112
  };
1120
1113
  const result = await this.post(
@@ -1125,13 +1118,15 @@ var NAuthClient = class {
1125
1118
  return result;
1126
1119
  }
1127
1120
  /**
1128
- * Request password change (must change on next login).
1129
- */
1130
- async requestPasswordChange() {
1131
- await this.post(this.config.endpoints.requestPasswordChange, {}, true);
1132
- }
1133
- /**
1134
- * Get MFA status.
1121
+ * Get MFA status for current user.
1122
+ *
1123
+ * @returns Promise of MFA status
1124
+ *
1125
+ * @example
1126
+ * ```typescript
1127
+ * const status = await this.client.getMfaStatus();
1128
+ * console.log('MFA enabled:', status.enabled);
1129
+ * ```
1135
1130
  */
1136
1131
  async getMfaStatus() {
1137
1132
  return this.get(this.config.endpoints.mfaStatus, true);
@@ -1174,7 +1169,7 @@ var NAuthClient = class {
1174
1169
  * @returns Success message
1175
1170
  */
1176
1171
  async setPreferredMfaMethod(method) {
1177
- return this.post(this.config.endpoints.mfaPreferred, { method }, true);
1172
+ return this.post(this.config.endpoints.mfaPreferred, { methodType: method }, true);
1178
1173
  }
1179
1174
  /**
1180
1175
  * Generate backup codes.
@@ -1184,14 +1179,10 @@ var NAuthClient = class {
1184
1179
  return result.codes;
1185
1180
  }
1186
1181
  /**
1187
- * Set MFA exemption (admin/test scenarios).
1182
+ * ============================================================================
1183
+ * Event System
1184
+ * ============================================================================
1188
1185
  */
1189
- async setMfaExemption(exempt, reason) {
1190
- await this.post(this.config.endpoints.mfaExemption, { exempt, reason }, true);
1191
- }
1192
- // ============================================================================
1193
- // Event System
1194
- // ============================================================================
1195
1186
  /**
1196
1187
  * Subscribe to authentication events.
1197
1188
  *
@@ -1366,28 +1357,33 @@ var NAuthClient = class {
1366
1357
  return this.get(this.config.endpoints.isTrustedDevice, true);
1367
1358
  }
1368
1359
  /**
1369
- * Get paginated audit history for the current user.
1360
+ * Get authentication audit history for current user.
1370
1361
  *
1371
- * Returns authentication and security events with full audit details including:
1372
- * - Event type (login, logout, MFA, etc.)
1373
- * - Event status (success, failure, suspicious)
1374
- * - Device information, location, risk factors
1375
- *
1376
- * @param params - Query parameters for filtering and pagination
1377
- * @returns Paginated audit history response
1362
+ * @param params - Optional query parameters (page, limit, eventType, etc.)
1363
+ * @returns Paginated audit history
1378
1364
  *
1379
1365
  * @example
1380
1366
  * ```typescript
1381
1367
  * const history = await client.getAuditHistory({
1382
1368
  * page: 1,
1383
1369
  * limit: 20,
1384
- * eventType: 'LOGIN_SUCCESS'
1370
+ * eventTypes: ['LOGIN_SUCCESS'],
1371
+ * eventStatus: ['FAILURE'],
1385
1372
  * });
1386
1373
  * ```
1387
1374
  */
1388
1375
  async getAuditHistory(params) {
1389
- const entries = Object.entries(params ?? {}).map(([k, v]) => [k, String(v)]);
1390
- const query = entries.length > 0 ? `?${new URLSearchParams(entries).toString()}` : "";
1376
+ const searchParams = new URLSearchParams();
1377
+ for (const [key, rawValue] of Object.entries(params ?? {})) {
1378
+ if (Array.isArray(rawValue)) {
1379
+ for (const item of rawValue) {
1380
+ searchParams.append(key, String(item));
1381
+ }
1382
+ continue;
1383
+ }
1384
+ searchParams.append(key, String(rawValue));
1385
+ }
1386
+ const query = searchParams.toString() ? `?${searchParams.toString()}` : "";
1391
1387
  const path = `${this.config.endpoints.auditHistory}${query}`;
1392
1388
  return this.get(path, true);
1393
1389
  }