@nexushub/client 0.0.7 → 0.0.8
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/cache-CtPpNvIZ.d.cts +11 -0
- package/dist/cache-CtPpNvIZ.d.ts +11 -0
- package/dist/chunk-3RG5ZIWI.js +10 -0
- package/dist/chunk-OBGZSXTJ.cjs +10 -0
- package/dist/content/local-cache-client.cjs +2 -1
- package/dist/content/local-cache-client.d.cts +4 -1
- package/dist/content/local-cache-client.d.ts +4 -1
- package/dist/content/local-cache-client.js +5 -2
- package/dist/content/local-cache-server.cjs +109 -7
- package/dist/content/local-cache-server.d.cts +3 -1
- package/dist/content/local-cache-server.d.ts +3 -1
- package/dist/content/local-cache-server.js +112 -1
- package/dist/index.cjs +189 -110
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +143 -40
- package/package.json +4 -1
- package/dist/chunk-2JRYABGG.cjs +0 -117
- package/dist/chunk-BPQMAYT3.js +0 -110
package/dist/index.cjs
CHANGED
|
@@ -1,10 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); 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; }
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
var webVitals = require('web-vitals');
|
|
5
|
-
var react = require('react');
|
|
6
|
-
var navigation = require('next/navigation');
|
|
7
|
-
var jsxRuntime = require('react/jsx-runtime');
|
|
3
|
+
var _chunkOBGZSXTJcjs = require('./chunk-OBGZSXTJ.cjs');
|
|
8
4
|
|
|
9
5
|
// src/config.ts
|
|
10
6
|
var DEFAULT_API_URL = "http://localhost:3001";
|
|
@@ -17,10 +13,10 @@ var hasEnv = () => {
|
|
|
17
13
|
var getEnvConfig = () => {
|
|
18
14
|
const env = hasEnv() ? process.env : {};
|
|
19
15
|
const isDev = env.NODE_ENV === "development" || env.NEXT_PUBLIC_NODE_ENV === "development";
|
|
20
|
-
const projectId = env.NEXT_PUBLIC_NEXUS_ID
|
|
21
|
-
const apiKey = env.NEXT_PUBLIC_NEXUS_KEY
|
|
22
|
-
const apiUrl = env.NEXT_PUBLIC_NEXUS_API_URL
|
|
23
|
-
const analyticsUrl = env.NEXT_PUBLIC_NEXUS_ANALYTICS_URL
|
|
16
|
+
const projectId = _nullishCoalesce(env.NEXT_PUBLIC_NEXUS_ID, () => ( env.NEXUS_PROJECT_ID));
|
|
17
|
+
const apiKey = _nullishCoalesce(env.NEXT_PUBLIC_NEXUS_KEY, () => ( env.NEXUS_API_KEY));
|
|
18
|
+
const apiUrl = _nullishCoalesce(_nullishCoalesce(env.NEXT_PUBLIC_NEXUS_API_URL, () => ( env.NEXUS_API_URL)), () => ( (isDev ? LOCAL_NEST_URL : DEFAULT_API_URL)));
|
|
19
|
+
const analyticsUrl = _nullishCoalesce(env.NEXT_PUBLIC_NEXUS_ANALYTICS_URL, () => ( (apiUrl.includes("localhost") ? LOCAL_RUST_URL : DEFAULT_ANALYTICS_URL)));
|
|
24
20
|
return {
|
|
25
21
|
projectId,
|
|
26
22
|
apiKey,
|
|
@@ -177,7 +173,7 @@ var MemoryCache = class {
|
|
|
177
173
|
try {
|
|
178
174
|
const jsonString = JSON.stringify(data);
|
|
179
175
|
return new Blob([jsonString]).size;
|
|
180
|
-
} catch {
|
|
176
|
+
} catch (e2) {
|
|
181
177
|
return 0;
|
|
182
178
|
}
|
|
183
179
|
}
|
|
@@ -237,7 +233,7 @@ var BrowserCache = class {
|
|
|
237
233
|
return null;
|
|
238
234
|
}
|
|
239
235
|
return entry.data;
|
|
240
|
-
} catch {
|
|
236
|
+
} catch (e3) {
|
|
241
237
|
this.delete(key);
|
|
242
238
|
return null;
|
|
243
239
|
}
|
|
@@ -256,7 +252,7 @@ var BrowserCache = class {
|
|
|
256
252
|
const keysToRemove = [];
|
|
257
253
|
for (let i = 0; i < localStorage.length; i++) {
|
|
258
254
|
const key = localStorage.key(i);
|
|
259
|
-
if (key
|
|
255
|
+
if (_optionalChain([key, 'optionalAccess', _ => _.startsWith, 'call', _2 => _2(this.prefix)])) {
|
|
260
256
|
keysToRemove.push(key);
|
|
261
257
|
}
|
|
262
258
|
}
|
|
@@ -270,7 +266,7 @@ var BrowserCache = class {
|
|
|
270
266
|
this.currentSize = 0;
|
|
271
267
|
for (let i = 0; i < localStorage.length; i++) {
|
|
272
268
|
const key = localStorage.key(i);
|
|
273
|
-
if (key
|
|
269
|
+
if (_optionalChain([key, 'optionalAccess', _3 => _3.startsWith, 'call', _4 => _4(this.prefix)])) {
|
|
274
270
|
const item = localStorage.getItem(key);
|
|
275
271
|
if (item) {
|
|
276
272
|
this.currentSize += new Blob([item]).size;
|
|
@@ -286,7 +282,7 @@ var BrowserCache = class {
|
|
|
286
282
|
let oldestTime = Infinity;
|
|
287
283
|
for (let i = 0; i < localStorage.length; i++) {
|
|
288
284
|
const key = localStorage.key(i);
|
|
289
|
-
if (key
|
|
285
|
+
if (_optionalChain([key, 'optionalAccess', _5 => _5.startsWith, 'call', _6 => _6(this.prefix)])) {
|
|
290
286
|
const item = localStorage.getItem(key);
|
|
291
287
|
if (item) {
|
|
292
288
|
try {
|
|
@@ -295,7 +291,7 @@ var BrowserCache = class {
|
|
|
295
291
|
oldestTime = entry.metadata.timestamp;
|
|
296
292
|
oldestKey = key;
|
|
297
293
|
}
|
|
298
|
-
} catch {
|
|
294
|
+
} catch (e4) {
|
|
299
295
|
localStorage.removeItem(key);
|
|
300
296
|
}
|
|
301
297
|
}
|
|
@@ -311,6 +307,22 @@ var BrowserCache = class {
|
|
|
311
307
|
}
|
|
312
308
|
};
|
|
313
309
|
|
|
310
|
+
// src/content/cache.ts
|
|
311
|
+
var LocalCacheConstructor;
|
|
312
|
+
if (typeof window === "undefined") {
|
|
313
|
+
try {
|
|
314
|
+
const serverPath = "./local-cache-server";
|
|
315
|
+
LocalCacheConstructor = _chunkOBGZSXTJcjs.__require.call(void 0, serverPath).LocalCache;
|
|
316
|
+
} catch (e) {
|
|
317
|
+
LocalCacheConstructor = class Dummy {
|
|
318
|
+
};
|
|
319
|
+
}
|
|
320
|
+
} else {
|
|
321
|
+
const clientPath = "./local-cache-client";
|
|
322
|
+
LocalCacheConstructor = _chunkOBGZSXTJcjs.__require.call(void 0, clientPath).LocalCache;
|
|
323
|
+
}
|
|
324
|
+
var LocalCache = LocalCacheConstructor;
|
|
325
|
+
|
|
314
326
|
// src/content/strategies.ts
|
|
315
327
|
var RateLimiter = class {
|
|
316
328
|
constructor(config) {
|
|
@@ -322,7 +334,7 @@ var RateLimiter = class {
|
|
|
322
334
|
const windowStart = now - this.config.timeWindow;
|
|
323
335
|
this.requests = this.requests.filter((time) => time > windowStart);
|
|
324
336
|
if (this.requests.length >= this.config.maxRequests) {
|
|
325
|
-
this.requests[0];
|
|
337
|
+
const oldestRequest = this.requests[0];
|
|
326
338
|
const waitTime = windowStart + this.config.timeWindow - now;
|
|
327
339
|
if (waitTime > 0) {
|
|
328
340
|
await new Promise((resolve) => setTimeout(resolve, waitTime));
|
|
@@ -379,10 +391,10 @@ var ExponentialBackoff = class {
|
|
|
379
391
|
return delay;
|
|
380
392
|
}
|
|
381
393
|
isClientError(error) {
|
|
382
|
-
return error
|
|
394
|
+
return _optionalChain([error, 'optionalAccess', _7 => _7.status]) >= 400 && _optionalChain([error, 'optionalAccess', _8 => _8.status]) < 500;
|
|
383
395
|
}
|
|
384
396
|
isRateLimitError(error) {
|
|
385
|
-
return error
|
|
397
|
+
return _optionalChain([error, 'optionalAccess', _9 => _9.status]) === 429;
|
|
386
398
|
}
|
|
387
399
|
};
|
|
388
400
|
var CircuitBreaker = class {
|
|
@@ -496,10 +508,10 @@ function buildQueryString(query) {
|
|
|
496
508
|
if (query.sort) params.append("sort", query.sort);
|
|
497
509
|
if (query.order) params.append("order", query.order);
|
|
498
510
|
if (query.search) params.append("search", query.search);
|
|
499
|
-
if (query.include
|
|
511
|
+
if (_optionalChain([query, 'access', _10 => _10.include, 'optionalAccess', _11 => _11.length])) {
|
|
500
512
|
params.append("include", query.include.join(","));
|
|
501
513
|
}
|
|
502
|
-
if (query.fields
|
|
514
|
+
if (_optionalChain([query, 'access', _12 => _12.fields, 'optionalAccess', _13 => _13.length])) {
|
|
503
515
|
params.append("fields", query.fields.join(","));
|
|
504
516
|
}
|
|
505
517
|
if (query.filter) {
|
|
@@ -522,7 +534,7 @@ var ContentEngine = class {
|
|
|
522
534
|
constructor(config) {
|
|
523
535
|
this.config = config;
|
|
524
536
|
this.isServer = typeof window === "undefined";
|
|
525
|
-
this.localCache = new
|
|
537
|
+
this.localCache = new LocalCache();
|
|
526
538
|
this.memoryCache = new MemoryCache({
|
|
527
539
|
maxSize: 500,
|
|
528
540
|
ttl: 5 * 60 * 1e3
|
|
@@ -558,7 +570,9 @@ var ContentEngine = class {
|
|
|
558
570
|
() => this._getPage(slug, options)
|
|
559
571
|
);
|
|
560
572
|
if (this.config.debug && duration > 100) {
|
|
561
|
-
console.warn(
|
|
573
|
+
console.warn(
|
|
574
|
+
`[NexusHub] \u26A0\uFE0F getPage("${slug}") took ${duration.toFixed(2)}ms`
|
|
575
|
+
);
|
|
562
576
|
}
|
|
563
577
|
return result;
|
|
564
578
|
}
|
|
@@ -583,11 +597,19 @@ var ContentEngine = class {
|
|
|
583
597
|
await this.rateLimiter.checkLimit();
|
|
584
598
|
const data = await this.backoff.execute(
|
|
585
599
|
async () => {
|
|
586
|
-
return this.fetchPage(
|
|
600
|
+
return this.fetchPage(
|
|
601
|
+
slug,
|
|
602
|
+
cacheKey,
|
|
603
|
+
tags,
|
|
604
|
+
revalidate,
|
|
605
|
+
forceRefresh
|
|
606
|
+
);
|
|
587
607
|
},
|
|
588
608
|
(attempt, delay, error) => {
|
|
589
609
|
if (this.config.debug) {
|
|
590
|
-
console.log(
|
|
610
|
+
console.log(
|
|
611
|
+
`[NexusHub] \u{1F504} Retry ${attempt} for '${slug}' after ${delay}ms: ${error.message}`
|
|
612
|
+
);
|
|
591
613
|
}
|
|
592
614
|
}
|
|
593
615
|
);
|
|
@@ -612,7 +634,9 @@ var ContentEngine = class {
|
|
|
612
634
|
() => this._getCollection(collectionId, query, options)
|
|
613
635
|
);
|
|
614
636
|
if (this.config.debug && duration > 100) {
|
|
615
|
-
console.warn(
|
|
637
|
+
console.warn(
|
|
638
|
+
`[NexusHub] \u26A0\uFE0F getCollection("${collectionId}") took ${duration.toFixed(2)}ms`
|
|
639
|
+
);
|
|
616
640
|
}
|
|
617
641
|
return result;
|
|
618
642
|
}
|
|
@@ -626,19 +650,30 @@ var ContentEngine = class {
|
|
|
626
650
|
} = options;
|
|
627
651
|
const queryString = buildQueryString(normalizedQuery);
|
|
628
652
|
const cacheKey = `collection:${collectionId}:${queryString}`;
|
|
629
|
-
const cached = this.checkCaches(
|
|
653
|
+
const cached = this.checkCaches(
|
|
654
|
+
cacheKey,
|
|
655
|
+
forceRefresh,
|
|
656
|
+
includeMetadata
|
|
657
|
+
);
|
|
630
658
|
if (cached) {
|
|
631
659
|
if (this.config.debug) {
|
|
632
|
-
console.log(
|
|
660
|
+
console.log(
|
|
661
|
+
`[NexusHub] \u26A1 Served collection '${collectionId}' from memory cache.`
|
|
662
|
+
);
|
|
633
663
|
}
|
|
634
664
|
return includeMetadata ? cached : cached.data;
|
|
635
665
|
}
|
|
636
666
|
if (!forceRefresh && process.env.NODE_ENV === "development") {
|
|
637
667
|
const localCollection = this.localCache.getCollection(collectionId);
|
|
638
668
|
if (localCollection) {
|
|
639
|
-
const result = this.applyLocalQuery(
|
|
669
|
+
const result = this.applyLocalQuery(
|
|
670
|
+
localCollection,
|
|
671
|
+
normalizedQuery
|
|
672
|
+
);
|
|
640
673
|
if (this.config.debug) {
|
|
641
|
-
console.log(
|
|
674
|
+
console.log(
|
|
675
|
+
`[NexusHub] \u{1F4C1} Served collection '${collectionId}' from local cache.`
|
|
676
|
+
);
|
|
642
677
|
}
|
|
643
678
|
this.memoryCache.set(cacheKey, result, {
|
|
644
679
|
tags: [...tags, CacheTags.collection(collectionId)],
|
|
@@ -651,7 +686,13 @@ var ContentEngine = class {
|
|
|
651
686
|
try {
|
|
652
687
|
await this.rateLimiter.checkLimit();
|
|
653
688
|
const result = await this.backoff.execute(async () => {
|
|
654
|
-
return this.fetchCollection(
|
|
689
|
+
return this.fetchCollection(
|
|
690
|
+
collectionId,
|
|
691
|
+
normalizedQuery,
|
|
692
|
+
cacheKey,
|
|
693
|
+
tags,
|
|
694
|
+
revalidate
|
|
695
|
+
);
|
|
655
696
|
});
|
|
656
697
|
this.circuitBreaker.recordSuccess();
|
|
657
698
|
return includeMetadata ? result : result.data;
|
|
@@ -659,10 +700,15 @@ var ContentEngine = class {
|
|
|
659
700
|
this.circuitBreaker.recordFailure();
|
|
660
701
|
const staleCache = this.memoryCache.get(cacheKey);
|
|
661
702
|
if (staleCache && !forceRefresh) {
|
|
662
|
-
console.warn(
|
|
703
|
+
console.warn(
|
|
704
|
+
`[NexusHub] \u26A0\uFE0F Using stale cache for collection '${collectionId}'`
|
|
705
|
+
);
|
|
663
706
|
return includeMetadata ? staleCache : staleCache.data;
|
|
664
707
|
}
|
|
665
|
-
throw this.normalizeError(
|
|
708
|
+
throw this.normalizeError(
|
|
709
|
+
error,
|
|
710
|
+
`Failed to fetch collection '${collectionId}'`
|
|
711
|
+
);
|
|
666
712
|
}
|
|
667
713
|
}
|
|
668
714
|
/**
|
|
@@ -678,7 +724,8 @@ var ContentEngine = class {
|
|
|
678
724
|
if (!forceRefresh && this.cacheStrategy === "memory") {
|
|
679
725
|
const cached = this.memoryCache.get(cacheKey);
|
|
680
726
|
if (cached && this.isCacheValid(cached.metadata)) {
|
|
681
|
-
if (this.config.debug)
|
|
727
|
+
if (this.config.debug)
|
|
728
|
+
console.log("[NexusHub] \u26A1 Served globals from memory cache.");
|
|
682
729
|
return cached.data;
|
|
683
730
|
}
|
|
684
731
|
}
|
|
@@ -702,13 +749,10 @@ var ContentEngine = class {
|
|
|
702
749
|
await this.rateLimiter.checkLimit();
|
|
703
750
|
const url = `${this.config.apiUrl}/content/${this.config.projectId}/globals`;
|
|
704
751
|
const params = include.length > 0 ? `?include=${include.join(",")}` : "";
|
|
705
|
-
const res = await this.fetchWithTimeout(
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
headers: this.getHeaders()
|
|
710
|
-
}
|
|
711
|
-
);
|
|
752
|
+
const res = await this.fetchWithTimeout(`${url}${params}`, {
|
|
753
|
+
method: "GET",
|
|
754
|
+
headers: this.getHeaders()
|
|
755
|
+
});
|
|
712
756
|
if (!res.ok) {
|
|
713
757
|
throw new Error(`API Error ${res.status}: ${res.statusText}`);
|
|
714
758
|
}
|
|
@@ -745,7 +789,7 @@ var ContentEngine = class {
|
|
|
745
789
|
}
|
|
746
790
|
return this.requestBatcher.schedule(cacheKey, async () => {
|
|
747
791
|
const params = new URLSearchParams();
|
|
748
|
-
if (options.include
|
|
792
|
+
if (_optionalChain([options, 'access', _14 => _14.include, 'optionalAccess', _15 => _15.length])) {
|
|
749
793
|
params.append("include", options.include.join(","));
|
|
750
794
|
}
|
|
751
795
|
const url = `${this.config.apiUrl}/content/${this.config.projectId}/collection/${collectionId}/${itemId}?${params}`;
|
|
@@ -778,10 +822,10 @@ var ContentEngine = class {
|
|
|
778
822
|
q: query,
|
|
779
823
|
limit: (options.limit || 20).toString()
|
|
780
824
|
});
|
|
781
|
-
if (options.collections
|
|
825
|
+
if (_optionalChain([options, 'access', _16 => _16.collections, 'optionalAccess', _17 => _17.length])) {
|
|
782
826
|
params.append("collections", options.collections.join(","));
|
|
783
827
|
}
|
|
784
|
-
if (options.fields
|
|
828
|
+
if (_optionalChain([options, 'access', _18 => _18.fields, 'optionalAccess', _19 => _19.length])) {
|
|
785
829
|
params.append("fields", options.fields.join(","));
|
|
786
830
|
}
|
|
787
831
|
const url = `${this.config.apiUrl}/content/${this.config.projectId}/search?${params}`;
|
|
@@ -824,7 +868,8 @@ var ContentEngine = class {
|
|
|
824
868
|
eventSource = new EventSource(url);
|
|
825
869
|
eventSource.onopen = () => {
|
|
826
870
|
retryCount = 0;
|
|
827
|
-
if (this.config.debug)
|
|
871
|
+
if (this.config.debug)
|
|
872
|
+
console.log("[NexusHub] \u{1F7E2} Real-time stream connected");
|
|
828
873
|
};
|
|
829
874
|
eventSource.onmessage = (event) => {
|
|
830
875
|
try {
|
|
@@ -841,18 +886,20 @@ var ContentEngine = class {
|
|
|
841
886
|
}
|
|
842
887
|
};
|
|
843
888
|
eventSource.onerror = () => {
|
|
844
|
-
eventSource
|
|
889
|
+
_optionalChain([eventSource, 'optionalAccess', _20 => _20.close, 'call', _21 => _21()]);
|
|
845
890
|
if (isClosed) return;
|
|
846
891
|
const timeout = Math.min(1e3 * Math.pow(2, retryCount), 1e4);
|
|
847
892
|
retryCount++;
|
|
848
|
-
console.warn(
|
|
893
|
+
console.warn(
|
|
894
|
+
`[NexusHub] \u{1F534} Stream disconnected. Reconnecting in ${timeout}ms...`
|
|
895
|
+
);
|
|
849
896
|
setTimeout(connect, timeout);
|
|
850
897
|
};
|
|
851
898
|
};
|
|
852
899
|
connect();
|
|
853
900
|
return () => {
|
|
854
901
|
isClosed = true;
|
|
855
|
-
eventSource
|
|
902
|
+
_optionalChain([eventSource, 'optionalAccess', _22 => _22.close, 'call', _23 => _23()]);
|
|
856
903
|
};
|
|
857
904
|
}
|
|
858
905
|
// --- CACHE MANAGEMENT ---
|
|
@@ -917,7 +964,9 @@ var ContentEngine = class {
|
|
|
917
964
|
invalidateCache(tags) {
|
|
918
965
|
this.memoryCache.invalidateByTags(tags);
|
|
919
966
|
if (this.config.debug) {
|
|
920
|
-
console.log(
|
|
967
|
+
console.log(
|
|
968
|
+
`[NexusHub] \u267B\uFE0F Invalidated cache for tags: ${tags.join(", ")}`
|
|
969
|
+
);
|
|
921
970
|
}
|
|
922
971
|
}
|
|
923
972
|
/**
|
|
@@ -957,7 +1006,9 @@ var ContentEngine = class {
|
|
|
957
1006
|
});
|
|
958
1007
|
if (!res.ok) {
|
|
959
1008
|
if (res.status === 404) {
|
|
960
|
-
throw new Error(
|
|
1009
|
+
throw new Error(
|
|
1010
|
+
`Page '${slug}' not found. Check your Dashboard or Seed data.`
|
|
1011
|
+
);
|
|
961
1012
|
}
|
|
962
1013
|
throw new Error(`API Error ${res.status}: ${res.statusText}`);
|
|
963
1014
|
}
|
|
@@ -974,7 +1025,11 @@ var ContentEngine = class {
|
|
|
974
1025
|
};
|
|
975
1026
|
this.writeCache(cacheKey, cacheEntry.data, {
|
|
976
1027
|
revalidate,
|
|
977
|
-
tags: [
|
|
1028
|
+
tags: [
|
|
1029
|
+
CacheTags.project(this.config.projectId),
|
|
1030
|
+
CacheTags.content(slug),
|
|
1031
|
+
...tags
|
|
1032
|
+
]
|
|
978
1033
|
});
|
|
979
1034
|
return cacheEntry;
|
|
980
1035
|
}
|
|
@@ -1004,7 +1059,11 @@ var ContentEngine = class {
|
|
|
1004
1059
|
};
|
|
1005
1060
|
this.writeCache(cacheKey, cacheEntry.data, {
|
|
1006
1061
|
revalidate,
|
|
1007
|
-
tags: [
|
|
1062
|
+
tags: [
|
|
1063
|
+
CacheTags.project(this.config.projectId),
|
|
1064
|
+
CacheTags.collection(collectionId),
|
|
1065
|
+
...tags
|
|
1066
|
+
]
|
|
1008
1067
|
});
|
|
1009
1068
|
return cacheEntry;
|
|
1010
1069
|
}
|
|
@@ -1156,7 +1215,7 @@ var generateCanvasHash = async () => {
|
|
|
1156
1215
|
hash = hash & hash;
|
|
1157
1216
|
}
|
|
1158
1217
|
return hash.toString(16);
|
|
1159
|
-
} catch {
|
|
1218
|
+
} catch (e5) {
|
|
1160
1219
|
return "";
|
|
1161
1220
|
}
|
|
1162
1221
|
};
|
|
@@ -1185,6 +1244,15 @@ var getVisitorId = async () => {
|
|
|
1185
1244
|
}
|
|
1186
1245
|
return vid;
|
|
1187
1246
|
};
|
|
1247
|
+
|
|
1248
|
+
// src/analytics/vitals.ts
|
|
1249
|
+
|
|
1250
|
+
|
|
1251
|
+
|
|
1252
|
+
|
|
1253
|
+
|
|
1254
|
+
|
|
1255
|
+
var _webvitals = require('web-vitals');
|
|
1188
1256
|
var METRIC_KEY_MAP = {
|
|
1189
1257
|
CLS: "cls",
|
|
1190
1258
|
LCP: "lcp",
|
|
@@ -1206,11 +1274,11 @@ var VitalsCollector = class {
|
|
|
1206
1274
|
this.metrics[key] = metric.value;
|
|
1207
1275
|
this.hasUpdates = true;
|
|
1208
1276
|
};
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1277
|
+
_webvitals.onCLS.call(void 0, recordMetric);
|
|
1278
|
+
_webvitals.onLCP.call(void 0, recordMetric);
|
|
1279
|
+
_webvitals.onTTFB.call(void 0, recordMetric);
|
|
1280
|
+
_webvitals.onINP.call(void 0, recordMetric);
|
|
1281
|
+
_webvitals.onFCP.call(void 0, recordMetric);
|
|
1214
1282
|
const navEntry = performance.getEntriesByType("navigation")[0];
|
|
1215
1283
|
if (navEntry) {
|
|
1216
1284
|
this.metrics.navigation_timing = {
|
|
@@ -1307,10 +1375,12 @@ var EventStorage = class {
|
|
|
1307
1375
|
return new Promise((resolve, reject) => {
|
|
1308
1376
|
const transaction = this.db.transaction([STORE_NAME], "readwrite");
|
|
1309
1377
|
const store = transaction.objectStore(STORE_NAME);
|
|
1378
|
+
let processed = 0;
|
|
1379
|
+
let errors = 0;
|
|
1310
1380
|
transaction.oncomplete = () => resolve();
|
|
1311
1381
|
transaction.onerror = () => reject(transaction.error);
|
|
1312
1382
|
ids.forEach((id) => {
|
|
1313
|
-
store.delete(id);
|
|
1383
|
+
const req = store.delete(id);
|
|
1314
1384
|
});
|
|
1315
1385
|
});
|
|
1316
1386
|
}
|
|
@@ -1340,7 +1410,7 @@ var Tracker = class {
|
|
|
1340
1410
|
// FIX: Add this property
|
|
1341
1411
|
this.isFlushing = false;
|
|
1342
1412
|
this.config = config;
|
|
1343
|
-
this.config.apiUrl.replace("/v1", "").replace(/\/$/, "");
|
|
1413
|
+
const baseUrl = this.config.apiUrl.replace("/v1", "").replace(/\/$/, "");
|
|
1344
1414
|
this.endpoint = `${this.config.analyticsUrl}/api/collect`;
|
|
1345
1415
|
this.circuitBreaker = new CircuitBreaker();
|
|
1346
1416
|
this.sessionStart = Date.now();
|
|
@@ -1518,8 +1588,8 @@ var AnalyticsEngine = class {
|
|
|
1518
1588
|
navigator.share = (data) => {
|
|
1519
1589
|
this.tracker.send("social_share", {
|
|
1520
1590
|
method: "native_share_menu",
|
|
1521
|
-
url: data
|
|
1522
|
-
title: data
|
|
1591
|
+
url: _optionalChain([data, 'optionalAccess', _24 => _24.url]) || window.location.href,
|
|
1592
|
+
title: _optionalChain([data, 'optionalAccess', _25 => _25.title])
|
|
1523
1593
|
});
|
|
1524
1594
|
return originalShare.apply(navigator, [data]);
|
|
1525
1595
|
};
|
|
@@ -1650,7 +1720,7 @@ var AnalyticsEngine = class {
|
|
|
1650
1720
|
this.tracker.send("click", {
|
|
1651
1721
|
element_type: "link",
|
|
1652
1722
|
href: link.href,
|
|
1653
|
-
text: link.innerText
|
|
1723
|
+
text: _optionalChain([link, 'access', _26 => _26.innerText, 'optionalAccess', _27 => _27.substring, 'call', _28 => _28(0, 50)]),
|
|
1654
1724
|
id: link.id,
|
|
1655
1725
|
classes: link.className,
|
|
1656
1726
|
dataset: { ...link.dataset }
|
|
@@ -1660,7 +1730,7 @@ var AnalyticsEngine = class {
|
|
|
1660
1730
|
if (button) {
|
|
1661
1731
|
this.tracker.send("click", {
|
|
1662
1732
|
element_type: "button",
|
|
1663
|
-
text: button.innerText
|
|
1733
|
+
text: _optionalChain([button, 'access', _29 => _29.innerText, 'optionalAccess', _30 => _30.substring, 'call', _31 => _31(0, 50)]),
|
|
1664
1734
|
id: button.id,
|
|
1665
1735
|
classes: button.className,
|
|
1666
1736
|
coordinates: { x: e.clientX, y: e.clientY }
|
|
@@ -1730,11 +1800,11 @@ var NexusClient = class {
|
|
|
1730
1800
|
constructor(config) {
|
|
1731
1801
|
const fullConfig = getFullConfig(config);
|
|
1732
1802
|
this.config = {
|
|
1733
|
-
debug: config
|
|
1734
|
-
cacheStrategy: config
|
|
1735
|
-
revalidateTime: config
|
|
1736
|
-
timeout: config
|
|
1737
|
-
retries: config
|
|
1803
|
+
debug: _optionalChain([config, 'optionalAccess', _32 => _32.debug]) || false,
|
|
1804
|
+
cacheStrategy: _optionalChain([config, 'optionalAccess', _33 => _33.cacheStrategy]) || "memory",
|
|
1805
|
+
revalidateTime: _optionalChain([config, 'optionalAccess', _34 => _34.revalidateTime]) || 60,
|
|
1806
|
+
timeout: _optionalChain([config, 'optionalAccess', _35 => _35.timeout]) || 1e4,
|
|
1807
|
+
retries: _optionalChain([config, 'optionalAccess', _36 => _36.retries]) || 3,
|
|
1738
1808
|
...fullConfig
|
|
1739
1809
|
};
|
|
1740
1810
|
this.content = new ContentEngine(this.config);
|
|
@@ -1762,16 +1832,24 @@ var NexusClient = class {
|
|
|
1762
1832
|
};
|
|
1763
1833
|
var nexus = new NexusClient();
|
|
1764
1834
|
var createNexusClient = (config) => new NexusClient(config);
|
|
1765
|
-
|
|
1835
|
+
|
|
1836
|
+
// src/components/NexusProvider.tsx
|
|
1837
|
+
var _react = require('react'); var _react2 = _interopRequireDefault(_react);
|
|
1838
|
+
var _navigation = require('next/navigation');
|
|
1839
|
+
|
|
1840
|
+
// src/auth/context.tsx
|
|
1841
|
+
|
|
1842
|
+
var _jsxruntime = require('react/jsx-runtime');
|
|
1843
|
+
var AuthContext = _react.createContext.call(void 0, null);
|
|
1766
1844
|
var AuthProvider = ({
|
|
1767
1845
|
children,
|
|
1768
1846
|
config
|
|
1769
1847
|
}) => {
|
|
1770
|
-
const [user, setUser] =
|
|
1771
|
-
const [isLoading, setIsLoading] =
|
|
1772
|
-
const [error, setError] =
|
|
1848
|
+
const [user, setUser] = _react.useState.call(void 0, null);
|
|
1849
|
+
const [isLoading, setIsLoading] = _react.useState.call(void 0, true);
|
|
1850
|
+
const [error, setError] = _react.useState.call(void 0, null);
|
|
1773
1851
|
const AUTH_BASE = `${config.apiUrl}/auth/project/${config.projectId}`;
|
|
1774
|
-
const checkSession =
|
|
1852
|
+
const checkSession = _react.useCallback.call(void 0, async () => {
|
|
1775
1853
|
try {
|
|
1776
1854
|
const res = await fetch(`${AUTH_BASE}/me`, {
|
|
1777
1855
|
headers: getHeaders(config)
|
|
@@ -1796,7 +1874,7 @@ var AuthProvider = ({
|
|
|
1796
1874
|
setIsLoading(false);
|
|
1797
1875
|
}
|
|
1798
1876
|
}, [AUTH_BASE, config]);
|
|
1799
|
-
|
|
1877
|
+
_react.useEffect.call(void 0, () => {
|
|
1800
1878
|
checkSession();
|
|
1801
1879
|
}, [checkSession]);
|
|
1802
1880
|
const login = async (creds) => {
|
|
@@ -1893,7 +1971,7 @@ var AuthProvider = ({
|
|
|
1893
1971
|
});
|
|
1894
1972
|
if (!res.ok) throw await parseError(res);
|
|
1895
1973
|
};
|
|
1896
|
-
return /* @__PURE__ */
|
|
1974
|
+
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, AuthContext.Provider, { value: {
|
|
1897
1975
|
user,
|
|
1898
1976
|
isLoading,
|
|
1899
1977
|
error,
|
|
@@ -1906,7 +1984,7 @@ var AuthProvider = ({
|
|
|
1906
1984
|
}, children });
|
|
1907
1985
|
};
|
|
1908
1986
|
var useNexusAuth = () => {
|
|
1909
|
-
const context =
|
|
1987
|
+
const context = _react.useContext.call(void 0, AuthContext);
|
|
1910
1988
|
if (!context) {
|
|
1911
1989
|
throw new Error("useNexusAuth must be used within a NexusProvider");
|
|
1912
1990
|
}
|
|
@@ -1928,7 +2006,7 @@ async function parseError(res) {
|
|
|
1928
2006
|
code: json.code || "UNKNOWN_ERROR",
|
|
1929
2007
|
message: json.message || "An error occurred during authentication"
|
|
1930
2008
|
};
|
|
1931
|
-
} catch {
|
|
2009
|
+
} catch (e6) {
|
|
1932
2010
|
return {
|
|
1933
2011
|
status: res.status,
|
|
1934
2012
|
code: "NETWORK_ERROR",
|
|
@@ -1936,23 +2014,26 @@ async function parseError(res) {
|
|
|
1936
2014
|
};
|
|
1937
2015
|
}
|
|
1938
2016
|
}
|
|
1939
|
-
|
|
2017
|
+
|
|
2018
|
+
// src/components/NexusProvider.tsx
|
|
2019
|
+
|
|
2020
|
+
var NexusContext = _react.createContext.call(void 0, nexus);
|
|
1940
2021
|
var NexusProvider = ({
|
|
1941
2022
|
children,
|
|
1942
2023
|
projectId,
|
|
1943
2024
|
disableAnalytics = false
|
|
1944
2025
|
}) => {
|
|
1945
|
-
const pathname =
|
|
1946
|
-
const searchParams =
|
|
1947
|
-
const isInitialized =
|
|
1948
|
-
const config =
|
|
2026
|
+
const pathname = _navigation.usePathname.call(void 0, );
|
|
2027
|
+
const searchParams = _navigation.useSearchParams.call(void 0, );
|
|
2028
|
+
const isInitialized = _react.useRef.call(void 0, false);
|
|
2029
|
+
const config = _react.useMemo.call(void 0, () => {
|
|
1949
2030
|
const currentConfig = nexus.getConfig();
|
|
1950
2031
|
if (projectId && currentConfig.projectId !== projectId) {
|
|
1951
2032
|
nexus.config.projectId = projectId;
|
|
1952
2033
|
}
|
|
1953
2034
|
return nexus.getConfig();
|
|
1954
2035
|
}, [projectId]);
|
|
1955
|
-
|
|
2036
|
+
_react.useEffect.call(void 0, () => {
|
|
1956
2037
|
if (typeof window === "undefined" || disableAnalytics) return;
|
|
1957
2038
|
if (!isInitialized.current) {
|
|
1958
2039
|
if (!nexus.analytics) {
|
|
@@ -1971,38 +2052,36 @@ var NexusProvider = ({
|
|
|
1971
2052
|
}
|
|
1972
2053
|
};
|
|
1973
2054
|
}, [disableAnalytics]);
|
|
1974
|
-
|
|
2055
|
+
_react.useEffect.call(void 0, () => {
|
|
1975
2056
|
if (nexus.analytics && !disableAnalytics) {
|
|
1976
2057
|
nexus.analytics.pageView();
|
|
1977
2058
|
}
|
|
1978
2059
|
}, [pathname, searchParams, disableAnalytics]);
|
|
1979
|
-
return /* @__PURE__ */
|
|
2060
|
+
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, NexusContext.Provider, { value: nexus, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, AuthProvider, { config, children }) });
|
|
1980
2061
|
};
|
|
1981
2062
|
|
|
1982
2063
|
// src/index.ts
|
|
1983
2064
|
var VERSION = "0.0.1";
|
|
1984
2065
|
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
|
|
1988
|
-
|
|
1989
|
-
|
|
1990
|
-
|
|
1991
|
-
|
|
1992
|
-
|
|
1993
|
-
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
|
|
1999
|
-
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
|
|
2004
|
-
|
|
2005
|
-
|
|
2006
|
-
exports.nexus = nexus;
|
|
2007
|
-
exports.useNexusAuth = useNexusAuth;
|
|
2008
|
-
exports.validateConfig = validateConfig;
|
|
2066
|
+
|
|
2067
|
+
|
|
2068
|
+
|
|
2069
|
+
|
|
2070
|
+
|
|
2071
|
+
|
|
2072
|
+
|
|
2073
|
+
|
|
2074
|
+
|
|
2075
|
+
|
|
2076
|
+
|
|
2077
|
+
|
|
2078
|
+
|
|
2079
|
+
|
|
2080
|
+
|
|
2081
|
+
|
|
2082
|
+
|
|
2083
|
+
|
|
2084
|
+
|
|
2085
|
+
|
|
2086
|
+
|
|
2087
|
+
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 = LocalCache; 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;
|
package/dist/index.d.cts
CHANGED
package/dist/index.d.ts
CHANGED