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.

add add, list and delete endpoints

Kiran K36975e91daf5
diff --git a/apps/docs/api-reference/endpoint/add-a-domain.mdx b/apps/docs/api-reference/endpoint/add-a-domain.mdx
new file mode 100644
index 0000000000..bc95b4dc0f
--- /dev/null
+++ b/apps/docs/api-reference/endpoint/add-a-domain.mdx
@@ -0,0 +1,4 @@
+---
+openapi: post /domains
+og:title: "Add a domain to the workspace with the Dub.co API - API Reference"
+---
diff --git a/apps/docs/api-reference/endpoint/delete-a-domain.mdx b/apps/docs/api-reference/endpoint/delete-a-domain.mdx
new file mode 100644
index 0000000000..6846f741c9
--- /dev/null
+++ b/apps/docs/api-reference/endpoint/delete-a-domain.mdx
@@ -0,0 +1,4 @@
+---
+openapi: delete /domains/{slug}
+og:title: "Delete a domain from the workspace with the Dub.co API - API Reference"
+---
diff --git a/apps/docs/api-reference/endpoint/retrieve-a-list-of-domains.mdx b/apps/docs/api-reference/endpoint/retrieve-a-list-of-domains.mdx
new file mode 100644
index 0000000000..a0702727f4
--- /dev/null
+++ b/apps/docs/api-reference/endpoint/retrieve-a-list-of-domains.mdx
@@ -0,0 +1,4 @@
+---
+openapi: get /domains
+og:title: "Get list of domains associated with the workspace with the Dub.co API - API Reference"
+---
diff --git a/apps/web/app/api/domains/[domain]/route.ts b/apps/web/app/api/domains/[domain]/route.ts
index fe36b0bd1a..fa4a2a6182 100644
--- a/apps/web/app/api/domains/[domain]/route.ts
+++ b/apps/web/app/api/domains/[domain]/route.ts
@@ -109,7 +109,7 @@ export const PUT = withAuth(
export const DELETE = withAuth(
async ({ domain }) => {
const response = await deleteDomainAndLinks(domain);
- return NextResponse.json(response);
+ return NextResponse.json({ slug: domain });
},
{
domainChecks: true,
diff --git a/apps/web/lib/openapi/domains/add-domain.ts b/apps/web/lib/openapi/domains/add-domain.ts
new file mode 100644
index 0000000000..3588496cb9
--- /dev/null
+++ b/apps/web/lib/openapi/domains/add-domain.ts
@@ -0,0 +1,34 @@
+import { openApiErrorResponses } from "@/lib/openapi/responses";
+import { DomainSchema, addDomainBodySchema } from "@/lib/zod/schemas";
+import { ZodOpenApiOperationObject } from "zod-openapi";
+import { workspaceParamsSchema } from "../request";
+
+export const addDomain: ZodOpenApiOperationObject = {
+ operationId: "addDomain",
+ "x-speakeasy-name-override": "add",
+ summary: "Add a domain",
+ description: "Add a domain to the authenticated workspace.",
+ requestParams: {
+ query: workspaceParamsSchema,
+ },
+ requestBody: {
+ content: {
+ "application/json": {
+ schema: addDomainBodySchema,
+ },
+ },
+ },
+ responses: {
+ "200": {
+ description: "The domain was added.",
+ content: {
+ "application/json": {
+ schema: DomainSchema,
+ },
+ },
+ },
+ ...openApiErrorResponses,
+ },
+ tags: ["Domains"],
+ security: [{ token: [] }],
+};
diff --git a/apps/web/lib/openapi/domains/delete-domain.ts b/apps/web/lib/openapi/domains/delete-domain.ts
new file mode 100644
index 0000000000..d081c128aa
--- /dev/null
+++ b/apps/web/lib/openapi/domains/delete-domain.ts
@@ -0,0 +1,28 @@
+import { openApiErrorResponses } from "@/lib/openapi/responses";
+import { DomainSchema } from "@/lib/zod/schemas";
+import { ZodOpenApiOperationObject } from "zod-openapi";
+import { workspaceParamsSchema } from "../request";
+
+export const deleteDomain: ZodOpenApiOperationObject = {
+ operationId: "deleteDomain",
+ "x-speakeasy-name-override": "deleteDomain",
+ summary: "Delete a domain",
+ description: "Delete a domain from a workspace.",
+ requestParams: {
+ query: workspaceParamsSchema,
+ path: DomainSchema.pick({ slug: true }),
+ },
+ responses: {
+ "200": {
+ description: "The domain was deleted.",
+ content: {
+ "application/json": {
+ schema: DomainSchema.pick({ slug: true }),
+ },
+ },
+ },
+ ...openApiErrorResponses,
+ },
+ tags: ["Domains"],
+ security: [{ token: [] }],
+};
diff --git a/apps/web/lib/openapi/domains/index.ts b/apps/web/lib/openapi/domains/index.ts
new file mode 100644
index 0000000000..8774dc2d65
--- /dev/null
+++ b/apps/web/lib/openapi/domains/index.ts
@@ -0,0 +1,14 @@
+import { ZodOpenApiPathsObject } from "zod-openapi";
+import { addDomain } from "./add-domain";
+import { listDomains } from "./list-domains";
+import { deleteDomain } from "./delete-domain";
+
+export const domainsPaths: ZodOpenApiPathsObject = {
+ "/domains": {
+ post: addDomain,
+ get: listDomains,
+ },
+ "/domains/{slug}": {
+ delete: deleteDomain,
+ },
+};
diff --git a/apps/web/lib/openapi/domains/list-domains.ts b/apps/web/lib/openapi/domains/list-domains.ts
new file mode 100644
index 0000000000..332539224a
--- /dev/null
+++ b/apps/web/lib/openapi/domains/list-domains.ts
@@ -0,0 +1,29 @@
+import { openApiErrorResponses } from "@/lib/openapi/responses";
+import { DomainSchema } from "@/lib/zod/schemas";
+import { ZodOpenApiOperationObject } from "zod-openapi";
+import { workspaceParamsSchema } from "../request";
+import z from "@/lib/zod";
+
+export const listDomains: ZodOpenApiOperationObject = {
+ operationId: "listDomains",
+ "x-speakeasy-name-override": "list",
+ summary: "Retrieve a list of domains",
+ description:
+ "Retrieve a list of domains associated with the authenticated workspace.",
+ requestParams: {
+ query: workspaceParamsSchema,
+ },
+ responses: {
+ "200": {
+ description: "The domains were retrieved.",
+ content: {
+ "application/json": {
+ schema: z.array(DomainSchema),
+ },
+ },
+ },
+ ...openApiErrorResponses,
+ },
+ tags: ["Domains"],
+ security: [{ token: [] }],
+};
diff --git a/apps/web/lib/zod/schemas/domains.ts b/apps/web/lib/zod/schemas/domains.ts
new file mode 100644
index 0000000000..63e0d510a0
--- /dev/null
+++ b/apps/web/lib/zod/schemas/domains.ts
@@ -0,0 +1,86 @@
+import z from "@/lib/zod";
+
+// TODO
+// Add max and min
+
+export const addDomainBodySchema = z.object({
+ slug: z
+ .string({ required_error: "Domain name is required" })
+ .min(1)
+ .max(50, "Domain name is too long. Max 50 characters long")
+ .describe("Name of the domain."),
+ target: z
+ .string()
+ .url("Target URL must be a valid URL.")
+ .optional()
+ .describe(
+ "The page your users will get redirected to when they visit your domain.",
+ ),
+ type: z
+ .enum(["redirect", "rewrite"])
+ .optional()
+ .default("redirect")
+ .describe("The type of redirect to use for this domain."),
+ expiredUrl: z
+ .string()
+ .url("Expired URL must be a valid URL")
+ .optional()
+ .describe(
+ "Redirect users to a specific URL when any link under this domain has expired.",
+ ),
+ placeholder: z
+ .string()
+ .url("Placeholder URL must be a valid URL")
+ .optional()
+ .describe(
+ "Provide context to your teammates in the link creation modal by showing them an example of a link to be shortened.",
+ ),
+});
+
+export const DomainSchema = z
+ .object({
+ slug: z
+ .string()
+ .describe("The domain name.")
+ .openapi({ example: "acme.com" }),
+ verified: z.boolean().describe("Whether the domain is verified."),
+ primary: z
+ .boolean()
+ .describe("Whether the domain is the primary domain for the workspace."),
+ archived: z
+ .boolean()
+ .describe("Whether the domain is archived.")
+ .default(false),
+ placeholder: z
+ .string()
+ .describe(
+ "Provide context to your teammates in the link creation modal by showing them an example of a link to be shortened.",
+ )
+ .default("https://dub.co/help/article/what-is-dub")
+ .openapi({ example: "https://dub.co/help/article/what-is-dub" }),
+ expiredUrl: z
+ .string()
+ .nullable()
+ .describe(
+ "The URL to redirect to when a link under this domain has expired.",
+ )
+ .openapi({ example: "https://acme.com/expired" }),
+ target: z
+ .string()
+ .nullable()
+ .describe(
+ "The page your users will get redirected to when they visit your domain.",
+ )
+ .openapi({ example: "https://acme.com/landing" }),
+ type: z
+ .string()
+ .describe("The type of redirect to use for this domain.")
+ .openapi({ enum: ["redirect", "rewrite"] }),
+ clicks: z
+ .number()
+ .describe("The number of clicks on the domain.")
+ .default(0),
+ })
+ .strict();
+
+export type Domain = z.infer<typeof DomainSchema>;
diff --git a/apps/web/lib/zod/schemas/index.ts b/apps/web/lib/zod/schemas/index.ts
index f8656b3fa0..8331fdf096 100644
--- a/apps/web/lib/zod/schemas/index.ts
+++ b/apps/web/lib/zod/schemas/index.ts
@@ -4,3 +4,4 @@ export * from "./misc";
export * from "./qr";
export * from "./tags";
export * from "./workspaces";
+export * from "./domains";
diff --git a/apps/web/lib/zod/schemas/workspaces.ts b/apps/web/lib/zod/schemas/workspaces.ts
index 932cd3f0f5..4317c76ace 100644
--- a/apps/web/lib/zod/schemas/workspaces.ts
+++ b/apps/web/lib/zod/schemas/workspaces.ts
@@ -6,14 +6,7 @@ import {
validSlugRegex,
} from "@dub/utils";
import slugify from "@sindresorhus/slugify";
-import { planSchema, roleSchema } from ".";
-
-export const DomainSchema = z.object({
- slug: z.string().describe("The domain of the workspace."),
- primary: z
- .boolean()
- .describe("Indicates if the domain is the primary domain."),
-});
+import { DomainSchema, planSchema, roleSchema } from ".";
export const WorkspaceSchema = z
.object({
@@ -49,7 +42,14 @@ export const WorkspaceSchema = z
}),
)
.describe("The role of the authenticated user in the workspace."),
- domains: z.array(DomainSchema).describe("The domains of the workspace."),
+ domains: z
+ .array(
+ DomainSchema.pick({
+ slug: true,
+ primary: true,
+ }),
+ )
+ .describe("The domains of the workspace."),
})
.openapi({
title: "Workspace",