Skip to main content

@thcare/thfx

Enumerations

Interfaces

Type Aliases

AnyFormComponent

Ƭ AnyFormComponent: FormComponent | SliderFormComponent | CustomFormComponent


AppTemplate

Ƭ AppTemplate: "web.th.care"

App template is used by the deployment engine to determine which project template to clone and hydrate with the solution data.


AzureHttpFunction

Ƭ AzureHttpFunction: (context: Context, req: HttpRequest) => Promisable<HttpResponseSimple | undefined>

Type declaration

▸ (context, req): Promisable<HttpResponseSimple | undefined>

An Azure function (from a function app), triggered by an HTTP request. The argument and return types come from version 3 of the @azure/functions library.

Parameters
NameTypeDescription
contextContextThe Azure context object
reqHttpRequestThe HTTP request being managed
Returns

Promisable<HttpResponseSimple | undefined>

  • The HTTP response, as expected by Azure

Event

Ƭ Event: { submission: { data: unknown ; form_id: string ; id: string ; user_id: string | null } ; type: "FormSubmitted" } | { type: "UserCreated" ; user: { user_id: string } } | { type: "UserLoggedIn" ; user: { email: string ; id: string } }


EventBody

Ƭ EventBody<T>: Extract<Event, { type: T }>

Type parameters

NameType
Textends EventType

EventHandler

Ƭ EventHandler<T>: { handler: (event: EventBody<T>) => Promisable<HookResult | undefined> ; type: "inline" } | { type: "http-post" ; url: string } | { name: string ; type: "bundled-azure-function" }

Type parameters

NameType
Textends EventType

EventMatcher

Ƭ EventMatcher<T>: Object

Type parameters

NameType
Textends EventType = EventType

Type declaration

NameType
typeT

EventType

Ƭ EventType: Event["type"]


FormSubmitHandler

Ƭ FormSubmitHandler<TSchema>: (options: { context: Context ; formData: Yup.InferType<TSchema> ; req: HttpRequest }) => Promisable<HookResult>

Type parameters

NameTypeDescription
TSchemaextends Yup.AnySchemaThe type of the schema. This is used to build the type of the formData argument.

Type declaration

▸ (options): Promisable<HookResult>

A callback function invoked via buildOnSubmitHandler.

Parameters
NameTypeDescription
optionsObject-
options.contextContextThe Azure context object
options.formDataYup.InferType<TSchema>Data from the submitted form
options.reqHttpRequestThe HTTP request being responded to
Returns

Promisable<HookResult>


Locale

Ƭ Locale: "en-CA" | "en-US" | "en-XA" | "fr-CA"

Locales supported by the framework

These are BCP-47 identifies. As the framework supports more locales, add them to this list.


Messages

Ƭ Messages: Record<string, MessageFormatElement[]>

Compiled message dictionary, ready to be provided to the <IntlProvider> component.

The IntlProvider will accept either this type or Record<string, string>. Restricting ourselves to just this type makes it easier to merge solution-provided strings with framework-providing strings, because both sets of strings have the same type.


PaletteColorOptions

Ƭ PaletteColorOptions: SimplePaletteColorOptions | ColorPartial


SolutionJson

Ƭ SolutionJson: Jsonify<Solution> & { thfxVersion?: string }

As part of the build process, solutions are compiled down to a simple JSON representation.

Any functions or objects that can't be represented as JSON will only be available by import-ing the solution, not by reading its thcare-solution.json file.


ValidatableValue

Ƭ ValidatableValue: null | boolean | number | string | ValidationRef | ValidationRegex | ValidatableValue[]

A value that can be checked by a validation rule


ValidationRule

Ƭ ValidationRule: SimpleValidationRule | WhenValidationRule


ValidationRuleTable

Ƭ ValidationRuleTable<Keys>: { [K in Keys]?: ValidationRule }

A table of validation rules, e.g. StringValidation.

Those interfaces need to conform to this type, to ensure that they didn't add any new types that belong in ValidationItem. But they can't implement this type because if they do that's saying that any string can be used as a key.

Type parameters

NameType
Keysextends string | number | symbol

WhenValidationRule

Ƭ WhenValidationRule: [key: string, logic: jsonlogic.RulesLogic]

Variables

SUPPORTED_LOCALES

Const SUPPORTED_LOCALES: Record<Locale, IdentifiedLocale>


SolutionJsonSchema

Const SolutionJsonSchema: ObjectSchema<{ thfxVersion: undefined | string }, AnyObject, { thfxVersion: undefined }, "">


default

Const default: Object

Type declaration

NameType
parse(solution: string | object) => SolutionJson

Functions

buildOnSubmitHandler

buildOnSubmitHandler<TSchema>(options): AzureHttpFunction

Build an Azure function that runs when a form is submitted. In the returned function, schema validation and error handling is managed for you; your handler callback just needs to do business logic.

Type parameters

NameType
TSchemaextends AnySchema

Parameters

NameTypeDescription
optionsObject-
options.formIdstringWhen this form is submitted, run the handler
options.formSchemaTSchemaLightweight schema for the form. Unfortunately, this needs to repeat some (but not all) of the validation rules from the form definition. Include every field, its type (string, number, etc.) and if it is required. Omit other validation rules, such as minimum and maximum value.
options.handlerFormSubmitHandler<TSchema>Callback to execute when the form is submitted

Returns

AzureHttpFunction


eventMatches

eventMatches(event, pattern): boolean

Parameters

NameType
eventEvent
patternEventMatcher<"FormSubmitted" | "UserCreated" | "UserLoggedIn">

Returns

boolean


getFormId

getFormId(form): string

Parameters

NameType
formForm

Returns

string


getValidationSchema

getValidationSchema(form): yup.AnyObjectSchema

Given a form definition, extract a schema for validating form submissions. The schema uses yup, a form validation library.

Parameters

NameTypeDescription
formPick<Form, "steps">The form to validate

Returns

yup.AnyObjectSchema

A yup schema