Skip to content

Codex/corrigir problema de conexao com api da meta - #4

Open
Marcelo-Rosas wants to merge 5 commits into
thaleslaray:mainfrom
Marcelo-Rosas:codex/corrigir-problema-de-conexao-com-api-da-meta
Open

Codex/corrigir problema de conexao com api da meta#4
Marcelo-Rosas wants to merge 5 commits into
thaleslaray:mainfrom
Marcelo-Rosas:codex/corrigir-problema-de-conexao-com-api-da-meta

Conversation

@Marcelo-Rosas

@Marcelo-Rosas Marcelo-Rosas commented Dec 22, 2025

Copy link
Copy Markdown

Summary by CodeRabbit

  • New Features

    • Integrated analytics tracking into the application to monitor usage patterns and performance metrics.
  • Chores

    • Updated Next.js framework to version 16.0.10.
    • Added supporting dependencies for analytics functionality.

✏️ Tip: You can customize this high-level summary in your review settings.

vercel Bot and others added 5 commits December 10, 2025 01:03
## Vercel Web Analytics Installation and Configuration

Successfully installed and configured Vercel Web Analytics for the Next.js project.

### Changes Made

**Modified Files:**
1. **app/layout.tsx** - Root layout component
   - Added import: `import { Analytics } from '@vercel/analytics/next'`
   - Added `<Analytics />` component inside the `<body>` tag after the `{children}` prop
   - The Analytics component is placed at the end of the body content to ensure all page elements are tracked

**Updated Dependencies:**
1. **package.json** - Added two dependencies:
   - `@vercel/analytics@^1.6.1` - Vercel Web Analytics package for Next.js
   - `react-is@^19.2.1` - Peer dependency required by recharts (was missing, causing build issues)

2. **package-lock.json** - Lockfile automatically updated with new dependencies and their transitive dependencies

### Implementation Details

- **Project Type:** App Router (Next.js 16.0.7 with Turbopack)
- **Package Manager:** npm
- **Build Status:** ✅ Successfully compiled and built
- **Routes Generated:** 47 static/dynamic routes

The Analytics component is now properly integrated and will automatically track web analytics events for the SmartZap WhatsApp Manager application. The component is placed at the end of the body to ensure all page interactions are captured.

### Notes

- The `react-is` package was installed as a dependency because it was required by recharts (v3.5.0) but was missing from node_modules
- All changes were made following the existing code structure and conventions
- The build completed successfully without errors
- The Analytics import uses the correct Next.js-specific export from '@vercel/analytics/next'

Co-authored-by: Vercel <vercel[bot]@users.noreply.github.com>
…to-nextjs-sex5wn

Add Vercel Web Analytics to Next.js
Updated dependencies to fix Next.js and React CVE vulnerabilities.

The fix-react2shell-next tool automatically updated the following packages to their secure versions:
- next
- react-server-dom-webpack
- react-server-dom-parcel  
- react-server-dom-turbopack

All package.json files have been scanned and vulnerable versions have been patched to the correct fixed versions based on the official React advisory.

Co-authored-by: Vercel <vercel[bot]@users.noreply.github.com>
…ts-cve-vu-b7dosq

Fix React Server Components CVE vulnerabilities
@coderabbitai

coderabbitai Bot commented Dec 22, 2025

Copy link
Copy Markdown

Walkthrough

This pull request enhances the account limits API route to accept and propagate a businessAccountId parameter throughout Meta API calls, improves quality score parsing, and adds robust error handling with specific HTTP status codes. Analytics tracking is integrated into the root layout, and dependencies are updated.

Changes

Cohort / File(s) Summary
API Route Enhancement
app/api/account/limits/route.ts
Expanded fetchLimitsFromMeta to accept businessAccountId parameter; updated all Meta API calls to include it. Enhanced quality score parsing to support quality_rating as primary value with fallback to quality_score.score. Extended credential validation to require businessAccountId in GET and POST paths. Added explicit error handling with 502 responses (GET) and 401/502/500 responses (POST). Updated POST logic to read businessAccountId from request body and fall back to Redis credentials.
Analytics Integration
app/layout.tsx
Imported Analytics component from @vercel/analytics/next and added it to RootLayout rendering alongside Toaster and children.
Dependencies
package.json
Added @vercel/analytics and react-is dependencies; updated next from ^16.0.7 to 16.0.10.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Key areas requiring attention:
    • Credential validation flow changes in both GET and POST paths—verify businessAccountId propagation across all code branches
    • Error handling logic (502 vs 500 responses)—ensure appropriate status codes align with failure scenarios
    • Quality score parsing fallback logic—confirm both quality_rating and quality_score.score paths are correct
    • Redis credential fallback for businessAccountId—validate that fallback behavior is consistent and handles missing values gracefully

Poem

