@yobytechautomation/config-lib 0.2.4 → 0.2.6
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.
|
@@ -40,6 +40,7 @@ exports.BASE_CONFIG_SERVICE = exports.BaseConfigServiceImpl = void 0;
|
|
|
40
40
|
const axios_1 = __importDefault(require("axios"));
|
|
41
41
|
const fs = __importStar(require("fs"));
|
|
42
42
|
const path = __importStar(require("path"));
|
|
43
|
+
const os = __importStar(require("os"));
|
|
43
44
|
class BaseConfigServiceImpl {
|
|
44
45
|
constructor() {
|
|
45
46
|
this.env = process.env;
|
|
@@ -95,9 +96,10 @@ class BaseConfigServiceImpl {
|
|
|
95
96
|
if (status !== 'active') {
|
|
96
97
|
throw new Error(`License ${status}. Please contact vendor.`);
|
|
97
98
|
}
|
|
98
|
-
|
|
99
|
+
const machineId = os.hostname();
|
|
99
100
|
fs.writeFileSync(cachePath, JSON.stringify({
|
|
100
101
|
lastValidated: new Date().toISOString(),
|
|
102
|
+
machineId,
|
|
101
103
|
}));
|
|
102
104
|
console.log('✅ License validated (online)');
|
|
103
105
|
}
|
|
@@ -105,11 +107,15 @@ class BaseConfigServiceImpl {
|
|
|
105
107
|
console.log('⚠️ Server not reachable, checking cache...');
|
|
106
108
|
if (fs.existsSync(cachePath)) {
|
|
107
109
|
const data = JSON.parse(fs.readFileSync(cachePath, 'utf-8'));
|
|
110
|
+
if (data.machineId !== os.hostname()) {
|
|
111
|
+
throw new Error('License cache copied from another machine');
|
|
112
|
+
}
|
|
108
113
|
const last = new Date(data.lastValidated);
|
|
109
114
|
const now = new Date();
|
|
110
115
|
const diffHours = (now.getTime() - last.getTime()) / (1000 * 60 * 60);
|
|
111
|
-
|
|
112
|
-
|
|
116
|
+
const MAX_OFFLINE_HOURS = 0.5; // 30 minutes
|
|
117
|
+
if (diffHours <= MAX_OFFLINE_HOURS) {
|
|
118
|
+
console.log('⚠️ Using cached license (temporary offline)');
|
|
113
119
|
return;
|
|
114
120
|
}
|
|
115
121
|
}
|