Skip to content

Commit 652073f

Browse files
abbaseyaclaude
andcommitted
refactor(utils): extract CONVERT_AGENT_USER_AGENT as a module constant
Replaces the two hard-coded 'ConvertAgent/1.0' literals in the http-client with a single named const declared near the imports, so the value is named once and the two injection sites reference it. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent fa7e6f9 commit 652073f

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

packages/utils/src/http-client.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ import {ERROR_MESSAGES, MESSAGES} from '@convertcom/js-sdk-enums';
99
import type {RequestOptions} from 'https';
1010
import {objectNotEmpty} from './object-utils';
1111

12+
/**
13+
* Server-side User-Agent advertised by the SDK so the metrics-endpoint
14+
* bot filter recognises Convert traffic via its `isConvertAgentUA` bypass.
15+
*/
16+
const CONVERT_AGENT_USER_AGENT = 'ConvertAgent/1.0';
17+
1218
export type HttpMethod =
1319
| 'GET'
1420
| 'DELETE'
@@ -212,7 +218,7 @@ export const HttpClient = {
212218
if (runtimeResult.runtime !== 'browser') {
213219
if (!options.headers) options.headers = {};
214220
(options.headers as Record<string, string>)['User-Agent'] =
215-
'ConvertAgent/1.0';
221+
CONVERT_AGENT_USER_AGENT;
216222
}
217223
if (config?.data && supportsRequestBody(method)) {
218224
options.body = JSON.stringify(config.data);
@@ -330,7 +336,7 @@ export const HttpClient = {
330336
// See note in the fetch branch above. old-nodejs is always
331337
// server-side, so the UA announcement always applies.
332338
if (!options.headers) options.headers = {};
333-
options.headers['User-Agent'] = 'ConvertAgent/1.0';
339+
options.headers['User-Agent'] = CONVERT_AGENT_USER_AGENT;
334340
if (postData) {
335341
options.headers['Content-Length'] = Buffer.byteLength(postData);
336342
}

0 commit comments

Comments
 (0)