Skip to content

[FFM-7051] - Add Harness-SDK-Info/Harness-AccountID/Harness-EnvironmentID headers #110

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@harnessio/ff-nodejs-server-sdk",
"version": "1.6.2",
"version": "1.7.0",
"description": "Feature flags SDK for NodeJS environments",
"main": "dist/cjs/index.js",
"module": "dist/esm/index.mjs",
Expand Down
15 changes: 14 additions & 1 deletion src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ export enum Event {
CHANGED = 'changed',
}

export const SDK_INFO = `NodeJS ${VERSION} Server`;

export default class Client {
private evaluator: Evaluator;
private repository: Repository;
Expand Down Expand Up @@ -91,6 +93,7 @@ export default class Client {
baseOptions: {
headers: {
'User-Agent': `NodeJsSDK/${VERSION}`,
'Harness-SDK-Info': SDK_INFO,
},
},
});
Expand Down Expand Up @@ -229,6 +232,16 @@ export default class Client {
);
}

if (decoded.accountID) {
this.configuration.baseOptions.headers['Harness-AccountID'] =
decoded.accountID;
}

if (decoded.environmentIdentifier) {
this.configuration.baseOptions.headers['Harness-EnvironmentID'] =
decoded.environmentIdentifier;
}

this.environment = decoded.environment;
this.cluster = decoded.clusterIdentifier || '1';
} catch (error) {
Expand Down Expand Up @@ -329,7 +342,7 @@ export default class Client {
this.repository,
);

this.streamProcessor.start();
this.streamProcessor.start(this.configuration.baseOptions.headers);
}

if (this.options.enableAnalytics) {
Expand Down
3 changes: 2 additions & 1 deletion src/streaming.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export class StreamProcessor {
);
}

start(): void {
start(headers: Record<string, string>): void {
this.log.info('Starting new StreamProcessor');

const url = `${this.options.baseUrl}/stream?cluster=${this.cluster}`;
Expand All @@ -79,6 +79,7 @@ export class StreamProcessor {
Accept: 'text/event-stream',
Authorization: `Bearer ${this.jwtToken}`,
'API-Key': this.apiKey,
...headers,
},
};

Expand Down
2 changes: 1 addition & 1 deletion src/version.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export const VERSION = '1.6.2';
export const VERSION = '1.7.0';