refactor: remove useBaseFetch for @modrinth/api-client (#5596)

* Reapply "fix: start swapping useBaseFetch usages to api-client"

This reverts commit f4f33db701.

* fix: bugs

* fix: analytics

* fix: lint
This commit is contained in:
Calum H.
2026-03-17 20:06:19 +00:00
committed by GitHub
parent 58c1e225c8
commit 87c86c7d0d
64 changed files with 2073 additions and 691 deletions
@@ -38,7 +38,13 @@
</div>
</template>
<script setup>
import { Badge, Breadcrumbs, useFormatDateTime, useFormatPrice } from '@modrinth/ui'
import {
Badge,
Breadcrumbs,
injectModrinthClient,
useFormatDateTime,
useFormatPrice,
} from '@modrinth/ui'
import { useQuery } from '@tanstack/vue-query'
import { products } from '~/generated/state.json'
@@ -47,6 +53,8 @@ definePageMeta({
middleware: 'auth',
})
const client = injectModrinthClient()
const formatPrice = useFormatPrice()
const formatDate = useFormatDateTime({
year: 'numeric',
@@ -57,7 +65,7 @@ const formatDate = useFormatDateTime({
const { data: charges } = useQuery({
queryKey: ['billing', 'payments'],
queryFn: async () => {
const charges = await useBaseFetch('billing/payments', { internal: true })
const charges = await client.labrinth.billing_internal.getPayments()
return charges
.filter((charge) => charge.status !== 'open' && charge.status !== 'cancelled')
.map((charge) => {
@@ -458,8 +458,7 @@
:country="country"
:publishable-key="config.public.stripePublishableKey"
:send-billing-request="
async (body) =>
await useBaseFetch('billing/payment', { internal: true, method: 'POST', body })
async (body) => await client.labrinth.billing_internal.initiatePayment(body)
"
:on-error="
(err) =>
@@ -613,6 +612,7 @@ import {
CopyCode,
defineMessages,
getPaymentMethodIcon,
injectModrinthClient,
injectNotificationManager,
OverflowMenu,
paymentMethodMessages,
@@ -626,13 +626,12 @@ import { calculateSavings, getCurrency } from '@modrinth/utils'
import { useQuery, useQueryClient } from '@tanstack/vue-query'
import { computed, ref } from 'vue'
import { useBaseFetch } from '@/composables/fetch.js'
import ModrinthServersIcon from '~/components/ui/servers/ModrinthServersIcon.vue'
import ServersUpgradeModalWrapper from '~/components/ui/servers/ServersUpgradeModalWrapper.vue'
import { useServersFetch } from '~/composables/servers/servers-fetch.ts'
import { products } from '~/generated/state.json'
const { addNotification, handleError } = injectNotificationManager()
const client = injectModrinthClient()
definePageMeta({
middleware: 'auth',
})
@@ -742,27 +741,27 @@ const queryClient = useQueryClient()
const { data: paymentMethods } = useQuery({
queryKey: ['billing', 'payment_methods'],
queryFn: () => useBaseFetch('billing/payment_methods', { internal: true }),
queryFn: () => client.labrinth.billing_internal.getPaymentMethods(),
})
const { data: charges } = useQuery({
queryKey: ['billing', 'payments'],
queryFn: () => useBaseFetch('billing/payments', { internal: true }),
queryFn: () => client.labrinth.billing_internal.getPayments(),
})
const { data: customer } = useQuery({
queryKey: ['billing', 'customer'],
queryFn: () => useBaseFetch('billing/customer', { internal: true }),
queryFn: () => client.labrinth.billing_internal.getCustomer(),
})
const { data: subscriptions } = useQuery({
queryKey: ['billing', 'subscriptions'],
queryFn: () => useBaseFetch('billing/subscriptions', { internal: true }),
queryFn: () => client.labrinth.billing_internal.getSubscriptions(),
})
const { data: productsData } = useQuery({
queryKey: ['billing', 'products'],
queryFn: () => useBaseFetch('billing/products', { internal: true }),
queryFn: () => client.labrinth.billing_internal.getProducts(),
})
const { data: serversData } = useQuery({
queryKey: ['servers'],
queryFn: () => useServersFetch('servers'),
queryFn: () => client.archon.servers_v0.list(),
})
const midasProduct = ref(products.find((x) => x.metadata?.type === 'midas'))
@@ -826,10 +825,7 @@ function addPaymentMethod() {
}
async function createSetupIntent() {
return await useBaseFetch('billing/payment_method', {
internal: true,
method: 'POST',
})
return await client.labrinth.billing_internal.addPaymentMethodFlow()
}
const removePaymentMethodIndex = ref()
@@ -844,12 +840,8 @@ async function switchMidasInterval(interval) {
changingInterval.value = true
startLoading()
try {
await useBaseFetch(`billing/subscription/${midasSubscription.value.id}`, {
internal: true,
method: 'PATCH',
body: {
interval,
},
await client.labrinth.billing_internal.editSubscription(midasSubscription.value.id, {
interval,
})
await refresh()
} catch (error) {
@@ -862,12 +854,8 @@ async function switchMidasInterval(interval) {
async function editPaymentMethod(index, primary) {
startLoading()
try {
await useBaseFetch(`billing/payment_method/${paymentMethods.value[index].id}`, {
internal: true,
method: 'PATCH',
data: {
primary,
},
await client.labrinth.billing_internal.editPaymentMethod(paymentMethods.value[index].id, {
primary,
})
await refresh()
} catch (err) {
@@ -883,10 +871,7 @@ async function editPaymentMethod(index, primary) {
async function removePaymentMethod(index) {
startLoading()
try {
await useBaseFetch(`billing/payment_method/${paymentMethods.value[index].id}`, {
internal: true,
method: 'DELETE',
})
await client.labrinth.billing_internal.removePaymentMethod(paymentMethods.value[index].id)
await refresh()
} catch (err) {
addNotification({
@@ -902,12 +887,8 @@ const cancelSubscriptionId = ref(null)
async function cancelSubscription(id, cancelled) {
startLoading()
try {
await useBaseFetch(`billing/subscription/${id}`, {
internal: true,
method: 'PATCH',
body: {
cancelled,
},
await client.labrinth.billing_internal.editSubscription(id, {
cancelled,
})
await refresh()
} catch (err) {
@@ -975,12 +956,8 @@ const showPyroUpgradeModal = (subscription) => {
const resubscribePyro = async (subscriptionId, wasSuspended) => {
try {
await useBaseFetch(`billing/subscription/${subscriptionId}`, {
internal: true,
method: 'PATCH',
body: {
cancelled: false,
},
await client.labrinth.billing_internal.editSubscription(subscriptionId, {
cancelled: false,
})
await refresh()
if (wasSuspended) {