abmp-npm 2.0.65 → 2.0.67

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/backend/consts.js CHANGED
@@ -1,5 +1,5 @@
1
1
  const PAC_API_URL = 'https://members.abmp.com/eweb/api/Wix';
2
- const TEST_PAC_API_URL = 'https://members.abmp.com/nfpactest/eweb/api/Wix';
2
+ const TEST_PAC_API_URL = 'https://members-test.abmp.com/eweb/api/Wix';
3
3
  const BACKUP_API_URL = 'https://psdevteamenterpris.wixstudio.com/abmp-backup/_functions';
4
4
  const SSO_TOKEN_AUTH_API_URL = 'https://members.professionalassistcorp.com/';
5
5
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "abmp-npm",
3
- "version": "2.0.65",
3
+ "version": "2.0.67",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "check-cycles": "madge --circular .",
@@ -5,6 +5,43 @@ const { DEFAULT_FILTER } = require('../consts.js');
5
5
 
6
6
  const { debouncedFunction } = require('./sharedUtils.js');
7
7
 
8
+ function isValidGeolocation(lat, lng) {
9
+ return Number.isFinite(lat) && Number.isFinite(lng) && (lat !== 0 || lng !== 0);
10
+ }
11
+
12
+ function applyGeolocationToFilter(filter, lat, lng, isSearchingNearby) {
13
+ return {
14
+ ...filter,
15
+ postalcode: isSearchingNearby ? null : filter.postalcode,
16
+ state: isSearchingNearby ? [] : filter.state,
17
+ city: isSearchingNearby ? [] : filter.city,
18
+ stateSearch: isSearchingNearby ? '' : filter.stateSearch,
19
+ citySearch: isSearchingNearby ? '' : filter.citySearch,
20
+ latitude: lat,
21
+ longitude: lng,
22
+ };
23
+ }
24
+
25
+ const GEOLOCATION_TIMEOUT_MS = 10000;
26
+
27
+ function getCurrentGeolocationWithTimeout(timeoutMs = GEOLOCATION_TIMEOUT_MS) {
28
+ return new Promise((resolve, reject) => {
29
+ const timer = setTimeout(() => {
30
+ reject(new Error(`Geolocation timed out after ${timeoutMs}ms`));
31
+ }, timeoutMs);
32
+ wixWindow
33
+ .getCurrentGeolocation()
34
+ .then(location => {
35
+ clearTimeout(timer);
36
+ resolve(location);
37
+ })
38
+ .catch(error => {
39
+ clearTimeout(timer);
40
+ reject(error);
41
+ });
42
+ });
43
+ }
44
+
8
45
  const createHomepageUtils = (_$w, filterProfiles) => {
9
46
  const getFiltersSelectors = filterName => ({
10
47
  checkBoxContainerSelector: _$w(`#${filterName}CheckBoxContainer`),
@@ -362,29 +399,24 @@ const createHomepageUtils = (_$w, filterProfiles) => {
362
399
  });
363
400
  }
364
401
  async function getAndSetUserLocation(isSearchingNearby, filter) {
365
- try {
366
- let location = {
367
- coords: {
368
- latitude: 0,
369
- longitude: 0,
370
- },
402
+ const { latitude: existingLat, longitude: existingLng } = filter;
403
+ if (isValidGeolocation(existingLat, existingLng)) {
404
+ return {
405
+ success: true,
406
+ filter: applyGeolocationToFilter(filter, existingLat, existingLng, isSearchingNearby),
371
407
  };
372
- location = await wixWindow.getCurrentGeolocation();
408
+ }
409
+
410
+ try {
411
+ const location = await getCurrentGeolocationWithTimeout();
373
412
 
374
413
  console.log('location inside getAndSetUserLocation', location);
375
414
  const userLat = location.coords?.latitude ?? 0;
376
415
  const userLong = location.coords?.longitude ?? 0;
377
- filter = {
378
- ...filter,
379
- postalcode: isSearchingNearby ? null : filter.postalcode,
380
- state: isSearchingNearby ? [] : filter.state,
381
- city: isSearchingNearby ? [] : filter.city,
382
- stateSearch: isSearchingNearby ? '' : filter.stateSearch,
383
- citySearch: isSearchingNearby ? '' : filter.citySearch,
384
- latitude: userLat,
385
- longitude: userLong,
416
+ return {
417
+ success: true,
418
+ filter: applyGeolocationToFilter(filter, userLat, userLong, isSearchingNearby),
386
419
  };
387
- return { success: true, filter };
388
420
  } catch (error) {
389
421
  console.warn('Failed to get user location in getAndSetUserLocation', error);
390
422
  return { success: false, filter };