@qaick/http-executor 0.1.0-alpha.2 → 0.1.0-alpha.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -13,6 +13,8 @@ export interface HttpTransport {
|
|
|
13
13
|
timeoutMs?: number;
|
|
14
14
|
}): Promise<HttpResponse>;
|
|
15
15
|
}
|
|
16
|
+
/** Internal Runtime-to-HTTP execution key. It is not part of persisted Action data. */
|
|
17
|
+
export declare const HTTP_EXECUTION_ID_KEY = "__qaick_execution_id";
|
|
16
18
|
export interface HttpCookie {
|
|
17
19
|
name: string;
|
|
18
20
|
value: string;
|
|
@@ -58,7 +60,9 @@ export declare class FetchHttpTransport implements HttpTransport {
|
|
|
58
60
|
}
|
|
59
61
|
export declare class HttpActionExecutor implements ActionExecutor {
|
|
60
62
|
private readonly transport;
|
|
63
|
+
private readonly sessions;
|
|
61
64
|
constructor(transport: HttpTransport);
|
|
62
65
|
supports(action: string): boolean;
|
|
63
66
|
execute(context: ActionExecutionContext): Promise<ActionExecutionResult>;
|
|
67
|
+
private sessionFor;
|
|
64
68
|
}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
/** Internal Runtime-to-HTTP execution key. It is not part of persisted Action data. */
|
|
2
|
+
export const HTTP_EXECUTION_ID_KEY = '__qaick_execution_id';
|
|
1
3
|
/** Cookie state shared by HTTP Actions during one execution. */
|
|
2
4
|
export class HttpCookieJar {
|
|
3
5
|
cookies = new Map();
|
|
@@ -187,6 +189,7 @@ export class FetchHttpTransport {
|
|
|
187
189
|
}
|
|
188
190
|
export class HttpActionExecutor {
|
|
189
191
|
transport;
|
|
192
|
+
sessions = new Map();
|
|
190
193
|
constructor(transport) {
|
|
191
194
|
this.transport = transport;
|
|
192
195
|
}
|
|
@@ -209,7 +212,9 @@ export class HttpActionExecutor {
|
|
|
209
212
|
throw new HttpActionError('HTTP_REQUEST_CONSTRUCTION_ERROR', `HTTP Action request could not be constructed. ${detail}`);
|
|
210
213
|
}
|
|
211
214
|
const timeoutMs = typeof context.step.adapterConfig?.timeoutMs === 'number' ? context.step.adapterConfig.timeoutMs : undefined;
|
|
212
|
-
const
|
|
215
|
+
const executionId = typeof context.runtimeValues[HTTP_EXECUTION_ID_KEY] === 'string' ? context.runtimeValues[HTTP_EXECUTION_ID_KEY] : undefined;
|
|
216
|
+
const transport = executionId ? this.sessionFor(executionId) : this.transport;
|
|
217
|
+
const response = await transport.request(request.url, { ...request, signal: context.signal, ...(timeoutMs !== undefined ? { timeoutMs } : {}) });
|
|
213
218
|
if (response.status < 200 || response.status >= 300) {
|
|
214
219
|
const serializedBody = typeof response.body === 'string' ? response.body : JSON.stringify(response.body) ?? '';
|
|
215
220
|
throw new HttpActionError('HTTP_STATUS_ERROR', `HTTP Action returned status ${response.status}.${serializedBody ? ` Response: ${serializedBody.slice(0, 500)}` : ''}`, { status: response.status });
|
|
@@ -225,6 +230,14 @@ export class HttpActionExecutor {
|
|
|
225
230
|
const finishedAt = new Date().toISOString();
|
|
226
231
|
return { outputs, evidence: { request: { url: request.url, method: request.method, headers: request.headers }, response: { status: response.status, headers: response.headers, body: response.body } }, timing: { startedAt, finishedAt, durationMs: Date.now() - startedMs } };
|
|
227
232
|
}
|
|
233
|
+
sessionFor(executionId) {
|
|
234
|
+
let session = this.sessions.get(executionId);
|
|
235
|
+
if (!session) {
|
|
236
|
+
session = new HttpExecutionSession(this.transport);
|
|
237
|
+
this.sessions.set(executionId, session);
|
|
238
|
+
}
|
|
239
|
+
return session;
|
|
240
|
+
}
|
|
228
241
|
}
|
|
229
242
|
function appendQuery(url, query) {
|
|
230
243
|
if (query === undefined || query === null)
|