santoid-sdk 2.0.1 → 3.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/CHANGELOG.md +11 -0
- package/README.md +259 -107
- package/api/AbstractService.d.ts +21 -0
- package/api/AbstractService.js +32 -0
- package/api/FaceMatchService.d.ts +9 -0
- package/api/FaceMatchService.js +15 -0
- package/api/TypificationService.d.ts +46 -0
- package/api/TypificationService.js +15 -0
- package/browser/liveness/index.js +1 -1
- package/liveness/index.d.ts +1 -3
- package/liveness/index.js +2 -19
- package/liveness/methods/livenessDetection/Service.d.ts +28 -0
- package/liveness/methods/livenessDetection/Service.js +130 -0
- package/liveness/methods/livenessDetection/index.d.ts +15 -0
- package/liveness/methods/livenessDetection/index.js +46 -0
- package/liveness/methods/uploadIdentificationDocument/Service.d.ts +62 -0
- package/liveness/methods/uploadIdentificationDocument/Service.js +134 -0
- package/liveness/methods/uploadIdentificationDocument/index.d.ts +24 -0
- package/liveness/methods/uploadIdentificationDocument/index.js +26 -0
- package/liveness/utils/getNextFrame.d.ts +6 -5
- package/liveness/utils/getNextFrame.js +24 -19
- package/liveness/utils/index.d.ts +2 -2
- package/node/liveness/index.d.ts +1 -3
- package/node/liveness/index.js +2 -19
- package/node/liveness/methods/livenessDetection/Service.d.ts +6 -0
- package/node/liveness/methods/livenessDetection/Service.js +20 -0
- package/node/liveness/methods/livenessDetection/index.d.ts +13 -0
- package/node/liveness/methods/livenessDetection/index.js +46 -0
- package/node/liveness/methods/uploadIdentificationDocument/Service.d.ts +4 -0
- package/node/liveness/methods/uploadIdentificationDocument/Service.js +19 -0
- package/node/liveness/methods/uploadIdentificationDocument/index.d.ts +25 -0
- package/node/liveness/methods/uploadIdentificationDocument/index.js +28 -0
- package/node/liveness/utils/index.d.ts +2 -2
- package/package.json +3 -3
- package/utils/error.d.ts +24 -0
- package/utils/error.js +27 -0
- package/utils/index.d.ts +7 -0
- package/utils/index.js +44 -0
- package/utils/types.d.ts +25 -14
- package/utils/websocket.d.ts +18 -0
- package/utils/websocket.js +57 -0
- package/liveness/methods/livenessDetection.d.ts +0 -6
- package/liveness/methods/livenessDetection.js +0 -129
- package/liveness/methods/uploadIdentificationDocument.d.ts +0 -91
- package/liveness/methods/uploadIdentificationDocument.js +0 -238
- package/liveness/utils/types.d.ts +0 -5
- package/liveness/utils/types.js +0 -17
- package/liveness/utils/websocket.d.ts +0 -3
- package/liveness/utils/websocket.js +0 -34
- package/node/liveness/methods/livenessDetection.d.ts +0 -6
- package/node/liveness/methods/livenessDetection.js +0 -114
- package/node/liveness/methods/uploadIdentificationDocument.d.ts +0 -91
- package/node/liveness/methods/uploadIdentificationDocument.js +0 -239
- package/node/liveness/utils/types.d.ts +0 -6
- package/node/liveness/utils/types.js +0 -17
- package/node/liveness/utils/websocket.d.ts +0 -5
- package/node/liveness/utils/websocket.js +0 -39
package/utils/types.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
import { type SDKError } from './error';
|
|
2
|
+
export type TCallbackFunction = (...args: any[]) => any | Promise<any>;
|
|
2
3
|
export type TPositions = 'front' | 'right' | 'left' | 'up' | 'bottom';
|
|
3
4
|
export type TErrorCode = 'wrong-position' | 'internal-error' | 'typification-error' | 'face-match-error' | 'liveness-error';
|
|
4
5
|
export interface IDecodedToken {
|
|
@@ -10,6 +11,14 @@ export interface ILivenessResults<FrameType> {
|
|
|
10
11
|
livenessId: string;
|
|
11
12
|
successFrames: Record<TPositions, FrameType>;
|
|
12
13
|
}
|
|
14
|
+
export interface IBaseWebSocket<TFrameType> {
|
|
15
|
+
readyState: number;
|
|
16
|
+
addEventListener?: (identifier: string, listener: TCallbackFunction) => any;
|
|
17
|
+
on?: (identifier: string, listener: TCallbackFunction) => any;
|
|
18
|
+
send: (data: TFrameType) => void;
|
|
19
|
+
close: () => any;
|
|
20
|
+
}
|
|
21
|
+
export type TWebSocketClass<TFrameType> = new (url: string) => IBaseWebSocket<TFrameType>;
|
|
13
22
|
export interface IBaseSDKOptions {
|
|
14
23
|
token: string;
|
|
15
24
|
track: string;
|
|
@@ -18,19 +27,21 @@ export interface IBaseSDKOptions {
|
|
|
18
27
|
customWebSocketUrl?: string;
|
|
19
28
|
customApiUrl?: string;
|
|
20
29
|
}
|
|
21
|
-
export interface ISDKOptions extends IBaseSDKOptions {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
30
|
+
export interface ISDKOptions<TFrameType, TMediaType> extends IBaseSDKOptions {
|
|
31
|
+
onNextStep?: (step: TPositions) => void | Promise<void>;
|
|
32
|
+
onFrontStep?: TCallbackFunction;
|
|
33
|
+
onRightStep?: TCallbackFunction;
|
|
34
|
+
onLeftStep?: TCallbackFunction;
|
|
35
|
+
onUpStep?: TCallbackFunction;
|
|
36
|
+
onBottomStep?: TCallbackFunction;
|
|
37
|
+
onError?: (error?: SDKError) => void | Promise<void>;
|
|
38
|
+
onSuccess?: (results: ILivenessResults<TFrameType>) => void | Promise<void>;
|
|
39
|
+
onStart?: TCallbackFunction;
|
|
40
|
+
onEnd?: TCallbackFunction;
|
|
41
|
+
startGettingFrames?: () => TMediaType | Promise<TMediaType>;
|
|
42
|
+
getNextFrame?: () => TFrameType | Promise<TFrameType>;
|
|
43
|
+
stopGettingFrames?: () => void | Promise<void>;
|
|
44
|
+
CustomWebSocketClass?: TWebSocketClass<TFrameType>;
|
|
34
45
|
}
|
|
35
46
|
export interface IWebSocketMessage {
|
|
36
47
|
can_send_next_bytes?: boolean;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { type ISDKOptions, type IBaseWebSocket, type TCallbackFunction, type TWebSocketClass } from './types';
|
|
2
|
+
interface IConstructorOptions<TFrameType> {
|
|
3
|
+
WebSocketClass: TWebSocketClass<TFrameType>;
|
|
4
|
+
decodeJwt: <TDecodeReturnType = any>(token: string) => TDecodeReturnType;
|
|
5
|
+
}
|
|
6
|
+
export declare class AbstractWebSocket<TFrameType, TMediaType> {
|
|
7
|
+
websocket: IBaseWebSocket<TFrameType>;
|
|
8
|
+
classOptions: IConstructorOptions<TFrameType>;
|
|
9
|
+
sdkOptions: ISDKOptions<TFrameType, TMediaType>;
|
|
10
|
+
constructor(classOptions: IConstructorOptions<TFrameType>, sdkOptions: ISDKOptions<TFrameType, TMediaType>);
|
|
11
|
+
startConnection(): void;
|
|
12
|
+
waitForWebSocketConnection(): Promise<void>;
|
|
13
|
+
disconnectFromWebSocket(): void;
|
|
14
|
+
get readyState(): number;
|
|
15
|
+
addListener(identifier: string, listener: TCallbackFunction): void;
|
|
16
|
+
send(payload: TFrameType): void;
|
|
17
|
+
}
|
|
18
|
+
export {};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AbstractWebSocket = void 0;
|
|
4
|
+
const constants_1 = require("./constants");
|
|
5
|
+
class AbstractWebSocket {
|
|
6
|
+
constructor(classOptions, sdkOptions) {
|
|
7
|
+
this.classOptions = classOptions;
|
|
8
|
+
this.sdkOptions = sdkOptions;
|
|
9
|
+
}
|
|
10
|
+
startConnection() {
|
|
11
|
+
var _a, _b;
|
|
12
|
+
const decodedToken = this.classOptions.decodeJwt(this.sdkOptions.token);
|
|
13
|
+
const query = {
|
|
14
|
+
x_endpoint_api_userinfo: this.sdkOptions.token,
|
|
15
|
+
domain: (_a = this.sdkOptions.domain) !== null && _a !== void 0 ? _a : decodedToken.claims.domain,
|
|
16
|
+
track: this.sdkOptions.track,
|
|
17
|
+
customerRequestId: this.sdkOptions.customId,
|
|
18
|
+
};
|
|
19
|
+
const queryStr = Object.entries(query).map(itemsArr => itemsArr.join('=')).join('&');
|
|
20
|
+
this.websocket = new this.classOptions.WebSocketClass(`${(_b = this.sdkOptions.customWebSocketUrl) !== null && _b !== void 0 ? _b : constants_1.WEBSOCKET_BASE_URL}?${queryStr}`);
|
|
21
|
+
}
|
|
22
|
+
async waitForWebSocketConnection() {
|
|
23
|
+
await new Promise((resolve) => {
|
|
24
|
+
const intervalKey = setInterval(() => {
|
|
25
|
+
if ([3, 1].includes(this.websocket.readyState)) {
|
|
26
|
+
clearInterval(intervalKey);
|
|
27
|
+
resolve();
|
|
28
|
+
}
|
|
29
|
+
}, 5);
|
|
30
|
+
});
|
|
31
|
+
if (this.websocket.readyState === 3) {
|
|
32
|
+
throw new Error('Cannot connect to server');
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
disconnectFromWebSocket() {
|
|
36
|
+
var _a, _b;
|
|
37
|
+
if (![2, 3].includes(this.websocket.readyState)) {
|
|
38
|
+
(_b = (_a = this.websocket).close) === null || _b === void 0 ? void 0 : _b.call(_a);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
get readyState() {
|
|
42
|
+
return this.websocket.readyState;
|
|
43
|
+
}
|
|
44
|
+
addListener(identifier, listener) {
|
|
45
|
+
var _a, _b;
|
|
46
|
+
if (this.websocket.on) {
|
|
47
|
+
this.websocket.on(identifier, listener);
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
(_b = (_a = this.websocket).addEventListener) === null || _b === void 0 ? void 0 : _b.call(_a, identifier, listener);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
send(payload) {
|
|
54
|
+
this.websocket.send(payload);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
exports.AbstractWebSocket = AbstractWebSocket;
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { type TWebSDKOptions } from '../utils/types';
|
|
2
|
-
export type FrameType = File | Blob | null | undefined;
|
|
3
|
-
export declare function livenessDetection(options: TWebSDKOptions): Promise<{
|
|
4
|
-
stopLivenessDetection: () => Promise<void>;
|
|
5
|
-
videoStream: MediaStream | undefined;
|
|
6
|
-
}>;
|
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.livenessDetection = void 0;
|
|
4
|
-
const constants_1 = require("../../utils/constants");
|
|
5
|
-
const getNextFrame_1 = require("../utils/getNextFrame");
|
|
6
|
-
const websocket_1 = require("../utils/websocket");
|
|
7
|
-
async function onWebSocketMessage(options, event) {
|
|
8
|
-
var _a, _b, _c;
|
|
9
|
-
const message = event.data;
|
|
10
|
-
let messageObj;
|
|
11
|
-
try {
|
|
12
|
-
messageObj = JSON.parse(message);
|
|
13
|
-
}
|
|
14
|
-
catch (err) {
|
|
15
|
-
console.error('Cannot parse API message', err);
|
|
16
|
-
}
|
|
17
|
-
if ((messageObj === null || messageObj === void 0 ? void 0 : messageObj.next_step) && !messageObj.error) {
|
|
18
|
-
await ((_a = options.nextStepCallback) === null || _a === void 0 ? void 0 : _a.call(options, messageObj.next_step));
|
|
19
|
-
await ((_b = options[`${messageObj.next_step}Callback`]) === null || _b === void 0 ? void 0 : _b.call(options));
|
|
20
|
-
}
|
|
21
|
-
if (messageObj === null || messageObj === void 0 ? void 0 : messageObj.error) {
|
|
22
|
-
await ((_c = options.errorCallback) === null || _c === void 0 ? void 0 : _c.call(options, { code: 'wrong-position' }));
|
|
23
|
-
}
|
|
24
|
-
return messageObj;
|
|
25
|
-
}
|
|
26
|
-
async function livenessDetection(options) {
|
|
27
|
-
var _a, _b, _c;
|
|
28
|
-
let websocketClosedBySDK = false;
|
|
29
|
-
let builtInGetNextFrameReturn;
|
|
30
|
-
let validationSuccess = false;
|
|
31
|
-
let endCalled = false;
|
|
32
|
-
let canSendNextBytes = true;
|
|
33
|
-
const successFrames = {
|
|
34
|
-
front: undefined,
|
|
35
|
-
right: undefined,
|
|
36
|
-
left: undefined,
|
|
37
|
-
up: undefined,
|
|
38
|
-
bottom: undefined,
|
|
39
|
-
};
|
|
40
|
-
let lastSentBytes;
|
|
41
|
-
let currentStep = 'front';
|
|
42
|
-
async function stopLivenessDetection(options, websocket, intervalKey) {
|
|
43
|
-
var _a;
|
|
44
|
-
if (intervalKey) {
|
|
45
|
-
clearInterval(intervalKey);
|
|
46
|
-
}
|
|
47
|
-
if (websocket) {
|
|
48
|
-
(0, websocket_1.disconnectFromWebSocket)(websocket);
|
|
49
|
-
}
|
|
50
|
-
if (builtInGetNextFrameReturn) {
|
|
51
|
-
builtInGetNextFrameReturn.stopGetNextFrame();
|
|
52
|
-
}
|
|
53
|
-
!endCalled && await ((_a = options.endCallback) === null || _a === void 0 ? void 0 : _a.call(options));
|
|
54
|
-
endCalled = true;
|
|
55
|
-
websocketClosedBySDK = true;
|
|
56
|
-
}
|
|
57
|
-
let sendFramesIntervalKey;
|
|
58
|
-
let websocket;
|
|
59
|
-
try {
|
|
60
|
-
websocket = await (0, websocket_1.connectToWebSocket)(options);
|
|
61
|
-
await ((_a = options.nextStepCallback) === null || _a === void 0 ? void 0 : _a.call(options, 'front'));
|
|
62
|
-
await ((_b = options.frontCallback) === null || _b === void 0 ? void 0 : _b.call(options));
|
|
63
|
-
if (!options.getNextFrame && !builtInGetNextFrameReturn) {
|
|
64
|
-
builtInGetNextFrameReturn = await (0, getNextFrame_1.builtInGetNextFrame)();
|
|
65
|
-
}
|
|
66
|
-
sendFramesIntervalKey = setInterval(async () => {
|
|
67
|
-
try {
|
|
68
|
-
if (canSendNextBytes) {
|
|
69
|
-
let bytes;
|
|
70
|
-
if (options.getNextFrame) {
|
|
71
|
-
bytes = await options.getNextFrame();
|
|
72
|
-
}
|
|
73
|
-
else {
|
|
74
|
-
bytes = await (builtInGetNextFrameReturn === null || builtInGetNextFrameReturn === void 0 ? void 0 : builtInGetNextFrameReturn.getNextFrame());
|
|
75
|
-
}
|
|
76
|
-
if (bytes) {
|
|
77
|
-
websocket === null || websocket === void 0 ? void 0 : websocket.send(bytes);
|
|
78
|
-
lastSentBytes = bytes;
|
|
79
|
-
canSendNextBytes = false;
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
catch (err) {
|
|
84
|
-
await stopLivenessDetection(options, websocket, sendFramesIntervalKey);
|
|
85
|
-
}
|
|
86
|
-
}, constants_1.SEND_FRAMES_INTERVAL_MS);
|
|
87
|
-
websocket.addEventListener('message', async (event) => {
|
|
88
|
-
var _a;
|
|
89
|
-
const parsedMessage = await onWebSocketMessage(options, event);
|
|
90
|
-
if (parsedMessage) {
|
|
91
|
-
canSendNextBytes = !!(parsedMessage === null || parsedMessage === void 0 ? void 0 : parsedMessage.can_send_next_bytes);
|
|
92
|
-
}
|
|
93
|
-
if ((parsedMessage === null || parsedMessage === void 0 ? void 0 : parsedMessage.validation) && currentStep) {
|
|
94
|
-
successFrames[currentStep] = lastSentBytes;
|
|
95
|
-
}
|
|
96
|
-
if (parsedMessage === null || parsedMessage === void 0 ? void 0 : parsedMessage.next_step) {
|
|
97
|
-
currentStep = parsedMessage.next_step;
|
|
98
|
-
}
|
|
99
|
-
if (parsedMessage === null || parsedMessage === void 0 ? void 0 : parsedMessage.success) {
|
|
100
|
-
successFrames.bottom = lastSentBytes;
|
|
101
|
-
validationSuccess = true;
|
|
102
|
-
await ((_a = options.successCallback) === null || _a === void 0 ? void 0 : _a.call(options, { livenessId: parsedMessage.livenessId, successFrames }));
|
|
103
|
-
await stopLivenessDetection(options, websocket, sendFramesIntervalKey);
|
|
104
|
-
}
|
|
105
|
-
});
|
|
106
|
-
websocket.addEventListener('error', async () => {
|
|
107
|
-
var _a;
|
|
108
|
-
!validationSuccess && ((_a = options.errorCallback) === null || _a === void 0 ? void 0 : _a.call(options, { code: 'internal-error' }));
|
|
109
|
-
await stopLivenessDetection(options, websocket, sendFramesIntervalKey);
|
|
110
|
-
});
|
|
111
|
-
websocket.addEventListener('close', async () => {
|
|
112
|
-
var _a;
|
|
113
|
-
if (!websocketClosedBySDK) {
|
|
114
|
-
!validationSuccess && ((_a = options.errorCallback) === null || _a === void 0 ? void 0 : _a.call(options, { code: 'internal-error' }));
|
|
115
|
-
await stopLivenessDetection(options, websocket, sendFramesIntervalKey);
|
|
116
|
-
}
|
|
117
|
-
});
|
|
118
|
-
return {
|
|
119
|
-
stopLivenessDetection: async () => { await stopLivenessDetection(options, websocket, sendFramesIntervalKey); },
|
|
120
|
-
videoStream: builtInGetNextFrameReturn === null || builtInGetNextFrameReturn === void 0 ? void 0 : builtInGetNextFrameReturn.videoStream,
|
|
121
|
-
};
|
|
122
|
-
}
|
|
123
|
-
catch (err) {
|
|
124
|
-
!validationSuccess && ((_c = options.errorCallback) === null || _c === void 0 ? void 0 : _c.call(options, { code: 'internal-error' }));
|
|
125
|
-
await stopLivenessDetection(options, websocket, sendFramesIntervalKey);
|
|
126
|
-
throw err;
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
exports.livenessDetection = livenessDetection;
|
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
import { type ILivenessResults, type TWebSDKOptions, type IBaseSDKOptions, type TCallbackFunction, type TErrorCode } from '../utils/types';
|
|
2
|
-
type TResultStatuses = 'success' | 'error' | null;
|
|
3
|
-
type FileType = Blob | File;
|
|
4
|
-
interface ITypificationResult {
|
|
5
|
-
n_documents: number;
|
|
6
|
-
predictOCR: Array<{
|
|
7
|
-
typification: {
|
|
8
|
-
document_type: string;
|
|
9
|
-
ocr_success: boolean;
|
|
10
|
-
typification_score: number;
|
|
11
|
-
};
|
|
12
|
-
ocr_error?: boolean | null;
|
|
13
|
-
ocr_message?: {
|
|
14
|
-
template: string;
|
|
15
|
-
labels: any;
|
|
16
|
-
} | null;
|
|
17
|
-
ocr_extraction: {
|
|
18
|
-
template: string;
|
|
19
|
-
labels: Array<{
|
|
20
|
-
x: number;
|
|
21
|
-
y: number;
|
|
22
|
-
w: number;
|
|
23
|
-
h: number;
|
|
24
|
-
bottomRight: number[];
|
|
25
|
-
topLeft: number[];
|
|
26
|
-
dataField?: string;
|
|
27
|
-
dataFieldValue?: boolean;
|
|
28
|
-
ocr?: string | null;
|
|
29
|
-
ocr_score?: number;
|
|
30
|
-
cropBase64?: string | null;
|
|
31
|
-
serpro_query?: {
|
|
32
|
-
serpro_data: any;
|
|
33
|
-
search_logs: {
|
|
34
|
-
document: string;
|
|
35
|
-
type: string;
|
|
36
|
-
search_time: string;
|
|
37
|
-
status_code: number;
|
|
38
|
-
message: string;
|
|
39
|
-
};
|
|
40
|
-
};
|
|
41
|
-
validation?: Record<string, number | boolean>;
|
|
42
|
-
}> | null;
|
|
43
|
-
} | boolean;
|
|
44
|
-
}>;
|
|
45
|
-
}
|
|
46
|
-
interface IFaceMatchResult {
|
|
47
|
-
comparison_score: number;
|
|
48
|
-
similarity_score: number;
|
|
49
|
-
match: boolean;
|
|
50
|
-
}
|
|
51
|
-
interface IUploadIdentificationDocumentResults {
|
|
52
|
-
uploadedDocument: FileType | null;
|
|
53
|
-
typification: {
|
|
54
|
-
status: TResultStatuses;
|
|
55
|
-
results: ITypificationResult | null;
|
|
56
|
-
loading: boolean;
|
|
57
|
-
error: any;
|
|
58
|
-
};
|
|
59
|
-
liveness: {
|
|
60
|
-
status: TResultStatuses;
|
|
61
|
-
results: ILivenessResults<FileType | null | undefined> | null;
|
|
62
|
-
loading: boolean;
|
|
63
|
-
error: any;
|
|
64
|
-
};
|
|
65
|
-
faceMatch: {
|
|
66
|
-
status: TResultStatuses;
|
|
67
|
-
results: IFaceMatchResult | null;
|
|
68
|
-
loading: boolean;
|
|
69
|
-
error: any;
|
|
70
|
-
};
|
|
71
|
-
}
|
|
72
|
-
interface IUploadIdentificationDocumentOptions extends IBaseSDKOptions {
|
|
73
|
-
resultChangeCallback: (results?: IUploadIdentificationDocumentResults) => void | Promise<void>;
|
|
74
|
-
successCallback: <FrameType, ResultsType = ILivenessResults<FrameType>>(results?: ResultsType) => void | Promise<void>;
|
|
75
|
-
errorCallback?: (error?: {
|
|
76
|
-
code: TErrorCode;
|
|
77
|
-
details?: any;
|
|
78
|
-
}) => void | Promise<void>;
|
|
79
|
-
endCallback?: TCallbackFunction;
|
|
80
|
-
}
|
|
81
|
-
export declare function uploadIdentificationDocument(options: IUploadIdentificationDocumentOptions): {
|
|
82
|
-
getResults: () => IUploadIdentificationDocumentResults;
|
|
83
|
-
startDocumentUpload: (file: FileType) => Promise<void>;
|
|
84
|
-
startLivenessDetection: (startLivenessDetectionOptions?: TWebSDKOptions) => Promise<{
|
|
85
|
-
stopLivenessDetection: () => Promise<void>;
|
|
86
|
-
videoStream: MediaStream | undefined;
|
|
87
|
-
} | undefined>;
|
|
88
|
-
startFaceComparison: () => void;
|
|
89
|
-
startAll: (file: FileType, startLivenessDetectionOptions?: TWebSDKOptions) => void;
|
|
90
|
-
};
|
|
91
|
-
export {};
|
|
@@ -1,238 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.uploadIdentificationDocument = void 0;
|
|
7
|
-
const axios_1 = __importDefault(require("axios"));
|
|
8
|
-
const constants_1 = require("../../utils/constants");
|
|
9
|
-
const utils_1 = require("../utils");
|
|
10
|
-
const livenessDetection_1 = require("./livenessDetection");
|
|
11
|
-
async function typificationPredict(options, file) {
|
|
12
|
-
var _a, _b, _c;
|
|
13
|
-
const formData = new FormData();
|
|
14
|
-
formData.append('track', options.track);
|
|
15
|
-
formData.append('imageFile', file);
|
|
16
|
-
const decodedToken = (0, utils_1.tryDecodeJwt)(options.token);
|
|
17
|
-
const domain = (_a = options.domain) !== null && _a !== void 0 ? _a : (_b = decodedToken === null || decodedToken === void 0 ? void 0 : decodedToken.claims) === null || _b === void 0 ? void 0 : _b.domain;
|
|
18
|
-
const axiosConfig = {
|
|
19
|
-
headers: {
|
|
20
|
-
'Content-Type': 'multipart/form-data',
|
|
21
|
-
Authorization: `Bearer ${options.token}`,
|
|
22
|
-
},
|
|
23
|
-
};
|
|
24
|
-
if (axiosConfig.headers && domain) {
|
|
25
|
-
axiosConfig.headers.Domain = domain;
|
|
26
|
-
}
|
|
27
|
-
const response = await axios_1.default.post(`${(_c = options === null || options === void 0 ? void 0 : options.customApiUrl) !== null && _c !== void 0 ? _c : constants_1.API_GATEWAY_URL}/api/v3/typification/predict`, formData, axiosConfig);
|
|
28
|
-
return response.data;
|
|
29
|
-
}
|
|
30
|
-
async function faceMatch(options, firstImage, secondImage) {
|
|
31
|
-
var _a, _b, _c;
|
|
32
|
-
const formData = new FormData();
|
|
33
|
-
formData.append('track', options.track);
|
|
34
|
-
formData.append('firstImage', firstImage);
|
|
35
|
-
formData.append('secondImage', secondImage);
|
|
36
|
-
const decodedToken = (0, utils_1.tryDecodeJwt)(options.token);
|
|
37
|
-
const domain = (_a = options.domain) !== null && _a !== void 0 ? _a : (_b = decodedToken === null || decodedToken === void 0 ? void 0 : decodedToken.claims) === null || _b === void 0 ? void 0 : _b.domain;
|
|
38
|
-
const axiosConfig = {
|
|
39
|
-
params: {
|
|
40
|
-
sensitive_data_compliance: true,
|
|
41
|
-
},
|
|
42
|
-
headers: {
|
|
43
|
-
'Content-Type': 'multipart/form-data',
|
|
44
|
-
Authorization: `Bearer ${options.token}`,
|
|
45
|
-
},
|
|
46
|
-
};
|
|
47
|
-
if (axiosConfig.headers && domain) {
|
|
48
|
-
axiosConfig.headers.Domain = domain;
|
|
49
|
-
}
|
|
50
|
-
const response = await axios_1.default.post(`${(_c = options === null || options === void 0 ? void 0 : options.customApiUrl) !== null && _c !== void 0 ? _c : constants_1.API_GATEWAY_URL}/api/v1/facematch/pair`, formData, axiosConfig);
|
|
51
|
-
return response.data;
|
|
52
|
-
}
|
|
53
|
-
function uploadIdentificationDocument(options) {
|
|
54
|
-
let results = {
|
|
55
|
-
uploadedDocument: null,
|
|
56
|
-
typification: {
|
|
57
|
-
status: null,
|
|
58
|
-
results: null,
|
|
59
|
-
loading: false,
|
|
60
|
-
error: null,
|
|
61
|
-
},
|
|
62
|
-
liveness: {
|
|
63
|
-
status: null,
|
|
64
|
-
results: null,
|
|
65
|
-
loading: false,
|
|
66
|
-
error: null,
|
|
67
|
-
},
|
|
68
|
-
faceMatch: {
|
|
69
|
-
status: null,
|
|
70
|
-
results: null,
|
|
71
|
-
loading: false,
|
|
72
|
-
error: null,
|
|
73
|
-
},
|
|
74
|
-
};
|
|
75
|
-
async function startFaceMatch(firstImage, secondImage) {
|
|
76
|
-
var _a, _b, _c;
|
|
77
|
-
try {
|
|
78
|
-
updateResults({
|
|
79
|
-
faceMatch: {
|
|
80
|
-
status: null,
|
|
81
|
-
results: null,
|
|
82
|
-
loading: true,
|
|
83
|
-
error: null,
|
|
84
|
-
},
|
|
85
|
-
});
|
|
86
|
-
const faceMatchResults = await faceMatch(options, firstImage, secondImage);
|
|
87
|
-
updateResults({
|
|
88
|
-
faceMatch: {
|
|
89
|
-
results: faceMatchResults,
|
|
90
|
-
status: 'success',
|
|
91
|
-
loading: false,
|
|
92
|
-
error: null,
|
|
93
|
-
},
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
|
-
catch (err) {
|
|
97
|
-
await ((_a = options.errorCallback) === null || _a === void 0 ? void 0 : _a.call(options, { code: 'face-match-error', details: (_b = err === null || err === void 0 ? void 0 : err.response) === null || _b === void 0 ? void 0 : _b.data }));
|
|
98
|
-
updateResults({
|
|
99
|
-
faceMatch: {
|
|
100
|
-
results: null,
|
|
101
|
-
status: 'error',
|
|
102
|
-
loading: false,
|
|
103
|
-
error: (_c = err === null || err === void 0 ? void 0 : err.response) === null || _c === void 0 ? void 0 : _c.data,
|
|
104
|
-
},
|
|
105
|
-
});
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
function tryStartFaceMatch() {
|
|
109
|
-
var _a;
|
|
110
|
-
if (results.uploadedDocument &&
|
|
111
|
-
((_a = results.liveness.results) === null || _a === void 0 ? void 0 : _a.successFrames.front) &&
|
|
112
|
-
!results.faceMatch.results &&
|
|
113
|
-
!results.faceMatch.loading) {
|
|
114
|
-
void startFaceMatch(results.uploadedDocument, results.liveness.results.successFrames.front);
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
function updateUploadedDocument(file) {
|
|
118
|
-
results.uploadedDocument = file;
|
|
119
|
-
tryStartFaceMatch();
|
|
120
|
-
}
|
|
121
|
-
function updateResults(updatedResults) {
|
|
122
|
-
var _a, _b, _c;
|
|
123
|
-
results = Object.assign(Object.assign({}, results), updatedResults);
|
|
124
|
-
void ((_a = options.resultChangeCallback) === null || _a === void 0 ? void 0 : _a.call(options, results));
|
|
125
|
-
if (Object.entries(results).every(([key, value]) => key === 'uploadedDocument' || !!value.results)) {
|
|
126
|
-
void ((_b = options.successCallback) === null || _b === void 0 ? void 0 : _b.call(options, results));
|
|
127
|
-
void ((_c = options.endCallback) === null || _c === void 0 ? void 0 : _c.call(options));
|
|
128
|
-
return;
|
|
129
|
-
}
|
|
130
|
-
if (results.faceMatch.status !== 'error') {
|
|
131
|
-
tryStartFaceMatch();
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
async function startDocumentUpload(file) {
|
|
135
|
-
var _a, _b, _c;
|
|
136
|
-
try {
|
|
137
|
-
updateResults({
|
|
138
|
-
typification: {
|
|
139
|
-
status: null,
|
|
140
|
-
results: null,
|
|
141
|
-
loading: true,
|
|
142
|
-
error: null,
|
|
143
|
-
},
|
|
144
|
-
});
|
|
145
|
-
updateUploadedDocument(file);
|
|
146
|
-
const typificationResults = await typificationPredict(options, file);
|
|
147
|
-
updateResults({
|
|
148
|
-
typification: {
|
|
149
|
-
status: 'success',
|
|
150
|
-
results: typificationResults,
|
|
151
|
-
loading: false,
|
|
152
|
-
error: null,
|
|
153
|
-
},
|
|
154
|
-
});
|
|
155
|
-
}
|
|
156
|
-
catch (err) {
|
|
157
|
-
await ((_a = options.errorCallback) === null || _a === void 0 ? void 0 : _a.call(options, { code: 'typification-error', details: (_b = err === null || err === void 0 ? void 0 : err.response) === null || _b === void 0 ? void 0 : _b.data }));
|
|
158
|
-
updateResults({
|
|
159
|
-
typification: {
|
|
160
|
-
status: 'error',
|
|
161
|
-
results: null,
|
|
162
|
-
loading: false,
|
|
163
|
-
error: (_c = err === null || err === void 0 ? void 0 : err.response) === null || _c === void 0 ? void 0 : _c.data,
|
|
164
|
-
},
|
|
165
|
-
});
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
async function startLivenessDetection(startLivenessDetectionOptions) {
|
|
169
|
-
var _a, _b, _c, _d, _e;
|
|
170
|
-
const adaptedLivenessOptions = Object.assign({}, startLivenessDetectionOptions);
|
|
171
|
-
delete adaptedLivenessOptions.successCallback;
|
|
172
|
-
delete adaptedLivenessOptions.errorCallback;
|
|
173
|
-
updateResults({
|
|
174
|
-
liveness: {
|
|
175
|
-
results: null,
|
|
176
|
-
status: null,
|
|
177
|
-
loading: true,
|
|
178
|
-
error: null,
|
|
179
|
-
},
|
|
180
|
-
});
|
|
181
|
-
try {
|
|
182
|
-
return await (0, livenessDetection_1.livenessDetection)(Object.assign(Object.assign({ domain: options.domain, customId: options.customId, customWebSocketUrl: options.customWebSocketUrl, successCallback: (livenessResults) => {
|
|
183
|
-
var _a;
|
|
184
|
-
void ((_a = startLivenessDetectionOptions === null || startLivenessDetectionOptions === void 0 ? void 0 : startLivenessDetectionOptions.successCallback) === null || _a === void 0 ? void 0 : _a.call(startLivenessDetectionOptions, livenessResults));
|
|
185
|
-
updateResults({
|
|
186
|
-
liveness: {
|
|
187
|
-
status: 'success',
|
|
188
|
-
results: (livenessResults),
|
|
189
|
-
loading: false,
|
|
190
|
-
error: null,
|
|
191
|
-
},
|
|
192
|
-
});
|
|
193
|
-
}, errorCallback: async (livenessErrorDetails) => {
|
|
194
|
-
var _a, _b;
|
|
195
|
-
if ((livenessErrorDetails === null || livenessErrorDetails === void 0 ? void 0 : livenessErrorDetails.code) === 'wrong-position') {
|
|
196
|
-
void ((_a = startLivenessDetectionOptions === null || startLivenessDetectionOptions === void 0 ? void 0 : startLivenessDetectionOptions.errorCallback) === null || _a === void 0 ? void 0 : _a.call(startLivenessDetectionOptions, livenessErrorDetails));
|
|
197
|
-
}
|
|
198
|
-
else {
|
|
199
|
-
void ((_b = options.errorCallback) === null || _b === void 0 ? void 0 : _b.call(options, livenessErrorDetails));
|
|
200
|
-
}
|
|
201
|
-
updateResults({
|
|
202
|
-
liveness: {
|
|
203
|
-
status: 'error',
|
|
204
|
-
results: null,
|
|
205
|
-
loading: (livenessErrorDetails === null || livenessErrorDetails === void 0 ? void 0 : livenessErrorDetails.code) === 'wrong-position',
|
|
206
|
-
error: livenessErrorDetails,
|
|
207
|
-
},
|
|
208
|
-
});
|
|
209
|
-
} }, adaptedLivenessOptions), { token: (_a = adaptedLivenessOptions.token) !== null && _a !== void 0 ? _a : options.token, track: (_b = adaptedLivenessOptions.track) !== null && _b !== void 0 ? _b : options.track }));
|
|
210
|
-
}
|
|
211
|
-
catch (err) {
|
|
212
|
-
await ((_c = options.errorCallback) === null || _c === void 0 ? void 0 : _c.call(options, { code: 'liveness-error', details: (_d = err === null || err === void 0 ? void 0 : err.response) === null || _d === void 0 ? void 0 : _d.data }));
|
|
213
|
-
updateResults({
|
|
214
|
-
liveness: {
|
|
215
|
-
status: 'error',
|
|
216
|
-
results: null,
|
|
217
|
-
loading: false,
|
|
218
|
-
error: (_e = err === null || err === void 0 ? void 0 : err.response) === null || _e === void 0 ? void 0 : _e.data,
|
|
219
|
-
},
|
|
220
|
-
});
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
function startAll(file, startLivenessDetectionOptions) {
|
|
224
|
-
void startDocumentUpload(file);
|
|
225
|
-
void startLivenessDetection(startLivenessDetectionOptions);
|
|
226
|
-
}
|
|
227
|
-
function getResults() {
|
|
228
|
-
return results;
|
|
229
|
-
}
|
|
230
|
-
return {
|
|
231
|
-
getResults,
|
|
232
|
-
startDocumentUpload,
|
|
233
|
-
startLivenessDetection,
|
|
234
|
-
startFaceComparison: tryStartFaceMatch,
|
|
235
|
-
startAll,
|
|
236
|
-
};
|
|
237
|
-
}
|
|
238
|
-
exports.uploadIdentificationDocument = uploadIdentificationDocument;
|
package/liveness/utils/types.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("../../utils/types"), exports);
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.disconnectFromWebSocket = exports.connectToWebSocket = void 0;
|
|
4
|
-
const _1 = require(".");
|
|
5
|
-
const constants_1 = require("../../utils/constants");
|
|
6
|
-
async function waitForWebSocketConnection(websocket) {
|
|
7
|
-
await new Promise((resolve) => {
|
|
8
|
-
const intervalKey = setInterval(() => {
|
|
9
|
-
if ([3, 1].includes(websocket.readyState)) {
|
|
10
|
-
clearInterval(intervalKey);
|
|
11
|
-
resolve();
|
|
12
|
-
}
|
|
13
|
-
}, 5);
|
|
14
|
-
});
|
|
15
|
-
if (websocket.readyState === 3) {
|
|
16
|
-
throw new Error('Cannot connect to server');
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
async function connectToWebSocket(options) {
|
|
20
|
-
var _a, _b;
|
|
21
|
-
const decodedToken = (0, _1.decodeJwt)(options.token);
|
|
22
|
-
const query = `?x_endpoint_api_userinfo=${options.token}&domain=${(_a = options.domain) !== null && _a !== void 0 ? _a : decodedToken.claims.domain}&track=${options.track}&customerRequestId=${options.customId}`;
|
|
23
|
-
const websocket = new WebSocket(`${(_b = options.customWebSocketUrl) !== null && _b !== void 0 ? _b : constants_1.WEBSOCKET_BASE_URL}${query}`);
|
|
24
|
-
await waitForWebSocketConnection(websocket);
|
|
25
|
-
return websocket;
|
|
26
|
-
}
|
|
27
|
-
exports.connectToWebSocket = connectToWebSocket;
|
|
28
|
-
function disconnectFromWebSocket(websocket) {
|
|
29
|
-
var _a;
|
|
30
|
-
if (![2, 3].includes(websocket.readyState)) {
|
|
31
|
-
(_a = websocket.close) === null || _a === void 0 ? void 0 : _a.call(websocket);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
exports.disconnectFromWebSocket = disconnectFromWebSocket;
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { type Data } from 'ws';
|
|
2
|
-
import { type TNodeSDKOptions } from '../utils/types';
|
|
3
|
-
export type FrameType = Data | null | undefined;
|
|
4
|
-
export declare function livenessDetection(options: TNodeSDKOptions): Promise<{
|
|
5
|
-
stopLivenessDetection: () => Promise<void>;
|
|
6
|
-
}>;
|