react-native-unit-components 3.5.2 → 3.5.4

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 (45) hide show
  1. package/lib/commonjs/components/UNCheckDepositComponent/UNCheckDepositComponent.js +3 -0
  2. package/lib/commonjs/components/UNCheckDepositComponent/UNCheckDepositComponent.js.map +1 -1
  3. package/lib/commonjs/components/UNCheckDepositComponent/UNCheckDepositComponent.utils.js +7 -0
  4. package/lib/commonjs/components/UNCheckDepositComponent/UNCheckDepositComponent.utils.js.map +1 -1
  5. package/lib/commonjs/messages/webMessages/unitComponentsMessages.js +1 -0
  6. package/lib/commonjs/messages/webMessages/unitComponentsMessages.js.map +1 -1
  7. package/lib/commonjs/services/veryfiService.js +19 -42
  8. package/lib/commonjs/services/veryfiService.js.map +1 -1
  9. package/lib/commonjs/types/shared/error.types.js.map +1 -1
  10. package/lib/commonjs/unitComponentsSdkManager/UnitComponentsSdkManager.js +19 -19
  11. package/lib/commonjs/unitComponentsSdkManager/UnitComponentsSdkManager.js.map +1 -1
  12. package/lib/module/components/UNCheckDepositComponent/UNCheckDepositComponent.js +3 -0
  13. package/lib/module/components/UNCheckDepositComponent/UNCheckDepositComponent.js.map +1 -1
  14. package/lib/module/components/UNCheckDepositComponent/UNCheckDepositComponent.utils.js +7 -0
  15. package/lib/module/components/UNCheckDepositComponent/UNCheckDepositComponent.utils.js.map +1 -1
  16. package/lib/module/messages/webMessages/unitComponentsMessages.js +1 -0
  17. package/lib/module/messages/webMessages/unitComponentsMessages.js.map +1 -1
  18. package/lib/module/services/veryfiService.js +19 -42
  19. package/lib/module/services/veryfiService.js.map +1 -1
  20. package/lib/module/types/shared/error.types.js.map +1 -1
  21. package/lib/module/unitComponentsSdkManager/UnitComponentsSdkManager.js +19 -19
  22. package/lib/module/unitComponentsSdkManager/UnitComponentsSdkManager.js.map +1 -1
  23. package/lib/typescript/src/components/UNCheckDepositComponent/UNCheckDepositComponent.d.ts +2 -1
  24. package/lib/typescript/src/components/UNCheckDepositComponent/UNCheckDepositComponent.d.ts.map +1 -1
  25. package/lib/typescript/src/components/UNCheckDepositComponent/UNCheckDepositComponent.utils.d.ts.map +1 -1
  26. package/lib/typescript/src/messages/webMessages/unitComponentsMessages.d.ts +3 -1
  27. package/lib/typescript/src/messages/webMessages/unitComponentsMessages.d.ts.map +1 -1
  28. package/lib/typescript/src/services/veryfiService.d.ts +4 -2
  29. package/lib/typescript/src/services/veryfiService.d.ts.map +1 -1
  30. package/lib/typescript/src/types/shared/error.types.d.ts +4 -0
  31. package/lib/typescript/src/types/shared/error.types.d.ts.map +1 -1
  32. package/package.json +2 -2
  33. package/src/components/UNCheckDepositComponent/UNCheckDepositComponent.tsx +5 -1
  34. package/src/components/UNCheckDepositComponent/UNCheckDepositComponent.utils.ts +7 -0
  35. package/src/messages/webMessages/unitComponentsMessages.ts +3 -0
  36. package/src/services/veryfiService.ts +24 -46
  37. package/src/types/shared/error.types.ts +5 -0
  38. package/src/unitComponentsSdkManager/UnitComponentsSdkManager.ts +19 -19
  39. package/lib/commonjs/services/veryfiService.utils.js +0 -87
  40. package/lib/commonjs/services/veryfiService.utils.js.map +0 -1
  41. package/lib/module/services/veryfiService.utils.js +0 -79
  42. package/lib/module/services/veryfiService.utils.js.map +0 -1
  43. package/lib/typescript/src/services/veryfiService.utils.d.ts +0 -10
  44. package/lib/typescript/src/services/veryfiService.utils.d.ts.map +0 -1
  45. package/src/services/veryfiService.utils.ts +0 -87
