Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/lib/components/backupRestoreBox.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
import { realtime } from '$lib/stores/sdk';
import { type Payload } from '@appwrite.io/console';
import { onMount } from 'svelte';
import { isCloud, isSelfHosted } from '$lib/system';
import { isSelfHosted } from '$lib/system';
import { organization } from '$lib/stores/organization';
import { isBillingEnabled } from '$lib/profiles/index.svelte';
import { Dependencies } from '$lib/constants';
import type { BackupArchive, BackupRestoration } from '$lib/sdk/backups';
import { goto, invalidate } from '$app/navigation';
Expand Down Expand Up @@ -126,7 +127,7 @@

onMount(() => {
// fast path: don't subscribe if org is on a free plan or is self-hosted.
if (isSelfHosted || (isCloud && isFreePlan($organization?.billingPlan))) return;
if (isSelfHosted || (isBillingEnabled && isFreePlan($organization?.billingPlan))) return;

return realtime.forProject(page.params.region, 'console', (response) => {
if (!response.channels.includes(`projects.${getProjectId()}`)) return;
Expand Down
4 changes: 2 additions & 2 deletions src/lib/components/cardContainer.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
import { page } from '$app/state';
import { Empty } from '$lib/components';
import { CARD_LIMIT } from '$lib/constants';
import { isCloud } from '$lib/system';
import CardPlanLimit from './cardPlanLimit.svelte';
import { preferences } from '$lib/stores/preferences';
import { isSmallViewport } from '$lib/stores/viewport';
import { getServiceLimit, type PlanServices } from '$lib/stores/billing';
import { isBillingEnabled } from '$lib/profiles/index.svelte';

export let disableEmpty = true;
export let offset = 0;
Expand All @@ -28,7 +28,7 @@
<slot />

{#if total > 3 ? total < limit + offset : total % 2 !== 0}
{#if isCloud && serviceId && total >= planLimit}
{#if isBillingEnabled && serviceId && total >= planLimit}
<CardPlanLimit {service} />
{:else}
<Empty on:click target={event} disabled={disableEmpty}>
Expand Down
7 changes: 3 additions & 4 deletions src/lib/components/navbar.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,13 @@
import { logout } from '$lib/helpers/logout';
import { app } from '$lib/stores/app';
import { isTabletViewport, isSmallViewport } from '$lib/stores/viewport';
import { isCloud } from '$lib/system.js';
import { user } from '$lib/stores/user';
import { Click, trackEvent } from '$lib/actions/analytics';
import { beforeNavigate } from '$app/navigation';
import { page } from '$app/state';
import type { Models } from '@appwrite.io/console';
import { organization } from '$lib/stores/organization';
import { resolvedProfile } from '$lib/profiles/index.svelte';
import { isBillingEnabled, resolvedProfile } from '$lib/profiles/index.svelte';
import { headerAlert } from '$lib/stores/headerAlert';
import ProgressBar from './progressbar/ProgressBar.svelte';
import { resolve } from '$app/paths';
Expand Down Expand Up @@ -196,7 +195,7 @@
<div slot="right" class="only-desktop" style:--border-width-s="1px">
<div class="right">
<Layout.Stack gap="l" direction="row" alignItems="center">
{#if isCloud && currentOrg?.showUpgrade}
{#if isBillingEnabled && currentOrg?.showUpgrade}
<Button.Anchor
size="s"
variant="primary"
Expand Down Expand Up @@ -326,7 +325,7 @@
]} />

{#if dailyCredits !== null}
<Typography.Caption>
<Typography.Caption variant="400">
{dailyCredits} daily and {monthlyCredits} monthly
credits
</Typography.Caption>
Expand Down
4 changes: 2 additions & 2 deletions src/lib/elements/table/body.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { goto } from '$app/navigation';
import { Click, trackEvent } from '$lib/actions/analytics';
import { getServiceLimit, upgradeURL, type PlanServices } from '$lib/stores/billing';
import { isCloud } from '$lib/system';
import { isBillingEnabled } from '$lib/profiles/index.svelte';
import { Button } from '../forms';

let tableBody: HTMLDivElement;
Expand Down Expand Up @@ -31,7 +31,7 @@
<div class="table-tbody" role="rowgroup" bind:this={tableBody}>
<slot />
</div>
{#if isCloud && limitReached && service}
{#if isBillingEnabled && limitReached && service}
<tr class="table-row">
<td class="table-col" width="100%" colspan={columns}>
<span class="u-flex u-gap-24 u-main-center u-cross-center">
Expand Down
9 changes: 5 additions & 4 deletions src/lib/layout/containerHeader.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@
type PlanServices
} from '$lib/stores/billing';
import { organization } from '$lib/stores/organization';
import { GRACE_PERIOD_OVERRIDE, isCloud } from '$lib/system';
import { GRACE_PERIOD_OVERRIDE } from '$lib/system';
import { createEventDispatcher, onMount } from 'svelte';
import { isBillingEnabled } from '$lib/profiles/index.svelte';
import { ContainerButton } from '.';
import { goto } from '$app/navigation';
import { Layout, Typography } from '@appwrite.io/pink-svelte';
Expand Down Expand Up @@ -89,8 +90,8 @@
$: if (isLimited) dispatch('data', { isButtonDisabled, limit, tier });
</script>

<!-- Show only if on Cloud, alerts are enabled, and it isn't a project limited service -->
{#if isCloud && showAlert}
<!-- Show only if billing is enabled, alerts are enabled, and it isn't a project limited service -->
{#if isBillingEnabled && showAlert}
<!-- some services are above limit -->
{@const services = overflowingServices
.map((s) => {
Expand Down Expand Up @@ -127,7 +128,7 @@
<Layout.Stack direction="row" alignContent="center">
<Layout.Stack direction="row">
<Typography.Title size="m">{title}</Typography.Title>
{#if isCloud && isLimited}
{#if isBillingEnabled && isLimited}
<DropList bind:show={showDropdown} width="16">
{#if hasProjectLimitation}
<Badge
Expand Down
15 changes: 9 additions & 6 deletions src/lib/layout/shell.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,14 @@
import { sdk } from '$lib/stores/sdk';
import { user } from '$lib/stores/user';
import { tierToPlan } from '$lib/stores/billing';
import { isCloud } from '$lib/system';
import SideNavigation from '$lib/layout/navigation.svelte';
import { hasOnboardingDismissed } from '$lib/helpers/onboarding';
import { isSidebarOpen, noWidthTransition } from '$lib/stores/sidebar';
import { page } from '$app/stores';
import type { Models } from '@appwrite.io/console';
import { getSidebarState, isInDatabasesRoute, updateSidebarState } from '$lib/helpers/sidebar';
import { isTabletViewport } from '$lib/stores/viewport';
import { ProfileMode, resolvedProfile } from '$lib/profiles/index.svelte';
import { isBillingEnabled, ProfileMode, resolvedProfile } from '$lib/profiles/index.svelte';
import { app } from '$lib/stores/app';
import { isFreePlan } from '$lib/helpers/billing';

Expand Down Expand Up @@ -161,10 +160,14 @@
$id: org.$id,
name: org.name,
isSelected: $organization?.$id === org.$id,
showUpgrade: isCloud ? isFreePlan(billingPlan) : false,
tierName: isCloud ? tierToPlan(billingPlan).name : null,
billingNextInvoiceDate: isCloud ? org['billingNextInvoiceDate'] : undefined,
billingCurrentInvoiceDate: isCloud ? org['billingCurrentInvoiceDate'] : undefined
showUpgrade: isBillingEnabled ? isFreePlan(billingPlan) : false,
tierName: isBillingEnabled ? tierToPlan(billingPlan).name : null,
billingNextInvoiceDate: isBillingEnabled
? org['billingNextInvoiceDate']
: undefined,
billingCurrentInvoiceDate: isBillingEnabled
? org['billingCurrentInvoiceDate']
: undefined
};
}),

Expand Down
5 changes: 5 additions & 0 deletions src/lib/profiles/index.svelte.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export type Profile = {
showConnectProjectOnToolbar: boolean;
showProgressBar: boolean;
showCreateOrganization: boolean;
billing: boolean;
services: {
'get-started': boolean;
overview: boolean;
Expand Down Expand Up @@ -109,6 +110,7 @@ export const base: Profile = {
showConnectProjectOnToolbar: true,
showProgressBar: true,
showCreateOrganization: true,
billing: true,
services: {
'get-started': true,
overview: true,
Expand Down Expand Up @@ -205,6 +207,7 @@ export const studio: Profile = {
showConnectProjectOnToolbar: false,
showProgressBar: false,
showCreateOrganization: false,
billing: false,
services: {
'get-started': false,
overview: false,
Expand Down Expand Up @@ -254,3 +257,5 @@ export const studio: Profile = {
};

export const resolvedProfile = env.PUBLIC_CONSOLE_PROFILE === 'studio' ? studio : base;

export const isBillingEnabled = isCloud && resolvedProfile.billing;
8 changes: 4 additions & 4 deletions src/lib/stores/billing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import type {
Plan,
PlansMap
} from '$lib/sdk/billing';
import { isCloud } from '$lib/system';
import { isBillingEnabled } from '$lib/profiles/index.svelte';
import { activeHeaderAlert, orgMissingPaymentMethod } from '$routes/(console)/store';
import { AppwriteException, Query } from '@appwrite.io/console';
import { derived, get, writable } from 'svelte/store';
Expand Down Expand Up @@ -159,7 +159,7 @@ export function getServiceLimit(
tier: Tier | CloudSdkBillingPlan = null,
plan?: Plan
): number {
if (!isCloud) return 0;
if (!isBillingEnabled) return 0;
if (!serviceId) return 0;

plan ??= get(currentPlan);
Expand Down Expand Up @@ -191,7 +191,7 @@ export const failedInvoice = cachedStore<
>('failedInvoice', function ({ set }) {
return {
load: async (orgId) => {
if (!isCloud) set(null);
if (!isBillingEnabled) set(null);
if (!get(canSeeBilling)) set(null);
const failedInvoices = await sdk.forConsole.billing.listInvoices(orgId, [
Query.equal('status', 'failed')
Expand Down Expand Up @@ -314,7 +314,7 @@ export function calculateTrialDay(org: Organization) {
}

export async function checkForProjectsLimit(org: Organization, orgProjectCount?: number) {
if (!isCloud) return;
if (!isBillingEnabled) return;
if (!org) return;

const plan = await sdk.forConsole.billing.getOrganizationPlan(org.$id);
Expand Down
5 changes: 2 additions & 3 deletions src/routes/(console)/+layout.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { sdk } from '$lib/stores/sdk';
import { isCloud } from '$lib/system';
import type { LayoutLoad } from './$types';
import { Query } from '@appwrite.io/console';
import type { Tier } from '$lib/stores/billing';
import type { Plan, PlanList } from '$lib/sdk/billing';
import { Dependencies } from '$lib/constants';
import { resolvedProfile } from '$lib/profiles/index.svelte';
import { isBillingEnabled, resolvedProfile } from '$lib/profiles/index.svelte';

export const load: LayoutLoad = async ({ depends, parent }) => {
const { organizations } = await parent();
Expand All @@ -17,7 +16,7 @@ export const load: LayoutLoad = async ({ depends, parent }) => {
const { endpoint, project } = sdk.forConsole.client.config;
const [preferences, plansArray, versionData, consoleVariables] = await Promise.all([
sdk.forConsole.account.getPrefs(),
isCloud ? sdk.forConsole.billing.listPlans() : null,
isBillingEnabled ? sdk.forConsole.billing.listPlans() : null,
fetch(`${endpoint}/health/version`, {
headers: { 'X-Appwrite-Project': project }
}).then((response) => response.json() as { version?: string }),
Expand Down
3 changes: 2 additions & 1 deletion src/routes/(console)/account/organizations/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import { sdk } from '$lib/stores/sdk';
import type { PageData } from './$types';
import { isCloud } from '$lib/system';
import { isBillingEnabled } from '$lib/profiles/index.svelte';
import { Badge, Skeleton } from '@appwrite.io/pink-svelte';
import type { Models } from '@appwrite.io/console';
import type { Organization } from '$lib/stores/organization';
Expand Down Expand Up @@ -85,7 +86,7 @@
function isCloudOrg(
data: Partial<Models.TeamList<Models.Preferences>> | Organization
): data is Organization {
return isCloud && 'billingPlan' in data;
return isBillingEnabled && 'billingPlan' in data;
}

function createOrg() {
Expand Down
7 changes: 3 additions & 4 deletions src/routes/(console)/account/organizations/+page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ import { sdk } from '$lib/stores/sdk';
import { getLimit, getPage, pageToOffset } from '$lib/helpers/load';
import { CARD_LIMIT } from '$lib/constants';
import type { PageLoad } from './$types';
import { isCloud } from '$lib/system';
import { resolvedProfile } from '$lib/profiles/index.svelte';
import { isBillingEnabled, resolvedProfile } from '$lib/profiles/index.svelte';

export const load: PageLoad = async ({ url, route }) => {
const page = getPage(url);
Expand All @@ -15,10 +14,10 @@ export const load: PageLoad = async ({ url, route }) => {
Query.offset(offset),
Query.limit(limit),
Query.orderDesc(''),
...(isCloud ? [Query.equal('platform', resolvedProfile.organizationPlatform)] : [])
...(isBillingEnabled ? [Query.equal('platform', resolvedProfile.organizationPlatform)] : [])
];

const organizations = !isCloud
const organizations = !isBillingEnabled
? await sdk.forConsole.teams.list({ queries })
: await sdk.forConsole.billing.listOrganization(queries);

Expand Down
8 changes: 4 additions & 4 deletions src/routes/(console)/organization-[organization]/+layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { defaultRoles, defaultScopes } from '$lib/constants';
import type { Plan } from '$lib/sdk/billing';
import { loadAvailableRegions } from '$routes/(console)/regions';
import type { Organization } from '$lib/stores/organization';
import { resolvedProfile } from '$lib/profiles/index.svelte';
import { isBillingEnabled, resolvedProfile } from '$lib/profiles/index.svelte';
import { resolve } from '$app/paths';

export const load: LayoutLoad = async ({ params, depends, parent }) => {
Expand All @@ -26,12 +26,12 @@ export const load: LayoutLoad = async ({ params, depends, parent }) => {

const requestedOrg = await checkPlatformAndRedirect(params, organizations, prefs);

let roles = isCloud ? [] : defaultRoles;
let scopes = isCloud ? [] : defaultScopes;
let roles = isBillingEnabled ? [] : defaultRoles;
let scopes = isBillingEnabled ? [] : defaultScopes;
let currentPlan: Plan = null;

try {
if (isCloud) {
if (isBillingEnabled) {
[{ roles, scopes }, currentPlan] = await Promise.all([
sdk.forConsole.billing.getRoles(params.organization),
sdk.forConsole.billing.getOrganizationPlan(params.organization)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { type Organization } from '$lib/stores/organization';
import { sdk } from '$lib/stores/sdk';
import { redirect } from '@sveltejs/kit';
import type { PageLoad } from './$types';
import { isCloud } from '$lib/system';
import { isBillingEnabled } from '$lib/profiles/index.svelte';
import { base } from '$app/paths';
import { isFreePlan } from '$lib/helpers/billing';

Expand Down Expand Up @@ -62,7 +62,7 @@ export const load: PageLoad = async ({ parent, depends, url, route }) => {
// ignore error
}

const areCreditsSupported = isCloud
const areCreditsSupported = isBillingEnabled
? (currentPlan?.supportsCredits ??
(!isFreePlan(organization.billingPlan) &&
organization?.billingPlan !== BillingPlan.GITHUB_EDUCATION))
Expand Down
12 changes: 6 additions & 6 deletions src/routes/(console)/organization-[organization]/header.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
import { GRACE_PERIOD_OVERRIDE, isCloud } from '$lib/system';
import { IconGithub, IconPlus, IconPlusSm } from '@appwrite.io/pink-icons-svelte';
import { Badge, Icon, Layout, Tooltip, Typography } from '@appwrite.io/pink-svelte';
import { resolvedProfile } from '$lib/profiles/index.svelte';
import { isBillingEnabled, resolvedProfile } from '$lib/profiles/index.svelte';
import { isFreePlan } from '$lib/helpers/billing';

let areMembersLimited: boolean = $state(false);
Expand Down Expand Up @@ -75,7 +75,7 @@
title: 'Usage',
hasChildren: true,
disabled: !(
isCloud &&
isBillingEnabled &&
($isOwner || $isBilling) &&
!page.data.currentPlan?.usagePerProject
)
Expand All @@ -84,7 +84,7 @@
href: `${path}/billing`,
event: 'billing',
title: 'Billing',
disabled: !(isCloud && $canSeeBilling)
disabled: !(isBillingEnabled && $canSeeBilling)
},
{
href: `${path}/settings`,
Expand Down Expand Up @@ -119,15 +119,15 @@
</Typography.Title>

{#if !resolvedProfile.minimalOrgHeader}
{#if isCloud && organization?.billingPlan === BillingPlan.GITHUB_EDUCATION}
{#if isBillingEnabled && organization?.billingPlan === BillingPlan.GITHUB_EDUCATION}
<Badge variant="secondary" content="Education">
<Icon icon={IconGithub} size="s" slot="start" />
</Badge>
{:else if isCloud && isFreePlan(organization?.billingPlan)}
{:else if isBillingEnabled && isFreePlan(organization?.billingPlan)}
<Badge variant="secondary" content="Free"></Badge>
{/if}

{#if isCloud && organization?.billingTrialStartDate && $daysLeftInTrial > 0 && organization.billingPlan !== BillingPlan.FREE && $plansInfo.get(organization.billingPlan)?.trialDays}
{#if isBillingEnabled && organization?.billingTrialStartDate && $daysLeftInTrial > 0 && organization.billingPlan !== BillingPlan.FREE && $plansInfo.get(organization.billingPlan)?.trialDays}
<Tooltip>
<Badge variant="secondary" content="Trial" />
<svelte:fragment slot="tooltip">
Expand Down
Loading
Loading