@supabase/realtime-js 2.14.0 → 2.15.0-next.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.
- package/dist/main/RealtimeChannel.d.ts.map +1 -1
- package/dist/main/RealtimeChannel.js +26 -10
- package/dist/main/RealtimeChannel.js.map +1 -1
- package/dist/main/RealtimeClient.d.ts.map +1 -1
- package/dist/main/RealtimeClient.js +23 -6
- package/dist/main/RealtimeClient.js.map +1 -1
- package/dist/main/index.auto.d.ts +11 -0
- package/dist/main/index.auto.d.ts.map +1 -0
- package/dist/main/index.auto.js +34 -0
- package/dist/main/index.auto.js.map +1 -0
- package/dist/main/lib/constants.d.ts +1 -0
- package/dist/main/lib/constants.d.ts.map +1 -1
- package/dist/main/lib/constants.js +2 -1
- package/dist/main/lib/constants.js.map +1 -1
- package/dist/main/lib/timer.d.ts.map +1 -1
- package/dist/main/lib/timer.js +1 -0
- package/dist/main/lib/timer.js.map +1 -1
- package/dist/main/lib/transformers.js +1 -1
- package/dist/main/lib/transformers.js.map +1 -1
- package/dist/main/lib/version.d.ts +1 -1
- package/dist/main/lib/version.js +1 -1
- package/dist/main/lib/websocket-factory-auto.d.ts +26 -0
- package/dist/main/lib/websocket-factory-auto.d.ts.map +1 -0
- package/dist/main/lib/websocket-factory-auto.js +71 -0
- package/dist/main/lib/websocket-factory-auto.js.map +1 -0
- package/dist/main/lib/websocket-factory.d.ts +0 -6
- package/dist/main/lib/websocket-factory.d.ts.map +1 -1
- package/dist/main/lib/websocket-factory.js +16 -53
- package/dist/main/lib/websocket-factory.js.map +1 -1
- package/dist/module/RealtimeChannel.d.ts.map +1 -1
- package/dist/module/RealtimeChannel.js +27 -11
- package/dist/module/RealtimeChannel.js.map +1 -1
- package/dist/module/RealtimeClient.d.ts.map +1 -1
- package/dist/module/RealtimeClient.js +23 -6
- package/dist/module/RealtimeClient.js.map +1 -1
- package/dist/module/index.auto.d.ts +11 -0
- package/dist/module/index.auto.d.ts.map +1 -0
- package/dist/module/index.auto.js +13 -0
- package/dist/module/index.auto.js.map +1 -0
- package/dist/module/lib/constants.d.ts +1 -0
- package/dist/module/lib/constants.d.ts.map +1 -1
- package/dist/module/lib/constants.js +1 -0
- package/dist/module/lib/constants.js.map +1 -1
- package/dist/module/lib/timer.d.ts.map +1 -1
- package/dist/module/lib/timer.js +1 -0
- package/dist/module/lib/timer.js.map +1 -1
- package/dist/module/lib/transformers.js +1 -1
- package/dist/module/lib/transformers.js.map +1 -1
- package/dist/module/lib/version.d.ts +1 -1
- package/dist/module/lib/version.js +1 -1
- package/dist/module/lib/websocket-factory-auto.d.ts +26 -0
- package/dist/module/lib/websocket-factory-auto.d.ts.map +1 -0
- package/dist/module/lib/websocket-factory-auto.js +67 -0
- package/dist/module/lib/websocket-factory-auto.js.map +1 -0
- package/dist/module/lib/websocket-factory.d.ts +0 -6
- package/dist/module/lib/websocket-factory.d.ts.map +1 -1
- package/dist/module/lib/websocket-factory.js +16 -53
- package/dist/module/lib/websocket-factory.js.map +1 -1
- package/package.json +14 -3
- package/src/RealtimeChannel.ts +38 -12
- package/src/RealtimeClient.ts +25 -5
- package/src/index.auto.ts +14 -0
- package/src/lib/constants.ts +1 -0
- package/src/lib/timer.ts +1 -0
- package/src/lib/transformers.ts +1 -1
- package/src/lib/version.ts +1 -1
- package/src/lib/websocket-factory-auto.ts +72 -0
- package/src/lib/websocket-factory.ts +19 -53
|
@@ -33,32 +33,6 @@ export interface WebSocketEnvironment {
|
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
export class WebSocketFactory {
|
|
36
|
-
/**
|
|
37
|
-
* Dynamic require that works in both CJS and ESM environments
|
|
38
|
-
* Bulletproof against strict ESM environments where require might not be in scope
|
|
39
|
-
* @private
|
|
40
|
-
*/
|
|
41
|
-
private static dynamicRequire(moduleId: string): any {
|
|
42
|
-
try {
|
|
43
|
-
// Check if we're in a Node.js environment first
|
|
44
|
-
if (
|
|
45
|
-
typeof process !== 'undefined' &&
|
|
46
|
-
process.versions &&
|
|
47
|
-
process.versions.node
|
|
48
|
-
) {
|
|
49
|
-
// In Node.js, both CJS and ESM support require for dynamic imports
|
|
50
|
-
// Wrap in try/catch to handle strict ESM environments
|
|
51
|
-
if (typeof require !== 'undefined') {
|
|
52
|
-
return require(moduleId)
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
return null
|
|
56
|
-
} catch {
|
|
57
|
-
// Catches any error from typeof require OR require() call in strict ESM
|
|
58
|
-
return null
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
36
|
private static detectEnvironment(): WebSocketEnvironment {
|
|
63
37
|
if (typeof WebSocket !== 'undefined') {
|
|
64
38
|
return { type: 'native', constructor: WebSocket }
|
|
@@ -112,39 +86,31 @@ export class WebSocketFactory {
|
|
|
112
86
|
process.versions.node
|
|
113
87
|
) {
|
|
114
88
|
const nodeVersion = parseInt(process.versions.node.split('.')[0])
|
|
89
|
+
|
|
90
|
+
// Node.js 22+ should have native WebSocket
|
|
115
91
|
if (nodeVersion >= 22) {
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
}
|
|
120
|
-
const undici = this.dynamicRequire('undici')
|
|
121
|
-
if (undici && undici.WebSocket) {
|
|
122
|
-
return { type: 'native', constructor: undici.WebSocket }
|
|
123
|
-
}
|
|
124
|
-
throw new Error('undici not available')
|
|
125
|
-
} catch (err) {
|
|
126
|
-
return {
|
|
127
|
-
type: 'unsupported',
|
|
128
|
-
error: `Node.js ${nodeVersion} detected but native WebSocket not found.`,
|
|
129
|
-
workaround:
|
|
130
|
-
'Install the "ws" package or check your Node.js installation.',
|
|
131
|
-
}
|
|
92
|
+
// Check if native WebSocket is available (should be in Node.js 22+)
|
|
93
|
+
if (typeof globalThis.WebSocket !== 'undefined') {
|
|
94
|
+
return { type: 'native', constructor: globalThis.WebSocket }
|
|
132
95
|
}
|
|
133
|
-
|
|
134
|
-
try {
|
|
135
|
-
// Use dynamic require to work in both CJS and ESM environments
|
|
136
|
-
const ws = this.dynamicRequire('ws')
|
|
137
|
-
if (ws) {
|
|
138
|
-
return { type: 'ws', constructor: ws.WebSocket ?? ws }
|
|
139
|
-
}
|
|
140
|
-
throw new Error('ws package not available')
|
|
141
|
-
} catch (err) {
|
|
96
|
+
// If not available, user needs to provide it
|
|
142
97
|
return {
|
|
143
98
|
type: 'unsupported',
|
|
144
|
-
error: `Node.js ${nodeVersion} detected
|
|
145
|
-
workaround:
|
|
99
|
+
error: `Node.js ${nodeVersion} detected but native WebSocket not found.`,
|
|
100
|
+
workaround:
|
|
101
|
+
'Provide a WebSocket implementation via the transport option.',
|
|
146
102
|
}
|
|
147
103
|
}
|
|
104
|
+
|
|
105
|
+
// Node.js < 22 doesn't have native WebSocket
|
|
106
|
+
return {
|
|
107
|
+
type: 'unsupported',
|
|
108
|
+
error: `Node.js ${nodeVersion} detected without native WebSocket support.`,
|
|
109
|
+
workaround:
|
|
110
|
+
'For Node.js < 22, install "ws" package and provide it via the transport option:\n' +
|
|
111
|
+
'import ws from "ws"\n' +
|
|
112
|
+
'new RealtimeClient(url, { transport: ws })',
|
|
113
|
+
}
|
|
148
114
|
}
|
|
149
115
|
|
|
150
116
|
return {
|