npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

typeorm-pii-compliance

v0.2.0

Published

TypeORM PII Compliance Service: Cascading Personally Identifiable Information Disposal

Readme

TypeORM PII(Personally Identifiable Information) Compliance Service

  • 개인 식별 정보 자동 파기 서비스

Node.js CI NPM Version License

Install

  • NPM
$ npm install typeorm-pii-compliance --save
  • Yarn
$ yarn add typeorm-pii-compliance

API

PiiComplianceService Class

  • Constructor(options?: PiiComplianceServiceOptions)
    • replaceChar(optional) : Masking 시 대체될 문자
      • '*' | '-' | string
    • beforeDisposal(optional) : 파기되기 전에 호출되는 콜백 함수
      • (type: EntityType, entity: any) => Promise<void> | void

@PiiId() Decorator

  • Options
    • hierarchyLevel(enum, required) : 정보 계층의 레벨을 설정하여 처리 우선순위를 조정합니다.
      • PiiHierarchyLevel.TOP : 최상위 레벨의 entity. 보통 User, Member entity에 정의합니다. 가장 나중에 처리됩니다.
      • PiiHierarchyLevel.HIGHER, PiiHierarchyLevel.HIGH, PiiHierarchyLevel.MIDDLE, PiiHierarchyLevel.LOW, PiiHierarchyLevel.LOWER
      • PiiHierarchyLevel.LEAF : History 계열의 데이터 등 최말단 레벨의 entity입니다. 가장 먼저 처리됩니다.
    • strategy(enum, optional) : 처리 전략
      • PiiDisposalStrategy.MASKING(default) : @PiiColumn()가 설정된 컬럼을 마스킹 처리합니다.
      • PiiDisposalStrategy.DELETE : Entity를 삭제합니다.
    • group(string, optional) : 그룹
      • 사용자를 인식하는 ID체계가 복수일 경우, group 값을 이용해 처리 컨텍스트를 분리할 수 있습니다.

@PiiColumn Decorator

  • Options
    • maskingMethod(required) : 마스킹 방식
      • null : null로 데이터를 변경합니다. 컬럼 타입이 nullable 인지 확인하세요.
      • zero : 0 으로 변환
      • blank : "" 으로 변환
      • edge1 ~ edge8 : 앞뒤로 1~8글자를 마스킹합니다.
      • center1 ~ center8 : 가운데부터 1~8글자를 마스킹합니다.
      • email : @를 중심으로 앞뒤 최대 5글자를 마스킹합니다.
      • (<T>(value: T) => Promise<T> | T) : 변환 콜백으로 별도의 변환 수행

Usage 1. PiiDisposalStrategy.DELETE

  • 개인 식별 정보가 포함된 entity를 삭제하기 위해 필터링에 사용할 user ID 컬럼에 @PiiId decorator를 설정해 주세요.
// 최상위 유저 테이블
@Entity()
export class User extends BaseEntity {
  @PrimaryGeneratedColumn()
  @PiiId({ strategy: PiiDisposalStrategy.DELETE, hierarchyLevel: PiiHierarchyLevel.TOP })
  id!: number;

  // ... other columns
}

// 유저에게 종속된 정보 테이블들 예시
@Entity()
export class OrderHistory extends BaseEntity {
  @PrimaryGeneratedColumn()
  seq!: number;

  @Index()
  @ManyToOne((type) => User, (parent) => parent.id)
  @PiiId({ strategy: PiiDisposalStrategy.DELETE, hierarchyLevel: PiiHierarchyLevel.LEAF })
  user!: User;

  // ... other columns
}

const service = new PiiComplianceService();
/*
 * User.id가 9999인 유저가 탈퇴한 경우 아래와 같이 호출하면 OrderHistory -> User entity 순서대로 삭제가 진행됩니다.
 */
await service.process(
  // User ID값
  9999,
  // 파기 처리되기 전에 호출되는 콜백
  async (type, entity) => {
    console.log(type, entity);
  }
);

Usage 2. PiiDisposalStrategy.MASKING

  • Entity 삭제 대신 일부 정보를 마스킹처리하려면 @PiiColumn decorator를 사용하세요.
// 최상위 유저 테이블
@Entity()
export class User extends BaseEntity {
  @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
}

// 유저에게 종속된 정보 테이블들 예시
@Entity()
export class OrderHistory extends BaseEntity {
  @PrimaryGeneratedColumn()
  seq!: number;

  @Index()
  @ManyToOne((type) => User, (parent) => parent.id)
  @PiiId({ strategy: PiiDisposalStrategy.DELETE, hierarchyLevel: PiiHierarchyLevel.LEAF })
  user!: User;

  // ... other columns
}

const service = new PiiComplianceService();
/*
 * User.id가 9999인 유저가 탈퇴한 경우 아래와 같이 호출하면 OrderHistory -> User entity 순서대로 마스킹과 삭제가 진행됩니다.
 */
await service.process(
        // User ID값
        9999,
        // 파기 처리되기 전에 호출되는 콜백
        async (type, entity) => {
          console.log(type, entity);
        }
);

Contributors