@novacraft-engineering/pulsar-cli 1.4.0 → 1.4.1
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/package.json +1 -1
- package/pulsar.js +6 -3
package/package.json
CHANGED
package/pulsar.js
CHANGED
|
@@ -42,14 +42,16 @@ function loadConfig() {
|
|
|
42
42
|
return {
|
|
43
43
|
apiUrl: process.env.PULSAR_API_URL || fromFile.apiUrl,
|
|
44
44
|
token: process.env.PULSAR_TOKEN || fromFile.token,
|
|
45
|
+
deviceId: fromFile.deviceId,
|
|
45
46
|
};
|
|
46
47
|
}
|
|
47
48
|
|
|
48
49
|
function saveConfig(config) {
|
|
49
50
|
// The config holds a bearer token — keep the dir and file owner-only so other local users on a
|
|
50
51
|
// shared host can't read the session.
|
|
52
|
+
const deviceId = config.deviceId || loadConfig().deviceId;
|
|
51
53
|
fs.mkdirSync(CONFIG_DIR, {recursive: true, mode: 0o700});
|
|
52
|
-
fs.writeFileSync(CONFIG_FILE, JSON.stringify(config, null, 2), {mode: 0o600});
|
|
54
|
+
fs.writeFileSync(CONFIG_FILE, JSON.stringify({...config, deviceId}, null, 2), {mode: 0o600});
|
|
53
55
|
try { fs.chmodSync(CONFIG_FILE, 0o600); } catch { /* best-effort on pre-existing files */ }
|
|
54
56
|
}
|
|
55
57
|
|
|
@@ -347,8 +349,9 @@ async function cmdLogin(args) {
|
|
|
347
349
|
|
|
348
350
|
const email = await prompt('Email: ');
|
|
349
351
|
const password = await prompt('Password: ', true);
|
|
350
|
-
const
|
|
351
|
-
|
|
352
|
+
const deviceId = loadConfig().deviceId || crypto.randomBytes(16).toString('hex');
|
|
353
|
+
const {token, user} = await api('/auth/login', {method: 'POST', body: {email, password}, headers: {'x-device-id': deviceId}, allowAnonymous: true});
|
|
354
|
+
saveConfig({apiUrl, token, deviceId});
|
|
352
355
|
console.log(`✓ logged in as ${user.email} (${user.platformRole})`);
|
|
353
356
|
}
|
|
354
357
|
|