feat: add snjs package

This commit is contained in:
Karol Sójko
2022-07-06 14:04:18 +02:00
parent 321a055bae
commit 0e40469e2f
296 changed files with 46109 additions and 187 deletions

View 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]
}
}