🐰 A clever update hops through the code,
With businessAccountId on every road,
Analytics watch from on high,
While errors now respond with truth, not a lie,
The Meta API, now properly fed—
Quality scores bloom in the rabbit's bed! 🌟

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 75.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title is in Portuguese and describes fixing a Meta API connection problem, which aligns with the main changes that refactor API calls to include businessAccountId and improve error handling.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

@coderabbitai coderabbitai 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.

Actionable comments posted: 1

🧹 Nitpick comments (2)
app/api/account/limits/route.ts (2)

114-117: Inconsistent credential validation may cause silent fallback.

The condition on line 114 validates phoneNumberId and accessToken but not businessAccountId. If a caller provides only phoneNumberId and accessToken in the body (without businessAccountId), the code will:

  1. Set businessAccountId = undefined (line 116)
  2. Trigger the fallback on line 124 (since businessAccountId is falsy)
  3. Silently override all credentials with Redis values

Consider validating all three fields together for consistency:

🔎 Proposed fix
     // Only use if they look like real credentials (not masked)
-    if (body.phoneNumberId && body.accessToken && !body.accessToken.includes('***')) {
+    if (body.phoneNumberId && body.businessAccountId && body.accessToken && !body.accessToken.includes('***')) {
       phoneNumberId = body.phoneNumberId
       businessAccountId = body.businessAccountId
       accessToken = body.accessToken
     }

140-150: Consider using 502 for upstream API errors in POST as well.

The GET handler returns 502 Bad Gateway for Meta API failures, which correctly indicates an upstream service error. The POST handler returns 500 Internal Server Error for the same scenario. For consistency and accurate error semantics, consider using 502 here as well.

🔎 Proposed fix
   } catch (error) {
     console.error('❌ Error fetching account limits:', error)
     return NextResponse.json({
       error: 'API_ERROR',
       message: 'Erro ao conectar com a API da Meta. Tente novamente.',
       details: error instanceof Error ? error.message : String(error)
-    }, { status: 500 })
+    }, { status: 502 })
   }
📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3221a89 and 48acb2e.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (3)
  • app/api/account/limits/route.ts
  • app/layout.tsx
  • package.json
🔇 Additional comments (5)
app/layout.tsx (1)

6-6: LGTM!

The Vercel Analytics integration is correctly implemented. Placing <Analytics /> outside the <Providers> wrapper is appropriate since it doesn't require React context and should capture page views at the root level.

Also applies to: 30-30

app/api/account/limits/route.ts (3)

15-19: LGTM!

Good refactoring to include businessAccountId as a required parameter. This aligns with the Meta Graph API requirements for fetching messaging limits at the business account level.


48-51: Good defensive parsing with fallback.

The quality score extraction correctly prioritizes quality_rating and falls back to quality_score.score, handling both potential API response formats.


77-101: LGTM!

The GET handler has proper validation and error handling:

  • Returns 401 for missing credentials
  • Returns 502 for upstream Meta API failures
  • Includes helpful error details for debugging
package.json (1)

79-79: No action needed. Next.js version 16.0.10 is a valid release on npm. The library has progressed to major version 16.

(The pinned version without a caret is intentional and differs from other dependencies—if this is a concern, it should be addressed separately as part of a broader dependency versioning strategy review.)

Comment thread package.json
"@upstash/qstash": "^2.8.4",
"@upstash/redis": "^1.35.7",
"@upstash/workflow": "^0.2.22",
"@vercel/analytics": "^1.6.1",

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Update react-is to the latest patch version compatible with React 19.

@vercel/analytics@^1.6.1 is correct—it matches the latest stable release. However, react-is@^19.2.1 should be react-is@^19.2.3 to align with the latest patch version. When using recharts with React 19, you must override the react-is dependency to match the React 19 version you're using, so the explicit inclusion of react-is is necessary and intentional.

🤖 Prompt for AI Agents
In package.json around line 67, the react-is dependency is pinned to ^19.2.1 but
should be updated to ^19.2.3 to match the latest React 19 patch; change the
react-is version in dependencies (or resolutions/overrides if you use them) to
^19.2.3 and run npm/yarn install to refresh the lockfile so recharts and other
packages resolve the compatible react-is version.

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread app/layout.tsx
import './globals.css'
import { Providers } from './providers'
import { Toaster } from 'sonner'
import { Analytics } from '@vercel/analytics/next'

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Fix Analytics import path

The root layout imports Analytics from @vercel/analytics/next, but the package exposes the React entrypoint (@vercel/analytics/react) for Next.js. Using the non-existent /next path will cause the Next.js build to fail with a module-not-found error, preventing the app from compiling and blocking the analytics instrumentation entirely. Switch the import to the documented React entrypoint to keep builds working.

Useful? React with 👍 / 👎.

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