biometry-sdk 1.2.2 → 1.2.3
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.cjs.js +1423 -0
- package/dist/biometry-sdk.esm.js +1419 -0
- package/dist/biometry-sdk.umd.js +1429 -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 -6
- 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
|
@@ -1 +1,26 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export declare class BiometryOnboarding extends HTMLElement {
|
|
2
|
+
private readonly shadow;
|
|
3
|
+
private sdk;
|
|
4
|
+
private videoElement;
|
|
5
|
+
private canvasElement;
|
|
6
|
+
private captureButton;
|
|
7
|
+
private resultCode?;
|
|
8
|
+
private description?;
|
|
9
|
+
constructor();
|
|
10
|
+
static get observedAttributes(): string[];
|
|
11
|
+
get apiKey(): string | null;
|
|
12
|
+
set apiKey(value: string | null);
|
|
13
|
+
get userFullname(): string | null;
|
|
14
|
+
set userFullname(value: string | null);
|
|
15
|
+
attributeChangedCallback(name: string, oldValue: string | null, newValue: string | null): void;
|
|
16
|
+
connectedCallback(): void;
|
|
17
|
+
disconnectedCallback(): void;
|
|
18
|
+
validateAttributes(): void;
|
|
19
|
+
init(): void;
|
|
20
|
+
private cleanup;
|
|
21
|
+
private initializeSDK;
|
|
22
|
+
private toggleState;
|
|
23
|
+
private attachSlotListeners;
|
|
24
|
+
private setupCamera;
|
|
25
|
+
private capturePhoto;
|
|
26
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
export declare class ProcessVideoComponent extends HTMLElement {
|
|
2
|
+
private sdk;
|
|
3
|
+
private apiKey;
|
|
4
|
+
private phrase;
|
|
5
|
+
private previewStream;
|
|
6
|
+
private recordedChunks;
|
|
7
|
+
private mediaRecorder;
|
|
8
|
+
private videoFile;
|
|
9
|
+
private startTime;
|
|
10
|
+
private timerInterval;
|
|
11
|
+
private recordingTimeout;
|
|
12
|
+
private videoElement;
|
|
13
|
+
private fileInput;
|
|
14
|
+
private recordButton;
|
|
15
|
+
private stopButton;
|
|
16
|
+
private submitButton;
|
|
17
|
+
private errorState;
|
|
18
|
+
private timeLimit;
|
|
19
|
+
constructor();
|
|
20
|
+
private initializeSDK;
|
|
21
|
+
connectedCallback(): void;
|
|
22
|
+
disconnectedCallback(): void;
|
|
23
|
+
attributeChangedCallback(name: string, oldValue: string | null, newValue: string | null): void;
|
|
24
|
+
private generateDefaultPhrase;
|
|
25
|
+
initializeUI(): void;
|
|
26
|
+
private attachSlotListeners;
|
|
27
|
+
private getSlotElement;
|
|
28
|
+
replaceSlotContent(slotName: string, content: string | HTMLElement): void;
|
|
29
|
+
removeSlotListener(slotName: string, event: string, callback: EventListener): void;
|
|
30
|
+
private toggleState;
|
|
31
|
+
private convertPhraseToWords;
|
|
32
|
+
private setupPreview;
|
|
33
|
+
private startTimer;
|
|
34
|
+
private stopTimer;
|
|
35
|
+
startRecording(): Promise<void>;
|
|
36
|
+
stopRecording(): void;
|
|
37
|
+
private onStopMediaRecorder;
|
|
38
|
+
private handleFileUpload;
|
|
39
|
+
handleSubmit(): Promise<void>;
|
|
40
|
+
static get observedAttributes(): string[];
|
|
41
|
+
get userFullname(): string | null;
|
|
42
|
+
set userFullname(value: string | null);
|
|
43
|
+
get isRecording(): boolean;
|
|
44
|
+
get currentPhrase(): string;
|
|
45
|
+
get videoDuration(): number | null;
|
|
46
|
+
get currentFile(): File | null;
|
|
47
|
+
get currentStream(): MediaStream | null;
|
|
48
|
+
set sdkInstance(newSdk: any);
|
|
49
|
+
get videoElementRef(): HTMLVideoElement;
|
|
50
|
+
get fileInputRef(): HTMLInputElement;
|
|
51
|
+
get recordingTimeLimit(): number;
|
|
52
|
+
set recordingTimeLimit(value: number);
|
|
53
|
+
}
|
package/dist/index.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,21 +1,31 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "biometry-sdk",
|
|
3
|
-
"version": "1.2.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "1.2.3",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "dist/biometry-sdk.cjs.js",
|
|
6
|
+
"module": "dist/biometry-sdk.esm.js",
|
|
7
|
+
"browser": "dist/biometry-sdk.umd.js",
|
|
6
8
|
"files": [
|
|
7
9
|
"dist/**/*",
|
|
8
10
|
"README.md"
|
|
9
11
|
],
|
|
10
12
|
"scripts": {
|
|
11
|
-
"build": "
|
|
13
|
+
"build": "rollup -c",
|
|
12
14
|
"test": "jest"
|
|
13
15
|
},
|
|
14
16
|
"devDependencies": {
|
|
17
|
+
"@rollup/plugin-commonjs": "^28.0.2",
|
|
18
|
+
"@rollup/plugin-node-resolve": "^16.0.0",
|
|
19
|
+
"@rollup/plugin-typescript": "^12.1.2",
|
|
15
20
|
"@types/jest": "^29.5.14",
|
|
16
21
|
"jest": "^29.7.0",
|
|
22
|
+
"rollup": "^4.34.0",
|
|
17
23
|
"ts-jest": "^29.2.5",
|
|
18
|
-
"
|
|
24
|
+
"tslib": "^2.8.1",
|
|
25
|
+
"typescript": "^5.7.3"
|
|
19
26
|
},
|
|
20
|
-
"license": "MIT"
|
|
27
|
+
"license": "MIT",
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"fix-webm-duration": "^1.0.6"
|
|
30
|
+
}
|
|
21
31
|
}
|
|
@@ -1,233 +0,0 @@
|
|
|
1
|
-
import { BiometrySDK } from "../sdk.js";
|
|
2
|
-
import { BiometryAttributes, BiometryOnboardingState } from "../types.js";
|
|
3
|
-
class BiometryOnboarding extends HTMLElement {
|
|
4
|
-
constructor() {
|
|
5
|
-
super();
|
|
6
|
-
this.videoElement = null;
|
|
7
|
-
this.canvasElement = null;
|
|
8
|
-
this.captureButton = null;
|
|
9
|
-
this.shadow = this.attachShadow({ mode: "open" });
|
|
10
|
-
this.sdk = null;
|
|
11
|
-
this.toggleState = this.toggleState.bind(this);
|
|
12
|
-
this.capturePhoto = this.capturePhoto.bind(this);
|
|
13
|
-
}
|
|
14
|
-
static get observedAttributes() {
|
|
15
|
-
return Object.values(BiometryAttributes);
|
|
16
|
-
}
|
|
17
|
-
get apiKey() {
|
|
18
|
-
return this.getAttribute("api-key");
|
|
19
|
-
}
|
|
20
|
-
set apiKey(value) {
|
|
21
|
-
if (value) {
|
|
22
|
-
this.setAttribute("api-key", value);
|
|
23
|
-
}
|
|
24
|
-
else {
|
|
25
|
-
this.removeAttribute("api-key");
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
get userFullname() {
|
|
29
|
-
return this.getAttribute("user-fullname");
|
|
30
|
-
}
|
|
31
|
-
set userFullname(value) {
|
|
32
|
-
if (value) {
|
|
33
|
-
this.setAttribute("user-fullname", value);
|
|
34
|
-
}
|
|
35
|
-
else {
|
|
36
|
-
this.removeAttribute("user-fullname");
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
attributeChangedCallback(name, oldValue, newValue) {
|
|
40
|
-
if (name === "api-key" || name === "user-fullname") {
|
|
41
|
-
this.validateAttributes();
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
connectedCallback() {
|
|
45
|
-
this.validateAttributes();
|
|
46
|
-
this.init();
|
|
47
|
-
}
|
|
48
|
-
disconnectedCallback() {
|
|
49
|
-
this.cleanup();
|
|
50
|
-
}
|
|
51
|
-
validateAttributes() {
|
|
52
|
-
if (!this.apiKey) {
|
|
53
|
-
console.error("API key is required.");
|
|
54
|
-
this.toggleState(BiometryOnboardingState.ErrorOther);
|
|
55
|
-
return;
|
|
56
|
-
}
|
|
57
|
-
if (!this.userFullname) {
|
|
58
|
-
console.error("User fullname is required.");
|
|
59
|
-
this.toggleState(BiometryOnboardingState.ErrorOther);
|
|
60
|
-
return;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
init() {
|
|
64
|
-
this.shadow.innerHTML = `
|
|
65
|
-
<style>
|
|
66
|
-
.wrapper {
|
|
67
|
-
position: relative;
|
|
68
|
-
}
|
|
69
|
-
video {
|
|
70
|
-
transform: scaleX(-1); /* Flip video for preview */
|
|
71
|
-
max-width: 100%;
|
|
72
|
-
border-radius: var(--border-radius, 8px);
|
|
73
|
-
}
|
|
74
|
-
canvas {
|
|
75
|
-
display: none;
|
|
76
|
-
}
|
|
77
|
-
</style>
|
|
78
|
-
<div class="wrapper">
|
|
79
|
-
<slot name="video">
|
|
80
|
-
<video id="video" autoplay playsinline></video>
|
|
81
|
-
</slot>
|
|
82
|
-
<slot name="canvas">
|
|
83
|
-
<canvas id="canvas" style="display: none;"></canvas>
|
|
84
|
-
</slot>
|
|
85
|
-
<slot name="button">
|
|
86
|
-
<button id="button">Capture Photo</button>
|
|
87
|
-
</slot>
|
|
88
|
-
<div class="status">
|
|
89
|
-
<slot name="loading" class="loading"></slot>
|
|
90
|
-
<slot name="success" class="success"></slot>
|
|
91
|
-
<slot name="error-no-face" class="error-no-face"></slot>
|
|
92
|
-
<slot name="error-multiple-faces" class="error-multiple-faces"></slot>
|
|
93
|
-
<slot name="error-not-centered" class="error-not-centered"></slot>
|
|
94
|
-
<slot name="error-other" class="error-other"></slot>
|
|
95
|
-
</div>
|
|
96
|
-
</div>
|
|
97
|
-
`;
|
|
98
|
-
this.initializeSDK();
|
|
99
|
-
this.attachSlotListeners();
|
|
100
|
-
this.setupCamera();
|
|
101
|
-
this.toggleState("");
|
|
102
|
-
}
|
|
103
|
-
cleanup() {
|
|
104
|
-
var _a;
|
|
105
|
-
if ((_a = this.videoElement) === null || _a === void 0 ? void 0 : _a.srcObject) {
|
|
106
|
-
const tracks = this.videoElement.srcObject.getTracks();
|
|
107
|
-
tracks.forEach((track) => track.stop());
|
|
108
|
-
}
|
|
109
|
-
if (this.videoElement) {
|
|
110
|
-
this.videoElement.srcObject = null;
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
initializeSDK() {
|
|
114
|
-
if (this.apiKey) {
|
|
115
|
-
this.sdk = new BiometrySDK(this.apiKey);
|
|
116
|
-
}
|
|
117
|
-
else {
|
|
118
|
-
this.toggleState(BiometryOnboardingState.ErrorOther);
|
|
119
|
-
console.error("API key is required to initialize the SDK.");
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
toggleState(state) {
|
|
123
|
-
const slots = [
|
|
124
|
-
BiometryOnboardingState.Loading,
|
|
125
|
-
BiometryOnboardingState.Success,
|
|
126
|
-
BiometryOnboardingState.ErrorNoFace,
|
|
127
|
-
BiometryOnboardingState.ErrorMultipleFaces,
|
|
128
|
-
BiometryOnboardingState.ErrorNotCentered,
|
|
129
|
-
BiometryOnboardingState.ErrorOther,
|
|
130
|
-
];
|
|
131
|
-
slots.forEach((slotName) => {
|
|
132
|
-
const slot = this.shadow.querySelector(`slot[name="${slotName}"]`);
|
|
133
|
-
if (slot) {
|
|
134
|
-
slot.style.display = slotName === state ? "block" : "none";
|
|
135
|
-
}
|
|
136
|
-
});
|
|
137
|
-
}
|
|
138
|
-
attachSlotListeners() {
|
|
139
|
-
const videoSlot = this.shadow.querySelector('slot[name="video"]');
|
|
140
|
-
const canvasSlot = this.shadow.querySelector('slot[name="canvas"]');
|
|
141
|
-
const buttonSlot = this.shadow.querySelector('slot[name="button"]');
|
|
142
|
-
const assignedVideoElements = videoSlot.assignedElements();
|
|
143
|
-
this.videoElement = (assignedVideoElements.length > 0 ? assignedVideoElements[0] : null) || this.shadow.querySelector("#video");
|
|
144
|
-
const assignedCanvasElements = canvasSlot.assignedElements();
|
|
145
|
-
this.canvasElement = (assignedCanvasElements.length > 0 ? assignedCanvasElements[0] : null) || this.shadow.querySelector("#canvas");
|
|
146
|
-
const assignedButtonElements = buttonSlot.assignedElements();
|
|
147
|
-
this.captureButton = (assignedButtonElements.length > 0 ? assignedButtonElements[0] : null) || this.shadow.querySelector("#button");
|
|
148
|
-
if (!this.videoElement) {
|
|
149
|
-
console.error("Video element is missing.");
|
|
150
|
-
return;
|
|
151
|
-
}
|
|
152
|
-
if (!this.captureButton) {
|
|
153
|
-
console.error("Capture button is missing.");
|
|
154
|
-
return;
|
|
155
|
-
}
|
|
156
|
-
else {
|
|
157
|
-
this.captureButton.addEventListener("click", this.capturePhoto);
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
setupCamera() {
|
|
161
|
-
if (!this.videoElement) {
|
|
162
|
-
console.error("Video element is missing.");
|
|
163
|
-
return;
|
|
164
|
-
}
|
|
165
|
-
navigator.mediaDevices
|
|
166
|
-
.getUserMedia({ video: true })
|
|
167
|
-
.then((stream) => {
|
|
168
|
-
this.videoElement.srcObject = stream;
|
|
169
|
-
})
|
|
170
|
-
.catch((error) => {
|
|
171
|
-
console.error("Error accessing camera:", error);
|
|
172
|
-
});
|
|
173
|
-
}
|
|
174
|
-
async capturePhoto() {
|
|
175
|
-
try {
|
|
176
|
-
if (!this.videoElement || !this.canvasElement || !this.sdk) {
|
|
177
|
-
console.error("Essential elements or SDK are not initialized.");
|
|
178
|
-
return;
|
|
179
|
-
}
|
|
180
|
-
const context = this.canvasElement.getContext("2d");
|
|
181
|
-
this.canvasElement.width = this.videoElement.videoWidth;
|
|
182
|
-
this.canvasElement.height = this.videoElement.videoHeight;
|
|
183
|
-
context.drawImage(this.videoElement, 0, 0, this.canvasElement.width, this.canvasElement.height);
|
|
184
|
-
this.toggleState("loading");
|
|
185
|
-
this.canvasElement.toBlob(async (blob) => {
|
|
186
|
-
try {
|
|
187
|
-
if (!blob) {
|
|
188
|
-
console.error("Failed to capture photo.");
|
|
189
|
-
this.toggleState(BiometryOnboardingState.ErrorOther);
|
|
190
|
-
return;
|
|
191
|
-
}
|
|
192
|
-
const file = new File([blob], "onboard-face.jpg", { type: "image/jpeg" });
|
|
193
|
-
try {
|
|
194
|
-
const response = await this.sdk.onboardFace(file, this.userFullname);
|
|
195
|
-
const result = response.data.onboard_result;
|
|
196
|
-
this.resultCode = result === null || result === void 0 ? void 0 : result.code;
|
|
197
|
-
this.description = (result === null || result === void 0 ? void 0 : result.description) || "Unknown error occurred.";
|
|
198
|
-
switch (this.resultCode) {
|
|
199
|
-
case 0:
|
|
200
|
-
this.toggleState(BiometryOnboardingState.Success);
|
|
201
|
-
break;
|
|
202
|
-
case 1:
|
|
203
|
-
this.toggleState(BiometryOnboardingState.ErrorNoFace);
|
|
204
|
-
break;
|
|
205
|
-
case 2:
|
|
206
|
-
this.toggleState(BiometryOnboardingState.ErrorMultipleFaces);
|
|
207
|
-
break;
|
|
208
|
-
case 3:
|
|
209
|
-
this.toggleState(BiometryOnboardingState.ErrorNotCentered);
|
|
210
|
-
break;
|
|
211
|
-
default:
|
|
212
|
-
this.toggleState(BiometryOnboardingState.ErrorOther);
|
|
213
|
-
}
|
|
214
|
-
console.log("Onboarding result:", result);
|
|
215
|
-
}
|
|
216
|
-
catch (error) {
|
|
217
|
-
console.error("Error onboarding face:", error);
|
|
218
|
-
this.toggleState(BiometryOnboardingState.ErrorOther);
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
catch (error) {
|
|
222
|
-
console.error("Error in toBlob callback:", error);
|
|
223
|
-
this.toggleState(BiometryOnboardingState.ErrorOther);
|
|
224
|
-
}
|
|
225
|
-
}, "image/jpeg");
|
|
226
|
-
}
|
|
227
|
-
catch (error) {
|
|
228
|
-
console.error("Error capturing photo:", error);
|
|
229
|
-
this.toggleState(BiometryOnboardingState.ErrorOther);
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
customElements.define("biometry-onboarding", BiometryOnboarding);
|
package/dist/index.js
DELETED
package/dist/sdk.js
DELETED
|
@@ -1,179 +0,0 @@
|
|
|
1
|
-
export class BiometrySDK {
|
|
2
|
-
constructor(apiKey) {
|
|
3
|
-
if (!apiKey) {
|
|
4
|
-
throw new Error('API Key is required to initialize the SDK.');
|
|
5
|
-
}
|
|
6
|
-
this.apiKey = apiKey;
|
|
7
|
-
}
|
|
8
|
-
async request(path, method, body, headers) {
|
|
9
|
-
const defaultHeaders = {
|
|
10
|
-
Authorization: `Bearer ${this.apiKey}`,
|
|
11
|
-
};
|
|
12
|
-
const requestHeaders = Object.assign(Object.assign({}, defaultHeaders), headers);
|
|
13
|
-
if (body && !(body instanceof FormData)) {
|
|
14
|
-
requestHeaders['Content-Type'] = 'application/json';
|
|
15
|
-
body = JSON.stringify(body);
|
|
16
|
-
}
|
|
17
|
-
const response = await fetch(`${BiometrySDK.BASE_URL}${path}`, {
|
|
18
|
-
method,
|
|
19
|
-
headers: requestHeaders,
|
|
20
|
-
body,
|
|
21
|
-
});
|
|
22
|
-
if (!response.ok) {
|
|
23
|
-
const errorData = await response.json().catch(() => ({}));
|
|
24
|
-
const errorMessage = (errorData === null || errorData === void 0 ? void 0 : errorData.error) || (errorData === null || errorData === void 0 ? void 0 : errorData.message) || 'Unknown error occurred';
|
|
25
|
-
throw new Error(`Error ${response.status}: ${errorMessage}`);
|
|
26
|
-
}
|
|
27
|
-
return await response.json();
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Submits consent for a user.
|
|
31
|
-
*
|
|
32
|
-
* @param {boolean} isConsentGiven - Indicates whether the user has given consent.
|
|
33
|
-
* @param {string} userFullName - The full name of the user giving consent.
|
|
34
|
-
* @returns {Promise<ConsentResponse>} A promise resolving to the consent response.
|
|
35
|
-
* @throws {Error} - If the user's full name is not provided or if the request fails.
|
|
36
|
-
*/
|
|
37
|
-
async giveConsent(isConsentGiven, userFullName) {
|
|
38
|
-
if (!userFullName) {
|
|
39
|
-
throw new Error('User Full Name is required to give consent.');
|
|
40
|
-
}
|
|
41
|
-
const body = {
|
|
42
|
-
is_consent_given: isConsentGiven,
|
|
43
|
-
user_fullname: userFullName,
|
|
44
|
-
};
|
|
45
|
-
const response = await this.request('/api-consent/consent', 'POST', body);
|
|
46
|
-
return {
|
|
47
|
-
is_consent_given: response.is_consent_given,
|
|
48
|
-
user_fullname: response.user_fullname,
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* Onboards a user's voice for biometric authentication.
|
|
53
|
-
*
|
|
54
|
-
* @param {File} audio - The audio file containing the user's voice.
|
|
55
|
-
* @param {string} userFullName - The full name of the user being onboarded.
|
|
56
|
-
* @param {string} uniqueId - A unique identifier for the onboarding process.
|
|
57
|
-
* @param {string} phrase - The phrase spoken in the audio file.
|
|
58
|
-
* @param {string} [requestUserProvidedId] - An optional user-provided ID to link transactions within a unified group.
|
|
59
|
-
* @returns {Promise<VoiceOnboardingResponse>} - A promise resolving to the voice onboarding response.
|
|
60
|
-
* @throws {Error} - If required parameters are missing or the request fails.
|
|
61
|
-
*/
|
|
62
|
-
async onboardVoice(audio, userFullName, uniqueId, phrase, requestUserProvidedId) {
|
|
63
|
-
if (!userFullName)
|
|
64
|
-
throw new Error('User fullname is required.');
|
|
65
|
-
if (!uniqueId)
|
|
66
|
-
throw new Error('Unique ID is required.');
|
|
67
|
-
if (!phrase)
|
|
68
|
-
throw new Error('Phrase is required.');
|
|
69
|
-
if (!audio)
|
|
70
|
-
throw new Error('Audio file is required.');
|
|
71
|
-
const formData = new FormData();
|
|
72
|
-
formData.append('unique_id', uniqueId);
|
|
73
|
-
formData.append('phrase', phrase);
|
|
74
|
-
formData.append('voice', audio);
|
|
75
|
-
const headers = {
|
|
76
|
-
'X-User-Fullname': userFullName,
|
|
77
|
-
};
|
|
78
|
-
if (requestUserProvidedId) {
|
|
79
|
-
headers['X-Request-User-Provided-ID'] = requestUserProvidedId;
|
|
80
|
-
}
|
|
81
|
-
return this.request('/api-gateway/onboard/voice', 'POST', formData, headers);
|
|
82
|
-
}
|
|
83
|
-
/**
|
|
84
|
-
* Onboards a user's face for biometric authentication.
|
|
85
|
-
*
|
|
86
|
-
* @param {File} face - Image file that contains user's face.
|
|
87
|
-
* @param {string} userFullName - The full name of the user being onboarded.
|
|
88
|
-
* @param {string} isDocument - Indicates whether the image is a document.
|
|
89
|
-
* @param {string} [requestUserProvidedId] - An optional user-provided ID to link transactions within a unified group.
|
|
90
|
-
* @returns {Promise<FaceOnboardingResponse>} - A promise resolving to the voice onboarding response.
|
|
91
|
-
* @throws {Error} - If required parameters are missing or the request fails.
|
|
92
|
-
*/
|
|
93
|
-
async onboardFace(face, userFullName, isDocument, requestUserProvidedId) {
|
|
94
|
-
if (!userFullName)
|
|
95
|
-
throw new Error('User fullname is required.');
|
|
96
|
-
if (!face)
|
|
97
|
-
throw new Error('Face image is required.');
|
|
98
|
-
const formData = new FormData();
|
|
99
|
-
formData.append('face', face);
|
|
100
|
-
if (isDocument) {
|
|
101
|
-
formData.append('is_document', 'true');
|
|
102
|
-
}
|
|
103
|
-
const headers = {
|
|
104
|
-
'X-User-Fullname': userFullName,
|
|
105
|
-
};
|
|
106
|
-
if (requestUserProvidedId) {
|
|
107
|
-
headers['X-Request-User-Provided-ID'] = requestUserProvidedId;
|
|
108
|
-
}
|
|
109
|
-
return this.request('/api-gateway/onboard/face', 'POST', formData, headers);
|
|
110
|
-
}
|
|
111
|
-
/**
|
|
112
|
-
* Matches a user's face from video against a reference image.
|
|
113
|
-
*
|
|
114
|
-
* @param {File} image - Reference image file that contains user's face.
|
|
115
|
-
* @param {string} video - Video file that contains user's face.
|
|
116
|
-
* @param {string} userFullName - Pass the full name of end-user to process Voice and Face recognition services.
|
|
117
|
-
* @param {string} processVideoRequestId - ID from the response header of /process-video endpoint.
|
|
118
|
-
* @param {boolean} usePrefilledVideo - Pass true to use the video from the process-video endpoint.
|
|
119
|
-
* @param {string} [requestUserProvidedId] - An optional user-provided ID to link transactions within a unified group.
|
|
120
|
-
* @returns {Promise<FaceMatchResponse>} - A promise resolving to the voice onboarding response.
|
|
121
|
-
* @throws {Error} - If required parameters are missing or the request fails.
|
|
122
|
-
*/
|
|
123
|
-
async matchFaces(image, video, userFullName, processVideoRequestId, usePrefilledVideo, requestUserProvidedId) {
|
|
124
|
-
if (!image)
|
|
125
|
-
throw new Error('Face image is required.');
|
|
126
|
-
if ((!processVideoRequestId && !usePrefilledVideo) && !video)
|
|
127
|
-
throw new Error('Video is required.');
|
|
128
|
-
const formData = new FormData();
|
|
129
|
-
if (video) {
|
|
130
|
-
formData.append('video', video);
|
|
131
|
-
}
|
|
132
|
-
formData.append('image', image);
|
|
133
|
-
const headers = {};
|
|
134
|
-
if (userFullName) {
|
|
135
|
-
headers['X-User-Fullname'] = userFullName;
|
|
136
|
-
}
|
|
137
|
-
if (processVideoRequestId) {
|
|
138
|
-
headers['X-Request-Id'] = processVideoRequestId;
|
|
139
|
-
}
|
|
140
|
-
if (processVideoRequestId && usePrefilledVideo) {
|
|
141
|
-
headers['X-Use-Prefilled-Video'] = 'true';
|
|
142
|
-
}
|
|
143
|
-
if (requestUserProvidedId) {
|
|
144
|
-
headers['X-Request-User-Provided-ID'] = requestUserProvidedId;
|
|
145
|
-
}
|
|
146
|
-
return this.request('/api-gateway/match-faces', 'POST', formData, headers);
|
|
147
|
-
}
|
|
148
|
-
/**
|
|
149
|
-
* Process the video through Biometry services to check liveness and authorize user
|
|
150
|
-
*
|
|
151
|
-
* @param {File} video - Video file that you want to process.
|
|
152
|
-
* @param {string} phrase - Set of numbers that user needs to say out loud in the video.
|
|
153
|
-
* @param {string} userFullName - Pass the full name of end-user to process Voice and Face recognition services.
|
|
154
|
-
* @param {string} requestUserProvidedId - An optional user-provided ID to link transactions within a unified group.
|
|
155
|
-
* @param {object} deviceInfo - Pass the device information in JSON format to include in transaction.
|
|
156
|
-
* @returns
|
|
157
|
-
*/
|
|
158
|
-
async processVideo(video, phrase, userFullName, requestUserProvidedId, deviceInfo) {
|
|
159
|
-
if (!video)
|
|
160
|
-
throw new Error('Video is required.');
|
|
161
|
-
if (!phrase)
|
|
162
|
-
throw new Error('Phrase is required.');
|
|
163
|
-
const formData = new FormData();
|
|
164
|
-
formData.append('phrase', phrase);
|
|
165
|
-
formData.append('video', video);
|
|
166
|
-
const headers = {};
|
|
167
|
-
if (userFullName) {
|
|
168
|
-
headers['X-User-Fullname'] = userFullName;
|
|
169
|
-
}
|
|
170
|
-
if (requestUserProvidedId) {
|
|
171
|
-
headers['X-Request-User-Provided-ID'] = requestUserProvidedId;
|
|
172
|
-
}
|
|
173
|
-
if (deviceInfo) {
|
|
174
|
-
headers['X-Device-Info'] = JSON.stringify(deviceInfo);
|
|
175
|
-
}
|
|
176
|
-
return this.request('/api-gateway/process-video', 'POST', formData, headers);
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
BiometrySDK.BASE_URL = 'https://api.biometrysolutions.com';
|