Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | 15x 15x 15x 15x 15x 15x 15x 15x 219x 15x 41x 41x 36x 5x 15x 260x | import { isNonNegativeInteger } from '../validation.ts'
export enum CustomerVariableName {
GetResultPath = 'fpjs_get_result_path',
BehaviorPathNestLevel = 'fpjs_integration_path_depth',
PreSharedSecret = 'fpjs_pre_shared_secret',
AgentDownloadPath = 'fpjs_agent_download_path',
FpCdnUrl = 'fpjs_cdn_url',
FpIngressBaseHost = 'fpjs_ingress_base_host',
}
export const internalVariables: Set<CustomerVariableName> = new Set<CustomerVariableName>([
CustomerVariableName.FpCdnUrl,
CustomerVariableName.FpIngressBaseHost,
])
type ParserValidator<T> = (value: T) => boolean
const stringParser = (value: string) => value
const intParser = (fallbackValue: number, validation: ParserValidator<number>) => (value: string) => {
const parsed = parseInt(value)
if (validation(parsed)) {
return parsed
}
return fallbackValue
}
export const customerVariableParsers = {
[CustomerVariableName.GetResultPath]: stringParser,
[CustomerVariableName.BehaviorPathNestLevel]: intParser(1, isNonNegativeInteger),
[CustomerVariableName.PreSharedSecret]: stringParser,
[CustomerVariableName.AgentDownloadPath]: stringParser,
[CustomerVariableName.FpCdnUrl]: stringParser,
[CustomerVariableName.FpIngressBaseHost]: stringParser,
}
export function parseCustomerVariable<T extends CustomerVariableName>(variable: T, value: string) {
// TS can't narrow the return type of a dynamically-indexed lookup across a union-keyed record.
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
return customerVariableParsers[variable](value) as CustomerVariableType<T>
}
export type CustomerVariableType<T extends CustomerVariableName> = ReturnType<(typeof customerVariableParsers)[T]>
export type CustomerVariableReturn = string | null | undefined
export type CustomerVariablesRecord = {
[Key in CustomerVariableName]: CustomerVariableType<Key> | undefined | null
}
export interface CustomerVariableProvider {
readonly name: string
getVariable: (variable: CustomerVariableName) => Promise<CustomerVariableReturn>
}
|