@@ -13,7 +13,6 @@ export async function listUnits(orgId: string, userId: string, email: string) {
1313 if ( ! response . ok ) {
1414 throw new Error ( `Failed to list units: ${ response . statusText } ` ) ;
1515 }
16-
1716 return response . json ( ) ;
1817}
1918
@@ -28,9 +27,135 @@ export async function getUnit(orgId: string, userId: string, email: string, unit
2827 'X-Email' : email ,
2928 } ,
3029 } ) ;
30+ if ( ! response . ok ) {
31+ throw new Error ( `Failed to get unit: ${ response . statusText } ` ) ;
32+ }
33+ return response . json ( ) ;
34+ }
35+
36+ export async function getUnitVersions ( orgId : string , userId : string , email : string , unitId : string ) {
37+ const response = await fetch ( `${ process . env . STATESMAN_BACKEND_URL } /internal/api/units/${ unitId } /versions` , {
38+ method : 'GET' ,
39+ headers : {
40+ 'Content-Type' : 'application/json' ,
41+ 'Authorization' : `Bearer ${ process . env . STATESMAN_BACKEND_WEBHOOK_SECRET } ` ,
42+ 'X-Org-ID' : orgId ,
43+ 'X-User-ID' : userId ,
44+ 'X-Email' : email ,
45+ } ,
46+ } ) ;
47+ if ( ! response . ok ) {
48+ throw new Error ( `Failed to get unit: ${ response . statusText } ` ) ;
49+ }
50+ return response . json ( ) ;
51+ }
52+
53+
54+ export async function lockUnit ( orgId : string , userId : string , email : string , unitId : string ) {
55+ const response = await fetch ( `${ process . env . STATESMAN_BACKEND_URL } /internal/api/units/${ unitId } /lock` , {
56+ method : 'POST' ,
57+ headers : {
58+ 'Content-Type' : 'application/json' ,
59+ 'Authorization' : `Bearer ${ process . env . STATESMAN_BACKEND_WEBHOOK_SECRET } ` ,
60+ 'X-Org-ID' : orgId ,
61+ 'X-User-ID' : userId ,
62+ 'X-Email' : email ,
63+ } ,
64+ } ) ;
65+ if ( ! response . ok ) {
66+ throw new Error ( `Failed to lock unit: ${ response . statusText } ` ) ;
67+ }
68+ return response . json ( ) ;
69+ }
70+
71+ export async function unlockUnit ( orgId : string , userId : string , email : string , unitId : string ) {
72+ const response = await fetch ( `${ process . env . STATESMAN_BACKEND_URL } /internal/api/units/${ unitId } /unlock` , {
73+ method : 'DELETE' ,
74+ headers : {
75+ 'Content-Type' : 'application/json' ,
76+ 'Authorization' : `Bearer ${ process . env . STATESMAN_BACKEND_WEBHOOK_SECRET } ` ,
77+ 'X-Org-ID' : orgId ,
78+ 'X-User-ID' : userId ,
79+ 'X-Email' : email ,
80+ } ,
81+ } ) ;
82+ if ( ! response . ok ) {
83+ throw new Error ( `Failed to unlock unit: ${ response . statusText } ` ) ;
84+ }
85+ return response . json ( ) ;
3186}
3287
33- export async function createUnit ( orgId : string , userId : string , email : string , unitId : string ) {
88+ export async function forcePushState ( orgId : string , userId : string , email : string , unitId : string , state : string ) {
89+ const response = await fetch ( `${ process . env . STATESMAN_BACKEND_URL } /internal/api/units/${ unitId } /upload` , {
90+ method : 'POST' ,
91+ headers : {
92+ 'Content-Type' : 'application/json' ,
93+ 'Authorization' : `Bearer ${ process . env . STATESMAN_BACKEND_WEBHOOK_SECRET } ` ,
94+ 'X-Org-ID' : orgId ,
95+ 'X-User-ID' : userId ,
96+ 'X-Email' : email ,
97+ } ,
98+ body : state ,
99+ } ) ;
100+ if ( ! response . ok ) {
101+ throw new Error ( `Failed to force push state: ${ response . statusText } ` ) ;
102+ }
103+ return response . json ( ) ;
104+ }
105+
106+ export async function downloadLatestState ( orgId : string , userId : string , email : string , unitId : string ) {
107+ const response = await fetch ( `${ process . env . STATESMAN_BACKEND_URL } /internal/api/units/${ unitId } /download` , {
108+ method : 'GET' ,
109+ headers : {
110+ 'Content-Type' : 'application/json' ,
111+ 'Authorization' : `Bearer ${ process . env . STATESMAN_BACKEND_WEBHOOK_SECRET } ` ,
112+ 'X-Org-ID' : orgId ,
113+ 'X-User-ID' : userId ,
114+ 'X-Email' : email ,
115+ } ,
116+ } ) ;
117+ return response . json ( )
118+ }
119+
120+ export async function restoreUnitStateVersion ( orgId : string , userId : string , email : string , unitId : string , timestamp : string , lockId : string ) {
121+ const response = await fetch ( `${ process . env . STATESMAN_BACKEND_URL } /internal/api/units/${ unitId } /restore` , {
122+ method : 'POST' ,
123+ headers : {
124+ 'Content-Type' : 'application/json' ,
125+ 'Authorization' : `Bearer ${ process . env . STATESMAN_BACKEND_WEBHOOK_SECRET } ` ,
126+ 'X-Org-ID' : orgId ,
127+ 'X-User-ID' : userId ,
128+ 'X-Email' : email ,
129+ } ,
130+ body : JSON . stringify ( {
131+ timestamp : timestamp ,
132+ lock_id : lockId ,
133+ } ) ,
134+ } ) ;
135+ if ( ! response . ok ) {
136+ throw new Error ( `Failed to restore unit state version: ${ response . statusText } ` ) ;
137+ }
138+ return response . json ( ) ;
139+ }
140+
141+ export async function getUnitStatus ( orgId : string , userId : string , email : string , unitId : string ) {
142+ const response = await fetch ( `${ process . env . STATESMAN_BACKEND_URL } /internal/api/units/${ unitId } /status` , {
143+ method : 'GET' ,
144+ headers : {
145+ 'Content-Type' : 'application/json' ,
146+ 'Authorization' : `Bearer ${ process . env . STATESMAN_BACKEND_WEBHOOK_SECRET } ` ,
147+ 'X-Org-ID' : orgId ,
148+ 'X-User-ID' : userId ,
149+ 'X-Email' : email ,
150+ } ,
151+ } ) ;
152+ if ( ! response . ok ) {
153+ throw new Error ( `Failed to get unit status: ${ response . statusText } ` ) ;
154+ }
155+ return response . json ( ) ;
156+ }
157+
158+ export async function createUnit ( orgId : string , userId : string , email : string , name : string ) {
34159 const response = await fetch ( `${ process . env . STATESMAN_BACKEND_URL } /internal/api/units` , {
35160 method : 'POST' ,
36161 headers : {
@@ -41,7 +166,7 @@ export async function createUnit(orgId: string, userId: string, email: string, u
41166 'X-Email' : email ,
42167 } ,
43168 body : JSON . stringify ( {
44- id : unitId ,
169+ name : name ,
45170 } ) ,
46171 } ) ;
47172 console . log ( response )
@@ -50,4 +175,21 @@ export async function createUnit(orgId: string, userId: string, email: string, u
50175 }
51176
52177 return response . json ( ) ;
178+ }
179+
180+ export async function deleteUnit ( orgId : string , userId : string , email : string , unitId : string ) {
181+ const response = await fetch ( `${ process . env . STATESMAN_BACKEND_URL } /internal/api/units/${ unitId } ` , {
182+ method : 'DELETE' ,
183+ headers : {
184+ 'Content-Type' : 'application/json' ,
185+ 'Authorization' : `Bearer ${ process . env . STATESMAN_BACKEND_WEBHOOK_SECRET } ` ,
186+ 'X-Org-ID' : orgId ,
187+ 'X-User-ID' : userId ,
188+ 'X-Email' : email ,
189+ } ,
190+ } ) ;
191+ if ( ! response . ok ) {
192+ throw new Error ( `Failed to delete unit: ${ response . statusText } ` ) ;
193+ }
194+
53195}
0 commit comments