@sun-panel/micro-app 1.0.5 → 1.0.7

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.
@@ -1,267 +1,139 @@
1
- import { WidgetInfo } from './common.js';
1
+ import type { AxiosResponse } from 'axios'
2
+ import { WidgetInfo } from './common.js'
2
3
 
3
4
  /**
4
5
  * 微应用 API 类型定义
5
6
  */
6
7
 
7
- /**
8
- * 窗口配置
9
- */
10
- export interface WindowConfig {
11
- height?: number
12
- width?: number
13
- left?: number
14
- top?: number
15
- isFullScreen?: boolean
16
- background?: string
17
- }
8
+ // ========== 请求类型 ==========
18
9
 
19
- /**
20
- * 打开窗口参数
21
- */
22
- export interface OpenWindowOptions {
23
- componentName: string // 必需:组件名
24
- windowConfig?: WindowConfig // 可选:窗口配置
25
- customParam?: any // 可选:自定义参数
26
- title?: string // 可选:窗口标题
10
+ interface RequestOptions {
11
+ targetUrl: string
12
+ method?: string
13
+ headers?: Record<string, string>
14
+ body?: string
15
+ templateReplacements: TemplateReplacementRule[]
27
16
  }
28
-
29
- /**
30
- * 窗口初始化参数
31
- */
32
- export interface PageInitializedParam {
33
- widgetInfo?: WidgetInfo;
34
- customParam: any;
17
+ export interface TemplateReplacementRule {
18
+ placeholder: string // 要替换的字符,用户自定义,如 "{{token}}"
19
+ fields: string[] // 替换参数,可选:targetUrl, method, headers, body
20
+ dataNode: string // 数据节点路径,如 "config.token"
35
21
  }
36
22
 
37
- /**
38
- * 高级代理请求参数
39
- */
40
- export interface AdvancedProxyRequest {
41
- url: string;
42
- method?: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
43
- headers?: Record<string, string>;
44
- body?: any;
45
- timeout?: number;
46
- [key: string]: any;
47
- }
48
-
49
- /**
50
- * 高级代理请求项
51
- */
52
- export interface AdvancedProxyItem {
53
- url: string;
54
- method?: string;
55
- headers?: Record<string, string>;
56
- body?: any;
57
- [key: string]: any;
58
- }
23
+ // ========== 微应用 API 接口 ==========
59
24
 
60
- /**
61
- * 批量代理请求参数
62
- */
63
- export interface AdvancedBatchProxyRequest {
64
- requests: AdvancedProxyItem[];
65
- parallel?: boolean;
66
- [key: string]: any;
67
- }
68
-
69
- /**
70
- * 保存数据节点请求
71
- */
72
- export interface SaveDataNodeRequest {
73
- node: string;
74
- data: any;
75
- [key: string]: any;
76
- }
77
-
78
- /**
79
- * 获取数据节点请求
80
- */
81
- export interface GetDataNodeRequest {
82
- node: string;
83
- [key: string]: any;
84
- }
85
-
86
- /**
87
- * 微应用 API 接口定义
88
- */
89
25
  export interface MicroAppAPI {
90
26
  // 窗口管理
91
27
  window: {
92
- /**
93
- * 打开窗口
94
- * @param param 窗口参数
95
- * @returns 窗口ID
96
- */
97
- open: (options: OpenWindowOptions) => string;
98
-
99
- /**
100
- * 关闭窗口
101
- * @param windowId 窗口ID
102
- * @returns 是否成功
103
- */
104
- close: (windowId: string) => boolean;
105
-
106
- /**
107
- * 切换窗口显示/隐藏
108
- * @param windowId 窗口ID
109
- * @returns 是否成功
110
- */
111
- toggle: (windowId: string) => boolean;
112
- };
28
+ open: (options: OpenWindowOptions) => string
29
+ // close: (windowId: string) => boolean
30
+ // toggle: (windowId: string) => boolean
31
+ }
113
32
 
114
33
  // 缓存管理
115
34
  localCache: {
116
- // 用户级缓存
35
+ // 用户缓存
117
36
  user: {
118
- /**
119
- * 获取缓存值
120
- * @param key 缓存键
121
- */
122
- get: (key: string) => Promise<any>;
123
-
124
- /**
125
- * 设置缓存值
126
- * @param key 缓存键
127
- * @param value 缓存值
128
- * @param expireTimestamp 过期时间戳(秒),0表示不过期
129
- */
130
- set: (key: string, value: any, expireTimestamp?: number) => Promise<void>;
131
-
132
- /**
133
- * 删除缓存
134
- * @param key 缓存键
135
- */
136
- del: (key: string) => Promise<void>;
137
-
138
- /**
139
- * 清空所有用户缓存
140
- */
141
- clear: () => Promise<void>;
142
-
143
- /**
144
- * 获取所有缓存键
145
- */
146
- getKeys: () => Promise<string[]>;
147
-
148
- /**
149
- * 获取数据并缓存(如果缓存不存在则调用API)
150
- * @param key 缓存键
151
- * @param apiCall API调用函数
152
- * @param expireTimestamp 过期时间(秒)
153
- */
154
- getWithCache: <T>(
155
- key: string,
156
- apiCall: () => Promise<T>,
157
- expireTimestamp?: number,
158
- ) => Promise<T>;
159
- };
160
-
37
+ get: (key: string) => Promise<any>
38
+ set: (key: string, value: any, expireTimestamp?: number) => Promise<void>
39
+ del: (key: string) => Promise<void>
40
+ clear: () => Promise<void>
41
+ getKeys: () => Promise<string[]>
42
+ // getWithCache: <T>(
43
+ // key: string,
44
+ // apiCall: () => Promise<T>,
45
+ // expireTimestamp?: number,
46
+ // ) => Promise<T>
47
+ }
161
48
  // 应用级缓存
162
49
  app: {
163
- /**
164
- * 获取缓存值
165
- * @param key 缓存键
166
- */
167
- get: (key: string) => Promise<any>;
168
-
169
- /**
170
- * 设置缓存值
171
- * @param key 缓存键
172
- * @param value 缓存值
173
- * @param expireTimestamp 过期时间戳(秒),0表示不过期
174
- */
175
- set: (key: string, value: any, expireTimestamp?: number) => Promise<void>;
176
-
177
- /**
178
- * 删除缓存
179
- * @param key 缓存键
180
- */
181
- del: (key: string) => Promise<void>;
182
-
183
- /**
184
- * 清空所有应用缓存
185
- */
186
- clear: () => Promise<void>;
187
-
188
- /**
189
- * 获取所有缓存键
190
- */
191
- getKeys: () => Promise<string[]>;
192
-
193
- /**
194
- * 获取数据并缓存(如果缓存不存在则调用API)
195
- * @param key 缓存键
196
- * @param apiCall API调用函数
197
- * @param expireTimestamp 过期时间(秒)
198
- */
199
- getWithCache: <T>(
200
- key: string,
201
- apiCall: () => Promise<T>,
202
- expireTimestamp?: number,
203
- ) => Promise<T>;
204
- };
205
- };
50
+ get: (key: string) => Promise<any>
51
+ set: (key: string, value: any, expireTimestamp?: number) => Promise<void>
52
+ del: (key: string) => Promise<void>
53
+ clear: () => Promise<void>
54
+ getKeys: () => Promise<string[]>
55
+ // getWithCache: <T>(
56
+ // key: string,
57
+ // apiCall: () => Promise<T>,
58
+ // expireTimestamp?: number,
59
+ // ) => Promise<T>
60
+ }
61
+ }
206
62
 
