Skip to main content

UserAgent

Upgather SDK


Upgather SDK / UserAgent

Class: UserAgent

Defined in: lib/utils/UserAgent.ts:28

Utility for generating consistent User-Agent strings for all SDK requests.

Remarks

This utility automatically generates standardized User-Agent headers that are included in all HTTP requests made by the SDK. The format follows web standards and includes version information for debugging and analytics.

The User-Agent string follows the format: upgather-sdk/<version> (+https://upgather-sdk-docs.prod.upgather.com)

User-Agent strings are cached for performance and automatically include the current package version with graceful fallback handling.

Example

import { UserAgent } from '@upgather/upgather-sdk';

const userAgent = UserAgent.getUserAgent();
console.log(userAgent);
// "upgather-sdk/0.2.2 (+https://upgather-sdk-docs.prod.upgather.com)"

Constructors

new UserAgent()

new UserAgent(): UserAgent

Returns

UserAgent

Methods

getUserAgent()

static getUserAgent(): string

Defined in: lib/utils/UserAgent.ts:63

Generates the standard User-Agent string for all SDK requests.

Returns

string

The formatted user agent string in the format: upgather-sdk/<version> (+docs-url)

Remarks

This method generates a standardized User-Agent header that follows web conventions. The string is cached after first generation for performance. The version is obtained from PackageInfo.getVersion which handles fallbacks gracefully.

The generated format is:

  • SDK name: "upgather-sdk"
  • Version: From package.json or "0.0.0-unknown" fallback
  • Documentation URL: Link to SDK documentation

Example

const userAgent = UserAgent.getUserAgent();
// Returns: "upgather-sdk/0.2.2 (+https://upgather-sdk-docs.prod.upgather.com)"

// Use in custom HTTP requests
fetch('/api/data', {
headers: {
'User-Agent': userAgent
}
});

resetCache()

static resetCache(): void

Defined in: lib/utils/UserAgent.ts:94

Resets the cached user agent string.

Returns

void

Remarks

This method clears the cached User-Agent string and also resets the underlying package information cache. This is primarily useful for testing scenarios or when you need to regenerate the User-Agent string with fresh package information.

When called, the next call to UserAgent.getUserAgent will regenerate the User-Agent string from scratch.

Example

// Clear cache and force regeneration
UserAgent.resetCache();
const freshUserAgent = UserAgent.getUserAgent(); // Will regenerate