forked from Yara724/api
169 lines
4.4 KiB
TypeScript
169 lines
4.4 KiB
TypeScript
export type FanavaranClientKey = "parsian" | "tejaratno";
|
|
|
|
export const FANAVARAN_CLIENT_KEYS: readonly FanavaranClientKey[] = [
|
|
"parsian",
|
|
"tejaratno",
|
|
] as const;
|
|
|
|
export function isFanavaranClientKey(
|
|
value: string,
|
|
): value is FanavaranClientKey {
|
|
const normalized = value?.trim().toLowerCase();
|
|
return normalized === "parsian" || normalized === "tejaratno";
|
|
}
|
|
|
|
export function normalizeFanavaranClientKey(value: string): FanavaranClientKey {
|
|
const normalized = value?.trim().toLowerCase();
|
|
if (normalized === "parsian" || normalized === "tejaratno") {
|
|
return normalized;
|
|
}
|
|
throw new Error(
|
|
`Invalid Fanavaran client "${value}". Expected one of: ${FANAVARAN_CLIENT_KEYS.join(", ")}`,
|
|
);
|
|
}
|
|
|
|
export interface FanavaranAuthConfig {
|
|
appName: string;
|
|
secret: string;
|
|
username: string;
|
|
password: string;
|
|
corpId: string;
|
|
contractId: string;
|
|
location: string;
|
|
}
|
|
|
|
export interface FanavaranPayloadDefaults {
|
|
AccidentCityId: number;
|
|
AccidentReportTypeId: number;
|
|
AccidentVehicleUsedId: number;
|
|
ClaimExpertId: number;
|
|
ExpertiseClaimExpertId: number;
|
|
CompensationReferenceId: number;
|
|
CulpritLicenceTypeId: number;
|
|
CulpritTypeId: number;
|
|
DmgCaseTypeId: number;
|
|
DmgHistoryStatus: number;
|
|
PlaqueKindId: number;
|
|
PlaqueSampleId: number;
|
|
DriverIsOwner: number;
|
|
FaultPercent: number;
|
|
ClaimFileTypeId: number;
|
|
}
|
|
|
|
export interface FanavaranClientProfile {
|
|
key: FanavaranClientKey;
|
|
auth: FanavaranAuthConfig;
|
|
defaults: FanavaranPayloadDefaults;
|
|
}
|
|
|
|
const FANAVARAN_CLIENT_PROFILES: Record<
|
|
FanavaranClientKey,
|
|
FanavaranClientProfile
|
|
> = {
|
|
tejaratno: {
|
|
key: "tejaratno",
|
|
auth: {
|
|
appName: "fanhab",
|
|
secret: "5Fa@N#A2B",
|
|
username: "fanhabUser",
|
|
password: "Fan#@2U$3er",
|
|
corpId: "3539",
|
|
contractId: "263",
|
|
location: "100",
|
|
},
|
|
defaults: {
|
|
AccidentCityId: 701,
|
|
AccidentReportTypeId: 155,
|
|
AccidentVehicleUsedId: 1,
|
|
ClaimExpertId: 4543092,
|
|
ExpertiseClaimExpertId: 4543092,
|
|
CompensationReferenceId: 167,
|
|
CulpritLicenceTypeId: 2,
|
|
CulpritTypeId: 337,
|
|
DmgCaseTypeId: 175,
|
|
DmgHistoryStatus: 5214,
|
|
PlaqueKindId: 8,
|
|
PlaqueSampleId: 10,
|
|
DriverIsOwner: 0,
|
|
FaultPercent: 100,
|
|
ClaimFileTypeId: 23,
|
|
},
|
|
},
|
|
parsian: {
|
|
key: "parsian",
|
|
auth: {
|
|
appName: "ParsianService",
|
|
secret: "P@r30@n$erv!ce",
|
|
username: "ParsianServiceUser",
|
|
password: "P@r30@n123",
|
|
corpId: "543",
|
|
contractId: "28",
|
|
location: "210050",
|
|
},
|
|
defaults: {
|
|
AccidentCityId: 701,
|
|
AccidentReportTypeId: 155,
|
|
AccidentVehicleUsedId: 1,
|
|
ClaimExpertId: 154,
|
|
ExpertiseClaimExpertId: 29,
|
|
CompensationReferenceId: 167,
|
|
CulpritLicenceTypeId: 2,
|
|
CulpritTypeId: 337,
|
|
DmgCaseTypeId: 175,
|
|
DmgHistoryStatus: 5214,
|
|
PlaqueKindId: 8,
|
|
PlaqueSampleId: 10,
|
|
DriverIsOwner: 0,
|
|
FaultPercent: 100,
|
|
ClaimFileTypeId: 70,
|
|
},
|
|
},
|
|
};
|
|
|
|
/** Resolve active Fanavaran tenant from env (`FANAVARAN_CLIENT`) with optional CLIENT_ID fallback. */
|
|
export function resolveFanavaranClientKey(): FanavaranClientKey {
|
|
const explicit = process.env.FANAVARAN_CLIENT?.trim().toLowerCase();
|
|
if (explicit === "parsian" || explicit === "tejaratno") {
|
|
return explicit;
|
|
}
|
|
|
|
// Optional deployment hint when FANAVARAN_CLIENT is not set.
|
|
if (String(process.env.CLIENT_ID ?? "") === "8") {
|
|
return "parsian";
|
|
}
|
|
|
|
return "tejaratno";
|
|
}
|
|
|
|
export function resolveFanavaranClientProfile(): FanavaranClientProfile {
|
|
return FANAVARAN_CLIENT_PROFILES[resolveFanavaranClientKey()];
|
|
}
|
|
|
|
export function getFanavaranClientProfile(
|
|
clientKey: FanavaranClientKey,
|
|
): FanavaranClientProfile {
|
|
return FANAVARAN_CLIENT_PROFILES[clientKey];
|
|
}
|
|
|
|
export function listFanavaranClientProfiles(): FanavaranClientProfile[] {
|
|
return FANAVARAN_CLIENT_KEYS.map((key) => FANAVARAN_CLIENT_PROFILES[key]);
|
|
}
|
|
|
|
export function fanavaranPreviewPath(
|
|
clientKey: FanavaranClientKey,
|
|
claimCaseId: string,
|
|
): string {
|
|
return `/v2/fanavaran/${clientKey}/claim-cases/${claimCaseId}/base-claim/preview`;
|
|
}
|
|
|
|
export function fanavaranSubmitPath(
|
|
clientKey: FanavaranClientKey,
|
|
claimCaseId: string,
|
|
): string {
|
|
return `/v2/fanavaran/${clientKey}/claim-cases/${claimCaseId}/base-claim/submit`;
|
|
}
|
|
|
|
export function fanavaranManualSubmitPath(claimCaseId: string): string {
|
|
return fanavaranSubmitPath(resolveFanavaranClientKey(), claimCaseId);
|
|
}
|