-
Notifications
You must be signed in to change notification settings - Fork 0
/
tokens.ts
100 lines (84 loc) · 2.14 KB
/
tokens.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import type { Primitive, TokenBase } from './shared';
const DATA_CLASSIFICATIONS = ['general', 'bank', 'pci', 'pii'] as const;
type DataClassification = typeof DATA_CLASSIFICATIONS[number];
const DATA_IMPACT_LEVELS = ['low', 'moderate', 'high'] as const;
type DataImpactLevel = typeof DATA_IMPACT_LEVELS[number];
const DATA_RESTRICTION_POLICIES = ['mask', 'redact'] as const;
type DataRestrictionPolicy = typeof DATA_RESTRICTION_POLICIES[number];
type DataObject<DataType = Primitive> = {
[member: string]: TokenData<DataType>;
};
type DataArray<DataType> = Array<TokenData<DataType>>;
type TokenData<DataType = Primitive> =
| Primitive
| DataObject<DataType>
| DataArray<DataType>
| DataType;
type MaskObject = {
[member: string]: TokenMask;
};
type MaskArray = Array<TokenMask>;
type TokenMask = string | MaskObject | MaskArray;
interface TokenEncryptionKey {
key: string;
alg: string;
}
interface TokenEncryption {
cek: TokenEncryptionKey;
kek: TokenEncryptionKey;
}
interface TokenPrivacy {
classification?: DataClassification;
impactLevel?: DataImpactLevel;
restrictionPolicy?: DataRestrictionPolicy;
}
interface Token<DataType = Primitive> extends TokenBase {
data: TokenData<DataType>;
privacy?: TokenPrivacy;
encryption?: TokenEncryption;
searchIndexes?: string[];
fingerprintExpression?: string;
mask?: TokenMask;
expiresAt?: string;
}
type CreateToken<DataType = Primitive> = Pick<
Token<DataType>,
| 'type'
| 'data'
| 'privacy'
| 'metadata'
| 'encryption'
| 'searchIndexes'
| 'fingerprintExpression'
| 'mask'
| 'expiresAt'
> & {
deduplicateToken?: boolean;
id?: string;
};
type UpdateToken<DataType = Primitive> = Partial<
Pick<
Token<DataType>,
| 'data'
| 'metadata'
| 'encryption'
| 'searchIndexes'
| 'fingerprintExpression'
| 'mask'
> & {
privacy: Omit<TokenPrivacy, 'classification'>;
deduplicateToken: boolean;
}
>;
export type {
Token,
CreateToken,
UpdateToken,
DataArray,
DataObject,
TokenData,
DataClassification,
DataImpactLevel,
DataRestrictionPolicy,
};
export { DATA_CLASSIFICATIONS, DATA_IMPACT_LEVELS, DATA_RESTRICTION_POLICIES };