import {z} from 'zod' export type GetApiProjectsProjectIdEnvironmentsEnvironmentIdDeploymentsArgs = {projectId: string, environmentId: string}; export type GetApiProjectsProjectIdEnvironmentsEnvironmentIdDeploymentsOptions = {baseUrl?: string | undefined, OAuth2?: string | undefined, fetch?: typeof fetch | undefined}; export const proxyRoute = z.object({id: z.string(), primary: z.boolean().nullable(), production_url: z.string().nullable(), attributes: z.record(z.string(), z.string()), type: z.enum(["proxy", "redirect", "upstream"]), tls: z.object({strict_transport_security: z.object({enabled: z.boolean().nullable(), include_subdomains: z.boolean().nullable(), preload: z.boolean().nullable()}), min_version: z.enum(["TLSv1.0", "TLSv1.1", "TLSv1.2", "TLSv1.3"]).nullable(), client_authentication: z.enum(["request", "require"]).nullable(), client_certificate_authorities: z.array(z.string())}), to: z.string()}); export const redirectRoute = z.object({id: z.string(), primary: z.boolean().nullable(), production_url: z.string().nullable(), attributes: z.record(z.string(), z.string()), type: z.enum(["proxy", "redirect", "upstream"]), tls: z.object({strict_transport_security: z.object({enabled: z.boolean().nullable(), include_subdomains: z.boolean().nullable(), preload: z.boolean().nullable()}), min_version: z.enum(["TLSv1.0", "TLSv1.1", "TLSv1.2", "TLSv1.3"]).nullable(), client_authentication: z.enum(["request", "require"]).nullable(), client_certificate_authorities: z.array(z.string())}), to: z.string(), redirects: z.object({expires: z.string(), paths: z.record(z.string(), z.object({regexp: z.boolean(), to: z.string(), prefix: z.boolean().nullable(), append_suffix: z.boolean().nullable(), code: z.union([z.literal(301), z.literal(302), z.literal(307), z.literal(308)]), expires: z.string().nullable()}))})}); export const upstreamRoute = z.object({id: z.string(), primary: z.boolean().nullable(), production_url: z.string().nullable(), attributes: z.record(z.string(), z.string()), type: z.enum(["proxy", "redirect", "upstream"]), tls: z.object({strict_transport_security: z.object({enabled: z.boolean().nullable(), include_subdomains: z.boolean().nullable(), preload: z.boolean().nullable()}), min_version: z.enum(["TLSv1.0", "TLSv1.1", "TLSv1.2", "TLSv1.3"]).nullable(), client_authentication: z.enum(["request", "require"]).nullable(), client_certificate_authorities: z.array(z.string())}), cache: z.object({enabled: z.boolean(), default_ttl: z.number().int(), cookies: z.array(z.string()), headers: z.array(z.string())}), ssi: z.object({enabled: z.boolean()}), upstream: z.string(), redirects: z.object({expires: z.string(), paths: z.record(z.string(), z.object({regexp: z.boolean(), to: z.string(), prefix: z.boolean().nullable(), append_suffix: z.boolean().nullable(), code: z.union([z.literal(301), z.literal(302), z.literal(307), z.literal(308)]), expires: z.string().nullable()}))}), sticky: z.object({enabled: z.boolean()})}); export const deployment = z.object({id: z.string(), created_at: z.string().nullable().optional(), updated_at: z.string().nullable().optional(), fingerprint: z.string().optional(), cluster_name: z.string(), project_info: z.object({title: z.string(), name: z.string(), namespace: z.string().nullable(), organization: z.string().nullable(), capabilities: z.object({}), settings: z.object({})}), environment_info: z.object({name: z.string(), status: z.string(), is_main: z.boolean(), is_production: z.boolean(), constraints: z.object({}), reference: z.string(), machine_name: z.string(), environment_type: z.string(), links: z.object({})}), deployment_target: z.string(), vpn: z.object({version: z.union([z.literal(1), z.literal(2)]), aggressive: z.enum(["no", "yes"]), modeconfig: z.enum(["pull", "push"]), authentication: z.string(), gateway_ip: z.string(), identity: z.string().nullable(), second_identity: z.string().nullable(), remote_identity: z.string().nullable(), remote_subnets: z.array(z.string()), ike: z.string(), esp: z.string(), ikelifetime: z.string(), lifetime: z.string(), margintime: z.string()}).nullable(), http_access: z.object({is_enabled: z.boolean(), addresses: z.array(z.object({permission: z.enum(["allow", "deny"]), address: z.string()})), basic_auth: z.record(z.string(), z.string())}), enable_smtp: z.boolean(), restrict_robots: z.boolean(), variables: z.array(z.object({name: z.string(), value: z.string().optional(), is_sensitive: z.boolean(), is_json: z.boolean(), visible_build: z.boolean(), visible_runtime: z.boolean()})), access: z.array(z.object({entity_id: z.string(), role: z.enum(["admin", "contributor", "viewer"])})), subscription: z.object({license_uri: z.string(), plan: z.enum(["2xlarge", "2xlarge-high-memory", "4xlarge", "8xlarge", "development", "large", "large-high-memory", "medium", "medium-high-memory", "standard", "standard-high-memory", "xlarge", "xlarge-high-memory"]).optional(), environments: z.number().int().optional(), storage: z.number().int(), included_users: z.number().int(), subscription_management_uri: z.string(), restricted: z.boolean(), suspended: z.boolean(), user_licenses: z.number().int(), resources: z.object({container_profiles: z.boolean(), production: z.object({legacy_development: z.boolean(), max_cpu: z.number().nullable(), max_memory: z.number().int().nullable(), max_environments: z.number().int().nullable()}), development: z.object({legacy_development: z.boolean(), max_cpu: z.number().nullable(), max_memory: z.number().int().nullable(), max_environments: z.number().int().nullable()})}).optional(), resource_validation_url: z.string().optional(), image_types: z.object({only: z.array(z.string()).optional(), exclude: z.array(z.string()).optional()}).optional()}), services: z.record(z.string(), z.object({type: z.string(), size: z.enum(["2XL", "4XL", "AUTO", "L", "M", "S", "XL"]), disk: z.number().int().nullable(), access: z.object({}), configuration: z.object({}), relationships: z.record(z.string(), z.string()), firewall: z.object({outbound: z.array(z.object({protocol: z.literal("tcp"), ips: z.array(z.string()), domains: z.array(z.string()), ports: z.array(z.number().int())}))}).nullable(), resources: z.object({base_memory: z.number().int().nullable(), memory_ratio: z.number().int().nullable(), profile_size: z.string().nullable(), minimum: z.object({cpu: z.number(), memory: z.number().int(), cpu_type: z.enum(["guaranteed", "shared"]), disk: z.number().int().nullable(), profile_size: z.string().nullable()}).nullable(), default: z.object({cpu: z.number(), memory: z.number().int(), cpu_type: z.enum(["guaranteed", "shared"]), disk: z.number().int().nullable(), profile_size: z.string().nullable()}).nullable(), disk: z.object({temporary: z.number().int().nullable(), instance: z.number().int().nullable(), storage: z.number().int().nullable()}).nullable()}).nullable(), container_profile: z.string().nullable(), endpoints: z.object({}).nullable(), instance_count: z.number().int().nullable()})), routes: z.record(z.string(), z.union([proxyRoute, redirectRoute, upstreamRoute])), webapps: z.record(z.string(), z.object({resources: z.object({base_memory: z.number().int().nullable(), memory_ratio: z.number().int().nullable(), profile_size: z.string().nullable(), minimum: z.object({cpu: z.number(), memory: z.number().int(), cpu_type: z.enum(["guaranteed", "shared"]), disk: z.number().int().nullable(), profile_size: z.string().nullable()}).nullable(), default: z.object({cpu: z.number(), memory: z.number().int(), cpu_type: z.enum(["guaranteed", "shared"]), disk: z.number().int().nullable(), profile_size: z.string().nullable()}).nullable(), disk: z.object({temporary: z.number().int().nullable(), instance: z.number().int().nullable(), storage: z.number().int().nullable()}).nullable()}).nullable(), size: z.enum(["2XL", "4XL", "AUTO", "L", "M", "S", "XL", "XS"]), disk: z.number().int().nullable(), access: z.record(z.string(), z.enum(["admin", "contributor", "viewer"])), relationships: z.record(z.string(), z.object({service: z.string().nullable(), endpoint: z.string().nullable()}).nullable()), additional_hosts: z.record(z.string(), z.string()), mounts: z.record(z.string(), z.object({source: z.enum(["instance", "local", "service", "storage", "temporary", "tmp"]), source_path: z.string(), service: z.string().nullable().optional()})), timezone: z.string().nullable(), variables: z.record(z.string(), z.record(z.string(), z.unknown())), firewall: z.object({outbound: z.array(z.object({protocol: z.literal("tcp"), ips: z.array(z.string()), domains: z.array(z.string()), ports: z.array(z.number().int())}))}).nullable(), container_profile: z.string().nullable(), operations: z.record(z.string(), z.object({commands: z.object({start: z.string(), stop: z.string().nullable().optional()}), timeout: z.number().int().nullable(), role: z.enum(["admin", "contributor", "viewer"])})), name: z.string(), type: z.string(), preflight: z.object({enabled: z.boolean(), ignored_rules: z.array(z.string())}), tree_id: z.string(), app_dir: z.string(), endpoints: z.object({}).nullable(), runtime: z.object({}), web: z.object({locations: z.record(z.string(), z.object({root: z.string().nullable(), expires: z.string(), passthru: z.string(), scripts: z.boolean(), index: z.array(z.string()).nullable().optional(), allow: z.boolean(), headers: z.record(z.string(), z.string()), rules: z.record(z.string(), z.object({expires: z.string().nullable().optional(), passthru: z.string().optional(), scripts: z.boolean().optional(), allow: z.boolean().optional(), headers: z.record(z.string(), z.string()).optional()})), request_buffering: z.object({enabled: z.boolean(), max_request_size: z.string().nullable()}).optional()})), commands: z.object({pre_start: z.string().nullable().optional(), start: z.string().nullable().optional(), post_start: z.string().nullable().optional()}).optional(), upstream: z.object({socket_family: z.enum(["tcp", "unix"]), protocol: z.enum(["fastcgi", "http"]).nullable()}).optional(), document_root: z.string().nullable().optional(), passthru: z.string().nullable().optional(), index_files: z.array(z.string()).nullable().optional(), whitelist: z.array(z.string()).nullable().optional(), blacklist: z.array(z.string()).nullable().optional(), expires: z.string().nullable().optional(), move_to_root: z.boolean()}), hooks: z.object({build: z.string().nullable(), deploy: z.string().nullable(), post_deploy: z.string().nullable()}), crons: z.record(z.string(), z.object({spec: z.string(), commands: z.object({start: z.string(), stop: z.string().nullable().optional()}), shutdown_timeout: z.number().int().nullable().optional(), timeout: z.number().int(), cmd: z.string().optional()})), source: z.object({root: z.string().nullable(), operations: z.record(z.string(), z.object({command: z.string().nullable()}))}), build: z.object({flavor: z.string().nullable(), caches: z.record(z.string(), z.object({directory: z.string().nullable(), watch: z.array(z.string()), allow_stale: z.boolean(), share_between_apps: z.boolean()}))}), dependencies: z.record(z.string(), z.object({})), stack: z.array(z.object({})).nullable(), is_across_submodule: z.boolean(), instance_count: z.number().int().nullable(), config_id: z.string(), slug_id: z.string()})), workers: z.record(z.string(), z.object({resources: z.object({base_memory: z.number().int().nullable(), memory_ratio: z.number().int().nullable(), profile_size: z.string().nullable(), minimum: z.object({cpu: z.number(), memory: z.number().int(), cpu_type: z.enum(["guaranteed", "shared"]), disk: z.number().int().nullable(), profile_size: z.string().nullable()}).nullable(), default: z.object({cpu: z.number(), memory: z.number().int(), cpu_type: z.enum(["guaranteed", "shared"]), disk: z.number().int().nullable(), profile_size: z.string().nullable()}).nullable(), disk: z.object({temporary: z.number().int().nullable(), instance: z.number().int().nullable(), storage: z.number().int().nullable()}).nullable()}).nullable(), size: z.enum(["2XL", "4XL", "AUTO", "L", "M", "S", "XL", "XS"]), disk: z.number().int().nullable(), access: z.record(z.string(), z.enum(["admin", "contributor", "viewer"])), relationships: z.record(z.string(), z.object({service: z.string().nullable(), endpoint: z.string().nullable()}).nullable()), additional_hosts: z.record(z.string(), z.string()), mounts: z.record(z.string(), z.object({source: z.enum(["instance", "local", "service", "storage", "temporary", "tmp"]), source_path: z.string(), service: z.string().nullable().optional()})), timezone: z.string().nullable(), variables: z.record(z.string(), z.record(z.string(), z.unknown())), firewall: z.object({outbound: z.array(z.object({protocol: z.literal("tcp"), ips: z.array(z.string()), domains: z.array(z.string()), ports: z.array(z.number().int())}))}).nullable(), container_profile: z.string().nullable(), operations: z.record(z.string(), z.object({commands: z.object({start: z.string(), stop: z.string().nullable().optional()}), timeout: z.number().int().nullable(), role: z.enum(["admin", "contributor", "viewer"])})), name: z.string(), type: z.string(), preflight: z.object({enabled: z.boolean(), ignored_rules: z.array(z.string())}), tree_id: z.string(), app_dir: z.string(), endpoints: z.object({}).nullable(), runtime: z.object({}), worker: z.object({commands: z.object({pre_start: z.string().nullable().optional(), start: z.string(), post_start: z.string().nullable().optional()}), disk: z.number().int().nullable().optional()}), app: z.string(), stack: z.array(z.object({})).nullable(), instance_count: z.number().int().nullable(), slug_id: z.string()})), container_profiles: z.record(z.string(), z.record(z.string(), z.object({cpu: z.number(), memory: z.number().int(), cpu_type: z.enum(["guaranteed", "shared"])})))}); export const deploymentCollection = z.array(deployment); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * Get an environment's deployment information * * GET /projects/{projectId}/environments/{environmentId}/deployments */ export const getApiProjectsProjectIdEnvironmentsEnvironmentIdDeployments = async (args: GetApiProjectsProjectIdEnvironmentsEnvironmentIdDeploymentsArgs, options?: GetApiProjectsProjectIdEnvironmentsEnvironmentIdDeploymentsOptions) => { const {baseUrl = "https://api.upsun.com", fetch: fetchFn = fetch, OAuth2} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (OAuth2 !== undefined) headers.set('authorization', `Bearer ${OAuth2}`) const url = `${baseUrl.replace(/\/+$/, '')}/projects/${encodeURIComponent(String(args.projectId))}/environments/${encodeURIComponent(String(args.environmentId))}/deployments${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(deploymentCollection, await res.json()) };