import {z} from 'zod' export type DeleteApiV1SpvRequestsSlugArgs = {slug: string}; export type DeleteApiV1SpvRequestsSlugOptions = {baseUrl: string, HTTPBearer?: string | undefined, fetch?: typeof fetch | undefined}; export const spvRequestStatus = z.enum(["pending-review", "approved", "rejected", "cancelled"]); export const materialisedRefsResponse = z.object({opportunitySlug: z.string(), vehicleSlug: z.string(), spSlug: z.string(), spcSlug: z.string()}); export const shareClassFeesAndCarry = z.object({name: z.string(), slug: z.string(), managementFeePercent: z.string().optional(), carryPercent: z.string().optional(), setupFee: z.object({}).optional()}); export const feesAndCarryResponse = z.object({shareClasses: z.array(shareClassFeesAndCarry).optional()}); export const spvRequestResponse = z.object({spvRequestSlug: z.string(), status: spvRequestStatus, templateId: z.string(), templateVersion: z.string(), tenantSlug: z.string(), clientId: z.string(), attributes: z.object({}), rejectionReason: z.string().optional(), cancelledAt: z.string().optional(), approvedAt: z.string().optional(), materialisedRefs: materialisedRefsResponse.optional(), feesAndCarry: feesAndCarryResponse.optional(), createdAt: z.string(), updatedAt: z.string()}); 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 }; /** * Cancel an SPV request * * DELETE /v1/spv-requests/{slug} */ export const deleteApiV1SpvRequestsSlug = async (args: DeleteApiV1SpvRequestsSlugArgs, options: DeleteApiV1SpvRequestsSlugOptions) => { const {baseUrl, 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(/\/+$/, '')}/v1/spv-requests/${encodeURIComponent(String(args.slug))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "DELETE", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(spvRequestResponse, await res.json()) };