refactor: region models

This commit is contained in:
ChiragAgg5k
2025-03-06 16:09:44 +05:30
parent 4d721eccac
commit 4e753a2aa6
5 changed files with 16 additions and 48 deletions
+2 -32
View File
@@ -66,31 +66,6 @@ export type EstimationDeleteOrganization = {
unpaidInvoices: Invoice[];
};
export type AllowedRegions =
| 'fra'
| 'nyc'
| 'sfo'
| 'blr'
| 'lon'
| 'ams'
| 'sgp'
| 'tor'
| 'syd'
| 'default'; //TODO: remove after migration
export type Region = {
$id: AllowedRegions;
name: string;
disabled: boolean;
default: boolean;
flag: string;
};
export type RegionList = {
regions: Region[];
total: number;
};
export type Address = {
$id: string;
streetAddress: string;
@@ -176,11 +151,6 @@ export type PlanList = {
export type PlansMap = Map<Tier, Plan>;
export type Roles = {
scopes: string[];
roles: string[];
};
export class Billing {
client: Client;
@@ -319,7 +289,7 @@ export class Billing {
});
}
async getRoles(organizationId: string): Promise<Roles> {
async getRoles(organizationId: string): Promise<Models.Roles> {
const path = `/organizations/${organizationId}/roles`;
const uri = new URL(this.client.config.endpoint + path);
return await this.client.call('get', uri, {
@@ -1088,7 +1058,7 @@ export class Billing {
);
}
async listRegions(): Promise<RegionList> {
async listRegions(): Promise<Models.ConsoleRegionList> {
const path = `/console/regions`;
const params = {};
const uri = new URL(this.client.config.endpoint + path);
+3 -3
View File
@@ -1,8 +1,8 @@
import { page } from '$app/stores';
import { derived, writable } from 'svelte/store';
import type { Models } from '@appwrite.io/console';
import type { Tier } from './billing';
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';
export type OrganizationError = {
status: number;
@@ -1,10 +1,9 @@
import { page } from '$app/stores';
import { sdk } from '$lib/stores/sdk';
import type { Models } from '@appwrite.io/console';
import { derived, writable } from 'svelte/store';
import type { RegionList } from '$lib/sdk/billing';
import { sdk } from '$lib/stores/sdk';
export const regions = writable<RegionList | undefined>(undefined);
export const regions = writable<Models.ConsoleRegionList | undefined>(undefined);
export const regionFlagUrls = derived(regions, ($regions) => {
if (!$regions?.regions?.length) return [];
@@ -1,15 +1,14 @@
<script lang="ts">
import { page } from '$app/stores';
import { RegionCard } from '$lib/components';
import { Flag, Pill } from '$lib/elements';
import { WizardStep } from '$lib/layout';
import { addNotification } from '$lib/stores/notifications';
import { sdk } from '$lib/stores/sdk';
import { regions } from '$routes/(console)/organization-[organization]/store';
import type { Models } from '@appwrite.io/console';
import { onMount } from 'svelte';
import { createProject } from './store';
import type { Region } from '$lib/sdk/billing';
import { addNotification } from '$lib/stores/notifications';
import type { Models } from '@appwrite.io/console';
import { page } from '$app/stores';
import { regions } from '$routes/(console)/organization-[organization]/store';
let prefs: Models.Preferences;
@@ -17,7 +16,7 @@
prefs = $page.data.account.prefs;
});
async function notifyRegion(selectedRegion: Region) {
async function notifyRegion(selectedRegion: Models.ConsoleRegion) {
try {
let newPrefs = { ...prefs };
newPrefs.notifications ??= [];
@@ -36,7 +35,7 @@
});
}
}
async function unNotifyRegion(selectedRegion: Region) {
async function unNotifyRegion(selectedRegion: Models.ConsoleRegion) {
try {
let newPrefs = { ...prefs };
newPrefs.notifications = newPrefs.notifications ?? [];
@@ -1,21 +1,21 @@
<script lang="ts">
import { goto } from '$app/navigation';
import { base } from '$app/paths';
import { Submit, trackEvent, trackError } from '$lib/actions/analytics';
import { Submit, trackError, trackEvent } from '$lib/actions/analytics';
import { BoxAvatar, CardGrid, Heading, Modal } from '$lib/components';
import { Button, FormList, InputText } from '$lib/elements/forms';
import { toLocaleDateTime } from '$lib/helpers/date';
import { addNotification } from '$lib/stores/notifications';
import { sdk } from '$lib/stores/sdk';
import { isCloud } from '$lib/system';
import type { Models } from '@appwrite.io/console';
import { onMount } from 'svelte';
import { project } from '../store';
import type { RegionList } from '$lib/sdk/billing';
let showDelete = false;
let name: string = null;
let regions: RegionList;
let regions: Models.ConsoleRegionList;
onMount(async () => {
if (isCloud) {
regions = await sdk.forConsole.billing.listRegions();