Skip to content
Draft
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
13 changes: 7 additions & 6 deletions packages/cli/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,21 @@ export class JulesClient {
this.apiKey = apiKey || getApiKey();
}

private getHeaders(): Record<string, string> {
private static buildHeaders(apiKey: string): Record<string, string> {
return {
'x-goog-api-key': this.apiKey,
'x-goog-api-key': apiKey,
'Content-Type': 'application/json',
Comment on lines +14 to 15

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

To improve maintainability and prevent potential typos, it's a good practice to define hardcoded strings for headers and content types as constants rather than using them as "magic strings" directly in the code.

You could define them as static readonly properties on the JulesClient class and reference them here. For example:

// At the top of the JulesClient class
private static readonly API_KEY_HEADER = 'x-goog-api-key';
private static readonly CONTENT_TYPE_HEADER = 'Content-Type';
private static readonly JSON_CONTENT_TYPE = 'application/json';

// In buildHeaders method
return {
  [JulesClient.API_KEY_HEADER]: apiKey,
  [JulesClient.CONTENT_TYPE_HEADER]: JulesClient.JSON_CONTENT_TYPE,
};

This change would make the header definitions more centralized and easier to manage.

};
}

private getHeaders(): Record<string, string> {
return JulesClient.buildHeaders(this.apiKey);
}

static async validateKey(apiKey: string): Promise<boolean> {
const response = await fetch(`${BASE_URL}/sessions`, {
method: 'GET',
headers: {
'x-goog-api-key': apiKey,
'Content-Type': 'application/json',
},
headers: JulesClient.buildHeaders(apiKey),
});

if (!response.ok) {
Expand Down
Loading