@yobytechautomation/config-lib 0.1.7 → 0.1.9

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.
@@ -39,8 +39,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
39
39
  exports.BASE_CONFIG_SERVICE = exports.BaseConfigServiceImpl = void 0;
40
40
  const axios_1 = __importDefault(require("axios"));
41
41
  const dotenv = __importStar(require("dotenv"));
42
+ const fs = __importStar(require("fs"));
43
+ const path = __importStar(require("path"));
42
44
  // 🔥 LOAD ENV FILE FIRST (VERY IMPORTANT)
43
- // dotenv.config();
44
45
  dotenv.config({ path: process.env.ENV_FILE || '.env.local' });
45
46
  /**
46
47
  * 🔥 BASE IMPLEMENTATION (LICENSE CONTROL)
@@ -52,22 +53,50 @@ class BaseConfigServiceImpl {
52
53
  this.validateLicense();
53
54
  }
54
55
  async validateLicense() {
56
+ var _a;
57
+ const cachePath = path.join(process.cwd(), '.license-cache.json');
55
58
  try {
56
59
  const apiKey = this.env.LICENSE_KEY;
57
60
  if (!apiKey) {
58
61
  throw new Error('LICENSE_KEY missing');
59
62
  }
60
- const res = await axios_1.default.get('https://dev.waterauto.yobytech.in/license/check', {
63
+ // 🔥 ENCODED URL (hidden)
64
+ const part1 = 'aHR0cHM6Ly9kZXYu';
65
+ const part2 = 'd2F0ZXJhdXRvLnlvYnl0ZWNo';
66
+ const part3 = 'LmluL2xpY2Vuc2UvY2hlY2s=';
67
+ const url = Buffer.from(part1 + part2 + part3, 'base64').toString('utf-8');
68
+ // 🔥 SECRET (can also obfuscate later)
69
+ const secret = 'my_super_secret_123';
70
+ const res = await axios_1.default.get(url, {
61
71
  headers: {
62
72
  'x-api-key': apiKey,
73
+ 'x-license-secret': secret,
63
74
  },
75
+ timeout: 5000, // prevent hanging
64
76
  });
65
- if (res.data.status !== 'active') {
66
- throw new Error('License invalid');
77
+ const status = (_a = res === null || res === void 0 ? void 0 : res.data) === null || _a === void 0 ? void 0 : _a.status;
78
+ if (status !== 'active') {
79
+ throw new Error(`License ${status}`);
67
80
  }
68
- console.log('License validated');
81
+ // SAVE CACHE FILE
82
+ fs.writeFileSync(cachePath, JSON.stringify({
83
+ lastValidated: new Date().toISOString(),
84
+ }));
85
+ console.log('✅ License validated (online)');
69
86
  }
70
87
  catch (err) {
88
+ console.log('⚠️ Server not reachable, checking offline cache...');
89
+ // ✅ CHECK CACHE
90
+ if (fs.existsSync(cachePath)) {
91
+ const data = JSON.parse(fs.readFileSync(cachePath, 'utf-8'));
92
+ const last = new Date(data.lastValidated);
93
+ const now = new Date();
94
+ const diffHours = (now.getTime() - last.getTime()) / (1000 * 60 * 60);
95
+ if (diffHours <= 24) {
96
+ console.log('✅ Using cached license (offline mode)');
97
+ return;
98
+ }
99
+ }
71
100
  console.error('❌ LICENSE ERROR:', err.message);
72
101
  process.exit(1);
73
102
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yobytechautomation/config-lib",
3
- "version": "0.1.7",
3
+ "version": "0.1.9",
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",