# Référence du client

Chaque fonction, classe et type publics, tels que publiés à la version `0.1.0-alpha.7`. La page [SDK JavaScript](/fr/guides/javascript-sdk/) présente l’aperçu et les exemples.

`@formerie/client/browser` a les mêmes exportations.

## Clients et adresses

### buildBrandedSchemaUrl

L’adresse du schéma sous `/v1/`, sans identifiant d’espace de travail.

```ts
function buildBrandedSchemaUrl(endpoint: string, form: string): string;
```

### buildBrandedSubmitUrl

L’adresse de soumission sous `/v1/`, sans identifiant d’espace de travail.

```ts
function buildBrandedSubmitUrl(endpoint: string, form: string): string;
```

### buildBrandedValidateUrl

L’adresse de validation sous `/v1/`, sans identifiant d’espace de travail.

```ts
function buildBrandedValidateUrl(endpoint: string, form: string): string;
```

### buildCanonicalSchemaUrl

L’adresse du schéma sous `/v1/`, comme `FormerieClient` l’appelle.

```ts
function buildCanonicalSchemaUrl(endpoint: string, workspace: string, form: string): string;
```

### buildCanonicalSubmitUrl

L’adresse de soumission sous `/v1/`, comme `FormerieClient` l’appelle.

```ts
function buildCanonicalSubmitUrl(endpoint: string, workspace: string, form: string): string;
```

### buildCanonicalValidateUrl

L’adresse de validation sous `/v1/`, comme `FormerieClient` l’appelle.

```ts
function buildCanonicalValidateUrl(endpoint: string, workspace: string, form: string): string;
```

### buildFormRuntimeHostedFormUrl

L’adresse de la page hébergée sur un nom d’hôte connecté à un seul formulaire.

```ts
function buildFormRuntimeHostedFormUrl(endpoint: string): string;
```

### buildFormRuntimeSchemaUrl

L’adresse de la route du schéma sur un nom d’hôte connecté à un seul formulaire.

```ts
function buildFormRuntimeSchemaUrl(endpoint: string): string;
```

### buildFormRuntimeSubmitUrl

L’adresse de la route de soumission sur un nom d’hôte connecté à un seul formulaire.

```ts
function buildFormRuntimeSubmitUrl(endpoint: string): string;
```

### buildFormRuntimeValidateUrl

L’adresse de la route de validation sur un nom d’hôte connecté à un seul formulaire.

```ts
function buildFormRuntimeValidateUrl(endpoint: string): string;
```

### buildRuntimeEmbedScriptUrl

L’adresse de `embed.js` sur un hôte.

```ts
function buildRuntimeEmbedScriptUrl(endpoint: string): string;
```

### buildRuntimeHostedFormUrl

L’adresse de la page hébergée, pour un espace de travail et un formulaire.

```ts
function buildRuntimeHostedFormUrl(endpoint: string, workspace: string, form: string): string;
```

### buildRuntimeSchemaUrl

L’adresse de la route du schéma, pour un espace de travail et un formulaire.

```ts
function buildRuntimeSchemaUrl(endpoint: string, workspace: string, form: string): string;
```

### buildRuntimeSubmitUrl

L’adresse de la route de soumission, pour un espace de travail et un formulaire.

```ts
function buildRuntimeSubmitUrl(endpoint: string, workspace: string, form: string): string;
```

### buildRuntimeValidateUrl

L’adresse de la route de validation, pour un espace de travail et un formulaire.

```ts
function buildRuntimeValidateUrl(endpoint: string, workspace: string, form: string): string;
```

### buildWorkspaceRuntimeHostedFormUrl

L’adresse de la page hébergée sur un nom d’hôte connecté à un espace de travail.

```ts
function buildWorkspaceRuntimeHostedFormUrl(endpoint: string, form: string): string;
```

### buildWorkspaceRuntimeSchemaUrl

L’adresse de la route du schéma sur un nom d’hôte connecté à un espace de travail.

```ts
function buildWorkspaceRuntimeSchemaUrl(endpoint: string, form: string): string;
```

### buildWorkspaceRuntimeSubmitUrl

L’adresse de la route de soumission sur un nom d’hôte connecté à un espace de travail.

```ts
function buildWorkspaceRuntimeSubmitUrl(endpoint: string, form: string): string;
```

### buildWorkspaceRuntimeValidateUrl

L’adresse de la route de validation sur un nom d’hôte connecté à un espace de travail.

