Files
supabase/apps/studio/lib/common/fetch/post.ts
Joshen Lim e539b892a6 Chore/more refactoring of data fetchers methods (#33553)
* Update postgres-service-status-query, password-strength, and free-project-limit-check-query

* Update exit-survey-send

* Update project-postgrest-config-query

* Update project-disk-resize-mutation

* Update project-update-mutation

* Update project-postgrest-config-update-mutation

* Update organization-audit-logs-query

* Fix types

* Update bucket-object-download-mutation

* Update organization-member-delete-invitation

* remove console log

* Add integer validation for disk size (enforced on the API, but lacking client side validation)

* Fix audit logs
2025-02-13 13:34:12 +08:00

33 lines
1.1 KiB
TypeScript

import { uuidv4 } from 'lib/helpers'
import type { SupaResponse } from 'types/base'
import { constructHeaders, handleError, handleResponse, handleResponseError } from './base'
/**
* @deprecated Please use post method from data/fetchers instead
*
* Exception for bucket-object-download-mutation as openapi-fetch doesn't support octet-stream responses
*/
export async function post<T = any>(
url: string,
data: { [prop: string]: any },
options?: { [prop: string]: any }
): Promise<SupaResponse<T>> {
const requestId = uuidv4()
try {
const { headers: optionHeaders, abortSignal, ...otherOptions } = options ?? {}
const headers = await constructHeaders(requestId, optionHeaders)
const response = await fetch(url, {
method: 'POST',
body: JSON.stringify(data),
referrerPolicy: 'no-referrer-when-downgrade',
headers,
...otherOptions,
signal: abortSignal,
})
if (!response.ok) return handleResponseError(response, requestId)
return handleResponse(response, requestId)
} catch (error) {
return handleError(error, requestId)
}
}