import {z} from 'zod' export type IdentityClaimWriteRequest = {based_on?: (number | null) | undefined, claim_type: 'identity', date_of_birth: string, first_name: string, last_name: string, reference?: (string | null) | undefined}; export type NationalityBasis = 'birth' | 'naturalisation' | 'descent' | 'marriage' | 'investment_programme' | 'other'; export type NationalityEntry = {basis?: (NationalityBasis | null) | undefined, country_code: string}; export type NationalitiesClaimWriteRequest = {based_on?: (number | null) | undefined, claim_type: 'nationalities', nationalities?: Array | undefined, reference?: (string | null) | undefined}; export type ResidenceClaimWriteRequest = {based_on?: (number | null) | undefined, city: string, claim_type: 'residence', country_code: string, district_county?: (string | null) | undefined, line1: string, line2?: (string | null) | undefined, line3?: (string | null) | undefined, postal_code: string, reference?: (string | null) | undefined}; export type TinExemptionReason = 'not_issued' | 'pending_application' | 'not_required'; export type TaxResidencyEntry = {country_code: string, tin?: (string | null) | undefined, tin_exemption_reason?: (TinExemptionReason | null) | undefined}; export type TaxResidenciesClaimWriteRequest = {based_on?: (number | null) | undefined, claim_type: 'tax_residencies', reference?: (string | null) | undefined, tax_residencies?: Array | undefined}; export type FatcaStatusClaimWriteRequest = {based_on?: (number | null) | undefined, claim_type: 'fatca_status', is_us_person: boolean, reference?: (string | null) | undefined}; export type PepStatusClaimWriteRequest = {based_on?: (number | null) | undefined, claim_type: 'pep_status', has_pep_association: boolean, is_pep: boolean, pep_associate_name?: (string | null) | undefined, pep_associate_relationship?: (string | null) | undefined, pep_role?: (string | null) | undefined, pep_role_end_date?: (string | null) | undefined, pep_role_start_date?: (string | null) | undefined, reference?: (string | null) | undefined}; export type ClaimEducationLevel = 'none' | 'secondary' | 'bachelors' | 'masters' | 'doctorate' | 'professional'; export type EducationLevelClaimWriteRequest = {based_on?: (number | null) | undefined, claim_type: 'education_level', education_level: ClaimEducationLevel, reference?: (string | null) | undefined}; export type ClaimEmploymentStatus = 'employed' | 'self_employed' | 'retired' | 'student' | 'unemployed'; export type ClaimIndustry = 'accountancy' | 'admin_secretarial' | 'agricultural' | 'arms_trade' | 'catering_hospitality' | 'company_services' | 'consulting' | 'creative_media' | 'defence_military' | 'education' | 'emergency_services' | 'energy' | 'export_import' | 'financial_services' | 'gambling' | 'government_public_sector' | 'health_medical' | 'legal' | 'leisure_entertainment_tourism' | 'manufacturing' | 'marketing_pr_advertising' | 'ngo' | 'nonprofit_charity' | 'oil_gas_mining' | 'pharmaceuticals' | 'precious_metals_stones' | 'professional_services' | 'property_construction_trade' | 'retail' | 'social_care_services' | 'technology' | 'telecommunications' | 'transport_logistics' | 'adult_entertainment' | 'cannabis_cbd' | 'cryptocurrencies' | 'embassy_consulate' | 'other'; export type EmploymentClaimWriteRequest = {based_on?: (number | null) | undefined, claim_type: 'employment', employment_status: ClaimEmploymentStatus, industry?: (ClaimIndustry | null) | undefined, industry_other?: (string | null) | undefined, reference?: (string | null) | undefined}; export type EurAmountBand = 'lt_50k' | '50k_100k' | '100k_250k' | '250k_500k' | '500k_1m' | '1m_3m' | 'gt_3m'; export type ClaimIncomeSource = 'salary' | 'pension' | 'rental_income' | 'dividends' | 'interest'; export type ClaimWealthSource = 'savings' | 'inheritance' | 'trust_fund' | 'investments' | 'borrowings' | 'real_estate'; export type FinancialProfileClaimWriteRequest = {annual_income_eur: EurAmountBand, based_on?: (number | null) | undefined, claim_type: 'financial_profile', income_sources: Array, net_worth_eur: EurAmountBand, reference?: (string | null) | undefined, wealth_sources: Array}; export type ClaimAssetClass = 'treasury_bills' | 'bonds' | 'equities' | 'etfs' | 'mutual_funds' | 'fx' | 'cfds' | 'derivatives' | 'crypto'; export type InvestmentExperienceClaimWriteRequest = {asset_classes?: Array | undefined, based_on?: (number | null) | undefined, claim_type: 'investment_experience', has_prior_experience: boolean, reference?: (string | null) | undefined}; export type ExpectedActivityClaimWriteRequest = {annual_transactions: string, asset_classes: Array, based_on?: (number | null) | undefined, claim_type: 'expected_activity', funding_currency: string, investment_amount: string, reference?: (string | null) | undefined}; export type ControlType = 'ownership' | 'voting' | 'other'; export type PersonRelationshipType = 'director' | 'shareholder' | 'beneficial_owner' | 'trustee' | 'settlor' | 'authorised_signatory' | 'senior_management'; export type RelationshipEntryInput = {appointment_date?: (string | null) | undefined, authority_scope?: (string | null) | undefined, control_type?: (ControlType | null) | undefined, end_date?: (string | null) | undefined, ownership_percentage?: (number | string | null) | undefined, position?: (string | null) | undefined, related_person: string, relationship_type: PersonRelationshipType}; export type RelationshipsClaimWriteRequest = {based_on?: (number | null) | undefined, claim_type: 'relationships', reference?: (string | null) | undefined, relationships: Array}; export type ClaimRegistrationEntityType = 'private_company' | 'public_company' | 'listed_company' | 'investment_firm' | 'pension_provident_fund' | 'investment_fund' | 'insurance_firm' | 'trust' | 'partnership' | 'bank_emi'; export type RegistrationClaimWriteRequest = {based_on?: (number | null) | undefined, claim_type: 'registration', country_of_incorporation: string, date_of_incorporation: string, entity_type: ClaimRegistrationEntityType, legal_name: string, reference?: (string | null) | undefined, registration_number: string, trading_name?: (string | null) | undefined}; export type ContactDetailsClaimWriteRequest = {based_on?: (number | null) | undefined, claim_type: 'contact_details', email?: (string | null) | undefined, phone_number: string, reference?: (string | null) | undefined}; export type LeiClaimWriteRequest = {based_on?: (number | null) | undefined, claim_type: 'lei', expiry_date: string, identifier: string, reference?: (string | null) | undefined}; export type RegisteredAddressClaimWriteRequest = {based_on?: (number | null) | undefined, city: string, claim_type: 'registered_address', country_code: string, district_county?: (string | null) | undefined, line1: string, line2?: (string | null) | undefined, line3?: (string | null) | undefined, operating_address_is_same?: boolean | undefined, postal_code: string, reference?: (string | null) | undefined}; export type OperatingAddressClaimWriteRequest = {based_on?: (number | null) | undefined, city: string, claim_type: 'operating_address', country_code: string, district_county?: (string | null) | undefined, line1: string, line2?: (string | null) | undefined, line3?: (string | null) | undefined, postal_code: string, reference?: (string | null) | undefined}; export type BusinessNatureClaimWriteRequest = {annual_turnover_eur: EurAmountBand, based_on?: (number | null) | undefined, business_activity: ClaimIndustry, business_activity_other?: (string | null) | undefined, claim_type: 'business_nature', has_nominee_shareholders: boolean, has_shell_bank_relationships: boolean, is_regulated: boolean, issues_bearer_shares: boolean, license_number?: (string | null) | undefined, reference?: (string | null) | undefined}; export type CreateApiPersonsPersonIdClaimsClaimIdVersionsArgs = {person_id: string, claim_id: string, 'Idempotency-Key'?: (string | null) | undefined, body: IdentityClaimWriteRequest | NationalitiesClaimWriteRequest | ResidenceClaimWriteRequest | TaxResidenciesClaimWriteRequest | FatcaStatusClaimWriteRequest | PepStatusClaimWriteRequest | EducationLevelClaimWriteRequest | EmploymentClaimWriteRequest | FinancialProfileClaimWriteRequest | InvestmentExperienceClaimWriteRequest | ExpectedActivityClaimWriteRequest | RelationshipsClaimWriteRequest | RegistrationClaimWriteRequest | ContactDetailsClaimWriteRequest | LeiClaimWriteRequest | RegisteredAddressClaimWriteRequest | OperatingAddressClaimWriteRequest | BusinessNatureClaimWriteRequest}; export type CreateApiPersonsPersonIdClaimsClaimIdVersionsOptions = {baseUrl?: string | undefined, HTTPBearer?: string | undefined, fetch?: typeof fetch | undefined}; export const claimType = z.enum(["identity", "nationalities", "residence", "tax_residencies", "fatca_status", "pep_status", "education_level", "employment", "financial_profile", "investment_experience", "expected_activity", "relationships", "registration", "contact_details", "lei", "registered_address", "operating_address", "business_nature"]); export const claimSummary = z.object({archived_at: z.string().nullable(), claim_type: claimType, created_at: z.string(), id: z.string(), person: z.string()}); export const identityClaimSpec = z.object({claim_type: z.literal("identity"), date_of_birth: z.string(), first_name: z.string(), last_name: z.string()}); export const nationalityBasis = z.enum(["birth", "naturalisation", "descent", "marriage", "investment_programme", "other"]); export const nationalityEntry = z.object({basis: nationalityBasis.nullable().optional(), country_code: z.string()}); export const nationalitiesClaimSpec = z.object({claim_type: z.literal("nationalities"), nationalities: z.array(nationalityEntry).optional()}); export const residenceClaimSpec = z.object({city: z.string(), claim_type: z.literal("residence"), country_code: z.string(), district_county: z.string().nullable().optional(), line1: z.string(), line2: z.string().nullable().optional(), line3: z.string().nullable().optional(), postal_code: z.string()}); export const tinExemptionReason = z.enum(["not_issued", "pending_application", "not_required"]); export const taxResidencyEntry = z.object({country_code: z.string(), tin: z.string().nullable().optional(), tin_exemption_reason: tinExemptionReason.nullable().optional()}); export const taxResidenciesClaimSpec = z.object({claim_type: z.literal("tax_residencies"), tax_residencies: z.array(taxResidencyEntry).optional()}); export const fatcaStatusClaimSpec = z.object({claim_type: z.literal("fatca_status"), is_us_person: z.boolean()}); export const pepStatusClaimSpec = z.object({claim_type: z.literal("pep_status"), has_pep_association: z.boolean(), is_pep: z.boolean(), pep_associate_name: z.string().nullable().optional(), pep_associate_relationship: z.string().nullable().optional(), pep_role: z.string().nullable().optional(), pep_role_end_date: z.string().nullable().optional(), pep_role_start_date: z.string().nullable().optional()}); export const claimEducationLevel = z.enum(["none", "secondary", "bachelors", "masters", "doctorate", "professional"]); export const educationLevelClaimSpec = z.object({claim_type: z.literal("education_level"), education_level: claimEducationLevel}); export const claimEmploymentStatus = z.enum(["employed", "self_employed", "retired", "student", "unemployed"]); export const claimIndustry = z.enum(["accountancy", "admin_secretarial", "agricultural", "arms_trade", "catering_hospitality", "company_services", "consulting", "creative_media", "defence_military", "education", "emergency_services", "energy", "export_import", "financial_services", "gambling", "government_public_sector", "health_medical", "legal", "leisure_entertainment_tourism", "manufacturing", "marketing_pr_advertising", "ngo", "nonprofit_charity", "oil_gas_mining", "pharmaceuticals", "precious_metals_stones", "professional_services", "property_construction_trade", "retail", "social_care_services", "technology", "telecommunications", "transport_logistics", "adult_entertainment", "cannabis_cbd", "cryptocurrencies", "embassy_consulate", "other"]); export const employmentClaimSpec = z.object({claim_type: z.literal("employment"), employment_status: claimEmploymentStatus, industry: claimIndustry.nullable().optional(), industry_other: z.string().nullable().optional()}); export const eurAmountBand = z.enum(["lt_50k", "50k_100k", "100k_250k", "250k_500k", "500k_1m", "1m_3m", "gt_3m"]); export const claimIncomeSource = z.enum(["salary", "pension", "rental_income", "dividends", "interest"]); export const claimWealthSource = z.enum(["savings", "inheritance", "trust_fund", "investments", "borrowings", "real_estate"]); export const financialProfileClaimSpec = z.object({annual_income_eur: eurAmountBand, claim_type: z.literal("financial_profile"), income_sources: z.array(claimIncomeSource), net_worth_eur: eurAmountBand, wealth_sources: z.array(claimWealthSource)}); export const claimAssetClass = z.enum(["treasury_bills", "bonds", "equities", "etfs", "mutual_funds", "fx", "cfds", "derivatives", "crypto"]); export const investmentExperienceClaimSpec = z.object({asset_classes: z.array(claimAssetClass).optional(), claim_type: z.literal("investment_experience"), has_prior_experience: z.boolean()}); export const expectedActivityClaimSpec = z.object({annual_transactions: z.string(), asset_classes: z.array(z.string()), claim_type: z.literal("expected_activity"), funding_currency: z.string(), investment_amount: z.string()}); export const controlType = z.enum(["ownership", "voting", "other"]); export const personRelationshipType = z.enum(["director", "shareholder", "beneficial_owner", "trustee", "settlor", "authorised_signatory", "senior_management"]); export const relationshipEntryOutput = z.object({appointment_date: z.string().nullable().optional(), authority_scope: z.string().nullable().optional(), control_type: controlType.nullable().optional(), end_date: z.string().nullable().optional(), ownership_percentage: z.string().nullable().optional(), position: z.string().nullable().optional(), related_person: z.string(), relationship_type: personRelationshipType}); export const relationshipsClaimSpecOutput = z.object({claim_type: z.literal("relationships"), relationships: z.array(relationshipEntryOutput)}); export const claimRegistrationEntityType = z.enum(["private_company", "public_company", "listed_company", "investment_firm", "pension_provident_fund", "investment_fund", "insurance_firm", "trust", "partnership", "bank_emi"]); export const registrationClaimSpec = z.object({claim_type: z.literal("registration"), country_of_incorporation: z.string(), date_of_incorporation: z.string(), entity_type: claimRegistrationEntityType, legal_name: z.string(), registration_number: z.string(), trading_name: z.string().nullable().optional()}); export const contactDetailsClaimSpec = z.object({claim_type: z.literal("contact_details"), email: z.string().nullable().optional(), phone_number: z.string()}); export const leiClaimSpec = z.object({claim_type: z.literal("lei"), expiry_date: z.string(), identifier: z.string()}); export const registeredAddressClaimSpec = z.object({city: z.string(), claim_type: z.literal("registered_address"), country_code: z.string(), district_county: z.string().nullable().optional(), line1: z.string(), line2: z.string().nullable().optional(), line3: z.string().nullable().optional(), operating_address_is_same: z.boolean().optional(), postal_code: z.string()}); export const operatingAddressClaimSpec = z.object({city: z.string(), claim_type: z.literal("operating_address"), country_code: z.string(), district_county: z.string().nullable().optional(), line1: z.string(), line2: z.string().nullable().optional(), line3: z.string().nullable().optional(), postal_code: z.string()}); export const businessNatureClaimSpec = z.object({annual_turnover_eur: eurAmountBand, business_activity: claimIndustry, business_activity_other: z.string().nullable().optional(), claim_type: z.literal("business_nature"), has_nominee_shareholders: z.boolean(), has_shell_bank_relationships: z.boolean(), is_regulated: z.boolean(), issues_bearer_shares: z.boolean(), license_number: z.string().nullable().optional()}); export const claimSourceRole = z.enum(["supports", "confirms"]); export const claimSourceType = z.enum(["form_submission", "meeting_transcript", "file", "api", "provider"]); export const claimSource = z.object({locator: z.record(z.string(), z.unknown()), role: claimSourceRole, source: z.string().nullable(), source_type: claimSourceType}); export const claimVersion = z.object({claim: claimSummary, created_at: z.string(), data: z.discriminatedUnion("claim_type", [identityClaimSpec, nationalitiesClaimSpec, residenceClaimSpec, taxResidenciesClaimSpec, fatcaStatusClaimSpec, pepStatusClaimSpec, educationLevelClaimSpec, employmentClaimSpec, financialProfileClaimSpec, investmentExperienceClaimSpec, expectedActivityClaimSpec, relationshipsClaimSpecOutput, registrationClaimSpec, contactDetailsClaimSpec, leiClaimSpec, registeredAddressClaimSpec, operatingAddressClaimSpec, businessNatureClaimSpec]), id: z.string(), number: z.number().int(), sources: z.array(claimSource), status: z.enum(["unverified", "verified"]), verified_at: z.string().nullable()}); 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 }; /** * Add a version to a claim * * POST /persons/{person_id}/claims/{claim_id}/versions */ export const createApiPersonsPersonIdClaimsClaimIdVersions = async (args: CreateApiPersonsPersonIdClaimsClaimIdVersionsArgs, options?: CreateApiPersonsPersonIdClaimsClaimIdVersionsOptions) => { const {baseUrl = "https://api.joinsophic.com", fetch: fetchFn = fetch, HTTPBearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args['Idempotency-Key'] != null) headers.set("Idempotency-Key", String(args['Idempotency-Key'])) if (HTTPBearer !== undefined) headers.set('authorization', `Bearer ${HTTPBearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/persons/${encodeURIComponent(String(args.person_id))}/claims/${encodeURIComponent(String(args.claim_id))}/versions${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(claimVersion, await res.json()) };