@buoy-gg/network 7.0.13 → 7.0.15

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 (123) hide show
  1. package/lib/commonjs/index.js +39 -0
  2. package/lib/commonjs/network/components/NetworkEventDetailView.js +30 -3
  3. package/lib/commonjs/network/components/NetworkEventItemCompact.js +4 -0
  4. package/lib/commonjs/network/components/NetworkHeaderLive.js +26 -6
  5. package/lib/commonjs/network/components/NetworkHeaderMenu.js +183 -0
  6. package/lib/commonjs/network/components/NetworkListScreen.js +126 -5
  7. package/lib/commonjs/network/components/NetworkModal.js +136 -29
  8. package/lib/commonjs/network/components/NetworkNumberPrompt.js +178 -0
  9. package/lib/commonjs/network/components/NetworkOverrideEditor.js +797 -0
  10. package/lib/commonjs/network/components/NetworkOverrideHeaderButton.js +102 -0
  11. package/lib/commonjs/network/components/NetworkOverridesButton.js +88 -0
  12. package/lib/commonjs/network/components/NetworkOverridesScreen.js +489 -0
  13. package/lib/commonjs/network/components/response-editor/Explorer.js +973 -0
  14. package/lib/commonjs/network/components/response-editor/deleteNestedDataByPath.js +56 -0
  15. package/lib/commonjs/network/components/response-editor/editorContext.js +33 -0
  16. package/lib/commonjs/network/components/response-editor/updateNestedDataByPath.js +61 -0
  17. package/lib/commonjs/network/hooks/useOverrideRules.js +36 -0
  18. package/lib/commonjs/network/overrides/applyToFetch.js +80 -0
  19. package/lib/commonjs/network/overrides/applyToXhr.js +190 -0
  20. package/lib/commonjs/network/overrides/engine.js +70 -0
  21. package/lib/commonjs/network/overrides/matchRule.js +81 -0
  22. package/lib/commonjs/network/overrides/overrideRulesStore.js +550 -0
  23. package/lib/commonjs/network/overrides/presets.js +70 -0
  24. package/lib/commonjs/network/overrides/resolveOverride.js +158 -0
  25. package/lib/commonjs/network/overrides/types.js +85 -0
  26. package/lib/commonjs/network/sync/networkSyncAdapter.js +230 -1
  27. package/lib/commonjs/network/types/index.js +5 -1
  28. package/lib/commonjs/network/utils/networkEventStore.js +52 -6
  29. package/lib/commonjs/network/utils/networkListener.js +90 -10
  30. package/lib/commonjs/preset.js +11 -0
  31. package/lib/module/index.js +15 -0
  32. package/lib/module/network/components/NetworkEventDetailView.js +31 -4
  33. package/lib/module/network/components/NetworkEventItemCompact.js +5 -1
  34. package/lib/module/network/components/NetworkHeaderLive.js +26 -6
  35. package/lib/module/network/components/NetworkHeaderMenu.js +177 -0
  36. package/lib/module/network/components/NetworkListScreen.js +127 -6
  37. package/lib/module/network/components/NetworkModal.js +138 -31
  38. package/lib/module/network/components/NetworkNumberPrompt.js +174 -0
  39. package/lib/module/network/components/NetworkOverrideEditor.js +794 -0
  40. package/lib/module/network/components/NetworkOverrideHeaderButton.js +99 -0
  41. package/lib/module/network/components/NetworkOverridesButton.js +85 -0
  42. package/lib/module/network/components/NetworkOverridesScreen.js +485 -0
  43. package/lib/module/network/components/response-editor/Explorer.js +972 -0
  44. package/lib/module/network/components/response-editor/deleteNestedDataByPath.js +51 -0
  45. package/lib/module/network/components/response-editor/editorContext.js +29 -0
  46. package/lib/module/network/components/response-editor/updateNestedDataByPath.js +56 -0
  47. package/lib/module/network/hooks/useOverrideRules.js +32 -0
  48. package/lib/module/network/overrides/applyToFetch.js +72 -0
  49. package/lib/module/network/overrides/applyToXhr.js +185 -0
  50. package/lib/module/network/overrides/engine.js +64 -0
  51. package/lib/module/network/overrides/matchRule.js +75 -0
  52. package/lib/module/network/overrides/overrideRulesStore.js +547 -0
  53. package/lib/module/network/overrides/presets.js +65 -0
  54. package/lib/module/network/overrides/resolveOverride.js +152 -0
  55. package/lib/module/network/overrides/types.js +80 -0
  56. package/lib/module/network/sync/networkSyncAdapter.js +230 -1
  57. package/lib/module/network/types/index.js +3 -1
  58. package/lib/module/network/utils/networkEventStore.js +52 -6
  59. package/lib/module/network/utils/networkListener.js +91 -10
  60. package/lib/module/preset.js +13 -1
  61. package/lib/typescript/index.d.ts +8 -0
  62. package/lib/typescript/index.d.ts.map +1 -1
  63. package/lib/typescript/network/components/NetworkEventDetailView.d.ts.map +1 -1
  64. package/lib/typescript/network/components/NetworkEventItemCompact.d.ts +6 -0
  65. package/lib/typescript/network/components/NetworkEventItemCompact.d.ts.map +1 -1
  66. package/lib/typescript/network/components/NetworkHeaderLive.d.ts +8 -1
  67. package/lib/typescript/network/components/NetworkHeaderLive.d.ts.map +1 -1
  68. package/lib/typescript/network/components/NetworkHeaderMenu.d.ts +46 -0
  69. package/lib/typescript/network/components/NetworkHeaderMenu.d.ts.map +1 -0
  70. package/lib/typescript/network/components/NetworkListScreen.d.ts.map +1 -1
  71. package/lib/typescript/network/components/NetworkModal.d.ts.map +1 -1
  72. package/lib/typescript/network/components/NetworkNumberPrompt.d.ts +33 -0
  73. package/lib/typescript/network/components/NetworkNumberPrompt.d.ts.map +1 -0
  74. package/lib/typescript/network/components/NetworkOverrideEditor.d.ts +17 -0
  75. package/lib/typescript/network/components/NetworkOverrideEditor.d.ts.map +1 -0
  76. package/lib/typescript/network/components/NetworkOverrideHeaderButton.d.ts +27 -0
  77. package/lib/typescript/network/components/NetworkOverrideHeaderButton.d.ts.map +1 -0
  78. package/lib/typescript/network/components/NetworkOverridesButton.d.ts +17 -0
  79. package/lib/typescript/network/components/NetworkOverridesButton.d.ts.map +1 -0
  80. package/lib/typescript/network/components/NetworkOverridesScreen.d.ts +29 -0
  81. package/lib/typescript/network/components/NetworkOverridesScreen.d.ts.map +1 -0
  82. package/lib/typescript/network/components/response-editor/Explorer.d.ts +17 -0
  83. package/lib/typescript/network/components/response-editor/Explorer.d.ts.map +1 -0
  84. package/lib/typescript/network/components/response-editor/deleteNestedDataByPath.d.ts +9 -0
  85. package/lib/typescript/network/components/response-editor/deleteNestedDataByPath.d.ts.map +1 -0
  86. package/lib/typescript/network/components/response-editor/editorContext.d.ts +29 -0
  87. package/lib/typescript/network/components/response-editor/editorContext.d.ts.map +1 -0
  88. package/lib/typescript/network/components/response-editor/updateNestedDataByPath.d.ts +10 -0
  89. package/lib/typescript/network/components/response-editor/updateNestedDataByPath.d.ts.map +1 -0
  90. package/lib/typescript/network/hooks/useOverrideRules.d.ts +29 -0
  91. package/lib/typescript/network/hooks/useOverrideRules.d.ts.map +1 -0
  92. package/lib/typescript/network/overrides/__tests__/applyToFetch.test.d.ts +16 -0
  93. package/lib/typescript/network/overrides/__tests__/applyToFetch.test.d.ts.map +1 -0
  94. package/lib/typescript/network/overrides/__tests__/applyToXhr.test.d.ts +19 -0
  95. package/lib/typescript/network/overrides/__tests__/applyToXhr.test.d.ts.map +1 -0
  96. package/lib/typescript/network/overrides/__tests__/resolveOverride.test.d.ts +22 -0
  97. package/lib/typescript/network/overrides/__tests__/resolveOverride.test.d.ts.map +1 -0
  98. package/lib/typescript/network/overrides/applyToFetch.d.ts +50 -0
  99. package/lib/typescript/network/overrides/applyToFetch.d.ts.map +1 -0
  100. package/lib/typescript/network/overrides/applyToXhr.d.ts +43 -0
  101. package/lib/typescript/network/overrides/applyToXhr.d.ts.map +1 -0
  102. package/lib/typescript/network/overrides/engine.d.ts +47 -0
  103. package/lib/typescript/network/overrides/engine.d.ts.map +1 -0
  104. package/lib/typescript/network/overrides/matchRule.d.ts +22 -0
  105. package/lib/typescript/network/overrides/matchRule.d.ts.map +1 -0
  106. package/lib/typescript/network/overrides/overrideRulesStore.d.ts +205 -0
  107. package/lib/typescript/network/overrides/overrideRulesStore.d.ts.map +1 -0
  108. package/lib/typescript/network/overrides/presets.d.ts +38 -0
  109. package/lib/typescript/network/overrides/presets.d.ts.map +1 -0
  110. package/lib/typescript/network/overrides/resolveOverride.d.ts +46 -0
  111. package/lib/typescript/network/overrides/resolveOverride.d.ts.map +1 -0
  112. package/lib/typescript/network/overrides/types.d.ts +169 -0
  113. package/lib/typescript/network/overrides/types.d.ts.map +1 -0
  114. package/lib/typescript/network/sync/networkSyncAdapter.d.ts +73 -0
  115. package/lib/typescript/network/sync/networkSyncAdapter.d.ts.map +1 -1
  116. package/lib/typescript/network/types/index.d.ts +10 -0
  117. package/lib/typescript/network/types/index.d.ts.map +1 -1
  118. package/lib/typescript/network/utils/networkEventStore.d.ts +14 -0
  119. package/lib/typescript/network/utils/networkEventStore.d.ts.map +1 -1
  120. package/lib/typescript/network/utils/networkListener.d.ts +3 -0
  121. package/lib/typescript/network/utils/networkListener.d.ts.map +1 -1
  122. package/lib/typescript/preset.d.ts.map +1 -1
  123. package/package.json +2 -2
