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

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

module.exports = require("assert");

/***/ }),

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

module.exports = require("buffer");

/***/ }),

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

module.exports = require("child_process");

/***/ }),

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

module.exports = require("cluster");

/***/ }),

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

module.exports = require("constants");

/***/ }),

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

module.exports = require("crypto");

/***/ }),

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

module.exports = require("dns");

/***/ }),

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

module.exports = require("events");

/***/ }),

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

module.exports = require("fs");

/***/ }),

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

module.exports = require("fs/promises");

/***/ }),

/***/ 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");

/***/ }),

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

module.exports = require("perf_hooks");

/***/ }),

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

module.exports = require("process");

/***/ }),

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

module.exports = require("readline");

/***/ }),

/***/ 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");

/***/ }),

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

module.exports = require("v8");

/***/ }),

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

module.exports = require("zlib");

/***/ }),

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

__webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */   "callProject": () => (/* binding */ callProject),
/* harmony export */   "default": () => (/* binding */ handle)
/* harmony export */ });
/* harmony import */ var _cocalc_server_projects_connection_call__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(113011);
/* harmony import */ var _cocalc_server_projects_connection_call__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_cocalc_server_projects_connection_call__WEBPACK_IMPORTED_MODULE_0__);
/* harmony import */ var lib_api_get_params__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(26438);
/* harmony import */ var lib_account_get_account__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(559459);
/* harmony import */ var _cocalc_util_misc__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(854006);
/* harmony import */ var _cocalc_util_misc__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_cocalc_util_misc__WEBPACK_IMPORTED_MODULE_2__);
/* harmony import */ var _cocalc_server_projects_is_collaborator__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(126804);
/* harmony import */ var _cocalc_server_projects_is_collaborator__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(_cocalc_server_projects_is_collaborator__WEBPACK_IMPORTED_MODULE_3__);
/*
API endpoint that makes it possible to send a message to a project
that the user is a collaborator on and get back a response.

See cocalc/src/packages/server/projects/connection/call.ts
for a list of messages.
*/ 




async function handle(req, res) {
    const account_id = await (0,lib_account_get_account__WEBPACK_IMPORTED_MODULE_1__/* ["default"] */ .Z)(req);
    try {
        const { project_id , mesg  } = (0,lib_api_get_params__WEBPACK_IMPORTED_MODULE_4__/* ["default"] */ .Z)(req);
        res.json(await callProject({
            account_id,
            project_id,
            mesg
        }));
    } catch (err) {
        res.json({
            error: err.message
        });
    }
}
// also used by the latex api call
async function callProject({ account_id , project_id , mesg ,  }) {
    if (!(0,_cocalc_util_misc__WEBPACK_IMPORTED_MODULE_2__.isValidUUID)(account_id)) {
        throw Error("user must be authenticated");
    }
    if (!(0,_cocalc_util_misc__WEBPACK_IMPORTED_MODULE_2__.isValidUUID)(project_id)) {
        throw Error("must specify project_id");
    }
    if (!await _cocalc_server_projects_is_collaborator__WEBPACK_IMPORTED_MODULE_3___default()({
        account_id,
        project_id
    })) {
        throw Error("authenticated user must be a collaborator on the project");
    }
    return await _cocalc_server_projects_connection_call__WEBPACK_IMPORTED_MODULE_0___default()({
        project_id,
        mesg
    });
}


/***/ }),

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


/*
Use the project hub socket API to communicate with the project.

The supported messages are implemented here in the project:

   cocalc/src/packages/project/servers/hub/handle-message.ts

and messages must be defined as in

   cocalc/src/packages/util/message.js

and they include:

- ping: for testing; returns a pong
- heartbeat: used for maintaining the connection
- named_server_port: finding out the port used by jupyter, jupyterlab, etc.
- project_exec: run shell command
- read_file_from_project: reads file and stores it as a blob in the database. blob expires in 24 hours.
- write_file_to_project: write abitrary file to disk in project (goes via a blob)
- write_text_file_to_project: write a text file, whose contents is in the message, to the project.
- print_to_pdf: tells sage worksheet to print
- send_signal: send a signal to a process
*/
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
const handle_message_1 = __webpack_require__(386441);
const connect_1 = __importDefault(__webpack_require__(673317));
async function call({ project_id, mesg, }) {
    const socket = await (0, connect_1.default)(project_id);
    return await (0, handle_message_1.callProjectMessage)({ mesg, socket });
}
exports["default"] = call;
//# sourceMappingURL=call.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, [6918,1199,8180,2921,9557,5245,6652,6942,5517,6099,5751,2739,6257,8759,2003,1808,4006,8312,5710,9459,4181,4557,7896,6177,7710,4012,5970,6394], () => (__webpack_exec__(219817)));
module.exports = __webpack_exports__;

})();