@insforge/sdk 1.0.1-refresh.1 → 1.0.1-refresh.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.d.mts +5 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +37 -5
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +37 -5
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -340,6 +340,11 @@ declare class Auth {
|
|
|
340
340
|
private database;
|
|
341
341
|
private initPromise;
|
|
342
342
|
constructor(http: HttpClient, tokenManager: TokenManager);
|
|
343
|
+
/**
|
|
344
|
+
* Check if an error represents an authentication failure
|
|
345
|
+
* Used to determine appropriate HTTP status code (401 vs 500)
|
|
346
|
+
*/
|
|
347
|
+
private isAuthenticationError;
|
|
343
348
|
/**
|
|
344
349
|
* Set the initialization promise that auth operations should wait for
|
|
345
350
|
* This ensures TokenManager mode is set before any auth operations
|
package/dist/index.d.ts
CHANGED
|
@@ -340,6 +340,11 @@ declare class Auth {
|
|
|
340
340
|
private database;
|
|
341
341
|
private initPromise;
|
|
342
342
|
constructor(http: HttpClient, tokenManager: TokenManager);
|
|
343
|
+
/**
|
|
344
|
+
* Check if an error represents an authentication failure
|
|
345
|
+
* Used to determine appropriate HTTP status code (401 vs 500)
|
|
346
|
+
*/
|
|
347
|
+
private isAuthenticationError;
|
|
343
348
|
/**
|
|
344
349
|
* Set the initialization promise that auth operations should wait for
|
|
345
350
|
* This ensures TokenManager mode is set before any auth operations
|
package/dist/index.js
CHANGED
|
@@ -182,9 +182,11 @@ var HttpClient = class {
|
|
|
182
182
|
this.isRefreshing = true;
|
|
183
183
|
try {
|
|
184
184
|
const newToken = await this.refreshCallback();
|
|
185
|
-
this.refreshQueue.forEach(({ resolve }) => {
|
|
185
|
+
this.refreshQueue.forEach(({ resolve, reject }) => {
|
|
186
186
|
if (newToken) {
|
|
187
187
|
resolve(newToken);
|
|
188
|
+
} else {
|
|
189
|
+
reject(new Error("Token refresh failed"));
|
|
188
190
|
}
|
|
189
191
|
});
|
|
190
192
|
this.refreshQueue = [];
|
|
@@ -575,6 +577,28 @@ var Auth = class {
|
|
|
575
577
|
this.initPromise = null;
|
|
576
578
|
this.database = new Database(http, tokenManager);
|
|
577
579
|
}
|
|
580
|
+
/**
|
|
581
|
+
* Check if an error represents an authentication failure
|
|
582
|
+
* Used to determine appropriate HTTP status code (401 vs 500)
|
|
583
|
+
*/
|
|
584
|
+
isAuthenticationError(error) {
|
|
585
|
+
if (error instanceof Error) {
|
|
586
|
+
const message = error.message.toLowerCase();
|
|
587
|
+
const authKeywords = [
|
|
588
|
+
"unauthorized",
|
|
589
|
+
"invalid token",
|
|
590
|
+
"expired token",
|
|
591
|
+
"token expired",
|
|
592
|
+
"invalid refresh token",
|
|
593
|
+
"refresh token",
|
|
594
|
+
"authentication",
|
|
595
|
+
"not authenticated",
|
|
596
|
+
"session expired"
|
|
597
|
+
];
|
|
598
|
+
return authKeywords.some((keyword) => message.includes(keyword));
|
|
599
|
+
}
|
|
600
|
+
return false;
|
|
601
|
+
}
|
|
578
602
|
/**
|
|
579
603
|
* Set the initialization promise that auth operations should wait for
|
|
580
604
|
* This ensures TokenManager mode is set before any auth operations
|
|
@@ -793,14 +817,22 @@ var Auth = class {
|
|
|
793
817
|
"REFRESH_FAILED"
|
|
794
818
|
);
|
|
795
819
|
} catch (error) {
|
|
796
|
-
this.tokenManager.clearSession();
|
|
797
|
-
this.http.setAuthToken(null);
|
|
798
820
|
if (error instanceof InsForgeError) {
|
|
821
|
+
if (error.statusCode === 401 || error.statusCode === 403) {
|
|
822
|
+
this.tokenManager.clearSession();
|
|
823
|
+
this.http.setAuthToken(null);
|
|
824
|
+
}
|
|
799
825
|
throw error;
|
|
800
826
|
}
|
|
827
|
+
const errorMessage = error instanceof Error ? error.message : "Token refresh failed";
|
|
828
|
+
const isAuthError = this.isAuthenticationError(error);
|
|
829
|
+
if (isAuthError) {
|
|
830
|
+
this.tokenManager.clearSession();
|
|
831
|
+
this.http.setAuthToken(null);
|
|
832
|
+
}
|
|
801
833
|
throw new InsForgeError(
|
|
802
|
-
|
|
803
|
-
401,
|
|
834
|
+
errorMessage,
|
|
835
|
+
isAuthError ? 401 : 500,
|
|
804
836
|
"REFRESH_FAILED"
|
|
805
837
|
);
|
|
806
838
|
}
|