Edits history of script submission #13826 for ' Register or transfer-in a new Domain (vercel)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Vercel = {
      token: string;
    };
    /**
     * Register or transfer-in a new Domain
     * This endpoint is used for adding a new apex domain name with Vercel for the authenticating user. Can also be used for initiating a domain transfer request from an external Registrar to Vercel.
     */
    export async function main(
      auth: Vercel,
      teamId: string | undefined,
      slug: string | undefined,
      body:
        | ({ method?: string } & {
            name: string;
            cdnEnabled?: false | true;
            zone?: false | true;
            method?: string;
          })
        | ({ method?: string } & { name: string; method: string; token?: string })
        | ({ method?: string } & {
            name: string;
            method: string;
            authCode?: string;
            expectedPrice?: number;
          }),
    ) {
      const url = new URL(`https://api.vercel.com/v5/domains`);
      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: "POST",
        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