import {z} from 'zod' export type RetentionPolicyUpdate = {name?: (string | null) | undefined, turn_retention_days?: (number | null) | undefined, session_retention_days?: (number | null) | undefined, archive_strategy?: ('soft_delete' | 'hard_delete' | null) | undefined, is_default?: (boolean | null) | undefined}; export type UpdateApiV1RetentionPoliciesPolicyIdArgs = {policy_id: string, body: RetentionPolicyUpdate}; export type UpdateApiV1RetentionPoliciesPolicyIdOptions = {baseUrl: string, APIKeyHeader?: string | undefined, fetch?: typeof fetch | undefined}; export const srcConversationSchemasRetentionPolicyResponse = z.object({id: z.string(), organization_id: z.string(), name: z.string(), turn_retention_days: z.number().int().nullable().optional(), session_retention_days: z.number().int().nullable().optional(), archive_strategy: z.enum(["soft_delete", "hard_delete"]), is_default: z.boolean(), created_at: z.string(), updated_at: 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 }; /** * Update a retention policy * * PUT /v1/retention-policies/{policy_id} */ export const updateApiV1RetentionPoliciesPolicyId = async (args: UpdateApiV1RetentionPoliciesPolicyIdArgs, options: UpdateApiV1RetentionPoliciesPolicyIdOptions) => { const {baseUrl, fetch: fetchFn = fetch, APIKeyHeader} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (APIKeyHeader !== undefined) headers.set("x-api-key", APIKeyHeader) const url = `${baseUrl.replace(/\/+$/, '')}/v1/retention-policies/${encodeURIComponent(String(args.policy_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(srcConversationSchemasRetentionPolicyResponse, await res.json()) };