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

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


Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.jsonbSet = void 0;
var misc_1 = __webpack_require__(854006);
/*
jsonbSet: This little piece of very hard to write (and clever?) code
makes it so we can set or **merge in at any nested level** (!)
arbitrary JSON objects.  We can also delete any key at any
level by making the value null or undefined!  This is amazingly
easy to use in queries -- basically making JSONP with postgres
as expressive as RethinkDB REQL (even better in some ways).
*/
// The input desc is an object that describes what is being set, e.g.,
//     account_id = '... some uuid ';
//     desc = {"users": {[account_id]:{group:'collaborator'}}}
// changes the users JSONB field of the table so that users[account_id] has
// the group set to "collaborator".
// If the merge field is set then we merge in the change; otherwise,
// we replace the value.
// IMPORTANT: this is a dangerous attack vector -- do not call this function
// with unsanitized input from a user!
function jsonbSet(desc, merge) {
    if (merge === void 0) { merge = false; }
    var params = [];
    function pushParam(val, type) {
        if (type.toUpperCase() == "JSONB") {
            val = JSON.stringify(val); // this is needed by the driver....}
        }
        params.push(val);
        return params.length;
    }
    function set(field, data, path) {
        var obj = "COALESCE(".concat(field, "#>'{").concat(path.join(","), "}', '{}'::JSONB)");
        for (var key in data) {
            var val = data[key];
            if (val == null) {
                // remove key from object
                obj = "(".concat(obj, " - '").concat(key, "')");
            }
            else {
                // set key in object
                if (merge && typeof val === "object" && !(0, misc_1.is_date)(val)) {
                    var subobj = set(field, val, path.concat([key]));
                    obj = "JSONB_SET(".concat(obj, ", '{").concat(key, "}', ").concat(subobj, ")");
                }
                else {
                    // completely replace field[key] with val.
                    obj = "JSONB_SET(".concat(obj, ", '{").concat(key, "}', $").concat(pushParam(val, "JSONB"), "::JSONB)");
                }
            }
        }
        return obj;
    }
    var v = [];
    for (var field in desc) {
        var data = desc[field];
        v.push("".concat(field, "=").concat(set(field, data, [])));
    }
    return { set: v.join(","), params: params };
}
exports.jsonbSet = jsonbSet;
//# sourceMappingURL=jsonb-utils.js.map

/***/ }),

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


