feat(snjs): add sign in with recovery codes use case (#2130)

* feat(snjs): add sign in with recovery codes use case

* fix(snjs): code review adjustments

* fix(snjs): remove unnecessary exposed getter

* fix(services): waiting for event handling

* fix: preferences test

Co-authored-by: Mo <mo@standardnotes.com>
This commit is contained in:
Karol Sójko
2023-01-09 06:52:56 +01:00
committed by GitHub
parent 5f09fc74da
commit be028ff87b
37 changed files with 838 additions and 81 deletions

View File

@@ -0,0 +1,33 @@
import { HttpServiceInterface } from '../../Http/HttpServiceInterface'
import { RecoveryKeyParamsRequestParams, SignInWithRecoveryCodesRequestParams } from '../../Request'
import {
GenerateRecoveryCodesResponse,
RecoveryKeyParamsResponse,
SignInWithRecoveryCodesResponse,
} from '../../Response'
import { AuthServerInterface } from './AuthServerInterface'
import { Paths } from './Paths'
export class AuthServer implements AuthServerInterface {
constructor(private httpService: HttpServiceInterface) {}
async generateRecoveryCodes(): Promise<GenerateRecoveryCodesResponse> {
const response = await this.httpService.post(Paths.v1.generateRecoveryCodes)
return response as GenerateRecoveryCodesResponse
}
async recoveryKeyParams(params: RecoveryKeyParamsRequestParams): Promise<RecoveryKeyParamsResponse> {
const response = await this.httpService.post(Paths.v1.recoveryKeyParams, params)
return response as RecoveryKeyParamsResponse
}
async signInWithRecoveryCodes(
params: SignInWithRecoveryCodesRequestParams,
): Promise<SignInWithRecoveryCodesResponse> {
const response = await this.httpService.post(Paths.v1.signInWithRecoveryCodes, params)
return response as SignInWithRecoveryCodesResponse
}
}

View File

@@ -0,0 +1,12 @@
import { RecoveryKeyParamsRequestParams, SignInWithRecoveryCodesRequestParams } from '../../Request'
import {
GenerateRecoveryCodesResponse,
RecoveryKeyParamsResponse,
SignInWithRecoveryCodesResponse,
} from '../../Response'
export interface AuthServerInterface {
generateRecoveryCodes(): Promise<GenerateRecoveryCodesResponse>
recoveryKeyParams(params: RecoveryKeyParamsRequestParams): Promise<RecoveryKeyParamsResponse>
signInWithRecoveryCodes(params: SignInWithRecoveryCodesRequestParams): Promise<SignInWithRecoveryCodesResponse>
}

View File

@@ -2,8 +2,15 @@ const SessionPaths = {
refreshSession: '/v1/sessions/refresh',
}
const RecoveryPaths = {
generateRecoveryCodes: '/v1/auth/recovery/codes',
recoveryKeyParams: '/v1/auth/recovery/login-params',
signInWithRecoveryCodes: '/v1/auth/recovery/login',
}
export const Paths = {
v1: {
...SessionPaths,
...RecoveryPaths,
},
}