import {z} from 'zod' export type ApplicationId = string; export type DocumentId = string; export type DeleteApiMortgagesApplicationsApplicationIdDocumentsDocumentIdArgs = {applicationId: ApplicationId, documentId: DocumentId, 'X-CorAPI-Client-ID': string, 'X-Correlation-ID': string, 'User-Agent': string}; export type DeleteApiMortgagesApplicationsApplicationIdDocumentsDocumentIdOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const deleteApiMortgagesApplicationsApplicationIdDocumentsDocumentIdResponse = z.object({status: z.string().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 }; /** * Delete a formerly uploaded document * * DELETE /mortgages/applications/{applicationId}/documents/{documentId} * * Also accepts auth: OAuth2 */ export const deleteApiMortgagesApplicationsApplicationIdDocumentsDocumentId = async (args: DeleteApiMortgagesApplicationsApplicationIdDocumentsDocumentIdArgs, options?: DeleteApiMortgagesApplicationsApplicationIdDocumentsDocumentIdOptions) => { const {baseUrl = "https://mortgage.common-api.ch", fetch: fetchFn = fetch, ApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args['X-CorAPI-Client-ID'] != null) headers.set("X-CorAPI-Client-ID", String(args['X-CorAPI-Client-ID'])) if (args['X-Correlation-ID'] != null) headers.set("X-Correlation-ID", String(args['X-Correlation-ID'])) if (args['User-Agent'] != null) headers.set("User-Agent", String(args['User-Agent'])) if (ApiKeyAuth !== undefined) headers.set("X-API-Key", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/mortgages/applications/${encodeURIComponent(String(args.applicationId))}/documents/${encodeURIComponent(String(args.documentId))}${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(deleteApiMortgagesApplicationsApplicationIdDocumentsDocumentIdResponse, await res.json()) };