Edits history of script submission #18604 for ' Create service (render)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Render = {
    	apiKey: string
    }
    /**
     * Create service
     * Create a service.
    
     */
    export async function main(
    	auth: Render,
    	body: {
    		type: 'static_site' | 'web_service' | 'private_service' | 'background_worker' | 'cron_job'
    		name: string
    		ownerId: string
    		repo?: string
    		autoDeploy?: 'yes' | 'no'
    		branch?: string
    		image?: {
    			ownerId: string
    			registryCredentialId?: string
    			imagePath: string
    		}
    		buildFilter?: { paths: string[]; ignoredPaths: string[] }
    		rootDir?: string
    		envVars?: { key: string; value: string } | { key: string; generateValue: false | true }[]
    		secretFiles?: { name: string; content: string }[]
    		environmentId?: string
    		serviceDetails?:
    			| {
    					buildCommand?: string
    					headers?: { path: string; name: string; value: string }[]
    					publishPath?: string
    					pullRequestPreviewsEnabled?: 'yes' | 'no'
    					previews?: { generation?: 'off' | 'manual' | 'automatic' }
    					routes?: {
    						type: 'redirect' | 'rewrite'
    						source: string
    						destination: string
    						priority?: number
    					}[]
    					renderSubdomainPolicy?: 'enabled' | 'disabled'
    			  }
    			| {
    					autoscaling?: {
    						enabled: false | true
    						min: number
    						max: number
    						criteria: {
    							cpu: { enabled: false | true; percentage: number }
    							memory: { enabled: false | true; percentage: number }
    						}
    					}
    					disk?: { name: string; mountPath: string; sizeGB?: number }
    					env?: 'docker' | 'elixir' | 'go' | 'node' | 'python' | 'ruby' | 'rust' | 'image'
    					runtime: 'docker' | 'elixir' | 'go' | 'node' | 'python' | 'ruby' | 'rust' | 'image'
    					envSpecificDetails?:
    						| {
    								dockerCommand?: string
    								dockerContext?: string
    								dockerfilePath?: string
    								registryCredentialId?: string
    						  }
    						| { buildCommand: string; startCommand: string }
    					healthCheckPath?: string
    					maintenanceMode?: { enabled: false | true; uri: string }
    					numInstances?: number
    					plan?: 'starter' | 'standard' | 'pro' | 'pro_plus' | 'pro_max' | 'pro_ultra'
    					preDeployCommand?: string
    					pullRequestPreviewsEnabled?: 'yes' | 'no'
    					previews?: { generation?: 'off' | 'manual' | 'automatic' }
    					region?: 'frankfurt' | 'oregon' | 'ohio' | 'singapore' | 'virginia'
    					maxShutdownDelaySeconds?: number
    					renderSubdomainPolicy?: 'enabled' | 'disabled'
    			  }
    			| {
    					autoscaling?: {
    						enabled: false | true
    						min: number
    						max: number
    						criteria: {
    							cpu: { enabled: false | true; percentage: number }
    							memory: { enabled: false | true; percentage: number }
    						}
    					}
    					disk?: { name: string; mountPath: string; sizeGB?: number }
    					env?: 'docker' | 'elixir' | 'go' | 'node' | 'python' | 'ruby' | 'rust' | 'image'
    					runtime: 'docker' | 'elixir' | 'go' | 'node' | 'python' | 'ruby' | 'rust' | 'image'
    					envSpecificDetails?:
    						| {
    								dockerCommand?: string
    								dockerContext?: string
    								dockerfilePath?: string
    								registryCredentialId?: string
    						  }
    						| { buildCommand: string; startCommand: string }
    					numInstances?: number
    					plan?: 'starter' | 'standard' | 'pro' | 'pro_plus' | 'pro_max' | 'pro_ultra'
    					preDeployCommand?: string
    					pullRequestPreviewsEnabled?: 'yes' | 'no'
    					previews?: { generation?: 'off' | 'manual' | 'automatic' }
    					region?: 'frankfurt' | 'oregon' | 'ohio' | 'singapore' | 'virginia'
    					maxShutdownDelaySeconds?: number
    			  }
    			| {
    					env?: 'docker' | 'elixir' | 'go' | 'node' | 'python' | 'ruby' | 'rust' | 'image'
    					runtime: 'docker' | 'elixir' | 'go' | 'node' | 'python' | 'ruby' | 'rust' | 'image'
    					envSpecificDetails?:
    						| {
    								dockerCommand: string
    								dockerContext: string
    								dockerfilePath: string
    								preDeployCommand?: string
    								registryCredential?: {
    									id: string
    									name: string
    									registry: 'GITHUB' | 'GITLAB' | 'DOCKER' | 'GOOGLE_ARTIFACT' | 'AWS_ECR'
    									username: string
    									updatedAt: string
    								}
    						  }
    						| {
    								buildCommand: string
    								startCommand: string
    								preDeployCommand?: string
    						  }
    					plan?: 'starter' | 'standard' | 'pro' | 'pro_plus' | 'pro_max' | 'pro_ultra'
    					region?: 'frankfurt' | 'oregon' | 'ohio' | 'singapore' | 'virginia'
    					schedule: string
    			  }
    	}
    ) {
    	const url = new URL(`https://api.render.com/v1/services`)
    
    	const response = await fetch(url, {
    		method: 'POST',
    		headers: {
    			'Content-Type': 'application/json',
    			Authorization: 'Bearer ' + auth.apiKey
    		},
    		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