+
Skip to content

Conversation

devkiran
Copy link
Collaborator

@devkiran devkiran commented Jul 11, 2025

Summary by CodeRabbit

  • New Features

    • Added support for Singular integration, including new API endpoints to process Singular lead and sale webhooks.
    • Introduced new utility to detect Singular tracking URLs and enhanced URL handling for tracking requests.
    • Added a new environment variable for Singular webhook authentication.
    • Expanded accepted payment processors to include RevenueCat.
  • Improvements

    • Refactored lead and sale tracking endpoints to use centralized functions, simplifying request handling and improving maintainability.
    • Enhanced type safety across the app by introducing new TypeScript types for click and lead events.
    • Updated integration management page to always render fresh data.
  • Bug Fixes

    • Improved error handling and logging for Stripe customer updates.
  • Chores

    • Updated example environment file and integration creation script for Singular.

Copy link
Contributor

vercel bot commented Jul 11, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
dub ✅ Ready (Inspect) Visit Preview Jul 18, 2025 5:06pm

Copy link
Contributor

coderabbitai bot commented Jul 11, 2025

Walkthrough

A new Singular integration was implemented, including webhook endpoints, event tracking, and URL handling. Core lead and sale tracking logic was refactored into reusable functions, simplifying API route handlers. Type definitions were standardized and decoupled from Zod schemas. Middleware and utility functions were updated to support Singular-specific tracking and URL patterns. Minor improvements and adjustments were made to page caching, error logging, and integration scripts.

Changes

File(s) Change Summary
apps/web/.env.example Added SINGULAR_WEBHOOK_TOKEN environment variable.
apps/web/app/(ee)/api/singular/webhook/route.ts Added Singular webhook API route with GET/HEAD handlers, event validation, and workspace lookup.
apps/web/app/(ee)/api/stripe/integration/webhook/checkout-session-completed.ts
apps/web/lib/actions/partners/create-commission.ts
apps/web/lib/integrations/shopify/create-sale.ts
apps/web/lib/webhook/transform.ts
Replaced Zod-inferred types with explicit ClickEventTB and LeadEventTB type aliases.
apps/web/app/(ee)/api/track/lead/route.ts
apps/web/app/(ee)/api/track/sale/route.ts
Refactored route handlers to delegate all tracking logic to new trackLead and trackSale functions.
apps/web/lib/api/conversions/track-lead.ts Added new trackLead function implementing full lead tracking workflow.
apps/web/lib/api/conversions/track-sale.ts Added new trackSale function implementing full sale tracking workflow.
apps/web/lib/integrations/singular/track-lead.ts Added module for parsing/handling Singular lead events and invoking internal lead tracking.
apps/web/lib/integrations/singular/track-sale.ts Added module for parsing/handling Singular sale events and invoking internal sale tracking.
apps/web/lib/middleware/link.ts Added Singular tracking URL detection for click ID caching; optimized user agent extraction.
apps/web/lib/middleware/utils/get-final-url.ts Appends Singular-specific query params (cl, ua, ip) to URLs; imports new helpers.
apps/web/lib/middleware/utils/is-singular-tracking-url.ts Introduced helper to detect Singular tracking URLs by domain suffix.
apps/web/lib/types.ts Added ClickEventTB and LeadEventTB types inferred from Zod schemas.
apps/web/lib/zod/schemas/sales.ts Added "revenuecat" as a valid paymentProcessor value in sale tracking schema.
apps/web/scripts/create-integration.ts Changed integration creation from "Slack" to "Singular"; updated fields and removed placeholders.
apps/web/app/app.dub.co/(dashboard)/[slug]/settings/(basic-layout)/integrations/[integrationSlug]/manage/page.tsx Exported revalidate = 0 to disable static revalidation for the page.
apps/web/lib/partnerstack/update-stripe-customers.ts
apps/web/lib/tolt/update-stripe-customers.ts
Replaced async logging with direct console.error for multiple Stripe customer errors.

Sequence Diagram(s)

Singular Webhook Event Flow

