Skip to content

feat: use console sdk with cloud services #1410

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
.DS_Store
.envrc
.vscode
.zed
node_modules
/build
/.svelte-kit
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -19,7 +19,7 @@
"e2e:ui": "playwright test tests/e2e --ui"
},
"dependencies": {
"@appwrite.io/console": "^1.3.2",
"@appwrite.io/console": "^1.4.0",
"@appwrite.io/pink": "0.25.0",
"@appwrite.io/pink-icons": "0.25.0",
"@popperjs/core": "^2.11.8",
10 changes: 5 additions & 5 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/lib/components/backupDatabaseAlert.svelte
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<script lang="ts">
import { page } from '$app/stores';
import { BillingPlan } from '$lib/constants';
import { Button } from '$lib/elements/forms';
import { organization } from '$lib/stores/organization';
import { HeaderAlert } from '$lib/layout';
import { isCloud } from '$lib/system';
import { upgradeURL } from '$lib/stores/billing';
import { hideNotification } from '$lib/helpers/notifications';
import { backupsBannerId, showPolicyAlert } from '$lib/stores/database';
import { BillingPlan } from '@appwrite.io/console';

function handleClose() {
showPolicyAlert.set(false);
@@ -16,7 +16,7 @@
</script>

{#if $showPolicyAlert && isCloud && $organization?.$id && $page.url.pathname.match(/\/databases\/database-[^/]+$/)}
{@const isFreePlan = $organization?.billingPlan === BillingPlan.FREE}
{@const isFreePlan = $organization?.billingPlan === BillingPlan.Tier0}

{@const subtitle = isFreePlan
? 'Upgrade your plan to ensure your data stays safe and backed up'
6 changes: 3 additions & 3 deletions src/lib/components/backupRestoreBox.svelte
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<script lang="ts">
import { sdk } from '$lib/stores/sdk';
import { type Payload, Query } from '@appwrite.io/console';
import { BillingPlan, type Payload, Query } from '@appwrite.io/console';
import { onMount } from 'svelte';
import { isCloud, isSelfHosted } from '$lib/system';
import { organization } from '$lib/stores/organization';
import { BillingPlan, Dependencies } from '$lib/constants';
import { Dependencies } from '$lib/constants';
import type { BackupArchive, BackupRestoration } from '$lib/sdk/backups';
import { goto, invalidate } from '$app/navigation';
import { page } from '$app/stores';
@@ -153,7 +153,7 @@

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

sdk.forConsole.client.subscribe('console', (response) => {
// nice!
4 changes: 2 additions & 2 deletions src/lib/components/billing/alerts/limitReached.svelte
Original file line number Diff line number Diff line change
@@ -2,14 +2,14 @@
import { base } from '$app/paths';
import { page } from '$app/stores';
import { trackEvent } from '$lib/actions/analytics';
import { BillingPlan } from '$lib/constants';
import { BillingPlan } from '@appwrite.io/console';
import { Button } from '$lib/elements/forms';
import { HeaderAlert } from '$lib/layout';
import { hideBillingHeaderRoutes, readOnly, tierToPlan, upgradeURL } from '$lib/stores/billing';
import { organization } from '$lib/stores/organization';
</script>

{#if $organization?.$id && $organization?.billingPlan === BillingPlan.FREE && $readOnly && !hideBillingHeaderRoutes.includes($page.url.pathname)}
{#if $organization?.$id && $organization?.billingPlan === BillingPlan.Tier0 && $readOnly && !hideBillingHeaderRoutes.includes($page.url.pathname)}
<HeaderAlert
type="error"
title={`${$organization.name} usage has reached the ${tierToPlan($organization.billingPlan).name} plan limit`}>
4 changes: 2 additions & 2 deletions src/lib/components/billing/alerts/missingPaymentMethod.svelte
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<script lang="ts">
import { base } from '$app/paths';
import { page } from '$app/stores';
import { BillingPlan } from '$lib/constants';
import { BillingPlan } from '@appwrite.io/console';
import { Button } from '$lib/elements/forms';
import { HeaderAlert } from '$lib/layout';
import { hideBillingHeaderRoutes } from '$lib/stores/billing';
import { orgMissingPaymentMethod } from '$routes/(console)/store';
</script>

{#if ($orgMissingPaymentMethod.billingPlan === BillingPlan.PRO || $orgMissingPaymentMethod.billingPlan === BillingPlan.SCALE) && !$orgMissingPaymentMethod.paymentMethodId && !$orgMissingPaymentMethod.backupPaymentMethodId && !hideBillingHeaderRoutes.includes($page.url.pathname)}
{#if ($orgMissingPaymentMethod.billingPlan === BillingPlan.Tier1 || $orgMissingPaymentMethod.billingPlan === BillingPlan.Tier2) && !$orgMissingPaymentMethod.paymentMethodId && !$orgMissingPaymentMethod.backupPaymentMethodId && !hideBillingHeaderRoutes.includes($page.url.pathname)}
<HeaderAlert
type="error"
title={`Payment method required for ${$orgMissingPaymentMethod.name}`}>
4 changes: 2 additions & 2 deletions src/lib/components/billing/alerts/newDevUpgradePro.svelte
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@
import { base } from '$app/paths';
import { page } from '$app/stores';
import { trackEvent } from '$lib/actions/analytics';
import { BillingPlan } from '$lib/constants';
import { BillingPlan } from '@appwrite.io/console';
import { Button } from '$lib/elements/forms';
import { organization } from '$lib/stores/organization';
import { activeHeaderAlert } from '$routes/(console)/store';
@@ -21,7 +21,7 @@
}
</script>

{#if show && $organization?.$id && $organization?.billingPlan === BillingPlan.FREE && !$page.url.pathname.includes('/console/account')}
{#if show && $organization?.$id && $organization?.billingPlan === BillingPlan.Tier0 && !$page.url.pathname.includes('/console/account')}
<GradientBanner on:close={handleClose}>
<div class="u-flex u-gap-24 u-main-center u-cross-center u-flex-vertical-mobile">
<span class="body-text-1">Get $50 Cloud credits for Appwrite Pro.</span>
3 changes: 1 addition & 2 deletions src/lib/components/billing/alerts/paymentMandate.svelte
Original file line number Diff line number Diff line change
@@ -8,8 +8,7 @@
import { confirmSetup } from '$lib/stores/stripe';

async function verifyPaymentMethod() {
const method = await sdk.forConsole.billing.setupPaymentMandate(
$organization.$id,
const method = await sdk.forConsole.account.updatePaymentMethodMandateOptions(
$paymentMissingMandate.$id
);
await confirmSetup(method.clientSecret, method.$id);
6 changes: 3 additions & 3 deletions src/lib/components/billing/couponInput.svelte
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
<script lang="ts">
import { Button, FormList, InputText } from '$lib/elements/forms';
import { formatCurrency } from '$lib/helpers/numbers';
import type { Coupon } from '$lib/sdk/billing';
import { sdk } from '$lib/stores/sdk';
import type { Models } from '@appwrite.io/console';
import { createEventDispatcher } from 'svelte';

const dispatch = createEventDispatcher();

export let required = false;
export let coupon: string = '';
export let couponData: Partial<Coupon> = {
export let couponData: Partial<Models.Coupon> = {
code: null,
status: null,
credits: null
};

async function addCoupon() {
try {
const response = await sdk.forConsole.billing.getCoupon(coupon);
const response = await sdk.forConsole.console.getCoupon(coupon);
couponData = response;
dispatch('validation', couponData);
coupon = null;
4 changes: 2 additions & 2 deletions src/lib/components/billing/emptyCardCloud.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script lang="ts">
import { trackEvent } from '$lib/actions/analytics';
import { BillingPlan } from '$lib/constants';
import { BillingPlan } from '@appwrite.io/console';
import { Button } from '$lib/elements/forms';
import { tierToPlan, upgradeURL } from '$lib/stores/billing';
import { Card } from '..';
@@ -14,7 +14,7 @@
<div class="u-flex u-flex-vertical u-main-center u-cross-center u-gap-8">
<h6 class="body-text-1 u-bold u-trim-1">Upgrade to add {service}</h6>
<p class="text u-text-center">
Upgrade to a {tierToPlan(BillingPlan.PRO).name} plan to add {service} to your organization
Upgrade to a {tierToPlan(BillingPlan.Tier1).name} plan to add {service} to your organization
</p>

<Button
6 changes: 2 additions & 4 deletions src/lib/components/billing/estimatedTotalBox.svelte
Original file line number Diff line number Diff line change
@@ -27,9 +27,7 @@
? grossCost - couponData.credits
: 0
: grossCost;
$: trialEndDate = new Date(
billingPayDate.getTime() + currentPlan.trialDays * 24 * 60 * 60 * 1000
);
$: trialEndDate = new Date(billingPayDate.getTime() + currentPlan.trial * 24 * 60 * 60 * 1000);
</script>

<section
@@ -59,7 +57,7 @@
</span>

<p class="text u-margin-block-start-16">
Your payment method will be charged this amount plus usage fees every 30 days {!currentPlan.trialDays
Your payment method will be charged this amount plus usage fees every 30 days {!currentPlan.trial
? `starting ${toLocaleDate(billingPayDate.toString())}`
: ` after your trial period ends on ${toLocaleDate(trialEndDate.toString())}`}.
</p>
18 changes: 9 additions & 9 deletions src/lib/components/billing/planComparisonBox.svelte
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<script lang="ts">
import { BillingPlan } from '$lib/constants';
import { BillingPlan } from '@appwrite.io/console';
import { formatNum } from '$lib/helpers/string';
import { plansInfo, tierFree, tierPro, type Tier } from '$lib/stores/billing';
import { Card, SecondaryTabs, SecondaryTabsItem } from '..';

let selectedTab: Tier = BillingPlan.FREE;
let selectedTab: Tier = BillingPlan.Tier0;
export let downgrade = false;

$: plan = $plansInfo.get(selectedTab);
@@ -14,13 +14,13 @@
<div class="comparison-box">
<SecondaryTabs stretch>
<SecondaryTabsItem
disabled={selectedTab === BillingPlan.FREE}
on:click={() => (selectedTab = BillingPlan.FREE)}>
disabled={selectedTab === BillingPlan.Tier0}
on:click={() => (selectedTab = BillingPlan.Tier0)}>
{tierFree.name}
</SecondaryTabsItem>
<SecondaryTabsItem
disabled={selectedTab === BillingPlan.PRO}
on:click={() => (selectedTab = BillingPlan.PRO)}>
disabled={selectedTab === BillingPlan.Tier1}
on:click={() => (selectedTab = BillingPlan.Tier1)}>
{tierPro.name}
</SecondaryTabsItem>
<!-- <SecondaryTabsItem
@@ -32,7 +32,7 @@
</div>

<div class="u-margin-block-start-24">
{#if selectedTab === BillingPlan.FREE}
{#if selectedTab === BillingPlan.Tier0}
<h3 class="u-bold body-text-1">{plan.name} plan</h3>
{#if downgrade}
<ul class="u-margin-block-start-8 list u-gap-4 u-small">
@@ -94,7 +94,7 @@
</li>
</ul>
{/if}
{:else if selectedTab === BillingPlan.PRO}
{:else if selectedTab === BillingPlan.Tier1}
<h3 class="u-bold body-text-1">{plan.name} plan</h3>
<p class="u-margin-block-start-8">Everything in the Free plan, plus:</p>
<ul class="un-order-list u-margin-inline-start-4">
@@ -104,7 +104,7 @@
<li>{formatNum(plan.executions)} executions</li>
<li>Email support</li>
</ul>
{:else if selectedTab === BillingPlan.SCALE}
{:else if selectedTab === BillingPlan.Tier2}
<h3 class="u-bold body-text-1">{plan.name} plan</h3>
<p class="u-margin-block-start-8">Everything in the Pro plan, plus:</p>
<ul class="un-order-list u-margin-inline-start-4">
9 changes: 4 additions & 5 deletions src/lib/components/billing/planExcess.svelte
Original file line number Diff line number Diff line change
@@ -17,9 +17,8 @@
import { abbreviateNumber } from '$lib/helpers/numbers';
import { formatNum } from '$lib/helpers/string';
import { onMount } from 'svelte';
import type { OrganizationUsage } from '$lib/sdk/billing';
import { sdk } from '$lib/stores/sdk';
import { BillingPlan } from '$lib/constants';
import { BillingPlan, type Models } from '@appwrite.io/console';
import { tooltip } from '$lib/actions/tooltip';

export let tier: Tier;
@@ -33,11 +32,11 @@
executions?: number;
members?: number;
} = null;
let usage: OrganizationUsage = null;
let usage: Models.UsageOrganization = null;
let showExcess = false;

onMount(async () => {
usage = await sdk.forConsole.billing.listUsage(
usage = await sdk.forConsole.organizations.getUsage(
$organization.$id,
$organization.billingCurrentInvoiceDate,
new Date().toISOString()
@@ -55,7 +54,7 @@
)}
</svelte:fragment>
Following payment of your final invoice, your organization will switch to the {tierToPlan(
BillingPlan.FREE
BillingPlan.Tier0
).name} plan. {#if excess?.members > 0}All team members except the owner will be removed on
that date.{/if} Service disruptions may occur unless resource usage is reduced.
<!-- Any executions, bandwidth, or messaging usage will be reset at that time. -->
22 changes: 11 additions & 11 deletions src/lib/components/billing/planSelection.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script lang="ts">
import { BillingPlan } from '$lib/constants';
import { BillingPlan } from '@appwrite.io/console';
import { formatCurrency } from '$lib/helpers/numbers';
import { plansInfo, tierFree, tierPro, tierScale, type Tier } from '$lib/stores/billing';
import { organization } from '$lib/stores/organization';
@@ -12,9 +12,9 @@
let classes: string = '';
export { classes as class };

$: freePlan = $plansInfo.get(BillingPlan.FREE);
$: proPlan = $plansInfo.get(BillingPlan.PRO);
$: scalePlan = $plansInfo.get(BillingPlan.SCALE);
$: freePlan = $plansInfo.get(BillingPlan.Tier0);
$: proPlan = $plansInfo.get(BillingPlan.Tier1);
$: scalePlan = $plansInfo.get(BillingPlan.Tier2);
</script>

{#if billingPlan}
@@ -24,7 +24,7 @@
name="plan"
bind:group={billingPlan}
disabled={anyOrgFree || !selfService}
value={BillingPlan.FREE}
value={BillingPlan.Tier0}
tooltipShow={anyOrgFree}
tooltipText="You are limited to 1 Free organization per account."
padding={1.5}>
@@ -34,7 +34,7 @@
class:u-opacity-50={disabled}>
<h4 class="body-text-2 u-bold">
{tierFree.name}
{#if $organization?.billingPlan === BillingPlan.FREE && !isNewOrg}
{#if $organization?.billingPlan === BillingPlan.Tier0 && !isNewOrg}
<span class="inline-tag">Current plan</span>
{/if}
</h4>
@@ -54,15 +54,15 @@
name="plan"
disabled={!selfService}
bind:group={billingPlan}
value={BillingPlan.PRO}
value={BillingPlan.Tier1}
padding={1.5}>
<svelte:fragment slot="custom" let:disabled>
<div
class="u-flex u-flex-vertical u-gap-4 u-width-full-line"
class:u-opacity-50={disabled}>
<h4 class="body-text-2 u-bold">
{tierPro.name}
{#if $organization?.billingPlan === BillingPlan.PRO && !isNewOrg}
{#if $organization?.billingPlan === BillingPlan.Tier1 && !isNewOrg}
<span class="inline-tag">Current plan</span>
{/if}
</h4>
@@ -76,18 +76,18 @@
</svelte:fragment>
</LabelCard>
</li>
{#if $organization?.billingPlan === BillingPlan.SCALE}
{#if $organization?.billingPlan === BillingPlan.Tier2}
<li>
<LabelCard
name="plan"
bind:group={billingPlan}
value={BillingPlan.SCALE}
value={BillingPlan.Tier2}
padding={1.5}>
<svelte:fragment slot="custom">
<div class="u-flex u-flex-vertical u-gap-4 u-width-full-line">
<h4 class="body-text-2 u-bold">
{tierScale.name}
{#if $organization?.billingPlan === BillingPlan.SCALE && !isNewOrg}
{#if $organization?.billingPlan === BillingPlan.Tier2 && !isNewOrg}
<span class="inline-tag">Current plan</span>
{/if}
</h4>
Loading