/** * PEAC Policy Kit Loader * * Loads and validates policy documents from YAML or JSON. * No network calls - file system only. * * @packageDocumentation */ import { ZodError } from 'zod'; import { PolicyDocument } from './types'; /** * Policy load error */ export declare class PolicyLoadError extends Error { readonly cause?: (Error | ZodError) | undefined; constructor(message: string, cause?: (Error | ZodError) | undefined); } /** * Policy validation error with details */ export declare class PolicyValidationError extends PolicyLoadError { readonly issues: ZodError['issues']; constructor(message: string, issues: ZodError['issues']); } /** * Parse a `peac-policy/0.1` document from raw bytes and validate against the * normative schema. Accepts the document format referenced from `peac.txt` * (via `policy_doc.url` or `policy_doc.inline`) or the inline payload of a * `docs/specs/PEAC-TXT.md`-conformant policy document fetched separately. * * Auto-detects JSON vs YAML. Throws `PolicyValidationError` when the document * is well-formed but does not satisfy `peac-policy/0.1` (e.g. missing * `version`, unknown `defaults.decision`, malformed `rules`). Throws * `PolicyLoadError` when the text cannot be parsed as either JSON or YAML. * * This function is network-free and accepts pre-fetched bytes. Callers are * responsible for fetching the document (typically via the URL returned by * `@peac/disc.parse(...).data.policy_doc.url`) and passing the bytes here. * * @param text - Raw UTF-8 bytes of a `peac-policy/0.1` document (YAML or JSON) * @returns Validated `PolicyDocument` * @throws PolicyLoadError on parse failure * @throws PolicyValidationError on schema validation failure * @see docs/specs/PEAC-TXT.md */ export declare function parsePolicyDocument(text: string): PolicyDocument; /** * Parse policy from string content * * @param content - YAML or JSON string * @param format - Optional format hint ('yaml' | 'json'), auto-detected if not provided * @returns Validated policy document * @throws PolicyLoadError on parse failure * @throws PolicyValidationError on schema validation failure */ export declare function parsePolicy(content: string, format?: 'yaml' | 'json'): PolicyDocument; /** * Validate a parsed policy object * * @param obj - Parsed policy object (from YAML/JSON) * @returns Validated policy document * @throws PolicyValidationError on schema validation failure */ export declare function validatePolicy(obj: unknown): PolicyDocument; /** * Load policy from file * * @param filePath - Path to policy file (.yaml, .yml, or .json) * @returns Validated policy document * @throws PolicyLoadError on file read or parse failure * @throws PolicyValidationError on schema validation failure */ export declare function loadPolicy(filePath: string): PolicyDocument; /** * Check if a policy file exists and is readable * * @param filePath - Path to policy file * @returns true if file exists and is readable */ export declare function policyFileExists(filePath: string): boolean; /** * Create a minimal example policy document * * Useful for scaffolding new policy files. */ export declare function createExamplePolicy(): PolicyDocument; /** * Serialize policy to YAML string * * @param policy - Policy document to serialize * @returns YAML string */ export declare function serializePolicyYaml(policy: PolicyDocument): string; /** * Serialize policy to JSON string * * @param policy - Policy document to serialize * @param pretty - Pretty-print with indentation (default: true) * @returns JSON string */ export declare function serializePolicyJson(policy: PolicyDocument, pretty?: boolean): string; //# sourceMappingURL=loader.d.ts.map