feat: implement BAA addon management

This commit is contained in:
Damodar Lohani committed 2026-02-24 08:09:24 +00:00
1 parent 35c23ea662
commit bf2166bd37
12 files changed
+323 -155

No files matched your search

+2 -2
View File
@@ -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=="],
+1 -1
View File
@@ -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",
+2
View File
@@ -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',
+2 -1
View File
@@ -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[] = [
@@ -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);
@@ -247,8 +247,17 @@
};
// addons (additional members, projects, etc.)
const billingAddonNames: Record<string, string> = {
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)
},
@@ -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}
<DownloadDPA />
<Baa locale={data.locale} countryList={data.countryList} />
<Baa addons={data.addons} />
<Soc2 locale={data.locale} countryList={data.countryList} />
{/if}
@@ -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
};
@@ -1,38 +1,145 @@
<script lang="ts">
import { Box, CardGrid } from '$lib/components';
import { Button } from '$lib/elements/forms';
import BaaModal from './BAAModal.svelte';
import { getChangePlanUrl, plansInfo } from '$lib/stores/billing';
import { currentPlan } from '$lib/stores/organization';
import { organization } from '$lib/stores/organization';
import { get } from 'svelte/store';
import { invalidate } from '$app/navigation';
import { Dependencies } from '$lib/constants';
import { addNotification } from '$lib/stores/notifications';
import { sdk } from '$lib/stores/sdk';
import { Submit, trackEvent, trackError } from '$lib/actions/analytics';
import { Badge } from '@appwrite.io/pink-svelte';
import type { Models } from '@appwrite.io/console';
import BAAEnableModal from './BAAEnableModal.svelte';
import BAADisableModal from './BAADisableModal.svelte';
let show = false;
export let addons: Models.AddonList | null = null;
export let locale: Models.Locale;
export let countryList: Models.CountryList;
let showEnable = false;
let showDisable = false;
let reEnabling = false;
$: planSupportsBaa = $currentPlan?.supportedAddons?.baa === true;
$: canUpgradeToBaa = !planSupportsBaa && hasUpgradeablePlanWithBaa($currentPlan);
$: baaAddon = addons?.addons?.find(
(a) => a.key === 'baa' && (a.status === 'active' || a.status === 'pending')
);
$: isActive = baaAddon?.status === 'active' && baaAddon?.currentValue === 1;
$: isScheduledForRemoval = isActive && baaAddon?.nextValue === 0;
function hasUpgradeablePlanWithBaa(plan: Models.BillingPlan): boolean {
if (!plan) return false;
const plans = get(plansInfo);
for (const [, p] of plans) {
if (p.order > plan.order && p.supportedAddons?.baa) {
return true;
}
}
return false;
}
async function handleReEnable() {
reEnabling = true;
try {
await sdk.forConsole.organizations.createToggleAddon({
organizationId: $organization.$id,
key: 'baa'
});
await Promise.all([
invalidate(Dependencies.ADDONS),
invalidate(Dependencies.ORGANIZATION)
]);
addNotification({
message: 'BAA addon has been re-enabled',
type: 'success'
});
trackEvent(Submit.BAAAddonEnable);
} catch (e) {
addNotification({
message: e.message,
type: 'error'
});
trackError(e, Submit.BAAAddonEnable);
} finally {
reEnabling = false;
}
}
</script>
<CardGrid>
<svelte:fragment slot="title">BAA</svelte:fragment>
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.
<svelte:fragment slot="aside">
<Box>
<h6>
<b>Business Associate Agreement (BAA)</b>
</h6>
<p class="text u-margin-block-start-8">
A Business Associate Agreement (BAA) is a HIPAA-required document ensuring outside
services handling patient information for a healthcare organization follow privacy
rules.
</p>
<Button
secondary
external
class="u-margin-block-start-16"
on:click={() => (show = true)}
event="request_baa">
<span class="text">Request BAA</span>
</Button>
{#if !planSupportsBaa && canUpgradeToBaa}
<p class="text u-margin-block-start-8">
BAA is not available on your current plan. Upgrade your plan to enable BAA for
your organization.
</p>
<Button
secondary
class="u-margin-block-start-16"
href={getChangePlanUrl($organization?.$id)}>
<span class="text">Upgrade plan</span>
</Button>
{:else if !planSupportsBaa}
<p class="text u-margin-block-start-8">
BAA is not available on your current plan.
</p>
{:else if isActive}
<div class="u-flex u-cross-center u-gap-8 u-margin-block-start-8">
{#if isScheduledForRemoval}
<Badge variant="secondary" type="warning" content="Scheduled for removal" />
{:else}
<Badge variant="secondary" type="success" content="Active" />
{/if}
</div>
<p class="text u-margin-block-start-8">
BAA is enabled for your organization at $350/month.
</p>
{#if isScheduledForRemoval}
<p class="text u-margin-block-start-8">
BAA will be removed at the end of your current billing cycle.
</p>
<Button
secondary
class="u-margin-block-start-16"
disabled={reEnabling}
on:click={handleReEnable}>
<span class="text">Keep BAA</span>
</Button>
{:else}
<Button
secondary
class="u-margin-block-start-16"
on:click={() => (showDisable = true)}>
<span class="text">Disable BAA</span>
</Button>
{/if}
{:else}
<p class="text u-margin-block-start-8">
Enable BAA for your organization to ensure HIPAA compliance. This addon costs
$350/month, prorated for your current billing cycle.
</p>
<Button
secondary
class="u-margin-block-start-16"
on:click={() => (showEnable = true)}>
<span class="text">Enable BAA</span>
</Button>
{/if}
</Box>
</svelte:fragment>
</CardGrid>
<BaaModal {locale} {countryList} bind:show />
<BAAEnableModal bind:show={showEnable} />
{#if baaAddon}
<BAADisableModal bind:show={showDisable} addonId={baaAddon.$id} />
{/if}
@@ -0,0 +1,54 @@
<script lang="ts">
import { invalidate } from '$app/navigation';
import { Modal } from '$lib/components';
import { Button } from '$lib/elements/forms';
import { Dependencies } from '$lib/constants';
import { addNotification } from '$lib/stores/notifications';
import { Submit, trackEvent, trackError } from '$lib/actions/analytics';
import { organization } from '$lib/stores/organization';
import { sdk } from '$lib/stores/sdk';
export let show = false;
export let addonId: string;
let error: string = null;
let submitting = false;
async function handleSubmit() {
submitting = true;
error = null;
try {
await sdk.forConsole.organizations.deleteToggleAddon({
organizationId: $organization.$id,
addonId
});
await Promise.all([
invalidate(Dependencies.ADDONS),
invalidate(Dependencies.ORGANIZATION)
]);
addNotification({
message: 'BAA addon will be removed at the end of your current billing cycle',
type: 'success'
});
trackEvent(Submit.BAAAddonDisable);
show = false;
} catch (e) {
error = e.message;
trackError(e, Submit.BAAAddonDisable);
} finally {
submitting = false;
}
}
</script>
<Modal bind:error bind:show onSubmit={handleSubmit} title="Disable BAA">
<p class="text">
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.
</p>
<svelte:fragment slot="footer">
<Button text on:click={() => (show = false)}>Cancel</Button>
<Button secondary submit disabled={submitting}>Disable BAA</Button>
</svelte:fragment>
</Modal>
@@ -0,0 +1,77 @@
<script lang="ts">
import { invalidate } from '$app/navigation';
import { resolve } from '$app/paths';
import { Modal } from '$lib/components';
import { Button } from '$lib/elements/forms';
import { Dependencies } from '$lib/constants';
import { addNotification } from '$lib/stores/notifications';
import { Submit, trackEvent, trackError } from '$lib/actions/analytics';
import { confirmPayment } from '$lib/stores/stripe';
import { organization } from '$lib/stores/organization';
import { sdk } from '$lib/stores/sdk';
import type { Models } from '@appwrite.io/console';
export let show = false;
let error: string = null;
let submitting = false;
async function handleSubmit() {
submitting = true;
error = null;
try {
const result: Models.Addon | Models.PaymentAuthentication =
await sdk.forConsole.organizations.createToggleAddon({
organizationId: $organization.$id,
key: 'baa'
});
if ('clientSecret' in result) {
const paymentAuth = result as unknown as Models.PaymentAuthentication;
const settingsUrl = resolve(
'/(console)/organization-[organization]/settings',
{ organization: $organization.$id }
);
await confirmPayment({
clientSecret: paymentAuth.clientSecret,
paymentMethodId: $organization.paymentMethodId,
orgId: $organization.$id,
route: `${settingsUrl}?type=validate-addon&addonId=${paymentAuth.invoiceId}`
});
return;
}
await Promise.all([
invalidate(Dependencies.ADDONS),
invalidate(Dependencies.ORGANIZATION)
]);
addNotification({
message: 'BAA addon has been enabled',
type: 'success'
});
trackEvent(Submit.BAAAddonEnable);
show = false;
} catch (e) {
error = e.message;
trackError(e, Submit.BAAAddonEnable);
} finally {
submitting = false;
}
}
</script>
<Modal bind:error bind:show onSubmit={handleSubmit} title="Enable BAA">
<p class="text">
By enabling BAA, a Business Associate Agreement will be activated for your organization to
ensure HIPAA compliance.
</p>
<p class="text u-margin-block-start-8">
This addon costs <b>$350/month</b>, prorated for the remainder of your current billing
cycle.
</p>
<svelte:fragment slot="footer">
<Button text on:click={() => (show = false)}>Cancel</Button>
<Button secondary submit disabled={submitting}>Enable BAA</Button>
</svelte:fragment>
</Modal>
@@ -1,125 +0,0 @@
<script lang="ts">
import { Submit, trackError, trackEvent } from '$lib/actions/analytics';
import { Modal } from '$lib/components';
import { Button, InputEmail, InputSelect, InputText } from '$lib/elements/forms';
import { addNotification } from '$lib/stores/notifications';
import { organization } from '$lib/stores/organization';
import { user } from '$lib/stores/user';
import { VARS } from '$lib/system';
import { onMount } from 'svelte';
import type { Models } from '@appwrite.io/console';
export let show = false;
export let locale: Models.Locale;
export let countryList: Models.CountryList;
let email = '';
let employees: string = null;
let employeesOptions = [
{
value: '1-5',
label: '1-5'
},
{
value: '6-10',
label: '6-10'
},
{
value: '11-50',
label: '11-50'
},
{
value: '50+',
label: '50+'
}
];
let country = '';
let countryOptions = [];
let role = '';
let website = '';
let error: string;
onMount(async () => {
if (locale.countryCode) {
country = locale.countryCode;
}
countryOptions = countryList.countries.map((country) => {
return {
value: country.code,
label: country.name
};
});
email = $user.email;
});
async function handleSubmit() {
const response = await fetch(`${VARS.GROWTH_ENDPOINT}/support`, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
subject: 'BAA Request',
email: email,
firstName: ($user?.name ?? '').slice(0, 40),
message: `BAA request for ${$organization?.name ?? ''} (${$organization?.$id ?? ''})`,
tags: ['cloud'],
metaFields: {
category: 'BAA',
userName: $user?.name ?? '',
orgId: $organization?.$id ?? '',
userId: $user?.$id ?? '',
employees: employees,
country: country,
role: role,
website: website
}
})
});
trackEvent(Submit.RequestBAA);
if (response.status !== 200) {
trackError(new Error(response.status.toString()), Submit.RequestBAA);
error = 'There was an error submitting your request. Please try again later.';
} else {
show = false;
addNotification({
message: `Your request was sent, we will get in contact with you at ${email} in a few working days`,
type: 'success'
});
}
}
</script>
<Modal bind:error bind:show onSubmit={handleSubmit} title="Request BAA">
<InputEmail label="Email" placeholder="Enter email" id="email" bind:value={email} />
<InputSelect
label="Number of employees"
id="employees"
placeholder="Select number of employees"
required
options={employeesOptions}
bind:value={employees} />
<InputSelect
label="Country"
id="country"
options={countryOptions}
placeholder="Select country"
required
bind:value={country} />
<InputText
label="Your role"
placeholder="Enter your role"
id="role"
bind:value={role}
required />
<InputText label="Website" placeholder="Enter website" id="website" bind:value={website} />
<svelte:fragment slot="footer">
<Button submit>
<span class="text">Send request</span>
</Button>
</svelte:fragment>
</Modal>