import {z} from 'zod' export type GetApiApiV1AutomationConnectionsArgs = {cursor?: string | undefined, filter?: string | undefined, limit?: number | undefined, listAll?: boolean | undefined, sort?: ('id' | 'name' | 'createdAt' | 'updatedAt' | '+id' | '+name' | '+createdAt' | '+updatedAt' | '-id' | '-name' | '-createdAt' | '-updatedAt') | undefined}; export type GetApiApiV1AutomationConnectionsOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const automationConnectionsListObject = z.object({id: z.string().optional(), name: z.string().optional(), ownerId: z.string().optional(), spaceId: z.string().optional(), createdAt: z.string().optional(), updatedAt: z.string().optional(), connectorId: z.string().optional(), isConnected: z.boolean().optional()}); export const paginationLink = z.object({href: z.string().nullable().optional()}); export const links = z.object({next: paginationLink.optional(), prev: paginationLink.optional()}); export const automationConnectionsList = z.object({data: z.array(automationConnectionsListObject).optional(), links: links.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 }; /** * List automation connections * * GET /api/v1/automation-connections */ export const getApiApiV1AutomationConnections = async (args: GetApiApiV1AutomationConnectionsArgs, options?: GetApiApiV1AutomationConnectionsOptions) => { const {baseUrl = "https://your-tenant.us.qlikcloud.com", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.cursor != null) query.append("cursor", String(args.cursor)) if (args.filter != null) query.append("filter", String(args.filter)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.listAll != null) query.append("listAll", String(args.listAll)) if (args.sort != null) query.append("sort", String(args.sort)) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/automation-connections${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(automationConnectionsList, await res.json()) };