import {z} from 'zod' export type GetApiApiV1ProjectsProjectUuidContentVerificationArgs = {projectUuid: string}; export type GetApiApiV1ProjectsProjectUuidContentVerificationOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const chartKind = z.enum(["line", "horizontal_bar", "vertical_bar", "scatter", "area", "mixed", "pie", "table", "big_number", "funnel", "custom", "treemap", "gauge", "map", "sankey", "data_app_viz"]); export const contentTypeCHART = z.literal("chart"); export const verifiedChartListItem = z.object({verifiedAt: z.string(), verifiedBy: z.object({lastName: z.string(), firstName: z.string(), userUuid: z.string()}), lastUpdatedAt: z.string().nullable(), views: z.number(), spaceName: z.string(), spaceUuid: z.string(), description: z.string().nullable(), name: z.string(), contentUuid: z.string(), uuid: z.string(), exploreName: z.string().nullable(), chartKind: chartKind, contentType: contentTypeCHART}); export const contentTypeDASHBOARD = z.literal("dashboard"); export const verifiedDashboardListItem = z.object({verifiedAt: z.string(), verifiedBy: z.object({lastName: z.string(), firstName: z.string(), userUuid: z.string()}), lastUpdatedAt: z.string().nullable(), views: z.number(), spaceName: z.string(), spaceUuid: z.string(), description: z.string().nullable(), name: z.string(), contentUuid: z.string(), uuid: z.string(), contentType: contentTypeDASHBOARD}); export const verifiedContentListItem = z.union([verifiedChartListItem, verifiedDashboardListItem]); export const apiVerifiedContentListResponse = z.object({results: z.array(verifiedContentListItem), status: z.literal("ok")}); 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 }; /** * List verified content * * GET /api/v1/projects/{projectUuid}/content-verification */ export const getApiApiV1ProjectsProjectUuidContentVerification = async (args: GetApiApiV1ProjectsProjectUuidContentVerificationArgs, options: GetApiApiV1ProjectsProjectUuidContentVerificationOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/projects/${encodeURIComponent(String(args.projectUuid))}/content-verification${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(apiVerifiedContentListResponse, await res.json()) };