diff --git a/src/consts.ts b/src/consts.ts index e63929e..a02454c 100644 --- a/src/consts.ts +++ b/src/consts.ts @@ -1,3 +1,8 @@ +/** + * Package name used as User-Agent header + */ +export const USER_AGENT = 'stackone-ai-node'; + /** * Default base URL for StackOne API */ diff --git a/src/requestBuilder.ts b/src/requestBuilder.ts index 973c64e..c729a88 100644 --- a/src/requestBuilder.ts +++ b/src/requestBuilder.ts @@ -1,3 +1,4 @@ +import { USER_AGENT } from './consts'; import { type ExecuteOptions, type HttpBodyType, @@ -57,7 +58,7 @@ export class RequestBuilder { */ prepareHeaders(): Record { return { - 'User-Agent': 'stackone-ai-node', + 'User-Agent': USER_AGENT, ...this.headers, }; } diff --git a/src/rpc-client.ts b/src/rpc-client.ts index a277fd8..f2e1f8d 100644 --- a/src/rpc-client.ts +++ b/src/rpc-client.ts @@ -1,3 +1,4 @@ +import { DEFAULT_BASE_URL, USER_AGENT } from './consts'; import { STACKONE_HEADER_KEYS } from './headers'; import { type RpcActionRequest, @@ -25,7 +26,7 @@ export class RpcClient { constructor(config: RpcClientConfig) { const validatedConfig = rpcClientConfigSchema.parse(config); - this.baseUrl = validatedConfig.serverURL || 'https://api.stackone.com'; + this.baseUrl = validatedConfig.serverURL || DEFAULT_BASE_URL; const username = validatedConfig.security.username; const password = validatedConfig.security.password || ''; this.authHeader = `Basic ${Buffer.from(`${username}:${password}`).toString('base64')}`; @@ -68,7 +69,7 @@ export class RpcClient { const httpHeaders = { 'Content-Type': 'application/json', Authorization: this.authHeader, - 'User-Agent': 'stackone-ai-node', + 'User-Agent': USER_AGENT, ...forwardedHeaders, } satisfies Record; diff --git a/src/utils/errors.ts b/src/utils/errors.ts index 0d01d7c..dd95bea 100644 --- a/src/utils/errors.ts +++ b/src/utils/errors.ts @@ -1,4 +1,4 @@ -// Type aliases for common types +import { USER_AGENT } from '../consts'; /** * Base exception for StackOne errors @@ -73,7 +73,7 @@ export class StackOneAPIError extends StackOneError { // Add request headers information (for debugging) errorMessage += '\n\nRequest Headers:'; errorMessage += '\n- Authorization: [REDACTED]'; - errorMessage += '\n- User-Agent: stackone-ai-node'; + errorMessage += `\n- User-Agent: ${USER_AGENT}`; // Add request body information if available if (this.requestBody) {