UNPKG

@trap_stevo/metrictide-client

Version:

A resilient, smart client designed to stream, store, and query metrics to and from a MetricTide analytics server. Whether you're tracking product usage, performance signals, or user behavior, MetricTide Client offers seamless integration, offline robustne

1,228 lines 51.8 kB
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties"; import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator"; import _defineProperty from "@babel/runtime/helpers/defineProperty"; import _classCallCheck from "@babel/runtime/helpers/classCallCheck"; import _createClass from "@babel/runtime/helpers/createClass"; var _excluded = ["headers"], _excluded2 = ["headers"]; function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; } function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } } function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; } import _regeneratorRuntime from "@babel/runtime/regenerator"; function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; } function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; } function _classPrivateMethodInitSpec(e, a) { _checkPrivateRedeclaration(e, a), a.add(e); } function _checkPrivateRedeclaration(e, t) { if (t.has(e)) throw new TypeError("Cannot initialize the same private elements twice on an object"); } function _assertClassBrand(e, t, n) { if ("function" == typeof e ? e === t : e.has(t)) return arguments.length < 3 ? t : n; throw new TypeError("Private element is not present on this object"); } import { ConnectPulse } from "@trap_stevo/connect-pulse"; import { VeriLink } from "@trap_stevo/verilink"; var _HUDMetricTide_brand = /*#__PURE__*/new WeakSet(); var HUDMetricTide = /*#__PURE__*/function () { function HUDMetricTide() { var config = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; _classCallCheck(this, HUDMetricTide); _classPrivateMethodInitSpec(this, _HUDMetricTide_brand); this.metricRequester = config.metricRequester || null; this.deviceIDPrefix = config.deviceIDPrefix || "MT-"; this.flushInterval = config.flushInterval || 10000; this.metricGateway = config.metricGateway || fetch; this.useOffline = config.offlineFirst || false; this.metricLinkConfigurations = config.metricLinkConfigurations || {}; this.metricLinkOptions = this.metricLinkConfigurations.options || {}; this.metricLinkPairPath = this.metricLinkPairPath || "/metric-device/pair"; this.metricLink = null; this.usingMetricLink = !!this.metricLinkConfigurations.enabled; this.connectionURL = config.connectionURL || ""; this.baseURL = config.baseURL || ""; this.metricStatusChecker = new ConnectPulse(_objectSpread({ url: "".concat(this.connectionURL), pulseInterval: 3000, pulseTimeout: 15000, notifyEveryPulse: false, debugMode: false }, config.metricStatusCheckerOptions || {})); this.deviceMetricID = null; var metricCacheConfigurations = config.metricCacheConfigurations || {}; this.metricCacheName = metricCacheConfigurations.name || "MetricCache"; this.metricCacheVersion = metricCacheConfigurations.version || 1; this.storeNames = metricCacheConfigurations.stores || ["buffer", "identity"]; this.bufferStore = metricCacheConfigurations.bufferStore || "buffer"; this.metricCache = null; this.activateOnlineListener(); this.init(); } return _createClass(HUDMetricTide, [{ key: "init", value: function () { var _init = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee() { return _regeneratorRuntime.wrap(function _callee$(_context) { while (1) switch (_context.prev = _context.next) { case 0: _context.next = 2; return _assertClassBrand(_HUDMetricTide_brand, this, _initMetricCache).call(this); case 2: _context.next = 4; return _assertClassBrand(_HUDMetricTide_brand, this, _initDeviceMetricID).call(this); case 4: if (!this.usingMetricLink) { _context.next = 7; break; } _context.next = 7; return _assertClassBrand(_HUDMetricTide_brand, this, _initMetricLink).call(this); case 7: if (!this.useOffline) { _context.next = 11; break; } _context.next = 10; return this.sync(); case 10: this.activateSyncInterval(); case 11: case "end": return _context.stop(); } }, _callee, this); })); function init() { return _init.apply(this, arguments); } return init; }() }, { key: "pair", value: function () { var _pair = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee2() { return _regeneratorRuntime.wrap(function _callee2$(_context2) { while (1) switch (_context2.prev = _context2.next) { case 0: if (this.metricLink) { _context2.next = 2; break; } return _context2.abrupt("return", false); case 2: _context2.next = 4; return this.metricLink.pair(this.metricLinkPairPath); case 4: return _context2.abrupt("return", _context2.sent); case 5: case "end": return _context2.stop(); } }, _callee2, this); })); function pair() { return _pair.apply(this, arguments); } return pair; }() }, { key: "sync", value: function () { var _sync = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee3() { var unsent, _iterator, _step, entry, result; return _regeneratorRuntime.wrap(function _callee3$(_context3) { while (1) switch (_context3.prev = _context3.next) { case 0: if (navigator.onLine) { _context3.next = 2; break; } return _context3.abrupt("return"); case 2: _context3.next = 4; return _assertClassBrand(_HUDMetricTide_brand, this, _loadAllFromStore).call(this, this.bufferStore); case 4: unsent = _context3.sent; if (unsent.length) { _context3.next = 7; break; } return _context3.abrupt("return"); case 7: _iterator = _createForOfIteratorHelper(unsent); _context3.prev = 8; _iterator.s(); case 10: if ((_step = _iterator.n()).done) { _context3.next = 26; break; } entry = _step.value; _context3.prev = 12; _context3.next = 15; return _assertClassBrand(_HUDMetricTide_brand, this, _post).call(this, "/track/".concat(encodeURIComponent(entry.metricDomain)), entry.payload); case 15: result = _context3.sent; if (!(result.success !== false)) { _context3.next = 19; break; } _context3.next = 19; return _assertClassBrand(_HUDMetricTide_brand, this, _removeFromStore).call(this, this.bufferStore, entry.payload.timestamp); case 19: _context3.next = 24; break; case 21: _context3.prev = 21; _context3.t0 = _context3["catch"](12); console.log("[MetricTide ~ Client] Did not sync metrics ~", _context3.t0.message); case 24: _context3.next = 10; break; case 26: _context3.next = 31; break; case 28: _context3.prev = 28; _context3.t1 = _context3["catch"](8); _iterator.e(_context3.t1); case 31: _context3.prev = 31; _iterator.f(); return _context3.finish(31); case 34: case "end": return _context3.stop(); } }, _callee3, this, [[8, 28, 31, 34], [12, 21]]); })); function sync() { return _sync.apply(this, arguments); } return sync; }() }, { key: "activateOnlineListener", value: function activateOnlineListener() { var _this = this; if (typeof window !== "undefined") { window.addEventListener("online", /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee4() { var online; return _regeneratorRuntime.wrap(function _callee4$(_context4) { while (1) switch (_context4.prev = _context4.next) { case 0: _context4.next = 2; return _assertClassBrand(_HUDMetricTide_brand, _this, _checkServerOnline).call(_this); case 2: online = _context4.sent; if (online) { _this.sync(); } case 4: case "end": return _context4.stop(); } }, _callee4); }))); } } }, { key: "activateSyncInterval", value: function activateSyncInterval() { var _this2 = this; this.destroySyncInterval(); this.flushTimer = setInterval(function () { return _this2.sync(); }, this.flushInterval); } }, { key: "destroyOnlineListener", value: function destroyOnlineListener() { if (typeof window !== "undefined") { window.removeEventListener("online", this.sync); } } }, { key: "destroySyncInterval", value: function destroySyncInterval() { if (this.flushTimer) { clearInterval(this.flushTimer); } } }, { key: "destroy", value: function destroy() { this.destroySyncInterval(); this.destroyOnlineListener(); } }, { key: "getDeviceID", value: function getDeviceID() { return this.deviceMetricID; } }, { key: "track", value: function () { var _track = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee5(metricDomain) { var metric, metricRequestOptions, _metric$value, value, _metric$metadata, metadata, _metric$tags, tags, payload, _args5 = arguments; return _regeneratorRuntime.wrap(function _callee5$(_context5) { while (1) switch (_context5.prev = _context5.next) { case 0: metric = _args5.length > 1 && _args5[1] !== undefined ? _args5[1] : {}; metricRequestOptions = _args5.length > 2 && _args5[2] !== undefined ? _args5[2] : {}; _metric$value = metric.value, value = _metric$value === void 0 ? 1 : _metric$value, _metric$metadata = metric.metadata, metadata = _metric$metadata === void 0 ? {} : _metric$metadata, _metric$tags = metric.tags, tags = _metric$tags === void 0 ? [] : _metric$tags; payload = { value: value, timestamp: Date.now(), metadata: _objectSpread(_objectSpread({}, metadata), {}, { deviceMetricID: this.deviceMetricID }), tags: tags }; if (!navigator.onLine) { _context5.next = 20; break; } _context5.prev = 5; _context5.next = 8; return _assertClassBrand(_HUDMetricTide_brand, this, _post).call(this, "/track/".concat(encodeURIComponent(metricDomain)), payload, metricRequestOptions); case 8: return _context5.abrupt("return", _context5.sent); case 11: _context5.prev = 11; _context5.t0 = _context5["catch"](5); if (!this.useOffline) { _context5.next = 17; break; } _context5.next = 16; return _assertClassBrand(_HUDMetricTide_brand, this, _saveToStore).call(this, this.bufferStore, { metricDomain: metricDomain, payload: payload }); case 16: return _context5.abrupt("return", { success: true, status: "saved_offline", metric: payload }); case 17: return _context5.abrupt("return", { success: false, status: "undelivered_metric", metric: payload }); case 18: _context5.next = 24; break; case 20: if (!this.useOffline) { _context5.next = 24; break; } _context5.next = 23; return _assertClassBrand(_HUDMetricTide_brand, this, _saveToStore).call(this, this.bufferStore, { metricDomain: metricDomain, payload: payload }); case 23: return _context5.abrupt("return", { success: true, status: "saved_offline", metric: payload }); case 24: case "end": return _context5.stop(); } }, _callee5, this, [[5, 11]]); })); function track(_x) { return _track.apply(this, arguments); } return track; }() }, { key: "getMetricsSince", value: function () { var _getMetricsSince = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee6() { var interval, source, filter, metricRequestOptions, _args6 = arguments; return _regeneratorRuntime.wrap(function _callee6$(_context6) { while (1) switch (_context6.prev = _context6.next) { case 0: interval = _args6.length > 0 && _args6[0] !== undefined ? _args6[0] : "1d"; source = _args6.length > 1 && _args6[1] !== undefined ? _args6[1] : "storage"; filter = _args6.length > 2 && _args6[2] !== undefined ? _args6[2] : {}; metricRequestOptions = _args6.length > 3 && _args6[3] !== undefined ? _args6[3] : {}; _context6.next = 6; return _assertClassBrand(_HUDMetricTide_brand, this, _post).call(this, "/metrics/since", { interval: interval, source: source, filter: filter }, metricRequestOptions); case 6: return _context6.abrupt("return", _context6.sent); case 7: case "end": return _context6.stop(); } }, _callee6, this); })); function getMetricsSince() { return _getMetricsSince.apply(this, arguments); } return getMetricsSince; }() }, { key: "getMetricsBetween", value: function () { var _getMetricsBetween = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee7(start, end) { var source, filter, metricRequestOptions, _args7 = arguments; return _regeneratorRuntime.wrap(function _callee7$(_context7) { while (1) switch (_context7.prev = _context7.next) { case 0: source = _args7.length > 2 && _args7[2] !== undefined ? _args7[2] : "storage"; filter = _args7.length > 3 && _args7[3] !== undefined ? _args7[3] : {}; metricRequestOptions = _args7.length > 4 && _args7[4] !== undefined ? _args7[4] : {}; _context7.next = 5; return _assertClassBrand(_HUDMetricTide_brand, this, _post).call(this, "/metrics/between", { start: start, end: end, source: source, filter: filter }, metricRequestOptions); case 5: return _context7.abrupt("return", _context7.sent); case 6: case "end": return _context7.stop(); } }, _callee7, this); })); function getMetricsBetween(_x2, _x3) { return _getMetricsBetween.apply(this, arguments); } return getMetricsBetween; }() }, { key: "getStoredMetrics", value: function () { var _getStoredMetrics = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee8() { var filter, metricRequestOptions, _args8 = arguments; return _regeneratorRuntime.wrap(function _callee8$(_context8) { while (1) switch (_context8.prev = _context8.next) { case 0: filter = _args8.length > 0 && _args8[0] !== undefined ? _args8[0] : {}; metricRequestOptions = _args8.length > 1 && _args8[1] !== undefined ? _args8[1] : {}; _context8.next = 4; return _assertClassBrand(_HUDMetricTide_brand, this, _post).call(this, "/metrics/stored", { filter: filter }, metricRequestOptions); case 4: return _context8.abrupt("return", _context8.sent); case 5: case "end": return _context8.stop(); } }, _callee8, this); })); function getStoredMetrics() { return _getStoredMetrics.apply(this, arguments); } return getStoredMetrics; }() }, { key: "getMetrics", value: function () { var _getMetrics = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee9() { var filter, metricRequestOptions, _args9 = arguments; return _regeneratorRuntime.wrap(function _callee9$(_context9) { while (1) switch (_context9.prev = _context9.next) { case 0: filter = _args9.length > 0 && _args9[0] !== undefined ? _args9[0] : {}; metricRequestOptions = _args9.length > 1 && _args9[1] !== undefined ? _args9[1] : {}; _context9.next = 4; return _assertClassBrand(_HUDMetricTide_brand, this, _post).call(this, "/metrics", { filter: filter }, metricRequestOptions); case 4: return _context9.abrupt("return", _context9.sent); case 5: case "end": return _context9.stop(); } }, _callee9, this); })); function getMetrics() { return _getMetrics.apply(this, arguments); } return getMetrics; }() }, { key: "getMetricsFromDomains", value: function () { var _getMetricsFromDomains = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee10() { var domains, options, metricRequestOptions, _args10 = arguments; return _regeneratorRuntime.wrap(function _callee10$(_context10) { while (1) switch (_context10.prev = _context10.next) { case 0: domains = _args10.length > 0 && _args10[0] !== undefined ? _args10[0] : []; options = _args10.length > 1 && _args10[1] !== undefined ? _args10[1] : {}; metricRequestOptions = _args10.length > 2 && _args10[2] !== undefined ? _args10[2] : {}; _context10.next = 5; return _assertClassBrand(_HUDMetricTide_brand, this, _post).call(this, "/metrics/from-domains", { domains: domains, options: options }, metricRequestOptions); case 5: return _context10.abrupt("return", _context10.sent); case 6: case "end": return _context10.stop(); } }, _callee10, this); })); function getMetricsFromDomains() { return _getMetricsFromDomains.apply(this, arguments); } return getMetricsFromDomains; }() }, { key: "getMetricsInDomain", value: function () { var _getMetricsInDomain = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee11(domain) { var options, metricRequestOptions, _args11 = arguments; return _regeneratorRuntime.wrap(function _callee11$(_context11) { while (1) switch (_context11.prev = _context11.next) { case 0: options = _args11.length > 1 && _args11[1] !== undefined ? _args11[1] : {}; metricRequestOptions = _args11.length > 2 && _args11[2] !== undefined ? _args11[2] : {}; _context11.next = 4; return _assertClassBrand(_HUDMetricTide_brand, this, _post).call(this, "/metrics/in-domain", { domain: domain, options: options }, metricRequestOptions); case 4: return _context11.abrupt("return", _context11.sent); case 5: case "end": return _context11.stop(); } }, _callee11, this); })); function getMetricsInDomain(_x4) { return _getMetricsInDomain.apply(this, arguments); } return getMetricsInDomain; }() }, { key: "getMetricByID", value: function () { var _getMetricByID = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee12(id) { var metricRequestOptions, _args12 = arguments; return _regeneratorRuntime.wrap(function _callee12$(_context12) { while (1) switch (_context12.prev = _context12.next) { case 0: metricRequestOptions = _args12.length > 1 && _args12[1] !== undefined ? _args12[1] : {}; _context12.next = 3; return _assertClassBrand(_HUDMetricTide_brand, this, _get).call(this, "/metrics/".concat(encodeURIComponent(id)), metricRequestOptions); case 3: return _context12.abrupt("return", _context12.sent); case 4: case "end": return _context12.stop(); } }, _callee12, this); })); function getMetricByID(_x5) { return _getMetricByID.apply(this, arguments); } return getMetricByID; }() }, { key: "updateMetric", value: function () { var _updateMetric = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee13(id, updates) { var metricRequestOptions, _args13 = arguments; return _regeneratorRuntime.wrap(function _callee13$(_context13) { while (1) switch (_context13.prev = _context13.next) { case 0: metricRequestOptions = _args13.length > 2 && _args13[2] !== undefined ? _args13[2] : {}; _context13.next = 3; return _assertClassBrand(_HUDMetricTide_brand, this, _post).call(this, "/metrics/update", { id: id, updates: updates }, metricRequestOptions); case 3: return _context13.abrupt("return", _context13.sent); case 4: case "end": return _context13.stop(); } }, _callee13, this); })); function updateMetric(_x6, _x7) { return _updateMetric.apply(this, arguments); } return updateMetric; }() }, { key: "searchByTagValue", value: function () { var _searchByTagValue = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee14(key, match) { var metricRequestOptions, _args14 = arguments; return _regeneratorRuntime.wrap(function _callee14$(_context14) { while (1) switch (_context14.prev = _context14.next) { case 0: metricRequestOptions = _args14.length > 2 && _args14[2] !== undefined ? _args14[2] : {}; _context14.next = 3; return _assertClassBrand(_HUDMetricTide_brand, this, _post).call(this, "/metrics/search-tag", { key: key, match: match }, metricRequestOptions); case 3: return _context14.abrupt("return", _context14.sent); case 4: case "end": return _context14.stop(); } }, _callee14, this); })); function searchByTagValue(_x8, _x9) { return _searchByTagValue.apply(this, arguments); } return searchByTagValue; }() }, { key: "getAggregate", value: function () { var _getAggregate = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee15(name) { var metricRequestOptions, _args15 = arguments; return _regeneratorRuntime.wrap(function _callee15$(_context15) { while (1) switch (_context15.prev = _context15.next) { case 0: metricRequestOptions = _args15.length > 1 && _args15[1] !== undefined ? _args15[1] : {}; _context15.next = 3; return _assertClassBrand(_HUDMetricTide_brand, this, _get).call(this, "/aggregate/name/".concat(encodeURIComponent(name)), metricRequestOptions); case 3: return _context15.abrupt("return", _context15.sent); case 4: case "end": return _context15.stop(); } }, _callee15, this); })); function getAggregate(_x10) { return _getAggregate.apply(this, arguments); } return getAggregate; }() }, { key: "getAggregateByType", value: function () { var _getAggregateByType = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee16(type) { var metricRequestOptions, _args16 = arguments; return _regeneratorRuntime.wrap(function _callee16$(_context16) { while (1) switch (_context16.prev = _context16.next) { case 0: metricRequestOptions = _args16.length > 1 && _args16[1] !== undefined ? _args16[1] : {}; _context16.next = 3; return _assertClassBrand(_HUDMetricTide_brand, this, _get).call(this, "/aggregate/type/".concat(encodeURIComponent(type)), metricRequestOptions); case 3: return _context16.abrupt("return", _context16.sent); case 4: case "end": return _context16.stop(); } }, _callee16, this); })); function getAggregateByType(_x11) { return _getAggregateByType.apply(this, arguments); } return getAggregateByType; }() }, { key: "groupByTag", value: function () { var _groupByTag = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee17(tagKey) { var metricRequestOptions, _args17 = arguments; return _regeneratorRuntime.wrap(function _callee17$(_context17) { while (1) switch (_context17.prev = _context17.next) { case 0: metricRequestOptions = _args17.length > 1 && _args17[1] !== undefined ? _args17[1] : {}; _context17.next = 3; return _assertClassBrand(_HUDMetricTide_brand, this, _get).call(this, "/aggregate/group-by-tag/".concat(encodeURIComponent(tagKey)), metricRequestOptions); case 3: return _context17.abrupt("return", _context17.sent); case 4: case "end": return _context17.stop(); } }, _callee17, this); })); function groupByTag(_x12) { return _groupByTag.apply(this, arguments); } return groupByTag; }() }, { key: "getTimeSeries", value: function () { var _getTimeSeries = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee18(name) { var options, metricRequestOptions, _args18 = arguments; return _regeneratorRuntime.wrap(function _callee18$(_context18) { while (1) switch (_context18.prev = _context18.next) { case 0: options = _args18.length > 1 && _args18[1] !== undefined ? _args18[1] : {}; metricRequestOptions = _args18.length > 2 && _args18[2] !== undefined ? _args18[2] : {}; _context18.next = 4; return _assertClassBrand(_HUDMetricTide_brand, this, _post).call(this, "/aggregate/time-series", _objectSpread({ name: name }, options), metricRequestOptions); case 4: return _context18.abrupt("return", _context18.sent); case 5: case "end": return _context18.stop(); } }, _callee18, this); })); function getTimeSeries(_x13) { return _getTimeSeries.apply(this, arguments); } return getTimeSeries; }() }, { key: "predictMetric", value: function () { var _predictMetric = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee19(name) { var config, metricRequestOptions, _args19 = arguments; return _regeneratorRuntime.wrap(function _callee19$(_context19) { while (1) switch (_context19.prev = _context19.next) { case 0: config = _args19.length > 1 && _args19[1] !== undefined ? _args19[1] : {}; metricRequestOptions = _args19.length > 2 && _args19[2] !== undefined ? _args19[2] : {}; _context19.next = 4; return _assertClassBrand(_HUDMetricTide_brand, this, _post).call(this, "/aggregate/predict", { name: name, config: config }, metricRequestOptions); case 4: return _context19.abrupt("return", _context19.sent); case 5: case "end": return _context19.stop(); } }, _callee19, this); })); function predictMetric(_x14) { return _predictMetric.apply(this, arguments); } return predictMetric; }() }, { key: "clearMetricsInDomain", value: function () { var _clearMetricsInDomain = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee20(domain) { var options, metricRequestOptions, _args20 = arguments; return _regeneratorRuntime.wrap(function _callee20$(_context20) { while (1) switch (_context20.prev = _context20.next) { case 0: options = _args20.length > 1 && _args20[1] !== undefined ? _args20[1] : {}; metricRequestOptions = _args20.length > 2 && _args20[2] !== undefined ? _args20[2] : {}; _context20.next = 4; return _assertClassBrand(_HUDMetricTide_brand, this, _post).call(this, "/metrics/clear-domain", { domain: domain, options: options }, metricRequestOptions); case 4: return _context20.abrupt("return", _context20.sent); case 5: case "end": return _context20.stop(); } }, _callee20, this); })); function clearMetricsInDomain(_x15) { return _clearMetricsInDomain.apply(this, arguments); } return clearMetricsInDomain; }() }, { key: "clearAllMetrics", value: function () { var _clearAllMetrics = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee21() { var metricRequestOptions, _args21 = arguments; return _regeneratorRuntime.wrap(function _callee21$(_context21) { while (1) switch (_context21.prev = _context21.next) { case 0: metricRequestOptions = _args21.length > 0 && _args21[0] !== undefined ? _args21[0] : {}; _context21.next = 3; return _assertClassBrand(_HUDMetricTide_brand, this, _post).call(this, "/metrics/clear-all", {}, metricRequestOptions); case 3: return _context21.abrupt("return", _context21.sent); case 4: case "end": return _context21.stop(); } }, _callee21, this); })); function clearAllMetrics() { return _clearAllMetrics.apply(this, arguments); } return clearAllMetrics; }() }]); }(); function _checkServerOnline() { return _checkServerOnline2.apply(this, arguments); } function _checkServerOnline2() { _checkServerOnline2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee22() { return _regeneratorRuntime.wrap(function _callee22$(_context22) { while (1) switch (_context22.prev = _context22.next) { case 0: _context22.prev = 0; _context22.next = 3; return this.metricStatusChecker.pulseCheck(); case 3: return _context22.abrupt("return", _context22.sent); case 6: _context22.prev = 6; _context22.t0 = _context22["catch"](0); return _context22.abrupt("return", false); case 9: case "end": return _context22.stop(); } }, _callee22, this, [[0, 6]]); })); return _checkServerOnline2.apply(this, arguments); } function _initDeviceMetricID() { return _initDeviceMetricID2.apply(this, arguments); } function _initDeviceMetricID2() { _initDeviceMetricID2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee23() { var _crypto$randomUUID, _crypto; var store, idKey, existing, newID; return _regeneratorRuntime.wrap(function _callee23$(_context23) { while (1) switch (_context23.prev = _context23.next) { case 0: store = "identity"; idKey = "deviceMetricID"; _context23.next = 4; return _assertClassBrand(_HUDMetricTide_brand, this, _ensureStore).call(this, store); case 4: _context23.next = 6; return _assertClassBrand(_HUDMetricTide_brand, this, _readFromStore).call(this, store, idKey); case 6: existing = _context23.sent; if (!existing) { _context23.next = 10; break; } this.deviceMetricID = existing.value; return _context23.abrupt("return"); case 10: newID = "".concat(this.deviceIDPrefix).concat(((_crypto$randomUUID = (_crypto = crypto).randomUUID) === null || _crypto$randomUUID === void 0 ? void 0 : _crypto$randomUUID.call(_crypto)) || Math.random().toString(36).slice(2)); _context23.next = 13; return _assertClassBrand(_HUDMetricTide_brand, this, _writeToStore).call(this, store, { id: idKey, value: newID }); case 13: this.deviceMetricID = newID; case 14: case "end": return _context23.stop(); } }, _callee23, this); })); return _initDeviceMetricID2.apply(this, arguments); } function _initMetricLink() { return _initMetricLink2.apply(this, arguments); } function _initMetricLink2() { _initMetricLink2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee24() { return _regeneratorRuntime.wrap(function _callee24$(_context24) { while (1) switch (_context24.prev = _context24.next) { case 0: this.metricLink = new VeriLink(_objectSpread({ serverURL: this.baseURL, deviceID: this.deviceMetricID, persistSessionKey: false, persistSessionID: false, mutator: "metric-t-mutate", vaultSGN: "metric-t-vault", linkSGN: "metric-t-link" }, this.metricLinkOptions)); _context24.prev = 1; _context24.next = 4; return this.metricLink.pair(this.metricLinkPairPath); case 4: _context24.next = 8; break; case 6: _context24.prev = 6; _context24.t0 = _context24["catch"](1); case 8: case "end": return _context24.stop(); } }, _callee24, this, [[1, 6]]); })); return _initMetricLink2.apply(this, arguments); } function _initMetricCache() { return _initMetricCache2.apply(this, arguments); } function _initMetricCache2() { _initMetricCache2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee25() { var _this3 = this; return _regeneratorRuntime.wrap(function _callee25$(_context25) { while (1) switch (_context25.prev = _context25.next) { case 0: return _context25.abrupt("return", new Promise(function (resolve, reject) { var request = indexedDB.open(_this3.metricCacheName, _this3.metricCacheVersion); request.onerror = function () { return reject("Did not open MetricCache."); }; request.onsuccess = function (event) { _this3.metricCache = event.target.result; resolve(); }; request.onupgradeneeded = function (event) { var db = event.target.result; var _iterator2 = _createForOfIteratorHelper(_this3.storeNames), _step2; try { for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) { var storeName = _step2.value; if (!db.objectStoreNames.contains(storeName)) { db.createObjectStore(storeName, { keyPath: "id" }); } } } catch (err) { _iterator2.e(err); } finally { _iterator2.f(); } }; })); case 1: case "end": return _context25.stop(); } }, _callee25); })); return _initMetricCache2.apply(this, arguments); } function _ensureStore(_x16) { return _ensureStore2.apply(this, arguments); } function _ensureStore2() { _ensureStore2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee26(storeName) { var _this4 = this; return _regeneratorRuntime.wrap(function _callee26$(_context26) { while (1) switch (_context26.prev = _context26.next) { case 0: if (this.metricCache.objectStoreNames.contains(storeName)) { _context26.next = 5; break; } this.metricCache.close(); this.metricCacheVersion += 1; _context26.next = 5; return new Promise(function (resolve, reject) { var request = indexedDB.open(_this4.metricCacheName, _this4.metricCacheVersion); request.onupgradeneeded = function (event) { var db = event.target.result; if (!db.objectStoreNames.contains(storeName)) { db.createObjectStore(storeName, { keyPath: "id" }); } }; request.onsuccess = function (event) { _this4.metricCache = event.target.result; resolve(); }; request.onerror = function () { return reject("Did not upgrade MetricCache."); }; }); case 5: case "end": return _context26.stop(); } }, _callee26, this); })); return _ensureStore2.apply(this, arguments); } function _saveToStore(_x17, _x18) { return _saveToStore2.apply(this, arguments); } function _saveToStore2() { _saveToStore2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee27(storeName, object) { var _object$payload, _this5 = this; var id; return _regeneratorRuntime.wrap(function _callee27$(_context27) { while (1) switch (_context27.prev = _context27.next) { case 0: id = ((_object$payload = object.payload) === null || _object$payload === void 0 ? void 0 : _object$payload.timestamp) || Date.now(); return _context27.abrupt("return", new Promise(function (resolve, reject) { var tx = _this5.metricCache.transaction(storeName, "readwrite"); var store = tx.objectStore(storeName); var req = store.put(_objectSpread(_objectSpread({}, object), {}, { id: id })); req.onsuccess = function () { return resolve(); }; req.onerror = function () { return reject("Did not store metric in MetricCache."); }; })); case 2: case "end": return _context27.stop(); } }, _callee27); })); return _saveToStore2.apply(this, arguments); } function _removeFromStore(_x19, _x20) { return _removeFromStore2.apply(this, arguments); } function _removeFromStore2() { _removeFromStore2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee28(storeName, id) { var _this6 = this; return _regeneratorRuntime.wrap(function _callee28$(_context28) { while (1) switch (_context28.prev = _context28.next) { case 0: return _context28.abrupt("return", new Promise(function (resolve, reject) { var tx = _this6.metricCache.transaction(storeName, "readwrite"); var store = tx.objectStore(storeName); var req = store["delete"](id); req.onsuccess = function () { return resolve(); }; req.onerror = function () { return reject("Did not remove metric from MetricCache."); }; })); case 1: case "end": return _context28.stop(); } }, _callee28); })); return _removeFromStore2.apply(this, arguments); } function _loadAllFromStore(_x21) { return _loadAllFromStore2.apply(this, arguments); } function _loadAllFromStore2() { _loadAllFromStore2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee29(storeName) { var _this7 = this; return _regeneratorRuntime.wrap(function _callee29$(_context29) { while (1) switch (_context29.prev = _context29.next) { case 0: return _context29.abrupt("return", new Promise(function (resolve, reject) { var tx = _this7.metricCache.transaction(storeName, "readonly"); var store = tx.objectStore(storeName); var req = store.getAll(); req.onsuccess = function (event) { return resolve(event.target.result || []); }; req.onerror = function () { return reject("Did not read metric from MetricCache."); }; })); case 1: case "end": return _context29.stop(); } }, _callee29); })); return _loadAllFromStore2.apply(this, arguments); } function _readFromStore(_x22, _x23) { return _readFromStore2.apply(this, arguments); } function _readFromStore2() { _readFromStore2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee30(storeName, id) { var _this8 = this; return _regeneratorRuntime.wrap(function _callee30$(_context30) { while (1) switch (_context30.prev = _context30.next) { case 0: return _context30.abrupt("return", new Promise(function (resolve, reject) { var tx = _this8.metricCache.transaction(storeName, "readonly"); var store = tx.objectStore(storeName); var req = store.get(id); req.onsuccess = function (event) { return resolve(event.target.result || null); }; req.onerror = function () { return reject("Did not read metric from MetricCache."); }; })); case 1: case "end": return _context30.stop(); } }, _callee30); })); return _readFromStore2.apply(this, arguments); } function _writeToStore(_x24, _x25) { return _writeToStore2.apply(this, arguments); } function _writeToStore2() { _writeToStore2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee31(storeName, object) { var _this9 = this; return _regeneratorRuntime.wrap(function _callee31$(_context31) { while (1) switch (_context31.prev = _context31.next) { case 0: return _context31.abrupt("return", new Promise(function (resolve, reject) { var tx = _this9.metricCache.transaction(storeName, "readwrite"); var store = tx.objectStore(storeName); var req = store.put(object); req.onsuccess = function () { return resolve(); }; req.onerror = function () { return reject("Did not write metric to MetricCache."); }; })); case 1: case "end": return _context31.stop(); } }, _callee31); })); return _writeToStore2.apply(this, arguments); } function _post(_x26, _x27) { return _post2.apply(this, arguments); } function _post2() { _post2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee32(path, body) { var options, fullPath, _options$headers, headers, optionData, request, _args32 = arguments; return _regeneratorRuntime.wrap(function _callee32$(_context32) { while (1) switch (_context32.prev = _context32.next) { case 0: options = _args32.length > 2 && _args32[2] !== undefined ? _args32[2] : {}; fullPath = this.baseURL + path; if (!this.metricLink) { _context32.next = 7; break; } _options$headers = options.headers, headers = _options$headers === void 0 ? {} : _options$headers, optionData = _objectWithoutProperties(options, _excluded); _context32.next = 6; return this.metricLink.send("POST", path, body, headers, _objectSpread({ fullResponse: true }, optionData !== null && optionData !== void 0 ? optionData : {})); case 6: return _context32.abrupt("return", _context32.sent); case 7: request = _objectSpread({ method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(body) }, options !== null && options !== void 0 ? options : {}); _context32.next = 10; return _assertClassBrand(_HUDMetricTide_brand, this, _executeFetch).call(this, fullPath, request); case 10: return _context32.abrupt("return", _context32.sent); case 11: case "end": return _context32.stop(); } }, _callee32, this); })); return _post2.apply(this, arguments); } function _get(_x28) { return _get2.apply(this, arguments); } function _get2() { _get2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee33(path) { var options, fullPath, _options$headers2, headers, optionData, request, _args33 = arguments; return _regeneratorRuntime.wrap(function _callee33$(_context33) { while (1) switch (_context33.prev = _context33.next) { case 0: options = _args33.length > 1 && _args33[1] !== undefined ? _args33[1] : {}; fullPath = this.baseURL + path; if (!this.metricLink) { _context33.next = 7; break; } _options$headers2 = options.headers, headers = _options$headers2 === void 0 ? {} : _options$headers2, optionData = _objectWithoutProperties(options, _excluded2); _context33.next = 6; return this.metricLink.send("GET", path, {}, headers, _objectSpread({ fullResponse: true }, optionData !== null && optionData !== void 0 ? optionData : {})); case 6: return _context33.abrupt("return", _context33.sent); case 7: request = _objectSpread({ method: "GET", headers: { "Content-Type": "application/json" } }, options !== null && options !== void 0 ? options : {}); _context33.next = 10; return _assertClassBrand(_HUDMetricTide_brand, this, _executeFetch).call(this, fullPath, request); case 10: return _context33.abr