typeorm-pii-compliance
Version:
TypeORM PII Compliance Service: Cascading Personally Identifiable Information Disposal
169 lines (129 loc) • 5 kB
Markdown
# TypeORM PII(Personally Identifiable Information) Compliance Service
- Cascading Personally Identifiable Information Disposal
[](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) : Character to be replaced when masking
- `'*' | '-' | string`
- `beforeDisposal`(optional) : Callback function called before disposal
- `(type: EntityType, entity: any) => Promise<void> | void`
### `` Decorator
- Options
- `hierarchyLevel`(enum, required) : Sets the level of the information hierarchy to adjust processing priorities.
- `PiiHierarchyLevel.TOP` : The top-level entity. Usually defined in User or Member entities. It will be
processed last.
- `PiiHierarchyLevel.HIGHER`, `PiiHierarchyLevel.HIGH`, `PiiHierarchyLevel.MIDDLE`, `PiiHierarchyLevel.LOW`
, `PiiHierarchyLevel.LOWER`
- `PiiHierarchyLevel.LEAF` : It is an entity at the lowest level, such as data in the history records. It is
processed first.
- `strategy`(enum, optional) : Disposal strategy
- `PiiDisposalStrategy.MASKING`(default) : `` Mask the set column.
- `PiiDisposalStrategy.DELETE` : Delete entity from data source.
- `group`(string, optional) : Group
- If there are multiple ID systems that recognize users, you can separate the processing contexts using the
group.
### `` Decorator
- Options
- `maskingMethod`(required) : Masking method
- `null` : Change the data to null. Check if the column type is nullable.
- `zero` : Change the data to 0(Number)
- `blank` : Change the data to ""(blank string)
- `edge1` ~ `edge8` : Masks 1 to 8 characters back and forth.
- `center1` ~ `center8` : Masks 1 to 8 characters from the center.
- `email` : Masks up to 5 characters before and after centered at @.
- `(<T>(value: T) => Promise<T> | T)` : Custom transform callback.
----
## Usage 1. PiiDisposalStrategy.DELETE
- To delete entities with PII, set the `` decorator in the user ID column to be used for filtering.
```typescript
// Top level user entity
export class User extends BaseEntity {
id!: number;
// ... other columns
}
// Examples of tables includes PII that depend on users
export class OrderHistory extends BaseEntity {
seq!: number;
user!: User;
// ... other columns
}
const service = new PiiComplianceService();
/*
* If a user with User.id of 9999 withdrew, the deletion proceeds in the order of OrderHistory -> User entity when called as follows.
*/
await service.process(
// User ID
9999,
// Callback
async (type, entity) => {
console.log(type, entity);
}
);
```
## Usage 2. PiiDisposalStrategy.MASKING
- Use the `` decorator to mask some PII instead of deleting the Entity.
```typescript
// Top level user entity
export class User extends BaseEntity {
id!: number;
firstName!: string;
lastName!: string;
email!: string;
// ... other columns
}
// Examples of tables includes PII that depend on users
export class OrderHistory extends BaseEntity {
seq!: number;
user!: User;
// ... other columns
}
const service = new PiiComplianceService();
await service.process(
// User ID
9999,
// Callback
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>