@passgage/sdk-react-native 1.0.15 → 1.0.17

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
  */
@@ -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
  */
@@ -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",
@@ -1156,7 +1132,7 @@ var enteranceFlow = async (data, options) => {
1156
1132
  const location = locationStore.getState().location;
1157
1133
  const qrAccessDevices = qrScannerStore.getState().qrAccessDevices;
1158
1134
  const { qrCode, device, isQrCode, nfcCode = "" } = data;
1159
- if (isQrCode ? !validateQRCode(qrCode) : validateNFCCode(nfcCode)) {
1135
+ if (isQrCode ? !validateQRCode(qrCode) : !validateNFCCode(nfcCode)) {
1160
1136
  return {
1161
1137
  success: false,
1162
1138
  message: "Invalid QR code format",
@@ -1176,7 +1152,7 @@ var enteranceFlow = async (data, options) => {
1176
1152
  if (!options?.skipRepetitiveCheck && !checkRepetitiveRead(isQrCode ? qrCode : nfcCode)) {
1177
1153
  return {
1178
1154
  success: false,
1179
- message: "QR code was recently scanned. Please wait before scanning again.",
1155
+ message: isQrCode ? "QR code was recently scanned. Please wait before scanning again." : "NFC code was recently scanned. Please wait before scanning again.",
1180
1156
  error: { code: "REPETITIVE_READ" }
1181
1157
  };
1182
1158
  }
@@ -1203,7 +1179,7 @@ var enteranceFlow = async (data, options) => {
1203
1179
  try {
1204
1180
  const enteranceQrRes = await QRAccessService.createEntranceFromQR(onlineRequestBody);
1205
1181
  if (enteranceQrRes.success) {
1206
- addQrReadRecord(qrCode);
1182
+ addQrReadRecord(isQrCode ? qrCode : nfcCode);
1207
1183
  return {
1208
1184
  success: !!enteranceQrRes?.success,
1209
1185
  message: enteranceQrRes.success ? "Enterance validated successfully" : "Enterance validation failed",
@@ -1236,7 +1212,7 @@ var enteranceFlow = async (data, options) => {
1236
1212
  } else {
1237
1213
  try {
1238
1214
  const enteranceQrRes = await QRAccessService.createEntranceFromQR(onlineRequestBody);
1239
- addQrReadRecord(qrCode);
1215
+ addQrReadRecord(isQrCode ? qrCode : nfcCode);
1240
1216
  return {
1241
1217
  success: !!enteranceQrRes?.success,
1242
1218
  message: enteranceQrRes.success ? "QR code validated successfully" : "QR code validation failed",
@@ -1473,9 +1449,7 @@ function PassgageAccessProvider(props) {
1473
1449
  var usePassgageAccessContext = () => {
1474
1450
  const ctx = React.useContext(PassgageAccessProvideContext);
1475
1451
  if (!ctx) {
1476
- throw new Error(
1477
- "usePassgageAccessContext must be used inside AuthProvider"
1478
- );
1452
+ throw new Error("usePassgageAccessContext must be used inside AuthProvider");
1479
1453
  }
1480
1454
  return ctx;
1481
1455
  };
@@ -1578,7 +1552,8 @@ function usePassgageNFCScanner(payload) {
1578
1552
  }
1579
1553
  const device = qrDevices.find((device2) => device2.nfc_code === nfcCode);
1580
1554
  if (!device) {
1581
- throw new Error("NFC device not found");
1555
+ payload?.onError?.({ success: false, message: "NFC device not found" });
1556
+ return;
1582
1557
  }
1583
1558
  const result = await enteranceFlow(
1584
1559
  {
@@ -1589,14 +1564,19 @@ function usePassgageNFCScanner(payload) {
1589
1564
  payload?.options
1590
1565
  );
1591
1566
  if (!result.success) {
1592
- throw new Error(result.message);
1567
+ payload?.onError?.({ success: false, message: result.message });
1593
1568
  }
1594
1569
  payload?.onSuccess?.(result.entrance);
1595
1570
  stopScanning();
1596
1571
  } catch (err) {
1597
- const error2 = err;
1598
- setError(error2);
1599
- payload?.onError?.(error2);
1572
+ setError({
1573
+ success: false,
1574
+ message: err?.message || "NFC scanning failed"
1575
+ });
1576
+ payload?.onError?.({
1577
+ success: false,
1578
+ message: err?.message || "NFC scanning failed"
1579
+ });
1600
1580
  stopScanning();
1601
1581
  }
1602
1582
  };
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",
@@ -1126,7 +1102,7 @@ var enteranceFlow = async (data, options) => {
1126
1102
  const location = locationStore.getState().location;
1127
1103
  const qrAccessDevices = qrScannerStore.getState().qrAccessDevices;
1128
1104
  const { qrCode, device, isQrCode, nfcCode = "" } = data;
1129
- if (isQrCode ? !validateQRCode(qrCode) : validateNFCCode(nfcCode)) {
1105
+ if (isQrCode ? !validateQRCode(qrCode) : !validateNFCCode(nfcCode)) {
1130
1106
  return {
1131
1107
  success: false,
1132
1108
  message: "Invalid QR code format",
@@ -1146,7 +1122,7 @@ var enteranceFlow = async (data, options) => {
1146
1122
  if (!options?.skipRepetitiveCheck && !checkRepetitiveRead(isQrCode ? qrCode : nfcCode)) {
1147
1123
  return {
1148
1124
  success: false,
1149
- message: "QR code was recently scanned. Please wait before scanning again.",
1125
+ message: isQrCode ? "QR code was recently scanned. Please wait before scanning again." : "NFC code was recently scanned. Please wait before scanning again.",
1150
1126
  error: { code: "REPETITIVE_READ" }
1151
1127
  };
1152
1128
  }
@@ -1173,7 +1149,7 @@ var enteranceFlow = async (data, options) => {
1173
1149
  try {
1174
1150
  const enteranceQrRes = await QRAccessService.createEntranceFromQR(onlineRequestBody);
1175
1151
  if (enteranceQrRes.success) {
1176
- addQrReadRecord(qrCode);
1152
+ addQrReadRecord(isQrCode ? qrCode : nfcCode);
1177
1153
  return {
1178
1154
  success: !!enteranceQrRes?.success,
1179
1155
  message: enteranceQrRes.success ? "Enterance validated successfully" : "Enterance validation failed",
@@ -1206,7 +1182,7 @@ var enteranceFlow = async (data, options) => {
1206
1182
  } else {
1207
1183
  try {
1208
1184
  const enteranceQrRes = await QRAccessService.createEntranceFromQR(onlineRequestBody);
1209
- addQrReadRecord(qrCode);
1185
+ addQrReadRecord(isQrCode ? qrCode : nfcCode);
1210
1186
  return {
1211
1187
  success: !!enteranceQrRes?.success,
1212
1188
  message: enteranceQrRes.success ? "QR code validated successfully" : "QR code validation failed",
@@ -1443,9 +1419,7 @@ function PassgageAccessProvider(props) {
1443
1419
  var usePassgageAccessContext = () => {
1444
1420
  const ctx = useContext(PassgageAccessProvideContext);
1445
1421
  if (!ctx) {
1446
- throw new Error(
1447
- "usePassgageAccessContext must be used inside AuthProvider"
1448
- );
1422
+ throw new Error("usePassgageAccessContext must be used inside AuthProvider");
1449
1423
  }
1450
1424
  return ctx;
1451
1425
  };
@@ -1548,7 +1522,8 @@ function usePassgageNFCScanner(payload) {
1548
1522
  }
1549
1523
  const device = qrDevices.find((device2) => device2.nfc_code === nfcCode);
1550
1524
  if (!device) {
1551
- throw new Error("NFC device not found");
1525
+ payload?.onError?.({ success: false, message: "NFC device not found" });
1526
+ return;
1552
1527
  }
1553
1528
  const result = await enteranceFlow(
1554
1529
  {
@@ -1559,14 +1534,19 @@ function usePassgageNFCScanner(payload) {
1559
1534
  payload?.options
1560
1535
  );
1561
1536
  if (!result.success) {
1562
- throw new Error(result.message);
1537
+ payload?.onError?.({ success: false, message: result.message });
1563
1538
  }
1564
1539
  payload?.onSuccess?.(result.entrance);
1565
1540
  stopScanning();
1566
1541
  } catch (err) {
1567
- const error2 = err;
1568
- setError(error2);
1569
- payload?.onError?.(error2);
1542
+ setError({
1543
+ success: false,
1544
+ message: err?.message || "NFC scanning failed"
1545
+ });
1546
+ payload?.onError?.({
1547
+ success: false,
1548
+ message: err?.message || "NFC scanning failed"
1549
+ });
1570
1550
  stopScanning();
1571
1551
  }
1572
1552
  };
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.17",
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",