Skip to content

Commit

Permalink
Merge branch 'development' of https://github.com/splitio/javascript-c…
Browse files Browse the repository at this point in the history
…ommons into sdks-7437
  • Loading branch information
Emmanuel Zamora committed Oct 20, 2023
2 parents d2655ca + 94fc1cc commit 40750b5
Show file tree
Hide file tree
Showing 16 changed files with 145 additions and 123 deletions.
8 changes: 8 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
1.10.0 (October 20, 2023)
- Added `defaultTreatment` property to the `SplitView` object returned by the `split` and `splits` methods of the SDK manager (Related to issue https://github.com/splitio/javascript-commons/issues/225).
- Updated log warning message to include the feature flag name when `getTreatment` method is called and the SDK client is not ready.

1.9.2 (October 19, 2023)
- Updated client module to support the Split Suite.
- Updated some transitive dependencies for vulnerability fixes.

1.9.1 (September 21, 2023)
- Updated browser listener to avoid registering a handler for 'unload' DOM events, that can prevent browsers from being able to put pages in the back/forward cache for faster back and forward loads (Related to issue https://github.com/splitio/javascript-client/issues/759).

Expand Down
218 changes: 110 additions & 108 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@splitsoftware/splitio-commons",
"version": "1.9.2-rc.1",
"version": "1.10.0",
"description": "Split Javascript SDK common components",
"main": "cjs/index.js",
"module": "esm/index.js",
Expand Down
2 changes: 1 addition & 1 deletion src/logger/messages/info.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as c from '../constants';
import { codesWarn } from './warn';

const READY_MSG = 'Split SDK is ready';
const READY_MSG = 'Split SDK client is ready';

export const codesInfo: [number, string][] = codesWarn.concat([
// client status
Expand Down
2 changes: 1 addition & 1 deletion src/logger/messages/warn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const codesWarn: [number, string][] = codesError.concat([
[c.SUBMITTERS_PUSH_FAILS, c.LOG_PREFIX_SYNC_SUBMITTERS + 'Dropping %s after retry. Reason: %s.'],
[c.SUBMITTERS_PUSH_RETRY, c.LOG_PREFIX_SYNC_SUBMITTERS + 'Failed to push %s, keeping data to retry on next iteration. Reason: %s.'],
// client status
[c.CLIENT_NOT_READY, '%s: the SDK is not ready, results may be incorrect. Make sure to wait for SDK readiness before using this method.'],
[c.CLIENT_NOT_READY, '%s: the SDK is not ready, results may be incorrect%s. Make sure to wait for SDK readiness before using this method.'],
[c.CLIENT_NO_LISTENER, 'No listeners for SDK Readiness detected. Incorrect control treatments could have been logged if you called getTreatment/s while the SDK was not yet ready.'],
// input validation
[c.WARN_SETTING_NULL, '%s: Property "%s" is of invalid type. Setting value to null.'],
Expand Down
5 changes: 4 additions & 1 deletion src/sdkClient/clientCS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ export function clientCSDecorator(log: ILogger, client: SplitIO.IClient, key: Sp
// Key is bound to the `track` method. Same thing happens with trafficType but only if provided
track: trafficType ? clientCS.track.bind(clientCS, key, trafficType) : clientCS.track.bind(clientCS, key),

isClientSide: true
// Not part of the public API. These properties are used to support other modules (e.g., Split Suite)
isClientSide: true,
key,
trafficType
}) as SplitIO.ICsClient;
}
3 changes: 2 additions & 1 deletion src/sdkClient/clientInputValidation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ export function clientInputValidationDecorator<TClient extends SplitIO.IClient |
if (maybeFlagSetNameOrNames) {
flagSetOrFlagSets = flagSetsAreValid(log, methodName, maybeFlagSetNameOrNames, settings.sync.__splitFiltersValidation.groupedFilters.bySet);
}
validateIfOperational(log, readinessManager, methodName);

validateIfOperational(log, readinessManager, methodName, splitOrSplits);

const valid = isNotDestroyed && key && (splitOrSplits || flagSetOrFlagSets.length > 0) && attributes !== false;

Expand Down
4 changes: 2 additions & 2 deletions src/sdkClient/sdkClientMethodCS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ function buildInstanceId(key: SplitIO.SplitKey) {
const method = 'Client instantiation';

/**
* Factory of client method for the client-side API variant where TT is ignored and thus
* clients don't have a binded TT for the track method.
* Factory of client method for the client-side API variant where TT is ignored.
* Therefore, clients don't have a bound TT for the track method.
*/
export function sdkClientMethodCSFactory(params: ISdkFactoryContext): (key?: SplitIO.SplitKey) => SplitIO.ICsClient {
const { storage, syncManager, sdkReadinessManager, settings: { core: { key }, startup: { readyTimeout }, log } } = params;
Expand Down
2 changes: 1 addition & 1 deletion src/sdkClient/sdkClientMethodCSWithTT.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const method = 'Client instantiation';

/**
* Factory of client method for the client-side (browser) variant of the Isomorphic JS SDK,
* where clients can have a binded TT for the track method, which is provided via the settings
* where clients can have a bound TT for the track method, which is provided via the settings
* (default client) or the client method (shared clients).
*/
export function sdkClientMethodCSFactory(params: ISdkFactoryContext): (key?: SplitIO.SplitKey, trafficType?: string) => SplitIO.ICsClient {
Expand Down
3 changes: 2 additions & 1 deletion src/sdkManager/__tests__/mocks/output.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@
"configs": {
"on": "\"color\": \"green\""
},
"sets": ["set_a"]
"sets": ["set_a"],
"defaultTreatment": "off"
}
3 changes: 2 additions & 1 deletion src/sdkManager/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ function objectToView(splitObject: ISplit | null): SplitIO.SplitView | null {
changeNumber: splitObject.changeNumber || 0,
treatments: collectTreatments(splitObject),
configs: splitObject.configurations || {},
sets: splitObject.sets || []
sets: splitObject.sets || [],
defaultTreatment: splitObject.defaultTreatment
};
}

Expand Down
1 change: 1 addition & 0 deletions src/storages/AbstractSegmentsCacheSync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export abstract class AbstractSegmentsCacheSync implements ISegmentsCacheSync {

/**
* Only used for the `skC`(segment keys count) telemetry stat: 1 for client-side, and total count of keys in server-side.
* @TODO for client-side it should be the number of clients, but it requires a refactor of MySegments caches to simplify the code.
*/
abstract getKeysCount(): number

Expand Down
7 changes: 6 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,12 @@ export namespace SplitIO {
* list of sets per feature flag
* @property {string[]} sets
*/
sets?: string[]
sets?: string[],
/**
* The default treatment of the feature flag.
* @property {string} defaultTreatment
*/
defaultTreatment: string,
};
/**
* A promise that resolves to a feature flag view.
Expand Down
2 changes: 1 addition & 1 deletion src/utils/inputValidation/__tests__/isOperational.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ describe('validateIfOperational', () => {
expect(validateIfOperational(loggerMock, readinessManagerMock, 'test_method')).toBe(false); // It should return true if SDK was ready.
expect(readinessManagerMock.isReady).toBeCalledTimes(1); // It checks for SDK_READY status.
expect(readinessManagerMock.isReadyFromCache).toBeCalledTimes(1); // It checks for SDK_READY_FROM_CACHE status.
expect(loggerMock.warn).toBeCalledWith(CLIENT_NOT_READY, ['test_method']); // It should log the expected warning.
expect(loggerMock.warn).toBeCalledWith(CLIENT_NOT_READY, ['test_method', '']); // It should log the expected warning.
expect(loggerMock.error).not.toBeCalled(); // But it should not log any errors.
});
});
4 changes: 2 additions & 2 deletions src/utils/inputValidation/isOperational.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ export function validateIfNotDestroyed(log: ILogger, readinessManager: IReadines
return false;
}

export function validateIfOperational(log: ILogger, readinessManager: IReadinessManager, method: string) {
export function validateIfOperational(log: ILogger, readinessManager: IReadinessManager, method: string, featureFlagNameOrNames?: string | string[] | false) {
if (readinessManager.isReady() || readinessManager.isReadyFromCache()) return true;

log.warn(CLIENT_NOT_READY, [method]);
log.warn(CLIENT_NOT_READY, [method, featureFlagNameOrNames ? ` for feature flag ${featureFlagNameOrNames.toString()}` : '']);
return false;
}
2 changes: 1 addition & 1 deletion src/utils/settingsValidation/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ export function settingsValidation(config: unknown, validationParams: ISettingsV
withDefaults.core.key = 'localhost_key';
} else {
// Keeping same behaviour than JS SDK: if settings key or TT are invalid,
// `false` value is used as binded key/TT of the default client, which leads to some issues.
// `false` value is used as bound key/TT of the default client, which leads to some issues.
// @ts-ignore, @TODO handle invalid keys as a non-recoverable error?
withDefaults.core.key = validateKey(log, maybeKey, 'Client instantiation');
}
Expand Down

0 comments on commit 40750b5

Please sign in to comment.