@yobytechautomation/config-lib 0.3.0 → 0.3.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.
|
@@ -41,15 +41,16 @@ const axios_1 = __importDefault(require("axios"));
|
|
|
41
41
|
const fs = __importStar(require("fs"));
|
|
42
42
|
const path = __importStar(require("path"));
|
|
43
43
|
const os = __importStar(require("os"));
|
|
44
|
+
const crypto = __importStar(require("crypto"));
|
|
44
45
|
class BaseConfigServiceImpl {
|
|
45
46
|
constructor() {
|
|
46
47
|
this.env = process.env;
|
|
47
48
|
this.checkIntegrity();
|
|
48
49
|
}
|
|
49
50
|
checkIntegrity() {
|
|
50
|
-
const fileContent = fs.readFileSync(__filename,
|
|
51
|
-
if (!fileContent.includes(
|
|
52
|
-
console.error(
|
|
51
|
+
const fileContent = fs.readFileSync(__filename, "utf-8");
|
|
52
|
+
if (!fileContent.includes("validateLicenseOrThrow")) {
|
|
53
|
+
console.error("❌ License system tampered");
|
|
53
54
|
process.exit(1);
|
|
54
55
|
}
|
|
55
56
|
}
|
|
@@ -57,65 +58,70 @@ class BaseConfigServiceImpl {
|
|
|
57
58
|
setInterval(async () => {
|
|
58
59
|
try {
|
|
59
60
|
await this.validateLicenseOrThrow();
|
|
60
|
-
console.log(
|
|
61
|
+
console.log("💓 License heartbeat OK");
|
|
61
62
|
}
|
|
62
63
|
catch (err) {
|
|
63
|
-
console.error(
|
|
64
|
+
console.error("💀 License revoked during runtime");
|
|
64
65
|
process.exit(1);
|
|
65
66
|
}
|
|
66
67
|
}, 5 * 60 * 1000);
|
|
67
68
|
}
|
|
68
69
|
getDatabaseConfig() {
|
|
69
|
-
throw new Error(
|
|
70
|
+
throw new Error("Method not implemented.");
|
|
70
71
|
}
|
|
71
72
|
getPort() {
|
|
72
|
-
throw new Error(
|
|
73
|
+
throw new Error("Method not implemented.");
|
|
73
74
|
}
|
|
74
75
|
getMode() {
|
|
75
|
-
throw new Error(
|
|
76
|
+
throw new Error("Method not implemented.");
|
|
76
77
|
}
|
|
77
78
|
getConsulConfig() {
|
|
78
|
-
throw new Error(
|
|
79
|
+
throw new Error("Method not implemented.");
|
|
79
80
|
}
|
|
80
81
|
getRedisConfig() {
|
|
81
|
-
throw new Error(
|
|
82
|
+
throw new Error("Method not implemented.");
|
|
82
83
|
}
|
|
83
84
|
getJWTConfig() {
|
|
84
|
-
throw new Error(
|
|
85
|
+
throw new Error("Method not implemented.");
|
|
85
86
|
}
|
|
86
87
|
getJUtilConfig() {
|
|
87
|
-
throw new Error(
|
|
88
|
+
throw new Error("Method not implemented.");
|
|
88
89
|
}
|
|
89
90
|
getMailConfig() {
|
|
90
|
-
throw new Error(
|
|
91
|
+
throw new Error("Method not implemented.");
|
|
91
92
|
}
|
|
92
93
|
getKAFKAConfig() {
|
|
93
|
-
throw new Error(
|
|
94
|
+
throw new Error("Method not implemented.");
|
|
94
95
|
}
|
|
95
96
|
async validateLicenseOrThrow() {
|
|
96
97
|
var _a, _b, _c;
|
|
97
|
-
const cachePath = path.join(process.cwd(),
|
|
98
|
+
const cachePath = path.join(process.cwd(), ".license-cache.json");
|
|
98
99
|
const apiKey = this.env.LICENSE_KEY;
|
|
99
100
|
if (!apiKey) {
|
|
100
|
-
throw new Error(
|
|
101
|
+
throw new Error("LICENSE_KEY missing");
|
|
101
102
|
}
|
|
102
103
|
try {
|
|
103
|
-
const part1 =
|
|
104
|
-
const part2 =
|
|
105
|
-
const part3 =
|
|
106
|
-
const url = Buffer.from(part1 + part2 + part3,
|
|
104
|
+
const part1 = "aHR0cHM6Ly9kZXYu";
|
|
105
|
+
const part2 = "d2F0ZXJhdXRvLnlvYnl0ZWNo";
|
|
106
|
+
const part3 = "LmluL2xpY2Vuc2UvY2hlY2s=";
|
|
107
|
+
const url = Buffer.from(part1 + part2 + part3, "base64").toString("utf-8");
|
|
107
108
|
const secret = process.env.LICENSE_SECRET;
|
|
108
109
|
const machineId = os.hostname();
|
|
110
|
+
const signature = crypto
|
|
111
|
+
.createHmac("sha256", secret)
|
|
112
|
+
.update(apiKey + machineId)
|
|
113
|
+
.digest("hex");
|
|
109
114
|
const res = await axios_1.default.get(url, {
|
|
110
115
|
headers: {
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
116
|
+
"x-api-key": apiKey,
|
|
117
|
+
"x-license-secret": secret,
|
|
118
|
+
"x-machine-id": machineId,
|
|
119
|
+
'x-signature': signature,
|
|
114
120
|
},
|
|
115
121
|
timeout: 5000,
|
|
116
122
|
});
|
|
117
123
|
const status = (_a = res === null || res === void 0 ? void 0 : res.data) === null || _a === void 0 ? void 0 : _a.status;
|
|
118
|
-
if (status !==
|
|
124
|
+
if (status !== "active") {
|
|
119
125
|
throw new Error(`License ${status}. Please contact vendor.`);
|
|
120
126
|
}
|
|
121
127
|
const machineId2 = os.hostname();
|
|
@@ -123,7 +129,7 @@ class BaseConfigServiceImpl {
|
|
|
123
129
|
lastValidated: new Date().toISOString(),
|
|
124
130
|
machineId: machineId2,
|
|
125
131
|
}));
|
|
126
|
-
console.log(
|
|
132
|
+
console.log("✅ License validated (online)");
|
|
127
133
|
}
|
|
128
134
|
catch (err) {
|
|
129
135
|
const errorMsg = (_c = (_b = err === null || err === void 0 ? void 0 : err.response) === null || _b === void 0 ? void 0 : _b.data) === null || _c === void 0 ? void 0 : _c.status;
|
|
@@ -132,25 +138,26 @@ class BaseConfigServiceImpl {
|
|
|
132
138
|
throw new Error(`License ${errorMsg}. Please contact vendor.`);
|
|
133
139
|
}
|
|
134
140
|
// 🔥 CASE 2 — SERVER NOT REACHABLE
|
|
135
|
-
console.error(
|
|
141
|
+
console.error("❌ License server unreachable");
|
|
136
142
|
// ⚠️ OPTIONAL STRICT CACHE (VERY LIMITED USE)
|
|
137
143
|
const ALLOW_OFFLINE = false; // 🔥 set FALSE for production
|
|
138
144
|
if (ALLOW_OFFLINE && fs.existsSync(cachePath)) {
|
|
139
|
-
const data = JSON.parse(fs.readFileSync(cachePath,
|
|
145
|
+
const data = JSON.parse(fs.readFileSync(cachePath, "utf-8"));
|
|
140
146
|
if (data.machineId !== os.hostname()) {
|
|
141
|
-
throw new Error(
|
|
147
|
+
throw new Error("License cache copied from another machine");
|
|
142
148
|
}
|
|
143
149
|
const last = new Date(data.lastValidated);
|
|
144
150
|
const now = new Date();
|
|
145
151
|
const diffMinutes = (now.getTime() - last.getTime()) / (1000 * 60);
|
|
146
|
-
if (diffMinutes <= 5) {
|
|
147
|
-
|
|
152
|
+
if (diffMinutes <= 5) {
|
|
153
|
+
// max 5 minutes only
|
|
154
|
+
console.log("⚠️ Temporary offline mode (5 min)");
|
|
148
155
|
return;
|
|
149
156
|
}
|
|
150
157
|
}
|
|
151
|
-
throw new Error(
|
|
158
|
+
throw new Error("License server unreachable. App blocked.");
|
|
152
159
|
}
|
|
153
160
|
}
|
|
154
161
|
}
|
|
155
162
|
exports.BaseConfigServiceImpl = BaseConfigServiceImpl;
|
|
156
|
-
exports.BASE_CONFIG_SERVICE = Symbol(
|
|
163
|
+
exports.BASE_CONFIG_SERVICE = Symbol("BASE_CONFIG_SERVICE");
|