/* * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. */ import * as z from "zod"; import { remap as remap$ } from "../../lib/primitives.js"; import { safeParse } from "../../lib/schemas.js"; import { ClosedEnum } from "../../types/enums.js"; import { Result as SafeParseResult } from "../../types/fp.js"; import { SDKValidationError } from "../errors/sdkvalidationerror.js"; import { FormFieldOption, FormFieldOption$inboundSchema, FormFieldOption$Outbound, FormFieldOption$outboundSchema, } from "./formfieldoption.js"; export const FormFieldType = { Text: "text", Checkbox: "checkbox", Tel: "tel", Email: "email", Url: "url", Textarea: "textarea", Select: "select", FilteredSelect: "filtered-select", MultiSelect: "multi-select", Datetime: "datetime", Date: "date", Time: "time", Number: "number", } as const; export type FormFieldType = ClosedEnum; export type FormField = { /** * The unique identifier of the form field. */ id?: string | undefined; /** * The label of the field */ label?: string | undefined; /** * The placeholder for the form field */ placeholder?: string | null | undefined; /** * The description of the form field */ description?: string | null | undefined; type?: FormFieldType | undefined; /** * Indicates if the form field is required, which means it must be filled in before the form can be submitted */ required?: boolean | undefined; customField?: boolean | undefined; /** * Only applicable to select fields. Allow the user to add a custom value though the option select if the desired value is not in the option select list. */ allowCustomValues?: boolean | undefined; /** * Indicates if the form field is displayed in a “read-only” mode. */ disabled?: boolean | null | undefined; /** * Indicates if the form field is not displayed but the value that is being stored on the connection. */ hidden?: boolean | null | undefined; /** * When the setting is deprecated, it should be hidden from the user interface. The value will still be stored on the connection for the sake of backwards compatibility. */ deprecated?: boolean | null | undefined; /** * Indicates if the form field contains sensitive data, which will display the value as a masked input. */ sensitive?: boolean | null | undefined; /** * Prefix to display in front of the form field. */ prefix?: string | null | undefined; /** * Suffix to display next to the form field. */ suffix?: string | null | undefined; options?: Array | undefined; }; /** @internal */ export const FormFieldType$inboundSchema: z.ZodNativeEnum< typeof FormFieldType > = z.nativeEnum(FormFieldType); /** @internal */ export const FormFieldType$outboundSchema: z.ZodNativeEnum< typeof FormFieldType > = FormFieldType$inboundSchema; /** * @internal * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module. */ export namespace FormFieldType$ { /** @deprecated use `FormFieldType$inboundSchema` instead. */ export const inboundSchema = FormFieldType$inboundSchema; /** @deprecated use `FormFieldType$outboundSchema` instead. */ export const outboundSchema = FormFieldType$outboundSchema; } /** @internal */ export const FormField$inboundSchema: z.ZodType< FormField, z.ZodTypeDef, unknown > = z.object({ id: z.string().optional(), label: z.string().optional(), placeholder: z.nullable(z.string()).optional(), description: z.nullable(z.string()).optional(), type: FormFieldType$inboundSchema.optional(), required: z.boolean().optional(), custom_field: z.boolean().optional(), allow_custom_values: z.boolean().default(false), disabled: z.nullable(z.boolean()).optional(), hidden: z.nullable(z.boolean()).optional(), deprecated: z.nullable(z.boolean()).optional(), sensitive: z.nullable(z.boolean()).optional(), prefix: z.nullable(z.string()).optional(), suffix: z.nullable(z.string()).optional(), options: z.array(FormFieldOption$inboundSchema).optional(), }).transform((v) => { return remap$(v, { "custom_field": "customField", "allow_custom_values": "allowCustomValues", }); }); /** @internal */ export type FormField$Outbound = { id?: string | undefined; label?: string | undefined; placeholder?: string | null | undefined; description?: string | null | undefined; type?: string | undefined; required?: boolean | undefined; custom_field?: boolean | undefined; allow_custom_values: boolean; disabled?: boolean | null | undefined; hidden?: boolean | null | undefined; deprecated?: boolean | null | undefined; sensitive?: boolean | null | undefined; prefix?: string | null | undefined; suffix?: string | null | undefined; options?: Array | undefined; }; /** @internal */ export const FormField$outboundSchema: z.ZodType< FormField$Outbound, z.ZodTypeDef, FormField > = z.object({ id: z.string().optional(), label: z.string().optional(), placeholder: z.nullable(z.string()).optional(), description: z.nullable(z.string()).optional(), type: FormFieldType$outboundSchema.optional(), required: z.boolean().optional(), customField: z.boolean().optional(), allowCustomValues: z.boolean().default(false), disabled: z.nullable(z.boolean()).optional(), hidden: z.nullable(z.boolean()).optional(), deprecated: z.nullable(z.boolean()).optional(), sensitive: z.nullable(z.boolean()).optional(), prefix: z.nullable(z.string()).optional(), suffix: z.nullable(z.string()).optional(), options: z.array(FormFieldOption$outboundSchema).optional(), }).transform((v) => { return remap$(v, { customField: "custom_field", allowCustomValues: "allow_custom_values", }); }); /** * @internal * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module. */ export namespace FormField$ { /** @deprecated use `FormField$inboundSchema` instead. */ export const inboundSchema = FormField$inboundSchema; /** @deprecated use `FormField$outboundSchema` instead. */ export const outboundSchema = FormField$outboundSchema; /** @deprecated use `FormField$Outbound` instead. */ export type Outbound = FormField$Outbound; } export function formFieldToJSON(formField: FormField): string { return JSON.stringify(FormField$outboundSchema.parse(formField)); } export function formFieldFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => FormField$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'FormField' from JSON`, ); }