Skip to content

Client reference

Every public function, class and type, as published at version 0.1.0-alpha.7. The JavaScript SDK page has the overview and examples.

@formerie/client/browser has the same exports.

Clients and addresses

buildBrandedSchemaUrl

The schema address under /v1/, with no workspace handle.

TypeScript
function buildBrandedSchemaUrl(endpoint: string, form: string): string;

buildBrandedSubmitUrl

The submit address under /v1/, with no workspace handle.

TypeScript
function buildBrandedSubmitUrl(endpoint: string, form: string): string;

buildBrandedValidateUrl

The validate address under /v1/, with no workspace handle.

TypeScript
function buildBrandedValidateUrl(endpoint: string, form: string): string;

buildCanonicalSchemaUrl

The schema address under /v1/, as FormerieClient calls it.

TypeScript
function buildCanonicalSchemaUrl(endpoint: string, workspace: string, form: string): string;

buildCanonicalSubmitUrl

The submit address under /v1/, as FormerieClient calls it.

TypeScript
function buildCanonicalSubmitUrl(endpoint: string, workspace: string, form: string): string;

buildCanonicalValidateUrl

The validate address under /v1/, as FormerieClient calls it.

TypeScript
function buildCanonicalValidateUrl(endpoint: string, workspace: string, form: string): string;

buildFormRuntimeHostedFormUrl

The hosted page’s address on a hostname connected to one form.

TypeScript
function buildFormRuntimeHostedFormUrl(endpoint: string): string;

buildFormRuntimeSchemaUrl

The schema route’s address on a hostname connected to one form.

TypeScript
function buildFormRuntimeSchemaUrl(endpoint: string): string;

buildFormRuntimeSubmitUrl

The submit route’s address on a hostname connected to one form.

TypeScript
function buildFormRuntimeSubmitUrl(endpoint: string): string;

buildFormRuntimeValidateUrl

The validate route’s address on a hostname connected to one form.

TypeScript
function buildFormRuntimeValidateUrl(endpoint: string): string;

buildRuntimeEmbedScriptUrl

The address of embed.js on a host.

TypeScript
function buildRuntimeEmbedScriptUrl(endpoint: string): string;

buildRuntimeHostedFormUrl

The hosted page’s address, for a workspace and a form.

TypeScript
function buildRuntimeHostedFormUrl(endpoint: string, workspace: string, form: string): string;

buildRuntimeSchemaUrl

The schema route’s address, for a workspace and a form.

TypeScript
function buildRuntimeSchemaUrl(endpoint: string, workspace: string, form: string): string;

buildRuntimeSubmitUrl

The submit route’s address, for a workspace and a form.

TypeScript
function buildRuntimeSubmitUrl(endpoint: string, workspace: string, form: string): string;

buildRuntimeValidateUrl

The validate route’s address, for a workspace and a form.

TypeScript
function buildRuntimeValidateUrl(endpoint: string, workspace: string, form: string): string;

buildWorkspaceRuntimeHostedFormUrl

The hosted page’s address on a hostname connected to a workspace.

TypeScript
function buildWorkspaceRuntimeHostedFormUrl(endpoint: string, form: string): string;

buildWorkspaceRuntimeSchemaUrl

The schema route’s address on a hostname connected to a workspace.

TypeScript
function buildWorkspaceRuntimeSchemaUrl(endpoint: string, form: string): string;

buildWorkspaceRuntimeSubmitUrl

The submit route’s address on a hostname connected to a workspace.

TypeScript
function buildWorkspaceRuntimeSubmitUrl(endpoint: string, form: string): string;

buildWorkspaceRuntimeValidateUrl

The validate route’s address on a hostname connected to a workspace.

TypeScript
function buildWorkspaceRuntimeValidateUrl(endpoint: string, form: string): string;

FORMERIE_API_ENDPOINT

The address FormerieClient calls by default.

TypeScript
const FORMERIE_API_ENDPOINT = "https://api.formerie.com";

FORMERIE_RUNTIME_ENDPOINT

The address FormerieRuntimeClient calls by default.

TypeScript
const FORMERIE_RUNTIME_ENDPOINT = "https://forms.formerie.com";

FormerieClient

The same requests on api.formerie.com. Use FormerieRuntimeClient for anything new.

TypeScript
class FormerieClient {
    constructor(config?: FormerieClientConfig);
    submit(workspace: string, form: string, payload: SubmitPayload, options?: SubmitRequestOptions): Promise<SubmitResponse>;
    submitBranded(form: string, payload: SubmitPayload, options?: SubmitRequestOptions): Promise<SubmitResponse>;
    validate(workspace: string, form: string, payload: ValidatePayload, options?: SubmitRequestOptions): Promise<ValidateResponse>;
    validateBranded(form: string, payload: ValidatePayload, options?: SubmitRequestOptions): Promise<ValidateResponse>;
    schema(workspace: string, form: string, options?: SubmitRequestOptions): Promise<PublicFormSchemaResult>;
    schemaBranded(form: string, options?: SubmitRequestOptions): Promise<PublicFormSchemaResult>;
    canonicalUrl(workspace: string, form: string): string;
    brandedUrl(form: string): string;
    canonicalSchemaUrl(workspace: string, form: string): string;
    brandedSchemaUrl(form: string): string;
    canonicalValidateUrl(workspace: string, form: string): string;
    brandedValidateUrl(form: string): string;
}

