import { omitUser } from '../utils/index.mjs';

class HeadlessTOTPClient {
    _networkClient;
    _subscriptionService;
    dfpProtectedAuth;
    authenticate;
    recover;
    constructor(_networkClient, _subscriptionService, dfpProtectedAuth){
        this._networkClient = _networkClient;
        this._subscriptionService = _subscriptionService;
        this.dfpProtectedAuth = dfpProtectedAuth;
        this.authenticate = this._subscriptionService.withUpdateSession(async (options)=>{
            const { dfp_telemetry_id, captcha_token } = await this.dfpProtectedAuth.getDFPTelemetryIDAndCaptcha();
            const resp = await this._networkClient.retriableFetchSDK({
                url: '/totps/authenticate',
                method: 'POST',
                body: {
                    session_duration_minutes: options.session_duration_minutes,
                    totp_code: options.totp_code,
                    captcha_token,
                    dfp_telemetry_id
                },
                retryCallback: this.dfpProtectedAuth.retryWithCaptchaAndDFP
            });
            return omitUser(resp);
        });
        this.recover = this._subscriptionService.withUpdateSession(async (options)=>{
            const { dfp_telemetry_id, captcha_token } = await this.dfpProtectedAuth.getDFPTelemetryIDAndCaptcha();
            const resp = await this._networkClient.retriableFetchSDK({
                url: '/totps/recover',
                method: 'POST',
                body: {
                    session_duration_minutes: options.session_duration_minutes,
                    recovery_code: options.recovery_code,
                    captcha_token,
                    dfp_telemetry_id
                },
                retryCallback: this.dfpProtectedAuth.retryWithCaptchaAndDFP
            });
            return omitUser(resp);
        });
    }
    async create(options) {
        const resp = await this._networkClient.fetchSDK({
            url: '/totps',
            method: 'POST',
            body: {
                expiration_minutes: options.expiration_minutes
            }
        });
        this._subscriptionService.updateUser(resp.__user);
        return omitUser(resp);
    }
    async recoveryCodes() {
        return this._networkClient.fetchSDK({
            url: '/totps/recovery_codes',
            method: 'POST'
        });
    }
}

export { HeadlessTOTPClient };
//# sourceMappingURL=HeadlessTOTPClient.mjs.map
