@tinywork/glass 1.0.3 → 1.0.5

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/index.ts +122 -120
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tinywork/glass",
3
- "version": "1.0.3",
3
+ "version": "1.0.5",
4
4
  "description": "",
5
5
  "main": "src/index.ts",
6
6
  "types": "src/index.ts",
package/src/index.ts CHANGED
@@ -199,7 +199,8 @@ declare global {
199
199
  | "version"
200
200
  | "plan"
201
201
  | "case"
202
- | "association";
202
+ | "association"
203
+ | "unknow";
203
204
 
204
205
  type ContextMenuParams =
205
206
  | { type: "log"; data: NetLog }
@@ -291,10 +292,6 @@ declare global {
291
292
  response?: any;
292
293
  rule?: RuleSchema;
293
294
  };
294
- interface IProgress {
295
- update: (option: { percent: number; text?: string }) => Promise<void>;
296
- destroy: () => Promise<void>;
297
- }
298
295
 
299
296
  interface IGlassExtension {
300
297
  install?: IGlassExtensionEvent<void>;
@@ -304,7 +301,8 @@ declare global {
304
301
  /** 要修改url时,直接在params.url = new URL方式修改 */
305
302
  onRequest?: IGlassExtensionEvent<{
306
303
  /** url为null时表示break了请求 */
307
- url: URL | null;
304
+ url: string | null;
305
+ originUrl?: string | null;
308
306
  isLocal?: boolean;
309
307
  }>;
310
308
  /** 在执行请求用例时触发,用于修改config */
@@ -333,7 +331,6 @@ declare global {
333
331
 
334
332
  /** 在postMessage到页面之前 */
335
333
  onMessagePost?: IGlassExtensionEvent<{ log: Partial<NetLog> }>;
336
- onResponse?: IGlassExtensionEvent<{ url: URL }>;
337
334
  deactivate?: IGlassExtensionEvent<void>;
338
335
  uninstall?: IGlassExtensionEvent<void>;
339
336
 
@@ -360,6 +357,7 @@ declare global {
360
357
  /** 右键请求日志 */
361
358
  onContextMenu?: IGlassExtensionEvent<{
362
359
  params: ContextMenuParams;
360
+ menus?: MenuItem[];
363
361
  }>;
364
362
 
365
363
  onRuleDefault?: IGlassExtensionEvent<{
@@ -375,118 +373,122 @@ declare global {
375
373
  }>;
376
374
  }
377
375
 
378
- type writeText = (text: string) => Promise<void>;
379
- type openExternal = (url: string) => Promise<void>;
380
- type getItem = <T>(key: string) => Promise<T>;
381
- type setItem = <T>(key: string, value: T) => Promise<void>;
382
- /** 保存cookie */
383
- type setCookie = (params: {
384
- name: string;
385
- origin?: string;
386
- path?: string;
387
- value: string;
388
- }) => IGlassExtensionInvokeResponse<void>;
389
- /** 获取cookie */
390
- type getCookie = (params: {
391
- name: string;
392
- origin?: string;
393
- path?: string;
394
- }) => IGlassExtensionInvokeResponse<string>;
395
- /** 保存文档组 */
396
- type saveGroup = (
397
- group: GroupSchema
398
- ) => IGlassExtensionInvokeResponse<void>;
399
- /** 批量保存文档组 */
400
- type saveGroups = (
401
- groups: GroupSchema[]
402
- ) => IGlassExtensionInvokeResponse<void>;
403
- /** 保存文档 */
404
- type saveDoc = (
405
- doc: DocSchema,
406
- options?: {
407
- /** 是否触发缓存更新 */
408
- hooks?: boolean;
409
- /** 是否根据文档自动生成rule规则 */
410
- defaultRule?: Partial<{
411
- name: string;
412
- origin: string;
413
- pathname: string;
414
- params: { key: string; value?: string }[];
415
- }>;
416
- }
417
- ) => IGlassExtensionInvokeResponse<{
418
- apiId: string;
419
- ruleId?: string;
420
- }>;
421
- /** 批量保存文档 */
422
- type saveDocs = (
423
- docs: DocSchema[],
424
- options?: {
425
- /** 是否根据文档自动生成rule规则 */
426
- defaultRules?: {
427
- name: string;
428
- origin: string;
429
- pathname: string;
430
- apiId: string;
431
- params?: { key: string; value?: string }[] | null;
432
- }[];
433
- }
434
- ) => IGlassExtensionInvokeResponse<void>;
435
- /** 批量更新rule的本地数据 */
436
- type saveExamples = (
437
- ruleId: string,
438
- examples: {
439
- id: string;
440
- contentType?: string;
441
- example?: string;
442
- name?: string;
443
- statusCode?: number;
444
- status?: boolean;
445
- }[]
446
- ) => IGlassExtensionInvokeResponse<void>;
447
- /** 注册菜单项 */
448
- type registerMenu = (
449
- id: string,
450
- options: MenuItem
451
- ) => IGlassExtensionInvokeResponse<void>;
452
- /** 移除菜单 */
453
- type unregisterMenu = (id: string) => IGlassExtensionInvokeResponse<void>;
454
-
455
- type showInputBox = (option: {
456
- title?: string;
457
- placeholder?: string;
458
- value?: string;
459
- }) => IGlassExtensionInvokeResponse<string>;
460
- type showMessage = (options: {
461
- message: string;
462
- title?: string;
463
- type?: "success" | "info" | "error";
464
- }) => IGlassExtensionInvokeResponse<void>;
465
- type showProgress = () => IProgress;
466
-
467
- type transformDocToJsonSchema = (
468
- doc: DocFullSchema
469
- ) => IGlassExtensionInvokeResponse<JSONSchema>;
470
- type genDataFromDocSchema = (
471
- doc: DocFullSchema
472
- ) => IGlassExtensionInvokeResponse<Record<string, any>>;
473
-
474
- type postMessage = (
475
- message: Partial<NetLog>
476
- ) => IGlassExtensionInvokeResponse<void>;
477
- type openBrowserWindow = (browserWindowOptions: {
478
- width?: number;
479
- height?: number;
480
- minHeight?: number;
481
- minWidth?: number;
482
- show?: boolean;
483
- alwaysOnTop?: boolean;
484
- url: string;
485
- until?: {
486
- mode: "cookie";
487
- type: "added" | "removed";
488
- info: Glass.Cookie;
489
- };
490
- }) => IGlassExtensionInvokeResponse<Glass.Cookie>;
376
+ interface IGlassBridge {
377
+ writeText(text: string): IGlassExtensionInvokeResponse<void>;
378
+ openExternal(url: string): IGlassExtensionInvokeResponse<void>;
379
+
380
+ getItem<T>(key: string): IGlassExtensionInvokeResponse<T>;
381
+ setItem<T>(key: string, value: T): IGlassExtensionInvokeResponse<void>;
382
+
383
+ /** 保存cookie */
384
+ setCookie(params: {
385
+ name: string;
386
+ origin?: string;
387
+ path?: string;
388
+ value: string;
389
+ }): IGlassExtensionInvokeResponse<void>;
390
+
391
+ /** 获取cookie */
392
+ getCookie(params: {
393
+ name: string;
394
+ origin?: string;
395
+ path?: string;
396
+ }): IGlassExtensionInvokeResponse<string>;
397
+ /** 保存文档组 */
398
+ saveGroup(group: GroupSchema): IGlassExtensionInvokeResponse<void>;
399
+ /** 批量保存文档组 */
400
+ saveGroups(groups: GroupSchema[]): IGlassExtensionInvokeResponse<void>;
401
+ /** 保存文档 */
402
+ saveDoc(
403
+ doc: DocSchema,
404
+ options?: {
405
+ /** 是否触发缓存更新 */
406
+ hooks?: boolean;
407
+ /** 是否根据文档自动生成rule规则 */
408
+ defaultRule?: Partial<{
409
+ name: string;
410
+ origin: string;
411
+ pathname: string;
412
+ params: { key: string; value?: string }[];
413
+ }>;
414
+ }
415
+ ): IGlassExtensionInvokeResponse<{
416
+ apiId: string;
417
+ ruleId?: string;
418
+ }>;
419
+ /** 批量保存文档 */
420
+ saveDocs(
421
+ docs: DocSchema[],
422
+ options?: {
423
+ /** 是否根据文档自动生成rule规则 */
424
+ defaultRules?: {
425
+ name: string;
426
+ origin: string;
427
+ pathname: string;
428
+ apiId: string;
429
+ params?: { key: string; value?: string }[] | null;
430
+ }[];
431
+ }
432
+ ): IGlassExtensionInvokeResponse<void>;
433
+ /** 批量更新rule的本地数据 */
434
+ saveExamples(
435
+ ruleId: string,
436
+ examples: {
437
+ id: string;
438
+ contentType?: string;
439
+ example?: string;
440
+ name?: string;
441
+ statusCode?: number;
442
+ status?: boolean;
443
+ }[]
444
+ ): IGlassExtensionInvokeResponse<void>;
445
+ /** 注册菜单项 */
446
+ registerMenu(
447
+ id: string,
448
+ options: MenuItem
449
+ ): IGlassExtensionInvokeResponse<void>;
450
+ /** 移除菜单 */
451
+ unregisterMenu(id: string): IGlassExtensionInvokeResponse<void>;
452
+
453
+ showInputBox(option: {
454
+ title?: string;
455
+ placeholder?: string;
456
+ value?: string;
457
+ }): IGlassExtensionInvokeResponse<string>;
458
+ showMessage(options: {
459
+ message: string;
460
+ title?: string;
461
+ type?: "success" | "info" | "error";
462
+ }): IGlassExtensionInvokeResponse<void>;
463
+ showProgress(option: {
464
+ percent: number;
465
+ text?: string;
466
+ }): IGlassExtensionInvokeResponse<void>;
467
+
468
+ transformDocToJsonSchema(
469
+ doc: DocFullSchema
470
+ ): IGlassExtensionInvokeResponse<JSONSchema>;
471
+ genDataFromDocSchema(
472
+ doc: DocFullSchema
473
+ ): IGlassExtensionInvokeResponse<Record<string, any>>;
474
+
475
+ postMessage(
476
+ message: Partial<NetLog>
477
+ ): IGlassExtensionInvokeResponse<void>;
478
+ openBrowserWindow(browserWindowOptions: {
479
+ width?: number;
480
+ height?: number;
481
+ minHeight?: number;
482
+ minWidth?: number;
483
+ show?: boolean;
484
+ alwaysOnTop?: boolean;
485
+ url: string;
486
+ until?: {
487
+ mode: "cookie";
488
+ type: "added" | "removed";
489
+ info: Glass.Cookie;
490
+ };
491
+ }): IGlassExtensionInvokeResponse<Glass.Cookie>;
492
+ }
491
493
  }
492
494
  }