feat(textract): migrate to AWS SDK, add AnalyzeExpense and AnalyzeID#5456
Conversation
- Replace hand-rolled AWS SigV4 signing with @aws-sdk/client-textract, matching sibling AWS integrations (secrets_manager, s3, sts) - Add Analyze Expense operation (invoice/receipt structured extraction) via AnalyzeExpense/StartExpenseAnalysis+GetExpenseAnalysis - Add Analyze Identity Document operation (AnalyzeID) with optional back-of-ID page - Add an operation selector to the textract_v2 block; defaults to the existing Analyze Document behavior for backward compatibility - Add tests for tool body/response mapping and route-level AWS response normalization
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
PR SummaryMedium Risk Overview Adds two API surfaces and tools: Analyze Expense (sync Extends Reviewed by Cursor Bugbot for commit 55cb4eb. Configure here. |
Greptile SummaryThis PR replaces the hand-rolled AWS SigV4 signing implementation in the Textract parse route with
Confidence Score: 5/5Safe to merge — the SDK migration is a drop-in replacement for the hand-rolled SigV4 signer, all security guards are preserved in the new shared module, and the new operations follow the same patterns as the existing route. The migration removes substantial bespoke code in favor of the official SDK and factors shared logic into a well-tested module. The documentFieldCondition function correctly handles the stale-processingMode scenario for analyze_id that was flagged in the previous review cycle. All three routes validate inputs at the contract layer and the route layer, SSRF and path-traversal guards are carried over intact, and 29 tests cover the key normalization and utility functions. No files require special attention. Important Files Changed
Reviews (6): Last reviewed commit: "chore(textract): drop redundant inline c..." | Re-trigger Greptile |
- textract_analyze_expense/textract_analyze_id now fall back to filePath/filePathBack when the document input is a URL string rather than an uploaded file object, so advanced "File reference" URL inputs actually reach the API (Cursor Bugbot) - mapTextractSdkError defaults to 500 (not 400) when the AWS SDK error has no HTTP status, since that implies a server-side/network failure rather than a bad request (Greptile)
|
@cursor review |
- Front-document fields (fileUpload/fileReference) are shared across all 3 operations; gate them with a values-aware condition so switching to Analyze Identity Document keeps them visible even if a stale processingMode='async' is left over from a previous operation - S3 URI field now also requires operation !== 'analyze_id', since that operation never supports S3 input
|
@cursor review |
pollTextractJob's merge callbacks spread only the latest page, dropping any field (DocumentMetadata, model version) the first page had but a follow-up NextToken page omits. Merge accumulated first so later pages only override fields they actually return.
|
@cursor review |
…ch failures fetchDocumentBytes hardcoded 400 for any non-OK response from a document URL, masking transient 5xx failures from the document host as client errors and blocking tool-execution retries. Use the actual response status instead.
|
@cursor review |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit dd92247. Configure here.
|
@cursor review |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit 55cb4eb. Configure here.
Summary
@aws-sdk/client-textractpackage, matching how sibling AWS integrations (Secrets Manager, S3, STS) already call AWSAnalyzeExpense(sync) /StartExpenseAnalysis+GetExpenseAnalysis(async, S3)AnalyzeID) for driver's licenses/passports, with an optional back-of-ID pageoperationdropdown to thetextract_v2block; defaults to the existing Analyze Document behavior so already-saved workflows are unaffectedtools/textract/types.tsType of Change
Testing
bun run type-check,bun run lint, andbun run check:api-validationall passChecklist