@frontegg/client
Advanced tools
Comparing version 2.0.21 to 2.0.22
@@ -8,3 +8,3 @@ export declare class FronteggAuthenticator { | ||
private shuttingDown; | ||
init(clientId: string, apiKey: string): Promise<void>; | ||
init(clientId: string, apiKey: string): Promise<any>; | ||
refreshAuthentication(): Promise<void>; | ||
@@ -11,0 +11,0 @@ validateAuthentication(): Promise<void>; |
@@ -41,2 +41,3 @@ "use strict"; | ||
var logger_1 = require("../helpers/logger"); | ||
var utils_1 = require("../middleware/utils"); | ||
var FronteggAuthenticator = /** @class */ (function () { | ||
@@ -53,6 +54,22 @@ function FronteggAuthenticator() { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var numberOfTries; | ||
var _this = this; | ||
return __generator(this, function (_a) { | ||
this.clientId = clientId; | ||
this.apiKey = apiKey; | ||
return [2 /*return*/, this.authenticate()]; | ||
numberOfTries = 3; | ||
if (process.env.FRONTEGG_AUTHENTICATOR_NUMBER_OF_TRIES) { | ||
if (isNaN(+(process.env.FRONTEGG_AUTHENTICATOR_NUMBER_OF_TRIES))) { | ||
logger_1.default.error('got invalid value for FRONTEGG_AUTHENTICATOR_NUMBER_OF_TRIES'); | ||
} | ||
else { | ||
numberOfTries = +(process.env.FRONTEGG_AUTHENTICATOR_NUMBER_OF_TRIES); | ||
} | ||
} | ||
return [2 /*return*/, utils_1.retry(function () { return _this.authenticate(); }, { | ||
numberOfTries: numberOfTries, | ||
secondsDelayRange: { | ||
min: 0.5, max: 5 | ||
} | ||
})]; | ||
}); | ||
@@ -59,0 +76,0 @@ }); |
@@ -12,1 +12,10 @@ /// <reference types="node" /> | ||
export declare function callMiddleware(req: any, res: any, middleware: any): Promise<void>; | ||
interface RetryOptions { | ||
numberOfTries: number; | ||
secondsDelayRange: { | ||
min: number; | ||
max: number; | ||
}; | ||
} | ||
export declare const retry: (func: Function, { numberOfTries, secondsDelayRange }: RetryOptions) => any; | ||
export {}; |
@@ -37,2 +37,3 @@ "use strict"; | ||
}; | ||
var _this = this; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -191,2 +192,32 @@ var logger_1 = require("../helpers/logger"); | ||
exports.callMiddleware = callMiddleware; | ||
exports.retry = function (func, _a) { | ||
var numberOfTries = _a.numberOfTries, secondsDelayRange = _a.secondsDelayRange; | ||
return __awaiter(_this, void 0, void 0, function () { | ||
var res, error_1, delayTime; | ||
return __generator(this, function (_b) { | ||
switch (_b.label) { | ||
case 0: | ||
_b.trys.push([0, 2, , 4]); | ||
return [4 /*yield*/, func()]; | ||
case 1: | ||
res = _b.sent(); | ||
return [2 /*return*/, res]; | ||
case 2: | ||
error_1 = _b.sent(); | ||
logger_1.default.debug("Failed, remaining tries: " + (numberOfTries - 1)); | ||
if (numberOfTries === 1) { | ||
throw error_1; | ||
} | ||
delayTime = Math.floor(Math.random() * (secondsDelayRange.max - secondsDelayRange.min + 1)) + secondsDelayRange.min; | ||
logger_1.default.debug("trying again in " + delayTime + " seconds"); | ||
return [4 /*yield*/, delay(delayTime * 1000)]; | ||
case 3: | ||
_b.sent(); | ||
return [2 /*return*/, exports.retry(func, { numberOfTries: numberOfTries - 1, secondsDelayRange: secondsDelayRange })]; | ||
case 4: return [2 /*return*/]; | ||
} | ||
}); | ||
}); | ||
}; | ||
var delay = function (ms) { return new Promise(function (resolve) { return setTimeout(resolve, ms); }); }; | ||
//# sourceMappingURL=utils.js.map |
{ | ||
"name": "@frontegg/client", | ||
"version": "2.0.21", | ||
"version": "2.0.22", | ||
"description": "Frontegg Javascript Library for backend", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
260571
3827
8