@supabase/realtime-js 2.72.1-canary.9 → 2.80.1-canary.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 (41) hide show
  1. package/README.md +2 -2
  2. package/dist/main/RealtimeChannel.d.ts.map +1 -1
  3. package/dist/main/RealtimeChannel.js +4 -3
  4. package/dist/main/RealtimeChannel.js.map +1 -1
  5. package/dist/main/RealtimeClient.d.ts +2 -0
  6. package/dist/main/RealtimeClient.d.ts.map +1 -1
  7. package/dist/main/RealtimeClient.js +30 -8
  8. package/dist/main/RealtimeClient.js.map +1 -1
  9. package/dist/main/lib/constants.d.ts +2 -2
  10. package/dist/main/lib/transformers.d.ts +1 -1
  11. package/dist/main/lib/transformers.d.ts.map +1 -1
  12. package/dist/main/lib/transformers.js +3 -0
  13. package/dist/main/lib/transformers.js.map +1 -1
  14. package/dist/main/lib/version.d.ts +1 -1
  15. package/dist/main/lib/version.js +1 -1
  16. package/dist/main/lib/websocket-factory.d.ts.map +1 -1
  17. package/dist/main/lib/websocket-factory.js +24 -18
  18. package/dist/main/lib/websocket-factory.js.map +1 -1
  19. package/dist/module/RealtimeChannel.d.ts.map +1 -1
  20. package/dist/module/RealtimeChannel.js +4 -3
  21. package/dist/module/RealtimeChannel.js.map +1 -1
  22. package/dist/module/RealtimeClient.d.ts +2 -0
  23. package/dist/module/RealtimeClient.d.ts.map +1 -1
  24. package/dist/module/RealtimeClient.js +30 -8
  25. package/dist/module/RealtimeClient.js.map +1 -1
  26. package/dist/module/lib/constants.d.ts +2 -2
  27. package/dist/module/lib/transformers.d.ts +1 -1
  28. package/dist/module/lib/transformers.d.ts.map +1 -1
  29. package/dist/module/lib/transformers.js +3 -0
  30. package/dist/module/lib/transformers.js.map +1 -1
  31. package/dist/module/lib/version.d.ts +1 -1
  32. package/dist/module/lib/version.js +1 -1
  33. package/dist/module/lib/websocket-factory.d.ts.map +1 -1
  34. package/dist/module/lib/websocket-factory.js +24 -18
  35. package/dist/module/lib/websocket-factory.js.map +1 -1
  36. package/package.json +4 -4
  37. package/src/RealtimeChannel.ts +3 -2
  38. package/src/RealtimeClient.ts +23 -5
  39. package/src/lib/transformers.ts +5 -1
  40. package/src/lib/version.ts +1 -1
  41. package/src/lib/websocket-factory.ts +27 -21
