Edits history of script submission #17535 for ' Update site (netlify)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Netlify = {
      token: string;
    };
    /**
     * Update site
     * **Note:** Environment variable keys and values have moved from `build_settings.env` and `repo.env` to a new endpoint. Please use [updateEnvVar](#tag/environmentVariables/operation/updateEnvVar) to update a site's environment variables.
     */
    export async function main(
      auth: Netlify,
      site_id: string,
      body: {
        id?: string;
        state?: string;
        plan?: string;
        name?: string;
        custom_domain?: string;
        domain_aliases?: string[];
        branch_deploy_custom_domain?: string;
        deploy_preview_custom_domain?: string;
        password?: string;
        notification_email?: string;
        url?: string;
        ssl_url?: string;
        admin_url?: string;
        screenshot_url?: string;
        created_at?: string;
        updated_at?: string;
        user_id?: string;
        session_id?: string;
        ssl?: false | true;
        force_ssl?: false | true;
        managed_dns?: false | true;
        deploy_url?: string;
        published_deploy?: {
          id?: string;
          site_id?: string;
          user_id?: string;
          build_id?: string;
          state?: string;
          name?: string;
          url?: string;
          ssl_url?: string;
          admin_url?: string;
          deploy_url?: string;
          deploy_ssl_url?: string;
          screenshot_url?: string;
          review_id?: number;
          draft?: false | true;
          required?: string[];
          required_functions?: string[];
          error_message?: string;
          branch?: string;
          commit_ref?: string;
          commit_url?: string;
          skipped?: false | true;
          created_at?: string;
          updated_at?: string;
          published_at?: string;
          title?: string;
          context?: string;
          locked?: false | true;
          review_url?: string;
          framework?: string;
          function_schedules?: { name?: string; cron?: string }[];
        };
        account_id?: string;
        account_name?: string;
        account_slug?: string;
        git_provider?: string;
        deploy_hook?: string;
        capabilities?: {};
        processing_settings?: { html?: { pretty_urls?: false | true } };
        build_settings?: {
          id?: number;
          provider?: string;
          deploy_key_id?: string;
          repo_path?: string;
          repo_branch?: string;
          dir?: string;
          functions_dir?: string;
          cmd?: string;
          allowed_branches?: string[];
          public_repo?: false | true;
          private_logs?: false | true;
          repo_url?: string;
          env?: {};
          installation_id?: number;
          stop_builds?: false | true;
        };
        id_domain?: string;
        default_hooks_data?: { access_token?: string };
        build_image?: string;
        prerender?: string;
        functions_region?: string;
      } & {
        repo?: {
          id?: number;
          provider?: string;
          deploy_key_id?: string;
          repo_path?: string;
          repo_branch?: string;
          dir?: string;
          functions_dir?: string;
          cmd?: string;
          allowed_branches?: string[];
          public_repo?: false | true;
          private_logs?: false | true;
          repo_url?: string;
          env?: {};
          installation_id?: number;
          stop_builds?: false | true;
        };
      },
    ) {
      const url = new URL(`https://api.netlify.com/api/v1/sites/${site_id}`);
    
      const response = await fetch(url, {
        method: "PATCH",
        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 235 days ago