Files
supabase/e2e/studio/utils/storage/client.ts
Ali Waseem c7f653f33f chore: move api solution to storage and parallelize tests (#42565)
## I have read the
[CONTRIBUTING.md](https://github.com/supabase/supabase/blob/master/CONTRIBUTING.md)
file.

YES

## What kind of change does this PR introduce?

- Move storage tests to run in parallel
- Updated utils to use env

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

* **Tests**
* Improved test reliability by shifting storage bucket setup and cleanup
from UI-based to API-backed operations.
* Enhanced test isolation with streamlined prerequisite navigation
steps.

* **Chores**
* Updated environment configuration to support dynamic API URL and
service role key settings.
* Refactored internal storage management utilities for improved
maintainability.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-02-06 10:50:41 -07:00

40 lines
1.1 KiB
TypeScript

import { env } from "../../env.config.js";
/**
* Make an HTTP request to the local Supabase Storage API.
*
* @param path - The path to append to the storage base URL (e.g., '/bucket')
* @param options - Optional method and body
* @returns Parsed JSON response
* @throws Error if the request fails
*/
export async function storageRequest<T>(
path: string,
options?: { method?: 'GET' | 'POST' | 'PUT' | 'DELETE'; body?: Record<string, unknown> }
): Promise<T> {
const storageUrl = `${env.API_URL}/storage/v1`
const headers: Record<string, string> = {
apikey: env.SERVICE_ROLE_KEY,
Authorization: `Bearer ${env.SERVICE_ROLE_KEY}`,
}
if (options?.body) {
headers['Content-Type'] = 'application/json'
}
const response = await fetch(`${storageUrl}${path}`, {
method: options?.method ?? 'GET',
headers,
body: options?.body ? JSON.stringify(options.body) : undefined,
})
if (!response.ok) {
const text = await response.text()
throw new Error(`Storage request failed (${response.status}): ${text}`)
}
const text = await response.text()
return text ? JSON.parse(text) : ({} as T)
}