@nauth-toolkit/client 0.1.112 → 0.1.115
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 +85 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +85 -3
- package/dist/index.d.ts +85 -3
- package/dist/index.mjs +85 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -2979,14 +2979,96 @@ declare class NAuthClient {
|
|
|
2979
2979
|
getMfaStatus(): Promise<MFAStatus>;
|
|
2980
2980
|
/**
|
|
2981
2981
|
* Get MFA devices.
|
|
2982
|
+
*
|
|
2983
|
+
* @returns Promise of MFA devices response
|
|
2984
|
+
*
|
|
2985
|
+
* @example
|
|
2986
|
+
* ```typescript
|
|
2987
|
+
* const result = await client.getMfaDevices();
|
|
2988
|
+
* console.log('Devices:', result.devices);
|
|
2989
|
+
* ```
|
|
2982
2990
|
*/
|
|
2983
|
-
getMfaDevices(): Promise<
|
|
2991
|
+
getMfaDevices(): Promise<GetMFADevicesResponse>;
|
|
2984
2992
|
/**
|
|
2985
2993
|
* Setup MFA device (authenticated user).
|
|
2994
|
+
*
|
|
2995
|
+
* Returns method-specific setup information:
|
|
2996
|
+
* - TOTP: { secret, qrCode, manualEntryKey }
|
|
2997
|
+
* - SMS: { maskedPhone } or { deviceId, autoCompleted: true }
|
|
2998
|
+
* - Email: { maskedEmail } or { deviceId, autoCompleted: true }
|
|
2999
|
+
* - Passkey: WebAuthn registration options
|
|
3000
|
+
*
|
|
3001
|
+
* @param method - MFA method to set up
|
|
3002
|
+
* @returns Promise of setup data response
|
|
3003
|
+
*
|
|
3004
|
+
* @example
|
|
3005
|
+
* ```typescript
|
|
3006
|
+
* const result = await client.setupMfaDevice('totp');
|
|
3007
|
+
* console.log('QR Code:', result.setupData.qrCode);
|
|
3008
|
+
* ```
|
|
2986
3009
|
*/
|
|
2987
|
-
setupMfaDevice(method: string): Promise<
|
|
3010
|
+
setupMfaDevice(method: string): Promise<GetSetupDataResponse>;
|
|
2988
3011
|
/**
|
|
2989
3012
|
* Verify MFA setup (authenticated user).
|
|
3013
|
+
*
|
|
3014
|
+
* Completes MFA device setup by verifying the setup data. The structure of `setupData` varies by method:
|
|
3015
|
+
*
|
|
3016
|
+
* **TOTP:**
|
|
3017
|
+
* - Requires both `secret` (from `getSetupData()` response) and `code` (from authenticator app)
|
|
3018
|
+
* - Example: `{ secret: 'JBSWY3DPEHPK3PXP', code: '123456' }`
|
|
3019
|
+
*
|
|
3020
|
+
* **SMS:**
|
|
3021
|
+
* - Requires `phoneNumber` and `code` (verification code sent to phone)
|
|
3022
|
+
* - Example: `{ phoneNumber: '+1234567890', code: '123456' }`
|
|
3023
|
+
*
|
|
3024
|
+
* **Email:**
|
|
3025
|
+
* - Requires `code` (verification code sent to email)
|
|
3026
|
+
* - Example: `{ code: '123456' }`
|
|
3027
|
+
*
|
|
3028
|
+
* **Passkey:**
|
|
3029
|
+
* - Requires `credential` (WebAuthn credential from registration) and `expectedChallenge`
|
|
3030
|
+
* - Example: `{ credential: {...}, expectedChallenge: '...' }`
|
|
3031
|
+
*
|
|
3032
|
+
* @param method - MFA method ('totp', 'sms', 'email', 'passkey')
|
|
3033
|
+
* @param setupData - Method-specific setup verification data
|
|
3034
|
+
* @param deviceName - Optional device name (can also be included in setupData for some methods)
|
|
3035
|
+
* @returns Promise with device ID of the created MFA device
|
|
3036
|
+
*
|
|
3037
|
+
* @example TOTP Setup
|
|
3038
|
+
* ```typescript
|
|
3039
|
+
* // Step 1: Get setup data
|
|
3040
|
+
* const setupData = await client.setupMfaDevice('totp');
|
|
3041
|
+
* // Returns: { setupData: { secret: 'JBSWY3DPEHPK3PXP', qrCode: '...', ... } }
|
|
3042
|
+
*
|
|
3043
|
+
* // Step 2: User scans QR code and enters code from authenticator app
|
|
3044
|
+
* const code = '123456'; // From authenticator app
|
|
3045
|
+
*
|
|
3046
|
+
* // Step 3: Verify setup (requires both secret and code)
|
|
3047
|
+
* const result = await client.verifyMfaSetup('totp', {
|
|
3048
|
+
* secret: setupData.setupData.secret,
|
|
3049
|
+
* code: code,
|
|
3050
|
+
* }, 'Google Authenticator');
|
|
3051
|
+
* // Returns: { deviceId: 123 }
|
|
3052
|
+
* ```
|
|
3053
|
+
*
|
|
3054
|
+
* @example SMS Setup
|
|
3055
|
+
* ```typescript
|
|
3056
|
+
* const result = await client.verifyMfaSetup('sms', {
|
|
3057
|
+
* phoneNumber: '+1234567890', // Phone number receiving the code
|
|
3058
|
+
* code: '123456', // Code sent to phone
|
|
3059
|
+
* }, 'My iPhone');
|
|
3060
|
+
* ```
|
|
3061
|
+
*
|
|
3062
|
+
* @example Passkey Setup
|
|
3063
|
+
* ```typescript
|
|
3064
|
+
* const credential = await navigator.credentials.create({
|
|
3065
|
+
* publicKey: setupData.setupData.options
|
|
3066
|
+
* });
|
|
3067
|
+
* const result = await client.verifyMfaSetup('passkey', {
|
|
3068
|
+
* credential: credential,
|
|
3069
|
+
* expectedChallenge: setupData.setupData.challenge,
|
|
3070
|
+
* }, 'MacBook Pro');
|
|
3071
|
+
* ```
|
|
2990
3072
|
*/
|
|
2991
3073
|
verifyMfaSetup(method: string, setupData: Record<string, unknown>, deviceName?: string): Promise<{
|
|
2992
3074
|
deviceId: number;
|
|
@@ -2994,7 +3076,7 @@ declare class NAuthClient {
|
|
|
2994
3076
|
/**
|
|
2995
3077
|
* Remove ALL MFA devices for a specific method type.
|
|
2996
3078
|
*
|
|
2997
|
-
*
|
|
3079
|
+
* WARNING: This removes ALL devices of the specified method.
|
|
2998
3080
|
* For example, if you have 3 TOTP devices, this will remove all 3.
|
|
2999
3081
|
*
|
|
3000
3082
|
* **Prefer `removeMfaDeviceById()`** to remove individual devices.
|
package/dist/index.d.ts
CHANGED
|
@@ -2979,14 +2979,96 @@ declare class NAuthClient {
|
|
|
2979
2979
|
getMfaStatus(): Promise<MFAStatus>;
|
|
2980
2980
|
/**
|
|
2981
2981
|
* Get MFA devices.
|
|
2982
|
+
*
|
|
2983
|
+
* @returns Promise of MFA devices response
|
|
2984
|
+
*
|
|
2985
|
+
* @example
|
|
2986
|
+
* ```typescript
|
|
2987
|
+
* const result = await client.getMfaDevices();
|
|
2988
|
+
* console.log('Devices:', result.devices);
|
|
2989
|
+
* ```
|
|
2982
2990
|
*/
|
|
2983
|
-
getMfaDevices(): Promise<
|
|
2991
|
+
getMfaDevices(): Promise<GetMFADevicesResponse>;
|
|
2984
2992
|
/**
|
|
2985
2993
|
* Setup MFA device (authenticated user).
|
|
2994
|
+
*
|
|
2995
|
+
* Returns method-specific setup information:
|
|
2996
|
+
* - TOTP: { secret, qrCode, manualEntryKey }
|
|
2997
|
+
* - SMS: { maskedPhone } or { deviceId, autoCompleted: true }
|
|
2998
|
+
* - Email: { maskedEmail } or { deviceId, autoCompleted: true }
|
|
2999
|
+
* - Passkey: WebAuthn registration options
|
|
3000
|
+
*
|
|
3001
|
+
* @param method - MFA method to set up
|
|
3002
|
+
* @returns Promise of setup data response
|
|
3003
|
+
*
|
|
3004
|
+
* @example
|
|
3005
|
+
* ```typescript
|
|
3006
|
+
* const result = await client.setupMfaDevice('totp');
|
|
3007
|
+
* console.log('QR Code:', result.setupData.qrCode);
|
|
3008
|
+
* ```
|
|
2986
3009
|
*/
|
|
2987
|
-
setupMfaDevice(method: string): Promise<
|
|
3010
|
+
setupMfaDevice(method: string): Promise<GetSetupDataResponse>;
|
|
2988
3011
|
/**
|
|
2989
3012
|
* Verify MFA setup (authenticated user).
|
|
3013
|
+
*
|
|
3014
|
+
* Completes MFA device setup by verifying the setup data. The structure of `setupData` varies by method:
|
|
3015
|
+
*
|
|
3016
|
+
* **TOTP:**
|
|
3017
|
+
* - Requires both `secret` (from `getSetupData()` response) and `code` (from authenticator app)
|
|
3018
|
+
* - Example: `{ secret: 'JBSWY3DPEHPK3PXP', code: '123456' }`
|
|
3019
|
+
*
|
|
3020
|
+
* **SMS:**
|
|
3021
|
+
* - Requires `phoneNumber` and `code` (verification code sent to phone)
|
|
3022
|
+
* - Example: `{ phoneNumber: '+1234567890', code: '123456' }`
|
|
3023
|
+
*
|
|
3024
|
+
* **Email:**
|
|
3025
|
+
* - Requires `code` (verification code sent to email)
|
|
3026
|
+
* - Example: `{ code: '123456' }`
|
|
3027
|
+
*
|
|
3028
|
+
* **Passkey:**
|
|
3029
|
+
* - Requires `credential` (WebAuthn credential from registration) and `expectedChallenge`
|
|
3030
|
+
* - Example: `{ credential: {...}, expectedChallenge: '...' }`
|
|
3031
|
+
*
|
|
3032
|
+
* @param method - MFA method ('totp', 'sms', 'email', 'passkey')
|
|
3033
|
+
* @param setupData - Method-specific setup verification data
|
|
3034
|
+
* @param deviceName - Optional device name (can also be included in setupData for some methods)
|
|
3035
|
+
* @returns Promise with device ID of the created MFA device
|
|
3036
|
+
*
|
|
3037
|
+
* @example TOTP Setup
|
|
3038
|
+
* ```typescript
|
|
3039
|
+
* // Step 1: Get setup data
|
|
3040
|
+
* const setupData = await client.setupMfaDevice('totp');
|
|
3041
|
+
* // Returns: { setupData: { secret: 'JBSWY3DPEHPK3PXP', qrCode: '...', ... } }
|
|
3042
|
+
*
|
|
3043
|
+
* // Step 2: User scans QR code and enters code from authenticator app
|
|
3044
|
+
* const code = '123456'; // From authenticator app
|
|
3045
|
+
*
|
|
3046
|
+
* // Step 3: Verify setup (requires both secret and code)
|
|
3047
|
+
* const result = await client.verifyMfaSetup('totp', {
|
|
3048
|
+
* secret: setupData.setupData.secret,
|
|
3049
|
+
* code: code,
|
|
3050
|
+
* }, 'Google Authenticator');
|
|
3051
|
+
* // Returns: { deviceId: 123 }
|
|
3052
|
+
* ```
|
|
3053
|
+
*
|
|
3054
|
+
* @example SMS Setup
|
|
3055
|
+
* ```typescript
|
|
3056
|
+
* const result = await client.verifyMfaSetup('sms', {
|
|
3057
|
+
* phoneNumber: '+1234567890', // Phone number receiving the code
|
|
3058
|
+
* code: '123456', // Code sent to phone
|
|
3059
|
+
* }, 'My iPhone');
|
|
3060
|
+
* ```
|
|
3061
|
+
*
|
|
3062
|
+
* @example Passkey Setup
|
|
3063
|
+
* ```typescript
|
|
3064
|
+
* const credential = await navigator.credentials.create({
|
|
3065
|
+
* publicKey: setupData.setupData.options
|
|
3066
|
+
* });
|
|
3067
|
+
* const result = await client.verifyMfaSetup('passkey', {
|
|
3068
|
+
* credential: credential,
|
|
3069
|
+
* expectedChallenge: setupData.setupData.challenge,
|
|
3070
|
+
* }, 'MacBook Pro');
|
|
3071
|
+
* ```
|
|
2990
3072
|
*/
|
|
2991
3073
|
verifyMfaSetup(method: string, setupData: Record<string, unknown>, deviceName?: string): Promise<{
|
|
2992
3074
|
deviceId: number;
|
|
@@ -2994,7 +3076,7 @@ declare class NAuthClient {
|
|
|
2994
3076
|
/**
|
|
2995
3077
|
* Remove ALL MFA devices for a specific method type.
|
|
2996
3078
|
*
|
|
2997
|
-
*
|
|
3079
|
+
* WARNING: This removes ALL devices of the specified method.
|
|
2998
3080
|
* For example, if you have 3 TOTP devices, this will remove all 3.
|
|
2999
3081
|
*
|
|
3000
3082
|
* **Prefer `removeMfaDeviceById()`** to remove individual devices.
|
package/dist/index.mjs
CHANGED
|
@@ -1733,7 +1733,8 @@ var NAuthClient = class {
|
|
|
1733
1733
|
*/
|
|
1734
1734
|
async respondToChallenge(response) {
|
|
1735
1735
|
if (this.selectedDeviceId !== void 0 && response.type === "MFA_REQUIRED" /* MFA_REQUIRED */ && (response.method === "totp" || response.method === "passkey")) {
|
|
1736
|
-
|
|
1736
|
+
const mfaResponse = response;
|
|
1737
|
+
mfaResponse.deviceId = this.selectedDeviceId;
|
|
1737
1738
|
}
|
|
1738
1739
|
if (response.type === "MFA_SETUP_REQUIRED" /* MFA_SETUP_REQUIRED */ && response.method === "totp") {
|
|
1739
1740
|
const setupData = response.setupData;
|
|
@@ -1971,18 +1972,100 @@ var NAuthClient = class {
|
|
|
1971
1972
|
}
|
|
1972
1973
|
/**
|
|
1973
1974
|
* Get MFA devices.
|
|
1975
|
+
*
|
|
1976
|
+
* @returns Promise of MFA devices response
|
|
1977
|
+
*
|
|
1978
|
+
* @example
|
|
1979
|
+
* ```typescript
|
|
1980
|
+
* const result = await client.getMfaDevices();
|
|
1981
|
+
* console.log('Devices:', result.devices);
|
|
1982
|
+
* ```
|
|
1974
1983
|
*/
|
|
1975
1984
|
async getMfaDevices() {
|
|
1976
1985
|
return this.get(this.config.endpoints.mfaDevices, true);
|
|
1977
1986
|
}
|
|
1978
1987
|
/**
|
|
1979
1988
|
* Setup MFA device (authenticated user).
|
|
1989
|
+
*
|
|
1990
|
+
* Returns method-specific setup information:
|
|
1991
|
+
* - TOTP: { secret, qrCode, manualEntryKey }
|
|
1992
|
+
* - SMS: { maskedPhone } or { deviceId, autoCompleted: true }
|
|
1993
|
+
* - Email: { maskedEmail } or { deviceId, autoCompleted: true }
|
|
1994
|
+
* - Passkey: WebAuthn registration options
|
|
1995
|
+
*
|
|
1996
|
+
* @param method - MFA method to set up
|
|
1997
|
+
* @returns Promise of setup data response
|
|
1998
|
+
*
|
|
1999
|
+
* @example
|
|
2000
|
+
* ```typescript
|
|
2001
|
+
* const result = await client.setupMfaDevice('totp');
|
|
2002
|
+
* console.log('QR Code:', result.setupData.qrCode);
|
|
2003
|
+
* ```
|
|
1980
2004
|
*/
|
|
1981
2005
|
async setupMfaDevice(method) {
|
|
1982
2006
|
return this.post(this.config.endpoints.mfaSetupData, { methodName: method }, true);
|
|
1983
2007
|
}
|
|
1984
2008
|
/**
|
|
1985
2009
|
* Verify MFA setup (authenticated user).
|
|
2010
|
+
*
|
|
2011
|
+
* Completes MFA device setup by verifying the setup data. The structure of `setupData` varies by method:
|
|
2012
|
+
*
|
|
2013
|
+
* **TOTP:**
|
|
2014
|
+
* - Requires both `secret` (from `getSetupData()` response) and `code` (from authenticator app)
|
|
2015
|
+
* - Example: `{ secret: 'JBSWY3DPEHPK3PXP', code: '123456' }`
|
|
2016
|
+
*
|
|
2017
|
+
* **SMS:**
|
|
2018
|
+
* - Requires `phoneNumber` and `code` (verification code sent to phone)
|
|
2019
|
+
* - Example: `{ phoneNumber: '+1234567890', code: '123456' }`
|
|
2020
|
+
*
|
|
2021
|
+
* **Email:**
|
|
2022
|
+
* - Requires `code` (verification code sent to email)
|
|
2023
|
+
* - Example: `{ code: '123456' }`
|
|
2024
|
+
*
|
|
2025
|
+
* **Passkey:**
|
|
2026
|
+
* - Requires `credential` (WebAuthn credential from registration) and `expectedChallenge`
|
|
2027
|
+
* - Example: `{ credential: {...}, expectedChallenge: '...' }`
|
|
2028
|
+
*
|
|
2029
|
+
* @param method - MFA method ('totp', 'sms', 'email', 'passkey')
|
|
2030
|
+
* @param setupData - Method-specific setup verification data
|
|
2031
|
+
* @param deviceName - Optional device name (can also be included in setupData for some methods)
|
|
2032
|
+
* @returns Promise with device ID of the created MFA device
|
|
2033
|
+
*
|
|
2034
|
+
* @example TOTP Setup
|
|
2035
|
+
* ```typescript
|
|
2036
|
+
* // Step 1: Get setup data
|
|
2037
|
+
* const setupData = await client.setupMfaDevice('totp');
|
|
2038
|
+
* // Returns: { setupData: { secret: 'JBSWY3DPEHPK3PXP', qrCode: '...', ... } }
|
|
2039
|
+
*
|
|
2040
|
+
* // Step 2: User scans QR code and enters code from authenticator app
|
|
2041
|
+
* const code = '123456'; // From authenticator app
|
|
2042
|
+
*
|
|
2043
|
+
* // Step 3: Verify setup (requires both secret and code)
|
|
2044
|
+
* const result = await client.verifyMfaSetup('totp', {
|
|
2045
|
+
* secret: setupData.setupData.secret,
|
|
2046
|
+
* code: code,
|
|
2047
|
+
* }, 'Google Authenticator');
|
|
2048
|
+
* // Returns: { deviceId: 123 }
|
|
2049
|
+
* ```
|
|
2050
|
+
*
|
|
2051
|
+
* @example SMS Setup
|
|
2052
|
+
* ```typescript
|
|
2053
|
+
* const result = await client.verifyMfaSetup('sms', {
|
|
2054
|
+
* phoneNumber: '+1234567890', // Phone number receiving the code
|
|
2055
|
+
* code: '123456', // Code sent to phone
|
|
2056
|
+
* }, 'My iPhone');
|
|
2057
|
+
* ```
|
|
2058
|
+
*
|
|
2059
|
+
* @example Passkey Setup
|
|
2060
|
+
* ```typescript
|
|
2061
|
+
* const credential = await navigator.credentials.create({
|
|
2062
|
+
* publicKey: setupData.setupData.options
|
|
2063
|
+
* });
|
|
2064
|
+
* const result = await client.verifyMfaSetup('passkey', {
|
|
2065
|
+
* credential: credential,
|
|
2066
|
+
* expectedChallenge: setupData.setupData.challenge,
|
|
2067
|
+
* }, 'MacBook Pro');
|
|
2068
|
+
* ```
|
|
1986
2069
|
*/
|
|
1987
2070
|
async verifyMfaSetup(method, setupData, deviceName) {
|
|
1988
2071
|
return this.post(
|
|
@@ -1996,7 +2079,7 @@ var NAuthClient = class {
|
|
|
1996
2079
|
/**
|
|
1997
2080
|
* Remove ALL MFA devices for a specific method type.
|
|
1998
2081
|
*
|
|
1999
|
-
*
|
|
2082
|
+
* WARNING: This removes ALL devices of the specified method.
|
|
2000
2083
|
* For example, if you have 3 TOTP devices, this will remove all 3.
|
|
2001
2084
|
*
|
|
2002
2085
|
* **Prefer `removeMfaDeviceById()`** to remove individual devices.
|