Skip to content

Commit

Permalink
Beta .2
Browse files Browse the repository at this point in the history
  • Loading branch information
kinyoklion committed Oct 17, 2024
2 parents 2fed2aa + 4f145f5 commit 42a928c
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 17 deletions.
4 changes: 2 additions & 2 deletions packages/sdk/react-native/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@launchdarkly/react-native-client-sdk",
"version": "10.8.0",
"version": "10.8.1-beta.2",
"description": "React Native LaunchDarkly SDK",
"homepage": "https://github.com/launchdarkly/js-core/tree/main/packages/sdk/react-native",
"repository": {
Expand Down Expand Up @@ -41,7 +41,7 @@
"react-native": "*"
},
"dependencies": {
"@launchdarkly/js-client-sdk-common": "1.9.0",
"@launchdarkly/js-client-sdk-common": "1.9.1-beta.2",
"@react-native-async-storage/async-storage": "^1.21.0",
"base64-js": "^1.5.1"
},
Expand Down
12 changes: 9 additions & 3 deletions packages/shared/common/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@launchdarkly/js-sdk-common",
"version": "2.10.0",
"version": "2.10.1-beta.1",
"type": "module",
"main": "./dist/esm/index.mjs",
"types": "./dist/esm/index.d.ts",
Expand All @@ -19,8 +19,14 @@
"client"
],
"exports": {
"require": { "types": "./dist/cjs/index.d.ts", "default": "./dist/cjs/index.cjs"},
"import": { "types": "./dist/esm/index.d.ts", "default": "./dist/esm/index.mjs"}
"require": {
"types": "./dist/cjs/index.d.ts",
"default": "./dist/cjs/index.cjs"
},
"import": {
"types": "./dist/esm/index.d.ts",
"default": "./dist/esm/index.mjs"
}
},
"scripts": {
"test": "npx jest --ci",
Expand Down
69 changes: 69 additions & 0 deletions packages/shared/sdk-client/__tests__/LDClientImpl.hooks.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { AutoEnvAttributes } from '@launchdarkly/js-sdk-common';
import { Hook, HookMetadata } from '../src/api';
import LDClientImpl from '../src/LDClientImpl';
import { createBasicPlatform } from './createBasicPlatform';
import * as mockResponseJson from './evaluation/mockResponse.json';
import { MockEventSource } from './streaming/LDClientImpl.mocks';
import { makeTestDataManagerFactory } from './TestDataManager';

it('should use hooks registered during configuration', async () => {
Expand Down Expand Up @@ -239,3 +241,70 @@ it('should execute both initial hooks and hooks added using addHook', async () =
},
);
});

