@caido/sdk-frontend 0.46.1-beta.0 → 0.46.1-beta.2

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.
@@ -68,8 +68,10 @@ type CommandContextRequest = {
68
68
  type: "RequestContext";
69
69
  /**
70
70
  * The request that is currently open in the request pane.
71
+ * If the request has not yet been saved in the database, the id will be undefined.
71
72
  */
72
73
  request: {
74
+ id: ID | undefined;
73
75
  host: string;
74
76
  port: number;
75
77
  path: string;
@@ -28,7 +28,7 @@ export type { ReplayTab, ReplaySession, ReplayCollection } from "./replay";
28
28
  export type { HostedFile } from "./files";
29
29
  export type { Filter } from "./filters";
30
30
  export type { HTTPQL, ID } from "./utils";
31
- export type { MatchReplaceRule, MatchReplaceCollection, MatchReplaceStrategy, } from "./matchReplace";
31
+ export type { MatchReplaceRule, MatchReplaceCollection, MatchReplaceSection, MatchReplaceSectionRequestBody, MatchReplaceSectionRequestFirstLine, MatchReplaceSectionRequestHeader, MatchReplaceSectionRequestMethod, MatchReplaceSectionRequestPath, MatchReplaceSectionRequestQuery, MatchReplaceSectionResponseBody, MatchReplaceSectionResponseFirstLine, MatchReplaceSectionResponseHeader, MatchReplaceSectionResponseStatusCode, MatchReplaceOperationStatusCode, MatchReplaceOperationStatusCodeUpdate, MatchReplaceOperationQuery, MatchReplaceOperationQueryRaw, MatchReplaceOperationQueryAdd, MatchReplaceOperationQueryRemove, MatchReplaceOperationQueryUpdate, MatchReplaceOperationPath, MatchReplaceOperationPathRaw, MatchReplaceOperationMethod, MatchReplaceOperationMethodUpdate, MatchReplaceOperationHeader, MatchReplaceOperationHeaderRaw, MatchReplaceOperationHeaderAdd, MatchReplaceOperationHeaderRemove, MatchReplaceOperationHeaderUpdate, MatchReplaceOperationBody, MatchReplaceOperationBodyRaw, MatchReplaceOperationFirstLine, MatchReplaceOperationFirstLineRaw, MatchReplaceReplacer, MatchReplaceReplacerTerm, MatchReplaceReplacerWorkflow, MatchReplaceMatcherName, MatchReplaceMatcherRaw, MatchReplaceMatcherRawFull, MatchReplaceMatcherRawRegex, MatchReplaceMatcherRawValue, } from "./matchReplace";
32
32
  export type { Scope } from "./scopes";
33
33
  export type { EnvironmentVariable } from "./environment";
34
34
  /**
@@ -50,22 +50,13 @@ export type MatchReplaceSDK = {
50
50
  * Create a rule.
51
51
  * @param options - The options for the rule.
52
52
  * @param options.name - The name of the rule.
53
- * @param options.isEnabled - Whether the rule is enabled.
54
- * @param options.matchTerm - The match term of the rule.
55
- * @param options.replaceTerm - The replace term of the rule.
56
- * @param options.isRegex - Whether the match term is a regex.
57
- * @param options.strategy - The strategy of the rule.
58
53
  * @param options.query - The HTTPQL query to match the rule against.
59
54
  * @param options.collectionId - The ID of the collection the rule belongs to.
60
55
  */
61
56
  createRule: (options: {
62
57
  name: string;
63
- isEnabled: boolean;
64
- matchTerm: string;
65
- replaceTerm: string;
66
- isRegex: boolean;
67
58
  query: HTTPQL;
68
- strategy: MatchReplaceStrategy;
59
+ section: MatchReplaceSection;
69
60
  collectionId: ID;
70
61
  }) => Promise<MatchReplaceRule>;
71
62
  /**
@@ -73,22 +64,20 @@ export type MatchReplaceSDK = {
73
64
  * @param id - The ID of the rule.
74
65
  * @param options - The new values for the rule.
75
66
  * @param options.name - The new name of the rule.
76
- * @param options.isEnabled - Whether the rule is enabled.
77
- * @param options.matchTerm - The new match term of the rule.
78
- * @param options.replaceTerm - The new replace term of the rule.
79
- * @param options.isRegex - Whether the match term is a regex.
80
67
  * @param options.query - The new HTTPQL query of the rule.
81
- * @param options.strategy - The new strategy of the rule.
68
+ * @param options.section - The new section of the rule.
82
69
  */
83
70
  updateRule: (id: ID, options: {
84
71
  name: string;
85
- isEnabled: boolean;
86
- matchTerm: string;
87
- replaceTerm: string;
88
- isRegex: boolean;
89
- query: HTTPQL;
90
- strategy: MatchReplaceStrategy;
72
+ query?: HTTPQL;
73
+ section: MatchReplaceSection;
91
74
  }) => Promise<MatchReplaceRule>;
75
+ /**
76
+ * Toggle a rule.
77
+ * @param id - The ID of the rule.
78
+ * @param enabled - Whether the rule should be enabled.
79
+ */
80
+ toggleRule: (id: ID, enabled: boolean) => Promise<void>;
92
81
  /**
93
82
  * Delete a rule.
94
83
  * @param id - The ID of the rule.
@@ -112,33 +101,208 @@ export type MatchReplaceRule = {
112
101
  * Whether the rule is enabled.
113
102
  */
114
103
  isEnabled: boolean;
115
- /**
116
- * The match term of the rule.
117
- */
118
- matchTerm: string;
119
- /**
120
- * The replace term of the rule.
121
- */
122
- replaceTerm: string;
123
- /**
124
- * Whether the match term is a regex.
125
- */
126
- isRegex: boolean;
127
104
  /**
128
105
  * The HTTPQL query to match the rule against.
129
106
  * Only requests that match the query will be affected by the rule.
130
107
  */
131
108
  query: HTTPQL;
132
109
  /**
133
- * The strategy of the rule.
110
+ * The section of the rule.
134
111
  */
135
- strategy: MatchReplaceStrategy;
112
+ section: MatchReplaceSection;
136
113
  /**
137
114
  * The ID of the collection the rule belongs to.
138
115
  */
139
116
  collectionId: ID;
140
117
  };
141
- export type MatchReplaceStrategy = "REQUEST_FIRST_LINE" | "REQUEST_HEADER" | "REQUEST_BODY" | "RESPONSE_FIRST_LINE" | "RESPONSE_HEADER" | "RESPONSE_BODY";
118
+ export type MatchReplaceSection = MatchReplaceSectionRequestBody | MatchReplaceSectionRequestFirstLine | MatchReplaceSectionRequestHeader | MatchReplaceSectionRequestMethod | MatchReplaceSectionRequestPath | MatchReplaceSectionRequestQuery | MatchReplaceSectionResponseBody | MatchReplaceSectionResponseFirstLine | MatchReplaceSectionResponseHeader | MatchReplaceSectionResponseStatusCode;
119
+ export type MatchReplaceSectionResponseStatusCode = {
120
+ kind: "SectionResponseStatusCode";
121
+ operation: MatchReplaceOperationStatusCode;
122
+ };
123
+ export type MatchReplaceOperationStatusCode = KeepOperation<MatchReplaceOperationStatusCodeUpdate>;
124
+ export type MatchReplaceOperationStatusCodeUpdate = {
125
+ kind: "OperationStatusCodeUpdate";
126
+ replacer: MatchReplaceReplacer;
127
+ };
128
+ export type MatchReplaceSectionRequestQuery = {
129
+ kind: "SectionRequestQuery";
130
+ operation: MatchReplaceOperationQuery;
131
+ };
132
+ export type MatchReplaceOperationQuery = MatchReplaceOperationQueryRaw | MatchReplaceOperationQueryAdd | MatchReplaceOperationQueryRemove | MatchReplaceOperationQueryUpdate;
133
+ export type MatchReplaceOperationQueryRaw = {
134
+ kind: "OperationQueryRaw";
135
+ matcher: MatchReplaceMatcherRaw;
136
+ replacer: MatchReplaceReplacer;
137
+ };
138
+ export type MatchReplaceOperationQueryAdd = {
139
+ kind: "OperationQueryAdd";
140
+ matcher: MatchReplaceMatcherName;
141
+ replacer: MatchReplaceReplacer;
142
+ };
143
+ export type MatchReplaceOperationQueryRemove = {
144
+ kind: "OperationQueryRemove";
145
+ matcher: MatchReplaceMatcherName;
146
+ };
147
+ export type MatchReplaceOperationQueryUpdate = {
148
+ kind: "OperationQueryUpdate";
149
+ matcher: MatchReplaceMatcherName;
150
+ replacer: MatchReplaceReplacer;
151
+ };
152
+ export type MatchReplaceSectionRequestPath = {
153
+ kind: "SectionRequestPath";
154
+ operation: MatchReplaceOperationPath;
155
+ };
156
+ export type MatchReplaceOperationPath = KeepOperation<MatchReplaceOperationPathRaw>;
157
+ export type MatchReplaceOperationPathRaw = {
158
+ kind: "OperationPathRaw";
159
+ matcher: MatchReplaceMatcherRaw;
160
+ replacer: MatchReplaceReplacer;
161
+ };
162
+ export type MatchReplaceSectionRequestMethod = {
163
+ kind: "SectionRequestMethod";
164
+ operation: MatchReplaceOperationMethod;
165
+ };
166
+ export type MatchReplaceOperationMethod = KeepOperation<MatchReplaceOperationMethodUpdate>;
167
+ export type MatchReplaceOperationMethodUpdate = {
168
+ kind: "OperationMethodUpdate";
169
+ replacer: MatchReplaceReplacer;
170
+ };
171
+ export type MatchReplaceSectionRequestHeader = {
172
+ kind: "SectionRequestHeader";
173
+ operation: MatchReplaceOperationHeader;
174
+ };
175
+ export type MatchReplaceSectionResponseHeader = {
176
+ kind: "SectionResponseHeader";
177
+ operation: MatchReplaceOperationHeader;
178
+ };
179
+ /**
180
+ * An operation for the header section.
181
+ * @category Match and Replace
182
+ */
183
+ export type MatchReplaceOperationHeader = MatchReplaceOperationHeaderRaw | MatchReplaceOperationHeaderAdd | MatchReplaceOperationHeaderRemove | MatchReplaceOperationHeaderUpdate;
184
+ export type MatchReplaceOperationHeaderRaw = {
185
+ kind: "OperationHeaderRaw";
186
+ matcher: MatchReplaceMatcherRaw;
187
+ replacer: MatchReplaceReplacer;
188
+ };
189
+ export type MatchReplaceOperationHeaderAdd = {
190
+ kind: "OperationHeaderAdd";
191
+ matcher: MatchReplaceMatcherName;
192
+ replacer: MatchReplaceReplacer;
193
+ };
194
+ export type MatchReplaceOperationHeaderRemove = {
195
+ kind: "OperationHeaderRemove";
196
+ matcher: MatchReplaceMatcherName;
197
+ };
198
+ export type MatchReplaceOperationHeaderUpdate = {
199
+ kind: "OperationHeaderUpdate";
200
+ matcher: MatchReplaceMatcherName;
201
+ replacer: MatchReplaceReplacer;
202
+ };
203
+ export type MatchReplaceSectionRequestBody = {
204
+ kind: "SectionRequestBody";
205
+ operation: MatchReplaceOperationBody;
206
+ };
207
+ export type MatchReplaceSectionResponseBody = {
208
+ kind: "SectionResponseBody";
209
+ operation: MatchReplaceOperationBody;
210
+ };
211
+ /**
212
+ * An operation for the body section.
213
+ * @category Match and Replace
214
+ */
215
+ export type MatchReplaceOperationBody = KeepOperation<MatchReplaceOperationBodyRaw>;
216
+ /**
217
+ * A raw operation for the body section.
218
+ * @category Match and Replace
219
+ */
220
+ export type MatchReplaceOperationBodyRaw = {
221
+ kind: "OperationBodyRaw";
222
+ matcher: MatchReplaceMatcherRaw;
223
+ replacer: MatchReplaceReplacer;
224
+ };
225
+ /**
226
+ * A section for the request first line.
227
+ * @category Match and Replace
228
+ */
229
+ export type MatchReplaceSectionRequestFirstLine = {
230
+ kind: "SectionRequestFirstLine";
231
+ operation: MatchReplaceOperationFirstLine;
232
+ };
233
+ /**
234
+ * A section for the response first line.
235
+ * @category Match and Replace
236
+ */
237
+ export type MatchReplaceSectionResponseFirstLine = {
238
+ kind: "SectionResponseFirstLine";
239
+ operation: MatchReplaceOperationFirstLine;
240
+ };
241
+ export type MatchReplaceOperationFirstLine = KeepOperation<MatchReplaceOperationFirstLineRaw>;
242
+ /**
243
+ * A raw operation for the request first line.
244
+ * @category Match and Replace
245
+ */
246
+ export type MatchReplaceOperationFirstLineRaw = {
247
+ kind: "OperationFirstLineRaw";
248
+ matcher: MatchReplaceMatcherRaw;
249
+ replacer: MatchReplaceReplacer;
250
+ };
251
+ export type MatchReplaceMatcherName = {
252
+ kind: "MatcherName";
253
+ name: string;
254
+ };
255
+ /**
256
+ * A matcher for raw operations in Match and Replace.
257
+ * @category Match and Replace
258
+ */
259
+ export type MatchReplaceMatcherRaw = MatchReplaceMatcherRawRegex | MatchReplaceMatcherRawValue | MatchReplaceMatcherRawFull;
260
+ /**
261
+ * This matcher will match using a regex over the section.
262
+ * @category Match and Replace
263
+ */
264
+ export type MatchReplaceMatcherRawRegex = {
265
+ kind: "MatcherRawRegex";
266
+ regex: string;
267
+ };
268
+ /**
269
+ * This matcher will match the value if present in the section.
270
+ * @category Match and Replace
271
+ */
272
+ export type MatchReplaceMatcherRawValue = {
273
+ kind: "MatcherRawValue";
274
+ value: string;
275
+ };
276
+ /**
277
+ * This matcher will match the entire section.
278
+ * @category Match and Replace
279
+ */
280
+ export type MatchReplaceMatcherRawFull = {
281
+ kind: "MatcherRawFull";
282
+ };
283
+ /**
284
+ * A replacer in Match and Replace.
285
+ * @category Match and Replace
286
+ */
287
+ export type MatchReplaceReplacer = MatchReplaceReplacerTerm | MatchReplaceReplacerWorkflow;
288
+ /**
289
+ * A replacer that replaces with a term.
290
+ * If the matcher is a regex, groups will be interpolated.
291
+ * @category Match and Replace
292
+ */
293
+ export type MatchReplaceReplacerTerm = {
294
+ kind: "ReplacerTerm";
295
+ term: string;
296
+ };
297
+ /**
298
+ * A replacer that replaces with the result of a workflow.
299
+ * The input of the workflow depends on the operation and matcher.
300
+ * @category Match and Replace
301
+ */
302
+ export type MatchReplaceReplacerWorkflow = {
303
+ kind: "ReplacerWorkflow";
304
+ workflowId: ID;
305
+ };
142
306
  /**
143
307
  * A collection in Match and Replace.
144
308
  * @category Match and Replace
@@ -148,3 +312,7 @@ export type MatchReplaceCollection = {
148
312
  name: string;
149
313
  ruleIds: ID[];
150
314
  };
315
+ type KeepOperation<T> = T & {
316
+ __operation?: never;
317
+ };
318
+ export {};