/
tc-types.d.ts
200 lines (172 loc) · 5.23 KB
/
tc-types.d.ts
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
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
// version 2.19.5
declare var tc: tcType;
declare var expect: any;
declare var assert: any;
interface tcType {
/**
* Get Environment variable value
* @param variableName variable name
*/
getVar(variableName: string): string;
/**
* Set Environment variable value
* @param variableName variable name
* @param value variable value
* @param scope [optional] environment scope with values: local, global and request
*/
setVar(variableName: string, value: any, scope?: "local" | "global" | "request"): void;
/**
* Add or update the query parameter of the URL
* @param paramName query parameter name
* @param value parameter value
* @since 2.11.0
*/
setParam(paramName: string, value: any): void;
/**
* Load and get node module from npm registry
* @param moduleName module name
* @param version [optional] module version, if empty latest version will be used
*/
loadModule(moduleName: string, version?: string): Promise<any>;
/**
* Read the file from disk
* @param path file path relative to project root or absolute path
* @param encoding [optional] encoding to use base64 or utf8. if empty utf8 will be used
*/
readFile(path: string, encoding?: string): Promise<string | undefined>;
/**
* Executes the command and returns the result
* @param command command to execute
*/
exec(command: string): Promise<any>;
/**
* Get all cookies in cookie store
* @param url [optional] to get cookies for url, if empty all cookies will be returned
* @since 2.14.0
*/
getCookies(url?: string): Promise<Cookie[]>;
/**
* Clear all existing cookies
* @param url [optional] to clear cookies for url, if empty all cookies will be cleared
* @param name [optional] to clear cookie by name, if empty all cookies for the url will be cleared
*/
clearCookies(url?: string, name?: string): Promise<void>;
/**
* Set cookie in cookie store
* @param url the url to set cookie for
* @param name cookie name
* @param value cookie value
* @since 2.14.0
*/
setCookie(url: string, name: string, value: string): Promise<void>;
/**
* Delay the execution for the specified milliseconds
* @param ms the delay time in milliseconds
* @since 2.9.2
*/
delay(ms: number): Promise<void>;
/**
* Test assertion (Only works in Post Request Script)
* @param name the name of the test
* @param result the result of the test -> boolean or function that returns false or throws exception
* @since 2.10.0
*/
test(name: string, result: boolean | (() => boolean | void)): void;
/**
* Run Request from the script
* @param reqId the request id
* @since 2.9.0
*/
runRequest(reqId: string): Promise<ResponseModel>;
/**
* Retry Request from the script. This will not execute the pre-reqs and pre script
* @since 2.17.5
*/
retryRequest(): Promise<ResponseModel>;
/**
* Skip Request from execution in collection run
* @param reqId the request id
* @since 2.16.0
*/
skipRequest(reqId: string): void;
/**
* Set the chart template and data
* @param template chart template HTML string
* @param data chart data
* @since 2.17.0
*/
chartHTML(template: string, data: any): void;
/**
* Get the Request Info
* @since 2.15.0
*/
info: InfoModel;
/**
* Get the Request object (Only Headers can be modified)
*/
request: RequestModel;
/**
* Get the Response object (read-only)
*/
response: ResponseModel;
}
type RequestModel = {
id: string;
name: string;
url: string;
method: string;
headers: KeyValue[];
body: RequestBody | undefined;
getHeader: (name: string) => string | undefined;
setHeader: (name: string, value: string) => void;
/**
* Set Request body - examples: https://github.com/rangav/thunder-client-support/releases/tag/v2.19.5
*/
setBody: (body: string | object | GraphqlBody | undefined, type?: BodyType) => void;
}
type ResponseModel = {
status: number;
time: number;
size: number;
contentType: string;
headers: KeyValue[];
cookies: KeyValue[];
json: any;
text: string;
getHeader: (name: string) => string | undefined;
}
type RequestBody = {
type: BodyType,
raw: string | undefined,
form: KeyValue[] | undefined,
files: KeyValue[] | undefined,
graphql: GraphqlBody | undefined,
binary: string | undefined
}
type KeyValue = {
name: string,
value: string,
isDisabled?: boolean | undefined
}
type BodyType = "none" | "text" | "json" | "xml" | "formdata" | "formencoded" | "graphql" | "binary";
type GraphqlBody = {
query: string,
variables?: string | undefined
}
type Cookie = {
key: string;
value: string;
expires?: string; // date in ISO 8601 format
domain: string;
path: string;
hostOnly: boolean;
httpOnly?: boolean;
creation: string; // date in ISO 8601 format
lastAccessed: string; // date in ISO 8601 format
}
type InfoModel = {
environmentName: string,
requestName: string,
collectionName: string,
folderName: string,
}