Edits history of script submission #13785 for ' Get deployment events (vercel)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Vercel = {
      token: string;
    };
    /**
     * Get deployment events
     * Get the build logs of a deployment by deployment ID and build ID. It can work as an infinite stream of logs or as a JSON endpoint depending on the input parameters.
     */
    export async function main(
      auth: Vercel,
      idOrUrl: string,
      direction: "backward" | "forward" | undefined,
      follow: "0" | "1" | undefined,
      limit: string | undefined,
      name: string | undefined,
      since: string | undefined,
      until: string | undefined,
      statusCode: string | undefined,
      delimiter: "0" | "1" | undefined,
      builds: "0" | "1" | undefined,
      teamId: string | undefined,
      slug: string | undefined,
    ) {
      const url = new URL(
        `https://api.vercel.com/v3/deployments/${idOrUrl}/events`,
      );
      for (const [k, v] of [
        ["direction", direction],
        ["follow", follow],
        ["limit", limit],
        ["name", name],
        ["since", since],
        ["until", until],
        ["statusCode", statusCode],
        ["delimiter", delimiter],
        ["builds", builds],
        ["teamId", teamId],
        ["slug", slug],
      ]) {
        if (v !== undefined && v !== "" && k !== undefined) {
          url.searchParams.append(k, v);
        }
      }
      const response = await fetch(url, {
        method: "GET",
        headers: {
          Authorization: "Bearer " + auth.token,
        },
        body: undefined,
      });
      if (!response.ok) {
        const text = await response.text();
        throw new Error(`${response.status} ${text}`);
      }
      return await response.text();
    }
    

    Submitted by hugo697 428 days ago