squarefi-bff-api-module 1.36.14 → 1.36.16
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.
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
export interface SubscriptionConfig {
|
|
2
2
|
channelName: string;
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
event?: 'INSERT' | 'UPDATE' | 'DELETE' | '*';
|
|
6
|
-
filter?: string;
|
|
3
|
+
/** Broadcast event name emitted by the database trigger (realtime.send). */
|
|
4
|
+
event: string;
|
|
7
5
|
}
|
|
8
6
|
export interface UseSupabaseSubscriptionProps {
|
|
9
7
|
config: SubscriptionConfig;
|
|
@@ -13,14 +13,12 @@ export const useSupabaseSubscription = ({ config, callback, enabled = true, key
|
|
|
13
13
|
supabaseClient.removeChannel(subscriptionRef.current);
|
|
14
14
|
subscriptionRef.current = null;
|
|
15
15
|
}
|
|
16
|
+
// The channel name IS the broadcast topic — it must match what the DB trigger sends
|
|
17
|
+
// (`wallet-transactions-<walletId>`). `key` only re-triggers the effect (see deps), it must
|
|
18
|
+
// never override the topic, otherwise the client subscribes to the wrong channel.
|
|
16
19
|
const subscription = supabaseClient
|
|
17
|
-
.channel(
|
|
18
|
-
.on('
|
|
19
|
-
event: config.event || '*',
|
|
20
|
-
schema: config.schema || 'public',
|
|
21
|
-
table: config.table,
|
|
22
|
-
...(config.filter && { filter: config.filter }),
|
|
23
|
-
}, (payload) => callbackRef.current(payload))
|
|
20
|
+
.channel(config.channelName, { config: { private: true } })
|
|
21
|
+
.on('broadcast', { event: config.event }, (payload) => callbackRef.current(payload))
|
|
24
22
|
.subscribe();
|
|
25
23
|
subscriptionRef.current = subscription;
|
|
26
24
|
return () => {
|
|
@@ -29,7 +27,7 @@ export const useSupabaseSubscription = ({ config, callback, enabled = true, key
|
|
|
29
27
|
subscriptionRef.current = null;
|
|
30
28
|
}
|
|
31
29
|
};
|
|
32
|
-
}, [enabled, config.channelName, config.
|
|
30
|
+
}, [enabled, config.channelName, config.event, supabaseClient, key]);
|
|
33
31
|
return {
|
|
34
32
|
isConnected: !!subscriptionRef.current,
|
|
35
33
|
isClientAvailable: !!supabaseClient,
|