@minihog/core 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +9 -0
- package/LICENSE +21 -0
- package/LICENSE-RRWEB +21 -0
- package/README.md +182 -2
- package/dist/browser.d.ts +11 -0
- package/dist/browser.d.ts.map +1 -0
- package/dist/browser.js +272 -0
- package/dist/browser.js.map +1 -0
- package/dist/errors.d.ts +4 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +51 -0
- package/dist/errors.js.map +1 -0
- package/dist/flags.d.ts +17 -0
- package/dist/flags.d.ts.map +1 -0
- package/dist/flags.js +156 -0
- package/dist/flags.js.map +1 -0
- package/dist/heatmaps.d.ts +4 -0
- package/dist/heatmaps.d.ts.map +1 -0
- package/dist/heatmaps.js +189 -0
- package/dist/heatmaps.js.map +1 -0
- package/dist/identity.d.ts +7 -0
- package/dist/identity.d.ts.map +1 -0
- package/dist/identity.js +46 -0
- package/dist/identity.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +299 -0
- package/dist/index.js.map +1 -0
- package/dist/internal/state.d.ts +30 -0
- package/dist/internal/state.d.ts.map +1 -0
- package/dist/internal/state.js +59 -0
- package/dist/internal/state.js.map +1 -0
- package/dist/internal/transport.d.ts +21 -0
- package/dist/internal/transport.d.ts.map +1 -0
- package/dist/internal/transport.js +168 -0
- package/dist/internal/transport.js.map +1 -0
- package/dist/internal/version.d.ts +2 -0
- package/dist/internal/version.d.ts.map +1 -0
- package/dist/internal/version.js +3 -0
- package/dist/internal/version.js.map +1 -0
- package/dist/remote-config.d.ts +36 -0
- package/dist/remote-config.d.ts.map +1 -0
- package/dist/remote-config.js +33 -0
- package/dist/remote-config.js.map +1 -0
- package/dist/replay-console.d.ts +3 -0
- package/dist/replay-console.d.ts.map +1 -0
- package/dist/replay-console.js +3 -0
- package/dist/replay-console.js.map +1 -0
- package/dist/replay-network.d.ts +7 -0
- package/dist/replay-network.d.ts.map +1 -0
- package/dist/replay-network.js +43 -0
- package/dist/replay-network.js.map +1 -0
- package/dist/replay.d.ts +26 -0
- package/dist/replay.d.ts.map +1 -0
- package/dist/replay.js +3989 -0
- package/dist/replay.js.map +7 -0
- package/dist/surveys.d.ts +20 -0
- package/dist/surveys.d.ts.map +1 -0
- package/dist/surveys.js +39 -0
- package/dist/surveys.js.map +1 -0
- package/dist/types.d.ts +66 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/web-vitals.d.ts +4 -0
- package/dist/web-vitals.d.ts.map +1 -0
- package/dist/web-vitals.js +65 -0
- package/dist/web-vitals.js.map +1 -0
- package/package.json +124 -3
- package/src/browser.ts +284 -0
- package/src/errors.ts +51 -0
- package/src/flags.ts +166 -0
- package/src/heatmaps.ts +209 -0
- package/src/identity.ts +45 -0
- package/src/index.ts +302 -0
- package/src/internal/state.ts +90 -0
- package/src/internal/transport.ts +181 -0
- package/src/internal/version.ts +2 -0
- package/src/remote-config.ts +56 -0
- package/src/replay-console.ts +2 -0
- package/src/replay-network.ts +44 -0
- package/src/replay.ts +218 -0
- package/src/surveys.ts +55 -0
- package/src/types.ts +66 -0
- package/src/web-vitals.ts +65 -0
package/CHANGELOG.md
ADDED
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Stefan Popov
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/LICENSE-RRWEB
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2018 Contributors (https://github.com/rrweb-io/rrweb/graphs/contributors)
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,183 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @minihog/core
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A modular TypeScript client for PostHog's browser ingestion APIs. The event core imports no external runtime modules. Browser analytics, feature flags, surveys, errors, web vitals, heatmaps, and session replay have separate ESM entry points.
|
|
4
|
+
|
|
5
|
+
## Install and capture
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
pnpm add @minihog/core
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
import { createMiniHog } from '@minihog/core';
|
|
13
|
+
import { startBrowserCapture } from '@minihog/core/browser';
|
|
14
|
+
|
|
15
|
+
const analytics = createMiniHog('phc_public_project_token', {
|
|
16
|
+
apiHost: '/api/_ph',
|
|
17
|
+
personProfiles: 'identified_only'
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
startBrowserCapture(analytics);
|
|
21
|
+
analytics.capture('project_opened', { slug: 'example' });
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
Use a public project token. A relative host requires a server proxy; direct EU and US ingestion origins also work. Imports and construction do not send requests. Browser capture starts when its function is called.
|
|
25
|
+
|
|
26
|
+
The package ships ESM and TypeScript declarations. It declares `@rrweb/record`, `@rrweb/rrweb-plugin-console-record`, and `web-vitals` as required peers. If your package manager does not install peers automatically, add them explicitly. Only imported features enter your browser bundle.
|
|
27
|
+
|
|
28
|
+
## Client options
|
|
29
|
+
|
|
30
|
+
| Option | Default | Purpose |
|
|
31
|
+
| ------------------------------- | ---------------------------------- | ---------------------------------------------------------- |
|
|
32
|
+
| `apiHost` | `https://us.i.posthog.com` | Ingestion origin or same-origin proxy path |
|
|
33
|
+
| `persistence` | `localStorage` | Use `memory` for ephemeral identity and consent |
|
|
34
|
+
| `storage`, `persistenceKey` | Browser storage, `minihog_<token>` | Supply a storage adapter or isolate clients |
|
|
35
|
+
| `migratePostHog` | `true` | Read standard existing PostHog identity and consent |
|
|
36
|
+
| `personProfiles` | `identified_only` | Choose `always`, `identified_only`, or `never` |
|
|
37
|
+
| `optOutByDefault`, `respectDnt` | `false` | Start opted out or honor Do Not Track |
|
|
38
|
+
| `sessionTimeoutMs` | `1800000` | Idle-session timeout, with a one-minute minimum |
|
|
39
|
+
| `flushIntervalMs` | `3000` | Time before a queued batch is sent |
|
|
40
|
+
| `maxQueueBytes` | `2097152` | Maximum in-memory queue size; also limited to 1,000 events |
|
|
41
|
+
| `maxRetries` | `3` | Retry count for transient failures |
|
|
42
|
+
| `requestTimeoutMs` | `10000` | Timeout for ingestion, configuration, flags, and surveys |
|
|
43
|
+
| `fetch` | Global Fetch | Replace transport, including unload delivery |
|
|
44
|
+
| `beforeSend` | None | Return a redacted event or `null` to discard it |
|
|
45
|
+
| `onError` | None | Receive delivery and extension errors |
|
|
46
|
+
|
|
47
|
+
Options and events are typed through `MiniHogOptions`, `CaptureOptions`, and `CaptureEvent`. `capture` returns the accepted event or `undefined` when capture is suppressed. `flush` waits for the current delivery attempt; retryable failures remain queued.
|
|
48
|
+
|
|
49
|
+
## Entry points
|
|
50
|
+
|
|
51
|
+
| Import | Functions | Included when used |
|
|
52
|
+
| ----------------- | ------------------------------------------------------------------ | ------------------------------------------------------------------------------------------ |
|
|
53
|
+
| `@minihog/core` | `createMiniHog` | Events, queue, identity storage, sessions, consent |
|
|
54
|
+
| `/browser` | `startBrowserCapture` | Pageviews, pageleaves, SPA navigation, attribution, scroll depth, autocapture, rage clicks |
|
|
55
|
+
| `/identity` | `identify`, `setPersonProperties`, `alias`, `group`, `resetGroups` | Person and group event helpers |
|
|
56
|
+
| `/flags` | `createFeatureFlags` | Remote v2 evaluations, variants, payloads, exposure events |
|
|
57
|
+
| `/surveys` | `getSurveys`, `surveyShown`, `surveySent`, `surveyDismissed` | Headless definitions and response events |
|
|
58
|
+
| `/errors` | `captureException`, `startErrorCapture` | Manual errors and browser error listeners |
|
|
59
|
+
| `/heatmaps` | `startHeatmaps` | Click/movement points, rage clicks, dead clicks |
|
|
60
|
+
| `/web-vitals` | `startWebVitals` | Google's CLS/FCP/INP/LCP algorithms and INP/LCP attribution |
|
|
61
|
+
| `/replay` | `startSessionReplay` | DOM recordings with rrweb |
|
|
62
|
+
| `/replay-console` | `consoleRecordingPlugin` | rrweb console serialization |
|
|
63
|
+
| `/replay-network` | `networkTimingPlugin` | Resource/navigation timing observations |
|
|
64
|
+
| `/remote-config` | `getRemoteConfig` | JSON configuration retrieval |
|
|
65
|
+
|
|
66
|
+
`getRemoteConfig(client, assetsHost?)` reads JSON project settings. US and EU Cloud ingestion origins use their matching asset origins automatically. Custom and relative proxy hosts are preserved; self-hosted installations can pass a separate asset origin.
|
|
67
|
+
|
|
68
|
+
## Identity and groups
|
|
69
|
+
|
|
70
|
+
```ts
|
|
71
|
+
import { identify, group, setPersonProperties } from '@minihog/core/identity';
|
|
72
|
+
|
|
73
|
+
identify(analytics, 'account-123', { plan: 'pro' }, { signup_source: 'docs' });
|
|
74
|
+
group(analytics, 'organization', 'team-456', { name: 'Example' });
|
|
75
|
+
setPersonProperties(analytics, { locale: 'en' });
|
|
76
|
+
|
|
77
|
+
// On logout, clear identity, super properties, groups, and session state.
|
|
78
|
+
analytics.reset();
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
`identify` links the previous anonymous ID using `$anon_distinct_id`. Calling it again for an identified person does not merge two identified accounts. `personProfiles: 'never'` disables person updates.
|
|
82
|
+
|
|
83
|
+
By default, the client reads the standard `posthog-js` localStorage/cookie identity and its default localStorage consent key on first use. It carries over the distinct ID, device ID, identified state, and active session. Subsequent state uses `minihog_<token>`. Set `migratePostHog: false` to start fresh. Custom PostHog storage names, cookie-based consent, and custom consent prefixes need an application migration.
|
|
84
|
+
|
|
85
|
+
MiniHog persists to localStorage, with memory fallback when storage is blocked. It does not create cross-subdomain cookies. `persistence: 'memory'` avoids durable MiniHog state.
|
|
86
|
+
|
|
87
|
+
## Consent, delivery, and teardown
|
|
88
|
+
|
|
89
|
+
```ts
|
|
90
|
+
const analytics = createMiniHog('phc_public_project_token', {
|
|
91
|
+
apiHost: '/api/_ph',
|
|
92
|
+
optOutByDefault: true,
|
|
93
|
+
respectDnt: true
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
analytics.optIn();
|
|
97
|
+
analytics.optOut();
|
|
98
|
+
await analytics.flush();
|
|
99
|
+
await analytics.destroy();
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
Opt-out suppresses capture and clears queued events and durable MiniHog identity. Extensions check consent; replay stops recording. Opt-out changes propagate between tabs. An already delivered request cannot be recalled.
|
|
103
|
+
|
|
104
|
+
Events are serialized when captured and sent in batches. Failed network requests, HTTP 408, 429, and 5xx responses are retried up to `maxRetries`; other HTTP errors are dropped. Request IDs remain unchanged across retries. Queue overflow drops the oldest event and calls `onError` when supplied.
|
|
105
|
+
|
|
106
|
+
`visibilitychange` and `pagehide` flush pending events. Small requests use `sendBeacon`; other requests use Fetch. When a custom `fetch` is supplied, all delivery uses that function, including unload flushes. Delivery during tab/process termination remains best effort, especially for a full replay snapshot larger than the browser's keepalive limit. The queue is in memory, so it does not provide durable offline delivery.
|
|
107
|
+
|
|
108
|
+
Sessions expire after 30 minutes without activity and rotate after 24 hours. Replay and web-vitals events are passive and do not extend an idle session. `getSessionId()` reads the session; `touchSession()` marks user activity.
|
|
109
|
+
|
|
110
|
+
`register`, `registerOnce`, `unregister`, and `getProperty` manage super properties. `destroy()` removes listeners, stops replay, flushes pending events, and releases timers. Google's web-vitals observers have no unsubscribe API; their callbacks become inert after teardown.
|
|
111
|
+
|
|
112
|
+
## Feature flags and experiments
|
|
113
|
+
|
|
114
|
+
```ts
|
|
115
|
+
import { createFeatureFlags } from '@minihog/core/flags';
|
|
116
|
+
|
|
117
|
+
const flags = createFeatureFlags(analytics, {
|
|
118
|
+
personProperties: { plan: 'pro' },
|
|
119
|
+
evaluationContexts: ['production']
|
|
120
|
+
});
|
|
121
|
+
await flags.reload();
|
|
122
|
+
|
|
123
|
+
const variant = flags.getFeatureFlag('new-checkout');
|
|
124
|
+
const payload = flags.getFeatureFlagPayload('new-checkout');
|
|
125
|
+
analytics.capture('checkout_completed');
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
Unknown flags return `undefined`. Flag access records a deduplicated `$feature_flag_called` event. Evaluation results are attached to subsequent events using `$feature/<key>` and `$active_feature_flags`. Identity and group changes invalidate evaluations and trigger a reload; stale responses cannot overwrite newer results. Bootstrap values and `onFeatureFlags` subscriptions are supported. This client does not evaluate flag rules locally.
|
|
129
|
+
|
|
130
|
+
## Web vitals and replay
|
|
131
|
+
|
|
132
|
+
```ts
|
|
133
|
+
import { startWebVitals } from '@minihog/core/web-vitals';
|
|
134
|
+
import { startSessionReplay } from '@minihog/core/replay';
|
|
135
|
+
import { consoleRecordingPlugin } from '@minihog/core/replay-console';
|
|
136
|
+
import { networkTimingPlugin } from '@minihog/core/replay-network';
|
|
137
|
+
|
|
138
|
+
startWebVitals(analytics);
|
|
139
|
+
const replay = startSessionReplay(analytics, {
|
|
140
|
+
maskAllInputs: true,
|
|
141
|
+
plugins: [consoleRecordingPlugin(), networkTimingPlugin(analytics.apiHost)]
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
replay.stop();
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
Only one recorder can run in a document. Inputs are masked by default; `.ph-no-capture`, `.ph-sensitive`, and `[data-private]` elements are blocked. `maskTextSelector` can mask displayed text. Console output can contain application data and needs its own review. The network plugin records timings and URLs, never headers or bodies.
|
|
148
|
+
|
|
149
|
+
Snapshots omit scripts, script preload links, comments, and whitespace inside `<head>` by default, while retaining styles and visible content. Pass `slimDOMOptions: {}` to retain those nodes. Use recorder masking options for DOM privacy rules; `beforeSend` can also redact, replace, or drop replay events.
|
|
150
|
+
|
|
151
|
+
Canvas pixels are excluded by default; set `recordCanvas: true` when they are needed. Full DOM snapshots run synchronously, so larger documents and frequent mutations cost more to record. Replay supports per-session sampling, minimum duration, and idle suspension. Sampling reduces recorded sessions; a minimum duration reduces uploads but still records events while waiting.
|
|
152
|
+
|
|
153
|
+
### Delay loading replay
|
|
154
|
+
|
|
155
|
+
Use dynamic imports to defer downloading and evaluating the recorder until your application's critical content is ready:
|
|
156
|
+
|
|
157
|
+
```ts
|
|
158
|
+
async function startReplay(analytics: import('@minihog/core').MiniHog) {
|
|
159
|
+
const [{ startSessionReplay }, { consoleRecordingPlugin }, { networkTimingPlugin }] = await Promise.all([
|
|
160
|
+
import('@minihog/core/replay'),
|
|
161
|
+
import('@minihog/core/replay-console'),
|
|
162
|
+
import('@minihog/core/replay-network')
|
|
163
|
+
]);
|
|
164
|
+
|
|
165
|
+
return startSessionReplay(analytics, {
|
|
166
|
+
plugins: [consoleRecordingPlugin(), networkTimingPlugin(analytics.apiHost)]
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
Call `await startReplay(analytics)` once the application is ready and any required consent is granted. Replay starts at that point; earlier interactions are not recorded. Keep the returned controller and call `stop()` when recording is no longer needed. Nuxt applications can use the module's [manual startup](https://github.com/stefashkaa/minihog/tree/main/packages/nuxt#delay-initialization).
|
|
172
|
+
|
|
173
|
+
## Compatibility
|
|
174
|
+
|
|
175
|
+
MiniHog requires ES2022, Web Crypto, Fetch, and native DOM APIs. It adds no polyfills or remotely downloaded scripts. Its API uses separate imports and camelCase methods. Automatic survey rendering, product tours, conversations, the toolbar, and advanced remote recording triggers are not supported.
|
|
176
|
+
|
|
177
|
+
Replay uses PostHog's SDK snapshot ingestion format, which has a weaker compatibility guarantee than the documented capture and flags APIs. MiniHog supports DOM recording and console/network-timing diagnostics; it does not capture network payloads or implement every `posthog-js` replay control.
|
|
178
|
+
|
|
179
|
+
## Contributing
|
|
180
|
+
|
|
181
|
+
See [CONTRIBUTING.md](https://github.com/stefashkaa/minihog/blob/main/CONTRIBUTING.md) for development setup and checks. The Nuxt companion is [`@minihog/nuxt`](https://github.com/stefashkaa/minihog/tree/main/packages/nuxt#readme).
|
|
182
|
+
|
|
183
|
+
Protocol references: [capture and batch](https://posthog.com/docs/api/capture), [flags v2](https://posthog.com/docs/api/flags), [sessions](https://posthog.com/docs/data/sessions), [custom surveys](https://posthog.com/docs/surveys/implementing-custom-surveys), [web-vitals](https://github.com/GoogleChrome/web-vitals), [rrweb](https://github.com/rrweb-io/rrweb).
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Cleanup, MiniHog } from './types.js';
|
|
2
|
+
export interface BrowserOptions {
|
|
3
|
+
pageviews?: boolean;
|
|
4
|
+
autocapture?: boolean;
|
|
5
|
+
rageclick?: boolean;
|
|
6
|
+
/** Avoid recording visible text in products that display personal information. */
|
|
7
|
+
captureText?: boolean;
|
|
8
|
+
}
|
|
9
|
+
/** Installs page/session attribution and DOM analytics; returns complete teardown. */
|
|
10
|
+
export declare function startBrowserCapture(client: MiniHog, options?: BrowserOptions): Cleanup;
|
|
11
|
+
//# sourceMappingURL=browser.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"browser.d.ts","sourceRoot":"","sources":["../src/browser.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,OAAO,EAAc,MAAM,YAAY,CAAC;AAE/D,MAAM,WAAW,cAAc;IAC7B,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,kFAAkF;IAClF,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB;AA0GD,sFAAsF;AACtF,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,OAAO,EAAE,OAAO,GAAE,cAAmB,GAAG,OAAO,CAuK1F"}
|
package/dist/browser.js
ADDED
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
import { uuid } from './internal/state.js';
|
|
2
|
+
const privateSelector = '.ph-no-capture,.ph-sensitive,.nocapture,[data-ph-no-capture],[data-private]';
|
|
3
|
+
function browserProperties() {
|
|
4
|
+
const agent = navigator.userAgent;
|
|
5
|
+
const browser = /Edg\//.test(agent)
|
|
6
|
+
? 'Microsoft Edge'
|
|
7
|
+
: /Firefox\//.test(agent)
|
|
8
|
+
? 'Firefox'
|
|
9
|
+
: /Chrome\//.test(agent)
|
|
10
|
+
? 'Chrome'
|
|
11
|
+
: /Safari\//.test(agent)
|
|
12
|
+
? 'Safari'
|
|
13
|
+
: 'Other';
|
|
14
|
+
const version = agent.match(/(?:Edg|Firefox|Chrome|Version)\/(\d+)/)?.[1];
|
|
15
|
+
const os = /Android/.test(agent)
|
|
16
|
+
? 'Android'
|
|
17
|
+
: /iPhone|iPad/.test(agent)
|
|
18
|
+
? 'iOS'
|
|
19
|
+
: /Mac/.test(agent)
|
|
20
|
+
? 'Mac OS X'
|
|
21
|
+
: /Windows/.test(agent)
|
|
22
|
+
? 'Windows'
|
|
23
|
+
: /Linux/.test(agent)
|
|
24
|
+
? 'Linux'
|
|
25
|
+
: 'Other';
|
|
26
|
+
return {
|
|
27
|
+
$browser: browser,
|
|
28
|
+
$browser_version: Number(version ?? 0),
|
|
29
|
+
$os: os,
|
|
30
|
+
$device_type: /iPad|Tablet/.test(agent) ? 'Tablet' : /Mobi|iPhone|Android/.test(agent) ? 'Mobile' : 'Desktop',
|
|
31
|
+
$screen_height: screen.height,
|
|
32
|
+
$screen_width: screen.width,
|
|
33
|
+
$viewport_height: innerHeight,
|
|
34
|
+
$viewport_width: innerWidth,
|
|
35
|
+
$browser_language: navigator.language,
|
|
36
|
+
$timezone: Intl.DateTimeFormat().resolvedOptions().timeZone,
|
|
37
|
+
$is_internal_or_test_user: /^(localhost|127\.0\.0\.1)$/.test(location.hostname)
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
function referrerProperties() {
|
|
41
|
+
let domain = '$direct';
|
|
42
|
+
try {
|
|
43
|
+
if (document.referrer)
|
|
44
|
+
domain = new URL(document.referrer).hostname;
|
|
45
|
+
}
|
|
46
|
+
catch {
|
|
47
|
+
/* Referrers can be suppressed. */
|
|
48
|
+
}
|
|
49
|
+
return { $referrer: document.referrer || '$direct', $referring_domain: domain };
|
|
50
|
+
}
|
|
51
|
+
function elements(target, captureText) {
|
|
52
|
+
const chain = [];
|
|
53
|
+
let element = target;
|
|
54
|
+
while (element && chain.length < 10) {
|
|
55
|
+
const tag = element.tagName.toLowerCase();
|
|
56
|
+
let nthChild = 1;
|
|
57
|
+
let nthOfType = 1;
|
|
58
|
+
let sibling = element.previousElementSibling;
|
|
59
|
+
while (sibling) {
|
|
60
|
+
nthChild++;
|
|
61
|
+
if (sibling.tagName === element.tagName)
|
|
62
|
+
nthOfType++;
|
|
63
|
+
sibling = sibling.previousElementSibling;
|
|
64
|
+
}
|
|
65
|
+
const entry = { tag_name: tag, nth_child: nthChild, nth_of_type: nthOfType };
|
|
66
|
+
if (element.id)
|
|
67
|
+
entry.attr__id = element.id;
|
|
68
|
+
if (element.classList.length)
|
|
69
|
+
entry.attr__class = [...element.classList].join(' ');
|
|
70
|
+
if (element instanceof HTMLAnchorElement)
|
|
71
|
+
entry.attr__href = element.href;
|
|
72
|
+
if (captureText &&
|
|
73
|
+
/^(a|button|label|span)$/.test(tag) &&
|
|
74
|
+
!element.querySelector(`input,textarea,[contenteditable],${privateSelector}`)) {
|
|
75
|
+
const text = element.textContent?.trim().slice(0, 255);
|
|
76
|
+
// Keep obvious email addresses and long numeric identifiers out of autocapture.
|
|
77
|
+
if (text && !/@|\d{6,}/.test(text))
|
|
78
|
+
entry.$el_text = text;
|
|
79
|
+
}
|
|
80
|
+
chain.push(entry);
|
|
81
|
+
element = element.parentElement;
|
|
82
|
+
}
|
|
83
|
+
return chain;
|
|
84
|
+
}
|
|
85
|
+
function elementsChain(chain) {
|
|
86
|
+
const quote = (value) => String(value).replaceAll('"', '\\"');
|
|
87
|
+
return chain
|
|
88
|
+
.map((element) => {
|
|
89
|
+
const classes = String(element.attr__class ?? '')
|
|
90
|
+
.split(/\s+/)
|
|
91
|
+
.filter(Boolean)
|
|
92
|
+
.sort();
|
|
93
|
+
const attributes = { 'nth-child': element.nth_child, 'nth-of-type': element.nth_of_type };
|
|
94
|
+
for (const [name, value] of Object.entries(element))
|
|
95
|
+
if (name.startsWith('attr__'))
|
|
96
|
+
attributes[name] = value;
|
|
97
|
+
if (element.$el_text)
|
|
98
|
+
attributes.text = element.$el_text;
|
|
99
|
+
if (element.attr__href)
|
|
100
|
+
attributes.href = element.attr__href;
|
|
101
|
+
if (element.attr__id)
|
|
102
|
+
attributes.attr_id = element.attr__id;
|
|
103
|
+
const properties = Object.keys(attributes)
|
|
104
|
+
.sort()
|
|
105
|
+
.map((key) => `${quote(key)}="${quote(attributes[key])}"`)
|
|
106
|
+
.join('');
|
|
107
|
+
return `${element.tag_name}${classes.map((name) => `.${name.replaceAll('"', '')}`).join('')}:${properties}`;
|
|
108
|
+
})
|
|
109
|
+
.join(';');
|
|
110
|
+
}
|
|
111
|
+
/** Installs page/session attribution and DOM analytics; returns complete teardown. */
|
|
112
|
+
export function startBrowserCapture(client, options = {}) {
|
|
113
|
+
if (typeof window === 'undefined')
|
|
114
|
+
return () => { };
|
|
115
|
+
const removers = [];
|
|
116
|
+
let page;
|
|
117
|
+
let maxScroll = 0;
|
|
118
|
+
let maxContent = 0;
|
|
119
|
+
let maxHeight = 0;
|
|
120
|
+
let left = false;
|
|
121
|
+
let previousClicks = [];
|
|
122
|
+
let disposed = false;
|
|
123
|
+
const referrer = referrerProperties();
|
|
124
|
+
client.register(browserProperties());
|
|
125
|
+
client.registerOnce({ $initial_referrer: referrer.$referrer, $initial_referring_domain: referrer.$referring_domain });
|
|
126
|
+
function attribution() {
|
|
127
|
+
const url = new URL(location.href);
|
|
128
|
+
const campaign = {};
|
|
129
|
+
for (const [name, value] of url.searchParams) {
|
|
130
|
+
if (/^utm_(source|medium|campaign|term|content|id)$/.test(name) || /^(gclid|fbclid|msclkid)$/.test(name))
|
|
131
|
+
campaign[name] = value;
|
|
132
|
+
}
|
|
133
|
+
client.register({ ...campaign, ...referrer, $current_url: url.href, $host: url.host, $pathname: url.pathname });
|
|
134
|
+
client.registerOnce({
|
|
135
|
+
$session_entry_url: url.href,
|
|
136
|
+
$session_entry_host: url.host,
|
|
137
|
+
$session_entry_pathname: url.pathname,
|
|
138
|
+
$session_entry_referrer: referrer.$referrer,
|
|
139
|
+
$session_entry_referring_domain: referrer.$referring_domain
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
function scroll() {
|
|
143
|
+
maxScroll = Math.max(maxScroll, scrollY);
|
|
144
|
+
maxContent = Math.max(maxContent, scrollY + innerHeight);
|
|
145
|
+
maxHeight = Math.max(maxHeight, document.documentElement.scrollHeight);
|
|
146
|
+
}
|
|
147
|
+
function previousPage() {
|
|
148
|
+
if (!page)
|
|
149
|
+
return {};
|
|
150
|
+
scroll();
|
|
151
|
+
const percentage = (value, total) => (total <= 1 ? 1 : Math.min(1, Math.max(0, value / total)));
|
|
152
|
+
return {
|
|
153
|
+
$prev_pageview_id: page.id,
|
|
154
|
+
$prev_pageview_pathname: page.pathname,
|
|
155
|
+
$prev_pageview_duration: (Date.now() - page.started) / 1000,
|
|
156
|
+
$prev_pageview_last_scroll: scrollY,
|
|
157
|
+
$prev_pageview_max_scroll: maxScroll,
|
|
158
|
+
$prev_pageview_last_scroll_percentage: percentage(scrollY, maxHeight - innerHeight),
|
|
159
|
+
$prev_pageview_max_scroll_percentage: percentage(maxScroll, maxHeight - innerHeight),
|
|
160
|
+
$prev_pageview_last_content: scrollY + innerHeight,
|
|
161
|
+
$prev_pageview_max_content: maxContent,
|
|
162
|
+
$prev_pageview_last_content_percentage: percentage(scrollY + innerHeight, maxHeight),
|
|
163
|
+
$prev_pageview_max_content_percentage: percentage(maxContent, maxHeight)
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
function pageview() {
|
|
167
|
+
if (disposed || client.hasOptedOut() || options.pageviews === false || (page?.url === location.href && !left))
|
|
168
|
+
return;
|
|
169
|
+
client.touchSession();
|
|
170
|
+
// Session rotation can synchronously create this pageview through the listener below.
|
|
171
|
+
if (page?.url === location.href && !left)
|
|
172
|
+
return;
|
|
173
|
+
const previous = previousPage();
|
|
174
|
+
page = { url: location.href, pathname: location.pathname, id: uuid(), started: Date.now() };
|
|
175
|
+
maxScroll = maxContent = maxHeight = 0;
|
|
176
|
+
left = false;
|
|
177
|
+
attribution();
|
|
178
|
+
client.register({ $pageview_id: page.id });
|
|
179
|
+
client.capture('$pageview', { ...previous, $title: document.title });
|
|
180
|
+
}
|
|
181
|
+
function leave() {
|
|
182
|
+
if (left || !page || client.hasOptedOut())
|
|
183
|
+
return;
|
|
184
|
+
left = true;
|
|
185
|
+
client.capture('$pageleave', { ...previousPage(), $current_url: page.url, $pathname: page.pathname }, { passive: true });
|
|
186
|
+
void client.flush({ beacon: true });
|
|
187
|
+
}
|
|
188
|
+
function autocapture(event) {
|
|
189
|
+
if (client.hasOptedOut())
|
|
190
|
+
return;
|
|
191
|
+
const target = event.composedPath().find((item) => item instanceof Element);
|
|
192
|
+
if (!(target instanceof Element) || target.closest(privateSelector))
|
|
193
|
+
return;
|
|
194
|
+
if (target.closest('input[type="password"],[contenteditable="true"]'))
|
|
195
|
+
return;
|
|
196
|
+
const actionable = target.closest('a,button,input,select,textarea,label,form,[role="button"],[role="link"]');
|
|
197
|
+
if (!actionable)
|
|
198
|
+
return;
|
|
199
|
+
const chain = elements(target, options.captureText !== false);
|
|
200
|
+
client.capture('$autocapture', {
|
|
201
|
+
$event_type: event.type,
|
|
202
|
+
$elements: chain,
|
|
203
|
+
$elements_chain: elementsChain(chain),
|
|
204
|
+
$el_text: chain[0]?.$el_text
|
|
205
|
+
});
|
|
206
|
+
if (event instanceof MouseEvent && event.type === 'click' && options.rageclick !== false) {
|
|
207
|
+
const now = Date.now();
|
|
208
|
+
previousClicks = previousClicks.filter((click) => now - click.time < 1000 && Math.abs(click.x - event.clientX) + Math.abs(click.y - event.clientY) < 30);
|
|
209
|
+
previousClicks.push({ x: event.clientX, y: event.clientY, time: now });
|
|
210
|
+
if (previousClicks.length === 3 &&
|
|
211
|
+
!target.closest('input,select,textarea,[role="spinbutton"]') &&
|
|
212
|
+
!window.getSelection()?.toString()) {
|
|
213
|
+
client.capture('$rageclick', { $event_type: 'click', $elements: chain, $elements_chain: elementsChain(chain) });
|
|
214
|
+
previousClicks = [];
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
function listen(target, type, listener, capture = false) {
|
|
219
|
+
target.addEventListener(type, listener, { capture, passive: true });
|
|
220
|
+
removers.push(() => target.removeEventListener(type, listener, capture));
|
|
221
|
+
}
|
|
222
|
+
if (options.pageviews !== false) {
|
|
223
|
+
for (const name of ['pushState', 'replaceState']) {
|
|
224
|
+
const original = history[name];
|
|
225
|
+
const wrapped = function (...args) {
|
|
226
|
+
original.apply(this, args);
|
|
227
|
+
queueMicrotask(pageview);
|
|
228
|
+
};
|
|
229
|
+
history[name] = wrapped;
|
|
230
|
+
removers.push(() => {
|
|
231
|
+
if (history[name] === wrapped)
|
|
232
|
+
history[name] = original;
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
listen(window, 'popstate', pageview);
|
|
236
|
+
listen(window, 'hashchange', pageview);
|
|
237
|
+
listen(window, 'pagehide', leave);
|
|
238
|
+
listen(window, 'pageshow', ((event) => {
|
|
239
|
+
if (event.persisted)
|
|
240
|
+
pageview();
|
|
241
|
+
}));
|
|
242
|
+
listen(window, 'scroll', scroll);
|
|
243
|
+
}
|
|
244
|
+
if (options.autocapture !== false)
|
|
245
|
+
for (const type of ['click', 'change', 'submit'])
|
|
246
|
+
listen(document, type, autocapture, true);
|
|
247
|
+
listen(window, 'resize', () => client.register({ $viewport_height: innerHeight, $viewport_width: innerWidth }));
|
|
248
|
+
removers.push(client.onConsentChange((enabled) => {
|
|
249
|
+
if (enabled) {
|
|
250
|
+
page = undefined;
|
|
251
|
+
pageview();
|
|
252
|
+
}
|
|
253
|
+
}));
|
|
254
|
+
removers.push(client.onSessionChange(() => {
|
|
255
|
+
for (const name of ['url', 'host', 'pathname', 'referrer', 'referring_domain'])
|
|
256
|
+
client.unregister(`$session_entry_${name}`);
|
|
257
|
+
page = undefined;
|
|
258
|
+
attribution();
|
|
259
|
+
pageview();
|
|
260
|
+
}));
|
|
261
|
+
attribution();
|
|
262
|
+
pageview();
|
|
263
|
+
const cleanup = () => {
|
|
264
|
+
disposed = true;
|
|
265
|
+
for (const remove of removers)
|
|
266
|
+
remove();
|
|
267
|
+
unregister();
|
|
268
|
+
};
|
|
269
|
+
const unregister = client.addCleanup(cleanup);
|
|
270
|
+
return cleanup;
|
|
271
|
+
}
|
|
272
|
+
//# sourceMappingURL=browser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"browser.js","sourceRoot":"","sources":["../src/browser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAC;AAW3C,MAAM,eAAe,GAAG,6EAA6E,CAAC;AAEtG,SAAS,iBAAiB;IACxB,MAAM,KAAK,GAAG,SAAS,CAAC,SAAS,CAAC;IAClC,MAAM,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC;QACjC,CAAC,CAAC,gBAAgB;QAClB,CAAC,CAAC,WAAW,CAAC,IAAI,CAAC,KAAK,CAAC;YACvB,CAAC,CAAC,SAAS;YACX,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC;gBACtB,CAAC,CAAC,QAAQ;gBACV,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC;oBACtB,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UAAU,EAAE,kBAAkB,CAAC;YAC5E,MAAM,CAAC,UAAU,CAAC,kBAAkB,IAAI,EAAE,CAAC,CAAC;QAC9C,IAAI,GAAG,SAAS,CAAC;QACjB,WAAW,EAAE,CAAC;QACd,QAAQ,EAAE,CAAC;IACb,CAAC,CAAC,CACH,CAAC;IACF,WAAW,EAAE,CAAC;IACd,QAAQ,EAAE,CAAC;IACX,MAAM,OAAO,GAAG,GAAG,EAAE;QACnB,QAAQ,GAAG,IAAI,CAAC;QAChB,KAAK,MAAM,MAAM,IAAI,QAAQ;YAAE,MAAM,EAAE,CAAC;QACxC,UAAU,EAAE,CAAC;IACf,CAAC,CAAC;IACF,MAAM,UAAU,GAAG,MAAM,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;IAC9C,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { Cleanup, MiniHog, Properties } from './types.js';
|
|
2
|
+
export declare function captureException(client: MiniHog, exception: unknown, properties?: Properties, handled?: boolean): void;
|
|
3
|
+
export declare function startErrorCapture(client: MiniHog): Cleanup;
|
|
4
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAE/D,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,UAAU,CAAC,EAAE,UAAU,EAAE,OAAO,UAAO,GAAG,IAAI,CA+BnH;AAED,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,OAAO,GAAG,OAAO,CAe1D"}
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
export function captureException(client, exception, properties, handled = true) {
|
|
2
|
+
const error = exception instanceof Error ? exception : new Error(String(exception));
|
|
3
|
+
client.capture('$exception', {
|
|
4
|
+
$exception_list: [
|
|
5
|
+
{
|
|
6
|
+
type: error.name,
|
|
7
|
+
value: error.message,
|
|
8
|
+
mechanism: { type: 'generic', handled },
|
|
9
|
+
stacktrace: {
|
|
10
|
+
type: 'raw',
|
|
11
|
+
frames: (error.stack?.split('\n').slice(1) ?? [])
|
|
12
|
+
.flatMap((line) => {
|
|
13
|
+
const match = line.trim().match(/^(?:at\s+)?(?:(.*?)\s*\()?((?:https?|file):.*?):(\d+):(\d+)\)?$/);
|
|
14
|
+
return match
|
|
15
|
+
? [
|
|
16
|
+
{
|
|
17
|
+
function: match[1]?.trim(),
|
|
18
|
+
filename: match[2],
|
|
19
|
+
lineno: Number(match[3]),
|
|
20
|
+
colno: Number(match[4]),
|
|
21
|
+
in_app: true
|
|
22
|
+
}
|
|
23
|
+
]
|
|
24
|
+
: [];
|
|
25
|
+
})
|
|
26
|
+
.reverse()
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
],
|
|
30
|
+
...properties
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
export function startErrorCapture(client) {
|
|
34
|
+
if (typeof window === 'undefined')
|
|
35
|
+
return () => { };
|
|
36
|
+
const error = (event) => {
|
|
37
|
+
if (event.error)
|
|
38
|
+
captureException(client, event.error, undefined, false);
|
|
39
|
+
};
|
|
40
|
+
const rejection = (event) => captureException(client, event.reason, undefined, false);
|
|
41
|
+
window.addEventListener('error', error);
|
|
42
|
+
window.addEventListener('unhandledrejection', rejection);
|
|
43
|
+
const stop = () => {
|
|
44
|
+
window.removeEventListener('error', error);
|
|
45
|
+
window.removeEventListener('unhandledrejection', rejection);
|
|
46
|
+
unregister();
|
|
47
|
+
};
|
|
48
|
+
const unregister = client.addCleanup(stop);
|
|
49
|
+
return stop;
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
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AAM,UAAU,iBAAiB,CAAC,MAAe;IAC/C,IAAI,OAAO,MAAM,KAAK,WAAW;QAAE,OAAO,GAAG,EAAE,GAAE,CAAC,CAAC;IACnD,MAAM,KAAK,GAAG,CAAC,KAAiB,EAAE,EAAE;QAClC,IAAI,KAAK,CAAC,KAAK;YAAE,gBAAgB,CAAC,MAAM,EAAE,KAAK,CAAC,KAAK,EAAE,SAAS,EAAE,KAAK,CAAC,CAAC;IAC3E,CAAC,CAAC;IACF,MAAM,SAAS,GAAG,CAAC,KAA4B,EAAE,EAAE,CAAC,gBAAgB,CAAC,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,SAAS,EAAE,KAAK,CAAC,CAAC;IAC7G,MAAM,CAAC,gBAAgB,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;IACxC,MAAM,CAAC,gBAAgB,CAAC,oBAAoB,EAAE,SAAS,CAAC,CAAC;IACzD,MAAM,IAAI,GAAG,GAAG,EAAE;QAChB,MAAM,CAAC,mBAAmB,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;QAC3C,MAAM,CAAC,mBAAmB,CAAC,oBAAoB,EAAE,SAAS,CAAC,CAAC;QAC5D,UAAU,EAAE,CAAC;IACf,CAAC,CAAC;IACF,MAAM,UAAU,GAAG,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;IAC3C,OAAO,IAAI,CAAC;AACd,CAAC"}
|
package/dist/flags.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { MiniHog, Properties } from './types.js';
|
|
2
|
+
export type FlagValue = boolean | string;
|
|
3
|
+
export interface FeatureFlagOptions {
|
|
4
|
+
bootstrap?: Record<string, FlagValue>;
|
|
5
|
+
personProperties?: Properties;
|
|
6
|
+
groupProperties?: Record<string, Properties>;
|
|
7
|
+
evaluationContexts?: string[];
|
|
8
|
+
}
|
|
9
|
+
export declare function createFeatureFlags(client: MiniHog, options?: FeatureFlagOptions): {
|
|
10
|
+
reload: () => Promise<Readonly<Record<string, FlagValue>>>;
|
|
11
|
+
getFeatureFlag: (key: string, sendEvent?: boolean) => FlagValue | undefined;
|
|
12
|
+
isFeatureEnabled: (key: string) => boolean | undefined;
|
|
13
|
+
getFeatureFlagPayload(key: string): unknown;
|
|
14
|
+
onFeatureFlags(listener: (flags: Readonly<Record<string, FlagValue>>) => void): () => void;
|
|
15
|
+
destroy: () => void;
|
|
16
|
+
};
|
|
17
|
+
//# sourceMappingURL=flags.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"flags.d.ts","sourceRoot":"","sources":["../src/flags.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAEtD,MAAM,MAAM,SAAS,GAAG,OAAO,GAAG,MAAM,CAAC;AAYzC,MAAM,WAAW,kBAAkB;IACjC,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;IACtC,gBAAgB,CAAC,EAAE,UAAU,CAAC;IAC9B,eAAe,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;IAC7C,kBAAkB,CAAC,EAAE,MAAM,EAAE,CAAC;CAC/B;AAED,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,OAAO,EAAE,OAAO,GAAE,kBAAuB;kBAgCzD,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC,CAAC;0BAyCxC,MAAM,0BAAqB,SAAS,GAAG,SAAS;4BA+CnD,MAAM;+BAIH,MAAM,GAAG,OAAO;6BAUlB,CAAC,KAAK,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC,KAAK,IAAI;;EAShF"}
|