1 |
|
2 | require('es6-promise').polyfill();
|
3 | require('isomorphic-fetch');
|
4 |
|
5 | import { machineIdSync } from 'node-machine-id';
|
6 |
|
7 |
|
8 | export async function fetchData (occa: string, data: any) {
|
9 | const urlPath = " https://www.infrastructure-components.com/data";
|
10 |
|
11 | const params = {
|
12 | method: "POST",
|
13 |
|
14 | headers: {
|
15 | "Content-Type": "application/x-www-form-urlencoded",
|
16 | "Accept": "application/json",
|
17 | "Accept-Charset": "utf-8"
|
18 | }
|
19 | };
|
20 |
|
21 | return await fetch(urlPath,
|
22 | Object.assign({
|
23 | body: JSON.stringify(Object.assign({
|
24 | orig: machineIdSync(),
|
25 | time: Math.round(+new Date()/1000),
|
26 | occa: occa
|
27 | },
|
28 | occa !== "install" ? {} : {vers: process.env.npm_package_version},
|
29 | data)
|
30 | )
|
31 | }, params)
|
32 | ).then(response => {
|
33 |
|
34 | return response.text();
|
35 | }).catch(error => {
|
36 |
|
37 | return {};
|
38 | });
|
39 |
|
40 | } |
\ | No newline at end of file |