From 87c86c7d0dad956ec74086e334d7c8ea78213793 Mon Sep 17 00:00:00 2001 From: "Calum H." Date: Tue, 17 Mar 2026 20:06:19 +0000 Subject: [PATCH] refactor: remove `useBaseFetch` for `@modrinth/api-client` (#5596) * Reapply "fix: start swapping useBaseFetch usages to api-client" This reverts commit f4f33db7019ea861addb2c66c204d736800b7b6c. * fix: bugs * fix: analytics * fix: lint --- CLAUDE.md | 3 +- .../src/components/ui/NotificationItem.vue | 4 +- .../src/components/ui/charts/ChartDisplay.vue | 9 +- .../components/ui/create/CreateLimitAlert.vue | 40 +- .../ui/dashboard/CreatorWithdrawModal.vue | 18 +- .../ui/dashboard/RevenueTransaction.vue | 27 +- .../src/components/ui/report/ReportView.vue | 17 +- .../src/components/ui/report/ReportsList.vue | 25 +- .../src/helpers/platform-notifications.ts | 93 ++--- apps/frontend/src/pages/[type]/[id].vue | 72 +--- .../src/pages/[type]/[id]/moderation.vue | 18 +- .../pages/[type]/[id]/settings/members.vue | 100 ++--- apps/frontend/src/pages/admin/affiliates.vue | 42 +- .../frontend/src/pages/admin/billing/[id].vue | 43 +- apps/frontend/src/pages/auth/authorize.vue | 44 +- .../src/pages/auth/reset-password.vue | 24 +- apps/frontend/src/pages/auth/sign-in.vue | 26 +- apps/frontend/src/pages/auth/sign-up.vue | 21 +- apps/frontend/src/pages/collection/[id].vue | 17 +- .../src/pages/dashboard/affiliate-links.vue | 43 +- .../src/pages/dashboard/analytics.vue | 4 +- .../src/pages/dashboard/collections.vue | 5 +- apps/frontend/src/pages/dashboard/index.vue | 11 +- .../src/pages/dashboard/notifications.vue | 12 +- .../src/pages/dashboard/organizations.vue | 8 +- .../src/pages/dashboard/revenue/index.vue | 49 +-- .../src/pages/dashboard/revenue/transfers.vue | 7 +- apps/frontend/src/pages/hosting/index.vue | 41 +- .../manage/[id]/options/properties.vue | 2 +- apps/frontend/src/pages/legal/cmp-info.vue | 10 +- .../src/pages/moderation/reports/[id].vue | 4 +- .../organization/[id]/settings/projects.vue | 52 ++- .../src/pages/settings/applications.vue | 42 +- .../src/pages/settings/authorizations.vue | 29 +- .../src/pages/settings/billing/charges.vue | 12 +- .../src/pages/settings/billing/index.vue | 61 +-- apps/frontend/src/pages/settings/pats.vue | 39 +- apps/frontend/src/pages/settings/sessions.vue | 15 +- .../src/providers/creator-withdraw.ts | 25 +- apps/frontend/src/utils/fetch-helpers.ts | 10 + .../src/modules/archon/servers/v0.ts | 19 +- .../src/modules/archon/servers/v1.ts | 1 + packages/api-client/src/modules/index.ts | 26 ++ .../modules/labrinth/affiliate/internal.ts | 72 ++++ .../src/modules/labrinth/auth/v2.ts | 87 ++++ .../src/modules/labrinth/globals/internal.ts | 22 + .../api-client/src/modules/labrinth/index.ts | 9 + .../src/modules/labrinth/limits/v3.ts | 41 ++ .../src/modules/labrinth/notifications/v2.ts | 128 ++++++ .../src/modules/labrinth/oauth/internal.ts | 208 ++++++++++ .../src/modules/labrinth/organizations/v3.ts | 70 ++++ .../src/modules/labrinth/pats/v2.ts | 66 +++ .../src/modules/labrinth/payout/v3.ts | 41 ++ .../src/modules/labrinth/payouts/v3.ts | 26 ++ .../src/modules/labrinth/projects/v2.ts | 27 ++ .../src/modules/labrinth/reports/v3.ts | 141 +++++++ .../src/modules/labrinth/sessions/v2.ts | 34 ++ .../src/modules/labrinth/tags/v2.ts | 29 ++ .../src/modules/labrinth/teams/v2.ts | 101 +++++ .../src/modules/labrinth/teams/v3.ts | 31 ++ .../src/modules/labrinth/threads/v3.ts | 22 + .../api-client/src/modules/labrinth/types.ts | 388 ++++++++++++++++++ .../src/modules/labrinth/users/v2.ts | 43 ++ .../affiliate/AffiliateLinkCard.vue | 8 +- 64 files changed, 2073 insertions(+), 691 deletions(-) create mode 100644 packages/api-client/src/modules/labrinth/affiliate/internal.ts create mode 100644 packages/api-client/src/modules/labrinth/auth/v2.ts create mode 100644 packages/api-client/src/modules/labrinth/globals/internal.ts create mode 100644 packages/api-client/src/modules/labrinth/limits/v3.ts create mode 100644 packages/api-client/src/modules/labrinth/notifications/v2.ts create mode 100644 packages/api-client/src/modules/labrinth/oauth/internal.ts create mode 100644 packages/api-client/src/modules/labrinth/pats/v2.ts create mode 100644 packages/api-client/src/modules/labrinth/payouts/v3.ts create mode 100644 packages/api-client/src/modules/labrinth/reports/v3.ts create mode 100644 packages/api-client/src/modules/labrinth/sessions/v2.ts create mode 100644 packages/api-client/src/modules/labrinth/tags/v2.ts create mode 100644 packages/api-client/src/modules/labrinth/teams/v2.ts create mode 100644 packages/api-client/src/modules/labrinth/teams/v3.ts diff --git a/CLAUDE.md b/CLAUDE.md index fe48257fe..4f94b3ce8 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -30,7 +30,7 @@ This is the Modrinth monorepo — it contains all Modrinth projects, both fronte | `api-client` | API client for Nuxt, Tauri, and Node/browser | | `app-lib` | Shared app library | | `blog` | Blog system and changelog data | -| `utils` | Shared utility functions | +| `utils` | Shared utility functions (mostly deprecated) | | `moderation` | Moderation utilities | | `daedalus` | Daedalus protocol | | `tooling-config` | ESLint, Prettier, TypeScript configs | @@ -85,6 +85,7 @@ Each project may have its own `CLAUDE.md` with detailed instructions: ### General - Do not create new non-source code files (e.g. Bash scripts, SQL scripts) unless explicitly prompted to - For Frontend, when doing lint checks, only use the `prepr` commands, do not use `typecheck` or `tsc` etc. +- Types in `@modrinth/utils` are considered highly outdated, if a component needs them, check if you can switch said component to use types from `packages/api-client` ## Edit Tool - Whitespace Handling (CLAUDE ONLY) diff --git a/apps/frontend/src/components/ui/NotificationItem.vue b/apps/frontend/src/components/ui/NotificationItem.vue index c56f32978..bf6fac681 100644 --- a/apps/frontend/src/components/ui/NotificationItem.vue +++ b/apps/frontend/src/components/ui/NotificationItem.vue @@ -328,6 +328,7 @@ import { Categories, CopyCode, DoubleIcon, + injectModrinthClient, injectNotificationManager, ProjectStatusBadge, useFormatDateTime, @@ -341,6 +342,7 @@ import { acceptTeamInvite, removeSelfFromTeam } from '~/helpers/teams' import ThreadSummary from './thread/ThreadSummary.vue' +const client = injectModrinthClient() const { addNotification } = injectNotificationManager() const emit = defineEmits(['update:notifications']) const formatRelativeTime = useRelativeTime() @@ -407,7 +409,7 @@ async function read() { ? props.notification.grouped_notifs.map((notif) => notif.id) : []), ] - const updateNotifs = await markAsRead(ids) + const updateNotifs = await markAsRead(client, ids) const newNotifs = updateNotifs(props.notifications) emit('update:notifications', newNotifs) } catch (err) { diff --git a/apps/frontend/src/components/ui/charts/ChartDisplay.vue b/apps/frontend/src/components/ui/charts/ChartDisplay.vue index 6966ea788..39564d4cb 100644 --- a/apps/frontend/src/components/ui/charts/ChartDisplay.vue +++ b/apps/frontend/src/components/ui/charts/ChartDisplay.vue @@ -357,7 +357,7 @@ const props = withDefaults( }, ) -const projects = ref(props.projects || []) +const projects = computed(() => props.projects || []) // const selectedChart = ref('downloads') const selectedChart = computed({ @@ -389,6 +389,13 @@ const tinyRevenueChart = ref() const selectedDisplayProjects = ref(props.projects || []) +watch( + () => props.projects, + (newProjects) => { + selectedDisplayProjects.value = newProjects || [] + }, +) + const removeProjectFromDisplay = (id: string) => { selectedDisplayProjects.value = selectedDisplayProjects.value.filter((p) => p.id !== id) } diff --git a/apps/frontend/src/components/ui/create/CreateLimitAlert.vue b/apps/frontend/src/components/ui/create/CreateLimitAlert.vue index 8dbc29676..1c628574f 100644 --- a/apps/frontend/src/components/ui/create/CreateLimitAlert.vue +++ b/apps/frontend/src/components/ui/create/CreateLimitAlert.vue @@ -42,13 +42,18 @@ diff --git a/apps/frontend/src/pages/dashboard/collections.vue b/apps/frontend/src/pages/dashboard/collections.vue index 737c016db..87ee588bc 100644 --- a/apps/frontend/src/pages/dashboard/collections.vue +++ b/apps/frontend/src/pages/dashboard/collections.vue @@ -155,6 +155,7 @@ import { commonMessages, defineMessages, DropdownSelect, + injectModrinthClient, StyledInput, useCompactNumber, useVIntl, @@ -162,7 +163,6 @@ import { import { useQuery } from '@tanstack/vue-query' import CollectionCreateModal from '~/components/ui/create/CollectionCreateModal.vue' -import { useBaseFetch } from '~/composables/fetch.js' const { formatMessage } = useVIntl() const { formatCompactNumber, formatCompactNumberPlural } = useCompactNumber() @@ -216,6 +216,7 @@ useHead({ const auth = await useAuth() const user = await useUser() +const client = injectModrinthClient() if (import.meta.client) { await initUserFollows() @@ -225,7 +226,7 @@ const filterQuery = ref('') const { data: collections } = useQuery({ queryKey: ['user', auth.value.user.id, 'collections'], - queryFn: () => useBaseFetch(`user/${auth.value.user.id}/collections`, { apiVersion: 3 }), + queryFn: () => client.labrinth.users_v2.getCollections(auth.value.user.id), }) const route = useNativeRoute() diff --git a/apps/frontend/src/pages/dashboard/index.vue b/apps/frontend/src/pages/dashboard/index.vue index 68b3d2714..5c1a818e6 100644 --- a/apps/frontend/src/pages/dashboard/index.vue +++ b/apps/frontend/src/pages/dashboard/index.vue @@ -97,7 +97,7 @@