refactor: model plan

This commit is contained in:
ChiragAgg5k
2025-03-11 13:53:10 +05:30
parent 9935add9d5
commit b034115cf9
14 changed files with 1538 additions and 1481 deletions
+23 -23
View File
@@ -108,9 +108,9 @@ pnpm run lint
Diagnostic tool that checks for the following:
- Unused CSS
- Svelte A11y hints
- TypeScript compiler errors
- Unused CSS
- Svelte A11y hints
- TypeScript compiler errors
```bash
pnpm run check
@@ -130,11 +130,11 @@ doc-548-submit-a-pull-request-section-to-contribution-guide
When `TYPE` can be:
- **feat** - is a new feature
- **doc** - documentation only changes
- **cicd** - changes related to CI/CD system
- **fix** - a bug fix
- **refactor** - code change that neither fixes a bug nor adds a feature
- **feat** - is a new feature
- **doc** - documentation only changes
- **cicd** - changes related to CI/CD system
- **fix** - a bug fix
- **refactor** - code change that neither fixes a bug nor adds a feature
**All PRs must include a commit message with a description of the changes made!**
@@ -175,12 +175,12 @@ $ git push origin [name_of_your_new_branch]
Before committing always make sure to run all available tools to improve the codebase:
- Formatter
- `pnpm run format`
- Tests
- `pnpm test`
- Diagnostics
- `pnpm run check`
- Formatter
- `pnpm run format`
- Tests
- `pnpm test`
- Diagnostics
- `pnpm run check`
### Performance
@@ -188,9 +188,9 @@ Page load times are a key consideration for users of all browsers and device typ
There are some general things we can do in front-end development:
- Minimize HTTP requests
- Minimize blocking content should be readable before client-side processing
- Lazy load "supplementary" content, especially images
- Minimize HTTP requests
- Minimize blocking content should be readable before client-side processing
- Lazy load "supplementary" content, especially images
### Don't Repeat Yourself (DRY)
@@ -202,12 +202,12 @@ If you stick to this principle, you will ensure that you will only ever need to
Separate _structure_ from _presentation_ from _behavior_ to aid maintainability and understanding.
- Keep CSS (presentation), JS (behavior) and HTML (structure) in the same respective Svelte component
- Avoid writing inline CSS or Javascript in HTML
- Avoid writing CSS or HTML in Javascript
- Don't choose HTML elements to imply style
- Where appropriate, use CSS or Svelte rather than Javascript for animations and transitions
- Try to use templates when defining markup in Javascript
- Keep CSS (presentation), JS (behavior) and HTML (structure) in the same respective Svelte component
- Avoid writing inline CSS or Javascript in HTML
- Avoid writing CSS or HTML in Javascript
- Don't choose HTML elements to imply style
- Where appropriate, use CSS or Svelte rather than Javascript for animations and transitions
- Try to use templates when defining markup in Javascript
### Write code to be read
+2 -2
View File
@@ -10,8 +10,8 @@
Appwrite Console has been built with the following frameworks:
- [Svelte](https://svelte.dev/)
- [Svelte Kit](https://kit.svelte.dev/)
- [Svelte](https://svelte.dev/)
- [Svelte Kit](https://kit.svelte.dev/)
## Developer Experience
+1478 -1378
View File
File diff suppressed because it is too large Load Diff
+4 -52
View File
@@ -65,55 +65,7 @@ export type PlanAddon = {
type: string;
};
export type Plan = {
$id: string;
name: string;
desc: string;
price: number;
order: number;
bandwidth: number;
storage: number;
imageTransformations: number;
webhooks: number;
users: number;
teams: number;
databases: number;
buckets: number;
fileSize: number;
functions: number;
executions: number;
realtime: number;
logs: number;
authPhone: number;
usage: {
bandwidth: AdditionalResource;
executions: AdditionalResource;
member: AdditionalResource;
realtime: AdditionalResource;
storage: AdditionalResource;
users: AdditionalResource;
};
addons: {
seats: PlanAddon;
};
trialDays: number;
isAvailable: boolean;
selfService: boolean;
premiumSupport: boolean;
budgeting: boolean;
supportsMockNumbers: boolean;
backupsEnabled: boolean;
backupPolicies: number;
emailBranding: boolean;
supportsCredits: boolean;
};
export type PlanList = {
plans: Plan[];
total: number;
};
export type PlansMap = Map<Tier, Plan>;
export type PlansMap = Map<Tier, Models.BillingPlan>;
export class Billing {
client: Client;
@@ -205,7 +157,7 @@ export class Billing {
});
}
async getOrganizationPlan(organizationId: string): Promise<Plan> {
async getOrganizationPlan(organizationId: string): Promise<Models.BillingPlan> {
const path = `/organizations/${organizationId}/plan`;
const uri = new URL(this.client.config.endpoint + path);
return await this.client.call('get', uri, {
@@ -213,7 +165,7 @@ export class Billing {
});
}
async getPlan(planId: string): Promise<Plan> {
async getPlan(planId: string): Promise<Models.BillingPlan> {
const path = `/console/plans/${planId}`;
const uri = new URL(this.client.config.endpoint + path);
return await this.client.call('get', uri, {
@@ -577,7 +529,7 @@ export class Billing {
);
}
async getPlansInfo(): Promise<PlanList> {
async getPlansInfo(): Promise<Models.BillingPlanList> {
const path = `/console/plans`;
const params = {};
const uri = new URL(this.client.config.endpoint + path);
+7 -3
View File
@@ -12,7 +12,7 @@ import PaymentMandate from '$lib/components/billing/alerts/paymentMandate.svelte
import { BillingPlan, NEW_DEV_PRO_UPGRADE_COUPON } from '$lib/constants';
import { cachedStore } from '$lib/helpers/cache';
import { sizeToBytes, type Size } from '$lib/helpers/sizeConvertion';
import type { AddressesList, Plan, PlansMap } from '$lib/sdk/billing';
import type { AddressesList, PlansMap } from '$lib/sdk/billing';
import { isCloud } from '$lib/system';
import { activeHeaderAlert, orgMissingPaymentMethod } from '$routes/(console)/store';
import type { Models } from '@appwrite.io/console';
@@ -129,7 +129,11 @@ export type PlanServices =
| 'authPhone'
| 'imageTransformations';
export function getServiceLimit(serviceId: PlanServices, tier: Tier = null, plan?: Plan): number {
export function getServiceLimit(
serviceId: PlanServices,
tier: Tier = null,
plan?: Models.BillingPlan
): number {
if (!isCloud) return 0;
if (!serviceId) return 0;
const info = get(plansInfo);
@@ -484,7 +488,7 @@ export const billingURL = derived(
export const hideBillingHeaderRoutes = ['/console/create-organization', '/console/account'];
export function calculateExcess(addon: Models.AggregationTeam, plan: Plan) {
export function calculateExcess(addon: Models.AggregationTeam, plan: Models.BillingPlan) {
return {
bandwidth: calculateResourceSurplus(addon.usageBandwidth, plan.bandwidth),
storage: calculateResourceSurplus(addon.usageStorage, plan.storage, 'GB'),
+1 -2
View File
@@ -1,5 +1,4 @@
import { page } from '$app/stores';
import type { Plan } from '$lib/sdk/billing';
import type { Models } from '@appwrite.io/console';
import { derived, writable } from 'svelte/store';
import type { Tier } from './billing';
@@ -50,5 +49,5 @@ export const organizationList = derived(
);
export const organization = derived(page, ($page) => $page.data?.organization as Organization);
export const currentPlan = derived(page, ($page) => $page.data?.currentPlan as Plan);
export const currentPlan = derived(page, ($page) => $page.data?.currentPlan as Models.BillingPlan);
export const members = derived(page, ($page) => $page.data.members as Models.MembershipList);
+3 -3
View File
@@ -1,8 +1,8 @@
import { Dependencies } from '$lib/constants';
import type { Plan } from '$lib/sdk/billing';
import type { Tier } from '$lib/stores/billing';
import { sdk } from '$lib/stores/sdk';
import { isCloud } from '$lib/system';
import type { Models } from '@appwrite.io/console';
import type { LayoutLoad } from './$types';
export const load: LayoutLoad = async ({ fetch, depends, parent }) => {
@@ -22,13 +22,13 @@ export const load: LayoutLoad = async ({ fetch, depends, parent }) => {
const [data, variables] = await Promise.all([versionPromise, variablesPromise]);
let plansInfo = new Map<Tier, Plan>();
let plansInfo = new Map<Tier, Models.BillingPlan>();
if (isCloud) {
const plansArray = await sdk.forConsole.billing.getPlansInfo();
plansInfo = plansArray.plans.reduce((map, plan) => {
map.set(plan.$id as Tier, plan);
return map;
}, new Map<Tier, Plan>());
}, new Map<Tier, Models.BillingPlan>());
}
return {
@@ -12,7 +12,6 @@
WizardSecondaryContent,
WizardSecondaryFooter
} from '$lib/layout';
import { type Plan } from '$lib/sdk/billing';
import { app } from '$lib/stores/app';
import { isOrganization } from '$lib/stores/billing.js';
import { addNotification } from '$lib/stores/notifications';
@@ -72,7 +71,7 @@
let couponData = data?.couponData;
let campaign = data?.campaign;
let billingPlan = BillingPlan.PRO;
let currentPlan: Plan;
let currentPlan: Models.BillingPlan;
function isUpgrade() {
const newPlan = $page.data.plansInfo.get(billingPlan);
@@ -1,12 +1,12 @@
import ProjectsAtRisk from '$lib/components/billing/alerts/projectsAtRisk.svelte';
import { defaultRoles, defaultScopes, Dependencies } from '$lib/constants';
import type { Plan } from '$lib/sdk/billing';
import { failedInvoice } from '$lib/stores/billing';
import { headerAlert } from '$lib/stores/headerAlert';
import type { Organization } from '$lib/stores/organization';
import { preferences } from '$lib/stores/preferences';
import { sdk } from '$lib/stores/sdk';
import { isCloud } from '$lib/system';
import type { Models } from '@appwrite.io/console';
import { error } from '@sveltejs/kit';
import { get } from 'svelte/store';
import type { LayoutLoad } from './$types';
@@ -19,7 +19,7 @@ export const load: LayoutLoad = async ({ params, depends }) => {
depends(Dependencies.PAYMENT_METHODS);
let roles = isCloud ? [] : defaultRoles;
let scopes = isCloud ? [] : defaultScopes;
let currentPlan: Plan = null;
let currentPlan: Models.BillingPlan | null = null;
try {
if (isCloud) {
@@ -8,13 +8,12 @@
import { toLocaleDate } from '$lib/helpers/date';
import { abbreviateNumber, formatCurrency, formatNumberWithCommas } from '$lib/helpers/numbers';
import { humanFileSize } from '$lib/helpers/sizeConvertion';
import type { Plan } from '$lib/sdk/billing';
import { plansInfo, upgradeURL } from '$lib/stores/billing';
import { organization } from '$lib/stores/organization';
import type { Models } from '@appwrite.io/console';
import CancelDowngradeModel from './cancelDowngradeModal.svelte';
export let currentPlan: Plan;
export let currentPlan: Models.BillingPlan;
export let creditList: Models.CreditList;
export let currentInvoice: Models.Invoice | undefined = undefined;
export let currentAggregation: Models.AggregationTeam | undefined = undefined;
@@ -1,19 +1,19 @@
import PaymentFailed from '$lib/components/billing/alerts/paymentFailed.svelte';
import { defaultRoles, defaultScopes, Dependencies } from '$lib/constants';
import type { Plan } from '$lib/sdk/billing';
import { failedInvoice } from '$lib/stores/billing';
import { headerAlert } from '$lib/stores/headerAlert';
import type { Organization } from '$lib/stores/organization';
import { preferences } from '$lib/stores/preferences';
import { sdk } from '$lib/stores/sdk';
import { isCloud } from '$lib/system';
import type { Models } from '@appwrite.io/console';
import { error } from '@sveltejs/kit';
import { get } from 'svelte/store';
import type { LayoutLoad } from './$types';
export const load: LayoutLoad = async ({ params, depends }) => {
depends(Dependencies.PROJECT);
let currentPlan: Plan = null;
let currentPlan: Models.BillingPlan | null = null;
try {
const project = await sdk.forConsole.projects.get(params.project);
@@ -1,7 +1,6 @@
import { CARD_LIMIT, Dependencies } from '$lib/constants';
import { timeFromNow } from '$lib/helpers/date';
import { getLimit, getPage, getView, pageToOffset, View } from '$lib/helpers/load';
import type { Plan } from '$lib/sdk/billing';
import { sdk } from '$lib/stores/sdk';
import { isCloud } from '$lib/system';
import { type Models, Query } from '@appwrite.io/console';
@@ -35,7 +34,11 @@ export const load: PageLoad = async ({ url, route, depends, parent }) => {
};
// TODO: @itznotabug we should improve this!
async function fetchDatabasesAndBackups(limit: number, offset: number, currentPlan?: Plan) {
async function fetchDatabasesAndBackups(
limit: number,
offset: number,
currentPlan?: Models.BillingPlan
) {
const backupsEnabled = currentPlan?.backupsEnabled ?? true;
const databases = await sdk.forProject.databases.list([
@@ -172,9 +172,9 @@
id={`${rowIndex}-key`}
isMultiple
fullWidth
bind:value={$messageParams[MessagingProviderType.Push].data[
rowIndex
][0]}
bind:value={
$messageParams[MessagingProviderType.Push].data[rowIndex][0]
}
placeholder="Enter key"
label="Key"
showLabel={false} />
@@ -183,9 +183,9 @@
id={`${rowIndex}-value`}
isMultiple
fullWidth
bind:value={$messageParams[MessagingProviderType.Push].data[
rowIndex
][1]}
bind:value={
$messageParams[MessagingProviderType.Push].data[rowIndex][1]
}
placeholder="Enter value"
label="Value"
showLabel={false}
@@ -8,10 +8,11 @@
import { readOnly, upgradeURL } from '$lib/stores/billing';
import { organization } from '$lib/stores/organization';
import { GRACE_PERIOD_OVERRIDE, isCloud } from '$lib/system';
import type { Models } from '@appwrite.io/console';
import { bucket } from '../store';
import { updateBucket } from './+page.svelte';
import type { Plan } from '$lib/sdk/billing';
export let currentPlan: Plan;
export let currentPlan: Models.BillingPlan;
const service = currentPlan['fileSize'];
const { value, unit, baseValue, units } = createByteUnitPair($bucket.maximumFileSize, 1000);