FormerieRuntimeClient

The client to use. Reads the schema, checks answers and submits, on forms.formerie.com or a hostname you’ve connected. submitWorkspace and its siblings suit a hostname connected to a workspace, and submitForm and its siblings a hostname connected to one form.

TypeScript
class FormerieRuntimeClient extends FormerieClient {
    constructor(config?: FormerieRuntimeClientConfig);
    submit(workspace: string, form: string, payload: SubmitPayload, options?: SubmitRequestOptions): Promise<SubmitResponse>;
    submitWorkspace(form: string, payload: SubmitPayload, options?: SubmitRequestOptions): Promise<SubmitResponse>;
    submitBranded(form: string, payload: SubmitPayload, options?: SubmitRequestOptions): Promise<SubmitResponse>;
    submitForm(payload: SubmitPayload, options?: SubmitRequestOptions): Promise<SubmitResponse>;
    validate(workspace: string, form: string, payload: ValidatePayload, options?: SubmitRequestOptions): Promise<ValidateResponse>;
    validateWorkspace(form: string, payload: ValidatePayload, options?: SubmitRequestOptions): Promise<ValidateResponse>;
    validateBranded(form: string, payload: ValidatePayload, options?: SubmitRequestOptions): Promise<ValidateResponse>;
    validateForm(payload: ValidatePayload, options?: SubmitRequestOptions): Promise<ValidateResponse>;
    schema(workspace: string, form: string, options?: SubmitRequestOptions): Promise<PublicFormSchemaResult>;
    schemaWorkspace(form: string, options?: SubmitRequestOptions): Promise<PublicFormSchemaResult>;
    schemaBranded(form: string, options?: SubmitRequestOptions): Promise<PublicFormSchemaResult>;
    schemaForm(options?: SubmitRequestOptions): Promise<PublicFormSchemaResult>;
    canonicalUrl(workspace: string, form: string): string;
    brandedUrl(form: string): string;
    canonicalSchemaUrl(workspace: string, form: string): string;
    brandedSchemaUrl(form: string): string;
    canonicalValidateUrl(workspace: string, form: string): string;
    brandedValidateUrl(form: string): string;
    hostedUrl(workspace: string, form: string): string;
    hostedWorkspaceUrl(form: string): string;
    hostedFormUrl(): string;
    embedScriptUrl(): string;
}

FormServiceClient

An older name for FormerieClient.

TypeScript
class FormServiceClient extends FormerieClient {}

Embeds

buildFormerieEmbedIframeUrl

The address an embed’s iframe loads, on a host and for an optional form.

TypeScript
function buildFormerieEmbedIframeUrl(endpoint: string, form?: string): string;

mountFormerieEmbed

Loads the hosted page in an iframe. Answers null when there’s no document or no target to put it in.

TypeScript
function mountFormerieEmbed(options?: MountFormerieEmbedOptions): MountedFormerieEmbed | null;

MountedFormerieEmbed

TypeScript
interface MountedFormerieEmbed {
    destroy(): void;
    element: Element;
    iframe: HTMLIFrameElement;
}

MountFormerieEmbedOptions

TypeScript
interface MountFormerieEmbedOptions {
    document?: Document;
    endpoint?: string;
    form?: string;
    height?: string;
    script?: HTMLScriptElement | null;
    target?: Element | string | null;
    title?: string;
}

Reading responses

getFieldErrors

Every problem with one field path, from an error response.

TypeScript
function getFieldErrors(response: ErrorCapableResponse, path: string): ValidationIssue[];

getFirstFieldError

The first problem with one field path, or null.

TypeScript
function getFirstFieldError(response: ErrorCapableResponse, path: string): ValidationIssue | null;

getFormErrors

The problems that belong to the whole form rather than one field.

TypeScript
function getFormErrors(response: ErrorCapableResponse): ValidationIssue[];

isSubmitError

Whether a response is an error.

TypeScript
function isSubmitError(response: ErrorCapableResponse): response is SubmitErrorResponse;

isSubmitSuccess

Whether a submit response was accepted.

TypeScript
function isSubmitSuccess(response: SubmitResponse): response is SubmitSuccessResponse;

isValidateSuccess

Whether a validate response passed.

TypeScript
function isValidateSuccess(response: ValidateResponse): response is ValidateSuccessResponse;

isValidationError

Whether a response is a VALIDATION_FAILED error.

TypeScript
function isValidationError(response: ErrorCapableResponse): response is SubmitErrorResponse & {
    error: ValidationFailedError;
};

Fallback messages

