@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.d.cts CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
2
  import React from 'react';
3
- export { LocalCache } from './content/local-cache-server.cjs';
3
+ import { I as ILocalCache } from './cache-types-B39iNHfE.cjs';
4
4
 
5
5
  interface MinimalNexusConfig {
6
6
  apiUrl?: string;
@@ -397,6 +397,18 @@ declare class BrowserCache {
397
397
  private evictOldest;
398
398
  }
399
399
 
400
+ declare class LocalCacheProxy implements ILocalCache {
401
+ private instance;
402
+ private cachePath?;
403
+ constructor(cachePath?: string);
404
+ private getInstance;
405
+ isLoaded(): boolean;
406
+ getPage(slug: string): Promise<any>;
407
+ getCollection(id: string): Promise<any[] | null>;
408
+ getGlobals(): Promise<any>;
409
+ getAllData(): Promise<any>;
410
+ }
411
+
400
412
  declare const VERSION = "0.0.1";
401
413
 
402
- export { AnalyticsEngine, type AuthContextType, type AuthError, AuthProvider, type AuthState, BrowserCache, type CacheEntry, type CacheMetadata, CacheTags, type CollectionQuery, type CollectionResponse, ContentEngine, type ContentResponse, DEFAULT_ANALYTICS_URL, DEFAULT_API_URL, type ErrorResponse, LOCAL_NEST_URL, LOCAL_RUST_URL, type LoginCredentials, MemoryCache, type MinimalNexusConfig, NexusClient, type NexusConfig, NexusProvider, type RegisterCredentials, type SiteUser, VERSION, createNexusClient, getEnvConfig, getFullConfig, mergeConfigs, nexus, useNexusAuth, validateConfig };
414
+ export { AnalyticsEngine, type AuthContextType, type AuthError, AuthProvider, type AuthState, BrowserCache, type CacheEntry, type CacheMetadata, CacheTags, type CollectionQuery, type CollectionResponse, ContentEngine, type ContentResponse, DEFAULT_ANALYTICS_URL, DEFAULT_API_URL, type ErrorResponse, LOCAL_NEST_URL, LOCAL_RUST_URL, LocalCacheProxy as LocalCache, type LoginCredentials, MemoryCache, type MinimalNexusConfig, NexusClient, type NexusConfig, NexusProvider, type RegisterCredentials, type SiteUser, VERSION, createNexusClient, getEnvConfig, getFullConfig, mergeConfigs, nexus, useNexusAuth, validateConfig };
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
2
  import React from 'react';
3
- export { LocalCache } from './content/local-cache-server.js';
3
+ import { I as ILocalCache } from './cache-types-B39iNHfE.js';
4
4
 
5
5
  interface MinimalNexusConfig {
6
6
  apiUrl?: string;
@@ -397,6 +397,18 @@ declare class BrowserCache {
397
397
  private evictOldest;
398
398
  }
399
399
 
400
+ declare class LocalCacheProxy implements ILocalCache {
401
+ private instance;
402
+ private cachePath?;
403
+ constructor(cachePath?: string);
404
+ private getInstance;
405
+ isLoaded(): boolean;
406
+ getPage(slug: string): Promise<any>;
407
+ getCollection(id: string): Promise<any[] | null>;
408
+ getGlobals(): Promise<any>;
409
+ getAllData(): Promise<any>;
410
+ }
411
+
400
412
  declare const VERSION = "0.0.1";
401
413
 
402
- export { AnalyticsEngine, type AuthContextType, type AuthError, AuthProvider, type AuthState, BrowserCache, type CacheEntry, type CacheMetadata, CacheTags, type CollectionQuery, type CollectionResponse, ContentEngine, type ContentResponse, DEFAULT_ANALYTICS_URL, DEFAULT_API_URL, type ErrorResponse, LOCAL_NEST_URL, LOCAL_RUST_URL, type LoginCredentials, MemoryCache, type MinimalNexusConfig, NexusClient, type NexusConfig, NexusProvider, type RegisterCredentials, type SiteUser, VERSION, createNexusClient, getEnvConfig, getFullConfig, mergeConfigs, nexus, useNexusAuth, validateConfig };
414
+ export { AnalyticsEngine, type AuthContextType, type AuthError, AuthProvider, type AuthState, BrowserCache, type CacheEntry, type CacheMetadata, CacheTags, type CollectionQuery, type CollectionResponse, ContentEngine, type ContentResponse, DEFAULT_ANALYTICS_URL, DEFAULT_API_URL, type ErrorResponse, LOCAL_NEST_URL, LOCAL_RUST_URL, LocalCacheProxy as LocalCache, type LoginCredentials, MemoryCache, type MinimalNexusConfig, NexusClient, type NexusConfig, NexusProvider, type RegisterCredentials, type SiteUser, VERSION, createNexusClient, getEnvConfig, getFullConfig, mergeConfigs, nexus, useNexusAuth, validateConfig };
package/dist/index.js CHANGED
@@ -1,10 +1,3 @@
1
- import { LocalCache } from './chunk-BPQMAYT3.js';
2
- export { LocalCache } from './chunk-BPQMAYT3.js';
3
- import { onCLS, onLCP, onTTFB, onINP, onFCP } from 'web-vitals';
4
- import { createContext, useState, useCallback, useEffect, useContext, useRef, useMemo } from 'react';
5
- import { usePathname, useSearchParams } from 'next/navigation';
6
- import { jsx } from 'react/jsx-runtime';
7
-
8
1
  // src/config.ts
9
2
  var DEFAULT_API_URL = "http://localhost:3001";
10
3
  var DEFAULT_ANALYTICS_URL = "http://localhost:3002";
@@ -310,6 +303,44 @@ var BrowserCache = class {
310
303
  }
311
304
  };
312
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 import("./content/local-cache-server.js");
316
+ this.instance = new mod.LocalCache(this.cachePath);
317
+ } else {
318
+ const mod = await import("./content/local-cache-client.js");
319
+ this.instance = new mod.LocalCache(this.cachePath);
320
+ }
321
+ return this.instance;
322
+ }
323
+ isLoaded() {
324
+ return this.instance?.isLoaded() || 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
+
313
344
  // src/content/strategies.ts
314
345
  var RateLimiter = class {
315
346
  constructor(config) {
@@ -321,7 +352,7 @@ var RateLimiter = class {
321
352
  const windowStart = now - this.config.timeWindow;
322
353
  this.requests = this.requests.filter((time) => time > windowStart);
323
354
  if (this.requests.length >= this.config.maxRequests) {
324
- this.requests[0];
355
+ const oldestRequest = this.requests[0];
325
356
  const waitTime = windowStart + this.config.timeWindow - now;
326
357
  if (waitTime > 0) {
327
358
  await new Promise((resolve) => setTimeout(resolve, waitTime));
@@ -521,7 +552,7 @@ var ContentEngine = class {
521
552
  constructor(config) {
522
553
  this.config = config;
523
554
  this.isServer = typeof window === "undefined";
524
- this.localCache = new LocalCache();
555
+ this.localCache = new LocalCacheProxy();
525
556
  this.memoryCache = new MemoryCache({
526
557
  maxSize: 500,
527
558
  ttl: 5 * 60 * 1e3
@@ -557,7 +588,9 @@ var ContentEngine = class {
557
588
  () => this._getPage(slug, options)
558
589
  );
559
590
  if (this.config.debug && duration > 100) {
560
- 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
+ );
561
594
  }
562
595
  return result;
563
596
  }
@@ -570,7 +603,11 @@ var ContentEngine = class {
570
603
  includeMetadata = false
571
604
  } = options;
572
605
  const cacheKey = `page:${slug}`;
573
- const cached = this.checkCaches(cacheKey, forceRefresh, includeMetadata);
606
+ const cached = await this.checkCaches(
607
+ cacheKey,
608
+ forceRefresh,
609
+ includeMetadata
610
+ );
574
611
  if (cached) {
575
612
  if (this.config.debug) console.log(`[NexusHub] \u26A1 Cache hit: ${slug}`);
576
613
  return includeMetadata ? cached : cached.data;
@@ -582,11 +619,19 @@ var ContentEngine = class {
582
619
  await this.rateLimiter.checkLimit();
583
620
  const data = await this.backoff.execute(
584
621
  async () => {
585
- return this.fetchPage(slug, cacheKey, tags, revalidate, forceRefresh);
622
+ return this.fetchPage(
623
+ slug,
624
+ cacheKey,
625
+ tags,
626
+ revalidate,
627
+ forceRefresh
628
+ );
586
629
  },
587
630
  (attempt, delay, error) => {
588
631
  if (this.config.debug) {
589
- 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
+ );
590
635
  }
591
636
  }
592
637
  );
@@ -611,7 +656,9 @@ var ContentEngine = class {
611
656
  () => this._getCollection(collectionId, query, options)
612
657
  );
613
658
  if (this.config.debug && duration > 100) {
614
- 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
+ );
615
662
  }
616
663
  return result;
617
664
  }
@@ -625,19 +672,30 @@ var ContentEngine = class {
625
672
  } = options;
626
673
  const queryString = buildQueryString(normalizedQuery);
627
674
  const cacheKey = `collection:${collectionId}:${queryString}`;
628
- const cached = this.checkCaches(cacheKey, forceRefresh, includeMetadata);
675
+ const cached = await this.checkCaches(
676
+ cacheKey,
677
+ forceRefresh,
678
+ includeMetadata
679
+ );
629
680
  if (cached) {
630
681
  if (this.config.debug) {
631
- console.log(`[NexusHub] \u26A1 Served collection '${collectionId}' from memory cache.`);
682
+ console.log(
683
+ `[NexusHub] \u26A1 Served collection '${collectionId}' from memory cache.`
684
+ );
632
685
  }
633
686
  return includeMetadata ? cached : cached.data;
634
687
  }
635
688
  if (!forceRefresh && process.env.NODE_ENV === "development") {
636
- const localCollection = this.localCache.getCollection(collectionId);
689
+ const localCollection = await this.localCache.getCollection(collectionId);
637
690
  if (localCollection) {
638
- const result = this.applyLocalQuery(localCollection, normalizedQuery);
691
+ const result = this.applyLocalQuery(
692
+ localCollection,
693
+ normalizedQuery
694
+ );
639
695
  if (this.config.debug) {
640
- 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
+ );
641
699
  }
642
700
  this.memoryCache.set(cacheKey, result, {
643
701
  tags: [...tags, CacheTags.collection(collectionId)],
@@ -650,7 +708,13 @@ var ContentEngine = class {
650
708
  try {
651
709
  await this.rateLimiter.checkLimit();
652
710
  const result = await this.backoff.execute(async () => {
653
- return this.fetchCollection(collectionId, normalizedQuery, cacheKey, tags, revalidate);
711
+ return this.fetchCollection(
712
+ collectionId,
713
+ normalizedQuery,
714
+ cacheKey,
715
+ tags,
716
+ revalidate
717
+ );
654
718
  });
655
719
  this.circuitBreaker.recordSuccess();
656
720
  return includeMetadata ? result : result.data;
@@ -658,10 +722,15 @@ var ContentEngine = class {
658
722
  this.circuitBreaker.recordFailure();
659
723
  const staleCache = this.memoryCache.get(cacheKey);
660
724
  if (staleCache && !forceRefresh) {
661
- 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
+ );
662
728
  return includeMetadata ? staleCache : staleCache.data;
663
729
  }
664
- throw this.normalizeError(error, `Failed to fetch collection '${collectionId}'`);
730
+ throw this.normalizeError(
731
+ error,
732
+ `Failed to fetch collection '${collectionId}'`
733
+ );
665
734
  }
666
735
  }
667
736
  /**
@@ -677,7 +746,8 @@ var ContentEngine = class {
677
746
  if (!forceRefresh && this.cacheStrategy === "memory") {
678
747
  const cached = this.memoryCache.get(cacheKey);
679
748
  if (cached && this.isCacheValid(cached.metadata)) {
680
- 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.");
681
751
  return cached.data;
682
752
  }
683
753
  }
@@ -701,13 +771,10 @@ var ContentEngine = class {
701
771
  await this.rateLimiter.checkLimit();
702
772
  const url = `${this.config.apiUrl}/content/${this.config.projectId}/globals`;
703
773
  const params = include.length > 0 ? `?include=${include.join(",")}` : "";
704
- const res = await this.fetchWithTimeout(
705
- `${url}${params}`,
706
- {
707
- method: "GET",
708
- headers: this.getHeaders()
709
- }
710
- );
774
+ const res = await this.fetchWithTimeout(`${url}${params}`, {
775
+ method: "GET",
776
+ headers: this.getHeaders()
777
+ });
711
778
  if (!res.ok) {
712
779
  throw new Error(`API Error ${res.status}: ${res.statusText}`);
713
780
  }
@@ -823,7 +890,8 @@ var ContentEngine = class {
823
890
  eventSource = new EventSource(url);
824
891
  eventSource.onopen = () => {
825
892
  retryCount = 0;
826
- 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");
827
895
  };
828
896
  eventSource.onmessage = (event) => {
829
897
  try {
@@ -844,7 +912,9 @@ var ContentEngine = class {
844
912
  if (isClosed) return;
845
913
  const timeout = Math.min(1e3 * Math.pow(2, retryCount), 1e4);
846
914
  retryCount++;
847
- 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
+ );
848
918
  setTimeout(connect, timeout);
849
919
  };
850
920
  };
@@ -858,7 +928,7 @@ var ContentEngine = class {
858
928
  /**
859
929
  * Check all caches in order of speed
860
930
  */
861
- checkCaches(key, forceRefresh, includeMetadata) {
931
+ async checkCaches(key, forceRefresh, includeMetadata) {
862
932
  if (forceRefresh) return null;
863
933
  if (this.cacheStrategy === "memory") {
864
934
  const cached = this.memoryCache.get(key);
@@ -883,7 +953,7 @@ var ContentEngine = class {
883
953
  if (process.env.NODE_ENV === "development") {
884
954
  if (key.startsWith("page:")) {
885
955
  const slug = key.split(":")[1];
886
- const local = this.localCache.getPage(slug);
956
+ const local = await this.localCache.getPage(slug);
887
957
  if (local) {
888
958
  return {
889
959
  data: local,
@@ -916,7 +986,9 @@ var ContentEngine = class {
916
986
  invalidateCache(tags) {
917
987
  this.memoryCache.invalidateByTags(tags);
918
988
  if (this.config.debug) {
919
- 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
+ );
920
992
  }
921
993
  }
922
994
  /**
@@ -956,7 +1028,9 @@ var ContentEngine = class {
956
1028
  });
957
1029
  if (!res.ok) {
958
1030
  if (res.status === 404) {
959
- 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
+ );
960
1034
  }
961
1035
  throw new Error(`API Error ${res.status}: ${res.statusText}`);
962
1036
  }
@@ -973,7 +1047,11 @@ var ContentEngine = class {
973
1047
  };
974
1048
  this.writeCache(cacheKey, cacheEntry.data, {
975
1049
  revalidate,
976
- 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
+ ]
977
1055
  });
978
1056
  return cacheEntry;
979
1057
  }
@@ -1003,7 +1081,11 @@ var ContentEngine = class {
1003
1081
  };
1004
1082
  this.writeCache(cacheKey, cacheEntry.data, {
1005
1083
  revalidate,
1006
- 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
+ ]
1007
1089
  });
1008
1090
  return cacheEntry;
1009
1091
  }
@@ -1184,6 +1266,15 @@ var getVisitorId = async () => {
1184
1266
  }
1185
1267
  return vid;
1186
1268
  };
1269
+
1270
+ // src/analytics/vitals.ts
1271
+ import {
1272
+ onCLS,
1273
+ onLCP,
1274
+ onTTFB,
1275
+ onINP,
1276
+ onFCP
1277
+ } from "web-vitals";
1187
1278
  var METRIC_KEY_MAP = {
1188
1279
  CLS: "cls",
1189
1280
  LCP: "lcp",
@@ -1306,10 +1397,12 @@ var EventStorage = class {
1306
1397
  return new Promise((resolve, reject) => {
1307
1398
  const transaction = this.db.transaction([STORE_NAME], "readwrite");
1308
1399
  const store = transaction.objectStore(STORE_NAME);
1400
+ let processed = 0;
1401
+ let errors = 0;
1309
1402
  transaction.oncomplete = () => resolve();
1310
1403
  transaction.onerror = () => reject(transaction.error);
1311
1404
  ids.forEach((id) => {
1312
- store.delete(id);
1405
+ const req = store.delete(id);
1313
1406
  });
1314
1407
  });
1315
1408
  }
@@ -1339,7 +1432,7 @@ var Tracker = class {
1339
1432
  // FIX: Add this property
1340
1433
  this.isFlushing = false;
1341
1434
  this.config = config;
1342
- this.config.apiUrl.replace("/v1", "").replace(/\/$/, "");
1435
+ const baseUrl = this.config.apiUrl.replace("/v1", "").replace(/\/$/, "");
1343
1436
  this.endpoint = `${this.config.analyticsUrl}/api/collect`;
1344
1437
  this.circuitBreaker = new CircuitBreaker();
1345
1438
  this.sessionStart = Date.now();
@@ -1761,6 +1854,14 @@ var NexusClient = class {
1761
1854
  };
1762
1855
  var nexus = new NexusClient();
1763
1856
  var createNexusClient = (config) => new NexusClient(config);
1857
+
1858
+ // src/components/NexusProvider.tsx
1859
+ import React2, { createContext as createContext2, useEffect as useEffect2, useRef, useMemo } from "react";
1860
+ import { usePathname, useSearchParams } from "next/navigation";
1861
+
1862
+ // src/auth/context.tsx
1863
+ import { createContext, useContext, useEffect, useState, useCallback } from "react";
1864
+ import { jsx } from "react/jsx-runtime";
1764
1865
  var AuthContext = createContext(null);
1765
1866
  var AuthProvider = ({
1766
1867
  children,
@@ -1935,7 +2036,10 @@ async function parseError(res) {
1935
2036
  };
1936
2037
  }
1937
2038
  }
1938
- var NexusContext = createContext(nexus);
2039
+
2040
+ // src/components/NexusProvider.tsx
2041
+ import { jsx as jsx2 } from "react/jsx-runtime";
2042
+ var NexusContext = createContext2(nexus);
1939
2043
  var NexusProvider = ({
1940
2044
  children,
1941
2045
  projectId,
@@ -1951,7 +2055,7 @@ var NexusProvider = ({
1951
2055
  }
1952
2056
  return nexus.getConfig();
1953
2057
  }, [projectId]);
1954
- useEffect(() => {
2058
+ useEffect2(() => {
1955
2059
  if (typeof window === "undefined" || disableAnalytics) return;
1956
2060
  if (!isInitialized.current) {
1957
2061
  if (!nexus.analytics) {
@@ -1970,15 +2074,36 @@ var NexusProvider = ({
1970
2074
  }
1971
2075
  };
1972
2076
  }, [disableAnalytics]);
1973
- useEffect(() => {
2077
+ useEffect2(() => {
1974
2078
  if (nexus.analytics && !disableAnalytics) {
1975
2079
  nexus.analytics.pageView();
1976
2080
  }
1977
2081
  }, [pathname, searchParams, disableAnalytics]);
1978
- return /* @__PURE__ */ jsx(NexusContext.Provider, { value: nexus, children: /* @__PURE__ */ jsx(AuthProvider, { config, children }) });
2082
+ return /* @__PURE__ */ jsx2(NexusContext.Provider, { value: nexus, children: /* @__PURE__ */ jsx2(AuthProvider, { config, children }) });
1979
2083
  };
1980
2084
 
1981
2085
  // src/index.ts
1982
2086
  var VERSION = "0.0.1";
1983
-
1984
- export { AnalyticsEngine, AuthProvider, BrowserCache, CacheTags, ContentEngine, DEFAULT_ANALYTICS_URL, DEFAULT_API_URL, LOCAL_NEST_URL, LOCAL_RUST_URL, MemoryCache, NexusClient, NexusProvider, VERSION, createNexusClient, getEnvConfig, getFullConfig, mergeConfigs, nexus, useNexusAuth, validateConfig };
2087
+ export {
2088
+ AnalyticsEngine,
2089
+ AuthProvider,
2090
+ BrowserCache,
2091
+ CacheTags,
2092
+ ContentEngine,
2093
+ DEFAULT_ANALYTICS_URL,
2094
+ DEFAULT_API_URL,
2095
+ LOCAL_NEST_URL,
2096
+ LOCAL_RUST_URL,
2097
+ LocalCacheProxy as LocalCache,
2098
+ MemoryCache,
2099
+ NexusClient,
2100
+ NexusProvider,
2101
+ VERSION,
2102
+ createNexusClient,
2103
+ getEnvConfig,
2104
+ getFullConfig,
2105
+ mergeConfigs,
2106
+ nexus,
2107
+ useNexusAuth,
2108
+ validateConfig
2109
+ };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@nexushub/client",
3
3
  "private": false,
4
- "version": "0.0.7",
4
+ "version": "0.0.9",
5
5
  "description": "The God-Tier NexusHub SDK",
6
6
  "type": "module",
7
7
  "main": "./dist/index.cjs",
@@ -18,6 +18,9 @@
18
18
  "nexus": "./dist/cli.cjs"
19
19
  },
20
20
  "browser": {
21
+ "fs": false,
22
+ "path": false,
23
+ "os": false,
21
24
  "./dist/content/local-cache-server.js": "./dist/content/local-cache-client.js",
22
25
  "./dist/content/local-cache-server.cjs": "./dist/content/local-cache-client.cjs"
23
26
  },
@@ -1,117 +0,0 @@
1
- 'use strict';
2
-
3
- var fs = require('fs');
4
- var path = require('path');
5
-
6
- function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
7
-
8
- var fs__default = /*#__PURE__*/_interopDefault(fs);
9
- var path__default = /*#__PURE__*/_interopDefault(path);
10
-
11
- // src/content/local-cache-server.ts
12
- var LocalCache = class {
13
- constructor(customPath) {
14
- this.data = null;
15
- this.hasLoaded = false;
16
- this.cachePath = customPath || ".nexus/cache.json";
17
- }
18
- /**
19
- * Returns true if the local cache file has been successfully
20
- * loaded and parsed into memory.
21
- */
22
- isLoaded() {
23
- return this.hasLoaded;
24
- }
25
- /**
26
- * Reads the cache file from the filesystem.
27
- * Internal method called lazily by the getters.
28
- */
29
- load() {
30
- if (typeof window !== "undefined") return;
31
- if (this.hasLoaded) return;
32
- try {
33
- const fullPath = path__default.default.resolve(process.cwd(), this.cachePath);
34
- if (fs__default.default.existsSync(fullPath)) {
35
- const fileContent = fs__default.default.readFileSync(fullPath, "utf-8");
36
- this.data = JSON.parse(fileContent);
37
- this.hasLoaded = true;
38
- if (process.env.NODE_ENV === "development") {
39
- console.log(
40
- `\u26A1 NexusHub: Serving content from local cache (${this.cachePath})`
41
- );
42
- console.log(` - Pages: ${this.data.pages?.length || 0}`);
43
- console.log(
44
- ` - Collections: ${Object.keys(this.data.collections || {}).length}`
45
- );
46
- console.log(
47
- ` - Globals: ${this.data.globals ? "Loaded" : "Not found"}`
48
- );
49
- }
50
- }
51
- } catch (error) {
52
- if (this.shouldWarnAboutMissingCache(error)) {
53
- console.warn(
54
- `\u26A0\uFE0F NexusHub: Local cache not found or invalid at ${this.cachePath}
55
- Run \`npx nexus pull\` to generate seed data if you want to work offline.`
56
- );
57
- }
58
- }
59
- }
60
- /**
61
- * Retrieve a specific page from the local pages array.
62
- */
63
- getPage(slug) {
64
- this.load();
65
- if (!this.data?.pages) return null;
66
- const page = this.data.pages.find((p) => p.slug === slug);
67
- if (!page) {
68
- if (process.env.NODE_ENV === "development") {
69
- console.warn(`\u26A0\uFE0F NexusHub: Page '${slug}' not found in local cache.`);
70
- }
71
- return null;
72
- }
73
- return page.data;
74
- }
75
- /**
76
- * Retrieve an entire collection from the local collections map.
77
- */
78
- getCollection(collectionId) {
79
- this.load();
80
- if (!this.data?.collections) return null;
81
- const collection = this.data.collections[collectionId];
82
- if (!collection) {
83
- if (process.env.NODE_ENV === "development") {
84
- console.warn(
85
- `\u26A0\uFE0F NexusHub: Collection '${collectionId}' not found in local cache.`
86
- );
87
- }
88
- return null;
89
- }
90
- return collection;
91
- }
92
- /**
93
- * Retrieve global settings from the local cache.
94
- */
95
- getGlobals() {
96
- this.load();
97
- return this.data?.globals || null;
98
- }
99
- /**
100
- * Returns the entire raw JSON data structure from the cache file.
101
- */
102
- getAllData() {
103
- this.load();
104
- return this.data;
105
- }
106
- /**
107
- * Helper to determine if we should bother the user with a warning.
108
- */
109
- shouldWarnAboutMissingCache(error) {
110
- const isMissing = error.code === "ENOENT";
111
- const isMalformed = error instanceof SyntaxError;
112
- if (process.env.NODE_ENV !== "development") return false;
113
- return !isMissing || isMalformed;
114
- }
115
- };
116
-
117
- exports.LocalCache = LocalCache;