awarts 0.3.1 → 0.3.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/index.js +50 -8
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -4710,26 +4710,61 @@ var open_default = open;
|
|
|
4710
4710
|
import fs7 from "node:fs/promises";
|
|
4711
4711
|
import path3 from "node:path";
|
|
4712
4712
|
import os4 from "node:os";
|
|
4713
|
+
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
4713
4714
|
|
|
4714
4715
|
// src/lib/auth-store.ts
|
|
4715
4716
|
import fs6 from "node:fs/promises";
|
|
4716
4717
|
import path2 from "node:path";
|
|
4717
4718
|
import os3 from "node:os";
|
|
4719
|
+
import crypto from "node:crypto";
|
|
4718
4720
|
var AWARTS_DIR = path2.join(os3.homedir(), ".awarts");
|
|
4719
4721
|
var AUTH_FILE = path2.join(AWARTS_DIR, "auth.json");
|
|
4722
|
+
function deriveKey() {
|
|
4723
|
+
const material = `awarts-cli:${os3.hostname()}:${os3.userInfo().username}`;
|
|
4724
|
+
return crypto.createHash("sha256").update(material).digest();
|
|
4725
|
+
}
|
|
4726
|
+
function encrypt(plaintext) {
|
|
4727
|
+
const key = deriveKey();
|
|
4728
|
+
const iv = crypto.randomBytes(12);
|
|
4729
|
+
const cipher = crypto.createCipheriv("aes-256-gcm", key, iv);
|
|
4730
|
+
const encrypted = Buffer.concat([cipher.update(plaintext, "utf8"), cipher.final()]);
|
|
4731
|
+
const tag = cipher.getAuthTag();
|
|
4732
|
+
return {
|
|
4733
|
+
version: 2,
|
|
4734
|
+
iv: iv.toString("hex"),
|
|
4735
|
+
tag: tag.toString("hex"),
|
|
4736
|
+
ciphertext: encrypted.toString("hex")
|
|
4737
|
+
};
|
|
4738
|
+
}
|
|
4739
|
+
function decrypt(file) {
|
|
4740
|
+
const key = deriveKey();
|
|
4741
|
+
const decipher = crypto.createDecipheriv("aes-256-gcm", key, Buffer.from(file.iv, "hex"));
|
|
4742
|
+
decipher.setAuthTag(Buffer.from(file.tag, "hex"));
|
|
4743
|
+
return decipher.update(file.ciphertext, "hex", "utf8") + decipher.final("utf8");
|
|
4744
|
+
}
|
|
4720
4745
|
async function ensureDir() {
|
|
4721
4746
|
await fs6.mkdir(AWARTS_DIR, { recursive: true, mode: 448 });
|
|
4722
4747
|
}
|
|
4723
4748
|
async function saveAuth(data) {
|
|
4724
4749
|
await ensureDir();
|
|
4725
|
-
|
|
4750
|
+
const encrypted = encrypt(JSON.stringify(data));
|
|
4751
|
+
await fs6.writeFile(AUTH_FILE, JSON.stringify(encrypted, null, 2), { encoding: "utf-8", mode: 384 });
|
|
4726
4752
|
}
|
|
4727
4753
|
async function loadAuth() {
|
|
4728
4754
|
try {
|
|
4729
4755
|
const raw = await fs6.readFile(AUTH_FILE, "utf-8");
|
|
4730
4756
|
const parsed = JSON.parse(raw);
|
|
4757
|
+
if (parsed.version === 2 && parsed.ciphertext) {
|
|
4758
|
+
const decrypted = JSON.parse(decrypt(parsed));
|
|
4759
|
+
if (typeof decrypted.token === "string" && typeof decrypted.user_id === "string") {
|
|
4760
|
+
return decrypted;
|
|
4761
|
+
}
|
|
4762
|
+
return null;
|
|
4763
|
+
}
|
|
4731
4764
|
if (typeof parsed.token === "string" && typeof parsed.user_id === "string") {
|
|
4732
|
-
|
|
4765
|
+
const data = parsed;
|
|
4766
|
+
await saveAuth(data);
|
|
4767
|
+
return data;
|
|
4733
4768
|
}
|
|
4734
4769
|
return null;
|
|
4735
4770
|
} catch {
|
|
@@ -4747,6 +4782,13 @@ async function getToken() {
|
|
|
4747
4782
|
}
|
|
4748
4783
|
|
|
4749
4784
|
// src/lib/api.ts
|
|
4785
|
+
var __dirname3 = path3.dirname(fileURLToPath2(import.meta.url));
|
|
4786
|
+
var _cliVersion = "0.0.0";
|
|
4787
|
+
try {
|
|
4788
|
+
const pkgPath = path3.resolve(__dirname3, "..", "package.json");
|
|
4789
|
+
const pkg = JSON.parse(await fs7.readFile(pkgPath, "utf-8"));
|
|
4790
|
+
_cliVersion = pkg.version ?? "0.0.0";
|
|
4791
|
+
} catch {}
|
|
4750
4792
|
var DEFAULT_API_URL = "https://honorable-bee-242.convex.site";
|
|
4751
4793
|
async function readConfigUrl() {
|
|
4752
4794
|
try {
|
|
@@ -4781,7 +4823,7 @@ async function apiRequest(method, endpoint, body) {
|
|
|
4781
4823
|
const token = await getToken();
|
|
4782
4824
|
const headers = {
|
|
4783
4825
|
"Content-Type": "application/json",
|
|
4784
|
-
"User-Agent":
|
|
4826
|
+
"User-Agent": `awarts-cli/${_cliVersion}`
|
|
4785
4827
|
};
|
|
4786
4828
|
if (token) {
|
|
4787
4829
|
headers["Authorization"] = `Bearer ${token}`;
|
|
@@ -4808,7 +4850,7 @@ async function postUnauthenticated(endpoint, body) {
|
|
|
4808
4850
|
method: "POST",
|
|
4809
4851
|
headers: {
|
|
4810
4852
|
"Content-Type": "application/json",
|
|
4811
|
-
"User-Agent":
|
|
4853
|
+
"User-Agent": `awarts-cli/${_cliVersion}`
|
|
4812
4854
|
},
|
|
4813
4855
|
body: body != null ? JSON.stringify(body) : undefined
|
|
4814
4856
|
});
|
|
@@ -5990,7 +6032,7 @@ import os7 from "node:os";
|
|
|
5990
6032
|
var KEYS_PATH = path6.join(os7.homedir(), ".awarts", "keys.json");
|
|
5991
6033
|
async function ensureDir3() {
|
|
5992
6034
|
const dir = path6.dirname(KEYS_PATH);
|
|
5993
|
-
await fs10.mkdir(dir, { recursive: true });
|
|
6035
|
+
await fs10.mkdir(dir, { recursive: true, mode: 448 });
|
|
5994
6036
|
}
|
|
5995
6037
|
async function loadKeys() {
|
|
5996
6038
|
try {
|
|
@@ -7376,12 +7418,12 @@ async function daemonRunLoop(intervalMs) {
|
|
|
7376
7418
|
|
|
7377
7419
|
// src/lib/version-check.ts
|
|
7378
7420
|
import { readFileSync } from "node:fs";
|
|
7379
|
-
import { fileURLToPath as
|
|
7421
|
+
import { fileURLToPath as fileURLToPath3 } from "node:url";
|
|
7380
7422
|
import { dirname, join } from "node:path";
|
|
7381
|
-
var
|
|
7423
|
+
var __dirname4 = dirname(fileURLToPath3(import.meta.url));
|
|
7382
7424
|
function getLocalVersion() {
|
|
7383
7425
|
try {
|
|
7384
|
-
const pkg = JSON.parse(readFileSync(join(
|
|
7426
|
+
const pkg = JSON.parse(readFileSync(join(__dirname4, "..", "package.json"), "utf-8"));
|
|
7385
7427
|
return pkg.version ?? "0.0.0";
|
|
7386
7428
|
} catch {
|
|
7387
7429
|
return "0.0.0";
|