@yobytechautomation/config-lib 0.2.8 → 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.
@@ -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) {
@@ -105,10 +105,12 @@ class BaseConfigServiceImpl {
105
105
  const part3 = 'LmluL2xpY2Vuc2UvY2hlY2s=';
106
106
  const url = Buffer.from(part1 + part2 + part3, 'base64').toString('utf-8');
107
107
  const secret = process.env.LICENSE_SECRET;
108
+ const machineId = os.hostname();
108
109
  const res = await axios_1.default.get(url, {
109
110
  headers: {
110
111
  'x-api-key': apiKey,
111
112
  'x-license-secret': secret,
113
+ 'x-machine-id': machineId,
112
114
  },
113
115
  timeout: 5000,
114
116
  });
@@ -116,30 +118,37 @@ class BaseConfigServiceImpl {
116
118
  if (status !== 'active') {
117
119
  throw new Error(`License ${status}. Please contact vendor.`);
118
120
  }
119
- const machineId = os.hostname();
121
+ const machineId2 = os.hostname();
120
122
  fs.writeFileSync(cachePath, JSON.stringify({
121
123
  lastValidated: new Date().toISOString(),
122
- machineId,
124
+ machineId: machineId2,
123
125
  }));
124
126
  console.log('✅ License validated (online)');
125
127
  }
126
128
  catch (err) {
127
- console.log('⚠️ Server not reachable, checking cache...');
128
- if (fs.existsSync(cachePath)) {
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)) {
129
139
  const data = JSON.parse(fs.readFileSync(cachePath, 'utf-8'));
130
140
  if (data.machineId !== os.hostname()) {
131
141
  throw new Error('License cache copied from another machine');
132
142
  }
133
143
  const last = new Date(data.lastValidated);
134
144
  const now = new Date();
135
- const diffHours = (now.getTime() - last.getTime()) / (1000 * 60 * 60);
136
- const MAX_OFFLINE_HOURS = 0.5; // 30 minutes
137
- if (diffHours <= MAX_OFFLINE_HOURS) {
138
- 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)');
139
148
  return;
140
149
  }
141
150
  }
142
- throw new Error(err.message || 'License validation failed');
151
+ throw new Error('License server unreachable. App blocked.');
143
152
  }
144
153
  }
145
154
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yobytechautomation/config-lib",
3
- "version": "0.2.8",
3
+ "version": "0.3.0",
4
4
  "description": "Shared multi-environment configuration helpers for SDC NestJS services",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",