remove: invoice, invoiceList and estimationDeleteOrganization manual types.

This commit is contained in:
Darshan
2025-12-18 13:36:10 +05:30
parent c3a5a3a4b2
commit 36f11f397c
11 changed files with 45 additions and 93 deletions
+10 -53
View File
@@ -1,45 +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 { PaymentMethod as StripePaymentMethod } from '@stripe/stripe-js';
import type { Organization, OrganizationError, OrganizationList } from '../stores/organization';
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;
@@ -57,15 +20,6 @@ export type EstimationItem = {
value: number;
};
export type EstimationDeleteOrganization = {
amount: number;
grossAmount: number;
credits: number;
discount: number;
items: EstimationItem[];
unpaidInvoices: Invoice[];
};
export type Coupon = {
$id: string;
code: string;
@@ -401,7 +355,7 @@ export class Billing {
async estimationDeleteOrganization(
organizationId: string
): Promise<EstimationDeleteOrganization> {
): Promise<Models.EstimationDeleteOrganization> {
const path = `/organizations/${organizationId}/estimations/delete-organization`;
const uri = new URL(this.client.config.endpoint + path);
return await this.client.call('patch', uri, {
@@ -624,7 +578,10 @@ export class Billing {
);
}
async listInvoices(organizationId: string, queries: string[] = []): Promise<InvoiceList> {
async listInvoices(
organizationId: string,
queries: string[] = []
): Promise<Models.InvoiceList> {
const path = `/organizations/${organizationId}/invoices`;
const params = {
organizationId,
@@ -642,7 +599,7 @@ export class Billing {
);
}
async getInvoice(organizationId: string, invoiceId: string): Promise<Invoice> {
async getInvoice(organizationId: string, invoiceId: string): Promise<Models.Invoice> {
const path = `/organizations/${organizationId}/invoices/${invoiceId}`;
const params = {
organizationId,
@@ -699,7 +656,7 @@ export class Billing {
);
}
async updateInvoiceStatus(organizationId: string, invoiceId: string): Promise<Invoice> {
async updateInvoiceStatus(organizationId: string, invoiceId: string): Promise<Models.Invoice> {
const path = `/organizations/${organizationId}/invoices/${invoiceId}/status`;
const uri = new URL(this.client.config.endpoint + path);
return await this.client.call('PATCH', uri, {
@@ -711,7 +668,7 @@ export class Billing {
organizationId: string,
invoiceId: string,
paymentMethodId: string
): Promise<Invoice> {
): Promise<Models.Invoice> {
const path = `/organizations/${organizationId}/invoices/${invoiceId}/payments`;
const params = {
organizationId,
@@ -1064,7 +1021,7 @@ export class Billing {
async setPaymentMethod(
paymentMethodId: string,
providerMethodId: string | PaymentMethod,
providerMethodId: string | StripePaymentMethod,
name: string,
state: string | undefined = undefined
): Promise<Models.PaymentMethod> {
+5 -11
View File
@@ -12,13 +12,7 @@ import PaymentMandate from '$lib/components/billing/alerts/paymentMandate.svelte
import { BillingPlan, NEW_DEV_PRO_UPGRADE_COUPON } from '$lib/constants';
import { cachedStore } from '$lib/helpers/cache';
import { type Size, sizeToBytes } from '$lib/helpers/sizeConvertion';
import type {
AddressesList,
AggregationTeam,
Invoice,
InvoiceList,
BillingPlansMap
} from '$lib/sdk/billing';
import type { AddressesList, AggregationTeam, BillingPlansMap } from '$lib/sdk/billing';
import { isCloud } from '$lib/system';
import { activeHeaderAlert, orgMissingPaymentMethod } from '$routes/(console)/store';
import { AppwriteException, Query, Platform, type Models } from '@appwrite.io/console';
@@ -85,7 +79,7 @@ export function getRoleLabel(role: string) {
return roles.find((r) => r.value === role)?.label ?? role;
}
export function tierToPlan(tier: Tier) {
export function tierToPlan(tier: Tier | string) {
switch (tier) {
case BillingPlan.FREE:
return tierFree;
@@ -154,7 +148,7 @@ export type PlanServices =
export function getServiceLimit(
serviceId: PlanServices,
tier: Tier = null,
tier: Tier | string = null,
plan?: Models.BillingPlan
): number {
if (!isCloud) return 0;
@@ -182,7 +176,7 @@ export function getServiceLimit(
}
export const failedInvoice = cachedStore<
Invoice,
Models.Invoice,
{
load: (orgId: string) => Promise<void>;
}
@@ -208,7 +202,7 @@ export const failedInvoice = cachedStore<
};
});
export const actionRequiredInvoices = writable<InvoiceList>(null);
export const actionRequiredInvoices = writable<Models.InvoiceList>(null);
export type TierData = {
name: string;
@@ -5,9 +5,8 @@
import { Button } from '$lib/elements/forms';
import DualTimeView from '$lib/components/dualTimeView.svelte';
import { formatCurrency } from '$lib/helpers/numbers';
import type { Invoice, InvoiceList } from '$lib/sdk/billing';
import { getApiEndpoint, sdk } from '$lib/stores/sdk';
import { Query } from '@appwrite.io/console';
import { type Models, Query } from '@appwrite.io/console';
import { trackEvent } from '$lib/actions/analytics';
import { selectedInvoice, showRetryModal } from './store';
import {
@@ -32,7 +31,7 @@
let limit = $state(5);
let offset = $state(0);
let isLoadingInvoices = $state(false);
let invoiceList: InvoiceList = $state({
let invoiceList: Models.InvoiceList = $state({
invoices: [],
total: 0
});
@@ -65,7 +64,7 @@
isLoadingInvoices = false;
}
function retryPayment(invoice: Invoice) {
function retryPayment(invoice: Models.Invoice) {
$selectedInvoice = invoice;
$showRetryModal = true;
}
@@ -5,7 +5,7 @@
import { toLocaleDate } from '$lib/helpers/date';
import { upgradeURL } from '$lib/stores/billing';
import { organization } from '$lib/stores/organization';
import type { Aggregation, Invoice } from '$lib/sdk/billing';
import type { Aggregation } from '$lib/sdk/billing';
import { abbreviateNumber, formatCurrency, formatNumberWithCommas } from '$lib/helpers/numbers';
import { BillingPlan } from '$lib/constants';
import { Click, trackEvent } from '$lib/actions/analytics';
@@ -23,8 +23,8 @@
import type { Models } from '@appwrite.io/console';
export let currentPlan: Models.BillingPlan;
export let currentInvoice: Invoice | undefined = undefined;
export let availableCredit: number | undefined = undefined;
export let currentInvoice: Models.Invoice | undefined = undefined;
export let currentAggregation: Aggregation | undefined = undefined;
let showCancel: boolean = false;
@@ -3,7 +3,6 @@
import { FakeModal } from '$lib/components';
import { Button } from '$lib/elements/forms';
import { Dependencies } from '$lib/constants';
import type { Invoice } from '$lib/sdk/billing';
import { addNotification } from '$lib/stores/notifications';
import { Submit, trackError, trackEvent } from '$lib/actions/analytics';
import { page } from '$app/state';
@@ -25,7 +24,7 @@
import type { Models } from '@appwrite.io/console';
export let show = false;
export let invoice: Invoice;
export let invoice: Models.Invoice;
let name: string;
let state: string = '';
@@ -1,7 +1,8 @@
import { page } from '$app/stores';
import { derived, writable } from 'svelte/store';
import type { Models } from '@appwrite.io/console';
import type { AggregationList, InvoiceUsage } from '$lib/sdk/billing';
import type { WizardStepsType } from '$lib/layout/wizardWithSteps.svelte';
import type { AggregationList, Invoice, InvoiceUsage } from '$lib/sdk/billing';
export const aggregationList = derived(
page,
@@ -14,7 +15,7 @@ export const addCreditWizardStore = writable<{ coupon: string; paymentMethodId:
paymentMethodId: null
});
export const selectedInvoice = writable<Invoice>(null);
export const selectedInvoice = writable<Models.Invoice>(null);
export const showRetryModal = writable(false);
export type RowFactoryOptions = {
@@ -1,8 +1,9 @@
<script lang="ts">
import { Alert } from '@appwrite.io/pink-svelte';
import type { EstimationDeleteOrganization } from '$lib/sdk/billing';
import InvoicesTable from './invoicesTable.svelte';
export let estimation: EstimationDeleteOrganization;
import type { Models } from '@appwrite.io/console';
export let estimation: Models.EstimationDeleteOrganization;
</script>
{#if estimation}
@@ -15,15 +15,15 @@
import { tierToPlan } from '$lib/stores/billing';
import { Table, Tabs, Alert } from '@appwrite.io/pink-svelte';
import DeleteOrganizationEstimation from './deleteOrganizationEstimation.svelte';
import type { EstimationDeleteOrganization, InvoiceList } from '$lib/sdk/billing';
import type { Models } from '@appwrite.io/console';
export let showDelete = false;
export let invoices: InvoiceList;
let error: string = null;
export let invoices: Models.InvoiceList;
let error: string = null;
let selectedTab = 'projects';
let organizationName: string = null;
let estimation: EstimationDeleteOrganization;
let estimation: Models.EstimationDeleteOrganization;
async function deleteOrg() {
try {
@@ -112,7 +112,8 @@
<b>This action is irreversible</b>.
{/if}
</p>
{#if estimation && (estimation.unpaidInvoices.length > 0 || estimation.grossAmount > 0)}
<!-- has estimation, has unpaid invoices, any of the invoices' gross amount is > 0 -->
{#if estimation && (estimation.unpaidInvoices.length > 0 || estimation.unpaidInvoices.some((invoice) => invoice.grossAmount > 0))}
<DeleteOrganizationEstimation {estimation} />
{:else}
{#if $projects.total > 0}
@@ -1,5 +1,4 @@
<script lang="ts">
import type { Invoice } from '$lib/sdk/billing';
import { getApiEndpoint } from '$lib/stores/sdk';
import { selectedInvoice, showRetryModal } from '../billing/store';
import { toLocaleDate } from '$lib/helpers/date';
@@ -14,13 +13,14 @@
IconRefresh
} from '@appwrite.io/pink-icons-svelte';
import { page } from '$app/state';
import type { Models } from '@appwrite.io/console';
export let showActions = true;
export let invoices: Array<Models.Invoice>;
const endpoint = getApiEndpoint();
export let invoices: Invoice[];
export let showActions = true;
function retryPayment(invoice: Invoice) {
function retryPayment(invoice: Models.Invoice) {
$selectedInvoice = invoice;
$showRetryModal = true;
}
@@ -1,8 +1,8 @@
import { sdk } from '$lib/stores/sdk';
import type { PageLoad } from './$types';
import { Query } from '@appwrite.io/console';
import { type Models, Query } from '@appwrite.io/console';
import type { UsageProjectInfo } from '../../store';
import type { Invoice, OrganizationUsage } from '$lib/sdk/billing';
import type { OrganizationUsage } from '$lib/sdk/billing';
export const load: PageLoad = async ({ params, parent }) => {
const { invoice } = params;
@@ -41,7 +41,7 @@ export const load: PageLoad = async ({ params, parent }) => {
let startDate: string = org.billingCurrentInvoiceDate;
let endDate: string = org.billingNextInvoiceDate;
let currentInvoice: Invoice = undefined;
let currentInvoice: Models.Invoice = undefined;
if (invoice) {
currentInvoice = await sdk.forConsole.billing.getInvoice(org.$id, invoice);
@@ -1,8 +1,8 @@
import type { AggregationTeam, Invoice, InvoiceUsage } from '$lib/sdk/billing';
import { accumulateUsage } from '$lib/sdk/usage';
import { sdk } from '$lib/stores/sdk';
import { Query } from '@appwrite.io/console';
import type { PageLoad } from './$types';
import { accumulateUsage } from '$lib/sdk/usage';
import { type Models, Query } from '@appwrite.io/console';
import type { AggregationTeam, InvoiceUsage } from '$lib/sdk/billing';
export const load: PageLoad = async ({ params, parent }) => {
const { invoice, project, region } = params;
@@ -10,7 +10,7 @@ export const load: PageLoad = async ({ params, parent }) => {
let startDate: string = organization.billingCurrentInvoiceDate;
let endDate: string = organization.billingNextInvoiceDate;
let currentInvoice: Invoice = undefined;
let currentInvoice: Models.Invoice = undefined;
let currentAggregation: AggregationTeam = undefined;
if (invoice) {