@@ -105,7 +105,8 @@ export type ConfigBindingFieldName =
105105 | "assets"
106106 | "unsafe_hello_world"
107107 | "worker_loaders"
108- | "vpc_services" ;
108+ | "vpc_services"
109+ | "vpc_networks" ;
109110
110111/**
111112 * @deprecated new code should use getBindingTypeFriendlyName() instead
@@ -145,6 +146,7 @@ export const friendlyBindingNames: Record<ConfigBindingFieldName, string> = {
145146 unsafe_hello_world : "Hello World" ,
146147 worker_loaders : "Worker Loader" ,
147148 vpc_services : "VPC Service" ,
149+ vpc_networks : "VPC Network" ,
148150} as const ;
149151
150152/**
@@ -187,6 +189,7 @@ const bindingTypeFriendlyNames: Record<Binding["type"], string> = {
187189 ratelimit : "Rate Limit" ,
188190 worker_loader : "Worker Loader" ,
189191 vpc_service : "VPC Service" ,
192+ vpc_network : "VPC Network" ,
190193 media : "Media" ,
191194 assets : "Assets" ,
192195 inherit : "Inherited" ,
@@ -1911,6 +1914,16 @@ function normalizeAndValidateEnvironment(
19111914 validateBindingArray ( envName , validateVpcServiceBinding ) ,
19121915 [ ]
19131916 ) ,
1917+ vpc_networks : notInheritable (
1918+ diagnostics ,
1919+ topLevelEnv ,
1920+ rawConfig ,
1921+ rawEnv ,
1922+ envName ,
1923+ "vpc_networks" ,
1924+ validateBindingArray ( envName , validateVpcNetworkBinding ) ,
1925+ [ ]
1926+ ) ,
19141927 version_metadata : notInheritable (
19151928 diagnostics ,
19161929 topLevelEnv ,
@@ -2958,6 +2971,7 @@ const validateUnsafeBinding: ValidatorFn = (diagnostics, field, value) => {
29582971 "pipeline" ,
29592972 "worker_loader" ,
29602973 "vpc_service" ,
2974+ "vpc_network" ,
29612975 "stream" ,
29622976 "media" ,
29632977 ] ;
@@ -4093,6 +4107,65 @@ const validateVpcServiceBinding: ValidatorFn = (diagnostics, field, value) => {
40934107 return isValid ;
40944108} ;
40954109
4110+ const validateVpcNetworkBinding : ValidatorFn = ( diagnostics , field , value ) => {
4111+ if ( typeof value !== "object" || value === null ) {
4112+ diagnostics . errors . push (
4113+ `"vpc_networks" bindings should be objects, but got ${ JSON . stringify (
4114+ value
4115+ ) } `
4116+ ) ;
4117+ return false ;
4118+ }
4119+ let isValid = true ;
4120+ // VPC network bindings must have a binding and exactly one of tunnel_id or network_id.
4121+ if ( ! isRequiredProperty ( value , "binding" , "string" ) ) {
4122+ diagnostics . errors . push (
4123+ `"${ field } " bindings should have a string "binding" field but got ${ JSON . stringify (
4124+ value
4125+ ) } .`
4126+ ) ;
4127+ isValid = false ;
4128+ }
4129+ const hasTunnelId = hasProperty ( value , "tunnel_id" ) ;
4130+ const hasNetworkId = hasProperty ( value , "network_id" ) ;
4131+ if ( hasTunnelId && hasNetworkId ) {
4132+ diagnostics . errors . push (
4133+ `"${ field } " bindings must have either a "tunnel_id" or "network_id", but not both.`
4134+ ) ;
4135+ isValid = false ;
4136+ } else if ( ! hasTunnelId && ! hasNetworkId ) {
4137+ diagnostics . errors . push (
4138+ `"${ field } " bindings must have either a "tunnel_id" or "network_id" field but got ${ JSON . stringify (
4139+ value
4140+ ) } .`
4141+ ) ;
4142+ isValid = false ;
4143+ } else if ( hasTunnelId && typeof value . tunnel_id !== "string" ) {
4144+ diagnostics . errors . push (
4145+ `"${ field } " bindings must have a string "tunnel_id" field but got ${ JSON . stringify (
4146+ value
4147+ ) } .`
4148+ ) ;
4149+ isValid = false ;
4150+ } else if ( hasNetworkId && typeof value . network_id !== "string" ) {
4151+ diagnostics . errors . push (
4152+ `"${ field } " bindings must have a string "network_id" field but got ${ JSON . stringify (
4153+ value
4154+ ) } .`
4155+ ) ;
4156+ isValid = false ;
4157+ }
4158+
4159+ validateAdditionalProperties ( diagnostics , field , Object . keys ( value ) , [
4160+ "binding" ,
4161+ "tunnel_id" ,
4162+ "network_id" ,
4163+ "remote" ,
4164+ ] ) ;
4165+
4166+ return isValid ;
4167+ } ;
4168+
40964169/**
40974170 * Check that bindings whose names might conflict, don't.
40984171 *
0 commit comments