@litemetrics/core 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/dist/index.cjs ADDED
@@ -0,0 +1,60 @@
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
+ COLLECT_PATH: () => COLLECT_PATH,
24
+ DEFAULT_BATCH_SIZE: () => DEFAULT_BATCH_SIZE,
25
+ DEFAULT_FLUSH_INTERVAL: () => DEFAULT_FLUSH_INTERVAL,
26
+ SESSION_TIMEOUT: () => SESSION_TIMEOUT,
27
+ STORAGE_KEY_LAST_ACTIVE: () => STORAGE_KEY_LAST_ACTIVE,
28
+ STORAGE_KEY_OPTOUT: () => STORAGE_KEY_OPTOUT,
29
+ STORAGE_KEY_QUEUE: () => STORAGE_KEY_QUEUE,
30
+ STORAGE_KEY_SESSION: () => STORAGE_KEY_SESSION,
31
+ STORAGE_KEY_USER: () => STORAGE_KEY_USER,
32
+ STORAGE_KEY_VISITOR: () => STORAGE_KEY_VISITOR
33
+ });
34
+ module.exports = __toCommonJS(index_exports);
35
+
36
+ // src/constants.ts
37
+ var DEFAULT_BATCH_SIZE = 10;
38
+ var DEFAULT_FLUSH_INTERVAL = 5e3;
39
+ var SESSION_TIMEOUT = 30 * 60 * 1e3;
40
+ var STORAGE_KEY_SESSION = "__litemetrics_sid";
41
+ var STORAGE_KEY_VISITOR = "__litemetrics_vid";
42
+ var STORAGE_KEY_QUEUE = "__litemetrics_q";
43
+ var STORAGE_KEY_OPTOUT = "__litemetrics_optout";
44
+ var STORAGE_KEY_USER = "__litemetrics_uid";
45
+ var STORAGE_KEY_LAST_ACTIVE = "__litemetrics_la";
46
+ var COLLECT_PATH = "/api/collect";
47
+ // Annotate the CommonJS export names for ESM import in node:
48
+ 0 && (module.exports = {
49
+ COLLECT_PATH,
50
+ DEFAULT_BATCH_SIZE,
51
+ DEFAULT_FLUSH_INTERVAL,
52
+ SESSION_TIMEOUT,
53
+ STORAGE_KEY_LAST_ACTIVE,
54
+ STORAGE_KEY_OPTOUT,
55
+ STORAGE_KEY_QUEUE,
56
+ STORAGE_KEY_SESSION,
57
+ STORAGE_KEY_USER,
58
+ STORAGE_KEY_VISITOR
59
+ });
60
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts","../src/constants.ts"],"sourcesContent":["export * from './types';\nexport * from './constants';\n","export const DEFAULT_BATCH_SIZE = 10;\nexport const DEFAULT_FLUSH_INTERVAL = 5000;\nexport const SESSION_TIMEOUT = 30 * 60 * 1000; // 30 minutes\nexport const STORAGE_KEY_SESSION = '__litemetrics_sid';\nexport const STORAGE_KEY_VISITOR = '__litemetrics_vid';\nexport const STORAGE_KEY_QUEUE = '__litemetrics_q';\nexport const STORAGE_KEY_OPTOUT = '__litemetrics_optout';\nexport const STORAGE_KEY_USER = '__litemetrics_uid';\nexport const STORAGE_KEY_LAST_ACTIVE = '__litemetrics_la';\nexport const COLLECT_PATH = '/api/collect';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAO,IAAM,qBAAqB;AAC3B,IAAM,yBAAyB;AAC/B,IAAM,kBAAkB,KAAK,KAAK;AAClC,IAAM,sBAAsB;AAC5B,IAAM,sBAAsB;AAC5B,IAAM,oBAAoB;AAC1B,IAAM,qBAAqB;AAC3B,IAAM,mBAAmB;AACzB,IAAM,0BAA0B;AAChC,IAAM,eAAe;","names":[]}
@@ -0,0 +1,280 @@
1
+ type EventType = 'pageview' | 'event' | 'identify';
2
+ interface BaseEvent {
3
+ type: EventType;
4
+ siteId: string;
5
+ timestamp: number;
6
+ sessionId: string;
7
+ visitorId: string;
8
+ }
9
+ interface PageviewEvent extends BaseEvent {
10
+ type: 'pageview';
11
+ url: string;
12
+ referrer?: string;
13
+ title?: string;
14
+ }
15
+ interface CustomEvent extends BaseEvent {
16
+ type: 'event';
17
+ name: string;
18
+ properties?: Record<string, unknown>;
19
+ }
20
+ interface IdentifyEvent extends BaseEvent {
21
+ type: 'identify';
22
+ userId: string;
23
+ traits?: Record<string, unknown>;
24
+ }
25
+ type LitemetricsEvent = PageviewEvent | CustomEvent | IdentifyEvent;
26
+ interface ConnectionInfo {
27
+ type?: string;
28
+ downlink?: number;
29
+ rtt?: number;
30
+ effectiveType?: string;
31
+ }
32
+ interface ClientContext {
33
+ screen?: {
34
+ width: number;
35
+ height: number;
36
+ };
37
+ language?: string;
38
+ timezone?: string;
39
+ connection?: ConnectionInfo;
40
+ utm?: UTMParams;
41
+ }
42
+ interface UTMParams {
43
+ source?: string;
44
+ medium?: string;
45
+ campaign?: string;
46
+ term?: string;
47
+ content?: string;
48
+ }
49
+ type ClientEvent = LitemetricsEvent & ClientContext;
50
+ interface GeoInfo {
51
+ country?: string;
52
+ city?: string;
53
+ region?: string;
54
+ }
55
+ interface DeviceInfo {
56
+ type: string;
57
+ browser: string;
58
+ os: string;
59
+ }
60
+ interface EnrichedEvent extends ClientContext {
61
+ type: EventType;
62
+ siteId: string;
63
+ timestamp: number;
64
+ sessionId: string;
65
+ visitorId: string;
66
+ url?: string;
67
+ referrer?: string;
68
+ title?: string;
69
+ name?: string;
70
+ properties?: Record<string, unknown>;
71
+ userId?: string;
72
+ traits?: Record<string, unknown>;
73
+ ip?: string;
74
+ geo?: GeoInfo;
75
+ device?: DeviceInfo;
76
+ }
77
+ interface CollectPayload {
78
+ events: ClientEvent[];
79
+ }
80
+ interface CollectResponse {
81
+ ok: boolean;
82
+ error?: string;
83
+ }
84
+ interface TrackerConfig {
85
+ siteId: string;
86
+ endpoint: string;
87
+ autoTrack?: boolean;
88
+ autoSpa?: boolean;
89
+ batchSize?: number;
90
+ flushInterval?: number;
91
+ respectDnt?: boolean;
92
+ debug?: boolean;
93
+ }
94
+ interface CollectorConfig {
95
+ db: DBConfig;
96
+ adminSecret?: string;
97
+ geoip?: boolean | GeoIPConfig;
98
+ cors?: CORSConfig;
99
+ trustProxy?: boolean;
100
+ }
101
+ interface DBConfig {
102
+ adapter?: 'clickhouse' | 'mongodb';
103
+ url: string;
104
+ }
105
+ interface GeoIPConfig {
106
+ dbPath?: string;
107
+ }
108
+ interface CORSConfig {
109
+ origins?: string[];
110
+ }
111
+ interface Site {
112
+ siteId: string;
113
+ secretKey: string;
114
+ name: string;
115
+ domain?: string;
116
+ allowedOrigins?: string[];
117
+ createdAt: string;
118
+ updatedAt: string;
119
+ }
120
+ interface CreateSiteRequest {
121
+ name: string;
122
+ domain?: string;
123
+ allowedOrigins?: string[];
124
+ }
125
+ interface UpdateSiteRequest {
126
+ name?: string;
127
+ domain?: string;
128
+ allowedOrigins?: string[];
129
+ }
130
+ interface DBAdapter {
131
+ init(): Promise<void>;
132
+ insertEvents(events: EnrichedEvent[]): Promise<void>;
133
+ query(q: QueryParams): Promise<QueryResult>;
134
+ queryTimeSeries(params: TimeSeriesParams): Promise<TimeSeriesResult>;
135
+ queryRetention(params: RetentionParams): Promise<RetentionResult>;
136
+ close(): Promise<void>;
137
+ listEvents(params: EventListParams): Promise<EventListResult>;
138
+ listUsers(params: UserListParams): Promise<UserListResult>;
139
+ getUserDetail(siteId: string, visitorId: string): Promise<UserDetail | null>;
140
+ getUserEvents(siteId: string, visitorId: string, params: EventListParams): Promise<EventListResult>;
141
+ createSite(data: CreateSiteRequest): Promise<Site>;
142
+ getSite(siteId: string): Promise<Site | null>;
143
+ getSiteBySecret(secretKey: string): Promise<Site | null>;
144
+ listSites(): Promise<Site[]>;
145
+ updateSite(siteId: string, data: UpdateSiteRequest): Promise<Site | null>;
146
+ deleteSite(siteId: string): Promise<boolean>;
147
+ regenerateSecret(siteId: string): Promise<Site | null>;
148
+ }
149
+ type Metric = 'pageviews' | 'visitors' | 'sessions' | 'events' | 'top_pages' | 'top_referrers' | 'top_countries' | 'top_cities' | 'top_events' | 'top_devices' | 'top_browsers' | 'top_os';
150
+ type Period = '1h' | '24h' | '7d' | '30d' | '90d' | 'custom';
151
+ interface QueryParams {
152
+ siteId: string;
153
+ metric: Metric;
154
+ period?: Period;
155
+ dateFrom?: string;
156
+ dateTo?: string;
157
+ filters?: Record<string, string>;
158
+ limit?: number;
159
+ compare?: boolean;
160
+ }
161
+ interface QueryResult {
162
+ metric: Metric;
163
+ period: Period;
164
+ data: QueryDataPoint[];
165
+ total: number;
166
+ previousTotal?: number;
167
+ changePercent?: number;
168
+ }
169
+ interface QueryDataPoint {
170
+ key: string;
171
+ value: number;
172
+ change?: number;
173
+ }
174
+ type Granularity = 'hour' | 'day' | 'week' | 'month';
175
+ interface TimeSeriesParams {
176
+ siteId: string;
177
+ metric: 'pageviews' | 'visitors' | 'sessions';
178
+ period?: Period;
179
+ dateFrom?: string;
180
+ dateTo?: string;
181
+ granularity?: Granularity;
182
+ filters?: Record<string, string>;
183
+ }
184
+ interface TimeSeriesResult {
185
+ metric: string;
186
+ granularity: Granularity;
187
+ data: TimeSeriesPoint[];
188
+ }
189
+ interface TimeSeriesPoint {
190
+ date: string;
191
+ value: number;
192
+ }
193
+ interface EventListParams {
194
+ siteId: string;
195
+ type?: EventType;
196
+ eventName?: string;
197
+ visitorId?: string;
198
+ userId?: string;
199
+ period?: Period;
200
+ dateFrom?: string;
201
+ dateTo?: string;
202
+ limit?: number;
203
+ offset?: number;
204
+ }
205
+ interface EventListItem {
206
+ id: string;
207
+ type: EventType;
208
+ timestamp: string;
209
+ visitorId: string;
210
+ sessionId: string;
211
+ url?: string;
212
+ referrer?: string;
213
+ title?: string;
214
+ name?: string;
215
+ properties?: Record<string, unknown>;
216
+ userId?: string;
217
+ traits?: Record<string, unknown>;
218
+ geo?: GeoInfo;
219
+ device?: DeviceInfo;
220
+ language?: string;
221
+ utm?: UTMParams;
222
+ }
223
+ interface EventListResult {
224
+ events: EventListItem[];
225
+ total: number;
226
+ limit: number;
227
+ offset: number;
228
+ }
229
+ interface UserListParams {
230
+ siteId: string;
231
+ search?: string;
232
+ limit?: number;
233
+ offset?: number;
234
+ }
235
+ interface UserDetail {
236
+ visitorId: string;
237
+ userId?: string;
238
+ traits?: Record<string, unknown>;
239
+ firstSeen: string;
240
+ lastSeen: string;
241
+ totalEvents: number;
242
+ totalPageviews: number;
243
+ totalSessions: number;
244
+ lastUrl?: string;
245
+ device?: DeviceInfo;
246
+ geo?: GeoInfo;
247
+ language?: string;
248
+ }
249
+ interface UserListResult {
250
+ users: UserDetail[];
251
+ total: number;
252
+ limit: number;
253
+ offset: number;
254
+ }
255
+ interface RetentionParams {
256
+ siteId: string;
257
+ period?: Period;
258
+ weeks?: number;
259
+ }
260
+ interface RetentionCohort {
261
+ week: string;
262
+ size: number;
263
+ retention: number[];
264
+ }
265
+ interface RetentionResult {
266
+ cohorts: RetentionCohort[];
267
+ }
268
+
269
+ declare const DEFAULT_BATCH_SIZE = 10;
270
+ declare const DEFAULT_FLUSH_INTERVAL = 5000;
271
+ declare const SESSION_TIMEOUT: number;
272
+ declare const STORAGE_KEY_SESSION = "__litemetrics_sid";
273
+ declare const STORAGE_KEY_VISITOR = "__litemetrics_vid";
274
+ declare const STORAGE_KEY_QUEUE = "__litemetrics_q";
275
+ declare const STORAGE_KEY_OPTOUT = "__litemetrics_optout";
276
+ declare const STORAGE_KEY_USER = "__litemetrics_uid";
277
+ declare const STORAGE_KEY_LAST_ACTIVE = "__litemetrics_la";
278
+ declare const COLLECT_PATH = "/api/collect";
279
+
280
+ export { type BaseEvent, COLLECT_PATH, type CORSConfig, type ClientContext, type ClientEvent, type CollectPayload, type CollectResponse, type CollectorConfig, type ConnectionInfo, type CreateSiteRequest, type CustomEvent, type DBAdapter, type DBConfig, DEFAULT_BATCH_SIZE, DEFAULT_FLUSH_INTERVAL, type DeviceInfo, type EnrichedEvent, type EventListItem, type EventListParams, type EventListResult, type EventType, type GeoIPConfig, type GeoInfo, type Granularity, type IdentifyEvent, type LitemetricsEvent, type Metric, type PageviewEvent, type Period, type QueryDataPoint, type QueryParams, type QueryResult, type RetentionCohort, type RetentionParams, type RetentionResult, SESSION_TIMEOUT, STORAGE_KEY_LAST_ACTIVE, STORAGE_KEY_OPTOUT, STORAGE_KEY_QUEUE, STORAGE_KEY_SESSION, STORAGE_KEY_USER, STORAGE_KEY_VISITOR, type Site, type TimeSeriesParams, type TimeSeriesPoint, type TimeSeriesResult, type TrackerConfig, type UTMParams, type UpdateSiteRequest, type UserDetail, type UserListParams, type UserListResult };
@@ -0,0 +1,280 @@
1
+ type EventType = 'pageview' | 'event' | 'identify';
2
+ interface BaseEvent {
3
+ type: EventType;
4
+ siteId: string;
5
+ timestamp: number;
6
+ sessionId: string;
7
+ visitorId: string;
8
+ }
9
+ interface PageviewEvent extends BaseEvent {
10
+ type: 'pageview';
11
+ url: string;
12
+ referrer?: string;
13
+ title?: string;
14
+ }
15
+ interface CustomEvent extends BaseEvent {
16
+ type: 'event';
17
+ name: string;
18
+ properties?: Record<string, unknown>;
19
+ }
20
+ interface IdentifyEvent extends BaseEvent {
21
+ type: 'identify';
22
+ userId: string;
23
+ traits?: Record<string, unknown>;
24
+ }
25
+ type LitemetricsEvent = PageviewEvent | CustomEvent | IdentifyEvent;
26
+ interface ConnectionInfo {
27
+ type?: string;
28
+ downlink?: number;
29
+ rtt?: number;
30
+ effectiveType?: string;
31
+ }
32
+ interface ClientContext {
33
+ screen?: {
34
+ width: number;
35
+ height: number;
36
+ };
37
+ language?: string;
38
+ timezone?: string;
39
+ connection?: ConnectionInfo;
40
+ utm?: UTMParams;
41
+ }
42
+ interface UTMParams {
43
+ source?: string;
44
+ medium?: string;
45
+ campaign?: string;
46
+ term?: string;
47
+ content?: string;
48
+ }
49
+ type ClientEvent = LitemetricsEvent & ClientContext;
50
+ interface GeoInfo {
51
+ country?: string;
52
+ city?: string;
53
+ region?: string;
54
+ }
55
+ interface DeviceInfo {
56
+ type: string;
57
+ browser: string;
58
+ os: string;
59
+ }
60
+ interface EnrichedEvent extends ClientContext {
61
+ type: EventType;
62
+ siteId: string;
63
+ timestamp: number;
64
+ sessionId: string;
65
+ visitorId: string;
66
+ url?: string;
67
+ referrer?: string;
68
+ title?: string;
69
+ name?: string;
70
+ properties?: Record<string, unknown>;
71
+ userId?: string;
72
+ traits?: Record<string, unknown>;
73
+ ip?: string;
74
+ geo?: GeoInfo;
75
+ device?: DeviceInfo;
76
+ }
77
+ interface CollectPayload {
78
+ events: ClientEvent[];
79
+ }
80
+ interface CollectResponse {
81
+ ok: boolean;
82
+ error?: string;
83
+ }
84
+ interface TrackerConfig {
85
+ siteId: string;
86
+ endpoint: string;
87
+ autoTrack?: boolean;
88
+ autoSpa?: boolean;
89
+ batchSize?: number;
90
+ flushInterval?: number;
91
+ respectDnt?: boolean;
92
+ debug?: boolean;
93
+ }
94
+ interface CollectorConfig {
95
+ db: DBConfig;
96
+ adminSecret?: string;
97
+ geoip?: boolean | GeoIPConfig;
98
+ cors?: CORSConfig;
99
+ trustProxy?: boolean;
100
+ }
101
+ interface DBConfig {
102
+ adapter?: 'clickhouse' | 'mongodb';
103
+ url: string;
104
+ }
105
+ interface GeoIPConfig {
106
+ dbPath?: string;
107
+ }
108
+ interface CORSConfig {
109
+ origins?: string[];
110
+ }
111
+ interface Site {
112
+ siteId: string;
113
+ secretKey: string;
114
+ name: string;
115
+ domain?: string;
116
+ allowedOrigins?: string[];
117
+ createdAt: string;
118
+ updatedAt: string;
119
+ }
120
+ interface CreateSiteRequest {
121
+ name: string;
122
+ domain?: string;
123
+ allowedOrigins?: string[];
124
+ }
125
+ interface UpdateSiteRequest {
126
+ name?: string;
127
+ domain?: string;
128
+ allowedOrigins?: string[];
129
+ }
130
+ interface DBAdapter {
131
+ init(): Promise<void>;
132
+ insertEvents(events: EnrichedEvent[]): Promise<void>;
133
+ query(q: QueryParams): Promise<QueryResult>;
134
+ queryTimeSeries(params: TimeSeriesParams): Promise<TimeSeriesResult>;
135
+ queryRetention(params: RetentionParams): Promise<RetentionResult>;
136
+ close(): Promise<void>;
137
+ listEvents(params: EventListParams): Promise<EventListResult>;
138
+ listUsers(params: UserListParams): Promise<UserListResult>;
139
+ getUserDetail(siteId: string, visitorId: string): Promise<UserDetail | null>;
140
+ getUserEvents(siteId: string, visitorId: string, params: EventListParams): Promise<EventListResult>;
141
+ createSite(data: CreateSiteRequest): Promise<Site>;
142
+ getSite(siteId: string): Promise<Site | null>;
143
+ getSiteBySecret(secretKey: string): Promise<Site | null>;
144
+ listSites(): Promise<Site[]>;
145
+ updateSite(siteId: string, data: UpdateSiteRequest): Promise<Site | null>;
146
+ deleteSite(siteId: string): Promise<boolean>;
147
+ regenerateSecret(siteId: string): Promise<Site | null>;
148
+ }
149
+ type Metric = 'pageviews' | 'visitors' | 'sessions' | 'events' | 'top_pages' | 'top_referrers' | 'top_countries' | 'top_cities' | 'top_events' | 'top_devices' | 'top_browsers' | 'top_os';
150
+ type Period = '1h' | '24h' | '7d' | '30d' | '90d' | 'custom';
151
+ interface QueryParams {
152
+ siteId: string;
153
+ metric: Metric;
154
+ period?: Period;
155
+ dateFrom?: string;
156
+ dateTo?: string;
157
+ filters?: Record<string, string>;
158
+ limit?: number;
159
+ compare?: boolean;
160
+ }
161
+ interface QueryResult {
162
+ metric: Metric;
163
+ period: Period;
164
+ data: QueryDataPoint[];
165
+ total: number;
166
+ previousTotal?: number;
167
+ changePercent?: number;
168
+ }
169
+ interface QueryDataPoint {
170
+ key: string;
171
+ value: number;
172
+ change?: number;
173
+ }
174
+ type Granularity = 'hour' | 'day' | 'week' | 'month';
175
+ interface TimeSeriesParams {
176
+ siteId: string;
177
+ metric: 'pageviews' | 'visitors' | 'sessions';
178
+ period?: Period;
179
+ dateFrom?: string;
180
+ dateTo?: string;
181
+ granularity?: Granularity;
182
+ filters?: Record<string, string>;
183
+ }
184
+ interface TimeSeriesResult {
185
+ metric: string;
186
+ granularity: Granularity;
187
+ data: TimeSeriesPoint[];
188
+ }
189
+ interface TimeSeriesPoint {
190
+ date: string;
191
+ value: number;
192
+ }
193
+ interface EventListParams {
194
+ siteId: string;
195
+ type?: EventType;
196
+ eventName?: string;
197
+ visitorId?: string;
198
+ userId?: string;
199
+ period?: Period;
200
+ dateFrom?: string;
201
+ dateTo?: string;
202
+ limit?: number;
203
+ offset?: number;
204
+ }
205
+ interface EventListItem {
206
+ id: string;
207
+ type: EventType;
208
+ timestamp: string;
209
+ visitorId: string;
210
+ sessionId: string;
211
+ url?: string;
212
+ referrer?: string;
213
+ title?: string;
214
+ name?: string;
215
+ properties?: Record<string, unknown>;
216
+ userId?: string;
217
+ traits?: Record<string, unknown>;
218
+ geo?: GeoInfo;
219
+ device?: DeviceInfo;
220
+ language?: string;
221
+ utm?: UTMParams;
222
+ }
223
+ interface EventListResult {
224
+ events: EventListItem[];
225
+ total: number;
226
+ limit: number;
227
+ offset: number;
228
+ }
229
+ interface UserListParams {
230
+ siteId: string;
231
+ search?: string;
232
+ limit?: number;
233
+ offset?: number;
234
+ }
235
+ interface UserDetail {
236
+ visitorId: string;
237
+ userId?: string;
238
+ traits?: Record<string, unknown>;
239
+ firstSeen: string;
240
+ lastSeen: string;
241
+ totalEvents: number;
242
+ totalPageviews: number;
243
+ totalSessions: number;
244
+ lastUrl?: string;
245
+ device?: DeviceInfo;
246
+ geo?: GeoInfo;
247
+ language?: string;
248
+ }
249
+ interface UserListResult {
250
+ users: UserDetail[];
251
+ total: number;
252
+ limit: number;
253
+ offset: number;
254
+ }
255
+ interface RetentionParams {
256
+ siteId: string;
257
+ period?: Period;
258
+ weeks?: number;
259
+ }
260
+ interface RetentionCohort {
261
+ week: string;
262
+ size: number;
263
+ retention: number[];
264
+ }
265
+ interface RetentionResult {
266
+ cohorts: RetentionCohort[];
267
+ }
268
+
269
+ declare const DEFAULT_BATCH_SIZE = 10;
270
+ declare const DEFAULT_FLUSH_INTERVAL = 5000;
271
+ declare const SESSION_TIMEOUT: number;
272
+ declare const STORAGE_KEY_SESSION = "__litemetrics_sid";
273
+ declare const STORAGE_KEY_VISITOR = "__litemetrics_vid";
274
+ declare const STORAGE_KEY_QUEUE = "__litemetrics_q";
275
+ declare const STORAGE_KEY_OPTOUT = "__litemetrics_optout";
276
+ declare const STORAGE_KEY_USER = "__litemetrics_uid";
277
+ declare const STORAGE_KEY_LAST_ACTIVE = "__litemetrics_la";
278
+ declare const COLLECT_PATH = "/api/collect";
279
+
280
+ export { type BaseEvent, COLLECT_PATH, type CORSConfig, type ClientContext, type ClientEvent, type CollectPayload, type CollectResponse, type CollectorConfig, type ConnectionInfo, type CreateSiteRequest, type CustomEvent, type DBAdapter, type DBConfig, DEFAULT_BATCH_SIZE, DEFAULT_FLUSH_INTERVAL, type DeviceInfo, type EnrichedEvent, type EventListItem, type EventListParams, type EventListResult, type EventType, type GeoIPConfig, type GeoInfo, type Granularity, type IdentifyEvent, type LitemetricsEvent, type Metric, type PageviewEvent, type Period, type QueryDataPoint, type QueryParams, type QueryResult, type RetentionCohort, type RetentionParams, type RetentionResult, SESSION_TIMEOUT, STORAGE_KEY_LAST_ACTIVE, STORAGE_KEY_OPTOUT, STORAGE_KEY_QUEUE, STORAGE_KEY_SESSION, STORAGE_KEY_USER, STORAGE_KEY_VISITOR, type Site, type TimeSeriesParams, type TimeSeriesPoint, type TimeSeriesResult, type TrackerConfig, type UTMParams, type UpdateSiteRequest, type UserDetail, type UserListParams, type UserListResult };
package/dist/index.js ADDED
@@ -0,0 +1,24 @@
1
+ // src/constants.ts
2
+ var DEFAULT_BATCH_SIZE = 10;
3
+ var DEFAULT_FLUSH_INTERVAL = 5e3;
4
+ var SESSION_TIMEOUT = 30 * 60 * 1e3;
5
+ var STORAGE_KEY_SESSION = "__litemetrics_sid";
6
+ var STORAGE_KEY_VISITOR = "__litemetrics_vid";
7
+ var STORAGE_KEY_QUEUE = "__litemetrics_q";
8
+ var STORAGE_KEY_OPTOUT = "__litemetrics_optout";
9
+ var STORAGE_KEY_USER = "__litemetrics_uid";
10
+ var STORAGE_KEY_LAST_ACTIVE = "__litemetrics_la";
11
+ var COLLECT_PATH = "/api/collect";
12
+ export {
13
+ COLLECT_PATH,
14
+ DEFAULT_BATCH_SIZE,
15
+ DEFAULT_FLUSH_INTERVAL,
16
+ SESSION_TIMEOUT,
17
+ STORAGE_KEY_LAST_ACTIVE,
18
+ STORAGE_KEY_OPTOUT,
19
+ STORAGE_KEY_QUEUE,
20
+ STORAGE_KEY_SESSION,
21
+ STORAGE_KEY_USER,
22
+ STORAGE_KEY_VISITOR
23
+ };
24
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/constants.ts"],"sourcesContent":["export const DEFAULT_BATCH_SIZE = 10;\nexport const DEFAULT_FLUSH_INTERVAL = 5000;\nexport const SESSION_TIMEOUT = 30 * 60 * 1000; // 30 minutes\nexport const STORAGE_KEY_SESSION = '__litemetrics_sid';\nexport const STORAGE_KEY_VISITOR = '__litemetrics_vid';\nexport const STORAGE_KEY_QUEUE = '__litemetrics_q';\nexport const STORAGE_KEY_OPTOUT = '__litemetrics_optout';\nexport const STORAGE_KEY_USER = '__litemetrics_uid';\nexport const STORAGE_KEY_LAST_ACTIVE = '__litemetrics_la';\nexport const COLLECT_PATH = '/api/collect';\n"],"mappings":";AAAO,IAAM,qBAAqB;AAC3B,IAAM,yBAAyB;AAC/B,IAAM,kBAAkB,KAAK,KAAK;AAClC,IAAM,sBAAsB;AAC5B,IAAM,sBAAsB;AAC5B,IAAM,oBAAoB;AAC1B,IAAM,qBAAqB;AAC3B,IAAM,mBAAmB;AACzB,IAAM,0BAA0B;AAChC,IAAM,eAAe;","names":[]}
package/package.json ADDED
@@ -0,0 +1,38 @@
1
+ {
2
+ "name": "@litemetrics/core",
3
+ "version": "0.1.0",
4
+ "description": "Shared types and utilities for Litemetrics analytics SDK",
5
+ "license": "MIT",
6
+ "author": "Metehan Kurucu",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/metehankurucu/litemetrics",
10
+ "directory": "packages/core"
11
+ },
12
+ "keywords": ["analytics", "tracking", "litemetrics", "types"],
13
+ "type": "module",
14
+ "main": "./dist/index.cjs",
15
+ "module": "./dist/index.js",
16
+ "types": "./dist/index.d.ts",
17
+ "exports": {
18
+ ".": {
19
+ "types": "./dist/index.d.ts",
20
+ "import": "./dist/index.js",
21
+ "require": "./dist/index.cjs"
22
+ }
23
+ },
24
+ "files": ["dist"],
25
+ "publishConfig": {
26
+ "access": "public"
27
+ },
28
+ "scripts": {
29
+ "build": "tsup",
30
+ "dev": "tsup --watch",
31
+ "typecheck": "tsc --noEmit",
32
+ "clean": "rm -rf dist"
33
+ },
34
+ "devDependencies": {
35
+ "tsup": "^8",
36
+ "typescript": "^5.7"
37
+ }
38
+ }