@@ -20,13 +20,13 @@ type WorkloadHttpClientOptions = WorkloadClientCommonOptions;
2020
2121export class WorkloadHttpClient {
2222 private apiUrl : string ;
23+ private runnerId : string ;
2324 private readonly deploymentId : string ;
24- private readonly defaultHeaders : Record < string , string > ;
2525
26- constructor ( opts : WorkloadHttpClientOptions ) {
26+ constructor ( private opts : WorkloadHttpClientOptions ) {
2727 this . apiUrl = opts . workerApiUrl . replace ( / \/ $ / , "" ) ;
28- this . defaultHeaders = getDefaultWorkloadHeaders ( opts ) ;
2928 this . deploymentId = opts . deploymentId ;
29+ this . runnerId = opts . runnerId ;
3030
3131 if ( ! this . apiUrl ) {
3232 throw new Error ( "apiURL is required and needs to be a non-empty string" ) ;
@@ -41,14 +41,25 @@ export class WorkloadHttpClient {
4141 this . apiUrl = apiUrl . replace ( / \/ $ / , "" ) ;
4242 }
4343
44+ updateRunnerId ( runnerId : string ) {
45+ this . runnerId = runnerId ;
46+ }
47+
48+ defaultHeaders ( ) : Record < string , string > {
49+ return getDefaultWorkloadHeaders ( {
50+ ...this . opts ,
51+ runnerId : this . runnerId ,
52+ } ) ;
53+ }
54+
4455 async heartbeatRun ( runId : string , snapshotId : string , body ?: WorkloadHeartbeatRequestBody ) {
4556 return wrapZodFetch (
4657 WorkloadHeartbeatResponseBody ,
4758 `${ this . apiUrl } /api/v1/workload-actions/runs/${ runId } /snapshots/${ snapshotId } /heartbeat` ,
4859 {
4960 method : "POST" ,
5061 headers : {
51- ...this . defaultHeaders ,
62+ ...this . defaultHeaders ( ) ,
5263 "Content-Type" : "application/json" ,
5364 } ,
5465 body : JSON . stringify ( body ?? { } ) ,
@@ -63,7 +74,7 @@ export class WorkloadHttpClient {
6374 {
6475 method : "GET" ,
6576 headers : {
66- ...this . defaultHeaders ,
77+ ...this . defaultHeaders ( ) ,
6778 } ,
6879 }
6980 ) ;
@@ -76,7 +87,7 @@ export class WorkloadHttpClient {
7687 {
7788 method : "GET" ,
7889 headers : {
79- ...this . defaultHeaders ,
90+ ...this . defaultHeaders ( ) ,
8091 } ,
8192 }
8293 ) ;
@@ -93,7 +104,7 @@ export class WorkloadHttpClient {
93104 {
94105 method : "POST" ,
95106 headers : {
96- ...this . defaultHeaders ,
107+ ...this . defaultHeaders ( ) ,
97108 } ,
98109 body : JSON . stringify ( body ) ,
99110 }
@@ -111,7 +122,7 @@ export class WorkloadHttpClient {
111122 {
112123 method : "POST" ,
113124 headers : {
114- ...this . defaultHeaders ,
125+ ...this . defaultHeaders ( ) ,
115126 } ,
116127 body : JSON . stringify ( body ) ,
117128 }
@@ -125,7 +136,7 @@ export class WorkloadHttpClient {
125136 {
126137 method : "GET" ,
127138 headers : {
128- ...this . defaultHeaders ,
139+ ...this . defaultHeaders ( ) ,
129140 } ,
130141 }
131142 ) ;
@@ -139,7 +150,7 @@ export class WorkloadHttpClient {
139150 {
140151 method : "POST" ,
141152 headers : {
142- ...this . defaultHeaders ,
153+ ...this . defaultHeaders ( ) ,
143154 "Content-Type" : "application/json" ,
144155 } ,
145156 body : JSON . stringify ( body ) ,
@@ -161,7 +172,7 @@ export class WorkloadHttpClient {
161172 {
162173 method : "GET" ,
163174 headers : {
164- ...this . defaultHeaders ,
175+ ...this . defaultHeaders ( ) ,
165176 } ,
166177 }
167178 ) ;
0 commit comments