biometry-sdk 1.2.2 → 1.2.4
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 +52 -77
- package/dist/biometry-sdk.esm.js +1419 -0
- package/dist/components/biometry-onboarding.d.ts +26 -1
- package/dist/components/process-video.d.ts +53 -0
- package/dist/index.d.ts +2 -0
- package/package.json +16 -5
- package/dist/components/biometry-onboarding.js +0 -233
- package/dist/index.js +0 -2
- package/dist/sdk.js +0 -179
- package/dist/sdk.test.js +0 -255
- package/dist/types.js +0 -14
package/dist/sdk.test.js
DELETED
|
@@ -1,255 +0,0 @@
|
|
|
1
|
-
import { BiometrySDK } from './sdk';
|
|
2
|
-
// Mock the fetch API globally
|
|
3
|
-
global.fetch = jest.fn();
|
|
4
|
-
describe('BiometrySDK', () => {
|
|
5
|
-
const apiKey = 'test-api-key';
|
|
6
|
-
const sdk = new BiometrySDK(apiKey);
|
|
7
|
-
afterEach(() => {
|
|
8
|
-
jest.clearAllMocks();
|
|
9
|
-
});
|
|
10
|
-
it('should throw an error if no API key is provided', () => {
|
|
11
|
-
expect(() => new BiometrySDK('')).toThrow('API Key is required to initialize the SDK.');
|
|
12
|
-
});
|
|
13
|
-
// CONSENT
|
|
14
|
-
it('should call fetch with correct headers and body when giving consent', async () => {
|
|
15
|
-
fetch.mockResolvedValueOnce({
|
|
16
|
-
ok: true,
|
|
17
|
-
json: async () => ({ is_consent_given: true, user_fullname: 'John Doe' }),
|
|
18
|
-
});
|
|
19
|
-
const result = await sdk.giveConsent(true, 'John Doe');
|
|
20
|
-
expect(fetch).toHaveBeenCalledWith('https://api.biometrysolutions.com/consent', expect.objectContaining({
|
|
21
|
-
method: 'POST',
|
|
22
|
-
headers: {
|
|
23
|
-
Authorization: `Bearer ${apiKey}`,
|
|
24
|
-
'Content-Type': 'application/json',
|
|
25
|
-
},
|
|
26
|
-
body: JSON.stringify({
|
|
27
|
-
is_consent_given: true,
|
|
28
|
-
user_fullname: 'John Doe',
|
|
29
|
-
}),
|
|
30
|
-
}));
|
|
31
|
-
expect(result).toEqual({ is_consent_given: true, user_fullname: 'John Doe', });
|
|
32
|
-
});
|
|
33
|
-
it('should throw an error if response is not ok', async () => {
|
|
34
|
-
fetch.mockResolvedValueOnce({
|
|
35
|
-
ok: false,
|
|
36
|
-
status: 400,
|
|
37
|
-
json: async () => ({ error: 'is_consent_given must be true' }),
|
|
38
|
-
});
|
|
39
|
-
await expect(sdk.giveConsent(true, 'John Doe')).rejects.toThrow('Error 400: undefined');
|
|
40
|
-
});
|
|
41
|
-
// VOICE ONBOARDING
|
|
42
|
-
it('should throw an error if user fullname is missing', async () => {
|
|
43
|
-
const audioFile = new File(['audio data'], 'audio.wav', { type: 'audio/wav' });
|
|
44
|
-
await expect(sdk.onboardVoice(audioFile, '', 'uniqueId', 'phrase')).rejects.toThrowError('User fullname is required.');
|
|
45
|
-
});
|
|
46
|
-
it('should throw an error if unique ID is missing', async () => {
|
|
47
|
-
const audioFile = new File(['audio data'], 'audio.wav', { type: 'audio/wav' });
|
|
48
|
-
await expect(sdk.onboardVoice(audioFile, 'User Name', '', 'phrase')).rejects.toThrowError('Unique ID is required.');
|
|
49
|
-
});
|
|
50
|
-
it('should throw an error if phrase is missing', async () => {
|
|
51
|
-
const audioFile = new File(['audio data'], 'audio.wav', { type: 'audio/wav' });
|
|
52
|
-
await expect(sdk.onboardVoice(audioFile, 'User Name', 'uniqueId', '')).rejects.toThrowError('Phrase is required.');
|
|
53
|
-
});
|
|
54
|
-
it('should throw an error if audio file is missing', async () => {
|
|
55
|
-
await expect(sdk.onboardVoice(null, 'User Name', 'uniqueId', 'phrase')).rejects.toThrowError('Audio file is required.');
|
|
56
|
-
});
|
|
57
|
-
it('should successfully onboard voice and return the response', async () => {
|
|
58
|
-
const mockResponse = {
|
|
59
|
-
status: 'good',
|
|
60
|
-
};
|
|
61
|
-
fetch.mockResolvedValueOnce({
|
|
62
|
-
ok: true,
|
|
63
|
-
json: async () => mockResponse,
|
|
64
|
-
});
|
|
65
|
-
const audioFile = new File(['audio data'], 'audio.wav', { type: 'audio/wav' });
|
|
66
|
-
const userFullName = 'User Name';
|
|
67
|
-
const uniqueId = 'uniqueId';
|
|
68
|
-
const phrase = 'phrase';
|
|
69
|
-
const formDataSpy = jest.spyOn(FormData.prototype, 'append');
|
|
70
|
-
const result = await sdk.onboardVoice(audioFile, userFullName, uniqueId, phrase);
|
|
71
|
-
expect(formDataSpy).toHaveBeenCalledWith('unique_id', uniqueId);
|
|
72
|
-
expect(formDataSpy).toHaveBeenCalledWith('phrase', phrase);
|
|
73
|
-
expect(formDataSpy).toHaveBeenCalledWith('voice', audioFile);
|
|
74
|
-
expect(fetch).toHaveBeenCalledWith('https://api.biometrysolutions.com/api-gateway/onboard/voice', expect.objectContaining({
|
|
75
|
-
method: 'POST',
|
|
76
|
-
headers: {
|
|
77
|
-
'Authorization': `Bearer ${apiKey}`,
|
|
78
|
-
'X-User-Fullname': userFullName,
|
|
79
|
-
},
|
|
80
|
-
body: expect.any(FormData)
|
|
81
|
-
}));
|
|
82
|
-
expect(result).toEqual(mockResponse);
|
|
83
|
-
});
|
|
84
|
-
// FACE ONBOARDING
|
|
85
|
-
it('should throw an error if user fullname is missing', async () => {
|
|
86
|
-
const imageFile = new File(['image data'], 'image.jpg', { type: 'image/jpeg' });
|
|
87
|
-
await expect(sdk.onboardFace(imageFile, '')).rejects.toThrowError('User fullname is required.');
|
|
88
|
-
});
|
|
89
|
-
it('should throw an error if image file is missing', async () => {
|
|
90
|
-
await expect(sdk.onboardFace(null, 'User Name')).rejects.toThrowError('Face image is required.');
|
|
91
|
-
});
|
|
92
|
-
it('should successfully onboard face and return the response', async () => {
|
|
93
|
-
const mockResponse = {
|
|
94
|
-
code: 200,
|
|
95
|
-
description: 'Face onboarded successfully',
|
|
96
|
-
};
|
|
97
|
-
fetch.mockResolvedValueOnce({
|
|
98
|
-
ok: true,
|
|
99
|
-
json: async () => mockResponse,
|
|
100
|
-
});
|
|
101
|
-
const imageFile = new File(['image data'], 'image.jpg', { type: 'image/jpeg' });
|
|
102
|
-
const userFullName = 'User Name';
|
|
103
|
-
const formDataSpy = jest.spyOn(FormData.prototype, 'append');
|
|
104
|
-
const result = await sdk.onboardFace(imageFile, userFullName);
|
|
105
|
-
expect(formDataSpy).toHaveBeenCalledWith('face', imageFile);
|
|
106
|
-
expect(fetch).toHaveBeenCalledWith('https://api.biometrysolutions.com/api-gateway/onboard/face', expect.objectContaining({
|
|
107
|
-
method: 'POST',
|
|
108
|
-
headers: {
|
|
109
|
-
'Authorization': `Bearer ${apiKey}`,
|
|
110
|
-
'X-User-Fullname': userFullName,
|
|
111
|
-
},
|
|
112
|
-
body: expect.any(FormData)
|
|
113
|
-
}));
|
|
114
|
-
expect(result).toEqual(mockResponse);
|
|
115
|
-
});
|
|
116
|
-
// FACE MATCH
|
|
117
|
-
it('should throw an error if face image is missing', async () => {
|
|
118
|
-
await expect(sdk.matchFaces(null, null)).rejects.toThrowError('Face image is required.');
|
|
119
|
-
});
|
|
120
|
-
it('should throw an error if video file is missing', async () => {
|
|
121
|
-
const imageFile = new File(['image data'], 'image.jpg', { type: 'image/jpeg' });
|
|
122
|
-
await expect(sdk.matchFaces(imageFile, null)).rejects.toThrowError('Video is required.');
|
|
123
|
-
});
|
|
124
|
-
it('should successfully match faces and return the response', async () => {
|
|
125
|
-
const mockResponse = {
|
|
126
|
-
code: 200,
|
|
127
|
-
result: 1,
|
|
128
|
-
description: 'Matched',
|
|
129
|
-
anchor: {
|
|
130
|
-
code: 200,
|
|
131
|
-
description: 'Anchor face',
|
|
132
|
-
},
|
|
133
|
-
target: {
|
|
134
|
-
code: 200,
|
|
135
|
-
description: 'Target face',
|
|
136
|
-
},
|
|
137
|
-
};
|
|
138
|
-
fetch.mockResolvedValueOnce({
|
|
139
|
-
ok: true,
|
|
140
|
-
json: async () => mockResponse,
|
|
141
|
-
});
|
|
142
|
-
const imageFile = new File(['image data'], 'image.jpg', { type: 'image/jpeg' });
|
|
143
|
-
const videoFile = new File(['video data'], 'video.mp4', { type: 'video/mp4' });
|
|
144
|
-
const formDataSpy = jest.spyOn(FormData.prototype, 'append');
|
|
145
|
-
const result = await sdk.matchFaces(imageFile, videoFile);
|
|
146
|
-
expect(formDataSpy).toHaveBeenCalledWith('video', videoFile);
|
|
147
|
-
expect(formDataSpy).toHaveBeenCalledWith('image', imageFile);
|
|
148
|
-
expect(fetch).toHaveBeenCalledWith('https://api.biometrysolutions.com/api-gateway/match-faces', expect.objectContaining({
|
|
149
|
-
method: 'POST',
|
|
150
|
-
headers: {
|
|
151
|
-
'Authorization': `Bearer ${apiKey}`,
|
|
152
|
-
},
|
|
153
|
-
body: expect.any(FormData)
|
|
154
|
-
}));
|
|
155
|
-
expect(result).toEqual(mockResponse);
|
|
156
|
-
});
|
|
157
|
-
it('should successfully match faces if processVideoRequestId is provided', async () => {
|
|
158
|
-
const mockResponse = {
|
|
159
|
-
code: 200,
|
|
160
|
-
result: 1,
|
|
161
|
-
description: 'Matched',
|
|
162
|
-
anchor: {
|
|
163
|
-
code: 200,
|
|
164
|
-
description: 'Anchor face',
|
|
165
|
-
},
|
|
166
|
-
target: {
|
|
167
|
-
code: 200,
|
|
168
|
-
description: 'Target face',
|
|
169
|
-
},
|
|
170
|
-
};
|
|
171
|
-
fetch.mockResolvedValueOnce({
|
|
172
|
-
ok: true,
|
|
173
|
-
json: async () => mockResponse,
|
|
174
|
-
});
|
|
175
|
-
const imageFile = new File(['image data'], 'image.jpg', { type: 'image/jpeg' });
|
|
176
|
-
const formDataSpy = jest.spyOn(FormData.prototype, 'append');
|
|
177
|
-
const result = await sdk.matchFaces(imageFile, undefined, 'User Name', 'processVideoRequestId', true);
|
|
178
|
-
expect(formDataSpy).toHaveBeenCalledWith('image', imageFile);
|
|
179
|
-
expect(fetch).toHaveBeenCalledWith('https://api.biometrysolutions.com/api-gateway/match-faces', expect.objectContaining({
|
|
180
|
-
method: 'POST',
|
|
181
|
-
headers: {
|
|
182
|
-
'Authorization': `Bearer ${apiKey}`,
|
|
183
|
-
'X-User-Fullname': 'User Name',
|
|
184
|
-
'X-Request-Id': 'processVideoRequestId',
|
|
185
|
-
'X-Use-Prefilled-Video': 'true',
|
|
186
|
-
},
|
|
187
|
-
body: expect.any(FormData)
|
|
188
|
-
}));
|
|
189
|
-
expect(result).toEqual(mockResponse);
|
|
190
|
-
});
|
|
191
|
-
// PROCESS VIDEO
|
|
192
|
-
it('should throw an error if video file is missing', async () => {
|
|
193
|
-
await expect(sdk.processVideo(null, 'phrase')).rejects.toThrowError('Video is required.');
|
|
194
|
-
});
|
|
195
|
-
it('should throw an error if phrase is missing', async () => {
|
|
196
|
-
const videoFile = new File(['video data'], 'video.mp4', { type: 'video/mp4' });
|
|
197
|
-
await expect(sdk.processVideo(videoFile, '')).rejects.toThrowError('Phrase is required.');
|
|
198
|
-
});
|
|
199
|
-
it('should successfully process video and return the response', async () => {
|
|
200
|
-
const mockResponse = {
|
|
201
|
-
data: {
|
|
202
|
-
'Active Speaker Detection': {
|
|
203
|
-
code: 0,
|
|
204
|
-
description: 'Successful check',
|
|
205
|
-
result: 90.00,
|
|
206
|
-
},
|
|
207
|
-
'Face Liveness Detection': {
|
|
208
|
-
code: 0,
|
|
209
|
-
description: 'Successful check',
|
|
210
|
-
result: true,
|
|
211
|
-
},
|
|
212
|
-
'Face Recognition': {
|
|
213
|
-
code: 0,
|
|
214
|
-
description: 'Successful check',
|
|
215
|
-
},
|
|
216
|
-
'Visual Speech Recognition': {
|
|
217
|
-
code: 0,
|
|
218
|
-
description: 'Successful check',
|
|
219
|
-
result: 'ONE TWO THREE FOUR FIVE SIX SEVEN EIGHT',
|
|
220
|
-
},
|
|
221
|
-
'Voice Recognition': {
|
|
222
|
-
status: 'good',
|
|
223
|
-
id: '123',
|
|
224
|
-
score: 0.99,
|
|
225
|
-
imposter_prob: 0.01,
|
|
226
|
-
log_odds: '1.0',
|
|
227
|
-
},
|
|
228
|
-
},
|
|
229
|
-
result_conditions: {
|
|
230
|
-
failed_conditions: [],
|
|
231
|
-
failed_refer_conditions: [],
|
|
232
|
-
status: 'pass',
|
|
233
|
-
},
|
|
234
|
-
message: 'video processed successfully',
|
|
235
|
-
};
|
|
236
|
-
fetch.mockResolvedValueOnce({
|
|
237
|
-
ok: true,
|
|
238
|
-
json: async () => mockResponse,
|
|
239
|
-
});
|
|
240
|
-
const videoFile = new File(['video data'], 'video.mp4', { type: 'video/mp4' });
|
|
241
|
-
const phrase = 'ONE TWO THREE FOUR FIVE SIX SEVEN EIGHT';
|
|
242
|
-
const formDataSpy = jest.spyOn(FormData.prototype, 'append');
|
|
243
|
-
const result = await sdk.processVideo(videoFile, phrase);
|
|
244
|
-
expect(formDataSpy).toHaveBeenCalledWith('video', videoFile);
|
|
245
|
-
expect(formDataSpy).toHaveBeenCalledWith('phrase', phrase);
|
|
246
|
-
expect(fetch).toHaveBeenCalledWith('https://api.biometrysolutions.com/api-gateway/process-video', expect.objectContaining({
|
|
247
|
-
method: 'POST',
|
|
248
|
-
headers: {
|
|
249
|
-
'Authorization': `Bearer ${apiKey}`,
|
|
250
|
-
},
|
|
251
|
-
body: expect.any(FormData)
|
|
252
|
-
}));
|
|
253
|
-
expect(result).toEqual(mockResponse);
|
|
254
|
-
});
|
|
255
|
-
});
|
package/dist/types.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
export var BiometryAttributes;
|
|
2
|
-
(function (BiometryAttributes) {
|
|
3
|
-
BiometryAttributes["ApiKey"] = "api-key";
|
|
4
|
-
BiometryAttributes["UserFullname"] = "user-fullname";
|
|
5
|
-
})(BiometryAttributes || (BiometryAttributes = {}));
|
|
6
|
-
export var BiometryOnboardingState;
|
|
7
|
-
(function (BiometryOnboardingState) {
|
|
8
|
-
BiometryOnboardingState["Loading"] = "loading";
|
|
9
|
-
BiometryOnboardingState["Success"] = "success";
|
|
10
|
-
BiometryOnboardingState["ErrorNoFace"] = "error-no-face";
|
|
11
|
-
BiometryOnboardingState["ErrorMultipleFaces"] = "error-multiple-faces";
|
|
12
|
-
BiometryOnboardingState["ErrorNotCentered"] = "error-not-centered";
|
|
13
|
-
BiometryOnboardingState["ErrorOther"] = "error-other";
|
|
14
|
-
})(BiometryOnboardingState || (BiometryOnboardingState = {}));
|