Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

bump packages

Steven Tey5c74043aa5ca
diff --git a/apps/web/scripts/misc/restore-link-analytics.ts b/apps/web/scripts/misc/restore-link-analytics.ts
new file mode 100644
index 0000000000..b6c3be30f1
--- /dev/null
+++ b/apps/web/scripts/misc/restore-link-analytics.ts
@@ -0,0 +1,78 @@
+import { prisma } from "@dub/prisma";
+import { chunk } from "@dub/utils";
+import "dotenv-flow/config";
+import * as fs from "fs";
+import * as Papa from "papaparse";
+import { getAnalytics } from "../../lib/analytics/get-analytics";
+
+let linksToRestore: { id: string }[] = [];
+
+async function main() {
+ Papa.parse(fs.createReadStream("deleted_links.csv", "utf-8"), {
+ header: true,
+ skipEmptyLines: true,
+ step: (result: {
+ data: {
+ link_id: string;
+ };
+ }) => {
+ linksToRestore.push({ id: result.data.link_id });
+ },
+ complete: async () => {
+ console.log(`Found ${linksToRestore.length} links to restore`);
+
+ const chunks = chunk(linksToRestore, 200);
+ for (let i = 0; i < chunks.length; i++) {
+ const chunk = chunks[i];
+ const linkIds = chunk.map((link) => link.id!);
+ const stats = await getAnalytics({
+ event: "composite",
+ groupBy: "top_links",
+ linkIds,
+ interval: "1y",
+ });
+ if (stats.length === 0) {
+ console.log(
+ `No stats found for links in batch ${i + 1} of ${chunks.length}`,
+ );
+ continue;
+ }
+ console.log(
+ `Stats found for links in batch ${i + 1} of ${chunks.length}`,
+ );
+
+ const linksToBackfill = stats.map((stat) => ({
+ id: stat.id,
+ clicks: stat.clicks,
+ leads: stat.leads,
+ conversions: Math.min(stat.leads, stat.sales),
+ sales: stat.sales,
+ saleAmount: stat.saleAmount,
+ }));
+ await Promise.all(
+ linksToBackfill.map(async (link) => {
+ const res = await prisma.link.update({
+ where: { id: link.id },
+ data: {
+ clicks: link.clicks,
+ leads: link.leads,
+ conversions: link.conversions,
+ sales: link.sales,
+ saleAmount: link.saleAmount,
+ },
+ });
+ console.log(
+ `Updated ${link.id} to ${res.clicks} clicks, ${res.leads} leads, ${res.conversions} conversions, ${res.sales} sales, ${res.saleAmount} saleAmount`,
+ );
+ }),
+ );
+
+ console.log(
+ `Backfilled stats for ${linksToBackfill.length} links in batch ${i + 1} of ${chunks.length}`,
+ );
+ }
+ },
+ });
+}
+
+main();
diff --git a/apps/web/scripts/misc/restore-links.ts b/apps/web/scripts/misc/restore-links.ts
new file mode 100644
index 0000000000..00f8e45d71
--- /dev/null
+++ b/apps/web/scripts/misc/restore-links.ts
@@ -0,0 +1,95 @@
+import { prisma } from "@dub/prisma";
+import { Prisma } from "@dub/prisma/client";
+import { chunk, getParamsFromURL, linkConstructorSimple } from "@dub/utils";
+import "dotenv-flow/config";
+import * as fs from "fs";
+import * as Papa from "papaparse";
+
+let linksToRestore: Prisma.LinkCreateManyInput[] = [];
+let linkTagsToRestore: Prisma.LinkTagCreateManyInput[] = [];
+
+async function main() {
+ Papa.parse(fs.createReadStream("deleted_links.csv", "utf-8"), {
+ header: true,
+ skipEmptyLines: true,
+ step: (result: {
+ data: {
+ link_id: string;
+ domain: string;
+ key: string;
+ url: string;
+ tag_ids: string;
+ workspace_id: string;
+ created_at: string;
+ program_id: string;
+ partner_id: string;
+ folder_id: string;
+ };
+ }) => {
+ const userId = "user_xxx";
+ if (!userId) {
+ throw new Error("No user id found for link");
+ }
+ const { utm_source, utm_medium, utm_campaign, utm_term, utm_content } =
+ getParamsFromURL(result.data.url);
+ const tagIds: string[] = result.data.tag_ids
+ ? JSON.parse(result.data.tag_ids.replace(/'/g, '"'))
+ : [];
+
+ linksToRestore.push({
+ id: result.data.link_id,
+ domain: result.data.domain,
+ key: result.data.key,
+ url: result.data.url,
+ shortLink: linkConstructorSimple({
+ domain: result.data.domain,
+ key: result.data.key,
+ }),
+ projectId: result.data.workspace_id,
+ createdAt: new Date(result.data.created_at),
+ programId: result.data.program_id || null,
+ partnerId: result.data.partner_id || null,
+ folderId: result.data.folder_id || null,
+ utm_source,
+ utm_medium,
+ utm_campaign,
+ utm_term,
+ utm_content,
+ userId,
+ trackConversion: true,
+ });
+
+ if (tagIds.length > 0) {
+ tagIds.forEach((tagId) => {
+ linkTagsToRestore.push({
+ linkId: result.data.link_id,
+ tagId,
+ });
+ });
+ }
+ },
+ complete: async () => {
+ console.log(`Found ${linksToRestore.length} links to restore`);
+
+ const chunks = chunk(linksToRestore, 500);
+ for (const chunk of chunks) {
+ const res = await prisma.link.createMany({
+ data: chunk,
+ skipDuplicates: true,
+ });
+ console.log(`Created ${res.count} links (out of ${chunk.length})`);
+ }
+
+ const linkTagsChunks = chunk(linkTagsToRestore, 500);
+ for (const chunk of linkTagsChunks) {
+ const res = await prisma.linkTag.createMany({
+ data: chunk,
+ skipDuplicates: true,
+ });
+ console.log(`Created ${res.count} link tags (out of ${chunk.length})`);
+ }
+ },
+ });
+}
+
+main();
diff --git a/packages/ui/package.json b/packages/ui/package.json
index 690c983920..83a81c3163 100644
--- a/packages/ui/package.json
+++ b/packages/ui/package.json
@@ -1,7 +1,7 @@
{
"name": "@dub/ui",
"description": "UI components for Dub",
- "version": "0.2.67",
+ "version": "0.2.68",
"sideEffects": false,
"main": "./dist/index.js",
"module": "./dist/index.mjs",
@@ -33,9 +33,9 @@
"check-types": "tsc --noEmit"
},
"peerDependencies": {
- "next": "15.5.4",
- "react": "19.1.1",
- "react-dom": "19.1.1"
+ "next": "15.5.7",
+ "react": "19.1.2",
+ "react-dom": "19.1.2"
},
"devDependencies": {
"@dub/tailwind-config": "workspace:*",
diff --git a/packages/utils/package.json b/packages/utils/package.json
index c88791fdf4..0e50bfc2e5 100644
--- a/packages/utils/package.json
+++ b/packages/utils/package.json
@@ -1,7 +1,7 @@
{
"name": "@dub/utils",
"description": "Utility functions and constants for Dub",
- "version": "0.1.46",
+ "version": "0.1.47",
"sideEffects": false,
"main": "./dist/index.mjs",
"module": "./dist/index.mjs",