@buoy-gg/network 7.0.78 → 7.0.79

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 (78) hide show
  1. package/README.md +68 -2
  2. package/lib/commonjs/expo-network.js +1 -0
  3. package/lib/commonjs/index.js +1 -1
  4. package/lib/commonjs/index.web.js +1 -1
  5. package/lib/commonjs/netinfo.js +1 -0
  6. package/lib/commonjs/network/components/NetworkEventDetailView.js +2 -2
  7. package/lib/commonjs/network/components/NetworkEventDetailView.web.js +1 -1
  8. package/lib/commonjs/network/components/NetworkEventItemCompact.js +2 -2
  9. package/lib/commonjs/network/components/NetworkEventItemCompact.web.js +1 -1
  10. package/lib/commonjs/network/components/NetworkModal.js +1 -1
  11. package/lib/commonjs/network/conditions/NetworkConditionsControl.js +1 -1
  12. package/lib/commonjs/network/conditions/NetworkConditionsControl.test.js +1 -1
  13. package/lib/commonjs/network/conditions/NetworkConditionsIcon.js +1 -1
  14. package/lib/commonjs/network/conditions/NetworkFloatingTool.js +1 -1
  15. package/lib/commonjs/network/conditions/NetworkFloatingTool.test.js +1 -1
  16. package/lib/commonjs/network/conditions/connectivity/netInfoFacade.js +1 -0
  17. package/lib/commonjs/network/conditions/connectivity/patchNetwork.js +1 -0
  18. package/lib/commonjs/network/conditions/pacer.js +1 -0
  19. package/lib/commonjs/network/conditions/profiles.js +1 -0
  20. package/lib/commonjs/network/conditions/remoteState.js +1 -0
  21. package/lib/commonjs/network/conditions/store.js +1 -1
  22. package/lib/commonjs/network/conditions/wait.js +1 -1
  23. package/lib/commonjs/network/conditions/xhr.js +1 -1
  24. package/lib/commonjs/network/overrides/engine.js +1 -1
  25. package/lib/commonjs/network/overrides/matchRule.js +1 -1
  26. package/lib/commonjs/network/overrides/overrideRulesStore.js +1 -1
  27. package/lib/commonjs/network/sync/networkSyncAdapter.js +1 -1
  28. package/lib/commonjs/network/utils/generateNetworkCopyText.js +1 -0
  29. package/lib/commonjs/network/utils/networkListener.js +4 -4
  30. package/lib/module/expo-network.js +1 -0
  31. package/lib/module/index.js +1 -1
  32. package/lib/module/index.web.js +1 -1
  33. package/lib/module/netinfo.js +1 -0
  34. package/lib/module/network/components/NetworkEventDetailView.js +2 -2
  35. package/lib/module/network/components/NetworkEventDetailView.web.js +2 -2
  36. package/lib/module/network/components/NetworkEventItemCompact.js +2 -2
  37. package/lib/module/network/components/NetworkEventItemCompact.web.js +1 -1
  38. package/lib/module/network/components/NetworkModal.js +1 -1
  39. package/lib/module/network/conditions/NetworkConditionsControl.js +1 -1
  40. package/lib/module/network/conditions/NetworkConditionsControl.test.js +1 -1
  41. package/lib/module/network/conditions/NetworkConditionsIcon.js +1 -1
  42. package/lib/module/network/conditions/NetworkFloatingTool.js +1 -1
  43. package/lib/module/network/conditions/NetworkFloatingTool.test.js +1 -1
  44. package/lib/module/network/conditions/connectivity/netInfoFacade.js +1 -0
  45. package/lib/module/network/conditions/connectivity/patchNetwork.js +1 -0
  46. package/lib/module/network/conditions/pacer.js +1 -0
  47. package/lib/module/network/conditions/profiles.js +1 -0
  48. package/lib/module/network/conditions/remoteState.js +1 -0
  49. package/lib/module/network/conditions/store.js +1 -1
  50. package/lib/module/network/conditions/wait.js +1 -1
  51. package/lib/module/network/conditions/xhr.js +1 -1
  52. package/lib/module/network/overrides/engine.js +1 -1
  53. package/lib/module/network/overrides/matchRule.js +1 -1
  54. package/lib/module/network/overrides/overrideRulesStore.js +1 -1
  55. package/lib/module/network/sync/networkSyncAdapter.js +1 -1
  56. package/lib/module/network/utils/generateNetworkCopyText.js +23 -22
  57. package/lib/module/network/utils/networkListener.js +4 -4
  58. package/lib/typescript/expo-network.d.ts +2 -0
  59. package/lib/typescript/index.d.ts +3 -2
  60. package/lib/typescript/index.web.d.ts +3 -2
  61. package/lib/typescript/netinfo.d.ts +3 -0
  62. package/lib/typescript/network/conditions/NetworkConditionsControl.d.ts +5 -2
  63. package/lib/typescript/network/conditions/NetworkFloatingTool.d.ts +4 -3
  64. package/lib/typescript/network/conditions/connectivity/netInfoFacade.d.ts +3 -0
  65. package/lib/typescript/network/conditions/connectivity/patchNetwork.d.ts +24 -0
  66. package/lib/typescript/network/conditions/pacer.d.ts +16 -0
  67. package/lib/typescript/network/conditions/profiles.d.ts +57 -0
  68. package/lib/typescript/network/conditions/remoteState.d.ts +4 -0
  69. package/lib/typescript/network/conditions/store.d.ts +45 -19
  70. package/lib/typescript/network/conditions/xhr.d.ts +1 -1
  71. package/lib/typescript/network/overrides/engine.d.ts +14 -0
  72. package/lib/typescript/network/overrides/matchRule.d.ts +3 -0
  73. package/lib/typescript/network/overrides/overrideRulesStore.d.ts +3 -0
  74. package/lib/typescript/network/overrides/types.d.ts +19 -0
  75. package/lib/typescript/network/sync/networkSyncAdapter.d.ts +27 -12
  76. package/lib/typescript/network/utils/networkListener.d.ts +4 -0
  77. package/lib/web/index.mjs +58 -57
  78. package/package.json +26 -3
