import {z} from 'zod' export type DeleteApiContractsContractIdMilestonesMilestoneRefCompletionArgs = {contract_id: string, milestone_ref: string}; export type DeleteApiContractsContractIdMilestonesMilestoneRefCompletionOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const currencyCode = z.string(); export const roundedMonetaryAmount = z.object({amount: z.string(), currency: currencyCode}); export const contractMilestoneStatus = z.enum(["OPEN", "DUE_THIS_PERIOD", "OVERDUE", "COMPLETED", "CANCELLED"]); export const externalReference = z.object({type: z.string(), id: z.string(), url: z.string().optional()}); export const contractMilestoneCancellation = z.object({effective_date: z.string(), credit_memo_id: z.string().nullable().optional()}); export const contractMilestone = z.object({id: z.string(), key: z.string(), name: z.string(), sequence: z.number().int(), percentage: z.string().nullable().optional(), allocated_amount: roundedMonetaryAmount.nullable().optional(), amount: roundedMonetaryAmount.nullable().optional(), expected_date: z.string().nullable().optional(), status: contractMilestoneStatus, completed_date: z.string().nullable().optional(), memo: z.string().nullable().optional(), external_references: z.array(externalReference), cancellation: contractMilestoneCancellation.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 }; /** * Reverses a milestone completion * * DELETE /contracts/{contract_id}/milestones/{milestone_ref}/completion */ export const deleteApiContractsContractIdMilestonesMilestoneRefCompletion = async (args: DeleteApiContractsContractIdMilestonesMilestoneRefCompletionArgs, options?: DeleteApiContractsContractIdMilestonesMilestoneRefCompletionOptions) => { const {baseUrl = "https://api.rillet.com", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/contracts/${encodeURIComponent(String(args.contract_id))}/milestones/${encodeURIComponent(String(args.milestone_ref))}/completion${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(contractMilestone, await res.json()) };