From a1e3383a3cbaa000d2487c28560fdc6a4bc63612 Mon Sep 17 00:00:00 2001 From: alvaro Date: Wed, 29 Oct 2025 18:14:54 +0100 Subject: [PATCH] Enrich executeProcessSync response with executionId --- src/api/types.ts | 4 +++ src/api/yepcodeApi.ts | 61 ++++++++++++++++++++++++++++--------------- 2 files changed, 44 insertions(+), 21 deletions(-) diff --git a/src/api/types.ts b/src/api/types.ts index 5853059..74b03d8 100644 --- a/src/api/types.ts +++ b/src/api/types.ts @@ -82,6 +82,10 @@ export interface Execution { export interface ExecutionId { executionId: string; } +export interface ExecuteProcessSyncResponse { + executionId: string; + data: any; +} export interface ExecutionLogsPaginatedResult { hasNextPage?: boolean; page?: number; diff --git a/src/api/yepcodeApi.ts b/src/api/yepcodeApi.ts index 3b6074d..aa45c35 100644 --- a/src/api/yepcodeApi.ts +++ b/src/api/yepcodeApi.ts @@ -8,6 +8,7 @@ import { ExecutionsPaginatedResult, Execution, ExecutionLogsPaginatedResult, + ExecuteProcessSyncResponse, Schedule, ScheduledProcessInput, SchedulesPaginatedResult, @@ -232,11 +233,16 @@ export class YepCodeApi { return date as string; } - private async request( + private async request( method: string, endpoint: string, - options: RequestOptions = {} - ): Promise { + options: RequestOptions = {}, + settings: { + includeHeaders?: boolean; + } = { + includeHeaders: false, + } + ): Promise { if (!this.accessToken || this.isAccessTokenExpired(this.accessToken)) { await this.getAccessToken(); } @@ -297,17 +303,24 @@ export class YepCodeApi { if (options.responseType === "stream") { if (typeof response.body?.getReader === "function") { // @ts-ignore - return Readable.fromWeb(response.body) as T; + return Readable.fromWeb(response.body); } // @ts-ignore - return response.body as T; + return response.body; } const responseText = await response.text(); try { - return JSON.parse(responseText); + const data = JSON.parse(responseText); + if (settings.includeHeaders) { + return { + data, + headers: response.headers, + }; + } + return data; } catch (e) { - return responseText as T; + return responseText; } } @@ -452,21 +465,31 @@ export class YepCodeApi { comment?: string; settings?: any; } = {} - ): Promise { + ): Promise { const headers: Record = {}; if (options.initiatedBy) { headers["Yep-Initiated-By"] = options.initiatedBy; } - return this.request("POST", `/processes/${processIdOrSlug}/execute-sync`, { - data: { - parameters: JSON.stringify(parameters), - tag: options.tag, - comment: options.comment, - settings: options.settings, + const { data, headers: responseHeaders } = await this.request( + "POST", + `/processes/${processIdOrSlug}/execute-sync`, + { + data: { + parameters: JSON.stringify(parameters), + tag: options.tag, + comment: options.comment, + settings: options.settings, + }, + headers, }, - headers, - }); + { includeHeaders: true } + ); + + return { + executionId: responseHeaders.get("yep-execution-id"), + data, + }; } async createSchedule( @@ -518,11 +541,7 @@ export class YepCodeApi { } async rerunExecution(id: string): Promise { - const response = await this.request<{ executionId: string }>( - "POST", - `/executions/${id}/rerun` - ); - return response.executionId; + return this.request("POST", `/executions/${id}/rerun`); } async killExecution(id: string): Promise {