@heycatch/sdk 0.7.0 → 0.7.1-dev.1123

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.
@@ -113,15 +113,66 @@ interface ServerTrackOptions extends TrackOptions {
113
113
  */
114
114
  declare const STAGE: "dev" | "prod";
115
115
  declare const SDK_VERSION: string;
116
+ /** Stamped when the installer could not determine a value. */
117
+ declare const UNKNOWN_INSTALL_VALUE: "unknown";
116
118
  /**
117
- * Frameworks the install guides can detect. Kept as a type alias, not a
118
- * runtime array: `apps/landing-web/tests/agent-install-guides.spec.ts`
119
- * reads this source text and asserts the set matches the guides' tables,
120
- * so docs, types, and reported values cannot drift.
119
+ * One captured event, as {@link HeyCatchBeforeSend} sees it just before it
120
+ * is queued for sending.
121
+ *
122
+ * Declared structurally, listing only the fields the SDK can promise. The
123
+ * index signature carries the underlying transport's own extra keys through
124
+ * untouched, so nothing is lost and nothing here has to move when they
125
+ * change.
126
+ */
127
+ interface HeyCatchCapturedEvent {
128
+ /** Event name - an autocapture name like `$autocapture`, or your own. */
129
+ event: string;
130
+ /** The event's property bag, as it will be sent. */
131
+ properties: Record<string, unknown>;
132
+ [key: string]: unknown;
133
+ }
134
+ /**
135
+ * Runs on every event right before it is queued. Return the event to keep
136
+ * it (mutated or not), or `null` to drop it.
137
+ *
138
+ * The SDK never calls this itself and never reads its return value - it
139
+ * forwards the function to the transport, whose own code calls it.
140
+ */
141
+ type HeyCatchBeforeSend = (event: HeyCatchCapturedEvent | null) => HeyCatchCapturedEvent | null;
142
+ /** The transport's older, deprecated hook. Prefer {@link HeyCatchBeforeSend}. */
143
+ type HeyCatchSanitizeProperties = (properties: Record<string, unknown>, eventName: string) => Record<string, unknown>;
144
+ /** Where the SDK may persist the distinct id and super properties. */
145
+ type HeyCatchPersistence = 'localStorage' | 'cookie' | 'memory' | 'localStorage+cookie' | 'sessionStorage';
146
+ /**
147
+ * Frameworks the install guides can detect. **Written out as a union, not
148
+ * derived from the array below**, because
149
+ * `apps/landing-web/tests/agent-install-guides.spec.ts` matches this
150
+ * declaration as source text to assert the set agrees with the guide's
151
+ * detection table. Collapsing it to `(typeof …)[number]` leaves that guard
152
+ * matching nothing.
153
+ *
154
+ * For the same reason, do not restate the declaration's opening line anywhere
155
+ * above it - including in a comment. The guard takes the FIRST match in the
156
+ * file, so a prose copy of it wins and yields zero ids. (Written here after
157
+ * doing exactly that; the spec's vacuity check is what caught it.)
121
158
  */
122
159
  type KnownFramework = 'nextjs' | 'vite-react' | 'react' | 'vue' | 'svelte' | 'astro' | 'angular' | 'react-native' | 'web';
123
160
  /** Coding agents that run the install. `other` is the catch-all. */
124
161
  type KnownInstallAgent = 'lovable' | 'bolt' | 'v0' | 'replit' | 'cursor' | 'claude-code' | 'codex' | 'windsurf' | 'other';
162
+ /**
163
+ * The same two sets at RUNTIME, for code that has to ask "is this reported
164
+ * value one we recognise?" - a question a type union cannot answer, because
165
+ * `install.framework` is deliberately `KnownFramework | (string & {})` so an
166
+ * unlisted framework still installs cleanly.
167
+ *
168
+ * The consumer is the internal stats page, which flags an unrecognised or
169
+ * missing value rather than silently rendering it as though it were expected.
170
+ *
171
+ * Drift between each array and its union is a **compile error** (see the
172
+ * assertions below), so this is a second spelling, not a second source.
173
+ */
174
+ declare const KNOWN_FRAMEWORKS: readonly ["nextjs", "vite-react", "react", "vue", "svelte", "astro", "angular", "react-native", "web"];
175
+ declare const KNOWN_INSTALL_AGENTS: readonly ["lovable", "bolt", "v0", "replit", "cursor", "claude-code", "codex", "windsurf", "other"];
125
176
  /**
126
177
  * Who installed the SDK and into what. Stamped as super-properties on
127
178
  * every event - the dashboard reads them off the event stream, so there
@@ -152,6 +203,66 @@ interface HeyCatchConfig {
152
203
  * are covered automatically - omit this unless the API lives elsewhere.
153
204
  */
154
205
  tracingHosts?: string[];
206
+ /**
207
+ * Turn off autocapture (clicks and form submissions). Pageviews,
208
+ * page-leaves, and rage-clicks are captured separately and are NOT
209
+ * affected by this one. Costs the recap's friction signals - the web
210
+ * entry logs this once at `init()` so the tradeoff isn't silent.
211
+ */
212
+ autocapture?: boolean;
213
+ /**
214
+ * Strip autocaptured elements' text content. Costs the recap's friction
215
+ * labels - logged once at `init()`.
216
+ */
217
+ maskAllText?: boolean;
218
+ /**
219
+ * Strip autocaptured elements' attributes. Costs debugging context on
220
+ * autocaptured events - logged once at `init()`.
221
+ */
222
+ maskAllElementAttributes?: boolean;
223
+ /**
224
+ * Property keys to drop from every captured event. HeyCatch's own
225
+ * `heycatch_*` attribution keys cannot be denylisted - they are what
226
+ * attributes an event to your project, so they are filtered back out
227
+ * (and named in the console) rather than silently honoured.
228
+ */
229
+ propertyDenylist?: string[];
230
+ /** @deprecated Superseded by {@link HeyCatchConfig.beforeSend}. */
231
+ sanitizeProperties?: HeyCatchSanitizeProperties;
232
+ /** Runs on every event right before it is queued; return `null` to drop it. */
233
+ beforeSend?: HeyCatchBeforeSend | HeyCatchBeforeSend[];
234
+ /** Where the SDK persists the distinct id and super properties. */
235
+ persistence?: HeyCatchPersistence;
236
+ /** Disable persistence entirely - every pageload starts a new anonymous person. */
237
+ disablePersistence?: boolean;
238
+ /** Days before the persistence cookie expires. Defaults to 365. */
239
+ cookieExpirationDays?: number;
240
+ /**
241
+ * Start with capturing off until the app calls
242
+ * `analytics.optInCapturing()` - a proper consent gate instead of the
243
+ * "don't call init" workaround. Browser storage is held off too, not
244
+ * just sending, so no distinct id is written before consent.
245
+ */
246
+ optOutCapturingByDefault?: boolean;
247
+ /** Honor the browser's Do Not Track signal. */
248
+ respectDnt?: boolean;
249
+ /**
250
+ * Batch captured events for a few seconds before sending (the default).
251
+ * Set `false` on a multi-page site - one where each click is a full page
252
+ * load - because a visitor who navigates away inside the batch window
253
+ * takes the batch with them; iOS Safari in particular does not reliably
254
+ * let the unload send through. A single-page app can leave it unset.
255
+ * Browser only.
256
+ */
257
+ requestBatching?: boolean;
258
+ /**
259
+ * How long captured events wait for a batch, in milliseconds. Defaults to
260
+ * 3000; the accepted range is 250-5000, and a value outside it falls back
261
+ * to the default with a console warning. The gentler alternative to
262
+ * `requestBatching: false` when you want to keep batching but shrink the
263
+ * window. Browser only.
264
+ */
265
+ flushIntervalMs?: number;
155
266
  }
