The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
fix tests
Steven Tey21b0ffd89129
diff --git a/apps/web/lib/api/links/utils/transform-link.ts b/apps/web/lib/api/links/utils/transform-link.tsindex 18d1213f09..d8f0480be9 100644--- a/apps/web/lib/api/links/utils/transform-link.ts+++ b/apps/web/lib/api/links/utils/transform-link.ts@@ -10,8 +10,11 @@ export const transformLink = (link: LinkWithTags) => {const tags = (link.tags || []).map(({ tag }) => tag);const webhookIds = link.webhooks?.map(({ webhookId }) => webhookId) ?? [];+ // remove webhooks from link+ const { webhooks, ...rest } = link;+return {- ...link,+ ...rest,tagId: tags?.[0]?.id ?? null, // backwards compatibilitytags,webhookIds,diff --git a/apps/web/lib/zod/schemas/webhooks.ts b/apps/web/lib/zod/schemas/webhooks.tsindex c997398221..c2e52419da 100644--- a/apps/web/lib/zod/schemas/webhooks.ts+++ b/apps/web/lib/zod/schemas/webhooks.ts@@ -14,7 +14,7 @@ export const webhookSchema = z.object({});export const createWebhookSchema = z.object({- name: z.string().min(1).max(30),+ name: z.string().min(1).max(40),url: z.string().url().max(190),secret: z.string().startsWith(WEBHOOK_SECRET_PREFIX),triggers: z.array(z.enum(WEBHOOK_TRIGGERS)),diff --git a/apps/web/scripts/create-key.ts b/apps/web/scripts/create-key.tsnew file mode 100644index 0000000000..c318f5f18c--- /dev/null+++ b/apps/web/scripts/create-key.ts@@ -0,0 +1,24 @@+// for backwards compatibility with old personal API keys++import { hashToken } from "@/lib/auth";+import { prisma } from "@/lib/prisma";+import { nanoid } from "@dub/utils";+import "dotenv-flow/config";++async function main() {+ const token = nanoid(24);+ console.log({ token });+ const hashedKey = await hashToken(token);+ // take first 3 and last 4 characters of the key+ const partialKey = `${token.slice(0, 3)}...${token.slice(-4)}`;+ await prisma.token.create({+ data: {+ name: "E2E Test Key",+ hashedKey,+ partialKey,+ userId: "xxx",+ },+ });+}++main();diff --git a/apps/web/tests/links/create-link.test.ts b/apps/web/tests/links/create-link.test.tsindex 1cc151b58b..c461626cd6 100644--- a/apps/web/tests/links/create-link.test.ts+++ b/apps/web/tests/links/create-link.test.ts@@ -425,6 +425,12 @@ describe.sequential("POST /links", async () => {});expect(LinkSchema.strict().parse(link)).toBeTruthy();+ const { status: status2, data: webhook } = await http.get<any>({+ path: `/webhooks/${E2E_WEBHOOK_ID}`,+ });+ expect(status2).toEqual(200);+ expect(webhook.linkIds).toContain(link.id);+afterAll(async () => {await h.deleteLink(link.id);});diff --git a/apps/web/tests/utils/schema.ts b/apps/web/tests/utils/schema.tsindex 272c75ee5e..a5771621da 100644--- a/apps/web/tests/utils/schema.ts+++ b/apps/web/tests/utils/schema.ts@@ -4,7 +4,7 @@ import { expect } from "vitest";export const expectedLink: Partial<Link> & {tagId: string | null;tags: [];- webhooks: [];+ webhookIds: string[];} = {id: expect.any(String),key: expect.any(String),@@ -38,7 +38,7 @@ export const expectedLink: Partial<Link> & {tagId: null, // backwards compatibilitycomments: null,tags: [],- webhooks: [],+ webhookIds: [],createdAt: expect.any(String),updatedAt: expect.any(String),expiredUrl: null,