@sazabi/react-native 0.0.0-stage → 0.1.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/LICENSE +202 -0
- package/README.md +286 -2
- package/dist/chunk-h2nxjrr9.js +5 -0
- package/dist/chunk-h2nxjrr9.js.map +15 -0
- package/dist/client-sdk-core/attributes.d.ts +8 -0
- package/dist/client-sdk-core/before-send.d.ts +15 -0
- package/dist/client-sdk-core/clock.d.ts +6 -0
- package/dist/client-sdk-core/console.d.ts +23 -0
- package/dist/client-sdk-core/index.d.ts +22 -0
- package/dist/client-sdk-core/intake-url.d.ts +38 -0
- package/dist/client-sdk-core/network-capture.d.ts +90 -0
- package/dist/client-sdk-core/patch-marker.d.ts +8 -0
- package/dist/client-sdk-core/pointer.d.ts +73 -0
- package/dist/client-sdk-core/random.d.ts +11 -0
- package/dist/client-sdk-core/sdk-health.d.ts +37 -0
- package/dist/client-sdk-core/session.d.ts +44 -0
- package/dist/client-sdk-core/trace-context.d.ts +33 -0
- package/dist/client-sdk-core/transport.d.ts +142 -0
- package/dist/client-sdk-core/types.d.ts +82 -0
- package/dist/client-sdk-core/url.d.ts +30 -0
- package/dist/errors.d.ts +46 -0
- package/dist/host.d.ts +30 -0
- package/dist/index.d.ts +52 -0
- package/dist/index.js +6 -0
- package/dist/index.js.map +28 -0
- package/dist/interactions.d.ts +40 -0
- package/dist/lifecycle.d.ts +16 -0
- package/dist/navigation.d.ts +24 -0
- package/dist/network.d.ts +12 -0
- package/dist/outbox.d.ts +53 -0
- package/dist/process-state.d.ts +49 -0
- package/dist/register.d.ts +1 -0
- package/dist/register.js +4 -0
- package/dist/register.js.map +10 -0
- package/dist/storage.d.ts +42 -0
- package/dist/types.d.ts +117 -0
- package/dist/version.d.ts +4 -0
- package/package.json +62 -4
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Absolute-URL parsing with no `URL` global. React Native's built-in `URL`
|
|
3
|
+
* throws "not implemented" for `hostname`, `pathname`, and `origin`, and the
|
|
4
|
+
* core must work there unpolyfilled, so the few fields the SDKs read are
|
|
5
|
+
* parsed here. Only absolute http(s)-style URLs resolve; a binding resolves
|
|
6
|
+
* relative references against its own base before calling in.
|
|
7
|
+
*/
|
|
8
|
+
export interface ParsedUrl {
|
|
9
|
+
/** e.g. `https:` */
|
|
10
|
+
protocol: string;
|
|
11
|
+
/** host with port, no credentials */
|
|
12
|
+
host: string;
|
|
13
|
+
hostname: string;
|
|
14
|
+
pathname: string;
|
|
15
|
+
search: string;
|
|
16
|
+
hash: string;
|
|
17
|
+
origin: string;
|
|
18
|
+
/** Normalized absolute URL with credentials stripped. */
|
|
19
|
+
href: string;
|
|
20
|
+
}
|
|
21
|
+
export declare const parseAbsoluteUrl: (raw: string) => ParsedUrl | undefined;
|
|
22
|
+
/**
|
|
23
|
+
* Whether `url` is `base` or lies under it: the same origin (scheme, host,
|
|
24
|
+
* port) and, when the base has a path, that path as whole segments. A string
|
|
25
|
+
* prefix would also match `https://intake.example.com.evil.test/`.
|
|
26
|
+
*/
|
|
27
|
+
export declare const isUnderBase: ({ url, base, }: {
|
|
28
|
+
url: string;
|
|
29
|
+
base: string;
|
|
30
|
+
}) => boolean;
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { type ClientEvent } from "./client-sdk-core/index.js";
|
|
2
|
+
import type { RejectionTracker } from "./types.js";
|
|
3
|
+
export interface ErrorCaptureOptions {
|
|
4
|
+
emit(event: ClientEvent): void;
|
|
5
|
+
/**
|
|
6
|
+
* Receives the fatal error's row instead of `emit`, before the previous
|
|
7
|
+
* handler runs: the crash path must stamp that row with the transport held
|
|
8
|
+
* so it cannot be flushed out of the queue before the outbox drains it.
|
|
9
|
+
*/
|
|
10
|
+
onFatal(event: ClientEvent): void;
|
|
11
|
+
unhandledRejections: boolean;
|
|
12
|
+
/** The tracker the host says held the slot before `init()`; runs after ours. */
|
|
13
|
+
previousRejectionTracker?: RejectionTracker;
|
|
14
|
+
}
|
|
15
|
+
export interface ErrorCaptureHandle {
|
|
16
|
+
teardown(): void;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Where `<SazabiRoot>` reports a render or commit error it caught. React 19's
|
|
20
|
+
* renderer hands an error no boundary caught straight to React Native's
|
|
21
|
+
* `ExceptionsManager` (the renderer's `onUncaughtError`), never through
|
|
22
|
+
* `ErrorUtils`, and the release app dies there. The root's boundary records
|
|
23
|
+
* the error through the process-wide sink first (so a root from a second
|
|
24
|
+
* copy of the module reaches the running instance), then rethrows it so
|
|
25
|
+
* React Native's fatal path still runs unchanged.
|
|
26
|
+
*/
|
|
27
|
+
export declare const captureRenderError: (error: unknown) => void;
|
|
28
|
+
/**
|
|
29
|
+
* Uncaught errors route through React Native's global handler; a fatal one
|
|
30
|
+
* terminates the app once the handler returns, which is why the crash outbox
|
|
31
|
+
* runs inside it. The previous handler (React Native's red box in
|
|
32
|
+
* development, a crash reporter's hook) always runs after ours. Render
|
|
33
|
+
* errors reach the same fatal path from `<SazabiRoot>` (`captureRenderError`);
|
|
34
|
+
* a crash reported more than once in one task is recorded once.
|
|
35
|
+
*
|
|
36
|
+
* Hermes exposes one promise-rejection tracker slot and no way to read it:
|
|
37
|
+
* `HermesInternal` is frozen (its methods non-writable and non-configurable,
|
|
38
|
+
* the object non-extensible) and the global that names it is non-writable
|
|
39
|
+
* and non-configurable too (`lib/VM/JSLib/HermesInternal.cpp`,
|
|
40
|
+
* `lib/VM/JSLib/GlobalObject.cpp`), so the installer cannot be wrapped from
|
|
41
|
+
* JavaScript and whoever held the slot before `init()` is unknowable. The
|
|
42
|
+
* host hands that tracker over as `errors.previousRejectionTracker` and ours
|
|
43
|
+
* runs it after recording; `errors.unhandledRejections: false` leaves the
|
|
44
|
+
* slot alone. Without either, a development build is told once per process.
|
|
45
|
+
*/
|
|
46
|
+
export declare const installErrorCapture: (options: ErrorCaptureOptions) => ErrorCaptureHandle;
|
package/dist/host.d.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { type EventAttributes } from "./client-sdk-core/index.js";
|
|
2
|
+
/**
|
|
3
|
+
* react-native-web renders in a real browser, where `@sazabi/browser` owns
|
|
4
|
+
* capture. This SDK installs nothing there.
|
|
5
|
+
*/
|
|
6
|
+
export declare const isWebHost: () => boolean;
|
|
7
|
+
/**
|
|
8
|
+
* Resource attributes the host can report without a native module: OTEL
|
|
9
|
+
* `os.*` from `Platform`, the `device.*` fields Android's
|
|
10
|
+
* `Platform.constants` carries (`Brand`, `Manufacturer`, `Model`), and on iOS
|
|
11
|
+
* the manufacturer plus `device.type` from `interfaceIdiom` (`phone`, `pad`,
|
|
12
|
+
* `tv`, `carplay`, `mac`, `vision`). iOS reports no model through JavaScript.
|
|
13
|
+
* `os.name` stays `Platform.OS` (`ios`, `android`) on both, so queries match
|
|
14
|
+
* one casing; iPadOS shows as `device.type: "pad"`.
|
|
15
|
+
*/
|
|
16
|
+
export declare const hostResourceAttributes: () => EventAttributes;
|
|
17
|
+
export declare const isDevHost: () => boolean;
|
|
18
|
+
/**
|
|
19
|
+
* The Metro (or Expo) development server this bundle was loaded from, as
|
|
20
|
+
* `<origin>/`, read from `SourceCode.scriptURL` the way React Native's own
|
|
21
|
+
* `getDevServer()` does. Only under `__DEV__`, and only for an http(s)
|
|
22
|
+
* bundle URL: a release bundle loads from a file.
|
|
23
|
+
*/
|
|
24
|
+
export declare const devServerOrigin: () => string | undefined;
|
|
25
|
+
/**
|
|
26
|
+
* A request URL as the core expects it: absolute, credentials stripped.
|
|
27
|
+
* Relative references are not requests on a native host, so they resolve to
|
|
28
|
+
* nothing and are neither captured nor injected.
|
|
29
|
+
*/
|
|
30
|
+
export declare const resolveUrl: (raw: string) => string | undefined;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { type EventSeverity } from "./client-sdk-core/index.js";
|
|
2
|
+
import { SazabiRoot } from "./interactions.js";
|
|
3
|
+
import { trackNavigation } from "./navigation.js";
|
|
4
|
+
import type { ReactNativeSdkConfig } from "./types.js";
|
|
5
|
+
export type { AttributeValue, BeforeSend, ClientEvent, ClientEventType, ConsoleCaptureConfig, ConsoleCaptureLevel, ErrorCaptureConfig, RejectionTracker, EventAttributes, EventSeverity, NavigationContainerRefLike, NetworkCaptureConfig, PointerCaptureConfig, ReactNativeSdkConfig, StorageAdapter, } from "./types.js";
|
|
6
|
+
export { SazabiRoot, trackNavigation };
|
|
7
|
+
declare module "react-native" {
|
|
8
|
+
interface ViewProps {
|
|
9
|
+
/** Names this element in touch rows (`app.widget.name`), ahead of `accessibilityLabel` and `testID`. */
|
|
10
|
+
sazabiName?: string;
|
|
11
|
+
/** Keeps the name of this element and everything inside it out of touch rows. */
|
|
12
|
+
sazabiMask?: boolean;
|
|
13
|
+
}
|
|
14
|
+
interface TextProps {
|
|
15
|
+
/** Names this element in touch rows (`app.widget.name`), ahead of `accessibilityLabel` and `testID`. */
|
|
16
|
+
sazabiName?: string;
|
|
17
|
+
/** Keeps the name of this element and everything inside it out of touch rows. */
|
|
18
|
+
sazabiMask?: boolean;
|
|
19
|
+
}
|
|
20
|
+
interface TouchableWithoutFeedbackProps {
|
|
21
|
+
/** Names this element in touch rows (`app.widget.name`), ahead of `accessibilityLabel` and `testID`. */
|
|
22
|
+
sazabiName?: string;
|
|
23
|
+
/** Keeps the name of this element and everything inside it out of touch rows. */
|
|
24
|
+
sazabiMask?: boolean;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
export { SDK_VERSION } from "./version.js";
|
|
28
|
+
/**
|
|
29
|
+
* Initialize the SDK. Idempotent: repeat calls are ignored. Installs nothing
|
|
30
|
+
* under react-native-web (use `@sazabi/browser` there). When `consent` is
|
|
31
|
+
* provided, nothing is installed until it resolves true.
|
|
32
|
+
*/
|
|
33
|
+
export declare const init: (config: ReactNativeSdkConfig) => void;
|
|
34
|
+
/** Set the client-asserted user identity (`session.distinct_id`). */
|
|
35
|
+
export declare const identify: (distinctId: string, traits?: Record<string, unknown>) => void;
|
|
36
|
+
/**
|
|
37
|
+
* Logout: clear the client-asserted identity and rotate both session and
|
|
38
|
+
* window ids, so later activity on this device never threads into the
|
|
39
|
+
* previous user's timeline.
|
|
40
|
+
*/
|
|
41
|
+
export declare const reset: () => void;
|
|
42
|
+
/** Emit a custom mark into the session event stream. */
|
|
43
|
+
export declare const addEvent: (name: string, attributes?: Record<string, unknown>) => void;
|
|
44
|
+
/**
|
|
45
|
+
* Emit an application log line (`app.event_type: "log"`) with session context
|
|
46
|
+
* attached. Drops silently before init/consent, like all capture.
|
|
47
|
+
*/
|
|
48
|
+
export declare const log: (severity: EventSeverity, message: string, metadata?: Record<string, unknown>) => void;
|
|
49
|
+
/** Force-flush queued events. */
|
|
50
|
+
export declare const flush: () => Promise<void>;
|
|
51
|
+
/** Tear down all patches/listeners (restoring originals) and flush. */
|
|
52
|
+
export declare const shutdown: () => Promise<void>;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import{n,i,e,r,t,a,s,c,o,u,l,p,f}from"./chunk-h2nxjrr9.js";var ee=(d,m=4096)=>d.length>m?d.slice(0,m):d,ge=(d,m="",g=0)=>{let y={};for(let[b,v]of Object.entries(d)){let S=m?`${m}.${b}`:b;if(v===null||v===void 0)continue;if(typeof v==="object"&&!Array.isArray(v)&&g<4){Object.assign(y,ge(v,S,g+1));continue}if(typeof v==="number"||typeof v==="boolean")y[S]=v;else if(typeof v==="string")y[S]=ee(v);else try{y[S]=ee(JSON.stringify(v)??"")}catch{}}return y};var qt={error:"ERROR",warn:"WARN",info:"INFO",debug:"DEBUG"},Ie=0,Ce=(d)=>{Ie+=1;try{d()}finally{Ie-=1}},We=1000,Gt=4000,Qt=(d)=>{let m;if(typeof d==="string")m=d;else if(d instanceof Error)m=`${d.name}: ${d.message}`;else try{m=JSON.stringify(d)??String(d)}catch{m=String(d)}return m.length>We?`${m.slice(0,We)}…`:m},Je=(d)=>{let m=[],g=!1;for(let y of d.levels){let b=console[y];if(typeof b!=="function"||i(b))continue;let v=function(...S){if(b.apply(this??console,S),g||Ie>0)return;try{if(typeof S[0]==="string"&&S[0].startsWith(d.selfPrefix))return;g=!0;let k=S.map(Qt).join(" ").slice(0,Gt);d.emit({type:"log",body:k||`console.${y}`,severity:qt[y],timeUnixMs:Date.now(),attributes:{"app.console.level":y}})}catch{}finally{g=!1}};n(v);try{console[y]=v}catch{continue}m.push(()=>{if(console[y]===v)console[y]=b})}return{teardown(){for(let y of m)try{y()}catch{}}}};var Wt=/^([0-9a-f]{32})\./,Jt=/^[a-z0-9-]+?-([0-9a-f]{32})\./,Zt=(d)=>{let m=e(d)?.hostname;if(!m)return;let g=(Wt.exec(m)??Jt.exec(m))?.[1];return g?`sazabi_public_${g}`:void 0},Ze="/v1/logs",en=(d)=>{let m=e(d);if(!m)return;if(m.protocol!=="https:"&&m.protocol!=="http:")return;let g=m.pathname.replace(/\/+$/,"");if(g.endsWith(Ze))g=g.slice(0,-Ze.length);return`${m.origin}${g}`},Pe=(d)=>{let m=d.intakeUrl??d.intakeHost;if(!m)return;let g=en(m);if(!g)return;let y=d.publicKey??Zt(m);if(!y)return;return{baseUrl:g,publicKey:y}};var et=()=>{let d=globalThis.crypto,m=d?.getRandomValues;if(typeof m==="function")return(b)=>{let v=new Uint8Array(b);return m.call(d,v),v};let g=(Date.now()^2654435769)>>>0,y=Math.random()*4294967295>>>0;return(b)=>{let v=new Uint8Array(b);for(let S=0;S<b;S+=1){let k=g,w=y;g=w,k^=k<<23,k^=k>>>17,k^=w^w>>>26,y=k>>>0,v[S]=g+y&255}return v}},Oe=(d)=>Array.from(d,(m)=>m.toString(16).padStart(2,"0")).join(""),Se=(d,m)=>Oe(d(m)),ae=(d,m)=>`${m}_${Date.now().toString(36)}${Se(d,8)}`;var tn=1000,nn=1e4,rn=10,on=500,tt=1000,nt=30,sn=4,an=10,Me=(d,m,g,y)=>Math.hypot(g-d,y-m),rt=(d)=>({"app.widget.id":d?.id,"app.widget.name":d?.name,"app.widget.tag":d?.tag}),ot=(d)=>{let m=d.sampleIntervalMs??tn,g=d.partialIntervalMs??nn,y=new Map,b=[],v=Number.NEGATIVE_INFINITY,S,k=(h,C)=>{h.path.push(`${Math.round(C-h.startPerf)}:${Math.round(h.lastX)},${Math.round(h.lastY)}`),h.sampleCount+=1,h.lastSamplePerf=C},w=(h,C,U)=>{let{contact:M}=h,O=U===void 0,z=Math.round(C-h.startPerf),F=Me(M.x,M.y,h.lastX,h.lastY);try{d.emit({type:"pointer",body:`pointer ${M.type} ${z}ms ${Math.round(F)}px${O?" (ongoing)":""}`,severity:"INFO",timeUnixMs:O?Date.now():h.startUnixMs,attributes:{"app.pointer.id":String(M.id),"app.pointer.type":M.type,"app.pointer.primary":M.primary,"app.pointer.gesture_id":h.gestureId,"app.screen.coordinate.x":Math.round(M.x),"app.screen.coordinate.y":Math.round(M.y),"app.pointer.end.x":Math.round(h.lastX),"app.pointer.end.y":Math.round(h.lastY),"app.pointer.distance":Math.round(F),"app.pointer.duration_ms":z,"app.pointer.pressure":h.maxPressure,"app.pointer.concurrent":h.maxConcurrent,"app.pointer.path":h.path.join(";")||void 0,"app.pointer.sample_count":h.sampleCount,"app.pointer.partial":O?!0:void 0,"app.pointer.ended_by":U,...rt(M.target)}})}catch{}h.path=[]},E=(h)=>{h.partialTimer=setTimeout(()=>{h.partialTimer=void 0;try{let C=t();if(C-h.lastSamplePerf>=m)k(h,C);w(h,C,void 0),E(h)}catch{}},g)},I=(h,C)=>{let U=h.target?.name,M=U?`"${U}"`:h.target?.id??`${Math.round(h.x)},${Math.round(h.y)}`,O={...rt(h.target),"app.pointer.type":h.pointerType,"app.pointer.gesture_id":h.gestureId,"app.screen.coordinate.x":Math.round(h.x),"app.screen.coordinate.y":Math.round(h.y)};try{d.emit({type:"click",body:`click ${M}`,severity:"INFO",timeUnixMs:h.timeUnixMs,attributes:O})}catch{}b.push({time:C,x:h.x,y:h.y});while(b.length>0&&C-b[0].time>tt)b.shift();let z=b.filter((F)=>Math.abs(F.x-h.x)<=nt&&Math.abs(F.y-h.y)<=nt);if(z.length>=sn&&C-v>tt){v=C;try{d.emit({type:"rage_click",body:`rage click ${M}`,severity:"WARN",timeUnixMs:Date.now(),attributes:{...O,"app.pointer.tap_count":z.length}})}catch{}}try{d.onTap?.({x:h.x,y:h.y,target:h.target,gestureId:h.gestureId})}catch{}},H=(h,C)=>{let{contact:U}=h;if(h.maxConcurrent!==1||(U.button??0)!==0||C-h.startPerf>on||h.maxDistance>rn)return;I({x:h.lastX,y:h.lastY,target:U.target,pointerType:U.type,gestureId:h.gestureId,timeUnixMs:h.startUnixMs},C)},B=(h,C,U,M)=>{let O=t();if(y.delete(h.contact.id),h.partialTimer!==void 0)clearTimeout(h.partialTimer),h.partialTimer=void 0;if(h.lastX=C,h.lastY=U,h.maxDistance=Math.max(h.maxDistance,Me(h.contact.x,h.contact.y,C,U)),w(h,O,M),M==="up")H(h,O);if(y.size===0)S=void 0};return{down(h){try{let C=y.get(h.id);if(C)B(C,C.lastX,C.lastY,"cancel");if(y.size>=an)return;let U=t();if(y.size===0||S===void 0)S=ae(d.randomBytes,"gest");let M=y.size+1;for(let z of y.values())z.maxConcurrent=Math.max(z.maxConcurrent,M);let O={contact:h,gestureId:S,startUnixMs:Date.now(),startPerf:U,lastSamplePerf:U,lastX:h.x,lastY:h.y,maxDistance:0,maxPressure:h.pressure,maxConcurrent:M,path:[],sampleCount:0};k(O,U),y.set(h.id,O),E(O)}catch{}},move(h,C,U,M){try{let O=y.get(h);if(!O)return;if(O.lastX=C,O.lastY=U,O.maxDistance=Math.max(O.maxDistance,Me(O.contact.x,O.contact.y,C,U)),M!==void 0)O.maxPressure=Math.max(O.maxPressure??0,M);let z=t();if(z-O.lastSamplePerf>=m)k(O,z)}catch{}},up(h,C,U){try{let M=y.get(h);if(M)B(M,C,U,"up")}catch{}},cancel(h){try{let C=y.get(h);if(C)B(C,C.lastX,C.lastY,"cancel")}catch{}},tap(h){try{I({x:h.x,y:h.y,target:h.target,pointerType:"none",timeUnixMs:Date.now()},t())}catch{}},teardown(){for(let h of Array.from(y.values()))try{B(h,h.lastX,h.lastY,"teardown")}catch{}y.clear(),b.length=0}}};var Ee="sazabi.session",Ne="sazabi.windowId",ke="sazabi.distinctId",dn=1800000,cn=86400000,un=60000,ln=5000,ye=()=>{let d=new Map;return{get:(m)=>d.get(m)??null,set:(m,g)=>{d.set(m,g)},remove:(m)=>{d.delete(m)}}},pn=(d)=>{if(!d)return;try{let m=JSON.parse(d);if(typeof m==="object"&&m!==null&&typeof m.id==="string"&&typeof m.startedAt==="number"&&typeof m.lastActivityAt==="number")return m}catch{}return},st=(d)=>{let{store:m,windowStore:g,randomBytes:y}=d,b=0,v=()=>{let w=Date.now(),E=pn(m.get(Ee));if(E&&w-E.lastActivityAt<=dn&&w-E.lastActivityAt>=-un&&w-E.startedAt<=cn)return E;let I={id:ae(y,"sess"),startedAt:w,lastActivityAt:w};return m.set(Ee,JSON.stringify(I)),b=w,I},S=g.get(Ne);if(!S)S=ae(y,"win"),g.set(Ne,S);let k=()=>{let w=Date.now();m.set(Ee,JSON.stringify({id:ae(y,"sess"),startedAt:w,lastActivityAt:w})),b=w,S=ae(y,"win"),g.set(Ne,S)};return{getSessionId(){return v().id},getWindowId(){return S},getDistinctId(){return m.get(ke)??void 0},setDistinctId(w){let E=m.get(ke)??void 0;if(E!==void 0&&E!==w)k();m.set(ke,w)},reset(){m.remove(ke),k()},touch(){let w=Date.now(),E=v();if(w-b>=ln)m.set(Ee,JSON.stringify({...E,lastActivityAt:w})),b=w}}};var fn=1,mn=/^[0-9a-f]{32}$/,gn=/^[0-9a-f]{16}$/,yn="0".repeat(32),vn="0".repeat(16),it=(d,m)=>{let g;do g=d(m);while(g.every((y)=>y===0));return Oe(g)},hn=(d)=>{if(typeof d!=="object"||d===null)return!1;let{traceId:m,spanId:g,traceFlags:y}=d;return typeof m==="string"&&mn.test(m)&&m!==yn&&typeof g==="string"&&gn.test(g)&&g!==vn&&typeof y==="number"},bn=Symbol.for("opentelemetry.js.api.1"),Sn=Symbol.for("OpenTelemetry Context Key SPAN"),En=()=>{try{let y=globalThis[bn]?.context?.active?.()?.getValue?.(Sn)?.spanContext?.();return hn(y)?y:void 0}catch{return}},kn=(d)=>{let m=(d.traceFlags&255).toString(16).padStart(2,"0");return`00-${d.traceId}-${d.spanId}-${m}`},xn=(d)=>{try{return d.traceState?.serialize()||void 0}catch{return}},at=(d)=>{let m=()=>({traceId:it(d.randomBytes,16),spanId:it(d.randomBytes,8),traceFlags:d.sampledFlag?fn:0});return{forRequest(){let g=En()??m(),y={traceparent:kn(g)},b=xn(g);if(b)y.tracestate=b;return{headers:y,traceId:g.traceId,spanId:g.spanId}}}};var dt=(d)=>{let m=new Set;return(g)=>{if(m.has(g.diagnostic))return;m.add(g.diagnostic);try{d({type:"sdk_health",body:`sdk_health ${g.diagnostic}`,severity:"INFO",timeUnixMs:Date.now(),attributes:{["app.sdk.diagnostic"]:g.diagnostic,...g.attributes}})}catch{}}};var wn={DEBUG:5,INFO:9,WARN:13,ERROR:17},Rn=1024,Tn=(d)=>{if(typeof d==="boolean")return{boolValue:d};if(typeof d==="number")return Number.isInteger(d)?{intValue:String(d)}:{doubleValue:d};return{stringValue:ee(d)}},xe=(d)=>{let m=[];for(let[g,y]of Object.entries(d)){if(y===void 0)continue;m.push({key:g,value:Tn(y)})}return m},ut=(d,m)=>{let g={timeUnixNano:`${d.timeUnixMs}000000`,severityNumber:wn[d.severity],severityText:d.severity,body:{stringValue:ee(d.body,Rn)},attributes:xe({...m,...d.attributes})};if(d.traceId)g.traceId=d.traceId;if(d.spanId)g.spanId=d.spanId;return g},De=(d)=>{let m=d.length;for(let g=0;g<d.length;g+=1){let y=d.charCodeAt(g);if(y<128)continue;if(y<2048)m+=1;else if(y>=55296&&y<=56319&&(d.charCodeAt(g+1)&64512)===56320)m+=2,g+=1;else m+=2}return m},An=4,ct=1048576,_n=30000,In=1000,Cn=60000,Pn=300000,On="app.sdk.dropped_events",Mn="x-sazabi-sdk",Le={kind:"retry",network:!0},Nn=(d)=>{try{let m=d.headers?.get?.("retry-after");if(!m)return;let g=Number(m),y=Number.isFinite(g)?g*1000:Date.parse(m)-Date.now();return y>0?Math.min(y,Pn):void 0}catch{return}},Dn=(d)=>{let m=d?.status;if(typeof m!=="number"||m>=200&&m<300)return{kind:"sent"};if(m===408||m===429||m>=500)return{kind:"retry",retryAfterMs:Nn(d)};return{kind:m===413?"split":"drop",status:m}},lt=(d)=>{let m=[],g=0,y=0,b,v=!1,S=!1,k=new Set,w=new Set,E=!1,I=0,H=0,B=0,h=0,C=new Set,U=(x)=>{try{d.onHealth?.(x)}catch{}},M=(x,_)=>{if(C.has(x))return;C.add(x);try{d.warn?.(_)}catch{}},O=(x)=>JSON.stringify({resourceLogs:[{resource:{attributes:xe(d.resourceAttributes)},scopeLogs:[{scope:{name:d.scope.name,version:d.scope.version},logRecords:x}]}]}),z=De(O([]))+64,F=Math.max(4096,d.maxBatchBytes-z),j=()=>{if(b!==void 0)clearTimeout(b),b=void 0},Z=()=>{if(b!==void 0||v)return;let x=B-Date.now();b=setTimeout(()=>{b=void 0,V()},x>0?x:d.flushIntervalMs)},ne=()=>{while(m.length>d.maxQueuedEvents||g>ct){let x=m.shift();if(g-=x.bytes,I+=1,x.saved)E=!0;M("full","the event queue is full (is the device offline?); dropping the oldest events.")}},K=(x,_)=>{let D=[];if(_<=0)return D;let A=[],P=0;for(let X of x){if(A.length>0&&P+X.bytes>F){if(D.push(A),A=[],P=0,D.length>=_)break}A.push(X),P+=X.bytes}if(A.length>0)D.push(A);return D},N=(x)=>{let _=K(m,x),D=0;for(let A of _)D+=A.length;for(let A of m.splice(0,D))g-=A.bytes;return _},Y=(x,_)=>_.length===0?x:{...x,attributes:[...x.attributes.filter((D)=>!_.some(({key:A})=>A===D.key)),..._]},Q=(x)=>{let _=x.map((P)=>P.record),D=I,A=_[0];if(D>0&&A)I=0,_[0]={...A,attributes:[...A.attributes,{key:On,value:{intValue:String(D)}}]};return{records:_,count:A?D:0}},q=(x,_=!1)=>{let D=globalThis.AbortController,A,P;try{A=D?new D:void 0,P=d.fetchImpl(d.url,{method:"POST",headers:{"content-type":"application/json",authorization:`Bearer ${d.publicKey}`,[Mn]:`${d.scope.name}/${d.scope.version}`},body:x,keepalive:_,signal:A?.signal})}catch{return Promise.resolve(Le)}return new Promise((X)=>{let be=setTimeout(()=>{try{A?.abort?.()}catch{}X(Le)},_n);Promise.resolve(P).then(Dn,()=>Le).then((jt)=>{clearTimeout(be),X(jt)})})},W=()=>Date.now()<B,se=(x)=>{m.push(...x),m.sort((_,D)=>_.seq-D.seq);for(let _ of x)g+=_.bytes;ne()},_e=(x,_)=>{let D=Date.now();if(D>=B){if(H+=1,_)h+=1}let A=Math.min(Cn,In*2**(H-1)),P=Math.max(x??0,A/2+Math.random()*A/2);B=Math.max(B,D+P),j(),Z()},ue=async(x,_)=>{let{records:D,count:A}=Q(x),P=await q(O(D),_);if(h>0&&(P.kind!=="retry"||P.network!==!0)){let X=h;h=0,U({diagnostic:"intake_unreachable",attributes:{"app.sdk.attempts":X}})}if(P.kind==="sent"){H=0;return}if(I+=A,P.kind==="split"&&x.length>1){let X=Math.ceil(x.length/2);for(let be of[x.slice(0,X),x.slice(X)])if(!_&&!v&&W())se(be),Z();else await ue(be,_);return}if(P.kind==="retry"){if(v){if(x.some((X)=>X.saved))E=!0;return}se(x),_e(P.retryAfterMs,P.network===!0);return}I+=x.length,M(String(P.status),`the intake refused a batch with HTTP ${P.status}; dropped ${x.length} event(s).`),U({diagnostic:"intake_rejected",attributes:{"app.sdk.http_status":P.status}})},re=0,ie=new Map,me=(x,_)=>{let D=re;re+=1;let A=ue(x,_).then(()=>{if(k.delete(A),w.delete(x),ie.delete(D),m.length===0&&k.size===0&&!E)try{d.onIdle?.()}catch{}});return k.add(A),w.add(x),ie.set(D,A),A},R=null,L=async()=>{while(!W()){for(let x of N(An-k.size))me(x,!1);if(m.length===0)break;await Promise.race(k)}},V=async(x)=>{j();let _=x?.keepalive===!0;if(_||v){await Promise.all(N(Number.POSITIVE_INFINITY).map((P)=>me(P,_)));return}let D=re;while(m.length>0&&!W()){if(R===null)R=L().finally(()=>{R=null});await R}if(m.length>0)Z();let A=[];for(let[P,X]of ie)if(P>=D)A.push(X);await Promise.all(A)};return{enqueue(x){if(v)return;let _=De(JSON.stringify(x))+1;if(_>ct){I+=1,M("oversized","dropped an event larger than the 1 MiB queue limit.");return}if(m.push({record:x,bytes:_,seq:y}),y+=1,g+=_,ne(),S)return;if(g>=F&&!W())V();else Z()},flush:V,drainEnvelopes(x){j();let _=x?xe(x):[];return N(Number.POSITIVE_INFINITY).map((D)=>{let{records:A}=Q(D);return O(A.map((P)=>Y(P,_)))})},snapshotEnvelopes(x){let _=xe(x);E=!1;for(let A of m){A.record=Y(A.record,_);let P=De(JSON.stringify(A.record))+1;g+=P-A.bytes,A.bytes=P,A.saved=!0}let D=new Set(m);for(let A of w)for(let P of A)if(P.saved)D.add(P);return K([...D].sort((A,P)=>A.seq-P.seq),Number.POSITIVE_INFINITY).map((A)=>O(A.map((P)=>P.record)))},holdFlushes(x){S=x},async sendEnvelope(x){let _=await q(x);if(_.kind==="retry")return!1;if(_.kind!=="sent")M(String(_.status),`the intake refused a stored crash report with HTTP ${_.status}; dropped it.`),U({diagnostic:"intake_rejected",attributes:{"app.sdk.http_status":_.status}});return!0},async shutdown(){v=!0,await V()}}};var pt=(d,m)=>{if(!d)return(y)=>y;let g=!1;return(y)=>{if(g)return m({reason:"before_send_nested",message:"an event was captured while beforeSend was running; nested events are dropped."}),null;g=!0;let b;try{b=d(y)}catch(v){return m({reason:"before_send_threw",message:`beforeSend threw (${v instanceof Error?v.message:String(v)}); the event was dropped.`}),null}finally{g=!1}if(b===null)return null;if(typeof b!=="object"||typeof b.type!=="string"||typeof b.body!=="string"||typeof b.severity!=="string"||typeof b.timeUnixMs!=="number"||typeof b.attributes!=="object"||b.attributes===null)return m({reason:"before_send_invalid",message:"beforeSend must return the event or null; the event was dropped."}),null;return b}};var T=globalThis.__sazabiReactNative??={initialized:!1,warnedWebHost:!1,warnedRejectionSlot:!1,generation:0,pendingReset:!1,screen:{}};var Ue="@sazabi/react-native",we="0.1.1",de="[@sazabi/react-native]";var ft=()=>globalThis.HermesInternal,mt=(d)=>{try{d()}catch{}},Ln=(d)=>{try{let m=typeof d==="string"?d:typeof d==="object"&&d!==null?JSON.stringify(d)??String(d):String(d);return ee(m)}catch{try{return ee(Object.prototype.toString.call(d))}catch{return"[unreadable thrown value]"}}},He=(d,m)=>{let g=d instanceof Error?d:void 0,y=(S)=>{try{let k=g?.[S];return typeof k==="string"?ee(k):void 0}catch{return}},b=y("name")||(m==="unhandledrejection"?"UnhandledRejection":"Error"),v=g?y("message")??"":Ln(d);return{type:"error",body:ee(`${b}: ${v}`,512),severity:"ERROR",timeUnixMs:Date.now(),attributes:{"exception.type":b,"exception.message":v,"exception.stacktrace":y("stack")??"","app.error.kind":m}}},gt=(d)=>{try{T.renderErrorSink?.(d)}catch{}},Un=(d)=>{if(d instanceof Error)return d.stack||`${d.name}: ${d.message}`;if(typeof d==="string")return d;try{return JSON.stringify(d)??String(d)}catch{return String(d)}},Be=(d)=>{if(!o())return;try{let m=d();Ce(()=>console.warn(m))}catch{}},yt=(d)=>{let m=globalThis.ErrorUtils,g=m?.getGlobalHandler?.(),y=!0,b=!1,v=(k)=>{if(!y||b)return;b=!0,setTimeout(()=>{b=!1},0),d.onFatal(He(k,"fatal"))},S=(k,w)=>{let E=()=>g?.(k,w);if(!y){E();return}try{if(w)v(k);else d.emit(He(k,"uncaught"))}catch{}Ce(E)};if(m?.setGlobalHandler?.(S),T.renderErrorSink=v,d.unhandledRejections){let k=d.previousRejectionTracker;if(!k&&!T.warnedRejectionSlot&&o()&&typeof ft()?.enablePromiseRejectionTracker==="function")T.warnedRejectionSlot=!0,Be(()=>`${de} init() takes over Hermes's only promise rejection tracker slot, and a tracker another library installed before it cannot be seen. If one exists, pass errors.previousRejectionTracker to keep it running, or errors.unhandledRejections: false to leave the slot alone.`);let w={allRejections:!0,onUnhandled:(E,I)=>{if(y)try{d.emit(He(I,"unhandledrejection"))}catch{}if(k){mt(()=>k.onUnhandled(E,I));return}Be(()=>`Possible unhandled promise rejection (id: ${E}):
|
|
2
|
+
${Un(I)}`)},onHandled:(E)=>{if(k){mt(()=>k.onHandled?.(E));return}Be(()=>`Promise rejection handled (id: ${E})
|
|
3
|
+
This means you can ignore any previous messages of the form "Possible unhandled promise rejection (id: ${E}):"`)}};try{ft()?.enablePromiseRejectionTracker?.(w)}catch{}}return{teardown(){if(y=!1,T.renderErrorSink===v)T.renderErrorSink=void 0;try{if(g&&m?.getGlobalHandler?.()===S)m.setGlobalHandler?.(g)}catch{}}}};import{Component as Hn,createElement as Bn}from"react";import{View as Fn}from"react-native";var Fe=(d)=>{T.tracker=d},Kn=60,$n=3,vt=64,Vn="sazabiName",zn="sazabiMask",ht=new Set(["button","link","tab","menuitem","checkbox","radio","switch","togglebutton","imagebutton","searchbox"]),ve=(d)=>{if(typeof d!=="string")return;let m=d.replace(/\s+/g," ").trim();if(!m)return;return m.length>vt?`${m.slice(0,vt)}…`:m},Yn=(d)=>{let m=d.type??d.elementType;if(typeof m==="function"){let g=m;return ve(g.displayName||g.name)}if(typeof m==="object"&&m!==null){let g=m.render??m.type;if(typeof g==="function"){let y=g;return ve(y.displayName||y.name)}}return},Xn=(d)=>{try{let m=d;if(!m||typeof m!=="object")return;let g,y=!1,b=!1,v=[];for(let S=0;m&&S<Kn;S+=1){let k=m.memoizedProps??void 0;if(k){if(k[zn])y=!0;if(g===void 0)g=ve(k[Vn])??ve(k.accessibilityLabel)??ve(k.testID);if(typeof k.onPress==="function"||typeof k.onPressIn==="function"||typeof k.accessibilityRole==="string"&&ht.has(k.accessibilityRole)||typeof k.role==="string"&&ht.has(k.role))b=!0}if(v.length<$n){let w=Yn(m);if(w&&w!=="SazabiRoot")v.unshift(w)}m=m.return}return{id:v.length>0?v.join(" > "):void 0,name:y?void 0:g,tag:v[v.length-1],interactive:b}}catch{return}},jn=(d)=>{let m=T.tracker;if(!m)return;try{let{changedTouches:g,touches:y}=d.nativeEvent,b=Xn(d._targetInst);for(let v of g)m.down({id:v.identifier,type:"touch",primary:y.length<=1,x:v.pageX,y:v.pageY,pressure:v.force||void 0,target:b})}catch{}},qn=(d)=>{let m=T.tracker;if(!m)return;try{for(let g of d.nativeEvent.changedTouches)m.move(g.identifier,g.pageX,g.pageY,g.force||void 0)}catch{}},Gn=(d)=>{let m=T.tracker;if(!m)return;try{for(let g of d.nativeEvent.changedTouches)m.up(g.identifier,g.pageX,g.pageY)}catch{}},Qn=(d)=>{let m=T.tracker;if(!m)return;try{for(let g of d.nativeEvent.changedTouches)m.cancel(g.identifier)}catch{}},Wn={flex:1};class bt extends Hn{static displayName="SazabiRoot";state={};static getDerivedStateFromError(d){return gt(d),{error:{value:d}}}render(){let d=this.state.error;if(d)throw d.value;return Bn(Fn,{style:Wn,collapsable:!1,onTouchStart:jn,onTouchMove:qn,onTouchEnd:Gn,onTouchCancel:Qn},this.props.children)}}import{AppState as St}from"react-native";var Et=(d)=>{let m=St.currentState,g=(b)=>{try{if(b===m)return;if(m=b,b!=="active"&&b!=="background"&&b!=="inactive")return;if(d.emit({type:"lifecycle",body:`lifecycle ${b}`,severity:"INFO",timeUnixMs:Date.now(),attributes:{"app.lifecycle.state":b}}),b!=="active")d.onBackground()}catch{}},y;try{y=St.addEventListener("change",g)}catch{}return{teardown(){try{y?.remove()}catch{}}}};var Ke=()=>T.screen,$e=(d,m)=>{T.navigationEmit=d,T.navigationRedactUrl=m},Jn=(d)=>{if(!d)return;let m=Object.keys(d);return m.length>0?m.join(","):void 0},Zn=(d)=>{let m=()=>{try{let y=d.getCurrentRoute();if(!y)return;let b=T.screen;if(y.key===b.key&&y.name===b.name&&y.path===b.path)return;T.screen={name:y.name,path:y.path,key:y.key},T.navigationEmit?.({type:"navigation",body:`navigation ${y.name}`,severity:"INFO",timeUnixMs:Date.now(),attributes:{"app.navigation.type":"screen","app.screen.name":y.name,"url.path":y.path===void 0?void 0:T.navigationRedactUrl?.(y.path)??y.path,"app.navigation.from":b.name,"app.navigation.params":Jn(y.params)}})}catch{}};m();let g;try{g=d.addListener("state",m)}catch{}return()=>{try{g?.()}catch{}}},kt=()=>{T.screen={},T.navigationEmit=void 0,T.navigationRedactUrl=void 0};var er=async(d,m)=>{try{let g=await d.getItem(m);return typeof g==="string"?g:null}catch{return null}},ce=(d)=>typeof d?.then==="function",xt=(d,m)=>{try{let g=d();return ce(g)?Promise.resolve(g).then(m,()=>{return}):m(g)}catch{return}},wt=(d,m)=>xt(()=>d.getItem(m),(g)=>({value:typeof g==="string"?g:null})),Rt=(d)=>xt(()=>d.getAllKeys?.(),(m)=>Array.isArray(m)?m.filter((g)=>typeof g==="string"):void 0),he=(d,m,g)=>{try{let y=d.setItem(m,g);return ce(y)?Promise.resolve(y).then(()=>!0,()=>!1):!0}catch{return!1}},G=(d,m)=>{try{let g=d.removeItem(m);return ce(g)?Promise.resolve(g).then(()=>!0,()=>!1):!0}catch{return!1}},Tt=(d,m)=>{let g=ye(),y=new Set,b=(async()=>{for(let v of m){let S=await er(d,v);if(S!==null&&!y.has(v))g.set(v,S)}})();return{store:{get:(v)=>g.get(v),set(v,S){g.set(v,S),y.add(v),he(d,v,S)},remove(v){g.remove(v),y.add(v),G(d,v)}},ready:b}};var ze="sazabi.outbox.",Ct="sazabi.outbox.index",Ye="sazabi.outbox.index.unmerged",Pt="sazabi.outbox",Ot="sazabi.outbox.unmerged",pe="sazabi.outbox.queue",Mt="app.outbox.id",Nt=20,Dt=524288,te=(d)=>`${ze}${d}`,tr=/^(?:[0-9a-f]{16}|legacy|legacy-unmerged)$/,nr=(d,m)=>(d??[]).filter((g)=>g.startsWith(ze)).map((g)=>g.slice(ze.length)).filter((g)=>tr.test(g)&&!m.has(g)),At=new WeakMap,oe=(d)=>{let m=At.get(d);if(m)return m;let g={batches:[],unmerged:[],loaded:!1,inFlight:new Set,discarded:0,unsaved:0};return At.set(d,g),g},Lt=(d,m)=>{oe(d).report=m},Ut=(d,m)=>{let g=oe(d);if(g.report===m)g.report=void 0},Ht=(d)=>{if(d.discarded===0&&d.unsaved===0)return;let{discarded:m,unsaved:g}=d;d.discarded=0,d.unsaved=0,d.report?.({diagnostic:"outbox_discarded",attributes:{"app.sdk.outbox_discarded":m,"app.sdk.outbox_unsaved":g}})},Xe=(d,m)=>{let g=d.report;if(!g)return;J(m,(y)=>{if(!y&&d.report===g)g({diagnostic:"outbox_persist_failed"})})},J=(d,m)=>ce(d)?Promise.resolve(d).then(m):m(d),Ae=(d)=>d.some(ce)?Promise.all(d):d,_t=(d,m)=>Ae(m.map((g)=>wt(d,g))),fe=(d,m,g)=>g.length===0?G(d,m):he(d,m,JSON.stringify(g)),le=(d)=>d.map((m)=>m.id),It=(d)=>{let m=new Set;return d.filter((g)=>{if(m.has(g.id))return!1;return m.add(g.id),!0})},qe=(d)=>{let m=oe(d);if(!m.loaded)return m.unmergedRead!==!1&&fe(d,Ye,le(m.unmerged));return J(fe(d,Ct,le(m.batches)),(g)=>g&&m.unmergedRead?J(G(d,Ye),()=>g):g)},Bt=(d)=>{let m=0,g=0;for(let y=d.length-1;y>=0;y-=1){if(m+=d[y].length,g===Nt||m>Dt&&g>0)break;g+=1}return d.slice(d.length-g)},je=(d,m)=>{let g=0,y=0;for(let b=m.length-1;b>=0;b-=1){let v=m[b]?.envelopes??[];g+=v.length;for(let S of v)y+=S.length;if(b<m.length-1&&(g>Nt||y>Dt)){let S=m.splice(0,b+1);for(let k of S)d.discarded+=k.envelopes?.length??0;return S}}return[]},Re=(d)=>{try{return JSON.parse(d)}catch{return}},Ft=(d)=>Array.isArray(d)?d.filter((m)=>typeof m==="string"):[],Te=(d)=>Ft(d?Re(d):void 0),Ve=(d,m)=>{let g=m?Re(m):void 0,y=Ft(g).filter((v)=>{let S=Re(v);return typeof S==="object"&&S!==null}),b=!m?0:Array.isArray(g)?g.length-y.length:1;if(d.discarded+=b,b)d.warn?.("discarded a stored crash report that is not valid JSON."),d.warn=void 0;return{envelopes:y,discarded:b}},rr=(d,m,[g,y,b,v,S],k,w)=>{if(y)m.unmergedRead=!0;else if(m.unmergedRead===void 0)m.unmergedRead=!1;let E=new Set,I=new Map,H=(K)=>K.flatMap((N)=>{let Y=I.get(N);if(Y)return Y;let Q=k.get(N),q;if(!Q)q=[{id:N}];else if(Q.value===null)q=[];else{let{envelopes:W,discarded:se}=Ve(m,Q.value);if(W.length===0)E.add(N),q=[];else{if(se)fe(d,te(N),W);q=[{id:N,envelopes:W}]}}return I.set(N,q),q}),B=H(Te(g?.value)),h=H(Te(y?.value)),C=new Set(le([...m.batches,...m.unmerged])),U=H(w.filter((K)=>!C.has(K)));if(!g&&m.unmergedRead===!1){m.discarded=0,m.unsaved=0;return}let M=new Set(le([...B,...h,...U,...m.batches,...m.unmerged])),O=[],z=(K,N)=>{if(!K||N.length===0||M.has(K))return!0;return M.add(K),E.delete(K),O.push({id:K,envelopes:N}),fe(d,te(K),N)},F=[];for(let[K,N,Y]of[[b,"legacy",Pt],[v,"legacy-unmerged",Ot]]){if(!K?.value)continue;F.push([Y,z(N,Ve(m,K.value).envelopes)])}let j=S?.value?Re(S.value):void 0;if(typeof j?.discarded==="number"&&j.discarded>0)m.unsaved+=Math.floor(j.discarded);let Z=z(typeof j?.id==="string"?j.id:void 0,Ve(m,JSON.stringify(j?.envelopes??[])).envelopes),ne;if(g)m.batches=It([...B,...h,...U,...O,...m.unmerged]),m.unmerged=[],m.loaded=!0,ne=je(m,m.batches);else m.unmerged=It([...h,...O,...m.unmerged]),ne=je(m,m.unmerged);Ht(m),J(qe(d),(K)=>{for(let N of le(ne))G(d,te(N));if(!K)return;for(let N of E)G(d,te(N));return J(Ae([Z,...F.map(([,N])=>N)]),([N,...Y])=>{for(let[Q,[q]]of F.entries())if(Y[Q])G(d,q);if(!S||!N)return;return J(S.value?G(d,pe):!0,()=>{m.queueRead=!0})})})},Ge=(d,m)=>{let g=oe(d);if(g.loading)return g.loading;g.warn??=m;let y=Rt(d),b=J(_t(d,[Ct,Ye,Pt,Ot,pe]),(S)=>J(y,(k)=>{let w=[...new Set([...Te(S[0]?.value),...Te(S[1]?.value)])],E=S[0]&&S[1]?nr(k,new Set(w)):[],I=[...w,...E];return J(_t(d,I.map(te)),(H)=>{rr(d,g,S,new Map(I.map((B,h)=>[B,H[h]])),E)})}));if(!ce(b)){if(g.loaded)g.loading=Promise.resolve();return Promise.resolve()}let v=b.then(()=>{if(!g.loaded)g.loading=void 0});return g.loading=v,v},Kt=async(d,m,g)=>{let y=oe(d),b=g.filter((E)=>!y.inFlight.has(E));if(b.length===0)return;for(let E of b)y.inFlight.add(E);let v;try{v=await Promise.all(b.map((E)=>m.sendEnvelope(E)))}finally{for(let E of b)y.inFlight.delete(E)}let S=new Set(b.filter((E,I)=>v[I]));if(S.size===0)return;let k=[];for(let E of[y.batches,y.unmerged])for(let I of E){let H=I.envelopes?.filter((B)=>!S.has(B));if(!H||H.length===I.envelopes?.length)continue;if(I.envelopes=H,H.length>0)fe(d,te(I.id),H);else k.push([E,I])}let w=await Ae(k.map(([,E])=>J(G(d,te(E.id)),(I)=>I||he(d,te(E.id),"[]"))));k.forEach(([E,I],H)=>{let B=E.indexOf(I);if(w[H]&&B>=0)E.splice(B,1)}),await qe(d)},$t=(d,m,g)=>{let y=m.drainEnvelopes({[Mt]:g}),b=Bt(y);if(b.length===0)return!0;let v=oe(d);v.discarded+=y.length-b.length;let S=v.loaded?v.batches:v.unmerged;S.push({id:g,envelopes:b});let k=je(v,S),w=fe(d,te(g),b),E=qe(d),I=E===!0&&w===!0;for(let H of le(k))G(d,te(H));if(Ht(v),Xe(v,w),v.loaded||v.unmergedRead!==!1)Xe(v,E);if(v.queueSaved===m)v.queueSaved=void 0,J(Ae([w,E]),(H)=>{if(H.every(Boolean)&&v.queueSaved===void 0)G(d,pe)});if(!I)Kt(d,m,b);return I},Qe=async(d,m)=>{await Ge(d);let g=oe(d);await Kt(d,m,[...new Set([...g.batches,...g.unmerged].flatMap((y)=>y.envelopes??[]))])},Vt=(d,m,g)=>{let y=oe(d);if(!y.queueRead)return;let b=m.snapshotEnvelopes({[Mt]:g}),v=Bt(b);if(y.queueSaved=v.length>0?m:void 0,y.queueSaved){let S=b.length-v.length;Xe(y,he(d,pe,JSON.stringify(S>0?{id:g,envelopes:v,discarded:S}:{id:g,envelopes:v})))}else G(d,pe)},zt=(d,m)=>{let g=oe(d);if(g.queueSaved!==m)return;g.queueSaved=void 0,G(d,pe)};var or=5000,sr=57344,ir=500,ar=200,dr=["x-request-id","cf-ray","x-vercel-id","x-amz-cf-id","fly-request-id"],cr=["sazabi.session","sazabi.distinctId"],ur=2000,lr="javascript",Yt=(d,m)=>({type:"custom",body:`identify ${d}`,severity:"INFO",timeUnixMs:Date.now(),attributes:{"app.custom.name":"identify",...m?ge(m,"custom"):{}}}),pr=(d)=>{let m=globalThis.fetch;if(typeof m!=="function")return;let g=(R,L)=>m(R,L),y=Pe(d);if(!y)return;let b=`${y.baseUrl}/v1/logs`,v=et(),S=d.storage,k=(R)=>console.warn(`${de} ${R}`),w=lt({url:b,publicKey:y.publicKey,resourceAttributes:{"service.name":d.serviceName,"service.version":d.serviceVersion,"deployment.environment":d.environment,"telemetry.sdk.name":Ue,"telemetry.sdk.version":we,"telemetry.sdk.language":lr,...c()},scope:{name:Ue,version:we},fetchImpl:g,flushIntervalMs:d.flushIntervalMs??or,maxBatchBytes:d.maxBatchBytes??sr,maxQueuedEvents:d.maxQueuedEvents??ir,warn:k,onHealth:(R)=>Z(R),onIdle:()=>{if(S)zt(S,w)}}),E,I=[],H=0,B=!1,h=d.network??{},C=(R)=>a(R,h.redactQueryParams),U=(R,L,V=Ke())=>{L.touch();let x={"app.event_type":R.type,"session.id":L.getSessionId(),"session.window_id":L.getWindowId(),"session.distinct_id":L.getDistinctId(),"app.screen.name":V.name,"app.screen.url":V.path===void 0?void 0:C(V.path),"derived.source":"sdk"};w.enqueue(ut(R,x))},M=new Set,O=(R)=>{if(M.has(R.reason))return;M.add(R.reason);let{message:L}=R;k(L)},z=pt(d.beforeSend,O),F=(R)=>{if(B)return;try{let L=z(R);if(!L)return;if(E)U(L,E);else if(H<ar||L.type==="sdk_health")I.push({kind:"event",event:L,screen:Ke()}),H+=1}catch{}},j=(R)=>{try{F(R())}catch{}},Z=dt(F);if(S)Lt(S,Z),Ge(S,k);let ne=u(),K=(R)=>r({url:R,base:y.baseUrl})||ne!==void 0&&r({url:R,base:ne})||o()&&R.includes("/symbolicate"),N=[];if(S)N.push(()=>Ut(S,Z));let Y,Q=!1;N.push(()=>{if(Y!==void 0)clearTimeout(Y);Y=void 0});let q=yt({emit:F,unhandledRejections:d.errors?.unhandledRejections!==!1,previousRejectionTracker:d.errors?.previousRejectionTracker,onFatal:(R)=>{Q=!0,w.holdFlushes(!0);try{if(ie(),F(R),S)$t(S,w,Se(v,8))}finally{w.holdFlushes(!1)}if(!S){w.flush();return}if(Y===void 0&&!B)Y=setTimeout(()=>{Y=void 0,Qe(S,w)},ur)}});if(N.push(()=>q.teardown()),d.pointer?.capture!==!1){let R=ot({emit:F,randomBytes:v,sampleIntervalMs:d.pointer?.sampleIntervalMs,partialIntervalMs:d.pointer?.partialIntervalMs});Fe(R),N.push(()=>{Fe(void 0),R.teardown()})}if($e(F,C),N.push(()=>$e(void 0)),d.console?.capture!==!1){let R=Je({emit:F,levels:d.console?.levels??["error","warn"],selfPrefix:de});N.push(()=>R.teardown())}let W=h.capture??!0,se=h.propagateTraceContext??!0;if(W||se){let R=f({emit:F,traceContext:at({sampledFlag:h.sampledFlag??!1,randomBytes:v}),capture:W,propagateTraceContext:se,allowlist:h.allowlist??[],redactQueryParams:h.redactQueryParams,requestIdHeaders:h.requestIdHeaders??dr,isInternalUrl:K,resolveUrl:l,isDefaultInjectionTarget:()=>!0});N.push(()=>R.teardown())}let _e=Et({emit:F,onBackground:()=>{if(S)Vt(S,w,Se(v,8));w.flush()}});N.push(()=>_e.teardown());let ue,re;if(S){let R=Tt(S,cr);ue=R.store,re=R.ready}else ue=ye(),re=Promise.resolve();let ie=()=>{if(E||B)return;let R=st({store:ue,windowStore:ye(),randomBytes:v});if(E=R,T.pendingReset)R.reset(),T.pendingReset=!1;let L=T.pendingIdentity;if(T.pendingIdentity=void 0,L)R.setDistinctId(L.distinctId),F(Yt(L.distinctId,L.traits));for(let V of I.splice(0))try{if(V.kind==="identify")R.setDistinctId(V.distinctId);else if(V.kind==="reset")R.reset();else U(V.event,R,V.screen)}catch{}if(S&&!Q)Qe(S,w)},me=(R)=>{let L=I.length;while(L>0&&I[L-1]?.kind!=="event")L-=1;let V=I.splice(L);if(R.kind==="reset"||V.some((x)=>x.kind==="reset"))I.push({kind:"reset"});if(R.kind==="identify")I.push(R)};T.instance={identify(R,L){j(()=>{if(E)E.setDistinctId(R);else me({kind:"identify",distinctId:R});return Yt(R,L)})},reset(){try{if(E)E.reset();else me({kind:"reset"})}catch{}},addEvent(R,L){j(()=>({type:"custom",body:`custom ${R}`,severity:"INFO",timeUnixMs:Date.now(),attributes:{"app.custom.name":R,...L?ge(L,"custom"):{}}}))},log(R,L,V){j(()=>({type:"log",body:L,severity:R,timeUnixMs:Date.now(),attributes:V?ge(V):{}}))},async flush(){await re,await w.flush()},async shutdown(){for(let R of N.reverse())try{R()}catch{}B=!0,p(),kt(),await re,await w.shutdown()}},re.then(ie,ie)},Xt=(d)=>{try{pr(d)}catch{}},ao=(d)=>{if(s()){if(!T.warnedWebHost)T.warnedWebHost=!0,console.warn(`${de} this app is running in a browser; use @sazabi/browser instead. SDK disabled.`);return}if(T.initialized)return;T.initialized=!0,T.generation+=1;let m=T.generation;if(!d.serviceName||!Pe(d)){console.warn(`${de} init() requires intakeUrl and serviceName; SDK disabled. Pass publicKey too if the intake URL is a proxy that carries no key.`);return}if(d.consent===void 0){Xt(d);return}try{Promise.resolve(d.consent()).then((g)=>{if(g===!0&&m===T.generation)Xt(d)}).catch(()=>{})}catch{}},co=(d,m)=>{if(T.instance)T.instance.identify(d,m);else T.pendingIdentity={distinctId:d,traits:m}},uo=()=>{if(T.instance)T.instance.reset();else T.pendingReset=!0,T.pendingIdentity=void 0},lo=(d,m)=>{T.instance?.addEvent(d,m)},po=(d,m,g)=>{T.instance?.log(d,m,g)},fo=async()=>{await T.instance?.flush()},mo=async()=>{let d=T.instance;T.instance=void 0,T.initialized=!1,T.generation+=1,T.pendingIdentity=void 0,T.pendingReset=!1,await d?.shutdown()};export{we as SDK_VERSION,bt as SazabiRoot,lo as addEvent,fo as flush,co as identify,ao as init,po as log,uo as reset,mo as shutdown,Zn as trackNavigation};
|
|
4
|
+
|
|
5
|
+
//# debugId=B9F1449F62B086F864756E2164756E21
|
|
6
|
+
//# sourceMappingURL=index.js.map
|