import {z} from 'zod' export type GetApiRunnersVariablesVariableSetsArgs = {searchQuery?: string | undefined, pageSize?: number | undefined, offset?: number | undefined}; export type GetApiRunnersVariablesVariableSetsOptions = {baseUrl?: string | undefined, JWTAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const variable = z.object({key: z.string().optional(), value: z.string().optional(), sensitivity: z.enum(["string", "secret"]).optional(), destination: z.enum(["env", "iac"]).optional()}); export const variableSetDescendant = z.object({id: z.string().optional(), name: z.string().optional()}); export const variableSetConsumers = z.object({workspaces: z.array(variableSetDescendant).optional(), projects: z.array(variableSetDescendant).optional()}); export const variableSet = z.object({id: z.string().optional(), version: z.number().int().optional(), name: z.string().optional(), description: z.string().optional(), labels: z.array(z.string()).optional(), parents: z.array(z.string()).optional(), variables: z.array(variable).optional(), descendants: z.array(variableSetDescendant).optional(), consumers: variableSetConsumers.optional()}); export const getApiRunnersVariablesVariableSetsResponse = z.array(variableSet); 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 variable sets * * GET /runners/variables/variable-sets */ export const getApiRunnersVariablesVariableSets = async (args: GetApiRunnersVariablesVariableSetsArgs, options?: GetApiRunnersVariablesVariableSetsOptions) => { const {baseUrl = "https://api.firefly.ai/v2", fetch: fetchFn = fetch, JWTAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.searchQuery != null) query.append("searchQuery", String(args.searchQuery)) if (args.pageSize != null) query.append("pageSize", String(args.pageSize)) if (args.offset != null) query.append("offset", String(args.offset)) if (JWTAuth !== undefined) headers.set('authorization', `Bearer ${JWTAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/runners/variables/variable-sets${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(getApiRunnersVariablesVariableSetsResponse, await res.json()) };