add: region based console variables on functions.

This commit is contained in:
Darshan committed 2025-05-29 15:19:45 +05:30
1 parent 72fe3ed06f
commit a40d0cc081
9 files changed
+63 -35

No files matched your search

+35 -17
View File
@@ -64,14 +64,39 @@ const getSubdomain = (region?: string) => {
}
};
function createConsoleSdk(client: Client) {
return {
client,
account: new Account(client),
avatars: new Avatars(client),
functions: new Functions(client),
health: new Health(client),
locale: new Locale(client),
projects: new Projects(client),
teams: new Teams(client),
users: new Users(client),
migrations: new Migrations(client),
console: new Console(client),
assistant: new Assistant(client),
billing: new Billing(client),
sources: new Sources(client),
sites: new Sites(client),
domains: new Domains(client)
};
}
const endpoint = getApiEndpoint();
const clientConsole = new Client();
const scopedConsoleClient = new Client();
const clientProject = new Client();
const clientRealtime = new Client();
if (!building) {
clientConsole.setEndpoint(endpoint).setProject('console');
scopedConsoleClient.setMode(endpoint).setProject('console');
clientRealtime.setEndpoint(endpoint).setProject('console');
clientProject.setEndpoint(endpoint).setMode('admin');
clientRealtime.setEndpoint(endpoint).setProject('console');
@@ -110,24 +135,17 @@ export const realtime = {
};
export const sdk = {
forConsole: {
client: clientConsole,
account: new Account(clientConsole),
avatars: new Avatars(clientConsole),
functions: new Functions(clientConsole),
health: new Health(clientConsole),
locale: new Locale(clientConsole),
projects: new Projects(clientConsole),
teams: new Teams(clientConsole),
users: new Users(clientConsole),
migrations: new Migrations(clientConsole),
console: new Console(clientConsole),
assistant: new Assistant(clientConsole),
billing: new Billing(clientConsole),
sources: new Sources(clientConsole),
sites: new Sites(clientConsole),
domains: new Domains(clientConsole)
forConsole: createConsoleSdk(clientConsole),
forScopedConsole(region: string) {
const regionAwareEndpoint = getApiEndpoint(region);
if (regionAwareEndpoint !== scopedConsoleClient.config.endpoint) {
scopedConsoleClient.setEndpoint(regionAwareEndpoint);
}
return createConsoleSdk(scopedConsoleClient);
},
forProject(region: string, projectId: string) {
const endpoint = getApiEndpoint(region);
if (endpoint !== clientProject.config.endpoint) {
@@ -19,9 +19,10 @@ export const load: LayoutLoad = async ({ params, depends }) => {
try {
const project = await sdk.forConsole.projects.get(params.project);
const [organization, prefs, _] = await Promise.all([
const [organization, prefs, regionalConsoleVariables, _] = await Promise.all([
sdk.forConsole.teams.get(project.teamId) as Promise<Organization>,
sdk.forConsole.account.getPrefs(),
sdk.forScopedConsole(project.region).console.variables(),
loadAvailableRegions(project.teamId)
]);
if (prefs?.organization !== project.teamId) {
@@ -54,6 +55,7 @@ export const load: LayoutLoad = async ({ params, depends }) => {
return {
project,
organization,
regionalConsoleVariables,
roles,
scopes,
currentPlan
@@ -5,7 +5,6 @@
import { Click, trackEvent } from '$lib/actions/analytics';
import type { Models } from '@appwrite.io/console';
import { isSelfHosted } from '$lib/system';
import { consoleVariables } from '$routes/(console)/store';
import { afterNavigate, goto } from '$app/navigation';
import { installation, repository } from '$lib/stores/vcs';
import { Repositories } from '$lib/components/git';
@@ -23,10 +22,11 @@
import Wizard from '$lib/layout/wizard.svelte';
import { Link } from '$lib/elements';
import { Button } from '$lib/elements/forms';
import { regionalConsoleVariables } from '../../store';
export let data;
const isVcsEnabled = $consoleVariables?._APP_VCS_ENABLED === true;
const isVcsEnabled = $regionalConsoleVariables?._APP_VCS_ENABLED === true;
const wizardBase = `${base}/project-${page.params.region}-${page.params.project}/functions`;
let previousPage: string = wizardBase;
afterNavigate(({ from }) => {
@@ -11,7 +11,6 @@
import { writable } from 'svelte/store';
import { ID, Runtime } from '@appwrite.io/console';
import type { Models } from '@appwrite.io/console';
import { consoleVariables } from '$routes/(console)/store';
import Details from '../(components)/details.svelte';
import Aside from '../(components)/aside.svelte';
import { iconPath } from '$lib/stores/app';
@@ -20,6 +19,7 @@
import Configuration from './configuration.svelte';
import { getIconFromRuntime } from '$lib/stores/runtimes';
import { removeFile } from '$lib/helpers/files';
import { regionalConsoleVariables } from '../../../store';
export let data;
@@ -82,7 +82,7 @@
await sdk
.forProject(page.params.region, page.params.project)
.proxy.createFunctionRule(
`${ID.unique()}.${$consoleVariables._APP_DOMAIN_FUNCTIONS}`,
`${ID.unique()}.${$regionalConsoleVariables._APP_DOMAIN_FUNCTIONS}`,
func.$id
);
@@ -13,7 +13,6 @@
import { ID, Runtime, VCSDeploymentType } from '@appwrite.io/console';
import type { Models } from '@appwrite.io/console';
import { onMount } from 'svelte';
import { consoleVariables } from '$routes/(console)/store';
import Details from '../(components)/details.svelte';
import ProductionBranchFieldset from '$lib/components/git/productionBranchFieldset.svelte';
import Configuration from './configuration.svelte';
@@ -22,6 +21,7 @@
import { Dependencies } from '$lib/constants';
import RepoCard from './repoCard.svelte';
import { getIconFromRuntime } from '$lib/stores/runtimes';
import { regionalConsoleVariables } from '$routes/(console)/project-[region]-[project]/store';
export let data;
@@ -92,7 +92,7 @@
await sdk
.forProject(page.params.region, page.params.project)
.proxy.createFunctionRule(
`${ID.unique()}.${$consoleVariables._APP_DOMAIN_FUNCTIONS}`,
`${ID.unique()}.${$regionalConsoleVariables._APP_DOMAIN_FUNCTIONS}`,
func.$id
);
@@ -22,7 +22,6 @@
Repositories,
RepositoryBehaviour
} from '$lib/components/git';
import { consoleVariables } from '$routes/(console)/store';
import Details from '../(components)/details.svelte';
import Aside from '../(components)/aside.svelte';
import { iconPath } from '$lib/stores/app';
@@ -31,6 +30,7 @@
import RepoCard from './repoCard.svelte';
import { Dependencies } from '$lib/constants';
import { getIconFromRuntime } from '$lib/stores/runtimes';
import { regionalConsoleVariables } from '$routes/(console)/project-[region]-[project]/store';
export let data;
@@ -148,7 +148,7 @@
await sdk
.forProject(page.params.region, page.params.project)
.proxy.createFunctionRule(
`${ID.unique()}.${$consoleVariables._APP_DOMAIN_FUNCTIONS}`,
`${ID.unique()}.${$regionalConsoleVariables._APP_DOMAIN_FUNCTIONS}`,
func.$id
);
@@ -20,9 +20,9 @@
import Wizard from '$lib/layout/wizard.svelte';
import { base } from '$app/paths';
import { writable } from 'svelte/store';
import { consoleVariables } from '$routes/(console)/store';
import NameserverTable from '$lib/components/domains/nameserverTable.svelte';
import RecordTable from '$lib/components/domains/recordTable.svelte';
import { regionalConsoleVariables } from '$routes/(console)/project-[region]-[project]/store';
let { data } = $props();
@@ -31,11 +31,11 @@
let selectedTab = $state<'cname' | 'nameserver' | 'a' | 'aaaa'>('nameserver');
$effect(() => {
if ($consoleVariables._APP_DOMAIN_TARGET_CNAME && isSubDomain) {
if ($regionalConsoleVariables._APP_DOMAIN_TARGET_CNAME && isSubDomain) {
selectedTab = 'cname';
} else if ($consoleVariables._APP_DOMAIN_TARGET_A) {
} else if ($regionalConsoleVariables._APP_DOMAIN_TARGET_A) {
selectedTab = 'a';
} else if ($consoleVariables._APP_DOMAIN_TARGET_AAAA) {
} else if ($regionalConsoleVariables._APP_DOMAIN_TARGET_AAAA) {
selectedTab = 'aaaa';
}
});
@@ -110,7 +110,7 @@
<Layout.Stack gap="xl">
<div>
<Tabs.Root variant="secondary" let:root>
{#if isSubDomain && !!$consoleVariables._APP_DOMAIN_TARGET_CNAME && $consoleVariables._APP_DOMAIN_TARGET_CNAME !== 'localhost'}
{#if isSubDomain && !!$regionalConsoleVariables._APP_DOMAIN_TARGET_CNAME && $regionalConsoleVariables._APP_DOMAIN_TARGET_CNAME !== 'localhost'}
<Tabs.Item.Button
{root}
on:click={() => (selectedTab = 'cname')}
@@ -126,7 +126,7 @@
Nameservers
</Tabs.Item.Button>
{/if}
{#if !!$consoleVariables._APP_DOMAIN_TARGET_A && $consoleVariables._APP_DOMAIN_TARGET_A !== '127.0.0.1'}
{#if !!$regionalConsoleVariables._APP_DOMAIN_TARGET_A && $regionalConsoleVariables._APP_DOMAIN_TARGET_A !== '127.0.0.1'}
<Tabs.Item.Button
{root}
on:click={() => (selectedTab = 'a')}
@@ -134,7 +134,7 @@
A
</Tabs.Item.Button>
{/if}
{#if !!$consoleVariables._APP_DOMAIN_TARGET_AAAA && $consoleVariables._APP_DOMAIN_TARGET_AAAA !== '::1'}
{#if !!$regionalConsoleVariables._APP_DOMAIN_TARGET_AAAA && $regionalConsoleVariables._APP_DOMAIN_TARGET_AAAA !== '::1'}
<Tabs.Item.Button
{root}
on:click={() => (selectedTab = 'aaaa')}
@@ -12,7 +12,7 @@
InteractiveText
} from '@appwrite.io/pink-svelte';
import type { Models } from '@appwrite.io/console';
import { consoleVariables } from '$routes/(console)/store';
import { regionalConsoleVariables } from '$routes/(console)/project-[region]-[project]/store';
export let domain: Domain | Models.ProxyRule;
</script>
@@ -44,7 +44,7 @@
<InteractiveText
variant="copy"
isVisible
text={$consoleVariables._APP_DOMAIN_TARGET_CNAME} />
text={$regionalConsoleVariables._APP_DOMAIN_TARGET_CNAME} />
</Table.Cell>
</Table.Row.Base>
</Table.Root>
@@ -25,6 +25,14 @@ export const onboarding = derived(
($project) => $project?.platforms?.length === 0 && $project?.keys?.length === 0
);
/**
* Same as the `consoleVariables` but from project's respective region!
*/
export const regionalConsoleVariables = derived(
page,
($page) => $page.data.scopedConsoleVariables as Models.ConsoleVariables
);
function createStats() {
const { subscribe, set, update } = writable<Map<string, BarSeriesOption['data']>>(new Map());