import {z} from 'zod' export type GetApiOrgsOrganizationServersArgs = {organization: string, sort?: string | undefined, 'page[size]'?: number | undefined, 'page[cursor]'?: string | undefined, 'filter[ip_address]'?: string | undefined, 'filter[name]'?: string | undefined, 'filter[region]'?: string | undefined, 'filter[size]'?: string | undefined, 'filter[provider]'?: string | undefined, 'filter[ubuntu_version]'?: string | undefined, 'filter[php_version]'?: string | undefined, 'filter[database_type]'?: string | undefined}; export type GetApiOrgsOrganizationServersOptions = {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 getApiOrgsOrganizationServersResponse = z.object({data: z.array(serverResource), links: z.object({first: z.string().optional(), last: z.string().optional(), prev: z.string().optional(), next: z.string().optional()}), meta: z.object({path: z.string().nullable(), per_page: z.number().int().gte(0), next_cursor: z.string().nullable(), prev_cursor: z.string().nullable()}), 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 }; /** * List servers * * GET /orgs/{organization}/servers */ export const getApiOrgsOrganizationServers = async (args: GetApiOrgsOrganizationServersArgs, options?: GetApiOrgsOrganizationServersOptions) => { const {baseUrl = "https://forge.laravel.com/api", fetch: fetchFn = fetch, oauth2} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/vnd.api+json") if (args.sort != null) query.append("sort", String(args.sort)) if (args['page[size]'] != null) query.append("page[size]", String(args['page[size]'])) if (args['page[cursor]'] != null) query.append("page[cursor]", String(args['page[cursor]'])) if (args['filter[ip_address]'] != null) query.append("filter[ip_address]", String(args['filter[ip_address]'])) if (args['filter[name]'] != null) query.append("filter[name]", String(args['filter[name]'])) if (args['filter[region]'] != null) query.append("filter[region]", String(args['filter[region]'])) if (args['filter[size]'] != null) query.append("filter[size]", String(args['filter[size]'])) if (args['filter[provider]'] != null) query.append("filter[provider]", String(args['filter[provider]'])) if (args['filter[ubuntu_version]'] != null) query.append("filter[ubuntu_version]", String(args['filter[ubuntu_version]'])) if (args['filter[php_version]'] != null) query.append("filter[php_version]", String(args['filter[php_version]'])) if (args['filter[database_type]'] != null) query.append("filter[database_type]", String(args['filter[database_type]'])) 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: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(getApiOrgsOrganizationServersResponse, await res.json()) };