```ts
function buildWorkspaceRuntimeValidateUrl(endpoint: string, form: string): string;
```

### FORMERIE_API_ENDPOINT

L’adresse que `FormerieClient` appelle par défaut.

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

### FORMERIE_RUNTIME_ENDPOINT

L’adresse que `FormerieRuntimeClient` appelle par défaut.

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

### FormerieClient

Les mêmes requêtes sur `api.formerie.com`. Utilisez `FormerieRuntimeClient` pour tout ce qui est nouveau.

```ts
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

Le client à utiliser. Lit le schéma, vérifie les réponses et soumet, sur `forms.formerie.com` ou un nom d’hôte que vous avez connecté. `submitWorkspace` et ses semblables conviennent à un nom d’hôte connecté à un espace de travail, et `submitForm` et ses semblables à un nom d’hôte connecté à un seul formulaire.

```ts
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

Un ancien nom de `FormerieClient`.

```ts
class FormServiceClient extends FormerieClient {}
```

## Intégrations

### buildFormerieEmbedIframeUrl

L’adresse que charge l’iframe d’une intégration, sur un hôte et pour un formulaire facultatif.

```ts
function buildFormerieEmbedIframeUrl(endpoint: string, form?: string): string;
```

### mountFormerieEmbed

Charge la page hébergée dans une iframe. Renvoie `null` s’il n’y a pas de document ou de cible où la placer.

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

### MountedFormerieEmbed

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

### MountFormerieEmbedOptions

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

## Lire les réponses

### getFieldErrors

Tous les problèmes d’un chemin de champ, à partir d’une réponse d’erreur.

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

### getFirstFieldError

Le premier problème d’un chemin de champ, ou `null`.

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

### getFormErrors

Les problèmes qui touchent tout le formulaire plutôt qu’un champ.

```ts
function getFormErrors(response: ErrorCapableResponse): ValidationIssue[];
```

### isSubmitError

Si une réponse est une erreur.

```ts
function isSubmitError(response: ErrorCapableResponse): response is SubmitErrorResponse;
```

### isSubmitSuccess

Si une réponse de soumission a été acceptée.

```ts
function isSubmitSuccess(response: SubmitResponse): response is SubmitSuccessResponse;
```

### isValidateSuccess

Si une réponse de validation est valide.

```ts
function isValidateSuccess(response: ValidateResponse): response is ValidateSuccessResponse;
```

### isValidationError

Si une réponse est une erreur `VALIDATION_FAILED`.

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

## Messages de repli

### DEFAULT_ERROR_MESSAGES

Le message de repli du SDK pour chaque code d’erreur.

```ts
const DEFAULT_ERROR_MESSAGES: Record<FormerieErrorCode, string>;
```

### DEFAULT_FIELD_ERROR_MESSAGES

Le message de repli du SDK pour chaque code d’erreur de champ intégré.

```ts
const DEFAULT_FIELD_ERROR_MESSAGES: Record<BuiltInFieldErrorCode, string>;
```

### messageForErrorCode

Le message de repli d’un code d’erreur. Préférez le message envoyé par le serveur.

```ts
function messageForErrorCode(code: FormerieErrorCode): string;
```

### messageForFieldErrorCode

Le message de repli d’un code d’erreur de champ. Préférez le message envoyé par le serveur.

```ts
function messageForFieldErrorCode(code: FieldErrorCode): string;
```

## Afficher les formulaires

### applyFormerieVerificationError

Affiche une erreur de vérification sur un formulaire.

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

### bindFormerieForm

Ajoute le comportement de Formerie à un `<form>` que votre page affiche déjà.

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

### bindFormerieHostedForm

La même chose, pour une page rendue par le serveur qui a à la fois une structure de formulaire et un script de schéma public.

```ts
function bindFormerieHostedForm(options?: BindFormerieHostedFormOptions): MountedFormerieForm;
```

### clearFormerieVerificationError

Efface l’erreur de vérification d’un formulaire.

```ts
function clearFormerieVerificationError(form: HTMLFormElement): void;
```

### collectFormerieVerificationToken

Obtient le jeton de vérification du module d’un formulaire, quand celui-ci en exige un.

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

### describeFormerieRenderFields

Une description à plat de chaque champ à afficher, pour votre propre rendu.

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

### describeFormerieRenderModel

Les champs et les étapes à afficher, pour votre propre rendu.

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

### loadFormerieRuntimeSchema

Charge le schéma public d’une cible de montage.

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

