diff --git a/.gitignore b/.gitignore index acf988c0..78408cdb 100644 --- a/.gitignore +++ b/.gitignore @@ -40,3 +40,6 @@ buck-out/ android/app/libs android/keystores/debug.keystore *.js.map + +# Utils +utils/version.ts diff --git a/flagsmith-core.ts b/flagsmith-core.ts index 9f8d0cef..a7db5334 100644 --- a/flagsmith-core.ts +++ b/flagsmith-core.ts @@ -25,6 +25,7 @@ import setDynatraceValue from './utils/set-dynatrace-value'; import { EvaluationContext } from './evaluation-context'; import { isTraitEvaluationContext, toEvaluationContext, toTraitEvaluationContextObject } from './utils/types'; import { ensureTrailingSlash } from './utils/ensureTrailingSlash'; +import { SDK_VERSION } from './utils/version'; enum FlagSource { "NONE" = "NONE", @@ -828,6 +829,10 @@ const Flagsmith = class { options.headers['Flagsmith-Application-Version'] = this.applicationMetadata.version; } + if (SDK_VERSION) { + options.headers['Flagsmith-SDK-user-agent'] = `flagsmith-js-sdk/${SDK_VERSION}` + } + if (headers) { Object.assign(options.headers, headers); } diff --git a/lib/flagsmith/package.json b/lib/flagsmith/package.json index bacae0e1..a95a398e 100644 --- a/lib/flagsmith/package.json +++ b/lib/flagsmith/package.json @@ -1,6 +1,6 @@ { "name": "flagsmith", - "version": "9.3.0", + "version": "9.3.1", "description": "Feature flagging to support continuous development", "main": "./index.js", "module": "./index.mjs", diff --git a/package.json b/package.json index 8a1838ba..80e33790 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,8 @@ "main": "./flagsmith/index.js", "scripts": { "typecheck": "tsc", - "build": "npm run generatetypes && npm run bundle && npm run typecheck", + "prebuild": "node scripts/write-version.js", + "build": "npm run prebuild && npm run bundle && npm run typecheck", "bundle": "rollup -c && node ./move-react.js", "deploy": "npm run build && npm test && cd ./lib/flagsmith/ && npm publish && cd ../../lib/react-native-flagsmith && npm publish", "deploy:beta": "npm run build && npm test && cd ./lib/flagsmith/ && npm publish --tag beta && cd ../../lib/react-native-flagsmith && npm publish --tag beta", diff --git a/scripts/write-version.js b/scripts/write-version.js new file mode 100644 index 00000000..b1483a76 --- /dev/null +++ b/scripts/write-version.js @@ -0,0 +1,10 @@ +/* eslint-disable @typescript-eslint/no-var-requires */ +const fs = require('fs'); +const path = require('path'); +const pkg = require('../lib/flagsmith/package.json'); + +const content = `// Auto-generated by write-version.js +export const SDK_VERSION = "${pkg.version}"; +`; + +fs.writeFileSync(path.join(__dirname, '../utils/version.ts'), content); diff --git a/test/init.test.ts b/test/init.test.ts index 4b162c89..6d9d66eb 100644 --- a/test/init.test.ts +++ b/test/init.test.ts @@ -1,7 +1,7 @@ import { waitFor } from '@testing-library/react'; import {defaultState, FLAGSMITH_KEY, getFlagsmith, getStateToCheck, identityState} from './test-constants'; import { promises as fs } from 'fs'; - +import { SDK_VERSION } from '../utils/version' describe('Flagsmith.init', () => { beforeEach(() => { // Avoid mocks, but if you need to add them here @@ -292,6 +292,7 @@ describe('Flagsmith.init', () => { headers: expect.objectContaining({ 'Flagsmith-Application-Name': 'Test App', 'Flagsmith-Application-Version': '1.2.3', + 'Flagsmith-SDK-user-agent': `flagsmith-js-sdk/${SDK_VERSION}`, }), }), ); diff --git a/utils/version.ts b/utils/version.ts new file mode 100644 index 00000000..f34f5479 --- /dev/null +++ b/utils/version.ts @@ -0,0 +1,2 @@ +// Auto-generated by write-version.js +export const SDK_VERSION = "9.3.1";