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.

Simplify OpenAPI workspace schema

Steven Teyee0e7039d8de
diff --git a/apps/web/app/(ee)/api/shopify/integration/callback/route.ts b/apps/web/app/(ee)/api/shopify/integration/callback/route.ts
index 900d364e4d..ecc93496ee 100644
--- a/apps/web/app/(ee)/api/shopify/integration/callback/route.ts
+++ b/apps/web/app/(ee)/api/shopify/integration/callback/route.ts
@@ -8,15 +8,15 @@ import { waitUntil } from "@vercel/functions";
import { NextResponse } from "next/server";
import { z } from "zod";
-const updateWorkspaceSchema = z.object({
- shopifyStoreId: z.string().nullable(),
-});
-
// PATCH /api/shopify/integration/callback – update a shopify store id
export const PATCH = withWorkspace(
async ({ req, workspace, session }) => {
const body = await parseRequestBody(req);
- const { shopifyStoreId } = updateWorkspaceSchema.parse(body);
+ const { shopifyStoreId } = z
+ .object({
+ shopifyStoreId: z.string().nullable(),
+ })
+ .parse(body);
try {
const response = await prisma.project.update({
diff --git a/apps/web/app/(ee)/api/stripe/integration/route.ts b/apps/web/app/(ee)/api/stripe/integration/route.ts
index 94c5ac24e6..f792860e5f 100644
--- a/apps/web/app/(ee)/api/stripe/integration/route.ts
+++ b/apps/web/app/(ee)/api/stripe/integration/route.ts
@@ -14,15 +14,15 @@ const CORS_HEADERS = {
"Access-Control-Allow-Headers": "Content-Type, Authorization",
};
-const updateWorkspaceSchema = z.object({
- stripeAccountId: z.string().nullable(),
-});
-
// PATCH /api/stripe/integration - update a workspace with a stripe connect account id
export const PATCH = withWorkspace(
async ({ req, workspace, session }) => {
const body = await parseRequestBody(req);
- const { stripeAccountId } = updateWorkspaceSchema.parse(body);
+ const { stripeAccountId } = z
+ .object({
+ stripeAccountId: z.string().nullable(),
+ })
+ .parse(body);
try {
const response = await prisma.project.update({
diff --git a/apps/web/app/api/workspaces/[idOrSlug]/route.ts b/apps/web/app/api/workspaces/[idOrSlug]/route.ts
index 0f0580a56c..6d7a2190a5 100644
--- a/apps/web/app/api/workspaces/[idOrSlug]/route.ts
+++ b/apps/web/app/api/workspaces/[idOrSlug]/route.ts
@@ -7,8 +7,9 @@ import { deleteWorkspace } from "@/lib/api/workspaces";
import { withWorkspace } from "@/lib/auth";
import { getFeatureFlags } from "@/lib/edge-config";
import { storage } from "@/lib/storage";
+import z from "@/lib/zod";
import {
- updateWorkspaceSchema,
+ createWorkspaceSchema,
WorkspaceSchema,
WorkspaceSchemaExtended,
} from "@/lib/zod/schemas/workspaces";
@@ -17,6 +18,21 @@ import { nanoid, R2_URL } from "@dub/utils";
import { waitUntil } from "@vercel/functions";
import { NextResponse } from "next/server";
+const updateWorkspaceSchema = createWorkspaceSchema.extend({
+ allowedHostnames: z.array(z.string()).optional(),
+ publishableKey: z
+ .union([
+ z
+ .string()
+ .regex(
+ /^dub_pk_[A-Za-z0-9_-]{16,64}$/,
+ "Invalid publishable key format",
+ ),
+ z.null(),
+ ])
+ .optional(),
+});
+
// GET /api/workspaces/[idOrSlug] – get a specific workspace by id or slug
export const GET = withWorkspace(
async ({ workspace, headers }) => {
diff --git a/apps/web/lib/openapi/workspaces/update-workspace.ts b/apps/web/lib/openapi/workspaces/update-workspace.ts
index 955b0e684a..2b15cbaa12 100644
--- a/apps/web/lib/openapi/workspaces/update-workspace.ts
+++ b/apps/web/lib/openapi/workspaces/update-workspace.ts
@@ -2,7 +2,7 @@ import { openApiErrorResponses } from "@/lib/openapi/responses";
import z from "@/lib/zod";
import {
WorkspaceSchema,
- updateWorkspaceSchema,
+ createWorkspaceSchema,
} from "@/lib/zod/schemas/workspaces";
import { ZodOpenApiOperationObject } from "zod-openapi";
@@ -22,7 +22,7 @@ export const updateWorkspace: ZodOpenApiOperationObject = {
requestBody: {
content: {
"application/json": {
- schema: updateWorkspaceSchema,
+ schema: createWorkspaceSchema.partial(),
},
},
},