Unify workspace dropdowns; Update layouts (#458)

Unified Account and Workspace drop-downs; Layout updates, now header lives within the PageBody component; Sidebars now use floating variant
This commit is contained in:
Giancarlo Buomprisco
2026-03-11 14:45:42 +08:00
committed by GitHub
parent ca585e09be
commit 4bc8448a1d
530 changed files with 14398 additions and 11198 deletions

View File

@@ -1,4 +1,4 @@
import { z } from 'zod';
import * as z from 'zod';
export enum LineItemType {
Flat = 'flat',
@@ -19,42 +19,13 @@ export const PaymentTypeSchema = z.enum(['one-time', 'recurring']);
export const LineItemSchema = z
.object({
id: z
.string({
description:
'Unique identifier for the line item. Defined by the Provider.',
})
.min(1),
name: z
.string({
description: 'Name of the line item. Displayed to the user.',
})
.min(1),
description: z
.string({
description:
'Description of the line item. Displayed to the user and will replace the auto-generated description inferred' +
' from the line item. This is useful if you want to provide a more detailed description to the user.',
})
.optional(),
cost: z
.number({
description: 'Cost of the line item. Displayed to the user.',
})
.min(0),
id: z.string().min(1),
name: z.string().min(1),
description: z.string().optional(),
cost: z.number().min(0),
type: LineItemTypeSchema,
unit: z
.string({
description:
'Unit of the line item. Displayed to the user. Example "seat" or "GB"',
})
.optional(),
setupFee: z
.number({
description: `Lemon Squeezy only: If true, in addition to the cost, a setup fee will be charged.`,
})
.positive()
.optional(),
unit: z.string().optional(),
setupFee: z.number().positive().optional(),
tiers: z
.array(
z.object({
@@ -90,16 +61,8 @@ export const LineItemSchema = z
export const PlanSchema = z
.object({
id: z
.string({
description: 'Unique identifier for the plan. Defined by yourself.',
})
.min(1),
name: z
.string({
description: 'Name of the plan. Displayed to the user.',
})
.min(1),
id: z.string().min(1),
name: z.string().min(1),
interval: BillingIntervalSchema.optional(),
custom: z.boolean().default(false).optional(),
label: z.string().min(1).optional(),
@@ -122,13 +85,7 @@ export const PlanSchema = z
path: ['lineItems'],
},
),
trialDays: z
.number({
description:
'Number of days for the trial period. Leave empty for no trial.',
})
.positive()
.optional(),
trialDays: z.number().positive().optional(),
paymentType: PaymentTypeSchema,
})
.refine(
@@ -207,56 +164,15 @@ export const PlanSchema = z
const ProductSchema = z
.object({
id: z
.string({
description:
'Unique identifier for the product. Defined by th Provider.',
})
.min(1),
name: z
.string({
description: 'Name of the product. Displayed to the user.',
})
.min(1),
description: z
.string({
description: 'Description of the product. Displayed to the user.',
})
.min(1),
currency: z
.string({
description: 'Currency code for the product. Displayed to the user.',
})
.min(3)
.max(3),
badge: z
.string({
description:
'Badge for the product. Displayed to the user. Example: "Popular"',
})
.optional(),
features: z
.array(
z.string({
description: 'Features of the product. Displayed to the user.',
}),
)
.nonempty(),
enableDiscountField: z
.boolean({
description: 'Enable discount field for the product in the checkout.',
})
.optional(),
highlighted: z
.boolean({
description: 'Highlight this product. Displayed to the user.',
})
.optional(),
hidden: z
.boolean({
description: 'Hide this product from being displayed to users.',
})
.optional(),
id: z.string().min(1),
name: z.string().min(1),
description: z.string().min(1),
currency: z.string().min(3).max(3),
badge: z.string().optional(),
features: z.array(z.string()).nonempty(),
enableDiscountField: z.boolean().optional(),
highlighted: z.boolean().optional(),
hidden: z.boolean().optional(),
plans: z.array(PlanSchema),
})
.refine((data) => data.plans.length > 0, {
@@ -337,14 +253,14 @@ const BillingSchema = z
},
);
export function createBillingSchema(config: z.infer<typeof BillingSchema>) {
export function createBillingSchema(config: z.output<typeof BillingSchema>) {
return BillingSchema.parse(config);
}
export type BillingConfig = z.infer<typeof BillingSchema>;
export type ProductSchema = z.infer<typeof ProductSchema>;
export type BillingConfig = z.output<typeof BillingSchema>;
export type ProductSchema = z.output<typeof ProductSchema>;
export function getPlanIntervals(config: z.infer<typeof BillingSchema>) {
export function getPlanIntervals(config: z.output<typeof BillingSchema>) {
const intervals = config.products
.flatMap((product) => product.plans.map((plan) => plan.interval))
.filter(Boolean);
@@ -363,7 +279,7 @@ export function getPlanIntervals(config: z.infer<typeof BillingSchema>) {
* @param planId
*/
export function getPrimaryLineItem(
config: z.infer<typeof BillingSchema>,
config: z.output<typeof BillingSchema>,
planId: string,
) {
for (const product of config.products) {
@@ -391,7 +307,7 @@ export function getPrimaryLineItem(
}
export function getProductPlanPair(
config: z.infer<typeof BillingSchema>,
config: z.output<typeof BillingSchema>,
planId: string,
) {
for (const product of config.products) {
@@ -406,7 +322,7 @@ export function getProductPlanPair(
}
export function getProductPlanPairByVariantId(
config: z.infer<typeof BillingSchema>,
config: z.output<typeof BillingSchema>,
planId: string,
) {
for (const product of config.products) {
@@ -422,7 +338,7 @@ export function getProductPlanPairByVariantId(
throw new Error('Plan not found');
}
export type PlanTypeMap = Map<string, z.infer<typeof LineItemTypeSchema>>;
export type PlanTypeMap = Map<string, z.output<typeof LineItemTypeSchema>>;
/**
* @name getPlanTypesMap
@@ -430,7 +346,7 @@ export type PlanTypeMap = Map<string, z.infer<typeof LineItemTypeSchema>>;
* @param config
*/
export function getPlanTypesMap(
config: z.infer<typeof BillingSchema>,
config: z.output<typeof BillingSchema>,
): PlanTypeMap {
const planTypes: PlanTypeMap = new Map();

View File

@@ -1,4 +1,4 @@
import { z } from 'zod';
import * as z from 'zod';
export const CancelSubscriptionParamsSchema = z.object({
subscriptionId: z.string(),

View File

@@ -1,4 +1,4 @@
import { z } from 'zod';
import * as z from 'zod';
export const CreateBillingPortalSessionSchema = z.object({
returnUrl: z.string().url(),

View File

@@ -1,4 +1,4 @@
import { z } from 'zod';
import * as z from 'zod';
import { PlanSchema } from '../create-billing-schema';
@@ -15,5 +15,5 @@ export const CreateBillingCheckoutSchema = z.object({
quantity: z.number(),
}),
),
metadata: z.record(z.string()).optional(),
metadata: z.record(z.string(), z.string()).optional(),
});

View File

@@ -1,32 +1,17 @@
import { z } from 'zod';
import * as z from 'zod';
const TimeFilter = z.object(
{
startTime: z.number(),
endTime: z.number(),
},
{
description: `The time range to filter the usage records. Used for Stripe`,
},
);
const TimeFilter = z.object({
startTime: z.number(),
endTime: z.number(),
});
const PageFilter = z.object(
{
page: z.number(),
size: z.number(),
},
{
description: `The page and size to filter the usage records. Used for LS`,
},
);
const PageFilter = z.object({
page: z.number(),
size: z.number(),
});
export const QueryBillingUsageSchema = z.object({
id: z.string({
description:
'The id of the usage record. For Stripe a meter ID, for LS a subscription item ID.',
}),
customerId: z.string({
description: 'The id of the customer in the billing system',
}),
id: z.string(),
customerId: z.string(),
filter: z.union([TimeFilter, PageFilter]),
});

View File

@@ -1,15 +1,8 @@
import { z } from 'zod';
import * as z from 'zod';
export const ReportBillingUsageSchema = z.object({
id: z.string({
description:
'The id of the usage record. For Stripe a customer ID, for LS a subscription item ID.',
}),
eventName: z
.string({
description: 'The name of the event that triggered the usage',
})
.optional(),
id: z.string(),
eventName: z.string().optional(),
usage: z.object({
quantity: z.number(),
action: z.enum(['increment', 'set']).optional(),

View File

@@ -1,4 +1,4 @@
import { z } from 'zod';
import * as z from 'zod';
export const RetrieveCheckoutSessionSchema = z.object({
sessionId: z.string(),

View File

@@ -1,4 +1,4 @@
import { z } from 'zod';
import * as z from 'zod';
export const UpdateSubscriptionParamsSchema = z.object({
subscriptionId: z.string().min(1),

View File

@@ -1,4 +1,4 @@
import { z } from 'zod';
import * as z from 'zod';
import {
CancelSubscriptionParamsSchema,
@@ -13,13 +13,13 @@ import { UpsertSubscriptionParams } from '../types';
export abstract class BillingStrategyProviderService {
abstract createBillingPortalSession(
params: z.infer<typeof CreateBillingPortalSessionSchema>,
params: z.output<typeof CreateBillingPortalSessionSchema>,
): Promise<{
url: string;
}>;
abstract retrieveCheckoutSession(
params: z.infer<typeof RetrieveCheckoutSessionSchema>,
params: z.output<typeof RetrieveCheckoutSessionSchema>,
): Promise<{
checkoutToken: string | null;
status: 'complete' | 'expired' | 'open';
@@ -31,31 +31,31 @@ export abstract class BillingStrategyProviderService {
}>;
abstract createCheckoutSession(
params: z.infer<typeof CreateBillingCheckoutSchema>,
params: z.output<typeof CreateBillingCheckoutSchema>,
): Promise<{
checkoutToken: string;
}>;
abstract cancelSubscription(
params: z.infer<typeof CancelSubscriptionParamsSchema>,
params: z.output<typeof CancelSubscriptionParamsSchema>,
): Promise<{
success: boolean;
}>;
abstract reportUsage(
params: z.infer<typeof ReportBillingUsageSchema>,
params: z.output<typeof ReportBillingUsageSchema>,
): Promise<{
success: boolean;
}>;
abstract queryUsage(
params: z.infer<typeof QueryBillingUsageSchema>,
params: z.output<typeof QueryBillingUsageSchema>,
): Promise<{
value: number;
}>;
abstract updateSubscriptionItem(
params: z.infer<typeof UpdateSubscriptionParamsSchema>,
params: z.output<typeof UpdateSubscriptionParamsSchema>,
): Promise<{
success: boolean;
}>;