@adventurelabs/scout-core 1.0.21 → 1.0.23
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.
|
@@ -2,13 +2,9 @@
|
|
|
2
2
|
import { useAppDispatch } from "../store/hooks";
|
|
3
3
|
import { useEffect, useRef } from "react";
|
|
4
4
|
import { addDevice, addPlan, addTag, deleteDevice, deletePlan, deleteTag, updateDevice, updatePlan, updateTag, } from "../store/scout";
|
|
5
|
-
|
|
6
|
-
import { get_device_by_id } from "../helpers/devices";
|
|
7
|
-
import { EnumWebResponse } from "../types/requests";
|
|
8
|
-
export function useScoutDbListener() {
|
|
9
|
-
const url = process.env.NEXT_PUBLIC_SUPABASE_URL || "";
|
|
10
|
-
const anon_key = process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY || "";
|
|
5
|
+
export function useScoutDbListener(scoutSupabase) {
|
|
11
6
|
const supabase = useRef(null);
|
|
7
|
+
const channels = useRef([]);
|
|
12
8
|
const dispatch = useAppDispatch();
|
|
13
9
|
function handleTagInserts(payload) {
|
|
14
10
|
console.log("[DB Listener] Tag INSERT received:", payload.new);
|
|
@@ -24,14 +20,8 @@ export function useScoutDbListener() {
|
|
|
24
20
|
}
|
|
25
21
|
async function handleDeviceInserts(payload) {
|
|
26
22
|
console.log("[DB Listener] Device INSERT received:", payload.new);
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
response_device.data) {
|
|
30
|
-
dispatch(addDevice(response_device.data));
|
|
31
|
-
}
|
|
32
|
-
else {
|
|
33
|
-
console.error("error getting device by id", payload);
|
|
34
|
-
}
|
|
23
|
+
// For now, just dispatch the raw payload since we don't have the device helper
|
|
24
|
+
dispatch(addDevice(payload.new));
|
|
35
25
|
}
|
|
36
26
|
function handleDeviceDeletes(payload) {
|
|
37
27
|
console.log("[DB Listener] Device DELETE received:", payload.old);
|
|
@@ -39,14 +29,8 @@ export function useScoutDbListener() {
|
|
|
39
29
|
}
|
|
40
30
|
async function handleDeviceUpdates(payload) {
|
|
41
31
|
console.log("[DB Listener] Device UPDATE received:", payload.new);
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
response_device.data) {
|
|
45
|
-
dispatch(updateDevice(response_device.data));
|
|
46
|
-
}
|
|
47
|
-
else {
|
|
48
|
-
console.error("error getting device by id", payload);
|
|
49
|
-
}
|
|
32
|
+
// For now, just dispatch the raw payload since we don't have the device helper
|
|
33
|
+
dispatch(updateDevice(payload.new));
|
|
50
34
|
}
|
|
51
35
|
function handlePlanInserts(payload) {
|
|
52
36
|
console.log("[DB Listener] Plan INSERT received:", payload.new);
|
|
@@ -61,43 +45,99 @@ export function useScoutDbListener() {
|
|
|
61
45
|
dispatch(updatePlan(payload.new));
|
|
62
46
|
}
|
|
63
47
|
useEffect(() => {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
48
|
+
console.log("=== SCOUT DB LISTENER DEBUG ===");
|
|
49
|
+
console.log("[DB Listener] Using shared Supabase client from ScoutRefreshProvider context");
|
|
50
|
+
if (!scoutSupabase) {
|
|
51
|
+
console.error("[DB Listener] No Supabase client available from ScoutRefreshProvider context");
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
supabase.current = scoutSupabase;
|
|
55
|
+
// Test authentication first
|
|
56
|
+
const testAuth = async () => {
|
|
57
|
+
try {
|
|
58
|
+
const { data: { user }, error, } = await scoutSupabase.auth.getUser();
|
|
59
|
+
console.log("[DB Listener] Auth test - User:", user ? "authenticated" : "anonymous");
|
|
60
|
+
console.log("[DB Listener] Auth test - Error:", error);
|
|
61
|
+
}
|
|
62
|
+
catch (err) {
|
|
63
|
+
console.error("[DB Listener] Auth test failed:", err);
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
testAuth();
|
|
67
|
+
// Create a single channel for all operations with unique name
|
|
68
|
+
const channelName = `scout_realtime_${Date.now()}`;
|
|
69
|
+
console.log("[DB Listener] Creating channel:", channelName);
|
|
70
|
+
const mainChannel = scoutSupabase.channel(channelName);
|
|
71
|
+
// Subscribe to all events
|
|
72
|
+
mainChannel
|
|
67
73
|
.on("postgres_changes", { event: "INSERT", schema: "public", table: "plans" }, handlePlanInserts)
|
|
68
|
-
.subscribe();
|
|
69
|
-
newSupabase
|
|
70
|
-
.channel("plans_delete")
|
|
71
74
|
.on("postgres_changes", { event: "DELETE", schema: "public", table: "plans" }, handlePlanDeletes)
|
|
72
|
-
.subscribe();
|
|
73
|
-
newSupabase
|
|
74
|
-
.channel("plans_update")
|
|
75
75
|
.on("postgres_changes", { event: "UPDATE", schema: "public", table: "plans" }, handlePlanUpdates)
|
|
76
|
-
.subscribe();
|
|
77
|
-
newSupabase
|
|
78
|
-
.channel("devices_delete")
|
|
79
|
-
.on("postgres_changes", { event: "DELETE", schema: "public", table: "devices" }, handleDeviceDeletes)
|
|
80
|
-
.subscribe();
|
|
81
|
-
newSupabase
|
|
82
|
-
.channel("devices_insert")
|
|
83
76
|
.on("postgres_changes", { event: "INSERT", schema: "public", table: "devices" }, handleDeviceInserts)
|
|
84
|
-
.
|
|
85
|
-
newSupabase
|
|
86
|
-
.channel("devices_update")
|
|
77
|
+
.on("postgres_changes", { event: "DELETE", schema: "public", table: "devices" }, handleDeviceDeletes)
|
|
87
78
|
.on("postgres_changes", { event: "UPDATE", schema: "public", table: "devices" }, handleDeviceUpdates)
|
|
88
|
-
.subscribe();
|
|
89
|
-
newSupabase
|
|
90
|
-
.channel("tags_insert")
|
|
91
79
|
.on("postgres_changes", { event: "INSERT", schema: "public", table: "tags" }, handleTagInserts)
|
|
92
|
-
.subscribe();
|
|
93
|
-
newSupabase
|
|
94
|
-
.channel("tags_delete")
|
|
95
80
|
.on("postgres_changes", { event: "DELETE", schema: "public", table: "tags" }, handleTagDeletes)
|
|
96
|
-
.subscribe();
|
|
97
|
-
newSupabase
|
|
98
|
-
.channel("tags_update")
|
|
99
81
|
.on("postgres_changes", { event: "UPDATE", schema: "public", table: "tags" }, handleTagUpdates)
|
|
100
|
-
.subscribe()
|
|
101
|
-
|
|
102
|
-
|
|
82
|
+
.subscribe((status) => {
|
|
83
|
+
console.log("[DB Listener] Subscription status:", status);
|
|
84
|
+
if (status === "SUBSCRIBED") {
|
|
85
|
+
console.log("[DB Listener] ✅ Successfully subscribed to real-time updates");
|
|
86
|
+
}
|
|
87
|
+
else if (status === "CHANNEL_ERROR") {
|
|
88
|
+
console.error("[DB Listener] ❌ Channel error occurred");
|
|
89
|
+
}
|
|
90
|
+
else if (status === "TIMED_OUT") {
|
|
91
|
+
console.error("[DB Listener] ⏰ Subscription timed out");
|
|
92
|
+
}
|
|
93
|
+
else if (status === "CLOSED") {
|
|
94
|
+
console.log("[DB Listener] 🔒 Channel closed");
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
channels.current.push(mainChannel);
|
|
98
|
+
// Test the connection with system events
|
|
99
|
+
const testChannelName = `test_connection_${Date.now()}`;
|
|
100
|
+
console.log("[DB Listener] Creating test channel:", testChannelName);
|
|
101
|
+
const testChannel = scoutSupabase.channel(testChannelName);
|
|
102
|
+
testChannel
|
|
103
|
+
.on("system", { event: "disconnect" }, () => {
|
|
104
|
+
console.log("[DB Listener] 🔌 Disconnected from Supabase");
|
|
105
|
+
})
|
|
106
|
+
.on("system", { event: "reconnect" }, () => {
|
|
107
|
+
console.log("[DB Listener] 🔗 Reconnected to Supabase");
|
|
108
|
+
})
|
|
109
|
+
.on("system", { event: "error" }, (error) => {
|
|
110
|
+
console.error("[DB Listener] ❌ System error:", error);
|
|
111
|
+
})
|
|
112
|
+
.subscribe((status) => {
|
|
113
|
+
console.log("[DB Listener] Test channel status:", status);
|
|
114
|
+
});
|
|
115
|
+
channels.current.push(testChannel);
|
|
116
|
+
// Test a simple database query to verify connection
|
|
117
|
+
const testDbConnection = async () => {
|
|
118
|
+
try {
|
|
119
|
+
const { data, error } = await scoutSupabase
|
|
120
|
+
.from("tags")
|
|
121
|
+
.select("count")
|
|
122
|
+
.limit(1);
|
|
123
|
+
console.log("[DB Listener] DB connection test - Success:", !!data);
|
|
124
|
+
console.log("[DB Listener] DB connection test - Error:", error);
|
|
125
|
+
}
|
|
126
|
+
catch (err) {
|
|
127
|
+
console.error("[DB Listener] DB connection test failed:", err);
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
testDbConnection();
|
|
131
|
+
console.log("=== END SCOUT DB LISTENER DEBUG ===");
|
|
132
|
+
// Cleanup function
|
|
133
|
+
return () => {
|
|
134
|
+
console.log("[DB Listener] 🧹 Cleaning up channels");
|
|
135
|
+
channels.current.forEach((channel) => {
|
|
136
|
+
if (channel) {
|
|
137
|
+
scoutSupabase.removeChannel(channel);
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
channels.current = [];
|
|
141
|
+
};
|
|
142
|
+
}, [scoutSupabase, dispatch]);
|
|
103
143
|
}
|
|
@@ -1 +1,648 @@
|
|
|
1
|
-
|
|
1
|
+
import { ReactNode } from "react";
|
|
2
|
+
import { SupabaseClient } from "@supabase/supabase-js";
|
|
3
|
+
import { Database } from "../types/supabase";
|
|
4
|
+
export declare function useSupabase(): SupabaseClient<Database, "public", {
|
|
5
|
+
Tables: {
|
|
6
|
+
actions: {
|
|
7
|
+
Row: {
|
|
8
|
+
id: number;
|
|
9
|
+
inserted_at: string;
|
|
10
|
+
opcode: number;
|
|
11
|
+
trigger: string[];
|
|
12
|
+
zone_id: number;
|
|
13
|
+
};
|
|
14
|
+
Insert: {
|
|
15
|
+
id?: number;
|
|
16
|
+
inserted_at?: string;
|
|
17
|
+
opcode: number;
|
|
18
|
+
trigger: string[];
|
|
19
|
+
zone_id: number;
|
|
20
|
+
};
|
|
21
|
+
Update: {
|
|
22
|
+
id?: number;
|
|
23
|
+
inserted_at?: string;
|
|
24
|
+
opcode?: number;
|
|
25
|
+
trigger?: string[];
|
|
26
|
+
zone_id?: number;
|
|
27
|
+
};
|
|
28
|
+
Relationships: [{
|
|
29
|
+
foreignKeyName: "actions_zone_id_fkey";
|
|
30
|
+
columns: ["zone_id"];
|
|
31
|
+
isOneToOne: false;
|
|
32
|
+
referencedRelation: "zones";
|
|
33
|
+
referencedColumns: ["id"];
|
|
34
|
+
}, {
|
|
35
|
+
foreignKeyName: "actions_zone_id_fkey";
|
|
36
|
+
columns: ["zone_id"];
|
|
37
|
+
isOneToOne: false;
|
|
38
|
+
referencedRelation: "zones_and_actions";
|
|
39
|
+
referencedColumns: ["id"];
|
|
40
|
+
}];
|
|
41
|
+
};
|
|
42
|
+
devices: {
|
|
43
|
+
Row: {
|
|
44
|
+
altitude: number | null;
|
|
45
|
+
created_by: string;
|
|
46
|
+
description: string;
|
|
47
|
+
device_type: Database["public"]["Enums"]["device_type"];
|
|
48
|
+
domain_name: string | null;
|
|
49
|
+
heading: number | null;
|
|
50
|
+
herd_id: number;
|
|
51
|
+
id: number;
|
|
52
|
+
inserted_at: string;
|
|
53
|
+
location: unknown | null;
|
|
54
|
+
name: string;
|
|
55
|
+
video_publisher_token: string | null;
|
|
56
|
+
video_subscriber_token: string | null;
|
|
57
|
+
};
|
|
58
|
+
Insert: {
|
|
59
|
+
altitude?: number | null;
|
|
60
|
+
created_by: string;
|
|
61
|
+
description: string;
|
|
62
|
+
device_type?: Database["public"]["Enums"]["device_type"];
|
|
63
|
+
domain_name?: string | null;
|
|
64
|
+
heading?: number | null;
|
|
65
|
+
herd_id: number;
|
|
66
|
+
id?: number;
|
|
67
|
+
inserted_at?: string;
|
|
68
|
+
location?: unknown | null;
|
|
69
|
+
name: string;
|
|
70
|
+
video_publisher_token?: string | null;
|
|
71
|
+
video_subscriber_token?: string | null;
|
|
72
|
+
};
|
|
73
|
+
Update: {
|
|
74
|
+
altitude?: number | null;
|
|
75
|
+
created_by?: string;
|
|
76
|
+
description?: string;
|
|
77
|
+
device_type?: Database["public"]["Enums"]["device_type"];
|
|
78
|
+
domain_name?: string | null;
|
|
79
|
+
heading?: number | null;
|
|
80
|
+
herd_id?: number;
|
|
81
|
+
id?: number;
|
|
82
|
+
inserted_at?: string;
|
|
83
|
+
location?: unknown | null;
|
|
84
|
+
name?: string;
|
|
85
|
+
video_publisher_token?: string | null;
|
|
86
|
+
video_subscriber_token?: string | null;
|
|
87
|
+
};
|
|
88
|
+
Relationships: [{
|
|
89
|
+
foreignKeyName: "devices_created_by_fkey";
|
|
90
|
+
columns: ["created_by"];
|
|
91
|
+
isOneToOne: false;
|
|
92
|
+
referencedRelation: "users";
|
|
93
|
+
referencedColumns: ["id"];
|
|
94
|
+
}, {
|
|
95
|
+
foreignKeyName: "devices_herd_id_fkey";
|
|
96
|
+
columns: ["herd_id"];
|
|
97
|
+
isOneToOne: false;
|
|
98
|
+
referencedRelation: "herds";
|
|
99
|
+
referencedColumns: ["id"];
|
|
100
|
+
}];
|
|
101
|
+
};
|
|
102
|
+
events: {
|
|
103
|
+
Row: {
|
|
104
|
+
altitude: number;
|
|
105
|
+
device_id: number;
|
|
106
|
+
earthranger_url: string | null;
|
|
107
|
+
file_path: string | null;
|
|
108
|
+
heading: number;
|
|
109
|
+
id: number;
|
|
110
|
+
inserted_at: string;
|
|
111
|
+
is_public: boolean;
|
|
112
|
+
location: unknown | null;
|
|
113
|
+
media_type: Database["public"]["Enums"]["media_type"];
|
|
114
|
+
media_url: string | null;
|
|
115
|
+
message: string;
|
|
116
|
+
timestamp_observation: string;
|
|
117
|
+
};
|
|
118
|
+
Insert: {
|
|
119
|
+
altitude: number;
|
|
120
|
+
device_id: number;
|
|
121
|
+
earthranger_url?: string | null;
|
|
122
|
+
file_path?: string | null;
|
|
123
|
+
heading: number;
|
|
124
|
+
id?: number;
|
|
125
|
+
inserted_at?: string;
|
|
126
|
+
is_public?: boolean;
|
|
127
|
+
location?: unknown | null;
|
|
128
|
+
media_type?: Database["public"]["Enums"]["media_type"];
|
|
129
|
+
media_url?: string | null;
|
|
130
|
+
message: string;
|
|
131
|
+
timestamp_observation?: string;
|
|
132
|
+
};
|
|
133
|
+
Update: {
|
|
134
|
+
altitude?: number;
|
|
135
|
+
device_id?: number;
|
|
136
|
+
earthranger_url?: string | null;
|
|
137
|
+
file_path?: string | null;
|
|
138
|
+
heading?: number;
|
|
139
|
+
id?: number;
|
|
140
|
+
inserted_at?: string;
|
|
141
|
+
is_public?: boolean;
|
|
142
|
+
location?: unknown | null;
|
|
143
|
+
media_type?: Database["public"]["Enums"]["media_type"];
|
|
144
|
+
media_url?: string | null;
|
|
145
|
+
message?: string;
|
|
146
|
+
timestamp_observation?: string;
|
|
147
|
+
};
|
|
148
|
+
Relationships: [{
|
|
149
|
+
foreignKeyName: "events_device_id_fkey";
|
|
150
|
+
columns: ["device_id"];
|
|
151
|
+
isOneToOne: false;
|
|
152
|
+
referencedRelation: "devices";
|
|
153
|
+
referencedColumns: ["id"];
|
|
154
|
+
}];
|
|
155
|
+
};
|
|
156
|
+
herds: {
|
|
157
|
+
Row: {
|
|
158
|
+
created_by: string;
|
|
159
|
+
description: string;
|
|
160
|
+
earthranger_domain: string | null;
|
|
161
|
+
earthranger_token: string | null;
|
|
162
|
+
id: number;
|
|
163
|
+
inserted_at: string;
|
|
164
|
+
is_public: boolean;
|
|
165
|
+
slug: string;
|
|
166
|
+
video_publisher_token: string | null;
|
|
167
|
+
video_server_url: string | null;
|
|
168
|
+
video_subscriber_token: string | null;
|
|
169
|
+
};
|
|
170
|
+
Insert: {
|
|
171
|
+
created_by: string;
|
|
172
|
+
description: string;
|
|
173
|
+
earthranger_domain?: string | null;
|
|
174
|
+
earthranger_token?: string | null;
|
|
175
|
+
id?: number;
|
|
176
|
+
inserted_at?: string;
|
|
177
|
+
is_public?: boolean;
|
|
178
|
+
slug: string;
|
|
179
|
+
video_publisher_token?: string | null;
|
|
180
|
+
video_server_url?: string | null;
|
|
181
|
+
video_subscriber_token?: string | null;
|
|
182
|
+
};
|
|
183
|
+
Update: {
|
|
184
|
+
created_by?: string;
|
|
185
|
+
description?: string;
|
|
186
|
+
earthranger_domain?: string | null;
|
|
187
|
+
earthranger_token?: string | null;
|
|
188
|
+
id?: number;
|
|
189
|
+
inserted_at?: string;
|
|
190
|
+
is_public?: boolean;
|
|
191
|
+
slug?: string;
|
|
192
|
+
video_publisher_token?: string | null;
|
|
193
|
+
video_server_url?: string | null;
|
|
194
|
+
video_subscriber_token?: string | null;
|
|
195
|
+
};
|
|
196
|
+
Relationships: [{
|
|
197
|
+
foreignKeyName: "herds_created_by_fkey";
|
|
198
|
+
columns: ["created_by"];
|
|
199
|
+
isOneToOne: false;
|
|
200
|
+
referencedRelation: "users";
|
|
201
|
+
referencedColumns: ["id"];
|
|
202
|
+
}];
|
|
203
|
+
};
|
|
204
|
+
plans: {
|
|
205
|
+
Row: {
|
|
206
|
+
herd_id: number;
|
|
207
|
+
id: number;
|
|
208
|
+
inserted_at: string;
|
|
209
|
+
instructions: string;
|
|
210
|
+
name: string;
|
|
211
|
+
};
|
|
212
|
+
Insert: {
|
|
213
|
+
herd_id: number;
|
|
214
|
+
id?: number;
|
|
215
|
+
inserted_at?: string;
|
|
216
|
+
instructions: string;
|
|
217
|
+
name: string;
|
|
218
|
+
};
|
|
219
|
+
Update: {
|
|
220
|
+
herd_id?: number;
|
|
221
|
+
id?: number;
|
|
222
|
+
inserted_at?: string;
|
|
223
|
+
instructions?: string;
|
|
224
|
+
name?: string;
|
|
225
|
+
};
|
|
226
|
+
Relationships: [{
|
|
227
|
+
foreignKeyName: "plans_herd_id_fkey";
|
|
228
|
+
columns: ["herd_id"];
|
|
229
|
+
isOneToOne: false;
|
|
230
|
+
referencedRelation: "herds";
|
|
231
|
+
referencedColumns: ["id"];
|
|
232
|
+
}];
|
|
233
|
+
};
|
|
234
|
+
tags: {
|
|
235
|
+
Row: {
|
|
236
|
+
class_name: string;
|
|
237
|
+
conf: number;
|
|
238
|
+
event_id: number;
|
|
239
|
+
height: number;
|
|
240
|
+
id: number;
|
|
241
|
+
inserted_at: string;
|
|
242
|
+
observation_type: Database["public"]["Enums"]["tag_observation_type"];
|
|
243
|
+
width: number;
|
|
244
|
+
x: number;
|
|
245
|
+
y: number;
|
|
246
|
+
};
|
|
247
|
+
Insert: {
|
|
248
|
+
class_name: string;
|
|
249
|
+
conf: number;
|
|
250
|
+
event_id: number;
|
|
251
|
+
height?: number;
|
|
252
|
+
id?: number;
|
|
253
|
+
inserted_at?: string;
|
|
254
|
+
observation_type: Database["public"]["Enums"]["tag_observation_type"];
|
|
255
|
+
width: number;
|
|
256
|
+
x: number;
|
|
257
|
+
y: number;
|
|
258
|
+
};
|
|
259
|
+
Update: {
|
|
260
|
+
class_name?: string;
|
|
261
|
+
conf?: number;
|
|
262
|
+
event_id?: number;
|
|
263
|
+
height?: number;
|
|
264
|
+
id?: number;
|
|
265
|
+
inserted_at?: string;
|
|
266
|
+
observation_type?: Database["public"]["Enums"]["tag_observation_type"];
|
|
267
|
+
width?: number;
|
|
268
|
+
x?: number;
|
|
269
|
+
y?: number;
|
|
270
|
+
};
|
|
271
|
+
Relationships: [{
|
|
272
|
+
foreignKeyName: "tags_event_id_fkey";
|
|
273
|
+
columns: ["event_id"];
|
|
274
|
+
isOneToOne: false;
|
|
275
|
+
referencedRelation: "events";
|
|
276
|
+
referencedColumns: ["id"];
|
|
277
|
+
}, {
|
|
278
|
+
foreignKeyName: "tags_event_id_fkey";
|
|
279
|
+
columns: ["event_id"];
|
|
280
|
+
isOneToOne: false;
|
|
281
|
+
referencedRelation: "events_with_tags";
|
|
282
|
+
referencedColumns: ["id"];
|
|
283
|
+
}];
|
|
284
|
+
};
|
|
285
|
+
users: {
|
|
286
|
+
Row: {
|
|
287
|
+
id: string;
|
|
288
|
+
username: string | null;
|
|
289
|
+
};
|
|
290
|
+
Insert: {
|
|
291
|
+
id: string;
|
|
292
|
+
username?: string | null;
|
|
293
|
+
};
|
|
294
|
+
Update: {
|
|
295
|
+
id?: string;
|
|
296
|
+
username?: string | null;
|
|
297
|
+
};
|
|
298
|
+
Relationships: [];
|
|
299
|
+
};
|
|
300
|
+
users_roles_per_herd: {
|
|
301
|
+
Row: {
|
|
302
|
+
herd_id: number;
|
|
303
|
+
id: number;
|
|
304
|
+
inserted_at: string;
|
|
305
|
+
role: Database["public"]["Enums"]["role"];
|
|
306
|
+
user_id: string;
|
|
307
|
+
};
|
|
308
|
+
Insert: {
|
|
309
|
+
herd_id: number;
|
|
310
|
+
id?: number;
|
|
311
|
+
inserted_at?: string;
|
|
312
|
+
role: Database["public"]["Enums"]["role"];
|
|
313
|
+
user_id: string;
|
|
314
|
+
};
|
|
315
|
+
Update: {
|
|
316
|
+
herd_id?: number;
|
|
317
|
+
id?: number;
|
|
318
|
+
inserted_at?: string;
|
|
319
|
+
role?: Database["public"]["Enums"]["role"];
|
|
320
|
+
user_id?: string;
|
|
321
|
+
};
|
|
322
|
+
Relationships: [{
|
|
323
|
+
foreignKeyName: "users_roles_per_herd_herd_id_fkey";
|
|
324
|
+
columns: ["herd_id"];
|
|
325
|
+
isOneToOne: false;
|
|
326
|
+
referencedRelation: "herds";
|
|
327
|
+
referencedColumns: ["id"];
|
|
328
|
+
}, {
|
|
329
|
+
foreignKeyName: "users_roles_per_herd_user_id_fkey";
|
|
330
|
+
columns: ["user_id"];
|
|
331
|
+
isOneToOne: false;
|
|
332
|
+
referencedRelation: "users";
|
|
333
|
+
referencedColumns: ["id"];
|
|
334
|
+
}];
|
|
335
|
+
};
|
|
336
|
+
zones: {
|
|
337
|
+
Row: {
|
|
338
|
+
herd_id: number;
|
|
339
|
+
id: number;
|
|
340
|
+
inserted_at: string;
|
|
341
|
+
region: unknown;
|
|
342
|
+
};
|
|
343
|
+
Insert: {
|
|
344
|
+
herd_id: number;
|
|
345
|
+
id?: number;
|
|
346
|
+
inserted_at?: string;
|
|
347
|
+
region: unknown;
|
|
348
|
+
};
|
|
349
|
+
Update: {
|
|
350
|
+
herd_id?: number;
|
|
351
|
+
id?: number;
|
|
352
|
+
inserted_at?: string;
|
|
353
|
+
region?: unknown;
|
|
354
|
+
};
|
|
355
|
+
Relationships: [{
|
|
356
|
+
foreignKeyName: "zones_herd_id_fkey";
|
|
357
|
+
columns: ["herd_id"];
|
|
358
|
+
isOneToOne: false;
|
|
359
|
+
referencedRelation: "herds";
|
|
360
|
+
referencedColumns: ["id"];
|
|
361
|
+
}];
|
|
362
|
+
};
|
|
363
|
+
};
|
|
364
|
+
Views: {
|
|
365
|
+
events_with_tags: {
|
|
366
|
+
Row: {
|
|
367
|
+
altitude: number | null;
|
|
368
|
+
device_id: number | null;
|
|
369
|
+
earthranger_url: string | null;
|
|
370
|
+
file_path: string | null;
|
|
371
|
+
heading: number | null;
|
|
372
|
+
herd_id: number | null;
|
|
373
|
+
id: number | null;
|
|
374
|
+
inserted_at: string | null;
|
|
375
|
+
is_public: boolean | null;
|
|
376
|
+
location: unknown | null;
|
|
377
|
+
media_type: Database["public"]["Enums"]["media_type"] | null;
|
|
378
|
+
media_url: string | null;
|
|
379
|
+
message: string | null;
|
|
380
|
+
tags: Database["public"]["Tables"]["tags"]["Row"][] | null;
|
|
381
|
+
timestamp_observation: string | null;
|
|
382
|
+
};
|
|
383
|
+
Relationships: [{
|
|
384
|
+
foreignKeyName: "devices_herd_id_fkey";
|
|
385
|
+
columns: ["herd_id"];
|
|
386
|
+
isOneToOne: false;
|
|
387
|
+
referencedRelation: "herds";
|
|
388
|
+
referencedColumns: ["id"];
|
|
389
|
+
}, {
|
|
390
|
+
foreignKeyName: "events_device_id_fkey";
|
|
391
|
+
columns: ["device_id"];
|
|
392
|
+
isOneToOne: false;
|
|
393
|
+
referencedRelation: "devices";
|
|
394
|
+
referencedColumns: ["id"];
|
|
395
|
+
}];
|
|
396
|
+
};
|
|
397
|
+
zones_and_actions: {
|
|
398
|
+
Row: {
|
|
399
|
+
actions: Database["public"]["Tables"]["actions"]["Row"][] | null;
|
|
400
|
+
herd_id: number | null;
|
|
401
|
+
id: number | null;
|
|
402
|
+
inserted_at: string | null;
|
|
403
|
+
region: unknown | null;
|
|
404
|
+
};
|
|
405
|
+
Relationships: [{
|
|
406
|
+
foreignKeyName: "zones_herd_id_fkey";
|
|
407
|
+
columns: ["herd_id"];
|
|
408
|
+
isOneToOne: false;
|
|
409
|
+
referencedRelation: "herds";
|
|
410
|
+
referencedColumns: ["id"];
|
|
411
|
+
}];
|
|
412
|
+
};
|
|
413
|
+
};
|
|
414
|
+
Functions: {
|
|
415
|
+
authorize: {
|
|
416
|
+
Args: {
|
|
417
|
+
requested_permission: Database["public"]["Enums"]["app_permission"];
|
|
418
|
+
};
|
|
419
|
+
Returns: boolean;
|
|
420
|
+
};
|
|
421
|
+
create_api_key: {
|
|
422
|
+
Args: {
|
|
423
|
+
id_of_device: number;
|
|
424
|
+
};
|
|
425
|
+
Returns: undefined;
|
|
426
|
+
};
|
|
427
|
+
create_user: {
|
|
428
|
+
Args: {
|
|
429
|
+
email: string;
|
|
430
|
+
};
|
|
431
|
+
Returns: string;
|
|
432
|
+
};
|
|
433
|
+
custom_access_token_hook: {
|
|
434
|
+
Args: {
|
|
435
|
+
event: import("../types/supabase").Json;
|
|
436
|
+
};
|
|
437
|
+
Returns: import("../types/supabase").Json;
|
|
438
|
+
};
|
|
439
|
+
get_device_by_id: {
|
|
440
|
+
Args: {
|
|
441
|
+
device_id_caller: number;
|
|
442
|
+
};
|
|
443
|
+
Returns: Database["public"]["CompositeTypes"]["device_pretty_location"];
|
|
444
|
+
};
|
|
445
|
+
get_device_from_api_key: {
|
|
446
|
+
Args: {
|
|
447
|
+
device_api_key: string;
|
|
448
|
+
};
|
|
449
|
+
Returns: {
|
|
450
|
+
altitude: number | null;
|
|
451
|
+
created_by: string;
|
|
452
|
+
description: string;
|
|
453
|
+
device_type: Database["public"]["Enums"]["device_type"];
|
|
454
|
+
domain_name: string | null;
|
|
455
|
+
heading: number | null;
|
|
456
|
+
herd_id: number;
|
|
457
|
+
id: number;
|
|
458
|
+
inserted_at: string;
|
|
459
|
+
location: unknown | null;
|
|
460
|
+
name: string;
|
|
461
|
+
video_publisher_token: string | null;
|
|
462
|
+
video_subscriber_token: string | null;
|
|
463
|
+
};
|
|
464
|
+
};
|
|
465
|
+
get_device_id_from_key: {
|
|
466
|
+
Args: {
|
|
467
|
+
device_api_key: string;
|
|
468
|
+
};
|
|
469
|
+
Returns: number;
|
|
470
|
+
};
|
|
471
|
+
get_devices_for_herd: {
|
|
472
|
+
Args: {
|
|
473
|
+
herd_id_caller: number;
|
|
474
|
+
};
|
|
475
|
+
Returns: Database["public"]["CompositeTypes"]["device_pretty_location"][];
|
|
476
|
+
};
|
|
477
|
+
get_events_and_tags_for_device: {
|
|
478
|
+
Args: {
|
|
479
|
+
device_id_caller: number;
|
|
480
|
+
limit_caller: number;
|
|
481
|
+
};
|
|
482
|
+
Returns: Database["public"]["CompositeTypes"]["event_and_tags_pretty_location"][];
|
|
483
|
+
};
|
|
484
|
+
get_events_and_tags_for_herd: {
|
|
485
|
+
Args: {
|
|
486
|
+
herd_id_caller: number;
|
|
487
|
+
limit_caller: number;
|
|
488
|
+
offset_caller: number;
|
|
489
|
+
};
|
|
490
|
+
Returns: Database["public"]["CompositeTypes"]["event_and_tags_pretty_location"][];
|
|
491
|
+
};
|
|
492
|
+
get_events_for_herd: {
|
|
493
|
+
Args: {
|
|
494
|
+
herd_id_in: number;
|
|
495
|
+
};
|
|
496
|
+
Returns: {
|
|
497
|
+
altitude: number;
|
|
498
|
+
device_id: number;
|
|
499
|
+
earthranger_url: string | null;
|
|
500
|
+
file_path: string | null;
|
|
501
|
+
heading: number;
|
|
502
|
+
id: number;
|
|
503
|
+
inserted_at: string;
|
|
504
|
+
is_public: boolean;
|
|
505
|
+
location: unknown | null;
|
|
506
|
+
media_type: Database["public"]["Enums"]["media_type"];
|
|
507
|
+
media_url: string | null;
|
|
508
|
+
message: string;
|
|
509
|
+
timestamp_observation: string;
|
|
510
|
+
}[];
|
|
511
|
+
};
|
|
512
|
+
get_events_with_tags_by_id: {
|
|
513
|
+
Args: {
|
|
514
|
+
event_id_caller: number;
|
|
515
|
+
};
|
|
516
|
+
Returns: Database["public"]["CompositeTypes"]["event_and_tags_pretty_location"];
|
|
517
|
+
};
|
|
518
|
+
get_events_with_tags_for_herd: {
|
|
519
|
+
Args: {
|
|
520
|
+
herd_id_caller: number;
|
|
521
|
+
offset_caller: number;
|
|
522
|
+
limit_caller: number;
|
|
523
|
+
};
|
|
524
|
+
Returns: Database["public"]["CompositeTypes"]["event_with_tags"][];
|
|
525
|
+
};
|
|
526
|
+
get_total_events_for_herd: {
|
|
527
|
+
Args: {
|
|
528
|
+
herd_id_caller: number;
|
|
529
|
+
};
|
|
530
|
+
Returns: number;
|
|
531
|
+
};
|
|
532
|
+
get_zones_and_actions_for_herd: {
|
|
533
|
+
Args: {
|
|
534
|
+
herd_id_caller: number;
|
|
535
|
+
limit_caller: number;
|
|
536
|
+
offset_caller: number;
|
|
537
|
+
};
|
|
538
|
+
Returns: Database["public"]["CompositeTypes"]["zones_and_actions_pretty_location"][];
|
|
539
|
+
};
|
|
540
|
+
load_api_keys: {
|
|
541
|
+
Args: {
|
|
542
|
+
id_of_device: string;
|
|
543
|
+
};
|
|
544
|
+
Returns: string[];
|
|
545
|
+
};
|
|
546
|
+
};
|
|
547
|
+
Enums: {
|
|
548
|
+
app_permission: "herds.delete" | "events.delete";
|
|
549
|
+
device_type: "trail_camera" | "drone_fixed_wing" | "drone_quad" | "gps_tracker" | "sentry_tower" | "smart_buoy" | "radio_mesh_base_station" | "radio_mesh_repeater" | "unknown";
|
|
550
|
+
media_type: "image" | "video" | "audio" | "text";
|
|
551
|
+
role: "admin" | "viewer" | "editor";
|
|
552
|
+
tag_observation_type: "manual" | "auto";
|
|
553
|
+
user_status: "ONLINE" | "OFFLINE";
|
|
554
|
+
};
|
|
555
|
+
CompositeTypes: {
|
|
556
|
+
device_pretty_location: {
|
|
557
|
+
id: number | null;
|
|
558
|
+
inserted_at: string | null;
|
|
559
|
+
created_by: string | null;
|
|
560
|
+
herd_id: number | null;
|
|
561
|
+
device_type: Database["public"]["Enums"]["device_type"] | null;
|
|
562
|
+
domain_name: string | null;
|
|
563
|
+
location: string | null;
|
|
564
|
+
altitude: number | null;
|
|
565
|
+
heading: number | null;
|
|
566
|
+
name: string | null;
|
|
567
|
+
description: string | null;
|
|
568
|
+
latitude: number | null;
|
|
569
|
+
longitude: number | null;
|
|
570
|
+
};
|
|
571
|
+
event_and_tags: {
|
|
572
|
+
id: number | null;
|
|
573
|
+
inserted_at: string | null;
|
|
574
|
+
message: string | null;
|
|
575
|
+
media_url: string | null;
|
|
576
|
+
latitude: number | null;
|
|
577
|
+
longitude: number | null;
|
|
578
|
+
altitude: number | null;
|
|
579
|
+
heading: number | null;
|
|
580
|
+
media_type: Database["public"]["Enums"]["media_type"] | null;
|
|
581
|
+
device_id: number | null;
|
|
582
|
+
timestamp_observation: string | null;
|
|
583
|
+
is_public: boolean | null;
|
|
584
|
+
tags: Database["public"]["Tables"]["tags"]["Row"][] | null;
|
|
585
|
+
herd_id: number | null;
|
|
586
|
+
};
|
|
587
|
+
event_and_tags_pretty_location: {
|
|
588
|
+
id: number | null;
|
|
589
|
+
inserted_at: string | null;
|
|
590
|
+
message: string | null;
|
|
591
|
+
media_url: string | null;
|
|
592
|
+
file_path: string | null;
|
|
593
|
+
latitude: number | null;
|
|
594
|
+
longitude: number | null;
|
|
595
|
+
earthranger_url: string | null;
|
|
596
|
+
altitude: number | null;
|
|
597
|
+
heading: number | null;
|
|
598
|
+
media_type: Database["public"]["Enums"]["media_type"] | null;
|
|
599
|
+
device_id: number | null;
|
|
600
|
+
timestamp_observation: string | null;
|
|
601
|
+
is_public: boolean | null;
|
|
602
|
+
tags: Database["public"]["Tables"]["tags"]["Row"][] | null;
|
|
603
|
+
herd_id: number | null;
|
|
604
|
+
};
|
|
605
|
+
event_plus_tags: {
|
|
606
|
+
id: number | null;
|
|
607
|
+
inserted_at: string | null;
|
|
608
|
+
message: string | null;
|
|
609
|
+
media_url: string | null;
|
|
610
|
+
location: unknown | null;
|
|
611
|
+
earthranger_url: string | null;
|
|
612
|
+
altitude: number | null;
|
|
613
|
+
heading: number | null;
|
|
614
|
+
media_type: Database["public"]["Enums"]["media_type"] | null;
|
|
615
|
+
device_id: number | null;
|
|
616
|
+
timestamp_observation: string | null;
|
|
617
|
+
is_public: boolean | null;
|
|
618
|
+
tags: Database["public"]["Tables"]["tags"]["Row"][] | null;
|
|
619
|
+
herd_id: number | null;
|
|
620
|
+
};
|
|
621
|
+
event_with_tags: {
|
|
622
|
+
id: number | null;
|
|
623
|
+
inserted_at: string | null;
|
|
624
|
+
message: string | null;
|
|
625
|
+
media_url: string | null;
|
|
626
|
+
latitude: number | null;
|
|
627
|
+
longitude: number | null;
|
|
628
|
+
altitude: number | null;
|
|
629
|
+
heading: number | null;
|
|
630
|
+
media_type: Database["public"]["Enums"]["media_type"] | null;
|
|
631
|
+
device_id: number | null;
|
|
632
|
+
timestamp_observation: string | null;
|
|
633
|
+
is_public: boolean | null;
|
|
634
|
+
tags: Database["public"]["Tables"]["tags"]["Row"][] | null;
|
|
635
|
+
};
|
|
636
|
+
zones_and_actions_pretty_location: {
|
|
637
|
+
id: number | null;
|
|
638
|
+
inserted_at: string | null;
|
|
639
|
+
region: string | null;
|
|
640
|
+
herd_id: number | null;
|
|
641
|
+
actions: Database["public"]["Tables"]["actions"]["Row"][] | null;
|
|
642
|
+
};
|
|
643
|
+
};
|
|
644
|
+
}>;
|
|
645
|
+
export interface ScoutRefreshProviderProps {
|
|
646
|
+
children: ReactNode;
|
|
647
|
+
}
|
|
648
|
+
export declare function ScoutRefreshProvider({ children }: ScoutRefreshProviderProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,8 +1,29 @@
|
|
|
1
1
|
"use client";
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
3
|
import { useScoutRefresh } from "../hooks/useScoutRefresh";
|
|
3
4
|
import { useScoutDbListener } from "../hooks/useScoutDbListener";
|
|
4
|
-
|
|
5
|
-
|
|
5
|
+
import { createContext, useContext, useRef } from "react";
|
|
6
|
+
import { createBrowserClient } from "@supabase/ssr";
|
|
7
|
+
// Create context for the Supabase client
|
|
8
|
+
const SupabaseContext = createContext(null);
|
|
9
|
+
// Hook to use the Supabase client
|
|
10
|
+
export function useSupabase() {
|
|
11
|
+
const supabase = useContext(SupabaseContext);
|
|
12
|
+
if (!supabase) {
|
|
13
|
+
throw new Error("useSupabase must be used within a SupabaseProvider");
|
|
14
|
+
}
|
|
15
|
+
return supabase;
|
|
16
|
+
}
|
|
17
|
+
export function ScoutRefreshProvider({ children }) {
|
|
18
|
+
const url = process.env.NEXT_PUBLIC_SUPABASE_URL || "";
|
|
19
|
+
const anon_key = process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY || "";
|
|
20
|
+
// Create a single Supabase client instance
|
|
21
|
+
const supabaseRef = useRef(null);
|
|
22
|
+
if (!supabaseRef.current) {
|
|
23
|
+
supabaseRef.current = createBrowserClient(url, anon_key);
|
|
24
|
+
console.log("[ScoutRefreshProvider] Created Supabase client");
|
|
25
|
+
}
|
|
26
|
+
useScoutDbListener(supabaseRef.current);
|
|
6
27
|
useScoutRefresh();
|
|
7
|
-
return
|
|
28
|
+
return (_jsx(SupabaseContext.Provider, { value: supabaseRef.current, children: children }));
|
|
8
29
|
}
|