Skip to content

Commit 30d102f

Browse files
Remove feature flag name from SDK not ready warning message and simplify validation function signatures
1 parent c3d9730 commit 30d102f

6 files changed

Lines changed: 59 additions & 11 deletions

File tree

src/logger/messages/warn.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export const codesWarn: [number, string][] = codesError.concat([
1414
[c.SUBMITTERS_PUSH_FAILS, c.LOG_PREFIX_SYNC_SUBMITTERS + 'Dropping %s after retry. Reason: %s.'],
1515
[c.SUBMITTERS_PUSH_RETRY, c.LOG_PREFIX_SYNC_SUBMITTERS + 'Failed to push %s, keeping data to retry on next iteration. Reason: %s.'],
1616
// client status
17-
[c.CLIENT_NOT_READY_FROM_CACHE, '%s: the SDK is not ready to evaluate. Results may be incorrect%s. Make sure to wait for SDK readiness before using this method.'],
17+
[c.CLIENT_NOT_READY_FROM_CACHE, '%s: the SDK is not ready to evaluate. Results may be incorrect. Make sure to wait for SDK readiness before using this method.'],
1818
[c.CLIENT_NO_LISTENER, 'No listeners for SDK_READY event detected. Incorrect control treatments could have been logged if you called getTreatment/s while the SDK was not yet synchronized with the backend.'],
1919
// input validation
2020
[c.WARN_SETTING_NULL, '%s: Property "%s" is of invalid type. Setting value to null.'],

src/sdkClient/clientInputValidation.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export function clientInputValidationDecorator<TClient extends SplitIO.IClient |
4646
const isNotDestroyed = validateIfNotDestroyed(log, readinessManager, methodName);
4747
const options = validateEvaluationOptions(log, maybeOptions, methodName);
4848

49-
validateIfReadyFromCache(log, readinessManager, methodName, nameOrNames);
49+
validateIfReadyFromCache(log, readinessManager, methodName);
5050

5151
const valid = isNotDestroyed && key && nameOrNames && attributes !== false;
5252

src/sdkConfig/index-ff-wrapper.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export function configsClientFactory(params: ISdkFactoryParams): SplitIO.Configs
4141
if (target) {
4242
// Serve config with target
4343
if (validateTarget(log, target, GET_CONFIG)) {
44-
const result = ffClient.getTreatmentWithConfig(target.key, name, target.attributes, target) as SplitIO.TreatmentWithConfig;
44+
const result = ffClient.getTreatmentWithConfig(target.key, name, target.attributes) as SplitIO.TreatmentWithConfig;
4545
return parseConfig(result.config);
4646
} else {
4747
log.error('Invalid target for getConfig.');

src/utils/inputValidation/__tests__/isOperational.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ describe('validateIfReadyFromCache', () => {
4646
// @ts-ignore
4747
expect(validateIfReadyFromCache(loggerMock, readinessManagerMock, 'test_method')).toBe(false); // It should return true if SDK was ready.
4848
expect(readinessManagerMock.isReadyFromCache).toBeCalledTimes(1); // It checks for SDK_READY_FROM_CACHE status.
49-
expect(loggerMock.warn).toBeCalledWith(CLIENT_NOT_READY_FROM_CACHE, ['test_method', '']); // It should log the expected warning.
49+
expect(loggerMock.warn).toBeCalledWith(CLIENT_NOT_READY_FROM_CACHE, ['test_method']); // It should log the expected warning.
5050
expect(loggerMock.error).not.toBeCalled(); // But it should not log any errors.
5151
});
5252
});

src/utils/inputValidation/isOperational.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ export function validateIfNotDestroyed(log: ILogger, readinessManager: IReadines
99
return false;
1010
}
1111

12-
export function validateIfReadyFromCache(log: ILogger, readinessManager: IReadinessManager, method: string, featureFlagNameOrNames?: string | string[] | false) {
12+
export function validateIfReadyFromCache(log: ILogger, readinessManager: IReadinessManager, method: string) {
1313
if (readinessManager.isReadyFromCache()) return true;
1414

15-
log.warn(CLIENT_NOT_READY_FROM_CACHE, [method, featureFlagNameOrNames ? ` for feature flag ${featureFlagNameOrNames.toString()}` : '']);
15+
log.warn(CLIENT_NOT_READY_FROM_CACHE, [method]);
1616
return false;
1717
}
1818

1919
// Operational means that the SDK is ready to evaluate (not destroyed and ready from cache)
20-
export function validateIfOperational(log: ILogger, readinessManager: IReadinessManager, method: string, featureFlagNameOrNames?: string | string[] | false) {
21-
return validateIfNotDestroyed(log, readinessManager, method) && validateIfReadyFromCache(log, readinessManager, method, featureFlagNameOrNames);
20+
export function validateIfOperational(log: ILogger, readinessManager: IReadinessManager, method: string) {
21+
return validateIfNotDestroyed(log, readinessManager, method) && validateIfReadyFromCache(log, readinessManager, method);
2222
}

types/splitio.d.ts

Lines changed: 51 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2287,7 +2287,7 @@ declare namespace SplitIO {
22872287

22882288
// Configs SDK
22892289

2290-
interface Target extends EvaluationOptions {
2290+
interface Target {
22912291
key: SplitKey;
22922292
attributes?: Attributes;
22932293
}
@@ -2300,6 +2300,7 @@ declare namespace SplitIO {
23002300
getArray(propertyName: string): ConfigArray;
23012301
getObject(propertyName: string): Config;
23022302
}
2303+
23032304
interface ConfigArray {
23042305
value: any;
23052306
getString(index: number, propertyDefaultValue?: string): string;
@@ -2310,7 +2311,7 @@ declare namespace SplitIO {
23102311
}
23112312

23122313
/**
2313-
* Common definitions between SDK instances for different environments interface.
2314+
* Configs SDK client interface.
23142315
*/
23152316
interface ConfigsClient extends IStatusInterface {
23162317
/**
@@ -2342,7 +2343,7 @@ declare namespace SplitIO {
23422343
* @param target - The target of the config we want to get.
23432344
* @returns The config object.
23442345
*/
2345-
getConfig(name: string, target?: Target): Config;
2346+
getConfig(name: string, target?: Target, options?: EvaluationOptions): Config;
23462347
/**
23472348
* Tracks an event to be fed to the results product on Split user interface.
23482349
*
@@ -2355,4 +2356,51 @@ declare namespace SplitIO {
23552356
*/
23562357
track(key: SplitKey, trafficType: string, eventType: string, value?: number, properties?: Properties): boolean;
23572358
}
2359+
2360+
/**
2361+
* Configs SDK client interface with async methods.
2362+
*/
2363+
interface AsyncConfigsClient extends IStatusInterface {
2364+
/**
2365+
* Current settings of the SDK instance.
2366+
*/
2367+
settings: ISettings;
2368+
/**
2369+
* Logger API.
2370+
*/
2371+
Logger: ILoggerAPI;
2372+
/**
2373+
* Initializes the client.
2374+
*/
2375+
init(): void;
2376+
/**
2377+
* Flushes the client.
2378+
*/
2379+
flush(): Promise<void>;
2380+
/**
2381+
* Destroys the client.
2382+
*
2383+
* @returns A promise that resolves once all clients are destroyed.
2384+
*/
2385+
destroy(): Promise<void>;
2386+
/**
2387+
* Gets the config object for a given config name and optional target. If no target is provided, the default variant of the config is returned.
2388+
*
2389+
* @param name - The name of the config we want to get.
2390+
* @param target - The target of the config we want to get.
2391+
* @returns A promise that resolves with the config object.
2392+
*/
2393+
getConfig(name: string, target?: Target, options?: EvaluationOptions): Promise<Config>;
2394+
/**
2395+
* Tracks an event to be fed to the results product on Split user interface.
2396+
*
2397+
* @param key - The key that identifies the entity related to this event.
2398+
* @param trafficType - The traffic type of the entity related to this event. See {@link https://developer.harness.io/docs/feature-management-experimentation/management-and-administration/fme-settings/traffic-types/}
2399+
* @param eventType - The event type corresponding to this event.
2400+
* @param value - The value of this event.
2401+
* @param properties - The properties of this event. Values can be string, number, boolean or null.
2402+
* @returns A promise that resolves with a boolean indicating whether the event was added to the queue successfully or not.
2403+
*/
2404+
track(key: SplitKey, trafficType: string, eventType: string, value?: number, properties?: Properties): Promise<boolean>;
2405+
}
23582406
}

0 commit comments

Comments
 (0)