@rnzeus/heimdall-sdk 0.7.0 → 0.8.0

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 (34) hide show
  1. package/README.md +20 -1
  2. package/dist/core/cloud/client.d.ts +2 -1
  3. package/dist/core/cloud/client.js +2 -2
  4. package/dist/core/cloud/link-device.d.ts +2 -1
  5. package/dist/core/cloud/link-device.js +2 -1
  6. package/dist/core/connection/session/create-session.js +1 -0
  7. package/dist/core/connection/session/types.d.ts +2 -0
  8. package/dist/core/connection/socket/connect-socket.js +18 -5
  9. package/dist/core/connection/socket/unreachable-message.d.ts +12 -0
  10. package/dist/core/connection/socket/unreachable-message.js +11 -0
  11. package/dist/public/prompt/component.js +3 -3
  12. package/dist/public/prompt/local-network.d.ts +31 -0
  13. package/dist/public/prompt/local-network.js +34 -0
  14. package/dist/public/prompt/theme.d.ts +6 -1
  15. package/dist/public/prompt/theme.js +23 -21
  16. package/dist/public/prompt/ui/action-button.d.ts +2 -1
  17. package/dist/public/prompt/ui/action-button.js +14 -3
  18. package/dist/public/prompt/ui/footer.d.ts +5 -2
  19. package/dist/public/prompt/ui/footer.js +3 -4
  20. package/dist/public/prompt/ui/header.js +2 -2
  21. package/dist/public/prompt/ui/status-line.d.ts +11 -0
  22. package/dist/public/prompt/ui/status-line.js +12 -0
  23. package/dist/public/prompt/use-connect-awaiter.d.ts +3 -2
  24. package/dist/public/prompt/use-connect-awaiter.js +55 -9
  25. package/dist/public/prompt/views/cloud-view.d.ts +3 -1
  26. package/dist/public/prompt/views/cloud-view.js +4 -3
  27. package/dist/public/prompt/views/connected-view.js +1 -1
  28. package/dist/public/prompt/views/manual-view.d.ts +5 -2
  29. package/dist/public/prompt/views/manual-view.js +3 -2
  30. package/dist/public/prompt/views/use-cloud-view.js +2 -0
  31. package/dist/types/options.d.ts +11 -1
  32. package/dist/version.d.ts +1 -1
  33. package/dist/version.js +1 -1
  34. package/package.json +2 -2
package/README.md CHANGED
@@ -184,7 +184,8 @@ disconnect();
184
184
  | `captureEarlyEvents` | `boolean` | `false` | buffer events that happen before the connection is up |
185
185
  | `keepAlive` | `boolean` | `false` | reconnect on app start: to the last channel, or through the cloud again if the last connection came from it |
186
186
  | `captureConsole` | `boolean` | `true` | console, uncaught errors, unhandled rejections |
