The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
fix import-customers
Kiran K7d9206dbf349
diff --git a/apps/web/app/(ee)/api/cron/import/firstpromoter/route.ts b/apps/web/app/(ee)/api/cron/import/firstpromoter/route.tsindex 2938b367b5..2b4b665bbe 100644--- a/apps/web/app/(ee)/api/cron/import/firstpromoter/route.ts+++ b/apps/web/app/(ee)/api/cron/import/firstpromoter/route.ts@@ -5,6 +5,7 @@ import { importCommissions } from "@/lib/firstpromoter/import-commissions";import { importCustomers } from "@/lib/firstpromoter/import-customers";import { importPartners } from "@/lib/firstpromoter/import-partners";import { firstPromoterImportPayloadSchema } from "@/lib/firstpromoter/schemas";+import { updateStripeCustomers } from "@/lib/firstpromoter/update-stripe-customers";import { NextResponse } from "next/server";export const dynamic = "force-dynamic";@@ -33,8 +34,11 @@ export async function POST(req: Request) {case "import-commissions":await importCommissions(payload);break;- // default:- // throw new Error(`Unknown action: ${payload.action}`);+ case "update-stripe-customers":+ await updateStripeCustomers(payload);+ break;+ default:+ throw new Error(`Unknown action: ${payload.action}`);}return NextResponse.json("OK");diff --git a/apps/web/lib/firstpromoter/import-campaigns.ts b/apps/web/lib/firstpromoter/import-campaigns.tsindex ab422673ae..19e4969c31 100644--- a/apps/web/lib/firstpromoter/import-campaigns.ts+++ b/apps/web/lib/firstpromoter/import-campaigns.ts@@ -33,7 +33,7 @@ export async function importCampaigns(payload: FirstPromoterImportPayload) {let processedBatches = 0;let currentPage = page;- while (hasMore && processedBatches < MAX_BATCHES) {+ while (processedBatches < MAX_BATCHES) {const campaigns = await firstPromoterApi.listCampaigns({page: currentPage,});diff --git a/apps/web/lib/firstpromoter/import-customers.ts b/apps/web/lib/firstpromoter/import-customers.tsindex 1bfde90edb..1e8bbeea5b 100644--- a/apps/web/lib/firstpromoter/import-customers.ts+++ b/apps/web/lib/firstpromoter/import-customers.ts@@ -35,7 +35,7 @@ export async function importCustomers(payload: FirstPromoterImportPayload) {let processedBatches = 0;let currentPage = page;- while (hasMore && processedBatches < MAX_BATCHES) {+ while (processedBatches < MAX_BATCHES) {const customers = await firstPromoterApi.listCustomers({page: currentPage,});@@ -143,7 +143,7 @@ async function createCustomer({import_id: importId,source: "firstpromoter",entity: "customer",- entity_id: customer.uid,+ entity_id: `${customer.id}`,} as const;if (links.length === 0) {@@ -239,6 +239,7 @@ async function createCustomer({event_name: "Sign up",customer_id: customerId,timestamp: new Date(customer.created_at).toISOString(),+ metadata: customer.metadata ? JSON.stringify(customer.metadata) : "",}),prisma.link.update({diff --git a/apps/web/lib/firstpromoter/import-partners.ts b/apps/web/lib/firstpromoter/import-partners.tsindex 7e86958db8..2a6254b599 100644--- a/apps/web/lib/firstpromoter/import-partners.ts+++ b/apps/web/lib/firstpromoter/import-partners.ts@@ -37,7 +37,7 @@ export async function importPartners(payload: FirstPromoterImportPayload) {let processedBatches = 0;let currentPage = page;- while (hasMore && processedBatches < MAX_BATCHES) {+ while (processedBatches < MAX_BATCHES) {const affiliates = await firstPromoterApi.listPartners({page: currentPage,});diff --git a/apps/web/lib/firstpromoter/importer.ts b/apps/web/lib/firstpromoter/importer.tsindex a13af41c2a..e0347735e6 100644--- a/apps/web/lib/firstpromoter/importer.ts+++ b/apps/web/lib/firstpromoter/importer.ts@@ -3,8 +3,8 @@ import { redis } from "@/lib/upstash";import { APP_DOMAIN_WITH_NGROK } from "@dub/utils";import { FirstPromoterCredentials, FirstPromoterImportPayload } from "./types";-export const PAGE_LIMIT = 10;-export const MAX_BATCHES = 2;+export const PAGE_LIMIT = 100;+export const MAX_BATCHES = 10;export const CACHE_EXPIRY = 60 * 60 * 24;export const CACHE_KEY_PREFIX = "firstpromoter:import";diff --git a/apps/web/lib/firstpromoter/schemas.ts b/apps/web/lib/firstpromoter/schemas.tsindex c8cd1fd26c..7674edd16f 100644--- a/apps/web/lib/firstpromoter/schemas.ts+++ b/apps/web/lib/firstpromoter/schemas.ts@@ -5,6 +5,7 @@ export const firstPromoterImportSteps = z.enum(["import-partners","import-customers","import-commissions",+ "update-stripe-customers",]);export const firstPromoterCredentialsSchema = z.object({@@ -93,7 +94,7 @@ export const firstPromoterCustomerSchema = z.object({email: z.string(),first_name: z.string().nullable(),last_name: z.string().nullable(),- uid: z.string(),+ uid: z.string().nullable(),created_at: z.string(),customer_since: z.string().nullable(),metadata: z.record(z.any()).nullable(),@@ -105,7 +106,7 @@ export const firstPromoterCustomerSchema = z.object({});export const firstPromoterCommissionSchema = z.object({- id: z.string(),+ id: z.number(),status: z.enum(["pending", "approved", "denied"]),metadata: z.record(z.any()).nullable(),is_self_referral: z.boolean(),@@ -136,18 +137,8 @@ export const firstPromoterCommissionSchema = z.object({.nullable(),referral: firstPromoterCustomerSchema.pick({- id: true,email: true,uid: true,}).nullable(),- promoter_campaign: z.object({- // campaign: firstPromoterCampaignSchema.pick({- // campaign: true,- // }),- promoter: firstPromoterPartnerSchema.pick({- id: true,- email: true,- }),- }),});diff --git a/apps/web/lib/zod/schemas/import-error-log.ts b/apps/web/lib/zod/schemas/import-error-log.tsindex b3ce823a8e..b5f3ad6d96 100644--- a/apps/web/lib/zod/schemas/import-error-log.ts+++ b/apps/web/lib/zod/schemas/import-error-log.ts@@ -16,6 +16,8 @@ export const importErrorLogSchema = z.object({"CLICK_NOT_FOUND","STRIPE_CUSTOMER_NOT_FOUND","TRANSACTION_NOT_FOUND",+ "SELF_REFERRAL",+ "NOT_SUPPORTED_UNIT",]),message: z.string(),});