@nauth-toolkit/client 0.8.1 → 0.8.2

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
@@ -239,6 +239,13 @@ interface ResendCodeRequest {
239
239
  interface GetSetupDataRequest {
240
240
  session: string;
241
241
  method: MFAMethod;
242
+ /**
243
+ * Optional method-specific setup input.
244
+ * SMS: `{ phoneNumber?: string, deviceName?: string }` — `phoneNumber` (E.164) is required when the
245
+ * account has no phone (challenge has `requiresPhoneCollection: 'true'`); a different number replaces
246
+ * the phone on file. Omit to resend to the phone on file.
247
+ */
248
+ setupData?: Record<string, unknown>;
242
249
  }
243
250
  /**
244
251
  * Challenge data request payload (e.g., passkey options).
@@ -3782,19 +3789,30 @@ declare class NAuthClient {
3782
3789
  destination: string;
3783
3790
  }>;
3784
3791
  /**
3785
- * Get setup data for MFA.
3792
+ * Get setup data for MFA during an `MFA_SETUP_REQUIRED` challenge.
3786
3793
  *
3787
3794
  * Returns method-specific setup information:
3788
3795
  * - TOTP: { secret, qrCode, manualEntryKey }
3789
- * - SMS: { maskedPhone }
3790
- * - Email: { maskedEmail }
3796
+ * - SMS: { maskedPhone } (code sent) or { deviceId, autoCompleted: true }
3797
+ * - Email: { maskedEmail } or { deviceId, autoCompleted: true }
3791
3798
  * - Passkey: WebAuthn registration options
3792
3799
  *
3800
+ * For SMS, pass `{ phoneNumber }` (E.164) when the challenge has `requiresPhoneCollection: 'true'`
3801
+ * (see `requiresPhoneCollection()`): the number is saved to the account and verified by the code.
3802
+ * Call again with a different `phoneNumber` to change it, or without `setupData` to resend.
3803
+ *
3793
3804
  * @param session - Challenge session token
3794
3805
  * @param method - MFA method to set up
3806
+ * @param setupData - Optional method-specific input (SMS: `{ phoneNumber?, deviceName? }`)
3795
3807
  * @returns Setup data wrapped in GetSetupDataResponse
3808
+ *
3809
+ * @example
3810
+ * ```typescript
3811
+ * const { setupData } = await client.getSetupData(session, 'sms', { phoneNumber: '+14155552671' });
3812
+ * // setupData: { maskedPhone: '+1***2671' }
3813
+ * ```
3796
3814
  */
3797
- getSetupData(session: string, method: GetSetupDataRequest['method']): Promise<GetSetupDataResponse>;
3815
+ getSetupData(session: string, method: GetSetupDataRequest['method'], setupData?: Record<string, unknown>): Promise<GetSetupDataResponse>;
3798
3816
  /**
3799
3817
  * Get challenge data (e.g., WebAuthn options).
3800
3818
  *
@@ -4392,6 +4410,11 @@ declare class NAuthClient {
4392
4410
  /**
4393
4411
  * Check if a challenge requires phone collection (user has no phone number).
4394
4412
  *
4413
+ * True for `VERIFY_PHONE` when the account has no phone (submit `phone` via
4414
+ * `respondToChallenge()` first), and for `MFA_SETUP_REQUIRED` when SMS is an allowed
4415
+ * method and the account has no phone (pass `{ phoneNumber }` as the third argument of
4416
+ * `getSetupData(session, 'sms', ...)` when the user picks SMS).
4417
+ *
4395
4418
  * @param challenge - Auth response with challenge
4396
4419
  * @returns True if phone collection is required
4397
4420
  *
package/dist/index.d.ts CHANGED
@@ -239,6 +239,13 @@ interface ResendCodeRequest {
239
239
  interface GetSetupDataRequest {
240
240
  session: string;
241
241
  method: MFAMethod;
242
+ /**
243
+ * Optional method-specific setup input.
244
+ * SMS: `{ phoneNumber?: string, deviceName?: string }` — `phoneNumber` (E.164) is required when the
245
+ * account has no phone (challenge has `requiresPhoneCollection: 'true'`); a different number replaces
246
+ * the phone on file. Omit to resend to the phone on file.
247
+ */
248
+ setupData?: Record<string, unknown>;
242
249
  }
