@callforge/tracking-client 0.9.2 → 0.10.1

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.js CHANGED
@@ -511,14 +511,15 @@ var CallForge = class _CallForge {
511
511
  return this.formatApiResponse(data);
512
512
  }
513
513
  async fetchLocation() {
514
- var _a, _b;
514
+ var _a, _b, _c, _d;
515
515
  const locationId = this.getLocationId();
516
516
  if (typeof window !== "undefined" && window.__cfTrackingLocation) {
517
517
  try {
518
518
  const data2 = await window.__cfTrackingLocation;
519
519
  const dataWithExtras = data2;
520
520
  const effectiveLocId = (_a = dataWithExtras.locId) != null ? _a : locationId;
521
- const location2 = this.toTrackingLocation(data2.location, dataWithExtras.zipOptions);
521
+ const zipOptions = (_c = dataWithExtras.zipOptions) != null ? _c : (_b = data2.location) == null ? void 0 : _b.zipOptions;
522
+ const location2 = this.toTrackingLocation(data2.location, zipOptions);
522
523
  this.saveLocationToCache(effectiveLocId, location2, data2.expiresAt);
523
524
  return location2;
524
525
  } catch (e) {
@@ -526,7 +527,7 @@ var CallForge = class _CallForge {
526
527
  }
527
528
  const cached = this.locationCache.get(locationId);
528
529
  if (cached) {
529
- return this.toTrackingLocation(cached.location, (_b = cached.location) == null ? void 0 : _b.zipOptions);
530
+ return this.toTrackingLocation(cached.location, (_d = cached.location) == null ? void 0 : _d.zipOptions);
530
531
  }
531
532
  const data = await this.fetchLocationFromApi(locationId);
532
533
  const location = this.toTrackingLocation(data.location, data.zipOptions);
@@ -553,11 +554,8 @@ var CallForge = class _CallForge {
553
554
  async fetchFromApi(locationId, sessionToken, params) {
554
555
  const controller = new AbortController();
555
556
  const timeoutId = setTimeout(() => controller.abort(), FETCH_TIMEOUT_MS);
556
- let didForceRefreshBootstrap = false;
557
- let usedBootstrapTokenInInitialRequest = false;
558
557
  try {
559
558
  let bootstrapToken = this.getCachedBootstrapToken();
560
- usedBootstrapTokenInInitialRequest = !!bootstrapToken;
561
559
  let response = await fetch(
562
560
  this.buildUrl(locationId, sessionToken, params, bootstrapToken),
563
561
  {
@@ -567,7 +565,6 @@ var CallForge = class _CallForge {
567
565
  );
568
566
  if (response.status === 401) {
569
567
  bootstrapToken = await this.getBootstrapToken(true);
570
- didForceRefreshBootstrap = true;
571
568
  if (bootstrapToken) {
572
569
  response = await fetch(
573
570
  this.buildUrl(locationId, sessionToken, params, bootstrapToken),
@@ -581,24 +578,7 @@ var CallForge = class _CallForge {
581
578
  if (!response.ok) {
582
579
  throw new Error(`API error: ${response.status} ${response.statusText}`);
583
580
  }
584
- let data = await response.json();
585
- if (data.leaseId === null && !usedBootstrapTokenInInitialRequest && !didForceRefreshBootstrap) {
586
- const refreshedBootstrapToken = await this.getBootstrapToken(true);
587
- didForceRefreshBootstrap = true;
588
- if (refreshedBootstrapToken) {
589
- const retryResponse = await fetch(
590
- this.buildUrl(locationId, sessionToken, params, refreshedBootstrapToken),
591
- {
592
- credentials: "omit",
593
- signal: controller.signal
594
- }
595
- );
596
- if (retryResponse.ok) {
597
- data = await retryResponse.json();
598
- }
599
- }
600
- }
601
- return data;
581
+ return await response.json();
602
582
  } finally {
603
583
  clearTimeout(timeoutId);
604
584
  }
package/dist/index.mjs CHANGED
@@ -487,14 +487,15 @@ var CallForge = class _CallForge {
487
487
  return this.formatApiResponse(data);
488
488
  }
489
489
  async fetchLocation() {
490
- var _a, _b;
490
+ var _a, _b, _c, _d;
491
491
  const locationId = this.getLocationId();
492
492
  if (typeof window !== "undefined" && window.__cfTrackingLocation) {
493
493
  try {
494
494
  const data2 = await window.__cfTrackingLocation;
495
495
  const dataWithExtras = data2;
496
496
  const effectiveLocId = (_a = dataWithExtras.locId) != null ? _a : locationId;
497
- const location2 = this.toTrackingLocation(data2.location, dataWithExtras.zipOptions);
497
+ const zipOptions = (_c = dataWithExtras.zipOptions) != null ? _c : (_b = data2.location) == null ? void 0 : _b.zipOptions;
498
+ const location2 = this.toTrackingLocation(data2.location, zipOptions);
498
499
  this.saveLocationToCache(effectiveLocId, location2, data2.expiresAt);
499
500
  return location2;
500
501
  } catch (e) {
@@ -502,7 +503,7 @@ var CallForge = class _CallForge {
502
503
  }
503
504
  const cached = this.locationCache.get(locationId);
504
505
  if (cached) {
505
- return this.toTrackingLocation(cached.location, (_b = cached.location) == null ? void 0 : _b.zipOptions);
506
+ return this.toTrackingLocation(cached.location, (_d = cached.location) == null ? void 0 : _d.zipOptions);
506
507
  }
507
508
  const data = await this.fetchLocationFromApi(locationId);
508
509
  const location = this.toTrackingLocation(data.location, data.zipOptions);
@@ -529,11 +530,8 @@ var CallForge = class _CallForge {
529
530
  async fetchFromApi(locationId, sessionToken, params) {
530
531
  const controller = new AbortController();
531
532
  const timeoutId = setTimeout(() => controller.abort(), FETCH_TIMEOUT_MS);
532
- let didForceRefreshBootstrap = false;
533
- let usedBootstrapTokenInInitialRequest = false;
534
533
  try {
535
534
  let bootstrapToken = this.getCachedBootstrapToken();
536
- usedBootstrapTokenInInitialRequest = !!bootstrapToken;
537
535
  let response = await fetch(
538
536
  this.buildUrl(locationId, sessionToken, params, bootstrapToken),
539
537
  {
@@ -543,7 +541,6 @@ var CallForge = class _CallForge {
543
541
  );
544
542
  if (response.status === 401) {
545
543
  bootstrapToken = await this.getBootstrapToken(true);
546
- didForceRefreshBootstrap = true;
547
544
  if (bootstrapToken) {
548
545
  response = await fetch(
549
546
  this.buildUrl(locationId, sessionToken, params, bootstrapToken),
@@ -557,24 +554,7 @@ var CallForge = class _CallForge {
557
554
  if (!response.ok) {
558
555
  throw new Error(`API error: ${response.status} ${response.statusText}`);
559
556
  }
560
- let data = await response.json();
561
- if (data.leaseId === null && !usedBootstrapTokenInInitialRequest && !didForceRefreshBootstrap) {
562
- const refreshedBootstrapToken = await this.getBootstrapToken(true);
563
- didForceRefreshBootstrap = true;
564
- if (refreshedBootstrapToken) {
565
- const retryResponse = await fetch(
566
- this.buildUrl(locationId, sessionToken, params, refreshedBootstrapToken),
567
- {
568
- credentials: "omit",
569
- signal: controller.signal
570
- }
571
- );
572
- if (retryResponse.ok) {
573
- data = await retryResponse.json();
574
- }
575
- }
576
- }
577
- return data;
557
+ return await response.json();
578
558
  } finally {
579
559
  clearTimeout(timeoutId);
580
560
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@callforge/tracking-client",
3
- "version": "0.9.2",
3
+ "version": "0.10.1",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/index.mjs",
6
6
  "types": "dist/index.d.ts",