generate-ui-cli 2.1.5 → 2.1.7

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/dist/index.js CHANGED
@@ -6,6 +6,7 @@ const generate_1 = require("./commands/generate");
6
6
  const angular_1 = require("./commands/angular");
7
7
  const login_1 = require("./commands/login");
8
8
  const config_1 = require("./runtime/config");
9
+ const telemetry_1 = require("./telemetry");
9
10
  const program = new commander_1.Command();
10
11
  program
11
12
  .name('generate-ui')
@@ -24,6 +25,7 @@ program
24
25
  .action(async (options) => {
25
26
  const { telemetry } = program.opts();
26
27
  try {
28
+ await (0, telemetry_1.trackGenerateCalled)();
27
29
  await (0, generate_1.generate)({
28
30
  openapi: options.openapi,
29
31
  output: options.output,
@@ -80,4 +82,14 @@ function handleCliError(error) {
80
82
  }
81
83
  process.exit(1);
82
84
  }
83
- program.parse();
85
+ async function run() {
86
+ console.log('[GenerateUI] started');
87
+ await (0, telemetry_1.trackCliStarted)();
88
+ if (process.argv.slice(2).length === 0) {
89
+ await (0, telemetry_1.trackCommandHelp)();
90
+ program.outputHelp();
91
+ return;
92
+ }
93
+ await program.parseAsync();
94
+ }
95
+ void run();
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const package_json_1 = __importDefault(require("../package.json"));
7
+ const TELEMETRY_URL = process.env.GENERATEUI_TELEMETRY_URL?.trim() ||
8
+ 'https://generateuibackend-production.up.railway.app/events';
9
+ async function sendInstallEvent() {
10
+ if (typeof fetch !== 'function')
11
+ return;
12
+ const payload = {
13
+ event: 'cli_installed',
14
+ cliVersion: package_json_1.default.version || '0.0.0',
15
+ npmUserAgent: process.env.npm_config_user_agent || ''
16
+ };
17
+ try {
18
+ await fetch(TELEMETRY_URL, {
19
+ method: 'POST',
20
+ headers: { 'Content-Type': 'application/json' },
21
+ body: JSON.stringify(payload)
22
+ });
23
+ }
24
+ catch {
25
+ // Postinstall must never block installation.
26
+ }
27
+ }
28
+ void sendInstallEvent();
@@ -11,8 +11,8 @@ function getCliVersion() {
11
11
  return package_json_1.default.version || '0.0.0';
12
12
  }
13
13
  function getApiBaseUrl() {
14
- return ('https://generateuibackend-production.up.railway.app/events');
14
+ return ('https://generateuibackend-production.up.railway.app');
15
15
  }
16
16
  function getWebAuthUrl() {
17
- return ('https://generateuibackend-production.up.railway.app/events');
17
+ return ('https://generateuibackend-production.up.railway.app');
18
18
  }
package/dist/telemetry.js CHANGED
@@ -1,5 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.trackCliStarted = trackCliStarted;
4
+ exports.trackCommandHelp = trackCommandHelp;
5
+ exports.trackGenerateCalled = trackGenerateCalled;
3
6
  exports.trackCommand = trackCommand;
4
7
  exports.trackLogin = trackLogin;
5
8
  const crypto_1 = require("crypto");
@@ -12,6 +15,12 @@ const TELEMETRY_TIMEOUT_MS = 1000;
12
15
  function getOsName() {
13
16
  return process.platform;
14
17
  }
18
+ function normalizeEmail(email) {
19
+ if (!email)
20
+ return null;
21
+ const trimmed = email.trim();
22
+ return trimmed.length > 0 ? trimmed : null;
23
+ }
15
24
  function loadOrCreateConfig() {
16
25
  let config = (0, user_config_1.loadUserConfig)();
17
26
  let isNew = false;
@@ -70,9 +79,7 @@ async function sendEvent(payload) {
70
79
  method: 'POST',
71
80
  headers: {
72
81
  'Content-Type': 'application/json',
73
- ...(token
74
- ? { Authorization: `Bearer ${token.accessToken}` }
75
- : {})
82
+ ...(token ? { Authorization: `Bearer ${token.accessToken}` } : {})
76
83
  },
77
84
  body: JSON.stringify(payload),
78
85
  signal: controller.signal
@@ -85,12 +92,34 @@ async function sendEvent(payload) {
85
92
  clearTimeout(timeout);
86
93
  }
87
94
  }
95
+ async function sendMandatoryEvent(event, extra) {
96
+ const { config } = loadOrCreateConfig();
97
+ const device = (0, device_1.loadDeviceIdentity)();
98
+ await sendEvent({
99
+ event,
100
+ installationId: config.installationId,
101
+ deviceId: device.deviceId,
102
+ cliVersion: (0, config_1.getCliVersion)(),
103
+ ...extra
104
+ });
105
+ }
106
+ async function trackCliStarted() {
107
+ await sendMandatoryEvent('cli_started');
108
+ }
109
+ async function trackCommandHelp() {
110
+ await sendMandatoryEvent('command_help');
111
+ }
112
+ async function trackGenerateCalled() {
113
+ await sendMandatoryEvent('generate_called');
114
+ }
88
115
  async function trackCommand(command, cliEnabled) {
89
116
  const { config, isNew } = loadOrCreateConfig();
90
117
  const enabled = isTelemetryEnabled(cliEnabled, config);
91
118
  if (!enabled)
92
119
  return;
93
120
  const device = (0, device_1.loadDeviceIdentity)();
121
+ if (!device?.deviceId)
122
+ return;
94
123
  if (isNew) {
95
124
  await sendEvent({
96
125
  event: 'first_run',
@@ -108,7 +137,7 @@ async function trackCommand(command, cliEnabled) {
108
137
  event: command,
109
138
  installationId: config.installationId,
110
139
  deviceId: device.deviceId,
111
- email: config.lastLoginEmail ?? '',
140
+ email: normalizeEmail(config.lastLoginEmail),
112
141
  cliVersion: (0, config_1.getCliVersion)()
113
142
  });
114
143
  }
@@ -118,11 +147,13 @@ async function trackLogin(email, cliEnabled) {
118
147
  if (!enabled)
119
148
  return;
120
149
  const device = (0, device_1.loadDeviceIdentity)();
150
+ if (!device?.deviceId)
151
+ return;
121
152
  await sendEvent({
122
153
  event: 'login',
123
154
  installationId: config.installationId,
124
155
  deviceId: device.deviceId,
125
- email: email ?? '',
156
+ email: normalizeEmail(email),
126
157
  cliVersion: (0, config_1.getCliVersion)()
127
158
  });
128
159
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "generate-ui-cli",
3
- "version": "2.1.5",
3
+ "version": "2.1.7",
4
4
  "description": "Generate UI from OpenAPI",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -37,6 +37,7 @@
37
37
  "scripts": {
38
38
  "build": "tsc -p tsconfig.json",
39
39
  "dev": "ts-node src/index.ts",
40
+ "postinstall": "node dist/postinstall.js",
40
41
  "prepublishOnly": "npm run build"
41
42
  },
42
43
  "dependencies": {