"use server";
import {
type InlinedFile,
type ProjectSettings,
SkipAutoDetectionConfirmation,
type UploadedFile,
} from "@vercel/sdk/models/createdeploymentop.js";
import { VERCEL_TEAM_ID, vercel } from "../lib/vercel";
export async function deployFiles(
files: Array<InlinedFile | UploadedFile>,
args: {
projectId?: string;
deploymentName?: string | undefined;
config?: ProjectSettings;
domain?: string;
}
) {
const {
projectId,
deploymentName = crypto.randomUUID(),
config,
domain,
} = args;
const deployment = await vercel.deployments.createDeployment({
requestBody: {
name: deploymentName,
files,
project: projectId,
projectSettings: config,
target: "production",
},
skipAutoDetectionConfirmation: config
? SkipAutoDetectionConfirmation.Zero
: SkipAutoDetectionConfirmation.One,
teamId: VERCEL_TEAM_ID,
});
// if you want your preview deployments to be public, you can do this by setting the ssoProtection to null
if (!projectId) {
await vercel.projects.updateProject({
requestBody: { ssoProtection: null },
idOrName: deployment.projectId,
teamId: VERCEL_TEAM_ID,
});
}
if (domain) {
await vercel.projects.addProjectDomain({
idOrName: deployment.projectId,
requestBody: {
name: domain,
},
teamId: VERCEL_TEAM_ID,
});
}
return deployment;
}
export async function getDeploymentStatus(id: string) {
const deployment = await vercel.deployments.getDeployment({
idOrUrl: id,
});
return {
readyState: deployment.readyState,
url: deployment.url,
id: deployment.id,
};
}