@@ -10,6 +10,18 @@ export default withRouteSpec({
1010 package_domain_id : z . string ( ) ,
1111 default_main_component_path : z . string ( ) . nullable ( ) . optional ( ) ,
1212 fully_qualified_domain_name : z . string ( ) . nullable ( ) . optional ( ) ,
13+ points_to : z
14+ . enum ( [
15+ "package_release" ,
16+ "package_build" ,
17+ "package_release_with_tag" ,
18+ "package" ,
19+ ] )
20+ . optional ( ) ,
21+ package_release_id : z . string ( ) . optional ( ) ,
22+ package_build_id : z . string ( ) . optional ( ) ,
23+ package_id : z . string ( ) . optional ( ) ,
24+ tag : z . string ( ) . optional ( ) ,
1325 } ) ,
1426 jsonResponse : z . object ( {
1527 ok : z . boolean ( ) ,
@@ -20,6 +32,11 @@ export default withRouteSpec({
2032 package_domain_id,
2133 default_main_component_path,
2234 fully_qualified_domain_name,
35+ points_to,
36+ package_release_id,
37+ package_build_id,
38+ package_id,
39+ tag,
2340 } = req . jsonBody
2441
2542 const existingDomain = ctx . db . getPackageDomainById ( package_domain_id )
@@ -51,6 +68,70 @@ export default withRouteSpec({
5168 }
5269 }
5370
71+ // Validate the points_to constraint if points_to is being updated
72+ if ( points_to !== undefined ) {
73+ if ( points_to === "package_release" ) {
74+ if ( ! package_release_id ) {
75+ return ctx . error ( 400 , {
76+ error_code : "missing_package_release_id" ,
77+ message :
78+ "package_release_id is required when points_to is 'package_release'" ,
79+ } )
80+ }
81+ if ( package_build_id || tag || package_id ) {
82+ return ctx . error ( 400 , {
83+ error_code : "invalid_params" ,
84+ message :
85+ "package_build_id, tag, and package_id must not be provided when points_to is 'package_release'" ,
86+ } )
87+ }
88+ } else if ( points_to === "package_build" ) {
89+ if ( ! package_build_id ) {
90+ return ctx . error ( 400 , {
91+ error_code : "missing_package_build_id" ,
92+ message :
93+ "package_build_id is required when points_to is 'package_build'" ,
94+ } )
95+ }
96+ if ( package_release_id || tag || package_id ) {
97+ return ctx . error ( 400 , {
98+ error_code : "invalid_params" ,
99+ message :
100+ "package_release_id, tag, and package_id must not be provided when points_to is 'package_build'" ,
101+ } )
102+ }
103+ } else if ( points_to === "package_release_with_tag" ) {
104+ if ( ! package_release_id || ! tag ) {
105+ return ctx . error ( 400 , {
106+ error_code : "missing_params" ,
107+ message :
108+ "package_release_id and tag are required when points_to is 'package_release_with_tag'" ,
109+ } )
110+ }
111+ if ( package_build_id || package_id ) {
112+ return ctx . error ( 400 , {
113+ error_code : "invalid_params" ,
114+ message :
115+ "package_build_id and package_id must not be provided when points_to is 'package_release_with_tag'" ,
116+ } )
117+ }
118+ } else if ( points_to === "package" ) {
119+ if ( ! package_id ) {
120+ return ctx . error ( 400 , {
121+ error_code : "missing_package_id" ,
122+ message : "package_id is required when points_to is 'package'" ,
123+ } )
124+ }
125+ if ( package_release_id || package_build_id || tag ) {
126+ return ctx . error ( 400 , {
127+ error_code : "invalid_params" ,
128+ message :
129+ "package_release_id, package_build_id, and tag must not be provided when points_to is 'package'" ,
130+ } )
131+ }
132+ }
133+ }
134+
54135 const updateValues : Record < string , unknown > = { }
55136
56137 if ( default_main_component_path !== undefined ) {
@@ -61,6 +142,15 @@ export default withRouteSpec({
61142 updateValues . fully_qualified_domain_name = fully_qualified_domain_name
62143 }
63144
145+ if ( points_to !== undefined ) {
146+ updateValues . points_to = points_to
147+ // Clear all pointer fields and set the appropriate ones
148+ updateValues . package_release_id = package_release_id ?? null
149+ updateValues . package_build_id = package_build_id ?? null
150+ updateValues . package_id = package_id ?? null
151+ updateValues . tag = tag ?? null
152+ }
153+
64154 if ( Object . keys ( updateValues ) . length === 0 ) {
65155 return ctx . json ( {
66156 ok : true ,
0 commit comments