Cleanup - unused files / unused exports / duplicate exports
[ProtonMail-WebClient.git] / packages / shared / lib / vpn / serversCount.ts
blob98bf6fd4464a2fe25402cfc557afb037bec8bbb4
1 import {
2     queryVPNCountriesCount,
3     queryVPNLogicalServerInfoCount,
4     queryVPNServersCount,
5 } from '@proton/shared/lib/api/vpn';
6 import type {
7     Api,
8     VPNCountriesCount,
9     VPNLogicalsCount,
10     VPNServersCount,
11     VPNServersCountData,
12 } from '@proton/shared/lib/interfaces';
14 export const defaultVPNServersCountData: VPNServersCountData = {
15     free: { countries: 3, servers: 150 },
16     paid: { countries: 70, servers: 1900 },
19 export const getVPNServersCountData = async (api: Api) => {
20     const [serversCount, countriesCount, logicalsCount] = await Promise.all([
21         api<VPNServersCount>(queryVPNServersCount()),
22         api<VPNCountriesCount>(queryVPNCountriesCount()),
23         api<VPNLogicalsCount>(queryVPNLogicalServerInfoCount()),
24     ]);
26     const countFreeVPNCountries =
27         countriesCount.Counts.find((count) => count.MaxTier === 0)?.Count || defaultVPNServersCountData.free.countries;
28     const countFreeVpnServers = logicalsCount.Counts['0'];
30     const countPaidVPNServers = Math.floor(serversCount.Servers / 50) * 50;
31     const countPaidVPNCountries = Math.floor(serversCount.Countries / 5) * 5;
33     const result: VPNServersCountData = {
34         free: {
35             servers: countFreeVpnServers,
36             countries: countFreeVPNCountries,
37         },
38         paid: {
39             servers: countPaidVPNServers,
40             countries: countPaidVPNCountries,
41         },
42     };
43     return result;