@pagopa/io-react-native-cie 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/IoReactNativeCie.podspec +28 -0
- package/LICENSE +201 -0
- package/README.md +406 -0
- package/android/build.gradle +83 -0
- package/android/gradle.properties +5 -0
- package/android/src/main/AndroidManifest.xml +3 -0
- package/android/src/main/AndroidManifestNew.xml +2 -0
- package/android/src/main/java/com/pagopa/ioreactnativecie/IoReactNativeCieModule.kt +302 -0
- package/android/src/main/java/com/pagopa/ioreactnativecie/IoReactNativeCiePackage.kt +17 -0
- package/android/src/main/java/com/pagopa/ioreactnativecie/cie/Atr.kt +39 -0
- package/android/src/main/java/com/pagopa/ioreactnativecie/cie/CieType.kt +157 -0
- package/ios/CIEType.swift +81 -0
- package/ios/IoReactNativeCie-Bridging-Header.h +2 -0
- package/ios/IoReactNativeCie.mm +43 -0
- package/ios/IoReactNativeCie.swift +227 -0
- package/lib/module/errors.js +2 -0
- package/lib/module/errors.js.map +1 -0
- package/lib/module/index.js +6 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/manager/index.js +149 -0
- package/lib/module/manager/index.js.map +1 -0
- package/lib/module/manager/types.js +50 -0
- package/lib/module/manager/types.js.map +1 -0
- package/lib/module/native.js +13 -0
- package/lib/module/native.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/module/utils/index.js +45 -0
- package/lib/module/utils/index.js.map +1 -0
- package/lib/typescript/package.json +1 -0
- package/lib/typescript/src/errors.d.ts +24 -0
- package/lib/typescript/src/errors.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +6 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/lib/typescript/src/manager/index.d.ts +113 -0
- package/lib/typescript/src/manager/index.d.ts.map +1 -0
- package/lib/typescript/src/manager/types.d.ts +83 -0
- package/lib/typescript/src/manager/types.d.ts.map +1 -0
- package/lib/typescript/src/native.d.ts +2 -0
- package/lib/typescript/src/native.d.ts.map +1 -0
- package/lib/typescript/src/utils/index.d.ts +30 -0
- package/lib/typescript/src/utils/index.d.ts.map +1 -0
- package/package.json +158 -0
- package/src/errors.ts +32 -0
- package/src/index.ts +14 -0
- package/src/manager/index.ts +167 -0
- package/src/manager/types.ts +94 -0
- package/src/native.ts +18 -0
- package/src/utils/index.ts +42 -0
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Represent the key of the alert message that can be set during the CIE reading process
|
|
5
|
+
*
|
|
6
|
+
* **Note**: Alert messages are only available on iOS
|
|
7
|
+
*/
|
|
8
|
+
export const AlertMessageKey = z.enum([
|
|
9
|
+
'readingInstructions',
|
|
10
|
+
'moreTags',
|
|
11
|
+
'readingInProgress',
|
|
12
|
+
'readingSuccess',
|
|
13
|
+
'invalidCard',
|
|
14
|
+
'tagLost',
|
|
15
|
+
'cardLocked',
|
|
16
|
+
'wrongPin1AttemptLeft',
|
|
17
|
+
'wrongPin2AttemptLeft',
|
|
18
|
+
'genericError',
|
|
19
|
+
]);
|
|
20
|
+
|
|
21
|
+
export type AlertMessageKey = z.infer<typeof AlertMessageKey>;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Event emitted during the CIE reading process with the name of the event and the progress of the reading up to that point.
|
|
25
|
+
* Event names may differ based on the platform.
|
|
26
|
+
*/
|
|
27
|
+
export const NfcEvent = z.object({
|
|
28
|
+
name: z.string(),
|
|
29
|
+
progress: z.coerce.number(),
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
export type NfcEvent = z.infer<typeof NfcEvent>;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Name of the error emitted during the CIE reading process
|
|
36
|
+
*/
|
|
37
|
+
export const NfcErrorName = z.enum([
|
|
38
|
+
'NOT_A_CIE',
|
|
39
|
+
'TAG_LOST',
|
|
40
|
+
'CANCELLED_BY_USER',
|
|
41
|
+
'APDU_ERROR',
|
|
42
|
+
'WRONG_PIN',
|
|
43
|
+
'CARD_BLOCKED',
|
|
44
|
+
'NO_INTERNET_CONNECTION',
|
|
45
|
+
'CERTIFICATE_EXPIRED',
|
|
46
|
+
'CERTIFICATE_REVOKED',
|
|
47
|
+
'AUTHENTICATION_ERROR',
|
|
48
|
+
'GENERIC_ERROR',
|
|
49
|
+
]);
|
|
50
|
+
|
|
51
|
+
export type NfcErrorName = z.infer<typeof NfcErrorName>;
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Represent an NFC error emitted during the CIE reading process
|
|
55
|
+
* It contains the name of the error, the message and the number of attempts
|
|
56
|
+
*/
|
|
57
|
+
export const NfcError = z.union([
|
|
58
|
+
z.object({
|
|
59
|
+
name: NfcErrorName,
|
|
60
|
+
message: z.string().optional(),
|
|
61
|
+
}),
|
|
62
|
+
z.object({
|
|
63
|
+
name: z.literal(NfcErrorName.enum.WRONG_PIN),
|
|
64
|
+
message: z.string().optional(),
|
|
65
|
+
attempts: z.number(),
|
|
66
|
+
}),
|
|
67
|
+
]);
|
|
68
|
+
|
|
69
|
+
export type NfcError = z.infer<typeof NfcError>;
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Represent the CIE attributes containing the CIE type
|
|
73
|
+
*/
|
|
74
|
+
export const CieAttributes = z.object({
|
|
75
|
+
type: z.string(),
|
|
76
|
+
base64: z.string(),
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
export type CieAttributes = z.infer<typeof CieAttributes>;
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Event handler that can be used to handle the CIE events during the reading process
|
|
83
|
+
*/
|
|
84
|
+
export type CieEventHandlers = {
|
|
85
|
+
onEvent: (event: NfcEvent) => void;
|
|
86
|
+
onError: (error: NfcError) => void;
|
|
87
|
+
onAttributesSuccess: (attributes: CieAttributes) => void;
|
|
88
|
+
onSuccess: (uri: string) => void;
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Possible events that can be listened to
|
|
93
|
+
*/
|
|
94
|
+
export type CieEvent = keyof CieEventHandlers;
|
package/src/native.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { NativeModules, Platform } from 'react-native';
|
|
2
|
+
|
|
3
|
+
const LINKING_ERROR =
|
|
4
|
+
`The package '@pagopa/io-react-native-cie' doesn't seem to be linked. Make sure: \n\n` +
|
|
5
|
+
Platform.select({ ios: "- You have run 'pod install'\n", default: '' }) +
|
|
6
|
+
'- You rebuilt the app after installing the package\n' +
|
|
7
|
+
'- You are not using Expo Go\n';
|
|
8
|
+
|
|
9
|
+
export const IoReactNativeCie = NativeModules.IoReactNativeCie
|
|
10
|
+
? NativeModules.IoReactNativeCie
|
|
11
|
+
: new Proxy(
|
|
12
|
+
{},
|
|
13
|
+
{
|
|
14
|
+
get() {
|
|
15
|
+
throw new Error(LINKING_ERROR);
|
|
16
|
+
},
|
|
17
|
+
}
|
|
18
|
+
);
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { IoReactNativeCie } from '../native';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Checks if the device has NFC hardware capabilities.
|
|
5
|
+
*
|
|
6
|
+
* On iOS the NFC features is always available.
|
|
7
|
+
*
|
|
8
|
+
* @returns A promise that resolves to true if the device supports NFC, false otherwise.
|
|
9
|
+
* @throws {CieError} If cannot check if NFC is available.
|
|
10
|
+
*/
|
|
11
|
+
export const hasNfcFeature = async () => {
|
|
12
|
+
return IoReactNativeCie.hasNfcFeature();
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Checks if NFC is currently enabled on the device.
|
|
17
|
+
*
|
|
18
|
+
* On iOS the NFC features is always enabled.
|
|
19
|
+
*
|
|
20
|
+
* @returns A promise that resolves to true if NFC is enabled, false otherwise.
|
|
21
|
+
* @throws {CieError} If cannot check if NFC is enabled.
|
|
22
|
+
*/
|
|
23
|
+
export const isNfcEnabled = async () => {
|
|
24
|
+
return IoReactNativeCie.isNfcEnabled();
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Verifies if the device supports CIE (Electronic Identity Card) authentication.
|
|
29
|
+
* @returns A promise that resolves to true if CIE authentication is supported, false otherwise.
|
|
30
|
+
*/
|
|
31
|
+
export const isCieAuthenticationSupported = async () => {
|
|
32
|
+
return IoReactNativeCie.isCieAuthenticationSupported();
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Opens the device's NFC settings page, allowing users to enable or disable NFC.
|
|
37
|
+
* @returns A promise that resolves when the settings page is opened.
|
|
38
|
+
* @throws {CieError} If cannot open the settings page.
|
|
39
|
+
*/
|
|
40
|
+
export const openNfcSettings = async () => {
|
|
41
|
+
return IoReactNativeCie.openNfcSettings();
|
|
42
|
+
};
|