Skip to content

Commit faf1ac2

Browse files
authored
refactor(consts): extract hard-coded strings into constants (#226)
1 parent 6373cfe commit faf1ac2

4 files changed

Lines changed: 12 additions & 5 deletions

File tree

src/consts.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
/**
2+
* Package name used as User-Agent header
3+
*/
4+
export const USER_AGENT = 'stackone-ai-node';
5+
16
/**
27
* Default base URL for StackOne API
38
*/

src/requestBuilder.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { USER_AGENT } from './consts';
12
import {
23
type ExecuteOptions,
34
type HttpBodyType,
@@ -57,7 +58,7 @@ export class RequestBuilder {
5758
*/
5859
prepareHeaders(): Record<string, string> {
5960
return {
60-
'User-Agent': 'stackone-ai-node',
61+
'User-Agent': USER_AGENT,
6162
...this.headers,
6263
};
6364
}

src/rpc-client.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { DEFAULT_BASE_URL, USER_AGENT } from './consts';
12
import { STACKONE_HEADER_KEYS } from './headers';
23
import {
34
type RpcActionRequest,
@@ -25,7 +26,7 @@ export class RpcClient {
2526

2627
constructor(config: RpcClientConfig) {
2728
const validatedConfig = rpcClientConfigSchema.parse(config);
28-
this.baseUrl = validatedConfig.serverURL || 'https://api.stackone.com';
29+
this.baseUrl = validatedConfig.serverURL || DEFAULT_BASE_URL;
2930
const username = validatedConfig.security.username;
3031
const password = validatedConfig.security.password || '';
3132
this.authHeader = `Basic ${Buffer.from(`${username}:${password}`).toString('base64')}`;
@@ -68,7 +69,7 @@ export class RpcClient {
6869
const httpHeaders = {
6970
'Content-Type': 'application/json',
7071
Authorization: this.authHeader,
71-
'User-Agent': 'stackone-ai-node',
72+
'User-Agent': USER_AGENT,
7273
...forwardedHeaders,
7374
} satisfies Record<string, string>;
7475

src/utils/errors.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Type aliases for common types
1+
import { USER_AGENT } from '../consts';
22

33
/**
44
* Base exception for StackOne errors
@@ -73,7 +73,7 @@ export class StackOneAPIError extends StackOneError {
7373
// Add request headers information (for debugging)
7474
errorMessage += '\n\nRequest Headers:';
7575
errorMessage += '\n- Authorization: [REDACTED]';
76-
errorMessage += '\n- User-Agent: stackone-ai-node';
76+
errorMessage += `\n- User-Agent: ${USER_AGENT}`;
7777

7878
// Add request body information if available
7979
if (this.requestBody) {

0 commit comments

Comments
 (0)