@supabase/realtime-js 2.71.2-canary.7 → 2.72.1-canary.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.
- package/README.md +96 -29
- package/dist/main/RealtimeChannel.d.ts.map +1 -1
- package/dist/main/RealtimeChannel.js +4 -3
- package/dist/main/RealtimeChannel.js.map +1 -1
- package/dist/main/RealtimeClient.d.ts +2 -0
- package/dist/main/RealtimeClient.d.ts.map +1 -1
- package/dist/main/RealtimeClient.js +30 -8
- package/dist/main/RealtimeClient.js.map +1 -1
- package/dist/main/lib/constants.d.ts +2 -2
- package/dist/main/lib/transformers.d.ts +1 -1
- package/dist/main/lib/transformers.d.ts.map +1 -1
- package/dist/main/lib/transformers.js +3 -0
- package/dist/main/lib/transformers.js.map +1 -1
- package/dist/main/lib/version.d.ts +1 -1
- package/dist/main/lib/version.d.ts.map +1 -1
- package/dist/main/lib/version.js +7 -1
- package/dist/main/lib/version.js.map +1 -1
- package/dist/main/lib/websocket-factory.d.ts.map +1 -1
- package/dist/main/lib/websocket-factory.js +24 -18
- package/dist/main/lib/websocket-factory.js.map +1 -1
- package/dist/module/RealtimeChannel.d.ts.map +1 -1
- package/dist/module/RealtimeChannel.js +4 -3
- package/dist/module/RealtimeChannel.js.map +1 -1
- package/dist/module/RealtimeClient.d.ts +2 -0
- package/dist/module/RealtimeClient.d.ts.map +1 -1
- package/dist/module/RealtimeClient.js +30 -8
- package/dist/module/RealtimeClient.js.map +1 -1
- package/dist/module/lib/constants.d.ts +2 -2
- package/dist/module/lib/transformers.d.ts +1 -1
- package/dist/module/lib/transformers.d.ts.map +1 -1
- package/dist/module/lib/transformers.js +3 -0
- package/dist/module/lib/transformers.js.map +1 -1
- package/dist/module/lib/version.d.ts +1 -1
- package/dist/module/lib/version.d.ts.map +1 -1
- package/dist/module/lib/version.js +7 -1
- package/dist/module/lib/version.js.map +1 -1
- package/dist/module/lib/websocket-factory.d.ts.map +1 -1
- package/dist/module/lib/websocket-factory.js +24 -18
- package/dist/module/lib/websocket-factory.js.map +1 -1
- package/package.json +6 -8
- package/src/RealtimeChannel.ts +3 -2
- package/src/RealtimeClient.ts +23 -5
- package/src/lib/transformers.ts +5 -1
- package/src/lib/version.ts +7 -1
- package/src/lib/websocket-factory.ts +27 -21
|
@@ -27,29 +27,35 @@ export class WebSocketFactory {
|
|
|
27
27
|
workaround: 'Use serverless functions or a different deployment target for WebSocket functionality.',
|
|
28
28
|
};
|
|
29
29
|
}
|
|
30
|
-
if (typeof process !== 'undefined'
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
if (
|
|
34
|
-
//
|
|
35
|
-
|
|
36
|
-
|
|
30
|
+
if (typeof process !== 'undefined') {
|
|
31
|
+
// Use dynamic property access to avoid Next.js Edge Runtime static analysis warnings
|
|
32
|
+
const processVersions = process['versions'];
|
|
33
|
+
if (processVersions && processVersions['node']) {
|
|
34
|
+
// Remove 'v' prefix if present and parse the major version
|
|
35
|
+
const versionString = processVersions['node'];
|
|
36
|
+
const nodeVersion = parseInt(versionString.replace(/^v/, '').split('.')[0]);
|
|
37
|
+
// Node.js 22+ should have native WebSocket
|
|
38
|
+
if (nodeVersion >= 22) {
|
|
39
|
+
// Check if native WebSocket is available (should be in Node.js 22+)
|
|
40
|
+
if (typeof globalThis.WebSocket !== 'undefined') {
|
|
41
|
+
return { type: 'native', constructor: globalThis.WebSocket };
|
|
42
|
+
}
|
|
43
|
+
// If not available, user needs to provide it
|
|
44
|
+
return {
|
|
45
|
+
type: 'unsupported',
|
|
46
|
+
error: `Node.js ${nodeVersion} detected but native WebSocket not found.`,
|
|
47
|
+
workaround: 'Provide a WebSocket implementation via the transport option.',
|
|
48
|
+
};
|
|
37
49
|
}
|
|
38
|
-
//
|
|
50
|
+
// Node.js < 22 doesn't have native WebSocket
|
|
39
51
|
return {
|
|
40
52
|
type: 'unsupported',
|
|
41
|
-
error: `Node.js ${nodeVersion} detected
|
|
42
|
-
workaround: '
|
|
53
|
+
error: `Node.js ${nodeVersion} detected without native WebSocket support.`,
|
|
54
|
+
workaround: 'For Node.js < 22, install "ws" package and provide it via the transport option:\n' +
|
|
55
|
+
'import ws from "ws"\n' +
|
|
56
|
+
'new RealtimeClient(url, { transport: ws })',
|
|
43
57
|
};
|
|
44
58
|
}
|
|
45
|
-
// Node.js < 22 doesn't have native WebSocket
|
|
46
|
-
return {
|
|
47
|
-
type: 'unsupported',
|
|
48
|
-
error: `Node.js ${nodeVersion} detected without native WebSocket support.`,
|
|
49
|
-
workaround: 'For Node.js < 22, install "ws" package and provide it via the transport option:\n' +
|
|
50
|
-
'import ws from "ws"\n' +
|
|
51
|
-
'new RealtimeClient(url, { transport: ws })',
|
|
52
|
-
};
|
|
53
59
|
}
|
|
54
60
|
return {
|
|
55
61
|
type: 'unsupported',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"websocket-factory.js","sourceRoot":"","sources":["../../../src/lib/websocket-factory.ts"],"names":[],"mappings":"AAkCA,MAAM,OAAO,gBAAgB;IACnB,MAAM,CAAC,iBAAiB;;QAC9B,IAAI,OAAO,SAAS,KAAK,WAAW,EAAE,CAAC;YACrC,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,WAAW,EAAE,SAAS,EAAE,CAAA;QACnD,CAAC;QAED,IAAI,OAAO,UAAU,KAAK,WAAW,IAAI,OAAQ,UAAkB,CAAC,SAAS,KAAK,WAAW,EAAE,CAAC;YAC9F,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,WAAW,EAAG,UAAkB,CAAC,SAAS,EAAE,CAAA;QACvE,CAAC;QAED,IAAI,OAAO,MAAM,KAAK,WAAW,IAAI,OAAQ,MAAc,CAAC,SAAS,KAAK,WAAW,EAAE,CAAC;YACtF,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,WAAW,EAAG,MAAc,CAAC,SAAS,EAAE,CAAA;QACnE,CAAC;QAED,IACE,OAAO,UAAU,KAAK,WAAW;YACjC,OAAQ,UAAkB,CA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AAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@supabase/realtime-js",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.72.1-canary.0",
|
|
4
4
|
"description": "Listen to realtime updates to your PostgreSQL database",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"realtime",
|
|
@@ -11,8 +11,8 @@
|
|
|
11
11
|
"firebase",
|
|
12
12
|
"supabase"
|
|
13
13
|
],
|
|
14
|
-
"homepage": "https://github.com/supabase/
|
|
15
|
-
"bugs": "https://github.com/supabase/
|
|
14
|
+
"homepage": "https://github.com/supabase/js-client-libs/tree/main/packages/core/realtime-js",
|
|
15
|
+
"bugs": "https://github.com/supabase/js-client-libs/issues",
|
|
16
16
|
"files": [
|
|
17
17
|
"dist",
|
|
18
18
|
"src"
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"types": "dist/module/index.d.ts",
|
|
23
23
|
"repository": {
|
|
24
24
|
"type": "git",
|
|
25
|
-
"url": "https://github.com/supabase/
|
|
25
|
+
"url": "https://github.com/supabase/js-client-libs.git",
|
|
26
26
|
"directory": "packages/core/realtime-js"
|
|
27
27
|
},
|
|
28
28
|
"author": "Supabase",
|
|
@@ -35,13 +35,11 @@
|
|
|
35
35
|
"build:module": "tsc -p tsconfig.module.json",
|
|
36
36
|
"test": "vitest run",
|
|
37
37
|
"test:watch": "vitest",
|
|
38
|
-
"coverage": "vitest run --coverage",
|
|
39
|
-
"coverage:text": "vitest run --coverage.enabled true --coverage.reporter=text",
|
|
38
|
+
"test:coverage": "vitest run --coverage.enabled true --coverage.reporter=text",
|
|
40
39
|
"docs": "typedoc src/index.ts --out docs/v2",
|
|
41
40
|
"docs:json": "typedoc --json docs/v2/spec.json --excludeExternals src/index.ts",
|
|
42
41
|
"check-exports": "attw --pack .",
|
|
43
|
-
"ci": "
|
|
44
|
-
"test:ci": "npm run test && npm run coverage"
|
|
42
|
+
"test:ci": "vitest run --coverage"
|
|
45
43
|
},
|
|
46
44
|
"dependencies": {
|
|
47
45
|
"@types/phoenix": "^1.6.6",
|
package/src/RealtimeChannel.ts
CHANGED
|
@@ -221,8 +221,9 @@ export default class RealtimeChannel {
|
|
|
221
221
|
const postgres_changes = this.bindings.postgres_changes?.map((r) => r.filter) ?? []
|
|
222
222
|
|
|
223
223
|
const presence_enabled =
|
|
224
|
-
!!this.bindings[REALTIME_LISTEN_TYPES.PRESENCE] &&
|
|
225
|
-
|
|
224
|
+
(!!this.bindings[REALTIME_LISTEN_TYPES.PRESENCE] &&
|
|
225
|
+
this.bindings[REALTIME_LISTEN_TYPES.PRESENCE].length > 0) ||
|
|
226
|
+
this.params.config.presence?.enabled === true
|
|
226
227
|
const accessTokenPayload: { access_token?: string } = {}
|
|
227
228
|
const config = {
|
|
228
229
|
broadcast,
|
package/src/RealtimeClient.ts
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
package/src/lib/transformers.ts
CHANGED
|
@@ -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
|
package/src/lib/version.ts
CHANGED
|
@@ -1 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
// Generated automatically during releases by scripts/update-version-files.ts
|
|
2
|
+
// This file provides runtime access to the package version for:
|
|
3
|
+
// - HTTP request headers (e.g., X-Client-Info header for API requests)
|
|
4
|
+
// - Debugging and support (identifying which version is running)
|
|
5
|
+
// - Telemetry and logging (version reporting in errors/analytics)
|
|
6
|
+
// - Ensuring build artifacts match the published package version
|
|
7
|
+
export const version = '2.72.1-canary.0'
|
|
@@ -73,32 +73,38 @@ export class WebSocketFactory {
|
|
|
73
73
|
}
|
|
74
74
|
}
|
|
75
75
|
|
|
76
|
-
if (typeof process !== 'undefined'
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
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
|
-
|
|
97
|
+
|
|
98
|
+
// Node.js < 22 doesn't have native WebSocket
|
|
86
99
|
return {
|
|
87
100
|
type: 'unsupported',
|
|
88
|
-
error: `Node.js ${nodeVersion} detected
|
|
89
|
-
workaround:
|
|
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 {
|