@nexushub/client 0.4.1 → 0.4.2

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,362 +1,7 @@
1
- import * as react_jsx_runtime from 'react/jsx-runtime';
2
- import React from 'react';
1
+ export { A as AnalyticsEngine, a as AuthContextType, b as AuthError, c as AuthProvider, d as AuthState, C as CacheEntry, e as CacheMetadata, f as CollectionQuery, g as CollectionResponse, h as ContentEngine, i as ContentResponse, D as DEFAULT_ANALYTICS_URL, j as DEFAULT_API_URL, E as ErrorResponse, L as LOCAL_NEST_URL, k as LOCAL_RUST_URL, l as LoginCredentials, M as MinimalNexusConfig, N as NexusClient, m as NexusConfig, n as NexusProvider, o as NexusProviderProps, R as RegisterCredentials, S as SiteUser, p as createNexusClient, q as getEnvConfig, r as getFullConfig, s as mergeConfigs, t as nexus, u as useNexus, v as useNexusAuth, w as validateConfig } from './react-C795ypnM.cjs';
3
2
  import { I as ILocalCache } from './cache-types-B39iNHfE.cjs';
4
-
5
- interface MinimalNexusConfig {
6
- apiUrl?: string;
7
- analyticsUrl?: string;
8
- apiKey?: string;
9
- projectId?: string;
10
- }
11
- declare const DEFAULT_API_URL = "https://endpoints.gnexus.co.tz";
12
- declare const DEFAULT_ANALYTICS_URL = "https://sentry.gnexus.co.tz";
13
- declare const LOCAL_NEST_URL = "https://endpoints.gnexus.co.tz";
14
- declare const LOCAL_RUST_URL = "https://sentry.gnexus.co.tz";
15
- declare const getEnvConfig: () => MinimalNexusConfig;
16
- declare const mergeConfigs: (base: MinimalNexusConfig, override: Partial<MinimalNexusConfig>) => MinimalNexusConfig;
17
- declare const getFullConfig: (partialConfig?: Partial<MinimalNexusConfig>) => MinimalNexusConfig;
18
- declare const validateConfig: (config: MinimalNexusConfig) => string[];
19
-
20
- interface NexusConfig extends MinimalNexusConfig {
21
- debug?: boolean;
22
- cacheStrategy?: 'memory' | 'localStorage' | 'none';
23
- revalidateTime?: number;
24
- timeout?: number;
25
- retries?: number;
26
- }
27
- interface NexusConfig {
28
- projectId: string;
29
- apiUrl: string;
30
- }
31
- interface ContentResponse<T = any> {
32
- id: string;
33
- type: string;
34
- data: T;
35
- meta: {
36
- version: number;
37
- updatedAt: string;
38
- locale?: string;
39
- cacheStatus: 'hit' | 'miss' | 'stale';
40
- };
41
- }
42
- interface CollectionResponse<T = any> {
43
- items: T[];
44
- total: number;
45
- page: number;
46
- limit: number;
47
- totalPages: number;
48
- hasNext: boolean;
49
- hasPrev: boolean;
50
- meta?: {
51
- fetchedAt: string;
52
- cacheStatus: string;
53
- filters?: Record<string, any>;
54
- };
55
- }
56
- interface CacheMetadata {
57
- timestamp: number;
58
- etag?: string;
59
- expiresAt: number;
60
- tags: string[];
61
- }
62
- interface CacheEntry<T = any> {
63
- data: T;
64
- metadata: CacheMetadata;
65
- }
66
- interface CollectionQuery {
67
- page?: number;
68
- limit?: number;
69
- sort?: string;
70
- order?: 'asc' | 'desc';
71
- filter?: Record<string, any>;
72
- fields?: string[];
73
- search?: string;
74
- include?: string[];
75
- }
76
- interface ErrorResponse {
77
- code: string;
78
- message: string;
79
- details?: any;
80
- timestamp: string;
81
- }
82
-
83
- declare class ContentEngine {
84
- private config;
85
- private localCache;
86
- private memoryCache;
87
- private browserCache?;
88
- private rateLimiter;
89
- private backoff;
90
- private requestBatcher;
91
- private circuitBreaker;
92
- private defaultRevalidate;
93
- private cacheStrategy;
94
- private abortController?;
95
- private isServer;
96
- constructor(config: NexusConfig);
97
- /**
98
- * Fetch a Single Page with full strategy pipeline
99
- */
100
- getPage<T = any>(slug: string, options?: {
101
- revalidate?: number;
102
- tags?: string[];
103
- forceRefresh?: boolean;
104
- includeMetadata?: boolean;
105
- }): Promise<T>;
106
- private _getPage;
107
- /**
108
- * Fetch a Collection (Optimized)
109
- */
110
- getCollection<T = any>(collectionId: string, query?: CollectionQuery, options?: {
111
- revalidate?: number;
112
- tags?: string[];
113
- forceRefresh?: boolean;
114
- includeMetadata?: boolean;
115
- }): Promise<CollectionResponse<T>>;
116
- private _getCollection;
117
- /**
118
- * Fetch Global Settings with nested includes support
119
- */
120
- getGlobals<T = any>(options?: {
121
- include?: string[];
122
- revalidate?: number;
123
- forceRefresh?: boolean;
124
- }): Promise<T>;
125
- /**
126
- * Get a single item from a collection (Uses Request Batching)
127
- * If you call this 10 times in a loop, it sends 1 HTTP request.
128
- */
129
- getItem<T = any>(collectionId: string, itemId: string, options?: {
130
- revalidate?: number;
131
- tags?: string[];
132
- include?: string[];
133
- }): Promise<T>;
134
- /**
135
- * Search across collections
136
- */
137
- search<T = any>(query: string, options?: {
138
- collections?: string[];
139
- fields?: string[];
140
- limit?: number;
141
- revalidate?: number;
142
- }): Promise<{
143
- results: T[];
144
- total: number;
145
- }>;
146
- /**
147
- * Prefetch content for better performance
148
- */
149
- prefetch(urls: string[]): Promise<void>;
150
- /**
151
- * Robust Real-time Subscriptions (SSE) with Auto-Reconnect
152
- */
153
- subscribeToUpdates(callback: (data: any) => void): () => void;
154
- /**
155
- * Check all caches in order of speed
156
- */
157
- private checkCaches;
158
- private writeCache;
159
- /**
160
- * ⚡ THE PULSE: Next.js Cache Revalidation Receiver
161
- * Used in app/api/nexus-revalidate/route.ts to handle instant updates from the NexusHub backend.
162
- *
163
- * @param req The incoming Request object from Next.js
164
- * @param revalidateFn The revalidateTag function imported from 'next/cache'
165
- */
166
- handleRevalidation(req: Request, revalidateFn: (tag: string) => void): Promise<{
167
- success: boolean;
168
- message?: string;
169
- now?: number;
170
- }>;
171
- /**
172
- * Invalidate cache by tags
173
- */
174
- invalidateCache(tags: string[]): void;
175
- /**
176
- * Clear all caches
177
- */
178
- clearCache(): void;
179
- /**
180
- * Get cache statistics
181
- */
182
- getCacheStats(): {
183
- memory: {
184
- size: number;
185
- hits: number;
186
- misses: number;
187
- hitRate: number;
188
- };
189
- browser: {
190
- size: number;
191
- } | null;
192
- local: {
193
- loaded: boolean;
194
- };
195
- };
196
- private fetchPage;
197
- private fetchCollection;
198
- private applyLocalQuery;
199
- private fetchWithTimeout;
200
- private getHeaders;
201
- private isCacheValid;
202
- private normalizeError;
203
- /**
204
- * Cancel ongoing requests
205
- */
206
- cancelRequests(): void;
207
- /**
208
- * Cleanup resources
209
- */
210
- private cleanup;
211
- }
212
-
213
- declare class AnalyticsEngine {
214
- private tracker;
215
- private cleanupFns;
216
- private isInitialized;
217
- private maxScrollDepth;
218
- private scrollThresholdsFired;
219
- private scrollTimer?;
220
- constructor(config: NexusConfig);
221
- start(): void;
222
- private lastPath;
223
- pageView(customReferrer?: string): void;
224
- private setupShareTracking;
225
- private setupScrollTracking;
226
- private clickBuffer;
227
- private setupClickTracking;
228
- private setupFormTracking;
229
- private setupOutboundTracking;
230
- private setupVideoTracking;
231
- private setupErrorTracking;
232
- private setupRouteTracking;
233
- private isInitializedByReactProvider;
234
- identify(userId: string, traits?: Record<string, any>): Promise<boolean>;
235
- group(groupId: string, traits?: Record<string, any>): Promise<boolean>;
236
- alias(newId: string): Promise<boolean>;
237
- reset(performGdprScrub?: boolean): void;
238
- track(eventName: string, properties?: Record<string, any>): void;
239
- trackPurchase(orderData: {
240
- orderId: string;
241
- total: number;
242
- revenue?: number;
243
- currency?: string;
244
- products: Array<{
245
- id: string;
246
- name: string;
247
- price: number;
248
- quantity: number;
249
- sku?: string;
250
- }>;
251
- }): void;
252
- trackError(error: Error, context?: Record<string, any>): void;
253
- private sendIdentityRequest;
254
- getSessionId(): string;
255
- stop(isFinalShutdown?: boolean): void;
256
- }
257
-
258
- declare class NexusClient {
259
- private config;
260
- content: ContentEngine;
261
- analytics?: AnalyticsEngine;
262
- constructor(config?: Partial<NexusConfig>);
263
- /**
264
- * Helper alias for cleaner content fetching.
265
- */
266
- getPage<T = any>(slug: string, options?: any): Promise<T>;
267
- /**
268
- * Returns a readonly snapshot of the current config.
269
- */
270
- getConfig(): Readonly<NexusConfig>;
271
- /**
272
- * Updates specific config fields at runtime.
273
- * Replaces the previous pattern of `(nexus as any).config.projectId = x`
274
- * which bypassed TypeScript and mutated internal state unsafely.
275
- */
276
- updateConfig(updates: Partial<NexusConfig>): void;
277
- }
278
- declare const nexus: NexusClient;
279
- declare const createNexusClient: (config: Partial<NexusConfig>) => NexusClient;
280
-
281
- interface NexusProviderProps {
282
- children: React.ReactNode;
283
- projectId?: string;
284
- disableAnalytics?: boolean;
285
- hasConsent?: boolean;
286
- enableLiveFeed?: boolean;
287
- onLiveEvent?: (event: LiveAnalyticsEvent) => void;
288
- }
289
- interface LiveAnalyticsEvent {
290
- eventType: string;
291
- projectId: string;
292
- sessionId: string;
293
- visitorId: string;
294
- userId?: string;
295
- data: {
296
- event_id: string;
297
- event_name?: string;
298
- url: string;
299
- timestamp: string;
300
- geo?: Record<string, any>;
301
- device?: Record<string, any>;
302
- performance?: Record<string, any>;
303
- ecommerce?: Record<string, any>;
304
- };
305
- timestamp: string;
306
- sequence: number;
307
- }
308
- declare const NexusProvider: ({ children, projectId, disableAnalytics, hasConsent, enableLiveFeed, onLiveEvent, }: NexusProviderProps) => react_jsx_runtime.JSX.Element;
309
- declare const useNexus: () => NexusClient;
310
-
311
- interface SiteUser {
312
- id: string;
313
- email: string;
314
- username?: string;
315
- firstName?: string;
316
- lastName?: string;
317
- avatarUrl?: string;
318
- role: string;
319
- organizationId?: string;
320
- organizationTraits?: Record<string, any>;
321
- metadata?: Record<string, any>;
322
- createdAt: string;
323
- }
324
- interface AuthState {
325
- user: SiteUser | null;
326
- isAuthenticated: boolean;
327
- isLoading: boolean;
328
- error: AuthError | null;
329
- }
330
- interface AuthError {
331
- code: string;
332
- message: string;
333
- status: number;
334
- }
335
- interface LoginCredentials {
336
- email: string;
337
- password: string;
338
- }
339
- interface RegisterCredentials {
340
- email: string;
341
- password: string;
342
- username?: string;
343
- firstName?: string;
344
- lastName?: string;
345
- metadata?: Record<string, any>;
346
- }
347
- interface AuthContextType extends AuthState {
348
- login: (creds: LoginCredentials) => Promise<void>;
349
- register: (creds: RegisterCredentials) => Promise<void>;
350
- logout: () => Promise<void>;
351
- updateProfile: (data: Partial<SiteUser>) => Promise<void>;
352
- requestPasswordReset: (email: string) => Promise<void>;
353
- }
354
-
355
- declare const AuthProvider: ({ children, config, }: {
356
- children: React.ReactNode;
357
- config: NexusConfig;
358
- }) => react_jsx_runtime.JSX.Element;
359
- declare const useNexusAuth: () => AuthContextType;
3
+ import 'react/jsx-runtime';
4
+ import 'react';
360
5
 
361
6
  /**
362
7
  * NexusHub Shared Cache Implementations
@@ -435,4 +80,4 @@ declare class LocalCacheProxy implements ILocalCache {
435
80
 
436
81
  declare const VERSION = "0.0.1";
437
82
 
438
- 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 NexusProviderProps, type RegisterCredentials, type SiteUser, VERSION, createNexusClient, getEnvConfig, getFullConfig, mergeConfigs, nexus, useNexus, useNexusAuth, validateConfig };
83
+ export { BrowserCache, CacheTags, LocalCacheProxy as LocalCache, MemoryCache, VERSION };