@buoy-gg/network 7.0.78 → 7.0.80

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 (133) hide show
  1. package/README.md +76 -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 +2 -2
  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/components/sockets/NetworkSocketsButton.js +1 -0
  12. package/lib/commonjs/network/components/sockets/NetworkSocketsScreen.js +1 -0
  13. package/lib/commonjs/network/components/sockets/SocketFrameView.js +1 -0
  14. package/lib/commonjs/network/components/sockets/SocketListView.js +1 -0
  15. package/lib/commonjs/network/components/sockets/SocketRows.js +1 -0
  16. package/lib/commonjs/network/components/sockets/SocketTricksView.js +1 -0
  17. package/lib/commonjs/network/conditions/NetworkConditionsControl.js +1 -1
  18. package/lib/commonjs/network/conditions/NetworkConditionsControl.test.js +1 -1
  19. package/lib/commonjs/network/conditions/NetworkConditionsIcon.js +1 -1
  20. package/lib/commonjs/network/conditions/NetworkFloatingTool.js +1 -1
  21. package/lib/commonjs/network/conditions/NetworkFloatingTool.test.js +1 -1
  22. package/lib/commonjs/network/conditions/connectivity/netInfoFacade.js +1 -0
  23. package/lib/commonjs/network/conditions/connectivity/patchNetwork.js +1 -0
  24. package/lib/commonjs/network/conditions/pacer.js +1 -0
  25. package/lib/commonjs/network/conditions/profiles.js +1 -0
  26. package/lib/commonjs/network/conditions/remoteState.js +1 -0
  27. package/lib/commonjs/network/conditions/store.js +1 -1
  28. package/lib/commonjs/network/conditions/wait.js +1 -1
  29. package/lib/commonjs/network/conditions/xhr.js +1 -1
  30. package/lib/commonjs/network/hooks/useSocketsState.js +1 -0
  31. package/lib/commonjs/network/overrides/engine.js +1 -1
  32. package/lib/commonjs/network/overrides/matchRule.js +1 -1
  33. package/lib/commonjs/network/overrides/overrideRulesStore.js +1 -1
  34. package/lib/commonjs/network/sockets/findProblems.js +1 -0
  35. package/lib/commonjs/network/sockets/foldFrames.js +1 -0
  36. package/lib/commonjs/network/sockets/format.js +1 -0
  37. package/lib/commonjs/network/sockets/readMessage.js +1 -0
  38. package/lib/commonjs/network/sockets/socketMoments.js +1 -0
  39. package/lib/commonjs/network/sockets/socketStore.js +1 -0
  40. package/lib/commonjs/network/sockets/socketsSyncAdapter.js +1 -0
  41. package/lib/commonjs/network/sockets/types.js +1 -0
  42. package/lib/commonjs/network/sockets/webSocketPatch.js +1 -0
  43. package/lib/commonjs/network/sync/networkSyncAdapter.js +1 -1
  44. package/lib/commonjs/network/utils/generateNetworkCopyText.js +1 -0
  45. package/lib/commonjs/network/utils/networkEventStore.js +1 -1
  46. package/lib/commonjs/network/utils/networkListener.js +4 -4
  47. package/lib/commonjs/network/utils/startNetworkCapture.js +1 -1
  48. package/lib/commonjs/preset.js +1 -1
  49. package/lib/module/expo-network.js +1 -0
  50. package/lib/module/index.js +1 -1
  51. package/lib/module/index.web.js +1 -1
  52. package/lib/module/netinfo.js +1 -0
  53. package/lib/module/network/components/NetworkEventDetailView.js +2 -2
  54. package/lib/module/network/components/NetworkEventDetailView.web.js +2 -2
  55. package/lib/module/network/components/NetworkEventItemCompact.js +2 -2
  56. package/lib/module/network/components/NetworkEventItemCompact.web.js +1 -1
  57. package/lib/module/network/components/NetworkModal.js +1 -1
  58. package/lib/module/network/components/sockets/NetworkSocketsButton.js +1 -0
  59. package/lib/module/network/components/sockets/NetworkSocketsScreen.js +1 -0
  60. package/lib/module/network/components/sockets/SocketFrameView.js +1 -0
  61. package/lib/module/network/components/sockets/SocketListView.js +1 -0
  62. package/lib/module/network/components/sockets/SocketRows.js +1 -0
  63. package/lib/module/network/components/sockets/SocketTricksView.js +1 -0
  64. package/lib/module/network/conditions/NetworkConditionsControl.js +1 -1
  65. package/lib/module/network/conditions/NetworkConditionsControl.test.js +1 -1
  66. package/lib/module/network/conditions/NetworkConditionsIcon.js +1 -1
  67. package/lib/module/network/conditions/NetworkFloatingTool.js +1 -1
  68. package/lib/module/network/conditions/NetworkFloatingTool.test.js +1 -1
  69. package/lib/module/network/conditions/connectivity/netInfoFacade.js +1 -0
  70. package/lib/module/network/conditions/connectivity/patchNetwork.js +1 -0
  71. package/lib/module/network/conditions/pacer.js +1 -0
  72. package/lib/module/network/conditions/profiles.js +1 -0
  73. package/lib/module/network/conditions/remoteState.js +1 -0
  74. package/lib/module/network/conditions/store.js +1 -1
  75. package/lib/module/network/conditions/wait.js +1 -1
  76. package/lib/module/network/conditions/xhr.js +1 -1
  77. package/lib/module/network/hooks/useSocketsState.js +1 -0
  78. package/lib/module/network/overrides/engine.js +1 -1
  79. package/lib/module/network/overrides/matchRule.js +1 -1
  80. package/lib/module/network/overrides/overrideRulesStore.js +1 -1
  81. package/lib/module/network/sockets/findProblems.js +1 -0
  82. package/lib/module/network/sockets/foldFrames.js +1 -0
  83. package/lib/module/network/sockets/format.js +1 -0
  84. package/lib/module/network/sockets/readMessage.js +1 -0
  85. package/lib/module/network/sockets/socketMoments.js +1 -0
  86. package/lib/module/network/sockets/socketStore.js +1 -0
  87. package/lib/module/network/sockets/socketsSyncAdapter.js +1 -0
  88. package/lib/module/network/sockets/types.js +1 -0
  89. package/lib/module/network/sockets/webSocketPatch.js +1 -0
  90. package/lib/module/network/sync/networkSyncAdapter.js +1 -1
  91. package/lib/module/network/utils/generateNetworkCopyText.js +23 -22
  92. package/lib/module/network/utils/networkEventStore.js +1 -1
  93. package/lib/module/network/utils/networkListener.js +4 -4
  94. package/lib/module/network/utils/startNetworkCapture.js +1 -1
  95. package/lib/module/preset.js +1 -1
  96. package/lib/typescript/expo-network.d.ts +2 -0
  97. package/lib/typescript/index.d.ts +14 -2
  98. package/lib/typescript/index.web.d.ts +7 -2
  99. package/lib/typescript/netinfo.d.ts +3 -0
  100. package/lib/typescript/network/components/sockets/NetworkSocketsButton.d.ts +17 -0
  101. package/lib/typescript/network/components/sockets/NetworkSocketsScreen.d.ts +19 -0
  102. package/lib/typescript/network/components/sockets/SocketFrameView.d.ts +9 -0
  103. package/lib/typescript/network/components/sockets/SocketListView.d.ts +9 -0
  104. package/lib/typescript/network/components/sockets/SocketRows.d.ts +19 -0
  105. package/lib/typescript/network/components/sockets/SocketTricksView.d.ts +23 -0
  106. package/lib/typescript/network/conditions/NetworkConditionsControl.d.ts +5 -2
  107. package/lib/typescript/network/conditions/NetworkFloatingTool.d.ts +4 -3
  108. package/lib/typescript/network/conditions/connectivity/netInfoFacade.d.ts +3 -0
  109. package/lib/typescript/network/conditions/connectivity/patchNetwork.d.ts +24 -0
  110. package/lib/typescript/network/conditions/pacer.d.ts +16 -0
  111. package/lib/typescript/network/conditions/profiles.d.ts +57 -0
  112. package/lib/typescript/network/conditions/remoteState.d.ts +4 -0
  113. package/lib/typescript/network/conditions/store.d.ts +45 -19
  114. package/lib/typescript/network/conditions/xhr.d.ts +1 -1
  115. package/lib/typescript/network/hooks/useSocketsState.d.ts +3 -0
  116. package/lib/typescript/network/overrides/engine.d.ts +14 -0
  117. package/lib/typescript/network/overrides/matchRule.d.ts +3 -0
  118. package/lib/typescript/network/overrides/overrideRulesStore.d.ts +22 -0
  119. package/lib/typescript/network/overrides/types.d.ts +33 -0
  120. package/lib/typescript/network/sockets/findProblems.d.ts +31 -0
  121. package/lib/typescript/network/sockets/foldFrames.d.ts +50 -0
  122. package/lib/typescript/network/sockets/format.d.ts +19 -0
  123. package/lib/typescript/network/sockets/readMessage.d.ts +41 -0
  124. package/lib/typescript/network/sockets/socketMoments.d.ts +24 -0
  125. package/lib/typescript/network/sockets/socketStore.d.ts +94 -0
  126. package/lib/typescript/network/sockets/socketsSyncAdapter.d.ts +66 -0
  127. package/lib/typescript/network/sockets/types.d.ts +139 -0
  128. package/lib/typescript/network/sockets/webSocketPatch.d.ts +57 -0
  129. package/lib/typescript/network/sync/networkSyncAdapter.d.ts +29 -12
  130. package/lib/typescript/network/types/index.d.ts +6 -0
  131. package/lib/typescript/network/utils/networkListener.d.ts +10 -0
  132. package/lib/web/index.mjs +60 -59
  133. package/package.json +26 -3
