Skip to content

The only tool you need to know what is happening and how to fix it.

billing extension on fe

ddux201dec9ef252
diff --git a/frontend/src/routes/settings/+page.svelte b/frontend/src/routes/settings/+page.svelte
index 5dbc95e5..27811c90 100644
--- a/frontend/src/routes/settings/+page.svelte
+++ b/frontend/src/routes/settings/+page.svelte
@@ -5,9 +5,25 @@
import { organizationState } from '$lib/state/organization.svelte';
import OrganizationTab from './organization-tab.svelte';
import UsersTab from './users-tab.svelte';
+ import type { Component } from 'svelte';
let loading = $state(true);
let error = $state<string | null>(null);
+ let BillingTab = $state<Component<{ organizationId: number }> | null>(null);
+
+ async function loadBillingModule() {
+ try {
+ // @ts-ignore - $billing alias only exists when billing extension is available
+ const module = await import('$billing/billing-tab.svelte');
+ BillingTab = module.default;
+ } catch {
+ // Billing extension not available - this is expected for open source builds
+ }
+ }
+
+ $effect(() => {
+ loadBillingModule();
+ });
const currentOrganizationId = $derived(projectsState.currentProject?.organizationId);
@@ -54,6 +70,9 @@
<div class="space-y-6">
<OrganizationTab />
<UsersTab organizationId={currentOrganizationId!} />
+ {#if BillingTab}
+ <BillingTab organizationId={currentOrganizationId!} />
+ {/if}
</div>
{/if}
</div>
diff --git a/frontend/svelte.config.js b/frontend/svelte.config.js
index 4932f243..e0aa1e44 100644
--- a/frontend/svelte.config.js
+++ b/frontend/svelte.config.js
@@ -1,5 +1,11 @@
import adapter from '@sveltejs/adapter-static';
import { vitePreprocess } from '@sveltejs/vite-plugin-svelte';
+import { existsSync } from 'fs';
+import path from 'path';
+
+const billingPath = process.env.BILLING_PATH || '../traceway-billing/frontend';
+const resolvedBillingPath = path.resolve(process.cwd(), billingPath);
+const billingExists = existsSync(resolvedBillingPath);
/** @type {import('@sveltejs/kit').Config} */
const config = {
@@ -13,7 +19,11 @@ const config = {
// See https://svelte.dev/docs/kit/adapters for more information about adapters.
adapter: adapter({
fallback: 'index.html'
- })
+ }),
+ alias: billingExists ? {
+ '$billing': resolvedBillingPath,
+ '$billing/*': `${resolvedBillingPath}/*`
+ } : {}
}
};
diff --git a/frontend/tsconfig.json b/frontend/tsconfig.json
index 2c2ed3c4..feea18bf 100644
--- a/frontend/tsconfig.json
+++ b/frontend/tsconfig.json
@@ -12,9 +12,4 @@
"strict": true,
"moduleResolution": "bundler"
}
- // Path aliases are handled by https://svelte.dev/docs/kit/configuration#alias
- // except $lib which is handled by https://svelte.dev/docs/kit/configuration#files
- //
- // To make changes to top-level options such as include and exclude, we recommend extending
- // the generated config; see https://svelte.dev/docs/kit/configuration#typescript
}
diff --git a/frontend/vite.config.ts b/frontend/vite.config.ts
index c3e0f6bf..9d740fb6 100644
--- a/frontend/vite.config.ts
+++ b/frontend/vite.config.ts
@@ -1,10 +1,15 @@
import tailwindcss from '@tailwindcss/vite';
import { sveltekit } from '@sveltejs/kit/vite';
import { defineConfig, loadEnv } from 'vite';
-import { readFileSync } from 'fs';
+import { readFileSync, existsSync } from 'fs';
+import path from 'path';
const pkg = JSON.parse(readFileSync('./package.json', 'utf-8'));
+const billingPath = process.env.BILLING_PATH || '../traceway-billing/frontend';
+const resolvedBillingPath = path.resolve(import.meta.dirname, billingPath);
+const billingExists = existsSync(resolvedBillingPath);
+
export default defineConfig(({ mode }) => {
const env = loadEnv(mode, process.cwd(), '');
@@ -12,7 +17,8 @@ export default defineConfig(({ mode }) => {
plugins: [tailwindcss(), sveltekit()],
define: {
__APP_VERSION__: JSON.stringify(env.PUBLIC_APP_VERSION || pkg.version),
- __CLOUD_MODE__: env.CLOUD_MODE
+ __CLOUD_MODE__: env.CLOUD_MODE,
+ __BILLING_AVAILABLE__: billingExists
},
server: {
proxy: {