DEFAULT_ERROR_MESSAGES

The SDK’s fallback message for each error code.

TypeScript
const DEFAULT_ERROR_MESSAGES: Record<FormerieErrorCode, string>;

DEFAULT_FIELD_ERROR_MESSAGES

The SDK’s fallback message for each built-in field error code.

TypeScript
const DEFAULT_FIELD_ERROR_MESSAGES: Record<BuiltInFieldErrorCode, string>;

messageForErrorCode

The fallback message for an error code. Prefer the message the server sends.

TypeScript
function messageForErrorCode(code: FormerieErrorCode): string;

messageForFieldErrorCode

The fallback message for a field error code. Prefer the message the server sends.

TypeScript
function messageForFieldErrorCode(code: FieldErrorCode): string;

Drawing forms

applyFormerieVerificationError

Shows a verification error on a form.

TypeScript
function applyFormerieVerificationError(form: HTMLFormElement, message: string): void;

bindFormerieForm

Adds Formerie’s behaviour to a <form> your page already rendered.

TypeScript
function bindFormerieForm(form: HTMLFormElement, options: BindFormerieFormOptions): MountedFormerieForm;

bindFormerieHostedForm

The same, for a server-rendered page that has both a form shell and a public schema script.

TypeScript
function bindFormerieHostedForm(options?: BindFormerieHostedFormOptions): MountedFormerieForm;

clearFormerieVerificationError

Clears a form’s verification error.

TypeScript
function clearFormerieVerificationError(form: HTMLFormElement): void;

collectFormerieVerificationToken

Gets the verification token from a form’s widget, when the form requires one.

TypeScript
function collectFormerieVerificationToken(options: FormerieVerificationTokenOptions): Promise<string | undefined>;

describeFormerieRenderFields

A flat description of each field to draw, for your own renderer.

TypeScript
function describeFormerieRenderFields(schema: PublicSchemaInput, values?: Record<string, unknown>, options?: DescribeFormerieRenderFieldsOptions): FormerieRenderField[];

describeFormerieRenderModel

The fields and steps to draw, for your own renderer.

TypeScript
function describeFormerieRenderModel(schema: PublicSchemaInput, values?: Record<string, unknown>, options?: DescribeFormerieRenderModelOptions): FormerieRenderModel;

loadFormerieRuntimeSchema

Loads the public schema for a mount target.

TypeScript
function loadFormerieRuntimeSchema(options: LoadFormerieRuntimeSchemaOptions): Promise<PublicFormSchemaResult>;

mountFormerieForm

The same, when your app already has the public schema.

TypeScript
function mountFormerieForm(target: Element | string, options: MountFormerieFormOptions): MountedFormerieForm;

mountFormerieRuntimeForm

Loads a form’s public schema and does the rest: draws it, collects answers and any verification token, submits, and shows errors from the server.

TypeScript
function mountFormerieRuntimeForm(target: Element | string, options: MountFormerieRuntimeFormOptions): Promise<MountedFormerieForm>;

readFormerieHostedSchema

Reads the public schema from the JSON script in a hosted page. Throws if it’s missing or empty.

TypeScript
function readFormerieHostedSchema(options?: ReadFormerieHostedSchemaOptions): PublicFormSchemaResponse;

renderFormerieFormHtml

The form’s HTML as a string, from a public schema.

TypeScript
function renderFormerieFormHtml(schema: PublicSchemaInput, options?: RenderFormerieFormHtmlOptions): string;

renderFormerieVerificationHtml

The HTML and script details for a schema’s human verification.

TypeScript
function renderFormerieVerificationHtml(verification: PublicFormSchemaResponse["verification"], options?: RenderFormerieVerificationHtmlOptions): FormerieVerificationHtml;

resetFormerieVerificationWidget

Resets a form’s verification widget, so it can give a new token.

TypeScript
function resetFormerieVerificationWidget(form: HTMLFormElement): void;

syncFormerieFormVisibility

Shows and hides a mounted form’s fields to match its answers, and returns each field’s state.

TypeScript
function syncFormerieFormVisibility(form: HTMLFormElement, schema: PublicSchemaInput, values?: Record<string, unknown>): Record<string, PublicFieldVisibilityState>;

BindFormerieFormOptions

TypeScript
type BindFormerieFormOptions = Omit<MountFormerieFormOptions, "formAttributes" | "includeHiddenFields" | "submitLabel">;

BindFormerieHostedFormOptions

TypeScript
interface BindFormerieHostedFormOptions extends Omit<BindFormerieFormOptions, "schema"> {
    form?: HTMLFormElement | string;
    root?: ParentNode;
    schema?: PublicFormSchemaResponse;
    schemaElement?: HTMLScriptElement | string;
}

DescribeFormerieRenderFieldsOptions

TypeScript
interface DescribeFormerieRenderFieldsOptions {
    includeHidden?: boolean;
}

DescribeFormerieRenderModelOptions

