santoid-sdk 2.0.2 → 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.
Files changed (57) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/README.md +259 -107
  3. package/api/AbstractService.d.ts +21 -0
  4. package/api/AbstractService.js +32 -0
  5. package/api/FaceMatchService.d.ts +9 -0
  6. package/api/FaceMatchService.js +15 -0
  7. package/api/TypificationService.d.ts +46 -0
  8. package/api/TypificationService.js +15 -0
  9. package/browser/liveness/index.js +1 -1
  10. package/liveness/index.d.ts +1 -3
  11. package/liveness/index.js +2 -19
  12. package/liveness/methods/livenessDetection/Service.d.ts +28 -0
  13. package/liveness/methods/livenessDetection/Service.js +130 -0
  14. package/liveness/methods/livenessDetection/index.d.ts +15 -0
  15. package/liveness/methods/livenessDetection/index.js +46 -0
  16. package/liveness/methods/uploadIdentificationDocument/Service.d.ts +62 -0
  17. package/liveness/methods/uploadIdentificationDocument/Service.js +134 -0
  18. package/liveness/methods/uploadIdentificationDocument/index.d.ts +24 -0
  19. package/liveness/methods/uploadIdentificationDocument/index.js +26 -0
  20. package/liveness/utils/getNextFrame.d.ts +6 -5
  21. package/liveness/utils/getNextFrame.js +24 -19
  22. package/liveness/utils/index.d.ts +2 -2
  23. package/node/liveness/index.d.ts +1 -3
  24. package/node/liveness/index.js +2 -19
  25. package/node/liveness/methods/livenessDetection/Service.d.ts +6 -0
  26. package/node/liveness/methods/livenessDetection/Service.js +20 -0
  27. package/node/liveness/methods/livenessDetection/index.d.ts +13 -0
  28. package/node/liveness/methods/livenessDetection/index.js +46 -0
  29. package/node/liveness/methods/uploadIdentificationDocument/Service.d.ts +4 -0
  30. package/node/liveness/methods/uploadIdentificationDocument/Service.js +19 -0
  31. package/node/liveness/methods/uploadIdentificationDocument/index.d.ts +25 -0
  32. package/node/liveness/methods/uploadIdentificationDocument/index.js +28 -0
  33. package/node/liveness/utils/index.d.ts +2 -2
  34. package/package.json +3 -3
  35. package/utils/error.d.ts +24 -0
  36. package/utils/error.js +27 -0
  37. package/utils/index.d.ts +7 -0
  38. package/utils/index.js +44 -0
  39. package/utils/types.d.ts +25 -14
  40. package/utils/websocket.d.ts +18 -0
  41. package/utils/websocket.js +57 -0
  42. package/liveness/methods/livenessDetection.d.ts +0 -6
  43. package/liveness/methods/livenessDetection.js +0 -129
  44. package/liveness/methods/uploadIdentificationDocument.d.ts +0 -91
  45. package/liveness/methods/uploadIdentificationDocument.js +0 -234
  46. package/liveness/utils/types.d.ts +0 -5
  47. package/liveness/utils/types.js +0 -17
  48. package/liveness/utils/websocket.d.ts +0 -3
  49. package/liveness/utils/websocket.js +0 -34
  50. package/node/liveness/methods/livenessDetection.d.ts +0 -6
  51. package/node/liveness/methods/livenessDetection.js +0 -114
  52. package/node/liveness/methods/uploadIdentificationDocument.d.ts +0 -91
  53. package/node/liveness/methods/uploadIdentificationDocument.js +0 -235
  54. package/node/liveness/utils/types.d.ts +0 -6
  55. package/node/liveness/utils/types.js +0 -17
  56. package/node/liveness/utils/websocket.d.ts +0 -5
  57. package/node/liveness/utils/websocket.js +0 -39
