medusa-telemetry
Advanced tools
Comparing version 0.0.16 to 0.0.17-snapshot-20230821094003
"use strict"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
Object.defineProperty(exports, "__esModule", { | ||
@@ -17,15 +16,10 @@ value: true | ||
exports.trackInstallation = trackInstallation; | ||
var _telemeter = _interopRequireDefault(require("./telemeter")); | ||
var _createFlush = _interopRequireDefault(require("./util/create-flush")); | ||
var telemeter = new _telemeter["default"](); | ||
var flush = (0, _createFlush["default"])(telemeter.isTrackingEnabled()); | ||
exports.flush = flush; | ||
if (flush) { | ||
process.on("exit", flush); | ||
} | ||
var track = function track(event) { | ||
@@ -35,5 +29,3 @@ var data = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
}; | ||
exports.track = track; | ||
var setTelemetryEnabled = function setTelemetryEnabled() { | ||
@@ -43,9 +35,6 @@ var enabled = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true; | ||
}; | ||
exports.setTelemetryEnabled = setTelemetryEnabled; | ||
function trackFeatureFlag(flag) { | ||
telemeter.trackFeatureFlag(flag); | ||
} | ||
function trackInstallation(installation, type) { | ||
@@ -56,3 +45,2 @@ switch (type) { | ||
break; | ||
case "module": | ||
@@ -59,0 +47,0 @@ telemeter.trackModule(installation); |
"use strict"; | ||
var _require = require("./util/is-ci"), | ||
isCI = _require.isCI; | ||
isCI = _require.isCI; | ||
try { | ||
var showAnalyticsNotification = require("./util/show-notification"); | ||
var Store = require("./store"); | ||
var eventStorage = new Store(); | ||
var disabled = eventStorage.disabled_; | ||
var enabledInConfig = eventStorage.getConfig("telemetry.enabled"); | ||
if (enabledInConfig === undefined && !disabled && !isCI()) { | ||
showAnalyticsNotification(); | ||
} | ||
} catch (e) {// ignore | ||
} catch (e) { | ||
// ignore | ||
} |
"use strict"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
Object.defineProperty(exports, "__esModule", { | ||
@@ -9,25 +8,14 @@ value: true | ||
exports["default"] = void 0; | ||
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator")); | ||
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator")); | ||
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")); | ||
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass")); | ||
var _configstore = _interopRequireDefault(require("configstore")); | ||
var _path = _interopRequireDefault(require("path")); | ||
var _inMemoryConfig = require("./util/in-memory-config"); | ||
var _isTruthy = _interopRequireDefault(require("./util/is-truthy")); | ||
var _outboxStore = _interopRequireDefault(require("./util/outbox-store")); | ||
var Store = /*#__PURE__*/function () { | ||
function Store() { | ||
(0, _classCallCheck2["default"])(this, Store); | ||
try { | ||
@@ -40,9 +28,6 @@ this.config_ = new _configstore["default"]("medusa", {}, { | ||
} | ||
var baseDir = _path["default"].dirname(this.config_.path); | ||
this.outbox_ = new _outboxStore["default"](baseDir); | ||
this.disabled_ = (0, _isTruthy["default"])(process.env.MEDUSA_DISABLE_TELEMETRY); | ||
} | ||
(0, _createClass2["default"])(Store, [{ | ||
@@ -64,3 +49,2 @@ key: "getQueueSize", | ||
} | ||
var eventString = JSON.stringify(event); | ||
@@ -74,52 +58,41 @@ return this.outbox_.appendToBuffer(eventString + "\n"); | ||
return _regenerator["default"].wrap(function _callee2$(_context2) { | ||
while (1) { | ||
switch (_context2.prev = _context2.next) { | ||
case 0: | ||
_context2.next = 2; | ||
return this.outbox_.startFlushEvents( /*#__PURE__*/function () { | ||
var _ref = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee(eventData) { | ||
var events; | ||
return _regenerator["default"].wrap(function _callee$(_context) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
events = eventData.split("\n").filter(function (e) { | ||
return e && e.length > 2; | ||
}).map(function (e) { | ||
return JSON.parse(e); | ||
}); | ||
_context.next = 3; | ||
return handler(events); | ||
case 3: | ||
return _context.abrupt("return", _context.sent); | ||
case 4: | ||
case "end": | ||
return _context.stop(); | ||
} | ||
} | ||
}, _callee); | ||
})); | ||
return function (_x2) { | ||
return _ref.apply(this, arguments); | ||
}; | ||
}()); | ||
case 2: | ||
return _context2.abrupt("return", _context2.sent); | ||
case 3: | ||
case "end": | ||
return _context2.stop(); | ||
} | ||
while (1) switch (_context2.prev = _context2.next) { | ||
case 0: | ||
_context2.next = 2; | ||
return this.outbox_.startFlushEvents( /*#__PURE__*/function () { | ||
var _ref = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee(eventData) { | ||
var events; | ||
return _regenerator["default"].wrap(function _callee$(_context) { | ||
while (1) switch (_context.prev = _context.next) { | ||
case 0: | ||
events = eventData.split("\n").filter(function (e) { | ||
return e && e.length > 2; | ||
}).map(function (e) { | ||
return JSON.parse(e); | ||
}); | ||
_context.next = 3; | ||
return handler(events); | ||
case 3: | ||
return _context.abrupt("return", _context.sent); | ||
case 4: | ||
case "end": | ||
return _context.stop(); | ||
} | ||
}, _callee); | ||
})); | ||
return function (_x2) { | ||
return _ref.apply(this, arguments); | ||
}; | ||
}()); | ||
case 2: | ||
return _context2.abrupt("return", _context2.sent); | ||
case 3: | ||
case "end": | ||
return _context2.stop(); | ||
} | ||
}, _callee2, this); | ||
})); | ||
function flushEvents(_x) { | ||
return _flushEvents.apply(this, arguments); | ||
} | ||
return flushEvents; | ||
@@ -140,4 +113,3 @@ }() | ||
}(); | ||
var _default = Store; | ||
exports["default"] = _default; |
"use strict"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
Object.defineProperty(exports, "__esModule", { | ||
@@ -9,31 +8,17 @@ value: true | ||
exports["default"] = void 0; | ||
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof")); | ||
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")); | ||
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass")); | ||
var _fs = _interopRequireDefault(require("fs")); | ||
var _isDocker = _interopRequireDefault(require("is-docker")); | ||
var _os = _interopRequireDefault(require("os")); | ||
var _path = require("path"); | ||
var _uuid = require("uuid"); | ||
var _store = _interopRequireDefault(require("./store")); | ||
var _createFlush = _interopRequireDefault(require("./util/create-flush")); | ||
var _getTermProgram = _interopRequireDefault(require("./util/get-term-program")); | ||
var _isCi = require("./util/is-ci"); | ||
var _isTruthy = _interopRequireDefault(require("./util/is-truthy")); | ||
var _showNotification = _interopRequireDefault(require("./util/show-notification")); | ||
var MEDUSA_TELEMETRY_VERBOSE = process.env.MEDUSA_TELEMETRY_VERBOSE || false; | ||
var Telemeter = /*#__PURE__*/function () { | ||
@@ -54,3 +39,2 @@ function Telemeter() { | ||
} | ||
(0, _createClass2["default"])(Telemeter, [{ | ||
@@ -62,10 +46,7 @@ key: "getMachineId", | ||
} | ||
var machineId = this.store_.getConfig("telemetry.machine_id"); | ||
if (typeof machineId !== "string") { | ||
if ((0, _typeof2["default"])(machineId) !== "string") { | ||
machineId = (0, _uuid.v4)(); | ||
this.store_.setConfig("telemetry.machine_id", machineId); | ||
} | ||
this.machineId = machineId; | ||
@@ -81,5 +62,3 @@ return machineId; | ||
} | ||
var enabled = this.store_.getConfig("telemetry.enabled"); | ||
if (enabled === undefined || enabled === null) { | ||
@@ -89,7 +68,5 @@ if (!(0, _isCi.isCI)()) { | ||
} | ||
enabled = true; | ||
this.store_.setConfig("telemetry.enabled", enabled); | ||
} | ||
this.trackingEnabled = enabled; | ||
@@ -104,5 +81,3 @@ return enabled; | ||
} | ||
var cpus = _os["default"].cpus(); | ||
var osInfo = { | ||
@@ -127,6 +102,4 @@ node_version: process.version, | ||
var packageJson = require.resolve("@medusajs/medusa/package.json"); | ||
var _JSON$parse = JSON.parse(_fs["default"].readFileSync(packageJson, "utf-8")), | ||
version = _JSON$parse.version; | ||
version = _JSON$parse.version; | ||
return version; | ||
@@ -138,3 +111,2 @@ } catch (e) { | ||
} | ||
return "-0.0.0"; | ||
@@ -149,6 +121,4 @@ } | ||
.join(_path.sep), "package.json"); | ||
var _require = require(jsonfile), | ||
version = _require.version; | ||
version = _require.version; | ||
return version; | ||
@@ -160,3 +130,2 @@ } catch (e) { | ||
} | ||
return "-0.0.0"; | ||
@@ -196,3 +165,2 @@ } | ||
var hasReachedQueueSize = this.queueSize_ >= this.maxQueueSize; | ||
if (hasReachedQueueSize || hasReachedFlushAt) { | ||
@@ -202,6 +170,4 @@ var flush = (0, _createFlush["default"])(this.isTrackingEnabled()); | ||
} | ||
if (this.flushInterval && !this.timer) { | ||
var _flush = (0, _createFlush["default"])(this.isTrackingEnabled()); | ||
if (_flush) { | ||
@@ -236,4 +202,3 @@ this.timer = setTimeout(_flush, this.flushInterval); | ||
}(); | ||
var _default = Telemeter; | ||
exports["default"] = _default; |
"use strict"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
Object.defineProperty(exports, "__esModule", { | ||
@@ -9,15 +8,8 @@ value: true | ||
exports["default"] = void 0; | ||
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator")); | ||
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator")); | ||
var _path = require("path"); | ||
var _child_process = require("child_process"); | ||
var _isTruthy = _interopRequireDefault(require("./is-truthy")); | ||
var MEDUSA_TELEMETRY_VERBOSE = process.env.MEDUSA_TELEMETRY_VERBOSE || false; | ||
function createFlush(enabled) { | ||
@@ -27,3 +19,2 @@ if (!enabled) { | ||
} | ||
return /*#__PURE__*/function () { | ||
@@ -33,33 +24,26 @@ var _flush = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee() { | ||
return _regenerator["default"].wrap(function _callee$(_context) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
if ((0, _isTruthy["default"])(MEDUSA_TELEMETRY_VERBOSE)) { | ||
console.log("Flushing queue..."); | ||
} | ||
forked = (0, _child_process.fork)((0, _path.join)(__dirname, "send.js"), { | ||
detached: true, | ||
stdio: MEDUSA_TELEMETRY_VERBOSE ? "inherit" : "ignore", | ||
execArgv: [] | ||
}); | ||
forked.unref(); | ||
case 3: | ||
case "end": | ||
return _context.stop(); | ||
} | ||
while (1) switch (_context.prev = _context.next) { | ||
case 0: | ||
if ((0, _isTruthy["default"])(MEDUSA_TELEMETRY_VERBOSE)) { | ||
console.log("Flushing queue..."); | ||
} | ||
forked = (0, _child_process.fork)((0, _path.join)(__dirname, "send.js"), { | ||
detached: true, | ||
stdio: MEDUSA_TELEMETRY_VERBOSE ? "inherit" : "ignore", | ||
execArgv: [] | ||
}); | ||
forked.unref(); | ||
case 3: | ||
case "end": | ||
return _context.stop(); | ||
} | ||
}, _callee); | ||
})); | ||
function flush() { | ||
return _flush.apply(this, arguments); | ||
} | ||
return flush; | ||
}(); | ||
} | ||
var _default = createFlush; | ||
exports["default"] = _default; |
@@ -7,8 +7,6 @@ "use strict"; | ||
exports["default"] = void 0; | ||
function getTermProgram() { | ||
var _process$env = process.env, | ||
TERM_PROGRAM = _process$env.TERM_PROGRAM, | ||
WT_SESSION = _process$env.WT_SESSION; | ||
TERM_PROGRAM = _process$env.TERM_PROGRAM, | ||
WT_SESSION = _process$env.WT_SESSION; | ||
if (TERM_PROGRAM) { | ||
@@ -20,7 +18,5 @@ return TERM_PROGRAM; | ||
} | ||
return undefined; | ||
} | ||
var _default = getTermProgram; | ||
exports["default"] = _default; |
"use strict"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
Object.defineProperty(exports, "__esModule", { | ||
@@ -9,15 +8,8 @@ value: true | ||
exports.InMemoryConfigStore = void 0; | ||
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")); | ||
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass")); | ||
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")); | ||
var _uuid = require("uuid"); | ||
var _os = _interopRequireDefault(require("os")); | ||
var _path = require("path"); | ||
var InMemoryConfigStore = /*#__PURE__*/function () { | ||
@@ -30,3 +22,2 @@ function InMemoryConfigStore() { | ||
} | ||
(0, _createClass2["default"])(InMemoryConfigStore, [{ | ||
@@ -78,3 +69,2 @@ key: "createBaseConfig", | ||
}(); | ||
exports.InMemoryConfigStore = InMemoryConfigStore; |
"use strict"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
Object.defineProperty(exports, "__esModule", { | ||
@@ -10,5 +9,4 @@ value: true | ||
exports.isCI = isCI; | ||
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof")); | ||
var _ciInfo = _interopRequireDefault(require("ci-info")); | ||
var CI_DEFINITIONS = [getEnvDetect({ | ||
@@ -42,21 +40,18 @@ key: "NOW_BUILDER_ANNOTATE", | ||
}), envFromCIAndCIName, herokuDetect, getEnvFromCIInfo, envFromCIWithNoName]; | ||
function lookupCI() { | ||
for (var _i = 0, _CI_DEFINITIONS = CI_DEFINITIONS; _i < _CI_DEFINITIONS.length; _i++) { | ||
var fn = _CI_DEFINITIONS[_i]; | ||
try { | ||
var res = fn(); | ||
if (res) { | ||
return res; | ||
} | ||
} catch (e) {// ignore | ||
} catch (e) { | ||
// ignore | ||
} | ||
} | ||
return null; | ||
} | ||
var CIName = lookupCI(); | ||
var CIName = lookupCI(); | ||
/** | ||
@@ -70,2 +65,3 @@ * Determines whether the environment where the code is running is in CI | ||
} | ||
/** | ||
@@ -76,3 +72,2 @@ * Gets the name of the CI environment (e.g. "Vercel", "Heroku", etc.) | ||
function getCIName() { | ||
@@ -82,6 +77,4 @@ if (!isCI()) { | ||
} | ||
return CIName; | ||
} | ||
function getEnvFromCIInfo() { | ||
@@ -91,6 +84,5 @@ if (_ciInfo["default"].isCI) return _ciInfo["default"].name || "ci-info detected w/o name"; | ||
} | ||
function getEnvDetect(_ref) { | ||
var key = _ref.key, | ||
name = _ref.name; | ||
name = _ref.name; | ||
return function () { | ||
@@ -100,11 +92,8 @@ if (process.env[key]) { | ||
} | ||
return null; | ||
}; | ||
} | ||
function herokuDetect() { | ||
return typeof process.env.NODE === "string" && /\.heroku\/node\/bin\/node/.test(process.env.NODE) && "Heroku"; | ||
return (0, _typeof2["default"])(process.env.NODE) === "string" && /\.heroku\/node\/bin\/node/.test(process.env.NODE) && "Heroku"; | ||
} | ||
function envFromCIAndCIName() { | ||
@@ -114,6 +103,4 @@ if (process.env.CI_NAME && process.env.CI) { | ||
} | ||
return null; | ||
} | ||
function envFromCIWithNoName() { | ||
@@ -123,4 +110,3 @@ if (process.env.CI) { | ||
} | ||
return null; | ||
} |
"use strict"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
Object.defineProperty(exports, "__esModule", { | ||
@@ -7,3 +8,3 @@ value: true | ||
exports["default"] = void 0; | ||
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof")); | ||
// Returns true for `true`, true, positive numbers | ||
@@ -13,17 +14,20 @@ // Returns false for `false`, false, 0, negative integers and anything else | ||
// Return if Boolean | ||
if (typeof value === "boolean") return value; // Return false if null or undefined | ||
if ((0, _typeof2["default"])(value) === "boolean") return value; | ||
if (value === undefined || value === null) return false; // If the String is true or false | ||
// Return false if null or undefined | ||
if (value === undefined || value === null) return false; | ||
// If the String is true or false | ||
if (value.toLowerCase() === "true") return true; | ||
if (value.toLowerCase() === "false") return false; // Now check if it's a number | ||
if (value.toLowerCase() === "false") return false; | ||
// Now check if it's a number | ||
var number = parseInt(value, 10); | ||
if (isNaN(number)) return false; | ||
if (number > 0) return true; // Default to false | ||
if (number > 0) return true; | ||
// Default to false | ||
return false; | ||
} | ||
var _default = isTruthy; | ||
exports["default"] = _default; |
"use strict"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
Object.defineProperty(exports, "__esModule", { | ||
@@ -9,25 +8,13 @@ value: true | ||
exports["default"] = void 0; | ||
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator")); | ||
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator")); | ||
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")); | ||
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass")); | ||
var _path = _interopRequireDefault(require("path")); | ||
var _fs = require("fs"); | ||
var _isTruthy = _interopRequireDefault(require("./is-truthy")); | ||
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, 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 normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; } | ||
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } | ||
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; } | ||
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; } | ||
var MEDUSA_TELEMETRY_VERBOSE = process.env.MEDUSA_TELEMETRY_VERBOSE || false; | ||
var Outbox = /*#__PURE__*/function () { | ||
@@ -40,3 +27,2 @@ function Outbox(baseDir) { | ||
} | ||
(0, _createClass2["default"])(Outbox, [{ | ||
@@ -59,3 +45,2 @@ key: "appendToBuffer", | ||
} | ||
try { | ||
@@ -69,3 +54,2 @@ var stats = (0, _fs.statSync)(this.bufferFilePath); | ||
} | ||
return 0; | ||
@@ -79,3 +63,2 @@ } | ||
} | ||
try { | ||
@@ -91,3 +74,2 @@ var fileBuffer = (0, _fs.readFileSync)(this.bufferFilePath); | ||
} | ||
return 0; | ||
@@ -101,70 +83,55 @@ } | ||
return _regenerator["default"].wrap(function _callee$(_context) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
now = "".concat(Date.now(), "-").concat(process.pid); | ||
success = false; | ||
contents = ""; | ||
_context.prev = 3; | ||
if ((0, _fs.existsSync)(filePath)) { | ||
_context.next = 6; | ||
break; | ||
} | ||
return _context.abrupt("return", true); | ||
case 6: | ||
// Unique temporary file name across multiple concurrent Medusa instances | ||
newPath = "".concat(this.bufferFilePath, "-").concat(now); | ||
(0, _fs.renameSync)(filePath, newPath); | ||
contents = (0, _fs.readFileSync)(newPath, "utf8"); | ||
(0, _fs.unlinkSync)(newPath); // There is still a chance process dies while sending data and some events are lost | ||
// This will be ok for now, however | ||
_context.next = 12; | ||
return flushOperation(contents); | ||
case 12: | ||
success = _context.sent; | ||
_context.next = 18; | ||
while (1) switch (_context.prev = _context.next) { | ||
case 0: | ||
now = "".concat(Date.now(), "-").concat(process.pid); | ||
success = false; | ||
contents = ""; | ||
_context.prev = 3; | ||
if ((0, _fs.existsSync)(filePath)) { | ||
_context.next = 6; | ||
break; | ||
} | ||
return _context.abrupt("return", true); | ||
case 6: | ||
// Unique temporary file name across multiple concurrent Medusa instances | ||
newPath = "".concat(this.bufferFilePath, "-").concat(now); | ||
(0, _fs.renameSync)(filePath, newPath); | ||
contents = (0, _fs.readFileSync)(newPath, "utf8"); | ||
(0, _fs.unlinkSync)(newPath); | ||
case 15: | ||
_context.prev = 15; | ||
_context.t0 = _context["catch"](3); | ||
// There is still a chance process dies while sending data and some events are lost | ||
// This will be ok for now, however | ||
_context.next = 12; | ||
return flushOperation(contents); | ||
case 12: | ||
success = _context.sent; | ||
_context.next = 18; | ||
break; | ||
case 15: | ||
_context.prev = 15; | ||
_context.t0 = _context["catch"](3); | ||
if ((0, _isTruthy["default"])(MEDUSA_TELEMETRY_VERBOSE)) { | ||
console.error("Failed to perform file flush", _context.t0); | ||
} | ||
case 18: | ||
_context.prev = 18; | ||
// if sending fails, we write the data back to the log | ||
if (!success) { | ||
if ((0, _isTruthy["default"])(MEDUSA_TELEMETRY_VERBOSE)) { | ||
console.error("Failed to perform file flush", _context.t0); | ||
console.error("File flush did not succeed - writing back to file", success); | ||
} | ||
case 18: | ||
_context.prev = 18; | ||
// if sending fails, we write the data back to the log | ||
if (!success) { | ||
if ((0, _isTruthy["default"])(MEDUSA_TELEMETRY_VERBOSE)) { | ||
console.error("File flush did not succeed - writing back to file", success); | ||
} | ||
this.appendToBuffer(contents); | ||
} | ||
return _context.finish(18); | ||
case 21: | ||
return _context.abrupt("return", true); | ||
case 22: | ||
case "end": | ||
return _context.stop(); | ||
} | ||
this.appendToBuffer(contents); | ||
} | ||
return _context.finish(18); | ||
case 21: | ||
return _context.abrupt("return", true); | ||
case 22: | ||
case "end": | ||
return _context.stop(); | ||
} | ||
}, _callee, this, [[3, 15, 18, 21]]); | ||
})); | ||
function flushFile(_x, _x2) { | ||
return _flushFile.apply(this, arguments); | ||
} | ||
return flushFile; | ||
@@ -177,78 +144,57 @@ }() | ||
var files, filtered, _iterator, _step, file; | ||
return _regenerator["default"].wrap(function _callee2$(_context2) { | ||
while (1) { | ||
switch (_context2.prev = _context2.next) { | ||
case 0: | ||
_context2.prev = 0; | ||
_context2.next = 3; | ||
return this.flushFile(this.bufferFilePath, flushOperation); | ||
case 3: | ||
files = (0, _fs.readdirSync)(this.baseDir); | ||
filtered = files.filter(function (p) { | ||
return p.startsWith("events.json"); | ||
}); | ||
_iterator = _createForOfIteratorHelper(filtered); | ||
_context2.prev = 6; | ||
_iterator.s(); | ||
case 8: | ||
if ((_step = _iterator.n()).done) { | ||
_context2.next = 14; | ||
break; | ||
} | ||
file = _step.value; | ||
_context2.next = 12; | ||
return this.flushFile(_path["default"].join(this.baseDir, file), flushOperation); | ||
case 12: | ||
_context2.next = 8; | ||
while (1) switch (_context2.prev = _context2.next) { | ||
case 0: | ||
_context2.prev = 0; | ||
_context2.next = 3; | ||
return this.flushFile(this.bufferFilePath, flushOperation); | ||
case 3: | ||
files = (0, _fs.readdirSync)(this.baseDir); | ||
filtered = files.filter(function (p) { | ||
return p.startsWith("events.json"); | ||
}); | ||
_iterator = _createForOfIteratorHelper(filtered); | ||
_context2.prev = 6; | ||
_iterator.s(); | ||
case 8: | ||
if ((_step = _iterator.n()).done) { | ||
_context2.next = 14; | ||
break; | ||
case 14: | ||
_context2.next = 19; | ||
break; | ||
case 16: | ||
_context2.prev = 16; | ||
_context2.t0 = _context2["catch"](6); | ||
_iterator.e(_context2.t0); | ||
case 19: | ||
_context2.prev = 19; | ||
_iterator.f(); | ||
return _context2.finish(19); | ||
case 22: | ||
return _context2.abrupt("return", true); | ||
case 25: | ||
_context2.prev = 25; | ||
_context2.t1 = _context2["catch"](0); | ||
if ((0, _isTruthy["default"])(MEDUSA_TELEMETRY_VERBOSE)) { | ||
console.error("Failed to perform flush", _context2.t1); | ||
} | ||
case 28: | ||
return _context2.abrupt("return", false); | ||
case 29: | ||
case "end": | ||
return _context2.stop(); | ||
} | ||
} | ||
file = _step.value; | ||
_context2.next = 12; | ||
return this.flushFile(_path["default"].join(this.baseDir, file), flushOperation); | ||
case 12: | ||
_context2.next = 8; | ||
break; | ||
case 14: | ||
_context2.next = 19; | ||
break; | ||
case 16: | ||
_context2.prev = 16; | ||
_context2.t0 = _context2["catch"](6); | ||
_iterator.e(_context2.t0); | ||
case 19: | ||
_context2.prev = 19; | ||
_iterator.f(); | ||
return _context2.finish(19); | ||
case 22: | ||
return _context2.abrupt("return", true); | ||
case 25: | ||
_context2.prev = 25; | ||
_context2.t1 = _context2["catch"](0); | ||
if ((0, _isTruthy["default"])(MEDUSA_TELEMETRY_VERBOSE)) { | ||
console.error("Failed to perform flush", _context2.t1); | ||
} | ||
case 28: | ||
return _context2.abrupt("return", false); | ||
case 29: | ||
case "end": | ||
return _context2.stop(); | ||
} | ||
}, _callee2, this, [[0, 25], [6, 16, 19, 22]]); | ||
})); | ||
function startFlushEvents(_x3) { | ||
return _startFlushEvents.apply(this, arguments); | ||
} | ||
return startFlushEvents; | ||
@@ -259,4 +205,3 @@ }() | ||
}(); | ||
var _default = Outbox; | ||
exports["default"] = _default; |
"use strict"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
var _telemetryDispatcher = _interopRequireDefault(require("./telemetry-dispatcher")); | ||
var MEDUSA_TELEMETRY_HOST = process.env.MEDUSA_TELEMETRY_HOST || ""; | ||
@@ -8,0 +6,0 @@ var MEDUSA_TELEMETRY_PATH = process.env.MEDUSA_TELEMETRY_PATH || ""; |
"use strict"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
Object.defineProperty(exports, "__esModule", { | ||
@@ -9,5 +8,3 @@ value: true | ||
exports["default"] = void 0; | ||
var _boxen = _interopRequireDefault(require("boxen")); | ||
var defaultConfig = { | ||
@@ -19,6 +16,6 @@ padding: 1, | ||
var defaultMessage = "Medusa collects anonymous usage analytics\n" + "to help improve Medusa for all users.\n" + "\n" + "If you'd like to opt-out, you can use `medusa telemetry --disable`\n"; | ||
/** | ||
* Analytics notice for the end-user | ||
*/ | ||
function showAnalyticsNotification() { | ||
@@ -29,4 +26,3 @@ var config = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : defaultConfig; | ||
} | ||
var _default = showAnalyticsNotification; | ||
exports["default"] = _default; |
"use strict"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
Object.defineProperty(exports, "__esModule", { | ||
@@ -9,25 +8,13 @@ value: true | ||
exports["default"] = void 0; | ||
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator")); | ||
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator")); | ||
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")); | ||
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass")); | ||
var _removeTrailingSlash = _interopRequireDefault(require("remove-trailing-slash")); | ||
var _axios = _interopRequireDefault(require("axios")); | ||
var _axiosRetry = _interopRequireDefault(require("axios-retry")); | ||
var _showNotification = _interopRequireDefault(require("./show-notification")); | ||
var _store = _interopRequireDefault(require("../store")); | ||
var _isTruthy = _interopRequireDefault(require("./is-truthy")); | ||
var MEDUSA_TELEMETRY_VERBOSE = process.env.MEDUSA_TELEMETRY_VERBOSE || false; | ||
var TelemetryDispatcher = /*#__PURE__*/function () { | ||
@@ -40,7 +27,5 @@ function TelemetryDispatcher(options) { | ||
var axiosInstance = options.axiosInstance; | ||
if (!axiosInstance) { | ||
axiosInstance = _axios["default"].create(); | ||
} | ||
this.axiosInstance = axiosInstance; | ||
@@ -55,3 +40,2 @@ this.timeout = options.timeout || false; | ||
} | ||
(0, _createClass2["default"])(TelemetryDispatcher, [{ | ||
@@ -64,5 +48,3 @@ key: "isTrackingEnabled", | ||
} | ||
var enabled = this.store_.getConfig("telemetry.enabled"); | ||
if (enabled === undefined || enabled === null) { | ||
@@ -73,3 +55,2 @@ (0, _showNotification["default"])(); | ||
} | ||
this.trackingEnabled = enabled; | ||
@@ -83,85 +64,67 @@ return enabled; | ||
var _this = this; | ||
return _regenerator["default"].wrap(function _callee2$(_context2) { | ||
while (1) { | ||
switch (_context2.prev = _context2.next) { | ||
case 0: | ||
if (this.isTrackingEnabled()) { | ||
_context2.next = 2; | ||
break; | ||
} | ||
return _context2.abrupt("return"); | ||
case 2: | ||
_context2.next = 4; | ||
return this.store_.flushEvents( /*#__PURE__*/function () { | ||
var _ref = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee(events) { | ||
var data, req; | ||
return _regenerator["default"].wrap(function _callee$(_context) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
if (events.length) { | ||
_context.next = 3; | ||
break; | ||
} | ||
if ((0, _isTruthy["default"])(MEDUSA_TELEMETRY_VERBOSE)) { | ||
console.log("No events to POST - skipping"); | ||
} | ||
return _context.abrupt("return", true); | ||
case 3: | ||
data = { | ||
batch: events, | ||
timestamp: new Date() | ||
}; | ||
req = { | ||
headers: {} | ||
}; | ||
_context.next = 7; | ||
return _this.axiosInstance.post("".concat(_this.host).concat(_this.path), data, req).then(function () { | ||
if ((0, _isTruthy["default"])(MEDUSA_TELEMETRY_VERBOSE)) { | ||
console.log("POSTing batch succeeded"); | ||
} | ||
return true; | ||
})["catch"](function (e) { | ||
if ((0, _isTruthy["default"])(MEDUSA_TELEMETRY_VERBOSE)) { | ||
console.error("Failed to POST event batch", e); | ||
} | ||
return false; | ||
}); | ||
case 7: | ||
return _context.abrupt("return", _context.sent); | ||
case 8: | ||
case "end": | ||
return _context.stop(); | ||
while (1) switch (_context2.prev = _context2.next) { | ||
case 0: | ||
if (this.isTrackingEnabled()) { | ||
_context2.next = 2; | ||
break; | ||
} | ||
return _context2.abrupt("return"); | ||
case 2: | ||
_context2.next = 4; | ||
return this.store_.flushEvents( /*#__PURE__*/function () { | ||
var _ref = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee(events) { | ||
var data, req; | ||
return _regenerator["default"].wrap(function _callee$(_context) { | ||
while (1) switch (_context.prev = _context.next) { | ||
case 0: | ||
if (events.length) { | ||
_context.next = 3; | ||
break; | ||
} | ||
} | ||
}, _callee); | ||
})); | ||
return function (_x) { | ||
return _ref.apply(this, arguments); | ||
}; | ||
}()); | ||
case 4: | ||
case "end": | ||
return _context2.stop(); | ||
} | ||
if ((0, _isTruthy["default"])(MEDUSA_TELEMETRY_VERBOSE)) { | ||
console.log("No events to POST - skipping"); | ||
} | ||
return _context.abrupt("return", true); | ||
case 3: | ||
data = { | ||
batch: events, | ||
timestamp: new Date() | ||
}; | ||
req = { | ||
headers: {} | ||
}; | ||
_context.next = 7; | ||
return _this.axiosInstance.post("".concat(_this.host).concat(_this.path), data, req).then(function () { | ||
if ((0, _isTruthy["default"])(MEDUSA_TELEMETRY_VERBOSE)) { | ||
console.log("POSTing batch succeeded"); | ||
} | ||
return true; | ||
})["catch"](function (e) { | ||
if ((0, _isTruthy["default"])(MEDUSA_TELEMETRY_VERBOSE)) { | ||
console.error("Failed to POST event batch", e); | ||
} | ||
return false; | ||
}); | ||
case 7: | ||
return _context.abrupt("return", _context.sent); | ||
case 8: | ||
case "end": | ||
return _context.stop(); | ||
} | ||
}, _callee); | ||
})); | ||
return function (_x) { | ||
return _ref.apply(this, arguments); | ||
}; | ||
}()); | ||
case 4: | ||
case "end": | ||
return _context2.stop(); | ||
} | ||
}, _callee2, this); | ||
})); | ||
function dispatch() { | ||
return _dispatch.apply(this, arguments); | ||
} | ||
return dispatch; | ||
@@ -176,18 +139,16 @@ }() | ||
} | ||
if (!error.response) { | ||
// Cannot determine if the request can be retried | ||
return false; | ||
} // Retry Server Errors (5xx). | ||
} | ||
// Retry Server Errors (5xx). | ||
if (error.response.status >= 500 && error.response.status <= 599) { | ||
return true; | ||
} // Retry if rate limited. | ||
} | ||
// Retry if rate limited. | ||
if (error.response.status === 429) { | ||
return true; | ||
} | ||
return false; | ||
@@ -198,4 +159,3 @@ } | ||
}(); | ||
var _default = TelemetryDispatcher; | ||
exports["default"] = _default; |
{ | ||
"name": "medusa-telemetry", | ||
"version": "0.0.16", | ||
"version": "0.0.17-snapshot-20230821094003", | ||
"description": "Telemetry for Medusa", | ||
@@ -14,2 +14,5 @@ "main": "dist/index.js", | ||
}, | ||
"files": [ | ||
"dist" | ||
], | ||
"author": "Sebastian Rindom", | ||
@@ -20,14 +23,15 @@ "license": "MIT", | ||
"@babel/core": "^7.14.3", | ||
"@babel/node": "^7.22.10", | ||
"@babel/preset-typescript": "^7.15.0", | ||
"babel-preset-medusa-package": "^1.1.19", | ||
"cross-env": "^5.2.1", | ||
"jest": "^25.5.2", | ||
"nodemon": "^2.0.1" | ||
"jest": "^25.5.4", | ||
"nodemon": "^2.0.20" | ||
}, | ||
"scripts": { | ||
"start": "nodemon --watch plugins/ --watch src/ --exec babel-node src/app.js", | ||
"start": "nodemon --watch plugins/ --watch src/ --exec babel-node src/index.js", | ||
"prepare": "cross-env NODE_ENV=production yarn run build", | ||
"watch": "babel -w src --out-dir dist/ --extensions \".ts,.js\" --ignore '**/__tests__','**/__mocks__'", | ||
"build": "babel src -d dist --extensions \".ts,.js\" --ignore '**/__tests__','**/__mocks__'", | ||
"serve": "node dist/app.js", | ||
"serve": "node dist/index.js", | ||
"postinstall": "node dist/postinstall.js || true", | ||
@@ -37,3 +41,4 @@ "test": "jest --passWithNoTests src" | ||
"dependencies": { | ||
"axios": "^0.21.1", | ||
"@babel/runtime": "^7.22.10", | ||
"axios": "^0.21.4", | ||
"axios-retry": "^3.1.9", | ||
@@ -40,0 +45,0 @@ "boxen": "^5.0.1", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
38430
10
8
14
983
+ Added@babel/runtime@^7.22.10
Updatedaxios@^0.21.4