Skip to content

feat: integrate IDfy CRC API for individual court record verification#1316

Open
bytedex wants to merge 1 commit into
mainfrom
feat/integrate-crc-idfy
Open

feat: integrate IDfy CRC API for individual court record verification#1316
bytedex wants to merge 1 commit into
mainfrom
feat/integrate-crc-idfy

Conversation

@bytedex
Copy link
Copy Markdown
Contributor

@bytedex bytedex commented May 29, 2026

Type of Change

  • Bugfix
  • New feature
  • Enhancement
  • Refactoring
  • Dependency updates

Description

Additional Changes

  • This PR modifies the database schema (database migration added)
  • This PR modifies dhall configs/environment variables

Motivation and Context

How did you test it?

Checklist

  • I formatted the code and addressed linter errors ./dev/format-all-files.sh
  • I reviewed submitted code
  • I added unit tests for my changes where possible
  • I added a CHANGELOG entry if applicable

Summary by CodeRabbit

  • New Features
    • Added CRC (court-record) verification: submit requests with name, optional father name, DOB (date), address, PAN, monitor/report options, and driver ID.
    • Async submission returns a request ID; results are surfaced in task responses and include a requestor marker.
    • Result payloads include case details link, monitoring flag/counts, report download link, risk summary/type, and overall verification status.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 29, 2026

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 1052b650-b76d-4258-9e10-7affdc7d57d8

📥 Commits

Reviewing files that changed from the base of the PR and between 0890c6b and a33ba7e.

📒 Files selected for processing (6)
  • lib/mobility-core/src/Kernel/External/Verification/Idfy/Client.hs
  • lib/mobility-core/src/Kernel/External/Verification/Idfy/Types/Request.hs
  • lib/mobility-core/src/Kernel/External/Verification/Idfy/Types/Response.hs
  • lib/mobility-core/src/Kernel/External/Verification/Interface/Idfy.hs
  • lib/mobility-core/src/Kernel/External/Verification/Interface/Types.hs
  • lib/mobility-core/src/Kernel/External/Verification/Types.hs
🚧 Files skipped from review as they are similar to previous changes (6)
  • lib/mobility-core/src/Kernel/External/Verification/Idfy/Client.hs
  • lib/mobility-core/src/Kernel/External/Verification/Types.hs
  • lib/mobility-core/src/Kernel/External/Verification/Idfy/Types/Request.hs
  • lib/mobility-core/src/Kernel/External/Verification/Interface/Types.hs
  • lib/mobility-core/src/Kernel/External/Verification/Interface/Idfy.hs
  • lib/mobility-core/src/Kernel/External/Verification/Idfy/Types/Response.hs

Walkthrough

Adds CRC (Court Record Check) verification end-to-end: request/response types, Idfy request payloads, a Servant client endpoint for ind_court_record, and interface functions to invoke the client and convert Idfy outputs to internal CRC responses.

Changes

CRC Verification Feature

Layer / File(s) Summary
Response contract and types
Kernel/External/Verification/Types.hs, Kernel/External/Verification/Idfy/Types/Response.hs
Defines CRCVerificationResponse and CRCVerificationOutput, adds CRCResult to IdfyResult, and updates VerificationResponse JSON handling for ind_court_record.
Idfy request payload types
Kernel/External/Verification/Idfy/Types/Request.hs
Adds CRCVerificationRequest = IdfyRequest CRCVerificationData and payload records CRCVerificationData / CRCEntityDetails (uses Day for dob).
Idfy client API
Kernel/External/Verification/Idfy/Client.hs
Adds VerifyCRCAPI Servant type for v3/tasks/async/verify_with_source/ind_court_record and implements verifyCRCAsync calling callIdfyAPI.
Interface request and response types
Kernel/External/Verification/Interface/Types.hs
Adds VerifyCRCReq, VerifyCRCAsyncResp alias, and extends GetTaskResp with CRCResp VT.CRCVerificationResponse.
Interface implementation and orchestration
Kernel/External/Verification/Interface/Idfy.hs
Exports verifyCRCAsync that builds the CRC payload, calls the Idfy client, returns async request info; extends getTask to handle CRCResult and adds convertCRCOutputToCRCVerification.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

