@@ -51,15 +51,19 @@ function updatePath(baseUrl: string, id: string, suffix?: string): string {
5151export async function fetchUpdateIds ( baseUrl : string , signal ?: AbortSignal ) : Promise < string [ ] > {
5252 const res = await fetch ( `${ baseUrl } /updates` , { signal } ) ;
5353 await ensureOk ( res ) ;
54- const data : { items : string [ ] } = await res . json ( ) ;
55- return data . items ;
54+ const data = await res . json ( ) ;
55+ return Array . isArray ( data ? .items ) ? data . items : [ ] ;
5656}
5757
5858/** GET /updates/{id}/status - returns update status with progress */
5959export async function fetchUpdateStatus ( baseUrl : string , id : string , signal ?: AbortSignal ) : Promise < UpdateStatus > {
6060 const res = await fetch ( updatePath ( baseUrl , id , 'status' ) , { signal } ) ;
6161 await ensureOk ( res ) ;
62- return res . json ( ) ;
62+ const data = await res . json ( ) ;
63+ if ( typeof data ?. status !== 'string' ) {
64+ throw new UpdatesApiError ( 'Invalid status response' , 0 ) ;
65+ }
66+ return data as UpdateStatus ;
6367}
6468
6569/** GET /updates/{id} - returns plugin-defined detail object */
@@ -74,37 +78,45 @@ export async function fetchUpdateDetail(
7478}
7579
7680/** PUT /updates/{id}/prepare - start preparation (202) */
77- export async function triggerPrepare ( baseUrl : string , id : string , data ?: unknown ) : Promise < void > {
81+ export async function triggerPrepare ( baseUrl : string , id : string , data ?: unknown , signal ?: AbortSignal ) : Promise < void > {
7882 const res = await fetch ( updatePath ( baseUrl , id , 'prepare' ) , {
7983 method : 'PUT' ,
8084 headers : { 'Content-Type' : 'application/json' } ,
8185 body : JSON . stringify ( data ?? { } ) ,
86+ signal,
8287 } ) ;
8388 await ensureOk ( res ) ;
8489}
8590
8691/** PUT /updates/{id}/execute - start execution (202) */
87- export async function triggerExecute ( baseUrl : string , id : string , data ?: unknown ) : Promise < void > {
92+ export async function triggerExecute ( baseUrl : string , id : string , data ?: unknown , signal ?: AbortSignal ) : Promise < void > {
8893 const res = await fetch ( updatePath ( baseUrl , id , 'execute' ) , {
8994 method : 'PUT' ,
9095 headers : { 'Content-Type' : 'application/json' } ,
9196 body : JSON . stringify ( data ?? { } ) ,
97+ signal,
9298 } ) ;
9399 await ensureOk ( res ) ;
94100}
95101
96102/** PUT /updates/{id}/automated - start automated update (202) */
97- export async function triggerAutomated ( baseUrl : string , id : string , data ?: unknown ) : Promise < void > {
103+ export async function triggerAutomated (
104+ baseUrl : string ,
105+ id : string ,
106+ data ?: unknown ,
107+ signal ?: AbortSignal
108+ ) : Promise < void > {
98109 const res = await fetch ( updatePath ( baseUrl , id , 'automated' ) , {
99110 method : 'PUT' ,
100111 headers : { 'Content-Type' : 'application/json' } ,
101112 body : JSON . stringify ( data ?? { } ) ,
113+ signal,
102114 } ) ;
103115 await ensureOk ( res ) ;
104116}
105117
106118/** DELETE /updates/{id} - remove update (204) */
107- export async function deleteUpdate ( baseUrl : string , id : string ) : Promise < void > {
108- const res = await fetch ( updatePath ( baseUrl , id ) , { method : 'DELETE' } ) ;
119+ export async function deleteUpdate ( baseUrl : string , id : string , signal ?: AbortSignal ) : Promise < void > {
120+ const res = await fetch ( updatePath ( baseUrl , id ) , { method : 'DELETE' , signal } ) ;
109121 await ensureOk ( res ) ;
110122}
0 commit comments