// Do all the account creation actions for the given account.  This should be called
// immediately after creating the account.
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
var __generator = (this && this.__generator) || function (thisArg, body) {
    var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
    return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
    function verb(n) { return function (v) { return step([n, v]); }; }
    function step(op) {
        if (f) throw new TypeError("Generator is already executing.");
        while (_) try {
            if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
            if (y = 0, t) op = [op[0] & 2, t.value];
            switch (op[0]) {
                case 0: case 1: t = op; break;
                case 4: _.label++; return { value: op[1], done: false };
                case 5: _.label++; y = op[1]; op = [0]; continue;
                case 7: op = _.ops.pop(); _.trys.pop(); continue;
                default:
                    if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
                    if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
                    if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
                    if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
                    if (t[2]) _.ops.pop();
                    _.trys.pop(); continue;
            }
            op = body.call(thisArg, _);
        } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
        if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
    }
};
var __values = (this && this.__values) || function(o) {
    var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
    if (m) return m.call(o);
    if (o && typeof o.length === "number") return {
        next: function () {
            if (o && i >= o.length) o = void 0;
            return { value: o && o[i++], done: !o };
        }
    };
    throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.creationActionsDone = void 0;
var pool_1 = __importDefault(__webpack_require__(541808));
var add_user_to_project_1 = __importDefault(__webpack_require__(159897));
function accountCreationActions(email_address, account_id) {
    return __awaiter(this, void 0, void 0, function () {
        var pool, rows, rows_1, rows_1_1, action, project_id, group, e_1_1;
        var e_1, _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    pool = (0, pool_1.default)();
                    return [4 /*yield*/, pool.query("SELECT action FROM account_creation_actions WHERE email_address=$1 AND expire > NOW()", [email_address])];
                case 1:
                    rows = (_b.sent()).rows;
                    _b.label = 2;
                case 2:
                    _b.trys.push([2, 8, 9, 10]);
                    rows_1 = __values(rows), rows_1_1 = rows_1.next();
                    _b.label = 3;
                case 3:
                    if (!!rows_1_1.done) return [3 /*break*/, 7];
                    action = rows_1_1.value.action;
                    if (!(action.action == "add_to_project")) return [3 /*break*/, 5];
                    project_id = action.project_id, group = action.group;
                    return [4 /*yield*/, (0, add_user_to_project_1.default)({ project_id: project_id, account_id: account_id, group: group })];
                case 4:
                    _b.sent();
                    return [3 /*break*/, 6];
                case 5: throw Error("unknown account creation action \"".concat(action.action, "\""));
                case 6:
                    rows_1_1 = rows_1.next();
                    return [3 /*break*/, 3];
                case 7: return [3 /*break*/, 10];
                case 8:
                    e_1_1 = _b.sent();
                    e_1 = { error: e_1_1 };
                    return [3 /*break*/, 10];
                case 9:
                    try {
                        if (rows_1_1 && !rows_1_1.done && (_a = rows_1.return)) _a.call(rows_1);
                    }
                    finally { if (e_1) throw e_1.error; }
                    return [7 /*endfinally*/];
                case 10: return [2 /*return*/];
            }
        });
    });
}
exports["default"] = accountCreationActions;
function creationActionsDone(account_id) {
    return __awaiter(this, void 0, void 0, function () {
        var pool;
        return __generator(this, function (_a) {
            switch (_a.label) {
                case 0:
                    pool = (0, pool_1.default)();
                    return [4 /*yield*/, pool.query("UPDATE accounts SET creation_actions_done=true WHERE account_id=$1::UUID", [account_id])];
                case 1:
                    _a.sent();
                    return [2 /*return*/];
            }
        });
    });
}
exports.creationActionsDone = creationActionsDone;
//# sourceMappingURL=account-creation-actions.js.map

/***/ }),

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


var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
var __generator = (this && this.__generator) || function (thisArg, body) {
    var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
    return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
    function verb(n) { return function (v) { return step([n, v]); }; }
    function step(op) {
        if (f) throw new TypeError("Generator is already executing.");
        while (_) try {
            if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
            if (y = 0, t) op = [op[0] & 2, t.value];
            switch (op[0]) {
                case 0: case 1: t = op; break;
                case 4: _.label++; return { value: op[1], done: false };
                case 5: _.label++; y = op[1]; op = [0]; continue;
                case 7: op = _.ops.pop(); _.trys.pop(); continue;
                default:
                    if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
                    if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
                    if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
                    if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
                    if (t[2]) _.ops.pop();
                    _.trys.pop(); continue;
            }
            op = body.call(thisArg, _);
        } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
        if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
    }
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
var pool_1 = __importDefault(__webpack_require__(541808));
var jsonb_utils_1 = __webpack_require__(908690);
var misc_1 = __webpack_require__(854006);
function addUserToProject(_a) {
    var account_id = _a.account_id, project_id = _a.project_id, group = _a.group;
    return __awaiter(this, void 0, void 0, function () {
        var pool, _b, set, params;
        var _c;
        return __generator(this, function (_d) {
            switch (_d.label) {
                case 0:
                    if (!(0, misc_1.is_valid_uuid_string)(account_id) || !(0, misc_1.is_valid_uuid_string)(project_id)) {
                        throw Error("account_id and project_id must be UUID's");
                    }
                    pool = (0, pool_1.default)();
                    if (!group) {
                        group = "collaborator";
                    }
                    _b = (0, jsonb_utils_1.jsonbSet)({ users: (_c = {}, _c[account_id] = { group: group }, _c) }), set = _b.set, params = _b.params;
                    return [4 /*yield*/, pool.query("UPDATE projects SET ".concat(set, " WHERE project_id=$").concat(params.length + 1), params.concat(project_id))];
                case 1:
                    _d.sent();
                    return [2 /*return*/];
            }
        });
    });
}
exports["default"] = addUserToProject;
//# sourceMappingURL=add-user-to-project.js.map

/***/ })

};
;