Skip to content

Commit

Permalink
Merge pull request #810 from splitio/nodejs_agent_option
Browse files Browse the repository at this point in the history
Add `agent` option for NodeJS
  • Loading branch information
EmilianoSanchez committed Jun 25, 2024
2 parents 7fad01b + 63330a4 commit b0b5bb7
Show file tree
Hide file tree
Showing 9 changed files with 142 additions and 80 deletions.
4 changes: 4 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
10.27.0 (June 25, 2024)
- Added `sync.requestOptions.agent` option to SDK configuration for NodeJS. This allows passing a custom NodeJS HTTP(S) Agent with specific configurations for the SDK requests, like custom TLS settings or a network proxy (See https://help.split.io/hc/en-us/articles/360020564931-Node-js-SDK#proxy).
- Updated some transitive dependencies for vulnerability fixes.

10.26.1 (June 14, 2024)
- Updated the internal imports of 'os' and 'ioredis' modules for NodeJS, to use EcmaScript 'import' rather than CommonJS 'require' for the ES modules build. This avoids runtime errors on some scenarios when bundling the SDK into a .mjs file or importing it from a .mjs file.
- Updated eventsource dependency for NodeJS. The eventsource v1.1.2 dependency was removed, and the SDK now uses an embedded adaptation that can accept an HTTP(S) agent option, like other HTTP(S) requests.
Expand Down
156 changes: 80 additions & 76 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": "@splitsoftware/splitio",
"version": "10.26.1",
"version": "10.27.0",
"description": "Split SDK",
"files": [
"README.md",
Expand Down
8 changes: 8 additions & 0 deletions src/platform/getOptions/__tests__/node.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,11 @@ tape('getOptions returns undefined if some url is not https', assert => {

assert.end();
});

tape('getOptions returns the provided options from settings', assert => {
const customRequestOptions = { agent: false };
const settings = settingsFactory({ sync: { requestOptions: customRequestOptions } });
assert.equal(getOptions(settings), customRequestOptions);

assert.end();
});
3 changes: 3 additions & 0 deletions src/platform/getOptions/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ const agent = new https.Agent({
});

export function getOptions(settings) {
// User provided options take precedence
if (settings.sync.requestOptions) return settings.sync.requestOptions;

// If some URL is not HTTPS, we don't use the agent, to let the SDK connect to HTTP endpoints
if (find(settings.urls, url => !url.startsWith('https:'))) return;

Expand Down
2 changes: 1 addition & 1 deletion src/settings/defaults/version.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export const packageVersion = '10.26.1';
export const packageVersion = '10.27.0';
6 changes: 5 additions & 1 deletion src/settings/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,9 @@ const params = {
};

export function settingsFactory(config) {
return settingsValidation(config, params);
const settings = settingsValidation(config, params);

// if provided, keeps reference to the `requestOptions` object
if (settings.sync.requestOptions) settings.sync.requestOptions = config.sync.requestOptions;
return settings;
}
5 changes: 4 additions & 1 deletion ts-tests/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,10 @@ let fullNodeSettings: SplitIO.INodeSettings = {
sync: {
splitFilters: splitFilters,
impressionsMode: 'OPTIMIZED',
enabled: true
enabled: true,
requestOptions: {
agent: new (require('https')).Agent(),
}
}
};
fullNodeSettings.storage.type = 'MEMORY';
Expand Down
Loading

0 comments on commit b0b5bb7

Please sign in to comment.