243
250
  /**
244
251
  * Challenge data request payload (e.g., passkey options).
@@ -3782,19 +3789,30 @@ declare class NAuthClient {
3782
3789
  destination: string;
3783
3790
  }>;
3784
3791
  /**
3785
- * Get setup data for MFA.
3792
+ * Get setup data for MFA during an `MFA_SETUP_REQUIRED` challenge.
3786
3793
  *
3787
3794
  * Returns method-specific setup information:
3788
3795
  * - TOTP: { secret, qrCode, manualEntryKey }
3789
- * - SMS: { maskedPhone }
3790
- * - Email: { maskedEmail }
3796
+ * - SMS: { maskedPhone } (code sent) or { deviceId, autoCompleted: true }
3797
+ * - Email: { maskedEmail } or { deviceId, autoCompleted: true }
3791
3798
  * - Passkey: WebAuthn registration options
3792
3799
  *
3800
+ * For SMS, pass `{ phoneNumber }` (E.164) when the challenge has `requiresPhoneCollection: 'true'`
3801
+ * (see `requiresPhoneCollection()`): the number is saved to the account and verified by the code.
3802
+ * Call again with a different `phoneNumber` to change it, or without `setupData` to resend.
3803
+ *
3793
3804
  * @param session - Challenge session token
3794
3805
  * @param method - MFA method to set up
3806
+ * @param setupData - Optional method-specific input (SMS: `{ phoneNumber?, deviceName? }`)
3795
3807
  * @returns Setup data wrapped in GetSetupDataResponse
3808
+ *
3809
+ * @example
3810
+ * ```typescript
3811
+ * const { setupData } = await client.getSetupData(session, 'sms', { phoneNumber: '+14155552671' });
3812
+ * // setupData: { maskedPhone: '+1***2671' }
3813
+ * ```
3796
3814
  */
3797
- getSetupData(session: string, method: GetSetupDataRequest['method']): Promise<GetSetupDataResponse>;
3815
+ getSetupData(session: string, method: GetSetupDataRequest['method'], setupData?: Record<string, unknown>): Promise<GetSetupDataResponse>;
3798
3816
  /**
3799
3817
  * Get challenge data (e.g., WebAuthn options).
3800
3818
  *
@@ -4392,6 +4410,11 @@ declare class NAuthClient {
4392
4410
  /**
4393
4411
  * Check if a challenge requires phone collection (user has no phone number).
4394
4412
  *
4413
+ * True for `VERIFY_PHONE` when the account has no phone (submit `phone` via
4414
+ * `respondToChallenge()` first), and for `MFA_SETUP_REQUIRED` when SMS is an allowed
4415
+ * method and the account has no phone (pass `{ phoneNumber }` as the third argument of
4416
+ * `getSetupData(session, 'sms', ...)` when the user picks SMS).
4417
+ *
4395
4418
  * @param challenge - Auth response with challenge
4396
4419
  * @returns True if phone collection is required
4397
4420
  *
package/dist/index.mjs CHANGED
@@ -2592,20 +2592,31 @@ var NAuthClient = class {
2592
2592
  return this.post(this.config.endpoints.resendCode, payload);
2593
2593
  }
2594
2594
  /**
2595
- * Get setup data for MFA.
2595
+ * Get setup data for MFA during an `MFA_SETUP_REQUIRED` challenge.
2596
2596
  *
2597
2597
  * Returns method-specific setup information:
2598
2598
  * - TOTP: { secret, qrCode, manualEntryKey }
2599
- * - SMS: { maskedPhone }
2600
- * - Email: { maskedEmail }
2599
+ * - SMS: { maskedPhone } (code sent) or { deviceId, autoCompleted: true }
2600
+ * - Email: { maskedEmail } or { deviceId, autoCompleted: true }
2601
2601
  * - Passkey: WebAuthn registration options
2602
2602
  *
2603
+ * For SMS, pass `{ phoneNumber }` (E.164) when the challenge has `requiresPhoneCollection: 'true'`
2604
+ * (see `requiresPhoneCollection()`): the number is saved to the account and verified by the code.
2605
+ * Call again with a different `phoneNumber` to change it, or without `setupData` to resend.
2606
+ *
2603
2607
  * @param session - Challenge session token
2604
2608
  * @param method - MFA method to set up
2609
+ * @param setupData - Optional method-specific input (SMS: `{ phoneNumber?, deviceName? }`)
2605
2610
  * @returns Setup data wrapped in GetSetupDataResponse
2611
+ *
2612
+ * @example
2613
+ * ```typescript
2614
+ * const { setupData } = await client.getSetupData(session, 'sms', { phoneNumber: '+14155552671' });
2615
+ * // setupData: { maskedPhone: '+1***2671' }
2616
+ * ```
2606
2617
  */
2607
- async getSetupData(session, method) {
2608
- const payload = { session, method };
2618
+ async getSetupData(session, method, setupData) {
2619
+ const payload = setupData ? { session, method, setupData } : { session, method };
2609
2620
  return this.post(this.config.endpoints.getSetupData, payload);
2610
2621
  }
2611
2622
  /**
@@ -3533,7 +3544,7 @@ var NAuthClient = class {
3533
3544
 
3534
3545
  // src/core/challenge-helpers.ts
3535
3546
  function requiresPhoneCollection(challenge) {
3536
- if (challenge.challengeName !== "VERIFY_PHONE" /* VERIFY_PHONE */) {
3547
+ if (challenge.challengeName !== "VERIFY_PHONE" /* VERIFY_PHONE */ && challenge.challengeName !== "MFA_SETUP_REQUIRED" /* MFA_SETUP_REQUIRED */) {
3537
3548
  return false;
3538
3549
  }
3539
3550
  const params = challenge.challengeParameters;