NestJS-idiomatic audit trails. Argos (Odysseus's faithful dog -- waited twenty years and never forgot) tracks who changed your entities and when.
npm install @neoma/argosPeer dependencies: @nestjs/common, @nestjs/core, typeorm
import { ArgosModule } from "@neoma/argos"
@Module({
imports: [
ArgosModule.forRoot({
resolveActor: (req) =>
req.principal ? `principal:${req.principal.id}` : null,
}),
],
})
export class AppModule {}Or with async configuration:
ArgosModule.forRootAsync({
useFactory: (config: ConfigService) => ({
resolveActor: (req) =>
req.principal ? `principal:${req.principal.id}` : null,
}),
inject: [ConfigService],
})import { CreatedBy, UpdatedBy } from "@neoma/argos"
@Entity()
export class Invoice {
@PrimaryGeneratedColumn("uuid")
public id!: string
@Column()
public amount!: number
@CreatedBy()
public createdBy!: string
@UpdatedBy()
public updatedBy!: string
}That's it. createdBy is set on insert, updatedBy is set on every save.
| Option | Type | Default | Description |
|---|---|---|---|
resolveActor |
(req: Request) => string | null | undefined | Promise<string | null | undefined> |
undefined |
Extracts the actor from the request. Return null or undefined to use the default. |
defaultActor |
string |
"system" |
Actor used when resolveActor is absent or returns null or undefined. |
Actors are prefixed strings -- not foreign keys:
principal:uuid-- authenticated userapi:name-- API keywebhook:source-- webhook callersystem-- unauthenticated or background
- Must use
repository.save()/repository.remove()--manager.update(), QueryBuilder, etc. bypass entity listeners silently. @CreatedBy()sets on insert and is never overwritten on update.@UpdatedBy()sets on everysave()-- both insert and update.