🎩 You're Invited:Meet the Socket team at Black Hat in Las Vegas, August 3-6.RSVP
Sign In

@alore/auth-react-sdk

Package Overview
Dependencies
Maintainers
4
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@alore/auth-react-sdk - npm Package Compare versions

Comparing version
1.1.0-alpha.5
to
1.1.0-alpha.6
+2
-1
dist/utils/AloreAuth.d.ts

@@ -1,2 +0,2 @@

import { AuthMachineContext, AuthProviderConfig, FetchWithProgressiveBackoffConfig, ForgeData } from '../types';
import type { AuthMachineContext, AuthProviderConfig, FetchWithProgressiveBackoffConfig, ForgeData } from '../types';
export declare class AloreAuth {

@@ -269,2 +269,3 @@ protected readonly aloreBaseUrl: string;

private verifyBackendStatus;
private extractErrorInfo;
}

@@ -555,9 +555,35 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {

console.error(error);
if (error instanceof TypeError &&
error.message === 'Failed to fetch' &&
attempt >= maxAttempts) {
console.error('Connection refused, the backend is probably not running.');
this.verifyBackendStatus();
// Treat any fetch TypeError as a network/CORS-style failure. Browsers localize the message.
const isFailedToFetch = error instanceof TypeError;
if (isFailedToFetch && attempt >= maxAttempts) {
// Determine whether backend is down or the request is likely blocked (e.g., CORS)
const origin = typeof window !== 'undefined' ? window.location.origin : undefined;
try {
// eslint-disable-next-line no-await-in-loop
const health = yield this.verifyBackendStatus();
const fullUrl = `${this.aloreBaseUrl}${url}`;
const message = origin
? `Request blocked by CORS policy. Endpoint: ${fullUrl}. Please ensure origin ${origin} is allowed.`
: `Request blocked by CORS policy. Endpoint: ${fullUrl}.`;
const corsErr = new AloreAuthError(ErrorTypes.CORS_BLOCKED, message);
// Preserve original fetch error and health-check details for diagnostics
// @ts-ignore
corsErr.data = {
originalError: this.extractErrorInfo(error),
healthCheck: Object.assign({ reachable: true }, health),
};
throw corsErr;
}
catch (healthError) {
// Backend health-check failed → server likely down/unreachable
const downErr = new AloreAuthError(ErrorTypes.SERVER_DOWN, `Server is unreachable at ${this.aloreBaseUrl}. Please try again later.`);
// @ts-ignore
downErr.data = {
originalError: this.extractErrorInfo(error),
healthCheck: { reachable: false, error: this.extractErrorInfo(healthError) },
};
throw downErr;
}
}
else if (attempt < maxAttempts) {
if (attempt < maxAttempts) {
console.error(`Attempt ${attempt} failed, retrying in ${delayValue}ms...`);

@@ -567,3 +593,4 @@ }

}
throw new Error(`Max attempts (${maxAttempts}) exceeded`);
// Final fallback (should rarely hit due to early throws above)
throw new AloreAuthError(ErrorTypes.FAILED_TO_FETCH, `Max attempts (${maxAttempts}) exceeded while contacting ${this.aloreBaseUrl}${url}`);
});

@@ -573,7 +600,8 @@ }

return __awaiter(this, void 0, void 0, function* () {
const endpoint = '/health/ready';
// eslint-disable-next-line no-undef
const init = { mode: 'no-cors', cache: 'no-store' };
try {
const res = yield fetch(`${this.aloreBaseUrl}/health-check`);
if (!res.ok) {
throw new Error('Failed to fetch');
}
yield fetch(`${this.aloreBaseUrl}${endpoint}`, init);
return { checkedEndpoints: [endpoint] };
}

@@ -585,2 +613,15 @@ catch (_a) {

}
// Capture a concise, serializable snapshot of an unknown error
// eslint-disable-next-line class-methods-use-this
extractErrorInfo(error) {
if (error instanceof Error) {
return { name: error.name, message: error.message, stack: error.stack };
}
try {
return JSON.parse(JSON.stringify(error));
}
catch (_a) {
return { error };
}
}
}

@@ -13,2 +13,3 @@ export declare enum ErrorCodes {

SERVER_DOWN = "SERVER_DOWN",
CORS_BLOCKED = "CORS_BLOCKED",
BAD_RESPONSE = "BAD_RESPONSE",

@@ -15,0 +16,0 @@ UNKNOWN_ERROR = "UNKNOWN_ERROR",

@@ -16,2 +16,3 @@ /* eslint-disable no-unused-vars */

ErrorTypes["SERVER_DOWN"] = "SERVER_DOWN";
ErrorTypes["CORS_BLOCKED"] = "CORS_BLOCKED";
ErrorTypes["BAD_RESPONSE"] = "BAD_RESPONSE";

@@ -18,0 +19,0 @@ ErrorTypes["UNKNOWN_ERROR"] = "UNKNOWN_ERROR";

{
"name": "@alore/auth-react-sdk",
"version": "1.1.0-alpha.5",
"version": "1.1.0-alpha.6",
"repository": "https://github.com/0xCarbon/alore-js",

@@ -5,0 +5,0 @@ "description": "SDK for Alore Auth",