Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions src/services/splitHttpClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,26 @@ const messageNoFetch = 'Global fetch API is not available.';
*/
export function splitHttpClientFactory(settings: Pick<ISettings, 'log' | 'version' | 'runtime' | 'core'>, getFetch?: () => (IFetch | undefined), getOptions?: () => object): ISplitHttpClient {

const { log, core: { authorizationKey }, version, runtime: { ip, hostname } } = settings;
const log = settings.log;
const options = getOptions && getOptions();
const fetch = getFetch && getFetch();

// if fetch is not available, log Error
if (!fetch) log.error(ERROR_CLIENT_CANNOT_GET_READY, [messageNoFetch]);

const headers: Record<string, string> = {
'Accept': 'application/json',
'Content-Type': 'application/json',
'Authorization': `Bearer ${authorizationKey}`,
'SplitSDKVersion': version
};
return function httpClient(url: string, reqOpts: IRequestOptions = {}, logErrorsAsInfo: boolean = false): Promise<IResponse> {

if (ip) headers['SplitSDKMachineIP'] = ip;
if (hostname) headers['SplitSDKMachineName'] = hostname;
const { core: { authorizationKey }, version, runtime: { ip, hostname } } = settings;

return function httpClient(url: string, reqOpts: IRequestOptions = {}, logErrorsAsInfo: boolean = false): Promise<IResponse> {
const headers: Record<string, string> = {
'Accept': 'application/json',
'Content-Type': 'application/json',
'Authorization': `Bearer ${authorizationKey}`,
'SplitSDKVersion': version
};

if (ip) headers['SplitSDKMachineIP'] = ip;
if (hostname) headers['SplitSDKMachineName'] = hostname;

const request = objectAssign({
headers: reqOpts.headers ? objectAssign({}, headers, reqOpts.headers) : headers,
Expand Down
8 changes: 4 additions & 4 deletions src/trackers/impressionsTracker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export function impressionsTrackerFactory(
countsCache?: IImpressionCountsCacheSync
): IImpressionsTracker {

const { log, impressionListener, runtime: { ip, hostname }, version } = settings;
const { log, impressionListener, runtime: { ip, hostname } } = settings;

return {
track(impressions: ImpressionDTO[], attributes?: SplitIO.Attributes) {
Expand Down Expand Up @@ -74,9 +74,9 @@ export function impressionsTrackerFactory(
// copy of impression, to avoid unexpected behaviour if modified by integrations or impressionListener
impression: objectAssign({}, impressions[i]),
attributes,
ip: ip as string,
hostname: hostname as string,
sdkLanguageVersion: version
ip,
hostname,
sdkLanguageVersion: settings.version
};

// Wrap in a timeout because we don't want it to be blocking.
Expand Down
4 changes: 2 additions & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -535,8 +535,8 @@ export namespace SplitIO {
export type ImpressionData = {
impression: ImpressionDTO,
attributes?: SplitIO.Attributes,
ip: string,
hostname: string,
ip: string| false,
hostname: string | false,
sdkLanguageVersion: string
};
/**
Expand Down