Edits history of script submission #11052 for ' Validate a Container Registry Name (digitalocean)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Digitalocean = {
      token: string;
    };
    /**
     * Validate a Container Registry Name
     * To validate that a container registry name is available for use, send a POST
    request to `/v2/registry/validate-name`.
    
    If the name is both formatted correctly and available, the response code will
    be 204 and contain no body. If the name is already in use, the response will
    be a 409 Conflict.
    
     */
    export async function main(auth: Digitalocean, body: { name: string }) {
      const url = new URL(`https://api.digitalocean.com/v2/registry/validate-name`);
    
      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 537 days ago