Edits history of script submission #10727 for ' Create a New App (digitalocean)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Digitalocean = {
      token: string;
    };
    /**
     * Create a New App
     * Create a new app by submitting an app specification. For documentation on app specifications (`AppSpec` objects), please refer to [the product documentation](https://docs.digitalocean.com/products/app-platform/reference/app-spec/).
     */
    export async function main(
      auth: Digitalocean,
      Accept: string,
      body: {
        spec: {
          name: string;
          region?:
            | "ams"
            | "nyc"
            | "fra"
            | "sfo"
            | "sgp"
            | "blr"
            | "tor"
            | "lon"
            | "syd";
          domains?: {
            domain: string;
            type?: "UNSPECIFIED" | "DEFAULT" | "PRIMARY" | "ALIAS";
            wildcard?: false | true;
            zone?: string;
            minimum_tls_version?: "1.2" | "1.3";
          }[];
          services?: {
            name?: string;
            git?: { branch?: string; repo_clone_url?: string };
            github?: {
              branch?: string;
              deploy_on_push?: false | true;
              repo?: string;
            };
            gitlab?: {
              branch?: string;
              deploy_on_push?: false | true;
              repo?: string;
            };
            image?: {
              registry?: string;
              registry_type?: "DOCKER_HUB" | "DOCR" | "GHCR";
              registry_credentials?: string;
              repository?: string;
              tag?: string;
              digest?: string;
              deploy_on_push?: { enabled?: false | true };
            };
            dockerfile_path?: string;
            build_command?: string;
            run_command?: string;
            source_dir?: string;
            envs?: {
              key: string;
              scope?: "UNSET" | "RUN_TIME" | "BUILD_TIME" | "RUN_AND_BUILD_TIME";
              type?: "GENERAL" | "SECRET";
              value?: string;
            }[];
            environment_slug?: string;
            log_destinations?: {
              name: string;
              papertrail?: { endpoint: string };
              datadog?: { endpoint?: string; api_key: string };
              logtail?: { token?: string };
              open_search?: {
                endpoint?: string;
                basic_auth?: { user?: string; password?: {} };
                index_name?: string;
                cluster_name?: string;
              };
            }[];
          } & {
            instance_count?: number;
            instance_size_slug?:
              | "apps-s-1vcpu-0.5gb"
              | "apps-s-1vcpu-1gb-fixed"
              | "apps-s-1vcpu-1gb"
              | "apps-s-1vcpu-2gb"
              | "apps-s-2vcpu-4gb"
              | "apps-d-1vcpu-0.5gb"
              | "apps-d-1vcpu-1gb"
              | "apps-d-1vcpu-2gb"
              | "apps-d-1vcpu-4gb"
              | "apps-d-2vcpu-4gb"
              | "apps-d-2vcpu-8gb"
              | "apps-d-4vcpu-8gb"
              | "apps-d-4vcpu-16gb"
              | "apps-d-8vcpu-32gb"
              | "basic-xxs"
              | "basic-xs"
              | "basic-s"
              | "basic-m"
              | "professional-xs"
              | "professional-s"
              | "professional-m"
              | "professional-1l"
              | "professional-l"
              | "professional-xl";
            autoscaling?: {
              min_instance_count?: number;
              max_instance_count?: number;
              metrics?: { cpu?: { percent?: number } };
            };
          } & {
              cors?: {
                allow_origins?: {
                  exact?: string;
                  prefix?: string;
                  regex?: string;
                }[];
                allow_methods?: string[];
                allow_headers?: string[];
                expose_headers?: string[];
                max_age?: string;
                allow_credentials?: false | true;
              } & {} & {};
              health_check?: {
                failure_threshold?: number;
                port?: number;
                http_path?: string;
                initial_delay_seconds?: number;
                period_seconds?: number;
                success_threshold?: number;
                timeout_seconds?: number;
              };
              protocol?: "HTTP" | "HTTP2";
              http_port?: number;
              internal_ports?: number[];
              routes?: { path?: string; preserve_path_prefix?: false | true }[];
              termination?: {
                drain_seconds?: number;
                grace_period_seconds?: number;
              };
            }[];
          static_sites?: {
            name?: string;
            git?: { branch?: string; repo_clone_url?: string };
            github?: {
              branch?: string;
              deploy_on_push?: false | true;
              repo?: string;
            };
            gitlab?: {
              branch?: string;
              deploy_on_push?: false | true;
              repo?: string;
            };
            image?: {
              registry?: string;
              registry_type?: "DOCKER_HUB" | "DOCR" | "GHCR";
              registry_credentials?: string;
              repository?: string;
              tag?: string;
              digest?: string;
              deploy_on_push?: { enabled?: false | true };
            };
            dockerfile_path?: string;
            build_command?: string;
            run_command?: string;
            source_dir?: string;
            envs?: {
              key: string;
              scope?: "UNSET" | "RUN_TIME" | "BUILD_TIME" | "RUN_AND_BUILD_TIME";
              type?: "GENERAL" | "SECRET";
              value?: string;
            }[];
            environment_slug?: string;
            log_destinations?: {
              name: string;
              papertrail?: { endpoint: string };
              datadog?: { endpoint?: string; api_key: string };
              logtail?: { token?: string };
              open_search?: {
                endpoint?: string;
                basic_auth?: { user?: string; password?: {} };
                index_name?: string;
                cluster_name?: string;
              };
            }[];
          } & {
            index_document?: string;
            error_document?: string;
            catchall_document?: string;
            output_dir?: string;
            cors?: {
              allow_origins?: { exact?: string; prefix?: string; regex?: string }[];
              allow_methods?: string[];
              allow_headers?: string[];
              expose_headers?: string[];
              max_age?: string;
              allow_credentials?: false | true;
            } & {} & {};
            routes?: { path?: string; preserve_path_prefix?: false | true }[];
          }[];
          jobs?: {
            name?: string;
            git?: { branch?: string; repo_clone_url?: string };
            github?: {
              branch?: string;
              deploy_on_push?: false | true;
              repo?: string;
            };
            gitlab?: {
              branch?: string;
              deploy_on_push?: false | true;
              repo?: string;
            };
            image?: {
              registry?: string;
              registry_type?: "DOCKER_HUB" | "DOCR" | "GHCR";
              registry_credentials?: string;
              repository?: string;
              tag?: string;
              digest?: string;
              deploy_on_push?: { enabled?: false | true };
            };
            dockerfile_path?: string;
            build_command?: string;
            run_command?: string;
            source_dir?: string;
            envs?: {
              key: string;
              scope?: "UNSET" | "RUN_TIME" | "BUILD_TIME" | "RUN_AND_BUILD_TIME";
              type?: "GENERAL" | "SECRET";
              value?: string;
            }[];
            environment_slug?: string;
            log_destinations?: {
              name: string;
              papertrail?: { endpoint: string };
              datadog?: { endpoint?: string; api_key: string };
              logtail?: { token?: string };
              open_search?: {
                endpoint?: string;
                basic_auth?: { user?: string; password?: {} };
                index_name?: string;
                cluster_name?: string;
              };
            }[];
          } & {
            instance_count?: number;
            instance_size_slug?:
              | "apps-s-1vcpu-0.5gb"
              | "apps-s-1vcpu-1gb-fixed"
              | "apps-s-1vcpu-1gb"
              | "apps-s-1vcpu-2gb"
              | "apps-s-2vcpu-4gb"
              | "apps-d-1vcpu-0.5gb"
              | "apps-d-1vcpu-1gb"
              | "apps-d-1vcpu-2gb"
              | "apps-d-1vcpu-4gb"
              | "apps-d-2vcpu-4gb"
              | "apps-d-2vcpu-8gb"
              | "apps-d-4vcpu-8gb"
              | "apps-d-4vcpu-16gb"
              | "apps-d-8vcpu-32gb"
              | "basic-xxs"
              | "basic-xs"
              | "basic-s"
              | "basic-m"
              | "professional-xs"
              | "professional-s"
              | "professional-m"
              | "professional-1l"
              | "professional-l"
              | "professional-xl";
            autoscaling?: {
              min_instance_count?: number;
              max_instance_count?: number;
              metrics?: { cpu?: { percent?: number } };
            };
          } & {
              kind?: "UNSPECIFIED" | "PRE_DEPLOY" | "POST_DEPLOY" | "FAILED_DEPLOY";
              termination?: { grace_period_seconds?: number };
            }[];
          workers?: {
            name?: string;
            git?: { branch?: string; repo_clone_url?: string };
            github?: {
              branch?: string;
              deploy_on_push?: false | true;
              repo?: string;
            };
            gitlab?: {
              branch?: string;
              deploy_on_push?: false | true;
              repo?: string;
            };
            image?: {
              registry?: string;
              registry_type?: "DOCKER_HUB" | "DOCR" | "GHCR";
              registry_credentials?: string;
              repository?: string;
              tag?: string;
              digest?: string;
              deploy_on_push?: { enabled?: false | true };
            };
            dockerfile_path?: string;
            build_command?: string;
            run_command?: string;
            source_dir?: string;
            envs?: {
              key: string;
              scope?: "UNSET" | "RUN_TIME" | "BUILD_TIME" | "RUN_AND_BUILD_TIME";
              type?: "GENERAL" | "SECRET";
              value?: string;
            }[];
            environment_slug?: string;
            log_destinations?: {
              name: string;
              papertrail?: { endpoint: string };
              datadog?: { endpoint?: string; api_key: string };
              logtail?: { token?: string };
              open_search?: {
                endpoint?: string;
                basic_auth?: { user?: string; password?: {} };
                index_name?: string;
                cluster_name?: string;
              };
            }[];
          } & {
            instance_count?: number;
            instance_size_slug?:
              | "apps-s-1vcpu-0.5gb"
              | "apps-s-1vcpu-1gb-fixed"
              | "apps-s-1vcpu-1gb"
              | "apps-s-1vcpu-2gb"
              | "apps-s-2vcpu-4gb"
              | "apps-d-1vcpu-0.5gb"
              | "apps-d-1vcpu-1gb"
              | "apps-d-1vcpu-2gb"
              | "apps-d-1vcpu-4gb"
              | "apps-d-2vcpu-4gb"
              | "apps-d-2vcpu-8gb"
              | "apps-d-4vcpu-8gb"
              | "apps-d-4vcpu-16gb"
              | "apps-d-8vcpu-32gb"
              | "basic-xxs"
              | "basic-xs"
              | "basic-s"
              | "basic-m"
              | "professional-xs"
              | "professional-s"
              | "professional-m"
              | "professional-1l"
              | "professional-l"
              | "professional-xl";
            autoscaling?: {
              min_instance_count?: number;
              max_instance_count?: number;
              metrics?: { cpu?: { percent?: number } };
            };
          } & { termination?: { grace_period_seconds?: number } }[];
          functions?: {
            cors?: {
              allow_origins?: { exact?: string; prefix?: string; regex?: string }[];
              allow_methods?: string[];
              allow_headers?: string[];
              expose_headers?: string[];
              max_age?: string;
              allow_credentials?: false | true;
            } & {} & {};
            routes?: { path?: string; preserve_path_prefix?: false | true }[];
            name: string;
            source_dir?: string;
            alerts?: {
              rule?:
                | "UNSPECIFIED_RULE"
                | "CPU_UTILIZATION"
                | "MEM_UTILIZATION"
                | "RESTART_COUNT"
                | "DEPLOYMENT_FAILED"
                | "DEPLOYMENT_LIVE"
                | "DOMAIN_FAILED"
                | "DOMAIN_LIVE"
                | "FUNCTIONS_ACTIVATION_COUNT"
                | "FUNCTIONS_AVERAGE_DURATION_MS"
                | "FUNCTIONS_ERROR_RATE_PER_MINUTE"
                | "FUNCTIONS_AVERAGE_WAIT_TIME_MS"
                | "FUNCTIONS_ERROR_COUNT"
                | "FUNCTIONS_GB_RATE_PER_SECOND";
              disabled?: false | true;
              operator?: "UNSPECIFIED_OPERATOR" | "GREATER_THAN" | "LESS_THAN";
              value?: number;
              window?:
                | "UNSPECIFIED_WINDOW"
                | "FIVE_MINUTES"
                | "TEN_MINUTES"
                | "THIRTY_MINUTES"
                | "ONE_HOUR";
            }[];
            envs?: {
              key: string;
              scope?: "UNSET" | "RUN_TIME" | "BUILD_TIME" | "RUN_AND_BUILD_TIME";
              type?: "GENERAL" | "SECRET";
              value?: string;
            }[];
            git?: { branch?: string; repo_clone_url?: string };
            github?: {
              branch?: string;
              deploy_on_push?: false | true;
              repo?: string;
            };
            gitlab?: {
              branch?: string;
              deploy_on_push?: false | true;
              repo?: string;
            };
            log_destinations?: {
              name: string;
              papertrail?: { endpoint: string };
              datadog?: { endpoint?: string; api_key: string };
              logtail?: { token?: string };
              open_search?: {
                endpoint?: string;
                basic_auth?: { user?: string; password?: {} };
                index_name?: string;
                cluster_name?: string;
              };
            }[];
          }[];
          databases?: {
            cluster_name?: string;
            db_name?: string;
            db_user?: string;
            engine?:
              | "UNSET"
              | "MYSQL"
              | "PG"
              | "REDIS"
              | "MONGODB"
              | "KAFKA"
              | "OPENSEARCH";
            name: string;
            production?: false | true;
            version?: string;
          }[];
          ingress?: {
            rules?: {
              match?: { path: { prefix: string } };
              cors?: {
                allow_origins?: {
                  exact?: string;
                  prefix?: string;
                  regex?: string;
                }[];
                allow_methods?: string[];
                allow_headers?: string[];
                expose_headers?: string[];
                max_age?: string;
                allow_credentials?: false | true;
              };
              component?: {
                name: string;
                preserve_path_prefix?: string;
                rewrite?: string;
              };
              redirect?: {
                uri?: string;
                authority?: string;
                port?: number;
                scheme?: string;
                redirect_code?: number;
              };
            }[];
          };
          egress?: { type?: "AUTOASSIGN" | "DEDICATED_IP" };
          maintenance?: { enabled?: false | true; archive?: false | true };
        };
        project_id?: string;
      },
    ) {
      const url = new URL(`https://api.digitalocean.com/v2/apps`);
    
      const response = await fetch(url, {
        method: "POST",
        headers: {
          Accept: Accept,
          "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 536 days ago