diff --git a/src/lib/sdk/billing.ts b/src/lib/sdk/billing.ts index 8cb3b58a9..95c9f5c77 100644 --- a/src/lib/sdk/billing.ts +++ b/src/lib/sdk/billing.ts @@ -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; diff --git a/src/lib/stores/billing.ts b/src/lib/stores/billing.ts index c14b4b949..734445daa 100644 --- a/src/lib/stores/billing.ts +++ b/src/lib/stores/billing.ts @@ -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< diff --git a/src/routes/(console)/organization-[organization]/usage/[[invoice]]/+page.svelte b/src/routes/(console)/organization-[organization]/usage/[[invoice]]/+page.svelte index 636f88fdd..089bcaa56 100644 --- a/src/routes/(console)/organization-[organization]/usage/[[invoice]]/+page.svelte +++ b/src/routes/(console)/organization-[organization]/usage/[[invoice]]/+page.svelte @@ -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} + + SMS OTP +

+ OTPs are billed per SMS message, with rates varying by recipient country. For a detailed + cost breakdown, see the pricing page. +

+ + {#if data.organizationUsage.authPhoneTotal} +
+

+ {formatNum(data.organizationUsage.authPhoneTotal)} + SMS OTPs +

+

+ Estimated cost + + {formatCurrency(data.organizationUsage.authPhoneEstimate)} + + +

+
+ + {#if project?.length > 0} + + {/if} + {:else} + +
+
+
+ {/if} +
+

diff --git a/src/routes/(console)/organization-[organization]/usage/[[invoice]]/+page.ts b/src/routes/(console)/organization-[organization]/usage/[[invoice]]/+page.ts index 74dffcda2..65bc7ca86 100644 --- a/src/routes/(console)/organization-[organization]/usage/[[invoice]]/+page.ts +++ b/src/routes/(console)/organization-[organization]/usage/[[invoice]]/+page.ts @@ -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, } }; } diff --git a/src/routes/(console)/organization-[organization]/usage/[[invoice]]/ProjectBreakdown.svelte b/src/routes/(console)/organization-[organization]/usage/[[invoice]]/ProjectBreakdown.svelte index 5516b61b7..aaba05954 100644 --- a/src/routes/(console)/organization-[organization]/usage/[[invoice]]/ProjectBreakdown.svelte +++ b/src/routes/(console)/organization-[organization]/usage/[[invoice]]/ProjectBreakdown.svelte @@ -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 @@ Project Usage + {#if estimate} + Estimated Cost + {/if} {#if $canSeeProjects} {/if} - {#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} {data.projectNames[project.projectId]?.name ?? 'Unknown'} {format(project.usage)} + {#if project.estimate} + {formatCurrency(project.estimate)} + {/if} {:else} @@ -76,6 +94,10 @@ {data.projectNames[project.projectId]?.name ?? 'Unknown'} {format(project.usage)} + {#if project.estimate} + {formatCurrency(project.estimate)} + {/if}