@saveeye/saveeye-sdk-reactnative-meter-recognition 0.0.0-stage → 0.1.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 (80) hide show
  1. package/LICENSE +20 -0
  2. package/README.md +112 -2
  3. package/android/build.gradle +123 -0
  4. package/android/generated/java/com/saveeyemeterrecognition/NativeSaveeyeMeterRecognitionSpec.java +38 -0
  5. package/android/generated/jni/CMakeLists.txt +36 -0
  6. package/android/generated/jni/RNSaveeyeMeterRecognitionSpec-generated.cpp +32 -0
  7. package/android/generated/jni/RNSaveeyeMeterRecognitionSpec.h +31 -0
  8. package/android/generated/jni/react/renderer/components/RNSaveeyeMeterRecognitionSpec/RNSaveeyeMeterRecognitionSpecJSI-generated.cpp +30 -0
  9. package/android/generated/jni/react/renderer/components/RNSaveeyeMeterRecognitionSpec/RNSaveeyeMeterRecognitionSpecJSI.h +114 -0
  10. package/android/gradle.properties +5 -0
  11. package/android/src/main/AndroidManifest.xml +3 -0
  12. package/android/src/main/AndroidManifestNew.xml +2 -0
  13. package/android/src/main/java/com/saveeyemeterrecognition/ImageResizer.kt +113 -0
  14. package/android/src/main/java/com/saveeyemeterrecognition/SaveeyeMeterRecognitionModule.kt +42 -0
  15. package/android/src/main/java/com/saveeyemeterrecognition/SaveeyeMeterRecognitionPackage.kt +34 -0
  16. package/ios/SaveeyeMeterRecognition.h +6 -0
  17. package/ios/SaveeyeMeterRecognition.mm +82 -0
  18. package/ios/generated/RNSaveeyeMeterRecognitionSpec/RNSaveeyeMeterRecognitionSpec-generated.mm +39 -0
  19. package/ios/generated/RNSaveeyeMeterRecognitionSpec/RNSaveeyeMeterRecognitionSpec.h +64 -0
  20. package/ios/generated/RNSaveeyeMeterRecognitionSpecJSI-generated.cpp +30 -0
  21. package/ios/generated/RNSaveeyeMeterRecognitionSpecJSI.h +114 -0
  22. package/lib/commonjs/ImageUtil.js +83 -0
  23. package/lib/commonjs/ImageUtil.js.map +1 -0
  24. package/lib/commonjs/MeterImageFilter.js +103 -0
  25. package/lib/commonjs/MeterImageFilter.js.map +1 -0
  26. package/lib/commonjs/NativeSaveeyeMeterRecognition.js +11 -0
  27. package/lib/commonjs/NativeSaveeyeMeterRecognition.js.map +1 -0
  28. package/lib/commonjs/index.js +51 -0
  29. package/lib/commonjs/index.js.map +1 -0
  30. package/lib/commonjs/recognizeMeter.js +84 -0
  31. package/lib/commonjs/recognizeMeter.js.map +1 -0
  32. package/lib/commonjs/types.js +21 -0
  33. package/lib/commonjs/types.js.map +1 -0
  34. package/lib/module/ImageUtil.js +77 -0
  35. package/lib/module/ImageUtil.js.map +1 -0
  36. package/lib/module/MeterImageFilter.js +96 -0
  37. package/lib/module/MeterImageFilter.js.map +1 -0
  38. package/lib/module/NativeSaveeyeMeterRecognition.js +7 -0
  39. package/lib/module/NativeSaveeyeMeterRecognition.js.map +1 -0
  40. package/lib/module/index.js +6 -0
  41. package/lib/module/index.js.map +1 -0
  42. package/lib/module/recognizeMeter.js +79 -0
  43. package/lib/module/recognizeMeter.js.map +1 -0
  44. package/lib/module/types.js +17 -0
  45. package/lib/module/types.js.map +1 -0
  46. package/lib/typescript/commonjs/package.json +1 -0
  47. package/lib/typescript/commonjs/src/ImageUtil.d.ts +10 -0
  48. package/lib/typescript/commonjs/src/ImageUtil.d.ts.map +1 -0
  49. package/lib/typescript/commonjs/src/MeterImageFilter.d.ts +32 -0
  50. package/lib/typescript/commonjs/src/MeterImageFilter.d.ts.map +1 -0
  51. package/lib/typescript/commonjs/src/NativeSaveeyeMeterRecognition.d.ts +17 -0
  52. package/lib/typescript/commonjs/src/NativeSaveeyeMeterRecognition.d.ts.map +1 -0
  53. package/lib/typescript/commonjs/src/index.d.ts +4 -0
  54. package/lib/typescript/commonjs/src/index.d.ts.map +1 -0
  55. package/lib/typescript/commonjs/src/recognizeMeter.d.ts +18 -0
  56. package/lib/typescript/commonjs/src/recognizeMeter.d.ts.map +1 -0
  57. package/lib/typescript/commonjs/src/types.d.ts +50 -0
  58. package/lib/typescript/commonjs/src/types.d.ts.map +1 -0
  59. package/lib/typescript/module/package.json +1 -0
  60. package/lib/typescript/module/src/ImageUtil.d.ts +10 -0
  61. package/lib/typescript/module/src/ImageUtil.d.ts.map +1 -0
  62. package/lib/typescript/module/src/MeterImageFilter.d.ts +32 -0
  63. package/lib/typescript/module/src/MeterImageFilter.d.ts.map +1 -0
  64. package/lib/typescript/module/src/NativeSaveeyeMeterRecognition.d.ts +17 -0
  65. package/lib/typescript/module/src/NativeSaveeyeMeterRecognition.d.ts.map +1 -0
  66. package/lib/typescript/module/src/index.d.ts +4 -0
  67. package/lib/typescript/module/src/index.d.ts.map +1 -0
  68. package/lib/typescript/module/src/recognizeMeter.d.ts +18 -0
  69. package/lib/typescript/module/src/recognizeMeter.d.ts.map +1 -0
  70. package/lib/typescript/module/src/types.d.ts +50 -0
  71. package/lib/typescript/module/src/types.d.ts.map +1 -0
  72. package/package.json +170 -4
  73. package/react-native.config.js +12 -0
  74. package/saveeye-sdk-meter-recognition.podspec +41 -0
  75. package/src/ImageUtil.ts +113 -0
  76. package/src/MeterImageFilter.ts +154 -0
  77. package/src/NativeSaveeyeMeterRecognition.ts +26 -0
  78. package/src/index.ts +22 -0
  79. package/src/recognizeMeter.ts +109 -0
  80. package/src/types.ts +55 -0
