import {z} from 'zod' export type GetApiProjectsProjectIdArgs = {projectId: string}; export type GetApiProjectsProjectIdOptions = {baseUrl?: string | undefined, OAuth2?: string | undefined, fetch?: typeof fetch | undefined}; export const project = z.object({id: z.string(), created_at: z.string().nullable(), updated_at: z.string().nullable(), attributes: z.record(z.string(), z.string()), title: z.string(), description: z.string(), owner: z.string(), namespace: z.string().nullable(), organization: z.string().nullable(), default_branch: z.string().nullable(), status: z.object({code: z.string(), message: z.string()}), timezone: z.string(), region: z.string(), repository: z.object({url: z.string(), client_ssh_key: z.string().nullable()}), default_domain: z.string().nullable(), subscription: z.object({license_uri: z.string(), plan: z.enum(["2xlarge", "2xlarge-high-memory", "4xlarge", "8xlarge", "development", "large", "large-high-memory", "medium", "medium-high-memory", "standard", "standard-high-memory", "xlarge", "xlarge-high-memory"]).optional(), environments: z.number().int().optional(), storage: z.number().int(), included_users: z.number().int(), subscription_management_uri: z.string(), restricted: z.boolean(), suspended: z.boolean(), user_licenses: z.number().int(), resources: z.object({container_profiles: z.boolean(), production: z.object({legacy_development: z.boolean(), max_cpu: z.number().nullable(), max_memory: z.number().int().nullable(), max_environments: z.number().int().nullable()}), development: z.object({legacy_development: z.boolean(), max_cpu: z.number().nullable(), max_memory: z.number().int().nullable(), max_environments: z.number().int().nullable()})}).optional(), resource_validation_url: z.string().optional(), image_types: z.object({only: z.array(z.string()).optional(), exclude: z.array(z.string()).optional()}).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 }; /** * Get a project * * GET /projects/{projectId} */ export const getApiProjectsProjectId = async (args: GetApiProjectsProjectIdArgs, options?: GetApiProjectsProjectIdOptions) => { const {baseUrl = "https://api.upsun.com", fetch: fetchFn = fetch, OAuth2} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (OAuth2 !== undefined) headers.set('authorization', `Bearer ${OAuth2}`) const url = `${baseUrl.replace(/\/+$/, '')}/projects/${encodeURIComponent(String(args.projectId))}${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(project, await res.json()) };