generate-ui-cli 2.1.1 → 2.1.2
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/commands/login.js +15 -2
- package/dist/runtime/config.js +2 -2
- package/dist/telemetry.js +14 -3
- package/package.json +1 -1
package/dist/commands/login.js
CHANGED
|
@@ -8,6 +8,7 @@ const http_1 = __importDefault(require("http"));
|
|
|
8
8
|
const url_1 = require("url");
|
|
9
9
|
const promises_1 = require("readline/promises");
|
|
10
10
|
const config_1 = require("../runtime/config");
|
|
11
|
+
const user_config_1 = require("../runtime/user-config");
|
|
11
12
|
const open_browser_1 = require("../runtime/open-browser");
|
|
12
13
|
const token_1 = require("../license/token");
|
|
13
14
|
const permissions_1 = require("../license/permissions");
|
|
@@ -24,6 +25,12 @@ async function login(options) {
|
|
|
24
25
|
// Cached permissions will be refreshed on next online command.
|
|
25
26
|
}
|
|
26
27
|
const email = await promptEmail();
|
|
28
|
+
if (email) {
|
|
29
|
+
(0, user_config_1.updateUserConfig)((config) => ({
|
|
30
|
+
...config,
|
|
31
|
+
lastLoginEmail: email
|
|
32
|
+
}));
|
|
33
|
+
}
|
|
27
34
|
await (0, telemetry_1.trackLogin)(email, options.telemetryEnabled);
|
|
28
35
|
console.log('✔ Login completo');
|
|
29
36
|
}
|
|
@@ -45,6 +52,7 @@ async function promptEmail() {
|
|
|
45
52
|
}
|
|
46
53
|
async function waitForLogin() {
|
|
47
54
|
return new Promise((resolve, reject) => {
|
|
55
|
+
let loginUrl = '';
|
|
48
56
|
const server = http_1.default.createServer((req, res) => {
|
|
49
57
|
const requestUrl = req.url || '/';
|
|
50
58
|
if (!requestUrl.startsWith('/callback')) {
|
|
@@ -132,7 +140,10 @@ async function waitForLogin() {
|
|
|
132
140
|
});
|
|
133
141
|
const timeout = setTimeout(() => {
|
|
134
142
|
server.close();
|
|
135
|
-
|
|
143
|
+
const help = loginUrl
|
|
144
|
+
? ` Ensure the login page is reachable and try again: ${loginUrl}`
|
|
145
|
+
: ` Ensure ${(0, config_1.getWebAuthUrl)()} and ${(0, config_1.getApiBaseUrl)()} are reachable.`;
|
|
146
|
+
reject(new Error(`Login timed out.${help}`));
|
|
136
147
|
}, LOGIN_TIMEOUT_MS);
|
|
137
148
|
server.listen(0, () => {
|
|
138
149
|
const address = server.address();
|
|
@@ -145,7 +156,9 @@ async function waitForLogin() {
|
|
|
145
156
|
const url = new url_1.URL((0, config_1.getWebAuthUrl)());
|
|
146
157
|
url.searchParams.set('redirect_uri', redirectUri);
|
|
147
158
|
url.searchParams.set('api_base', (0, config_1.getApiBaseUrl)());
|
|
148
|
-
|
|
159
|
+
loginUrl = url.toString();
|
|
160
|
+
console.log(`Open this URL to finish login: ${loginUrl}`);
|
|
161
|
+
(0, open_browser_1.openBrowser)(loginUrl);
|
|
149
162
|
});
|
|
150
163
|
});
|
|
151
164
|
}
|
package/dist/runtime/config.js
CHANGED
|
@@ -12,9 +12,9 @@ function getCliVersion() {
|
|
|
12
12
|
}
|
|
13
13
|
function getApiBaseUrl() {
|
|
14
14
|
return (process.env.GENERATEUI_API_BASE_URL?.trim() ||
|
|
15
|
-
'
|
|
15
|
+
'https://generateuibackend-production.up.railway.app');
|
|
16
16
|
}
|
|
17
17
|
function getWebAuthUrl() {
|
|
18
18
|
return (process.env.GENERATEUI_WEB_AUTH_URL?.trim() ||
|
|
19
|
-
'
|
|
19
|
+
'https://generateuibackend-production.up.railway.app');
|
|
20
20
|
}
|
package/dist/telemetry.js
CHANGED
|
@@ -6,8 +6,9 @@ const crypto_1 = require("crypto");
|
|
|
6
6
|
const config_1 = require("./runtime/config");
|
|
7
7
|
const user_config_1 = require("./runtime/user-config");
|
|
8
8
|
const device_1 = require("./license/device");
|
|
9
|
+
const token_1 = require("./license/token");
|
|
9
10
|
const TELEMETRY_URL = process.env.GENERATEUI_TELEMETRY_URL?.trim() ||
|
|
10
|
-
'https://api.generateui.dev/
|
|
11
|
+
'https://api.generateui.dev/telemetry';
|
|
11
12
|
const TELEMETRY_TIMEOUT_MS = 1000;
|
|
12
13
|
function getOsName() {
|
|
13
14
|
return process.platform;
|
|
@@ -50,7 +51,8 @@ function loadOrCreateConfig() {
|
|
|
50
51
|
return {
|
|
51
52
|
config: {
|
|
52
53
|
installationId,
|
|
53
|
-
telemetry: config.telemetry
|
|
54
|
+
telemetry: config.telemetry,
|
|
55
|
+
lastLoginEmail: config.lastLoginEmail
|
|
54
56
|
},
|
|
55
57
|
isNew
|
|
56
58
|
};
|
|
@@ -61,13 +63,17 @@ function isTelemetryEnabled(cliEnabled, config) {
|
|
|
61
63
|
return config.telemetry !== false;
|
|
62
64
|
}
|
|
63
65
|
async function sendEvent(payload) {
|
|
66
|
+
const token = (0, token_1.loadToken)();
|
|
64
67
|
const controller = new AbortController();
|
|
65
68
|
const timeout = setTimeout(() => controller.abort(), TELEMETRY_TIMEOUT_MS);
|
|
66
69
|
try {
|
|
67
70
|
await fetch(TELEMETRY_URL, {
|
|
68
71
|
method: 'POST',
|
|
69
72
|
headers: {
|
|
70
|
-
'Content-Type': 'application/json'
|
|
73
|
+
'Content-Type': 'application/json',
|
|
74
|
+
...(token
|
|
75
|
+
? { Authorization: `Bearer ${token.accessToken}` }
|
|
76
|
+
: {})
|
|
71
77
|
},
|
|
72
78
|
body: JSON.stringify(payload),
|
|
73
79
|
signal: controller.signal
|
|
@@ -91,6 +97,7 @@ async function trackCommand(command, cliEnabled) {
|
|
|
91
97
|
event: 'first_run',
|
|
92
98
|
installationId: config.installationId,
|
|
93
99
|
deviceId: device.deviceId,
|
|
100
|
+
deviceCreatedAt: device.createdAt,
|
|
94
101
|
os: getOsName(),
|
|
95
102
|
arch: process.arch,
|
|
96
103
|
cliVersion: (0, config_1.getCliVersion)()
|
|
@@ -99,7 +106,9 @@ async function trackCommand(command, cliEnabled) {
|
|
|
99
106
|
await sendEvent({
|
|
100
107
|
event: 'command_run',
|
|
101
108
|
installationId: config.installationId,
|
|
109
|
+
deviceId: device.deviceId,
|
|
102
110
|
command,
|
|
111
|
+
email: config.lastLoginEmail ?? '',
|
|
103
112
|
cliVersion: (0, config_1.getCliVersion)()
|
|
104
113
|
});
|
|
105
114
|
}
|
|
@@ -108,9 +117,11 @@ async function trackLogin(email, cliEnabled) {
|
|
|
108
117
|
const enabled = isTelemetryEnabled(cliEnabled, config);
|
|
109
118
|
if (!enabled)
|
|
110
119
|
return;
|
|
120
|
+
const device = (0, device_1.loadDeviceIdentity)();
|
|
111
121
|
await sendEvent({
|
|
112
122
|
event: 'login',
|
|
113
123
|
installationId: config.installationId,
|
|
124
|
+
deviceId: device.deviceId,
|
|
114
125
|
email: email ?? '',
|
|
115
126
|
cliVersion: (0, config_1.getCliVersion)()
|
|
116
127
|
});
|