@yobytechautomation/config-lib 0.2.0 → 0.2.2

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.
@@ -57,21 +57,65 @@ export interface BaseConfigService {
57
57
  };
58
58
  };
59
59
  }
60
- /**
61
- * 🔥 BASE IMPLEMENTATION (LICENSE CONTROL)
62
- */
63
60
  export declare abstract class BaseConfigServiceImpl implements BaseConfigService {
64
61
  protected env: Record<string, any>;
65
62
  constructor();
66
- private validateLicense;
67
- abstract getDatabaseConfig(): TypeOrmModuleOptions;
68
- abstract getPort(): number;
69
- abstract getMode(): string;
70
- abstract getConsulConfig(): any;
71
- abstract getRedisConfig(): any;
72
- abstract getJWTConfig(): any;
73
- abstract getJUtilConfig(): any;
74
- abstract getMailConfig(): any;
75
- abstract getKAFKAConfig(): any;
63
+ getDatabaseConfig(): TypeOrmModuleOptions;
64
+ getPort(): number;
65
+ getMode(): string;
66
+ getConsulConfig(): {
67
+ host: string;
68
+ port: number;
69
+ secure: boolean;
70
+ serviceName: string;
71
+ serviceHost: string;
72
+ servicePort: number;
73
+ };
74
+ getRedisConfig(): {
75
+ host: string;
76
+ port: number;
77
+ password?: string;
78
+ username?: string;
79
+ db?: number;
80
+ };
81
+ getJWTConfig(): {
82
+ accessTokenSecret: string;
83
+ accessTokenExpIn: number;
84
+ refreshTokenSecret: string;
85
+ refreshTokenExpIn: number;
86
+ };
87
+ getJUtilConfig(): {
88
+ accessLogMaxAgeDays: number;
89
+ accessLogMaxSizeMb: number;
90
+ authServiceUrl: string;
91
+ };
92
+ getMailConfig(): {
93
+ mailPort: number;
94
+ mailSecure: string;
95
+ mailHost: string;
96
+ mailUser: string;
97
+ mailPass: string;
98
+ mailFrom: string;
99
+ mailDir: string;
100
+ mailOrigin: string;
101
+ };
102
+ getKAFKAConfig(): {
103
+ clientId: string;
104
+ brokers: string[];
105
+ groupId: string;
106
+ topicName: string;
107
+ ssl?: {
108
+ rejectUnauthorized: boolean;
109
+ ca?: string;
110
+ cert?: string;
111
+ key?: string;
112
+ };
113
+ sasl?: {
114
+ mechanism: string;
115
+ username: string;
116
+ password: string;
117
+ };
118
+ };
119
+ validateLicenseOrThrow(): Promise<void>;
76
120
  }
77
121
  export declare const BASE_CONFIG_SERVICE: unique symbol;
@@ -38,67 +38,82 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
38
38
  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
- const dotenv = __importStar(require("dotenv"));
42
41
  const fs = __importStar(require("fs"));
43
42
  const path = __importStar(require("path"));
44
- // 🔥 LOAD ENV FILE FIRST (VERY IMPORTANT)
45
- dotenv.config({ path: process.env.ENV_FILE || '.env.local' });
46
- /**
47
- * 🔥 BASE IMPLEMENTATION (LICENSE CONTROL)
48
- */
49
43
  class BaseConfigServiceImpl {
50
44
  constructor() {
51
- // 🔥 reload env AFTER dotenv
52
45
  this.env = process.env;
53
- this.validateLicense();
54
46
  }
55
- async validateLicense() {
47
+ getDatabaseConfig() {
48
+ throw new Error('Method not implemented.');
49
+ }
50
+ getPort() {
51
+ throw new Error('Method not implemented.');
52
+ }
53
+ getMode() {
54
+ throw new Error('Method not implemented.');
55
+ }
56
+ getConsulConfig() {
57
+ throw new Error('Method not implemented.');
58
+ }
59
+ getRedisConfig() {
60
+ throw new Error('Method not implemented.');
61
+ }
62
+ getJWTConfig() {
63
+ throw new Error('Method not implemented.');
64
+ }
65
+ getJUtilConfig() {
66
+ throw new Error('Method not implemented.');
67
+ }
68
+ getMailConfig() {
69
+ throw new Error('Method not implemented.');
70
+ }
71
+ getKAFKAConfig() {
72
+ throw new Error('Method not implemented.');
73
+ }
74
+ async validateLicenseOrThrow() {
56
75
  var _a;
57
76
  const cachePath = path.join(process.cwd(), '.license-cache.json');
77
+ const apiKey = this.env.LICENSE_KEY;
78
+ if (!apiKey || apiKey.length < 10) {
79
+ throw new Error('LICENSE_KEY missing');
80
+ }
58
81
  try {
59
- const apiKey = this.env.LICENSE_KEY;
60
- if (!apiKey || apiKey.length < 10) {
61
- throw new Error('LICENSE_KEY missing');
62
- }
63
- // 🔥 ENCODED URL (hidden)
64
82
  const part1 = 'aHR0cHM6Ly9kZXYu';
65
83
  const part2 = 'd2F0ZXJhdXRvLnlvYnl0ZWNo';
66
84
  const part3 = 'LmluL2xpY2Vuc2UvY2hlY2s=';
67
85
  const url = Buffer.from(part1 + part2 + part3, 'base64').toString('utf-8');
68
- // 🔥 SECRET (can also obfuscate later)
69
86
  const secret = 'my_super_secret_123';
70
87
  const res = await axios_1.default.get(url, {
71
88
  headers: {
72
89
  'x-api-key': apiKey,
73
90
  'x-license-secret': secret,
74
91
  },
75
- timeout: 5000, // prevent hanging
92
+ timeout: 5000,
76
93
  });
77
94
  const status = (_a = res === null || res === void 0 ? void 0 : res.data) === null || _a === void 0 ? void 0 : _a.status;
78
95
  if (status !== 'active') {
79
96
  throw new Error(`License ${status}. Please contact vendor.`);
80
97
  }
81
- // ✅ SAVE CACHE FILE
98
+ // ✅ SAVE CACHE
82
99
  fs.writeFileSync(cachePath, JSON.stringify({
83
100
  lastValidated: new Date().toISOString(),
84
101
  }));
85
102
  console.log('✅ License validated (online)');
86
103
  }
87
104
  catch (err) {
88
- console.log('⚠️ Server not reachable, checking offline cache...');
89
- // ✅ CHECK CACHE
105
+ console.log('⚠️ Server not reachable, checking cache...');
90
106
  if (fs.existsSync(cachePath)) {
91
107
  const data = JSON.parse(fs.readFileSync(cachePath, 'utf-8'));
92
108
  const last = new Date(data.lastValidated);
93
109
  const now = new Date();
94
110
  const diffHours = (now.getTime() - last.getTime()) / (1000 * 60 * 60);
95
111
  if (diffHours <= 24) {
96
- console.log('✅ Using cached license (offline mode)');
112
+ console.log('✅ Using cached license (offline)');
97
113
  return;
98
114
  }
99
115
  }
100
- console.error(' LICENSE ERROR:', err.message);
101
- process.exit(1);
116
+ throw new Error(err.message || 'License validation failed');
102
117
  }
103
118
  }
104
119
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yobytechautomation/config-lib",
3
- "version": "0.2.0",
3
+ "version": "0.2.2",
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",