/** * PEAC Policy Kit Types * * Deterministic policy format for CAL semantics. * Version: peac-policy/0.1 * * Design principles: * - No scripting, no dynamic code * - Deterministic, auditable, side-effect free * - First-match-wins rule semantics * * @packageDocumentation */ import { z } from 'zod'; import { ControlPurposeSchema, ControlLicensingModeSchema, ControlDecisionSchema, SubjectTypeSchema } from '@peac/schema'; /** * Policy format version */ export declare const POLICY_VERSION = "peac-policy/0.1"; /** * Subject type (re-export from schema) */ export type SubjectType = z.infer; /** * Control purpose (re-export from schema) */ export type ControlPurpose = z.infer; /** * Control licensing mode (re-export from schema) */ export type ControlLicensingMode = z.infer; /** * Control decision (re-export from schema) */ export type ControlDecision = z.infer; /** * Subject matcher - criteria for matching a subject * * All fields are optional (omitted = any/wildcard). * When multiple fields are present, all must match (AND logic). */ export declare const SubjectMatcherSchema: z.ZodObject<{ type: z.ZodOptional, z.ZodArray>]>>; labels: z.ZodOptional>; id: z.ZodOptional; }, z.core.$strict>; export type SubjectMatcher = z.infer; /** * Policy rule - a single rule in the policy * * Evaluated in order; first match wins. */ export declare const PolicyRuleSchema: z.ZodObject<{ name: z.ZodString; subject: z.ZodOptional, z.ZodArray>]>>; labels: z.ZodOptional>; id: z.ZodOptional; }, z.core.$strict>>; purpose: z.ZodOptional, z.ZodArray>]>>; licensing_mode: z.ZodOptional, z.ZodArray>]>>; decision: z.ZodEnum<{ allow: "allow"; deny: "deny"; review: "review"; }>; reason: z.ZodOptional; }, z.core.$strict>; export type PolicyRule = z.infer; /** * Policy defaults - fallback values when no rule matches */ export declare const PolicyDefaultsSchema: z.ZodObject<{ decision: z.ZodEnum<{ allow: "allow"; deny: "deny"; review: "review"; }>; reason: z.ZodOptional; }, z.core.$strict>; export type PolicyDefaults = z.infer; /** * Complete policy document */ export declare const PolicyDocumentSchema: z.ZodObject<{ version: z.ZodLiteral<"peac-policy/0.1">; name: z.ZodOptional; defaults: z.ZodObject<{ decision: z.ZodEnum<{ allow: "allow"; deny: "deny"; review: "review"; }>; reason: z.ZodOptional; }, z.core.$strict>; rules: z.ZodArray, z.ZodArray>]>>; labels: z.ZodOptional>; id: z.ZodOptional; }, z.core.$strict>>; purpose: z.ZodOptional, z.ZodArray>]>>; licensing_mode: z.ZodOptional, z.ZodArray>]>>; decision: z.ZodEnum<{ allow: "allow"; deny: "deny"; review: "review"; }>; reason: z.ZodOptional; }, z.core.$strict>>; }, z.core.$strict>; export type PolicyDocument = z.infer; /** * Evaluation context - input to policy evaluation */ export interface EvaluationContext { /** Subject information */ subject?: { /** Subject ID */ id?: string; /** Subject type */ type?: SubjectType; /** Subject labels */ labels?: string[]; }; /** Purpose of access */ purpose?: ControlPurpose; /** Licensing mode */ licensing_mode?: ControlLicensingMode; } /** * Evaluation result */ export interface EvaluationResult { /** Decision from evaluation */ decision: ControlDecision; /** Name of matched rule (undefined if default applied) */ matched_rule?: string; /** Reason for decision */ reason?: string; /** Whether default was applied (no rule matched) */ is_default: boolean; } /** * Structured rate limit configuration. * * Uses `window_seconds` for future-proofing (avoids enum lock-in). * CLI parses human-friendly strings like "100/hour" to this format. * * @example * ```typescript * const limit: RateLimitConfig = { * limit: 100, * window_seconds: 3600, // 1 hour * burst: 10, * partition: 'agent', * }; * ``` */ export declare const RateLimitConfigSchema: z.ZodObject<{ limit: z.ZodNumber; window_seconds: z.ZodNumber; burst: z.ZodOptional; partition: z.ZodOptional, z.ZodString]>>; }, z.core.$strict>; export type RateLimitConfig = z.infer; /** * Parse a human-friendly rate limit string to RateLimitConfig. * * @example * ```typescript * parseRateLimit('100/hour'); // { limit: 100, window_seconds: 3600 } * parseRateLimit('1000/day'); // { limit: 1000, window_seconds: 86400 } * parseRateLimit('10/minute'); // { limit: 10, window_seconds: 60 } * ``` */ export declare function parseRateLimit(input: string): RateLimitConfig; /** * Format a RateLimitConfig to human-friendly string. */ export declare function formatRateLimit(config: RateLimitConfig): string; /** * Requirements for 'review' decision (challenge-required semantics). * * When decision is 'review' and requirements are not met: * - Enforcement returns a challenge response (e.g., HTTP 402) * - Client provides proof (e.g., PEAC receipt) * - On valid proof, access is granted * * This differs from 'deny' which is unconditional rejection. * * @example * ```typescript * const rule: PolicyRule = { * name: 'inference-needs-receipt', * purpose: 'inference', * decision: 'review', * requirements: { receipt: true }, * }; * ``` */ export declare const DecisionRequirementsSchema: z.ZodObject<{ receipt: z.ZodOptional; }, z.core.$strict>; export type DecisionRequirements = z.infer; /** * Profile parameter definition. * * Defines a configurable parameter for a profile. */ export declare const ProfileParameterSchema: z.ZodObject<{ description: z.ZodString; required: z.ZodOptional; default: z.ZodOptional>; example: z.ZodOptional; validate: z.ZodOptional>; }, z.core.$strict>; export type ProfileParameter = z.infer; /** * Profile definition. * * A profile is a pre-configured policy template for a specific use case * (e.g., news publisher, SaaS docs, open source project). * * Profiles are compiled to TypeScript at build time for: * - Type safety * - No runtime YAML/fs dependencies * - Deterministic output * * @example * ```typescript * const profile: ProfileDefinition = { * id: 'news-media', * name: 'News Media Publisher', * description: 'Policy for news and media publishers...', * policy: { ... }, * parameters: { * contact: { description: 'Contact email', required: true, validate: 'email' }, * rate_limit: { description: 'Rate limit', default: '100/hour', validate: 'rate_limit' }, * }, * defaults: { * requirements: { receipt: true }, * }, * }; * ``` */ export declare const ProfileDefinitionSchema: z.ZodObject<{ id: z.ZodString; name: z.ZodString; description: z.ZodString; policy: z.ZodObject<{ version: z.ZodLiteral<"peac-policy/0.1">; name: z.ZodOptional; defaults: z.ZodObject<{ decision: z.ZodEnum<{ allow: "allow"; deny: "deny"; review: "review"; }>; reason: z.ZodOptional; }, z.core.$strict>; rules: z.ZodArray, z.ZodArray>]>>; labels: z.ZodOptional>; id: z.ZodOptional; }, z.core.$strict>>; purpose: z.ZodOptional, z.ZodArray>]>>; licensing_mode: z.ZodOptional, z.ZodArray>]>>; decision: z.ZodEnum<{ allow: "allow"; deny: "deny"; review: "review"; }>; reason: z.ZodOptional; }, z.core.$strict>>; }, z.core.$strict>; parameters: z.ZodRecord; default: z.ZodOptional>; example: z.ZodOptional; validate: z.ZodOptional>; }, z.core.$strict>>; defaults: z.ZodOptional; }, z.core.$strict>>; rate_limit: z.ZodOptional; partition: z.ZodOptional, z.ZodString]>>; }, z.core.$strict>>; }, z.core.$strict>>; }, z.core.$strict>; export type ProfileDefinition = z.infer; /** * Policy constraints for rate limiting and budget control. * * These constraints are ADVISORY - enforcement happens at the edge/application layer. * PEAC receipts capture what constraints were DECLARED, not whether they were enforced. * * @example * ```typescript * const constraints: PolicyConstraints = { * rate_limit: { window_s: 3600, max: 100 }, * budget: { max_requests: 1000 }, * }; * ``` */ export declare const PolicyConstraintsSchema: z.ZodObject<{ rate_limit: z.ZodOptional; }, z.core.$strict>>; budget: z.ZodOptional; max_requests: z.ZodOptional; }, z.core.$strict>>; }, z.core.$strict>; export type PolicyConstraints = z.infer; /** * Enforcement profile for purpose handling. * * Defines how undeclared or unknown purposes are handled at the enforcement layer. * These are distinct from use-case profiles (api-provider, news-media, etc.). * * Three canonical profiles: * - `strict`: Deny undeclared purposes (regulated data, private APIs) * - `balanced`: Review + constraints for undeclared purposes (general web, default) * - `open`: Allow undeclared purposes with recording (public content, research) */ export type EnforcementProfileId = 'strict' | 'balanced' | 'open'; /** * Enforcement profile definition. * * Specifies how to handle requests with undeclared, unknown, or missing purposes. */ export declare const EnforcementProfileSchema: z.ZodObject<{ id: z.ZodEnum<{ strict: "strict"; balanced: "balanced"; open: "open"; }>; name: z.ZodString; description: z.ZodString; undeclared_decision: z.ZodEnum<{ allow: "allow"; deny: "deny"; review: "review"; }>; unknown_decision: z.ZodEnum<{ allow: "allow"; deny: "deny"; review: "review"; }>; purpose_reason: z.ZodEnum<{ allowed: "allowed"; constrained: "constrained"; denied: "denied"; downgraded: "downgraded"; undeclared_default: "undeclared_default"; unknown_preserved: "unknown_preserved"; }>; default_constraints: z.ZodOptional; }, z.core.$strict>>; budget: z.ZodOptional; max_requests: z.ZodOptional; }, z.core.$strict>>; }, z.core.$strict>>; receipts: z.ZodEnum<{ optional: "optional"; required: "required"; omit: "omit"; }>; }, z.core.$strict>; export type EnforcementProfile = z.infer; //# sourceMappingURL=types.d.ts.map