import {z} from 'zod' export type UpdatePartnerResidencyApplicationRequest = {expectedVersion: number, applicationData: {residencyType: 'limited_e_resident' | 'e_resident' | 'resident_annual', personalDetails: {givenName: string, surname: string, email: string, dateOfBirth: string, sex: 'male' | 'female', countryOfBirth: string, citizenships: Array, alternateNamesAttestation: boolean, alternateNames?: (string | null) | undefined, criminalBackgroundAttestation: boolean, proofOfAddressUploadId?: string | undefined, proofOfAddressSwornStatement?: ({agreed: true, signature: string, locale?: ('en' | 'es') | undefined}) | undefined, address: {line1: string, line2?: (string | null) | undefined, city: string, state?: (string | null) | undefined, postalCode: string, country: string} | null, phoneNumber: string}, information?: ({residencyReason?: (string | null) | undefined, referralSource?: (string | null) | undefined}) | undefined}, referralCode?: string | undefined, redirectUrl?: string | undefined}; export type PatchApiApiV1PartnerResidencyApplicationsIdArgs = {id: string, body: UpdatePartnerResidencyApplicationRequest}; export type PatchApiApiV1PartnerResidencyApplicationsIdOptions = {baseUrl?: string | undefined, partnerKey?: string | undefined, fetch?: typeof fetch | undefined}; export const partnerResidencyApplication = z.object({id: z.string(), version: z.number().int().gt(0), statusId: z.enum(["Draft", "Pending Review", "Approved", "Rejected"]), applicationVersion: z.string(), submittedAt: z.string().nullable(), createdAt: z.string(), approvedAt: z.string().nullable(), rejectedAt: z.string().nullable(), residentPermitNumber: z.string().nullable(), referralCode: z.string().nullable(), applicationData: z.object({residencyType: z.enum(["limited_e_resident", "e_resident", "resident_annual", "null"]).nullable(), aoc: z.object({aocId: z.string().nullable(), signed: z.boolean(), signedByName: z.string().nullable(), signedAt: z.string().nullable(), agentAuthorized: z.boolean()}), personalDetails: z.object({givenName: z.string(), surname: z.string(), email: z.string(), dateOfBirth: z.string(), sex: z.string(), countryOfBirth: z.string().min(2).max(2).nullable(), citizenships: z.array(z.string().min(2).max(2)), alternateNamesAttestation: z.boolean(), alternateNames: z.string().nullable(), criminalBackgroundAttestation: z.boolean(), proofOfAddressUploadId: z.string().nullable(), address: z.object({line1: z.string().nullable(), line2: z.string().nullable(), city: z.string().nullable(), state: z.string().nullable(), postalCode: z.string().nullable(), country: z.string().min(2).max(2).nullable()}), phoneNumber: z.string().nullable()}).nullable(), information: z.object({residencyReason: z.string().nullable(), referralSource: z.string().nullable()})}), applicantPortalAccess: z.object({email: z.string().nullable(), hasLoggedIn: z.boolean(), lastLogin: z.string().nullable(), claimLinkSent: z.boolean(), claimLinkSentAt: z.string().nullable()}), nextSteps: z.object({agreementUrl: z.string().nullable(), proofOfAddressRequired: z.boolean(), paymentRequired: z.boolean(), verificationRequired: z.boolean(), verificationInstructions: z.string().nullable(), submitReady: z.boolean()})}); export const patchApiApiV1PartnerResidencyApplicationsIdResponse = z.object({data: partnerResidencyApplication}); 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 }; /** * Update a draft partner residency application * * PATCH /api/v1/partner/residency_applications/{id} */ export const patchApiApiV1PartnerResidencyApplicationsId = async (args: PatchApiApiV1PartnerResidencyApplicationsIdArgs, options?: PatchApiApiV1PartnerResidencyApplicationsIdOptions) => { const {baseUrl = "https://portal.eprospera.com", fetch: fetchFn = fetch, partnerKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (partnerKey !== undefined) headers.set('authorization', `Bearer ${partnerKey}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/partner/residency_applications/${encodeURIComponent(String(args.id))}${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(patchApiApiV1PartnerResidencyApplicationsIdResponse, await res.json()) };