import {z} from 'zod' export type NodeBalancerMethod = 'round_robin' | 'least_conn' | 'ip_hash'; export type CreateLoadBalancerSiteRequest = {domain: string, allow_wildcard_subdomains?: boolean | undefined, balancer_method?: NodeBalancerMethod | undefined, balancer_keepalive_max_connections?: number | undefined, balancing?: (Array<{server_id?: number | undefined, port?: number | undefined, weight?: number | undefined, backup?: boolean | undefined, down?: boolean | undefined}>) | undefined}; export type CreateApiOrgsOrganizationServersServerSitesBalancerArgs = {organization: string, server: number, body: CreateLoadBalancerSiteRequest}; export type CreateApiOrgsOrganizationServersServerSitesBalancerOptions = {baseUrl?: string | undefined, oauth2?: string | undefined, fetch?: typeof fetch | undefined}; export const siteStatus = z.enum(["installed", "creating", "removing", "installing", "uninstalling", "deployed", "never-deployed", "deploying", "failed", "maintenance"]); export const repositoryStatus = z.enum(["installed", "installing", "removing"]); export const maintenanceModeStatus = z.enum(["disabling", "enabling"]); export const appType = z.enum(["Statamic", "WordPress", "phpMyAdmin", "Laravel", "Symfony", "PHP", "Next.js", "Nuxt.js", "Static HTML", "Custom", "Craft", "Minecraft"]); export const serverResourceIdentifier = z.object({type: z.literal("servers"), id: z.string()}); export const tagResourceIdentifier = z.object({type: z.literal("tags"), id: z.string()}); export const deploymentResourceIdentifier = z.object({type: z.literal("deployments"), id: z.string()}); export const securityRuleResourceIdentifier = z.object({type: z.literal("securityRules"), id: z.string()}); export const redirectRuleResourceIdentifier = z.object({type: z.literal("redirect-rules"), id: z.string()}); export const link = z.object({href: z.string(), rel: z.string().optional(), describedby: z.string().optional(), title: z.string().optional(), type: z.string().optional(), hreflang: z.union([z.string(), z.array(z.string())]).optional(), meta: z.object({}).optional()}); export const siteResource = z.object({id: z.string(), type: z.literal("sites"), attributes: z.object({name: z.string(), status: siteStatus, url: z.string(), user: z.string(), https: z.boolean(), web_directory: z.string(), root_directory: z.string().nullable(), aliases: z.array(z.unknown()), php_version: z.string(), deployment_status: z.string(), quick_deploy: z.boolean().nullable(), isolated: z.boolean(), shared_paths: z.record(z.string(), z.string()), repository: z.object({provider: z.string(), url: z.string().nullable(), branch: z.string().nullable(), status: repositoryStatus.nullable()}), database: z.string().nullable(), maintenance_mode: z.object({enabled: z.boolean(), status: maintenanceModeStatus.nullable()}), zero_downtime_deployments: z.boolean(), deployment_script: z.string().nullable(), wildcards: z.boolean().nullable(), app_type: z.union([appType, z.literal("Custom")]).nullable(), uses_envoyer: z.boolean(), deployment_url: z.string(), healthcheck_url: z.string().nullable(), created_at: z.string().nullable(), updated_at: z.string().nullable()}).optional(), relationships: z.object({server: z.object({data: serverResourceIdentifier.nullable()}).optional(), tags: z.object({data: z.array(tagResourceIdentifier)}).optional(), latestDeployment: z.object({data: deploymentResourceIdentifier.nullable()}).optional(), securityRules: z.object({data: z.array(securityRuleResourceIdentifier)}).optional(), redirectRules: z.object({data: z.array(redirectRuleResourceIdentifier)}).optional()}).optional(), links: z.object({self: link})}); export const serverType = z.enum(["app", "web", "loadbalancer", "database", "cache", "worker", "meilisearch", "openclaw"]); export const serverResource = z.object({id: z.string(), type: z.literal("servers"), attributes: z.object({id: z.number().int(), credential_id: z.number().int().nullable(), name: z.string(), slug: z.string(), type: serverType, ubuntu_version: z.string().nullable(), ssh_port: z.number().int(), provider: z.string(), identifier: z.string().nullable(), size: z.string(), region: z.string(), php_version: z.string().nullable(), php_cli_version: z.string().nullable(), opcache_status: z.string().nullable(), database_type: z.string().nullable(), db_status: z.string().nullable(), redis_status: z.string().nullable(), ip_address: z.string().nullable(), private_ip_address: z.string().nullable(), revoked: z.boolean(), created_at: z.string(), updated_at: z.string(), connection_status: z.string(), timezone: z.string(), local_public_key: z.string().nullable(), is_ready: z.boolean()}).optional(), relationships: z.object({tags: z.object({data: z.array(tagResourceIdentifier)}).optional()}).optional(), links: z.object({self: link})}); export const tagResource = z.object({id: z.string(), type: z.literal("tags"), attributes: z.object({name: z.string(), created_at: z.string(), updated_at: z.string()}).optional()}); export const deploymentStatus = z.enum(["cancelled", "deploying", "failed", "failed-build", "finished", "pending", "queued"]); export const deploymentResource = z.object({id: z.string(), type: z.literal("deployments"), attributes: z.object({commit: z.object({hash: z.string().nullable(), author: z.string().nullable(), message: z.string().nullable(), branch: z.string().nullable()}), type: z.string(), status: deploymentStatus, started_at: z.string(), ended_at: z.string(), created_at: z.string(), updated_at: z.string()}).optional()}); export const securityRuleResource = z.object({id: z.string(), type: z.literal("securityRules"), attributes: z.object({name: z.string(), path: z.string().nullable(), status: z.string().nullable(), created_at: z.string(), updated_at: z.string()}).optional(), links: z.object({self: link})}); export const redirectRuleType = z.enum(["redirect", "permanent"]); export const redirectRuleResource = z.object({id: z.string(), type: z.literal("redirect-rules"), attributes: z.object({from: z.string(), to: z.string(), type: redirectRuleType, status: z.enum(["installing", "installed", "removing"]), created_at: z.string(), updated_at: z.string()}).optional(), links: z.object({self: link})}); export const createApiOrgsOrganizationServersServerSitesBalancerResponse = z.object({data: siteResource, included: z.array(z.union([serverResource, tagResource, deploymentResource, securityRuleResource, redirectRuleResource])).optional()}); 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 }; /** * Create site on a load balancer * * POST /orgs/{organization}/servers/{server}/sites/balancer */ export const createApiOrgsOrganizationServersServerSitesBalancer = async (args: CreateApiOrgsOrganizationServersServerSitesBalancerArgs, options?: CreateApiOrgsOrganizationServersServerSitesBalancerOptions) => { const {baseUrl = "https://forge.laravel.com/api", fetch: fetchFn = fetch, oauth2} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/vnd.api+json") if (oauth2 !== undefined) headers.set('authorization', `Bearer ${oauth2}`) const url = `${baseUrl.replace(/\/+$/, '')}/orgs/${encodeURIComponent(String(args.organization))}/servers/${encodeURIComponent(String(args.server))}/sites/balancer${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(createApiOrgsOrganizationServersServerSitesBalancerResponse, await res.json()) };