import {z} from 'zod' export type CreateApiV1PoliciesPolicyIdUploadArgs = {policy_id: string, body: BodyInit}; export type CreateApiV1PoliciesPolicyIdUploadOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const policyCategory = z.enum(["privacy", "ethics", "security", "compliance", "operational", "brand", "custom"]); export const policyStatus = z.enum(["draft", "active", "archived"]); export const policy = z.object({id: z.string(), team_id: z.string(), name: z.string(), description: z.string().nullable().optional(), category: policyCategory, status: policyStatus.optional(), source_text: z.string().nullable().optional(), file_path: z.string().nullable().optional(), file_name: z.string().nullable().optional(), file_type: z.string().nullable().optional(), file_size_bytes: z.number().int().nullable().optional(), converted_file_path: z.string().nullable().optional(), is_preset: z.boolean().optional(), preset_source: z.string().nullable().optional(), tags: z.array(z.string()).nullable().optional(), created_at: z.number().int(), updated_at: z.number().int(), created_by: z.string()}); 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 }; /** * Upload File * * POST /v1/policies/{policy_id}/upload */ export const createApiV1PoliciesPolicyIdUpload = async (args: CreateApiV1PoliciesPolicyIdUploadArgs, options: CreateApiV1PoliciesPolicyIdUploadOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/v1/policies/${encodeURIComponent(String(args.policy_id))}/upload${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: args.body}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(policy, await res.json()) };