@djvlc/openapi-admin-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.
- package/dist/index.d.mts +127 -0
- package/dist/index.d.ts +127 -0
- package/dist/index.js +167 -0
- package/dist/index.mjs +141 -0
- package/package.json +61 -0
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { ApiResponse, PaginatedApiResponse, PageSchema, PublishConfig, VersionInfo, ComponentMeta, ActionDefinition, DataQueryDefinition } from '@djvlc/contracts-types';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @djvlc/openapi-admin-client - Admin API 客户端
|
|
5
|
+
*
|
|
6
|
+
* 自动从 OpenAPI 规范生成,提供类型安全的 Admin API 访问
|
|
7
|
+
*
|
|
8
|
+
* @packageDocumentation
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
interface AdminClientConfig {
|
|
12
|
+
/** API 基础 URL */
|
|
13
|
+
baseUrl: string;
|
|
14
|
+
/** 认证 Token */
|
|
15
|
+
token?: string;
|
|
16
|
+
/** 请求超时(毫秒) */
|
|
17
|
+
timeout?: number;
|
|
18
|
+
/** 自定义请求头 */
|
|
19
|
+
headers?: Record<string, string>;
|
|
20
|
+
/** 请求拦截器 */
|
|
21
|
+
onRequest?: (config: RequestInit) => RequestInit;
|
|
22
|
+
/** 响应拦截器 */
|
|
23
|
+
onResponse?: <T>(response: ApiResponse<T>) => ApiResponse<T>;
|
|
24
|
+
/** 错误处理 */
|
|
25
|
+
onError?: (error: Error) => void;
|
|
26
|
+
}
|
|
27
|
+
/** 创建页面请求 */
|
|
28
|
+
interface CreatePageRequest {
|
|
29
|
+
title: string;
|
|
30
|
+
description?: string;
|
|
31
|
+
templateId?: string;
|
|
32
|
+
workspaceId?: string;
|
|
33
|
+
}
|
|
34
|
+
/** 更新页面请求 */
|
|
35
|
+
interface UpdatePageRequest {
|
|
36
|
+
title?: string;
|
|
37
|
+
description?: string;
|
|
38
|
+
schema?: PageSchema;
|
|
39
|
+
}
|
|
40
|
+
/** 页面列表查询参数 */
|
|
41
|
+
interface ListPagesParams {
|
|
42
|
+
page?: number;
|
|
43
|
+
pageSize?: number;
|
|
44
|
+
status?: 'draft' | 'published';
|
|
45
|
+
search?: string;
|
|
46
|
+
sortBy?: string;
|
|
47
|
+
sortOrder?: 'asc' | 'desc';
|
|
48
|
+
}
|
|
49
|
+
/** 页面详情响应 */
|
|
50
|
+
interface PageDetail {
|
|
51
|
+
id: string;
|
|
52
|
+
uid: string;
|
|
53
|
+
title: string;
|
|
54
|
+
description?: string;
|
|
55
|
+
status: 'draft' | 'published';
|
|
56
|
+
schema: PageSchema;
|
|
57
|
+
currentVersionId?: string;
|
|
58
|
+
createdAt: string;
|
|
59
|
+
updatedAt: string;
|
|
60
|
+
createdBy: string;
|
|
61
|
+
}
|
|
62
|
+
/** 组件列表查询参数 */
|
|
63
|
+
interface ListComponentsParams {
|
|
64
|
+
page?: number;
|
|
65
|
+
pageSize?: number;
|
|
66
|
+
category?: string;
|
|
67
|
+
status?: string;
|
|
68
|
+
search?: string;
|
|
69
|
+
}
|
|
70
|
+
/** 发布结果 */
|
|
71
|
+
interface PublishResult {
|
|
72
|
+
pageVersionId: string;
|
|
73
|
+
manifestId: string;
|
|
74
|
+
publishedAt: string;
|
|
75
|
+
channel: string;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Admin API 客户端类
|
|
79
|
+
*/
|
|
80
|
+
declare class AdminApiClient {
|
|
81
|
+
private config;
|
|
82
|
+
constructor(config: AdminClientConfig);
|
|
83
|
+
/**
|
|
84
|
+
* 发送请求
|
|
85
|
+
*/
|
|
86
|
+
private request;
|
|
87
|
+
/** 获取页面列表 */
|
|
88
|
+
listPages(params?: ListPagesParams): Promise<PaginatedApiResponse<PageDetail>>;
|
|
89
|
+
/** 获取页面详情 */
|
|
90
|
+
getPage(pageId: string): Promise<ApiResponse<PageDetail>>;
|
|
91
|
+
/** 创建页面 */
|
|
92
|
+
createPage(data: CreatePageRequest): Promise<ApiResponse<PageDetail>>;
|
|
93
|
+
/** 更新页面 */
|
|
94
|
+
updatePage(pageId: string, data: UpdatePageRequest): Promise<ApiResponse<PageDetail>>;
|
|
95
|
+
/** 删除页面 */
|
|
96
|
+
deletePage(pageId: string): Promise<ApiResponse<void>>;
|
|
97
|
+
/** 保存草稿 */
|
|
98
|
+
saveDraft(pageId: string, schema: PageSchema): Promise<ApiResponse<void>>;
|
|
99
|
+
/** 发布页面 */
|
|
100
|
+
publishPage(pageId: string, config: PublishConfig): Promise<ApiResponse<PublishResult>>;
|
|
101
|
+
/** 回滚页面 */
|
|
102
|
+
rollbackPage(pageId: string, versionId: string): Promise<ApiResponse<void>>;
|
|
103
|
+
/** 获取版本历史 */
|
|
104
|
+
getVersionHistory(pageId: string): Promise<ApiResponse<VersionInfo[]>>;
|
|
105
|
+
/** 获取组件列表 */
|
|
106
|
+
listComponents(params?: ListComponentsParams): Promise<PaginatedApiResponse<ComponentMeta>>;
|
|
107
|
+
/** 获取组件详情 */
|
|
108
|
+
getComponent(name: string, version?: string): Promise<ApiResponse<ComponentMeta>>;
|
|
109
|
+
/** 阻断组件版本 */
|
|
110
|
+
blockComponent(name: string, version: string, reason: string): Promise<ApiResponse<void>>;
|
|
111
|
+
/** 解除组件阻断 */
|
|
112
|
+
unblockComponent(name: string, version: string): Promise<ApiResponse<void>>;
|
|
113
|
+
/** 获取 ActionDefinition 列表 */
|
|
114
|
+
listActionDefinitions(): Promise<ApiResponse<ActionDefinition[]>>;
|
|
115
|
+
/** 创建 ActionDefinition */
|
|
116
|
+
createActionDefinition(data: Omit<ActionDefinition, 'id'>): Promise<ApiResponse<ActionDefinition>>;
|
|
117
|
+
/** 获取 DataQueryDefinition 列表 */
|
|
118
|
+
listDataQueryDefinitions(): Promise<ApiResponse<DataQueryDefinition[]>>;
|
|
119
|
+
/** 创建 DataQueryDefinition */
|
|
120
|
+
createDataQueryDefinition(data: Omit<DataQueryDefinition, 'id'>): Promise<ApiResponse<DataQueryDefinition>>;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* 创建 Admin API 客户端实例
|
|
124
|
+
*/
|
|
125
|
+
declare function createAdminClient(config: AdminClientConfig): AdminApiClient;
|
|
126
|
+
|
|
127
|
+
export { AdminApiClient, type AdminClientConfig, type CreatePageRequest, type ListComponentsParams, type ListPagesParams, type PageDetail, type PublishResult, type UpdatePageRequest, createAdminClient, AdminApiClient as default };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { ApiResponse, PaginatedApiResponse, PageSchema, PublishConfig, VersionInfo, ComponentMeta, ActionDefinition, DataQueryDefinition } from '@djvlc/contracts-types';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @djvlc/openapi-admin-client - Admin API 客户端
|
|
5
|
+
*
|
|
6
|
+
* 自动从 OpenAPI 规范生成,提供类型安全的 Admin API 访问
|
|
7
|
+
*
|
|
8
|
+
* @packageDocumentation
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
interface AdminClientConfig {
|
|
12
|
+
/** API 基础 URL */
|
|
13
|
+
baseUrl: string;
|
|
14
|
+
/** 认证 Token */
|
|
15
|
+
token?: string;
|
|
16
|
+
/** 请求超时(毫秒) */
|
|
17
|
+
timeout?: number;
|
|
18
|
+
/** 自定义请求头 */
|
|
19
|
+
headers?: Record<string, string>;
|
|
20
|
+
/** 请求拦截器 */
|
|
21
|
+
onRequest?: (config: RequestInit) => RequestInit;
|
|
22
|
+
/** 响应拦截器 */
|
|
23
|
+
onResponse?: <T>(response: ApiResponse<T>) => ApiResponse<T>;
|
|
24
|
+
/** 错误处理 */
|
|
25
|
+
onError?: (error: Error) => void;
|
|
26
|
+
}
|
|
27
|
+
/** 创建页面请求 */
|
|
28
|
+
interface CreatePageRequest {
|
|
29
|
+
title: string;
|
|
30
|
+
description?: string;
|
|
31
|
+
templateId?: string;
|
|
32
|
+
workspaceId?: string;
|
|
33
|
+
}
|
|
34
|
+
/** 更新页面请求 */
|
|
35
|
+
interface UpdatePageRequest {
|
|
36
|
+
title?: string;
|
|
37
|
+
description?: string;
|
|
38
|
+
schema?: PageSchema;
|
|
39
|
+
}
|
|
40
|
+
/** 页面列表查询参数 */
|
|
41
|
+
interface ListPagesParams {
|
|
42
|
+
page?: number;
|
|
43
|
+
pageSize?: number;
|
|
44
|
+
status?: 'draft' | 'published';
|
|
45
|
+
search?: string;
|
|
46
|
+
sortBy?: string;
|
|
47
|
+
sortOrder?: 'asc' | 'desc';
|
|
48
|
+
}
|
|
49
|
+
/** 页面详情响应 */
|
|
50
|
+
interface PageDetail {
|
|
51
|
+
id: string;
|
|
52
|
+
uid: string;
|
|
53
|
+
title: string;
|
|
54
|
+
description?: string;
|
|
55
|
+
status: 'draft' | 'published';
|
|
56
|
+
schema: PageSchema;
|
|
57
|
+
currentVersionId?: string;
|
|
58
|
+
createdAt: string;
|
|
59
|
+
updatedAt: string;
|
|
60
|
+
createdBy: string;
|
|
61
|
+
}
|
|
62
|
+
/** 组件列表查询参数 */
|
|
63
|
+
interface ListComponentsParams {
|
|
64
|
+
page?: number;
|
|
65
|
+
pageSize?: number;
|
|
66
|
+
category?: string;
|
|
67
|
+
status?: string;
|
|
68
|
+
search?: string;
|
|
69
|
+
}
|
|
70
|
+
/** 发布结果 */
|
|
71
|
+
interface PublishResult {
|
|
72
|
+
pageVersionId: string;
|
|
73
|
+
manifestId: string;
|
|
74
|
+
publishedAt: string;
|
|
75
|
+
channel: string;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Admin API 客户端类
|
|
79
|
+
*/
|
|
80
|
+
declare class AdminApiClient {
|
|
81
|
+
private config;
|
|
82
|
+
constructor(config: AdminClientConfig);
|
|
83
|
+
/**
|
|
84
|
+
* 发送请求
|
|
85
|
+
*/
|
|
86
|
+
private request;
|
|
87
|
+
/** 获取页面列表 */
|
|
88
|
+
listPages(params?: ListPagesParams): Promise<PaginatedApiResponse<PageDetail>>;
|
|
89
|
+
/** 获取页面详情 */
|
|
90
|
+
getPage(pageId: string): Promise<ApiResponse<PageDetail>>;
|
|
91
|
+
/** 创建页面 */
|
|
92
|
+
createPage(data: CreatePageRequest): Promise<ApiResponse<PageDetail>>;
|
|
93
|
+
/** 更新页面 */
|
|
94
|
+
updatePage(pageId: string, data: UpdatePageRequest): Promise<ApiResponse<PageDetail>>;
|
|
95
|
+
/** 删除页面 */
|
|
96
|
+
deletePage(pageId: string): Promise<ApiResponse<void>>;
|
|
97
|
+
/** 保存草稿 */
|
|
98
|
+
saveDraft(pageId: string, schema: PageSchema): Promise<ApiResponse<void>>;
|
|
99
|
+
/** 发布页面 */
|
|
100
|
+
publishPage(pageId: string, config: PublishConfig): Promise<ApiResponse<PublishResult>>;
|
|
101
|
+
/** 回滚页面 */
|
|
102
|
+
rollbackPage(pageId: string, versionId: string): Promise<ApiResponse<void>>;
|
|
103
|
+
/** 获取版本历史 */
|
|
104
|
+
getVersionHistory(pageId: string): Promise<ApiResponse<VersionInfo[]>>;
|
|
105
|
+
/** 获取组件列表 */
|
|
106
|
+
listComponents(params?: ListComponentsParams): Promise<PaginatedApiResponse<ComponentMeta>>;
|
|
107
|
+
/** 获取组件详情 */
|
|
108
|
+
getComponent(name: string, version?: string): Promise<ApiResponse<ComponentMeta>>;
|
|
109
|
+
/** 阻断组件版本 */
|
|
110
|
+
blockComponent(name: string, version: string, reason: string): Promise<ApiResponse<void>>;
|
|
111
|
+
/** 解除组件阻断 */
|
|
112
|
+
unblockComponent(name: string, version: string): Promise<ApiResponse<void>>;
|
|
113
|
+
/** 获取 ActionDefinition 列表 */
|
|
114
|
+
listActionDefinitions(): Promise<ApiResponse<ActionDefinition[]>>;
|
|
115
|
+
/** 创建 ActionDefinition */
|
|
116
|
+
createActionDefinition(data: Omit<ActionDefinition, 'id'>): Promise<ApiResponse<ActionDefinition>>;
|
|
117
|
+
/** 获取 DataQueryDefinition 列表 */
|
|
118
|
+
listDataQueryDefinitions(): Promise<ApiResponse<DataQueryDefinition[]>>;
|
|
119
|
+
/** 创建 DataQueryDefinition */
|
|
120
|
+
createDataQueryDefinition(data: Omit<DataQueryDefinition, 'id'>): Promise<ApiResponse<DataQueryDefinition>>;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* 创建 Admin API 客户端实例
|
|
124
|
+
*/
|
|
125
|
+
declare function createAdminClient(config: AdminClientConfig): AdminApiClient;
|
|
126
|
+
|
|
127
|
+
export { AdminApiClient, type AdminClientConfig, type CreatePageRequest, type ListComponentsParams, type ListPagesParams, type PageDetail, type PublishResult, type UpdatePageRequest, createAdminClient, AdminApiClient as default };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,167 @@
|
|
|
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
|
+
AdminApiClient: () => AdminApiClient,
|
|
24
|
+
createAdminClient: () => createAdminClient,
|
|
25
|
+
default: () => index_default
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(index_exports);
|
|
28
|
+
var AdminApiClient = class {
|
|
29
|
+
constructor(config) {
|
|
30
|
+
this.config = {
|
|
31
|
+
timeout: 3e4,
|
|
32
|
+
...config
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* 发送请求
|
|
37
|
+
*/
|
|
38
|
+
async request(method, path, options) {
|
|
39
|
+
let url = `${this.config.baseUrl}${path}`;
|
|
40
|
+
if (options?.params) {
|
|
41
|
+
const searchParams = new URLSearchParams();
|
|
42
|
+
Object.entries(options.params).forEach(([key, value]) => {
|
|
43
|
+
if (value !== void 0) {
|
|
44
|
+
searchParams.append(key, String(value));
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
const queryString = searchParams.toString();
|
|
48
|
+
if (queryString) {
|
|
49
|
+
url += `?${queryString}`;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
let requestConfig = {
|
|
53
|
+
method,
|
|
54
|
+
headers: {
|
|
55
|
+
"Content-Type": "application/json",
|
|
56
|
+
...this.config.token ? { Authorization: `Bearer ${this.config.token}` } : {},
|
|
57
|
+
...this.config.headers
|
|
58
|
+
},
|
|
59
|
+
body: options?.body ? JSON.stringify(options.body) : void 0
|
|
60
|
+
};
|
|
61
|
+
if (this.config.onRequest) {
|
|
62
|
+
requestConfig = this.config.onRequest(requestConfig);
|
|
63
|
+
}
|
|
64
|
+
try {
|
|
65
|
+
const controller = new AbortController();
|
|
66
|
+
const timeoutId = setTimeout(() => controller.abort(), this.config.timeout);
|
|
67
|
+
const response = await fetch(url, {
|
|
68
|
+
...requestConfig,
|
|
69
|
+
signal: controller.signal
|
|
70
|
+
});
|
|
71
|
+
clearTimeout(timeoutId);
|
|
72
|
+
let result = await response.json();
|
|
73
|
+
if (this.config.onResponse) {
|
|
74
|
+
result = this.config.onResponse(result);
|
|
75
|
+
}
|
|
76
|
+
return result;
|
|
77
|
+
} catch (error) {
|
|
78
|
+
if (this.config.onError) {
|
|
79
|
+
this.config.onError(error);
|
|
80
|
+
}
|
|
81
|
+
throw error;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
// ==================== 页面管理 ====================
|
|
85
|
+
/** 获取页面列表 */
|
|
86
|
+
async listPages(params) {
|
|
87
|
+
return this.request("GET", "/api/admin/pages", { params });
|
|
88
|
+
}
|
|
89
|
+
/** 获取页面详情 */
|
|
90
|
+
async getPage(pageId) {
|
|
91
|
+
return this.request("GET", `/api/admin/pages/${pageId}`);
|
|
92
|
+
}
|
|
93
|
+
/** 创建页面 */
|
|
94
|
+
async createPage(data) {
|
|
95
|
+
return this.request("POST", "/api/admin/pages", { body: data });
|
|
96
|
+
}
|
|
97
|
+
/** 更新页面 */
|
|
98
|
+
async updatePage(pageId, data) {
|
|
99
|
+
return this.request("PUT", `/api/admin/pages/${pageId}`, { body: data });
|
|
100
|
+
}
|
|
101
|
+
/** 删除页面 */
|
|
102
|
+
async deletePage(pageId) {
|
|
103
|
+
return this.request("DELETE", `/api/admin/pages/${pageId}`);
|
|
104
|
+
}
|
|
105
|
+
/** 保存草稿 */
|
|
106
|
+
async saveDraft(pageId, schema) {
|
|
107
|
+
return this.request("POST", `/api/admin/pages/${pageId}/draft`, { body: { schema } });
|
|
108
|
+
}
|
|
109
|
+
/** 发布页面 */
|
|
110
|
+
async publishPage(pageId, config) {
|
|
111
|
+
return this.request("POST", `/api/admin/pages/${pageId}/publish`, { body: config });
|
|
112
|
+
}
|
|
113
|
+
/** 回滚页面 */
|
|
114
|
+
async rollbackPage(pageId, versionId) {
|
|
115
|
+
return this.request("POST", `/api/admin/pages/${pageId}/rollback`, { body: { versionId } });
|
|
116
|
+
}
|
|
117
|
+
/** 获取版本历史 */
|
|
118
|
+
async getVersionHistory(pageId) {
|
|
119
|
+
return this.request("GET", `/api/admin/pages/${pageId}/versions`);
|
|
120
|
+
}
|
|
121
|
+
// ==================== 组件管理 ====================
|
|
122
|
+
/** 获取组件列表 */
|
|
123
|
+
async listComponents(params) {
|
|
124
|
+
return this.request("GET", "/api/admin/components", { params });
|
|
125
|
+
}
|
|
126
|
+
/** 获取组件详情 */
|
|
127
|
+
async getComponent(name, version) {
|
|
128
|
+
const path = version ? `/api/admin/components/${name}/versions/${version}` : `/api/admin/components/${name}`;
|
|
129
|
+
return this.request("GET", path);
|
|
130
|
+
}
|
|
131
|
+
/** 阻断组件版本 */
|
|
132
|
+
async blockComponent(name, version, reason) {
|
|
133
|
+
return this.request("POST", `/api/admin/components/${name}/versions/${version}/block`, {
|
|
134
|
+
body: { reason }
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
/** 解除组件阻断 */
|
|
138
|
+
async unblockComponent(name, version) {
|
|
139
|
+
return this.request("POST", `/api/admin/components/${name}/versions/${version}/unblock`);
|
|
140
|
+
}
|
|
141
|
+
// ==================== Definition 管理 ====================
|
|
142
|
+
/** 获取 ActionDefinition 列表 */
|
|
143
|
+
async listActionDefinitions() {
|
|
144
|
+
return this.request("GET", "/api/admin/definitions/actions");
|
|
145
|
+
}
|
|
146
|
+
/** 创建 ActionDefinition */
|
|
147
|
+
async createActionDefinition(data) {
|
|
148
|
+
return this.request("POST", "/api/admin/definitions/actions", { body: data });
|
|
149
|
+
}
|
|
150
|
+
/** 获取 DataQueryDefinition 列表 */
|
|
151
|
+
async listDataQueryDefinitions() {
|
|
152
|
+
return this.request("GET", "/api/admin/definitions/queries");
|
|
153
|
+
}
|
|
154
|
+
/** 创建 DataQueryDefinition */
|
|
155
|
+
async createDataQueryDefinition(data) {
|
|
156
|
+
return this.request("POST", "/api/admin/definitions/queries", { body: data });
|
|
157
|
+
}
|
|
158
|
+
};
|
|
159
|
+
function createAdminClient(config) {
|
|
160
|
+
return new AdminApiClient(config);
|
|
161
|
+
}
|
|
162
|
+
var index_default = AdminApiClient;
|
|
163
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
164
|
+
0 && (module.exports = {
|
|
165
|
+
AdminApiClient,
|
|
166
|
+
createAdminClient
|
|
167
|
+
});
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
var AdminApiClient = class {
|
|
3
|
+
constructor(config) {
|
|
4
|
+
this.config = {
|
|
5
|
+
timeout: 3e4,
|
|
6
|
+
...config
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* 发送请求
|
|
11
|
+
*/
|
|
12
|
+
async request(method, path, options) {
|
|
13
|
+
let url = `${this.config.baseUrl}${path}`;
|
|
14
|
+
if (options?.params) {
|
|
15
|
+
const searchParams = new URLSearchParams();
|
|
16
|
+
Object.entries(options.params).forEach(([key, value]) => {
|
|
17
|
+
if (value !== void 0) {
|
|
18
|
+
searchParams.append(key, String(value));
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
const queryString = searchParams.toString();
|
|
22
|
+
if (queryString) {
|
|
23
|
+
url += `?${queryString}`;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
let requestConfig = {
|
|
27
|
+
method,
|
|
28
|
+
headers: {
|
|
29
|
+
"Content-Type": "application/json",
|
|
30
|
+
...this.config.token ? { Authorization: `Bearer ${this.config.token}` } : {},
|
|
31
|
+
...this.config.headers
|
|
32
|
+
},
|
|
33
|
+
body: options?.body ? JSON.stringify(options.body) : void 0
|
|
34
|
+
};
|
|
35
|
+
if (this.config.onRequest) {
|
|
36
|
+
requestConfig = this.config.onRequest(requestConfig);
|
|
37
|
+
}
|
|
38
|
+
try {
|
|
39
|
+
const controller = new AbortController();
|
|
40
|
+
const timeoutId = setTimeout(() => controller.abort(), this.config.timeout);
|
|
41
|
+
const response = await fetch(url, {
|
|
42
|
+
...requestConfig,
|
|
43
|
+
signal: controller.signal
|
|
44
|
+
});
|
|
45
|
+
clearTimeout(timeoutId);
|
|
46
|
+
let result = await response.json();
|
|
47
|
+
if (this.config.onResponse) {
|
|
48
|
+
result = this.config.onResponse(result);
|
|
49
|
+
}
|
|
50
|
+
return result;
|
|
51
|
+
} catch (error) {
|
|
52
|
+
if (this.config.onError) {
|
|
53
|
+
this.config.onError(error);
|
|
54
|
+
}
|
|
55
|
+
throw error;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
// ==================== 页面管理 ====================
|
|
59
|
+
/** 获取页面列表 */
|
|
60
|
+
async listPages(params) {
|
|
61
|
+
return this.request("GET", "/api/admin/pages", { params });
|
|
62
|
+
}
|
|
63
|
+
/** 获取页面详情 */
|
|
64
|
+
async getPage(pageId) {
|
|
65
|
+
return this.request("GET", `/api/admin/pages/${pageId}`);
|
|
66
|
+
}
|
|
67
|
+
/** 创建页面 */
|
|
68
|
+
async createPage(data) {
|
|
69
|
+
return this.request("POST", "/api/admin/pages", { body: data });
|
|
70
|
+
}
|
|
71
|
+
/** 更新页面 */
|
|
72
|
+
async updatePage(pageId, data) {
|
|
73
|
+
return this.request("PUT", `/api/admin/pages/${pageId}`, { body: data });
|
|
74
|
+
}
|
|
75
|
+
/** 删除页面 */
|
|
76
|
+
async deletePage(pageId) {
|
|
77
|
+
return this.request("DELETE", `/api/admin/pages/${pageId}`);
|
|
78
|
+
}
|
|
79
|
+
/** 保存草稿 */
|
|
80
|
+
async saveDraft(pageId, schema) {
|
|
81
|
+
return this.request("POST", `/api/admin/pages/${pageId}/draft`, { body: { schema } });
|
|
82
|
+
}
|
|
83
|
+
/** 发布页面 */
|
|
84
|
+
async publishPage(pageId, config) {
|
|
85
|
+
return this.request("POST", `/api/admin/pages/${pageId}/publish`, { body: config });
|
|
86
|
+
}
|
|
87
|
+
/** 回滚页面 */
|
|
88
|
+
async rollbackPage(pageId, versionId) {
|
|
89
|
+
return this.request("POST", `/api/admin/pages/${pageId}/rollback`, { body: { versionId } });
|
|
90
|
+
}
|
|
91
|
+
/** 获取版本历史 */
|
|
92
|
+
async getVersionHistory(pageId) {
|
|
93
|
+
return this.request("GET", `/api/admin/pages/${pageId}/versions`);
|
|
94
|
+
}
|
|
95
|
+
// ==================== 组件管理 ====================
|
|
96
|
+
/** 获取组件列表 */
|
|
97
|
+
async listComponents(params) {
|
|
98
|
+
return this.request("GET", "/api/admin/components", { params });
|
|
99
|
+
}
|
|
100
|
+
/** 获取组件详情 */
|
|
101
|
+
async getComponent(name, version) {
|
|
102
|
+
const path = version ? `/api/admin/components/${name}/versions/${version}` : `/api/admin/components/${name}`;
|
|
103
|
+
return this.request("GET", path);
|
|
104
|
+
}
|
|
105
|
+
/** 阻断组件版本 */
|
|
106
|
+
async blockComponent(name, version, reason) {
|
|
107
|
+
return this.request("POST", `/api/admin/components/${name}/versions/${version}/block`, {
|
|
108
|
+
body: { reason }
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
/** 解除组件阻断 */
|
|
112
|
+
async unblockComponent(name, version) {
|
|
113
|
+
return this.request("POST", `/api/admin/components/${name}/versions/${version}/unblock`);
|
|
114
|
+
}
|
|
115
|
+
// ==================== Definition 管理 ====================
|
|
116
|
+
/** 获取 ActionDefinition 列表 */
|
|
117
|
+
async listActionDefinitions() {
|
|
118
|
+
return this.request("GET", "/api/admin/definitions/actions");
|
|
119
|
+
}
|
|
120
|
+
/** 创建 ActionDefinition */
|
|
121
|
+
async createActionDefinition(data) {
|
|
122
|
+
return this.request("POST", "/api/admin/definitions/actions", { body: data });
|
|
123
|
+
}
|
|
124
|
+
/** 获取 DataQueryDefinition 列表 */
|
|
125
|
+
async listDataQueryDefinitions() {
|
|
126
|
+
return this.request("GET", "/api/admin/definitions/queries");
|
|
127
|
+
}
|
|
128
|
+
/** 创建 DataQueryDefinition */
|
|
129
|
+
async createDataQueryDefinition(data) {
|
|
130
|
+
return this.request("POST", "/api/admin/definitions/queries", { body: data });
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
function createAdminClient(config) {
|
|
134
|
+
return new AdminApiClient(config);
|
|
135
|
+
}
|
|
136
|
+
var index_default = AdminApiClient;
|
|
137
|
+
export {
|
|
138
|
+
AdminApiClient,
|
|
139
|
+
createAdminClient,
|
|
140
|
+
index_default as default
|
|
141
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@djvlc/openapi-admin-client",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "DJV Low-code Platform - Admin 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
|
+
"generate": "openapi-typescript ../specs/admin-api.yaml -o src/types.ts && npm run build",
|
|
21
|
+
"dev": "tsup src/index.ts --format cjs,esm --dts --watch",
|
|
22
|
+
"lint": "eslint src/ --ext .ts",
|
|
23
|
+
"typecheck": "tsc --noEmit",
|
|
24
|
+
"clean": "rimraf dist",
|
|
25
|
+
"prepublishOnly": "pnpm run build"
|
|
26
|
+
},
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"@djvlc/contracts-types": "1.0.0"
|
|
29
|
+
},
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"@types/node": "^20.0.0",
|
|
32
|
+
"@typescript-eslint/eslint-plugin": "^7.0.0",
|
|
33
|
+
"@typescript-eslint/parser": "^7.0.0",
|
|
34
|
+
"eslint": "^8.56.0",
|
|
35
|
+
"openapi-typescript": "^6.0.0",
|
|
36
|
+
"rimraf": "^5.0.0",
|
|
37
|
+
"tsup": "^8.0.0",
|
|
38
|
+
"typescript": "^5.3.0"
|
|
39
|
+
},
|
|
40
|
+
"keywords": [
|
|
41
|
+
"lowcode",
|
|
42
|
+
"openapi",
|
|
43
|
+
"client",
|
|
44
|
+
"admin-api",
|
|
45
|
+
"djvlc"
|
|
46
|
+
],
|
|
47
|
+
"author": "DJV Team",
|
|
48
|
+
"license": "MIT",
|
|
49
|
+
"repository": {
|
|
50
|
+
"type": "git",
|
|
51
|
+
"url": "git+https://github.com/djvlc/contracts.git",
|
|
52
|
+
"directory": "openapi/admin-client"
|
|
53
|
+
},
|
|
54
|
+
"publishConfig": {
|
|
55
|
+
"access": "public",
|
|
56
|
+
"registry": "https://registry.npmjs.org/"
|
|
57
|
+
},
|
|
58
|
+
"engines": {
|
|
59
|
+
"node": ">=18.0.0"
|
|
60
|
+
}
|
|
61
|
+
}
|