From 3ed29924d668c8cd55d549947b538c1ed84dbd65 Mon Sep 17 00:00:00 2001 From: Emiliano Sanchez Date: Wed, 13 Apr 2022 14:20:15 -0300 Subject: [PATCH] updated how settings version is accessed --- src/services/splitHttpClient.ts | 22 ++++++++++++---------- src/trackers/impressionsTracker.ts | 8 ++++---- src/types.ts | 4 ++-- 3 files changed, 18 insertions(+), 16 deletions(-) diff --git a/src/services/splitHttpClient.ts b/src/services/splitHttpClient.ts index d9ec90f7..b5df0e68 100644 --- a/src/services/splitHttpClient.ts +++ b/src/services/splitHttpClient.ts @@ -14,24 +14,26 @@ const messageNoFetch = 'Global fetch API is not available.'; */ export function splitHttpClientFactory(settings: Pick, 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 = { - 'Accept': 'application/json', - 'Content-Type': 'application/json', - 'Authorization': `Bearer ${authorizationKey}`, - 'SplitSDKVersion': version - }; + return function httpClient(url: string, reqOpts: IRequestOptions = {}, logErrorsAsInfo: boolean = false): Promise { - 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 { + const headers: Record = { + '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, diff --git a/src/trackers/impressionsTracker.ts b/src/trackers/impressionsTracker.ts index ecd40a5d..f3274678 100644 --- a/src/trackers/impressionsTracker.ts +++ b/src/trackers/impressionsTracker.ts @@ -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) { @@ -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. diff --git a/src/types.ts b/src/types.ts index 7d523223..6c330eec 100644 --- a/src/types.ts +++ b/src/types.ts @@ -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 }; /**