Compliance Decorators
Define TypeScript audit trails, sensitive-data classification, redaction, and retention policies with AxilJS semantic decorators.
On this page8
Compliance decorators declare audit, privacy, and data-governance constraints as semantic metadata. These declarations can be consumed by logging pipelines, database layers, and export tooling.
@tAudit
tAudit records an application action in an immutable audit trail.
1import { tAudit } from '@axiljs/decorator'
2
3@tAudit({
4 action: 'user.deleted',
5})
6async deleteUser(id: string) {}
7
8@tAudit({
9 action: 'funds.transferred',
10 compliance: ['SOC2', 'PCI-DSS'],
11 sensitivity: 'high',
12})
13async transferFunds() {}Options
| Option | Type | Description |
|---|---|---|
action | string | Audit action identifier |
compliance | string[] | Compliance frameworks |
sensitivity | 'low' | 'medium' | 'high' | Data sensitivity level |
includeRequest | boolean | Include request data |
includeResponse | boolean | Include response data |
Note
@axiljs/runtime executes these at runtime: tAudit through the audit interceptor (an audit.log event per call, after wire() / wireAll()), and tRedact / tSensitive through redact(), redactResponses() and redactingTransport(). See Runtime.
@tSensitive
tSensitive classifies a property under a specific sensitivity classification.
1@tSensitive('PII')
2email: string
3
4@tSensitive('PCI')
5cardNumber: string
6
7@tSensitive('PHI')
8diagnosis: stringSupported classifications include:
| Classification | Description |
|---|---|
'PII' | Personally identifiable information |
'PHI' | Protected health information |
'PCI' | Payment card industry data |
'SECRET' | Secrets and credentials |
'INTERNAL' | Internal-only data |
@tRedact
tRedact prevents a property value from appearing in logs or outbound responses.
@tRedact()
password: stringFor controlled masking, specify a redaction strategy:
1@tRedact({
2 strategy: 'mask',
3 visibleChars: 4,
4})
5cardNumber: stringFor example, the masked value can appear as:
****1234Strategies
| Strategy | Description |
|---|---|
'mask' | Replace with asterisks while showing the configured number of characters |
'hash' | Replace with a one-way hash |
'remove' | Omit the value entirely from output |
@tRetention
tRetention declares a data-retention policy for an entity or property.
The decorator allows retention requirements to be represented as metadata rather than embedding retention logic directly into application code.
1import { tRetention } from '@axiljs/decorator'
2
3@tRetention({ duration: '90d', after: 'created' })
4class AccessLog {}| Option | Type | Description |
|---|---|---|
duration | string | Retention window, such as '90d' or '1y' |
after | 'created' | 'accessed' | 'updated' | Event the window is measured from |
tRetention can be applied to classes and properties.
Combining Compliance Semantics
Compliance decorators can be composed to describe both what data represents and how it should be handled.
1class PaymentRecord {
2 @tSensitive('PCI')
3 @tRedact({
4 strategy: 'mask',
5 visibleChars: 4,
6 })
7 cardNumber: string
8}An audit operation can separately declare its governance requirements:
1@tAudit({
2 action: 'funds.transferred',
3 compliance: ['SOC2', 'PCI-DSS'],
4 sensitivity: 'high',
5})
6async transferFunds() {
7 return this.paymentService.transfer()
8}This separates compliance intent from the implementation of logging, redaction, storage, or export behavior.
Reference
| Decorator | Purpose |
|---|---|
tAudit | Declare immutable audit-trail events |
tSensitive | Classify sensitive data |
tRedact | Prevent sensitive values from appearing in output |
tRetention | Declare data-retention policies |
Compliance decorators are semantic declarations. Their metadata can be consumed by independent infrastructure components such as logging pipelines, database layers, and export tooling rather than requiring compliance logic to be embedded into every business method.
Was this page helpful?