@nexushub/client 0.8.9 → 1.1.0

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/react.d.cts CHANGED
@@ -1,6 +1,16 @@
1
- import * as react_jsx_runtime from 'react/jsx-runtime';
2
1
  import React from 'react';
3
2
 
3
+ interface NexusRendererProps {
4
+ content: string;
5
+ className?: string;
6
+ onCommentClick?: (commentId: string) => void;
7
+ onImageClick?: (src: string, alt?: string) => void;
8
+ hydrateCharts?: boolean;
9
+ enableImageInteraction?: boolean;
10
+ documentClassName?: string;
11
+ }
12
+ declare function NexusRenderer({ content, className, onCommentClick, onImageClick, hydrateCharts, enableImageInteraction, documentClassName, }: NexusRendererProps): React.JSX.Element;
13
+
4
14
  interface MinimalNexusConfig {
5
15
  apiUrl?: string;
6
16
  analyticsUrl?: string;
@@ -14,6 +24,18 @@ interface NexusConfig extends MinimalNexusConfig {
14
24
  revalidateTime?: number | false;
15
25
  timeout?: number;
16
26
  retries?: number;
27
+ /** Internal/runtime version; populated automatically. */
28
+ sdkVersion?: string;
29
+ /** GN-Apex owns cache invalidation. Forever is intentional by default. */
30
+ cacheInvalidation?: "platform" | "manual";
31
+ environment?: "development" | "staging" | "production";
32
+ privacy?: {
33
+ analytics?: boolean;
34
+ fingerprinting?: boolean;
35
+ redact?: boolean;
36
+ };
37
+ autoTracking?: boolean;
38
+ publicKeyOnly?: boolean;
17
39
  }
18
40
  interface NexusConfig {
19
41
  projectId: string;
@@ -58,6 +80,8 @@ declare class ContentEngine {
58
80
  private abortController?;
59
81
  private isServer;
60
82
  constructor(config: NexusConfig);
83
+ /** Update runtime configuration without exposing internal mutation. */
84
+ updateConfig(config: NexusConfig): void;
61
85
  /**
62
86
  * Fetch a Single Page with full strategy pipeline
63
87
  */
@@ -79,7 +103,7 @@ declare class ContentEngine {
79
103
  }): Promise<CollectionResponse<T>>;
80
104
  private _getCollection;
81
105
  /**
82
- * Fetch Global Settings with nested includes support
106
+ * Fetch Global Settings
83
107
  */
84
108
  getGlobals<T = any>(options?: {
85
109
  include?: string[];
@@ -108,31 +132,11 @@ declare class ContentEngine {
108
132
  total: number;
109
133
  }>;
110
134
  /**
111
- * Prefetch content for better performance
135
+ * Prefetch content
112
136
  */
113
137
  prefetch(urls: string[]): Promise<void>;
114
138
  /**
115
139
  * Robust Real-time Subscriptions (SSE) with Auto-Reconnect
116
- *
117
- * ⚠️ SCOPE — READ BEFORE RELYING ON THIS FOR "instant" UPDATES:
118
- * This connects from the BROWSER TAB it's called in, and on message it
119
- * only clears THIS SDK INSTANCE's in-memory `memoryCache` (via
120
- * invalidateCache below) in THAT browser tab's JS heap. In a typical
121
- * Next.js deployment — and Cloudflare specifically, which is stateless
122
- * per-request at the edge — that is a different process/isolate than the
123
- * one that will render the NEXT server request for this content. So:
124
- * - ✅ Useful for: a client component that reads from `nexus.content`
125
- * directly in the browser and re-renders in place without a page
126
- * navigation (e.g. a live-updating dashboard widget).
127
- * - ❌ NOT sufficient for: "user A edits content in the CMS, user B's
128
- * already-loaded page updates" via a server-rendered page. That
129
- * requires the backend's /api/revalidate webhook (see
130
- * content.service.ts `pingNextRevalidateWebhook`) to have actually
131
- * cleared the *server's* Data Cache, so the NEXT navigation or
132
- * server request picks up fresh data. This SSE channel does not
133
- * replace that — it's a complementary, browser-local optimization.
134
- * If your symptom was "stale content after editing," fix the webhook
135
- * wiring first; treat this method as an enhancement layered on top.
136
140
  */
137
141
  subscribeToUpdates(callback: (data: any) => void): () => void;
138
142
  private checkCaches;
@@ -159,9 +163,13 @@ declare class ContentEngine {
159
163
  private fetchWithTimeout;
160
164
  private getHeaders;
161
165
  private isCacheValid;
166
+ /**
167
+ * 🛡️ FIX: Normalizes timeout errors (AbortError, 408, or Timeout messages)
168
+ * into clean, standardized "Request timeout" errors.
169
+ */
162
170
  private normalizeError;
163
171
  cancelRequests(): void;
164
- private cleanup;
172
+ cleanup(): void;
165
173
  }
166
174
 
167
175
  declare class AnalyticsEngine {
@@ -209,25 +217,159 @@ declare class AnalyticsEngine {
209
217
  stop(isFinalShutdown?: boolean): void;
210
218
  }
211
219
 
220
+ type NexusEventMap = {
221
+ "request:start": {
222
+ requestId: string;
223
+ url: string;
224
+ method: string;
225
+ };
226
+ "request:end": {
227
+ requestId: string;
228
+ url: string;
229
+ status: number;
230
+ duration: number;
231
+ };
232
+ "cache:hit": {
233
+ key: string;
234
+ stale?: boolean;
235
+ };
236
+ "cache:miss": {
237
+ key: string;
238
+ };
239
+ "analytics:queued": {
240
+ count: number;
241
+ };
242
+ "analytics:flushed": {
243
+ sent: number;
244
+ remaining: number;
245
+ };
246
+ "content:updated": {
247
+ type: string;
248
+ slug?: string;
249
+ collectionId?: string;
250
+ id?: string;
251
+ };
252
+ "error": {
253
+ error: unknown;
254
+ };
255
+ };
256
+ type Listener<T> = (payload: T) => void;
257
+ declare class NexusEventBus<M extends Record<string, any> = NexusEventMap> {
258
+ private listeners;
259
+ on<K extends keyof M>(event: K, listener: Listener<M[K]>): () => void;
260
+ emit<K extends keyof M>(event: K, payload: M[K]): void;
261
+ clear(): void;
262
+ }
263
+
264
+ interface NexusRequestOptions extends RequestInit {
265
+ timeout?: number;
266
+ retries?: number;
267
+ next?: {
268
+ tags?: string[];
269
+ revalidate?: number | false;
270
+ };
271
+ }
272
+ declare class NexusHttpClient {
273
+ private config;
274
+ private events;
275
+ private readonly limiter;
276
+ private readonly breaker;
277
+ private readonly backoff;
278
+ constructor(config: NexusConfig, events?: NexusEventBus<NexusEventMap>);
279
+ updateConfig(config: NexusConfig): void;
280
+ request(input: string, options?: NexusRequestOptions): Promise<Response>;
281
+ getStats(): {
282
+ rateLimit: {
283
+ currentRequests: number;
284
+ limit: number;
285
+ };
286
+ circuit: string;
287
+ };
288
+ }
289
+
290
+ declare class FeatureFlags {
291
+ private values;
292
+ constructor(initial?: Record<string, any>);
293
+ set(values: Record<string, any>): void;
294
+ isEnabled(key: string, fallback?: boolean): boolean;
295
+ get<T = any>(key: string, fallback?: T): T;
296
+ all(): {
297
+ [x: string]: any;
298
+ };
299
+ }
300
+ declare class RemoteConfig {
301
+ private values;
302
+ set(values: Record<string, any>): void;
303
+ get<T = any>(key: string, fallback?: T): T;
304
+ all(): {
305
+ [x: string]: any;
306
+ };
307
+ }
308
+
309
+ /**
310
+ * GN-Apex client: intentionally zero-config for GN-Apex generated sites.
311
+ * Platform configuration is discovered automatically; explicit overrides are
312
+ * an escape hatch for SDK consumers, not a requirement for site developers.
313
+ * Cache revalidation is FALSE by default on purpose: GN-Apex/Cloudflare owns
314
+ * invalidation and purge, so immutable content can stay cached indefinitely.
315
+ */
212
316
  declare class NexusClient {
213
317
  private config;
214
318
  content: ContentEngine;
215
319
  analytics?: AnalyticsEngine;
320
+ readonly events: NexusEventBus;
321
+ readonly http: NexusHttpClient;
322
+ readonly flags: FeatureFlags;
323
+ readonly remoteConfig: RemoteConfig;
216
324
  constructor(config?: Partial<NexusConfig>);
217
325
  /**
218
- * Helper alias for cleaner content fetching.
326
+ * Helper alias for cleaner page content fetching.
219
327
  */
220
328
  getPage<T = any>(slug: string, options?: any): Promise<T>;
221
329
  /**
222
- * Returns a readonly snapshot of the current config.
330
+ * Returns a readonly snapshot of the active configuration.
223
331
  */
224
332
  getConfig(): Readonly<NexusConfig>;
225
333
  /**
226
- * Updates specific config fields at runtime.
227
- * Replaces the previous pattern of `(nexus as any).config.projectId = x`
228
- * which bypassed TypeScript and mutated internal state unsafely.
334
+ * Updates runtime configuration dynamically without breaking active listeners.
229
335
  */
230
336
  updateConfig(updates: Partial<NexusConfig>): void;
337
+ /**
338
+ * Returns deep system diagnostics including HTTP and cache performance.
339
+ */
340
+ diagnostics(): {
341
+ cache: {
342
+ memory: {
343
+ size: number;
344
+ hits: number;
345
+ misses: number;
346
+ hitRate: number;
347
+ };
348
+ browser: {
349
+ size: number;
350
+ } | null;
351
+ local: {
352
+ loaded: boolean;
353
+ };
354
+ };
355
+ http: {
356
+ rateLimit: {
357
+ currentRequests: number;
358
+ limit: number;
359
+ };
360
+ circuit: string;
361
+ };
362
+ analyticsQueue: number | undefined;
363
+ version: string;
364
+ environment: string;
365
+ online: boolean;
366
+ userAgent?: string;
367
+ memory?: number;
368
+ };
369
+ /**
370
+ * Gracefully terminates background tasks and cleans up listeners.
371
+ */
372
+ destroy(): void;
231
373
  }
232
374
 
233
375
  interface NexusProviderProps {
@@ -263,7 +405,7 @@ interface LiveFeedContextValue {
263
405
  isConnected: boolean;
264
406
  }
265
407
  declare const useNexusLiveFeed: () => LiveFeedContextValue;
266
- declare const NexusProvider: ({ children, projectId, disableAnalytics, hasConsent, enableLiveFeed, onLiveEvent, autoPromptPush, }: NexusProviderProps) => react_jsx_runtime.JSX.Element;
408
+ declare const NexusProvider: ({ children, projectId, disableAnalytics, hasConsent, enableLiveFeed, onLiveEvent, autoPromptPush, }: NexusProviderProps) => React.JSX.Element;
267
409
  declare const useNexus: () => NexusClient;
268
410
  declare const useNexusAnalytics: () => {
269
411
  track: (eventName: string, properties?: Record<string, any>) => void;
@@ -334,33 +476,36 @@ interface AuthContextType extends AuthState {
334
476
  declare const AuthProvider: ({ children, config, }: {
335
477
  children: React.ReactNode;
336
478
  config: NexusConfig;
337
- }) => react_jsx_runtime.JSX.Element;
479
+ }) => React.JSX.Element;
338
480
  declare const useNexusAuth: () => AuthContextType;
339
481
 
340
482
  interface NexusRichTextProps {
341
483
  value: string;
342
484
  className?: string;
485
+ hydrateCharts?: boolean;
486
+ onCommentClick?: (commentId: string) => void;
487
+ onImageClick?: (src: string, alt?: string) => void;
343
488
  }
344
- declare function NexusRichText({ value, className }: NexusRichTextProps): react_jsx_runtime.JSX.Element | null;
489
+ declare function NexusRichText({ value, className, hydrateCharts, onCommentClick, onImageClick, }: NexusRichTextProps): React.JSX.Element | null;
345
490
  interface NexusLongTextProps {
346
491
  value: string;
347
492
  className?: string;
348
493
  }
349
- declare function NexusLongText({ value, className }: NexusLongTextProps): react_jsx_runtime.JSX.Element | null;
494
+ declare function NexusLongText({ value, className }: NexusLongTextProps): React.JSX.Element | null;
350
495
  interface NexusIconProps {
351
496
  name: string;
352
497
  className?: string;
353
498
  size?: number;
354
499
  strokeWidth?: number;
355
500
  }
356
- declare function NexusIcon({ name, className, size, strokeWidth, }: NexusIconProps): react_jsx_runtime.JSX.Element | null;
501
+ declare function NexusIcon({ name, className, size, strokeWidth, }: NexusIconProps): React.JSX.Element | null;
357
502
  interface NexusImageProps extends React.ImgHTMLAttributes<HTMLImageElement> {
358
503
  value: string | {
359
504
  url: string;
360
505
  alt?: string;
361
506
  } | null;
362
507
  }
363
- declare function NexusImage({ value, className, alt, ...props }: NexusImageProps): react_jsx_runtime.JSX.Element | null;
508
+ declare function NexusImage({ value, className, alt, ...props }: NexusImageProps): React.JSX.Element | null;
364
509
  interface NexusGalleryProps {
365
510
  value: Array<string | {
366
511
  url: string;
@@ -369,13 +514,13 @@ interface NexusGalleryProps {
369
514
  className?: string;
370
515
  imageClassName?: string;
371
516
  }
372
- declare function NexusGallery({ value, className, imageClassName, }: NexusGalleryProps): react_jsx_runtime.JSX.Element | null;
517
+ declare function NexusGallery({ value, className, imageClassName, }: NexusGalleryProps): React.JSX.Element | null;
373
518
  interface NexusVideoProps {
374
519
  value: string | null;
375
520
  className?: string;
376
521
  autoplay?: boolean;
377
522
  }
378
- declare function NexusVideo({ value, className, autoplay, }: NexusVideoProps): react_jsx_runtime.JSX.Element | null;
523
+ declare function NexusVideo({ value, className, autoplay, }: NexusVideoProps): React.JSX.Element | null;
379
524
  interface NexusMapProps {
380
525
  value: {
381
526
  lat: number;
@@ -384,27 +529,20 @@ interface NexusMapProps {
384
529
  } | null;
385
530
  className?: string;
386
531
  }
387
- declare function NexusMap({ value, className }: NexusMapProps): react_jsx_runtime.JSX.Element | null;
532
+ declare function NexusMap({ value, className }: NexusMapProps): React.JSX.Element | null;
388
533
  interface NexusColorProps {
389
534
  value: string | null;
390
535
  className?: string;
391
536
  showHexLabel?: boolean;
392
537
  }
393
- /**
394
- * Renders a color value as a styled swatch with optional HEX/RGB label copy-trigger.
395
- */
396
- declare function NexusColor({ value, className, showHexLabel, }: NexusColorProps): react_jsx_runtime.JSX.Element | null;
538
+ declare function NexusColor({ value, className, showHexLabel, }: NexusColorProps): React.JSX.Element | null;
397
539
  interface NexusGradientProps {
398
540
  value: string | null;
399
541
  children?: React.ReactNode;
400
542
  className?: string;
401
543
  asTextMask?: boolean;
402
544
  }
403
- /**
404
- * Renders a container or text utilizing a CSS background-gradient.
405
- * supporting text-clip masks (e.g. gradient headings).
406
- */
407
- declare function NexusGradient({ value, children, className, asTextMask, }: NexusGradientProps): react_jsx_runtime.JSX.Element;
545
+ declare function NexusGradient({ value, children, className, asTextMask, }: NexusGradientProps): React.JSX.Element;
408
546
  interface NexusAddressProps {
409
547
  value: {
410
548
  street?: string;
@@ -415,65 +553,44 @@ interface NexusAddressProps {
415
553
  } | null;
416
554
  className?: string;
417
555
  }
418
- /**
419
- * Formats structured location address payloads into an elegant micro-card.
420
- */
421
- declare function NexusAddress({ value, className }: NexusAddressProps): react_jsx_runtime.JSX.Element | null;
556
+ declare function NexusAddress({ value, className }: NexusAddressProps): React.JSX.Element | null;
422
557
  interface NexusKeyValueProps {
423
558
  value: Record<string, string> | null;
424
559
  className?: string;
425
560
  }
426
- /**
427
- * Renders arbitrary specifications or metadata maps inside an elegant tabular grid.
428
- */
429
- declare function NexusKeyValue({ value, className }: NexusKeyValueProps): react_jsx_runtime.JSX.Element | null;
561
+ declare function NexusKeyValue({ value, className }: NexusKeyValueProps): React.JSX.Element | null;
430
562
  interface NexusTagsProps {
431
563
  value: string[] | null;
432
564
  className?: string;
433
565
  badgeClassName?: string;
434
566
  }
435
- /**
436
- * Iterates and renders arrays or tags as styled status badges.
437
- */
438
- declare function NexusTags({ value, className, badgeClassName, }: NexusTagsProps): react_jsx_runtime.JSX.Element | null;
567
+ declare function NexusTags({ value, className, badgeClassName, }: NexusTagsProps): React.JSX.Element | null;
439
568
  interface NexusProgressProps {
440
569
  value: number | null;
441
570
  max?: number;
442
571
  className?: string;
443
572
  color?: string;
444
573
  }
445
- /**
446
- * Renders progress fields or percent ratings inside a smooth horizontal bar.
447
- */
448
- declare function NexusProgress({ value, max, className, color, }: NexusProgressProps): react_jsx_runtime.JSX.Element | null;
574
+ declare function NexusProgress({ value, max, className, color, }: NexusProgressProps): React.JSX.Element | null;
449
575
  interface NexusBlendContainerProps {
450
576
  mode: string | null;
451
577
  children: React.ReactNode;
452
578
  className?: string;
453
579
  }
454
- /**
455
- * Wraps dynamic components to apply a specified mix-blend-mode container safely.
456
- */
457
- declare function NexusBlendContainer({ mode, children, className, }: NexusBlendContainerProps): react_jsx_runtime.JSX.Element;
580
+ declare function NexusBlendContainer({ mode, children, className, }: NexusBlendContainerProps): React.JSX.Element;
458
581
  interface NexusCodeProps {
459
582
  value: string | null;
460
583
  language?: string;
461
584
  className?: string;
462
585
  showLineNumbers?: boolean;
463
586
  }
464
- /**
465
- * Renders scrollable JSON, script contents, or code files with an instant Copy button.
466
- */
467
- declare function NexusCode({ value, language, className, showLineNumbers, }: NexusCodeProps): react_jsx_runtime.JSX.Element | null;
587
+ declare function NexusCode({ value, language, className, showLineNumbers, }: NexusCodeProps): React.JSX.Element | null;
468
588
  interface NexusBooleanProps {
469
589
  value: boolean | null;
470
590
  className?: string;
471
591
  trueLabel?: string;
472
592
  falseLabel?: string;
473
593
  }
474
- /**
475
- * Renders toggles or boolean validations as a styled linter-safe status badge.
476
- */
477
- declare function NexusBoolean({ value, className, trueLabel, falseLabel, }: NexusBooleanProps): react_jsx_runtime.JSX.Element | null;
594
+ declare function NexusBoolean({ value, className, trueLabel, falseLabel, }: NexusBooleanProps): React.JSX.Element | null;
478
595
 
479
- export { AuthProvider, type LiveAnalyticsEvent, NexusAddress, type NexusAddressProps, NexusBlendContainer, type NexusBlendContainerProps, NexusBoolean, type NexusBooleanProps, NexusCode, type NexusCodeProps, NexusColor, type NexusColorProps, NexusGallery, type NexusGalleryProps, NexusGradient, type NexusGradientProps, NexusIcon, type NexusIconProps, NexusImage, type NexusImageProps, NexusKeyValue, type NexusKeyValueProps, NexusLongText, type NexusLongTextProps, NexusMap, type NexusMapProps, NexusProgress, type NexusProgressProps, NexusProvider, type NexusProviderProps, NexusRichText, type NexusRichTextProps, NexusTags, type NexusTagsProps, NexusVideo, type NexusVideoProps, useNexus, useNexusAnalytics, useNexusAuth, useNexusLiveFeed };
596
+ export { AuthProvider, type LiveAnalyticsEvent, NexusAddress, type NexusAddressProps, NexusBlendContainer, type NexusBlendContainerProps, NexusBoolean, type NexusBooleanProps, NexusCode, type NexusCodeProps, NexusColor, type NexusColorProps, NexusGallery, type NexusGalleryProps, NexusGradient, type NexusGradientProps, NexusIcon, type NexusIconProps, NexusImage, type NexusImageProps, NexusKeyValue, type NexusKeyValueProps, NexusLongText, type NexusLongTextProps, NexusMap, type NexusMapProps, NexusProgress, type NexusProgressProps, NexusProvider, type NexusProviderProps, NexusRenderer, NexusRichText, type NexusRichTextProps, NexusTags, type NexusTagsProps, NexusVideo, type NexusVideoProps, useNexus, useNexusAnalytics, useNexusAuth, useNexusLiveFeed };