The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Add project paths
Kiran K5eedc9cf20da
diff --git a/apps/web/lib/openapi/index.ts b/apps/web/lib/openapi/index.tsindex be52a41e3f..d7d3bf1929 100644--- a/apps/web/lib/openapi/index.ts+++ b/apps/web/lib/openapi/index.ts@@ -2,8 +2,10 @@ import { createDocument } from "zod-openapi";import { linksPaths } from "./links";import { tagsPaths } from "./tags";+import { projectsPaths } from "./projects";import { LinkSchema } from "@/lib/zod/schemas/links";import { TagSchema } from "@/lib/zod/schemas/tags";+import { ProjectSchema } from "@/lib/zod/schemas/projects";export const openAPIDocument = createDocument({openapi: "3.0.3",@@ -30,12 +32,13 @@ export const openAPIDocument = createDocument({],paths: {...linksPaths,+ ...projectsPaths,...tagsPaths,- // ...projectPaths,},components: {schemas: {LinkSchema,+ ProjectSchema,TagSchema,},},diff --git a/apps/web/lib/openapi/projects/get-project-info.ts b/apps/web/lib/openapi/projects/get-project-info.tsnew file mode 100644index 0000000000..69fa58464c--- /dev/null+++ b/apps/web/lib/openapi/projects/get-project-info.ts@@ -0,0 +1,30 @@+import { ZodOpenApiOperationObject } from "zod-openapi";++import z from "@/lib/zod";+import { ProjectSchema } from "@/lib/zod/schemas/projects";++export const getProjectInfo: ZodOpenApiOperationObject = {+ operationId: "getProjectInfo",+ summary: "Retrieve a project",+ description: "Retrieve a project for the authenticated user.",+ requestParams: {+ path: z.object({+ projectSlug: z+ .string()+ .describe(+ "The slug for the project to retrieve. E.g. for `app.dub.co/acme`, the projectSlug is `acme`.",+ ),+ }),+ },+ responses: {+ "200": {+ description: "The retrieved project",+ content: {+ "application/json": {+ schema: ProjectSchema,+ },+ },+ },+ },+ tags: ["Projects"],+};diff --git a/apps/web/lib/openapi/projects/get-projects.ts b/apps/web/lib/openapi/projects/get-projects.tsnew file mode 100644index 0000000000..b9a142aae0--- /dev/null+++ b/apps/web/lib/openapi/projects/get-projects.ts@@ -0,0 +1,21 @@+import { ZodOpenApiOperationObject } from "zod-openapi";++import z from "@/lib/zod";+import { ProjectSchema } from "@/lib/zod/schemas/projects";++export const getProjects: ZodOpenApiOperationObject = {+ operationId: "getProjects",+ summary: "Retrieve a list of projects",+ description: "Retrieve a list of projects for the authenticated user.",+ responses: {+ "200": {+ description: "A list of projects",+ content: {+ "application/json": {+ schema: z.array(ProjectSchema),+ },+ },+ },+ },+ tags: ["Projects"],+};diff --git a/apps/web/lib/openapi/projects/index.ts b/apps/web/lib/openapi/projects/index.tsnew file mode 100644index 0000000000..e9571b5ac7--- /dev/null+++ b/apps/web/lib/openapi/projects/index.ts@@ -0,0 +1,13 @@+import { ZodOpenApiPathsObject } from "zod-openapi";++import { getProjects } from "./get-projects";+import { getProjectInfo } from "./get-project-info";++export const projectsPaths: ZodOpenApiPathsObject = {+ "/projects": {+ get: getProjects,+ },+ "/projects/{projectSlug}": {+ get: getProjectInfo,+ },+};diff --git a/apps/web/lib/types.ts b/apps/web/lib/types.tsindex f3a85aad85..fa30d64d97 100644--- a/apps/web/lib/types.ts+++ b/apps/web/lib/types.ts@@ -1,5 +1,7 @@import { DirectorySyncProviders } from "@boxyhq/saml-jackson";+import z from "@/lib/zod";+import { PlanSchema } from "./zod/schemas";import { CreateLinkBodySchema } from "./zod/schemas/links";export { type Link as LinkProps } from "@prisma/client";@@ -44,7 +46,7 @@ export type TagColorProps =| "pink"| "brown";-export type PlanProps = "free" | "pro" | "business" | "enterprise";+export type PlanProps = z.infer<typeof PlanSchema>;export interface ProjectProps {id: string;@@ -141,4 +143,4 @@ export interface SAMLProviderProps {};}-export type NewLinkProps = z.infer<typeof CreateLinkBodySchema>;\ No newline at end of file+export type NewLinkProps = z.infer<typeof CreateLinkBodySchema>;diff --git a/apps/web/lib/zod/schemas/projects.ts b/apps/web/lib/zod/schemas/projects.tsindex 8280c8e253..09448245bf 100644--- a/apps/web/lib/zod/schemas/projects.ts+++ b/apps/web/lib/zod/schemas/projects.ts@@ -1,75 +1,53 @@import z from "@/lib/zod";-import { ProjectSchema } from "prisma/zod";-import { ZodOpenApiOperationObject, ZodOpenApiPathsObject } from "zod-openapi";+import { RoleSchema, PlanSchema } from "prisma/zod";-export const ProjectSchemaOpenApi = ProjectSchema.pick({- id: true,- name: true,- slug: true,- logo: true,- usage: true,- usageLimit: true,- plan: true,- stripeId: true,- billingCycleStart: true,- createdAt: true,-}).openapi({- title: "Project",- properties: {- id: {- description: "The unique ID of the project.",- },- name: {- description: "The name of the project.",- },- slug: {- description: "The slug of the project.",- },- logo: {- description: "The logo of the project.",- },- usage: {- description: "The usage of the project.",- },- usageLimit: {- description: "The usage limit of the project.",- },- plan: {- description: "The plan of the project.",- },- stripeId: {- description: "The Stripe ID of the project.",- },- billingCycleStart: {- description:+export const ProjectSchema = z+ .object({+ id: z.string().describe("The unique ID of the project."),+ name: z.string().describe("The name of the project."),+ slug: z.string().describe("The slug of the project."),+ logo: z+ .string()+ .nullable()+ .default(null)+ .describe("The logo of the project."),+ usage: z.number().describe("The usage of the project."),+ usageLimit: z.number().describe("The usage limit of the project."),+ linksUsage: z.number().describe("The links usage of the project."),+ linksLimit: z.number().describe("The links limit of the project."),+ domainsLimit: z.number().describe("The domains limit of the project."),+ tagsLimit: z.number().describe("The tags limit of the project."),+ usersLimit: z.number().describe("The users limit of the project."),+ plan: PlanSchema.describe("The plan of the project."),+ stripeId: z.string().nullable().describe("The Stripe ID of the project."),+ billingCycleStart: z+ .number()+ .describe("The date and time when the billing cycle starts for the project.",- },- createdAt: {- description: "The date and time when the project was created.",- },- },-});--export type Project = z.infer<typeof ProjectSchemaOpenApi>;--export const getProjects: ZodOpenApiOperationObject = {- operationId: "getProjects",- summary: "Retrieve a list of projects",- description: "Retrieve a list of projects for the authenticated user.",- responses: {- "200": {- description: "The projects were retrieved",- content: {- "application/json": {- schema: z.array(ProjectSchemaOpenApi),- },- },- },- },-};--export const projectPaths: ZodOpenApiPathsObject = {- "/projects": {- get: getProjects,- },-};+ ),+ createdAt: z+ .date()+ .describe("The date and time when the project was created."),+ users: z+ .array(+ z.object({+ role: RoleSchema.describe(+ "The role of the authenticated user in the project.",+ ),+ }),+ )+ .describe("The role of the authenticated user in the project."),+ domains: z+ .array(+ z.object({+ slug: z.string().describe("The domain of the project."),+ }),+ )+ .describe("The domains of the project."),+ metadata: z.object({+ defaultDomains: z.array(z.string()),+ }),+ })+ .openapi({+ title: "Project",+ });diff --git a/apps/web/prisma/schema.prisma b/apps/web/prisma/schema.prismaindex a26720fc5f..7843f186ad 100644--- a/apps/web/prisma/schema.prisma+++ b/apps/web/prisma/schema.prisma@@ -29,28 +29,28 @@ model User {emailVerified DateTime?image String?- accounts Account[]- sessions Session[]- projects ProjectUsers[]- links Link[]- tokens Token[]- createdAt DateTime @default(now())+ accounts Account[]+ sessions Session[]+ projects ProjectUsers[]+ links Link[]+ tokens Token[]+ createdAt DateTime @default(now())}model Account {- id String @id @default(cuid())- userId String- type String- provider String- providerAccountId String- refresh_token String? @db.Text- refresh_token_expires_in Int?- access_token String? @db.Text- expires_at Int?- token_type String?- scope String?- id_token String? @db.Text- session_state String?+ id String @id @default(cuid())+ userId String+ type String+ provider String+ providerAccountId String+ refresh_token String? @db.Text+ refresh_token_expires_in Int?+ 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)@@ -77,48 +77,48 @@ model VerificationToken {}model Token {- id String @id @default(cuid())- name String- hashedKey String @unique+ id String @id @default(cuid())+ name String+ hashedKey String @uniquepartialKey String- expires DateTime?- lastUsed DateTime?- createdAt DateTime @default(now())- updatedAt DateTime @updatedAt- user User @relation(fields: [userId], references: [id], onDelete: Cascade)- userId String+ expires DateTime?+ lastUsed DateTime?+ createdAt DateTime @default(now())+ updatedAt DateTime @updatedAt+ user User @relation(fields: [userId], references: [id], onDelete: Cascade)+ userId String@@index([userId])}model Project {- id String @id @default(cuid())- name String- slug String @unique- logo String?-- plan String @default("free")- stripeId String? @unique // Stripe subscription ID- billingCycleStart Int // day of the month when the billing cycle starts- usage Int @default(0)- usageLimit Int @default(1000)- linksUsage Int @default(0)- linksLimit Int @default(25)- domainsLimit Int @default(3)- tagsLimit Int @default(5)- usersLimit Int @default(1)- monitoringId String? @unique // cron job ID for monitoring-- users ProjectUsers[]- invites ProjectInvite[]- sentEmails SentEmail[]- links Link[]- domains Domain[]- tags Tag[]-- createdAt DateTime @default(now())- updatedAt DateTime @updatedAt- metadata Json? @default("{\"defaultDomains\":[\"dub.sh\",\"chatg.pt\",\"spti.fi\",\"amzn.id\"]}")+ id String @id @default(cuid())+ name String+ slug String @unique+ logo String?++ plan String @default("free")+ stripeId String? @unique // Stripe subscription ID+ billingCycleStart Int // day of the month when the billing cycle starts+ usage Int @default(0)+ usageLimit Int @default(1000)+ linksUsage Int @default(0)+ linksLimit Int @default(25)+ domainsLimit Int @default(3)+ tagsLimit Int @default(5)+ usersLimit Int @default(1)+ monitoringId String? @unique // cron job ID for monitoring++ users ProjectUsers[]+ invites ProjectInvite[]+ sentEmails SentEmail[]+ links Link[]+ domains Domain[]+ tags Tag[]++ createdAt DateTime @default(now())+ updatedAt DateTime @updatedAt+ metadata Json? @default("{\"defaultDomains\":[\"dub.sh\",\"chatg.pt\",\"spti.fi\",\"amzn.id\"]}")}model ProjectInvite {@@ -137,9 +137,16 @@ enum Role {member}+enum Plan {+ free+ pro+ business+ enterprise+}+model ProjectUsers {id String @id @default(cuid())- role Role @default(member)+ role Role @default(member)createdAt DateTime @default(now())updatedAt DateTime @updatedAtuser User @relation(fields: [userId], references: [id], onDelete: Cascade)@@ -152,33 +159,33 @@ model ProjectUsers {}model SentEmail {- id String @id @default(cuid())+ id String @id @default(cuid())type String- createdAt DateTime @default(now())- project Project? @relation(fields: [projectId], references: [id], onDelete: Cascade)+ createdAt DateTime @default(now())+ project Project? @relation(fields: [projectId], references: [id], onDelete: Cascade)projectId String?@@index([projectId])}model Domain {- id String @id @default(cuid())- slug String @unique- verified Boolean @default(false)- target String?- type String @default("redirect")- placeholder String @default("https://dub.co/help/article/what-is-dub")- description String?- project Project? @relation(fields: [projectId], references: [id], onDelete: Cascade)- projectId String?- primary Boolean @default(false)- archived Boolean @default(false)- links Link[]- clicks Int @default(0)- lastClicked DateTime? // when the link was last clicked- lastChecked DateTime @default(now())- createdAt DateTime @default(now())- updatedAt DateTime @updatedAt+ id String @id @default(cuid())+ slug String @unique+ verified Boolean @default(false)+ target String?+ type String @default("redirect")+ placeholder String @default("https://dub.co/help/article/what-is-dub")+ description String?+ project Project? @relation(fields: [projectId], references: [id], onDelete: Cascade)+ projectId String?+ primary Boolean @default(false)+ archived Boolean @default(false)+ links Link[]+ clicks Int @default(0)+ lastClicked DateTime? // when the link was last clicked+ lastChecked DateTime @default(now())+ createdAt DateTime @default(now())+ updatedAt DateTime @updatedAt@@index(projectId)@@index(clicks(sort: Desc))@@ -208,12 +215,12 @@ model Link {utm_content String? // UTM content for the link (e.g. description)// Link cloaking/masking via rewrite- rewrite Boolean @default(false) // whether to rewrite the link or not+ rewrite Boolean @default(false) // whether to rewrite the link or not// Custom device targetingios String? @db.LongText // custom link for iOS devicesandroid String? @db.LongText // custom link for Android devices- geo Json? @db.Json // custom link for specific countries+ geo Json? @db.Json // custom link for specific countries// User who created the linkuser User? @relation(fields: [userId], references: [id])@@ -225,19 +232,19 @@ model Link {// Relational reference to the project domainprojectDomain Domain? @relation(fields: [domain], references: [slug], onUpdate: Cascade, onDelete: Cascade)- publicStats Boolean @default(false) // whether to show public stats or not- clicks Int @default(0) // number of clicks+ publicStats Boolean @default(false) // whether to show public stats or not+ clicks Int @default(0) // number of clickslastClicked DateTime? // when the link was last clicked- checkDisabled Boolean @default(false) // disable 404 checking- createdAt DateTime @default(now())- updatedAt DateTime @updatedAt+ checkDisabled Boolean @default(false) // disable 404 checking+ createdAt DateTime @default(now())+ updatedAt DateTime @updatedAt// Link tagstag Tag? @relation(fields: [tagId], references: [id])tagId String?// Comments on the particular shortlink- comments String? @db.LongText+ comments String? @db.LongText// TODO: might wanna add indices for utm_source, utm_medium, utm_campaign@@ -279,13 +286,13 @@ model jackson_index {}model jackson_store {- key String @id @db.VarChar(250)- value String @db.Text- iv String? @db.VarChar(64)- tag String? @db.VarChar(64)- namespace String? @db.VarChar(64)- createdAt DateTime @default(now()) @db.Timestamp(0)- modifiedAt DateTime? @db.Timestamp(0)+ key String @id @db.VarChar(250)+ value String @db.Text+ iv String? @db.VarChar(64)+ tag String? @db.VarChar(64)+ namespace String? @db.VarChar(64)+ createdAt DateTime @default(now()) @db.Timestamp(0)+ modifiedAt DateTime? @db.Timestamp(0)@@index([namespace], map: "_jackson_store_namespace")}@@ -295,4 +302,4 @@ model jackson_ttl {expiresAt BigInt@@index([expiresAt], map: "_jackson_ttl_expires_at")-}\ No newline at end of file+}diff --git a/apps/web/prisma/zod/index.ts b/apps/web/prisma/zod/index.tsindex 581c6b6c39..19d88ae733 100644--- a/apps/web/prisma/zod/index.ts+++ b/apps/web/prisma/zod/index.ts@@ -128,6 +128,10 @@ export const RoleSchema = z.enum(['owner','member']);export type RoleType = `${z.infer<typeof RoleSchema>}`+export const PlanSchema = z.enum(['free','pro','business','enterprise']);++export type PlanType = `${z.infer<typeof PlanSchema>}`+/////////////////////////////////////////// MODELS/////////////////////////////////////////