@medusajs/telemetry 2.22.0-snapshot-20261020204851 → 2.22.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/AGENTS.md ADDED
@@ -0,0 +1,36 @@
1
+ # @medusajs/telemetry
2
+
3
+ Anonymous usage telemetry for the Medusa CLI and server. Used internally by `@medusajs/cli`, `@medusajs/medusa` commands, `@medusajs/framework` (feature flags), and `create-medusa-app`; applications never configure it directly.
4
+
5
+ ## Using this package
6
+
7
+ - Opting out (end users): set `MEDUSA_DISABLE_TELEMETRY=true` or run `npx medusa telemetry --disable` (persists `telemetry.enabled: false`).
8
+ - https://docs.medusajs.com/learn/resources/usage.md
9
+ - https://docs.medusajs.com/resources/medusa-cli/commands/telemtry.md
10
+ - Exports (from `src/index.js`):
11
+ - `track(event, data?)`: queue an event, e.g. `track("CLI_START")`, `track("CLI_USER", { with_id: !!id })`
12
+ - `setTelemetryEnabled(enabled = true)`: backs the `medusa telemetry` command in `packages/cli/medusa-cli/src/create-cli.ts`
13
+ - `trackFeatureFlag(flag)`, `trackInstallation(installation, "plugin" | "module")`: attached to every later event
14
+ - `flush`, `Store`, `Telemeter`
15
+ - `Store` doubles as Medusa's persistent per-machine config store; other packages use it for non-telemetry flags (`star.prompted` in `packages/medusa/src/commands/develop.ts`, the Claude Code plugin prompt in `packages/medusa/src/utils/claude-code-plugin.ts`).
16
+
17
+ ## Architecture
18
+
19
+ - Plain JavaScript (`src/*.js`, compiled via `allowJs`); no types beyond generated declarations.
20
+ - Flow: `track` -> `Telemeter.enqueue_` -> `Store.addEvent` appends a JSON line to `events.json` (`util/outbox-store.js`) next to the `configstore` file named `medusa` -> when `flushAt` (20 events), `maxQueueSize` (500 KB) or `flushInterval` (10 s) is hit, `util/create-flush.js` forks `util/send.js` as a detached, unref'd child -> `util/telemetry-dispatcher.js` POSTs `{ batch, timestamp }` with `axios-retry` (3 retries on network errors, 5xx, 429).
21
+ - Every event carries `machine_id` (stored as `telemetry.machine_id`), OS/CI info (`util/is-ci.js`), the resolved `@medusajs/medusa` and `@medusajs/cli` versions, feature flags, modules, and plugins.
22
+ - Env vars: `MEDUSA_DISABLE_TELEMETRY`, `MEDUSA_TELEMETRY_VERBOSE` (logs flush/send errors; also makes the forked sender inherit stdio), `MEDUSA_TELEMETRY_HOST` / `MEDUSA_TELEMETRY_PATH` (default `https://telemetry.medusa-commerce.com` + `/batch`).
23
+
24
+ ## Development
25
+
26
+ - `yarn build`, `yarn watch`, `yarn test` (`jest --passWithNoTests src`; there are currently no tests).
27
+ - The `start` script (nodemon on `plugins/`) is stale; don't rely on it.
28
+ - To debug locally, point `MEDUSA_TELEMETRY_HOST` at a local server and set `MEDUSA_TELEMETRY_VERBOSE=true`.
29
+
30
+ ## Gotchas
31
+
32
+ - Importing the package has side effects: it constructs a `Telemeter`, reads/writes config, may print the opt-out notice (outside CI) on first run, and registers `process.on("exit", flush)`.
33
+ - `postinstall` runs `node dist/postinstall.js || true` to show the opt-out notice on install; it must never throw.
34
+ - `MEDUSA_DISABLE_TELEMETRY` only stops events from being written (`Store.addEvent`); the on/off decision for flushing comes from the stored `telemetry.enabled` config, which defaults to `true` when unset.
35
+ - If `configstore` can't write (read-only home dir), `Store` falls back to `InMemoryConfigStore` with a throwaway `not-a-machine-id-*` id and the OS temp dir as base path.
36
+ - The sender is a separate process: a failed POST writes the batch back to `events.json`, but events can be lost if that process dies mid-send (see comment in `outbox-store.js`).
package/README.md ADDED
@@ -0,0 +1,70 @@
1
+ <p align="center">
2
+ <a href="https://www.medusajs.com">
3
+ <picture>
4
+ <source media="(prefers-color-scheme: dark)" srcset="https://user-images.githubusercontent.com/59018053/229103275-b5e482bb-4601-46e6-8142-244f531cebdb.svg">
5
+ <source media="(prefers-color-scheme: light)" srcset="https://user-images.githubusercontent.com/59018053/229103726-e5b529a3-9b3f-4970-8a1f-c6af37f087bf.svg">
6
+ <img alt="Medusa logo" src="https://user-images.githubusercontent.com/59018053/229103726-e5b529a3-9b3f-4970-8a1f-c6af37f087bf.svg">
7
+ </picture>
8
+ </a>
9
+ </p>
10
+ <h1 align="center">
11
+ @medusajs/telemetry
12
+ </h1>
13
+
14
+ <h4 align="center">
15
+ <a href="https://docs.medusajs.com">Documentation</a> |
16
+ <a href="https://www.medusajs.com">Website</a>
17
+ </h4>
18
+
19
+ <p align="center">
20
+ Building blocks for digital commerce
21
+ </p>
22
+ <p align="center">
23
+ <a href="https://github.com/medusajs/medusa/blob/develop/LICENSE">
24
+ <img src="https://img.shields.io/badge/license-MIT-blue.svg" alt="Medusa is released under the MIT license." />
25
+ </a>
26
+ <a href="https://github.com/medusajs/medusa/blob/develop/CONTRIBUTING.md">
27
+ <img src="https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat" alt="PRs welcome!" />
28
+ </a>
29
+ <a href="https://discord.gg/xpCwq3Kfn8">
30
+ <img src="https://img.shields.io/badge/chat-on%20discord-7289DA.svg" alt="Discord Chat" />
31
+ </a>
32
+ <a href="https://twitter.com/intent/follow?screen_name=medusajs">
33
+ <img src="https://img.shields.io/twitter/follow/medusajs.svg?label=Follow%20@medusajs" alt="Follow @medusajs" />
34
+ </a>
35
+ </p>
36
+
37
+ `@medusajs/telemetry` collects anonymous, non-sensitive usage data from the Medusa CLI and application, such as OS and Node.js version and the Medusa version in use. It is an internal dependency of `@medusajs/medusa`, `@medusajs/framework`, and `@medusajs/cli`; you don't install or call it directly, but you can opt out of it.
38
+
39
+ ## At a glance
40
+
41
+ | | |
42
+ | --- | --- |
43
+ | Package | `@medusajs/telemetry` |
44
+ | Type | Internal tooling |
45
+
46
+ ## Opting out
47
+
48
+ Set the environment variable:
49
+
50
+ ```bash
51
+ MEDUSA_DISABLE_TELEMETRY=true
52
+ ```
53
+
54
+ Or run the CLI command in your project:
55
+
56
+ ```bash
57
+ npx medusa telemetry --disable
58
+ ```
59
+
60
+ ## Configuration
61
+
62
+ | Environment variable | Description | Default |
63
+ | --- | --- | --- |
64
+ | `MEDUSA_DISABLE_TELEMETRY` | Disables telemetry collection when truthy. | - |
65
+ | `MEDUSA_TELEMETRY_VERBOSE` | Logs telemetry activity to the console when truthy. | - |
66
+
67
+ ## Resources
68
+
69
+ - [Usage information](https://docs.medusajs.com/learn/resources/usage)
70
+ - [`medusa telemetry` command](https://docs.medusajs.com/resources/medusa-cli/commands/telemtry)
package/dist/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export function trackFeatureFlag(flag: any): void;
2
2
  export function trackInstallation(installation: any, type: any): void;
3
+ export const flush: (() => Promise<void>) | undefined;
3
4
  export function track(event: any, data?: {}): void;
4
5
  export function setTelemetryEnabled(enabled?: boolean): void;
5
6
  export { default as Store } from "./store";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.js"],"names":[],"mappings":"AA8CA,kDAEC;AAED,sEAWC;AAvBM,mDAEN;AAEM,6DAEN"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.js"],"names":[],"mappings":"AAmBA,kDAEC;AAED,sEASC;AA3BD,sDAA+D;AAMxD,mDAEN;AAEM,6DAEN"}