@@ -0,0 +1,134 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.UploadIdentificationDocumentService = void 0;
4
+ const TypificationService_1 = require("../../../api/TypificationService");
5
+ const FaceMatchService_1 = require("../../../api/FaceMatchService");
6
+ const error_1 = require("../../../utils/error");
7
+ const index_1 = require("../../utils/index");
8
+ class UploadIdentificationDocumentService {
9
+ constructor(options, internalOptions) {
10
+ this.results = {
11
+ uploadedDocument: null,
12
+ typification: { status: null, results: null, loading: false, error: null },
13
+ liveness: { status: null, results: null, loading: false, error: null },
14
+ faceMatch: { status: null, results: null, loading: false, error: null },
15
+ };
16
+ this.options = options;
17
+ this.internalOptions = internalOptions;
18
+ this.typificationService = new TypificationService_1.TypificationService(options, { FormDataClass: FormData, tryDecodeJwt: index_1.tryDecodeJwt });
19
+ this.faceMatchService = new FaceMatchService_1.FaceMatchService(options, { FormDataClass: FormData, tryDecodeJwt: index_1.tryDecodeJwt });
20
+ }
21
+ getResults() {
22
+ return this.results;
23
+ }
24
+ async updateResults(updatedResults) {
25
+ var _a, _b, _c, _d, _e, _f;
26
+ this.results = Object.assign(Object.assign({}, this.results), updatedResults);
27
+ await ((_b = (_a = this.options).onUpdate) === null || _b === void 0 ? void 0 : _b.call(_a, this.results));
28
+ if (Object.entries(this.results).every(([key, value]) => key === 'uploadedDocument' || !!value.results)) {
29
+ await ((_d = (_c = this.options).onSuccess) === null || _d === void 0 ? void 0 : _d.call(_c, this.results));
30
+ await ((_f = (_e = this.options).onEnd) === null || _f === void 0 ? void 0 : _f.call(_e));
31
+ return;
32
+ }
33
+ if (!this.results.faceMatch.results && this.results.faceMatch.status !== 'error') {
34
+ void this.tryStartFaceMatch();
35
+ }
36
+ }
37
+ updateUploadedDocument(file) {
38
+ this.results.uploadedDocument = file;
39
+ if (!this.results.faceMatch.results) {
40
+ void this.tryStartFaceMatch();
41
+ }
42
+ }
43
+ async startDocumentUpload(file) {
44
+ var _a, _b, _c;
45
+ try {
46
+ void this.updateResults({ typification: { status: null, results: null, loading: true, error: null } });
47
+ this.updateUploadedDocument(file);
48
+ const typificationResults = await this.typificationService.predict(file);
49
+ void this.updateResults({ typification: { status: 'success', results: typificationResults, loading: false, error: null } });
50
+ }
51
+ catch (err) {
52
+ await ((_b = (_a = this.options).onError) === null || _b === void 0 ? void 0 : _b.call(_a, new error_1.SDKError({
53
+ message: 'Error during typification',
54
+ code: error_1.EUploadIdentificationDocumentErrorCodes.TYPIFICATION_ERROR,
55
+ details: err,
56
+ })));
57
+ void this.updateResults({ typification: { status: 'error', results: null, loading: false, error: (_c = err === null || err === void 0 ? void 0 : err.response) === null || _c === void 0 ? void 0 : _c.data } });
58
+ }
59
+ }
60
+ startLivenessDetection(startLivenessDetectionOptions) {
61
+ var _a, _b, _c;
62
+ const adaptedLivenessDetection = Object.assign(Object.assign({}, this.options.livenessDetectionOptions), startLivenessDetectionOptions);
63
+ void this.updateResults({ liveness: { results: null, status: null, loading: true, error: null } });
64
+ try {
65
+ return this.internalOptions.livenessDetection(Object.assign(Object.assign({ domain: this.options.domain, customId: this.options.customId, customWebSocketUrl: this.options.customWebSocketUrl, token: this.options.token, track: this.options.track }, adaptedLivenessDetection), { onSuccess: async (livenessResults) => {
66
+ var _a;
67
+ await ((_a = adaptedLivenessDetection === null || adaptedLivenessDetection === void 0 ? void 0 : adaptedLivenessDetection.onSuccess) === null || _a === void 0 ? void 0 : _a.call(adaptedLivenessDetection, livenessResults));
68
+ void this.updateResults({
69
+ liveness: {
70
+ status: 'success',
71
+ results: (livenessResults),
72
+ loading: false,
73
+ error: null,
74
+ },
75
+ });
76
+ }, onError: async (livenessErrorDetails) => {
77
+ var _a, _b, _c;
78
+ await ((_a = adaptedLivenessDetection === null || adaptedLivenessDetection === void 0 ? void 0 : adaptedLivenessDetection.onError) === null || _a === void 0 ? void 0 : _a.call(adaptedLivenessDetection, livenessErrorDetails));
79
+ await ((_c = (_b = this.options).onError) === null || _c === void 0 ? void 0 : _c.call(_b, livenessErrorDetails));
80
+ void this.updateResults({
81
+ liveness: {
82
+ status: 'error',
83
+ results: null,
84
+ loading: (livenessErrorDetails === null || livenessErrorDetails === void 0 ? void 0 : livenessErrorDetails.code) === 'wrong-position',
85
+ error: livenessErrorDetails,
86
+ },
87
+ });
88
+ } }));
89
+ }
90
+ catch (err) {
91
+ void ((_b = (_a = this.options).onError) === null || _b === void 0 ? void 0 : _b.call(_a, new error_1.SDKError({
92
+ message: 'Error during liveness detection',
93
+ code: error_1.EUploadIdentificationDocumentErrorCodes.LIVENESS_DETECTION_ERROR,
94
+ details: err,
95
+ })));
96
+ void this.updateResults({ liveness: { status: 'error', results: null, loading: false, error: (_c = err === null || err === void 0 ? void 0 : err.response) === null || _c === void 0 ? void 0 : _c.data } });
97
+ }
98
+ }
99
+ async startFaceMatch(firstImage, secondImage) {
100
+ var _a, _b, _c;
101
+ try {
102
+ void this.updateResults({ faceMatch: { status: null, results: null, loading: true, error: null } });
103
+ const faceMatchResults = await this.faceMatchService.faceMatch(firstImage, secondImage);
104
+ void this.updateResults({ faceMatch: { results: faceMatchResults, status: 'success', loading: false, error: null } });
105
+ }
106
+ catch (err) {
107
+ await ((_b = (_a = this.options).onError) === null || _b === void 0 ? void 0 : _b.call(_a, new error_1.SDKError({
108
+ message: 'Error when comparing the face with the document',
109
+ code: error_1.EUploadIdentificationDocumentErrorCodes.FACE_MATCH_ERROR,
110
+ details: err,
111
+ })));
112
+ void this.updateResults({ faceMatch: { results: null, status: 'error', loading: false, error: (_c = err === null || err === void 0 ? void 0 : err.response) === null || _c === void 0 ? void 0 : _c.data } });
113
+ }
114
+ }
115
+ async tryStartFaceMatch() {
116
+ var _a, _b, _c;
117
+ if (this.results.uploadedDocument &&
118
+ ((_a = this.results.liveness.results) === null || _a === void 0 ? void 0 : _a.successFrames.front) &&
119
+ !this.results.faceMatch.loading) {
120
+ await this.startFaceMatch(this.results.uploadedDocument, this.results.liveness.results.successFrames.front);
121
+ }
122
+ else {
123
+ await ((_c = (_b = this.options).onError) === null || _c === void 0 ? void 0 : _c.call(_b, new error_1.SDKError({
124
+ message: 'Unavailable faces',
125
+ code: error_1.EUploadIdentificationDocumentErrorCodes.FACE_MATCH_UNAVAILABLE_FACES_ERROR,
126
+ })));
127
+ }
128
+ }
129
+ startAll(file, startLivenessDetectionOptions) {
130
+ void this.startDocumentUpload(file);
131
+ void this.startLivenessDetection(startLivenessDetectionOptions);
132
+ }
133
+ }
134
+ exports.UploadIdentificationDocumentService = UploadIdentificationDocumentService;
@@ -0,0 +1,24 @@
1
+ import { type IServiceOptions } from './Service';
2
+ import { type TFrameType, type TMediaType } from '../livenessDetection';
3
+ type TFileType = Blob | File;
4
+ export declare function uploadIdentificationDocument(options: IServiceOptions<TFrameType, TMediaType, TFileType>): {
5
+ startDocumentUpload: (file: TFileType) => Promise<void>;
6
+ startLivenessDetection: (startLivenessDetectionOptions?: (Omit<import("../../../utils/types").ISDKOptions<TFrameType, TMediaType>, "token" | "track"> & {
7
+ track?: string | undefined;
8
+ token?: string | undefined;
9
+ }) | undefined) => (Omit<{
10
+ getVideoStream: () => TMediaType;
11
+ stopLivenessDetection: () => Promise<void>;
12
+ resumeGettingFrames: () => void;
13
+ pauseGettingFrames: () => void;
14
+ }, "getVideoStream"> & {
15
+ getVideoStream?: (() => TMediaType) | undefined;
16
+ }) | undefined;
17
+ startFaceComparison: () => Promise<void>;
18
+ startAll: (file: TFileType, startLivenessDetectionOptions?: (Omit<import("../../../utils/types").ISDKOptions<TFrameType, TMediaType>, "token" | "track"> & {
19
+ track?: string | undefined;
20
+ token?: string | undefined;
21
+ }) | undefined) => void;
22
+ getResults: () => import("./Service").IUploadIdentificationDocumentResults<TFileType>;
23
+ };
24
+ export {};
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.uploadIdentificationDocument = void 0;
4
+ const Service_1 = require("./Service");
5
+ const livenessDetection_1 = require("../livenessDetection");
6
+ function uploadIdentificationDocument(options) {
7
+ const uploadIdentificationDocumentService = new Service_1.UploadIdentificationDocumentService(options, { livenessDetection: livenessDetection_1.livenessDetection });
8
+ return {
9
+ startDocumentUpload: async (...rest) => {
10
+ await uploadIdentificationDocumentService.startDocumentUpload(...rest);
11
+ },
12
+ startLivenessDetection: (...rest) => {
13
+ return uploadIdentificationDocumentService.startLivenessDetection(...rest);
14
+ },
15
+ startFaceComparison: async (...rest) => {
16
+ await uploadIdentificationDocumentService.tryStartFaceMatch(...rest);
17
+ },
18
+ startAll: (...rest) => {
19
+ uploadIdentificationDocumentService.startAll(...rest);
20
+ },
21
+ getResults: (...rest) => {
22
+ return uploadIdentificationDocumentService.getResults(...rest);
23
+ },
24
+ };
25
+ }
26
+ exports.uploadIdentificationDocument = uploadIdentificationDocument;
@@ -1,6 +1,7 @@
1
- export interface builtInGetNextFrameReturn {
2
- getNextFrame: () => Promise<Blob | null>;
3
- stopGetNextFrame: () => void;
4
- videoStream: MediaStream | undefined;
1
+ export interface IFrameControls<TFrameType, TMediaType> {
2
+ startGettingFrames?: () => TMediaType | Promise<TMediaType>;
3
+ getNextFrame?: () => TFrameType | Promise<TFrameType>;
4
+ stopGettingFrames?: () => void | Promise<void>;
5
+ videoStream?: TMediaType;
5
6
  }
6
- export declare function builtInGetNextFrame(): Promise<builtInGetNextFrameReturn>;
7
+ export declare function getDefaultFrameControls<TFrameType, TMediaType>(): Promise<IFrameControls<TFrameType, TMediaType>>;
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.builtInGetNextFrame = void 0;
4
- async function builtInGetNextFrame() {
3
+ exports.getDefaultFrameControls = void 0;
4
+ async function getDefaultFrameControls() {
5
5
  let videoStream;
6
6
  let videoElement;
7
7
  let canvasElement;
@@ -25,7 +25,7 @@ async function builtInGetNextFrame() {
25
25
  throw new Error('Cannot found video element');
26
26
  }
27
27
  }
28
- function stopGetNextFrame() {
28
+ function stopGettingFrames() {
29
29
  if (videoElement) {
30
30
  document.body.removeChild(videoElement);
31
31
  videoElement = undefined;
@@ -36,25 +36,30 @@ async function builtInGetNextFrame() {
36
36
  if (canvasContext) {
37
37
  canvasContext = undefined;
38
38
  }
39
- videoStream === null || videoStream === void 0 ? void 0 : videoStream.getTracks().forEach(track => { track.stop(); });
40
- videoStream = undefined;
39
+ if (videoStream) {
40
+ videoStream === null || videoStream === void 0 ? void 0 : videoStream.getTracks().forEach(track => { track.stop(); });
41
+ videoStream = undefined;
42
+ }
41
43
  }
42
- if (!videoStream || !videoElement || !canvasElement) {
43
- videoStream = await navigator.mediaDevices.getUserMedia({ video: true });
44
- videoElement = document.createElement('video');
45
- videoElement.setAttribute('autoplay', 'true');
46
- videoElement.style.transform = 'scale(-1, 1)';
47
- videoElement.style.position = 'absolute';
48
- videoElement.style.left = '99999px';
49
- document.body.appendChild(videoElement);
50
- videoElement.srcObject = videoStream;
51
- canvasElement = document.createElement('canvas');
52
- canvasContext = canvasElement.getContext('2d');
44
+ async function startGettingFrames() {
45
+ if (!videoStream || !videoElement || !canvasElement) {
46
+ videoStream = await navigator.mediaDevices.getUserMedia({ video: true });
47
+ videoElement = document.createElement('video');
48
+ videoElement.setAttribute('autoplay', 'true');
49
+ videoElement.style.transform = 'scale(-1, 1)';
50
+ videoElement.style.position = 'absolute';
51
+ videoElement.style.left = '99999px';
52
+ document.body.appendChild(videoElement);
53
+ videoElement.srcObject = videoStream;
54
+ canvasElement = document.createElement('canvas');
55
+ canvasContext = canvasElement.getContext('2d');
56
+ }
57
+ return videoStream;
53
58
  }
54
59
  return {
60
+ startGettingFrames,
55
61
  getNextFrame,
56
- stopGetNextFrame,
57
- videoStream,
62
+ stopGettingFrames,
58
63
  };
59
64
  }
60
- exports.builtInGetNextFrame = builtInGetNextFrame;
65
+ exports.getDefaultFrameControls = getDefaultFrameControls;
@@ -1,2 +1,2 @@
1
- export declare function decodeJwt(token: string): any;
2
- export declare function tryDecodeJwt(token: string): any;
1
+ export declare function decodeJwt<TDecodeReturnType = any>(token: string): TDecodeReturnType;
2
+ export declare function tryDecodeJwt<TDecodeReturnType = any>(token: string): TDecodeReturnType | null;
@@ -1,8 +1,6 @@
1
1
  import { livenessDetection } from './methods/livenessDetection';
2
2
  import { uploadIdentificationDocument } from './methods/uploadIdentificationDocument';
3
- export { livenessDetection } from './methods/livenessDetection';
4
- export { uploadIdentificationDocument } from './methods/uploadIdentificationDocument';
5
- export * from './utils/types';
3
+ export { livenessDetection, uploadIdentificationDocument, };
6
4
  export default class SantoiDSDK {
7
5
  static livenessDetection: typeof livenessDetection;
8
6
  static uploadIdentificationDocument: typeof uploadIdentificationDocument;
@@ -1,27 +1,10 @@
1
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
2
  Object.defineProperty(exports, "__esModule", { value: true });
17
3
  exports.uploadIdentificationDocument = exports.livenessDetection = void 0;
18
4
  const livenessDetection_1 = require("./methods/livenessDetection");
5
+ Object.defineProperty(exports, "livenessDetection", { enumerable: true, get: function () { return livenessDetection_1.livenessDetection; } });
19
6
  const uploadIdentificationDocument_1 = require("./methods/uploadIdentificationDocument");
20
- var livenessDetection_2 = require("./methods/livenessDetection");
21
- Object.defineProperty(exports, "livenessDetection", { enumerable: true, get: function () { return livenessDetection_2.livenessDetection; } });
22
- var uploadIdentificationDocument_2 = require("./methods/uploadIdentificationDocument");
23
- Object.defineProperty(exports, "uploadIdentificationDocument", { enumerable: true, get: function () { return uploadIdentificationDocument_2.uploadIdentificationDocument; } });
24
- __exportStar(require("./utils/types"), exports);
7
+ Object.defineProperty(exports, "uploadIdentificationDocument", { enumerable: true, get: function () { return uploadIdentificationDocument_1.uploadIdentificationDocument; } });
25
8
  class SantoiDSDK {
26
9
  }
27
10
  SantoiDSDK.livenessDetection = livenessDetection_1.livenessDetection;
@@ -0,0 +1,6 @@
1
+ import { LivenessDetectionService } from '../../../../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
+ }
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NodeLivenessDetectionService = void 0;
4
+ const Service_1 = require("../../../../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.callEveryXSeconds)(async () => { await this.sendFramesToWebSocket(); }, constants_1.SEND_FRAMES_INTERVAL_MS);
18
+ }
19
+ }
20
+ exports.NodeLivenessDetectionService = NodeLivenessDetectionService;
@@ -0,0 +1,13 @@
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 {};
@@ -0,0 +1,46 @@
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
+ void abstractWebSocket.waitForWebSocketConnection()
19
+ .then(() => { void livenessDetectionHandler.onConnect(); })
20
+ .catch(() => { void livenessDetectionHandler.onError(); });
21
+ abstractWebSocket.addListener('message', (data) => {
22
+ void livenessDetectionHandler.onWebSocketMessage({ data: Buffer.from(data).toString() });
23
+ });
24
+ abstractWebSocket.addListener('error', () => {
25
+ void livenessDetectionHandler.onError();
26
+ });
27
+ abstractWebSocket.addListener('close', () => {
28
+ void 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({ message: 'Error while starting SDK', code: error_1.EDefaultErrorCodes.INITIALIZATION_ERROR });
44
+ }
45
+ }
46
+ exports.livenessDetection = livenessDetection;
@@ -0,0 +1,4 @@
1
+ import { UploadIdentificationDocumentService, type IServiceOptions, type IInternalServiceOptions } from '../../../../liveness/methods/uploadIdentificationDocument/Service';
2
+ export declare class NodeUploadIdentificationDocumentService<TFrameType, TMediaType, TFileType> extends UploadIdentificationDocumentService<TFrameType, TMediaType, TFileType> {
3
+ constructor(options: IServiceOptions<TFrameType, TMediaType, TFileType>, internalOptions: IInternalServiceOptions<TFrameType, TMediaType>);
4
+ }
@@ -0,0 +1,19 @@
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.NodeUploadIdentificationDocumentService = void 0;
7
+ const form_data_1 = __importDefault(require("form-data"));
8
+ const Service_1 = require("../../../../liveness/methods/uploadIdentificationDocument/Service");
9
+ const TypificationService_1 = require("../../../../api/TypificationService");
10
+ const FaceMatchService_1 = require("../../../../api/FaceMatchService");
11
+ const index_1 = require("../../utils/index");
12
+ class NodeUploadIdentificationDocumentService extends Service_1.UploadIdentificationDocumentService {
13
+ constructor(options, internalOptions) {
14
+ super(options, internalOptions);
15
+ this.typificationService = new TypificationService_1.TypificationService(options, { FormDataClass: form_data_1.default, tryDecodeJwt: index_1.tryDecodeJwt });
16
+ this.faceMatchService = new FaceMatchService_1.FaceMatchService(options, { FormDataClass: form_data_1.default, tryDecodeJwt: index_1.tryDecodeJwt });
17
+ }
18
+ }
19
+ exports.NodeUploadIdentificationDocumentService = NodeUploadIdentificationDocumentService;
@@ -0,0 +1,25 @@
1
+ import { type Data } from 'ws';
2
+ import { type IServiceOptions } from '../../../../liveness/methods/uploadIdentificationDocument/Service';
3
+ import { type TFrameType, type TMediaType } from '../livenessDetection';
4
+ type TFileType = Data;
5
+ export declare function uploadIdentificationDocument(options: IServiceOptions<TFrameType, TMediaType, TFileType>): {
6
+ startDocumentUpload: (file: Data) => Promise<void>;
7
+ startLivenessDetection: (startLivenessDetectionOptions?: (Omit<import("../../../../utils/types").ISDKOptions<Data, undefined>, "token" | "track"> & {
8
+ track?: string | undefined;
9
+ token?: string | undefined;
10
+ }) | undefined) => (Omit<{
11
+ getVideoStream: () => import("../../../../liveness/methods/livenessDetection").TMediaType;
12
+ stopLivenessDetection: () => Promise<void>;
13
+ resumeGettingFrames: () => void;
14
+ pauseGettingFrames: () => void;
15
+ }, "getVideoStream"> & {
16
+ getVideoStream?: (() => undefined) | undefined;
17
+ }) | undefined;
18
+ startFaceComparison: () => Promise<void>;
19
+ startAll: (file: Data, startLivenessDetectionOptions?: (Omit<import("../../../../utils/types").ISDKOptions<Data, undefined>, "token" | "track"> & {
20
+ track?: string | undefined;
21
+ token?: string | undefined;
22
+ }) | undefined) => void;
23
+ getResults: () => import("../../../../liveness/methods/uploadIdentificationDocument/Service").IUploadIdentificationDocumentResults<Data>;
24
+ };
25
+ export {};
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.uploadIdentificationDocument = void 0;
4
+ const Service_1 = require("./Service");
5
+ const livenessDetection_1 = require("../livenessDetection");
6
+ function uploadIdentificationDocument(options) {
7
+ const uploadIdentificationDocumentService = new Service_1.NodeUploadIdentificationDocumentService(options, {
8
+ livenessDetection: livenessDetection_1.livenessDetection,
9
+ });
10
+ return {
11
+ startDocumentUpload: async (...rest) => {
12
+ await uploadIdentificationDocumentService.startDocumentUpload(...rest);
13
+ },
14
+ startLivenessDetection: (...rest) => {
15
+ return uploadIdentificationDocumentService.startLivenessDetection(...rest);
16
+ },
17
+ startFaceComparison: async (...rest) => {
18
+ await uploadIdentificationDocumentService.tryStartFaceMatch(...rest);
19
+ },
20
+ startAll: (...rest) => {
21
+ uploadIdentificationDocumentService.startAll(...rest);
22
+ },
23
+ getResults: (...rest) => {
24
+ return uploadIdentificationDocumentService.getResults(...rest);
25
+ },
26
+ };
27
+ }
28
+ exports.uploadIdentificationDocument = uploadIdentificationDocument;
@@ -1,2 +1,2 @@
1
- export declare function decodeJwt(token: string): any;
2
- export declare function tryDecodeJwt(token: string): any;
1
+ export declare function decodeJwt<TDecodeReturnType = any>(token: string): TDecodeReturnType;
2
+ export declare function tryDecodeJwt<TDecodeReturnType = any>(token: string): TDecodeReturnType | null;
package/package.json CHANGED
@@ -1,16 +1,16 @@
1
1
  {
2
2
  "name": "santoid-sdk",
3
- "version": "2.0.2",
3
+ "version": "3.0.0",
4
4
  "description": "",
5
5
  "main": "liveness/index.js",
6
6
  "types": "liveness/index.d.ts",
7
7
  "scripts": {
8
8
  "expose:cmd": "mv -v dist/* ./ && rm -rf ./dist",
9
- "build:clear": "rm -rf ./browser ./liveness ./node ./utils ./index.js ./index.d.ts ./dist",
9
+ "build:clear": "rm -rf ./browser ./api ./liveness ./node ./utils ./index.js ./index.d.ts ./dist",
10
10
  "build:webpack": "webpack --mode=production",
11
11
  "build:typescript": "npm run build:clear && tsc -p tsconfig.prod.json",
12
12
  "build": "npm run build:typescript && npm run build:webpack && npm run expose:cmd",
13
- "test": "jest --coverage false",
13
+ "test": "jest --coverage false --runInBand",
14
14
  "test:coverage": "jest --coverage --runInBand"
15
15
  },
16
16
  "keywords": [],
@@ -0,0 +1,24 @@
1
+ export declare enum EDefaultErrorCodes {
2
+ INITIALIZATION_ERROR = "initialization-error",
3
+ INTERNAL_ERROR = "internal-error"
4
+ }
5
+ export declare enum ELivenessDetectionErrorCodes {
6
+ WRONG_POSITION = "liveness-detection/wrong-position"
7
+ }
8
+ export declare enum EUploadIdentificationDocumentErrorCodes {
9
+ FACE_MATCH_ERROR = "upload-identification-document/face-match-error",
10
+ FACE_MATCH_UNAVAILABLE_FACES_ERROR = "upload-identification-document/face-match-unavailable-faces-error",
11
+ TYPIFICATION_ERROR = "upload-identification-document/typification-error",
12
+ LIVENESS_DETECTION_ERROR = "upload-identification-document/liveness-detection-error"
13
+ }
14
+ interface ISDKErrorConstructorParams {
15
+ message: string;
16
+ code: EDefaultErrorCodes | ELivenessDetectionErrorCodes | EUploadIdentificationDocumentErrorCodes;
17
+ details?: any;
18
+ }
19
+ export declare class SDKError extends Error {
20
+ code: string;
21
+ details?: any;
22
+ constructor({ message, code, details }: ISDKErrorConstructorParams);
23
+ }
24
+ export {};
package/utils/error.js ADDED
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SDKError = exports.EUploadIdentificationDocumentErrorCodes = exports.ELivenessDetectionErrorCodes = exports.EDefaultErrorCodes = void 0;
4
+ var EDefaultErrorCodes;
5
+ (function (EDefaultErrorCodes) {
6
+ EDefaultErrorCodes["INITIALIZATION_ERROR"] = "initialization-error";
7
+ EDefaultErrorCodes["INTERNAL_ERROR"] = "internal-error";
8
+ })(EDefaultErrorCodes || (exports.EDefaultErrorCodes = EDefaultErrorCodes = {}));
9
+ var ELivenessDetectionErrorCodes;
10
+ (function (ELivenessDetectionErrorCodes) {
11
+ ELivenessDetectionErrorCodes["WRONG_POSITION"] = "liveness-detection/wrong-position";
12
+ })(ELivenessDetectionErrorCodes || (exports.ELivenessDetectionErrorCodes = ELivenessDetectionErrorCodes = {}));
13
+ var EUploadIdentificationDocumentErrorCodes;
14
+ (function (EUploadIdentificationDocumentErrorCodes) {
15
+ EUploadIdentificationDocumentErrorCodes["FACE_MATCH_ERROR"] = "upload-identification-document/face-match-error";
16
+ EUploadIdentificationDocumentErrorCodes["FACE_MATCH_UNAVAILABLE_FACES_ERROR"] = "upload-identification-document/face-match-unavailable-faces-error";
17
+ EUploadIdentificationDocumentErrorCodes["TYPIFICATION_ERROR"] = "upload-identification-document/typification-error";
18
+ EUploadIdentificationDocumentErrorCodes["LIVENESS_DETECTION_ERROR"] = "upload-identification-document/liveness-detection-error";
19
+ })(EUploadIdentificationDocumentErrorCodes || (exports.EUploadIdentificationDocumentErrorCodes = EUploadIdentificationDocumentErrorCodes = {}));
20
+ class SDKError extends Error {
21
+ constructor({ message, code, details }) {
22
+ super(message);
23
+ this.code = code;
24
+ this.details = details;
25
+ }
26
+ }
27
+ exports.SDKError = SDKError;
@@ -0,0 +1,7 @@
1
+ import { type TCallbackFunction } from './types';
2
+ export declare const wait: (ms: number) => Promise<void>;
3
+ export declare function waitFor(conditionFn: TCallbackFunction): Promise<void>;
4
+ export declare function callEveryXSeconds(fn: () => Promise<any>, xSeconds: number, baseConfig?: {
5
+ stop: boolean;
6
+ }): () => void;
7
+ export declare function capitalizeFirstLetter(str: string): string;
package/utils/index.js ADDED
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.capitalizeFirstLetter = exports.callEveryXSeconds = exports.waitFor = exports.wait = void 0;
4
+ const wait = async (ms) => {
5
+ await new Promise((resolve) => {
6
+ setTimeout(resolve, ms);
7
+ });
8
+ };
9
+ exports.wait = wait;
10
+ async function waitFor(conditionFn) {
11
+ await new Promise((resolve) => {
12
+ if (conditionFn()) {
13
+ resolve();
14
+ }
15
+ else {
16
+ setTimeout(() => {
17
+ void waitFor(conditionFn).then(resolve);
18
+ }, 500);
19
+ }
20
+ });
21
+ }
22
+ exports.waitFor = waitFor;
23
+ function callEveryXSeconds(fn, xSeconds, baseConfig = { stop: false }) {
24
+ const temporaryConfig = { timerEnd: false };
25
+ setTimeout(() => {
26
+ temporaryConfig.timerEnd = true;
27
+ }, xSeconds);
28
+ void fn()
29
+ .then(async () => {
30
+ await waitFor(() => temporaryConfig.timerEnd);
31
+ if (!baseConfig.stop) {
32
+ callEveryXSeconds(fn, xSeconds, baseConfig);
33
+ }
34
+ });
35
+ function unsubscribe() {
36
+ baseConfig.stop = true;
37
+ }
38
+ return unsubscribe;
39
+ }
40
+ exports.callEveryXSeconds = callEveryXSeconds;
41
+ function capitalizeFirstLetter(str) {
42
+ return str.charAt(0).toUpperCase() + str.slice(1);
43
+ }
44
+ exports.capitalizeFirstLetter = capitalizeFirstLetter;