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.

create dots app

Kiran Ke4dadacfed9d
diff --git a/apps/web/lib/dots/create-dots-app.ts b/apps/web/lib/dots/create-dots-app.ts
new file mode 100644
index 0000000000..102184a480
--- /dev/null
+++ b/apps/web/lib/dots/create-dots-app.ts
@@ -0,0 +1,34 @@
+import { Project } from "@prisma/client";
+import { DOTS_API_URL } from "./env";
+import { dotsAppSchema } from "./schemas";
+import { getBasicAuthToken } from "./utils";
+
+export const createDotsApp = async ({
+ workspace,
+}: {
+ workspace: Pick<Project, "id" | "name">;
+}) => {
+ const response = await fetch(`${DOTS_API_URL}/apps`, {
+ method: "POST",
+ headers: {
+ "Content-Type": "application/json",
+ Authorization: `Basic ${getBasicAuthToken()}`,
+ },
+ body: JSON.stringify({
+ name: workspace.name,
+ metadata: {
+ workspaceId: workspace.id,
+ },
+ }),
+ });
+
+ if (!response.ok) {
+ console.error(await response.text());
+
+ throw new Error(
+ `Failed to create Dots app for the workspace ${workspace.id}.`,
+ );
+ }
+
+ return dotsAppSchema.parse(await response.json());
+};
diff --git a/apps/web/lib/dots/schemas.ts b/apps/web/lib/dots/schemas.ts
new file mode 100644
index 0000000000..f07f0b1598
--- /dev/null
+++ b/apps/web/lib/dots/schemas.ts
@@ -0,0 +1,7 @@
+import z from "../zod";
+
+export const dotsAppSchema = z.object({
+ id: z.string(),
+ name: z.string(),
+ status: z.string(),
+});
diff --git a/apps/web/lib/dots/utils.ts b/apps/web/lib/dots/utils.ts
new file mode 100644
index 0000000000..f687ad7e4f
--- /dev/null
+++ b/apps/web/lib/dots/utils.ts
@@ -0,0 +1,5 @@
+import { DOTS_API_KEY, DOTS_CLIENT_ID } from "./env";
+
+export const getBasicAuthToken = () => {
+ return Buffer.from(`${DOTS_CLIENT_ID}:${DOTS_API_KEY}`).toString("base64");
+};