@@ -362,7 +362,7 @@ export class ManagementClient {
362362 payload : Record < string , any > ,
363363 ) : Promise < RolePermission > {
364364 const key = resolveKey ( roleKey ) ;
365- return this . request ( 'PUT ' , `${ this . paths . rolePermissionsRoot ( key ) } /` , {
365+ return this . request ( 'POST ' , `${ this . paths . rolePermissionsRoot ( key ) } /` , {
366366 jsonBody : payload ,
367367 } ) ;
368368 }
@@ -372,7 +372,8 @@ export class ManagementClient {
372372 contentType : string ,
373373 ) : Promise < void > {
374374 const key = resolveKey ( roleKey ) ;
375- await this . request ( 'DELETE' , `${ this . paths . rolePermissionsRoot ( key ) } /${ contentType } /` , {
375+ await this . request ( 'DELETE' , `${ this . paths . rolePermissionsRoot ( key ) } /` , {
376+ params : { content_type : contentType } ,
376377 parseJson : false ,
377378 } ) ;
378379 }
@@ -382,10 +383,10 @@ export class ManagementClient {
382383 permissions : Array < Record < string , any > > ,
383384 ) : Promise < RolePermission [ ] > {
384385 const key = resolveKey ( roleKey ) ;
385- const payload = await this . request ( 'PUT ' , `${ this . paths . rolePermissionsBatch ( key ) } /` , {
386+ const payload = await this . request ( 'POST ' , `${ this . paths . rolePermissionsBatch ( key ) } /` , {
386387 jsonBody : permissions ,
387388 } ) ;
388- return Array . isArray ( payload ) ? payload : [ payload ] ;
389+ return Array . isArray ( payload ) ? payload : [ ] ;
389390 }
390391
391392 // Management permission objects
@@ -467,7 +468,7 @@ export class ManagementClient {
467468 payload : Record < string , any > ,
468469 ) : Promise < RolePermission > {
469470 const key = resolveKey ( roleKey ) ;
470- return this . request ( 'PUT ' , `${ this . paths . fluxRolePermissionsRoot ( key ) } /` , {
471+ return this . request ( 'POST ' , `${ this . paths . fluxRolePermissionsRoot ( key ) } /` , {
471472 jsonBody : payload ,
472473 } ) ;
473474 }
@@ -476,8 +477,8 @@ export class ManagementClient {
476477 const key = resolveKey ( roleKey ) ;
477478 await this . request (
478479 'DELETE' ,
479- `${ this . paths . fluxRolePermissionsRoot ( key ) } /${ contentType } / ` ,
480- { parseJson : false } ,
480+ `${ this . paths . fluxRolePermissionsRoot ( key ) } /` ,
481+ { params : { content_type : contentType } , parseJson : false } ,
481482 ) ;
482483 }
483484
@@ -486,10 +487,10 @@ export class ManagementClient {
486487 permissions : Array < Record < string , any > > ,
487488 ) : Promise < RolePermission [ ] > {
488489 const key = resolveKey ( roleKey ) ;
489- const payload = await this . request ( 'PUT ' , `${ this . paths . fluxRolePermissionsBatch ( key ) } /` , {
490+ const payload = await this . request ( 'POST ' , `${ this . paths . fluxRolePermissionsBatch ( key ) } /` , {
490491 jsonBody : permissions ,
491492 } ) ;
492- return Array . isArray ( payload ) ? payload : [ payload ] ;
493+ return Array . isArray ( payload ) ? payload : [ ] ;
493494 }
494495
495496 // Flux permission objects
@@ -532,12 +533,14 @@ export class ManagementClient {
532533 // ------------------------------------------------------------------ //
533534
534535 async listFolders ( params ?: Record < string , any > ) : Promise < FolderList > {
535- return this . request ( 'GET' , `${ this . paths . foldersRoot ( ) } /` , { params } ) ;
536+ return this . request ( 'GET' , `${ this . paths . foldersTreeRoot ( ) } /` , { params } ) ;
536537 }
537538
538539 async getFolder ( folderKey : FolderRef ) : Promise < FolderSummary > {
539540 const key = resolveKey ( folderKey ) ;
540- return this . request ( 'GET' , `${ this . paths . folderRoot ( key ) } /` ) ;
541+ return this . request ( 'GET' , `${ this . paths . foldersTreeItem ( ) } /` , {
542+ params : { key } ,
543+ } ) ;
541544 }
542545
543546 async getFolderByPath ( path : string ) : Promise < FolderSummary > {
@@ -565,12 +568,18 @@ export class ManagementClient {
565568 payload : Record < string , any > ,
566569 ) : Promise < FolderSummary > {
567570 const key = resolveKey ( folderKey ) ;
568- return this . request ( 'PUT' , `${ this . paths . folderRoot ( key ) } /` , { jsonBody : payload } ) ;
571+ return this . request ( 'PUT' , `${ this . paths . foldersTreeItem ( ) } /` , {
572+ params : { key } ,
573+ jsonBody : payload ,
574+ } ) ;
569575 }
570576
571577 async deleteFolder ( folderKey : FolderRef ) : Promise < void > {
572578 const key = resolveKey ( folderKey ) ;
573- await this . request ( 'DELETE' , `${ this . paths . folderRoot ( key ) } /` , { parseJson : false } ) ;
579+ await this . request ( 'DELETE' , `${ this . paths . foldersTreeItem ( ) } /` , {
580+ params : { key } ,
581+ parseJson : false ,
582+ } ) ;
574583 }
575584
576585 // ------------------------------------------------------------------ //
@@ -687,7 +696,8 @@ export class ManagementClient {
687696 const vKey = resolveKey ( versionKey ) ;
688697 return this . request (
689698 'GET' ,
690- `${ this . paths . folderSchemaTree ( fKey , vKey ) } /${ fieldPath } /` ,
699+ `${ this . paths . folderSchemaTree ( fKey , vKey ) } /field/` ,
700+ { params : { path : fieldPath } } ,
691701 ) ;
692702 }
693703
@@ -701,8 +711,8 @@ export class ManagementClient {
701711 const vKey = resolveKey ( versionKey ) ;
702712 return this . request (
703713 'PUT' ,
704- `${ this . paths . folderSchemaTree ( fKey , vKey ) } /${ fieldPath } /` ,
705- { jsonBody : payload } ,
714+ `${ this . paths . folderSchemaTree ( fKey , vKey ) } /field /` ,
715+ { params : { path : fieldPath } , jsonBody : payload } ,
706716 ) ;
707717 }
708718
@@ -715,8 +725,8 @@ export class ManagementClient {
715725 const vKey = resolveKey ( versionKey ) ;
716726 await this . request (
717727 'DELETE' ,
718- `${ this . paths . folderSchemaTree ( fKey , vKey ) } /${ fieldPath } /` ,
719- { parseJson : false } ,
728+ `${ this . paths . folderSchemaTree ( fKey , vKey ) } /field /` ,
729+ { params : { path : fieldPath } , parseJson : false } ,
720730 ) ;
721731 }
722732
@@ -864,7 +874,8 @@ export class ManagementClient {
864874 const vKey = resolveKey ( versionKey ) ;
865875 return this . request (
866876 'GET' ,
867- `${ this . paths . componentSchemaTree ( cKey , vKey ) } /${ fieldPath } /` ,
877+ `${ this . paths . componentSchemaTree ( cKey , vKey ) } /field/` ,
878+ { params : { path : fieldPath } } ,
868879 ) ;
869880 }
870881
@@ -878,8 +889,8 @@ export class ManagementClient {
878889 const vKey = resolveKey ( versionKey ) ;
879890 return this . request (
880891 'PUT' ,
881- `${ this . paths . componentSchemaTree ( cKey , vKey ) } /${ fieldPath } /` ,
882- { jsonBody : payload } ,
892+ `${ this . paths . componentSchemaTree ( cKey , vKey ) } /field /` ,
893+ { params : { path : fieldPath } , jsonBody : payload } ,
883894 ) ;
884895 }
885896
@@ -892,8 +903,8 @@ export class ManagementClient {
892903 const vKey = resolveKey ( versionKey ) ;
893904 await this . request (
894905 'DELETE' ,
895- `${ this . paths . componentSchemaTree ( cKey , vKey ) } /${ fieldPath } /` ,
896- { parseJson : false } ,
906+ `${ this . paths . componentSchemaTree ( cKey , vKey ) } /field /` ,
907+ { params : { path : fieldPath } , parseJson : false } ,
897908 ) ;
898909 }
899910
@@ -921,14 +932,18 @@ export class ManagementClient {
921932 options ?: { component ?: ComponentRef ; externalId ?: string } ,
922933 ) : Promise < ResourceSummary > {
923934 const key = resolveKey ( folderKey ) ;
924- const body = { ... payload } ;
935+ const params : Record < string , string > = { } ;
925936 if ( options ?. component ) {
926- body . component = resolveKey ( options . component ) ;
937+ params . component = resolveKey ( options . component ) ;
927938 }
939+ const body = { ...payload } ;
928940 if ( options ?. externalId ) {
929941 body . external_id = options . externalId ;
930942 }
931- return this . request ( 'POST' , `${ this . paths . resourceBase ( key ) } /` , { jsonBody : body } ) ;
943+ return this . request ( 'POST' , `${ this . paths . resourceBase ( key ) } /` , {
944+ params : Object . keys ( params ) . length ? params : undefined ,
945+ jsonBody : body ,
946+ } ) ;
932947 }
933948
934949 async upsertResource (
@@ -937,11 +952,14 @@ export class ManagementClient {
937952 options : { externalId : string ; component ?: ComponentRef } ,
938953 ) : Promise < ResourceSummary > {
939954 const key = resolveKey ( folderKey ) ;
940- const body : Record < string , any > = { ... payload , external_id : options . externalId } ;
955+ const params : Record < string , string > = { external_id : options . externalId } ;
941956 if ( options . component ) {
942- body . component = resolveKey ( options . component ) ;
957+ params . component = resolveKey ( options . component ) ;
943958 }
944- return this . request ( 'PUT' , `${ this . paths . resourceBase ( key ) } /` , { jsonBody : body } ) ;
959+ return this . request ( 'PUT' , `${ this . paths . resourceBase ( key ) } /` , {
960+ params,
961+ jsonBody : payload ,
962+ } ) ;
945963 }
946964
947965 async batchUpsertResources (
@@ -955,6 +973,12 @@ export class ManagementClient {
955973 ) : Promise < BatchUpsertResult > {
956974 const fKey = resolveKey ( folderKey ) ;
957975 const maxConcurrency = options ?. maxConcurrency ?? 5 ;
976+ if ( maxConcurrency < 1 ) {
977+ throw new Error ( 'maxConcurrency must be at least 1' ) ;
978+ }
979+ if ( items . length === 0 ) {
980+ return { succeeded : [ ] , failed : [ ] } ;
981+ }
958982 const failFast = options ?. failFast ?? false ;
959983 const onProgress = options ?. onProgress ;
960984
@@ -966,17 +990,14 @@ export class ManagementClient {
966990
967991 const processItem = async ( index : number , item : BatchUpsertItem ) : Promise < void > => {
968992 try {
969- const body : Record < string , any > = {
970- ...item . payload ,
971- external_id : item . external_id ,
972- } ;
993+ const params : Record < string , string > = { external_id : item . external_id } ;
973994 if ( item . component ) {
974- body . component = item . component ;
995+ params . component = item . component ;
975996 }
976997 const result : ResourceSummary = await this . request (
977998 'PUT' ,
978999 `${ this . paths . resourceBase ( fKey ) } /` ,
979- { jsonBody : body } ,
1000+ { params , jsonBody : item . payload } ,
9801001 ) ;
9811002 succeeded . push ( result ) ;
9821003 } catch ( err ) {
@@ -1000,8 +1021,8 @@ export class ManagementClient {
10001021 const batch = queue . slice ( i , i + maxConcurrency ) ;
10011022 try {
10021023 await Promise . all ( batch . map ( ( [ index , item ] ) => processItem ( index , item ) ) ) ;
1003- } catch {
1004- if ( failFast ) break ;
1024+ } catch ( err ) {
1025+ if ( failFast ) throw err ;
10051026 }
10061027 i += maxConcurrency ;
10071028 }
@@ -1016,9 +1037,11 @@ export class ManagementClient {
10161037 ) : Promise < ResourceSummary > {
10171038 const fKey = resolveKey ( folderKey ) ;
10181039 const rKey = resolveKey ( resourceKey ) ;
1019- return this . request ( 'PUT' , `${ this . paths . resourceBase ( fKey ) } /${ rKey } /` , {
1040+ await this . request ( 'PUT' , `${ this . paths . resourceBase ( fKey ) } /${ rKey } /` , {
10201041 jsonBody : payload ,
1042+ parseJson : false ,
10211043 } ) ;
1044+ return this . getResource ( fKey , rKey ) ;
10221045 }
10231046
10241047 async deleteResource ( folderKey : FolderRef , resourceKey : ResourceRef ) : Promise < void > {
@@ -1309,8 +1332,8 @@ export class ManagementClient {
13091332 body . protection_reason = options . protectionReason ;
13101333 }
13111334 return this . request (
1312- 'POST ' ,
1313- `${ this . paths . environmentRoot ( oKey , pKey , eKey ) } /protect /` ,
1335+ 'PATCH ' ,
1336+ `${ this . paths . environmentRoot ( oKey , pKey , eKey ) } /protection /` ,
13141337 { jsonBody : body } ,
13151338 ) ;
13161339 }
@@ -1320,12 +1343,8 @@ export class ManagementClient {
13201343 projectKey : ProjectRef ,
13211344 envKey : EnvironmentRef ,
13221345 ) : Promise < EnvironmentSummary > {
1323- const oKey = resolveKey ( orgKey ) ;
1324- const pKey = resolveKey ( projectKey ) ;
1325- const eKey = resolveKey ( envKey ) ;
1326- return this . request (
1327- 'POST' ,
1328- `${ this . paths . environmentRoot ( oKey , pKey , eKey ) } /unprotect/` ,
1329- ) ;
1346+ return this . updateEnvironmentProtection ( orgKey , projectKey , envKey , {
1347+ protectionLevel : 'none' ,
1348+ } ) ;
13301349 }
13311350}
0 commit comments