Edits history of script submission #13861 for ' Update a check (vercel)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Vercel = {
      token: string;
    };
    /**
     * Update a check
     * Update an existing check. This endpoint must be called with an OAuth2 or it will produce a 400 error.
     */
    export async function main(
      auth: Vercel,
      deploymentId: string,
      checkId: string,
      teamId: string | undefined,
      slug: string | undefined,
      body: {
        name?: string;
        path?: string;
        status?: "running" | "completed";
        conclusion?: "canceled" | "failed" | "neutral" | "succeeded" | "skipped";
        detailsUrl?: string;
        output?: {
          metrics?: {
            FCP: { value: number; previousValue?: number; source: "web-vitals" };
            LCP: { value: number; previousValue?: number; source: "web-vitals" };
            CLS: { value: number; previousValue?: number; source: "web-vitals" };
            TBT: { value: number; previousValue?: number; source: "web-vitals" };
            virtualExperienceScore?: {
              value: number;
              previousValue?: number;
              source: "web-vitals";
            };
          };
        };
        externalId?: string;
      },
    ) {
      const url = new URL(
        `https://api.vercel.com/v1/deployments/${deploymentId}/checks/${checkId}`,
      );
      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