@@ -0,0 +1,24 @@
1
+ import type { SocketFrame } from "./types";
2
+ /**
3
+ * The socket moments the Events timeline shows: opened, closed, errored, and
4
+ * messages Buoy faked. Single messages stay in the Sockets screen; a chat app
5
+ * would bury every other tool's events in typing indicators.
6
+ *
7
+ * Shaped like `@buoy-gg/events`' UnifiedEvent without importing it, because
8
+ * Events loads this package, not the other way round (same deal as three's
9
+ * onThreeLoad).
10
+ */
11
+ export interface SocketMoment {
12
+ id: string;
13
+ source: "socket";
14
+ timestamp: number;
15
+ title: string;
16
+ subtitle: string;
17
+ status: "success" | "error" | "pending" | "neutral";
18
+ originalEvent: SocketFrame;
19
+ correlationId: string;
20
+ }
21
+ export declare function toSocketMoment(frame: SocketFrame, url: string): SocketMoment | null;
22
+ /** Follow socket moments as they happen. Returns the unsubscribe. */
23
+ export declare function onSocketMoment(listener: (moment: SocketMoment) => void): () => void;
24
+ //# sourceMappingURL=socketMoments.d.ts.map
@@ -0,0 +1,94 @@
1
+ import { BaseEventStore } from "@buoy-gg/shared-ui";
2
+ import type { SocketAction, SocketActionResult, SocketFrame, SocketsState } from "./types";
3
+ import { type SocketControl, type SocketRecorder } from "./webSocketPatch";
4
+ export declare function isToolingSocket(url: string): boolean;
5
+ /** Desktop: how the mirror reaches the device. */
6
+ export interface SocketsRemote {
7
+ act(action: SocketAction): Promise<SocketActionResult>;
8
+ getFrame(id: string): Promise<{
9
+ frame: SocketFrame;
10
+ partner: SocketFrame | null;
11
+ } | null>;
12
+ }
13
+ declare class SocketStore extends BaseEventStore<SocketFrame> implements SocketRecorder {
14
+ private connections;
15
+ private controls;
16
+ /** Open requests by socket, then by correlation id → frame id and send time. */
17
+ private pending;
18
+ /** Message types that got a reply, per URL. Kept so cut-off frames don't forget them. */
19
+ private answered;
20
+ private socketSeq;
21
+ private frameSeq;
22
+ private blocked;
23
+ private offline;
24
+ private installed;
25
+ private mirror;
26
+ private remote;
27
+ private capturingSince;
28
+ private mirrored;
29
+ private cache;
30
+ private version;
31
+ private recheck;
32
+ private retryOnAccess;
33
+ constructor();
34
+ /**
35
+ * Install the WebSocket wrapper. Called at import in a React Native dev
36
+ * build (see preset.tsx), and on first subscribe elsewhere. Never in mirror
37
+ * mode: Desktop must not watch its own sockets.
38
+ */
39
+ install(): boolean;
40
+ protected startCapturing(): void;
41
+ /** The wrapper stays installed; there is nothing to stop. */
42
+ protected stopCapturing(): void;
43
+ isCapturing(): boolean;
44
+ disableCapture(): void;
45
+ /** Tell listeners something besides the frame list changed (a connection, a test switch). */
46
+ private bump;
47
+ private nextFrameId;
48
+ private setConnection;
49
+ private push;
50
+ register(url: string, protocols: string[] | undefined, control: SocketControl): string | null;
51
+ private trimConnections;
52
+ open(socketId: string): void;
53
+ close(socketId: string, code: number | undefined, reason: string | undefined, byBuoy: boolean): void;
54
+ error(socketId: string): void;
55
+ message(socketId: string, direction: "in" | "out", raw: unknown, flags?: {
56
+ fake?: "inject" | "send";
57
+ held?: boolean;
58
+ sentWhileClosed?: boolean;
59
+ }): string | undefined;
60
+ /** Learn that a type gets replies, with caps: oldest URL and oldest type go first. */
61
+ private rememberAnswered;
62
+ /**
63
+ * Wake when the next open request's wait is over, so "no reply" shows on
64
+ * time even if nothing else happens, and again when it is too old to pair,
65
+ * so it is forgotten: a message with an `id` that never gets an answer (a
66
+ * one-way event) must not keep memory forever. Stops when none are left.
67
+ */
68
+ private scheduleRecheck;
69
+ cutOff(): string | null;
70
+ isFrozen(socketId: string): boolean;
71
+ /** Network's offline mode reaches sockets too: open ones drop, new ones fail. */
72
+ private syncOffline;
73
+ getState(): SocketsState;
74
+ getFrame(id: string): SocketFrame | undefined;
75
+ /** Subscribe to every change: frames, connections, tests. Returns unsubscribe. */
76
+ subscribeState(listener: () => void): () => void;
77
+ /** Desktop: send actions to the device instead of running them here. */
78
+ setRemote(remote: SocketsRemote | null): void;
79
+ /** One whole frame and its reply or request. On Desktop it comes from the device. */
80
+ loadFrame(id: string): Promise<{
81
+ frame: SocketFrame;
82
+ partner: SocketFrame | null;
83
+ } | null>;
84
+ /** Desktop: show the device's state. */
85
+ applySnapshot(state: SocketsState | null): void;
86
+ act(action: SocketAction): Promise<SocketActionResult>;
87
+ actLocal(action: SocketAction): SocketActionResult;
88
+ clearEvents(): void;
89
+ protected notifyArrayListeners(): void;
90
+ }
91
+ /** Singleton: every socket the app opens, and what Buoy is doing to them. */
92
+ export declare const socketStore: SocketStore;
93
+ export {};
94
+ //# sourceMappingURL=socketStore.d.ts.map
@@ -0,0 +1,66 @@
1
+ import type { SocketFrame, SocketsState } from "./types";
2
+ /**
3
+ * External-sync adapter for the Sockets screen, under its own `sockets` key.
4
+ *
5
+ * Its own key, not part of `network`'s snapshot: a chat app sends messages all
6
+ * day, and every message would otherwise re-send the HTTP list (and its 1.25 MB
7
+ * budget) with it. Split, a busy socket only re-sends the socket snapshot.
8
+ *
9
+ * The snapshot carries the newest SNAPSHOT_FRAMES frames with short text, for
10
+ * Desktop's list. Whole messages and the full history come from actions:
11
+ * `getFrame` for one, `query` for a filtered page (what the MCP uses).
12
+ */
13
+ export declare const SNAPSHOT_FRAMES = 300;
14
+ /** Text kept per frame in the snapshot. The rest is fetched by `getFrame`. */
15
+ export declare const SNAPSHOT_TEXT = 1000;
16
+ /** With bodies, a list still cuts each one here: 50 big messages would flood an agent. `frameId` gets one whole. */
17
+ export declare const LIST_BODY_TEXT = 4000;
18
+ export interface SocketQuery {
19
+ socketId?: string;
20
+ frameId?: string;
21
+ /** `chat.*` matches by prefix; anything else matches part of the name. */
22
+ type?: string;
23
+ direction?: "in" | "out" | "lifecycle";
24
+ /** Only frames that are part of a problem. */
25
+ problems?: boolean;
26
+ /** Only frames at or after this time (ms since epoch). */
27
+ since?: number;
28
+ limit?: number;
29
+ includeBodies?: boolean;
30
+ includePings?: boolean;
31
+ }
32
+ export declare function matchesType(type: string | undefined, pattern: string): boolean;
33
+ export declare function querySockets(state: SocketsState, q?: SocketQuery): {
34
+ connections: import("./types").SocketConnection[];
35
+ problems: import("./types").SocketProblem[];
36
+ tests: import("./types").SocketTestState;
37
+ capturingSince: number | null;
38
+ frames: SocketFrame[];
39
+ total: number;
40
+ flagged: string[];
41
+ };
42
+ export declare const socketsSyncAdapter: {
43
+ version: number;
44
+ getSnapshot: () => SocketsState;
45
+ subscribe: (onChange: () => void) => () => void;
46
+ actions: {
47
+ /** One whole frame, with its reply or request beside it. */
48
+ getFrame: (params?: unknown) => {
49
+ frame: SocketFrame;
50
+ partner: SocketFrame | null;
51
+ } | null;
52
+ /** A filtered page of frames plus every socket and problem. See SocketQuery. */
53
+ query: (params?: unknown) => {
54
+ connections: import("./types").SocketConnection[];
55
+ problems: import("./types").SocketProblem[];
56
+ tests: import("./types").SocketTestState;
57
+ capturingSince: number | null;
58
+ frames: SocketFrame[];
59
+ total: number;
60
+ flagged: string[];
61
+ };
62
+ /** inject | send | close | freeze | block | reset | clear. Says what really happened. */
63
+ act: (params?: unknown) => import("./types").SocketActionResult;
64
+ };
65
+ };
66
+ //# sourceMappingURL=socketsSyncAdapter.d.ts.map
@@ -0,0 +1,139 @@
1
+ /**
2
+ * Socket capture types — the Sockets screen of the Network tool.
3
+ *
4
+ * One list holds everything that happened on every socket, newest first:
5
+ * messages both ways AND the open/close/error moments, so a reconnect shows up
6
+ * between the messages around it instead of on a separate screen.
7
+ */
8
+ export type SocketState = "connecting" | "open" | "closing" | "closed";
9
+ export interface SocketConnection {
10
+ /** `s1`, `s2`, ... in the order the app created them. */
11
+ id: string;
12
+ /** The URL with secret query values hidden (`?token=[hidden]`). */
13
+ url: string;
14
+ protocols?: string[];
15
+ /** Nth socket this app made to the same URL (its path, query ignored). 1 = first. */
16
+ attempt: number;
17
+ state: SocketState;
18
+ createdAt: number;
19
+ openedAt?: number;
20
+ closedAt?: number;
21
+ closeCode?: number;
22
+ closeReason?: string;
23
+ /** Buoy closed it (Drop / Kick out / offline), not the app or the server. */
24
+ closedByBuoy?: boolean;
25
+ /** Freeze is on: messages both ways are held back while it still looks open. */
26
+ frozen?: boolean;
27
+ sent: number;
28
+ received: number;
29
+ bytesSent: number;
30
+ bytesReceived: number;
31
+ /** Heartbeat messages, counted here and folded out of the list. */
32
+ pings: number;
33
+ lastMessageAt?: number;
34
+ }
35
+ export type SocketFrameKind = "message" | "open" | "close" | "error";
36
+ export interface SocketFrame {
37
+ /** `f1`, `f2`, ... unique for this app run. */
38
+ id: string;
39
+ socketId: string;
40
+ kind: SocketFrameKind;
41
+ timestamp: number;
42
+ /** Messages only: `out` = the app sent it, `in` = the app got it. */
43
+ direction?: "in" | "out";
44
+ /** The message as text, secrets hidden, cut at MAX_FRAME_CHARS. Binary shows as a short note. */
45
+ data?: string;
46
+ /** Length of the original message in bytes (or characters for text). */
47
+ size?: number;
48
+ binary?: boolean;
49
+ /** `data` was cut at MAX_FRAME_CHARS when captured: the rest is gone. */
50
+ truncated?: boolean;
51
+ /** `data` is a short preview for a list. `getFrame` has the whole text. */
52
+ dataCut?: boolean;
53
+ /** `data` is JSON. */
54
+ json?: boolean;
55
+ /** The message's name, read from `type`, `event`, `op`, `action` or `method`. */
56
+ type?: string;
57
+ /** The id that ties a request to its reply: `requestId`, `id`, `ref`, ... */
58
+ correlationId?: string;
59
+ /** A heartbeat (`ping`, `pong`, `heartbeat`, engine.io `2`/`3`). */
60
+ ping?: boolean;
61
+ /** Buoy made this message: `inject` = pushed into the app, `send` = sent to the server. */
62
+ fake?: "inject" | "send";
63
+ /** Held back by Freeze, Block or offline mode: the other side never got it. */
64
+ held?: boolean;
65
+ /** The app sent this while the socket was not open. */
66
+ sentWhileClosed?: boolean;
67
+ /** For a request: the id of its reply, and how long the reply took. */
68
+ replyId?: string;
69
+ replyMs?: number;
70
+ /** For a reply: the id of the request it answers. */
71
+ replyTo?: string;
72
+ /** close / error */
73
+ code?: number;
74
+ reason?: string;
75
+ byBuoy?: boolean;
76
+ /** close: the socket never opened (refused, bad response, no server). */
77
+ neverOpened?: boolean;
78
+ }
79
+ export type SocketProblemKind = "no-reply" | "reconnect-storm" | "auth-loop" | "cant-connect" | "two-sockets" | "sent-while-closed";
80
+ export interface SocketProblem {
81
+ kind: SocketProblemKind;
82
+ /** Plain words, ready for a row, a chip or an agent. */
83
+ message: string;
84
+ socketId?: string;
85
+ url?: string;
86
+ /** The frames that prove it. */
87
+ frameIds: string[];
88
+ at: number;
89
+ }
90
+ /** What Buoy is doing to sockets right now — every one of these is fake behavior. */
91
+ export interface SocketTestState {
92
+ /** New sockets fail at once, like a server that is down. */
93
+ blocked: boolean;
94
+ /** Network's offline mode is on, so sockets act offline too. */
95
+ offline: boolean;
96
+ /** Sockets with Freeze on. */
97
+ frozen: string[];
98
+ }
99
+ export interface SocketsState {
100
+ connections: SocketConnection[];
101
+ frames: SocketFrame[];
102
+ problems: SocketProblem[];
103
+ tests: SocketTestState;
104
+ /** When capture began. Sockets opened before this are not seen. */
105
+ capturingSince: number | null;
106
+ }
107
+ /** What the Tricks screen, Desktop and the MCP can do. */
108
+ export type SocketAction = {
109
+ action: "inject";
110
+ socketId: string;
111
+ data: string;
112
+ } | {
113
+ action: "send";
114
+ socketId: string;
115
+ data: string;
116
+ } | {
117
+ action: "close";
118
+ socketId: string;
119
+ code?: number;
120
+ reason?: string;
121
+ } | {
122
+ action: "freeze";
123
+ socketId: string;
124
+ frozen: boolean;
125
+ } | {
126
+ action: "block";
127
+ blocked: boolean;
128
+ } | {
129
+ action: "reset";
130
+ } | {
131
+ action: "clear";
132
+ };
133
+ export interface SocketActionResult {
134
+ ok: boolean;
135
+ /** What really happened, in plain words. */
136
+ message: string;
137
+ frameId?: string;
138
+ }
139
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1,57 @@
1
+ /**
2
+ * The WebSocket wrapper behind the Sockets screen.
3
+ *
4
+ * `globalThis.WebSocket` is replaced by a subclass, so every socket the app
5
+ * makes after this runs is seen with no setup. The subclass is still a real
6
+ * WebSocket (`instanceof` holds, the constants are inherited), and it talks to
7
+ * the network through the real one.
8
+ *
9
+ * WHY THE APP'S HANDLERS ARE KEPT HERE. To push a fake message into the app,
10
+ * freeze a socket, or fake a 1006 close, Buoy has to decide what reaches the
11
+ * app's own `onmessage`/`addEventListener` code. So the wrapper keeps the
12
+ * app's handlers in its own list and registers ONE listener per event with the
13
+ * real socket. That listener records the event, then hands it to the app's
14
+ * handlers unless a test is holding it back. React Native's WebSocket and the
15
+ * browser's both deliver through those listeners, so one path covers both.
16
+ *
17
+ * Fake closes: a browser refuses `close(1006)`, and Android ignores `close()`
18
+ * before the socket opens. So Buoy gives the app the close it asked for right
19
+ * away, closes the real socket with its own code, and hides the real close
20
+ * when it comes later.
21
+ */
22
+ interface MessageFlags {
23
+ fake?: "inject" | "send";
24
+ held?: boolean;
25
+ sentWhileClosed?: boolean;
26
+ }
27
+ /** What the store learns from a socket. Implemented by socketStore. */
28
+ export interface SocketRecorder {
29
+ /** null = don't track this socket (Buoy's own, Metro's, or capture is off). */
30
+ register(url: string, protocols: string[] | undefined, control: SocketControl): string | null;
31
+ open(socketId: string): void;
32
+ message(socketId: string, direction: "in" | "out", raw: unknown, flags?: MessageFlags): string | undefined;
33
+ close(socketId: string, code: number | undefined, reason: string | undefined, byBuoy: boolean): void;
34
+ error(socketId: string): void;
35
+ /** Why new sockets fail and messages are held (block or offline), or null. */
36
+ cutOff(): string | null;
37
+ isFrozen(socketId: string): boolean;
38
+ }
39
+ /** What the store can do to one socket. */
40
+ export interface SocketControl {
41
+ /** Hand the app a message as if the server sent it. */
42
+ inject(data: string): string | undefined;
43
+ /** Send a message to the server. */
44
+ send(data: string): string | undefined;
45
+ /** Close as if the network (1006) or the server (1008, ...) did it. */
46
+ fakeClose(code: number, reason: string): void;
47
+ isOpen(): boolean;
48
+ }
49
+ /** Whether the wrapper is installed in this runtime. */
50
+ export declare function isWebSocketPatched(): boolean;
51
+ /**
52
+ * Install the wrapper once. Returns false when there is no WebSocket here or
53
+ * it is already installed.
54
+ */
55
+ export declare function installWebSocketPatch(recorder: SocketRecorder): boolean;
56
+ export {};
57
+ //# sourceMappingURL=webSocketPatch.d.ts.map
@@ -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: string;
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>;
@@ -224,11 +239,13 @@ export declare const networkSyncAdapter: {
224
239
  ok: boolean;
225
240
  count: number;
226
241
  enabled: boolean;
242
+ saved: boolean;
227
243
  error?: undefined;
228
244
  } | {
229
245
  ok: boolean;
230
246
  count: number;
231
247
  enabled: boolean;
248
+ saved: boolean;
232
249
  error?: undefined;
233
250
  }>;
