Skip to content
Merged
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion release-please-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"bump-patch-for-minor-pre-major": false,
"draft": false,
"prerelease": false,
"include-component-in-tag": false
"include-component-in-tag": false,
"extra-files": ["sdk/version.ts"]
}
},
"$schema": "https://raw.githubusercontent.com/googleapis/release-please/main/schemas/config.json",
Expand Down
10 changes: 2 additions & 8 deletions sdk/utils.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { createHash } from 'crypto';
import { Fetch, FlagsmithTraitValue, TraitConfig } from './types.js';
import { Dispatcher } from 'undici-types';
import { SDK_VERSION } from './version.js';

type Traits = { [key: string]: TraitConfig | FlagsmithTraitValue };

const FLAGSMITH_USER_AGENT = 'flagsmith-nodejs-sdk';
const FLAGSMITH_UNKNOWN_VERSION = 'unknown';

export function isTraitConfig(
traitValue: TraitConfig | FlagsmithTraitValue
Expand Down Expand Up @@ -130,11 +130,5 @@ export class Deferred<T> {
}

export function getUserAgent(): string {
try {
const packageJson = require('../package.json');
const version = packageJson?.version;
return version ? `${FLAGSMITH_USER_AGENT}/${version}` : FLAGSMITH_UNKNOWN_VERSION;
} catch {
return FLAGSMITH_UNKNOWN_VERSION;
}
return `${FLAGSMITH_USER_AGENT}/${SDK_VERSION}`;
}
1 change: 1 addition & 0 deletions sdk/version.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const SDK_VERSION = '9.0.1'; // x-release-please-version
3 changes: 1 addition & 2 deletions tests/sdk/flagsmith.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -512,8 +512,7 @@ test('getIdentityFlags succeeds if initial fetch failed then succeeded', async (
expect(flags2.isFeatureEnabled('some_feature')).toBe(true);
});

// Skip in ESM build: require() path resolution differs
test.skipIf(isEsmBuild)('get_user_agent_extracts_version_from_package_json', async () => {
test('get_user_agent_matches_package_version', async () => {
const userAgent = getUserAgent();
const packageJson = require('../../package.json');

Expand Down
Loading