forked from Yara724/api
Enforce claim beneficiary access and retire unused legacy APIs
This commit is contained in:
@@ -58,7 +58,10 @@ export class FanavaranAuthService {
|
||||
*/
|
||||
static readonly TOKEN_TIME_ZONE = "Asia/Tehran";
|
||||
|
||||
private readonly tokenCache = new Map<FanavaranClientKey, CachedFanavaranAuth>();
|
||||
private readonly tokenCache = new Map<
|
||||
FanavaranClientKey,
|
||||
CachedFanavaranAuth
|
||||
>();
|
||||
private readonly inflightLogin = new Map<
|
||||
FanavaranClientKey,
|
||||
Promise<string>
|
||||
@@ -94,12 +97,7 @@ export class FanavaranAuthService {
|
||||
| string
|
||||
| undefined;
|
||||
if (typeof data === "string") return data;
|
||||
return (
|
||||
data?.Message ||
|
||||
data?.message ||
|
||||
errorOrMessage.message ||
|
||||
""
|
||||
);
|
||||
return data?.Message || data?.message || errorOrMessage.message || "";
|
||||
}
|
||||
if (errorOrMessage instanceof Error) return errorOrMessage.message;
|
||||
return errorOrMessage == null ? "" : String(errorOrMessage);
|
||||
@@ -145,10 +143,6 @@ export class FanavaranAuthService {
|
||||
return Math.max(0, state.until - Date.now());
|
||||
}
|
||||
|
||||
isInBackoff(clientKey: FanavaranClientKey): boolean {
|
||||
return this.getBackoffRemainingMs(clientKey) > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Call after any Fanavaran HTTP failure. Sets a tenant-wide pause when the
|
||||
* error is the familiar “try again later” overload response.
|
||||
@@ -172,12 +166,15 @@ export class FanavaranAuthService {
|
||||
|
||||
invalidateToken(clientKey: FanavaranClientKey): void {
|
||||
this.tokenCache.delete(clientKey);
|
||||
void this.authTokenModel.deleteOne({ clientKey }).exec().catch((error) => {
|
||||
this.logger.warn(
|
||||
`[${clientKey}] Failed to clear persisted Fanavaran auth token`,
|
||||
error,
|
||||
);
|
||||
});
|
||||
void this.authTokenModel
|
||||
.deleteOne({ clientKey })
|
||||
.exec()
|
||||
.catch((error) => {
|
||||
this.logger.warn(
|
||||
`[${clientKey}] Failed to clear persisted Fanavaran auth token`,
|
||||
error,
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -331,7 +328,10 @@ export class FanavaranAuthService {
|
||||
fingerprint: string,
|
||||
): Promise<string | null> {
|
||||
try {
|
||||
const doc = await this.authTokenModel.findOne({ clientKey }).lean().exec();
|
||||
const doc = await this.authTokenModel
|
||||
.findOne({ clientKey })
|
||||
.lean()
|
||||
.exec();
|
||||
if (!doc?.authenticationToken || !doc.expiresAt) {
|
||||
return null;
|
||||
}
|
||||
@@ -454,11 +454,10 @@ export class FanavaranAuthService {
|
||||
}
|
||||
|
||||
if (auditSession) {
|
||||
const exchange =
|
||||
this.fanavaranAuditService.captureAxiosExchange(
|
||||
response,
|
||||
requestHeaders,
|
||||
);
|
||||
const exchange = this.fanavaranAuditService.captureAxiosExchange(
|
||||
response,
|
||||
requestHeaders,
|
||||
);
|
||||
await this.fanavaranAuditService.recordStep({
|
||||
session: auditSession,
|
||||
step: FanavaranAuditStep.GET_APP_TOKEN,
|
||||
@@ -498,7 +497,11 @@ export class FanavaranAuthService {
|
||||
durationMs: Date.now() - startedAt,
|
||||
});
|
||||
}
|
||||
throw this.toGatewayError(error, "Failed to get appToken from external API", auditSession);
|
||||
throw this.toGatewayError(
|
||||
error,
|
||||
"Failed to get appToken from external API",
|
||||
auditSession,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -551,11 +554,10 @@ export class FanavaranAuthService {
|
||||
}
|
||||
|
||||
if (auditSession) {
|
||||
const exchange =
|
||||
this.fanavaranAuditService.captureAxiosExchange(
|
||||
response,
|
||||
requestHeaders,
|
||||
);
|
||||
const exchange = this.fanavaranAuditService.captureAxiosExchange(
|
||||
response,
|
||||
requestHeaders,
|
||||
);
|
||||
await this.fanavaranAuditService.recordStep({
|
||||
session: auditSession,
|
||||
step: FanavaranAuditStep.LOGIN,
|
||||
@@ -598,7 +600,11 @@ export class FanavaranAuthService {
|
||||
durationMs: Date.now() - startedAt,
|
||||
});
|
||||
}
|
||||
throw this.toGatewayError(error, "Failed to login to external API", auditSession);
|
||||
throw this.toGatewayError(
|
||||
error,
|
||||
"Failed to login to external API",
|
||||
auditSession,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user