import {z} from 'zod' export type GithubComAlchemillahqSylvePkgNetworkBridgevlanPortPolicy = {mode?: string | undefined, taggedVlans?: Array | undefined, untaggedVlan?: number | undefined}; export type GithubComAlchemillahqSylveInternalInterfacesServicesJailAddJailNetworkRequest = {defaultGateway?: boolean | undefined, dhcp?: boolean | undefined, ip4?: number | undefined, ip4Raw?: string | undefined, ip4gw?: number | undefined, ip4gwRaw?: string | undefined, ip6?: number | undefined, ip6Raw?: string | undefined, ip6gw?: number | undefined, ip6gwRaw?: string | undefined, macId?: number | undefined, macRaw?: string | undefined, name: string, slaac?: boolean | undefined, switchName: string, vlanPolicy?: GithubComAlchemillahqSylvePkgNetworkBridgevlanPortPolicy | undefined}; export type CreateApiJailCtidNetworksArgs = {ctid: number, body: GithubComAlchemillahqSylveInternalInterfacesServicesJailAddJailNetworkRequest}; export type CreateApiJailCtidNetworksOptions = {baseUrl: string, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const githubComAlchemillahqSylveInternalNetworkAttachmentKind = z.enum(["vm", "jail"]); export const githubComAlchemillahqSylvePkgNetworkBridgevlanPortPolicy = z.object({mode: z.string().optional(), taggedVlans: z.array(z.number().int()).optional(), untaggedVlan: z.number().int().optional()}); export const githubComAlchemillahqSylveInternalNetworkAttachmentContract = z.object({defaultAccessVlan: z.number().int().optional(), kind: githubComAlchemillahqSylveInternalNetworkAttachmentKind.optional(), switchName: z.string().optional(), switchType: z.string().optional(), version: z.number().int().optional(), vlanFiltering: z.boolean().optional(), vlanPolicy: githubComAlchemillahqSylvePkgNetworkBridgevlanPortPolicy.optional()}); export const githubComAlchemillahqSylveInternalDbModelsNetworkObjectEntry = z.object({createdAt: z.string().optional(), id: z.number().int().optional(), objectId: z.number().int().optional(), updatedAt: z.string().optional(), value: z.string().optional()}); export const githubComAlchemillahqSylveInternalDbModelsNetworkObjectResolution = z.object({createdAt: z.string().optional(), id: z.number().int().optional(), objectId: z.number().int().optional(), resolvedIp: z.string().optional(), resolvedValue: z.string().optional(), updatedAt: z.string().optional()}); export const githubComAlchemillahqSylveInternalDbModelsNetworkObjectUsage = z.object({id: z.number().int().optional(), name: z.string().optional(), type: z.string().optional()}); export const githubComAlchemillahqSylveInternalDbModelsNetworkObject = z.object({autoUpdate: z.boolean().optional(), createdAt: z.string().optional(), description: z.string().optional(), entries: z.array(githubComAlchemillahqSylveInternalDbModelsNetworkObjectEntry).optional(), id: z.number().int().optional(), isUsed: z.boolean().optional(), isUsedBy: z.string().optional(), lastRefreshAt: z.string().optional(), lastRefreshError: z.string().optional(), name: z.string().optional(), refreshIntervalSeconds: z.number().int().optional(), resolutionChecksum: z.string().optional(), resolutions: z.array(githubComAlchemillahqSylveInternalDbModelsNetworkObjectResolution).optional(), sourceChecksum: z.string().optional(), type: z.string().optional(), updatedAt: z.string().optional(), usedBy: z.array(githubComAlchemillahqSylveInternalDbModelsNetworkObjectUsage).optional()}); export const githubComAlchemillahqSylveInternalDbModelsNetworkManualSwitch = z.object({bridge: z.string().optional(), createdAt: z.string().optional(), defaultAccessVlan: z.number().int().optional(), id: z.number().int().optional(), name: z.string().optional(), updatedAt: z.string().optional(), vlanFiltering: z.boolean().optional(), vlanStateAvailable: z.boolean().optional(), vlanStateError: z.string().optional()}); export const githubComAlchemillahqSylveInternalDbModelsNetworkStandardSwitchAddress = z.object({cidr: z.string().optional(), family: z.number().int().optional(), id: z.number().int().optional(), object: githubComAlchemillahqSylveInternalDbModelsNetworkObject.optional(), objectId: z.number().int().optional(), ordering: z.number().int().optional(), switchId: z.number().int().optional()}); export const githubComAlchemillahqSylveInternalDbModelsNetworkNetworkPort = z.object({id: z.number().int().optional(), name: z.string().optional(), switch: z.lazy(() => githubComAlchemillahqSylveInternalDbModelsNetworkStandardSwitch.optional()), switchId: z.number().int().optional(), vlanPolicy: githubComAlchemillahqSylvePkgNetworkBridgevlanPortPolicy.optional()}); export const githubComAlchemillahqSylveInternalDbModelsNetworkStandardSwitch: z.ZodType = z.object({address: z.string().optional(), address6: z.string().optional(), address6Id: z.number().int().optional(), address6Obj: githubComAlchemillahqSylveInternalDbModelsNetworkObject.optional(), addressId: z.number().int().optional(), addressObj: githubComAlchemillahqSylveInternalDbModelsNetworkObject.optional(), addresses: z.array(githubComAlchemillahqSylveInternalDbModelsNetworkStandardSwitchAddress).optional(), bridgeMacMode: z.string().optional(), bridgeMacObject: githubComAlchemillahqSylveInternalDbModelsNetworkObject.optional(), bridgeMacObjectId: z.number().int().optional(), bridgeMacSourcePort: z.string().optional(), bridgeName: z.string().optional(), createdAt: z.string().optional(), defaultAccessVlan: z.number().int().optional(), defaultRoute: z.boolean().optional(), defaultRoute6: z.boolean().optional(), dhcp: z.boolean().optional(), disableBridgeOffloads: z.boolean().optional(), disableIPv6: z.boolean().optional(), gateway6AddressId: z.number().int().optional(), gateway6AddressObj: githubComAlchemillahqSylveInternalDbModelsNetworkObject.optional(), gateway6Manual: z.string().optional(), gatewayAddressId: z.number().int().optional(), gatewayAddressObj: githubComAlchemillahqSylveInternalDbModelsNetworkObject.optional(), gatewayManual: z.string().optional(), hostVlan: z.number().int().optional(), id: z.number().int().optional(), mtu: z.number().int().optional(), name: z.string().optional(), network6Id: z.number().int().optional(), network6Manual: z.string().optional(), network6Obj: githubComAlchemillahqSylveInternalDbModelsNetworkObject.optional(), networkId: z.number().int().optional(), networkManual: z.string().optional(), networkObj: githubComAlchemillahqSylveInternalDbModelsNetworkObject.optional(), ports: z.array(githubComAlchemillahqSylveInternalDbModelsNetworkNetworkPort).optional(), private: z.boolean().optional(), slaac: z.boolean().optional(), updatedAt: z.string().optional(), vlan: z.number().int().optional(), vlanFiltering: z.boolean().optional()}); export const githubComAlchemillahqSylveInternalDbModelsJailNetwork = z.object({attachment: githubComAlchemillahqSylveInternalNetworkAttachmentContract.optional(), defaultGateway: z.boolean().optional(), dhcp: z.boolean().optional(), id: z.number().int().optional(), ipv4GwId: z.number().int().optional(), ipv4GwObj: githubComAlchemillahqSylveInternalDbModelsNetworkObject.optional(), ipv4Id: z.number().int().optional(), ipv4Obj: githubComAlchemillahqSylveInternalDbModelsNetworkObject.optional(), ipv6GwId: z.number().int().optional(), ipv6GwObj: githubComAlchemillahqSylveInternalDbModelsNetworkObject.optional(), ipv6Id: z.number().int().optional(), ipv6Obj: githubComAlchemillahqSylveInternalDbModelsNetworkObject.optional(), jid: z.number().int().optional(), macId: z.number().int().optional(), macObj: githubComAlchemillahqSylveInternalDbModelsNetworkObject.optional(), manualSwitch: githubComAlchemillahqSylveInternalDbModelsNetworkManualSwitch.optional(), name: z.string().optional(), slaac: z.boolean().optional(), standardSwitch: githubComAlchemillahqSylveInternalDbModelsNetworkStandardSwitch.optional(), switchId: z.number().int().optional(), switchType: z.string().optional(), vlanPolicy: githubComAlchemillahqSylvePkgNetworkBridgevlanPortPolicy.optional()}); export const githubComAlchemillahqSylveInternalAPIResponseGithubComAlchemillahqSylveInternalDbModelsJailNetwork = z.object({data: githubComAlchemillahqSylveInternalDbModelsJailNetwork.optional(), error: z.string().optional(), message: z.string().optional(), status: 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 }; /** * Attach a network to a jail * * POST /jail/{ctid}/networks */ export const createApiJailCtidNetworks = async (args: CreateApiJailCtidNetworksArgs, options: CreateApiJailCtidNetworksOptions) => { const {baseUrl, fetch: fetchFn = fetch, BearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (BearerAuth !== undefined) headers.set("Authorization", BearerAuth) const url = `${baseUrl.replace(/\/+$/, '')}/jail/${encodeURIComponent(String(args.ctid))}/networks${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(githubComAlchemillahqSylveInternalAPIResponseGithubComAlchemillahqSylveInternalDbModelsJailNetwork, await res.json()) };