Skip to content

feat(integrations): add Brex integration#4983

Merged
waleedlatif1 merged 7 commits into
stagingfrom
feat/brex-integration
Jun 12, 2026
Merged

feat(integrations): add Brex integration#4983
waleedlatif1 merged 7 commits into
stagingfrom
feat/brex-integration

Conversation

@waleedlatif1

Copy link
Copy Markdown
Collaborator

Summary

  • Add Brex integration with 28 tools across Expenses, Receipts, Transactions & Accounts, Team, Budgets, and Payments
  • Receipt handling follows the standard file pattern: file-upload subblock + normalizeFileInput + internal route (/api/tools/brex/upload-receipt) that downloads the UserFile from storage and PUTs it to Brex's pre-signed S3 URL (receipt_upload for a specific expense, receipt_match for auto-matching)
  • Contract-bound route (brexUploadReceiptContract) with checkInternalAuth before parseRequest, file access authorization, and a 50 MB receipt size limit per Brex docs
  • All endpoints, params, and response shapes verified against Brex's published OpenAPI specs (developer.brex.com/_bundle/openapi/*.yaml); list tools use Brex cursor pagination (cursor/limit, next_cursor)
  • Intentionally read-focused: no money movement, card issuance/termination, or PAN access tools
  • Block with conditional subblocks per operation, advanced-mode filters, wand timestamp generation, BlockMeta with 8 templates and 6 skills
  • Generated docs with manual intro section; route tests for the upload route (8 tests)

Type of Change

  • New feature

Testing

  • 8 route tests for the receipt upload route (auth, upload/match flows, name override, API error propagation, size limit, pre-signed failure, file access denial)
  • Programmatic block↔tool alignment audit (28 ops ↔ 28 tools, required params, canonical IDs, inputs coverage)
  • tsc --noEmit, biome check, check:api-validation:strict, and registry-wide block/tool tests all pass

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

@vercel

vercel Bot commented Jun 11, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
docs Skipped Skipped Jun 12, 2026 12:39am

Request Review

@gitguardian

gitguardian Bot commented Jun 11, 2026

Copy link
Copy Markdown

️✅ There are no secrets present in this pull request anymore.

If these secrets were true positive and are still valid, we highly recommend you to revoke them.
While these secrets were previously flagged, we no longer have a reference to the
specific commits where they were detected. Once a secret has been leaked into a git
repository, you should consider it compromised, even if it was deleted immediately.
Find here more information about risks.


🦉 GitGuardian detects secrets in your source code to help developers and security teams secure the modern development process. You are seeing this because you or someone else with access to this repository has authorized GitGuardian to scan your pull request.

@cursor

cursor Bot commented Jun 11, 2026

Copy link
Copy Markdown

PR Summary

Medium Risk
Large new surface around financial data and API tokens; receipt upload follows existing hardened file-route patterns but still handles user files and third-party pre-signed URLs.

Overview
Adds a Brex integration so workflows and agents can use corporate spend data via a user API token.

The integration ships 28 tools (expenses, receipts, card/cash transactions and accounts, statements, budgets, spend limits, team/org data, vendors, and transfer status) plus a Brex workflow block with operation-specific subblocks, templates, and skills. Scope is read-heavy: listing and reporting dominate; writes are limited to expense memo updates and receipt upload/match.

Receipt flows use the standard file pattern and a dedicated POST /api/tools/brex/upload-receipt route: internal auth, contract validation, file access checks, a 50 MB cap, Brex pre-signed URL creation, then DNS-pinned PUT to S3 with SSRF guards. BrexIcon and docs/catalog entries wire the integration into the app and docs site.

Reviewed by Cursor Bugbot for commit 5be5521. Configure here.

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cursor review

Comment thread apps/sim/app/api/tools/brex/upload-receipt/route.ts
@greptile-apps

greptile-apps Bot commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR adds a Brex integration with 28 tools spanning Expenses, Receipts, Transactions & Accounts, Team, Budgets, and Payments — all wired up through a single BlockConfig that maps brex_${operation} to the corresponding tool at runtime.

  • Receipt upload route (/api/tools/brex/upload-receipt) implements a two-phase flow: POST to Brex to get a presigned S3 URL, then a SSRF-validated pinned-IP PUT to upload the file binary; size is capped at 50 MB, file access is gated by assertToolFileAccess, and the API key schema rejects header-injection characters.
  • get_expense correctly uses the non-deprecated GET /v1/expenses/{id} endpoint; update_expense uses PUT /v1/expenses/card/{id} (the only available update path); list_card_accounts correctly handles Brex's non-paginated plain-array response while all other list tools use cursor pagination.
  • Two separate tools (brex_upload_receipt / brex_match_receipt) share the same internal route but differ in whether expenseId is passed, giving LLMs distinct verbs for "attach to expense" vs. "auto-match"; the contract's optional expenseId and the PAGINATED_OPERATIONS set are both internally consistent with the block's conditional subblock logic.

