UNPKG

t-comm

Version:

专业、稳定、纯粹的工具库

82 lines (75 loc) 2.86 kB
'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); var _regeneratorRuntime = require('@babel/runtime/regenerator'); var tslib_es6 = require('../tslib.es6-0d92ef81.js'); var axios = require('axios'); function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; } var _regeneratorRuntime__default = /*#__PURE__*/_interopDefaultLegacy(_regeneratorRuntime); var axios__default = /*#__PURE__*/_interopDefaultLegacy(axios); var ReportType; (function (ReportType) { ReportType[ReportType["PERFORMANCE"] = 1] = "PERFORMANCE"; ReportType[ReportType["BUNDLE"] = 2] = "BUNDLE"; ReportType[ReportType["AUTO_TEST"] = 3] = "AUTO_TEST"; ReportType[ReportType["BUNDLE_MP"] = 4] = "BUNDLE_MP"; })(ReportType || (ReportType = {})); var ReportPlatform; (function (ReportPlatform) { ReportPlatform[ReportPlatform["NOT_KNOWN"] = 0] = "NOT_KNOWN"; ReportPlatform[ReportPlatform["H5"] = 1] = "H5"; ReportPlatform[ReportPlatform["MP"] = 2] = "MP"; })(ReportPlatform || (ReportPlatform = {})); /** * 上报数据到研发平台 * @param {object} param 参数 * @param {object} param.data 上报数据 * @param {string} param.host 请求域名 * @param {ReportType} param.type 上报类型 * @param {ReportPlatform} param.platform 上报平台 * @returns 上报结果 * @example * ```ts * await reportToRdPlatform({ * data: { metric: 'fcp', value: 1234 }, * host: 'https://your-host.example.com', * type: 1, // PERFORMANCE * platform: 1, // H5 * }); * ``` */ function reportToRdPlatform(_ref) { var data = _ref.data, host = _ref.host, _ref$type = _ref.type, type = _ref$type === void 0 ? 1 : _ref$type, _ref$platform = _ref.platform, platform = _ref$platform === void 0 ? 1 : _ref$platform; return tslib_es6.__awaiter(this, void 0, void 0, /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee() { var url, res; return _regeneratorRuntime__default["default"].wrap(function (_context) { while (1) switch (_context.prev = _context.next) { case 0: url = host.includes('localhost:') ? "".concat(host, "/performance-report") : "".concat(host, "/rd-platform-cgi/performance-report"); _context.next = 1; return axios__default["default"]({ method: 'POST', url: url, data: { data: data, type: type, platform: platform } })["catch"](function (err) { console.log('[reportToRdPlatform] err', err); }); case 1: res = _context.sent; return _context.abrupt("return", res.data); case 2: case "end": return _context.stop(); } }, _callee); })); } exports.reportToRdPlatform = reportToRdPlatform;