import {z} from 'zod' export type DeleteApiV2WorkflowsDlqArgs = {dlqIds?: Array | undefined, cursor?: string | undefined, count?: number | undefined, fromDate?: number | undefined, toDate?: number | undefined, workflowUrl?: Array | undefined, workflowRunId?: string | undefined, workflowCreatedAt?: number | undefined, label?: Array | undefined, failureFunctionState?: Array | undefined, callerIp?: Array | undefined, flowControlKey?: Array | undefined}; export type DeleteApiV2WorkflowsDlqOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const deleteApiV2WorkflowsDlqResponse = z.object({deleted: z.number().int().optional(), cursor: 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 }; /** * Bulk Delete Failed Workflow Runs * * DELETE /v2/workflows/dlq * * Also accepts auth: bearerAuthQuery */ export const deleteApiV2WorkflowsDlq = async (args: DeleteApiV2WorkflowsDlqArgs, options?: DeleteApiV2WorkflowsDlqOptions) => { const {baseUrl = "https://qstash-eu-central-1.upstash.io", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") for (const item of args.dlqIds ?? []) query.append("dlqIds", String(item)) if (args.cursor != null) query.append("cursor", String(args.cursor)) if (args.count != null) query.append("count", String(args.count)) if (args.fromDate != null) query.append("fromDate", String(args.fromDate)) if (args.toDate != null) query.append("toDate", String(args.toDate)) for (const item of args.workflowUrl ?? []) query.append("workflowUrl", String(item)) if (args.workflowRunId != null) query.append("workflowRunId", String(args.workflowRunId)) if (args.workflowCreatedAt != null) query.append("workflowCreatedAt", String(args.workflowCreatedAt)) for (const item of args.label ?? []) query.append("label", String(item)) for (const item of args.failureFunctionState ?? []) query.append("failureFunctionState", String(item)) for (const item of args.callerIp ?? []) query.append("callerIp", String(item)) for (const item of args.flowControlKey ?? []) query.append("flowControlKey", String(item)) if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v2/workflows/dlq${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(deleteApiV2WorkflowsDlqResponse, await res.json()) };