@nexushub/client 0.0.1

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.
@@ -0,0 +1,356 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import React from 'react';
3
+
4
+ interface MinimalNexusConfig {
5
+ apiUrl?: string;
6
+ apiKey?: string;
7
+ projectId?: string;
8
+ }
9
+
10
+ interface NexusConfig extends MinimalNexusConfig {
11
+ debug?: boolean;
12
+ cacheStrategy?: 'memory' | 'localStorage' | 'none';
13
+ revalidateTime?: number;
14
+ timeout?: number;
15
+ retries?: number;
16
+ }
17
+ interface NexusConfig {
18
+ projectId: string;
19
+ apiUrl: string;
20
+ }
21
+ interface ContentResponse<T = any> {
22
+ id: string;
23
+ type: string;
24
+ data: T;
25
+ meta: {
26
+ version: number;
27
+ updatedAt: string;
28
+ locale?: string;
29
+ cacheStatus: 'hit' | 'miss' | 'stale';
30
+ };
31
+ }
32
+ interface CollectionResponse<T = any> {
33
+ items: T[];
34
+ total: number;
35
+ page: number;
36
+ limit: number;
37
+ totalPages: number;
38
+ hasNext: boolean;
39
+ hasPrev: boolean;
40
+ meta?: {
41
+ fetchedAt: string;
42
+ cacheStatus: string;
43
+ filters?: Record<string, any>;
44
+ };
45
+ }
46
+ interface CacheMetadata {
47
+ timestamp: number;
48
+ etag?: string;
49
+ expiresAt: number;
50
+ tags: string[];
51
+ }
52
+ interface CacheEntry<T = any> {
53
+ data: T;
54
+ metadata: CacheMetadata;
55
+ }
56
+ interface CollectionQuery {
57
+ page?: number;
58
+ limit?: number;
59
+ sort?: string;
60
+ order?: 'asc' | 'desc';
61
+ filter?: Record<string, any>;
62
+ fields?: string[];
63
+ search?: string;
64
+ include?: string[];
65
+ }
66
+ interface ErrorResponse {
67
+ code: string;
68
+ message: string;
69
+ details?: any;
70
+ timestamp: string;
71
+ }
72
+
73
+ declare class ContentEngine {
74
+ private config;
75
+ private localCache;
76
+ private memoryCache;
77
+ private browserCache?;
78
+ private rateLimiter;
79
+ private backoff;
80
+ private requestBatcher;
81
+ private defaultRevalidate;
82
+ private cacheStrategy;
83
+ private abortController?;
84
+ private isServer;
85
+ constructor(config: NexusConfig);
86
+ /**
87
+ * Fetch a Singleton Page with enhanced caching
88
+ */
89
+ getPage<T = any>(slug: string, options?: {
90
+ revalidate?: number;
91
+ tags?: string[];
92
+ forceRefresh?: boolean;
93
+ includeMetadata?: boolean;
94
+ }): Promise<T>;
95
+ private _getPage;
96
+ /**
97
+ * Fetch a Collection with advanced query capabilities
98
+ */
99
+ getCollection<T = any>(collectionId: string, query?: CollectionQuery, options?: {
100
+ revalidate?: number;
101
+ tags?: string[];
102
+ forceRefresh?: boolean;
103
+ includeMetadata?: boolean;
104
+ }): Promise<CollectionResponse<T>>;
105
+ private _getCollection;
106
+ /**
107
+ * Fetch Global Settings with nested includes support
108
+ */
109
+ getGlobals<T = any>(options?: {
110
+ include?: string[];
111
+ revalidate?: number;
112
+ forceRefresh?: boolean;
113
+ }): Promise<T>;
114
+ /**
115
+ * Fetch a single item from a collection
116
+ */
117
+ getItem<T = any>(collectionId: string, itemId: string, options?: {
118
+ revalidate?: number;
119
+ tags?: string[];
120
+ include?: string[];
121
+ }): Promise<T>;
122
+ /**
123
+ * Search across collections
124
+ */
125
+ search<T = any>(query: string, options?: {
126
+ collections?: string[];
127
+ fields?: string[];
128
+ limit?: number;
129
+ revalidate?: number;
130
+ }): Promise<{
131
+ results: T[];
132
+ total: number;
133
+ }>;
134
+ /**
135
+ * Prefetch content for better performance
136
+ */
137
+ prefetch(urls: string[]): Promise<void>;
138
+ /**
139
+ * Invalidate cache by tags
140
+ */
141
+ invalidateCache(tags: string[]): void;
142
+ /**
143
+ * Clear all caches
144
+ */
145
+ clearCache(): void;
146
+ /**
147
+ * Get cache statistics
148
+ */
149
+ getCacheStats(): {
150
+ memory: {
151
+ size: number;
152
+ hits: number;
153
+ misses: number;
154
+ hitRate: number;
155
+ };
156
+ browser: {
157
+ size: number;
158
+ } | null;
159
+ local: {
160
+ loaded: boolean;
161
+ };
162
+ };
163
+ /**
164
+ * Cancel ongoing requests
165
+ */
166
+ cancelRequests(): void;
167
+ /**
168
+ * Subscribe to content updates (SSE)
169
+ */
170
+ subscribeToUpdates(callback: (data: any) => void): () => void;
171
+ private fetchPage;
172
+ private fetchCollection;
173
+ private fetchWithTimeout;
174
+ private applyLocalQuery;
175
+ private isCacheValid;
176
+ private getHeaders;
177
+ private normalizeError;
178
+ /**
179
+ * Cleanup resources
180
+ */
181
+ private cleanup;
182
+ }
183
+
184
+ declare class NexusClient {
185
+ private config;
186
+ content: ContentEngine;
187
+ constructor(config?: Partial<NexusConfig>);
188
+ getPage<T = any>(slug: string, options?: any): Promise<T>;
189
+ getConfig(): Readonly<NexusConfig>;
190
+ }
191
+ declare const nexus: NexusClient;
192
+ declare const createNexusClient: (config: Partial<NexusConfig>) => NexusClient;
193
+
194
+ declare const NexusProvider: ({ children, projectId }: {
195
+ children: React.ReactNode;
196
+ projectId?: string;
197
+ }) => react_jsx_runtime.JSX.Element;
198
+
199
+ interface SiteUser {
200
+ id: string;
201
+ email: string;
202
+ name?: string;
203
+ avatarUrl?: string;
204
+ role: string;
205
+ metadata: Record<string, any>;
206
+ }
207
+ interface AuthState {
208
+ user: SiteUser | null;
209
+ isLoading: boolean;
210
+ error: Error | null;
211
+ isAuthenticated: boolean;
212
+ }
213
+ interface LoginCredentials {
214
+ email: string;
215
+ password: string;
216
+ }
217
+ interface RegisterCredentials {
218
+ email: string;
219
+ password: string;
220
+ name?: string;
221
+ metadata?: Record<string, any>;
222
+ }
223
+ interface AuthContextType extends AuthState {
224
+ login: (creds: LoginCredentials) => Promise<void>;
225
+ register: (creds: RegisterCredentials) => Promise<void>;
226
+ logout: () => Promise<void>;
227
+ loginWithGoogle: () => void;
228
+ updateProfile: (data: Partial<SiteUser>) => Promise<void>;
229
+ }
230
+
231
+ declare const useNexusAuth: () => AuthContextType;
232
+
233
+ /**
234
+ * NexusHub Advanced Caching System
235
+ *
236
+ * Features:
237
+ * 1. Multi-layer caching (Memory > Local > Remote)
238
+ * 2. Cache tagging for precise invalidation
239
+ * 3. LRU eviction policy
240
+ * 4. Cache statistics and monitoring
241
+ * 5. Development mode with filesystem cache
242
+ */
243
+ interface CacheOptions {
244
+ maxSize?: number;
245
+ ttl?: number;
246
+ tags?: string[];
247
+ revalidate?: number;
248
+ }
249
+ interface CacheStats {
250
+ size: number;
251
+ hits: number;
252
+ misses: number;
253
+ hitRate: number;
254
+ evictions: number;
255
+ }
256
+ declare const CacheTags: {
257
+ project: (projectId: string) => string;
258
+ content: (slug: string) => string;
259
+ collection: (collectionId: string) => string;
260
+ global: string;
261
+ user: (userId: string) => string;
262
+ media: (mediaId: string) => string;
263
+ };
264
+ declare class MemoryCache {
265
+ private cache;
266
+ private tagIndex;
267
+ private stats;
268
+ private maxSize;
269
+ private defaultTTL;
270
+ constructor(options?: CacheOptions);
271
+ set<T = any>(key: string, data: T, options?: CacheOptions): void;
272
+ get<T = any>(key: string): {
273
+ data: T;
274
+ metadata: any;
275
+ } | null;
276
+ delete(key: string): boolean;
277
+ invalidateByTags(tags: string[]): void;
278
+ clear(): void;
279
+ getStats(): CacheStats;
280
+ private evictLRU;
281
+ private calculateSize;
282
+ private updateHitRate;
283
+ }
284
+ declare class LocalCache {
285
+ private data;
286
+ private hasLoaded;
287
+ private cachePath;
288
+ constructor(customPath?: string);
289
+ isLoaded(): boolean;
290
+ private load;
291
+ getPage(slug: string): any;
292
+ getCollection(collectionId: string): any[] | null;
293
+ getGlobals(): any;
294
+ getAllData(): any;
295
+ private shouldWarnAboutMissingCache;
296
+ }
297
+ declare class BrowserCache {
298
+ private projectId;
299
+ private prefix;
300
+ private maxSize;
301
+ private currentSize;
302
+ constructor(projectId: string);
303
+ set<T = any>(key: string, data: T, ttl?: number): void;
304
+ get<T = any>(key: string): T | null;
305
+ delete(key: string): void;
306
+ clear(): void;
307
+ private getStorageKey;
308
+ private calculateCurrentSize;
309
+ private calculateStorageSize;
310
+ private evictOldest;
311
+ }
312
+
313
+ /**
314
+ * Advanced strategies for resilience and performance
315
+ */
316
+ interface RateLimiterConfig {
317
+ maxRequests: number;
318
+ timeWindow: number;
319
+ }
320
+ declare class RateLimiter {
321
+ private requests;
322
+ private config;
323
+ constructor(config: RateLimiterConfig);
324
+ checkLimit(): Promise<void>;
325
+ getStats(): {
326
+ currentRequests: number;
327
+ limit: number;
328
+ };
329
+ }
330
+ interface BackoffConfig {
331
+ maxRetries: number;
332
+ baseDelay: number;
333
+ maxDelay: number;
334
+ jitter?: boolean;
335
+ }
336
+ declare class ExponentialBackoff {
337
+ private config;
338
+ constructor(config: BackoffConfig);
339
+ execute<T>(fn: () => Promise<T>, onRetry?: (attempt: number, delay: number, error: Error) => void): Promise<T>;
340
+ private calculateDelay;
341
+ private isClientError;
342
+ private isRateLimitError;
343
+ }
344
+ declare class RequestBatcher {
345
+ private batchWindow;
346
+ private maxBatchSize;
347
+ private batch;
348
+ private batchTimeout?;
349
+ private processing;
350
+ constructor(batchWindow?: number, // milliseconds
351
+ maxBatchSize?: number);
352
+ schedule<T>(key: string, request: () => Promise<T>): Promise<T>;
353
+ private processBatch;
354
+ }
355
+
356
+ export { type BackoffConfig, BrowserCache, type CacheEntry, type CacheMetadata, type CacheOptions, type CacheStats, CacheTags, type CollectionQuery, type CollectionResponse, ContentEngine, type ContentResponse, type ErrorResponse, ExponentialBackoff, LocalCache, MemoryCache, NexusClient, type NexusConfig, NexusProvider, RateLimiter, type RateLimiterConfig, RequestBatcher, type SiteUser, createNexusClient, nexus, useNexusAuth };
@@ -0,0 +1,356 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import React from 'react';
3
+
4
+ interface MinimalNexusConfig {
5
+ apiUrl?: string;
6
+ apiKey?: string;
7
+ projectId?: string;
8
+ }
9
+
10
+ interface NexusConfig extends MinimalNexusConfig {
11
+ debug?: boolean;
12
+ cacheStrategy?: 'memory' | 'localStorage' | 'none';
13
+ revalidateTime?: number;
14
+ timeout?: number;
15
+ retries?: number;
16
+ }
17
+ interface NexusConfig {
18
+ projectId: string;
19
+ apiUrl: string;
20
+ }
21
+ interface ContentResponse<T = any> {
22
+ id: string;
23
+ type: string;
24
+ data: T;
25
+ meta: {
26
+ version: number;
27
+ updatedAt: string;
28
+ locale?: string;
29
+ cacheStatus: 'hit' | 'miss' | 'stale';
30
+ };
31
+ }
32
+ interface CollectionResponse<T = any> {
33
+ items: T[];
34
+ total: number;
35
+ page: number;
36
+ limit: number;
37
+ totalPages: number;
38
+ hasNext: boolean;
39
+ hasPrev: boolean;
40
+ meta?: {
41
+ fetchedAt: string;
42
+ cacheStatus: string;
43
+ filters?: Record<string, any>;
44
+ };
45
+ }
46
+ interface CacheMetadata {
47
+ timestamp: number;
48
+ etag?: string;
49
+ expiresAt: number;
50
+ tags: string[];
51
+ }
52
+ interface CacheEntry<T = any> {
53
+ data: T;
54
+ metadata: CacheMetadata;
55
+ }
56
+ interface CollectionQuery {
57
+ page?: number;
58
+ limit?: number;
59
+ sort?: string;
60
+ order?: 'asc' | 'desc';
61
+ filter?: Record<string, any>;
62
+ fields?: string[];
63
+ search?: string;
64
+ include?: string[];
65
+ }
66
+ interface ErrorResponse {
67
+ code: string;
68
+ message: string;
69
+ details?: any;
70
+ timestamp: string;
71
+ }
72
+
73
+ declare class ContentEngine {
74
+ private config;
75
+ private localCache;
76
+ private memoryCache;
77
+ private browserCache?;
78
+ private rateLimiter;
79
+ private backoff;
80
+ private requestBatcher;
81
+ private defaultRevalidate;
82
+ private cacheStrategy;
83
+ private abortController?;
84
+ private isServer;
85
+ constructor(config: NexusConfig);
86
+ /**
87
+ * Fetch a Singleton Page with enhanced caching
88
+ */
89
+ getPage<T = any>(slug: string, options?: {
90
+ revalidate?: number;
91
+ tags?: string[];
92
+ forceRefresh?: boolean;
93
+ includeMetadata?: boolean;
94
+ }): Promise<T>;
95
+ private _getPage;
96
+ /**
97
+ * Fetch a Collection with advanced query capabilities
98
+ */
99
+ getCollection<T = any>(collectionId: string, query?: CollectionQuery, options?: {
100
+ revalidate?: number;
101
+ tags?: string[];
102
+ forceRefresh?: boolean;
103
+ includeMetadata?: boolean;
104
+ }): Promise<CollectionResponse<T>>;
105
+ private _getCollection;
106
+ /**
107
+ * Fetch Global Settings with nested includes support
108
+ */
109
+ getGlobals<T = any>(options?: {
110
+ include?: string[];
111
+ revalidate?: number;
112
+ forceRefresh?: boolean;
113
+ }): Promise<T>;
114
+ /**
115
+ * Fetch a single item from a collection
116
+ */
117
+ getItem<T = any>(collectionId: string, itemId: string, options?: {
118
+ revalidate?: number;
119
+ tags?: string[];
120
+ include?: string[];
121
+ }): Promise<T>;
122
+ /**
123
+ * Search across collections
124
+ */
125
+ search<T = any>(query: string, options?: {
126
+ collections?: string[];
127
+ fields?: string[];
128
+ limit?: number;
129
+ revalidate?: number;
130
+ }): Promise<{
131
+ results: T[];
132
+ total: number;
133
+ }>;
134
+ /**
135
+ * Prefetch content for better performance
136
+ */
137
+ prefetch(urls: string[]): Promise<void>;
138
+ /**
139
+ * Invalidate cache by tags
140
+ */
141
+ invalidateCache(tags: string[]): void;
142
+ /**
143
+ * Clear all caches
144
+ */
145
+ clearCache(): void;
146
+ /**
147
+ * Get cache statistics
148
+ */
149
+ getCacheStats(): {
150
+ memory: {
151
+ size: number;
152
+ hits: number;
153
+ misses: number;
154
+ hitRate: number;
155
+ };
156
+ browser: {
157
+ size: number;
158
+ } | null;
159
+ local: {
160
+ loaded: boolean;
161
+ };
162
+ };
163
+ /**
164
+ * Cancel ongoing requests
165
+ */
166
+ cancelRequests(): void;
167
+ /**
168
+ * Subscribe to content updates (SSE)
169
+ */
170
+ subscribeToUpdates(callback: (data: any) => void): () => void;
171
+ private fetchPage;
172
+ private fetchCollection;
173
+ private fetchWithTimeout;
174
+ private applyLocalQuery;
175
+ private isCacheValid;
176
+ private getHeaders;
177
+ private normalizeError;
178
+ /**
179
+ * Cleanup resources
180
+ */
181
+ private cleanup;
182
+ }
183
+
184
+ declare class NexusClient {
185
+ private config;
186
+ content: ContentEngine;
187
+ constructor(config?: Partial<NexusConfig>);
188
+ getPage<T = any>(slug: string, options?: any): Promise<T>;
189
+ getConfig(): Readonly<NexusConfig>;
190
+ }
191
+ declare const nexus: NexusClient;
192
+ declare const createNexusClient: (config: Partial<NexusConfig>) => NexusClient;
193
+
194
+ declare const NexusProvider: ({ children, projectId }: {
195
+ children: React.ReactNode;
196
+ projectId?: string;
197
+ }) => react_jsx_runtime.JSX.Element;
198
+
199
+ interface SiteUser {
200
+ id: string;
201
+ email: string;
202
+ name?: string;
203
+ avatarUrl?: string;
204
+ role: string;
205
+ metadata: Record<string, any>;
206
+ }
207
+ interface AuthState {
208
+ user: SiteUser | null;
209
+ isLoading: boolean;
210
+ error: Error | null;
211
+ isAuthenticated: boolean;
212
+ }
213
+ interface LoginCredentials {
214
+ email: string;
215
+ password: string;
216
+ }
217
+ interface RegisterCredentials {
218
+ email: string;
219
+ password: string;
220
+ name?: string;
221
+ metadata?: Record<string, any>;
222
+ }
223
+ interface AuthContextType extends AuthState {
224
+ login: (creds: LoginCredentials) => Promise<void>;
225
+ register: (creds: RegisterCredentials) => Promise<void>;
226
+ logout: () => Promise<void>;
227
+ loginWithGoogle: () => void;
228
+ updateProfile: (data: Partial<SiteUser>) => Promise<void>;
229
+ }
230
+
231
+ declare const useNexusAuth: () => AuthContextType;
232
+
233
+ /**
234
+ * NexusHub Advanced Caching System
235
+ *
236
+ * Features:
237
+ * 1. Multi-layer caching (Memory > Local > Remote)
238
+ * 2. Cache tagging for precise invalidation
239
+ * 3. LRU eviction policy
240
+ * 4. Cache statistics and monitoring
241
+ * 5. Development mode with filesystem cache
242
+ */
243
+ interface CacheOptions {
244
+ maxSize?: number;
245
+ ttl?: number;
246
+ tags?: string[];
247
+ revalidate?: number;
248
+ }
249
+ interface CacheStats {
250
+ size: number;
251
+ hits: number;
252
+ misses: number;
253
+ hitRate: number;
254
+ evictions: number;
255
+ }
256
+ declare const CacheTags: {
257
+ project: (projectId: string) => string;
258
+ content: (slug: string) => string;
259
+ collection: (collectionId: string) => string;
260
+ global: string;
261
+ user: (userId: string) => string;
262
+ media: (mediaId: string) => string;
263
+ };
264
+ declare class MemoryCache {
265
+ private cache;
266
+ private tagIndex;
267
+ private stats;
268
+ private maxSize;
269
+ private defaultTTL;
270
+ constructor(options?: CacheOptions);
271
+ set<T = any>(key: string, data: T, options?: CacheOptions): void;
272
+ get<T = any>(key: string): {
273
+ data: T;
274
+ metadata: any;
275
+ } | null;
276
+ delete(key: string): boolean;
277
+ invalidateByTags(tags: string[]): void;
278
+ clear(): void;
279
+ getStats(): CacheStats;
280
+ private evictLRU;
281
+ private calculateSize;
282
+ private updateHitRate;
283
+ }
284
+ declare class LocalCache {
285
+ private data;
286
+ private hasLoaded;
287
+ private cachePath;
288
+ constructor(customPath?: string);
289
+ isLoaded(): boolean;
290
+ private load;
291
+ getPage(slug: string): any;
292
+ getCollection(collectionId: string): any[] | null;
293
+ getGlobals(): any;
294
+ getAllData(): any;
295
+ private shouldWarnAboutMissingCache;
296
+ }
297
+ declare class BrowserCache {
298
+ private projectId;
299
+ private prefix;
300
+ private maxSize;
301
+ private currentSize;
302
+ constructor(projectId: string);
303
+ set<T = any>(key: string, data: T, ttl?: number): void;
304
+ get<T = any>(key: string): T | null;
305
+ delete(key: string): void;
306
+ clear(): void;
307
+ private getStorageKey;
308
+ private calculateCurrentSize;
309
+ private calculateStorageSize;
310
+ private evictOldest;
311
+ }
312
+
313
+ /**
314
+ * Advanced strategies for resilience and performance
315
+ */
316
+ interface RateLimiterConfig {
317
+ maxRequests: number;
318
+ timeWindow: number;
319
+ }
320
+ declare class RateLimiter {
321
+ private requests;
322
+ private config;
323
+ constructor(config: RateLimiterConfig);
324
+ checkLimit(): Promise<void>;
325
+ getStats(): {
326
+ currentRequests: number;
327
+ limit: number;
328
+ };
329
+ }
330
+ interface BackoffConfig {
331
+ maxRetries: number;
332
+ baseDelay: number;
333
+ maxDelay: number;
334
+ jitter?: boolean;
335
+ }
336
+ declare class ExponentialBackoff {
337
+ private config;
338
+ constructor(config: BackoffConfig);
339
+ execute<T>(fn: () => Promise<T>, onRetry?: (attempt: number, delay: number, error: Error) => void): Promise<T>;
340
+ private calculateDelay;
341
+ private isClientError;
342
+ private isRateLimitError;
343
+ }
344
+ declare class RequestBatcher {
345
+ private batchWindow;
346
+ private maxBatchSize;
347
+ private batch;
348
+ private batchTimeout?;
349
+ private processing;
350
+ constructor(batchWindow?: number, // milliseconds
351
+ maxBatchSize?: number);
352
+ schedule<T>(key: string, request: () => Promise<T>): Promise<T>;
353
+ private processBatch;
354
+ }
355
+
356
+ export { type BackoffConfig, BrowserCache, type CacheEntry, type CacheMetadata, type CacheOptions, type CacheStats, CacheTags, type CollectionQuery, type CollectionResponse, ContentEngine, type ContentResponse, type ErrorResponse, ExponentialBackoff, LocalCache, MemoryCache, NexusClient, type NexusConfig, NexusProvider, RateLimiter, type RateLimiterConfig, RequestBatcher, type SiteUser, createNexusClient, nexus, useNexusAuth };