sequenceDiagram
    participant Singular
    participant API as /api/singular/webhook
    participant DB as Database
    participant Lead as trackLead
    participant Sale as trackSale

    Singular->>API: GET /api/singular/webhook?...
    API->>API: Validate SINGULAR_WEBHOOK_TOKEN and query params
    API->>DB: Lookup workspace by dub_workspace_id
    API->>API: Map event_name to internal type
    alt event_name == "lead"
        API->>Lead: trackLead(params, workspace)
        Lead-->>API: Lead tracking result
    else event_name == "sale"
        API->>Sale: trackSale(params, workspace)
        Sale-->>API: Sale tracking result
    end
    API-->>Singular: JSON { "OK": true }
Loading

Lead/Sale Tracking Delegation

sequenceDiagram
    participant Route as /api/track/lead or /api/track/sale
    participant Logic as trackLead/trackSale
    participant DB as Database
    participant Redis as Redis
    participant Webhook as Workspace Webhook

    Route->>Logic: Call with parsed params and workspace
    Logic->>Redis: Deduplication (lead/sale)
    Logic->>DB: Lookup or upsert customer/lead/sale
    Logic->>Webhook: Send event notification
    Logic-->>Route: Tracking result
    Route-->>Client: JSON response
Loading

Poem

🐇
A Singular hop, a leap through the code,
Webhooks and tracking, in neat new abode.
Types now explicit, Zod takes a rest,
Middleware sniffs out the Singular quest.
With leads and with sales, the logic’s now lean—
Oh what a fine integration machine!


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 9874ea8 and 69025d4.

📒 Files selected for processing (3)
  • apps/web/app/app.dub.co/(dashboard)/[slug]/settings/(basic-layout)/integrations/[integrationSlug]/manage/page.tsx (1 hunks)
  • apps/web/lib/partnerstack/update-stripe-customers.ts (0 hunks)
  • apps/web/lib/tolt/update-stripe-customers.ts (0 hunks)
💤 Files with no reviewable changes (2)
  • apps/web/lib/partnerstack/update-stripe-customers.ts
  • apps/web/lib/tolt/update-stripe-customers.ts
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: devkiran
PR: dubinc/dub#2637
File: apps/web/app/(ee)/api/singular/webhook/route.ts:0-0
Timestamp: 2025-07-17T06:41:45.598Z
Learning: In the Singular integration (apps/web/app/(ee)/api/singular/webhook/route.ts), the event names in the singularToDubEvent object have intentionally different casing: "Copy GAID" and "copy IDFA". This casing difference is valid and should not be changed, as these are the correct event names expected from Singular.
apps/web/app/app.dub.co/(dashboard)/[slug]/settings/(basic-layout)/integrations/[integrationSlug]/manage/page.tsx (1)
Learnt from: TWilson023
PR: dubinc/dub#2614
File: apps/web/ui/partners/design/previews/lander-preview.tsx:181-181
Timestamp: 2025-07-09T20:52:56.592Z
Learning: In apps/web/ui/partners/design/previews/lander-preview.tsx, the ellipsis wave animation delay calculation `3 - i * -0.15` is intentionally designed to create negative delays that offset each dot's animation cycle. This pattern works correctly for the intended ellipsis effect and should not be changed to positive incremental delays.
🧬 Code Graph Analysis (1)
apps/web/app/app.dub.co/(dashboard)/[slug]/settings/(basic-layout)/integrations/[integrationSlug]/manage/page.tsx (3)
apps/web/app/app.dub.co/(dashboard)/[slug]/settings/(basic-layout)/integrations/[integrationSlug]/page.tsx (1)
  • revalidate (5-5)
apps/web/app/app.dub.co/(dashboard)/[slug]/settings/(basic-layout)/integrations/enabled/page.tsx (1)
  • revalidate (13-13)
apps/web/app/app.dub.co/(dashboard)/[slug]/settings/(basic-layout)/integrations/page.tsx (1)
  • revalidate (3-3)
⏰ 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 (1)
apps/web/app/app.dub.co/(dashboard)/[slug]/settings/(basic-layout)/integrations/[integrationSlug]/manage/page.tsx (1)

7-8: LGTM! Consistent caching strategy for integration management.

Setting revalidate = 0 ensures this integration management page always renders fresh data on each request, which is appropriate for a page where users edit integration settings. This follows the established pattern used in other integration management pages in the same directory structure.

✨ Finishing Touches
  • 📝 Generate Docstrings

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.
    • Explain this complex logic.
    • 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. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • 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 src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

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

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

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

Documentation and Community

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

