From ae2064f46f6ca37a1a33dbee1c90f36045ebe2da Mon Sep 17 00:00:00 2001 From: sjones Date: Tue, 9 Dec 2025 20:22:08 -0800 Subject: [PATCH 1/4] add http2SessionOptions to ServiceConfig --- src/authorizer/index.ts | 7 ++++++- src/directory/index.ts | 11 ++++++++--- src/directory/types.ts | 2 ++ tests/directory/v3/index.test.ts | 14 ++++++++++++++ 4 files changed, 30 insertions(+), 4 deletions(-) diff --git a/src/authorizer/index.ts b/src/authorizer/index.ts index f5ab282..76fb54a 100644 --- a/src/authorizer/index.ts +++ b/src/authorizer/index.ts @@ -30,7 +30,10 @@ import { createClient, Interceptor, } from "@connectrpc/connect"; -import { createGrpcTransport } from "@connectrpc/connect-node"; +import { + createGrpcTransport, + Http2SessionOptions, +} from "@connectrpc/connect-node"; import { handleError, setHeader, traceMessage } from "../util/connect"; import { TopazRegistry } from "../util/serializer"; @@ -65,6 +68,7 @@ type AuthorizerConfig = { caFile?: string; insecure?: boolean; customHeaders?: { [key: string]: unknown }; + http2SessionOptions?: Http2SessionOptions; }; type Path = { @@ -104,6 +108,7 @@ export class Authorizer { baseUrl: serviceUrl, interceptors: interceptors, nodeOptions: baseNodeOptions, + ...config?.http2SessionOptions, }); this.AuthClient = createClient(AuthorizerClient, baseGrpcTransport); diff --git a/src/directory/index.ts b/src/directory/index.ts index 4a8f92c..41dc93a 100644 --- a/src/directory/index.ts +++ b/src/directory/index.ts @@ -206,12 +206,15 @@ export class Directory { const nodeOptions = createNodeOptions(config); let customHeaders = Object.assign({}, fallback?.customHeaders || {}); customHeaders = Object.assign(customHeaders, config?.customHeaders || {}); + const http2SessionOptions = + config?.http2SessionOptions || fallback?.http2SessionOptions; if ( serviceUrl !== baseServiceUrl || apiKey !== baseApiKey || tenantId !== baseTenantId || - nodeOptions !== baseNodeOptions + nodeOptions !== baseNodeOptions || + http2SessionOptions !== baseHttp2SessionOptions ) { const interceptors = [createHeadersInterceptor(apiKey, tenantId)]; if (process.env.NODE_TRACE_MESSAGE) { @@ -222,6 +225,7 @@ export class Directory { baseUrl: serviceUrl || "https://localhost:9292", interceptors: interceptors, nodeOptions: nodeOptions, + ...config?.http2SessionOptions, }); } return baseGrpcTransport; @@ -241,9 +245,9 @@ export class Directory { } const baseServiceUrl = config.url; - const baseApiKey = config.apiKey; const baseTenantId = config.tenantId; + const baseHttp2SessionOptions = config.http2SessionOptions; const baseCaFile = !!config.caFile ? readFileSync(config.caFile) : undefined; @@ -260,9 +264,10 @@ export class Directory { const baseGrpcTransport = !!config.url || (!!config.apiKey && !!config.tenantId) ? createGrpcTransport({ - baseUrl: baseServiceUrl || "https://localhost:9292", + baseUrl: config.url || "https://localhost:9292", interceptors: interceptors, nodeOptions: baseNodeOptions, + ...config?.http2SessionOptions, }) : undefined; diff --git a/src/directory/types.ts b/src/directory/types.ts index 103f52c..06124c3 100644 --- a/src/directory/types.ts +++ b/src/directory/types.ts @@ -56,6 +56,7 @@ import { Registry, } from "@bufbuild/protobuf"; import { Timestamp } from "@bufbuild/protobuf/wkt"; +import { Http2SessionOptions } from "@connectrpc/connect-node"; import { NestedOmit, NestedOptional, Optional } from "../util/types"; @@ -276,6 +277,7 @@ export type ServiceConfig = { caFile?: string; insecure?: boolean; customHeaders?: CustomHeaders; + http2SessionOptions?: Http2SessionOptions; }; export type SetManifestResponse = Omit< SetManifestResponse$, diff --git a/tests/directory/v3/index.test.ts b/tests/directory/v3/index.test.ts index 3481f9e..b85e394 100644 --- a/tests/directory/v3/index.test.ts +++ b/tests/directory/v3/index.test.ts @@ -48,6 +48,7 @@ describe("Directory", () => { customHeaders: { foo: "bar", }, + idleConnectionTimeoutMs: 60000, }; const directory = new Directory(config); @@ -75,6 +76,7 @@ describe("Directory", () => { customHeaders: { base: "bar", }, + idleConnectionTimeoutMs: 60000, reader: { url: "https://readerUrl", apiKey: "readerApiKey", @@ -83,6 +85,7 @@ describe("Directory", () => { customHeaders: { reader: "bar", }, + idleConnectionTimeoutMs: 60000, }, writer: { url: "https://writerUrl", @@ -91,19 +94,23 @@ describe("Directory", () => { customHeaders: { writer: "bar", }, + idleConnectionTimeoutMs: 60000, }, importer: { url: "https://importerUrl", apiKey: "importerApiKey", tenantId: "importerTenantId", + idleConnectionTimeoutMs: 60000, }, exporter: { caFile: "exporterCaFile", customHeaders: {}, + idleConnectionTimeoutMs: 60000, }, model: { apiKey: "modelApiKey", tenantId: "modelTenantId", + idleConnectionTimeoutMs: 60000, }, rejectUnauthorized: true, }; @@ -119,6 +126,7 @@ describe("Directory", () => { ca: "caFile", rejectUnauthorized: true, }, + idleConnectionTimeoutMs: 60000, }), ], [ @@ -129,6 +137,7 @@ describe("Directory", () => { ca: "readerCaFile", rejectUnauthorized: true, }, + idleConnectionTimeoutMs: 60000, }), ], [ @@ -139,6 +148,7 @@ describe("Directory", () => { ca: "caFile", rejectUnauthorized: true, }, + idleConnectionTimeoutMs: 60000, }), ], [ @@ -149,6 +159,7 @@ describe("Directory", () => { ca: "caFile", rejectUnauthorized: true, }, + idleConnectionTimeoutMs: 60000, }), ], [ @@ -159,6 +170,7 @@ describe("Directory", () => { ca: "exporterCaFile", rejectUnauthorized: true, }, + idleConnectionTimeoutMs: 60000, }), ], [ @@ -169,6 +181,7 @@ describe("Directory", () => { ca: "caFile", rejectUnauthorized: true, }, + idleConnectionTimeoutMs: 60000, }), ], ]); @@ -189,6 +202,7 @@ describe("Directory", () => { url: "localhost:9292", tenantId: "tenantId", apiKey: "apiKey", + idleConnectionTimeoutMs: 60000, reader: { url: "readerUrl", apiKey: "readerApiKey", From c67e10a887c671e5b40c47ff47da4485e533f629 Mon Sep 17 00:00:00 2001 From: sjones Date: Fri, 12 Dec 2025 10:21:20 -0800 Subject: [PATCH 2/4] revert baseServiceUrl change --- src/directory/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/directory/index.ts b/src/directory/index.ts index 41dc93a..d20b3b1 100644 --- a/src/directory/index.ts +++ b/src/directory/index.ts @@ -264,7 +264,7 @@ export class Directory { const baseGrpcTransport = !!config.url || (!!config.apiKey && !!config.tenantId) ? createGrpcTransport({ - baseUrl: config.url || "https://localhost:9292", + baseUrl: baseServiceUrl || "https://localhost:9292", interceptors: interceptors, nodeOptions: baseNodeOptions, ...config?.http2SessionOptions, From 70be617f2680c84c8db8b0b2f7de268143bafcba Mon Sep 17 00:00:00 2001 From: sjones Date: Fri, 12 Dec 2025 11:28:43 -0800 Subject: [PATCH 3/4] fix tests --- src/directory/index.ts | 4 ++-- tests/directory/v3/index.test.ts | 27 ++++++++++++++++++++------- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/src/directory/index.ts b/src/directory/index.ts index d20b3b1..cf6aa6e 100644 --- a/src/directory/index.ts +++ b/src/directory/index.ts @@ -225,7 +225,7 @@ export class Directory { baseUrl: serviceUrl || "https://localhost:9292", interceptors: interceptors, nodeOptions: nodeOptions, - ...config?.http2SessionOptions, + ...http2SessionOptions, }); } return baseGrpcTransport; @@ -267,7 +267,7 @@ export class Directory { baseUrl: baseServiceUrl || "https://localhost:9292", interceptors: interceptors, nodeOptions: baseNodeOptions, - ...config?.http2SessionOptions, + ...baseHttp2SessionOptions, }) : undefined; diff --git a/tests/directory/v3/index.test.ts b/tests/directory/v3/index.test.ts index b85e394..b1f3e6c 100644 --- a/tests/directory/v3/index.test.ts +++ b/tests/directory/v3/index.test.ts @@ -26,6 +26,7 @@ import { ImportResponseSchema, InvalidArgumentError, NotFoundError, + ServiceConfig, SetManifestResponseSchema, SetObjectResponseSchema, SetRelationResponseSchema, @@ -68,7 +69,7 @@ describe("Directory", () => { return path as string; }); - const config = { + const config: ServiceConfig = { url: "https://localhost:9292", tenantId: "tenantId", apiKey: "apiKey", @@ -76,7 +77,9 @@ describe("Directory", () => { customHeaders: { base: "bar", }, - idleConnectionTimeoutMs: 60000, + http2SessionOptions: { + idleConnectionTimeoutMs: 60000, + }, reader: { url: "https://readerUrl", apiKey: "readerApiKey", @@ -85,7 +88,9 @@ describe("Directory", () => { customHeaders: { reader: "bar", }, - idleConnectionTimeoutMs: 60000, + http2SessionOptions: { + idleConnectionTimeoutMs: 60000, + }, }, writer: { url: "https://writerUrl", @@ -94,23 +99,31 @@ describe("Directory", () => { customHeaders: { writer: "bar", }, - idleConnectionTimeoutMs: 60000, + http2SessionOptions: { + idleConnectionTimeoutMs: 60000, + }, }, importer: { url: "https://importerUrl", apiKey: "importerApiKey", tenantId: "importerTenantId", - idleConnectionTimeoutMs: 60000, + http2SessionOptions: { + idleConnectionTimeoutMs: 60000, + }, }, exporter: { caFile: "exporterCaFile", customHeaders: {}, - idleConnectionTimeoutMs: 60000, + http2SessionOptions: { + idleConnectionTimeoutMs: 60000, + }, }, model: { apiKey: "modelApiKey", tenantId: "modelTenantId", - idleConnectionTimeoutMs: 60000, + http2SessionOptions: { + idleConnectionTimeoutMs: 60000, + }, }, rejectUnauthorized: true, }; From 2490fa8aa6916b3be57eb73733f82bbd92de0785 Mon Sep 17 00:00:00 2001 From: sjones Date: Fri, 12 Dec 2025 11:50:26 -0800 Subject: [PATCH 4/4] fix test --- tests/directory/v3/index.test.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/directory/v3/index.test.ts b/tests/directory/v3/index.test.ts index b1f3e6c..95fdb84 100644 --- a/tests/directory/v3/index.test.ts +++ b/tests/directory/v3/index.test.ts @@ -14,6 +14,7 @@ import { DeleteObjectResponseSchema, DeleteRelationResponseSchema, Directory, + DirectoryConfig, EtagMismatchError, ExportResponseSchema, GetGraphResponseSchema, @@ -26,7 +27,6 @@ import { ImportResponseSchema, InvalidArgumentError, NotFoundError, - ServiceConfig, SetManifestResponseSchema, SetObjectResponseSchema, SetRelationResponseSchema, @@ -69,7 +69,7 @@ describe("Directory", () => { return path as string; }); - const config: ServiceConfig = { + const config: DirectoryConfig = { url: "https://localhost:9292", tenantId: "tenantId", apiKey: "apiKey", @@ -125,7 +125,7 @@ describe("Directory", () => { idleConnectionTimeoutMs: 60000, }, }, - rejectUnauthorized: true, + insecure: false, }; const directory = new Directory(config);