import {z} from 'zod' export type GetApiV1FormsFormIdBusinessInformationArgs = {form_id: string}; export type GetApiV1FormsFormIdBusinessInformationOptions = {baseUrl?: string | undefined, AuthToken?: string | undefined, fetch?: typeof fetch | undefined}; export const businessInformation = z.object({id: z.string().optional(), form_id: z.string().optional(), document_ids: z.array(z.string()).optional(), business_country: z.string(), company_name: z.string(), trading_name: z.string().nullable().optional(), legal_entity_type: z.string(), sector: z.string(), company_registration_number: z.string().nullable().optional(), vat_number: z.string().nullable().optional(), incorporation_date: z.string(), business_website: z.string().nullable().optional(), business_activity_description: z.string(), registered_address: z.object({city: z.string(), street: z.string(), country: z.string(), postal_code: z.string(), apartment_number: z.string().nullable().optional(), building_name: z.string().nullable().optional(), building_number: z.string().nullable().optional(), state_or_province: z.string().nullable().optional()}), trading_address: z.object({city: z.string(), street: z.string(), country: z.string(), postal_code: z.string(), apartment_number: z.string().nullable().optional(), building_name: z.string().nullable().optional(), building_number: z.string().nullable().optional(), state_or_province: z.string().nullable().optional()}).optional(), created_at: z.string().optional(), updated_at: z.string().optional()}).nullable(); export const getApiV1FormsFormIdBusinessInformationResponse = z.object({data: businessInformation.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 }; /** * Get business information for specific form * * GET /v1/forms/{form_id}/business_information */ export const getApiV1FormsFormIdBusinessInformation = async (args: GetApiV1FormsFormIdBusinessInformationArgs, options?: GetApiV1FormsFormIdBusinessInformationOptions) => { const {baseUrl = "https://devapi.currencycloud.com/onboarding", fetch: fetchFn = fetch, AuthToken} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (AuthToken !== undefined) headers.set("X-Auth-Token", AuthToken) const url = `${baseUrl.replace(/\/+$/, '')}/v1/forms/${encodeURIComponent(String(args.form_id))}/business_information${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(getApiV1FormsFormIdBusinessInformationResponse, await res.json()) };