chenyc
2025-12-09 545c24c6a711d71b65f3d4e8122fee3837fb1edc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import MockAgent from './mock-agent'
 
declare class SnapshotRecorder {
  constructor (options?: SnapshotRecorder.Options)
 
  record (requestOpts: any, response: any): Promise<void>
  findSnapshot (requestOpts: any): SnapshotRecorder.Snapshot | undefined
  loadSnapshots (filePath?: string): Promise<void>
  saveSnapshots (filePath?: string): Promise<void>
  clear (): void
  getSnapshots (): SnapshotRecorder.Snapshot[]
  size (): number
  resetCallCounts (): void
  deleteSnapshot (requestOpts: any): boolean
  getSnapshotInfo (requestOpts: any): SnapshotRecorder.SnapshotInfo | null
  replaceSnapshots (snapshotData: SnapshotRecorder.SnapshotData[]): void
  destroy (): void
}
 
declare namespace SnapshotRecorder {
  type SnapshotRecorderMode = 'record' | 'playback' | 'update'
 
  export interface Options {
    snapshotPath?: string
    mode?: SnapshotRecorderMode
    maxSnapshots?: number
    autoFlush?: boolean
    flushInterval?: number
    matchHeaders?: string[]
    ignoreHeaders?: string[]
    excludeHeaders?: string[]
    matchBody?: boolean
    matchQuery?: boolean
    caseSensitive?: boolean
    shouldRecord?: (requestOpts: any) => boolean
    shouldPlayback?: (requestOpts: any) => boolean
    excludeUrls?: (string | RegExp)[]
  }
 
  export interface Snapshot {
    request: {
      method: string
      url: string
      headers: Record<string, string>
      body?: string
    }
    responses: {
      statusCode: number
      headers: Record<string, string>
      body: string
      trailers: Record<string, string>
    }[]
    callCount: number
    timestamp: string
  }
 
  export interface SnapshotInfo {
    hash: string
    request: {
      method: string
      url: string
      headers: Record<string, string>
      body?: string
    }
    responseCount: number
    callCount: number
    timestamp: string
  }
 
  export interface SnapshotData {
    hash: string
    snapshot: Snapshot
  }
}
 
declare class SnapshotAgent extends MockAgent {
  constructor (options?: SnapshotAgent.Options)
 
  saveSnapshots (filePath?: string): Promise<void>
  loadSnapshots (filePath?: string): Promise<void>
  getRecorder (): SnapshotRecorder
  getMode (): SnapshotRecorder.SnapshotRecorderMode
  clearSnapshots (): void
  resetCallCounts (): void
  deleteSnapshot (requestOpts: any): boolean
  getSnapshotInfo (requestOpts: any): SnapshotRecorder.SnapshotInfo | null
  replaceSnapshots (snapshotData: SnapshotRecorder.SnapshotData[]): void
}
 
declare namespace SnapshotAgent {
  export interface Options extends MockAgent.Options {
    mode?: SnapshotRecorder.SnapshotRecorderMode
    snapshotPath?: string
    maxSnapshots?: number
    autoFlush?: boolean
    flushInterval?: number
    matchHeaders?: string[]
    ignoreHeaders?: string[]
    excludeHeaders?: string[]
    matchBody?: boolean
    matchQuery?: boolean
    caseSensitive?: boolean
    shouldRecord?: (requestOpts: any) => boolean
    shouldPlayback?: (requestOpts: any) => boolean
    excludeUrls?: (string | RegExp)[]
  }
}
 
export { SnapshotAgent, SnapshotRecorder }