brew-tui 0.3.2 → 0.3.3
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/build/index.js +31 -29
- package/build/index.js.map +1 -1
- package/package.json +1 -1
package/build/index.js
CHANGED
|
@@ -535,8 +535,8 @@ async function getMachineId2() {
|
|
|
535
535
|
try {
|
|
536
536
|
const { readFile: readMachineId } = await import("fs/promises");
|
|
537
537
|
const { join: join4 } = await import("path");
|
|
538
|
-
const { homedir:
|
|
539
|
-
const machineIdPath = join4(
|
|
538
|
+
const { homedir: homedir3 } = await import("os");
|
|
539
|
+
const machineIdPath = join4(homedir3(), ".brew-tui", "machine-id");
|
|
540
540
|
return (await readMachineId(machineIdPath, "utf-8")).trim() || null;
|
|
541
541
|
} catch {
|
|
542
542
|
return null;
|
|
@@ -4019,48 +4019,50 @@ import { Box as Box28, Text as Text29, useInput as useInput13 } from "ink";
|
|
|
4019
4019
|
import { TextInput as TextInput5 } from "@inkjs/ui";
|
|
4020
4020
|
|
|
4021
4021
|
// src/lib/license/promo.ts
|
|
4022
|
-
import { readFile as readFile4, writeFile as writeFile4, rename as rename3 } from "fs/promises";
|
|
4023
|
-
import { randomBytes as randomBytes2 } from "crypto";
|
|
4022
|
+
import { readFile as readFile4, writeFile as writeFile4, rename as rename3, mkdir as mkdir2 } from "fs/promises";
|
|
4023
|
+
import { randomBytes as randomBytes2, randomUUID as randomUUID2 } from "crypto";
|
|
4024
4024
|
import { join as join3 } from "path";
|
|
4025
|
+
import { homedir as homedir2 } from "os";
|
|
4026
|
+
var MACHINE_ID_PATH2 = join3(homedir2(), ".brew-tui", "machine-id");
|
|
4027
|
+
async function getMachineId3() {
|
|
4028
|
+
try {
|
|
4029
|
+
const id2 = (await readFile4(MACHINE_ID_PATH2, "utf-8")).trim();
|
|
4030
|
+
if (id2) return id2;
|
|
4031
|
+
} catch {
|
|
4032
|
+
}
|
|
4033
|
+
const id = randomUUID2();
|
|
4034
|
+
await mkdir2(join3(homedir2(), ".brew-tui"), { recursive: true, mode: 448 });
|
|
4035
|
+
await writeFile4(MACHINE_ID_PATH2, id, { encoding: "utf-8", mode: 384 });
|
|
4036
|
+
return id;
|
|
4037
|
+
}
|
|
4025
4038
|
var PROMO_PATH = join3(DATA_DIR, "promo.json");
|
|
4026
|
-
var PROMO_API_URL = "https://api.molinesdesigns.com/promo";
|
|
4027
|
-
async function
|
|
4039
|
+
var PROMO_API_URL = "https://api.molinesdesigns.com/api/promo";
|
|
4040
|
+
async function redeemPromoCode(code) {
|
|
4028
4041
|
const normalized = code.trim().toUpperCase();
|
|
4029
|
-
|
|
4030
|
-
return { valid: false, error: "Invalid promo code format" };
|
|
4031
|
-
}
|
|
4042
|
+
const machineId = await getMachineId3();
|
|
4032
4043
|
try {
|
|
4033
|
-
const res = await fetchWithTimeout(`${PROMO_API_URL}/
|
|
4044
|
+
const res = await fetchWithTimeout(`${PROMO_API_URL}/redeem`, {
|
|
4034
4045
|
method: "POST",
|
|
4035
4046
|
headers: { "Content-Type": "application/json" },
|
|
4036
|
-
body: JSON.stringify({ code: normalized })
|
|
4047
|
+
body: JSON.stringify({ code: normalized, machineId })
|
|
4037
4048
|
}, 1e4);
|
|
4038
4049
|
if (!res.ok) {
|
|
4039
4050
|
const body = await res.json().catch(() => ({}));
|
|
4040
|
-
return {
|
|
4051
|
+
return { success: false, error: body.error ?? "Invalid or expired promo code" };
|
|
4041
4052
|
}
|
|
4042
4053
|
const data = await res.json();
|
|
4043
|
-
|
|
4044
|
-
|
|
4045
|
-
type: data.type,
|
|
4046
|
-
durationDays: data.durationDays
|
|
4047
|
-
};
|
|
4054
|
+
var serverExpiresAt = data.data.expiresAt;
|
|
4055
|
+
var serverType = data.data.type;
|
|
4048
4056
|
} catch (err) {
|
|
4049
|
-
logger.error("Promo
|
|
4050
|
-
return {
|
|
4051
|
-
}
|
|
4052
|
-
}
|
|
4053
|
-
async function redeemPromoCode(code) {
|
|
4054
|
-
const validation = await validatePromoCode(code);
|
|
4055
|
-
if (!validation.valid) {
|
|
4056
|
-
return { success: false, error: validation.error };
|
|
4057
|
+
logger.error("Promo redeem failed", { error: String(err) });
|
|
4058
|
+
return { success: false, error: "Could not reach promo server. Check your connection." };
|
|
4057
4059
|
}
|
|
4058
4060
|
await ensureDataDirs();
|
|
4059
4061
|
const redemption = {
|
|
4060
|
-
code:
|
|
4062
|
+
code: normalized,
|
|
4061
4063
|
redeemedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
4062
|
-
expiresAt:
|
|
4063
|
-
type:
|
|
4064
|
+
expiresAt: serverExpiresAt,
|
|
4065
|
+
type: serverType
|
|
4064
4066
|
};
|
|
4065
4067
|
let file = { version: 1, redemptions: [] };
|
|
4066
4068
|
try {
|
|
@@ -4227,7 +4229,7 @@ function AccountView() {
|
|
|
4227
4229
|
/* @__PURE__ */ jsx30(Box28, { marginTop: 1, children: /* @__PURE__ */ jsxs29(Text29, { color: COLORS.textSecondary, children: [
|
|
4228
4230
|
status === "pro" ? `d ${t("hint_deactivate")}` : "",
|
|
4229
4231
|
" ",
|
|
4230
|
-
t("app_version", { version: "0.3.
|
|
4232
|
+
t("app_version", { version: "0.3.3" })
|
|
4231
4233
|
] }) })
|
|
4232
4234
|
] });
|
|
4233
4235
|
}
|