@be-link/shield-for-tcb-node-sdk 1.0.7 → 1.0.8
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/README.md +6 -104
- package/index.d.ts +0 -2
- package/index.js +1 -6
- package/modules/BaseService.d.ts +0 -6
- package/modules/BaseService.js +4 -20
- package/package.json +1 -1
- package/utils/http.d.ts +0 -7
- package/utils/http.js +0 -31
- package/modules/config/serviceV2.d.ts +0 -58
- package/modules/config/serviceV2.js +0 -107
- package/modules/config/typesV2.d.ts +0 -106
- package/modules/config/typesV2.js +0 -2
package/README.md
CHANGED
|
@@ -10,96 +10,7 @@ npm install @be-link/shield-for-tcb-node-sdk
|
|
|
10
10
|
pnpm add @be-link/shield-for-tcb-node-sdk
|
|
11
11
|
```
|
|
12
12
|
|
|
13
|
-
##
|
|
14
|
-
|
|
15
|
-
V2 SDK 从 MySQL 数据源读取配置,支持按 service + key 获取配置,并提供自动类型解析。
|
|
16
|
-
|
|
17
|
-
### 基本使用
|
|
18
|
-
|
|
19
|
-
```typescript
|
|
20
|
-
import { backendConfigServiceV2 } from '@be-link/shield-for-tcb-node-sdk'
|
|
21
|
-
```
|
|
22
|
-
|
|
23
|
-
### 获取服务列表
|
|
24
|
-
|
|
25
|
-
```typescript
|
|
26
|
-
const services = await backendConfigServiceV2.getServices('local')
|
|
27
|
-
// 返回: ['BackendUser', 'Trade', 'User', ...]
|
|
28
|
-
```
|
|
29
|
-
|
|
30
|
-
### 获取服务的配置键列表
|
|
31
|
-
|
|
32
|
-
```typescript
|
|
33
|
-
const keys = await backendConfigServiceV2.getServiceKeys('TestService', 'local')
|
|
34
|
-
// 返回: ['TestServiceKey1', 'TestServiceKey2', 'TestServiceKey3', ...]
|
|
35
|
-
```
|
|
36
|
-
|
|
37
|
-
### 获取单个配置
|
|
38
|
-
|
|
39
|
-
```typescript
|
|
40
|
-
// 原始格式(包含元数据)
|
|
41
|
-
const config = await backendConfigServiceV2.fetchConfig({
|
|
42
|
-
service: 'TestService',
|
|
43
|
-
key: 'TestServiceKey1',
|
|
44
|
-
env: 'local'
|
|
45
|
-
})
|
|
46
|
-
// 返回: { config_key: 'TestServiceKey1', value: 'xxx', value_type: 'string', updated_at: '...' }
|
|
47
|
-
|
|
48
|
-
// 自动解析类型(推荐)
|
|
49
|
-
const host = await backendConfigServiceV2.getConfigValue<string>('TestService', 'TestServiceKey1', 'local')
|
|
50
|
-
// 返回: '127.0.0.1'
|
|
51
|
-
|
|
52
|
-
const port = await backendConfigServiceV2.getConfigValue<number>('TestService', 'TestServiceKey1', 'local')
|
|
53
|
-
// 返回: 1234(自动解析为数字)
|
|
54
|
-
|
|
55
|
-
const enabled = await backendConfigServiceV2.getConfigValue<boolean>('TestService', 'TestServiceKey1', 'local')
|
|
56
|
-
// 返回: true/false(自动解析为布尔值)
|
|
57
|
-
|
|
58
|
-
const jsonConfig = await backendConfigServiceV2.getConfigValue<object>('BackendUser', 'TestServiceKey1', 'local')
|
|
59
|
-
// 返回: { ... }(自动 JSON 解析)
|
|
60
|
-
```
|
|
61
|
-
|
|
62
|
-
### 批量获取配置
|
|
63
|
-
|
|
64
|
-
```typescript
|
|
65
|
-
// 原始格式
|
|
66
|
-
const configs = await backendConfigServiceV2.fetchConfigs({
|
|
67
|
-
service: 'TestService',
|
|
68
|
-
keys: ['TestServiceKey1', 'TestServiceKey2'],
|
|
69
|
-
env: 'local'
|
|
70
|
-
})
|
|
71
|
-
// 返回: { 'TestServiceKey1': { value: 'xxx', value_type: 'string' }, ... }
|
|
72
|
-
|
|
73
|
-
// 自动解析类型(推荐)
|
|
74
|
-
const values = await backendConfigServiceV2.getConfigValues(
|
|
75
|
-
'TestService',
|
|
76
|
-
['TestServiceKey1', 'TestServiceKey2', 'TestServiceKey3'],
|
|
77
|
-
'local'
|
|
78
|
-
)
|
|
79
|
-
// 返回: {
|
|
80
|
-
// }
|
|
81
|
-
```
|
|
82
|
-
|
|
83
|
-
### 环境变量
|
|
84
|
-
|
|
85
|
-
| 变量名 | 说明 | 示例 |
|
|
86
|
-
|--------|------|------|
|
|
87
|
-
| `SHIELD_SDK_HOST` | 覆盖 SDK 请求地址(本地开发用) | `http://localhost:8090` |
|
|
88
|
-
| `CONTAINER_ENV` | 容器环境,默认 `SCF`(云函数),设置为其他值使用内网地址 | `ECS` |
|
|
89
|
-
| `NODE_ENV` | 环境标识,`prod` 使用生产环境地址 | `local` / `ppe` / `prod` |
|
|
90
|
-
|
|
91
|
-
### 本地开发
|
|
92
|
-
|
|
93
|
-
```bash
|
|
94
|
-
# 设置本地服务地址
|
|
95
|
-
export SHIELD_SDK_HOST=http://localhost:8090
|
|
96
|
-
```
|
|
97
|
-
|
|
98
|
-
---
|
|
99
|
-
|
|
100
|
-
## V1 SDK(旧版)
|
|
101
|
-
|
|
102
|
-
V1 SDK 从 YAML 文件读取配置,保持向后兼容。
|
|
13
|
+
## 使用
|
|
103
14
|
|
|
104
15
|
```typescript
|
|
105
16
|
import { backendConfigService, frontendConfigService } from '@be-link/shield-for-tcb-node-sdk'
|
|
@@ -110,21 +21,12 @@ const config = await backendConfigService.fetchConfig({ key: 'your-key', type: '
|
|
|
110
21
|
// 前端使用(跳过异常处理,直接抛出原始错误)
|
|
111
22
|
const frontendConfig = await frontendConfigService.fetchConfig({ key: 'your-key', type: 'json' })
|
|
112
23
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
---
|
|
24
|
+
// 获取全局动态配置
|
|
25
|
+
const globalConfig = await backendConfigService.fetchGlobalDynamicConfig()
|
|
116
26
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|------|--------|--------|
|
|
121
|
-
| 数据源 | YAML 文件 | MySQL |
|
|
122
|
-
| 获取方式 | 按 key | 按 service + key |
|
|
123
|
-
| 类型解析 | 手动指定 type | 自动根据 value_type 解析 |
|
|
124
|
-
| 批量获取 | ❌ | ✅ |
|
|
125
|
-
| 配置管理 | ❌ | ✅(通过管理后台) |
|
|
126
|
-
| 版本追踪 | ❌ | ✅ |
|
|
127
|
-
| 审计日志 | ❌ | ✅ |
|
|
27
|
+
// 获取 COS 临时密钥
|
|
28
|
+
const cosTempSecret = await backendConfigService.getCosTempSecret()
|
|
29
|
+
```
|
|
128
30
|
|
|
129
31
|
## 发布流程
|
|
130
32
|
|
package/index.d.ts
CHANGED
|
@@ -1,4 +1,2 @@
|
|
|
1
1
|
export { backendConfigService } from './modules/config/service';
|
|
2
2
|
export type { Service as ConfigControllerTypes } from './modules/config/types';
|
|
3
|
-
export { backendConfigServiceV2, ConfigServiceV2 } from './modules/config/serviceV2';
|
|
4
|
-
export type { ServiceV2 as ConfigControllerTypesV2 } from './modules/config/typesV2';
|
package/index.js
CHANGED
|
@@ -1,10 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
// V1 SDK (YAML 数据源)
|
|
3
|
+
exports.backendConfigService = void 0;
|
|
5
4
|
var service_1 = require("./modules/config/service");
|
|
6
5
|
Object.defineProperty(exports, "backendConfigService", { enumerable: true, get: function () { return service_1.backendConfigService; } });
|
|
7
|
-
// V2 SDK (MySQL 数据源)
|
|
8
|
-
var serviceV2_1 = require("./modules/config/serviceV2");
|
|
9
|
-
Object.defineProperty(exports, "backendConfigServiceV2", { enumerable: true, get: function () { return serviceV2_1.backendConfigServiceV2; } });
|
|
10
|
-
Object.defineProperty(exports, "ConfigServiceV2", { enumerable: true, get: function () { return serviceV2_1.ConfigServiceV2; } });
|
package/modules/BaseService.d.ts
CHANGED
|
@@ -9,12 +9,6 @@ export default abstract class BaseService {
|
|
|
9
9
|
protected readonly publicDevHost = "https://ecommerce-dev.wejourney.top";
|
|
10
10
|
protected readonly publicProdHost = "https://ecommerce-release.wejourney.top";
|
|
11
11
|
constructor();
|
|
12
|
-
/** 获取 Host */
|
|
13
|
-
protected getHost(): string;
|
|
14
|
-
/** 获取 Host (V2,支持环境变量覆盖) */
|
|
15
|
-
protected getHostV2(): string;
|
|
16
12
|
/** 获取API URL */
|
|
17
13
|
protected getApiUrl(func: Function): string;
|
|
18
|
-
/** 获取API URL (V2,支持环境变量覆盖) */
|
|
19
|
-
protected getApiUrlV2(path: string): string;
|
|
20
14
|
}
|
package/modules/BaseService.js
CHANGED
|
@@ -16,32 +16,16 @@ class BaseService {
|
|
|
16
16
|
/** 如果是云函数环境, 默认走公网访问 */
|
|
17
17
|
this.isPublicEnv = (process.env.CONTAINER_ENV || 'SCF') === 'SCF';
|
|
18
18
|
}
|
|
19
|
-
/** 获取
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
/** 获取API URL */
|
|
20
|
+
getApiUrl(func) {
|
|
21
|
+
const host = this.isPublicEnv
|
|
22
22
|
? env_1.default.isProduction()
|
|
23
23
|
? this.publicProdHost
|
|
24
24
|
: this.publicDevHost
|
|
25
25
|
: env_1.default.isProduction()
|
|
26
26
|
? this.natProdHost
|
|
27
27
|
: this.natDevHost;
|
|
28
|
-
|
|
29
|
-
/** 获取 Host (V2,支持环境变量覆盖) */
|
|
30
|
-
getHostV2() {
|
|
31
|
-
// 支持通过环境变量覆盖 host(用于本地测试)
|
|
32
|
-
const overrideHost = process.env.SHIELD_SDK_HOST;
|
|
33
|
-
if (overrideHost) {
|
|
34
|
-
return overrideHost;
|
|
35
|
-
}
|
|
36
|
-
return this.getHost();
|
|
37
|
-
}
|
|
38
|
-
/** 获取API URL */
|
|
39
|
-
getApiUrl(func) {
|
|
40
|
-
return `${this.getHost()}${this.prefixUrl}/${(0, string_1.camelToKebabCase)(func.name)}`;
|
|
41
|
-
}
|
|
42
|
-
/** 获取API URL (V2,支持环境变量覆盖) */
|
|
43
|
-
getApiUrlV2(path) {
|
|
44
|
-
return `${this.getHostV2()}${this.prefixUrl}${path}`;
|
|
28
|
+
return `${host}${this.prefixUrl}/${(0, string_1.camelToKebabCase)(func.name)}`;
|
|
45
29
|
}
|
|
46
30
|
}
|
|
47
31
|
exports.default = BaseService;
|
package/package.json
CHANGED
package/utils/http.d.ts
CHANGED
|
@@ -1,12 +1,5 @@
|
|
|
1
1
|
type CallApiOptions = {
|
|
2
2
|
skipErrorHandling?: boolean;
|
|
3
3
|
};
|
|
4
|
-
type GetApiOptions = {
|
|
5
|
-
skipErrorHandling?: boolean;
|
|
6
|
-
};
|
|
7
4
|
export declare function callApi<T extends (args: any) => Promise<any>>(url: string, request?: Parameters<T>[0], options?: CallApiOptions): Promise<Awaited<ReturnType<T>>>;
|
|
8
|
-
/**
|
|
9
|
-
* GET 请求 API
|
|
10
|
-
*/
|
|
11
|
-
export declare function getApi<T extends (args: any) => Promise<any>>(url: string, options?: GetApiOptions): Promise<Awaited<ReturnType<T>>>;
|
|
12
5
|
export {};
|
package/utils/http.js
CHANGED
|
@@ -37,7 +37,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
37
37
|
};
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
39
|
exports.callApi = callApi;
|
|
40
|
-
exports.getApi = getApi;
|
|
41
40
|
const axios_1 = __importDefault(require("axios"));
|
|
42
41
|
const uuid_1 = require("uuid");
|
|
43
42
|
const axios_retry_1 = __importDefault(require("axios-retry"));
|
|
@@ -100,33 +99,3 @@ async function callApi(url, request, options) {
|
|
|
100
99
|
throw error;
|
|
101
100
|
}
|
|
102
101
|
}
|
|
103
|
-
/**
|
|
104
|
-
* GET 请求 API
|
|
105
|
-
*/
|
|
106
|
-
async function getApi(url, options) {
|
|
107
|
-
const requestId = (0, uuid_1.v4)();
|
|
108
|
-
try {
|
|
109
|
-
console.info(`准备发起shield-for-tcb GET请求[${requestId}]: ${url}`);
|
|
110
|
-
const response = await axios_1.default.get(url, {
|
|
111
|
-
headers: { 'x-request-id': requestId, 'content-type': 'application/json' },
|
|
112
|
-
});
|
|
113
|
-
const responseData = response.data;
|
|
114
|
-
return responseData.data;
|
|
115
|
-
}
|
|
116
|
-
catch (error) {
|
|
117
|
-
if (options?.skipErrorHandling) {
|
|
118
|
-
throw error;
|
|
119
|
-
}
|
|
120
|
-
const axiosError = error;
|
|
121
|
-
if (axiosError.response) {
|
|
122
|
-
const response = axiosError.response;
|
|
123
|
-
const data = response.data;
|
|
124
|
-
console.error(`shield-for-tcb GET异常: ${axiosError.message}, requestId: ${requestId}`);
|
|
125
|
-
console.info('响应信息', data.message);
|
|
126
|
-
console.error('异常堆栈', JSON.stringify(error.stack));
|
|
127
|
-
throw axiosError;
|
|
128
|
-
}
|
|
129
|
-
console.error(`shield-for-tcb GET未知异常: ${axiosError.message}`, error.stack);
|
|
130
|
-
throw error;
|
|
131
|
-
}
|
|
132
|
-
}
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import { ServiceV2 } from './typesV2';
|
|
2
|
-
import BaseService from '../BaseService';
|
|
3
|
-
/**
|
|
4
|
-
* V2 配置服务
|
|
5
|
-
* 从 MySQL 数据源读取配置,支持按 service + key 获取
|
|
6
|
-
*/
|
|
7
|
-
export declare class ConfigServiceV2 extends BaseService implements ServiceV2.ConfigController {
|
|
8
|
-
protected prefixUrl: string;
|
|
9
|
-
/**
|
|
10
|
-
* 获取单个配置
|
|
11
|
-
* @param req 请求参数
|
|
12
|
-
* @returns 配置数据,如果配置不存在返回 null
|
|
13
|
-
*/
|
|
14
|
-
fetchConfig(req: ServiceV2.Request.FetchConfig): Promise<ServiceV2.Response.FetchConfigResponse | null>;
|
|
15
|
-
/**
|
|
16
|
-
* 批量获取配置
|
|
17
|
-
* @param req 请求参数
|
|
18
|
-
* @returns 配置数据映射
|
|
19
|
-
*/
|
|
20
|
-
fetchConfigs(req: ServiceV2.Request.FetchConfigs): Promise<ServiceV2.Response.FetchConfigsResponse>;
|
|
21
|
-
/**
|
|
22
|
-
* 获取所有服务列表
|
|
23
|
-
* @param env 环境名称(可选,默认使用当前环境)
|
|
24
|
-
* @returns 服务名称列表
|
|
25
|
-
*/
|
|
26
|
-
getServices(env?: string): Promise<ServiceV2.Response.GetServicesResponse>;
|
|
27
|
-
/**
|
|
28
|
-
* 获取指定服务的配置键列表
|
|
29
|
-
* @param serviceName 服务名称
|
|
30
|
-
* @param env 环境名称(可选,默认使用当前环境)
|
|
31
|
-
* @returns 配置键列表
|
|
32
|
-
*/
|
|
33
|
-
getServiceKeys(serviceName: string, env?: string): Promise<ServiceV2.Response.GetServiceKeysResponse>;
|
|
34
|
-
/**
|
|
35
|
-
* 获取配置值(自动解析类型)
|
|
36
|
-
* @param service 服务名称
|
|
37
|
-
* @param key 配置键
|
|
38
|
-
* @param env 环境(可选)
|
|
39
|
-
* @returns 解析后的配置值
|
|
40
|
-
*/
|
|
41
|
-
getConfigValue<T = any>(service: string, key: string, env?: string): Promise<T | null>;
|
|
42
|
-
/**
|
|
43
|
-
* 批量获取配置值
|
|
44
|
-
* @param service 服务名称
|
|
45
|
-
* @param keys 配置键列表(可选,不传则获取该服务所有配置)
|
|
46
|
-
* @param env 环境(可选)
|
|
47
|
-
* @returns 配置值映射(服务端已自动解析类型)
|
|
48
|
-
*/
|
|
49
|
-
getConfigValues<T = any>(service: string, keys?: string[], env?: string): Promise<Record<string, T>>;
|
|
50
|
-
/**
|
|
51
|
-
* 获取指定服务的所有配置
|
|
52
|
-
* @param service 服务名称
|
|
53
|
-
* @param env 环境(可选)
|
|
54
|
-
* @returns 该服务所有配置(Map<config_key, parsed_value> 格式)
|
|
55
|
-
*/
|
|
56
|
-
fetchAllConfigs<T = any>(service: string, env?: string): Promise<Record<string, T>>;
|
|
57
|
-
}
|
|
58
|
-
export declare const backendConfigServiceV2: ConfigServiceV2;
|
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.backendConfigServiceV2 = exports.ConfigServiceV2 = void 0;
|
|
7
|
-
const http_1 = require("../../utils/http");
|
|
8
|
-
const BaseService_1 = __importDefault(require("../BaseService"));
|
|
9
|
-
/**
|
|
10
|
-
* V2 配置服务
|
|
11
|
-
* 从 MySQL 数据源读取配置,支持按 service + key 获取
|
|
12
|
-
*/
|
|
13
|
-
class ConfigServiceV2 extends BaseService_1.default {
|
|
14
|
-
constructor() {
|
|
15
|
-
super(...arguments);
|
|
16
|
-
this.prefixUrl = '/shield/v2/config';
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* 获取单个配置
|
|
20
|
-
* @param req 请求参数
|
|
21
|
-
* @returns 配置数据,如果配置不存在返回 null
|
|
22
|
-
*/
|
|
23
|
-
fetchConfig(req) {
|
|
24
|
-
return (0, http_1.callApi)(this.getApiUrlV2('/fetch'), req, {
|
|
25
|
-
skipErrorHandling: true,
|
|
26
|
-
}).catch(() => null);
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* 批量获取配置
|
|
30
|
-
* @param req 请求参数
|
|
31
|
-
* @returns 配置数据映射
|
|
32
|
-
*/
|
|
33
|
-
fetchConfigs(req) {
|
|
34
|
-
return (0, http_1.callApi)(this.getApiUrlV2('/fetch-batch'), req).catch(() => ({}));
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* 获取所有服务列表
|
|
38
|
-
* @param env 环境名称(可选,默认使用当前环境)
|
|
39
|
-
* @returns 服务名称列表
|
|
40
|
-
*/
|
|
41
|
-
async getServices(env) {
|
|
42
|
-
const query = env ? `?env=${encodeURIComponent(env)}` : '';
|
|
43
|
-
return (0, http_1.getApi)(this.getApiUrlV2('/services') + query).catch(() => []);
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* 获取指定服务的配置键列表
|
|
47
|
-
* @param serviceName 服务名称
|
|
48
|
-
* @param env 环境名称(可选,默认使用当前环境)
|
|
49
|
-
* @returns 配置键列表
|
|
50
|
-
*/
|
|
51
|
-
async getServiceKeys(serviceName, env) {
|
|
52
|
-
const query = env ? `?env=${encodeURIComponent(env)}` : '';
|
|
53
|
-
return (0, http_1.getApi)(this.getApiUrlV2(`/services/${serviceName}/keys`) + query).catch(() => []);
|
|
54
|
-
}
|
|
55
|
-
/**
|
|
56
|
-
* 获取配置值(自动解析类型)
|
|
57
|
-
* @param service 服务名称
|
|
58
|
-
* @param key 配置键
|
|
59
|
-
* @param env 环境(可选)
|
|
60
|
-
* @returns 解析后的配置值
|
|
61
|
-
*/
|
|
62
|
-
async getConfigValue(service, key, env) {
|
|
63
|
-
const result = await this.fetchConfig({ service, key, env });
|
|
64
|
-
if (!result) {
|
|
65
|
-
return null;
|
|
66
|
-
}
|
|
67
|
-
// 根据类型解析值
|
|
68
|
-
switch (result.value_type) {
|
|
69
|
-
case 'number':
|
|
70
|
-
return Number(result.value);
|
|
71
|
-
case 'boolean':
|
|
72
|
-
return (result.value === 'true' || result.value === '1');
|
|
73
|
-
case 'object':
|
|
74
|
-
case 'array':
|
|
75
|
-
try {
|
|
76
|
-
return JSON.parse(result.value);
|
|
77
|
-
}
|
|
78
|
-
catch {
|
|
79
|
-
return result.value;
|
|
80
|
-
}
|
|
81
|
-
default:
|
|
82
|
-
return result.value;
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
/**
|
|
86
|
-
* 批量获取配置值
|
|
87
|
-
* @param service 服务名称
|
|
88
|
-
* @param keys 配置键列表(可选,不传则获取该服务所有配置)
|
|
89
|
-
* @param env 环境(可选)
|
|
90
|
-
* @returns 配置值映射(服务端已自动解析类型)
|
|
91
|
-
*/
|
|
92
|
-
async getConfigValues(service, keys, env) {
|
|
93
|
-
return this.fetchConfigs({ service, keys, env });
|
|
94
|
-
}
|
|
95
|
-
/**
|
|
96
|
-
* 获取指定服务的所有配置
|
|
97
|
-
* @param service 服务名称
|
|
98
|
-
* @param env 环境(可选)
|
|
99
|
-
* @returns 该服务所有配置(Map<config_key, parsed_value> 格式)
|
|
100
|
-
*/
|
|
101
|
-
async fetchAllConfigs(service, env) {
|
|
102
|
-
return this.fetchConfigs({ service, env });
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
exports.ConfigServiceV2 = ConfigServiceV2;
|
|
106
|
-
// 导出单例
|
|
107
|
-
exports.backendConfigServiceV2 = new ConfigServiceV2();
|
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
export declare namespace ServiceV2 {
|
|
2
|
-
namespace Entity {
|
|
3
|
-
/**
|
|
4
|
-
* 配置项
|
|
5
|
-
*/
|
|
6
|
-
interface ConfigItem {
|
|
7
|
-
config_key: string;
|
|
8
|
-
value: string;
|
|
9
|
-
value_type: 'string' | 'number' | 'boolean' | 'object' | 'array';
|
|
10
|
-
updated_at: string;
|
|
11
|
-
}
|
|
12
|
-
/**
|
|
13
|
-
* 批量配置项
|
|
14
|
-
*/
|
|
15
|
-
interface BatchConfigItem {
|
|
16
|
-
value: string;
|
|
17
|
-
value_type: 'string' | 'number' | 'boolean' | 'object' | 'array';
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
namespace Request {
|
|
21
|
-
/**
|
|
22
|
-
* 获取单个配置请求参数
|
|
23
|
-
*/
|
|
24
|
-
interface FetchConfig {
|
|
25
|
-
service: string;
|
|
26
|
-
key: string;
|
|
27
|
-
env?: string;
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* 批量获取配置请求参数
|
|
31
|
-
*/
|
|
32
|
-
interface FetchConfigs {
|
|
33
|
-
service: string;
|
|
34
|
-
keys?: string[];
|
|
35
|
-
env?: string;
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* 获取服务列表请求参数
|
|
39
|
-
*/
|
|
40
|
-
interface GetServices {
|
|
41
|
-
env?: string;
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* 获取服务配置键列表请求参数
|
|
45
|
-
*/
|
|
46
|
-
interface GetServiceKeys {
|
|
47
|
-
serviceName: string;
|
|
48
|
-
env?: string;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
namespace Response {
|
|
52
|
-
/**
|
|
53
|
-
* 获取单个配置响应
|
|
54
|
-
*/
|
|
55
|
-
interface FetchConfigResponse {
|
|
56
|
-
config_key: string;
|
|
57
|
-
value: string;
|
|
58
|
-
value_type: 'string' | 'number' | 'boolean' | 'object' | 'array';
|
|
59
|
-
updated_at: string;
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* 批量获取配置响应
|
|
63
|
-
* 返回 Map<config_key, parsed_value> 格式
|
|
64
|
-
* value 会自动解析:JSON 对象/数组会解析,其他返回原始字符串
|
|
65
|
-
*/
|
|
66
|
-
type FetchConfigsResponse = Record<string, any>;
|
|
67
|
-
/**
|
|
68
|
-
* 获取服务列表响应
|
|
69
|
-
*/
|
|
70
|
-
type GetServicesResponse = string[];
|
|
71
|
-
/**
|
|
72
|
-
* 获取服务配置键列表响应
|
|
73
|
-
*/
|
|
74
|
-
type GetServiceKeysResponse = string[];
|
|
75
|
-
}
|
|
76
|
-
/**
|
|
77
|
-
* V2 配置控制器接口
|
|
78
|
-
*/
|
|
79
|
-
interface ConfigController {
|
|
80
|
-
/**
|
|
81
|
-
* 获取单个配置
|
|
82
|
-
* @param req 请求参数
|
|
83
|
-
* @returns 配置数据
|
|
84
|
-
*/
|
|
85
|
-
fetchConfig(req: Request.FetchConfig): Promise<Response.FetchConfigResponse | null>;
|
|
86
|
-
/**
|
|
87
|
-
* 批量获取配置
|
|
88
|
-
* @param req 请求参数
|
|
89
|
-
* @returns 配置数据映射
|
|
90
|
-
*/
|
|
91
|
-
fetchConfigs(req: Request.FetchConfigs): Promise<Response.FetchConfigsResponse>;
|
|
92
|
-
/**
|
|
93
|
-
* 获取所有服务列表
|
|
94
|
-
* @param env 环境名称
|
|
95
|
-
* @returns 服务列表
|
|
96
|
-
*/
|
|
97
|
-
getServices(env?: string): Promise<Response.GetServicesResponse>;
|
|
98
|
-
/**
|
|
99
|
-
* 获取指定服务的配置键列表
|
|
100
|
-
* @param serviceName 服务名称
|
|
101
|
-
* @param env 环境名称
|
|
102
|
-
* @returns 配置键列表
|
|
103
|
-
*/
|
|
104
|
-
getServiceKeys(serviceName: string, env?: string): Promise<Response.GetServiceKeysResponse>;
|
|
105
|
-
}
|
|
106
|
-
}
|