Skip to content
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
24 changes: 20 additions & 4 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,14 @@ on:
default: staging
options:
- staging
- staging-apse1
- staging-sg
- production-us
- production-eu
- production-apse1
- production-sg
- production-au
- production-uk
- production-jp
- production-kr
- production-us-and-eu

deploy_api:
Expand Down Expand Up @@ -89,7 +93,7 @@ jobs:
if [ "${{ github.event.inputs.environment }}" == "staging" ]; then
envs+=("\"staging-eu\"")
fi
if [ "${{ github.event.inputs.environment }}" == "staging-apse1" ]; then
if [ "${{ github.event.inputs.environment }}" == "staging-uk" ]; then
envs+=("\"staging-apse1\"")
fi
if [ "${{ github.event.inputs.environment }}" == "production-us" ]; then
Expand All @@ -98,9 +102,21 @@ jobs:
if [ "${{ github.event.inputs.environment }}" == "production-eu" ]; then
envs+=("\"prod-eu\"")
fi
if [ "${{ github.event.inputs.environment }}" == "production-apse1" ]; then
if [ "${{ github.event.inputs.environment }}" == "production-sg" ]; then
envs+=("\"prod-apse1\"")
fi
if [ "${{ github.event.inputs.environment }}" == "production-au" ]; then
envs+=("\"prod-apse2\"")
fi
if [ "${{ github.event.inputs.environment }}" == "production-uk" ]; then
envs+=("\"prod-ew2\"")
fi
if [ "${{ github.event.inputs.environment }}" == "production-jp" ]; then
envs+=("\"prod-apne1\"")
fi
if [ "${{ github.event.inputs.environment }}" == "production-kr" ]; then
envs+=("\"prod-apne2\"")
fi
if [ "${{ github.event.inputs.environment }}" == "production-us-and-eu" ]; then
envs+=("\"prod-us\"")
envs+=("\"prod-eu\"")
Expand Down
22 changes: 19 additions & 3 deletions apps/dashboard/src/context/feature-flags-provider.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,31 @@
import { IS_ENTERPRISE, IS_SELF_HOSTED, LAUNCH_DARKLY_CLIENT_SIDE_ID } from '@/config';
import { AsyncProviderConfig, asyncWithLDProvider } from 'launchdarkly-react-client-sdk';
import { lazy, Suspense } from 'react';
import { IS_ENTERPRISE, IS_SELF_HOSTED, LAUNCH_DARKLY_CLIENT_SIDE_ID } from '@/config';
import { getRegionConfig } from './region/region-config';
import { detectRegionFromURL } from './region/region-utils';

function getAwsRegion(): string {
const currentRegion = detectRegionFromURL();
const regionConfig = getRegionConfig(currentRegion);
return regionConfig?.awsRegion || '';
}

const awsRegion = getAwsRegion();

const LD_CONFIG: AsyncProviderConfig = {
clientSideID: LAUNCH_DARKLY_CLIENT_SIDE_ID,
reactOptions: {
useCamelCaseFlagKeys: false,
},
context: {
kind: 'user',
anonymous: true,
kind: 'multi',
user: {
anonymous: true,
},
region: {
key: awsRegion || 'unknown',
awsRegion: awsRegion,
},
},
options: {
bootstrap: 'localStorage',
Expand Down
46 changes: 29 additions & 17 deletions apps/dashboard/src/context/identity-provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@ import { setUser as sentrySetUser, setTags as setSentryTags } from '@sentry/reac
import { useLDClient } from 'launchdarkly-react-client-sdk';
import { useEffect, useRef } from 'react';
import { useAuth } from './auth/hooks';
import { getRegionConfig } from './region/region-config';
import { useRegion } from './region/region-context';
import { useSegment } from './segment/hooks';

export function IdentityProvider({ children }: { children: React.ReactNode }) {
const ldClient = useLDClient();
const segment = useSegment();
const { currentUser, currentOrganization } = useAuth();
const { selectedRegion } = useRegion();
const hasIdentifiedUser = useRef(false);
const hasIdentifiedOrg = useRef(false);

Expand All @@ -26,30 +29,37 @@ export function IdentityProvider({ children }: { children: React.ReactNode }) {
}, [ldClient, currentUser]);

useEffect(() => {
if (!currentOrganization || !currentUser || hasIdentifiedOrg.current) return;
if (!currentOrganization || !currentUser) return;

const hasExternalId = currentUser._id;
const hasOrganization = currentOrganization._id;
const shouldMonitor = hasExternalId && hasOrganization;

if (shouldMonitor) {
segment.identify(currentUser);
if (!hasIdentifiedOrg.current) {
segment.identify(currentUser);

sentrySetUser({
email: currentUser.email ?? '',
username: `${currentUser.firstName} ${currentUser.lastName}`,
id: currentUser._id,
});
sentrySetUser({
email: currentUser.email ?? '',
username: `${currentUser.firstName} ${currentUser.lastName}`,
id: currentUser._id,
});

setSentryTags({
'user.createdAt': currentUser.createdAt,
'organization.id': currentOrganization._id,
'organization.name': currentOrganization.name,
'organization.tier': currentOrganization.apiServiceLevel,
'organization.createdAt': currentOrganization.createdAt,
});

setSentryTags({
'user.createdAt': currentUser.createdAt,
'organization.id': currentOrganization._id,
'organization.name': currentOrganization.name,
'organization.tier': currentOrganization.apiServiceLevel,
'organization.createdAt': currentOrganization.createdAt,
});
hasIdentifiedOrg.current = true;
}

if (ldClient) {
const regionConfig = getRegionConfig(selectedRegion);
const awsRegion = regionConfig?.awsRegion || '';

ldClient.identify({
kind: 'multi',
organization: {
Expand All @@ -64,14 +74,16 @@ export function IdentityProvider({ children }: { children: React.ReactNode }) {
lastName: currentUser.lastName,
email: currentUser.email,
},
region: {
key: awsRegion || 'unknown',
awsRegion: awsRegion,
},
});
}
} else {
sentrySetUser(null);
}

hasIdentifiedOrg.current = true;
}, [ldClient, currentOrganization, currentUser, segment]);
}, [ldClient, currentOrganization, currentUser, segment, selectedRegion]);

return <>{children}</>;
}
8 changes: 4 additions & 4 deletions apps/dashboard/src/routes/root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,17 +67,17 @@ const RootRouteInternal = () => {
<ClerkProvider>
<SegmentProvider>
<AuthProvider>
<IdentityProvider>
<RegionProvider>
<RegionProvider>
<IdentityProvider>
<HelmetProvider>
<TooltipProvider delayDuration={100}>
<EscapeKeyManagerProvider>
<Outlet />
</EscapeKeyManagerProvider>
</TooltipProvider>
</HelmetProvider>
</RegionProvider>
</IdentityProvider>
</IdentityProvider>
</RegionProvider>
</AuthProvider>
</SegmentProvider>
</ClerkProvider>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,14 @@ export class LaunchDarklyFeatureFlagsService implements IFeatureFlagsService {
};
}

const region = process.env.NOVU_REGION;
if (region) {
mappedContext.region = {
key: region,
awsRegion: region,
};
}

/*
* LaunchDarkly requires at least one context kind in multi-kind contexts
* Add a fallback global context to prevent "A multi-kind context must contain at least one kind" error
Expand Down
Loading