import {z} from 'zod' export type GetApiApiV1ProvidersAwsDcVpcsArgs = {AccessKeyID?: string | undefined, SecretAccessKey?: string | undefined, Credential?: string | undefined, dc: string}; export type GetApiApiV1ProvidersAwsDcVpcsOptions = {baseUrl: string, apiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const aWSVpcCidrBlockAssociation = z.object({associationId: z.string().optional(), cidrBlock: z.string().optional(), state: z.string().optional(), statusMessage: z.string().optional()}); export const aWSVpcIpv6CidrBlockAssociation = z.object({associationId: z.string().optional(), cidrBlock: z.string().optional(), state: z.string().optional(), statusMessage: z.string().optional()}); export const aWSTag = z.object({key: z.string().optional(), value: z.string().optional()}); export const aWSVPC = z.object({cidrBlock: z.string().optional(), cidrBlockAssociationSet: z.array(aWSVpcCidrBlockAssociation).optional(), dhcpOptionsId: z.string().optional(), instanceTenancy: z.string().optional(), ipv6CidrBlockAssociationSet: z.array(aWSVpcIpv6CidrBlockAssociation).optional(), isDefault: z.boolean().optional(), name: z.string().optional(), ownerId: z.string().optional(), state: z.string().optional(), tags: z.array(aWSTag).optional(), vpcId: z.string().optional()}); export const aWSVPCList = z.array(aWSVPC); 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 }; /** * Lists available AWS vpc's * * GET /api/v1/providers/aws/{dc}/vpcs */ export const getApiApiV1ProvidersAwsDcVpcs = async (args: GetApiApiV1ProvidersAwsDcVpcsArgs, options: GetApiApiV1ProvidersAwsDcVpcsOptions) => { const {baseUrl, fetch: fetchFn = fetch, apiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.AccessKeyID != null) headers.set("AccessKeyID", String(args.AccessKeyID)) if (args.SecretAccessKey != null) headers.set("SecretAccessKey", String(args.SecretAccessKey)) if (args.Credential != null) headers.set("Credential", String(args.Credential)) if (apiKey !== undefined) headers.set("Authorization", apiKey) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/providers/aws/${encodeURIComponent(String(args.dc))}/vpcs${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(aWSVPCList, await res.json()) };