feat: add sms to usage

This commit is contained in:
loks0n committed 2025-01-09 11:21:53 +00:00
1 parent be7aa21121
commit 92c45a5621
5 files changed
+96 -9

No files matched your search

+5
View File
@@ -195,7 +195,11 @@ export type OrganizationUsage = {
executions: number;
bandwidth: number;
users: number;
authPhoneTotal: number;
authPhoneEstimate: number;
}>;
authPhoneTotal: number;
authPhoneEstimate: number;
};
export type AggregationList = {
@@ -270,6 +274,7 @@ export type Plan = {
executions: number;
realtime: number;
logs: number;
authPhone: number;
addons: {
bandwidth: AdditionalResource;
executions: AdditionalResource;
+7 -2
View File
@@ -128,15 +128,20 @@ export type PlanServices =
| 'teams'
| 'users'
| 'usersAddon'
| 'webhooks';
| 'webhooks'
| 'authPhone';
export function getServiceLimit(serviceId: PlanServices, tier: Tier = null, plan?: Plan): number {
if (serviceId === 'authPhone') {
return 10;
}
if (!isCloud) return 0;
if (!serviceId) return 0;
const info = get(plansInfo);
if (!info) return 0;
plan ??= info.get(tier ?? get(organization)?.billingPlan);
return plan?.[serviceId];
return plan?.[serviceId] ?? 0;
}
export const failedInvoice = cachedStore<
@@ -18,6 +18,8 @@
import { BillingPlan } from '$lib/constants';
import { trackEvent } from '$lib/actions/analytics';
import TotalMembers from './totalMembers.svelte';
import { tooltip } from '$lib/actions/tooltip';
import { formatCurrency } from '$lib/helpers/numbers';
export let data;
@@ -376,6 +378,57 @@
{/if}
</svelte:fragment>
</CardGrid>
<CardGrid>
<Heading tag="h6" size="7">SMS OTP</Heading>
<p class="text">
OTPs are billed per SMS message, with rates varying by recipient country. For a detailed
cost breakdown, see the <a
href="https://appwrite.io/docs/advanced/platform/otp-sms"
class="link">pricing page</a
>.
</p>
<svelte:fragment slot="aside">
{#if data.organizationUsage.authPhoneTotal}
<div class="u-flex u-main-space-between">
<p>
<span class="heading-level-4"
>{formatNum(data.organizationUsage.authPhoneTotal)}</span>
<span class="body-text-1 u-bold">SMS OTPs</span>
</p>
<p class="u-flex u-gap-8 u-cross-center">
<span class="u-color-text-offline">Estimated cost</span>
<span class="body-text-2">
{formatCurrency(data.organizationUsage.authPhoneEstimate)}
<span
class="icon-info u-color-text-offline"
use:tooltip={{
content:
'The first 10 SMS OTP messages are provided at no cost. Pricing may vary as it depends on telecom rates and vendor agreements.'
}} />
</span>
</p>
</div>
{#if project?.length > 0}
<ProjectBreakdown
projects={project}
metric="authPhoneTotal"
estimate="authPhoneEstimate"
{data} />
{/if}
{:else}
<Card isDashed>
<div class="u-flex u-cross-center u-flex-vertical u-main-center u-flex">
<span
class="icon-chart-square-bar text-large"
aria-hidden="true"
style="font-size: 32px;" />
<p class="u-bold">No data to show</p>
</div>
</Card>
{/if}
</svelte:fragment>
</CardGrid>
<TotalMembers members={data?.organizationMembers} />
<p class="text common-section u-color-text-gray">
@@ -27,7 +27,9 @@ export const load: PageLoad = async ({ params, parent }) => {
executionsTotal: null,
projects: null,
executionsMBSecondsTotal: null,
buildsMBSecondsTotal: null
buildsMBSecondsTotal: null,
authPhoneTotal: null,
authPhoneEstimate: null,
}
};
}
@@ -10,41 +10,52 @@
TableRowLink,
TableScroll
} from '$lib/elements/table';
import { abbreviateNumber } from '$lib/helpers/numbers';
import { abbreviateNumber, formatCurrency } from '$lib/helpers/numbers';
import { humanFileSize } from '$lib/helpers/sizeConvertion';
import type { OrganizationUsage } from '$lib/sdk/billing';
import { base } from '$app/paths';
import { canSeeProjects } from '$lib/stores/roles';
type Metric = 'users' | 'storage' | 'bandwidth' | 'executions';
type Metric = 'users' | 'storage' | 'bandwidth' | 'executions' | 'authPhoneTotal';
type Estimate = 'authPhoneEstimate';
export let data: PageData;
export let projects: OrganizationUsage['projects'];
export let metric: Metric;
export let estimate: Estimate | undefined = undefined;
function getProjectUsageLink(projectId: string): string {
return `${base}/project-${projectId}/settings/usage`;
}
function groupByProject(metric: Metric): Array<{ projectId: string; usage: number }> {
function groupByProject(
metric: Metric,
estimate?: Estimate
): Array<{ projectId: string; usage: number; estimate?: number }> {
const data = [];
for (const project of projects) {
const usage = project[metric];
if (!usage) {
continue;
}
data.push({
projectId: project.projectId,
usage: usage ?? 0
usage: usage ?? 0,
estimate: estimate ? project[estimate] : undefined
});
}
return data;
}
function format(value: number): string {
const humanized = humanFileSize(value);
switch (metric) {
case 'authPhoneTotal':
case 'executions':
case 'users':
return abbreviateNumber(value);
case 'storage':
case 'bandwidth':
const humanized = humanFileSize(value);
return humanized.value + humanized.unit;
}
}
@@ -57,18 +68,25 @@
<TableHeader>
<TableCellHead>Project</TableCellHead>
<TableCellHead>Usage</TableCellHead>
{#if estimate}
<TableCellHead>Estimated Cost</TableCellHead>
{/if}
{#if $canSeeProjects}
<TableCellHead />
{/if}
</TableHeader>
<TableBody>
{#each groupByProject(metric).sort((a, b) => b.usage - a.usage) as project}
{#each groupByProject(metric, estimate).sort((a, b) => b.usage - a.usage) as project}
{#if !$canSeeProjects}
<TableRow>
<TableCell title="Project">
{data.projectNames[project.projectId]?.name ?? 'Unknown'}
</TableCell>
<TableCell title="Usage">{format(project.usage)}</TableCell>
{#if project.estimate}
<TableCell title="Estimate"
>{formatCurrency(project.estimate)}</TableCell>
{/if}
</TableRow>
{:else}
<TableRowLink href={getProjectUsageLink(project.projectId)}>
@@ -76,6 +94,10 @@
{data.projectNames[project.projectId]?.name ?? 'Unknown'}
</TableCell>
<TableCell title="Usage">{format(project.usage)}</TableCell>
{#if project.estimate}
<TableCell title="Estimate"
>{formatCurrency(project.estimate)}</TableCell>
{/if}
<TableCell right={true}>
<span
class="icon-cheveron-right u-cross-child-center ignore-icon-rotate" />