import {z} from 'zod' export type GetApiApiV1AnalyticsCollectionIdArgs = {id: string}; export type GetApiApiV1AnalyticsCollectionIdOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiApiV1AnalyticsCollectionIdResponse = z.object({data: z.array(z.object({id: z.number().optional(), name: z.string().optional(), description: z.string().optional(), reports: z.array(z.object({id: z.number().optional(), title: z.string(), description: z.string().optional(), userId: z.number().optional(), sqlString: z.string(), isFavorite: z.boolean().optional(), isReadOnly: z.boolean().optional(), collectionId: z.number(), lastEditedBy: z.string().optional(), tags: z.array(z.object({id: z.number(), name: z.string(), description: z.string().optional(), palette: z.enum(["default", "warning", "success", "danger", "primary"]).optional(), isOfficial: z.boolean().optional(), createdAt: z.string().optional(), updatedAt: z.string().optional()})).optional(), parameters: z.array(z.object({name: z.string(), type: z.string(), defaultValue: z.string(), valueMap: z.array(z.object({label: z.string(), value: z.string()})).optional()})).nullable().optional(), createdAt: z.string().optional(), updatedAt: z.string().optional()})).optional(), createdAt: z.string().optional(), updatedAt: z.string().optional()})).nullable()}); 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 }; /** * View collection * * GET /api/v1/analytics/collection/{id} */ export const getApiApiV1AnalyticsCollectionId = async (args: GetApiApiV1AnalyticsCollectionIdArgs, options?: GetApiApiV1AnalyticsCollectionIdOptions) => { const {baseUrl = "https://xentral.xentral.biz", fetch: fetchFn = fetch, BearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/analytics/collection/${encodeURIComponent(String(args.id))}${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(getApiApiV1AnalyticsCollectionIdResponse, await res.json()) };