@@ -1,87 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.readJpegDimensions = exports.labelSidesFromPages = void 0;
7
- const JPEG_SOF_MARKERS = [0xc0, 0xc1, 0xc2, 0xc3, 0xc5, 0xc6, 0xc7, 0xc9, 0xca, 0xcb, 0xcd, 0xce, 0xcf];
8
- const readJpegDimensions = base64 => {
9
- try {
10
- // SOF sits near the file start; a 4-aligned prefix keeps atob happy and cheap.
11
- const prefix = base64.length > 786432 ? base64.slice(0, 786432) : base64;
12
- const bytes = atob(prefix);
13
- if (bytes.charCodeAt(0) !== 0xff || bytes.charCodeAt(1) !== 0xd8) return null;
14
- let i = 2;
15
- while (i + 9 < bytes.length) {
16
- if (bytes.charCodeAt(i) !== 0xff) {
17
- i++;
18
- continue;
19
- }
20
- const marker = bytes.charCodeAt(i + 1);
21
- if (marker === 0xff) {
22
- i++;
23
- continue;
24
- }
25
- if (marker === 0x01 || marker >= 0xd0 && marker <= 0xd9) {
26
- i += 2;
27
- continue;
28
- }
29
- if (JPEG_SOF_MARKERS.includes(marker)) {
30
- return {
31
- height: bytes.charCodeAt(i + 5) * 256 + bytes.charCodeAt(i + 6),
32
- width: bytes.charCodeAt(i + 7) * 256 + bytes.charCodeAt(i + 8)
33
- };
34
- }
35
- i += 2 + bytes.charCodeAt(i + 2) * 256 + bytes.charCodeAt(i + 3);
36
- }
37
- return null;
38
- } catch {
39
- return null;
40
- }
41
- };
42
-
43
- // Veryfi's parsed result is the authority on which image is the front
44
- // (their meta.pages[].is_front); page order does not correspond to the
45
- // delivery array's order, so pages are matched to our images by exact
46
- // pixel dimensions. Returns null whenever the verdict is not unambiguous.
47
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
48
- exports.readJpegDimensions = readJpegDimensions;
49
- const labelSidesFromPages = (images, pages) => {
50
- if (!Array.isArray(pages) || pages.length !== 2 || images.length !== 2) return null;
51
- const fronts = pages.filter(p => p && p.is_front === true);
52
- const backs = pages.filter(p => p && p.is_front === false);
53
- const frontPage = fronts[0];
54
- const backPage = backs[0];
55
- if (fronts.length !== 1 || backs.length !== 1 || !frontPage || !backPage) return null;
56
- if (typeof frontPage.width !== 'number' || typeof frontPage.height !== 'number') return null;
57
- const dims = [];
58
- for (const img of images) {
59
- const d = readJpegDimensions(img.base64Img);
60
- if (!d) return null;
61
- dims.push(d);
62
- }
63
-
64
- // Veryfi may auto-rotate pages in the parsed result, so dimensions are
65
- // compared as an unordered pair.
66
- const sameDims = (d, w, h) => d.width === w && d.height === h || d.width === h && d.height === w;
67
- const matchesFront = dims.map(d => sameDims(d, frontPage.width, frontPage.height));
68
- if (matchesFront.filter(Boolean).length !== 1) return null;
69
- const frontIdx = matchesFront.indexOf(true);
70
- const backIdx = 1 - frontIdx;
71
- const frontImage = images[frontIdx];
72
- const backImage = images[backIdx];
73
- const backDims = dims[backIdx];
74
- if (!frontImage || !backImage || !backDims) return null;
75
- if (typeof backPage.width === 'number' && typeof backPage.height === 'number') {
76
- if (!sameDims(backDims, backPage.width, backPage.height)) return null;
77
- }
78
- return [{
79
- base64Img: frontImage.base64Img,
80
- isFront: true
81
- }, {
82
- base64Img: backImage.base64Img,
83
- isFront: false
84
- }];
85
- };
86
- exports.labelSidesFromPages = labelSidesFromPages;
87
- //# sourceMappingURL=veryfiService.utils.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["JPEG_SOF_MARKERS","readJpegDimensions","base64","prefix","length","slice","bytes","atob","charCodeAt","i","marker","includes","height","width","exports","labelSidesFromPages","images","pages","Array","isArray","fronts","filter","p","is_front","backs","frontPage","backPage","dims","img","d","base64Img","push","sameDims","w","h","matchesFront","map","Boolean","frontIdx","indexOf","backIdx","frontImage","backImage","backDims","isFront"],"sourceRoot":"../../../src","sources":["services/veryfiService.utils.ts"],"mappings":";;;;;;AAKA,MAAMA,gBAAgB,GAAG,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC;AAEhG,MAAMC,kBAAkB,GAAIC,MAAc,IAA+C;EAC9F,IAAI;IACF;IACA,MAAMC,MAAM,GAAGD,MAAM,CAACE,MAAM,GAAG,MAAM,GAAGF,MAAM,CAACG,KAAK,CAAC,CAAC,EAAE,MAAM,CAAC,GAAGH,MAAM;IACxE,MAAMI,KAAK,GAAGC,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 0xc7, 0xc9, 0xca, 0xcb, 0xcd, 0xce, 0xcf];
2
- export const readJpegDimensions = base64 => {
3
- try {
4
- // SOF sits near the file start; a 4-aligned prefix keeps atob happy and cheap.
5
- const prefix = base64.length > 786432 ? base64.slice(0, 786432) : base64;
6
- const bytes = atob(prefix);
7
- if (bytes.charCodeAt(0) !== 0xff || bytes.charCodeAt(1) !== 0xd8) return null;
8
- let i = 2;
9
- while (i + 9 < bytes.length) {
10
- if (bytes.charCodeAt(i) !== 0xff) {
11
- i++;
12
- continue;
13
- }
14
- const marker = bytes.charCodeAt(i + 1);
15
- if (marker === 0xff) {
16
- i++;
17
- continue;
18
- }
19
- if (marker === 0x01 || marker >= 0xd0 && marker <= 0xd9) {
20
- i += 2;
21
- continue;
22
- }
23
- if (JPEG_SOF_MARKERS.includes(marker)) {
24
- return {
25
- height: bytes.charCodeAt(i + 5) * 256 + bytes.charCodeAt(i + 6),
26
- width: bytes.charCodeAt(i + 7) * 256 + bytes.charCodeAt(i + 8)
27
- };
28
- }
29
- i += 2 + bytes.charCodeAt(i + 2) * 256 + bytes.charCodeAt(i + 3);
30
- }
31
- return null;
32
- } catch {
33
- return null;
34
- }
35
- };
36
-
37
- // Veryfi's parsed result is the authority on which image is the front
38
- // (their meta.pages[].is_front); page order does not correspond to the
39
- // delivery array's order, so pages are matched to our images by exact
40
- // pixel dimensions. Returns null whenever the verdict is not unambiguous.
41
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
42
- export const labelSidesFromPages = (images, pages) => {
43
- if (!Array.isArray(pages) || pages.length !== 2 || images.length !== 2) return null;
44
- const fronts = pages.filter(p => p && p.is_front === true);
45
- const backs = pages.filter(p => p && p.is_front === false);
46
- const frontPage = fronts[0];
47
- const backPage = backs[0];
48
- if (fronts.length !== 1 || backs.length !== 1 || !frontPage || !backPage) return null;
49
- if (typeof frontPage.width !== 'number' || typeof frontPage.height !== 'number') return null;
50
- const dims = [];
51
- for (const img of images) {
52
- const d = readJpegDimensions(img.base64Img);
53
- if (!d) return null;
54
- dims.push(d);
55
- }
56
-
57
- // Veryfi may auto-rotate pages in the parsed result, so dimensions are
58
- // compared as an unordered pair.
59
- const sameDims = (d, w, h) => d.width === w && d.height === h || d.width === h && d.height === w;
60
- const matchesFront = dims.map(d => sameDims(d, frontPage.width, frontPage.height));
61
- if (matchesFront.filter(Boolean).length !== 1) return null;
62
- const frontIdx = matchesFront.indexOf(true);
63
- const backIdx = 1 - frontIdx;
64
- const frontImage = images[frontIdx];
65
- const backImage = images[backIdx];
66
- const backDims = dims[backIdx];
67
- if (!frontImage || !backImage || !backDims) return null;
68
- if (typeof backPage.width === 'number' && typeof backPage.height === 'number') {
69
- if (!sameDims(backDims, backPage.width, backPage.height)) return null;
70
- }
71
- return [{
72
- base64Img: frontImage.base64Img,
73
- isFront: true
74
- }, {
75
- base64Img: backImage.base64Img,
76
- isFront: false
77
- }];
78
- };
79
- //# sourceMappingURL=veryfiService.utils.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["JPEG_SOF_MARKERS","readJpegDimensions","base64","prefix","length","slice","bytes","atob","charCodeAt","i","marker","includes","height","width","labelSidesFromPages","images","pages","Array","isArray","fronts","filter","p","is_front","backs","frontPage","backPage","dims","img","d","base64Img","push","sameDims","w","h","matchesFront","map","Boolean","frontIdx","indexOf","backIdx","frontImage","backImage","backDims","isFront"],"sourceRoot":"../../../src","sources":["services/veryfiService.utils.ts"],"mappings":"AAKA,MAAMA,gBAAgB,GAAG,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC;AAEvG,OAAO,MAAMC,kBAAkB,GAAIC,MAAc,IAA+C;EAC9F,IAAI;IACF;IACA,MAAMC,MAAM,GAAGD,MAAM,CAACE,MAAM,GAAG,MAAM,GAAGF,MAAM,CAACG,KAAK,CAAC,CAA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MAAM,KAAKqB,CAAC,IAAML,CAAC,CAACf,KAAK,KAAKoB,CAAC,IAAIL,CAAC,CAAChB,MAAM,KAAKoB,CAAE;EAExE,MAAME,YAAY,GAAGR,IAAI,CAACS,GAAG,CAAEP,CAAC,IAAKG,QAAQ,CAACH,CAAC,EAAEJ,SAAS,CAACX,KAAK,EAAEW,SAAS,CAACZ,MAAM,CAAC,CAAC;EACpF,IAAIsB,YAAY,CAACd,MAAM,CAACgB,OAAO,CAAC,CAAChC,MAAM,KAAK,CAAC,EAAE,OAAO,IAAI;EAE1D,MAAMiC,QAAQ,GAAGH,YAAY,CAACI,OAAO,CAAC,IAAI,CAAC;EAC3C,MAAMC,OAAO,GAAG,CAAC,GAAGF,QAAQ;EAC5B,MAAMG,UAAU,GAAGzB,MAAM,CAACsB,QAAQ,CAAC;EACnC,MAAMI,SAAS,GAAG1B,MAAM,CAACwB,OAAO,CAAC;EACjC,MAAMG,QAAQ,GAAGhB,IAAI,CAACa,OAAO,CAAC;EAC9B,IAAI,CAACC,UAAU,IAAI,CAACC,SAAS,IAAI,CAACC,QAAQ,EAAE,OAAO,IAAI;EACvD,IAAI,OAAOjB,QAAQ,CAACZ,KAAK,KAAK,QAAQ,IAAI,OAAOY,QAAQ,CAACb,MAAM,KAAK,QAAQ,EAAE;IAC7E,IAAI,CAACmB,QAAQ,CAACW,QAAQ,EAAEjB,QAAQ,CAACZ,KAAK,EAAEY,QAAQ,CAACb,MAAM,CAAC,EAAE,OAAO,IAAI;EACvE;EAEA,OAAO,CACL;IAAEiB,SAAS,EAAEW,UAAU,CAACX,SAAS;IAAEc,OAAO,EAAE;EAAK,CAAC,EAClD;IAAEd,SAAS,EAAEY,SAAS,CAACZ,SAAS;IAAEc,OAAO,EAAE;EAAM,CAAC,CACnD;AACH,CAAC","ignoreList":[]}
@@ -1,10 +0,0 @@
1
- export interface UNVeryfiImage {
2
- base64Img: string;
3
- isFront: boolean;
4
- }
5
- export declare const readJpegDimensions: (base64: string) => {
6
- width: number;
7
- height: number;
8
- } | null;
9
- export declare const labelSidesFromPages: (images: UNVeryfiImage[], pages: any) => UNVeryfiImage[] | null;
10
- //# sourceMappingURL=veryfiService.utils.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"veryfiService.utils.d.ts","sourceRoot":"","sources":["../../../../src/services/veryfiService.utils.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,aAAa;IAC5B,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,OAAO,CAAC;CAClB;AAID,eAAO,MAAM,kBAAkB,WAAY,MAAM,KAAG;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GAAG,IAiCvF,CAAC;AAOF,eAAO,MAAM,mBAAmB,WAAY,aAAa,EAAE,SAAS,GAAG,KAAG,aAAa,EAAE,GAAG,IAuC3F,CAAC"}
@@ -1,87 +0,0 @@
1
- export interface UNVeryfiImage {
2
- base64Img: string;
3
- isFront: boolean;
4
- }
5
-
6
- const JPEG_SOF_MARKERS = [0xc0, 0xc1, 0xc2, 0xc3, 0xc5, 0xc6, 0xc7, 0xc9, 0xca, 0xcb, 0xcd, 0xce, 0xcf];
7
-
8
- export const readJpegDimensions = (base64: string): { width: number; height: number } | null => {
9
- try {
10
- // SOF sits near the file start; a 4-aligned prefix keeps atob happy and cheap.
11
- const prefix = base64.length > 786432 ? base64.slice(0, 786432) : base64;
12
- const bytes = atob(prefix);
13
- if (bytes.charCodeAt(0) !== 0xff || bytes.charCodeAt(1) !== 0xd8) return null;
14
- let i = 2;
15
- while (i + 9 < bytes.length) {
16
- if (bytes.charCodeAt(i) !== 0xff) {
17
- i++;
18
- continue;
19
- }
20
- const marker = bytes.charCodeAt(i + 1);
21
- if (marker === 0xff) {
22
- i++;
23
- continue;
24
- }
25
- if (marker === 0x01 || (marker >= 0xd0 && marker <= 0xd9)) {
26
- i += 2;
27
- continue;
28
- }
29
- if (JPEG_SOF_MARKERS.includes(marker)) {
30
- return {
31
- height: bytes.charCodeAt(i + 5) * 256 + bytes.charCodeAt(i + 6),
32
- width: bytes.charCodeAt(i + 7) * 256 + bytes.charCodeAt(i + 8),
33
- };
34
- }
35
- i += 2 + bytes.charCodeAt(i + 2) * 256 + bytes.charCodeAt(i + 3);
36
- }
37
- return null;
38
- } catch {
39
- return null;
40
- }
41
- };
42
-
43
- // Veryfi's parsed result is the authority on which image is the front
44
- // (their meta.pages[].is_front); page order does not correspond to the
45
- // delivery array's order, so pages are matched to our images by exact
46
- // pixel dimensions. Returns null whenever the verdict is not unambiguous.
47
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
48
- export const labelSidesFromPages = (images: UNVeryfiImage[], pages: any): UNVeryfiImage[] | null => {
49
- if (!Array.isArray(pages) || pages.length !== 2 || images.length !== 2) return null;
50
-
51
- const fronts = pages.filter((p) => p && p.is_front === true);
52
- const backs = pages.filter((p) => p && p.is_front === false);
53
- const frontPage = fronts[0];
54
- const backPage = backs[0];
55
- if (fronts.length !== 1 || backs.length !== 1 || !frontPage || !backPage) return null;
56
- if (typeof frontPage.width !== 'number' || typeof frontPage.height !== 'number') return null;
57
-
58
- const dims: { width: number; height: number }[] = [];
59
- for (const img of images) {
60
- const d = readJpegDimensions(img.base64Img);
61
- if (!d) return null;
62
- dims.push(d);
63
- }
64
-
65
- // Veryfi may auto-rotate pages in the parsed result, so dimensions are
66
- // compared as an unordered pair.
67
- const sameDims = (d: { width: number; height: number }, w: number, h: number) =>
68
- (d.width === w && d.height === h) || (d.width === h && d.height === w);
69
-
70
- const matchesFront = dims.map((d) => sameDims(d, frontPage.width, frontPage.height));
71
- if (matchesFront.filter(Boolean).length !== 1) return null;
72
-
73
- const frontIdx = matchesFront.indexOf(true);
74
- const backIdx = 1 - frontIdx;
75
- const frontImage = images[frontIdx];
76
- const backImage = images[backIdx];
77
- const backDims = dims[backIdx];
78
- if (!frontImage || !backImage || !backDims) return null;
79
- if (typeof backPage.width === 'number' && typeof backPage.height === 'number') {
80
- if (!sameDims(backDims, backPage.width, backPage.height)) return null;
81
- }
82
-
83
- return [
84
- { base64Img: frontImage.base64Img, isFront: true },
85
- { base64Img: backImage.base64Img, isFront: false },
86
- ];
87
- };