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
2 changes: 1 addition & 1 deletion src/logger/messages/warn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export const codesWarn: [number, string][] = codesError.concat([
[c.WARN_LOWERCASE_TRAFFIC_TYPE, '%s: traffic_type_name should be all lowercase - converting string to lowercase.'],
[c.WARN_NOT_EXISTENT_TT, '%s: traffic type "%s" does not have any corresponding split in this environment, make sure you\'re tracking your events to a valid traffic type defined in the web console.'],
// initialization / settings validation
[c.WARN_INTEGRATION_INVALID, c.logPrefixSettings+': %s integration %s at settings %s invalid. %s'],
[c.WARN_INTEGRATION_INVALID, c.logPrefixSettings+': %s integration item(s) at settings is invalid. %s'],
[c.WARN_SPLITS_FILTER_IGNORED, c.logPrefixSettings+': split filters have been configured but will have no effect if mode is not "%s", since synchronization is being deferred to an external tool.'],
[c.WARN_SPLITS_FILTER_INVALID, c.logPrefixSettings+': split filter at position %s is invalid. It must be an object with a valid filter type ("byName" or "byPrefix") and a list of "values".'],
[c.WARN_SPLITS_FILTER_EMPTY, c.logPrefixSettings+': splitFilters configuration must be a non-empty array of filter objects.'],
Expand Down
8 changes: 4 additions & 4 deletions src/utils/inputValidation/__tests__/apiKey.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ describe('validateAndTrackApiKey', () => {
expect(validateAndTrackApiKey(loggerMock, validApiKey)).toBe(validApiKey);

expect(loggerMock.warn.mock.calls).toEqual([
[WARN_API_KEY, ['1 factory with this API Key']],
[WARN_API_KEY, ['2 factories with this API Key']],
[WARN_API_KEY, ['3 factories with this API Key']]
[WARN_API_KEY, ['1 factory/ies with this API Key']],
[WARN_API_KEY, ['2 factory/ies with this API Key']],
[WARN_API_KEY, ['3 factory/ies with this API Key']]
]); // We get a warning each time we register the same api key, with the number of instances we have.

// We will release the used api key leaving only 1 "use" on the cache.
Expand All @@ -100,7 +100,7 @@ describe('validateAndTrackApiKey', () => {

// So we get the warning again.
expect(validateAndTrackApiKey(loggerMock, validApiKey)).toBe(validApiKey);
expect(loggerMock.warn).toBeCalledWith(WARN_API_KEY, ['1 factory with this API Key']);
expect(loggerMock.warn).toBeCalledWith(WARN_API_KEY, ['1 factory/ies with this API Key']);

// Leave it with 0
releaseApiKey(validApiKey);
Expand Down
2 changes: 1 addition & 1 deletion src/utils/inputValidation/__tests__/event.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ describe('INPUT VALIDATION for Event types', () => {
const expectedLog = invalidEvents[i]['msg'];

expect(validateEvent(loggerMock, invalidValue, 'test_method')).toBe(false); // Invalid event types should always return false.
expect(loggerMock.error).toBeCalledWith(expectedLog, expectedLog === ERROR_EVENT_TYPE_FORMAT ? ['test_method', invalidValue] : ['test_method']); // Should log the error for the invalid event type.
expect(loggerMock.error).toBeCalledWith(expectedLog, expectedLog === ERROR_EVENT_TYPE_FORMAT ? ['test_method', invalidValue] : ['test_method', 'event_type']); // Should log the error for the invalid event type.

loggerMock.error.mockClear();
}
Expand Down
2 changes: 1 addition & 1 deletion src/utils/inputValidation/__tests__/trafficType.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ describe('INPUT VALIDATION for Traffic Types', () => {
const expectedLog = invalidTrafficTypes[i]['msg'];

expect(validateTrafficType(loggerMock, invalidValue, 'test_method')).toBe(false); // Invalid traffic types should always return false.
expect(loggerMock.error.mock.calls[i]).toEqual([expectedLog, ['test_method']]); // Should log the error for the invalid traffic type.
expect(loggerMock.error.mock.calls[i]).toEqual([expectedLog, ['test_method', 'traffic_type']]); // Should log the error for the invalid traffic type.
}

expect(loggerMock.warn).not.toBeCalled(); // It should have not logged any warnings.
Expand Down
2 changes: 1 addition & 1 deletion src/utils/inputValidation/apiKey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export function validateAndTrackApiKey(log: ILogger, maybeApiKey: any): string |
log.warn(WARN_API_KEY, ['an instance of the Split factory']);
}
} else {
log.warn(WARN_API_KEY, [`${usedKeysMap[apiKey]} ${usedKeysMap[apiKey] === 1 ? 'factory' : 'factories'} with this API Key`]);
log.warn(WARN_API_KEY, [`${usedKeysMap[apiKey]} factory/ies with this API Key`]);
usedKeysMap[apiKey]++;
}
}
Expand Down
7 changes: 4 additions & 3 deletions src/utils/inputValidation/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@ import { ILogger } from '../../logger/types';
import { isString } from '../lang';

const EVENT_TYPE_REGEX = /^[a-zA-Z0-9][-_.:a-zA-Z0-9]{0,79}$/;
const item = 'event_type';

export function validateEvent(log: ILogger, maybeEvent: any, method: string): string | false {
if (maybeEvent == undefined) { // eslint-disable-line eqeqeq
log.error(ERROR_NULL, [method]);
log.error(ERROR_NULL, [method, item]);
} else if (!isString(maybeEvent)) {
log.error(ERROR_INVALID, [method]);
log.error(ERROR_INVALID, [method, item]);
} else { // It is a string.
if (maybeEvent.length === 0) {
log.error(ERROR_EMPTY, [method]);
log.error(ERROR_EMPTY, [method, item]);
} else if (!EVENT_TYPE_REGEX.test(maybeEvent)) {
log.error(ERROR_EVENT_TYPE_FORMAT, [method, maybeEvent]);
} else {
Expand Down
7 changes: 4 additions & 3 deletions src/utils/inputValidation/trafficType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@ import { ILogger } from '../../logger/types';
import { isString } from '../lang';

const CAPITAL_LETTERS_REGEX = /[A-Z]/;
const item = 'traffic_type';

export function validateTrafficType(log: ILogger, maybeTT: any, method: string): string | false {
if (maybeTT == undefined) { // eslint-disable-line eqeqeq
log.error(ERROR_NULL, [method]);
log.error(ERROR_NULL, [method, item]);
} else if (!isString(maybeTT)) {
log.error(ERROR_INVALID, [method]);
log.error(ERROR_INVALID, [method, item]);
} else {
if (maybeTT.length === 0) {
log.error(ERROR_EMPTY, [method]);
log.error(ERROR_EMPTY, [method, item]);
} else {
if (CAPITAL_LETTERS_REGEX.test(maybeTT)) {
log.warn(WARN_LOWERCASE_TRAFFIC_TYPE, [method]);
Expand Down
2 changes: 1 addition & 1 deletion src/utils/settingsValidation/integrations/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export function validateIntegrations(settings: { log: ILogger, integrations?: an

// Log a warning if at least one item is invalid
const invalids = integrations.length - validIntegrations.length;
if (invalids) log.warn(WARN_INTEGRATION_INVALID, [invalids, invalids === 1 ? 'item' : 'items', invalids === 1 ? 'is' : 'are', extraWarning || '']);
if (invalids) log.warn(WARN_INTEGRATION_INVALID, [invalids, extraWarning || '']);

return validIntegrations;
}