From bf2166bd37d0e317ba3afc7ec40edb47d31c843c Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Tue, 24 Feb 2026 08:09:24 +0000 Subject: [PATCH] feat: implement BAA addon management --- bun.lock | 4 +- package.json | 2 +- src/lib/actions/analytics.ts | 2 + src/lib/constants.ts | 3 +- .../billing/+page.ts | 1 + .../billing/planSummary.svelte | 14 +- .../settings/+page.svelte | 38 ++++- .../settings/+page.ts | 13 +- .../settings/BAA.svelte | 145 +++++++++++++++--- .../settings/BAADisableModal.svelte | 54 +++++++ .../settings/BAAEnableModal.svelte | 77 ++++++++++ .../settings/BAAModal.svelte | 125 --------------- 12 files changed, 323 insertions(+), 155 deletions(-) create mode 100644 src/routes/(console)/organization-[organization]/settings/BAADisableModal.svelte create mode 100644 src/routes/(console)/organization-[organization]/settings/BAAEnableModal.svelte delete mode 100644 src/routes/(console)/organization-[organization]/settings/BAAModal.svelte diff --git a/bun.lock b/bun.lock index 36d1113af..083357f2c 100644 --- a/bun.lock +++ b/bun.lock @@ -6,7 +6,7 @@ "name": "@appwrite/console", "dependencies": { "@ai-sdk/svelte": "^1.1.24", - "@appwrite.io/console": "https://pkg.vc/-/@appwrite/@appwrite.io/console@de65a99", + "@appwrite.io/console": "https://pkg.vc/-/@appwrite/@appwrite.io/console@44b749b", "@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", @@ -108,7 +108,7 @@ "@analytics/type-utils": ["@analytics/type-utils@0.6.4", "", {}, "sha512-Ou1gQxFakOWLcPnbFVsrPb8g1wLLUZYYJXDPjHkG07+5mustGs5yqACx42UAu4A6NszNN6Z5gGxhyH45zPWRxw=="], - "@appwrite.io/console": ["@appwrite.io/console@https://pkg.vc/-/@appwrite/@appwrite.io/console@de65a99", { "dependencies": { "json-bigint": "1.0.0" } }], + "@appwrite.io/console": ["@appwrite.io/console@https://pkg.vc/-/@appwrite/@appwrite.io/console@44b749b", { "dependencies": { "json-bigint": "1.0.0" } }], "@appwrite.io/pink-icons": ["@appwrite.io/pink-icons@0.25.0", "", {}, "sha512-0O3i2oEuh5mWvjO80i+X6rbzrWLJ1m5wmv2/M3a1p2PyBJsFxN8xQMTEmTn3Wl/D26SsM7SpzbdW6gmfgoVU9Q=="], diff --git a/package.json b/package.json index 1905197e2..db18e2499 100644 --- a/package.json +++ b/package.json @@ -20,7 +20,7 @@ }, "dependencies": { "@ai-sdk/svelte": "^1.1.24", - "@appwrite.io/console": "https://pkg.vc/-/@appwrite/@appwrite.io/console@de65a99", + "@appwrite.io/console": "https://pkg.vc/-/@appwrite/@appwrite.io/console@44b749b", "@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", diff --git a/src/lib/actions/analytics.ts b/src/lib/actions/analytics.ts index 305bf33d9..48a0414e6 100644 --- a/src/lib/actions/analytics.ts +++ b/src/lib/actions/analytics.ts @@ -425,6 +425,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', diff --git a/src/lib/constants.ts b/src/lib/constants.ts index 2cb52605e..549c56fd6 100644 --- a/src/lib/constants.ts +++ b/src/lib/constants.ts @@ -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[] = [ diff --git a/src/routes/(console)/organization-[organization]/billing/+page.ts b/src/routes/(console)/organization-[organization]/billing/+page.ts index 4c10658ca..202a6ee25 100644 --- a/src/routes/(console)/organization-[organization]/billing/+page.ts +++ b/src/routes/(console)/organization-[organization]/billing/+page.ts @@ -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); diff --git a/src/routes/(console)/organization-[organization]/billing/planSummary.svelte b/src/routes/(console)/organization-[organization]/billing/planSummary.svelte index afe13b517..a26820575 100644 --- a/src/routes/(console)/organization-[organization]/billing/planSummary.svelte +++ b/src/routes/(console)/organization-[organization]/billing/planSummary.svelte @@ -247,8 +247,17 @@ }; // addons (additional members, projects, etc.) + const billingAddonNames: Record = { + addon_baa: 'BAA Agreement' + }; + 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, @@ -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) }, diff --git a/src/routes/(console)/organization-[organization]/settings/+page.svelte b/src/routes/(console)/organization-[organization]/settings/+page.svelte index b5bf05fc0..e9a158158 100644 --- a/src/routes/(console)/organization-[organization]/settings/+page.svelte +++ b/src/routes/(console)/organization-[organization]/settings/+page.svelte @@ -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'; @@ -22,8 +24,38 @@ let name: string; let showDelete = false; - onMount(() => { + onMount(async () => { name = $organization.name; + + if (page.url.searchParams.get('type') === 'validate-addon') { + const addonId = page.url.searchParams.get('addonId'); + if (addonId) { + try { + await sdk.forConsole.organizations.validateToggleAddonPayment({ + organizationId: $organization.$id, + addonId + }); + await Promise.all([ + invalidate(Dependencies.ADDONS), + invalidate(Dependencies.ORGANIZATION) + ]); + addNotification({ + message: 'BAA addon has been enabled', + type: 'success' + }); + } catch (e) { + addNotification({ + message: e.message, + type: 'error' + }); + } + const settingsUrl = resolve( + '/(console)/organization-[organization]/settings', + { organization: $organization.$id } + ); + await goto(settingsUrl, { replaceState: true }); + } + } }); async function updateName() { @@ -75,7 +107,7 @@ {#if isCloud} - + {/if} diff --git a/src/routes/(console)/organization-[organization]/settings/+page.ts b/src/routes/(console)/organization-[organization]/settings/+page.ts index 1f377bfe3..8ec4edb17 100644 --- a/src/routes/(console)/organization-[organization]/settings/+page.ts +++ b/src/routes/(console)/organization-[organization]/settings/+page.ts @@ -7,8 +7,9 @@ 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'])] }), @@ -16,12 +17,20 @@ export const load: PageLoad = async ({ depends, params, parent }) => { ? 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 }; diff --git a/src/routes/(console)/organization-[organization]/settings/BAA.svelte b/src/routes/(console)/organization-[organization]/settings/BAA.svelte index 87b33da1f..a4e4d4725 100644 --- a/src/routes/(console)/organization-[organization]/settings/BAA.svelte +++ b/src/routes/(console)/organization-[organization]/settings/BAA.svelte @@ -1,38 +1,145 @@ BAA - After requesting a BAA, we will contact you via email for the next steps. + A Business Associate Agreement (BAA) is a HIPAA-required document ensuring outside services + handling patient information for a healthcare organization follow privacy rules.
Business Associate Agreement (BAA)
-

- A Business Associate Agreement (BAA) is a HIPAA-required document ensuring outside - services handling patient information for a healthcare organization follow privacy - rules. -

- + {#if !planSupportsBaa && canUpgradeToBaa} +

+ BAA is not available on your current plan. Upgrade your plan to enable BAA for + your organization. +

+ + {:else if !planSupportsBaa} +

+ BAA is not available on your current plan. +

+ {:else if isActive} +
+ {#if isScheduledForRemoval} + + {:else} + + {/if} +
+

+ BAA is enabled for your organization at $350/month. +

+ {#if isScheduledForRemoval} +

+ BAA will be removed at the end of your current billing cycle. +

+ + {:else} + + {/if} + {:else} +

+ Enable BAA for your organization to ensure HIPAA compliance. This addon costs + $350/month, prorated for your current billing cycle. +

+ + {/if}
- + + +{#if baaAddon} + +{/if} diff --git a/src/routes/(console)/organization-[organization]/settings/BAADisableModal.svelte b/src/routes/(console)/organization-[organization]/settings/BAADisableModal.svelte new file mode 100644 index 000000000..df8d321b8 --- /dev/null +++ b/src/routes/(console)/organization-[organization]/settings/BAADisableModal.svelte @@ -0,0 +1,54 @@ + + + +

+ Are you sure you want to disable the BAA addon? The addon will remain active until the end + of your current billing cycle and will not be renewed. +

+ + + + + +
diff --git a/src/routes/(console)/organization-[organization]/settings/BAAEnableModal.svelte b/src/routes/(console)/organization-[organization]/settings/BAAEnableModal.svelte new file mode 100644 index 000000000..b129f85c6 --- /dev/null +++ b/src/routes/(console)/organization-[organization]/settings/BAAEnableModal.svelte @@ -0,0 +1,77 @@ + + + +

+ By enabling BAA, a Business Associate Agreement will be activated for your organization to + ensure HIPAA compliance. +

+

+ This addon costs $350/month, prorated for the remainder of your current billing + cycle. +

+ + + + + +
diff --git a/src/routes/(console)/organization-[organization]/settings/BAAModal.svelte b/src/routes/(console)/organization-[organization]/settings/BAAModal.svelte deleted file mode 100644 index 1aaccfef2..000000000 --- a/src/routes/(console)/organization-[organization]/settings/BAAModal.svelte +++ /dev/null @@ -1,125 +0,0 @@ - - - - - - - - - - - - -