Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 | /** * Socket.IO Types * * Type definitions for WebSocket communication between client and server. */ import type { NotificationPayload } from '@/lib/notifications/types'; /** * Order update payload sent via WebSocket */ export interface OrderUpdatePayload { orderId: string; status: string; timestamp: string; message: string; trackingNumber?: string; } /** * Inventory alert payload for admin dashboard */ export interface InventoryAlertPayload { productId: string; productName: string; currentStock: number; threshold: number; alertType: 'low_stock' | 'out_of_stock' | 'restock'; timestamp: string; } /** * Cart sync payload for cross-device cart synchronization */ export interface CartSyncPayload { items: Array<{ productId: string; quantity: number; }>; updatedAt: string; } /** * New order payload for admin live dashboard */ export interface NewOrderPayload { orderId: string; orderNumber: string; total: number; customerName: string; itemCount: number; timestamp: string; } /** * Connection confirmation payload */ export interface ConnectedPayload { userId: string; connectedAt: string; } /** * Events emitted from server to client */ export interface ServerToClientEvents { /** New notification received */ notification: (data: NotificationPayload) => void; /** Order status update */ orderUpdate: (data: OrderUpdatePayload) => void; /** Inventory alert (admin only) */ inventoryAlert: (data: InventoryAlertPayload) => void; /** Cart synchronization */ cartSync: (data: CartSyncPayload) => void; /** New order received (admin only) */ newOrder: (data: NewOrderPayload) => void; /** Connection confirmed */ connected: (data: ConnectedPayload) => void; /** Error message */ error: (data: { message: string; code?: string }) => void; } /** * Events emitted from client to server */ export interface ClientToServerEvents { /** Subscribe to channels */ subscribe: (channels: string[]) => void; /** Unsubscribe from channels */ unsubscribe: (channels: string[]) => void; /** Mark notifications as read */ markRead: (notificationIds: string[]) => void; /** Join order tracking room */ joinOrder: (orderId: string) => void; /** Leave order tracking room */ leaveOrder: (orderId: string) => void; /** Sync cart across devices */ syncCart: (data: CartSyncPayload) => void; } /** * Inter-server events (for scaling with Redis adapter) */ export interface InterServerEvents { ping: () => void; } /** * Socket data attached to each connection */ export interface SocketData { userId: string; role: string; sessionId: string; connectedAt: Date; } /** * Channel types for room-based communication */ export type ChannelType = | `user:${string}` // User-specific channel | `order:${string}` // Order tracking channel | 'admin' // Admin broadcast channel | 'orders' // All orders channel (admin) | 'inventory'; // Inventory alerts channel (admin) /** * Socket connection status */ export type ConnectionStatus = 'connected' | 'connecting' | 'disconnected' | 'error'; /** * Socket configuration options */ export interface SocketConfig { url: string; reconnectionAttempts: number; reconnectionDelay: number; reconnectionDelayMax: number; timeout: number; } /** * Default socket configuration */ export const DEFAULT_SOCKET_CONFIG: SocketConfig = { url: process.env.NEXT_PUBLIC_SOCKET_URL || '', reconnectionAttempts: 5, reconnectionDelay: 1000, reconnectionDelayMax: 5000, timeout: 20000, }; |