|
1 | 1 | import { initializeWasm } from "@arcjet/redact-wasm";
|
2 |
| -import type { SensitiveInfoEntity } from "@arcjet/redact-wasm"; |
| 2 | +import type { |
| 3 | + RedactedSensitiveInfoEntity as RedactedSensitiveInfoEntityWasm, |
| 4 | + RedactSensitiveInfoConfig, |
| 5 | + SensitiveInfoEntity, |
| 6 | +} from "@arcjet/redact-wasm"; |
3 | 7 |
|
4 | 8 | /**
|
5 |
| - * Types of sensitive information. |
| 9 | + * Types of standard sensitive information that can be detected. |
6 | 10 | */
|
7 |
| -export type ArcjetSensitiveInfoType = |
8 |
| - | "email" |
9 |
| - | "phone-number" |
10 |
| - | "ip-address" |
11 |
| - | "credit-card-number"; |
| 11 | +export type ArcjetSensitiveInfoType = Exclude< |
| 12 | + SensitiveInfoEntity["tag"], |
| 13 | + "custom" |
| 14 | +>; |
12 | 15 |
|
13 | 16 | type DetectSensitiveInfoEntities<T> = (
|
14 | 17 | tokens: string[],
|
@@ -65,34 +68,34 @@ export type RedactOptions<Detect> = {
|
65 | 68 | replace?: Replace<Detect>;
|
66 | 69 | };
|
67 | 70 |
|
68 |
| -function userEntitiesToWasm(entity: unknown) { |
| 71 | +function userEntitiesToWasm(entity: unknown): SensitiveInfoEntity { |
69 | 72 | if (typeof entity !== "string") {
|
70 | 73 | throw new Error("redaction entities must be strings");
|
71 | 74 | }
|
72 | 75 |
|
73 | 76 | if (entity === "email") {
|
74 |
| - return { tag: "email" as const }; |
| 77 | + return { tag: "email" }; |
75 | 78 | }
|
76 | 79 |
|
77 | 80 | if (entity === "phone-number") {
|
78 |
| - return { tag: "phone-number" as const }; |
| 81 | + return { tag: "phone-number" }; |
79 | 82 | }
|
80 | 83 |
|
81 | 84 | if (entity === "ip-address") {
|
82 |
| - return { tag: "ip-address" as const }; |
| 85 | + return { tag: "ip-address" }; |
83 | 86 | }
|
84 | 87 |
|
85 | 88 | if (entity === "credit-card-number") {
|
86 |
| - return { tag: "credit-card-number" as const }; |
| 89 | + return { tag: "credit-card-number" }; |
87 | 90 | }
|
88 | 91 |
|
89 | 92 | return {
|
90 |
| - tag: "custom" as const, |
| 93 | + tag: "custom", |
91 | 94 | val: entity,
|
92 | 95 | };
|
93 | 96 | }
|
94 | 97 |
|
95 |
| -function wasmEntitiesToString(entity: SensitiveInfoEntity) { |
| 98 | +function wasmEntitiesToString(entity: SensitiveInfoEntity): string { |
96 | 99 | if (entity.tag === "email") {
|
97 | 100 | return "email";
|
98 | 101 | }
|
@@ -135,18 +138,15 @@ function noOpReplace(
|
135 | 138 | }
|
136 | 139 | /* c8 ignore stop */
|
137 | 140 |
|
138 |
| -interface RedactedSensitiveInfoEntity { |
139 |
| - original: string; |
140 |
| - redacted: string; |
141 |
| - start: number; |
142 |
| - end: number; |
| 141 | +interface RedactedSensitiveInfoEntity |
| 142 | + extends Omit<RedactedSensitiveInfoEntityWasm, "identifiedType"> { |
143 | 143 | identifiedType: string;
|
144 | 144 | }
|
145 | 145 |
|
146 | 146 | function getWasmOptions<
|
147 | 147 | const Detect extends DetectSensitiveInfoEntities<CustomEntities> | undefined,
|
148 | 148 | const CustomEntities extends string,
|
149 |
| ->(options?: RedactOptions<Detect>) { |
| 149 | +>(options?: RedactOptions<Detect>): RedactSensitiveInfoConfig { |
150 | 150 | if (typeof options === "object" && options !== null) {
|
151 | 151 | if (typeof options.entities !== "undefined") {
|
152 | 152 | if (Array.isArray(options.entities)) {
|
|
0 commit comments