@adventurelabs/scout-core 1.2.5 → 1.2.6

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.
@@ -5,7 +5,9 @@ import { SupabaseClient } from "@supabase/supabase-js";
5
5
  export declare function get_pins_for_herd(client: SupabaseClient<Database>, herd_id: number): Promise<IWebResponseCompatible<IPin[]>>;
6
6
  export declare function get_pin_by_id(client: SupabaseClient<Database>, pin_id: number): Promise<IWebResponseCompatible<IPin | null>>;
7
7
  export declare function create_pin(client: SupabaseClient<Database>, newPin: PinInsert): Promise<IWebResponseCompatible<IPin | null>>;
8
+ export declare function create_pin_with_coordinates(client: SupabaseClient<Database>, latitude: number, longitude: number, pinData: Omit<PinInsert, "location">): Promise<IWebResponseCompatible<IPin | null>>;
8
9
  export declare function update_pin(client: SupabaseClient<Database>, pin_id: number, updatedPin: Partial<PinInsert>): Promise<IWebResponseCompatible<IPin | null>>;
10
+ export declare function update_pin_location(client: SupabaseClient<Database>, pin_id: number, latitude: number, longitude: number, updatedPin?: Partial<Omit<PinInsert, "location">>): Promise<IWebResponseCompatible<IPin | null>>;
9
11
  export declare function delete_pin(client: SupabaseClient<Database>, pin_id: number): Promise<IWebResponseCompatible<IPin | null>>;
10
12
  export declare function get_pins_by_created_by(client: SupabaseClient<Database>, user_id: string): Promise<IWebResponseCompatible<IPin[]>>;
11
13
  export declare function get_pins_by_color(client: SupabaseClient<Database>, herd_id: number, color: string): Promise<IWebResponseCompatible<IPin[]>>;
@@ -1,6 +1,6 @@
1
1
  import { IWebResponse } from "../types/requests";
