import { getDomainOrThrow } from "@/lib/api/domains/get-domain-or-throw";
import { DubApiError, ErrorCodes } from "@/lib/api/errors";
import { createLink, processLink } from "@/lib/api/links";
import { throwIfLinksUsageExceeded } from "@/lib/api/links/usage-checks";
import { parseRequestBody } from "@/lib/api/utils";
import { withWorkspace } from "@/lib/auth";
import { ratelimit } from "@/lib/upstash";
import { sendWorkspaceWebhook } from "@/lib/webhook/publish";
import {
createLinkBodySchema,
getLinksQuerySchemaExtended,
linkEventSchema,
} from "@/lib/zod/schemas/links";
import { getSearchParamsWithArray } from "@dub/utils";
import { waitUntil } from "@vercel/functions";
import { NextResponse } from "next/server";
// POST /api/links – create a link
export const POST = withWorkspace(
async ({ req, headers, workspace }) => {
const searchParams = getSearchParamsWithArray(req.url);
const {
domain,