@@ -0,0 +1,102 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.NetworkOverrideHeaderButton = NetworkOverrideHeaderButton;
7
+ var _reactNative = require("react-native");
8
+ var _sharedUi = require("@buoy-gg/shared-ui");
9
+ var _useOverrideRules = require("../hooks/useOverrideRules");
10
+ var _useNetworkSelection = require("../hooks/useNetworkSelection");
11
+ var _matchRule = require("../overrides/matchRule");
12
+ var _presets = require("../overrides/presets");
13
+ var _networkEventStore = require("../utils/networkEventStore");
14
+ var _networkSavedStore = require("../utils/networkSavedStore");
15
+ var _jsxRuntime = require("react/jsx-runtime");
16
+ /**
17
+ * The Override action, in the request-detail header.
18
+ *
19
+ * A labelled word rather than an icon: every other control here is a glyph
20
+ * (back, pin, bookmark) and glyphs are fine for things you already know. This
21
+ * one is the least familiar action in the tool, and "Override" spelled out is
22
+ * the entire explanation.
23
+ *
24
+ * A self-subscribing leaf, for the same two reasons `NetworkDetailPinActions`
25
+ * is one: the modal root stays free of subscriptions, and the selected id is
26
+ * subscribed here so stepping between requests doesn't rebuild the header
27
+ * around a new prop.
28
+ *
29
+ * It lights up while a rule covers the request you're looking at — the same
30
+ * warning tint the OVERRIDDEN strip and the toolbar flask use, because "you are
31
+ * not seeing the truth" is one idea and should look like one.
32
+ *
33
+ * Tapping it goes straight to the Overrides screen with the rule open: a new
34
+ * one prefilled from this request, or the existing one if something already
35
+ * covers it. One destination, so there's never a question of where the thing
36
+ * you just made went.
37
+ */
38
+ function NetworkOverrideHeaderButton({
39
+ onOpen
40
+ }) {
41
+ const eventId = (0, _useNetworkSelection.useSelectedNetworkEventId)();
42
+ const {
43
+ rules,
44
+ isRuleSpent
45
+ } = (0, _useOverrideRules.useOverrideRules)();
46
+
47
+ // Resolved here rather than held as a prop: the live store has the fresh copy
48
+ // while a request is in flight, and the saved store is the only copy once it
49
+ // has been cleared or aged out.
50
+ const event = eventId ? _networkEventStore.networkEventStore.getEvents().find(e => e.id === eventId) ?? _networkSavedStore.networkSavedStore.getEventById(eventId) : null;
51
+ const existing = event ? rules.find(rule => rule.enabled && !isRuleSpent(rule) && (0, _matchRule.ruleMatches)(rule, event.url, String(event.method || "GET"))) ?? null : null;
52
+ const active = existing !== null;
53
+ const handlePress = () => {
54
+ if (!event) return;
55
+ if (existing) {
56
+ // Editing what's already there, rather than stacking a second rule the
57
+ // first would shadow — first enabled match wins.
58
+ const {
59
+ id,
60
+ hits: _h,
61
+ seen: _s,
62
+ createdAt: _c,
63
+ ...draft
64
+ } = existing;
65
+ onOpen(draft, id);
66
+ return;
67
+ }
68
+ onOpen((0, _presets.draftFromEvent)(event));
69
+ };
70
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.TouchableOpacity, {
71
+ onPress: handlePress,
72
+ "sentry-label": "ignore open overrides",
73
+ accessibilityLabel: active ? "Edit the override on this request" : "Override this request",
74
+ style: [styles.button, active && styles.buttonActive],
75
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, {
76
+ style: [styles.label, active && styles.labelActive],
77
+ children: "Override"
78
+ })
79
+ });
80
+ }
81
+ const styles = _reactNative.StyleSheet.create({
82
+ button: {
83
+ paddingHorizontal: 10,
84
+ paddingVertical: 6,
85
+ borderRadius: 6,
86
+ borderWidth: 1,
87
+ borderColor: _sharedUi.macOSColors.border.input,
88
+ backgroundColor: _sharedUi.macOSColors.background.input
89
+ },
90
+ buttonActive: {
91
+ borderColor: _sharedUi.macOSColors.semantic.warning + "77",
92
+ backgroundColor: _sharedUi.macOSColors.semantic.warningBackground
93
+ },
94
+ label: {
95
+ fontSize: 11,
96
+ fontWeight: "700",
97
+ color: _sharedUi.macOSColors.text.primary
98
+ },
99
+ labelActive: {
100
+ color: _sharedUi.macOSColors.semantic.warning
101
+ }
102
+ });
@@ -0,0 +1,88 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.NetworkOverridesButton = NetworkOverridesButton;
7
+ var _reactNative = require("react-native");
8
+ var _sharedUi = require("@buoy-gg/shared-ui");
9
+ var _useOverrideRules = require("../hooks/useOverrideRules");
10
+ var _jsxRuntime = require("react/jsx-runtime");
11
+ /**
12
+ * Header button for the Overrides screen, and the always-visible "overrides
13
+ * are active" indicator.
14
+ *
15
+ * A self-subscribing LEAF, like the other live header pieces: the rule list
16
+ * changes on its own schedule (every hit bumps a counter) and the modal shell
17
+ * has no business re-rendering for it.
18
+ *
19
+ * The active tint is not decoration. A rule left enabled from yesterday makes
20
+ * the app behave wrongly in a way that looks exactly like a real bug, so the
21
+ * tool has to keep saying so from the top level — Chrome shows the same
22
+ * warning in its Overrides pane for the same reason.
23
+ */
24
+ function NetworkOverridesButton({
25
+ onPress
26
+ }) {
27
+ const {
28
+ activeCount
29
+ } = (0, _useOverrideRules.useOverrideRules)();
30
+ const active = activeCount > 0;
31
+ return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.TouchableOpacity, {
32
+ onPress: onPress,
33
+ "sentry-label": "ignore open overrides",
34
+ style: [styles.button, active && styles.buttonActive],
35
+ accessibilityLabel: active ? `Response overrides — ${activeCount} active` : "Response overrides",
36
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_sharedUi.FlaskConical, {
37
+ size: 14,
38
+ color: active ? _sharedUi.macOSColors.semantic.warning : _sharedUi.macOSColors.text.secondary
39
+ }), active ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.View, {
40
+ style: styles.badge,
41
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, {
42
+ style: styles.badgeText,
43
+ children: activeCount
44
+ })
45
+ }) : null]
46
+ });
47
+ }
48
+ const styles = _reactNative.StyleSheet.create({
49
+ // The header's standard 32×32 action box — same shape, fill, border and
50
+ // radius as search/power/clear. It was a bare padded glyph, which read as a
51
+ // different CLASS of control than its neighbours when it is exactly the same
52
+ // kind of thing.
53
+ button: {
54
+ width: 32,
55
+ height: 32,
56
+ borderRadius: 8,
57
+ alignItems: "center",
58
+ justifyContent: "center",
59
+ backgroundColor: _sharedUi.macOSColors.background.hover,
60
+ borderWidth: 1,
61
+ borderColor: _sharedUi.macOSColors.border.default
62
+ },
63
+ // Active fills the whole box, the way the power toggle goes green — the
64
+ // warning now reads at a glance instead of as a tinted glyph.
65
+ buttonActive: {
66
+ backgroundColor: _sharedUi.macOSColors.semantic.warningBackground,
67
+ borderColor: _sharedUi.macOSColors.semantic.warning + "77"
68
+ },
69
+ badge: {
70
+ position: "absolute",
71
+ // Inside the box now that there is one; a corner-hung badge would clip
72
+ // against the neighbouring buttons' 8pt gap.
73
+ top: 1,
74
+ right: 1,
75
+ minWidth: 12,
76
+ height: 12,
77
+ borderRadius: 6,
78
+ paddingHorizontal: 3,
79
+ alignItems: "center",
80
+ justifyContent: "center",
81
+ backgroundColor: _sharedUi.macOSColors.semantic.warning
82
+ },
83
+ badgeText: {
84
+ fontSize: 8,
85
+ fontWeight: "800",
86
+ color: _sharedUi.macOSColors.background.base
87
+ }
88
+ });
@@ -0,0 +1,489 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.NetworkOverridesScreen = NetworkOverridesScreen;
7
+ var _react = require("react");
8
+ var _reactNative = require("react-native");
9
+ var _sharedUi = require("@buoy-gg/shared-ui");
10
+ var _useOverrideRules = require("../hooks/useOverrideRules");
11
+ var _NetworkOverrideEditor = require("./NetworkOverrideEditor");
12
+ var _overrideRulesStore = require("../overrides/overrideRulesStore");
13
+ var _jsxRuntime = require("react/jsx-runtime");
14
+ /**
15
+ * The rule manager: what's armed, and how to stop all of it.
16
+ *
17
+ * One bar across the top is both the warning and the switch. It used to be two
18
+ * things — an ON/OFF pill beside a title, and a separate banner saying the same
19
+ * thing in different words — which left the pill reading as though it applied
20
+ * to the selected rule. A state pill is ambiguous; a verb button isn't.
21
+ */
22
+
23
+ function blankDraft() {
24
+ return {
25
+ enabled: true,
26
+ urlPattern: "",
27
+ kind: "respond",
28
+ status: 500,
29
+ body: "",
30
+ times: null
31
+ };
32
+ }
33
+ function toDraft(rule) {
34
+ const {
35
+ id: _id,
36
+ hits: _hits,
37
+ seen: _seen,
38
+ createdAt: _createdAt,
39
+ ...draft
40
+ } = rule;
41
+ return draft;
42
+ }
43
+
44
+ /** Plain-language names for statuses, so a row never reads as a bare number. */
45
+ const STATUS_NAMES = {
46
+ 200: "Success",
47
+ 201: "Created",
48
+ 400: "Bad request",
49
+ 401: "Unauthorized",
50
+ 403: "Forbidden",
51
+ 404: "Not found",
52
+ 429: "Rate limited",
53
+ 500: "Server error",
54
+ 503: "Unavailable"
55
+ };
56
+
57
+ /** What the rule DOES, in the same words the editor uses. */
58
+ function outcomeLine(rule) {
59
+ const parts = [];
60
+ if (rule.kind === "respond") {
61
+ const status = rule.status ?? 200;
62
+ const name = STATUS_NAMES[status];
63
+ parts.push(name ? `${name} ${status}` : String(status));
64
+ } else if (rule.kind === "fail") {
65
+ parts.push(rule.failKind === "timeout" ? "Timeout" : "Offline");
66
+ } else {
67
+ parts.push("Real response");
68
+ }
69
+ if (rule.delayMs) parts.push(`${rule.delayMs / 1000}s`);
70
+ if (rule.alternate) parts.push("every other");else if (rule.times === 1) parts.push("once");else if (typeof rule.times === "number") parts.push(`${rule.times}×`);
71
+ return parts.join(" · ");
72
+ }
73
+
74
+ /**
75
+ * Where the rule applies — PATH only, not the whole URL.
76
+ *
77
+ * The host is the same for every rule in a typical app, so showing it pushes
78
+ * the part that differs off the end of the line.
79
+ */
80
+ function scopeLine(rule) {
81
+ const method = rule.methods?.length ? rule.methods.join("/") : "Any";
82
+ let path = rule.urlPattern;
83
+ const schemeEnd = path.indexOf("://");
84
+ if (schemeEnd !== -1) {
85
+ const slash = path.indexOf("/", schemeEnd + 3);
86
+ path = slash === -1 ? path.slice(schemeEnd + 3) : path.slice(slash);
87
+ }
88
+ return `${method} ${path}`;
89
+ }
90
+
91
+ /**
92
+ * One rule. Toggle · two lines · hit count, and nothing else.
93
+ *
94
+ * The pencil and trash icons are gone: the row itself opens the editor (where
95
+ * Delete now lives), and three tap targets in a 44pt row is a config table, not
96
+ * a list. `hits` stays as the only right-hand element because "my glob never
97
+ * matched" is the most common rule bug and the count is how you find out.
98
+ */
99
+ function RuleRow({
100
+ rule,
101
+ spent,
102
+ onToggle,
103
+ onEdit
104
+ }) {
105
+ const live = rule.enabled && !spent;
106
+ const accent = live ? _sharedUi.macOSColors.semantic.warning : _sharedUi.macOSColors.text.muted;
107
+ return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.View, {
108
+ style: styles.row,
109
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.TouchableOpacity, {
110
+ onPress: onToggle,
111
+ "sentry-label": "ignore toggle override rule",
112
+ accessibilityLabel: live ? "Turn rule off" : "Turn rule on",
113
+ style: [styles.toggle, live && {
114
+ borderColor: accent,
115
+ backgroundColor: `${accent}33`
116
+ }],
117
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.View, {
118
+ style: [styles.toggleDot, {
119
+ backgroundColor: accent
120
+ }]
121
+ })
122
+ }), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.TouchableOpacity, {
123
+ onPress: onEdit,
124
+ "sentry-label": "ignore edit override rule",
125
+ style: styles.rowBody,
126
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, {
127
+ style: [styles.rowTitle, !live && styles.rowTitleOff],
128
+ numberOfLines: 1,
129
+ children: outcomeLine(rule)
130
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, {
131
+ style: styles.rowScope,
132
+ numberOfLines: 1,
133
+ children: scopeLine(rule)
134
+ })]
135
+ }), rule.hits > 0 ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, {
136
+ style: styles.rowHits,
137
+ children: rule.hits
138
+ }) : null]
139
+ });
140
+ }
141
+ /**
142
+ * Stable-router gate.
143
+ *
144
+ * The screens in `NetworkModal` are rendered as permanent siblings, and the
145
+ * convention there is that a HIDDEN screen must not subscribe to anything.
146
+ * Splitting the body out is how this one honours that: `useOverrideRules`
147
+ * subscribes to a store that ticks while rules are firing, and a hidden screen
148
+ * re-rendering for that would be pure waste. (The header's overrides button is
149
+ * a deliberate exception — it's always visible and its whole job is to react.)
150
+ */
151
+ function NetworkOverridesScreen(props) {
152
+ if (!props.visible) return null;
153
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(OverridesBody, {
154
+ ...props
155
+ });
156
+ }
157
+ function OverridesBody({
158
+ isPro,
159
+ onUpgradePress,
160
+ pendingDraft,
161
+ onPendingConsumed,
162
+ applySafeAreaInset
163
+ }) {
164
+ const {
165
+ enabled,
166
+ autoPaused,
167
+ rules,
168
+ activeCount,
169
+ setEnabled,
170
+ upsertRule,
171
+ setRuleEnabled,
172
+ removeRule,
173
+ isRuleSpent
174
+ } = (0, _useOverrideRules.useOverrideRules)();
175
+ const [editing, setEditing] = (0, _react.useState)(null);
176
+
177
+ // Reaching this screen proves the app renders, so the launch-safety streak
178
+ // has nothing to guard against — see `noteHealthyLaunch`.
179
+ (0, _react.useEffect)(() => {
180
+ _overrideRulesStore.overrideRulesStore.noteHealthyLaunch();
181
+ }, []);
182
+
183
+ /**
184
+ * Open a rule for editing, pulling its body over if this surface doesn't have
185
+ * it.
186
+ *
187
+ * On the device that's already the case and the fetch resolves synchronously.
188
+ * On the dashboard a large body is left out of the snapshot on purpose (see
189
+ * `stripLargeRuleBodies`), so it arrives a moment after the editor does — the
190
+ * `id` re-check keeps a slow reply from landing in a rule you've since moved
191
+ * on from.
192
+ */
193
+ const hydrateBody = (0, _react.useCallback)(id => {
194
+ void _overrideRulesStore.overrideRulesStore.fetchRuleBody(id).then(body => {
195
+ if (body == null) return;
196
+ setEditing(current => current?.id === id ? {
197
+ ...current,
198
+ draft: {
199
+ ...current.draft,
200
+ body,
201
+ bodyOmitted: undefined
202
+ }
203
+ } : current);
204
+ });
205
+ }, []);
206
+ (0, _react.useEffect)(() => {
207
+ if (!pendingDraft) return;
208
+ const {
209
+ id,
210
+ ...draft
211
+ } = pendingDraft;
212
+ setEditing({
213
+ id,
214
+ draft
215
+ });
216
+ // Same reason as `openRule`: the detail page's Override button hands over an
217
+ // existing rule, and on the dashboard that rule's body may not be here yet.
218
+ if (id && draft.bodyOmitted) hydrateBody(id);
219
+ onPendingConsumed?.();
220
+ }, [pendingDraft, onPendingConsumed, hydrateBody]);
221
+
222
+ /**
223
+ * Leave the editor when the rule it's editing stops existing.
224
+ *
225
+ * Rules can be cleared from somewhere else — the dashboard, an MCP agent —
226
+ * while this editor is open. Without this, Save would upsert the old id and
227
+ * quietly RESURRECT a rule someone had just deleted. Only guards existing
228
+ * rules; a draft with no id yet is a new rule and has nothing to lose.
229
+ */
230
+ (0, _react.useEffect)(() => {
231
+ if (!editing?.id) return;
232
+ if (rules.some(rule => rule.id === editing.id)) return;
233
+ setEditing(null);
234
+ }, [editing?.id, rules]);
235
+ const openRule = rule => {
236
+ setEditing({
237
+ id: rule.id,
238
+ draft: toDraft(rule)
239
+ });
240
+ if (rule.bodyOmitted) hydrateBody(rule.id);
241
+ };
242
+
243
+ /**
244
+ * On the free tier a new rule REPLACES the live one rather than being refused.
245
+ *
246
+ * The old behaviour put an upgrade modal in the action path: you tapped a
247
+ * thing and got a sales pitch instead of the thing. Nobody buys from a modal
248
+ * that just cancelled their action, and it hid the feature behind a wall
249
+ * instead of letting you feel its shape. "One override at a time" is a shape
250
+ * a developer understands.
251
+ */
252
+ const enforceFreeTier = keepId => {
253
+ if (isPro) return;
254
+ rules.filter(rule => rule.enabled && !isRuleSpent(rule) && rule.id !== keepId).forEach(rule => setRuleEnabled(rule.id, false));
255
+ };
256
+ const handleSave = () => {
257
+ if (!editing) return;
258
+ const draft = {
259
+ ...editing.draft,
260
+ urlPattern: editing.draft.urlPattern.trim()
261
+ };
262
+ if (!draft.urlPattern) return;
263
+ const saved = upsertRule({
264
+ ...draft,
265
+ id: editing.id
266
+ });
267
+ if (draft.enabled) {
268
+ enforceFreeTier(saved?.id ?? editing.id);
269
+ // Arm the master switch. Deliberately creating a rule and having it sit
270
+ // inert because overrides happen to be paused is the silent-failure this
271
+ // feature can least afford — the preset path already does this, and the
272
+ // manager disagreeing with it was just a gap.
273
+ setEnabled(true);
274
+ }
275
+ setEditing(null);
276
+ };
277
+ const handleToggle = rule => {
278
+ const next = !rule.enabled;
279
+ setRuleEnabled(rule.id, next);
280
+ if (next) enforceFreeTier(rule.id);
281
+ };
282
+ if (editing) {
283
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_NetworkOverrideEditor.NetworkOverrideEditor, {
284
+ draft: editing.draft,
285
+ onChange: draft => setEditing({
286
+ ...editing,
287
+ draft
288
+ }),
289
+ onSave: handleSave,
290
+ onCancel: () => setEditing(null),
291
+ saveLabel: editing.id ? "Save" : "Add",
292
+ applySafeAreaInset: applySafeAreaInset
293
+ });
294
+ }
295
+ const hasRules = rules.length > 0;
296
+ return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.View, {
297
+ style: styles.root,
298
+ children: [hasRules ? /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.View, {
299
+ style: [styles.bar, enabled && activeCount > 0 && styles.barOn],
300
+ children: [enabled && activeCount > 0 ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_sharedUi.AlertTriangle, {
301
+ size: 12,
302
+ color: _sharedUi.macOSColors.semantic.warning
303
+ }) : null, /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, {
304
+ style: [styles.barText, enabled && activeCount > 0 && styles.barTextOn],
305
+ numberOfLines: 2,
306
+ children: autoPaused ? "Overrides paused — they'd been on for 3 launches" : enabled && activeCount > 0 ? `${activeCount} override${activeCount === 1 ? " is" : "s are"} on` : "Overrides are off"
307
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.TouchableOpacity, {
308
+ onPress: () => setEnabled(!(enabled && activeCount > 0)),
309
+ "sentry-label": "ignore toggle overrides master",
310
+ style: styles.barButton,
311
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, {
312
+ style: styles.barButtonText,
313
+ children: enabled && activeCount > 0 ? "Turn all off" : autoPaused ? "Turn back on" : "Turn on"
314
+ })
315
+ })]
316
+ }) : null, /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.View, {
317
+ style: styles.listHeader,
318
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, {
319
+ style: styles.listHeaderText,
320
+ children: hasRules ? `${rules.length} rule${rules.length === 1 ? "" : "s"}` : ""
321
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.TouchableOpacity, {
322
+ onPress: () => setEditing({
323
+ draft: blankDraft()
324
+ }),
325
+ "sentry-label": "ignore new override rule",
326
+ accessibilityLabel: "New override rule",
327
+ style: styles.newButton,
328
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_sharedUi.Plus, {
329
+ size: 14,
330
+ color: _sharedUi.macOSColors.semantic.info
331
+ })
332
+ })]
333
+ }), !hasRules ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.View, {
334
+ style: styles.emptyWrap,
335
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_sharedUi.EmptyState, {
336
+ icon: _sharedUi.FlaskConical,
337
+ title: "Nothing overridden"
338
+ // Names the control that actually exists. This said "tap Force 500"
339
+ // — a button from the deleted preset list, which sent anyone
340
+ // following it looking for something that isn't there.
341
+ ,
342
+ description: "Open any request and tap Override, or + to write a rule."
343
+ })
344
+ }) : /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.ScrollView, {
345
+ style: styles.list,
346
+ contentContainerStyle: styles.listContent,
347
+ keyboardShouldPersistTaps: "handled",
348
+ children: [rules.map(rule => /*#__PURE__*/(0, _jsxRuntime.jsx)(RuleRow, {
349
+ rule: rule,
350
+ spent: isRuleSpent(rule),
351
+ onToggle: () => handleToggle(rule),
352
+ onEdit: () => openRule(rule)
353
+ }, rule.id)), /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, {
354
+ style: styles.footNote,
355
+ children: isPro ? "Dev builds only." : "Dev builds only. Free: one override at a time. Pro: up to 50."
356
+ })]
357
+ })]
358
+ });
359
+ }
360
+ const styles = _reactNative.StyleSheet.create({
361
+ root: {
362
+ flex: 1
363
+ },
364
+ bar: {
365
+ flexDirection: "row",
366
+ alignItems: "center",
367
+ gap: 8,
368
+ paddingHorizontal: 12,
369
+ paddingVertical: 10,
370
+ borderBottomWidth: 1,
371
+ borderBottomColor: _sharedUi.macOSColors.border.default,
372
+ backgroundColor: _sharedUi.macOSColors.background.card
373
+ },
374
+ barOn: {
375
+ borderBottomColor: _sharedUi.macOSColors.semantic.warning + "44",
376
+ backgroundColor: _sharedUi.macOSColors.semantic.warningBackground
377
+ },
378
+ barText: {
379
+ flex: 1,
380
+ fontSize: 12,
381
+ fontWeight: "600",
382
+ color: _sharedUi.macOSColors.text.secondary
383
+ },
384
+ barTextOn: {
385
+ color: _sharedUi.macOSColors.semantic.warning
386
+ },
387
+ barButton: {
388
+ paddingHorizontal: 10,
389
+ paddingVertical: 6,
390
+ borderRadius: 5,
391
+ borderWidth: 1,
392
+ borderColor: _sharedUi.macOSColors.border.hover,
393
+ backgroundColor: _sharedUi.macOSColors.background.base
394
+ },
395
+ barButtonText: {
396
+ fontSize: 11,
397
+ fontWeight: "700",
398
+ color: _sharedUi.macOSColors.text.primary
399
+ },
400
+ listHeader: {
401
+ flexDirection: "row",
402
+ alignItems: "center",
403
+ justifyContent: "space-between",
404
+ paddingHorizontal: 12,
405
+ paddingTop: 10,
406
+ paddingBottom: 4
407
+ },
408
+ listHeaderText: {
409
+ fontSize: 10,
410
+ fontWeight: "700",
411
+ letterSpacing: 0.6,
412
+ color: _sharedUi.macOSColors.text.muted,
413
+ textTransform: "uppercase"
414
+ },
415
+ newButton: {
416
+ padding: 6,
417
+ borderRadius: 5,
418
+ borderWidth: 1,
419
+ borderColor: _sharedUi.macOSColors.border.default,
420
+ backgroundColor: _sharedUi.macOSColors.background.card
421
+ },
422
+ emptyWrap: {
423
+ flex: 1,
424
+ justifyContent: "center"
425
+ },
426
+ list: {
427
+ flex: 1
428
+ },
429
+ listContent: {
430
+ padding: 10,
431
+ gap: 6
432
+ },
433
+ row: {
434
+ flexDirection: "row",
435
+ alignItems: "center",
436
+ gap: 10,
437
+ paddingHorizontal: 10,
438
+ paddingVertical: 10,
439
+ borderRadius: 6,
440
+ borderWidth: 1,
441
+ borderColor: _sharedUi.macOSColors.border.default,
442
+ backgroundColor: _sharedUi.macOSColors.background.card
443
+ },
444
+ toggle: {
445
+ width: 22,
446
+ height: 22,
447
+ borderRadius: 11,
448
+ borderWidth: 1,
449
+ borderColor: _sharedUi.macOSColors.border.default,
450
+ alignItems: "center",
451
+ justifyContent: "center"
452
+ },
453
+ toggleDot: {
454
+ width: 8,
455
+ height: 8,
456
+ borderRadius: 4
457
+ },
458
+ rowBody: {
459
+ flex: 1
460
+ },
461
+ rowTitle: {
462
+ fontSize: 12,
463
+ fontWeight: "600",
464
+ color: _sharedUi.macOSColors.text.primary
465
+ },
466
+ rowTitleOff: {
467
+ color: _sharedUi.macOSColors.text.muted
468
+ },
469
+ rowScope: {
470
+ fontSize: 10,
471
+ fontFamily: "monospace",
472
+ color: _sharedUi.macOSColors.text.secondary,
473
+ marginTop: 2
474
+ },
475
+ rowHits: {
476
+ fontSize: 11,
477
+ fontWeight: "700",
478
+ color: _sharedUi.macOSColors.semantic.warning,
479
+ minWidth: 16,
480
+ textAlign: "right"
481
+ },
482
+ footNote: {
483
+ fontSize: 10,
484
+ lineHeight: 14,
485
+ color: _sharedUi.macOSColors.text.muted,
486
+ paddingHorizontal: 4,
487
+ paddingTop: 8
488
+ }
489
+ });