@@ -69,6 +69,7 @@ export type RealtimeClientOptions = {
69
69
  transport?: WebSocketLikeConstructor
70
70
  timeout?: number
71
71
  heartbeatIntervalMs?: number
72
+ heartbeatCallback?: (status: HeartbeatStatus) => void
72
73
  logger?: Function
73
74
  encode?: Function
74
75
  decode?: Function
@@ -146,6 +147,7 @@ export default class RealtimeClient {
146
147
  * @param options.params The optional params to pass when connecting.
147
148
  * @param options.headers Deprecated: headers cannot be set on websocket connections and this option will be removed in the future.
148
149
  * @param options.heartbeatIntervalMs The millisec interval to send a heartbeat message.
150
+ * @param options.heartbeatCallback The optional function to handle heartbeat status.
149
151
  * @param options.logger The optional function for specialized logging, ie: logger: (kind, msg, data) => { console.log(`${kind}: ${msg}`, data) }
150
152
  * @param options.logLevel Sets the log level for Realtime
151
153
  * @param options.encode The function to encode outgoing messages. Defaults to JSON: (payload, callback) => callback(JSON.stringify(payload))
@@ -397,7 +399,11 @@ export default class RealtimeClient {
397
399
  */
398
400
  async sendHeartbeat() {
399
401
  if (!this.isConnected()) {
400
- this.heartbeatCallback('disconnected')
402
+ try {
403
+ this.heartbeatCallback('disconnected')
404
+ } catch (e) {
405
+ this.log('error', 'error in heartbeat callback', e)
406
+ }
401
407
  return
402
408
  }
403
409
 
@@ -405,7 +411,11 @@ export default class RealtimeClient {
405
411
  if (this.pendingHeartbeatRef) {
406
412
  this.pendingHeartbeatRef = null
407
413
  this.log('transport', 'heartbeat timeout. Attempting to re-establish connection')
408
- this.heartbeatCallback('timeout')
414
+ try {
415
+ this.heartbeatCallback('timeout')
416
+ } catch (e) {
417
+ this.log('error', 'error in heartbeat callback', e)
418
+ }
409
419
 
410
420
  // Force reconnection after heartbeat timeout
411
421
  this._wasManualDisconnect = false
@@ -427,7 +437,11 @@ export default class RealtimeClient {
427
437
  payload: {},
428
438
  ref: this.pendingHeartbeatRef,
429
439
  })
430
- this.heartbeatCallback('sent')
440
+ try {
441
+ this.heartbeatCallback('sent')
442
+ } catch (e) {
443
+ this.log('error', 'error in heartbeat callback', e)
444
+ }
431
445
 
432
446
  this._setAuthSafely('heartbeat')
433
447
  }
@@ -518,7 +532,11 @@ export default class RealtimeClient {
518
532
  this.decode(rawMessage.data, (msg: RealtimeMessage) => {
519
533
  // Handle heartbeat responses
520
534
  if (msg.topic === 'phoenix' && msg.event === 'phx_reply') {
521
- this.heartbeatCallback(msg.payload.status === 'ok' ? 'ok' : 'error')
535
+ try {
536
+ this.heartbeatCallback(msg.payload.status === 'ok' ? 'ok' : 'error')
537
+ } catch (e) {
538
+ this.log('error', 'error in heartbeat callback', e)
539
+ }
522
540
  }
523
541
 
524
542
  // Handle pending heartbeat reference cleanup
@@ -806,7 +824,7 @@ export default class RealtimeClient {
806
824
  options?.heartbeatIntervalMs ?? CONNECTION_TIMEOUTS.HEARTBEAT_INTERVAL
807
825
  this.worker = options?.worker ?? false
808
826
  this.accessToken = options?.accessToken ?? null
809
-
827
+ this.heartbeatCallback = options?.heartbeatCallback ?? noop
810
828
  // Handle special cases
811
829
  if (options?.params) this.params = options.params
812
830
  if (options?.logger) this.logger = options.logger
@@ -60,11 +60,15 @@ type Record = {
60
60
  */
61
61
  export const convertChangeData = (
62
62
  columns: Columns,
63
- record: Record,
63
+ record: Record | null,
64
64
  options: { skipTypes?: string[] } = {}
65
65
  ): Record => {
66
66
  const skipTypes = options.skipTypes ?? []
67
67
 
68
+ if (!record) {
69
+ return {}
70
+ }
71
+
68
72
  return Object.keys(record).reduce((acc, rec_key) => {
69
73
  acc[rec_key] = convertColumn(rec_key, columns, record, skipTypes)
70
74
  return acc
@@ -4,4 +4,4 @@
4
4
  // - Debugging and support (identifying which version is running)
5
5
  // - Telemetry and logging (version reporting in errors/analytics)
6
6
  // - Ensuring build artifacts match the published package version
7
- export const version = '2.72.1-canary.9'
7
+ export const version = '2.80.1-canary.1'
@@ -73,32 +73,38 @@ export class WebSocketFactory {
73
73
  }
74
74
  }
75
75
 
76
- if (typeof process !== 'undefined' && process.versions && process.versions.node) {
77
- const nodeVersion = parseInt(process.versions.node.split('.')[0])
78
-
79
- // Node.js 22+ should have native WebSocket
80
- if (nodeVersion >= 22) {
81
- // Check if native WebSocket is available (should be in Node.js 22+)
82
- if (typeof globalThis.WebSocket !== 'undefined') {
83
- return { type: 'native', constructor: globalThis.WebSocket }
76
+ if (typeof process !== 'undefined') {
77
+ // Use dynamic property access to avoid Next.js Edge Runtime static analysis warnings
78
+ const processVersions = (process as any)['versions']
79
+ if (processVersions && processVersions['node']) {
80
+ // Remove 'v' prefix if present and parse the major version
81
+ const versionString = processVersions['node']
82
+ const nodeVersion = parseInt(versionString.replace(/^v/, '').split('.')[0])
83
+
84
+ // Node.js 22+ should have native WebSocket
85
+ if (nodeVersion >= 22) {
86
+ // Check if native WebSocket is available (should be in Node.js 22+)
87
+ if (typeof globalThis.WebSocket !== 'undefined') {
88
+ return { type: 'native', constructor: globalThis.WebSocket }
89
+ }
90
+ // If not available, user needs to provide it
91
+ return {
92
+ type: 'unsupported',
93
+ error: `Node.js ${nodeVersion} detected but native WebSocket not found.`,
94
+ workaround: 'Provide a WebSocket implementation via the transport option.',
95
+ }
84
96
  }
85
- // If not available, user needs to provide it
97
+
98
+ // Node.js < 22 doesn't have native WebSocket
86
99
  return {
87
100
  type: 'unsupported',
88
- error: `Node.js ${nodeVersion} detected but native WebSocket not found.`,
89
- workaround: 'Provide a WebSocket implementation via the transport option.',
101
+ error: `Node.js ${nodeVersion} detected without native WebSocket support.`,
102
+ workaround:
103
+ 'For Node.js < 22, install "ws" package and provide it via the transport option:\n' +
104
+ 'import ws from "ws"\n' +
105
+ 'new RealtimeClient(url, { transport: ws })',
90
106
  }
91
107
  }
92
-
93
- // Node.js < 22 doesn't have native WebSocket
94
- return {
95
- type: 'unsupported',
96
- error: `Node.js ${nodeVersion} detected without native WebSocket support.`,
97
- workaround:
98
- 'For Node.js < 22, install "ws" package and provide it via the transport option:\n' +
99
- 'import ws from "ws"\n' +
100
- 'new RealtimeClient(url, { transport: ws })',
101
- }
102
108
  }
103
109
 
104
110
  return {