domain apis (#146)

* fix: create domain api

* add domain apis

* fix url

---------

Co-authored-by: harshsbhat <harsh121102@gmail.com>
This commit is contained in:
KM Koushik
2025-04-05 06:48:03 +11:00
committed by GitHub
parent 43600419cb
commit 70026cb11d
11 changed files with 415 additions and 12 deletions

View File

@@ -0,0 +1,3 @@
---
openapi: post /v1/domains
---

View File

@@ -0,0 +1,3 @@
---
openapi: put /v1/domains/{id}/verify
---

View File

@@ -85,6 +85,22 @@
},
"updatedAt": {
"type": "string"
},
"dmarcAdded": {
"type": "boolean",
"default": false
},
"isVerifying": {
"type": "boolean",
"default": false
},
"errorMessage": {
"type": "string",
"nullable": true
},
"subdomain": {
"type": "string",
"nullable": true
}
},
"required": [
@@ -102,6 +118,158 @@
}
}
}
},
"post": {
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"name": {
"type": "string"
},
"region": {
"type": "string"
}
},
"required": [
"name",
"region"
]
}
}
}
},
"responses": {
"200": {
"description": "Create a new domain",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"id": {
"type": "number",
"description": "The ID of the domain",
"example": 1
},
"name": {
"type": "string",
"description": "The name of the domain",
"example": "example.com"
},
"teamId": {
"type": "number",
"description": "The ID of the team",
"example": 1
},
"status": {
"type": "string",
"enum": [
"NOT_STARTED",
"PENDING",
"SUCCESS",
"FAILED",
"TEMPORARY_FAILURE"
]
},
"region": {
"type": "string",
"default": "us-east-1"
},
"clickTracking": {
"type": "boolean",
"default": false
},
"openTracking": {
"type": "boolean",
"default": false
},
"publicKey": {
"type": "string"
},
"dkimStatus": {
"type": "string",
"nullable": true
},
"spfDetails": {
"type": "string",
"nullable": true
},
"createdAt": {
"type": "string"
},
"updatedAt": {
"type": "string"
},
"dmarcAdded": {
"type": "boolean",
"default": false
},
"isVerifying": {
"type": "boolean",
"default": false
},
"errorMessage": {
"type": "string",
"nullable": true
},
"subdomain": {
"type": "string",
"nullable": true
}
},
"required": [
"id",
"name",
"teamId",
"status",
"publicKey",
"createdAt",
"updatedAt"
]
}
}
}
}
}
}
},
"/v1/domains/{id}/verify": {
"put": {
"parameters": [
{
"schema": {
"type": "number",
"example": 1
},
"required": true,
"name": "id",
"in": "path"
}
],
"responses": {
"200": {
"description": "Create a new domain",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"message": {
"type": "string"
}
},
"required": [
"message"
]
}
}
}
}
}
}
},
"/v1/emails/{emailId}": {

View File

@@ -96,7 +96,9 @@
{
"group": "Domains",
"pages": [
"api-reference/domains/get-domain"
"api-reference/domains/get-domain",
"api-reference/domains/create-domain",
"api-reference/domains/verify-domain"
]
}
],

View File

@@ -18,14 +18,8 @@ export const DomainSchema = z.object({
spfDetails: z.string().optional().nullish(),
createdAt: z.string(),
updatedAt: z.string(),
});
export const CreateDomainSchema = DomainSchema.omit({
id: true,
createdAt: true,
updatedAt: true,
teamId: true,
publicKey: true,
dkimStatus: true,
spfDetails: true,
dmarcAdded: z.boolean().default(false),
isVerifying: z.boolean().default(false),
errorMessage: z.string().optional().nullish(),
subdomain: z.string().optional().nullish(),
});

View File

@@ -0,0 +1,45 @@
import { createRoute, z } from "@hono/zod-openapi";
import { DomainSchema } from "~/lib/zod/domain-schema";
import { PublicAPIApp } from "~/server/public-api/hono";
import { createDomain as createDomainService } from "~/server/service/domain-service";
import { getTeamFromToken } from "~/server/public-api/auth";
const route = createRoute({
method: "post",
path: "/v1/domains",
request: {
body: {
required: true,
content: {
"application/json": {
schema: z.object({
name: z.string(),
region: z.string(),
}),
},
},
},
},
responses: {
200: {
content: {
"application/json": {
schema: DomainSchema,
},
},
description: "Create a new domain",
},
},
});
function createDomain(app: PublicAPIApp) {
app.openapi(route, async (c) => {
const team = await getTeamFromToken(c);
const body = c.req.valid("json");
const response = await createDomainService(team.id, body.name, body.region);
return c.json(response);
});
}
export default createDomain;

View File

@@ -0,0 +1,49 @@
import { createRoute, z } from "@hono/zod-openapi";
import { PublicAPIApp } from "~/server/public-api/hono";
import { getTeamFromToken } from "~/server/public-api/auth";
import { db } from "~/server/db";
const route = createRoute({
method: "put",
path: "/v1/domains/{id}/verify",
request: {
params: z.object({
id: z.coerce.number().openapi({
param: {
name: "id",
in: "path",
},
example: 1,
}),
}),
},
responses: {
200: {
content: {
"application/json": {
schema: z.object({
message: z.string(),
}),
},
},
description: "Create a new domain",
},
},
});
function verifyDomain(app: PublicAPIApp) {
app.openapi(route, async (c) => {
const team = await getTeamFromToken(c);
await db.domain.update({
where: { id: c.req.valid("param").id },
data: { isVerifying: true },
});
return c.json({
message: "Domain verification started",
});
});
}
export default verifyDomain;

View File

@@ -9,12 +9,16 @@ import updateEmailScheduledAt from "./api/emails/update-email";
import cancelScheduledEmail from "./api/emails/cancel-email";
import getContacts from "./api/contacts/get-contacts";
import upsertContact from "./api/contacts/upsert-contact";
import createDomain from "./api/domains/create-domain";
import deleteContact from "./api/contacts/delete-contact";
import verifyDomain from "./api/domains/verify-domain";
export const app = getApp();
/**Domain related APIs */
getDomains(app);
createDomain(app);
verifyDomain(app);
/**Email related APIs */
getEmail(app);