I hopped to the repo, nose all a-quiver,
Court records summoned by bytes I deliver,
Types stitched in branches, a client that sings,
Async requests dancing on digital springs,
Hooray — CRC checks, from rabbit to river! 🐰✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title accurately and specifically describes the main change: integrating the IDfy CRC API for individual court record verification, which is the primary focus across all modified files.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/integrate-crc-idfy

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
lib/mobility-core/src/Kernel/External/Verification/Interface/Idfy.hs (1)

213-242: ⚡ Quick win

Confirm entity_type value expected by IDfy CRC API
lib/mobility-core/src/Kernel/External/Verification/Interface/Idfy.hs hardcodes Idfy.CRCVerificationData.entity_type to "individual". Publicly indexed IDfy resources don’t expose the ind_court_record endpoint (or an authoritative enum of entity_type values), so it can’t be validated whether "individual" is always correct or whether other values (e.g., organization/company) must be used.

What are the valid values for entity_type in IDfy CRC (ind_court_record) for the individual-vs-organization variants?

If multiple values are supported, model entity_type as a typed/configured value (e.g., an enum/ADT) instead of a string literal.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@lib/mobility-core/src/Kernel/External/Verification/Interface/Idfy.hs` around
lines 213 - 242, verifyCRCAsync currently hardcodes
Idfy.CRCVerificationData.entity_type = "individual", but the IDfy CRC API may
accept multiple entity types (individual vs organization) so you must confirm
the canonical values with IDfy docs/support and stop using a string literal;
introduce a typed ADT/enum (e.g., EntityType = Individual | Organization) and
expose it via IdfyCfg or the VerifyCRCReq so the caller can select the correct
variant, update buildIdfyRequest and Idfy.CRCVerificationData construction to
map the new ADT to the API string, and adjust types/signatures where
Idfy.CRCVerificationData.entity_type is set to ensure compile-time safety
instead of hardcoded "individual".
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@lib/mobility-core/src/Kernel/External/Verification/Interface/Idfy.hs`:
- Around line 213-242: verifyCRCAsync currently hardcodes
Idfy.CRCVerificationData.entity_type = "individual", but the IDfy CRC API may
accept multiple entity types (individual vs organization) so you must confirm
the canonical values with IDfy docs/support and stop using a string literal;
introduce a typed ADT/enum (e.g., EntityType = Individual | Organization) and
expose it via IdfyCfg or the VerifyCRCReq so the caller can select the correct
variant, update buildIdfyRequest and Idfy.CRCVerificationData construction to
map the new ADT to the API string, and adjust types/signatures where
Idfy.CRCVerificationData.entity_type is set to ensure compile-time safety
instead of hardcoded "individual".

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 85d2c292-368c-4b73-a72f-c6f9dc6c655a

📥 Commits

Reviewing files that changed from the base of the PR and between cbc823a and 9412c23.

📒 Files selected for processing (6)
  • lib/mobility-core/src/Kernel/External/Verification/Idfy/Client.hs
  • lib/mobility-core/src/Kernel/External/Verification/Idfy/Types/Request.hs
  • lib/mobility-core/src/Kernel/External/Verification/Idfy/Types/Response.hs
  • lib/mobility-core/src/Kernel/External/Verification/Interface/Idfy.hs
  • lib/mobility-core/src/Kernel/External/Verification/Interface/Types.hs
  • lib/mobility-core/src/Kernel/External/Verification/Types.hs

Copy link
Copy Markdown
Contributor Author

@bytedex bytedex left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ClaudeWeb review this pr

Copy link
Copy Markdown
Contributor

@khuzema786 khuzema786 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review: IDfy CRC API Integration

The integration is structurally sound and consistent with the existing IDfy verification patterns (RC, DL, PAN, Udyam). No security issues found — API keys are properly decrypted via decrypt, PII fields are passed through correctly. A few things to address before merging.


Warning — GetTaskResp is a breaking change for all downstream consumers

File: lib/mobility-core/src/Kernel/External/Verification/Interface/Types.hs

