"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());
    });
};
Object.defineProperty(exports, "__esModule", { value: true });
require('es6-promise').polyfill();
require('isomorphic-fetch');
// @ts-ignore
const node_machine_id_1 = require("node-machine-id");
function fetchData(occa, data) {
    return __awaiter(this, void 0, void 0, function* () {
        const urlPath = " https://www.infrastructure-components.com/data";
        const params = {
            method: "POST",
            headers: {
                "Content-Type": "application/x-www-form-urlencoded",
                "Accept": "application/json",
                "Accept-Charset": "utf-8"
            }
        };
        return yield fetch(urlPath, Object.assign({
            body: JSON.stringify(Object.assign({
                orig: node_machine_id_1.machineIdSync(),
                time: Math.round(+new Date() / 1000),
                occa: occa
            }, occa !== "install" ? {} : { vers: process.env.npm_package_version }, data))
        }, params)).then(response => {
            //console.log("post result: ", response);
            return response.text();
        }).catch(error => {
            //console.error("post-error: ", error);
            return {};
        });
    });
}
exports.fetchData = fetchData;
//# sourceMappingURL=scripts-libs.js.map