import {z} from 'zod' export type TeamMemberV3 = {user_id: string, team_role: 'member' | 'owner'}; export type TeamCreateV3Req = {title: string, icon?: (string | null) | undefined, icon_type?: ('EMOJI' | 'ICON' | null) | undefined, badge_color?: string | undefined, members?: Array | undefined, parent_team_id?: (string | null) | undefined}; export type CreateApiApiV3MetaWorkspacesWorkspaceIdTeamsArgs = {workspaceId: string, body: TeamCreateV3Req}; export type CreateApiApiV3MetaWorkspacesWorkspaceIdTeamsOptions = {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 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 }; /** * Create Team * * POST /api/v3/meta/workspaces/{workspaceId}/teams * * Also accepts auth: bearerAuth */ export const createApiApiV3MetaWorkspacesWorkspaceIdTeams = async (args: CreateApiApiV3MetaWorkspacesWorkspaceIdTeamsArgs, options?: CreateApiApiV3MetaWorkspacesWorkspaceIdTeamsOptions) => { const {baseUrl = "https://app.nocodb.com", fetch: fetchFn = fetch, xcToken} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") 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: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(teamV3, await res.json()) };