@@ -1,26 +1,52 @@
1
- export declare const NETWORK_CONDITIONS: {
2
- readonly normal: {
3
- readonly label: "Normal";
4
- readonly delayMs: 0;
5
- };
6
- readonly offline: {
7
- readonly label: "Offline (requests)";
8
- readonly delayMs: 0;
9
- };
10
- readonly slow: {
11
- readonly label: "Slow (+500 ms)";
12
- readonly delayMs: 500;
1
+ import { type NetworkConditionProfile, type NetworkConnection, type NetworkConditionStamp } from "./profiles";
2
+ export { NETWORK_CONDITIONS, CONDITIONS_SCOPE } from "./profiles";
3
+ export type { NetworkConditionProfile, NetworkConnection, NetworkConditionStamp } from "./profiles";
4
+ export interface ConnectionSupport {
5
+ supported: boolean;
6
+ reason?: string;
7
+ }
8
+ declare const connectionSupport: {
9
+ netInfo: ConnectionSupport;
10
+ expoNetwork: ConnectionSupport;
11
+ };
12
+ export declare const getNetworkConnection: () => NetworkConnection;
13
+ export declare const getConditionsRevision: () => number;
14
+ export declare const getEffectiveNetworkConnection: () => "real" | "offline" | "wifi" | "cellular" | "noInternet";
15
+ export declare const networkConditionsActive: () => boolean;
16
+ export declare function setConnectionSupport(key: keyof typeof connectionSupport, value: ConnectionSupport): void;
17
+ export declare function getNetworkConditions(): {
18
+ version: 2;
19
+ runtimeId: string;
20
+ revision: number;
21
+ profile: "offline" | "normal" | "slow" | "verySlow" | "slow3g" | "slow4g" | "fast4g";
22
+ connection: NetworkConnection;
23
+ available: boolean;
24
+ active: boolean;
25
+ delayMs: number;
26
+ downloadBytesPerSecond: number | null;
27
+ uploadBytesPerSecond: number | null;
28
+ capabilities: {
29
+ fetch: string;
30
+ xhr: string;
31
+ upload: string;
32
+ webSocket: boolean;
33
+ nativeImages: boolean;
34
+ nativeModules: boolean;
35
+ netInfo: ConnectionSupport;
36
+ expoNetwork: ConnectionSupport;
13
37
  };
14
- readonly verySlow: {
15
- readonly label: "Very slow (+2000 ms)";
16
- readonly delayMs: 2000;
38
+ scope: {
39
+ download: string;
40
+ upload: string;
41
+ transports: string;
17
42
  };
18
43
  };
19
- export type NetworkConditionProfile = keyof typeof NETWORK_CONDITIONS;
20
- export interface NetworkConditionStamp {
21
- readonly profile: NetworkConditionProfile;
22
- readonly delayMs: number;
44
+ export type NetworkConditionsState = ReturnType<typeof getNetworkConditions>;
45
+ export interface NetworkConditionsChange {
46
+ profile?: NetworkConditionProfile;
47
+ connection?: NetworkConnection;
23
48
  }
49
+ export declare function setNetworkConditions(value?: unknown): NetworkConditionsState;
24
50
  export declare const networkConditionsRuntimeId: string;
25
51
  export declare const conditionsCanApply: () => boolean;
26
52
  export declare const getNetworkCondition: () => NetworkConditionProfile;
@@ -1,5 +1,5 @@
1
1
  import type { OverrideOutcome } from "../overrides/types";
2
2
  import type { NetworkConditionStamp } from "./store";
3
3
  /** Active simulation uses a send-to-completion deadline, including the wait. */
4
- export declare function runConditionXhr(target: XMLHttpRequest, url: string, condition: NetworkConditionStamp, outcome: OverrideOutcome | null, dispatch: () => void): void;
4
+ export declare function runConditionXhr(target: XMLHttpRequest, url: string, condition: NetworkConditionStamp, outcome: OverrideOutcome | null, dispatch: () => void, body?: unknown): void;
5
5
  //# sourceMappingURL=xhr.d.ts.map
@@ -3,6 +3,10 @@ export interface OverrideHooks {
3
3
  getRules: () => readonly OverrideRule[];
4
4
  /** The rule APPLIED to a request. */
5
5
  recordHit: (ruleId: string) => void;
6
+ /** Resolves once saved rules are loaded (a request at app start waits for it). */
7
+ ready?: () => Promise<void>;
8
+ /** True once saved rules are loaded, for callers that can't wait on a promise first. */
9
+ isReady?: () => boolean;
6
10
  /**
7
11
  * The rule MATCHED a request, whether or not it applied.
8
12
  *
@@ -12,6 +16,16 @@ export interface OverrideHooks {
12
16
  recordMatch: (ruleId: string) => void;
13
17
  }
14
18
  export declare function setOverrideHooks(next: OverrideHooks | null): void;
19
+ /**
20
+ * Wait for saved rules before an async request decides. At app start the
21
+ * rules are still loading; a loaded bug case's sandbox would otherwise miss
22
+ * the app's first calls and let them reach real servers.
23
+ */
24
+ export declare function overrideRulesReady(): Promise<void>;
25
+ /** Whether saved rules are loaded yet. */
26
+ export declare function overrideRulesLoaded(): boolean;
27
+ /** Whether any rule reads the request body (a body match or a GraphQL operation). */
28
+ export declare function overrideRulesNeedBody(): boolean;
15
29
  /**
16
30
  * Whether a rule stored right now could ever be applied to a request.
17
31
  *
@@ -17,6 +17,9 @@ import type { OverrideRule } from "./types";
17
17
  */
18
18
  export declare function escapeRegex(pattern: string): string;
19
19
  export declare function compilePattern(pattern: string): RegExp;
20
+ /** A GraphQL JSON body (one operation or a batch) that names `operation`. */
21
+ /** JSON with object keys sorted at every level, so equal values give equal text. */
22
+ export declare function canonicalJson(value: unknown): string;
20
23
  /** Does this rule apply to this request? Ignores `enabled` — callers check it. */
21
24
  export declare function ruleMatches(rule: OverrideRule, url: string, method: string, headers?: Record<string, string>, body?: string): boolean;
22
25
  //# sourceMappingURL=matchRule.d.ts.map
@@ -111,6 +111,8 @@ declare class OverrideRulesStore {
111
111
  * needs no second check.
112
112
  */
113
113
  getRules(): readonly OverrideRule[];
114
+ private sandboxCache;
115
+ private sandboxOnly;
114
116
  /**
115
117
  * The rule's real body, fetching it from the device when this surface only
116
118
  * has the stripped copy (see `OverrideRule.bodyOmitted`).
@@ -172,6 +174,7 @@ declare class OverrideRulesStore {
172
174
  * because a rule has to fire from app boot — with the Network tool closed and
173
175
  * nothing capturing. On the web `loadNow` has usually done it already.
174
176
  */
177
+ isLoaded(): boolean;
175
178
  ensureLoaded(): Promise<void>;
176
179
  /**
177
180
  * Web only: read the saved rules from localStorage right now.
@@ -89,6 +89,25 @@ export interface OverrideRule {
89
89
  * asked first. A body that isn't text (FormData, a Blob) never matches.
90
90
  */
91
91
  bodyIncludes?: string;
92
+ /**
93
+ * Only GraphQL requests whose JSON body names this `operationName` (or a
94
+ * batch that holds it). Parsed, not matched as text, so spacing and key
95
+ * order in the body don't matter.
96
+ */
97
+ graphqlOperation?: string;
98
+ /**
99
+ * With graphqlOperation: only when that operation's `variables` equal this,
100
+ * written as JSON with its keys sorted (see canonicalJson). Parsed, so
101
+ * spacing and key order don't matter. Missing variables count as {}.
102
+ */
103
+ graphqlVariables?: string;
104
+ /**
105
+ * Part of a loaded bug case's sandbox (bug links). Such a rule keeps
106
+ * applying while Buoy's account access is off, because the case's data is
107
+ * in the app either way and must not reach a real server, and it is never
108
+ * auto-paused at launch. Release builds still never apply any rule.
109
+ */
110
+ sandbox?: boolean;
92
111
  kind: OverrideRuleKind;
93
112
  /** `respond` only. Clamped to [STATUS_MIN, STATUS_MAX]. Defaults to 200. */
94
113
  status?: number;
@@ -1,3 +1,4 @@
1
+ import { getNetworkConditions, setNetworkConditions } from "../conditions/store";
1
2
  import type { OverrideRulesState } from "../overrides/overrideRulesStore";
2
3
  import { type OverrideRuleKind } from "../overrides/types";
3
4
  import type { NetworkEvent } from "../types";
@@ -54,10 +55,31 @@ export declare const networkSyncAdapter: {
54
55
  version: number;
55
56
  getSnapshot: () => {
56
57
  conditions: {
57
- version: number;
58
+ version: 2;
58
59
  runtimeId: string;
59
- profile: "normal" | "offline" | "slow" | "verySlow";
60
+ revision: number;
61
+ profile: "offline" | "normal" | "slow" | "verySlow" | "slow3g" | "slow4g" | "fast4g";
62
+ connection: import("../..").NetworkConnection;
60
63
  available: boolean;
64
+ active: boolean;
65
+ delayMs: number;
66
+ downloadBytesPerSecond: number | null;
67
+ uploadBytesPerSecond: number | null;
68
+ capabilities: {
69
+ fetch: string;
70
+ xhr: string;
71
+ upload: string;
72
+ webSocket: boolean;
73
+ nativeImages: boolean;
74
+ nativeModules: boolean;
75
+ netInfo: import("../conditions/store").ConnectionSupport;
76
+ expoNetwork: import("../conditions/store").ConnectionSupport;
77
+ };
78
+ scope: {
79
+ download: string;
80
+ upload: string;
81
+ transports: string;
82
+ };
61
83
  };
62
84
  events: NetworkEvent[];
63
85
  /**
@@ -79,16 +101,8 @@ export declare const networkSyncAdapter: {
79
101
  };
80
102
  subscribe: (onChange: () => void) => () => void;
81
103
  actions: {
82
- getNetworkConditions: () => {
83
- runtimeId: string;
84
- profile: "normal" | "offline" | "slow" | "verySlow";
85
- available: boolean;
86
- };
87
- setNetworkConditions: (params?: unknown) => {
88
- runtimeId: string;
89
- profile: "normal" | "offline" | "slow" | "verySlow";
90
- available: boolean;
91
- };
104
+ getNetworkConditions: typeof getNetworkConditions;
105
+ setNetworkConditions: typeof setNetworkConditions;
92
106
  clearEvents: () => void;
93
107
  /**
94
108
  * Return the full (un-stripped) request/response bodies for one event,
@@ -101,6 +115,7 @@ export declare const networkSyncAdapter: {
101
115
  method: string;
102
116
  status: number | null;
103
117
  override: import("../types").NetworkOverrideMark | null;
118
+ condition: import("../..").NetworkConditionStamp | null;
104
119
  requestData: {} | null;
105
120
  responseData: {} | null;
106
121
  requestHeaders: Record<string, string>;
@@ -170,6 +170,10 @@ declare class NetworkListener {
170
170
  * in flight are emitted when they finish. The recorder stops recording on
171
171
  * the first call, so each request is reported once. See
172
172
  * core/src/earlyNetwork.ts for the record shapes.
173
+ *
174
+ * The recorder sits on a hidden `Symbol.for("buoy.earlyNetwork")` key. An
175
+ * older core only sets `__BUOY_EARLY_NETWORK__`, so that name is read as a
176
+ * fallback. Drop the fallback once no supported core writes only that name.
173
177
  */
174
178
  adoptEarlyRequests(): void;
175
179
  private adoptEarlyFetch;