@qaick/http-executor 0.1.0-alpha.4 → 0.1.0-alpha.5

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
+ /** Host-owned cookies that already exist before a QAick execution starts. */
17
+ export type HttpAmbientCookieProvider = (url: string) => Promise<string | undefined>;
16
18
  /** Internal Runtime-to-HTTP execution key. It is not part of persisted Action data. */
17
19
  export declare const HTTP_EXECUTION_ID_KEY = "__qaick_execution_id";
18
20
  export interface HttpCookie {
@@ -34,7 +36,8 @@ export declare class HttpCookieJar {
34
36
  export declare class HttpExecutionSession implements HttpTransport {
35
37
  private readonly transport;
36
38
  readonly cookies: HttpCookieJar;
37
- constructor(transport: HttpTransport, cookies?: HttpCookieJar);
39
+ private readonly ambientCookies?;
40
+ constructor(transport: HttpTransport, cookies?: HttpCookieJar, ambientCookies?: HttpAmbientCookieProvider | undefined);
38
41
  request(url: string, init: {
39
42
  method: string;
40
43
  body?: unknown;
@@ -39,9 +39,11 @@ export class HttpCookieJar {
39
39
  export class HttpExecutionSession {
40
40
  transport;
41
41
  cookies;
42
- constructor(transport, cookies = new HttpCookieJar()) {
42
+ ambientCookies;
43
+ constructor(transport, cookies = new HttpCookieJar(), ambientCookies) {
43
44
  this.transport = transport;
44
45
  this.cookies = cookies;
46
+ this.ambientCookies = ambientCookies;
45
47
  }
46
48
  async request(url, init) {
47
49
  let currentUrl = url;
@@ -50,7 +52,8 @@ export class HttpExecutionSession {
50
52
  const headers = { ...(currentInit.headers ?? {}) };
51
53
  const cookieHeader = headerName(headers, 'cookie');
52
54
  const managed = this.cookies.header(currentUrl);
53
- const merged = mergeCookieHeaders(cookieHeader ? headers[cookieHeader] : undefined, managed);
55
+ const ambient = this.ambientCookies ? await this.ambientCookies(currentUrl).catch(() => undefined) : undefined;
56
+ const merged = mergeCookieHeaders(cookieHeader ? headers[cookieHeader] : undefined, managed, ambient);
54
57
  if (merged)
55
58
  headers[cookieHeader ?? 'cookie'] = merged;
56
59
  const response = await this.transport.request(currentUrl, { ...currentInit, headers });
@@ -89,9 +92,9 @@ function headerValue(headers, expected) {
89
92
  return name ? headers[name] : undefined;
90
93
  }
91
94
  function isRedirect(status) { return status === 301 || status === 302 || status === 303 || status === 307 || status === 308; }
92
- function mergeCookieHeaders(explicit, managed) {
95
+ function mergeCookieHeaders(explicit, managed, ambient) {
93
96
  const cookies = new Map();
94
- for (const value of [managed, explicit]) {
97
+ for (const value of [ambient, managed, explicit]) {
95
98
  for (const item of value?.split(';') ?? []) {
96
99
  const separator = item.indexOf('=');
97
100
  if (separator <= 0)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@qaick/http-executor",
3
- "version": "0.1.0-alpha.4",
3
+ "version": "0.1.0-alpha.5",
4
4
  "description": "Reusable QAick HTTP Action execution with browser and native Node transports.",
5
5
  "keywords": [
6
6
  "qaick",