import {z} from 'zod' export type GetApiApiV1OjkAuditRetentionArgs = {'X-Tenant-ID'?: string | undefined, 'X-Org-ID'?: string | undefined, data_types?: string | undefined}; export type GetApiApiV1OjkAuditRetentionOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const oJKRetentionStatusResponse = z.object({compliance_status: z.enum(["compliant", "non_compliant"]).optional(), framework: z.string().optional(), retention_days: z.number().int().optional(), min_retention_days: z.number().int().optional(), data_types: z.array(z.object({data_type: z.string().optional(), status: z.string().optional(), oldest_record: z.string().optional(), newest_record: z.string().optional(), total_records: z.number().int().optional()})).optional(), next_cleanup: 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 }; /** * Get OJK retention status * * GET /api/v1/ojk/audit/retention */ export const getApiApiV1OjkAuditRetention = async (args: GetApiApiV1OjkAuditRetentionArgs, options?: GetApiApiV1OjkAuditRetentionOptions) => { const {baseUrl = "https://orchestrator.getaxonflow.com", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args['X-Tenant-ID'] != null) headers.set("X-Tenant-ID", String(args['X-Tenant-ID'])) if (args['X-Org-ID'] != null) headers.set("X-Org-ID", String(args['X-Org-ID'])) if (args.data_types != null) query.append("data_types", String(args.data_types)) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/ojk/audit/retention${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(oJKRetentionStatusResponse, await res.json()) };