import {z} from 'zod' export type GetApiCustomersIdAccountOwnershipsArgs = {id: string}; export type GetApiCustomersIdAccountOwnershipsOptions = {baseUrl?: string | undefined, HTTPBearer?: string | undefined, fetch?: typeof fetch | undefined}; export const currency = z.enum(["EUR", "USD", "GBP"]); export const accountStatus = z.enum(["active", "suspended", "closing", "closed"]); export const account = z.object({bank_payment_reference: z.string(), base_currency: currency, can_deposit: z.boolean(), can_place_buy_order: z.boolean(), can_place_sell_order: z.boolean(), can_withdraw: z.boolean(), created_at: z.string(), funding_currencies: z.array(currency), has_deposited: z.boolean(), has_placed_buy_order: z.boolean(), has_placed_sell_order: z.boolean(), has_withdrawn: z.boolean(), id: z.string(), is_primary_owner_mifid_pro: z.boolean(), modified_at: z.string(), name: z.string(), reference: z.string(), status: accountStatus}); export const address = z.object({city: z.string(), country_code: z.string(), district_county: z.string().nullable(), line1: z.string(), line2: z.string().nullable(), line3: z.string().nullable(), postal_code: z.string()}); export const customerStatus = z.enum(["active", "suspended", "closing", "closed"]); export const individualCustomer = z.object({address: address.nullable(), created_at: z.string(), customer_type: z.literal("individual"), date_of_birth: z.string().nullable(), first_name: z.string(), full_name: z.string(), id: z.string(), id_number: z.string().nullable(), last_name: z.string(), mifid_category: z.string().nullable(), modified_at: z.string(), nationalities: z.array(z.string()).nullable(), onboarding: z.string().nullable(), passport_number: z.string().nullable(), phone_number: z.string().nullable(), reference: z.string().nullable(), referrer_code: z.string().nullable(), risk_profile: z.string().nullable(), risk_score: z.string().nullable(), status: customerStatus, tax_number: z.string().nullable()}); export const jointCustomer = z.object({address: address.nullable(), created_at: z.string(), customer_type: z.literal("joint"), first_name: z.string().nullable(), full_name: z.string(), id: z.string(), last_name: z.string().nullable(), mifid_category: z.string().nullable(), modified_at: z.string(), onboarding: z.string().nullable(), phone_number: z.string().nullable(), reference: z.string().nullable(), referrer_code: z.string().nullable(), risk_profile: z.string().nullable(), risk_score: z.string().nullable(), status: customerStatus}); export const businessCustomer = z.object({address: address.nullable(), created_at: z.string(), customer_type: z.literal("business"), entity_name: z.string(), entity_type: z.string().nullable(), full_name: z.string(), id: z.string(), lei_code: z.string().nullable(), lei_code_expiry_date: z.string().nullable(), mifid_category: z.string().nullable(), modified_at: z.string(), onboarding: z.string().nullable(), operating_address: address.nullable(), phone_number: z.string().nullable(), reference: z.string().nullable(), referrer_code: z.string().nullable(), risk_profile: z.string().nullable(), risk_score: z.string().nullable(), status: customerStatus}); export const accountOwnership = z.object({account: account, created_at: z.string(), customer: z.discriminatedUnion("customer_type", [individualCustomer, jointCustomer, businessCustomer]), id: z.string(), is_primary: z.boolean(), modified_at: z.string()}); export const getApiCustomersIdAccountOwnershipsResponse = z.array(accountOwnership); 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 }; /** * List Customer Account Ownerships * * GET /customers/{id}/account-ownerships */ export const getApiCustomersIdAccountOwnerships = async (args: GetApiCustomersIdAccountOwnershipsArgs, options?: GetApiCustomersIdAccountOwnershipsOptions) => { const {baseUrl = "https://api.joinsophic.com", fetch: fetchFn = fetch, HTTPBearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (HTTPBearer !== undefined) headers.set('authorization', `Bearer ${HTTPBearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/customers/${encodeURIComponent(String(args.id))}/account-ownerships${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(getApiCustomersIdAccountOwnershipsResponse, await res.json()) };