@djangocfg/centrifugo 2.1.48 → 2.1.50

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@djangocfg/centrifugo",
3
- "version": "2.1.48",
3
+ "version": "2.1.50",
4
4
  "description": "Production-ready Centrifugo WebSocket client for React with real-time subscriptions, RPC patterns, and connection state management",
5
5
  "keywords": [
6
6
  "centrifugo",
@@ -51,9 +51,9 @@
51
51
  "centrifuge": "^5.2.2"
52
52
  },
53
53
  "peerDependencies": {
54
- "@djangocfg/api": "^2.1.48",
55
- "@djangocfg/ui-nextjs": "^2.1.48",
56
- "@djangocfg/layouts": "^2.1.48",
54
+ "@djangocfg/api": "^2.1.50",
55
+ "@djangocfg/ui-nextjs": "^2.1.50",
56
+ "@djangocfg/layouts": "^2.1.50",
57
57
  "consola": "^3.4.2",
58
58
  "lucide-react": "^0.545.0",
59
59
  "moment": "^2.30.1",
@@ -61,7 +61,7 @@
61
61
  "react-dom": "^19.1.0"
62
62
  },
63
63
  "devDependencies": {
64
- "@djangocfg/typescript-config": "^2.1.48",
64
+ "@djangocfg/typescript-config": "^2.1.50",
65
65
  "@types/react": "^19.1.0",
66
66
  "@types/react-dom": "^19.1.0",
67
67
  "moment": "^2.30.1",
@@ -8,6 +8,7 @@
8
8
  import { Centrifuge } from 'centrifuge';
9
9
 
10
10
  import { getConsolaLogger } from '../logger/consolaLogger';
11
+ import { dispatchCentrifugoError } from '../../events';
11
12
 
12
13
  import type { Logger } from '../logger';
13
14
  export interface CentrifugoClientOptions {
@@ -589,6 +590,17 @@ export class CentrifugoRPCClient {
589
590
  return result.data as TResponse;
590
591
  } catch (error) {
591
592
  this.logger.error(`Native RPC failed: ${method}`, error);
593
+
594
+ // Dispatch error event for ErrorsTracker
595
+ const errorMessage = error instanceof Error ? error.message : String(error);
596
+ const errorCode = (error as any)?.code;
597
+ dispatchCentrifugoError({
598
+ method,
599
+ error: errorMessage,
600
+ code: errorCode,
601
+ data,
602
+ });
603
+
592
604
  throw error;
593
605
  }
594
606
  }
package/src/events.ts CHANGED
@@ -2,6 +2,7 @@
2
2
  * Centrifugo Package Events
3
3
  *
4
4
  * Event-driven communication for Centrifugo monitor dialog
5
+ * and error tracking via CustomEvents
5
6
  */
6
7
 
7
8
  import { events } from '@djangocfg/ui-nextjs';
@@ -15,6 +16,11 @@ export const CENTRIFUGO_MONITOR_EVENTS = {
15
16
  CLOSE_MONITOR_DIALOG: 'CENTRIFUGO_CLOSE_MONITOR_DIALOG',
16
17
  } as const;
17
18
 
19
+ /**
20
+ * Error event name for ErrorsTracker integration
21
+ */
22
+ export const CENTRIFUGO_ERROR_EVENT = 'centrifugo-error' as const;
23
+
18
24
  // ─────────────────────────────────────────────────────────────────────────
19
25
  // Event Payload Types
20
26
  // ─────────────────────────────────────────────────────────────────────────
@@ -24,6 +30,21 @@ export interface OpenMonitorDialogPayload {
24
30
  defaultTab?: 'connection' | 'messages' | 'subscriptions';
25
31
  }
26
32
 
33
+ /**
34
+ * Payload for centrifugo-error CustomEvent
35
+ * Compatible with ErrorsTracker CentrifugoErrorDetail
36
+ */
37
+ export interface CentrifugoErrorPayload {
38
+ /** RPC method that failed */
39
+ method: string;
40
+ /** Error message */
41
+ error: string;
42
+ /** Error code from Centrifugo */
43
+ code?: number;
44
+ /** Additional data sent with the request */
45
+ data?: any;
46
+ }
47
+
27
48
  // ─────────────────────────────────────────────────────────────────────────
28
49
  // Event Emitters
29
50
  // ─────────────────────────────────────────────────────────────────────────
@@ -42,3 +63,42 @@ export const emitCloseMonitorDialog = () => {
42
63
  });
43
64
  };
44
65
 
66
+ // ─────────────────────────────────────────────────────────────────────────
67
+ // Error Event Dispatcher (CustomEvent for ErrorsTracker)
68
+ // ─────────────────────────────────────────────────────────────────────────
69
+
70
+ /**
71
+ * Dispatch Centrifugo error event for ErrorsTracker
72
+ *
73
+ * Uses window.dispatchEvent with CustomEvent to integrate with
74
+ * ErrorsTracker from @djangocfg/layouts package.
75
+ *
76
+ * @example
77
+ * ```ts
78
+ * dispatchCentrifugoError({
79
+ * method: 'terminal.input',
80
+ * error: 'timeout',
81
+ * code: 1,
82
+ * data: { session_id: 'abc-123' },
83
+ * });
84
+ * ```
85
+ */
86
+ export const dispatchCentrifugoError = (payload: CentrifugoErrorPayload): void => {
87
+ if (typeof window === 'undefined') {
88
+ return;
89
+ }
90
+
91
+ try {
92
+ window.dispatchEvent(new CustomEvent(CENTRIFUGO_ERROR_EVENT, {
93
+ detail: {
94
+ ...payload,
95
+ timestamp: new Date(),
96
+ },
97
+ bubbles: true,
98
+ cancelable: false,
99
+ }));
100
+ } catch (eventError) {
101
+ // Silently fail - event dispatch should never crash the app
102
+ }
103
+ };
104
+