import {z} from 'zod' export type DeleteApiApiV1QueryDashboardsDashboardIdWidgetsWidgetIdArgs = {revision?: string | undefined}; export type DeleteApiApiV1QueryDashboardsDashboardIdWidgetsWidgetIdOptions = {baseUrl?: string | undefined, secretKey?: string | undefined, fetch?: typeof fetch | undefined}; export const dashboardRevision = z.string(); export const dashboardWidgetDisplay = z.union([z.object({type: z.literal("table"), prettyFormatting: z.boolean().optional(), sorting: z.array(z.object({id: z.string().optional(), desc: z.boolean().optional()})).optional()}), z.object({type: z.literal("chart"), chartType: z.enum(["bar", "line"]), xAxisColumn: z.string().nullable(), yAxisColumns: z.array(z.string()), groupByColumn: z.string().nullable(), stacked: z.boolean(), sortByColumn: z.string().nullable(), sortDirection: z.enum(["asc", "desc"]), aggregation: z.enum(["sum", "avg", "count", "min", "max"]), seriesColors: z.record(z.string(), z.string()).optional()}), z.object({type: z.literal("bignumber"), column: z.string(), aggregation: z.enum(["sum", "avg", "count", "min", "max", "first", "last"]), sortDirection: z.enum(["asc", "desc"]).optional(), abbreviate: z.boolean().optional(), prefix: z.string().optional(), suffix: z.string().optional()}), z.object({type: z.literal("title")})]); export const dashboardWidgetPosition = z.object({x: z.number().int().gte(0).lte(11), y: z.number().int().gte(0), w: z.number().int().gte(1).lte(12), h: z.number().int().gte(1)}); export const dashboardObject = z.object({id: z.string().optional(), title: z.string().optional(), description: z.string().optional(), revision: dashboardRevision.optional(), createdAt: z.string().optional(), updatedAt: z.string().optional(), widgets: z.array(z.object({id: z.string().optional(), title: z.string().optional(), query: z.string().optional(), display: dashboardWidgetDisplay.optional(), fillGaps: z.boolean().optional(), position: dashboardWidgetPosition.optional()})).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 dashboard widget * * DELETE /api/v1/query/dashboards/{dashboardId}/widgets/{widgetId} */ export const deleteApiApiV1QueryDashboardsDashboardIdWidgetsWidgetId = async (args: DeleteApiApiV1QueryDashboardsDashboardIdWidgetsWidgetIdArgs, options?: DeleteApiApiV1QueryDashboardsDashboardIdWidgetsWidgetIdOptions) => { const {baseUrl = "https://api.trigger.dev", fetch: fetchFn = fetch, secretKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.revision != null) query.append("revision", String(args.revision)) if (secretKey !== undefined) headers.set('authorization', `Bearer ${secretKey}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/query/dashboards/${encodeURIComponent(String(args.dashboardId))}/widgets/${encodeURIComponent(String(args.widgetId))}${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(dashboardObject, await res.json()) };