secure-redact 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +178 -0
- package/dist/assets/advanced.worker-DSVrF0gl.js +890 -0
- package/dist/assets/advanced.worker-DSVrF0gl.js.map +1 -0
- package/dist/assets/index-C62fEJ4q.js +888 -0
- package/dist/assets/index-C62fEJ4q.js.map +1 -0
- package/dist/assets/nlp.worker-u7Lr_A3c.js +521 -0
- package/dist/assets/nlp.worker-u7Lr_A3c.js.map +1 -0
- package/dist/assets/ocr.worker-D5s6dY7M.js +139 -0
- package/dist/assets/ocr.worker-D5s6dY7M.js.map +1 -0
- package/dist/lib.d.ts +158 -0
- package/dist/secure-redact.es.js +30138 -0
- package/dist/secure-redact.es.js.map +1 -0
- package/dist/secure-redact.umd.js +108 -0
- package/dist/secure-redact.umd.js.map +1 -0
- package/dist/style.css +1 -0
- package/dist/vite.svg +1 -0
- package/package.json +79 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 HackBell
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
# secure-redact
|
|
2
|
+
|
|
3
|
+
> Client-side PII detection and redaction React component. Upload documents, automatically detect sensitive information using OCR + AI, review detections, and download redacted copies — **all without sending originals to any server**.
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/secure-redact)
|
|
6
|
+
[](https://github.com/your-repo/secure-redact/blob/main/LICENSE)
|
|
7
|
+
|
|
8
|
+
## Features
|
|
9
|
+
|
|
10
|
+
- 🔒 **100% Client-Side** — Documents never leave the browser
|
|
11
|
+
- 🤖 **AI-Powered** — Gemini 2.0 Flash for semantic PII detection with pixel-perfect accuracy
|
|
12
|
+
- 📝 **Multi-Layer Detection** — Regex + NLP + Spatial Analysis + Gemini AI
|
|
13
|
+
- 📄 **PDF & Image Support** — PNG, JPEG, WebP, BMP, and PDF documents
|
|
14
|
+
- 🎯 **Pixel-Perfect Redaction** — Word-ID based mapping for exact bounding boxes
|
|
15
|
+
- 👁️ **Review UI** — Interactive modal to review and toggle detections before redacting
|
|
16
|
+
- 📋 **Audit Trail** — Evidence log of all detected entities and actions taken
|
|
17
|
+
- 🇮🇳 **Indian Documents** — Built-in support for Aadhaar, PAN, GST, IFSC, etc.
|
|
18
|
+
|
|
19
|
+
## Install
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
npm install secure-redact
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Quick Start
|
|
26
|
+
|
|
27
|
+
```tsx
|
|
28
|
+
import { SecureRedact } from 'secure-redact';
|
|
29
|
+
import 'secure-redact/style.css';
|
|
30
|
+
|
|
31
|
+
function App() {
|
|
32
|
+
return (
|
|
33
|
+
<SecureRedact
|
|
34
|
+
apiKey="your-gemini-api-key"
|
|
35
|
+
requiredFields={['NAME', 'DOB']}
|
|
36
|
+
onComplete={(maskedFile, evidence) => {
|
|
37
|
+
// maskedFile: File — the redacted document ready to download/upload
|
|
38
|
+
console.log('Redacted file:', maskedFile.name, maskedFile.size);
|
|
39
|
+
|
|
40
|
+
// evidence: EvidenceLog — audit trail of detections
|
|
41
|
+
console.log('Entities detected:', evidence.detectedEntities.length);
|
|
42
|
+
}}
|
|
43
|
+
/>
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## Props
|
|
49
|
+
|
|
50
|
+
| Prop | Type | Default | Description |
|
|
51
|
+
|------|------|---------|-------------|
|
|
52
|
+
| `apiKey` | `string` | *required* | Gemini API key ([get one here](https://aistudio.google.com/apikey)) |
|
|
53
|
+
| `requiredFields` | `string[]` | `[]` | PII types to KEEP visible (everything else is redacted) |
|
|
54
|
+
| `onComplete` | `(file: File, evidence: EvidenceLog) => void` | *required* | Called when redaction is complete |
|
|
55
|
+
| `confidenceThreshold` | `number` | `0.5` | Minimum confidence (0-1) for PII detection |
|
|
56
|
+
| `maxFileSizeMB` | `number` | `25` | Maximum file size in MB |
|
|
57
|
+
| `acceptedTypes` | `string[]` | Images + PDF | Accepted MIME types |
|
|
58
|
+
| `showDocTypeSelector` | `boolean` | `false` | Show document type picker UI |
|
|
59
|
+
| `className` | `string` | — | Custom CSS class for root container |
|
|
60
|
+
|
|
61
|
+
## Available PII Types
|
|
62
|
+
|
|
63
|
+
Use these values in the `requiredFields` array:
|
|
64
|
+
|
|
65
|
+
| Type | Description |
|
|
66
|
+
|------|-------------|
|
|
67
|
+
| `NAME` | Person/organization names |
|
|
68
|
+
| `PHONE` | Phone/mobile numbers |
|
|
69
|
+
| `EMAIL` | Email addresses |
|
|
70
|
+
| `ADDRESS` | Physical addresses |
|
|
71
|
+
| `AADHAAR` | Aadhaar (UID) numbers |
|
|
72
|
+
| `PAN` | PAN card numbers |
|
|
73
|
+
| `CREDIT_CARD` | Credit/debit card numbers |
|
|
74
|
+
| `DOB` | Dates of birth |
|
|
75
|
+
| `MEDICAL` | Medical information |
|
|
76
|
+
| `ACCOUNT_NUMBER` | Bank account numbers |
|
|
77
|
+
| `IFSC` | IFSC codes |
|
|
78
|
+
| `INVOICE_NO` | Invoice numbers |
|
|
79
|
+
| `GST` | GST/GSTIN numbers |
|
|
80
|
+
|
|
81
|
+
## Examples
|
|
82
|
+
|
|
83
|
+
### Redact everything (maximum privacy)
|
|
84
|
+
|
|
85
|
+
```tsx
|
|
86
|
+
<SecureRedact
|
|
87
|
+
apiKey="your-key"
|
|
88
|
+
requiredFields={[]} // nothing kept visible
|
|
89
|
+
onComplete={(file) => downloadFile(file)}
|
|
90
|
+
/>
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
### Keep only name and address visible
|
|
94
|
+
|
|
95
|
+
```tsx
|
|
96
|
+
<SecureRedact
|
|
97
|
+
apiKey="your-key"
|
|
98
|
+
requiredFields={['NAME', 'ADDRESS']}
|
|
99
|
+
onComplete={(file, evidence) => {
|
|
100
|
+
console.log(`${evidence.detectedEntities.length} entities processed`);
|
|
101
|
+
}}
|
|
102
|
+
/>
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
### With document type selector UI
|
|
106
|
+
|
|
107
|
+
```tsx
|
|
108
|
+
<SecureRedact
|
|
109
|
+
apiKey="your-key"
|
|
110
|
+
showDocTypeSelector={true}
|
|
111
|
+
onComplete={(file) => uploadToServer(file)}
|
|
112
|
+
/>
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
### Using the lower-level component
|
|
116
|
+
|
|
117
|
+
```tsx
|
|
118
|
+
import { SecureUploader } from 'secure-redact';
|
|
119
|
+
import 'secure-redact/style.css';
|
|
120
|
+
|
|
121
|
+
<SecureUploader
|
|
122
|
+
apiKey="your-key"
|
|
123
|
+
requiredFields={['NAME']}
|
|
124
|
+
confidenceThreshold={0.7}
|
|
125
|
+
onUpload={(maskedFile, evidenceJson) => {
|
|
126
|
+
const evidence = JSON.parse(evidenceJson);
|
|
127
|
+
// ...
|
|
128
|
+
}}
|
|
129
|
+
/>
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
## How It Works
|
|
133
|
+
|
|
134
|
+
```
|
|
135
|
+
Document Upload
|
|
136
|
+
↓
|
|
137
|
+
Tesseract.js OCR (browser-side)
|
|
138
|
+
↓
|
|
139
|
+
Multi-Layer PII Detection:
|
|
140
|
+
├── Layer 0: Regex + Checksums (Aadhaar, PAN, CC, Phone)
|
|
141
|
+
├── Layer 1: NLP Heuristics (Names, Addresses, Medical)
|
|
142
|
+
├── Layer 2: Spatial Key-Value Mapping ("Name:" → "John Doe")
|
|
143
|
+
└── Layer 4: Gemini AI Word-ID Detection (pixel-perfect)
|
|
144
|
+
↓
|
|
145
|
+
Interactive Review Modal
|
|
146
|
+
↓
|
|
147
|
+
Destructive Redaction (black rectangles)
|
|
148
|
+
↓
|
|
149
|
+
Redacted File + Evidence Log
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
## Evidence Log
|
|
153
|
+
|
|
154
|
+
The `evidence` object returned in `onComplete` has this structure:
|
|
155
|
+
|
|
156
|
+
```typescript
|
|
157
|
+
interface EvidenceLog {
|
|
158
|
+
timestamp: string; // ISO timestamp
|
|
159
|
+
fileName: string; // Original file name
|
|
160
|
+
detectedEntities: Array<{
|
|
161
|
+
type: PIIType; // e.g., 'NAME', 'AADHAAR'
|
|
162
|
+
confidence: number; // 0-1 detection confidence
|
|
163
|
+
action: 'masked' | 'kept_visible';
|
|
164
|
+
userConfirmed: boolean;
|
|
165
|
+
}>;
|
|
166
|
+
requiredFields: string[]; // Fields that were kept visible
|
|
167
|
+
}
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
## Requirements
|
|
171
|
+
|
|
172
|
+
- **React** ≥ 18.0.0
|
|
173
|
+
- **Gemini API Key** — [Get one free](https://aistudio.google.com/apikey)
|
|
174
|
+
- **Vite** (recommended) — Workers use `new URL(..., import.meta.url)` syntax
|
|
175
|
+
|
|
176
|
+
## License
|
|
177
|
+
|
|
178
|
+
MIT
|