@yobytechautomation/config-lib 0.2.0 → 0.2.1

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