@chaos-maker/core 0.4.0 → 0.6.0
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/README.md +131 -10
- package/dist/chaos-config.schema.json +1314 -0
- package/dist/chaos-config.schema.notes.md +32 -0
- package/dist/chaos-maker.cjs +30 -5
- package/dist/chaos-maker.js +3845 -2400
- package/dist/chaos-maker.umd.js +30 -5
- package/dist/sw.js +1 -1
- package/dist/sw.mjs +861 -451
- package/dist/types/ChaosMaker.d.ts +46 -0
- package/dist/types/builder.d.ts +24 -0
- package/dist/types/config.d.ts +82 -14
- package/dist/types/debug.d.ts +58 -0
- package/dist/types/errors.d.ts +14 -2
- package/dist/types/events.d.ts +59 -1
- package/dist/types/format-event.d.ts +13 -0
- package/dist/types/groups.d.ts +71 -0
- package/dist/types/index.d.ts +33 -5
- package/dist/types/interceptors/domAssailant.d.ts +2 -1
- package/dist/types/interceptors/eventSource.d.ts +2 -1
- package/dist/types/interceptors/networkFetch.d.ts +2 -1
- package/dist/types/interceptors/networkXHR.d.ts +2 -1
- package/dist/types/interceptors/websocket.d.ts +2 -1
- package/dist/types/presets.d.ts +63 -2
- package/dist/types/runtime-state.d.ts +6 -0
- package/dist/types/seed-reporting.d.ts +1 -0
- package/dist/types/session-errors.d.ts +18 -0
- package/dist/types/sw-bridge-source.d.ts +5 -2
- package/dist/types/sw.d.ts +7 -0
- package/dist/types/utils.d.ts +46 -1
- package/dist/types/validation-deprecation.d.ts +7 -0
- package/dist/types/validation-format.d.ts +10 -0
- package/dist/types/validation-strip.d.ts +11 -0
- package/dist/types/validation-types.d.ts +34 -0
- package/dist/types/validation.d.ts +52 -0
- package/package.json +5 -3
package/dist/sw.mjs
CHANGED
|
@@ -1,21 +1,44 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
class
|
|
5
|
-
constructor(
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
this
|
|
1
|
+
var pe = Object.defineProperty;
|
|
2
|
+
var ge = (n, e, o) => e in n ? pe(n, e, { enumerable: !0, configurable: !0, writable: !0, value: o }) : n[e] = o;
|
|
3
|
+
var O = (n, e, o) => ge(n, typeof e != "symbol" ? e + "" : e, o);
|
|
4
|
+
class he {
|
|
5
|
+
constructor(e = 2e3) {
|
|
6
|
+
O(this, "listeners", /* @__PURE__ */ new Map());
|
|
7
|
+
O(this, "log", []);
|
|
8
|
+
O(this, "logger");
|
|
9
|
+
O(this, "ruleIds");
|
|
10
|
+
this.maxLogEntries = e;
|
|
9
11
|
}
|
|
10
|
-
on(
|
|
11
|
-
this.listeners.has(
|
|
12
|
+
on(e, o) {
|
|
13
|
+
this.listeners.has(e) || this.listeners.set(e, /* @__PURE__ */ new Set()), this.listeners.get(e).add(o);
|
|
12
14
|
}
|
|
13
|
-
off(
|
|
14
|
-
var
|
|
15
|
-
(
|
|
15
|
+
off(e, o) {
|
|
16
|
+
var t;
|
|
17
|
+
(t = this.listeners.get(e)) == null || t.delete(o);
|
|
16
18
|
}
|
|
17
|
-
emit(
|
|
18
|
-
this.log.push(
|
|
19
|
+
emit(e) {
|
|
20
|
+
this.log.push(e), this.log.length > this.maxLogEntries && this.log.shift(), this.notify(this.listeners.get(e.type), e), this.notify(this.listeners.get("*"), e);
|
|
21
|
+
}
|
|
22
|
+
/** Attach a Debug Mode logger. When unset, `debug()` is a fast-path no-op. */
|
|
23
|
+
setLogger(e) {
|
|
24
|
+
this.logger = e;
|
|
25
|
+
}
|
|
26
|
+
/** Attach the rule-id map so debug events auto-resolve `ruleType` /
|
|
27
|
+
* `ruleId` from a rule object reference. */
|
|
28
|
+
setRuleIds(e) {
|
|
29
|
+
this.ruleIds = e;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Emit a Debug Mode event. Fast-path no-op when no logger is attached —
|
|
33
|
+
* single undefined-check before any allocation. When `rule` is supplied
|
|
34
|
+
* and present in the rule-id map, `detail.ruleType` and `detail.ruleId`
|
|
35
|
+
* are filled in automatically.
|
|
36
|
+
*/
|
|
37
|
+
debug(e, o, t) {
|
|
38
|
+
var p;
|
|
39
|
+
if (!this.logger) return;
|
|
40
|
+
const s = t ? (p = this.ruleIds) == null ? void 0 : p.get(t) : void 0, i = s ? { ...o, ruleType: s.ruleType, ruleId: s.ruleId } : o, l = this.logger.log(e, i);
|
|
41
|
+
l && this.emit(l);
|
|
19
42
|
}
|
|
20
43
|
getLog() {
|
|
21
44
|
return [...this.log];
|
|
@@ -23,624 +46,990 @@ class se {
|
|
|
23
46
|
clearLog() {
|
|
24
47
|
this.log = [];
|
|
25
48
|
}
|
|
26
|
-
notify(
|
|
27
|
-
if (
|
|
28
|
-
for (const
|
|
49
|
+
notify(e, o) {
|
|
50
|
+
if (e)
|
|
51
|
+
for (const t of e)
|
|
29
52
|
try {
|
|
30
|
-
|
|
53
|
+
t(o);
|
|
31
54
|
} catch {
|
|
32
55
|
}
|
|
33
56
|
}
|
|
34
57
|
}
|
|
35
|
-
function
|
|
36
|
-
let
|
|
58
|
+
function be(n) {
|
|
59
|
+
let e = n | 0;
|
|
37
60
|
return () => {
|
|
38
|
-
|
|
39
|
-
let
|
|
40
|
-
return
|
|
61
|
+
e = e + 1831565813 | 0;
|
|
62
|
+
let o = Math.imul(e ^ e >>> 15, 1 | e);
|
|
63
|
+
return o = o + Math.imul(o ^ o >>> 7, 61 | o) ^ o, ((o ^ o >>> 14) >>> 0) / 4294967296;
|
|
41
64
|
};
|
|
42
65
|
}
|
|
43
|
-
function
|
|
66
|
+
function ye() {
|
|
44
67
|
return Math.random() * 4294967296 >>> 0;
|
|
45
68
|
}
|
|
46
|
-
function
|
|
47
|
-
const
|
|
69
|
+
function ue(n) {
|
|
70
|
+
const e = n ?? ye();
|
|
48
71
|
return {
|
|
49
|
-
random:
|
|
50
|
-
seed:
|
|
72
|
+
random: be(e),
|
|
73
|
+
seed: e
|
|
51
74
|
};
|
|
52
75
|
}
|
|
53
|
-
|
|
54
|
-
|
|
76
|
+
const J = "default";
|
|
77
|
+
class le {
|
|
78
|
+
constructor() {
|
|
79
|
+
O(this, "groups", /* @__PURE__ */ new Map());
|
|
80
|
+
/**
|
|
81
|
+
* Tracks groups that have already emitted a `rule-group:gated` event since
|
|
82
|
+
* the last toggle. Cleared on every `setEnabled()` so the next toggle cycle
|
|
83
|
+
* gets a fresh diagnostic event without flooding.
|
|
84
|
+
*/
|
|
85
|
+
O(this, "gatedEmitted", /* @__PURE__ */ new Set());
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Look up an existing group or create a new one.
|
|
89
|
+
*
|
|
90
|
+
* - Implicit (auto-create from `isActive`): `explicit: false`, defaults
|
|
91
|
+
* `enabled: true`.
|
|
92
|
+
* - Explicit (`ChaosConfig.groups` / `createGroup()`): `explicit: true`.
|
|
93
|
+
* When called with both `explicit: true` and `enabled` set, the existing
|
|
94
|
+
* group's `enabled` is overwritten; the explicit form is the source of truth.
|
|
95
|
+
*/
|
|
96
|
+
ensure(e, o) {
|
|
97
|
+
const t = this.groups.get(e);
|
|
98
|
+
if (t)
|
|
99
|
+
return o != null && o.explicit && (t.explicit = !0), (o == null ? void 0 : o.enabled) !== void 0 && (t.enabled = o.enabled), t;
|
|
100
|
+
const s = {
|
|
101
|
+
name: e,
|
|
102
|
+
enabled: (o == null ? void 0 : o.enabled) ?? !0,
|
|
103
|
+
explicit: (o == null ? void 0 : o.explicit) ?? !1
|
|
104
|
+
};
|
|
105
|
+
return this.groups.set(e, s), s;
|
|
106
|
+
}
|
|
107
|
+
setEnabled(e, o) {
|
|
108
|
+
this.ensure(e).enabled = o, this.gatedEmitted.clear();
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Auto-creates unknown groups on first check (implicit). Rationale:
|
|
112
|
+
* silently returning `true` for unknown names lets typos like
|
|
113
|
+
* `group: 'paymets'` mask chaos as if no group existed; auto-registering
|
|
114
|
+
* surfaces the typo via `list()` / `getSnapshot()` and keeps default-on
|
|
115
|
+
* backward compat.
|
|
116
|
+
*/
|
|
117
|
+
isActive(e) {
|
|
118
|
+
return this.ensure(e ?? J).enabled;
|
|
119
|
+
}
|
|
120
|
+
/** True when this group should emit a `rule-group:gated` event right now (first block since last toggle). */
|
|
121
|
+
shouldEmitGated(e) {
|
|
122
|
+
return this.gatedEmitted.has(e) ? !1 : (this.gatedEmitted.add(e), !0);
|
|
123
|
+
}
|
|
124
|
+
has(e) {
|
|
125
|
+
return this.groups.has(e);
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Remove a group from the registry.
|
|
129
|
+
* - `'default'` cannot be removed (returns `false`).
|
|
130
|
+
* - By default, throws when any rule in `referencedBy` still uses the group.
|
|
131
|
+
* - Pass `{ force: true }` to remove anyway. Subsequent `isActive(name)`
|
|
132
|
+
* calls auto-recreate the group (default-on).
|
|
133
|
+
*/
|
|
134
|
+
remove(e, o, t) {
|
|
135
|
+
if (e === J) return !1;
|
|
136
|
+
if (!(t != null && t.force) && o.has(e))
|
|
137
|
+
throw new Error(
|
|
138
|
+
`[chaos-maker] Cannot remove group '${e}': still referenced by one or more rules. Pass { force: true } to override.`
|
|
139
|
+
);
|
|
140
|
+
const s = this.groups.delete(e);
|
|
141
|
+
return s && this.gatedEmitted.delete(e), s;
|
|
142
|
+
}
|
|
143
|
+
list() {
|
|
144
|
+
return [...this.groups.values()].map(
|
|
145
|
+
(e) => ({ ...e })
|
|
146
|
+
);
|
|
147
|
+
}
|
|
148
|
+
getSnapshot() {
|
|
149
|
+
const e = {};
|
|
150
|
+
for (const o of this.groups.values()) e[o.name] = o.enabled;
|
|
151
|
+
return e;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
function I(n, e) {
|
|
155
|
+
return e() < n;
|
|
55
156
|
}
|
|
56
|
-
function
|
|
57
|
-
const
|
|
58
|
-
return
|
|
157
|
+
function P(n, e) {
|
|
158
|
+
const o = (e.get(n) ?? 0) + 1;
|
|
159
|
+
return e.set(n, o), o;
|
|
59
160
|
}
|
|
60
|
-
function
|
|
61
|
-
return
|
|
161
|
+
function $(n, e) {
|
|
162
|
+
return n.onNth !== void 0 ? e === n.onNth : n.everyNth !== void 0 ? e % n.everyNth === 0 : n.afterN !== void 0 ? e > n.afterN : !0;
|
|
62
163
|
}
|
|
63
|
-
function
|
|
64
|
-
return
|
|
164
|
+
function Z(n, e) {
|
|
165
|
+
return e === "*" ? !0 : n.includes(e);
|
|
65
166
|
}
|
|
66
|
-
function
|
|
67
|
-
switch (
|
|
167
|
+
function ke(n, e) {
|
|
168
|
+
switch (e) {
|
|
68
169
|
case "truncate":
|
|
69
|
-
return
|
|
170
|
+
return n.slice(0, Math.max(0, Math.floor(n.length / 2)));
|
|
70
171
|
case "malformed-json":
|
|
71
|
-
return `${
|
|
172
|
+
return `${n}"}`;
|
|
72
173
|
case "empty":
|
|
73
174
|
return "";
|
|
74
175
|
case "wrong-type":
|
|
75
176
|
return "<html><body>Unexpected HTML</body></html>";
|
|
76
177
|
}
|
|
77
178
|
}
|
|
78
|
-
function
|
|
79
|
-
|
|
80
|
-
|
|
179
|
+
function q(n, e, o, t) {
|
|
180
|
+
if (!e || e.isActive(n.group)) return !0;
|
|
181
|
+
const s = n.group ?? J;
|
|
182
|
+
return e.shouldEmitGated(s) && o && o.emit({
|
|
183
|
+
type: "rule-group:gated",
|
|
184
|
+
timestamp: Date.now(),
|
|
185
|
+
applied: !1,
|
|
186
|
+
detail: { ...t, groupName: s }
|
|
187
|
+
}), o == null || o.debug("rule-skip-group", { ...t, groupName: s }, n), !1;
|
|
188
|
+
}
|
|
189
|
+
function we(n, e) {
|
|
190
|
+
var t, s, i, l, p, u, a, S, A, M, L, N, T, f;
|
|
191
|
+
const o = (c) => {
|
|
192
|
+
if (c)
|
|
193
|
+
for (const d of c) e(d);
|
|
194
|
+
};
|
|
195
|
+
o((t = n.network) == null ? void 0 : t.failures), o((s = n.network) == null ? void 0 : s.latencies), o((i = n.network) == null ? void 0 : i.aborts), o((l = n.network) == null ? void 0 : l.corruptions), o((p = n.network) == null ? void 0 : p.cors), o((u = n.ui) == null ? void 0 : u.assaults), o((a = n.websocket) == null ? void 0 : a.drops), o((S = n.websocket) == null ? void 0 : S.delays), o((A = n.websocket) == null ? void 0 : A.corruptions), o((M = n.websocket) == null ? void 0 : M.closes), o((L = n.sse) == null ? void 0 : L.drops), o((N = n.sse) == null ? void 0 : N.delays), o((T = n.sse) == null ? void 0 : T.corruptions), o((f = n.sse) == null ? void 0 : f.closes);
|
|
196
|
+
}
|
|
197
|
+
function ce(n) {
|
|
198
|
+
const e = n.replace(/#[^\r\n]*/g, " "), o = /\b(?:query|mutation|subscription)\s+([A-Za-z_][A-Za-z0-9_]*)/.exec(e);
|
|
199
|
+
return (o == null ? void 0 : o[1]) ?? null;
|
|
81
200
|
}
|
|
82
|
-
function
|
|
201
|
+
function Me(n) {
|
|
83
202
|
try {
|
|
84
|
-
return JSON.parse(
|
|
203
|
+
return JSON.parse(n);
|
|
85
204
|
} catch {
|
|
86
205
|
return;
|
|
87
206
|
}
|
|
88
207
|
}
|
|
89
|
-
function
|
|
90
|
-
if (!
|
|
91
|
-
if (Array.isArray(
|
|
92
|
-
return
|
|
93
|
-
const
|
|
94
|
-
return !
|
|
208
|
+
function ie(n) {
|
|
209
|
+
if (!n || typeof n != "object") return { isGraphQL: !1, operationName: null };
|
|
210
|
+
if (Array.isArray(n))
|
|
211
|
+
return n.length === 0 ? { isGraphQL: !1, operationName: null } : ie(n[0]);
|
|
212
|
+
const e = n, o = typeof e.query == "string", t = typeof e.operationName == "string";
|
|
213
|
+
return !o && !t ? { isGraphQL: !1, operationName: null } : t && e.operationName.length > 0 ? { isGraphQL: !0, operationName: e.operationName } : o ? { isGraphQL: !0, operationName: ce(e.query) } : { isGraphQL: !0, operationName: null };
|
|
95
214
|
}
|
|
96
|
-
function
|
|
97
|
-
let
|
|
215
|
+
function ve(n) {
|
|
216
|
+
let e;
|
|
98
217
|
try {
|
|
99
|
-
|
|
218
|
+
e = new URL(n, "http://_chaos-maker.invalid");
|
|
100
219
|
} catch {
|
|
101
220
|
return { kind: "not-graphql" };
|
|
102
221
|
}
|
|
103
|
-
const
|
|
104
|
-
return
|
|
105
|
-
}
|
|
106
|
-
function
|
|
107
|
-
const
|
|
108
|
-
if (
|
|
109
|
-
if (
|
|
110
|
-
const
|
|
111
|
-
if (
|
|
112
|
-
const { isGraphQL:
|
|
113
|
-
return
|
|
222
|
+
const o = e.searchParams.get("operationName"), t = e.searchParams.get("query");
|
|
223
|
+
return o && o.length > 0 ? { kind: "extracted", operationName: o } : t && t.length > 0 ? { kind: "extracted", operationName: ce(t) } : { kind: "not-graphql" };
|
|
224
|
+
}
|
|
225
|
+
function Ce(n, e, o, t) {
|
|
226
|
+
const s = n.toUpperCase();
|
|
227
|
+
if (s === "POST") {
|
|
228
|
+
if (o !== null) {
|
|
229
|
+
const i = Me(o);
|
|
230
|
+
if (i === void 0) return { kind: "not-graphql" };
|
|
231
|
+
const { isGraphQL: l, operationName: p } = ie(i);
|
|
232
|
+
return l ? { kind: "extracted", operationName: p } : { kind: "not-graphql" };
|
|
114
233
|
}
|
|
115
|
-
return
|
|
234
|
+
return t ? { kind: "unparseable" } : { kind: "not-graphql" };
|
|
116
235
|
}
|
|
117
|
-
return
|
|
236
|
+
return s === "GET" ? ve(e) : { kind: "not-graphql" };
|
|
118
237
|
}
|
|
119
|
-
function
|
|
120
|
-
return
|
|
238
|
+
function Se(n, e) {
|
|
239
|
+
return e === null ? !1 : typeof n == "string" ? n === e : ((n.global || n.sticky) && (n.lastIndex = 0), n.test(e));
|
|
121
240
|
}
|
|
122
|
-
function
|
|
123
|
-
return
|
|
241
|
+
function Te(n, e) {
|
|
242
|
+
return n ? e.kind === "not-graphql" ? { kind: "no-match" } : e.kind === "unparseable" ? { kind: "unparseable" } : Se(n, e.operationName) ? { kind: "match", operationName: e.operationName } : { kind: "no-match" } : e.kind === "extracted" ? { kind: "skip-no-constraint", operationName: e.operationName } : { kind: "skip-no-constraint", operationName: null };
|
|
124
243
|
}
|
|
125
|
-
function
|
|
126
|
-
return typeof Request < "u" &&
|
|
244
|
+
function K(n) {
|
|
245
|
+
return typeof Request < "u" && n instanceof Request;
|
|
127
246
|
}
|
|
128
|
-
function
|
|
129
|
-
return
|
|
247
|
+
function Ee(n) {
|
|
248
|
+
return K(n) ? n.url : n.toString();
|
|
130
249
|
}
|
|
131
|
-
function
|
|
132
|
-
return
|
|
250
|
+
function Le(n, e) {
|
|
251
|
+
return e != null && e.method ? e.method.toUpperCase() : K(n) ? n.method.toUpperCase() : "GET";
|
|
133
252
|
}
|
|
134
|
-
function
|
|
135
|
-
if (
|
|
136
|
-
return t.signal;
|
|
137
|
-
if (H(e))
|
|
253
|
+
function Ae(n, e) {
|
|
254
|
+
if (e != null && e.signal)
|
|
138
255
|
return e.signal;
|
|
256
|
+
if (K(n))
|
|
257
|
+
return n.signal;
|
|
139
258
|
}
|
|
140
|
-
function
|
|
259
|
+
function Ne() {
|
|
141
260
|
if (typeof DOMException < "u")
|
|
142
261
|
return new DOMException("The user aborted a request.", "AbortError");
|
|
143
|
-
const
|
|
144
|
-
return
|
|
262
|
+
const n = new Error("The user aborted a request.");
|
|
263
|
+
return n.name = "AbortError", n;
|
|
145
264
|
}
|
|
146
|
-
function
|
|
147
|
-
if (!
|
|
148
|
-
return
|
|
149
|
-
const
|
|
150
|
-
|
|
151
|
-
},
|
|
152
|
-
|
|
265
|
+
function xe(n, e) {
|
|
266
|
+
if (!e)
|
|
267
|
+
return n;
|
|
268
|
+
const o = new AbortController(), t = (p) => {
|
|
269
|
+
l(), o.signal.aborted || o.abort(p.reason);
|
|
270
|
+
}, s = () => t(n), i = () => t(e), l = () => {
|
|
271
|
+
n.removeEventListener("abort", s), e.removeEventListener("abort", i);
|
|
153
272
|
};
|
|
154
|
-
return
|
|
155
|
-
}
|
|
156
|
-
function
|
|
157
|
-
return
|
|
158
|
-
...
|
|
159
|
-
signal:
|
|
160
|
-
} :
|
|
161
|
-
}
|
|
162
|
-
async function
|
|
163
|
-
const
|
|
164
|
-
if (
|
|
165
|
-
if (typeof
|
|
166
|
-
if (typeof URLSearchParams < "u" &&
|
|
167
|
-
return { text:
|
|
168
|
-
if (typeof Blob < "u" &&
|
|
169
|
-
if (!(
|
|
273
|
+
return n.aborted ? (t(n), o.signal) : e.aborted ? (t(e), o.signal) : (n.addEventListener("abort", s, { once: !0 }), e.addEventListener("abort", i, { once: !0 }), o.signal);
|
|
274
|
+
}
|
|
275
|
+
function _e(n, e) {
|
|
276
|
+
return e ? {
|
|
277
|
+
...n ?? {},
|
|
278
|
+
signal: e
|
|
279
|
+
} : n;
|
|
280
|
+
}
|
|
281
|
+
async function Re(n, e) {
|
|
282
|
+
const o = e == null ? void 0 : e.body;
|
|
283
|
+
if (o != null) {
|
|
284
|
+
if (typeof o == "string") return { text: o, unparseable: !1 };
|
|
285
|
+
if (typeof URLSearchParams < "u" && o instanceof URLSearchParams)
|
|
286
|
+
return { text: o.toString(), unparseable: !1 };
|
|
287
|
+
if (typeof Blob < "u" && o instanceof Blob) {
|
|
288
|
+
if (!(o.type === "" || /json|text|graphql/i.test(o.type))) return { text: null, unparseable: !0 };
|
|
170
289
|
try {
|
|
171
|
-
return { text: await
|
|
290
|
+
return { text: await o.text(), unparseable: !1 };
|
|
172
291
|
} catch {
|
|
173
292
|
return { text: null, unparseable: !0 };
|
|
174
293
|
}
|
|
175
294
|
}
|
|
176
295
|
return { text: null, unparseable: !0 };
|
|
177
296
|
}
|
|
178
|
-
if (
|
|
179
|
-
if (
|
|
297
|
+
if (K(n)) {
|
|
298
|
+
if (n.body === null) return { text: null, unparseable: !1 };
|
|
180
299
|
try {
|
|
181
|
-
return { text: await
|
|
300
|
+
return { text: await n.clone().text(), unparseable: !1 };
|
|
182
301
|
} catch {
|
|
183
302
|
return { text: null, unparseable: !0 };
|
|
184
303
|
}
|
|
185
304
|
}
|
|
186
305
|
return { text: null, unparseable: !1 };
|
|
187
306
|
}
|
|
188
|
-
function
|
|
189
|
-
|
|
190
|
-
type:
|
|
307
|
+
function U(n, e, o, t, s) {
|
|
308
|
+
n == null || n.emit({
|
|
309
|
+
type: e,
|
|
191
310
|
timestamp: Date.now(),
|
|
192
311
|
applied: !1,
|
|
193
|
-
detail: { url:
|
|
312
|
+
detail: { url: o, method: t, ...s, reason: "graphql-body-unparseable" }
|
|
194
313
|
});
|
|
195
314
|
}
|
|
196
|
-
function
|
|
197
|
-
if (!
|
|
198
|
-
if (
|
|
199
|
-
const
|
|
200
|
-
|
|
201
|
-
return { proceed: !1, outcome: u };
|
|
202
|
-
const p = $(e, a);
|
|
203
|
-
return B(e, p) ? { proceed: !0, outcome: u } : { proceed: !1, outcome: u };
|
|
315
|
+
function W(n, e, o, t) {
|
|
316
|
+
if (!Z(e, n.urlPattern)) return { proceed: !1, outcome: null };
|
|
317
|
+
if (n.methods && !n.methods.includes(o)) return { proceed: !1, outcome: null };
|
|
318
|
+
const s = Te(n.graphqlOperation, t);
|
|
319
|
+
return s.kind === "no-match" ? { proceed: !1, outcome: s } : { proceed: !0, outcome: s };
|
|
204
320
|
}
|
|
205
|
-
function
|
|
206
|
-
return
|
|
321
|
+
function B(n) {
|
|
322
|
+
return n ? n.kind === "match" || n.kind === "skip-no-constraint" ? n.operationName ? { operationName: n.operationName } : {} : {} : {};
|
|
207
323
|
}
|
|
208
|
-
function
|
|
209
|
-
|
|
324
|
+
function m(n, e, o, t, s, i) {
|
|
325
|
+
n == null || n.emit({
|
|
210
326
|
type: "network:abort",
|
|
211
327
|
timestamp: Date.now(),
|
|
212
|
-
applied:
|
|
213
|
-
detail: { url:
|
|
328
|
+
applied: s,
|
|
329
|
+
detail: { url: o, method: t, timeoutMs: e.timeout, ...B(i) }
|
|
214
330
|
});
|
|
215
331
|
}
|
|
216
|
-
function
|
|
217
|
-
|
|
332
|
+
function Q(n, e, o, t, s, i) {
|
|
333
|
+
n == null || n.emit({
|
|
218
334
|
type: "network:corruption",
|
|
219
335
|
timestamp: Date.now(),
|
|
220
|
-
applied:
|
|
221
|
-
detail: { url:
|
|
336
|
+
applied: s,
|
|
337
|
+
detail: { url: o, method: t, strategy: e.strategy, ...B(i) }
|
|
222
338
|
});
|
|
223
339
|
}
|
|
224
|
-
function
|
|
225
|
-
return
|
|
340
|
+
function Oe(n) {
|
|
341
|
+
return n.graphqlOperation !== void 0;
|
|
226
342
|
}
|
|
227
|
-
function
|
|
228
|
-
return async (
|
|
229
|
-
var
|
|
230
|
-
const
|
|
231
|
-
const
|
|
232
|
-
for (const
|
|
233
|
-
if (
|
|
343
|
+
function Ie(n, e, o, t, s = /* @__PURE__ */ new Map(), i) {
|
|
344
|
+
return async (l, p) => {
|
|
345
|
+
var k, w, C, E, R;
|
|
346
|
+
const u = Ee(l), a = Le(l, p), S = Ae(l, p), A = (() => {
|
|
347
|
+
const r = [e.failures, e.latencies, e.aborts, e.corruptions, e.cors];
|
|
348
|
+
for (const b of r)
|
|
349
|
+
if (b != null && b.some(Oe)) return !0;
|
|
234
350
|
return !1;
|
|
235
351
|
})();
|
|
236
|
-
let
|
|
237
|
-
if (
|
|
238
|
-
const
|
|
239
|
-
|
|
352
|
+
let M = { kind: "not-graphql" };
|
|
353
|
+
if (A) {
|
|
354
|
+
const r = await Re(l, p);
|
|
355
|
+
M = Ce(a, u, r.text, r.unparseable);
|
|
240
356
|
}
|
|
241
|
-
if (
|
|
242
|
-
for (const
|
|
243
|
-
|
|
244
|
-
const
|
|
245
|
-
if (
|
|
246
|
-
|
|
247
|
-
|
|
357
|
+
if (e.cors)
|
|
358
|
+
for (const r of e.cors) {
|
|
359
|
+
t == null || t.debug("rule-evaluating", { url: u, method: a }, r);
|
|
360
|
+
const b = W(r, u, a, M);
|
|
361
|
+
if (!b.proceed) {
|
|
362
|
+
t == null || t.debug("rule-skip-match", { url: u, method: a }, r);
|
|
363
|
+
continue;
|
|
364
|
+
}
|
|
365
|
+
t == null || t.debug("rule-matched", { url: u, method: a }, r);
|
|
366
|
+
const x = P(r, s);
|
|
367
|
+
if (!$(r, x)) {
|
|
368
|
+
t == null || t.debug("rule-skip-counting", { url: u, method: a }, r);
|
|
248
369
|
continue;
|
|
249
370
|
}
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
371
|
+
if (!q(r, i, t, { url: u, method: a })) continue;
|
|
372
|
+
const v = I(r.probability, o);
|
|
373
|
+
if (((k = b.outcome) == null ? void 0 : k.kind) === "unparseable") {
|
|
374
|
+
v && U(t, "network:cors", u, a, {});
|
|
375
|
+
continue;
|
|
376
|
+
}
|
|
377
|
+
if (t == null || t.emit({
|
|
254
378
|
type: "network:cors",
|
|
255
379
|
timestamp: Date.now(),
|
|
256
380
|
applied: v,
|
|
257
|
-
detail: { url:
|
|
258
|
-
}), v) {
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
throw x.stack = "", x;
|
|
381
|
+
detail: { url: u, method: a, ...B(b.outcome) }
|
|
382
|
+
}), !v) {
|
|
383
|
+
t == null || t.debug("rule-skip-probability", { url: u, method: a }, r);
|
|
384
|
+
continue;
|
|
262
385
|
}
|
|
386
|
+
t == null || t.debug("rule-applied", { url: u, method: a }, r);
|
|
387
|
+
const _ = new TypeError("Failed to fetch");
|
|
388
|
+
throw _.stack = "", _;
|
|
263
389
|
}
|
|
264
|
-
let
|
|
265
|
-
const
|
|
266
|
-
!
|
|
390
|
+
let L = null, N = null, T, f, c = !1;
|
|
391
|
+
const d = (r) => {
|
|
392
|
+
!L || c || (c = !0, f && (clearTimeout(f), f = void 0), m(t, L, u, a, r, N));
|
|
267
393
|
};
|
|
268
|
-
if (
|
|
269
|
-
for (const
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
394
|
+
if (e.aborts)
|
|
395
|
+
for (const r of e.aborts) {
|
|
396
|
+
t == null || t.debug("rule-evaluating", { url: u, method: a, timeoutMs: r.timeout }, r);
|
|
397
|
+
const b = W(r, u, a, M);
|
|
398
|
+
if (!b.proceed) {
|
|
399
|
+
t == null || t.debug("rule-skip-match", { url: u, method: a, timeoutMs: r.timeout }, r);
|
|
400
|
+
continue;
|
|
401
|
+
}
|
|
402
|
+
t == null || t.debug("rule-matched", { url: u, method: a, timeoutMs: r.timeout }, r);
|
|
403
|
+
const x = P(r, s);
|
|
404
|
+
if (!$(r, x)) {
|
|
405
|
+
t == null || t.debug("rule-skip-counting", { url: u, method: a, timeoutMs: r.timeout }, r);
|
|
406
|
+
continue;
|
|
407
|
+
}
|
|
408
|
+
if (!q(r, i, t, { url: u, method: a, timeoutMs: r.timeout })) continue;
|
|
409
|
+
const v = I(r.probability, o);
|
|
410
|
+
if (((w = b.outcome) == null ? void 0 : w.kind) === "unparseable") {
|
|
411
|
+
v && U(t, "network:abort", u, a, { timeoutMs: r.timeout });
|
|
273
412
|
continue;
|
|
274
413
|
}
|
|
275
|
-
if (!
|
|
276
|
-
|
|
414
|
+
if (!v) {
|
|
415
|
+
t == null || t.debug("rule-skip-probability", { url: u, method: a, timeoutMs: r.timeout }, r), m(t, r, u, a, !1, b.outcome);
|
|
277
416
|
continue;
|
|
278
417
|
}
|
|
279
|
-
console.warn(`CHAOS: Aborting ${
|
|
280
|
-
const
|
|
281
|
-
T =
|
|
282
|
-
const
|
|
283
|
-
|
|
418
|
+
t == null || t.debug("rule-applied", { url: u, method: a, timeoutMs: r.timeout }, r), console.warn(`CHAOS: Aborting ${a} ${u} after ${r.timeout || 0}ms`), L = r, N = b.outcome;
|
|
419
|
+
const _ = new AbortController();
|
|
420
|
+
T = xe(_.signal, S);
|
|
421
|
+
const j = () => {
|
|
422
|
+
c || (d(!0), _.abort(Ne()));
|
|
284
423
|
};
|
|
285
|
-
|
|
424
|
+
r.timeout ? f = setTimeout(j, r.timeout) : j();
|
|
286
425
|
break;
|
|
287
426
|
}
|
|
288
|
-
if (
|
|
427
|
+
if (L)
|
|
289
428
|
try {
|
|
290
|
-
const
|
|
291
|
-
return
|
|
292
|
-
} catch (
|
|
293
|
-
throw
|
|
429
|
+
const r = await n(l, _e(p, T));
|
|
430
|
+
return d(!1), r;
|
|
431
|
+
} catch (r) {
|
|
432
|
+
throw d(!1), r;
|
|
294
433
|
}
|
|
295
|
-
if (
|
|
296
|
-
for (const
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
434
|
+
if (e.failures)
|
|
435
|
+
for (const r of e.failures) {
|
|
436
|
+
t == null || t.debug("rule-evaluating", { url: u, method: a, statusCode: r.statusCode }, r);
|
|
437
|
+
const b = W(r, u, a, M);
|
|
438
|
+
if (!b.proceed) {
|
|
439
|
+
t == null || t.debug("rule-skip-match", { url: u, method: a, statusCode: r.statusCode }, r);
|
|
300
440
|
continue;
|
|
301
441
|
}
|
|
302
|
-
|
|
303
|
-
|
|
442
|
+
t == null || t.debug("rule-matched", { url: u, method: a, statusCode: r.statusCode }, r);
|
|
443
|
+
const x = P(r, s);
|
|
444
|
+
if (!$(r, x)) {
|
|
445
|
+
t == null || t.debug("rule-skip-counting", { url: u, method: a, statusCode: r.statusCode }, r);
|
|
446
|
+
continue;
|
|
447
|
+
}
|
|
448
|
+
if (!q(r, i, t, { url: u, method: a, statusCode: r.statusCode })) continue;
|
|
449
|
+
const v = I(r.probability, o);
|
|
450
|
+
if (((C = b.outcome) == null ? void 0 : C.kind) === "unparseable") {
|
|
451
|
+
v && U(t, "network:failure", u, a, { statusCode: r.statusCode });
|
|
452
|
+
continue;
|
|
453
|
+
}
|
|
454
|
+
if (t == null || t.emit({
|
|
304
455
|
type: "network:failure",
|
|
305
456
|
timestamp: Date.now(),
|
|
306
|
-
applied:
|
|
307
|
-
detail: { url:
|
|
308
|
-
}),
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
return new Response(v, {
|
|
312
|
-
status: o.statusCode,
|
|
313
|
-
statusText: o.statusText ?? "Service Unavailable (Chaos)",
|
|
314
|
-
headers: x
|
|
315
|
-
});
|
|
457
|
+
applied: v,
|
|
458
|
+
detail: { url: u, method: a, statusCode: r.statusCode, ...B(b.outcome) }
|
|
459
|
+
}), !v) {
|
|
460
|
+
t == null || t.debug("rule-skip-probability", { url: u, method: a, statusCode: r.statusCode }, r);
|
|
461
|
+
continue;
|
|
316
462
|
}
|
|
463
|
+
t == null || t.debug("rule-applied", { url: u, method: a, statusCode: r.statusCode }, r), console.warn(`CHAOS: Forcing ${r.statusCode} for ${a} ${u}`);
|
|
464
|
+
const _ = r.body ?? JSON.stringify({ error: "Chaos Maker Attack!" }), j = r.headers ?? {};
|
|
465
|
+
return new Response(_, {
|
|
466
|
+
status: r.statusCode,
|
|
467
|
+
statusText: r.statusText ?? "Service Unavailable (Chaos)",
|
|
468
|
+
headers: j
|
|
469
|
+
});
|
|
317
470
|
}
|
|
318
|
-
if (
|
|
319
|
-
for (const
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
471
|
+
if (e.latencies)
|
|
472
|
+
for (const r of e.latencies) {
|
|
473
|
+
t == null || t.debug("rule-evaluating", { url: u, method: a, delayMs: r.delayMs }, r);
|
|
474
|
+
const b = W(r, u, a, M);
|
|
475
|
+
if (!b.proceed) {
|
|
476
|
+
t == null || t.debug("rule-skip-match", { url: u, method: a, delayMs: r.delayMs }, r);
|
|
477
|
+
continue;
|
|
478
|
+
}
|
|
479
|
+
t == null || t.debug("rule-matched", { url: u, method: a, delayMs: r.delayMs }, r);
|
|
480
|
+
const x = P(r, s);
|
|
481
|
+
if (!$(r, x)) {
|
|
482
|
+
t == null || t.debug("rule-skip-counting", { url: u, method: a, delayMs: r.delayMs }, r);
|
|
483
|
+
continue;
|
|
484
|
+
}
|
|
485
|
+
if (!q(r, i, t, { url: u, method: a, delayMs: r.delayMs })) continue;
|
|
486
|
+
const v = I(r.probability, o);
|
|
487
|
+
if (((E = b.outcome) == null ? void 0 : E.kind) === "unparseable") {
|
|
488
|
+
v && U(t, "network:latency", u, a, { delayMs: r.delayMs });
|
|
323
489
|
continue;
|
|
324
490
|
}
|
|
325
|
-
|
|
326
|
-
r == null || r.emit({
|
|
491
|
+
if (t == null || t.emit({
|
|
327
492
|
type: "network:latency",
|
|
328
493
|
timestamp: Date.now(),
|
|
329
|
-
applied:
|
|
330
|
-
detail: { url:
|
|
331
|
-
}),
|
|
494
|
+
applied: v,
|
|
495
|
+
detail: { url: u, method: a, delayMs: r.delayMs, ...B(b.outcome) }
|
|
496
|
+
}), !v) {
|
|
497
|
+
t == null || t.debug("rule-skip-probability", { url: u, method: a, delayMs: r.delayMs }, r);
|
|
498
|
+
continue;
|
|
499
|
+
}
|
|
500
|
+
t == null || t.debug("rule-applied", { url: u, method: a, delayMs: r.delayMs }, r), console.warn(`CHAOS: Adding ${r.delayMs}ms latency to ${a} ${u}`), await new Promise((_) => setTimeout(_, r.delayMs));
|
|
332
501
|
}
|
|
333
|
-
let
|
|
334
|
-
if (
|
|
335
|
-
for (const
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
502
|
+
let g = null, h = null;
|
|
503
|
+
if (e.corruptions)
|
|
504
|
+
for (const r of e.corruptions) {
|
|
505
|
+
t == null || t.debug("rule-evaluating", { url: u, method: a, strategy: r.strategy }, r);
|
|
506
|
+
const b = W(r, u, a, M);
|
|
507
|
+
if (!b.proceed) {
|
|
508
|
+
t == null || t.debug("rule-skip-match", { url: u, method: a, strategy: r.strategy }, r);
|
|
509
|
+
continue;
|
|
510
|
+
}
|
|
511
|
+
t == null || t.debug("rule-matched", { url: u, method: a, strategy: r.strategy }, r);
|
|
512
|
+
const x = P(r, s);
|
|
513
|
+
if (!$(r, x)) {
|
|
514
|
+
t == null || t.debug("rule-skip-counting", { url: u, method: a, strategy: r.strategy }, r);
|
|
515
|
+
continue;
|
|
516
|
+
}
|
|
517
|
+
if (!q(r, i, t, { url: u, method: a, strategy: r.strategy })) continue;
|
|
518
|
+
const v = I(r.probability, o);
|
|
519
|
+
if (((R = b.outcome) == null ? void 0 : R.kind) === "unparseable") {
|
|
520
|
+
v && U(t, "network:corruption", u, a, { strategy: r.strategy });
|
|
339
521
|
continue;
|
|
340
522
|
}
|
|
341
|
-
if (!
|
|
342
|
-
|
|
523
|
+
if (!v) {
|
|
524
|
+
t == null || t.debug("rule-skip-probability", { url: u, method: a, strategy: r.strategy }, r), Q(t, r, u, a, !1, b.outcome);
|
|
343
525
|
continue;
|
|
344
526
|
}
|
|
345
|
-
|
|
527
|
+
t == null || t.debug("rule-applied", { url: u, method: a, strategy: r.strategy }, r), g = r, h = b.outcome;
|
|
346
528
|
break;
|
|
347
529
|
}
|
|
348
|
-
let
|
|
530
|
+
let y;
|
|
349
531
|
try {
|
|
350
|
-
|
|
351
|
-
} catch (
|
|
352
|
-
throw
|
|
532
|
+
y = await n(l, p);
|
|
533
|
+
} catch (r) {
|
|
534
|
+
throw g && Q(t, g, u, a, !1, h), r;
|
|
353
535
|
}
|
|
354
|
-
if (!
|
|
355
|
-
return
|
|
536
|
+
if (!g)
|
|
537
|
+
return y;
|
|
356
538
|
try {
|
|
357
|
-
console.warn(`CHAOS: Corrupting response for ${
|
|
358
|
-
const
|
|
359
|
-
return
|
|
360
|
-
status:
|
|
361
|
-
statusText:
|
|
362
|
-
headers:
|
|
539
|
+
console.warn(`CHAOS: Corrupting response for ${a} ${u} with strategy: ${g.strategy}`);
|
|
540
|
+
const r = await y.text(), b = ke(r, g.strategy);
|
|
541
|
+
return Q(t, g, u, a, !0, h), new Response(b, {
|
|
542
|
+
status: y.status,
|
|
543
|
+
statusText: y.statusText,
|
|
544
|
+
headers: y.headers
|
|
363
545
|
});
|
|
364
|
-
} catch (
|
|
365
|
-
throw
|
|
546
|
+
} catch (r) {
|
|
547
|
+
throw Q(t, g, u, a, !1, h), r;
|
|
366
548
|
}
|
|
367
549
|
};
|
|
368
550
|
}
|
|
369
|
-
const
|
|
370
|
-
function
|
|
371
|
-
return
|
|
551
|
+
const X = /* @__PURE__ */ Symbol.for("chaos-maker.websocket.intercepted");
|
|
552
|
+
function Pe(n, e) {
|
|
553
|
+
return n === "both" ? !0 : n === e;
|
|
372
554
|
}
|
|
373
|
-
function
|
|
374
|
-
return typeof
|
|
555
|
+
function ee(n) {
|
|
556
|
+
return typeof n == "string" ? "text" : "binary";
|
|
375
557
|
}
|
|
376
|
-
function
|
|
377
|
-
switch (
|
|
558
|
+
function ne(n, e) {
|
|
559
|
+
switch (e) {
|
|
378
560
|
case "truncate":
|
|
379
|
-
return
|
|
561
|
+
return n.slice(0, Math.max(0, Math.floor(n.length / 2)));
|
|
380
562
|
case "malformed-json":
|
|
381
|
-
return `${
|
|
563
|
+
return `${n}"}`;
|
|
382
564
|
case "empty":
|
|
383
565
|
return "";
|
|
384
566
|
case "wrong-type":
|
|
385
567
|
return "<html><body>Unexpected HTML</body></html>";
|
|
386
568
|
}
|
|
387
569
|
}
|
|
388
|
-
function
|
|
389
|
-
if (
|
|
390
|
-
if (
|
|
391
|
-
return typeof Blob < "u" &&
|
|
392
|
-
if (typeof Blob < "u" &&
|
|
393
|
-
return
|
|
394
|
-
if (
|
|
395
|
-
return
|
|
396
|
-
const
|
|
397
|
-
return new Uint8Array(
|
|
398
|
-
}
|
|
399
|
-
function
|
|
400
|
-
if (!
|
|
401
|
-
for (const
|
|
402
|
-
if (
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
570
|
+
function oe(n, e) {
|
|
571
|
+
if (e === "malformed-json" || e === "wrong-type") return null;
|
|
572
|
+
if (e === "empty")
|
|
573
|
+
return typeof Blob < "u" && n instanceof Blob ? new Blob([]) : n instanceof ArrayBuffer ? new ArrayBuffer(0) : new Uint8Array(0);
|
|
574
|
+
if (typeof Blob < "u" && n instanceof Blob)
|
|
575
|
+
return n.slice(0, Math.max(0, Math.floor(n.size / 2)));
|
|
576
|
+
if (n instanceof ArrayBuffer)
|
|
577
|
+
return n.slice(0, Math.max(0, Math.floor(n.byteLength / 2)));
|
|
578
|
+
const o = n, t = Math.max(0, Math.floor(o.byteLength / 2));
|
|
579
|
+
return new Uint8Array(o.buffer.slice(o.byteOffset, o.byteOffset + t));
|
|
580
|
+
}
|
|
581
|
+
function D(n, e, o, t, s, i, l) {
|
|
582
|
+
if (!n) return null;
|
|
583
|
+
for (const p of n) {
|
|
584
|
+
if (l == null || l.debug("rule-evaluating", { url: e, direction: o }, p), !Z(e, p.urlPattern)) {
|
|
585
|
+
l == null || l.debug("rule-skip-match", { url: e, direction: o }, p);
|
|
586
|
+
continue;
|
|
587
|
+
}
|
|
588
|
+
if (!Pe(p.direction, o)) {
|
|
589
|
+
l == null || l.debug("rule-skip-match", { url: e, direction: o }, p);
|
|
590
|
+
continue;
|
|
591
|
+
}
|
|
592
|
+
l == null || l.debug("rule-matched", { url: e, direction: o }, p);
|
|
593
|
+
const u = P(p, s);
|
|
594
|
+
if (!$(p, u)) {
|
|
595
|
+
l == null || l.debug("rule-skip-counting", { url: e, direction: o }, p);
|
|
596
|
+
continue;
|
|
597
|
+
}
|
|
598
|
+
if (q(p, i, l, { url: e, direction: o })) {
|
|
599
|
+
if (!I(p.probability, t)) {
|
|
600
|
+
l == null || l.debug("rule-skip-probability", { url: e, direction: o }, p);
|
|
601
|
+
continue;
|
|
602
|
+
}
|
|
603
|
+
return l == null || l.debug("rule-applied", { url: e, direction: o }, p), p;
|
|
604
|
+
}
|
|
406
605
|
}
|
|
407
606
|
return null;
|
|
408
607
|
}
|
|
409
|
-
function
|
|
410
|
-
|
|
608
|
+
function z(n, e, o, t, s) {
|
|
609
|
+
n.emit({
|
|
411
610
|
type: "websocket:drop",
|
|
412
611
|
timestamp: Date.now(),
|
|
413
612
|
applied: !0,
|
|
414
|
-
detail: { url:
|
|
613
|
+
detail: { url: e, direction: o, payloadType: t, ...s ? { reason: s } : {} }
|
|
415
614
|
});
|
|
416
615
|
}
|
|
417
|
-
function
|
|
418
|
-
|
|
616
|
+
function te(n, e, o, t, s) {
|
|
617
|
+
n.emit({
|
|
419
618
|
type: "websocket:delay",
|
|
420
619
|
timestamp: Date.now(),
|
|
421
620
|
applied: !0,
|
|
422
|
-
detail: { url:
|
|
621
|
+
detail: { url: e, direction: o, payloadType: t, delayMs: s }
|
|
423
622
|
});
|
|
424
623
|
}
|
|
425
|
-
function
|
|
426
|
-
|
|
624
|
+
function G(n, e, o, t, s, i, l) {
|
|
625
|
+
n.emit({
|
|
427
626
|
type: "websocket:corrupt",
|
|
428
627
|
timestamp: Date.now(),
|
|
429
|
-
applied:
|
|
430
|
-
detail: { url:
|
|
628
|
+
applied: i,
|
|
629
|
+
detail: { url: e, direction: o, payloadType: t, strategy: s, ...l ? { reason: l } : {} }
|
|
431
630
|
});
|
|
432
631
|
}
|
|
433
|
-
function
|
|
434
|
-
|
|
632
|
+
function $e(n, e, o, t) {
|
|
633
|
+
n.emit({
|
|
435
634
|
type: "websocket:close",
|
|
436
635
|
timestamp: Date.now(),
|
|
437
636
|
applied: !0,
|
|
438
|
-
detail: { url:
|
|
637
|
+
detail: { url: e, closeCode: o, closeReason: t }
|
|
439
638
|
});
|
|
440
639
|
}
|
|
441
|
-
function
|
|
442
|
-
const
|
|
640
|
+
function qe(n, e, o, t, s, i) {
|
|
641
|
+
const l = /* @__PURE__ */ new Map();
|
|
443
642
|
let p = !0;
|
|
444
|
-
const
|
|
445
|
-
let
|
|
446
|
-
|
|
447
|
-
},
|
|
448
|
-
var
|
|
449
|
-
(
|
|
450
|
-
},
|
|
451
|
-
const
|
|
452
|
-
if (
|
|
453
|
-
for (const
|
|
454
|
-
clearTimeout(
|
|
455
|
-
|
|
643
|
+
const u = (f, c) => {
|
|
644
|
+
let d = l.get(f);
|
|
645
|
+
d || (d = /* @__PURE__ */ new Set(), l.set(f, d)), d.add(c);
|
|
646
|
+
}, a = (f, c) => {
|
|
647
|
+
var d;
|
|
648
|
+
(d = l.get(f)) == null || d.delete(c);
|
|
649
|
+
}, S = (f, c) => {
|
|
650
|
+
const d = l.get(f);
|
|
651
|
+
if (d) {
|
|
652
|
+
for (const g of d)
|
|
653
|
+
clearTimeout(g.handle), g.kind === "delay" && z(o, g.url, g.direction, g.payloadType, c);
|
|
654
|
+
l.delete(f);
|
|
456
655
|
}
|
|
457
|
-
},
|
|
458
|
-
const
|
|
459
|
-
data:
|
|
460
|
-
origin:
|
|
461
|
-
lastEventId:
|
|
462
|
-
source:
|
|
463
|
-
ports: Array.from(
|
|
656
|
+
}, A = (f, c, d) => {
|
|
657
|
+
const g = new MessageEvent("message", {
|
|
658
|
+
data: d,
|
|
659
|
+
origin: c.origin,
|
|
660
|
+
lastEventId: c.lastEventId,
|
|
661
|
+
source: c.source,
|
|
662
|
+
ports: Array.from(c.ports ?? [])
|
|
464
663
|
});
|
|
465
|
-
|
|
466
|
-
},
|
|
467
|
-
if (!p) return { handled: !1, data:
|
|
468
|
-
const h = "outbound",
|
|
469
|
-
if (
|
|
470
|
-
return
|
|
471
|
-
let
|
|
472
|
-
const
|
|
473
|
-
if (
|
|
474
|
-
if (
|
|
475
|
-
|
|
664
|
+
g[X] = !0, f.dispatchEvent(g);
|
|
665
|
+
}, M = (f, c, d, g) => {
|
|
666
|
+
if (!p) return { handled: !1, data: d };
|
|
667
|
+
const h = "outbound", y = ee(d);
|
|
668
|
+
if (D(e.drops, c, h, t, s, i, o))
|
|
669
|
+
return z(o, c, h, y), { handled: !0, data: d };
|
|
670
|
+
let k = d;
|
|
671
|
+
const w = D(e.corruptions, c, h, t, s, i, o);
|
|
672
|
+
if (w)
|
|
673
|
+
if (y === "text")
|
|
674
|
+
k = ne(k, w.strategy), G(o, c, h, y, w.strategy, !0);
|
|
476
675
|
else {
|
|
477
|
-
const
|
|
478
|
-
|
|
676
|
+
const E = oe(k, w.strategy);
|
|
677
|
+
E === null ? G(o, c, h, y, w.strategy, !1, "incompatible-payload-type") : (k = E, G(o, c, h, y, w.strategy, !0));
|
|
479
678
|
}
|
|
480
|
-
const
|
|
481
|
-
if (
|
|
482
|
-
|
|
483
|
-
const
|
|
679
|
+
const C = D(e.delays, c, h, t, s, i, o);
|
|
680
|
+
if (C) {
|
|
681
|
+
te(o, c, h, y, C.delayMs);
|
|
682
|
+
const E = {
|
|
484
683
|
kind: "delay",
|
|
485
684
|
handle: setTimeout(() => {
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
},
|
|
492
|
-
url:
|
|
685
|
+
if (a(f, E), !!p)
|
|
686
|
+
try {
|
|
687
|
+
g(k);
|
|
688
|
+
} catch {
|
|
689
|
+
}
|
|
690
|
+
}, C.delayMs),
|
|
691
|
+
url: c,
|
|
493
692
|
direction: h,
|
|
494
|
-
payloadType:
|
|
693
|
+
payloadType: y
|
|
495
694
|
};
|
|
496
|
-
return
|
|
695
|
+
return u(f, E), { handled: !0, data: k };
|
|
497
696
|
}
|
|
498
|
-
return { handled: !1, data:
|
|
499
|
-
},
|
|
500
|
-
|
|
501
|
-
const
|
|
502
|
-
if (
|
|
503
|
-
const h = "inbound",
|
|
504
|
-
if (
|
|
505
|
-
|
|
697
|
+
return { handled: !1, data: k };
|
|
698
|
+
}, L = (f, c) => {
|
|
699
|
+
f.addEventListener("message", (d) => {
|
|
700
|
+
const g = d;
|
|
701
|
+
if (g[X] || !p) return;
|
|
702
|
+
const h = "inbound", y = ee(g.data);
|
|
703
|
+
if (D(e.drops, c, h, t, s, i, o)) {
|
|
704
|
+
g.stopImmediatePropagation(), z(o, c, h, y);
|
|
506
705
|
return;
|
|
507
706
|
}
|
|
508
|
-
let
|
|
509
|
-
const
|
|
510
|
-
if (
|
|
511
|
-
if (
|
|
512
|
-
|
|
707
|
+
let k = g.data, w = !1;
|
|
708
|
+
const C = D(e.corruptions, c, h, t, s, i, o);
|
|
709
|
+
if (C)
|
|
710
|
+
if (y === "text")
|
|
711
|
+
k = ne(k, C.strategy), w = !0, G(o, c, h, y, C.strategy, !0);
|
|
513
712
|
else {
|
|
514
|
-
const
|
|
515
|
-
|
|
713
|
+
const R = oe(k, C.strategy);
|
|
714
|
+
R === null ? G(o, c, h, y, C.strategy, !1, "incompatible-payload-type") : (k = R, w = !0, G(o, c, h, y, C.strategy, !0));
|
|
516
715
|
}
|
|
517
|
-
const
|
|
518
|
-
if (
|
|
519
|
-
|
|
520
|
-
const
|
|
716
|
+
const E = D(e.delays, c, h, t, s, i, o);
|
|
717
|
+
if (E) {
|
|
718
|
+
g.stopImmediatePropagation(), te(o, c, h, y, E.delayMs);
|
|
719
|
+
const R = {
|
|
521
720
|
kind: "delay",
|
|
522
721
|
handle: setTimeout(() => {
|
|
523
|
-
|
|
524
|
-
},
|
|
525
|
-
url:
|
|
722
|
+
a(f, R), p && A(f, g, k);
|
|
723
|
+
}, E.delayMs),
|
|
724
|
+
url: c,
|
|
526
725
|
direction: h,
|
|
527
|
-
payloadType:
|
|
726
|
+
payloadType: y
|
|
528
727
|
};
|
|
529
|
-
|
|
728
|
+
u(f, R);
|
|
530
729
|
return;
|
|
531
730
|
}
|
|
532
|
-
|
|
731
|
+
w && (g.stopImmediatePropagation(), A(f, g, k));
|
|
533
732
|
});
|
|
534
|
-
},
|
|
535
|
-
if (
|
|
536
|
-
for (const
|
|
537
|
-
if (!
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
733
|
+
}, N = (f, c) => {
|
|
734
|
+
if (e.closes)
|
|
735
|
+
for (const d of e.closes) {
|
|
736
|
+
if (o.debug("rule-evaluating", { url: c }, d), !Z(c, d.urlPattern)) {
|
|
737
|
+
o.debug("rule-skip-match", { url: c }, d);
|
|
738
|
+
continue;
|
|
739
|
+
}
|
|
740
|
+
o.debug("rule-matched", { url: c }, d);
|
|
741
|
+
const g = P(d, s);
|
|
742
|
+
if (!$(d, g)) {
|
|
743
|
+
o.debug("rule-skip-counting", { url: c }, d);
|
|
744
|
+
continue;
|
|
745
|
+
}
|
|
746
|
+
if (!q(d, i, o, { url: c })) continue;
|
|
747
|
+
if (!I(d.probability, t)) {
|
|
748
|
+
o.debug("rule-skip-probability", { url: c }, d);
|
|
749
|
+
continue;
|
|
750
|
+
}
|
|
751
|
+
o.debug("rule-applied", { url: c }, d);
|
|
752
|
+
const h = d.code ?? 1e3, y = d.reason ?? "Chaos Maker close", k = d.afterMs ?? 0, w = () => {
|
|
541
753
|
if (p) {
|
|
542
|
-
|
|
754
|
+
S(f, "close-interrupt"), $e(o, c, h, y);
|
|
543
755
|
try {
|
|
544
|
-
|
|
756
|
+
f.close(h, y);
|
|
545
757
|
} catch {
|
|
546
758
|
try {
|
|
547
|
-
|
|
759
|
+
f.close();
|
|
548
760
|
} catch {
|
|
549
761
|
}
|
|
550
762
|
}
|
|
551
763
|
}
|
|
552
764
|
};
|
|
553
|
-
if (
|
|
554
|
-
|
|
765
|
+
if (k <= 0)
|
|
766
|
+
f.readyState === f.OPEN ? w() : f.addEventListener("open", w, { once: !0 });
|
|
555
767
|
else {
|
|
556
|
-
const
|
|
557
|
-
const
|
|
768
|
+
const C = () => {
|
|
769
|
+
const E = {
|
|
558
770
|
kind: "close",
|
|
559
|
-
handle: setTimeout(
|
|
771
|
+
handle: setTimeout(w, k)
|
|
560
772
|
};
|
|
561
|
-
|
|
773
|
+
u(f, E);
|
|
562
774
|
};
|
|
563
|
-
|
|
775
|
+
f.readyState === f.OPEN ? C() : f.addEventListener("open", C, { once: !0 });
|
|
564
776
|
}
|
|
565
777
|
return;
|
|
566
778
|
}
|
|
567
779
|
};
|
|
568
|
-
function T(
|
|
569
|
-
const
|
|
570
|
-
return
|
|
571
|
-
const
|
|
572
|
-
|
|
573
|
-
},
|
|
780
|
+
function T(f, c) {
|
|
781
|
+
const d = new n(f, c), g = typeof f == "string" ? f : f.toString(), h = d.send.bind(d);
|
|
782
|
+
return d.send = function(k) {
|
|
783
|
+
const w = M(d, g, k, h);
|
|
784
|
+
w.handled || h(w.data);
|
|
785
|
+
}, L(d, g), N(d, g), d;
|
|
574
786
|
}
|
|
575
787
|
Object.defineProperty(T, "prototype", {
|
|
576
|
-
value:
|
|
788
|
+
value: n.prototype,
|
|
577
789
|
writable: !1
|
|
578
790
|
});
|
|
579
|
-
for (const
|
|
580
|
-
T[
|
|
791
|
+
for (const f of ["CONNECTING", "OPEN", "CLOSING", "CLOSED"])
|
|
792
|
+
T[f] = n[f];
|
|
581
793
|
return {
|
|
582
794
|
Wrapped: T,
|
|
583
795
|
uninstall() {
|
|
584
796
|
p = !1;
|
|
585
|
-
for (const [,
|
|
586
|
-
for (const
|
|
587
|
-
clearTimeout(
|
|
588
|
-
|
|
797
|
+
for (const [, f] of l)
|
|
798
|
+
for (const c of f)
|
|
799
|
+
clearTimeout(c.handle), c.kind === "delay" && z(o, c.url, c.direction, c.payloadType, "stop-during-delay");
|
|
800
|
+
l.clear();
|
|
589
801
|
}
|
|
590
802
|
};
|
|
591
803
|
}
|
|
592
|
-
|
|
593
|
-
|
|
804
|
+
function De(n) {
|
|
805
|
+
return n === void 0 ? { enabled: !1 } : typeof n == "boolean" ? { enabled: n } : { enabled: n.enabled };
|
|
806
|
+
}
|
|
807
|
+
const Ge = [
|
|
808
|
+
{ pick: (n) => {
|
|
809
|
+
var e;
|
|
810
|
+
return (e = n.network) == null ? void 0 : e.failures;
|
|
811
|
+
}, ruleType: "failure" },
|
|
812
|
+
{ pick: (n) => {
|
|
813
|
+
var e;
|
|
814
|
+
return (e = n.network) == null ? void 0 : e.latencies;
|
|
815
|
+
}, ruleType: "latency" },
|
|
816
|
+
{ pick: (n) => {
|
|
817
|
+
var e;
|
|
818
|
+
return (e = n.network) == null ? void 0 : e.aborts;
|
|
819
|
+
}, ruleType: "abort" },
|
|
820
|
+
{ pick: (n) => {
|
|
821
|
+
var e;
|
|
822
|
+
return (e = n.network) == null ? void 0 : e.corruptions;
|
|
823
|
+
}, ruleType: "corruption" },
|
|
824
|
+
{ pick: (n) => {
|
|
825
|
+
var e;
|
|
826
|
+
return (e = n.network) == null ? void 0 : e.cors;
|
|
827
|
+
}, ruleType: "cors" },
|
|
828
|
+
{ pick: (n) => {
|
|
829
|
+
var e;
|
|
830
|
+
return (e = n.ui) == null ? void 0 : e.assaults;
|
|
831
|
+
}, ruleType: "ui-assault" },
|
|
832
|
+
{ pick: (n) => {
|
|
833
|
+
var e;
|
|
834
|
+
return (e = n.websocket) == null ? void 0 : e.drops;
|
|
835
|
+
}, ruleType: "ws-drop" },
|
|
836
|
+
{ pick: (n) => {
|
|
837
|
+
var e;
|
|
838
|
+
return (e = n.websocket) == null ? void 0 : e.delays;
|
|
839
|
+
}, ruleType: "ws-delay" },
|
|
840
|
+
{ pick: (n) => {
|
|
841
|
+
var e;
|
|
842
|
+
return (e = n.websocket) == null ? void 0 : e.corruptions;
|
|
843
|
+
}, ruleType: "ws-corrupt" },
|
|
844
|
+
{ pick: (n) => {
|
|
845
|
+
var e;
|
|
846
|
+
return (e = n.websocket) == null ? void 0 : e.closes;
|
|
847
|
+
}, ruleType: "ws-close" },
|
|
848
|
+
{ pick: (n) => {
|
|
849
|
+
var e;
|
|
850
|
+
return (e = n.sse) == null ? void 0 : e.drops;
|
|
851
|
+
}, ruleType: "sse-drop" },
|
|
852
|
+
{ pick: (n) => {
|
|
853
|
+
var e;
|
|
854
|
+
return (e = n.sse) == null ? void 0 : e.delays;
|
|
855
|
+
}, ruleType: "sse-delay" },
|
|
856
|
+
{ pick: (n) => {
|
|
857
|
+
var e;
|
|
858
|
+
return (e = n.sse) == null ? void 0 : e.corruptions;
|
|
859
|
+
}, ruleType: "sse-corrupt" },
|
|
860
|
+
{ pick: (n) => {
|
|
861
|
+
var e;
|
|
862
|
+
return (e = n.sse) == null ? void 0 : e.closes;
|
|
863
|
+
}, ruleType: "sse-close" }
|
|
864
|
+
];
|
|
865
|
+
function Fe(n) {
|
|
866
|
+
const e = /* @__PURE__ */ new WeakMap();
|
|
867
|
+
for (const { pick: o, ruleType: t } of Ge) {
|
|
868
|
+
const s = o(n);
|
|
869
|
+
s && s.forEach((i, l) => {
|
|
870
|
+
e.set(i, { ruleType: t, ruleId: `${t}#${l}` });
|
|
871
|
+
});
|
|
872
|
+
}
|
|
873
|
+
return e;
|
|
874
|
+
}
|
|
875
|
+
function Ue(n, e) {
|
|
876
|
+
const o = [];
|
|
877
|
+
return e.ruleId && o.push(`rule=${e.ruleId}`), e.phase && o.push(e.phase), e.method && o.push(e.method), e.url && o.push(e.url), e.statusCode !== void 0 && o.push(`-> ${e.statusCode}`), e.delayMs !== void 0 && o.push(`+${e.delayMs}ms`), e.direction && o.push(e.direction), e.eventType && o.push(`event=${e.eventType}`), e.selector && o.push(`selector=${e.selector}`), e.action && o.push(`action=${e.action}`), e.strategy && o.push(`strategy=${e.strategy}`), e.groupName && o.push(`group=${e.groupName}`), e.reason && o.push(`reason=${e.reason}`), o.length === 0 ? n : `${n}: ${o.join(" ")}`;
|
|
878
|
+
}
|
|
879
|
+
class We {
|
|
880
|
+
constructor(e, o = "page") {
|
|
881
|
+
this.opts = e, this.target = o;
|
|
882
|
+
}
|
|
883
|
+
isEnabled() {
|
|
884
|
+
return this.opts.enabled;
|
|
885
|
+
}
|
|
886
|
+
/**
|
|
887
|
+
* Build a `type: 'debug'` event with `detail.stage = stage`, mirror a
|
|
888
|
+
* `[Chaos] ...` (page) or `[Chaos SW] ...` (Service Worker) line to
|
|
889
|
+
* `console.debug`, and return the event for the emitter to fan out. The
|
|
890
|
+
* formatted string is never stored on the event payload.
|
|
891
|
+
*
|
|
892
|
+
* Returns `null` when the logger was constructed with `enabled: false`.
|
|
893
|
+
* Internal callers (the emitter fast-path) never reach this branch because
|
|
894
|
+
* `ChaosMaker` does not attach a logger when debug is off, but the guard
|
|
895
|
+
* keeps the public `Logger` API consistent with the `DebugOptions.enabled`
|
|
896
|
+
* contract for external consumers who instantiate it directly.
|
|
897
|
+
*/
|
|
898
|
+
log(e, o) {
|
|
899
|
+
if (!this.opts.enabled) return null;
|
|
900
|
+
const t = { ...o, stage: e }, s = {
|
|
901
|
+
type: "debug",
|
|
902
|
+
timestamp: Date.now(),
|
|
903
|
+
applied: !1,
|
|
904
|
+
detail: t
|
|
905
|
+
};
|
|
906
|
+
if (typeof console < "u" && typeof console.debug == "function") {
|
|
907
|
+
const i = this.target === "sw" ? "[Chaos SW]" : "[Chaos]";
|
|
908
|
+
try {
|
|
909
|
+
console.debug(`${i} ${Ue(e, t)}`);
|
|
910
|
+
} catch {
|
|
911
|
+
}
|
|
912
|
+
}
|
|
913
|
+
return s;
|
|
914
|
+
}
|
|
915
|
+
}
|
|
916
|
+
const de = /* @__PURE__ */ Symbol.for("chaos-maker.runtime.patch-kind"), H = /* @__PURE__ */ Symbol.for("chaos-maker.runtime.active-instance");
|
|
917
|
+
function Be(n) {
|
|
918
|
+
return typeof n == "object" && n !== null || typeof n == "function";
|
|
919
|
+
}
|
|
920
|
+
function re(n, e) {
|
|
921
|
+
try {
|
|
922
|
+
Object.defineProperty(n, de, {
|
|
923
|
+
value: e,
|
|
924
|
+
configurable: !0
|
|
925
|
+
});
|
|
926
|
+
} catch {
|
|
927
|
+
}
|
|
928
|
+
return n;
|
|
929
|
+
}
|
|
930
|
+
function se(n) {
|
|
931
|
+
if (Be(n))
|
|
932
|
+
return n[de];
|
|
933
|
+
}
|
|
934
|
+
function He(n) {
|
|
935
|
+
return n[H];
|
|
936
|
+
}
|
|
937
|
+
function je(n, e) {
|
|
938
|
+
try {
|
|
939
|
+
Object.defineProperty(n, H, {
|
|
940
|
+
value: e,
|
|
941
|
+
configurable: !0
|
|
942
|
+
});
|
|
943
|
+
} catch {
|
|
944
|
+
}
|
|
945
|
+
}
|
|
946
|
+
function Qe(n, e) {
|
|
947
|
+
const o = n;
|
|
948
|
+
if (o[H] === e)
|
|
949
|
+
try {
|
|
950
|
+
delete o[H];
|
|
951
|
+
} catch {
|
|
952
|
+
try {
|
|
953
|
+
o[H] = void 0;
|
|
954
|
+
} catch {
|
|
955
|
+
}
|
|
956
|
+
}
|
|
957
|
+
}
|
|
958
|
+
const Y = /* @__PURE__ */ Symbol.for("chaos-maker.sw.installed");
|
|
959
|
+
function ze() {
|
|
594
960
|
return typeof self < "u" ? self : typeof globalThis < "u" ? globalThis : null;
|
|
595
961
|
}
|
|
596
|
-
function
|
|
597
|
-
const
|
|
598
|
-
!
|
|
599
|
-
for (const
|
|
962
|
+
function fe(n, e) {
|
|
963
|
+
const o = n.clients;
|
|
964
|
+
!o || typeof o.matchAll != "function" || o.matchAll({ includeUncontrolled: !0 }).then((t) => {
|
|
965
|
+
for (const s of t)
|
|
600
966
|
try {
|
|
601
|
-
|
|
967
|
+
s.postMessage(e);
|
|
602
968
|
} catch {
|
|
603
969
|
}
|
|
604
970
|
}).catch(() => {
|
|
605
971
|
});
|
|
606
972
|
}
|
|
607
|
-
function
|
|
608
|
-
|
|
609
|
-
const
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
973
|
+
function ae(n, e) {
|
|
974
|
+
n.running && V(n);
|
|
975
|
+
const o = ue(e.seed);
|
|
976
|
+
n.seed = o.seed, n.random = o.random, n.requestCounters = /* @__PURE__ */ new Map(), n.groups = new le();
|
|
977
|
+
for (const i of e.groups ?? [])
|
|
978
|
+
n.groups.ensure(i.name, { enabled: i.enabled ?? !0, explicit: !0 });
|
|
979
|
+
we(e, (i) => {
|
|
980
|
+
i.group && n.groups.ensure(i.group);
|
|
981
|
+
}), n.groups.ensure(J, { enabled: !0 });
|
|
982
|
+
const t = De(e.debug);
|
|
983
|
+
t.enabled ? (n.emitter.setRuleIds(Fe(e)), n.emitter.setLogger(new We(t, "sw"))) : (n.emitter.setRuleIds(void 0), n.emitter.setLogger(void 0));
|
|
984
|
+
const s = He(n.target);
|
|
985
|
+
if (s && s !== n && n.emitter.debug("lifecycle", {
|
|
986
|
+
phase: "sw:config-applied",
|
|
987
|
+
reason: "active-instance-conflict"
|
|
988
|
+
}), se(n.target.fetch) === "fetch" && n.emitter.debug("lifecycle", {
|
|
989
|
+
phase: "sw:config-applied",
|
|
990
|
+
reason: "target-fetch-already-patched"
|
|
991
|
+
}), typeof n.target.WebSocket < "u" && se(n.target.WebSocket) === "websocket" && n.emitter.debug("lifecycle", {
|
|
992
|
+
phase: "sw:config-applied",
|
|
993
|
+
reason: "target-websocket-already-patched"
|
|
994
|
+
}), n.emitter.debug("lifecycle", { phase: "sw:config-applied" }), e.network) {
|
|
995
|
+
const i = n.target;
|
|
996
|
+
typeof i.fetch == "function" && (n.originalFetch = i.fetch, i.fetch = re(
|
|
997
|
+
Ie(
|
|
998
|
+
n.originalFetch.bind(i),
|
|
999
|
+
e.network,
|
|
1000
|
+
n.random,
|
|
1001
|
+
n.emitter,
|
|
1002
|
+
n.requestCounters,
|
|
1003
|
+
n.groups
|
|
1004
|
+
),
|
|
1005
|
+
"fetch"
|
|
618
1006
|
));
|
|
619
1007
|
}
|
|
620
|
-
return
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
}
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
1008
|
+
return e.websocket && typeof n.target.WebSocket < "u" && (n.originalWebSocket = n.target.WebSocket, n.webSocketHandle = qe(
|
|
1009
|
+
n.originalWebSocket,
|
|
1010
|
+
e.websocket,
|
|
1011
|
+
n.emitter,
|
|
1012
|
+
n.random,
|
|
1013
|
+
n.requestCounters,
|
|
1014
|
+
n.groups
|
|
1015
|
+
), n.target.WebSocket = re(n.webSocketHandle.Wrapped, "websocket")), n.running = !0, je(n.target, n), n.seed;
|
|
1016
|
+
}
|
|
1017
|
+
function V(n) {
|
|
1018
|
+
!n.running && !n.originalFetch && !n.originalWebSocket || (n.originalFetch && (n.target.fetch = n.originalFetch, n.originalFetch = void 0), n.originalWebSocket && (n.target.WebSocket = n.originalWebSocket, n.originalWebSocket = void 0), n.webSocketHandle && (n.webSocketHandle.uninstall(), n.webSocketHandle = void 0), n.emitter.debug("lifecycle", { phase: "sw:config-stopped" }), n.emitter.setLogger(void 0), n.emitter.setRuleIds(void 0), n.seed = null, n.requestCounters.clear(), Qe(n.target, n), n.running = !1);
|
|
1019
|
+
}
|
|
1020
|
+
function F(n, e, o) {
|
|
1021
|
+
var s;
|
|
1022
|
+
const t = (s = e.ports) == null ? void 0 : s[0];
|
|
1023
|
+
if (t && typeof t.postMessage == "function")
|
|
635
1024
|
try {
|
|
636
|
-
|
|
1025
|
+
t.postMessage(o);
|
|
637
1026
|
return;
|
|
638
1027
|
} catch {
|
|
639
1028
|
}
|
|
640
|
-
|
|
1029
|
+
fe(n, o);
|
|
641
1030
|
}
|
|
642
|
-
function
|
|
643
|
-
const
|
|
1031
|
+
function Je(n = {}) {
|
|
1032
|
+
const e = ze(), o = {
|
|
644
1033
|
isRunning: () => !1,
|
|
645
1034
|
getSeed: () => null,
|
|
646
1035
|
getLog: () => [],
|
|
@@ -649,72 +1038,93 @@ function xe(e = {}) {
|
|
|
649
1038
|
uninstall: () => {
|
|
650
1039
|
}
|
|
651
1040
|
};
|
|
652
|
-
if (!
|
|
653
|
-
return
|
|
654
|
-
const
|
|
655
|
-
if (
|
|
656
|
-
const
|
|
657
|
-
target:
|
|
658
|
-
emitter:
|
|
1041
|
+
if (!e || typeof e.fetch != "function" || typeof e.addEventListener != "function")
|
|
1042
|
+
return o;
|
|
1043
|
+
const t = e[Y];
|
|
1044
|
+
if (t) return t;
|
|
1045
|
+
const s = new he(n.maxLogEntries ?? 2e3), i = ue(0), l = {
|
|
1046
|
+
target: e,
|
|
1047
|
+
emitter: s,
|
|
659
1048
|
running: !1,
|
|
660
1049
|
seed: null,
|
|
661
|
-
random:
|
|
662
|
-
requestCounters: /* @__PURE__ */ new Map()
|
|
1050
|
+
random: i.random,
|
|
1051
|
+
requestCounters: /* @__PURE__ */ new Map(),
|
|
1052
|
+
groups: new le()
|
|
663
1053
|
};
|
|
664
|
-
|
|
665
|
-
|
|
1054
|
+
s.on("*", (a) => {
|
|
1055
|
+
fe(e, { __chaosMakerSWEvent: !0, event: a });
|
|
666
1056
|
});
|
|
667
|
-
const
|
|
668
|
-
const
|
|
669
|
-
if (!
|
|
670
|
-
const M =
|
|
1057
|
+
const p = (a) => {
|
|
1058
|
+
const S = a, A = S.data;
|
|
1059
|
+
if (!A || typeof A != "object") return;
|
|
1060
|
+
const M = A;
|
|
671
1061
|
if (M.__chaosMakerConfig) {
|
|
672
|
-
const
|
|
673
|
-
|
|
1062
|
+
const L = ae(l, M.__chaosMakerConfig);
|
|
1063
|
+
F(e, S, {
|
|
674
1064
|
__chaosMakerAck: !0,
|
|
675
|
-
seed:
|
|
676
|
-
running:
|
|
1065
|
+
seed: L,
|
|
1066
|
+
running: l.running
|
|
677
1067
|
});
|
|
678
1068
|
return;
|
|
679
1069
|
}
|
|
680
1070
|
if (M.__chaosMakerStop) {
|
|
681
|
-
|
|
1071
|
+
V(l), F(e, S, {
|
|
682
1072
|
__chaosMakerAck: !0,
|
|
683
1073
|
running: !1
|
|
684
1074
|
});
|
|
685
1075
|
return;
|
|
686
1076
|
}
|
|
1077
|
+
if (M.__chaosMakerToggleGroup) {
|
|
1078
|
+
const { name: L, enabled: N } = M.__chaosMakerToggleGroup, T = L.trim();
|
|
1079
|
+
if (!T) {
|
|
1080
|
+
F(e, S, {
|
|
1081
|
+
__chaosMakerAck: !0,
|
|
1082
|
+
running: l.running
|
|
1083
|
+
});
|
|
1084
|
+
return;
|
|
1085
|
+
}
|
|
1086
|
+
l.groups.setEnabled(T, N), l.emitter.emit({
|
|
1087
|
+
type: N ? "rule-group:enabled" : "rule-group:disabled",
|
|
1088
|
+
timestamp: Date.now(),
|
|
1089
|
+
applied: !0,
|
|
1090
|
+
detail: { groupName: T }
|
|
1091
|
+
}), l.emitter.debug("lifecycle", { phase: "sw:group-toggled", groupName: T, enabled: N }), F(e, S, {
|
|
1092
|
+
__chaosMakerAck: !0,
|
|
1093
|
+
running: l.running
|
|
1094
|
+
});
|
|
1095
|
+
return;
|
|
1096
|
+
}
|
|
687
1097
|
if (M.__chaosMakerGetLog) {
|
|
688
|
-
|
|
1098
|
+
F(e, S, {
|
|
689
1099
|
__chaosMakerLog: !0,
|
|
690
|
-
log:
|
|
1100
|
+
log: s.getLog()
|
|
691
1101
|
});
|
|
692
1102
|
return;
|
|
693
1103
|
}
|
|
694
1104
|
if (M.__chaosMakerClearLog) {
|
|
695
|
-
|
|
1105
|
+
s.clearLog(), F(e, S, {
|
|
696
1106
|
__chaosMakerAck: !0,
|
|
697
|
-
running:
|
|
1107
|
+
running: l.running
|
|
698
1108
|
});
|
|
699
1109
|
return;
|
|
700
1110
|
}
|
|
701
1111
|
};
|
|
702
|
-
if (
|
|
703
|
-
const
|
|
704
|
-
|
|
705
|
-
}
|
|
706
|
-
const
|
|
707
|
-
isRunning: () =>
|
|
708
|
-
getSeed: () =>
|
|
709
|
-
getLog: () =>
|
|
710
|
-
clearLog: () =>
|
|
1112
|
+
if (e.addEventListener("message", p), (n.source ?? "message") === "self-global") {
|
|
1113
|
+
const a = e.__CHAOS_CONFIG__;
|
|
1114
|
+
a && typeof a == "object" && ae(l, a);
|
|
1115
|
+
}
|
|
1116
|
+
const u = {
|
|
1117
|
+
isRunning: () => l.running,
|
|
1118
|
+
getSeed: () => l.seed,
|
|
1119
|
+
getLog: () => s.getLog(),
|
|
1120
|
+
clearLog: () => s.clearLog(),
|
|
711
1121
|
uninstall: () => {
|
|
712
|
-
|
|
1122
|
+
e.removeEventListener("message", p), V(l), delete e[Y];
|
|
713
1123
|
}
|
|
714
1124
|
};
|
|
715
|
-
return
|
|
1125
|
+
return e[Y] = u, u;
|
|
716
1126
|
}
|
|
717
|
-
typeof self < "u" && typeof importScripts == "function" &&
|
|
1127
|
+
typeof self < "u" && typeof importScripts == "function" && Je({ source: "message" });
|
|
718
1128
|
export {
|
|
719
|
-
|
|
1129
|
+
Je as installChaosSW
|
|
720
1130
|
};
|