feat: add snjs package
This commit is contained in:
33
packages/snjs/lib/Services/Challenge/ChallengeResponse.ts
Normal file
33
packages/snjs/lib/Services/Challenge/ChallengeResponse.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
import { isNullOrUndefined } from '@standardnotes/utils'
|
||||
import { Challenge } from './Challenge'
|
||||
import {
|
||||
ChallengeResponseInterface,
|
||||
ChallengeValidation,
|
||||
ChallengeValue,
|
||||
ChallengeArtifacts,
|
||||
} from '@standardnotes/services'
|
||||
|
||||
export class ChallengeResponse implements ChallengeResponseInterface {
|
||||
constructor(
|
||||
public readonly challenge: Challenge,
|
||||
public readonly values: ChallengeValue[],
|
||||
public readonly artifacts?: ChallengeArtifacts,
|
||||
) {
|
||||
Object.freeze(this)
|
||||
}
|
||||
|
||||
getValueForType(type: ChallengeValidation): ChallengeValue {
|
||||
const value = this.values.find((value) => value.prompt.validation === type)
|
||||
if (isNullOrUndefined(value)) {
|
||||
throw Error('Could not find value for validation type ' + type)
|
||||
}
|
||||
return value
|
||||
}
|
||||
|
||||
getDefaultValue(): ChallengeValue {
|
||||
if (this.values.length > 1) {
|
||||
throw Error('Attempting to retrieve default response value when more than one value exists')
|
||||
}
|
||||
return this.values[0]
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user