@passgage/sdk-react-native 1.0.3 → 1.0.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.
- package/README.md +165 -33
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
# @passgage-
|
|
1
|
+
# @passgage/sdk-react-native
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Complete Passgage Access SDK for React Native with authentication, QR/NFC scanning, check-in, and remote work features.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
7
7
|
```bash
|
|
8
|
-
npm install @passgage-
|
|
8
|
+
npm install @passgage/sdk-react-native
|
|
9
9
|
# or
|
|
10
|
-
yarn add @passgage-
|
|
10
|
+
yarn add @passgage/sdk-react-native
|
|
11
11
|
```
|
|
12
12
|
|
|
13
13
|
### Peer Dependencies
|
|
@@ -15,13 +15,14 @@ yarn add @passgage-sdk/react-native @passgage-sdk/core
|
|
|
15
15
|
You also need to install these peer dependencies:
|
|
16
16
|
|
|
17
17
|
```bash
|
|
18
|
-
npm install react-native-vision-camera react-native-nfc-manager @react-native-community/geolocation
|
|
18
|
+
npm install react-native-vision-camera react-native-nfc-manager @react-native-community/geolocation react-native-keychain
|
|
19
19
|
```
|
|
20
20
|
|
|
21
21
|
Follow the installation instructions for each native library:
|
|
22
22
|
- [react-native-vision-camera](https://react-native-vision-camera.com/docs/guides)
|
|
23
23
|
- [react-native-nfc-manager](https://github.com/revtel/react-native-nfc-manager)
|
|
24
24
|
- [@react-native-community/geolocation](https://github.com/react-native-geolocation/react-native-geolocation)
|
|
25
|
+
- [react-native-keychain](https://github.com/oblador/react-native-keychain)
|
|
25
26
|
|
|
26
27
|
## Usage
|
|
27
28
|
|
|
@@ -30,13 +31,16 @@ Follow the installation instructions for each native library:
|
|
|
30
31
|
Wrap your app with `PassgageAccessProvider`:
|
|
31
32
|
|
|
32
33
|
```typescript
|
|
33
|
-
import { PassgageAccessProvider } from '@passgage-
|
|
34
|
+
import { PassgageAccessProvider } from '@passgage/sdk-react-native';
|
|
34
35
|
|
|
35
36
|
function App() {
|
|
36
37
|
return (
|
|
37
38
|
<PassgageAccessProvider
|
|
38
39
|
baseURL="https://your-api.passgage.com"
|
|
39
|
-
|
|
40
|
+
onUnauthorized={() => {
|
|
41
|
+
// Handle session expiration
|
|
42
|
+
console.log('Session expired');
|
|
43
|
+
}}
|
|
40
44
|
>
|
|
41
45
|
<YourApp />
|
|
42
46
|
</PassgageAccessProvider>
|
|
@@ -44,13 +48,47 @@ function App() {
|
|
|
44
48
|
}
|
|
45
49
|
```
|
|
46
50
|
|
|
47
|
-
###
|
|
51
|
+
### Authentication
|
|
48
52
|
|
|
49
53
|
```typescript
|
|
50
|
-
import {
|
|
54
|
+
import { usePassgageAuth } from '@passgage/sdk-react-native';
|
|
55
|
+
|
|
56
|
+
function LoginScreen() {
|
|
57
|
+
const { login, logout, user, isLoading, isAuthenticated } = usePassgageAuth({
|
|
58
|
+
onLoginSuccess: (user) => {
|
|
59
|
+
console.log('Logged in:', user?.fullName);
|
|
60
|
+
},
|
|
61
|
+
onLoginError: (error) => {
|
|
62
|
+
console.error('Login failed:', error);
|
|
63
|
+
},
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
const handleLogin = async () => {
|
|
67
|
+
await login({
|
|
68
|
+
login: 'user@example.com',
|
|
69
|
+
password: 'password123',
|
|
70
|
+
});
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
return (
|
|
74
|
+
<View>
|
|
75
|
+
{isAuthenticated ? (
|
|
76
|
+
<Text>Welcome, {user?.fullName}!</Text>
|
|
77
|
+
) : (
|
|
78
|
+
<Button title="Login" onPress={handleLogin} disabled={isLoading} />
|
|
79
|
+
)}
|
|
80
|
+
</View>
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
### QR Scanner
|
|
86
|
+
|
|
87
|
+
```typescript
|
|
88
|
+
import { usePassgageQRScanner } from '@passgage/sdk-react-native';
|
|
51
89
|
|
|
52
90
|
function QRScanScreen() {
|
|
53
|
-
const { scan, isLoading, error } =
|
|
91
|
+
const { scan, isLoading, error } = usePassgageQRScanner({
|
|
54
92
|
onSuccess: (entrance) => {
|
|
55
93
|
console.log('QR scan successful:', entrance);
|
|
56
94
|
},
|
|
@@ -61,20 +99,22 @@ function QRScanScreen() {
|
|
|
61
99
|
|
|
62
100
|
return (
|
|
63
101
|
<View>
|
|
64
|
-
|
|
65
|
-
|
|
102
|
+
<Camera
|
|
103
|
+
onCodeScanned={(code) => scan(code)}
|
|
104
|
+
isActive={!isLoading}
|
|
105
|
+
/>
|
|
66
106
|
</View>
|
|
67
107
|
);
|
|
68
108
|
}
|
|
69
109
|
```
|
|
70
110
|
|
|
71
|
-
### NFC Scanner
|
|
111
|
+
### NFC Scanner
|
|
72
112
|
|
|
73
113
|
```typescript
|
|
74
|
-
import {
|
|
114
|
+
import { usePassgageNFCScanner } from '@passgage/sdk-react-native';
|
|
75
115
|
|
|
76
116
|
function NFCScanScreen() {
|
|
77
|
-
const { startScanning, stopScanning, isScanning } =
|
|
117
|
+
const { startScanning, stopScanning, isScanning } = usePassgageNFCScanner({
|
|
78
118
|
onSuccess: (entrance) => {
|
|
79
119
|
console.log('NFC scan successful:', entrance);
|
|
80
120
|
},
|
|
@@ -88,28 +128,48 @@ function NFCScanScreen() {
|
|
|
88
128
|
return () => stopScanning();
|
|
89
129
|
}, []);
|
|
90
130
|
|
|
91
|
-
return
|
|
131
|
+
return (
|
|
132
|
+
<View>
|
|
133
|
+
<Text>{isScanning ? 'Scanning...' : 'Tap to scan'}</Text>
|
|
134
|
+
</View>
|
|
135
|
+
);
|
|
92
136
|
}
|
|
93
137
|
```
|
|
94
138
|
|
|
95
|
-
### Check-In
|
|
139
|
+
### Check-In
|
|
96
140
|
|
|
97
141
|
```typescript
|
|
98
|
-
import {
|
|
142
|
+
import { usePassgageCheckIn, usePassgageAuth } from '@passgage/sdk-react-native';
|
|
99
143
|
|
|
100
144
|
function CheckInScreen() {
|
|
101
|
-
const {
|
|
145
|
+
const { user } = usePassgageAuth();
|
|
146
|
+
const { getNearbyBranches, checkInEntry, checkInExit, isLoading } = usePassgageCheckIn();
|
|
147
|
+
const [branches, setBranches] = useState([]);
|
|
148
|
+
|
|
149
|
+
useEffect(() => {
|
|
150
|
+
const loadBranches = async () => {
|
|
151
|
+
const result = await getNearbyBranches({ radius: 5000 });
|
|
152
|
+
if (result.success) {
|
|
153
|
+
setBranches(result.data);
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
loadBranches();
|
|
157
|
+
}, []);
|
|
102
158
|
|
|
103
159
|
const handleCheckIn = async (branchId: string) => {
|
|
104
|
-
await
|
|
160
|
+
const result = await checkInEntry({
|
|
105
161
|
branchId,
|
|
106
|
-
|
|
162
|
+
userId: user.id,
|
|
107
163
|
});
|
|
164
|
+
|
|
165
|
+
if (result.success) {
|
|
166
|
+
console.log('Checked in successfully');
|
|
167
|
+
}
|
|
108
168
|
};
|
|
109
169
|
|
|
110
170
|
return (
|
|
111
171
|
<View>
|
|
112
|
-
{
|
|
172
|
+
{branches.map((branch) => (
|
|
113
173
|
<TouchableOpacity key={branch.id} onPress={() => handleCheckIn(branch.id)}>
|
|
114
174
|
<Text>{branch.title}</Text>
|
|
115
175
|
</TouchableOpacity>
|
|
@@ -119,18 +179,41 @@ function CheckInScreen() {
|
|
|
119
179
|
}
|
|
120
180
|
```
|
|
121
181
|
|
|
122
|
-
### Remote Work
|
|
182
|
+
### Remote Work
|
|
123
183
|
|
|
124
184
|
```typescript
|
|
125
|
-
import {
|
|
185
|
+
import { usePassgageRemoteWork, usePassgageAuth } from '@passgage/sdk-react-native';
|
|
126
186
|
|
|
127
187
|
function RemoteWorkScreen() {
|
|
128
|
-
const {
|
|
188
|
+
const { user } = usePassgageAuth();
|
|
189
|
+
const { logEntry, logExit, isLoading } = usePassgageRemoteWork();
|
|
190
|
+
|
|
191
|
+
const handleStartWork = async () => {
|
|
192
|
+
const result = await logEntry({
|
|
193
|
+
userId: user.id,
|
|
194
|
+
description: 'Working from home',
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
if (result.success) {
|
|
198
|
+
console.log('Work entry logged');
|
|
199
|
+
}
|
|
200
|
+
};
|
|
201
|
+
|
|
202
|
+
const handleEndWork = async () => {
|
|
203
|
+
const result = await logExit({
|
|
204
|
+
userId: user.id,
|
|
205
|
+
description: 'Finished work',
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
if (result.success) {
|
|
209
|
+
console.log('Work exit logged');
|
|
210
|
+
}
|
|
211
|
+
};
|
|
129
212
|
|
|
130
213
|
return (
|
|
131
214
|
<View>
|
|
132
|
-
<Button title="
|
|
133
|
-
<Button title="
|
|
215
|
+
<Button title="Start Work" onPress={handleStartWork} disabled={isLoading} />
|
|
216
|
+
<Button title="End Work" onPress={handleEndWork} disabled={isLoading} />
|
|
134
217
|
</View>
|
|
135
218
|
);
|
|
136
219
|
}
|
|
@@ -140,17 +223,66 @@ function RemoteWorkScreen() {
|
|
|
140
223
|
|
|
141
224
|
### Hooks
|
|
142
225
|
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
- `
|
|
146
|
-
- `
|
|
147
|
-
- `
|
|
148
|
-
- `
|
|
226
|
+
All hooks use the `usePassgage*` prefix to avoid naming conflicts:
|
|
227
|
+
|
|
228
|
+
- `usePassgageAuth()` - Authentication and user management
|
|
229
|
+
- `usePassgageQRScanner()` - QR code scanning with validation
|
|
230
|
+
- `usePassgageNFCScanner()` - NFC card scanning with validation
|
|
231
|
+
- `usePassgageCheckIn()` - GPS-based check-in with nearby branches
|
|
232
|
+
- `usePassgageRemoteWork()` - Remote work entry/exit logging
|
|
233
|
+
- `useLocation()` - Location tracking and permissions
|
|
234
|
+
- `usePassgageAccess()` - Access SDK context and services
|
|
149
235
|
|
|
150
236
|
### Components
|
|
151
237
|
|
|
152
238
|
- `<PassgageAccessProvider>` - SDK configuration provider
|
|
153
239
|
|
|
240
|
+
### Services
|
|
241
|
+
|
|
242
|
+
Low-level services are also available through `usePassgageAccess()`:
|
|
243
|
+
|
|
244
|
+
- `authService` - Authentication operations
|
|
245
|
+
- `qrAccessService` - QR code validation
|
|
246
|
+
- `nfcAccessService` - NFC card validation
|
|
247
|
+
- `checkInService` - Check-in operations
|
|
248
|
+
- `remoteWorkService` - Remote work logging
|
|
249
|
+
- `locationService` - Location management
|
|
250
|
+
- `deviceAccessService` - Device operations
|
|
251
|
+
|
|
252
|
+
## Security Features
|
|
253
|
+
|
|
254
|
+
- **JWT Authentication**: Secure token-based authentication
|
|
255
|
+
- **Automatic Token Refresh**: Tokens are automatically refreshed when expired
|
|
256
|
+
- **Secure Storage**: Tokens stored securely using platform-specific secure storage
|
|
257
|
+
- **TLS 1.2+**: All network communications encrypted
|
|
258
|
+
- **Location Verification**: Automatic location validation with range checking
|
|
259
|
+
- **Anti-Passback**: Support for anti-passback rules
|
|
260
|
+
|
|
261
|
+
## Token Flow
|
|
262
|
+
|
|
263
|
+
The SDK automatically handles authentication tokens:
|
|
264
|
+
|
|
265
|
+
1. User logs in → JWT tokens stored securely
|
|
266
|
+
2. API client automatically adds `Authorization: Bearer {token}` to all requests
|
|
267
|
+
3. Tokens are automatically refreshed when they expire
|
|
268
|
+
4. On logout, all tokens are cleared
|
|
269
|
+
|
|
270
|
+
**You don't need to manually manage tokens!** Just use the hooks and the SDK handles everything.
|
|
271
|
+
|
|
272
|
+
## Example Application
|
|
273
|
+
|
|
274
|
+
A complete example React Native app demonstrating all SDK features:
|
|
275
|
+
|
|
276
|
+
👉 [Passgage SDK Example App](https://github.com/passgage/passgage-sdk-example-react-native)
|
|
277
|
+
|
|
278
|
+
## TypeScript Support
|
|
279
|
+
|
|
280
|
+
The SDK is written in TypeScript and includes full type definitions for all APIs, hooks, and models.
|
|
281
|
+
|
|
154
282
|
## License
|
|
155
283
|
|
|
156
284
|
Proprietary - Passgage © 2025
|
|
285
|
+
|
|
286
|
+
## Support
|
|
287
|
+
|
|
288
|
+
For support, contact devops@passgage.com
|
package/dist/index.d.mts
CHANGED
|
@@ -1264,6 +1264,6 @@ declare function useLocation(options?: UseLocationOptions): UseLocationReturn;
|
|
|
1264
1264
|
* Complete SDK with core functionality and React Native integration
|
|
1265
1265
|
*/
|
|
1266
1266
|
|
|
1267
|
-
declare const SDK_VERSION = "1.0.
|
|
1267
|
+
declare const SDK_VERSION = "1.0.4";
|
|
1268
1268
|
|
|
1269
1269
|
export { type APIError, ApiClient, type ApiClientConfig, AuthService, type AuthState, type AuthTokens, type BaseResponse, type Branch, type CheckInEntryParams, type CheckInExitParams, type CheckInOptions, type CheckInResult, CheckInService, type CompanyInfo, type Coordinates, type CreateEntranceFromQRRequest, type CreateEntranceRequest, type Device, type DeviceAccessRequest, DeviceAccessService, DeviceDirection, DeviceUsage, endpoints as Endpoints, type Entrance, type EntranceQueryParams, EntranceType, type GetNearbyBranchesParams, LocationService, type LocationVerificationLog, type LoginCredentials, type LoginRequest, type LoginResponse, type LoginResult, NFCAccessService, type NFCValidationOptions, type NFCValidationResult, type NearbyBranchesRequest, type PaginationMeta, type PassgageAccessConfig, type PassgageAccessContextValue, PassgageAccessProvider, type PassgageAccessProviderProps, QRAccessService, type QRValidationOptions, type QRValidationResult, type QrAccessResponse, type QrDevice, type RefreshTokenRequest, type RefreshTokenResponse, type RefreshTokenResult, type RemoteWorkEntryOptions, type RemoteWorkEntryParams, type RemoteWorkExitParams, type RemoteWorkResult, RemoteWorkService, type RequestOptions, SDK_VERSION, type TokenInfo, type TokenStorage, type UseLocationOptions, type UseLocationReturn, type UsePassgageAuthOptions, type UsePassgageAuthReturn, type UsePassgageCheckInOptions, type UsePassgageCheckInReturn, type UsePassgageNFCScannerOptions, type UsePassgageNFCScannerReturn, type UsePassgageQRScannerOptions, type UsePassgageQRScannerReturn, type UsePassgageRemoteWorkReturn, type User, calculateDistance, checkOnLocation, checkRepetitiveRead, clearReadRecords, createApiClient, formatDate, formatDateTime, formatISO, formatTime, parseISO, useLocation, usePassgageAccess, usePassgageAuth, usePassgageCheckIn, usePassgageNFCScanner, usePassgageQRScanner, usePassgageRemoteWork, validateCoordinates, validateDeviceId, validateNFCCode, validateQRCode };
|
package/dist/index.d.ts
CHANGED
|
@@ -1264,6 +1264,6 @@ declare function useLocation(options?: UseLocationOptions): UseLocationReturn;
|
|
|
1264
1264
|
* Complete SDK with core functionality and React Native integration
|
|
1265
1265
|
*/
|
|
1266
1266
|
|
|
1267
|
-
declare const SDK_VERSION = "1.0.
|
|
1267
|
+
declare const SDK_VERSION = "1.0.4";
|
|
1268
1268
|
|
|
1269
1269
|
export { type APIError, ApiClient, type ApiClientConfig, AuthService, type AuthState, type AuthTokens, type BaseResponse, type Branch, type CheckInEntryParams, type CheckInExitParams, type CheckInOptions, type CheckInResult, CheckInService, type CompanyInfo, type Coordinates, type CreateEntranceFromQRRequest, type CreateEntranceRequest, type Device, type DeviceAccessRequest, DeviceAccessService, DeviceDirection, DeviceUsage, endpoints as Endpoints, type Entrance, type EntranceQueryParams, EntranceType, type GetNearbyBranchesParams, LocationService, type LocationVerificationLog, type LoginCredentials, type LoginRequest, type LoginResponse, type LoginResult, NFCAccessService, type NFCValidationOptions, type NFCValidationResult, type NearbyBranchesRequest, type PaginationMeta, type PassgageAccessConfig, type PassgageAccessContextValue, PassgageAccessProvider, type PassgageAccessProviderProps, QRAccessService, type QRValidationOptions, type QRValidationResult, type QrAccessResponse, type QrDevice, type RefreshTokenRequest, type RefreshTokenResponse, type RefreshTokenResult, type RemoteWorkEntryOptions, type RemoteWorkEntryParams, type RemoteWorkExitParams, type RemoteWorkResult, RemoteWorkService, type RequestOptions, SDK_VERSION, type TokenInfo, type TokenStorage, type UseLocationOptions, type UseLocationReturn, type UsePassgageAuthOptions, type UsePassgageAuthReturn, type UsePassgageCheckInOptions, type UsePassgageCheckInReturn, type UsePassgageNFCScannerOptions, type UsePassgageNFCScannerReturn, type UsePassgageQRScannerOptions, type UsePassgageQRScannerReturn, type UsePassgageRemoteWorkReturn, type User, calculateDistance, checkOnLocation, checkRepetitiveRead, clearReadRecords, createApiClient, formatDate, formatDateTime, formatISO, formatTime, parseISO, useLocation, usePassgageAccess, usePassgageAuth, usePassgageCheckIn, usePassgageNFCScanner, usePassgageQRScanner, usePassgageRemoteWork, validateCoordinates, validateDeviceId, validateNFCCode, validateQRCode };
|
package/dist/index.js
CHANGED
|
@@ -1965,7 +1965,7 @@ function usePassgageRemoteWork() {
|
|
|
1965
1965
|
}
|
|
1966
1966
|
|
|
1967
1967
|
// src/index.ts
|
|
1968
|
-
var SDK_VERSION = "1.0.
|
|
1968
|
+
var SDK_VERSION = "1.0.4";
|
|
1969
1969
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1970
1970
|
0 && (module.exports = {
|
|
1971
1971
|
ApiClient,
|
package/dist/index.mjs
CHANGED