|
8 | 8 | ExecutionsPaginatedResult, |
9 | 9 | Execution, |
10 | 10 | ExecutionLogsPaginatedResult, |
| 11 | + ExecuteProcessSyncResponse, |
11 | 12 | Schedule, |
12 | 13 | ScheduledProcessInput, |
13 | 14 | SchedulesPaginatedResult, |
@@ -232,11 +233,16 @@ export class YepCodeApi { |
232 | 233 | return date as string; |
233 | 234 | } |
234 | 235 |
|
235 | | - private async request<T>( |
| 236 | + private async request( |
236 | 237 | method: string, |
237 | 238 | endpoint: string, |
238 | | - options: RequestOptions = {} |
239 | | - ): Promise<T> { |
| 239 | + options: RequestOptions = {}, |
| 240 | + settings: { |
| 241 | + includeHeaders?: boolean; |
| 242 | + } = { |
| 243 | + includeHeaders: false, |
| 244 | + } |
| 245 | + ): Promise<any> { |
240 | 246 | if (!this.accessToken || this.isAccessTokenExpired(this.accessToken)) { |
241 | 247 | await this.getAccessToken(); |
242 | 248 | } |
@@ -297,17 +303,24 @@ export class YepCodeApi { |
297 | 303 | if (options.responseType === "stream") { |
298 | 304 | if (typeof response.body?.getReader === "function") { |
299 | 305 | // @ts-ignore |
300 | | - return Readable.fromWeb(response.body) as T; |
| 306 | + return Readable.fromWeb(response.body); |
301 | 307 | } |
302 | 308 | // @ts-ignore |
303 | | - return response.body as T; |
| 309 | + return response.body; |
304 | 310 | } |
305 | 311 |
|
306 | 312 | const responseText = await response.text(); |
307 | 313 | try { |
308 | | - return JSON.parse(responseText); |
| 314 | + const data = JSON.parse(responseText); |
| 315 | + if (settings.includeHeaders) { |
| 316 | + return { |
| 317 | + data, |
| 318 | + headers: response.headers, |
| 319 | + }; |
| 320 | + } |
| 321 | + return data; |
309 | 322 | } catch (e) { |
310 | | - return responseText as T; |
| 323 | + return responseText; |
311 | 324 | } |
312 | 325 | } |
313 | 326 |
|
@@ -452,21 +465,31 @@ export class YepCodeApi { |
452 | 465 | comment?: string; |
453 | 466 | settings?: any; |
454 | 467 | } = {} |
455 | | - ): Promise<any> { |
| 468 | + ): Promise<ExecuteProcessSyncResponse> { |
456 | 469 | const headers: Record<string, string> = {}; |
457 | 470 | if (options.initiatedBy) { |
458 | 471 | headers["Yep-Initiated-By"] = options.initiatedBy; |
459 | 472 | } |
460 | 473 |
|
461 | | - return this.request("POST", `/processes/${processIdOrSlug}/execute-sync`, { |
462 | | - data: { |
463 | | - parameters: JSON.stringify(parameters), |
464 | | - tag: options.tag, |
465 | | - comment: options.comment, |
466 | | - settings: options.settings, |
| 474 | + const { data, headers: responseHeaders } = await this.request( |
| 475 | + "POST", |
| 476 | + `/processes/${processIdOrSlug}/execute-sync`, |
| 477 | + { |
| 478 | + data: { |
| 479 | + parameters: JSON.stringify(parameters), |
| 480 | + tag: options.tag, |
| 481 | + comment: options.comment, |
| 482 | + settings: options.settings, |
| 483 | + }, |
| 484 | + headers, |
467 | 485 | }, |
468 | | - headers, |
469 | | - }); |
| 486 | + { includeHeaders: true } |
| 487 | + ); |
| 488 | + |
| 489 | + return { |
| 490 | + executionId: responseHeaders.get("yep-execution-id"), |
| 491 | + data, |
| 492 | + }; |
470 | 493 | } |
471 | 494 |
|
472 | 495 | async createSchedule( |
@@ -518,11 +541,7 @@ export class YepCodeApi { |
518 | 541 | } |
519 | 542 |
|
520 | 543 | async rerunExecution(id: string): Promise<string> { |
521 | | - const response = await this.request<{ executionId: string }>( |
522 | | - "POST", |
523 | | - `/executions/${id}/rerun` |
524 | | - ); |
525 | | - return response.executionId; |
| 544 | + return this.request("POST", `/executions/${id}/rerun`); |
526 | 545 | } |
527 | 546 |
|
528 | 547 | async killExecution(id: string): Promise<void> { |
|
0 commit comments