@passgage/sdk-react-native 1.0.15 → 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 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: Error) => void;
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: Error | null;
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: Error) => void;
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: Error | null;
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 <= allowedRange,
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",
@@ -1176,7 +1150,7 @@ var enteranceFlow = async (data, options) => {
1176
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
  }
@@ -1203,7 +1177,7 @@ var enteranceFlow = async (data, options) => {
1203
1177
  try {
1204
1178
  const enteranceQrRes = await QRAccessService.createEntranceFromQR(onlineRequestBody);
1205
1179
  if (enteranceQrRes.success) {
1206
- addQrReadRecord(qrCode);
1180
+ addQrReadRecord(isQrCode ? qrCode : nfcCode);
1207
1181
  return {
1208
1182
  success: !!enteranceQrRes?.success,
1209
1183
  message: enteranceQrRes.success ? "Enterance validated successfully" : "Enterance validation failed",
@@ -1236,7 +1210,7 @@ var enteranceFlow = async (data, options) => {
1236
1210
  } else {
1237
1211
  try {
1238
1212
  const enteranceQrRes = await QRAccessService.createEntranceFromQR(onlineRequestBody);
1239
- addQrReadRecord(qrCode);
1213
+ addQrReadRecord(isQrCode ? qrCode : nfcCode);
1240
1214
  return {
1241
1215
  success: !!enteranceQrRes?.success,
1242
1216
  message: enteranceQrRes.success ? "QR code validated successfully" : "QR code validation failed",
@@ -1473,9 +1447,7 @@ function PassgageAccessProvider(props) {
1473
1447
  var usePassgageAccessContext = () => {
1474
1448
  const ctx = React.useContext(PassgageAccessProvideContext);
1475
1449
  if (!ctx) {
1476
- throw new Error(
1477
- "usePassgageAccessContext must be used inside AuthProvider"
1478
- );
1450
+ console.error("usePassgageAccessContext must be used inside AuthProvider");
1479
1451
  }
1480
1452
  return ctx;
1481
1453
  };
@@ -1578,7 +1550,8 @@ function usePassgageNFCScanner(payload) {
1578
1550
  }
1579
1551
  const device = qrDevices.find((device2) => device2.nfc_code === nfcCode);
1580
1552
  if (!device) {
1581
- throw new Error("NFC device not found");
1553
+ payload?.onError?.({ success: false, message: "NFC device not found" });
1554
+ return;
1582
1555
  }
1583
1556
  const result = await enteranceFlow(
1584
1557
  {
@@ -1589,14 +1562,19 @@ function usePassgageNFCScanner(payload) {
1589
1562
  payload?.options
1590
1563
  );
1591
1564
  if (!result.success) {
1592
- throw new Error(result.message);
1565
+ payload?.onError?.({ success: false, message: result.message });
1593
1566
  }
1594
1567
  payload?.onSuccess?.(result.entrance);
1595
1568
  stopScanning();
1596
1569
  } catch (err) {
1597
- const error2 = err;
1598
- setError(error2);
1599
- payload?.onError?.(error2);
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
+ });
1600
1578
  stopScanning();
1601
1579
  }
1602
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 <= allowedRange,
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",
@@ -1146,7 +1120,7 @@ var enteranceFlow = async (data, options) => {
1146
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
  }
@@ -1173,7 +1147,7 @@ var enteranceFlow = async (data, options) => {
1173
1147
  try {
1174
1148
  const enteranceQrRes = await QRAccessService.createEntranceFromQR(onlineRequestBody);
1175
1149
  if (enteranceQrRes.success) {
1176
- addQrReadRecord(qrCode);
1150
+ addQrReadRecord(isQrCode ? qrCode : nfcCode);
1177
1151
  return {
1178
1152
  success: !!enteranceQrRes?.success,
1179
1153
  message: enteranceQrRes.success ? "Enterance validated successfully" : "Enterance validation failed",
@@ -1206,7 +1180,7 @@ var enteranceFlow = async (data, options) => {
1206
1180
  } else {
1207
1181
  try {
1208
1182
  const enteranceQrRes = await QRAccessService.createEntranceFromQR(onlineRequestBody);
1209
- addQrReadRecord(qrCode);
1183
+ addQrReadRecord(isQrCode ? qrCode : nfcCode);
1210
1184
  return {
1211
1185
  success: !!enteranceQrRes?.success,
1212
1186
  message: enteranceQrRes.success ? "QR code validated successfully" : "QR code validation failed",
@@ -1443,9 +1417,7 @@ function PassgageAccessProvider(props) {
1443
1417
  var usePassgageAccessContext = () => {
1444
1418
  const ctx = useContext(PassgageAccessProvideContext);
1445
1419
  if (!ctx) {
1446
- throw new Error(
1447
- "usePassgageAccessContext must be used inside AuthProvider"
1448
- );
1420
+ console.error("usePassgageAccessContext must be used inside AuthProvider");
1449
1421
  }
1450
1422
  return ctx;
1451
1423
  };
@@ -1548,7 +1520,8 @@ function usePassgageNFCScanner(payload) {
1548
1520
  }
1549
1521
  const device = qrDevices.find((device2) => device2.nfc_code === nfcCode);
1550
1522
  if (!device) {
1551
- throw new Error("NFC device not found");
1523
+ payload?.onError?.({ success: false, message: "NFC device not found" });
1524
+ return;
1552
1525
  }
1553
1526
  const result = await enteranceFlow(
1554
1527
  {
@@ -1559,14 +1532,19 @@ function usePassgageNFCScanner(payload) {
1559
1532
  payload?.options
1560
1533
  );
1561
1534
  if (!result.success) {
1562
- throw new Error(result.message);
1535
+ payload?.onError?.({ success: false, message: result.message });
1563
1536
  }
1564
1537
  payload?.onSuccess?.(result.entrance);
1565
1538
  stopScanning();
1566
1539
  } catch (err) {
1567
- const error2 = err;
1568
- setError(error2);
1569
- payload?.onError?.(error2);
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
+ });
1570
1548
  stopScanning();
1571
1549
  }
1572
1550
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@passgage/sdk-react-native",
3
- "version": "1.0.15",
3
+ "version": "1.0.16",
4
4
  "description": "Passgage Access SDK - React Native wrapper with components and hooks",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",