165 lines
4.6 KiB
TypeScript
165 lines
4.6 KiB
TypeScript
import { IsNotEmpty, IsOptional, validateOrReject } from "class-validator";
|
|
import dotenv from "dotenv";
|
|
import { Service } from "typedi";
|
|
|
|
@Service()
|
|
export class BackendVariables {
|
|
@IsNotEmpty()
|
|
public readonly DATABASE_PORT!: string;
|
|
|
|
@IsNotEmpty()
|
|
public readonly DATABASE_HOST!: string;
|
|
|
|
@IsNotEmpty()
|
|
public readonly DATABASE_USERNAME!: string;
|
|
|
|
@IsNotEmpty()
|
|
public readonly DATABASE_PASSWORD!: string;
|
|
|
|
@IsNotEmpty()
|
|
public readonly DATABASE_NAME!: string;
|
|
|
|
@IsNotEmpty()
|
|
public readonly DATABASE_URL!: string;
|
|
|
|
@IsNotEmpty()
|
|
public readonly API_ROOT_URL!: string;
|
|
|
|
@IsNotEmpty()
|
|
public readonly APP_HOST!: string;
|
|
|
|
@IsOptional()
|
|
public readonly APP_LABEL!: string;
|
|
|
|
@IsNotEmpty()
|
|
public readonly APP_PORT!: string;
|
|
|
|
@IsNotEmpty()
|
|
public readonly APP_ROOT_URL!: string;
|
|
|
|
@IsNotEmpty()
|
|
public readonly IDNOT_BASE_URL!: string;
|
|
|
|
@IsNotEmpty()
|
|
public readonly IDNOT_API_BASE_URL!: string;
|
|
|
|
@IsNotEmpty()
|
|
public readonly IDNOT_CONNEXION_URL!: string;
|
|
|
|
@IsNotEmpty()
|
|
public readonly IDNOT_CLIENT_ID!: string;
|
|
|
|
@IsNotEmpty()
|
|
public readonly IDNOT_CLIENT_SECRET!: string;
|
|
|
|
@IsNotEmpty()
|
|
public readonly IDNOT_REDIRECT_URL!: string;
|
|
|
|
@IsNotEmpty()
|
|
public readonly IDNOT_API_KEY!: string;
|
|
|
|
@IsNotEmpty()
|
|
public readonly PINATA_API_KEY!: string;
|
|
|
|
@IsNotEmpty()
|
|
public readonly PINATA_API_SECRET!: string;
|
|
|
|
@IsNotEmpty()
|
|
public readonly PINATA_GATEWAY!: string;
|
|
|
|
@IsNotEmpty()
|
|
public readonly ACCESS_TOKEN_SECRET!: string;
|
|
|
|
@IsNotEmpty()
|
|
public readonly REFRESH_TOKEN_SECRET!: string;
|
|
|
|
@IsNotEmpty()
|
|
public readonly MAILCHIMP_API_KEY!: string;
|
|
|
|
@IsNotEmpty()
|
|
public readonly SECURE_API_KEY!: string;
|
|
|
|
@IsNotEmpty()
|
|
public readonly SECURE_API_BASE_URL!: string;
|
|
|
|
@IsNotEmpty()
|
|
public readonly ENV!: string;
|
|
|
|
@IsNotEmpty()
|
|
public readonly DOCAPOST_BASE_URL!: string;
|
|
|
|
@IsNotEmpty()
|
|
public readonly DOCAPOST_ROOT!: string;
|
|
|
|
@IsNotEmpty()
|
|
public readonly DOCAPOST_VERSION!: string;
|
|
|
|
@IsNotEmpty()
|
|
public readonly DOCAPOST_DOCUMENT_PROCESS_ID!: string;
|
|
|
|
@IsNotEmpty()
|
|
public readonly DOCAPOST_CONNECT_PROCESS_ID!: string;
|
|
|
|
@IsNotEmpty()
|
|
public readonly BACK_API_HOST!: string;
|
|
|
|
@IsNotEmpty()
|
|
public readonly DOCAPOST_APP_ID!: string;
|
|
|
|
@IsNotEmpty()
|
|
public readonly DOCAPOST_APP_PASSWORD!: string;
|
|
|
|
public constructor() {
|
|
dotenv.config();
|
|
this.DATABASE_PORT = process.env["DATABASE_PORT"]!;
|
|
this.DATABASE_HOST = process.env["DATABASE_HOST"]!;
|
|
this.DATABASE_USERNAME = process.env["DATABASE_USERNAME"]!;
|
|
this.DATABASE_PASSWORD = process.env["DATABASE_PASSWORD"]!;
|
|
this.DATABASE_NAME = process.env["DATABASE_NAME"]!;
|
|
this.DATABASE_URL = process.env["DEV_PRISMA_STUDIO_DB_URL"]!;
|
|
this.API_ROOT_URL = process.env["API_ROOT_URL"]!;
|
|
this.APP_HOST = process.env["APP_HOST"]!;
|
|
this.APP_PORT = process.env["APP_PORT"]!;
|
|
this.APP_ROOT_URL = process.env["APP_ROOT_URL"]!;
|
|
this.APP_LABEL = process.env["APP_LABEL"]!;
|
|
this.IDNOT_BASE_URL = process.env["IDNOT_BASE_URL"]!;
|
|
this.IDNOT_API_BASE_URL = process.env["IDNOT_API_BASE_URL"]!;
|
|
this.IDNOT_CONNEXION_URL = process.env["IDNOT_CONNEXION_URL"]!;
|
|
this.IDNOT_CLIENT_ID = process.env["IDNOT_CLIENT_ID"]!;
|
|
this.IDNOT_CLIENT_SECRET = process.env["IDNOT_CLIENT_SECRET"]!;
|
|
this.IDNOT_REDIRECT_URL = process.env["IDNOT_REDIRECT_URL"]!;
|
|
this.IDNOT_API_KEY = process.env["IDNOT_API_KEY"]!;
|
|
this.PINATA_API_KEY = process.env["PINATA_API_KEY"]!;
|
|
this.PINATA_API_SECRET = process.env["PINATA_API_SECRET"]!;
|
|
this.PINATA_GATEWAY = process.env["PINATA_GATEWAY"]!;
|
|
this.ACCESS_TOKEN_SECRET = process.env["ACCESS_TOKEN_SECRET"]!;
|
|
this.REFRESH_TOKEN_SECRET = process.env["REFRESH_TOKEN_SECRET"]!;
|
|
this.MAILCHIMP_API_KEY = process.env["MAILCHIMP_API_KEY"]!;
|
|
this.SECURE_API_KEY = process.env["SECURE_API_KEY"]!;
|
|
this.SECURE_API_BASE_URL = process.env["SECURE_API_BASE_URL"]!;
|
|
this.ENV = process.env["ENV"]!;
|
|
this.DOCAPOST_BASE_URL = process.env["DOCAPOST_BASE_URL"]!;
|
|
this.DOCAPOST_ROOT = process.env["DOCAPOST_ROOT"]!;
|
|
this.DOCAPOST_VERSION = process.env["DOCAPOST_VERSION"]!;
|
|
this.DOCAPOST_DOCUMENT_PROCESS_ID = process.env["DOCAPOST_DOCUMENT_PROCESS_ID"]!;
|
|
this.DOCAPOST_CONNECT_PROCESS_ID = process.env["DOCAPOST_CONNECT_PROCESS_ID"]!;
|
|
this.BACK_API_HOST = process.env["BACK_API_HOST"]!;
|
|
this.DOCAPOST_APP_ID = process.env["DOCAPOST_APP_ID"]!;
|
|
this.DOCAPOST_APP_PASSWORD = process.env["DOCAPOST_APP_PASSWORD"]!;
|
|
|
|
}
|
|
public async validate(groups?: string[]) {
|
|
const validationOptions = groups ? { groups } : undefined;
|
|
|
|
try {
|
|
await validateOrReject(this, validationOptions);
|
|
} catch (error: any) {
|
|
if (process.env["ENV"] === "dev" || process.env["ENV"] === 'stg') {
|
|
throw error;
|
|
}
|
|
throw new Error("Some env variables are required!");
|
|
}
|
|
return this;
|
|
}
|
|
}
|