@allstak/react-native 0.3.0 → 0.3.1
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/AllStakRN.podspec +25 -0
- package/README.md +369 -145
- package/build-hooks/allstak-sourcemaps.gradle +132 -0
- package/build-hooks/eas-post-bundle.js +127 -0
- package/build-hooks/upload-sourcemaps.js +175 -0
- package/build-hooks/xcode-build-phase.sh +90 -0
- package/dist/build/sourcemaps.d.mts +94 -0
- package/dist/build/sourcemaps.d.ts +94 -0
- package/dist/build/sourcemaps.js +142 -0
- package/dist/build/sourcemaps.js.map +1 -0
- package/dist/build/sourcemaps.mjs +115 -0
- package/dist/build/sourcemaps.mjs.map +1 -0
- package/dist/index.d.mts +198 -20
- package/dist/index.d.ts +198 -20
- package/dist/index.js +383 -74
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +378 -79
- package/dist/index.mjs.map +1 -1
- package/native/android/src/main/java/io/allstak/rn/AllStakRNModule.java +17 -0
- package/native/ios/AllStakRNModule.m +16 -0
- package/package.json +17 -2
package/dist/index.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
5
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
8
|
var __export = (target, all) => {
|
|
7
9
|
for (var name in all)
|
|
@@ -15,6 +17,14 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
15
17
|
}
|
|
16
18
|
return to;
|
|
17
19
|
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
18
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
29
|
|
|
20
30
|
// src/index.ts
|
|
@@ -22,19 +32,26 @@ var index_exports = {};
|
|
|
22
32
|
__export(index_exports, {
|
|
23
33
|
AllStak: () => AllStak,
|
|
24
34
|
AllStakClient: () => AllStakClient,
|
|
35
|
+
AllStakProvider: () => AllStakProvider,
|
|
25
36
|
HttpRequestModule: () => HttpRequestModule,
|
|
26
37
|
INGEST_HOST: () => INGEST_HOST,
|
|
27
38
|
ReplaySurrogate: () => ReplaySurrogate,
|
|
28
39
|
SDK_NAME: () => SDK_NAME,
|
|
29
40
|
SDK_VERSION: () => SDK_VERSION,
|
|
30
41
|
Scope: () => Scope,
|
|
42
|
+
__devTriggerNativeCrash: () => __devTriggerNativeCrash,
|
|
43
|
+
__resetAutoNavigationFlagForTest: () => __resetAutoNavigationFlagForTest,
|
|
44
|
+
__resetConsoleInstrumentationFlagForTest: () => __resetConsoleInstrumentationFlagForTest,
|
|
45
|
+
__resetProviderInstanceForTest: () => __resetProviderInstanceForTest,
|
|
31
46
|
__setNativeModuleForTest: () => __setNativeModuleForTest,
|
|
32
47
|
applyArchitectureTags: () => applyArchitectureTags,
|
|
33
48
|
detectArchitecture: () => detectArchitecture,
|
|
34
49
|
drainPendingNativeCrashes: () => drainPendingNativeCrashes,
|
|
35
50
|
installReactNative: () => installReactNative,
|
|
36
51
|
instrumentNavigationFromLinking: () => instrumentNavigationFromLinking,
|
|
37
|
-
instrumentReactNavigation: () => instrumentReactNavigation
|
|
52
|
+
instrumentReactNavigation: () => instrumentReactNavigation,
|
|
53
|
+
tryAutoInstrumentNavigation: () => tryAutoInstrumentNavigation,
|
|
54
|
+
useAllStak: () => useAllStak
|
|
38
55
|
});
|
|
39
56
|
module.exports = __toCommonJS(index_exports);
|
|
40
57
|
|
|
@@ -1003,7 +1020,7 @@ function installHttpInstrumentation(module2, options, ownIngestHost) {
|
|
|
1003
1020
|
// src/client.ts
|
|
1004
1021
|
var INGEST_HOST = "https://api.allstak.sa";
|
|
1005
1022
|
var SDK_NAME = "allstak-react-native";
|
|
1006
|
-
var SDK_VERSION = "0.3.
|
|
1023
|
+
var SDK_VERSION = "0.3.1";
|
|
1007
1024
|
var ERRORS_PATH = "/ingest/v1/errors";
|
|
1008
1025
|
var LOGS_PATH = "/ingest/v1/logs";
|
|
1009
1026
|
var VALID_BREADCRUMB_TYPES = /* @__PURE__ */ new Set(["http", "log", "ui", "navigation", "query", "default"]);
|
|
@@ -1484,6 +1501,9 @@ var AllStak = {
|
|
|
1484
1501
|
}
|
|
1485
1502
|
};
|
|
1486
1503
|
|
|
1504
|
+
// src/provider.tsx
|
|
1505
|
+
var React = __toESM(require("react"));
|
|
1506
|
+
|
|
1487
1507
|
// src/auto-breadcrumbs.ts
|
|
1488
1508
|
var FETCH_FLAG2 = "__allstak_fetch_patched__";
|
|
1489
1509
|
var CONSOLE_FLAG = "__allstak_console_patched__";
|
|
@@ -1530,36 +1550,92 @@ function instrumentFetch(addBreadcrumb, ownBaseUrl) {
|
|
|
1530
1550
|
wrapped[FETCH_FLAG2] = true;
|
|
1531
1551
|
g.fetch = wrapped;
|
|
1532
1552
|
}
|
|
1533
|
-
|
|
1553
|
+
var CONSOLE_DEFAULTS = {
|
|
1554
|
+
log: false,
|
|
1555
|
+
info: false,
|
|
1556
|
+
warn: true,
|
|
1557
|
+
error: true
|
|
1558
|
+
};
|
|
1559
|
+
var CONSOLE_METHOD_TO_LEVEL = {
|
|
1560
|
+
log: "info",
|
|
1561
|
+
info: "info",
|
|
1562
|
+
warn: "warn",
|
|
1563
|
+
error: "error"
|
|
1564
|
+
};
|
|
1565
|
+
var MAX_ARG_BYTES = 5e3;
|
|
1566
|
+
function instrumentConsole(addBreadcrumb, options = {}) {
|
|
1534
1567
|
if (typeof console === "undefined") return;
|
|
1535
1568
|
if (console[CONSOLE_FLAG]) return;
|
|
1536
|
-
const
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
} catch {
|
|
1542
|
-
}
|
|
1543
|
-
return origWarn.apply(console, args);
|
|
1569
|
+
const opts = {
|
|
1570
|
+
log: options.log ?? CONSOLE_DEFAULTS.log,
|
|
1571
|
+
info: options.info ?? CONSOLE_DEFAULTS.info,
|
|
1572
|
+
warn: options.warn ?? CONSOLE_DEFAULTS.warn,
|
|
1573
|
+
error: options.error ?? CONSOLE_DEFAULTS.error
|
|
1544
1574
|
};
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1575
|
+
const wrap = (method) => {
|
|
1576
|
+
const orig = console[method];
|
|
1577
|
+
if (typeof orig !== "function") return;
|
|
1578
|
+
const level = CONSOLE_METHOD_TO_LEVEL[method];
|
|
1579
|
+
console[method] = function(...args) {
|
|
1580
|
+
if (opts[method]) {
|
|
1581
|
+
try {
|
|
1582
|
+
const serialized = args.map(safeStringifyArg);
|
|
1583
|
+
const message = truncate(serialized.join(" "));
|
|
1584
|
+
addBreadcrumb("log", message, level, {
|
|
1585
|
+
category: "console",
|
|
1586
|
+
method,
|
|
1587
|
+
args: serialized
|
|
1588
|
+
});
|
|
1589
|
+
} catch {
|
|
1590
|
+
}
|
|
1591
|
+
}
|
|
1592
|
+
return orig.apply(console, args);
|
|
1593
|
+
};
|
|
1551
1594
|
};
|
|
1595
|
+
if (opts.log) wrap("log");
|
|
1596
|
+
if (opts.info) wrap("info");
|
|
1597
|
+
if (opts.warn) wrap("warn");
|
|
1598
|
+
if (opts.error) wrap("error");
|
|
1552
1599
|
console[CONSOLE_FLAG] = true;
|
|
1553
1600
|
}
|
|
1554
|
-
function
|
|
1555
|
-
if (
|
|
1601
|
+
function __resetConsoleInstrumentationFlagForTest() {
|
|
1602
|
+
if (typeof console !== "undefined") {
|
|
1603
|
+
delete console[CONSOLE_FLAG];
|
|
1604
|
+
}
|
|
1605
|
+
}
|
|
1606
|
+
function safeStringifyArg(v) {
|
|
1607
|
+
if (v === null || v === void 0) return String(v);
|
|
1556
1608
|
if (typeof v === "string") return v;
|
|
1557
|
-
if (v
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
return
|
|
1609
|
+
if (typeof v === "number" || typeof v === "boolean" || typeof v === "bigint") return String(v);
|
|
1610
|
+
if (typeof v === "symbol") return v.toString();
|
|
1611
|
+
if (typeof v === "function") return `[Function${v.name ? ` ${v.name}` : ""}]`;
|
|
1612
|
+
if (v instanceof Error) {
|
|
1613
|
+
return `${v.name || "Error"}: ${v.message}${v.stack ? `
|
|
1614
|
+
${v.stack}` : ""}`;
|
|
1615
|
+
}
|
|
1616
|
+
if (typeof v === "object") {
|
|
1617
|
+
try {
|
|
1618
|
+
const seen = /* @__PURE__ */ new WeakSet();
|
|
1619
|
+
const out = JSON.stringify(v, (_key, val) => {
|
|
1620
|
+
if (typeof val === "object" && val !== null) {
|
|
1621
|
+
if (seen.has(val)) return "[Circular]";
|
|
1622
|
+
seen.add(val);
|
|
1623
|
+
}
|
|
1624
|
+
if (typeof val === "bigint") return val.toString();
|
|
1625
|
+
if (typeof val === "function") return `[Function${val.name ? ` ${val.name}` : ""}]`;
|
|
1626
|
+
if (typeof val === "symbol") return val.toString();
|
|
1627
|
+
return val;
|
|
1628
|
+
});
|
|
1629
|
+
return out ?? Object.prototype.toString.call(v);
|
|
1630
|
+
} catch {
|
|
1631
|
+
return Object.prototype.toString.call(v);
|
|
1632
|
+
}
|
|
1562
1633
|
}
|
|
1634
|
+
return String(v);
|
|
1635
|
+
}
|
|
1636
|
+
function truncate(s) {
|
|
1637
|
+
if (s.length <= MAX_ARG_BYTES) return s;
|
|
1638
|
+
return s.slice(0, MAX_ARG_BYTES) + "\u2026[truncated]";
|
|
1563
1639
|
}
|
|
1564
1640
|
|
|
1565
1641
|
// src/architecture.ts
|
|
@@ -1587,6 +1663,7 @@ function applyArchitectureTags(setTag) {
|
|
|
1587
1663
|
// src/navigation.ts
|
|
1588
1664
|
var NAV_FLAG = /* @__PURE__ */ Symbol.for("allstak.nav.subscribed");
|
|
1589
1665
|
var LINKING_FLAG = "__allstak_linking_patched__";
|
|
1666
|
+
var NAV_AUTO_PATCH_FLAG = /* @__PURE__ */ Symbol.for("allstak.nav.autoPatched");
|
|
1590
1667
|
function instrumentReactNavigation(navigationRef, options = {}) {
|
|
1591
1668
|
if (!navigationRef || typeof navigationRef.addListener !== "function") {
|
|
1592
1669
|
return () => {
|
|
@@ -1654,8 +1731,59 @@ function instrumentNavigationFromLinking() {
|
|
|
1654
1731
|
} catch {
|
|
1655
1732
|
}
|
|
1656
1733
|
}
|
|
1734
|
+
function tryAutoInstrumentNavigation() {
|
|
1735
|
+
const g = globalThis;
|
|
1736
|
+
const isMetro = typeof g.__METRO_GLOBAL_PREFIX__ !== "undefined" || typeof g.__r === "function" || typeof g.HermesInternal !== "undefined";
|
|
1737
|
+
if (isMetro) return false;
|
|
1738
|
+
try {
|
|
1739
|
+
const rnav = require("@react-navigation/native");
|
|
1740
|
+
if (!rnav || !rnav.NavigationContainer) return false;
|
|
1741
|
+
if (rnav[NAV_AUTO_PATCH_FLAG]) return true;
|
|
1742
|
+
const React2 = require("react");
|
|
1743
|
+
if (!React2 || typeof React2.forwardRef !== "function") return false;
|
|
1744
|
+
const OrigContainer = rnav.NavigationContainer;
|
|
1745
|
+
const Wrapped = React2.forwardRef(function AllStakNavigationContainer(props, userRef) {
|
|
1746
|
+
const internalRef = React2.useRef(null);
|
|
1747
|
+
const setRef = React2.useCallback((r) => {
|
|
1748
|
+
internalRef.current = r;
|
|
1749
|
+
if (typeof userRef === "function") userRef(r);
|
|
1750
|
+
else if (userRef) userRef.current = r;
|
|
1751
|
+
}, [userRef]);
|
|
1752
|
+
React2.useEffect(() => {
|
|
1753
|
+
if (internalRef.current) {
|
|
1754
|
+
try {
|
|
1755
|
+
instrumentReactNavigation(internalRef.current);
|
|
1756
|
+
} catch {
|
|
1757
|
+
}
|
|
1758
|
+
}
|
|
1759
|
+
}, []);
|
|
1760
|
+
return React2.createElement(OrigContainer, { ...props, ref: setRef });
|
|
1761
|
+
});
|
|
1762
|
+
Wrapped.displayName = "AllStakNavigationContainer";
|
|
1763
|
+
try {
|
|
1764
|
+
Object.defineProperty(rnav, "NavigationContainer", {
|
|
1765
|
+
value: Wrapped,
|
|
1766
|
+
configurable: true,
|
|
1767
|
+
writable: true
|
|
1768
|
+
});
|
|
1769
|
+
rnav[NAV_AUTO_PATCH_FLAG] = true;
|
|
1770
|
+
return true;
|
|
1771
|
+
} catch {
|
|
1772
|
+
return false;
|
|
1773
|
+
}
|
|
1774
|
+
} catch {
|
|
1775
|
+
return false;
|
|
1776
|
+
}
|
|
1777
|
+
}
|
|
1778
|
+
function __resetAutoNavigationFlagForTest() {
|
|
1779
|
+
try {
|
|
1780
|
+
const rnav = require("@react-navigation/native");
|
|
1781
|
+
if (rnav) delete rnav[NAV_AUTO_PATCH_FLAG];
|
|
1782
|
+
} catch {
|
|
1783
|
+
}
|
|
1784
|
+
}
|
|
1657
1785
|
|
|
1658
|
-
// src/
|
|
1786
|
+
// src/install.ts
|
|
1659
1787
|
function instrumentXmlHttpRequest() {
|
|
1660
1788
|
const flag = "__allstak_xhr_patched__";
|
|
1661
1789
|
const X = globalThis.XMLHttpRequest;
|
|
@@ -1707,43 +1835,6 @@ function instrumentXmlHttpRequest() {
|
|
|
1707
1835
|
};
|
|
1708
1836
|
X.prototype[flag] = true;
|
|
1709
1837
|
}
|
|
1710
|
-
var __testNativeModule = null;
|
|
1711
|
-
function __setNativeModuleForTest(mod) {
|
|
1712
|
-
__testNativeModule = mod;
|
|
1713
|
-
}
|
|
1714
|
-
async function drainPendingNativeCrashes(release) {
|
|
1715
|
-
try {
|
|
1716
|
-
let native = __testNativeModule;
|
|
1717
|
-
if (!native) {
|
|
1718
|
-
const rn = require("react-native");
|
|
1719
|
-
native = rn?.NativeModules?.AllStakNative;
|
|
1720
|
-
}
|
|
1721
|
-
if (!native) return;
|
|
1722
|
-
if (typeof native.install === "function") {
|
|
1723
|
-
try {
|
|
1724
|
-
await native.install(release ?? "");
|
|
1725
|
-
} catch {
|
|
1726
|
-
}
|
|
1727
|
-
}
|
|
1728
|
-
if (typeof native.drainPendingCrash === "function") {
|
|
1729
|
-
const json = await native.drainPendingCrash();
|
|
1730
|
-
if (json && json !== "") {
|
|
1731
|
-
try {
|
|
1732
|
-
const payload = JSON.parse(json);
|
|
1733
|
-
const err = new Error(payload?.message ?? "Native crash");
|
|
1734
|
-
err.name = payload?.exceptionClass ?? "NativeCrash";
|
|
1735
|
-
err.stack = Array.isArray(payload?.stackTrace) ? payload.stackTrace.join("\n") : String(payload?.stackTrace ?? "");
|
|
1736
|
-
AllStak.captureException(err, {
|
|
1737
|
-
...payload?.metadata || {},
|
|
1738
|
-
"native.crash": "true"
|
|
1739
|
-
});
|
|
1740
|
-
} catch {
|
|
1741
|
-
}
|
|
1742
|
-
}
|
|
1743
|
-
}
|
|
1744
|
-
} catch {
|
|
1745
|
-
}
|
|
1746
|
-
}
|
|
1747
1838
|
function installReactNative(options = {}) {
|
|
1748
1839
|
const autoError = options.autoErrorHandler !== false;
|
|
1749
1840
|
const autoPromise = options.autoPromiseRejections !== false;
|
|
@@ -1790,9 +1881,21 @@ function installReactNative(options = {}) {
|
|
|
1790
1881
|
}
|
|
1791
1882
|
if (options.autoConsoleBreadcrumbs !== false) {
|
|
1792
1883
|
try {
|
|
1793
|
-
|
|
1884
|
+
const cfg = AllStak.getConfig();
|
|
1885
|
+
instrumentConsole(__safeAddBreadcrumbForInstrumentation, cfg?.captureConsole);
|
|
1886
|
+
} catch {
|
|
1887
|
+
}
|
|
1888
|
+
}
|
|
1889
|
+
if (options.autoNavigationBreadcrumbs !== false) {
|
|
1890
|
+
let navResult = false;
|
|
1891
|
+
try {
|
|
1892
|
+
navResult = tryAutoInstrumentNavigation();
|
|
1794
1893
|
} catch {
|
|
1795
1894
|
}
|
|
1895
|
+
if (options.debugLogs) {
|
|
1896
|
+
if (navResult) console.log("[AllStak] Navigation auto-instrumentation enabled");
|
|
1897
|
+
else console.log("[AllStak] Navigation auto-instrumentation not applied; use instrumentReactNavigation(ref) fallback");
|
|
1898
|
+
}
|
|
1796
1899
|
}
|
|
1797
1900
|
if (autoDevice) {
|
|
1798
1901
|
try {
|
|
@@ -1843,17 +1946,30 @@ function installReactNative(options = {}) {
|
|
|
1843
1946
|
}
|
|
1844
1947
|
}
|
|
1845
1948
|
if (autoPromise) {
|
|
1949
|
+
const wrapTrackerReason = (rejection) => rejection instanceof Error ? rejection : new Error(`Unhandled promise rejection: ${String(rejection)}`);
|
|
1950
|
+
const ship = (err) => {
|
|
1951
|
+
try {
|
|
1952
|
+
AllStak.captureException(err, { source: "unhandledRejection" });
|
|
1953
|
+
} catch {
|
|
1954
|
+
}
|
|
1955
|
+
};
|
|
1956
|
+
try {
|
|
1957
|
+
const hermesInternal = globalThis.HermesInternal;
|
|
1958
|
+
if (hermesInternal && typeof hermesInternal.enablePromiseRejectionTracker === "function") {
|
|
1959
|
+
hermesInternal.enablePromiseRejectionTracker({
|
|
1960
|
+
allRejections: true,
|
|
1961
|
+
onUnhandled: (_id, rejection) => ship(wrapTrackerReason(rejection)),
|
|
1962
|
+
onHandled: () => {
|
|
1963
|
+
}
|
|
1964
|
+
});
|
|
1965
|
+
}
|
|
1966
|
+
} catch {
|
|
1967
|
+
}
|
|
1846
1968
|
try {
|
|
1847
1969
|
const tracking = require("promise/setimmediate/rejection-tracking");
|
|
1848
1970
|
tracking.enable({
|
|
1849
1971
|
allRejections: true,
|
|
1850
|
-
onUnhandled: (_id, rejection) =>
|
|
1851
|
-
const err = rejection instanceof Error ? rejection : new Error(`Unhandled promise rejection: ${String(rejection)}`);
|
|
1852
|
-
try {
|
|
1853
|
-
AllStak.captureException(err, { source: "unhandledRejection" });
|
|
1854
|
-
} catch {
|
|
1855
|
-
}
|
|
1856
|
-
},
|
|
1972
|
+
onUnhandled: (_id, rejection) => ship(wrapTrackerReason(rejection)),
|
|
1857
1973
|
onHandled: () => {
|
|
1858
1974
|
}
|
|
1859
1975
|
});
|
|
@@ -1863,13 +1979,206 @@ function installReactNative(options = {}) {
|
|
|
1863
1979
|
g.addEventListener("unhandledrejection", (ev) => {
|
|
1864
1980
|
const reason = ev?.reason;
|
|
1865
1981
|
const err = reason instanceof Error ? reason : new Error(String(reason));
|
|
1866
|
-
|
|
1867
|
-
AllStak.captureException(err, { source: "unhandledRejection" });
|
|
1868
|
-
} catch {
|
|
1869
|
-
}
|
|
1982
|
+
ship(err);
|
|
1870
1983
|
});
|
|
1871
1984
|
}
|
|
1872
1985
|
}
|
|
1873
1986
|
}
|
|
1874
1987
|
}
|
|
1988
|
+
|
|
1989
|
+
// src/provider.tsx
|
|
1990
|
+
var AllStakContext = React.createContext(null);
|
|
1991
|
+
var __providerOwnedInstance = null;
|
|
1992
|
+
var AllStakErrorBoundary = class extends React.Component {
|
|
1993
|
+
constructor() {
|
|
1994
|
+
super(...arguments);
|
|
1995
|
+
this.state = { error: null };
|
|
1996
|
+
this.resetError = () => this.setState({ error: null });
|
|
1997
|
+
}
|
|
1998
|
+
static getDerivedStateFromError(error) {
|
|
1999
|
+
return { error };
|
|
2000
|
+
}
|
|
2001
|
+
componentDidCatch(error, info) {
|
|
2002
|
+
try {
|
|
2003
|
+
AllStak.addBreadcrumb("ui", "React error boundary caught error", "error", {
|
|
2004
|
+
componentStack: info.componentStack ?? ""
|
|
2005
|
+
});
|
|
2006
|
+
AllStak.captureException(error, {
|
|
2007
|
+
componentStack: info.componentStack ?? "",
|
|
2008
|
+
source: "AllStakProvider.ErrorBoundary"
|
|
2009
|
+
});
|
|
2010
|
+
if (this.props.debug) {
|
|
2011
|
+
console.log(`[AllStak] Captured render error: ${error.message}`);
|
|
2012
|
+
}
|
|
2013
|
+
} catch {
|
|
2014
|
+
}
|
|
2015
|
+
try {
|
|
2016
|
+
this.props.onError?.(error, info.componentStack ?? void 0);
|
|
2017
|
+
} catch {
|
|
2018
|
+
}
|
|
2019
|
+
}
|
|
2020
|
+
render() {
|
|
2021
|
+
if (this.state.error) {
|
|
2022
|
+
const { fallback } = this.props;
|
|
2023
|
+
if (typeof fallback === "function") {
|
|
2024
|
+
return fallback({ error: this.state.error, resetError: this.resetError });
|
|
2025
|
+
}
|
|
2026
|
+
if (fallback !== void 0) return fallback;
|
|
2027
|
+
return null;
|
|
2028
|
+
}
|
|
2029
|
+
return this.props.children;
|
|
2030
|
+
}
|
|
2031
|
+
};
|
|
2032
|
+
function AllStakProvider({
|
|
2033
|
+
children,
|
|
2034
|
+
apiKey,
|
|
2035
|
+
environment,
|
|
2036
|
+
release,
|
|
2037
|
+
host,
|
|
2038
|
+
user,
|
|
2039
|
+
tags,
|
|
2040
|
+
debug,
|
|
2041
|
+
enableHttpTracking,
|
|
2042
|
+
httpTracking,
|
|
2043
|
+
captureConsole,
|
|
2044
|
+
sampleRate,
|
|
2045
|
+
beforeSend,
|
|
2046
|
+
replay,
|
|
2047
|
+
tracesSampleRate,
|
|
2048
|
+
service,
|
|
2049
|
+
dist,
|
|
2050
|
+
destroyOnUnmount = false,
|
|
2051
|
+
fallback,
|
|
2052
|
+
onError,
|
|
2053
|
+
autoErrorHandler,
|
|
2054
|
+
autoPromiseRejections,
|
|
2055
|
+
autoDeviceTags,
|
|
2056
|
+
autoAppStateBreadcrumbs,
|
|
2057
|
+
autoNetworkCapture,
|
|
2058
|
+
autoFetchBreadcrumbs,
|
|
2059
|
+
autoConsoleBreadcrumbs,
|
|
2060
|
+
autoNavigationBreadcrumbs
|
|
2061
|
+
}) {
|
|
2062
|
+
const clientRef = React.useRef(null);
|
|
2063
|
+
if (!clientRef.current) {
|
|
2064
|
+
const existing = AllStak._getInstance();
|
|
2065
|
+
if (existing && __providerOwnedInstance === existing) {
|
|
2066
|
+
clientRef.current = existing;
|
|
2067
|
+
if (debug) {
|
|
2068
|
+
console.log(`[AllStak] Reusing session ${AllStak.getSessionId()}`);
|
|
2069
|
+
}
|
|
2070
|
+
} else {
|
|
2071
|
+
const config = {
|
|
2072
|
+
apiKey,
|
|
2073
|
+
environment,
|
|
2074
|
+
release,
|
|
2075
|
+
host,
|
|
2076
|
+
user,
|
|
2077
|
+
tags,
|
|
2078
|
+
enableHttpTracking,
|
|
2079
|
+
httpTracking,
|
|
2080
|
+
captureConsole,
|
|
2081
|
+
sampleRate,
|
|
2082
|
+
beforeSend,
|
|
2083
|
+
replay,
|
|
2084
|
+
tracesSampleRate,
|
|
2085
|
+
service,
|
|
2086
|
+
dist
|
|
2087
|
+
};
|
|
2088
|
+
clientRef.current = AllStak.init(config);
|
|
2089
|
+
__providerOwnedInstance = clientRef.current;
|
|
2090
|
+
installReactNative({
|
|
2091
|
+
autoErrorHandler,
|
|
2092
|
+
autoPromiseRejections,
|
|
2093
|
+
autoDeviceTags,
|
|
2094
|
+
autoAppStateBreadcrumbs,
|
|
2095
|
+
autoNetworkCapture,
|
|
2096
|
+
autoFetchBreadcrumbs,
|
|
2097
|
+
autoConsoleBreadcrumbs,
|
|
2098
|
+
autoNavigationBreadcrumbs,
|
|
2099
|
+
debugLogs: debug
|
|
2100
|
+
});
|
|
2101
|
+
if (debug) {
|
|
2102
|
+
console.log(`[AllStak] Initialized \u2014 session ${AllStak.getSessionId()}`);
|
|
2103
|
+
}
|
|
2104
|
+
}
|
|
2105
|
+
}
|
|
2106
|
+
React.useEffect(() => {
|
|
2107
|
+
return () => {
|
|
2108
|
+
if (destroyOnUnmount) {
|
|
2109
|
+
AllStak.destroy();
|
|
2110
|
+
__providerOwnedInstance = null;
|
|
2111
|
+
clientRef.current = null;
|
|
2112
|
+
if (debug) console.log("[AllStak] Destroyed on unmount");
|
|
2113
|
+
}
|
|
2114
|
+
};
|
|
2115
|
+
}, [destroyOnUnmount, debug]);
|
|
2116
|
+
return /* @__PURE__ */ React.createElement(AllStakContext.Provider, { value: clientRef.current }, /* @__PURE__ */ React.createElement(AllStakErrorBoundary, { fallback, onError, debug }, children));
|
|
2117
|
+
}
|
|
2118
|
+
function useAllStak() {
|
|
2119
|
+
return React.useMemo(
|
|
2120
|
+
() => ({
|
|
2121
|
+
captureException: (error, ctx) => AllStak.captureException(error, ctx),
|
|
2122
|
+
captureMessage: (msg, level = "info") => AllStak.captureMessage(msg, level),
|
|
2123
|
+
setUser: (user) => AllStak.setUser(user),
|
|
2124
|
+
setTag: (key, value) => AllStak.setTag(key, value),
|
|
2125
|
+
addBreadcrumb: (type, message, level, data) => AllStak.addBreadcrumb(type, message, level, data)
|
|
2126
|
+
}),
|
|
2127
|
+
[]
|
|
2128
|
+
);
|
|
2129
|
+
}
|
|
2130
|
+
function __resetProviderInstanceForTest() {
|
|
2131
|
+
__providerOwnedInstance = null;
|
|
2132
|
+
}
|
|
2133
|
+
|
|
2134
|
+
// src/index.ts
|
|
2135
|
+
var __testNativeModule = null;
|
|
2136
|
+
function __setNativeModuleForTest(mod) {
|
|
2137
|
+
__testNativeModule = mod;
|
|
2138
|
+
}
|
|
2139
|
+
async function __devTriggerNativeCrash() {
|
|
2140
|
+
try {
|
|
2141
|
+
let native = __testNativeModule;
|
|
2142
|
+
if (!native) {
|
|
2143
|
+
const rn = require("react-native");
|
|
2144
|
+
native = rn?.NativeModules?.AllStakNative;
|
|
2145
|
+
}
|
|
2146
|
+
if (!native || typeof native.__devTriggerCrash !== "function") return;
|
|
2147
|
+
await native.__devTriggerCrash();
|
|
2148
|
+
} catch {
|
|
2149
|
+
}
|
|
2150
|
+
}
|
|
2151
|
+
async function drainPendingNativeCrashes(release) {
|
|
2152
|
+
try {
|
|
2153
|
+
let native = __testNativeModule;
|
|
2154
|
+
if (!native) {
|
|
2155
|
+
const rn = require("react-native");
|
|
2156
|
+
native = rn?.NativeModules?.AllStakNative;
|
|
2157
|
+
}
|
|
2158
|
+
if (!native) return;
|
|
2159
|
+
if (typeof native.install === "function") {
|
|
2160
|
+
try {
|
|
2161
|
+
await native.install(release ?? "");
|
|
2162
|
+
} catch {
|
|
2163
|
+
}
|
|
2164
|
+
}
|
|
2165
|
+
if (typeof native.drainPendingCrash === "function") {
|
|
2166
|
+
const json = await native.drainPendingCrash();
|
|
2167
|
+
if (json && json !== "") {
|
|
2168
|
+
try {
|
|
2169
|
+
const payload = JSON.parse(json);
|
|
2170
|
+
const err = new Error(payload?.message ?? "Native crash");
|
|
2171
|
+
err.name = payload?.exceptionClass ?? "NativeCrash";
|
|
2172
|
+
err.stack = Array.isArray(payload?.stackTrace) ? payload.stackTrace.join("\n") : String(payload?.stackTrace ?? "");
|
|
2173
|
+
AllStak.captureException(err, {
|
|
2174
|
+
...payload?.metadata || {},
|
|
2175
|
+
"native.crash": "true"
|
|
2176
|
+
});
|
|
2177
|
+
} catch {
|
|
2178
|
+
}
|
|
2179
|
+
}
|
|
2180
|
+
}
|
|
2181
|
+
} catch {
|
|
2182
|
+
}
|
|
2183
|
+
}
|
|
1875
2184
|
//# sourceMappingURL=index.js.map
|