2
2
  export async function get_pins_for_herd(client, herd_id) {
3
- // Call get_pins_for_herd with rpc
3
+ // Call get_pins_for_herd with rpc - returns pins_pretty_location with extracted coordinates
4
4
  const { data, error } = await client.rpc("get_pins_for_herd", {
5
5
  herd_id_caller: herd_id,
6
6
  });
@@ -24,13 +24,8 @@ export async function get_pin_by_id(client, pin_id) {
24
24
  if (!data) {
25
25
  return IWebResponse.error("Pin not found").to_compatible();
26
26
  }
27
- // Convert to pretty location format with coordinates
28
- const pinWithCoords = {
29
- ...data,
30
- latitude: data.latitude ? parseFloat(data.latitude.toString()) : 0,
31
- longitude: data.longitude ? parseFloat(data.longitude.toString()) : 0,
32
- };
33
- return IWebResponse.success(pinWithCoords).to_compatible();
27
+ // Raw table data - no coordinate extraction (use get_pins_for_herd for coordinates)
28
+ return IWebResponse.success(data).to_compatible();
34
29
  }
35
30
  export async function create_pin(client, newPin) {
36
31
  const { data, error } = await client
@@ -44,13 +39,30 @@ export async function create_pin(client, newPin) {
44
39
  if (!data) {
45
40
  return IWebResponse.error("Failed to create pin").to_compatible();
46
41
  }
47
- // Convert to pretty location format with coordinates
48
- const pinWithCoords = {
49
- ...data,
50
- latitude: data.latitude ? parseFloat(data.latitude.toString()) : 0,
51
- longitude: data.longitude ? parseFloat(data.longitude.toString()) : 0,
52
- };
53
- return IWebResponse.success(pinWithCoords).to_compatible();
42
+ // Raw table data - coordinates extracted by RPC function or realtime broadcasts
43
+ return IWebResponse.success(data).to_compatible();
44
+ }
45
+ export async function create_pin_with_coordinates(client, latitude, longitude, pinData) {
46
+ // Create pin with PostGIS Point from lat/lng coordinates
47
+ const { data, error } = await client
48
+ .from("pins")
49
+ .insert([
50
+ {
51
+ ...pinData,
52
+ // Use PostGIS ST_MakePoint to create geography from coordinates
53
+ // Note: PostGIS Point format is (longitude, latitude)
54
+ location: `SRID=4326;POINT(${longitude} ${latitude})`,
55
+ },
56
+ ])
57
+ .select("*")
58
+ .single();
59
+ if (error) {
60
+ return IWebResponse.error(error.message).to_compatible();
61
+ }
62
+ if (!data) {
63
+ return IWebResponse.error("Failed to create pin").to_compatible();
64
+ }
65
+ return IWebResponse.success(data).to_compatible();
54
66
  }
55
67
  export async function update_pin(client, pin_id, updatedPin) {
56
68
  // Remove fields that shouldn't be updated
@@ -70,13 +82,32 @@ export async function update_pin(client, pin_id, updatedPin) {
70
82
  if (!data) {
71
83
  return IWebResponse.error("Pin not found or update failed").to_compatible();
72
84
  }
73
- // Convert to pretty location format with coordinates
74
- const pinWithCoords = {
75
- ...data,
76
- latitude: data.latitude ? parseFloat(data.latitude.toString()) : 0,
77
- longitude: data.longitude ? parseFloat(data.longitude.toString()) : 0,
85
+ // Raw table data - coordinates extracted by RPC function or realtime broadcasts
86
+ return IWebResponse.success(data).to_compatible();
87
+ }
88
+ export async function update_pin_location(client, pin_id, latitude, longitude, updatedPin) {
89
+ const updateData = {
90
+ ...updatedPin,
91
+ // Use PostGIS format to update location
92
+ location: `SRID=4326;POINT(${longitude} ${latitude})`,
78
93
  };
79
- return IWebResponse.success(pinWithCoords).to_compatible();
94
+ // Remove fields that shouldn't be updated
95
+ delete updateData.id;
96
+ delete updateData.created_at;
97
+ delete updateData.created_by;
98
+ const { data, error } = await client
99
+ .from("pins")
100
+ .update(updateData)
101
+ .eq("id", pin_id)
102
+ .select("*")
103
+ .single();
104
+ if (error) {
105
+ return IWebResponse.error(error.message).to_compatible();
106
+ }
107
+ if (!data) {
108
+ return IWebResponse.error("Pin not found or update failed").to_compatible();
109
+ }
110
+ return IWebResponse.success(data).to_compatible();
80
111
  }
81
112
  export async function delete_pin(client, pin_id) {
82
113
  const { data, error } = await client
@@ -91,13 +122,8 @@ export async function delete_pin(client, pin_id) {
91
122
  if (!data) {
92
123
  return IWebResponse.error("Pin not found or deletion failed").to_compatible();
93
124
  }
94
- // Convert to pretty location format with coordinates
95
- const pinWithCoords = {
96
- ...data,
97
- latitude: data.latitude ? parseFloat(data.latitude.toString()) : 0,
98
- longitude: data.longitude ? parseFloat(data.longitude.toString()) : 0,
99
- };
100
- return IWebResponse.success(pinWithCoords).to_compatible();
125
+ // Raw table data - coordinates extracted by realtime broadcasts
126
+ return IWebResponse.success(data).to_compatible();
101
127
  }
102
128
  export async function get_pins_by_created_by(client, user_id) {
103
129
  const { data, error } = await client
@@ -111,13 +137,8 @@ export async function get_pins_by_created_by(client, user_id) {
111
137
  if (!data) {
112
138
  return IWebResponse.error("No pins found for user").to_compatible();
113
139
  }
114
- // Convert to pretty location format with coordinates
115
- const pinsWithCoords = data.map((pin) => ({
116
- ...pin,
117
- latitude: pin.latitude ? parseFloat(pin.latitude.toString()) : 0,
118
- longitude: pin.longitude ? parseFloat(pin.longitude.toString()) : 0,
119
- }));
120
- return IWebResponse.success(pinsWithCoords).to_compatible();
140
+ // Raw table data without extracted coordinates - use get_pins_for_herd for coordinates
141
+ return IWebResponse.success(data).to_compatible();
121
142
  }
122
143
  export async function get_pins_by_color(client, herd_id, color) {
123
144
  const { data, error } = await client
@@ -132,11 +153,6 @@ export async function get_pins_by_color(client, herd_id, color) {
132
153
  if (!data) {
133
154
  return IWebResponse.error(`No pins found with color: ${color}`).to_compatible();
134
155
  }
135
- // Convert to pretty location format with coordinates
136
- const pinsWithCoords = data.map((pin) => ({
137
- ...pin,
138
- latitude: pin.latitude ? parseFloat(pin.latitude.toString()) : 0,
139
- longitude: pin.longitude ? parseFloat(pin.longitude.toString()) : 0,
140
- }));
141
- return IWebResponse.success(pinsWithCoords).to_compatible();
156
+ // Raw table data without extracted coordinates - use get_pins_for_herd for coordinates
157
+ return IWebResponse.success(data).to_compatible();
142
158
  }
@@ -556,8 +556,7 @@ export declare function useSupabase(): SupabaseClient<Database, "public", "publi
556
556
  description: string | null;
557
557
  herd_id: number;
558
558
  id: number;
559
- latitude: unknown;
560
- longitude: unknown;
559
+ location: unknown;
561
560
  name: string;
562
561
  };
563
562
  Insert: {
@@ -568,8 +567,7 @@ export declare function useSupabase(): SupabaseClient<Database, "public", "publi
568
567
  description?: string | null;
569
568
  herd_id: number;
570
569
  id?: number;
571
- latitude: unknown;
572
- longitude: unknown;
570
+ location?: unknown;
573
571
  name: string;
574
572
  };
575
573
  Update: {
@@ -580,8 +578,7 @@ export declare function useSupabase(): SupabaseClient<Database, "public", "publi
580
578
  description?: string | null;
581
579
  herd_id?: number;
582
580
  id?: number;
583
- latitude?: unknown;
584
- longitude?: unknown;
581
+ location?: unknown;
585
582
  name?: string;
586
583
  };
587
584
  Relationships: [{
@@ -1550,6 +1547,7 @@ export declare function useSupabase(): SupabaseClient<Database, "public", "publi
1550
1547
  pins_pretty_location: {
1551
1548
  id: number | null;
1552
1549
  created_at: string | null;
1550
+ location: unknown;
1553
1551
  altitude_relative_to_ground: number | null;
1554
1552
  color: string | null;
1555
1553
  name: string | null;
@@ -583,8 +583,7 @@ export type Database = {
583
583
  description: string | null;
584
584
  herd_id: number;
585
585
  id: number;
586
- latitude: unknown;
587
- longitude: unknown;
586
+ location: unknown;
588
587
  name: string;
589
588
  };
590
589
  Insert: {
@@ -595,8 +594,7 @@ export type Database = {
595
594
  description?: string | null;
596
595
  herd_id: number;
597
596
  id?: number;
598
- latitude: unknown;
599
- longitude: unknown;
597
+ location?: unknown;
600
598
  name: string;
601
599
  };
602
600
  Update: {
@@ -607,8 +605,7 @@ export type Database = {
607
605
  description?: string | null;
608
606
  herd_id?: number;
609
607
  id?: number;
610
- latitude?: unknown;
611
- longitude?: unknown;
608
+ location?: unknown;
612
609
  name?: string;
613
610
  };
614
611
  Relationships: [
@@ -1605,6 +1602,7 @@ export type Database = {
1605
1602
  pins_pretty_location: {
1606
1603
  id: number | null;
1607
1604
  created_at: string | null;
1605
+ location: unknown;
1608
1606
  altitude_relative_to_ground: number | null;
1609
1607
  color: string | null;
1610
1608
  name: string | null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adventurelabs/scout-core",
3
- "version": "1.2.5",
3
+ "version": "1.2.6",
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",