@vess-id/ai-identity 0.0.0-dev-20260902121045

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.
Files changed (173) hide show
  1. package/README.md +265 -0
  2. package/dist/agent/agent-did-manager.d.ts +97 -0
  3. package/dist/agent/agent-did-manager.d.ts.map +1 -0
  4. package/dist/auth/auth-provider.d.ts +51 -0
  5. package/dist/auth/auth-provider.d.ts.map +1 -0
  6. package/dist/auth/index.d.ts +2 -0
  7. package/dist/auth/index.d.ts.map +1 -0
  8. package/dist/client.d.ts +63 -0
  9. package/dist/client.d.ts.map +1 -0
  10. package/dist/config/index.d.ts +84 -0
  11. package/dist/config/index.d.ts.map +1 -0
  12. package/dist/constraint/constraint-evaluator.d.ts +103 -0
  13. package/dist/constraint/constraint-evaluator.d.ts.map +1 -0
  14. package/dist/constraint/index.d.ts +5 -0
  15. package/dist/constraint/index.d.ts.map +1 -0
  16. package/dist/did/agent.d.ts +58 -0
  17. package/dist/did/agent.d.ts.map +1 -0
  18. package/dist/did/did-utils.d.ts +82 -0
  19. package/dist/did/did-utils.d.ts.map +1 -0
  20. package/dist/did/key-manager.d.ts +19 -0
  21. package/dist/did/key-manager.d.ts.map +1 -0
  22. package/dist/gateway/gateway-client.d.ts +103 -0
  23. package/dist/gateway/gateway-client.d.ts.map +1 -0
  24. package/dist/gateway/index.d.ts +2 -0
  25. package/dist/gateway/index.d.ts.map +1 -0
  26. package/dist/grant/grant-manager.d.ts +140 -0
  27. package/dist/grant/grant-manager.d.ts.map +1 -0
  28. package/dist/grant/index.d.ts +2 -0
  29. package/dist/grant/index.d.ts.map +1 -0
  30. package/dist/identity/device-enroll-manager.d.ts +117 -0
  31. package/dist/identity/device-enroll-manager.d.ts.map +1 -0
  32. package/dist/identity/user-identity-manager.d.ts +123 -0
  33. package/dist/identity/user-identity-manager.d.ts.map +1 -0
  34. package/dist/identity/user-key-pair-manager.d.ts +22 -0
  35. package/dist/identity/user-key-pair-manager.d.ts.map +1 -0
  36. package/dist/index.d.mts +42685 -0
  37. package/dist/index.d.ts +57 -0
  38. package/dist/index.d.ts.map +1 -0
  39. package/dist/index.js +19534 -0
  40. package/dist/index.js.map +1 -0
  41. package/dist/index.mjs +19347 -0
  42. package/dist/index.mjs.map +1 -0
  43. package/dist/internal-signature/canonical.d.ts +80 -0
  44. package/dist/internal-signature/canonical.d.ts.map +1 -0
  45. package/dist/internal-signature/index.d.ts +17 -0
  46. package/dist/internal-signature/index.d.ts.map +1 -0
  47. package/dist/internal-signature/signer.d.ts +76 -0
  48. package/dist/internal-signature/signer.d.ts.map +1 -0
  49. package/dist/policy/cedar-engine.d.ts +334 -0
  50. package/dist/policy/cedar-engine.d.ts.map +1 -0
  51. package/dist/policy/cedar-entities.d.ts +59 -0
  52. package/dist/policy/cedar-entities.d.ts.map +1 -0
  53. package/dist/policy/decision.d.ts +46 -0
  54. package/dist/policy/decision.d.ts.map +1 -0
  55. package/dist/policy/index.d.ts +15 -0
  56. package/dist/policy/index.d.ts.map +1 -0
  57. package/dist/registry/access-orchestrator.d.ts +184 -0
  58. package/dist/registry/access-orchestrator.d.ts.map +1 -0
  59. package/dist/registry/action-aliases.d.ts +37 -0
  60. package/dist/registry/action-aliases.d.ts.map +1 -0
  61. package/dist/registry/action-input-validator.d.ts +19 -0
  62. package/dist/registry/action-input-validator.d.ts.map +1 -0
  63. package/dist/registry/action-normalizer.d.ts +47 -0
  64. package/dist/registry/action-normalizer.d.ts.map +1 -0
  65. package/dist/registry/action-registry-json.d.ts +35897 -0
  66. package/dist/registry/action-registry-json.d.ts.map +1 -0
  67. package/dist/registry/action-registry.d.ts +101 -0
  68. package/dist/registry/action-registry.d.ts.map +1 -0
  69. package/dist/registry/action-risk.d.ts +109 -0
  70. package/dist/registry/action-risk.d.ts.map +1 -0
  71. package/dist/registry/action-summary.d.ts +16 -0
  72. package/dist/registry/action-summary.d.ts.map +1 -0
  73. package/dist/registry/index.d.ts +14 -0
  74. package/dist/registry/index.d.ts.map +1 -0
  75. package/dist/registry/providers.d.ts +32 -0
  76. package/dist/registry/providers.d.ts.map +1 -0
  77. package/dist/registry/reauth-constants.d.ts +56 -0
  78. package/dist/registry/reauth-constants.d.ts.map +1 -0
  79. package/dist/registry/resource-type-labels.d.ts +15 -0
  80. package/dist/registry/resource-type-labels.d.ts.map +1 -0
  81. package/dist/registry/resource-types.d.ts +47 -0
  82. package/dist/registry/resource-types.d.ts.map +1 -0
  83. package/dist/resolver/approval-time-resolution.d.ts +72 -0
  84. package/dist/resolver/approval-time-resolution.d.ts.map +1 -0
  85. package/dist/resolver/canonical-resource-id.d.ts +37 -0
  86. package/dist/resolver/canonical-resource-id.d.ts.map +1 -0
  87. package/dist/resolver/compare-resource-id.d.ts +37 -0
  88. package/dist/resolver/compare-resource-id.d.ts.map +1 -0
  89. package/dist/resolver/salient-digest.d.ts +48 -0
  90. package/dist/resolver/salient-digest.d.ts.map +1 -0
  91. package/dist/resolver/target-resolver.d.ts +28 -0
  92. package/dist/resolver/target-resolver.d.ts.map +1 -0
  93. package/dist/state/index.d.ts +3 -0
  94. package/dist/state/index.d.ts.map +1 -0
  95. package/dist/state/json-state-store.d.ts +24 -0
  96. package/dist/state/json-state-store.d.ts.map +1 -0
  97. package/dist/state/state-store.interface.d.ts +37 -0
  98. package/dist/state/state-store.interface.d.ts.map +1 -0
  99. package/dist/storage/filesystem-key-storage.d.ts +16 -0
  100. package/dist/storage/filesystem-key-storage.d.ts.map +1 -0
  101. package/dist/storage/index.d.ts +4 -0
  102. package/dist/storage/index.d.ts.map +1 -0
  103. package/dist/storage/key-storage.interface.d.ts +42 -0
  104. package/dist/storage/key-storage.interface.d.ts.map +1 -0
  105. package/dist/storage/memory-key-storage.d.ts +17 -0
  106. package/dist/storage/memory-key-storage.d.ts.map +1 -0
  107. package/dist/tool/tool-manager.d.ts +44 -0
  108. package/dist/tool/tool-manager.d.ts.map +1 -0
  109. package/dist/types/agent.d.ts +139 -0
  110. package/dist/types/agent.d.ts.map +1 -0
  111. package/dist/types/audit.d.ts +23 -0
  112. package/dist/types/audit.d.ts.map +1 -0
  113. package/dist/types/cedar-policy.d.ts +60 -0
  114. package/dist/types/cedar-policy.d.ts.map +1 -0
  115. package/dist/types/connector-plugin.d.ts +252 -0
  116. package/dist/types/connector-plugin.d.ts.map +1 -0
  117. package/dist/types/connectors.d.ts +39 -0
  118. package/dist/types/connectors.d.ts.map +1 -0
  119. package/dist/types/context.d.ts +152 -0
  120. package/dist/types/context.d.ts.map +1 -0
  121. package/dist/types/did.d.ts +18 -0
  122. package/dist/types/did.d.ts.map +1 -0
  123. package/dist/types/errors.d.ts +24 -0
  124. package/dist/types/errors.d.ts.map +1 -0
  125. package/dist/types/grant.d.ts +522 -0
  126. package/dist/types/grant.d.ts.map +1 -0
  127. package/dist/types/index.d.ts +22 -0
  128. package/dist/types/index.d.ts.map +1 -0
  129. package/dist/types/intent.d.ts +133 -0
  130. package/dist/types/intent.d.ts.map +1 -0
  131. package/dist/types/invitation.d.ts +97 -0
  132. package/dist/types/invitation.d.ts.map +1 -0
  133. package/dist/types/jira.d.ts +348 -0
  134. package/dist/types/jira.d.ts.map +1 -0
  135. package/dist/types/oauth.d.ts +72 -0
  136. package/dist/types/oauth.d.ts.map +1 -0
  137. package/dist/types/organization.d.ts +77 -0
  138. package/dist/types/organization.d.ts.map +1 -0
  139. package/dist/types/permission-mode.d.ts +138 -0
  140. package/dist/types/permission-mode.d.ts.map +1 -0
  141. package/dist/types/permission-vc.d.ts +800 -0
  142. package/dist/types/permission-vc.d.ts.map +1 -0
  143. package/dist/types/receipt.d.ts +133 -0
  144. package/dist/types/receipt.d.ts.map +1 -0
  145. package/dist/types/target-binding.d.ts +163 -0
  146. package/dist/types/target-binding.d.ts.map +1 -0
  147. package/dist/types/tier.d.ts +13 -0
  148. package/dist/types/tier.d.ts.map +1 -0
  149. package/dist/types/vc.d.ts +213 -0
  150. package/dist/types/vc.d.ts.map +1 -0
  151. package/dist/types/vp.d.ts +25 -0
  152. package/dist/types/vp.d.ts.map +1 -0
  153. package/dist/utils/action-classifier.d.ts +13 -0
  154. package/dist/utils/action-classifier.d.ts.map +1 -0
  155. package/dist/utils/crypto.d.ts +22 -0
  156. package/dist/utils/crypto.d.ts.map +1 -0
  157. package/dist/utils/freemail-domains.d.ts +13 -0
  158. package/dist/utils/freemail-domains.d.ts.map +1 -0
  159. package/dist/utils/sdjwt-client.d.ts +415 -0
  160. package/dist/utils/sdjwt-client.d.ts.map +1 -0
  161. package/dist/utils/sdjwt-disclosure.d.ts +13 -0
  162. package/dist/utils/sdjwt-disclosure.d.ts.map +1 -0
  163. package/dist/utils/tier-utils.d.ts +15 -0
  164. package/dist/utils/tier-utils.d.ts.map +1 -0
  165. package/dist/vc/api-vc-manager.d.ts +43 -0
  166. package/dist/vc/api-vc-manager.d.ts.map +1 -0
  167. package/dist/vc/vc-manager.d.ts +55 -0
  168. package/dist/vc/vc-manager.d.ts.map +1 -0
  169. package/dist/vp/kb-jwt-builder.d.ts +89 -0
  170. package/dist/vp/kb-jwt-builder.d.ts.map +1 -0
  171. package/dist/vp/vp-manager.d.ts +75 -0
  172. package/dist/vp/vp-manager.d.ts.map +1 -0
  173. package/package.json +66 -0
