Require the damaged party in user flows to select an active insurer branch and preserve branch access rules. Accept older licence issue dates, correct anniversary boundaries, and update Fanavaran audit documentation and regression coverage.
25 KiB
Fanavaran hardcoded outbound values — current audit
Date: 2026-11-11. Remote baseline: API 90bdc51 on origin/main, with the
existing local branch-routing work restored. This is a source audit of possible
outbound values, not a capture of production requests. Mongo configuration can
override seed defaults, so the numbers below are code defaults, not a claim about
what is configured on a particular production server.
The requirement “never send guessed/default business codes” is not satisfied. The staff-location fix is present, and recent hull changes removed several numeric fallbacks, but other defaults can still reach Fanavaran. Merely checking that a default ID exists in a lookup does not establish that it describes this accident, driver, vehicle, or assessment.
This document updates the outbound-default findings in lookup-coding-audit.md, which predates the latest hull and location changes. This audit changes documentation only.
Audited paths
| Area | Sources and responsibility |
|---|---|
| Application write entry points | src/fanavaran/fanavaran.controller.ts: base claim, damage case, attachments, expertise preview/submit; automatic and soft-ensure stage calls in ClaimRequestManagementService use the same builders |
| Payloads and HTTP writes | src/claim-request-management/claim-request-management.service.ts: GEN.03, GEN.12, GEN.44, GEN.07, third-party GEN.08, hull base PUT and GEN.06 |
| Product-specific helpers | src/claim-request-management/fanavaran-{hull-base-claim,hull-expertise,hull-expertise-lookups,hull-lookup-validation,party-roles,other-people,accident-vehicle-used,v15-third-party-base}.ts |
| Configuration and headers | src/core/config/fanavaran-client.config.ts, src/fanavaran/fanavaran-{client-config,auth,location}.service.ts, config schema, system settings |
| Lookup/inquiry and local catalogues | src/fanavaran/fanavaran-lookup.service.ts, fanavaran-lookup.config.ts, src/lookups/, src/static/outer-car-parts-catalog.ts, part helpers, vehicle/stage review code |
| Expert and user UI | Expert Fanavaran API route, vehicle review, stage-field defaults, damage reply fields; user inquiry/part-selection consumers. No matching numeric payload defaults were found in the current UI source search; the expert UI does accept backend-prefilled defaults. |
| Standalone tools | scripts/fanavaran-flow-ui-server.js, scripts/data/fanavaran-flow-ui.html, scripts/fanavaran-flow-test.sh, scripts/fanavaran-auth.sh, scripts/get-fanavaran-car-parts.sh; report-seeding fixtures were distinguished from application writes |
The runtime tenant type supports parsian, tejaratno, and moallem.
esg/src had no direct Fanavaran references in the search. rewrite was excluded.
1. Business IDs that can still be sent from defaults
Line references are against the restored worktree at audit time. service means
src/claim-request-management/claim-request-management.service.ts.
| Field / stage | Hardcoded or seeded value | When it reaches the payload | Evidence / required source |
|---|---|---|---|
AccidentCauseId — base, both products |
6 | Always initialized to 6. accidentReason is passed into the builder but its selected ID / fanavaran code is not applied. Hull checks membership, which can accept the wrong but active cause. |
service:405, 1894; use the actual selected cause mapped to this tenant. |
AccidentCityId — base, both products |
701 | Profile default unless an expert stage review changes it. The shared builder does not resolve the supplied coordinates into a city. | Config :100; service:1893, 5691; use accident-city selection/inquiry. |
AccidentReportTypeId — base, both products |
155 | Profile default unless reviewed. | Config :101; service:5692; explicit report-type selection. |
CompensationReferenceId — third-party base |
167 | Included from the profile; not among the current editable stage fields or manual-ID overrides. Hull's key whitelist removes it. | Config :106; service:1893; confirm the required contract/codebook and source. |
CulpritLicenceTypeId — base, both products |
2 | Included from the profile. The resolved driver identity includes licenseType, but the payload does not use it. Hull checks whether 2 is active, not whether it is the driver's licence category. |
Config :107; service:4679 vicinity; map the actual stored driver's selection. |
LicenceTypeId — third-party damage |
2 | Always assigned from defaults.CulpritLicenceTypeId, ignoring the damaged driver's stored licence type. |
service:3253. |
CulpritTypeId — third-party base |
337 / 338 | Final value comes from a static map: policyholder/driver same national code → 337, different → 338. Missing role information can default to 337. It is no longer simply the profile's 337. | fanavaran-party-roles.ts:205–226; service:4687; resolve current tenant IDs by confirmed role meaning and reject unknown roles. |
AccidentVehicleUsedId — third-party base and damage |
1 | Fallback when inquiry/group resolution is unresolved; an expert's approved use type can override it. Hull base has removed this numeric fallback. | service:4771, 3208; preserve the actual vehicle use or require a selection. |
DmgCaseTypeId — third-party damage |
175 | Unconditionally taken from the profile. No current expert stage field for it. | service:3235; determine the actual damage-case classification. |
DmgHistoryStatus — third-party damage |
5214 | Profile default unless reviewed. | service:3231–3233; actual history/explicit selection. |
PlaqueKindId / PlaqueSampleId — third-party damage |
8 / 10 | National-plate fallback when matched Fanavaran vehicle has no kind. Even with a real kind, a missing sample still falls back to 10 and is labelled vehicle-inquiry. |
src/lookups/fanavaran-last-car-policy.ts:391–392, 450–470; require sourced plate IDs with compatible kind/sample. |
PlaqueMiddleCodeId — third-party damage |
Static 1–24 letter map | Used when the matched vehicle does not provide a middle code. These are explicit fixed mappings rather than a default letter, but are still tenant-unverified numeric codes. | service:424–449, 3266; map through the tenant's plate-letter catalogue. |
PoliceOfficerId — third-party base |
1 | Assigned directly; hull explicitly replaces it with null. | service:1857; fanavaran-hull-base-claim.ts:164; real officer selection or null if permitted. |
InspectionPlaceId — third-party expertise |
282 | Default unless reviewed. Fetching the inspection-place list does not select or validate this fallback at the write boundary. | service:6014–6020; explicit inspection place. |
DropAmountStatus — third-party expertise |
5458 | Always assigned directly, even though drop-amount-status is fetched. Not a current editable stage field. |
service:6015–6020; derive from confirmed depreciation outcome or require selection. |
DmgSections[].AccidentLevel — third-party expertise |
5456 | Any nonnumeric typeOfDamage falls back to 5456. The ordinary expert UI sends تعمیر / تعویض, so normal UI replies take this fallback. Those values express repair/replacement, not damage severity. |
service:5888–5899; expert damagePartTable.tsx:2292–2305, claimReplySubmit.tsx:183–192; add a separate severity field rather than treating repair method as severity. |
FileTypeId, including Files[].FileTypeId — attachments |
Parsian 63 / Tejaratno 23 / Moallem 17 | One configured type is assigned across collected document/photo categories. Hull checks that the ID is active, not that its meaning matches each document. | Config :155, 181, 201 vicinity; service:5126, 5329, 5495–5497; per-document semantic mapping to current tenant catalogue. |
CityId — GEN.44 person creation |
9131 | Fallback if a person's explicit city and caption lookup cannot resolve it; shared helper has no tenant argument. This remains despite the HTTP Location fix. | fanavaran-other-people.ts:95, 251–254; actual person city, never a Parsian city ID for another tenant. |
PersonKindId — GEN.44 |
46 | Natural-person caption lookup fallback; shared across all clients. | fanavaran-other-people.ts:96, 265–268; resolve correct person kind for the tenant/person. |
IsIranian — GEN.44 |
1 / 0 | Fallback when ans lookup is unavailable. The helper assumes Iranian unless explicitly false or a naturalized code is present. |
fanavaran-other-people.ts:214–215, 259–261; encode confirmed nationality using the proper contract. |
ClaimFileTypeId also has a startup migration: Moallem's stored 23 → 17
(fanavaran-client-config.service.ts:40–45). Editing a stored value back to 23
does not survive that startup migration.
The static plate-letter map is:
الف=1، ب=2، پ=3، ج=4، د=5، س=6، ص=7، ط=8، ع=9، ق=10، ل=11، م=12، ن=13، و=14، ه=15، ی=16، ک=17، ژ=18، ت=19، ث=20، ز=21، ش=22، ف=23، گ=24.
2. Default values that are not lookup IDs but still assert case facts
| Field | Current assumption | Source / consequence |
|---|---|---|
AccidentLocationAddress |
استان تهران شهر تهران |
service:404, 1910, 5690. Location coordinates are accepted by the builder but not used here. Expert review/manual text can replace it. This address default is separate from the fixed HTTP Location header. |
CulpritLicenceNo, damage LicenceNo |
Environment dummy, else 9705463515 |
service:412–413, 1812, 1818, 3250, 7570. Real licence preferred, but missing/empty values and even empty manual overrides are replaced by a fabricated number. |
CulpritLicenceIssuDate, damage LicenceIssuDate |
1394/10/13 |
fanavaran-party-roles.ts:11, 237–242; shared builder also initializes it at service:1835. Real stored date wins if available. |
EstimateAmount |
1000 rials | service:407, 1770, 3238. Base uses it when no positive calculated estimate exists; damage builder always initializes to it, with manual amount override available. |
FaultPercent — damage |
100 | Profile default, service:3239; does not derive an actual percentage. |
CustomerFaultPercent — hull |
100 | service:2642, fanavaran-hull-base-claim.ts:59, 154–157; expert stage review can replace it. |
RepairDuration — hull expertise |
3 days | service:2844–2846, fanavaran-hull-expertise.ts:80, 121–122; review can replace it. Optional HullExpertiseRepairDuration exists in the profile interface but this builder does not use it. |
DamagedCount — third-party base |
1 | service:1838. Current two-party flow has one beneficiary, but this is a fixed scenario assumption. |
IsLicenseMatchWithVehicleKind |
1 | service:1842; no actual licence/category compatibility calculation here. |
HasOtherCulprit, IsAccidentOutOfBorder, IsFatalAccident, IsPlaqueChanged, IsLicenseReplacement — third-party base |
0 | service:1843–1848, 1865; assertions of “no”, not inferred accident facts. |
IsLicenseReplaced — hull |
Always 0 | fanavaran-hull-base-claim.ts:126–129; forced even if the incoming builder value differs. Current code intentionally implements the previous contract decision. |
IsOwnerChanged, CostSeparationToDmgSections — hull |
0 when absent | fanavaran-hull-base-claim.ts:135–142. Encoded through ans, validated for membership on hull writes. |
Count — hull damage section |
1 | fanavaran-hull-expertise.ts:156; one item per selected part row. Must be explicit if quantities can differ. |
ComponentReplacementTaxAndToll — third-party expertise |
0 | service:6051; not computed from an expert-entered tax value. |
PoliceReportDesc |
شرح گزارش |
service:1858; arbitrary placeholder, manual text override possible. |
Calculated sums starting at zero, optional nulls, empty collections, retry counts, timeouts and pagination limits are not themselves guessed business IDs. They must be distinguished from asserting “zero tax”, “100% fault”, or “no fatality”.
3. Implicit guesses that still violate the intention
These no longer necessarily use a numeric fallback, but still choose a business meaning without evidence from the case:
- Vehicle use:
fanavaran-accident-vehicle-used.ts:37–80preserves a valid preferred use, otherwise chooses a caption containingشخص, otherwise the first active row in the vehicle group. A live row is not proof of actual use. Used by third-party base/damage; hull base now bypasses this substitution. - Vehicle model:
service:2029–2065can select the first caption matching a broad body type such as sedan/SUV. This is a fallback in the damage builder; an approved exact vehicle kind has priority. A broad type is not a model. - Hull accident/culprit/authority:
service:2642–2653selectsتصادف(حادثه),بیمهگذار, and an authority caption containingبیمهگذارunless review supplies alternatives. IDs come from current lookup responses, but the scenario is still assumed. - Hull damage kind/cost kind:
service:2746–2752choosesتخریبandمجموع لوازمfor the sections. The removed 5485/1 numeric fallbacks are gone, but the same two meanings are still automatically applied to all parts. - Hull accessory:
fanavaran-hull-expertise-lookups.ts:77–102first matches the part's accessory kind; otherwise picks the policy's factory-parts bundle. This is a policy-sourced fallback, not a fixed record ID, but bundle applicability still requires a business rule. - Hull culprit identity/value: policy
CustomerIdcan substitute for the driver when person inquiry misses (service:2625vicinity), and insuredVehicleValuecan substitute for market/current value. Neither is a fixed number, but policyholder is not necessarily driver and insured value is not necessarily current market value.
4. Cross-stage default leakage in the base payload
fanavaranPayloadDefaultsWithoutExpertIds (service:3426–3437) removes only
ClaimExpertId and ExpertiseClaimExpertId. The base builder spreads all
remaining profile defaults (service:1892–1894).
For Parsian/Moallem third-party payloads, unlike the hull and Tejarat V15 whitelists, this can leave these extra defaults on the outgoing base object:
DmgCaseTypeId=175DmgHistoryStatus=5214DriverIsOwner=0FaultPercent=100ClaimFileTypeId=63(Parsian) /17(Moallem)- Optional
HullExpertiseRepairDuration, if present in stored defaults.
The numbers reflect seeds and may differ in Mongo. The defect is the unrestricted spread, regardless of values. These fields belong to other stages; approval of the base accident fields does not fix their leakage. Each product/stage needs an explicit outbound key whitelist.
5. What the recent fixes actually solved
- Claim HTTP
Location: fixed for application claim writes.service:3375–3423requestsrequireStaffLocation: true; the location service uses assigned stafflocations[].idor that staff member's branch code, and throwsFANAVARAN_STAFF_LOCATION_MISSINGwhen none exists. This is used by claim base, damage, attachment, expertise, hull update, and claim-linked GEN.44 writes. The branch Mongo_idis not sent as the OpBUId. - General lookup/read headers still have a tenant Location fallback.
fanavaran-auth.service.ts:281usesauth.locationwhen no explicit override exists. GenericFanavaranLookupService.postToFanavaranalso uses those headers, although itscreateOtherPersonwrapper currently has no production caller insrc. This does not undo the strict claim-write resolver. - Hull base
UsedId: fixed. Exact policy vehicle/version is used; a missing value blocks the write rather than falling back to 1. - Hull
VehicleHullAccessoryId=3043330: removed. It now comes from the current policy's accessories, with exact-part/factory-bundle resolution. - Hull numeric accident/culprit/authority/damage/cost fallbacks: the old 2/300/first-row-or-1/5485/1 substitutions have been removed. Caption-derived defaults and other fields listed above remain.
PoliceOfficerId=1: removed for hull, still present for third-party.- Assessor/case-owner expert IDs: fixed in application payloads. Assigned
staff's product-specific codes are required; profile
ClaimExpertIdandExpertiseClaimExpertIdseeds are stripped rather than used as write fallbacks. Their numeric presence in config alone must not be reported as an active application expert-ID fallback.
6. Standalone Fanavaran flow UI has separate defaults
The file currently open in the IDE, scripts/fanavaran-flow-ui-server.js, launches
scripts/fanavaran-flow-test.sh (:962–970). It does not call the Nest claim
builder. Fixing one implementation does not automatically fix the other.
| Tool / location | Defaults or fixed choices |
|---|---|
Flow shell :409–448 |
City701, report155, third-party use1, compensation167, licence2, culprit337, cause6, damage type175, history5214, plate8/10, fault100, estimate1000, inspection282, drop5458, severity5456, Tehran address, dummy licence/date, hull repair3. Environment values override these; absent ones silently use the defaults. |
Flow shell :352–380 |
Fixed tenant CorpId/ContractId and Location: Tejaratno 3539/263/100, Parsian 543/28/210050, Moallem 5650/304/30900. Shell hull contract falls back to the configured third-party contract if a hull contract is not supplied. |
Flow HTML :1052–1092, :1316–1399 |
Static expert/branch lists. Tejaratno auto-selects case-owner2721 and assessor2709 at location100; Moallem defaults to first case-owner5347 and assessor5350 at location30900; Parsian chooses branch210110 and the first listed maker32/reviewer3989 when no preference exists. Other static choices remain in these tables. |
Flow HTML :789–790, :1611–1619 |
Static culprit337/338 mapping by role scenario. |
Flow HTML :851–853, :879–900 |
Prefilled GEN.44 city9131/person-kind46/Iranian1, example amounts, repair3, fault100, example vehicle current value0. Also contains sample identity/plate/licence values; do not treat these as real inquiry evidence. |
Flow server :1168 |
Party inquiry falls back to Location 100 if neither environment nor query supplies it. |
Auth shell scripts/fanavaran-auth.sh:26–55 |
Independent hardcoded tenant auth scope/location defaults. |
| Car-parts GET shell | Prompts for business credentials/scope; defaults the connection URL. It does not build claim/damage/expertise payloads. |
The flow UI now requires live active hull lookup selections for relevant stages; that does not remove the shell's underlying defaults, nor static staff/branch choices. It can still write real records when its submission actions are run.
7. Fixed identifiers that need a different treatment
InsuranceLineId=5(third-party) / 4 (car-body): explicit product routing constants insrc/lookups/fanavaran-last-car-policy.ts:5–6. These encode the selected product; they are not a fallback to a random policy/person record.- Role IDs161/166 (and the defined owner role163) identify accepted response
roles.
fanavaran-driver-inquiry.tsselects actual returned person IDs rather than sending 161/166 asDriverIdor falling back to the first arbitrary row. - Tejarat notifier lists in
src/fanavaran/tejarat-notifier.tscontain the tenant-supplied IDs5516/5517 and5519–5526. They are allowed choices, not an automatic notifier selection; review is required. The shared DB lookup's tenant provenance still needs attention. - Tenant CorpId/ContractId, authentication identities and API URL roots are deployment configuration. They must be configured for the deployment rather than deleted as though they were guessed accident data. Auth material also exists in seed/tool source; no secret values are reproduced in this report.
- Seed expert IDs still exist (Parsian154/29, Tejaratno2721/2709, Moallem5347/5350; shared4543092/2709). As noted above, the application excludes them from outbound expert-ID resolution; the standalone HTML does not.
- Runtime auth-location seeds are Parsian110011 / Tejaratno100 / Moallem1; standalone auth/flow tools have different Parsian/Moallem defaults. Scope them explicitly when using those tools.
8. Catalogue/cache provenance also needs to be fixed
Removing numeric ?? default statements alone is insufficient:
getLiveFanavaranCatalogItems(service:774–784) falls back to the shared static car-component list when lookup rows are empty. This helper is used for selections, despite the snapshot comment saying it is legacy-only. StoredpartIdis then passed intoDmgSectionId/AccessoryKindId. Hull validates membership against live rows; third-party has no equivalent complete guard.- Mongo
lookupsis keyed bynamewithout tenant/product scope; vehicle-kinds has globally uniqueIdwithout tenant scope. DB-first/cache fallback can therefore produce a real code from the wrong insurer. Lookup startup sync can also populate a tenant's disk cache from that shared DB. getRemoteLookupaccepts any non-null parsed cache value, including an API error object; callers may turn it into an empty list and then use defaults.- Vehicle/stage review validation at save time is not comprehensive proof of current-tenant outbound validity. Hull validates many codebook IDs immediately before writing; third-party lacks an equivalent complete validation layer.
- Offline/mock inquiry data is another explicit source of seeded values:
src/offline-inquiry/, SandHub and global system settings. Offline inquiries default to enabled, and live SandHub requires an explicit true setting. Production configuration must be verified separately; this audit did not read production settings or treat fixture IDs as evidence of live inquiries.
9. Recommended implementation order
- Whitelist every stage/product payload. Eliminate cross-stage default leakage.
- Remove invented cause/licence/person/city/plate values and preserve actual stored inquiry selections with tenant/product provenance. Missing required values must produce an actionable Persian preview/submit error before any remote write; optional unresolved values should be null/omitted per contract.
- Add explicit expert fields for genuinely unavailable data: cause, licence type, compensation reference, damage-case type, separate damage severity, depreciation status, relevant flags, and document category as needed. Reuse existing city/report/history/inspection controls, initially unselected.
- Resolve tenant codes by selected meaning and current lookup response. Never fall back to first/personal row, fixed record ID, or another insurer's code. Keep a deliberate, documented distinction for product/role protocol constants.
- Make lookup and vehicle-kind storage tenant-scoped. Reject invalid cache shapes and refetch/review old unsourced IDs rather than migrating by number.
- Apply the same strict rules to both standalone flow tools and application writes. Replace static staff/branch defaults with explicit selections.
- Update tests that currently assert defaults; add tests that missing, stale,
inactive, wrong-tenant and semantically unrelated IDs never trigger remote
POST/PUT. Test normal
تعمیر/تعویضreplies with independent severity data.
Verification and limits
- Stashed tracked/untracked local changes, fast-forwarded API to
90bdc51, and restored the stash without conflicts. Other checked non-rewrite repositories were already current; earlier stashes were preserved. - The backend Jest run completed successfully: 94 suites, 823 tests in the restored worktree. Existing tests include intentional fallback expectations (for example GEN.44 city9131/person-kind46); passing does not prove absence of guessed values. External providers are mocked in these tests.
- An isolated local probe executed source-extracted builder methods without
initializing Nest/Mongo or calling HTTP. A supplied cause999 still produced
cause6; Parsian/Moallem shared base objects retained the cross-stage fields
listed above; both
تعمیرandتعویضproduced accident level5456. This probes the builder before product filtering, not a complete production HTTP exchange. - Source tracing covered the application's Fanavaran write builders and their shared submission paths plus standalone tools. No Fanavaran write, real SMS, production database change, or live tenant lookup was performed for this audit.
- Application behavior has not been changed. The table is a remediation worklist, not a statement that the “no default codes” policy is already implemented.