@nexushub/client 0.0.7 → 0.0.9

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 CHANGED
@@ -1,12 +1,4 @@
1
- 'use strict';
2
-
3
- var chunk2JRYABGG_cjs = require('./chunk-2JRYABGG.cjs');
4
- var webVitals = require('web-vitals');
5
- var react = require('react');
6
- var navigation = require('next/navigation');
7
- var jsxRuntime = require('react/jsx-runtime');
8
-
9
- // src/config.ts
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }// src/config.ts
10
2
  var DEFAULT_API_URL = "http://localhost:3001";
11
3
  var DEFAULT_ANALYTICS_URL = "http://localhost:3002";
12
4
  var LOCAL_NEST_URL = "http://localhost:3001";
@@ -17,10 +9,10 @@ var hasEnv = () => {
17
9
  var getEnvConfig = () => {
18
10
  const env = hasEnv() ? process.env : {};
19
11
  const isDev = env.NODE_ENV === "development" || env.NEXT_PUBLIC_NODE_ENV === "development";
20
- const projectId = env.NEXT_PUBLIC_NEXUS_ID ?? env.NEXUS_PROJECT_ID;
21
- const apiKey = env.NEXT_PUBLIC_NEXUS_KEY ?? env.NEXUS_API_KEY;
22
- const apiUrl = env.NEXT_PUBLIC_NEXUS_API_URL ?? env.NEXUS_API_URL ?? (isDev ? LOCAL_NEST_URL : DEFAULT_API_URL);
23
- const analyticsUrl = env.NEXT_PUBLIC_NEXUS_ANALYTICS_URL ?? (apiUrl.includes("localhost") ? LOCAL_RUST_URL : DEFAULT_ANALYTICS_URL);
12
+ const projectId = _nullishCoalesce(env.NEXT_PUBLIC_NEXUS_ID, () => ( env.NEXUS_PROJECT_ID));
13
+ const apiKey = _nullishCoalesce(env.NEXT_PUBLIC_NEXUS_KEY, () => ( env.NEXUS_API_KEY));
14
+ const apiUrl = _nullishCoalesce(_nullishCoalesce(env.NEXT_PUBLIC_NEXUS_API_URL, () => ( env.NEXUS_API_URL)), () => ( (isDev ? LOCAL_NEST_URL : DEFAULT_API_URL)));
15
+ const analyticsUrl = _nullishCoalesce(env.NEXT_PUBLIC_NEXUS_ANALYTICS_URL, () => ( (apiUrl.includes("localhost") ? LOCAL_RUST_URL : DEFAULT_ANALYTICS_URL)));
24
16
  return {
25
17
  projectId,
26
18
  apiKey,
@@ -177,7 +169,7 @@ var MemoryCache = class {
177
169
  try {
178
170
  const jsonString = JSON.stringify(data);
179
171
  return new Blob([jsonString]).size;
180
- } catch {
172
+ } catch (e2) {
181
173
  return 0;
182
174
  }
183
175
  }
@@ -237,7 +229,7 @@ var BrowserCache = class {
237
229
  return null;
238
230
  }
239
231
  return entry.data;
240
- } catch {
232
+ } catch (e3) {
241
233
  this.delete(key);
242
234
  return null;
243
235
  }
@@ -256,7 +248,7 @@ var BrowserCache = class {
256
248
  const keysToRemove = [];
257
249
  for (let i = 0; i < localStorage.length; i++) {
258
250
  const key = localStorage.key(i);
259
- if (key?.startsWith(this.prefix)) {
251
+ if (_optionalChain([key, 'optionalAccess', _ => _.startsWith, 'call', _2 => _2(this.prefix)])) {
260
252
  keysToRemove.push(key);
261
253
  }
262
254
  }
@@ -270,7 +262,7 @@ var BrowserCache = class {
270
262
  this.currentSize = 0;
271
263
  for (let i = 0; i < localStorage.length; i++) {
272
264
  const key = localStorage.key(i);
273
- if (key?.startsWith(this.prefix)) {
265
+ if (_optionalChain([key, 'optionalAccess', _3 => _3.startsWith, 'call', _4 => _4(this.prefix)])) {
274
266
  const item = localStorage.getItem(key);
275
267
  if (item) {
276
268
  this.currentSize += new Blob([item]).size;
@@ -286,7 +278,7 @@ var BrowserCache = class {
286
278
  let oldestTime = Infinity;
287
279
  for (let i = 0; i < localStorage.length; i++) {
288
280
  const key = localStorage.key(i);
289
- if (key?.startsWith(this.prefix)) {
281
+ if (_optionalChain([key, 'optionalAccess', _5 => _5.startsWith, 'call', _6 => _6(this.prefix)])) {
290
282
  const item = localStorage.getItem(key);
291
283
  if (item) {
292
284
  try {
@@ -295,7 +287,7 @@ var BrowserCache = class {
295
287
  oldestTime = entry.metadata.timestamp;
296
288
  oldestKey = key;
297
289
  }
298
- } catch {
290
+ } catch (e4) {
299
291
  localStorage.removeItem(key);
300
292
  }
301
293
  }
@@ -311,6 +303,44 @@ var BrowserCache = class {
311
303
  }
312
304
  };
313
305
 
306
+ // src/content/cache.ts
307
+ var LocalCacheProxy = class {
308
+ constructor(cachePath) {
309
+ this.instance = null;
310
+ this.cachePath = cachePath;
311
+ }
312
+ async getInstance() {
313
+ if (this.instance) return this.instance;
314
+ if (typeof window === "undefined") {
315
+ const mod = await Promise.resolve().then(() => _interopRequireWildcard(require("./content/local-cache-server.cjs")));
316
+ this.instance = new mod.LocalCache(this.cachePath);
317
+ } else {
318
+ const mod = await Promise.resolve().then(() => _interopRequireWildcard(require("./content/local-cache-client.cjs")));
319
+ this.instance = new mod.LocalCache(this.cachePath);
320
+ }
321
+ return this.instance;
322
+ }
323
+ isLoaded() {
324
+ return _optionalChain([this, 'access', _7 => _7.instance, 'optionalAccess', _8 => _8.isLoaded, 'call', _9 => _9()]) || false;
325
+ }
326
+ async getPage(slug) {
327
+ const inst = await this.getInstance();
328
+ return inst.getPage(slug);
329
+ }
330
+ async getCollection(id) {
331
+ const inst = await this.getInstance();
332
+ return inst.getCollection(id);
333
+ }
334
+ async getGlobals() {
335
+ const inst = await this.getInstance();
336
+ return inst.getGlobals();
337
+ }
338
+ async getAllData() {
339
+ const inst = await this.getInstance();
340
+ return inst.getAllData();
341
+ }
342
+ };
343
+
314
344
  // src/content/strategies.ts
315
345
  var RateLimiter = class {
316
346
  constructor(config) {
@@ -322,7 +352,7 @@ var RateLimiter = class {
322
352
  const windowStart = now - this.config.timeWindow;
323
353
  this.requests = this.requests.filter((time) => time > windowStart);
324
354
  if (this.requests.length >= this.config.maxRequests) {
325
- this.requests[0];
355
+ const oldestRequest = this.requests[0];
326
356
  const waitTime = windowStart + this.config.timeWindow - now;
327
357
  if (waitTime > 0) {
328
358
  await new Promise((resolve) => setTimeout(resolve, waitTime));
@@ -379,10 +409,10 @@ var ExponentialBackoff = class {
379
409
  return delay;
380
410
  }
381
411
  isClientError(error) {
382
- return error?.status >= 400 && error?.status < 500;
412
+ return _optionalChain([error, 'optionalAccess', _10 => _10.status]) >= 400 && _optionalChain([error, 'optionalAccess', _11 => _11.status]) < 500;
383
413
  }
384
414
  isRateLimitError(error) {
385
- return error?.status === 429;
415
+ return _optionalChain([error, 'optionalAccess', _12 => _12.status]) === 429;
386
416
  }
387
417
  };
388
418
  var CircuitBreaker = class {
@@ -496,10 +526,10 @@ function buildQueryString(query) {
496
526
  if (query.sort) params.append("sort", query.sort);
497
527
  if (query.order) params.append("order", query.order);
498
528
  if (query.search) params.append("search", query.search);
499
- if (query.include?.length) {
529
+ if (_optionalChain([query, 'access', _13 => _13.include, 'optionalAccess', _14 => _14.length])) {
500
530
  params.append("include", query.include.join(","));
501
531
  }
502
- if (query.fields?.length) {
532
+ if (_optionalChain([query, 'access', _15 => _15.fields, 'optionalAccess', _16 => _16.length])) {
503
533
  params.append("fields", query.fields.join(","));
504
534
  }
505
535
  if (query.filter) {
@@ -522,7 +552,7 @@ var ContentEngine = class {
522
552
  constructor(config) {
523
553
  this.config = config;
524
554
  this.isServer = typeof window === "undefined";
525
- this.localCache = new chunk2JRYABGG_cjs.LocalCache();
555
+ this.localCache = new LocalCacheProxy();
526
556
  this.memoryCache = new MemoryCache({
527
557
  maxSize: 500,
528
558
  ttl: 5 * 60 * 1e3
@@ -558,7 +588,9 @@ var ContentEngine = class {
558
588
  () => this._getPage(slug, options)
559
589
  );
560
590
  if (this.config.debug && duration > 100) {
561
- console.warn(`[NexusHub] \u26A0\uFE0F getPage("${slug}") took ${duration.toFixed(2)}ms`);
591
+ console.warn(
592
+ `[NexusHub] \u26A0\uFE0F getPage("${slug}") took ${duration.toFixed(2)}ms`
593
+ );
562
594
  }
563
595
  return result;
564
596
  }
@@ -571,7 +603,11 @@ var ContentEngine = class {
571
603
  includeMetadata = false
572
604
  } = options;
573
605
  const cacheKey = `page:${slug}`;
574
- const cached = this.checkCaches(cacheKey, forceRefresh, includeMetadata);
606
+ const cached = await this.checkCaches(
607
+ cacheKey,
608
+ forceRefresh,
609
+ includeMetadata
610
+ );
575
611
  if (cached) {
576
612
  if (this.config.debug) console.log(`[NexusHub] \u26A1 Cache hit: ${slug}`);
577
613
  return includeMetadata ? cached : cached.data;
@@ -583,11 +619,19 @@ var ContentEngine = class {
583
619
  await this.rateLimiter.checkLimit();
584
620
  const data = await this.backoff.execute(
585
621
  async () => {
586
- return this.fetchPage(slug, cacheKey, tags, revalidate, forceRefresh);
622
+ return this.fetchPage(
623
+ slug,
624
+ cacheKey,
625
+ tags,
626
+ revalidate,
627
+ forceRefresh
628
+ );
587
629
  },
588
630
  (attempt, delay, error) => {
589
631
  if (this.config.debug) {
590
- console.log(`[NexusHub] \u{1F504} Retry ${attempt} for '${slug}' after ${delay}ms: ${error.message}`);
632
+ console.log(
633
+ `[NexusHub] \u{1F504} Retry ${attempt} for '${slug}' after ${delay}ms: ${error.message}`
634
+ );
591
635
  }
592
636
  }
593
637
  );
@@ -612,7 +656,9 @@ var ContentEngine = class {
612
656
  () => this._getCollection(collectionId, query, options)
613
657
  );
614
658
  if (this.config.debug && duration > 100) {
615
- console.warn(`[NexusHub] \u26A0\uFE0F getCollection("${collectionId}") took ${duration.toFixed(2)}ms`);
659
+ console.warn(
660
+ `[NexusHub] \u26A0\uFE0F getCollection("${collectionId}") took ${duration.toFixed(2)}ms`
661
+ );
616
662
  }
617
663
  return result;
618
664
  }
@@ -626,19 +672,30 @@ var ContentEngine = class {
626
672
  } = options;
627
673
  const queryString = buildQueryString(normalizedQuery);
628
674
  const cacheKey = `collection:${collectionId}:${queryString}`;
629
- const cached = this.checkCaches(cacheKey, forceRefresh, includeMetadata);
675
+ const cached = await this.checkCaches(
676
+ cacheKey,
677
+ forceRefresh,
678
+ includeMetadata
679
+ );
630
680
  if (cached) {
631
681
  if (this.config.debug) {
632
- console.log(`[NexusHub] \u26A1 Served collection '${collectionId}' from memory cache.`);
682
+ console.log(
683
+ `[NexusHub] \u26A1 Served collection '${collectionId}' from memory cache.`
684
+ );
633
685
  }
634
686
  return includeMetadata ? cached : cached.data;
635
687
  }
636
688
  if (!forceRefresh && process.env.NODE_ENV === "development") {
637
- const localCollection = this.localCache.getCollection(collectionId);
689
+ const localCollection = await this.localCache.getCollection(collectionId);
638
690
  if (localCollection) {
639
- const result = this.applyLocalQuery(localCollection, normalizedQuery);
691
+ const result = this.applyLocalQuery(
692
+ localCollection,
693
+ normalizedQuery
694
+ );
640
695
  if (this.config.debug) {
641
- console.log(`[NexusHub] \u{1F4C1} Served collection '${collectionId}' from local cache.`);
696
+ console.log(
697
+ `[NexusHub] \u{1F4C1} Served collection '${collectionId}' from local cache.`
698
+ );
642
699
  }
643
700
  this.memoryCache.set(cacheKey, result, {
644
701
  tags: [...tags, CacheTags.collection(collectionId)],
@@ -651,7 +708,13 @@ var ContentEngine = class {
651
708
  try {
652
709
  await this.rateLimiter.checkLimit();
653
710
  const result = await this.backoff.execute(async () => {
654
- return this.fetchCollection(collectionId, normalizedQuery, cacheKey, tags, revalidate);
711
+ return this.fetchCollection(
712
+ collectionId,
713
+ normalizedQuery,
714
+ cacheKey,
715
+ tags,
716
+ revalidate
717
+ );
655
718
  });
656
719
  this.circuitBreaker.recordSuccess();
657
720
  return includeMetadata ? result : result.data;
@@ -659,10 +722,15 @@ var ContentEngine = class {
659
722
  this.circuitBreaker.recordFailure();
660
723
  const staleCache = this.memoryCache.get(cacheKey);
661
724
  if (staleCache && !forceRefresh) {
662
- console.warn(`[NexusHub] \u26A0\uFE0F Using stale cache for collection '${collectionId}'`);
725
+ console.warn(
726
+ `[NexusHub] \u26A0\uFE0F Using stale cache for collection '${collectionId}'`
727
+ );
663
728
  return includeMetadata ? staleCache : staleCache.data;
664
729
  }
665
- throw this.normalizeError(error, `Failed to fetch collection '${collectionId}'`);
730
+ throw this.normalizeError(
731
+ error,
732
+ `Failed to fetch collection '${collectionId}'`
733
+ );
666
734
  }
667
735
  }
668
736
  /**
@@ -678,7 +746,8 @@ var ContentEngine = class {
678
746
  if (!forceRefresh && this.cacheStrategy === "memory") {
679
747
  const cached = this.memoryCache.get(cacheKey);
680
748
  if (cached && this.isCacheValid(cached.metadata)) {
681
- if (this.config.debug) console.log("[NexusHub] \u26A1 Served globals from memory cache.");
749
+ if (this.config.debug)
750
+ console.log("[NexusHub] \u26A1 Served globals from memory cache.");
682
751
  return cached.data;
683
752
  }
684
753
  }
@@ -702,13 +771,10 @@ var ContentEngine = class {
702
771
  await this.rateLimiter.checkLimit();
703
772
  const url = `${this.config.apiUrl}/content/${this.config.projectId}/globals`;
704
773
  const params = include.length > 0 ? `?include=${include.join(",")}` : "";
705
- const res = await this.fetchWithTimeout(
706
- `${url}${params}`,
707
- {
708
- method: "GET",
709
- headers: this.getHeaders()
710
- }
711
- );
774
+ const res = await this.fetchWithTimeout(`${url}${params}`, {
775
+ method: "GET",
776
+ headers: this.getHeaders()
777
+ });
712
778
  if (!res.ok) {
713
779
  throw new Error(`API Error ${res.status}: ${res.statusText}`);
714
780
  }
@@ -745,7 +811,7 @@ var ContentEngine = class {
745
811
  }
746
812
  return this.requestBatcher.schedule(cacheKey, async () => {
747
813
  const params = new URLSearchParams();
748
- if (options.include?.length) {
814
+ if (_optionalChain([options, 'access', _17 => _17.include, 'optionalAccess', _18 => _18.length])) {
749
815
  params.append("include", options.include.join(","));
750
816
  }
751
817
  const url = `${this.config.apiUrl}/content/${this.config.projectId}/collection/${collectionId}/${itemId}?${params}`;
@@ -778,10 +844,10 @@ var ContentEngine = class {
778
844
  q: query,
779
845
  limit: (options.limit || 20).toString()
780
846
  });
781
- if (options.collections?.length) {
847
+ if (_optionalChain([options, 'access', _19 => _19.collections, 'optionalAccess', _20 => _20.length])) {
782
848
  params.append("collections", options.collections.join(","));
783
849
  }
784
- if (options.fields?.length) {
850
+ if (_optionalChain([options, 'access', _21 => _21.fields, 'optionalAccess', _22 => _22.length])) {
785
851
  params.append("fields", options.fields.join(","));
786
852
  }
787
853
  const url = `${this.config.apiUrl}/content/${this.config.projectId}/search?${params}`;
@@ -824,7 +890,8 @@ var ContentEngine = class {
824
890
  eventSource = new EventSource(url);
825
891
  eventSource.onopen = () => {
826
892
  retryCount = 0;
827
- if (this.config.debug) console.log("[NexusHub] \u{1F7E2} Real-time stream connected");
893
+ if (this.config.debug)
894
+ console.log("[NexusHub] \u{1F7E2} Real-time stream connected");
828
895
  };
829
896
  eventSource.onmessage = (event) => {
830
897
  try {
@@ -841,25 +908,27 @@ var ContentEngine = class {
841
908
  }
842
909
  };
843
910
  eventSource.onerror = () => {
844
- eventSource?.close();
911
+ _optionalChain([eventSource, 'optionalAccess', _23 => _23.close, 'call', _24 => _24()]);
845
912
  if (isClosed) return;
846
913
  const timeout = Math.min(1e3 * Math.pow(2, retryCount), 1e4);
847
914
  retryCount++;
848
- console.warn(`[NexusHub] \u{1F534} Stream disconnected. Reconnecting in ${timeout}ms...`);
915
+ console.warn(
916
+ `[NexusHub] \u{1F534} Stream disconnected. Reconnecting in ${timeout}ms...`
917
+ );
849
918
  setTimeout(connect, timeout);
850
919
  };
851
920
  };
852
921
  connect();
853
922
  return () => {
854
923
  isClosed = true;
855
- eventSource?.close();
924
+ _optionalChain([eventSource, 'optionalAccess', _25 => _25.close, 'call', _26 => _26()]);
856
925
  };
857
926
  }
858
927
  // --- CACHE MANAGEMENT ---
859
928
  /**
860
929
  * Check all caches in order of speed
861
930
  */
862
- checkCaches(key, forceRefresh, includeMetadata) {
931
+ async checkCaches(key, forceRefresh, includeMetadata) {
863
932
  if (forceRefresh) return null;
864
933
  if (this.cacheStrategy === "memory") {
865
934
  const cached = this.memoryCache.get(key);
@@ -884,7 +953,7 @@ var ContentEngine = class {
884
953
  if (process.env.NODE_ENV === "development") {
885
954
  if (key.startsWith("page:")) {
886
955
  const slug = key.split(":")[1];
887
- const local = this.localCache.getPage(slug);
956
+ const local = await this.localCache.getPage(slug);
888
957
  if (local) {
889
958
  return {
890
959
  data: local,
@@ -917,7 +986,9 @@ var ContentEngine = class {
917
986
  invalidateCache(tags) {
918
987
  this.memoryCache.invalidateByTags(tags);
919
988
  if (this.config.debug) {
920
- console.log(`[NexusHub] \u267B\uFE0F Invalidated cache for tags: ${tags.join(", ")}`);
989
+ console.log(
990
+ `[NexusHub] \u267B\uFE0F Invalidated cache for tags: ${tags.join(", ")}`
991
+ );
921
992
  }
922
993
  }
923
994
  /**
@@ -957,7 +1028,9 @@ var ContentEngine = class {
957
1028
  });
958
1029
  if (!res.ok) {
959
1030
  if (res.status === 404) {
960
- throw new Error(`Page '${slug}' not found. Check your Dashboard or Seed data.`);
1031
+ throw new Error(
1032
+ `Page '${slug}' not found. Check your Dashboard or Seed data.`
1033
+ );
961
1034
  }
962
1035
  throw new Error(`API Error ${res.status}: ${res.statusText}`);
963
1036
  }
@@ -974,7 +1047,11 @@ var ContentEngine = class {
974
1047
  };
975
1048
  this.writeCache(cacheKey, cacheEntry.data, {
976
1049
  revalidate,
977
- tags: [CacheTags.project(this.config.projectId), CacheTags.content(slug), ...tags]
1050
+ tags: [
1051
+ CacheTags.project(this.config.projectId),
1052
+ CacheTags.content(slug),
1053
+ ...tags
1054
+ ]
978
1055
  });
979
1056
  return cacheEntry;
980
1057
  }
@@ -1004,7 +1081,11 @@ var ContentEngine = class {
1004
1081
  };
1005
1082
  this.writeCache(cacheKey, cacheEntry.data, {
1006
1083
  revalidate,
1007
- tags: [CacheTags.project(this.config.projectId), CacheTags.collection(collectionId), ...tags]
1084
+ tags: [
1085
+ CacheTags.project(this.config.projectId),
1086
+ CacheTags.collection(collectionId),
1087
+ ...tags
1088
+ ]
1008
1089
  });
1009
1090
  return cacheEntry;
1010
1091
  }
@@ -1156,7 +1237,7 @@ var generateCanvasHash = async () => {
1156
1237
  hash = hash & hash;
1157
1238
  }
1158
1239
  return hash.toString(16);
1159
- } catch {
1240
+ } catch (e5) {
1160
1241
  return "";
1161
1242
  }
1162
1243
  };
@@ -1185,6 +1266,15 @@ var getVisitorId = async () => {
1185
1266
  }
1186
1267
  return vid;
1187
1268
  };
1269
+
1270
+ // src/analytics/vitals.ts
1271
+
1272
+
1273
+
1274
+
1275
+
1276
+
1277
+ var _webvitals = require('web-vitals');
1188
1278
  var METRIC_KEY_MAP = {
1189
1279
  CLS: "cls",
1190
1280
  LCP: "lcp",
@@ -1206,11 +1296,11 @@ var VitalsCollector = class {
1206
1296
  this.metrics[key] = metric.value;
1207
1297
  this.hasUpdates = true;
1208
1298
  };
1209
- webVitals.onCLS(recordMetric);
1210
- webVitals.onLCP(recordMetric);
1211
- webVitals.onTTFB(recordMetric);
1212
- webVitals.onINP(recordMetric);
1213
- webVitals.onFCP(recordMetric);
1299
+ _webvitals.onCLS.call(void 0, recordMetric);
1300
+ _webvitals.onLCP.call(void 0, recordMetric);
1301
+ _webvitals.onTTFB.call(void 0, recordMetric);
1302
+ _webvitals.onINP.call(void 0, recordMetric);
1303
+ _webvitals.onFCP.call(void 0, recordMetric);
1214
1304
  const navEntry = performance.getEntriesByType("navigation")[0];
1215
1305
  if (navEntry) {
1216
1306
  this.metrics.navigation_timing = {
@@ -1307,10 +1397,12 @@ var EventStorage = class {
1307
1397
  return new Promise((resolve, reject) => {
1308
1398
  const transaction = this.db.transaction([STORE_NAME], "readwrite");
1309
1399
  const store = transaction.objectStore(STORE_NAME);
1400
+ let processed = 0;
1401
+ let errors = 0;
1310
1402
  transaction.oncomplete = () => resolve();
1311
1403
  transaction.onerror = () => reject(transaction.error);
1312
1404
  ids.forEach((id) => {
1313
- store.delete(id);
1405
+ const req = store.delete(id);
1314
1406
  });
1315
1407
  });
1316
1408
  }
@@ -1340,7 +1432,7 @@ var Tracker = class {
1340
1432
  // FIX: Add this property
1341
1433
  this.isFlushing = false;
1342
1434
  this.config = config;
1343
- this.config.apiUrl.replace("/v1", "").replace(/\/$/, "");
1435
+ const baseUrl = this.config.apiUrl.replace("/v1", "").replace(/\/$/, "");
1344
1436
  this.endpoint = `${this.config.analyticsUrl}/api/collect`;
1345
1437
  this.circuitBreaker = new CircuitBreaker();
1346
1438
  this.sessionStart = Date.now();
@@ -1518,8 +1610,8 @@ var AnalyticsEngine = class {
1518
1610
  navigator.share = (data) => {
1519
1611
  this.tracker.send("social_share", {
1520
1612
  method: "native_share_menu",
1521
- url: data?.url || window.location.href,
1522
- title: data?.title
1613
+ url: _optionalChain([data, 'optionalAccess', _27 => _27.url]) || window.location.href,
1614
+ title: _optionalChain([data, 'optionalAccess', _28 => _28.title])
1523
1615
  });
1524
1616
  return originalShare.apply(navigator, [data]);
1525
1617
  };
@@ -1650,7 +1742,7 @@ var AnalyticsEngine = class {
1650
1742
  this.tracker.send("click", {
1651
1743
  element_type: "link",
1652
1744
  href: link.href,
1653
- text: link.innerText?.substring(0, 50),
1745
+ text: _optionalChain([link, 'access', _29 => _29.innerText, 'optionalAccess', _30 => _30.substring, 'call', _31 => _31(0, 50)]),
1654
1746
  id: link.id,
1655
1747
  classes: link.className,
1656
1748
  dataset: { ...link.dataset }
@@ -1660,7 +1752,7 @@ var AnalyticsEngine = class {
1660
1752
  if (button) {
1661
1753
  this.tracker.send("click", {
1662
1754
  element_type: "button",
1663
- text: button.innerText?.substring(0, 50),
1755
+ text: _optionalChain([button, 'access', _32 => _32.innerText, 'optionalAccess', _33 => _33.substring, 'call', _34 => _34(0, 50)]),
1664
1756
  id: button.id,
1665
1757
  classes: button.className,
1666
1758
  coordinates: { x: e.clientX, y: e.clientY }
@@ -1730,11 +1822,11 @@ var NexusClient = class {
1730
1822
  constructor(config) {
1731
1823
  const fullConfig = getFullConfig(config);
1732
1824
  this.config = {
1733
- debug: config?.debug || false,
1734
- cacheStrategy: config?.cacheStrategy || "memory",
1735
- revalidateTime: config?.revalidateTime || 60,
1736
- timeout: config?.timeout || 1e4,
1737
- retries: config?.retries || 3,
1825
+ debug: _optionalChain([config, 'optionalAccess', _35 => _35.debug]) || false,
1826
+ cacheStrategy: _optionalChain([config, 'optionalAccess', _36 => _36.cacheStrategy]) || "memory",
1827
+ revalidateTime: _optionalChain([config, 'optionalAccess', _37 => _37.revalidateTime]) || 60,
1828
+ timeout: _optionalChain([config, 'optionalAccess', _38 => _38.timeout]) || 1e4,
1829
+ retries: _optionalChain([config, 'optionalAccess', _39 => _39.retries]) || 3,
1738
1830
  ...fullConfig
1739
1831
  };
1740
1832
  this.content = new ContentEngine(this.config);
@@ -1762,16 +1854,24 @@ var NexusClient = class {
1762
1854
  };
1763
1855
  var nexus = new NexusClient();
1764
1856
  var createNexusClient = (config) => new NexusClient(config);
1765
- var AuthContext = react.createContext(null);
1857
+
1858
+ // src/components/NexusProvider.tsx
1859
+ var _react = require('react'); var _react2 = _interopRequireDefault(_react);
1860
+ var _navigation = require('next/navigation');
1861
+
1862
+ // src/auth/context.tsx
1863
+
1864
+ var _jsxruntime = require('react/jsx-runtime');
1865
+ var AuthContext = _react.createContext.call(void 0, null);
1766
1866
  var AuthProvider = ({
1767
1867
  children,
1768
1868
  config
1769
1869
  }) => {
1770
- const [user, setUser] = react.useState(null);
1771
- const [isLoading, setIsLoading] = react.useState(true);
1772
- const [error, setError] = react.useState(null);
1870
+ const [user, setUser] = _react.useState.call(void 0, null);
1871
+ const [isLoading, setIsLoading] = _react.useState.call(void 0, true);
1872
+ const [error, setError] = _react.useState.call(void 0, null);
1773
1873
  const AUTH_BASE = `${config.apiUrl}/auth/project/${config.projectId}`;
1774
- const checkSession = react.useCallback(async () => {
1874
+ const checkSession = _react.useCallback.call(void 0, async () => {
1775
1875
  try {
1776
1876
  const res = await fetch(`${AUTH_BASE}/me`, {
1777
1877
  headers: getHeaders(config)
@@ -1796,7 +1896,7 @@ var AuthProvider = ({
1796
1896
  setIsLoading(false);
1797
1897
  }
1798
1898
  }, [AUTH_BASE, config]);
1799
- react.useEffect(() => {
1899
+ _react.useEffect.call(void 0, () => {
1800
1900
  checkSession();
1801
1901
  }, [checkSession]);
1802
1902
  const login = async (creds) => {
@@ -1893,7 +1993,7 @@ var AuthProvider = ({
1893
1993
  });
1894
1994
  if (!res.ok) throw await parseError(res);
1895
1995
  };
1896
- return /* @__PURE__ */ jsxRuntime.jsx(AuthContext.Provider, { value: {
1996
+ return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, AuthContext.Provider, { value: {
1897
1997
  user,
1898
1998
  isLoading,
1899
1999
  error,
@@ -1906,7 +2006,7 @@ var AuthProvider = ({
1906
2006
  }, children });
1907
2007
  };
1908
2008
  var useNexusAuth = () => {
1909
- const context = react.useContext(AuthContext);
2009
+ const context = _react.useContext.call(void 0, AuthContext);
1910
2010
  if (!context) {
1911
2011
  throw new Error("useNexusAuth must be used within a NexusProvider");
1912
2012
  }
@@ -1928,7 +2028,7 @@ async function parseError(res) {
1928
2028
  code: json.code || "UNKNOWN_ERROR",
1929
2029
  message: json.message || "An error occurred during authentication"
1930
2030
  };
1931
- } catch {
2031
+ } catch (e6) {
1932
2032
  return {
1933
2033
  status: res.status,
1934
2034
  code: "NETWORK_ERROR",
@@ -1936,23 +2036,26 @@ async function parseError(res) {
1936
2036
  };
1937
2037
  }
1938
2038
  }
1939
- var NexusContext = react.createContext(nexus);
2039
+
2040
+ // src/components/NexusProvider.tsx
2041
+
2042
+ var NexusContext = _react.createContext.call(void 0, nexus);
1940
2043
  var NexusProvider = ({
1941
2044
  children,
1942
2045
  projectId,
1943
2046
  disableAnalytics = false
1944
2047
  }) => {
1945
- const pathname = navigation.usePathname();
1946
- const searchParams = navigation.useSearchParams();
1947
- const isInitialized = react.useRef(false);
1948
- const config = react.useMemo(() => {
2048
+ const pathname = _navigation.usePathname.call(void 0, );
2049
+ const searchParams = _navigation.useSearchParams.call(void 0, );
2050
+ const isInitialized = _react.useRef.call(void 0, false);
2051
+ const config = _react.useMemo.call(void 0, () => {
1949
2052
  const currentConfig = nexus.getConfig();
1950
2053
  if (projectId && currentConfig.projectId !== projectId) {
1951
2054
  nexus.config.projectId = projectId;
1952
2055
  }
1953
2056
  return nexus.getConfig();
1954
2057
  }, [projectId]);
1955
- react.useEffect(() => {
2058
+ _react.useEffect.call(void 0, () => {
1956
2059
  if (typeof window === "undefined" || disableAnalytics) return;
1957
2060
  if (!isInitialized.current) {
1958
2061
  if (!nexus.analytics) {
@@ -1971,38 +2074,36 @@ var NexusProvider = ({
1971
2074
  }
1972
2075
  };
1973
2076
  }, [disableAnalytics]);
1974
- react.useEffect(() => {
2077
+ _react.useEffect.call(void 0, () => {
1975
2078
  if (nexus.analytics && !disableAnalytics) {
1976
2079
  nexus.analytics.pageView();
1977
2080
  }
1978
2081
  }, [pathname, searchParams, disableAnalytics]);
1979
- return /* @__PURE__ */ jsxRuntime.jsx(NexusContext.Provider, { value: nexus, children: /* @__PURE__ */ jsxRuntime.jsx(AuthProvider, { config, children }) });
2082
+ return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, NexusContext.Provider, { value: nexus, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, AuthProvider, { config, children }) });
1980
2083
  };
1981
2084
 
1982
2085
  // src/index.ts
1983
2086
  var VERSION = "0.0.1";
1984
2087
 
1985
- Object.defineProperty(exports, "LocalCache", {
1986
- enumerable: true,
1987
- get: function () { return chunk2JRYABGG_cjs.LocalCache; }
1988
- });
1989
- exports.AnalyticsEngine = AnalyticsEngine;
1990
- exports.AuthProvider = AuthProvider;
1991
- exports.BrowserCache = BrowserCache;
1992
- exports.CacheTags = CacheTags;
1993
- exports.ContentEngine = ContentEngine;
1994
- exports.DEFAULT_ANALYTICS_URL = DEFAULT_ANALYTICS_URL;
1995
- exports.DEFAULT_API_URL = DEFAULT_API_URL;
1996
- exports.LOCAL_NEST_URL = LOCAL_NEST_URL;
1997
- exports.LOCAL_RUST_URL = LOCAL_RUST_URL;
1998
- exports.MemoryCache = MemoryCache;
1999
- exports.NexusClient = NexusClient;
2000
- exports.NexusProvider = NexusProvider;
2001
- exports.VERSION = VERSION;
2002
- exports.createNexusClient = createNexusClient;
2003
- exports.getEnvConfig = getEnvConfig;
2004
- exports.getFullConfig = getFullConfig;
2005
- exports.mergeConfigs = mergeConfigs;
2006
- exports.nexus = nexus;
2007
- exports.useNexusAuth = useNexusAuth;
2008
- exports.validateConfig = validateConfig;
2088
+
2089
+
2090
+
2091
+
2092
+
2093
+
2094
+
2095
+
2096
+
2097
+
2098
+
2099
+
2100
+
2101
+
2102
+
2103
+
2104
+
2105
+
2106
+
2107
+
2108
+
2109
+ exports.AnalyticsEngine = AnalyticsEngine; exports.AuthProvider = AuthProvider; exports.BrowserCache = BrowserCache; exports.CacheTags = CacheTags; exports.ContentEngine = ContentEngine; exports.DEFAULT_ANALYTICS_URL = DEFAULT_ANALYTICS_URL; exports.DEFAULT_API_URL = DEFAULT_API_URL; exports.LOCAL_NEST_URL = LOCAL_NEST_URL; exports.LOCAL_RUST_URL = LOCAL_RUST_URL; exports.LocalCache = LocalCacheProxy; exports.MemoryCache = MemoryCache; exports.NexusClient = NexusClient; exports.NexusProvider = NexusProvider; exports.VERSION = VERSION; exports.createNexusClient = createNexusClient; exports.getEnvConfig = getEnvConfig; exports.getFullConfig = getFullConfig; exports.mergeConfigs = mergeConfigs; exports.nexus = nexus; exports.useNexusAuth = useNexusAuth; exports.validateConfig = validateConfig;