@thewhateverapp/platform 0.7.24 → 0.8.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.
@@ -0,0 +1,178 @@
1
+ /**
2
+ * Realtime WebSocket Pub/Sub Types
3
+ *
4
+ * Provides type definitions for the realtime messaging system
5
+ * powered by Cloudflare Durable Objects.
6
+ */
7
+ /**
8
+ * Message types for WebSocket communication
9
+ */
10
+ export type RealtimeMessageType = 'subscribe' | 'unsubscribe' | 'publish' | 'ping' | 'pong' | 'data' | 'error' | 'connected' | 'subscribed' | 'unsubscribed';
11
+ /**
12
+ * Base message structure for realtime communication
13
+ */
14
+ export interface RealtimeMessage {
15
+ type: RealtimeMessageType;
16
+ channel?: string;
17
+ channels?: string[];
18
+ data?: unknown;
19
+ timestamp?: number;
20
+ message?: string;
21
+ }
22
+ /**
23
+ * Options for publishing messages
24
+ */
25
+ export interface PublishOptions {
26
+ /**
27
+ * Whether to wait for confirmation
28
+ * @default false
29
+ */
30
+ waitForConfirm?: boolean;
31
+ }
32
+ /**
33
+ * Result of a publish operation
34
+ */
35
+ export interface PublishResult {
36
+ success: boolean;
37
+ channel: string;
38
+ recipients: number;
39
+ }
40
+ /**
41
+ * Environment bindings required for Realtime
42
+ */
43
+ export interface RealtimeEnv {
44
+ /**
45
+ * Durable Object namespace binding for RealtimeChannel
46
+ */
47
+ REALTIME?: DurableObjectNamespace;
48
+ /**
49
+ * App ID for channel isolation
50
+ */
51
+ APP_ID?: string;
52
+ }
53
+ /**
54
+ * Server-side Realtime Provider interface
55
+ *
56
+ * Used in API routes to publish messages to connected clients.
57
+ *
58
+ * @example
59
+ * ```typescript
60
+ * import { getRealtime } from '@thewhateverapp/platform';
61
+ *
62
+ * export async function POST(req: Request) {
63
+ * const realtime = await getRealtime();
64
+ *
65
+ * // Publish to a channel
66
+ * await realtime.publish('counter', { count: 42 });
67
+ *
68
+ * return new Response('OK');
69
+ * }
70
+ * ```
71
+ */
72
+ export interface RealtimeProvider {
73
+ /**
74
+ * Publish a message to a channel
75
+ *
76
+ * All connected clients subscribed to this channel will receive the message.
77
+ *
78
+ * @param channel - Channel name to publish to
79
+ * @param data - Data to send (will be JSON serialized)
80
+ * @param options - Optional publish options
81
+ * @returns Result with recipient count
82
+ */
83
+ publish(channel: string, data: unknown, options?: PublishOptions): Promise<PublishResult>;
84
+ /**
85
+ * Get statistics about connected clients
86
+ *
87
+ * @returns Stats including total connections and per-channel counts
88
+ */
89
+ getStats(): Promise<RealtimeStats>;
90
+ /**
91
+ * Check if the realtime service is healthy
92
+ *
93
+ * @returns True if the service is responding
94
+ */
95
+ isHealthy(): Promise<boolean>;
96
+ }
97
+ /**
98
+ * Statistics about realtime connections
99
+ */
100
+ export interface RealtimeStats {
101
+ totalConnections: number;
102
+ channels: Record<string, number>;
103
+ }
104
+ /**
105
+ * Options for creating a realtime connection (client-side)
106
+ */
107
+ export interface RealtimeConnectionOptions {
108
+ /**
109
+ * Channels to subscribe to immediately on connect
110
+ */
111
+ channels?: string[];
112
+ /**
113
+ * Auto-reconnect on disconnect
114
+ * @default true
115
+ */
116
+ autoReconnect?: boolean;
117
+ /**
118
+ * Reconnect delay in milliseconds
119
+ * @default 1000
120
+ */
121
+ reconnectDelay?: number;
122
+ /**
123
+ * Maximum reconnect attempts (0 = unlimited)
124
+ * @default 10
125
+ */
126
+ maxReconnectAttempts?: number;
127
+ /**
128
+ * Ping interval in milliseconds (0 = disabled)
129
+ * @default 30000
130
+ */
131
+ pingInterval?: number;
132
+ }
133
+ /**
134
+ * Connection state for client-side realtime
135
+ */
136
+ export type RealtimeConnectionState = 'connecting' | 'connected' | 'disconnected' | 'reconnecting';
137
+ /**
138
+ * Client-side realtime connection interface
139
+ */
140
+ export interface RealtimeConnection {
141
+ /**
142
+ * Current connection state
143
+ */
144
+ readonly state: RealtimeConnectionState;
145
+ /**
146
+ * Currently subscribed channels
147
+ */
148
+ readonly channels: readonly string[];
149
+ /**
150
+ * Subscribe to a channel
151
+ */
152
+ subscribe(channel: string): void;
153
+ /**
154
+ * Unsubscribe from a channel
155
+ */
156
+ unsubscribe(channel: string): void;
157
+ /**
158
+ * Publish a message (client-to-server-to-all)
159
+ */
160
+ publish(channel: string, data: unknown): void;
161
+ /**
162
+ * Add a message listener for a channel
163
+ */
164
+ on(channel: string, callback: (data: unknown) => void): () => void;
165
+ /**
166
+ * Add a listener for all messages
167
+ */
168
+ onAny(callback: (channel: string, data: unknown) => void): () => void;
169
+ /**
170
+ * Add a connection state listener
171
+ */
172
+ onStateChange(callback: (state: RealtimeConnectionState) => void): () => void;
173
+ /**
174
+ * Disconnect and cleanup
175
+ */
176
+ disconnect(): void;
177
+ }
178
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/realtime/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;GAEG;AACH,MAAM,MAAM,mBAAmB,GAC3B,WAAW,GACX,aAAa,GACb,SAAS,GACT,MAAM,GACN,MAAM,GACN,MAAM,GACN,OAAO,GACP,WAAW,GACX,YAAY,GACZ,cAAc,CAAC;AAEnB;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,mBAAmB,CAAC;IAC1B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IACpB,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B;;;OAGG;IACH,cAAc,CAAC,EAAE,OAAO,CAAC;CAC1B;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,OAAO,EAAE,OAAO,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;CACpB;AAED;;GAEG;AACH,MAAM,WA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IACH,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IAEnC;;OAEG;IACH,OAAO,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,GAAG,IAAI,CAAC;IAE9C;;OAEG;IACH,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,IAAI,EAAE,OAAO,KAAK,IAAI,GAAG,MAAM,IAAI,CAAC;IAEnE;;OAEG;IACH,KAAK,CAAC,QAAQ,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,KAAK,IAAI,GAAG,MAAM,IAAI,CAAC;IAEtE;;OAEG;IACH,aAAa,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,uBAAuB,KAAK,IAAI,GAAG,MAAM,IAAI,CAAC;IAE9E;;OAEG;IACH,UAAU,IAAI,IAAI,CAAC;CACpB"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Realtime WebSocket Pub/Sub Types
3
+ *
4
+ * Provides type definitions for the realtime messaging system
5
+ * powered by Cloudflare Durable Objects.
6
+ */
7
+ export {};
8
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/realtime/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thewhateverapp/platform",
3
- "version": "0.7.24",
3
+ "version": "0.8.0",
4
4
  "description": "Universal SDK for The Whatever App platform services",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -50,15 +50,20 @@
50
50
  "homepage": "https://thewhatever.app",
51
51
  "devDependencies": {
52
52
  "@cloudflare/workers-types": "^4.20250402.0",
53
+ "@types/react": "^18.0.0",
53
54
  "typescript": "^5.7.3"
54
55
  },
55
56
  "peerDependencies": {
56
57
  "@cloudflare/workers-types": "^4.0.0",
57
- "@opennextjs/cloudflare": "^1.0.0"
58
+ "@opennextjs/cloudflare": "^1.0.0",
59
+ "react": "^18.0.0"
58
60
  },
59
61
  "peerDependenciesMeta": {
60
62
  "@opennextjs/cloudflare": {
61
63
  "optional": true
64
+ },
65
+ "react": {
66
+ "optional": true
62
67
  }
63
68
  }
64
69
  }