TypeScript
interface DescribeFormerieRenderModelOptions extends DescribeFormerieRenderFieldsOptions {
    includeEmptySteps?: boolean;
}

FormerieHeadingLevel

TypeScript
type FormerieHeadingLevel = 1 | 2 | 3 | 4 | 5 | 6;

FormerieRenderClassNames

TypeScript
interface FormerieRenderClassNames {
    checkboxField?: string;
    field?: string;
    fieldDescription?: string;
    fieldError?: string;
    honeypot?: string;
    status?: string;
    verification?: string;
    verificationError?: string;
}

FormerieRenderControl

TypeScript
type FormerieRenderControl = "array" | "checkbox" | "checkbox-group" | "input" | "select" | "textarea";

FormerieRenderField

TypeScript
interface FormerieRenderField {
    control: FormerieRenderControl;
    description?: string;
    id: string;
    inputMode?: string;
    inputType?: string;
    label: string;
    max?: number | string;
    maxLength?: number;
    min?: number | string;
    minLength?: number;
    multiple?: boolean;
    name: string;
    node: PublicArrayField | PublicScalarField;
    options?: string[];
    placeholder?: string;
    path: string;
    required: boolean;
    step?: string;
    value?: unknown;
    visibility: PublicFieldVisibilityState;
}

FormerieRenderModel

TypeScript
interface FormerieRenderModel {
    fields: FormerieRenderField[];
    fieldsByPath: Record<string, FormerieRenderField>;
    steps: FormerieRenderStep[];
    unsteppedFields: FormerieRenderField[];
}

FormerieRenderStep

TypeScript
interface FormerieRenderStep {
    fields: FormerieRenderField[];
    id: string;
    label: string;
    validateOn?: PublicFormStep["validateOn"];
}

FormerieRuntimeMountTarget

TypeScript
type FormerieRuntimeMountTarget = FormerieTarget | {
    formBound: true;
};

FormerieVerificationHtml

TypeScript
interface FormerieVerificationHtml {
    attributes: string;
    markup: string;
    scripts: string;
}

FormerieVerificationTokenOptions

TypeScript
interface FormerieVerificationTokenOptions {
    form: HTMLFormElement;
}

LoadFormerieRuntimeSchemaOptions

TypeScript
interface LoadFormerieRuntimeSchemaOptions {
    client?: FormerieRuntimeClient;
    endpoint?: string;
    schemaOptions?: SubmitRequestOptions;
    target: FormerieRuntimeMountTarget;
}

MountedFormerieForm

TypeScript
interface MountedFormerieForm {
    destroy(): void;
    element: Element;
    form: HTMLFormElement;
    submit(): Promise<SubmitResponse>;
    values(): Record<string, unknown>;
}

MountFormerieFormOptions

TypeScript
interface MountFormerieFormOptions extends RenderFormerieFormHtmlOptions {
    client?: FormerieRuntimeClient;
    endpoint?: string;
    fetcher?: typeof fetch;
    focusInvalid?: boolean;
    loadVerificationScript?: boolean;
    metadata?: CreateFormerieSubmitPayloadOptions["metadata"] | (() => CreateFormerieSubmitPayloadOptions["metadata"] | Promise<CreateFormerieSubmitPayloadOptions["metadata"]>);
    onError?: (response: SubmitResponse) => void;
    onSubmit?: (payload: SubmitPayload) => SubmitResponse | Promise<SubmitResponse>;
    onSuccess?: (response: SubmitResponse & {
        ok: true;
    }) => void;
    pendingMessage?: string;
    resetOnSuccess?: boolean;
    schema: PublicFormSchemaResponse;
    submitOptions?: SubmitRequestOptions;
    submitUrl?: string;
    target?: FormerieRuntimeMountTarget;
    turnstileToken?: string | (() => string | Promise<string | undefined> | undefined);
    verificationToken?: string | (() => string | Promise<string | undefined> | undefined);
}

MountFormerieRuntimeFormOptions

TypeScript
interface MountFormerieRuntimeFormOptions extends Omit<MountFormerieFormOptions, "client" | "endpoint" | "schema" | "target">, LoadFormerieRuntimeSchemaOptions {
}

ReadFormerieHostedSchemaOptions

TypeScript
interface ReadFormerieHostedSchemaOptions {
    root?: ParentNode;
    schemaElement?: HTMLScriptElement | string;
}

RenderFormerieFormHtmlOptions

TypeScript
interface RenderFormerieFormHtmlOptions {
    classes?: FormerieRenderClassNames;
    formAttributes?: Record<string, boolean | number | string | null | undefined>;
    headingLevel?: FormerieHeadingLevel;
    honeypotField?: string;
    honeypotLabel?: string;
    includeHeading?: boolean;
    includeHiddenFields?: boolean;
    includeVerification?: boolean;
    submitLabel?: string;
    values?: Record<string, unknown>;
}

RenderFormerieVerificationHtmlOptions

TypeScript
interface RenderFormerieVerificationHtmlOptions {
    containerClass?: string;
    errorClass?: string;
}

