diff --git a/.husky/pre-commit b/.husky/pre-commit new file mode 100644 index 0000000..da23e2c --- /dev/null +++ b/.husky/pre-commit @@ -0,0 +1,2 @@ +#!/bin/sh +npm run precommit diff --git a/flagsmith-core.ts b/flagsmith-core.ts index 461aa52..d81d05e 100644 --- a/flagsmith-core.ts +++ b/flagsmith-core.ts @@ -838,6 +838,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/package-lock.json b/package-lock.json index 1588642..0f9b06d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -35,6 +35,7 @@ "eslint-plugin-react": "7.28.0", "eslint-plugin-react-hooks": "4.3.0", "fork-ts-checker-webpack-plugin": "^7.2.1", + "husky": "^9.1.7", "in-publish": "^2.0.1", "jest": "^29.7.0", "jest-environment-jsdom": "^29.7.0", @@ -6152,6 +6153,22 @@ "node": ">=10.17.0" } }, + "node_modules/husky": { + "version": "9.1.7", + "resolved": "https://registry.npmjs.org/husky/-/husky-9.1.7.tgz", + "integrity": "sha512-5gs5ytaNjBrh5Ow3zrvdUUY+0VxIuWVL4i9irt6friV+BqdCfmV11CQTWMiBYWHbXhco+J1kHfTOUkePhCDvMA==", + "dev": true, + "license": "MIT", + "bin": { + "husky": "bin.js" + }, + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/typicode" + } + }, "node_modules/iconv-lite": { "version": "0.6.3", "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.6.3.tgz", @@ -15005,6 +15022,12 @@ "integrity": "sha512-B4FFZ6q/T2jhhksgkbEW3HBvWIfDW85snkQgawt07S7J5QXTk6BkNV+0yAeZrM5QpMAdYlocGoljn0sJ/WQkFw==", "dev": true }, + "husky": { + "version": "9.1.7", + "resolved": "https://registry.npmjs.org/husky/-/husky-9.1.7.tgz", + "integrity": "sha512-5gs5ytaNjBrh5Ow3zrvdUUY+0VxIuWVL4i9irt6friV+BqdCfmV11CQTWMiBYWHbXhco+J1kHfTOUkePhCDvMA==", + "dev": true + }, "iconv-lite": { "version": "0.6.3", "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.6.3.tgz", diff --git a/package.json b/package.json index 5f51a59..07c94d4 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,9 @@ "postinstall": "patch-package", "prepublish": "npx in-publish && npm run build || echo", "test": "jest --env=jsdom", - "checknodeversion": "npx ls-engines" + "checknodeversion": "npx ls-engines", + "prepare": "husky", + "precommit": "npm run typecheck && npm run prebuild" }, "repository": { "type": "git", @@ -50,6 +52,7 @@ "eslint-plugin-react": "7.28.0", "eslint-plugin-react-hooks": "4.3.0", "fork-ts-checker-webpack-plugin": "^7.2.1", + "husky": "^9.1.7", "in-publish": "^2.0.1", "jest": "^29.7.0", "jest-environment-jsdom": "^29.7.0", diff --git a/test/init.test.ts b/test/init.test.ts index 916a4e9..02cdb04 100644 --- a/test/init.test.ts +++ b/test/init.test.ts @@ -307,6 +307,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}`, }), }), );