Skip to content

Commit 5c74043

Browse files
committed
bump packages
1 parent ed22fda commit 5c74043

File tree

4 files changed

+178
-5
lines changed

4 files changed

+178
-5
lines changed
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
import { prisma } from "@dub/prisma";
2+
import { chunk } from "@dub/utils";
3+
import "dotenv-flow/config";
4+
import * as fs from "fs";
5+
import * as Papa from "papaparse";
6+
import { getAnalytics } from "../../lib/analytics/get-analytics";
7+
8+
let linksToRestore: { id: string }[] = [];
9+
10+
async function main() {
11+
Papa.parse(fs.createReadStream("deleted_links.csv", "utf-8"), {
12+
header: true,
13+
skipEmptyLines: true,
14+
step: (result: {
15+
data: {
16+
link_id: string;
17+
};
18+
}) => {
19+
linksToRestore.push({ id: result.data.link_id });
20+
},
21+
complete: async () => {
22+
console.log(`Found ${linksToRestore.length} links to restore`);
23+
24+
const chunks = chunk(linksToRestore, 200);
25+
for (let i = 0; i < chunks.length; i++) {
26+
const chunk = chunks[i];
27+
const linkIds = chunk.map((link) => link.id!);
28+
const stats = await getAnalytics({
29+
event: "composite",
30+
groupBy: "top_links",
31+
linkIds,
32+
interval: "1y",
33+
});
34+
if (stats.length === 0) {
35+
console.log(
36+
`No stats found for links in batch ${i + 1} of ${chunks.length}`,
37+
);
38+
continue;
39+
}
40+
console.log(
41+
`Stats found for links in batch ${i + 1} of ${chunks.length}`,
42+
);
43+
44+
const linksToBackfill = stats.map((stat) => ({
45+
id: stat.id,
46+
clicks: stat.clicks,
47+
leads: stat.leads,
48+
conversions: Math.min(stat.leads, stat.sales),
49+
sales: stat.sales,
50+
saleAmount: stat.saleAmount,
51+
}));
52+
await Promise.all(
53+
linksToBackfill.map(async (link) => {
54+
const res = await prisma.link.update({
55+
where: { id: link.id },
56+
data: {
57+
clicks: link.clicks,
58+
leads: link.leads,
59+
conversions: link.conversions,
60+
sales: link.sales,
61+
saleAmount: link.saleAmount,
62+
},
63+
});
64+
console.log(
65+
`Updated ${link.id} to ${res.clicks} clicks, ${res.leads} leads, ${res.conversions} conversions, ${res.sales} sales, ${res.saleAmount} saleAmount`,
66+
);
67+
}),
68+
);
69+
70+
console.log(
71+
`Backfilled stats for ${linksToBackfill.length} links in batch ${i + 1} of ${chunks.length}`,
72+
);
73+
}
74+
},
75+
});
76+
}
77+
78+
main();
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
import { prisma } from "@dub/prisma";
2+
import { Prisma } from "@dub/prisma/client";
3+
import { chunk, getParamsFromURL, linkConstructorSimple } from "@dub/utils";
4+
import "dotenv-flow/config";
5+
import * as fs from "fs";
6+
import * as Papa from "papaparse";
7+
8+
let linksToRestore: Prisma.LinkCreateManyInput[] = [];
9+
let linkTagsToRestore: Prisma.LinkTagCreateManyInput[] = [];
10+
11+
async function main() {
12+
Papa.parse(fs.createReadStream("deleted_links.csv", "utf-8"), {
13+
header: true,
14+
skipEmptyLines: true,
15+
step: (result: {
16+
data: {
17+
link_id: string;
18+
domain: string;
19+
key: string;
20+
url: string;
21+
tag_ids: string;
22+
workspace_id: string;
23+
created_at: string;
24+
program_id: string;
25+
partner_id: string;
26+
folder_id: string;
27+
};
28+
}) => {
29+
const userId = "user_xxx";
30+
if (!userId) {
31+
throw new Error("No user id found for link");
32+
}
33+
const { utm_source, utm_medium, utm_campaign, utm_term, utm_content } =
34+
getParamsFromURL(result.data.url);
35+
const tagIds: string[] = result.data.tag_ids
36+
? JSON.parse(result.data.tag_ids.replace(/'/g, '"'))
37+
: [];
38+
39+
linksToRestore.push({
40+
id: result.data.link_id,
41+
domain: result.data.domain,
42+
key: result.data.key,
43+
url: result.data.url,
44+
shortLink: linkConstructorSimple({
45+
domain: result.data.domain,
46+
key: result.data.key,
47+
}),
48+
projectId: result.data.workspace_id,
49+
createdAt: new Date(result.data.created_at),
50+
programId: result.data.program_id || null,
51+
partnerId: result.data.partner_id || null,
52+
folderId: result.data.folder_id || null,
53+
utm_source,
54+
utm_medium,
55+
utm_campaign,
56+
utm_term,
57+
utm_content,
58+
userId,
59+
trackConversion: true,
60+
});
61+
62+
if (tagIds.length > 0) {
63+
tagIds.forEach((tagId) => {
64+
linkTagsToRestore.push({
65+
linkId: result.data.link_id,
66+
tagId,
67+
});
68+
});
69+
}
70+
},
71+
complete: async () => {
72+
console.log(`Found ${linksToRestore.length} links to restore`);
73+
74+
const chunks = chunk(linksToRestore, 500);
75+
for (const chunk of chunks) {
76+
const res = await prisma.link.createMany({
77+
data: chunk,
78+
skipDuplicates: true,
79+
});
80+
console.log(`Created ${res.count} links (out of ${chunk.length})`);
81+
}
82+
83+
const linkTagsChunks = chunk(linkTagsToRestore, 500);
84+
for (const chunk of linkTagsChunks) {
85+
const res = await prisma.linkTag.createMany({
86+
data: chunk,
87+
skipDuplicates: true,
88+
});
89+
console.log(`Created ${res.count} link tags (out of ${chunk.length})`);
90+
}
91+
},
92+
});
93+
}
94+
95+
main();

packages/ui/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@dub/ui",
33
"description": "UI components for Dub",
4-
"version": "0.2.67",
4+
"version": "0.2.68",
55
"sideEffects": false,
66
"main": "./dist/index.js",
77
"module": "./dist/index.mjs",
@@ -33,9 +33,9 @@
3333
"check-types": "tsc --noEmit"
3434
},
3535
"peerDependencies": {
36-
"next": "15.5.4",
37-
"react": "19.1.1",
38-
"react-dom": "19.1.1"
36+
"next": "15.5.7",
37+
"react": "19.1.2",
38+
"react-dom": "19.1.2"
3939
},
4040
"devDependencies": {
4141
"@dub/tailwind-config": "workspace:*",

packages/utils/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@dub/utils",
33
"description": "Utility functions and constants for Dub",
4-
"version": "0.1.46",
4+
"version": "0.1.47",
55
"sideEffects": false,
66
"main": "./dist/index.mjs",
77
"module": "./dist/index.mjs",

0 commit comments

Comments
 (0)