@stuntman/client 0.1.5 → 0.1.6
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/dist/apiClient.d.ts +2 -2
- package/dist/apiClient.js +5 -5
- package/dist/ruleBuilder.js +4 -0
- package/package.json +1 -1
- package/src/apiClient.ts +8 -8
- package/src/ruleBuilder.ts +4 -0
package/dist/apiClient.d.ts
CHANGED
|
@@ -17,7 +17,7 @@ export declare class Client {
|
|
|
17
17
|
enableRule(id: string): Promise<void>;
|
|
18
18
|
removeRule(id: string): Promise<void>;
|
|
19
19
|
addRule(rule: Stuntman.SerializableRule): Promise<Stuntman.Rule>;
|
|
20
|
-
getTraffic(rule: Stuntman.Rule): Promise<
|
|
21
|
-
getTraffic(ruleIdOrLabel: string): Promise<
|
|
20
|
+
getTraffic(rule: Stuntman.Rule): Promise<Stuntman.LogEntry[]>;
|
|
21
|
+
getTraffic(ruleIdOrLabel: string): Promise<Stuntman.LogEntry[]>;
|
|
22
22
|
}
|
|
23
23
|
export {};
|
package/dist/apiClient.js
CHANGED
|
@@ -124,7 +124,7 @@ class Client {
|
|
|
124
124
|
catch (kiss) {
|
|
125
125
|
// and swallow
|
|
126
126
|
}
|
|
127
|
-
if ('error' in json) {
|
|
127
|
+
if (json && 'error' in json) {
|
|
128
128
|
throw new clientError_1.ClientError(json.error);
|
|
129
129
|
}
|
|
130
130
|
throw new Error(`Unexpected errror: ${text}`);
|
|
@@ -137,11 +137,11 @@ class Client {
|
|
|
137
137
|
}
|
|
138
138
|
async getRules() {
|
|
139
139
|
const response = await this.fetch(`${this.baseUrl}/rules`);
|
|
140
|
-
return response.json();
|
|
140
|
+
return (await response.json());
|
|
141
141
|
}
|
|
142
142
|
async getRule(id) {
|
|
143
143
|
const response = await this.fetch(`${this.baseUrl}/rule/${encodeURIComponent(id)}`);
|
|
144
|
-
return response.json();
|
|
144
|
+
return (await response.json());
|
|
145
145
|
}
|
|
146
146
|
async disableRule(id) {
|
|
147
147
|
await this.fetch(`${this.baseUrl}/rule/${encodeURIComponent(id)}/disable`);
|
|
@@ -159,12 +159,12 @@ class Client {
|
|
|
159
159
|
body: JSON.stringify(serializedRule),
|
|
160
160
|
headers: { 'content-type': 'application/json' },
|
|
161
161
|
});
|
|
162
|
-
return response.json();
|
|
162
|
+
return (await response.json());
|
|
163
163
|
}
|
|
164
164
|
async getTraffic(ruleOrIdOrLabel) {
|
|
165
165
|
const ruleId = typeof ruleOrIdOrLabel === 'object' ? ruleOrIdOrLabel.id : ruleOrIdOrLabel;
|
|
166
166
|
const response = await this.fetch(`${this.baseUrl}/traffic${ruleId ? `/${encodeURIComponent(ruleId)}` : ''}`);
|
|
167
|
-
return response.json();
|
|
167
|
+
return (await response.json());
|
|
168
168
|
}
|
|
169
169
|
}
|
|
170
170
|
exports.Client = Client;
|
package/dist/ruleBuilder.js
CHANGED
|
@@ -11,6 +11,9 @@ class RuleBuilderBaseBase {
|
|
|
11
11
|
id: (0, uuid_1.v4)(),
|
|
12
12
|
ttlSeconds: shared_1.DEFAULT_RULE_TTL_SECONDS,
|
|
13
13
|
priority: shared_1.DEFAULT_RULE_PRIORITY,
|
|
14
|
+
actions: {
|
|
15
|
+
mockResponse: { status: 200 },
|
|
16
|
+
},
|
|
14
17
|
matches: {
|
|
15
18
|
localFn: (req) => {
|
|
16
19
|
var _a, _b, _c, _d;
|
|
@@ -467,6 +470,7 @@ class RuleBuilderInitialized extends RuleBuilderBase {
|
|
|
467
470
|
return this;
|
|
468
471
|
}
|
|
469
472
|
proxyPass() {
|
|
473
|
+
this.rule.actions = { proxyPass: true };
|
|
470
474
|
return this.rule;
|
|
471
475
|
}
|
|
472
476
|
mockResponse(response, localVariables) {
|
package/package.json
CHANGED
package/src/apiClient.ts
CHANGED
|
@@ -135,7 +135,7 @@ export class Client {
|
|
|
135
135
|
} catch (kiss) {
|
|
136
136
|
// and swallow
|
|
137
137
|
}
|
|
138
|
-
if ('error' in json) {
|
|
138
|
+
if (json && 'error' in json) {
|
|
139
139
|
throw new ClientError(json.error);
|
|
140
140
|
}
|
|
141
141
|
throw new Error(`Unexpected errror: ${text}`);
|
|
@@ -148,12 +148,12 @@ export class Client {
|
|
|
148
148
|
|
|
149
149
|
async getRules(): Promise<Stuntman.LiveRule[]> {
|
|
150
150
|
const response = await this.fetch(`${this.baseUrl}/rules`);
|
|
151
|
-
return response.json() as
|
|
151
|
+
return (await response.json()) as Promise<Stuntman.LiveRule[]>;
|
|
152
152
|
}
|
|
153
153
|
|
|
154
154
|
async getRule(id: string): Promise<Stuntman.LiveRule> {
|
|
155
155
|
const response = await this.fetch(`${this.baseUrl}/rule/${encodeURIComponent(id)}`);
|
|
156
|
-
return response.json() as
|
|
156
|
+
return (await response.json()) as Stuntman.LiveRule;
|
|
157
157
|
}
|
|
158
158
|
|
|
159
159
|
async disableRule(id: string): Promise<void> {
|
|
@@ -175,15 +175,15 @@ export class Client {
|
|
|
175
175
|
body: JSON.stringify(serializedRule),
|
|
176
176
|
headers: { 'content-type': 'application/json' },
|
|
177
177
|
});
|
|
178
|
-
return response.json() as
|
|
178
|
+
return (await response.json()) as Stuntman.Rule;
|
|
179
179
|
}
|
|
180
180
|
|
|
181
181
|
// TODO improve filtering by timestamp from - to, multiple labels, etc.
|
|
182
|
-
async getTraffic(rule: Stuntman.Rule): Promise<
|
|
183
|
-
async getTraffic(ruleIdOrLabel: string): Promise<
|
|
184
|
-
async getTraffic(ruleOrIdOrLabel: string | Stuntman.Rule): Promise<
|
|
182
|
+
async getTraffic(rule: Stuntman.Rule): Promise<Stuntman.LogEntry[]>;
|
|
183
|
+
async getTraffic(ruleIdOrLabel: string): Promise<Stuntman.LogEntry[]>;
|
|
184
|
+
async getTraffic(ruleOrIdOrLabel: string | Stuntman.Rule): Promise<Stuntman.LogEntry[]> {
|
|
185
185
|
const ruleId = typeof ruleOrIdOrLabel === 'object' ? ruleOrIdOrLabel.id : ruleOrIdOrLabel;
|
|
186
186
|
const response = await this.fetch(`${this.baseUrl}/traffic${ruleId ? `/${encodeURIComponent(ruleId)}` : ''}`);
|
|
187
|
-
return response.json() as
|
|
187
|
+
return (await response.json()) as Stuntman.LogEntry[];
|
|
188
188
|
}
|
|
189
189
|
}
|
package/src/ruleBuilder.ts
CHANGED
|
@@ -40,6 +40,9 @@ class RuleBuilderBaseBase {
|
|
|
40
40
|
id: uuidv4(),
|
|
41
41
|
ttlSeconds: DEFAULT_RULE_TTL_SECONDS,
|
|
42
42
|
priority: DEFAULT_RULE_PRIORITY,
|
|
43
|
+
actions: {
|
|
44
|
+
mockResponse: { status: 200 },
|
|
45
|
+
},
|
|
43
46
|
matches: {
|
|
44
47
|
localFn: (req: Stuntman.Request): Stuntman.RuleMatchResult => {
|
|
45
48
|
const ___url = new URL(req.url);
|
|
@@ -548,6 +551,7 @@ class RuleBuilderInitialized extends RuleBuilderBase {
|
|
|
548
551
|
}
|
|
549
552
|
|
|
550
553
|
proxyPass(): Stuntman.SerializableRule {
|
|
554
|
+
this.rule.actions = { proxyPass: true };
|
|
551
555
|
return this.rule;
|
|
552
556
|
}
|
|
553
557
|
|