@drakkar.software/sunglasses-core 0.3.0 → 0.5.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.d.mts CHANGED
@@ -215,7 +215,7 @@ interface SunglassesConfig {
215
215
  consentExpiryMs?: number;
216
216
  /**
217
217
  * When true, every event that passes the middleware pipeline is also written
218
- * to a permanent local archive (`sunglasses:archive` in IStorageAdapter).
218
+ * to a permanent local archive (`sg:archive` in IStorageAdapter).
219
219
  *
220
220
  * Unlike the EventQueue, the archive is **never cleared automatically** after
221
221
  * a flush — events persist until `client.clearLocalArchive()` is called.
@@ -654,7 +654,7 @@ declare class MiddlewarePipeline {
654
654
  * Persists per-event counts bucketed by time period (daily, weekly, monthly, all-time).
655
655
  *
656
656
  * Storage key format:
657
- * `sunglasses:count:{period}:{bucket}:{eventName}`
657
+ * `sg:count:{period}:{bucket}:{eventName}`
658
658
  *
659
659
  * where `bucket` is:
660
660
  * - daily: "2024-01-15"
@@ -1087,6 +1087,58 @@ declare class LocalEventArchive {
1087
1087
  */
1088
1088
  declare function asTyped<T extends EventMap>(client: ISunglassesClient): ISunglassesTypedClient<T>;
1089
1089
 
1090
+ /**
1091
+ * A typed analytics stub that is safe to use before the SDK initialises.
1092
+ *
1093
+ * All calls are silent no-ops (or safe defaults) until `init()` is called
1094
+ * with the real `SunglassesCore` instance. After `init()`, every method
1095
+ * delegates to the real client transparently.
1096
+ *
1097
+ * This is the recommended pattern for module-level analytics singletons:
1098
+ *
1099
+ * ```typescript
1100
+ * // analytics.ts
1101
+ * import { createLazyClient, SunglassesCore } from '@drakkar.software/sunglasses-core';
1102
+ *
1103
+ * type MyEvents = {
1104
+ * button_clicked: { buttonId: string };
1105
+ * page_viewed: undefined;
1106
+ * };
1107
+ *
1108
+ * export const analytics = createLazyClient<MyEvents>();
1109
+ *
1110
+ * export async function initAnalytics() {
1111
+ * const client = await SunglassesCore.create({ ... });
1112
+ * analytics.init(client);
1113
+ * return client;
1114
+ * }
1115
+ * ```
1116
+ *
1117
+ * ```typescript
1118
+ * // anywhere else
1119
+ * import { analytics } from './analytics';
1120
+ *
1121
+ * // Safe at import time — noop if called before init(), real event after:
1122
+ * analytics.capture('button_clicked', { buttonId: 'cta' }); // ✓ typed
1123
+ * analytics.capture('unknown_event', {}); // ✗ TS error
1124
+ * ```
1125
+ *
1126
+ * ### Why not `Object.assign(stub, asTyped(client))`?
1127
+ *
1128
+ * `asTyped` returns the client itself. `Object.assign` only copies own
1129
+ * enumerable properties — class prototype methods like `capture()` are
1130
+ * **not** own properties and are silently skipped. Using `createLazyClient`
1131
+ * avoids this footgun entirely.
1132
+ */
1133
+ declare function createLazyClient<T extends EventMap>(): ISunglassesTypedClient<T> & {
1134
+ /**
1135
+ * Wire up the real SDK client.
1136
+ * Safe to call multiple times — last call wins.
1137
+ * After calling, all subsequent analytics calls delegate to `client`.
1138
+ */
1139
+ init(client: ISunglassesClient): void;
1140
+ };
1141
+
1090
1142
  /**
1091
1143
  * Generate a UUID v4 using the Web Crypto API.
1092
1144
  *
@@ -1107,4 +1159,4 @@ declare function sha256Hex(input: string): Promise<string>;
1107
1159
  */
1108
1160
  declare function nowISO(): string;
1109
1161
 
1110
- export { type CleanupConfig, type ConsentHistoryEntry, ConsentManager, type ConsentState, type ConsentStatus, type ErrorEventProperties, type EventContext, type EventCountPeriod, EventCounter, type EventMap, EventQueue, type EventType, FrequencyMiddleware, type FrequencyMiddlewareOptions, type HttpAdapterConfig, type IAnalyticsAdapter, type IEventCounter, type IMiddleware, type IStorageAdapter, type ISunglassesClient, type ISunglassesTypedClient, IdentityManager, type IdentityState, LocalEventArchive, type Logger, type MiddlewareNext, MiddlewarePipeline, PiiSanitizer, SamplingMiddleware, type SamplingMiddlewareOptions, type ScreenTrackingOptions, SessionManager, type SessionState, type StarfishAdapterConfig, type SunglassesConfig, SunglassesCore, type SunglassesEvent, TraitManager, type UserDataExport, asTyped, createLogger, generateUUID, nowISO, sha256Hex };
1162
+ export { type CleanupConfig, type ConsentHistoryEntry, ConsentManager, type ConsentState, type ConsentStatus, type ErrorEventProperties, type EventContext, type EventCountPeriod, EventCounter, type EventMap, EventQueue, type EventType, FrequencyMiddleware, type FrequencyMiddlewareOptions, type HttpAdapterConfig, type IAnalyticsAdapter, type IEventCounter, type IMiddleware, type IStorageAdapter, type ISunglassesClient, type ISunglassesTypedClient, IdentityManager, type IdentityState, LocalEventArchive, type Logger, type MiddlewareNext, MiddlewarePipeline, PiiSanitizer, SamplingMiddleware, type SamplingMiddlewareOptions, type ScreenTrackingOptions, SessionManager, type SessionState, type StarfishAdapterConfig, type SunglassesConfig, SunglassesCore, type SunglassesEvent, TraitManager, type UserDataExport, asTyped, createLazyClient, createLogger, generateUUID, nowISO, sha256Hex };
package/dist/index.d.ts CHANGED
@@ -215,7 +215,7 @@ interface SunglassesConfig {
215
215
  consentExpiryMs?: number;
216
216
  /**
217
217
  * When true, every event that passes the middleware pipeline is also written
218
- * to a permanent local archive (`sunglasses:archive` in IStorageAdapter).
218
+ * to a permanent local archive (`sg:archive` in IStorageAdapter).
219
219
  *
220
220
  * Unlike the EventQueue, the archive is **never cleared automatically** after
221
221
  * a flush — events persist until `client.clearLocalArchive()` is called.
@@ -654,7 +654,7 @@ declare class MiddlewarePipeline {
654
654
  * Persists per-event counts bucketed by time period (daily, weekly, monthly, all-time).
655
655
  *
656
656
  * Storage key format:
657
- * `sunglasses:count:{period}:{bucket}:{eventName}`
657
+ * `sg:count:{period}:{bucket}:{eventName}`
658
658
  *
659
659
  * where `bucket` is:
660
660
  * - daily: "2024-01-15"
@@ -1087,6 +1087,58 @@ declare class LocalEventArchive {
1087
1087
  */
1088
1088
  declare function asTyped<T extends EventMap>(client: ISunglassesClient): ISunglassesTypedClient<T>;
1089
1089
 
1090
+ /**
1091
+ * A typed analytics stub that is safe to use before the SDK initialises.
1092
+ *
1093
+ * All calls are silent no-ops (or safe defaults) until `init()` is called
1094
+ * with the real `SunglassesCore` instance. After `init()`, every method
1095
+ * delegates to the real client transparently.
1096
+ *
1097
+ * This is the recommended pattern for module-level analytics singletons:
1098
+ *
1099
+ * ```typescript
1100
+ * // analytics.ts
1101
+ * import { createLazyClient, SunglassesCore } from '@drakkar.software/sunglasses-core';
1102
+ *
1103
+ * type MyEvents = {
1104
+ * button_clicked: { buttonId: string };
1105
+ * page_viewed: undefined;
1106
+ * };
1107
+ *
1108
+ * export const analytics = createLazyClient<MyEvents>();
1109
+ *
1110
+ * export async function initAnalytics() {
1111
+ * const client = await SunglassesCore.create({ ... });
1112
+ * analytics.init(client);
1113
+ * return client;
1114
+ * }
1115
+ * ```
1116
+ *
1117
+ * ```typescript
1118
+ * // anywhere else
1119
+ * import { analytics } from './analytics';
1120
+ *
1121
+ * // Safe at import time — noop if called before init(), real event after:
1122
+ * analytics.capture('button_clicked', { buttonId: 'cta' }); // ✓ typed
1123
+ * analytics.capture('unknown_event', {}); // ✗ TS error
1124
+ * ```
1125
+ *
1126
+ * ### Why not `Object.assign(stub, asTyped(client))`?
1127
+ *
1128
+ * `asTyped` returns the client itself. `Object.assign` only copies own
1129
+ * enumerable properties — class prototype methods like `capture()` are
1130
+ * **not** own properties and are silently skipped. Using `createLazyClient`
1131
+ * avoids this footgun entirely.
1132
+ */
1133
+ declare function createLazyClient<T extends EventMap>(): ISunglassesTypedClient<T> & {
1134
+ /**
1135
+ * Wire up the real SDK client.
1136
+ * Safe to call multiple times — last call wins.
1137
+ * After calling, all subsequent analytics calls delegate to `client`.
1138
+ */
1139
+ init(client: ISunglassesClient): void;
1140
+ };
1141
+
1090
1142
  /**
1091
1143
  * Generate a UUID v4 using the Web Crypto API.
1092
1144
  *
@@ -1107,4 +1159,4 @@ declare function sha256Hex(input: string): Promise<string>;
1107
1159
  */
1108
1160
  declare function nowISO(): string;
1109
1161
 
1110
- export { type CleanupConfig, type ConsentHistoryEntry, ConsentManager, type ConsentState, type ConsentStatus, type ErrorEventProperties, type EventContext, type EventCountPeriod, EventCounter, type EventMap, EventQueue, type EventType, FrequencyMiddleware, type FrequencyMiddlewareOptions, type HttpAdapterConfig, type IAnalyticsAdapter, type IEventCounter, type IMiddleware, type IStorageAdapter, type ISunglassesClient, type ISunglassesTypedClient, IdentityManager, type IdentityState, LocalEventArchive, type Logger, type MiddlewareNext, MiddlewarePipeline, PiiSanitizer, SamplingMiddleware, type SamplingMiddlewareOptions, type ScreenTrackingOptions, SessionManager, type SessionState, type StarfishAdapterConfig, type SunglassesConfig, SunglassesCore, type SunglassesEvent, TraitManager, type UserDataExport, asTyped, createLogger, generateUUID, nowISO, sha256Hex };
1162
+ export { type CleanupConfig, type ConsentHistoryEntry, ConsentManager, type ConsentState, type ConsentStatus, type ErrorEventProperties, type EventContext, type EventCountPeriod, EventCounter, type EventMap, EventQueue, type EventType, FrequencyMiddleware, type FrequencyMiddlewareOptions, type HttpAdapterConfig, type IAnalyticsAdapter, type IEventCounter, type IMiddleware, type IStorageAdapter, type ISunglassesClient, type ISunglassesTypedClient, IdentityManager, type IdentityState, LocalEventArchive, type Logger, type MiddlewareNext, MiddlewarePipeline, PiiSanitizer, SamplingMiddleware, type SamplingMiddlewareOptions, type ScreenTrackingOptions, SessionManager, type SessionState, type StarfishAdapterConfig, type SunglassesConfig, SunglassesCore, type SunglassesEvent, TraitManager, type UserDataExport, asTyped, createLazyClient, createLogger, generateUUID, nowISO, sha256Hex };
package/dist/index.js CHANGED
@@ -33,6 +33,7 @@ __export(index_exports, {
33
33
  SunglassesCore: () => SunglassesCore,
34
34
  TraitManager: () => TraitManager,
35
35
  asTyped: () => asTyped,
36
+ createLazyClient: () => createLazyClient,
36
37
  createLogger: () => createLogger,
37
38
  generateUUID: () => generateUUID,
38
39
  nowISO: () => nowISO,
@@ -46,7 +47,7 @@ function nowISO() {
46
47
  }
47
48
 
48
49
  // src/ConsentManager.ts
49
- var STORAGE_KEY = "sunglasses:consent";
50
+ var STORAGE_KEY = "sg:consent";
50
51
  var MAX_HISTORY_LENGTH = 10;
51
52
  var ConsentManager = class {
52
53
  constructor(storage, logger) {
@@ -204,7 +205,7 @@ var ConsentManager = class {
204
205
  };
205
206
 
206
207
  // src/EventCounter.ts
207
- var KEY_PREFIX = "sunglasses:count";
208
+ var KEY_PREFIX = "sg:count";
208
209
  var EventCounter = class {
209
210
  constructor(storage, logger) {
210
211
  this.storage = storage;
@@ -379,7 +380,7 @@ function toISOWeek(date) {
379
380
  }
380
381
 
381
382
  // src/EventQueue.ts
382
- var STORAGE_KEY2 = "sunglasses:queue";
383
+ var STORAGE_KEY2 = "sg:queue";
383
384
  var EventQueue = class {
384
385
  constructor(storage, logger, maxSize) {
385
386
  this.storage = storage;
@@ -492,8 +493,8 @@ async function sha256Hex(input) {
492
493
  }
493
494
 
494
495
  // src/IdentityManager.ts
495
- var ANON_ID_KEY = "sunglasses:anon_id";
496
- var DISTINCT_ID_KEY = "sunglasses:distinct_id";
496
+ var ANON_ID_KEY = "sg:anon_id";
497
+ var DISTINCT_ID_KEY = "sg:distinct_id";
497
498
  var IdentityManager = class {
498
499
  constructor(storage, logger, anonymizeUserId) {
499
500
  this.storage = storage;
@@ -581,7 +582,7 @@ var IdentityManager = class {
581
582
  };
582
583
 
583
584
  // src/LocalEventArchive.ts
584
- var STORAGE_KEY3 = "sunglasses:archive";
585
+ var STORAGE_KEY3 = "sg:archive";
585
586
  var LocalEventArchive = class {
586
587
  constructor(storage, logger) {
587
588
  this.storage = storage;
@@ -801,7 +802,7 @@ var PiiSanitizer = class {
801
802
  };
802
803
 
803
804
  // src/SessionManager.ts
804
- var STORAGE_KEY4 = "sunglasses:session";
805
+ var STORAGE_KEY4 = "sg:session";
805
806
  var DEFAULT_IDLE_TIMEOUT_MS = 30 * 60 * 1e3;
806
807
  var SessionManager = class {
807
808
  constructor(storage, logger, idleTimeoutMs = DEFAULT_IDLE_TIMEOUT_MS) {
@@ -914,7 +915,7 @@ var SessionManager = class {
914
915
  };
915
916
 
916
917
  // src/TraitManager.ts
917
- var STORAGE_KEY5 = "sunglasses:traits";
918
+ var STORAGE_KEY5 = "sg:traits";
918
919
  var SENSITIVE_KEYS = /* @__PURE__ */ new Set([
919
920
  "email",
920
921
  "phone",
@@ -1590,6 +1591,105 @@ var SamplingMiddleware = class {
1590
1591
  function asTyped(client) {
1591
1592
  return client;
1592
1593
  }
1594
+
1595
+ // src/LazyClient.ts
1596
+ function createLazyClient() {
1597
+ let _inner = null;
1598
+ const lazy = {
1599
+ init(client) {
1600
+ _inner = client;
1601
+ },
1602
+ // ── Event tracking ────────────────────────────────────────────────────────
1603
+ capture(eventName, properties, options) {
1604
+ _inner?.capture(eventName, properties, options);
1605
+ },
1606
+ screen(screenName, properties) {
1607
+ _inner?.screen(screenName, properties);
1608
+ },
1609
+ identify(userId, traits) {
1610
+ _inner?.identify(userId, traits);
1611
+ },
1612
+ alias(newId, existingId) {
1613
+ _inner?.alias(newId, existingId);
1614
+ },
1615
+ group(groupId, groupTraits) {
1616
+ _inner?.group(groupId, groupTraits);
1617
+ },
1618
+ async reset() {
1619
+ await _inner?.reset();
1620
+ },
1621
+ // ── Super properties ──────────────────────────────────────────────────────
1622
+ register(properties) {
1623
+ _inner?.register(properties);
1624
+ },
1625
+ unregister(...keys) {
1626
+ _inner?.unregister(...keys);
1627
+ },
1628
+ getRegisteredProperties() {
1629
+ return _inner?.getRegisteredProperties() ?? {};
1630
+ },
1631
+ // ── Consent ───────────────────────────────────────────────────────────────
1632
+ async optIn() {
1633
+ await _inner?.optIn();
1634
+ },
1635
+ async optOut() {
1636
+ await _inner?.optOut();
1637
+ },
1638
+ hasOptedIn() {
1639
+ return _inner?.hasOptedIn() ?? false;
1640
+ },
1641
+ hasOptedOut() {
1642
+ return _inner?.hasOptedOut() ?? false;
1643
+ },
1644
+ getConsentStatus() {
1645
+ return _inner?.getConsentStatus() ?? "unknown";
1646
+ },
1647
+ getConsentHistory() {
1648
+ return _inner?.getConsentHistory() ?? [];
1649
+ },
1650
+ // ── Lifecycle ─────────────────────────────────────────────────────────────
1651
+ async flush() {
1652
+ await _inner?.flush();
1653
+ },
1654
+ async shutdown() {
1655
+ await _inner?.shutdown();
1656
+ },
1657
+ // ── Event counting ────────────────────────────────────────────────────────
1658
+ async getEventCount(eventName, period, date) {
1659
+ return _inner?.getEventCount(eventName, period, date) ?? Promise.resolve(0);
1660
+ },
1661
+ async resetEventCount(eventName) {
1662
+ await _inner?.resetEventCount(eventName);
1663
+ },
1664
+ get eventCounter() {
1665
+ return _inner?.eventCounter ?? null;
1666
+ },
1667
+ getQueuedEventCount() {
1668
+ return _inner?.getQueuedEventCount() ?? 0;
1669
+ },
1670
+ // ── Local archive / data portability ─────────────────────────────────────
1671
+ async clearLocalArchive(config) {
1672
+ await _inner?.clearLocalArchive(config);
1673
+ },
1674
+ async exportUserData() {
1675
+ return _inner?.exportUserData() ?? {
1676
+ exportedAt: (/* @__PURE__ */ new Date()).toISOString(),
1677
+ anonymousId: "",
1678
+ distinctId: null,
1679
+ traits: {},
1680
+ consentStatus: "unknown",
1681
+ consentHistory: [],
1682
+ queuedEvents: [],
1683
+ archivedEvents: [],
1684
+ eventCountSummary: {}
1685
+ };
1686
+ },
1687
+ async deleteUserData(options) {
1688
+ await _inner?.deleteUserData(options);
1689
+ }
1690
+ };
1691
+ return lazy;
1692
+ }
1593
1693
  // Annotate the CommonJS export names for ESM import in node:
1594
1694
  0 && (module.exports = {
1595
1695
  ConsentManager,
@@ -1605,6 +1705,7 @@ function asTyped(client) {
1605
1705
  SunglassesCore,
1606
1706
  TraitManager,
1607
1707
  asTyped,
1708
+ createLazyClient,
1608
1709
  createLogger,
1609
1710
  generateUUID,
1610
1711
  nowISO,
package/dist/index.mjs CHANGED
@@ -4,7 +4,7 @@ function nowISO() {
4
4
  }
5
5
 
6
6
  // src/ConsentManager.ts
7
- var STORAGE_KEY = "sunglasses:consent";
7
+ var STORAGE_KEY = "sg:consent";
8
8
  var MAX_HISTORY_LENGTH = 10;
9
9
  var ConsentManager = class {
10
10
  constructor(storage, logger) {
@@ -162,7 +162,7 @@ var ConsentManager = class {
162
162
  };
163
163
 
164
164
  // src/EventCounter.ts
165
- var KEY_PREFIX = "sunglasses:count";
165
+ var KEY_PREFIX = "sg:count";
166
166
  var EventCounter = class {
167
167
  constructor(storage, logger) {
168
168
  this.storage = storage;
@@ -337,7 +337,7 @@ function toISOWeek(date) {
337
337
  }
338
338
 
339
339
  // src/EventQueue.ts
340
- var STORAGE_KEY2 = "sunglasses:queue";
340
+ var STORAGE_KEY2 = "sg:queue";
341
341
  var EventQueue = class {
342
342
  constructor(storage, logger, maxSize) {
343
343
  this.storage = storage;
@@ -450,8 +450,8 @@ async function sha256Hex(input) {
450
450
  }
451
451
 
452
452
  // src/IdentityManager.ts
453
- var ANON_ID_KEY = "sunglasses:anon_id";
454
- var DISTINCT_ID_KEY = "sunglasses:distinct_id";
453
+ var ANON_ID_KEY = "sg:anon_id";
454
+ var DISTINCT_ID_KEY = "sg:distinct_id";
455
455
  var IdentityManager = class {
456
456
  constructor(storage, logger, anonymizeUserId) {
457
457
  this.storage = storage;
@@ -539,7 +539,7 @@ var IdentityManager = class {
539
539
  };
540
540
 
541
541
  // src/LocalEventArchive.ts
542
- var STORAGE_KEY3 = "sunglasses:archive";
542
+ var STORAGE_KEY3 = "sg:archive";
543
543
  var LocalEventArchive = class {
544
544
  constructor(storage, logger) {
545
545
  this.storage = storage;
@@ -759,7 +759,7 @@ var PiiSanitizer = class {
759
759
  };
760
760
 
761
761
  // src/SessionManager.ts
762
- var STORAGE_KEY4 = "sunglasses:session";
762
+ var STORAGE_KEY4 = "sg:session";
763
763
  var DEFAULT_IDLE_TIMEOUT_MS = 30 * 60 * 1e3;
764
764
  var SessionManager = class {
765
765
  constructor(storage, logger, idleTimeoutMs = DEFAULT_IDLE_TIMEOUT_MS) {
@@ -872,7 +872,7 @@ var SessionManager = class {
872
872
  };
873
873
 
874
874
  // src/TraitManager.ts
875
- var STORAGE_KEY5 = "sunglasses:traits";
875
+ var STORAGE_KEY5 = "sg:traits";
876
876
  var SENSITIVE_KEYS = /* @__PURE__ */ new Set([
877
877
  "email",
878
878
  "phone",
@@ -1548,6 +1548,105 @@ var SamplingMiddleware = class {
1548
1548
  function asTyped(client) {
1549
1549
  return client;
1550
1550
  }
1551
+
1552
+ // src/LazyClient.ts
1553
+ function createLazyClient() {
1554
+ let _inner = null;
1555
+ const lazy = {
1556
+ init(client) {
1557
+ _inner = client;
1558
+ },
1559
+ // ── Event tracking ────────────────────────────────────────────────────────
1560
+ capture(eventName, properties, options) {
1561
+ _inner?.capture(eventName, properties, options);
1562
+ },
1563
+ screen(screenName, properties) {
1564
+ _inner?.screen(screenName, properties);
1565
+ },
1566
+ identify(userId, traits) {
1567
+ _inner?.identify(userId, traits);
1568
+ },
1569
+ alias(newId, existingId) {
1570
+ _inner?.alias(newId, existingId);
1571
+ },
1572
+ group(groupId, groupTraits) {
1573
+ _inner?.group(groupId, groupTraits);
1574
+ },
1575
+ async reset() {
1576
+ await _inner?.reset();
1577
+ },
1578
+ // ── Super properties ──────────────────────────────────────────────────────
1579
+ register(properties) {
1580
+ _inner?.register(properties);
1581
+ },
1582
+ unregister(...keys) {
1583
+ _inner?.unregister(...keys);
1584
+ },
1585
+ getRegisteredProperties() {
1586
+ return _inner?.getRegisteredProperties() ?? {};
1587
+ },
1588
+ // ── Consent ───────────────────────────────────────────────────────────────
1589
+ async optIn() {
1590
+ await _inner?.optIn();
1591
+ },
1592
+ async optOut() {
1593
+ await _inner?.optOut();
1594
+ },
1595
+ hasOptedIn() {
1596
+ return _inner?.hasOptedIn() ?? false;
1597
+ },
1598
+ hasOptedOut() {
1599
+ return _inner?.hasOptedOut() ?? false;
1600
+ },
1601
+ getConsentStatus() {
1602
+ return _inner?.getConsentStatus() ?? "unknown";
1603
+ },
1604
+ getConsentHistory() {
1605
+ return _inner?.getConsentHistory() ?? [];
1606
+ },
1607
+ // ── Lifecycle ─────────────────────────────────────────────────────────────
1608
+ async flush() {
1609
+ await _inner?.flush();
1610
+ },
1611
+ async shutdown() {
1612
+ await _inner?.shutdown();
1613
+ },
1614
+ // ── Event counting ────────────────────────────────────────────────────────
1615
+ async getEventCount(eventName, period, date) {
1616
+ return _inner?.getEventCount(eventName, period, date) ?? Promise.resolve(0);
1617
+ },
1618
+ async resetEventCount(eventName) {
1619
+ await _inner?.resetEventCount(eventName);
1620
+ },
1621
+ get eventCounter() {
1622
+ return _inner?.eventCounter ?? null;
1623
+ },
1624
+ getQueuedEventCount() {
1625
+ return _inner?.getQueuedEventCount() ?? 0;
1626
+ },
1627
+ // ── Local archive / data portability ─────────────────────────────────────
1628
+ async clearLocalArchive(config) {
1629
+ await _inner?.clearLocalArchive(config);
1630
+ },
1631
+ async exportUserData() {
1632
+ return _inner?.exportUserData() ?? {
1633
+ exportedAt: (/* @__PURE__ */ new Date()).toISOString(),
1634
+ anonymousId: "",
1635
+ distinctId: null,
1636
+ traits: {},
1637
+ consentStatus: "unknown",
1638
+ consentHistory: [],
1639
+ queuedEvents: [],
1640
+ archivedEvents: [],
1641
+ eventCountSummary: {}
1642
+ };
1643
+ },
1644
+ async deleteUserData(options) {
1645
+ await _inner?.deleteUserData(options);
1646
+ }
1647
+ };
1648
+ return lazy;
1649
+ }
1551
1650
  export {
1552
1651
  ConsentManager,
1553
1652
  EventCounter,
@@ -1562,6 +1661,7 @@ export {
1562
1661
  SunglassesCore,
1563
1662
  TraitManager,
1564
1663
  asTyped,
1664
+ createLazyClient,
1565
1665
  createLogger,
1566
1666
  generateUUID,
1567
1667
  nowISO,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@drakkar.software/sunglasses-core",
3
- "version": "0.3.0",
3
+ "version": "0.5.0",
4
4
  "description": "Platform-agnostic event tracking engine for SunGlasses",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",