@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.
Files changed (68) hide show
  1. package/dist/main/RealtimeChannel.d.ts.map +1 -1
  2. package/dist/main/RealtimeChannel.js +26 -10
  3. package/dist/main/RealtimeChannel.js.map +1 -1
  4. package/dist/main/RealtimeClient.d.ts.map +1 -1
  5. package/dist/main/RealtimeClient.js +23 -6
  6. package/dist/main/RealtimeClient.js.map +1 -1
  7. package/dist/main/index.auto.d.ts +11 -0
  8. package/dist/main/index.auto.d.ts.map +1 -0
  9. package/dist/main/index.auto.js +34 -0
  10. package/dist/main/index.auto.js.map +1 -0
  11. package/dist/main/lib/constants.d.ts +1 -0
  12. package/dist/main/lib/constants.d.ts.map +1 -1
  13. package/dist/main/lib/constants.js +2 -1
  14. package/dist/main/lib/constants.js.map +1 -1
  15. package/dist/main/lib/timer.d.ts.map +1 -1
  16. package/dist/main/lib/timer.js +1 -0
  17. package/dist/main/lib/timer.js.map +1 -1
  18. package/dist/main/lib/transformers.js +1 -1
  19. package/dist/main/lib/transformers.js.map +1 -1
  20. package/dist/main/lib/version.d.ts +1 -1
  21. package/dist/main/lib/version.js +1 -1
  22. package/dist/main/lib/websocket-factory-auto.d.ts +26 -0
  23. package/dist/main/lib/websocket-factory-auto.d.ts.map +1 -0
  24. package/dist/main/lib/websocket-factory-auto.js +71 -0
  25. package/dist/main/lib/websocket-factory-auto.js.map +1 -0
  26. package/dist/main/lib/websocket-factory.d.ts +0 -6
  27. package/dist/main/lib/websocket-factory.d.ts.map +1 -1
  28. package/dist/main/lib/websocket-factory.js +16 -53
  29. package/dist/main/lib/websocket-factory.js.map +1 -1
  30. package/dist/module/RealtimeChannel.d.ts.map +1 -1
  31. package/dist/module/RealtimeChannel.js +27 -11
  32. package/dist/module/RealtimeChannel.js.map +1 -1
  33. package/dist/module/RealtimeClient.d.ts.map +1 -1
  34. package/dist/module/RealtimeClient.js +23 -6
  35. package/dist/module/RealtimeClient.js.map +1 -1
  36. package/dist/module/index.auto.d.ts +11 -0
  37. package/dist/module/index.auto.d.ts.map +1 -0
  38. package/dist/module/index.auto.js +13 -0
  39. package/dist/module/index.auto.js.map +1 -0
  40. package/dist/module/lib/constants.d.ts +1 -0
  41. package/dist/module/lib/constants.d.ts.map +1 -1
  42. package/dist/module/lib/constants.js +1 -0
  43. package/dist/module/lib/constants.js.map +1 -1
  44. package/dist/module/lib/timer.d.ts.map +1 -1
  45. package/dist/module/lib/timer.js +1 -0
  46. package/dist/module/lib/timer.js.map +1 -1
  47. package/dist/module/lib/transformers.js +1 -1
  48. package/dist/module/lib/transformers.js.map +1 -1
  49. package/dist/module/lib/version.d.ts +1 -1
  50. package/dist/module/lib/version.js +1 -1
  51. package/dist/module/lib/websocket-factory-auto.d.ts +26 -0
  52. package/dist/module/lib/websocket-factory-auto.d.ts.map +1 -0
  53. package/dist/module/lib/websocket-factory-auto.js +67 -0
  54. package/dist/module/lib/websocket-factory-auto.js.map +1 -0
  55. package/dist/module/lib/websocket-factory.d.ts +0 -6
  56. package/dist/module/lib/websocket-factory.d.ts.map +1 -1
  57. package/dist/module/lib/websocket-factory.js +16 -53
  58. package/dist/module/lib/websocket-factory.js.map +1 -1
  59. package/package.json +14 -3
  60. package/src/RealtimeChannel.ts +38 -12
  61. package/src/RealtimeClient.ts +25 -5
  62. package/src/index.auto.ts +14 -0
  63. package/src/lib/constants.ts +1 -0
  64. package/src/lib/timer.ts +1 -0
  65. package/src/lib/transformers.ts +1 -1
  66. package/src/lib/version.ts +1 -1
  67. package/src/lib/websocket-factory-auto.ts +72 -0
  68. 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
- try {
117
- if (typeof globalThis.WebSocket !== 'undefined') {
118
- return { type: 'native', constructor: globalThis.WebSocket }
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 without WebSocket support.`,
145
- workaround: 'Install the "ws" package: npm install ws',
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 {