Skip to content

update console SDK #1860

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
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
},
"dependencies": {
"@ai-sdk/svelte": "^1.1.24",
"@appwrite.io/console": "https://pkg.pr.new/appwrite-labs/cloud/@appwrite.io/console@1959",
"@appwrite.io/console": "https://try-module.cloud/module/@appwrite/%40appwrite.io%2Fconsole@e50c8d0b7",
"@appwrite.io/pink": "0.25.0",
"@appwrite.io/pink-icons": "0.25.0",
"@appwrite.io/pink-icons-svelte": "^2.0.0-RC.1",
Expand Down
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.

2 changes: 1 addition & 1 deletion src/lib/commandCenter/searchers/organizations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { isCloud } from '$lib/system';
export const orgSearcher = (async (query: string) => {
const { teams } = !isCloud
? await sdk.forConsole.teams.list()
: await sdk.forConsole.billing.listOrganization();
: await sdk.forConsole.organizations.list();

return teams
.filter((organization) => organization.name.toLowerCase().includes(query.toLowerCase()))
Expand Down
3 changes: 1 addition & 2 deletions src/lib/components/billing/alerts/paymentMandate.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/lib/components/billing/couponInput.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

async function addCoupon() {
try {
const response = await sdk.forConsole.billing.getCouponAccount(coupon);
const response = await sdk.forConsole.account.getCoupon(coupon);
couponData = response;
dispatch('validation', couponData);
coupon = null;
Expand Down
13 changes: 6 additions & 7 deletions src/lib/components/billing/estimatedTotalBox.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@
import { InputChoice, InputNumber } from '$lib/elements/forms';
import { toLocaleDate } from '$lib/helpers/date';
import { formatCurrency } from '$lib/helpers/numbers';
import type { Coupon, PlansMap } from '$lib/sdk/billing';
import type { Coupon } from '$lib/sdk/billing';
import { type Tier } from '$lib/stores/billing';
import { Card, Divider, Layout, Typography } from '@appwrite.io/pink-svelte';
import { CreditsApplied } from '.';
import type { Models } from '@appwrite.io/console';

export let billingPlan: Tier;
export let collaborators: string[];
export let couponData: Partial<Coupon>;
export let plans: PlansMap;
export let plans: Map<Tier, Models.BillingPlan>;
export let billingBudget: number;
export let fixedCoupon = false; // If true, the coupon cannot be removed
export let isDowngrade = false;
Expand All @@ -29,9 +30,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>

<Card.Base padding="s">
Expand All @@ -54,7 +53,7 @@
<Layout.Stack direction="row" justifyContent="space-between">
<Typography.Text>
Upcoming charge<br />
Due on {!currentPlan.trialDays
Due on {!currentPlan.trial
? toLocaleDate(billingPayDate.toString())
: toLocaleDate(trialEndDate.toString())}</Typography.Text>
<Typography.Text>{formatCurrency(estimatedTotal)}</Typography.Text>
Expand All @@ -64,7 +63,7 @@
You'll pay <b>{formatCurrency(estimatedTotal)}</b> now, with your first billing cycle
starting on
<b
>{!currentPlan.trialDays
>{!currentPlan.trial
? toLocaleDate(billingPayDate.toString())
: toLocaleDate(trialEndDate.toString())}</b
>. {#if couponData?.status === 'active'}Once your credits run out, you'll be charged
Expand Down
4 changes: 2 additions & 2 deletions src/lib/components/billing/planComparisonBox.svelte
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<script lang="ts">
import { BillingPlan } from '$lib/constants';
import { formatNum } from '$lib/helpers/string';
import { plansInfo, tierFree, tierPro, tierScale, type Tier } from '$lib/stores/billing';
import { plansInfo, tierFree, tierPro, tierScale } from '$lib/stores/billing';
import { Card, Layout, Tabs, Typography } from '@appwrite.io/pink-svelte';

export let downgrade = false;

let selectedTab: Tier = BillingPlan.FREE;
let selectedTab: BillingPlan = BillingPlan.FREE;

$: plan = $plansInfo.get(selectedTab);
</script>
Expand Down
10 changes: 5 additions & 5 deletions src/lib/components/billing/planExcess.svelte
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
<script lang="ts">
import { calculateExcess, plansInfo, tierToPlan, type Tier } from '$lib/stores/billing';
import { calculateExcess, plansInfo, tierToPlan } from '$lib/stores/billing';
import { organization } from '$lib/stores/organization';
import { toLocaleDate } from '$lib/helpers/date';
import { humanFileSize } from '$lib/helpers/sizeConvertion';
import { abbreviateNumber } from '$lib/helpers/numbers';
import { formatNum } from '$lib/helpers/string';
import { onMount } from 'svelte';
import type { Aggregation } from '$lib/sdk/billing';
import { sdk } from '$lib/stores/sdk';
import { BillingPlan } from '$lib/constants';
import { Alert, Icon, Table, Tooltip } from '@appwrite.io/pink-svelte';
import { IconInfo } from '@appwrite.io/pink-icons-svelte';
import type { Models } from '@appwrite.io/console';

export let tier: Tier;
export let tier: BillingPlan;

const plan = $plansInfo?.get(tier);
let excess: {
Expand All @@ -22,11 +22,11 @@
executions?: number;
members?: number;
} = null;
let aggregation: Aggregation = null;
let aggregation: Models.AggregationTeam = null;
let showExcess = false;

onMount(async () => {
aggregation = await sdk.forConsole.billing.getAggregation(
aggregation = await sdk.forConsole.organizations.getAggregation(
$organization.$id,
$organization.billingAggregationId
);
Expand Down
3 changes: 1 addition & 2 deletions src/lib/components/billing/validateCreditModal.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@

async function addCoupon() {
try {
// const response = await sdk.forConsole.billing.getCoupon(coupon);
const response = await sdk.forConsole.billing.getCouponAccount(coupon); //TODO: double check that this is the correct method
const response = await sdk.forConsole.account.getCoupon(coupon);

if (response.onlyNewOrgs && !isNewOrg) {
show = false;
Expand Down
3 changes: 3 additions & 0 deletions src/lib/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,9 @@ export const eventServices: Array<EventService> = [
];

export enum BillingPlan {
Tier0 = 'tier-0',
Tier1 = 'tier-1',
Tier2 = 'tier-2',
FREE = 'tier-0',
PRO = 'tier-1',
SCALE = 'tier-2',
Expand Down
10 changes: 4 additions & 6 deletions src/lib/layout/unauthenticated.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,20 @@
import AppwriteLogoLight from '$lib/images/appwrite-logo-light.svg';
import LoginDark from '$lib/images/login/login-dark-mode.png';
import LoginLight from '$lib/images/login/login-light-mode.png';
import type { Coupon } from '$lib/sdk/billing';
import { app } from '$lib/stores/app';
import type { Campaign } from '$lib/stores/campaigns';
import { Typography, Layout, Avatar } from '@appwrite.io/pink-svelte';
import { getCampaignImageUrl } from '$routes/(public)/card/helpers';

import type { Models } from '@appwrite.io/console';
export const imgLight = LoginLight;
export const imgDark = LoginDark;

export let campaign: Campaign = null;
export let coupon: Coupon = null;
export let campaign: Models.Campaign = null;
export let coupon: Models.Coupon = null;
export let align: 'start' | 'center' | 'end' = 'start';

$: variation = ((coupon?.campaign ?? campaign) ? campaign?.template : 'default') as
| 'default'
| Campaign['template'];
| Models.Campaign['template'];

let currentReviewNumber = 0;
$: currentReview = campaign?.reviews?.[currentReviewNumber];
Expand Down
112 changes: 7 additions & 105 deletions src/lib/sdk/billing.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { Tier } from '$lib/stores/billing';
import type { Campaign } from '$lib/stores/campaigns';
import type { Client, Models } from '@appwrite.io/console';
import type { PaymentMethod } from '@stripe/stripe-js';
import type { Organization, OrganizationError, OrganizationList } from '../stores/organization';
import type { BillingPlan } from '$lib/constants';

export type PaymentMethodData = {
$id: string;
Expand All @@ -29,42 +29,6 @@ export type PaymentList = {
total: number;
};

export type Invoice = {
$id: string;
$createdAt: Date;
$updatedAt: Date;
permissions: string[];
teamId: string;
aggregationId: string;
plan: Tier;
amount: number;
tax: number;
taxAmount: number;
vat: number;
vatAmount: number;
grossAmount: number;
creditsUsed: number;
currency: string;
from: string;
to: string;
status: string;
dueAt: string;
clientSecret: string;
usage: {
name: string;
value: number /* service over the limit*/;
amount: number /* price of service over the limit*/;
rate: number;
desc: string;
}[];
lastError?: string;
};

export type InvoiceList = {
invoices: Invoice[];
total: number;
};

export type Estimation = {
amount: number;
grossAmount: number;
Expand All @@ -88,7 +52,7 @@ export type EstimationDeleteOrganization = {
credits: number;
discount: number;
items: EstimationItem[];
unpaidInvoices: Invoice[];
unpaidInvoices: Models.Invoice[];
};

export type Coupon = {
Expand Down Expand Up @@ -345,7 +309,7 @@ export type PlanList = {
total: number;
};

export type PlansMap = Map<Tier, Plan>;
export type PlansMap = Map<BillingPlan, Models.BillingPlan>;

export type Roles = {
scopes: string[];
Expand Down Expand Up @@ -375,7 +339,10 @@ export class Billing {
);
}

async validateOrganization(organizationId: string, invites: string[]): Promise<Organization> {
async validateOrganization(
organizationId: string,
invites: string[]
): Promise<Models.Organization<Record<string, unknown>>> {
const path = `/organizations/${organizationId}/validate`;
const params = {
organizationId,
Expand Down Expand Up @@ -653,41 +620,6 @@ export class Billing {
);
}

async listInvoices(organizationId: string, queries: string[] = []): Promise<InvoiceList> {
const path = `/organizations/${organizationId}/invoices`;
const params = {
organizationId,
queries
};

const uri = new URL(this.client.config.endpoint + path);
return await this.client.call(
'get',
uri,
{
'content-type': 'application/json'
},
params
);
}

async getInvoice(organizationId: string, invoiceId: string): Promise<Invoice> {
const path = `/organizations/${organizationId}/invoices/${invoiceId}`;
const params = {
organizationId,
invoiceId
};
const uri = new URL(this.client.config.endpoint + path);
return await this.client.call(
'get',
uri,
{
'content-type': 'application/json'
},
params
);
}

async getInvoiceView(
organizationId: string,
invoiceId: string
Expand Down Expand Up @@ -728,36 +660,6 @@ export class Billing {
);
}

async updateInvoiceStatus(organizationId: string, invoiceId: string): Promise<Invoice> {
const path = `/organizations/${organizationId}/invoices/${invoiceId}/status`;
const uri = new URL(this.client.config.endpoint + path);
return await this.client.call('PATCH', uri, {
'content-type': 'application/json'
});
}

async retryPayment(
organizationId: string,
invoiceId: string,
paymentMethodId: string
): Promise<Invoice> {
const path = `/organizations/${organizationId}/invoices/${invoiceId}/payments`;
const params = {
organizationId,
invoiceId,
paymentMethodId
};
const uri = new URL(this.client.config.endpoint + path);
return await this.client.call(
'post',
uri,
{
'content-type': 'application/json'
},
params
);
}

async listUsage(
organizationId: string,
startDate: string = undefined,
Expand Down
Loading
Loading