@giouwur/biometric-sdk 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/README.md +215 -0
- package/bin/init.js +50 -0
- package/dist/index.d.mts +569 -0
- package/dist/index.d.ts +569 -0
- package/dist/index.js +4725 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +4667 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +45 -0
- package/templates/test-page.tsx +1219 -0
package/README.md
ADDED
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
# @giouwur/biometric-sdk 🚀
|
|
2
|
+
|
|
3
|
+
A comprehensive React SDK for biometric enrollment, identification, and verification. Built with **React**, **Zustand**, and **Tailwind CSS**.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## ✨ Features
|
|
8
|
+
|
|
9
|
+
- **Multi-modal Support**: Fingerprints (Flat & Rolled), Face, Palm, and Iris.
|
|
10
|
+
- **WebSocket Protocol**: Built-in communication with biometric devices.
|
|
11
|
+
- **State Management**: Zero-config stores for biometric data and device status.
|
|
12
|
+
- **Fully Customizable**:
|
|
13
|
+
- All UI components accept `className`.
|
|
14
|
+
- Custom themes via CSS variables.
|
|
15
|
+
- Low-level primitives to build your own capture flows.
|
|
16
|
+
- **Type Safe**: Exported TypeScript interfaces for all components and stores.
|
|
17
|
+
|
|
18
|
+
---
|
|
19
|
+
|
|
20
|
+
## 📦 Installation
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
npm install @giouwur/biometric-sdk
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
---
|
|
27
|
+
|
|
28
|
+
## 🛠️ Step-by-Step Setup
|
|
29
|
+
|
|
30
|
+
### 1. Wrap with BiometricProvider
|
|
31
|
+
|
|
32
|
+
Wrap your app (usually in `layout.tsx` or `App.tsx`) with the provider to share configuration.
|
|
33
|
+
|
|
34
|
+
```tsx
|
|
35
|
+
import { BiometricProvider } from "@giouwur/biometric-sdk";
|
|
36
|
+
|
|
37
|
+
export default function Layout({ children }) {
|
|
38
|
+
return (
|
|
39
|
+
<BiometricProvider
|
|
40
|
+
config={{
|
|
41
|
+
wsUrl: "ws://127.0.0.1:5000/biometric", // Local device bridge
|
|
42
|
+
apiBaseUrl: "https://your-api.com/v1", // Optional for services
|
|
43
|
+
deviceId: "scanner_front_01", // Optional identifier
|
|
44
|
+
}}
|
|
45
|
+
>
|
|
46
|
+
{children}
|
|
47
|
+
</BiometricProvider>
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
### 2. Basic Usage (Modules)
|
|
53
|
+
|
|
54
|
+
Use pre-built modules for a "drop-in" enrollment experience.
|
|
55
|
+
|
|
56
|
+
```tsx
|
|
57
|
+
import { FingerEnrollModule, FaceEnrollModule } from "@giouwur/biometric-sdk";
|
|
58
|
+
|
|
59
|
+
function EnrollmentPage() {
|
|
60
|
+
return (
|
|
61
|
+
<div className="space-y-8">
|
|
62
|
+
<FingerEnrollModule className="custom-card-style" />
|
|
63
|
+
<FaceEnrollModule />
|
|
64
|
+
</div>
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### 3. Automatic Documentation & Test Page
|
|
70
|
+
|
|
71
|
+
You can automatically generate a comprehensive documentation and test page in your project by running:
|
|
72
|
+
|
|
73
|
+
```bash
|
|
74
|
+
npx @giouwur/biometric-sdk init
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
This will create `app/sdk-test/page.tsx` (or `src/app/sdk-test/page.tsx`) with all possible SDK examples and documentation.
|
|
78
|
+
|
|
79
|
+
---
|
|
80
|
+
|
|
81
|
+
---
|
|
82
|
+
|
|
83
|
+
## 🎨 Customization
|
|
84
|
+
|
|
85
|
+
### Style Overrides (Tailwind)
|
|
86
|
+
|
|
87
|
+
All modules and UI components accept the `className` prop.
|
|
88
|
+
|
|
89
|
+
```tsx
|
|
90
|
+
<FingerEnrollModule className="!bg-slate-900 border-2 border-primary/20 rounded-2xl p-8" />
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
### Custom Themes (CSS Variables)
|
|
94
|
+
|
|
95
|
+
Override global colors for your brand:
|
|
96
|
+
|
|
97
|
+
```css
|
|
98
|
+
:root {
|
|
99
|
+
--primary: 219 255 0; /* HSL values */
|
|
100
|
+
--primary-foreground: 0 0 0;
|
|
101
|
+
--success: 34 197 94;
|
|
102
|
+
}
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
---
|
|
106
|
+
|
|
107
|
+
## 🧠 State & Data Access
|
|
108
|
+
|
|
109
|
+
### Accessing Stores
|
|
110
|
+
|
|
111
|
+
The SDK uses **Zustand** for state. You can read data or trigger actions from anywhere.
|
|
112
|
+
|
|
113
|
+
```tsx
|
|
114
|
+
import { useEnrollmentStore } from "@giouwur/biometric-sdk";
|
|
115
|
+
|
|
116
|
+
function Status() {
|
|
117
|
+
const { fingerprints, faces } = useEnrollmentStore();
|
|
118
|
+
const count = Object.keys(fingerprints).length;
|
|
119
|
+
|
|
120
|
+
return (
|
|
121
|
+
<div>
|
|
122
|
+
Capturados: {count} huellas y {faces.length} rostros.
|
|
123
|
+
</div>
|
|
124
|
+
);
|
|
125
|
+
}
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
### Protocol Primitives
|
|
129
|
+
|
|
130
|
+
Build your own capture modal instead of using the pre-built ones:
|
|
131
|
+
|
|
132
|
+
```tsx
|
|
133
|
+
import { useBiometricStore } from "@giouwur/biometric-sdk";
|
|
134
|
+
|
|
135
|
+
function MyCapture() {
|
|
136
|
+
const { sendMessage, registerHandler } = useBiometricStore();
|
|
137
|
+
|
|
138
|
+
const handleCapture = () => {
|
|
139
|
+
// 1. Listen for responses
|
|
140
|
+
registerHandler("fingerprint_captured", (msg) => {
|
|
141
|
+
console.log("Imagen recibida (base64):", msg.image);
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
// 2. Trigger capture
|
|
145
|
+
sendMessage({
|
|
146
|
+
messageType: "capture_fingerprint",
|
|
147
|
+
position: "RIGHT_INDEX",
|
|
148
|
+
});
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
return <button onClick={handleCapture}>Iniciar Escaneo</button>;
|
|
152
|
+
}
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
---
|
|
156
|
+
|
|
157
|
+
## 🔌 API Integration Flow
|
|
158
|
+
|
|
159
|
+
The SDK doesn't make API calls directly to your backend. It provides the data you need to send.
|
|
160
|
+
|
|
161
|
+
1. **Load data**: `loadApplicantData(data)`
|
|
162
|
+
2. **Capture**: User interacts with modules.
|
|
163
|
+
3. **Build Payload**: `buildEnrollmentRequest()` returns a standardized object.
|
|
164
|
+
|
|
165
|
+
```tsx
|
|
166
|
+
const store = useEnrollmentStore.getState();
|
|
167
|
+
|
|
168
|
+
// Al finalizar el proceso
|
|
169
|
+
const payload = store.buildEnrollmentRequest();
|
|
170
|
+
|
|
171
|
+
await fetch("/api/enroll", {
|
|
172
|
+
method: "POST",
|
|
173
|
+
body: JSON.stringify(payload),
|
|
174
|
+
});
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
---
|
|
178
|
+
|
|
179
|
+
## 🖼️ Image Utilities
|
|
180
|
+
|
|
181
|
+
Includes helpers for common biometric image tasks:
|
|
182
|
+
|
|
183
|
+
```tsx
|
|
184
|
+
import {
|
|
185
|
+
getImageSrcForDisplay, // Adds data:image/png;base64,... header
|
|
186
|
+
normalizeImageForStorage, // Removes headers for storage
|
|
187
|
+
base64toBlob, // Convert for FormData uploads
|
|
188
|
+
} from "@giouwur/biometric-sdk";
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
---
|
|
192
|
+
|
|
193
|
+
## 📐 Exported Components & Types
|
|
194
|
+
|
|
195
|
+
### UI Primitives
|
|
196
|
+
|
|
197
|
+
- `<Button />`, `<Card />`, `<Input />`, `<Select />`
|
|
198
|
+
- `<Modal />`, `<BiometricSlot />`, `<StatusChip />`
|
|
199
|
+
|
|
200
|
+
### Types (Full TS Support)
|
|
201
|
+
|
|
202
|
+
```tsx
|
|
203
|
+
import type {
|
|
204
|
+
BiometricItem,
|
|
205
|
+
EnrollmentState,
|
|
206
|
+
BiometricState,
|
|
207
|
+
BiometricSlotProps,
|
|
208
|
+
} from "@intell/biometric-sdk";
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
---
|
|
212
|
+
|
|
213
|
+
## 📜 License
|
|
214
|
+
|
|
215
|
+
MIT © [Intelli Biometrics]
|
package/bin/init.js
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const fs = require('fs');
|
|
4
|
+
const path = require('path');
|
|
5
|
+
|
|
6
|
+
async function init() {
|
|
7
|
+
console.log('🚀 Inicializando página de prueba de @giouwur/biometric-sdk...');
|
|
8
|
+
|
|
9
|
+
const cwd = process.cwd();
|
|
10
|
+
|
|
11
|
+
// 1. Detectar directorio de destino (Next.js App Router)
|
|
12
|
+
let appDir = '';
|
|
13
|
+
if (fs.existsSync(path.join(cwd, 'src', 'app'))) {
|
|
14
|
+
appDir = path.join(cwd, 'src', 'app');
|
|
15
|
+
} else if (fs.existsSync(path.join(cwd, 'app'))) {
|
|
16
|
+
appDir = path.join(cwd, 'app');
|
|
17
|
+
} else {
|
|
18
|
+
console.error('❌ No se detectó un directorio "app" o "src/app" (Next.js App Router).');
|
|
19
|
+
console.log('Asegúrate de ejecutar este comando en la raíz de tu proyecto Next.js.');
|
|
20
|
+
process.exit(1);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const targetDir = path.join(appDir, 'sdk-test');
|
|
24
|
+
const targetFile = path.join(targetDir, 'page.tsx');
|
|
25
|
+
|
|
26
|
+
// 2. Crear carpeta si no existe
|
|
27
|
+
if (!fs.existsSync(targetDir)) {
|
|
28
|
+
fs.mkdirSync(targetDir, { recursive: true });
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// 3. Copiar template
|
|
32
|
+
const templatePath = path.join(__dirname, '..', 'templates', 'test-page.tsx');
|
|
33
|
+
|
|
34
|
+
if (!fs.existsSync(templatePath)) {
|
|
35
|
+
console.error('❌ Error interno: No se encontró el template en ' + templatePath);
|
|
36
|
+
process.exit(1);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
try {
|
|
40
|
+
const content = fs.readFileSync(templatePath, 'utf8');
|
|
41
|
+
fs.writeFileSync(targetFile, content);
|
|
42
|
+
console.log(`✅ ¡Éxito! Página creada en: ${targetFile}`);
|
|
43
|
+
console.log('\nAhora puedes visitar: http://localhost:3000/sdk-test');
|
|
44
|
+
} catch (err) {
|
|
45
|
+
console.error('❌ Error al copiar el archivo:', err.message);
|
|
46
|
+
process.exit(1);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
init();
|