187
- | `cloud` | `{ url: string }` | — | optional, see [Connecting without typing an address](#connecting-without-typing-an-address) |
187
+ | `cloud` | `{ url: string; appKey?: string }` | — | optional, see [Connecting without typing an address](#connecting-without-typing-an-address) and [Team apps](#team-apps) |
188
+ | `ai` | `"strict" \| "off"` | — | what AI may get from this app's data in Heimdall, see [Team apps](#team-apps) |
188
189
 
189
190
  `<HeimdallConnectPrompt />` accepts `onCopyToClipboard?: (text: string) => void` to plug in your clipboard library.
190
191
 
@@ -215,6 +216,24 @@ The cloud only stores accounts, devices and the current address of the desktop.
215
216
 
216
217
  **Devices.** A device in the account is a phone, a tablet or a simulator; several apps (for example dev and stage builds) can be linked to it. Linking an Android app to an iPhone, or an emulator to a real device, asks for confirmation. Pass `device` (see [Options](#options)) to make the iOS simulator recognisable too.
217
218
 
219
+ ## Team apps
220
+
221
+ A team in Heimdall Cloud registers its app on the team's **Apps** page and gets a public **app key** (`hk_…`). It is not a secret: it ties the app to the team, like a DSN.
222
+
223
+ ```ts
224
+ configureConnectPrompt({
225
+ // ...
226
+ cloud: { url: "https://heimdall.rnzeus.dev", appKey: "hk_..." },
227
+ ai: "strict", // optional
228
+ });
229
+ ```
230
+
231
+ - **Find me** links the device straight into the team's devices; the tester doesn't pick a team.
232
+ - Heimdall applies the team's AI rule for the app (Member's choice, Strict or Off) to bug reports with its events, through the cloud and in manual mode alike. Without a key Heimdall matches the app by `appId`.
233
+ - `ai` is the app developers' own limit on what AI clients may get from the app's data in Heimdall: `"strict"` — the Strict data set, no screenshots; `"off"` — nothing. It can only make Heimdall stricter, never looser than the team's rule.
234
+
235
+ Older Heimdall versions ignore both.
236
+
218
237
  ## Production safety
219
238
 
220
239
  - `enabled` defaults to `__DEV__`. In a release build the SDK does nothing unless you pass `enabled: true`.
@@ -32,8 +32,9 @@ export type CloudConnection = {
32
32
  };
33
33
  token?: string;
34
34
  };
35
- export declare function createClaim({ baseUrl, appId, platform, installId, device, }: {
35
+ export declare function createClaim({ baseUrl, appKey, appId, platform, installId, device, }: {
36
36
  baseUrl: string;
37
+ appKey?: string;
37
38
  appId?: string;
38
39
  platform?: string;
39
40
  installId?: string;
@@ -24,12 +24,12 @@ async function request({ baseUrl, path, method = "GET", token, body, }) {
24
24
  clearTimeout(timeout);
25
25
  }
26
26
  }
27
- export async function createClaim({ baseUrl, appId, platform, installId, device, }) {
27
+ export async function createClaim({ baseUrl, appKey, appId, platform, installId, device, }) {
28
28
  const { status, data } = await request({
29
29
  baseUrl,
30
30
  path: "/claims",
31
31
  method: "POST",
32
- body: { appId, platform, installId, device },
32
+ body: { appKey, appId, platform, installId, device },
33
33
  });
34
34
  if (status !== 201)
35
35
  throw new Error(`Cloud error ${status}`);
@@ -7,8 +7,9 @@ export type LinkDeviceResult = {
7
7
  } | {
8
8
  status: "cancelled";
9
9
  };
10
- export declare function linkDevice({ baseUrl, appId, platform, installId, device, isCancelled, }: {
10
+ export declare function linkDevice({ baseUrl, appKey, appId, platform, installId, device, isCancelled, }: {
11
11
  baseUrl: string;
12
+ appKey?: string;
12
13
  appId?: string;
13
14
  platform?: string;
14
15
  installId?: string;
@@ -3,9 +3,10 @@ import { createClaim, pollClaim } from "./client.js";
3
3
  import { saveCloudDevice } from "./storage.js";
4
4
  const POLL_INTERVAL_MS = 2000;
5
5
  const delay = (ms) => new Promise((resolve) => setTimeout(() => resolve(), ms));
6
- export async function linkDevice({ baseUrl, appId, platform, installId, device, isCancelled, }) {
6
+ export async function linkDevice({ baseUrl, appKey, appId, platform, installId, device, isCancelled, }) {
7
7
  const claim = await createClaim({
8
8
  baseUrl,
9
+ appKey,
9
10
  appId,
10
11
  platform,
11
12
  installId,
@@ -18,5 +18,6 @@ export function createSession(options, source = "manual") {
18
18
  sessionId,
19
19
  createdAt,
20
20
  options,
21
+ source,
21
22
  };
22
23
  }
@@ -6,6 +6,8 @@ export type HeimdallSession = {
6
6
  createdAt: string;
7
7
  options: HeimdallConnectOptions;
8
8
  secure?: SecureTransport;
9
+ /** where the host address came from: shown when the host can't be reached */
10
+ source?: ConnectionSource;
9
11
  };
10
12
  export type ConnectionSource = "cloud" | "manual";
11
13
  export type LastConnection = {
@@ -4,6 +4,7 @@ import { isConnected, getSocket, setConnected, setSocket, setLastError, } from "
4
4
  import { handleSocketLost } from "./handle-socket-lost.js";
5
5
  import { flushEarlyEvents } from "./flush-early-events.js";
6
6
  import { normalizeSocketError } from "./normalize-socket-error.js";
7
+ import { unreachableMessage } from "./unreachable-message.js";
7
8
  import { SOCKET } from "./constants.js";
8
9
  import { getCapabilities } from "./capabilities.js";
9
10
  import { handleHostLine } from "./host-message.js";
@@ -14,7 +15,7 @@ import { normaliseAppInfo, readDeviceInfo } from "../../system/index.js";
14
15
  import { CERTIFICATE_MISMATCH, NO_ANSWER, matchesPin, parseHostAnswer, readPeerCertificate, rejectionMessage, } from "./secure-transport.js";
15
16
  const HOST_ANSWER_TIMEOUT_MS = 5000;
16
17
  function buildHello({ session, options, secure, }) {
17
- var _a, _b;
18
+ var _a, _b, _c;
18
19
  const activeSession = getCurrentSession();
19
20
  const hello = {
20
21
  kind: "hello",
@@ -31,8 +32,11 @@ function buildHello({ session, options, secure, }) {
31
32
  if (device)
32
33
  hello.device = device;
33
34
  const app = normaliseAppInfo(options.app);
34
- if (app)
35
- hello.app = app;
35
+ const key = (_c = options.cloud) === null || _c === void 0 ? void 0 : _c.appKey;
36
+ if (app || key)
37
+ hello.app = { ...app, ...(key ? { key } : {}) };
38
+ if (options.ai)
39
+ hello.policy = { ai: options.ai };
36
40
  if (secure)
37
41
  hello.auth = { token: secure.token };
38
42
  const capabilities = getCapabilities();
@@ -147,16 +151,25 @@ export function connectSocket(optionsOrSession) {
147
151
  const newSocket = secure
148
152
  ? TcpSocket.connectTLS({ host: options.host, port: options.port, ca: secure.cert }, () => void onSecureConnect())
149
153
  : TcpSocket.createConnection({ host: options.host, port: options.port }, onPlainConnect);
154
+ const unreachable = (reason) => {
155
+ var _a;
156
+ return unreachableMessage({
157
+ host: options.host,
158
+ port: options.port,
159
+ source: (_a = session.source) !== null && _a !== void 0 ? _a : "manual",
160
+ reason,
161
+ });
162
+ };
150
163
  const connectTimeout = setTimeout(() => {
151
164
  if (getSocket() !== newSocket || isConnected())
152
165
  return;
153
- setLastError(`Can't reach Heimdall at ${options.host}:${options.port}. Same Wi-Fi?`);
166
+ setLastError(unreachable("no answer"));
154
167
  handleSocketLost();
155
168
  }, SOCKET.CONNECT_TIMEOUT_MS);
156
169
  newSocket.on("error", (error) => {
157
170
  clearTimeout(connectTimeout);
158
171
  const message = normalizeSocketError(error);
159
- setLastError(message);
172
+ setLastError(isConnected() ? message : unreachable(message));
160
173
  if (__DEV__) {
161
174
  console.warn("[Heimdall] socket error:", message);
162
175
  }
@@ -0,0 +1,12 @@
1
+ import type { ConnectionSource } from "../session";
2
+ /**
3
+ * Why a connection to the host failed, with the address and where it came from: an old address from the cloud,
4
+ * an old one typed by hand and a phone that can't see the computer look alike otherwise. The system's reason
5
+ * stays in the text, the iOS Local Network check reads it.
6
+ */
7
+ export declare function unreachableMessage({ host, port, source, reason, }: {
8
+ host: string;
9
+ port: number;
10
+ source: ConnectionSource;
11
+ reason: string;
12
+ }): string;
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Why a connection to the host failed, with the address and where it came from: an old address from the cloud,
3
+ * an old one typed by hand and a phone that can't see the computer look alike otherwise. The system's reason
4
+ * stays in the text, the iOS Local Network check reads it.
5
+ */
6
+ export function unreachableMessage({ host, port, source, reason, }) {
7
+ const hint = source === "manual"
8
+ ? "Same Wi-Fi, no VPN? The address may have changed: see Heimdall → Settings → Connection."
9
+ : "Same Wi-Fi as the computer, no VPN?";
10
+ return `Can't reach Heimdall at ${host}:${port} (${source}): ${reason.replace(/\.$/, "")}. ${hint}`;
11
+ }
@@ -17,7 +17,7 @@ import styles from "./styles.js";
17
17
  const HeimdallConnectPrompt = ({ onCopyToClipboard, }) => {
18
18
  var _a, _b;
19
19
  const [ui, setUi] = usePromptUi();
20
- const { isConnecting, startConnecting } = useConnectAwaiter({
20
+ const { isConnecting, notice, startConnecting } = useConnectAwaiter({
21
21
  visible: ui.visible,
22
22
  });
23
23
  const { onCancel, onConfirmConnect, onConfirmDisconnect, handleCopyChannel } = usePrompt({ ...ui, onCopyToClipboard, startConnecting });
@@ -43,9 +43,9 @@ const HeimdallConnectPrompt = ({ onCopyToClipboard, }) => {
43
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
44
  }
45
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") }));
46
+ return (_jsx(CloudView, { baseUrl: cloudUrl, visible: ui.visible, socketError: ui.errorMessage, theme: theme, isConnecting: isConnecting, notice: notice, startConnecting: startConnecting, onManual: () => switchMode("manual") }));
47
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 }));
48
+ return (_jsx(ManualView, { ui: ui, setUi: setUi, theme: theme, isDark: isDark, canCopy: canCopy, onCopyChannel: handleCopyChannel, onConnect: onConfirmConnect, onAuto: cloudUrl ? () => switchMode("cloud") : undefined, isConnecting: isConnecting, notice: notice }));
49
49
  };
50
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
51
  styles.card,
@@ -0,0 +1,31 @@
1
+ /**
2
+ * iOS asks “Find devices on local networks” on the first connection to a LAN address and fails that very
3
+ * connection with “No route to host”. While the question may still be open, the prompt keeps trying instead.
4
+ */
5
+ export declare const LOCAL_NETWORK: {
6
+ /** how long the user may take to answer iOS */
7
+ waitMs: number;
8
+ retryMs: number;
9
+ /** after this the user has most likely answered: say where to turn it on, and keep trying */
10
+ hintAfterMs: number;
11
+ hint: string;
12
+ notice: string;
13
+ denied: string;
14
+ };
15
+ export declare function shouldWaitForLocalNetwork({ platform, error, startedAt, now, }: {
16
+ platform: string;
17
+ error: string | null;
18
+ /** when the user pressed Connect */
19
+ startedAt: number;
20
+ now: number;
21
+ }): boolean;
22
+ /** What the prompt says while it keeps trying: first the iOS question, then where to turn access on. */
23
+ export declare function localNetworkNotice({ startedAt, now, }: {
24
+ startedAt: number;
25
+ now: number;
26
+ }): string;
27
+ /** after the wait: a “no route” on iOS most likely means the permission is off */
28
+ export declare function localNetworkError({ platform, error, }: {
29
+ platform: string;
30
+ error: string;
31
+ }): string;
@@ -0,0 +1,34 @@
1
+ /**
2
+ * iOS asks “Find devices on local networks” on the first connection to a LAN address and fails that very
3
+ * connection with “No route to host”. While the question may still be open, the prompt keeps trying instead.
4
+ */
5
+ export const LOCAL_NETWORK = {
6
+ /** how long the user may take to answer iOS */
7
+ waitMs: 30000,
8
+ retryMs: 1500,
9
+ /** after this the user has most likely answered: say where to turn it on, and keep trying */
10
+ hintAfterMs: 8000,
11
+ hint: "No access yet. If you tapped Don't Allow, turn it on in Settings → Privacy & Security → Local Network.",
12
+ notice: "Allow “Local Network” in the iOS prompt: Heimdall connects right after.",
13
+ denied: "Local Network access is off for this app: Settings → Privacy & Security → Local Network.",
14
+ };
15
+ /** POSIX texts of EHOSTUNREACH / ENETUNREACH, as iOS reports a connection the Local Network permission held back */
16
+ const NO_ROUTE = /no route to host|host is unreachable|network is unreachable|EHOSTUNREACH|ENETUNREACH/i;
17
+ export function shouldWaitForLocalNetwork({ platform, error, startedAt, now, }) {
18
+ return (platform === "ios" &&
19
+ error !== null &&
20
+ NO_ROUTE.test(error) &&
21
+ now - startedAt < LOCAL_NETWORK.waitMs);
22
+ }
23
+ /** What the prompt says while it keeps trying: first the iOS question, then where to turn access on. */
24
+ export function localNetworkNotice({ startedAt, now, }) {
25
+ return now - startedAt < LOCAL_NETWORK.hintAfterMs
26
+ ? LOCAL_NETWORK.notice
27
+ : LOCAL_NETWORK.hint;
28
+ }
29
+ /** after the wait: a “no route” on iOS most likely means the permission is off */
30
+ export function localNetworkError({ platform, error, }) {
31
+ return platform === "ios" && NO_ROUTE.test(error)
32
+ ? LOCAL_NETWORK.denied
33
+ : error;
34
+ }
@@ -1,3 +1,4 @@
1
+ /** Heimdall's own colours, as in the desktop app: the brand orange for the main action, the soft orange for links. */
1
2
  export type PromptTheme = {
2
3
  backdrop: string;
3
4
  card: string;
@@ -6,10 +7,14 @@ export type PromptTheme = {
6
7
  border: string;
7
8
  inputBackground: string;
8
9
  inputDisabledBackground: string;
10
+ /** the main button: the brand orange */
9
11
  primary: string;
10
12
  onPrimary: string;
13
+ /** links and the “connecting” dot */
14
+ link: string;
11
15
  danger: string;
12
- success: string;
16
+ /** connected, as the session blue in the desktop app */
17
+ session: string;
13
18
  warning: string;
14
19
  idle: string;
15
20
  };
@@ -2,31 +2,33 @@ import { useColorScheme } from "react-native";
2
2
  const LIGHT = {
3
3
  backdrop: "rgba(0,0,0,0.38)",
4
4
  card: "#FFFFFF",
5
- text: "#111827",
6
- muted: "#6B7280",
7
- border: "#E5E7EB",
8
- inputBackground: "#FFFFFF",
9
- inputDisabledBackground: "#F3F4F6",
10
- primary: "#2563EB",
11
- onPrimary: "#FFFFFF",
12
- danger: "#DC2626",
13
- success: "#16A34A",
14
- warning: "#D97706",
5
+ text: "#161B22",
6
+ muted: "#5F6672",
7
+ border: "#DDE1E7",
8
+ inputBackground: "#F7F8FA",
9
+ inputDisabledBackground: "#EEF0F3",
10
+ primary: "#FC7F1C",
11
+ onPrimary: "#1C0D00",
12
+ link: "#B85407",
13
+ danger: "#C62828",
14
+ session: "#0A78BF",
15
+ warning: "#B85407",
15
16
  idle: "#9CA3AF",
16
17
  };
17
18
  const DARK = {
18
19
  backdrop: "rgba(0,0,0,0.55)",
19
- card: "#1C1F26",
20
- text: "#F3F4F6",
21
- muted: "#9CA3AF",
22
- border: "#2D323C",
23
- inputBackground: "#14171C",
24
- inputDisabledBackground: "#23272F",
25
- primary: "#3B82F6",
26
- onPrimary: "#FFFFFF",
27
- danger: "#F87171",
28
- success: "#4ADE80",
29
- warning: "#FBBF24",
20
+ card: "#171C23",
21
+ text: "#DEE2ED",
22
+ muted: "#9E9E9E",
23
+ border: "#30353E",
24
+ inputBackground: "#0F141B",
25
+ inputDisabledBackground: "#1D232B",
26
+ primary: "#FC7F1C",
27
+ onPrimary: "#1C0D00",
28
+ link: "#FFAD66",
29
+ danger: "#FF6B6B",
30
+ session: "#42BAFD",
31
+ warning: "#FFAD66",
30
32
  idle: "#6B7280",
31
33
  };
32
34
  export const usePromptTheme = () => useColorScheme() === "dark" ? DARK : LIGHT;
@@ -4,7 +4,8 @@ type Props = {
4
4
  title: string;
5
5
  onPress: () => void;
6
6
  theme: PromptTheme;
7
- variant?: "primary" | "danger" | "link";
7
+ /** quiet: a link for a rarer action, in the muted colour */
8
+ variant?: "primary" | "danger" | "link" | "quiet";
8
9
  disabled?: boolean;
9
10
  };
10
11
  declare const ActionButton: ({ title, onPress, theme, variant, disabled, }: Props) => JSX.Element;
@@ -1,13 +1,19 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { Pressable, StyleSheet, Text } from "react-native";
3
3
  const ActionButton = ({ title, onPress, theme, variant = "primary", disabled = false, }) => {
4
- const isLink = variant === "link";
4
+ const isLink = variant === "link" || variant === "quiet";
5
5
  const background = isLink
6
6
  ? "transparent"
7
7
  : variant === "danger"
8
8
  ? theme.danger
9
9
  : theme.primary;
10
- const color = isLink ? theme.primary : theme.onPrimary;
10
+ const color = variant === "link"
11
+ ? theme.link
12
+ : variant === "quiet"
13
+ ? theme.muted
14
+ : variant === "danger"
15
+ ? theme.card
16
+ : theme.onPrimary;
11
17
  return (_jsx(Pressable, { onPress: onPress, disabled: disabled, hitSlop: 8, style: ({ pressed }) => [
12
18
  isLink ? styles.link : styles.button,
13
19
  { backgroundColor: background },
@@ -15,7 +21,12 @@ const ActionButton = ({ title, onPress, theme, variant = "primary", disabled = f
15
21
  ], children: _jsx(Text, { style: [styles.title, { color }], children: title }) }));
16
22
  };
17
23
  const styles = StyleSheet.create({
18
- button: { borderRadius: 8, paddingHorizontal: 14, paddingVertical: 9 },
24
+ button: {
25
+ alignItems: "center",
26
+ borderRadius: 10,
27
+ paddingHorizontal: 14,
28
+ paddingVertical: 11,
29
+ },
19
30
  link: { paddingVertical: 9 },
20
31
  title: { fontSize: 14, fontWeight: "600" },
21
32
  dimmed: { opacity: 0.5 },
@@ -1,7 +1,10 @@
1
1
  import type { JSX, ReactNode } from "react";
2
2
  type Props = {
3
- secondary?: ReactNode;
3
+ /** the main action, across the whole card */
4
4
  primary?: ReactNode;
5
+ /** links under it: the other way to connect on the left, a rarer action on the right */
6
+ start?: ReactNode;
7
+ end?: ReactNode;
5
8
  };
6
- declare const Footer: ({ secondary, primary }: Props) => JSX.Element;
9
+ declare const Footer: ({ primary, start, end }: Props) => JSX.Element;
7
10
  export default Footer;
@@ -1,13 +1,12 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { StyleSheet, View } from "react-native";
3
- const Footer = ({ secondary, primary }) => (_jsxs(View, { style: styles.row, children: [_jsx(View, { style: styles.secondary, children: secondary }), primary] }));
3
+ const Footer = ({ primary, start, end }) => (_jsxs(View, { style: styles.column, children: [primary, start || end ? (_jsxs(View, { style: styles.links, children: [_jsx(View, { children: start }), _jsx(View, { children: end })] })) : null] }));
4
4
  const styles = StyleSheet.create({
5
- row: {
5
+ column: { gap: 6, marginTop: 16 },
6
+ links: {
6
7
  alignItems: "center",
7
8
  flexDirection: "row",
8
9
  justifyContent: "space-between",
9
- marginTop: 16,
10
10
  },
11
- secondary: { alignItems: "center", flexDirection: "row", gap: 16 },
12
11
  });
13
12
  export default Footer;
@@ -3,8 +3,8 @@ import { StyleSheet, Text, View } from "react-native";
3
3
  const Header = ({ title, status, theme }) => {
4
4
  const dot = {
5
5
  idle: theme.idle,
6
- busy: theme.warning,
7
- connected: theme.success,
6
+ busy: theme.link,
7
+ connected: theme.session,
8
8
  error: theme.danger,
9
9
  }[status];
10
10
  return (_jsxs(View, { style: styles.row, children: [_jsx(View, { style: [styles.dot, { backgroundColor: dot }] }), _jsx(Text, { style: [styles.title, { color: theme.text }], numberOfLines: 1, children: title })] }));
@@ -0,0 +1,11 @@
1
+ import type { JSX } from "react";
2
+ import type { PromptTheme } from "../theme";
3
+ type Props = {
4
+ error: string | null;
5
+ /** a step the user takes while it connects, e.g. the iOS Local Network question */
6
+ notice: string | null;
7
+ theme: PromptTheme;
8
+ };
9
+ /** What went wrong, or what the user has to do for the connection to go on. */
10
+ declare const StatusLine: ({ error, notice, theme }: Props) => JSX.Element | null;
11
+ export default StatusLine;
@@ -0,0 +1,12 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { Text } from "react-native";
3
+ import styles from "../views/styles.js";
4
+ /** What went wrong, or what the user has to do for the connection to go on. */
5
+ const StatusLine = ({ error, notice, theme }) => {
6
+ if (error)
7
+ return _jsx(Text, { style: [styles.error, { color: theme.danger }], children: error });
8
+ if (notice)
9
+ return _jsx(Text, { style: [styles.error, { color: theme.muted }], children: notice });
10
+ return null;
11
+ };
12
+ export default StatusLine;
@@ -1,11 +1,12 @@
1
1
  /**
2
- * Keeps the prompt open while connecting: closes it only on success,
3
- * leaves it open with the error otherwise.
2
+ * Keeps the prompt open while connecting: closes it only on success, leaves it open with the error otherwise.
3
+ * On iOS a first connection that the Local Network question holds back is tried again until the user answers.
4
4
  */
5
5
  declare const useConnectAwaiter: ({ visible }: {
6
6
  visible: boolean;
7
7
  }) => {
8
8
  isConnecting: boolean;
9
+ notice: string | null;
9
10
  startConnecting: (connectFn: () => void) => void;
10
11
  };
11
12
  export default useConnectAwaiter;
@@ -1,15 +1,24 @@
1
1
  import { useCallback, useEffect, useRef, useState } from "react";
2
+ import { Platform } from "react-native";
2
3
  import { getLastError, getSocket, hidePrompt, isConnected, setLastError, subscribeSocketState, } from "../../core/connection/index.js";
4
+ import { LOCAL_NETWORK, localNetworkError, localNetworkNotice, shouldWaitForLocalNetwork, } from "./local-network.js";
5
+ const IDLE = { isConnecting: false, notice: null };
3
6
  /**
4
- * Keeps the prompt open while connecting: closes it only on success,
5
- * leaves it open with the error otherwise.
7
+ * Keeps the prompt open while connecting: closes it only on success, leaves it open with the error otherwise.
8
+ * On iOS a first connection that the Local Network question holds back is tried again until the user answers.
6
9
  */
7
10
  const useConnectAwaiter = ({ visible }) => {
8
- const [isConnecting, setConnecting] = useState(false);
11
+ const [state, setState] = useState(IDLE);
9
12
  const awaitingRef = useRef(false);
13
+ const attemptRef = useRef(null);
14
+ const retryRef = useRef(null);
10
15
  const finish = useCallback(() => {
11
16
  awaitingRef.current = false;
12
- setConnecting(false);
17
+ attemptRef.current = null;
18
+ if (retryRef.current)
19
+ clearTimeout(retryRef.current);
20
+ retryRef.current = null;
21
+ setState(IDLE);
13
22
  }, []);
14
23
  useEffect(() => subscribeSocketState(() => {
15
24
  if (!awaitingRef.current)
@@ -17,18 +26,51 @@ const useConnectAwaiter = ({ visible }) => {
17
26
  if (isConnected()) {
18
27
  finish();
19
28
  hidePrompt();
29
+ return;
20
30
  }
21
- else if (getLastError()) {
22
- finish();
31
+ const error = getLastError();
32
+ const attempt = attemptRef.current;
33
+ if (!error)
34
+ return;
35
+ if (attempt &&
36
+ shouldWaitForLocalNetwork({
37
+ platform: Platform.OS,
38
+ error,
39
+ startedAt: attempt.startedAt,
40
+ now: Date.now(),
41
+ })) {
42
+ if (retryRef.current)
43
+ return;
44
+ setState({
45
+ isConnecting: true,
46
+ notice: localNetworkNotice({
47
+ startedAt: attempt.startedAt,
48
+ now: Date.now(),
49
+ }),
50
+ });
51
+ retryRef.current = setTimeout(() => {
52
+ retryRef.current = null;
53
+ if (!awaitingRef.current)
54
+ return;
55
+ setLastError(null);
56
+ attempt.connectFn();
57
+ }, LOCAL_NETWORK.retryMs);
58
+ return;
23
59
  }
60
+ const message = localNetworkError({ platform: Platform.OS, error });
61
+ if (message !== error)
62
+ setLastError(message);
63
+ finish();
24
64
  }), [finish]);
25
65
  useEffect(() => {
26
66
  if (!visible)
27
67
  finish();
28
68
  }, [visible, finish]);
69
+ useEffect(() => finish, [finish]);
29
70
  const startConnecting = useCallback((connectFn) => {
30
71
  awaitingRef.current = true;
31
- setConnecting(true);
72
+ attemptRef.current = { connectFn, startedAt: Date.now() };
73
+ setState({ isConnecting: true, notice: null });
32
74
  connectFn();
33
75
  if (!awaitingRef.current)
34
76
  return;
@@ -36,10 +78,14 @@ const useConnectAwaiter = ({ visible }) => {
36
78
  finish();
37
79
  hidePrompt();
38
80
  }
39
- else if (!getSocket()) {
81
+ else if (!getSocket() && !getLastError()) {
40
82
  setLastError("Heimdall SDK is disabled in this build.");
41
83
  }
42
84
  }, [finish]);
43
- return { isConnecting, startConnecting };
85
+ return {
86
+ isConnecting: state.isConnecting,
87
+ notice: state.notice,
88
+ startConnecting,
89
+ };
44
90
  };
45
91
  export default useConnectAwaiter;
@@ -6,8 +6,10 @@ type Props = {
6
6
  socketError: string | null;
7
7
  theme: PromptTheme;
8
8
  isConnecting: boolean;
9
+ /** a step the user takes while it connects, e.g. the iOS Local Network question */
10
+ notice: string | null;
9
11
  startConnecting: (connectFn: () => void) => void;
10
12
  onManual: () => void;
11
13
  };
12
- declare const CloudView: ({ baseUrl, visible, socketError, theme, isConnecting, startConnecting, onManual, }: Props) => JSX.Element;
14
+ declare const CloudView: ({ baseUrl, visible, socketError, theme, isConnecting, notice, startConnecting, onManual, }: Props) => JSX.Element;
13
15
  export default CloudView;
@@ -3,10 +3,11 @@ import { Text } from "react-native";
3
3
  import ActionButton from "../ui/action-button.js";
4
4
  import Footer from "../ui/footer.js";
5
5
  import ScreenRecording from "../ui/screen-recording.js";
6
+ import StatusLine from "../ui/status-line.js";
6
7
  import Header from "../ui/header.js";
7
8
  import useCloudView from "./use-cloud-view.js";
8
9
  import styles from "./styles.js";
9
- const CloudView = ({ baseUrl, visible, socketError, theme, isConnecting, startConnecting, onManual, }) => {
10
+ const CloudView = ({ baseUrl, visible, socketError, theme, isConnecting, notice, startConnecting, onManual, }) => {
10
11
  const { deviceName, phase, message, onFindMe, onCancelLinking, onConnect, onUnlink, } = useCloudView({ baseUrl, visible, startConnecting });
11
12
  const error = isConnecting ? null : (message !== null && message !== void 0 ? message : socketError);
12
13
  const isBusy = phase !== "idle" || isConnecting;
@@ -14,7 +15,7 @@ const CloudView = ({ baseUrl, visible, socketError, theme, isConnecting, startCo
14
15
  return (_jsxs(_Fragment, { children: [_jsx(Header, { title: "Heimdall", status: "busy", theme: theme }), _jsx(Text, { style: [styles.text, { color: theme.muted }], children: "Sign in and pick this device in the browser, then come back." }), _jsx(Footer, { primary: _jsx(ActionButton, { title: "Cancel", variant: "link", theme: theme, onPress: onCancelLinking }) })] }));
15
16
  }
16
17
  return (_jsxs(_Fragment, { children: [_jsx(Header, { title: deviceName !== null && deviceName !== void 0 ? deviceName : "Heimdall", status: error ? "error" : isBusy ? "busy" : "idle", theme: theme }), _jsx(Text, { style: [styles.text, { color: theme.muted }], children: deviceName
17
- ? "Start Heimdall for this device on your Mac."
18
- : "Link this device with your Heimdall account." }), error ? (_jsx(Text, { style: [styles.error, { color: theme.danger }], children: error })) : null, _jsx(ScreenRecording, { theme: theme }), _jsx(Footer, { secondary: _jsxs(_Fragment, { children: [deviceName ? (_jsx(ActionButton, { title: "Unlink", variant: "link", theme: theme, disabled: isBusy, onPress: onUnlink })) : null, _jsx(ActionButton, { title: "Enter manually", variant: "link", theme: theme, disabled: isBusy, onPress: onManual })] }), primary: _jsx(ActionButton, { title: isConnecting ? "Connecting…" : deviceName ? "Connect" : "Find me", theme: theme, disabled: isBusy, onPress: deviceName ? onConnect : onFindMe }) })] }));
18
+ ? "Start Heimdall for this device on your computer."
19
+ : "Link this device with your Heimdall account." }), _jsx(StatusLine, { error: error, notice: notice, theme: theme }), _jsx(ScreenRecording, { theme: theme }), _jsx(Footer, { start: _jsx(ActionButton, { title: "Enter manually", variant: "link", theme: theme, disabled: isBusy, onPress: onManual }), end: deviceName ? (_jsx(ActionButton, { title: "Unlink", variant: "quiet", theme: theme, disabled: isBusy, onPress: onUnlink })) : null, primary: _jsx(ActionButton, { title: isConnecting ? "Connecting…" : deviceName ? "Connect" : "Find me", theme: theme, disabled: isBusy, onPress: deviceName ? onConnect : onFindMe }) })] }));
19
20
  };
20
21
  export default CloudView;
@@ -6,5 +6,5 @@ import Footer from "../ui/footer.js";
6
6
  import Header from "../ui/header.js";
7
7
  import ScreenRecording from "../ui/screen-recording.js";
8
8
  import styles from "./styles.js";
9
- const ConnectedView = ({ hostLabel, channel, theme, isDark, canCopy, onCopyChannel, onClose, onDisconnect, }) => (_jsxs(_Fragment, { children: [_jsx(Header, { title: "Connected", status: "connected", theme: theme }), _jsx(Text, { style: [styles.value, { color: theme.text }], children: hostLabel }), _jsxs(View, { style: styles.channelRow, children: [_jsx(Text, { style: [styles.channel, { color: theme.muted }], numberOfLines: 1, selectable: true, children: channel }), _jsx(CopyButton, { tone: isDark ? "dark" : "light", disabled: !canCopy, onPress: onCopyChannel })] }), _jsx(ScreenRecording, { theme: theme }), _jsx(Footer, { secondary: _jsx(ActionButton, { title: "Close", variant: "link", theme: theme, onPress: onClose }), primary: _jsx(ActionButton, { title: "Disconnect", variant: "danger", theme: theme, onPress: onDisconnect }) })] }));
9
+ const ConnectedView = ({ hostLabel, channel, theme, isDark, canCopy, onCopyChannel, onClose, onDisconnect, }) => (_jsxs(_Fragment, { children: [_jsx(Header, { title: "Connected", status: "connected", theme: theme }), _jsx(Text, { style: [styles.value, { color: theme.text }], children: hostLabel }), _jsxs(View, { style: styles.channelRow, children: [_jsx(Text, { style: [styles.channel, { color: theme.muted }], numberOfLines: 1, selectable: true, children: channel }), _jsx(CopyButton, { tone: isDark ? "dark" : "light", disabled: !canCopy, onPress: onCopyChannel })] }), _jsx(ScreenRecording, { theme: theme }), _jsx(Footer, { start: _jsx(ActionButton, { title: "Close", variant: "link", theme: theme, onPress: onClose }), primary: _jsx(ActionButton, { title: "Disconnect", variant: "danger", theme: theme, onPress: onDisconnect }) })] }));
10
10
  export default ConnectedView;
@@ -9,8 +9,11 @@ type Props = {
9
9
  canCopy: boolean;
10
10
  onCopyChannel: () => void;
11
11
  onConnect: () => void;
12
- onBack?: () => void;
12
+ /** back to finding the computer through Heimdall cloud: the counterpart of “Enter manually” */
13
+ onAuto?: () => void;
13
14
  isConnecting: boolean;
15
+ /** a step the user takes while it connects, e.g. the iOS Local Network question */
16
+ notice: string | null;
14
17
  };
15
- declare const ManualView: ({ ui, setUi, theme, isDark, canCopy, onCopyChannel, onConnect, onBack, isConnecting, }: Props) => JSX.Element;
18
+ declare const ManualView: ({ ui, setUi, theme, isDark, canCopy, onCopyChannel, onConnect, onAuto, isConnecting, notice, }: Props) => JSX.Element;
16
19
  export default ManualView;
@@ -5,9 +5,10 @@ import { CopyButton } from "../../copy-button/index.js";
5
5
  import ActionButton from "../ui/action-button.js";
6
6
  import Footer from "../ui/footer.js";
7
7
  import ScreenRecording from "../ui/screen-recording.js";
8
+ import StatusLine from "../ui/status-line.js";
8
9
  import Header from "../ui/header.js";
9
10
  import styles from "./styles.js";
10
- const ManualView = ({ ui, setUi, theme, isDark, canCopy, onCopyChannel, onConnect, onBack, isConnecting, }) => {
11
+ const ManualView = ({ ui, setUi, theme, isDark, canCopy, onCopyChannel, onConnect, onAuto, isConnecting, notice, }) => {
11
12
  var _a, _b;
12
13
  const error = isConnecting ? null : ui.errorMessage;
13
14
  const inputStyle = [
@@ -21,6 +22,6 @@ const ManualView = ({ ui, setUi, theme, isDark, canCopy, onCopyChannel, onConnec
21
22
  const labelStyle = [styles.label, { color: theme.muted }];
22
23
  // The host matches by this code alone, so it is what people read out and type.
23
24
  const code = (_b = (_a = parseChannel(ui.channel.trim().toLowerCase())) === null || _a === void 0 ? void 0 : _a.shortId) !== null && _b !== void 0 ? _b : null;
24
- return (_jsxs(_Fragment, { children: [_jsx(Header, { title: "Heimdall", status: isConnecting ? "busy" : error ? "error" : "idle", theme: theme }), _jsx(Text, { style: labelStyle, children: "Host" }), _jsx(TextInput, { value: ui.host, onChangeText: (text) => setUi((prev) => ({ ...prev, host: text })), style: inputStyle, autoCapitalize: "none", autoCorrect: false, editable: !isConnecting, placeholder: "127.0.0.1", placeholderTextColor: theme.idle }), _jsx(Text, { style: labelStyle, children: "Port" }), _jsx(TextInput, { value: ui.port, onChangeText: (text) => setUi((prev) => ({ ...prev, port: text })), style: inputStyle, keyboardType: "number-pad", editable: !isConnecting, placeholder: "35678", placeholderTextColor: theme.idle }), _jsx(Text, { style: labelStyle, children: "Channel" }), _jsxs(View, { style: styles.inputRow, children: [_jsx(TextInput, { value: ui.channel, onChangeText: (text) => setUi((prev) => ({ ...prev, channel: text })), style: [inputStyle, styles.inputFlex], autoCapitalize: "none", autoCorrect: false, editable: !isConnecting, placeholder: "heimdall://session-xxxxxx", placeholderTextColor: theme.idle }), _jsx(CopyButton, { tone: isDark ? "dark" : "light", disabled: !canCopy, onPress: onCopyChannel })] }), code ? (_jsxs(_Fragment, { children: [_jsx(Text, { style: labelStyle, children: "Code for Heimdall" }), _jsx(Text, { style: [styles.code, { color: theme.text }], selectable: true, children: code })] })) : null, error ? (_jsx(Text, { style: [styles.error, { color: theme.danger }], children: error })) : null, _jsx(ScreenRecording, { theme: theme }), _jsx(Footer, { secondary: onBack ? (_jsx(ActionButton, { title: "Back", variant: "link", theme: theme, disabled: isConnecting, onPress: onBack })) : null, primary: _jsx(ActionButton, { title: isConnecting ? "Connecting…" : "Connect", theme: theme, disabled: isConnecting, onPress: onConnect }) })] }));
25
+ return (_jsxs(_Fragment, { children: [_jsx(Header, { title: "Heimdall", status: isConnecting ? "busy" : error ? "error" : "idle", theme: theme }), _jsx(Text, { style: labelStyle, children: "Host" }), _jsx(TextInput, { value: ui.host, onChangeText: (text) => setUi((prev) => ({ ...prev, host: text })), style: inputStyle, autoCapitalize: "none", autoCorrect: false, editable: !isConnecting, placeholder: "127.0.0.1", placeholderTextColor: theme.idle }), _jsx(Text, { style: labelStyle, children: "Port" }), _jsx(TextInput, { value: ui.port, onChangeText: (text) => setUi((prev) => ({ ...prev, port: text })), style: inputStyle, keyboardType: "number-pad", editable: !isConnecting, placeholder: "35678", placeholderTextColor: theme.idle }), _jsx(Text, { style: labelStyle, children: "Channel" }), _jsxs(View, { style: styles.inputRow, children: [_jsx(TextInput, { value: ui.channel, onChangeText: (text) => setUi((prev) => ({ ...prev, channel: text })), style: [inputStyle, styles.inputFlex], autoCapitalize: "none", autoCorrect: false, editable: !isConnecting, placeholder: "heimdall://session-xxxxxx", placeholderTextColor: theme.idle }), _jsx(CopyButton, { tone: isDark ? "dark" : "light", disabled: !canCopy, onPress: onCopyChannel })] }), code ? (_jsxs(_Fragment, { children: [_jsx(Text, { style: labelStyle, children: "Code for Heimdall" }), _jsx(Text, { style: [styles.code, { color: theme.text }], selectable: true, children: code })] })) : null, _jsx(StatusLine, { error: error, notice: notice, theme: theme }), _jsx(ScreenRecording, { theme: theme }), _jsx(Footer, { start: onAuto ? (_jsx(ActionButton, { title: "Find automatically", variant: "link", theme: theme, disabled: isConnecting, onPress: onAuto })) : null, primary: _jsx(ActionButton, { title: isConnecting ? "Connecting…" : "Connect", theme: theme, disabled: isConnecting, onPress: onConnect }) })] }));
25
26
  };
26
27
  export default ManualView;
@@ -17,6 +17,7 @@ const useCloudView = ({ baseUrl, visible, startConnecting, }) => {
17
17
  setMessage(null);
18
18
  }, [visible]);
19
19
  const onFindMe = useCallback(async () => {
20
+ var _a;
20
21
  const defaults = getPromptState().defaults;
21
22
  cancelledRef.current = false;
22
23
  setMessage(null);
@@ -24,6 +25,7 @@ const useCloudView = ({ baseUrl, visible, startConnecting, }) => {
24
25
  try {
25
26
  const result = await linkDevice({
26
27
  baseUrl,
28
+ appKey: (_a = defaults === null || defaults === void 0 ? void 0 : defaults.cloud) === null || _a === void 0 ? void 0 : _a.appKey,
27
29
  appId: defaults === null || defaults === void 0 ? void 0 : defaults.appId,
28
30
  platform: defaults === null || defaults === void 0 ? void 0 : defaults.platform,
29
31
  installId: getOrCreateClientId(),
@@ -31,8 +31,18 @@ export type HeimdallConnectOptions = {
31
31
  id?: string;
32
32
  isEmulator?: boolean;
33
33
  };
34
- /** heimdall-cloud service: enables "Find me" device linking in the connect prompt */
34
+ /**
35
+ * heimdall-cloud service: enables "Find me" device linking in the connect prompt.
36
+ * `appKey` — the app's public key from the team's Apps page: linked devices go to the team, and Heimdall
37
+ * applies the team's AI rules to this app. Not a secret.
38
+ */
35
39
  cloud?: {
36
40
  url: string;
41
+ appKey?: string;
37
42
  };
43
+ /**
44
+ * What AI may get from this app's data in Heimdall, set by the app's developers: "strict" — the Strict data set,
45
+ * no screenshots; "off" — nothing. It can only make Heimdall stricter. Not set — Heimdall's own rules apply.
46
+ */
47
+ ai?: "strict" | "off";
38
48
  };
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const SDK_VERSION = "0.7.0";
1
+ export declare const SDK_VERSION = "0.8.0";
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const SDK_VERSION = "0.7.0";
1
+ export const SDK_VERSION = "0.8.0";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rnzeus/heimdall-sdk",
3
- "version": "0.7.0",
3
+ "version": "0.8.0",
4
4
  "description": "React Native client for Heimdall — a desktop debug inspector for network, WebSocket, Zustand and console",
5
5
  "license": "MIT",
6
6
  "author": "Volodymyr Dudkevych",
@@ -111,7 +111,7 @@
111
111
  }
112
112
  },
113
113
  "dependencies": {
114
- "@rnzeus/heimdall-protocol": "^0.6.0"
114
+ "@rnzeus/heimdall-protocol": "^0.7.0"
115
115
  },
116
116
  "devDependencies": {
117
117
  "@rnzeus/heimdall-lens": "^0.1.0",