feat: add services package
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
import { assertUnreachable } from '@standardnotes/utils'
|
||||
import { ChallengeKeyboardType } from '../Types/ChallengeKeyboardType'
|
||||
import { ChallengeRawValue } from '../Types/ChallengeRawValue'
|
||||
import { ChallengeValidation } from '../Types/ChallengeValidation'
|
||||
import { ChallengePromptInterface } from './ChallengePromptInterface'
|
||||
import { ChallengePromptTitle } from './PromptTitles'
|
||||
|
||||
/* istanbul ignore file */
|
||||
|
||||
export class ChallengePrompt implements ChallengePromptInterface {
|
||||
public readonly id = Math.random()
|
||||
public readonly placeholder: string
|
||||
public readonly title: string
|
||||
public readonly validates: boolean
|
||||
|
||||
constructor(
|
||||
public readonly validation: ChallengeValidation,
|
||||
title?: string,
|
||||
placeholder?: string,
|
||||
public readonly secureTextEntry = true,
|
||||
public readonly keyboardType?: ChallengeKeyboardType,
|
||||
public readonly initialValue?: ChallengeRawValue,
|
||||
) {
|
||||
switch (this.validation) {
|
||||
case ChallengeValidation.AccountPassword:
|
||||
this.title = title ?? ChallengePromptTitle.AccountPassword
|
||||
this.placeholder = placeholder ?? ChallengePromptTitle.AccountPassword
|
||||
this.validates = true
|
||||
break
|
||||
case ChallengeValidation.LocalPasscode:
|
||||
this.title = title ?? ChallengePromptTitle.LocalPasscode
|
||||
this.placeholder = placeholder ?? ChallengePromptTitle.LocalPasscode
|
||||
this.validates = true
|
||||
break
|
||||
case ChallengeValidation.Biometric:
|
||||
this.title = title ?? ChallengePromptTitle.Biometrics
|
||||
this.placeholder = placeholder ?? ''
|
||||
this.validates = true
|
||||
break
|
||||
case ChallengeValidation.ProtectionSessionDuration:
|
||||
this.title = title ?? ChallengePromptTitle.RememberFor
|
||||
this.placeholder = placeholder ?? ''
|
||||
this.validates = true
|
||||
break
|
||||
case ChallengeValidation.None:
|
||||
this.title = title ?? ''
|
||||
this.placeholder = placeholder ?? ''
|
||||
this.validates = false
|
||||
break
|
||||
default:
|
||||
assertUnreachable(this.validation)
|
||||
}
|
||||
Object.freeze(this)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
import { ChallengeKeyboardType } from '../Types/ChallengeKeyboardType'
|
||||
import { ChallengeRawValue } from '../Types/ChallengeRawValue'
|
||||
import { ChallengeValidation } from '../Types/ChallengeValidation'
|
||||
|
||||
/**
|
||||
* A Challenge can have many prompts. Each prompt represents a unique input,
|
||||
* such as a text field, or biometric scanner.
|
||||
*/
|
||||
export interface ChallengePromptInterface {
|
||||
readonly id: number
|
||||
readonly placeholder: string
|
||||
readonly title: string
|
||||
readonly validates: boolean
|
||||
|
||||
readonly validation: ChallengeValidation
|
||||
readonly secureTextEntry: boolean
|
||||
readonly keyboardType?: ChallengeKeyboardType
|
||||
readonly initialValue?: ChallengeRawValue
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
/* istanbul ignore file */
|
||||
|
||||
export const ChallengePromptTitle = {
|
||||
AccountPassword: 'Account Password',
|
||||
LocalPasscode: 'Application Passcode',
|
||||
Biometrics: 'Biometrics',
|
||||
RememberFor: 'Remember For',
|
||||
Mfa: 'Two-factor Authentication Code',
|
||||
}
|
||||
Reference in New Issue
Block a user