/**
 * Holding the service config
 * @module config
 */
/// <reference types="node" />
import { EventEmitter } from 'events';
import { Algorithm } from 'jsonwebtoken';
import SocketIO from 'socket.io';
/**
 * Internal, used in {@link Config#serviceReady}
 */
interface ReadyStatus {
    isAgendaReady?: boolean;
    isMongooseReady?: boolean;
    isTestEmailReady?: boolean;
}
/**
 * Email adress composed of its name and its email adress: '"Fred Foo" <foo@example.com>'.
 */
export interface Address {
    name: string;
    address: string;
}
/**
 * Properties for configuring Krypton Authentication.
 */
export interface Properties {
    /** JSON Web Token signing algorithm. The default value is ``RS256``. */
    algorithm?: Algorithm;
    /**
     * Time until the authentication token expires in milliseconds.
     * The default value is ``15 * 60 * 1000`` (15 minutes).
     * Call the ``refreshToken`` mutation to renew it.
     */
    authTokenExpiryTime?: number;
    /**
     * MongoDB server address.
     * Example: ``mongodb://user:password@host.com:27017/DBname``.
     * The default value is ``mongodb://localhost:27017/users``.
     */
    dbAddress?: string;
    /**
     * MongoDB config, only if you need to set a special configuration for MongoDB.
     * The default configuration used by Krypton aims to make the system resilient to database connection problems. Krypton will try to reconnect automatically to MongoDB. You can adapt this behavior by tweaking this property.
     * Example: ``{reconnectInterval: 500}``.
     */
    dbConfig?: {
        [key: string]: any;
    };
    /**
     * Event emitter transmitting krypton errors on "error" event and email errors on "email-error" event.
     */
    eventEmitter?: EventEmitter;
    /** Custom user model, see :ref:`extended-schema`. */
    extendedSchema?: object;
    /**
     * Enable or disable GraphiQL IDE. The default value is `true`.
     * In the page header, you will find an input field to include your auth token and be able to make authenticated requests.
     *
     * **Note:** Include your auth token directly, no need to precede it with ``Bearer``.
     */
    graphiql?: boolean;
    /**
     * Public URL of the service.
     *
     * **Very important for use in production:** when users receive emails to reset their password or to confirm their account, the links will be pointing to the ``host`` of the service. The default value is ``null``. When ``null``, Krypton Authentication uses the address located in ``req.headers.host`` that can correspond to the machine ``localhost``.
     */
    host?: string;
    /**
     * Sender address displayed in emails sent to users. The default value is ``undefined``.
     * ::
     *     app.use(kryptonAuth({ mailFrom: '"Fred Foo 👻" <foo@example.com>' }));
     *     // or
     *     app.use(kryptonAuth({
     *         mailFrom: {
     *              name: "Fred Foo 👻";
     *              address: "foo@example.com";
     *          }
     *     }));
     */
    mailFrom?: string | Address;
    /**
     * A `Nodemailer configuration <https://nodemailer.com/smtp/#examples>`_ used to send administration emails to users. The default value is ``undefined``.
     * ::
     *    const nodemailerConfig = {
     *         host: "smtp.example.email",
     *         port: 587,
     *         secure: false, // true for 465, false for other ports
     *         auth: {
     *             user: credentials.user,
     *             pass: credentials.pass
     *        }
     *    };
     *
     *    app.use('/auth', kryptonAuth({ nodemailerConfig }));
     *
     * If left ``undefined`` a Nodemailer test account is set automatically. It will print URL links on the command line to let you preview the emails that would have normally been sent.
     * ::
     *     Message sent: <365ea109-f645-e3a1-5e08-48e4c8a37bcb@JohannC>
     *     Preview URL: https://ethereal.email/message/Xklk07cTigz7mlaKXkllHsRk0gyz7kuxAAAAAWLgnFDcJwUFl8MZ-h1shKs
     */
    nodemailerConfig?: any;
    /**
     * The filepath to the `EJS <https://ejs.co/>`_ template file of notification page.
     * This library include a simple one located in `./nodes_module/krypton-auth/lib/templates/pages/Notification.ejs <https://github.com/JohannC/krypton-auth/blob/master/lib/templates/pages/Notification.ejs>`_.
     * You can create another, just gives the file path to the `EJS <https://ejs.co/>`_ file you wish to send. Here are the locals you can use inside the template:
     *
     * * ``notifications``: ``Array`` of ``Object`` notification. Each notification object contains two properties:
     *     * ``type``: ``String Enum`` either equal to ``success`` - ``warning`` - ``error`` - ``info``
     *     * ``message``: ``String`` property containing the notificaiton message
     */
    notificationPageTemplate?: string;
    /**
     * The callback that will be executed when service is launched and ready. The default value is: ``() => console.log("Krypton Authentication is ready.");``.
     */
    onReady?: () => void;
    /**
     * The private key of the service. If both privateKey and privateKeyFilePath are undefined, it will create one under ``your-app/private-key.txt`` all along with the public key. You can retrieve the pair of keys created for re-use afterward.
     */
    privateKey?: string;
    /**
     * The file path to the private key of the service. If both privateKey and privateKeyFilePath are undefined, it will create one under ``your-app/private-key.txt`` all along with the public key. You can retrieve the pair of keys created for re-use afterward.
     */
    privateKeyFilePath?: string;
    /**
     * The public key of the service. If both publicKey and publicKeyFilePath are undefined, it will create one under ``your-app/public-key.txt`` all along with the private key. You can retrieve the pair of keys created for re-use afterward.
     */
    publicKey?: string;
    /**
     * The file path to the public key of the service. If both publicKey and publicKeyFilePath are undefined, it will create one under ``your-app/public-key.txt`` all along with the private key. You can retrieve the pair of keys created for re-use afterward.
     */
    publicKeyFilePath?: string;
    /**
     * The time until the refresh token expires in milliseconds. If a user is inactive during this period he will have to login in order to get a new refresh token. The default value is ``7 * 24 * 60 * 60 * 1000`` (7 days).
     *
     * **Note:** before the refresh token has expired, you can call the :ref:`refreshToken <refresh-authentication-tokens>` mutation. Both the auth token and the refresh token will be renewed and your user won't face any service interruption.
     */
    refreshTokenExpiryTime?: number;
    /**
     * The file path to the `EJS <https://ejs.co/>`_ template file of the email to reset forgotten password.
     * This library include a simple one located in `./nodes_module/krypton-auth/lib/templates/emails/ResetPassword.ejs <https://github.com/JohannC/krypton-auth/blob/master/lib/templates/emails/ResetPassword.ejs>`_.
     * You can create another, just gives the file path to the `EJS <https://ejs.co/>`_ file you wish to send. Here are the locals you can use inside the template:
     *
     * * ``user`` - The current user: ``<p>Hi <%= user.fistName %></p>``
     * * ``link`` - The link to the reset form: ``Click here: <a href="<%= link %>"><%= link %>``
     */
    resetPasswordEmailTemplate?: string;
    /**
     * The file path to the `EJS <https://ejs.co/>`_ template file of the reset password form.
     * This library include a simple one located in `./nodes_module/krypton-auth/lib/templates/forms/ResetPassword.ejs <https://github.com/JohannC/krypton-auth/blob/master/lib/templates/forms/ResetPassword.ejs>`_.
     * You can create another, just gives the file path to the `EJS <https://ejs.co/>`_ file you wish to send.
     * Here are the locals you can use inside the template:
     *
     * * ``link``: The link of the API: ``xhr.open("POST", '<%= link %>')``
     * * ``token``: The reset password token to include in the GraphQL :ref:`resetMyPassword <reset-password>` mutation (example below)
     *
     * ::
     *
     *     const xhr = new XMLHttpRequest();
     *     xhr.responseType = 'json';
     *     xhr.open("POST", '<%= link %>');
     *     xhr.setRequestHeader("Content-Type", "application/json");
     *     const mutation = {
     *         query: `mutation{resetMyPassword(password:"${formData.get("password")}" passwordRecoveryToken:<%= token %>){
     *             notifications{
     *                 type
     *                 message
     *             }
     *          }}`
     *       }
     *     xhr.send(JSON.stringify(mutation));
     */
    resetPasswordFormTemplate?: string;
    /**
     * The filepath to the `EJS <https://ejs.co/>`_ template file of the email to verify user account.
     * This library include a simple one located in `./nodes_module/krypton-auth/lib/templates/emails/VerifyEmail.ejs <https://github.com/JohannC/krypton-auth/blob/master/lib/templates/emails/VerifyEmail.ejs>`_.
     * You can create another, just gives the file path to the `EJS <https://ejs.co/>`_ file you wish to send.
     * Here are the locals you can use inside the template:
     *
     * * ``user`` - The current user: ``<p>Hi <%= user.firstName %></p>``
     * * ``link`` - The verification link: ``Click here: <a href="<%= link %>"><%= link %>``
     */
    verifyEmailTemplate?: string;
}
export declare class DefaultProperties implements Properties {
    algorithm: Algorithm;
    authTokenExpiryTime: number;
    dbAddress: string;
    dbConfig: {
        useCreateIndex: boolean;
        useFindAndModify: boolean;
        useNewUrlParser: boolean;
        useUnifiedTopology: boolean;
    };
    eventEmitter: any;
    extendedSchema: {};
    graphiql: boolean;
    host: any;
    mailFrom: any;
    nodemailerConfig: any;
    notificationPageTemplate: string;
    privateKey: any;
    privateKeyFilePath: any;
    publicKey: any;
    publicKeyFilePath: any;
    refreshTokenExpiryTime: number;
    resetPasswordEmailTemplate: string;
    resetPasswordFormTemplate: string;
    verifyEmailTemplate: string;
    onReady: () => void;
}
declare class ServiceConfiguration extends DefaultProperties implements ReadyStatus {
    hostURLObject: any;
    isAgendaReady: boolean;
    isMongooseReady: boolean;
    isTestEmailReady: boolean;
    io: SocketIO.Server;
    clientIdToSocket: Map<string, SocketIO.Socket>;
    /**
     * Setting SocketIO server to push email notifications to GraphiQL IDE
     * @param  {SocketIO.Server} io
     * @returns {void}
     */
    setSocketIO: (io: SocketIO.Server) => void;
    /**
     * Called by Mongoose and Agenda when connection established with MongoDB.
     * When both calls has been made it calls {@link Config#onReady}
     * @param  {ReadyStatus} status
     * @returns {void}
     */
    serviceReady: (status: ReadyStatus) => void;
    /**
     * Called by Mongoose when connection with MongoDB failed.
     * @param  {Error} err
     * @returns {void}
     */
    dbConnectionFailed: (err: Error) => void;
    /**
     * Returns the complete router adress of Krypton Authentication
     * @param  {Request} req
     * @returns The the complete router of the service
     */
    getRouterAddress: (req: any) => string;
    /**
     * Returns the domain of Krypton Authentication to set the domain parameter into cookies
     * @param  {Request} req
     * @returns The domain of the service
     */
    getDomainAddress: () => string;
    /**
     * Merging user options and default properties
     * @param  {Properties} properties?
     * @returns {void}
     */
    set(properties?: Properties): void;
    /**
     * Creates the public and private key pair and saves them in the file paths provided
     * @private
     * @param {string} publicKeyFilePath
     * @param {string} privateKeyFilePath
     * @returns {{ publicKey: string, privateKey: string }}
     * @memberof DefaultConfig
     */
    private createAndSaveKeyPair;
    private getValidMongoDBUrl;
    private getValidhttpUrl;
}
declare const config: ServiceConfiguration;
export default config;
