All files / services/internal configService.ts

96.61% Statements 57/59
100% Branches 12/12
31.03% Functions 9/29
96.61% Lines 57/59

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 601x 1x 1x 1x 1x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 27x 27x 13x 13x 13x 13x 68x 68x 1x 1x 68x 68x 13x   13x   13x 1x 1x 1x 1x 1x 1x 1x 1x  
import { Container, Service, Token } from 'typedi';
import { AppType } from '@constants/enum/appType';
 
@Service()
export class ConfigService {
  /* If the .env var name starts with VITE_ it is available on the UI & API */
 
  getNmsUdFormWebUrl = () => this.get('VITE_NMSUD_FORM_WEB_URL');
  getNmsUdApiUrl = () => this.get('VITE_NMSUD_API_URL');
  getNmsUdFormDataUrl = () => this.get('VITE_NMSUD_FORM_DATA_URL');
  getNmsUdFormDocsUrl = () => this.get('VITE_NMSUD_FORM_DOCS_URL');
 
  getApiPort = () => this.getNumber('API_PORT', 3001);
  getApiSecret = () => this.get('API_SECRET');
 
  getXataApiKey = () => this.get('XATA_API_KEY');
  getXataDbUrl = () => this.get('XATA_DB_URL');
  getXataFallbackBranch = () => this.get('XATA_FALLBACK_BRANCH');
 
  getDiscordWebhookUrl = () => this.get('DISCORD_WEBHOOK_URL');
 
  getGithubActionTriggerOnDecision = () => this.getBool('GITHUB_ACTION_TRIGGER_ON_DECISION');
  getGithubActionOwner = () => this.get('GITHUB_ACTION_OWNER');
  getGithubActionRepo = () => this.get('GITHUB_ACTION_REPO');
  getGithubActionWorkflowId = () => this.get('GITHUB_ACTION_WORKFLOW_ID');
  getGithubActionMinBetweenRuns = () => this.getNumber('GITHUB_ACTION_MINUTES_BETWEEN_RUN');
  getGithubActionAuthToken = () => this.get('GITHUB_AUTH_TOKEN');
 
  getCaptchaEnabled = () => this.getBool('VITE_ENABLE_CAPTCHA');
  getHCaptchaSecret = () => this.get('HCAPTCHA_SECRET');
  getHCaptchaSiteKey = () => this.get('VITE_HCAPTCHA_SITE_KEY');
 
  /* Special case, available on UI & API */
  isProd = () =>
    this.get('NODE_ENV').toLocaleLowerCase() === 'production' ||
    this.get('MODE').toLocaleLowerCase() === 'production';
  packageVersion = () => this.get('PACKAGE_VERSION');
  buildVersion = () => this.get('BUILD_VERSION');
 
  get(property: string, defaultValue?: string): string {
    const value = process?.env?.[property];
    if (defaultValue != null) {
      return value ?? defaultValue;
    }
    return value ?? '';
  }
  getBool = (property: string, defaultValue?: string) =>
    this.get(property, defaultValue).toLowerCase() == 'true';
  getNumber = (property: string, defaultValue?: number) =>
    Number(this.get(property, defaultValue?.toString?.()));
}
 
export const BOT_PATH = new Token<string>('BOT_PATH');
export const getBotPath = () => Container.get(BOT_PATH);
 
export const APP_TYPE = new Token<AppType>('APP_TYPE');
export const getAppType = () => Container.get(APP_TYPE);
 
export const getConfig = () => Container.get(ConfigService);