Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Upgrade LaunchDarkly SDK and use anonymous users #9285

Merged
merged 7 commits into from
Jul 7, 2023
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@linode/manager": Tech Stories
---

Upgrade LaunchDarkly client library ([#9285](https://github.com/linode/manager/pull/9285))
2 changes: 1 addition & 1 deletion packages/manager/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"ipaddr.js": "^1.9.1",
"jspdf": "^2.3.1",
"jspdf-autotable": "^3.5.14",
"launchdarkly-react-client-sdk": "^2.29.1",
"launchdarkly-react-client-sdk": "^3.0.6",
"libphonenumber-js": "^1.10.6",
"lodash": "^4.17.21",
"logic-query-parser": "^0.0.5",
Expand Down
20 changes: 8 additions & 12 deletions packages/manager/src/IdentifyUser.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import md5 from 'md5';
import * as React from 'react';
import { LAUNCH_DARKLY_API_KEY } from 'src/constants';
import { useLDClient } from 'src/containers/withFeatureFlagProvider.container';
import { useLDClient } from 'launchdarkly-react-client-sdk';
import { configureErrorReportingUser } from './exceptionReporting';
import useFeatureFlagsLoad from './hooks/useFeatureFlagLoad';
import { useAccount } from './queries/account';
Expand Down Expand Up @@ -53,22 +52,19 @@ export const IdentifyUser = () => {
? 'Unknown'
: account?.country;

const _taxID = accountError
const taxID = accountError
? 'Unknown'
: account?.tax_id === ''
? 'Unknown'
: account?.tax_id;

if (client && userID && country && username && _taxID) {
if (client && country && username && taxID) {
client
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated to the version update, but this feels like a good candidate for a try/catch block. not high on this change but since we never used that API version before may be worth considering

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@abailly-akamai Just to confirm, are you asking for something additional than the catch block we're already doing for the client.identity? https://github.com/linode/manager/pull/9285/files/9ae0dbfe5c8b7c5d019d80b0c77ec53ace0a5fce#diff-bce16ff1b4dbf5a6d7e4637a4277c38540996a930370da1c953d9f7793caf834R76

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah no, that's good to go!

.identify({
key: md5(String(userID)),
name: username,
kind: 'user',
anonymous: true,
country,
custom: {
taxID: _taxID,
},
privateAttributeNames: ['country', 'taxID'],
abailly-akamai marked this conversation as resolved.
Show resolved Hide resolved
taxID,
privateAttributes: ['country, taxID'],
})
.then(() => setFeatureFlagsLoaded())
/**
Expand All @@ -87,7 +83,7 @@ export const IdentifyUser = () => {
setFeatureFlagsLoaded();
}
}
}, [client, userID, username, account, accountError]);
}, [client, username, account, accountError]);

return null;
};
Expand Down
3 changes: 1 addition & 2 deletions packages/manager/src/__data__/ldClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const client: LDClient = {
waitUntilGoalsReady: jest.fn(),
waitUntilReady: jest.fn(),
track: jest.fn(),
getUser: jest.fn(),
getContext: jest.fn(),
identify: jest.fn(),
off: jest.fn(),
on: jest.fn(),
Expand All @@ -15,7 +15,6 @@ const client: LDClient = {
variation: jest.fn(),
variationDetail: jest.fn(),
close: jest.fn(),
alias: jest.fn(),
};

export default client;
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { useLDClient, withLDProvider } from 'launchdarkly-react-client-sdk';
import { withLDProvider } from 'launchdarkly-react-client-sdk';

import { LAUNCH_DARKLY_API_KEY } from 'src/constants';

export { useLDClient };

/**
* only wrap the component in the HOC if we've passed
* the Launch Darkly API key as an environment variable.
Expand All @@ -15,14 +13,7 @@ export { useLDClient };
const featureFlagProvider = LAUNCH_DARKLY_API_KEY
? withLDProvider({
clientSideID: LAUNCH_DARKLY_API_KEY,
/**
* Initialize the app with an anonymous user.
*/
user: {
key: 'anonymous',
anonymous: true,
privateAttributeNames: ['country', 'taxID'],
},
options: { allAttributesPrivate: true },
})
: (component: React.ComponentType) => component;

Expand Down
3 changes: 1 addition & 2 deletions packages/manager/src/dev-tools/FeatureFlagTool.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import * as React from 'react';
import { useDispatch } from 'react-redux';
import withFeatureFlagProvider from 'src/containers/withFeatureFlagProvider.container';
import { Flags, FlagSet } from 'src/featureFlags';
import { Dispatch } from 'src/hooks/types';
import useFlags from 'src/hooks/useFlags';
Expand Down Expand Up @@ -58,4 +57,4 @@ const FeatureFlagTool: React.FC<{}> = () => {
);
};

export default withFeatureFlagProvider(FeatureFlagTool);
export default FeatureFlagTool;
3 changes: 1 addition & 2 deletions packages/manager/src/dev-tools/MockDataTool.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as React from 'react';
import withFeatureFlagProvider from 'src/containers/withFeatureFlagProvider.container';
import Grid from '@mui/material/Unstable_Grid2';
import { MockData, mockDataController } from './mockDataController';
import ServiceWorkerTool from './ServiceWorkerTool';
Expand Down Expand Up @@ -62,4 +61,4 @@ const MockDataTool: React.FC<{}> = () => {
);
};

export default withFeatureFlagProvider(MockDataTool);
export default MockDataTool;
34 changes: 17 additions & 17 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -10286,30 +10286,30 @@ language-tags@=1.0.5:
dependencies:
language-subtag-registry "~0.3.2"

launchdarkly-js-client-sdk@2.24.2:
version "2.24.2"
resolved "https://registry.yarnpkg.com/launchdarkly-js-client-sdk/-/launchdarkly-js-client-sdk-2.24.2.tgz#8a8a206d8ea22f1bfbc2906e0615115c6e075798"
integrity sha512-8jrLOia0vfZ4stqQRv9TjAYfRGK2JyWpLIL6PbTl99LqTtJMuYtryFUQp0b8WH1153YN+gVdoqPVI7uwbbzLLQ==
launchdarkly-js-client-sdk@^3.1.3:
version "3.1.3"
resolved "https://registry.yarnpkg.com/launchdarkly-js-client-sdk/-/launchdarkly-js-client-sdk-3.1.3.tgz#e046439f0e4f0bfd6d38b9eaa4420a6e40ffc0c7"
integrity sha512-/JR/ri8z3bEj9RFTTKDjd+con4F1MsWUea1MmBDtFj4gDA0l9NDm1KzhMKiIeoBdmB2rSaeFYe4CaYOEp8IryA==
dependencies:
escape-string-regexp "^4.0.0"
launchdarkly-js-sdk-common "3.8.2"
launchdarkly-js-sdk-common "5.0.3"

launchdarkly-js-sdk-common@3.8.2:
version "3.8.2"
resolved "https://registry.yarnpkg.com/launchdarkly-js-sdk-common/-/launchdarkly-js-sdk-common-3.8.2.tgz#38838f1c4e30cb07b4827de6f2928ab3530ea7c6"
integrity sha512-pEqZ3FTKtYrTaPdbPntFJs87svzcezrkoRWY2GEFmyPC33txOqU788x0yby2+haC/saFPNfXpH6bbiJE/GjMSA==
launchdarkly-js-sdk-common@5.0.3:
version "5.0.3"
resolved "https://registry.yarnpkg.com/launchdarkly-js-sdk-common/-/launchdarkly-js-sdk-common-5.0.3.tgz#345f899f5779be8b03d6599978c855eb838d8b7f"
integrity sha512-wKG8UsVbPVq8+7eavgAm5CVmulQWN6Ddod2ZoA3euZ1zPvJPwIQ2GrOYaCJr3cFrrMIX+nQyBJHBHYxUAPcM+Q==
dependencies:
base64-js "^1.3.0"
fast-deep-equal "^2.0.1"
uuid "^3.3.2"
uuid "^8.0.0"

launchdarkly-react-client-sdk@^2.29.1:
version "2.29.4"
resolved "https://registry.yarnpkg.com/launchdarkly-react-client-sdk/-/launchdarkly-react-client-sdk-2.29.4.tgz#7c1bb9c3db5d1df55688d801eed2e7c56f173526"
integrity sha512-f0vcrn/PtZl6DC0r2qQwwXg0JY/bkrFahijOfeB9RJY/gEgSAmO/eNmTGEyjKEGdc9SwzVmRzwS6i8OXs8np/w==
launchdarkly-react-client-sdk@^3.0.6:
version "3.0.6"
resolved "https://registry.yarnpkg.com/launchdarkly-react-client-sdk/-/launchdarkly-react-client-sdk-3.0.6.tgz#5c694a4a013757d2afb5213efd28d9c16af1595e"
integrity sha512-r7gSshScugjnJB4lJ6mAOMKpV4Pj/wUks3tsRHdfeXgER9jPdxmZOAkm0besMjK0S7lfQdjxJ2KIXrh+Mn1sQA==
dependencies:
hoist-non-react-statics "^3.3.2"
launchdarkly-js-client-sdk "2.24.2"
launchdarkly-js-client-sdk "^3.1.3"
lodash.camelcase "^4.3.0"

lazy-ass@^1.6.0:
Expand Down Expand Up @@ -14325,12 +14325,12 @@ utrie@^1.0.2:
dependencies:
base64-arraybuffer "^1.0.2"

uuid@^3.3.2, uuid@^3.3.3:
uuid@^3.3.3:
version "3.4.0"
resolved "https://registry.yarnpkg.com/uuid/-/uuid-3.4.0.tgz#b23e4358afa8a202fe7a100af1f5f883f02007ee"
integrity sha512-HjSDRw6gZE5JMggctHBcjVak08+KEVhSIiDzFnT9S9aegmp85S/bReBVTb4QTFaRNptJ9kuYaNhnbNEOkbKb/A==

uuid@^8.3.0, uuid@^8.3.2:
uuid@^8.0.0, uuid@^8.3.0, uuid@^8.3.2:
version "8.3.2"
resolved "https://registry.yarnpkg.com/uuid/-/uuid-8.3.2.tgz#80d5b5ced271bb9af6c445f21a1a04c606cefbe2"
integrity sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==
Expand Down