@heycatch/sdk 0.8.0 → 0.8.2-dev.1657

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@heycatch/sdk",
3
- "version": "0.8.0",
3
+ "version": "0.8.2-dev.1657",
4
4
  "description": "HeyCatch SDK",
5
5
  "keywords": [
6
6
  "analytics",
@@ -24,9 +24,8 @@
24
24
  "exports": {
25
25
  ".": {
26
26
  "react-native": {
27
- "types": "./dist/react-native.d.ts",
28
- "import": "./dist/react-native.js",
29
- "require": "./dist/react-native.cjs"
27
+ "types": "./dist/react-native.d.cts",
28
+ "default": "./dist/react-native.cjs"
30
29
  },
31
30
  "browser": {
32
31
  "types": "./dist/index.d.ts",
@@ -50,9 +49,8 @@
50
49
  "require": "./dist/server.cjs"
51
50
  },
52
51
  "./react-native": {
53
- "types": "./dist/react-native.d.ts",
54
- "import": "./dist/react-native.js",
55
- "require": "./dist/react-native.cjs"
52
+ "types": "./dist/react-native.d.cts",
53
+ "default": "./dist/react-native.cjs"
56
54
  }
57
55
  },
58
56
  "main": "./dist/index.cjs",
@@ -1,110 +0,0 @@
1
- import { d as HeyCatchPersonProperties, b as HeyCatchConfig, e as HeyCatchProperties, j as TrackOptions } from './shared-C0-GQTbz.js';
2
- export { H as HeyCatchBeforeSend, a as HeyCatchCapturedEvent, c as HeyCatchPersistence, f as HeyCatchSanitizeProperties, P as PersonPropertyUpdate, S as SDK_VERSION, h as STAGE, i as ServerTrackOptions } from './shared-C0-GQTbz.js';
3
- import { ReactNode } from 'react';
4
-
5
- /**
6
- * The consent pair on native, where it is a REAL gate, not a no-op: the
7
- * native transport has its own persisted opt-out, and `init()` wires
8
- * `optOutCapturingByDefault` to it. A native app under GDPR needs a consent
9
- * banner exactly as much as a web app does.
10
- *
11
- * Synchronous, matching the web spelling, so one signature serves shared
12
- * code. Nothing awaits the write - the transport queues captures behind its
13
- * own storage load - but a failure is reported rather than dropped.
14
- *
15
- * No-op before `init()`.
16
- */
17
- declare function optInCapturing(): void;
18
- /** The withdraw half. No-op before `init()`. */
19
- declare function optOutCapturing(): void;
20
-
21
- /**
22
- * Link the device's anonymous visitor to the authenticated user. Same
23
- * contract as the web entry: a stable internal user id - never an email or
24
- * a session token - with email/name in the PROPERTIES. No-op before
25
- * `init()`, mirroring the web entry.
26
- */
27
- declare function setIdentity(userId: string, properties?: HeyCatchPersonProperties, propertiesOnce?: HeyCatchPersonProperties): void;
28
- /**
29
- * Clear the current identity. Call on sign-out so the next user on this
30
- * device starts anonymous.
31
- */
32
- declare function resetIdentity(): void;
33
-
34
- declare function init(config: HeyCatchConfig): void;
35
-
36
- /**
37
- * Record a screen view. `HeyCatchProvider` calls this automatically on
38
- * Expo Router route changes; call it manually only on a non-Expo-Router
39
- * navigator (pass the current route name from your navigation container).
40
- *
41
- * Manual by design: the transport's own screen autocapture is broken on
42
- * React Navigation v7 (what current Expo Router runs on) - its hooks may
43
- * not run above the navigator, which is exactly where a provider sits.
44
- */
45
- declare function trackScreen(name: string, properties?: HeyCatchProperties): void;
46
-
47
- /**
48
- * Record a product event. Touch autocapture (via `HeyCatchProvider`) and
49
- * lifecycle events cover behaviour - this is for the moments only the app
50
- * knows about. Same validation contract as the web entry; `userId` in the
51
- * options is ignored here, the device session already knows who.
52
- */
53
- declare function trackEvent(event: string, properties?: HeyCatchProperties, options?: TrackOptions): void;
54
- /**
55
- * Update the current person's properties without sending a product event -
56
- * same surface as the web entry. The `$set` event is the transport's
57
- * person-update carrier; it is a built-in, not a custom event, so no
58
- * `heycatch_custom_user_event` stamp.
59
- */
60
- declare function setPersonProperties(set?: HeyCatchPersonProperties, setOnce?: HeyCatchPersonProperties): void;
61
-
62
- /**
63
- * Mount once in the root layout (`app/_layout.tsx`), wrapping the layout's
64
- * children. It adds the two things `init` alone cannot: touch autocapture
65
- * (the transport hooks touches via a root View, so a component is
66
- * structurally required) and automatic screen views on Expo Router.
67
- * Everything else - lifecycle events, identity, business events - works
68
- * from `init` alone.
69
- */
70
- declare function HeyCatchProvider({ children, }: {
71
- children: ReactNode;
72
- }): ReactNode;
73
-
74
- /**
75
- * The React Native entry. The `react-native` export condition routes a
76
- * bare `@heycatch/sdk` import here under Metro (newest Expo enables
77
- * package exports with that condition), so the customer API stays ONE
78
- * surface across web, server, and native.
79
- *
80
- * Wraps posthog-react-native - a regular dependency, deliberately NOT
81
- * bundled: bundling breaks its optional-Expo-peer probing. Not a peer
82
- * either: a peer would force the agent guide to name the vendor in its
83
- * install line (the vendor-ban spec forbids exactly that); the dependency
84
- * resolves silently instead. The Expo companions are app-level installs
85
- * the guide's RN line carries (`expo-file-system` above all - without it
86
- * persistence silently falls back to memory and every launch becomes a
87
- * new anonymous person).
88
- *
89
- * Flags, surveys, replay, and error tracking are never fetched or enabled.
90
- * Native-only additions to the namespace: `trackScreen`, plus the
91
- * `HeyCatchProvider` component for touch autocapture + Expo Router screen
92
- * views.
93
- */
94
-
95
- /**
96
- * The same-shaped `analytics` namespace as the web and server entries,
97
- * plus the native-only `trackScreen`.
98
- */
99
- declare const analytics: {
100
- readonly init: typeof init;
101
- readonly optInCapturing: typeof optInCapturing;
102
- readonly optOutCapturing: typeof optOutCapturing;
103
- readonly resetIdentity: typeof resetIdentity;
104
- readonly setIdentity: typeof setIdentity;
105
- readonly setPersonProperties: typeof setPersonProperties;
106
- readonly trackEvent: typeof trackEvent;
107
- readonly trackScreen: typeof trackScreen;
108
- };
109
-
110
- export { HeyCatchConfig, HeyCatchPersonProperties, HeyCatchProperties, HeyCatchProvider, TrackOptions, analytics };
@@ -1,2 +0,0 @@
1
- var oe=(e=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(e,{get:(t,r)=>(typeof require<"u"?require:t)[r]}):e)(function(e){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+e+'" is not supported')});var ze="project",Zt="[a-z0-9]",zr=new RegExp(`^${Zt}$`);var Pt=/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/;function ie(e){let t=Pt.exec(e);if(t===null)return!1;let[,r="",n=""]=t,o=Number(r),s=Number(n);return o>255||s>255?!1:o===0||o===10||o===127||o===100&&s>=64&&s<=127||o===169&&s===254||o===172&&s>=16&&s<=31||o===192&&s===168}var Et=/^::ffff:([0-9a-f]{1,4}):([0-9a-f]{1,4})$/;function Ct(e){if(e==="::1"||e==="::")return!0;if(e.startsWith("::ffff:")){let t=Et.exec(e);if(t===null)return ie(e.slice(7));let[,r="",n=""]=t,o=Number.parseInt(r,16),s=Number.parseInt(n,16);return ie(`${Math.floor(o/256)}.${o%256}.${Math.floor(s/256)}.${s%256}`)}return/^f[cd][0-9a-f]{2}:/.test(e)||/^fe[89ab][0-9a-f]:/.test(e)}function At(e){return e.toLowerCase().replace(/^\[/,"").replace(/\]$/,"").replace(/\.+$/,"")}function ye(e){let t=At(e);return t==="localhost"||t.endsWith(".localhost")||ie(t)||Ct(t)}import{PostHog as pr}from"posthog-react-native";var $e;function p(e,t,r){function n(c,u){if(c._zod||Object.defineProperty(c,"_zod",{value:{def:u,constr:i,traits:new Set},enumerable:!1}),c._zod.traits.has(e))return;c._zod.traits.add(e),t(c,u);let a=i.prototype,l=Object.keys(a);for(let h=0;h<l.length;h++){let d=l[h];d in c||(c[d]=a[d].bind(c))}}let o=r?.Parent??Object;class s extends o{}Object.defineProperty(s,"name",{value:e});function i(c){var u;let a=r?.Parent?new s:this;n(a,c),(u=a._zod).deferred??(u.deferred=[]);for(let l of a._zod.deferred)l();return a}return Object.defineProperty(i,"init",{value:n}),Object.defineProperty(i,Symbol.hasInstance,{value:c=>r?.Parent&&c instanceof r.Parent?!0:c?._zod?.traits?.has(e)}),Object.defineProperty(i,"name",{value:e}),i}var k=class extends Error{constructor(){super("Encountered Promise during synchronous parse. Use .parseAsync() instead.")}};($e=globalThis).__zod_globalConfig??($e.__zod_globalConfig={});var se=globalThis.__zod_globalConfig;function I(e){return e&&Object.assign(se,e),se}function we(e){let t=Object.values(e).filter(n=>typeof n=="number");return Object.entries(e).filter(([n,o])=>t.indexOf(+n)===-1).map(([n,o])=>o)}function ke(e,t){return typeof t=="bigint"?t.toString():t}function Ze(e){return{get value(){{let r=e();return Object.defineProperty(this,"value",{value:r}),r}throw new Error("cached value already set")}}}function Pe(e){let t=e.startsWith("^")?1:0,r=e.endsWith("$")?e.length-1:e.length;return e.slice(t,r)}var be=Symbol("evaluating");function P(e,t,r){let n;Object.defineProperty(e,t,{get(){if(n!==be)return n===void 0&&(n=be,n=r()),n},set(o){Object.defineProperty(e,t,{value:o})},configurable:!0})}var ue="captureStackTrace"in Error?Error.captureStackTrace:(...e)=>{};function Y(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function Ee(e){if(Y(e)===!1)return!1;let t=e.constructor;if(t===void 0||typeof t!="function")return!0;let r=t.prototype;return!(Y(r)===!1||Object.prototype.hasOwnProperty.call(r,"isPrototypeOf")===!1)}function ae(e){return Ee(e)?{...e}:Array.isArray(e)?[...e]:e instanceof Map?new Map(e):e instanceof Set?new Set(e):e}var Ce=new Set(["string","number","symbol"]);function Ae(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function pe(e,t,r){let n=new e._zod.constr(t??e._zod.def);return(!t||r?.parent)&&(n._zod.parent=e),n}function b(e){let t=e;if(!t)return{};if(typeof t=="string")return{error:()=>t};if(t?.message!==void 0){if(t?.error!==void 0)throw new Error("Cannot specify both `message` and `error` params");t.error=t.message}return delete t.message,typeof t.error=="string"?{...t,error:()=>t.error}:t}function Se(e){return Object.keys(e).filter(t=>e[t]._zod.optin==="optional"&&e[t]._zod.optout==="optional")}var $r={safeint:[Number.MIN_SAFE_INTEGER,Number.MAX_SAFE_INTEGER],int32:[-2147483648,2147483647],uint32:[0,4294967295],float32:[-34028234663852886e22,34028234663852886e22],float64:[-Number.MAX_VALUE,Number.MAX_VALUE]};function H(e,t=0){if(e.aborted===!0)return!0;for(let r=t;r<e.issues.length;r++)if(e.issues[r]?.continue!==!0)return!0;return!1}function Ie(e,t=0){if(e.aborted===!0)return!0;for(let r=t;r<e.issues.length;r++)if(e.issues[r]?.continue===!1)return!0;return!1}function le(e,t){return t.map(r=>{var n;return(n=r).path??(n.path=[]),r.path.unshift(e),r})}function J(e){return typeof e=="string"?e:e?.message}function T(e,t,r){let n=e.message?e.message:J(e.inst?._zod.def?.error?.(e))??J(t?.error?.(e))??J(r.customError?.(e))??J(r.localeError?.(e))??"Invalid input",{inst:o,continue:s,input:i,...c}=e;return c.path??(c.path=[]),c.message=n,t?.reportInput&&(c.input=i),c}function fe(...e){let[t,r,n]=e;return typeof t=="string"?{message:t,code:"custom",input:r,inst:n}:{...t}}var Te=(e,t)=>{e.name="$ZodError",Object.defineProperty(e,"_zod",{value:e._zod,enumerable:!1}),Object.defineProperty(e,"issues",{value:t,enumerable:!1}),e.message=JSON.stringify(t,ke,2),Object.defineProperty(e,"toString",{value:()=>e.message,enumerable:!1})},Me=p("$ZodError",Te),U=p("$ZodError",Te,{Parent:Error});var It=e=>(t,r,n,o)=>{let s=n?{...n,async:!1}:{async:!1},i=t._zod.run({value:r,issues:[]},s);if(i instanceof Promise)throw new k;if(i.issues.length){let c=new(o?.Err??e)(i.issues.map(u=>T(u,s,I())));throw ue(c,o?.callee),c}return i.value},q=It(U),Tt=e=>async(t,r,n,o)=>{let s=n?{...n,async:!0}:{async:!0},i=t._zod.run({value:r,issues:[]},s);if(i instanceof Promise&&(i=await i),i.issues.length){let c=new(o?.Err??e)(i.issues.map(u=>T(u,s,I())));throw ue(c,o?.callee),c}return i.value},X=Tt(U),Mt=e=>(t,r,n)=>{let o=n?{...n,async:!1}:{async:!1},s=t._zod.run({value:r,issues:[]},o);if(s instanceof Promise)throw new k;return s.issues.length?{success:!1,error:new(e??Me)(s.issues.map(i=>T(i,o,I())))}:{success:!0,data:s.value}},V=Mt(U),Rt=e=>async(t,r,n)=>{let o=n?{...n,async:!0}:{async:!0},s=t._zod.run({value:r,issues:[]},o);return s instanceof Promise&&(s=await s),s.issues.length?{success:!1,error:new e(s.issues.map(i=>T(i,o,I())))}:{success:!0,data:s.value}},B=Rt(U);var Nt="(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))",Ot=new RegExp(`^${Nt}$`);var Re=e=>{let t=e?`[\\s\\S]{${e?.minimum??0},${e?.maximum??""}}`:"[\\s\\S]*";return new RegExp(`^${t}$`)};var Ne=/^-?\d+(?:\.\d+)?$/,Oe=/^(?:true|false)$/i;var K=p("$ZodCheck",(e,t)=>{var r;e._zod??(e._zod={}),e._zod.def=t,(r=e._zod).onattach??(r.onattach=[])});var Le=p("$ZodCheckStringFormat",(e,t)=>{var r,n;K.init(e,t),e._zod.onattach.push(o=>{let s=o._zod.bag;s.format=t.format,t.pattern&&(s.patterns??(s.patterns=new Set),s.patterns.add(t.pattern))}),t.pattern?(r=e._zod).check??(r.check=o=>{t.pattern.lastIndex=0,!t.pattern.test(o.value)&&o.issues.push({origin:"string",code:"invalid_format",format:t.format,input:o.value,...t.pattern?{pattern:t.pattern.toString()}:{},inst:e,continue:!t.abort})}):(n=e._zod).check??(n.check=()=>{})}),De=p("$ZodCheckRegex",(e,t)=>{Le.init(e,t),e._zod.check=r=>{t.pattern.lastIndex=0,!t.pattern.test(r.value)&&r.issues.push({origin:"string",code:"invalid_format",format:"regex",input:r.value,pattern:t.pattern.toString(),inst:e,continue:!t.abort})}});var Fe={major:4,minor:4,patch:3};var $=p("$ZodType",(e,t)=>{var r;e??(e={}),e._zod.def=t,e._zod.bag=e._zod.bag||{},e._zod.version=Fe;let n=[...e._zod.def.checks??[]];e._zod.traits.has("$ZodCheck")&&n.unshift(e);for(let o of n)for(let s of o._zod.onattach)s(e);if(n.length===0)(r=e._zod).deferred??(r.deferred=[]),e._zod.deferred?.push(()=>{e._zod.run=e._zod.parse});else{let o=(i,c,u)=>{let a=H(i),l;for(let h of c){if(h._zod.def.when){if(Ie(i)||!h._zod.def.when(i))continue}else if(a)continue;let d=i.issues.length,g=h._zod.check(i);if(g instanceof Promise&&u?.async===!1)throw new k;if(l||g instanceof Promise)l=(l??Promise.resolve()).then(async()=>{await g,i.issues.length!==d&&(a||(a=H(i,d)))});else{if(i.issues.length===d)continue;a||(a=H(i,d))}}return l?l.then(()=>i):i},s=(i,c,u)=>{if(H(i))return i.aborted=!0,i;let a=o(c,n,u);if(a instanceof Promise){if(u.async===!1)throw new k;return a.then(l=>e._zod.parse(l,u))}return e._zod.parse(a,u)};e._zod.run=(i,c)=>{if(c.skipChecks)return e._zod.parse(i,c);if(c.direction==="backward"){let a=e._zod.parse({value:i.value,issues:[]},{...c,skipChecks:!0});return a instanceof Promise?a.then(l=>s(l,i,c)):s(a,i,c)}let u=e._zod.parse(i,c);if(u instanceof Promise){if(c.async===!1)throw new k;return u.then(a=>o(a,n,c))}return o(u,n,c)}}P(e,"~standard",()=>({validate:o=>{try{let s=V(e,o);return s.success?{value:s.data}:{issues:s.error?.issues}}catch{return B(e,o).then(i=>i.success?{value:i.data}:{issues:i.error?.issues})}},vendor:"zod",version:1}))}),Ge=p("$ZodString",(e,t)=>{$.init(e,t),e._zod.pattern=[...e?._zod.bag?.patterns??[]].pop()??Re(e._zod.bag),e._zod.parse=(r,n)=>{if(t.coerce)try{r.value=String(r.value)}catch{}return typeof r.value=="string"||r.issues.push({expected:"string",code:"invalid_type",input:r.value,inst:e}),r}});var We=p("$ZodNumber",(e,t)=>{$.init(e,t),e._zod.pattern=e._zod.bag.pattern??Ne,e._zod.parse=(r,n)=>{if(t.coerce)try{r.value=Number(r.value)}catch{}let o=r.value;if(typeof o=="number"&&!Number.isNaN(o)&&Number.isFinite(o))return r;let s=typeof o=="number"?Number.isNaN(o)?"NaN":Number.isFinite(o)?void 0:"Infinity":void 0;return r.issues.push({expected:"number",code:"invalid_type",input:o,inst:e,...s?{received:s}:{}}),r}});var Je=p("$ZodBoolean",(e,t)=>{$.init(e,t),e._zod.pattern=Oe,e._zod.parse=(r,n)=>{if(t.coerce)try{r.value=!!r.value}catch{}let o=r.value;return typeof o=="boolean"||r.issues.push({expected:"boolean",code:"invalid_type",input:o,inst:e}),r}});function Ue(e,t,r){e.issues.length&&t.issues.push(...le(r,e.issues)),t.value[r]=e.value}var Ye=p("$ZodArray",(e,t)=>{$.init(e,t),e._zod.parse=(r,n)=>{let o=r.value;if(!Array.isArray(o))return r.issues.push({expected:"array",code:"invalid_type",input:o,inst:e}),r;r.value=Array(o.length);let s=[];for(let i=0;i<o.length;i++){let c=o[i],u=t.element._zod.run({value:c,issues:[]},n);u instanceof Promise?s.push(u.then(a=>Ue(a,r,i))):Ue(u,r,i)}return s.length?Promise.all(s).then(()=>r):r}});function Q(e,t,r,n,o,s){let i=r in n;if(e.issues.length){if(o&&s&&!i)return;t.issues.push(...le(r,e.issues))}if(!i&&!o){e.issues.length||t.issues.push({code:"invalid_type",expected:"nonoptional",input:void 0,path:[r]});return}e.value===void 0?i&&(t.value[r]=void 0):t.value[r]=e.value}function jt(e){let t=Object.keys(e.shape);for(let n of t)if(!e.shape?.[n]?._zod?.traits?.has("$ZodType"))throw new Error(`Invalid element at key "${n}": expected a Zod schema`);let r=Se(e.shape);return{...e,keys:t,keySet:new Set(t),numKeys:t.length,optionalKeys:new Set(r)}}function Lt(e,t,r,n,o,s){let i=[],c=o.keySet,u=o.catchall._zod,a=u.def.type,l=u.optin==="optional",h=u.optout==="optional";for(let d in t){if(d==="__proto__"||c.has(d))continue;if(a==="never"){i.push(d);continue}let g=u.run({value:t[d],issues:[]},n);g instanceof Promise?e.push(g.then(v=>Q(v,r,d,t,l,h))):Q(g,r,d,t,l,h)}return i.length&&r.issues.push({code:"unrecognized_keys",keys:i,input:t,inst:s}),e.length?Promise.all(e).then(()=>r):r}var qe=p("$ZodObject",(e,t)=>{if($.init(e,t),!Object.getOwnPropertyDescriptor(t,"shape")?.get){let c=t.shape;Object.defineProperty(t,"shape",{get:()=>{let u={...c};return Object.defineProperty(t,"shape",{value:u}),u}})}let n=Ze(()=>jt(t));P(e._zod,"propValues",()=>{let c=t.shape,u={};for(let a in c){let l=c[a]._zod;if(l.values){u[a]??(u[a]=new Set);for(let h of l.values)u[a].add(h)}}return u});let o=Y,s=t.catchall,i;e._zod.parse=(c,u)=>{i??(i=n.value);let a=c.value;if(!o(a))return c.issues.push({expected:"object",code:"invalid_type",input:a,inst:e}),c;c.value={};let l=[],h=i.shape;for(let d of i.keys){let g=h[d],v=g._zod.optin==="optional",G=g._zod.optout==="optional",j=g._zod.run({value:a[d],issues:[]},u);j instanceof Promise?l.push(j.then(m=>Q(m,c,d,a,v,G))):Q(j,c,d,a,v,G)}return s?Lt(l,a,c,u,n.value,e):l.length?Promise.all(l).then(()=>c):c}});var Xe=p("$ZodEnum",(e,t)=>{$.init(e,t);let r=we(t.entries),n=new Set(r);e._zod.values=n,e._zod.pattern=new RegExp(`^(${r.filter(o=>Ce.has(typeof o)).map(o=>typeof o=="string"?Ae(o):o.toString()).join("|")})$`),e._zod.parse=(o,s)=>{let i=o.value;return n.has(i)||o.issues.push({code:"invalid_value",values:r,input:i,inst:e}),o}});function Ve(e,t){return t===void 0&&(e.issues.length||e.fallback)?{issues:[],value:void 0}:e}var Qe=p("$ZodOptional",(e,t)=>{$.init(e,t),e._zod.optin="optional",e._zod.optout="optional",P(e._zod,"values",()=>t.innerType._zod.values?new Set([...t.innerType._zod.values,void 0]):void 0),P(e._zod,"pattern",()=>{let r=t.innerType._zod.pattern;return r?new RegExp(`^(${Pe(r.source)})?$`):void 0}),e._zod.parse=(r,n)=>{if(t.innerType._zod.optin==="optional"){let o=r.value,s=t.innerType._zod.run(r,n);return s instanceof Promise?s.then(i=>Ve(i,o)):Ve(s,o)}return r.value===void 0?r:t.innerType._zod.run(r,n)}});var et=p("$ZodDefault",(e,t)=>{$.init(e,t),e._zod.optin="optional",P(e._zod,"values",()=>t.innerType._zod.values),e._zod.parse=(r,n)=>{if(n.direction==="backward")return t.innerType._zod.run(r,n);if(r.value===void 0)return r.value=t.defaultValue,r;let o=t.innerType._zod.run(r,n);return o instanceof Promise?o.then(s=>Be(s,t)):Be(o,t)}});function Be(e,t){return e.value===void 0&&(e.value=t.defaultValue),e}var tt=p("$ZodCustom",(e,t)=>{K.init(e,t),$.init(e,t),e._zod.parse=(r,n)=>r,e._zod.check=r=>{let n=r.value,o=t.fn(n);if(o instanceof Promise)return o.then(s=>Ke(s,r,n,e));Ke(o,r,n,e)}});function Ke(e,t,r,n){if(!e){let o={code:"custom",input:r,inst:n,path:[...n._zod.def.path??[]],continue:!n._zod.def.abort};n._zod.def.params&&(o.params=n._zod.def.params),t.issues.push(fe(o))}}function rt(e,t){return new e({type:"string",...b(t)})}function nt(e,t){return new e({type:"number",checks:[],...b(t)})}function ot(e,t){return new e({type:"boolean",...b(t)})}function de(e,t){return new De({check:"string_format",format:"regex",...b(t),pattern:e})}function it(e,t,r){let n=b(r);return n.abort??(n.abort=!0),new e({type:"custom",check:"custom",fn:t,...n})}var Z=p("ZodMiniType",(e,t)=>{if(!e._zod)throw new Error("Uninitialized schema in ZodMiniType.");$.init(e,t),e.def=t,e.type=t.type,e.parse=(r,n)=>q(e,r,n,{callee:e.parse}),e.safeParse=(r,n)=>V(e,r,n),e.parseAsync=async(r,n)=>X(e,r,n,{callee:e.parseAsync}),e.safeParseAsync=async(r,n)=>B(e,r,n),e.check=(...r)=>e.clone({...t,checks:[...t.checks??[],...r.map(n=>typeof n=="function"?{_zod:{check:n,def:{check:"custom"},onattach:[]}}:n)]},{parent:!0}),e.with=e.check,e.clone=(r,n)=>pe(e,r,n),e.brand=()=>e,e.register=((r,n)=>(r.add(e,n),e)),e.apply=r=>r(e)}),Ht=p("ZodMiniString",(e,t)=>{Ge.init(e,t),Z.init(e,t)});function A(e){return rt(Ht,e)}var Ft=p("ZodMiniNumber",(e,t)=>{We.init(e,t),Z.init(e,t)});function me(e){return nt(Ft,e)}var Ut=p("ZodMiniBoolean",(e,t)=>{Je.init(e,t),Z.init(e,t)});function E(e){return ot(Ut,e)}var Vt=p("ZodMiniArray",(e,t)=>{Ye.init(e,t),Z.init(e,t)});function he(e,t){return new Vt({type:"array",element:e,...b(t)})}var Bt=p("ZodMiniObject",(e,t)=>{qe.init(e,t),Z.init(e,t),P(e,"shape",()=>t.shape)});function _e(e,t){let r={type:"object",shape:e??{},...b(t)};return new Bt(r)}var Kt=p("ZodMiniEnum",(e,t)=>{Xe.init(e,t),Z.init(e,t),e.options=Object.values(t.entries)});function st(e,t){let r=Array.isArray(e)?Object.fromEntries(e.map(n=>[n,n])):e;return new Kt({type:"enum",entries:r,...b(t)})}var Gt=p("ZodMiniOptional",(e,t)=>{Qe.init(e,t),Z.init(e,t)});function x(e){return new Gt({type:"optional",innerType:e})}var Wt=p("ZodMiniDefault",(e,t)=>{et.init(e,t),Z.init(e,t)});function M(e,t){return new Wt({type:"default",innerType:e,get defaultValue(){return typeof t=="function"?t():ae(t)}})}var Jt=p("ZodMiniCustom",(e,t)=>{tt.init(e,t),Z.init(e,t)});function ge(e,t){return it(Jt,e??(()=>!0),t)}var ee="https://in.heycatch.ai",N="prod",O="0.8.0",ct="phc_oiDt6uXiBiEA2aT43SMzMAFE9D4gMVkRP3BtvYRsmHqe";function ut(e=N){return e!=="dev"?null:`[HeyCatch] WARNING: this is an internal development build (v${O}). Events are being sent to the HeyCatch development environment and will NEVER appear in your dashboard. Reinstall the latest stable version - resolve it with \`npm view @heycatch/sdk version\` - or re-run the install guide: https://heycatch.ai/agents.md`}var R="unknown",Qt=["localStorage","cookie","memory","localStorage+cookie","sessionStorage"];var at=_e({projectKey:A({error:'config.projectKey is missing or malformed \u2014 expected a string starting with "hck_pk_". Copy it from your project page in the HeyCatch dashboard.'}).check(de(/^hck_pk_/,{error:'config.projectKey is missing or malformed \u2014 expected a string starting with "hck_pk_". Copy it from your project page in the HeyCatch dashboard.'})),tracingHosts:M(he(A()),[]),install:M(_e({framework:M(A(),R),frameworkVersion:M(A(),R),agent:M(A(),R)}),{framework:R,frameworkVersion:R,agent:R}),autocapture:x(E()),maskAllText:x(E()),maskAllElementAttributes:x(E()),propertyDenylist:x(he(A())),sanitizeProperties:x(ge(e=>typeof e=="function")),beforeSend:x(ge(e=>typeof e=="function"||Array.isArray(e)&&e.every(t=>typeof t=="function"))),persistence:x(st(Qt)),disablePersistence:x(E()),cookieExpirationDays:x(me()),optOutCapturingByDefault:x(E()),respectDnt:x(E()),requestBatching:x(E()),flushIntervalMs:x(me())});var er=5e3,tr=60,rr=1e3,nr=60,or=new Set(["$set"]),xe="heycatch_volume_cap_reached",pt=3,ir=6e4;function te({bucket:e,perMinute:t,now:r}){if(e===void 0)return t;let n=Math.max(0,r-e.at);return Math.min(t,e.tokens+n*t/ir)}function sr(e){return e===void 0||e.length===0?!1:ye(cr(e))}function cr(e){if(e.startsWith("[")){let r=e.indexOf("]");return r===-1?e:e.slice(0,r+1)}let t=e.indexOf(":");return t!==-1&&t===e.lastIndexOf(":")?e.slice(0,t):e}function lt(e){let{$session_id:t,$host:r}=e.properties;return{sessionId:typeof t=="string"?t:"",host:typeof r=="string"?r:void 0}}var dt=4;function ft(e){if(e!==void 0)return typeof e=="object"&&e!==null&&"tokens"in e&&typeof e.tokens=="number"&&Number.isFinite(e.tokens)&&e.tokens>=0&&"at"in e&&typeof e.at=="number"&&Number.isFinite(e.at)?{tokens:e.tokens,at:e.at}:!1}function ur(e){if(typeof e=="object"&&e!==null&&"sessionId"in e&&typeof e.sessionId=="string"&&"count"in e&&typeof e.count=="number"&&Number.isInteger(e.count)&&e.count>=0&&"markerAttempts"in e&&typeof e.markerAttempts=="number"&&Number.isInteger(e.markerAttempts)&&e.markerAttempts>=0){let t=ft("person"in e?e.person:void 0),r=ft("localhost"in e?e.localhost:void 0);if(t!==!1&&r!==!1)return{sessionId:e.sessionId,count:e.count,markerAttempts:e.markerAttempts,person:t,localhost:r}}return null}function ar(e){if(e===null)return[];try{let t=JSON.parse(e);if(Array.isArray(t))return t.flatMap(r=>{let n=ur(r);return n===null?[]:[n]}).slice(0,dt)}catch{}return[]}function mt({store:e,warn:t,emitMarker:r,cap:n=er,personUpdateBudget:o=tr,localhostFreeEvents:s=rr,localhostRatePerMinute:i=nr,now:c=Date.now}){let u=[],a=!1,l=!1,h=!1,d=!1;function g(){if(e===void 0||a)return u;try{return ar(e.read())}catch{return u}}function v(m){let w=g().filter(f=>f.sessionId!==m.sessionId);u=[m,...w].slice(0,dt);try{e?.write(JSON.stringify(u))}catch{a=!0}}function G(m){let w=g().find(_=>_.sessionId===m),f=u.find(_=>_.sessionId===m),y=[w,f].filter(_=>_!==void 0),W=c();function L(_,D){let C;for(let{[_]:S}of y)S!==void 0&&te({bucket:S,perMinute:D,now:W})<te({bucket:C,perMinute:D,now:W})&&(C=S);return C}return{sessionId:m,count:Math.max(0,...y.map(_=>_.count)),markerAttempts:Math.max(0,...y.map(_=>_.markerAttempts)),person:L("person",o),localhost:L("localhost",i)}}function j(m,w){let f=w,y=c(),{sessionId:W,host:L}=lt(m);f.person!==void 0&&f.person.at>y&&(f={...f,person:{...f.person,at:y}},v(f)),f.localhost!==void 0&&f.localhost.at>y&&(f={...f,localhost:{...f.localhost,at:y}},v(f));let _=or.has(m.event),D=_?te({bucket:f.person,perMinute:o,now:y}):0;if(_&&D<1)return h||(h=!0,t(`[HeyCatch] setPersonProperties is being called more than ${o} times a minute - call it when a property changes, not on every render. Dropping the extra updates for now; other events are unaffected.`)),null;let C=f.count>=s&&sr(L),S=C?te({bucket:f.localhost,perMinute:i,now:y}):0;return C&&S<1?(d||(d=!0,t(`[HeyCatch] this local dev session (${L??"unknown host"}, session ${W||"unknown"}) sent ${s} events - throttling it to ${i} a minute so a dev loop cannot flood your analytics. Production traffic is unaffected.`)),null):(v({...f,count:f.count+1,..._?{person:{tokens:D-1,at:y}}:{},...C?{localhost:{tokens:S-1,at:y}}:{}}),m)}return m=>{if(m===null||m.event===xe)return m;let{sessionId:w}=lt(m),f=G(w);return f.count<n?j(m,f):(l||(l=!0,t(`[HeyCatch] this session sent ${n} events, the per-session cap - dropping the rest until a new session starts (session ${w||"unknown"}). A tracking call inside a render loop or an effect is the usual cause.`)),f.markerAttempts<pt&&(v({...f,markerAttempts:pt}),r({cap:n,sessionId:w})||v({...f,markerAttempts:f.markerAttempts+1})),null)}}function ht(e){let t=mt({warn:r=>{console.warn(r)},emitMarker:({cap:r})=>{let n=e();return n?.capture(xe,{heycatch_session_event_cap:r}),n!==null}});return r=>r===null||t({event:r.event,properties:r.properties??{}})===null?null:r}var re=null;function z(){return re}var ve=null;function _t(){ve?.()}function gt(e){if(re!==null)return;let t=at.safeParse(e);if(!t.success){let i=t.error.issues[0]?.message??"init() requires a config object with { projectKey }.";console.error(`[HeyCatch] ${i}`);return}let r=new pr(ct,{host:ee,preloadFeatureFlags:!1,disableRemoteFeatureFlags:!0,sendFeatureFlagEvent:!1,disableSurveys:!0,...t.data.optOutCapturingByDefault===void 0?{}:{defaultOptIn:!t.data.optOutCapturingByDefault},before_send:[ht(()=>re)]}),{install:n}=t.data,o={heycatch_framework:n.framework,heycatch_framework_version:n.frameworkVersion,heycatch_agent:n.agent};ve=()=>{r.register({heycatch_sdk_version:O,heycatch_sdk_stage:N,heycatch_project_key:t.data.projectKey,...o}),r.group(ze,t.data.projectKey,{key:t.data.projectKey,sdk_version:O,sdk_stage:N,framework:n.framework,framework_version:n.frameworkVersion,agent:n.agent,api_host:ee})},ve(),re=r,console.info(`[HeyCatch] SDK v${O} (${N}) initialized \u2192 ${ee}`);let s=ut();s!==null&&console.warn(s)}function xt(e){return t=>{console.error(`[HeyCatch] consent ${e} could not be saved - capture state may reset on the next app launch:`,t)}}function vt(){z()?.optIn().catch(xt("opt-in"))}function zt(){z()?.optOut().catch(xt("opt-out"))}function yt(e,t,r){let n=z();if(n!==null){if(typeof e!="string"||e.length===0){console.error("[HeyCatch] setIdentity() requires a non-empty string user id. Pass a stable internal user id from your auth provider \u2014 not an email or session token.");return}n.identify(e,{...t?{$set:t}:{},...r?{$set_once:r}:{}})}}function $t(){let e=z();e!==null&&(e.reset(),_t())}function ne(e,t){let r=z();if(r!==null){if(typeof e!="string"||e.length===0){console.error("[HeyCatch] trackScreen() requires a non-empty screen name.");return}r.screen(e,t?t:void 0)}}function bt(e,t,r){let n=z();if(n!==null){if(typeof e!="string"||e.length===0){console.error("[HeyCatch] trackEvent() requires a non-empty event name.");return}if(e.startsWith("$")){console.error(`[HeyCatch] trackEvent() event names cannot start with "$" (got "${e}") - that prefix is reserved for built-in events.`);return}n.capture(e,{...t,...r?.set?{$set:r.set}:{},...r?.setOnce?{$set_once:r.setOnce}:{},heycatch_custom_user_event:!0})}}function wt(e,t){let r=z();r!==null&&(!e&&!t||r.capture("$set",{...e?{$set:e}:{},...t?{$set_once:t}:{}}))}import{PostHogProvider as lr}from"posthog-react-native";import{useEffect as fr}from"react";import{jsx as gr,jsxs as xr}from"react/jsx-runtime";function dr(){try{if(typeof oe!="function")return null;let e=oe("expo-router");return typeof e=="object"&&e!==null&&"usePathname"in e&&typeof e.usePathname=="function"&&"useGlobalSearchParams"in e&&typeof e.useGlobalSearchParams=="function"?{usePathname:e.usePathname,useGlobalSearchParams:e.useGlobalSearchParams}:null}catch{return null}}var kt=dr();function mr(e){let t=JSON.parse(e);if(typeof t!="object"||t===null)return{};let r={};for(let[n,o]of Object.entries(t)){if(typeof o=="string"||typeof o=="number"||typeof o=="boolean"){r[n]=o;continue}Array.isArray(o)&&(r[n]=o.filter(s=>typeof s=="string").join(","))}return r}function hr({router:e}){let{useGlobalSearchParams:t,usePathname:r}=e,n=r(),o=JSON.stringify(t());return fr(()=>{ne(n,mr(o))},[n,o]),null}function _r({children:e}){let t=z();return t===null?(console.error("[HeyCatch] HeyCatchProvider mounted before init() - call analytics.init({ projectKey }) at module scope of the root layout."),e):xr(lr,{autocapture:{captureScreens:!1,captureTouches:!0},client:t,children:[kt===null?null:gr(hr,{router:kt}),e]})}var Ws={init:gt,optInCapturing:vt,optOutCapturing:zt,resetIdentity:$t,setIdentity:yt,setPersonProperties:wt,trackEvent:bt,trackScreen:ne};export{_r as HeyCatchProvider,O as SDK_VERSION,N as STAGE,Ws as analytics};
2
- //# sourceMappingURL=react-native.js.map