Skip to content

Commit d782dfa

Browse files
authored
feat: send flagsmith sdk user agent (#332)
* feat: added-write-version-and-header-passing * feat: re-added-generate-types * feat: ignore-version * feat: removed-evaluation-context-type-generation * chore: added-user-agent-sdk-test
1 parent 055edbf commit d782dfa

File tree

7 files changed

+25
-3
lines changed

7 files changed

+25
-3
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,6 @@ buck-out/
4040
android/app/libs
4141
android/keystores/debug.keystore
4242
*.js.map
43+
44+
# Utils
45+
utils/version.ts

flagsmith-core.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import setDynatraceValue from './utils/set-dynatrace-value';
2525
import { EvaluationContext } from './evaluation-context';
2626
import { isTraitEvaluationContext, toEvaluationContext, toTraitEvaluationContextObject } from './utils/types';
2727
import { ensureTrailingSlash } from './utils/ensureTrailingSlash';
28+
import { SDK_VERSION } from './utils/version';
2829

2930
enum FlagSource {
3031
"NONE" = "NONE",
@@ -828,6 +829,10 @@ const Flagsmith = class {
828829
options.headers['Flagsmith-Application-Version'] = this.applicationMetadata.version;
829830
}
830831

832+
if (SDK_VERSION) {
833+
options.headers['Flagsmith-SDK-user-agent'] = `flagsmith-js-sdk/${SDK_VERSION}`
834+
}
835+
831836
if (headers) {
832837
Object.assign(options.headers, headers);
833838
}

lib/flagsmith/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "flagsmith",
3-
"version": "9.3.0",
3+
"version": "9.3.1",
44
"description": "Feature flagging to support continuous development",
55
"main": "./index.js",
66
"module": "./index.mjs",

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
"main": "./flagsmith/index.js",
55
"scripts": {
66
"typecheck": "tsc",
7-
"build": "npm run generatetypes && npm run bundle && npm run typecheck",
7+
"prebuild": "node scripts/write-version.js",
8+
"build": "npm run prebuild && npm run bundle && npm run typecheck",
89
"bundle": "rollup -c && node ./move-react.js",
910
"deploy": "npm run build && npm test && cd ./lib/flagsmith/ && npm publish && cd ../../lib/react-native-flagsmith && npm publish",
1011
"deploy:beta": "npm run build && npm test && cd ./lib/flagsmith/ && npm publish --tag beta && cd ../../lib/react-native-flagsmith && npm publish --tag beta",

scripts/write-version.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/* eslint-disable @typescript-eslint/no-var-requires */
2+
const fs = require('fs');
3+
const path = require('path');
4+
const pkg = require('../lib/flagsmith/package.json');
5+
6+
const content = `// Auto-generated by write-version.js
7+
export const SDK_VERSION = "${pkg.version}";
8+
`;
9+
10+
fs.writeFileSync(path.join(__dirname, '../utils/version.ts'), content);

test/init.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { waitFor } from '@testing-library/react';
22
import {defaultState, FLAGSMITH_KEY, getFlagsmith, getStateToCheck, identityState} from './test-constants';
33
import { promises as fs } from 'fs';
4-
4+
import { SDK_VERSION } from '../utils/version'
55
describe('Flagsmith.init', () => {
66
beforeEach(() => {
77
// Avoid mocks, but if you need to add them here
@@ -292,6 +292,7 @@ describe('Flagsmith.init', () => {
292292
headers: expect.objectContaining({
293293
'Flagsmith-Application-Name': 'Test App',
294294
'Flagsmith-Application-Version': '1.2.3',
295+
'Flagsmith-SDK-user-agent': `flagsmith-js-sdk/${SDK_VERSION}`,
295296
}),
296297
}),
297298
);

utils/version.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// Auto-generated by write-version.js
2+
export const SDK_VERSION = "9.3.1";

0 commit comments

Comments
 (0)