Skip to content

Commit

Permalink
remove ld deps and feature flags
Browse files Browse the repository at this point in the history
  • Loading branch information
tmyracle committed Jan 10, 2024
1 parent b500040 commit 435c6c6
Show file tree
Hide file tree
Showing 20 changed files with 5 additions and 165 deletions.
15 changes: 0 additions & 15 deletions apps/client/components/APM.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import { useAuth0 } from '@auth0/auth0-react'
import { useIntercom } from '@maybe-finance/client/shared'
import { useLDClient } from 'launchdarkly-react-client-sdk'
import { useRouter } from 'next/router'
import { useEffect } from 'react'
import * as Sentry from '@sentry/react'

export default function APM() {
const { user } = useAuth0()
const router = useRouter()
const ld = useLDClient()
const intercom = useIntercom()

// Boot intercom
Expand Down Expand Up @@ -36,18 +34,5 @@ export default function APM() {
}
}, [user])

// Identify LaunchDarkly user
useEffect(() => {
if (ld && user) {
ld.waitUntilReady().then(() => {
ld.identify({
key: user.sub,
email: user.email,
name: user.name,
})
})
}
}, [ld, user])

return null
}
18 changes: 1 addition & 17 deletions apps/client/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,14 @@ import {
UserAccountContextProvider,
AuthProvider,
} from '@maybe-finance/client/shared'
import type { ClientType } from '@maybe-finance/client/shared'
import { AccountsManager } from '@maybe-finance/client/features'
import { AccountContextProvider } from '@maybe-finance/client/shared'
import * as Sentry from '@sentry/react'
import { BrowserTracing } from '@sentry/tracing'
import { useFlags, withLDProvider } from 'launchdarkly-react-client-sdk'
import env from '../env'
import '../styles.css'
import { withAuthenticationRequired } from '@auth0/auth0-react'
import ModalManager from '../components/ModalManager'
import Maintenance from '../components/Maintenance'
import Meta from '../components/Meta'
import APM from '../components/APM'

Expand Down Expand Up @@ -51,7 +48,7 @@ const WithAuth = withAuthenticationRequired(function ({ children }: PropsWithChi
)
})

