@buoy-gg/network 7.0.12 → 7.0.14

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.
Files changed (136) hide show
  1. package/lib/commonjs/index.js +52 -0
  2. package/lib/commonjs/network/components/NetworkDetailStepper.js +26 -14
  3. package/lib/commonjs/network/components/NetworkEventDetailView.js +86 -14
  4. package/lib/commonjs/network/components/NetworkEventItemCompact.js +4 -0
  5. package/lib/commonjs/network/components/NetworkHeaderLive.js +32 -7
  6. package/lib/commonjs/network/components/NetworkHeaderMenu.js +183 -0
  7. package/lib/commonjs/network/components/NetworkListScreen.js +134 -8
  8. package/lib/commonjs/network/components/NetworkModal.js +198 -51
  9. package/lib/commonjs/network/components/NetworkNumberPrompt.js +178 -0
  10. package/lib/commonjs/network/components/NetworkOverrideEditor.js +797 -0
  11. package/lib/commonjs/network/components/NetworkOverrideHeaderButton.js +102 -0
  12. package/lib/commonjs/network/components/NetworkOverridesButton.js +88 -0
  13. package/lib/commonjs/network/components/NetworkOverridesScreen.js +489 -0
  14. package/lib/commonjs/network/components/response-editor/Explorer.js +973 -0
  15. package/lib/commonjs/network/components/response-editor/deleteNestedDataByPath.js +56 -0
  16. package/lib/commonjs/network/components/response-editor/editorContext.js +33 -0
  17. package/lib/commonjs/network/components/response-editor/updateNestedDataByPath.js +61 -0
  18. package/lib/commonjs/network/hooks/useNetworkSelection.js +53 -0
  19. package/lib/commonjs/network/hooks/useOverrideRules.js +36 -0
  20. package/lib/commonjs/network/overrides/applyToFetch.js +80 -0
  21. package/lib/commonjs/network/overrides/applyToXhr.js +190 -0
  22. package/lib/commonjs/network/overrides/engine.js +70 -0
  23. package/lib/commonjs/network/overrides/matchRule.js +81 -0
  24. package/lib/commonjs/network/overrides/overrideRulesStore.js +550 -0
  25. package/lib/commonjs/network/overrides/presets.js +70 -0
  26. package/lib/commonjs/network/overrides/resolveOverride.js +158 -0
  27. package/lib/commonjs/network/overrides/types.js +85 -0
  28. package/lib/commonjs/network/sync/networkSyncAdapter.js +230 -1
  29. package/lib/commonjs/network/types/index.js +5 -1
  30. package/lib/commonjs/network/utils/networkEventStore.js +52 -6
  31. package/lib/commonjs/network/utils/networkListener.js +90 -10
  32. package/lib/commonjs/network/utils/networkSelectionStore.js +193 -0
  33. package/lib/commonjs/preset.js +11 -0
  34. package/lib/module/index.js +19 -0
  35. package/lib/module/network/components/NetworkDetailStepper.js +27 -15
  36. package/lib/module/network/components/NetworkEventDetailView.js +87 -15
  37. package/lib/module/network/components/NetworkEventItemCompact.js +5 -1
  38. package/lib/module/network/components/NetworkHeaderLive.js +32 -7
  39. package/lib/module/network/components/NetworkHeaderMenu.js +177 -0
  40. package/lib/module/network/components/NetworkListScreen.js +135 -9
  41. package/lib/module/network/components/NetworkModal.js +200 -53
  42. package/lib/module/network/components/NetworkNumberPrompt.js +174 -0
  43. package/lib/module/network/components/NetworkOverrideEditor.js +794 -0
  44. package/lib/module/network/components/NetworkOverrideHeaderButton.js +99 -0
  45. package/lib/module/network/components/NetworkOverridesButton.js +85 -0
  46. package/lib/module/network/components/NetworkOverridesScreen.js +485 -0
  47. package/lib/module/network/components/response-editor/Explorer.js +972 -0
  48. package/lib/module/network/components/response-editor/deleteNestedDataByPath.js +51 -0
  49. package/lib/module/network/components/response-editor/editorContext.js +29 -0
  50. package/lib/module/network/components/response-editor/updateNestedDataByPath.js +56 -0
  51. package/lib/module/network/hooks/useNetworkSelection.js +46 -0
  52. package/lib/module/network/hooks/useOverrideRules.js +32 -0
  53. package/lib/module/network/overrides/applyToFetch.js +72 -0
  54. package/lib/module/network/overrides/applyToXhr.js +185 -0
  55. package/lib/module/network/overrides/engine.js +64 -0
  56. package/lib/module/network/overrides/matchRule.js +75 -0
  57. package/lib/module/network/overrides/overrideRulesStore.js +547 -0
  58. package/lib/module/network/overrides/presets.js +65 -0
  59. package/lib/module/network/overrides/resolveOverride.js +152 -0
  60. package/lib/module/network/overrides/types.js +80 -0
  61. package/lib/module/network/sync/networkSyncAdapter.js +230 -1
  62. package/lib/module/network/types/index.js +3 -1
  63. package/lib/module/network/utils/networkEventStore.js +52 -6
  64. package/lib/module/network/utils/networkListener.js +91 -10
  65. package/lib/module/network/utils/networkSelectionStore.js +188 -0
  66. package/lib/module/preset.js +13 -1
  67. package/lib/typescript/index.d.ts +9 -0
  68. package/lib/typescript/index.d.ts.map +1 -1
  69. package/lib/typescript/network/components/NetworkDetailStepper.d.ts +8 -5
  70. package/lib/typescript/network/components/NetworkDetailStepper.d.ts.map +1 -1
  71. package/lib/typescript/network/components/NetworkEventDetailView.d.ts +36 -1
  72. package/lib/typescript/network/components/NetworkEventDetailView.d.ts.map +1 -1
  73. package/lib/typescript/network/components/NetworkEventItemCompact.d.ts +6 -0
  74. package/lib/typescript/network/components/NetworkEventItemCompact.d.ts.map +1 -1
  75. package/lib/typescript/network/components/NetworkHeaderLive.d.ts +13 -3
  76. package/lib/typescript/network/components/NetworkHeaderLive.d.ts.map +1 -1
  77. package/lib/typescript/network/components/NetworkHeaderMenu.d.ts +46 -0
  78. package/lib/typescript/network/components/NetworkHeaderMenu.d.ts.map +1 -0
  79. package/lib/typescript/network/components/NetworkListScreen.d.ts.map +1 -1
  80. package/lib/typescript/network/components/NetworkModal.d.ts.map +1 -1
  81. package/lib/typescript/network/components/NetworkNumberPrompt.d.ts +33 -0
  82. package/lib/typescript/network/components/NetworkNumberPrompt.d.ts.map +1 -0
  83. package/lib/typescript/network/components/NetworkOverrideEditor.d.ts +17 -0
  84. package/lib/typescript/network/components/NetworkOverrideEditor.d.ts.map +1 -0
  85. package/lib/typescript/network/components/NetworkOverrideHeaderButton.d.ts +27 -0
  86. package/lib/typescript/network/components/NetworkOverrideHeaderButton.d.ts.map +1 -0
  87. package/lib/typescript/network/components/NetworkOverridesButton.d.ts +17 -0
  88. package/lib/typescript/network/components/NetworkOverridesButton.d.ts.map +1 -0
  89. package/lib/typescript/network/components/NetworkOverridesScreen.d.ts +29 -0
  90. package/lib/typescript/network/components/NetworkOverridesScreen.d.ts.map +1 -0
  91. package/lib/typescript/network/components/response-editor/Explorer.d.ts +17 -0
  92. package/lib/typescript/network/components/response-editor/Explorer.d.ts.map +1 -0
  93. package/lib/typescript/network/components/response-editor/deleteNestedDataByPath.d.ts +9 -0
  94. package/lib/typescript/network/components/response-editor/deleteNestedDataByPath.d.ts.map +1 -0
  95. package/lib/typescript/network/components/response-editor/editorContext.d.ts +29 -0
  96. package/lib/typescript/network/components/response-editor/editorContext.d.ts.map +1 -0
  97. package/lib/typescript/network/components/response-editor/updateNestedDataByPath.d.ts +10 -0
  98. package/lib/typescript/network/components/response-editor/updateNestedDataByPath.d.ts.map +1 -0
  99. package/lib/typescript/network/hooks/useNetworkSelection.d.ts +26 -0
  100. package/lib/typescript/network/hooks/useNetworkSelection.d.ts.map +1 -0
  101. package/lib/typescript/network/hooks/useOverrideRules.d.ts +29 -0
  102. package/lib/typescript/network/hooks/useOverrideRules.d.ts.map +1 -0
  103. package/lib/typescript/network/overrides/__tests__/applyToFetch.test.d.ts +16 -0
  104. package/lib/typescript/network/overrides/__tests__/applyToFetch.test.d.ts.map +1 -0
  105. package/lib/typescript/network/overrides/__tests__/applyToXhr.test.d.ts +19 -0
  106. package/lib/typescript/network/overrides/__tests__/applyToXhr.test.d.ts.map +1 -0
  107. package/lib/typescript/network/overrides/__tests__/resolveOverride.test.d.ts +22 -0
  108. package/lib/typescript/network/overrides/__tests__/resolveOverride.test.d.ts.map +1 -0
  109. package/lib/typescript/network/overrides/applyToFetch.d.ts +50 -0
  110. package/lib/typescript/network/overrides/applyToFetch.d.ts.map +1 -0
  111. package/lib/typescript/network/overrides/applyToXhr.d.ts +43 -0
  112. package/lib/typescript/network/overrides/applyToXhr.d.ts.map +1 -0
  113. package/lib/typescript/network/overrides/engine.d.ts +47 -0
  114. package/lib/typescript/network/overrides/engine.d.ts.map +1 -0
  115. package/lib/typescript/network/overrides/matchRule.d.ts +22 -0
  116. package/lib/typescript/network/overrides/matchRule.d.ts.map +1 -0
  117. package/lib/typescript/network/overrides/overrideRulesStore.d.ts +205 -0
  118. package/lib/typescript/network/overrides/overrideRulesStore.d.ts.map +1 -0
  119. package/lib/typescript/network/overrides/presets.d.ts +38 -0
  120. package/lib/typescript/network/overrides/presets.d.ts.map +1 -0
  121. package/lib/typescript/network/overrides/resolveOverride.d.ts +46 -0
  122. package/lib/typescript/network/overrides/resolveOverride.d.ts.map +1 -0
  123. package/lib/typescript/network/overrides/types.d.ts +169 -0
  124. package/lib/typescript/network/overrides/types.d.ts.map +1 -0
  125. package/lib/typescript/network/sync/networkSyncAdapter.d.ts +73 -0
  126. package/lib/typescript/network/sync/networkSyncAdapter.d.ts.map +1 -1
  127. package/lib/typescript/network/types/index.d.ts +10 -0
  128. package/lib/typescript/network/types/index.d.ts.map +1 -1
  129. package/lib/typescript/network/utils/networkEventStore.d.ts +14 -0
  130. package/lib/typescript/network/utils/networkEventStore.d.ts.map +1 -1
  131. package/lib/typescript/network/utils/networkListener.d.ts +3 -0
  132. package/lib/typescript/network/utils/networkListener.d.ts.map +1 -1
  133. package/lib/typescript/network/utils/networkSelectionStore.d.ts +117 -0
  134. package/lib/typescript/network/utils/networkSelectionStore.d.ts.map +1 -0
  135. package/lib/typescript/preset.d.ts.map +1 -1
  136. package/package.json +2 -2
