@adventurelabs/scout-core 1.0.125 → 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.
@@ -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
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adventurelabs/scout-core",
3
- "version": "1.0.125",
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",