Skip to content
Open
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
4 changes: 2 additions & 2 deletions bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
},
"dependencies": {
"@ai-sdk/svelte": "^1.1.24",
"@appwrite.io/console": "https://pkg.vc/-/@appwrite/@appwrite.io/console@8e7decc",
"@appwrite.io/console": "https://pkg.vc/-/@appwrite/@appwrite.io/console@86906d2",
"@appwrite.io/pink-icons": "0.25.0",
"@appwrite.io/pink-icons-svelte": "https://pkg.vc/-/@appwrite/@appwrite.io/pink-icons-svelte@df765cc",
"@appwrite.io/pink-legacy": "^1.0.3",
Expand Down
2 changes: 2 additions & 0 deletions src/lib/actions/analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,8 @@ export enum Submit {
MessagingTopicSubscriberDelete = 'submit_messaging_topic_subscriber_delete',
ApplyQuickFilter = 'submit_apply_quick_filter',
RequestBAA = 'submit_request_baa',
BAAAddonEnable = 'submit_baa_addon_enable',
BAAAddonDisable = 'submit_baa_addon_disable',
RequestSoc2 = 'submit_request_soc2',
SiteCreate = 'submit_site_create',
SiteDelete = 'submit_site_delete',
Expand Down
3 changes: 2 additions & 1 deletion src/lib/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ export enum Dependencies {
MESSAGING_TOPIC_SUBSCRIBERS = 'dependency:messaging_topic_subscribers',
SITE = 'dependency:site',
SITES = 'dependency:sites',
SITES_DOMAINS = 'dependency:sites_domains'
SITES_DOMAINS = 'dependency:sites_domains',
ADDONS = 'dependency:addons'
}

export const defaultScopes: string[] = [
Expand Down
2 changes: 1 addition & 1 deletion src/lib/stores/migration.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { writable } from 'svelte/store';
import { Resources } from '@appwrite.io/console';
import { AppwriteMigrationResource as Resources } from '@appwrite.io/console';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== Check the narrowing introduced in migration store =="
rg -nP 'AppwriteMigrationResource as Resources|providerResources:\s*Record<Provider,\s*Resources\[\]>' src/lib/stores/migration.ts -C3

echo "== Confirm failing call sites and expected provider-specific report methods =="
rg -nP 'get(Supabase|Firebase|NHost)Report\(' src/routes/\(console\)/\(migration-wizard\)/resource-form.svelte -C3

echo "== Discover migration resource enums referenced in repository =="
rg -nP '\b(AppwriteMigrationResource|SupabaseMigrationResource|FirebaseMigrationResource|NHostMigrationResource)\b' -g '!**/node_modules/**'

echo "== Print declared `@appwrite.io/console` dependency version =="
python - <<'PY'
import json, pathlib
p = pathlib.Path("package.json")
if not p.exists():
    print("package.json not found")
    raise SystemExit(0)
data = json.loads(p.read_text())
v = data.get("dependencies", {}).get("@appwrite.io/console") or data.get("devDependencies", {}).get("@appwrite.io/console")
print("@appwrite.io/console:", v)
PY

Repository: appwrite/console

Length of output: 2125


Appwrite-only enum alias breaks provider-specific SDK method calls

Line 2 aliases AppwriteMigrationResource as the shared Resources type, which narrows providerResources to appwrite-only enum values. This causes type incompatibility when getSupabaseReport(), getFirebaseReport(), and getNHostReport() are called with mismatched resource types (lines 56, 67, 74 in resource-form.svelte).

The @todo comment on line 54 confirms this was known to be incomplete.

Import the provider-specific resource enums from @appwrite.io/console and use a mapped type for providerResources:

Proposed fix
-import { AppwriteMigrationResource as Resources } from '@appwrite.io/console';
+import {
+    AppwriteMigrationResource,
+    SupabaseMigrationResource,
+    FirebaseMigrationResource,
+    NHostMigrationResource
+} from '@appwrite.io/console';

+type ProviderResourcesMap = {
+    appwrite: AppwriteMigrationResource[];
+    supabase: SupabaseMigrationResource[];
+    firebase: FirebaseMigrationResource[];
+    nhost: NHostMigrationResource[];
+};

-export const providerResources: Record<Provider, Resources[]> = {
-    appwrite: Object.values(Resources),
+export const providerResources: ProviderResourcesMap = {
+    appwrite: Object.values(AppwriteMigrationResource) as AppwriteMigrationResource[],
     supabase: [
-        Resources.User,
-        Resources.Database,
+        SupabaseMigrationResource.User,
+        SupabaseMigrationResource.Database,
         // ...
     ],
     // firebase/nhost similarly with their own enums
 };
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/lib/stores/migration.ts` at line 2, The current import aliases
AppwriteMigrationResource as Resources which narrows providerResources to
Appwrite-only enums and breaks calls to getSupabaseReport, getFirebaseReport,
and getNHostReport from resource-form.svelte; fix by importing the
provider-specific enum types (e.g., AppwriteMigrationResource,
SupabaseMigrationResource, FirebaseMigrationResource, NHostMigrationResource)
from `@appwrite.io/console` and change the providerResources type to a
mapped/union type keyed by provider (e.g., a ProviderResourcesMap or a
discriminated union) so each provider maps to its own enum; update any
references to Resources in migration.ts and the resource-form.svelte parameters
to use the new mapped type so getSupabaseReport/getFirebaseReport/getNHostReport
receive the correct enum values.

import { includesAll } from '$lib/helpers/array';

const initialFormData = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
} from '$lib/stores/migration';
import { Button } from '$lib/elements/forms';
import { wizard } from '$lib/stores/wizard';
import { Resources, type Models } from '@appwrite.io/console';
import { AppwriteMigrationResource as Resources, type Models } from '@appwrite.io/console';
import type { sdk } from '$lib/stores/sdk';
import ImportReport from '$routes/(console)/project-[region]-[project]/settings/migrations/(import)/importReport.svelte';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export const load: PageLoad = async ({ parent, depends, url, route }) => {
depends(Dependencies.CREDIT);
depends(Dependencies.INVOICES);
depends(Dependencies.ADDRESS);
depends(Dependencies.ADDONS);
// aggregation reloads on page param changes
depends(Dependencies.BILLING_AGGREGATION);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,8 +247,17 @@
};

// addons (additional members, projects, etc.)
const billingAddonNames: Record<string, string> = {
addon_baa: 'HIPAA BAA'
};

const addons = (currentAggregation?.resources || [])
.filter((r) => r.amount > 0 && currentPlan?.addons?.[r.resourceId]?.price > 0)
.filter(
(r) =>
r.amount > 0 &&
(currentPlan?.addons?.[r.resourceId]?.price > 0 ||
r.resourceId.startsWith('addon_'))
)
.map((addon) => ({
id: `addon-${addon.resourceId}`,
expandable: false,
Expand All @@ -258,7 +267,8 @@
? 'Additional members'
: addon.resourceId === 'projects'
? 'Additional projects'
: `${addon.resourceId} overage (${formatNum(addon.value)})`,
: (billingAddonNames[addon.resourceId] ??
`${addon.resourceId} overage (${formatNum(addon.value)})`),
usage: '',
price: formatCurrency(addon.amount)
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
import { sdk } from '$lib/stores/sdk';
import { members, organization } from '$lib/stores/organization';
import { projects } from '../store';
import { invalidate } from '$app/navigation';
import { goto, invalidate } from '$app/navigation';
import { resolve } from '$app/paths';
import { Dependencies } from '$lib/constants';
import { onMount } from 'svelte';
import { page } from '$app/state';
import Delete from './deleteOrganizationModal.svelte';
import DownloadDPA from './downloadDPA.svelte';
import { Submit, trackEvent, trackError } from '$lib/actions/analytics';
Expand All @@ -22,8 +24,66 @@
let name: string;
let showDelete = false;

onMount(() => {
onMount(async () => {
name = $organization.name;

if (page.url.searchParams.get('type') === 'validate-addon') {
let addonId = page.url.searchParams.get('addonId');

// Fall back to listing addons if addonId is missing or invalid
if (!addonId || addonId === 'undefined') {
try {
const addons = await sdk.forConsole.organizations.listAddons({
organizationId: $organization.$id
});
const pending = addons.addons.find(
(a) => a.key === 'baa' && a.status === 'pending'
);
addonId = pending?.$id ?? null;
} catch {
addonId = null;
}
Comment on lines +35 to +45
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Avoid reporting success when addon lookup fails.

If listAddons fails (network/5xx/auth), the code sets addonId = null and then shows “BAA addon has been enabled” in the fallback branch. That can hide real failures and mislead users.

Proposed fix
 onMount(async () => {
     name = $organization.name;

     if (page.url.searchParams.get('type') === 'validate-addon') {
         let addonId = page.url.searchParams.get('addonId');
+        let lookupFailed = false;

         // Fall back to listing addons if addonId is missing or invalid
         if (!addonId || addonId === 'undefined') {
             try {
                 const addons = await sdk.forConsole.organizations.listAddons({
                     organizationId: $organization.$id
                 });
                 const pending = addons.addons.find(
                     (a) => a.key === 'baa' && a.status === 'pending'
                 );
                 addonId = pending?.$id ?? null;
-            } catch {
-                addonId = null;
+            } catch (e) {
+                lookupFailed = true;
+                addNotification({
+                    message: e?.message ?? 'Unable to verify BAA addon status. Please retry.',
+                    type: 'error'
+                });
             }
         }
+
+        if (lookupFailed) {
+            const settingsUrl = resolve('/(console)/organization-[organization]/settings', {
+                organization: $organization.$id
+            });
+            await goto(settingsUrl, { replaceState: true });
+            return;
+        }

         if (addonId) {
             // existing logic...

Also applies to: 80-89

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/routes/`(console)/organization-[organization]/settings/+page.svelte
around lines 35 - 45, The current try/catch around
sdk.forConsole.organizations.listAddons swallows errors and sets addonId = null,
which later causes the UI to show “BAA addon has been enabled” incorrectly;
instead, catch should record the failure (e.g., set an addonLookupError flag or
store the caught error) rather than conflating “no addon” and “lookup failed”,
and update the UI logic that reads addonId/pending to check this failure flag
before rendering the success/fallback branch; specifically, modify the block
using listAddons, pending, and addonId so the catch saves the error (or boolean)
and the downstream rendering avoids reporting success when addonLookupError is
set.

}

if (addonId) {
try {
await sdk.forConsole.organizations.validateAddonPayment({
organizationId: $organization.$id,
addonId
});
await Promise.all([
invalidate(Dependencies.ADDONS),
invalidate(Dependencies.ORGANIZATION)
]);
addNotification({
message: 'BAA addon has been enabled',
type: 'success'
});
} catch (e) {
// If addon not found, payment webhook may have already activated it
if (e?.type === 'addon_not_found' || e?.code === 404) {
await Promise.all([
invalidate(Dependencies.ADDONS),
invalidate(Dependencies.ORGANIZATION)
]);
addNotification({
message: 'BAA addon has been enabled',
type: 'success'
});
} else {
addNotification({
message: e.message,
type: 'error'
});
}
}
}

const settingsUrl = resolve('/(console)/organization-[organization]/settings', {
organization: $organization.$id
});
await goto(settingsUrl, { replaceState: true });
}
});

async function updateName() {
Expand Down Expand Up @@ -75,7 +135,7 @@

{#if isCloud}
<DownloadDPA />
<Baa locale={data.locale} countryList={data.countryList} />
<Baa addons={data.addons} />
<Soc2 locale={data.locale} countryList={data.countryList} />
{/if}

Expand Down
13 changes: 11 additions & 2 deletions src/routes/(console)/organization-[organization]/settings/+page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,30 @@ import { isCloud } from '$lib/system';
export const load: PageLoad = async ({ depends, params, parent }) => {
const { countryList, locale } = await parent();
depends(Dependencies.ORGANIZATION);
depends(Dependencies.ADDONS);

const [projects, invoices] = await Promise.all([
const [projects, invoices, addons] = await Promise.all([
sdk.forConsole.projects.list({
queries: [Query.equal('teamId', params.organization), Query.select(['$id', 'name'])]
}),
isCloud
? sdk.forConsole.organizations.listInvoices({
organizationId: params.organization
})
: undefined
: undefined,
isCloud
? sdk.forConsole.organizations
.listAddons({
organizationId: params.organization
})
.catch(() => null)
: null
]);

return {
projects,
invoices,
addons,
countryList,
locale
};
Expand Down
Loading
Loading