import {z} from 'zod' export type SigningRequestSettings = {allow_download?: boolean | undefined, attach_pdf_on_finish?: boolean | undefined, allow_editing_before_sending?: boolean | undefined, use_signing_order?: boolean | undefined, hand_drawn_only?: boolean | undefined, send_signing_email?: boolean | undefined, send_finish_email?: boolean | undefined, send_expiration_email?: boolean | undefined, send_cancellation_email?: boolean | undefined, require_otp_verification?: (boolean | null) | undefined, disable_guided_navigation?: (boolean | null) | undefined, allow_presigning_download?: (boolean | null) | undefined, show_qr_code?: (boolean | null) | undefined, allow_decline?: (boolean | null) | undefined, show_save_for_later?: (boolean | null) | undefined, identity_editable_fields?: (Array | null) | undefined, notify_identity_change_email?: boolean | undefined}; export type Recipient = {id?: string | undefined, _temp_id?: string | undefined, template_user_id?: string | undefined, first_name: string, last_name?: string | undefined, email: string, designation: 'Signer' | 'Approver' | 'CC', order?: number | undefined, phone_number?: (string | null) | undefined, street_address?: (string | null) | undefined, city?: (string | null) | undefined, state_province?: (string | null) | undefined, postal_code?: (string | null) | undefined, country?: (string | null) | undefined, title?: (string | null) | undefined, company?: (string | null) | undefined, custom_fields?: {[key: string]: unknown} | undefined}; export type DeletedRecipient = {recipient_id: string, field_action: 'delete' | 'reassign', reassign_to_recipient_id?: string | undefined}; export type DateFormatRules = {dateFormat?: ('MM/dd/yyyy' | 'dd/MM/yyyy' | 'yyyy-MM-dd' | 'MMMM dd, yyyy' | 'MMM dd, yyyy' | 'dd MMMM yyyy') | undefined, fontSize?: number | undefined}; export type FileFormatRules = {acceptedFileTypes?: ('image_and_pdf' | 'image' | 'pdf') | undefined}; export type FieldValidationRules = {[key: string]: unknown} | null; export type Condition = {field_id: string, operator: 'is_filled' | 'is_empty' | 'equals' | 'not_equals' | 'contains' | 'not_contains' | 'greater_than' | 'less_than' | 'greater_than_or_equal' | 'less_than_or_equal', value?: (string | number | null) | undefined}; export type ConditionGroup = {conditions: Array}; export type ConditionSet = {logic: 'and' | 'or', groups: Array}; export type Field = {id?: string | undefined, template_field_id?: string | undefined, type: 'signature' | 'text' | 'date' | 'checkbox' | 'dropdown' | 'initial' | 'initials' | 'text_area' | 'textarea' | 'image' | 'stamp' | 'approval_signature' | 'approval_checkmark' | 'approval_date', position: {x: number, y: number, width: number, height: number}, page_number: number, required?: boolean | undefined, recipient_id?: string | undefined, variable_name?: (string | null) | undefined, variable_defined_name?: (string | null) | undefined, dropdown_options?: (Array | Record) | undefined, date_default?: (string | null) | undefined, date_signing_default?: boolean | undefined, multi_group_id?: (string | null) | undefined, format_rules?: (DateFormatRules | FileFormatRules | {[key: string]: unknown} | null) | undefined, validation_rules?: FieldValidationRules | undefined, read_only?: boolean | undefined, read_only_value?: (string | null) | undefined, prefilled_data?: ('first_name' | 'last_name' | 'full_name' | 'email' | 'phone_number' | 'company' | 'title' | 'street_address' | 'city' | 'state_province' | 'postal_code' | 'country' | null) | undefined, required_conditions?: ConditionSet | undefined, visibility_conditions?: ConditionSet | undefined, background_color?: (string | null) | undefined, seal_participant_temp_id?: (string | null) | undefined}; export type SigningRequestReminder = {id?: string | undefined, hours: number, all_users?: boolean | undefined, recipient_id?: (string | null) | undefined, subject: string, message: string}; export type UpdateSigningRequestBodySchema = {signing_request_properties?: ({name?: string | undefined, description?: string | undefined, document?: string | undefined, expiration_hours?: number | undefined, settings?: SigningRequestSettings | undefined, completion_title?: (string | null) | undefined, completion_message?: (string | null) | undefined, completion_redirect_url?: (string | null) | undefined, completion_redirect_delay?: (number | null) | undefined}) | undefined, recipients?: Array | undefined, deleted_recipients?: Array | undefined, force_remove_conditions?: boolean | undefined, fields?: Array | undefined, reminders?: Array | undefined, language?: ('en' | 'es' | 'it' | 'pt' | 'fr' | 'de' | 'el' | 'ru' | 'pl' | 'cs' | 'sv' | 'nl' | 'ro' | 'nb' | 'ca' | null) | undefined, documents_layout_version?: number | undefined}; export type UpdateApiSigningRequestsIdArgs = {id: string, body: UpdateSigningRequestBodySchema}; export type UpdateApiSigningRequestsIdOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const recipient = z.object({id: z.string().optional(), _temp_id: z.string().optional(), template_user_id: z.string().optional(), first_name: z.string().max(100), last_name: z.string().max(100).optional(), email: z.string().max(255), designation: z.enum(["Signer", "Approver", "CC"]), order: z.number().int().gte(1).optional(), phone_number: z.string().max(50).nullable().optional(), street_address: z.string().max(255).nullable().optional(), city: z.string().max(100).nullable().optional(), state_province: z.string().max(100).nullable().optional(), postal_code: z.string().max(20).nullable().optional(), country: z.string().max(100).nullable().optional(), title: z.string().max(100).nullable().optional(), company: z.string().max(255).nullable().optional(), custom_fields: z.record(z.string(), z.unknown()).optional()}); export const reminder = z.object({id: z.string(), hours: z.number().int().gte(1), subject: z.string().max(255), message: z.string().max(5000), all_users: z.boolean().optional(), template_user_id: z.string().nullable().optional(), recipient_id: z.string().nullable().optional(), sent_on: z.string().nullable().optional(), created_at: z.string().optional(), updated_at: z.string().optional()}); export const signingRequestUpdateResponse = z.object({id: z.string(), name: z.string(), signing_request: z.object({id: z.string().optional(), name: z.string().optional(), description: z.string().nullable().optional(), document_url: z.string().optional(), document_url_expires_at: z.string().nullable().optional(), document_page_count: z.number().int().optional(), status: z.string().optional(), expiration_hours: z.number().int().optional(), settings: z.object({allow_download: z.boolean().optional(), attach_pdf_on_finish: z.boolean().optional(), hand_drawn_only: z.boolean().optional()}).optional(), template_id: z.string().nullable().optional(), expires_at: z.string().nullable().optional(), created_date: z.string().optional(), sent_date: z.string().nullable().optional(), finished_date: z.string().nullable().optional(), cancelled_date: z.string().nullable().optional()}).optional(), recipients: z.array(recipient).optional(), reminders: z.array(reminder).optional(), summary: z.object({properties_updated: z.boolean().optional(), recipients_created: z.number().int().optional(), recipients_updated: z.number().int().optional(), recipients_deleted: z.number().int().optional(), fields_created: z.number().int().optional(), fields_updated: z.number().int().optional(), fields_reassigned: z.number().int().optional(), fields_deleted: z.number().int().optional(), reminders_created: z.number().int().optional(), reminders_updated: z.number().int().optional(), warnings: z.array(z.string()).optional()}).optional()}); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * Comprehensive Update Signing Request * * PUT /signing-requests/{id} */ export const updateApiSigningRequestsId = async (args: UpdateApiSigningRequestsIdArgs, options?: UpdateApiSigningRequestsIdOptions) => { const {baseUrl = "https://api.firma.dev/functions/v1/signing-request-api", fetch: fetchFn = fetch, ApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (ApiKeyAuth !== undefined) headers.set("Authorization", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/signing-requests/${encodeURIComponent(String(args.id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(signingRequestUpdateResponse, await res.json()) };