156
267
 
157
- export { type HeyCatchConfig as H, type PersonPropertyUpdate as P, SDK_VERSION as S, type TrackOptions as T, type HeyCatchPersonProperties as a, type HeyCatchProperties as b, STAGE as c, type ServerTrackOptions as d };
268
+ export { type HeyCatchBeforeSend as H, KNOWN_FRAMEWORKS as K, type PersonPropertyUpdate as P, SDK_VERSION as S, type TrackOptions as T, UNKNOWN_INSTALL_VALUE as U, type HeyCatchCapturedEvent as a, type HeyCatchConfig as b, type HeyCatchPersistence as c, type HeyCatchPersonProperties as d, type HeyCatchProperties as e, type HeyCatchSanitizeProperties as f, KNOWN_INSTALL_AGENTS as g, STAGE as h, type ServerTrackOptions as i };
@@ -113,15 +113,66 @@ interface ServerTrackOptions extends TrackOptions {
113
113
  */
114
114
  declare const STAGE: "dev" | "prod";
115
115
  declare const SDK_VERSION: string;
116
+ /** Stamped when the installer could not determine a value. */
117
+ declare const UNKNOWN_INSTALL_VALUE: "unknown";
116
118
  /**
117
- * Frameworks the install guides can detect. Kept as a type alias, not a
118
- * runtime array: `apps/landing-web/tests/agent-install-guides.spec.ts`
119
- * reads this source text and asserts the set matches the guides' tables,
120
- * so docs, types, and reported values cannot drift.
119
+ * One captured event, as {@link HeyCatchBeforeSend} sees it just before it
120
+ * is queued for sending.
121
+ *
122
+ * Declared structurally, listing only the fields the SDK can promise. The
123
+ * index signature carries the underlying transport's own extra keys through
124
+ * untouched, so nothing is lost and nothing here has to move when they
125
+ * change.
126
+ */
127
+ interface HeyCatchCapturedEvent {
128
+ /** Event name - an autocapture name like `$autocapture`, or your own. */
129
+ event: string;
130
+ /** The event's property bag, as it will be sent. */
131
+ properties: Record<string, unknown>;
132
+ [key: string]: unknown;
133
+ }
134
+ /**
135
+ * Runs on every event right before it is queued. Return the event to keep
136
+ * it (mutated or not), or `null` to drop it.
137
+ *
138
+ * The SDK never calls this itself and never reads its return value - it
139
+ * forwards the function to the transport, whose own code calls it.
140
+ */
141
+ type HeyCatchBeforeSend = (event: HeyCatchCapturedEvent | null) => HeyCatchCapturedEvent | null;
142
+ /** The transport's older, deprecated hook. Prefer {@link HeyCatchBeforeSend}. */
143
+ type HeyCatchSanitizeProperties = (properties: Record<string, unknown>, eventName: string) => Record<string, unknown>;
144
+ /** Where the SDK may persist the distinct id and super properties. */
145
+ type HeyCatchPersistence = 'localStorage' | 'cookie' | 'memory' | 'localStorage+cookie' | 'sessionStorage';
146
+ /**
147
+ * Frameworks the install guides can detect. **Written out as a union, not
148
+ * derived from the array below**, because
149
+ * `apps/landing-web/tests/agent-install-guides.spec.ts` matches this
150
+ * declaration as source text to assert the set agrees with the guide's
151
+ * detection table. Collapsing it to `(typeof …)[number]` leaves that guard
152
+ * matching nothing.
153
+ *
154
+ * For the same reason, do not restate the declaration's opening line anywhere
155
+ * above it - including in a comment. The guard takes the FIRST match in the
156
+ * file, so a prose copy of it wins and yields zero ids. (Written here after
157
+ * doing exactly that; the spec's vacuity check is what caught it.)
121
158
  */
122
159
  type KnownFramework = 'nextjs' | 'vite-react' | 'react' | 'vue' | 'svelte' | 'astro' | 'angular' | 'react-native' | 'web';
123
160
  /** Coding agents that run the install. `other` is the catch-all. */
124
161
  type KnownInstallAgent = 'lovable' | 'bolt' | 'v0' | 'replit' | 'cursor' | 'claude-code' | 'codex' | 'windsurf' | 'other';
162
+ /**
163
+ * The same two sets at RUNTIME, for code that has to ask "is this reported
164
+ * value one we recognise?" - a question a type union cannot answer, because
165
+ * `install.framework` is deliberately `KnownFramework | (string & {})` so an
166
+ * unlisted framework still installs cleanly.
167
+ *
168
+ * The consumer is the internal stats page, which flags an unrecognised or
169
+ * missing value rather than silently rendering it as though it were expected.
170
+ *
171
+ * Drift between each array and its union is a **compile error** (see the
172
+ * assertions below), so this is a second spelling, not a second source.
173
+ */
174
+ declare const KNOWN_FRAMEWORKS: readonly ["nextjs", "vite-react", "react", "vue", "svelte", "astro", "angular", "react-native", "web"];
175
+ declare const KNOWN_INSTALL_AGENTS: readonly ["lovable", "bolt", "v0", "replit", "cursor", "claude-code", "codex", "windsurf", "other"];
125
176
  /**
126
177
  * Who installed the SDK and into what. Stamped as super-properties on
127
178
  * every event - the dashboard reads them off the event stream, so there
@@ -152,6 +203,66 @@ interface HeyCatchConfig {
152
203
  * are covered automatically - omit this unless the API lives elsewhere.
153
204
  */
154
205
  tracingHosts?: string[];
206
+ /**
207
+ * Turn off autocapture (clicks and form submissions). Pageviews,
208
+ * page-leaves, and rage-clicks are captured separately and are NOT
209
+ * affected by this one. Costs the recap's friction signals - the web
210
+ * entry logs this once at `init()` so the tradeoff isn't silent.
211
+ */
212
+ autocapture?: boolean;
213
+ /**
214
+ * Strip autocaptured elements' text content. Costs the recap's friction
215
+ * labels - logged once at `init()`.
216
+ */
217
+ maskAllText?: boolean;
218
+ /**
219
+ * Strip autocaptured elements' attributes. Costs debugging context on
220
+ * autocaptured events - logged once at `init()`.
221
+ */
222
+ maskAllElementAttributes?: boolean;
223
+ /**
224
+ * Property keys to drop from every captured event. HeyCatch's own
225
+ * `heycatch_*` attribution keys cannot be denylisted - they are what
226
+ * attributes an event to your project, so they are filtered back out
227
+ * (and named in the console) rather than silently honoured.
228
+ */
229
+ propertyDenylist?: string[];
230
+ /** @deprecated Superseded by {@link HeyCatchConfig.beforeSend}. */
231
+ sanitizeProperties?: HeyCatchSanitizeProperties;
232
+ /** Runs on every event right before it is queued; return `null` to drop it. */
233
+ beforeSend?: HeyCatchBeforeSend | HeyCatchBeforeSend[];
234
+ /** Where the SDK persists the distinct id and super properties. */
235
+ persistence?: HeyCatchPersistence;
236
+ /** Disable persistence entirely - every pageload starts a new anonymous person. */
237
+ disablePersistence?: boolean;
238
+ /** Days before the persistence cookie expires. Defaults to 365. */
239
+ cookieExpirationDays?: number;
240
+ /**
241
+ * Start with capturing off until the app calls
242
+ * `analytics.optInCapturing()` - a proper consent gate instead of the
243
+ * "don't call init" workaround. Browser storage is held off too, not
244
+ * just sending, so no distinct id is written before consent.
245
+ */
246
+ optOutCapturingByDefault?: boolean;
247
+ /** Honor the browser's Do Not Track signal. */
248
+ respectDnt?: boolean;
249
+ /**
250
+ * Batch captured events for a few seconds before sending (the default).
251
+ * Set `false` on a multi-page site - one where each click is a full page
252
+ * load - because a visitor who navigates away inside the batch window
253
+ * takes the batch with them; iOS Safari in particular does not reliably
254
+ * let the unload send through. A single-page app can leave it unset.
255
+ * Browser only.
256
+ */
257
+ requestBatching?: boolean;
258
+ /**
259
+ * How long captured events wait for a batch, in milliseconds. Defaults to
260
+ * 3000; the accepted range is 250-5000, and a value outside it falls back
261
+ * to the default with a console warning. The gentler alternative to
262
+ * `requestBatching: false` when you want to keep batching but shrink the
263
+ * window. Browser only.
264
+ */
265
+ flushIntervalMs?: number;
155
266
  }