…ic, remove deprecated functions, and enhance error handling. Introduce new trackLead and trackSale functions for improved event processing.
…nt trackSale function for sale event processing. Refactor sale tracking logic in Singular integration to enhance clarity and maintainability.
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/api/conversions/track-lead.ts (1)

74-76: Simplify nested property access with optional chaining.

The current nested property access can be simplified using optional chaining for better readability and safety.

-    if (clickEvent && clickEvent.data && clickEvent.data.length > 0) {
+    if (clickEvent?.data?.length > 0) {
       clickData = clickEvent.data[0];
     }
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between d8c1f47 and f06d3f7.

📒 Files selected for processing (2)
  • apps/web/app/(ee)/api/track/lead/route.ts (2 hunks)
  • apps/web/lib/api/conversions/track-lead.ts (1 hunks)
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: devkiran
PR: dubinc/dub#2637
File: apps/web/app/(ee)/api/singular/webhook/route.ts:0-0
Timestamp: 2025-07-17T06:41:45.598Z
Learning: In the Singular integration (apps/web/app/(ee)/api/singular/webhook/route.ts), the event names in the singularToDubEvent object have intentionally different casing: "Copy GAID" and "copy IDFA". This casing difference is valid and should not be changed, as these are the correct event names expected from Singular.
apps/web/lib/api/conversions/track-lead.ts (1)
Learnt from: devkiran
PR: dubinc/dub#2637
File: apps/web/app/(ee)/api/singular/webhook/route.ts:0-0
Timestamp: 2025-07-17T06:41:45.598Z
Learning: In the Singular integration (apps/web/app/(ee)/api/singular/webhook/route.ts), the event names in the singularToDubEvent object have intentionally different casing: "Copy GAID" and "copy IDFA". This casing difference is valid and should not be changed, as these are the correct event names expected from Singular.
🧬 Code Graph Analysis (1)
apps/web/app/(ee)/api/track/lead/route.ts (1)
apps/web/lib/api/conversions/track-lead.ts (1)
  • trackLead (28-288)
🪛 Biome (1.9.4)
apps/web/lib/api/conversions/track-lead.ts

[error] 74-74: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

🔇 Additional comments (8)
apps/web/app/(ee)/api/track/lead/route.ts (2)

1-1: Excellent refactoring approach!

The centralization of lead tracking logic into a dedicated module improves maintainability and follows good separation of concerns.


44-58: Clean delegation to centralized tracking function!

The refactored implementation correctly passes all necessary parameters to the centralized trackLead function and maintains the same API contract. This approach improves code maintainability while preserving all original functionality.

apps/web/lib/api/conversions/track-lead.ts (6)

23-26: Well-structured type definitions!

The TrackLeadParams type properly extends the Zod schema input while adding the necessary rawBody and workspace properties for the internal function. This ensures type safety throughout the tracking workflow.


41-59: Robust deduplication implementation!

The Redis-based deduplication logic is well-designed with:

  • Proper cache key structure including workspace, customer, and event name
  • Appropriate 1-week expiration to prevent indefinite storage
  • NX flag to ensure atomic duplicate prevention
  • String normalization correctly uses replaceAll for multiple spaces

104-148: Well-structured database operations!

The helper functions are excellently designed:

  • upsertCustomer properly handles both creation and update scenarios
  • createLeadEventPayload efficiently supports multiple event quantities with unique IDs
  • Clean separation of concerns improves maintainability

152-189: Excellent async/sync mode handling!

The implementation properly differentiates between synchronous and asynchronous modes:

  • "wait" mode executes customer creation and lead recording synchronously for immediate consistency
  • "async" mode defers operations to background processing for better performance
  • Proper use of waitUntil for serverless environments

191-264: Comprehensive background processing workflow!

The background processing efficiently handles all necessary operations:

  • Proper parallelization of link updates, workspace usage, and conversion logging
  • Conditional partner commission creation with appropriate checks
  • Avatar persistence to R2 storage with proper dimensions
  • Webhook dispatch with transformed event data

268-288: Well-structured response with backwards compatibility!

The response formatting properly:

  • Validates response structure with Zod schema
  • Maintains API consistency for existing clients
  • Includes backwards compatibility fields with clear deprecation comments
  • Provides clean migration path for future API updates

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

点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载