Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions apps/frontend/src/composables/featureFlags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export const DEFAULT_FEATURE_FLAGS = validateValues({
showProjectPageQuickServerButton: false,
newProjectGeneralSettings: false,
newProjectEnvironmentSettings: true,
archonSentryCapture: false,
hideRussiaCensorshipBanner: false,
disablePrettyProjectUrlRedirects: false,
hidePreviewBanner: false,
Expand Down
4 changes: 4 additions & 0 deletions apps/frontend/src/helpers/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import {
} from '@modrinth/api-client'
import type { Ref } from 'vue'

import { useFeatureFlags } from '~/composables/featureFlags.ts'

async function getRateLimitKeyFromSecretsStore(): Promise<string | undefined> {
try {
const mod = 'cloudflare:workers'
Expand All @@ -28,13 +30,15 @@ export function createModrinthClient(
auth: Ref<{ token: string | undefined }>,
config: { apiBaseUrl: string; archonBaseUrl: string; rateLimitKey?: string },
): NuxtModrinthClient {
const flags = useFeatureFlags()
const optionalFeatures = [
import.meta.dev ? (new VerboseLoggingFeature() as AbstractFeature) : undefined,
].filter(Boolean) as AbstractFeature[]

const clientConfig: NuxtClientConfig = {
labrinthBaseUrl: config.apiBaseUrl,
archonBaseUrl: config.archonBaseUrl,
archonSentryCapture: () => flags.value.archonSentryCapture,
rateLimitKey: config.rateLimitKey || getRateLimitKeyFromSecretsStore,
features: [
// for modrinth hosting
Expand Down
16 changes: 16 additions & 0 deletions packages/api-client/src/core/abstract-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ export abstract class AbstractModrinthClient extends AbstractUploadClient {
...options.headers,
},
}
this.attachArchonSentryCaptureHeader(mergedOptions)

const headers = mergedOptions.headers
if (headers && 'Content-Type' in headers && headers['Content-Type'] === '') {
Expand Down Expand Up @@ -309,6 +310,21 @@ export abstract class AbstractModrinthClient extends AbstractUploadClient {
return headers
}

protected attachArchonSentryCaptureHeader(options: RequestOptions): void {
if (options.api !== 'archon' || !options.headers || !this.shouldCaptureArchonRequests()) {
return
}

options.headers['modrinth-sentry-capture'] = '1'
}

private shouldCaptureArchonRequests(): boolean {
const archonSentryCapture = this.config.archonSentryCapture
return typeof archonSentryCapture === 'function'
? archonSentryCapture()
: archonSentryCapture === true
}

/**
* Execute the actual HTTP request
*
Expand Down
1 change: 1 addition & 0 deletions packages/api-client/src/platform/xhr-upload-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export abstract class XHRUploadClient extends AbstractModrinthClient {
...options.headers,
},
}
this.attachArchonSentryCaptureHeader(mergedOptions)

const context = this.buildUploadContext(url, path, mergedOptions)

Expand Down
8 changes: 8 additions & 0 deletions packages/api-client/src/types/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,14 @@ export interface ClientConfig {
*/
headers?: Record<string, string>

/**
* Whether to attach `modrinth-sentry-capture: 1` to Archon requests.
* Can be a callback so apps can drive this from runtime feature flags.
*
* @default false
*/
archonSentryCapture?: boolean | (() => boolean)

/**
* Features to enable for this client
* Features are applied in the order they appear in this array
Expand Down
Loading