"use strict";
exports.id = 9022;
exports.ids = [9022];
exports.modules = {

/***/ 29459:
/***/ (function(__unused_webpack_module, exports, __webpack_require__) {


var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
const pool_1 = __importDefault(__webpack_require__(541808));
async function isAccountAvailable(email_address) {
    const pool = (0, pool_1.default)("medium");
    const { rows } = await pool.query("SELECT account_id FROM accounts WHERE email_address=$1", [email_address]);
    return rows.length == 0;
}
exports["default"] = isAccountAvailable;
//# sourceMappingURL=is-account-available.js.map

/***/ }),

/***/ 74895:
/***/ (function(__unused_webpack_module, exports, __webpack_require__) {


var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.getFooter = void 0;
const settings_1 = __webpack_require__(840336);
const site_url_1 = __importDefault(__webpack_require__(661348));
async function getFooter() {
    let { help_email, site_name, organization_name, organization_url } = await (0, settings_1.getServerSettings)();
    // Make sure everything is defined somehow...
    if (!help_email) {
        help_email = "help@cocalc.com";
    }
    if (!site_name) {
        site_name = "OpenCoCalc";
    }
    if (!organization_name) {
        organization_name = "Hosted CoCalc";
    }
    if (!organization_url) {
        try {
            organization_url = await (0, site_url_1.default)();
        }
        catch (_) {
            organization_url = "https://example.com";
        }
    }
    const html = `
<p style="margin-top:100px; padding-top:15px; border-top: 1px solid gray; color: gray; font-size:85%; text-align:center">
This email was sent from <a href="${organization_url}">${site_name}</a> by ${organization_name}.
Contact <a href="mailto:${help_email}">${help_email}</a> if you have any questions.
</p>`;
    const text = `\n\n\n\n----------------------------------------------------------------------
This email was sent from ${site_name} by ${organization_name} (see ${organization_url}).
Contact ${help_email} if you have any questions.
`;
    return { html, text };
}
exports.getFooter = getFooter;
async function appendFooter(message) {
    let footer;
    try {
        footer = await getFooter();
    }
    catch (_) {
        return message;
    }
    return {
        ...message,
        html: message.html + "\n\n" + footer.html,
        text: message.text + "\n\n" + footer.text,
    };
}
exports["default"] = appendFooter;
//# sourceMappingURL=footer.js.map

/***/ }),

/***/ 526577:
/***/ (function(__unused_webpack_module, exports, __webpack_require__) {


/* Returns the configured help email address.
   Cached with "long" TTL so doesn't put load on database
   even if called frequently.
*/
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
const pool_1 = __importDefault(__webpack_require__(541808));
async function getHelpEmail() {
    const pool = (0, pool_1.default)("long");
    const { rows } = await pool.query("SELECT value FROM server_settings WHERE name='help_email'");
    if (rows.length == 0 || !rows[0].value) {
        throw Error("no help email address set");
    }
    return rows[0].value;
}
exports["default"] = getHelpEmail;
//# sourceMappingURL=help.js.map

/***/ }),

/***/ 92500:
/***/ (function(__unused_webpack_module, exports, __webpack_require__) {


/* We use the official V3 Sendgrid API:

https://www.npmjs.com/package/@sendgrid/mail

The cocalc ASM group numbers are at

https://app.sendgrid.com/suppressions/advanced_suppression_manager
*/
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.getSendgrid = void 0;
const pool_1 = __importDefault(__webpack_require__(541808));
const mail_1 = __importDefault(__webpack_require__(949571));
const help_1 = __importDefault(__webpack_require__(526577));
const footer_1 = __importDefault(__webpack_require__(74895));
const theme_1 = __webpack_require__(981975);
// Init throws error if we can't initialize Sendgrid right now.
// It also updates the key if it changes in at most one minute (?).
let initialized = 0;
async function getSendgrid() {
    const now = new Date().valueOf();
    if (now - initialized < 1000 * 30) {
        // initialized recently
        return mail_1.default;
    }
    const pool = (0, pool_1.default)("long");
    const { rows } = await pool.query("SELECT value FROM server_settings WHERE name='sendgrid_key'");
    if (rows.length == 0 || !rows[0]?.value) {
        if (initialized) {
            // no key now, but there was a key before -- so clear it and error
            mail_1.default.setApiKey("");
        }
        throw Error("no sendgrid key");
    }
    mail_1.default.setApiKey(rows[0].value);
    initialized = new Date().valueOf();
    return mail_1.default;
}
exports.getSendgrid = getSendgrid;
async function sendEmail(message) {
    const sg = await getSendgrid();
    const msg = await (0, footer_1.default)(message);
    if (!msg.from) {
        msg.from = await (0, help_1.default)(); // fallback
    }
    if (msg.asm_group) {
        msg.asm = { group_id: msg.asm_group };
        delete msg.asm_group;
    }
    // plain template with a header (cocalc logo), a h1 title, and a footer
    msg.template_id = theme_1.SENDGRID_TEMPLATE_ID;
    // https://docs.sendgrid.com/api-reference/mail-send/mail-send
    await sg.send(msg);
}
exports["default"] = sendEmail;
//# sourceMappingURL=sendgrid.js.map

/***/ }),

/***/ 738182:
/***/ (function(__unused_webpack_module, exports, __webpack_require__) {


/*
 *  This file is part of CoCalc: Copyright © 2021 Sagemath, Inc.
 *  License: AGPLv3 s.t. "Commons Clause" – see LICENSE.md for details
 */
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
const nodemailer_1 = __webpack_require__(765909);
const help_1 = __importDefault(__webpack_require__(526577));
const footer_1 = __importDefault(__webpack_require__(74895));
const server_settings_1 = __webpack_require__(526177);
async function sendEmail(message, type = "email") {
    let settings;
    try {
        settings = await getSMTPSettings(type);
    }
    catch (err) {
        throw Error(`SMTP ${type} is not properly configured for this server. Contact the site administrator. -- ${err}`);
    }
    if (!message.from) {
        if (settings.from) {
            message.from = settings.from;
        }
        else {
            message.from = await (0, help_1.default)(); // fallback
        }
    }
    const server = await getServer(settings);
    const msg = await (0, footer_1.default)(message);
    await server.sendMail(msg);
}
exports["default"] = sendEmail;
let server = undefined;
let cacheSettings = ""; // what settings were used to compute cached server.
async function getServer(settings) {
    const s = JSON.stringify(settings);
    if (server !== undefined && s == cacheSettings)
        return server;
    server = await (0, nodemailer_1.createTransport)({
        host: settings.server,
        port: settings.port,
        secure: settings.secure,
        auth: {
            user: settings.login,
            pass: settings.password,
        },
    });
    cacheSettings = s;
    return server;
}
/**
 * Depending on if this is for regular emails or password resets,
 * we return the SMTP settings depending on the server settings.
 * Usually, password reset and regular email settings are the same for SMTP.
 * Only exception is when that override entry is set to smtp, then use the
 * secondary SMTP configuartion.
 */
async function getEmailServerSettings(type) {
    const settings = await (0, server_settings_1.getServerSettings)();
    const defaultSMTP = {
        server: settings.email_smtp_server,
        login: settings.email_smtp_login,
        password: settings.email_smtp_password,
        secure: settings.email_smtp_secure,
        from: settings.email_smtp_from,
        port: settings.email_smtp_port,
    };
    if (type == "email") {
        return defaultSMTP;
    }
    switch (settings.password_reset_override) {
        case "default":
            return defaultSMTP;
        case "smtp":
            return {
                server: settings.password_reset_smtp_server,
                login: settings.password_reset_smtp_login,
                password: settings.password_reset_smtp_password,
                secure: settings.password_reset_smtp_secure,
                from: settings.password_reset_smtp_from,
                port: settings.password_reset_smtp_port,
            };
    }
    throw new Error(`unexpected password_reset_override: ${settings.password_reset_override}`);
}
async function getSMTPSettings(type) {
    if (type != "email" && type != "password_reset") {
        throw Error("type must be 'email' or 'password_reset'");
    }
    const settings = await getEmailServerSettings(type);
    if (!settings.server) {
        throw Error(`SMTP ${type} server must be configured`);
    }
    if (!settings.login) {
        throw Error(`SMTP ${type} username must be configured`);
    }
    if (!settings.password) {
        throw Error(`SMTP ${type} password must be configured`);
    }
    return settings;
}
//# sourceMappingURL=smtp.js.map

/***/ }),

/***/ 840336:
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {


Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.getServerSettings = void 0;
var server_settings_1 = __webpack_require__(526177);
Object.defineProperty(exports, "getServerSettings", ({ enumerable: true, get: function () { return server_settings_1.getServerSettings; } }));
//# sourceMappingURL=index.js.map

/***/ }),

