Skip to main content

API Reference

Complete reference for all exports from @hex-di/guard.

Tokens

ExportTypeDescription
createPermissionfunctionCreates a branded nominal permission token using Symbol.for()
PermissiontypeThe branded permission token type
createPermissionGroupfunctionBundles related permissions into a named group
PermissionGrouptypeType for permission groups
createRolefunctionCreates a role with permissions and optional inheritance
RoletypeThe role type with flattened permissions

Policy Combinators

ExportTypeDescription
hasPermissionfunctionChecks if subject has a specific permission
hasRolefunctionChecks if subject has a specific role
hasAttributefunctionChecks if subject attribute matches a value
hasResourceAttributefunctionChecks if resource attribute matches a value
hasSignaturefunctionChecks if electronic signature is present
hasRelationshipfunctionChecks if subject has relationship to resource
allOffunctionAll sub-policies must grant (AND logic)
anyOffunctionAt least one sub-policy must grant (OR logic)
notfunctionInverts the decision of a sub-policy
withLabelfunctionAttaches a human-readable label to a policy
anyOfRolesfunctionShorthand for anyOf with multiple role checks
PolicyConstrainttypeDiscriminated union type for all policies

Evaluation

ExportTypeDescription
evaluatefunctionSynchronous pure policy evaluation
evaluateAsyncfunctionAsync evaluation with attribute resolution
DecisiontypeResult of policy evaluation with trace
EvaluationTracetypeRecursive tree of evaluation steps
EvaluationContexttypeContext for resource attributes and signatures
EvaluateOptionstypeOptions for evaluation (e.g., maxDepth)
AttributeResolvertypeAsync function for resolving attributes
RelationshipResolvertypeInterface for resolving relationships
NoopRelationshipResolverconstNo-op implementation of relationship resolver

Subject

ExportTypeDescription
AuthSubjecttypeIdentity with permissions, roles, and attributes
createAuthSubjectfunctionFactory for creating auth subjects
withAttributesfunctionCreates new subject with additional attributes
getAttributefunctionType-safe attribute retrieval
PrecomputedSubjectclassOptimized subject with flattened permissions
SubjectProviderPortconstPort for resolving current subject
SubjectProvidertypeInterface for subject providers

Guard/Enforcement

ExportTypeDescription
enforcePolicyfunctionWraps adapter with policy enforcement
AccessDeniedErrorconstError when policy denies access
AuditWriteFailedErrorconstError when audit trail write fails
createGuardGraphfunctionCreates graph fragment with guard infrastructure
createGuardHealthCheckfunctionCreates health check for guard infrastructure
createCompletenessMonitorfunctionMonitors audit trail completeness
GuardOptionstypeOptions for guard enforcement
AuditEntrytypeAudit trail entry structure
AuditTrailtypeInterface for audit trail implementations
AuditTrailPorttypePort for audit trail
createNoopAuditTrailAdapterfunctionNo-op audit trail for testing

GxP Infrastructure

ExportTypeDescription
createWriteAheadLogfunctionCreates WAL for durability
WalEntrytypeWrite-ahead log entry
createCircuitBreakerfunctionCreates circuit breaker for fault tolerance
CircuitBreakerStatetypeCircuit breaker states (closed/open/half-open)
detectClockDriftfunctionDetects clock drift between components
checkClockDriftfunctionValidates clock synchronization
enforceRetentionfunctionApplies retention policy to audit entries
getPurgeableEntriesfunctionIdentifies entries for retention
RetentionPolicytypeConfiguration for data retention
createMetaAuditEntryfunctionCreates meta-audit entry
MetaAuditTrailtypeInterface for meta-audit trail
archiveAuditTrailfunctionArchives audit entries to cold storage
createDecommissioningChecklistfunctionGenerates system decommissioning checklist
createScopeDisposalVerifierfunctionVerifies proper scope disposal
createScopeRegistryfunctionManages scope lifecycle

Hooks

ExportTypeDescription
createPortGateHookfunctionCreates resolution hook for port gating
createRoleGatefunctionShorthand for role-based port gating
PortGatedErrortypeError when port gate blocks resolution
PortGatetypeConfiguration for port gates

Serialization

ExportTypeDescription
serializePolicyfunctionConverts policy to JSON string
deserializePolicyfunctionConverts JSON string to policy
explainPolicyfunctionGenerates human-readable policy description
PolicyDeserializationErrortypeError during deserialization

Inspection

ExportTypeDescription
GuardInspectorclassInspector for guard system state
GuardInspectorPortconstPort for guard inspector
createGuardLibraryInspectorfunctionCreates library-level inspector
GuardLibraryInspectorPortconstPort for library inspector
GuardLibraryInspectorAdapterconstAdapter for library inspection
GuardInspectionSnapshottypeSnapshot of guard state

Events & Spans

ExportTypeDescription
GuardEventtypeDiscriminated union of guard events
GuardEventSinktypeInterface for event handling
GuardEventSinkPorttypePort for event sink
NoopGuardEventSinkconstNo-op event sink
GuardSpanSinktypeInterface for span tracking
GuardSpanSinkPorttypePort for span sink
NoopGuardSpanSinkconstNo-op span sink

Signature Service

ExportTypeDescription
SignatureServicePorttypePort for electronic signature service
NoopSignatureServiceconstNo-op signature service
ElectronicSignaturetypeElectronic signature structure
SignatureMeaningtypeSignature type meanings

Utilities

ExportTypeDescription
flattenPermissionsfunctionFlattens permissions from role hierarchy
inferPolicyTypefunctionInfers TypeScript type from policy