@sun-panel/micro-app 1.0.5 → 1.0.6

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,9 +1,53 @@
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
 
8
+ /**
9
+ * 微应用错误类型
10
+ */
11
+ export class MicroAppNetworkRequestError extends Error {
12
+ type: 'microApp' | 'targetUrl' | 'unknown'
13
+ response?: AxiosResponse
14
+
15
+ constructor(message: string, type: 'microApp' | 'targetUrl' | 'unknown' = 'unknown', response?: any) {
16
+ super(message)
17
+ this.name = 'MicroAppNetworkRequestError'
18
+ this.type = type
19
+ this.response = response
20
+ }
21
+ }
22
+
23
+ /**
24
+ * 数据节点错误类型
25
+ */
26
+ export class MicroDataNodeError extends Error {
27
+ code: string | number
28
+ response?: AxiosResponse
29
+
30
+ constructor(message: string, code: string | number, response?: any) {
31
+ super(message)
32
+ this.name = 'MicroDataNodeError'
33
+ this.code = code
34
+ this.response = response
35
+ }
36
+ }
37
+
38
+
39
+ /**
40
+ * 高级代理请求参数
41
+ */
42
+ export interface AdvancedProxyRequest {
43
+ targetUrl: string
44
+ method?: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH'
45
+ headers?: Record<string, string>
46
+ body?: any
47
+ timeout?: number
48
+ [key: string]: any
49
+ }
50
+
7
51
  /**
8
52
  * 窗口配置
9
53
  */
@@ -30,57 +74,8 @@ export interface OpenWindowOptions {
30
74
  * 窗口初始化参数
31
75
  */
32
76
  export interface PageInitializedParam {
33
- widgetInfo?: WidgetInfo;
34
- customParam: any;
35
- }
36
-
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
- }
59
-
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;
77
+ widgetInfo?: WidgetInfo
78
+ customParam: any
84
79
  }
85
80
 
86
81
  /**
@@ -94,127 +89,54 @@ export interface MicroAppAPI {
94
89
  * @param param 窗口参数
95
90
  * @returns 窗口ID
96
91
  */
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
- };
92
+ open: (options: OpenWindowOptions) => string
93
+ // close: (windowId: string) => boolean
94
+ // toggle: (windowId: string) => boolean
95
+ }
113
96
 
114
97
  // 缓存管理
115
98
  localCache: {
116
- // 用户级缓存
99
+ // 用户缓存
117
100
  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
-
101
+ get: (key: string) => Promise<any>
102
+ set: (key: string, value: any, expireTimestamp?: number) => Promise<void>
103
+ del: (key: string) => Promise<void>
104
+ clear: () => Promise<void>
105
+ getKeys: () => Promise<string[]>
106
+ // getWithCache: <T>(
107
+ // key: string,
108
+ // apiCall: () => Promise<T>,
109
+ // expireTimestamp?: number,
110
+ // ) => Promise<T>
111
+ }
161
112
  // 应用级缓存
162
113
  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
- };
114
+ get: (key: string) => Promise<any>
115
+ set: (key: string, value: any, expireTimestamp?: number) => Promise<void>
116
+ del: (key: string) => Promise<void>
117
+ clear: () => Promise<void>
118
+ getKeys: () => Promise<string[]>
119
+ // getWithCache: <T>(
120
+ // key: string,
121
+ // apiCall: () => Promise<T>,
122
+ // expireTimestamp?: number,
123
+ // ) => Promise<T>
124
+ }
125
+ }
206
126
 
207
127
  // 数据节点
208
128
  dataNode: {
209
129
  // 用户数据节点
210
130
  user: {
211
131
  getByKey: <T = any>(node: string, key: string) => Promise<T>
132
+ getByKeys: <T = any>(node: string, keys: string[]) => Promise<T>
212
133
  setByKey: <T = any>(node: string, key: string, value: Record<string, any>) => Promise<T>
213
134
  delByKey: <T = any>(node: string, key: string) => Promise<T>
214
135
  }
215
136
  // 应用级数据节点
216
137
  app: {
217
138
  getByKey: <T = any>(node: string, key: string) => Promise<T>
139
+ getByKeys: <T = any>(node: string, keys: string[]) => Promise<T>
218
140
  setByKey: <T = any>(node: string, key: string, value: Record<string, any>) => Promise<T>
219
141
  delByKey: <T = any>(node: string, key: string) => Promise<T>
220
142
  }
@@ -223,45 +145,30 @@ export interface MicroAppAPI {
223
145
 
224
146
  // 网络透传
225
147
  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
- };
148
+ request: <T = any>(params: AdvancedProxyRequest) => Promise<T>
149
+ // batchRequest: <T = any>(params: AdvancedBatchProxyRequest) => Promise<T>
150
+ // smartBatchRequest: <T = any>(
151
+ // requests: AdvancedProxyItem[],
152
+ // batchSize?: number,
153
+ // ) => Promise<T[]>
154
+ }
248
155
 
249
156
 
250
157
  widget: {
251
- save: <T = any>(data: WidgetInfo) => Promise<T>
158
+ save: <T = any>(data: WidgetInfo, closeWindowAfterSuccess?: boolean) => Promise<T>
252
159
  },
253
160
 
254
- // 状态(只读)
255
- state: {
256
- /**
257
- * 当前窗口数量
258
- */
259
- windowCount: number;
260
-
261
- /**
262
- * 可见窗口数量
263
- */
264
- visibleWindows: number;
265
- };
161
+ // // 状态(只读)
162
+ // state: {
163
+ // /**
164
+ // * 当前窗口数量
165
+ // */
166
+ // windowCount: number;
167
+
168
+ // /**
169
+ // * 可见窗口数量
170
+ // */
171
+ // visibleWindows: number;
172
+ // };
266
173
  }
267
174
 
@@ -5,20 +5,20 @@ 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
15
  }
16
16
 
17
17
  export interface SpContextWidget extends SpContext {
18
18
  // itemInfo: ItemInfo;
19
- background: string;
19
+ // background: string;
20
20
  widgetInfo: WidgetInfo;
21
- gridSizeType: GridSizeType;
21
+ // gridSizeType: GridSizeType;
22
22
  }
23
23
 
24
24
  export interface SpContextPage extends SpContext {
@@ -33,7 +33,8 @@ export interface WidgetInfo {
33
33
  widgetId: string // 小部件ID
34
34
  background?: string // 背景颜色
35
35
  config: Record<string, any> // 配置
36
- privateConfig: Record<string, any> // 私有配置
36
+ gridSize: string
37
+ title: string
37
38
  }
38
39
 
39
40
 
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.6",
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",