Confidence Score: 5/5

Safe to merge — the receipt upload route is well-hardened and all 28 tools follow established project patterns without introducing money-movement or card-issuance capabilities.

The integration is read-heavy and deliberately scoped to safe operations. Security-sensitive paths (SSRF, file access, header injection, size limits) all have server-side enforcement and corresponding tests. The block-to-tool mapping, PAGINATED_OPERATIONS set, and conditional subblock logic are internally consistent across all 28 operations.

No files require special attention. The route, contract, tools, and block are all consistent with each other.

Important Files Changed

Filename Overview
apps/sim/app/api/tools/brex/upload-receipt/route.ts Receipt upload route with solid security: SSRF validation, pinned-IP PUT to S3, file access authorization, 50 MB size guard, and header-injection-resistant API key schema.
apps/sim/lib/api/contracts/tools/brex.ts Zod contract applies .trim().min(1) on both expenseId and receiptName, and the apiKey regex prevents header-injection characters.
apps/sim/blocks/blocks/brex.ts Block correctly maps 28 operations to 28 tools, PAGINATED_OPERATIONS set properly excludes list_card_accounts while including all cursor-paginated tools.
apps/sim/tools/brex/upload_receipt.ts Tool correctly marks expenseId as required (distinct from brex_match_receipt which omits it), uses user-only visibility for apiKey.
apps/sim/tools/brex/match_receipt.ts Auto-match tool correctly shares the upload-receipt route without expenseId.
apps/sim/tools/brex/utils.ts toBrexDateTime correctly converts timezone-suffixed ISO 8601 to naive UTC. appendBrexArrayParam handles comma-delimited inputs with trimming.
apps/sim/tools/brex/get_expense.ts Correctly uses /v1/expenses/{id} (the non-deprecated endpoint) rather than the old /v1/expenses/card/{id}.
apps/sim/tools/brex/update_expense.ts Uses the card-specific PUT endpoint /v1/expenses/card/{id} with .trim() on expenseId before encoding.
apps/sim/app/api/tools/brex/upload-receipt/route.test.ts 8 tests cover auth, upload/match routing, name override, API error propagation, 50 MB limit, SSRF validation failure, presigned-URL PUT failure, and file access denial.
apps/sim/tools/brex/utils.test.ts Good coverage for toBrexDateTime, appendBrexArrayParam, and appendBrexPagination.

Sequence Diagram

sequenceDiagram
    participant B as Block / Tool
    participant R as /api/tools/brex/upload-receipt
    participant BrexAPI as Brex API
    participant S3 as Pre-signed S3 URL

    B->>R: "POST {apiKey, expenseId?, file, receiptName?}"
    R->>R: checkInternalAuth
    R->>R: parseRequest Zod trim+min expenseId and receiptName
    R->>R: assertToolFileAccess(file.key, userId)
    R->>R: downloadFileFromStorage check 50 MB
    alt expenseId present
        R->>BrexAPI: "POST /v1/expenses/card/{expenseId}/receipt_upload"
    else no expenseId
        R->>BrexAPI: POST /v1/expenses/card/receipt_match
    end
    BrexAPI-->>R: "{id, uri}"
    R->>R: validateUrlWithDNS(uri) SSRF check
    R->>S3: secureFetchWithPinnedIP PUT binary
    S3-->>R: 200 OK
    R-->>B: "{success:true, output:{receiptId, receiptName, expenseId}}"
Loading

Reviews (7): Last reviewed commit: "fix(brex): normalize timezone-suffixed t..." | Re-trigger Greptile

Comment thread apps/sim/lib/api/contracts/tools/brex.ts Outdated
Comment thread apps/sim/lib/api/contracts/tools/brex.ts
@waleedlatif1 waleedlatif1 force-pushed the feat/brex-integration branch from 03f842d to 0446c75 Compare June 11, 2026 23:54
@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cursor review

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

✅ 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 0446c75. Configure here.

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cursor review

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

✅ 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 27ced43. Configure here.

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cursor review

Comment thread apps/sim/blocks/blocks/brex.ts
@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cursor review

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

✅ 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 cfe4ef7. Configure here.

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cursor review

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

✅ 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 5be5521. Configure here.

@waleedlatif1 waleedlatif1 merged commit 5ab6d0d into staging Jun 12, 2026
15 checks passed
@waleedlatif1 waleedlatif1 deleted the feat/brex-integration branch June 12, 2026 00:47
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.

1 participant