207
63
  // 数据节点
208
64
  dataNode: {
209
65
  // 用户数据节点
210
66
  user: {
211
67
  getByKey: <T = any>(node: string, key: string) => Promise<T>
68
+ getByKeys: <T = any>(node: string, keys: string[]) => Promise<T>
212
69
  setByKey: <T = any>(node: string, key: string, value: Record<string, any>) => Promise<T>
213
70
  delByKey: <T = any>(node: string, key: string) => Promise<T>
214
71
  }
215
72
  // 应用级数据节点
216
73
  app: {
217
74
  getByKey: <T = any>(node: string, key: string) => Promise<T>
75
+ getByKeys: <T = any>(node: string, keys: string[]) => Promise<T>
218
76
  setByKey: <T = any>(node: string, key: string, value: Record<string, any>) => Promise<T>
219
77
  delByKey: <T = any>(node: string, key: string) => Promise<T>
220
78
  }
221
79
  }
222
80
 
223
-
224
81
  // 网络透传
225
82
  network: {
226
- /**
227
- * 发送单个请求
228
- * @param params 请求参数
229
- */
230
- request: <T = any>(params: AdvancedProxyRequest) => Promise<T>;
231
-
232
- /**
233
- * 批量发送请求
234
- * @param params 批量请求参数
235
- */
236
- batchRequest: <T = any>(params: AdvancedBatchProxyRequest) => Promise<T>;
237
-
238
- /**
239
- * 智能批量请求(自动分批)
240
- * @param requests 请求列表
241
- * @param batchSize 每批数量
242
- */
243
- smartBatchRequest: <T = any>(
244
- requests: AdvancedProxyItem[],
245
- batchSize?: number,
246
- ) => Promise<T[]>;
247
- };
248
-
83
+ request: <T = any>(params: RequestOptions) => Promise<T>
84
+ // batchRequest: <T = any>(params: MicroApp.ApiRequest.AdvancedBatchProxyRequest) => Promise<T>
85
+ // smartBatchRequest: <T = any>(
86
+ // requests: MicroApp.ApiRequest.AdvancedProxyItem[],
87
+ // batchSize?: number,
88
+ // ) => Promise<T[]>
89
+ }
249
90
 
