UNPKG

genezio

Version:

Command line utility to interact with Genezio infrastructure.

106 lines (105 loc) 3.61 kB
"use strict"; /** * This is an auto generated code. This code should not be modified since the file can be overwritten * if new genezio commands are executed. */ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); Object.defineProperty(exports, "__esModule", { value: true }); exports.Remote = void 0; const http = __importStar(require("http")); const https = __importStar(require("https")); async function makeRequestNode(request, url, agent) { const data = JSON.stringify(request); const hostUrl = new URL(url); const options = { hostname: hostUrl.hostname, path: hostUrl.search ? hostUrl.pathname + hostUrl.search : hostUrl.pathname, port: hostUrl.port, method: "POST", headers: { "Content-Type": "application/json", }, agent: agent, }; const client = url.includes("https") ? https : http; return new Promise((resolve, reject) => { const req = client.request(options, (res) => { let body = ""; res.on("data", (d) => { body += d; }); res.on("end", function () { const response = JSON.parse(body); resolve(response); }); }); req.on("error", (error) => { reject(error); }); req.write(data); req.end(); }); } /** * The class through which all request to the Genezio backend will be passed. * */ class Remote { constructor(url) { this.url = undefined; this.agent = undefined; this.url = url; if (http !== null && https !== null) { const client = url.includes("https") ? https : http; this.agent = new client.Agent({ keepAlive: true }); } } deserialize(s) { const e = new Error(s.message); e.stack = s.stack; e.info = s.info; e.code = s.code; return e; } async call(method, ...args) { const requestContent = { jsonrpc: "2.0", method: method, params: args, id: 3 }; const response = await makeRequestNode(requestContent, this.url, this.agent); if (response.error) { throw this.deserialize(response.error); } return response.result; } } exports.Remote = Remote;