Skip to content

Commit f03930b

Browse files
authored
[FFM-7017] - Add Harness-SDK-Info/Harness-AccountID/Harness-EnvironmentID headers (#110)
* [FFM-7017] - Add Harness-SDK-Info/Harness-AccountID/Harness-EnvironmentID headers What Add meta data headers `Harness-SDK-Info`, `Harness-AccountID` and `Harness-EnvironmentID` to bring NodeJS in line with other server SDKs. Why Helps with backend load testing to identify problematic clients Testing Manual with Java SDK proxy
1 parent 1136317 commit f03930b

File tree

5 files changed

+22
-4
lines changed

5 files changed

+22
-4
lines changed

package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@harnessio/ff-nodejs-server-sdk",
3-
"version": "1.6.2",
3+
"version": "1.7.0",
44
"description": "Feature flags SDK for NodeJS environments",
55
"main": "dist/cjs/index.js",
66
"module": "dist/esm/index.mjs",

src/client.ts

+14
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ export enum Event {
4444
CHANGED = 'changed',
4545
}
4646

47+
export const SDK_INFO = `NodeJS ${VERSION} Server`;
48+
4749
export default class Client {
4850
private evaluator: Evaluator;
4951
private repository: Repository;
@@ -91,6 +93,7 @@ export default class Client {
9193
baseOptions: {
9294
headers: {
9395
'User-Agent': `NodeJsSDK/${VERSION}`,
96+
'Harness-SDK-Info': SDK_INFO,
9497
},
9598
},
9699
});
@@ -229,6 +232,16 @@ export default class Client {
229232
);
230233
}
231234

235+
if (decoded.accountID) {
236+
this.configuration.baseOptions.headers['Harness-AccountID'] =
237+
decoded.accountID;
238+
}
239+
240+
if (decoded.environmentIdentifier) {
241+
this.configuration.baseOptions.headers['Harness-EnvironmentID'] =
242+
decoded.environmentIdentifier;
243+
}
244+
232245
this.environment = decoded.environment;
233246
this.cluster = decoded.clusterIdentifier || '1';
234247
} catch (error) {
@@ -327,6 +340,7 @@ export default class Client {
327340
this.cluster,
328341
this.eventBus,
329342
this.repository,
343+
this.configuration.baseOptions.headers,
330344
);
331345

332346
this.streamProcessor.start();

src/streaming.ts

+4
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ export class StreamProcessor {
3333
private readonly api: ClientApi;
3434
private readonly repository: Repository;
3535
private readonly retryDelayMs: number;
36+
private readonly headers: Record<string, string>;
3637

3738
private options: Options;
3839
private request: ClientRequest;
@@ -50,6 +51,7 @@ export class StreamProcessor {
5051
cluster: string,
5152
eventBus: EventEmitter,
5253
repository: Repository,
54+
headers: Record<string, string>,
5355
) {
5456
this.api = api;
5557
this.apiKey = apiKey;
@@ -66,6 +68,7 @@ export class StreamProcessor {
6668
this.retryDelayMs = Math.floor(
6769
Math.random() * (maxDelay - minDelay) + minDelay,
6870
);
71+
this.headers = headers;
6972
}
7073

7174
start(): void {
@@ -79,6 +82,7 @@ export class StreamProcessor {
7982
Accept: 'text/event-stream',
8083
Authorization: `Bearer ${this.jwtToken}`,
8184
'API-Key': this.apiKey,
85+
...this.headers,
8286
},
8387
};
8488

src/version.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export const VERSION = '1.6.2';
1+
export const VERSION = '1.7.0';

0 commit comments

Comments
 (0)