import {z} from 'zod' export type OriginType = 0 | 1 | 2 | 3; export type StandardOriginModel = {OriginUrl?: (string | null) | undefined, HostHeader?: (string | null) | undefined, VerifySsl?: (boolean | null) | undefined}; export type MagicContainersOriginModel = {AppId?: (string | null) | undefined, EndPointId?: (string | null) | undefined}; export type LoadBalancerOriginCreateModel = {Name?: (string | null) | undefined, Weight?: (number | null) | undefined, Enabled?: (boolean | null) | undefined, OriginType?: (OriginType | null) | undefined, EdgeScriptId?: (number | null) | undefined, StorageZoneId?: (number | null) | undefined, StandardOrigin?: (StandardOriginModel | null) | undefined, MagicContainersOrigin?: (MagicContainersOriginModel | null) | undefined}; export type CreateApiLoadbalancerLoadBalancerIdOrigingroupOriginGroupIdOriginArgs = {loadBalancerId: number, originGroupId: number, body: LoadBalancerOriginCreateModel}; export type CreateApiLoadbalancerLoadBalancerIdOrigingroupOriginGroupIdOriginOptions = {baseUrl?: string | undefined, AccessKey?: string | undefined, fetch?: typeof fetch | undefined}; export const healthStatus = z.union([z.literal(0), z.literal(1)]); export const originType = z.union([z.literal(0), z.literal(1), z.literal(2), z.literal(3)]); export const standardOriginModel = z.object({OriginUrl: z.string().nullable().optional(), HostHeader: z.string().nullable().optional(), VerifySsl: z.boolean().nullable().optional()}); export const magicContainersOriginModel = z.object({AppId: z.string().nullable().optional(), EndPointId: z.string().nullable().optional()}); export const loadBalancerOriginModel = z.object({Id: z.number().int().optional(), Name: z.string().nullable().optional(), Weight: z.number().int().optional(), Enabled: z.boolean().optional(), HealthStatus: healthStatus.optional(), OriginType: originType.optional(), EdgeScriptId: z.number().int().nullable().optional(), StorageZoneId: z.number().int().nullable().optional(), StandardOrigin: standardOriginModel.nullable().optional(), MagicContainersOrigin: magicContainersOriginModel.nullable().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 }; /** * Add a new origin to an origin group * * POST /loadbalancer/{loadBalancerId}/origingroup/{originGroupId}/origin * * Also accepts auth: bearer */ export const createApiLoadbalancerLoadBalancerIdOrigingroupOriginGroupIdOrigin = async (args: CreateApiLoadbalancerLoadBalancerIdOrigingroupOriginGroupIdOriginArgs, options?: CreateApiLoadbalancerLoadBalancerIdOrigingroupOriginGroupIdOriginOptions) => { const {baseUrl = "https://api.bunny.net", 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(/\/+$/, '')}/loadbalancer/${encodeURIComponent(String(args.loadBalancerId))}/origingroup/${encodeURIComponent(String(args.originGroupId))}/origin${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(loadBalancerOriginModel, await res.json()) };