import {z} from 'zod' export type LegalEntityType = 'company' | 'individual'; export type Individual = {name?: string | undefined, birth_date?: string | undefined, phone_number?: string | undefined, email?: string | undefined, address_line?: string | undefined, address_line_2?: string | undefined, address_postal_code?: string | undefined, address_city?: string | undefined, address_country?: unknown | undefined}; export type BankAccountCountryCode = string; export type ApprovalsBankAccount = {bank_name?: string | undefined, bank_account_number?: string | undefined, bank_account_number_type?: ('IBAN' | 'BBAN') | undefined, bank_account_country_code?: BankAccountCountryCode | undefined, bank_account_currency: unknown, payout_currency: unknown, bank_identification_code?: string | undefined}; export type ApprovalsPayoutDestination = {id?: string | undefined, created_at?: string | undefined, created_by?: string | undefined, updated_at?: string | undefined, deleted_by?: string | undefined, deleted_at?: string | undefined, language?: ('en' | 'no') | undefined, payout_destination_id: string, payout_destination_name?: string | undefined, payout_destination_description?: string | undefined, payout_reference: string, type?: LegalEntityType | undefined, country_code?: unknown | undefined, organization_number?: string | undefined, individual?: Individual | undefined, bank_accounts: Array, payout_interval_type?: ('daily' | 'weekly' | 'monthly' | 'manual') | undefined, form_submitter?: ({email?: string | undefined, name?: string | undefined, title?: string | undefined}) | undefined, settlement_report_configuration?: {emails: Array} | undefined, report_configuration?: ({create_report_configuration: boolean, email?: string | undefined, schedule?: ('daily' | 'weekly' | 'monthly') | undefined, reference?: string | undefined, content_types?: (Array<'application/pdf' | 'text/csv'>) | undefined}) | undefined}; export type CreateApiAccountsAidManagementSettingsApprovalsPayoutDestinationsArgs = {aid: unknown, body: ApprovalsPayoutDestination}; export type CreateApiAccountsAidManagementSettingsApprovalsPayoutDestinationsOptions = {baseUrl?: string | undefined, JWT?: string | undefined, fetch?: typeof fetch | undefined}; export const legalEntityType = z.enum(["company", "individual"]); export const individual = z.object({name: z.string().optional(), birth_date: z.string().optional(), phone_number: z.string().optional(), email: z.string().optional(), address_line: z.string().optional(), address_line_2: z.string().optional(), address_postal_code: z.string().optional(), address_city: z.string().optional(), address_country: z.string().optional()}); export const bankAccountCountryCode = z.string().min(2).max(2); export const approvalsBankAccount = z.object({bank_name: z.string().optional(), bank_account_number: z.string().optional(), bank_account_number_type: z.enum(["IBAN", "BBAN"]).optional(), bank_account_country_code: bankAccountCountryCode.optional(), bank_account_currency: z.string(), payout_currency: z.string(), bank_identification_code: z.string().optional()}); export const approvalStatus = z.enum(["ACTIVE", "DECLINED", "UNDER_MANUAL_REVIEW", "AUTOMATIC_REVIEW", "WAITING_FOR_SIGNATURE", "WAITING_FOR_DECLARATION", "ERROR", "ARCHIVED", "WAITING_FOR_DETAILS", "TERMINATED"]); export const approvalLinks = z.array(z.object({href: z.string().optional(), rel: z.enum(["contract_url", "cdd_case_url", "dintero_cdd_case_url", "declaration_url", "signed_contract_file_url"]).optional()})); export const approvalsPayoutDestinationResponse = z.object({id: z.string().optional(), created_at: z.string().optional(), created_by: z.string().optional(), updated_at: z.string().optional(), deleted_by: z.string().optional(), deleted_at: z.string().optional(), language: z.enum(["en", "no"]).max(2).optional(), payout_destination_id: z.string().max(40), payout_destination_name: z.string().max(60).optional(), payout_destination_description: z.string().max(1000).optional(), payout_reference: z.string().max(60), type: legalEntityType.optional(), country_code: z.string().min(2).max(2).optional(), organization_number: z.string().optional(), individual: individual.optional(), bank_accounts: z.array(approvalsBankAccount), payout_interval_type: z.enum(["daily", "weekly", "monthly", "manual"]).optional(), form_submitter: z.object({email: z.string().optional(), name: z.string().optional(), title: z.string().optional()}).optional(), settlement_report_configuration: z.object({emails: z.array(z.string())}).optional(), report_configuration: z.object({create_report_configuration: z.boolean(), email: z.string().optional(), schedule: z.enum(["daily", "weekly", "monthly"]).optional(), reference: z.string().optional(), content_types: z.array(z.enum(["application/pdf", "text/csv"])).optional()}).optional(), case_status: approvalStatus.optional(), links: approvalLinks.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 }; /** * aid_management_settings_approvals_payout_destinations_post * * POST /accounts/{aid}/management/settings/approvals/payout-destinations */ export const createApiAccountsAidManagementSettingsApprovalsPayoutDestinations = async (args: CreateApiAccountsAidManagementSettingsApprovalsPayoutDestinationsArgs, options?: CreateApiAccountsAidManagementSettingsApprovalsPayoutDestinationsOptions) => { const {baseUrl = "https://api.dintero.com/v1", fetch: fetchFn = fetch, JWT} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (JWT !== undefined) headers.set('authorization', `Bearer ${JWT}`) const url = `${baseUrl.replace(/\/+$/, '')}/accounts/${encodeURIComponent(String(args.aid))}/management/settings/approvals/payout-destinations${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", 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(approvalsPayoutDestinationResponse, await res.json()) };