forked from Yara724/api
urls dynamic integration
This commit is contained in:
@@ -219,6 +219,7 @@ import { HttpService } from "@nestjs/axios";
|
|||||||
import { firstValueFrom } from "rxjs";
|
import { firstValueFrom } from "rxjs";
|
||||||
import {
|
import {
|
||||||
fanavaranSubmitPath,
|
fanavaranSubmitPath,
|
||||||
|
getFanavaranLookupBaseUrl,
|
||||||
getFanavaranClientProfile,
|
getFanavaranClientProfile,
|
||||||
resolveFanavaranClientKey,
|
resolveFanavaranClientKey,
|
||||||
resolveFanavaranProductContractId,
|
resolveFanavaranProductContractId,
|
||||||
@@ -228,10 +229,7 @@ import { buildEnrichedDamagedParts } from "src/expert-claim/dto/claim-damaged-pa
|
|||||||
import { FanavaranAuditService } from "src/fanavaran/fanavaran-audit.service";
|
import { FanavaranAuditService } from "src/fanavaran/fanavaran-audit.service";
|
||||||
import type { FanavaranAuditSession } from "src/fanavaran/fanavaran-audit.types";
|
import type { FanavaranAuditSession } from "src/fanavaran/fanavaran-audit.types";
|
||||||
import { FanavaranAuthService } from "src/fanavaran/fanavaran-auth.service";
|
import { FanavaranAuthService } from "src/fanavaran/fanavaran-auth.service";
|
||||||
import {
|
import { FANAVARAN_REMOTE_LOOKUPS } from "src/fanavaran/fanavaran-lookup.config";
|
||||||
FANAVARAN_LOOKUP_BASE_URL,
|
|
||||||
FANAVARAN_REMOTE_LOOKUPS,
|
|
||||||
} from "src/fanavaran/fanavaran-lookup.config";
|
|
||||||
import { FanavaranLookupService } from "src/fanavaran/fanavaran-lookup.service";
|
import { FanavaranLookupService } from "src/fanavaran/fanavaran-lookup.service";
|
||||||
import {
|
import {
|
||||||
FanavaranAuditSource,
|
FanavaranAuditSource,
|
||||||
@@ -3306,6 +3304,7 @@ export class ClaimRequestManagementService {
|
|||||||
): Promise<string> {
|
): Promise<string> {
|
||||||
return fanavaranClaimsBaseUrl(
|
return fanavaranClaimsBaseUrl(
|
||||||
await this.resolveFanavaranClaimProduct(claimCaseId, blameCase),
|
await this.resolveFanavaranClaimProduct(claimCaseId, blameCase),
|
||||||
|
resolveFanavaranClientKey(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3447,7 +3446,7 @@ export class ClaimRequestManagementService {
|
|||||||
(await this.resolveFanavaranClaimProduct(options?.claimCaseId));
|
(await this.resolveFanavaranClaimProduct(options?.claimCaseId));
|
||||||
const insuranceLineId =
|
const insuranceLineId =
|
||||||
options?.insuranceLineId ?? fanavaranInsuranceLineIdForProduct(product);
|
options?.insuranceLineId ?? fanavaranInsuranceLineIdForProduct(product);
|
||||||
const policyInquiryUrl = `https://apimanager.iraneit.com/BimeApiManager/api/BimeApi/v2.0/common/Policies/inquiry-my-policies?InsuranceLineId=${insuranceLineId}&NationalCode=${nationalCodeOfInsurer}`;
|
const policyInquiryUrl = `${getFanavaranLookupBaseUrl(clientKey)}/common/Policies/inquiry-my-policies?InsuranceLineId=${insuranceLineId}&NationalCode=${nationalCodeOfInsurer}`;
|
||||||
const startedAt = Date.now();
|
const startedAt = Date.now();
|
||||||
|
|
||||||
const requestMeta = {
|
const requestMeta = {
|
||||||
@@ -3821,7 +3820,7 @@ export class ClaimRequestManagementService {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
const url = `${FANAVARAN_LOOKUP_BASE_URL}/common/other-people`;
|
const url = `${getFanavaranLookupBaseUrl(clientKey)}/common/other-people`;
|
||||||
const startedAt = Date.now();
|
const startedAt = Date.now();
|
||||||
const auditSession: FanavaranAuditSession = {
|
const auditSession: FanavaranAuditSession = {
|
||||||
trackingCode: this.fanavaranAuditService.generateTrackingCode(),
|
trackingCode: this.fanavaranAuditService.generateTrackingCode(),
|
||||||
@@ -4533,7 +4532,12 @@ export class ClaimRequestManagementService {
|
|||||||
claimId: claimCase.claimId ?? null,
|
claimId: claimCase.claimId ?? null,
|
||||||
dmgCaseId: claimCase.dmgCaseId ?? null,
|
dmgCaseId: claimCase.dmgCaseId ?? null,
|
||||||
submitUrl: claimCase.claimId
|
submitUrl: claimCase.claimId
|
||||||
? fanavaranClaimStageUrl(product, "damage-case", claimCase.claimId)
|
? fanavaranClaimStageUrl(
|
||||||
|
product,
|
||||||
|
"damage-case",
|
||||||
|
claimCase.claimId,
|
||||||
|
clientKey,
|
||||||
|
)
|
||||||
: null,
|
: null,
|
||||||
warning: warnings.length ? warnings.join(" ") : undefined,
|
warning: warnings.length ? warnings.join(" ") : undefined,
|
||||||
payload,
|
payload,
|
||||||
@@ -6111,7 +6115,7 @@ export class ClaimRequestManagementService {
|
|||||||
: built,
|
: built,
|
||||||
clientKey,
|
clientKey,
|
||||||
);
|
);
|
||||||
const url = `${fanavaranClaimsBaseUrl("car-body")}/${nestedId}`;
|
const url = `${fanavaranClaimsBaseUrl("car-body", clientKey)}/${nestedId}`;
|
||||||
this.logger.log(
|
this.logger.log(
|
||||||
`[Fanavaran hull sync] PUT ${url} keys=${Object.keys(hull).join(",")}`,
|
`[Fanavaran hull sync] PUT ${url} keys=${Object.keys(hull).join(",")}`,
|
||||||
);
|
);
|
||||||
@@ -6248,6 +6252,7 @@ export class ClaimRequestManagementService {
|
|||||||
product,
|
product,
|
||||||
"damage-case",
|
"damage-case",
|
||||||
claimCase.claimId,
|
claimCase.claimId,
|
||||||
|
clientKey,
|
||||||
);
|
);
|
||||||
if (url == null) {
|
if (url == null) {
|
||||||
this.logger.log(
|
this.logger.log(
|
||||||
|
|||||||
@@ -1,5 +1,10 @@
|
|||||||
import { BlameRequestType } from "src/Types&Enums/blame-request-management/blameRequestType.enum";
|
import { BlameRequestType } from "src/Types&Enums/blame-request-management/blameRequestType.enum";
|
||||||
import { PartyRole } from "src/request-management/entities/schema/partyRole.enum";
|
import { PartyRole } from "src/request-management/entities/schema/partyRole.enum";
|
||||||
|
import {
|
||||||
|
getFanavaranLookupBaseUrl,
|
||||||
|
resolveFanavaranClientKey,
|
||||||
|
type FanavaranClientKey,
|
||||||
|
} from "src/core/config/fanavaran-client.config";
|
||||||
import {
|
import {
|
||||||
FANAVARAN_CAR_BODY_LINE_ID,
|
FANAVARAN_CAR_BODY_LINE_ID,
|
||||||
FANAVARAN_THIRD_PARTY_LINE_ID,
|
FANAVARAN_THIRD_PARTY_LINE_ID,
|
||||||
@@ -12,9 +17,6 @@ import type { InquiryParticipantRoleAssignments } from "src/request-management/i
|
|||||||
|
|
||||||
export type FanavaranClaimProduct = FanavaranCarPolicyProduct;
|
export type FanavaranClaimProduct = FanavaranCarPolicyProduct;
|
||||||
|
|
||||||
const FANAVARAN_CLAIMS_HOST =
|
|
||||||
"https://apimanager.iraneit.com/BimeApiManager/api/BimeApi/v2.0/car";
|
|
||||||
|
|
||||||
export function fanavaranClaimProductFromBlameType(
|
export function fanavaranClaimProductFromBlameType(
|
||||||
type?: string | null,
|
type?: string | null,
|
||||||
): FanavaranClaimProduct {
|
): FanavaranClaimProduct {
|
||||||
@@ -44,8 +46,9 @@ export function fanavaranClaimsResourcePath(
|
|||||||
|
|
||||||
export function fanavaranClaimsBaseUrl(
|
export function fanavaranClaimsBaseUrl(
|
||||||
product: FanavaranClaimProduct,
|
product: FanavaranClaimProduct,
|
||||||
|
clientKey: FanavaranClientKey = resolveFanavaranClientKey(),
|
||||||
): string {
|
): string {
|
||||||
return `${FANAVARAN_CLAIMS_HOST}/${fanavaranClaimsResourcePath(product)}`;
|
return `${getFanavaranLookupBaseUrl(clientKey)}/car/${fanavaranClaimsResourcePath(product)}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type FanavaranClaimStage =
|
export type FanavaranClaimStage =
|
||||||
@@ -66,14 +69,17 @@ export function fanavaranHasDamageCaseStage(
|
|||||||
return product === "third-party";
|
return product === "third-party";
|
||||||
}
|
}
|
||||||
|
|
||||||
export function fanavaranHullImportClaimsUrl(): string {
|
export function fanavaranHullImportClaimsUrl(
|
||||||
return `${FANAVARAN_CLAIMS_HOST}/${FANAVARAN_HULL_IMPORT_CLAIMS_PATH}`;
|
clientKey: FanavaranClientKey = resolveFanavaranClientKey(),
|
||||||
|
): string {
|
||||||
|
return `${getFanavaranLookupBaseUrl(clientKey)}/car/${FANAVARAN_HULL_IMPORT_CLAIMS_PATH}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function fanavaranClaimStageUrl(
|
export function fanavaranClaimStageUrl(
|
||||||
product: FanavaranClaimProduct,
|
product: FanavaranClaimProduct,
|
||||||
stage: FanavaranClaimStage,
|
stage: FanavaranClaimStage,
|
||||||
claimId: number | string,
|
claimId: number | string,
|
||||||
|
clientKey: FanavaranClientKey = resolveFanavaranClientKey(),
|
||||||
): string | null {
|
): string | null {
|
||||||
if (stage === "damage-case" && !fanavaranHasDamageCaseStage(product)) {
|
if (stage === "damage-case" && !fanavaranHasDamageCaseStage(product)) {
|
||||||
return null;
|
return null;
|
||||||
@@ -89,7 +95,7 @@ export function fanavaranClaimStageUrl(
|
|||||||
: stage === "culprits"
|
: stage === "culprits"
|
||||||
? "culprits"
|
? "culprits"
|
||||||
: "expertise";
|
: "expertise";
|
||||||
return `${fanavaranClaimsBaseUrl(product)}/${claimId}/${suffix}`;
|
return `${fanavaranClaimsBaseUrl(product, clientKey)}/${claimId}/${suffix}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function fanavaranInsuranceLineIdForProduct(
|
export function fanavaranInsuranceLineIdForProduct(
|
||||||
|
|||||||
@@ -1,5 +1,21 @@
|
|||||||
export type FanavaranClientKey = "parsian" | "tejaratno" | "moallem";
|
export type FanavaranClientKey = "parsian" | "tejaratno" | "moallem";
|
||||||
|
|
||||||
|
const FANAVARAN_API_ROOTS: Record<FanavaranClientKey, string> = {
|
||||||
|
parsian: "https://apimanager.iraneit.com/BimeApiManager/api",
|
||||||
|
tejaratno: "https://apimanager.iraneit.com/BimeApiManager/api",
|
||||||
|
moallem: "https://api.inssw.ir/BimeApiManager/api",
|
||||||
|
};
|
||||||
|
|
||||||
|
export function getFanavaranApiRoot(clientKey: FanavaranClientKey): string {
|
||||||
|
return FANAVARAN_API_ROOTS[clientKey];
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getFanavaranLookupBaseUrl(
|
||||||
|
clientKey: FanavaranClientKey,
|
||||||
|
): string {
|
||||||
|
return `${getFanavaranApiRoot(clientKey)}/BimeApi/v2.0`;
|
||||||
|
}
|
||||||
|
|
||||||
export const FANAVARAN_CLIENT_KEYS: readonly FanavaranClientKey[] = [
|
export const FANAVARAN_CLIENT_KEYS: readonly FanavaranClientKey[] = [
|
||||||
"parsian",
|
"parsian",
|
||||||
"tejaratno",
|
"tejaratno",
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import { isAxiosError } from "axios";
|
|||||||
import { Model } from "mongoose";
|
import { Model } from "mongoose";
|
||||||
import { firstValueFrom } from "rxjs";
|
import { firstValueFrom } from "rxjs";
|
||||||
import {
|
import {
|
||||||
|
getFanavaranApiRoot,
|
||||||
getFanavaranClientProfile,
|
getFanavaranClientProfile,
|
||||||
type FanavaranAuthConfig,
|
type FanavaranAuthConfig,
|
||||||
type FanavaranClientKey,
|
type FanavaranClientKey,
|
||||||
@@ -44,10 +45,13 @@ interface TenantBackoffState {
|
|||||||
export class FanavaranAuthService {
|
export class FanavaranAuthService {
|
||||||
private readonly logger = new Logger(FanavaranAuthService.name);
|
private readonly logger = new Logger(FanavaranAuthService.name);
|
||||||
|
|
||||||
private readonly getAppTokenUrl =
|
private getAppTokenUrl(clientKey: FanavaranClientKey): string {
|
||||||
"https://apimanager.iraneit.com/BimeApiManager/api/EITAuthentication/GetAppToken";
|
return `${getFanavaranApiRoot(clientKey)}/EITAuthentication/GetAppToken`;
|
||||||
private readonly loginUrl =
|
}
|
||||||
"https://apimanager.iraneit.com/BimeApiManager/api/EITAuthentication/Login";
|
|
||||||
|
private loginUrl(clientKey: FanavaranClientKey): string {
|
||||||
|
return `${getFanavaranApiRoot(clientKey)}/EITAuthentication/Login`;
|
||||||
|
}
|
||||||
|
|
||||||
/** When Fanavaran says "try again later", pause all tenant calls. */
|
/** When Fanavaran says "try again later", pause all tenant calls. */
|
||||||
static readonly TRANSIENT_BACKOFF_MS = 5 * 60 * 1000;
|
static readonly TRANSIENT_BACKOFF_MS = 5 * 60 * 1000;
|
||||||
@@ -181,8 +185,12 @@ export class FanavaranAuthService {
|
|||||||
* Stable fingerprint of tenant auth. Any change (location, credentials, …)
|
* Stable fingerprint of tenant auth. Any change (location, credentials, …)
|
||||||
* forces a fresh GetAppToken+Login even before Tehran midnight.
|
* forces a fresh GetAppToken+Login even before Tehran midnight.
|
||||||
*/
|
*/
|
||||||
static authFingerprint(auth: FanavaranAuthConfig): string {
|
static authFingerprint(
|
||||||
|
clientKey: FanavaranClientKey,
|
||||||
|
auth: FanavaranAuthConfig,
|
||||||
|
): string {
|
||||||
return [
|
return [
|
||||||
|
getFanavaranApiRoot(clientKey),
|
||||||
auth.appName,
|
auth.appName,
|
||||||
auth.secret,
|
auth.secret,
|
||||||
auth.username,
|
auth.username,
|
||||||
@@ -211,6 +219,7 @@ export class FanavaranAuthService {
|
|||||||
): Promise<string> {
|
): Promise<string> {
|
||||||
this.assertNotInBackoff(clientKey);
|
this.assertNotInBackoff(clientKey);
|
||||||
const fingerprint = FanavaranAuthService.authFingerprint(
|
const fingerprint = FanavaranAuthService.authFingerprint(
|
||||||
|
clientKey,
|
||||||
getFanavaranClientProfile(clientKey).auth,
|
getFanavaranClientProfile(clientKey).auth,
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -277,9 +286,17 @@ export class FanavaranAuthService {
|
|||||||
auditSession?: FanavaranAuditSession,
|
auditSession?: FanavaranAuditSession,
|
||||||
): Promise<string> {
|
): Promise<string> {
|
||||||
const profile = getFanavaranClientProfile(clientKey);
|
const profile = getFanavaranClientProfile(clientKey);
|
||||||
const fingerprint = FanavaranAuthService.authFingerprint(profile.auth);
|
const fingerprint = FanavaranAuthService.authFingerprint(
|
||||||
const appToken = await this.fetchAppToken(profile.auth, auditSession);
|
clientKey,
|
||||||
|
profile.auth,
|
||||||
|
);
|
||||||
|
const appToken = await this.fetchAppToken(
|
||||||
|
clientKey,
|
||||||
|
profile.auth,
|
||||||
|
auditSession,
|
||||||
|
);
|
||||||
const authenticationToken = await this.fetchLoginToken(
|
const authenticationToken = await this.fetchLoginToken(
|
||||||
|
clientKey,
|
||||||
appToken,
|
appToken,
|
||||||
profile.auth,
|
profile.auth,
|
||||||
auditSession,
|
auditSession,
|
||||||
@@ -413,9 +430,11 @@ export class FanavaranAuthService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async fetchAppToken(
|
private async fetchAppToken(
|
||||||
|
clientKey: FanavaranClientKey,
|
||||||
config: Pick<FanavaranAuthConfig, "appName" | "secret">,
|
config: Pick<FanavaranAuthConfig, "appName" | "secret">,
|
||||||
auditSession?: FanavaranAuditSession,
|
auditSession?: FanavaranAuditSession,
|
||||||
): Promise<string> {
|
): Promise<string> {
|
||||||
|
const url = this.getAppTokenUrl(clientKey);
|
||||||
const startedAt = Date.now();
|
const startedAt = Date.now();
|
||||||
const requestHeaders = {
|
const requestHeaders = {
|
||||||
appname: config.appName,
|
appname: config.appName,
|
||||||
@@ -427,7 +446,7 @@ export class FanavaranAuthService {
|
|||||||
session: auditSession,
|
session: auditSession,
|
||||||
step: FanavaranAuditStep.GET_APP_TOKEN,
|
step: FanavaranAuditStep.GET_APP_TOKEN,
|
||||||
status: FanavaranAuditStatus.STARTED,
|
status: FanavaranAuditStatus.STARTED,
|
||||||
requestUrl: this.getAppTokenUrl,
|
requestUrl: url,
|
||||||
requestMethod: "POST",
|
requestMethod: "POST",
|
||||||
requestHeaders,
|
requestHeaders,
|
||||||
requestBody: "",
|
requestBody: "",
|
||||||
@@ -437,7 +456,7 @@ export class FanavaranAuthService {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await firstValueFrom(
|
const response = await firstValueFrom(
|
||||||
this.httpService.post(this.getAppTokenUrl, "", {
|
this.httpService.post(url, "", {
|
||||||
headers: requestHeaders,
|
headers: requestHeaders,
|
||||||
transformRequest: this.emptyBodyTransformRequest(),
|
transformRequest: this.emptyBodyTransformRequest(),
|
||||||
}),
|
}),
|
||||||
@@ -462,7 +481,7 @@ export class FanavaranAuthService {
|
|||||||
session: auditSession,
|
session: auditSession,
|
||||||
step: FanavaranAuditStep.GET_APP_TOKEN,
|
step: FanavaranAuditStep.GET_APP_TOKEN,
|
||||||
status: FanavaranAuditStatus.SUCCESS,
|
status: FanavaranAuditStatus.SUCCESS,
|
||||||
requestUrl: this.getAppTokenUrl,
|
requestUrl: url,
|
||||||
requestMethod: "POST",
|
requestMethod: "POST",
|
||||||
httpStatus: response.status,
|
httpStatus: response.status,
|
||||||
requestHeaders: exchange.requestHeaders,
|
requestHeaders: exchange.requestHeaders,
|
||||||
@@ -485,7 +504,7 @@ export class FanavaranAuthService {
|
|||||||
session: auditSession,
|
session: auditSession,
|
||||||
step: FanavaranAuditStep.GET_APP_TOKEN,
|
step: FanavaranAuditStep.GET_APP_TOKEN,
|
||||||
status: FanavaranAuditStatus.FAILURE,
|
status: FanavaranAuditStatus.FAILURE,
|
||||||
requestUrl: this.getAppTokenUrl,
|
requestUrl: url,
|
||||||
requestMethod: "POST",
|
requestMethod: "POST",
|
||||||
httpStatus: exchange.httpStatus,
|
httpStatus: exchange.httpStatus,
|
||||||
requestHeaders: exchange.requestHeaders,
|
requestHeaders: exchange.requestHeaders,
|
||||||
@@ -506,10 +525,12 @@ export class FanavaranAuthService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async fetchLoginToken(
|
private async fetchLoginToken(
|
||||||
|
clientKey: FanavaranClientKey,
|
||||||
appToken: string,
|
appToken: string,
|
||||||
config: Pick<FanavaranAuthConfig, "username" | "password">,
|
config: Pick<FanavaranAuthConfig, "username" | "password">,
|
||||||
auditSession?: FanavaranAuditSession,
|
auditSession?: FanavaranAuditSession,
|
||||||
): Promise<string> {
|
): Promise<string> {
|
||||||
|
const url = this.loginUrl(clientKey);
|
||||||
const startedAt = Date.now();
|
const startedAt = Date.now();
|
||||||
const requestHeaders = {
|
const requestHeaders = {
|
||||||
appToken,
|
appToken,
|
||||||
@@ -522,7 +543,7 @@ export class FanavaranAuthService {
|
|||||||
session: auditSession,
|
session: auditSession,
|
||||||
step: FanavaranAuditStep.LOGIN,
|
step: FanavaranAuditStep.LOGIN,
|
||||||
status: FanavaranAuditStatus.STARTED,
|
status: FanavaranAuditStatus.STARTED,
|
||||||
requestUrl: this.loginUrl,
|
requestUrl: url,
|
||||||
requestMethod: "POST",
|
requestMethod: "POST",
|
||||||
requestHeaders,
|
requestHeaders,
|
||||||
requestBody: "",
|
requestBody: "",
|
||||||
@@ -532,7 +553,7 @@ export class FanavaranAuthService {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await firstValueFrom(
|
const response = await firstValueFrom(
|
||||||
this.httpService.post(this.loginUrl, "", {
|
this.httpService.post(url, "", {
|
||||||
headers: requestHeaders,
|
headers: requestHeaders,
|
||||||
transformRequest: this.emptyBodyTransformRequest(),
|
transformRequest: this.emptyBodyTransformRequest(),
|
||||||
}),
|
}),
|
||||||
@@ -562,7 +583,7 @@ export class FanavaranAuthService {
|
|||||||
session: auditSession,
|
session: auditSession,
|
||||||
step: FanavaranAuditStep.LOGIN,
|
step: FanavaranAuditStep.LOGIN,
|
||||||
status: FanavaranAuditStatus.SUCCESS,
|
status: FanavaranAuditStatus.SUCCESS,
|
||||||
requestUrl: this.loginUrl,
|
requestUrl: url,
|
||||||
requestMethod: "POST",
|
requestMethod: "POST",
|
||||||
httpStatus: response.status,
|
httpStatus: response.status,
|
||||||
requestHeaders: exchange.requestHeaders,
|
requestHeaders: exchange.requestHeaders,
|
||||||
@@ -588,7 +609,7 @@ export class FanavaranAuthService {
|
|||||||
session: auditSession,
|
session: auditSession,
|
||||||
step: FanavaranAuditStep.LOGIN,
|
step: FanavaranAuditStep.LOGIN,
|
||||||
status: FanavaranAuditStatus.FAILURE,
|
status: FanavaranAuditStatus.FAILURE,
|
||||||
requestUrl: this.loginUrl,
|
requestUrl: url,
|
||||||
requestMethod: "POST",
|
requestMethod: "POST",
|
||||||
httpStatus: exchange.httpStatus,
|
httpStatus: exchange.httpStatus,
|
||||||
requestHeaders: exchange.requestHeaders,
|
requestHeaders: exchange.requestHeaders,
|
||||||
|
|||||||
@@ -71,6 +71,7 @@ export class FanavaranClientConfigService implements OnModuleInit {
|
|||||||
previousFingerprints.set(
|
previousFingerprints.set(
|
||||||
key,
|
key,
|
||||||
FanavaranAuthService.authFingerprint(
|
FanavaranAuthService.authFingerprint(
|
||||||
|
key,
|
||||||
getFanavaranClientProfile(key).auth,
|
getFanavaranClientProfile(key).auth,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
@@ -110,7 +111,10 @@ export class FanavaranClientConfigService implements OnModuleInit {
|
|||||||
setFanavaranClientProfilesCache(cache);
|
setFanavaranClientProfilesCache(cache);
|
||||||
|
|
||||||
for (const key of FANAVARAN_CLIENT_KEYS) {
|
for (const key of FANAVARAN_CLIENT_KEYS) {
|
||||||
const next = FanavaranAuthService.authFingerprint(cache[key]!.auth);
|
const next = FanavaranAuthService.authFingerprint(
|
||||||
|
key,
|
||||||
|
cache[key]!.auth,
|
||||||
|
);
|
||||||
const prev = previousFingerprints.get(key);
|
const prev = previousFingerprints.get(key);
|
||||||
if (prev && prev !== next) {
|
if (prev && prev !== next) {
|
||||||
this.logger.warn(
|
this.logger.warn(
|
||||||
|
|||||||
@@ -11,7 +11,10 @@ import { InjectModel } from "@nestjs/mongoose";
|
|||||||
import { Model } from "mongoose";
|
import { Model } from "mongoose";
|
||||||
import { firstValueFrom } from "rxjs";
|
import { firstValueFrom } from "rxjs";
|
||||||
import { isAxiosError } from "axios";
|
import { isAxiosError } from "axios";
|
||||||
import { type FanavaranClientKey } from "src/core/config/fanavaran-client.config";
|
import {
|
||||||
|
getFanavaranLookupBaseUrl,
|
||||||
|
type FanavaranClientKey,
|
||||||
|
} from "src/core/config/fanavaran-client.config";
|
||||||
import {
|
import {
|
||||||
LookupModel,
|
LookupModel,
|
||||||
type LookupDocument,
|
type LookupDocument,
|
||||||
@@ -184,7 +187,11 @@ export class FanavaranLookupService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const data = await this.fetchFromFanavaran(clientKey, url);
|
const tenantUrl = url.replace(
|
||||||
|
FANAVARAN_LOOKUP_BASE_URL,
|
||||||
|
getFanavaranLookupBaseUrl(clientKey),
|
||||||
|
);
|
||||||
|
const data = await this.fetchFromFanavaran(clientKey, tenantUrl);
|
||||||
await this.writeCacheFile(clientKey, cacheFile, data);
|
await this.writeCacheFile(clientKey, cacheFile, data);
|
||||||
return data;
|
return data;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -249,7 +256,7 @@ export class FanavaranLookupService {
|
|||||||
vin: string,
|
vin: string,
|
||||||
options?: { contractIdOverride?: string },
|
options?: { contractIdOverride?: string },
|
||||||
): Promise<unknown> {
|
): Promise<unknown> {
|
||||||
const url = `${FANAVARAN_LOOKUP_BASE_URL}/car/vehicles/inquiry-by-vin?vin=${encodeURIComponent(vin)}`;
|
const url = `${getFanavaranLookupBaseUrl(clientKey)}/car/vehicles/inquiry-by-vin?vin=${encodeURIComponent(vin)}`;
|
||||||
return this.fetchFromFanavaran(clientKey, url, options);
|
return this.fetchFromFanavaran(clientKey, url, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -260,7 +267,7 @@ export class FanavaranLookupService {
|
|||||||
options?: { contractIdOverride?: string },
|
options?: { contractIdOverride?: string },
|
||||||
): Promise<unknown> {
|
): Promise<unknown> {
|
||||||
const url =
|
const url =
|
||||||
`${FANAVARAN_LOOKUP_BASE_URL}/common/Policies/inquiry-my-policies` +
|
`${getFanavaranLookupBaseUrl(clientKey)}/common/Policies/inquiry-my-policies` +
|
||||||
`?InsuranceLineId=${insuranceLineId}` +
|
`?InsuranceLineId=${insuranceLineId}` +
|
||||||
`&NationalCode=${encodeURIComponent(nationalCode)}`;
|
`&NationalCode=${encodeURIComponent(nationalCode)}`;
|
||||||
return this.fetchFromFanavaran(clientKey, url, options);
|
return this.fetchFromFanavaran(clientKey, url, options);
|
||||||
@@ -271,7 +278,7 @@ export class FanavaranLookupService {
|
|||||||
policyId: number,
|
policyId: number,
|
||||||
options?: { contractIdOverride?: string },
|
options?: { contractIdOverride?: string },
|
||||||
): Promise<unknown> {
|
): Promise<unknown> {
|
||||||
const url = `${FANAVARAN_LOOKUP_BASE_URL}/car/third-party-car-policies/${policyId}`;
|
const url = `${getFanavaranLookupBaseUrl(clientKey)}/car/third-party-car-policies/${policyId}`;
|
||||||
return this.fetchFromFanavaran(clientKey, url, options);
|
return this.fetchFromFanavaran(clientKey, url, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -280,7 +287,7 @@ export class FanavaranLookupService {
|
|||||||
policyId: number,
|
policyId: number,
|
||||||
options?: { contractIdOverride?: string },
|
options?: { contractIdOverride?: string },
|
||||||
): Promise<unknown> {
|
): Promise<unknown> {
|
||||||
const url = `${FANAVARAN_LOOKUP_BASE_URL}/car/vehicle-hull-policies/${policyId}`;
|
const url = `${getFanavaranLookupBaseUrl(clientKey)}/car/vehicle-hull-policies/${policyId}`;
|
||||||
return this.fetchFromFanavaran(clientKey, url, options);
|
return this.fetchFromFanavaran(clientKey, url, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -290,7 +297,7 @@ export class FanavaranLookupService {
|
|||||||
policyId: number,
|
policyId: number,
|
||||||
options?: { contractIdOverride?: string },
|
options?: { contractIdOverride?: string },
|
||||||
): Promise<unknown> {
|
): Promise<unknown> {
|
||||||
const url = `${FANAVARAN_LOOKUP_BASE_URL}/car/vehicle-hull-policies/${policyId}/dmg-accessories`;
|
const url = `${getFanavaranLookupBaseUrl(clientKey)}/car/vehicle-hull-policies/${policyId}/dmg-accessories`;
|
||||||
return this.fetchFromFanavaran(clientKey, url, options);
|
return this.fetchFromFanavaran(clientKey, url, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -301,7 +308,7 @@ export class FanavaranLookupService {
|
|||||||
options?: { contractIdOverride?: string },
|
options?: { contractIdOverride?: string },
|
||||||
): Promise<unknown> {
|
): Promise<unknown> {
|
||||||
const query = versionNo == null ? "" : `?versionno=${versionNo}`;
|
const query = versionNo == null ? "" : `?versionno=${versionNo}`;
|
||||||
const url = `${FANAVARAN_LOOKUP_BASE_URL}/car/vehicles/${vehicleId}${query}`;
|
const url = `${getFanavaranLookupBaseUrl(clientKey)}/car/vehicles/${vehicleId}${query}`;
|
||||||
return this.fetchFromFanavaran(clientKey, url, options);
|
return this.fetchFromFanavaran(clientKey, url, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -310,7 +317,7 @@ export class FanavaranLookupService {
|
|||||||
customerId: number,
|
customerId: number,
|
||||||
options?: { contractIdOverride?: string },
|
options?: { contractIdOverride?: string },
|
||||||
): Promise<unknown> {
|
): Promise<unknown> {
|
||||||
const url = `${FANAVARAN_LOOKUP_BASE_URL}/common/customers/${customerId}`;
|
const url = `${getFanavaranLookupBaseUrl(clientKey)}/common/customers/${customerId}`;
|
||||||
return this.fetchFromFanavaran(clientKey, url, options);
|
return this.fetchFromFanavaran(clientKey, url, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -324,7 +331,7 @@ export class FanavaranLookupService {
|
|||||||
},
|
},
|
||||||
): Promise<unknown> {
|
): Promise<unknown> {
|
||||||
const url =
|
const url =
|
||||||
`${FANAVARAN_LOOKUP_BASE_URL}/common/parties/inquiry-by-unique-identifier` +
|
`${getFanavaranLookupBaseUrl(clientKey)}/common/parties/inquiry-by-unique-identifier` +
|
||||||
`?NationalCode=${encodeURIComponent(params.nationalCode)}` +
|
`?NationalCode=${encodeURIComponent(params.nationalCode)}` +
|
||||||
`&BirthYear=${params.birthYear}` +
|
`&BirthYear=${params.birthYear}` +
|
||||||
`&BirthMonth=${params.birthMonth}` +
|
`&BirthMonth=${params.birthMonth}` +
|
||||||
@@ -336,7 +343,7 @@ export class FanavaranLookupService {
|
|||||||
clientKey: FanavaranClientKey,
|
clientKey: FanavaranClientKey,
|
||||||
personId: number,
|
personId: number,
|
||||||
): Promise<unknown> {
|
): Promise<unknown> {
|
||||||
const url = `${FANAVARAN_LOOKUP_BASE_URL}/common/other-people/${personId}`;
|
const url = `${getFanavaranLookupBaseUrl(clientKey)}/common/other-people/${personId}`;
|
||||||
return this.fetchFromFanavaran(clientKey, url);
|
return this.fetchFromFanavaran(clientKey, url);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -344,7 +351,7 @@ export class FanavaranLookupService {
|
|||||||
clientKey: FanavaranClientKey,
|
clientKey: FanavaranClientKey,
|
||||||
payload: Record<string, unknown>,
|
payload: Record<string, unknown>,
|
||||||
): Promise<unknown> {
|
): Promise<unknown> {
|
||||||
const url = `${FANAVARAN_LOOKUP_BASE_URL}/common/other-people`;
|
const url = `${getFanavaranLookupBaseUrl(clientKey)}/common/other-people`;
|
||||||
return this.postToFanavaran(clientKey, url, payload);
|
return this.postToFanavaran(clientKey, url, payload);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -407,7 +414,7 @@ export class FanavaranLookupService {
|
|||||||
|
|
||||||
// Try fetching the full list directly from Fanavaran
|
// Try fetching the full list directly from Fanavaran
|
||||||
let companies: unknown;
|
let companies: unknown;
|
||||||
const url = `${FANAVARAN_LOOKUP_BASE_URL}/common/code-list/insurance-corp`;
|
const url = `${getFanavaranLookupBaseUrl(clientKey)}/common/code-list/insurance-corp`;
|
||||||
try {
|
try {
|
||||||
companies = await this.fetchFromFanavaran(clientKey, url);
|
companies = await this.fetchFromFanavaran(clientKey, url);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
Reference in New Issue
Block a user