import {z} from 'zod' export type ShareholderPatch = {ownership_details?: ({ownership_share?: number | undefined, ownership_roles?: (Array<'owner' | 'director' | 'executive' | 'representative' | 'user'>) | undefined, id_type?: ('drivers_license' | 'identification_card' | 'passport') | undefined, id_number?: string | undefined, id_issue_country?: string | undefined}) | undefined, legal_entity?: ({id?: string | undefined, type: 'company', company_name?: string | undefined, company_number?: string | undefined, vat_number?: string | undefined, tax_id?: string | undefined, company_structure?: ('limited_liability_company' | 'private_limited_company' | 'public_limited_company' | 'general_partnership' | 'limited_liability_partnership' | 'limited_partnership' | 'limited_liability_entrep_company' | 'joint_stock_company' | 'single_member_llc' | 'multi_member_llc' | 'private_partnership' | 'private_corporation' | 'public_company') | undefined, country_of_incorporation?: string | undefined, incorporation_date?: string | undefined, registered_office_address?: ({address_line1: string, address_line2?: string | undefined, apartment?: string | undefined, city: string, state_province?: string | undefined, country: string, postal_code: string, company_name?: string | undefined}) | undefined, company_operating_address?: ({address_line1: string, address_line2?: string | undefined, apartment?: string | undefined, city: string, state_province?: string | undefined, country: string, postal_code: string, company_name?: string | undefined}) | undefined, contact_name?: string | undefined, contact_email?: string | undefined, contact_phone_number?: string | undefined, annual_revenue_amount?: number | undefined, annual_revenue_currency?: string | undefined, employees_number?: ('small' | 'medium' | 'large' | 'enterprise') | undefined} | {id?: string | undefined, type: 'individual', first_name?: string | undefined, last_name?: string | undefined, email?: string | undefined, phone_number?: string | undefined, dob?: string | undefined, citizenship?: string | undefined, residency_address?: ({address_line1: string, address_line2?: string | undefined, apartment?: string | undefined, city: string, state_province?: string | undefined, country: string, postal_code: string, company_name?: string | undefined}) | undefined}) | undefined}; export type PatchApiApiV1MerchantsMerchantIdShareholdersShareholderIdArgs = {merchantId: string, shareholderId: string, body: ShareholderPatch}; export type PatchApiApiV1MerchantsMerchantIdShareholdersShareholderIdOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const shareholderResponse = z.object({success: z.boolean(), data: z.object({id: z.string(), ownership_details: z.object({ownership_share: z.number().gte(0).lte(100), ownership_roles: z.array(z.union([z.literal("owner"), z.literal("director"), z.literal("executive"), z.literal("representative"), z.literal("user")])), id_type: z.union([z.literal("drivers_license"), z.literal("identification_card"), z.literal("passport")]).optional(), id_number: z.string().optional(), id_issue_country: z.string().min(2).max(2).optional()}), legal_entity: z.discriminatedUnion("type", [z.object({id: z.string(), verification_required: z.boolean(), verification_link: z.string().optional(), verification_status: z.union([z.literal("pending_verification"), z.literal("in_review"), z.literal("more_information_required"), z.literal("verified"), z.literal("rejected")]), type: z.literal("company"), company_name: z.string().min(2).max(30), company_number: z.string().min(4).max(20), vat_number: z.string().min(4).max(20).optional(), tax_id: z.string().min(4).max(20).optional(), company_structure: z.union([z.literal("limited_liability_company"), z.literal("private_limited_company"), z.literal("public_limited_company"), z.literal("general_partnership"), z.literal("limited_liability_partnership"), z.literal("limited_partnership"), z.literal("limited_liability_entrep_company"), z.literal("joint_stock_company"), z.literal("single_member_llc"), z.literal("multi_member_llc"), z.literal("private_partnership"), z.literal("private_corporation"), z.literal("public_company")]), country_of_incorporation: z.string().min(2).max(2), incorporation_date: z.string().optional(), registered_office_address: z.object({address_line1: z.string(), address_line2: z.string().optional(), apartment: z.string().optional(), city: z.string(), state_province: z.string().optional(), country: z.string().min(2).max(2), postal_code: z.string(), company_name: z.string().optional()}), company_operating_address: z.object({address_line1: z.string(), address_line2: z.string().optional(), apartment: z.string().optional(), city: z.string(), state_province: z.string().optional(), country: z.string().min(2).max(2), postal_code: z.string(), company_name: z.string().optional()}).optional(), contact_name: z.string().min(2).max(30), contact_email: z.string(), contact_phone_number: z.string(), annual_revenue_amount: z.number().optional(), annual_revenue_currency: z.string().min(3).max(3).optional(), employees_number: z.union([z.literal("small"), z.literal("medium"), z.literal("large"), z.literal("enterprise")]).optional()}), z.object({id: z.string(), verification_required: z.boolean(), verification_link: z.string().optional(), verification_status: z.union([z.literal("pending_verification"), z.literal("in_review"), z.literal("more_information_required"), z.literal("verified"), z.literal("rejected")]), type: z.literal("individual"), first_name: z.string().min(1).max(30), last_name: z.string().min(1).max(30), email: z.string(), phone_number: z.string(), dob: z.string(), citizenship: z.string().min(2).max(2), residency_address: z.object({address_line1: z.string(), address_line2: z.string().optional(), apartment: z.string().optional(), city: z.string(), state_province: z.string().optional(), country: z.string().min(2).max(2), postal_code: z.string(), company_name: z.string().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 }; /** * Partially update a shareholder for a Merchant Legal Entity * * PATCH /api/v1/merchants/{merchantId}/shareholders/{shareholderId} */ export const patchApiApiV1MerchantsMerchantIdShareholdersShareholderId = async (args: PatchApiApiV1MerchantsMerchantIdShareholdersShareholderIdArgs, options?: PatchApiApiV1MerchantsMerchantIdShareholdersShareholderIdOptions) => { const {baseUrl = "https://core.quidkey.com", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/merchants/${encodeURIComponent(String(args.merchantId))}/shareholders/${encodeURIComponent(String(args.shareholderId))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", 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(shareholderResponse, await res.json()) };