You've already forked AstralRinth
forked from didirus/AstralRinth
feat: base api-client impl (#4694)
* feat: base api-client impl * fix: doc * feat: start work on module stuff * feat: migrate v2/v3 projects into module system * fix: lint & README.md contributing * refactor: remove utils old api client prototype * fix: lint * fix: api url issues * fix: baseurl in error.vue * fix: readme * fix typo in readme * Update apps/frontend/src/providers/api-client.ts Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: Calum H. <hendersoncal117@gmail.com> * Update packages/api-client/src/features/verbose-logging.ts Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: Calum H. <hendersoncal117@gmail.com> * Update packages/api-client/src/features/retry.ts Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: Calum H. <hendersoncal117@gmail.com> --------- Signed-off-by: Calum H. <hendersoncal117@gmail.com> Co-authored-by: Prospector <6166773+Prospector@users.noreply.github.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
42
apps/frontend/src/providers/api-client.ts
Normal file
42
apps/frontend/src/providers/api-client.ts
Normal file
@@ -0,0 +1,42 @@
|
||||
import type { AbstractFeature, AuthConfig, NuxtClientConfig } from '@modrinth/api-client'
|
||||
import {
|
||||
AuthFeature,
|
||||
CircuitBreakerFeature,
|
||||
NuxtCircuitBreakerStorage,
|
||||
NuxtModrinthClient,
|
||||
VerboseLoggingFeature,
|
||||
} from '@modrinth/api-client'
|
||||
import { createContext } from '@modrinth/ui'
|
||||
|
||||
export function createModrinthClient(
|
||||
auth: { token: string | undefined },
|
||||
config: { apiBaseUrl: string; archonBaseUrl: string; rateLimitKey?: string },
|
||||
): NuxtModrinthClient {
|
||||
const optionalFeatures = [
|
||||
import.meta.dev ? (new VerboseLoggingFeature() as AbstractFeature) : undefined,
|
||||
].filter(Boolean) as AbstractFeature[]
|
||||
|
||||
const clientConfig: NuxtClientConfig = {
|
||||
labrinthBaseUrl: config.apiBaseUrl,
|
||||
archonBaseUrl: config.archonBaseUrl,
|
||||
rateLimitKey: config.rateLimitKey,
|
||||
features: [
|
||||
new AuthFeature({
|
||||
token: async () => auth.token,
|
||||
} as AuthConfig),
|
||||
new CircuitBreakerFeature({
|
||||
storage: new NuxtCircuitBreakerStorage(),
|
||||
maxFailures: 3,
|
||||
resetTimeout: 30000,
|
||||
}),
|
||||
...optionalFeatures,
|
||||
],
|
||||
}
|
||||
|
||||
return new NuxtModrinthClient(clientConfig)
|
||||
}
|
||||
|
||||
export const [injectModrinthClient, provideModrinthClient] = createContext<NuxtModrinthClient>(
|
||||
'root',
|
||||
'modrinthClient',
|
||||
)
|
||||
Reference in New Issue
Block a user