@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.
Files changed (48) hide show
  1. package/IoReactNativeCie.podspec +28 -0
  2. package/LICENSE +201 -0
  3. package/README.md +406 -0
  4. package/android/build.gradle +83 -0
  5. package/android/gradle.properties +5 -0
  6. package/android/src/main/AndroidManifest.xml +3 -0
  7. package/android/src/main/AndroidManifestNew.xml +2 -0
  8. package/android/src/main/java/com/pagopa/ioreactnativecie/IoReactNativeCieModule.kt +302 -0
  9. package/android/src/main/java/com/pagopa/ioreactnativecie/IoReactNativeCiePackage.kt +17 -0
  10. package/android/src/main/java/com/pagopa/ioreactnativecie/cie/Atr.kt +39 -0
  11. package/android/src/main/java/com/pagopa/ioreactnativecie/cie/CieType.kt +157 -0
  12. package/ios/CIEType.swift +81 -0
  13. package/ios/IoReactNativeCie-Bridging-Header.h +2 -0
  14. package/ios/IoReactNativeCie.mm +43 -0
  15. package/ios/IoReactNativeCie.swift +227 -0
  16. package/lib/module/errors.js +2 -0
  17. package/lib/module/errors.js.map +1 -0
  18. package/lib/module/index.js +6 -0
  19. package/lib/module/index.js.map +1 -0
  20. package/lib/module/manager/index.js +149 -0
  21. package/lib/module/manager/index.js.map +1 -0
  22. package/lib/module/manager/types.js +50 -0
  23. package/lib/module/manager/types.js.map +1 -0
  24. package/lib/module/native.js +13 -0
  25. package/lib/module/native.js.map +1 -0
  26. package/lib/module/package.json +1 -0
  27. package/lib/module/utils/index.js +45 -0
  28. package/lib/module/utils/index.js.map +1 -0
  29. package/lib/typescript/package.json +1 -0
  30. package/lib/typescript/src/errors.d.ts +24 -0
  31. package/lib/typescript/src/errors.d.ts.map +1 -0
  32. package/lib/typescript/src/index.d.ts +6 -0
  33. package/lib/typescript/src/index.d.ts.map +1 -0
  34. package/lib/typescript/src/manager/index.d.ts +113 -0
  35. package/lib/typescript/src/manager/index.d.ts.map +1 -0
  36. package/lib/typescript/src/manager/types.d.ts +83 -0
  37. package/lib/typescript/src/manager/types.d.ts.map +1 -0
  38. package/lib/typescript/src/native.d.ts +2 -0
  39. package/lib/typescript/src/native.d.ts.map +1 -0
  40. package/lib/typescript/src/utils/index.d.ts +30 -0
  41. package/lib/typescript/src/utils/index.d.ts.map +1 -0
  42. package/package.json +158 -0
  43. package/src/errors.ts +32 -0
  44. package/src/index.ts +14 -0
  45. package/src/manager/index.ts +167 -0
  46. package/src/manager/types.ts +94 -0
  47. package/src/native.ts +18 -0
  48. package/src/utils/index.ts +42 -0
