Skip to content

Commit

Permalink
Merge pull request #817 from splitio/enhanced_sdk_headers
Browse files Browse the repository at this point in the history
[Enhanced SDK headers] Update type definitions
  • Loading branch information
EmilianoSanchez authored Sep 6, 2024
2 parents 15fd63e + 38c45ee commit 051d5c5
Show file tree
Hide file tree
Showing 7 changed files with 95 additions and 27 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ jobs:

steps:
- name: Download assets
uses: actions/download-artifact@v4.1.7
uses: actions/download-artifact@v3
with:
name: assets
path: umd
Expand Down Expand Up @@ -120,7 +120,7 @@ jobs:

steps:
- name: Download assets
uses: actions/download-artifact@v4.1.7
uses: actions/download-artifact@v3
with:
name: assets
path: umd
Expand Down
5 changes: 5 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
10.28.0 (September 6, 2024)
- Updated @splitsoftware/splitio-commons package to version 1.17.0 that includes minor updates:
- Added `sync.requestOptions.getHeaderOverrides` configuration option to enhance SDK HTTP request Headers for Authorization Frameworks.
- Updated some transitive dependencies for vulnerability fixes.

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.
Expand Down
34 changes: 17 additions & 17 deletions package-lock.json

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

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@splitsoftware/splitio",
"version": "10.27.0",
"version": "10.28.0",
"description": "Split SDK",
"files": [
"README.md",
Expand Down Expand Up @@ -40,7 +40,7 @@
"node": ">=6"
},
"dependencies": {
"@splitsoftware/splitio-commons": "1.16.0",
"@splitsoftware/splitio-commons": "1.17.0",
"@types/google.analytics": "0.0.40",
"@types/ioredis": "^4.28.0",
"bloom-filters": "^3.0.0",
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.27.0';
export const packageVersion = '10.28.0';
10 changes: 7 additions & 3 deletions ts-tests/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ splitView = {
configs: {
off: '{"dimensions":"{\"height\":20,\"width\":40}"}'
},
sets: ['set_a','set_b'],
sets: ['set_a', 'set_b'],
defaultTreatment: 'off'
};
splitViews = [splitView];
Expand Down Expand Up @@ -565,7 +565,10 @@ let fullBrowserSettings: SplitIO.IBrowserSettings = {
sync: {
splitFilters: splitFilters,
impressionsMode: 'DEBUG',
enabled: true
enabled: true,
requestOptions: {
getHeaderOverrides(context) { return { ...context.headers, 'header': 'value' } },
}
},
userConsent: 'GRANTED'
};
Expand Down Expand Up @@ -618,6 +621,7 @@ let fullNodeSettings: SplitIO.INodeSettings = {
impressionsMode: 'OPTIMIZED',
enabled: true,
requestOptions: {
getHeaderOverrides(context) { return { ...context.headers, 'header': 'value' } },
agent: new (require('https')).Agent(),
}
}
Expand Down Expand Up @@ -666,7 +670,7 @@ let fullAsyncSettings: SplitIO.INodeAsyncSettings = {
mode: 'consumer',
debug: true,
sync: {
splitFilters: splitFilters
splitFilters: splitFilters,
}
};

Expand Down
63 changes: 61 additions & 2 deletions types/splitio.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,11 @@ interface ISettings {
readonly sync: {
splitFilters: SplitIO.SplitFilter[],
impressionsMode: SplitIO.ImpressionsMode,
enabled: boolean
enabled: boolean,
flagSpecVersion: string,
requestOptions?: {
getHeaderOverrides?: (context: { headers: Record<string, string> }) => Record<string, string>
}
}
/**
* User consent status if using in browser. Undefined if using in NodeJS.
Expand Down Expand Up @@ -1126,7 +1130,40 @@ declare namespace SplitIO {
* @typedef {string} userConsent
* @default 'GRANTED'
*/
userConsent?: ConsentStatus
userConsent?: ConsentStatus,
sync?: ISharedSettings['sync'] & {
/**
* Custom options object for HTTP(S) requests in the Browser.
* If provided, this object is merged with the options object passed by the SDK for EventSource and Fetch calls.
*/
requestOptions?: {
/**
* Custom function called before each request, allowing you to add or update headers in SDK HTTP requests.
* Some headers, such as `SplitSDKVersion`, are required by the SDK and cannot be overridden.
* To pass multiple headers with the same name, combine their values into a single line, separated by commas. Example: `{ 'Authorization': 'value1, value2' }`
* Or provide keys with different case since headers are case-insensitive. Example: `{ 'authorization': 'value1', 'Authorization': 'value2' }`
*
* NOTE: to pass custom headers to the streaming connection in Browser, you should polyfill the `window.EventSource` object with a library that supports headers,
* like https://www.npmjs.com/package/event-source-polyfill, since native EventSource does not support them and will be ignored.
*
* @property getHeaderOverrides
* @default undefined
*
* @param context - The context for the request.
* @param context.headers - The current headers in the request.
* @returns A set of headers to be merged with the current headers.
*
* @example
* const getHeaderOverrides = (context) => {
* return {
* 'Authorization': context.headers['Authorization'] + ', other-value',
* 'custom-header': 'custom-value'
* };
* };
*/
getHeaderOverrides?: (context: { headers: Record<string, string> }) => Record<string, string>
},
}
}
/**
* Settings interface for SDK instances created on NodeJS.
Expand Down Expand Up @@ -1176,6 +1213,28 @@ declare namespace SplitIO {
* @see {@link https://www.npmjs.com/package/node-fetch#options}
*/
requestOptions?: {
/**
* Custom function called before each request, allowing you to add or update headers in SDK HTTP requests.
* Some headers, such as `SplitSDKVersion`, are required by the SDK and cannot be overridden.
* To pass multiple headers with the same name, combine their values into a single line, separated by commas. Example: `{ 'Authorization': 'value1, value2' }`
* Or provide keys with different case since headers are case-insensitive. Example: `{ 'authorization': 'value1', 'Authorization': 'value2' }`
*
* @property getHeaderOverrides
* @default undefined
*
* @param context - The context for the request.
* @param context.headers - The current headers in the request.
* @returns A set of headers to be merged with the current headers.
*
* @example
* const getHeaderOverrides = (context) => {
* return {
* 'Authorization': context.headers['Authorization'] + ', other-value',
* 'custom-header': 'custom-value'
* };
* };
*/
getHeaderOverrides?: (context: { headers: Record<string, string> }) => Record<string, string>
/**
* Custom NodeJS HTTP(S) Agent used by the SDK for HTTP(S) requests.
*
Expand Down

0 comments on commit 051d5c5

Please sign in to comment.