Adding CRCResp to the GetTaskResp sum type means every pattern match on GetTaskResp without a wildcard catch in nammayatri/nammayatri will now be non-exhaustive. Please confirm all call sites are updated alongside this PR or in an atomic follow-up.

If GetTaskResp values are ever serialised and stored (Redis, job queue, etc.), old payloads without the "CRCResp" tag will fail to deserialise after this ships.


Warning — Untyped status and risk_type fields (confidence 80)

File: lib/mobility-core/src/Kernel/External/Verification/Types.hs

status :: Maybe Text and risk_type :: Maybe Text are the primary fields callers will branch on. IDfy returns a finite set of values for both ("completed" / "in_progress" / "failed" and "low" / "medium" / "high"). As free-form Text, a misspelled or unexpected value from the API silently produces wrong downstream behavior.

Suggested fix — model them as ADTs with a fallback:

data CRCStatus = CRCCompleted | CRCInProgress | CRCFailed | CRCStatusUnknown Text
  deriving (Show, Generic, ToSchema)

data CRCRiskType = CRCLow | CRCMedium | CRCHigh | CRCRiskUnknown Text
  deriving (Show, Generic, ToSchema)

Same concern applies to report_mode :: Maybe Text in the request type — if the IDfy API accepts only a fixed set of modes, this should be an ADT.


Warning — No tests added (confidence 85)

convertCRCOutputToCRCVerification is a pure function with no external dependencies — it's trivially testable. A unit test covering the happy path (all fields populated) and the all-Nothing degenerate case would catch any field-mapping mistakes (e.g., riskSummary vs risk_summary mixups). No other conversion functions in this file have tests either, but this PR is a good place to start.


Potential — dob :: Maybe Text format undocumented (confidence 65)

File: lib/mobility-core/src/Kernel/External/Verification/Idfy/Types/Request.hs

IDfy typically expects dob in DD-MM-YYYY format. An incorrect format will fail silently at the type level and only surface as a 4xx at runtime. At minimum add a comment:

dob :: Maybe Text  -- Expected format: DD-MM-YYYY

A newtype Dob = Dob Text with a smart constructor would be stronger.


Potential — entity_type hardcoded magic string (confidence 65)

File: lib/mobility-core/src/Kernel/External/Verification/Interface/Idfy.hs (~line 228)

entity_type = "individual" is hardcoded. Since ind_court_record is individual-only per the IDfy docs, this is safe today. CodeRabbit already flagged this. If the intent is always individual, consider:

data CRCEntityType = Individual

instance ToJSON CRCEntityType where
  toJSON Individual = "individual"

Even a one-constructor ADT removes the magic string and makes the intent explicit.


Process — PR description checklist is empty

All checklist items are unchecked. Please tick off formatting/lint check, self-review, and tests (or mark N/A), and add a CHANGELOG.md entry for the new capability.

@khuzema786
Copy link
Copy Markdown
Contributor

I'll fetch the PR diff, description, and comments in parallel to do a thorough review.The gh token doesn't have read:org scope. Let me try the GitHub MCP tool instead.Let me fetch the PR details, diff, and comments using the GitHub MCP tools.Now let me get the PR files and look at the actual diff.Let me read the existing source files for deeper context before writing my review.Now I have everything I need. Let me write the review.Now I'll write the review and post it as inline comments plus a summary.The inline line comments failed to resolve — posting as a summary review instead.Review posted. Here's a summary of what was flagged:


Verdict: Comment (not blocking, but a few things need attention)

The integration follows the established IDfy pattern cleanly. No security issues — keys are properly decrypted, PII is handled correctly. Key findings:

Warnings

  1. GetTaskResp breaking change — Adding CRCResp to this sum type makes every downstream case match non-exhaustive. All call sites in nammayatri/nammayatri must be updated. If this type is ever serialised to a store, old payloads will also break on deserialisation.

  2. status and risk_type are untyped Text — These are the fields callers branch on to decide what to do with a result. IDfy returns a fixed enum of values; modelling as ADTs (with an Unknown Text fallback) makes downstream code exhaustive and safe.

  3. No testsconvertCRCOutputToCRCVerification is a pure function. A unit test covering the happy path and the all-Nothing case costs very little and guards against field-mapping regressions.

