From ff6981db634363823b864aa513888d29948a6a5a Mon Sep 17 00:00:00 2001 From: TensorNull Date: Wed, 29 Jul 2026 12:59:22 +0800 Subject: [PATCH] fix: snapshot supported client options once --- src/client.ts | 32 +++++++++++++++++++------------- tests/config.test.ts | 2 +- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/src/client.ts b/src/client.ts index 8023ef1..17a641c 100644 --- a/src/client.ts +++ b/src/client.ts @@ -12,26 +12,32 @@ type UnsupportedCometAPIOption = (typeof UNSUPPORTED_COMETAPI_OPTIONS)[number]; function sanitizeOptions>( options: T, ): Omit { - const { - provider, - workloadIdentity, - dangerouslyAllowBrowser, - ...supportedOptions - } = options; - const unsupportedOptions = { - provider, - workloadIdentity, - dangerouslyAllowBrowser, - }; - for (const option of UNSUPPORTED_COMETAPI_OPTIONS) { - if (unsupportedOptions[option] !== undefined) { + if (Reflect.get(options, option) !== undefined) { throw new OpenAIError( `The \`${option}\` option is not supported by CometAPI.`, ); } } + const supportedOptions = {} as Omit; + for (const option of Reflect.ownKeys(options)) { + if ( + UNSUPPORTED_COMETAPI_OPTIONS.includes( + option as UnsupportedCometAPIOption, + ) || + !Object.prototype.propertyIsEnumerable.call(options, option) + ) { + continue; + } + Object.defineProperty(supportedOptions, option, { + configurable: true, + enumerable: true, + value: Reflect.get(options, option), + writable: true, + }); + } + return supportedOptions; } diff --git a/tests/config.test.ts b/tests/config.test.ts index bebcddd..593194e 100644 --- a/tests/config.test.ts +++ b/tests/config.test.ts @@ -309,7 +309,7 @@ describe("CometAPI configuration", () => { options as unknown as CometAPIOptions, ); - expect(reads).toBeGreaterThan(0); + expect(reads).toBe(1); expect(error.message).toMatch(/browser-like environment/i); expectSecretFreeError(error, [browserKey], logger); });