fix: share integration transport and enforce access

This commit is contained in:
ajnart committed 2026-09-12 20:26:39 +02:00
1 parent 52c82f72db
commit c2a587bda7
16 files changed
+284 -117

No files matched your search

@@ -1,9 +1,10 @@
import { Buffer } from "node:buffer";
import { STATUS_CODES } from "node:http";
import type { ConnectionOptions } from "node:tls";
import { Headers, Response } from "undici";
import type { CustomJsxNetworkScope, CustomWidgetMethod } from "../core";
import type { CustomWidgetMethod } from "../core";
import type { CustomWidgetHttpRequest, CustomWidgetHttpResponse } from "./request-types";
export type { CustomWidgetAuthConfig, CustomWidgetHttpRequest, CustomWidgetHttpResponse } from "./request-types";
import { applyAuth } from "./auth";
import { CustomWidgetDomainError } from "./errors";
import {
@@ -16,6 +17,7 @@ import {
} from "./network-policy";
import { closeDispatcher } from "./request-dispatcher-lifecycle";
import { parseResponseBody } from "./response";
import { redactResponseSecrets } from "./response-redaction";
export {
assertSafeStaticHeaders,
@@ -39,34 +41,6 @@ export const MAX_REQUEST_DURATION_MS = 45_000;
const TIMEOUT_ERROR_CODES = new Set(["UND_ERR_CONNECT_TIMEOUT", "UND_ERR_HEADERS_TIMEOUT", "UND_ERR_BODY_TIMEOUT"]);
const RESPONSE_TOO_LARGE_ERROR_CODE = "UND_ERR_RES_EXCEEDED_MAX_SIZE";
export interface CustomWidgetAuthConfig {
type: string;
secrets: Array<{ kind: string; value: string }>;
headerName?: string | null;
}
export interface CustomWidgetHttpRequest {
tls?: Pick<ConnectionOptions, "ca" | "checkServerIdentity">;
pathPrefix?: string;
baseUrl: string;
targetUrl?: string | URL;
method: CustomWidgetMethod;
body?: string;
staticHeaders?: Record<string, string>;
auth?: CustomWidgetAuthConfig;
networkScope: CustomJsxNetworkScope;
kind: "query" | "action";
cacheKey?: string;
cacheTtlSeconds?: number;
logError?: (event: { origin: string; method: CustomWidgetMethod; errorName: string; reason?: "timeout" }) => void;
}
export interface CustomWidgetHttpResponse {
ok: boolean;
status: number;
statusText: string;
data: unknown;
}
const cache = new Map<string, { expiresAt: number; response: CustomWidgetHttpResponse }>();
const inFlight = new Map<string, Promise<CustomWidgetHttpResponse>>();
let cacheEpoch = 0;
@@ -147,7 +121,7 @@ async function performRequestWithinDeadline(
ok: response.ok,
status: response.status,
statusText: response.statusText,
data: await parseResponseBody(response),
data: redactResponseSecrets(await parseResponseBody(response), input.redactSecrets ?? []),
},
};
} else {