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.

Massive PR – built out most of the app, changed API route structure, added favicons, etc. Still got lots to do though

Steven Teyfc537e5ae81d
diff --git a/components/app/link-card.tsx b/components/app/link-card.tsx
new file mode 100644
index 0000000000..5ac9806a15
--- /dev/null
+++ b/components/app/link-card.tsx
@@ -0,0 +1,67 @@
+import BlurImage from "@/components/shared/blur-image";
+import CopyButton from "@/components/shared/copy-button";
+import { LoadingDots } from "@/components/shared/icons";
+import { useRouter } from "next/router";
+import useSWR from "swr";
+import { fetcher, nFormatter, linkConstructor } from "@/lib/utils";
+import Link from "next/link";
+
+export default function LinkCard({
+ _key: key,
+ url,
+}: {
+ _key: string;
+ url: string;
+}) {
+ const urlHostname = new URL(url).hostname;
+
+ const router = useRouter();
+ const { slug } = router.query as {
+ slug: string;
+ };
+
+ const { data: clicks, isValidating } = useSWR<string>(
+ `/api/projects/${slug}/links/${key}/clicks`,
+ fetcher
+ );
+
+ return (
+ <div className="flex items-center border border-gray-200 dark:border-gray-600 hover:border-black dark:hover:border-white p-3 max-w-md rounded-md transition-all">
+ <BlurImage
+ src={`https://logo.clearbit.com/${urlHostname}`}
+ alt={urlHostname}
+ className="w-10 h-10 rounded-full mr-2 border border-gray-200 dark:border-gray-600"
+ width={20}
+ height={20}
+ />
+ <div>
+ <div className="flex items-center space-x-2 mb-1">
+ <a
+ className="text-blue-800 dark:text-blue-400 font-semibold"
+ href={linkConstructor(key)}
+ target="_blank"
+ rel="noreferrer"
+ >
+ {linkConstructor(key, true)}
+ </a>
+ <CopyButton url={linkConstructor(key)} />
+ <Link href={`${router.asPath}/${encodeURI(key)}`}>
+ <a className="rounded-md bg-gray-100 dark:bg-gray-800 px-2 py-0.5 hover:scale-105 active:scale-95 transition-all duration-75">
+ <p className="text-sm text-gray-500 dark:text-white">
+ {isValidating || !clicks ? (
+ <LoadingDots color="#71717A" />
+ ) : (
+ nFormatter(parseInt(clicks))
+ )}{" "}
+ clicks
+ </p>
+ </a>
+ </Link>
+ </div>
+ <p className="text-sm text-gray-500 dark:text-gray-400 truncate w-72">
+ {url}
+ </p>
+ </div>
+ </div>
+ );
+}
diff --git a/components/home/link-card.tsx b/components/home/link-card.tsx
index d30cb38fb0..d3597e9454 100644
--- a/components/home/link-card.tsx
+++ b/components/home/link-card.tsx
@@ -20,7 +20,7 @@ export default function LinkCard({
const urlHostname = new URL(url).hostname;
const { data: clicks, isValidating } = useSWR<string>(
- `/api/links/${key}/clicks`,
+ `/api/edge/links/${key}/clicks`,
fetcher
);
@@ -50,7 +50,7 @@ export default function LinkCard({
return (
<motion.li
variants={FRAMER_MOTION_LIST_ITEM_VARIANTS}
- className="flex items-center border border-gray-200 dark:border-gray-600 hover:border-black dark:hover:border-white p-3 rounded-md transition-all"
+ className="flex items-center border border-gray-200 dark:border-gray-600 hover:border-black dark:hover:border-white p-3 max-w-md rounded-md transition-all"
>
<BlurImage
src={`https://logo.clearbit.com/${urlHostname}`}
diff --git a/components/home/placeholder-card.tsx b/components/home/placeholder-card.tsx
index edbb9bebf8..d024c53e01 100644
--- a/components/home/placeholder-card.tsx
+++ b/components/home/placeholder-card.tsx
@@ -5,7 +5,7 @@ export default function PlaceholderCard() {
return (
<motion.li
variants={FRAMER_MOTION_LIST_ITEM_VARIANTS}
- className="flex items-center border border-gray-200 dark:border-gray-600 hover:border-black dark:hover:border-white p-3 rounded-md transition-all"
+ className="flex items-center border border-gray-200 dark:border-gray-600 hover:border-black dark:hover:border-white p-3 max-w-md rounded-md transition-all"
>
<div className="w-10 h-10 rounded-full mr-2 bg-gray-200 dark:bg-gray-600 animate-pulse" />
<div>
diff --git a/components/layout/app/index.tsx b/components/layout/app/index.tsx
index 6c967ab332..05d2cd72f9 100644
--- a/components/layout/app/index.tsx
+++ b/components/layout/app/index.tsx
@@ -1,6 +1,15 @@
import { ReactNode } from "react";
+import dynamic from "next/dynamic";
+import Link from "next/link";
import Meta from "../meta";
import { useSession, signOut } from "next-auth/react";
+import { Logo, Divider } from "@/components/shared/icons";
+import ListBox from "./list-box";
+
+const NavTabs = dynamic(() => import("./nav-tabs"), {
+ ssr: false,
+ loading: () => <div className="w-full h-12 -mb-0.5" />,
+}); // dynamic import to avoid react hydration mismatch error
export default function AppLayout({ children }: { children: ReactNode }) {
const { data: session } = useSession();
@@ -8,7 +17,33 @@ export default function AppLayout({ children }: { children: ReactNode }) {
return (
<div>
<Meta />
- {children}
+ <div className="min-h-screen w-full bg-gray-50">
+ <div className="sticky top-0 left-0 right-0 border-b bg-white border-gray-200 z-10">
+ <div className="max-w-screen-xl mx-auto px-5 sm:px-20">
+ <div className="h-10 flex justify-between items-center my-3">
+ <div className="flex items-center">
+ <Link href="/">
+ <a>
+ <Logo className="w-8 h-8 active:scale-95 transition-all duration-75" />
+ </a>
+ </Link>
+ <Divider className="h-8 w-8 ml-3 text-gray-200" />
+ <ListBox />
+ </div>
+ <button className="rounded-full overflow-hidden border border-gray-300 w-10 h-10 flex justify-center items-center active:scale-95 focus:outline-none transition-all duration-75">
+ {session && (
+ <img
+ alt={session?.user?.email || "Avatar for logged in user"}
+ src={`https://avatars.dicebear.com/api/micah/${session?.user?.email}.svg`}
+ />
+ )}
+ </button>
+ </div>
+ <NavTabs />
+ </div>
+ </div>
+ <div className="max-w-screen-xl mx-auto px-5 sm:px-20">{children}</div>
+ </div>
</div>
);
}
diff --git a/components/layout/app/list-box.tsx b/components/layout/app/list-box.tsx
new file mode 100644
index 0000000000..5f05121b4d
--- /dev/null
+++ b/components/layout/app/list-box.tsx
@@ -0,0 +1,102 @@
+import { Fragment, useMemo } from "react";
+import { Listbox, Transition } from "@headlessui/react";
+import { Tick, ChevronUpDown } from "@/components/shared/icons";
+import { useRouter } from "next/router";
+import BlurImage from "@/components/shared/blur-image";
+import useSWR from "swr";
+import { fetcher } from "@/lib/utils";
+import { ProjectProps } from "@/lib/api/types";
+
+export default function ListBox() {
+ const { data: projects } = useSWR<ProjectProps[]>("/api/projects", fetcher);
+
+ const router = useRouter();
+ const selected = useMemo(() => {
+ const { teamSlug } = router.query;
+ return (
+ projects?.find(({ slug }) => slug === teamSlug) || {
+ name: "Dub.sh",
+ slug: "dub",
+ }
+ );
+ }, [router, projects]);
+
+ if (!projects)
+ return (
+ <div className="w-52 h-9 px-2 rounded-lg bg-gray-100 animate-pulse flex justify-end items-center">
+ <ChevronUpDown className="h-4 w-4 text-gray-400" aria-hidden="true" />
+ </div>
+ );
+
+ return (
+ <div className="w-52 -mt-1">
+ <Listbox
+ value={selected}
+ onChange={(e) => {
+ router.push(`/${e.slug}`);
+ }}
+ >
+ <div className="relative mt-1">
+ <Listbox.Button className="relative w-full rounded-lg bg-white hover:bg-gray-100 py-1.5 pl-3 pr-10 text-left focus:outline-none text-sm active:scale-95 transition-all duration-75">
+ <div className="flex justify-start items-center space-x-3">
+ <BlurImage
+ src={`https://avatar.tobi.sh/${selected.slug}`}
+ alt={selected.name}
+ className="w-8 h-8 flex-shrink-0 rounded-full overflow-hidden border border-gray-300"
+ width={48}
+ height={48}
+ />
+ <span className="block truncate font-medium">
+ {selected.name}
+ </span>
+ </div>
+ <span className="pointer-events-none absolute inset-y-0 right-0 flex items-center pr-2">
+ <ChevronUpDown
+ className="h-4 w-4 text-gray-400"
+ aria-hidden="true"
+ />
+ </span>
+ </Listbox.Button>
+ <Transition
+ as={Fragment}
+ leave="transition ease-in duration-100"
+ leaveFrom="opacity-100"
+ leaveTo="opacity-0"
+ >
+ <Listbox.Options className="absolute mt-1 max-h-60 w-60 overflow-auto rounded-md bg-white p-2 text-base shadow-lg ring-1 ring-black ring-opacity-5 focus:outline-none sm:text-sm">
+ {projects.map(({ name, slug }) => (
+ <Listbox.Option
+ key={slug}
+ className={`relative flex items-center space-x-2 cursor-pointer p-2 rounded-md hover:bg-gray-100 active:scale-95 ${
+ selected.slug === slug ? "font-medium" : ""
+ } transition-all duration-75`}
+ value={{ name, slug }}
+ >
+ <BlurImage
+ src={`https://avatar.tobi.sh/${slug}`}
+ alt={name}
+ className="w-7 h-7 flex-shrink-0 rounded-full overflow-hidden border border-gray-300"
+ width={48}
+ height={48}
+ />
+ <span
+ className={`block truncate ${
+ selected.slug === slug ? "font-medium" : "font-normal"
+ }`}
+ >
+ {name}
+ </span>
+ {selected.slug === slug ? (
+ <span className="absolute inset-y-0 right-0 flex items-center pr-3 text-black">
+ <Tick className="h-5 w-5" aria-hidden="true" />
+ </span>
+ ) : null}
+ </Listbox.Option>
+ ))}
+ </Listbox.Options>
+ </Transition>
+ </div>
+ </Listbox>
+ </div>
+ );
+}
diff --git a/components/layout/app/nav-tabs.tsx b/components/layout/app/nav-tabs.tsx
new file mode 100644
index 0000000000..5cfe29dda7
--- /dev/null
+++ b/components/layout/app/nav-tabs.tsx
@@ -0,0 +1,38 @@
+import { useMemo } from "react";
+import Link from "next/link";
+import { NextRouter, useRouter } from "next/router";
+
+const TabsHelper = (router: NextRouter): { name: string; href: string }[] => {
+ const { slug } = router.query;
+ if (slug) {
+ return [{ name: "Overview", href: `/${slug}` }];
+ }
+ return [{ name: "Overview", href: `/` }];
+};
+
+export default function NavTabs() {
+ const router = useRouter();
+ const tabs = useMemo(() => {
+ return TabsHelper(router);
+ }, [router.query]);
+
+ return (
+ <div className="flex justify-start space-x-8 items-center h-12 -mb-0.5">
+ {tabs.map(({ name, href }) => (
+ <Link key={href} href={href}>
+ <a
+ className={`px-1 py-3 border-b-2 ${
+ router.asPath === href
+ ? "border-black font-semibold"
+ : "border-transparent text-gray-700 hover:text-black"
+ } transition-all`}
+ >
+ <p className="text-sm active:scale-95 transition-all duration-75">
+ {name}
+ </p>
+ </a>
+ </Link>
+ ))}
+ </div>
+ );
+}
diff --git a/components/layout/meta.tsx b/components/layout/meta.tsx
index b7bba5d480..d93d354d96 100644
--- a/components/layout/meta.tsx
+++ b/components/layout/meta.tsx
@@ -1,5 +1,7 @@
import Head from "next/head";
+const faviconFolder = "/static/favicons";
+
export default function Meta() {
return (
<Head>
@@ -8,27 +10,54 @@ export default function Meta() {
name="description"
content="An open-source link shortener with built-in analytics and free custom domains."
/>
- <link rel="icon" href="/favicon.ico" />
- <link rel="shortcut icon" type="image/x-icon" href="/favicon.ico" />
- <link rel="apple-touch-icon" sizes="180x180" href="/favicon.ico" />
- <meta name="theme-color" content="#7b46f6" />
+ <link
+ rel="apple-touch-icon"
+ sizes="180x180"
+ href={`${faviconFolder}/apple-touch-icon.png`}
+ />
+ <link
+ rel="icon"
+ type="image/png"
+ sizes="32x32"
+ href={`${faviconFolder}/favicon-32x32.png`}
+ />
+ <link
+ rel="icon"
+ type="image/png"
+ sizes="16x16"
+ href={`${faviconFolder}/favicon-16x16.png`}
+ />
+ <link rel="manifest" href="/site.webmanifest" />
+ <link
+ rel="mask-icon"
+ href={`${faviconFolder}/safari-pinned-tab.svg`}
+ color="#5bbad5"
+ />
+ <meta name="msapplication-TileColor" content="#ffffff" />
+ <meta name="theme-color" content="#ffffff" />
<meta charSet="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="keywords" content="hacker news, slack, bot" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
- <meta itemProp="image" content="https://dub.sh/thumbnail.png" />
- <meta property="og:image" content="https://dub.sh/thumbnail.png" />
+ <meta itemProp="image" content="https://dub.sh/static/thumbnail.png" />
+ <meta property="og:image" content="https://dub.sh/static/thumbnail.png" />
<meta name="twitter:card" content="summary_large_image" />
<meta name="twitter:site" content="@vercel" />
<meta name="twitter:creator" content="@steventey" />
- <meta name="twitter:title" content="Dub - Open-Source Link Shortener" />
+ <meta
+ name="twitter:title"
+ content="Dub - Open-Source Bitly Alternative"
+ />
<meta
name="twitter:description"
content="An open-source link shortener with built-in analytics and free custom domains."
/>
- <meta name="twitter:image" content="https://dub.sh/thumbnail.png" />
+ <meta
+ name="twitter:image"
+ content="https://dub.sh/static/thumbnail.png"
+ />
</Head>
);
}
diff --git a/components/shared/icons/chevron-down.tsx b/components/shared/icons/chevron-down.tsx
new file mode 100644
index 0000000000..dea1e85cdd
--- /dev/null
+++ b/components/shared/icons/chevron-down.tsx
@@ -0,0 +1,18 @@
+export default function ChevronDown({ className }: { className?: string }) {
+ return (
+ <svg
+ className={className}
+ viewBox="0 0 24 24"
+ width="24"
+ height="24"
+ stroke="currentColor"
+ strokeWidth="2"
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ fill="none"
+ shapeRendering="geometricPrecision"
+ >
+ <path d="M6 9l6 6 6-6" />
+ </svg>
+ );
+}
diff --git a/components/shared/icons/chevron-left.tsx b/components/shared/icons/chevron-left.tsx
new file mode 100644
index 0000000000..d79b2beb38
--- /dev/null
+++ b/components/shared/icons/chevron-left.tsx
@@ -0,0 +1,18 @@
+export default function ChevronLeft({ className }: { className?: string }) {
+ return (
+ <svg
+ className={className}
+ viewBox="0 0 24 24"
+ width="24"
+ height="24"
+ stroke="currentColor"
+ strokeWidth="2"
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ fill="none"
+ shapeRendering="geometricPrecision"
+ >
+ <path d="M15 18l-6-6 6-6" />
+ </svg>
+ );
+}
diff --git a/components/shared/icons/chevron-right.tsx b/components/shared/icons/chevron-right.tsx
new file mode 100644
index 0000000000..6d960f28a8
--- /dev/null
+++ b/components/shared/icons/chevron-right.tsx
@@ -0,0 +1,18 @@
+export default function ChevronRight({ className }: { className?: string }) {
+ return (
+ <svg
+ className={className}
+ viewBox="0 0 24 24"
+ width="24"
+ height="24"
+ stroke="currentColor"
+ strokeWidth="2"
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ fill="none"
+ shapeRendering="geometricPrecision"
+ >
+ <path d="M9 18l6-6-6-6" />
+ </svg>
+ );
+}
diff --git a/components/shared/icons/chevron-up-down.tsx b/components/shared/icons/chevron-up-down.tsx
new file mode 100644
index 0000000000..89254048ec
--- /dev/null
+++ b/components/shared/icons/chevron-up-down.tsx
@@ -0,0 +1,18 @@
+export default function ChevronUpDown({ className }: { className?: string }) {
+ return (
+ <svg
+ className={className}
+ viewBox="0 0 24 24"
+ width="24"
+ height="24"
+ stroke="currentColor"
+ strokeWidth="2"
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ fill="none"
+ shapeRendering="geometricPrecision"
+ >
+ <path d="M17 8.517L12 3 7 8.517M7 15.48l5 5.517 5-5.517" />
+ </svg>
+ );
+}
diff --git a/components/shared/icons/divider.tsx b/components/shared/icons/divider.tsx
new file mode 100644
index 0000000000..6c93adef23
--- /dev/null
+++ b/components/shared/icons/divider.tsx
@@ -0,0 +1,18 @@
+export default function Divider({ className }: { className: string }) {
+ return (
+ <svg
+ fill="none"
+ shapeRendering="geometricPrecision"
+ stroke="currentColor"
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ strokeWidth="1"
+ viewBox="0 0 24 24"
+ width="14"
+ height="14"
+ className={className}
+ >
+ <path d="M16.88 3.549L7.12 20.451" />{" "}
+ </svg>
+ );
+}
diff --git a/components/shared/icons/github.tsx b/components/shared/icons/github.tsx
new file mode 100644
index 0000000000..d4f44e3a75
--- /dev/null
+++ b/components/shared/icons/github.tsx
@@ -0,0 +1,11 @@
+export default function Github() {
+ <svg
+ xmlns="http://www.w3.org/2000/svg"
+ width="20"
+ height="20"
+ fill="currentColor"
+ viewBox="0 0 24 24"
+ >
+ <path d="M12 0c-6.626 0-12 5.373-12 12 0 5.302 3.438 9.8 8.207 11.387.599.111.793-.261.793-.577v-2.234c-3.338.726-4.033-1.416-4.033-1.416-.546-1.387-1.333-1.756-1.333-1.756-1.089-.745.083-.729.083-.729 1.205.084 1.839 1.237 1.839 1.237 1.07 1.834 2.807 1.304 3.492.997.107-.775.418-1.305.762-1.604-2.665-.305-5.467-1.334-5.467-5.931 0-1.311.469-2.381 1.236-3.221-.124-.303-.535-1.524.117-3.176 0 0 1.008-.322 3.301 1.23.957-.266 1.983-.399 3.003-.404 1.02.005 2.047.138 3.006.404 2.291-1.552 3.297-1.23 3.297-1.23.653 1.653.242 2.874.118 3.176.77.84 1.235 1.911 1.235 3.221 0 4.609-2.807 5.624-5.479 5.921.43.372.823 1.102.823 2.222v3.293c0 .319.192.694.801.576 4.765-1.589 8.199-6.086 8.199-11.386 0-6.627-5.373-12-12-12z" />
+ </svg>;
+}
diff --git a/components/shared/icons/index.tsx b/components/shared/icons/index.tsx
index 321bdf9e65..8cb3fe03e2 100644
--- a/components/shared/icons/index.tsx
+++ b/components/shared/icons/index.tsx
@@ -4,3 +4,10 @@ export { default as Tick } from "./tick";
export { default as Copy } from "./copy";
export { default as X } from "./x";
export { default as Chart } from "./chart";
+export { default as Divider } from "./divider";
+export { default as Logo } from "./logo";
+export { default as Github } from "./github";
+export { default as ChevronRight } from "./chevron-right";
+export { default as ChevronLeft } from "./chevron-left";
+export { default as ChevronDown } from "./chevron-down";
+export { default as ChevronUpDown } from "./chevron-up-down";
diff --git a/components/shared/icons/logo.tsx b/components/shared/icons/logo.tsx
new file mode 100644
index 0000000000..8a93e557f3
--- /dev/null
+++ b/components/shared/icons/logo.tsx
@@ -0,0 +1,41 @@
+export default function Logo({ className }: { className: string }) {
+ return (
+ <svg
+ width="191"
+ height="191"
+ fill="none"
+ viewBox="0 0 191 191"
+ className={className}
+ >
+ <g clipPath="url(#clip0_36_30)">
+ <path
+ fill="#000"
+ d="M191 95.5c0 52.743-42.757 95.5-95.5 95.5S0 148.243 0 95.5 42.757 0 95.5 0 191 42.757 191 95.5z"
+ ></path>
+ <mask
+ id="mask0_36_30"
+ style={{ maskType: "alpha" }}
+ width="191"
+ height="191"
+ x="0"
+ y="0"
+ maskUnits="userSpaceOnUse"
+ >
+ <path
+ fill="#000"
+ d="M191 95.5c0 52.743-42.757 95.5-95.5 95.5S0 148.243 0 95.5 42.757 0 95.5 0 191 42.757 191 95.5z"
+ ></path>
+ </mask>
+ <g fill="#fff" mask="url(#mask0_36_30)">
+ <circle cx="95" cy="100" r="49"></circle>
+ <path d="M122-14h22v162h-22V-14z"></path>
+ </g>
+ </g>
+ <defs>
+ <clipPath id="clip0_36_30">
+ <path fill="#fff" d="M0 0H191V191H0z"></path>
+ </clipPath>
+ </defs>{" "}
+ </svg>
+ );
+}
diff --git a/components/stats/device-icon.tsx b/components/stats/device-icon.tsx
index 3c264cb95d..bf2dc3eeb2 100644
--- a/components/stats/device-icon.tsx
+++ b/components/stats/device-icon.tsx
@@ -1,6 +1,6 @@
import { DeviceTabs } from "@/lib/stats";
import { Chrome, Safari, Apple } from "components/shared/icons/devices";
-import Image from "next/future/image";
+import BlurImage from "@/components/shared/blur-image";
export default function DeviceIcon({
display,
@@ -22,7 +22,7 @@ export default function DeviceIcon({
}
if (tab === "device") {
return (
- <Image
+ <BlurImage
src={
display === "Desktop"
? `https://faisalman.github.io/ua-parser-js/images/types/default.png`
@@ -42,23 +42,20 @@ export default function DeviceIcon({
return <Safari className={className} />;
} else {
return (
- <Image
+ <BlurImage
src={`https://faisalman.github.io/ua-parser-js/images/browsers/${display.toLowerCase()}.png`}
alt={display}
width={20}
height={20}
className={className}
- onError={(e) => {
- e.currentTarget.src = `https://faisalman.github.io/ua-parser-js/images/browsers/default.png`;
- }}
/>
);
}
} else if (tab === "os") {
if (display === "Mac OS") {
return (
- <Image
- src="/icons/macos.png"
+ <BlurImage
+ src="/static/icons/macos.png"
alt={display}
width={20}
height={20}
@@ -69,15 +66,12 @@ export default function DeviceIcon({
return <Apple className="w-5 h-5 -ml-1" />;
} else {
return (
- <Image
+ <BlurImage
src={`https://faisalman.github.io/ua-parser-js/images/os/${display.toLowerCase()}.png`}
alt={display}
width={30}
height={20}
className="w-5 h-4"
- onError={(e) => {
- e.currentTarget.src = `https://faisalman.github.io/ua-parser-js/images/os/default.png`;
- }}
/>
);
}
@@ -91,7 +85,7 @@ export default function DeviceIcon({
);
} else {
return (
- <Image
+ <BlurImage
src={`https://faisalman.github.io/ua-parser-js/images/companies/default.png`}
alt={display}
width={20}
diff --git a/components/stats/index.tsx b/components/stats/index.tsx
index 02bb4827c7..fc125d5577 100644
--- a/components/stats/index.tsx
+++ b/components/stats/index.tsx
@@ -12,7 +12,7 @@ export default function Stats() {
const { data, isValidating } = useSWR<StatsProps>(
router.query.key &&
- `/api/links/${router.query.key}/stats${
+ `/api/edge/links/${router.query.key}/stats${
router.query.interval ? `?interval=${router.query.interval}` : ""
}`,
fetcher,
diff --git a/lib/api/auth.ts b/lib/api/auth.ts
new file mode 100644
index 0000000000..2e8b173bab
--- /dev/null
+++ b/lib/api/auth.ts
@@ -0,0 +1,20 @@
+import { NextApiRequest, NextApiResponse } from "next";
+import { unstable_getServerSession } from "next-auth/next";
+import { authOptions } from "@/pages/api/auth/[...nextauth]";
+
+interface Session {
+ user: {
+ email?: string | null;
+ id?: string | null;
+ name?: string | null;
+ };
+}
+
+export async function getSession(req: NextApiRequest, res: NextApiResponse) {
+ const session = (await unstable_getServerSession(
+ req,
+ res,
+ authOptions
+ )) as Session | null;
+ return session;
+}
diff --git a/lib/api/links.ts b/lib/api/links.ts
new file mode 100644
index 0000000000..3cb768602d
--- /dev/null
+++ b/lib/api/links.ts
@@ -0,0 +1,33 @@
+import { redis } from "@/lib/redis";
+import { customAlphabet } from "nanoid";
+
+const nanoid = customAlphabet(
+ "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",
+ 7
+); // 7-character random string
+
+export async function setRandomKey(
+ url: string
+): Promise<{ response: number; key: string }> {
+ /* recursively set link till successful */
+ const key = nanoid();
+ const response = await redis.hsetnx(`dub.sh:links`, key, url); // add to hash
+ if (response === 0) {
+ // by the off chance that key already exists
+ return setRandomKey(url);
+ } else {
+ return { response, key };
+ }
+}
+
+export async function getRandomKey(): Promise<string> {
+ /* recursively get random key till it gets one that's avaialble */
+ const key = nanoid();
+ const response = await redis.hexists(`dub.sh:links`, key); // check if key exists
+ if (response === 1) {
+ // by the off chance that key already exists
+ return getRandomKey();
+ } else {
+ return key;
+ }
+}
diff --git a/lib/api/types.ts b/lib/api/types.ts
new file mode 100644
index 0000000000..1a7c680278
--- /dev/null
+++ b/lib/api/types.ts
@@ -0,0 +1,10 @@
+export interface LinkProps {
+ key: string;
+ url: string;
+}
+
+export interface ProjectProps {
+ name: string;
+ slug: string;
+ links: LinkProps[];
+}
diff --git a/lib/constants.ts b/lib/constants.ts
index b7253c0ed1..0532e6c551 100644
--- a/lib/constants.ts
+++ b/lib/constants.ts
@@ -13,7 +13,7 @@ export const FRAMER_MOTION_LIST_ITEM_VARIANTS = {
show: { scale: 1, opacity: 1, transition: { type: "spring" } },
};
-export const RESERVED_KEYS = ["pricing", "about"];
+export const RESERVED_KEYS = ["pricing", "about", "stats"];
export const COUNTRIES: { [key: string]: string } = {
AF: "Afghanistan",
diff --git a/lib/middleware/app.ts b/lib/middleware/app.ts
index 3c2664ec7a..428c279e7f 100644
--- a/lib/middleware/app.ts
+++ b/lib/middleware/app.ts
@@ -5,7 +5,6 @@ import { getToken } from "next-auth/jwt";
export default async function AppMiddleware(req: NextRequest) {
const { path } = parse(req);
const session = await getToken({ req, secret: process.env.NEXTAUTH_SECRET });
- console.log(session);
if (!session && path !== "/login") {
return NextResponse.redirect(new URL("/login", req.url));
} else if (session && path === "/login") {
diff --git a/lib/middleware/link.ts b/lib/middleware/link.ts
index 53729e70e1..e1374de1ec 100644
--- a/lib/middleware/link.ts
+++ b/lib/middleware/link.ts
@@ -22,6 +22,7 @@ export default async function LinkMiddleware(
member: {
geo: process.env.VERCEL === "1" ? req.geo : LOCALHOST_GEO_DATA,
ua: userAgent(req),
+ referer: req.headers.get("referer"),
timestamp: Date.now(),
},
})
diff --git a/lib/middleware/utils.ts b/lib/middleware/utils.ts
index 4d75547eb3..dcb9939c9e 100644
--- a/lib/middleware/utils.ts
+++ b/lib/middleware/utils.ts
@@ -1,4 +1,5 @@
import { NextRequest } from "next/server";
+import { RESERVED_KEYS } from "@/lib/constants";
export const parse = (req: NextRequest) => {
let hostname = req.headers.get("host");
diff --git a/lib/prisma.ts b/lib/prisma.ts
new file mode 100644
index 0000000000..10082dc2b2
--- /dev/null
+++ b/lib/prisma.ts
@@ -0,0 +1,11 @@
+import { PrismaClient } from "@prisma/client";
+
+declare global {
+ var prisma: PrismaClient | undefined;
+}
+
+const prisma = global.prisma || new PrismaClient();
+
+if (process.env.NODE_ENV === "development") global.prisma = prisma;
+
+export default prisma;
diff --git a/lib/stripe.ts b/lib/stripe.ts
new file mode 100644
index 0000000000..8d8b9d00e9
--- /dev/null
+++ b/lib/stripe.ts
@@ -0,0 +1,15 @@
+import Stripe from "stripe";
+
+export const stripe = new Stripe(
+ process.env.STRIPE_SECRET_KEY_LIVE ?? process.env.STRIPE_SECRET_KEY ?? "",
+ {
+ // https://github.com/stripe/stripe-node#usage-with-typescript
+ apiVersion: "2022-08-01",
+ // Register this as an official Stripe plugin.
+ // https://stripe.com/docs/building-plugins#setappinfo
+ appInfo: {
+ name: "Dub.sh",
+ version: "0.1.0",
+ },
+ }
+);
diff --git a/lib/utils.ts b/lib/utils.ts
index eea8f26274..d38fed5e96 100644
--- a/lib/utils.ts
+++ b/lib/utils.ts
@@ -4,8 +4,18 @@ export async function fetcher<JSON = any>(
): Promise<JSON> {
const res = await fetch(input, init);
- if (!res.ok && res.status === 401) {
- throw new Error("Unauthorized");
+ if (!res.ok) {
+ if (res.status === 401) {
+ throw new Error("Unauthorized");
+ } else if (res.status === 403) {
+ throw new Error("Forbidden");
+ } else if (res.status === 404) {
+ throw new Error("Not Found");
+ } else if (res.status === 500) {
+ throw new Error("Internal Server Error");
+ } else {
+ throw new Error("An unexpected error occurred");
+ }
}
return res.json();
diff --git a/middleware.ts b/middleware.ts
index 3a2d5fbe04..1c19f147a3 100644
--- a/middleware.ts
+++ b/middleware.ts
@@ -8,7 +8,10 @@ import { parse } from "@/lib/middleware/utils";
import { RESERVED_KEYS } from "@/lib/constants";
export const config = {
- matcher: "/([^/.]*)",
+ matcher: [
+ // Comment to force multi-line for better diffs
+ "/((?!api|_next|static|app|favicon.ico|site.webmanifest).*)",
+ ],
};
export default async function middleware(req: NextRequest, ev: NextFetchEvent) {
diff --git a/next.config.js b/next.config.js
index 3c84eb066d..0750ebb250 100644
--- a/next.config.js
+++ b/next.config.js
@@ -2,6 +2,11 @@
module.exports = {
reactStrictMode: true,
images: {
- domains: ["logo.clearbit.com", "avatar.tobi.sh", "faisalman.github.io"],
+ domains: [
+ "logo.clearbit.com",
+ "avatar.tobi.sh",
+ "faisalman.github.io",
+ "avatars.dicebear.com",
+ ],
},
};
diff --git a/package-lock.json b/package-lock.json
index 82f1722074..036e0f9a61 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -6,7 +6,8 @@
"": {
"dependencies": {
"@headlessui/react": "^1.6.6",
- "@next-auth/upstash-redis-adapter": "^3.0.1",
+ "@next-auth/prisma-adapter": "^1.0.4",
+ "@prisma/client": "^4.3.1",
"@tailwindcss/forms": "^0.5.3",
"@upstash/redis": "^1.12.0",
"@visx/axis": "^2.12.2",
@@ -22,8 +23,10 @@
"next-auth": "^4.10.3",
"nodemailer": "^6.7.8",
"npm": "^8.19.0",
- "react": "^18.2.0",
+ "prisma": "^4.3.1",
+ "react": "^18.1.0",
"react-dom": "18.1.0",
+ "stripe": "^10.7.0",
"swr": "^2.0.0-beta.1",
"tailwind-scrollbar-hide": "^1.1.7",
"topojson-client": "^3.1.0"
@@ -140,15 +143,12 @@
"tslib": "^2.3.1"
}
},
- "node_modules/@next-auth/upstash-redis-adapter": {
- "version": "3.0.1",
- "resolved": "https://registry.npmjs.org/@next-auth/upstash-redis-adapter/-/upstash-redis-adapter-3.0.1.tgz",
- "integrity": "sha512-1nqS2tUCFR8ehM+mL/SRZL0sFlMOJfFXS7f3sZCy6xLpjfYnCJSPnDkm95pWMQE6u4gWS08ehADF6LDYcl79Uw==",
- "dependencies": {
- "uuid": "^8.3.2"
- },
+ "node_modules/@next-auth/prisma-adapter": {
+ "version": "1.0.4",
+ "resolved": "https://registry.npmjs.org/@next-auth/prisma-adapter/-/prisma-adapter-1.0.4.tgz",
+ "integrity": "sha512-jIOM6CzCbl2/Mzbx9kb2IjtHoJOeRN9wtQgLk4EUm5bhneSVGv1rtz5TDskvp2UfCa+EK9nDmug+lje41z80Gg==",
"peerDependencies": {
- "@upstash/redis": "^1.0.1",
+ "@prisma/client": ">=2.26.0 || >=3",
"next-auth": "^4"
}
},
@@ -395,6 +395,37 @@
"url": "https://github.com/sponsors/panva"
}
},
+ "node_modules/@prisma/client": {
+ "version": "4.3.1",
+ "resolved": "https://registry.npmjs.org/@prisma/client/-/client-4.3.1.tgz",
+ "integrity": "sha512-FA0/d1VMJNWqzU7WVWTNWJ+lGOLR9JUBnF73GdIPAEVo/6dWk4gHx0EmgeU+SMv4MZoxgOeTBJF2azhg7x0hMw==",
+ "hasInstallScript": true,
+ "dependencies": {
+ "@prisma/engines-version": "4.3.0-32.c875e43600dfe042452e0b868f7a48b817b9640b"
+ },
+ "engines": {
+ "node": ">=14.17"
+ },
+ "peerDependencies": {
+ "prisma": "*"
+ },
+ "peerDependenciesMeta": {
+ "prisma": {
+ "optional": true
+ }
+ }
+ },
+ "node_modules/@prisma/engines": {
+ "version": "4.3.1",
+ "resolved": "https://registry.npmjs.org/@prisma/engines/-/engines-4.3.1.tgz",
+ "integrity": "sha512-4JF/uMaEDAPdcdZNOrnzE3BvrbGpjgV0FcPT3EVoi6I86fWkloqqxBt+KcK/+fIRR0Pxj66uGR9wVH8U1Y13JA==",
+ "hasInstallScript": true
+ },
+ "node_modules/@prisma/engines-version": {
+ "version": "4.3.0-32.c875e43600dfe042452e0b868f7a48b817b9640b",
+ "resolved": "https://registry.npmjs.org/@prisma/engines-version/-/engines-version-4.3.0-32.c875e43600dfe042452e0b868f7a48b817b9640b.tgz",
+ "integrity": "sha512-8yWpXkQRmiSfsi2Wb/ZS5D3RFbeu/btL9Pm/gdF4phB0Lo5KGsDFMxFMgaD64mwED2nHc8ZaEJg/+4Jymb9Znw=="
+ },
"node_modules/@swc/helpers": {
"version": "0.4.3",
"resolved": "https://registry.npmjs.org/@swc/helpers/-/helpers-0.4.3.tgz",
@@ -476,7 +507,6 @@
"version": "17.0.35",
"resolved": "https://registry.npmjs.org/@types/node/-/node-17.0.35.tgz",
"integrity": "sha512-vu1SrqBjbbZ3J6vwY17jBs8Sr/BKA+/a/WtjRG+whKg1iuLFOosq872EXS0eXWILdO36DHQQeku/ZcL6hz2fpg==",
- "dev": true,
"license": "MIT"
},
"node_modules/@types/prop-types": {
@@ -874,6 +904,18 @@
"node": "^6 || ^7 || ^8 || ^9 || ^10 || ^11 || ^12 || >=13.7"
}
},
+ "node_modules/call-bind": {
+ "version": "1.0.2",
+ "resolved": "https://registry.npmjs.org/call-bind/-/call-bind-1.0.2.tgz",
+ "integrity": "sha512-7O+FbCihrB5WGbFYesctwmTKae6rOiIzmz1icreWJ+0aA7LJfuqhEso2T9ncpcFtzMQtzXf2QGGueWJGTYsqrA==",
+ "dependencies": {
+ "function-bind": "^1.1.1",
+ "get-intrinsic": "^1.0.2"
+ },
+ "funding": {
+ "url": "https://github.com/sponsors/ljharb"
+ }
+ },
"node_modules/camelcase-css": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/camelcase-css/-/camelcase-css-2.0.1.tgz",
@@ -1203,6 +1245,19 @@
"integrity": "sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A==",
"license": "MIT"
},
+ "node_modules/get-intrinsic": {
+ "version": "1.1.2",
+ "resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.1.2.tgz",
+ "integrity": "sha512-Jfm3OyCxHh9DJyc28qGk+JmfkpO41A4XkneDSujN9MDXrm4oDKdHvndhZ2dN94+ERNfkYJWDclW6k2L/ZGHjXA==",
+ "dependencies": {
+ "function-bind": "^1.1.1",
+ "has": "^1.0.3",
+ "has-symbols": "^1.0.3"
+ },
+ "funding": {
+ "url": "https://github.com/sponsors/ljharb"
+ }
+ },
"node_modules/glob-parent": {
"version": "5.1.2",
"resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-5.1.2.tgz",
@@ -1227,6 +1282,17 @@
"node": ">= 0.4.0"
}
},
+ "node_modules/has-symbols": {
+ "version": "1.0.3",
+ "resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.0.3.tgz",
+ "integrity": "sha512-l3LCuF6MgDNwTDKkdYGEihYjt5pRPbEg46rtlmnSPlUbgmB8LOIrKJbYYFBSbnPaJexMKtiPO8hmeRjRz2Td+A==",
+ "engines": {
+ "node": ">= 0.4"
+ },
+ "funding": {
+ "url": "https://github.com/sponsors/ljharb"
+ }
+ },
"node_modules/hey-listen": {
"version": "1.0.8",
"resolved": "https://registry.npmjs.org/hey-listen/-/hey-listen-1.0.8.tgz",
@@ -3662,6 +3728,8 @@
},
"node_modules/npm/node_modules/semver/node_modules/lru-cache": {
"version": "6.0.0",
+ "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz",
+ "integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==",
"inBundle": true,
"license": "ISC",
"dependencies": {
@@ -3962,6 +4030,14 @@
"node": ">= 6"
}
},
+ "node_modules/object-inspect": {
+ "version": "1.12.2",
+ "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.12.2.tgz",
+ "integrity": "sha512-z+cPxW0QGUp0mcqcsgQyLVRDoXFQbXOwBaqyF7VIgI4TWNQsDHrBpUQslRmIfAoYWdYzs6UlKJtB2XJpTaNSpQ==",
+ "funding": {
+ "url": "https://github.com/sponsors/ljharb"
+ }
+ },
"node_modules/oidc-token-hash": {
"version": "5.0.1",
"resolved": "https://registry.npmjs.org/oidc-token-hash/-/oidc-token-hash-5.0.1.tgz",
@@ -4191,6 +4267,22 @@
"resolved": "https://registry.npmjs.org/pretty-format/-/pretty-format-3.8.0.tgz",
"integrity": "sha512-WuxUnVtlWL1OfZFQFuqvnvs6MiAGk9UNsBostyBOB0Is9wb5uRESevA6rnl/rkksXaGX3GzZhPup5d6Vp1nFew=="
},
+ "node_modules/prisma": {
+ "version": "4.3.1",
+ "resolved": "https://registry.npmjs.org/prisma/-/prisma-4.3.1.tgz",
+ "integrity": "sha512-90xo06wtqil76Xsi3mNpc4Js3SdDRR5g4qb9h+4VWY4Y8iImJY6xc3PX+C9xxTSt1lr0Q89A0MLkJjd8ax6KiQ==",
+ "hasInstallScript": true,
+ "dependencies": {
+ "@prisma/engines": "4.3.1"
+ },
+ "bin": {
+ "prisma": "build/index.js",
+ "prisma2": "build/index.js"
+ },
+ "engines": {
+ "node": ">=14.17"
+ }
+ },
"node_modules/prop-types": {
"version": "15.8.1",
"resolved": "https://registry.npmjs.org/prop-types/-/prop-types-15.8.1.tgz",
@@ -4201,6 +4293,20 @@
"react-is": "^16.13.1"
}
},
+ "node_modules/qs": {
+ "version": "6.11.0",
+ "resolved": "https://registry.npmjs.org/qs/-/qs-6.11.0.tgz",
+ "integrity": "sha512-MvjoMCJwEarSbUYk5O+nmoSzSutSsTwF85zcHPQ9OrlFoZOYIjaqBAJIqIXjptyD5vThxGq52Xu/MaJzRkIk4Q==",
+ "dependencies": {
+ "side-channel": "^1.0.4"
+ },
+ "engines": {
+ "node": ">=0.6"
+ },
+ "funding": {
+ "url": "https://github.com/sponsors/ljharb"
+ }
+ },
"node_modules/queue-microtask": {
"version": "1.2.3",
"resolved": "https://registry.npmjs.org/queue-microtask/-/queue-microtask-1.2.3.tgz",
@@ -4234,9 +4340,9 @@
}
},
"node_modules/react": {
- "version": "18.2.0",
- "resolved": "https://registry.npmjs.org/react/-/react-18.2.0.tgz",
- "integrity": "sha512-/3IjMdb2L9QbBdWiW5e3P2/npwMBaU9mHCSCUzNln0ZCYbcfTsGbTJrU/kGemdH2IWmB2ioZ+zkxtmq6g09fGQ==",
+ "version": "18.1.0",
+ "resolved": "https://registry.npmjs.org/react/-/react-18.1.0.tgz",
+ "integrity": "sha512-4oL8ivCz5ZEPyclFQXaNksK3adutVS8l2xzZU0cqEFrE9Sb7fC0EFK5uEk74wIreL1DERyjvsU915j1pcT2uEQ==",
"dependencies": {
"loose-envify": "^1.1.0"
},
@@ -4382,6 +4488,19 @@
"loose-envify": "^1.1.0"
}
},
+ "node_modules/side-channel": {
+ "version": "1.0.4",
+ "resolved": "https://registry.npmjs.org/side-channel/-/side-channel-1.0.4.tgz",
+ "integrity": "sha512-q5XPytqFEIKHkGdiMIrY10mvLRvnQh42/+GoBlFW3b2LXLE2xxJpZFdm94we0BaoV3RwJyGqg5wS7epxTv0Zvw==",
+ "dependencies": {
+ "call-bind": "^1.0.0",
+ "get-intrinsic": "^1.0.2",
+ "object-inspect": "^1.9.0"
+ },
+ "funding": {
+ "url": "https://github.com/sponsors/ljharb"
+ }
+ },
"node_modules/source-map-js": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/source-map-js/-/source-map-js-1.0.2.tgz",
@@ -4391,6 +4510,18 @@
"node": ">=0.10.0"
}
},
+ "node_modules/stripe": {
+ "version": "10.7.0",
+ "resolved": "https://registry.npmjs.org/stripe/-/stripe-10.7.0.tgz",
+ "integrity": "sha512-yCd8xTPaPLps7BYJL3FuBwza6A4TcYvE074bCEpN5xJUYBUYN4lly0F275HkUa7QODXn8UjO93oIanV/L6O14w==",
+ "dependencies": {
+ "@types/node": ">=8.1.0",
+ "qs": "^6.10.3"
+ },
+ "engines": {
+ "node": "^8.1 || >=10.*"
+ }
+ },
"node_modules/style-value-types": {
"version": "5.1.2",
"resolved": "https://registry.npmjs.org/style-value-types/-/style-value-types-5.1.2.tgz",
@@ -4739,13 +4870,11 @@
"tslib": "^2.3.1"
}
},
- "@next-auth/upstash-redis-adapter": {
- "version": "3.0.1",
- "resolved": "https://registry.npmjs.org/@next-auth/upstash-redis-adapter/-/upstash-redis-adapter-3.0.1.tgz",
- "integrity": "sha512-1nqS2tUCFR8ehM+mL/SRZL0sFlMOJfFXS7f3sZCy6xLpjfYnCJSPnDkm95pWMQE6u4gWS08ehADF6LDYcl79Uw==",
- "requires": {
- "uuid": "^8.3.2"
- }
+ "@next-auth/prisma-adapter": {
+ "version": "1.0.4",
+ "resolved": "https://registry.npmjs.org/@next-auth/prisma-adapter/-/prisma-adapter-1.0.4.tgz",
+ "integrity": "sha512-jIOM6CzCbl2/Mzbx9kb2IjtHoJOeRN9wtQgLk4EUm5bhneSVGv1rtz5TDskvp2UfCa+EK9nDmug+lje41z80Gg==",
+ "requires": {}
},
"@next/env": {
"version": "12.2.6-canary.8",
@@ -4858,6 +4987,24 @@
"resolved": "https://registry.npmjs.org/@panva/hkdf/-/hkdf-1.0.2.tgz",
"integrity": "sha512-MSAs9t3Go7GUkMhpKC44T58DJ5KGk2vBo+h1cqQeqlMfdGkxaVB78ZWpv9gYi/g2fa4sopag9gJsNvS8XGgWJA=="
},
+ "@prisma/client": {
+ "version": "4.3.1",
+ "resolved": "https://registry.npmjs.org/@prisma/client/-/client-4.3.1.tgz",
+ "integrity": "sha512-FA0/d1VMJNWqzU7WVWTNWJ+lGOLR9JUBnF73GdIPAEVo/6dWk4gHx0EmgeU+SMv4MZoxgOeTBJF2azhg7x0hMw==",
+ "requires": {
+ "@prisma/engines-version": "4.3.0-32.c875e43600dfe042452e0b868f7a48b817b9640b"
+ }
+ },
+ "@prisma/engines": {
+ "version": "4.3.1",
+ "resolved": "https://registry.npmjs.org/@prisma/engines/-/engines-4.3.1.tgz",
+ "integrity": "sha512-4JF/uMaEDAPdcdZNOrnzE3BvrbGpjgV0FcPT3EVoi6I86fWkloqqxBt+KcK/+fIRR0Pxj66uGR9wVH8U1Y13JA=="
+ },
+ "@prisma/engines-version": {
+ "version": "4.3.0-32.c875e43600dfe042452e0b868f7a48b817b9640b",
+ "resolved": "https://registry.npmjs.org/@prisma/engines-version/-/engines-version-4.3.0-32.c875e43600dfe042452e0b868f7a48b817b9640b.tgz",
+ "integrity": "sha512-8yWpXkQRmiSfsi2Wb/ZS5D3RFbeu/btL9Pm/gdF4phB0Lo5KGsDFMxFMgaD64mwED2nHc8ZaEJg/+4Jymb9Znw=="
+ },
"@swc/helpers": {
"version": "0.4.3",
"resolved": "https://registry.npmjs.org/@swc/helpers/-/helpers-0.4.3.tgz",
@@ -4934,8 +5081,7 @@
"@types/node": {
"version": "17.0.35",
"resolved": "https://registry.npmjs.org/@types/node/-/node-17.0.35.tgz",
- "integrity": "sha512-vu1SrqBjbbZ3J6vwY17jBs8Sr/BKA+/a/WtjRG+whKg1iuLFOosq872EXS0eXWILdO36DHQQeku/ZcL6hz2fpg==",
- "dev": true
+ "integrity": "sha512-vu1SrqBjbbZ3J6vwY17jBs8Sr/BKA+/a/WtjRG+whKg1iuLFOosq872EXS0eXWILdO36DHQQeku/ZcL6hz2fpg=="
},
"@types/prop-types": {
"version": "15.7.5",
@@ -5238,6 +5384,15 @@
"update-browserslist-db": "^1.0.5"
}
},
+ "call-bind": {
+ "version": "1.0.2",
+ "resolved": "https://registry.npmjs.org/call-bind/-/call-bind-1.0.2.tgz",
+ "integrity": "sha512-7O+FbCihrB5WGbFYesctwmTKae6rOiIzmz1icreWJ+0aA7LJfuqhEso2T9ncpcFtzMQtzXf2QGGueWJGTYsqrA==",
+ "requires": {
+ "function-bind": "^1.1.1",
+ "get-intrinsic": "^1.0.2"
+ }
+ },
"camelcase-css": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/camelcase-css/-/camelcase-css-2.0.1.tgz",
@@ -5484,6 +5639,16 @@
"resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz",
"integrity": "sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A=="
},
+ "get-intrinsic": {
+ "version": "1.1.2",
+ "resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.1.2.tgz",
+ "integrity": "sha512-Jfm3OyCxHh9DJyc28qGk+JmfkpO41A4XkneDSujN9MDXrm4oDKdHvndhZ2dN94+ERNfkYJWDclW6k2L/ZGHjXA==",
+ "requires": {
+ "function-bind": "^1.1.1",
+ "has": "^1.0.3",
+ "has-symbols": "^1.0.3"
+ }
+ },
"glob-parent": {
"version": "5.1.2",
"resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-5.1.2.tgz",
@@ -5500,6 +5665,11 @@
"function-bind": "^1.1.1"
}
},
+ "has-symbols": {
+ "version": "1.0.3",
+ "resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.0.3.tgz",
+ "integrity": "sha512-l3LCuF6MgDNwTDKkdYGEihYjt5pRPbEg46rtlmnSPlUbgmB8LOIrKJbYYFBSbnPaJexMKtiPO8hmeRjRz2Td+A=="
+ },
"hey-listen": {
"version": "1.0.8",
"resolved": "https://registry.npmjs.org/hey-listen/-/hey-listen-1.0.8.tgz",
@@ -7103,6 +7273,8 @@
"dependencies": {
"lru-cache": {
"version": "6.0.0",
+ "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz",
+ "integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==",
"bundled": true,
"requires": {
"yallist": "^4.0.0"
@@ -7319,6 +7491,11 @@
"resolved": "https://registry.npmjs.org/object-hash/-/object-hash-3.0.0.tgz",
"integrity": "sha512-RSn9F68PjH9HqtltsSnqYC1XXoWe9Bju5+213R98cNGttag9q9yAOTzdbsqvIa7aNm5WffBZFpWYr2aWrklWAw=="
},
+ "object-inspect": {
+ "version": "1.12.2",
+ "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.12.2.tgz",
+ "integrity": "sha512-z+cPxW0QGUp0mcqcsgQyLVRDoXFQbXOwBaqyF7VIgI4TWNQsDHrBpUQslRmIfAoYWdYzs6UlKJtB2XJpTaNSpQ=="
+ },
"oidc-token-hash": {
"version": "5.0.1",
"resolved": "https://registry.npmjs.org/oidc-token-hash/-/oidc-token-hash-5.0.1.tgz",
@@ -7450,6 +7627,14 @@
"resolved": "https://registry.npmjs.org/pretty-format/-/pretty-format-3.8.0.tgz",
"integrity": "sha512-WuxUnVtlWL1OfZFQFuqvnvs6MiAGk9UNsBostyBOB0Is9wb5uRESevA6rnl/rkksXaGX3GzZhPup5d6Vp1nFew=="
},
+ "prisma": {
+ "version": "4.3.1",
+ "resolved": "https://registry.npmjs.org/prisma/-/prisma-4.3.1.tgz",
+ "integrity": "sha512-90xo06wtqil76Xsi3mNpc4Js3SdDRR5g4qb9h+4VWY4Y8iImJY6xc3PX+C9xxTSt1lr0Q89A0MLkJjd8ax6KiQ==",
+ "requires": {
+ "@prisma/engines": "4.3.1"
+ }
+ },
"prop-types": {
"version": "15.8.1",
"resolved": "https://registry.npmjs.org/prop-types/-/prop-types-15.8.1.tgz",
@@ -7460,6 +7645,14 @@
"react-is": "^16.13.1"
}
},
+ "qs": {
+ "version": "6.11.0",
+ "resolved": "https://registry.npmjs.org/qs/-/qs-6.11.0.tgz",
+ "integrity": "sha512-MvjoMCJwEarSbUYk5O+nmoSzSutSsTwF85zcHPQ9OrlFoZOYIjaqBAJIqIXjptyD5vThxGq52Xu/MaJzRkIk4Q==",
+ "requires": {
+ "side-channel": "^1.0.4"
+ }
+ },
"queue-microtask": {
"version": "1.2.3",
"resolved": "https://registry.npmjs.org/queue-microtask/-/queue-microtask-1.2.3.tgz",
@@ -7471,9 +7664,9 @@
"integrity": "sha512-WuyALRjWPDGtt/wzJiadO5AXY+8hZ80hVpe6MyivgraREW751X3SbhRvG3eLKOYN+8VEvqLcf3wdnt44Z4S4SA=="
},
"react": {
- "version": "18.2.0",
- "resolved": "https://registry.npmjs.org/react/-/react-18.2.0.tgz",
- "integrity": "sha512-/3IjMdb2L9QbBdWiW5e3P2/npwMBaU9mHCSCUzNln0ZCYbcfTsGbTJrU/kGemdH2IWmB2ioZ+zkxtmq6g09fGQ==",
+ "version": "18.1.0",
+ "resolved": "https://registry.npmjs.org/react/-/react-18.1.0.tgz",
+ "integrity": "sha512-4oL8ivCz5ZEPyclFQXaNksK3adutVS8l2xzZU0cqEFrE9Sb7fC0EFK5uEk74wIreL1DERyjvsU915j1pcT2uEQ==",
"requires": {
"loose-envify": "^1.1.0"
}
@@ -7577,11 +7770,30 @@
"loose-envify": "^1.1.0"
}
},
+ "side-channel": {
+ "version": "1.0.4",
+ "resolved": "https://registry.npmjs.org/side-channel/-/side-channel-1.0.4.tgz",
+ "integrity": "sha512-q5XPytqFEIKHkGdiMIrY10mvLRvnQh42/+GoBlFW3b2LXLE2xxJpZFdm94we0BaoV3RwJyGqg5wS7epxTv0Zvw==",
+ "requires": {
+ "call-bind": "^1.0.0",
+ "get-intrinsic": "^1.0.2",
+ "object-inspect": "^1.9.0"
+ }
+ },
"source-map-js": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/source-map-js/-/source-map-js-1.0.2.tgz",
"integrity": "sha512-R0XvVJ9WusLiqTCEiGCmICCMplcCkIwwR11mOSD9CR5u+IXYdiseeEuXCVAjS54zqwkLcPNnmU4OeJ6tUrWhDw=="
},
+ "stripe": {
+ "version": "10.7.0",
+ "resolved": "https://registry.npmjs.org/stripe/-/stripe-10.7.0.tgz",
+ "integrity": "sha512-yCd8xTPaPLps7BYJL3FuBwza6A4TcYvE074bCEpN5xJUYBUYN4lly0F275HkUa7QODXn8UjO93oIanV/L6O14w==",
+ "requires": {
+ "@types/node": ">=8.1.0",
+ "qs": "^6.10.3"
+ }
+ },
"style-value-types": {
"version": "5.1.2",
"resolved": "https://registry.npmjs.org/style-value-types/-/style-value-types-5.1.2.tgz",
diff --git a/package.json b/package.json
index 3018cdf3b0..24fbdeff5c 100644
--- a/package.json
+++ b/package.json
@@ -7,7 +7,8 @@
},
"dependencies": {
"@headlessui/react": "^1.6.6",
- "@next-auth/upstash-redis-adapter": "^3.0.1",
+ "@next-auth/prisma-adapter": "^1.0.4",
+ "@prisma/client": "^4.3.1",
"@tailwindcss/forms": "^0.5.3",
"@upstash/redis": "^1.12.0",
"@visx/axis": "^2.12.2",
@@ -23,8 +24,10 @@
"next-auth": "^4.10.3",
"nodemailer": "^6.7.8",
"npm": "^8.19.0",
- "react": "^18.2.0",
+ "prisma": "^4.3.1",
+ "react": "^18.1.0",
"react-dom": "18.1.0",
+ "stripe": "^10.7.0",
"swr": "^2.0.0-beta.1",
"tailwind-scrollbar-hide": "^1.1.7",
"topojson-client": "^3.1.0"
diff --git a/pages/api/auth/[...nextauth].ts b/pages/api/auth/[...nextauth].ts
index 60f86a442a..f45c3e7905 100644
--- a/pages/api/auth/[...nextauth].ts
+++ b/pages/api/auth/[...nextauth].ts
@@ -1,29 +1,42 @@
-import NextAuth from "next-auth";
+import NextAuth, { type NextAuthOptions } from "next-auth";
import EmailProvider from "next-auth/providers/email";
-import { UpstashRedisAdapter } from "@next-auth/upstash-redis-adapter";
-import { redis } from "@/lib/redis";
+import { PrismaAdapter } from "@next-auth/prisma-adapter";
+import prisma from "@/lib/prisma";
-const useSecureCookies = !!process.env.VERCEL_URL;
+const VERCEL_DEPLOYMENT = !!process.env.VERCEL_URL;
-export default NextAuth({
- adapter: UpstashRedisAdapter(redis),
+export const authOptions: NextAuthOptions = {
providers: [
EmailProvider({
server: process.env.EMAIL_SERVER,
from: process.env.EMAIL_FROM,
}),
],
+ adapter: PrismaAdapter(prisma),
session: { strategy: "jwt" },
cookies: {
sessionToken: {
- name: `${useSecureCookies ? "__Secure-" : ""}next-auth.session-token`,
+ name: `${VERCEL_DEPLOYMENT ? "__Secure-" : ""}next-auth.session-token`,
options: {
httpOnly: true,
sameSite: "lax",
path: "/",
- domain: ".dub.sh",
- secure: useSecureCookies,
+ // When working on localhost, the cookie domain must be omitted entirely (https://stackoverflow.com/a/1188145)
+ domain: VERCEL_DEPLOYMENT ? ".dub.sh" : undefined,
+ secure: VERCEL_DEPLOYMENT,
},
},
},
-});
+ callbacks: {
+ session: async ({ session, token, user }) => {
+ session.user = {
+ // @ts-ignore
+ id: token.sub,
+ ...session.user,
+ };
+ return session;
+ },
+ },
+};
+
+export default NextAuth(authOptions);
diff --git a/pages/api/links/[key]/clicks.ts b/pages/api/edge/links/[key]/clicks.ts
similarity index 93%
rename from pages/api/links/[key]/clicks.ts
rename to pages/api/edge/links/[key]/clicks.ts
index 3560576e2c..7302619026 100644
--- a/pages/api/links/[key]/clicks.ts
+++ b/pages/api/edge/links/[key]/clicks.ts
@@ -8,7 +8,7 @@ export const config = {
export default async function handler(req: NextRequest) {
if (req.method === "GET") {
const url = req.nextUrl.pathname;
- const key = url.split("/")[3];
+ const key = url.split("/")[4];
const response = (await redis.zcard(`dub.sh:${key}:clicks`)) || "0";
return new Response(JSON.stringify(response), { status: 200 });
} else {
diff --git a/pages/api/links/[key]/stats.ts b/pages/api/edge/links/[key]/stats.ts
similarity index 96%
rename from pages/api/links/[key]/stats.ts
rename to pages/api/edge/links/[key]/stats.ts
index e7b15b9901..c27496395a 100644
--- a/pages/api/links/[key]/stats.ts
+++ b/pages/api/edge/links/[key]/stats.ts
@@ -14,7 +14,7 @@ export const config = {
export default async function handler(req: NextRequest) {
if (req.method === "GET") {
const url = req.nextUrl.pathname;
- const key = url.split("/")[3];
+ const key = url.split("/")[4];
const interval = req.nextUrl.searchParams.get("interval") as
| IntervalProps
| undefined;
diff --git a/pages/api/edge/links/index.ts b/pages/api/edge/links/index.ts
new file mode 100644
index 0000000000..1097d8c238
--- /dev/null
+++ b/pages/api/edge/links/index.ts
@@ -0,0 +1,40 @@
+import type { NextRequest } from "next/server";
+import { redis } from "@/lib/redis";
+import { setRandomKey } from "@/lib/api/links";
+
+export const config = {
+ runtime: "experimental-edge",
+};
+
+export default async function handler(req: NextRequest) {
+ if (req.method === "POST") {
+ const url = req.nextUrl.searchParams.get("url");
+ if (!url) {
+ return new Response(`Missing url or hostname`, { status: 400 });
+ }
+ const { response, key } = await setRandomKey(url);
+ if (response === 1) {
+ // if key was successfully added
+ await redis.zadd(`dub.sh:generic:timestamp`, {
+ score: Date.now(),
+ member: key,
+ });
+ return new Response(
+ JSON.stringify({
+ key,
+ url,
+ }),
+ { status: 200 }
+ );
+ } else {
+ return new Response(
+ JSON.stringify({
+ error: "failed to save link",
+ }),
+ { status: 500 }
+ );
+ }
+ } else {
+ return new Response(`Method ${req.method} Not Allowed`, { status: 405 });
+ }
+}
diff --git a/pages/api/links/index.ts b/pages/api/links/index.ts
index cb450d2601..a5b2be75de 100644
--- a/pages/api/links/index.ts
+++ b/pages/api/links/index.ts
@@ -1,41 +1,48 @@
-import type { NextRequest } from "next/server";
+import { NextApiRequest, NextApiResponse } from "next";
import { redis } from "@/lib/redis";
+import { getSession } from "@/lib/api/auth";
import { customAlphabet } from "nanoid";
-export const config = {
- runtime: "experimental-edge",
-};
+export default async function handler(
+ req: NextApiRequest,
+ res: NextApiResponse
+) {
+ // const session = await getSession(req, res);
+ // if (!session?.user.id) return res.status(401).end("Unauthorized");
-export default async function handler(req: NextRequest) {
- if (req.method === "POST") {
- const url = req.nextUrl.searchParams.get("url");
- const hostname = req.nextUrl.searchParams.get("hostname");
- if (!url || !hostname) {
- return new Response(`Missing url or hostname`, { status: 400 });
+ // GET /api/links – get all links associated with the authenticated user
+ if (req.method === "GET") {
+ const { hostname } = req.query;
+ const response = await redis.hgetall(`${hostname}:links`);
+ return res.status(200).json(response);
+
+ // POST /api/links – create a new link
+ } else if (req.method === "POST") {
+ let { hostname, key, url } = req.body;
+ if (!hostname || !key || !url) {
+ return res.status(400).json({ error: "Missing hostname, key or url" });
}
- const nanoid = customAlphabet(
- "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",
- 7
- ); // 7-character random string
- const key = nanoid(); //
- const response = await redis.hsetnx(`${hostname}:links`, key, url);
- if (response === 1) {
- return new Response(
- JSON.stringify({
- key,
- url,
- }),
- { status: 200 }
- );
+ const pipeline = redis.pipeline();
+ pipeline.hsetnx(`${hostname}:links`, key, url);
+ pipeline.zadd(`${hostname}:links:timestamp`, {
+ score: Date.now(),
+ member: key,
+ });
+
+ const response = await pipeline.exec();
+
+ if (response === [1, 1]) {
+ return res.status(200).json({
+ key,
+ url,
+ });
} else {
- return new Response(
- JSON.stringify({
- error: "failed to save link",
- }),
- { status: 500 }
- );
+ return res.status(500).json({
+ error: "Failed to save link",
+ });
}
} else {
- return new Response(`Method ${req.method} Not Allowed`, { status: 405 });
+ res.setHeader("Allow", ["GET", "POST"]);
+ return res.status(405).json({ error: `Method ${req.method} Not Allowed` });
}
}
diff --git a/pages/api/projects/[slug]/index.ts b/pages/api/projects/[slug]/index.ts
new file mode 100644
index 0000000000..260ebb31e3
--- /dev/null
+++ b/pages/api/projects/[slug]/index.ts
@@ -0,0 +1,62 @@
+import { NextApiRequest, NextApiResponse } from "next";
+import { getSession } from "@/lib/api/auth";
+import prisma from "@/lib/prisma";
+import { redis } from "@/lib/redis";
+
+export default async function handler(
+ req: NextApiRequest,
+ res: NextApiResponse
+) {
+ const session = await getSession(req, res);
+ if (!session?.user.id) return res.status(401).end("Unauthorized");
+
+ const { slug } = req.query;
+ if (!slug || typeof slug !== "string") {
+ return res
+ .status(400)
+ .json({ error: "Missing or misconfigured project slug" });
+ }
+
+ // GET /api/projects/[slug] – get a specific project with it's links
+ if (req.method === "GET") {
+ const response = await prisma.project.findFirst({
+ where: {
+ slug,
+ users: {
+ some: {
+ userId: session.user.id,
+ },
+ },
+ },
+ });
+ if (response) {
+ const keys = await redis.zrange<string[]>(
+ `${slug}:links:timestamps`,
+ 0,
+ -1,
+ {
+ rev: true,
+ }
+ );
+ const urls =
+ keys.length > 0 ? await redis.hmget(`${slug}:links`, ...keys) : {};
+ const links = Object.entries(urls || {}).map(([key, value]) => ({
+ key,
+ url: value,
+ }));
+ return res.status(200).json({
+ ...response,
+ links,
+ });
+ } else {
+ return res.status(404).json({ error: "Project not found" });
+ }
+
+ // PUT /api/projects/[slug] – edit a project
+ } else if (req.method === "PUT") {
+ return res.status(200).send("TODO");
+ } else {
+ res.setHeader("Allow", ["GET", "PUT"]);
+ return res.status(405).json({ error: `Method ${req.method} Not Allowed` });
+ }
+}
diff --git a/pages/api/projects/[slug]/links/[key]/clicks.ts b/pages/api/projects/[slug]/links/[key]/clicks.ts
new file mode 100644
index 0000000000..e4d25b9a22
--- /dev/null
+++ b/pages/api/projects/[slug]/links/[key]/clicks.ts
@@ -0,0 +1,40 @@
+import { NextApiRequest, NextApiResponse } from "next";
+import { getSession } from "@/lib/api/auth";
+import { redis } from "@/lib/redis";
+import prisma from "@/lib/prisma";
+
+export default async function handler(
+ req: NextApiRequest,
+ res: NextApiResponse
+) {
+ const session = await getSession(req, res);
+ if (!session?.user.id) return res.status(401).end("Unauthorized");
+
+ const { slug } = req.query;
+ if (!slug || typeof slug !== "string") {
+ return res
+ .status(400)
+ .json({ error: "Missing or misconfigured project slug" });
+ }
+
+ const isProjectOwner = await prisma.project.count({
+ where: {
+ slug,
+ users: {
+ some: {
+ userId: session.user.id,
+ },
+ },
+ },
+ });
+ if (!isProjectOwner) return res.status(401).end("Unauthorized");
+
+ if (req.method === "GET") {
+ const { slug, key } = req.query;
+ const response = (await redis.zcard(`${slug}:${key}:clicks`)) || "0";
+ return res.status(200).json(response);
+ } else {
+ res.setHeader("Allow", ["GET"]);
+ return res.status(405).json({ error: `Method ${req.method} Not Allowed` });
+ }
+}
diff --git a/pages/api/projects/[slug]/links/[key]/stats.ts b/pages/api/projects/[slug]/links/[key]/stats.ts
new file mode 100644
index 0000000000..20899ba7c4
--- /dev/null
+++ b/pages/api/projects/[slug]/links/[key]/stats.ts
@@ -0,0 +1,54 @@
+import { NextApiRequest, NextApiResponse } from "next";
+import { getSession } from "@/lib/api/auth";
+import { redis } from "@/lib/redis";
+import prisma from "@/lib/prisma";
+import { IntervalProps, intervalData, RawStatsProps } from "@/lib/stats";
+
+export default async function handler(
+ req: NextApiRequest,
+ res: NextApiResponse
+) {
+ const session = await getSession(req, res);
+ if (!session?.user.id) return res.status(401).end("Unauthorized");
+
+ const { slug } = req.query;
+ if (!slug || typeof slug !== "string") {
+ return res
+ .status(400)
+ .json({ error: "Missing or misconfigured project slug" });
+ }
+
+ const isProjectOwner = await prisma.project.count({
+ where: {
+ slug,
+ users: {
+ some: {
+ userId: session.user.id,
+ },
+ },
+ },
+ });
+ if (!isProjectOwner) return res.status(401).end("Unauthorized");
+
+ if (req.method === "GET") {
+ const { slug, key, interval } = req.query as {
+ slug: string;
+ key: string;
+ interval: IntervalProps;
+ };
+ const start = Date.now() - intervalData[interval || "7d"].milliseconds;
+ const end = Date.now();
+ const response = await redis.zrange<RawStatsProps[]>(
+ `${slug}:${key}:clicks`,
+ start,
+ end,
+ {
+ byScore: true,
+ }
+ );
+ return res.status(200).json(response);
+ } else {
+ res.setHeader("Allow", ["GET"]);
+ return res.status(405).json({ error: `Method ${req.method} Not Allowed` });
+ }
+}
diff --git a/pages/api/projects/[slug]/links/index.ts b/pages/api/projects/[slug]/links/index.ts
new file mode 100644
index 0000000000..6f377943c7
--- /dev/null
+++ b/pages/api/projects/[slug]/links/index.ts
@@ -0,0 +1,61 @@
+import { NextApiRequest, NextApiResponse } from "next";
+import { redis } from "@/lib/redis";
+import { getSession } from "@/lib/api/auth";
+import prisma from "@/lib/prisma";
+
+export default async function handler(
+ req: NextApiRequest,
+ res: NextApiResponse
+) {
+ const session = await getSession(req, res);
+ if (!session?.user.id) return res.status(401).end("Unauthorized");
+
+ const { slug } = req.query;
+ if (!slug || typeof slug !== "string") {
+ return res
+ .status(400)
+ .json({ error: "Missing or misconfigured project slug" });
+ }
+
+ const isProjectOwner = await prisma.project.count({
+ where: {
+ slug,
+ users: {
+ some: {
+ userId: session.user.id,
+ },
+ },
+ },
+ });
+ if (!isProjectOwner) return res.status(401).end("Unauthorized");
+
+ // POST /api/links – create a new link
+ if (req.method === "POST") {
+ let { hostname, key, url } = req.body;
+ if (!hostname || !key || !url) {
+ return res.status(400).json({ error: "Missing hostname, key or url" });
+ }
+ const pipeline = redis.pipeline();
+ pipeline.hsetnx(`${hostname}:links`, key, url);
+ pipeline.zadd(`${hostname}:links:timestamp`, {
+ score: Date.now(),
+ member: key,
+ });
+
+ const response = await pipeline.exec();
+
+ if (response === [1, 1]) {
+ return res.status(200).json({
+ key,
+ url,
+ });
+ } else {
+ return res.status(500).json({
+ error: "Failed to save link",
+ });
+ }
+ } else {
+ res.setHeader("Allow", ["GET", "POST"]);
+ return res.status(405).json({ error: `Method ${req.method} Not Allowed` });
+ }
+}
diff --git a/pages/api/projects/index.ts b/pages/api/projects/index.ts
new file mode 100644
index 0000000000..fd50037ef1
--- /dev/null
+++ b/pages/api/projects/index.ts
@@ -0,0 +1,49 @@
+import { NextApiRequest, NextApiResponse } from "next";
+import { getSession } from "@/lib/api/auth";
+import prisma from "@/lib/prisma";
+
+export default async function handler(
+ req: NextApiRequest,
+ res: NextApiResponse
+) {
+ const session = await getSession(req, res);
+ if (!session?.user.id) return res.status(401).end("Unauthorized");
+
+ // GET /api/projects – get all projects associated with the authenticated user
+ if (req.method === "GET") {
+ const response = await prisma.project.findMany({
+ where: {
+ users: {
+ some: {
+ userId: session.user.id,
+ },
+ },
+ },
+ });
+ return res.status(200).json(response);
+
+ // POST /api/projects – create a new project
+ } else if (req.method === "POST") {
+ const { name, slug } = req.body;
+ if (!name || !slug)
+ return res.status(400).json({ error: "Missing name or slug" });
+
+ const project = await prisma.project.create({
+ data: {
+ name,
+ slug,
+ users: {
+ create: {
+ userId: session.user.id,
+ role: "owner",
+ },
+ },
+ },
+ });
+
+ return res.status(200).json(project);
+ } else {
+ res.setHeader("Allow", ["GET", "POST"]);
+ return res.status(405).json({ error: `Method ${req.method} Not Allowed` });
+ }
+}
diff --git a/pages/app/[slug]/[key].tsx b/pages/app/[slug]/[key].tsx
new file mode 100644
index 0000000000..a845933500
--- /dev/null
+++ b/pages/app/[slug]/[key].tsx
@@ -0,0 +1,10 @@
+import Stats from "@/components/stats";
+import HomeLayout from "@/components/layout/home";
+
+export default function StatsPage() {
+ return (
+ <HomeLayout>
+ <Stats />
+ </HomeLayout>
+ );
+}
diff --git a/pages/app/[slug]/index.tsx b/pages/app/[slug]/index.tsx
new file mode 100644
index 0000000000..c9aa1e48cb
--- /dev/null
+++ b/pages/app/[slug]/index.tsx
@@ -0,0 +1,40 @@
+import AppLayout from "components/layout/app";
+import { useRouter } from "next/router";
+import useSWR from "swr";
+import { fetcher } from "@/lib/utils";
+import LinkCard from "@/components/app/link-card";
+import PlaceholderCard from "@/components/home/placeholder-card";
+import { useEffect } from "react";
+import { ProjectProps } from "@/lib/api/types";
+
+export default function Project() {
+ const router = useRouter();
+ const { slug } = router.query as {
+ slug: string;
+ };
+
+ const { data, error } = useSWR<ProjectProps>(
+ router.isReady && `/api/projects/${slug}`,
+ fetcher
+ );
+
+ useEffect(() => {
+ if (error) {
+ router.push("/404");
+ }
+ }, [error]);
+
+ return (
+ <AppLayout>
+ <div className="grid gap-2 mt-3">
+ {data?.links && data.links.length > 0
+ ? data.links.map(({ key, url }) => (
+ <LinkCard key={key} _key={key} url={url} />
+ ))
+ : Array.from({ length: 3 }).map((_, i) => (
+ <PlaceholderCard key={i} />
+ ))}
+ </div>
+ </AppLayout>
+ );
+}
diff --git a/pages/app/index.tsx b/pages/app/index.tsx
index 32e27edeea..617a4e65b9 100644
--- a/pages/app/index.tsx
+++ b/pages/app/index.tsx
@@ -1,10 +1,28 @@
-import { signOut } from "next-auth/react";
+import AppLayout from "components/layout/app";
+import Link from "next/link";
+import useSWR from "swr";
+import { fetcher } from "@/lib/utils";
+import { ProjectProps } from "@/lib/api/types";
export default function App() {
+ const { data } = useSWR<ProjectProps[]>(`/api/projects`, fetcher);
+
return (
- <div>
- <h1>App</h1>
- <button onClick={() => signOut()}>Sign out</button>
- </div>
+ <AppLayout>
+ <div className="my-10 grid grid-cols-1 sm:grid-cols-3 gap-3">
+ {data
+ ? data.map(({ name, slug }) => (
+ <Link key={slug} href={`/${slug}`}>
+ <a>
+ <div className="bg-white dark:bg-gray-800 shadow rounded-lg p-4 hover:shadow-lg transition-all">
+ <h2 className="text-xl font-bold">{name}</h2>
+ <p className="text-gray-500 dark:text-gray-400">{slug}</p>
+ </div>
+ </a>
+ </Link>
+ ))
+ : null}
+ </div>
+ </AppLayout>
);
}
diff --git a/pages/app/login.tsx b/pages/app/login.tsx
index 3202be85a2..70c139712c 100644
--- a/pages/app/login.tsx
+++ b/pages/app/login.tsx
@@ -4,12 +4,12 @@ import { LoadingDots } from "@/components/shared/icons";
export default function Login() {
const [signInClicked, setSignInClicked] = useState(false);
- const [buttonText, setButtonText] = useState("Sign in with magic link");
+ const [buttonText, setButtonText] = useState("Send magic link");
return (
<div className="h-screen w-screen flex justify-center items-center">
<div className="inline-block w-full max-w-md py-8 px-4 sm:px-16 overflow-hidden text-center align-middle transition-all transform bg-white shadow-xl rounded-2xl">
- <h1 className="font-bold text-3xl mb-4">Sign In</h1>
+ <h1 className="font-bold text-3xl mb-4">Log In to Dub</h1>
<form
onSubmit={async (e) => {
@@ -18,23 +18,14 @@ export default function Login() {
signIn("email", {
email: e.currentTarget.email.value,
redirect: false,
- }).then(
- (
- res: void | {
- error: string | undefined;
- status: number;
- ok: boolean;
- url: string | null;
- }
- ) => {
- setSignInClicked(false);
- if (res?.ok && !res?.error) {
- setButtonText("Email sent - check your inbox!");
- } else {
- setButtonText("Error sending email - try again?");
- }
+ }).then((res) => {
+ setSignInClicked(false);
+ if (res?.ok && !res?.error) {
+ setButtonText("Email sent - check your inbox!");
+ } else {
+ setButtonText("Error sending email - try again?");
}
- );
+ });
}}
className="mt-5 flex flex-col space-y-4"
>
diff --git a/pages/app/settings.tsx b/pages/app/settings.tsx
new file mode 100644
index 0000000000..a4f1d200cd
--- /dev/null
+++ b/pages/app/settings.tsx
@@ -0,0 +1,9 @@
+import AppLayout from "components/layout/app";
+
+export default function Settings() {
+ return (
+ <AppLayout>
+ <h1>Settings</h1>
+ </AppLayout>
+ );
+}
diff --git a/pages/index.tsx b/pages/index.tsx
index 094efcd829..1efd01b9a9 100644
--- a/pages/index.tsx
+++ b/pages/index.tsx
@@ -7,14 +7,12 @@ import PlaceholderCard from "@/components/home/placeholder-card";
import { LoadingDots } from "@/components/shared/icons";
import { StatsProvider } from "@/components/stats/context";
import { motion } from "framer-motion";
+import { LinkProps } from "@/lib/api/types";
export default function Home() {
const [saving, setSaving] = useState(false);
const [url, setUrl] = useState("");
- const [hashes, setHashes] = useLocalStorage<{ key: string; url: string }[]>(
- "hashes",
- []
- );
+ const [hashes, setHashes] = useLocalStorage<LinkProps[]>("hashes", []);
return (
<HomeLayout>
@@ -40,7 +38,7 @@ export default function Home() {
onSubmit={async (e) => {
e.preventDefault();
setSaving(true);
- fetch(`/api/links?url=${url}&hostname=dub.sh`, {
+ fetch(`/api/edge/links?url=${url}&hostname=dub.sh`, {
method: "POST",
headers: {
"Content-Type": "application/json",
diff --git a/pages/stats/[key].tsx b/pages/stats/[key].tsx
index 664516b799..a845933500 100644
--- a/pages/stats/[key].tsx
+++ b/pages/stats/[key].tsx
@@ -1,6 +1,4 @@
import Stats from "@/components/stats";
-import { GetStaticPaths, GetStaticProps } from "next";
-import { ParsedUrlQuery } from "querystring";
import HomeLayout from "@/components/layout/home";
export default function StatsPage() {
@@ -10,21 +8,3 @@ export default function StatsPage() {
</HomeLayout>
);
}
-
-export const getStaticPaths: GetStaticPaths = async () => {
- return {
- paths: [],
- fallback: "blocking",
- };
-};
-
-interface Params extends ParsedUrlQuery {
- key: string;
-}
-
-export const getStaticProps: GetStaticProps = async (context) => {
- const { key } = context.params as Params; // https://wallis.dev/blog/nextjs-getstaticprops-and-getstaticpaths-with-typescript
- return {
- props: { key },
- };
-};
diff --git a/prisma/schema.prisma b/prisma/schema.prisma
new file mode 100644
index 0000000000..8e0c4049bf
--- /dev/null
+++ b/prisma/schema.prisma
@@ -0,0 +1,82 @@
+// This is your Prisma schema file,
+// learn more about it in the docs: https://pris.ly/d/prisma-schema
+
+datasource db {
+ provider = "mysql"
+ url = env("DATABASE_URL")
+ referentialIntegrity = "prisma"
+}
+
+generator client {
+ provider = "prisma-client-js"
+ previewFeatures = ["referentialIntegrity"]
+}
+
+model User {
+ id String @id @default(cuid())
+ name String?
+ email String? @unique
+ emailVerified DateTime?
+ image String?
+ accounts Account[]
+ sessions Session[]
+ projects ProjectUsers[]
+}
+
+model Account {
+ id String @id @default(cuid())
+ userId String
+ type String
+ provider String
+ providerAccountId String
+ refresh_token String? @db.Text
+ access_token String? @db.Text
+ expires_at Int?
+ token_type String?
+ scope String?
+ id_token String? @db.Text
+ session_state String?
+
+ user User @relation(fields: [userId], references: [id], onDelete: Cascade)
+
+ @@unique([provider, providerAccountId])
+}
+
+model Session {
+ id String @id @default(cuid())
+ sessionToken String @unique
+ userId String
+ expires DateTime
+ user User @relation(fields: [userId], references: [id], onDelete: Cascade)
+}
+
+model VerificationToken {
+ identifier String
+ token String @unique
+ expires DateTime
+
+ @@unique([identifier, token])
+}
+
+model Project {
+ id String @id @default(cuid())
+ name String
+ slug String @unique // domain name
+ verified Boolean @default(false)
+ createdAt DateTime @default(now())
+ updatedAt DateTime @updatedAt
+ users ProjectUsers[]
+}
+
+model ProjectUsers {
+ id String @id @default(cuid())
+ role String @default("member")
+ createdAt DateTime @default(now())
+ updatedAt DateTime @updatedAt
+ user User @relation(fields: [userId], references: [id], onDelete: Cascade)
+ userId String
+ project Project @relation(fields: [projectId], references: [id], onDelete: Cascade)
+ projectId String
+
+ @@unique([userId, projectId])
+}
\ No newline at end of file
diff --git a/public/favicon.ico b/public/favicon.ico
index 4965832f2c..e983a9850d 100644
Binary files a/public/favicon.ico and b/public/favicon.ico differ
diff --git a/public/site.webmanifest b/public/site.webmanifest
new file mode 100644
index 0000000000..bdcf016fd8
--- /dev/null
+++ b/public/site.webmanifest
@@ -0,0 +1,19 @@
+{
+ "name": "",
+ "short_name": "",
+ "icons": [
+ {
+ "src": "/static/favicons/android-chrome-192x192.png",
+ "sizes": "192x192",
+ "type": "image/png"
+ },
+ {
+ "src": "/static/favicons/android-chrome-512x512.png",
+ "sizes": "512x512",
+ "type": "image/png"
+ }
+ ],
+ "theme_color": "#ffffff",
+ "background_color": "#ffffff",
+ "display": "standalone"
+}
diff --git a/public/static/favicons/android-chrome-192x192.png b/public/static/favicons/android-chrome-192x192.png
new file mode 100644
index 0000000000..b5fe708c53
Binary files /dev/null and b/public/static/favicons/android-chrome-192x192.png differ
diff --git a/public/static/favicons/android-chrome-512x512.png b/public/static/favicons/android-chrome-512x512.png
new file mode 100644
index 0000000000..97fd52e9c5
Binary files /dev/null and b/public/static/favicons/android-chrome-512x512.png differ
diff --git a/public/static/favicons/apple-touch-icon.png b/public/static/favicons/apple-touch-icon.png
new file mode 100644
index 0000000000..6f47d61ea7
Binary files /dev/null and b/public/static/favicons/apple-touch-icon.png differ
diff --git a/public/static/favicons/browserconfig.xml b/public/static/favicons/browserconfig.xml
new file mode 100644
index 0000000000..d416bc536f
--- /dev/null
+++ b/public/static/favicons/browserconfig.xml
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="utf-8"?>
+<browserconfig>
+ <msapplication>
+ <tile>
+ <square150x150logo src="/mstile-150x150.png"/>
+ <TileColor>#ffffff</TileColor>
+ </tile>
+ </msapplication>
+</browserconfig>
diff --git a/public/static/favicons/favicon-16x16.png b/public/static/favicons/favicon-16x16.png
new file mode 100644
index 0000000000..905435d0a7
Binary files /dev/null and b/public/static/favicons/favicon-16x16.png differ
diff --git a/public/static/favicons/favicon-32x32.png b/public/static/favicons/favicon-32x32.png
new file mode 100644
index 0000000000..13cdfbf1ae
Binary files /dev/null and b/public/static/favicons/favicon-32x32.png differ
diff --git a/public/static/favicons/mstile-150x150.png b/public/static/favicons/mstile-150x150.png
new file mode 100644
index 0000000000..43c078f720
Binary files /dev/null and b/public/static/favicons/mstile-150x150.png differ
diff --git a/public/static/favicons/safari-pinned-tab.svg b/public/static/favicons/safari-pinned-tab.svg
new file mode 100644
index 0000000000..6c6e2c5206
--- /dev/null
+++ b/public/static/favicons/safari-pinned-tab.svg
@@ -0,0 +1,27 @@
+<?xml version="1.0" standalone="no"?>
+<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20010904//EN"
+ "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
+<svg version="1.0" xmlns="http://www.w3.org/2000/svg"
+ width="573.000000pt" height="573.000000pt" viewBox="0 0 573.000000 573.000000"
+ preserveAspectRatio="xMidYMid meet">
+<metadata>
+Created by potrace 1.14, written by Peter Selinger 2001-2017
+</metadata>
+<g transform="translate(0.000000,573.000000) scale(0.100000,-0.100000)"
+fill="#000000" stroke="none">
+<path d="M2669 5726 c-2 -2 -35 -6 -74 -9 -100 -9 -228 -28 -315 -47 -25 -6
+-54 -12 -65 -14 -215 -41 -611 -201 -825 -334 -121 -75 -253 -167 -311 -216
+-130 -110 -162 -140 -239 -217 -376 -377 -627 -822 -759 -1344 -30 -118 -48
+-227 -70 -425 -9 -78 -7 -488 3 -550 3 -19 8 -55 11 -80 9 -71 24 -159 41
+-235 9 -38 18 -81 20 -95 3 -14 9 -36 14 -50 5 -14 19 -59 31 -100 83 -290
+264 -635 475 -906 125 -162 317 -357 454 -464 25 -19 47 -37 50 -40 17 -18
+166 -120 270 -185 168 -106 440 -228 642 -289 113 -35 321 -81 428 -95 189
+-26 244 -29 455 -26 214 3 242 5 373 26 34 5 79 12 100 15 32 4 228 51 295 69
+9 3 25 7 35 9 119 30 468 185 622 278 144 87 343 233 439 322 126 117 250 247
+316 331 17 21 35 43 40 49 86 95 256 375 344 565 128 278 197 526 247 896 13
+97 12 497 -2 605 -21 161 -24 183 -28 205 -30 145 -43 196 -72 298 -31 107
+-55 174 -103 292 -72 178 -214 428 -341 599 -316 429 -762 775 -1240 960 -52
+21 -104 41 -115 45 -100 40 -373 108 -505 126 -24 3 -113 16 -145 21 -36 5
+-491 14 -496 10z"/>
+</g>
+</svg>
diff --git a/public/icons/macos.png b/public/static/icons/macos.png
similarity index 100%
rename from public/icons/macos.png
rename to public/static/icons/macos.png
diff --git a/public/static/logo-square.png b/public/static/logo-square.png
new file mode 100644
index 0000000000..d528c73157
Binary files /dev/null and b/public/static/logo-square.png differ
diff --git a/public/static/logo.png b/public/static/logo.png
new file mode 100644
index 0000000000..1653c4e3cd
Binary files /dev/null and b/public/static/logo.png differ
diff --git a/public/thumbnail.png b/public/static/thumbnail.png
similarity index 100%
rename from public/thumbnail.png
rename to public/static/thumbnail.png
diff --git a/public/vercel.svg b/public/static/vercel.svg
similarity index 100%
rename from public/vercel.svg
rename to public/static/vercel.svg
diff --git a/yarn.lock b/yarn.lock
index 3d48b9f828..1227ee3d7f 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -93,12 +93,10 @@
"hey-listen" "^1.0.8"
"tslib" "^2.3.1"
-"@next-auth/upstash-redis-adapter@^3.0.1":
- "integrity" "sha512-1nqS2tUCFR8ehM+mL/SRZL0sFlMOJfFXS7f3sZCy6xLpjfYnCJSPnDkm95pWMQE6u4gWS08ehADF6LDYcl79Uw=="
- "resolved" "https://registry.npmjs.org/@next-auth/upstash-redis-adapter/-/upstash-redis-adapter-3.0.1.tgz"
- "version" "3.0.1"
- dependencies:
- "uuid" "^8.3.2"
+"@next-auth/prisma-adapter@^1.0.4":
+ "integrity" "sha512-jIOM6CzCbl2/Mzbx9kb2IjtHoJOeRN9wtQgLk4EUm5bhneSVGv1rtz5TDskvp2UfCa+EK9nDmug+lje41z80Gg=="
+ "resolved" "https://registry.npmjs.org/@next-auth/prisma-adapter/-/prisma-adapter-1.0.4.tgz"
+ "version" "1.0.4"
"integrity" "sha512-VJVvvWD5f1HXF3OTzWDdHomWsUwM70Bg8AR29iKhyMkaTu84qtR2IiQmrqO9tioht0OTRbu6J9HHZRh1UZmBLA=="
@@ -275,6 +273,23 @@
"resolved" "https://registry.npmjs.org/@panva/hkdf/-/hkdf-1.0.2.tgz"
"version" "1.0.2"
+"@prisma/client@^4.3.1", "@prisma/client@>=2.26.0 || >=3":
+ "integrity" "sha512-FA0/d1VMJNWqzU7WVWTNWJ+lGOLR9JUBnF73GdIPAEVo/6dWk4gHx0EmgeU+SMv4MZoxgOeTBJF2azhg7x0hMw=="
+ "resolved" "https://registry.npmjs.org/@prisma/client/-/client-4.3.1.tgz"
+ "version" "4.3.1"
+ dependencies:
+ "@prisma/engines-version" "4.3.0-32.c875e43600dfe042452e0b868f7a48b817b9640b"
+
+"@prisma/engines-version@4.3.0-32.c875e43600dfe042452e0b868f7a48b817b9640b":
+ "integrity" "sha512-8yWpXkQRmiSfsi2Wb/ZS5D3RFbeu/btL9Pm/gdF4phB0Lo5KGsDFMxFMgaD64mwED2nHc8ZaEJg/+4Jymb9Znw=="
+ "resolved" "https://registry.npmjs.org/@prisma/engines-version/-/engines-version-4.3.0-32.c875e43600dfe042452e0b868f7a48b817b9640b.tgz"
+ "version" "4.3.0-32.c875e43600dfe042452e0b868f7a48b817b9640b"
+
+"@prisma/[email protected]":
+ "integrity" "sha512-4JF/uMaEDAPdcdZNOrnzE3BvrbGpjgV0FcPT3EVoi6I86fWkloqqxBt+KcK/+fIRR0Pxj66uGR9wVH8U1Y13JA=="
+ "resolved" "https://registry.npmjs.org/@prisma/engines/-/engines-4.3.1.tgz"
+ "version" "4.3.1"
+
"integrity" "sha512-6JrF+fdUK2zbGpJIlN7G3v966PQjyx/dPt1T9km2wj+EUBqgrxCk3uX4Kct16MIm9gGxfKRcfax2hVf5jvlTzA=="
"resolved" "https://registry.npmjs.org/@swc/helpers/-/helpers-0.4.3.tgz"
@@ -345,7 +360,7 @@
"resolved" "https://registry.npmjs.org/@types/lodash/-/lodash-4.14.184.tgz"
"version" "4.14.184"
+"@types/node@>=8.1.0", "@types/[email protected]":
"integrity" "sha512-vu1SrqBjbbZ3J6vwY17jBs8Sr/BKA+/a/WtjRG+whKg1iuLFOosq872EXS0eXWILdO36DHQQeku/ZcL6hz2fpg=="
"resolved" "https://registry.npmjs.org/@types/node/-/node-17.0.35.tgz"
"version" "17.0.35"
@@ -391,7 +406,7 @@
dependencies:
"@types/geojson" "*"
-"@upstash/redis@^1.0.1", "@upstash/redis@^1.12.0":
+"@upstash/redis@^1.12.0":
"integrity" "sha512-i6oarviHs7xOi9aLe8N52bFSg8FAC8JeArINLqtlEuLGNTkIhdNIJYEs4Sk/xq0EDmHSXFGPWdp+6R8JL9XoIg=="
"resolved" "https://registry.npmjs.org/@upstash/redis/-/redis-1.12.0.tgz"
"version" "1.12.0"
@@ -713,6 +728,14 @@
"tar" "^6.1.11"
"unique-filename" "^2.0.0"
+"call-bind@^1.0.0":
+ "integrity" "sha512-7O+FbCihrB5WGbFYesctwmTKae6rOiIzmz1icreWJ+0aA7LJfuqhEso2T9ncpcFtzMQtzXf2QGGueWJGTYsqrA=="
+ "resolved" "https://registry.npmjs.org/call-bind/-/call-bind-1.0.2.tgz"
+ "version" "1.0.2"
+ dependencies:
+ "function-bind" "^1.1.1"
+ "get-intrinsic" "^1.0.2"
+
"camelcase-css@^2.0.1":
"integrity" "sha512-QOSvevhslijgYwRx6Rv7zKdMF8lbRmx+uQGx2+vDc+KI/eBnsy9kit5aj23AgGu3pa4t9AgwbnXWqS+iOY+2aA=="
"resolved" "https://registry.npmjs.org/camelcase-css/-/camelcase-css-2.0.1.tgz"
@@ -1070,6 +1093,15 @@
"strip-ansi" "^6.0.1"
"wide-align" "^1.1.5"
+"get-intrinsic@^1.0.2":
+ "integrity" "sha512-Jfm3OyCxHh9DJyc28qGk+JmfkpO41A4XkneDSujN9MDXrm4oDKdHvndhZ2dN94+ERNfkYJWDclW6k2L/ZGHjXA=="
+ "resolved" "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.1.2.tgz"
+ "version" "1.1.2"
+ dependencies:
+ "function-bind" "^1.1.1"
+ "has" "^1.0.3"
+ "has-symbols" "^1.0.3"
+
"glob-parent@^5.1.2", "glob-parent@~5.1.2":
"integrity" "sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow=="
"resolved" "https://registry.npmjs.org/glob-parent/-/glob-parent-5.1.2.tgz"
@@ -1119,6 +1151,11 @@
"has-flag@^4.0.0":
"version" "4.0.0"
+"has-symbols@^1.0.3":
+ "integrity" "sha512-l3LCuF6MgDNwTDKkdYGEihYjt5pRPbEg46rtlmnSPlUbgmB8LOIrKJbYYFBSbnPaJexMKtiPO8hmeRjRz2Td+A=="
+ "resolved" "https://registry.npmjs.org/has-symbols/-/has-symbols-1.0.3.tgz"
+ "version" "1.0.3"
+
"has-unicode@^2.0.1":
"version" "2.0.1"
@@ -1828,6 +1865,11 @@
"resolved" "https://registry.npmjs.org/object-hash/-/object-hash-3.0.0.tgz"
"version" "3.0.0"
+"object-inspect@^1.9.0":
+ "integrity" "sha512-z+cPxW0QGUp0mcqcsgQyLVRDoXFQbXOwBaqyF7VIgI4TWNQsDHrBpUQslRmIfAoYWdYzs6UlKJtB2XJpTaNSpQ=="
+ "resolved" "https://registry.npmjs.org/object-inspect/-/object-inspect-1.12.2.tgz"
+ "version" "1.12.2"
+
"oidc-token-hash@^5.0.1":
"integrity" "sha512-EvoOtz6FIEBzE+9q253HsLCVRiK/0doEJ2HCvvqMQb3dHZrP3WlJKYtJ55CRTw4jmYomzH4wkPuCj/I3ZvpKxQ=="
"resolved" "https://registry.npmjs.org/oidc-token-hash/-/oidc-token-hash-5.0.1.tgz"
@@ -2000,6 +2042,13 @@
"resolved" "https://registry.npmjs.org/pretty-format/-/pretty-format-3.8.0.tgz"
"version" "3.8.0"
+"prisma@*", "prisma@^4.3.1":
+ "integrity" "sha512-90xo06wtqil76Xsi3mNpc4Js3SdDRR5g4qb9h+4VWY4Y8iImJY6xc3PX+C9xxTSt1lr0Q89A0MLkJjd8ax6KiQ=="
+ "resolved" "https://registry.npmjs.org/prisma/-/prisma-4.3.1.tgz"
+ "version" "4.3.1"
+ dependencies:
+ "@prisma/engines" "4.3.1"
+
"proc-log@^2.0.0", "proc-log@^2.0.1":
"version" "2.0.1"
@@ -2035,6 +2084,13 @@
"qrcode-terminal@^0.12.0":
"version" "0.12.0"
+"qs@^6.10.3":
+ "integrity" "sha512-MvjoMCJwEarSbUYk5O+nmoSzSutSsTwF85zcHPQ9OrlFoZOYIjaqBAJIqIXjptyD5vThxGq52Xu/MaJzRkIk4Q=="
+ "resolved" "https://registry.npmjs.org/qs/-/qs-6.11.0.tgz"
+ "version" "6.11.0"
+ dependencies:
+ "side-channel" "^1.0.4"
+
"queue-microtask@^1.2.2":
"integrity" "sha512-NuaNSa6flKT5JaSYQzJok04JzTL1CA6aGhv5rfLW3PgqA+M2ChpZQnAC8h8i4ZFkBS8X5RqkDBHA7r4hej3K9A=="
"resolved" "https://registry.npmjs.org/queue-microtask/-/queue-microtask-1.2.3.tgz"
@@ -2065,10 +2121,10 @@
dependencies:
"debounce" "^1.2.1"
-"react@^16 || ^17 || ^18", "react@^16.0.0-0 || ^17.0.0-0 || ^18.0.0-0", "react@^16.11.0 || ^17.0.0 || ^18.0.0", "react@^16.3.0-0 || ^17.0.0-0 || ^18.0.0-0", "react@^16.8.0 || ^17.0.0 || ^18.0.0", "react@^16.8.0-0 || ^17.0.0-0 || ^18.0.0-0", "react@^17.0.2 || ^18", "react@^17.0.2 || ^18.0.0-0", "react@^18.0.0", "react@^18.1.0", "react@^18.2.0", "react@>= 16.8.0 || 17.x.x || ^18.0.0-0", "react@>=16.13":
- "integrity" "sha512-/3IjMdb2L9QbBdWiW5e3P2/npwMBaU9mHCSCUzNln0ZCYbcfTsGbTJrU/kGemdH2IWmB2ioZ+zkxtmq6g09fGQ=="
- "resolved" "https://registry.npmjs.org/react/-/react-18.2.0.tgz"
- "version" "18.2.0"
+"react@^16 || ^17 || ^18", "react@^16.0.0-0 || ^17.0.0-0 || ^18.0.0-0", "react@^16.11.0 || ^17.0.0 || ^18.0.0", "react@^16.3.0-0 || ^17.0.0-0 || ^18.0.0-0", "react@^16.8.0 || ^17.0.0 || ^18.0.0", "react@^16.8.0-0 || ^17.0.0-0 || ^18.0.0-0", "react@^17.0.2 || ^18", "react@^17.0.2 || ^18.0.0-0", "react@^18.0.0", "react@^18.1.0", "react@>= 16.8.0 || 17.x.x || ^18.0.0-0", "react@>=16.13":
+ "integrity" "sha512-4oL8ivCz5ZEPyclFQXaNksK3adutVS8l2xzZU0cqEFrE9Sb7fC0EFK5uEk74wIreL1DERyjvsU915j1pcT2uEQ=="
+ "resolved" "https://registry.npmjs.org/react/-/react-18.1.0.tgz"
+ "version" "18.1.0"
dependencies:
"loose-envify" "^1.1.0"
@@ -2194,6 +2250,15 @@
"set-blocking@^2.0.0":
"version" "2.0.0"
+"side-channel@^1.0.4":
+ "integrity" "sha512-q5XPytqFEIKHkGdiMIrY10mvLRvnQh42/+GoBlFW3b2LXLE2xxJpZFdm94we0BaoV3RwJyGqg5wS7epxTv0Zvw=="
+ "resolved" "https://registry.npmjs.org/side-channel/-/side-channel-1.0.4.tgz"
+ "version" "1.0.4"
+ dependencies:
+ "call-bind" "^1.0.0"
+ "get-intrinsic" "^1.0.2"
+ "object-inspect" "^1.9.0"
+
"signal-exit@^3.0.7":
"version" "3.0.7"
@@ -2258,6 +2323,14 @@
dependencies:
"ansi-regex" "^5.0.1"
+"stripe@^10.7.0":
+ "integrity" "sha512-yCd8xTPaPLps7BYJL3FuBwza6A4TcYvE074bCEpN5xJUYBUYN4lly0F275HkUa7QODXn8UjO93oIanV/L6O14w=="
+ "resolved" "https://registry.npmjs.org/stripe/-/stripe-10.7.0.tgz"
+ "version" "10.7.0"
+ dependencies:
+ "@types/node" ">=8.1.0"
+ "qs" "^6.10.3"
+
"integrity" "sha512-Vs9fNreYF9j6W2VvuDTP7kepALi7sk0xtk2Tu8Yxi9UoajJdEVpNpCov0HsLTqXvNGKX+Uv09pkozVITi1jf3Q=="
"resolved" "https://registry.npmjs.org/style-value-types/-/style-value-types-5.1.2.tgz"