The schema and answers

applyFormerieValidationErrors

Shows a response’s errors next to the matching inputs, and returns the paths it placed.

TypeScript
function applyFormerieValidationErrors(root: ParentNode, source: SubmitResponse | ValidateResponse | ValidationFailedError | unknown, options?: ApplyFormerieValidationErrorsOptions): string[];

clearFormerieValidationErrors

Clears errors shown by applyFormerieValidationErrors.

TypeScript
function clearFormerieValidationErrors(root: ParentNode, options?: ApplyFormerieValidationErrorsOptions): void;

collectFormerieFormFields

Reads a form element’s answers as nested fields.

TypeScript
function collectFormerieFormFields(form: HTMLFormElement, options?: FormerieFieldCollectionOptions): Record<string, unknown>;

createFormerieSubmitPayload

Builds the submit body from FormData, a form element or an object.

TypeScript
function createFormerieSubmitPayload(source: FormData | HTMLFormElement | Record<string, unknown>, options?: CreateFormerieSubmitPayloadOptions): SubmitPayload;

evaluatePublicCondition

Whether a condition from a public schema holds for these answers.

TypeScript
function evaluatePublicCondition(condition: unknown, values: Record<string, unknown>): boolean;

evaluatePublicFieldVisibility

Each visibility rule’s path, with its state for these answers.

TypeScript
function evaluatePublicFieldVisibility(schema: PublicSchemaInput, values: Record<string, unknown>): Record<string, PublicFieldVisibilityState>;

firstValidationMessageForField

A response’s first message for one field path, or null.

TypeScript
function firstValidationMessageForField(source: SubmitResponse | ValidateResponse | ValidationFailedError | unknown, path: string): string | null;

formDataToFormerieFields

Turns FormData into nested fields.

TypeScript
function formDataToFormerieFields(formData: FormData, options?: FormerieFieldCollectionOptions): Record<string, unknown>;

getPublicFieldVisibility

One field path’s state for these answers.

TypeScript
function getPublicFieldVisibility(schema: PublicSchemaInput, values: Record<string, unknown>, path: string): PublicFieldVisibilityState;

getPublicSchemaField

Finds one field in a public schema by its path.

TypeScript
function getPublicSchemaField(schema: PublicSchemaInput, path: string): PublicSchemaNode | undefined;

isPublicSchemaPathHidden

Whether a field path is hidden for these answers.

TypeScript
function isPublicSchemaPathHidden(schema: PublicSchemaInput, values: Record<string, unknown>, path: string): boolean;

listPublicSchemaFields

Lists every field in a public schema, with its path.

TypeScript
function listPublicSchemaFields(schema: PublicSchemaInput): PublicSchemaFieldEntry[];

resolveFormerieFieldValue

Reads a value by field path, such as contact.email.

TypeScript
function resolveFormerieFieldValue(values: Record<string, unknown>, path: string): unknown;

resolveHiddenPublicSchemaPaths

Every field path hidden for these answers.

TypeScript
function resolveHiddenPublicSchemaPaths(schema: PublicSchemaInput, values: Record<string, unknown>): Set<string>;

setFormerieFieldValue

Sets a value by field path.

TypeScript
function setFormerieFieldValue(fields: Record<string, unknown>, path: string, value: unknown): Record<string, unknown>;

validateFormeriePublicFields

Checks answers in the browser against a public schema, for quick feedback. The server still has the final say.

TypeScript
function validateFormeriePublicFields(schema: PublicSchemaInput, submittedFields: unknown, options?: ValidateFormeriePublicFieldsOptions): FormeriePublicFieldsValidationResult;

validationIssuesByField

A response’s problems, by field path.

TypeScript
function validationIssuesByField(source: SubmitResponse | ValidateResponse | ValidationFailedError | unknown): Record<string, ValidationIssue[]>;

validationMessagesByField

A response’s messages, by field path.

TypeScript
function validationMessagesByField(source: SubmitResponse | ValidateResponse | ValidationFailedError | unknown): Record<string, string[]>;

validationMessagesForField

A response’s messages for one field path.

TypeScript
function validationMessagesForField(source: SubmitResponse | ValidateResponse | ValidationFailedError | unknown, path: string): string[];

visiblePublicSchemaFields

Lists the fields visible for these answers.

TypeScript
function visiblePublicSchemaFields(schema: PublicSchemaInput, values: Record<string, unknown>): PublicSchemaFieldEntry[];

ApplyFormerieValidationErrorsOptions

TypeScript
interface ApplyFormerieValidationErrorsOptions {
    clearExisting?: boolean;
    errorAttribute?: string;
    errorForAttribute?: string;
    fieldAttribute?: string;
    invalidAttribute?: string;
}

CreateFormerieSubmitPayloadOptions

TypeScript
interface CreateFormerieSubmitPayloadOptions extends FormerieFieldCollectionOptions {
    metadata?: Record<string, unknown>;
    turnstileToken?: string;
    verificationToken?: string;
}

