jsm-core
Version: 
Core library for JSM project
363 lines (362 loc) • 10.7 kB
TypeScript
import cacheDuration from "./cache.config";
type MaxDepth = 5;
type LeafKeys<T, Depth extends number[] = []> = Depth["length"] extends MaxDepth ? never : T extends object ? {
    [K in Extract<keyof T, string | number>]: T[K] extends object ? `${K}.${LeafKeys<T[K], [...Depth, 1]>}` : `${K}`;
}[Extract<keyof T, string | number>] : never;
export type TCacheDurationKey = LeafKeys<typeof cacheDuration>;
declare const config: {
    /**
     * Environement
     */
    environement: "development" | "production";
    readonly isDev: boolean;
    readonly isProd: boolean;
    /**
     * Development mode
     */
    dev: {
        master: {
            email: string;
            password: string;
        };
        faker: {
            userPassword: string;
        };
        debugProduction: boolean;
    };
    /**
     * Configuration for logging.
     */
    logging: {
        /**
         * Whether to log duplicate errors or not.
         */
        log_duplicate_errors: boolean;
        /**
         * The log level.
         */
        level: string;
    };
    /**
     * Configuration for Agenda.js.
     */
    agenda: {
        /**
         * The name of the database collection used by Agenda.js.
         */
        dbCollection: string;
        /**
         * The pool time for Agenda.js.
         */
        pooltime: string;
        /**
         * The concurrency for Agenda.js.
         */
        concurrency: number;
        /**
         * Configuration for Agendash.
         */
        agendash: {
            /**
             * Whether Agendash is enabled or not.
             */
            enabled: boolean;
            /**
             * The username for Agendash.
             */
            user: string;
            /**
             * The password for Agendash.
             */
            password: string;
        };
    };
    /**
     * Configuration for amqplib.
     */
    amqplib: {
        /**
         * The host for amqplib.
         */
        host: string;
        /**
         * The port for amqplib.
         */
        port: number;
        /**
         * The retry delay for amqplib.
         */
        retryDelay: number;
        /**
         * The maximum retries for amqplib.
         */
        maxRetries: number;
        user: string;
        password: string;
    };
    /**
     * Configuration for email services.
     */
    emails: {
        /**
         * Configuration for Mailgun.
         */
        mailgun: {
            /**
             * The API key for Mailgun.
             */
            apiKey: string;
            /**
             * The API username for Mailgun.
             */
            apiUsername: string;
            /**
             * The domain for Mailgun.
             */
            domain: string;
        };
        /**
         * Configuration for Nodemailer.
         */
        nodemailer: {
            /**
             * The service for Nodemailer.
             */
            service: string;
            /**
             * The user for Nodemailer.
             */
            user: string;
            /**
             * The password for Nodemailer.
             */
            pass: string;
        };
    };
    /**
     * Configuration for security-related settings.
     */
    security: {
        /**
         * The secret used for internal service communication.
         */
        internalServiceSecret: string;
        /**
         * The secret used for external service communication.
         */
        externalServiceSecret: string;
        /**
         * The secret used for frontend service communication.
         */
        frontendServiceSecret: string;
        /**
         * JWT Configuration
         */
        jwt: {
            /**
             * The secret used for JSON Web Token (JWT) generation and verification.
             */
            secret: string;
            /**
             * The algorithm used for JSON Web Token (JWT) generation and verification.
             */
            algorithm: string;
            /**
             * @description The expiration for JSON Web Token (JWT).
             * - The time range must be specified with a number followed by a unit of time (e.g. "5 minutes", "3 hours", "1 day")
             * - Valid units of time are "second", "minute", "hour", "day", "week", "month", and "year"
             * - Valid units of time can be abbreviated to "s", "m", "h", "d", "w", "M", and "y"
             * - If no unit of time is specified, the default unit is "day"
             * - If the unit of time is plural (e.g. "days"), it must be pluralized using an "s"
             * - If the unit of time is abbreviated, it must be followed by an "s"
             * - The time range string must be in the format "[number] [unit of time]s?"
             * - For example, "5 minutes" is valid, but "5 minute" is not valid, and "5 m" is not valid either
             * - If the unit of time is plural (e.g. "days"), it must be pluralized using an "s"
             * - This function return {false} if the time range string is not in the correct format
             */
            tokenExpiration: string;
            /**
             * @description The expiration for JSON Web Refresh Token (JWT).
             * - The time range must be specified with a number followed by a unit of time (e.g. "5 minutes", "3 hours", "1 day")
             * - Valid units of time are "second", "minute", "hour", "day", "week", "month", and "year"
             * - Valid units of time can be abbreviated to "s", "m", "h", "d", "w", "M", and "y"
             * - If no unit of time is specified, the default unit is "day"
             * - If the unit of time is plural (e.g. "days"), it must be pluralized using an "s"
             * - If the unit of time is abbreviated, it must be followed by an "s"
             * - The time range string must be in the format "[number] [unit of time]s?"
             * - For example, "5 minutes" is valid, but "5 minute" is not valid, and "5 m" is not valid either
             * - If the unit of time is plural (e.g. "days"), it must be pluralized using an "s"
             * - This function return {false} if the time range string is not in the correct format
             */
            refreshTokenExpiration: string;
        };
    };
    /**
     * Configuration for logging.
     */
    activityLog: {
        /**
         * The secret key for logging.
         */
        secretKey: string;
        /**
         * The URL for logging.
         */
        url: string;
    };
    /**
     * Configuration for HTTP.
     */
    http: {
        /**
         * The body size limit for HTTP.
         */
        bodySizeLimit: string;
        services: {
            /**
             * @description Configuration for services with '/api/v2' path.
             */
            api: {
                [service: string]: string;
            };
            hosts: {
                [service: string]: string;
            };
        };
        /**
         * Configuration for the API.
         */
        api: {
            /**
             * The prefix for the API.
             */
            prefix: `/${string}`;
        };
        /**
         * SDK Configuration
         */
        sdk: {
            baseURL: string;
            appId: string;
            appSecret: string;
            debug: boolean;
        };
        upload: {
            /**
             * The maximum file size for uploads.
             * Default is 16MB.
             */
            maxFileSize: number;
        };
    };
    /**
     * Configuration for settings.
     */
    settings: {
        preferences: {
            /**
             * The default language for the application.
             */
            defaultLanguage: string;
        };
        /**
         * Configuration for tracking.
         */
        tracking: {
            /**
             * The suffix length for tracking.
             */
            suffixLength: number;
        };
        /**
         * Configuration for items listing.
         */
        listing: {
            /**
             * The default count for items listing.
             */
            defaultCount: number;
        };
    };
    /**
     * Configuration for the current service.
     */
    currentService: {
        /**
         * The name of the current service.
         */
        name: string;
        /**
         * The port of the current service.
         */
        port: number;
        /**
         * The database for the current service.
         */
        db: import("./db.config").TDatabaseConfig;
    };
    cacheManager: {
        redis: {
            /**
             * The URL for the Redis cache manager.
             */
            url: string;
            /**
             * The port for the Redis cache manager.
             */
            port: number;
            /**
             *
             */
            user: string | null;
            /**
             * The password for the Redis cache manager.
             */
            password: string | null;
        };
        keyPrefix: string;
        /**
         * @description All values in seconds
         */
        cacheDuration: {
            dev: number;
            insights: {
                customers: {
                    aggregateCustomersByParcelStatus: number;
                    aggregateCustomersByOrderStatus: number;
                };
                products: {
                    aggregateProductsByParcelStatus: number;
                    aggregateProductsByOrderStatus: number;
                };
                orders: {
                    storesPerformanceInsights: number;
                    aggregateOrderGlobalInsights: number;
                    aggregateOrderGlobalInsightsForStore: number;
                };
                shipping: {
                    zoningPerformanceData: number;
                    storesPerformanceInsights: number;
                    aggregateParcelGlobalInsights: number;
                    aggregateParcelGlobalInsightsForStore: number;
                };
            };
            reports: {
                payment: {
                    allOfficesPaymentSummaries: number;
                };
            };
        };
        getDuration(key: TCacheDurationKey): number;
    };
};
export default config;
/**
 * A generic type that makes each object value of the object extensible.
 *
 * @template T - The original object type.
 */
export type DeepExtensible<T> = {
    [K in keyof T]: T[K] extends object ? DeepExtensible<T[K]> & Record<string, any> : T[K];
};
export type TConfig = DeepExtensible<typeof config> & Record<string, any>;