@alacard-project/config-sdk 1.0.0 → 1.0.3
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.
- package/dist/config-client.d.ts +0 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/nest-helpers.d.ts +16 -0
- package/dist/nest-helpers.js +57 -0
- package/package.json +11 -6
- package/src/config-client.ts +0 -2
- package/src/index.ts +2 -0
- package/src/nest-helpers.ts +63 -0
- package/.idea/workspace.xml +0 -45
package/dist/config-client.d.ts
CHANGED
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -15,3 +15,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./config-client"), exports);
|
|
18
|
+
__exportStar(require("./vault-client"), exports);
|
|
19
|
+
__exportStar(require("./nest-helpers"), exports);
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Environment } from '@alacard-project/shared';
|
|
2
|
+
export declare abstract class BaseConfigService {
|
|
3
|
+
protected readonly configService: any;
|
|
4
|
+
private remoteConfig;
|
|
5
|
+
constructor(configService: any);
|
|
6
|
+
setRemoteConfig(config: Record<string, string>): void;
|
|
7
|
+
protected get<T = string>(key: string, defaultValue?: T): T;
|
|
8
|
+
protected getRequiredString(key: string): string;
|
|
9
|
+
protected getRequiredNumber(key: string): number;
|
|
10
|
+
protected getOptionalString(key: string, defaultValue: string): string;
|
|
11
|
+
protected getOptionalNumber(key: string, defaultValue: number): number;
|
|
12
|
+
get environment(): Environment;
|
|
13
|
+
get databaseUrl(): string;
|
|
14
|
+
get kafkaBrokers(): string[];
|
|
15
|
+
get isProduction(): boolean;
|
|
16
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BaseConfigService = void 0;
|
|
4
|
+
const shared_1 = require("@alacard-project/shared");
|
|
5
|
+
// Note: This requires @nestjs/config to be installed in the consumer microservice
|
|
6
|
+
// We keep it in the SDK as a helper for NestJS-based microservices.
|
|
7
|
+
class BaseConfigService {
|
|
8
|
+
configService;
|
|
9
|
+
remoteConfig = {};
|
|
10
|
+
constructor(configService) {
|
|
11
|
+
this.configService = configService;
|
|
12
|
+
}
|
|
13
|
+
setRemoteConfig(config) {
|
|
14
|
+
this.remoteConfig = { ...this.remoteConfig, ...config };
|
|
15
|
+
}
|
|
16
|
+
get(key, defaultValue) {
|
|
17
|
+
if (this.remoteConfig[key] !== undefined) {
|
|
18
|
+
return this.remoteConfig[key];
|
|
19
|
+
}
|
|
20
|
+
return this.configService.get(key, defaultValue);
|
|
21
|
+
}
|
|
22
|
+
getRequiredString(key) {
|
|
23
|
+
const value = this.get(key);
|
|
24
|
+
if (!value && process.env.NODE_ENV !== shared_1.Environment.TEST) {
|
|
25
|
+
throw new Error(`Configuration Error: ${key} is required`);
|
|
26
|
+
}
|
|
27
|
+
return value || '';
|
|
28
|
+
}
|
|
29
|
+
getRequiredNumber(key) {
|
|
30
|
+
const value = this.get(key);
|
|
31
|
+
if (!value && process.env.NODE_ENV !== shared_1.Environment.TEST) {
|
|
32
|
+
throw new Error(`Configuration Error: ${key} is required`);
|
|
33
|
+
}
|
|
34
|
+
return parseInt(value || '0', 10);
|
|
35
|
+
}
|
|
36
|
+
getOptionalString(key, defaultValue) {
|
|
37
|
+
return this.get(key, defaultValue) || defaultValue;
|
|
38
|
+
}
|
|
39
|
+
getOptionalNumber(key, defaultValue) {
|
|
40
|
+
const value = this.get(key);
|
|
41
|
+
return value ? parseInt(value, 10) : defaultValue;
|
|
42
|
+
}
|
|
43
|
+
get environment() {
|
|
44
|
+
return this.get('NODE_ENV', shared_1.Environment.DEVELOPMENT) || shared_1.Environment.DEVELOPMENT;
|
|
45
|
+
}
|
|
46
|
+
get databaseUrl() {
|
|
47
|
+
return this.getRequiredString('DATABASE_URL');
|
|
48
|
+
}
|
|
49
|
+
get kafkaBrokers() {
|
|
50
|
+
const brokers = this.get('KAFKA_BROKERS', 'localhost:9092');
|
|
51
|
+
return (brokers || 'localhost:9092').split(',');
|
|
52
|
+
}
|
|
53
|
+
get isProduction() {
|
|
54
|
+
return this.environment === shared_1.Environment.PRODUCTION;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
exports.BaseConfigService = BaseConfigService;
|
package/package.json
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alacard-project/config-sdk",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
|
+
"engines": {
|
|
5
|
+
"node": ">=24.0.0"
|
|
6
|
+
},
|
|
4
7
|
"private": false,
|
|
5
8
|
"description": "Standalone gRPC-based Configuration SDK for Alacard microservices",
|
|
6
9
|
"main": "dist/index.js",
|
|
@@ -11,15 +14,17 @@
|
|
|
11
14
|
"prepublishOnly": "npm run build"
|
|
12
15
|
},
|
|
13
16
|
"dependencies": {
|
|
17
|
+
"@alacard-project/shared": "^1.0.4",
|
|
18
|
+
"@bufbuild/protobuf": "^2.11.0",
|
|
14
19
|
"@grpc/grpc-js": "^1.14.3",
|
|
15
20
|
"@grpc/proto-loader": "^0.8.0",
|
|
16
|
-
"
|
|
21
|
+
"axios": "^1.7.9",
|
|
17
22
|
"dotenv": "^16.4.6",
|
|
18
|
-
"
|
|
23
|
+
"kafkajs": "^2.2.4"
|
|
19
24
|
},
|
|
20
25
|
"devDependencies": {
|
|
21
|
-
"
|
|
22
|
-
"
|
|
23
|
-
"
|
|
26
|
+
"@types/node": "^24.10.0",
|
|
27
|
+
"ts-proto": "^2.6.1",
|
|
28
|
+
"typescript": "^5.9.3"
|
|
24
29
|
}
|
|
25
30
|
}
|
package/src/config-client.ts
CHANGED
|
@@ -6,8 +6,6 @@ import { ConfigServiceClient } from './proto/config';
|
|
|
6
6
|
import { GetConfigRequest } from './proto/config';
|
|
7
7
|
import { VaultClient, VaultOptions } from './vault-client';
|
|
8
8
|
|
|
9
|
-
export { VaultOptions };
|
|
10
|
-
|
|
11
9
|
export interface ConfigOptions {
|
|
12
10
|
serviceName: string;
|
|
13
11
|
environment: string;
|
package/src/index.ts
CHANGED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { Environment } from '@alacard-project/shared';
|
|
2
|
+
|
|
3
|
+
// Note: This requires @nestjs/config to be installed in the consumer microservice
|
|
4
|
+
// We keep it in the SDK as a helper for NestJS-based microservices.
|
|
5
|
+
|
|
6
|
+
export abstract class BaseConfigService {
|
|
7
|
+
private remoteConfig: Record<string, string> = {};
|
|
8
|
+
|
|
9
|
+
constructor(protected readonly configService: any) { }
|
|
10
|
+
|
|
11
|
+
setRemoteConfig(config: Record<string, string>) {
|
|
12
|
+
this.remoteConfig = { ...this.remoteConfig, ...config };
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
protected get<T = string>(key: string, defaultValue?: T): T {
|
|
16
|
+
if (this.remoteConfig[key] !== undefined) {
|
|
17
|
+
return this.remoteConfig[key] as unknown as T;
|
|
18
|
+
}
|
|
19
|
+
return this.configService.get(key, defaultValue);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
protected getRequiredString(key: string): string {
|
|
23
|
+
const value = this.get<string>(key);
|
|
24
|
+
if (!value && process.env.NODE_ENV !== Environment.TEST) {
|
|
25
|
+
throw new Error(`Configuration Error: ${key} is required`);
|
|
26
|
+
}
|
|
27
|
+
return value || '';
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
protected getRequiredNumber(key: string): number {
|
|
31
|
+
const value = this.get<string>(key);
|
|
32
|
+
if (!value && process.env.NODE_ENV !== Environment.TEST) {
|
|
33
|
+
throw new Error(`Configuration Error: ${key} is required`);
|
|
34
|
+
}
|
|
35
|
+
return parseInt(value || '0', 10);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
protected getOptionalString(key: string, defaultValue: string): string {
|
|
39
|
+
return this.get<string>(key, defaultValue) || defaultValue;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
protected getOptionalNumber(key: string, defaultValue: number): number {
|
|
43
|
+
const value = this.get<string>(key);
|
|
44
|
+
return value ? parseInt(value, 10) : defaultValue;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
get environment(): Environment {
|
|
48
|
+
return this.get<Environment>('NODE_ENV', Environment.DEVELOPMENT) || Environment.DEVELOPMENT;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
get databaseUrl(): string {
|
|
52
|
+
return this.getRequiredString('DATABASE_URL');
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
get kafkaBrokers(): string[] {
|
|
56
|
+
const brokers = this.get<string>('KAFKA_BROKERS', 'localhost:9092');
|
|
57
|
+
return (brokers || 'localhost:9092').split(',');
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
get isProduction(): boolean {
|
|
61
|
+
return this.environment === Environment.PRODUCTION;
|
|
62
|
+
}
|
|
63
|
+
}
|
package/.idea/workspace.xml
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
-
<project version="4">
|
|
3
|
-
<component name="ChangeListManager">
|
|
4
|
-
<list default="true" id="d6ddd62d-b258-48c7-8ac2-ae28e47081ad" name="Changes" comment="" />
|
|
5
|
-
<option name="SHOW_DIALOG" value="false" />
|
|
6
|
-
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
|
7
|
-
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
|
|
8
|
-
<option name="LAST_RESOLUTION" value="IGNORE" />
|
|
9
|
-
</component>
|
|
10
|
-
<component name="MarkdownSettingsMigration">
|
|
11
|
-
<option name="stateVersion" value="1" />
|
|
12
|
-
</component>
|
|
13
|
-
<component name="ProjectId" id="38cLw1hfbaQQ7IG2qhtRfg4zBzC" />
|
|
14
|
-
<component name="ProjectViewState">
|
|
15
|
-
<option name="hideEmptyMiddlePackages" value="true" />
|
|
16
|
-
<option name="showLibraryContents" value="true" />
|
|
17
|
-
</component>
|
|
18
|
-
<component name="PropertiesComponent"><![CDATA[{
|
|
19
|
-
"keyToString": {
|
|
20
|
-
"RunOnceActivity.ShowReadmeOnStart": "true",
|
|
21
|
-
"WebServerToolWindowFactoryState": "false",
|
|
22
|
-
"node.js.detected.package.eslint": "true",
|
|
23
|
-
"node.js.detected.package.tslint": "true",
|
|
24
|
-
"node.js.selected.package.eslint": "(autodetect)",
|
|
25
|
-
"node.js.selected.package.tslint": "(autodetect)",
|
|
26
|
-
"nodejs_package_manager_path": "npm",
|
|
27
|
-
"vue.rearranger.settings.migration": "true"
|
|
28
|
-
}
|
|
29
|
-
}]]></component>
|
|
30
|
-
<component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" />
|
|
31
|
-
<component name="TaskManager">
|
|
32
|
-
<task active="true" id="Default" summary="Default task">
|
|
33
|
-
<changelist id="d6ddd62d-b258-48c7-8ac2-ae28e47081ad" name="Changes" comment="" />
|
|
34
|
-
<created>1769094147893</created>
|
|
35
|
-
<option name="number" value="Default" />
|
|
36
|
-
<option name="presentableId" value="Default" />
|
|
37
|
-
<updated>1769094147893</updated>
|
|
38
|
-
<workItem from="1769094150802" duration="320000" />
|
|
39
|
-
</task>
|
|
40
|
-
<servers />
|
|
41
|
-
</component>
|
|
42
|
-
<component name="TypeScriptGeneratedFilesManager">
|
|
43
|
-
<option name="version" value="3" />
|
|
44
|
-
</component>
|
|
45
|
-
</project>
|