(() => {
var exports = {};
exports.id = 735;
exports.ids = [735];
exports.modules = {

/***/ 439491:
/***/ ((module) => {

"use strict";
module.exports = require("assert");

/***/ }),

/***/ 714300:
/***/ ((module) => {

"use strict";
module.exports = require("buffer");

/***/ }),

/***/ 706113:
/***/ ((module) => {

"use strict";
module.exports = require("crypto");

/***/ }),

/***/ 809523:
/***/ ((module) => {

"use strict";
module.exports = require("dns");

/***/ }),

/***/ 582361:
/***/ ((module) => {

"use strict";
module.exports = require("events");

/***/ }),

/***/ 657147:
/***/ ((module) => {

"use strict";
module.exports = require("fs");

/***/ }),

/***/ 113685:
/***/ ((module) => {

"use strict";
module.exports = require("http");

/***/ }),

/***/ 241808:
/***/ ((module) => {

"use strict";
module.exports = require("net");

/***/ }),

/***/ 822037:
/***/ ((module) => {

"use strict";
module.exports = require("os");

/***/ }),

/***/ 371017:
/***/ ((module) => {

"use strict";
module.exports = require("path");

/***/ }),

/***/ 677282:
/***/ ((module) => {

"use strict";
module.exports = require("process");

/***/ }),

/***/ 12781:
/***/ ((module) => {

"use strict";
module.exports = require("stream");

/***/ }),

/***/ 371576:
/***/ ((module) => {

"use strict";
module.exports = require("string_decoder");

/***/ }),

/***/ 924404:
/***/ ((module) => {

"use strict";
module.exports = require("tls");

/***/ }),

/***/ 76224:
/***/ ((module) => {

"use strict";
module.exports = require("tty");

/***/ }),

/***/ 257310:
/***/ ((module) => {

"use strict";
module.exports = require("url");

/***/ }),

/***/ 473837:
/***/ ((module) => {

"use strict";
module.exports = require("util");

/***/ }),

/***/ 817831:
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {

"use strict";
__webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */   "default": () => (/* binding */ handle)
/* harmony export */ });
/* harmony import */ var _cocalc_server_licenses_get_managed__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(644415);
/* harmony import */ var _cocalc_server_licenses_get_managed__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_cocalc_server_licenses_get_managed__WEBPACK_IMPORTED_MODULE_0__);
/* harmony import */ var lib_account_get_account__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(559459);
/*
Get all licenses that the signed in user manages.

See docs in @cocalc/server/licenses/get-managed.ts

Returns [License1, License2, ...] on success or {error:'a message'} on failure.
For the fields in the License objects, see @cocalc/server/licenses/get-managed.ts
*/ 

async function handle(req, res) {
    try {
        res.json(await get(req));
    } catch (err) {
        res.json({
            error: `${err.message}`
        });
        return;
    }
}
async function get(req) {
    const account_id = await (0,lib_account_get_account__WEBPACK_IMPORTED_MODULE_1__/* ["default"] */ .Z)(req);
    if (account_id == null) {
        return [];
    }
    return await _cocalc_server_licenses_get_managed__WEBPACK_IMPORTED_MODULE_0___default()(account_id);
}


/***/ }),

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

"use strict";

/*
Returns array of licenses that a given user manages.
*/
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));
const util_1 = __webpack_require__(863563);
const misc_1 = __webpack_require__(854006);
async function getManagedLicenses(account_id) {
    if (!(0, misc_1.isValidUUID)(account_id)) {
        throw Error("invalid account_id -- must be a uuid");
    }
    const pool = (0, pool_1.default)();
    const { rows } = await pool.query(`SELECT id, title, description,
    expires, activates, last_used, created,
    managers, upgrades, quota, run_limit, info
    FROM site_licenses WHERE $1=ANY(managers) ORDER BY created DESC`, [account_id]);
    (0, util_1.toEpoch)(rows, ["expires", "activates", "last_used", "created"]);
    for (const row of rows) {
        row.is_manager = true;
    }
    return rows;
}
exports["default"] = getManagedLicenses;
//# sourceMappingURL=get-managed.js.map

/***/ }),

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

var crypto = __webpack_require__(706113);

var rn = function(max) {
  var rnBytes = crypto.randomBytes(2);
  var randomNum = rnBytes.readUInt8(0) * 256 + rnBytes.readUInt8(1);
  return randomNum % max;
}

var digits = '0123456789'
var base62 = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz'
var base30 = '0123456789ABCDFHKLMNPQRSTUVWXYZ'  // 1-9, A-Z exclude(E, G, I, J, O) for human read

exports.generate = function(len, chars) {
  len = len || 16;
  chars = chars || base62;
  var key = '';
  var charsLen = chars.length;
  for (var i=0; i<len; i++) {
    key += chars[rn(charsLen)];
  }
  return key;
};

exports.generateDigits = function(len) {
  len = len || 16;
  return exports.generate(len, digits)
};

exports.generateBase30 = function(len) {
  len = len || 16;
  return exports.generate(len, base30)
}


/***/ })

};
;

// load runtime
var __webpack_require__ = require("../../../../webpack-api-runtime.js");
__webpack_require__.C(exports);
var __webpack_exec__ = (moduleId) => (__webpack_require__(__webpack_require__.s = moduleId))
var __webpack_exports__ = __webpack_require__.X(0, [8180,2921,9557,5245,1808,4006,8312,5710,9459,3563], () => (__webpack_exec__(817831)));
module.exports = __webpack_exports__;

})();