Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

Add error handling for realtime inspector broadcast (#20565)

Joshen Limc5ebc8023c3b
diff --git a/apps/docs/package.json b/apps/docs/package.json
index 1a109effc28..86ad2449f31 100644
--- a/apps/docs/package.json
+++ b/apps/docs/package.json
@@ -28,7 +28,7 @@
"@octokit/plugin-paginate-graphql": "^4.0.0",
"@radix-ui/react-accordion": "^1.1.2",
"@supabase/auth-helpers-react": "^0.4.2",
- "@supabase/supabase-js": "^2.38.2",
+ "@supabase/supabase-js": "^2.39.3",
"common": "*",
"config": "*",
"framer-motion": "^6.5.1",
diff --git a/apps/studio/components/interfaces/Realtime/Inspector/MessagesTable.tsx b/apps/studio/components/interfaces/Realtime/Inspector/MessagesTable.tsx
index 402b122a498..d8a6846f41e 100644
--- a/apps/studio/components/interfaces/Realtime/Inspector/MessagesTable.tsx
+++ b/apps/studio/components/interfaces/Realtime/Inspector/MessagesTable.tsx
@@ -1,12 +1,12 @@
-import { useParams } from 'common'
import { isEqual } from 'lodash'
-import { Loader2 } from 'lucide-react'
+import { Loader2, MegaphoneIcon } from 'lucide-react'
import Link from 'next/link'
import { Key, useEffect, useState } from 'react'
import DataGrid, { RenderRowProps, Row } from 'react-data-grid'
-import { Button, IconBroadcast, IconDatabaseChanges, IconExternalLink, IconPresence, cn } from 'ui'
+import { useParams } from 'common'
import ShimmerLine from 'components/ui/ShimmerLine'
+import { Button, IconBroadcast, IconDatabaseChanges, IconExternalLink, IconPresence, cn } from 'ui'
import MessageSelection from './MessageSelection'
import { LogData } from './Messages.types'
import NoChannelEmptyState from './NoChannelEmptyState'
@@ -33,7 +33,7 @@ const NoResultAlert = ({
<NoChannelEmptyState />
) : (
<>
- {enabled ? <p>No Realtime messages found</p> : null}
+ {enabled && <p className="text-foreground">No Realtime messages found</p>}
<p className="text-foreground-lighter">Realtime message logs will be shown here</p>
<div className="mt-4 border bg-surface-100 border-border rounded-md justify-start items-center flex flex-col w-full">
@@ -136,7 +136,7 @@ const MessagesTable = ({
<div className={cn('flex h-full flex-row', enabled ? 'border-brand-400' : null)}>
<div className="flex flex-grow flex-col">
{enabled && (
- <div className="w-full h-8 px-4 bg-surface-100 border-b items-center inline-flex justify-between text-foreground-light">
+ <div className="w-full h-9 px-4 bg-surface-100 border-b items-center inline-flex justify-between text-foreground-light">
<div className="inline-flex gap-2.5 text-xs">
<Loader2 size="16" className="animate-spin" />
<div>Listening</div>
@@ -149,10 +149,12 @@ const MessagesTable = ({
: `No message found yet...`}
</div>
</div>
- <Button type="text" onClick={showSendMessage} className="group">
- <span className="text-foreground-light group-hover:text-foreground transition">
- Broadcast a message
- </span>
+ <Button
+ type="default"
+ onClick={showSendMessage}
+ icon={<MegaphoneIcon size={14} strokeWidth={1.5} />}
+ >
+ <span>Broadcast a message</span>
</Button>
</div>
)}
diff --git a/apps/studio/components/interfaces/Realtime/Inspector/RealtimeTokensPopover/index.tsx b/apps/studio/components/interfaces/Realtime/Inspector/RealtimeTokensPopover/index.tsx
index 348b234d828..98e81352ae6 100644
--- a/apps/studio/components/interfaces/Realtime/Inspector/RealtimeTokensPopover/index.tsx
+++ b/apps/studio/components/interfaces/Realtime/Inspector/RealtimeTokensPopover/index.tsx
@@ -20,7 +20,7 @@ export const RealtimeTokensPopover = ({ config, onChangeConfig }: RealtimeTokens
? apiService.serviceApiKey
: undefined
- const anonServiceRoleKey = apiService?.service_api_keys.find((x) => x.name === 'anon key')
+ const anonRoleKey = apiService?.service_api_keys.find((x) => x.name === 'anon key')
? apiService.serviceApiKey
: undefined
@@ -41,7 +41,7 @@ export const RealtimeTokensPopover = ({ config, onChangeConfig }: RealtimeTokens
snap.role !== undefined &&
snap.role.type === 'postgrest'
) {
- token = anonServiceRoleKey
+ token = anonRoleKey
bearer = getRoleImpersonationJWT(config.projectRef, jwtSecret, snap.role)
} else {
token = serviceRoleKey
diff --git a/apps/studio/components/interfaces/Realtime/Inspector/index.tsx b/apps/studio/components/interfaces/Realtime/Inspector/index.tsx
index 0dbed74dad5..646b02b276c 100644
--- a/apps/studio/components/interfaces/Realtime/Inspector/index.tsx
+++ b/apps/studio/components/interfaces/Realtime/Inspector/index.tsx
@@ -47,8 +47,7 @@ export const RealtimeInspector = () => {
visible={sendMessageShown}
onSelectCancel={() => setSendMessageShown(false)}
onSelectConfirm={(v) => {
- sendMessage(v.message, v.payload)
- setSendMessageShown(false)
+ sendMessage(v.message, v.payload, () => setSendMessageShown(false))
}}
/>
</div>
diff --git a/apps/studio/components/interfaces/Realtime/Inspector/useRealtimeMessages.ts b/apps/studio/components/interfaces/Realtime/Inspector/useRealtimeMessages.ts
index b92206f91ec..375463d51d6 100644
--- a/apps/studio/components/interfaces/Realtime/Inspector/useRealtimeMessages.ts
+++ b/apps/studio/components/interfaces/Realtime/Inspector/useRealtimeMessages.ts
@@ -193,14 +193,19 @@ export const useRealtimeMessages = ({
])
const sendMessage = useCallback(
- (message: string, payload: any) => {
+ async (message: string, payload: any, callback: () => void) => {
if (channel) {
- channel.send({
+ const res = await channel.send({
type: 'broadcast',
event: message,
payload,
})
- toast.success('Successfully broadcasted message')
+ if (res === 'error') {
+ toast.error('Failed to broadcast message')
+ } else {
+ toast.success('Successfully broadcasted message')
+ callback()
+ }
} else {
toast.error('Failed to broadcast message: channel has not been set')
}
diff --git a/apps/studio/package.json b/apps/studio/package.json
index c3835cee2e9..e7f3f310d18 100644
--- a/apps/studio/package.json
+++ b/apps/studio/package.json
@@ -33,7 +33,7 @@
"@stripe/stripe-js": "^2.1.11",
"@supabase/auth-helpers-react": "^0.4.2",
"@supabase/shared-types": "0.1.55",
- "@supabase/supabase-js": "^2.38.2",
+ "@supabase/supabase-js": "^2.39.3",
"@tanstack/react-query": "^4.35.7",
"@tanstack/react-query-devtools": "^4.35.7",
"@uidotdev/usehooks": "^2.4.1",
diff --git a/apps/www/package.json b/apps/www/package.json
index 0c43b2719e6..18d8d4153c0 100644
--- a/apps/www/package.json
+++ b/apps/www/package.json
@@ -26,7 +26,7 @@
"@react-three/fiber": "^7.0.29",
"@supabase/auth-helpers-react": "^0.4.2",
"@supabase/auth-ui-react": "^0.4.5",
- "@supabase/supabase-js": "^2.38.2",
+ "@supabase/supabase-js": "^2.39.3",
"classnames": "^2.3.1",
"cobe": "^0.6.2",
"common": "*",
diff --git a/package-lock.json b/package-lock.json
index 766d68aa99e..6aa90954208 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -496,7 +496,7 @@
"@octokit/plugin-paginate-graphql": "^4.0.0",
"@radix-ui/react-accordion": "^1.1.2",
"@supabase/auth-helpers-react": "^0.4.2",
- "@supabase/supabase-js": "^2.38.2",
+ "@supabase/supabase-js": "^2.39.3",
"common": "*",
"config": "*",
"framer-motion": "^6.5.1",
@@ -737,7 +737,7 @@
"@stripe/stripe-js": "^2.1.11",
"@supabase/auth-helpers-react": "^0.4.2",
"@supabase/shared-types": "0.1.55",
- "@supabase/supabase-js": "^2.38.2",
+ "@supabase/supabase-js": "^2.39.3",
"@tanstack/react-query": "^4.35.7",
"@tanstack/react-query-devtools": "^4.35.7",
"@uidotdev/usehooks": "^2.4.1",
@@ -1043,7 +1043,7 @@
"@react-three/fiber": "^7.0.29",
"@supabase/auth-helpers-react": "^0.4.2",
"@supabase/auth-ui-react": "^0.4.5",
- "@supabase/supabase-js": "^2.38.2",
+ "@supabase/supabase-js": "^2.39.3",
"classnames": "^2.3.1",
"cobe": "^0.6.2",
"common": "*",
@@ -10755,9 +10755,9 @@
"link": true
},
"node_modules/@supabase/gotrue-js": {
- "version": "2.58.0",
- "resolved": "https://registry.npmjs.org/@supabase/gotrue-js/-/gotrue-js-2.58.0.tgz",
- "integrity": "sha512-cDslIiiPUzS8DQQqYxK9kT+Ngbrbx0a68e+AsU3H4+eLyAfq+m9aAqKXHHr3H5jqeFvIprSe87r4SeyOYyMnrQ==",
+ "version": "2.62.0",
+ "resolved": "https://registry.npmjs.org/@supabase/gotrue-js/-/gotrue-js-2.62.0.tgz",
+ "integrity": "sha512-4eBuZNXGOk7ewqJuHPYMnk8clCtEx6Hfnu6yHLjZlx7w18TqcojcTRUBZagErtpgwwdfzUwKbquexhbrpH/ysw==",
"dependencies": {
"@supabase/node-fetch": "^2.6.14"
}
@@ -10812,20 +10812,22 @@
"license": "MIT"
},
"node_modules/@supabase/postgrest-js": {
- "version": "1.8.5",
- "license": "MIT",
+ "version": "1.9.2",
+ "resolved": "https://registry.npmjs.org/@supabase/postgrest-js/-/postgrest-js-1.9.2.tgz",
+ "integrity": "sha512-I6yHo8CC9cxhOo6DouDMy9uOfW7hjdsnCxZiaJuIVZm1dBGTFiQPgfMa9zXCamEWzNyWRjZvupAUuX+tqcl5Sw==",
"dependencies": {
"@supabase/node-fetch": "^2.6.14"
}
},
"node_modules/@supabase/realtime-js": {
- "version": "2.8.2",
- "license": "MIT",
+ "version": "2.9.3",
+ "resolved": "https://registry.npmjs.org/@supabase/realtime-js/-/realtime-js-2.9.3.tgz",
+ "integrity": "sha512-lAp50s2n3FhGJFq+wTSXLNIDPw5Y0Wxrgt44eM5nLSA3jZNUUP3Oq2Ccd1CbZdVntPCWLZvJaU//pAd2NE+QnQ==",
"dependencies": {
"@supabase/node-fetch": "^2.6.14",
"@types/phoenix": "^1.5.4",
- "@types/websocket": "^1.0.3",
- "websocket": "^1.0.34"
+ "@types/ws": "^8.5.10",
+ "ws": "^8.14.2"
}
},
"node_modules/@supabase/shared-types": {
@@ -10852,14 +10854,15 @@
}
},
"node_modules/@supabase/supabase-js": {
- "version": "2.38.3",
- "license": "MIT",
+ "version": "2.39.3",
+ "resolved": "https://registry.npmjs.org/@supabase/supabase-js/-/supabase-js-2.39.3.tgz",
+ "integrity": "sha512-NoltJSaJNKDJNutO5sJPAAi5RIWrn1z2XH+ig1+cHDojT6BTN7TvZPNa3Kq3gFQWfO5H1N9El/bCTZJ3iFW2kQ==",
"dependencies": {
"@supabase/functions-js": "^2.1.5",
- "@supabase/gotrue-js": "^2.56.0",
+ "@supabase/gotrue-js": "^2.60.0",
"@supabase/node-fetch": "^2.6.14",
- "@supabase/postgrest-js": "^1.8.5",
- "@supabase/realtime-js": "^2.8.2",
+ "@supabase/postgrest-js": "^1.9.0",
+ "@supabase/realtime-js": "^2.9.3",
"@supabase/storage-js": "^2.5.4"
}
},
@@ -11893,8 +11896,9 @@
"license": "MIT"
},
"node_modules/@types/phoenix": {
- "version": "1.6.3",
- "license": "MIT"
+ "version": "1.6.4",
+ "resolved": "https://registry.npmjs.org/@types/phoenix/-/phoenix-1.6.4.tgz",
+ "integrity": "sha512-B34A7uot1Cv0XtaHRYDATltAdKx0BvVKNgYNqE4WjtPUa4VQJM7kxeXcVKaH+KS+kCmZ+6w+QaUdcljiheiBJA=="
},
"node_modules/@types/pretty-hrtime": {
"version": "1.0.1",
@@ -12153,9 +12157,10 @@
"dev": true,
"license": "MIT"
},
- "node_modules/@types/websocket": {
- "version": "1.0.8",
- "license": "MIT",
+ "node_modules/@types/ws": {
+ "version": "8.5.10",
+ "resolved": "https://registry.npmjs.org/@types/ws/-/ws-8.5.10.tgz",
+ "integrity": "sha512-vmQSUcfalpIq0R9q7uTo2lXs6eGIpt9wtnLdMv9LVpIjCA/+ufZRozlVoVelIYixx1ugCBKDhn89vnsEGOCx9A==",
"dependencies": {
"@types/node": "*"
}
@@ -14314,6 +14319,8 @@
"version": "4.0.7",
"hasInstallScript": true,
"license": "MIT",
+ "optional": true,
+ "peer": true,
"dependencies": {
"node-gyp-build": "^4.3.0"
},
@@ -15971,14 +15978,6 @@
"version": "2.0.1",
"license": "MIT"
},
- "node_modules/d": {
- "version": "1.0.1",
- "license": "ISC",
- "dependencies": {
- "es5-ext": "^0.10.50",
- "type": "^1.0.1"
- }
- },
"node_modules/d3": {
"version": "7.8.5",
"license": "ISC",
@@ -17293,42 +17292,12 @@
"url": "https://github.com/sponsors/ljharb"
}
},
- "node_modules/es5-ext": {
- "version": "0.10.62",
- "hasInstallScript": true,
- "license": "ISC",
- "dependencies": {
- "es6-iterator": "^2.0.3",
- "es6-symbol": "^3.1.3",
- "next-tick": "^1.1.0"
- },
- "engines": {
- "node": ">=0.10"
- }
- },
- "node_modules/es6-iterator": {
- "version": "2.0.3",
- "license": "MIT",
- "dependencies": {
- "d": "1",
- "es5-ext": "^0.10.35",
- "es6-symbol": "^3.1.1"
- }
- },
"node_modules/es6-promise": {
"version": "3.3.1",
"resolved": "https://registry.npmjs.org/es6-promise/-/es6-promise-3.3.1.tgz",
"integrity": "sha512-SOp9Phqvqn7jtEUxPWdWfWoLmyt2VaJ6MpvP9Comy1MceMXqE6bxvaTu4iaxpYYPzhny28Lc+M87/c2cPK6lDg==",
"dev": true
},
- "node_modules/es6-symbol": {
- "version": "3.1.3",
- "license": "ISC",
- "dependencies": {
- "d": "^1.0.1",
- "ext": "^1.1.2"
- }
- },
"node_modules/esbuild": {
"version": "0.18.20",
"dev": true,
@@ -18598,17 +18567,6 @@
],
"license": "MIT"
},
- "node_modules/ext": {
- "version": "1.7.0",
- "license": "ISC",
- "dependencies": {
- "type": "^2.7.2"
- }
- },
- "node_modules/ext/node_modules/type": {
- "version": "2.7.2",
- "license": "ISC"
- },
"node_modules/extend": {
"version": "3.0.2",
"license": "MIT"
@@ -21441,10 +21399,6 @@
"url": "https://github.com/sponsors/ljharb"
}
},
- "node_modules/is-typedarray": {
- "version": "1.0.0",
- "license": "MIT"
- },
"node_modules/is-unicode-supported": {
"version": "0.1.0",
"dev": true,
@@ -27148,10 +27102,6 @@
"react-dom": "*"
}
},
- "node_modules/next-tick": {
- "version": "1.1.0",
- "license": "ISC"
- },
"node_modules/nextjs-node-loader": {
"version": "1.1.5-alpha.0",
"resolved": "https://registry.npmjs.org/nextjs-node-loader/-/nextjs-node-loader-1.1.5-alpha.0.tgz",
@@ -27316,6 +27266,8 @@
"node_modules/node-gyp-build": {
"version": "4.6.1",
"license": "MIT",
+ "optional": true,
+ "peer": true,
"bin": {
"node-gyp-build": "bin.js",
"node-gyp-build-optional": "optional.js",
@@ -35033,10 +34985,6 @@
"win32"
]
},
- "node_modules/type": {
- "version": "1.2.0",
- "license": "ISC"
- },
"node_modules/type-check": {
"version": "0.4.0",
"license": "MIT",
@@ -35143,13 +35091,6 @@
"version": "0.0.6",
"license": "MIT"
},
- "node_modules/typedarray-to-buffer": {
- "version": "3.1.5",
- "license": "MIT",
- "dependencies": {
- "is-typedarray": "^1.0.0"
- }
- },
"node_modules/typescript": {
"version": "5.2.2",
"license": "Apache-2.0",
@@ -35721,6 +35662,8 @@
"version": "5.0.10",
"hasInstallScript": true,
"license": "MIT",
+ "optional": true,
+ "peer": true,
"dependencies": {
"node-gyp-build": "^4.3.0"
},
@@ -36426,32 +36369,6 @@
"node": ">=4.0"
}
},
- "node_modules/websocket": {
- "version": "1.0.34",
- "license": "Apache-2.0",
- "dependencies": {
- "bufferutil": "^4.0.1",
- "debug": "^2.2.0",
- "es5-ext": "^0.10.50",
- "typedarray-to-buffer": "^3.1.5",
- "utf-8-validate": "^5.0.2",
- "yaeti": "^0.0.6"
- },
- "engines": {
- "node": ">=4.0.0"
- }
- },
- "node_modules/websocket/node_modules/debug": {
- "version": "2.6.9",
- "license": "MIT",
- "dependencies": {
- "ms": "2.0.0"
- }
- },
- "node_modules/websocket/node_modules/ms": {
- "version": "2.0.0",
- "license": "MIT"
- },
"node_modules/whatwg-encoding": {
"version": "2.0.0",
"dev": true,
@@ -36720,7 +36637,6 @@
},
"node_modules/ws": {
"version": "8.14.2",
- "dev": true,
"license": "MIT",
"engines": {
"node": ">=10.0.0"
@@ -36770,13 +36686,6 @@
"node": ">=10"
}
},
- "node_modules/yaeti": {
- "version": "0.0.6",
- "license": "MIT",
- "engines": {
- "node": ">=0.10.32"
- }
- },
"node_modules/yallist": {
"version": "3.1.1",
"resolved": "https://registry.npmjs.org/yallist/-/yallist-3.1.1.tgz",
@@ -37841,7 +37750,7 @@
"license": "MIT",
"devDependencies": {
"@faker-js/faker": "^6.1.2",
- "@supabase/supabase-js": "^2.37.0",
+ "@supabase/supabase-js": "^2.39.3",
"@testdeck/jest": "^0.3.3",
"@types/jest": "^29.5.4",
"@types/node": "^17.0.24",
diff --git a/tests/package.json b/tests/package.json
index fd4bb543672..9fa13d5a4c5 100644
--- a/tests/package.json
+++ b/tests/package.json
@@ -18,7 +18,7 @@
"license": "MIT",
"devDependencies": {
"@faker-js/faker": "^6.1.2",
- "@supabase/supabase-js": "^2.37.0",
+ "@supabase/supabase-js": "^2.39.3",
"@testdeck/jest": "^0.3.3",
"@types/jest": "^29.5.4",
"@types/node": "^17.0.24",