@supernick135/face-scanner-client
Version:
Node.js client library for ZKTeco face scanning devices integration with comprehensive API support
222 lines (178 loc) • 6.7 kB
JavaScript
/**
* Biometric Client for Face Scanner API
* Specialized client for biometric data management
*/
const FaceScannerClient = require('./FaceScannerClient');
class BiometricClient extends FaceScannerClient {
constructor(options = {}) {
super(options);
}
// User management
async getUsers(options = {}) {
return this.getBiometricUsers(options);
}
async getUser(userId) {
return this.getBiometricUser(userId);
}
async createUser(userData) {
return this.http.post('/biometric/users', userData);
}
async updateUser(userId, userData) {
return this.http.put(`/biometric/users/${userId}`, userData);
}
async deleteUser(userId) {
return this.http.delete(`/biometric/users/${userId}`);
}
// Biometric templates
async getUserTemplates(userId) {
return this.http.get(`/biometric/users/${userId}/templates`);
}
async addUserTemplate(userId, templateData) {
return this.http.post(`/biometric/users/${userId}/templates`, templateData);
}
async deleteUserTemplate(userId, templateId) {
return this.http.delete(`/biometric/users/${userId}/templates/${templateId}`);
}
// Face photos
async getUserPhotos(userId) {
return this.http.get(`/biometric/users/${userId}/photos`);
}
async addUserPhoto(userId, photoData) {
const formData = new FormData();
if (Buffer.isBuffer(photoData)) {
formData.append('photo', photoData, 'photo.jpg');
} else if (typeof photoData === 'string') {
formData.append('photoPath', photoData);
} else {
formData.append('photo', photoData);
}
return this.http.post(`/biometric/users/${userId}/photos`, formData, {
headers: {
'Content-Type': 'multipart/form-data'
}
});
}
async deleteUserPhoto(userId, photoId) {
return this.http.delete(`/biometric/users/${userId}/photos/${photoId}`);
}
// Synchronization
async syncDevice(deviceId, options = {}) {
return this.syncBiometricData(deviceId);
}
async syncAllDevices() {
const devices = await this.getDevices();
const results = await Promise.allSettled(
devices.map(device => this.syncBiometricData(device.id))
);
return results.map((result, index) => ({
deviceId: devices[index].id,
success: result.status === 'fulfilled',
data: result.status === 'fulfilled' ? result.value : null,
error: result.status === 'rejected' ? result.reason.message : null
}));
}
async getSyncStatus(deviceId) {
return this.http.get(`/biometric/sync/${deviceId}/status`);
}
// Bulk operations
async bulkCreateUsers(users) {
return this.http.post('/biometric/users/bulk', { users });
}
async bulkUpdateUsers(updates) {
return this.http.put('/biometric/users/bulk', { updates });
}
async bulkDeleteUsers(userIds) {
return this.http.delete('/biometric/users/bulk', {
data: { userIds }
});
}
// Search and filtering
async searchUsers(query, options = {}) {
const params = new URLSearchParams();
params.append('q', query);
if (options.limit) params.append('limit', options.limit);
if (options.offset) params.append('offset', options.offset);
return this.http.get(`/biometric/users/search?${params}`);
}
async getUsersByGroup(groupId, options = {}) {
const params = new URLSearchParams();
if (options.limit) params.append('limit', options.limit);
if (options.offset) params.append('offset', options.offset);
return this.http.get(`/biometric/groups/${groupId}/users?${params}`);
}
// Statistics and analytics
async getBiometricStats() {
return this.http.get('/biometric/stats');
}
async getUserStats(userId) {
return this.http.get(`/biometric/users/${userId}/stats`);
}
async getTemplateQuality(userId, templateId) {
return this.http.get(`/biometric/users/${userId}/templates/${templateId}/quality`);
}
// Import/Export
async exportUsers(options = {}) {
const params = new URLSearchParams();
if (options.format) params.append('format', options.format); // csv, json, xlsx
if (options.includePhotos) params.append('includePhotos', options.includePhotos);
if (options.includeTemplates) params.append('includeTemplates', options.includeTemplates);
return this.http.get(`/biometric/users/export?${params}`);
}
async importUsers(userData, options = {}) {
return this.http.post('/biometric/users/import', userData, {
params: options
});
}
// Enrollment workflows
async startEnrollment(userId, deviceId) {
return this.http.post('/biometric/enrollment/start', {
userId,
deviceId
});
}
async getEnrollmentStatus(enrollmentId) {
return this.http.get(`/biometric/enrollment/${enrollmentId}/status`);
}
async completeEnrollment(enrollmentId, templateData) {
return this.http.post(`/biometric/enrollment/${enrollmentId}/complete`, templateData);
}
async cancelEnrollment(enrollmentId) {
return this.http.post(`/biometric/enrollment/${enrollmentId}/cancel`);
}
// Verification and identification
async verifyUser(userId, templateData) {
return this.http.post('/biometric/verify', {
userId,
template: templateData
});
}
async identifyUser(templateData, options = {}) {
return this.http.post('/biometric/identify', {
template: templateData,
threshold: options.threshold || 0.8,
maxResults: options.maxResults || 10
});
}
// Access control integration
async getUserAccessRights(userId) {
return this.http.get(`/biometric/users/${userId}/access`);
}
async updateUserAccessRights(userId, accessRights) {
return this.http.put(`/biometric/users/${userId}/access`, accessRights);
}
// Utilities
async validateUserData(userData) {
return this.http.post('/biometric/users/validate', userData);
}
async checkDuplicates(userData) {
return this.http.post('/biometric/users/check-duplicates', userData);
}
async getUserActivity(userId, options = {}) {
const params = new URLSearchParams();
if (options.startDate) params.append('startDate', options.startDate);
if (options.endDate) params.append('endDate', options.endDate);
if (options.limit) params.append('limit', options.limit);
return this.http.get(`/biometric/users/${userId}/activity?${params}`);
}
}
module.exports = BiometricClient;