import {z} from 'zod' export type SiteType = 'laravel' | 'symfony' | 'statamic' | 'wordpress' | 'phpmyadmin' | 'php' | 'nextjs' | 'nuxtjs' | 'static-html' | 'other' | 'custom'; export type CreateSiteDomainMode = 'on-forge' | 'custom'; export type WwwRedirectType = 'from-www' | 'to-www' | 'none'; export type PhpVersion = 'php5' | 'php56-old' | 'php56' | 'php70' | 'php71' | 'php72' | 'php73' | 'php74' | 'php80' | 'php81' | 'php82' | 'php83' | 'php84' | 'php85'; export type SourceControlProvider = 'github' | 'gitlab' | 'bitbucket' | 'gitlab-custom' | 'custom'; export type CreateSiteRequest = {type: SiteType, domain_mode?: (string | CreateSiteDomainMode) | undefined, name?: (string | string) | undefined, www_redirect_type?: WwwRedirectType | undefined, allow_wildcard_subdomains?: boolean | undefined, root_directory?: (string | null) | undefined, web_directory?: (string | null) | undefined, is_isolated?: boolean | undefined, isolated_user?: string | undefined, php_version?: PhpVersion | undefined, zero_downtime_deployments?: boolean | undefined, nginx_template_id?: number | undefined, source_control_provider?: SourceControlProvider | undefined, source_control_provider_id?: (number | null) | undefined, repository?: (string | null) | undefined, branch?: (string | null) | undefined, database_id?: number | undefined, database_user_id?: number | undefined, statamic_setup?: string | undefined, statamic_starter_kit?: string | undefined, statamic_super_user_email?: string | undefined, statamic_super_user_password?: (string | null) | undefined, install_composer_dependencies?: boolean | undefined, generate_deploy_key?: boolean | undefined, public_deploy_key?: string | undefined, private_deploy_key?: string | undefined, frontend_package_manager?: string | undefined, frontend_build_command?: string | undefined, nuxt_next_mode?: string | undefined, nuxt_next_port?: number | undefined, push_to_deploy?: boolean | undefined, tags?: (Array | null) | undefined, shared_paths?: Array<{from: string, to: string}> | undefined}; export type CreateApiOrgsOrganizationServersServerSitesArgs = {organization: string, server: number, body: CreateSiteRequest}; export type CreateApiOrgsOrganizationServersServerSitesOptions = {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 createApiOrgsOrganizationServersServerSitesResponse = 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 * * POST /orgs/{organization}/servers/{server}/sites */ export const createApiOrgsOrganizationServersServerSites = async (args: CreateApiOrgsOrganizationServersServerSitesArgs, options?: CreateApiOrgsOrganizationServersServerSitesOptions) => { 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${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(createApiOrgsOrganizationServersServerSitesResponse, await res.json()) };