@@ -0,0 +1,50 @@
1
+ export type RecognitionImageFile = {
2
+ uri: string;
3
+ type: string;
4
+ name: string;
5
+ };
6
+ export declare enum MeterInterfaceType {
7
+ Base = "BASE",
8
+ Echelon = "ECHELON",
9
+ HanRj45 = "HAN_RJ45",
10
+ Ir = "IR",
11
+ Kamstrup = "KAMSTRUP",
12
+ P1 = "P1"
13
+ }
14
+ export declare enum AccessoryRequirement {
15
+ Optional = "OPTIONAL",
16
+ Required = "REQUIRED"
17
+ }
18
+ export type RecognizedPowerMeter = {
19
+ manufacturer: string;
20
+ model: string;
21
+ };
22
+ export type CompatibleProductAccessory = {
23
+ /** Set when the accessory is country-specific */
24
+ countryId?: string | null;
25
+ requirement: AccessoryRequirement;
26
+ description?: string | null;
27
+ isAvailable: boolean;
28
+ product: {
29
+ id: string;
30
+ name: string;
31
+ sku: string;
32
+ };
33
+ };
34
+ export type CompatibleProduct = {
35
+ /** Product identifier, usable when creating an order line */
36
+ id: string;
37
+ name: string;
38
+ sku: string;
39
+ meterInterfaceType: MeterInterfaceType;
40
+ accessories: CompatibleProductAccessory[];
41
+ };
42
+ export type RecognizedMeter = {
43
+ /** Whether this app/partner may access recognition details */
44
+ hasAccess: boolean;
45
+ /** Whether the image matched a known electricity meter */
46
+ success: boolean;
47
+ powerMeter?: RecognizedPowerMeter | null;
48
+ compatibleProducts: CompatibleProduct[];
49
+ };
50
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,oBAAoB,GAAG;IACjC,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,oBAAY,kBAAkB;IAC5B,IAAI,SAAS;IACb,OAAO,YAAY;IACnB,OAAO,aAAa;IACpB,EAAE,OAAO;IACT,QAAQ,aAAa;IACrB,EAAE,OAAO;CACV;AAED,oBAAY,oBAAoB;IAC9B,QAAQ,aAAa;IACrB,QAAQ,aAAa;CACtB;AAED,MAAM,MAAM,oBAAoB,GAAG;IACjC,YAAY,EAAE,MAAM,CAAC;IACrB,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,MAAM,MAAM,0BAA0B,GAAG;IACvC,iDAAiD;IACjD,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,WAAW,EAAE,oBAAoB,CAAC;IAClC,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,WAAW,EAAE,OAAO,CAAC;IACrB,OAAO,EAAE;QACP,EAAE,EAAE,MAAM,CAAC;QACX,IAAI,EAAE,MAAM,CAAC;QACb,GAAG,EAAE,MAAM,CAAC;KACb,CAAC;CACH,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG;IAC9B,6DAA6D;IAC7D,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;IACZ,kBAAkB,EAAE,kBAAkB,CAAC;IACvC,WAAW,EAAE,0BAA0B,EAAE,CAAC;CAC3C,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG;IAC5B,8DAA8D;IAC9D,SAAS,EAAE,OAAO,CAAC;IACnB,0DAA0D;IAC1D,OAAO,EAAE,OAAO,CAAC;IACjB,UAAU,CAAC,EAAE,oBAAoB,GAAG,IAAI,CAAC;IACzC,kBAAkB,EAAE,iBAAiB,EAAE,CAAC;CACzC,CAAC"}
@@ -0,0 +1 @@
1
+ {"type":"module"}
@@ -0,0 +1,10 @@
1
+ import type { RecognitionImageFile } from './types';
2
+ export declare const MAX_IMAGE_SIZE_BYTES: number;
3
+ /**
4
+ * Prepares an image for upload to recognizeMeter: converts HEIC/HEIF to JPEG
5
+ * (the backend only accepts JPEG or PNG), then resizes/compresses it if
6
+ * needed so it fits within maxBytes. Returns the original image unchanged
7
+ * if it's already a supported format and within the limit.
8
+ */
9
+ export declare function prepareImageForUpload(image: RecognitionImageFile, maxBytes?: number): Promise<RecognitionImageFile>;
10
+ //# sourceMappingURL=ImageUtil.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ImageUtil.d.ts","sourceRoot":"","sources":["../../../../src/ImageUtil.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAEpD,eAAO,MAAM,oBAAoB,QAAmB,CAAC;AAuDrD;;;;;GAKG;AACH,wBAAsB,qBAAqB,CACzC,KAAK,EAAE,oBAAoB,EAC3B,QAAQ,GAAE,MAA6B,GACtC,OAAO,CAAC,oBAAoB,CAAC,CA6C/B"}
@@ -0,0 +1,32 @@
1
+ import { type Label } from '@react-native-ml-kit/image-labeling';
2
+ /**
3
+ * On-device pre-check run before uploading a photo to recognizeMeter, so
4
+ * obviously unrelated photos (pets, feet, selfies, food...) are rejected
5
+ * without a network round-trip. Photos of a SaveEye device itself (detected
6
+ * by its QR code) are rejected with their own reason so apps can tell the
7
+ * user to photograph the power meter instead. Biased towards accepting: the
8
+ * backend still rejects anything that slips through, while a false rejection
9
+ * blocks a real user.
10
+ */
11
+ export type MeterImageCheckReason = 'meter_text' | 'meter_label' | 'rejected_label' | 'no_signal' | 'saveeye_device' | 'check_unavailable';
12
+ export type MeterImageCheck = {
13
+ isLikelyMeter: boolean;
14
+ reason: MeterImageCheckReason;
15
+ /** Highest-confidence label ML Kit returned, if any */
16
+ topLabel?: string;
17
+ /** Number of 4+ digit runs found by OCR (meter readings, serial numbers) */
18
+ digitRuns: number;
19
+ };
20
+ export declare const REJECT_LABEL_MIN_CONFIDENCE = 0.7;
21
+ export declare const METER_LABEL_MIN_CONFIDENCE = 0.5;
22
+ export declare const REJECT_LABELS: Set<string>;
23
+ export declare const METER_LABELS: Set<string>;
24
+ export declare function countDigitRuns(text: string): number;
25
+ export declare function evaluateMeterSignals(labels: Pick<Label, 'text' | 'confidence'>[], ocrText: string, barcodeValues?: string[]): MeterImageCheck;
26
+ /**
27
+ * Classifies a local image URI as likely/unlikely to show an electricity
28
+ * meter using on-device ML Kit OCR, image labeling and QR scanning. Never
29
+ * throws: if ML Kit fails, the image is accepted (`check_unavailable`).
30
+ */
31
+ export declare function checkMeterImage(uri: string): Promise<MeterImageCheck>;
32
+ //# sourceMappingURL=MeterImageFilter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MeterImageFilter.d.ts","sourceRoot":"","sources":["../../../../src/MeterImageFilter.ts"],"names":[],"mappings":"AACA,OAAsB,EAAE,KAAK,KAAK,EAAE,MAAM,qCAAqC,CAAC;AAGhF;;;;;;;;GAQG;AAEH,MAAM,MAAM,qBAAqB,GAC7B,YAAY,GACZ,aAAa,GACb,gBAAgB,GAChB,WAAW,GACX,gBAAgB,GAChB,mBAAmB,CAAC;AAExB,MAAM,MAAM,eAAe,GAAG;IAC5B,aAAa,EAAE,OAAO,CAAC;IACvB,MAAM,EAAE,qBAAqB,CAAC;IAC9B,uDAAuD;IACvD,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,4EAA4E;IAC5E,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,eAAO,MAAM,2BAA2B,MAAM,CAAC;AAC/C,eAAO,MAAM,0BAA0B,MAAM,CAAC;AAE9C,eAAO,MAAM,aAAa,aAuBxB,CAAC;AAEH,eAAO,MAAM,YAAY,aAUvB,CAAC;AAQH,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAKnD;AAED,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG,YAAY,CAAC,EAAE,EAC5C,OAAO,EAAE,MAAM,EACf,aAAa,GAAE,MAAM,EAAO,GAC3B,eAAe,CAyCjB;AAED;;;;GAIG;AACH,wBAAsB,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,CAAC,CAiB3E"}
@@ -0,0 +1,17 @@
1
+ import type { TurboModule } from 'react-native';
2
+ export type ResizedImage = {
3
+ uri: string;
4
+ size: number;
5
+ };
6
+ export interface Spec extends TurboModule {
7
+ /**
8
+ * Decodes the image at `uri` (any format the OS can read, incl. HEIC),
9
+ * applies its EXIF orientation, scales it down so neither side exceeds
10
+ * `maxDimension` and writes it to a temp file as `format` ('JPEG' | 'PNG')
11
+ * with `quality` 0-100 (JPEG only).
12
+ */
13
+ resizeImage(uri: string, maxDimension: number, quality: number, format: string): Promise<ResizedImage>;
14
+ }
15
+ declare const _default: Spec;
16
+ export default _default;
17
+ //# sourceMappingURL=NativeSaveeyeMeterRecognition.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"NativeSaveeyeMeterRecognition.d.ts","sourceRoot":"","sources":["../../../../src/NativeSaveeyeMeterRecognition.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAGhD,MAAM,MAAM,YAAY,GAAG;IACzB,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,MAAM,WAAW,IAAK,SAAQ,WAAW;IACvC;;;;;OAKG;IACH,WAAW,CACT,GAAG,EAAE,MAAM,EACX,YAAY,EAAE,MAAM,EACpB,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,YAAY,CAAC,CAAC;CAC1B;;AAID,wBAAwE"}
@@ -0,0 +1,4 @@
1
+ export { recognizeMeter, type MeterRecognitionResult, type RecognizeMeterOptions, } from './recognizeMeter';
2
+ export { checkMeterImage, evaluateMeterSignals, REJECT_LABELS, METER_LABELS, type MeterImageCheck, type MeterImageCheckReason, } from './MeterImageFilter';
3
+ export { MeterInterfaceType, AccessoryRequirement, type RecognitionImageFile, type RecognizedMeter, type RecognizedPowerMeter, type CompatibleProduct, type CompatibleProductAccessory, } from './types';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,KAAK,sBAAsB,EAC3B,KAAK,qBAAqB,GAC3B,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EACL,eAAe,EACf,oBAAoB,EACpB,aAAa,EACb,YAAY,EACZ,KAAK,eAAe,EACpB,KAAK,qBAAqB,GAC3B,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACL,kBAAkB,EAClB,oBAAoB,EACpB,KAAK,oBAAoB,EACzB,KAAK,eAAe,EACpB,KAAK,oBAAoB,EACzB,KAAK,iBAAiB,EACtB,KAAK,0BAA0B,GAChC,MAAM,SAAS,CAAC"}
@@ -0,0 +1,18 @@
1
+ import { type MeterImageCheck } from './MeterImageFilter';
2
+ import type { RecognitionImageFile, RecognizedMeter } from './types';
3
+ export type MeterRecognitionResult = RecognizedMeter & {
4
+ /** True when the on-device check rejected the image; nothing was uploaded */
5
+ rejectedLocally: boolean;
6
+ localCheck?: MeterImageCheck;
7
+ };
8
+ export type RecognizeMeterOptions = {
9
+ /** Skip the on-device "does this look like a meter" check */
10
+ skipLocalCheck?: boolean;
11
+ };
12
+ /**
13
+ * Checks the photo on-device and, if it plausibly shows an electricity
14
+ * meter, converts/resizes it and uploads it for recognition. The core SaveEye
15
+ * SDK must be initialized first, as it provides authentication.
16
+ */
17
+ export declare function recognizeMeter(image: RecognitionImageFile, countryId?: string, options?: RecognizeMeterOptions): Promise<MeterRecognitionResult>;
18
+ //# sourceMappingURL=recognizeMeter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"recognizeMeter.d.ts","sourceRoot":"","sources":["../../../../src/recognizeMeter.ts"],"names":[],"mappings":"AAGA,OAAO,EAAmB,KAAK,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAC3E,OAAO,KAAK,EAEV,oBAAoB,EACpB,eAAe,EAEhB,MAAM,SAAS,CAAC;AA6CjB,MAAM,MAAM,sBAAsB,GAAG,eAAe,GAAG;IACrD,6EAA6E;IAC7E,eAAe,EAAE,OAAO,CAAC;IACzB,UAAU,CAAC,EAAE,eAAe,CAAC;CAC9B,CAAC;AAEF,MAAM,MAAM,qBAAqB,GAAG;IAClC,6DAA6D;IAC7D,cAAc,CAAC,EAAE,OAAO,CAAC;CAC1B,CAAC;AAEF;;;;GAIG;AACH,wBAAsB,cAAc,CAClC,KAAK,EAAE,oBAAoB,EAC3B,SAAS,CAAC,EAAE,MAAM,EAClB,OAAO,CAAC,EAAE,qBAAqB,GAC9B,OAAO,CAAC,sBAAsB,CAAC,CAkCjC"}
@@ -0,0 +1,50 @@
1
+ export type RecognitionImageFile = {
2
+ uri: string;
3
+ type: string;
4
+ name: string;
5
+ };
6
+ export declare enum MeterInterfaceType {
7
+ Base = "BASE",
8
+ Echelon = "ECHELON",
9
+ HanRj45 = "HAN_RJ45",
10
+ Ir = "IR",
11
+ Kamstrup = "KAMSTRUP",
12
+ P1 = "P1"
13
+ }
14
+ export declare enum AccessoryRequirement {
15
+ Optional = "OPTIONAL",
16
+ Required = "REQUIRED"
17
+ }
18
+ export type RecognizedPowerMeter = {
19
+ manufacturer: string;
20
+ model: string;
21
+ };
22
+ export type CompatibleProductAccessory = {
23
+ /** Set when the accessory is country-specific */
24
+ countryId?: string | null;
25
+ requirement: AccessoryRequirement;
26
+ description?: string | null;
27
+ isAvailable: boolean;
28
+ product: {
29
+ id: string;
30
+ name: string;
31
+ sku: string;
32
+ };
33
+ };
34
+ export type CompatibleProduct = {
35
+ /** Product identifier, usable when creating an order line */
36
+ id: string;
37
+ name: string;
38
+ sku: string;
39
+ meterInterfaceType: MeterInterfaceType;
40
+ accessories: CompatibleProductAccessory[];
41
+ };
42
+ export type RecognizedMeter = {
43
+ /** Whether this app/partner may access recognition details */
44
+ hasAccess: boolean;
45
+ /** Whether the image matched a known electricity meter */
46
+ success: boolean;
47
+ powerMeter?: RecognizedPowerMeter | null;
48
+ compatibleProducts: CompatibleProduct[];
49
+ };
50
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,oBAAoB,GAAG;IACjC,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,oBAAY,kBAAkB;IAC5B,IAAI,SAAS;IACb,OAAO,YAAY;IACnB,OAAO,aAAa;IACpB,EAAE,OAAO;IACT,QAAQ,aAAa;IACrB,EAAE,OAAO;CACV;AAED,oBAAY,oBAAoB;IAC9B,QAAQ,aAAa;IACrB,QAAQ,aAAa;CACtB;AAED,MAAM,MAAM,oBAAoB,GAAG;IACjC,YAAY,EAAE,MAAM,CAAC;IACrB,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,MAAM,MAAM,0BAA0B,GAAG;IACvC,iDAAiD;IACjD,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,WAAW,EAAE,oBAAoB,CAAC;IAClC,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,WAAW,EAAE,OAAO,CAAC;IACrB,OAAO,EAAE;QACP,EAAE,EAAE,MAAM,CAAC;QACX,IAAI,EAAE,MAAM,CAAC;QACb,GAAG,EAAE,MAAM,CAAC;KACb,CAAC;CACH,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG;IAC9B,6DAA6D;IAC7D,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;IACZ,kBAAkB,EAAE,kBAAkB,CAAC;IACvC,WAAW,EAAE,0BAA0B,EAAE,CAAC;CAC3C,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG;IAC5B,8DAA8D;IAC9D,SAAS,EAAE,OAAO,CAAC;IACnB,0DAA0D;IAC1D,OAAO,EAAE,OAAO,CAAC;IACjB,UAAU,CAAC,EAAE,oBAAoB,GAAG,IAAI,CAAC;IACzC,kBAAkB,EAAE,iBAAiB,EAAE,CAAC;CACzC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,172 @@
1
1
  {
2
2
  "name": "@saveeye/saveeye-sdk-reactnative-meter-recognition",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "description": "Recognize electricity meters from photos with the SaveEye SDK, with on-device filtering of unrelated photos and native image resizing",
5
+ "source": "./src/index.ts",
6
+ "main": "./lib/commonjs/index.js",
7
+ "module": "./lib/module/index.js",
8
+ "types": "./lib/typescript/module/src/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "import": {
12
+ "types": "./lib/typescript/module/src/index.d.ts",
13
+ "default": "./lib/module/index.js"
14
+ },
15
+ "require": {
16
+ "types": "./lib/typescript/commonjs/src/index.d.ts",
17
+ "default": "./lib/commonjs/index.js"
18
+ }
19
+ }
20
+ },
21
+ "files": [
22
+ "src",
23
+ "lib",
24
+ "android",
25
+ "ios",
26
+ "*.podspec",
27
+ "react-native.config.js",
28
+ "!ios/build",
29
+ "!android/build",
30
+ "!android/gradle",
31
+ "!android/gradlew",
32
+ "!android/gradlew.bat",
33
+ "!android/local.properties",
34
+ "!**/__tests__",
35
+ "!**/__fixtures__",
36
+ "!**/__mocks__",
37
+ "!**/.*"
38
+ ],
39
+ "scripts": {
40
+ "test": "jest",
41
+ "typecheck": "tsc",
42
+ "lint": "eslint \"**/*.{js,ts,tsx}\"",
43
+ "clean": "del-cli lib",
44
+ "prepare": "bob build",
45
+ "format": "prettier --write ."
46
+ },
47
+ "keywords": [
48
+ "react-native",
49
+ "ios",
50
+ "android",
51
+ "saveeye",
52
+ "meter-recognition"
53
+ ],
54
+ "repository": {
55
+ "type": "git",
56
+ "url": "git+https://github.com/saveeye/SaveEye-SDK-MeterRecognition-ReactNative.git"
57
+ },
58
+ "author": "SaveEye ApS <thj@saveeye.dk> (https://www.saveeye.dk)",
59
+ "homepage": "https://github.com/saveeye/SaveEye-SDK-MeterRecognition-ReactNative#readme",
60
+ "bugs": {
61
+ "url": "https://github.com/saveeye/SaveEye-SDK-MeterRecognition-ReactNative/issues"
62
+ },
63
+ "license": "MIT",
64
+ "publishConfig": {
65
+ "registry": "https://registry.npmjs.org/"
66
+ },
67
+ "peerDependencies": {
68
+ "@apollo/client": "^3.12.4",
69
+ "@react-native-ml-kit/barcode-scanning": "^2.0.0",
70
+ "@react-native-ml-kit/image-labeling": "^2.0.0",
71
+ "@react-native-ml-kit/text-recognition": "^2.0.0",
72
+ "@saveeye/saveeye-sdk-reactnative": "^2.0.0-beta.0",
73
+ "react": "*",
74
+ "react-native": "*"
75
+ },
76
+ "devDependencies": {
77
+ "@apollo/client": "^3.12.4",
78
+ "@react-native-ml-kit/barcode-scanning": "2.0.0",
79
+ "@react-native-ml-kit/image-labeling": "2.0.0",
80
+ "@react-native-ml-kit/text-recognition": "2.0.0",
81
+ "@react-native/eslint-config": "^0.73.1",
82
+ "@saveeye/saveeye-sdk-reactnative": "file:../SaveEye-SDK-ReactNative",
83
+ "@types/jest": "^29.5.5",
84
+ "@types/react": "^18.2.44",
85
+ "del-cli": "^5.1.0",
86
+ "eslint": "^8.51.0",
87
+ "eslint-config-prettier": "^9.0.0",
88
+ "eslint-plugin-prettier": "^5.0.1",
89
+ "jest": "^29.7.0",
90
+ "prettier": "^3.0.3",
91
+ "react": "18.3.1",
92
+ "react-native": "0.76.5",
93
+ "react-native-builder-bob": "^0.35.2",
94
+ "typescript": "^5.2.2"
95
+ },
96
+ "jest": {
97
+ "preset": "react-native",
98
+ "modulePathIgnorePatterns": [
99
+ "<rootDir>/lib/"
100
+ ]
101
+ },
102
+ "eslintConfig": {
103
+ "root": true,
104
+ "extends": [
105
+ "@react-native",
106
+ "prettier"
107
+ ],
108
+ "rules": {
109
+ "react/react-in-jsx-scope": "off",
110
+ "prettier/prettier": [
111
+ "error",
112
+ {
113
+ "quoteProps": "consistent",
114
+ "singleQuote": true,
115
+ "tabWidth": 2,
116
+ "trailingComma": "es5",
117
+ "useTabs": false
118
+ }
119
+ ]
120
+ }
121
+ },
122
+ "eslintIgnore": [
123
+ "node_modules/",
124
+ "lib/"
125
+ ],
126
+ "prettier": {
127
+ "quoteProps": "consistent",
128
+ "singleQuote": true,
129
+ "tabWidth": 2,
130
+ "trailingComma": "es5",
131
+ "useTabs": false
132
+ },
133
+ "react-native-builder-bob": {
134
+ "source": "src",
135
+ "output": "lib",
136
+ "targets": [
137
+ "codegen",
138
+ [
139
+ "commonjs",
140
+ {
141
+ "esm": true
142
+ }
143
+ ],
144
+ [
145
+ "module",
146
+ {
147
+ "esm": true
148
+ }
149
+ ],
150
+ [
151
+ "typescript",
152
+ {
153
+ "project": "tsconfig.build.json",
154
+ "esm": true
155
+ }
156
+ ]
157
+ ]
158
+ },
159
+ "codegenConfig": {
160
+ "name": "RNSaveeyeMeterRecognitionSpec",
161
+ "type": "modules",
162
+ "jsSrcsDir": "src",
163
+ "outputDir": {
164
+ "ios": "ios/generated",
165
+ "android": "android/generated"
166
+ },
167
+ "android": {
168
+ "javaPackageName": "com.saveeyemeterrecognition"
169
+ },
170
+ "includesGeneratedCode": true
171
+ }
172
+ }
@@ -0,0 +1,12 @@
1
+ /**
2
+ * @type {import('@react-native-community/cli-types').UserDependencyConfig}
3
+ */
4
+ module.exports = {
5
+ dependency: {
6
+ platforms: {
7
+ android: {
8
+ cmakeListsPath: 'generated/jni/CMakeLists.txt',
9
+ },
10
+ },
11
+ },
12
+ };
@@ -0,0 +1,41 @@
1
+ require "json"
2
+
3
+ package = JSON.parse(File.read(File.join(__dir__, "package.json")))
4
+ folly_compiler_flags = '-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1 -Wno-comma -Wno-shorten-64-to-32'
5
+
6
+ Pod::Spec.new do |s|
7
+ s.name = "saveeye-sdk-meter-recognition"
8
+ s.version = package["version"]
9
+ s.summary = package["description"]
10
+ s.homepage = package["homepage"]
11
+ s.license = package["license"]
12
+ s.authors = package["author"]
13
+
14
+ s.platforms = { :ios => min_ios_version_supported }
15
+ s.source = { :git => "https://github.com/saveeye/SaveEye-SDK-MeterRecognition-ReactNative.git", :tag => "#{s.version}" }
16
+
17
+ s.source_files = "ios/**/*.{h,m,mm,cpp}"
18
+
19
+ # Use install_modules_dependencies helper to install the dependencies if React Native version >=0.71.0.
20
+ # See https://github.com/facebook/react-native/blob/febf6b7f33fdb4904669f99d795eba4c0f95d7bf/scripts/cocoapods/new_architecture.rb#L79.
21
+ if respond_to?(:install_modules_dependencies, true)
22
+ install_modules_dependencies(s)
23
+ else
24
+ s.dependency "React-Core"
25
+
26
+ # Don't install the dependencies when we run `pod install` in the old architecture.
27
+ if ENV['RCT_NEW_ARCH_ENABLED'] == '1' then
28
+ s.compiler_flags = folly_compiler_flags + " -DRCT_NEW_ARCH_ENABLED=1"
29
+ s.pod_target_xcconfig = {
30
+ "HEADER_SEARCH_PATHS" => "\"$(PODS_ROOT)/boost\"",
31
+ "OTHER_CPLUSPLUSFLAGS" => "-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1",
32
+ "CLANG_CXX_LANGUAGE_STANDARD" => "c++17"
33
+ }
34
+ s.dependency "React-Codegen"
35
+ s.dependency "RCT-Folly"
36
+ s.dependency "RCTRequired"
37
+ s.dependency "RCTTypeSafety"
38
+ s.dependency "ReactCommon/turbomodule/core"
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,113 @@
1
+ import NativeSaveeyeMeterRecognition from './NativeSaveeyeMeterRecognition';
2
+ import type { RecognitionImageFile } from './types';
3
+
4
+ export const MAX_IMAGE_SIZE_BYTES = 10 * 1024 * 1024;
5
+
6
+ const INITIAL_QUALITY = 90;
7
+ const MIN_QUALITY = 10;
8
+ const QUALITY_STEP = 15;
9
+ const INITIAL_MAX_DIMENSION = 4096;
10
+ const DIMENSION_SCALE_STEP = 0.8;
11
+ const MAX_ATTEMPTS = 6;
12
+
13
+ const HEIC_TYPE_PATTERN = /^image\/hei[cf]$/i;
14
+ const HEIC_EXTENSION_PATTERN = /\.hei[cf]$/i;
15
+
16
+ function getNativeModule() {
17
+ if (!NativeSaveeyeMeterRecognition) {
18
+ throw new Error(
19
+ 'SaveEye meter recognition native module is not linked. Rebuild the app after installing the package (pod install on iOS).'
20
+ );
21
+ }
22
+ return NativeSaveeyeMeterRecognition;
23
+ }
24
+
25
+ async function getFileSize(uri: string): Promise<number> {
26
+ const response = await fetch(uri);
27
+ const blob = await response.blob();
28
+ return blob.size;
29
+ }
30
+
31
+ function isHeic(image: RecognitionImageFile): boolean {
32
+ return (
33
+ HEIC_TYPE_PATTERN.test(image.type) ||
34
+ HEIC_EXTENSION_PATTERN.test(image.name) ||
35
+ HEIC_EXTENSION_PATTERN.test(image.uri)
36
+ );
37
+ }
38
+
39
+ async function convertHeicToJpeg(
40
+ image: RecognitionImageFile
41
+ ): Promise<{ image: RecognitionImageFile; size: number }> {
42
+ const converted = await getNativeModule().resizeImage(
43
+ image.uri,
44
+ INITIAL_MAX_DIMENSION,
45
+ INITIAL_QUALITY,
46
+ 'JPEG'
47
+ );
48
+
49
+ return {
50
+ image: {
51
+ uri: converted.uri,
52
+ type: 'image/jpeg',
53
+ name: image.name.replace(HEIC_EXTENSION_PATTERN, '.jpg'),
54
+ },
55
+ size: converted.size,
56
+ };
57
+ }
58
+
59
+ /**
60
+ * Prepares an image for upload to recognizeMeter: converts HEIC/HEIF to JPEG
61
+ * (the backend only accepts JPEG or PNG), then resizes/compresses it if
62
+ * needed so it fits within maxBytes. Returns the original image unchanged
63
+ * if it's already a supported format and within the limit.
64
+ */
65
+ export async function prepareImageForUpload(
66
+ image: RecognitionImageFile,
67
+ maxBytes: number = MAX_IMAGE_SIZE_BYTES
68
+ ): Promise<RecognitionImageFile> {
69
+ let current = image;
70
+ let size: number;
71
+
72
+ if (isHeic(current)) {
73
+ const converted = await convertHeicToJpeg(current);
74
+ current = converted.image;
75
+ size = converted.size;
76
+ } else {
77
+ size = await getFileSize(current.uri);
78
+ }
79
+
80
+ if (size <= maxBytes) {
81
+ return current;
82
+ }
83
+
84
+ const format = current.type === 'image/png' ? 'PNG' : 'JPEG';
85
+ let quality = INITIAL_QUALITY;
86
+ let maxDimension = INITIAL_MAX_DIMENSION;
87
+
88
+ for (let attempt = 0; attempt < MAX_ATTEMPTS && size > maxBytes; attempt++) {
89
+ const resized = await getNativeModule().resizeImage(
90
+ current.uri,
91
+ maxDimension,
92
+ quality,
93
+ format
94
+ );
95
+
96
+ current = {
97
+ uri: resized.uri,
98
+ type: format === 'PNG' ? 'image/png' : 'image/jpeg',
99
+ name: current.name,
100
+ };
101
+ size = resized.size;
102
+ quality = Math.max(MIN_QUALITY, quality - QUALITY_STEP);
103
+ maxDimension = Math.round(maxDimension * DIMENSION_SCALE_STEP);
104
+ }
105
+
106
+ if (size > maxBytes) {
107
+ throw new Error(
108
+ `Unable to resize image below ${maxBytes} bytes (final size: ${size} bytes)`
109
+ );
110
+ }
111
+
112
+ return current;
113
+ }