Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@steven-tey
Copy link
Collaborator

@steven-tey steven-tey commented Aug 13, 2025

Summary by CodeRabbit

  • New Features

    • Analytics filters now support an optional country parameter.
    • Expanded geo inputs: country and geo keys now accept any string (still expect 2-letter ISO codes), increasing flexibility across analytics, links, and partner creation.
  • Chores

    • Enabled strict cron request verification in all environments for improved reliability.

@vercel
Copy link
Contributor

vercel bot commented Aug 13, 2025

The latest updates on your projects. Learn more about Vercel for Git β†—οΈŽ

Project Deployment Preview Updated (UTC)
dub βœ… Ready Preview Aug 13, 2025 8:25pm

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Aug 13, 2025

Walkthrough

Schema validations were loosened from COUNTRY_CODES enums to strings across analytics, links, and partner creation. A local schema added an optional country filter for AI-generated analytics filters. Cron verification removed a development bypass, now always enforcing Authorization header checks against CRON_SECRET.

Changes

Cohort / File(s) Summary
Analytics filters and schemas
apps/web/lib/ai/generate-filters.ts, apps/web/lib/zod/schemas/analytics.ts
Added optional country to AI generate-filters schema (enum-based). In analyticsQuerySchema, country validation changed from enum(COUNTRY_CODES) to string with updated description.
Links geo schemas
apps/web/lib/zod/schemas/links.ts
Relaxed geo key validation from enum(COUNTRY_CODES) to string in createLinkBodySchema and LinkSchema; descriptions updated.
Partners schema
apps/web/lib/zod/schemas/partners.ts
In createPartnerSchema, country changed from enum(COUNTRY_CODES) to string; description updated. onboardPartnerSchema still uses enum(COUNTRY_CODES).
Cron verification
apps/web/lib/cron/verify-vercel.ts
Removed dev/local bypass; always verifies Authorization header against CRON_SECRET; unauthorized errors unchanged.

Sequence Diagram(s)

sequenceDiagram
  participant VercelCron as Vercel Cron
  participant API as verifyVercel()
  participant Secrets as Env (CRON_SECRET)

  VercelCron->>API: HTTP request with Authorization header
  API->>Secrets: Read CRON_SECRET
  alt Missing or mismatch
    API-->>VercelCron: 401 DubApiError "Invalid QStash request signature"
  else Match
    API-->>VercelCron: Proceed to handler (verified)
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~15 minutes

Possibly related PRs

Poem

A whisk of ears, a schema hop,
From enums tight to strings that pop.
The cron gate stands, no secret slips,
We check the headersβ€”no more skips.
I thump approval, code aligned,
Carrots cached, constraints refined. πŸ₯•βœ¨

✨ Finishing Touches
  • πŸ“ Generate Docstrings
πŸ§ͺ Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch optimize-openapi

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
πŸͺ§ Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
apps/web/lib/ai/generate-filters.ts (1)

14-31: Consider the schema merge approach and polyfill comment.

The implementation creates a polyfill for the country field with enum validation while the main analytics schema uses string validation. This creates inconsistency in validation logic between the two schemas.

Consider these alternatives:

  1. Use the same validation approach (string) in both schemas for consistency
  2. If enum validation is truly needed here, document why this schema requires stricter validation than the main analytics schema

Apply this diff for consistency with the main schema:

-        country: z
-          .enum(COUNTRY_CODES)
-          .optional()
-          .describe(
-            "The country to retrieve analytics for. Must be passed as a 2-letter ISO 3166-1 country code. See https://d.to/geo for more information.",
-          ),
+        country: z
+          .string()
+          .optional()
+          .describe(
+            "The country to retrieve analytics for. Must be passed as a 2-letter ISO 3166-1 country code. See https://d.to/geo for more information.",
+          ),
πŸ“œ Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

πŸ“₯ Commits

Reviewing files that changed from the base of the PR and between 7776071 and 306dd17.

πŸ“’ Files selected for processing (5)
  • apps/web/lib/ai/generate-filters.ts (1 hunks)
  • apps/web/lib/cron/verify-vercel.ts (1 hunks)
  • apps/web/lib/zod/schemas/analytics.ts (1 hunks)
  • apps/web/lib/zod/schemas/links.ts (2 hunks)
  • apps/web/lib/zod/schemas/partners.ts (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
apps/web/lib/ai/generate-filters.ts (2)
apps/web/lib/zod/schemas/analytics.ts (1)
  • analyticsQuerySchema (69-254)
apps/web/lib/analytics/constants.ts (1)
  • VALID_ANALYTICS_FILTERS (157-187)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: build
πŸ”‡ Additional comments (7)
apps/web/lib/zod/schemas/analytics.ts (1)

147-153: LGTM! Country validation has been loosened appropriately.

The change from z.enum(COUNTRY_CODES) to z.string() for the country field aligns with the PR objective to remove strict country code validation from the OpenAPI spec while maintaining the descriptive guidance for users.

apps/web/lib/cron/verify-vercel.ts (1)

5-7: LGTM! Development bypass correctly removed.

The commented-out VERCEL bypass ensures that cron verification now always enforces Authorization header checks against CRON_SECRET, improving security by removing the development-only exception.

apps/web/lib/ai/generate-filters.ts (1)

6-9: Both imports are used β€” keep them

The imports are required in apps/web/lib/ai/generate-filters.ts:

  • import { COUNTRY_CODES } from "@dub/utils" β€” used in z.enum(COUNTRY_CODES)
  • import z from "../zod" β€” used to build/merge the schema (z.object / z.enum)

No change needed.

apps/web/lib/zod/schemas/links.ts (2)

378-384: LGTM! Geo targeting validation properly loosened.

The change from z.record(z.enum(COUNTRY_CODES), parseUrlSchema) to z.record(z.string(), parseUrlSchema) in createLinkBodySchema.geo correctly removes the strict country code validation while maintaining the URL validation for geo-targeting values.


621-626: LGTM! LinkSchema geo field validation updated consistently.

The change from z.record(z.enum(COUNTRY_CODES), z.string().url()) to z.record(z.string(), z.string().url()) maintains consistency with the create schema changes.

apps/web/lib/zod/schemas/partners.ts (2)

387-392: LGTM! Partner country validation loosened consistently.

The change from z.enum(COUNTRY_CODES) to z.string() for the createPartnerSchema.country field aligns with the overall PR objective to remove strict country code validation.


441-472: Note: Intentional validation inconsistency in onboard schema.

The onboardPartnerSchema.country field on Line 451 continues to use z.enum(COUNTRY_CODES) while createPartnerSchema.country now uses z.string(). This appears intentional based on the AI summary, likely because onboarding requires stricter validation for compliance purposes.

@steven-tey steven-tey merged commit 026b30a into main Aug 13, 2025
9 checks passed
@steven-tey steven-tey deleted the optimize-openapi branch August 13, 2025 20:34
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.

2 participants