Skip to content

Commit 82ebe61

Browse files
Reuse string constant
1 parent aed81d9 commit 82ebe61

File tree

4 files changed

+9
-12
lines changed

4 files changed

+9
-12
lines changed

src/logger/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ export const ENGINE_MATCHER_ERROR = 329;
120120
// Log prefixes (a.k.a. tags or categories)
121121
export const LOG_PREFIX_SETTINGS = 'settings';
122122
export const LOG_PREFIX_INSTANTIATION = 'Factory instantiation';
123+
export const LOG_PREFIX_CLIENT_INSTANTIATION = 'Client instantiation';
123124
export const LOG_PREFIX_ENGINE = 'engine';
124125
export const LOG_PREFIX_ENGINE_COMBINER = LOG_PREFIX_ENGINE + ':combiner: ';
125126
export const LOG_PREFIX_ENGINE_MATCHER = LOG_PREFIX_ENGINE + ':matcher: ';

src/sdkClient/sdkClientMethodCS.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { getMatching, keyParser } from '../utils/key';
55
import { sdkClientFactory } from './sdkClient';
66
import { ISyncManagerCS } from '../sync/types';
77
import { objectAssign } from '../utils/lang/objectAssign';
8-
import { RETRIEVE_CLIENT_DEFAULT, NEW_SHARED_CLIENT, RETRIEVE_CLIENT_EXISTING } from '../logger/constants';
8+
import { RETRIEVE_CLIENT_DEFAULT, NEW_SHARED_CLIENT, RETRIEVE_CLIENT_EXISTING, LOG_PREFIX_CLIENT_INSTANTIATION } from '../logger/constants';
99
import { SDK_SEGMENTS_ARRIVED } from '../readiness/constants';
1010
import { ISdkFactoryContext } from '../sdkFactory/types';
1111

@@ -14,8 +14,6 @@ function buildInstanceId(key: SplitIO.SplitKey) {
1414
return `${key.matchingKey ? key.matchingKey : key}-${key.bucketingKey ? key.bucketingKey : key}-`;
1515
}
1616

17-
const method = 'Client instantiation';
18-
1917
/**
2018
* Factory of client method for the client-side API variant where TT is ignored.
2119
* Therefore, clients don't have a bound TT for the track method.
@@ -43,7 +41,7 @@ export function sdkClientMethodCSFactory(params: ISdkFactoryContext): (key?: Spl
4341
}
4442

4543
// Validate the key value. The trafficType (2nd argument) is ignored
46-
const validKey = validateKey(log, key, method);
44+
const validKey = validateKey(log, key, LOG_PREFIX_CLIENT_INSTANTIATION);
4745
if (validKey === false) {
4846
throw new Error('Shared Client needs a valid key.');
4947
}

src/sdkClient/sdkClientMethodCSWithTT.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { getMatching, keyParser } from '../utils/key';
66
import { sdkClientFactory } from './sdkClient';
77
import { ISyncManagerCS } from '../sync/types';
88
import { objectAssign } from '../utils/lang/objectAssign';
9-
import { RETRIEVE_CLIENT_DEFAULT, NEW_SHARED_CLIENT, RETRIEVE_CLIENT_EXISTING } from '../logger/constants';
9+
import { RETRIEVE_CLIENT_DEFAULT, NEW_SHARED_CLIENT, RETRIEVE_CLIENT_EXISTING, LOG_PREFIX_CLIENT_INSTANTIATION } from '../logger/constants';
1010
import { SDK_SEGMENTS_ARRIVED } from '../readiness/constants';
1111
import { ISdkFactoryContext } from '../sdkFactory/types';
1212

@@ -15,8 +15,6 @@ function buildInstanceId(key: SplitIO.SplitKey, trafficType?: string) {
1515
return `${key.matchingKey ? key.matchingKey : key}-${key.bucketingKey ? key.bucketingKey : key}-${trafficType !== undefined ? trafficType : ''}`;
1616
}
1717

18-
const method = 'Client instantiation';
19-
2018
/**
2119
* Factory of client method for the client-side (browser) variant of the Isomorphic JS SDK,
2220
* where clients can have a bound TT for the track method, which is provided via the settings
@@ -46,14 +44,14 @@ export function sdkClientMethodCSFactory(params: ISdkFactoryContext): (key?: Spl
4644
}
4745

4846
// Validate the key value
49-
const validKey = validateKey(log, key, `Shared ${method}`);
47+
const validKey = validateKey(log, key, LOG_PREFIX_CLIENT_INSTANTIATION);
5048
if (validKey === false) {
5149
throw new Error('Shared Client needs a valid key.');
5250
}
5351

5452
let validTrafficType;
5553
if (trafficType !== undefined) {
56-
validTrafficType = validateTrafficType(log, trafficType, `Shared ${method}`);
54+
validTrafficType = validateTrafficType(log, trafficType, LOG_PREFIX_CLIENT_INSTANTIATION);
5755
if (validTrafficType === false) {
5856
throw new Error('Shared Client needs a valid traffic type or no traffic type at all.');
5957
}

src/utils/settingsValidation/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { ISettingsValidationParams } from './types';
77
import { ISettings } from '../../types';
88
import { validateKey } from '../inputValidation/key';
99
import { validateTrafficType } from '../inputValidation/trafficType';
10-
import { ERROR_MIN_CONFIG_PARAM } from '../../logger/constants';
10+
import { ERROR_MIN_CONFIG_PARAM, LOG_PREFIX_CLIENT_INSTANTIATION } from '../../logger/constants';
1111

1212
// Exported for telemetry
1313
export const base = {
@@ -166,13 +166,13 @@ export function settingsValidation(config: unknown, validationParams: ISettingsV
166166
// Keeping same behaviour than JS SDK: if settings key or TT are invalid,
167167
// `false` value is used as bound key/TT of the default client, which leads to some issues.
168168
// @ts-ignore, @TODO handle invalid keys as a non-recoverable error?
169-
withDefaults.core.key = validateKey(log, maybeKey, 'Client instantiation');
169+
withDefaults.core.key = validateKey(log, maybeKey, LOG_PREFIX_CLIENT_INSTANTIATION);
170170
}
171171

172172
if (validationParams.acceptTT) {
173173
const maybeTT = withDefaults.core.trafficType;
174174
if (maybeTT !== undefined) { // @ts-ignore
175-
withDefaults.core.trafficType = validateTrafficType(log, maybeTT, 'Client instantiation');
175+
withDefaults.core.trafficType = validateTrafficType(log, maybeTT, LOG_PREFIX_CLIENT_INSTANTIATION);
176176
}
177177
}
178178
} else {

0 commit comments

Comments
 (0)