FormerieFieldCollectionOptions

TypeScript
interface FormerieFieldCollectionOptions {
    schema?: PublicSchemaInput;
    includeMissingCheckboxes?: boolean;
}

FormeriePublicFieldsValidationResult

TypeScript
interface FormeriePublicFieldsValidationResult {
    ok: boolean;
    values: Record<string, unknown>;
    errors: Record<string, ValidationIssue[]>;
    issues: ValidationIssue[];
}

PublicSchemaFieldEntry

TypeScript
interface PublicSchemaFieldEntry {
    path: string;
    key: string;
    parentPath?: string;
    depth: number;
    repeated: boolean;
    node: PublicSchemaNode;
}

PublicSchemaInput

TypeScript
type PublicSchemaInput = PublicFormSchemaResponse | Record<string, PublicSchemaNode>;

ValidateFormeriePublicFieldsOptions

TypeScript
interface ValidateFormeriePublicFieldsOptions {
    mode?: "final" | "partial" | "step";
    paths?: string[];
    step?: string;
}

Target helpers

isBrandedFormerieTarget

Whether a target is a form on a hostname connected to a workspace.

TypeScript
function isBrandedFormerieTarget(target: FormerieTarget): target is BrandedFormerieTarget;

schemaFormerieTarget

Reads the schema of a target.

TypeScript
function schemaFormerieTarget(client: FormerieClient, target: FormerieTarget, options?: SubmitRequestOptions): Promise<PublicFormSchemaResult>;

submitFormerieTarget

Submits to a target.

TypeScript
function submitFormerieTarget(client: FormerieClient, target: FormerieTarget, payload: SubmitPayload, options?: SubmitRequestOptions): Promise<SubmitResponse>;

validateFormerieTarget

Checks answers for a target.

TypeScript
function validateFormerieTarget(client: FormerieClient, target: FormerieTarget, payload: ValidatePayload, options?: SubmitRequestOptions): Promise<ValidateResponse>;

BrandedFormerieTarget

TypeScript
interface BrandedFormerieTarget {
    form: string;
    branded: true;
}

CanonicalFormerieTarget

TypeScript
type CanonicalFormerieTarget = WorkspaceFormerieTarget;

FormerieTarget

TypeScript
type FormerieTarget = CanonicalFormerieTarget | BrandedFormerieTarget;

WorkspaceFormerieTarget

TypeScript
interface WorkspaceFormerieTarget {
    workspace: string;
    form: string;
    branded?: false;
}

Types

BuiltInFieldErrorCode

TypeScript
type BuiltInFieldErrorCode = "FIELD_REQUIRED" | "FIELD_TYPE_INVALID" | "FIELD_STRING_TOO_SHORT" | "FIELD_STRING_TOO_LONG" | "FIELD_STRING_LENGTH_INVALID" | "FIELD_STRING_PREFIX_INVALID" | "FIELD_STRING_SUFFIX_INVALID" | "FIELD_STRING_CONTAINS_REQUIRED" | "FIELD_STRING_CONTAINS_FORBIDDEN" | "FIELD_EMAIL_INVALID" | "FIELD_PHONE_INVALID" | "FIELD_UUID_INVALID" | "FIELD_COUNTRY_CODE_INVALID" | "FIELD_POSTAL_CODE_INVALID" | "FIELD_REGION_CODE_INVALID" | "FIELD_URL_INVALID" | "FIELD_URL_PROTOCOL_NOT_ALLOWED" | "FIELD_DATE_INVALID" | "FIELD_DATE_TOO_EARLY" | "FIELD_DATE_TOO_LATE" | "FIELD_TIME_INVALID" | "FIELD_DATETIME_INVALID" | "FIELD_NUMBER_TOO_SMALL" | "FIELD_NUMBER_TOO_LARGE" | "FIELD_INTEGER_REQUIRED" | "FIELD_DECIMAL_PLACES_INVALID" | "FIELD_VALUE_NOT_ALLOWED" | "FIELD_PATTERN_INVALID" | "FIELD_ACCEPTED_REQUIRED" | "FIELD_SELECTION_TOO_FEW" | "FIELD_SELECTION_TOO_MANY" | "FIELD_ARRAY_TOO_SHORT" | "FIELD_ARRAY_TOO_LONG" | "FIELD_ARRAY_DUPLICATES" | "FIELD_OBJECT_INVALID" | "FORM_RULE_FAILED";

FieldErrorCode

TypeScript
type FieldErrorCode = BuiltInFieldErrorCode | (string & {});

FormerieClientConfig

TypeScript
interface FormerieClientConfig {
    endpoint?: string;
    fetcher?: typeof fetch;
    defaultHeaders?: HeadersInit;
}

FormerieError

TypeScript
interface FormerieError {
    code: FormerieErrorCode;
    message: string;
}

FormerieErrorCode