/***/ 661348:
/***/ (function(__unused_webpack_module, exports, __webpack_require__) {


var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
const server_settings_1 = __webpack_require__(526177);
const base_path_1 = __importDefault(__webpack_require__(8312));
// Returns url of this site in terms of the base path (determined
// by an env variable when server starts) and the "Domain name"
// setting of site settings.  This URL does NOT end in a /
async function siteURL(dns) {
    if (!dns) {
        dns = (await (0, server_settings_1.getServerSettings)()).dns?.toLowerCase();
    }
    if (!dns) {
        dns = "localhost";
    }
    if (!dns.startsWith("http")) {
        dns = "https://" + dns;
    }
    return `${dns}${base_path_1.default == "/" ? "" : base_path_1.default}`;
}
exports["default"] = siteURL;
//# sourceMappingURL=site-url.js.map

/***/ }),

/***/ 981975:
/***/ ((__unused_webpack_module, exports) => {


/*
 *  This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.
 *  License: AGPLv3 s.t. "Commons Clause" – see LICENSE.md for details
 */
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.COLORS = exports.SENDGRID_ASM_NEWSLETTER = exports.SENDGRID_ASM_INVITES = exports.SENDGRID_TEMPLATE_ID = exports.JUPYTER_CLASSIC_MODERN = exports.sign_up_id = exports.gtag_id = exports.COPYRIGHT_AGENT_HTML = exports.BILLING_TAXID = exports.BILLING_ADDRESS = exports.BILLING_EMAIL = exports.TWITTER_HANDLE = exports.HELP_EMAIL = exports.LIVE_DEMO_REQUEST = exports.BLOG_URL = exports.DOC_URL = exports.DISCUSSION_GROUP = exports.DOMAIN_URL = exports.DNS = exports.APP_TAGLINE = exports.COMPANY_EMAIL = exports.COMPANY_NAME = exports.SITE_NAME = void 0;
/*
Theme configuration file for CoCalc

Copyright 2017, SageMath, Inc. -- ALL RIGHTS RESERVED

This file is not part of the open-source licensed release, because it contains information
specific to the company "SageMath, Inc." and the product "CoCalc".
Upon deployment, please replace this file with a suitable replacement (i.e. come up with your own name, etc.)

This is used mainly in the front-end, but some aspects are also used on the back-end
*/
exports.SITE_NAME = "CoCalc";
exports.COMPANY_NAME = "SageMath, Inc.";
exports.COMPANY_EMAIL = "office@sagemath.com";
exports.APP_TAGLINE = "Collaborative Calculation";
exports.DNS = "cocalc.com";
exports.DOMAIN_URL = `https://${exports.DNS}`;
exports.DISCUSSION_GROUP = "https://groups.google.com/forum/#!forum/cocalc";
exports.DOC_URL = "https://doc.cocalc.com/";
exports.BLOG_URL = "https://blog.sagemath.com/";
exports.LIVE_DEMO_REQUEST = "https://docs.google.com/forms/d/e/1FAIpQLSesDZkGD2XVu8BHKd_sPwn5g7MrLAA8EYRTpB6daedGVMTpkA/viewform";
exports.HELP_EMAIL = "help@cocalc.com";
exports.TWITTER_HANDLE = "cocalc_com"; // without the @
exports.BILLING_EMAIL = "billing@sagemath.com";
exports.BILLING_ADDRESS = `\
17725 SE 123RD PL
Renton, WA 98059-6621
USA\
`;
exports.BILLING_TAXID = "TAX EIN: 47-3015407";
exports.COPYRIGHT_AGENT_HTML = `\
William Stein (Copyright Agent)<br>
c/o SageMath, Inc.<br>
17725 SE 123RD PL<br>
Renton, WA 98059-6621<br>
USA<br>
<a href='mailto:copyright@sagemath.com'>copyright@sagemath.com</a>\
`;
// for conversion tracking (commercial only)
exports.gtag_id = "AW-943259268";
exports.sign_up_id = "44ZfCImosncQhP3jwQM";
// documentation
exports.JUPYTER_CLASSIC_MODERN = "https://doc.cocalc.com/jupyter.html#classical-versus-cocalc";
// this is used in packages/hub/email.coffee and hub.coffee to specify the template and ASM groups for sendgrid
exports.SENDGRID_TEMPLATE_ID = "0375d02c-945f-4415-a611-7dc3411e2a78";
// asm_group: 699 is for invites https://app.sendgrid.com/suppressions/advanced_suppression_manager
exports.SENDGRID_ASM_INVITES = 699;
exports.SENDGRID_ASM_NEWSLETTER = 698;
// This is the applications color scheme
const MAIN_COLORS = {
    BLUE_DDD: "#0E2B59",
    BLUE_DD: "#2A5AA6",
    BLUE_D: "#4474c0",
    BLUE: "#6690D2",
    BLUE_L: "#80afff",
    BLUE_LL: "#94B3E5",
    BLUE_LLL: "#c7d9f5",
    BLUE_DOC: "#4375c1",
    BRWN: "#593E05",
    YELL_D: "#bf7b00",
    YELL_L: "#fbb635",
    GRAY_DDD: "#dddddd",
    GRAY_DD: "#303030",
    GRAY_D: "#434343",
    GRAY_M: "#5f5f5f",
    GRAY: "#808080",
    GRAY_L: "#c0c0c0",
    GRAY_L0: "#e0e0e0",
    GRAY_LL: "#eeeeee",
    GRAY_LLL: "#f5f5f5",
    // bootstrap 3 colors
    BS_GREEN_BGRND: "rgb(92,184,92)",
    BS_BLUE_BGRND: "rgb(66, 139, 202)",
    BS_BLUE_TEXT: "rgb(33, 150, 243)",
    BS_GREEN_LL: "#E8F5E9",
    BS_GREEN: "#5CB85C",
    BS_GREEN_D: "#449d44",
    BS_GREEN_DD: "#398439",
    BS_RED: "#dc3545",
    // These were inexplicably in app-framework.ts, so I moved them here.
    BG_RED: "#d9534f",
    FG_RED: "#c9302c",
    FG_BLUE: "#428bca",
    ATND_BG_RED_M: "#ff7875",
    ATND_BG_RED_L: "#fff2f0",
    ANTD_BG_BLUE_L: "#e6f4ff",
    ANTD_RED_WARN: "#f5222d",
    ANTD_YELL_M: "#fadb14",
    ANTD_RED: "#f5222d",
    ANTD_ORANGE: "#ffbb96",
    ANTD_GREEN: "#87d068",
    ANTD_GREEN_D: "#237804",
    COCALC_BLUE: "#4474c0",
    COCALC_ORANGE: "#fcc861", // orange used for the logo
};
exports.COLORS = {
    ...MAIN_COLORS,
    // The definitions below add semantic meaning by using the colors
    // navigation bar at the top
    TOP_BAR: {
        BG: MAIN_COLORS.GRAY_LL,
        HOVER: MAIN_COLORS.GRAY_LLL,
        ACTIVE: "white",
        TEXT: MAIN_COLORS.GRAY,
        TEXT_ACTIVE: MAIN_COLORS.GRAY_D,
        X: MAIN_COLORS.GRAY,
        X_HOVER: MAIN_COLORS.GRAY_L,
        SIGN_IN_BG: MAIN_COLORS.YELL_L,
    },
    // landing page
    LANDING: { LOGIN_BAR_BG: MAIN_COLORS.BLUE_D },
};
//# sourceMappingURL=theme.js.map

/***/ })

};
;