Potential Issues

  1. dob :: Maybe Text has no format documentation — IDfy typically expects DD-MM-YYYY. A wrong format is a runtime API error with no compile-time signal.
  2. entity_type = "individual" magic string — CodeRabbit already flagged this; low risk for an individual-only endpoint, but an ADT makes intent explicit.

Process

  • All PR checklist items are unchecked (formatting, self-review, tests, changelog).

data CRCEntityDetails = CRCEntityDetails
{ name :: Text,
father_name :: Maybe Text,
dob :: Maybe Text,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be of Day type? Also, these fields seem mandatory

@bytedex bytedex force-pushed the feat/integrate-crc-idfy branch from 9412c23 to 0890c6b Compare June 2, 2026 07:44
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
lib/mobility-core/src/Kernel/External/Verification/Idfy/Types/Request.hs (1)

154-154: ⚡ Quick win

dob date format matches IDfy (YYYY-MM-DD)

  • IDfy expects dob in ISO 8601 YYYY-MM-DD, and the existing formatting ("%F") matches that, so the DD-MM-YYYY mismatch concern doesn’t apply.
  • Still worth tightening the type/documentation for dob :: Maybe Text to avoid free-form Text misuse (e.g., use a typed date/newtype).
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@lib/mobility-core/src/Kernel/External/Verification/Idfy/Types/Request.hs` at
line 154, The dob field is currently declared as "dob :: Maybe Text" which
allows free-form strings; change it to a strongly typed date (e.g., newtype
IdfyDOB = IdfyDOB Day or a newtype wrapping Text with validation) and update the
request record to use that type instead of Maybe Text; add parsing/formatting
(FromJSON/ToJSON or To/FromText) enforcing the YYYY-MM-DD format and adjust any
constructors, serializers, and places that construct or pattern-match on the dob
field (search for the dob field name in the request type and its JSON instances
to update).
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@lib/mobility-core/src/Kernel/External/Verification/Idfy/Types/Request.hs`:
- Line 154: The dob field is currently declared as "dob :: Maybe Text" which
allows free-form strings; change it to a strongly typed date (e.g., newtype
IdfyDOB = IdfyDOB Day or a newtype wrapping Text with validation) and update the
request record to use that type instead of Maybe Text; add parsing/formatting
(FromJSON/ToJSON or To/FromText) enforcing the YYYY-MM-DD format and adjust any
constructors, serializers, and places that construct or pattern-match on the dob
field (search for the dob field name in the request type and its JSON instances
to update).

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 927ec18d-33ba-47bb-84c1-94493452e718

📥 Commits

Reviewing files that changed from the base of the PR and between 9412c23 and 0890c6b.

📒 Files selected for processing (6)
  • lib/mobility-core/src/Kernel/External/Verification/Idfy/Client.hs
  • lib/mobility-core/src/Kernel/External/Verification/Idfy/Types/Request.hs
  • lib/mobility-core/src/Kernel/External/Verification/Idfy/Types/Response.hs
  • lib/mobility-core/src/Kernel/External/Verification/Interface/Idfy.hs
  • lib/mobility-core/src/Kernel/External/Verification/Interface/Types.hs
  • lib/mobility-core/src/Kernel/External/Verification/Types.hs
🚧 Files skipped from review as they are similar to previous changes (5)
  • lib/mobility-core/src/Kernel/External/Verification/Types.hs
  • lib/mobility-core/src/Kernel/External/Verification/Interface/Types.hs
  • lib/mobility-core/src/Kernel/External/Verification/Idfy/Types/Response.hs
  • lib/mobility-core/src/Kernel/External/Verification/Idfy/Client.hs
  • lib/mobility-core/src/Kernel/External/Verification/Interface/Idfy.hs

@bytedex bytedex force-pushed the feat/integrate-crc-idfy branch 2 times, most recently from c2d1757 to 694b88c Compare June 2, 2026 07:54
@bytedex bytedex force-pushed the feat/integrate-crc-idfy branch from 694b88c to a33ba7e Compare June 2, 2026 13:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants