Edits history of script submission #13789 for ' Gets a list of aliases with status for the current promote (vercel)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Vercel = {
      token: string;
    };
    /**
     * Gets a list of aliases with status for the current promote
     * Get a list of aliases related to the last promote request with their mapping status
     */
    export async function main(
      auth: Vercel,
      projectId: string,
      limit: string | undefined,
      since: string | undefined,
      until: string | undefined,
      failedOnly: string | undefined,
      teamId: string | undefined,
      slug: string | undefined,
    ) {
      const url = new URL(
        `https://api.vercel.com/v1/projects/${projectId}/promote/aliases`,
      );
      for (const [k, v] of [
        ["limit", limit],
        ["since", since],
        ["until", until],
        ["failedOnly", failedOnly],
        ["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.json();
    }
    

    Submitted by hugo697 428 days ago