@@ -0,0 +1,794 @@
1
+ "use strict";
2
+
3
+ import { useMemo, useState } from "react";
4
+ import { ScrollView, StyleSheet, Text, TextInput, TouchableOpacity, View } from "react-native";
5
+ import { ChevronDown, ChevronRight, macOSColors, useSafeAreaInsets } from "@buoy-gg/shared-ui";
6
+ import Explorer from "./response-editor/Explorer";
7
+ import { ResponseEditorContext } from "./response-editor/editorContext";
8
+ import { NetworkNumberPrompt } from "./NetworkNumberPrompt";
9
+ import { STATUS_MAX, STATUS_MIN } from "../overrides/types";
10
+
11
+ /**
12
+ * The rule form — one decision, everything else out of the way.
13
+ *
14
+ * It used to ask for six things at equal weight (URL, method, kind, status,
15
+ * body, lifetime) with three paragraphs of hint text explaining them. That's a
16
+ * form, not a tool, and the hints were the tell: a control that needs a
17
+ * paragraph is the wrong control.
18
+ *
19
+ * Two things fixed it.
20
+ *
21
+ * FIRST, `kind` is gone from the UI. `respond | fail | delay` is our data
22
+ * model, not the developer's — nobody thinks "kind=respond, status=500", they
23
+ * think "make it a 500" or "make it go offline". Folding kind + status +
24
+ * failKind into a single OUTCOME list removes a section, a paragraph, and an
25
+ * entire concept, and every option now says what it does without being
26
+ * explained.
27
+ *
28
+ * SECOND, everything that arrives already correct is collapsed. A rule made
29
+ * from a real request knows its URL and method, so those become one summary
30
+ * line you can open if you need it. The body is prefilled and usually edited in
31
+ * the response tree instead, so it collapses too. What's left on arrival is the
32
+ * question actually being asked.
33
+ */
34
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
35
+ const METHODS = ["GET", "POST", "PUT", "PATCH", "DELETE"];
36
+ const DELAY_PRESETS = [0, 500, 1000, 3000, 10000];
37
+
38
+ /**
39
+ * The single decision, ordered by how often a developer reaches for it.
40
+ *
41
+ * Each carries a plain-language name AND its status code: scanning for "the
42
+ * auth one" shouldn't require knowing that 401 is unauthorized, and someone who
43
+ * does know should be able to find 401 without reading labels.
44
+ */
45
+
46
+ const OUTCOMES = [{
47
+ id: "500",
48
+ label: "Server error",
49
+ code: "500",
50
+ danger: true,
51
+ patch: {
52
+ kind: "respond",
53
+ status: 500,
54
+ statusText: "Internal Server Error"
55
+ }
56
+ }, {
57
+ id: "401",
58
+ label: "Unauthorized",
59
+ code: "401",
60
+ danger: true,
61
+ patch: {
62
+ kind: "respond",
63
+ status: 401,
64
+ statusText: "Unauthorized"
65
+ }
66
+ }, {
67
+ id: "404",
68
+ label: "Not found",
69
+ code: "404",
70
+ danger: true,
71
+ patch: {
72
+ kind: "respond",
73
+ status: 404,
74
+ statusText: "Not Found"
75
+ }
76
+ }, {
77
+ id: "403",
78
+ label: "Forbidden",
79
+ code: "403",
80
+ danger: true,
81
+ patch: {
82
+ kind: "respond",
83
+ status: 403,
84
+ statusText: "Forbidden"
85
+ }
86
+ }, {
87
+ id: "429",
88
+ label: "Rate limited",
89
+ code: "429",
90
+ danger: true,
91
+ patch: {
92
+ kind: "respond",
93
+ status: 429,
94
+ statusText: "Too Many Requests"
95
+ }
96
+ }, {
97
+ id: "503",
98
+ label: "Unavailable",
99
+ code: "503",
100
+ danger: true,
101
+ patch: {
102
+ kind: "respond",
103
+ status: 503,
104
+ statusText: "Service Unavailable"
105
+ }
106
+ }, {
107
+ id: "400",
108
+ label: "Bad request",
109
+ code: "400",
110
+ danger: true,
111
+ patch: {
112
+ kind: "respond",
113
+ status: 400,
114
+ statusText: "Bad Request"
115
+ }
116
+ }, {
117
+ id: "200",
118
+ label: "Success",
119
+ code: "200",
120
+ patch: {
121
+ kind: "respond",
122
+ status: 200,
123
+ statusText: "OK"
124
+ }
125
+ }, {
126
+ id: "offline",
127
+ label: "Offline",
128
+ danger: true,
129
+ patch: {
130
+ kind: "fail",
131
+ failKind: "network"
132
+ }
133
+ }, {
134
+ id: "timeout",
135
+ label: "Timeout",
136
+ danger: true,
137
+ patch: {
138
+ kind: "fail",
139
+ failKind: "timeout"
140
+ }
141
+ }, {
142
+ id: "passthrough",
143
+ label: "Real response",
144
+ patch: {
145
+ kind: "delay"
146
+ }
147
+ }];
148
+ function outcomeIdFor(draft) {
149
+ if (draft.kind === "delay") return "passthrough";
150
+ if (draft.kind === "fail") {
151
+ return draft.failKind === "timeout" ? "timeout" : "offline";
152
+ }
153
+ return String(draft.status ?? 200);
154
+ }
155
+ function OutcomeChip({
156
+ outcome,
157
+ active,
158
+ onPress
159
+ }) {
160
+ const accent = outcome.danger ? macOSColors.semantic.error : macOSColors.semantic.info;
161
+ return /*#__PURE__*/_jsxs(TouchableOpacity, {
162
+ onPress: onPress,
163
+ "sentry-label": "ignore override outcome",
164
+ accessibilityLabel: `${outcome.label}${outcome.code ? ` ${outcome.code}` : ""}`,
165
+ style: [styles.outcome, active && {
166
+ borderColor: accent,
167
+ backgroundColor: `${accent}1F`
168
+ }],
169
+ children: [/*#__PURE__*/_jsx(Text, {
170
+ style: [styles.outcomeLabel, active && {
171
+ color: accent
172
+ }],
173
+ children: outcome.label
174
+ }), outcome.code ? /*#__PURE__*/_jsx(Text, {
175
+ style: [styles.outcomeCode, active && {
176
+ color: accent
177
+ }],
178
+ children: outcome.code
179
+ }) : null]
180
+ });
181
+ }
182
+
183
+ /** A collapsed row that opens to reveal its controls. */
184
+ function Disclosure({
185
+ title,
186
+ summary,
187
+ open,
188
+ onToggle,
189
+ children
190
+ }) {
191
+ return /*#__PURE__*/_jsxs(View, {
192
+ style: styles.disclosure,
193
+ children: [/*#__PURE__*/_jsxs(TouchableOpacity, {
194
+ onPress: onToggle,
195
+ "sentry-label": "ignore override disclosure",
196
+ style: styles.disclosureHeader,
197
+ children: [open ? /*#__PURE__*/_jsx(ChevronDown, {
198
+ size: 12,
199
+ color: macOSColors.text.muted
200
+ }) : /*#__PURE__*/_jsx(ChevronRight, {
201
+ size: 12,
202
+ color: macOSColors.text.muted
203
+ }), /*#__PURE__*/_jsx(Text, {
204
+ style: styles.disclosureTitle,
205
+ children: title
206
+ }), summary && !open ? /*#__PURE__*/_jsx(Text, {
207
+ style: styles.disclosureSummary,
208
+ numberOfLines: 1,
209
+ children: summary
210
+ }) : null]
211
+ }), open ? /*#__PURE__*/_jsx(View, {
212
+ style: styles.disclosureBody,
213
+ children: children
214
+ }) : null]
215
+ });
216
+ }
217
+ function Chip({
218
+ label,
219
+ active,
220
+ onPress
221
+ }) {
222
+ return /*#__PURE__*/_jsx(TouchableOpacity, {
223
+ onPress: onPress,
224
+ "sentry-label": "ignore override chip",
225
+ style: [styles.chip, active && styles.chipActive],
226
+ children: /*#__PURE__*/_jsx(Text, {
227
+ style: [styles.chipText, active && styles.chipTextActive],
228
+ children: label
229
+ })
230
+ });
231
+ }
232
+ export function NetworkOverrideEditor({
233
+ draft,
234
+ onChange,
235
+ onSave,
236
+ onCancel,
237
+ saveLabel = "Save",
238
+ applySafeAreaInset = false
239
+ }) {
240
+ // `minBottom` is a floor, not a preference: the dimension map can't know
241
+ // about a device that ships next year, and an unmapped one falls through to
242
+ // `bottom: 0`. This guarantees the buttons clear the indicator either way.
243
+ const insets = useSafeAreaInsets({
244
+ minBottom: 16
245
+ });
246
+ const bottomInset = applySafeAreaInset ? insets.bottom : 0;
247
+ const patch = next => onChange({
248
+ ...draft,
249
+ ...next
250
+ });
251
+
252
+ // A rule made from a request arrives with its scope already right, so it
253
+ // starts closed. A blank one has nothing to match on yet, so it starts open.
254
+ const [scopeOpen, setScopeOpen] = useState(!draft.urlPattern.trim());
255
+ const [bodyOpen, setBodyOpen] = useState(false);
256
+ /**
257
+ * The "Edit all" buffer — deliberately NOT seeded with the current body.
258
+ *
259
+ * Prefilling it would be the obvious thing and it's wrong twice over: a real
260
+ * response is routinely hundreds of KB, which a multiline TextInput handles
261
+ * badly, and you only reach for this when you intend to REPLACE the whole
262
+ * thing anyway. Starting empty means paste-and-go instead of select-all-
263
+ * delete-paste on a field that's fighting you.
264
+ */
265
+ const [pasteText, setPasteText] = useState(null);
266
+ /** Which custom number the top-of-screen prompt is asking for, if any. */
267
+ const [prompt, setPrompt] = useState(null);
268
+ const activeOutcome = outcomeIdFor(draft);
269
+ /** True when the status is a real one that no listed outcome covers. */
270
+ const customStatusActive = draft.kind === "respond" && typeof draft.status === "number" && !OUTCOMES.some(outcome => outcome.code === String(draft.status));
271
+ const showsBody = draft.kind === "respond";
272
+ const method = draft.methods?.[0];
273
+ const scopeSummary = `${method ?? "Any"} ${draft.urlPattern || "No URL yet"}`;
274
+ const bodySummary = useMemo(() => {
275
+ const body = (draft.body ?? "").trim();
276
+ if (!body) return "Empty";
277
+ const lines = body.split("\n").length;
278
+ return `${lines} line${lines === 1 ? "" : "s"}`;
279
+ }, [draft.body]);
280
+
281
+ /**
282
+ * The body as a tree, or null when it can't be one (empty, or not JSON).
283
+ *
284
+ * Memoized on the raw string because an override body can be large and this
285
+ * would otherwise re-parse on every keystroke elsewhere in the form.
286
+ */
287
+ const parsedBody = useMemo(() => {
288
+ const body = (draft.body ?? "").trim();
289
+ if (!body) return null;
290
+ try {
291
+ return JSON.parse(body);
292
+ } catch {
293
+ return null;
294
+ }
295
+ }, [draft.body]);
296
+ const bodyIsNonJsonText = (draft.body ?? "").trim().length > 0 && !parsedBody;
297
+ const delayMs = draft.delayMs ?? 0;
298
+ /** Custom fields own the value only when no preset chip already claims it. */
299
+ const customDelayActive = delayMs > 0 && !DELAY_PRESETS.includes(delayMs);
300
+ const customTimesActive = !draft.alternate && typeof draft.times === "number" && draft.times !== 1;
301
+ return /*#__PURE__*/_jsxs(View, {
302
+ style: styles.root,
303
+ children: [/*#__PURE__*/_jsxs(ScrollView, {
304
+ style: styles.scroll,
305
+ contentContainerStyle: styles.scrollContent,
306
+ keyboardShouldPersistTaps: "handled",
307
+ children: [/*#__PURE__*/_jsxs(Disclosure, {
308
+ title: "Applies to",
309
+ summary: scopeSummary,
310
+ open: scopeOpen,
311
+ onToggle: () => setScopeOpen(v => !v),
312
+ children: [/*#__PURE__*/_jsx(TextInput, {
313
+ style: styles.input,
314
+ value: draft.urlPattern,
315
+ onChangeText: urlPattern => patch({
316
+ urlPattern
317
+ }),
318
+ placeholder: "https://api.example.com/v1/users*",
319
+ placeholderTextColor: macOSColors.text.muted,
320
+ autoCapitalize: "none",
321
+ autoCorrect: false,
322
+ multiline: true,
323
+ "sentry-label": "ignore override url pattern"
324
+ }), /*#__PURE__*/_jsxs(View, {
325
+ style: styles.chipRow,
326
+ children: [/*#__PURE__*/_jsx(Chip, {
327
+ label: "Any",
328
+ active: !method,
329
+ onPress: () => patch({
330
+ methods: undefined
331
+ })
332
+ }), METHODS.map(m => /*#__PURE__*/_jsx(Chip, {
333
+ label: m,
334
+ active: method === m,
335
+ onPress: () => patch({
336
+ methods: [m]
337
+ })
338
+ }, m))]
339
+ })]
340
+ }), /*#__PURE__*/_jsxs(View, {
341
+ style: styles.outcomeGrid,
342
+ children: [OUTCOMES.map(outcome => /*#__PURE__*/_jsx(OutcomeChip, {
343
+ outcome: outcome,
344
+ active: activeOutcome === outcome.id,
345
+ onPress: () => patch(outcome.patch)
346
+ }, outcome.id)), /*#__PURE__*/_jsx(TouchableOpacity, {
347
+ onPress: () => setPrompt("status"),
348
+ "sentry-label": "ignore custom status",
349
+ accessibilityLabel: "Custom status code",
350
+ style: [styles.customField, customStatusActive && styles.customFieldActive],
351
+ children: /*#__PURE__*/_jsx(Text, {
352
+ style: [styles.customValue, customStatusActive && styles.customInputActive],
353
+ children: customStatusActive ? String(draft.status) : "Custom"
354
+ })
355
+ })]
356
+ }), showsBody ? /*#__PURE__*/_jsx(Disclosure, {
357
+ title: "Response body",
358
+ summary: bodySummary,
359
+ open: bodyOpen,
360
+ onToggle: () => setBodyOpen(v => !v),
361
+ children: pasteText !== null ?
362
+ /*#__PURE__*/
363
+ /* Replace-the-whole-thing mode. Starts empty — see `pasteText`. */
364
+ _jsxs(_Fragment, {
365
+ children: [/*#__PURE__*/_jsx(TextInput, {
366
+ style: [styles.input, styles.bodyInput],
367
+ value: pasteText,
368
+ onChangeText: setPasteText,
369
+ placeholder: "Paste a new body\u2026",
370
+ placeholderTextColor: macOSColors.text.muted,
371
+ autoCapitalize: "none",
372
+ autoCorrect: false,
373
+ autoFocus: true,
374
+ multiline: true,
375
+ "sentry-label": "ignore override body paste"
376
+ }), /*#__PURE__*/_jsxs(View, {
377
+ style: styles.inlineActions,
378
+ children: [/*#__PURE__*/_jsx(TouchableOpacity, {
379
+ onPress: () => setPasteText(null),
380
+ "sentry-label": "ignore cancel body paste",
381
+ style: styles.textButton,
382
+ children: /*#__PURE__*/_jsx(Text, {
383
+ style: styles.textButtonMuted,
384
+ children: "Cancel"
385
+ })
386
+ }), /*#__PURE__*/_jsx(TouchableOpacity, {
387
+ onPress: () => {
388
+ const next = pasteText.trim();
389
+ // Pretty-print JSON on the way in so the tree it becomes
390
+ // is readable; anything else is kept exactly as pasted.
391
+ try {
392
+ patch({
393
+ body: JSON.stringify(JSON.parse(next), null, 2)
394
+ });
395
+ } catch {
396
+ patch({
397
+ body: next
398
+ });
399
+ }
400
+ setPasteText(null);
401
+ },
402
+ disabled: !pasteText.trim(),
403
+ "sentry-label": "ignore apply body paste",
404
+ style: styles.textButton,
405
+ children: /*#__PURE__*/_jsx(Text, {
406
+ style: [styles.textButtonLabel, !pasteText.trim() && styles.textButtonDisabled],
407
+ children: "Replace"
408
+ })
409
+ })]
410
+ })]
411
+ }) : /*#__PURE__*/_jsxs(_Fragment, {
412
+ children: [parsedBody !== null ?
413
+ /*#__PURE__*/
414
+ /* The SAME tree as the request detail — tap a value to edit
415
+ it. Editing writes the whole document back as the rule's
416
+ body, so the two surfaces behave identically. */
417
+ _jsx(ResponseEditorContext.Provider, {
418
+ value: {
419
+ root: parsedBody,
420
+ onChange: next => patch({
421
+ body: JSON.stringify(next, null, 2)
422
+ })
423
+ },
424
+ children: /*#__PURE__*/_jsx(Explorer, {
425
+ editable: true,
426
+ label: "",
427
+ value: parsedBody,
428
+ defaultExpanded: [""]
429
+ })
430
+ }) : /*#__PURE__*/_jsx(Text, {
431
+ style: styles.emptyBody,
432
+ children: bodyIsNonJsonText ? "This body isn't JSON, so there's no tree to show." : "No body yet."
433
+ }), /*#__PURE__*/_jsx(TouchableOpacity, {
434
+ onPress: () => setPasteText(""),
435
+ "sentry-label": "ignore edit all body",
436
+ style: styles.textButton,
437
+ children: /*#__PURE__*/_jsx(Text, {
438
+ style: styles.textButtonLabel,
439
+ children: "Edit all"
440
+ })
441
+ })]
442
+ })
443
+ }) : null, /*#__PURE__*/_jsxs(View, {
444
+ style: styles.field,
445
+ children: [/*#__PURE__*/_jsx(Text, {
446
+ style: styles.subLabel,
447
+ children: "Delay"
448
+ }), /*#__PURE__*/_jsxs(View, {
449
+ style: styles.chipRow,
450
+ children: [DELAY_PRESETS.map(ms => /*#__PURE__*/_jsx(Chip, {
451
+ label: ms === 0 ? "None" : `${ms / 1000}s`,
452
+ active: delayMs === ms,
453
+ onPress: () => patch({
454
+ delayMs: ms
455
+ })
456
+ }, ms)), /*#__PURE__*/_jsx(TouchableOpacity, {
457
+ onPress: () => setPrompt("delay"),
458
+ "sentry-label": "ignore custom delay",
459
+ accessibilityLabel: "Custom delay in seconds",
460
+ style: [styles.customField, customDelayActive && styles.customFieldActive],
461
+ children: /*#__PURE__*/_jsx(Text, {
462
+ style: [styles.customValue, customDelayActive && styles.customInputActive],
463
+ children: customDelayActive ? `${delayMs / 1000}s` : "Custom"
464
+ })
465
+ })]
466
+ })]
467
+ }), /*#__PURE__*/_jsxs(View, {
468
+ style: styles.field,
469
+ children: [/*#__PURE__*/_jsx(Text, {
470
+ style: styles.subLabel,
471
+ children: "Fires"
472
+ }), /*#__PURE__*/_jsx(Text, {
473
+ style: styles.subHint,
474
+ children: "A limited rule switches itself off once it's used up. Every other alternates forever \u2014 the first request through, the next overridden."
475
+ }), /*#__PURE__*/_jsxs(View, {
476
+ style: styles.chipRow,
477
+ children: [/*#__PURE__*/_jsx(Chip, {
478
+ label: "Always",
479
+ active: !draft.alternate && draft.times == null,
480
+ onPress: () => patch({
481
+ alternate: false,
482
+ times: null
483
+ })
484
+ }), /*#__PURE__*/_jsx(Chip, {
485
+ label: "Once",
486
+ active: !draft.alternate && draft.times === 1,
487
+ onPress: () => patch({
488
+ alternate: false,
489
+ times: 1
490
+ })
491
+ }), /*#__PURE__*/_jsx(Chip, {
492
+ label: "Every other",
493
+ active: draft.alternate === true,
494
+ onPress: () => patch({
495
+ alternate: true,
496
+ times: null
497
+ })
498
+ }), /*#__PURE__*/_jsx(TouchableOpacity, {
499
+ onPress: () => {
500
+ patch({
501
+ alternate: false
502
+ });
503
+ setPrompt("times");
504
+ },
505
+ "sentry-label": "ignore custom times",
506
+ accessibilityLabel: "Custom number of times",
507
+ style: [styles.customField, customTimesActive && styles.customFieldActive],
508
+ children: /*#__PURE__*/_jsx(Text, {
509
+ style: [styles.customValue, customTimesActive && styles.customInputActive],
510
+ children: customTimesActive ? `${draft.times}×` : "Custom"
511
+ })
512
+ })]
513
+ })]
514
+ })]
515
+ }), prompt === "status" ? /*#__PURE__*/_jsx(NetworkNumberPrompt, {
516
+ title: "Custom status code",
517
+ hint: `${STATUS_MIN}–${STATUS_MAX}`,
518
+ value: customStatusActive ? draft.status : undefined,
519
+ min: STATUS_MIN,
520
+ max: STATUS_MAX,
521
+ onSubmit: next => {
522
+ patch({
523
+ kind: "respond",
524
+ status: next ?? undefined,
525
+ statusText: undefined
526
+ });
527
+ setPrompt(null);
528
+ },
529
+ onCancel: () => setPrompt(null)
530
+ }) : null, prompt === "delay" ? /*#__PURE__*/_jsx(NetworkNumberPrompt, {
531
+ title: "Custom delay",
532
+ hint: "Seconds",
533
+ value: customDelayActive ? delayMs / 1000 : undefined,
534
+ min: 0,
535
+ onSubmit: next => {
536
+ patch({
537
+ delayMs: next != null ? Math.round(next * 1000) : 0
538
+ });
539
+ setPrompt(null);
540
+ },
541
+ onCancel: () => setPrompt(null)
542
+ }) : null, prompt === "times" ? /*#__PURE__*/_jsx(NetworkNumberPrompt, {
543
+ title: "Fires how many times",
544
+ hint: "Leave empty for always",
545
+ value: customTimesActive ? draft.times : undefined,
546
+ min: 1,
547
+ onSubmit: next => {
548
+ // Empty or zero means "no limit" rather than a rule that is spent
549
+ // before it ever fires.
550
+ patch({
551
+ alternate: false,
552
+ times: next && next > 0 ? next : null
553
+ });
554
+ setPrompt(null);
555
+ },
556
+ onCancel: () => setPrompt(null)
557
+ }) : null, /*#__PURE__*/_jsxs(View, {
558
+ style: [styles.footer, {
559
+ paddingBottom: 12 + bottomInset
560
+ }],
561
+ children: [/*#__PURE__*/_jsx(TouchableOpacity, {
562
+ onPress: onCancel,
563
+ "sentry-label": "ignore cancel override",
564
+ style: [styles.footerButton, styles.cancelButton],
565
+ children: /*#__PURE__*/_jsx(Text, {
566
+ style: styles.cancelText,
567
+ children: "Cancel"
568
+ })
569
+ }), /*#__PURE__*/_jsx(TouchableOpacity, {
570
+ onPress: onSave,
571
+ disabled: !draft.urlPattern.trim(),
572
+ "sentry-label": "ignore save override",
573
+ style: [styles.footerButton, styles.saveButton, !draft.urlPattern.trim() && styles.saveButtonDisabled],
574
+ children: /*#__PURE__*/_jsx(Text, {
575
+ style: styles.saveText,
576
+ children: saveLabel
577
+ })
578
+ })]
579
+ })]
580
+ });
581
+ }
582
+ const styles = StyleSheet.create({
583
+ root: {
584
+ flex: 1
585
+ },
586
+ scroll: {
587
+ flex: 1
588
+ },
589
+ scrollContent: {
590
+ padding: 12,
591
+ paddingBottom: 24,
592
+ gap: 4
593
+ },
594
+ field: {
595
+ gap: 8,
596
+ paddingVertical: 6
597
+ },
598
+ outcomeGrid: {
599
+ flexDirection: "row",
600
+ flexWrap: "wrap",
601
+ gap: 6,
602
+ paddingVertical: 10
603
+ },
604
+ outcome: {
605
+ flexDirection: "row",
606
+ alignItems: "center",
607
+ gap: 6,
608
+ paddingHorizontal: 10,
609
+ paddingVertical: 9,
610
+ borderRadius: 6,
611
+ borderWidth: 1,
612
+ borderColor: macOSColors.border.default,
613
+ backgroundColor: macOSColors.background.card
614
+ },
615
+ outcomeLabel: {
616
+ fontSize: 12,
617
+ fontWeight: "600",
618
+ color: macOSColors.text.primary
619
+ },
620
+ outcomeCode: {
621
+ fontSize: 10,
622
+ fontWeight: "700",
623
+ color: macOSColors.text.muted
624
+ },
625
+ disclosure: {
626
+ borderRadius: 6,
627
+ borderWidth: 1,
628
+ borderColor: macOSColors.border.default,
629
+ backgroundColor: macOSColors.background.card,
630
+ overflow: "hidden"
631
+ },
632
+ disclosureHeader: {
633
+ flexDirection: "row",
634
+ alignItems: "center",
635
+ gap: 6,
636
+ paddingHorizontal: 10,
637
+ paddingVertical: 10
638
+ },
639
+ disclosureTitle: {
640
+ fontSize: 12,
641
+ fontWeight: "600",
642
+ color: macOSColors.text.primary
643
+ },
644
+ disclosureSummary: {
645
+ flex: 1,
646
+ textAlign: "right",
647
+ fontSize: 11,
648
+ color: macOSColors.text.muted
649
+ },
650
+ disclosureBody: {
651
+ paddingHorizontal: 10,
652
+ paddingBottom: 10,
653
+ gap: 8
654
+ },
655
+ input: {
656
+ backgroundColor: macOSColors.background.input,
657
+ borderWidth: 1,
658
+ borderColor: macOSColors.border.input,
659
+ borderRadius: 6,
660
+ paddingHorizontal: 10,
661
+ paddingVertical: 8,
662
+ color: macOSColors.text.primary,
663
+ fontSize: 12,
664
+ fontFamily: "monospace",
665
+ minHeight: 40
666
+ },
667
+ bodyInput: {
668
+ minHeight: 140,
669
+ textAlignVertical: "top"
670
+ },
671
+ chipRow: {
672
+ flexDirection: "row",
673
+ flexWrap: "wrap",
674
+ gap: 6
675
+ },
676
+ chip: {
677
+ paddingHorizontal: 10,
678
+ paddingVertical: 6,
679
+ borderRadius: 5,
680
+ borderWidth: 1,
681
+ borderColor: macOSColors.border.default,
682
+ backgroundColor: macOSColors.background.base
683
+ },
684
+ chipActive: {
685
+ borderColor: macOSColors.semantic.info,
686
+ backgroundColor: `${macOSColors.semantic.info}1F`
687
+ },
688
+ chipText: {
689
+ fontSize: 11,
690
+ fontWeight: "600",
691
+ color: macOSColors.text.secondary
692
+ },
693
+ chipTextActive: {
694
+ color: macOSColors.semantic.info
695
+ },
696
+ customField: {
697
+ flexDirection: "row",
698
+ alignItems: "center",
699
+ paddingHorizontal: 8,
700
+ borderRadius: 5,
701
+ borderWidth: 1,
702
+ borderColor: macOSColors.border.default,
703
+ backgroundColor: macOSColors.background.base
704
+ },
705
+ customFieldActive: {
706
+ borderColor: macOSColors.semantic.info,
707
+ backgroundColor: `${macOSColors.semantic.info}1F`
708
+ },
709
+ customValue: {
710
+ paddingVertical: 6,
711
+ fontSize: 11,
712
+ fontWeight: "600",
713
+ color: macOSColors.text.secondary
714
+ },
715
+ customInputActive: {
716
+ color: macOSColors.semantic.info
717
+ },
718
+ subHint: {
719
+ fontSize: 10,
720
+ lineHeight: 14,
721
+ color: macOSColors.text.muted,
722
+ marginTop: -2
723
+ },
724
+ subLabel: {
725
+ fontSize: 10,
726
+ fontWeight: "700",
727
+ letterSpacing: 0.6,
728
+ color: macOSColors.text.muted,
729
+ textTransform: "uppercase"
730
+ },
731
+ textButton: {
732
+ alignSelf: "flex-start",
733
+ paddingVertical: 4
734
+ },
735
+ textButtonLabel: {
736
+ fontSize: 11,
737
+ fontWeight: "600",
738
+ color: macOSColors.semantic.info
739
+ },
740
+ textButtonMuted: {
741
+ fontSize: 11,
742
+ fontWeight: "600",
743
+ color: macOSColors.text.secondary
744
+ },
745
+ textButtonDisabled: {
746
+ opacity: 0.4
747
+ },
748
+ inlineActions: {
749
+ flexDirection: "row",
750
+ alignItems: "center",
751
+ justifyContent: "space-between"
752
+ },
753
+ emptyBody: {
754
+ fontSize: 11,
755
+ color: macOSColors.text.muted,
756
+ paddingVertical: 6
757
+ },
758
+ footer: {
759
+ flexDirection: "row",
760
+ gap: 8,
761
+ padding: 12,
762
+ borderTopWidth: 1,
763
+ borderTopColor: macOSColors.border.default,
764
+ backgroundColor: macOSColors.background.base
765
+ },
766
+ footerButton: {
767
+ flex: 1,
768
+ paddingVertical: 11,
769
+ borderRadius: 6,
770
+ alignItems: "center",
771
+ borderWidth: 1
772
+ },
773
+ cancelButton: {
774
+ borderColor: macOSColors.border.default,
775
+ backgroundColor: macOSColors.background.card
776
+ },
777
+ cancelText: {
778
+ fontSize: 12,
779
+ fontWeight: "600",
780
+ color: macOSColors.text.secondary
781
+ },
782
+ saveButton: {
783
+ borderColor: macOSColors.semantic.info,
784
+ backgroundColor: `${macOSColors.semantic.info}22`
785
+ },
786
+ saveButtonDisabled: {
787
+ opacity: 0.4
788
+ },
789
+ saveText: {
790
+ fontSize: 12,
791
+ fontWeight: "700",
792
+ color: macOSColors.semantic.info
793
+ }
794
+ });