Skip to content

Commit bd55232

Browse files
Upgrade JS-commons, which includes custom headers support
1 parent db9ec8d commit bd55232

File tree

6 files changed

+70
-26
lines changed

6 files changed

+70
-26
lines changed

CHANGES.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
0.14.2 (August XX, 2024)
2-
- Updated some transitive dependencies for vulnerability fixes.
1+
0.15.0 (September XX, 2024)
2+
- Updated @splitsoftware/splitio-commons package to version 1.17.0 that includes minor updates:
3+
- Added `sync.requestOptions.getHeaderOverrides` configuration option to enhance SDK HTTP request Headers for Authorization Frameworks.
4+
- Updated some transitive dependencies for vulnerability fixes.
35

46
0.14.1 (June 14, 2024)
57
- Updated @splitsoftware/splitio-commons package to version 1.16.0 that includes some vulnerability and bug fixes.

package-lock.json

Lines changed: 17 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@splitsoftware/splitio-browserjs",
3-
"version": "0.14.1",
3+
"version": "0.15.0",
44
"description": "Split SDK for JavaScript on Browser",
55
"main": "cjs/index.js",
66
"module": "esm/index.js",
@@ -64,7 +64,7 @@
6464
"bugs": "https://github.com/splitio/javascript-browser-client/issues",
6565
"homepage": "https://github.com/splitio/javascript-browser-client#readme",
6666
"dependencies": {
67-
"@splitsoftware/splitio-commons": "1.16.0",
67+
"@splitsoftware/splitio-commons": "1.17.0",
6868
"@types/google.analytics": "0.0.40",
6969
"tslib": "^2.3.1",
7070
"unfetch": "^4.2.0"

src/settings/defaults.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { LogLevels, isLogLevelString } from '@splitsoftware/splitio-commons/src/
22
import { ConsentStatus, LogLevel } from '@splitsoftware/splitio-commons/src/types';
33
import { CONSENT_GRANTED } from '@splitsoftware/splitio-commons/src/utils/constants';
44

5-
const packageVersion = '0.14.1';
5+
const packageVersion = '0.15.0';
66

77
/**
88
* In browser, the default debug level, can be set via the `localStorage.splitio_debug` item.

ts-tests/index.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ splitView = {
136136
configs: {
137137
off: '{"dimensions":"{\"height\":20,\"width\":40}"}'
138138
},
139-
sets: ['set_a','set_b'],
139+
sets: ['set_a', 'set_b'],
140140
defaultTreatment: 'off'
141141
};
142142
splitViews = [splitView];
@@ -589,7 +589,10 @@ let fullBrowserSettings: SplitIO.IBrowserSettings = {
589589
splitFilters: splitFilters,
590590
impressionsMode: 'DEBUG',
591591
localhostMode: LocalhostFromObject(),
592-
enabled: true
592+
enabled: true,
593+
requestOptions: {
594+
getHeaderOverrides(context) { return { ...context.headers, 'header': 'value' }; },
595+
}
593596
},
594597
userConsent: 'GRANTED'
595598
};
@@ -636,7 +639,10 @@ let fullBrowserAsyncSettings: SplitIO.IBrowserAsyncSettings = {
636639
streamingEnabled: true,
637640
sync: {
638641
impressionsMode: 'DEBUG',
639-
enabled: true
642+
enabled: true,
643+
requestOptions: {
644+
getHeaderOverrides(context) { return { ...context.headers, 'header': 'value' }; },
645+
}
640646
},
641647
userConsent: 'GRANTED'
642648
};

types/splitio.d.ts

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,11 @@ interface ISettings {
9292
splitFilters: SplitIO.SplitFilter[],
9393
impressionsMode: SplitIO.ImpressionsMode,
9494
enabled: boolean,
95-
localhostMode?: SplitIO.LocalhostFactory
95+
flagSpecVersion: string,
96+
localhostMode?: SplitIO.LocalhostFactory,
97+
requestOptions?: {
98+
getHeaderOverrides?: (context: { headers: Record<string, string> }) => Record<string, string>
99+
},
96100
},
97101
readonly userConsent: SplitIO.ConsentStatus
98102
}
@@ -252,6 +256,38 @@ interface ISharedSettings {
252256
* @default true
253257
*/
254258
enabled?: boolean
259+
/**
260+
* Custom options object for HTTP(S) requests in the Browser.
261+
* If provided, this object is merged with the options object passed by the SDK for EventSource and Fetch calls.
262+
* This configuration has no effect in "consumer" mode, as no HTTP(S) requests are made by the SDK.
263+
*/
264+
requestOptions?: {
265+
/**
266+
* Custom function called before each request, allowing you to add or update headers in SDK HTTP requests.
267+
* Some headers, such as `SplitSDKVersion`, are required by the SDK and cannot be overridden.
268+
* To pass multiple headers with the same name, combine their values into a single line, separated by commas. Example: `{ 'Authorization': 'value1, value2' }`
269+
* Or provide keys with different case since headers are case-insensitive. Example: `{ 'authorization': 'value1', 'Authorization': 'value2' }`
270+
*
271+
* NOTE: to pass custom headers to the streaming connection in Browser, you should polyfill the `window.EventSource` object with a library that supports headers,
272+
* like https://www.npmjs.com/package/event-source-polyfill, since native EventSource does not support them and will be ignored.
273+
*
274+
* @property getHeaderOverrides
275+
* @default undefined
276+
*
277+
* @param context - The context for the request.
278+
* @param context.headers - The current headers in the request.
279+
* @returns A set of headers to be merged with the current headers.
280+
*
281+
* @example
282+
* const getHeaderOverrides = (context) => {
283+
* return {
284+
* 'Authorization': context.headers['Authorization'] + ', other-value',
285+
* 'custom-header': 'custom-value'
286+
* };
287+
* };
288+
*/
289+
getHeaderOverrides?: (context: { headers: Record<string, string> }) => Record<string, string>
290+
},
255291
}
256292
}
257293
/**

0 commit comments

Comments
 (0)