Skip to content

Conversation

@aadamgough
Copy link
Collaborator

Summary

Added more salesforce endpoints. Changed refresh token logic bc salesforce doesn't return expires_in in their token response, but their documentation explains how the token expires in 2 hours. so we have a function that has a default expiration of two hours for salesforce specifically.

Fixes #(issue)

Type of Change

  • Bug fix
  • New feature

Testing

Tested manually

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
Copy link

vercel bot commented Dec 4, 2025

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

1 Skipped Deployment
Project Deployment Preview Comments Updated (UTC)
docs Skipped Skipped Dec 7, 2025 2:42am

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Dec 4, 2025

Greptile Overview

Greptile Summary

Fixed Salesforce token refresh logic by adding a database hook that sets a default 2-hour expiration for tokens (since Salesforce doesn't return expires_in), enabled refresh token rotation, and added 11 new endpoints for reports, dashboards, and SOQL queries.

  • Added account.create.after hook in apps/sim/lib/auth/auth.ts:101 to automatically set accessTokenExpiresAt to 2 hours for Salesforce accounts
  • Changed supportsRefreshTokenRotation from false to true for Salesforce in apps/sim/lib/oauth/oauth.ts:1265
  • Added offline_access scope to Salesforce OAuth configuration
  • Implemented new tools: list/get/run reports, list/get/refresh dashboards, execute SOQL queries, describe/list objects
  • Enhanced error logging in token refresh flow with additional context fields
  • All new tools follow existing patterns with proper OAuth integration, error handling, and response transformation

Confidence Score: 4/5

  • This PR is safe to merge with minor code duplication to address
  • The token refresh logic fix is well-implemented with proper error handling and logging. The new endpoints follow established patterns and include comprehensive error handling. Score of 4 (not 5) due to significant code duplication of helper functions across three new files that should be extracted to a shared utility
  • apps/sim/tools/salesforce/dashboards.ts, query.ts, and reports.ts have duplicated helper functions that could be refactored

Important Files Changed

File Analysis

Filename Score Overview
apps/sim/lib/auth/auth.ts 5/5 Added database hook to set 2-hour token expiration for Salesforce accounts after creation, updated scopes to include offline_access
apps/sim/lib/oauth/oauth.ts 5/5 Changed Salesforce supportsRefreshTokenRotation to true and enhanced error logging for token refresh failures
apps/sim/tools/salesforce/dashboards.ts 4/5 New file implementing list, get, and refresh dashboard tools with proper error handling and instance URL extraction
apps/sim/tools/salesforce/query.ts 4/5 New file implementing SOQL query execution, pagination, object description, and listing tools
apps/sim/tools/salesforce/reports.ts 4/5 New file implementing list, get, run reports and list report types tools with filtering capabilities

Sequence Diagram

sequenceDiagram
    participant User
    participant Auth
    participant DB
    participant SF
    
    User->>Auth: Login via OAuth
    Auth->>SF: Authenticate user
    SF-->>Auth: Provide access (no expires_in)
    Auth->>DB: Create Account
    Note over DB: Hook sets 2hr expiration
    DB-->>Auth: Account Ready
    Auth-->>User: Login Success
    
    Note over User,SF: Refresh Flow
    User->>Auth: API Call
    Auth->>Auth: Check Expiration
    Auth->>SF: Refresh access
    SF-->>Auth: Provide new access
    Auth->>DB: Update (2hr expiration)
    Auth-->>User: Success
Loading

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

9 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

@aadamgough aadamgough merged commit 92c03b8 into staging Dec 7, 2025
9 checks passed
@aadamgough aadamgough deleted the improvement/salesforce branch December 7, 2025 03:03
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