import {z} from 'zod' export type ServerType = 'app' | 'web' | 'loadbalancer' | 'database' | 'cache' | 'worker' | 'meilisearch' | 'openclaw'; export type PhpVersion = 'php5' | 'php56-old' | 'php56' | 'php70' | 'php71' | 'php72' | 'php73' | 'php74' | 'php80' | 'php81' | 'php82' | 'php83' | 'php84' | 'php85'; export type DatabaseType = 'mysql' | 'mysql8' | 'mysql84' | 'mysql9' | 'mariadb' | 'mariadb106' | 'mariadb1011' | 'mariadb114' | 'postgres' | 'postgres13' | 'postgres14' | 'postgres15' | 'postgres16' | 'postgres17' | 'postgres18'; export type CreateApiOrgsOrganizationServersArgs = {organization: string, body: {name: string, provider: string, credential_id?: number | undefined, team_id?: (number | null) | undefined, type: ServerType, ubuntu_version: '22.04' | '24.04', php_version?: PhpVersion | undefined, database_type?: DatabaseType | undefined, recipe_id?: (number | null) | undefined, tags?: (Array | null) | undefined, aws?: ({region_id?: string | undefined, size_id?: string | undefined, vpc_uuid?: string | undefined, subnet_uuid?: string | undefined, disk_size?: number | undefined}) | undefined, ocean2?: ({region_id?: string | undefined, size_id?: string | undefined, vpc_uuid?: string | undefined, enable_weekly_backups?: boolean | undefined}) | undefined, hetzner?: ({region_id?: string | undefined, size_id?: string | undefined, network_id?: number | undefined, enable_daily_backups?: boolean | undefined, enable_weekly_backups?: boolean | undefined}) | undefined, vultr?: ({region_id?: string | undefined, size_id?: string | undefined, network_id?: string | undefined}) | undefined, akamai?: ({region_id?: string | undefined, size_id?: string | undefined}) | undefined, laravel?: ({region_id?: string | undefined, size_id?: string | undefined, vpc_uuid?: string | undefined}) | undefined, custom?: ({ip_address?: string | undefined, private_ip_address?: (string | null) | undefined, ssh_port?: number | undefined, behind_nat?: boolean | undefined, nat_ssh_port?: (number | null) | undefined}) | undefined, add_key_to_source_control?: boolean | undefined, database?: string | undefined}}; export type CreateApiOrgsOrganizationServersOptions = {baseUrl?: string | undefined, oauth2?: string | undefined, fetch?: typeof fetch | undefined}; export const serverType = z.enum(["app", "web", "loadbalancer", "database", "cache", "worker", "meilisearch", "openclaw"]); export const tagResourceIdentifier = z.object({type: z.literal("tags"), 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 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 createApiOrgsOrganizationServersResponse = z.object({data: serverResource, included: z.array(tagResource).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 server * * POST /orgs/{organization}/servers */ export const createApiOrgsOrganizationServers = async (args: CreateApiOrgsOrganizationServersArgs, options?: CreateApiOrgsOrganizationServersOptions) => { 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${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(createApiOrgsOrganizationServersResponse, await res.json()) };