forked from Shared/esg
Add health check and retry logic and circuit breaker
This commit is contained in:
@@ -21,6 +21,7 @@ import { withRetry } from '../../common/helpers/retry.helper';
|
||||
import { AmitisAuthServiceConfig } from '../../config/configuration';
|
||||
import { GeneralTokenDocument } from '../schemas/general-token.schema';
|
||||
import { GeneralTokenService } from '../services/general-token.service';
|
||||
import { DistributedLockService } from '../services/distributed-lock.service';
|
||||
|
||||
interface CentInsurTokenResponse {
|
||||
Token?: string;
|
||||
@@ -64,6 +65,7 @@ export class AmitisProvider {
|
||||
constructor(
|
||||
configService: ConfigService,
|
||||
private readonly generalTokenService: GeneralTokenService,
|
||||
private readonly distributedLockService: DistributedLockService,
|
||||
) {
|
||||
this.config = configService.get<AmitisAuthServiceConfig>('amitis')!;
|
||||
this.httpClient = createOutboundAxiosInstance({
|
||||
@@ -87,6 +89,7 @@ export class AmitisProvider {
|
||||
inquiryType: InquiryType,
|
||||
username: string,
|
||||
password: string,
|
||||
signal?: AbortSignal,
|
||||
): Promise<string> {
|
||||
const tokenKey = this.getTokenKey(providerName, inquiryType);
|
||||
const latestToken = await this.generalTokenService.getLatestToken(tokenKey);
|
||||
@@ -96,21 +99,30 @@ export class AmitisProvider {
|
||||
return latestToken.accessToken;
|
||||
}
|
||||
|
||||
// Try to refresh if we have a refresh token and it's within 24 hours
|
||||
if (latestToken?.refreshToken && this.isWithin24Hours(latestToken)) {
|
||||
try {
|
||||
return await this.refreshAccessToken(latestToken, providerName, inquiryType);
|
||||
} catch (error) {
|
||||
this.logger.warn(
|
||||
`AMITIS token refresh failed for ${providerName}/${inquiryType}, requesting a new token: ${
|
||||
error instanceof Error ? error.message : String(error)
|
||||
}`,
|
||||
);
|
||||
}
|
||||
}
|
||||
return this.distributedLockService.withLock(
|
||||
`provider-token:${tokenKey}`,
|
||||
async () => {
|
||||
const current = await this.generalTokenService.getLatestToken(tokenKey);
|
||||
if (current && !this.isExpired(current) && this.isWithin24Hours(current)) {
|
||||
return current.accessToken;
|
||||
}
|
||||
|
||||
// Login to get new token
|
||||
return this.login(providerName, inquiryType, username, password);
|
||||
if (current?.refreshToken && this.isWithin24Hours(current)) {
|
||||
try {
|
||||
return await this.refreshAccessToken(current, providerName, inquiryType, signal);
|
||||
} catch (error) {
|
||||
this.logger.warn(
|
||||
`AMITIS token refresh failed for ${providerName}/${inquiryType}, requesting a new token: ${
|
||||
error instanceof Error ? error.message : String(error)
|
||||
}`,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return this.login(providerName, inquiryType, username, password, signal);
|
||||
},
|
||||
{ signal },
|
||||
);
|
||||
}
|
||||
|
||||
private async login(
|
||||
@@ -118,6 +130,7 @@ export class AmitisProvider {
|
||||
inquiryType: InquiryType,
|
||||
username: string,
|
||||
password: string,
|
||||
signal?: AbortSignal,
|
||||
): Promise<string> {
|
||||
const loginBody = new URLSearchParams({
|
||||
username: username.toLowerCase(),
|
||||
@@ -138,6 +151,7 @@ export class AmitisProvider {
|
||||
headers: {
|
||||
'Content-Type': 'application/x-www-form-urlencoded',
|
||||
},
|
||||
signal,
|
||||
},
|
||||
),
|
||||
);
|
||||
@@ -161,13 +175,14 @@ export class AmitisProvider {
|
||||
latestToken: GeneralTokenDocument,
|
||||
providerName: ProviderName,
|
||||
inquiryType: InquiryType,
|
||||
signal?: AbortSignal,
|
||||
): Promise<string> {
|
||||
try {
|
||||
const response = await this.withGentleAuthRetry(() =>
|
||||
this.httpClient.post<CentInsurTokenResponse>(this.config.refreshPath, {
|
||||
Token: latestToken.accessToken,
|
||||
RefreshToken: latestToken.refreshToken,
|
||||
}),
|
||||
}, { signal }),
|
||||
);
|
||||
const token = this.extractToken(response.data, latestToken.refreshToken);
|
||||
|
||||
|
||||
@@ -88,25 +88,25 @@ export class HamtaProvider extends LegacyApiProvider {
|
||||
context: ProviderExecutionContext,
|
||||
): Promise<LegacyInquiryResult> {
|
||||
if (inquiryType === InquiryType.PERSON) {
|
||||
return this.inquireCivilRegistration(payload as CivilRegistrationPayload);
|
||||
return this.inquireCivilRegistration(payload as CivilRegistrationPayload, context.signal);
|
||||
}
|
||||
|
||||
if (inquiryType === InquiryType.POSTAL_CODE) {
|
||||
return this.inquirePostalCode(payload as PostalCodePayload);
|
||||
return this.inquirePostalCode(payload as PostalCodePayload, context.signal);
|
||||
}
|
||||
|
||||
if (inquiryType === InquiryType.SHAHKAR) {
|
||||
return this.inquireShahkar(payload as ShahkarPayload);
|
||||
return this.inquireShahkar(payload as ShahkarPayload, context.signal);
|
||||
}
|
||||
|
||||
if (inquiryType === InquiryType.SHEBA) {
|
||||
return this.inquireSayah(payload as SayahPayload);
|
||||
return this.inquireSayah(payload as SayahPayload, context.signal);
|
||||
}
|
||||
|
||||
return super.callProvider(inquiryType, payload, context);
|
||||
}
|
||||
|
||||
private async inquirePostalCode(payload: PostalCodePayload): Promise<{ raw: unknown }> {
|
||||
private async inquirePostalCode(payload: PostalCodePayload, signal?: AbortSignal): Promise<{ raw: unknown }> {
|
||||
const postalCode = this.getRequiredString(
|
||||
payload.postalCode ?? payload.PostalCode,
|
||||
'postalCode',
|
||||
@@ -119,6 +119,7 @@ export class HamtaProvider extends LegacyApiProvider {
|
||||
InquiryType.POSTAL_CODE,
|
||||
inquiryConfig.username,
|
||||
inquiryConfig.password,
|
||||
signal,
|
||||
);
|
||||
|
||||
try {
|
||||
@@ -128,6 +129,7 @@ export class HamtaProvider extends LegacyApiProvider {
|
||||
params: { PostalCode: postalCode },
|
||||
headers: { Authorization: `Bearer ${token}` },
|
||||
timeout: this.hamtaConfig.timeout,
|
||||
signal,
|
||||
}),
|
||||
);
|
||||
|
||||
@@ -145,6 +147,7 @@ export class HamtaProvider extends LegacyApiProvider {
|
||||
|
||||
private async inquireCivilRegistration(
|
||||
payload: CivilRegistrationPayload,
|
||||
signal?: AbortSignal,
|
||||
): Promise<PersonInquiryResult> {
|
||||
const nationalCode = this.getRequiredString(
|
||||
payload.nationalCode ?? payload.NIN,
|
||||
@@ -171,6 +174,7 @@ export class HamtaProvider extends LegacyApiProvider {
|
||||
},
|
||||
timeout: this.hamtaConfig.timeout,
|
||||
responseType: 'text',
|
||||
signal,
|
||||
}),
|
||||
);
|
||||
|
||||
@@ -196,7 +200,7 @@ export class HamtaProvider extends LegacyApiProvider {
|
||||
}
|
||||
}
|
||||
|
||||
private async inquireShahkar(payload: ShahkarPayload): Promise<{ raw: unknown }> {
|
||||
private async inquireShahkar(payload: ShahkarPayload, signal?: AbortSignal): Promise<{ raw: unknown }> {
|
||||
const nationalCode = this.getRequiredString(
|
||||
payload.nationalCode ?? payload.nationalCod ?? payload.NationalCod,
|
||||
'nationalCode',
|
||||
@@ -221,6 +225,7 @@ export class HamtaProvider extends LegacyApiProvider {
|
||||
},
|
||||
timeout: this.hamtaConfig.timeout,
|
||||
responseType: 'text',
|
||||
signal,
|
||||
}),
|
||||
);
|
||||
|
||||
@@ -253,7 +258,7 @@ export class HamtaProvider extends LegacyApiProvider {
|
||||
}
|
||||
}
|
||||
|
||||
private async inquireSayah(payload: SayahPayload): Promise<{ raw: unknown }> {
|
||||
private async inquireSayah(payload: SayahPayload, signal?: AbortSignal): Promise<{ raw: unknown }> {
|
||||
const accountOwnerType = payload.accountOwnerType ?? '1';
|
||||
const nationalId = payload.nationalCode ?? '';
|
||||
const legalId = payload.legalId ?? null;
|
||||
@@ -266,6 +271,7 @@ export class HamtaProvider extends LegacyApiProvider {
|
||||
InquiryType.SHEBA,
|
||||
inquiryConfig.username,
|
||||
inquiryConfig.password,
|
||||
signal,
|
||||
);
|
||||
|
||||
try {
|
||||
@@ -283,6 +289,7 @@ export class HamtaProvider extends LegacyApiProvider {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
timeout: this.hamtaConfig.timeout,
|
||||
signal,
|
||||
}),
|
||||
);
|
||||
|
||||
|
||||
@@ -100,19 +100,19 @@ export class MoallemProvider extends LegacyApiProvider {
|
||||
context: ProviderExecutionContext,
|
||||
): Promise<LegacyInquiryResult> {
|
||||
if (inquiryType === InquiryType.PERSON) {
|
||||
return this.inquireCivilRegistration(payload as CivilRegistrationPayload);
|
||||
return this.inquireCivilRegistration(payload as CivilRegistrationPayload, context.signal);
|
||||
}
|
||||
|
||||
if (inquiryType === InquiryType.POSTAL_CODE) {
|
||||
return this.inquirePostalCode(payload as PostalCodePayload);
|
||||
return this.inquirePostalCode(payload as PostalCodePayload, context.signal);
|
||||
}
|
||||
|
||||
if (inquiryType === InquiryType.SHAHKAR) {
|
||||
return this.inquireShahkar(payload as ShahkarPayload);
|
||||
return this.inquireShahkar(payload as ShahkarPayload, context.signal);
|
||||
}
|
||||
|
||||
if (inquiryType === InquiryType.SHEBA) {
|
||||
return this.inquireSayah(payload as SayahPayload);
|
||||
return this.inquireSayah(payload as SayahPayload, context.signal);
|
||||
}
|
||||
|
||||
if (inquiryType === InquiryType.CAR_BY_PLATE) {
|
||||
@@ -121,6 +121,7 @@ export class MoallemProvider extends LegacyApiProvider {
|
||||
payload as CarPlatePayload,
|
||||
(message, code, fallback, extras) =>
|
||||
this.formatProviderError(message, code, fallback, extras as never),
|
||||
context.signal,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -130,6 +131,7 @@ export class MoallemProvider extends LegacyApiProvider {
|
||||
payload as CarChassisPayload,
|
||||
(message, code, fallback, extras) =>
|
||||
this.formatProviderError(message, code, fallback, extras as never),
|
||||
context.signal,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -139,13 +141,14 @@ export class MoallemProvider extends LegacyApiProvider {
|
||||
payload as CarPlatePayload,
|
||||
(message, code, fallback, extras) =>
|
||||
this.formatProviderError(message, code, fallback, extras as never),
|
||||
context.signal,
|
||||
);
|
||||
}
|
||||
|
||||
return super.callProvider(inquiryType, payload, context);
|
||||
}
|
||||
|
||||
private async inquirePostalCode(payload: PostalCodePayload): Promise<{ raw: unknown }> {
|
||||
private async inquirePostalCode(payload: PostalCodePayload, signal?: AbortSignal): Promise<{ raw: unknown }> {
|
||||
const postalCode = this.getRequiredString(
|
||||
payload.postalCode ?? payload.PostalCode,
|
||||
'postalCode',
|
||||
@@ -157,6 +160,7 @@ export class MoallemProvider extends LegacyApiProvider {
|
||||
InquiryType.POSTAL_CODE,
|
||||
inquiryConfig.username,
|
||||
inquiryConfig.password,
|
||||
signal,
|
||||
);
|
||||
|
||||
try {
|
||||
@@ -166,6 +170,7 @@ export class MoallemProvider extends LegacyApiProvider {
|
||||
params: { PostalCode: postalCode },
|
||||
headers: { Authorization: `Bearer ${token}` },
|
||||
timeout: this.moallemConfig.timeout,
|
||||
signal,
|
||||
}),
|
||||
);
|
||||
|
||||
@@ -183,6 +188,7 @@ export class MoallemProvider extends LegacyApiProvider {
|
||||
|
||||
private async inquireCivilRegistration(
|
||||
payload: CivilRegistrationPayload,
|
||||
signal?: AbortSignal,
|
||||
): Promise<PersonInquiryResult> {
|
||||
const nationalCode = this.getRequiredString(
|
||||
payload.nationalCode ?? payload.NIN,
|
||||
@@ -209,6 +215,7 @@ export class MoallemProvider extends LegacyApiProvider {
|
||||
},
|
||||
timeout: this.moallemConfig.timeout,
|
||||
responseType: 'text',
|
||||
signal,
|
||||
}),
|
||||
);
|
||||
|
||||
@@ -234,7 +241,7 @@ export class MoallemProvider extends LegacyApiProvider {
|
||||
}
|
||||
}
|
||||
|
||||
private async inquireShahkar(payload: ShahkarPayload): Promise<{ raw: unknown }> {
|
||||
private async inquireShahkar(payload: ShahkarPayload, signal?: AbortSignal): Promise<{ raw: unknown }> {
|
||||
const nationalCode = this.getRequiredString(
|
||||
payload.nationalCode ?? payload.nationalCod ?? payload.NationalCod,
|
||||
'nationalCode',
|
||||
@@ -259,6 +266,7 @@ export class MoallemProvider extends LegacyApiProvider {
|
||||
},
|
||||
timeout: this.moallemConfig.timeout,
|
||||
responseType: 'text',
|
||||
signal,
|
||||
}),
|
||||
);
|
||||
|
||||
@@ -291,7 +299,7 @@ export class MoallemProvider extends LegacyApiProvider {
|
||||
}
|
||||
}
|
||||
|
||||
private async inquireSayah(payload: SayahPayload): Promise<{ raw: unknown }> {
|
||||
private async inquireSayah(payload: SayahPayload, signal?: AbortSignal): Promise<{ raw: unknown }> {
|
||||
const accountOwnerType = payload.accountOwnerType ?? '1';
|
||||
const nationalId = payload.nationalCode ?? '';
|
||||
const legalId = payload.legalId ?? null;
|
||||
@@ -303,6 +311,7 @@ export class MoallemProvider extends LegacyApiProvider {
|
||||
InquiryType.SHEBA,
|
||||
inquiryConfig.username,
|
||||
inquiryConfig.password,
|
||||
signal,
|
||||
);
|
||||
|
||||
try {
|
||||
@@ -320,6 +329,7 @@ export class MoallemProvider extends LegacyApiProvider {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
timeout: this.moallemConfig.timeout,
|
||||
signal,
|
||||
}),
|
||||
);
|
||||
|
||||
|
||||
@@ -144,18 +144,18 @@ export class ParsianProvider extends BaseProvider<LegacyInquiryPayload, LegacyIn
|
||||
protected async callProvider(
|
||||
inquiryType: InquiryType,
|
||||
payload: LegacyInquiryPayload,
|
||||
_context: ProviderExecutionContext,
|
||||
context: ProviderExecutionContext,
|
||||
): Promise<LegacyInquiryResult> {
|
||||
if (inquiryType === InquiryType.PERSON) {
|
||||
return this.inquireCivilRegistration(payload as ParsianCivilRegistrationPayload);
|
||||
return this.inquireCivilRegistration(payload as ParsianCivilRegistrationPayload, context.signal);
|
||||
}
|
||||
|
||||
if (inquiryType === InquiryType.SHAHKAR) {
|
||||
return this.inquireShahkar(payload as ParsianShahkarPayload);
|
||||
return this.inquireShahkar(payload as ParsianShahkarPayload, context.signal);
|
||||
}
|
||||
|
||||
if (inquiryType === InquiryType.SHEBA) {
|
||||
return this.inquireSayah(payload as ParsianSayahPayload);
|
||||
return this.inquireSayah(payload as ParsianSayahPayload, context.signal);
|
||||
}
|
||||
|
||||
if (inquiryType === InquiryType.CAR_BY_PLATE) {
|
||||
@@ -164,6 +164,7 @@ export class ParsianProvider extends BaseProvider<LegacyInquiryPayload, LegacyIn
|
||||
payload as CarPlatePayload,
|
||||
(message, code, fallback, extras) =>
|
||||
this.formatProviderError(message, code, fallback, extras as never),
|
||||
context.signal,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -173,28 +174,33 @@ export class ParsianProvider extends BaseProvider<LegacyInquiryPayload, LegacyIn
|
||||
payload as CarChassisPayload,
|
||||
(message, code, fallback, extras) =>
|
||||
this.formatProviderError(message, code, fallback, extras as never),
|
||||
context.signal,
|
||||
);
|
||||
}
|
||||
|
||||
if (inquiryType === InquiryType.THIRD_PARTY_CAR) {
|
||||
return this.centInsurCarSupport.inquireThirdPartyCar(
|
||||
// Parsian third-party plate inquiries must use the one-factor plate
|
||||
// lookup. The national-code policy endpoint is not a substitute: it
|
||||
// can return a different vehicle/policy and creates false matches.
|
||||
return this.centInsurCarSupport.inquireCarByPlate(
|
||||
this.config,
|
||||
payload as CarPlatePayload,
|
||||
(message, code, fallback, extras) =>
|
||||
this.formatProviderError(message, code, fallback, extras as never),
|
||||
context.signal,
|
||||
);
|
||||
}
|
||||
|
||||
if (inquiryType === InquiryType.POLICY_BY_CHASSIS) {
|
||||
return this.inquirePolicyByChassis(payload as ParsianPolicyByChassisPayload);
|
||||
return this.inquirePolicyByChassis(payload as ParsianPolicyByChassisPayload, context.signal);
|
||||
}
|
||||
|
||||
if (inquiryType === InquiryType.POLICY_BY_PLATE) {
|
||||
return this.inquirePolicyByPlate(payload as ParsianPolicyByPlatePayload);
|
||||
return this.inquirePolicyByPlate(payload as ParsianPolicyByPlatePayload, context.signal);
|
||||
}
|
||||
|
||||
if (inquiryType === InquiryType.POLICY_BY_NATIONAL_CODE) {
|
||||
return this.inquirePolicyByNationalCode(payload as ParsianPolicyByNationalCodePayload);
|
||||
return this.inquirePolicyByNationalCode(payload as ParsianPolicyByNationalCodePayload, context.signal);
|
||||
}
|
||||
|
||||
throw this.formatProviderError(
|
||||
@@ -204,7 +210,7 @@ export class ParsianProvider extends BaseProvider<LegacyInquiryPayload, LegacyIn
|
||||
);
|
||||
}
|
||||
|
||||
private async inquireShahkar(payload: ParsianShahkarPayload): Promise<{ raw: unknown }> {
|
||||
private async inquireShahkar(payload: ParsianShahkarPayload, signal?: AbortSignal): Promise<{ raw: unknown }> {
|
||||
const nationalCode = this.getRequiredString(
|
||||
payload.nationalCode ?? payload.nationalCod ?? payload.NationalCod,
|
||||
'nationalCode',
|
||||
@@ -236,6 +242,7 @@ export class ParsianProvider extends BaseProvider<LegacyInquiryPayload, LegacyIn
|
||||
'X-PACKAGE-API-KEY': inquiryConfig.apiKey,
|
||||
},
|
||||
timeout: this.config.timeout,
|
||||
signal,
|
||||
}),
|
||||
);
|
||||
|
||||
@@ -274,6 +281,7 @@ export class ParsianProvider extends BaseProvider<LegacyInquiryPayload, LegacyIn
|
||||
|
||||
private async inquireCivilRegistration(
|
||||
payload: ParsianCivilRegistrationPayload,
|
||||
signal?: AbortSignal,
|
||||
): Promise<PersonInquiryResult> {
|
||||
const nationalCode = this.getRequiredString(
|
||||
payload.nationalCode ?? payload.NIN,
|
||||
@@ -307,6 +315,7 @@ export class ParsianProvider extends BaseProvider<LegacyInquiryPayload, LegacyIn
|
||||
},
|
||||
timeout: this.config.timeout,
|
||||
responseType: 'text',
|
||||
signal,
|
||||
}),
|
||||
);
|
||||
|
||||
@@ -337,12 +346,14 @@ export class ParsianProvider extends BaseProvider<LegacyInquiryPayload, LegacyIn
|
||||
|
||||
private async inquirePolicyByChassis(
|
||||
payload: ParsianPolicyByChassisPayload,
|
||||
signal?: AbortSignal,
|
||||
): Promise<{ raw: unknown }> {
|
||||
const chassisNo = this.getRequiredString(payload.chassisNo, 'chassisNo');
|
||||
const policy = await this.callCarPolicySoap(
|
||||
InquiryType.POLICY_BY_CHASSIS,
|
||||
'CIIWSPolicyChassis',
|
||||
{ ChassisNo: chassisNo },
|
||||
signal,
|
||||
);
|
||||
|
||||
return {
|
||||
@@ -355,12 +366,14 @@ export class ParsianProvider extends BaseProvider<LegacyInquiryPayload, LegacyIn
|
||||
|
||||
private async inquirePolicyByNationalCode(
|
||||
payload: ParsianPolicyByNationalCodePayload,
|
||||
signal?: AbortSignal,
|
||||
): Promise<{ raw: unknown }> {
|
||||
const nationalCode = this.getRequiredString(payload.nationalCode, 'nationalCode');
|
||||
const policy = await this.callCarPolicySoap(
|
||||
InquiryType.POLICY_BY_NATIONAL_CODE,
|
||||
'CIIWSPolicyNationalId',
|
||||
{ NationalId: nationalCode },
|
||||
signal,
|
||||
);
|
||||
|
||||
return {
|
||||
@@ -373,6 +386,7 @@ export class ParsianProvider extends BaseProvider<LegacyInquiryPayload, LegacyIn
|
||||
|
||||
private async inquirePolicyByPlate(
|
||||
payload: ParsianPolicyByPlatePayload,
|
||||
signal?: AbortSignal,
|
||||
): Promise<{ raw: unknown }> {
|
||||
const nationalCode = this.getRequiredString(payload.nationalCode, 'nationalCode');
|
||||
const plk1 = this.getRequiredString(payload.plk1, 'plk1');
|
||||
@@ -383,6 +397,7 @@ export class ParsianProvider extends BaseProvider<LegacyInquiryPayload, LegacyIn
|
||||
InquiryType.POLICY_BY_PLATE,
|
||||
'CIIWSPolicyVehicleMeli',
|
||||
{ Plk1: plk1, Plk2: plk2, Plk3: plk3, PlkSrl: plksrl },
|
||||
signal,
|
||||
);
|
||||
|
||||
assertCarPolicyOwnedBy(nationalCode, policy, (message, code, fallback, extras) =>
|
||||
@@ -405,6 +420,7 @@ export class ParsianProvider extends BaseProvider<LegacyInquiryPayload, LegacyIn
|
||||
inquiryType: InquiryType,
|
||||
methodName: string,
|
||||
fields: Record<string, string>,
|
||||
signal?: AbortSignal,
|
||||
): Promise<Record<string, string>> {
|
||||
const inquiryConfig = this.config.inquiries[inquiryType];
|
||||
|
||||
@@ -432,13 +448,16 @@ export class ParsianProvider extends BaseProvider<LegacyInquiryPayload, LegacyIn
|
||||
},
|
||||
timeout: this.config.timeout,
|
||||
responseType: 'text',
|
||||
signal,
|
||||
}),
|
||||
);
|
||||
|
||||
const policy = parseFirstCarPolicy(response.data);
|
||||
const providerError = getCarPolicyProviderError(response.data, policy);
|
||||
if (providerError) {
|
||||
throw this.formatProviderError(providerError.message, providerError.code);
|
||||
throw this.formatProviderError(providerError.message, providerError.code, undefined, {
|
||||
providerCode: providerError.providerCode,
|
||||
});
|
||||
}
|
||||
|
||||
return policy;
|
||||
@@ -453,7 +472,7 @@ export class ParsianProvider extends BaseProvider<LegacyInquiryPayload, LegacyIn
|
||||
}
|
||||
}
|
||||
|
||||
private async inquireSayah(payload: ParsianSayahPayload): Promise<{ raw: unknown }> {
|
||||
private async inquireSayah(payload: ParsianSayahPayload, signal?: AbortSignal): Promise<{ raw: unknown }> {
|
||||
const accountOwnerType = payload.accountOwnerType ?? '1';
|
||||
const nationalId = payload.nationalCode ?? '';
|
||||
const legalId = payload.legalId ?? null;
|
||||
@@ -473,6 +492,7 @@ export class ParsianProvider extends BaseProvider<LegacyInquiryPayload, LegacyIn
|
||||
InquiryType.SHEBA,
|
||||
inquiryConfig.username,
|
||||
inquiryConfig.password,
|
||||
signal,
|
||||
);
|
||||
|
||||
try {
|
||||
@@ -490,6 +510,7 @@ export class ParsianProvider extends BaseProvider<LegacyInquiryPayload, LegacyIn
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
timeout: this.config.timeout,
|
||||
signal,
|
||||
}),
|
||||
);
|
||||
|
||||
|
||||
@@ -443,7 +443,10 @@ export class TejaratNouProvider implements InquiryProvider<LegacyInquiryPayload,
|
||||
body: Record<string, unknown> | undefined,
|
||||
context: ProviderExecutionContext,
|
||||
): Promise<T> {
|
||||
const token = await this.generalTokenService.getTejaratNouAccessToken(this.config);
|
||||
const token = await this.generalTokenService.getTejaratNouAccessToken(
|
||||
this.config,
|
||||
context.signal,
|
||||
);
|
||||
|
||||
try {
|
||||
const response = await this.httpClient.request<TejaratNouGatewayResponse<T>>({
|
||||
@@ -454,6 +457,7 @@ export class TejaratNouProvider implements InquiryProvider<LegacyInquiryPayload,
|
||||
Authorization: `Bearer ${token}`,
|
||||
Accept: 'text/plain',
|
||||
},
|
||||
signal: context.signal,
|
||||
});
|
||||
|
||||
const envelope = response.data;
|
||||
|
||||
Reference in New Issue
Block a user