"use strict";
(() => {
var exports = {};
exports.id = 8500;
exports.ids = [8500];
exports.modules = {

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

module.exports = require("assert");

/***/ }),

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

module.exports = require("buffer");

/***/ }),

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

module.exports = require("crypto");

/***/ }),

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

module.exports = require("dns");

/***/ }),

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

module.exports = require("events");

/***/ }),

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

module.exports = require("fs");

/***/ }),

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

module.exports = require("http");

/***/ }),

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

module.exports = require("https");

/***/ }),

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

module.exports = require("net");

/***/ }),

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

module.exports = require("os");

/***/ }),

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

module.exports = require("path");

/***/ }),

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

module.exports = require("process");

/***/ }),

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

module.exports = require("punycode");

/***/ }),

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

module.exports = require("querystring");

/***/ }),

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

module.exports = require("stream");

/***/ }),

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

module.exports = require("string_decoder");

/***/ }),

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

module.exports = require("tls");

/***/ }),

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

module.exports = require("tty");

/***/ }),

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

module.exports = require("url");

/***/ }),

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

module.exports = require("util");

/***/ }),

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

module.exports = require("zlib");

/***/ }),

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

__webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */   "default": () => (/* binding */ handle)
/* harmony export */ });
/* harmony import */ var _cocalc_server_support_get_tickets__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(889552);
/* harmony import */ var _cocalc_server_support_get_tickets__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_cocalc_server_support_get_tickets__WEBPACK_IMPORTED_MODULE_0__);
/* harmony import */ var lib_account_get_account__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(559459);
/*
Get all support tickets for a signed in user.
*/ 

async function handle(req, res) {
    const account_id = await (0,lib_account_get_account__WEBPACK_IMPORTED_MODULE_1__/* ["default"] */ .Z)(req);
    if (account_id == null) {
        res.json({
            error: "you must be signed in to get support tickets"
        });
        return;
    }
    let tickets;
    try {
        tickets = await _cocalc_server_support_get_tickets__WEBPACK_IMPORTED_MODULE_0___default()(account_id);
    } catch (err) {
        res.json({
            error: `${err.message}`
        });
        return;
    }
    res.json({
        tickets
    });
}


/***/ }),

/***/ 889552:
/***/ (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 zendesk_client_1 = __importDefault(__webpack_require__(214641));
const misc_1 = __webpack_require__(854006);
const util_1 = __webpack_require__(662895);
async function getTickets(account_id) {
    if (!(0, misc_1.is_valid_uuid_string)(account_id)) {
        return [];
    }
    const client = await (0, zendesk_client_1.default)();
    // See https://developer.zendesk.com/api-reference/ticketing/ticket-management/search/
    const query = `type:ticket external_id:${account_id}`;
    // @ts-ignore
    const result = await client.search.query(query);
    for (const ticket of result) {
        // ticket url is a JSON object, but we need a nice link that the user can click
        // on to interact with the ticket.
        ticket.userURL = (0, util_1.urlToUserURL)(ticket.url);
    }
    return result;
}
exports["default"] = getTickets;
//# sourceMappingURL=get-tickets.js.map

/***/ })

};
;

// 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,6652,6942,5517,6099,4069,1808,4006,8312,5710,9459,4181,4557,7896,6177,5486], () => (__webpack_exec__(18386)));
module.exports = __webpack_exports__;

})();