Skip to content

Commit c84e56e

Browse files
committed
fix(review): address PR #911 review feedback
Address review comments from copilot-pull-request-reviewer, coderabbitai[bot]: - linkedin-ads.service.ts: auto-resolve org ID from LINKEDIN_ACCOUNTS when ad account is overridden via env var, preventing account/org mismatch (per Copilot) - linkedin-ads.service.ts: add debug logging to getAccountId() and getOrgId() for deployment observability (per CodeRabbit) LFXV2-2180 Resolves 1 review thread. Signed-off-by: Misha Rautela <mrautela@linuxfoundation.org>
1 parent b6471fb commit c84e56e

1 file changed

Lines changed: 37 additions & 3 deletions

File tree

apps/lfx-one/src/server/services/linkedin-ads.service.ts

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,13 @@ import type { LinkedInCampaignCreateRequest, LinkedInCampaignCreateResult, Linke
55

66
import { LINKEDIN_API_VERSION, LINKEDIN_GEO_RESOLVE_MAP } from '@lfx-one/shared/constants';
77

8-
import { LINKEDIN_DEFAULT_ACCOUNT_ID, LINKEDIN_DEFAULT_ORG_ID, LINKEDIN_EMPLOYER_EXCLUSIONS, LINKEDIN_TARGETING_PROFILES } from '../constants';
8+
import {
9+
LINKEDIN_ACCOUNTS,
10+
LINKEDIN_DEFAULT_ACCOUNT_ID,
11+
LINKEDIN_DEFAULT_ORG_ID,
12+
LINKEDIN_EMPLOYER_EXCLUSIONS,
13+
LINKEDIN_TARGETING_PROFILES,
14+
} from '../constants';
915

1016
import type { Request } from 'express';
1117

@@ -38,11 +44,39 @@ function getLinkedInEnv(key: string): string {
3844
}
3945

4046
function getAccountId(): string {
41-
return process.env['LINKEDIN_AD_ACCOUNT_ID'] || LINKEDIN_DEFAULT_ACCOUNT_ID;
47+
const envValue = process.env['LINKEDIN_AD_ACCOUNT_ID'];
48+
if (envValue) {
49+
logger.debug(undefined, 'linkedin_config', `Using LinkedIn account from env: ${envValue}`);
50+
return envValue;
51+
}
52+
logger.debug(undefined, 'linkedin_config', `Using default LinkedIn account: ${LINKEDIN_DEFAULT_ACCOUNT_ID}`);
53+
return LINKEDIN_DEFAULT_ACCOUNT_ID;
4254
}
4355

4456
function getOrgId(): string {
45-
return process.env['LINKEDIN_ORG_ID'] || LINKEDIN_DEFAULT_ORG_ID;
57+
const envOrgId = process.env['LINKEDIN_ORG_ID'];
58+
if (envOrgId) {
59+
logger.debug(undefined, 'linkedin_config', `Using LinkedIn org from env: ${envOrgId}`);
60+
return envOrgId;
61+
}
62+
63+
// Auto-resolve org ID from the accounts list when a non-default account is set
64+
const accountId = getAccountId();
65+
if (accountId !== LINKEDIN_DEFAULT_ACCOUNT_ID) {
66+
const match = LINKEDIN_ACCOUNTS.find((a) => a.accountId === accountId);
67+
if (match) {
68+
logger.debug(undefined, 'linkedin_config', `Auto-resolved org ${match.orgId} for account ${accountId} (${match.label})`);
69+
return match.orgId;
70+
}
71+
logger.warning(
72+
undefined,
73+
'linkedin_config',
74+
`Account ${accountId} not found in LINKEDIN_ACCOUNTS — falling back to default org ${LINKEDIN_DEFAULT_ORG_ID}`
75+
);
76+
}
77+
78+
logger.debug(undefined, 'linkedin_config', `Using default LinkedIn org: ${LINKEDIN_DEFAULT_ORG_ID}`);
79+
return LINKEDIN_DEFAULT_ORG_ID;
4680
}
4781

4882
function getAccessToken(): string {

0 commit comments

Comments
 (0)