package/dist/index.js CHANGED
@@ -3,62 +3,36 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.Telemeter = exports.Store = exports.setTelemetryEnabled = exports.track = void 0;
6
+ exports.Telemeter = exports.Store = exports.setTelemetryEnabled = exports.track = exports.flush = void 0;
7
7
  exports.trackFeatureFlag = trackFeatureFlag;
8
8
  exports.trackInstallation = trackInstallation;
9
9
  const telemeter_1 = __importDefault(require("./telemeter"));
10
10
  const create_flush_1 = __importDefault(require("./util/create-flush"));
11
- /**
12
- * Creating the telemeter reads its config from disk and inspects the
13
- * environment, and tracking writes to the outbox synchronously. Neither should
14
- * happen while the importing process boots, so the telemeter is created on
15
- * first use and tracked events are processed shortly after, or on exit.
16
- */
17
- const TRACKING_DELAY_MS = 2000;
18
- let telemeter;
19
- const pending = [];
20
- let drainTimer;
21
- function getTelemeter() {
22
- telemeter ??= new telemeter_1.default();
23
- return telemeter;
11
+ const telemeter = new telemeter_1.default();
12
+ exports.flush = (0, create_flush_1.default)(telemeter.isTrackingEnabled());
13
+ if (exports.flush) {
14
+ process.on(`exit`, exports.flush);
24
15
  }
25
- function drain() {
26
- clearTimeout(drainTimer);
27
- drainTimer = undefined;
28
- while (pending.length) {
29
- pending.shift()(getTelemeter());
30
- }
31
- }
32
- function defer(fn) {
33
- pending.push(fn);
34
- drainTimer ??= setTimeout(drain, TRACKING_DELAY_MS).unref();
35
- }
36
- process.on(`exit`, () => {
37
- drain();
38
- (0, create_flush_1.default)(getTelemeter().isTrackingEnabled())?.();
39
- });
40
16
  const track = (event, data = {}) => {
41
- defer((t) => t.track(event, data));
17
+ telemeter.track(event, data);
42
18
  };
43
19
  exports.track = track;
44
20
  const setTelemetryEnabled = (enabled = true) => {
45
- getTelemeter().setTelemetryEnabled(enabled);
21
+ telemeter.setTelemetryEnabled(enabled);
46
22
  };
47
23
  exports.setTelemetryEnabled = setTelemetryEnabled;
48
24
  function trackFeatureFlag(flag) {
49
- defer((t) => t.trackFeatureFlag(flag));
25
+ telemeter.trackFeatureFlag(flag);
50
26
  }
51
27
  function trackInstallation(installation, type) {
52
- defer((t) => {
53
- switch (type) {
54
- case `plugin`:
55
- t.trackPlugin(installation);
56
- break;
57
- case `module`:
58
- t.trackModule(installation);
59
- break;
60
- }
61
- });
28
+ switch (type) {
29
+ case `plugin`:
30
+ telemeter.trackPlugin(installation);
31
+ break;
32
+ case `module`:
33
+ telemeter.trackModule(installation);
34
+ break;
35
+ }
62
36
  }
63
37
  var store_1 = require("./store");
64
38
  Object.defineProperty(exports, "Store", { enumerable: true, get: function () { return __importDefault(store_1).default; } });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@medusajs/telemetry",
3
- "version": "2.22.0-snapshot-20261020204851",
3
+ "version": "2.22.0",
4
4
  "description": "Telemetry for Medusa",
5
5
  "main": "dist/index.js",
6
6
  "repository": {
@@ -18,8 +18,12 @@
18
18
  "access": "public"
19
19
  },
20
20
  "files": [
21
- "dist"
21
+ "dist",
22
+ "AGENTS.md"
22
23
  ],
24
+ "llms": "https://docs.medusajs.com/llms.txt",
25
+ "llmsFull": "https://docs.medusajs.com/llms-full.txt",
26
+ "mcpServer": "https://docs.medusajs.com/mcp",
23
27
  "author": "Sebastian Rindom",
24
28
  "license": "MIT",
25
29
  "scripts": {