@passgage/sdk-react-native 1.0.1

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/README.md ADDED
@@ -0,0 +1,156 @@
1
+ # @passgage-sdk/react-native
2
+
3
+ React Native wrapper for Passgage Access SDK with ready-to-use components and hooks.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @passgage-sdk/react-native @passgage-sdk/core
9
+ # or
10
+ yarn add @passgage-sdk/react-native @passgage-sdk/core
11
+ ```
12
+
13
+ ### Peer Dependencies
14
+
15
+ You also need to install these peer dependencies:
16
+
17
+ ```bash
18
+ npm install react-native-vision-camera react-native-nfc-manager @react-native-community/geolocation
19
+ ```
20
+
21
+ Follow the installation instructions for each native library:
22
+ - [react-native-vision-camera](https://react-native-vision-camera.com/docs/guides)
23
+ - [react-native-nfc-manager](https://github.com/revtel/react-native-nfc-manager)
24
+ - [@react-native-community/geolocation](https://github.com/react-native-geolocation/react-native-geolocation)
25
+
26
+ ## Usage
27
+
28
+ ### Provider Setup
29
+
30
+ Wrap your app with `PassgageAccessProvider`:
31
+
32
+ ```typescript
33
+ import { PassgageAccessProvider } from '@passgage-sdk/react-native';
34
+
35
+ function App() {
36
+ return (
37
+ <PassgageAccessProvider
38
+ baseURL="https://your-api.passgage.com"
39
+ token="your-jwt-token"
40
+ >
41
+ <YourApp />
42
+ </PassgageAccessProvider>
43
+ );
44
+ }
45
+ ```
46
+
47
+ ### QR Scanner Hook
48
+
49
+ ```typescript
50
+ import { useQRScanner } from '@passgage-sdk/react-native';
51
+
52
+ function QRScanScreen() {
53
+ const { scan, isLoading, error } = useQRScanner({
54
+ onSuccess: (entrance) => {
55
+ console.log('QR scan successful:', entrance);
56
+ },
57
+ onError: (error) => {
58
+ console.error('QR scan failed:', error);
59
+ },
60
+ });
61
+
62
+ return (
63
+ <View>
64
+ {/* Your camera view */}
65
+ <Camera onCodeScanned={(code) => scan(code)} />
66
+ </View>
67
+ );
68
+ }
69
+ ```
70
+
71
+ ### NFC Scanner Hook
72
+
73
+ ```typescript
74
+ import { useNFCScanner } from '@passgage-sdk/react-native';
75
+
76
+ function NFCScanScreen() {
77
+ const { startScanning, stopScanning, isScanning } = useNFCScanner({
78
+ onSuccess: (entrance) => {
79
+ console.log('NFC scan successful:', entrance);
80
+ },
81
+ onError: (error) => {
82
+ console.error('NFC scan failed:', error);
83
+ },
84
+ });
85
+
86
+ useEffect(() => {
87
+ startScanning();
88
+ return () => stopScanning();
89
+ }, []);
90
+
91
+ return <View>{/* Your NFC scan UI */}</View>;
92
+ }
93
+ ```
94
+
95
+ ### Check-In Hook
96
+
97
+ ```typescript
98
+ import { useCheckIn } from '@passgage-sdk/react-native';
99
+
100
+ function CheckInScreen() {
101
+ const { nearbyBranches, checkIn, isLoading } = useCheckIn();
102
+
103
+ const handleCheckIn = async (branchId: string) => {
104
+ await checkIn({
105
+ branchId,
106
+ entranceType: 0, // 0 = ENTRY, 1 = EXIT
107
+ });
108
+ };
109
+
110
+ return (
111
+ <View>
112
+ {nearbyBranches.map((branch) => (
113
+ <TouchableOpacity key={branch.id} onPress={() => handleCheckIn(branch.id)}>
114
+ <Text>{branch.title}</Text>
115
+ </TouchableOpacity>
116
+ ))}
117
+ </View>
118
+ );
119
+ }
120
+ ```
121
+
122
+ ### Remote Work Hook
123
+
124
+ ```typescript
125
+ import { useRemoteWork } from '@passgage-sdk/react-native';
126
+
127
+ function RemoteWorkScreen() {
128
+ const { logEntry, logExit, isLoading } = useRemoteWork();
129
+
130
+ return (
131
+ <View>
132
+ <Button title="Log Entry" onPress={() => logEntry()} />
133
+ <Button title="Log Exit" onPress={() => logExit()} />
134
+ </View>
135
+ );
136
+ }
137
+ ```
138
+
139
+ ## API
140
+
141
+ ### Hooks
142
+
143
+ - `useQRScanner()` - QR code scanning with validation
144
+ - `useNFCScanner()` - NFC card scanning with validation
145
+ - `useCheckIn()` - GPS-based check-in
146
+ - `useRemoteWork()` - Remote work logging
147
+ - `useLocation()` - Location tracking
148
+ - `usePassgageAccess()` - Access SDK context
149
+
150
+ ### Components
151
+
152
+ - `<PassgageAccessProvider>` - SDK configuration provider
153
+
154
+ ## License
155
+
156
+ Proprietary - Passgage © 2025
@@ -0,0 +1,251 @@
1
+ import React, { ReactNode } from 'react';
2
+ import { ApiClient, AuthService, QRAccessService, NFCAccessService, CheckInService, RemoteWorkService, DeviceAccessService, LocationService, User, LoginCredentials, LoginResult, Entrance, QrDevice, EntranceType, Branch, Coordinates } from '@passgage/sdk-core';
3
+ export { BaseResponse, Branch, Coordinates, Device, Entrance, EntranceType, QrDevice } from '@passgage/sdk-core';
4
+
5
+ /**
6
+ * Passgage Access Provider
7
+ * Main provider component for SDK configuration
8
+ */
9
+
10
+ interface PassgageAccessConfig {
11
+ baseURL: string;
12
+ token?: string;
13
+ apiVersion?: string;
14
+ timeout?: number;
15
+ onUnauthorized?: () => void;
16
+ onError?: (error: Error) => void;
17
+ }
18
+ interface PassgageAccessContextValue {
19
+ apiClient: ApiClient;
20
+ authService: AuthService;
21
+ qrAccessService: QRAccessService;
22
+ nfcAccessService: NFCAccessService;
23
+ checkInService: CheckInService;
24
+ remoteWorkService: RemoteWorkService;
25
+ deviceAccessService: DeviceAccessService;
26
+ locationService: LocationService;
27
+ config: PassgageAccessConfig;
28
+ setToken: (token: string | null) => void;
29
+ clearToken: () => void;
30
+ }
31
+ interface PassgageAccessProviderProps {
32
+ children: ReactNode;
33
+ baseURL: string;
34
+ token?: string;
35
+ apiVersion?: string;
36
+ timeout?: number;
37
+ onUnauthorized?: () => void;
38
+ onError?: (error: Error) => void;
39
+ }
40
+ declare function PassgageAccessProvider({ children, baseURL, token, apiVersion, timeout, onUnauthorized, onError, }: PassgageAccessProviderProps): React.JSX.Element;
41
+ /**
42
+ * Hook to access Passgage SDK context
43
+ */
44
+ declare function usePassgageAccess(): PassgageAccessContextValue;
45
+
46
+ /**
47
+ * Authentication Hook
48
+ *
49
+ * Provides authentication functionality including login, logout, and user state management.
50
+ */
51
+
52
+ interface UsePassgageAuthOptions {
53
+ /**
54
+ * Callback called when login is successful
55
+ */
56
+ onLoginSuccess?: (user?: User) => void;
57
+ /**
58
+ * Callback called when login fails
59
+ */
60
+ onLoginError?: (error: string) => void;
61
+ /**
62
+ * Callback called when logout is successful
63
+ */
64
+ onLogoutSuccess?: () => void;
65
+ /**
66
+ * Automatically check for stored tokens on mount
67
+ * @default true
68
+ */
69
+ autoRestore?: boolean;
70
+ }
71
+ interface UsePassgageAuthReturn {
72
+ /**
73
+ * Login with credentials
74
+ */
75
+ login: (credentials: LoginCredentials) => Promise<LoginResult>;
76
+ /**
77
+ * Logout current user
78
+ */
79
+ logout: () => Promise<void>;
80
+ /**
81
+ * Refresh access token
82
+ */
83
+ refreshToken: () => Promise<boolean>;
84
+ /**
85
+ * Whether user is authenticated
86
+ */
87
+ isAuthenticated: boolean;
88
+ /**
89
+ * Current user information
90
+ */
91
+ user: User | null;
92
+ /**
93
+ * Whether an auth operation is in progress
94
+ */
95
+ isLoading: boolean;
96
+ /**
97
+ * Last error message
98
+ */
99
+ error: string | null;
100
+ /**
101
+ * Clear error message
102
+ */
103
+ clearError: () => void;
104
+ }
105
+ /**
106
+ * Authentication hook
107
+ *
108
+ * @example
109
+ * ```typescript
110
+ * function LoginScreen() {
111
+ * const { login, isLoading, error, isAuthenticated } = usePassgageAuth({
112
+ * onLoginSuccess: (user) => {
113
+ * console.log('Logged in:', user);
114
+ * navigation.navigate('Home');
115
+ * },
116
+ * onLoginError: (error) => {
117
+ * Alert.alert('Login Failed', error);
118
+ * }
119
+ * });
120
+ *
121
+ * const handleLogin = async () => {
122
+ * await login({
123
+ * login: 'user@example.com',
124
+ * password: 'password123'
125
+ * });
126
+ * };
127
+ *
128
+ * if (isAuthenticated) {
129
+ * return <Text>Already logged in!</Text>;
130
+ * }
131
+ *
132
+ * return (
133
+ * <View>
134
+ * <Button
135
+ * title="Login"
136
+ * onPress={handleLogin}
137
+ * disabled={isLoading}
138
+ * />
139
+ * {error && <Text>{error}</Text>}
140
+ * </View>
141
+ * );
142
+ * }
143
+ * ```
144
+ */
145
+ declare function usePassgageAuth(options?: UsePassgageAuthOptions): UsePassgageAuthReturn;
146
+
147
+ /**
148
+ * useQRScanner hook
149
+ * QR code scanning with validation
150
+ */
151
+
152
+ interface UseQRScannerOptions {
153
+ onSuccess?: (entrance?: Entrance) => void;
154
+ onError?: (error: Error) => void;
155
+ skipLocationCheck?: boolean;
156
+ skipRepetitiveCheck?: boolean;
157
+ }
158
+ interface UseQRScannerReturn {
159
+ scan: (qrCode: string, device?: QrDevice) => Promise<void>;
160
+ isLoading: boolean;
161
+ error: Error | null;
162
+ }
163
+ declare function useQRScanner(options?: UseQRScannerOptions): UseQRScannerReturn;
164
+
165
+ /**
166
+ * useNFCScanner hook
167
+ * NFC card scanning with validation
168
+ */
169
+
170
+ interface UseNFCScannerOptions {
171
+ onSuccess?: (entrance?: Entrance) => void;
172
+ onError?: (error: Error) => void;
173
+ skipLocationCheck?: boolean;
174
+ skipRepetitiveCheck?: boolean;
175
+ autoStart?: boolean;
176
+ }
177
+ interface UseNFCScannerReturn {
178
+ startScanning: () => Promise<void>;
179
+ stopScanning: () => Promise<void>;
180
+ isScanning: boolean;
181
+ error: Error | null;
182
+ }
183
+ declare function useNFCScanner(options?: UseNFCScannerOptions): UseNFCScannerReturn;
184
+
185
+ /**
186
+ * useCheckIn hook
187
+ * GPS-based check-in to nearby branches
188
+ */
189
+
190
+ interface UseCheckInOptions {
191
+ radius?: number;
192
+ autoFetch?: boolean;
193
+ }
194
+ interface CheckInParams {
195
+ branchId: string;
196
+ entranceType: EntranceType;
197
+ }
198
+ interface UseCheckInReturn {
199
+ nearbyBranches: Branch[];
200
+ fetchNearbyBranches: () => Promise<void>;
201
+ checkIn: (params: CheckInParams) => Promise<Entrance | undefined>;
202
+ isLoading: boolean;
203
+ error: Error | null;
204
+ }
205
+ declare function useCheckIn(options?: UseCheckInOptions): UseCheckInReturn;
206
+
207
+ /**
208
+ * useRemoteWork hook
209
+ * Remote work entry/exit logging
210
+ */
211
+
212
+ interface RemoteWorkOptions {
213
+ timestamp?: Date | string;
214
+ description?: string;
215
+ }
216
+ interface UseRemoteWorkReturn {
217
+ logEntry: (options?: RemoteWorkOptions) => Promise<Entrance | undefined>;
218
+ logExit: (options?: RemoteWorkOptions) => Promise<Entrance | undefined>;
219
+ logRemoteWork: (entranceType: EntranceType, options?: RemoteWorkOptions) => Promise<Entrance | undefined>;
220
+ isLoading: boolean;
221
+ error: Error | null;
222
+ }
223
+ declare function useRemoteWork(): UseRemoteWorkReturn;
224
+
225
+ /**
226
+ * useLocation hook
227
+ * Location tracking using React Native Geolocation
228
+ */
229
+
230
+ interface UseLocationOptions {
231
+ enableHighAccuracy?: boolean;
232
+ timeout?: number;
233
+ maximumAge?: number;
234
+ watchPosition?: boolean;
235
+ }
236
+ interface UseLocationReturn {
237
+ location: Coordinates | null;
238
+ error: Error | null;
239
+ isLoading: boolean;
240
+ refreshLocation: () => Promise<void>;
241
+ }
242
+ declare function useLocation(options?: UseLocationOptions): UseLocationReturn;
243
+
244
+ /**
245
+ * Passgage Access SDK - React Native Package
246
+ * React Native wrapper with components and hooks
247
+ */
248
+
249
+ declare const SDK_VERSION = "1.0.0";
250
+
251
+ export { type CheckInParams, type PassgageAccessConfig, type PassgageAccessContextValue, PassgageAccessProvider, type PassgageAccessProviderProps, type RemoteWorkOptions, SDK_VERSION, type UseCheckInOptions, type UseCheckInReturn, type UseLocationOptions, type UseLocationReturn, type UseNFCScannerOptions, type UseNFCScannerReturn, type UsePassgageAuthOptions, type UsePassgageAuthReturn, type UseQRScannerOptions, type UseQRScannerReturn, type UseRemoteWorkReturn, useCheckIn, useLocation, useNFCScanner, usePassgageAccess, usePassgageAuth, useQRScanner, useRemoteWork };
@@ -0,0 +1,251 @@
1
+ import React, { ReactNode } from 'react';
2
+ import { ApiClient, AuthService, QRAccessService, NFCAccessService, CheckInService, RemoteWorkService, DeviceAccessService, LocationService, User, LoginCredentials, LoginResult, Entrance, QrDevice, EntranceType, Branch, Coordinates } from '@passgage/sdk-core';
3
+ export { BaseResponse, Branch, Coordinates, Device, Entrance, EntranceType, QrDevice } from '@passgage/sdk-core';
4
+
5
+ /**
6
+ * Passgage Access Provider
7
+ * Main provider component for SDK configuration
8
+ */
9
+
10
+ interface PassgageAccessConfig {
11
+ baseURL: string;
12
+ token?: string;
13
+ apiVersion?: string;
14
+ timeout?: number;
15
+ onUnauthorized?: () => void;
16
+ onError?: (error: Error) => void;
17
+ }
18
+ interface PassgageAccessContextValue {
19
+ apiClient: ApiClient;
20
+ authService: AuthService;
21
+ qrAccessService: QRAccessService;
22
+ nfcAccessService: NFCAccessService;
23
+ checkInService: CheckInService;
24
+ remoteWorkService: RemoteWorkService;
25
+ deviceAccessService: DeviceAccessService;
26
+ locationService: LocationService;
27
+ config: PassgageAccessConfig;
28
+ setToken: (token: string | null) => void;
29
+ clearToken: () => void;
30
+ }
31
+ interface PassgageAccessProviderProps {
32
+ children: ReactNode;
33
+ baseURL: string;
34
+ token?: string;
35
+ apiVersion?: string;
36
+ timeout?: number;
37
+ onUnauthorized?: () => void;
38
+ onError?: (error: Error) => void;
39
+ }
40
+ declare function PassgageAccessProvider({ children, baseURL, token, apiVersion, timeout, onUnauthorized, onError, }: PassgageAccessProviderProps): React.JSX.Element;
41
+ /**
42
+ * Hook to access Passgage SDK context
43
+ */
44
+ declare function usePassgageAccess(): PassgageAccessContextValue;
45
+
46
+ /**
47
+ * Authentication Hook
48
+ *
49
+ * Provides authentication functionality including login, logout, and user state management.
50
+ */
51
+
52
+ interface UsePassgageAuthOptions {
53
+ /**
54
+ * Callback called when login is successful
55
+ */
56
+ onLoginSuccess?: (user?: User) => void;
57
+ /**
58
+ * Callback called when login fails
59
+ */
60
+ onLoginError?: (error: string) => void;
61
+ /**
62
+ * Callback called when logout is successful
63
+ */
64
+ onLogoutSuccess?: () => void;
65
+ /**
66
+ * Automatically check for stored tokens on mount
67
+ * @default true
68
+ */
69
+ autoRestore?: boolean;
70
+ }
71
+ interface UsePassgageAuthReturn {
72
+ /**
73
+ * Login with credentials
74
+ */
75
+ login: (credentials: LoginCredentials) => Promise<LoginResult>;
76
+ /**
77
+ * Logout current user
78
+ */
79
+ logout: () => Promise<void>;
80
+ /**
81
+ * Refresh access token
82
+ */
83
+ refreshToken: () => Promise<boolean>;
84
+ /**
85
+ * Whether user is authenticated
86
+ */
87
+ isAuthenticated: boolean;
88
+ /**
89
+ * Current user information
90
+ */
91
+ user: User | null;
92
+ /**
93
+ * Whether an auth operation is in progress
94
+ */
95
+ isLoading: boolean;
96
+ /**
97
+ * Last error message
98
+ */
99
+ error: string | null;
100
+ /**
101
+ * Clear error message
102
+ */
103
+ clearError: () => void;
104
+ }
105
+ /**
106
+ * Authentication hook
107
+ *
108
+ * @example
109
+ * ```typescript
110
+ * function LoginScreen() {
111
+ * const { login, isLoading, error, isAuthenticated } = usePassgageAuth({
112
+ * onLoginSuccess: (user) => {
113
+ * console.log('Logged in:', user);
114
+ * navigation.navigate('Home');
115
+ * },
116
+ * onLoginError: (error) => {
117
+ * Alert.alert('Login Failed', error);
118
+ * }
119
+ * });
120
+ *
121
+ * const handleLogin = async () => {
122
+ * await login({
123
+ * login: 'user@example.com',
124
+ * password: 'password123'
125
+ * });
126
+ * };
127
+ *
128
+ * if (isAuthenticated) {
129
+ * return <Text>Already logged in!</Text>;
130
+ * }
131
+ *
132
+ * return (
133
+ * <View>
134
+ * <Button
135
+ * title="Login"
136
+ * onPress={handleLogin}
137
+ * disabled={isLoading}
138
+ * />
139
+ * {error && <Text>{error}</Text>}
140
+ * </View>
141
+ * );
142
+ * }
143
+ * ```
144
+ */
145
+ declare function usePassgageAuth(options?: UsePassgageAuthOptions): UsePassgageAuthReturn;
146
+
147
+ /**
148
+ * useQRScanner hook
149
+ * QR code scanning with validation
150
+ */
151
+
152
+ interface UseQRScannerOptions {
153
+ onSuccess?: (entrance?: Entrance) => void;
154
+ onError?: (error: Error) => void;
155
+ skipLocationCheck?: boolean;
156
+ skipRepetitiveCheck?: boolean;
157
+ }
158
+ interface UseQRScannerReturn {
159
+ scan: (qrCode: string, device?: QrDevice) => Promise<void>;
160
+ isLoading: boolean;
161
+ error: Error | null;
162
+ }
163
+ declare function useQRScanner(options?: UseQRScannerOptions): UseQRScannerReturn;
164
+
165
+ /**
166
+ * useNFCScanner hook
167
+ * NFC card scanning with validation
168
+ */
169
+
170
+ interface UseNFCScannerOptions {
171
+ onSuccess?: (entrance?: Entrance) => void;
172
+ onError?: (error: Error) => void;
173
+ skipLocationCheck?: boolean;
174
+ skipRepetitiveCheck?: boolean;
175
+ autoStart?: boolean;
176
+ }
177
+ interface UseNFCScannerReturn {
178
+ startScanning: () => Promise<void>;
179
+ stopScanning: () => Promise<void>;
180
+ isScanning: boolean;
181
+ error: Error | null;
182
+ }
183
+ declare function useNFCScanner(options?: UseNFCScannerOptions): UseNFCScannerReturn;
184
+
185
+ /**
186
+ * useCheckIn hook
187
+ * GPS-based check-in to nearby branches
188
+ */
189
+
190
+ interface UseCheckInOptions {
191
+ radius?: number;
192
+ autoFetch?: boolean;
193
+ }
194
+ interface CheckInParams {
195
+ branchId: string;
196
+ entranceType: EntranceType;
197
+ }
198
+ interface UseCheckInReturn {
199
+ nearbyBranches: Branch[];
200
+ fetchNearbyBranches: () => Promise<void>;
201
+ checkIn: (params: CheckInParams) => Promise<Entrance | undefined>;
202
+ isLoading: boolean;
203
+ error: Error | null;
204
+ }
205
+ declare function useCheckIn(options?: UseCheckInOptions): UseCheckInReturn;
206
+
207
+ /**
208
+ * useRemoteWork hook
209
+ * Remote work entry/exit logging
210
+ */
211
+
212
+ interface RemoteWorkOptions {
213
+ timestamp?: Date | string;
214
+ description?: string;
215
+ }
216
+ interface UseRemoteWorkReturn {
217
+ logEntry: (options?: RemoteWorkOptions) => Promise<Entrance | undefined>;
218
+ logExit: (options?: RemoteWorkOptions) => Promise<Entrance | undefined>;
219
+ logRemoteWork: (entranceType: EntranceType, options?: RemoteWorkOptions) => Promise<Entrance | undefined>;
220
+ isLoading: boolean;
221
+ error: Error | null;
222
+ }
223
+ declare function useRemoteWork(): UseRemoteWorkReturn;
224
+
225
+ /**
226
+ * useLocation hook
227
+ * Location tracking using React Native Geolocation
228
+ */
229
+
230
+ interface UseLocationOptions {
231
+ enableHighAccuracy?: boolean;
232
+ timeout?: number;
233
+ maximumAge?: number;
234
+ watchPosition?: boolean;
235
+ }
236
+ interface UseLocationReturn {
237
+ location: Coordinates | null;
238
+ error: Error | null;
239
+ isLoading: boolean;
240
+ refreshLocation: () => Promise<void>;
241
+ }
242
+ declare function useLocation(options?: UseLocationOptions): UseLocationReturn;
243
+
244
+ /**
245
+ * Passgage Access SDK - React Native Package
246
+ * React Native wrapper with components and hooks
247
+ */
248
+
249
+ declare const SDK_VERSION = "1.0.0";
250
+
251
+ export { type CheckInParams, type PassgageAccessConfig, type PassgageAccessContextValue, PassgageAccessProvider, type PassgageAccessProviderProps, type RemoteWorkOptions, SDK_VERSION, type UseCheckInOptions, type UseCheckInReturn, type UseLocationOptions, type UseLocationReturn, type UseNFCScannerOptions, type UseNFCScannerReturn, type UsePassgageAuthOptions, type UsePassgageAuthReturn, type UseQRScannerOptions, type UseQRScannerReturn, type UseRemoteWorkReturn, useCheckIn, useLocation, useNFCScanner, usePassgageAccess, usePassgageAuth, useQRScanner, useRemoteWork };