@klime/browser 1.0.3 → 1.2.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/README.md +138 -3
- package/dist/index.cjs +459 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +106 -0
- package/dist/index.d.ts +83 -2
- package/dist/index.js +412 -277
- package/dist/index.js.map +1 -0
- package/package.json +17 -3
- package/dist/types.d.ts +0 -49
- package/dist/types.js +0 -1
package/README.md
CHANGED
|
@@ -44,6 +44,83 @@ client.group(
|
|
|
44
44
|
client.group("org_456", null, { userId: "user_123" });
|
|
45
45
|
```
|
|
46
46
|
|
|
47
|
+
## Installation Prompt
|
|
48
|
+
|
|
49
|
+
Copy and paste this prompt into Cursor, Copilot, or your favorite AI editor to integrate Klime:
|
|
50
|
+
|
|
51
|
+
```
|
|
52
|
+
Integrate Klime for customer analytics. Klime tracks user activity to identify which customers are healthy vs at risk of churning.
|
|
53
|
+
|
|
54
|
+
ANALYTICS MODES (determine which applies):
|
|
55
|
+
- Companies & Teams: Your customers are companies with multiple team members (SaaS, enterprise tools)
|
|
56
|
+
→ Use identify() + group() + track()
|
|
57
|
+
- Individual Customers: Your customers are individuals with private accounts (consumer apps, creator tools)
|
|
58
|
+
→ Use identify() + track() only (no group() needed)
|
|
59
|
+
|
|
60
|
+
KEY CONCEPTS:
|
|
61
|
+
- Every track() call requires either userId OR groupId (no anonymous events)
|
|
62
|
+
- Use groupId alone for org-level events (webhooks, cron jobs, system metrics)
|
|
63
|
+
- group() links a user to a company AND sets company traits (only for Companies & Teams mode)
|
|
64
|
+
- Order doesn't matter - events before identify/group still get attributed correctly
|
|
65
|
+
|
|
66
|
+
BEST PRACTICES:
|
|
67
|
+
- Initialize client ONCE (singleton, React context, or module-level)
|
|
68
|
+
- Write key is safe to embed in client code (it's write-only, not a secret)
|
|
69
|
+
- Events auto-flush on page unload - no manual shutdown needed
|
|
70
|
+
|
|
71
|
+
Install: npm install @klime/browser
|
|
72
|
+
|
|
73
|
+
import { KlimeClient } from "@klime/browser";
|
|
74
|
+
|
|
75
|
+
const client = new KlimeClient({ writeKey: "YOUR_WRITE_KEY" });
|
|
76
|
+
|
|
77
|
+
// Identify users at signup/login:
|
|
78
|
+
client.identify("usr_abc123", { email: "jane@acme.com", name: "Jane Smith" });
|
|
79
|
+
|
|
80
|
+
// Track key activities:
|
|
81
|
+
client.track("Report Generated", { report_type: "revenue" }, { userId: "usr_abc123" });
|
|
82
|
+
client.track("Feature Used", { feature: "export", format: "csv" }, { userId: "usr_abc123" });
|
|
83
|
+
client.track("Teammate Invited", { role: "member" }, { userId: "usr_abc123" });
|
|
84
|
+
|
|
85
|
+
// If Companies & Teams mode: link user to their company and set company traits
|
|
86
|
+
client.group("org_456", { name: "Acme Inc", plan: "enterprise" }, { userId: "usr_abc123" });
|
|
87
|
+
|
|
88
|
+
INTEGRATION WORKFLOW:
|
|
89
|
+
|
|
90
|
+
Phase 1: Discover
|
|
91
|
+
Explore the codebase to understand:
|
|
92
|
+
1. What framework is used? (React, Vue, Svelte, vanilla JS, etc.)
|
|
93
|
+
2. Where is user identity available? (e.g., useUser().id, useAuth().user.id, session.user.id, store.user)
|
|
94
|
+
3. Is this Companies & Teams or Individual Customers?
|
|
95
|
+
- Look for: organization, workspace, tenant, team, account in URL/context/store → Companies & Teams (use group())
|
|
96
|
+
- No company/org concept, just individual users → Individual Customers (skip group())
|
|
97
|
+
4. Where do core user actions happen? (onClick handlers, form submissions, hooks, event handlers)
|
|
98
|
+
5. Is there existing analytics? (search: segment, posthog, mixpanel, amplitude, .track)
|
|
99
|
+
Match your integration style to the framework's conventions.
|
|
100
|
+
|
|
101
|
+
Phase 2: Instrument
|
|
102
|
+
Add these calls using idiomatic patterns for the framework:
|
|
103
|
+
- Initialize client once (React: context provider, Vue: plugin, Svelte: store, vanilla: module singleton)
|
|
104
|
+
- identify() in auth/login success handler
|
|
105
|
+
- group() when user-org association is established (Companies & Teams mode only)
|
|
106
|
+
- track() for key user actions (see below)
|
|
107
|
+
|
|
108
|
+
WHAT TO TRACK:
|
|
109
|
+
Active engagement (primary): feature usage, resource creation, collaboration, completing flows
|
|
110
|
+
Session signals (secondary): dashboard access, app opened - distinguishes "low usage" from "churned"
|
|
111
|
+
Do NOT track: every click, page navigations, component renders
|
|
112
|
+
|
|
113
|
+
Phase 3: Verify
|
|
114
|
+
Confirm: client initialized, identify/group/track calls added
|
|
115
|
+
|
|
116
|
+
Phase 4: Summarize
|
|
117
|
+
Report what you added:
|
|
118
|
+
- Files modified and what was added to each
|
|
119
|
+
- Events being tracked (list event names and what triggers them)
|
|
120
|
+
- How userId is obtained (and groupId if Companies & Teams mode)
|
|
121
|
+
- Any assumptions made or questions
|
|
122
|
+
```
|
|
123
|
+
|
|
47
124
|
## API Reference
|
|
48
125
|
|
|
49
126
|
### Constructor
|
|
@@ -65,9 +142,13 @@ new KlimeClient(config: {
|
|
|
65
142
|
|
|
66
143
|
#### `track(event: string, properties?: object, options?: { userId?, groupId? })`
|
|
67
144
|
|
|
68
|
-
Track
|
|
145
|
+
Track an event. Events can be attributed in two ways:
|
|
146
|
+
|
|
147
|
+
- **User events**: Provide `userId` to track user activity (most common)
|
|
148
|
+
- **Group events**: Provide `groupId` without `userId` for organization-level events
|
|
69
149
|
|
|
70
150
|
```javascript
|
|
151
|
+
// User event (most common)
|
|
71
152
|
client.track(
|
|
72
153
|
"Button Clicked",
|
|
73
154
|
{
|
|
@@ -76,9 +157,19 @@ client.track(
|
|
|
76
157
|
},
|
|
77
158
|
{ userId: "user_123" }
|
|
78
159
|
);
|
|
160
|
+
|
|
161
|
+
// Group event (for webhooks, cron jobs, system events)
|
|
162
|
+
client.track(
|
|
163
|
+
"Events Received",
|
|
164
|
+
{
|
|
165
|
+
count: 100,
|
|
166
|
+
source: "webhook",
|
|
167
|
+
},
|
|
168
|
+
{ groupId: "org_456" }
|
|
169
|
+
);
|
|
79
170
|
```
|
|
80
171
|
|
|
81
|
-
> **
|
|
172
|
+
> **Note**: The `groupId` option can also be combined with `userId` for multi-tenant scenarios where you need to specify which organization context a user event occurred in.
|
|
82
173
|
|
|
83
174
|
#### `identify(userId: string, traits?: object)`
|
|
84
175
|
|
|
@@ -131,8 +222,52 @@ await client.shutdown();
|
|
|
131
222
|
- **Automatic Batching**: Events are automatically batched and sent every 2 seconds or when the batch size reaches 20 events
|
|
132
223
|
- **Automatic Retries**: Failed requests are automatically retried with exponential backoff
|
|
133
224
|
- **Browser Context**: Automatically captures userAgent, locale, and timezone
|
|
134
|
-
- **Page Unload Handling**:
|
|
225
|
+
- **Page Unload Handling**: Flushes on `visibilitychange` (when tab is hidden), `pagehide`, and `beforeunload`, and uses `fetch` with `keepalive: true` (when batch ≤64KB) so requests can complete after the page unloads
|
|
135
226
|
- **Zero Dependencies**: Uses only native browser APIs
|
|
227
|
+
- **Universal Module Support**: Works with ESM and CommonJS (no `transpilePackages` needed)
|
|
228
|
+
|
|
229
|
+
## Module Compatibility
|
|
230
|
+
|
|
231
|
+
This package ships dual ESM/CommonJS builds and works out of the box with:
|
|
232
|
+
|
|
233
|
+
- **Bundlers**: Vite, webpack, esbuild, Rollup, Parcel
|
|
234
|
+
- **Frameworks**: Next.js, Remix, Nuxt, SvelteKit, Astro
|
|
235
|
+
- **Runtimes**: Browsers, Node.js (SSR), Deno, Bun
|
|
236
|
+
|
|
237
|
+
```javascript
|
|
238
|
+
// ESM (recommended)
|
|
239
|
+
import { KlimeClient } from "@klime/browser";
|
|
240
|
+
|
|
241
|
+
// CommonJS
|
|
242
|
+
const { KlimeClient } = require("@klime/browser");
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
No special configuration required — it just works.
|
|
246
|
+
|
|
247
|
+
## Performance
|
|
248
|
+
|
|
249
|
+
When you call `track()`, `identify()`, or `group()`, the SDK:
|
|
250
|
+
|
|
251
|
+
1. Adds the event to an in-memory queue (microseconds)
|
|
252
|
+
2. Returns immediately without waiting for network I/O
|
|
253
|
+
|
|
254
|
+
Events are sent to Klime's servers asynchronously via the browser's `fetch` API. This means:
|
|
255
|
+
|
|
256
|
+
- **No network waiting**: HTTP requests happen asynchronously in the background
|
|
257
|
+
- **No UI blocking**: Tracking calls don't freeze the browser or delay user interactions
|
|
258
|
+
- **Automatic batching**: Events are queued and sent in batches (default: every 2 seconds or 20 events)
|
|
259
|
+
|
|
260
|
+
```javascript
|
|
261
|
+
// This returns immediately - no HTTP request is made here
|
|
262
|
+
client.track("Button Clicked", { button: "signup" }, { userId: "user_123" });
|
|
263
|
+
|
|
264
|
+
// Your code continues without waiting
|
|
265
|
+
navigate("/dashboard");
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
The only blocking operation is `await flush()`, which waits for all queued events to be sent. The SDK automatically flushes on page unload (and uses `keepalive` so the request can complete after the page is gone).
|
|
269
|
+
|
|
270
|
+
**SPAs (e.g. Next.js)**: Client-side route changes do not trigger `beforeunload` or `pagehide`. To avoid losing events on navigation, call `flush()` when the route changes (e.g. in your router's `onRouteChange` or in a `useEffect` that depends on `pathname`).
|
|
136
271
|
|
|
137
272
|
## Configuration
|
|
138
273
|
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,459 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
KlimeClient: () => KlimeClient,
|
|
24
|
+
SendError: () => SendError
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(index_exports);
|
|
27
|
+
|
|
28
|
+
// src/types.ts
|
|
29
|
+
var SendError = class extends Error {
|
|
30
|
+
constructor(message, events) {
|
|
31
|
+
super(message);
|
|
32
|
+
this.name = "SendError";
|
|
33
|
+
this.events = events;
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
// src/index.ts
|
|
38
|
+
var DEFAULT_ENDPOINT = "https://i.klime.com";
|
|
39
|
+
var DEFAULT_FLUSH_INTERVAL = 2e3;
|
|
40
|
+
var DEFAULT_MAX_BATCH_SIZE = 20;
|
|
41
|
+
var DEFAULT_MAX_QUEUE_SIZE = 1e3;
|
|
42
|
+
var DEFAULT_RETRY_MAX_ATTEMPTS = 5;
|
|
43
|
+
var DEFAULT_RETRY_INITIAL_DELAY = 1e3;
|
|
44
|
+
var MAX_BATCH_SIZE = 100;
|
|
45
|
+
var MAX_EVENT_SIZE_BYTES = 200 * 1024;
|
|
46
|
+
var MAX_BATCH_SIZE_BYTES = 10 * 1024 * 1024;
|
|
47
|
+
var KEEPALIVE_MAX_BODY_BYTES = 64 * 1024;
|
|
48
|
+
var SDK_VERSION = "1.1.0";
|
|
49
|
+
var createDefaultLogger = () => ({
|
|
50
|
+
debug: (message, ...args) => console.debug(`[Klime] ${message}`, ...args),
|
|
51
|
+
info: (message, ...args) => console.info(`[Klime] ${message}`, ...args),
|
|
52
|
+
warn: (message, ...args) => console.warn(`[Klime] ${message}`, ...args),
|
|
53
|
+
error: (message, ...args) => console.error(`[Klime] ${message}`, ...args)
|
|
54
|
+
});
|
|
55
|
+
var KlimeClient = class {
|
|
56
|
+
constructor(config) {
|
|
57
|
+
this.queue = [];
|
|
58
|
+
this.flushTimer = null;
|
|
59
|
+
this.isShutdown = false;
|
|
60
|
+
this.flushPromise = null;
|
|
61
|
+
this.unloadHandler = null;
|
|
62
|
+
this.visibilityChangeHandler = null;
|
|
63
|
+
if (!config.writeKey) {
|
|
64
|
+
throw new Error("writeKey is required");
|
|
65
|
+
}
|
|
66
|
+
this.config = {
|
|
67
|
+
writeKey: config.writeKey,
|
|
68
|
+
endpoint: config.endpoint || DEFAULT_ENDPOINT,
|
|
69
|
+
flushInterval: config.flushInterval ?? DEFAULT_FLUSH_INTERVAL,
|
|
70
|
+
maxBatchSize: Math.min(
|
|
71
|
+
config.maxBatchSize ?? DEFAULT_MAX_BATCH_SIZE,
|
|
72
|
+
MAX_BATCH_SIZE
|
|
73
|
+
),
|
|
74
|
+
maxQueueSize: config.maxQueueSize ?? DEFAULT_MAX_QUEUE_SIZE,
|
|
75
|
+
retryMaxAttempts: config.retryMaxAttempts ?? DEFAULT_RETRY_MAX_ATTEMPTS,
|
|
76
|
+
retryInitialDelay: config.retryInitialDelay ?? DEFAULT_RETRY_INITIAL_DELAY,
|
|
77
|
+
autoFlushOnUnload: config.autoFlushOnUnload ?? true,
|
|
78
|
+
logger: config.logger ?? createDefaultLogger(),
|
|
79
|
+
onError: config.onError,
|
|
80
|
+
onSuccess: config.onSuccess
|
|
81
|
+
};
|
|
82
|
+
if (this.config.autoFlushOnUnload && typeof window !== "undefined") {
|
|
83
|
+
this.unloadHandler = () => {
|
|
84
|
+
this.flush();
|
|
85
|
+
};
|
|
86
|
+
window.addEventListener("beforeunload", this.unloadHandler);
|
|
87
|
+
window.addEventListener("pagehide", this.unloadHandler);
|
|
88
|
+
this.visibilityChangeHandler = () => {
|
|
89
|
+
if (typeof document !== "undefined" && document.visibilityState === "hidden") {
|
|
90
|
+
this.flush();
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
document.addEventListener("visibilitychange", this.visibilityChangeHandler);
|
|
94
|
+
}
|
|
95
|
+
this.scheduleFlush();
|
|
96
|
+
}
|
|
97
|
+
track(event, properties, options) {
|
|
98
|
+
if (this.isShutdown) {
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
const eventObj = {
|
|
102
|
+
type: "track",
|
|
103
|
+
messageId: this.generateUUID(),
|
|
104
|
+
event,
|
|
105
|
+
timestamp: this.generateTimestamp(),
|
|
106
|
+
properties: properties || {},
|
|
107
|
+
context: this.getContext()
|
|
108
|
+
};
|
|
109
|
+
if (options?.userId) {
|
|
110
|
+
eventObj.userId = options.userId;
|
|
111
|
+
}
|
|
112
|
+
if (options?.groupId) {
|
|
113
|
+
eventObj.groupId = options.groupId;
|
|
114
|
+
}
|
|
115
|
+
this.enqueue(eventObj);
|
|
116
|
+
}
|
|
117
|
+
identify(userId, traits) {
|
|
118
|
+
if (this.isShutdown) {
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
const eventObj = {
|
|
122
|
+
type: "identify",
|
|
123
|
+
messageId: this.generateUUID(),
|
|
124
|
+
userId,
|
|
125
|
+
timestamp: this.generateTimestamp(),
|
|
126
|
+
traits: traits || {},
|
|
127
|
+
context: this.getContext()
|
|
128
|
+
};
|
|
129
|
+
this.enqueue(eventObj);
|
|
130
|
+
}
|
|
131
|
+
group(groupId, traits, options) {
|
|
132
|
+
if (this.isShutdown) {
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
const eventObj = {
|
|
136
|
+
type: "group",
|
|
137
|
+
messageId: this.generateUUID(),
|
|
138
|
+
groupId,
|
|
139
|
+
timestamp: this.generateTimestamp(),
|
|
140
|
+
traits: traits || {},
|
|
141
|
+
context: this.getContext()
|
|
142
|
+
};
|
|
143
|
+
if (options?.userId) {
|
|
144
|
+
eventObj.userId = options.userId;
|
|
145
|
+
}
|
|
146
|
+
this.enqueue(eventObj);
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Track an event synchronously. Returns BatchResponse or throws SendError.
|
|
150
|
+
*/
|
|
151
|
+
async trackSync(event, properties, options) {
|
|
152
|
+
if (this.isShutdown) {
|
|
153
|
+
throw new SendError("Client is shutdown", []);
|
|
154
|
+
}
|
|
155
|
+
const eventObj = {
|
|
156
|
+
type: "track",
|
|
157
|
+
messageId: this.generateUUID(),
|
|
158
|
+
event,
|
|
159
|
+
timestamp: this.generateTimestamp(),
|
|
160
|
+
properties: properties || {},
|
|
161
|
+
context: this.getContext()
|
|
162
|
+
};
|
|
163
|
+
if (options?.userId) {
|
|
164
|
+
eventObj.userId = options.userId;
|
|
165
|
+
}
|
|
166
|
+
if (options?.groupId) {
|
|
167
|
+
eventObj.groupId = options.groupId;
|
|
168
|
+
}
|
|
169
|
+
return this.sendSync([eventObj]);
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Identify a user synchronously. Returns BatchResponse or throws SendError.
|
|
173
|
+
*/
|
|
174
|
+
async identifySync(userId, traits) {
|
|
175
|
+
if (this.isShutdown) {
|
|
176
|
+
throw new SendError("Client is shutdown", []);
|
|
177
|
+
}
|
|
178
|
+
const eventObj = {
|
|
179
|
+
type: "identify",
|
|
180
|
+
messageId: this.generateUUID(),
|
|
181
|
+
userId,
|
|
182
|
+
timestamp: this.generateTimestamp(),
|
|
183
|
+
traits: traits || {},
|
|
184
|
+
context: this.getContext()
|
|
185
|
+
};
|
|
186
|
+
return this.sendSync([eventObj]);
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Associate a user with a group synchronously. Returns BatchResponse or throws SendError.
|
|
190
|
+
*/
|
|
191
|
+
async groupSync(groupId, traits, options) {
|
|
192
|
+
if (this.isShutdown) {
|
|
193
|
+
throw new SendError("Client is shutdown", []);
|
|
194
|
+
}
|
|
195
|
+
const eventObj = {
|
|
196
|
+
type: "group",
|
|
197
|
+
messageId: this.generateUUID(),
|
|
198
|
+
groupId,
|
|
199
|
+
timestamp: this.generateTimestamp(),
|
|
200
|
+
traits: traits || {},
|
|
201
|
+
context: this.getContext()
|
|
202
|
+
};
|
|
203
|
+
if (options?.userId) {
|
|
204
|
+
eventObj.userId = options.userId;
|
|
205
|
+
}
|
|
206
|
+
return this.sendSync([eventObj]);
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* Return the number of events currently in the queue.
|
|
210
|
+
*/
|
|
211
|
+
getQueueSize() {
|
|
212
|
+
return this.queue.length;
|
|
213
|
+
}
|
|
214
|
+
async flush() {
|
|
215
|
+
if (this.flushPromise) {
|
|
216
|
+
return this.flushPromise;
|
|
217
|
+
}
|
|
218
|
+
this.flushPromise = this.doFlush();
|
|
219
|
+
try {
|
|
220
|
+
await this.flushPromise;
|
|
221
|
+
} finally {
|
|
222
|
+
this.flushPromise = null;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
async shutdown() {
|
|
226
|
+
if (this.isShutdown) {
|
|
227
|
+
return;
|
|
228
|
+
}
|
|
229
|
+
this.isShutdown = true;
|
|
230
|
+
if (this.unloadHandler && typeof window !== "undefined") {
|
|
231
|
+
window.removeEventListener("beforeunload", this.unloadHandler);
|
|
232
|
+
window.removeEventListener("pagehide", this.unloadHandler);
|
|
233
|
+
}
|
|
234
|
+
if (this.visibilityChangeHandler && typeof document !== "undefined") {
|
|
235
|
+
document.removeEventListener("visibilitychange", this.visibilityChangeHandler);
|
|
236
|
+
}
|
|
237
|
+
if (this.flushTimer) {
|
|
238
|
+
clearTimeout(this.flushTimer);
|
|
239
|
+
this.flushTimer = null;
|
|
240
|
+
}
|
|
241
|
+
await this.flush();
|
|
242
|
+
}
|
|
243
|
+
enqueue(event) {
|
|
244
|
+
const eventSize = this.estimateEventSize(event);
|
|
245
|
+
if (eventSize > MAX_EVENT_SIZE_BYTES) {
|
|
246
|
+
this.config.logger.warn(
|
|
247
|
+
`Event size (${eventSize} bytes) exceeds ${MAX_EVENT_SIZE_BYTES} bytes limit`
|
|
248
|
+
);
|
|
249
|
+
return;
|
|
250
|
+
}
|
|
251
|
+
if (this.queue.length >= this.config.maxQueueSize) {
|
|
252
|
+
const dropped = this.queue.shift();
|
|
253
|
+
this.config.logger.warn(`Queue full, dropping oldest event: ${dropped?.type}`);
|
|
254
|
+
}
|
|
255
|
+
this.queue.push(event);
|
|
256
|
+
this.config.logger.debug(`Enqueued ${event.type} event, queue size: ${this.queue.length}`);
|
|
257
|
+
if (this.queue.length >= this.config.maxBatchSize) {
|
|
258
|
+
this.flush();
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
async doFlush() {
|
|
262
|
+
if (this.queue.length === 0) {
|
|
263
|
+
return;
|
|
264
|
+
}
|
|
265
|
+
if (this.flushTimer) {
|
|
266
|
+
clearTimeout(this.flushTimer);
|
|
267
|
+
this.flushTimer = null;
|
|
268
|
+
}
|
|
269
|
+
while (this.queue.length > 0) {
|
|
270
|
+
const batch = this.extractBatch();
|
|
271
|
+
if (batch.length === 0) {
|
|
272
|
+
break;
|
|
273
|
+
}
|
|
274
|
+
await this.sendBatch(batch);
|
|
275
|
+
}
|
|
276
|
+
this.scheduleFlush();
|
|
277
|
+
}
|
|
278
|
+
extractBatch() {
|
|
279
|
+
const batch = [];
|
|
280
|
+
let batchSize = 0;
|
|
281
|
+
while (this.queue.length > 0 && batch.length < MAX_BATCH_SIZE) {
|
|
282
|
+
const event = this.queue[0];
|
|
283
|
+
const eventSize = this.estimateEventSize(event);
|
|
284
|
+
if (batchSize + eventSize > MAX_BATCH_SIZE_BYTES) {
|
|
285
|
+
break;
|
|
286
|
+
}
|
|
287
|
+
batch.push(this.queue.shift());
|
|
288
|
+
batchSize += eventSize;
|
|
289
|
+
}
|
|
290
|
+
return batch;
|
|
291
|
+
}
|
|
292
|
+
async sendBatch(batch) {
|
|
293
|
+
if (batch.length === 0) {
|
|
294
|
+
return;
|
|
295
|
+
}
|
|
296
|
+
this.config.logger.debug(`Sending batch of ${batch.length} events`);
|
|
297
|
+
const result = await this.doSend(batch);
|
|
298
|
+
if (result === null) {
|
|
299
|
+
const error = new Error(`Failed to send batch of ${batch.length} events after retries`);
|
|
300
|
+
this.invokeOnError(error, batch);
|
|
301
|
+
} else if (result.failed > 0 && result.errors) {
|
|
302
|
+
this.config.logger.warn(
|
|
303
|
+
`Batch partially failed. Accepted: ${result.accepted}, Failed: ${result.failed}`,
|
|
304
|
+
result.errors
|
|
305
|
+
);
|
|
306
|
+
this.invokeOnSuccess(result);
|
|
307
|
+
} else {
|
|
308
|
+
this.config.logger.debug(`Batch sent successfully. Accepted: ${result.accepted}`);
|
|
309
|
+
this.invokeOnSuccess(result);
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
async sendSync(events) {
|
|
313
|
+
this.config.logger.debug(`Sending ${events.length} events synchronously`);
|
|
314
|
+
const result = await this.doSend(events);
|
|
315
|
+
if (result === null) {
|
|
316
|
+
throw new SendError(`Failed to send ${events.length} events after retries`, events);
|
|
317
|
+
}
|
|
318
|
+
return result;
|
|
319
|
+
}
|
|
320
|
+
async doSend(batch) {
|
|
321
|
+
const request = { batch };
|
|
322
|
+
const requestUrl = `${this.config.endpoint}/v1/batch`;
|
|
323
|
+
const body = JSON.stringify(request);
|
|
324
|
+
const useKeepalive = body.length <= KEEPALIVE_MAX_BODY_BYTES;
|
|
325
|
+
let attempt = 0;
|
|
326
|
+
let delay = this.config.retryInitialDelay;
|
|
327
|
+
while (attempt < this.config.retryMaxAttempts) {
|
|
328
|
+
try {
|
|
329
|
+
const response = await fetch(requestUrl, {
|
|
330
|
+
method: "POST",
|
|
331
|
+
headers: {
|
|
332
|
+
"Content-Type": "application/json",
|
|
333
|
+
Authorization: `Bearer ${this.config.writeKey}`
|
|
334
|
+
},
|
|
335
|
+
body,
|
|
336
|
+
keepalive: useKeepalive
|
|
337
|
+
});
|
|
338
|
+
const data = await response.json();
|
|
339
|
+
if (response.ok) {
|
|
340
|
+
return data;
|
|
341
|
+
}
|
|
342
|
+
if (response.status === 400 || response.status === 401) {
|
|
343
|
+
this.config.logger.error(`Permanent error (${response.status}):`, data);
|
|
344
|
+
return null;
|
|
345
|
+
}
|
|
346
|
+
if (response.status === 429 || response.status === 503) {
|
|
347
|
+
const retryAfter = response.headers.get("Retry-After");
|
|
348
|
+
if (retryAfter) {
|
|
349
|
+
delay = parseInt(retryAfter, 10) * 1e3;
|
|
350
|
+
}
|
|
351
|
+
attempt++;
|
|
352
|
+
if (attempt < this.config.retryMaxAttempts) {
|
|
353
|
+
this.config.logger.debug(`Retrying after ${delay}ms (attempt ${attempt})`);
|
|
354
|
+
await this.sleep(delay);
|
|
355
|
+
delay = Math.min(delay * 2, 16e3);
|
|
356
|
+
continue;
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
attempt++;
|
|
360
|
+
if (attempt < this.config.retryMaxAttempts) {
|
|
361
|
+
this.config.logger.debug(`Retrying after ${delay}ms (attempt ${attempt})`);
|
|
362
|
+
await this.sleep(delay);
|
|
363
|
+
delay = Math.min(delay * 2, 16e3);
|
|
364
|
+
}
|
|
365
|
+
} catch (error) {
|
|
366
|
+
attempt++;
|
|
367
|
+
if (attempt < this.config.retryMaxAttempts) {
|
|
368
|
+
this.config.logger.debug(`Retrying after ${delay}ms (attempt ${attempt})`);
|
|
369
|
+
await this.sleep(delay);
|
|
370
|
+
delay = Math.min(delay * 2, 16e3);
|
|
371
|
+
} else {
|
|
372
|
+
this.config.logger.error("Failed to send batch after retries:", error);
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
return null;
|
|
377
|
+
}
|
|
378
|
+
invokeOnError(error, batch) {
|
|
379
|
+
if (this.config.onError) {
|
|
380
|
+
try {
|
|
381
|
+
this.config.onError(error, batch);
|
|
382
|
+
} catch (e) {
|
|
383
|
+
this.config.logger.error("Error in onError callback:", e);
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
invokeOnSuccess(response) {
|
|
388
|
+
if (this.config.onSuccess) {
|
|
389
|
+
try {
|
|
390
|
+
this.config.onSuccess(response);
|
|
391
|
+
} catch (e) {
|
|
392
|
+
this.config.logger.error("Error in onSuccess callback:", e);
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
scheduleFlush() {
|
|
397
|
+
if (this.isShutdown || this.flushTimer) {
|
|
398
|
+
return;
|
|
399
|
+
}
|
|
400
|
+
this.flushTimer = setTimeout(() => {
|
|
401
|
+
this.flush();
|
|
402
|
+
}, this.config.flushInterval);
|
|
403
|
+
}
|
|
404
|
+
generateUUID() {
|
|
405
|
+
if (typeof crypto !== "undefined" && crypto.randomUUID) {
|
|
406
|
+
return crypto.randomUUID();
|
|
407
|
+
}
|
|
408
|
+
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => {
|
|
409
|
+
const r = Math.random() * 16 | 0;
|
|
410
|
+
const v = c === "x" ? r : r & 3 | 8;
|
|
411
|
+
return v.toString(16);
|
|
412
|
+
});
|
|
413
|
+
}
|
|
414
|
+
generateTimestamp() {
|
|
415
|
+
return (/* @__PURE__ */ new Date()).toISOString();
|
|
416
|
+
}
|
|
417
|
+
getContext() {
|
|
418
|
+
const context = {
|
|
419
|
+
library: {
|
|
420
|
+
name: "js-sdk",
|
|
421
|
+
version: SDK_VERSION
|
|
422
|
+
}
|
|
423
|
+
};
|
|
424
|
+
if (typeof navigator !== "undefined") {
|
|
425
|
+
if (navigator.userAgent) {
|
|
426
|
+
context.userAgent = navigator.userAgent;
|
|
427
|
+
}
|
|
428
|
+
if (navigator.language) {
|
|
429
|
+
context.locale = navigator.language;
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
if (typeof Intl !== "undefined" && Intl.DateTimeFormat) {
|
|
433
|
+
try {
|
|
434
|
+
const timezone = Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
435
|
+
if (timezone) {
|
|
436
|
+
context.timezone = timezone;
|
|
437
|
+
}
|
|
438
|
+
} catch (e) {
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
return context;
|
|
442
|
+
}
|
|
443
|
+
estimateEventSize(event) {
|
|
444
|
+
try {
|
|
445
|
+
return JSON.stringify(event).length;
|
|
446
|
+
} catch {
|
|
447
|
+
return 500;
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
sleep(ms) {
|
|
451
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
452
|
+
}
|
|
453
|
+
};
|
|
454
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
455
|
+
0 && (module.exports = {
|
|
456
|
+
KlimeClient,
|
|
457
|
+
SendError
|
|
458
|
+
});
|
|
459
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/types.ts"],"sourcesContent":["import {\n KlimeConfig,\n TrackOptions,\n Event,\n BatchRequest,\n BatchResponse,\n EventContext,\n Logger,\n SendError,\n} from \"./types\";\n\n// Re-export types for users\nexport { SendError, BatchResponse, Logger } from \"./types\";\nexport type { KlimeConfig, TrackOptions, Event } from \"./types\";\n\nconst DEFAULT_ENDPOINT = \"https://i.klime.com\";\nconst DEFAULT_FLUSH_INTERVAL = 2000;\nconst DEFAULT_MAX_BATCH_SIZE = 20;\nconst DEFAULT_MAX_QUEUE_SIZE = 1000;\nconst DEFAULT_RETRY_MAX_ATTEMPTS = 5;\nconst DEFAULT_RETRY_INITIAL_DELAY = 1000;\nconst MAX_BATCH_SIZE = 100;\nconst MAX_EVENT_SIZE_BYTES = 200 * 1024; // 200KB\nconst MAX_BATCH_SIZE_BYTES = 10 * 1024 * 1024; // 10MB\n/** Max body size for fetch keepalive (spec limit). Requests larger than this omit keepalive. */\nconst KEEPALIVE_MAX_BODY_BYTES = 64 * 1024; // 64KB\nconst SDK_VERSION = \"1.1.0\";\n\n// Default logger that wraps console with [Klime] prefix\nconst createDefaultLogger = (): Logger => ({\n debug: (message: string, ...args: any[]) =>\n console.debug(`[Klime] ${message}`, ...args),\n info: (message: string, ...args: any[]) =>\n console.info(`[Klime] ${message}`, ...args),\n warn: (message: string, ...args: any[]) =>\n console.warn(`[Klime] ${message}`, ...args),\n error: (message: string, ...args: any[]) =>\n console.error(`[Klime] ${message}`, ...args),\n});\n\n// Internal config type with required fields and optional callbacks/logger\ninterface InternalConfig {\n writeKey: string;\n endpoint: string;\n flushInterval: number;\n maxBatchSize: number;\n maxQueueSize: number;\n retryMaxAttempts: number;\n retryInitialDelay: number;\n autoFlushOnUnload: boolean;\n logger: Logger;\n onError?: (error: Error, events: Event[]) => void;\n onSuccess?: (response: BatchResponse) => void;\n}\n\nexport class KlimeClient {\n private config: InternalConfig;\n private queue: Event[] = [];\n private flushTimer: ReturnType<typeof setTimeout> | null = null;\n private isShutdown = false;\n private flushPromise: Promise<void> | null = null;\n private unloadHandler: (() => void) | null = null;\n private visibilityChangeHandler: (() => void) | null = null;\n\n constructor(config: KlimeConfig) {\n if (!config.writeKey) {\n throw new Error(\"writeKey is required\");\n }\n\n this.config = {\n writeKey: config.writeKey,\n endpoint: config.endpoint || DEFAULT_ENDPOINT,\n flushInterval: config.flushInterval ?? DEFAULT_FLUSH_INTERVAL,\n maxBatchSize: Math.min(\n config.maxBatchSize ?? DEFAULT_MAX_BATCH_SIZE,\n MAX_BATCH_SIZE\n ),\n maxQueueSize: config.maxQueueSize ?? DEFAULT_MAX_QUEUE_SIZE,\n retryMaxAttempts: config.retryMaxAttempts ?? DEFAULT_RETRY_MAX_ATTEMPTS,\n retryInitialDelay:\n config.retryInitialDelay ?? DEFAULT_RETRY_INITIAL_DELAY,\n autoFlushOnUnload: config.autoFlushOnUnload ?? true,\n logger: config.logger ?? createDefaultLogger(),\n onError: config.onError,\n onSuccess: config.onSuccess,\n };\n\n if (this.config.autoFlushOnUnload && typeof window !== \"undefined\") {\n this.unloadHandler = () => {\n this.flush();\n };\n window.addEventListener(\"beforeunload\", this.unloadHandler);\n window.addEventListener(\"pagehide\", this.unloadHandler);\n this.visibilityChangeHandler = () => {\n if (typeof document !== \"undefined\" && document.visibilityState === \"hidden\") {\n this.flush();\n }\n };\n document.addEventListener(\"visibilitychange\", this.visibilityChangeHandler);\n }\n\n this.scheduleFlush();\n }\n\n track(\n event: string,\n properties?: Record<string, any>,\n options?: TrackOptions\n ): void {\n if (this.isShutdown) {\n return;\n }\n\n const eventObj: Event = {\n type: \"track\",\n messageId: this.generateUUID(),\n event,\n timestamp: this.generateTimestamp(),\n properties: properties || {},\n context: this.getContext(),\n };\n\n if (options?.userId) {\n eventObj.userId = options.userId;\n }\n if (options?.groupId) {\n eventObj.groupId = options.groupId;\n }\n\n this.enqueue(eventObj);\n }\n\n identify(userId: string, traits?: Record<string, any>): void {\n if (this.isShutdown) {\n return;\n }\n\n const eventObj: Event = {\n type: \"identify\",\n messageId: this.generateUUID(),\n userId,\n timestamp: this.generateTimestamp(),\n traits: traits || {},\n context: this.getContext(),\n };\n\n this.enqueue(eventObj);\n }\n\n group(\n groupId: string,\n traits?: Record<string, any>,\n options?: TrackOptions\n ): void {\n if (this.isShutdown) {\n return;\n }\n\n const eventObj: Event = {\n type: \"group\",\n messageId: this.generateUUID(),\n groupId,\n timestamp: this.generateTimestamp(),\n traits: traits || {},\n context: this.getContext(),\n };\n\n if (options?.userId) {\n eventObj.userId = options.userId;\n }\n\n this.enqueue(eventObj);\n }\n\n /**\n * Track an event synchronously. Returns BatchResponse or throws SendError.\n */\n async trackSync(\n event: string,\n properties?: Record<string, any>,\n options?: TrackOptions\n ): Promise<BatchResponse> {\n if (this.isShutdown) {\n throw new SendError(\"Client is shutdown\", []);\n }\n\n const eventObj: Event = {\n type: \"track\",\n messageId: this.generateUUID(),\n event,\n timestamp: this.generateTimestamp(),\n properties: properties || {},\n context: this.getContext(),\n };\n\n if (options?.userId) {\n eventObj.userId = options.userId;\n }\n if (options?.groupId) {\n eventObj.groupId = options.groupId;\n }\n\n return this.sendSync([eventObj]);\n }\n\n /**\n * Identify a user synchronously. Returns BatchResponse or throws SendError.\n */\n async identifySync(\n userId: string,\n traits?: Record<string, any>\n ): Promise<BatchResponse> {\n if (this.isShutdown) {\n throw new SendError(\"Client is shutdown\", []);\n }\n\n const eventObj: Event = {\n type: \"identify\",\n messageId: this.generateUUID(),\n userId,\n timestamp: this.generateTimestamp(),\n traits: traits || {},\n context: this.getContext(),\n };\n\n return this.sendSync([eventObj]);\n }\n\n /**\n * Associate a user with a group synchronously. Returns BatchResponse or throws SendError.\n */\n async groupSync(\n groupId: string,\n traits?: Record<string, any>,\n options?: TrackOptions\n ): Promise<BatchResponse> {\n if (this.isShutdown) {\n throw new SendError(\"Client is shutdown\", []);\n }\n\n const eventObj: Event = {\n type: \"group\",\n messageId: this.generateUUID(),\n groupId,\n timestamp: this.generateTimestamp(),\n traits: traits || {},\n context: this.getContext(),\n };\n\n if (options?.userId) {\n eventObj.userId = options.userId;\n }\n\n return this.sendSync([eventObj]);\n }\n\n /**\n * Return the number of events currently in the queue.\n */\n getQueueSize(): number {\n return this.queue.length;\n }\n\n async flush(): Promise<void> {\n if (this.flushPromise) {\n return this.flushPromise;\n }\n\n this.flushPromise = this.doFlush();\n try {\n await this.flushPromise;\n } finally {\n this.flushPromise = null;\n }\n }\n\n async shutdown(): Promise<void> {\n if (this.isShutdown) {\n return;\n }\n\n this.isShutdown = true;\n\n if (this.unloadHandler && typeof window !== \"undefined\") {\n window.removeEventListener(\"beforeunload\", this.unloadHandler);\n window.removeEventListener(\"pagehide\", this.unloadHandler);\n }\n if (this.visibilityChangeHandler && typeof document !== \"undefined\") {\n document.removeEventListener(\"visibilitychange\", this.visibilityChangeHandler);\n }\n\n if (this.flushTimer) {\n clearTimeout(this.flushTimer);\n this.flushTimer = null;\n }\n\n await this.flush();\n }\n\n private enqueue(event: Event): void {\n // Check event size\n const eventSize = this.estimateEventSize(event);\n if (eventSize > MAX_EVENT_SIZE_BYTES) {\n this.config.logger.warn(\n `Event size (${eventSize} bytes) exceeds ${MAX_EVENT_SIZE_BYTES} bytes limit`\n );\n return;\n }\n\n // Drop oldest if queue is full\n if (this.queue.length >= this.config.maxQueueSize) {\n const dropped = this.queue.shift();\n this.config.logger.warn(`Queue full, dropping oldest event: ${dropped?.type}`);\n }\n\n this.queue.push(event);\n this.config.logger.debug(`Enqueued ${event.type} event, queue size: ${this.queue.length}`);\n\n // Check if we should flush immediately\n if (this.queue.length >= this.config.maxBatchSize) {\n this.flush();\n }\n }\n\n private async doFlush(): Promise<void> {\n if (this.queue.length === 0) {\n return;\n }\n\n // Clear the flush timer\n if (this.flushTimer) {\n clearTimeout(this.flushTimer);\n this.flushTimer = null;\n }\n\n // Process batches\n while (this.queue.length > 0) {\n const batch = this.extractBatch();\n if (batch.length === 0) {\n break;\n }\n\n await this.sendBatch(batch);\n }\n\n // Schedule next flush\n this.scheduleFlush();\n }\n\n private extractBatch(): Event[] {\n const batch: Event[] = [];\n let batchSize = 0;\n\n while (this.queue.length > 0 && batch.length < MAX_BATCH_SIZE) {\n const event = this.queue[0];\n const eventSize = this.estimateEventSize(event);\n\n // Check if adding this event would exceed batch size limit\n if (batchSize + eventSize > MAX_BATCH_SIZE_BYTES) {\n break;\n }\n\n batch.push(this.queue.shift()!);\n batchSize += eventSize;\n }\n\n return batch;\n }\n\n private async sendBatch(batch: Event[]): Promise<void> {\n if (batch.length === 0) {\n return;\n }\n\n this.config.logger.debug(`Sending batch of ${batch.length} events`);\n const result = await this.doSend(batch);\n\n if (result === null) {\n // Send failed after all retries\n const error = new Error(`Failed to send batch of ${batch.length} events after retries`);\n this.invokeOnError(error, batch);\n } else if (result.failed > 0 && result.errors) {\n this.config.logger.warn(\n `Batch partially failed. Accepted: ${result.accepted}, Failed: ${result.failed}`,\n result.errors\n );\n // Still invoke success callback since some events were accepted\n this.invokeOnSuccess(result);\n } else {\n this.config.logger.debug(`Batch sent successfully. Accepted: ${result.accepted}`);\n this.invokeOnSuccess(result);\n }\n }\n\n private async sendSync(events: Event[]): Promise<BatchResponse> {\n this.config.logger.debug(`Sending ${events.length} events synchronously`);\n const result = await this.doSend(events);\n\n if (result === null) {\n throw new SendError(`Failed to send ${events.length} events after retries`, events);\n }\n\n return result;\n }\n\n private async doSend(batch: Event[]): Promise<BatchResponse | null> {\n const request: BatchRequest = { batch };\n const requestUrl = `${this.config.endpoint}/v1/batch`;\n const body = JSON.stringify(request);\n const useKeepalive = body.length <= KEEPALIVE_MAX_BODY_BYTES;\n\n let attempt = 0;\n let delay = this.config.retryInitialDelay;\n\n while (attempt < this.config.retryMaxAttempts) {\n try {\n const response = await fetch(requestUrl, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n Authorization: `Bearer ${this.config.writeKey}`,\n },\n body,\n keepalive: useKeepalive,\n });\n\n const data: BatchResponse = await response.json();\n\n if (response.ok) {\n return data;\n }\n\n // Handle error responses\n if (response.status === 400 || response.status === 401) {\n // Permanent errors - don't retry\n this.config.logger.error(`Permanent error (${response.status}):`, data);\n return null;\n }\n\n // Transient errors - retry with backoff\n if (response.status === 429 || response.status === 503) {\n const retryAfter = response.headers.get(\"Retry-After\");\n if (retryAfter) {\n delay = parseInt(retryAfter, 10) * 1000;\n }\n\n attempt++;\n if (attempt < this.config.retryMaxAttempts) {\n this.config.logger.debug(`Retrying after ${delay}ms (attempt ${attempt})`);\n await this.sleep(delay);\n delay = Math.min(delay * 2, 16000); // Cap at 16s\n continue;\n }\n }\n\n // Other errors - retry\n attempt++;\n if (attempt < this.config.retryMaxAttempts) {\n this.config.logger.debug(`Retrying after ${delay}ms (attempt ${attempt})`);\n await this.sleep(delay);\n delay = Math.min(delay * 2, 16000);\n }\n } catch (error) {\n // Network errors - retry\n attempt++;\n if (attempt < this.config.retryMaxAttempts) {\n this.config.logger.debug(`Retrying after ${delay}ms (attempt ${attempt})`);\n await this.sleep(delay);\n delay = Math.min(delay * 2, 16000);\n } else {\n this.config.logger.error(\"Failed to send batch after retries:\", error);\n }\n }\n }\n\n return null;\n }\n\n private invokeOnError(error: Error, batch: Event[]): void {\n if (this.config.onError) {\n try {\n this.config.onError(error, batch);\n } catch (e) {\n this.config.logger.error(\"Error in onError callback:\", e);\n }\n }\n }\n\n private invokeOnSuccess(response: BatchResponse): void {\n if (this.config.onSuccess) {\n try {\n this.config.onSuccess(response);\n } catch (e) {\n this.config.logger.error(\"Error in onSuccess callback:\", e);\n }\n }\n }\n\n private scheduleFlush(): void {\n if (this.isShutdown || this.flushTimer) {\n return;\n }\n\n this.flushTimer = setTimeout(() => {\n this.flush();\n }, this.config.flushInterval);\n }\n\n private generateUUID(): string {\n if (typeof crypto !== \"undefined\" && crypto.randomUUID) {\n return crypto.randomUUID();\n }\n // Fallback for older browsers\n return \"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx\".replace(/[xy]/g, (c) => {\n const r = (Math.random() * 16) | 0;\n const v = c === \"x\" ? r : (r & 0x3) | 0x8;\n return v.toString(16);\n });\n }\n\n private generateTimestamp(): string {\n return new Date().toISOString();\n }\n\n private getContext(): EventContext {\n const context: EventContext = {\n library: {\n name: \"js-sdk\",\n version: SDK_VERSION,\n },\n };\n\n if (typeof navigator !== \"undefined\") {\n if (navigator.userAgent) {\n context.userAgent = navigator.userAgent;\n }\n if (navigator.language) {\n context.locale = navigator.language;\n }\n }\n\n if (typeof Intl !== \"undefined\" && Intl.DateTimeFormat) {\n try {\n const timezone = Intl.DateTimeFormat().resolvedOptions().timeZone;\n if (timezone) {\n context.timezone = timezone;\n }\n } catch (e) {\n // Ignore timezone errors\n }\n }\n\n return context;\n }\n\n private estimateEventSize(event: Event): number {\n // Rough estimate: JSON stringified size\n try {\n return JSON.stringify(event).length;\n } catch {\n // Fallback: rough estimate based on structure\n return 500; // Conservative estimate\n }\n }\n\n private sleep(ms: number): Promise<void> {\n return new Promise((resolve) => setTimeout(resolve, ms));\n }\n}\n","export interface Logger {\n debug(message: string, ...args: any[]): void;\n info(message: string, ...args: any[]): void;\n warn(message: string, ...args: any[]): void;\n error(message: string, ...args: any[]): void;\n}\n\nexport interface KlimeConfig {\n writeKey: string;\n endpoint?: string;\n flushInterval?: number; // milliseconds, default 2000\n maxBatchSize?: number; // default 20, max 100\n maxQueueSize?: number; // default 1000\n retryMaxAttempts?: number; // default 5\n retryInitialDelay?: number; // milliseconds, default 1000\n autoFlushOnUnload?: boolean; // default true\n logger?: Logger; // optional custom logger\n onError?: (error: Error, events: Event[]) => void; // callback for batch failures\n onSuccess?: (response: BatchResponse) => void; // callback for successful sends\n}\n\nexport interface TrackOptions {\n userId?: string;\n groupId?: string;\n}\n\nexport interface Event {\n type: 'track' | 'identify' | 'group';\n messageId: string;\n event?: string; // required for track\n userId?: string; // required for identify\n groupId?: string; // required for group\n timestamp: string; // ISO 8601\n properties?: Record<string, any>; // for track\n traits?: Record<string, any>; // for identify/group\n context?: EventContext;\n}\n\nexport interface EventContext {\n library?: {\n name: string;\n version: string;\n };\n userAgent?: string;\n locale?: string;\n timezone?: string;\n}\n\nexport interface BatchRequest {\n batch: Event[];\n}\n\nexport interface BatchResponse {\n status: string;\n accepted: number;\n failed: number;\n errors?: ValidationError[];\n}\n\nexport interface ValidationError {\n index: number;\n message: string;\n code: string;\n}\n\nexport class SendError extends Error {\n events: Event[];\n\n constructor(message: string, events: Event[]) {\n super(message);\n this.name = 'SendError';\n this.events = events;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACiEO,IAAM,YAAN,cAAwB,MAAM;AAAA,EAGnC,YAAY,SAAiB,QAAiB;AAC5C,UAAM,OAAO;AACb,SAAK,OAAO;AACZ,SAAK,SAAS;AAAA,EAChB;AACF;;;AD1DA,IAAM,mBAAmB;AACzB,IAAM,yBAAyB;AAC/B,IAAM,yBAAyB;AAC/B,IAAM,yBAAyB;AAC/B,IAAM,6BAA6B;AACnC,IAAM,8BAA8B;AACpC,IAAM,iBAAiB;AACvB,IAAM,uBAAuB,MAAM;AACnC,IAAM,uBAAuB,KAAK,OAAO;AAEzC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