Skip to content

Commit

Permalink
Remove settings from getFetch
Browse files Browse the repository at this point in the history
  • Loading branch information
EmilianoSanchez committed Jan 3, 2024
1 parent 3450da7 commit e8b02c5
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 53 deletions.
3 changes: 3 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
10.25.0 (January 4, 2024)
- Updated SDK to support URLs using 'http://' scheme in NodeJS, for connecting to the Split Synchronizer in proxy mode using HTTP.

10.24.1 (December 12, 2023)
- Updated SDK cache for browsers using localStorage, to clear cached feature flag definitions before initiating the synchronization process if the cache was previously synchronized with a different SDK key (i.e., a different environment) or different Split Filter criteria, to avoid using invalid cached data when the SDK is ready from cache.
- Updated @splitsoftware/splitio-commons package to version 1.12.1.
Expand Down
62 changes: 31 additions & 31 deletions package-lock.json

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

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@splitsoftware/splitio",
"version": "10.24.1",
"version": "10.24.2-rc.0",
"description": "Split SDK",
"files": [
"README.md",
Expand Down Expand Up @@ -40,20 +40,20 @@
"node": ">=6"
},
"dependencies": {
"@splitsoftware/splitio-commons": "1.12.1",
"@splitsoftware/splitio-commons": "1.12.2-rc.0",
"@types/google.analytics": "0.0.40",
"@types/ioredis": "^4.28.0",
"bloom-filters": "^3.0.0",
"ioredis": "^4.28.0",
"js-yaml": "^3.13.1",
"node-fetch": "^2.6.7",
"node-fetch": "^2.7.0",
"unfetch": "^4.2.0"
},
"optionalDependencies": {
"eventsource": "^1.1.2"
},
"devDependencies": {
"@types/node-fetch": "^2.5.12",
"@types/node-fetch": "^2.6.10",
"@types/seedrandom": "^3.0.2",
"copyfiles": "^2.4.1",
"cross-env": "^7.0.3",
Expand Down
31 changes: 28 additions & 3 deletions src/platform/getFetch/__tests__/node.spec.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,33 @@
import tape from 'tape-catch';
import { getFetch } from '../node';
import sinon from 'sinon';
import { getFetch, __setFetch } from '../node';

tape('getFetch returns node-fetch module in Node', assert => {
assert.equal(getFetch(), require('node-fetch'));
tape('getFetch returns a wrapped node-fetch module in Node', assert => {
assert.equal(typeof getFetch(), 'function');

assert.end();
});

tape('getFetch passes an agent object to HTTPs requests', assert => {
const fetchMock = sinon.stub();
__setFetch(fetchMock);

const fetch = getFetch();

fetch('http://test.com');
assert.true(fetchMock.calledWithExactly('http://test.com', { agent: undefined }));

fetch('https-https://', { option: 'value' });
assert.true(fetchMock.calledWithExactly('https-https://', { option: 'value', agent: undefined }));

fetch('https://test.com');
assert.true(fetchMock.calledWithExactly('https://test.com', { agent: sinon.match.object }));

fetch('https://test.com', { option: 'value' });
assert.true(fetchMock.calledWithExactly('https://test.com', { option: 'value', agent: sinon.match.object }));

// Restore
__setFetch(require('node-fetch'));

assert.end();
});
20 changes: 8 additions & 12 deletions src/platform/getFetch/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,13 @@ export function __setFetch(fetch) {
}

/**
* Retrieves 'node-fetch', a Fetch API polyfill for NodeJS.
*
* @param {import("@splitsoftware/splitio-commons/types/types").ISettings} settings - The settings object used to determine the options.
* @returns {Object} The options derived from the provided settings.
* Retrieves 'node-fetch', a Fetch API polyfill for NodeJS, with fallback to global 'fetch' if available.
* It passes an https agent with keepAlive enabled if URL is https.
*/
export function getFetch(settings) {
const useHttpsAgent = Object.values(settings.urls).every((url) => url.startsWith('https'));

return nodeFetch && useHttpsAgent ?
(url, options) => {
return nodeFetch(url, Object.assign({ agent }, options));
} :
nodeFetch;
export function getFetch() {
if (nodeFetch) {
return (url, options) => {
return nodeFetch(url, Object.assign({ agent: url.startsWith('https://') ? agent : undefined }, options));
};
}
}
2 changes: 0 additions & 2 deletions src/platform/node.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import EventEmitter from 'events';
import { getFetch } from '../platform/getFetch/node';
import { getEventSource } from '../platform/getEventSource/node';
import { getOptions } from '../platform/request/options/node';
import { NodeSignalListener } from '@splitsoftware/splitio-commons/src/listeners/node';
import { now } from '@splitsoftware/splitio-commons/src/utils/timeTracker/now/node';

export const platform = {
getOptions,
getFetch,
getEventSource,
EventEmitter,
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.24.1';
export const packageVersion = '10.24.2-rc.0';

0 comments on commit e8b02c5

Please sign in to comment.