import {z} from 'zod' export type DeleteApiV1UafRequestsIdArgs = {id: string}; export type DeleteApiV1UafRequestsIdOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const modelsRelyingParty = z.object({id: z.string(), name: z.string(), appId: z.string(), icon: z.string()}); export const modelsClientData = z.object({remoteAddress: z.string().optional(), userAgent: z.string().optional()}); export const modelsLocation = z.object({country: z.string(), region: z.string(), city: z.string()}); export const modelsLink = z.object({rel: z.string(), method: z.string(), href: z.string()}); export const modelsRequestDevice = z.object({deviceId: z.string().optional(), keyName: z.string().optional()}); export const modelsRequestError = z.object({code: z.number().int(), reason: z.string().optional()}); export const modelsHankoRequest = z.object({id: z.string(), operation: z.enum(["AUTH", "DEREG", "REG"]), username: z.string(), userId: z.string(), status: z.enum(["PENDING", "OK", "FAILED", "INVALIDATED"]), createdAt: z.string(), validUntil: z.string(), relyingParty: modelsRelyingParty, clientData: modelsClientData.optional(), location: modelsLocation.optional(), links: z.array(modelsLink), transaction: z.string().optional(), request: z.string(), deviceID: z.string(), device: modelsRequestDevice.optional(), isSecondFactorOnly: z.boolean().optional(), error: modelsRequestError.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 }; /** * Cancel the request for the Hanko Authenticator * * DELETE /v1/uaf/requests/{id} */ export const deleteApiV1UafRequestsId = async (args: DeleteApiV1UafRequestsIdArgs, options?: DeleteApiV1UafRequestsIdOptions) => { const {baseUrl = "https://.hanko.io/admin", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/v1/uaf/requests/${encodeURIComponent(String(args.id))}${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(modelsHankoRequest, await res.json()) };