function App({
export default function App({
Component: Page,
pageProps,
}: AppProps & {
Expand All @@ -60,15 +57,8 @@ function App({
isPublic?: boolean
}
}) {
const flags = useFlags() as ClientType.ClientSideFeatureFlag

const getLayout = Page.getLayout ?? ((page) => page)

// Maintenance Guard
if (flags.maintenance) {
return <Maintenance />
}

return (
<LogProvider logger={console}>
<ErrorBoundary
Expand Down Expand Up @@ -98,9 +88,3 @@ function App({
</LogProvider>
)
}

export default withLDProvider<{ Component; pageProps }>({
clientSideID: env.NEXT_PUBLIC_LD_CLIENT_SIDE_ID,
// Prevent a new LD user being registered on each page load by always initializing with the same key
user: { key: 'anonymous-client', anonymous: true },
})(App)
1 change: 0 additions & 1 deletion apps/server/src/app/__tests__/account.integration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import { resetUser } from './utils/user'
import { createTestInvestmentAccount } from './utils/account'
import { default as _plaid } from '../lib/plaid'

jest.mock('launchdarkly-node-server-sdk')
jest.mock('../middleware/validate-plaid-jwt.ts')
jest.mock('bull')
jest.mock('plaid')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import { default as _plaid } from '../lib/plaid'
import nock from 'nock'
import { resetUser } from './utils/user'

jest.mock('launchdarkly-node-server-sdk')
jest.mock('../middleware/validate-plaid-jwt.ts')
jest.mock('plaid')

Expand Down
2 changes: 0 additions & 2 deletions apps/server/src/app/__tests__/stripe.integration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import stripe from '../lib/stripe'
import { PgService } from '@maybe-finance/server/shared'
import { DateTime } from 'luxon'

jest.mock('launchdarkly-node-server-sdk')

const prisma = new PrismaClient()
const logger = createLogger({ transports: new transports.Console() })

Expand Down
7 changes: 1 addition & 6 deletions apps/server/src/app/lib/endpoint.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { IFeatureFlagService, IMarketDataService } from '@maybe-finance/server/shared'
import type { IMarketDataService } from '@maybe-finance/server/shared'
import type {
IAccountQueryService,
IInstitutionService,
Expand All @@ -13,7 +13,6 @@ import {
EndpointFactory,
QueueService,
PgService,
LaunchDarklyFeatureFlagService,
PolygonMarketDataService,
CacheService,
ServerUtil,
Expand Down Expand Up @@ -55,7 +54,6 @@ import {
} from '@maybe-finance/server/features'
import { SharedType } from '@maybe-finance/shared'
import prisma from './prisma'
import ldClient from './ldClient'
import plaid, { getPlaidWebhookUrl } from './plaid'
import finicity, { getFinicityTxPushUrl, getFinicityWebhookUrl } from './finicity'
import stripe from './stripe'
Expand All @@ -74,8 +72,6 @@ const redis = new Redis(env.NX_REDIS_URL, {
retryStrategy: ServerUtil.redisRetryStrategy({ maxAttempts: 5 }),
})

const featureFlagService: IFeatureFlagService = new LaunchDarklyFeatureFlagService(ldClient)

export const queueService = new QueueService(
logger.child({ service: 'QueueService' }),
process.env.NODE_ENV === 'test'
Expand Down Expand Up @@ -352,7 +348,6 @@ export async function createContext(req: Request) {
valuationService,
institutionService,
cryptoService,
featureFlagService,
queueService,
plaidService,
plaidWebhooks,
Expand Down
6 changes: 0 additions & 6 deletions apps/server/src/app/lib/ldClient.ts

This file was deleted.

16 changes: 0 additions & 16 deletions apps/server/src/app/lib/logger.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,7 @@
import { createLogger } from '@maybe-finance/server/shared'
import ldClient from './ldClient'

const logger = createLogger({
level: 'info',
})

function setLevel() {
ldClient
.variation('server-log-level', { key: 'anonymous-server', anonymous: true }, 'info')
.then((level) => {
logger.level = level
logger[level](`Server logger using level: ${level}`)
})
}

// Don't configure for Jest
if (process.env.NODE_ENV !== 'test') {
ldClient.waitForInitialization().then(setLevel)
ldClient.on('update:server-log-level', setLevel)
}

export default logger
24 changes: 2 additions & 22 deletions apps/server/src/app/middleware/maintenance.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type { Express } from 'express'
import ldClient from '../lib/ldClient'

type MaintenanceOptions = {
statusCode?: number
Expand All @@ -9,28 +8,9 @@ type MaintenanceOptions = {

export default function maintenance(
app: Express,
{ statusCode = 503, path = '/maintenance', featureKey = 'maintenance' }: MaintenanceOptions = {}
{ statusCode = 503, path = '/maintenance' }: MaintenanceOptions = {}
) {
let enabled = false

function loadFeatureFlag() {
ldClient
.waitForInitialization()
.then((ld) => {
ld.variation(featureKey, { key: 'anonymous-server', anonymous: true }, false).then(
(flag) => (enabled = flag)
)
})
.catch((err) => {
console.error(`error loading feature flag`, err)
})
}

loadFeatureFlag()

ldClient.on(`update:${featureKey}`, () => {
loadFeatureFlag()
})
const enabled = false

app.get(path, async (req, res) => {
res.status(200).json({ enabled })
Expand Down
2 changes: 0 additions & 2 deletions apps/server/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import type { AddressInfo } from 'net'
import env from './env'
import app from './app/app'
import logger from './app/lib/logger'
import ldClient from './app/lib/ldClient'
import * as Sentry from '@sentry/node'

process.on('uncaughtException', function (error) {
Expand All @@ -22,5 +21,4 @@ const server = app.listen(env.NX_PORT, () => {
// Handle SIGTERM coming from ECS Fargate
process.on('SIGTERM', () => server.close())

server.on('close', () => ldClient.close())
server.on('error', (err) => logger.error('Server failed to start from main.ts', err))
1 change: 0 additions & 1 deletion apps/workers/src/app/__tests__/queue.integration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import '../../main'
import { queueService, securityPricingService } from '../lib/di'

jest.mock('plaid')
jest.mock('launchdarkly-node-server-sdk')

// For TypeScript support
const plaid = jest.mocked(_plaid)
Expand Down
5 changes: 1 addition & 4 deletions apps/workers/src/app/lib/di.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,12 @@ import {
EmailProcessor,
TransactionService,
} from '@maybe-finance/server/features'
import type { IFeatureFlagService, IMarketDataService } from '@maybe-finance/server/shared'
import type { IMarketDataService } from '@maybe-finance/server/shared'
import {
BullQueueFactory,
CacheService,
CryptoService,
InMemoryQueueFactory,
LaunchDarklyFeatureFlagService,
PgService,
PolygonMarketDataService,
QueueService,
Expand All @@ -58,7 +57,6 @@ import logger from './logger'
import prisma from './prisma'
import plaid from './plaid'
import finicity from './finicity'
import ldClient from './ldClient'
import postmark from './postmark'
import { managementClient } from './auth0'
import stripe from './stripe'
Expand All @@ -71,7 +69,6 @@ const redis = new Redis(env.NX_REDIS_URL, {
retryStrategy: ServerUtil.redisRetryStrategy({ maxAttempts: 5 }),
})

export const featureFlagService: IFeatureFlagService = new LaunchDarklyFeatureFlagService(ldClient)
export const cryptoService = new CryptoService(env.NX_DATABASE_SECRET)
export const pgService = new PgService(logger.child({ service: 'PgService' }), env.NX_DATABASE_URL)

Expand Down
6 changes: 0 additions & 6 deletions apps/workers/src/app/lib/ldClient.ts

This file was deleted.

16 changes: 0 additions & 16 deletions apps/workers/src/app/lib/logger.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,7 @@
import { createLogger } from '@maybe-finance/server/shared'
import ldClient from './ldClient'

const logger = createLogger({
level: 'info',
})

function setLevel() {
ldClient
.variation('workers-log-level', { key: 'anonymous-server', anonymous: true }, 'info')
.then((level) => {
logger.level = level
logger[level](`Workers logger using level: ${level}`)
})
}

// Don't configure for Jest
if (process.env.NODE_ENV !== 'test') {
ldClient.waitForInitialization().then(setLevel)
ldClient.on('update:workers-log-level', setLevel)
}

export default logger
9 changes: 0 additions & 9 deletions aws/maybe-app/lib/stacks/server-stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,15 +170,6 @@ export class ServerStack extends Stack {
}
)
),
NX_LD_SDK_KEY: ECSSecret.fromSsmParameter(
StringParameter.fromSecureStringParameterAttributes(
this,
'LaunchDarklySDKKeyParam',
{
parameterName: '/providers/NX_LD_SDK_KEY',
}
)
),
NX_POLYGON_API_KEY: ECSSecret.fromSsmParameter(
StringParameter.fromSecureStringParameterAttributes(
this,
Expand Down
9 changes: 0 additions & 9 deletions aws/maybe-app/lib/stacks/workers-stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,15 +124,6 @@ export class WorkersStack extends Stack {
}
)
),
NX_LD_SDK_KEY: ECSSecret.fromSsmParameter(
StringParameter.fromSecureStringParameterAttributes(
this,
'LaunchDarklySDKKeyParam',
{
parameterName: '/providers/NX_LD_SDK_KEY',
}
)
),
NX_POLYGON_API_KEY: ECSSecret.fromSsmParameter(
StringParameter.fromSecureStringParameterAttributes(
this,
Expand Down
4 changes: 0 additions & 4 deletions libs/client/shared/src/types/client-side-feature-flags.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
export type MetricStatus = 'coming-soon' | 'under-construction' | 'active'

export type ClientSideFeatureFlag = Partial<{
maintenance: boolean
}>
25 changes: 0 additions & 25 deletions libs/server/shared/src/services/feature-flag.service.ts

This file was deleted.

1 change: 0 additions & 1 deletion libs/server/shared/src/services/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
export * from './crypto.service'
export * from './feature-flag.service'
export * from './queue.service'
export * from './queue'
export * from './cache.service'
Expand Down
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,6 @@
"jwk-to-pem": "^2.0.5",
"jwks-rsa": "^3.0.0",
"jwt-decode": "^3.1.2",
"launchdarkly-node-server-sdk": "^6.4.3",
"launchdarkly-react-client-sdk": "^2.25.1",
"lodash": "^4.17.21",
"luxon": "^3.1.0",
"mime-types": "^2.1.35",
Expand Down

0 comments on commit 435c6c6

Please sign in to comment.