TypeScript
type FormerieErrorCode = "BAD_REQUEST" | "INVALID_JSON" | "FORM_NOT_FOUND" | "FORM_DISABLED" | "FORBIDDEN_ORIGIN" | "VALIDATION_FAILED" | "SPAM_REJECTED" | "TURNSTILE_FAILED" | "QUEUE_FAILED" | "UNAUTHORIZED" | "DEAD_LETTER_NOT_FOUND" | "DEAD_LETTER_NOT_REPLAYABLE" | "RATE_LIMITED" | "FORM_QUOTA_REACHED" | "FORM_NOT_OPEN" | "FORM_CLOSED" | "DUPLICATE_SUBMISSION" | "INTERNAL_ERROR" | "NETWORK_ERROR" | "INVALID_RESPONSE";

FormerieRuntimeClientConfig

TypeScript
interface FormerieRuntimeClientConfig extends FormerieClientConfig {
}

FormServiceClientConfig

TypeScript
interface FormServiceClientConfig extends FormerieClientConfig {
}

FormServiceError

TypeScript
interface FormServiceError extends FormerieError {
}

FormServiceErrorCode

TypeScript
type FormServiceErrorCode = FormerieErrorCode;

PublicArrayField

TypeScript
interface PublicArrayField {
    type: "array";
    description?: string;
    label?: string;
    required?: boolean;
    minItems?: number;
    maxItems?: number;
    uniqueItems?: boolean;
    item: PublicSchemaNode;
    messages?: Record<string, string>;
}

PublicCompositeValidator

TypeScript
interface PublicCompositeValidator {
    type: "allOf" | "anyOf";
    validators: PublicContextualValidator[];
    code: string;
    message: string;
    rule?: string;
}

PublicContextualValidator

TypeScript
type PublicContextualValidator = PublicFieldValidator | PublicRequiredValidator | PublicCompositeValidator;

PublicFieldValidator

TypeScript
interface PublicFieldValidator {
    type: "regex" | PublicNativeFieldValidatorType;
    code: string;
    message: string;
    rule?: string;
    allowedProtocols?: string[];
    country?: "CA" | "US";
    flags?: string;
    pattern?: string;
    value?: string;
    version?: "any" | "v4" | "v7";
}

PublicFieldVisibilityState

TypeScript
type PublicFieldVisibilityState = "visible" | "hidden";

PublicFormBehaviorSettings

TypeScript
interface PublicFormBehaviorSettings {
    submitButtonLabel?: string;
    successMessage?: string;
    successRedirectUrl?: string;
}

PublicFormBrandingSettings

TypeScript
interface PublicFormBrandingSettings {
    accentColor?: string;
    accentTextColor?: string;
    backgroundColor?: string;
    borderColor?: string;
    brandName?: string;
    customCss?: string;
    density?: "compact" | "comfortable" | "spacious";
    errorColor?: string;
    errorTextColor?: string;
    fieldBackgroundColor?: string;
    fontPreset?: "arial" | "georgia" | "helvetica" | "inter" | "mono" | "system" | "times" | "verdana";
    logoUrl?: string;
    mutedTextColor?: string;
    previewTheme?: "dark" | "light";
    radius?: "none" | "soft" | "round";
    surfaceColor?: string;
    textColor?: string;
    themes?: {
        dark?: PublicFormBrandingTheme;
        light?: PublicFormBrandingTheme;
    };
}

PublicFormBrandingTheme

TypeScript
interface PublicFormBrandingTheme {
    accentColor?: string;
    accentTextColor?: string;
    backgroundColor?: string;
    borderColor?: string;
    errorColor?: string;
    errorTextColor?: string;
    fieldBackgroundColor?: string;
    mutedTextColor?: string;
    surfaceColor?: string;
    textColor?: string;
}

PublicFormLayoutSettings

TypeScript
interface PublicFormLayoutSettings {
    containerMaxWidth?: string;
    containerMinWidth?: string;
    containerWidthMode?: "contained" | "custom" | "full";
}

PublicFormSchemaResponse

TypeScript
interface PublicFormSchemaResponse {
    ok: true;
    enabled: boolean;
    formHandle: string;
    metadata?: {
        schemaVersion?: string;
        label?: string;
        description?: string;
    };
    schemaId: string;
    settings?: PublicFormSettings;
    turnstile: {
        required: boolean;
    };
    verification?: {
        provider: "turnstile" | "recaptcha-v2" | "recaptcha-v3";
        required: boolean;
        siteKey?: string;
        expectedAction?: string;
    };
    limits?: {
        maxSubmissionJsonBytes?: number;
        schedule?: {
            opensAt?: string;
            closesAt?: string;
            notOpenMessage?: string;
            closedMessage?: string;
        };
    };
    fields: Record<string, PublicSchemaNode>;
    steps?: PublicFormStep[];
    visibilityRules?: PublicVisibilityRule[];
    validationRules?: PublicValidationRule[];
    workspaceHandle: string;
}

PublicFormSchemaResult

TypeScript
type PublicFormSchemaResult = PublicFormSchemaResponse | SubmitErrorResponse;

