typeorm-pii-compliance
Version:
TypeORM PII Compliance Service: Cascading Personally Identifiable Information Disposal
153 lines (128 loc) • 5.33 kB
Markdown
# TypeORM PII(Personally Identifiable Information) Compliance Service
- 개인 식별 정보 자동 파기 서비스
[](https://github.com/kibae/typeorm-pii-compliance/actions/workflows/node.js.yml)
[](https://www.npmjs.com/package/typeorm-pii-compliance)
[](https://github.com/kibae/typeorm-pii-compliance/blob/main/LICENSE)
## Install
- NPM
```shell
$ npm install typeorm-pii-compliance --save
```
- Yarn
```shell
$ yarn add typeorm-pii-compliance
```
----
## API
### `PiiComplianceService` Class
- `Constructor(options?: PiiComplianceServiceOptions)`
- `replaceChar`(optional) : Masking 시 대체될 문자
- `'*' | '-' | string`
- `beforeDisposal`(optional) : 파기되기 전에 호출되는 콜백 함수
- `(type: EntityType, entity: any) => Promise<void> | void`
### `` 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) : ``가 설정된 컬럼을 마스킹 처리합니다.
- `PiiDisposalStrategy.DELETE` : Entity를 삭제합니다.
- `group`(string, optional) : 그룹
- 사용자를 인식하는 ID체계가 복수일 경우, group 값을 이용해 처리 컨텍스트를 분리할 수 있습니다.
### `` 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 컬럼에 `` decorator를 설정해 주세요.
```typescript
// 최상위 유저 테이블
export class User extends BaseEntity {
id!: number;
// ... other columns
}
// 유저에게 종속된 정보 테이블들 예시
export class OrderHistory extends BaseEntity {
seq!: number;
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 삭제 대신 일부 정보를 마스킹처리하려면 `` decorator를 사용하세요.
```typescript
// 최상위 유저 테이블
export class User extends BaseEntity {
id!: number;
firstName!: string;
lastName!: string;
email!: string;
// ... other columns
}
// 유저에게 종속된 정보 테이블들 예시
export class OrderHistory extends BaseEntity {
seq!: number;
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
<a href="https://github.com/kibae/typeorm-pii-compliance/graphs/contributors">
<img src="https://contrib.rocks/image?repo=kibae/typeorm-pii-compliance" />
</a>