156
267
 
157
- export { type HeyCatchConfig as H, type PersonPropertyUpdate as P, SDK_VERSION as S, type TrackOptions as T, type HeyCatchPersonProperties as a, type HeyCatchProperties as b, STAGE as c, type ServerTrackOptions as d };
268
+ export { type HeyCatchBeforeSend as H, KNOWN_FRAMEWORKS as K, type PersonPropertyUpdate as P, SDK_VERSION as S, type TrackOptions as T, UNKNOWN_INSTALL_VALUE as U, type HeyCatchCapturedEvent as a, type HeyCatchConfig as b, type HeyCatchPersistence as c, type HeyCatchPersonProperties as d, type HeyCatchProperties as e, type HeyCatchSanitizeProperties as f, KNOWN_INSTALL_AGENTS as g, STAGE as h, type ServerTrackOptions as i };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@heycatch/sdk",
3
- "version": "0.7.0",
3
+ "version": "0.7.1-dev.1123",
4
4
  "description": "HeyCatch SDK",
5
5
  "keywords": [
6
6
  "analytics",
@@ -82,6 +82,9 @@
82
82
  "optional": true
83
83
  }
84
84
  },
85
+ "engines": {
86
+ "node": ">=22"
87
+ },
85
88
  "publishConfig": {
86
89
  "access": "public",
87
90
  "registry": "https://registry.npmjs.org/"