Skip to content

Commit 21a2377

Browse files
Implementation and type definitions
1 parent 04e3f08 commit 21a2377

File tree

4 files changed

+46
-1
lines changed

4 files changed

+46
-1
lines changed

CHANGES.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
10.27.0 (June 25, 2024)
2+
- Added `sync.requestOptions.agent` property to SDK configuration, to pass a custom HTTP(S) Agent to the SDK requests in NodeJS. This allows the SDK to use a custom agent with specific configurations, like a network proxy or custom TLS settings (See https://help.split.io/hc/en-us/articles/360020564931-Node-js-SDK#proxy).
3+
14
10.26.1 (June 14, 2024)
25
- 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.
36
- 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.

src/platform/getOptions/node.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ const agent = new https.Agent({
1111
});
1212

1313
export function getOptions(settings) {
14+
// User provided options take precedence
15+
if (settings.sync.requestOptions) return settings.sync.requestOptions;
16+
1417
// If some URL is not HTTPS, we don't use the agent, to let the SDK connect to HTTP endpoints
1518
if (find(settings.urls, url => !url.startsWith('https:'))) return;
1619

ts-tests/index.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -616,7 +616,10 @@ let fullNodeSettings: SplitIO.INodeSettings = {
616616
sync: {
617617
splitFilters: splitFilters,
618618
impressionsMode: 'OPTIMIZED',
619-
enabled: true
619+
enabled: true,
620+
requestOptions: {
621+
agent: new (require('https')).Agent(),
622+
}
620623
}
621624
};
622625
fullNodeSettings.storage.type = 'MEMORY';

types/splitio.d.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
/// <reference types="google.analytics" />
66
import { RedisOptions } from "ioredis";
7+
import { RequestOptions } from "http";
78

89
export as namespace SplitIO;
910
export = SplitIO;
@@ -1168,6 +1169,41 @@ declare namespace SplitIO {
11681169
* @default 'standalone'
11691170
*/
11701171
mode?: 'standalone'
1172+
sync?: INodeBasicSettings['sync'] & {
1173+
/**
1174+
* Custom options object for HTTP(S) requests in NodeJS.
1175+
* If provided, this object is merged with the options object passed by the SDK for EventSource and Node-Fetch calls.
1176+
* @see {@link https://www.npmjs.com/package/node-fetch#options}
1177+
*/
1178+
requestOptions?: {
1179+
/**
1180+
* Custom NodeJS HTTP(S) Agent used by the SDK for HTTP(S) requests.
1181+
*
1182+
* You can use it, for example, for certificate pinning or setting a network proxy:
1183+
*
1184+
* ```javascript
1185+
* const { HttpsProxyAgent } = require('https-proxy-agent');
1186+
*
1187+
* const proxyAgent = new HttpsProxyAgent(process.env.HTTPS_PROXY || 'http://10.10.1.10:1080');
1188+
*
1189+
* const factory = SplitFactory({
1190+
* ...
1191+
* sync: {
1192+
* requestOptions: {
1193+
* agent: proxyAgent
1194+
* }
1195+
* }
1196+
* })
1197+
* ```
1198+
*
1199+
* @see {@link https://nodejs.org/api/https.html#class-httpsagent}
1200+
*
1201+
* @property {http.Agent | https.Agent} agent
1202+
* @default undefined
1203+
*/
1204+
agent?: RequestOptions["agent"]
1205+
},
1206+
}
11711207
}
11721208
/**
11731209
* Settings interface with async storage for SDK instances created on NodeJS.

0 commit comments

Comments
 (0)