import {z} from 'zod' export type GetApiApiV3MetaWorkspacesWorkspaceIdTeamsArgs = {workspaceId: string}; export type GetApiApiV3MetaWorkspacesWorkspaceIdTeamsOptions = {baseUrl?: string | undefined, xcToken?: string | undefined, fetch?: typeof fetch | undefined}; export const teamV3 = z.object({id: z.string(), title: z.string().max(150), icon: z.string().nullable().optional(), icon_type: z.enum(["EMOJI", "ICON"]).nullable().optional(), badge_color: z.string().optional(), members_count: z.number().int(), managers_count: z.number().int().optional(), fk_org_id: z.string().optional(), fk_workspace_id: z.string().optional(), created_at: z.string().optional(), updated_at: z.string().optional(), fk_parent_team_id: z.string().nullable().optional(), depth: z.number().int().optional(), path: z.string().optional(), is_member: z.boolean().optional(), scim_managed: z.boolean().optional(), managers: z.array(z.string()).optional()}); export const getApiApiV3MetaWorkspacesWorkspaceIdTeamsResponse = z.object({list: z.array(teamV3)}); 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 Teams * * GET /api/v3/meta/workspaces/{workspaceId}/teams * * Also accepts auth: bearerAuth */ export const getApiApiV3MetaWorkspacesWorkspaceIdTeams = async (args: GetApiApiV3MetaWorkspacesWorkspaceIdTeamsArgs, options?: GetApiApiV3MetaWorkspacesWorkspaceIdTeamsOptions) => { 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/workspaces/${encodeURIComponent(String(args.workspaceId))}/teams${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(getApiApiV3MetaWorkspacesWorkspaceIdTeamsResponse, await res.json()) };