santoid-sdk 7.0.0 → 9.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 +25 -4
- package/README.md +123 -237
- package/api/AbstractService.js +9 -3
- package/api/ApiLivenessSessionService.d.ts +14 -1
- package/api/ApiLivenessSessionService.js +20 -11
- package/browser/index.js +1 -1
- package/browser/liveness-capture.js +2 -0
- package/browser/liveness-capture.js.LICENSE.txt +350 -0
- package/client/age/index.d.ts +18 -0
- package/client/age/index.js +40 -0
- package/client/index.d.ts +4 -2
- package/client/index.js +4 -2
- package/client/liveness/index.d.ts +2 -2
- package/client/liveness/index.js +3 -3
- package/client/liveness/methods/livenessSession/Service.d.ts +10 -3
- package/client/liveness/methods/livenessSession/Service.js +14 -6
- package/client/liveness/methods/livenessSession/index.d.ts +13 -9
- package/client/liveness/methods/livenessSession/index.js +12 -9
- package/client/liveness/methods/livenessSession/isLivenessApproved.d.ts +6 -0
- package/client/liveness/methods/livenessSession/isLivenessApproved.js +13 -0
- package/client/liveness/methods/uploadIdentificationDocument/Service.d.ts +8 -29
- package/client/liveness/methods/uploadIdentificationDocument/Service.js +25 -66
- package/client/liveness/methods/uploadIdentificationDocument/index.d.ts +4 -18
- package/client/liveness/methods/uploadIdentificationDocument/index.js +4 -8
- package/client/liveness-capture/LivenessCapture.d.ts +13 -0
- package/client/liveness-capture/LivenessCapture.js +23 -0
- package/client/liveness-capture/displayText.d.ts +54 -0
- package/client/liveness-capture/displayText.js +57 -0
- package/client/liveness-capture/index.d.ts +36 -0
- package/client/liveness-capture/index.js +2 -0
- package/client/liveness-capture/index.js.LICENSE.txt +350 -0
- package/package.json +11 -4
- package/server/index.d.ts +0 -2
- package/server/index.js +0 -2
- package/server/liveness/index.d.ts +1 -2
- package/server/liveness/index.js +1 -3
- package/server/liveness/methods/uploadIdentificationDocument/Service.d.ts +3 -3
- package/server/liveness/methods/uploadIdentificationDocument/Service.js +2 -2
- package/server/liveness/methods/uploadIdentificationDocument/index.d.ts +7 -21
- package/server/liveness/methods/uploadIdentificationDocument/index.js +4 -10
- package/tsconfig.json +3 -0
- package/tsconfig.prod.json +3 -0
- package/utils/constants.d.ts +1 -2
- package/utils/constants.js +4 -3
- package/utils/error.d.ts +6 -5
- package/utils/error.js +7 -6
- package/utils/index.d.ts +2 -0
- package/utils/index.js +12 -1
- package/utils/types.d.ts +8 -39
- package/webpack.config.cjs +45 -2
- package/client/liveness/methods/livenessDetection/Service.d.ts +0 -28
- package/client/liveness/methods/livenessDetection/Service.js +0 -138
- package/client/liveness/methods/livenessDetection/index.d.ts +0 -23
- package/client/liveness/methods/livenessDetection/index.js +0 -58
- package/server/liveness/methods/livenessDetection/Service.d.ts +0 -6
- package/server/liveness/methods/livenessDetection/Service.js +0 -20
- package/server/liveness/methods/livenessDetection/index.d.ts +0 -13
- package/server/liveness/methods/livenessDetection/index.js +0 -50
- package/utils/websocket.d.ts +0 -18
- package/utils/websocket.js +0 -62
package/utils/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.retryAsyncFunctionXTimes = exports.callAsyncFunctionEveryXSeconds = exports.waitFor = exports.wait = exports.capitalizeFirstLetter = void 0;
|
|
3
|
+
exports.looksLikeApiToken = exports.API_TOKEN_PREFIXES = exports.retryAsyncFunctionXTimes = exports.callAsyncFunctionEveryXSeconds = exports.waitFor = exports.wait = exports.capitalizeFirstLetter = void 0;
|
|
4
4
|
const axios_1 = require("axios");
|
|
5
5
|
const constants_1 = require("./constants");
|
|
6
6
|
function capitalizeFirstLetter(str) {
|
|
@@ -61,3 +61,14 @@ async function retryAsyncFunctionXTimes(requestAsyncFn, retryCondition = default
|
|
|
61
61
|
}
|
|
62
62
|
}
|
|
63
63
|
exports.retryAsyncFunctionXTimes = retryAsyncFunctionXTimes;
|
|
64
|
+
// Prefixos que identificam um token de API. Mesmo criterio do orchestrator
|
|
65
|
+
// (infrastructure/auth/auth.go, getUserData) e do santoid-liveness
|
|
66
|
+
// (crud/api_token.py): sao chaves opacas, nao JWT, e tentar decodifica-las
|
|
67
|
+
// como JWT falharia.
|
|
68
|
+
exports.API_TOKEN_PREFIXES = ['st_', 'AIza'];
|
|
69
|
+
function looksLikeApiToken(token) {
|
|
70
|
+
if (!token)
|
|
71
|
+
return false;
|
|
72
|
+
return exports.API_TOKEN_PREFIXES.some((prefix) => token.startsWith(prefix));
|
|
73
|
+
}
|
|
74
|
+
exports.looksLikeApiToken = looksLikeApiToken;
|
package/utils/types.d.ts
CHANGED
|
@@ -1,54 +1,23 @@
|
|
|
1
|
-
import { type SDKError } from './error';
|
|
2
1
|
export type TCallbackFunction = (...args: any[]) => any | Promise<any>;
|
|
3
|
-
export type TPositions = 'front' | 'right' | 'left' | 'up' | 'bottom';
|
|
4
2
|
export interface IDecodedToken {
|
|
5
3
|
claims: {
|
|
6
4
|
domain: string;
|
|
7
5
|
};
|
|
8
6
|
}
|
|
9
|
-
export interface ILivenessResults<FrameType> {
|
|
10
|
-
livenessId: string;
|
|
11
|
-
successFrames: Record<TPositions, FrameType>;
|
|
12
|
-
}
|
|
13
|
-
export interface IBaseWebSocket<TFrameType> {
|
|
14
|
-
readyState: number;
|
|
15
|
-
addEventListener?: (identifier: string, listener: TCallbackFunction) => any;
|
|
16
|
-
on?: (identifier: string, listener: TCallbackFunction) => any;
|
|
17
|
-
send: (data: TFrameType) => void;
|
|
18
|
-
close: () => any;
|
|
19
|
-
}
|
|
20
|
-
export type TWebSocketClass<TFrameType> = new (url: string) => IBaseWebSocket<TFrameType>;
|
|
21
7
|
export interface IBaseSDKOptions {
|
|
22
8
|
token: string;
|
|
9
|
+
/**
|
|
10
|
+
* Chave de API do SantoiD, enviada em x-api-key.
|
|
11
|
+
*
|
|
12
|
+
* Opcional: uma chave passada em `token` tambem e' reconhecida pelo prefixo
|
|
13
|
+
* (st_, AIza), como faz o orchestrator. Este campo existe para quando a
|
|
14
|
+
* chave nao seguir esse formato.
|
|
15
|
+
*/
|
|
16
|
+
apiKey?: string;
|
|
23
17
|
track: string;
|
|
24
18
|
template?: string;
|
|
25
19
|
customId?: string;
|
|
26
20
|
domain?: string;
|
|
27
|
-
customWebSocketUrl?: string;
|
|
28
21
|
customApiUrl?: string;
|
|
29
22
|
useBillingAccounts?: boolean;
|
|
30
23
|
}
|
|
31
|
-
export interface ISDKOptions<TFrameType, TMediaType> extends IBaseSDKOptions {
|
|
32
|
-
onNextStep?: (step: TPositions) => void | Promise<void>;
|
|
33
|
-
onFrontStep?: TCallbackFunction;
|
|
34
|
-
onRightStep?: TCallbackFunction;
|
|
35
|
-
onLeftStep?: TCallbackFunction;
|
|
36
|
-
onUpStep?: TCallbackFunction;
|
|
37
|
-
onBottomStep?: TCallbackFunction;
|
|
38
|
-
onError?: (error?: SDKError) => void | Promise<void>;
|
|
39
|
-
onSuccess?: (results: ILivenessResults<TFrameType>) => void | Promise<void>;
|
|
40
|
-
onStart?: TCallbackFunction;
|
|
41
|
-
onEnd?: TCallbackFunction;
|
|
42
|
-
startGettingFrames?: () => TMediaType | Promise<TMediaType>;
|
|
43
|
-
getNextFrame?: () => TFrameType | Promise<TFrameType>;
|
|
44
|
-
stopGettingFrames?: () => void | Promise<void>;
|
|
45
|
-
CustomWebSocketClass?: TWebSocketClass<TFrameType>;
|
|
46
|
-
}
|
|
47
|
-
export interface IWebSocketMessage {
|
|
48
|
-
can_send_next_bytes?: boolean;
|
|
49
|
-
next_step?: TPositions;
|
|
50
|
-
validation?: boolean;
|
|
51
|
-
error?: boolean;
|
|
52
|
-
success?: boolean;
|
|
53
|
-
livenessId: string;
|
|
54
|
-
}
|
package/webpack.config.cjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
const path = require('path')
|
|
2
|
+
const webpack = require('webpack')
|
|
2
3
|
|
|
3
4
|
const { CleanWebpackPlugin } = require('clean-webpack-plugin')
|
|
4
5
|
|
|
@@ -31,6 +32,10 @@ const generalConfig = {
|
|
|
31
32
|
],
|
|
32
33
|
exclude: /node_modules/,
|
|
33
34
|
},
|
|
35
|
+
{
|
|
36
|
+
test: /\.css$/,
|
|
37
|
+
use: ['style-loader', 'css-loader'],
|
|
38
|
+
},
|
|
34
39
|
],
|
|
35
40
|
},
|
|
36
41
|
|
|
@@ -53,6 +58,35 @@ const browserConfig = {
|
|
|
53
58
|
},
|
|
54
59
|
}
|
|
55
60
|
|
|
61
|
+
// A captura leva React e o componente de camera dentro do proprio arquivo, e o
|
|
62
|
+
// CSS vai injetado: quem usa nao instala nem importa nada alem do SDK. Por
|
|
63
|
+
// isso ela tem entry proprio, separado do bundle principal.
|
|
64
|
+
const livenessCaptureBrowserConfig = {
|
|
65
|
+
entry: './src/client/liveness-capture/index.tsx',
|
|
66
|
+
target: 'web',
|
|
67
|
+
output: {
|
|
68
|
+
path: path.resolve(__dirname, './dist/browser'),
|
|
69
|
+
filename: 'liveness-capture.js',
|
|
70
|
+
libraryTarget: 'umd',
|
|
71
|
+
globalObject: 'this',
|
|
72
|
+
umdNamedDefine: true,
|
|
73
|
+
library: 'SantoiDLivenessCapture',
|
|
74
|
+
},
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// Sobrescreve a saida do tsc para o pacote npm: o import de
|
|
78
|
+
// santoid-sdk/client/liveness-capture tambem recebe o React embutido, e nao o
|
|
79
|
+
// do app que instalou o SDK.
|
|
80
|
+
const livenessCapturePackageConfig = {
|
|
81
|
+
entry: './src/client/liveness-capture/index.tsx',
|
|
82
|
+
target: 'web',
|
|
83
|
+
output: {
|
|
84
|
+
path: path.resolve(__dirname, './dist/client/liveness-capture'),
|
|
85
|
+
filename: 'index.js',
|
|
86
|
+
libraryTarget: 'commonjs2',
|
|
87
|
+
},
|
|
88
|
+
}
|
|
89
|
+
|
|
56
90
|
module.exports = (env, argv) => {
|
|
57
91
|
if (argv.mode === 'development') {
|
|
58
92
|
generalConfig.devtool = 'cheap-module-source-map'
|
|
@@ -60,7 +94,16 @@ module.exports = (env, argv) => {
|
|
|
60
94
|
throw new Error('Specify env')
|
|
61
95
|
}
|
|
62
96
|
|
|
63
|
-
|
|
97
|
+
const configs = [browserConfig, livenessCaptureBrowserConfig, livenessCapturePackageConfig]
|
|
98
|
+
|
|
99
|
+
configs.forEach((config) => Object.assign(config, generalConfig))
|
|
100
|
+
|
|
101
|
+
// Arquivo unico: um chunk separado seria buscado relativo ao app hospedeiro,
|
|
102
|
+
// onde ele nao existe.
|
|
103
|
+
const singleFile = new webpack.optimize.LimitChunkCountPlugin({ maxChunks: 1 })
|
|
104
|
+
|
|
105
|
+
livenessCaptureBrowserConfig.plugins = [...generalConfig.plugins, singleFile]
|
|
106
|
+
livenessCapturePackageConfig.plugins = [singleFile]
|
|
64
107
|
|
|
65
|
-
return
|
|
108
|
+
return configs
|
|
66
109
|
}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { type ISDKOptions, type TPositions, type IWebSocketMessage } from '../../../../utils/types';
|
|
2
|
-
import { type IFrameControls } from '../../utils/getNextFrame';
|
|
3
|
-
import { type AbstractWebSocket } from '../../../../utils/websocket';
|
|
4
|
-
export declare class LivenessDetectionService<TFrameType, TMediaType> {
|
|
5
|
-
options: ISDKOptions<TFrameType, TMediaType>;
|
|
6
|
-
abstractWebSocket: AbstractWebSocket<TFrameType, TMediaType>;
|
|
7
|
-
frameGetControls: IFrameControls<TFrameType, TMediaType>;
|
|
8
|
-
currentStep: TPositions;
|
|
9
|
-
lastSentBytes: TFrameType;
|
|
10
|
-
pauseSendingFramesToWebSocket: boolean;
|
|
11
|
-
websocketClosedBySDK: boolean;
|
|
12
|
-
validationSuccess: boolean;
|
|
13
|
-
canSendNextBytes: boolean;
|
|
14
|
-
endCalled: boolean;
|
|
15
|
-
cancelSendingFramesToWebsocket?: () => void;
|
|
16
|
-
successFrames: Record<TPositions, TFrameType>;
|
|
17
|
-
constructor(options: ISDKOptions<TFrameType, TMediaType>, abstractWebSocket: AbstractWebSocket<TFrameType, TMediaType>);
|
|
18
|
-
onWebSocketMessage(event: {
|
|
19
|
-
data: any;
|
|
20
|
-
}): Promise<IWebSocketMessage>;
|
|
21
|
-
stopLivenessDetection(): Promise<void>;
|
|
22
|
-
sendFramesToWebSocket(): Promise<void>;
|
|
23
|
-
onConnect(): Promise<void>;
|
|
24
|
-
onError(): Promise<void>;
|
|
25
|
-
resumeGettingFrames(): void;
|
|
26
|
-
pauseGettingFrames(): void;
|
|
27
|
-
getVideoStream(): TMediaType | undefined;
|
|
28
|
-
}
|
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.LivenessDetectionService = void 0;
|
|
4
|
-
const error_1 = require("../../../../utils/error");
|
|
5
|
-
const getNextFrame_1 = require("../../utils/getNextFrame");
|
|
6
|
-
const utils_1 = require("../../../../utils");
|
|
7
|
-
const constants_1 = require("../../../../utils/constants");
|
|
8
|
-
class LivenessDetectionService {
|
|
9
|
-
constructor(options, abstractWebSocket) {
|
|
10
|
-
this.frameGetControls = {};
|
|
11
|
-
this.currentStep = 'front';
|
|
12
|
-
this.pauseSendingFramesToWebSocket = false;
|
|
13
|
-
this.websocketClosedBySDK = false;
|
|
14
|
-
this.validationSuccess = false;
|
|
15
|
-
this.canSendNextBytes = true;
|
|
16
|
-
this.endCalled = false;
|
|
17
|
-
this.cancelSendingFramesToWebsocket = undefined;
|
|
18
|
-
this.successFrames = {
|
|
19
|
-
front: undefined,
|
|
20
|
-
right: undefined,
|
|
21
|
-
left: undefined,
|
|
22
|
-
up: undefined,
|
|
23
|
-
bottom: undefined,
|
|
24
|
-
};
|
|
25
|
-
this.options = options;
|
|
26
|
-
this.abstractWebSocket = abstractWebSocket;
|
|
27
|
-
}
|
|
28
|
-
async onWebSocketMessage(event) {
|
|
29
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
30
|
-
const message = event.data;
|
|
31
|
-
const parsedMessage = JSON.parse(message);
|
|
32
|
-
if ((parsedMessage === null || parsedMessage === void 0 ? void 0 : parsedMessage.validation) && this.currentStep) {
|
|
33
|
-
this.successFrames[this.currentStep] = this.lastSentBytes;
|
|
34
|
-
}
|
|
35
|
-
if ((parsedMessage === null || parsedMessage === void 0 ? void 0 : parsedMessage.next_step) && !parsedMessage.error) {
|
|
36
|
-
this.currentStep = parsedMessage.next_step;
|
|
37
|
-
await ((_b = (_a = this.options).onNextStep) === null || _b === void 0 ? void 0 : _b.call(_a, parsedMessage.next_step));
|
|
38
|
-
await ((_d = (_c = this.options)[`on${(0, utils_1.capitalizeFirstLetter)(parsedMessage.next_step)}Step`]) === null || _d === void 0 ? void 0 : _d.call(_c));
|
|
39
|
-
}
|
|
40
|
-
if (parsedMessage) {
|
|
41
|
-
this.canSendNextBytes = !!(parsedMessage === null || parsedMessage === void 0 ? void 0 : parsedMessage.can_send_next_bytes);
|
|
42
|
-
}
|
|
43
|
-
if (parsedMessage === null || parsedMessage === void 0 ? void 0 : parsedMessage.success) {
|
|
44
|
-
this.successFrames.bottom = this.lastSentBytes;
|
|
45
|
-
this.validationSuccess = true;
|
|
46
|
-
await ((_f = (_e = this.options).onSuccess) === null || _f === void 0 ? void 0 : _f.call(_e, {
|
|
47
|
-
livenessId: parsedMessage.livenessId,
|
|
48
|
-
successFrames: this.successFrames,
|
|
49
|
-
}));
|
|
50
|
-
await this.stopLivenessDetection();
|
|
51
|
-
}
|
|
52
|
-
if (parsedMessage === null || parsedMessage === void 0 ? void 0 : parsedMessage.error) {
|
|
53
|
-
await ((_h = (_g = this.options).onError) === null || _h === void 0 ? void 0 : _h.call(_g, new error_1.SDKError({
|
|
54
|
-
message: 'Wrong position',
|
|
55
|
-
code: error_1.ELivenessDetectionErrorCodes.WRONG_POSITION,
|
|
56
|
-
fatal: false,
|
|
57
|
-
})));
|
|
58
|
-
}
|
|
59
|
-
return parsedMessage;
|
|
60
|
-
}
|
|
61
|
-
async stopLivenessDetection() {
|
|
62
|
-
var _a, _b, _c, _d, _e;
|
|
63
|
-
await (0, utils_1.waitFor)(() => {
|
|
64
|
-
return !!this.cancelSendingFramesToWebsocket;
|
|
65
|
-
});
|
|
66
|
-
(_a = this.cancelSendingFramesToWebsocket) === null || _a === void 0 ? void 0 : _a.call(this);
|
|
67
|
-
await ((_c = (_b = this.frameGetControls).stopGettingFrames) === null || _c === void 0 ? void 0 : _c.call(_b));
|
|
68
|
-
this.abstractWebSocket.disconnectFromWebSocket();
|
|
69
|
-
if (!this.endCalled) {
|
|
70
|
-
await ((_e = (_d = this.options).onEnd) === null || _e === void 0 ? void 0 : _e.call(_d));
|
|
71
|
-
this.endCalled = true;
|
|
72
|
-
}
|
|
73
|
-
this.websocketClosedBySDK = true;
|
|
74
|
-
}
|
|
75
|
-
async sendFramesToWebSocket() {
|
|
76
|
-
var _a, _b;
|
|
77
|
-
try {
|
|
78
|
-
if (this.canSendNextBytes && !this.pauseSendingFramesToWebSocket) {
|
|
79
|
-
const bytes = await ((_b = (_a = this.frameGetControls).getNextFrame) === null || _b === void 0 ? void 0 : _b.call(_a));
|
|
80
|
-
if (bytes) {
|
|
81
|
-
this.abstractWebSocket.send(bytes);
|
|
82
|
-
this.lastSentBytes = bytes;
|
|
83
|
-
this.canSendNextBytes = false;
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
catch (err) {
|
|
88
|
-
await this.stopLivenessDetection();
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
async onConnect() {
|
|
92
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
93
|
-
try {
|
|
94
|
-
if (this.options.getNextFrame) {
|
|
95
|
-
this.frameGetControls.startGettingFrames = this.options.startGettingFrames;
|
|
96
|
-
this.frameGetControls.getNextFrame = this.options.getNextFrame;
|
|
97
|
-
this.frameGetControls.stopGettingFrames = this.options.stopGettingFrames;
|
|
98
|
-
this.frameGetControls.videoStream = await ((_b = (_a = this.options).startGettingFrames) === null || _b === void 0 ? void 0 : _b.call(_a));
|
|
99
|
-
}
|
|
100
|
-
else {
|
|
101
|
-
const defaultFrameControls = await (0, getNextFrame_1.getDefaultFrameControls)();
|
|
102
|
-
this.frameGetControls.startGettingFrames = defaultFrameControls.startGettingFrames;
|
|
103
|
-
this.frameGetControls.getNextFrame = defaultFrameControls.getNextFrame;
|
|
104
|
-
this.frameGetControls.stopGettingFrames = defaultFrameControls.stopGettingFrames;
|
|
105
|
-
this.frameGetControls.videoStream = await ((_d = (_c = this.frameGetControls).startGettingFrames) === null || _d === void 0 ? void 0 : _d.call(_c));
|
|
106
|
-
}
|
|
107
|
-
await ((_f = (_e = this.options).onStart) === null || _f === void 0 ? void 0 : _f.call(_e, { videoStream: this.getVideoStream() }));
|
|
108
|
-
await ((_h = (_g = this.options).onNextStep) === null || _h === void 0 ? void 0 : _h.call(_g, 'front'));
|
|
109
|
-
await ((_k = (_j = this.options).onFrontStep) === null || _k === void 0 ? void 0 : _k.call(_j));
|
|
110
|
-
this.cancelSendingFramesToWebsocket = (0, utils_1.callAsyncFunctionEveryXSeconds)(async () => { await this.sendFramesToWebSocket(); }, constants_1.SEND_FRAMES_INTERVAL_MS);
|
|
111
|
-
}
|
|
112
|
-
catch (err) {
|
|
113
|
-
await this.onError();
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
async onError() {
|
|
117
|
-
var _a, _b;
|
|
118
|
-
if (!this.validationSuccess) {
|
|
119
|
-
await ((_b = (_a = this.options).onError) === null || _b === void 0 ? void 0 : _b.call(_a, new error_1.SDKError({
|
|
120
|
-
message: 'Internal Error',
|
|
121
|
-
code: error_1.EDefaultErrorCodes.INTERNAL_ERROR,
|
|
122
|
-
fatal: false,
|
|
123
|
-
})));
|
|
124
|
-
await this.stopLivenessDetection();
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
resumeGettingFrames() {
|
|
128
|
-
this.pauseSendingFramesToWebSocket = false;
|
|
129
|
-
}
|
|
130
|
-
pauseGettingFrames() {
|
|
131
|
-
this.pauseSendingFramesToWebSocket = true;
|
|
132
|
-
}
|
|
133
|
-
getVideoStream() {
|
|
134
|
-
var _a;
|
|
135
|
-
return (_a = this.frameGetControls) === null || _a === void 0 ? void 0 : _a.videoStream;
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
exports.LivenessDetectionService = LivenessDetectionService;
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { type ISDKOptions } from '../../../../utils/types';
|
|
2
|
-
export type TFrameType = File | Blob;
|
|
3
|
-
export type TMediaType = MediaStream | undefined;
|
|
4
|
-
type ILivenessDetectionParams = Omit<ISDKOptions<TFrameType, TMediaType>, 'onStart'> & {
|
|
5
|
-
onStart?: (params: {
|
|
6
|
-
videoStream: TMediaType;
|
|
7
|
-
}) => void | Promise<void>;
|
|
8
|
-
};
|
|
9
|
-
/**
|
|
10
|
-
* @deprecated Prova de vida v1, sobre o detector in-house (WebSocket com o
|
|
11
|
-
* desafio de cinco posicoes). Substituida por {@link livenessSession}, que usa
|
|
12
|
-
* o AWS Rekognition Face Liveness.
|
|
13
|
-
*
|
|
14
|
-
* Continua funcionando e sera mantida ate a migracao dos clientes, mas nao
|
|
15
|
-
* recebe mais evolucao. Codigo novo deve usar livenessSession.
|
|
16
|
-
*/
|
|
17
|
-
export declare function livenessDetection(options: ILivenessDetectionParams): {
|
|
18
|
-
getVideoStream: () => TMediaType;
|
|
19
|
-
stopLivenessDetection: () => Promise<void>;
|
|
20
|
-
resumeGettingFrames: () => void;
|
|
21
|
-
pauseGettingFrames: () => void;
|
|
22
|
-
};
|
|
23
|
-
export {};
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.livenessDetection = void 0;
|
|
4
|
-
const Service_1 = require("./Service");
|
|
5
|
-
const error_1 = require("../../../../utils/error");
|
|
6
|
-
const websocket_1 = require("../../../../utils/websocket");
|
|
7
|
-
const index_1 = require("../../utils/index");
|
|
8
|
-
/**
|
|
9
|
-
* @deprecated Prova de vida v1, sobre o detector in-house (WebSocket com o
|
|
10
|
-
* desafio de cinco posicoes). Substituida por {@link livenessSession}, que usa
|
|
11
|
-
* o AWS Rekognition Face Liveness.
|
|
12
|
-
*
|
|
13
|
-
* Continua funcionando e sera mantida ate a migracao dos clientes, mas nao
|
|
14
|
-
* recebe mais evolucao. Codigo novo deve usar livenessSession.
|
|
15
|
-
*/
|
|
16
|
-
function livenessDetection(options) {
|
|
17
|
-
var _a;
|
|
18
|
-
try {
|
|
19
|
-
const abstractWebSocket = new websocket_1.AbstractWebSocket({ WebSocketClass: (_a = options.CustomWebSocketClass) !== null && _a !== void 0 ? _a : WebSocket, decodeJwt: index_1.decodeJwt }, options);
|
|
20
|
-
abstractWebSocket.startConnection();
|
|
21
|
-
const livenessDetectionService = new Service_1.LivenessDetectionService(options, abstractWebSocket);
|
|
22
|
-
abstractWebSocket.waitForWebSocketConnection()
|
|
23
|
-
.then(() => { livenessDetectionService.onConnect(); })
|
|
24
|
-
.catch(() => { livenessDetectionService.onError(); });
|
|
25
|
-
abstractWebSocket.addListener('message', (event) => {
|
|
26
|
-
livenessDetectionService.onWebSocketMessage(event);
|
|
27
|
-
});
|
|
28
|
-
abstractWebSocket.addListener('error', () => {
|
|
29
|
-
livenessDetectionService.onError();
|
|
30
|
-
});
|
|
31
|
-
abstractWebSocket.addListener('close', () => {
|
|
32
|
-
livenessDetectionService.onError();
|
|
33
|
-
});
|
|
34
|
-
return {
|
|
35
|
-
// The use of arrow functions is mandatory, as without them the "this" value changes over time
|
|
36
|
-
getVideoStream: () => {
|
|
37
|
-
return livenessDetectionService.getVideoStream();
|
|
38
|
-
},
|
|
39
|
-
stopLivenessDetection: async () => {
|
|
40
|
-
await livenessDetectionService.stopLivenessDetection();
|
|
41
|
-
},
|
|
42
|
-
resumeGettingFrames: () => {
|
|
43
|
-
livenessDetectionService.resumeGettingFrames();
|
|
44
|
-
},
|
|
45
|
-
pauseGettingFrames: () => {
|
|
46
|
-
livenessDetectionService.pauseGettingFrames();
|
|
47
|
-
},
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
catch (err) {
|
|
51
|
-
throw new error_1.SDKError({
|
|
52
|
-
message: 'Error while starting SDK',
|
|
53
|
-
code: error_1.EDefaultErrorCodes.INITIALIZATION_ERROR,
|
|
54
|
-
fatal: true,
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
exports.livenessDetection = livenessDetection;
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { LivenessDetectionService } from '../../../../client/liveness/methods/livenessDetection/Service';
|
|
2
|
-
import { type ISDKOptions } from '../../../../utils/types';
|
|
3
|
-
export declare class NodeLivenessDetectionService<TFrameType, TMediaType> extends LivenessDetectionService<TFrameType, TMediaType> {
|
|
4
|
-
options: ISDKOptions<TFrameType, TMediaType>;
|
|
5
|
-
onConnect(): Promise<void>;
|
|
6
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.NodeLivenessDetectionService = void 0;
|
|
4
|
-
const Service_1 = require("../../../../client/liveness/methods/livenessDetection/Service");
|
|
5
|
-
const constants_1 = require("../../../../utils/constants");
|
|
6
|
-
const utils_1 = require("../../../../utils");
|
|
7
|
-
class NodeLivenessDetectionService extends Service_1.LivenessDetectionService {
|
|
8
|
-
async onConnect() {
|
|
9
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
10
|
-
this.frameGetControls.startGettingFrames = this.options.startGettingFrames;
|
|
11
|
-
this.frameGetControls.getNextFrame = this.options.getNextFrame;
|
|
12
|
-
this.frameGetControls.stopGettingFrames = this.options.stopGettingFrames;
|
|
13
|
-
await ((_b = (_a = this.options).startGettingFrames) === null || _b === void 0 ? void 0 : _b.call(_a));
|
|
14
|
-
await ((_d = (_c = this.options).onStart) === null || _d === void 0 ? void 0 : _d.call(_c));
|
|
15
|
-
await ((_f = (_e = this.options).onNextStep) === null || _f === void 0 ? void 0 : _f.call(_e, 'front'));
|
|
16
|
-
await ((_h = (_g = this.options).onFrontStep) === null || _h === void 0 ? void 0 : _h.call(_g));
|
|
17
|
-
this.cancelSendingFramesToWebsocket = (0, utils_1.callAsyncFunctionEveryXSeconds)(async () => { await this.sendFramesToWebSocket(); }, constants_1.SEND_FRAMES_INTERVAL_MS);
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
exports.NodeLivenessDetectionService = NodeLivenessDetectionService;
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { type Data } from 'ws';
|
|
2
|
-
import { type ISDKOptions } from '../../../../utils/types';
|
|
3
|
-
export type TFrameType = Data;
|
|
4
|
-
export type TMediaType = undefined;
|
|
5
|
-
type ILivenessDetectionParams = Omit<ISDKOptions<TFrameType, TMediaType>, 'onStart'> & {
|
|
6
|
-
onStart?: () => void | Promise<void>;
|
|
7
|
-
};
|
|
8
|
-
export declare function livenessDetection(options: ILivenessDetectionParams): {
|
|
9
|
-
stopLivenessDetection: () => Promise<void>;
|
|
10
|
-
resumeGettingFrames: () => void;
|
|
11
|
-
pauseGettingFrames: () => void;
|
|
12
|
-
};
|
|
13
|
-
export {};
|
|
@@ -1,50 +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.livenessDetection = void 0;
|
|
7
|
-
const ws_1 = __importDefault(require("ws"));
|
|
8
|
-
const error_1 = require("../../../../utils/error");
|
|
9
|
-
const websocket_1 = require("../../../../utils/websocket");
|
|
10
|
-
const index_1 = require("../../utils/index");
|
|
11
|
-
const Service_1 = require("./Service");
|
|
12
|
-
function livenessDetection(options) {
|
|
13
|
-
var _a;
|
|
14
|
-
try {
|
|
15
|
-
const abstractWebSocket = new websocket_1.AbstractWebSocket({ WebSocketClass: (_a = options.CustomWebSocketClass) !== null && _a !== void 0 ? _a : ws_1.default, decodeJwt: index_1.decodeJwt }, options);
|
|
16
|
-
abstractWebSocket.startConnection();
|
|
17
|
-
const livenessDetectionHandler = new Service_1.NodeLivenessDetectionService(options, abstractWebSocket);
|
|
18
|
-
abstractWebSocket.waitForWebSocketConnection()
|
|
19
|
-
.then(() => { livenessDetectionHandler.onConnect(); })
|
|
20
|
-
.catch(() => { livenessDetectionHandler.onError(); });
|
|
21
|
-
abstractWebSocket.addListener('message', (data) => {
|
|
22
|
-
livenessDetectionHandler.onWebSocketMessage({ data: Buffer.from(data).toString() });
|
|
23
|
-
});
|
|
24
|
-
abstractWebSocket.addListener('error', () => {
|
|
25
|
-
livenessDetectionHandler.onError();
|
|
26
|
-
});
|
|
27
|
-
abstractWebSocket.addListener('close', () => {
|
|
28
|
-
livenessDetectionHandler.onError();
|
|
29
|
-
});
|
|
30
|
-
return {
|
|
31
|
-
stopLivenessDetection: async () => {
|
|
32
|
-
await livenessDetectionHandler.stopLivenessDetection();
|
|
33
|
-
},
|
|
34
|
-
resumeGettingFrames: () => {
|
|
35
|
-
livenessDetectionHandler.resumeGettingFrames();
|
|
36
|
-
},
|
|
37
|
-
pauseGettingFrames: () => {
|
|
38
|
-
livenessDetectionHandler.pauseGettingFrames();
|
|
39
|
-
},
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
catch (err) {
|
|
43
|
-
throw new error_1.SDKError({
|
|
44
|
-
message: 'Error while starting SDK',
|
|
45
|
-
code: error_1.EDefaultErrorCodes.INITIALIZATION_ERROR,
|
|
46
|
-
fatal: true,
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
exports.livenessDetection = livenessDetection;
|
package/utils/websocket.d.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
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 {};
|
package/utils/websocket.js
DELETED
|
@@ -1,62 +0,0 @@
|
|
|
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
|
-
};
|
|
18
|
-
if (this.sdkOptions.customId) {
|
|
19
|
-
query.customerRequestId = this.sdkOptions.customId;
|
|
20
|
-
}
|
|
21
|
-
if (this.sdkOptions.useBillingAccounts) {
|
|
22
|
-
query.clientCredentials = true;
|
|
23
|
-
}
|
|
24
|
-
const queryStr = Object.entries(query).map(itemsArr => itemsArr.join('=')).join('&');
|
|
25
|
-
this.websocket = new this.classOptions.WebSocketClass(`${(_b = this.sdkOptions.customWebSocketUrl) !== null && _b !== void 0 ? _b : constants_1.WEBSOCKET_BASE_URL}?${queryStr}`);
|
|
26
|
-
}
|
|
27
|
-
async waitForWebSocketConnection() {
|
|
28
|
-
await new Promise((resolve) => {
|
|
29
|
-
const intervalKey = setInterval(() => {
|
|
30
|
-
if ([3, 1].includes(this.websocket.readyState)) {
|
|
31
|
-
clearInterval(intervalKey);
|
|
32
|
-
resolve();
|
|
33
|
-
}
|
|
34
|
-
}, 5);
|
|
35
|
-
});
|
|
36
|
-
if (this.websocket.readyState === 3) {
|
|
37
|
-
throw new Error('Cannot connect to server');
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
disconnectFromWebSocket() {
|
|
41
|
-
var _a, _b;
|
|
42
|
-
if (![2, 3].includes(this.websocket.readyState)) {
|
|
43
|
-
(_b = (_a = this.websocket).close) === null || _b === void 0 ? void 0 : _b.call(_a);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
get readyState() {
|
|
47
|
-
return this.websocket.readyState;
|
|
48
|
-
}
|
|
49
|
-
addListener(identifier, listener) {
|
|
50
|
-
var _a, _b;
|
|
51
|
-
if (this.websocket.on) {
|
|
52
|
-
this.websocket.on(identifier, listener);
|
|
53
|
-
}
|
|
54
|
-
else {
|
|
55
|
-
(_b = (_a = this.websocket).addEventListener) === null || _b === void 0 ? void 0 : _b.call(_a, identifier, listener);
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
send(payload) {
|
|
59
|
-
this.websocket.send(payload);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
exports.AbstractWebSocket = AbstractWebSocket;
|