انتقل إلى المحتوى الرئيسي

Class: AuditClient

Defined in: packages/audit-client/src/client.ts:123

The producer's entry point to the audit trail, for one module. It does two things and nothing else: it writes a record to the module's own outbox, and it builds the hook that records refusals. Publishing is the relay's.

Constructors​

Constructor​

new AuditClient(options): AuditClient

Defined in: packages/audit-client/src/client.ts:131

Parameters​

options​

AuditClientOptions

Returns​

AuditClient

Throws​

unknown_module when the module is not one of the estate's.

Accessors​

module​

Get Signature​

get module(): string

Defined in: packages/audit-client/src/client.ts:141

Returns​

string

The module records are produced for.

Methods​

accessDenyHook()​

accessDenyHook(db): AccessDenyHook

Defined in: packages/audit-client/src/client.ts:274

The refusal-time hook for messaging's receiver. It files the denial under the subject's tenant token (or platform), with the decoded actor when there is one and the platform actor when there is not, and copies the reason unchanged. A failure rejects, which the receiver logs; the refusal stands either way.

The record's actor is the one the refused message claimed, not one anything verified. Under actor_token_invalid and actor_unverified the claim is exactly what failed, so the sender chose it, and a reader must not take it as who acted: it says whom the message pretended to act for. There are no verified claims to record instead, since a token that failed verification proves nothing.

Parameters​

db​

Database<AuditOutboxTables>

The receiving module's pool.

Returns​

AccessDenyHook

A function for ReceiverOptions.onDeny.


record()​

record<DB>(tx, entry, options?): Promise<{ recordId: string; }>

Defined in: packages/audit-client/src/client.ts:157

Writes one audit record to the outbox in the caller's transaction, and does nothing else: it commits with the change it describes or not at all. The actor is read from the transaction's scope, never from the caller.

Type Parameters​

DB​

DB extends AuditOutboxTables

Parameters​

tx​

ScopedTransaction<DB>

The transaction from withScope or withPlatformScope.

entry​

AuditEntry

The action, outcome, target and payload.

options?​

RecordOptions = {}

A tenant (platform transactions only) or a correlation id.

Returns​

Promise<{ recordId: string; }>

The new record's id.

Throws​

The transaction was not opened by persistence; the module may not record the action; the record is invalid; there is no correlation id.


recordAccessDenied()​

recordAccessDenied(db, denied): Promise<{ recordId: string; }>

Defined in: packages/audit-client/src/client.ts:222

Records an access.deny in its own transaction on the receiving module's pool. For a refusal that happens before any scope exists (messaging's receiver) or whose caller's transaction rolls back (a handler's scope_denied, principal_unknown): a denial must survive the thing that was denied.

The payload is always version 2 (version: 2, nine reasons, slice 2 D2.2), whatever the reason: one producer writing two versions would make the version say nothing about who wrote it. Version 1 records already in the chain stay as they are, and the audit service accepts both.

Parameters​

db​

Database<AuditOutboxTables>

The receiving module's pool, as that module's own role.

denied​

AccessDeniedEntry

The refusal; its reason is stored unchanged.

Returns​

Promise<{ recordId: string; }>

The new record's id.

Throws​

The module may not record access.deny, or the record is invalid.