import {z} from 'zod' export type ApplicationRuntimeType = 'shared' | 'reserved'; export type AutoscalingSettings = {min: number, max: number}; export type UpdateRegionSettingsRequest = {allowedRegionIds?: (Array | null) | undefined, requiredRegionIds?: (Array | null) | undefined, maxAllowedRegions?: (number | null) | undefined, nodeSelectors?: ({[key: string]: string} | null) | undefined}; export type ImagePullPolicy = 'always' | 'ifNotPresent'; export type ContainerEntryPoint = {command?: (string | null) | undefined, commandArray?: (Array | null) | undefined, arguments?: (string | null) | undefined, argumentsArray?: (Array | null) | undefined, workingDirectory?: (string | null) | undefined}; export type HttpGetProbeRequestDetails = {path?: string | undefined, portNumber?: number | undefined}; export type HttpStatusCode = 'continue' | 'switchingProtocols' | 'processing' | 'earlyHints' | 'ok' | 'created' | 'accepted' | 'nonAuthoritativeInformation' | 'noContent' | 'resetContent' | 'partialContent' | 'multiStatus' | 'alreadyReported' | 'imUsed' | 'multipleChoices' | 'movedPermanently' | 'found' | 'seeOther' | 'notModified' | 'useProxy' | 'unused' | 'temporaryRedirect' | 'permanentRedirect' | 'badRequest' | 'unauthorized' | 'paymentRequired' | 'forbidden' | 'notFound' | 'methodNotAllowed' | 'notAcceptable' | 'proxyAuthenticationRequired' | 'requestTimeout' | 'conflict' | 'gone' | 'lengthRequired' | 'preconditionFailed' | 'requestEntityTooLarge' | 'requestUriTooLong' | 'unsupportedMediaType' | 'requestedRangeNotSatisfiable' | 'expectationFailed' | 'misdirectedRequest' | 'unprocessableEntity' | 'locked' | 'failedDependency' | 'upgradeRequired' | 'preconditionRequired' | 'tooManyRequests' | 'requestHeaderFieldsTooLarge' | 'unavailableForLegalReasons' | 'internalServerError' | 'notImplemented' | 'badGateway' | 'serviceUnavailable' | 'gatewayTimeout' | 'httpVersionNotSupported' | 'variantAlsoNegotiates' | 'insufficientStorage' | 'loopDetected' | 'notExtended' | 'networkAuthenticationRequired'; export type HttpGetProbeResponseDetails = {expectedStatusCode?: HttpStatusCode | undefined}; export type HttpGetProbe = {request?: HttpGetProbeRequestDetails | undefined, response?: HttpGetProbeResponseDetails | undefined}; export type TcpSocketProbeRequestDetails = {portNumber?: number | undefined}; export type TcpSocketProbe = {request?: TcpSocketProbeRequestDetails | undefined}; export type GrpcProbeRequestDetails = {portNumber?: number | undefined, serviceName?: (string | null) | undefined}; export type GrpcProbe = {request?: GrpcProbeRequestDetails | undefined}; export type ContainerProbe = {initialDelaySeconds?: (number | null) | undefined, periodSeconds?: (number | null) | undefined, timeoutSeconds?: (number | null) | undefined, failureThreshold?: (number | null) | undefined, successThreshold?: (number | null) | undefined, httpGet?: HttpGetProbe | undefined, tcpSocket?: TcpSocketProbe | undefined, grpc?: GrpcProbe | undefined}; export type ContainerProbes = {startup?: ContainerProbe | undefined, readiness?: ContainerProbe | undefined, liveness?: ContainerProbe | undefined}; export type EnvironmentVariable = {name: string, value?: string | undefined}; export type StickySessionSettings = {enabled?: boolean | undefined, sessionHeaders: Array, cookieName?: string | undefined}; export type Protocol = 'tcp' | 'udp' | 'sctp'; export type ContainerPortMappingRequest = {containerPort: number, exposedPort?: (number | null) | undefined, protocols?: Array | undefined}; export type CdnEndpointRequest = {isSslEnabled?: boolean | undefined, stickySessions?: StickySessionSettings | undefined, pullZoneId?: (number | null) | undefined, portMappings?: Array | undefined}; export type AnycastIpProtocolVersion = 'iPv4'; export type AnycastEndpointRequest = {type: AnycastIpProtocolVersion, portMappings: Array}; export type EndpointRequest = {displayName: string, cdn?: CdnEndpointRequest | undefined, anycast?: AnycastEndpointRequest | undefined}; export type VolumeMountRequest = {name: string, mountPath: string}; export type ContainerRequest = {id?: (string | null) | undefined, name: string, image?: (string | null) | undefined, imageName: string, imageNamespace: string, imageTag: string, imageDigest?: (string | null) | undefined, imageRegistryId: string, imagePullPolicy?: ImagePullPolicy | undefined, entryPoint?: ContainerEntryPoint | undefined, probes?: ContainerProbes | undefined, environmentVariables?: Array | undefined, endpoints?: Array | undefined, volumeMounts?: Array | undefined}; export type VolumeRequest = {name: string, size: number}; export type GpuConfig = {type: string, count?: number | undefined}; export type PatchApplicationRequest = {name?: (string | null) | undefined, runtimeType?: ApplicationRuntimeType | undefined, autoScaling?: AutoscalingSettings | undefined, regionSettings?: UpdateRegionSettingsRequest | undefined, containerTemplates?: (Array | null) | undefined, volumes?: (Array | null) | undefined, gpu?: GpuConfig | undefined}; export type PatchApiAppsAppIdArgs = {appId: string, body: PatchApplicationRequest}; export type PatchApiAppsAppIdOptions = {baseUrl?: string | undefined, AccessKey?: string | undefined, fetch?: typeof fetch | undefined}; export const addApplicationResponse = z.object({id: z.string().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 }; /** * Patch Application * * PATCH /apps/{appId} */ export const patchApiAppsAppId = async (args: PatchApiAppsAppIdArgs, options?: PatchApiAppsAppIdOptions) => { const {baseUrl = "https://api.bunny.net/mc", fetch: fetchFn = fetch, AccessKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (AccessKey !== undefined) headers.set("AccessKey", AccessKey) const url = `${baseUrl.replace(/\/+$/, '')}/apps/${encodeURIComponent(String(args.appId))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", 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(addApplicationResponse, await res.json()) };