@djvlc/openapi-registry-client 1.0.0

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.
@@ -0,0 +1,286 @@
1
+ import { ApiResponse, PaginationParams, ComponentCategory, ComponentStatus, SortOrder, PaginatedApiResponse, ComponentMeta, BlockedComponent, HealthCheckResponse } from '@djvlc/contracts-types';
2
+ export { ApiResponse, BlockedComponent, ComponentCategory, ComponentMeta, ComponentStatus, ComponentVersionRecord, HealthCheckResponse, ManifestItem, PaginatedApiResponse, PaginationParams, SortOrder } from '@djvlc/contracts-types';
3
+
4
+ /**
5
+ * @djvlc/openapi-registry-client - Registry API 客户端
6
+ *
7
+ * 组件注册中心 API 客户端,提供类型安全的 Registry API 访问
8
+ * 用于 Editor/Platform 管理组件版本
9
+ *
10
+ * @packageDocumentation
11
+ */
12
+
13
+ /**
14
+ * Registry API 客户端配置
15
+ */
16
+ interface RegistryClientConfig {
17
+ /** API 基础 URL */
18
+ baseUrl: string;
19
+ /** 认证 Token */
20
+ token?: string;
21
+ /** 获取 Token 的函数(支持动态获取) */
22
+ getToken?: () => string | Promise<string>;
23
+ /** API Key(服务间调用) */
24
+ apiKey?: string;
25
+ /** 请求超时(毫秒) */
26
+ timeout?: number;
27
+ /** 自定义请求头 */
28
+ headers?: Record<string, string>;
29
+ /** 获取 Trace Headers(用于链路追踪) */
30
+ getTraceHeaders?: () => Record<string, string>;
31
+ /** 请求拦截器 */
32
+ onRequest?: (config: RequestInit) => RequestInit;
33
+ /** 响应拦截器 */
34
+ onResponse?: <T>(response: ApiResponse<T>) => ApiResponse<T>;
35
+ /** 错误处理 */
36
+ onError?: (error: Error) => void;
37
+ }
38
+ /**
39
+ * 组件列表查询参数
40
+ * GET /api/registry/components
41
+ */
42
+ interface ListComponentsParams extends PaginationParams {
43
+ /** 组件分类 */
44
+ category?: ComponentCategory;
45
+ /** 组件状态 */
46
+ status?: ComponentStatus;
47
+ /** 搜索关键词 */
48
+ search?: string;
49
+ /** 排序字段 */
50
+ sortBy?: 'name' | 'publishedAt' | 'downloads' | 'usageCount';
51
+ /** 排序方向 */
52
+ sortOrder?: SortOrder;
53
+ }
54
+ /**
55
+ * 版本列表查询参数
56
+ * GET /api/registry/components/{name}/versions
57
+ */
58
+ interface ListVersionsParams extends PaginationParams {
59
+ /** 版本状态 */
60
+ status?: ComponentStatus;
61
+ }
62
+ /**
63
+ * 注册组件版本请求
64
+ * POST /api/registry/components/{name}/versions
65
+ */
66
+ interface RegisterVersionRequest {
67
+ /** 组件名称 */
68
+ name: string;
69
+ /** 版本号 */
70
+ version: string;
71
+ /** 显示名称 */
72
+ label: string;
73
+ /** 描述 */
74
+ description?: string;
75
+ /** 分类 */
76
+ category: ComponentCategory;
77
+ /** 图标 */
78
+ icon?: string;
79
+ /** 入口文件 URL */
80
+ entry: string;
81
+ /** 样式文件 URL */
82
+ styleEntry?: string;
83
+ /** SRI 完整性哈希 */
84
+ integrity: string;
85
+ /** 属性定义 (JSON Schema) */
86
+ props?: Record<string, unknown>;
87
+ /** 事件定义 */
88
+ events?: Array<{
89
+ name: string;
90
+ label?: string;
91
+ description?: string;
92
+ payloadSchema?: Record<string, unknown>;
93
+ }>;
94
+ /** 插槽定义 */
95
+ slots?: Array<{
96
+ name: string;
97
+ label?: string;
98
+ description?: string;
99
+ allowedComponents?: string[];
100
+ }>;
101
+ /** 能力声明 */
102
+ capabilities?: {
103
+ actions?: string[];
104
+ queries?: string[];
105
+ hostApis?: string[];
106
+ permissions?: string[];
107
+ };
108
+ /** 兼容性信息 */
109
+ compat?: {
110
+ runtimeVersion?: string;
111
+ browsers?: Record<string, string>;
112
+ platforms?: ('web' | 'h5' | 'miniprogram' | 'ios' | 'android')[];
113
+ };
114
+ /** 依赖列表 */
115
+ dependencies?: Array<{
116
+ name: string;
117
+ versionRange: string;
118
+ }>;
119
+ /** 更新日志 */
120
+ changelog?: string;
121
+ }
122
+ /**
123
+ * 阻断版本请求
124
+ * POST /api/registry/components/{name}/versions/{version}/block
125
+ */
126
+ interface BlockVersionRequest {
127
+ /** 阻断原因 */
128
+ reason: string;
129
+ /** 回退版本 */
130
+ fallbackVersion?: string;
131
+ /** 是否通知用户 */
132
+ notifyUsers?: boolean;
133
+ }
134
+ /**
135
+ * 解除阻断请求
136
+ * POST /api/registry/components/{name}/versions/{version}/unblock
137
+ */
138
+ interface UnblockVersionRequest {
139
+ /** 解除原因 */
140
+ reason: string;
141
+ }
142
+ /**
143
+ * 废弃版本请求
144
+ * POST /api/registry/components/{name}/versions/{version}/deprecate
145
+ */
146
+ interface DeprecateVersionRequest {
147
+ /** 废弃说明 */
148
+ message: string;
149
+ /** 替代版本 */
150
+ replacementVersion?: string;
151
+ /** 是否废弃所有之前版本 */
152
+ deprecateAllPrevious?: boolean;
153
+ }
154
+ /**
155
+ * 解析版本请求
156
+ * POST /api/registry/resolve
157
+ */
158
+ interface ResolveVersionsRequest {
159
+ /** 要解析的组件列表 */
160
+ components: Array<{
161
+ /** 组件名称 */
162
+ name: string;
163
+ /** 版本范围(semver) */
164
+ versionRange?: string;
165
+ }>;
166
+ }
167
+ /**
168
+ * 组件版本信息(简化版,用于版本列表)
169
+ */
170
+ interface ComponentVersion {
171
+ /** 版本号 */
172
+ version: string;
173
+ /** 状态 */
174
+ status: ComponentStatus;
175
+ /** 发布时间 */
176
+ publishedAt: string;
177
+ /** 下载量 */
178
+ downloads: number;
179
+ /** 更新日志 */
180
+ changelog?: string;
181
+ }
182
+ /**
183
+ * 阻断组件信息(扩展自 BlockedComponent)
184
+ * 继承 contracts-types 中的 BlockedComponent,添加 Registry API 特有字段
185
+ */
186
+ interface BlockedComponentInfo extends BlockedComponent {
187
+ /** 阻断操作者 */
188
+ blockedBy: string;
189
+ /** 影响的页面数 */
190
+ affectedPages: number;
191
+ }
192
+ /**
193
+ * 更新检查结果
194
+ */
195
+ interface UpdateCheckResult {
196
+ /** 组件名称 */
197
+ name: string;
198
+ /** 当前版本 */
199
+ currentVersion: string;
200
+ /** 最新版本 */
201
+ latestVersion: string;
202
+ /** 是否有更新 */
203
+ hasUpdate: boolean;
204
+ /** 更新类型 */
205
+ updateType?: 'major' | 'minor' | 'patch';
206
+ /** 更新日志 */
207
+ changelog?: string;
208
+ }
209
+ /**
210
+ * Registry API 客户端类
211
+ * 用于组件注册中心的版本管理
212
+ */
213
+ declare class RegistryApiClient {
214
+ private config;
215
+ constructor(config: RegistryClientConfig);
216
+ /**
217
+ * 获取认证 Token
218
+ */
219
+ private getAuthToken;
220
+ /**
221
+ * 获取认证头
222
+ */
223
+ private getAuthHeaders;
224
+ /**
225
+ * 发送请求
226
+ */
227
+ private request;
228
+ /** 获取组件列表 */
229
+ listComponents(params?: ListComponentsParams): Promise<PaginatedApiResponse<ComponentMeta>>;
230
+ /** 获取组件信息(最新 active 版本) */
231
+ getComponent(name: string): Promise<ApiResponse<ComponentMeta>>;
232
+ /** 注册新组件版本 */
233
+ registerVersion(name: string, data: RegisterVersionRequest): Promise<ApiResponse<ComponentMeta>>;
234
+ /** 获取组件所有版本 */
235
+ listVersions(name: string, params?: ListVersionsParams): Promise<PaginatedApiResponse<ComponentVersion>>;
236
+ /** 获取组件指定版本 */
237
+ getVersion(name: string, version: string): Promise<ApiResponse<ComponentMeta>>;
238
+ /** 晋升版本(pending -> active) */
239
+ promoteVersion(name: string, version: string, options?: {
240
+ approvedBy?: string;
241
+ comment?: string;
242
+ }): Promise<ApiResponse<ComponentMeta>>;
243
+ /** 阻断组件版本 */
244
+ blockVersion(name: string, version: string, data: BlockVersionRequest): Promise<ApiResponse<{
245
+ blockedAt: string;
246
+ affectedPages: number;
247
+ }>>;
248
+ /** 解除组件阻断 */
249
+ unblockVersion(name: string, version: string, data?: UnblockVersionRequest): Promise<ApiResponse<void>>;
250
+ /** 废弃组件版本 */
251
+ deprecateVersion(name: string, version: string, data: DeprecateVersionRequest): Promise<ApiResponse<{
252
+ deprecatedVersions: string[];
253
+ }>>;
254
+ /** 获取所有被阻断的组件 */
255
+ listBlockedComponents(params?: PaginationParams): Promise<PaginatedApiResponse<BlockedComponentInfo>>;
256
+ /** 解析组件版本 */
257
+ resolveVersions(data: ResolveVersionsRequest): Promise<ApiResponse<ComponentMeta[]>>;
258
+ /** 批量解析组件版本 */
259
+ batchResolveVersions(requests: Array<{
260
+ pageId: string;
261
+ components: Array<{
262
+ name: string;
263
+ versionRange?: string;
264
+ }>;
265
+ }>): Promise<ApiResponse<Array<{
266
+ pageId: string;
267
+ components: ComponentMeta[];
268
+ errors?: Array<{
269
+ name: string;
270
+ error: string;
271
+ }>;
272
+ }>>>;
273
+ /** 检查组件更新 */
274
+ checkUpdates(components: Array<{
275
+ name: string;
276
+ currentVersion: string;
277
+ }>): Promise<ApiResponse<UpdateCheckResult[]>>;
278
+ /** 健康检查 */
279
+ health(): Promise<ApiResponse<HealthCheckResponse>>;
280
+ }
281
+ /**
282
+ * 创建 Registry API 客户端实例
283
+ */
284
+ declare function createRegistryClient(config: RegistryClientConfig): RegistryApiClient;
285
+
286
+ export { type BlockVersionRequest, type BlockedComponentInfo, type ComponentVersion, type DeprecateVersionRequest, type ListComponentsParams, type ListVersionsParams, type RegisterVersionRequest, RegistryApiClient, type RegistryClientConfig, type ResolveVersionsRequest, type UnblockVersionRequest, type UpdateCheckResult, createRegistryClient, RegistryApiClient as default };
@@ -0,0 +1,286 @@
1
+ import { ApiResponse, PaginationParams, ComponentCategory, ComponentStatus, SortOrder, PaginatedApiResponse, ComponentMeta, BlockedComponent, HealthCheckResponse } from '@djvlc/contracts-types';
2
+ export { ApiResponse, BlockedComponent, ComponentCategory, ComponentMeta, ComponentStatus, ComponentVersionRecord, HealthCheckResponse, ManifestItem, PaginatedApiResponse, PaginationParams, SortOrder } from '@djvlc/contracts-types';
3
+
4
+ /**
5
+ * @djvlc/openapi-registry-client - Registry API 客户端
6
+ *
7
+ * 组件注册中心 API 客户端,提供类型安全的 Registry API 访问
8
+ * 用于 Editor/Platform 管理组件版本
9
+ *
10
+ * @packageDocumentation
11
+ */
12
+
13
+ /**
14
+ * Registry API 客户端配置
15
+ */
16
+ interface RegistryClientConfig {
17
+ /** API 基础 URL */
18
+ baseUrl: string;
19
+ /** 认证 Token */
20
+ token?: string;
21
+ /** 获取 Token 的函数(支持动态获取) */
22
+ getToken?: () => string | Promise<string>;
23
+ /** API Key(服务间调用) */
24
+ apiKey?: string;
25
+ /** 请求超时(毫秒) */
26
+ timeout?: number;
27
+ /** 自定义请求头 */
28
+ headers?: Record<string, string>;
29
+ /** 获取 Trace Headers(用于链路追踪) */
30
+ getTraceHeaders?: () => Record<string, string>;
31
+ /** 请求拦截器 */
32
+ onRequest?: (config: RequestInit) => RequestInit;
33
+ /** 响应拦截器 */
34
+ onResponse?: <T>(response: ApiResponse<T>) => ApiResponse<T>;
35
+ /** 错误处理 */
36
+ onError?: (error: Error) => void;
37
+ }
38
+ /**
39
+ * 组件列表查询参数
40
+ * GET /api/registry/components
41
+ */
42
+ interface ListComponentsParams extends PaginationParams {
43
+ /** 组件分类 */
44
+ category?: ComponentCategory;
45
+ /** 组件状态 */
46
+ status?: ComponentStatus;
47
+ /** 搜索关键词 */
48
+ search?: string;
49
+ /** 排序字段 */
50
+ sortBy?: 'name' | 'publishedAt' | 'downloads' | 'usageCount';
51
+ /** 排序方向 */
52
+ sortOrder?: SortOrder;
53
+ }
54
+ /**
55
+ * 版本列表查询参数
56
+ * GET /api/registry/components/{name}/versions
57
+ */
58
+ interface ListVersionsParams extends PaginationParams {
59
+ /** 版本状态 */
60
+ status?: ComponentStatus;
61
+ }
62
+ /**
63
+ * 注册组件版本请求
64
+ * POST /api/registry/components/{name}/versions
65
+ */
66
+ interface RegisterVersionRequest {
67
+ /** 组件名称 */
68
+ name: string;
69
+ /** 版本号 */
70
+ version: string;
71
+ /** 显示名称 */
72
+ label: string;
73
+ /** 描述 */
74
+ description?: string;
75
+ /** 分类 */
76
+ category: ComponentCategory;
77
+ /** 图标 */
78
+ icon?: string;
79
+ /** 入口文件 URL */
80
+ entry: string;
81
+ /** 样式文件 URL */
82
+ styleEntry?: string;
83
+ /** SRI 完整性哈希 */
84
+ integrity: string;
85
+ /** 属性定义 (JSON Schema) */
86
+ props?: Record<string, unknown>;
87
+ /** 事件定义 */
88
+ events?: Array<{
89
+ name: string;
90
+ label?: string;
91
+ description?: string;
92
+ payloadSchema?: Record<string, unknown>;
93
+ }>;
94
+ /** 插槽定义 */
95
+ slots?: Array<{
96
+ name: string;
97
+ label?: string;
98
+ description?: string;
99
+ allowedComponents?: string[];
100
+ }>;
101
+ /** 能力声明 */
102
+ capabilities?: {
103
+ actions?: string[];
104
+ queries?: string[];
105
+ hostApis?: string[];
106
+ permissions?: string[];
107
+ };
108
+ /** 兼容性信息 */
109
+ compat?: {
110
+ runtimeVersion?: string;
111
+ browsers?: Record<string, string>;
112
+ platforms?: ('web' | 'h5' | 'miniprogram' | 'ios' | 'android')[];
113
+ };
114
+ /** 依赖列表 */
115
+ dependencies?: Array<{
116
+ name: string;
117
+ versionRange: string;
118
+ }>;
119
+ /** 更新日志 */
120
+ changelog?: string;
121
+ }
122
+ /**
123
+ * 阻断版本请求
124
+ * POST /api/registry/components/{name}/versions/{version}/block
125
+ */
126
+ interface BlockVersionRequest {
127
+ /** 阻断原因 */
128
+ reason: string;
129
+ /** 回退版本 */
130
+ fallbackVersion?: string;
131
+ /** 是否通知用户 */
132
+ notifyUsers?: boolean;
133
+ }
134
+ /**
135
+ * 解除阻断请求
136
+ * POST /api/registry/components/{name}/versions/{version}/unblock
137
+ */
138
+ interface UnblockVersionRequest {
139
+ /** 解除原因 */
140
+ reason: string;
141
+ }
142
+ /**
143
+ * 废弃版本请求
144
+ * POST /api/registry/components/{name}/versions/{version}/deprecate
145
+ */
146
+ interface DeprecateVersionRequest {
147
+ /** 废弃说明 */
148
+ message: string;
149
+ /** 替代版本 */
150
+ replacementVersion?: string;
151
+ /** 是否废弃所有之前版本 */
152
+ deprecateAllPrevious?: boolean;
153
+ }
154
+ /**
155
+ * 解析版本请求
156
+ * POST /api/registry/resolve
157
+ */
158
+ interface ResolveVersionsRequest {
159
+ /** 要解析的组件列表 */
160
+ components: Array<{
161
+ /** 组件名称 */
162
+ name: string;
163
+ /** 版本范围(semver) */
164
+ versionRange?: string;
165
+ }>;
166
+ }
167
+ /**
168
+ * 组件版本信息(简化版,用于版本列表)
169
+ */
170
+ interface ComponentVersion {
171
+ /** 版本号 */
172
+ version: string;
173
+ /** 状态 */
174
+ status: ComponentStatus;
175
+ /** 发布时间 */
176
+ publishedAt: string;
177
+ /** 下载量 */
178
+ downloads: number;
179
+ /** 更新日志 */
180
+ changelog?: string;
181
+ }
182
+ /**
183
+ * 阻断组件信息(扩展自 BlockedComponent)
184
+ * 继承 contracts-types 中的 BlockedComponent,添加 Registry API 特有字段
185
+ */
186
+ interface BlockedComponentInfo extends BlockedComponent {
187
+ /** 阻断操作者 */
188
+ blockedBy: string;
189
+ /** 影响的页面数 */
190
+ affectedPages: number;
191
+ }
192
+ /**
193
+ * 更新检查结果
194
+ */
195
+ interface UpdateCheckResult {
196
+ /** 组件名称 */
197
+ name: string;
198
+ /** 当前版本 */
199
+ currentVersion: string;
200
+ /** 最新版本 */
201
+ latestVersion: string;
202
+ /** 是否有更新 */
203
+ hasUpdate: boolean;
204
+ /** 更新类型 */
205
+ updateType?: 'major' | 'minor' | 'patch';
206
+ /** 更新日志 */
207
+ changelog?: string;
208
+ }
209
+ /**
210
+ * Registry API 客户端类
211
+ * 用于组件注册中心的版本管理
212
+ */
213
+ declare class RegistryApiClient {
214
+ private config;
215
+ constructor(config: RegistryClientConfig);
216
+ /**
217
+ * 获取认证 Token
218
+ */
219
+ private getAuthToken;
220
+ /**
221
+ * 获取认证头
222
+ */
223
+ private getAuthHeaders;
224
+ /**
225
+ * 发送请求
226
+ */
227
+ private request;
228
+ /** 获取组件列表 */
229
+ listComponents(params?: ListComponentsParams): Promise<PaginatedApiResponse<ComponentMeta>>;
230
+ /** 获取组件信息(最新 active 版本) */
231
+ getComponent(name: string): Promise<ApiResponse<ComponentMeta>>;
232
+ /** 注册新组件版本 */
233
+ registerVersion(name: string, data: RegisterVersionRequest): Promise<ApiResponse<ComponentMeta>>;
234
+ /** 获取组件所有版本 */
235
+ listVersions(name: string, params?: ListVersionsParams): Promise<PaginatedApiResponse<ComponentVersion>>;
236
+ /** 获取组件指定版本 */
237
+ getVersion(name: string, version: string): Promise<ApiResponse<ComponentMeta>>;
238
+ /** 晋升版本(pending -> active) */
239
+ promoteVersion(name: string, version: string, options?: {
240
+ approvedBy?: string;
241
+ comment?: string;
242
+ }): Promise<ApiResponse<ComponentMeta>>;
243
+ /** 阻断组件版本 */
244
+ blockVersion(name: string, version: string, data: BlockVersionRequest): Promise<ApiResponse<{
245
+ blockedAt: string;
246
+ affectedPages: number;
247
+ }>>;
248
+ /** 解除组件阻断 */
249
+ unblockVersion(name: string, version: string, data?: UnblockVersionRequest): Promise<ApiResponse<void>>;
250
+ /** 废弃组件版本 */
251
+ deprecateVersion(name: string, version: string, data: DeprecateVersionRequest): Promise<ApiResponse<{
252
+ deprecatedVersions: string[];
253
+ }>>;
254
+ /** 获取所有被阻断的组件 */
255
+ listBlockedComponents(params?: PaginationParams): Promise<PaginatedApiResponse<BlockedComponentInfo>>;
256
+ /** 解析组件版本 */
257
+ resolveVersions(data: ResolveVersionsRequest): Promise<ApiResponse<ComponentMeta[]>>;
258
+ /** 批量解析组件版本 */
259
+ batchResolveVersions(requests: Array<{
260
+ pageId: string;
261
+ components: Array<{
262
+ name: string;
263
+ versionRange?: string;
264
+ }>;
265
+ }>): Promise<ApiResponse<Array<{
266
+ pageId: string;
267
+ components: ComponentMeta[];
268
+ errors?: Array<{
269
+ name: string;
270
+ error: string;
271
+ }>;
272
+ }>>>;
273
+ /** 检查组件更新 */
274
+ checkUpdates(components: Array<{
275
+ name: string;
276
+ currentVersion: string;
277
+ }>): Promise<ApiResponse<UpdateCheckResult[]>>;
278
+ /** 健康检查 */
279
+ health(): Promise<ApiResponse<HealthCheckResponse>>;
280
+ }
281
+ /**
282
+ * 创建 Registry API 客户端实例
283
+ */
284
+ declare function createRegistryClient(config: RegistryClientConfig): RegistryApiClient;
285
+
286
+ export { type BlockVersionRequest, type BlockedComponentInfo, type ComponentVersion, type DeprecateVersionRequest, type ListComponentsParams, type ListVersionsParams, type RegisterVersionRequest, RegistryApiClient, type RegistryClientConfig, type ResolveVersionsRequest, type UnblockVersionRequest, type UpdateCheckResult, createRegistryClient, RegistryApiClient as default };
package/dist/index.js ADDED
@@ -0,0 +1,214 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ RegistryApiClient: () => RegistryApiClient,
24
+ createRegistryClient: () => createRegistryClient,
25
+ default: () => index_default
26
+ });
27
+ module.exports = __toCommonJS(index_exports);
28
+ var RegistryApiClient = class {
29
+ constructor(config) {
30
+ this.config = {
31
+ timeout: 3e4,
32
+ ...config
33
+ };
34
+ }
35
+ /**
36
+ * 获取认证 Token
37
+ */
38
+ async getAuthToken() {
39
+ if (this.config.getToken) {
40
+ return this.config.getToken();
41
+ }
42
+ return this.config.token;
43
+ }
44
+ /**
45
+ * 获取认证头
46
+ */
47
+ async getAuthHeaders() {
48
+ const headers = {};
49
+ const token = await this.getAuthToken();
50
+ if (token) {
51
+ headers["Authorization"] = `Bearer ${token}`;
52
+ }
53
+ if (this.config.apiKey) {
54
+ headers["x-api-key"] = this.config.apiKey;
55
+ }
56
+ return headers;
57
+ }
58
+ /**
59
+ * 发送请求
60
+ */
61
+ async request(method, path, options) {
62
+ let url = `${this.config.baseUrl}${path}`;
63
+ if (options?.params) {
64
+ const searchParams = new URLSearchParams();
65
+ Object.entries(options.params).forEach(([key, value]) => {
66
+ if (value !== void 0) {
67
+ searchParams.append(key, String(value));
68
+ }
69
+ });
70
+ const queryString = searchParams.toString();
71
+ if (queryString) {
72
+ url += `?${queryString}`;
73
+ }
74
+ }
75
+ const authHeaders = await this.getAuthHeaders();
76
+ let requestConfig = {
77
+ method,
78
+ headers: {
79
+ "Content-Type": "application/json",
80
+ ...authHeaders,
81
+ ...this.config.getTraceHeaders ? this.config.getTraceHeaders() : {},
82
+ ...this.config.headers
83
+ },
84
+ body: options?.body ? JSON.stringify(options.body) : void 0
85
+ };
86
+ if (this.config.onRequest) {
87
+ requestConfig = this.config.onRequest(requestConfig);
88
+ }
89
+ try {
90
+ const controller = new AbortController();
91
+ const timeoutId = setTimeout(() => controller.abort(), this.config.timeout);
92
+ const response = await fetch(url, {
93
+ ...requestConfig,
94
+ signal: controller.signal
95
+ });
96
+ clearTimeout(timeoutId);
97
+ let result = await response.json();
98
+ if (this.config.onResponse) {
99
+ result = this.config.onResponse(result);
100
+ }
101
+ return result;
102
+ } catch (error) {
103
+ if (this.config.onError) {
104
+ this.config.onError(error);
105
+ }
106
+ throw error;
107
+ }
108
+ }
109
+ // ==================== 组件管理 ====================
110
+ /** 获取组件列表 */
111
+ async listComponents(params) {
112
+ return this.request("GET", "/api/registry/components", {
113
+ params
114
+ });
115
+ }
116
+ /** 获取组件信息(最新 active 版本) */
117
+ async getComponent(name) {
118
+ return this.request(
119
+ "GET",
120
+ `/api/registry/components/${encodeURIComponent(name)}`
121
+ );
122
+ }
123
+ /** 注册新组件版本 */
124
+ async registerVersion(name, data) {
125
+ return this.request(
126
+ "POST",
127
+ `/api/registry/components/${encodeURIComponent(name)}/versions`,
128
+ { body: data }
129
+ );
130
+ }
131
+ /** 获取组件所有版本 */
132
+ async listVersions(name, params) {
133
+ return this.request(
134
+ "GET",
135
+ `/api/registry/components/${encodeURIComponent(name)}/versions`,
136
+ { params }
137
+ );
138
+ }
139
+ /** 获取组件指定版本 */
140
+ async getVersion(name, version) {
141
+ return this.request(
142
+ "GET",
143
+ `/api/registry/components/${encodeURIComponent(name)}/versions/${encodeURIComponent(version)}`
144
+ );
145
+ }
146
+ /** 晋升版本(pending -> active) */
147
+ async promoteVersion(name, version, options) {
148
+ return this.request(
149
+ "POST",
150
+ `/api/registry/components/${encodeURIComponent(name)}/versions/${encodeURIComponent(version)}/promote`,
151
+ { body: options }
152
+ );
153
+ }
154
+ // ==================== 阻断与废弃 ====================
155
+ /** 阻断组件版本 */
156
+ async blockVersion(name, version, data) {
157
+ return this.request(
158
+ "POST",
159
+ `/api/registry/components/${encodeURIComponent(name)}/versions/${encodeURIComponent(version)}/block`,
160
+ { body: data }
161
+ );
162
+ }
163
+ /** 解除组件阻断 */
164
+ async unblockVersion(name, version, data) {
165
+ return this.request(
166
+ "POST",
167
+ `/api/registry/components/${encodeURIComponent(name)}/versions/${encodeURIComponent(version)}/unblock`,
168
+ { body: data }
169
+ );
170
+ }
171
+ /** 废弃组件版本 */
172
+ async deprecateVersion(name, version, data) {
173
+ return this.request(
174
+ "POST",
175
+ `/api/registry/components/${encodeURIComponent(name)}/versions/${encodeURIComponent(version)}/deprecate`,
176
+ { body: data }
177
+ );
178
+ }
179
+ /** 获取所有被阻断的组件 */
180
+ async listBlockedComponents(params) {
181
+ return this.request("GET", "/api/registry/blocked", {
182
+ params
183
+ });
184
+ }
185
+ // ==================== 版本解析 ====================
186
+ /** 解析组件版本 */
187
+ async resolveVersions(data) {
188
+ return this.request("POST", "/api/registry/resolve", { body: data });
189
+ }
190
+ /** 批量解析组件版本 */
191
+ async batchResolveVersions(requests) {
192
+ return this.request("POST", "/api/registry/resolve/batch", { body: { requests } });
193
+ }
194
+ /** 检查组件更新 */
195
+ async checkUpdates(components) {
196
+ return this.request("POST", "/api/registry/check-updates", {
197
+ body: { components }
198
+ });
199
+ }
200
+ // ==================== 健康检查 ====================
201
+ /** 健康检查 */
202
+ async health() {
203
+ return this.request("GET", "/api/registry/health");
204
+ }
205
+ };
206
+ function createRegistryClient(config) {
207
+ return new RegistryApiClient(config);
208
+ }
209
+ var index_default = RegistryApiClient;
210
+ // Annotate the CommonJS export names for ESM import in node:
211
+ 0 && (module.exports = {
212
+ RegistryApiClient,
213
+ createRegistryClient
214
+ });
package/dist/index.mjs ADDED
@@ -0,0 +1,188 @@
1
+ // src/index.ts
2
+ var RegistryApiClient = class {
3
+ constructor(config) {
4
+ this.config = {
5
+ timeout: 3e4,
6
+ ...config
7
+ };
8
+ }
9
+ /**
10
+ * 获取认证 Token
11
+ */
12
+ async getAuthToken() {
13
+ if (this.config.getToken) {
14
+ return this.config.getToken();
15
+ }
16
+ return this.config.token;
17
+ }
18
+ /**
19
+ * 获取认证头
20
+ */
21
+ async getAuthHeaders() {
22
+ const headers = {};
23
+ const token = await this.getAuthToken();
24
+ if (token) {
25
+ headers["Authorization"] = `Bearer ${token}`;
26
+ }
27
+ if (this.config.apiKey) {
28
+ headers["x-api-key"] = this.config.apiKey;
29
+ }
30
+ return headers;
31
+ }
32
+ /**
33
+ * 发送请求
34
+ */
35
+ async request(method, path, options) {
36
+ let url = `${this.config.baseUrl}${path}`;
37
+ if (options?.params) {
38
+ const searchParams = new URLSearchParams();
39
+ Object.entries(options.params).forEach(([key, value]) => {
40
+ if (value !== void 0) {
41
+ searchParams.append(key, String(value));
42
+ }
43
+ });
44
+ const queryString = searchParams.toString();
45
+ if (queryString) {
46
+ url += `?${queryString}`;
47
+ }
48
+ }
49
+ const authHeaders = await this.getAuthHeaders();
50
+ let requestConfig = {
51
+ method,
52
+ headers: {
53
+ "Content-Type": "application/json",
54
+ ...authHeaders,
55
+ ...this.config.getTraceHeaders ? this.config.getTraceHeaders() : {},
56
+ ...this.config.headers
57
+ },
58
+ body: options?.body ? JSON.stringify(options.body) : void 0
59
+ };
60
+ if (this.config.onRequest) {
61
+ requestConfig = this.config.onRequest(requestConfig);
62
+ }
63
+ try {
64
+ const controller = new AbortController();
65
+ const timeoutId = setTimeout(() => controller.abort(), this.config.timeout);
66
+ const response = await fetch(url, {
67
+ ...requestConfig,
68
+ signal: controller.signal
69
+ });
70
+ clearTimeout(timeoutId);
71
+ let result = await response.json();
72
+ if (this.config.onResponse) {
73
+ result = this.config.onResponse(result);
74
+ }
75
+ return result;
76
+ } catch (error) {
77
+ if (this.config.onError) {
78
+ this.config.onError(error);
79
+ }
80
+ throw error;
81
+ }
82
+ }
83
+ // ==================== 组件管理 ====================
84
+ /** 获取组件列表 */
85
+ async listComponents(params) {
86
+ return this.request("GET", "/api/registry/components", {
87
+ params
88
+ });
89
+ }
90
+ /** 获取组件信息(最新 active 版本) */
91
+ async getComponent(name) {
92
+ return this.request(
93
+ "GET",
94
+ `/api/registry/components/${encodeURIComponent(name)}`
95
+ );
96
+ }
97
+ /** 注册新组件版本 */
98
+ async registerVersion(name, data) {
99
+ return this.request(
100
+ "POST",
101
+ `/api/registry/components/${encodeURIComponent(name)}/versions`,
102
+ { body: data }
103
+ );
104
+ }
105
+ /** 获取组件所有版本 */
106
+ async listVersions(name, params) {
107
+ return this.request(
108
+ "GET",
109
+ `/api/registry/components/${encodeURIComponent(name)}/versions`,
110
+ { params }
111
+ );
112
+ }
113
+ /** 获取组件指定版本 */
114
+ async getVersion(name, version) {
115
+ return this.request(
116
+ "GET",
117
+ `/api/registry/components/${encodeURIComponent(name)}/versions/${encodeURIComponent(version)}`
118
+ );
119
+ }
120
+ /** 晋升版本(pending -> active) */
121
+ async promoteVersion(name, version, options) {
122
+ return this.request(
123
+ "POST",
124
+ `/api/registry/components/${encodeURIComponent(name)}/versions/${encodeURIComponent(version)}/promote`,
125
+ { body: options }
126
+ );
127
+ }
128
+ // ==================== 阻断与废弃 ====================
129
+ /** 阻断组件版本 */
130
+ async blockVersion(name, version, data) {
131
+ return this.request(
132
+ "POST",
133
+ `/api/registry/components/${encodeURIComponent(name)}/versions/${encodeURIComponent(version)}/block`,
134
+ { body: data }
135
+ );
136
+ }
137
+ /** 解除组件阻断 */
138
+ async unblockVersion(name, version, data) {
139
+ return this.request(
140
+ "POST",
141
+ `/api/registry/components/${encodeURIComponent(name)}/versions/${encodeURIComponent(version)}/unblock`,
142
+ { body: data }
143
+ );
144
+ }
145
+ /** 废弃组件版本 */
146
+ async deprecateVersion(name, version, data) {
147
+ return this.request(
148
+ "POST",
149
+ `/api/registry/components/${encodeURIComponent(name)}/versions/${encodeURIComponent(version)}/deprecate`,
150
+ { body: data }
151
+ );
152
+ }
153
+ /** 获取所有被阻断的组件 */
154
+ async listBlockedComponents(params) {
155
+ return this.request("GET", "/api/registry/blocked", {
156
+ params
157
+ });
158
+ }
159
+ // ==================== 版本解析 ====================
160
+ /** 解析组件版本 */
161
+ async resolveVersions(data) {
162
+ return this.request("POST", "/api/registry/resolve", { body: data });
163
+ }
164
+ /** 批量解析组件版本 */
165
+ async batchResolveVersions(requests) {
166
+ return this.request("POST", "/api/registry/resolve/batch", { body: { requests } });
167
+ }
168
+ /** 检查组件更新 */
169
+ async checkUpdates(components) {
170
+ return this.request("POST", "/api/registry/check-updates", {
171
+ body: { components }
172
+ });
173
+ }
174
+ // ==================== 健康检查 ====================
175
+ /** 健康检查 */
176
+ async health() {
177
+ return this.request("GET", "/api/registry/health");
178
+ }
179
+ };
180
+ function createRegistryClient(config) {
181
+ return new RegistryApiClient(config);
182
+ }
183
+ var index_default = RegistryApiClient;
184
+ export {
185
+ RegistryApiClient,
186
+ createRegistryClient,
187
+ index_default as default
188
+ };
package/package.json ADDED
@@ -0,0 +1,66 @@
1
+ {
2
+ "name": "@djvlc/openapi-registry-client",
3
+ "version": "1.0.0",
4
+ "description": "DJV Low-code Platform - Registry API 客户端",
5
+ "main": "./dist/index.js",
6
+ "module": "./dist/index.mjs",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.mjs",
12
+ "require": "./dist/index.js"
13
+ }
14
+ },
15
+ "files": [
16
+ "dist"
17
+ ],
18
+ "scripts": {
19
+ "build": "tsup src/index.ts --format cjs,esm --dts --clean",
20
+ "dev": "tsup src/index.ts --format cjs,esm --dts --watch",
21
+ "lint": "eslint src/ --ext .ts",
22
+ "typecheck": "tsc --noEmit",
23
+ "clean": "rimraf dist"
24
+ },
25
+ "dependencies": {
26
+ "@djvlc/contracts-types": "1.3.0"
27
+ },
28
+ "devDependencies": {
29
+ "@types/node": "^20.0.0",
30
+ "@typescript-eslint/eslint-plugin": "^7.0.0",
31
+ "@typescript-eslint/parser": "^7.0.0",
32
+ "eslint": "^8.56.0",
33
+ "rimraf": "^5.0.0",
34
+ "tsup": "^8.0.0",
35
+ "typescript": "^5.3.0"
36
+ },
37
+ "peerDependencies": {
38
+ "@djvlc/contracts-types": "1.3.0"
39
+ },
40
+ "peerDependenciesMeta": {
41
+ "@djvlc/contracts-types": {
42
+ "optional": false
43
+ }
44
+ },
45
+ "keywords": [
46
+ "lowcode",
47
+ "openapi",
48
+ "client",
49
+ "registry-api",
50
+ "djvlc"
51
+ ],
52
+ "author": "DJV Team",
53
+ "license": "MIT",
54
+ "repository": {
55
+ "type": "git",
56
+ "url": "git+https://github.com/djvlc/contracts.git",
57
+ "directory": "openapi/registry-client"
58
+ },
59
+ "publishConfig": {
60
+ "access": "public",
61
+ "registry": "https://registry.npmjs.org/"
62
+ },
63
+ "engines": {
64
+ "node": ">=18.0.0"
65
+ }
66
+ }