The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
update email
Steven Teyc8adcf23cdfc
diff --git a/apps/web/app/api/tokens/route.ts b/apps/web/app/api/tokens/route.tsindex c33e38101a..42f2fa3b9d 100644--- a/apps/web/app/api/tokens/route.ts+++ b/apps/web/app/api/tokens/route.ts@@ -1,3 +1,4 @@+import { scopesToName } from "@/lib/api/tokens/scopes";import { parseRequestBody } from "@/lib/api/utils";import { hashToken, withWorkspace } from "@/lib/auth";import { prisma } from "@/lib/prisma";@@ -62,7 +63,15 @@ export const POST = withWorkspace(subject: `A new API key has been created for your workspace ${workspace.name} on Dub`,react: APIKeyCreated({email: session.user.email,- apiKeyName: name,+ token: {+ name,+ type: scopesToName(scopes || []).name,+ permissions: scopesToName(scopes || []).description,+ },+ workspace: {+ name: workspace.name,+ slug: workspace.slug,+ },}),}),);diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/tokens/page-client.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/tokens/page-client.tsxindex 1c5405f067..2f213201d7 100644--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/tokens/page-client.tsx+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/tokens/page-client.tsx@@ -1,5 +1,6 @@"use client";+import { scopesToName } from "@/lib/api/tokens/scopes";import useWorkspace from "@/lib/swr/use-workspace";import { TokenProps } from "@/lib/types";import { useAddEditTokenModal } from "@/ui/modals/add-edit-token-modal";@@ -7,7 +8,7 @@ import { useDeleteTokenModal } from "@/ui/modals/delete-token-modal";import { useTokenCreatedModal } from "@/ui/modals/token-created-modal";import EmptyState from "@/ui/shared/empty-state";import { Delete } from "@/ui/shared/icons";-import { Button, LoadingSpinner, Popover, TokenAvatar } from "@dub/ui";+import { Badge, Button, LoadingSpinner, Popover, TokenAvatar } from "@dub/ui";import { Key } from "@dub/ui/src/icons";import { fetcher, timeAgo } from "@dub/utils";import { Edit3, MoreVertical } from "lucide-react";@@ -59,7 +60,7 @@ export default function TokensPageClient() {<AddTokenButton /></div>{isLoading || !tokens ? (- <div className="flex flex-col items-center justify-center space-y-4 pb-20 pt-10">+ <div className="flex flex-col items-center justify-center space-y-4 py-20"><LoadingSpinner className="h-6 w-6 text-gray-500" /><p className="text-sm text-gray-500">Fetching API keys...</p></div>@@ -115,9 +116,12 @@ const TokenRow = (token: TokenProps) => {<TokenAvatar id={token.id} /><div className="flex flex-col space-y-px"><p className="font-semibold text-gray-700">{token.name}</p>- <p className="text-sm text-gray-500" suppressHydrationWarning>- Created {timeAgo(token.createdAt, { withAgo: true })}- </p>+ <div className="flex items-center gap-x-2">+ <p className="text-sm text-gray-500" suppressHydrationWarning>+ Created {timeAgo(token.createdAt, { withAgo: true })}+ </p>+ <Badge variant="neutral">{scopesToName(token.scopes).name}</Badge>+ </div></div></div><div className="font-mono text-sm">{token.partialKey}</div>diff --git a/apps/web/emails/api-key-created.tsx b/apps/web/emails/api-key-created.tsxindex 0be974dcc0..8668eb49b0 100644--- a/apps/web/emails/api-key-created.tsx+++ b/apps/web/emails/api-key-created.tsx@@ -16,15 +16,31 @@ import Footer from "./components/footer";export default function APIKeyCreated({email = "[email protected]",- apiKeyName = "Acme",+ workspace = {+ name: "Acme, Inc",+ slug: "acme",+ },+ token = {+ name: "Acme API Key",+ type: "All access",+ permissions: "full access to all resources",+ },}: {email: string;- apiKeyName: string;+ workspace: {+ name: string;+ slug: string;+ };+ token: {+ name: string;+ type: string;+ permissions: string;+ };}) {return (<Html><Head />- <Preview>New API Key Created</Preview>+ <Preview>New Workspace API Key Created</Preview><Tailwind><Body className="mx-auto my-auto bg-white font-sans"><Container className="mx-auto my-10 max-w-[500px] rounded border border-solid border-gray-200 px-10 py-5">@@ -37,17 +53,22 @@ export default function APIKeyCreated({/></Section><Heading className="mx-0 my-7 p-0 text-center text-xl font-semibold text-black">- New API Key Created+ New Workspace API Key Created</Heading><Text className="text-sm leading-6 text-black">- You created a new API key for your Dub.co account with the name{" "}- <strong>"{apiKeyName}"</strong> on{" "}+ You've created a new API key for your Dub.co workspace{" "}+ <strong>{workspace.name}</strong> with the name{" "}+ <strong>"{token.name}"</strong> on{" "}{formatDate(new Date().toString())}.</Text>- <Section className="my-8 text-center">+ <Text className="text-sm leading-6 text-black">+ Since this is a <strong>{token.type}</strong> token, it has{" "}+ {token.permissions}.+ </Text>+ <Section className="mb-8 mt-4 text-center"><LinkclassName="rounded-full bg-black px-6 py-3 text-center text-[12px] font-semibold text-white no-underline"- href="https://app.dub.co/settings/tokens"+ href={`https://app.dub.co/${workspace.slug}/settings/tokens`}>View API Keys</Link>@@ -55,7 +76,7 @@ export default function APIKeyCreated({<Text className="text-sm leading-6 text-black">If you did not create this API key, you can{" "}<Link- href="https://app.dub.co/settings/tokens"+ href={`https://app.dub.co/${workspace.slug}/settings/tokens`}className="text-black underline"><strong>delete this key</strong>diff --git a/apps/web/lib/api/tokens/scopes.ts b/apps/web/lib/api/tokens/scopes.tsindex a71af2e031..2b740e435e 100644--- a/apps/web/lib/api/tokens/scopes.ts+++ b/apps/web/lib/api/tokens/scopes.ts@@ -184,16 +184,35 @@ export const scopePresets = [{value: "all_access",label: "All",- description: "This API key will have full access to all resources",+ description: "full access to all resources",},{value: "read_only",label: "Read Only",- description: "This API key will have read-only access to all resources",+ description: "read-only access to all resources",},{value: "restricted",label: "Restricted",- description: "This API key will have restricted access to some resources",+ description: "restricted access to some resources",},];++export const scopesToName = (scopes: string[]) => {+ if (scopes.includes("apis.all")) {+ return {+ name: "All access",+ description: "full access to all resources",+ };+ }+ if (scopes.includes("apis.read")) {+ return {+ name: "Read-only",+ description: "read-only access to all resources",+ };+ }+ return {+ name: "Restricted",+ description: "restricted access to some resources",+ };+};diff --git a/apps/web/ui/modals/add-edit-token-modal.tsx b/apps/web/ui/modals/add-edit-token-modal.tsxindex 23b8871a30..870e3275b7 100644--- a/apps/web/ui/modals/add-edit-token-modal.tsx+++ b/apps/web/ui/modals/add-edit-token-modal.tsx@@ -229,6 +229,7 @@ function AddEditTokenModal({<AnimatedSizeContainer height><div className="p-1 pt-0 text-sm text-gray-500">+ This API key will have{" "}{scopePresets.find((p) => p.value === preset)?.description}</div>{preset === "restricted" && (