Duplicate Code Opportunity
Summary
- Pattern: The
getConfigEnvValue helper function (10 lines) is defined as a private function in two sibling service modules with byte-for-byte identical implementations. Both files also independently compute normalizedAuthType with the same expression.
- Locations:
src/services/api-proxy-credential-env.ts:17–26 and src/services/api-proxy-service-config.ts:75–84
- Impact: The credential-injection path reads env values through two independent copies of the same lookup logic (
additionalEnv → envFile → process.env); any change to env-precedence rules must be applied to both files
Evidence
src/services/api-proxy-credential-env.ts (lines 17–26):
function getConfigEnvValue(config: WrapperConfig, key: string): string | undefined {
const envFileValue = config.envFile
? readEnvFile(config.envFile)[key]
: undefined;
const value =
config.additionalEnv?.[key] ??
envFileValue ??
(config.envAll ? process.env[key] : undefined);
const normalizedValue = value?.trim();
return normalizedValue || undefined;
}
src/services/api-proxy-service-config.ts (lines 75–84) — identical:
function getConfigEnvValue(config: WrapperConfig, key: string): string | undefined {
const envFileValue = config.envFile
? readEnvFile(config.envFile)[key]
: undefined;
const value =
config.additionalEnv?.[key] ??
envFileValue ??
(config.envAll ? process.env[key] : undefined);
const normalizedValue = value?.trim();
return normalizedValue || undefined;
}
Additionally, both files compute normalizedAuthType with the same expression:
api-proxy-credential-env.ts:38: const normalizedAuthType = (process.env.AWF_AUTH_TYPE || '').trim().toLowerCase();
api-proxy-service-config.ts:93: const normalizedAuthType = (process.env.AWF_AUTH_TYPE || '').trim().toLowerCase();
Note: These two files were split from a single api-proxy-service.ts during a prior refactoring. The duplication was introduced by that split.
Suggested Refactoring
Export getConfigEnvValue from a shared module — either extend the existing src/env-utils.ts or create src/services/api-proxy-config-utils.ts:
// src/env-utils.ts (or a new shared module)
export function getConfigEnvValue(config: WrapperConfig, key: string): string | undefined {
const envFileValue = config.envFile ? readEnvFile(config.envFile)[key] : undefined;
const value =
config.additionalEnv?.[key] ??
envFileValue ??
(config.envAll ? process.env[key] : undefined);
return value?.trim() || undefined;
}
Both api-proxy-credential-env.ts and api-proxy-service-config.ts then import and use the shared function, removing the private copies.
Affected Files
src/services/api-proxy-credential-env.ts — lines 17–26 (remove private copy), line 38 (normalizedAuthType)
src/services/api-proxy-service-config.ts — lines 75–84 (remove private copy), line 93 (normalizedAuthType)
Effort Estimate
Low
Detected by Duplicate Code Detector workflow. Run date: 2026-06-04
Generated by Duplicate Code Detector · sonnet46 2.2M · ◷
Duplicate Code Opportunity
Summary
getConfigEnvValuehelper function (10 lines) is defined as a private function in two sibling service modules with byte-for-byte identical implementations. Both files also independently computenormalizedAuthTypewith the same expression.src/services/api-proxy-credential-env.ts:17–26andsrc/services/api-proxy-service-config.ts:75–84additionalEnv → envFile → process.env); any change to env-precedence rules must be applied to both filesEvidence
src/services/api-proxy-credential-env.ts(lines 17–26):src/services/api-proxy-service-config.ts(lines 75–84) — identical:Additionally, both files compute
normalizedAuthTypewith the same expression:api-proxy-credential-env.ts:38:const normalizedAuthType = (process.env.AWF_AUTH_TYPE || '').trim().toLowerCase();api-proxy-service-config.ts:93:const normalizedAuthType = (process.env.AWF_AUTH_TYPE || '').trim().toLowerCase();Note: These two files were split from a single
api-proxy-service.tsduring a prior refactoring. The duplication was introduced by that split.Suggested Refactoring
Export
getConfigEnvValuefrom a shared module — either extend the existingsrc/env-utils.tsor createsrc/services/api-proxy-config-utils.ts:Both
api-proxy-credential-env.tsandapi-proxy-service-config.tsthen import and use the shared function, removing the private copies.Affected Files
src/services/api-proxy-credential-env.ts— lines 17–26 (remove private copy), line 38 (normalizedAuthType)src/services/api-proxy-service-config.ts— lines 75–84 (remove private copy), line 93 (normalizedAuthType)Effort Estimate
Low
Detected by Duplicate Code Detector workflow. Run date: 2026-06-04