From 0d57f904ece99e7a8b74b3f25a39a328e99d15c5 Mon Sep 17 00:00:00 2001 From: LaunchDarklyReleaseBot <86431345+LaunchDarklyReleaseBot@users.noreply.github.com> Date: Wed, 7 Dec 2022 12:55:34 -0800 Subject: [PATCH] prepare 2.29.3 release (#173) * Initial commit * Delete extraneous files from lib. * Update initLDClient.test.ts * Update withLDProvider.tsx (#18) * update JS SDK dependency to 2.16.3 * use JS SDK 2.17.0 * improve tests to clarify which options we're passing in and which ones are added by the wrapper * set wrapperName to react-client-sdk * lint * Update withLDProvider.test.tsx * update JS SDK to 2.17.5 + a few dev dependency bumps (#21) * downgrade typescript to 3.8.3 (#22) * [Fixes for] Expose LDProvider as a standalone component (#31) * remove startsWith usage (#23) * Fix the broken build (#24) * Expose ld provider (#40) * Add tests for the LDProvider * Add LDProvider component * Add LDProvider to main export * Update provider tests * Remove unused EnhancedComponent * Abstract function to generate react options * add waitForUserToInitializeClient flag to Provider * rename to LDProvider.tsx * fix tests * remove async from componentDidMount * fixes from CR * add test * cleanup * update types for componentDidUpdate * await initLDClient Co-authored-by: Nicholas Mitchell Co-authored-by: Martin Heller * update to JS SDK 2.18.0 (adds disableSyncEventPost) (#25) * 45 fix providers to respect subscribed flags (#46) * Fixed asyncWithLDProvider.tsx and provider.tsx so that they only provide flag changes for subscribed flags. * Removed unused imports. * Addressed PR feedback. Fixed linting errors. Co-authored-by: Clay Embry * targetflags simplified logic (#26) * remove client-side ids from examples (#27) * update JS SDK to 2.18.1 * Fixing camelCaseKeys export (#44) * new js-common-sdk version (#30) * adding alias functionality (#31) * pin typedoc to unblock our releases (#32) * Removed the guides link * add inlineUsersToEvents to TypeScript defs by updating js-client-sdk (#33) * debugging * Fix linting errors * [ch103643] Fix examples to use local sdk * Remove unwanted changes. * Update package.json * Update yarn.lock * Update lock files. * Update package-lock.json * Update package-lock.json * Update package.json * Update link-dev.sh Co-authored-by: Ben Woskow <48036130+bwoskow-ld@users.noreply.github.com> * Update link-dev.sh * Update yarn.lock * Add react 17 peer dep (#61) * Update common JS SDK library to use fixes for debug event generation issues. (#36) * HOC static hoisting (#71) * Added a test for hoisting react statics in withLDProvider HOC * Fixed linting errors * Fixed more linting errors * update example app deps (#38) * Updated asyncWithLDProvider to fetch latest flag values when the Provider renders (#39) * Updated asyncWithLDProvider to fetch latest flag values when the Provider renders * Fixed linting * Updates docs URLs * fix: improve types of withLDProvider (#97) * [sc-107070] Include src for sourcemaps to work * [sc-127032] Omit deferInitialization from asyncWithLDProvider config * Removed and ignored lock files. * Update types.ts * Update typescript version (#44) * Update Makefile * Update Makefile * Deleting test-types.ts (#45) * [sc-132394] Add typedoc for AsyncProviderConfig (#47) Co-authored-by: Molly * Pass in client (#105) * [sc134057] Fix react sdk lint errors (#48) * remove custom TypeDoc build, use Releaser's standard logic (#49) * update js-client-sdk to 2.20.1 for localstorage error-handling fix and others * export more public symbols from entry point * [sc134364] Upgrade typescript, tslint and jest. (#50) Co-authored-by: Eli Bishop * update js-client-sdk to 2.20.2 for sc-142333 fix (#53) * First commit. TODO: migrate enzyme to rtl. * Removed enzyme. Fixed prettier parentheses rule. * Fixed broken snapshot tests. Removed unused imports. * Update package.json * Update the version of the js-client-sdk * Update patch version. * Rename master to main (#56) * Set sendEventsOnlyForVariation by default * Add jest-environment-jsdom as explicit dependency * Fix TS error * Add jest-environment-jsdom as explicit dependency * Fix TS error * Update tests * Move wrapper options into base options obj * Target ES6 * Add tests for camel case cases * Remove vestigial package * Make targetFlags doc more clear * Add error hook and handler * Revert changes to original docs * Add context and flags proxy util * Use flags proxy and update tests * Fixup * Fixup * Don't call variation when initializing * Add option and failing test * Passing test * Remove incorrect comment and fix typo * Update proxy's get trap * except after c * Remove unproxied flags from context * Restore ldClient dec and clean up camelization * Update src/types.ts Co-authored-by: Molly * Fixup * Handle symbols * Add type constraint to withLDProvider * Remove getter setter * Remove error handler and fix bad merge * Update snapshots * Update releaser config * Fixup * Update version of js-client-sdk used. (#82) * Upgrade js-client-sdk version to 2.24.0 (#83) * Upgrade common to 2.24.2 (#84) * Populate the context with the initial flag state and proxy. (#85) * [sc-178466] Bugfix flags proxy errors when using native functions (#91) * [sc-178466] Fix native function proxy errors * Added unit tests. * Fix ts any error * Update getFlagsProxy.test.ts Co-authored-by: Yusinto Ngadiman * Update config.yml Co-authored-by: Yusinto Ngadiman Co-authored-by: Ben Woskow <48036130+bwoskow-ld@users.noreply.github.com> Co-authored-by: Eli Bishop Co-authored-by: LaunchDarklyCI Co-authored-by: Martin Heller Co-authored-by: Ben Woskow Co-authored-by: bezreyhan Co-authored-by: Nicholas Mitchell Co-authored-by: Martin Heller Co-authored-by: clayembry Co-authored-by: Clay Embry Co-authored-by: Jonathan Felchlin Co-authored-by: Mac Lockard Co-authored-by: Gavin Whelan Co-authored-by: Nathan Waddell <45477581+NathanWaddell121107@users.noreply.github.com> Co-authored-by: Clifford Tawiah Co-authored-by: Cliff Tawiah <82856282+ctawiah@users.noreply.github.com> Co-authored-by: LaunchDarklyReleaseBot Co-authored-by: Ember Stevens Co-authored-by: ember-stevens <79482775+ember-stevens@users.noreply.github.com> Co-authored-by: Derek Sifford Co-authored-by: Jaz White Co-authored-by: Molly Co-authored-by: Tim Lee Co-authored-by: Louis Chan <91093020+louis-launchdarkly@users.noreply.github.com> Co-authored-by: Louis Chan Co-authored-by: Ryan Lamb <4955475+kinyoklion@users.noreply.github.com> Co-authored-by: Christie Williams Co-authored-by: Yusinto Ngadiman --- package.json | 3 ++- src/getFlagsProxy.test.ts | 21 +++++++++++++-------- src/getFlagsProxy.ts | 10 ++++++---- 3 files changed, 21 insertions(+), 13 deletions(-) diff --git a/package.json b/package.json index a54e7d3..24832bd 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,8 @@ "check-typescript": "tsc", "prepublishOnly": "npm run build", "prettier": "prettier --write 'src/*.@(js|ts|tsx|json|css)'", - "link-dev": "./link-dev.sh" + "link-dev": "./link-dev.sh", + "check": "npm i && npm run prettier && npm run lint && tsc && npm run test" }, "repository": { "type": "git", diff --git a/src/getFlagsProxy.test.ts b/src/getFlagsProxy.test.ts index a12bfab..04aa638 100644 --- a/src/getFlagsProxy.test.ts +++ b/src/getFlagsProxy.test.ts @@ -2,11 +2,6 @@ import { LDClient, LDFlagSet } from 'launchdarkly-js-client-sdk'; import getFlagsProxy from './getFlagsProxy'; import { defaultReactOptions } from './types'; -// tslint:disable-next-line: no-unsafe-any -const variation = jest.fn((k: string): string | undefined => rawFlags[k]); - -const ldClient = ({ variation } as unknown) as LDClient; - const rawFlags: LDFlagSet = { 'foo-bar': 'foobar', 'baz-qux': 'bazqux', @@ -17,8 +12,18 @@ const camelizedFlags: LDFlagSet = { bazQux: 'bazqux', }; +// cast as unknown first to be able to partially mock ldClient +const ldClient = ({ variation: jest.fn((flagKey) => rawFlags[flagKey] as string) } as unknown) as LDClient; + beforeEach(jest.clearAllMocks); +test('native Object functions should be ignored', () => { + const { flags } = getFlagsProxy(ldClient, rawFlags); + flags.hasOwnProperty('fooBar'); + flags.propertyIsEnumerable('bazQux'); + expect(ldClient.variation).not.toHaveBeenCalled(); +}); + test('camel cases keys', () => { const { flags } = getFlagsProxy(ldClient, rawFlags); @@ -31,12 +36,12 @@ test('does not camel cases keys', () => { expect(flags).toEqual(rawFlags); }); -test('proxy calls variation on flag read', () => { +test('proxy calls ldClient.variation on flag read', () => { const { flags } = getFlagsProxy(ldClient, rawFlags); expect(flags.fooBar).toBe('foobar'); - expect(variation).toHaveBeenCalledWith('foo-bar', 'foobar'); + expect(ldClient.variation).toHaveBeenCalledWith('foo-bar', 'foobar'); }); test('returns flag key map', () => { @@ -56,5 +61,5 @@ test('does not use proxy if option is false', () => { expect(flags['foo-bar']).toBe('foobar'); - expect(variation).not.toHaveBeenCalled(); + expect(ldClient.variation).not.toHaveBeenCalled(); }); diff --git a/src/getFlagsProxy.ts b/src/getFlagsProxy.ts index 22c6ac4..409676a 100644 --- a/src/getFlagsProxy.ts +++ b/src/getFlagsProxy.ts @@ -58,17 +58,19 @@ function toFlagsProxy(ldClient: LDClient, flags: LDFlagSet, flagKeyMap: LDFlagKe // trap for reading a flag value using `LDClient#variation` to trigger an evaluation event get(target, prop, receiver) { const currentValue = Reflect.get(target, prop, receiver); - if (typeof prop === 'symbol') { + + // only process flag keys and ignore symbols and native Object functions + if (typeof prop === 'symbol' || !hasFlag(flagKeyMap, prop)) { return currentValue; } + if (currentValue === undefined) { return; } - const originalFlagKey = hasFlag(flagKeyMap, prop) ? flagKeyMap[prop] : prop; - const nextValue = ldClient.variation(originalFlagKey, currentValue); - return nextValue; + return ldClient.variation(flagKeyMap[prop], currentValue); }, + // disable all mutation functions to make proxy readonly setPrototypeOf: () => false, set: () => false,