@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.
- package/LICENSE +21 -0
- package/README.md +210 -2
- package/dist/core/cloud/client.d.ts +44 -0
- package/dist/core/cloud/client.js +65 -0
- package/dist/core/cloud/index.d.ts +4 -0
- package/dist/core/cloud/index.js +4 -0
- package/dist/core/cloud/link-device.d.ts +14 -0
- package/dist/core/cloud/link-device.js +28 -0
- package/dist/core/cloud/state.d.ts +10 -0
- package/dist/core/cloud/state.js +21 -0
- package/dist/core/cloud/storage.d.ts +7 -0
- package/dist/core/cloud/storage.js +31 -0
- package/dist/core/connection/channel/generate.d.ts +10 -0
- package/dist/core/connection/channel/generate.js +22 -0
- package/dist/core/connection/channel/index.d.ts +4 -0
- package/dist/core/connection/channel/index.js +4 -0
- package/dist/core/connection/channel/parse.d.ts +9 -0
- package/dist/core/connection/channel/parse.js +27 -0
- package/dist/core/connection/channel/sanitize.d.ts +9 -0
- package/dist/core/connection/channel/sanitize.js +15 -0
- package/dist/core/connection/channel/types.d.ts +9 -0
- package/dist/core/connection/channel/types.js +1 -0
- package/dist/core/connection/index.d.ts +7 -0
- package/dist/core/connection/index.js +7 -0
- package/dist/core/connection/lifecycle/connect.d.ts +2 -0
- package/dist/core/connection/lifecycle/connect.js +46 -0
- package/dist/core/connection/lifecycle/destroy.d.ts +1 -0
- package/dist/core/connection/lifecycle/destroy.js +12 -0
- package/dist/core/connection/lifecycle/disconnect.d.ts +1 -0
- package/dist/core/connection/lifecycle/disconnect.js +10 -0
- package/dist/core/connection/lifecycle/early-events.d.ts +2 -0
- package/dist/core/connection/lifecycle/early-events.js +18 -0
- package/dist/core/connection/lifecycle/index.d.ts +5 -0
- package/dist/core/connection/lifecycle/index.js +5 -0
- package/dist/core/connection/lifecycle/keep-alive.d.ts +5 -0
- package/dist/core/connection/lifecycle/keep-alive.js +40 -0
- package/dist/core/connection/prompt/index.d.ts +1 -0
- package/dist/core/connection/prompt/index.js +1 -0
- package/dist/core/connection/prompt/prompt-state.d.ts +12 -0
- package/dist/core/connection/prompt/prompt-state.js +30 -0
- package/dist/core/connection/resolver/cloud.d.ts +4 -0
- package/dist/core/connection/resolver/cloud.js +29 -0
- package/dist/core/connection/resolver/index.d.ts +3 -0
- package/dist/core/connection/resolver/index.js +3 -0
- package/dist/core/connection/resolver/manual.d.ts +2 -0
- package/dist/core/connection/resolver/manual.js +3 -0
- package/dist/core/connection/resolver/types.d.ts +9 -0
- package/dist/core/connection/resolver/types.js +1 -0
- package/dist/core/connection/sdk-enabled.d.ts +3 -0
- package/dist/core/connection/sdk-enabled.js +10 -0
- package/dist/core/connection/session/clear-last-connection.d.ts +1 -0
- package/dist/core/connection/session/clear-last-connection.js +11 -0
- package/dist/core/connection/session/client-id.d.ts +3 -0
- package/dist/core/connection/session/client-id.js +25 -0
- package/dist/core/connection/session/constants.d.ts +14 -0
- package/dist/core/connection/session/constants.js +21 -0
- package/dist/core/connection/session/create-session.d.ts +3 -0
- package/dist/core/connection/session/create-session.js +21 -0
- package/dist/core/connection/session/index.d.ts +6 -0
- package/dist/core/connection/session/index.js +6 -0
- package/dist/core/connection/session/load-last-connection.d.ts +2 -0
- package/dist/core/connection/session/load-last-connection.js +16 -0
- package/dist/core/connection/session/state.d.ts +7 -0
- package/dist/core/connection/session/state.js +23 -0
- package/dist/core/connection/session/types.d.ts +12 -0
- package/dist/core/connection/session/types.js +1 -0
- package/dist/core/connection/socket/connect-socket.d.ts +3 -0
- package/dist/core/connection/socket/connect-socket.js +110 -0
- package/dist/core/connection/socket/constants.d.ts +4 -0
- package/dist/core/connection/socket/constants.js +4 -0
- package/dist/core/connection/socket/destroy-socket.d.ts +1 -0
- package/dist/core/connection/socket/destroy-socket.js +4 -0
- package/dist/core/connection/socket/disconnect-socket.d.ts +1 -0
- package/dist/core/connection/socket/disconnect-socket.js +26 -0
- package/dist/core/connection/socket/early-buffer.d.ts +7 -0
- package/dist/core/connection/socket/early-buffer.js +26 -0
- package/dist/core/connection/socket/flush-early-events.d.ts +1 -0
- package/dist/core/connection/socket/flush-early-events.js +18 -0
- package/dist/core/connection/socket/handle-socket-lost.d.ts +1 -0
- package/dist/core/connection/socket/handle-socket-lost.js +24 -0
- package/dist/core/connection/socket/index.d.ts +6 -0
- package/dist/core/connection/socket/index.js +6 -0
- package/dist/core/connection/socket/normalize-socket-error.d.ts +1 -0
- package/dist/core/connection/socket/normalize-socket-error.js +13 -0
- package/dist/core/connection/socket/send-event.d.ts +3 -0
- package/dist/core/connection/socket/send-event.js +45 -0
- package/dist/core/connection/socket/state.d.ts +8 -0
- package/dist/core/connection/socket/state.js +35 -0
- package/dist/core/console/index.d.ts +2 -0
- package/dist/core/console/index.js +2 -0
- package/dist/core/console/patch-console.d.ts +1 -0
- package/dist/core/console/patch-console.js +64 -0
- package/dist/core/console/restore-console.d.ts +1 -0
- package/dist/core/console/restore-console.js +28 -0
- package/dist/core/console/send-console-event.d.ts +8 -0
- package/dist/core/console/send-console-event.js +95 -0
- package/dist/core/console/state.d.ts +19 -0
- package/dist/core/console/state.js +25 -0
- package/dist/core/mmkv/index.d.ts +0 -0
- package/dist/core/mmkv/index.js +2 -0
- package/dist/core/network/get-interceptor.d.ts +11 -0
- package/dist/core/network/get-interceptor.js +19 -0
- package/dist/core/network/headers.d.ts +6 -0
- package/dist/core/network/headers.js +46 -0
- package/dist/core/network/index.d.ts +2 -0
- package/dist/core/network/index.js +2 -0
- package/dist/core/network/patch-xhr.d.ts +2 -0
- package/dist/core/network/patch-xhr.js +40 -0
- package/dist/core/network/restore-xhr.d.ts +1 -0
- package/dist/core/network/restore-xhr.js +40 -0
- package/dist/core/network/rn-blob.d.ts +1 -0
- package/dist/core/network/rn-blob.js +15 -0
- package/dist/core/network/should-skip.d.ts +2 -0
- package/dist/core/network/should-skip.js +30 -0
- package/dist/core/network/state.d.ts +5 -0
- package/dist/core/network/state.js +14 -0
- package/dist/core/network/xhr-callbacks.d.ts +12 -0
- package/dist/core/network/xhr-callbacks.js +169 -0
- package/dist/core/network/xhr-runtime-state.d.ts +4 -0
- package/dist/core/network/xhr-runtime-state.js +15 -0
- package/dist/core/network/xhr-types.d.ts +33 -0
- package/dist/core/network/xhr-types.js +1 -0
- package/dist/core/public.d.ts +2 -0
- package/dist/core/public.js +1 -0
- package/dist/core/react-query/index.d.ts +0 -0
- package/dist/core/react-query/index.js +2 -0
- package/dist/core/system/dev-server.d.ts +6 -0
- package/dist/core/system/dev-server.js +37 -0
- package/dist/core/system/device-info.d.ts +3 -0
- package/dist/core/system/device-info.js +46 -0
- package/dist/core/system/index.d.ts +2 -0
- package/dist/core/system/index.js +2 -0
- package/dist/core/websocket/index.d.ts +2 -0
- package/dist/core/websocket/index.js +2 -0
- package/dist/core/websocket/patch-websocket.d.ts +2 -0
- package/dist/core/websocket/patch-websocket.js +247 -0
- package/dist/core/websocket/restore-websocket.d.ts +1 -0
- package/dist/core/websocket/restore-websocket.js +16 -0
- package/dist/core/websocket/should-skip.d.ts +2 -0
- package/dist/core/websocket/should-skip.js +22 -0
- package/dist/core/websocket/state.d.ts +9 -0
- package/dist/core/websocket/state.js +21 -0
- package/dist/core/zustand/index.d.ts +1 -0
- package/dist/core/zustand/index.js +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +3 -0
- package/dist/public/copy-button/component.d.ts +9 -0
- package/dist/public/copy-button/component.js +13 -0
- package/dist/public/copy-button/index.d.ts +1 -0
- package/dist/public/copy-button/index.js +1 -0
- package/dist/public/copy-button/styles.d.ts +64 -0
- package/dist/public/copy-button/styles.js +52 -0
- package/dist/public/index.d.ts +1 -0
- package/dist/public/index.js +1 -0
- package/dist/public/prompt/component.d.ts +7 -0
- package/dist/public/prompt/component.js +56 -0
- package/dist/public/prompt/index.d.ts +1 -0
- package/dist/public/prompt/index.js +1 -0
- package/dist/public/prompt/prompt-mode.d.ts +3 -0
- package/dist/public/prompt/prompt-mode.js +19 -0
- package/dist/public/prompt/styles.d.ts +23 -0
- package/dist/public/prompt/styles.js +23 -0
- package/dist/public/prompt/theme.d.ts +16 -0
- package/dist/public/prompt/theme.js +32 -0
- package/dist/public/prompt/types.d.ts +12 -0
- package/dist/public/prompt/types.js +1 -0
- package/dist/public/prompt/ui/action-button.d.ts +11 -0
- package/dist/public/prompt/ui/action-button.js +23 -0
- package/dist/public/prompt/ui/footer.d.ts +7 -0
- package/dist/public/prompt/ui/footer.js +13 -0
- package/dist/public/prompt/ui/header.d.ts +10 -0
- package/dist/public/prompt/ui/header.js +17 -0
- package/dist/public/prompt/ui/report-link.d.ts +8 -0
- package/dist/public/prompt/ui/report-link.js +19 -0
- package/dist/public/prompt/use-connect-awaiter.d.ts +11 -0
- package/dist/public/prompt/use-connect-awaiter.js +45 -0
- package/dist/public/prompt/use-prompt-animation.d.ts +17 -0
- package/dist/public/prompt/use-prompt-animation.js +53 -0
- package/dist/public/prompt/use-prompt-ui.d.ts +3 -0
- package/dist/public/prompt/use-prompt-ui.js +99 -0
- package/dist/public/prompt/use-prompt.d.ts +11 -0
- package/dist/public/prompt/use-prompt.js +43 -0
- package/dist/public/prompt/views/cloud-view.d.ts +13 -0
- package/dist/public/prompt/views/cloud-view.js +19 -0
- package/dist/public/prompt/views/connected-view.d.ts +14 -0
- package/dist/public/prompt/views/connected-view.js +9 -0
- package/dist/public/prompt/views/manual-view.d.ts +16 -0
- package/dist/public/prompt/views/manual-view.js +21 -0
- package/dist/public/prompt/views/styles.d.ts +44 -0
- package/dist/public/prompt/views/styles.js +23 -0
- package/dist/public/prompt/views/use-cloud-view.d.ts +15 -0
- package/dist/public/prompt/views/use-cloud-view.js +103 -0
- package/dist/public/public.d.ts +1 -0
- package/dist/public/public.js +1 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/index.js +2 -0
- package/dist/types/options.d.ts +30 -0
- package/dist/types/options.js +1 -0
- package/dist/types/protocol.d.ts +1 -0
- package/dist/types/protocol.js +1 -0
- package/dist/types/public.d.ts +1 -0
- package/dist/types/public.js +1 -0
- package/dist/utils/body-snippet.d.ts +19 -0
- package/dist/utils/body-snippet.js +186 -0
- package/dist/utils/debug-log.d.ts +26 -0
- package/dist/utils/debug-log.js +44 -0
- package/dist/utils/generate-random-id.d.ts +1 -0
- package/dist/utils/generate-random-id.js +8 -0
- package/dist/utils/index.d.ts +5 -0
- package/dist/utils/index.js +5 -0
- package/dist/utils/parse-url.d.ts +5 -0
- package/dist/utils/parse-url.js +32 -0
- package/dist/utils/safe-serialize.d.ts +6 -0
- package/dist/utils/safe-serialize.js +77 -0
- package/dist/version.d.ts +1 -0
- package/dist/version.js +1 -0
- package/dist/zustand/index.d.ts +1 -0
- package/dist/zustand/index.js +1 -0
- package/dist/zustand/middleware.d.ts +18 -0
- package/dist/zustand/middleware.js +77 -0
- package/package.json +88 -4
- package/zustand/index.d.ts +1 -0
- package/zustand/index.js +1 -0
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export async function readRNBlobAsText(blob) {
|
|
2
|
+
var _a;
|
|
3
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
4
|
+
const mod = require("react-native/Libraries/Blob/FileReader");
|
|
5
|
+
const BlobFileReader = (_a = mod.default) !== null && _a !== void 0 ? _a : mod;
|
|
6
|
+
const reader = new BlobFileReader();
|
|
7
|
+
reader.readAsText(blob);
|
|
8
|
+
return await new Promise((resolve, reject) => {
|
|
9
|
+
const onLoad = () => { var _a; return resolve(String((_a = reader.result) !== null && _a !== void 0 ? _a : "")); };
|
|
10
|
+
const onErr = () => { var _a; return reject((_a = reader.error) !== null && _a !== void 0 ? _a : new Error("blob_read_error")); };
|
|
11
|
+
reader.addEventListener("load", onLoad);
|
|
12
|
+
reader.addEventListener("error", onErr);
|
|
13
|
+
reader.addEventListener("abort", onErr);
|
|
14
|
+
});
|
|
15
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { isCloudHost } from "../cloud/state.js";
|
|
2
|
+
import { isDevServerHost } from "../system/index.js";
|
|
3
|
+
function matchList(value, list) {
|
|
4
|
+
if (!list || list.length === 0)
|
|
5
|
+
return false;
|
|
6
|
+
return list.some((rule) => typeof rule === "string" ? value === rule : rule.test(value));
|
|
7
|
+
}
|
|
8
|
+
export function shouldSkip(url, host, path, filters) {
|
|
9
|
+
if (isCloudHost(host))
|
|
10
|
+
return true;
|
|
11
|
+
if (isDevServerHost(host))
|
|
12
|
+
return true;
|
|
13
|
+
if (host.startsWith("localhost")) {
|
|
14
|
+
if (path.startsWith("/symbolicate") ||
|
|
15
|
+
path.startsWith("/open-debugger") ||
|
|
16
|
+
path.startsWith("/onchange")) {
|
|
17
|
+
return true;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
if (matchList(url, filters.ignoreUrls) ||
|
|
21
|
+
matchList(path, filters.ignoreUrls)) {
|
|
22
|
+
return true;
|
|
23
|
+
}
|
|
24
|
+
if (filters.allowedHosts && filters.allowedHosts.length > 0) {
|
|
25
|
+
if (!matchList(host, filters.allowedHosts)) {
|
|
26
|
+
return true;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { NetworkFilters } from "../../types";
|
|
2
|
+
export declare function getFilters(): NetworkFilters;
|
|
3
|
+
export declare function setFilters(value: NetworkFilters): void;
|
|
4
|
+
export declare function isPatched(): boolean;
|
|
5
|
+
export declare function setPatched(value: boolean): void;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
let patched = false;
|
|
2
|
+
let filters = {};
|
|
3
|
+
export function getFilters() {
|
|
4
|
+
return filters;
|
|
5
|
+
}
|
|
6
|
+
export function setFilters(value) {
|
|
7
|
+
filters = value;
|
|
8
|
+
}
|
|
9
|
+
export function isPatched() {
|
|
10
|
+
return patched;
|
|
11
|
+
}
|
|
12
|
+
export function setPatched(value) {
|
|
13
|
+
patched = value;
|
|
14
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { NetworkFilters } from "../../types";
|
|
2
|
+
import type { HeadersMap, Meta, XHR } from "./xhr-types";
|
|
3
|
+
export declare function createXhrCallbacks(deps: {
|
|
4
|
+
requests: Map<number, Meta>;
|
|
5
|
+
getFilters: () => NetworkFilters;
|
|
6
|
+
}): {
|
|
7
|
+
openCallback: (method: string, url: string, xhr: XHR) => void;
|
|
8
|
+
requestHeadersCallback: (header: string, value: string, xhr: XHR) => void;
|
|
9
|
+
headerReceivedCallback: (responseContentType: string, responseSize: number, responseHeaders: HeadersMap, xhr: XHR) => void;
|
|
10
|
+
sendCallback: (data: any, xhr: XHR) => void;
|
|
11
|
+
responseCallback: (status: number, timeout: number, response: any, responseURL: string, responseType: string, xhr: XHR) => void;
|
|
12
|
+
};
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import { shouldSkip } from "./should-skip.js";
|
|
2
|
+
import { generateRandomId, parseUrl } from "../../utils/index.js";
|
|
3
|
+
import { sendEvent } from "../connection/index.js";
|
|
4
|
+
import { normaliseHeaderName, normaliseResponseHeaders, } from "./headers.js";
|
|
5
|
+
import { buildBodySnippet, debugLog } from "../../utils/index.js";
|
|
6
|
+
import { nextXhrIndex } from "./xhr-runtime-state.js";
|
|
7
|
+
import { readRNBlobAsText } from "./rn-blob.js";
|
|
8
|
+
export function createXhrCallbacks(deps) {
|
|
9
|
+
const { requests, getFilters } = deps;
|
|
10
|
+
const openCallback = (method, url, xhr) => {
|
|
11
|
+
const fullUrl = String(url !== null && url !== void 0 ? url : "");
|
|
12
|
+
const { host, path } = parseUrl(fullUrl);
|
|
13
|
+
if (shouldSkip(fullUrl, host, path, getFilters())) {
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
xhr._index = nextXhrIndex();
|
|
17
|
+
const meta = {
|
|
18
|
+
tsStart: 0,
|
|
19
|
+
requestId: "",
|
|
20
|
+
method: String(method || "GET").toUpperCase(),
|
|
21
|
+
url: fullUrl,
|
|
22
|
+
host,
|
|
23
|
+
path,
|
|
24
|
+
requestHeaders: {},
|
|
25
|
+
};
|
|
26
|
+
requests.set(xhr._index, meta);
|
|
27
|
+
};
|
|
28
|
+
const requestHeadersCallback = (header, value, xhr) => {
|
|
29
|
+
const meta = requests.get(xhr._index);
|
|
30
|
+
if (!meta)
|
|
31
|
+
return;
|
|
32
|
+
const key = normaliseHeaderName(header);
|
|
33
|
+
if (!key)
|
|
34
|
+
return;
|
|
35
|
+
if (value == null)
|
|
36
|
+
return;
|
|
37
|
+
meta.requestHeaders[key] = String(value);
|
|
38
|
+
};
|
|
39
|
+
const headerReceivedCallback = (responseContentType, responseSize, responseHeaders, xhr) => {
|
|
40
|
+
const meta = requests.get(xhr._index);
|
|
41
|
+
if (!meta)
|
|
42
|
+
return;
|
|
43
|
+
meta.responseHeaders = normaliseResponseHeaders(responseHeaders);
|
|
44
|
+
meta.responseContentType = String(responseContentType !== null && responseContentType !== void 0 ? responseContentType : "");
|
|
45
|
+
meta.responseSize = Number(responseSize !== null && responseSize !== void 0 ? responseSize : 0);
|
|
46
|
+
};
|
|
47
|
+
const sendCallback = (data, xhr) => {
|
|
48
|
+
const meta = requests.get(xhr._index);
|
|
49
|
+
if (!meta)
|
|
50
|
+
return;
|
|
51
|
+
const tsStart = Date.now();
|
|
52
|
+
meta.tsStart = tsStart;
|
|
53
|
+
meta.requestId = `${tsStart}-${Math.random().toString(16).slice(2)}`;
|
|
54
|
+
const requestContentType = meta.requestHeaders["content-type"];
|
|
55
|
+
const reqBody = buildBodySnippet(data, { contentType: requestContentType });
|
|
56
|
+
meta.requestBodySnippet = reqBody.snippet;
|
|
57
|
+
meta.requestBodySize = reqBody.sizeBytes;
|
|
58
|
+
meta.requestBodySnippetBytes = reqBody.snippetBytes;
|
|
59
|
+
meta.requestBodyTruncated = reqBody.truncated;
|
|
60
|
+
if (reqBody.isBlob) {
|
|
61
|
+
meta.__requestBlob = data;
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
meta.__requestBlob = undefined;
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
const responseCallback = (status, timeout, response, responseURL, responseType, xhr) => {
|
|
68
|
+
const meta = requests.get(xhr._index);
|
|
69
|
+
if (!meta)
|
|
70
|
+
return;
|
|
71
|
+
meta.responseURL = responseURL;
|
|
72
|
+
meta.responseType = responseType;
|
|
73
|
+
const tsEnd = Date.now();
|
|
74
|
+
const ok = typeof status === "number" && status >= 200 && status < 300;
|
|
75
|
+
const responseHeaders = meta.responseHeaders && Object.keys(meta.responseHeaders).length > 0
|
|
76
|
+
? meta.responseHeaders
|
|
77
|
+
: xhr.responseHeaders
|
|
78
|
+
? normaliseResponseHeaders(xhr.responseHeaders)
|
|
79
|
+
: {};
|
|
80
|
+
const responseContentType = meta.responseContentType || responseHeaders["content-type"];
|
|
81
|
+
const resBody = buildBodySnippet(response, {
|
|
82
|
+
contentType: responseContentType,
|
|
83
|
+
});
|
|
84
|
+
let responseBodySnippet = resBody.snippet;
|
|
85
|
+
let responseBodySize = resBody.sizeBytes;
|
|
86
|
+
let responseBodySnippetBytes = resBody.snippetBytes;
|
|
87
|
+
let responseBodyTruncated = resBody.truncated;
|
|
88
|
+
if (resBody.isBlob) {
|
|
89
|
+
meta.__responseBlob = response;
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
meta.__responseBlob = undefined;
|
|
93
|
+
}
|
|
94
|
+
const basePayload = {
|
|
95
|
+
id: generateRandomId(),
|
|
96
|
+
type: "network",
|
|
97
|
+
transport: "xhr",
|
|
98
|
+
requestId: meta.requestId || `${tsEnd}-unknown`,
|
|
99
|
+
tsStart: meta.tsStart || tsEnd,
|
|
100
|
+
tsEnd,
|
|
101
|
+
method: meta.method,
|
|
102
|
+
url: meta.url,
|
|
103
|
+
host: meta.host,
|
|
104
|
+
path: meta.path,
|
|
105
|
+
status: typeof status === "number" ? status : undefined,
|
|
106
|
+
ok,
|
|
107
|
+
durationMs: tsEnd - (meta.tsStart || tsEnd),
|
|
108
|
+
error: timeout ? "xhr_timeout" : ok ? undefined : "xhr_error",
|
|
109
|
+
requestHeaders: meta.requestHeaders,
|
|
110
|
+
responseHeaders,
|
|
111
|
+
requestContentType: meta.requestHeaders["content-type"],
|
|
112
|
+
responseContentType,
|
|
113
|
+
};
|
|
114
|
+
const finalizeAndSend = async () => {
|
|
115
|
+
if (meta.__requestBlob) {
|
|
116
|
+
try {
|
|
117
|
+
const txt = await readRNBlobAsText(meta.__requestBlob);
|
|
118
|
+
const reqBody = buildBodySnippet(txt, {
|
|
119
|
+
contentType: meta.requestHeaders["content-type"],
|
|
120
|
+
});
|
|
121
|
+
meta.requestBodySnippet = reqBody.snippet;
|
|
122
|
+
meta.requestBodySize = reqBody.sizeBytes;
|
|
123
|
+
meta.requestBodySnippetBytes = reqBody.snippetBytes;
|
|
124
|
+
meta.requestBodyTruncated = reqBody.truncated;
|
|
125
|
+
}
|
|
126
|
+
catch {
|
|
127
|
+
// ignore
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
if (meta.__responseBlob) {
|
|
131
|
+
try {
|
|
132
|
+
const txt = await readRNBlobAsText(meta.__responseBlob);
|
|
133
|
+
const resBody = buildBodySnippet(txt, {
|
|
134
|
+
contentType: responseContentType,
|
|
135
|
+
});
|
|
136
|
+
responseBodySnippet = resBody.snippet;
|
|
137
|
+
responseBodySize = resBody.sizeBytes;
|
|
138
|
+
responseBodySnippetBytes = resBody.snippetBytes;
|
|
139
|
+
responseBodyTruncated = resBody.truncated;
|
|
140
|
+
}
|
|
141
|
+
catch {
|
|
142
|
+
// ignore
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
const payload = {
|
|
146
|
+
...basePayload,
|
|
147
|
+
requestBodySnippet: meta.requestBodySnippet,
|
|
148
|
+
requestBodySize: meta.requestBodySize,
|
|
149
|
+
responseBodySnippet,
|
|
150
|
+
responseBodySize,
|
|
151
|
+
requestBodySnippetBytes: meta.requestBodySnippetBytes,
|
|
152
|
+
responseBodySnippetBytes,
|
|
153
|
+
requestBodyTruncated: meta.requestBodyTruncated,
|
|
154
|
+
responseBodyTruncated,
|
|
155
|
+
};
|
|
156
|
+
debugLog("network", `sendEvent: ${meta.method} ${meta.url} status=${status} ok=${ok}`);
|
|
157
|
+
sendEvent(payload);
|
|
158
|
+
requests.delete(xhr._index);
|
|
159
|
+
};
|
|
160
|
+
void finalizeAndSend();
|
|
161
|
+
};
|
|
162
|
+
return {
|
|
163
|
+
openCallback,
|
|
164
|
+
requestHeadersCallback,
|
|
165
|
+
headerReceivedCallback,
|
|
166
|
+
sendCallback,
|
|
167
|
+
responseCallback,
|
|
168
|
+
};
|
|
169
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { XHRInterceptorModule } from "./get-interceptor";
|
|
2
|
+
import type { HeimdallXhrState } from "./xhr-types";
|
|
3
|
+
export declare function nextXhrIndex(): number;
|
|
4
|
+
export declare function getOrCreateHeimdallXhrState(interceptor: XHRInterceptorModule): HeimdallXhrState;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
let nextXHRId = 0;
|
|
2
|
+
export function nextXhrIndex() {
|
|
3
|
+
return nextXHRId++;
|
|
4
|
+
}
|
|
5
|
+
export function getOrCreateHeimdallXhrState(interceptor) {
|
|
6
|
+
const g = globalThis;
|
|
7
|
+
if (!g.__heimdallXhrState) {
|
|
8
|
+
g.__heimdallXhrState = {
|
|
9
|
+
enabled: false,
|
|
10
|
+
interceptor,
|
|
11
|
+
requests: new Map(),
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
return g.__heimdallXhrState;
|
|
15
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { XHRInterceptorModule } from "./get-interceptor";
|
|
2
|
+
export type HeadersMap = Record<string, string>;
|
|
3
|
+
export type XHR = {
|
|
4
|
+
_index: number;
|
|
5
|
+
responseHeaders?: HeadersMap;
|
|
6
|
+
};
|
|
7
|
+
export type Meta = {
|
|
8
|
+
tsStart: number;
|
|
9
|
+
requestId: string;
|
|
10
|
+
method: string;
|
|
11
|
+
url: string;
|
|
12
|
+
host: string;
|
|
13
|
+
path: string;
|
|
14
|
+
requestHeaders: HeadersMap;
|
|
15
|
+
requestBodySnippet?: string;
|
|
16
|
+
requestBodySize?: number;
|
|
17
|
+
requestBodySnippetBytes?: number;
|
|
18
|
+
requestBodyTruncated?: boolean;
|
|
19
|
+
responseHeaders?: HeadersMap;
|
|
20
|
+
responseContentType?: string;
|
|
21
|
+
responseSize?: number;
|
|
22
|
+
responseURL?: string;
|
|
23
|
+
responseType?: string;
|
|
24
|
+
responseBodySnippetBytes?: number;
|
|
25
|
+
responseBodyTruncated?: boolean;
|
|
26
|
+
__requestBlob?: any;
|
|
27
|
+
__responseBlob?: any;
|
|
28
|
+
};
|
|
29
|
+
export type HeimdallXhrState = {
|
|
30
|
+
enabled: boolean;
|
|
31
|
+
interceptor: XHRInterceptorModule;
|
|
32
|
+
requests: Map<number, Meta>;
|
|
33
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { connect, disconnect, configureConnectPrompt, showPrompt as showSDKConnectPrompt, } from "./connection/index.js";
|
|
File without changes
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* host:port of the Metro server the bundle was loaded from (e.g. "127.0.0.1:8081"),
|
|
3
|
+
* or null for an embedded release bundle. Traffic to it is RN tooling, never app traffic.
|
|
4
|
+
*/
|
|
5
|
+
export declare function getDevServerHost(): string | null;
|
|
6
|
+
export declare function isDevServerHost(host: string): boolean;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { NativeModules, TurboModuleRegistry } from "react-native";
|
|
2
|
+
let cachedHost;
|
|
3
|
+
const hostOf = (url) => {
|
|
4
|
+
if (typeof url !== "string")
|
|
5
|
+
return null;
|
|
6
|
+
const match = /^https?:\/\/([^/?#]+)/i.exec(url);
|
|
7
|
+
return match ? match[1].toLowerCase() : null;
|
|
8
|
+
};
|
|
9
|
+
const readScriptUrl = () => {
|
|
10
|
+
var _a, _b, _c;
|
|
11
|
+
try {
|
|
12
|
+
const turbo = TurboModuleRegistry.get("SourceCode");
|
|
13
|
+
const url = (_a = turbo === null || turbo === void 0 ? void 0 : turbo.getConstants) === null || _a === void 0 ? void 0 : _a.call(turbo).scriptURL;
|
|
14
|
+
if (url)
|
|
15
|
+
return url;
|
|
16
|
+
}
|
|
17
|
+
catch { }
|
|
18
|
+
try {
|
|
19
|
+
const legacy = NativeModules.SourceCode;
|
|
20
|
+
return (_c = (_b = legacy === null || legacy === void 0 ? void 0 : legacy.getConstants) === null || _b === void 0 ? void 0 : _b.call(legacy).scriptURL) !== null && _c !== void 0 ? _c : legacy === null || legacy === void 0 ? void 0 : legacy.scriptURL;
|
|
21
|
+
}
|
|
22
|
+
catch { }
|
|
23
|
+
return null;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* host:port of the Metro server the bundle was loaded from (e.g. "127.0.0.1:8081"),
|
|
27
|
+
* or null for an embedded release bundle. Traffic to it is RN tooling, never app traffic.
|
|
28
|
+
*/
|
|
29
|
+
export function getDevServerHost() {
|
|
30
|
+
if (cachedHost === undefined)
|
|
31
|
+
cachedHost = hostOf(readScriptUrl());
|
|
32
|
+
return cachedHost;
|
|
33
|
+
}
|
|
34
|
+
export function isDevServerHost(host) {
|
|
35
|
+
const devServer = getDevServerHost();
|
|
36
|
+
return devServer !== null && host.toLowerCase() === devServer;
|
|
37
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { Platform } from "react-native";
|
|
2
|
+
const text = (value) => {
|
|
3
|
+
if (value === null || value === undefined)
|
|
4
|
+
return undefined;
|
|
5
|
+
const out = String(value).trim();
|
|
6
|
+
return out ? out : undefined;
|
|
7
|
+
};
|
|
8
|
+
const compact = (input) => {
|
|
9
|
+
const out = {};
|
|
10
|
+
for (const [key, value] of Object.entries(input)) {
|
|
11
|
+
if (value !== undefined)
|
|
12
|
+
out[key] = value;
|
|
13
|
+
}
|
|
14
|
+
return Object.keys(out).length > 0 ? out : undefined;
|
|
15
|
+
};
|
|
16
|
+
export function readDeviceInfo() {
|
|
17
|
+
var _a, _b, _c;
|
|
18
|
+
try {
|
|
19
|
+
const constants = (_a = Platform.constants) !== null && _a !== void 0 ? _a : {};
|
|
20
|
+
if (Platform.OS === "android") {
|
|
21
|
+
return compact({
|
|
22
|
+
os: "android",
|
|
23
|
+
osVersion: (_b = text(constants.Release)) !== null && _b !== void 0 ? _b : text(Platform.Version),
|
|
24
|
+
model: text(constants.Model),
|
|
25
|
+
manufacturer: text(constants.Manufacturer),
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
return compact({
|
|
29
|
+
os: text(Platform.OS),
|
|
30
|
+
osVersion: (_c = text(constants.osVersion)) !== null && _c !== void 0 ? _c : text(Platform.Version),
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
catch {
|
|
34
|
+
return undefined;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
export function normaliseAppInfo(app) {
|
|
38
|
+
if (!app || typeof app !== "object")
|
|
39
|
+
return undefined;
|
|
40
|
+
const input = app;
|
|
41
|
+
return compact({
|
|
42
|
+
version: text(input.version),
|
|
43
|
+
build: text(input.build),
|
|
44
|
+
environment: text(input.environment),
|
|
45
|
+
});
|
|
46
|
+
}
|