Edits history of script submission #13846 for ' Retrieves a list of Integration log drains (vercel)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Vercel = {
      token: string;
    };
    /**
     * Retrieves a list of Integration log drains
     * Retrieves a list of all Integration log drains that are defined for the authenticated user or team. When using an OAuth2 token, the list is limited to log drains created by the authenticated integration.
     */
    export async function main(
      auth: Vercel,
      teamId: string | undefined,
      slug: string | undefined,
    ) {
      const url = new URL(`https://api.vercel.com/v2/integrations/log-drains`);
      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: "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