@adventurelabs/scout-core 1.0.126 → 1.0.128

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,19 +1,18 @@
1
1
  "use server";
2
2
  import { newServerClient } from "../supabase/server";
3
- import { BUCKET_NAME_SCOUT, SIGNED_URL_EXPIRATION_SECONDS, } from "../constants/db";
3
+ import { SIGNED_URL_EXPIRATION_SECONDS, } from "../constants/db";
4
4
  /**
5
5
  * Splits file path into bucket name and path. Must be at leaast one slash in your file path
6
6
  * @param filePath
7
7
  * @returns IFilePathParts | null - null if invalid file path
8
8
  */
9
- function getPartsFromFilePath(filePath) {
9
+ function getBucketFromFilePath(filePath) {
10
10
  const parts = filePath.split("/");
11
11
  if (parts.length < 2) {
12
12
  return null;
13
13
  }
14
14
  const bucket_name = parts[0];
15
- const path = parts.slice(1).join("/");
16
- return { bucket_name, path };
15
+ return bucket_name;
17
16
  }
18
17
  /**
19
18
  * Generates a signed URL for a file in Supabase storage
@@ -25,14 +24,14 @@ function getPartsFromFilePath(filePath) {
25
24
  export async function generateSignedUrl(filePath, expiresIn = SIGNED_URL_EXPIRATION_SECONDS, supabaseClient) {
26
25
  try {
27
26
  const supabase = supabaseClient || (await newServerClient());
28
- const parts = getPartsFromFilePath(filePath);
29
- if (!parts) {
27
+ const bucket_name = getBucketFromFilePath(filePath);
28
+ if (!bucket_name) {
30
29
  console.error("Invalid file path:", filePath);
31
30
  return null;
32
31
  }
33
32
  const { data, error } = await supabase.storage
34
- .from(parts.bucket_name)
35
- .createSignedUrl(parts.path, expiresIn);
33
+ .from(bucket_name)
34
+ .createSignedUrl(filePath, expiresIn);
36
35
  if (error) {
37
36
  console.error("Error generating signed URL:", error.message);
38
37
  return null;
@@ -49,11 +48,16 @@ export async function generateSignedUrlsBatch(filePaths, expiresIn = SIGNED_URL_
49
48
  const supabase = supabaseClient || (await newServerClient());
50
49
  const signedUrlPromises = filePaths.map(async (filePath) => {
51
50
  try {
51
+ const bucket_name = getBucketFromFilePath(filePath);
52
+ if (!bucket_name) {
53
+ console.error("Invalid file path:", filePath);
54
+ return null;
55
+ }
52
56
  const { data, error } = await supabase.storage
53
- .from(BUCKET_NAME_SCOUT)
57
+ .from(bucket_name)
54
58
  .createSignedUrl(filePath, expiresIn);
55
59
  if (error) {
56
- console.error(`Error generating signed URL for ${filePath}:`, error.message);
60
+ console.warn(`Error generating signed URL for ${filePath}:`, error.message);
57
61
  return null;
58
62
  }
59
63
  return data.signedUrl;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adventurelabs/scout-core",
3
- "version": "1.0.126",
3
+ "version": "1.0.128",
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",