Decorators

Compliance Decorators

Define TypeScript audit trails, sensitive-data classification, redaction, and retention policies with AxilJS semantic decorators.

3 min readUpdated DocumentationEdit this page
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.

TypeScript
TS
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

OptionTypeDescription
actionstringAudit action identifier
compliancestring[]Compliance frameworks
sensitivity'low' | 'medium' | 'high'Data sensitivity level
includeRequestbooleanInclude request data
includeResponsebooleanInclude 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.

TypeScript
TS
1@tSensitive('PII')
2email: string
3
4@tSensitive('PCI')
5cardNumber: string
6
7@tSensitive('PHI')
8diagnosis: string

Supported classifications include:

ClassificationDescription
'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.

TypeScript
TS
@tRedact()
password: string

For controlled masking, specify a redaction strategy:

TypeScript
TS
1@tRedact({
2  strategy: 'mask',
3  visibleChars: 4,
4})
5cardNumber: string

For example, the masked value can appear as:

Output
TXT
****1234

Strategies

StrategyDescription
'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.

TypeScript
TS
1import { tRetention } from '@axiljs/decorator'
2
3@tRetention({ duration: '90d', after: 'created' })
4class AccessLog {}
OptionTypeDescription
durationstringRetention 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.

TypeScript
TS
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:

TypeScript
TS
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

DecoratorPurpose
tAuditDeclare immutable audit-trail events
tSensitiveClassify sensitive data
tRedactPrevent sensitive values from appearing in output
tRetentionDeclare 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?

Help improve the documentation

AxilJS is open source and documentation improvements are welcome.

AxilJS DocumentationMIT License · Built by SyntaxilitY