import {z} from 'zod' export type GetApiApiV3MetaOrgsOrgIdEnvironmentsArgs = {orgId: string}; export type GetApiApiV3MetaOrgsOrgIdEnvironmentsOptions = {baseUrl?: string | undefined, xcToken?: string | undefined, fetch?: typeof fetch | undefined}; export const environmentV3 = z.object({id: z.string(), key: z.string().max(50), title: z.string().max(255), description: z.string().nullable().optional(), color: z.string().max(20).nullable().optional(), is_default: z.boolean(), is_locked: z.boolean(), workspace_id: z.string().optional(), org_id: z.string().optional(), created_at: z.string().optional(), updated_at: z.string().optional(), created_by: z.string().optional()}); export const getApiApiV3MetaOrgsOrgIdEnvironmentsResponse = z.object({list: z.array(environmentV3)}); 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 Organization Environments * * GET /api/v3/meta/orgs/{orgId}/environments * * Also accepts auth: bearerAuth */ export const getApiApiV3MetaOrgsOrgIdEnvironments = async (args: GetApiApiV3MetaOrgsOrgIdEnvironmentsArgs, options?: GetApiApiV3MetaOrgsOrgIdEnvironmentsOptions) => { const {baseUrl = "https://app.nocodb.com", fetch: fetchFn = fetch, xcToken} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (xcToken !== undefined) headers.set("xc-token", xcToken) const url = `${baseUrl.replace(/\/+$/, '')}/api/v3/meta/orgs/${encodeURIComponent(String(args.orgId))}/environments${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(getApiApiV3MetaOrgsOrgIdEnvironmentsResponse, await res.json()) };