To delete entities with PII, set the @PiiId decorator in the user ID column to be used for filtering.
// Top level user entity
@Entity()exportclassUserextendsBaseEntity{
@PrimaryGeneratedColumn()
@PiiId({strategy: PiiDisposalStrategy.DELETE,hierarchyLevel: PiiHierarchyLevel.TOP})id!: number;// ... other columns}// Examples of tables includes PII that depend on users
@Entity()exportclassOrderHistoryextendsBaseEntity{
@PrimaryGeneratedColumn()seq!: number;
@Index()
@ManyToOne((type)=>User,(parent)=>parent.id)
@PiiId({strategy: PiiDisposalStrategy.DELETE,hierarchyLevel: PiiHierarchyLevel.LEAF})user!: User;// ... other columns}constservice=newPiiComplianceService();/* * If a user with User.id of 9999 withdrew, the deletion proceeds in the order of OrderHistory -> User entity when called as follows. */awaitservice.process(// User ID9999,// Callbackasync(type,entity)=>{console.log(type,entity);});
Usage 2. PiiDisposalStrategy.MASKING
Use the @PiiColumn decorator to mask some PII instead of deleting the Entity.
// Top level user entity
@Entity()exportclassUserextendsBaseEntity{
@PrimaryGeneratedColumn()
@PiiId({strategy: PiiDisposalStrategy.MASKING,hierarchyLevel: PiiHierarchyLevel.TOP})id!: number;
@Column()
@PiiColumn({maskingMethod: 'edge2'})firstName!: string;
@Column()
@PiiColumn({maskingMethod: 'edge2'})lastName!: string;
@Column()
@PiiColumn({maskingMethod: 'email'})email!: string;// ... other columns}// Examples of tables includes PII that depend on users
@Entity()exportclassOrderHistoryextendsBaseEntity{
@PrimaryGeneratedColumn()seq!: number;
@Index()
@ManyToOne((type)=>User,(parent)=>parent.id)
@PiiId({strategy: PiiDisposalStrategy.DELETE,hierarchyLevel: PiiHierarchyLevel.LEAF})user!: User;// ... other columns}constservice=newPiiComplianceService();awaitservice.process(// User ID9999,// Callbackasync(type,entity)=>{console.log(type,entity);});
Contributors
About
TypeORM PII Compliance Service: Cascading Personally Identifiable Information Disposal