/* eslint-disable @typescript-eslint/no-non-null-assertion */ import { Injectable, LogLevel } from '@nestjs/common'; import { ConfigService } from '@nestjs/config'; import { EmailDriver } from 'src/integrations/email/interfaces/email.interface'; import { LoggerDriverType } from 'src/integrations/logger/interfaces'; import { ExceptionHandlerDriver } from 'src/integrations/exception-handler/interfaces'; import { StorageDriverType } from 'src/integrations/file-storage/interfaces'; import { MessageQueueDriverType } from 'src/integrations/message-queue/interfaces'; import { AwsRegion } from './interfaces/aws-region.interface'; import { SupportDriver } from './interfaces/support.interface'; @Injectable() export class EnvironmentService { constructor(private configService: ConfigService) {} isDebugMode(): boolean { return this.configService.get('DEBUG_MODE') ?? false; } isSignInPrefilled(): boolean { return this.configService.get('SIGN_IN_PREFILLED') ?? false; } isBillingEnabled() { return this.configService.get('IS_BILLING_ENABLED') ?? false; } getBillingUrl() { return this.configService.get('BILLING_PLAN_REQUIRED_LINK') ?? ''; } isTelemetryEnabled(): boolean { return this.configService.get('TELEMETRY_ENABLED') ?? true; } isTelemetryAnonymizationEnabled(): boolean { return ( this.configService.get('TELEMETRY_ANONYMIZATION_ENABLED') ?? true ); } getPort(): number { return this.configService.get('PORT') ?? 3000; } getPGDatabaseUrl(): string { return this.configService.get('PG_DATABASE_URL')!; } getRedisHost(): string { return this.configService.get('REDIS_HOST') ?? '127.0.0.1'; } getRedisPort(): number { return +(this.configService.get('REDIS_PORT') ?? 6379); } getFrontBaseUrl(): string { return this.configService.get('FRONT_BASE_URL')!; } getServerUrl(): string { return this.configService.get('SERVER_URL')!; } getAccessTokenSecret(): string { return this.configService.get('ACCESS_TOKEN_SECRET')!; } getAccessTokenExpiresIn(): string { return this.configService.get('ACCESS_TOKEN_EXPIRES_IN') ?? '30m'; } getRefreshTokenSecret(): string { return this.configService.get('REFRESH_TOKEN_SECRET')!; } getRefreshTokenExpiresIn(): string { return this.configService.get('REFRESH_TOKEN_EXPIRES_IN') ?? '90d'; } getRefreshTokenCoolDown(): string { return this.configService.get('REFRESH_TOKEN_COOL_DOWN') ?? '1m'; } getLoginTokenSecret(): string { return this.configService.get('LOGIN_TOKEN_SECRET')!; } getLoginTokenExpiresIn(): string { return this.configService.get('LOGIN_TOKEN_EXPIRES_IN') ?? '15m'; } getTransientTokenExpiresIn(): string { return ( this.configService.get('SHORT_TERM_TOKEN_EXPIRES_IN') ?? '5m' ); } getApiTokenExpiresIn(): string { return this.configService.get('API_TOKEN_EXPIRES_IN') ?? '1000y'; } getFrontAuthCallbackUrl(): string { return ( this.configService.get('FRONT_AUTH_CALLBACK_URL') ?? this.getFrontBaseUrl() + '/verify' ); } isMessagingProviderGmailEnabled(): boolean { return ( this.configService.get('MESSAGING_PROVIDER_GMAIL_ENABLED') ?? false ); } getMessagingProviderGmailCallbackUrl(): string | undefined { return this.configService.get( 'MESSAGING_PROVIDER_GMAIL_CALLBACK_URL', ); } isAuthGoogleEnabled(): boolean { return this.configService.get('AUTH_GOOGLE_ENABLED') ?? false; } getAuthGoogleClientId(): string | undefined { return this.configService.get('AUTH_GOOGLE_CLIENT_ID'); } getAuthGoogleClientSecret(): string | undefined { return this.configService.get('AUTH_GOOGLE_CLIENT_SECRET'); } getAuthGoogleCallbackUrl(): string | undefined { return this.configService.get('AUTH_GOOGLE_CALLBACK_URL'); } getStorageDriverType(): StorageDriverType { return ( this.configService.get('STORAGE_TYPE') ?? StorageDriverType.Local ); } getMessageQueueDriverType(): MessageQueueDriverType { return ( this.configService.get('MESSAGE_QUEUE_TYPE') ?? MessageQueueDriverType.Sync ); } getStorageS3Region(): AwsRegion | undefined { return this.configService.get('STORAGE_S3_REGION'); } getStorageS3Name(): string | undefined { return this.configService.get('STORAGE_S3_NAME'); } getStorageS3Endpoint(): string | undefined { return this.configService.get('STORAGE_S3_ENDPOINT'); } getStorageLocalPath(): string { return ( this.configService.get('STORAGE_LOCAL_PATH') ?? '.local-storage' ); } getEmailFromAddress(): string { return ( this.configService.get('EMAIL_FROM_ADDRESS') ?? 'noreply@yourdomain.com' ); } getEmailSystemAddress(): string { return ( this.configService.get('EMAIL_SYSTEM_ADDRESS') ?? 'system@yourdomain.com' ); } getEmailFromName(): string { return ( this.configService.get('EMAIL_FROM_NAME') ?? 'John from YourDomain' ); } getEmailDriver(): EmailDriver { return ( this.configService.get('EMAIL_DRIVER') ?? EmailDriver.Logger ); } getEmailHost(): string | undefined { return this.configService.get('EMAIL_SMTP_HOST'); } getEmailPort(): number | undefined { return this.configService.get('EMAIL_SMTP_PORT'); } getEmailUser(): string | undefined { return this.configService.get('EMAIL_SMTP_USER'); } getEmailPassword(): string | undefined { return this.configService.get('EMAIL_SMTP_PASSWORD'); } getSupportDriver(): string { return ( this.configService.get('SUPPORT_DRIVER') ?? SupportDriver.None ); } getSupportFrontChatId(): string | undefined { return this.configService.get('SUPPORT_FRONT_CHAT_ID'); } getSupportFrontHMACKey(): string | undefined { return this.configService.get('SUPPORT_FRONT_HMAC_KEY'); } getLoggerDriverType(): LoggerDriverType { return ( this.configService.get('LOGGER_DRIVER') ?? LoggerDriverType.Console ); } getLoggerIsBufferEnabled(): boolean | undefined { return this.configService.get('LOGGER_IS_BUFFER_ENABLED') ?? true; } getExceptionHandlerDriverType(): ExceptionHandlerDriver { return ( this.configService.get( 'EXCEPTION_HANDLER_DRIVER', ) ?? ExceptionHandlerDriver.Console ); } getLogLevels(): LogLevel[] { return ( this.configService.get('LOG_LEVELS') ?? [ 'log', 'error', 'warn', ] ); } getSentryDSN(): string | undefined { return this.configService.get('SENTRY_DSN'); } getDemoWorkspaceIds(): string[] { return this.configService.get('DEMO_WORKSPACE_IDS') ?? []; } getOpenRouterApiKey(): string | undefined { return this.configService.get('OPENROUTER_API_KEY'); } getPasswordResetTokenExpiresIn(): string { return ( this.configService.get('PASSWORD_RESET_TOKEN_EXPIRES_IN') ?? '5m' ); } getInactiveDaysBeforeEmail(): number | undefined { return this.configService.get( 'WORKSPACE_INACTIVE_DAYS_BEFORE_NOTIFICATION', ); } getInactiveDaysBeforeDelete(): number | undefined { return this.configService.get( 'WORKSPACE_INACTIVE_DAYS_BEFORE_DELETION', ); } isSignUpDisabled(): boolean { return this.configService.get('IS_SIGN_UP_DISABLED') ?? false; } getApiRateLimitingTtl(): number { return this.configService.get('API_RATE_LIMITING_TTL') ?? 100; } getApiRateLimitingLimit(): number { return this.configService.get('API_RATE_LIMITING_LIMIT') ?? 500; } getMutationMaximumRecordAffected(): number { return ( this.configService.get('MUTATION_MAXIMUM_RECORD_AFFECTED') ?? 100 ); } getBillingStripeBasePlanProductId(): string { return ( this.configService.get('BILLING_STRIPE_BASE_PLAN_PRODUCT_ID') ?? '' ); } getStripeApiKey(): string { return this.configService.get('STRIPE_API_KEY') ?? ''; } }