import {z} from 'zod' export type HiveType = 'WEBSITE' | 'GOOGLE_DOCS' | 'DOCS' | 'TRANSCRIPTS'; export type Files = {id?: string | undefined, orgId?: string | undefined, fileName?: string | undefined, fileUrl?: string | undefined, createdBy?: string | undefined, createdAt?: string | undefined, updatedBy?: string | undefined, updatedAt?: string | undefined}; export type BackendDbModelsHiveContent = {hiveType: HiveType, url?: (string | null) | undefined, files?: (Array | null) | undefined, hiveProps?: (Record | null) | undefined, internalProps?: (Record | null) | undefined}; export type UpdateApiV1HivesHiveIdArgs = {hive_id: string, body: BackendDbModelsHiveContent}; export type UpdateApiV1HivesHiveIdOptions = {baseUrl?: string | undefined, HTTPBearer?: string | undefined, fetch?: typeof fetch | undefined}; export const hiveType = z.enum(["WEBSITE", "GOOGLE_DOCS", "DOCS", "TRANSCRIPTS"]); export const files = z.object({id: z.string().optional(), orgId: z.string().optional(), fileName: z.string().optional(), fileUrl: z.string().optional(), createdBy: z.string().optional(), createdAt: z.string().optional(), updatedBy: z.string().optional(), updatedAt: z.string().optional()}); export const hiveContentOutput = z.object({hiveType: hiveType, url: z.string().min(1).max(512).nullable().optional(), files: z.array(files).nullable().optional(), hiveProps: z.object({}).nullable().optional(), internalProps: z.object({}).nullable().optional()}); export const hive = z.object({id: z.string().optional(), orgId: z.string().optional(), content: hiveContentOutput, status: z.string(), createdBy: z.string().optional(), createdAt: z.string().optional(), updatedBy: z.string().optional(), updatedAt: 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 }; /** * Update a Specific Hive by ID * * PUT /v1/hives/{hive_id} */ export const updateApiV1HivesHiveId = async (args: UpdateApiV1HivesHiveIdArgs, options?: UpdateApiV1HivesHiveIdOptions) => { const {baseUrl = "https://api.trata.ai", fetch: fetchFn = fetch, HTTPBearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (HTTPBearer !== undefined) headers.set('authorization', `Bearer ${HTTPBearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/hives/${encodeURIComponent(String(args.hive_id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", 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(hive, await res.json()) };