import {z} from 'zod' export type GetApiPersonsPersonIdUpdatesArgs = {person_id: string, cursor?: string | undefined, limit?: number | undefined, 'LMG-Data-Privacy-Access-Principal': string, 'LMG-Data-Privacy-Access-Justification': string}; export type GetApiPersonsPersonIdUpdatesOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const employmentStatus = z.enum(["apprenticeship", "company_owner", "employed", "managing_director", "public_official", "retired", "self_employed", "student", "unemployed"]); export const annualSalary = z.enum(["lt_50k_eur", "gte_50k_lt_75k_eur", "gte_75k_lt_100k_eur", "gte_100k_lt_150k_eur", "gte_150k_eur"]); export const industrySector = z.enum(["agriculture", "commodities", "construction", "education", "financial_services", "gambling", "healthcare", "it", "jewellery_trading", "manufacturing", "precious_metals_trading", "professional_services", "public_sector", "real_estate", "retail", "service_industry", "sport", "tourism", "transport", "used_vehicles_trading", "weapons_trading", "other"]); export const personDataUpdateTaxResidency = z.object({country: z.string().min(2).max(2), tax_identification_number: z.string().min(1).max(255)}); export const personDataUpdateRequestStatus = z.enum(["created", "processing", "success", "failure"]); export const statusChangePersonDataUpdateRequestStatus = z.object({status: personDataUpdateRequestStatus, timestamp: z.string()}); export const personDataUpdateAnnotatedResponse = z.object({id: z.string(), type: z.enum(["email", "phone_number", "registered_address", "employment", "tax_residencies"]), email: z.string().optional(), number: z.string().min(1).max(45).optional(), line_1: z.string().max(255).optional(), line_2: z.string().max(255).nullable().optional(), postal_code: z.string().max(20).optional(), city: z.string().max(255).optional(), country: z.string().min(2).max(2).optional(), status: employmentStatus.optional(), annual_salary: annualSalary.optional(), sector: industrySector.optional(), residencies: z.array(personDataUpdateTaxResidency).optional(), history: z.array(statusChangePersonDataUpdateRequestStatus)}); export const encodedPaginationResponse = z.object({next_cursor: z.string().optional()}); export const encodedPaginatedCollectionResponsePersonDataUpdateAnnotatedResponse = z.object({data: z.array(personDataUpdateAnnotatedResponse), pagination: encodedPaginationResponse}); 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 Person Data Update Requests * * GET /persons/{person_id}/updates */ export const getApiPersonsPersonIdUpdates = async (args: GetApiPersonsPersonIdUpdatesArgs, options?: GetApiPersonsPersonIdUpdatesOptions) => { const {baseUrl = "https://sandbox.api.lemon.markets/v1", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.cursor != null) query.append("cursor", String(args.cursor)) if (args.limit != null) query.append("limit", String(args.limit)) if (args['LMG-Data-Privacy-Access-Principal'] != null) headers.set("LMG-Data-Privacy-Access-Principal", String(args['LMG-Data-Privacy-Access-Principal'])) if (args['LMG-Data-Privacy-Access-Justification'] != null) headers.set("LMG-Data-Privacy-Access-Justification", String(args['LMG-Data-Privacy-Access-Justification'])) if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/persons/${encodeURIComponent(String(args.person_id))}/updates${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(encodedPaginatedCollectionResponsePersonDataUpdateAnnotatedResponse, await res.json()) };