import {z} from 'zod' export type CoreEvent = {canaryRevision?: string | undefined, message?: string | undefined, revision?: string | undefined, status?: string | undefined, time?: string | undefined, type?: string | undefined}; export type CoreEvents = Array; export type EgressIPMetadata = {createdAt?: string | undefined, updatedAt?: string | undefined, createdBy?: string | undefined, updatedBy?: string | undefined, displayName?: string | undefined, gatewayName?: string | undefined, name: string, vpcName?: string | undefined, workspace?: string | undefined}; export type EgressIPSpec = {ipFamily: 'IPv4' | 'IPv6', publicIp?: string | undefined}; export type Status = 'DELETING' | 'TERMINATED' | 'FAILED' | 'DEACTIVATED' | 'DEACTIVATING' | 'UPLOADING' | 'BUILDING' | 'DEPLOYING' | 'DEPLOYED' | 'BUILT'; export type EgressIP = {events?: CoreEvents | undefined, metadata: EgressIPMetadata, spec: EgressIPSpec, status?: Status | undefined}; export type CreateApiVpcsVpcNameEgressgatewaysGatewayNameIpsArgs = {vpcName: string, gatewayName: string, body: EgressIP}; export type CreateApiVpcsVpcNameEgressgatewaysGatewayNameIpsOptions = {baseUrl?: string | undefined, OAuth2?: string | undefined, fetch?: typeof fetch | undefined}; export const coreEvent = z.object({canaryRevision: z.string().optional(), message: z.string().optional(), revision: z.string().optional(), status: z.string().optional(), time: z.string().optional(), type: z.string().optional()}); export const coreEvents = z.array(coreEvent); export const egressIPMetadata = z.object({createdAt: z.string().optional(), updatedAt: z.string().optional(), createdBy: z.string().optional(), updatedBy: z.string().optional(), displayName: z.string().optional(), gatewayName: z.string().optional(), name: z.string(), vpcName: z.string().optional(), workspace: z.string().optional()}); export const egressIPSpec = z.object({ipFamily: z.enum(["IPv4", "IPv6"]), publicIp: z.string().optional()}); export const status = z.enum(["DELETING", "TERMINATED", "FAILED", "DEACTIVATED", "DEACTIVATING", "UPLOADING", "BUILDING", "DEPLOYING", "DEPLOYED", "BUILT"]); export const egressIP = z.object({events: coreEvents.optional(), metadata: egressIPMetadata, spec: egressIPSpec, status: status.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 }; /** * Allocate a new egress IP from the gateway * * POST /vpcs/{vpcName}/egressgateways/{gatewayName}/ips * * Also accepts auth: ApiKeyAuth */ export const createApiVpcsVpcNameEgressgatewaysGatewayNameIps = async (args: CreateApiVpcsVpcNameEgressgatewaysGatewayNameIpsArgs, options?: CreateApiVpcsVpcNameEgressgatewaysGatewayNameIpsOptions) => { const {baseUrl = "https://api.blaxel.ai/v0", fetch: fetchFn = fetch, OAuth2} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (OAuth2 !== undefined) headers.set('authorization', `Bearer ${OAuth2}`) const url = `${baseUrl.replace(/\/+$/, '')}/vpcs/${encodeURIComponent(String(args.vpcName))}/egressgateways/${encodeURIComponent(String(args.gatewayName))}/ips${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(egressIP, await res.json()) };