@callforge/tracking-client 0.9.1 → 0.9.2
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 +22 -1
- package/dist/index.mjs +22 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -553,8 +553,11 @@ var CallForge = class _CallForge {
|
|
|
553
553
|
async fetchFromApi(locationId, sessionToken, params) {
|
|
554
554
|
const controller = new AbortController();
|
|
555
555
|
const timeoutId = setTimeout(() => controller.abort(), FETCH_TIMEOUT_MS);
|
|
556
|
+
let didForceRefreshBootstrap = false;
|
|
557
|
+
let usedBootstrapTokenInInitialRequest = false;
|
|
556
558
|
try {
|
|
557
559
|
let bootstrapToken = this.getCachedBootstrapToken();
|
|
560
|
+
usedBootstrapTokenInInitialRequest = !!bootstrapToken;
|
|
558
561
|
let response = await fetch(
|
|
559
562
|
this.buildUrl(locationId, sessionToken, params, bootstrapToken),
|
|
560
563
|
{
|
|
@@ -564,6 +567,7 @@ var CallForge = class _CallForge {
|
|
|
564
567
|
);
|
|
565
568
|
if (response.status === 401) {
|
|
566
569
|
bootstrapToken = await this.getBootstrapToken(true);
|
|
570
|
+
didForceRefreshBootstrap = true;
|
|
567
571
|
if (bootstrapToken) {
|
|
568
572
|
response = await fetch(
|
|
569
573
|
this.buildUrl(locationId, sessionToken, params, bootstrapToken),
|
|
@@ -577,7 +581,24 @@ var CallForge = class _CallForge {
|
|
|
577
581
|
if (!response.ok) {
|
|
578
582
|
throw new Error(`API error: ${response.status} ${response.statusText}`);
|
|
579
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
602
|
} finally {
|
|
582
603
|
clearTimeout(timeoutId);
|
|
583
604
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -529,8 +529,11 @@ var CallForge = class _CallForge {
|
|
|
529
529
|
async fetchFromApi(locationId, sessionToken, params) {
|
|
530
530
|
const controller = new AbortController();
|
|
531
531
|
const timeoutId = setTimeout(() => controller.abort(), FETCH_TIMEOUT_MS);
|
|
532
|
+
let didForceRefreshBootstrap = false;
|
|
533
|
+
let usedBootstrapTokenInInitialRequest = false;
|
|
532
534
|
try {
|
|
533
535
|
let bootstrapToken = this.getCachedBootstrapToken();
|
|
536
|
+
usedBootstrapTokenInInitialRequest = !!bootstrapToken;
|
|
534
537
|
let response = await fetch(
|
|
535
538
|
this.buildUrl(locationId, sessionToken, params, bootstrapToken),
|
|
536
539
|
{
|
|
@@ -540,6 +543,7 @@ var CallForge = class _CallForge {
|
|
|
540
543
|
);
|
|
541
544
|
if (response.status === 401) {
|
|
542
545
|
bootstrapToken = await this.getBootstrapToken(true);
|
|
546
|
+
didForceRefreshBootstrap = true;
|
|
543
547
|
if (bootstrapToken) {
|
|
544
548
|
response = await fetch(
|
|
545
549
|
this.buildUrl(locationId, sessionToken, params, bootstrapToken),
|
|
@@ -553,7 +557,24 @@ var CallForge = class _CallForge {
|
|
|
553
557
|
if (!response.ok) {
|
|
554
558
|
throw new Error(`API error: ${response.status} ${response.statusText}`);
|
|
555
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
578
|
} finally {
|
|
558
579
|
clearTimeout(timeoutId);
|
|
559
580
|
}
|