Skip to content

Commit 051d5c5

Browse files
Merge pull request #817 from splitio/enhanced_sdk_headers
[Enhanced SDK headers] Update type definitions
2 parents 15fd63e + 38c45ee commit 051d5c5

File tree

7 files changed

+95
-27
lines changed

7 files changed

+95
-27
lines changed

.github/workflows/ci-cd.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ jobs:
8181

8282
steps:
8383
- name: Download assets
84-
uses: actions/download-artifact@v4.1.7
84+
uses: actions/download-artifact@v3
8585
with:
8686
name: assets
8787
path: umd
@@ -120,7 +120,7 @@ jobs:
120120

121121
steps:
122122
- name: Download assets
123-
uses: actions/download-artifact@v4.1.7
123+
uses: actions/download-artifact@v3
124124
with:
125125
name: assets
126126
path: umd

CHANGES.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
10.28.0 (September 6, 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.
5+
16
10.27.0 (June 25, 2024)
27
- 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).
38
- Updated some transitive dependencies for vulnerability 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",
3-
"version": "10.27.0",
3+
"version": "10.28.0",
44
"description": "Split SDK",
55
"files": [
66
"README.md",
@@ -40,7 +40,7 @@
4040
"node": ">=6"
4141
},
4242
"dependencies": {
43-
"@splitsoftware/splitio-commons": "1.16.0",
43+
"@splitsoftware/splitio-commons": "1.17.0",
4444
"@types/google.analytics": "0.0.40",
4545
"@types/ioredis": "^4.28.0",
4646
"bloom-filters": "^3.0.0",

src/settings/defaults/version.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export const packageVersion = '10.27.0';
1+
export const packageVersion = '10.28.0';

ts-tests/index.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ splitView = {
124124
configs: {
125125
off: '{"dimensions":"{\"height\":20,\"width\":40}"}'
126126
},
127-
sets: ['set_a','set_b'],
127+
sets: ['set_a', 'set_b'],
128128
defaultTreatment: 'off'
129129
};
130130
splitViews = [splitView];
@@ -565,7 +565,10 @@ let fullBrowserSettings: SplitIO.IBrowserSettings = {
565565
sync: {
566566
splitFilters: splitFilters,
567567
impressionsMode: 'DEBUG',
568-
enabled: true
568+
enabled: true,
569+
requestOptions: {
570+
getHeaderOverrides(context) { return { ...context.headers, 'header': 'value' } },
571+
}
569572
},
570573
userConsent: 'GRANTED'
571574
};
@@ -618,6 +621,7 @@ let fullNodeSettings: SplitIO.INodeSettings = {
618621
impressionsMode: 'OPTIMIZED',
619622
enabled: true,
620623
requestOptions: {
624+
getHeaderOverrides(context) { return { ...context.headers, 'header': 'value' } },
621625
agent: new (require('https')).Agent(),
622626
}
623627
}
@@ -666,7 +670,7 @@ let fullAsyncSettings: SplitIO.INodeAsyncSettings = {
666670
mode: 'consumer',
667671
debug: true,
668672
sync: {
669-
splitFilters: splitFilters
673+
splitFilters: splitFilters,
670674
}
671675
};
672676

types/splitio.d.ts

Lines changed: 61 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,11 @@ interface ISettings {
111111
readonly sync: {
112112
splitFilters: SplitIO.SplitFilter[],
113113
impressionsMode: SplitIO.ImpressionsMode,
114-
enabled: boolean
114+
enabled: boolean,
115+
flagSpecVersion: string,
116+
requestOptions?: {
117+
getHeaderOverrides?: (context: { headers: Record<string, string> }) => Record<string, string>
118+
}
115119
}
116120
/**
117121
* User consent status if using in browser. Undefined if using in NodeJS.
@@ -1126,7 +1130,40 @@ declare namespace SplitIO {
11261130
* @typedef {string} userConsent
11271131
* @default 'GRANTED'
11281132
*/
1129-
userConsent?: ConsentStatus
1133+
userConsent?: ConsentStatus,
1134+
sync?: ISharedSettings['sync'] & {
1135+
/**
1136+
* Custom options object for HTTP(S) requests in the Browser.
1137+
* If provided, this object is merged with the options object passed by the SDK for EventSource and Fetch calls.
1138+
*/
1139+
requestOptions?: {
1140+
/**
1141+
* Custom function called before each request, allowing you to add or update headers in SDK HTTP requests.
1142+
* Some headers, such as `SplitSDKVersion`, are required by the SDK and cannot be overridden.
1143+
* To pass multiple headers with the same name, combine their values into a single line, separated by commas. Example: `{ 'Authorization': 'value1, value2' }`
1144+
* Or provide keys with different case since headers are case-insensitive. Example: `{ 'authorization': 'value1', 'Authorization': 'value2' }`
1145+
*
1146+
* NOTE: to pass custom headers to the streaming connection in Browser, you should polyfill the `window.EventSource` object with a library that supports headers,
1147+
* like https://www.npmjs.com/package/event-source-polyfill, since native EventSource does not support them and will be ignored.
1148+
*
1149+
* @property getHeaderOverrides
1150+
* @default undefined
1151+
*
1152+
* @param context - The context for the request.
1153+
* @param context.headers - The current headers in the request.
1154+
* @returns A set of headers to be merged with the current headers.
1155+
*
1156+
* @example
1157+
* const getHeaderOverrides = (context) => {
1158+
* return {
1159+
* 'Authorization': context.headers['Authorization'] + ', other-value',
1160+
* 'custom-header': 'custom-value'
1161+
* };
1162+
* };
1163+
*/
1164+
getHeaderOverrides?: (context: { headers: Record<string, string> }) => Record<string, string>
1165+
},
1166+
}
11301167
}
11311168
/**
11321169
* Settings interface for SDK instances created on NodeJS.
@@ -1176,6 +1213,28 @@ declare namespace SplitIO {
11761213
* @see {@link https://www.npmjs.com/package/node-fetch#options}
11771214
*/
11781215
requestOptions?: {
1216+
/**
1217+
* Custom function called before each request, allowing you to add or update headers in SDK HTTP requests.
1218+
* Some headers, such as `SplitSDKVersion`, are required by the SDK and cannot be overridden.
1219+
* To pass multiple headers with the same name, combine their values into a single line, separated by commas. Example: `{ 'Authorization': 'value1, value2' }`
1220+
* Or provide keys with different case since headers are case-insensitive. Example: `{ 'authorization': 'value1', 'Authorization': 'value2' }`
1221+
*
1222+
* @property getHeaderOverrides
1223+
* @default undefined
1224+
*
1225+
* @param context - The context for the request.
1226+
* @param context.headers - The current headers in the request.
1227+
* @returns A set of headers to be merged with the current headers.
1228+
*
1229+
* @example
1230+
* const getHeaderOverrides = (context) => {
1231+
* return {
1232+
* 'Authorization': context.headers['Authorization'] + ', other-value',
1233+
* 'custom-header': 'custom-value'
1234+
* };
1235+
* };
1236+
*/
1237+
getHeaderOverrides?: (context: { headers: Record<string, string> }) => Record<string, string>
11791238
/**
11801239
* Custom NodeJS HTTP(S) Agent used by the SDK for HTTP(S) requests.
11811240
*

0 commit comments

Comments
 (0)