@reopt-ai/data-sdk-client 0.1.5 → 0.2.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.
- package/README.md +141 -7
- package/dist/client-B1GlWwVq.d.ts +744 -0
- package/dist/client-B1GlWwVq.d.ts.map +1 -0
- package/dist/client-BCrui21p.d.cts +744 -0
- package/dist/client-BCrui21p.d.cts.map +1 -0
- package/dist/exceptions-C9Fh0BIR.js +285 -0
- package/dist/exceptions-C9Fh0BIR.js.map +1 -0
- package/dist/exceptions-CuhGo9A5.cjs +289 -0
- package/dist/exceptions-CuhGo9A5.cjs.map +1 -0
- package/dist/index.cjs +75 -1874
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +83 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.ts +35 -33
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +49 -70
- package/dist/index.js.map +1 -1
- package/dist/next.cjs +51 -1919
- package/dist/next.cjs.map +1 -1
- package/dist/next.d.cts +31 -0
- package/dist/next.d.cts.map +1 -0
- package/dist/next.d.ts +8 -10
- package/dist/next.d.ts.map +1 -0
- package/dist/next.js +36 -49
- package/dist/next.js.map +1 -1
- package/dist/observe-D-BHMwrO.cjs +54 -0
- package/dist/observe-D-BHMwrO.cjs.map +1 -0
- package/dist/observe-D1pNg1qL.js +54 -0
- package/dist/observe-D1pNg1qL.js.map +1 -0
- package/dist/react.cjs +105 -1863
- package/dist/react.cjs.map +1 -1
- package/dist/react.d.cts +80 -0
- package/dist/react.d.cts.map +1 -0
- package/dist/react.d.ts +53 -47
- package/dist/react.d.ts.map +1 -0
- package/dist/react.js +118 -23
- package/dist/react.js.map +1 -1
- package/dist/registry-BPhiH_l9.js +1775 -0
- package/dist/registry-BPhiH_l9.js.map +1 -0
- package/dist/registry-CGqrOtf4.cjs +1810 -0
- package/dist/registry-CGqrOtf4.cjs.map +1 -0
- package/dist/tracing-DAhaKkl0.cjs +93 -0
- package/dist/tracing-DAhaKkl0.cjs.map +1 -0
- package/dist/tracing-Dt1RVuQ9.js +93 -0
- package/dist/tracing-Dt1RVuQ9.js.map +1 -0
- package/package.json +31 -16
- package/dist/chunk-2UPF3C7D.js +0 -106
- package/dist/chunk-2UPF3C7D.js.map +0 -1
- package/dist/chunk-4MTDZBRS.js +0 -57
- package/dist/chunk-4MTDZBRS.js.map +0 -1
- package/dist/chunk-BJGIHFDA.js +0 -1627
- package/dist/chunk-BJGIHFDA.js.map +0 -1
- package/dist/client-TesmBLXd.d.ts +0 -581
- package/dist/exceptions-NQHZUDYO.js +0 -9
- package/dist/exceptions-NQHZUDYO.js.map +0 -1
- package/dist/tracing-LC3NZND7.js +0 -91
- package/dist/tracing-LC3NZND7.js.map +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reopt-ai/data-sdk-client",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "reopt-data browser SDK — vanilla, React and Next.js App Router client components",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"license": "MIT",
|
|
@@ -17,19 +17,34 @@
|
|
|
17
17
|
"type": "module",
|
|
18
18
|
"exports": {
|
|
19
19
|
".": {
|
|
20
|
-
"
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
"import": {
|
|
21
|
+
"types": "./dist/index.d.ts",
|
|
22
|
+
"default": "./dist/index.js"
|
|
23
|
+
},
|
|
24
|
+
"require": {
|
|
25
|
+
"types": "./dist/index.d.cts",
|
|
26
|
+
"default": "./dist/index.cjs"
|
|
27
|
+
}
|
|
23
28
|
},
|
|
24
29
|
"./react": {
|
|
25
|
-
"
|
|
26
|
-
|
|
27
|
-
|
|
30
|
+
"import": {
|
|
31
|
+
"types": "./dist/react.d.ts",
|
|
32
|
+
"default": "./dist/react.js"
|
|
33
|
+
},
|
|
34
|
+
"require": {
|
|
35
|
+
"types": "./dist/react.d.cts",
|
|
36
|
+
"default": "./dist/react.cjs"
|
|
37
|
+
}
|
|
28
38
|
},
|
|
29
39
|
"./next": {
|
|
30
|
-
"
|
|
31
|
-
|
|
32
|
-
|
|
40
|
+
"import": {
|
|
41
|
+
"types": "./dist/next.d.ts",
|
|
42
|
+
"default": "./dist/next.js"
|
|
43
|
+
},
|
|
44
|
+
"require": {
|
|
45
|
+
"types": "./dist/next.d.cts",
|
|
46
|
+
"default": "./dist/next.cjs"
|
|
47
|
+
}
|
|
33
48
|
}
|
|
34
49
|
},
|
|
35
50
|
"main": "./dist/index.cjs",
|
|
@@ -51,26 +66,26 @@
|
|
|
51
66
|
}
|
|
52
67
|
},
|
|
53
68
|
"dependencies": {
|
|
54
|
-
"@reopt-ai/data-contract": "0.
|
|
69
|
+
"@reopt-ai/data-contract": "0.7.0"
|
|
55
70
|
},
|
|
56
71
|
"devDependencies": {
|
|
57
72
|
"@testing-library/react": "^16.3.2",
|
|
58
73
|
"@types/node": "^22.20.1",
|
|
59
74
|
"@types/react": "^19.2.18",
|
|
60
|
-
"esbuild": "^0.28.2",
|
|
61
75
|
"jsdom": "^30.0.1",
|
|
62
|
-
"next": "16.3.
|
|
76
|
+
"next": "16.3.3",
|
|
63
77
|
"react": "^19.2.8",
|
|
64
|
-
"
|
|
78
|
+
"tsdown": "^0.22.14",
|
|
65
79
|
"typescript": "^5.9.3",
|
|
66
80
|
"vitest": "^4.1.11",
|
|
67
81
|
"@reopt-ai/data-sdk-core": "0.0.0",
|
|
68
82
|
"@repo/typescript-config": "0.0.0"
|
|
69
83
|
},
|
|
70
84
|
"scripts": {
|
|
71
|
-
"build": "
|
|
85
|
+
"build": "tsdown && pnpm run check:dist && pnpm run check:size",
|
|
86
|
+
"check:package": "node ../../scripts/check-package-contract.mjs",
|
|
72
87
|
"check-types": "tsc --noEmit",
|
|
73
|
-
"dev": "
|
|
88
|
+
"dev": "tsdown --watch",
|
|
74
89
|
"lint": "oxlint .",
|
|
75
90
|
"test": "vitest run",
|
|
76
91
|
"test:watch": "vitest",
|
package/dist/chunk-2UPF3C7D.js
DELETED
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
getOrCreateClient
|
|
3
|
-
} from "./chunk-BJGIHFDA.js";
|
|
4
|
-
|
|
5
|
-
// src/react/index.tsx
|
|
6
|
-
import { createContext, useCallback, useContext, useEffect, useMemo, useRef } from "react";
|
|
7
|
-
import { jsx } from "react/jsx-runtime";
|
|
8
|
-
var ReoptContext = createContext(null);
|
|
9
|
-
var NOT_AVAILABLE = { eventId: "", queued: false, reason: "tracking_paused" };
|
|
10
|
-
var NO_FLUSH = { status: "idle", sent: 0, failed: 0, pending: 0 };
|
|
11
|
-
function ReoptProvider({ children, config, bootstrap, initialPageView = true }) {
|
|
12
|
-
const client = typeof window === "undefined" ? null : getOrCreateClient(
|
|
13
|
-
{ ...config, bootstrap: bootstrap !== void 0 ? bootstrap : config.bootstrap ?? null },
|
|
14
|
-
{ pageview: initialPageView }
|
|
15
|
-
);
|
|
16
|
-
const value = useMemo(() => bindClient(client), [client]);
|
|
17
|
-
return /* @__PURE__ */ jsx(ReoptContext.Provider, { value, children });
|
|
18
|
-
}
|
|
19
|
-
function bindClient(client) {
|
|
20
|
-
const call = (fn, fallback) => client ? fn(client) : fallback;
|
|
21
|
-
return {
|
|
22
|
-
client,
|
|
23
|
-
track: (options) => call((c) => c.track(options), NOT_AVAILABLE),
|
|
24
|
-
identify: (options) => call((c) => c.identify(options), NOT_AVAILABLE),
|
|
25
|
-
increment: (options) => call((c) => c.increment(options), NOT_AVAILABLE),
|
|
26
|
-
decrement: (options) => call((c) => c.decrement(options), NOT_AVAILABLE),
|
|
27
|
-
pageView: (options) => call((c) => c.pageView(options), NOT_AVAILABLE),
|
|
28
|
-
screenView: (name, properties) => call((c) => c.screenView(name, properties), NOT_AVAILABLE),
|
|
29
|
-
captureWebVital: (metric) => call((c) => c.captureWebVital(metric), NOT_AVAILABLE),
|
|
30
|
-
captureException: (error, properties) => call((c) => c.captureException(error, properties), NOT_AVAILABLE),
|
|
31
|
-
register: (properties) => call((c) => c.register(properties), void 0),
|
|
32
|
-
unregister: (...keys) => call((c) => c.unregister(...keys), void 0),
|
|
33
|
-
setProfileId: (id) => call((c) => c.setProfileId(id), void 0),
|
|
34
|
-
getProfileId: () => call((c) => c.getProfileId(), null),
|
|
35
|
-
getDeviceId: () => call((c) => c.disabled ? null : c.getDeviceId(), null),
|
|
36
|
-
reset: () => call((c) => c.reset(), void 0),
|
|
37
|
-
flush: () => call((c) => c.flush(), Promise.resolve(NO_FLUSH)),
|
|
38
|
-
setConsent: (category, allowed) => call((c) => c.setConsent(category, allowed), void 0),
|
|
39
|
-
getConsent: (category) => call((c) => c.getConsent(category), false),
|
|
40
|
-
setAllConsent: (allowed) => call((c) => c.setAllConsent(allowed), void 0),
|
|
41
|
-
pauseTracking: () => call((c) => c.pauseTracking(), void 0),
|
|
42
|
-
resumeTracking: () => call((c) => c.resumeTracking(), void 0)
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
function useReopt() {
|
|
46
|
-
const context = useContext(ReoptContext);
|
|
47
|
-
if (!context) {
|
|
48
|
-
throw new Error("useReopt must be used within a ReoptProvider");
|
|
49
|
-
}
|
|
50
|
-
return context;
|
|
51
|
-
}
|
|
52
|
-
function useReoptClient() {
|
|
53
|
-
return useReopt().client;
|
|
54
|
-
}
|
|
55
|
-
function useTrack() {
|
|
56
|
-
const { track } = useReopt();
|
|
57
|
-
return useCallback((name, properties) => track({ name, properties }), [track]);
|
|
58
|
-
}
|
|
59
|
-
function useIdentify() {
|
|
60
|
-
const { identify } = useReopt();
|
|
61
|
-
return useCallback(
|
|
62
|
-
(profileId, properties) => identify({ profileId, properties }),
|
|
63
|
-
[identify]
|
|
64
|
-
);
|
|
65
|
-
}
|
|
66
|
-
function usePageView() {
|
|
67
|
-
return useReopt().pageView;
|
|
68
|
-
}
|
|
69
|
-
function useConsent() {
|
|
70
|
-
const { setConsent, getConsent, setAllConsent } = useReopt();
|
|
71
|
-
return useMemo(() => ({ setConsent, getConsent, setAllConsent }), [setConsent, getConsent, setAllConsent]);
|
|
72
|
-
}
|
|
73
|
-
function useLatest(value) {
|
|
74
|
-
const ref = useRef(value);
|
|
75
|
-
useEffect(() => {
|
|
76
|
-
ref.current = value;
|
|
77
|
-
});
|
|
78
|
-
return ref;
|
|
79
|
-
}
|
|
80
|
-
function useTrackOnMount(name, properties) {
|
|
81
|
-
const track = useTrack();
|
|
82
|
-
const latest = useLatest({ track, properties });
|
|
83
|
-
useEffect(() => {
|
|
84
|
-
latest.current.track(name, latest.current.properties);
|
|
85
|
-
}, [name, latest]);
|
|
86
|
-
}
|
|
87
|
-
function usePageViewOnMount(options) {
|
|
88
|
-
const pageView = usePageView();
|
|
89
|
-
const latest = useLatest({ pageView, options });
|
|
90
|
-
useEffect(() => {
|
|
91
|
-
latest.current.pageView(latest.current.options);
|
|
92
|
-
}, [latest]);
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
export {
|
|
96
|
-
ReoptProvider,
|
|
97
|
-
useReopt,
|
|
98
|
-
useReoptClient,
|
|
99
|
-
useTrack,
|
|
100
|
-
useIdentify,
|
|
101
|
-
usePageView,
|
|
102
|
-
useConsent,
|
|
103
|
-
useTrackOnMount,
|
|
104
|
-
usePageViewOnMount
|
|
105
|
-
};
|
|
106
|
-
//# sourceMappingURL=chunk-2UPF3C7D.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/react/index.tsx"],"sourcesContent":["\"use client\";\n\nimport { createContext, useCallback, useContext, useEffect, useMemo, useRef, type ReactNode } from \"react\";\nimport type { ReoptBootstrap } from \"@reopt-ai/data-contract/identity\";\nimport type {\n ConsentCategory,\n DecrementOptions,\n FlushResult,\n IdentifyOptions,\n IncrementOptions,\n PageViewOptions,\n QueueResult,\n TrackEventOptions,\n} from \"@reopt-ai/data-sdk-core\";\nimport type { WebVitalMetric } from \"../capture/web-vitals.js\";\nimport type { ReoptClient } from \"../client.js\";\nimport type { ReoptClientConfig } from \"../config.js\";\nimport { getOrCreateClient } from \"../registry.js\";\n\nexport interface ReoptContextValue {\n /** `null` during server rendering and before hydration. */\n client: ReoptClient | null;\n track: (options: TrackEventOptions) => QueueResult;\n identify: (options: IdentifyOptions) => QueueResult;\n increment: (options: IncrementOptions) => QueueResult;\n decrement: (options: DecrementOptions) => QueueResult;\n pageView: (options?: PageViewOptions) => QueueResult;\n screenView: (screenName: string, properties?: Record<string, unknown>) => QueueResult;\n captureWebVital: (metric: WebVitalMetric) => QueueResult;\n captureException: (error: unknown, properties?: Record<string, unknown>) => QueueResult;\n register: (properties: Record<string, unknown>) => void;\n unregister: (...keys: string[]) => void;\n setProfileId: (profileId: string | number | null) => void;\n getProfileId: () => string | number | null;\n getDeviceId: () => string | null;\n reset: () => void;\n flush: () => Promise<FlushResult>;\n setConsent: (category: ConsentCategory, allowed: boolean) => void;\n getConsent: (category: ConsentCategory) => boolean;\n setAllConsent: (allowed: boolean) => void;\n pauseTracking: () => void;\n resumeTracking: () => void;\n}\n\nconst ReoptContext = createContext<ReoptContextValue | null>(null);\n\n/** What a call returns when there is no client (server render). Never queued, never an error. */\nconst NOT_AVAILABLE: QueueResult = { eventId: \"\", queued: false, reason: \"tracking_paused\" };\nconst NO_FLUSH: FlushResult = { status: \"idle\", sent: 0, failed: 0, pending: 0 };\n\nexport interface ReoptProviderProps {\n children: ReactNode;\n /** `bootstrap` may also be passed here; the prop below wins. */\n config: Omit<ReoptClientConfig, \"bootstrap\"> & { bootstrap?: ReoptBootstrap | null };\n /** From the server SDK's `getBootstrap()`. `null` = the server knows nothing about this visitor. */\n bootstrap?: ReoptBootstrap | null;\n /**\n * Send `$pageview` when the client is created. Default `true`. Set to\n * `false` when a router-aware component owns page views (the Next entry\n * does this for you).\n */\n initialPageView?: boolean;\n}\n\n/**\n * Creates the client **during render**, not in an effect. React runs effects\n * children-first, so a child's `useEffect` (a consent banner, a\n * `useTrackOnMount`) would otherwise run before the provider's effect had\n * created anything. Creation is idempotent per write key — StrictMode's\n * double render and a remount reuse the same instance.\n *\n * The client is never closed on unmount: it is page-scoped, and a provider\n * that unmounts during a StrictMode simulation or a layout swap must not\n * tear down the queue. Call `client.close()` yourself if you need to.\n */\nexport function ReoptProvider({ children, config, bootstrap, initialPageView = true }: ReoptProviderProps) {\n const client =\n typeof window === \"undefined\"\n ? null\n : getOrCreateClient(\n { ...config, bootstrap: bootstrap !== undefined ? bootstrap : (config.bootstrap ?? null) },\n { pageview: initialPageView }\n );\n\n const value = useMemo<ReoptContextValue>(() => bindClient(client), [client]);\n return <ReoptContext.Provider value={value}>{children}</ReoptContext.Provider>;\n}\n\nfunction bindClient(client: ReoptClient | null): ReoptContextValue {\n const call = <T,>(fn: (client: ReoptClient) => T, fallback: T): T => (client ? fn(client) : fallback);\n return {\n client,\n track: (options) => call((c) => c.track(options), NOT_AVAILABLE),\n identify: (options) => call((c) => c.identify(options), NOT_AVAILABLE),\n increment: (options) => call((c) => c.increment(options), NOT_AVAILABLE),\n decrement: (options) => call((c) => c.decrement(options), NOT_AVAILABLE),\n pageView: (options) => call((c) => c.pageView(options), NOT_AVAILABLE),\n screenView: (name, properties) => call((c) => c.screenView(name, properties), NOT_AVAILABLE),\n captureWebVital: (metric) => call((c) => c.captureWebVital(metric), NOT_AVAILABLE),\n captureException: (error, properties) => call((c) => c.captureException(error, properties), NOT_AVAILABLE),\n register: (properties) => call((c) => c.register(properties), undefined),\n unregister: (...keys) => call((c) => c.unregister(...keys), undefined),\n setProfileId: (id) => call((c) => c.setProfileId(id), undefined),\n getProfileId: () => call((c) => c.getProfileId(), null),\n getDeviceId: () => call((c) => (c.disabled ? null : c.getDeviceId()), null),\n reset: () => call((c) => c.reset(), undefined),\n flush: () => call((c) => c.flush(), Promise.resolve(NO_FLUSH)),\n setConsent: (category, allowed) => call((c) => c.setConsent(category, allowed), undefined),\n getConsent: (category) => call((c) => c.getConsent(category), false),\n setAllConsent: (allowed) => call((c) => c.setAllConsent(allowed), undefined),\n pauseTracking: () => call((c) => c.pauseTracking(), undefined),\n resumeTracking: () => call((c) => c.resumeTracking(), undefined),\n };\n}\n\nexport function useReopt(): ReoptContextValue {\n const context = useContext(ReoptContext);\n if (!context) {\n throw new Error(\"useReopt must be used within a ReoptProvider\");\n }\n return context;\n}\n\n/** The underlying client, or `null` on the server. */\nexport function useReoptClient(): ReoptClient | null {\n return useReopt().client;\n}\n\nexport function useTrack() {\n const { track } = useReopt();\n return useCallback((name: string, properties?: Record<string, unknown>) => track({ name, properties }), [track]);\n}\n\nexport function useIdentify() {\n const { identify } = useReopt();\n return useCallback(\n (profileId: string | number, properties?: Record<string, unknown>) => identify({ profileId, properties }),\n [identify]\n );\n}\n\nexport function usePageView() {\n return useReopt().pageView;\n}\n\nexport function useConsent() {\n const { setConsent, getConsent, setAllConsent } = useReopt();\n return useMemo(() => ({ setConsent, getConsent, setAllConsent }), [setConsent, getConsent, setAllConsent]);\n}\n\n/**\n * The latest value of `value`, readable from an effect that must not rerun\n * when it changes. Stands in for `useEffectEvent`, which needs React 19.2\n * while this package supports 18.\n */\nfunction useLatest<T>(value: T) {\n const ref = useRef(value);\n useEffect(() => {\n ref.current = value;\n });\n return ref;\n}\n\n/** Tracks `name` once per mount (and again if `name` changes). Property changes alone do not re-track. */\nexport function useTrackOnMount(name: string, properties?: Record<string, unknown>) {\n const track = useTrack();\n const latest = useLatest({ track, properties });\n useEffect(() => {\n latest.current.track(name, latest.current.properties);\n }, [name, latest]);\n}\n\n/** Sends one `$pageview` on mount with the options current at that moment. */\nexport function usePageViewOnMount(options?: PageViewOptions) {\n const pageView = usePageView();\n const latest = useLatest({ pageView, options });\n useEffect(() => {\n latest.current.pageView(latest.current.options);\n }, [latest]);\n}\n\nexport type { ReoptBootstrap, ReoptClient, ReoptClientConfig, WebVitalMetric };\nexport type {\n ConsentCategory,\n DecrementOptions,\n FlushResult,\n IdentifyOptions,\n IncrementOptions,\n PageViewOptions,\n QueueResult,\n TrackEventOptions,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.ts
|
|
2
|
-
var MAX_STACK_CHARS = 8e3;
|
|
3
|
-
function describeError(value, source) {
|
|
4
|
-
const path = typeof location !== "undefined" ? location.pathname : "";
|
|
5
|
-
if (value instanceof Error) {
|
|
6
|
-
return {
|
|
7
|
-
$exception_type: value.name || "Error",
|
|
8
|
-
$exception_message: value.message,
|
|
9
|
-
...value.stack ? { $exception_stack: value.stack.slice(0, MAX_STACK_CHARS) } : {},
|
|
10
|
-
$exception_source: source,
|
|
11
|
-
$exception_handled: false,
|
|
12
|
-
path
|
|
13
|
-
};
|
|
14
|
-
}
|
|
15
|
-
return {
|
|
16
|
-
$exception_type: typeof value === "object" && value !== null ? "UnknownError" : typeof value,
|
|
17
|
-
$exception_message: safeString(value),
|
|
18
|
-
$exception_source: source,
|
|
19
|
-
$exception_handled: false,
|
|
20
|
-
path
|
|
21
|
-
};
|
|
22
|
-
}
|
|
23
|
-
function safeString(value) {
|
|
24
|
-
try {
|
|
25
|
-
return typeof value === "string" ? value : JSON.stringify(value) ?? String(value);
|
|
26
|
-
} catch {
|
|
27
|
-
return String(value);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
function installExceptionCapture(report) {
|
|
31
|
-
if (typeof window === "undefined") return () => {
|
|
32
|
-
};
|
|
33
|
-
const onError = (event) => {
|
|
34
|
-
try {
|
|
35
|
-
report(describeError(event.error ?? new Error(event.message), "window.onerror"));
|
|
36
|
-
} catch {
|
|
37
|
-
}
|
|
38
|
-
};
|
|
39
|
-
const onRejection = (event) => {
|
|
40
|
-
try {
|
|
41
|
-
report(describeError(event.reason, "unhandledrejection"));
|
|
42
|
-
} catch {
|
|
43
|
-
}
|
|
44
|
-
};
|
|
45
|
-
window.addEventListener("error", onError);
|
|
46
|
-
window.addEventListener("unhandledrejection", onRejection);
|
|
47
|
-
return () => {
|
|
48
|
-
window.removeEventListener("error", onError);
|
|
49
|
-
window.removeEventListener("unhandledrejection", onRejection);
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
export {
|
|
54
|
-
describeError,
|
|
55
|
-
installExceptionCapture
|
|
56
|
-
};
|
|
57
|
-
//# sourceMappingURL=chunk-4MTDZBRS.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/capture/exceptions.ts"],"sourcesContent":["export type ExceptionProperties = {\n $exception_type: string;\n $exception_message: string;\n $exception_stack?: string;\n $exception_source: \"window.onerror\" | \"unhandledrejection\";\n $exception_handled: boolean;\n path: string;\n};\n\nconst MAX_STACK_CHARS = 8_000;\n\nexport function describeError(value: unknown, source: ExceptionProperties[\"$exception_source\"]): ExceptionProperties {\n const path = typeof location !== \"undefined\" ? location.pathname : \"\";\n if (value instanceof Error) {\n return {\n $exception_type: value.name || \"Error\",\n $exception_message: value.message,\n ...(value.stack ? { $exception_stack: value.stack.slice(0, MAX_STACK_CHARS) } : {}),\n $exception_source: source,\n $exception_handled: false,\n path,\n };\n }\n return {\n $exception_type: typeof value === \"object\" && value !== null ? \"UnknownError\" : typeof value,\n $exception_message: safeString(value),\n $exception_source: source,\n $exception_handled: false,\n path,\n };\n}\n\nfunction safeString(value: unknown): string {\n try {\n return typeof value === \"string\" ? value : (JSON.stringify(value) ?? String(value));\n } catch {\n return String(value);\n }\n}\n\n/**\n * Reports uncaught errors and unhandled promise rejections. Errors thrown by\n * the reporter itself are swallowed — an analytics SDK must never turn one\n * crash into two.\n */\nexport function installExceptionCapture(report: (properties: ExceptionProperties) => void): () => void {\n if (typeof window === \"undefined\") return () => {};\n const onError = (event: ErrorEvent) => {\n try {\n // Some environments deliver the message but not the Error object.\n report(describeError(event.error ?? new Error(event.message), \"window.onerror\"));\n } catch {\n // see above\n }\n };\n const onRejection = (event: PromiseRejectionEvent) => {\n try {\n report(describeError(event.reason, \"unhandledrejection\"));\n } catch {\n // see above\n }\n };\n window.addEventListener(\"error\", onError);\n window.addEventListener(\"unhandledrejection\", onRejection);\n return () => {\n window.removeEventListener(\"error\", onError);\n window.removeEventListener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