@rnzeus/heimdall-sdk 0.0.0-stage → 0.2.3

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 (223) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +210 -2
  3. package/dist/core/cloud/client.d.ts +44 -0
  4. package/dist/core/cloud/client.js +65 -0
  5. package/dist/core/cloud/index.d.ts +4 -0
  6. package/dist/core/cloud/index.js +4 -0
  7. package/dist/core/cloud/link-device.d.ts +14 -0
  8. package/dist/core/cloud/link-device.js +28 -0
  9. package/dist/core/cloud/state.d.ts +10 -0
  10. package/dist/core/cloud/state.js +21 -0
  11. package/dist/core/cloud/storage.d.ts +7 -0
  12. package/dist/core/cloud/storage.js +31 -0
  13. package/dist/core/connection/channel/generate.d.ts +10 -0
  14. package/dist/core/connection/channel/generate.js +22 -0
  15. package/dist/core/connection/channel/index.d.ts +4 -0
  16. package/dist/core/connection/channel/index.js +4 -0
  17. package/dist/core/connection/channel/parse.d.ts +9 -0
  18. package/dist/core/connection/channel/parse.js +27 -0
  19. package/dist/core/connection/channel/sanitize.d.ts +9 -0
  20. package/dist/core/connection/channel/sanitize.js +15 -0
  21. package/dist/core/connection/channel/types.d.ts +9 -0
  22. package/dist/core/connection/channel/types.js +1 -0
  23. package/dist/core/connection/index.d.ts +7 -0
  24. package/dist/core/connection/index.js +7 -0
  25. package/dist/core/connection/lifecycle/connect.d.ts +2 -0
  26. package/dist/core/connection/lifecycle/connect.js +46 -0
  27. package/dist/core/connection/lifecycle/destroy.d.ts +1 -0
  28. package/dist/core/connection/lifecycle/destroy.js +12 -0
  29. package/dist/core/connection/lifecycle/disconnect.d.ts +1 -0
  30. package/dist/core/connection/lifecycle/disconnect.js +10 -0
  31. package/dist/core/connection/lifecycle/early-events.d.ts +2 -0
  32. package/dist/core/connection/lifecycle/early-events.js +18 -0
  33. package/dist/core/connection/lifecycle/index.d.ts +5 -0
  34. package/dist/core/connection/lifecycle/index.js +5 -0
  35. package/dist/core/connection/lifecycle/keep-alive.d.ts +5 -0
  36. package/dist/core/connection/lifecycle/keep-alive.js +40 -0
  37. package/dist/core/connection/prompt/index.d.ts +1 -0
  38. package/dist/core/connection/prompt/index.js +1 -0
  39. package/dist/core/connection/prompt/prompt-state.d.ts +12 -0
  40. package/dist/core/connection/prompt/prompt-state.js +30 -0
  41. package/dist/core/connection/resolver/cloud.d.ts +4 -0
  42. package/dist/core/connection/resolver/cloud.js +29 -0
  43. package/dist/core/connection/resolver/index.d.ts +3 -0
  44. package/dist/core/connection/resolver/index.js +3 -0
  45. package/dist/core/connection/resolver/manual.d.ts +2 -0
  46. package/dist/core/connection/resolver/manual.js +3 -0
  47. package/dist/core/connection/resolver/types.d.ts +9 -0
  48. package/dist/core/connection/resolver/types.js +1 -0
  49. package/dist/core/connection/sdk-enabled.d.ts +3 -0
  50. package/dist/core/connection/sdk-enabled.js +10 -0
  51. package/dist/core/connection/session/clear-last-connection.d.ts +1 -0
  52. package/dist/core/connection/session/clear-last-connection.js +11 -0
  53. package/dist/core/connection/session/client-id.d.ts +3 -0
  54. package/dist/core/connection/session/client-id.js +25 -0
  55. package/dist/core/connection/session/constants.d.ts +14 -0
  56. package/dist/core/connection/session/constants.js +21 -0
  57. package/dist/core/connection/session/create-session.d.ts +3 -0
  58. package/dist/core/connection/session/create-session.js +21 -0
  59. package/dist/core/connection/session/index.d.ts +6 -0
  60. package/dist/core/connection/session/index.js +6 -0
  61. package/dist/core/connection/session/load-last-connection.d.ts +2 -0
  62. package/dist/core/connection/session/load-last-connection.js +16 -0
  63. package/dist/core/connection/session/state.d.ts +7 -0
  64. package/dist/core/connection/session/state.js +23 -0
  65. package/dist/core/connection/session/types.d.ts +12 -0
  66. package/dist/core/connection/session/types.js +1 -0
  67. package/dist/core/connection/socket/connect-socket.d.ts +3 -0
  68. package/dist/core/connection/socket/connect-socket.js +110 -0
  69. package/dist/core/connection/socket/constants.d.ts +4 -0
  70. package/dist/core/connection/socket/constants.js +4 -0
  71. package/dist/core/connection/socket/destroy-socket.d.ts +1 -0
  72. package/dist/core/connection/socket/destroy-socket.js +4 -0
  73. package/dist/core/connection/socket/disconnect-socket.d.ts +1 -0
  74. package/dist/core/connection/socket/disconnect-socket.js +26 -0
  75. package/dist/core/connection/socket/early-buffer.d.ts +7 -0
  76. package/dist/core/connection/socket/early-buffer.js +26 -0
  77. package/dist/core/connection/socket/flush-early-events.d.ts +1 -0
  78. package/dist/core/connection/socket/flush-early-events.js +18 -0
  79. package/dist/core/connection/socket/handle-socket-lost.d.ts +1 -0
  80. package/dist/core/connection/socket/handle-socket-lost.js +24 -0
  81. package/dist/core/connection/socket/index.d.ts +6 -0
  82. package/dist/core/connection/socket/index.js +6 -0
  83. package/dist/core/connection/socket/normalize-socket-error.d.ts +1 -0
  84. package/dist/core/connection/socket/normalize-socket-error.js +13 -0
  85. package/dist/core/connection/socket/send-event.d.ts +3 -0
  86. package/dist/core/connection/socket/send-event.js +45 -0
  87. package/dist/core/connection/socket/state.d.ts +8 -0
  88. package/dist/core/connection/socket/state.js +35 -0
  89. package/dist/core/console/index.d.ts +2 -0
  90. package/dist/core/console/index.js +2 -0
  91. package/dist/core/console/patch-console.d.ts +1 -0
  92. package/dist/core/console/patch-console.js +64 -0
  93. package/dist/core/console/restore-console.d.ts +1 -0
  94. package/dist/core/console/restore-console.js +28 -0
  95. package/dist/core/console/send-console-event.d.ts +8 -0
  96. package/dist/core/console/send-console-event.js +95 -0
  97. package/dist/core/console/state.d.ts +19 -0
  98. package/dist/core/console/state.js +25 -0
  99. package/dist/core/mmkv/index.d.ts +0 -0
  100. package/dist/core/mmkv/index.js +2 -0
  101. package/dist/core/network/get-interceptor.d.ts +11 -0
  102. package/dist/core/network/get-interceptor.js +19 -0
  103. package/dist/core/network/headers.d.ts +6 -0
  104. package/dist/core/network/headers.js +46 -0
  105. package/dist/core/network/index.d.ts +2 -0
  106. package/dist/core/network/index.js +2 -0
  107. package/dist/core/network/patch-xhr.d.ts +2 -0
  108. package/dist/core/network/patch-xhr.js +40 -0
  109. package/dist/core/network/restore-xhr.d.ts +1 -0
  110. package/dist/core/network/restore-xhr.js +40 -0
  111. package/dist/core/network/rn-blob.d.ts +1 -0
  112. package/dist/core/network/rn-blob.js +15 -0
  113. package/dist/core/network/should-skip.d.ts +2 -0
  114. package/dist/core/network/should-skip.js +30 -0
  115. package/dist/core/network/state.d.ts +5 -0
  116. package/dist/core/network/state.js +14 -0
  117. package/dist/core/network/xhr-callbacks.d.ts +12 -0
  118. package/dist/core/network/xhr-callbacks.js +169 -0
  119. package/dist/core/network/xhr-runtime-state.d.ts +4 -0
  120. package/dist/core/network/xhr-runtime-state.js +15 -0
  121. package/dist/core/network/xhr-types.d.ts +33 -0
  122. package/dist/core/network/xhr-types.js +1 -0
  123. package/dist/core/public.d.ts +2 -0
  124. package/dist/core/public.js +1 -0
  125. package/dist/core/react-query/index.d.ts +0 -0
  126. package/dist/core/react-query/index.js +2 -0
  127. package/dist/core/system/dev-server.d.ts +6 -0
  128. package/dist/core/system/dev-server.js +37 -0
  129. package/dist/core/system/device-info.d.ts +3 -0
  130. package/dist/core/system/device-info.js +46 -0
  131. package/dist/core/system/index.d.ts +2 -0
  132. package/dist/core/system/index.js +2 -0
  133. package/dist/core/websocket/index.d.ts +2 -0
  134. package/dist/core/websocket/index.js +2 -0
  135. package/dist/core/websocket/patch-websocket.d.ts +2 -0
  136. package/dist/core/websocket/patch-websocket.js +247 -0
  137. package/dist/core/websocket/restore-websocket.d.ts +1 -0
  138. package/dist/core/websocket/restore-websocket.js +16 -0
  139. package/dist/core/websocket/should-skip.d.ts +2 -0
  140. package/dist/core/websocket/should-skip.js +22 -0
  141. package/dist/core/websocket/state.d.ts +9 -0
  142. package/dist/core/websocket/state.js +21 -0
  143. package/dist/core/zustand/index.d.ts +1 -0
  144. package/dist/core/zustand/index.js +1 -0
  145. package/dist/index.d.ts +3 -0
  146. package/dist/index.js +3 -0
  147. package/dist/public/copy-button/component.d.ts +9 -0
  148. package/dist/public/copy-button/component.js +13 -0
  149. package/dist/public/copy-button/index.d.ts +1 -0
  150. package/dist/public/copy-button/index.js +1 -0
  151. package/dist/public/copy-button/styles.d.ts +64 -0
  152. package/dist/public/copy-button/styles.js +52 -0
  153. package/dist/public/index.d.ts +1 -0
  154. package/dist/public/index.js +1 -0
  155. package/dist/public/prompt/component.d.ts +7 -0
  156. package/dist/public/prompt/component.js +56 -0
  157. package/dist/public/prompt/index.d.ts +1 -0
  158. package/dist/public/prompt/index.js +1 -0
  159. package/dist/public/prompt/prompt-mode.d.ts +3 -0
  160. package/dist/public/prompt/prompt-mode.js +19 -0
  161. package/dist/public/prompt/styles.d.ts +23 -0
  162. package/dist/public/prompt/styles.js +23 -0
  163. package/dist/public/prompt/theme.d.ts +16 -0
  164. package/dist/public/prompt/theme.js +32 -0
  165. package/dist/public/prompt/types.d.ts +12 -0
  166. package/dist/public/prompt/types.js +1 -0
  167. package/dist/public/prompt/ui/action-button.d.ts +11 -0
  168. package/dist/public/prompt/ui/action-button.js +23 -0
  169. package/dist/public/prompt/ui/footer.d.ts +7 -0
  170. package/dist/public/prompt/ui/footer.js +13 -0
  171. package/dist/public/prompt/ui/header.d.ts +10 -0
  172. package/dist/public/prompt/ui/header.js +17 -0
  173. package/dist/public/prompt/ui/report-link.d.ts +8 -0
  174. package/dist/public/prompt/ui/report-link.js +19 -0
  175. package/dist/public/prompt/use-connect-awaiter.d.ts +11 -0
  176. package/dist/public/prompt/use-connect-awaiter.js +45 -0
  177. package/dist/public/prompt/use-prompt-animation.d.ts +17 -0
  178. package/dist/public/prompt/use-prompt-animation.js +53 -0
  179. package/dist/public/prompt/use-prompt-ui.d.ts +3 -0
  180. package/dist/public/prompt/use-prompt-ui.js +99 -0
  181. package/dist/public/prompt/use-prompt.d.ts +11 -0
  182. package/dist/public/prompt/use-prompt.js +43 -0
  183. package/dist/public/prompt/views/cloud-view.d.ts +13 -0
  184. package/dist/public/prompt/views/cloud-view.js +19 -0
  185. package/dist/public/prompt/views/connected-view.d.ts +14 -0
  186. package/dist/public/prompt/views/connected-view.js +9 -0
  187. package/dist/public/prompt/views/manual-view.d.ts +16 -0
  188. package/dist/public/prompt/views/manual-view.js +21 -0
  189. package/dist/public/prompt/views/styles.d.ts +44 -0
  190. package/dist/public/prompt/views/styles.js +23 -0
  191. package/dist/public/prompt/views/use-cloud-view.d.ts +15 -0
  192. package/dist/public/prompt/views/use-cloud-view.js +103 -0
  193. package/dist/public/public.d.ts +1 -0
  194. package/dist/public/public.js +1 -0
  195. package/dist/types/index.d.ts +2 -0
  196. package/dist/types/index.js +2 -0
  197. package/dist/types/options.d.ts +30 -0
  198. package/dist/types/options.js +1 -0
  199. package/dist/types/protocol.d.ts +1 -0
  200. package/dist/types/protocol.js +1 -0
  201. package/dist/types/public.d.ts +1 -0
  202. package/dist/types/public.js +1 -0
  203. package/dist/utils/body-snippet.d.ts +19 -0
  204. package/dist/utils/body-snippet.js +186 -0
  205. package/dist/utils/debug-log.d.ts +26 -0
  206. package/dist/utils/debug-log.js +44 -0
  207. package/dist/utils/generate-random-id.d.ts +1 -0
  208. package/dist/utils/generate-random-id.js +8 -0
  209. package/dist/utils/index.d.ts +5 -0
  210. package/dist/utils/index.js +5 -0
  211. package/dist/utils/parse-url.d.ts +5 -0
  212. package/dist/utils/parse-url.js +32 -0
  213. package/dist/utils/safe-serialize.d.ts +6 -0
  214. package/dist/utils/safe-serialize.js +77 -0
  215. package/dist/version.d.ts +1 -0
  216. package/dist/version.js +1 -0
  217. package/dist/zustand/index.d.ts +1 -0
  218. package/dist/zustand/index.js +1 -0
  219. package/dist/zustand/middleware.d.ts +18 -0
  220. package/dist/zustand/middleware.js +77 -0
  221. package/package.json +88 -4
  222. package/zustand/index.d.ts +1 -0
  223. package/zustand/index.js +1 -0
