@adventurelabs/scout-core 1.0.21 → 1.0.22

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 +1,3 @@
1
- export declare function useScoutDbListener(): void;
1
+ import { SupabaseClient } from "@supabase/supabase-js";
2
+ import { Database } from "../types/supabase";
3
+ export declare function useScoutDbListener(supabaseClient: SupabaseClient<Database>): void;
@@ -2,24 +2,26 @@
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
- import { createBrowserClient } from "@supabase/ssr";
6
5
  import { get_device_by_id } from "../helpers/devices";
7
6
  import { EnumWebResponse } from "../types/requests";
8
- export function useScoutDbListener() {
7
+ export function useScoutDbListener(supabaseClient) {
9
8
  const url = process.env.NEXT_PUBLIC_SUPABASE_URL || "";
10
9
  const anon_key = process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY || "";
11
10
  const supabase = useRef(null);
12
11
  const dispatch = useAppDispatch();
12
+ // Add instance tracking
13
+ const instanceId = useRef(Math.random().toString(36).substr(2, 9));
14
+ console.log(`[DB Listener] Hook initialized - Instance ID: ${instanceId.current}`);
13
15
  function handleTagInserts(payload) {
14
- console.log("[DB Listener] Tag INSERT received:", payload.new);
16
+ console.log(`[DB Listener] Tag INSERT received (Instance ${instanceId.current}):`, payload.new);
15
17
  dispatch(addTag(payload.new));
16
18
  }
17
19
  function handleTagDeletes(payload) {
18
- console.log("[DB Listener] Tag DELETE received:", payload.old);
20
+ console.log(`[DB Listener] Tag DELETE received (Instance ${instanceId.current}):`, payload.old);
19
21
  dispatch(deleteTag(payload.old));
20
22
  }
21
23
  function handleTagUpdates(payload) {
22
- console.log("[DB Listener] Tag UPDATE received:", payload.new);
24
+ console.log(`[DB Listener] Tag UPDATE received (Instance ${instanceId.current}):`, payload.new);
23
25
  dispatch(updateTag(payload.new));
24
26
  }
25
27
  async function handleDeviceInserts(payload) {
@@ -61,43 +63,43 @@ export function useScoutDbListener() {
61
63
  dispatch(updatePlan(payload.new));
62
64
  }
63
65
  useEffect(() => {
64
- const newSupabase = createBrowserClient(url, anon_key);
65
- newSupabase
66
+ console.log(`[DB Listener] Using provided Supabase client - Instance ${instanceId.current}`);
67
+ supabaseClient
66
68
  .channel("plans_insert")
67
69
  .on("postgres_changes", { event: "INSERT", schema: "public", table: "plans" }, handlePlanInserts)
68
70
  .subscribe();
69
- newSupabase
71
+ supabaseClient
70
72
  .channel("plans_delete")
71
73
  .on("postgres_changes", { event: "DELETE", schema: "public", table: "plans" }, handlePlanDeletes)
72
74
  .subscribe();
73
- newSupabase
75
+ supabaseClient
74
76
  .channel("plans_update")
75
77
  .on("postgres_changes", { event: "UPDATE", schema: "public", table: "plans" }, handlePlanUpdates)
76
78
  .subscribe();
77
- newSupabase
79
+ supabaseClient
78
80
  .channel("devices_delete")
79
81
  .on("postgres_changes", { event: "DELETE", schema: "public", table: "devices" }, handleDeviceDeletes)
80
82
  .subscribe();
81
- newSupabase
83
+ supabaseClient
82
84
  .channel("devices_insert")
83
85
  .on("postgres_changes", { event: "INSERT", schema: "public", table: "devices" }, handleDeviceInserts)
84
86
  .subscribe();
85
- newSupabase
87
+ supabaseClient
86
88
  .channel("devices_update")
87
89
  .on("postgres_changes", { event: "UPDATE", schema: "public", table: "devices" }, handleDeviceUpdates)
88
90
  .subscribe();
89
- newSupabase
91
+ supabaseClient
90
92
  .channel("tags_insert")
91
93
  .on("postgres_changes", { event: "INSERT", schema: "public", table: "tags" }, handleTagInserts)
92
94
  .subscribe();
93
- newSupabase
95
+ supabaseClient
94
96
  .channel("tags_delete")
95
97
  .on("postgres_changes", { event: "DELETE", schema: "public", table: "tags" }, handleTagDeletes)
96
98
  .subscribe();
97
- newSupabase
99
+ supabaseClient
98
100
  .channel("tags_update")
99
101
  .on("postgres_changes", { event: "UPDATE", schema: "public", table: "tags" }, handleTagUpdates)
100
102
  .subscribe();
101
- supabase.current = newSupabase;
102
- }, []);
103
+ supabase.current = supabaseClient;
104
+ }, [supabaseClient]);
103
105
  }
@@ -1 +1,648 @@
1
- export declare function ScoutRefreshProvider(): null;
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
- export function ScoutRefreshProvider() {
5
- useScoutDbListener();
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 null; // This component doesn't render anything, it just provides the refresh functionality
28
+ return (_jsx(SupabaseContext.Provider, { value: supabaseRef.current, children: children }));
8
29
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adventurelabs/scout-core",
3
- "version": "1.0.21",
3
+ "version": "1.0.22",
4
4
  "description": "Core utilities and helpers for Adventure Labs Scout applications",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",