@logludo/sdk 0.0.0-stage → 1.0.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.
@@ -0,0 +1,373 @@
1
+ export type LogLevel = "silent" | "errors" | "info" | "verbose";
2
+ export type EventCategory = "session_start" | "session_end" | "error" | "progression" | "monetization" | "gameplay" | "design" | "performance";
3
+ export type AggregateType = "sum" | "average" | "frequency";
4
+ export interface ScenelyticsPayload {
5
+ x?: number;
6
+ y?: number;
7
+ endX?: number;
8
+ endY?: number;
9
+ direction?: number;
10
+ angle?: number;
11
+ color?: string;
12
+ shape?: string;
13
+ type?: string;
14
+ pointType?: string;
15
+ track_id?: TrackTarget;
16
+ trackId?: TrackTarget;
17
+ link_id?: string;
18
+ linkId?: string;
19
+ link_scope?: string;
20
+ linkScope?: string;
21
+ recent_path?: string;
22
+ [key: string]: unknown;
23
+ }
24
+ export interface EventPayload {
25
+ action?: string;
26
+ room_name?: string;
27
+ scene_name?: string;
28
+ x?: number;
29
+ y?: number;
30
+ endX?: number;
31
+ endY?: number;
32
+ track_id?: TrackTarget;
33
+ trackId?: TrackTarget;
34
+ link_id?: string;
35
+ linkId?: string;
36
+ link_scope?: string;
37
+ linkScope?: string;
38
+ scenelytics?: ScenelyticsPayload;
39
+ [key: string]: unknown;
40
+ }
41
+ export interface SpatialObjectLike {
42
+ x?: number;
43
+ y?: number;
44
+ position?: {
45
+ x?: number;
46
+ y?: number;
47
+ };
48
+ id?: string | number;
49
+ name?: string;
50
+ }
51
+ export type TrackTarget = string | SpatialObjectLike;
52
+ export interface LogLudoOptions {
53
+ /** Your LogLudo Project Identifier (Game ID). */
54
+ gameId?: string;
55
+ /** Alias for `gameId`. */
56
+ game_ID?: string;
57
+ /** Ingestion API base URL. Defaults to `"https://api.logludo.com/v0"`. */
58
+ apiUrl?: string;
59
+ /** Alias for `apiUrl`. */
60
+ api_url?: string;
61
+ /** Your game's release version string (e.g. `"1.2.0"`). Defaults to `"1.0.0"`. */
62
+ gameVersion?: string;
63
+ /** Alias for `gameVersion`. */
64
+ appVersion?: string;
65
+ /** Optional explicit framework name (e.g. `"Phaser"`, `"PixiJS"`, `"Three.js"`). */
66
+ framework?: string;
67
+ /** Override dev/debug build detection (`true` -> `"run"`, `false` -> `"build"`). */
68
+ debug?: boolean;
69
+ /** Explicitly set `"run"` (dev) or `"build"` (release). */
70
+ buildType?: "run" | "build";
71
+ /** Console logging verbosity. Defaults to `"info"` in dev, `"errors"` in prod. */
72
+ logLevel?: LogLevel;
73
+ /** Alias for `logLevel`. */
74
+ log_level?: LogLevel;
75
+ /** Automatically attach global `error` and `unhandledrejection` handlers. Defaults to `true`. */
76
+ captureCrashes?: boolean;
77
+ /** Alias for `captureCrashes`. */
78
+ capture_crashes?: boolean;
79
+ /** Automatically sample FPS via `requestAnimationFrame` and emit `performance` pings. Defaults to `true`. */
80
+ autoPerformance?: boolean;
81
+ /** Delay in ms after entering a scene before sending a performance ping. Defaults to `10000`. */
82
+ performanceDelayMs?: number;
83
+ /** Optional repeating performance ping interval in ms (`0` = once per scene). Defaults to `0`. */
84
+ performanceIntervalMs?: number;
85
+ /** Enable SceneLytics dev capture hotkeys (`Ctrl+Shift+F9`). Defaults to `true`. */
86
+ captureHotkeysEnabled?: boolean;
87
+ /** Require `Ctrl+Shift` modifier with `F9` for SceneLytics capture. Defaults to `true`. */
88
+ captureRequireModifier?: boolean;
89
+ /** Optional canvas element, CSS selector, or resolver function used by `captureScene()`. */
90
+ canvas?: HTMLCanvasElement | string | (() => HTMLCanvasElement | null);
91
+ /** Initial scene/level name emitted on boot. */
92
+ initialScene?: string;
93
+ /** Automatically flush buffered events on interval, critical events, and unload. Defaults to `true`. */
94
+ autoFlush?: boolean;
95
+ /** Event buffer threshold before auto-flushing. Defaults to `4` in browser, `10` otherwise. */
96
+ batchLimit?: number;
97
+ /** Periodic flush interval in ms. Defaults to `2000` in dev, `5000` in production web. */
98
+ flushIntervalMs?: number;
99
+ /** Canonical duplicate suppression window in ms. Defaults to `2000`. */
100
+ dedupWindowMs?: number;
101
+ /** Local fallback percentage (0-100) for `experiment()` before server flags load. Defaults to `50`. */
102
+ defaultExperimentPercentage?: number;
103
+ /** Flush queued events automatically whenever `enterScene()` changes scenes. Defaults to `false`. */
104
+ autoFlushOnSceneChange?: boolean;
105
+ /** Optional extra fields merged into the automatic `session_start` event. */
106
+ sessionStartPayload?: Record<string, unknown>;
107
+ /** Optional authenticated/explicit player identifier. */
108
+ userId?: string;
109
+ /** Custom key prefix for localStorage persistence. Defaults to `"logludo"`. */
110
+ storagePrefix?: string;
111
+ /** Custom spatial origin anchor X offset. Defaults to `0`. */
112
+ anchorX?: number;
113
+ /** Custom spatial origin anchor Y offset. Defaults to `0`. */
114
+ anchorY?: number;
115
+ }
116
+ export interface CaptureSceneOptions {
117
+ sceneName?: string;
118
+ canvas?: HTMLCanvasElement | string;
119
+ tileSize?: number;
120
+ waitForRender?: boolean;
121
+ }
122
+ export interface PhaserAttachOptions {
123
+ gameVersion?: string;
124
+ trackScenes?: boolean;
125
+ autoStartInitialScene?: boolean;
126
+ }
127
+ export interface TelemetryEnvelope {
128
+ game_id: string;
129
+ game_version: string;
130
+ session_id: string;
131
+ event_name: string;
132
+ payload: Record<string, unknown>;
133
+ }
134
+ export interface ExperimentsResponse {
135
+ success: boolean;
136
+ game_id?: string;
137
+ experiments: string[];
138
+ flags: Record<string, boolean>;
139
+ error?: string;
140
+ }
141
+ export interface AggregateFrequencyItem {
142
+ item: string;
143
+ count: number;
144
+ }
145
+ export type AggregateValue = number | AggregateFrequencyItem[];
146
+
147
+ /**
148
+ * Formats a coordinate rounded to 1 decimal place without trailing `.0`.
149
+ */
150
+ export declare function formatCoord(val: number): string;
151
+ /**
152
+ * Offsets coordinates by anchor `(ax, ay)`, deduplicates stationary points (<0.75px),
153
+ * simplifies collinear segments using iterative Ramer-Douglas-Peucker (1.5px tolerance),
154
+ * and encodes into `"x0,y0;x1,y1;..."` compact format compatible with LogLudo SceneLytics.
155
+ */
156
+ export declare function minifyPath(rawPath: ReadonlyArray<readonly [number, number]>, ax?: number, ay?: number, curX?: number, curY?: number, maxPoints?: number): string;
157
+
158
+ export interface KeyValueStore {
159
+ getItem(key: string): string | null;
160
+ setItem(key: string, value: string): void;
161
+ removeItem(key: string): void;
162
+ }
163
+ /**
164
+ * Creates a resilient storage adapter backed by `window.localStorage` when available,
165
+ * transparently falling back to an isolated in-memory Map in Node/SSR/sandboxed environments.
166
+ */
167
+ export declare function createSafeStorage(): KeyValueStore;
168
+
169
+ export interface EnvironmentInfo {
170
+ platform: string;
171
+ clientType: string;
172
+ osInfo: string;
173
+ deviceModel: string;
174
+ domain: string;
175
+ url: string;
176
+ }
177
+ export declare function detectDevMode(explicitDebug?: boolean, explicitBuildType?: "run" | "build"): boolean;
178
+ export declare function detectEnvironment(): EnvironmentInfo;
179
+ export declare function detectFramework(explicitFramework?: string): string;
180
+
181
+ export interface CapturePayload {
182
+ game_id: string;
183
+ game_version: string;
184
+ room_name: string;
185
+ image_base64?: string;
186
+ tile_x?: number;
187
+ tile_y?: number;
188
+ manifest?: {
189
+ width: number;
190
+ height: number;
191
+ tileSize: number;
192
+ columns: number;
193
+ rows: number;
194
+ };
195
+ }
196
+ export declare function resolveTargetCanvas(explicit?: HTMLCanvasElement | string | (() => HTMLCanvasElement | null)): HTMLCanvasElement | null;
197
+ export declare function captureAndUploadCanvas(params: {
198
+ canvas: HTMLCanvasElement;
199
+ apiUrl: string;
200
+ gameId: string;
201
+ gameVersion: string;
202
+ sceneName: string;
203
+ tileSize?: number;
204
+ }): Promise<boolean>;
205
+
206
+ export declare const SDK_VERSION = "js-1.0.0";
207
+ export declare const DEFAULT_API_URL = "https://api.logludo.com/v0";
208
+ export declare const GAME_ID_PLACEHOLDER = "__LOGLUDO_INJECT_GAME_ID_HERE__";
209
+ export declare class LogLudoClient {
210
+ initialized: boolean;
211
+ sessionId: string;
212
+ deviceId: string;
213
+ bucket: number;
214
+ daysSinceInstall: number;
215
+ sessionCount: number;
216
+ activeMask: number;
217
+ firstOpenDate: number;
218
+ installTime: number;
219
+ isFirstSessionToday: boolean;
220
+ isDev: boolean;
221
+ framework: string;
222
+ private _options;
223
+ private _storage;
224
+ private _completedFunnelSteps;
225
+ private _completedFunnelDropoffs;
226
+ private _eventBuffer;
227
+ private _bufferRaws;
228
+ private _inFlightBatchCount;
229
+ private _isFlushing;
230
+ private _flushQueued;
231
+ private _flushQueuedForce;
232
+ private _offlineDirty;
233
+ private _retryAfterTime;
234
+ private _retryBackoffMs;
235
+ private _recentEventHistory;
236
+ private _dedupHistoryLimit;
237
+ private _dedupWarnedAt;
238
+ private _frame;
239
+ private _spamTracker;
240
+ private _pathCallTracker;
241
+ private _rateWarnedAt;
242
+ private _eventsThisSecond;
243
+ private _lastEventSecond;
244
+ private _lastFlushTime;
245
+ private _gameIdWarned;
246
+ private _activeExperiments;
247
+ private _experimentFlags;
248
+ private _experimentsLoaded;
249
+ private _experimentReadyCallbacks;
250
+ private _experimentWarned;
251
+ private _expTimeoutHandle;
252
+ private _trackedPaths;
253
+ private _targetKeyMap;
254
+ private _targetKeySeq;
255
+ private _activeLinks;
256
+ private _linkSeq;
257
+ private _aggregates;
258
+ private _sessionStartTimeMs;
259
+ private _currentSceneName;
260
+ private _sceneEnterTimeMs;
261
+ private _scenePingSent;
262
+ private _lastScenePingMs;
263
+ private _sessionEnded;
264
+ private _fpsSamples;
265
+ private _lastRafTime;
266
+ private _rafId;
267
+ private _flushTimer;
268
+ private _offlineSaveTimer;
269
+ private _cleanupListeners;
270
+ private _userTraits;
271
+ private _explicitFlushInterval;
272
+ constructor(initialOptions?: LogLudoOptions);
273
+ private _logRank;
274
+ private _log;
275
+ private _storageKey;
276
+ private _applyOptions;
277
+ configure(options: LogLudoOptions): this;
278
+ init(options?: LogLudoOptions): this;
279
+ private _loadOfflineBuffer;
280
+ private _loadOrCreateDeviceData;
281
+ private _generateDeviceId;
282
+ saveDeviceData(): void;
283
+ saveOffline(): void;
284
+ private _loadCachedExperiments;
285
+ private _flushPendingCrashFromStorage;
286
+ private _attachBrowserListeners;
287
+ private _detachListeners;
288
+ private _startTimers;
289
+ private _stopTimers;
290
+ private _ensureRafLoop;
291
+ private _emitPerformancePing;
292
+ enterScene(sceneName: string): this;
293
+ enter_scene(sceneName: string): this;
294
+ setScene(sceneName: string): this;
295
+ set_scene(sceneName: string): this;
296
+ identify(userId: string, traits?: Record<string, unknown>): this;
297
+ isExperimentsReady(): boolean;
298
+ is_experiments_ready(): boolean;
299
+ private _hashExperimentBucket;
300
+ private _flushExperimentCallbacks;
301
+ whenExperimentsReady(callback: () => void, timeoutMs?: number): void;
302
+ when_experiments_ready(callback: () => void, timeoutMs?: number): void;
303
+ experiment(name: string, defaultOrPct?: boolean | number, fallbackPct?: number): boolean;
304
+ fetchExperiments(): Promise<void>;
305
+ private _retroactivelyTagBufferedExperiments;
306
+ private _attachExperimentContext;
307
+ private _resolveTrackKey;
308
+ trackPath(target: TrackTarget, maxLength?: number): this;
309
+ track_path(target: TrackTarget, maxLength?: number): this;
310
+ samplePath(target: TrackTarget, x: number, y: number): this;
311
+ sample_path(target: TrackTarget, x: number, y: number): this;
312
+ stopTrackingPath(target: TrackTarget): this;
313
+ stop_tracking_path(target: TrackTarget): this;
314
+ startLink(scope?: string): string;
315
+ start_link(scope?: string): string;
316
+ getLink(scope?: string): string | undefined;
317
+ get_link(scope?: string): string | undefined;
318
+ clearLink(scope?: string): void;
319
+ clear_link(scope?: string): void;
320
+ private _formatAggregate;
321
+ aggregateAdd(name: string, value: number | string, type?: AggregateType): this;
322
+ aggregate_add(name: string, value: number | string, type?: AggregateType): this;
323
+ aggregatePop(name: string): AggregateValue | undefined;
324
+ aggregate_pop(name: string): AggregateValue | undefined;
325
+ aggregateGetAll(pop?: boolean): Record<string, AggregateValue>;
326
+ aggregate_get_all(pop?: boolean): Record<string, AggregateValue>;
327
+ funnelStep(stepId: string, payload?: EventPayload): boolean;
328
+ funnel_step(stepId: string, payload?: EventPayload): boolean;
329
+ funnelDropoff(stepId: string, reason?: string, payload?: EventPayload): boolean;
330
+ funnel_dropoff(stepId: string, reason?: string, payload?: EventPayload): boolean;
331
+ private _purgeUnflushedSpam;
332
+ private _checkStepSpam;
333
+ sendEvent(name: EventCategory | (string & {}), payload?: EventPayload): boolean;
334
+ send_event(name: EventCategory | (string & {}), payload?: EventPayload): boolean;
335
+ flush(force?: boolean, useKeepalive?: boolean): Promise<boolean>;
336
+ flushEvents(force?: boolean): Promise<boolean>;
337
+ flush_events(force?: boolean): Promise<boolean>;
338
+ private _markFlushFailed;
339
+ private _clearPending;
340
+ handleException(err: {
341
+ message?: string;
342
+ stack?: string;
343
+ } | Error | unknown, extra?: {
344
+ action?: string;
345
+ severity?: string;
346
+ currentScene?: string;
347
+ }): void;
348
+ handle_exception(err: {
349
+ message?: string;
350
+ stack?: string;
351
+ } | Error | unknown, extra?: {
352
+ action?: string;
353
+ severity?: string;
354
+ currentScene?: string;
355
+ }): void;
356
+ private _endSession;
357
+ captureScene(sceneNameOrOptions?: string | CaptureSceneOptions, maybeOptions?: CaptureSceneOptions): Promise<boolean>;
358
+ capture_room(sceneNameOrOptions?: string | CaptureSceneOptions, maybeOptions?: CaptureSceneOptions): Promise<boolean>;
359
+ /**
360
+ * Zero-dependency adapter for Phaser 3 (`Phaser.Game`).
361
+ * Automatically attaches canvas capture, version metadata, and Phaser scene transitions.
362
+ */
363
+ attachPhaser(phaserGame: any, options?: PhaserAttachOptions): () => void;
364
+ attach_phaser(phaserGame: any, options?: PhaserAttachOptions): () => void;
365
+ getQueuedEventCount(): number;
366
+ /** Current periodic flush cadence in milliseconds. */
367
+ getFlushIntervalMs(): number;
368
+ destroy(): void;
369
+ }
370
+ export declare const LOGLUDO: LogLudoClient;
371
+
372
+
373
+ export default LOGLUDO;