@@ -0,0 +1,247 @@
1
+ import { generateRandomId, parseUrl } from "../../utils/index.js";
2
+ import { sendEvent } from "../connection/index.js";
3
+ import { buildBodySnippet, debugLog, tryMinifyJsonString } from "../../utils/index.js";
4
+ import { getWsFilters, getOriginalWebSocket, isWsPatched, setOriginalWebSocket, setWsFilters, setWsPatched, } from "./state.js";
5
+ import { shouldSkipWs } from "./should-skip.js";
6
+ const wsMeta = new WeakMap();
7
+ function now() {
8
+ return Date.now();
9
+ }
10
+ function previewString(s, max = 200) {
11
+ const out = s.length > max ? s.slice(0, max) + "…" : s;
12
+ return out.replace(/\s+/g, " ");
13
+ }
14
+ function looksLikeJsonText(s) {
15
+ const t = s.trim();
16
+ return t.startsWith("{") || t.startsWith("[");
17
+ }
18
+ function guessContentType(data) {
19
+ if (typeof data === "string") {
20
+ if (!looksLikeJsonText(data))
21
+ return "text/plain";
22
+ // Only mark as JSON if it's actually valid JSON (otherwise JSON viewers will fail).
23
+ // Also avoid JSON.parse on huge frames.
24
+ if (data.length > 1000000)
25
+ return "text/plain";
26
+ return tryMinifyJsonString(data) ? "application/json" : "text/plain";
27
+ }
28
+ return undefined;
29
+ }
30
+ function buildWsFrame(meta, direction, data) {
31
+ // Default path: treat as text if string, else describe as binary/unknown.
32
+ if (typeof data === "string") {
33
+ const ct = guessContentType(data);
34
+ const r = buildBodySnippet(data, { contentType: ct });
35
+ return {
36
+ direction,
37
+ dataSnippet: r.snippet,
38
+ dataSnippetBytes: r.snippetBytes,
39
+ dataTruncated: r.truncated,
40
+ dataSize: r.sizeBytes,
41
+ dataContentType: ct,
42
+ };
43
+ }
44
+ // ArrayBuffer / TypedArray
45
+ const byteLen = data instanceof ArrayBuffer
46
+ ? data.byteLength
47
+ : ArrayBuffer.isView(data)
48
+ ? data.byteLength
49
+ : undefined;
50
+ if (typeof byteLen === "number") {
51
+ const snippet = `[binary ${byteLen} bytes]`;
52
+ const r = buildBodySnippet(snippet, { contentType: "text/plain" });
53
+ return {
54
+ direction,
55
+ dataSnippet: r.snippet,
56
+ dataSnippetBytes: r.snippetBytes,
57
+ dataTruncated: false,
58
+ dataSize: byteLen,
59
+ dataContentType: "application/octet-stream",
60
+ };
61
+ }
62
+ // RN Blob-like: buildBodySnippet will return placeholder + isBlob, but content type is unknown.
63
+ const r = buildBodySnippet(data, { contentType: undefined });
64
+ return {
65
+ direction,
66
+ dataSnippet: r.snippet,
67
+ dataSnippetBytes: r.snippetBytes,
68
+ dataTruncated: r.truncated,
69
+ dataSize: r.sizeBytes,
70
+ dataContentType: undefined,
71
+ };
72
+ }
73
+ function sendWsEvent(payload) {
74
+ sendEvent(payload);
75
+ }
76
+ export function patchWebSocket(options) {
77
+ var _a;
78
+ debugLog("ws", `patchWebSocket called, allowedHosts=${JSON.stringify(options === null || options === void 0 ? void 0 : options.allowedHosts)}, ignoreUrls=${JSON.stringify(options === null || options === void 0 ? void 0 : options.ignoreUrls)}`);
79
+ const g = globalThis;
80
+ const CurrentWS = g.WebSocket;
81
+ if (typeof CurrentWS === "undefined")
82
+ return false;
83
+ setWsFilters({
84
+ allowedHosts: options === null || options === void 0 ? void 0 : options.allowedHosts,
85
+ ignoreUrls: options === null || options === void 0 ? void 0 : options.ignoreUrls,
86
+ });
87
+ if (isWsPatched())
88
+ return true;
89
+ setWsPatched(true);
90
+ const Original = (_a = getOriginalWebSocket()) !== null && _a !== void 0 ? _a : CurrentWS;
91
+ setOriginalWebSocket(Original);
92
+ debugLog("ws", "WebSocket patching in progress...");
93
+ function PatchedWebSocket(...args) {
94
+ var _a;
95
+ // RN WebSocket supports (url, protocols?, options?) — keep it generic and forward all args.
96
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
97
+ const ws = new Original(...args);
98
+ const urlArg = args.length > 0 ? args[0] : undefined;
99
+ const fullUrl = String((_a = urlArg !== null && urlArg !== void 0 ? urlArg : ws.url) !== null && _a !== void 0 ? _a : "");
100
+ const { host, path } = parseUrl(fullUrl);
101
+ const skipped = shouldSkipWs(fullUrl, host, path, getWsFilters());
102
+ if (skipped) {
103
+ return ws;
104
+ }
105
+ const meta = {
106
+ connectionId: generateRandomId(),
107
+ url: fullUrl,
108
+ };
109
+ wsMeta.set(ws, meta);
110
+ debugLog("ws", `attach connectionId=${meta.connectionId} url=${meta.url}`);
111
+ const attach = (type, fn) => {
112
+ const ael = ws.addEventListener;
113
+ if (typeof ael === "function") {
114
+ ael.call(ws, type, fn);
115
+ return;
116
+ }
117
+ // RN WebSocket frequently uses onopen/onmessage/onerror/onclose instead of addEventListener.
118
+ const prop = `on${type}`;
119
+ const prev = ws[prop];
120
+ ws[prop] = (ev) => {
121
+ try {
122
+ fn(ev);
123
+ }
124
+ finally {
125
+ try {
126
+ if (typeof prev === "function")
127
+ prev.call(ws, ev);
128
+ }
129
+ catch {
130
+ // ignore
131
+ }
132
+ }
133
+ };
134
+ };
135
+ // open
136
+ attach("open", () => {
137
+ debugLog("ws", `open connectionId=${meta.connectionId}`);
138
+ debugLog("ws", `sendEvent: open connectionId=${meta.connectionId} url=${meta.url}`);
139
+ sendWsEvent({
140
+ id: generateRandomId(),
141
+ type: "ws",
142
+ transport: "websocket",
143
+ connectionId: meta.connectionId,
144
+ ts: now(),
145
+ url: meta.url,
146
+ kind: "open",
147
+ });
148
+ });
149
+ // close
150
+ attach("close", (ev) => {
151
+ debugLog("ws", `close connectionId=${meta.connectionId} code=${String(ev === null || ev === void 0 ? void 0 : ev.code)} reason=${String(ev === null || ev === void 0 ? void 0 : ev.reason)}`);
152
+ debugLog("ws", `sendEvent: close connectionId=${meta.connectionId} code=${String(ev === null || ev === void 0 ? void 0 : ev.code)}`);
153
+ sendWsEvent({
154
+ id: generateRandomId(),
155
+ type: "ws",
156
+ transport: "websocket",
157
+ connectionId: meta.connectionId,
158
+ ts: now(),
159
+ url: meta.url,
160
+ kind: "close",
161
+ code: typeof (ev === null || ev === void 0 ? void 0 : ev.code) === "number" ? ev.code : undefined,
162
+ reason: typeof (ev === null || ev === void 0 ? void 0 : ev.reason) === "string" ? ev.reason : undefined,
163
+ });
164
+ wsMeta.delete(ws);
165
+ });
166
+ // error
167
+ attach("error", (ev) => {
168
+ var _a;
169
+ const msg = (typeof (ev === null || ev === void 0 ? void 0 : ev.message) === "string" && ev.message) ||
170
+ (typeof ((_a = ev === null || ev === void 0 ? void 0 : ev.error) === null || _a === void 0 ? void 0 : _a.message) === "string" && ev.error.message) ||
171
+ "websocket_error";
172
+ debugLog("ws", `error connectionId=${meta.connectionId} msg=${msg}`);
173
+ debugLog("ws", `sendEvent: error connectionId=${meta.connectionId} msg=${msg}`);
174
+ sendWsEvent({
175
+ id: generateRandomId(),
176
+ type: "ws",
177
+ transport: "websocket",
178
+ connectionId: meta.connectionId,
179
+ ts: now(),
180
+ url: meta.url,
181
+ kind: "error",
182
+ error: msg,
183
+ });
184
+ });
185
+ // incoming frame
186
+ attach("message", (ev) => {
187
+ var _a, _b, _c;
188
+ const frame = buildWsFrame(meta, "in", ev === null || ev === void 0 ? void 0 : ev.data);
189
+ const raw = typeof (ev === null || ev === void 0 ? void 0 : ev.data) === "string" ? previewString(ev.data) : typeof (ev === null || ev === void 0 ? void 0 : ev.data);
190
+ debugLog("ws", `frame(in) connectionId=${meta.connectionId} bytes=${String((_b = (_a = frame.dataSize) !== null && _a !== void 0 ? _a : frame.dataSnippetBytes) !== null && _b !== void 0 ? _b : "?")} truncated=${String(frame.dataTruncated)} ct=${String(frame.dataContentType)} data=${String(raw)}`);
191
+ debugLog("ws", `sendEvent: frame(in) connectionId=${meta.connectionId} bytes=${String((_c = frame.dataSize) !== null && _c !== void 0 ? _c : frame.dataSnippetBytes)}`);
192
+ sendWsEvent({
193
+ id: generateRandomId(),
194
+ type: "ws",
195
+ transport: "websocket",
196
+ connectionId: meta.connectionId,
197
+ ts: now(),
198
+ url: meta.url,
199
+ kind: "frame",
200
+ ...frame,
201
+ });
202
+ });
203
+ // outgoing frame
204
+ const originalSend = ws.send;
205
+ if (typeof originalSend === "function") {
206
+ ws.send = function patchedSend(data) {
207
+ var _a, _b, _c;
208
+ const m = wsMeta.get(ws);
209
+ if (m) {
210
+ const frame = buildWsFrame(m, "out", data);
211
+ const raw = typeof data === "string" ? previewString(data) : typeof data;
212
+ debugLog("ws", `frame(out) connectionId=${m.connectionId} bytes=${String((_b = (_a = frame.dataSize) !== null && _a !== void 0 ? _a : frame.dataSnippetBytes) !== null && _b !== void 0 ? _b : "?")} truncated=${String(frame.dataTruncated)} ct=${String(frame.dataContentType)} data=${String(raw)}`);
213
+ debugLog("ws", `sendEvent: frame(out) connectionId=${m.connectionId} bytes=${String((_c = frame.dataSize) !== null && _c !== void 0 ? _c : frame.dataSnippetBytes)}`);
214
+ sendWsEvent({
215
+ id: generateRandomId(),
216
+ type: "ws",
217
+ transport: "websocket",
218
+ connectionId: m.connectionId,
219
+ ts: now(),
220
+ url: m.url,
221
+ kind: "frame",
222
+ ...frame,
223
+ });
224
+ }
225
+ return originalSend.call(ws, data);
226
+ };
227
+ }
228
+ return ws;
229
+ }
230
+ // Preserve prototype + statics (CONNECTING/OPEN/CLOSING/CLOSED etc.)
231
+ PatchedWebSocket.prototype = Original.prototype;
232
+ try {
233
+ Object.setPrototypeOf(PatchedWebSocket, Original);
234
+ }
235
+ catch {
236
+ // ignore
237
+ }
238
+ try {
239
+ Object.assign(PatchedWebSocket, Original);
240
+ }
241
+ catch {
242
+ // ignore
243
+ }
244
+ g.WebSocket = PatchedWebSocket;
245
+ debugLog("ws", "WebSocket patched successfully");
246
+ return true;
247
+ }
@@ -0,0 +1 @@
1
+ export declare function restoreWebSocket(): void;
@@ -0,0 +1,16 @@
1
+ import { getOriginalWebSocket, setOriginalWebSocket, setWsFilters, setWsPatched } from "./state.js";
2
+ export function restoreWebSocket() {
3
+ const g = globalThis;
4
+ setWsPatched(false);
5
+ setWsFilters({});
6
+ const Original = getOriginalWebSocket();
7
+ if (Original) {
8
+ try {
9
+ g.WebSocket = Original;
10
+ }
11
+ catch {
12
+ // ignore
13
+ }
14
+ }
15
+ setOriginalWebSocket(null);
16
+ }
@@ -0,0 +1,2 @@
1
+ import type { NetworkFilters } from "../../types";
2
+ export declare function shouldSkipWs(url: string, host: string, path: string, filters: NetworkFilters): boolean;
@@ -0,0 +1,22 @@
1
+ import { isDevServerHost } from "../system/index.js";
2
+ function matchList(value, list) {
3
+ if (!list || list.length === 0)
4
+ return false;
5
+ return list.some((rule) => typeof rule === "string" ? value === rule : rule.test(value));
6
+ }
7
+ export function shouldSkipWs(url, host, path, filters) {
8
+ // Metro HMR / debugger sockets
9
+ if (isDevServerHost(host))
10
+ return true;
11
+ // ignoreUrls
12
+ if (matchList(url, filters.ignoreUrls) || matchList(path, filters.ignoreUrls)) {
13
+ return true;
14
+ }
15
+ // allowedHosts
16
+ if (filters.allowedHosts && filters.allowedHosts.length > 0) {
17
+ if (!matchList(host, filters.allowedHosts)) {
18
+ return true;
19
+ }
20
+ }
21
+ return false;
22
+ }
@@ -0,0 +1,9 @@
1
+ import type { NetworkFilters } from "../../types";
2
+ type WebSocketCtor = typeof WebSocket | null;
3
+ export declare function getWsFilters(): NetworkFilters;
4
+ export declare function setWsFilters(value: NetworkFilters): void;
5
+ export declare function isWsPatched(): boolean;
6
+ export declare function setWsPatched(value: boolean): void;
7
+ export declare function getOriginalWebSocket(): WebSocketCtor;
8
+ export declare function setOriginalWebSocket(ws: WebSocketCtor): void;
9
+ export {};
@@ -0,0 +1,21 @@
1
+ let patched = false;
2
+ let filters = {};
3
+ let originalWebSocket = null;
4
+ export function getWsFilters() {
5
+ return filters;
6
+ }
7
+ export function setWsFilters(value) {
8
+ filters = value;
9
+ }
10
+ export function isWsPatched() {
11
+ return patched;
12
+ }
13
+ export function setWsPatched(value) {
14
+ patched = value;
15
+ }
16
+ export function getOriginalWebSocket() {
17
+ return originalWebSocket;
18
+ }
19
+ export function setOriginalWebSocket(ws) {
20
+ originalWebSocket = ws;
21
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,3 @@
1
+ export * from "./public/public";
2
+ export * from "./types/public";
3
+ export * from "./core/public";
package/dist/index.js ADDED
@@ -0,0 +1,3 @@
1
+ export * from "./public/public.js";
2
+ export * from "./types/public.js";
3
+ export * from "./core/public.js";
@@ -0,0 +1,9 @@
1
+ import type { PressableProps } from "react-native";
2
+ type Props = PressableProps & {
3
+ tone?: "light" | "dark";
4
+ };
5
+ declare const CopyButton: {
6
+ ({ tone, ...props }: Props): import("react/jsx-runtime").JSX.Element;
7
+ displayName: string;
8
+ };
9
+ export default CopyButton;
@@ -0,0 +1,13 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Pressable, View } from "react-native";
3
+ import styles from "./styles.js";
4
+ const CopyButton = ({ tone = "light", ...props }) => {
5
+ const isDark = tone === "dark";
6
+ return (_jsx(Pressable, { ...props, disabled: props.disabled || props.onPress === undefined, style: [
7
+ styles.copyButton,
8
+ isDark && styles.copyButtonDark,
9
+ props.disabled && styles.copyButtonDisabled,
10
+ ], children: _jsxs(View, { style: styles.copyIconWrapper, children: [_jsx(View, { style: [styles.copyIconBack, isDark && styles.copyIconDark] }), _jsx(View, { style: [styles.copyIconFront, isDark && styles.copyIconDark] })] }) }));
11
+ };
12
+ CopyButton.displayName = "CopyButton";
13
+ export default CopyButton;
@@ -0,0 +1 @@
1
+ export { default as CopyButton } from "./component";
@@ -0,0 +1 @@
1
+ export { default as CopyButton } from "./component.js";
@@ -0,0 +1,64 @@
1
+ declare const _default: {
2
+ copyButton: {
3
+ backgroundColor: string;
4
+ borderColor: string;
5
+ borderRadius: number;
6
+ borderWidth: number;
7
+ height: number;
8
+ width: number;
9
+ };
10
+ copyButtonDisabled: {
11
+ opacity: number;
12
+ };
13
+ copyButtonDark: {
14
+ backgroundColor: string;
15
+ borderColor: string;
16
+ };
17
+ copyIconDark: {
18
+ backgroundColor: string;
19
+ borderColor: string;
20
+ };
21
+ copyIconWrapper: {
22
+ alignItems: "center";
23
+ flex: number;
24
+ justifyContent: "center";
25
+ };
26
+ copyIconBack: {
27
+ backgroundColor: string;
28
+ borderColor: string;
29
+ borderRadius: number;
30
+ borderWidth: number;
31
+ height: number;
32
+ left: "50%";
33
+ position: "absolute";
34
+ top: "50%";
35
+ transform: ({
36
+ translateX: number;
37
+ translateY?: undefined;
38
+ } | {
39
+ translateY: number;
40
+ translateX?: undefined;
41
+ })[];
42
+ width: number;
43
+ };
44
+ copyIconFront: {
45
+ backgroundColor: string;
46
+ borderColor: string;
47
+ borderRadius: number;
48
+ borderWidth: number;
49
+ height: number;
50
+ left: "50%";
51
+ position: "absolute";
52
+ top: "50%";
53
+ transform: ({
54
+ translateX: number;
55
+ translateY?: undefined;
56
+ } | {
57
+ translateY: number;
58
+ translateX?: undefined;
59
+ })[];
60
+ width: number;
61
+ zIndex: number;
62
+ };
63
+ };
64
+ export default _default;
@@ -0,0 +1,52 @@
1
+ import { StyleSheet } from "react-native";
2
+ export default StyleSheet.create({
3
+ copyButton: {
4
+ backgroundColor: "#f3f3f3",
5
+ borderColor: "#ddd",
6
+ borderRadius: 999,
7
+ borderWidth: 1,
8
+ height: 28,
9
+ width: 28,
10
+ },
11
+ copyButtonDisabled: {
12
+ opacity: 0.4,
13
+ },
14
+ copyButtonDark: {
15
+ backgroundColor: "#23272F",
16
+ borderColor: "#2D323C",
17
+ },
18
+ copyIconDark: {
19
+ backgroundColor: "#23272F",
20
+ borderColor: "#9CA3AF",
21
+ },
22
+ copyIconWrapper: {
23
+ alignItems: "center",
24
+ flex: 1,
25
+ justifyContent: "center",
26
+ },
27
+ copyIconBack: {
28
+ backgroundColor: "#f0f0f0",
29
+ borderColor: "#555",
30
+ borderRadius: 3,
31
+ borderWidth: 1,
32
+ height: 14,
33
+ left: "50%",
34
+ position: "absolute",
35
+ top: "50%",
36
+ transform: [{ translateX: -5 }, { translateY: -8 }],
37
+ width: 12,
38
+ },
39
+ copyIconFront: {
40
+ backgroundColor: "#f3f3f3",
41
+ borderColor: "#555",
42
+ borderRadius: 3,
43
+ borderWidth: 1,
44
+ height: 14,
45
+ left: "50%",
46
+ position: "absolute",
47
+ top: "50%",
48
+ transform: [{ translateX: -8 }, { translateY: -5 }],
49
+ width: 12,
50
+ zIndex: 1,
51
+ },
52
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,7 @@
1
+ import { type JSX } from "react";
2
+ import type { Props } from "./types";
3
+ declare const HeimdallConnectPrompt: {
4
+ ({ onCopyToClipboard, }: Props): JSX.Element | null;
5
+ displayName: string;
6
+ };
7
+ export default HeimdallConnectPrompt;
@@ -0,0 +1,56 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Animated, KeyboardAvoidingView, Platform, Pressable, StyleSheet, useColorScheme, } from "react-native";
3
+ import { useCallback, useMemo, useState } from "react";
4
+ import { getPromptState, setLastError } from "../../core/connection/index.js";
5
+ import { getCloudHostName } from "../../core/cloud/index.js";
6
+ import { loadPromptMode, savePromptMode } from "./prompt-mode.js";
7
+ import { usePromptTheme } from "./theme.js";
8
+ import usePrompt from "./use-prompt.js";
9
+ import usePromptAnimation from "./use-prompt-animation.js";
10
+ import usePromptUi from "./use-prompt-ui.js";
11
+ import useConnectAwaiter from "./use-connect-awaiter.js";
12
+ import CloudView from "./views/cloud-view.js";
13
+ import ConnectedView from "./views/connected-view.js";
14
+ import ManualView from "./views/manual-view.js";
15
+ import ReportLink from "./ui/report-link.js";
16
+ import styles from "./styles.js";
17
+ const HeimdallConnectPrompt = ({ onCopyToClipboard, }) => {
18
+ var _a, _b;
19
+ const [ui, setUi] = usePromptUi();
20
+ const { isConnecting, startConnecting } = useConnectAwaiter({
21
+ visible: ui.visible,
22
+ });
23
+ const { onCancel, onConfirmConnect, onConfirmDisconnect, handleCopyChannel } = usePrompt({ ...ui, onCopyToClipboard, startConnecting });
24
+ const { mounted, opacity, scale } = usePromptAnimation({
25
+ visible: ui.visible,
26
+ });
27
+ const theme = usePromptTheme();
28
+ const isDark = useColorScheme() === "dark";
29
+ const cloudUrl = (_b = (_a = getPromptState().defaults) === null || _a === void 0 ? void 0 : _a.cloud) === null || _b === void 0 ? void 0 : _b.url;
30
+ const [mode, setMode] = useState(() => { var _a; return cloudUrl ? ((_a = loadPromptMode()) !== null && _a !== void 0 ? _a : "cloud") : "manual"; });
31
+ const switchMode = useCallback((next) => {
32
+ setLastError(null);
33
+ setMode(next);
34
+ savePromptMode(next);
35
+ }, []);
36
+ const backdropPointerEvents = useMemo(() => (ui.visible ? "auto" : "none"), [ui.visible]);
37
+ if (!mounted)
38
+ return null;
39
+ const canCopy = Boolean(ui.channel && onCopyToClipboard);
40
+ const renderContent = () => {
41
+ var _a;
42
+ if (ui.isConnected) {
43
+ return (_jsx(ConnectedView, { hostLabel: (_a = getCloudHostName(ui.channel)) !== null && _a !== void 0 ? _a : `${ui.host}:${ui.port}`, channel: ui.channel, theme: theme, isDark: isDark, canCopy: canCopy, onCopyChannel: handleCopyChannel, onClose: onCancel, onDisconnect: onConfirmDisconnect }));
44
+ }
45
+ if (cloudUrl && mode === "cloud") {
46
+ return (_jsx(CloudView, { baseUrl: cloudUrl, visible: ui.visible, socketError: ui.errorMessage, theme: theme, isConnecting: isConnecting, startConnecting: startConnecting, onManual: () => switchMode("manual") }));
47
+ }
48
+ return (_jsx(ManualView, { ui: ui, setUi: setUi, theme: theme, isDark: isDark, canCopy: canCopy, onCopyChannel: handleCopyChannel, onConnect: onConfirmConnect, onBack: cloudUrl ? () => switchMode("cloud") : undefined, isConnecting: isConnecting }));
49
+ };
50
+ return (_jsxs(Animated.View, { style: [styles.backdrop, { backgroundColor: theme.backdrop, opacity }], pointerEvents: backdropPointerEvents, children: [_jsx(Pressable, { style: StyleSheet.absoluteFill, onPress: onCancel }), _jsx(KeyboardAvoidingView, { style: styles.keyboard, behavior: Platform.OS === "ios" ? "padding" : undefined, pointerEvents: "box-none", children: _jsxs(Animated.View, { style: [
51
+ styles.card,
52
+ { backgroundColor: theme.card, transform: [{ scale }] },
53
+ ], children: [renderContent(), cloudUrl ? _jsx(ReportLink, { baseUrl: cloudUrl, theme: theme }) : null] }) })] }));
54
+ };
55
+ HeimdallConnectPrompt.displayName = "HeimdallConnectPrompt";
56
+ export default HeimdallConnectPrompt;
@@ -0,0 +1 @@
1
+ export { default as HeimdallConnectPrompt } from "./component";
@@ -0,0 +1 @@
1
+ export { default as HeimdallConnectPrompt } from "./component.js";
@@ -0,0 +1,3 @@
1
+ export type PromptMode = "cloud" | "manual";
2
+ export declare function loadPromptMode(): PromptMode | null;
3
+ export declare function savePromptMode(mode: PromptMode): void;
@@ -0,0 +1,19 @@
1
+ import { SESSION_STORAGE } from "../../core/connection/session/constants.js";
2
+ const KEY_PROMPT_MODE = "promptMode";
3
+ export function loadPromptMode() {
4
+ try {
5
+ const value = SESSION_STORAGE.getString(KEY_PROMPT_MODE);
6
+ return value === "cloud" || value === "manual" ? value : null;
7
+ }
8
+ catch {
9
+ return null;
10
+ }
11
+ }
12
+ export function savePromptMode(mode) {
13
+ try {
14
+ SESSION_STORAGE.set(KEY_PROMPT_MODE, mode);
15
+ }
16
+ catch {
17
+ // ignore
18
+ }
19
+ }
@@ -0,0 +1,23 @@
1
+ declare const _default: {
2
+ backdrop: {
3
+ position: "absolute";
4
+ top: number;
5
+ right: number;
6
+ bottom: number;
7
+ left: number;
8
+ zIndex: number;
9
+ elevation: number;
10
+ };
11
+ keyboard: {
12
+ alignItems: "center";
13
+ flex: number;
14
+ justifyContent: "center";
15
+ };
16
+ card: {
17
+ borderRadius: number;
18
+ maxWidth: number;
19
+ padding: number;
20
+ width: "86%";
21
+ };
22
+ };
23
+ export default _default;
@@ -0,0 +1,23 @@
1
+ import { StyleSheet } from "react-native";
2
+ export default StyleSheet.create({
3
+ backdrop: {
4
+ position: "absolute",
5
+ top: 0,
6
+ right: 0,
7
+ bottom: 0,
8
+ left: 0,
9
+ zIndex: 9999,
10
+ elevation: 9999,
11
+ },
12
+ keyboard: {
13
+ alignItems: "center",
14
+ flex: 1,
15
+ justifyContent: "center",
16
+ },
17
+ card: {
18
+ borderRadius: 14,
19
+ maxWidth: 360,
20
+ padding: 18,
21
+ width: "86%",
22
+ },
23
+ });
@@ -0,0 +1,16 @@
1
+ export type PromptTheme = {
2
+ backdrop: string;
3
+ card: string;
4
+ text: string;
5
+ muted: string;
6
+ border: string;
7
+ inputBackground: string;
8
+ inputDisabledBackground: string;
9
+ primary: string;
10
+ onPrimary: string;
11
+ danger: string;
12
+ success: string;
13
+ warning: string;
14
+ idle: string;
15
+ };
16
+ export declare const usePromptTheme: () => PromptTheme;