@passgage/sdk-react-native 1.0.2 → 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 +58 -28
- package/dist/index.d.ts +58 -28
- package/dist/index.js +163 -78
- package/dist/index.mjs +160 -75
- 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
|
@@ -1133,82 +1133,112 @@ interface UsePassgageAuthReturn {
|
|
|
1133
1133
|
declare function usePassgageAuth(options?: UsePassgageAuthOptions): UsePassgageAuthReturn;
|
|
1134
1134
|
|
|
1135
1135
|
/**
|
|
1136
|
-
*
|
|
1136
|
+
* usePassgageQRScanner hook
|
|
1137
1137
|
* QR code scanning with validation
|
|
1138
1138
|
*/
|
|
1139
1139
|
|
|
1140
|
-
interface
|
|
1140
|
+
interface UsePassgageQRScannerOptions {
|
|
1141
1141
|
onSuccess?: (entrance?: Entrance) => void;
|
|
1142
1142
|
onError?: (error: Error) => void;
|
|
1143
1143
|
skipLocationCheck?: boolean;
|
|
1144
1144
|
skipRepetitiveCheck?: boolean;
|
|
1145
1145
|
}
|
|
1146
|
-
interface
|
|
1146
|
+
interface UsePassgageQRScannerReturn {
|
|
1147
1147
|
scan: (qrCode: string, device?: QrDevice) => Promise<void>;
|
|
1148
1148
|
isLoading: boolean;
|
|
1149
1149
|
error: Error | null;
|
|
1150
1150
|
}
|
|
1151
|
-
declare function
|
|
1151
|
+
declare function usePassgageQRScanner(options?: UsePassgageQRScannerOptions): UsePassgageQRScannerReturn;
|
|
1152
1152
|
|
|
1153
1153
|
/**
|
|
1154
|
-
*
|
|
1154
|
+
* usePassgageNFCScanner hook
|
|
1155
1155
|
* NFC card scanning with validation
|
|
1156
1156
|
*/
|
|
1157
1157
|
|
|
1158
|
-
interface
|
|
1158
|
+
interface UsePassgageNFCScannerOptions {
|
|
1159
1159
|
onSuccess?: (entrance?: Entrance) => void;
|
|
1160
1160
|
onError?: (error: Error) => void;
|
|
1161
1161
|
skipLocationCheck?: boolean;
|
|
1162
1162
|
skipRepetitiveCheck?: boolean;
|
|
1163
1163
|
autoStart?: boolean;
|
|
1164
1164
|
}
|
|
1165
|
-
interface
|
|
1165
|
+
interface UsePassgageNFCScannerReturn {
|
|
1166
1166
|
startScanning: () => Promise<void>;
|
|
1167
1167
|
stopScanning: () => Promise<void>;
|
|
1168
1168
|
isScanning: boolean;
|
|
1169
1169
|
error: Error | null;
|
|
1170
1170
|
}
|
|
1171
|
-
declare function
|
|
1171
|
+
declare function usePassgageNFCScanner(options?: UsePassgageNFCScannerOptions): UsePassgageNFCScannerReturn;
|
|
1172
1172
|
|
|
1173
1173
|
/**
|
|
1174
|
-
*
|
|
1174
|
+
* usePassgageCheckIn hook
|
|
1175
1175
|
* GPS-based check-in to nearby branches
|
|
1176
1176
|
*/
|
|
1177
1177
|
|
|
1178
|
-
interface
|
|
1178
|
+
interface UsePassgageCheckInOptions {
|
|
1179
1179
|
radius?: number;
|
|
1180
|
-
autoFetch?: boolean;
|
|
1181
1180
|
}
|
|
1182
|
-
interface
|
|
1181
|
+
interface CheckInEntryParams {
|
|
1183
1182
|
branchId: string;
|
|
1184
|
-
|
|
1183
|
+
userId: string;
|
|
1184
|
+
}
|
|
1185
|
+
interface CheckInExitParams {
|
|
1186
|
+
branchId: string;
|
|
1187
|
+
userId: string;
|
|
1185
1188
|
}
|
|
1186
|
-
interface
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1189
|
+
interface GetNearbyBranchesParams {
|
|
1190
|
+
radius?: number;
|
|
1191
|
+
}
|
|
1192
|
+
interface UsePassgageCheckInReturn {
|
|
1193
|
+
getNearbyBranches: (params?: GetNearbyBranchesParams) => Promise<{
|
|
1194
|
+
success: boolean;
|
|
1195
|
+
data?: Branch[];
|
|
1196
|
+
error?: string;
|
|
1197
|
+
}>;
|
|
1198
|
+
checkInEntry: (params: CheckInEntryParams) => Promise<{
|
|
1199
|
+
success: boolean;
|
|
1200
|
+
data?: any;
|
|
1201
|
+
error?: string;
|
|
1202
|
+
}>;
|
|
1203
|
+
checkInExit: (params: CheckInExitParams) => Promise<{
|
|
1204
|
+
success: boolean;
|
|
1205
|
+
data?: any;
|
|
1206
|
+
error?: string;
|
|
1207
|
+
}>;
|
|
1190
1208
|
isLoading: boolean;
|
|
1191
1209
|
error: Error | null;
|
|
1192
1210
|
}
|
|
1193
|
-
declare function
|
|
1211
|
+
declare function usePassgageCheckIn(options?: UsePassgageCheckInOptions): UsePassgageCheckInReturn;
|
|
1194
1212
|
|
|
1195
1213
|
/**
|
|
1196
|
-
*
|
|
1214
|
+
* usePassgageRemoteWork hook
|
|
1197
1215
|
* Remote work entry/exit logging
|
|
1198
1216
|
*/
|
|
1199
|
-
|
|
1200
|
-
|
|
1217
|
+
interface RemoteWorkEntryParams {
|
|
1218
|
+
userId: string;
|
|
1219
|
+
description?: string;
|
|
1201
1220
|
timestamp?: Date | string;
|
|
1221
|
+
}
|
|
1222
|
+
interface RemoteWorkExitParams {
|
|
1223
|
+
userId: string;
|
|
1202
1224
|
description?: string;
|
|
1225
|
+
timestamp?: Date | string;
|
|
1203
1226
|
}
|
|
1204
|
-
interface
|
|
1205
|
-
logEntry: (
|
|
1206
|
-
|
|
1207
|
-
|
|
1227
|
+
interface UsePassgageRemoteWorkReturn {
|
|
1228
|
+
logEntry: (params: RemoteWorkEntryParams) => Promise<{
|
|
1229
|
+
success: boolean;
|
|
1230
|
+
data?: any;
|
|
1231
|
+
error?: string;
|
|
1232
|
+
}>;
|
|
1233
|
+
logExit: (params: RemoteWorkExitParams) => Promise<{
|
|
1234
|
+
success: boolean;
|
|
1235
|
+
data?: any;
|
|
1236
|
+
error?: string;
|
|
1237
|
+
}>;
|
|
1208
1238
|
isLoading: boolean;
|
|
1209
1239
|
error: Error | null;
|
|
1210
1240
|
}
|
|
1211
|
-
declare function
|
|
1241
|
+
declare function usePassgageRemoteWork(): UsePassgageRemoteWorkReturn;
|
|
1212
1242
|
|
|
1213
1243
|
/**
|
|
1214
1244
|
* useLocation hook
|
|
@@ -1234,6 +1264,6 @@ declare function useLocation(options?: UseLocationOptions): UseLocationReturn;
|
|
|
1234
1264
|
* Complete SDK with core functionality and React Native integration
|
|
1235
1265
|
*/
|
|
1236
1266
|
|
|
1237
|
-
declare const SDK_VERSION = "1.0.
|
|
1267
|
+
declare const SDK_VERSION = "1.0.4";
|
|
1238
1268
|
|
|
1239
|
-
export { type APIError, ApiClient, type ApiClientConfig, AuthService, type AuthState, type AuthTokens, type BaseResponse, type Branch, type
|
|
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
|
@@ -1133,82 +1133,112 @@ interface UsePassgageAuthReturn {
|
|
|
1133
1133
|
declare function usePassgageAuth(options?: UsePassgageAuthOptions): UsePassgageAuthReturn;
|
|
1134
1134
|
|
|
1135
1135
|
/**
|
|
1136
|
-
*
|
|
1136
|
+
* usePassgageQRScanner hook
|
|
1137
1137
|
* QR code scanning with validation
|
|
1138
1138
|
*/
|
|
1139
1139
|
|
|
1140
|
-
interface
|
|
1140
|
+
interface UsePassgageQRScannerOptions {
|
|
1141
1141
|
onSuccess?: (entrance?: Entrance) => void;
|
|
1142
1142
|
onError?: (error: Error) => void;
|
|
1143
1143
|
skipLocationCheck?: boolean;
|
|
1144
1144
|
skipRepetitiveCheck?: boolean;
|
|
1145
1145
|
}
|
|
1146
|
-
interface
|
|
1146
|
+
interface UsePassgageQRScannerReturn {
|
|
1147
1147
|
scan: (qrCode: string, device?: QrDevice) => Promise<void>;
|
|
1148
1148
|
isLoading: boolean;
|
|
1149
1149
|
error: Error | null;
|
|
1150
1150
|
}
|
|
1151
|
-
declare function
|
|
1151
|
+
declare function usePassgageQRScanner(options?: UsePassgageQRScannerOptions): UsePassgageQRScannerReturn;
|
|
1152
1152
|
|
|
1153
1153
|
/**
|
|
1154
|
-
*
|
|
1154
|
+
* usePassgageNFCScanner hook
|
|
1155
1155
|
* NFC card scanning with validation
|
|
1156
1156
|
*/
|
|
1157
1157
|
|
|
1158
|
-
interface
|
|
1158
|
+
interface UsePassgageNFCScannerOptions {
|
|
1159
1159
|
onSuccess?: (entrance?: Entrance) => void;
|
|
1160
1160
|
onError?: (error: Error) => void;
|
|
1161
1161
|
skipLocationCheck?: boolean;
|
|
1162
1162
|
skipRepetitiveCheck?: boolean;
|
|
1163
1163
|
autoStart?: boolean;
|
|
1164
1164
|
}
|
|
1165
|
-
interface
|
|
1165
|
+
interface UsePassgageNFCScannerReturn {
|
|
1166
1166
|
startScanning: () => Promise<void>;
|
|
1167
1167
|
stopScanning: () => Promise<void>;
|
|
1168
1168
|
isScanning: boolean;
|
|
1169
1169
|
error: Error | null;
|
|
1170
1170
|
}
|
|
1171
|
-
declare function
|
|
1171
|
+
declare function usePassgageNFCScanner(options?: UsePassgageNFCScannerOptions): UsePassgageNFCScannerReturn;
|
|
1172
1172
|
|
|
1173
1173
|
/**
|
|
1174
|
-
*
|
|
1174
|
+
* usePassgageCheckIn hook
|
|
1175
1175
|
* GPS-based check-in to nearby branches
|
|
1176
1176
|
*/
|
|
1177
1177
|
|
|
1178
|
-
interface
|
|
1178
|
+
interface UsePassgageCheckInOptions {
|
|
1179
1179
|
radius?: number;
|
|
1180
|
-
autoFetch?: boolean;
|
|
1181
1180
|
}
|
|
1182
|
-
interface
|
|
1181
|
+
interface CheckInEntryParams {
|
|
1183
1182
|
branchId: string;
|
|
1184
|
-
|
|
1183
|
+
userId: string;
|
|
1184
|
+
}
|
|
1185
|
+
interface CheckInExitParams {
|
|
1186
|
+
branchId: string;
|
|
1187
|
+
userId: string;
|
|
1185
1188
|
}
|
|
1186
|
-
interface
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1189
|
+
interface GetNearbyBranchesParams {
|
|
1190
|
+
radius?: number;
|
|
1191
|
+
}
|
|
1192
|
+
interface UsePassgageCheckInReturn {
|
|
1193
|
+
getNearbyBranches: (params?: GetNearbyBranchesParams) => Promise<{
|
|
1194
|
+
success: boolean;
|
|
1195
|
+
data?: Branch[];
|
|
1196
|
+
error?: string;
|
|
1197
|
+
}>;
|
|
1198
|
+
checkInEntry: (params: CheckInEntryParams) => Promise<{
|
|
1199
|
+
success: boolean;
|
|
1200
|
+
data?: any;
|
|
1201
|
+
error?: string;
|
|
1202
|
+
}>;
|
|
1203
|
+
checkInExit: (params: CheckInExitParams) => Promise<{
|
|
1204
|
+
success: boolean;
|
|
1205
|
+
data?: any;
|
|
1206
|
+
error?: string;
|
|
1207
|
+
}>;
|
|
1190
1208
|
isLoading: boolean;
|
|
1191
1209
|
error: Error | null;
|
|
1192
1210
|
}
|
|
1193
|
-
declare function
|
|
1211
|
+
declare function usePassgageCheckIn(options?: UsePassgageCheckInOptions): UsePassgageCheckInReturn;
|
|
1194
1212
|
|
|
1195
1213
|
/**
|
|
1196
|
-
*
|
|
1214
|
+
* usePassgageRemoteWork hook
|
|
1197
1215
|
* Remote work entry/exit logging
|
|
1198
1216
|
*/
|
|
1199
|
-
|
|
1200
|
-
|
|
1217
|
+
interface RemoteWorkEntryParams {
|
|
1218
|
+
userId: string;
|
|
1219
|
+
description?: string;
|
|
1201
1220
|
timestamp?: Date | string;
|
|
1221
|
+
}
|
|
1222
|
+
interface RemoteWorkExitParams {
|
|
1223
|
+
userId: string;
|
|
1202
1224
|
description?: string;
|
|
1225
|
+
timestamp?: Date | string;
|
|
1203
1226
|
}
|
|
1204
|
-
interface
|
|
1205
|
-
logEntry: (
|
|
1206
|
-
|
|
1207
|
-
|
|
1227
|
+
interface UsePassgageRemoteWorkReturn {
|
|
1228
|
+
logEntry: (params: RemoteWorkEntryParams) => Promise<{
|
|
1229
|
+
success: boolean;
|
|
1230
|
+
data?: any;
|
|
1231
|
+
error?: string;
|
|
1232
|
+
}>;
|
|
1233
|
+
logExit: (params: RemoteWorkExitParams) => Promise<{
|
|
1234
|
+
success: boolean;
|
|
1235
|
+
data?: any;
|
|
1236
|
+
error?: string;
|
|
1237
|
+
}>;
|
|
1208
1238
|
isLoading: boolean;
|
|
1209
1239
|
error: Error | null;
|
|
1210
1240
|
}
|
|
1211
|
-
declare function
|
|
1241
|
+
declare function usePassgageRemoteWork(): UsePassgageRemoteWorkReturn;
|
|
1212
1242
|
|
|
1213
1243
|
/**
|
|
1214
1244
|
* useLocation hook
|
|
@@ -1234,6 +1264,6 @@ declare function useLocation(options?: UseLocationOptions): UseLocationReturn;
|
|
|
1234
1264
|
* Complete SDK with core functionality and React Native integration
|
|
1235
1265
|
*/
|
|
1236
1266
|
|
|
1237
|
-
declare const SDK_VERSION = "1.0.
|
|
1267
|
+
declare const SDK_VERSION = "1.0.4";
|
|
1238
1268
|
|
|
1239
|
-
export { type APIError, ApiClient, type ApiClientConfig, AuthService, type AuthState, type AuthTokens, type BaseResponse, type Branch, type
|
|
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
|
@@ -54,13 +54,13 @@ __export(index_exports, {
|
|
|
54
54
|
formatISO: () => formatISO,
|
|
55
55
|
formatTime: () => formatTime,
|
|
56
56
|
parseISO: () => parseISO,
|
|
57
|
-
useCheckIn: () => useCheckIn,
|
|
58
57
|
useLocation: () => useLocation,
|
|
59
|
-
useNFCScanner: () => useNFCScanner,
|
|
60
58
|
usePassgageAccess: () => usePassgageAccess,
|
|
61
59
|
usePassgageAuth: () => usePassgageAuth,
|
|
62
|
-
|
|
63
|
-
|
|
60
|
+
usePassgageCheckIn: () => usePassgageCheckIn,
|
|
61
|
+
usePassgageNFCScanner: () => usePassgageNFCScanner,
|
|
62
|
+
usePassgageQRScanner: () => usePassgageQRScanner,
|
|
63
|
+
usePassgageRemoteWork: () => usePassgageRemoteWork,
|
|
64
64
|
validateCoordinates: () => validateCoordinates,
|
|
65
65
|
validateDeviceId: () => validateDeviceId,
|
|
66
66
|
validateNFCCode: () => validateNFCCode,
|
|
@@ -1554,7 +1554,7 @@ function usePassgageAuth(options = {}) {
|
|
|
1554
1554
|
};
|
|
1555
1555
|
}
|
|
1556
1556
|
|
|
1557
|
-
// src/hooks/
|
|
1557
|
+
// src/hooks/usePassgageQRScanner.ts
|
|
1558
1558
|
var import_react4 = require("react");
|
|
1559
1559
|
|
|
1560
1560
|
// src/hooks/useLocation.ts
|
|
@@ -1630,8 +1630,8 @@ function useLocation(options = {}) {
|
|
|
1630
1630
|
};
|
|
1631
1631
|
}
|
|
1632
1632
|
|
|
1633
|
-
// src/hooks/
|
|
1634
|
-
function
|
|
1633
|
+
// src/hooks/usePassgageQRScanner.ts
|
|
1634
|
+
function usePassgageQRScanner(options = {}) {
|
|
1635
1635
|
const { qrAccessService, deviceAccessService } = usePassgageAccess();
|
|
1636
1636
|
const { location } = useLocation();
|
|
1637
1637
|
const [isLoading, setIsLoading] = (0, import_react4.useState)(false);
|
|
@@ -1676,14 +1676,14 @@ function useQRScanner(options = {}) {
|
|
|
1676
1676
|
};
|
|
1677
1677
|
}
|
|
1678
1678
|
|
|
1679
|
-
// src/hooks/
|
|
1679
|
+
// src/hooks/usePassgageNFCScanner.ts
|
|
1680
1680
|
var import_react5 = require("react");
|
|
1681
1681
|
var import_react_native_nfc_manager = __toESM(require("react-native-nfc-manager"));
|
|
1682
1682
|
function reversedHexToDec(hexString) {
|
|
1683
1683
|
const hex = hexString.replace(/:/g, "");
|
|
1684
1684
|
return parseInt(hex, 16).toString();
|
|
1685
1685
|
}
|
|
1686
|
-
function
|
|
1686
|
+
function usePassgageNFCScanner(options = {}) {
|
|
1687
1687
|
const { nfcAccessService, deviceAccessService } = usePassgageAccess();
|
|
1688
1688
|
const { location } = useLocation();
|
|
1689
1689
|
const [isScanning, setIsScanning] = (0, import_react5.useState)(false);
|
|
@@ -1759,128 +1759,213 @@ function useNFCScanner(options = {}) {
|
|
|
1759
1759
|
};
|
|
1760
1760
|
}
|
|
1761
1761
|
|
|
1762
|
-
// src/hooks/
|
|
1762
|
+
// src/hooks/usePassgageCheckIn.ts
|
|
1763
1763
|
var import_react6 = require("react");
|
|
1764
|
-
function
|
|
1765
|
-
const { checkInService
|
|
1764
|
+
function usePassgageCheckIn(options = {}) {
|
|
1765
|
+
const { checkInService } = usePassgageAccess();
|
|
1766
1766
|
const { location } = useLocation();
|
|
1767
|
-
const [nearbyBranches, setNearbyBranches] = (0, import_react6.useState)([]);
|
|
1768
1767
|
const [isLoading, setIsLoading] = (0, import_react6.useState)(false);
|
|
1769
1768
|
const [error, setError] = (0, import_react6.useState)(null);
|
|
1770
|
-
const
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
const response = await checkInService.getNearbyBranches({
|
|
1778
|
-
latitude: location.latitude,
|
|
1779
|
-
longitude: location.longitude,
|
|
1780
|
-
radius: options.radius
|
|
1781
|
-
});
|
|
1782
|
-
if (response.success && response.data) {
|
|
1783
|
-
setNearbyBranches(response.data);
|
|
1769
|
+
const getNearbyBranches = (0, import_react6.useCallback)(
|
|
1770
|
+
async (params) => {
|
|
1771
|
+
if (!location) {
|
|
1772
|
+
return {
|
|
1773
|
+
success: false,
|
|
1774
|
+
error: "Location not available"
|
|
1775
|
+
};
|
|
1784
1776
|
}
|
|
1785
|
-
|
|
1786
|
-
setError(
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
1777
|
+
setIsLoading(true);
|
|
1778
|
+
setError(null);
|
|
1779
|
+
try {
|
|
1780
|
+
const response = await checkInService.getNearbyBranches({
|
|
1781
|
+
latitude: location.latitude,
|
|
1782
|
+
longitude: location.longitude,
|
|
1783
|
+
radius: params?.radius || options.radius
|
|
1784
|
+
});
|
|
1785
|
+
if (response.success && response.data) {
|
|
1786
|
+
return {
|
|
1787
|
+
success: true,
|
|
1788
|
+
data: response.data
|
|
1789
|
+
};
|
|
1790
|
+
}
|
|
1791
|
+
return {
|
|
1792
|
+
success: false,
|
|
1793
|
+
error: response.message || "Failed to fetch nearby branches"
|
|
1794
|
+
};
|
|
1795
|
+
} catch (err) {
|
|
1796
|
+
const error2 = err;
|
|
1797
|
+
setError(error2);
|
|
1798
|
+
return {
|
|
1799
|
+
success: false,
|
|
1800
|
+
error: error2.message || "Failed to fetch nearby branches"
|
|
1801
|
+
};
|
|
1802
|
+
} finally {
|
|
1803
|
+
setIsLoading(false);
|
|
1804
|
+
}
|
|
1805
|
+
},
|
|
1806
|
+
[checkInService, location, options.radius]
|
|
1807
|
+
);
|
|
1808
|
+
const checkInEntry = (0, import_react6.useCallback)(
|
|
1792
1809
|
async (params) => {
|
|
1793
1810
|
setIsLoading(true);
|
|
1794
1811
|
setError(null);
|
|
1795
1812
|
try {
|
|
1796
|
-
const userId = "";
|
|
1797
1813
|
const result = await checkInService.checkIn({
|
|
1798
|
-
|
|
1799
|
-
userId,
|
|
1814
|
+
branchId: params.branchId,
|
|
1815
|
+
userId: params.userId,
|
|
1816
|
+
entranceType: 0 /* ENTRY */,
|
|
1800
1817
|
userLocation: location || void 0
|
|
1801
1818
|
});
|
|
1802
|
-
if (
|
|
1803
|
-
|
|
1819
|
+
if (result.success) {
|
|
1820
|
+
return {
|
|
1821
|
+
success: true,
|
|
1822
|
+
data: result.entrance
|
|
1823
|
+
};
|
|
1804
1824
|
}
|
|
1805
|
-
return
|
|
1825
|
+
return {
|
|
1826
|
+
success: false,
|
|
1827
|
+
error: result.message || "Check-in failed"
|
|
1828
|
+
};
|
|
1806
1829
|
} catch (err) {
|
|
1807
|
-
|
|
1808
|
-
|
|
1830
|
+
const error2 = err;
|
|
1831
|
+
setError(error2);
|
|
1832
|
+
return {
|
|
1833
|
+
success: false,
|
|
1834
|
+
error: error2.message || "Check-in failed"
|
|
1835
|
+
};
|
|
1836
|
+
} finally {
|
|
1837
|
+
setIsLoading(false);
|
|
1838
|
+
}
|
|
1839
|
+
},
|
|
1840
|
+
[checkInService, location]
|
|
1841
|
+
);
|
|
1842
|
+
const checkInExit = (0, import_react6.useCallback)(
|
|
1843
|
+
async (params) => {
|
|
1844
|
+
setIsLoading(true);
|
|
1845
|
+
setError(null);
|
|
1846
|
+
try {
|
|
1847
|
+
const result = await checkInService.checkIn({
|
|
1848
|
+
branchId: params.branchId,
|
|
1849
|
+
userId: params.userId,
|
|
1850
|
+
entranceType: 1 /* EXIT */,
|
|
1851
|
+
userLocation: location || void 0
|
|
1852
|
+
});
|
|
1853
|
+
if (result.success) {
|
|
1854
|
+
return {
|
|
1855
|
+
success: true,
|
|
1856
|
+
data: result.entrance
|
|
1857
|
+
};
|
|
1858
|
+
}
|
|
1859
|
+
return {
|
|
1860
|
+
success: false,
|
|
1861
|
+
error: result.message || "Check-out failed"
|
|
1862
|
+
};
|
|
1863
|
+
} catch (err) {
|
|
1864
|
+
const error2 = err;
|
|
1865
|
+
setError(error2);
|
|
1866
|
+
return {
|
|
1867
|
+
success: false,
|
|
1868
|
+
error: error2.message || "Check-out failed"
|
|
1869
|
+
};
|
|
1809
1870
|
} finally {
|
|
1810
1871
|
setIsLoading(false);
|
|
1811
1872
|
}
|
|
1812
1873
|
},
|
|
1813
1874
|
[checkInService, location]
|
|
1814
1875
|
);
|
|
1815
|
-
(0, import_react6.useEffect)(() => {
|
|
1816
|
-
if (options.autoFetch && location) {
|
|
1817
|
-
fetchNearbyBranches();
|
|
1818
|
-
}
|
|
1819
|
-
}, [options.autoFetch, location, fetchNearbyBranches]);
|
|
1820
1876
|
return {
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
|
|
1877
|
+
getNearbyBranches,
|
|
1878
|
+
checkInEntry,
|
|
1879
|
+
checkInExit,
|
|
1824
1880
|
isLoading,
|
|
1825
1881
|
error
|
|
1826
1882
|
};
|
|
1827
1883
|
}
|
|
1828
1884
|
|
|
1829
|
-
// src/hooks/
|
|
1885
|
+
// src/hooks/usePassgageRemoteWork.ts
|
|
1830
1886
|
var import_react7 = require("react");
|
|
1831
|
-
function
|
|
1887
|
+
function usePassgageRemoteWork() {
|
|
1832
1888
|
const { remoteWorkService } = usePassgageAccess();
|
|
1833
1889
|
const [isLoading, setIsLoading] = (0, import_react7.useState)(false);
|
|
1834
1890
|
const [error, setError] = (0, import_react7.useState)(null);
|
|
1835
|
-
const
|
|
1836
|
-
async (
|
|
1891
|
+
const logEntry = (0, import_react7.useCallback)(
|
|
1892
|
+
async (params) => {
|
|
1837
1893
|
setIsLoading(true);
|
|
1838
1894
|
setError(null);
|
|
1839
1895
|
try {
|
|
1840
|
-
const userId = "";
|
|
1841
1896
|
const result = await remoteWorkService.logRemoteWork({
|
|
1842
|
-
userId,
|
|
1843
|
-
entranceType
|
|
1844
|
-
timestamp:
|
|
1845
|
-
description:
|
|
1897
|
+
userId: params.userId,
|
|
1898
|
+
entranceType: 0 /* ENTRY */,
|
|
1899
|
+
timestamp: params.timestamp,
|
|
1900
|
+
description: params.description
|
|
1846
1901
|
});
|
|
1847
|
-
if (
|
|
1848
|
-
|
|
1902
|
+
if (result.success) {
|
|
1903
|
+
return {
|
|
1904
|
+
success: true,
|
|
1905
|
+
data: result.entrance
|
|
1906
|
+
};
|
|
1849
1907
|
}
|
|
1850
|
-
return
|
|
1908
|
+
return {
|
|
1909
|
+
success: false,
|
|
1910
|
+
error: result.message || "Failed to log entry"
|
|
1911
|
+
};
|
|
1851
1912
|
} catch (err) {
|
|
1852
1913
|
const error2 = err;
|
|
1853
1914
|
setError(error2);
|
|
1854
|
-
|
|
1915
|
+
return {
|
|
1916
|
+
success: false,
|
|
1917
|
+
error: error2.message || "Failed to log entry"
|
|
1918
|
+
};
|
|
1855
1919
|
} finally {
|
|
1856
1920
|
setIsLoading(false);
|
|
1857
1921
|
}
|
|
1858
1922
|
},
|
|
1859
1923
|
[remoteWorkService]
|
|
1860
1924
|
);
|
|
1861
|
-
const logEntry = (0, import_react7.useCallback)(
|
|
1862
|
-
async (options) => {
|
|
1863
|
-
return logRemoteWork(0 /* ENTRY */, options);
|
|
1864
|
-
},
|
|
1865
|
-
[logRemoteWork]
|
|
1866
|
-
);
|
|
1867
1925
|
const logExit = (0, import_react7.useCallback)(
|
|
1868
|
-
async (
|
|
1869
|
-
|
|
1926
|
+
async (params) => {
|
|
1927
|
+
setIsLoading(true);
|
|
1928
|
+
setError(null);
|
|
1929
|
+
try {
|
|
1930
|
+
const result = await remoteWorkService.logRemoteWork({
|
|
1931
|
+
userId: params.userId,
|
|
1932
|
+
entranceType: 1 /* EXIT */,
|
|
1933
|
+
timestamp: params.timestamp,
|
|
1934
|
+
description: params.description
|
|
1935
|
+
});
|
|
1936
|
+
if (result.success) {
|
|
1937
|
+
return {
|
|
1938
|
+
success: true,
|
|
1939
|
+
data: result.entrance
|
|
1940
|
+
};
|
|
1941
|
+
}
|
|
1942
|
+
return {
|
|
1943
|
+
success: false,
|
|
1944
|
+
error: result.message || "Failed to log exit"
|
|
1945
|
+
};
|
|
1946
|
+
} catch (err) {
|
|
1947
|
+
const error2 = err;
|
|
1948
|
+
setError(error2);
|
|
1949
|
+
return {
|
|
1950
|
+
success: false,
|
|
1951
|
+
error: error2.message || "Failed to log exit"
|
|
1952
|
+
};
|
|
1953
|
+
} finally {
|
|
1954
|
+
setIsLoading(false);
|
|
1955
|
+
}
|
|
1870
1956
|
},
|
|
1871
|
-
[
|
|
1957
|
+
[remoteWorkService]
|
|
1872
1958
|
);
|
|
1873
1959
|
return {
|
|
1874
1960
|
logEntry,
|
|
1875
1961
|
logExit,
|
|
1876
|
-
logRemoteWork,
|
|
1877
1962
|
isLoading,
|
|
1878
1963
|
error
|
|
1879
1964
|
};
|
|
1880
1965
|
}
|
|
1881
1966
|
|
|
1882
1967
|
// src/index.ts
|
|
1883
|
-
var SDK_VERSION = "1.0.
|
|
1968
|
+
var SDK_VERSION = "1.0.4";
|
|
1884
1969
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1885
1970
|
0 && (module.exports = {
|
|
1886
1971
|
ApiClient,
|
|
@@ -1907,13 +1992,13 @@ var SDK_VERSION = "1.0.2";
|
|
|
1907
1992
|
formatISO,
|
|
1908
1993
|
formatTime,
|
|
1909
1994
|
parseISO,
|
|
1910
|
-
useCheckIn,
|
|
1911
1995
|
useLocation,
|
|
1912
|
-
useNFCScanner,
|
|
1913
1996
|
usePassgageAccess,
|
|
1914
1997
|
usePassgageAuth,
|
|
1915
|
-
|
|
1916
|
-
|
|
1998
|
+
usePassgageCheckIn,
|
|
1999
|
+
usePassgageNFCScanner,
|
|
2000
|
+
usePassgageQRScanner,
|
|
2001
|
+
usePassgageRemoteWork,
|
|
1917
2002
|
validateCoordinates,
|
|
1918
2003
|
validateDeviceId,
|
|
1919
2004
|
validateNFCCode,
|
package/dist/index.mjs
CHANGED
|
@@ -1490,7 +1490,7 @@ function usePassgageAuth(options = {}) {
|
|
|
1490
1490
|
};
|
|
1491
1491
|
}
|
|
1492
1492
|
|
|
1493
|
-
// src/hooks/
|
|
1493
|
+
// src/hooks/usePassgageQRScanner.ts
|
|
1494
1494
|
import { useState as useState3, useCallback as useCallback3 } from "react";
|
|
1495
1495
|
|
|
1496
1496
|
// src/hooks/useLocation.ts
|
|
@@ -1566,8 +1566,8 @@ function useLocation(options = {}) {
|
|
|
1566
1566
|
};
|
|
1567
1567
|
}
|
|
1568
1568
|
|
|
1569
|
-
// src/hooks/
|
|
1570
|
-
function
|
|
1569
|
+
// src/hooks/usePassgageQRScanner.ts
|
|
1570
|
+
function usePassgageQRScanner(options = {}) {
|
|
1571
1571
|
const { qrAccessService, deviceAccessService } = usePassgageAccess();
|
|
1572
1572
|
const { location } = useLocation();
|
|
1573
1573
|
const [isLoading, setIsLoading] = useState3(false);
|
|
@@ -1612,14 +1612,14 @@ function useQRScanner(options = {}) {
|
|
|
1612
1612
|
};
|
|
1613
1613
|
}
|
|
1614
1614
|
|
|
1615
|
-
// src/hooks/
|
|
1615
|
+
// src/hooks/usePassgageNFCScanner.ts
|
|
1616
1616
|
import { useState as useState4, useCallback as useCallback4, useEffect as useEffect3 } from "react";
|
|
1617
1617
|
import NfcManager, { NfcTech } from "react-native-nfc-manager";
|
|
1618
1618
|
function reversedHexToDec(hexString) {
|
|
1619
1619
|
const hex = hexString.replace(/:/g, "");
|
|
1620
1620
|
return parseInt(hex, 16).toString();
|
|
1621
1621
|
}
|
|
1622
|
-
function
|
|
1622
|
+
function usePassgageNFCScanner(options = {}) {
|
|
1623
1623
|
const { nfcAccessService, deviceAccessService } = usePassgageAccess();
|
|
1624
1624
|
const { location } = useLocation();
|
|
1625
1625
|
const [isScanning, setIsScanning] = useState4(false);
|
|
@@ -1695,128 +1695,213 @@ function useNFCScanner(options = {}) {
|
|
|
1695
1695
|
};
|
|
1696
1696
|
}
|
|
1697
1697
|
|
|
1698
|
-
// src/hooks/
|
|
1699
|
-
import { useState as useState5,
|
|
1700
|
-
function
|
|
1701
|
-
const { checkInService
|
|
1698
|
+
// src/hooks/usePassgageCheckIn.ts
|
|
1699
|
+
import { useState as useState5, useCallback as useCallback5 } from "react";
|
|
1700
|
+
function usePassgageCheckIn(options = {}) {
|
|
1701
|
+
const { checkInService } = usePassgageAccess();
|
|
1702
1702
|
const { location } = useLocation();
|
|
1703
|
-
const [nearbyBranches, setNearbyBranches] = useState5([]);
|
|
1704
1703
|
const [isLoading, setIsLoading] = useState5(false);
|
|
1705
1704
|
const [error, setError] = useState5(null);
|
|
1706
|
-
const
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
const response = await checkInService.getNearbyBranches({
|
|
1714
|
-
latitude: location.latitude,
|
|
1715
|
-
longitude: location.longitude,
|
|
1716
|
-
radius: options.radius
|
|
1717
|
-
});
|
|
1718
|
-
if (response.success && response.data) {
|
|
1719
|
-
setNearbyBranches(response.data);
|
|
1705
|
+
const getNearbyBranches = useCallback5(
|
|
1706
|
+
async (params) => {
|
|
1707
|
+
if (!location) {
|
|
1708
|
+
return {
|
|
1709
|
+
success: false,
|
|
1710
|
+
error: "Location not available"
|
|
1711
|
+
};
|
|
1720
1712
|
}
|
|
1721
|
-
|
|
1722
|
-
setError(
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1713
|
+
setIsLoading(true);
|
|
1714
|
+
setError(null);
|
|
1715
|
+
try {
|
|
1716
|
+
const response = await checkInService.getNearbyBranches({
|
|
1717
|
+
latitude: location.latitude,
|
|
1718
|
+
longitude: location.longitude,
|
|
1719
|
+
radius: params?.radius || options.radius
|
|
1720
|
+
});
|
|
1721
|
+
if (response.success && response.data) {
|
|
1722
|
+
return {
|
|
1723
|
+
success: true,
|
|
1724
|
+
data: response.data
|
|
1725
|
+
};
|
|
1726
|
+
}
|
|
1727
|
+
return {
|
|
1728
|
+
success: false,
|
|
1729
|
+
error: response.message || "Failed to fetch nearby branches"
|
|
1730
|
+
};
|
|
1731
|
+
} catch (err) {
|
|
1732
|
+
const error2 = err;
|
|
1733
|
+
setError(error2);
|
|
1734
|
+
return {
|
|
1735
|
+
success: false,
|
|
1736
|
+
error: error2.message || "Failed to fetch nearby branches"
|
|
1737
|
+
};
|
|
1738
|
+
} finally {
|
|
1739
|
+
setIsLoading(false);
|
|
1740
|
+
}
|
|
1741
|
+
},
|
|
1742
|
+
[checkInService, location, options.radius]
|
|
1743
|
+
);
|
|
1744
|
+
const checkInEntry = useCallback5(
|
|
1728
1745
|
async (params) => {
|
|
1729
1746
|
setIsLoading(true);
|
|
1730
1747
|
setError(null);
|
|
1731
1748
|
try {
|
|
1732
|
-
const userId = "";
|
|
1733
1749
|
const result = await checkInService.checkIn({
|
|
1734
|
-
|
|
1735
|
-
userId,
|
|
1750
|
+
branchId: params.branchId,
|
|
1751
|
+
userId: params.userId,
|
|
1752
|
+
entranceType: 0 /* ENTRY */,
|
|
1736
1753
|
userLocation: location || void 0
|
|
1737
1754
|
});
|
|
1738
|
-
if (
|
|
1739
|
-
|
|
1755
|
+
if (result.success) {
|
|
1756
|
+
return {
|
|
1757
|
+
success: true,
|
|
1758
|
+
data: result.entrance
|
|
1759
|
+
};
|
|
1740
1760
|
}
|
|
1741
|
-
return
|
|
1761
|
+
return {
|
|
1762
|
+
success: false,
|
|
1763
|
+
error: result.message || "Check-in failed"
|
|
1764
|
+
};
|
|
1742
1765
|
} catch (err) {
|
|
1743
|
-
|
|
1744
|
-
|
|
1766
|
+
const error2 = err;
|
|
1767
|
+
setError(error2);
|
|
1768
|
+
return {
|
|
1769
|
+
success: false,
|
|
1770
|
+
error: error2.message || "Check-in failed"
|
|
1771
|
+
};
|
|
1772
|
+
} finally {
|
|
1773
|
+
setIsLoading(false);
|
|
1774
|
+
}
|
|
1775
|
+
},
|
|
1776
|
+
[checkInService, location]
|
|
1777
|
+
);
|
|
1778
|
+
const checkInExit = useCallback5(
|
|
1779
|
+
async (params) => {
|
|
1780
|
+
setIsLoading(true);
|
|
1781
|
+
setError(null);
|
|
1782
|
+
try {
|
|
1783
|
+
const result = await checkInService.checkIn({
|
|
1784
|
+
branchId: params.branchId,
|
|
1785
|
+
userId: params.userId,
|
|
1786
|
+
entranceType: 1 /* EXIT */,
|
|
1787
|
+
userLocation: location || void 0
|
|
1788
|
+
});
|
|
1789
|
+
if (result.success) {
|
|
1790
|
+
return {
|
|
1791
|
+
success: true,
|
|
1792
|
+
data: result.entrance
|
|
1793
|
+
};
|
|
1794
|
+
}
|
|
1795
|
+
return {
|
|
1796
|
+
success: false,
|
|
1797
|
+
error: result.message || "Check-out failed"
|
|
1798
|
+
};
|
|
1799
|
+
} catch (err) {
|
|
1800
|
+
const error2 = err;
|
|
1801
|
+
setError(error2);
|
|
1802
|
+
return {
|
|
1803
|
+
success: false,
|
|
1804
|
+
error: error2.message || "Check-out failed"
|
|
1805
|
+
};
|
|
1745
1806
|
} finally {
|
|
1746
1807
|
setIsLoading(false);
|
|
1747
1808
|
}
|
|
1748
1809
|
},
|
|
1749
1810
|
[checkInService, location]
|
|
1750
1811
|
);
|
|
1751
|
-
useEffect4(() => {
|
|
1752
|
-
if (options.autoFetch && location) {
|
|
1753
|
-
fetchNearbyBranches();
|
|
1754
|
-
}
|
|
1755
|
-
}, [options.autoFetch, location, fetchNearbyBranches]);
|
|
1756
1812
|
return {
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1813
|
+
getNearbyBranches,
|
|
1814
|
+
checkInEntry,
|
|
1815
|
+
checkInExit,
|
|
1760
1816
|
isLoading,
|
|
1761
1817
|
error
|
|
1762
1818
|
};
|
|
1763
1819
|
}
|
|
1764
1820
|
|
|
1765
|
-
// src/hooks/
|
|
1821
|
+
// src/hooks/usePassgageRemoteWork.ts
|
|
1766
1822
|
import { useState as useState6, useCallback as useCallback6 } from "react";
|
|
1767
|
-
function
|
|
1823
|
+
function usePassgageRemoteWork() {
|
|
1768
1824
|
const { remoteWorkService } = usePassgageAccess();
|
|
1769
1825
|
const [isLoading, setIsLoading] = useState6(false);
|
|
1770
1826
|
const [error, setError] = useState6(null);
|
|
1771
|
-
const
|
|
1772
|
-
async (
|
|
1827
|
+
const logEntry = useCallback6(
|
|
1828
|
+
async (params) => {
|
|
1773
1829
|
setIsLoading(true);
|
|
1774
1830
|
setError(null);
|
|
1775
1831
|
try {
|
|
1776
|
-
const userId = "";
|
|
1777
1832
|
const result = await remoteWorkService.logRemoteWork({
|
|
1778
|
-
userId,
|
|
1779
|
-
entranceType
|
|
1780
|
-
timestamp:
|
|
1781
|
-
description:
|
|
1833
|
+
userId: params.userId,
|
|
1834
|
+
entranceType: 0 /* ENTRY */,
|
|
1835
|
+
timestamp: params.timestamp,
|
|
1836
|
+
description: params.description
|
|
1782
1837
|
});
|
|
1783
|
-
if (
|
|
1784
|
-
|
|
1838
|
+
if (result.success) {
|
|
1839
|
+
return {
|
|
1840
|
+
success: true,
|
|
1841
|
+
data: result.entrance
|
|
1842
|
+
};
|
|
1785
1843
|
}
|
|
1786
|
-
return
|
|
1844
|
+
return {
|
|
1845
|
+
success: false,
|
|
1846
|
+
error: result.message || "Failed to log entry"
|
|
1847
|
+
};
|
|
1787
1848
|
} catch (err) {
|
|
1788
1849
|
const error2 = err;
|
|
1789
1850
|
setError(error2);
|
|
1790
|
-
|
|
1851
|
+
return {
|
|
1852
|
+
success: false,
|
|
1853
|
+
error: error2.message || "Failed to log entry"
|
|
1854
|
+
};
|
|
1791
1855
|
} finally {
|
|
1792
1856
|
setIsLoading(false);
|
|
1793
1857
|
}
|
|
1794
1858
|
},
|
|
1795
1859
|
[remoteWorkService]
|
|
1796
1860
|
);
|
|
1797
|
-
const logEntry = useCallback6(
|
|
1798
|
-
async (options) => {
|
|
1799
|
-
return logRemoteWork(0 /* ENTRY */, options);
|
|
1800
|
-
},
|
|
1801
|
-
[logRemoteWork]
|
|
1802
|
-
);
|
|
1803
1861
|
const logExit = useCallback6(
|
|
1804
|
-
async (
|
|
1805
|
-
|
|
1862
|
+
async (params) => {
|
|
1863
|
+
setIsLoading(true);
|
|
1864
|
+
setError(null);
|
|
1865
|
+
try {
|
|
1866
|
+
const result = await remoteWorkService.logRemoteWork({
|
|
1867
|
+
userId: params.userId,
|
|
1868
|
+
entranceType: 1 /* EXIT */,
|
|
1869
|
+
timestamp: params.timestamp,
|
|
1870
|
+
description: params.description
|
|
1871
|
+
});
|
|
1872
|
+
if (result.success) {
|
|
1873
|
+
return {
|
|
1874
|
+
success: true,
|
|
1875
|
+
data: result.entrance
|
|
1876
|
+
};
|
|
1877
|
+
}
|
|
1878
|
+
return {
|
|
1879
|
+
success: false,
|
|
1880
|
+
error: result.message || "Failed to log exit"
|
|
1881
|
+
};
|
|
1882
|
+
} catch (err) {
|
|
1883
|
+
const error2 = err;
|
|
1884
|
+
setError(error2);
|
|
1885
|
+
return {
|
|
1886
|
+
success: false,
|
|
1887
|
+
error: error2.message || "Failed to log exit"
|
|
1888
|
+
};
|
|
1889
|
+
} finally {
|
|
1890
|
+
setIsLoading(false);
|
|
1891
|
+
}
|
|
1806
1892
|
},
|
|
1807
|
-
[
|
|
1893
|
+
[remoteWorkService]
|
|
1808
1894
|
);
|
|
1809
1895
|
return {
|
|
1810
1896
|
logEntry,
|
|
1811
1897
|
logExit,
|
|
1812
|
-
logRemoteWork,
|
|
1813
1898
|
isLoading,
|
|
1814
1899
|
error
|
|
1815
1900
|
};
|
|
1816
1901
|
}
|
|
1817
1902
|
|
|
1818
1903
|
// src/index.ts
|
|
1819
|
-
var SDK_VERSION = "1.0.
|
|
1904
|
+
var SDK_VERSION = "1.0.4";
|
|
1820
1905
|
export {
|
|
1821
1906
|
ApiClient,
|
|
1822
1907
|
AuthService,
|
|
@@ -1842,13 +1927,13 @@ export {
|
|
|
1842
1927
|
formatISO,
|
|
1843
1928
|
formatTime,
|
|
1844
1929
|
parseISO,
|
|
1845
|
-
useCheckIn,
|
|
1846
1930
|
useLocation,
|
|
1847
|
-
useNFCScanner,
|
|
1848
1931
|
usePassgageAccess,
|
|
1849
1932
|
usePassgageAuth,
|
|
1850
|
-
|
|
1851
|
-
|
|
1933
|
+
usePassgageCheckIn,
|
|
1934
|
+
usePassgageNFCScanner,
|
|
1935
|
+
usePassgageQRScanner,
|
|
1936
|
+
usePassgageRemoteWork,
|
|
1852
1937
|
validateCoordinates,
|
|
1853
1938
|
validateDeviceId,
|
|
1854
1939
|
validateNFCCode,
|