91
+ // 小部件
250
92
  widget: {
251
93
  save: <T = any>(data: WidgetInfo) => Promise<T>
252
94
  },
95
+ }
253
96
 
254
- // 状态(只读)
255
- state: {
256
- /**
257
- * 当前窗口数量
258
- */
259
- windowCount: number;
97
+ // ========== 窗口相关类型 ==========
260
98
 
261
- /**
262
- * 可见窗口数量
263
- */
264
- visibleWindows: number;
265
- };
99
+ export interface WindowConfig {
100
+ height?: number
101
+ width?: number
102
+ left?: number
103
+ top?: number
104
+ isFullScreen?: boolean
105
+ background?: string
266
106
  }
267
107
 
108
+ export interface OpenWindowOptions {
109
+ componentName: string // 必需:组件名
110
+ windowConfig?: WindowConfig // 可选:窗口配置
111
+ customParam?: any // 可选:自定义参数
112
+ title?: string // 可选:窗口标题
113
+ }
114
+
115
+ // ========== 错误类型 ==========
116
+
117
+ export class MicroAppNetworkRequestError extends Error {
118
+ type: 'microApp' | 'targetUrl' | 'unknown'
119
+ response?: AxiosResponse
120
+
121
+ constructor(message: string, type: 'microApp' | 'targetUrl' | 'unknown' = 'unknown', response?: any) {
122
+ super(message)
123
+ this.name = 'MicroAppNetworkRequestError'
124
+ this.type = type
125
+ this.response = response
126
+ }
127
+ }
128
+
129
+ export class MicroDataNodeError extends Error {
130
+ code: string | number
131
+ response?: AxiosResponse
132
+
133
+ constructor(message: string, code: string | number, response?: any) {
134
+ super(message)
135
+ this.name = 'MicroDataNodeError'
136
+ this.code = code
137
+ this.response = response
138
+ }
139
+ }
@@ -5,20 +5,25 @@ import { MicroAppAPI } from './api';
5
5
 
6
6
  export interface SpContext {
7
7
  api: MicroAppAPI;
8
- isDark: boolean;
8
+ darkMode: boolean;
9
9
  language: string;
10
10
  networkMode: string;
11
11
  staticPath: string;
12
12
  role: number;
13
13
  // size: { width: number; height: number };
14
- [key: string]: any;
14
+ // [key: string]: any;
15
+ }
16
+
17
+ export interface PageInitializedParam {
18
+ widgetInfo?: WidgetInfo
19
+ customParam: any
15
20
  }
16
21
 
17
22
  export interface SpContextWidget extends SpContext {
18
23
  // itemInfo: ItemInfo;
19
- background: string;
24
+ // background: string;
20
25
  widgetInfo: WidgetInfo;
21
- gridSizeType: GridSizeType;
26
+ // gridSizeType: GridSizeType;
22
27
  }
23
28
 
24
29
  export interface SpContextPage extends SpContext {
@@ -33,7 +38,8 @@ export interface WidgetInfo {
33
38
  widgetId: string // 小部件ID
34
39
  background?: string // 背景颜色
35
40
  config: Record<string, any> // 配置
36
- privateConfig: Record<string, any> // 私有配置
41
+ gridSize: string
42
+ title: string
37
43
  }
38
44
 
39
45
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sun-panel/micro-app",
3
- "version": "1.0.5",
3
+ "version": "1.0.7",
4
4
  "description": "Sun Panel Micro App - A Lit-based framework for developing micro applications with built-in event binding and validation support",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.esm.js",