234
251
  /**
@@ -40,6 +40,12 @@ export interface NetworkEvent {
40
40
  responseHeaders: Record<string, string>;
41
41
  requestData?: unknown;
42
42
  responseData?: unknown;
43
+ /** `responseData` was parsed from JSON text (so a string was a JSON string). */
44
+ responseJson?: boolean;
45
+ /** `responseData` was cut at the size cap (or left out as too large): not the real answer. */
46
+ responseTruncated?: boolean;
47
+ /** `responseData` wasn't read (still streaming, or unreadable): a placeholder. */
48
+ responseUnread?: boolean;
43
49
  responseSize?: number;
44
50
  requestSize?: number;
45
51
  timestamp: number;
@@ -27,6 +27,12 @@ export interface NetworkingEvent {
27
27
  headers?: Record<string, string>;
28
28
  body?: unknown;
29
29
  size?: number;
30
+ /** The body was parsed from JSON text (so a string body was a JSON string). */
31
+ json?: boolean;
32
+ /** The body was cut at the size cap (or left out as too large): not the real answer. */
33
+ truncated?: boolean;
34
+ /** The body wasn't read (still streaming, or unreadable): what's there is a placeholder. */
35
+ unread?: boolean;
30
36
  };
31
37
  error?: {
32
38
  message: string;
@@ -170,6 +176,10 @@ declare class NetworkListener {
170
176
  * in flight are emitted when they finish. The recorder stops recording on
171
177
  * the first call, so each request is reported once. See
172
178
  * core/src/earlyNetwork.ts for the record shapes.
179
+ *
180
+ * The recorder sits on a hidden `Symbol.for("buoy.earlyNetwork")` key. An
181
+ * older core only sets `__BUOY_EARLY_NETWORK__`, so that name is read as a
182
+ * fallback. Drop the fallback once no supported core writes only that name.
173
183
  */
174
184
  adoptEarlyRequests(): void;
175
185
  private adoptEarlyFetch;