import {z} from 'zod' export type GetApiRunnersVariablesProjectsProjectIdArgs = {projectId: string}; export type GetApiRunnersVariablesProjectsProjectIdOptions = {baseUrl?: string | undefined, JWTAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const variableOrigin = z.object({type: z.enum(["project", "workspace", "variable_set"]), fullName: z.string().optional(), fullId: z.string().optional(), variableSetFullName: z.string().optional(), variableSetFullId: z.string().optional(), consumerType: z.enum(["project", "workspace"]).optional(), projectDepth: z.number().int().optional(), variableSetDepth: z.number().int().optional(), variableSetId: z.string()}); export const variableWithOrigin = z.object({key: z.string().optional(), value: z.string().optional(), sensitivity: z.enum(["string", "secret"]).optional(), destination: z.enum(["env", "iac"]).optional(), origin: variableOrigin.optional()}); export const getApiRunnersVariablesProjectsProjectIdResponse = z.array(variableWithOrigin); 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 variables for a project * * GET /runners/variables/projects/{projectId} */ export const getApiRunnersVariablesProjectsProjectId = async (args: GetApiRunnersVariablesProjectsProjectIdArgs, options?: GetApiRunnersVariablesProjectsProjectIdOptions) => { 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 (JWTAuth !== undefined) headers.set('authorization', `Bearer ${JWTAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/runners/variables/projects/${encodeURIComponent(String(args.projectId))}${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(getApiRunnersVariablesProjectsProjectIdResponse, await res.json()) };