santoid-sdk 5.2.0 → 5.4.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 (66) hide show
  1. package/.bitbucket/pipelines/generated/pipeline/pipes/sonarsource/sonarcloud-scan/sonarcloud-scan.log +263 -295
  2. package/CHANGELOG.md +7 -0
  3. package/README.md +455 -143
  4. package/api/ApiAsyncService.d.ts +32 -0
  5. package/api/ApiAsyncService.js +15 -0
  6. package/api/ApiFaceMatchService.d.ts +30 -0
  7. package/api/ApiFaceMatchService.js +32 -0
  8. package/api/ApiOcrService.d.ts +62 -0
  9. package/api/ApiOcrService.js +25 -0
  10. package/api/ApiTypificationService.d.ts +23 -0
  11. package/api/{TypificationService.js → ApiTypificationService.js} +8 -9
  12. package/browser/index.js +1 -1
  13. package/client/core/commons/BaseCoreService.d.ts +23 -0
  14. package/client/core/commons/BaseCoreService.js +156 -0
  15. package/client/core/index.d.ts +4 -0
  16. package/client/core/index.js +9 -0
  17. package/client/core/methods/faceMatch/Service.d.ts +19 -0
  18. package/client/core/methods/faceMatch/Service.js +122 -0
  19. package/client/core/methods/faceMatch/index.d.ts +15 -0
  20. package/client/core/methods/faceMatch/index.js +43 -0
  21. package/client/core/methods/ocr/Service.d.ts +11 -0
  22. package/client/core/methods/ocr/Service.js +52 -0
  23. package/client/core/methods/ocr/index.d.ts +10 -0
  24. package/client/core/methods/ocr/index.js +40 -0
  25. package/client/core/methods/typification/Service.d.ts +9 -0
  26. package/client/core/methods/typification/Service.js +52 -0
  27. package/client/core/methods/typification/index.d.ts +10 -0
  28. package/client/core/methods/typification/index.js +40 -0
  29. package/client/core/utils/types.d.ts +30 -0
  30. package/client/core/utils/types.js +2 -0
  31. package/client/index.d.ts +6 -0
  32. package/client/index.js +6 -0
  33. package/client/liveness/methods/livenessDetection/Service.js +10 -2
  34. package/client/liveness/methods/livenessDetection/index.js +5 -1
  35. package/client/liveness/methods/uploadIdentificationDocument/Service.d.ts +19 -19
  36. package/client/liveness/methods/uploadIdentificationDocument/Service.js +8 -4
  37. package/client/liveness/methods/uploadIdentificationDocument/index.d.ts +4 -6
  38. package/client/liveness/utils/getNextFrame.d.ts +4 -1
  39. package/client/liveness/utils/getNextFrame.js +9 -3
  40. package/package.json +1 -1
  41. package/server/core/index.d.ts +4 -0
  42. package/server/core/index.js +9 -0
  43. package/server/core/methods/faceMatch/Service.d.ts +9 -0
  44. package/server/core/methods/faceMatch/Service.js +23 -0
  45. package/server/core/methods/faceMatch/index.d.ts +7 -0
  46. package/server/core/methods/faceMatch/index.js +28 -0
  47. package/server/core/methods/ocr/Service.d.ts +9 -0
  48. package/server/core/methods/ocr/Service.js +23 -0
  49. package/server/core/methods/ocr/index.d.ts +7 -0
  50. package/server/core/methods/ocr/index.js +28 -0
  51. package/server/core/methods/typification/Service.d.ts +9 -0
  52. package/server/core/methods/typification/Service.js +23 -0
  53. package/server/core/methods/typification/index.d.ts +7 -0
  54. package/server/core/methods/typification/index.js +28 -0
  55. package/server/index.d.ts +6 -0
  56. package/server/index.js +6 -0
  57. package/server/liveness/methods/livenessDetection/index.js +5 -1
  58. package/server/liveness/methods/uploadIdentificationDocument/Service.d.ts +2 -2
  59. package/server/liveness/methods/uploadIdentificationDocument/Service.js +4 -4
  60. package/server/liveness/methods/uploadIdentificationDocument/index.d.ts +6 -8
  61. package/utils/error.d.ts +19 -2
  62. package/utils/error.js +21 -2
  63. package/utils/types.d.ts +1 -0
  64. package/api/FaceMatchService.d.ts +0 -42
  65. package/api/FaceMatchService.js +0 -26
  66. package/api/TypificationService.d.ts +0 -90
