openfin-cli
Version:
Supports command line development in the OpenFin environment.
51 lines (50 loc) • 3.29 kB
JavaScript
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());
});
};
import axios from 'axios';
import machineId from 'node-machine-id';
import os from 'os';
const getAppName = (configObject) => {
var _a, _b, _c, _d, _e, _f, _g, _h;
return ((_h = (_f = (_d = (_b = (_a = configObject.startup_app) === null || _a === void 0 ? void 0 : _a.name) !== null && _b !== void 0 ? _b : (_c = configObject.startup_app) === null || _c === void 0 ? void 0 : _c.uuid) !== null && _d !== void 0 ? _d : (_e = configObject.platform) === null || _e === void 0 ? void 0 : _e.name) !== null && _f !== void 0 ? _f : (_g = configObject.platform) === null || _g === void 0 ? void 0 : _g.uuid) !== null && _h !== void 0 ? _h : 'no-app-name-or-uuid');
};
export const reportUsage = (status, config, configObject) => __awaiter(void 0, void 0, void 0, function* () {
var _a, _b, _c;
if (process.platform === 'win32')
return;
const reportUrl = new URL('https://install.openfin.co/installer-usage?');
const reportUrlParams = new URLSearchParams({
appName: getAppName(configObject),
appLocation: typeof __dirname !== 'undefined' ? __dirname : 'unknown',
version: (_b = (_a = configObject === null || configObject === void 0 ? void 0 : configObject.runtime) === null || _a === void 0 ? void 0 : _a.version) !== null && _b !== void 0 ? _b : 'undefined',
machineId: yield machineId.machineId(true),
manifestUrl: config !== null && config !== void 0 ? config : 'undefined',
platform: `${os.platform()}-${os.release()})`,
licenseKey: (_c = configObject === null || configObject === void 0 ? void 0 : configObject.licenseKey) !== null && _c !== void 0 ? _c : 'contract_identifier',
launchMethod: 'openfin-cli',
launchStatus: status || 'SUCCESS',
});
reportUrl.search = reportUrlParams.toString();
try {
const reportUrlString = reportUrl.toString();
global.logger.debug(`OpenFin Reporting Usage Data: ${reportUrlString}`);
const response = yield axios.get(reportUrlString);
if (response.status !== 200) {
global.logger.error('OpenFin Report Usage Data Failed');
}
else {
global.logger.debug(`OpenFin Report Usage Data: Status: ${response.status}`);
global.logger.debug(`OpenFin Report Usage Data: Response: ${response.data.toString()}`);
}
}
catch (error) {
const err = error instanceof Error || error instanceof String ? error.toString() : JSON.stringify(error);
global.logger.warn('OpenFin Report Usage Data Failed:', err);
}
});