it('should not execute hooks for prerequisite evaluations', async () => {
const testHook: Hook = {
beforeEvaluation: jest.fn(),
afterEvaluation: jest.fn(),
beforeIdentify: jest.fn(),
afterIdentify: jest.fn(),
getMetadata(): HookMetadata {
return {
name: 'test hook',
};
},
};

const platform = createBasicPlatform();
let mockEventSource: MockEventSource;
const simulatedEvents = [{ data: JSON.stringify(mockResponseJson) }];
platform.requests.createEventSource.mockImplementation(
(streamUri: string = '', options: any = {}) => {
mockEventSource = new MockEventSource(streamUri, options);
mockEventSource.simulateEvents('put', simulatedEvents);
return mockEventSource;
},
);

const factory = makeTestDataManagerFactory('sdk-key', platform);
const client = new LDClientImpl(
'sdk-key',
AutoEnvAttributes.Disabled,
platform,
{
sendEvents: false,
hooks: [testHook],
logger: {
debug: jest.fn(),
info: jest.fn(),
warn: jest.fn(),
error: jest.fn(),
},
},
factory,
);

await client.identify({ key: 'user-key' });
await client.variation('has-prereq-depth-1', false);

expect(testHook.beforeEvaluation).toHaveBeenCalledTimes(1);

expect(testHook.beforeEvaluation).toHaveBeenCalledWith(
{ context: { key: 'user-key' }, defaultValue: false, flagKey: 'has-prereq-depth-1' },
{},
);

expect(testHook.afterEvaluation).toHaveBeenCalledTimes(1);

expect(testHook.afterEvaluation).toHaveBeenCalledWith(
{ context: { key: 'user-key' }, defaultValue: false, flagKey: 'has-prereq-depth-1' },
{},
{
reason: {
kind: 'FALLTHROUGH',
},
value: true,
variationIndex: 0,
},
);
});
24 changes: 16 additions & 8 deletions packages/shared/sdk-client/package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"name": "@launchdarkly/js-client-sdk-common",
"version": "1.9.0",
"version": "1.9.1-beta.2",
"type": "module",
"main": "./dist/index.mjs",
"types": "./dist/index.d.ts",
"main": "./dist/esm/index.mjs",
"types": "./dist/esm/index.d.ts",
"homepage": "https://github.com/launchdarkly/js-core/tree/main/packages/shared/sdk-client",
"repository": {
"type": "git",
Expand All @@ -19,14 +19,22 @@
"client"
],
"exports": {
"types": "./dist/index.d.ts",
"require": "./dist/index.cjs",
"import": "./dist/index.mjs"
"require": {
"types": "./dist/cjs/index.d.ts",
"default": "./dist/cjs/index.cjs"
},
"import": {
"types": "./dist/esm/index.d.ts",
"default": "./dist/esm/index.mjs"
}
},
"scripts": {
"doc": "../../../scripts/build-doc.sh .",
"test": "npx jest --ci",
"build": "tsc --noEmit && rollup -c rollup.config.js",
"make-cjs-package-json": "echo '{\"type\":\"commonjs\"}' > dist/cjs/package.json",
"make-esm-package-json": "echo '{\"type\":\"module\"}' > dist/esm/package.json",
"make-package-jsons": "npm run make-cjs-package-json && npm run make-esm-package-json",
"build": "npx tsc --noEmit && rollup -c rollup.config.js && npm run make-package-jsons",
"clean": "rimraf dist",
"lint": "npx eslint . --ext .ts",
"lint:fix": "yarn run lint -- --fix",
Expand All @@ -35,7 +43,7 @@
},
"license": "Apache-2.0",
"dependencies": {
"@launchdarkly/js-sdk-common": "2.10.0"
"@launchdarkly/js-sdk-common": "2.10.1-beta.1"
},
"devDependencies": {
"@rollup/plugin-commonjs": "^25.0.0",
Expand Down
6 changes: 3 additions & 3 deletions packages/shared/sdk-client/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const getSharedConfig = (format, file) => ({

export default [
{
...getSharedConfig('es', 'dist/index.mjs'),
...getSharedConfig('es', 'dist/esm/index.mjs'),
plugins: [
typescript({
module: 'esnext',
Expand All @@ -37,7 +37,7 @@ export default [
],
},
{
...getSharedConfig('cjs', 'dist/index.cjs'),
plugins: [typescript({ tsconfig: './tsconfig.json' }), common(), resolve(), json()],
...getSharedConfig('cjs', 'dist/cjs/index.cjs'),
plugins: [typescript({ tsconfig: './tsconfig.json', outputToFilesystem: true, }), common(), resolve(), json()],
},
];
2 changes: 1 addition & 1 deletion packages/shared/sdk-client/src/LDClientImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ export default class LDClientImpl implements LDClient {
}

prerequisites?.forEach((prereqKey) => {
this.variation(prereqKey, undefined);
this._variationInternal(prereqKey, undefined, this._eventFactoryDefault);
});
this._eventProcessor?.sendEvent(
eventFactory.evalEventClient(
Expand Down

0 comments on commit 42a928c

Please sign in to comment.