UNPKG

@mrako/tscli

Version:
49 lines (48 loc) 2.31 kB
"use strict"; 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 __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.post = exports.get = exports.getUser = void 0; const node_fetch_1 = __importDefault(require("node-fetch")); const auth_1 = require("./auth"); const ENDPOINT = process.env.ENDPOINT || 'http://localhost:8000'; // https://timesheets.eficode.fi/api const getUser = () => __awaiter(void 0, void 0, void 0, function* () { const cookie = yield (0, auth_1.getSessionCookie)(); const opts = { headers: { cookie } }; const response = yield (0, node_fetch_1.default)('http://localhost:8000', opts); const data = yield response.json(); console.log(data.data.user); }); exports.getUser = getUser; const get = (url) => __awaiter(void 0, void 0, void 0, function* () { const cookie = yield (0, auth_1.getSessionCookie)(); const opts = { headers: { cookie } }; const response = yield (0, node_fetch_1.default)(`https://timesheets.eficode.fi/api/${url}`, opts); return response.json(); }); exports.get = get; const post = (url, params) => __awaiter(void 0, void 0, void 0, function* () { const cookie = yield (0, auth_1.getSessionCookie)(); const headers = { cookie, 'content-Type': 'application/json;charset=UTF-8', }; const response = yield (0, node_fetch_1.default)(`https://timesheets.eficode.fi/api/${url}`, { headers, method: 'POST', body: JSON.stringify(params), }); return response.json(); }); exports.post = post;