@yobytechautomation/config-lib 0.2.9 → 0.3.0
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/base-config.service.js +15 -8
- package/package.json +1 -1
|
@@ -93,7 +93,7 @@ class BaseConfigServiceImpl {
|
|
|
93
93
|
throw new Error('Method not implemented.');
|
|
94
94
|
}
|
|
95
95
|
async validateLicenseOrThrow() {
|
|
96
|
-
var _a;
|
|
96
|
+
var _a, _b, _c;
|
|
97
97
|
const cachePath = path.join(process.cwd(), '.license-cache.json');
|
|
98
98
|
const apiKey = this.env.LICENSE_KEY;
|
|
99
99
|
if (!apiKey) {
|
|
@@ -126,22 +126,29 @@ class BaseConfigServiceImpl {
|
|
|
126
126
|
console.log('✅ License validated (online)');
|
|
127
127
|
}
|
|
128
128
|
catch (err) {
|
|
129
|
-
|
|
130
|
-
|
|
129
|
+
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;
|
|
130
|
+
// 🔥 CASE 1 — SERVER RESPONDED (LICENSE INVALID)
|
|
131
|
+
if (errorMsg) {
|
|
132
|
+
throw new Error(`License ${errorMsg}. Please contact vendor.`);
|
|
133
|
+
}
|
|
134
|
+
// 🔥 CASE 2 — SERVER NOT REACHABLE
|
|
135
|
+
console.error('❌ License server unreachable');
|
|
136
|
+
// ⚠️ OPTIONAL STRICT CACHE (VERY LIMITED USE)
|
|
137
|
+
const ALLOW_OFFLINE = false; // 🔥 set FALSE for production
|
|
138
|
+
if (ALLOW_OFFLINE && fs.existsSync(cachePath)) {
|
|
131
139
|
const data = JSON.parse(fs.readFileSync(cachePath, 'utf-8'));
|
|
132
140
|
if (data.machineId !== os.hostname()) {
|
|
133
141
|
throw new Error('License cache copied from another machine');
|
|
134
142
|
}
|
|
135
143
|
const last = new Date(data.lastValidated);
|
|
136
144
|
const now = new Date();
|
|
137
|
-
const
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
console.log('⚠️ Using cached license (temporary offline)');
|
|
145
|
+
const diffMinutes = (now.getTime() - last.getTime()) / (1000 * 60);
|
|
146
|
+
if (diffMinutes <= 5) { // max 5 minutes only
|
|
147
|
+
console.log('⚠️ Temporary offline mode (5 min)');
|
|
141
148
|
return;
|
|
142
149
|
}
|
|
143
150
|
}
|
|
144
|
-
throw new Error(
|
|
151
|
+
throw new Error('License server unreachable. App blocked.');
|
|
145
152
|
}
|
|
146
153
|
}
|
|
147
154
|
}
|