import {z} from 'zod' export type ShareServerRequest = {server_id: number}; export type CreateApiOrgsOrganizationTeamsTeamServersArgs = {organization: string, team: number, body: ShareServerRequest}; export type CreateApiOrgsOrganizationTeamsTeamServersOptions = {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 createApiOrgsOrganizationTeamsTeamServersResponse = 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 a new server share * * POST /orgs/{organization}/teams/{team}/servers */ export const createApiOrgsOrganizationTeamsTeamServers = async (args: CreateApiOrgsOrganizationTeamsTeamServersArgs, options?: CreateApiOrgsOrganizationTeamsTeamServersOptions) => { 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))}/teams/${encodeURIComponent(String(args.team))}/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(createApiOrgsOrganizationTeamsTeamServersResponse, await res.json()) };