@passgage/sdk-react-native 1.0.14 → 1.0.16
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/dist/index.d.mts +3 -8
- package/dist/index.d.ts +3 -8
- package/dist/index.js +31 -57
- package/dist/index.mjs +31 -57
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -634,11 +634,6 @@ interface NFCValidationResult extends FlowResponseType {
|
|
|
634
634
|
}
|
|
635
635
|
declare const NfcAccessService: {
|
|
636
636
|
validateNFCFormat: (code: string) => boolean;
|
|
637
|
-
shouldValidateLocation: (device?: QrDevice) => boolean;
|
|
638
|
-
validateLocation: (device?: QrDevice, userLocation?: Coordinates) => {
|
|
639
|
-
valid: boolean;
|
|
640
|
-
distance?: number;
|
|
641
|
-
};
|
|
642
637
|
/**
|
|
643
638
|
* Validate NFC code with full checks
|
|
644
639
|
*/
|
|
@@ -904,7 +899,7 @@ interface PassgageAccessProviderProps {
|
|
|
904
899
|
locationPermissionErrorCallback?: (error: any) => void;
|
|
905
900
|
}
|
|
906
901
|
declare function PassgageAccessProvider(props: PassgageAccessProviderProps): React.JSX.Element;
|
|
907
|
-
declare const usePassgageAccessContext: () => PassgageAccessProviderProps;
|
|
902
|
+
declare const usePassgageAccessContext: () => PassgageAccessProviderProps | undefined;
|
|
908
903
|
|
|
909
904
|
interface EnteranceFlowOptions {
|
|
910
905
|
skipLocationCheck?: boolean;
|
|
@@ -936,7 +931,7 @@ declare const usePassgageQRScanner: (payload: UsePassgageQRScanner) => UsePassga
|
|
|
936
931
|
interface UsePassgageNFCScannerOptions {
|
|
937
932
|
options: EnteranceFlowOptions;
|
|
938
933
|
onSuccess?: (entrance?: Entrance) => void;
|
|
939
|
-
onError?: (error:
|
|
934
|
+
onError?: (error: FlowResponseType) => void;
|
|
940
935
|
}
|
|
941
936
|
interface UsePassgageNFCScannerReturn {
|
|
942
937
|
nfcData?: string;
|
|
@@ -944,7 +939,7 @@ interface UsePassgageNFCScannerReturn {
|
|
|
944
939
|
startScanning: () => Promise<void>;
|
|
945
940
|
stopScanning: () => Promise<void>;
|
|
946
941
|
isScanning: boolean;
|
|
947
|
-
error:
|
|
942
|
+
error: FlowResponseType | null;
|
|
948
943
|
}
|
|
949
944
|
/**
|
|
950
945
|
* Convert hex string to decimal
|
package/dist/index.d.ts
CHANGED
|
@@ -634,11 +634,6 @@ interface NFCValidationResult extends FlowResponseType {
|
|
|
634
634
|
}
|
|
635
635
|
declare const NfcAccessService: {
|
|
636
636
|
validateNFCFormat: (code: string) => boolean;
|
|
637
|
-
shouldValidateLocation: (device?: QrDevice) => boolean;
|
|
638
|
-
validateLocation: (device?: QrDevice, userLocation?: Coordinates) => {
|
|
639
|
-
valid: boolean;
|
|
640
|
-
distance?: number;
|
|
641
|
-
};
|
|
642
637
|
/**
|
|
643
638
|
* Validate NFC code with full checks
|
|
644
639
|
*/
|
|
@@ -904,7 +899,7 @@ interface PassgageAccessProviderProps {
|
|
|
904
899
|
locationPermissionErrorCallback?: (error: any) => void;
|
|
905
900
|
}
|
|
906
901
|
declare function PassgageAccessProvider(props: PassgageAccessProviderProps): React.JSX.Element;
|
|
907
|
-
declare const usePassgageAccessContext: () => PassgageAccessProviderProps;
|
|
902
|
+
declare const usePassgageAccessContext: () => PassgageAccessProviderProps | undefined;
|
|
908
903
|
|
|
909
904
|
interface EnteranceFlowOptions {
|
|
910
905
|
skipLocationCheck?: boolean;
|
|
@@ -936,7 +931,7 @@ declare const usePassgageQRScanner: (payload: UsePassgageQRScanner) => UsePassga
|
|
|
936
931
|
interface UsePassgageNFCScannerOptions {
|
|
937
932
|
options: EnteranceFlowOptions;
|
|
938
933
|
onSuccess?: (entrance?: Entrance) => void;
|
|
939
|
-
onError?: (error:
|
|
934
|
+
onError?: (error: FlowResponseType) => void;
|
|
940
935
|
}
|
|
941
936
|
interface UsePassgageNFCScannerReturn {
|
|
942
937
|
nfcData?: string;
|
|
@@ -944,7 +939,7 @@ interface UsePassgageNFCScannerReturn {
|
|
|
944
939
|
startScanning: () => Promise<void>;
|
|
945
940
|
stopScanning: () => Promise<void>;
|
|
946
941
|
isScanning: boolean;
|
|
947
|
-
error:
|
|
942
|
+
error: FlowResponseType | null;
|
|
948
943
|
}
|
|
949
944
|
/**
|
|
950
945
|
* Convert hex string to decimal
|
package/dist/index.js
CHANGED
|
@@ -608,8 +608,9 @@ function checkOnLocation(targetLat, targetLon, allowedRange, userPosition) {
|
|
|
608
608
|
userPosition.latitude,
|
|
609
609
|
userPosition.longitude
|
|
610
610
|
);
|
|
611
|
+
let threshInKm = allowedRange / 1e3;
|
|
611
612
|
return {
|
|
612
|
-
ok: distance <=
|
|
613
|
+
ok: distance <= threshInKm,
|
|
613
614
|
distance
|
|
614
615
|
};
|
|
615
616
|
}
|
|
@@ -708,27 +709,6 @@ var NfcAccessService = {
|
|
|
708
709
|
validateNFCFormat: (code) => {
|
|
709
710
|
return validateNFCCode(code);
|
|
710
711
|
},
|
|
711
|
-
shouldValidateLocation: (device) => {
|
|
712
|
-
return device?.nfc_range_matter === "1" && !!device?.latitude && !!device.longitude;
|
|
713
|
-
},
|
|
714
|
-
validateLocation: (device, userLocation) => {
|
|
715
|
-
if (!NfcAccessService.shouldValidateLocation(device)) {
|
|
716
|
-
return { valid: true };
|
|
717
|
-
}
|
|
718
|
-
if (!userLocation) {
|
|
719
|
-
return { valid: false };
|
|
720
|
-
}
|
|
721
|
-
const locationCheck = checkOnLocation(
|
|
722
|
-
device?.latitude,
|
|
723
|
-
device?.longitude,
|
|
724
|
-
device?.nfc_range || 100,
|
|
725
|
-
userLocation
|
|
726
|
-
);
|
|
727
|
-
return {
|
|
728
|
-
valid: locationCheck.ok,
|
|
729
|
-
distance: locationCheck.distance
|
|
730
|
-
};
|
|
731
|
-
},
|
|
732
712
|
/**
|
|
733
713
|
* Validate NFC code with full checks
|
|
734
714
|
*/
|
|
@@ -739,9 +719,7 @@ var NfcAccessService = {
|
|
|
739
719
|
};
|
|
740
720
|
if (device.is_iot) {
|
|
741
721
|
try {
|
|
742
|
-
const enteranceQrRes = await QRAccessService.createEntranceFromQR(
|
|
743
|
-
onlineRequestBody
|
|
744
|
-
);
|
|
722
|
+
const enteranceQrRes = await QRAccessService.createEntranceFromQR(onlineRequestBody);
|
|
745
723
|
return {
|
|
746
724
|
success: !!enteranceQrRes?.success,
|
|
747
725
|
message: "QR code validated successfully",
|
|
@@ -756,9 +734,7 @@ var NfcAccessService = {
|
|
|
756
734
|
}
|
|
757
735
|
} else {
|
|
758
736
|
try {
|
|
759
|
-
const enteranceQrRes = await QRAccessService.createEntranceFromQR(
|
|
760
|
-
onlineRequestBody
|
|
761
|
-
);
|
|
737
|
+
const enteranceQrRes = await QRAccessService.createEntranceFromQR(onlineRequestBody);
|
|
762
738
|
return {
|
|
763
739
|
success: !!enteranceQrRes?.success,
|
|
764
740
|
message: "QR code validated successfully",
|
|
@@ -999,7 +975,6 @@ var SecureStorage = {
|
|
|
999
975
|
);
|
|
1000
976
|
} catch (error) {
|
|
1001
977
|
console.error("Failed to save tokens to secure storage:", error);
|
|
1002
|
-
throw new Error("Failed to save tokens");
|
|
1003
978
|
}
|
|
1004
979
|
},
|
|
1005
980
|
/**
|
|
@@ -1047,7 +1022,6 @@ var SecureStorage = {
|
|
|
1047
1022
|
);
|
|
1048
1023
|
} catch (error) {
|
|
1049
1024
|
console.error("Failed to save user to secure storage:", error);
|
|
1050
|
-
throw new Error("Failed to save user");
|
|
1051
1025
|
}
|
|
1052
1026
|
},
|
|
1053
1027
|
/**
|
|
@@ -1156,7 +1130,7 @@ var enteranceFlow = async (data, options) => {
|
|
|
1156
1130
|
const location = locationStore.getState().location;
|
|
1157
1131
|
const qrAccessDevices = qrScannerStore.getState().qrAccessDevices;
|
|
1158
1132
|
const { qrCode, device, isQrCode, nfcCode = "" } = data;
|
|
1159
|
-
if (isQrCode ? !validateQRCode(qrCode) : validateNFCCode(nfcCode)) {
|
|
1133
|
+
if (isQrCode ? !validateQRCode(qrCode) : !validateNFCCode(nfcCode)) {
|
|
1160
1134
|
return {
|
|
1161
1135
|
success: false,
|
|
1162
1136
|
message: "Invalid QR code format",
|
|
@@ -1173,14 +1147,14 @@ var enteranceFlow = async (data, options) => {
|
|
|
1173
1147
|
}
|
|
1174
1148
|
};
|
|
1175
1149
|
}
|
|
1176
|
-
if (!options
|
|
1150
|
+
if (!options?.skipRepetitiveCheck && !checkRepetitiveRead(isQrCode ? qrCode : nfcCode)) {
|
|
1177
1151
|
return {
|
|
1178
1152
|
success: false,
|
|
1179
|
-
message: "QR code was recently scanned. Please wait before scanning again.",
|
|
1153
|
+
message: isQrCode ? "QR code was recently scanned. Please wait before scanning again." : "NFC code was recently scanned. Please wait before scanning again.",
|
|
1180
1154
|
error: { code: "REPETITIVE_READ" }
|
|
1181
1155
|
};
|
|
1182
1156
|
}
|
|
1183
|
-
if (!options
|
|
1157
|
+
if (!options?.skipLocationCheck) {
|
|
1184
1158
|
const locationValidation = validateLocation(device, location ?? void 0);
|
|
1185
1159
|
if (!locationValidation.valid) {
|
|
1186
1160
|
return {
|
|
@@ -1201,11 +1175,9 @@ var enteranceFlow = async (data, options) => {
|
|
|
1201
1175
|
const enteranceResIot = await QRAccessService.triggerIoTDevice(device.id);
|
|
1202
1176
|
if (enteranceResIot.success) {
|
|
1203
1177
|
try {
|
|
1204
|
-
const enteranceQrRes = await QRAccessService.createEntranceFromQR(
|
|
1205
|
-
onlineRequestBody
|
|
1206
|
-
);
|
|
1178
|
+
const enteranceQrRes = await QRAccessService.createEntranceFromQR(onlineRequestBody);
|
|
1207
1179
|
if (enteranceQrRes.success) {
|
|
1208
|
-
addQrReadRecord(qrCode);
|
|
1180
|
+
addQrReadRecord(isQrCode ? qrCode : nfcCode);
|
|
1209
1181
|
return {
|
|
1210
1182
|
success: !!enteranceQrRes?.success,
|
|
1211
1183
|
message: enteranceQrRes.success ? "Enterance validated successfully" : "Enterance validation failed",
|
|
@@ -1237,10 +1209,8 @@ var enteranceFlow = async (data, options) => {
|
|
|
1237
1209
|
}
|
|
1238
1210
|
} else {
|
|
1239
1211
|
try {
|
|
1240
|
-
const enteranceQrRes = await QRAccessService.createEntranceFromQR(
|
|
1241
|
-
|
|
1242
|
-
);
|
|
1243
|
-
addQrReadRecord(qrCode);
|
|
1212
|
+
const enteranceQrRes = await QRAccessService.createEntranceFromQR(onlineRequestBody);
|
|
1213
|
+
addQrReadRecord(isQrCode ? qrCode : nfcCode);
|
|
1244
1214
|
return {
|
|
1245
1215
|
success: !!enteranceQrRes?.success,
|
|
1246
1216
|
message: enteranceQrRes.success ? "QR code validated successfully" : "QR code validation failed",
|
|
@@ -1477,9 +1447,7 @@ function PassgageAccessProvider(props) {
|
|
|
1477
1447
|
var usePassgageAccessContext = () => {
|
|
1478
1448
|
const ctx = React.useContext(PassgageAccessProvideContext);
|
|
1479
1449
|
if (!ctx) {
|
|
1480
|
-
|
|
1481
|
-
"usePassgageAccessContext must be used inside AuthProvider"
|
|
1482
|
-
);
|
|
1450
|
+
console.error("usePassgageAccessContext must be used inside AuthProvider");
|
|
1483
1451
|
}
|
|
1484
1452
|
return ctx;
|
|
1485
1453
|
};
|
|
@@ -1495,7 +1463,7 @@ var usePassgageQRScanner = (payload) => {
|
|
|
1495
1463
|
if (!qrDevice) {
|
|
1496
1464
|
qrDevice = qrDevices.find((item) => item.qr_code_id === qrCode);
|
|
1497
1465
|
if (!qrDevice) {
|
|
1498
|
-
payload
|
|
1466
|
+
payload?.onError?.(
|
|
1499
1467
|
error ?? { message: "QR Device not found", success: false }
|
|
1500
1468
|
);
|
|
1501
1469
|
return;
|
|
@@ -1507,12 +1475,12 @@ var usePassgageQRScanner = (payload) => {
|
|
|
1507
1475
|
qrCode,
|
|
1508
1476
|
isQrCode: true
|
|
1509
1477
|
},
|
|
1510
|
-
payload
|
|
1478
|
+
payload?.options
|
|
1511
1479
|
);
|
|
1512
1480
|
if (!result.success) {
|
|
1513
|
-
payload
|
|
1481
|
+
payload?.onError?.(result);
|
|
1514
1482
|
} else {
|
|
1515
|
-
payload
|
|
1483
|
+
payload?.onSuccess?.(result.entrance);
|
|
1516
1484
|
}
|
|
1517
1485
|
} catch (err) {
|
|
1518
1486
|
const errorObj = {
|
|
@@ -1521,7 +1489,7 @@ var usePassgageQRScanner = (payload) => {
|
|
|
1521
1489
|
error: { code: "QR_SCAN_FAILED" }
|
|
1522
1490
|
};
|
|
1523
1491
|
setError(errorObj);
|
|
1524
|
-
payload
|
|
1492
|
+
payload?.onError?.(errorObj);
|
|
1525
1493
|
} finally {
|
|
1526
1494
|
setIsLoading(false);
|
|
1527
1495
|
}
|
|
@@ -1582,7 +1550,8 @@ function usePassgageNFCScanner(payload) {
|
|
|
1582
1550
|
}
|
|
1583
1551
|
const device = qrDevices.find((device2) => device2.nfc_code === nfcCode);
|
|
1584
1552
|
if (!device) {
|
|
1585
|
-
|
|
1553
|
+
payload?.onError?.({ success: false, message: "NFC device not found" });
|
|
1554
|
+
return;
|
|
1586
1555
|
}
|
|
1587
1556
|
const result = await enteranceFlow(
|
|
1588
1557
|
{
|
|
@@ -1590,17 +1559,22 @@ function usePassgageNFCScanner(payload) {
|
|
|
1590
1559
|
nfcCode,
|
|
1591
1560
|
isQrCode: false
|
|
1592
1561
|
},
|
|
1593
|
-
payload
|
|
1562
|
+
payload?.options
|
|
1594
1563
|
);
|
|
1595
1564
|
if (!result.success) {
|
|
1596
|
-
|
|
1565
|
+
payload?.onError?.({ success: false, message: result.message });
|
|
1597
1566
|
}
|
|
1598
|
-
payload
|
|
1567
|
+
payload?.onSuccess?.(result.entrance);
|
|
1599
1568
|
stopScanning();
|
|
1600
1569
|
} catch (err) {
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1570
|
+
setError({
|
|
1571
|
+
success: false,
|
|
1572
|
+
message: err?.message || "NFC scanning failed"
|
|
1573
|
+
});
|
|
1574
|
+
payload?.onError?.({
|
|
1575
|
+
success: false,
|
|
1576
|
+
message: err?.message || "NFC scanning failed"
|
|
1577
|
+
});
|
|
1604
1578
|
stopScanning();
|
|
1605
1579
|
}
|
|
1606
1580
|
};
|
package/dist/index.mjs
CHANGED
|
@@ -578,8 +578,9 @@ function checkOnLocation(targetLat, targetLon, allowedRange, userPosition) {
|
|
|
578
578
|
userPosition.latitude,
|
|
579
579
|
userPosition.longitude
|
|
580
580
|
);
|
|
581
|
+
let threshInKm = allowedRange / 1e3;
|
|
581
582
|
return {
|
|
582
|
-
ok: distance <=
|
|
583
|
+
ok: distance <= threshInKm,
|
|
583
584
|
distance
|
|
584
585
|
};
|
|
585
586
|
}
|
|
@@ -678,27 +679,6 @@ var NfcAccessService = {
|
|
|
678
679
|
validateNFCFormat: (code) => {
|
|
679
680
|
return validateNFCCode(code);
|
|
680
681
|
},
|
|
681
|
-
shouldValidateLocation: (device) => {
|
|
682
|
-
return device?.nfc_range_matter === "1" && !!device?.latitude && !!device.longitude;
|
|
683
|
-
},
|
|
684
|
-
validateLocation: (device, userLocation) => {
|
|
685
|
-
if (!NfcAccessService.shouldValidateLocation(device)) {
|
|
686
|
-
return { valid: true };
|
|
687
|
-
}
|
|
688
|
-
if (!userLocation) {
|
|
689
|
-
return { valid: false };
|
|
690
|
-
}
|
|
691
|
-
const locationCheck = checkOnLocation(
|
|
692
|
-
device?.latitude,
|
|
693
|
-
device?.longitude,
|
|
694
|
-
device?.nfc_range || 100,
|
|
695
|
-
userLocation
|
|
696
|
-
);
|
|
697
|
-
return {
|
|
698
|
-
valid: locationCheck.ok,
|
|
699
|
-
distance: locationCheck.distance
|
|
700
|
-
};
|
|
701
|
-
},
|
|
702
682
|
/**
|
|
703
683
|
* Validate NFC code with full checks
|
|
704
684
|
*/
|
|
@@ -709,9 +689,7 @@ var NfcAccessService = {
|
|
|
709
689
|
};
|
|
710
690
|
if (device.is_iot) {
|
|
711
691
|
try {
|
|
712
|
-
const enteranceQrRes = await QRAccessService.createEntranceFromQR(
|
|
713
|
-
onlineRequestBody
|
|
714
|
-
);
|
|
692
|
+
const enteranceQrRes = await QRAccessService.createEntranceFromQR(onlineRequestBody);
|
|
715
693
|
return {
|
|
716
694
|
success: !!enteranceQrRes?.success,
|
|
717
695
|
message: "QR code validated successfully",
|
|
@@ -726,9 +704,7 @@ var NfcAccessService = {
|
|
|
726
704
|
}
|
|
727
705
|
} else {
|
|
728
706
|
try {
|
|
729
|
-
const enteranceQrRes = await QRAccessService.createEntranceFromQR(
|
|
730
|
-
onlineRequestBody
|
|
731
|
-
);
|
|
707
|
+
const enteranceQrRes = await QRAccessService.createEntranceFromQR(onlineRequestBody);
|
|
732
708
|
return {
|
|
733
709
|
success: !!enteranceQrRes?.success,
|
|
734
710
|
message: "QR code validated successfully",
|
|
@@ -969,7 +945,6 @@ var SecureStorage = {
|
|
|
969
945
|
);
|
|
970
946
|
} catch (error) {
|
|
971
947
|
console.error("Failed to save tokens to secure storage:", error);
|
|
972
|
-
throw new Error("Failed to save tokens");
|
|
973
948
|
}
|
|
974
949
|
},
|
|
975
950
|
/**
|
|
@@ -1017,7 +992,6 @@ var SecureStorage = {
|
|
|
1017
992
|
);
|
|
1018
993
|
} catch (error) {
|
|
1019
994
|
console.error("Failed to save user to secure storage:", error);
|
|
1020
|
-
throw new Error("Failed to save user");
|
|
1021
995
|
}
|
|
1022
996
|
},
|
|
1023
997
|
/**
|
|
@@ -1126,7 +1100,7 @@ var enteranceFlow = async (data, options) => {
|
|
|
1126
1100
|
const location = locationStore.getState().location;
|
|
1127
1101
|
const qrAccessDevices = qrScannerStore.getState().qrAccessDevices;
|
|
1128
1102
|
const { qrCode, device, isQrCode, nfcCode = "" } = data;
|
|
1129
|
-
if (isQrCode ? !validateQRCode(qrCode) : validateNFCCode(nfcCode)) {
|
|
1103
|
+
if (isQrCode ? !validateQRCode(qrCode) : !validateNFCCode(nfcCode)) {
|
|
1130
1104
|
return {
|
|
1131
1105
|
success: false,
|
|
1132
1106
|
message: "Invalid QR code format",
|
|
@@ -1143,14 +1117,14 @@ var enteranceFlow = async (data, options) => {
|
|
|
1143
1117
|
}
|
|
1144
1118
|
};
|
|
1145
1119
|
}
|
|
1146
|
-
if (!options
|
|
1120
|
+
if (!options?.skipRepetitiveCheck && !checkRepetitiveRead(isQrCode ? qrCode : nfcCode)) {
|
|
1147
1121
|
return {
|
|
1148
1122
|
success: false,
|
|
1149
|
-
message: "QR code was recently scanned. Please wait before scanning again.",
|
|
1123
|
+
message: isQrCode ? "QR code was recently scanned. Please wait before scanning again." : "NFC code was recently scanned. Please wait before scanning again.",
|
|
1150
1124
|
error: { code: "REPETITIVE_READ" }
|
|
1151
1125
|
};
|
|
1152
1126
|
}
|
|
1153
|
-
if (!options
|
|
1127
|
+
if (!options?.skipLocationCheck) {
|
|
1154
1128
|
const locationValidation = validateLocation(device, location ?? void 0);
|
|
1155
1129
|
if (!locationValidation.valid) {
|
|
1156
1130
|
return {
|
|
@@ -1171,11 +1145,9 @@ var enteranceFlow = async (data, options) => {
|
|
|
1171
1145
|
const enteranceResIot = await QRAccessService.triggerIoTDevice(device.id);
|
|
1172
1146
|
if (enteranceResIot.success) {
|
|
1173
1147
|
try {
|
|
1174
|
-
const enteranceQrRes = await QRAccessService.createEntranceFromQR(
|
|
1175
|
-
onlineRequestBody
|
|
1176
|
-
);
|
|
1148
|
+
const enteranceQrRes = await QRAccessService.createEntranceFromQR(onlineRequestBody);
|
|
1177
1149
|
if (enteranceQrRes.success) {
|
|
1178
|
-
addQrReadRecord(qrCode);
|
|
1150
|
+
addQrReadRecord(isQrCode ? qrCode : nfcCode);
|
|
1179
1151
|
return {
|
|
1180
1152
|
success: !!enteranceQrRes?.success,
|
|
1181
1153
|
message: enteranceQrRes.success ? "Enterance validated successfully" : "Enterance validation failed",
|
|
@@ -1207,10 +1179,8 @@ var enteranceFlow = async (data, options) => {
|
|
|
1207
1179
|
}
|
|
1208
1180
|
} else {
|
|
1209
1181
|
try {
|
|
1210
|
-
const enteranceQrRes = await QRAccessService.createEntranceFromQR(
|
|
1211
|
-
|
|
1212
|
-
);
|
|
1213
|
-
addQrReadRecord(qrCode);
|
|
1182
|
+
const enteranceQrRes = await QRAccessService.createEntranceFromQR(onlineRequestBody);
|
|
1183
|
+
addQrReadRecord(isQrCode ? qrCode : nfcCode);
|
|
1214
1184
|
return {
|
|
1215
1185
|
success: !!enteranceQrRes?.success,
|
|
1216
1186
|
message: enteranceQrRes.success ? "QR code validated successfully" : "QR code validation failed",
|
|
@@ -1447,9 +1417,7 @@ function PassgageAccessProvider(props) {
|
|
|
1447
1417
|
var usePassgageAccessContext = () => {
|
|
1448
1418
|
const ctx = useContext(PassgageAccessProvideContext);
|
|
1449
1419
|
if (!ctx) {
|
|
1450
|
-
|
|
1451
|
-
"usePassgageAccessContext must be used inside AuthProvider"
|
|
1452
|
-
);
|
|
1420
|
+
console.error("usePassgageAccessContext must be used inside AuthProvider");
|
|
1453
1421
|
}
|
|
1454
1422
|
return ctx;
|
|
1455
1423
|
};
|
|
@@ -1465,7 +1433,7 @@ var usePassgageQRScanner = (payload) => {
|
|
|
1465
1433
|
if (!qrDevice) {
|
|
1466
1434
|
qrDevice = qrDevices.find((item) => item.qr_code_id === qrCode);
|
|
1467
1435
|
if (!qrDevice) {
|
|
1468
|
-
payload
|
|
1436
|
+
payload?.onError?.(
|
|
1469
1437
|
error ?? { message: "QR Device not found", success: false }
|
|
1470
1438
|
);
|
|
1471
1439
|
return;
|
|
@@ -1477,12 +1445,12 @@ var usePassgageQRScanner = (payload) => {
|
|
|
1477
1445
|
qrCode,
|
|
1478
1446
|
isQrCode: true
|
|
1479
1447
|
},
|
|
1480
|
-
payload
|
|
1448
|
+
payload?.options
|
|
1481
1449
|
);
|
|
1482
1450
|
if (!result.success) {
|
|
1483
|
-
payload
|
|
1451
|
+
payload?.onError?.(result);
|
|
1484
1452
|
} else {
|
|
1485
|
-
payload
|
|
1453
|
+
payload?.onSuccess?.(result.entrance);
|
|
1486
1454
|
}
|
|
1487
1455
|
} catch (err) {
|
|
1488
1456
|
const errorObj = {
|
|
@@ -1491,7 +1459,7 @@ var usePassgageQRScanner = (payload) => {
|
|
|
1491
1459
|
error: { code: "QR_SCAN_FAILED" }
|
|
1492
1460
|
};
|
|
1493
1461
|
setError(errorObj);
|
|
1494
|
-
payload
|
|
1462
|
+
payload?.onError?.(errorObj);
|
|
1495
1463
|
} finally {
|
|
1496
1464
|
setIsLoading(false);
|
|
1497
1465
|
}
|
|
@@ -1552,7 +1520,8 @@ function usePassgageNFCScanner(payload) {
|
|
|
1552
1520
|
}
|
|
1553
1521
|
const device = qrDevices.find((device2) => device2.nfc_code === nfcCode);
|
|
1554
1522
|
if (!device) {
|
|
1555
|
-
|
|
1523
|
+
payload?.onError?.({ success: false, message: "NFC device not found" });
|
|
1524
|
+
return;
|
|
1556
1525
|
}
|
|
1557
1526
|
const result = await enteranceFlow(
|
|
1558
1527
|
{
|
|
@@ -1560,17 +1529,22 @@ function usePassgageNFCScanner(payload) {
|
|
|
1560
1529
|
nfcCode,
|
|
1561
1530
|
isQrCode: false
|
|
1562
1531
|
},
|
|
1563
|
-
payload
|
|
1532
|
+
payload?.options
|
|
1564
1533
|
);
|
|
1565
1534
|
if (!result.success) {
|
|
1566
|
-
|
|
1535
|
+
payload?.onError?.({ success: false, message: result.message });
|
|
1567
1536
|
}
|
|
1568
|
-
payload
|
|
1537
|
+
payload?.onSuccess?.(result.entrance);
|
|
1569
1538
|
stopScanning();
|
|
1570
1539
|
} catch (err) {
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1540
|
+
setError({
|
|
1541
|
+
success: false,
|
|
1542
|
+
message: err?.message || "NFC scanning failed"
|
|
1543
|
+
});
|
|
1544
|
+
payload?.onError?.({
|
|
1545
|
+
success: false,
|
|
1546
|
+
message: err?.message || "NFC scanning failed"
|
|
1547
|
+
});
|
|
1574
1548
|
stopScanning();
|
|
1575
1549
|
}
|
|
1576
1550
|
};
|