@@ -0,0 +1,80 @@
1
+ /**
2
+ * P1-A14a-1 / Threat Model S4 — canonical-string + signature-header
3
+ * helpers for HMAC body signing of internal HTTP requests.
4
+ *
5
+ * Pure module: no NestJS, no I/O, no side effects. SDK is the
6
+ * single source of truth (P1-A14a-2d) — api / remote-mcp /
7
+ * slack-bot all import from `@vess-id/ai-identity`.
8
+ *
9
+ * Header format (Q1 = A, Stripe-style versioned):
10
+ * X-Internal-Signature: v1=<keyId>:<unixSeconds>:<base64(hmac)>
11
+ *
12
+ * Canonical string (Q2 = A, no header inclusion):
13
+ * ${METHOD.toUpperCase()}\n${path}\n${unixSeconds}\n${sha256Hex(rawBody)}
14
+ *
15
+ * Replay window (Q3 = A): 300 seconds — enforced by the api guard,
16
+ * not here. This module is responsible for *constructing* the
17
+ * canonical string and *parsing* the header; freshness is policy.
18
+ */
19
+ export declare const SIGNATURE_HEADER = "x-internal-signature";
20
+ export declare const SIGNATURE_VERSION_PREFIX = "v1=";
21
+ /**
22
+ * SHA-256 hex digest of an arbitrary buffer or string. Hex (not
23
+ * base64) so the canonical string is URL-safe and grep-friendly in
24
+ * logs if a future debug session ever needs to reconstruct it
25
+ * server-side.
26
+ */
27
+ export declare function sha256Hex(input: Buffer | string): string;
28
+ /**
29
+ * Build the canonical string that gets HMAC'd. The components are
30
+ * separated by `\n` because no legitimate input contains `\n` (the
31
+ * method is uppercase ASCII, the path is URL-encoded by the caller,
32
+ * the timestamp is digits, the body hash is hex). Using `\n` as
33
+ * separator avoids ambiguity that delimiters like `:` would
34
+ * introduce when the path contains a colon.
35
+ *
36
+ * Whitespace is NOT trimmed — input must be exactly what will land
37
+ * on the wire. Caller controls case and encoding.
38
+ */
39
+ export declare function buildCanonicalString(args: {
40
+ method: string;
41
+ path: string;
42
+ unixSeconds: number;
43
+ rawBody: Buffer | string;
44
+ }): string;
45
+ /** Shape of a parsed `X-Internal-Signature` header. */
46
+ export interface ParsedSignature {
47
+ /** Identifier of the signing key (e.g. `'mcp-v2'`). */
48
+ keyId: string;
49
+ /** Unix epoch seconds at signing time. */
50
+ unixSeconds: number;
51
+ /** Base64-encoded HMAC-SHA256 digest. */
52
+ signature: string;
53
+ }
54
+ /**
55
+ * Parse a `X-Internal-Signature` header value. Returns `null` for
56
+ * any malformed shape rather than throwing — the api guard converts
57
+ * `null` to a `401 Unauthorized` so a malformed header never
58
+ * triggers a `500`.
59
+ *
60
+ * Accepted: `v1=<keyId>:<digits>:<base64>`
61
+ *
62
+ * Defensive checks:
63
+ * - Must start with `v1=` (Q1: explicit version prefix)
64
+ * - keyId / signature must be non-empty after split
65
+ * - timestamp must parse to a finite, non-negative integer
66
+ * - keyId must be ASCII identifier-safe ([A-Za-z0-9_-]+) so a
67
+ * malicious header cannot smuggle control chars or whitespace
68
+ * into log lines / metric labels
69
+ * - signature must be valid base64 (only base64 alphabet chars)
70
+ */
71
+ export declare function parseSignatureHeader(headerValue: string | undefined): ParsedSignature | null;
72
+ /**
73
+ * Format a ParsedSignature back into a header string. Round-trips
74
+ * with `parseSignatureHeader` for any validly-shaped input.
75
+ *
76
+ * Used by the signing side (HTTP client). Keeping it next to the
77
+ * parser pins the format in one place.
78
+ */
79
+ export declare function formatSignatureHeader(parsed: ParsedSignature): string;
80
+ //# sourceMappingURL=canonical.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"canonical.d.ts","sourceRoot":"","sources":["../../src/internal-signature/canonical.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;GAiBG;AAEH,eAAO,MAAM,gBAAgB,yBAAyB,CAAA;AACtD,eAAO,MAAM,wBAAwB,QAAQ,CAAA;AAE7C;;;;;GAKG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAExD;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE;IACzC,MAAM,EAAE,MAAM,CAAA;IACd,IAAI,EAAE,MAAM,CAAA;IACZ,WAAW,EAAE,MAAM,CAAA;IACnB,OAAO,EAAE,MAAM,GAAG,MAAM,CAAA;CACzB,GAAG,MAAM,CAGT;AAED,uDAAuD;AACvD,MAAM,WAAW,eAAe;IAC9B,uDAAuD;IACvD,KAAK,EAAE,MAAM,CAAA;IACb,0CAA0C;IAC1C,WAAW,EAAE,MAAM,CAAA;IACnB,yCAAyC;IACzC,SAAS,EAAE,MAAM,CAAA;CAClB;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,oBAAoB,CAAC,WAAW,EAAE,MAAM,GAAG,SAAS,GAAG,eAAe,GAAG,IAAI,CA4B5F;AAED;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,eAAe,GAAG,MAAM,CAErE"}
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Public API of `@vess-id/ai-identity/internal-signature` (P1-A14a-2d).
3
+ *
4
+ * Re-exported via the SDK barrel (`packages/sdk/src/index.ts`) so
5
+ * consumers can write:
6
+ *
7
+ * import { signRequest, SIGNATURE_HEADER } from '@vess-id/ai-identity'
8
+ *
9
+ * SDK is the single source of truth — api / remote-mcp / slack-bot
10
+ * all import from here. The api side keeps verifier-only types
11
+ * (`HmacKeyset`, `InternalSignatureGuard`) in
12
+ * `packages/api/src/common/internal-signature/` so the SDK avoids
13
+ * a NestJS dependency.
14
+ */
15
+ export { buildCanonicalString, formatSignatureHeader, parseSignatureHeader, sha256Hex, SIGNATURE_HEADER, SIGNATURE_VERSION_PREFIX, type ParsedSignature, } from './canonical';
16
+ export { signRequest, MIN_SIGNER_KEY_BYTES, type InternalHmacSignerKey, type SignRequestArgs, } from './signer';
17
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/internal-signature/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EACL,oBAAoB,EACpB,qBAAqB,EACrB,oBAAoB,EACpB,SAAS,EACT,gBAAgB,EAChB,wBAAwB,EACxB,KAAK,eAAe,GACrB,MAAM,aAAa,CAAA;AAEpB,OAAO,EACL,WAAW,EACX,oBAAoB,EACpB,KAAK,qBAAqB,EAC1B,KAAK,eAAe,GACrB,MAAM,UAAU,CAAA"}
@@ -0,0 +1,76 @@
1
+ /**
2
+ * P1-A14a-2d — pure HMAC signer for outbound /api/internal/**
3
+ * requests. Lives in SDK so remote-mcp and slack-bot (both of which
4
+ * already depend on `@vess-id/ai-identity`) can attach
5
+ * `X-Internal-Signature` to every request without dragging the
6
+ * api package into their dependency graph.
7
+ *
8
+ * Pure (no I/O, no Nest). Mirrors the `utils/crypto.ts` profile:
9
+ * the only Node-builtin used is `crypto.createHmac`.
10
+ *
11
+ * Pairing with the verifier
12
+ * -------------------------
13
+ * The verifier (api side, `HmacKeyset.verify` →
14
+ * `buildCanonicalString` → constant-time compare) reads the same
15
+ * `buildCanonicalString` from this module by construction. As long
16
+ * as both sides pass the same `(method, path, unixSeconds, rawBody)`
17
+ * the HMACs match by definition.
18
+ *
19
+ * Body bytes
20
+ * ----------
21
+ * The caller MUST pass the exact bytes that go on the wire as
22
+ * `rawBody`. Re-running `JSON.stringify(...)` on each side would
23
+ * risk a byte mismatch (object key order is implementation-defined
24
+ * in spec, even though V8 preserves insertion order in practice).
25
+ * The api-client `makeRequest` helper computes `JSON.stringify`
26
+ * once, hands the same string to both `signRequest` and `fetch`.
27
+ */
28
+ /**
29
+ * Minimum signer key length in raw bytes. 32 bytes = 256 bits
30
+ * matches HMAC-SHA256's natural block size and the verifier's
31
+ * `MIN_KEY_BYTES`. A truncated env var (accidental newline,
32
+ * copy-paste error) is the realistic failure mode this guards
33
+ * against.
34
+ */
35
+ export declare const MIN_SIGNER_KEY_BYTES = 32;
36
+ export interface InternalHmacSignerKey {
37
+ /** Stable identifier for the key, e.g. `'mcp-v1'`. Embedded in
38
+ * the X-Internal-Signature header so the verifier can pick the
39
+ * right key. Must match `/^[A-Za-z0-9_-]+$/`. */
40
+ keyId: string;
41
+ /** Raw HMAC secret. >= MIN_SIGNER_KEY_BYTES bytes. */
42
+ secret: Buffer;
43
+ }
44
+ export interface SignRequestArgs {
45
+ /** HTTP method. Will be upper-cased by `buildCanonicalString`,
46
+ * but callers should pass the uppercase form they use on the
47
+ * wire so signer and `fetch()` stay in lockstep. */
48
+ method: string;
49
+ /** URL path with query string already stripped (verifier does
50
+ * `request.originalUrl?.split('?')[0]`; signer must mirror).
51
+ * Path encoding (e.g. `%2F` vs `/`) is caller's responsibility
52
+ * — the canonical string treats them as different bytes. */
53
+ path: string;
54
+ /** Wire bytes. The same string/buffer passed to `fetch({body})`
55
+ * must be passed here — `JSON.stringify` runs ONCE per request
56
+ * in the caller. */
57
+ rawBody: Buffer | string;
58
+ /** Optional fixed timestamp for testing. Defaults to
59
+ * `Math.floor(Date.now() / 1000)`. */
60
+ unixSeconds?: number;
61
+ }
62
+ /**
63
+ * Sign an outbound request and return a fully-formatted
64
+ * `X-Internal-Signature` header value. The caller sets the header
65
+ * on the outbound request directly:
66
+ *
67
+ * ```ts
68
+ * headers[SIGNATURE_HEADER] = signRequest(key, { method, path, rawBody })
69
+ * ```
70
+ *
71
+ * Throws if key material is invalid (bad keyId or short secret) —
72
+ * surfacing misconfiguration loudly at request time rather than
73
+ * silently producing a header the verifier will reject.
74
+ */
75
+ export declare function signRequest(key: InternalHmacSignerKey, args: SignRequestArgs): string;
76
+ //# sourceMappingURL=signer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"signer.d.ts","sourceRoot":"","sources":["../../src/internal-signature/signer.ts"],"names":[],"mappings":"AAOA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAEH;;;;;;GAMG;AACH,eAAO,MAAM,oBAAoB,KAAK,CAAA;AAEtC,MAAM,WAAW,qBAAqB;IACpC;;sDAEkD;IAClD,KAAK,EAAE,MAAM,CAAA;IACb,sDAAsD;IACtD,MAAM,EAAE,MAAM,CAAA;CACf;AAED,MAAM,WAAW,eAAe;IAC9B;;yDAEqD;IACrD,MAAM,EAAE,MAAM,CAAA;IACd;;;iEAG6D;IAC7D,IAAI,EAAE,MAAM,CAAA;IACZ;;yBAEqB;IACrB,OAAO,EAAE,MAAM,GAAG,MAAM,CAAA;IACxB;2CACuC;IACvC,WAAW,CAAC,EAAE,MAAM,CAAA;CACrB;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,qBAAqB,EAAE,IAAI,EAAE,eAAe,GAAG,MAAM,CAgBrF"}
@@ -0,0 +1,334 @@
1
+ /**
2
+ * CedarEngine — minimal wrapper around `@cedar-policy/cedar-wasm/nodejs`.
3
+ *
4
+ * Phase 1 Step 1 scope (server-side / Node-runtime only):
5
+ * - preparseSchema : ingest Cedar schema text → opaque SchemaHandle
6
+ * - preparsePolicySet: ingest Cedar PolicySet text → opaque PolicySetHandle
7
+ * - evaluate : run statefulIsAuthorized against preparsed handles
8
+ *
9
+ * Browser callers receive `CedarEngineUnavailableError` because the
10
+ * `/nodejs` subpath depends on Node `fs` to instantiate the wasm.
11
+ *
12
+ * Performance notes (companion design spec Appendix C, PoC 2026-05-23):
13
+ * - statefulIsAuthorized + preparsed cache: p50 0.067ms / p99 0.076ms
14
+ * (~9x faster than re-parsing every call). The wasm caches preparsed
15
+ * handles internally keyed by string name/id, so the opaque handles
16
+ * we expose are thin wrappers around an auto-generated id.
17
+ *
18
+ * Concurrency / TOCTOU (Cedar design spec rev 5/6, fix C3):
19
+ * - `createCedarEngine()` caches the in-flight Promise (not the resolved
20
+ * engine). Two parallel callers therefore share the same load — no
21
+ * duplicated dynamic import of the 4.1 MB wasm.
22
+ * - On load failure the cached promise is cleared so the next caller can
23
+ * retry. This avoids permanently poisoning the module after a transient
24
+ * failure (e.g. wasm streaming compile blip).
25
+ *
26
+ * Design ref: docs/specs/2026-05-23-cedar-rar-permission-redesign.md
27
+ * Plan ref: docs/specs/2026-05-23-cedar-rar-implementation-plan-phase1.md
28
+ */
29
+ /**
30
+ * Decision domain exposed by the wrapper. Cedar's wasm uses lowercase
31
+ * `'allow' | 'deny'`; we normalize to the spec's casing so callers can
32
+ * pattern-match on a single canonical form across the codebase.
33
+ */
34
+ export type CedarDecision = 'Allow' | 'Deny';
35
+ /**
36
+ * Structured error returned for evaluation-time problems (policy execution
37
+ * errors). Parse / schema errors are surfaced at preparse time as thrown
38
+ * `CedarParseError`s instead.
39
+ */
40
+ export interface CedarError {
41
+ /** Policy id that errored, if attributable. */
42
+ policyId?: string;
43
+ /** Human-readable message from Cedar. */
44
+ message: string;
45
+ /** Optional structured diagnostic code from Cedar. */
46
+ code?: string;
47
+ }
48
+ /**
49
+ * Phase 2-1-H — structured policy validation error surfaced by
50
+ * `CedarParseError.validationErrors` (and re-exported as a public type
51
+ * so API / UI callers don't have to re-implement source-location math).
52
+ *
53
+ * One `PolicyValidationError` entry corresponds to one cedar-wasm
54
+ * diagnostic (top-level `errors[]` entries + their `related[]`
55
+ * descendants are flattened into a single list, since callers always
56
+ * want to render every diagnostic — the related chain is metadata about
57
+ * the top-level failure, not a separate parse).
58
+ *
59
+ * Fields:
60
+ * - `code` — machine-readable classification, snake_case. Phase 1
61
+ * surface: `'parse_error'` (default). Future cedar-wasm releases
62
+ * ship structured codes; the classifier here uses message-pattern
63
+ * heuristics until then (see `classifyCedarErrorMessage`).
64
+ * - `message` — cedar-wasm's human-readable English. UI is
65
+ * responsible for i18n / templating; we don't translate here.
66
+ * - `line` / `column` — 1-based caret. Computed from the byte
67
+ * `start` offset in cedar-wasm's `sourceLocations[]` against the
68
+ * ORIGINAL policy text, so the caret matches what the user sees
69
+ * in the textarea / editor.
70
+ * - `context` — the offending byte slice (max 200 chars, truncated
71
+ * with an ellipsis). Lets UIs render an inline highlight without
72
+ * a second round trip.
73
+ * - `offset` — 0-based byte offset (for editors that prefer offsets
74
+ * to line/column; line/column is provided as a convenience).
75
+ */
76
+ export interface PolicyValidationError {
77
+ /**
78
+ * Machine-readable code, snake_case. Currently a small set:
79
+ * - `'parse_error'` — syntax / grammar failure (default)
80
+ * - `'unexpected_end_of_input'` — incomplete policy
81
+ * - `'unexpected_token'` — token didn't match expected production
82
+ * - `'unknown_extension'` — referenced an unknown extension fn
83
+ * - `'unknown'` — fallback when no heuristic matches
84
+ * Callers that switch on this string MUST default to a generic
85
+ * branch — the set will grow as cedar-wasm exposes structured codes.
86
+ */
87
+ code: string;
88
+ /** Cedar's human-readable English diagnostic. */
89
+ message: string;
90
+ /** 1-based line in the original policy text where the error starts. */
91
+ line?: number;
92
+ /** 1-based column in the line (counts UTF-16 code units, matching JS String). */
93
+ column?: number;
94
+ /**
95
+ * The raw policy slice that triggered the error, truncated to 200
96
+ * chars with a trailing ellipsis when longer. Useful for UIs to
97
+ * highlight the offending span without re-computing offsets.
98
+ */
99
+ context?: string;
100
+ /** 0-based byte offset into the policy text (when known). */
101
+ offset?: number;
102
+ }
103
+ /**
104
+ * Opaque handle to a Cedar schema that has been parsed and cached
105
+ * inside the wasm. Returned by `preparseSchema`; pass to `evaluate`.
106
+ *
107
+ * The wasm caches by string name, so the handle carries the auto-generated
108
+ * id. Callers must treat the type as opaque.
109
+ */
110
+ export interface SchemaHandle {
111
+ readonly __cedar: 'schema';
112
+ readonly name: string;
113
+ }
114
+ /** Opaque handle to a Cedar PolicySet. Returned by `preparsePolicySet`. */
115
+ export interface PolicySetHandle {
116
+ readonly __cedar: 'policySet';
117
+ readonly id: string;
118
+ }
119
+ /**
120
+ * A Cedar entity in the JSON shape expected by the wasm.
121
+ *
122
+ * We keep this as `Record<string, unknown>` rather than importing the
123
+ * detailed `EntityJson` type from `@cedar-policy/cedar-wasm` because the
124
+ * SDK is consumed by browser bundlers; pulling in the d.ts would force
125
+ * the wasm typings into browser builds (the runtime is still lazy-loaded).
126
+ * Callers cast as needed; runtime validation is delegated to the wasm.
127
+ */
128
+ export type CedarEntity = Record<string, unknown>;
129
+ export interface CedarEvaluateRequest {
130
+ /** Cedar entity-uid expression, e.g. `Agent::"agent-1"`. */
131
+ principal: string;
132
+ /** Cedar entity-uid expression, e.g. `Action::"gmail.message.send"`. */
133
+ action: string;
134
+ /** Cedar entity-uid expression, e.g. `GmailThread::"thread-1"`. */
135
+ resource: string;
136
+ /** Free-form context dict (must match the schema's context shape). */
137
+ context: Record<string, unknown>;
138
+ }
139
+ export interface EvaluateInput {
140
+ policySetHandle: PolicySetHandle;
141
+ schemaHandle?: SchemaHandle;
142
+ entities: ReadonlyArray<CedarEntity>;
143
+ request: CedarEvaluateRequest;
144
+ }
145
+ export interface EvaluateResult {
146
+ decision: CedarDecision;
147
+ /** Policy ids that determined the decision (Cedar's `diagnostics.reason`). */
148
+ reasons: string[];
149
+ /** Evaluation-time errors, if any. Empty array on success. */
150
+ errors: CedarError[];
151
+ }
152
+ export interface CedarEngine {
153
+ preparseSchema(schemaText: string): SchemaHandle;
154
+ preparsePolicySet(cedarText: string): PolicySetHandle;
155
+ evaluate(input: EvaluateInput): EvaluateResult;
156
+ }
157
+ /**
158
+ * Thrown when the Cedar wasm module cannot be loaded — typically because
159
+ * the wrapper is running in a browser (the `/nodejs` subpath requires Node
160
+ * `fs`), but also raised for any unexpected load-time failure.
161
+ */
162
+ export declare class CedarEngineUnavailableError extends Error {
163
+ readonly name = "CedarEngineUnavailableError";
164
+ constructor(cause: unknown);
165
+ }
166
+ /**
167
+ * Thrown by `preparseSchema` / `preparsePolicySet` when Cedar reports a
168
+ * structured `{ type: 'failure', errors: [...] }` answer. Callers (e.g.
169
+ * the Policy Registry lint) can inspect `errors` for diagnostics.
170
+ *
171
+ * Phase 2-1-H — `validationErrors` is a parallel, richer view of the
172
+ * same failures with line / column / context derived against the
173
+ * original policy text. The legacy `errors` field is preserved as-is
174
+ * so call sites that only need the message text don't need to change.
175
+ */
176
+ export declare class CedarParseError extends Error {
177
+ readonly name = "CedarParseError";
178
+ readonly errors: CedarError[];
179
+ /**
180
+ * Structured diagnostics with `{ code, message, line, column, context,
181
+ * offset }`. Always non-empty when the throw is from cedar-wasm; may
182
+ * be empty when constructed from a non-cedar-wasm path (e.g. when an
183
+ * upstream caller wraps an unexpected throw).
184
+ */
185
+ readonly validationErrors: PolicyValidationError[];
186
+ constructor(message: string, errors: CedarError[], validationErrors?: PolicyValidationError[]);
187
+ }
188
+ /**
189
+ * Minimal subset of the cedar-wasm module surface we depend on. We type only
190
+ * the shape we use so the SDK's d.ts doesn't accidentally pull in the full
191
+ * upstream typings (which would broaden the public type-surface).
192
+ */
193
+ interface CedarWasmModule {
194
+ preparseSchema(name: string, schema: string): CedarCheckParseAnswer;
195
+ preparsePolicySet(psetId: string, policies: {
196
+ staticPolicies: string;
197
+ }): CedarCheckParseAnswer;
198
+ statefulIsAuthorized(call: CedarStatefulCall): CedarAuthorizationAnswer;
199
+ }
200
+ interface CedarStatefulCall {
201
+ principal: {
202
+ type: string;
203
+ id: string;
204
+ };
205
+ action: {
206
+ type: string;
207
+ id: string;
208
+ };
209
+ resource: {
210
+ type: string;
211
+ id: string;
212
+ };
213
+ context: Record<string, unknown>;
214
+ preparsedSchemaName?: string;
215
+ preparsedPolicySetId: string;
216
+ validateRequest?: boolean;
217
+ entities: ReadonlyArray<CedarEntity>;
218
+ }
219
+ type CedarCheckParseAnswer = {
220
+ type: 'success';
221
+ } | {
222
+ type: 'failure';
223
+ errors: CedarDetailedError[];
224
+ };
225
+ type CedarAuthorizationAnswer = {
226
+ type: 'success';
227
+ response: {
228
+ decision: 'allow' | 'deny';
229
+ diagnostics: {
230
+ reason: string[];
231
+ errors: CedarAuthorizationError[];
232
+ };
233
+ };
234
+ warnings: CedarDetailedError[];
235
+ } | {
236
+ type: 'failure';
237
+ errors: CedarDetailedError[];
238
+ warnings: CedarDetailedError[];
239
+ };
240
+ interface CedarDetailedError {
241
+ message: string;
242
+ code?: string | null;
243
+ /**
244
+ * Source spans reported by cedar-wasm's miette-backed diagnostic
245
+ * pipeline. `start` / `end` are 0-based byte offsets into the policy
246
+ * text. `label` is a short hint about what was expected. We type only
247
+ * the subset we use; cedar-wasm may include additional fields.
248
+ */
249
+ sourceLocations?: ReadonlyArray<{
250
+ start?: number;
251
+ end?: number;
252
+ label?: string | null;
253
+ }> | null;
254
+ /** Cascaded diagnostics — same shape as the top-level error. */
255
+ related?: ReadonlyArray<CedarDetailedError> | null;
256
+ }
257
+ interface CedarAuthorizationError {
258
+ policyId: string;
259
+ error: CedarDetailedError;
260
+ }
261
+ type CedarLoader = () => Promise<CedarWasmModule>;
262
+ /**
263
+ * Create (or reuse) the singleton Cedar engine.
264
+ *
265
+ * - First call performs the dynamic import of cedar-wasm.
266
+ * - Subsequent calls return the cached Promise — TOCTOU-safe.
267
+ * - If the in-flight load rejects, the cache is cleared so retries work.
268
+ */
269
+ export declare function createCedarEngine(): Promise<CedarEngine>;
270
+ /**
271
+ * Phase 2-1-H — flatten cedar-wasm's `{ message, sourceLocations[],
272
+ * related[] }` tree into a list of `PolicyValidationError` entries
273
+ * with line/column derived against the original policy text.
274
+ *
275
+ * `related[]` entries are walked recursively and emitted as siblings
276
+ * of the top-level error (cedar-wasm uses `related` for "and also..."
277
+ * style cascade diagnostics — UIs typically render all of them, not
278
+ * just the head).
279
+ *
280
+ * If cedar-wasm returns no `sourceLocations`, we still emit an entry
281
+ * (without line/column) so the caller always sees at least one error
282
+ * per failure path.
283
+ *
284
+ * @internal — Phase 2-1-H heuristic implementation. Exported for cross-package
285
+ * reuse (API + agentd / remote-mcp future surfaces) and unit tests, but NOT a
286
+ * stable public API. Will be replaced once cedar-wasm exposes structured
287
+ * diagnostic codes upstream (tracked as Phase 2-2-I). Semver of `@vess-id/ai-identity`
288
+ * may remove or rename this function without a major bump.
289
+ */
290
+ export declare function buildValidationErrors(errors: ReadonlyArray<CedarDetailedError>, sourceText: string): PolicyValidationError[];
291
+ /**
292
+ * Heuristic classifier mapping cedar-wasm's English message text to a
293
+ * stable snake_case code. cedar-wasm@4.11.0 does not yet expose a
294
+ * structured `code` field (the `code` slot in `CedarDetailedError` is
295
+ * always `null` for parse failures), so we match on substring patterns
296
+ * that have proven stable across recent releases.
297
+ *
298
+ * If `cedarCode` is supplied (future cedar-wasm release) it wins.
299
+ *
300
+ * Returned codes (must stay in sync with the JSDoc on
301
+ * `PolicyValidationError.code`):
302
+ * - `parse_error` — generic parse failure (fallback)
303
+ * - `unexpected_end_of_input` — incomplete policy
304
+ * - `unexpected_token` — token didn't match expected production
305
+ * - `unknown_extension` — referenced unknown extension fn
306
+ * - `unknown` — message didn't match any pattern
307
+ *
308
+ * @internal — Phase 2-1-H heuristic implementation, same caveat as
309
+ * `buildValidationErrors`. Will be replaced once cedar-wasm exposes structured
310
+ * diagnostic codes upstream (Phase 2-2-I).
311
+ */
312
+ export declare function classifyCedarErrorMessage(message: string, cedarCode?: string): string;
313
+ /** Drop the cached engine Promise. Production callers should never need this. */
314
+ export declare function __resetCedarEngineCache(): void;
315
+ /**
316
+ * Override the cedar-wasm loader used by `createCedarEngine`. Pass `null` to
317
+ * restore the default dynamic-import loader.
318
+ */
319
+ export declare function __setCedarLoaderForTests(loader: CedarLoader | null): void;
320
+ /**
321
+ * Test-only wrapper around the module-internal `parseEntityUid`. Lets the
322
+ * spec assert the entity-uid regex directly (e.g. that single-colon namespace
323
+ * forms are rejected) without contorting `evaluate` invocations.
324
+ *
325
+ * Production code MUST NOT call this — the leading underscores follow the
326
+ * `__resetCedarEngineCache` / `__setCedarLoaderForTests` convention used
327
+ * elsewhere in this module for test-only escape hatches.
328
+ */
329
+ export declare function __parseEntityUidForTests(uid: string): {
330
+ type: string;
331
+ id: string;
332
+ };
333
+ export {};
334
+ //# sourceMappingURL=cedar-engine.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cedar-engine.d.ts","sourceRoot":"","sources":["../../src/policy/cedar-engine.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAIH;;;;GAIG;AACH,MAAM,MAAM,aAAa,GAAG,OAAO,GAAG,MAAM,CAAA;AAE5C;;;;GAIG;AACH,MAAM,WAAW,UAAU;IACzB,+CAA+C;IAC/C,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,yCAAyC;IACzC,OAAO,EAAE,MAAM,CAAA;IACf,sDAAsD;IACtD,IAAI,CAAC,EAAE,MAAM,CAAA;CACd;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,MAAM,WAAW,qBAAqB;IACpC;;;;;;;;;OASG;IACH,IAAI,EAAE,MAAM,CAAA;IACZ,iDAAiD;IACjD,OAAO,EAAE,MAAM,CAAA;IACf,uEAAuE;IACvE,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,iFAAiF;IACjF,MAAM,CAAC,EAAE,MAAM,CAAA;IACf;;;;OAIG;IACH,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,6DAA6D;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AM,GACjB,qBAAqB,EAAE,CAgCzB;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,yBAAyB,CACvC,OAAO,EAAE,MAAM,EACf,SAAS,CAAC,EAAE,MAAM,GACjB,MAAM,CAQR;AAkFD,iFAAiF;AACjF,wBAAgB,uBAAuB,IAAI,IAAI,CAE9C;AAED;;;GAGG;AACH,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,WAAW,GAAG,IAAI,GAAG,IAAI,CAEzE;AAED;;;;;;;;GAQG;AACH,wBAAgB,wBAAwB,CAAC,GAAG,EAAE,MAAM,GAAG;IACrD,IAAI,EAAE,MAAM,CAAA;IACZ,EAAE,EAAE,MAAM,CAAA;CACX,CAEA"}
@@ -0,0 +1,59 @@
1
+ /**
2
+ * buildCedarEntities — Cedar entity-list builder (Cedar unification Step 1).
3
+ *
4
+ * Spec ref:
5
+ * - docs/specs/2026-05-24-cedar-unification-design.md §7.1
6
+ * Phase 1 採用方針: entity attribute と context の **二重 bind**。本 helper は
7
+ * entity 側のみを組み立て、`context.action.risk_level` は呼び出し側
8
+ * (`CedarDecisionService.buildCedarEvaluateRequest`) が context にも別途
9
+ * 注入する。これは Cedar 4.11.0 が schema-less な entity attribute 直参照を
10
+ * policy text 内では制限するため、policy 内では `context.action.risk_level`
11
+ * 経由を Phase 1 で採用するという rev 3 C1 で確定した設計判断による。
12
+ *
13
+ * Action entity の `attrs.risk_level` は本 helper の責務、
14
+ * `context.action.risk_level` は CedarDecisionService の責務。
15
+ * Phase 2+ で Cedar schema 導入時に context 側を撤去し entity 直参照に統一する。
16
+ */
17
+ import type { CedarEntity } from './cedar-engine';
18
+ /**
19
+ * Principal or resource descriptor accepted by {@link buildCedarEntities}.
20
+ * `type` is the Cedar entity-type name (e.g., `Agent`, `User`, `GmailThread`).
21
+ * `attrs` defaults to `{}` if omitted. `parents` is always `[]` in Phase 1
22
+ * (entity hierarchy is reserved for Phase 2 schema work).
23
+ */
24
+ export interface CedarEntityDescriptor {
25
+ type: string;
26
+ id: string;
27
+ attrs?: Record<string, unknown>;
28
+ }
29
+ /**
30
+ * Input contract for {@link buildCedarEntities}. `action` is the dotted
31
+ * action name (e.g., `'gmail.message.send'`); the helper looks up the
32
+ * Phase 1 risk level via {@link resolveActionRisk} and binds it as
33
+ * `Action::"<id>".attrs.risk_level`.
34
+ *
35
+ * Context (including `context.action.risk_level`, `context.approval.granted`,
36
+ * `context.environment.*`) is **not** built here — the caller (typically
37
+ * `CedarDecisionService`) builds context separately because the same entities
38
+ * are reused across Phase A / Phase B (approval=false / approval=true)
39
+ * evaluations.
40
+ */
41
+ export interface CedarEntitiesInput {
42
+ principal: CedarEntityDescriptor;
43
+ action: string;
44
+ resource: CedarEntityDescriptor;
45
+ }
46
+ /**
47
+ * Build the Cedar entity list (principal + action + resource) for a single
48
+ * authorization evaluation.
49
+ *
50
+ * Returns exactly 3 entities, in stable order [principal, action, resource].
51
+ * The Action entity gets `attrs.risk_level` populated from
52
+ * {@link resolveActionRisk}. principal / resource pass through `attrs`
53
+ * unchanged (defaulting to `{}` when omitted).
54
+ *
55
+ * Entity hierarchy (`parents`) is intentionally empty in Phase 1 — Phase 2
56
+ * will introduce schema-driven parents (e.g., GmailThread → GmailLabel).
57
+ */
58
+ export declare function buildCedarEntities(input: CedarEntitiesInput): CedarEntity[];
59
+ //# sourceMappingURL=cedar-entities.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cedar-entities.d.ts","sourceRoot":"","sources":["../../src/policy/cedar-entities.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAGjD;;;;;GAKG;AACH,MAAM,WAAW,qBAAqB;IACpC,IAAI,EAAE,MAAM,CAAA;IACZ,EAAE,EAAE,MAAM,CAAA;IACV,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CAChC;AAED;;;;;;;;;;;GAWG;AACH,MAAM,WAAW,kBAAkB;IACjC,SAAS,EAAE,qBAAqB,CAAA;IAChC,MAAM,EAAE,MAAM,CAAA;IACd,QAAQ,EAAE,qBAAqB,CAAA;CAChC;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,kBAAkB,GAAG,WAAW,EAAE,CAsB3E"}
@@ -0,0 +1,46 @@
1
+ /**
2
+ * Decision 7-value enum — A2A / AP2 aligned (Cedar unification Step 1).
3
+ *
4
+ * Spec ref:
5
+ * - docs/specs/2026-05-24-cedar-unification-design.md §3
6
+ * - decision #9 (Locked Decisions §2): A2A 互換 7 値、後方互換破壊 OK
7
+ *
8
+ * HTTP mapping (spec §3, line 169):
9
+ * - `permit` → 200
10
+ * - `auth_required` → 202 (replaces legacy `RequireApproval`)
11
+ * - `input_required` → reserved for Phase 2+
12
+ * - `denied` → 403 (explicit forbid policy match)
13
+ * - `denied_default` → 403 (no permit policy matched)
14
+ * - `denied_by_user` → 403 (HITL UI rejection)
15
+ * - `indeterminate` → 500 (Cedar evaluation error, fail-closed)
16
+ *
17
+ * Phase 1 Step 1 scope: SDK enum + runtime guard only.
18
+ * Step 2 (API layer) will rewire `CedarDecisionService` to emit these values
19
+ * and replace the legacy 3-value `CedarDecisionValue` (`Permit | Forbid |
20
+ * RequireApproval`) over the wire. Both types coexist during the transition.
21
+ */
22
+ /**
23
+ * The 7 decision states a permission evaluator may emit. Lowercase + snake_case
24
+ * to match A2A protocol naming conventions.
25
+ */
26
+ export type Decision = 'permit' | 'auth_required' | 'input_required' | 'denied' | 'denied_default' | 'denied_by_user' | 'indeterminate';
27
+ /**
28
+ * Frozen ordered tuple of every {@link Decision} value. Useful for `it.each`
29
+ * test enumeration, exhaustiveness assertions, and audit-log validation.
30
+ *
31
+ * The order is **stable** and is the canonical iteration order (permit first,
32
+ * then approval gate, then input gate, then the 3 denied variants, then the
33
+ * fail-closed indeterminate). Do not rely on alphabetic order.
34
+ */
35
+ export declare const DECISION_VALUES: readonly ["permit", "auth_required", "input_required", "denied", "denied_default", "denied_by_user", "indeterminate"];
36
+ /**
37
+ * Runtime type guard for {@link Decision}. Returns `true` only if `value` is
38
+ * one of the 7 canonical literals. Use this when validating wire payloads
39
+ * (audit log rows, HTTP bodies, IPC) before narrowing to `Decision`.
40
+ *
41
+ * Legacy 3-value capitalized literals (`Permit`, `Forbid`, `RequireApproval`)
42
+ * are **not** accepted; callers that still need to handle the old wire format
43
+ * must do their own translation (Step 2 will provide the migration helper).
44
+ */
45
+ export declare function isDecision(value: unknown): value is Decision;
46
+ //# sourceMappingURL=decision.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"decision.d.ts","sourceRoot":"","sources":["../../src/policy/decision.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH;;;GAGG;AACH,MAAM,MAAM,QAAQ,GAChB,QAAQ,GACR,eAAe,GACf,gBAAgB,GAChB,QAAQ,GACR,gBAAgB,GAChB,gBAAgB,GAChB,eAAe,CAAA;AAEnB;;;;;;;GAOG;AACH,eAAO,MAAM,eAAe,uHAQgB,CAAA;AAE5C;;;;;;;;GAQG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,QAAQ,CAK5D"}
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Policy module — Cedar policy engine wrapper (Phase 1 Step 1).
3
+ *
4
+ * Re-exports the Cedar engine factory + types. Test-only helpers
5
+ * (`__resetCedarEngineCache`, `__setCedarLoaderForTests`) are
6
+ * intentionally NOT re-exported here; tests import them from the
7
+ * module directly via `'../cedar-engine'`.
8
+ */
9
+ export { createCedarEngine, CedarEngineUnavailableError, CedarParseError, buildValidationErrors, classifyCedarErrorMessage, } from './cedar-engine';
10
+ export type { CedarEngine, CedarDecision, CedarError, CedarEntity, CedarEvaluateRequest, EvaluateInput, EvaluateResult, SchemaHandle, PolicySetHandle, PolicyValidationError, } from './cedar-engine';
11
+ export { buildCedarEntities } from './cedar-entities';
12
+ export type { CedarEntitiesInput, CedarEntityDescriptor, } from './cedar-entities';
13
+ export { DECISION_VALUES, isDecision } from './decision';
14
+ export type { Decision } from './decision';
15
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/policy/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EACL,iBAAiB,EACjB,2BAA2B,EAC3B,eAAe,EACf,qBAAqB,EACrB,yBAAyB,GAC1B,MAAM,gBAAgB,CAAA;AAEvB,YAAY,EACV,WAAW,EACX,aAAa,EACb,UAAU,EACV,WAAW,EACX,oBAAoB,EACpB,aAAa,EACb,cAAc,EACd,YAAY,EACZ,eAAe,EACf,qBAAqB,GACtB,MAAM,gBAAgB,CAAA;AAGvB,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAA;AACrD,YAAY,EACV,kBAAkB,EAClB,qBAAqB,GACtB,MAAM,kBAAkB,CAAA;AACzB,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AACxD,YAAY,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA"}