### mountFormerieForm

La même chose, quand votre application a déjà le schéma public.

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

### mountFormerieRuntimeForm

Charge le schéma public d’un formulaire et fait le reste : l’affiche, recueille les réponses et le jeton de vérification, soumet et montre les erreurs du serveur.

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

### readFormerieHostedSchema

Lit le schéma public dans le script JSON d’une page hébergée. Lève une erreur s’il est absent ou vide.

```ts
function readFormerieHostedSchema(options?: ReadFormerieHostedSchemaOptions): PublicFormSchemaResponse;
```

### renderFormerieFormHtml

Le HTML du formulaire sous forme de chaîne, à partir d’un schéma public.

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

### renderFormerieVerificationHtml

Le HTML et les détails de script de la vérification humaine d’un schéma.

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

### resetFormerieVerificationWidget

Réinitialise le module de vérification d’un formulaire, pour qu’il puisse donner un nouveau jeton.

```ts
function resetFormerieVerificationWidget(form: HTMLFormElement): void;
```

### syncFormerieFormVisibility

Affiche et masque les champs d’un formulaire monté selon ses réponses, et renvoie l’état de chaque champ.

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

### BindFormerieFormOptions

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

### BindFormerieHostedFormOptions

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

### DescribeFormerieRenderFieldsOptions

```ts
interface DescribeFormerieRenderFieldsOptions {
    includeHidden?: boolean;
}
```

### DescribeFormerieRenderModelOptions

```ts
interface DescribeFormerieRenderModelOptions extends DescribeFormerieRenderFieldsOptions {
    includeEmptySteps?: boolean;
}
```

### FormerieHeadingLevel

```ts
type FormerieHeadingLevel = 1 | 2 | 3 | 4 | 5 | 6;
```

### FormerieRenderClassNames

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

### FormerieRenderControl

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

### FormerieRenderField

```ts
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

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

### FormerieRenderStep

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

### FormerieRuntimeMountTarget

```ts
type FormerieRuntimeMountTarget = FormerieTarget | {
    formBound: true;
};
```

### FormerieVerificationHtml

```ts
interface FormerieVerificationHtml {
    attributes: string;
    markup: string;
    scripts: string;
}
```

### FormerieVerificationTokenOptions

```ts
interface FormerieVerificationTokenOptions {
    form: HTMLFormElement;
}
```

### LoadFormerieRuntimeSchemaOptions

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

### MountedFormerieForm

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

### MountFormerieFormOptions

```ts
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

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

### ReadFormerieHostedSchemaOptions

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

### RenderFormerieFormHtmlOptions

