@tinywork/glass 1.0.2 → 1.0.4
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/package.json +1 -1
- package/src/index.ts +474 -543
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -1,561 +1,492 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* The cookie that was changed.
|
|
19
|
-
*/
|
|
20
|
-
cookie: Cookie,
|
|
21
|
-
/**
|
|
22
|
-
* The cause of the change with one of the following values:
|
|
23
|
-
*/
|
|
24
|
-
cause:
|
|
25
|
-
| "explicit"
|
|
26
|
-
| "overwrite"
|
|
27
|
-
| "expired"
|
|
28
|
-
| "evicted"
|
|
29
|
-
| "expired-overwrite",
|
|
30
|
-
/**
|
|
31
|
-
* `true` if the cookie was removed, `false` otherwise.
|
|
32
|
-
*/
|
|
33
|
-
removed: boolean
|
|
34
|
-
) => void
|
|
35
|
-
): this;
|
|
36
|
-
abstract removeListener(
|
|
37
|
-
event: "changed",
|
|
38
|
-
listener: (
|
|
39
|
-
event: Event,
|
|
40
|
-
/**
|
|
41
|
-
* The cookie that was changed.
|
|
42
|
-
*/
|
|
43
|
-
cookie: Cookie,
|
|
44
|
-
/**
|
|
45
|
-
* The cause of the change with one of the following values:
|
|
46
|
-
*/
|
|
47
|
-
cause:
|
|
48
|
-
| "explicit"
|
|
49
|
-
| "overwrite"
|
|
50
|
-
| "expired"
|
|
51
|
-
| "evicted"
|
|
52
|
-
| "expired-overwrite",
|
|
53
|
-
/**
|
|
54
|
-
* `true` if the cookie was removed, `false` otherwise.
|
|
55
|
-
*/
|
|
56
|
-
removed: boolean
|
|
57
|
-
) => void
|
|
58
|
-
): this;
|
|
59
|
-
}
|
|
60
|
-
export type Session = {
|
|
61
|
-
setProxy: (options: { mode: "direct" }) => Promise<void>;
|
|
62
|
-
cookies: Cookies;
|
|
63
|
-
};
|
|
64
|
-
export abstract class BrowserWindow {
|
|
65
|
-
webContents: {
|
|
66
|
-
session: Session;
|
|
67
|
-
};
|
|
68
|
-
}
|
|
1
|
+
export {};
|
|
2
|
+
|
|
3
|
+
type IGlassExtensionEvent<T> = (params: T) => Promise<T>;
|
|
4
|
+
type IGlassExtensionInvokeResponse<T> = Promise<{
|
|
5
|
+
success: boolean;
|
|
6
|
+
message?: string;
|
|
7
|
+
data?: T;
|
|
8
|
+
}>;
|
|
9
|
+
|
|
10
|
+
declare global {
|
|
11
|
+
namespace Glass {
|
|
12
|
+
type MenuItem = {
|
|
13
|
+
/** 用来click回调时区分 */
|
|
14
|
+
id: string;
|
|
15
|
+
label: string;
|
|
16
|
+
};
|
|
69
17
|
|
|
70
|
-
/** 1-新增,2-修改,3-删除 */
|
|
71
|
-
|
|
18
|
+
/** 1-新增,2-修改,3-删除 */
|
|
19
|
+
type Operation = 1 | 2 | 3;
|
|
72
20
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
declare?: boolean;
|
|
79
|
-
output: { code: string; filename?: string };
|
|
80
|
-
}
|
|
81
|
-
| {
|
|
82
|
-
type: "remove";
|
|
83
|
-
data: DocSchema;
|
|
84
|
-
}
|
|
85
|
-
| {
|
|
86
|
-
type: "bind" | "unbind";
|
|
87
|
-
data: DocSchema;
|
|
88
|
-
}
|
|
89
|
-
| {
|
|
90
|
-
type: "check";
|
|
21
|
+
type Cookie = {
|
|
22
|
+
name: string;
|
|
23
|
+
origin?: string;
|
|
24
|
+
path?: string;
|
|
25
|
+
value?: string;
|
|
91
26
|
};
|
|
92
27
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
export type DocFullSchema = DocSchema & {
|
|
143
|
-
external: {
|
|
144
|
-
group: string;
|
|
145
|
-
orgId?: string;
|
|
146
|
-
teamId?: string;
|
|
147
|
-
};
|
|
148
|
-
};
|
|
149
|
-
|
|
150
|
-
export type GroupSchema = {
|
|
151
|
-
id: string;
|
|
152
|
-
orgId?: string | null;
|
|
153
|
-
teamId?: string | null;
|
|
154
|
-
parentId: string | null;
|
|
155
|
-
name: string;
|
|
156
|
-
desc?: string;
|
|
157
|
-
origin?: string;
|
|
158
|
-
prefix?: string;
|
|
159
|
-
code?: string;
|
|
160
|
-
status: boolean;
|
|
161
|
-
hash?: string;
|
|
162
|
-
/** 无hash时,用updatedAt */
|
|
163
|
-
updatedAt?: string;
|
|
164
|
-
/** 是否支持app编辑 */
|
|
165
|
-
readonly?: boolean;
|
|
166
|
-
};
|
|
167
|
-
|
|
168
|
-
export type Project = {
|
|
169
|
-
id: string;
|
|
170
|
-
orgId?: string | null;
|
|
171
|
-
teamId?: string | null;
|
|
172
|
-
name: string;
|
|
173
|
-
desc?: string;
|
|
174
|
-
status: boolean;
|
|
175
|
-
actived?: boolean;
|
|
176
|
-
hash?: string;
|
|
177
|
-
};
|
|
178
|
-
|
|
179
|
-
export type Version = {
|
|
180
|
-
id: string;
|
|
181
|
-
projectId: string;
|
|
182
|
-
name: string;
|
|
183
|
-
desc?: string;
|
|
184
|
-
status: boolean;
|
|
185
|
-
actived?: boolean;
|
|
186
|
-
hash?: string;
|
|
187
|
-
};
|
|
188
|
-
|
|
189
|
-
export type Plan = {
|
|
190
|
-
id: string;
|
|
191
|
-
versionId: string;
|
|
192
|
-
name: string;
|
|
193
|
-
desc?: string;
|
|
194
|
-
origin: string;
|
|
195
|
-
prefix: string;
|
|
196
|
-
params?: string;
|
|
197
|
-
headers?: string;
|
|
198
|
-
body?: string;
|
|
199
|
-
/** 校验结果的ts类型声明 */
|
|
200
|
-
assert?: string;
|
|
201
|
-
hash?: string;
|
|
202
|
-
};
|
|
203
|
-
|
|
204
|
-
export type Case = {
|
|
205
|
-
id: string;
|
|
206
|
-
versionId: string;
|
|
207
|
-
planId?: string;
|
|
208
|
-
name: string;
|
|
209
|
-
desc?: string;
|
|
210
|
-
origin: string;
|
|
211
|
-
pathname: string;
|
|
212
|
-
method: "GET" | "POST" | "PUT" | "DELETE";
|
|
213
|
-
params?: Record<string, any>;
|
|
214
|
-
headers?: Record<string, any>;
|
|
215
|
-
body?: any;
|
|
216
|
-
apiId?: string;
|
|
217
|
-
/** 校验结果的ts类型声明 */
|
|
218
|
-
assert?: string;
|
|
219
|
-
hash?: string;
|
|
220
|
-
};
|
|
221
|
-
|
|
222
|
-
export type CaseData = Omit<Case, "params" | "headers" | "body"> & {
|
|
223
|
-
params?: string;
|
|
224
|
-
headers?: string;
|
|
225
|
-
body?: string;
|
|
226
|
-
};
|
|
227
|
-
|
|
228
|
-
export type Association = {
|
|
229
|
-
versionId: string;
|
|
230
|
-
apiId: string;
|
|
231
|
-
tags?: string[];
|
|
232
|
-
hash?: string;
|
|
233
|
-
};
|
|
234
|
-
|
|
235
|
-
export type MockMode = "None" | "Local" | "Advance";
|
|
236
|
-
export type ActionMode = "Modify" | "Add" | "Remove";
|
|
237
|
-
export type ActionTarget = "Origin";
|
|
238
|
-
export type ContextMenuType =
|
|
239
|
-
| "log"
|
|
240
|
-
| "group"
|
|
241
|
-
| "doc"
|
|
242
|
-
| "rule"
|
|
243
|
-
| "project"
|
|
244
|
-
| "version"
|
|
245
|
-
| "plan"
|
|
246
|
-
| "case"
|
|
247
|
-
| "association";
|
|
248
|
-
|
|
249
|
-
export type ContextMenuParams =
|
|
250
|
-
| { type: "log"; data: NetLog }
|
|
251
|
-
| { type: "group"; data: GroupSchema }
|
|
252
|
-
| { type: "doc"; data: DocSchema }
|
|
253
|
-
| { type: "rule"; data: RuleSchema }
|
|
254
|
-
| { type: "project"; data: Project }
|
|
255
|
-
| { type: "version"; data: Version }
|
|
256
|
-
| { type: "plan"; data: Plan }
|
|
257
|
-
| { type: "case"; data: Case }
|
|
258
|
-
| { type: "association"; data: Association };
|
|
259
|
-
|
|
260
|
-
export type SyncDataType =
|
|
261
|
-
| "group"
|
|
262
|
-
| "doc"
|
|
263
|
-
| "rule"
|
|
264
|
-
| "project"
|
|
265
|
-
| "version"
|
|
266
|
-
| "plan"
|
|
267
|
-
| "case";
|
|
268
|
-
|
|
269
|
-
export type SyncDataParams =
|
|
270
|
-
| { type: "group"; data: GroupSchema }
|
|
271
|
-
| { type: "doc"; data: DocSchema }
|
|
272
|
-
| { type: "rule"; data: RuleSchema }
|
|
273
|
-
| { type: "project"; data: Project }
|
|
274
|
-
| { type: "version"; data: Version }
|
|
275
|
-
| { type: "plan"; data: Plan }
|
|
276
|
-
| { type: "case"; data: CaseData };
|
|
277
|
-
|
|
278
|
-
export type MockModelSchema = {
|
|
279
|
-
id: string;
|
|
280
|
-
ruleId?: string;
|
|
281
|
-
contentType?: string;
|
|
282
|
-
example?: string;
|
|
283
|
-
name?: string;
|
|
284
|
-
statusCode?: number;
|
|
285
|
-
status?: boolean;
|
|
286
|
-
updatedAt?: string;
|
|
287
|
-
};
|
|
288
|
-
|
|
289
|
-
export type RewriteActionSchema = {
|
|
290
|
-
id: string;
|
|
291
|
-
ruleId?: string;
|
|
292
|
-
name?: string;
|
|
293
|
-
action?: ActionMode;
|
|
294
|
-
target?: ActionTarget;
|
|
295
|
-
oldValue?: string;
|
|
296
|
-
newValue?: string;
|
|
297
|
-
status?: boolean;
|
|
298
|
-
updatedAt?: string;
|
|
299
|
-
};
|
|
300
|
-
|
|
301
|
-
export type FilterSchema = {
|
|
302
|
-
origin?: string;
|
|
303
|
-
pathname?: string;
|
|
304
|
-
params?: { key: string; value?: string }[];
|
|
305
|
-
};
|
|
306
|
-
|
|
307
|
-
export type RuleSchema = FilterSchema & {
|
|
308
|
-
id: string;
|
|
309
|
-
orgId?: string | null;
|
|
310
|
-
teamId?: string | null;
|
|
311
|
-
mode?: MockMode; // 是否走mock
|
|
312
|
-
name?: string;
|
|
313
|
-
apiId?: string;
|
|
314
|
-
throttle?: number;
|
|
315
|
-
/** 本地匹配规则是排序用 */
|
|
316
|
-
sort?: number;
|
|
317
|
-
tags?: string[];
|
|
318
|
-
localOptions?: MockModelSchema[];
|
|
319
|
-
actions?: RewriteActionSchema[];
|
|
320
|
-
hash?: string;
|
|
321
|
-
updatedAt?: string;
|
|
322
|
-
};
|
|
323
|
-
|
|
324
|
-
export type NetLog = {
|
|
325
|
-
uid: string;
|
|
326
|
-
url: string;
|
|
327
|
-
realUrl: string;
|
|
328
|
-
method: string;
|
|
329
|
-
requestHeaders: string[][];
|
|
330
|
-
query?: string;
|
|
331
|
-
body?: any;
|
|
332
|
-
statusCode?: number;
|
|
333
|
-
responseHeaders?: string[][];
|
|
334
|
-
resourceType?: ResourceType;
|
|
335
|
-
response?: any;
|
|
336
|
-
rule?: RuleSchema;
|
|
337
|
-
};
|
|
338
|
-
export interface IProgress {
|
|
339
|
-
update: (option: { percent: number; text?: string }) => Promise<void>;
|
|
340
|
-
destroy: () => Promise<void>;
|
|
341
|
-
}
|
|
342
|
-
export interface IGlassContext {
|
|
343
|
-
getItem: <T>(key: string) => Promise<T>;
|
|
344
|
-
setItem: <T>(key: string, value: T) => Promise<void>;
|
|
345
|
-
|
|
346
|
-
saveGroup: (
|
|
347
|
-
group: GroupSchema
|
|
348
|
-
) => Promise<{ success: boolean; message?: string }>;
|
|
349
|
-
saveGroups: (
|
|
350
|
-
groups: GroupSchema[]
|
|
351
|
-
) => Promise<{ success: boolean; message?: string }>;
|
|
352
|
-
saveDoc: (
|
|
353
|
-
doc: DocSchema,
|
|
354
|
-
options?: {
|
|
355
|
-
/** 是否触发缓存更新 */
|
|
356
|
-
hooks?: boolean;
|
|
357
|
-
/** 是否根据文档自动生成rule规则 */
|
|
358
|
-
defaultRule?: Partial<{
|
|
359
|
-
name: string;
|
|
360
|
-
origin: string;
|
|
361
|
-
pathname: string;
|
|
362
|
-
params: { key: string; value?: string }[];
|
|
363
|
-
}>;
|
|
364
|
-
}
|
|
365
|
-
) => Promise<{
|
|
366
|
-
success: boolean;
|
|
367
|
-
message?: string;
|
|
368
|
-
data?: {
|
|
28
|
+
type GlassAction = "file" | "remove" | "bind" | "unbind" | "check";
|
|
29
|
+
type GlassActionParams =
|
|
30
|
+
| {
|
|
31
|
+
type: "file";
|
|
32
|
+
data: DocSchema;
|
|
33
|
+
declare?: boolean;
|
|
34
|
+
output: { code: string; filename?: string };
|
|
35
|
+
}
|
|
36
|
+
| {
|
|
37
|
+
type: "remove";
|
|
38
|
+
data: DocSchema;
|
|
39
|
+
}
|
|
40
|
+
| {
|
|
41
|
+
type: "bind" | "unbind";
|
|
42
|
+
data: DocSchema;
|
|
43
|
+
}
|
|
44
|
+
| {
|
|
45
|
+
type: "check";
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
type ResourceType =
|
|
49
|
+
| "Fetch/XHR"
|
|
50
|
+
| "JS"
|
|
51
|
+
| "CSS"
|
|
52
|
+
| "Img"
|
|
53
|
+
| "Media"
|
|
54
|
+
| "Font"
|
|
55
|
+
| "Doc"
|
|
56
|
+
| "WS"
|
|
57
|
+
| "Wasm"
|
|
58
|
+
| "Other";
|
|
59
|
+
|
|
60
|
+
type JSONPropertySchema = {
|
|
61
|
+
type: string;
|
|
62
|
+
description?: string;
|
|
63
|
+
items?: JSONPropertySchema;
|
|
64
|
+
properties?: {
|
|
65
|
+
[key: string]: JSONPropertySchema;
|
|
66
|
+
};
|
|
67
|
+
required?: string[];
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
type JSONSchema = JSONPropertySchema & {
|
|
71
|
+
$schema?: string;
|
|
72
|
+
$id?: string;
|
|
73
|
+
title?: string;
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
type DocSchema = {
|
|
369
77
|
apiId: string;
|
|
370
|
-
|
|
78
|
+
groupId: string;
|
|
79
|
+
name: string;
|
|
80
|
+
desc?: string;
|
|
81
|
+
pathname?: string;
|
|
82
|
+
method?: "GET" | "POST" | "PUT" | "DELETE";
|
|
83
|
+
code?: string; // ts声明
|
|
84
|
+
modifier?: string; // 最后操作人
|
|
85
|
+
modifyTime?: string; // 最后操作时间
|
|
86
|
+
tags?: string[] | null;
|
|
87
|
+
status: boolean;
|
|
88
|
+
hash?: string;
|
|
89
|
+
/** 无hash时,用updatedAt */
|
|
90
|
+
updatedAt?: string;
|
|
91
|
+
/** 是否支持app编辑 */
|
|
92
|
+
readonly?: boolean;
|
|
93
|
+
|
|
94
|
+
prefix?: string;
|
|
371
95
|
};
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
96
|
+
|
|
97
|
+
type DocFullSchema = DocSchema & {
|
|
98
|
+
external: {
|
|
99
|
+
group: string;
|
|
100
|
+
orgId?: string;
|
|
101
|
+
teamId?: string;
|
|
102
|
+
};
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
type GroupSchema = {
|
|
106
|
+
id: string;
|
|
107
|
+
orgId?: string | null;
|
|
108
|
+
teamId?: string | null;
|
|
109
|
+
parentId: string | null;
|
|
110
|
+
name: string;
|
|
111
|
+
desc?: string;
|
|
112
|
+
origin?: string;
|
|
113
|
+
prefix?: string;
|
|
114
|
+
code?: string;
|
|
115
|
+
status: boolean;
|
|
116
|
+
hash?: string;
|
|
117
|
+
/** 无hash时,用updatedAt */
|
|
118
|
+
updatedAt?: string;
|
|
119
|
+
/** 是否支持app编辑 */
|
|
120
|
+
readonly?: boolean;
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
type Project = {
|
|
124
|
+
id: string;
|
|
125
|
+
orgId?: string | null;
|
|
126
|
+
teamId?: string | null;
|
|
127
|
+
name: string;
|
|
128
|
+
desc?: string;
|
|
129
|
+
status: boolean;
|
|
130
|
+
actived?: boolean;
|
|
131
|
+
hash?: string;
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
type Version = {
|
|
135
|
+
id: string;
|
|
136
|
+
projectId: string;
|
|
137
|
+
name: string;
|
|
138
|
+
desc?: string;
|
|
139
|
+
status: boolean;
|
|
140
|
+
actived?: boolean;
|
|
141
|
+
hash?: string;
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
type Plan = {
|
|
145
|
+
id: string;
|
|
146
|
+
versionId: string;
|
|
147
|
+
name: string;
|
|
148
|
+
desc?: string;
|
|
149
|
+
origin: string;
|
|
150
|
+
prefix: string;
|
|
151
|
+
params?: string;
|
|
152
|
+
headers?: string;
|
|
153
|
+
body?: string;
|
|
154
|
+
/** 校验结果的ts类型声明 */
|
|
155
|
+
assert?: string;
|
|
156
|
+
hash?: string;
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
type Case = {
|
|
160
|
+
id: string;
|
|
161
|
+
versionId: string;
|
|
162
|
+
planId?: string;
|
|
163
|
+
name: string;
|
|
164
|
+
desc?: string;
|
|
165
|
+
origin: string;
|
|
166
|
+
pathname: string;
|
|
167
|
+
method: "GET" | "POST" | "PUT" | "DELETE";
|
|
168
|
+
params?: Record<string, any>;
|
|
169
|
+
headers?: Record<string, any>;
|
|
170
|
+
body?: any;
|
|
171
|
+
apiId?: string;
|
|
172
|
+
/** 校验结果的ts类型声明 */
|
|
173
|
+
assert?: string;
|
|
174
|
+
hash?: string;
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
type CaseData = Omit<Case, "params" | "headers" | "body"> & {
|
|
178
|
+
params?: string;
|
|
179
|
+
headers?: string;
|
|
180
|
+
body?: string;
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
type Association = {
|
|
184
|
+
versionId: string;
|
|
185
|
+
apiId: string;
|
|
186
|
+
tags?: string[];
|
|
187
|
+
hash?: string;
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
type MockMode = "None" | "Local" | "Advance";
|
|
191
|
+
type ActionMode = "Modify" | "Add" | "Remove";
|
|
192
|
+
type ActionTarget = "Origin";
|
|
193
|
+
type ContextMenuType =
|
|
194
|
+
| "log"
|
|
195
|
+
| "group"
|
|
196
|
+
| "doc"
|
|
197
|
+
| "rule"
|
|
198
|
+
| "project"
|
|
199
|
+
| "version"
|
|
200
|
+
| "plan"
|
|
201
|
+
| "case"
|
|
202
|
+
| "association";
|
|
203
|
+
|
|
204
|
+
type ContextMenuParams =
|
|
205
|
+
| { type: "log"; data: NetLog }
|
|
206
|
+
| { type: "group"; data: GroupSchema }
|
|
207
|
+
| { type: "doc"; data: DocSchema }
|
|
208
|
+
| { type: "rule"; data: RuleSchema }
|
|
209
|
+
| { type: "project"; data: Project }
|
|
210
|
+
| { type: "version"; data: Version }
|
|
211
|
+
| { type: "plan"; data: Plan }
|
|
212
|
+
| { type: "case"; data: Case }
|
|
213
|
+
| { type: "association"; data: Association };
|
|
214
|
+
|
|
215
|
+
type SyncDataType =
|
|
216
|
+
| "group"
|
|
217
|
+
| "doc"
|
|
218
|
+
| "rule"
|
|
219
|
+
| "project"
|
|
220
|
+
| "version"
|
|
221
|
+
| "plan"
|
|
222
|
+
| "case";
|
|
223
|
+
|
|
224
|
+
type SyncDataParams = (
|
|
225
|
+
| { type: "group"; data: GroupSchema }
|
|
226
|
+
| { type: "doc"; data: DocSchema }
|
|
227
|
+
| { type: "rule"; data: RuleSchema }
|
|
228
|
+
| { type: "project"; data: Project }
|
|
229
|
+
| { type: "version"; data: Version }
|
|
230
|
+
| { type: "plan"; data: Plan }
|
|
231
|
+
| { type: "case"; data: CaseData }
|
|
232
|
+
) & { operation: Operation; orgId?: string | null };
|
|
233
|
+
|
|
234
|
+
type MockModelSchema = {
|
|
390
235
|
id: string;
|
|
236
|
+
ruleId?: string;
|
|
391
237
|
contentType?: string;
|
|
392
238
|
example?: string;
|
|
393
239
|
name?: string;
|
|
394
240
|
statusCode?: number;
|
|
395
241
|
status?: boolean;
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
registerMenu: (id: string, options: MenuItemConstructorOptions) => void;
|
|
400
|
-
unregisterMenu: (id: string) => void;
|
|
401
|
-
|
|
402
|
-
getSession: (id: string, isPersist?: boolean) => Session;
|
|
403
|
-
showInputBox: (option: {
|
|
404
|
-
title?: string;
|
|
405
|
-
placeholder?: string;
|
|
406
|
-
value?: string;
|
|
407
|
-
}) => Promise<string>;
|
|
408
|
-
showMessage: (options: {
|
|
409
|
-
message: string;
|
|
410
|
-
title?: string;
|
|
411
|
-
type?: "success" | "info" | "error";
|
|
412
|
-
}) => Promise<void>;
|
|
413
|
-
showProgress: () => IProgress;
|
|
414
|
-
|
|
415
|
-
transformDocToJsonSchema: (doc: DocFullSchema) => JSONSchema;
|
|
416
|
-
genDataFromDocSchema: (doc: DocFullSchema) => Record<string, any>;
|
|
417
|
-
|
|
418
|
-
postMessage: (message: Partial<NetLog>) => Promise<void>;
|
|
419
|
-
}
|
|
242
|
+
updatedAt?: string;
|
|
243
|
+
};
|
|
420
244
|
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
245
|
+
type RewriteActionSchema = {
|
|
246
|
+
id: string;
|
|
247
|
+
ruleId?: string;
|
|
248
|
+
name?: string;
|
|
249
|
+
action?: ActionMode;
|
|
250
|
+
target?: ActionTarget;
|
|
251
|
+
oldValue?: string;
|
|
252
|
+
newValue?: string;
|
|
253
|
+
status?: boolean;
|
|
254
|
+
updatedAt?: string;
|
|
255
|
+
};
|
|
256
|
+
|
|
257
|
+
type FilterSchema = {
|
|
258
|
+
origin?: string;
|
|
259
|
+
pathname?: string;
|
|
260
|
+
params?: { key: string; value?: string }[];
|
|
261
|
+
};
|
|
262
|
+
|
|
263
|
+
type RuleSchema = FilterSchema & {
|
|
264
|
+
id: string;
|
|
265
|
+
orgId?: string | null;
|
|
266
|
+
teamId?: string | null;
|
|
267
|
+
mode?: MockMode; // 是否走mock
|
|
268
|
+
name?: string;
|
|
269
|
+
apiId?: string;
|
|
270
|
+
throttle?: number;
|
|
271
|
+
/** 本地匹配规则是排序用 */
|
|
272
|
+
sort?: number;
|
|
273
|
+
tags?: string[];
|
|
274
|
+
localOptions?: MockModelSchema[];
|
|
275
|
+
actions?: RewriteActionSchema[];
|
|
276
|
+
hash?: string;
|
|
277
|
+
updatedAt?: string;
|
|
278
|
+
};
|
|
279
|
+
|
|
280
|
+
type NetLog = {
|
|
281
|
+
uid: string;
|
|
441
282
|
url: string;
|
|
283
|
+
realUrl: string;
|
|
442
284
|
method: string;
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
285
|
+
requestHeaders: string[][];
|
|
286
|
+
query?: string;
|
|
287
|
+
body?: any;
|
|
288
|
+
statusCode?: number;
|
|
289
|
+
responseHeaders?: string[][];
|
|
290
|
+
resourceType?: ResourceType;
|
|
291
|
+
response?: any;
|
|
292
|
+
rule?: RuleSchema;
|
|
293
|
+
};
|
|
294
|
+
|
|
295
|
+
interface IGlassExtension {
|
|
296
|
+
install?: IGlassExtensionEvent<void>;
|
|
297
|
+
activate?: IGlassExtensionEvent<void>;
|
|
298
|
+
/** 通过设置页面修改数据 */
|
|
299
|
+
onItemChange?: IGlassExtensionEvent<void>;
|
|
300
|
+
/** 要修改url时,直接在params.url = new URL方式修改 */
|
|
301
|
+
onRequest?: IGlassExtensionEvent<{
|
|
302
|
+
/** url为null时表示break了请求 */
|
|
303
|
+
url: string | null;
|
|
304
|
+
originUrl?: string | null;
|
|
305
|
+
isLocal?: boolean;
|
|
306
|
+
}>;
|
|
307
|
+
/** 在执行请求用例时触发,用于修改config */
|
|
308
|
+
onRequestExec?: IGlassExtensionEvent<{
|
|
309
|
+
url: string;
|
|
310
|
+
method: string;
|
|
311
|
+
headers?: Record<string, any>;
|
|
312
|
+
params?: Record<string, any>;
|
|
313
|
+
data?: any;
|
|
314
|
+
}>;
|
|
315
|
+
|
|
316
|
+
/** 在用例批量执行前触发 */
|
|
317
|
+
beforeCasesExec?: IGlassExtensionEvent<{ list: Case[] }>;
|
|
318
|
+
/** 在单条用例执行时触发 */
|
|
319
|
+
onCaseExec?: IGlassExtensionEvent<Case>;
|
|
320
|
+
/** 在用例批量执行后触发 */
|
|
321
|
+
afterCasesExec?: IGlassExtensionEvent<{
|
|
322
|
+
list: Case[];
|
|
323
|
+
failCases: { id: string; message?: string }[];
|
|
324
|
+
}>;
|
|
325
|
+
|
|
326
|
+
/** 远程服务同步数据至本机 */
|
|
327
|
+
onSyncDownload?: IGlassExtensionEvent<SyncDataParams>;
|
|
328
|
+
/** 本机变更同步数据至远程服务 */
|
|
329
|
+
onSyncUpload?: IGlassExtensionEvent<SyncDataParams>;
|
|
330
|
+
|
|
331
|
+
/** 在postMessage到页面之前 */
|
|
332
|
+
onMessagePost?: IGlassExtensionEvent<{ log: Partial<NetLog> }>;
|
|
333
|
+
deactivate?: IGlassExtensionEvent<void>;
|
|
334
|
+
uninstall?: IGlassExtensionEvent<void>;
|
|
335
|
+
|
|
336
|
+
onDocChange?: IGlassExtensionEvent<{
|
|
337
|
+
doc: DocFullSchema | null;
|
|
338
|
+
originDoc: DocFullSchema | null;
|
|
339
|
+
orgId?: string | null;
|
|
340
|
+
}>;
|
|
341
|
+
onGroupChange?: IGlassExtensionEvent<{
|
|
342
|
+
group: GroupSchema | null;
|
|
343
|
+
originGroup: GroupSchema | null;
|
|
344
|
+
orgId?: string | null;
|
|
345
|
+
}>;
|
|
346
|
+
/** glass cli拉取接口文档 */
|
|
347
|
+
onDocCliUpdate?: IGlassExtensionEvent<{
|
|
348
|
+
id: string;
|
|
349
|
+
orgId?: string | null;
|
|
350
|
+
}>;
|
|
351
|
+
/** glass cli执行 */
|
|
352
|
+
onGlassAction?: IGlassExtensionEvent<{
|
|
353
|
+
params: GlassActionParams;
|
|
354
|
+
orgId?: string | null;
|
|
355
|
+
}>;
|
|
356
|
+
/** 右键请求日志 */
|
|
357
|
+
onContextMenu?: IGlassExtensionEvent<{
|
|
358
|
+
params: ContextMenuParams;
|
|
359
|
+
}>;
|
|
360
|
+
|
|
361
|
+
onRuleDefault?: IGlassExtensionEvent<{
|
|
362
|
+
docs: DocSchema[];
|
|
363
|
+
log: NetLog;
|
|
364
|
+
rule?: RuleSchema;
|
|
365
|
+
}>;
|
|
366
|
+
/** 根据doc或者log来初始化case */
|
|
367
|
+
onCaseDefault?: IGlassExtensionEvent<{
|
|
368
|
+
docs: DocSchema[];
|
|
369
|
+
log?: NetLog;
|
|
370
|
+
caseData?: CaseData;
|
|
371
|
+
}>;
|
|
446
372
|
}
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
373
|
+
|
|
374
|
+
interface IGlassBridge {
|
|
375
|
+
writeText(text: string): IGlassExtensionInvokeResponse<void>;
|
|
376
|
+
openExternal(url: string): IGlassExtensionInvokeResponse<void>;
|
|
377
|
+
|
|
378
|
+
getItem<T>(key: string): IGlassExtensionInvokeResponse<T>;
|
|
379
|
+
setItem<T>(key: string, value: T): IGlassExtensionInvokeResponse<void>;
|
|
380
|
+
|
|
381
|
+
/** 保存cookie */
|
|
382
|
+
setCookie(params: {
|
|
383
|
+
name: string;
|
|
384
|
+
origin?: string;
|
|
385
|
+
path?: string;
|
|
386
|
+
value: string;
|
|
387
|
+
}): IGlassExtensionInvokeResponse<void>;
|
|
388
|
+
|
|
389
|
+
/** 获取cookie */
|
|
390
|
+
getCookie(params: {
|
|
391
|
+
name: string;
|
|
392
|
+
origin?: string;
|
|
393
|
+
path?: string;
|
|
394
|
+
}): IGlassExtensionInvokeResponse<string>;
|
|
395
|
+
/** 保存文档组 */
|
|
396
|
+
saveGroup(group: GroupSchema): IGlassExtensionInvokeResponse<void>;
|
|
397
|
+
/** 批量保存文档组 */
|
|
398
|
+
saveGroups(groups: GroupSchema[]): IGlassExtensionInvokeResponse<void>;
|
|
399
|
+
/** 保存文档 */
|
|
400
|
+
saveDoc(
|
|
401
|
+
doc: DocSchema,
|
|
402
|
+
options?: {
|
|
403
|
+
/** 是否触发缓存更新 */
|
|
404
|
+
hooks?: boolean;
|
|
405
|
+
/** 是否根据文档自动生成rule规则 */
|
|
406
|
+
defaultRule?: Partial<{
|
|
407
|
+
name: string;
|
|
408
|
+
origin: string;
|
|
409
|
+
pathname: string;
|
|
410
|
+
params: { key: string; value?: string }[];
|
|
411
|
+
}>;
|
|
412
|
+
}
|
|
413
|
+
): IGlassExtensionInvokeResponse<{
|
|
414
|
+
apiId: string;
|
|
415
|
+
ruleId?: string;
|
|
416
|
+
}>;
|
|
417
|
+
/** 批量保存文档 */
|
|
418
|
+
saveDocs(
|
|
419
|
+
docs: DocSchema[],
|
|
420
|
+
options?: {
|
|
421
|
+
/** 是否根据文档自动生成rule规则 */
|
|
422
|
+
defaultRules?: {
|
|
423
|
+
name: string;
|
|
424
|
+
origin: string;
|
|
425
|
+
pathname: string;
|
|
426
|
+
apiId: string;
|
|
427
|
+
params?: { key: string; value?: string }[] | null;
|
|
428
|
+
}[];
|
|
429
|
+
}
|
|
430
|
+
): IGlassExtensionInvokeResponse<void>;
|
|
431
|
+
/** 批量更新rule的本地数据 */
|
|
432
|
+
saveExamples(
|
|
433
|
+
ruleId: string,
|
|
434
|
+
examples: {
|
|
435
|
+
id: string;
|
|
436
|
+
contentType?: string;
|
|
437
|
+
example?: string;
|
|
438
|
+
name?: string;
|
|
439
|
+
statusCode?: number;
|
|
440
|
+
status?: boolean;
|
|
441
|
+
}[]
|
|
442
|
+
): IGlassExtensionInvokeResponse<void>;
|
|
443
|
+
/** 注册菜单项 */
|
|
444
|
+
registerMenu(
|
|
445
|
+
id: string,
|
|
446
|
+
options: MenuItem
|
|
447
|
+
): IGlassExtensionInvokeResponse<void>;
|
|
448
|
+
/** 移除菜单 */
|
|
449
|
+
unregisterMenu(id: string): IGlassExtensionInvokeResponse<void>;
|
|
450
|
+
|
|
451
|
+
showInputBox(option: {
|
|
452
|
+
title?: string;
|
|
453
|
+
placeholder?: string;
|
|
454
|
+
value?: string;
|
|
455
|
+
}): IGlassExtensionInvokeResponse<string>;
|
|
456
|
+
showMessage(options: {
|
|
457
|
+
message: string;
|
|
458
|
+
title?: string;
|
|
459
|
+
type?: "success" | "info" | "error";
|
|
460
|
+
}): IGlassExtensionInvokeResponse<void>;
|
|
461
|
+
showProgress(option: {
|
|
462
|
+
percent: number;
|
|
463
|
+
text?: string;
|
|
464
|
+
}): IGlassExtensionInvokeResponse<void>;
|
|
465
|
+
|
|
466
|
+
transformDocToJsonSchema(
|
|
467
|
+
doc: DocFullSchema
|
|
468
|
+
): IGlassExtensionInvokeResponse<JSONSchema>;
|
|
469
|
+
genDataFromDocSchema(
|
|
470
|
+
doc: DocFullSchema
|
|
471
|
+
): IGlassExtensionInvokeResponse<Record<string, any>>;
|
|
472
|
+
|
|
473
|
+
postMessage(
|
|
474
|
+
message: Partial<NetLog>
|
|
475
|
+
): IGlassExtensionInvokeResponse<void>;
|
|
476
|
+
openBrowserWindow(browserWindowOptions: {
|
|
477
|
+
width?: number;
|
|
478
|
+
height?: number;
|
|
479
|
+
minHeight?: number;
|
|
480
|
+
minWidth?: number;
|
|
481
|
+
show?: boolean;
|
|
482
|
+
alwaysOnTop?: boolean;
|
|
483
|
+
url: string;
|
|
484
|
+
until?: {
|
|
485
|
+
mode: "cookie";
|
|
486
|
+
type: "added" | "removed";
|
|
487
|
+
info: Glass.Cookie;
|
|
488
|
+
};
|
|
489
|
+
}): IGlassExtensionInvokeResponse<Glass.Cookie>;
|
|
488
490
|
}
|
|
489
|
-
|
|
490
|
-
deactivate?(context: IGlassContext): Promise<void>;
|
|
491
|
-
uninstall?(context: IGlassContext): Promise<void>;
|
|
492
|
-
|
|
493
|
-
onDocChange?(
|
|
494
|
-
context: IGlassContext,
|
|
495
|
-
doc: DocFullSchema | null,
|
|
496
|
-
originDoc: DocFullSchema | null,
|
|
497
|
-
orgId?: string | null
|
|
498
|
-
): Promise<boolean>;
|
|
499
|
-
onGroupChange?(
|
|
500
|
-
context: IGlassContext,
|
|
501
|
-
group: GroupSchema | null,
|
|
502
|
-
originGroup: GroupSchema | null,
|
|
503
|
-
orgId?: string | null
|
|
504
|
-
): Promise<boolean>;
|
|
505
|
-
/** glass cli拉取接口文档 */
|
|
506
|
-
onDocCliUpdate?(
|
|
507
|
-
context: IGlassContext,
|
|
508
|
-
id: string,
|
|
509
|
-
orgId?: string | null
|
|
510
|
-
): Promise<void>;
|
|
511
|
-
/** glass cli执行 */
|
|
512
|
-
onGlassAction?(
|
|
513
|
-
context: IGlassContext,
|
|
514
|
-
params: GlassActionParams,
|
|
515
|
-
orgId?: string | null
|
|
516
|
-
): Promise<void>;
|
|
517
|
-
/** 右键请求日志 */
|
|
518
|
-
onContextMenu?(
|
|
519
|
-
context: IGlassContext,
|
|
520
|
-
params: ContextMenuParams,
|
|
521
|
-
menus?: MenuItemConstructorOptions[]
|
|
522
|
-
): Promise<void>;
|
|
523
|
-
|
|
524
|
-
getDefaultRule?(
|
|
525
|
-
context: IGlassContext,
|
|
526
|
-
docs: DocSchema[],
|
|
527
|
-
log: NetLog,
|
|
528
|
-
rule?: {
|
|
529
|
-
id: string;
|
|
530
|
-
mode: "None";
|
|
531
|
-
} & Partial<{
|
|
532
|
-
name: string;
|
|
533
|
-
origin: string;
|
|
534
|
-
pathname: string;
|
|
535
|
-
params: { key: string; value?: string }[];
|
|
536
|
-
apiId: string;
|
|
537
|
-
}>
|
|
538
|
-
): Promise<void>;
|
|
539
|
-
/** 根据doc或者log来初始化case */
|
|
540
|
-
getDefaultCase?(
|
|
541
|
-
context: IGlassContext,
|
|
542
|
-
docs: DocSchema[],
|
|
543
|
-
log?: NetLog,
|
|
544
|
-
defaultCase?: Partial<Case>
|
|
545
|
-
): Promise<void>;
|
|
491
|
+
}
|
|
546
492
|
}
|
|
547
|
-
|
|
548
|
-
export type writeText = (text: string) => void;
|
|
549
|
-
export type openExternal = (url: string) => void;
|
|
550
|
-
export type openBrowserWindow = (browserWindowOptions: {
|
|
551
|
-
width?: number;
|
|
552
|
-
height?: number;
|
|
553
|
-
minHeight?: number;
|
|
554
|
-
minWidth?: number;
|
|
555
|
-
show?: boolean;
|
|
556
|
-
alwaysOnTop?: boolean;
|
|
557
|
-
url: string;
|
|
558
|
-
webPreferences?: {
|
|
559
|
-
session?: Session;
|
|
560
|
-
};
|
|
561
|
-
}) => Promise<BrowserWindow>;
|