@@ -0,0 +1,113 @@
1
+ import { AlertMessageKey, type CieEvent, type CieEventHandlers } from './types';
2
+ /**
3
+ * Adds a listener for a specific CIE event.
4
+ *
5
+ * @param event - The event to listen to {@see CieEvent}
6
+ * @param listener - The listener to add {@see CieEventHandler}
7
+ * @returns Function to remove the listener
8
+ * @example
9
+ * ```typescript
10
+ * const removeListener = CieManager.addListener('onEvent', event => {
11
+ * console.log(event.name, event.progress);
12
+ * });
13
+ * // ...
14
+ * removeListener();
15
+ */
16
+ declare const addListener: <E extends CieEvent>(event: E, listener: CieEventHandlers[E]) => () => void;
17
+ /**
18
+ * Removes a listener for a specific CIE event.
19
+ *
20
+ * @param event - The event to remove the listener from {@see CieEvent}
21
+ */
22
+ declare const removeListener: (event: CieEvent) => void;
23
+ /**
24
+ * Removes all registered event, error, and success listeners for CIE operations.
25
+ *
26
+ * @example
27
+ * ```typescript
28
+ * CieManager.removeAllListeners();
29
+ * ```
30
+ */
31
+ declare const removeAllListeners: () => void;
32
+ /**
33
+ * Sets a custom Identity Provider (IDP) URL for authentication.
34
+ * If not set, will be used the default IDP URL:
35
+ * https://idserver.servizicie.interno.gov.it/idp/
36
+ *
37
+ * @param url - The custom IDP URL to use
38
+ * @example
39
+ * ```typescript
40
+ * CieManager.setCustomIdpUrl('https://custom.idp.com/auth');
41
+ * ```
42
+ */
43
+ declare const setCustomIdpUrl: (url: string) => any;
44
+ /**
45
+ * Sets an alert message for the CIE reading process.
46
+ *
47
+ * **Note**: Alert messages are only available on iOS
48
+ *
49
+ * @param key - The key of the alert message to set
50
+ * @param value - The value of the alert message to set
51
+ * @example
52
+ * ```typescript
53
+ * CieManager.setAlertMessage('readingInstructions', 'Please scan your CIE card');
54
+ * ```
55
+ */
56
+ export declare const setAlertMessage: (key: AlertMessageKey, value: string) => any;
57
+ /**
58
+ * Updates the current displayed alert message for the CIE reading process.
59
+ *
60
+ * **Note**: Alert messages are only available on iOS
61
+ *
62
+ * @param value - The value of the alert message to set
63
+ * @example
64
+ * ```typescript
65
+ * CieManager.setCurrentAlertMessage('Please scan your CIE card');
66
+ * ```
67
+ */
68
+ export declare const setCurrentAlertMessage: (value: string) => any;
69
+ /**
70
+ * Starts the process of reading attributes from the CIE card.
71
+ *
72
+ * @param timeout - Optional timeout in milliseconds (default: 10000) (**Note**: Android only)
73
+ * @returns Promise<void>
74
+ * @throws {CieError} If reading attributes fails
75
+ * @example
76
+ * ```typescript
77
+ * await CieManager.startReadingAttributes();
78
+ * // or with custom timeout
79
+ * await CieManager.startReadingAttributes(15000);
80
+ * ```
81
+ */
82
+ declare const startReadingAttributes: (timeout?: number) => Promise<void>;
83
+ /**
84
+ * Starts the CIE reading and authentication process.
85
+ *
86
+ * @param pin - The CIE card PIN code
87
+ * @param authenticationUrl - The authentication service URL
88
+ * @param timeout - Optional timeout in milliseconds (default: 10000) (**Note**: Android only)
89
+ * @returns Promise<void>
90
+ * @throws {CieError} If could not start reading for authentication
91
+ * @example
92
+ * ```typescript
93
+ * await CieManager.startReading('12345678', 'https://idserver.example.com/auth');
94
+ * // or with custom timeout
95
+ * await CieManager.startReading('12345678', 'https://idserver.example.com/auth', 20000);
96
+ * ```
97
+ */
98
+ declare const startReading: (pin: string, authenticationUrl: string, timeout?: number) => Promise<void>;
99
+ /**
100
+ * Stops any ongoing CIE reading process.
101
+ *
102
+ * **Note:** Android only. On iOS the reading process is stopped by closing
103
+ * the system NFC overlay
104
+ *
105
+ * @returns Promise<void>
106
+ * @example
107
+ * ```typescript
108
+ * await CieManager.stopReading();
109
+ * ```
110
+ */
111
+ declare const stopReading: () => Promise<void>;
112
+ export { addListener, removeListener, removeAllListeners, setCustomIdpUrl, startReadingAttributes, startReading, stopReading, };
113
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/manager/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,KAAK,QAAQ,EAAE,KAAK,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAMhF;;;;;;;;;;;;;GAaG;AACH,QAAA,MAAM,WAAW,GAAI,CAAC,SAAS,QAAQ,EACrC,OAAO,CAAC,EACR,UAAU,gBAAgB,CAAC,CAAC,CAAC,eAI9B,CAAC;AAEF;;;;GAIG;AACH,QAAA,MAAM,cAAc,GAAI,OAAO,QAAQ,SAEtC,CAAC;AAEF;;;;;;;GAOG;AACH,QAAA,MAAM,kBAAkB,YAKvB,CAAC;AAEF;;;;;;;;;;GAUG;AACH,QAAA,MAAM,eAAe,GAAI,KAAK,MAAM,QAEnC,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,eAAe,GAAI,KAAK,eAAe,EAAE,OAAO,MAAM,QAElE,CAAC;AAEF;;;;;;;;;;GAUG;AACH,eAAO,MAAM,sBAAsB,GAAI,OAAO,MAAM,QAEnD,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,QAAA,MAAM,sBAAsB,GAC1B,UAAS,MAAwB,KAChC,OAAO,CAAC,IAAI,CAEd,CAAC;AAEF;;;;;;;;;;;;;;GAcG;AACH,QAAA,MAAM,YAAY,GAChB,KAAK,MAAM,EACX,mBAAmB,MAAM,EACzB,UAAS,MAAwB,KAChC,OAAO,CAAC,IAAI,CAEd,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,QAAA,MAAM,WAAW,QAAa,OAAO,CAAC,IAAI,CAEzC,CAAC;AAEF,OAAO,EACL,WAAW,EACX,cAAc,EACd,kBAAkB,EAClB,eAAe,EACf,sBAAsB,EACtB,YAAY,EACZ,WAAW,GACZ,CAAC"}
@@ -0,0 +1,83 @@
1
+ import { z } from 'zod';
2
+ /**
3
+ * Represent the key of the alert message that can be set during the CIE reading process
4
+ *
5
+ * **Note**: Alert messages are only available on iOS
6
+ */
7
+ export declare const AlertMessageKey: z.ZodEnum<["readingInstructions", "moreTags", "readingInProgress", "readingSuccess", "invalidCard", "tagLost", "cardLocked", "wrongPin1AttemptLeft", "wrongPin2AttemptLeft", "genericError"]>;
8
+ export type AlertMessageKey = z.infer<typeof AlertMessageKey>;
9
+ /**
10
+ * Event emitted during the CIE reading process with the name of the event and the progress of the reading up to that point.
11
+ * Event names may differ based on the platform.
12
+ */
13
+ export declare const NfcEvent: z.ZodObject<{
14
+ name: z.ZodString;
15
+ progress: z.ZodNumber;
16
+ }, "strip", z.ZodTypeAny, {
17
+ name: string;
18
+ progress: number;
19
+ }, {
20
+ name: string;
21
+ progress: number;
22
+ }>;
23
+ export type NfcEvent = z.infer<typeof NfcEvent>;
24
+ /**
25
+ * Name of the error emitted during the CIE reading process
26
+ */
27
+ export declare const NfcErrorName: z.ZodEnum<["NOT_A_CIE", "TAG_LOST", "CANCELLED_BY_USER", "APDU_ERROR", "WRONG_PIN", "CARD_BLOCKED", "NO_INTERNET_CONNECTION", "CERTIFICATE_EXPIRED", "CERTIFICATE_REVOKED", "AUTHENTICATION_ERROR", "GENERIC_ERROR"]>;
28
+ export type NfcErrorName = z.infer<typeof NfcErrorName>;
29
+ /**
30
+ * Represent an NFC error emitted during the CIE reading process
31
+ * It contains the name of the error, the message and the number of attempts
32
+ */
33
+ export declare const NfcError: z.ZodUnion<[z.ZodObject<{
34
+ name: z.ZodEnum<["NOT_A_CIE", "TAG_LOST", "CANCELLED_BY_USER", "APDU_ERROR", "WRONG_PIN", "CARD_BLOCKED", "NO_INTERNET_CONNECTION", "CERTIFICATE_EXPIRED", "CERTIFICATE_REVOKED", "AUTHENTICATION_ERROR", "GENERIC_ERROR"]>;
35
+ message: z.ZodOptional<z.ZodString>;
36
+ }, "strip", z.ZodTypeAny, {
37
+ name: "NOT_A_CIE" | "TAG_LOST" | "CANCELLED_BY_USER" | "APDU_ERROR" | "WRONG_PIN" | "CARD_BLOCKED" | "NO_INTERNET_CONNECTION" | "CERTIFICATE_EXPIRED" | "CERTIFICATE_REVOKED" | "AUTHENTICATION_ERROR" | "GENERIC_ERROR";
38
+ message?: string | undefined;
39
+ }, {
40
+ name: "NOT_A_CIE" | "TAG_LOST" | "CANCELLED_BY_USER" | "APDU_ERROR" | "WRONG_PIN" | "CARD_BLOCKED" | "NO_INTERNET_CONNECTION" | "CERTIFICATE_EXPIRED" | "CERTIFICATE_REVOKED" | "AUTHENTICATION_ERROR" | "GENERIC_ERROR";
41
+ message?: string | undefined;
42
+ }>, z.ZodObject<{
43
+ name: z.ZodLiteral<"WRONG_PIN">;
44
+ message: z.ZodOptional<z.ZodString>;
45
+ attempts: z.ZodNumber;
46
+ }, "strip", z.ZodTypeAny, {
47
+ name: "WRONG_PIN";
48
+ attempts: number;
49
+ message?: string | undefined;
50
+ }, {
51
+ name: "WRONG_PIN";
52
+ attempts: number;
53
+ message?: string | undefined;
54
+ }>]>;
55
+ export type NfcError = z.infer<typeof NfcError>;
56
+ /**
57
+ * Represent the CIE attributes containing the CIE type
58
+ */
59
+ export declare const CieAttributes: z.ZodObject<{
60
+ type: z.ZodString;
61
+ base64: z.ZodString;
62
+ }, "strip", z.ZodTypeAny, {
63
+ type: string;
64
+ base64: string;
65
+ }, {
66
+ type: string;
67
+ base64: string;
68
+ }>;
69
+ export type CieAttributes = z.infer<typeof CieAttributes>;
70
+ /**
71
+ * Event handler that can be used to handle the CIE events during the reading process
72
+ */
73
+ export type CieEventHandlers = {
74
+ onEvent: (event: NfcEvent) => void;
75
+ onError: (error: NfcError) => void;
76
+ onAttributesSuccess: (attributes: CieAttributes) => void;
77
+ onSuccess: (uri: string) => void;
78
+ };
79
+ /**
80
+ * Possible events that can be listened to
81
+ */
82
+ export type CieEvent = keyof CieEventHandlers;
83
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/manager/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB;;;;GAIG;AACH,eAAO,MAAM,eAAe,+LAW1B,CAAC;AAEH,MAAM,MAAM,eAAe,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,eAAe,CAAC,CAAC;AAE9D;;;GAGG;AACH,eAAO,MAAM,QAAQ;;;;;;;;;EAGnB,CAAC;AAEH,MAAM,MAAM,QAAQ,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,QAAQ,CAAC,CAAC;AAEhD;;GAEG;AACH,eAAO,MAAM,YAAY,uNAYvB,CAAC;AAEH,MAAM,MAAM,YAAY,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,YAAY,CAAC,CAAC;AAExD;;;GAGG;AACH,eAAO,MAAM,QAAQ;;;;;;;;;;;;;;;;;;;;;IAUnB,CAAC;AAEH,MAAM,MAAM,QAAQ,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,QAAQ,CAAC,CAAC;AAEhD;;GAEG;AACH,eAAO,MAAM,aAAa;;;;;;;;;EAGxB,CAAC;AAEH,MAAM,MAAM,aAAa,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,aAAa,CAAC,CAAC;AAE1D;;GAEG;AACH,MAAM,MAAM,gBAAgB,GAAG;IAC7B,OAAO,EAAE,CAAC,KAAK,EAAE,QAAQ,KAAK,IAAI,CAAC;IACnC,OAAO,EAAE,CAAC,KAAK,EAAE,QAAQ,KAAK,IAAI,CAAC;IACnC,mBAAmB,EAAE,CAAC,UAAU,EAAE,aAAa,KAAK,IAAI,CAAC;IACzD,SAAS,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAC;CAClC,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,QAAQ,GAAG,MAAM,gBAAgB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare const IoReactNativeCie: any;
2
+ //# sourceMappingURL=native.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"native.d.ts","sourceRoot":"","sources":["../../../src/native.ts"],"names":[],"mappings":"AAQA,eAAO,MAAM,gBAAgB,KASxB,CAAC"}
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Checks if the device has NFC hardware capabilities.
3
+ *
4
+ * On iOS the NFC features is always available.
5
+ *
6
+ * @returns A promise that resolves to true if the device supports NFC, false otherwise.
7
+ * @throws {CieError} If cannot check if NFC is available.
8
+ */
9
+ export declare const hasNfcFeature: () => Promise<any>;
10
+ /**
11
+ * Checks if NFC is currently enabled on the device.
12
+ *
13
+ * On iOS the NFC features is always enabled.
14
+ *
15
+ * @returns A promise that resolves to true if NFC is enabled, false otherwise.
16
+ * @throws {CieError} If cannot check if NFC is enabled.
17
+ */
18
+ export declare const isNfcEnabled: () => Promise<any>;
19
+ /**
20
+ * Verifies if the device supports CIE (Electronic Identity Card) authentication.
21
+ * @returns A promise that resolves to true if CIE authentication is supported, false otherwise.
22
+ */
23
+ export declare const isCieAuthenticationSupported: () => Promise<any>;
24
+ /**
25
+ * Opens the device's NFC settings page, allowing users to enable or disable NFC.
26
+ * @returns A promise that resolves when the settings page is opened.
27
+ * @throws {CieError} If cannot open the settings page.
28
+ */
29
+ export declare const openNfcSettings: () => Promise<any>;
30
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/utils/index.ts"],"names":[],"mappings":"AAEA;;;;;;;GAOG;AACH,eAAO,MAAM,aAAa,oBAEzB,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,YAAY,oBAExB,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,4BAA4B,oBAExC,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,eAAe,oBAE3B,CAAC"}
package/package.json ADDED
@@ -0,0 +1,158 @@
1
+ {
2
+ "name": "@pagopa/io-react-native-cie",
3
+ "version": "1.0.0",
4
+ "description": "Native support for CIE",
5
+ "source": "./src/index.ts",
6
+ "main": "./lib/module/index.js",
7
+ "types": "./lib/typescript/src/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./lib/typescript/src/index.d.ts",
11
+ "default": "./lib/module/index.js"
12
+ },
13
+ "./package.json": "./package.json"
14
+ },
15
+ "files": [
16
+ "src",
17
+ "lib",
18
+ "android",
19
+ "ios",
20
+ "cpp",
21
+ "*.podspec",
22
+ "react-native.config.js",
23
+ "!ios/build",
24
+ "!android/build",
25
+ "!android/gradle",
26
+ "!android/gradlew",
27
+ "!android/gradlew.bat",
28
+ "!android/local.properties",
29
+ "!**/__tests__",
30
+ "!**/__fixtures__",
31
+ "!**/__mocks__",
32
+ "!**/.*"
33
+ ],
34
+ "scripts": {
35
+ "example": "yarn workspace @pagopa/io-react-native-cie-example",
36
+ "test": "jest",
37
+ "typecheck": "tsc",
38
+ "lint": "eslint \"**/*.{js,ts,tsx}\"",
39
+ "clean": "del-cli android/build example/android/build example/android/app/build example/ios/build lib",
40
+ "prepare": "bob build",
41
+ "release": "release-it"
42
+ },
43
+ "keywords": [
44
+ "react-native",
45
+ "ios",
46
+ "android"
47
+ ],
48
+ "repository": {
49
+ "type": "git",
50
+ "url": "git+https://github.com/pagopa/io-react-native-cie.git"
51
+ },
52
+ "author": "PagoPa (https://github.com/pagopa)",
53
+ "license": "MIT",
54
+ "bugs": {
55
+ "url": "https://github.com/pagopa/io-react-native-cie/issues"
56
+ },
57
+ "homepage": "https://github.com/pagopa/io-react-native-cie#readme",
58
+ "publishConfig": {
59
+ "registry": "https://registry.npmjs.org/"
60
+ },
61
+ "devDependencies": {
62
+ "@commitlint/config-conventional": "^19.6.0",
63
+ "@eslint/compat": "^1.2.7",
64
+ "@eslint/eslintrc": "^3.3.0",
65
+ "@eslint/js": "^9.22.0",
66
+ "@evilmartians/lefthook": "^1.5.0",
67
+ "@react-native/eslint-config": "^0.78.0",
68
+ "@release-it/conventional-changelog": "^9.0.2",
69
+ "@types/jest": "^29.5.5",
70
+ "@types/react": "^19.0.0",
71
+ "commitlint": "^19.6.1",
72
+ "del-cli": "^5.1.0",
73
+ "eslint": "^9.22.0",
74
+ "eslint-config-prettier": "^10.1.1",
75
+ "eslint-plugin-eslint-comments": "^3.2.0",
76
+ "eslint-plugin-prettier": "^5.2.3",
77
+ "jest": "^29.7.0",
78
+ "prettier": "^3.0.3",
79
+ "react": "19.0.0",
80
+ "react-native": "0.78.2",
81
+ "react-native-builder-bob": "^0.40.6",
82
+ "release-it": "^17.10.0",
83
+ "turbo": "^1.10.7",
84
+ "typescript": "^5.2.2"
85
+ },
86
+ "peerDependencies": {
87
+ "react": "*",
88
+ "react-native": "*"
89
+ },
90
+ "workspaces": [
91
+ "example"
92
+ ],
93
+ "packageManager": "yarn@3.6.1",
94
+ "jest": {
95
+ "preset": "react-native",
96
+ "modulePathIgnorePatterns": [
97
+ "<rootDir>/example/node_modules",
98
+ "<rootDir>/lib/"
99
+ ]
100
+ },
101
+ "commitlint": {
102
+ "extends": [
103
+ "@commitlint/config-conventional"
104
+ ]
105
+ },
106
+ "release-it": {
107
+ "git": {
108
+ "commitMessage": "chore: release ${version}",
109
+ "tagName": "v${version}"
110
+ },
111
+ "npm": {
112
+ "publish": true
113
+ },
114
+ "github": {
115
+ "release": true
116
+ },
117
+ "plugins": {
118
+ "@release-it/conventional-changelog": {
119
+ "preset": {
120
+ "name": "angular"
121
+ }
122
+ }
123
+ }
124
+ },
125
+ "prettier": {
126
+ "quoteProps": "consistent",
127
+ "singleQuote": true,
128
+ "tabWidth": 2,
129
+ "trailingComma": "es5",
130
+ "useTabs": false
131
+ },
132
+ "react-native-builder-bob": {
133
+ "source": "src",
134
+ "output": "lib",
135
+ "targets": [
136
+ [
137
+ "module",
138
+ {
139
+ "esm": true
140
+ }
141
+ ],
142
+ [
143
+ "typescript",
144
+ {
145
+ "project": "tsconfig.build.json"
146
+ }
147
+ ]
148
+ ]
149
+ },
150
+ "create-react-native-library": {
151
+ "type": "legacy-module",
152
+ "languages": "kotlin-swift",
153
+ "version": "0.49.8"
154
+ },
155
+ "dependencies": {
156
+ "zod": "^3.24.4"
157
+ }
158
+ }
package/src/errors.ts ADDED
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Error codes returned by the iOS module.
3
+ */
4
+ type CieErrorCodesIOS =
5
+ | 'PIN_REGEX_NOT_VALID'
6
+ | 'INVALID_AUTH_URL'
7
+ | 'THREADING_ERROR'
8
+ | 'UNKNOWN_EXCEPTION';
9
+
10
+ /**
11
+ * Error codes returned by the Android side.
12
+ */
13
+ type CieErrorCodesAndroid =
14
+ | 'PIN_REGEX_NOT_VALID'
15
+ | 'INVALID_AUTH_URL'
16
+ | 'UNKNOWN_EXCEPTION';
17
+
18
+ /**
19
+ * All error codes that the module could return.
20
+ */
21
+ export type CieErrorCodes = CieErrorCodesAndroid | CieErrorCodesIOS;
22
+
23
+ /**
24
+ * Error type returned by a rejected promise.
25
+ *
26
+ * If additional error information are available,
27
+ * they are stored in the {@link CieError["userInfo"]} field.
28
+ */
29
+ export type CieError = {
30
+ message: CieErrorCodes;
31
+ userInfo: Record<string, string>;
32
+ };
package/src/index.ts ADDED
@@ -0,0 +1,14 @@
1
+ import * as CieUtils from './utils';
2
+ import * as CieManager from './manager';
3
+
4
+ export { CieUtils, CieManager };
5
+
6
+ export type {
7
+ NfcEvent,
8
+ NfcError,
9
+ CieAttributes,
10
+ CieEventHandlers,
11
+ CieEvent,
12
+ } from './manager/types';
13
+
14
+ export type { CieError, CieErrorCodes } from './errors';
@@ -0,0 +1,167 @@
1
+ import { NativeEventEmitter, NativeModules } from 'react-native';
2
+ import { IoReactNativeCie } from '../native';
3
+ import { AlertMessageKey, type CieEvent, type CieEventHandlers } from './types';
4
+
5
+ const DEFAULT_TIMEOUT = 10000;
6
+
7
+ const eventEmitter = new NativeEventEmitter(NativeModules.IoReactNativeCie);
8
+
9
+ /**
10
+ * Adds a listener for a specific CIE event.
11
+ *
12
+ * @param event - The event to listen to {@see CieEvent}
13
+ * @param listener - The listener to add {@see CieEventHandler}
14
+ * @returns Function to remove the listener
15
+ * @example
16
+ * ```typescript
17
+ * const removeListener = CieManager.addListener('onEvent', event => {
18
+ * console.log(event.name, event.progress);
19
+ * });
20
+ * // ...
21
+ * removeListener();
22
+ */
23
+ const addListener = <E extends CieEvent>(
24
+ event: E,
25
+ listener: CieEventHandlers[E]
26
+ ) => {
27
+ const subscription = eventEmitter.addListener(event, listener);
28
+ return subscription.remove;
29
+ };
30
+
31
+ /**
32
+ * Removes a listener for a specific CIE event.
33
+ *
34
+ * @param event - The event to remove the listener from {@see CieEvent}
35
+ */
36
+ const removeListener = (event: CieEvent) => {
37
+ eventEmitter.removeAllListeners(event);
38
+ };
39
+
40
+ /**
41
+ * Removes all registered event, error, and success listeners for CIE operations.
42
+ *
43
+ * @example
44
+ * ```typescript
45
+ * CieManager.removeAllListeners();
46
+ * ```
47
+ */
48
+ const removeAllListeners = () => {
49
+ eventEmitter.removeAllListeners('onEvent');
50
+ eventEmitter.removeAllListeners('onError');
51
+ eventEmitter.removeAllListeners('onAttributesSuccess');
52
+ eventEmitter.removeAllListeners('onSuccess');
53
+ };
54
+
55
+ /**
56
+ * Sets a custom Identity Provider (IDP) URL for authentication.
57
+ * If not set, will be used the default IDP URL:
58
+ * https://idserver.servizicie.interno.gov.it/idp/
59
+ *
60
+ * @param url - The custom IDP URL to use
61
+ * @example
62
+ * ```typescript
63
+ * CieManager.setCustomIdpUrl('https://custom.idp.com/auth');
64
+ * ```
65
+ */
66
+ const setCustomIdpUrl = (url: string) => {
67
+ return IoReactNativeCie.setCustomIdpUrl(url);
68
+ };
69
+
70
+ /**
71
+ * Sets an alert message for the CIE reading process.
72
+ *
73
+ * **Note**: Alert messages are only available on iOS
74
+ *
75
+ * @param key - The key of the alert message to set
76
+ * @param value - The value of the alert message to set
77
+ * @example
78
+ * ```typescript
79
+ * CieManager.setAlertMessage('readingInstructions', 'Please scan your CIE card');
80
+ * ```
81
+ */
82
+ export const setAlertMessage = (key: AlertMessageKey, value: string) => {
83
+ return IoReactNativeCie.setAlertMessage(key, value);
84
+ };
85
+
86
+ /**
87
+ * Updates the current displayed alert message for the CIE reading process.
88
+ *
89
+ * **Note**: Alert messages are only available on iOS
90
+ *
91
+ * @param value - The value of the alert message to set
92
+ * @example
93
+ * ```typescript
94
+ * CieManager.setCurrentAlertMessage('Please scan your CIE card');
95
+ * ```
96
+ */
97
+ export const setCurrentAlertMessage = (value: string) => {
98
+ return IoReactNativeCie.setCurrentAlertMessage(value);
99
+ };
100
+
101
+ /**
102
+ * Starts the process of reading attributes from the CIE card.
103
+ *
104
+ * @param timeout - Optional timeout in milliseconds (default: 10000) (**Note**: Android only)
105
+ * @returns Promise<void>
106
+ * @throws {CieError} If reading attributes fails
107
+ * @example
108
+ * ```typescript
109
+ * await CieManager.startReadingAttributes();
110
+ * // or with custom timeout
111
+ * await CieManager.startReadingAttributes(15000);
112
+ * ```
113
+ */
114
+ const startReadingAttributes = async (
115
+ timeout: number = DEFAULT_TIMEOUT
116
+ ): Promise<void> => {
117
+ return IoReactNativeCie.startReadingAttributes(timeout);
118
+ };
119
+
120
+ /**
121
+ * Starts the CIE reading and authentication process.
122
+ *
123
+ * @param pin - The CIE card PIN code
124
+ * @param authenticationUrl - The authentication service URL
125
+ * @param timeout - Optional timeout in milliseconds (default: 10000) (**Note**: Android only)
126
+ * @returns Promise<void>
127
+ * @throws {CieError} If could not start reading for authentication
128
+ * @example
129
+ * ```typescript
130
+ * await CieManager.startReading('12345678', 'https://idserver.example.com/auth');
131
+ * // or with custom timeout
132
+ * await CieManager.startReading('12345678', 'https://idserver.example.com/auth', 20000);
133
+ * ```
134
+ */
135
+ const startReading = async (
136
+ pin: string,
137
+ authenticationUrl: string,
138
+ timeout: number = DEFAULT_TIMEOUT
139
+ ): Promise<void> => {
140
+ return IoReactNativeCie.startReading(pin, authenticationUrl, timeout);
141
+ };
142
+
143
+ /**
144
+ * Stops any ongoing CIE reading process.
145
+ *
146
+ * **Note:** Android only. On iOS the reading process is stopped by closing
147
+ * the system NFC overlay
148
+ *
149
+ * @returns Promise<void>
150
+ * @example
151
+ * ```typescript
152
+ * await CieManager.stopReading();
153
+ * ```
154
+ */
155
+ const stopReading = async (): Promise<void> => {
156
+ return IoReactNativeCie.stopReading();
157
+ };
158
+
159
+ export {
160
+ addListener,
161
+ removeListener,
162
+ removeAllListeners,
163
+ setCustomIdpUrl,
164
+ startReadingAttributes,
165
+ startReading,
166
+ stopReading,
167
+ };