@adventurelabs/scout-core 1.0.17 → 1.0.19

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.
@@ -164,25 +164,68 @@ export async function get_event_and_tags_by_event_id(event_id) {
164
164
  data: null,
165
165
  };
166
166
  }
167
- if (!data[0]) {
167
+ if (!data || data.length === 0) {
168
168
  return {
169
169
  status: EnumWebResponse.ERROR,
170
170
  msg: "Event not found",
171
171
  data: null,
172
172
  };
173
173
  }
174
- // Transform location to latitude/longitude
174
+ // Debug the raw event data from database
175
+ console.log("Raw event data from DB:", {
176
+ eventId: data[0].id,
177
+ mediaUrl: data[0].media_url,
178
+ filePath: data[0].file_path,
179
+ message: data[0].message,
180
+ deviceId: data[0].device_id,
181
+ location: data[0].location,
182
+ locationType: typeof data[0].location,
183
+ hasCoordinates: data[0].location &&
184
+ typeof data[0].location === "object" &&
185
+ "coordinates" in data[0].location,
186
+ });
187
+ // Transform location to latitude/longitude with better error handling
188
+ let latitude = null;
189
+ let longitude = null;
190
+ try {
191
+ if (data[0].location) {
192
+ if (typeof data[0].location === "object" && data[0].location !== null) {
193
+ // Handle PostGIS Point format: { coordinates: [lon, lat] }
194
+ if ("coordinates" in data[0].location &&
195
+ Array.isArray(data[0].location.coordinates)) {
196
+ longitude = data[0].location.coordinates[0];
197
+ latitude = data[0].location.coordinates[1];
198
+ }
199
+ // Handle alternative format: { x: lon, y: lat }
200
+ else if ("x" in data[0].location && "y" in data[0].location) {
201
+ longitude = data[0].location.x;
202
+ latitude = data[0].location.y;
203
+ }
204
+ }
205
+ // Handle string format: "Point(lon lat)"
206
+ else if (typeof data[0].location === "string") {
207
+ const match = data[0].location.match(/Point\(([^)]+)\)/);
208
+ if (match) {
209
+ const coords = match[1].split(" ").map(Number);
210
+ if (coords.length === 2) {
211
+ longitude = coords[0];
212
+ latitude = coords[1];
213
+ }
214
+ }
215
+ }
216
+ }
217
+ }
218
+ catch (locationError) {
219
+ console.warn("Error parsing location data:", locationError);
220
+ // Continue with null coordinates
221
+ }
175
222
  const transformedData = {
176
223
  id: data[0].id,
177
224
  inserted_at: data[0].inserted_at,
178
225
  message: data[0].message,
179
226
  media_url: data[0].media_url,
180
- latitude: data[0].location
181
- ? data[0].location.coordinates[1]
182
- : null,
183
- longitude: data[0].location
184
- ? data[0].location.coordinates[0]
185
- : null,
227
+ latitude: latitude,
228
+ longitude: longitude,
186
229
  altitude: data[0].altitude,
187
230
  heading: data[0].heading,
188
231
  media_type: data[0].media_type,
@@ -191,8 +234,22 @@ export async function get_event_and_tags_by_event_id(event_id) {
191
234
  is_public: data[0].is_public,
192
235
  tags: data[0].tags || [],
193
236
  earthranger_url: data[0].earthranger_url,
237
+ file_path: data[0].file_path,
194
238
  };
239
+ // Debug before signed URL generation
240
+ console.log("Before signed URL generation:", {
241
+ eventId: transformedData.id,
242
+ mediaUrl: transformedData.media_url,
243
+ filePath: transformedData.file_path,
244
+ hasFilePath: !!transformedData.file_path,
245
+ });
195
246
  // Add signed URL to event using the same client
196
247
  const eventWithSignedUrl = await addSignedUrlToEvent(transformedData, supabase);
248
+ // Debug after signed URL generation
249
+ console.log("After signed URL generation:", {
250
+ eventId: eventWithSignedUrl.id,
251
+ mediaUrl: eventWithSignedUrl.media_url,
252
+ filePath: eventWithSignedUrl.file_path,
253
+ });
197
254
  return IWebResponse.success(eventWithSignedUrl).to_compatible();
198
255
  }
@@ -18,6 +18,7 @@ export type IUserRolePerHerd = Database["public"]["Tables"]["users_roles_per_her
18
18
  export type IHerd = Database["public"]["Tables"]["herds"]["Row"];
19
19
  export type IEventWithTags = Database["public"]["CompositeTypes"]["event_with_tags"] & {
20
20
  earthranger_url: string | null;
21
+ file_path: string | null;
21
22
  };
22
23
  export type IDevicePrettyLocation = Database["public"]["CompositeTypes"]["device_pretty_location"];
23
24
  export type IEventAndTagsPrettyLocation = Database["public"]["CompositeTypes"]["event_and_tags_pretty_location"];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adventurelabs/scout-core",
3
- "version": "1.0.17",
3
+ "version": "1.0.19",
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",