PublicFormSettings

TypeScript
interface PublicFormSettings {
    behavior?: PublicFormBehaviorSettings;
    branding?: PublicFormBrandingSettings;
    layout?: PublicFormLayoutSettings;
}

PublicFormStep

TypeScript
interface PublicFormStep {
    id: string;
    label?: string;
    fields: string[];
    validateOn?: "change" | "blur" | "stepSubmit";
}

PublicNativeFieldValidatorType

TypeScript
type PublicNativeFieldValidatorType = "contains" | "countryCode" | "domain" | "email" | "endsWith" | "ip" | "ipv4" | "ipv6" | "notContains" | "phoneE164" | "postalCode" | "regionCode" | "startsWith" | "url" | "uuid";

PublicObjectField

TypeScript
interface PublicObjectField {
    type: "object";
    description?: string;
    label?: string;
    required?: boolean;
    fields: Record<string, PublicSchemaNode>;
    messages?: Record<string, string>;
}

PublicRequiredValidator

TypeScript
interface PublicRequiredValidator {
    type: "required";
    code: string;
    message: string;
    rule?: string;
}

PublicScalarField

TypeScript
interface PublicScalarField {
    type: "string" | "email" | "url" | "phone" | "number" | "boolean" | "date" | "textarea" | "select" | "checkbox";
    defaultValue?: string | number | boolean | string[];
    description?: string;
    label?: string;
    placeholder?: string;
    required?: boolean;
    min?: number;
    max?: number;
    exactLength?: number;
    pattern?: string;
    allowedValues?: string[];
    allowedProtocols?: string[];
    phoneFormat?: "e164";
    uuidVersion?: "any" | "v4" | "v7";
    countryCode?: "iso2";
    postalCodeCountry?: "CA" | "US";
    regionCodeCountry?: "CA" | "US";
    dateMin?: string;
    dateMax?: string;
    timeFormat?: "HH:mm" | "HH:mm:ss";
    dateTimeFormat?: "iso8601";
    startsWith?: string;
    endsWith?: string;
    contains?: string;
    notContains?: string;
    caseTransform?: "upper" | "lower";
    collapseWhitespace?: boolean;
    integer?: boolean;
    maxDecimalPlaces?: number;
    accepted?: boolean;
    minSelections?: number;
    maxSelections?: number;
    trim?: boolean;
    normalizeEmail?: boolean;
    pipeline?: PublicFieldPipelineStep[];
    sanitizers?: PublicFieldSanitizer[];
    transformers?: PublicFieldTransformer[];
    validators?: PublicFieldValidator[];
    messages?: Record<string, string>;
}

PublicSchemaNode

TypeScript
type PublicSchemaNode = PublicScalarField | PublicObjectField | PublicArrayField;

PublicValidationAction

TypeScript
interface PublicValidationAction {
    path: string;
    validator?: PublicContextualValidator;
}

PublicValidationRule

TypeScript
interface PublicValidationRule {
    id: string;
    label?: string;
    when: unknown;
    then: PublicValidationAction[];
}

PublicVisibilityRule

TypeScript
interface PublicVisibilityRule {
    id: string;
    label?: string;
    path: string;
    default?: PublicFieldVisibilityState;
    when: unknown;
    state: PublicFieldVisibilityState;
}

SubmitErrorResponse

TypeScript
interface SubmitErrorResponse {
    ok: false;
    error: FormerieError | ValidationFailedError;
}

SubmitPayload

TypeScript
interface SubmitPayload {
    fields: Record<string, unknown>;
    turnstileToken?: string;
    verificationToken?: string;
    metadata?: Record<string, unknown>;
}

SubmitRequestOptions

TypeScript
interface SubmitRequestOptions {
    signal?: AbortSignal;
    headers?: HeadersInit;
}

SubmitResponse

TypeScript
type SubmitResponse = SubmitSuccessResponse | SubmitErrorResponse;

SubmitSuccessResponse

TypeScript
interface SubmitSuccessResponse {
    ok: true;
    submissionId: string;
    status: "accepted";
}

ValidatePayload

TypeScript
interface ValidatePayload {
    fields: Record<string, unknown>;
    mode?: "partial" | "step";
    step?: string;
    metadata?: Record<string, unknown>;
}

ValidateResponse

TypeScript
type ValidateResponse = ValidateSuccessResponse | SubmitErrorResponse;

ValidateSuccessResponse

TypeScript
interface ValidateSuccessResponse {
    ok: true;
    status: "valid";
    mode: "partial" | "step";
    step?: string;
    values: Record<string, unknown>;
}

ValidationFailedError

TypeScript
interface ValidationFailedError extends FormerieError {
    code: "VALIDATION_FAILED";
    fields: Record<string, ValidationIssue[]>;
    issues: ValidationIssue[];
}

ValidationIssue

TypeScript
interface ValidationIssue {
    path: string;
    code: FieldErrorCode;
    message: string;
    rule: string;
    params?: Record<string, unknown>;
}