@@ -0,0 +1,156 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BaseCoreService = void 0;
4
+ const error_1 = require("../../../utils/error");
5
+ const getNextFrame_1 = require("../../liveness/utils/getNextFrame");
6
+ class BaseCoreService {
7
+ constructor(options) {
8
+ this.results = { status: null, results: null, loading: false, error: null };
9
+ this.cameraIsActive = false;
10
+ this.cameraIsSetup = false;
11
+ this.options = options;
12
+ }
13
+ async initialize(file) {
14
+ var _a;
15
+ if (file) {
16
+ // Start processing immediately
17
+ this.startProcessing(file);
18
+ }
19
+ else {
20
+ // If necessary, open camera and take photo before start processing
21
+ const startTheCameraImmediately = (_a = this.options.startTheCameraImmediately) !== null && _a !== void 0 ? _a : this.options.startTheCameraImmediately === undefined;
22
+ if (startTheCameraImmediately) {
23
+ await this.startCamera();
24
+ }
25
+ }
26
+ }
27
+ async updateResults(updatedResults) {
28
+ var _a, _b;
29
+ this.results = Object.assign(Object.assign({}, this.results), updatedResults);
30
+ await ((_b = (_a = this.options).onUpdate) === null || _b === void 0 ? void 0 : _b.call(_a, this.results));
31
+ }
32
+ getVideoStream() {
33
+ var _a;
34
+ return (_a = this.frameGetControls) === null || _a === void 0 ? void 0 : _a.videoStream;
35
+ }
36
+ async setupCamera() {
37
+ this.frameGetControls = await (0, getNextFrame_1.getDefaultFrameControls)();
38
+ this.cameraIsSetup = true;
39
+ }
40
+ async startCamera(cameraOptions) {
41
+ var _a, _b, _c, _d, _e, _f;
42
+ try {
43
+ if (this.cameraIsActive) {
44
+ throw new error_1.SDKError({
45
+ message: 'The camera has already been initialized',
46
+ code: error_1.ECameraErrorCodes.ALREADY_STARTED,
47
+ fatal: false,
48
+ });
49
+ }
50
+ if (this.results.loading) {
51
+ throw new error_1.SDKError({
52
+ message: 'Typification processing has already started',
53
+ code: error_1.EProcessingErrorCodes.ALREADY_STARTED,
54
+ fatal: false,
55
+ });
56
+ }
57
+ if (!this.cameraIsSetup) {
58
+ await this.setupCamera();
59
+ }
60
+ this.frameGetControls.videoStream = await ((_b = (_a = this.frameGetControls).startGettingFrames) === null || _b === void 0 ? void 0 : _b.call(_a, cameraOptions));
61
+ await ((_d = (_c = this.options).onCameraStart) === null || _d === void 0 ? void 0 : _d.call(_c, { videoStream: this.getVideoStream() }));
62
+ this.cameraIsActive = true;
63
+ }
64
+ catch (err) {
65
+ const validatedError = err instanceof error_1.SDKError
66
+ ? err
67
+ : new error_1.SDKError({
68
+ message: 'Camera initialization error',
69
+ code: error_1.ECameraErrorCodes.INITIALIZATION_ERROR,
70
+ fatal: false,
71
+ details: err,
72
+ });
73
+ await ((_f = (_e = this.options).onError) === null || _f === void 0 ? void 0 : _f.call(_e, validatedError));
74
+ }
75
+ }
76
+ async stopCamera() {
77
+ var _a, _b, _c, _d, _e, _f;
78
+ try {
79
+ if (!this.cameraIsActive) {
80
+ throw new error_1.SDKError({
81
+ message: 'Camera not initialized',
82
+ code: error_1.ECameraErrorCodes.NOT_INITIALIZED,
83
+ fatal: false,
84
+ });
85
+ }
86
+ await ((_b = (_a = this.frameGetControls).stopGettingFrames) === null || _b === void 0 ? void 0 : _b.call(_a));
87
+ await ((_d = (_c = this.options).onCameraStop) === null || _d === void 0 ? void 0 : _d.call(_c));
88
+ this.cameraIsActive = false;
89
+ }
90
+ catch (err) {
91
+ const validatedError = err instanceof error_1.SDKError
92
+ ? err
93
+ : new error_1.SDKError({
94
+ message: 'Error during camera shutdown',
95
+ code: error_1.ECameraErrorCodes.SHUTDOWN_ERROR,
96
+ fatal: false,
97
+ details: err,
98
+ });
99
+ await ((_f = (_e = this.options).onError) === null || _f === void 0 ? void 0 : _f.call(_e, validatedError));
100
+ }
101
+ }
102
+ async captureImage({ startProcessing = true } = {}) {
103
+ var _a, _b;
104
+ const bytes = await ((_b = (_a = this.frameGetControls).getNextFrame) === null || _b === void 0 ? void 0 : _b.call(_a));
105
+ if (bytes) {
106
+ if (startProcessing) {
107
+ await this.stopCamera();
108
+ await this.startProcessing(bytes);
109
+ }
110
+ return bytes;
111
+ }
112
+ else {
113
+ throw new error_1.SDKError({
114
+ message: 'Cannot capture image',
115
+ code: error_1.ECameraErrorCodes.CANNOT_CAPTURE_IMAGE,
116
+ fatal: false,
117
+ });
118
+ }
119
+ }
120
+ async waitForResults(requestId) {
121
+ let validationNotified = false;
122
+ return await new Promise((resolve, reject) => {
123
+ const interval = setInterval(async () => {
124
+ var _a, _b, _c, _d;
125
+ try {
126
+ (_b = (_a = this.options).onClearInterval) === null || _b === void 0 ? void 0 : _b.call(_a, interval);
127
+ const data = await this.service.get(requestId);
128
+ if ((data === null || data === void 0 ? void 0 : data.status) === 'validation' && !validationNotified) {
129
+ await ((_d = (_c = this.options).onValidationRequested) === null || _d === void 0 ? void 0 : _d.call(_c, {
130
+ track: this.options.track,
131
+ requestId: data.id,
132
+ }));
133
+ validationNotified = true;
134
+ return;
135
+ }
136
+ if ((data === null || data === void 0 ? void 0 : data.status) === 'error') {
137
+ throw new Error('Não foi possível processar os resultados do Upload de Documentos');
138
+ }
139
+ if ((data === null || data === void 0 ? void 0 : data.status) === 'processed' && data.fileURL) {
140
+ const response = await fetch(data.fileURL);
141
+ const typificationResults = await response.json();
142
+ if (typificationResults) {
143
+ clearInterval(interval);
144
+ resolve(typificationResults);
145
+ }
146
+ }
147
+ }
148
+ catch (error) {
149
+ clearInterval(interval);
150
+ reject(error);
151
+ }
152
+ }, 5000);
153
+ });
154
+ }
155
+ }
156
+ exports.BaseCoreService = BaseCoreService;
@@ -0,0 +1,4 @@
1
+ import { typification } from './methods/typification';
2
+ import { faceMatch } from './methods/faceMatch';
3
+ import { ocr } from './methods/ocr';
4
+ export { typification, faceMatch, ocr, };
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ocr = exports.faceMatch = exports.typification = void 0;
4
+ const typification_1 = require("./methods/typification");
5
+ Object.defineProperty(exports, "typification", { enumerable: true, get: function () { return typification_1.typification; } });
6
+ const faceMatch_1 = require("./methods/faceMatch");
7
+ Object.defineProperty(exports, "faceMatch", { enumerable: true, get: function () { return faceMatch_1.faceMatch; } });
8
+ const ocr_1 = require("./methods/ocr");
9
+ Object.defineProperty(exports, "ocr", { enumerable: true, get: function () { return ocr_1.ocr; } });
@@ -0,0 +1,19 @@
1
+ import { ApiFaceMatchService, type IFaceMatchResult } from '../../../../api/ApiFaceMatchService';
2
+ import { type TCoreServiceOptions } from '../../utils/types';
3
+ import { BaseCoreService } from '../../commons/BaseCoreService';
4
+ export type TFaceMatchServiceOptions<TMediaType> = Omit<TCoreServiceOptions<TMediaType, IFaceMatchResult>, 'template' | 'onValidationRequested'>;
5
+ export declare class FaceMatchService<TFrameType, TMediaType> extends BaseCoreService<TFrameType, TMediaType, IFaceMatchResult> {
6
+ service: ApiFaceMatchService<TFrameType>;
7
+ selectedFile1: TFrameType | undefined;
8
+ selectedFile2: TFrameType | undefined;
9
+ constructor(options: TFaceMatchServiceOptions<TMediaType>);
10
+ initialize(file1?: TFrameType, file2?: TFrameType): Promise<void>;
11
+ captureFirstImage({ startProcessing }?: {
12
+ startProcessing?: boolean | undefined;
13
+ }): Promise<NonNullable<Awaited<TFrameType>>>;
14
+ captureSecondImage({ startProcessing }?: {
15
+ startProcessing?: boolean | undefined;
16
+ }): Promise<NonNullable<Awaited<TFrameType>>>;
17
+ startProcessing(file1: TFrameType, file2?: TFrameType): Promise<void>;
18
+ waitForResultsFaceMatch(requestId: string): Promise<IFaceMatchResult>;
19
+ }
@@ -0,0 +1,122 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FaceMatchService = void 0;
4
+ const uuid_1 = require("uuid");
5
+ const error_1 = require("../../../../utils/error");
6
+ const utils_1 = require("../../../liveness/utils");
7
+ const ApiFaceMatchService_1 = require("../../../../api/ApiFaceMatchService");
8
+ const BaseCoreService_1 = require("../../commons/BaseCoreService");
9
+ class FaceMatchService extends BaseCoreService_1.BaseCoreService {
10
+ constructor(options) {
11
+ super(options);
12
+ this.selectedFile1 = undefined;
13
+ this.selectedFile2 = undefined;
14
+ this.service = new ApiFaceMatchService_1.ApiFaceMatchService(options, { FormDataClass: FormData, tryDecodeJwt: utils_1.tryDecodeJwt });
15
+ }
16
+ async initialize(file1, file2) {
17
+ var _a;
18
+ if (file1) {
19
+ // Start processing immediately
20
+ this.startProcessing(file1, file2);
21
+ }
22
+ else {
23
+ // If necessary, open camera and take photo before start processing
24
+ const startTheCameraImmediately = (_a = this.options.startTheCameraImmediately) !== null && _a !== void 0 ? _a : this.options.startTheCameraImmediately === undefined;
25
+ if (startTheCameraImmediately) {
26
+ await this.startCamera();
27
+ }
28
+ }
29
+ }
30
+ async captureFirstImage({ startProcessing = true } = {}) {
31
+ // The superclass only works with one file
32
+ const bytes = await super.captureImage({ startProcessing: false });
33
+ this.selectedFile1 = bytes;
34
+ if (startProcessing) {
35
+ await this.stopCamera();
36
+ await this.startProcessing(this.selectedFile1);
37
+ }
38
+ return bytes;
39
+ }
40
+ async captureSecondImage({ startProcessing = true } = {}) {
41
+ if (!this.selectedFile1) {
42
+ throw new error_1.SDKError({
43
+ message: 'Select the first image before selecting the second',
44
+ code: error_1.EFaceMatchErrorCodes.FIRST_IMAGE_NOT_SELECTED,
45
+ fatal: false,
46
+ });
47
+ }
48
+ // The superclass only works with one file
49
+ const bytes = await super.captureImage({ startProcessing: false });
50
+ this.selectedFile2 = bytes;
51
+ if (startProcessing) {
52
+ await this.stopCamera();
53
+ await this.startProcessing(this.selectedFile1, this.selectedFile2);
54
+ }
55
+ return bytes;
56
+ }
57
+ async startProcessing(file1, file2) {
58
+ var _a, _b, _c, _d, _e, _f, _g;
59
+ try {
60
+ if (this.cameraIsActive) {
61
+ throw new error_1.SDKError({
62
+ message: 'Cannot start because the camera is running',
63
+ code: error_1.ECameraErrorCodes.IS_RUNNING,
64
+ fatal: false,
65
+ });
66
+ }
67
+ if ((_a = this.results) === null || _a === void 0 ? void 0 : _a.loading) {
68
+ throw new error_1.SDKError({
69
+ message: 'Processing has already started',
70
+ code: error_1.EProcessingErrorCodes.ALREADY_STARTED,
71
+ fatal: false,
72
+ });
73
+ }
74
+ this.updateResults({ status: null, results: null, loading: true, error: null });
75
+ const { requestId } = await this.service.faceMatch(file1, file2, `sdk-ocr-${(0, uuid_1.v4)()}`);
76
+ const results = await this.waitForResultsFaceMatch(requestId);
77
+ this.updateResults({ status: 'success', results, loading: false, error: null });
78
+ (_c = (_b = this.options).onSuccess) === null || _c === void 0 ? void 0 : _c.call(_b, results);
79
+ (_e = (_d = this.options).onEnd) === null || _e === void 0 ? void 0 : _e.call(_d);
80
+ }
81
+ catch (err) {
82
+ const validatedError = err instanceof error_1.SDKError
83
+ ? err
84
+ : new error_1.SDKError({
85
+ message: 'Error during document upload/analysis',
86
+ code: error_1.EProcessingErrorCodes.PROCESSING_ERROR,
87
+ fatal: false,
88
+ details: err,
89
+ });
90
+ await ((_g = (_f = this.options).onError) === null || _g === void 0 ? void 0 : _g.call(_f, validatedError));
91
+ this.updateResults({ status: 'error', results: null, loading: false, error: validatedError });
92
+ }
93
+ }
94
+ async waitForResultsFaceMatch(requestId) {
95
+ return await new Promise((resolve, reject) => {
96
+ const interval = setInterval(async () => {
97
+ var _a, _b, _c, _d;
98
+ try {
99
+ (_b = (_a = this.options).onClearInterval) === null || _b === void 0 ? void 0 : _b.call(_a, interval);
100
+ const data = await this.service.get(requestId);
101
+ if ((data === null || data === void 0 ? void 0 : data.status) === 'error' || (data === null || data === void 0 ? void 0 : data.status) === 'error_connector') {
102
+ throw new Error('Não foi possível processar os resultados do FaceMatch');
103
+ }
104
+ if ((data === null || data === void 0 ? void 0 : data.status) === 'processed' && data.fileURL) {
105
+ const response = await fetch(data.fileURL);
106
+ let faceMatchResults = await response.json();
107
+ faceMatchResults = Object.assign(Object.assign({}, faceMatchResults), { fileImage1: (_c = data.fileImage1) !== null && _c !== void 0 ? _c : '', fileImage2: (_d = data.fileImage2) !== null && _d !== void 0 ? _d : '' });
108
+ if (faceMatchResults) {
109
+ clearInterval(interval);
110
+ resolve(faceMatchResults);
111
+ }
112
+ }
113
+ }
114
+ catch (error) {
115
+ clearInterval(interval);
116
+ reject(new Error(error));
117
+ }
118
+ }, 5000);
119
+ });
120
+ }
121
+ }
122
+ exports.FaceMatchService = FaceMatchService;
@@ -0,0 +1,15 @@
1
+ import { type TFaceMatchServiceOptions } from './Service';
2
+ export type TFrameType = File | Blob;
3
+ export type TMediaType = MediaStream | undefined;
4
+ export declare function faceMatch(options: TFaceMatchServiceOptions<TMediaType>, file1?: TFrameType, file2?: TFrameType): Promise<{
5
+ startCamera: (cameraOptions?: import("../../../liveness/utils/getNextFrame").IStartGettingFramesOptions | undefined) => Promise<void>;
6
+ stopCamera: () => Promise<void>;
7
+ captureFirstImage: (rest_0?: {
8
+ startProcessing?: boolean | undefined;
9
+ } | undefined) => Promise<NonNullable<TFrameType>>;
10
+ captureSecondImage: (rest_0?: {
11
+ startProcessing?: boolean | undefined;
12
+ } | undefined) => Promise<NonNullable<TFrameType>>;
13
+ getVideoStream: () => TMediaType;
14
+ sendFiles: (file1: TFrameType, file2?: TFrameType | undefined) => Promise<void>;
15
+ }>;
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.faceMatch = void 0;
4
+ const error_1 = require("../../../../utils/error");
5
+ const Service_1 = require("./Service");
6
+ async function faceMatch(options, file1, file2) {
7
+ var _a, _b;
8
+ try {
9
+ const service = new Service_1.FaceMatchService(options);
10
+ await service.initialize(file1, file2);
11
+ await ((_b = (_a = service.options).onStart) === null || _b === void 0 ? void 0 : _b.call(_a, { videoStream: service.getVideoStream() }));
12
+ // Methods are exported like this to prevent the value of "this" from changing
13
+ return {
14
+ startCamera: async (...rest) => {
15
+ await service.startCamera(...rest);
16
+ },
17
+ stopCamera: async () => {
18
+ await service.stopCamera();
19
+ },
20
+ captureFirstImage: async (...rest) => {
21
+ return await service.captureFirstImage(...rest);
22
+ },
23
+ captureSecondImage: async (...rest) => {
24
+ return await service.captureSecondImage(...rest);
25
+ },
26
+ getVideoStream: () => {
27
+ return service.getVideoStream();
28
+ },
29
+ sendFiles: async (...rest) => {
30
+ await service.startProcessing(...rest);
31
+ },
32
+ };
33
+ }
34
+ catch (err) {
35
+ throw new error_1.SDKError({
36
+ message: 'Error while starting SDK',
37
+ code: error_1.EDefaultErrorCodes.INITIALIZATION_ERROR,
38
+ fatal: true,
39
+ details: err,
40
+ });
41
+ }
42
+ }
43
+ exports.faceMatch = faceMatch;
@@ -0,0 +1,11 @@
1
+ import { ApiOcrService, type IOcrResult } from '../../../../api/ApiOcrService';
2
+ import { type TCoreServiceOptions } from '../../utils/types';
3
+ import { BaseCoreService } from '../../commons/BaseCoreService';
4
+ export type TOcrServiceOptions<TMediaType> = TCoreServiceOptions<TMediaType, IOcrResult> & {
5
+ template: string;
6
+ };
7
+ export declare class OcrService<TFrameType, TMediaType> extends BaseCoreService<TFrameType, TMediaType, IOcrResult> {
8
+ service: ApiOcrService<TFrameType>;
9
+ constructor(options: TOcrServiceOptions<TMediaType>);
10
+ startProcessing(file: TFrameType): Promise<void>;
11
+ }
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.OcrService = void 0;
4
+ const uuid_1 = require("uuid");
5
+ const error_1 = require("../../../../utils/error");
6
+ const utils_1 = require("../../../liveness/utils");
7
+ const ApiOcrService_1 = require("../../../../api/ApiOcrService");
8
+ const BaseCoreService_1 = require("../../commons/BaseCoreService");
9
+ class OcrService extends BaseCoreService_1.BaseCoreService {
10
+ constructor(options) {
11
+ super(options);
12
+ this.service = new ApiOcrService_1.ApiOcrService(options, { FormDataClass: FormData, tryDecodeJwt: utils_1.tryDecodeJwt });
13
+ }
14
+ async startProcessing(file) {
15
+ var _a, _b, _c, _d, _e, _f, _g;
16
+ try {
17
+ if (this.cameraIsActive) {
18
+ throw new error_1.SDKError({
19
+ message: 'Cannot start because the camera is running',
20
+ code: error_1.ECameraErrorCodes.IS_RUNNING,
21
+ fatal: false,
22
+ });
23
+ }
24
+ if ((_a = this.results) === null || _a === void 0 ? void 0 : _a.loading) {
25
+ throw new error_1.SDKError({
26
+ message: 'Processing has already started',
27
+ code: error_1.EProcessingErrorCodes.ALREADY_STARTED,
28
+ fatal: false,
29
+ });
30
+ }
31
+ this.updateResults({ status: null, results: null, loading: true, error: null });
32
+ const { requestId } = await this.service.extract(file, `sdk-ocr-${(0, uuid_1.v4)()}`);
33
+ const results = await this.waitForResults(requestId);
34
+ this.updateResults({ status: 'success', results, loading: false, error: null });
35
+ (_c = (_b = this.options).onSuccess) === null || _c === void 0 ? void 0 : _c.call(_b, results);
36
+ (_e = (_d = this.options).onEnd) === null || _e === void 0 ? void 0 : _e.call(_d);
37
+ }
38
+ catch (err) {
39
+ const validatedError = err instanceof error_1.SDKError
40
+ ? err
41
+ : new error_1.SDKError({
42
+ message: 'Error during document upload/analysis',
43
+ code: error_1.EProcessingErrorCodes.PROCESSING_ERROR,
44
+ fatal: false,
45
+ details: err,
46
+ });
47
+ await ((_g = (_f = this.options).onError) === null || _g === void 0 ? void 0 : _g.call(_f, validatedError));
48
+ this.updateResults({ status: 'error', results: null, loading: false, error: validatedError });
49
+ }
50
+ }
51
+ }
52
+ exports.OcrService = OcrService;
@@ -0,0 +1,10 @@
1
+ import { type TOcrServiceOptions } from './Service';
2
+ export type TFrameType = File | Blob;
3
+ export type TMediaType = MediaStream | undefined;
4
+ export declare function ocr(options: TOcrServiceOptions<TMediaType>, file?: TFrameType): Promise<{
5
+ startCamera: (cameraOptions?: import("../../../liveness/utils/getNextFrame").IStartGettingFramesOptions | undefined) => Promise<void>;
6
+ stopCamera: () => Promise<void>;
7
+ captureImage: () => Promise<NonNullable<TFrameType>>;
8
+ getVideoStream: () => TMediaType;
9
+ sendFile: (file: TFrameType) => Promise<void>;
10
+ }>;
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ocr = void 0;
4
+ const error_1 = require("../../../../utils/error");
5
+ const Service_1 = require("./Service");
6
+ async function ocr(options, file) {
7
+ var _a, _b;
8
+ try {
9
+ const service = new Service_1.OcrService(options);
10
+ await service.initialize(file);
11
+ await ((_b = (_a = service.options).onStart) === null || _b === void 0 ? void 0 : _b.call(_a, { videoStream: service.getVideoStream() }));
12
+ // Methods are exported like this to prevent the value of "this" from changing
13
+ return {
14
+ startCamera: async (...rest) => {
15
+ await service.startCamera(...rest);
16
+ },
17
+ stopCamera: async () => {
18
+ await service.stopCamera();
19
+ },
20
+ captureImage: async () => {
21
+ return await service.captureImage();
22
+ },
23
+ getVideoStream: () => {
24
+ return service.getVideoStream();
25
+ },
26
+ sendFile: async (file) => {
27
+ await service.startProcessing(file);
28
+ },
29
+ };
30
+ }
31
+ catch (err) {
32
+ throw new error_1.SDKError({
33
+ message: 'Error while starting SDK',
34
+ code: error_1.EDefaultErrorCodes.INITIALIZATION_ERROR,
35
+ fatal: true,
36
+ details: err,
37
+ });
38
+ }
39
+ }
40
+ exports.ocr = ocr;
@@ -0,0 +1,9 @@
1
+ import { ApiTypificationService, type ITypificationResult } from '../../../../api/ApiTypificationService';
2
+ import { type TCoreServiceOptions } from '../../utils/types';
3
+ import { BaseCoreService } from '../../commons/BaseCoreService';
4
+ export type TTypificationServiceOptions<TMediaType> = Omit<TCoreServiceOptions<TMediaType, ITypificationResult>, 'template'>;
5
+ export declare class TypificationService<TFrameType, TMediaType> extends BaseCoreService<TFrameType, TMediaType, ITypificationResult> {
6
+ service: ApiTypificationService<TFrameType>;
7
+ constructor(options: TTypificationServiceOptions<TMediaType>);
8
+ startProcessing(file: TFrameType): Promise<void>;
9
+ }
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TypificationService = void 0;
4
+ const uuid_1 = require("uuid");
5
+ const error_1 = require("../../../../utils/error");
6
+ const utils_1 = require("../../../liveness/utils");
7
+ const ApiTypificationService_1 = require("../../../../api/ApiTypificationService");
8
+ const BaseCoreService_1 = require("../../commons/BaseCoreService");
9
+ class TypificationService extends BaseCoreService_1.BaseCoreService {
10
+ constructor(options) {
11
+ super(options);
12
+ this.service = new ApiTypificationService_1.ApiTypificationService(options, { FormDataClass: FormData, tryDecodeJwt: utils_1.tryDecodeJwt });
13
+ }
14
+ async startProcessing(file) {
15
+ var _a, _b, _c, _d, _e, _f, _g;
16
+ try {
17
+ if (this.cameraIsActive) {
18
+ throw new error_1.SDKError({
19
+ message: 'Cannot start because the camera is running',
20
+ code: error_1.ECameraErrorCodes.IS_RUNNING,
21
+ fatal: false,
22
+ });
23
+ }
24
+ if ((_a = this.results) === null || _a === void 0 ? void 0 : _a.loading) {
25
+ throw new error_1.SDKError({
26
+ message: 'Processing has already started',
27
+ code: error_1.EProcessingErrorCodes.ALREADY_STARTED,
28
+ fatal: false,
29
+ });
30
+ }
31
+ this.updateResults({ status: null, results: null, loading: true, error: null });
32
+ const { requestId } = await this.service.predict(file, `sdk-typification-${(0, uuid_1.v4)()}`);
33
+ const results = await this.waitForResults(requestId);
34
+ this.updateResults({ status: 'success', results, loading: false, error: null });
35
+ (_c = (_b = this.options).onSuccess) === null || _c === void 0 ? void 0 : _c.call(_b, results);
36
+ (_e = (_d = this.options).onEnd) === null || _e === void 0 ? void 0 : _e.call(_d);
37
+ }
38
+ catch (err) {
39
+ const validatedError = err instanceof error_1.SDKError
40
+ ? err
41
+ : new error_1.SDKError({
42
+ message: 'Error during document upload/analysis',
43
+ code: error_1.EProcessingErrorCodes.PROCESSING_ERROR,
44
+ fatal: false,
45
+ details: err,
46
+ });
47
+ await ((_g = (_f = this.options).onError) === null || _g === void 0 ? void 0 : _g.call(_f, validatedError));
48
+ this.updateResults({ status: 'error', results: null, loading: false, error: validatedError });
49
+ }
50
+ }
51
+ }
52
+ exports.TypificationService = TypificationService;
@@ -0,0 +1,10 @@
1
+ import { type TTypificationServiceOptions } from './Service';
2
+ export type TFrameType = File | Blob;
3
+ export type TMediaType = MediaStream | undefined;
4
+ export declare function typification(options: TTypificationServiceOptions<TMediaType>, file?: TFrameType): Promise<{
5
+ startCamera: (cameraOptions?: import("../../../liveness/utils/getNextFrame").IStartGettingFramesOptions | undefined) => Promise<void>;
6
+ stopCamera: () => Promise<void>;
7
+ captureImage: () => Promise<NonNullable<TFrameType>>;
8
+ getVideoStream: () => TMediaType;
9
+ sendFile: (file: TFrameType) => Promise<void>;
10
+ }>;
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.typification = void 0;
4
+ const error_1 = require("../../../../utils/error");
5
+ const Service_1 = require("./Service");
6
+ async function typification(options, file) {
7
+ var _a, _b;
8
+ try {
9
+ const service = new Service_1.TypificationService(options);
10
+ await service.initialize(file);
11
+ await ((_b = (_a = service.options).onStart) === null || _b === void 0 ? void 0 : _b.call(_a, { videoStream: service.getVideoStream() }));
12
+ // Methods are exported like this to prevent the value of "this" from changing
13
+ return {
14
+ startCamera: async (...rest) => {
15
+ await service.startCamera(...rest);
16
+ },
17
+ stopCamera: async () => {
18
+ await service.stopCamera();
19
+ },
20
+ captureImage: async () => {
21
+ return await service.captureImage();
22
+ },
23
+ getVideoStream: () => {
24
+ return service.getVideoStream();
25
+ },
26
+ sendFile: async (file) => {
27
+ await service.startProcessing(file);
28
+ },
29
+ };
30
+ }
31
+ catch (err) {
32
+ throw new error_1.SDKError({
33
+ message: 'Error while starting SDK',
34
+ code: error_1.EDefaultErrorCodes.INITIALIZATION_ERROR,
35
+ fatal: true,
36
+ details: err,
37
+ });
38
+ }
39
+ }
40
+ exports.typification = typification;
@@ -0,0 +1,30 @@
1
+ import { type SDKError } from '../../../utils/error';
2
+ import { type IBaseSDKOptions, type TCallbackFunction } from '../../../utils/types';
3
+ export type TCoreServiceOptions<TMediaType, TResultsContentType> = IBaseSDKOptions & {
4
+ onStart?: (params: {
5
+ videoStream: TMediaType;
6
+ }) => void | Promise<void>;
7
+ onCameraStart?: (params: {
8
+ videoStream: TMediaType;
9
+ }) => void | Promise<void>;
10
+ onCameraStop?: () => void | Promise<void>;
11
+ onUpdate?: (results?: ICoreServiceResult<TResultsContentType>) => void | Promise<void>;
12
+ onValidationRequested?: (requestInformation: IRequestInformation) => void | Promise<void>;
13
+ onClearInterval?: (interval: ReturnType<typeof setInterval>) => void | Promise<void>;
14
+ onError?: (error?: SDKError) => void | Promise<void>;
15
+ onSuccess?: (results: TResultsContentType) => void | Promise<void>;
16
+ onEnd?: TCallbackFunction;
17
+ startTheCameraImmediately?: boolean;
18
+ };
19
+ interface IRequestInformation {
20
+ track: string;
21
+ requestId: string;
22
+ }
23
+ export type TResultStatuses = 'success' | 'error' | null;
24
+ export interface ICoreServiceResult<TResultsContentType> {
25
+ status: TResultStatuses;
26
+ results: TResultsContentType | null;
27
+ loading: boolean;
28
+ error: SDKError | null;
29
+ }
30
+ export {};
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/client/index.d.ts CHANGED
@@ -1,8 +1,14 @@
1
1
  import { livenessDetection } from './liveness/methods/livenessDetection';
2
2
  import { uploadIdentificationDocument } from './liveness/methods/uploadIdentificationDocument';
3
3
  import { insertUploadIdentificationDocument } from './embedded/methods/insertUploadIdentificationDocument';
4
+ import { typification } from './core/methods/typification';
5
+ import { faceMatch } from './core/methods/faceMatch';
6
+ import { ocr } from './core/methods/ocr';
4
7
  export default class SantoiDSDK {
5
8
  static readonly livenessDetection: typeof livenessDetection;
6
9
  static readonly uploadIdentificationDocument: typeof uploadIdentificationDocument;
7
10
  static readonly insertUploadIdentificationDocument: typeof insertUploadIdentificationDocument;
11
+ static readonly typification: typeof typification;
12
+ static readonly ocr: typeof ocr;
13
+ static readonly faceMatch: typeof faceMatch;
8
14
  }