@adventurelabs/scout-core 1.0.124 → 1.0.126

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,8 +2,8 @@
2
2
  import { newServerClient } from "../supabase/server";
3
3
  import { IWebResponse } from "../types/requests";
4
4
  export async function get_devices_by_herd(herd_id, client) {
5
- // call get_devices_with_components_for_herd with rpc
6
- const { data, error } = await client.rpc("get_devices_with_components_for_herd", {
5
+ // call get_devices_for_herd with rpc
6
+ const { data, error } = await client.rpc("get_devices_for_herd", {
7
7
  herd_id_caller: herd_id,
8
8
  });
9
9
  if (!data) {
@@ -1,6 +1,20 @@
1
1
  "use server";
2
2
  import { newServerClient } from "../supabase/server";
3
3
  import { BUCKET_NAME_SCOUT, SIGNED_URL_EXPIRATION_SECONDS, } from "../constants/db";
4
+ /**
5
+ * Splits file path into bucket name and path. Must be at leaast one slash in your file path
6
+ * @param filePath
7
+ * @returns IFilePathParts | null - null if invalid file path
8
+ */
9
+ function getPartsFromFilePath(filePath) {
10
+ const parts = filePath.split("/");
11
+ if (parts.length < 2) {
12
+ return null;
13
+ }
14
+ const bucket_name = parts[0];
15
+ const path = parts.slice(1).join("/");
16
+ return { bucket_name, path };
17
+ }
4
18
  /**
5
19
  * Generates a signed URL for a file in Supabase storage
6
20
  * @param filePath - The path to the file in storage (e.g., "events/123/image.jpg")
@@ -11,9 +25,14 @@ import { BUCKET_NAME_SCOUT, SIGNED_URL_EXPIRATION_SECONDS, } from "../constants/
11
25
  export async function generateSignedUrl(filePath, expiresIn = SIGNED_URL_EXPIRATION_SECONDS, supabaseClient) {
12
26
  try {
13
27
  const supabase = supabaseClient || (await newServerClient());
28
+ const parts = getPartsFromFilePath(filePath);
29
+ if (!parts) {
30
+ console.error("Invalid file path:", filePath);
31
+ return null;
32
+ }
14
33
  const { data, error } = await supabase.storage
15
- .from(BUCKET_NAME_SCOUT)
16
- .createSignedUrl(filePath, expiresIn);
34
+ .from(parts.bucket_name)
35
+ .createSignedUrl(parts.path, expiresIn);
17
36
  if (error) {
18
37
  console.error("Error generating signed URL:", error.message);
19
38
  return null;
@@ -40,7 +59,7 @@ export async function generateSignedUrlsBatch(filePaths, expiresIn = SIGNED_URL_
40
59
  return data.signedUrl;
41
60
  }
42
61
  catch (error) {
43
- console.error(`Exception generating signed URL for ${filePath}:`, error);
62
+ console.warn(`Exception generating signed URL for ${filePath}:`, error);
44
63
  return null;
45
64
  }
46
65
  });
@@ -6,9 +6,8 @@ export type DeviceType = Database["public"]["Enums"]["device_type"];
6
6
  export type MediaType = Database["public"]["Enums"]["media_type"];
7
7
  export type TagObservationType = Database["public"]["Enums"]["tag_observation_type"];
8
8
  export type IUser = User;
9
- export type IDevice = Database["public"]["CompositeTypes"]["device_with_components"] & {
9
+ export type IDevice = Database["public"]["CompositeTypes"]["device_pretty_location"] & {
10
10
  api_keys_scout?: IApiKeyScout[];
11
- recent_events?: IEventAndTagsPrettyLocation[];
12
11
  };
13
12
  export type IEvent = Database["public"]["Tables"]["events"]["Row"];
14
13
  export type ITag = Database["public"]["Tables"]["tags"]["Row"];
@@ -30,31 +29,6 @@ export type IArtifact = Database["public"]["Tables"]["artifacts"]["Row"];
30
29
  export type IArtifactWithMediaUrl = IArtifact & {
31
30
  media_url?: string | null;
32
31
  };
33
- export type IComponentInfo = {
34
- id: number;
35
- serial_number: string;
36
- product_number: string | null;
37
- certificate_id: number | null;
38
- status: Database["public"]["Enums"]["component_status"];
39
- created_at: string;
40
- updated_at: string | null;
41
- };
42
- export type IDeviceWithComponents = {
43
- id: number;
44
- inserted_at: string;
45
- created_by: string | null;
46
- herd_id: number;
47
- device_type: Database["public"]["Enums"]["device_type"];
48
- domain_name: string | null;
49
- location: string | null;
50
- altitude: number | null;
51
- heading: number | null;
52
- name: string | null;
53
- description: string | null;
54
- latitude: number | null;
55
- longitude: number | null;
56
- components: IComponentInfo[];
57
- };
58
32
  export type ComponentInsert = Database["public"]["Tables"]["components"]["Insert"];
59
33
  export type VersionsSoftwareInsert = Database["public"]["Tables"]["versions_software"]["Insert"];
60
34
  export type ArtifactInsert = Database["public"]["Tables"]["artifacts"]["Insert"];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adventurelabs/scout-core",
3
- "version": "1.0.124",
3
+ "version": "1.0.126",
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",