Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 19 additions & 13 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,32 @@ type UnsupportedCometAPIOption = (typeof UNSUPPORTED_COMETAPI_OPTIONS)[number];
function sanitizeOptions<T extends Partial<ClientOptions>>(
options: T,
): Omit<T, UnsupportedCometAPIOption> {
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<T, UnsupportedCometAPIOption>;
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;
}

Expand Down
2 changes: 1 addition & 1 deletion tests/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand Down