@peac/control 0.9.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +23 -0
- package/dist/adapter.d.ts +143 -0
- package/dist/adapter.d.ts.map +1 -0
- package/dist/adapter.js +74 -0
- package/dist/adapter.js.map +1 -0
- package/dist/constraints.d.ts +107 -0
- package/dist/constraints.d.ts.map +1 -0
- package/dist/constraints.js +14 -0
- package/dist/constraints.js.map +1 -0
- package/dist/enforcement.d.ts +35 -0
- package/dist/enforcement.d.ts.map +1 -0
- package/dist/enforcement.js +201 -0
- package/dist/enforcement.js.map +1 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +57 -0
- package/dist/index.js.map +1 -0
- package/dist/state.d.ts +27 -0
- package/dist/state.d.ts.map +1 -0
- package/dist/state.js +139 -0
- package/dist/state.js.map +1 -0
- package/dist/types.d.ts +23 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +6 -0
- package/dist/types.js.map +1 -0
- package/dist/validators.d.ts +798 -0
- package/dist/validators.d.ts.map +1 -0
- package/dist/validators.js +159 -0
- package/dist/validators.js.map +1 -0
- package/package.json +36 -0
package/README.md
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# @peac/control
|
|
2
|
+
|
|
3
|
+
PEAC Protocol Control - control engine interfaces and validation
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pnpm add @peac/control
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Documentation
|
|
12
|
+
|
|
13
|
+
See [peacprotocol.org](https://peacprotocol.org) for full documentation.
|
|
14
|
+
|
|
15
|
+
## License
|
|
16
|
+
|
|
17
|
+
Apache-2.0
|
|
18
|
+
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
PEAC Protocol is an open source project stewarded by Originary and community contributors.
|
|
22
|
+
|
|
23
|
+
[Originary](https://www.originary.xyz) | [Docs](https://peacprotocol.org) | [GitHub](https://github.com/peacprotocol/peac)
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PEAC Control Engine Adapter Interface
|
|
3
|
+
*
|
|
4
|
+
* Minimal, vendor-neutral interface for control engine implementations.
|
|
5
|
+
* Control engines evaluate authorization policies and return allow/deny decisions.
|
|
6
|
+
*
|
|
7
|
+
* @packageDocumentation
|
|
8
|
+
*/
|
|
9
|
+
import type { ControlStep } from '@peac/schema';
|
|
10
|
+
/**
|
|
11
|
+
* Context provided to control engine for evaluation
|
|
12
|
+
*
|
|
13
|
+
* This is the minimal context needed for most control engines.
|
|
14
|
+
* Engines may require additional context via the `policy` field.
|
|
15
|
+
*/
|
|
16
|
+
export interface ControlEvaluationContext {
|
|
17
|
+
/** Resource being accessed (e.g., "https://api.example.com/v1/chat") */
|
|
18
|
+
resource: string;
|
|
19
|
+
/** HTTP method or operation (e.g., "POST", "read", "write") */
|
|
20
|
+
method: string;
|
|
21
|
+
/** Requested payment amount (smallest currency unit), if applicable */
|
|
22
|
+
amount?: number;
|
|
23
|
+
/** Currency (ISO 4217), if applicable */
|
|
24
|
+
currency?: string;
|
|
25
|
+
/** Subject identifier (e.g., agent ID, user ID) */
|
|
26
|
+
subject?: string;
|
|
27
|
+
/** Policy document fetched from policy_uri (engine-specific structure) */
|
|
28
|
+
policy: unknown;
|
|
29
|
+
/** Current timestamp (Unix seconds) for temporal checks */
|
|
30
|
+
timestamp?: number;
|
|
31
|
+
/** Additional context (engine-specific) */
|
|
32
|
+
[key: string]: unknown;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Control Engine Adapter
|
|
36
|
+
*
|
|
37
|
+
* Minimal interface that all control engines must implement.
|
|
38
|
+
*
|
|
39
|
+
* **Design principles**:
|
|
40
|
+
* - Vendor-neutral: No hardcoded engine names or vendor-specific types
|
|
41
|
+
* - Stateless: Engine is responsible for fetching its own state if needed
|
|
42
|
+
* - Async: Allows engines to make network calls (fetch policies, check quotas)
|
|
43
|
+
* - Opaque: Policy structure is engine-specific (unknown type)
|
|
44
|
+
*
|
|
45
|
+
* **Examples of engines**:
|
|
46
|
+
* - Spend control: Per-transaction, daily, monthly limits
|
|
47
|
+
* - Risk scoring: Fraud detection, anomaly detection
|
|
48
|
+
* - Mandate enforcement: Enterprise approval chains
|
|
49
|
+
* - Rate limiting: Request quotas, throttling
|
|
50
|
+
*
|
|
51
|
+
* **Usage**:
|
|
52
|
+
* ```typescript
|
|
53
|
+
* const engine: ControlEngineAdapter = new MyControlEngine();
|
|
54
|
+
* const step = await engine.evaluate({
|
|
55
|
+
* resource: "https://api.example.com/v1/chat",
|
|
56
|
+
* method: "POST",
|
|
57
|
+
* amount: 250,
|
|
58
|
+
* currency: "USD",
|
|
59
|
+
* policy: { ... } // Fetched from policy_uri
|
|
60
|
+
* });
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
export interface ControlEngineAdapter {
|
|
64
|
+
/**
|
|
65
|
+
* Engine identifier (vendor-neutral)
|
|
66
|
+
*
|
|
67
|
+
* Examples:
|
|
68
|
+
* - "spend-control-service"
|
|
69
|
+
* - "risk-engine"
|
|
70
|
+
* - "mandate-service"
|
|
71
|
+
*
|
|
72
|
+
* See docs/specs/registries.json for common identifiers.
|
|
73
|
+
*/
|
|
74
|
+
readonly engineId: string;
|
|
75
|
+
/**
|
|
76
|
+
* Engine version (optional, for tracking)
|
|
77
|
+
*
|
|
78
|
+
* Format: Semantic versioning (e.g., "1.2.3")
|
|
79
|
+
*/
|
|
80
|
+
readonly version?: string;
|
|
81
|
+
/**
|
|
82
|
+
* Evaluate authorization policy and return control decision
|
|
83
|
+
*
|
|
84
|
+
* @param context - Evaluation context (resource, method, amount, policy, etc.)
|
|
85
|
+
* @returns Control step with decision (allow/deny) and optional limits_snapshot
|
|
86
|
+
* @throws Error if evaluation fails (network error, invalid policy, etc.)
|
|
87
|
+
*
|
|
88
|
+
* **Requirements**:
|
|
89
|
+
* - MUST return a valid ControlStep with result: "allow" | "deny" | "review"
|
|
90
|
+
* - SHOULD populate reason if result is "deny" or "review"
|
|
91
|
+
* - MAY populate limits_snapshot with engine-specific state
|
|
92
|
+
* - MAY populate evidence_ref with URL to detailed evidence
|
|
93
|
+
* - MUST NOT throw on normal deny decisions (only throw on errors)
|
|
94
|
+
*/
|
|
95
|
+
evaluate(context: ControlEvaluationContext): Promise<ControlStep>;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Control Engine Registry
|
|
99
|
+
*
|
|
100
|
+
* Optional helper for managing multiple control engines.
|
|
101
|
+
*
|
|
102
|
+
* **Usage**:
|
|
103
|
+
* ```typescript
|
|
104
|
+
* const registry = new ControlEngineRegistry();
|
|
105
|
+
* registry.register(new SpendControlEngine());
|
|
106
|
+
* registry.register(new RiskEngine());
|
|
107
|
+
*
|
|
108
|
+
* const engine = registry.get("spend-control-service");
|
|
109
|
+
* const step = await engine.evaluate(context);
|
|
110
|
+
* ```
|
|
111
|
+
*/
|
|
112
|
+
export declare class ControlEngineRegistry {
|
|
113
|
+
private engines;
|
|
114
|
+
/**
|
|
115
|
+
* Register a control engine
|
|
116
|
+
*
|
|
117
|
+
* @param engine - Control engine adapter
|
|
118
|
+
* @throws Error if engine with same ID already registered
|
|
119
|
+
*/
|
|
120
|
+
register(engine: ControlEngineAdapter): void;
|
|
121
|
+
/**
|
|
122
|
+
* Get control engine by ID
|
|
123
|
+
*
|
|
124
|
+
* @param engineId - Engine identifier
|
|
125
|
+
* @returns Control engine adapter
|
|
126
|
+
* @throws Error if engine not found
|
|
127
|
+
*/
|
|
128
|
+
get(engineId: string): ControlEngineAdapter;
|
|
129
|
+
/**
|
|
130
|
+
* Check if engine is registered
|
|
131
|
+
*
|
|
132
|
+
* @param engineId - Engine identifier
|
|
133
|
+
* @returns True if engine is registered
|
|
134
|
+
*/
|
|
135
|
+
has(engineId: string): boolean;
|
|
136
|
+
/**
|
|
137
|
+
* Get all registered engine IDs
|
|
138
|
+
*
|
|
139
|
+
* @returns Array of engine IDs
|
|
140
|
+
*/
|
|
141
|
+
list(): string[];
|
|
142
|
+
}
|
|
143
|
+
//# sourceMappingURL=adapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAEhD;;;;;GAKG;AACH,MAAM,WAAW,wBAAwB;IACvC,wEAAwE;IACxE,QAAQ,EAAE,MAAM,CAAC;IAEjB,+DAA+D;IAC/D,MAAM,EAAE,MAAM,CAAC;IAEf,uEAAuE;IACvE,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB,yCAAyC;IACzC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB,mDAAmD;IACnD,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB,0EAA0E;IAC1E,MAAM,EAAE,OAAO,CAAC;IAEhB,2DAA2D;IAC3D,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB,2CAA2C;IAC3C,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,MAAM,WAAW,oBAAoB;IACnC;;;;;;;;;OASG;IACH,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAE1B;;;;OAIG;IACH,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAE1B;;;;;;;;;;;;;OAaG;IACH,QAAQ,CAAC,OAAO,EAAE,wBAAwB,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC;CACnE;AAED;;;;;;;;;;;;;;GAcG;AACH,qBAAa,qBAAqB;IAChC,OAAO,CAAC,OAAO,CAA2C;IAE1D;;;;;OAKG;IACH,QAAQ,CAAC,MAAM,EAAE,oBAAoB,GAAG,IAAI;IAO5C;;;;;;OAMG;IACH,GAAG,CAAC,QAAQ,EAAE,MAAM,GAAG,oBAAoB;IAQ3C;;;;;OAKG;IACH,GAAG,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO;IAI9B;;;;OAIG;IACH,IAAI,IAAI,MAAM,EAAE;CAGjB"}
|
package/dist/adapter.js
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* PEAC Control Engine Adapter Interface
|
|
4
|
+
*
|
|
5
|
+
* Minimal, vendor-neutral interface for control engine implementations.
|
|
6
|
+
* Control engines evaluate authorization policies and return allow/deny decisions.
|
|
7
|
+
*
|
|
8
|
+
* @packageDocumentation
|
|
9
|
+
*/
|
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
+
exports.ControlEngineRegistry = void 0;
|
|
12
|
+
/**
|
|
13
|
+
* Control Engine Registry
|
|
14
|
+
*
|
|
15
|
+
* Optional helper for managing multiple control engines.
|
|
16
|
+
*
|
|
17
|
+
* **Usage**:
|
|
18
|
+
* ```typescript
|
|
19
|
+
* const registry = new ControlEngineRegistry();
|
|
20
|
+
* registry.register(new SpendControlEngine());
|
|
21
|
+
* registry.register(new RiskEngine());
|
|
22
|
+
*
|
|
23
|
+
* const engine = registry.get("spend-control-service");
|
|
24
|
+
* const step = await engine.evaluate(context);
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
class ControlEngineRegistry {
|
|
28
|
+
engines = new Map();
|
|
29
|
+
/**
|
|
30
|
+
* Register a control engine
|
|
31
|
+
*
|
|
32
|
+
* @param engine - Control engine adapter
|
|
33
|
+
* @throws Error if engine with same ID already registered
|
|
34
|
+
*/
|
|
35
|
+
register(engine) {
|
|
36
|
+
if (this.engines.has(engine.engineId)) {
|
|
37
|
+
throw new Error(`Control engine already registered: ${engine.engineId}`);
|
|
38
|
+
}
|
|
39
|
+
this.engines.set(engine.engineId, engine);
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Get control engine by ID
|
|
43
|
+
*
|
|
44
|
+
* @param engineId - Engine identifier
|
|
45
|
+
* @returns Control engine adapter
|
|
46
|
+
* @throws Error if engine not found
|
|
47
|
+
*/
|
|
48
|
+
get(engineId) {
|
|
49
|
+
const engine = this.engines.get(engineId);
|
|
50
|
+
if (!engine) {
|
|
51
|
+
throw new Error(`Control engine not found: ${engineId}`);
|
|
52
|
+
}
|
|
53
|
+
return engine;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Check if engine is registered
|
|
57
|
+
*
|
|
58
|
+
* @param engineId - Engine identifier
|
|
59
|
+
* @returns True if engine is registered
|
|
60
|
+
*/
|
|
61
|
+
has(engineId) {
|
|
62
|
+
return this.engines.has(engineId);
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Get all registered engine IDs
|
|
66
|
+
*
|
|
67
|
+
* @returns Array of engine IDs
|
|
68
|
+
*/
|
|
69
|
+
list() {
|
|
70
|
+
return Array.from(this.engines.keys());
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
exports.ControlEngineRegistry = ControlEngineRegistry;
|
|
74
|
+
//# sourceMappingURL=adapter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adapter.js","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":";AAAA;;;;;;;GAOG;;;AAsGH;;;;;;;;;;;;;;GAcG;AACH,MAAa,qBAAqB;IACxB,OAAO,GAAG,IAAI,GAAG,EAAgC,CAAC;IAE1D;;;;;OAKG;IACH,QAAQ,CAAC,MAA4B;QACnC,IAAI,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAC;YACtC,MAAM,IAAI,KAAK,CAAC,sCAAsC,MAAM,CAAC,QAAQ,EAAE,CAAC,CAAC;QAC3E,CAAC;QACD,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;IAC5C,CAAC;IAED;;;;;;OAMG;IACH,GAAG,CAAC,QAAgB;QAClB,MAAM,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QAC1C,IAAI,CAAC,MAAM,EAAE,CAAC;YACZ,MAAM,IAAI,KAAK,CAAC,6BAA6B,QAAQ,EAAE,CAAC,CAAC;QAC3D,CAAC;QACD,OAAO,MAAM,CAAC;IAChB,CAAC;IAED;;;;;OAKG;IACH,GAAG,CAAC,QAAgB;QAClB,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IACpC,CAAC;IAED;;;;OAIG;IACH,IAAI;QACF,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC;IACzC,CAAC;CACF;AAjDD,sDAiDC"}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generic Control Constraint Types
|
|
3
|
+
*
|
|
4
|
+
* These are informational helper types that control engines MAY use
|
|
5
|
+
* in their limits_snapshot fields. They are NOT part of the normative
|
|
6
|
+
* wire format.
|
|
7
|
+
*
|
|
8
|
+
* Control engines are free to use custom constraint models.
|
|
9
|
+
* These types provide common patterns (temporal, usage, budget)
|
|
10
|
+
* that many engines need.
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* Constraint type identifiers
|
|
14
|
+
*/
|
|
15
|
+
export type ConstraintType = 'temporal' | 'usage' | 'budget' | 'combined';
|
|
16
|
+
/**
|
|
17
|
+
* Temporal constraint - time-based access control
|
|
18
|
+
*
|
|
19
|
+
* Common use cases:
|
|
20
|
+
* - Access only during business hours
|
|
21
|
+
* - Time-limited API keys
|
|
22
|
+
* - Temporary elevated permissions
|
|
23
|
+
*/
|
|
24
|
+
export interface TemporalConstraint {
|
|
25
|
+
/** Constraint type */
|
|
26
|
+
type: 'temporal';
|
|
27
|
+
/** Access granted from (Unix timestamp seconds) */
|
|
28
|
+
valid_from?: number;
|
|
29
|
+
/** Access expires at (Unix timestamp seconds) */
|
|
30
|
+
valid_until?: number;
|
|
31
|
+
/** Maximum duration in seconds */
|
|
32
|
+
duration?: number;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Usage constraint - count-based restrictions
|
|
36
|
+
*
|
|
37
|
+
* Common use cases:
|
|
38
|
+
* - Rate limiting (N requests per window)
|
|
39
|
+
* - Quota management (N API calls per month)
|
|
40
|
+
* - One-time use tokens
|
|
41
|
+
*/
|
|
42
|
+
export interface UsageConstraint {
|
|
43
|
+
/** Constraint type */
|
|
44
|
+
type: 'usage';
|
|
45
|
+
/** Maximum number of uses allowed */
|
|
46
|
+
max_uses: number;
|
|
47
|
+
/** Current usage count (tracked by issuer) */
|
|
48
|
+
current_uses?: number;
|
|
49
|
+
/** Usage window in seconds (optional) */
|
|
50
|
+
window?: number;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Budget constraint - amount-based restrictions
|
|
54
|
+
*
|
|
55
|
+
* Common use cases:
|
|
56
|
+
* - Spending limits (per transaction, daily, monthly)
|
|
57
|
+
* - Credit limits
|
|
58
|
+
* - Expense controls
|
|
59
|
+
*/
|
|
60
|
+
export interface BudgetConstraint {
|
|
61
|
+
/** Constraint type */
|
|
62
|
+
type: 'budget';
|
|
63
|
+
/** Maximum amount allowed (smallest currency unit) */
|
|
64
|
+
max_amount: number;
|
|
65
|
+
/** Current spent amount (tracked by issuer) */
|
|
66
|
+
current_amount?: number;
|
|
67
|
+
/** Budget window in seconds (optional) */
|
|
68
|
+
window?: number;
|
|
69
|
+
/** Currency (ISO 4217) */
|
|
70
|
+
currency: string;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Combined constraint - multiple restrictions
|
|
74
|
+
*
|
|
75
|
+
* Combines temporal, usage, and budget constraints.
|
|
76
|
+
* All specified constraints must be satisfied.
|
|
77
|
+
*/
|
|
78
|
+
export interface CombinedConstraint {
|
|
79
|
+
/** Constraint type */
|
|
80
|
+
type: 'combined';
|
|
81
|
+
/** Temporal restrictions */
|
|
82
|
+
temporal?: Omit<TemporalConstraint, 'type'>;
|
|
83
|
+
/** Usage restrictions */
|
|
84
|
+
usage?: Omit<UsageConstraint, 'type'>;
|
|
85
|
+
/** Budget restrictions */
|
|
86
|
+
budget?: Omit<BudgetConstraint, 'type'>;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Constraint union type
|
|
90
|
+
*/
|
|
91
|
+
export type Constraint = TemporalConstraint | UsageConstraint | BudgetConstraint | CombinedConstraint;
|
|
92
|
+
/**
|
|
93
|
+
* Enforcement result from evaluating a constraint
|
|
94
|
+
*/
|
|
95
|
+
export interface ConstraintEnforcementResult {
|
|
96
|
+
/** Whether the constraint is satisfied */
|
|
97
|
+
allowed: boolean;
|
|
98
|
+
/** Reason if not allowed */
|
|
99
|
+
reason?: string;
|
|
100
|
+
/** Remaining quota information */
|
|
101
|
+
remaining?: {
|
|
102
|
+
uses?: number;
|
|
103
|
+
amount?: number;
|
|
104
|
+
seconds?: number;
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
//# sourceMappingURL=constraints.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constraints.d.ts","sourceRoot":"","sources":["../src/constraints.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH;;GAEG;AACH,MAAM,MAAM,cAAc,GACtB,UAAU,GACV,OAAO,GACP,QAAQ,GACR,UAAU,CAAC;AAEf;;;;;;;GAOG;AACH,MAAM,WAAW,kBAAkB;IACjC,sBAAsB;IACtB,IAAI,EAAE,UAAU,CAAC;IAEjB,mDAAmD;IACnD,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB,iDAAiD;IACjD,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB,kCAAkC;IAClC,QAAQ,CAAC,EAAE,MAAM,CAAC;C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AChB,OAAO,CAAC,EAAE,MAAM,CAAC;KAClB,CAAC;CACH"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Generic Control Constraint Types
|
|
4
|
+
*
|
|
5
|
+
* These are informational helper types that control engines MAY use
|
|
6
|
+
* in their limits_snapshot fields. They are NOT part of the normative
|
|
7
|
+
* wire format.
|
|
8
|
+
*
|
|
9
|
+
* Control engines are free to use custom constraint models.
|
|
10
|
+
* These types provide common patterns (temporal, usage, budget)
|
|
11
|
+
* that many engines need.
|
|
12
|
+
*/
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
//# sourceMappingURL=constraints.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constraints.js","sourceRoot":"","sources":["../src/constraints.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;GAUG"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PEAC Control Abstraction Layer (CAL) Enforcement
|
|
3
|
+
*
|
|
4
|
+
* Enforcement logic for mandates and control blocks.
|
|
5
|
+
*/
|
|
6
|
+
import type { Constraint, ControlState, ConstraintEnforcementResult, TemporalConstraint, UsageConstraint, BudgetConstraint, CombinedConstraint } from './types';
|
|
7
|
+
type EnforcementResult = ConstraintEnforcementResult;
|
|
8
|
+
/**
|
|
9
|
+
* Enforce temporal mandate
|
|
10
|
+
*/
|
|
11
|
+
export declare function enforceTemporalConstraint(mandate: TemporalConstraint, currentTime?: number): EnforcementResult;
|
|
12
|
+
/**
|
|
13
|
+
* Enforce usage mandate
|
|
14
|
+
*/
|
|
15
|
+
export declare function enforceUsageConstraint(mandate: UsageConstraint, state?: ControlState): EnforcementResult;
|
|
16
|
+
/**
|
|
17
|
+
* Enforce budget mandate
|
|
18
|
+
*/
|
|
19
|
+
export declare function enforceBudgetConstraint(mandate: BudgetConstraint, state?: ControlState, requestedAmount?: number): EnforcementResult;
|
|
20
|
+
/**
|
|
21
|
+
* Enforce combined mandate
|
|
22
|
+
*/
|
|
23
|
+
export declare function enforceCombinedConstraint(mandate: CombinedConstraint, state?: ControlState, requestedAmount?: number, currentTime?: number): EnforcementResult;
|
|
24
|
+
/**
|
|
25
|
+
* Enforce mandate (dispatcher)
|
|
26
|
+
*/
|
|
27
|
+
export declare function enforceConstraint(mandate: Constraint, state?: ControlState, requestedAmount?: number, currentTime?: number): EnforcementResult;
|
|
28
|
+
/**
|
|
29
|
+
* Enforce control block
|
|
30
|
+
*
|
|
31
|
+
* @deprecated Use enforceConstraint directly. This function is maintained for backward compatibility.
|
|
32
|
+
*/
|
|
33
|
+
export declare function enforceControlBlock(constraint: Constraint, state?: ControlState, requestedAmount?: number, currentTime?: number): EnforcementResult;
|
|
34
|
+
export {};
|
|
35
|
+
//# sourceMappingURL=enforcement.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"enforcement.d.ts","sourceRoot":"","sources":["../src/enforcement.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EACV,UAAU,EACV,YAAY,EACZ,2BAA2B,EAC3B,kBAAkB,EAClB,eAAe,EACf,gBAAgB,EAChB,kBAAkB,EACnB,MAAM,SAAS,CAAC;AAEjB,KAAK,iBAAiB,GAAG,2BAA2B,CAAC;AAErD;;GAEG;AACH,wBAAgB,yBAAyB,CACvC,OAAO,EAAE,kBAAkB,EAC3B,WAAW,GAAE,MAAsC,GAClD,iBAAiB,CAiCnB;AAED;;GAEG;AACH,wBAAgB,sBAAsB,CACpC,OAAO,EAAE,eAAe,EACxB,KAAK,CAAC,EAAE,YAAY,GACnB,iBAAiB,CAgCnB;AAED;;GAEG;AACH,wBAAgB,uBAAuB,CACrC,OAAO,EAAE,gBAAgB,EACzB,KAAK,CAAC,EAAE,YAAY,EACpB,eAAe,CAAC,EAAE,MAAM,GACvB,iBAAiB,CA4CnB;AAED;;GAEG;AACH,wBAAgB,yBAAyB,CACvC,OAAO,EAAE,kBAAkB,EAC3B,KAAK,CAAC,EAAE,YAAY,EACpB,eAAe,CAAC,EAAE,MAAM,EACxB,WAAW,CAAC,EAAE,MAAM,GACnB,iBAAiB,CAmDnB;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAC/B,OAAO,EAAE,UAAU,EACnB,KAAK,CAAC,EAAE,YAAY,EACpB,eAAe,CAAC,EAAE,MAAM,EACxB,WAAW,CAAC,EAAE,MAAM,GACnB,iBAAiB,CAsBnB;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CACjC,UAAU,EAAE,UAAU,EACtB,KAAK,CAAC,EAAE,YAAY,EACpB,eAAe,CAAC,EAAE,MAAM,EACxB,WAAW,CAAC,EAAE,MAAM,GACnB,iBAAiB,CAEnB"}
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* PEAC Control Abstraction Layer (CAL) Enforcement
|
|
4
|
+
*
|
|
5
|
+
* Enforcement logic for mandates and control blocks.
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.enforceTemporalConstraint = enforceTemporalConstraint;
|
|
9
|
+
exports.enforceUsageConstraint = enforceUsageConstraint;
|
|
10
|
+
exports.enforceBudgetConstraint = enforceBudgetConstraint;
|
|
11
|
+
exports.enforceCombinedConstraint = enforceCombinedConstraint;
|
|
12
|
+
exports.enforceConstraint = enforceConstraint;
|
|
13
|
+
exports.enforceControlBlock = enforceControlBlock;
|
|
14
|
+
/**
|
|
15
|
+
* Enforce temporal mandate
|
|
16
|
+
*/
|
|
17
|
+
function enforceTemporalConstraint(mandate, currentTime = Math.floor(Date.now() / 1000)) {
|
|
18
|
+
// Check valid_from
|
|
19
|
+
if (mandate.valid_from !== undefined && currentTime < mandate.valid_from) {
|
|
20
|
+
const remaining = mandate.valid_from - currentTime;
|
|
21
|
+
return {
|
|
22
|
+
allowed: false,
|
|
23
|
+
reason: `Access not yet valid (starts in ${remaining}s)`,
|
|
24
|
+
remaining: { seconds: remaining },
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
// Check valid_until
|
|
28
|
+
if (mandate.valid_until !== undefined && currentTime > mandate.valid_until) {
|
|
29
|
+
return {
|
|
30
|
+
allowed: false,
|
|
31
|
+
reason: 'Access has expired',
|
|
32
|
+
remaining: { seconds: 0 },
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
// Calculate remaining time
|
|
36
|
+
let remainingSeconds;
|
|
37
|
+
if (mandate.valid_until !== undefined) {
|
|
38
|
+
remainingSeconds = mandate.valid_until - currentTime;
|
|
39
|
+
}
|
|
40
|
+
else if (mandate.duration !== undefined && mandate.valid_from !== undefined) {
|
|
41
|
+
const expiresAt = mandate.valid_from + mandate.duration;
|
|
42
|
+
remainingSeconds = expiresAt - currentTime;
|
|
43
|
+
}
|
|
44
|
+
return {
|
|
45
|
+
allowed: true,
|
|
46
|
+
remaining: remainingSeconds !== undefined ? { seconds: remainingSeconds } : undefined,
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Enforce usage mandate
|
|
51
|
+
*/
|
|
52
|
+
function enforceUsageConstraint(mandate, state) {
|
|
53
|
+
const currentUses = state?.usage_count ?? mandate.current_uses ?? 0;
|
|
54
|
+
// Check if max uses exceeded
|
|
55
|
+
if (currentUses >= mandate.max_uses) {
|
|
56
|
+
return {
|
|
57
|
+
allowed: false,
|
|
58
|
+
reason: `Usage limit exceeded (${currentUses}/${mandate.max_uses})`,
|
|
59
|
+
remaining: { uses: 0 },
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
// Check usage window if specified
|
|
63
|
+
if (mandate.window !== undefined && state?.first_use !== undefined) {
|
|
64
|
+
const currentTime = Math.floor(Date.now() / 1000);
|
|
65
|
+
const windowExpiry = state.first_use + mandate.window;
|
|
66
|
+
if (currentTime > windowExpiry) {
|
|
67
|
+
return {
|
|
68
|
+
allowed: false,
|
|
69
|
+
reason: 'Usage window expired',
|
|
70
|
+
remaining: { uses: 0 },
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
const remainingUses = mandate.max_uses - currentUses;
|
|
75
|
+
return {
|
|
76
|
+
allowed: true,
|
|
77
|
+
remaining: { uses: remainingUses },
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Enforce budget mandate
|
|
82
|
+
*/
|
|
83
|
+
function enforceBudgetConstraint(mandate, state, requestedAmount) {
|
|
84
|
+
const currentAmount = state?.spent_amount ?? mandate.current_amount ?? 0;
|
|
85
|
+
// Check if budget exceeded
|
|
86
|
+
if (currentAmount >= mandate.max_amount) {
|
|
87
|
+
return {
|
|
88
|
+
allowed: false,
|
|
89
|
+
reason: `Budget limit exceeded (${currentAmount}/${mandate.max_amount} ${mandate.currency})`,
|
|
90
|
+
remaining: { amount: 0 },
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
// Check if requested amount would exceed budget
|
|
94
|
+
if (requestedAmount !== undefined) {
|
|
95
|
+
if (currentAmount + requestedAmount > mandate.max_amount) {
|
|
96
|
+
const remaining = mandate.max_amount - currentAmount;
|
|
97
|
+
return {
|
|
98
|
+
allowed: false,
|
|
99
|
+
reason: `Requested amount would exceed budget (${requestedAmount} > ${remaining} ${mandate.currency} remaining)`,
|
|
100
|
+
remaining: { amount: remaining },
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
// Check budget window if specified
|
|
105
|
+
if (mandate.window !== undefined && state?.first_use !== undefined) {
|
|
106
|
+
const currentTime = Math.floor(Date.now() / 1000);
|
|
107
|
+
const windowExpiry = state.first_use + mandate.window;
|
|
108
|
+
if (currentTime > windowExpiry) {
|
|
109
|
+
return {
|
|
110
|
+
allowed: false,
|
|
111
|
+
reason: 'Budget window expired',
|
|
112
|
+
remaining: { amount: 0 },
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
const remainingAmount = mandate.max_amount - currentAmount;
|
|
117
|
+
return {
|
|
118
|
+
allowed: true,
|
|
119
|
+
remaining: { amount: remainingAmount },
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Enforce combined mandate
|
|
124
|
+
*/
|
|
125
|
+
function enforceCombinedConstraint(mandate, state, requestedAmount, currentTime) {
|
|
126
|
+
const results = [];
|
|
127
|
+
// Check temporal constraints
|
|
128
|
+
if (mandate.temporal !== undefined) {
|
|
129
|
+
const temporalConstraint = {
|
|
130
|
+
type: 'temporal',
|
|
131
|
+
...mandate.temporal,
|
|
132
|
+
};
|
|
133
|
+
const result = enforceTemporalConstraint(temporalConstraint, currentTime);
|
|
134
|
+
results.push(result);
|
|
135
|
+
}
|
|
136
|
+
// Check usage constraints
|
|
137
|
+
if (mandate.usage !== undefined) {
|
|
138
|
+
const usageConstraint = {
|
|
139
|
+
type: 'usage',
|
|
140
|
+
...mandate.usage,
|
|
141
|
+
};
|
|
142
|
+
const result = enforceUsageConstraint(usageConstraint, state);
|
|
143
|
+
results.push(result);
|
|
144
|
+
}
|
|
145
|
+
// Check budget constraints
|
|
146
|
+
if (mandate.budget !== undefined) {
|
|
147
|
+
const budgetConstraint = {
|
|
148
|
+
type: 'budget',
|
|
149
|
+
...mandate.budget,
|
|
150
|
+
};
|
|
151
|
+
const result = enforceBudgetConstraint(budgetConstraint, state, requestedAmount);
|
|
152
|
+
results.push(result);
|
|
153
|
+
}
|
|
154
|
+
// All constraints must be satisfied
|
|
155
|
+
const failedResult = results.find((r) => !r.allowed);
|
|
156
|
+
if (failedResult) {
|
|
157
|
+
return failedResult;
|
|
158
|
+
}
|
|
159
|
+
// Merge remaining information
|
|
160
|
+
const remaining = {};
|
|
161
|
+
for (const result of results) {
|
|
162
|
+
if (result.remaining) {
|
|
163
|
+
Object.assign(remaining, result.remaining);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
return {
|
|
167
|
+
allowed: true,
|
|
168
|
+
remaining: Object.keys(remaining).length > 0 ? remaining : undefined,
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Enforce mandate (dispatcher)
|
|
173
|
+
*/
|
|
174
|
+
function enforceConstraint(mandate, state, requestedAmount, currentTime) {
|
|
175
|
+
switch (mandate.type) {
|
|
176
|
+
case 'temporal':
|
|
177
|
+
return enforceTemporalConstraint(mandate, currentTime);
|
|
178
|
+
case 'usage':
|
|
179
|
+
return enforceUsageConstraint(mandate, state);
|
|
180
|
+
case 'budget':
|
|
181
|
+
return enforceBudgetConstraint(mandate, state, requestedAmount);
|
|
182
|
+
case 'combined':
|
|
183
|
+
return enforceCombinedConstraint(mandate, state, requestedAmount, currentTime);
|
|
184
|
+
default:
|
|
185
|
+
// TypeScript exhaustiveness check
|
|
186
|
+
const _exhaustive = mandate;
|
|
187
|
+
return {
|
|
188
|
+
allowed: false,
|
|
189
|
+
reason: `Unknown mandate type: ${_exhaustive.type}`,
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Enforce control block
|
|
195
|
+
*
|
|
196
|
+
* @deprecated Use enforceConstraint directly. This function is maintained for backward compatibility.
|
|
197
|
+
*/
|
|
198
|
+
function enforceControlBlock(constraint, state, requestedAmount, currentTime) {
|
|
199
|
+
return enforceConstraint(constraint, state, requestedAmount, currentTime);
|
|
200
|
+
}
|
|
201
|
+
//# sourceMappingURL=enforcement.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"enforcement.js","sourceRoot":"","sources":["../src/enforcement.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;AAiBH,8DAoCC;AAKD,wDAmCC;AAKD,0DAgDC;AAKD,8DAwDC;AAKD,8CA2BC;AAOD,kDAOC;AA/OD;;GAEG;AACH,SAAgB,yBAAyB,CACvC,OAA2B,EAC3B,cAAsB,IAAI,CAAC,KAAK,C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|
|
4
|
+
* Control engine interfaces, generic constraint helpers, and validation.
|
|
5
|
+
*
|
|
6
|
+
* @packageDocumentation
|
|
7
|
+
*/
|
|
8
|
+
export type { ControlEngineAdapter, ControlEvaluationContext } from './adapter';
|
|
9
|
+
export { ControlEngineRegistry } from './adapter';
|
|
10
|
+
export type { ControlBlock, ControlStep, ControlDecision, ControlValidationResult, ControlPurpose, ControlLicensingMode, } from './types';
|
|
11
|
+
export type { ConstraintType, TemporalConstraint, UsageConstraint, BudgetConstraint, CombinedConstraint, Constraint, ConstraintEnforcementResult, } from './constraints';
|
|
12
|
+
export type { MandateType, TemporalMandate, UsageMandate, BudgetMandate, CombinedMandate, Mandate, EnforcementResult, ControlState, } from './types';
|
|
13
|
+
export { TemporalConstraintSchema, UsageConstraintSchema, BudgetConstraintSchema, CombinedConstraintSchema, ConstraintSchema, ControlBlockSchema, ControlStateSchema, ControlPurposeSchema, ControlLicensingModeSchema, ControlDecisionSchema, ControlStepSchema, ChainControlBlockSchema, } from './validators';
|
|
14
|
+
export { TemporalConstraintSchema as TemporalMandateSchema, UsageConstraintSchema as UsageMandateSchema, BudgetConstraintSchema as BudgetMandateSchema, CombinedConstraintSchema as CombinedMandateSchema, ConstraintSchema as MandateSchema, } from './validators';
|
|
15
|
+
export { enforceTemporalConstraint, enforceUsageConstraint, enforceBudgetConstraint, enforceCombinedConstraint, enforceConstraint, enforceControlBlock, } from './enforcement';
|
|
16
|
+
export { enforceTemporalConstraint as enforceTemporalMandate, enforceUsageConstraint as enforceUsageMandate, enforceBudgetConstraint as enforceBudgetMandate, enforceCombinedConstraint as enforceCombinedMandate, enforceConstraint as enforceMandate, } from './enforcement';
|
|
17
|
+
export { createControlState, updateStateAfterUse, isStateExpired, resetState, getStateSummary, } from './state';
|
|
18
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;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