Edits history of script submission #13868 for ' Update an existing project (vercel)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Vercel = {
      token: string;
    };
    /**
     * Update an existing project
     * Update the fields of a project using either its `name` or `id`.
     */
    export async function main(
      auth: Vercel,
      idOrName: string,
      teamId: string | undefined,
      slug: string | undefined,
      body: {
        autoExposeSystemEnvs?: false | true;
        autoAssignCustomDomains?: false | true;
        autoAssignCustomDomainsUpdatedBy?: string;
        buildCommand?: string;
        commandForIgnoringBuildStep?: string;
        customerSupportCodeVisibility?: false | true;
        devCommand?: string;
        directoryListing?: false | true;
        framework?:
          | "blitzjs"
          | "nextjs"
          | "gatsby"
          | "remix"
          | "react-router"
          | "astro"
          | "hexo"
          | "eleventy"
          | "docusaurus-2"
          | "docusaurus"
          | "preact"
          | "solidstart-1"
          | "solidstart"
          | "dojo"
          | "ember"
          | "vue"
          | "scully"
          | "ionic-angular"
          | "angular"
          | "polymer"
          | "svelte"
          | "sveltekit"
          | "sveltekit-1"
          | "ionic-react"
          | "create-react-app"
          | "gridsome"
          | "umijs"
          | "sapper"
          | "saber"
          | "stencil"
          | "nuxtjs"
          | "redwoodjs"
          | "hugo"
          | "jekyll"
          | "brunch"
          | "middleman"
          | "zola"
          | "hydrogen"
          | "vite"
          | "vitepress"
          | "vuepress"
          | "parcel"
          | "fasthtml"
          | "sanity-v3"
          | "sanity"
          | "storybook";
        gitForkProtection?: false | true;
        gitLFS?: false | true;
        installCommand?: string;
        name?: string;
        nodeVersion?: "22.x" | "20.x" | "18.x" | "16.x" | "14.x" | "12.x" | "10.x";
        outputDirectory?: string;
        previewDeploymentsDisabled?: false | true;
        publicSource?: false | true;
        rootDirectory?: string;
        serverlessFunctionRegion?: string;
        serverlessFunctionZeroConfigFailover?: false | true;
        skewProtectionBoundaryAt?: number;
        skewProtectionMaxAge?: number;
        skipGitConnectDuringLink?: false | true;
        sourceFilesOutsideRootDirectory?: false | true;
        enablePreviewFeedback?: false | true;
        enableProductionFeedback?: false | true;
        enableAffectedProjectsDeployments?: false | true;
        oidcTokenConfig?: { enabled: false | true; issuerMode?: "team" | "global" };
        passwordProtection?: {
          deploymentType:
            | "all"
            | "preview"
            | "prod_deployment_urls_and_all_previews";
          password?: string;
        };
        ssoProtection?: {
          deploymentType:
            | "all"
            | "preview"
            | "prod_deployment_urls_and_all_previews";
        };
        trustedIps?: {
          deploymentType:
            | "all"
            | "preview"
            | "prod_deployment_urls_and_all_previews"
            | "production";
          addresses: { value: string; note?: string }[];
          protectionMode: "exclusive" | "additional";
        };
        optionsAllowlist?: { paths: { value: string }[] };
      },
    ) {
      const url = new URL(`https://api.vercel.com/v9/projects/${idOrName}`);
      for (const [k, v] of [
        ["teamId", teamId],
        ["slug", slug],
      ]) {
        if (v !== undefined && v !== "" && k !== undefined) {
          url.searchParams.append(k, v);
        }
      }
      const response = await fetch(url, {
        method: "PATCH",
        headers: {
          "Content-Type": "application/json",
          Authorization: "Bearer " + auth.token,
        },
        body: JSON.stringify(body),
      });
      if (!response.ok) {
        const text = await response.text();
        throw new Error(`${response.status} ${text}`);
      }
      return await response.json();
    }
    

    Submitted by hugo697 428 days ago