import {z} from 'zod' export type UUID = string; export type GetApiV0InvestorsIdArgs = {id: UUID}; export type GetApiV0InvestorsIdOptions = {baseUrl?: string | undefined, basicAuth?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const countryCodeAlpha2 = z.enum(["AD", "AE", "AF", "AG", "AI", "AL", "AM", "AO", "AQ", "AR", "AS", "AT", "AU", "AW", "AX", "AZ", "BA", "BB", "BD", "BE", "BF", "BG", "BH", "BI", "BJ", "BL", "BM", "BN", "BO", "BQ", "BR", "BS", "BT", "BV", "BW", "BY", "BZ", "CA", "CC", "CD", "CF", "CG", "CH", "CI", "CK", "CL", "CM", "CN", "CO", "CR", "CU", "CV", "CW", "CX", "CY", "CZ", "DE", "DJ", "DK", "DM", "DO", "DZ", "EC", "EE", "EG", "EH", "ER", "ES", "ET", "FI", "FJ", "FK", "FM", "FO", "FR", "GA", "GB", "GD", "GE", "GF", "GG", "GH", "GI", "GL", "GM", "GN", "GP", "GQ", "GR", "GS", "GT", "GU", "GW", "GY", "HK", "HM", "HN", "HR", "HT", "HU", "ID", "IE", "IL", "IM", "IN", "IO", "IQ", "IR", "IS", "IT", "JE", "JM", "JO", "JP", "KE", "KG", "KH", "KI", "KM", "KN", "KP", "KR", "KW", "KY", "KZ", "LA", "LB", "LC", "LI", "LK", "LR", "LS", "LT", "LU", "LV", "LY", "MA", "MC", "MD", "ME", "MF", "MG", "MH", "MK", "ML", "MM", "MN", "MO", "MP", "MQ", "MR", "MS", "MT", "MU", "MV", "MW", "MX", "MY", "MZ", "NA", "NC", "NE", "NF", "NG", "NI", "NL", "NO", "NP", "NR", "NU", "NZ", "OM", "PA", "PE", "PF", "PG", "PH", "PK", "PL", "PM", "PN", "PR", "PS", "PT", "PW", "PY", "QA", "RE", "RO", "RS", "RU", "RW", "SA", "SB", "SC", "SD", "SE", "SG", "SH", "SI", "SJ", "SK", "SL", "SM", "SN", "SO", "SR", "SS", "ST", "SV", "SX", "SY", "SZ", "TC", "TD", "TF", "TG", "TH", "TJ", "TK", "TL", "TM", "TN", "TO", "TR", "TT", "TV", "TW", "TZ", "UA", "UG", "UM", "US", "UY", "UZ", "VA", "VC", "VE", "VG", "VI", "VN", "VU", "WF", "WS", "YE", "YT", "ZA", "ZM", "ZW"]); export const day = z.string(); export const legalEntityName = z.string(); export const uUID = z.string(); export const shareClassSymbol = z.enum(["EUTBL", "USTBL", "eurUSTBL", "SPKCC", "eurSPKCC", "UKTBL", "eurUKTBL", "SAFO", "SAFOd", "eurSAFO", "eurSAFOd", "gbpSAFO", "gbpSAFOd", "chfSAFO", "sekSAFO", "nokSAFO", "dkkSAFO", "plnSAFO", "hufSAFO", "czkSAFO"]); export const getApiV0InvestorsIdResponse = z.union([z.object({firstName: z.string(), lastName: z.string(), country: countryCodeAlpha2, address: z.string(), zipCode: z.string(), city: z.string(), details: z.union([z.object({type: z.literal("individual"), taxInformationByCountryOfResidence: z.array(z.object({country: countryCodeAlpha2, taxInformation: z.object({taxIdentificationNumber: z.string(), updatedAt: z.string()}).nullable().optional()})), dateOfBirth: day.nullable(), placeOfBirth: z.string().min(1).nullable(), gender: z.enum(["Female", "Male"]).nullable(), industry: z.enum(["AgricultureAndFoodProcessing", "ArtsMediaAndEntertainment", "CasinosAndGambling", "Construction", "Cryptocurrency", "DefenseAndMilitaryIndustry", "Education", "EnergyAndUtilities", "FinancialServices", "FoodAndLodging", "Government", "HealthProfessions", "HoldingCompany", "IndustryAndManufacturing", "Mining", "NonProfit", "ProfessionalServices", "RealEstate", "RetailTradeAutomotive", "RetailTradeJewelryAntiques", "RetailTradeOthers", "SportAndTourism", "TechnologyAndComputing", "Transportation", "Politics", "Retired", "Student"]).nullable()}), z.object({type: z.literal("organization"), legalName: legalEntityName, legalEntityType: z.string(), registrationNumber: z.string(), industry: z.enum(["AgricultureAndFoodProcessing", "ArtsMediaAndEntertainment", "CasinosAndGambling", "Construction", "Cryptocurrency", "DefenseAndMilitaryIndustry", "Education", "EnergyAndUtilities", "FinancialServices", "FoodAndLodging", "Government", "HealthProfessions", "HoldingCompany", "IndustryAndManufacturing", "Mining", "NonProfit", "ProfessionalServices", "RealEstate", "RetailTradeAutomotive", "RetailTradeJewelryAntiques", "RetailTradeOthers", "SportAndTourism", "TechnologyAndComputing", "Transportation"])})]), relatedPersons: z.array(z.object({firstName: z.string(), lastName: z.string(), gender: z.enum(["Female", "Male"]).nullable().optional(), dateOfBirth: day.nullable().optional(), cityOfBirth: z.string().nullable().optional(), countryOfBirth: countryCodeAlpha2.nullable().optional(), nationality: countryCodeAlpha2.nullable().optional(), addressOfResidence: z.string().nullable().optional(), cityOfResidence: z.string().nullable().optional(), zipCodeOfResidence: z.string().nullable().optional(), countryOfResidence: countryCodeAlpha2.nullable().optional(), relationshipTypes: z.array(z.enum(["ubo", "director", "self", "other"])), fiscalIdentificationNumber: z.string().nullable().optional()})).optional(), id: uUID, distributorId: uUID, createdOn: z.string(), updatedOn: z.string(), status: z.literal("compliant"), complianceStatus: z.literal("compliant"), allowedByDistributorShareClasses: z.array(shareClassSymbol).nullable().optional(), hasAccessToProfessionalProducts: z.boolean()}), z.object({firstName: z.string(), lastName: z.string(), country: countryCodeAlpha2, address: z.string(), zipCode: z.string(), city: z.string(), details: z.union([z.object({type: z.literal("individual"), taxInformationByCountryOfResidence: z.array(z.object({country: countryCodeAlpha2, taxInformation: z.object({taxIdentificationNumber: z.string(), updatedAt: z.string()}).nullable().optional()})), dateOfBirth: day.nullable(), placeOfBirth: z.string().min(1).nullable(), gender: z.enum(["Female", "Male"]).nullable(), industry: z.enum(["AgricultureAndFoodProcessing", "ArtsMediaAndEntertainment", "CasinosAndGambling", "Construction", "Cryptocurrency", "DefenseAndMilitaryIndustry", "Education", "EnergyAndUtilities", "FinancialServices", "FoodAndLodging", "Government", "HealthProfessions", "HoldingCompany", "IndustryAndManufacturing", "Mining", "NonProfit", "ProfessionalServices", "RealEstate", "RetailTradeAutomotive", "RetailTradeJewelryAntiques", "RetailTradeOthers", "SportAndTourism", "TechnologyAndComputing", "Transportation", "Politics", "Retired", "Student"]).nullable()}), z.object({type: z.literal("organization"), legalName: legalEntityName, legalEntityType: z.string(), registrationNumber: z.string(), industry: z.enum(["AgricultureAndFoodProcessing", "ArtsMediaAndEntertainment", "CasinosAndGambling", "Construction", "Cryptocurrency", "DefenseAndMilitaryIndustry", "Education", "EnergyAndUtilities", "FinancialServices", "FoodAndLodging", "Government", "HealthProfessions", "HoldingCompany", "IndustryAndManufacturing", "Mining", "NonProfit", "ProfessionalServices", "RealEstate", "RetailTradeAutomotive", "RetailTradeJewelryAntiques", "RetailTradeOthers", "SportAndTourism", "TechnologyAndComputing", "Transportation"])})]), relatedPersons: z.array(z.object({firstName: z.string(), lastName: z.string(), gender: z.enum(["Female", "Male"]).nullable().optional(), dateOfBirth: day.nullable().optional(), cityOfBirth: z.string().nullable().optional(), countryOfBirth: countryCodeAlpha2.nullable().optional(), nationality: countryCodeAlpha2.nullable().optional(), addressOfResidence: z.string().nullable().optional(), cityOfResidence: z.string().nullable().optional(), zipCodeOfResidence: z.string().nullable().optional(), countryOfResidence: countryCodeAlpha2.nullable().optional(), relationshipTypes: z.array(z.enum(["ubo", "director", "self", "other"])), fiscalIdentificationNumber: z.string().nullable().optional()})).optional(), id: uUID, distributorId: uUID, createdOn: z.string(), updatedOn: z.string(), status: z.literal("non-compliant"), complianceStatus: z.literal("non-compliant"), allowedByDistributorShareClasses: z.array(shareClassSymbol).nullable().optional()}), z.object({firstName: z.string(), lastName: z.string(), country: countryCodeAlpha2, address: z.string(), zipCode: z.string(), city: z.string(), details: z.union([z.object({type: z.literal("individual"), taxInformationByCountryOfResidence: z.array(z.object({country: countryCodeAlpha2, taxInformation: z.object({taxIdentificationNumber: z.string(), updatedAt: z.string()}).nullable().optional()})), dateOfBirth: day.nullable(), placeOfBirth: z.string().min(1).nullable(), gender: z.enum(["Female", "Male"]).nullable(), industry: z.enum(["AgricultureAndFoodProcessing", "ArtsMediaAndEntertainment", "CasinosAndGambling", "Construction", "Cryptocurrency", "DefenseAndMilitaryIndustry", "Education", "EnergyAndUtilities", "FinancialServices", "FoodAndLodging", "Government", "HealthProfessions", "HoldingCompany", "IndustryAndManufacturing", "Mining", "NonProfit", "ProfessionalServices", "RealEstate", "RetailTradeAutomotive", "RetailTradeJewelryAntiques", "RetailTradeOthers", "SportAndTourism", "TechnologyAndComputing", "Transportation", "Politics", "Retired", "Student"]).nullable()}), z.object({type: z.literal("organization"), legalName: legalEntityName, legalEntityType: z.string(), registrationNumber: z.string(), industry: z.enum(["AgricultureAndFoodProcessing", "ArtsMediaAndEntertainment", "CasinosAndGambling", "Construction", "Cryptocurrency", "DefenseAndMilitaryIndustry", "Education", "EnergyAndUtilities", "FinancialServices", "FoodAndLodging", "Government", "HealthProfessions", "HoldingCompany", "IndustryAndManufacturing", "Mining", "NonProfit", "ProfessionalServices", "RealEstate", "RetailTradeAutomotive", "RetailTradeJewelryAntiques", "RetailTradeOthers", "SportAndTourism", "TechnologyAndComputing", "Transportation"])})]), relatedPersons: z.array(z.object({firstName: z.string(), lastName: z.string(), gender: z.enum(["Female", "Male"]).nullable().optional(), dateOfBirth: day.nullable().optional(), cityOfBirth: z.string().nullable().optional(), countryOfBirth: countryCodeAlpha2.nullable().optional(), nationality: countryCodeAlpha2.nullable().optional(), addressOfResidence: z.string().nullable().optional(), cityOfResidence: z.string().nullable().optional(), zipCodeOfResidence: z.string().nullable().optional(), countryOfResidence: countryCodeAlpha2.nullable().optional(), relationshipTypes: z.array(z.enum(["ubo", "director", "self", "other"])), fiscalIdentificationNumber: z.string().nullable().optional()})).optional(), id: uUID, distributorId: uUID, createdOn: z.string(), updatedOn: z.string(), status: z.literal("pending-onboarding-workflow"), complianceStatus: z.literal("pending-onboarding"), allowedByDistributorShareClasses: z.array(shareClassSymbol).nullable().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 }; /** * Get investor * * GET /v0/investors/{id} */ export const getApiV0InvestorsId = async (args: GetApiV0InvestorsIdArgs, options?: GetApiV0InvestorsIdOptions) => { const {baseUrl = "https://distributor-api.spiko.io", fetch: fetchFn = fetch, basicAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (basicAuth !== undefined) headers.set('authorization', `Basic ${btoa(`${basicAuth.username}:${basicAuth.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/v0/investors/${encodeURIComponent(String(args.id))}${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(getApiV0InvestorsIdResponse, await res.json()) };