import {z} from 'zod' export type CreateApiBaseBaseIdAuthorityMatrixRoleArgs = {baseId: string, body: {name: string, description?: string | undefined, enabled?: boolean | undefined, tables?: (Array<{tableId: string, disabledActions?: Array | undefined, fieldRecordPermission?: (Array<{fieldId: string, disabledActions?: Array | undefined}>) | undefined, recordFilter?: Record | undefined, enabledViewIds?: Array | undefined, enabled?: boolean | undefined}>) | undefined, nodes?: (Array<{nodeType: 'workflow' | 'app', nodeId: string, enabled?: boolean | undefined}>) | undefined}}; export type CreateApiBaseBaseIdAuthorityMatrixRoleOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiBaseBaseIdAuthorityMatrixRoleResponse = z.object({id: z.string(), name: z.string(), description: z.string().optional(), baseId: z.string(), createdTime: z.string(), enabledTime: z.string().optional(), tables: z.array(z.object({authorityMatrixRoleId: z.string(), tableId: z.string(), disabledActions: z.array(z.string()).optional(), enabledViewIds: z.array(z.string()).optional(), fieldRecordPermission: z.array(z.object({fieldId: z.string(), disabledActions: z.array(z.string()).optional()})).optional(), recordFilter: z.object({}).optional(), createdTime: z.string(), enabledTime: z.string().optional()})), nodes: z.array(z.object({id: z.string().optional(), authorityMatrixRoleId: z.string(), nodeType: z.enum(["workflow", "app"]), nodeId: z.string(), enabledTime: z.string().optional(), createdTime: z.string().optional()})).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 }; /** * Add authority matrix role * * POST /base/{baseId}/authority-matrix-role */ export const createApiBaseBaseIdAuthorityMatrixRole = async (args: CreateApiBaseBaseIdAuthorityMatrixRoleArgs, options?: CreateApiBaseBaseIdAuthorityMatrixRoleOptions) => { const {baseUrl = "https://app.teable.ai/api", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/base/${encodeURIComponent(String(args.baseId))}/authority-matrix-role${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(createApiBaseBaseIdAuthorityMatrixRoleResponse, await res.json()) };