```ts
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

```ts
interface RenderFormerieVerificationHtmlOptions {
    containerClass?: string;
    errorClass?: string;
}
```

## Le schéma et les réponses

### applyFormerieValidationErrors

Affiche les erreurs d’une réponse à côté des champs correspondants, et renvoie les chemins qu’elle a placés.

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

### clearFormerieValidationErrors

Efface les erreurs affichées par `applyFormerieValidationErrors`.

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

### collectFormerieFormFields

Lit les réponses d’un élément de formulaire sous forme de champs imbriqués.

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

### createFormerieSubmitPayload

Construit le corps de la soumission à partir de `FormData`, d’un élément de formulaire ou d’un objet.

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

### evaluatePublicCondition

Si une condition d’un schéma public est vraie pour ces réponses.

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

### evaluatePublicFieldVisibility

Le chemin de chaque règle de visibilité, avec son état pour ces réponses.

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

### firstValidationMessageForField

Le premier message d’une réponse pour un chemin de champ, ou `null`.

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

### formDataToFormerieFields

Transforme `FormData` en champs imbriqués.

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

### getPublicFieldVisibility

L’état d’un chemin de champ pour ces réponses.

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

### getPublicSchemaField

Trouve un champ dans un schéma public par son chemin.

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

### isPublicSchemaPathHidden

Si un chemin de champ est masqué pour ces réponses.

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

### listPublicSchemaFields

Énumère tous les champs d’un schéma public, avec leur chemin.

```ts
function listPublicSchemaFields(schema: PublicSchemaInput): PublicSchemaFieldEntry[];
```

### resolveFormerieFieldValue

Lit une valeur par chemin de champ, comme `contact.email`.

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

### resolveHiddenPublicSchemaPaths

Tous les chemins de champ masqués pour ces réponses.

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

### setFormerieFieldValue

Définit une valeur par chemin de champ.

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

### validateFormeriePublicFields

Vérifie des réponses dans le navigateur par rapport à un schéma public, pour une rétroaction rapide. Le serveur garde le dernier mot.

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

### validationIssuesByField

Les problèmes d’une réponse, par chemin de champ.

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

### validationMessagesByField

Les messages d’une réponse, par chemin de champ.

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

### validationMessagesForField

Les messages d’une réponse pour un chemin de champ.

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

### visiblePublicSchemaFields

Énumère les champs visibles pour ces réponses.

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

### ApplyFormerieValidationErrorsOptions

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

### CreateFormerieSubmitPayloadOptions

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

### FormerieFieldCollectionOptions

```ts
interface FormerieFieldCollectionOptions {
    schema?: PublicSchemaInput;
    includeMissingCheckboxes?: boolean;
}
```

### FormeriePublicFieldsValidationResult

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

### PublicSchemaFieldEntry

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

### PublicSchemaInput

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

### ValidateFormeriePublicFieldsOptions

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

## Assistants de cible

### isBrandedFormerieTarget

Si une cible est un formulaire sur un nom d’hôte connecté à un espace de travail.

```ts
function isBrandedFormerieTarget(target: FormerieTarget): target is BrandedFormerieTarget;
```

### schemaFormerieTarget

Lit le schéma d’une cible.

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

### submitFormerieTarget

Soumet à une cible.

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

### validateFormerieTarget

Vérifie des réponses pour une cible.

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

### BrandedFormerieTarget

```ts
interface BrandedFormerieTarget {
    form: string;
    branded: true;
}
```

### CanonicalFormerieTarget

```ts
type CanonicalFormerieTarget = WorkspaceFormerieTarget;
```

### FormerieTarget

```ts
type FormerieTarget = CanonicalFormerieTarget | BrandedFormerieTarget;
```

### WorkspaceFormerieTarget

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

## Types

### BuiltInFieldErrorCode

```ts
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

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

### FormerieClientConfig

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

### FormerieError

```ts
interface FormerieError {
    code: FormerieErrorCode;
    message: string;
}
```

### FormerieErrorCode

```ts
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

```ts
interface FormerieRuntimeClientConfig extends FormerieClientConfig {
}
```

### FormServiceClientConfig

```ts
interface FormServiceClientConfig extends FormerieClientConfig {
}
```

### FormServiceError

```ts
interface FormServiceError extends FormerieError {
}
```

### FormServiceErrorCode

```ts
type FormServiceErrorCode = FormerieErrorCode;
```

### PublicArrayField

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

### PublicCompositeValidator

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

### PublicContextualValidator

```ts
type PublicContextualValidator = PublicFieldValidator | PublicRequiredValidator | PublicCompositeValidator;
```

### PublicFieldValidator

```ts
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

```ts
type PublicFieldVisibilityState = "visible" | "hidden";
```

### PublicFormBehaviorSettings

```ts
interface PublicFormBehaviorSettings {
    submitButtonLabel?: string;
    successMessage?: string;
    successRedirectUrl?: string;
}
```

### PublicFormBrandingSettings

```ts
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

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

### PublicFormLayoutSettings

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

### PublicFormSchemaResponse

```ts
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

```ts
type PublicFormSchemaResult = PublicFormSchemaResponse | SubmitErrorResponse;
```

### PublicFormSettings

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

### PublicFormStep

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

### PublicNativeFieldValidatorType

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

### PublicObjectField

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

### PublicRequiredValidator

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

### PublicScalarField

```ts
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

```ts
type PublicSchemaNode = PublicScalarField | PublicObjectField | PublicArrayField;
```

### PublicValidationAction

```ts
interface PublicValidationAction {
    path: string;
    validator?: PublicContextualValidator;
}
```

### PublicValidationRule

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

### PublicVisibilityRule

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

### SubmitErrorResponse

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

### SubmitPayload

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

### SubmitRequestOptions

```ts
interface SubmitRequestOptions {
    signal?: AbortSignal;
    headers?: HeadersInit;
}
```

### SubmitResponse

```ts
type SubmitResponse = SubmitSuccessResponse | SubmitErrorResponse;
```

### SubmitSuccessResponse

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

### ValidatePayload

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

### ValidateResponse

```ts
type ValidateResponse = ValidateSuccessResponse | SubmitErrorResponse;
```

### ValidateSuccessResponse

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

### ValidationFailedError

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

### ValidationIssue

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