Skip to content

Commit

Permalink
feat: Add wrapper support. (#526)
Browse files Browse the repository at this point in the history
For contract test implementation see:
launchdarkly/sdk-test-harness#223
  • Loading branch information
kinyoklion authored Jul 31, 2024
1 parent 60ac92b commit 29a43a4
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 4 deletions.
1 change: 1 addition & 0 deletions contract-tests/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ app.get('/', (req, res) => {
'inline-context',
'anonymous-redaction',
'evaluation-hooks',
'wrapper'
],
});
});
Expand Down
8 changes: 8 additions & 0 deletions contract-tests/sdkClientEntity.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,14 @@ export function makeSdkConfig(options, tag) {
(hook) => new TestHook(hook.name, hook.callbackUri, hook.data, hook.errors),
);
}
if (options.wrapper) {
if(options.wrapper.name) {
cf.wrapperName = options.wrapper.name;
}
if(options.wrapper.version) {
cf.wrapperVersion = options.wrapper.version;
}
}
return cf;
}

Expand Down
10 changes: 8 additions & 2 deletions packages/sdk/server-node/__tests__/platform/NodeInfo.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as os from 'os';
import NodeInfo from '../../src/platform/NodeInfo';

describe('given an information instance', () => {
const info = new NodeInfo();
const info = new NodeInfo({});

it('can get platform information', () => {
const data = info.platformData();
Expand All @@ -25,8 +25,14 @@ describe('given an information instance', () => {
});
});

test('it supports wrapper name and version', () => {
const info = new NodeInfo({ wrapperName: 'the-wrapper', wrapperVersion: 'the-version' });
expect(info.sdkData().wrapperName).toEqual('the-wrapper');
expect(info.sdkData().wrapperVersion).toEqual('the-version');
});

describe('given an information instance with mock data', () => {
const info = new NodeInfo();
const info = new NodeInfo({});

it('can get platform information', () => {
const platformSpy = jest.spyOn(os, 'platform');
Expand Down
4 changes: 3 additions & 1 deletion packages/sdk/server-node/src/platform/NodeInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ function processPlatformName(name: string): string {
}

export default class NodeInfo implements platform.Info {
constructor(private readonly config: { wrapperName?: string; wrapperVersion?: string }) {}
platformData(): platform.PlatformData {
return {
os: {
Expand All @@ -38,7 +39,8 @@ export default class NodeInfo implements platform.Info {
name: packageJson.name,
version: packageJson.version,
userAgentBase: 'NodeJSClient',
// No wrapper name/version at the moment.
wrapperName: this.config.wrapperName,
wrapperVersion: this.config.wrapperVersion,
};
}
}
3 changes: 2 additions & 1 deletion packages/sdk/server-node/src/platform/NodePlatform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import NodeInfo from './NodeInfo';
import NodeRequests from './NodeRequests';

export default class NodePlatform implements platform.Platform {
info: platform.Info = new NodeInfo();
info: platform.Info;

fileSystem?: platform.Filesystem | undefined = new NodeFilesystem();

Expand All @@ -15,6 +15,7 @@ export default class NodePlatform implements platform.Platform {
requests: platform.Requests;

constructor(options: LDOptions) {
this.info = new NodeInfo(options);
this.requests = new NodeRequests(options.tlsParams, options.proxyOptions, options.logger);
}
}

0 comments on commit 29a43a4

Please sign in to comment.