- Introduced new SIM management queue and processor to handle SIM-related tasks efficiently. - Added SIM activation fee handling in the checkout service, ensuring proper validation and inclusion in cart calculations. - Enhanced the SimCatalogService to retrieve and filter activation fees based on SKU, improving order validation. - Updated the checkout process to automatically add default activation fees when none are specified, improving user experience. - Refactored the ActivationForm component to display activation fees clearly during the SIM configuration process. - Improved error handling and logging across various services to provide better insights during operations. - Updated tests to cover new features and ensure reliability in the checkout and SIM management workflows.
174 lines
6.1 KiB
TypeScript
174 lines
6.1 KiB
TypeScript
/**
|
|
* Catalog Domain - Schemas
|
|
*
|
|
* Zod schemas for runtime validation of catalog product data.
|
|
*/
|
|
|
|
import { z } from "zod";
|
|
|
|
// ============================================================================
|
|
// Base Catalog Product Schema
|
|
// ============================================================================
|
|
|
|
export const catalogProductBaseSchema = z.object({
|
|
id: z.string(),
|
|
sku: z.string(),
|
|
name: z.string(),
|
|
description: z.string().optional(),
|
|
displayOrder: z.number().optional(),
|
|
billingCycle: z.string().optional(),
|
|
monthlyPrice: z.number().optional(),
|
|
oneTimePrice: z.number().optional(),
|
|
unitPrice: z.number().optional(),
|
|
catalogMetadata: z.record(z.string(), z.unknown()).optional(),
|
|
});
|
|
|
|
// ============================================================================
|
|
// PricebookEntry Schema
|
|
// ============================================================================
|
|
|
|
export const catalogPricebookEntrySchema = z.object({
|
|
id: z.string().optional(),
|
|
name: z.string().optional(),
|
|
unitPrice: z.number().optional(),
|
|
pricebook2Id: z.string().optional(),
|
|
product2Id: z.string().optional(),
|
|
isActive: z.boolean().optional(),
|
|
});
|
|
|
|
// ============================================================================
|
|
// Internet Product Schemas
|
|
// ============================================================================
|
|
|
|
export const internetCatalogProductSchema = catalogProductBaseSchema.extend({
|
|
internetPlanTier: z.string().optional(),
|
|
internetOfferingType: z.string().optional(),
|
|
features: z.array(z.string()).optional(),
|
|
});
|
|
|
|
export const internetPlanTemplateSchema = z.object({
|
|
tierDescription: z.string(),
|
|
description: z.string().optional(),
|
|
features: z.array(z.string()).optional(),
|
|
});
|
|
|
|
export const internetPlanCatalogItemSchema = internetCatalogProductSchema.extend({
|
|
catalogMetadata: z.object({
|
|
tierDescription: z.string().optional(),
|
|
features: z.array(z.string()).optional(),
|
|
isRecommended: z.boolean().optional(),
|
|
}).optional(),
|
|
});
|
|
|
|
export const internetInstallationCatalogItemSchema = internetCatalogProductSchema.extend({
|
|
catalogMetadata: z.object({
|
|
installationTerm: z.enum(["One-time", "12-Month", "24-Month"]),
|
|
}).optional(),
|
|
});
|
|
|
|
export const internetAddonCatalogItemSchema = internetCatalogProductSchema.extend({
|
|
isBundledAddon: z.boolean().optional(),
|
|
bundledAddonId: z.string().optional(),
|
|
});
|
|
|
|
export const internetCatalogCollectionSchema = z.object({
|
|
plans: z.array(internetPlanCatalogItemSchema),
|
|
installations: z.array(internetInstallationCatalogItemSchema),
|
|
addons: z.array(internetAddonCatalogItemSchema),
|
|
});
|
|
|
|
export const internetCatalogResponseSchema = internetCatalogCollectionSchema;
|
|
|
|
// ============================================================================
|
|
// SIM Product Schemas
|
|
// ============================================================================
|
|
|
|
export const simCatalogProductSchema = catalogProductBaseSchema.extend({
|
|
simDataSize: z.string().optional(),
|
|
simPlanType: z.string().optional(),
|
|
simHasFamilyDiscount: z.boolean().optional(),
|
|
isBundledAddon: z.boolean().optional(),
|
|
bundledAddonId: z.string().optional(),
|
|
});
|
|
|
|
export const simActivationFeeCatalogItemSchema = simCatalogProductSchema.extend({
|
|
catalogMetadata: z
|
|
.object({
|
|
isDefault: z.boolean().optional(),
|
|
autoAdd: z.boolean().optional(),
|
|
})
|
|
.optional(),
|
|
});
|
|
|
|
export const simCatalogCollectionSchema = z.object({
|
|
plans: z.array(simCatalogProductSchema),
|
|
activationFees: z.array(simActivationFeeCatalogItemSchema),
|
|
addons: z.array(simCatalogProductSchema),
|
|
});
|
|
|
|
export const simCatalogResponseSchema = simCatalogCollectionSchema;
|
|
|
|
// ============================================================================
|
|
// VPN Product Schema
|
|
// ============================================================================
|
|
|
|
export const vpnCatalogProductSchema = catalogProductBaseSchema.extend({
|
|
vpnRegion: z.string().optional(),
|
|
});
|
|
|
|
export const vpnCatalogCollectionSchema = z.object({
|
|
plans: z.array(vpnCatalogProductSchema),
|
|
activationFees: z.array(vpnCatalogProductSchema),
|
|
});
|
|
|
|
export const vpnCatalogResponseSchema = vpnCatalogCollectionSchema;
|
|
|
|
// ============================================================================
|
|
// Catalog Filter Schema
|
|
// ============================================================================
|
|
|
|
/**
|
|
* Schema for catalog filtering options
|
|
*/
|
|
export const catalogFilterSchema = z.object({
|
|
category: z.string().optional(),
|
|
priceMin: z.number().optional(),
|
|
priceMax: z.number().optional(),
|
|
search: z.string().optional(),
|
|
});
|
|
|
|
// ============================================================================
|
|
// Inferred Types from Schemas (Schema-First Approach)
|
|
// ============================================================================
|
|
|
|
export type CatalogProductBase = z.infer<typeof catalogProductBaseSchema>;
|
|
export type CatalogPricebookEntry = z.infer<typeof catalogPricebookEntrySchema>;
|
|
|
|
// Internet products
|
|
export type InternetCatalogProduct = z.infer<typeof internetCatalogProductSchema>;
|
|
export type InternetPlanTemplate = z.infer<typeof internetPlanTemplateSchema>;
|
|
export type InternetPlanCatalogItem = z.infer<typeof internetPlanCatalogItemSchema>;
|
|
export type InternetInstallationCatalogItem = z.infer<typeof internetInstallationCatalogItemSchema>;
|
|
export type InternetAddonCatalogItem = z.infer<typeof internetAddonCatalogItemSchema>;
|
|
export type InternetCatalogCollection = z.infer<typeof internetCatalogCollectionSchema>;
|
|
|
|
// SIM products
|
|
export type SimCatalogProduct = z.infer<typeof simCatalogProductSchema>;
|
|
export type SimActivationFeeCatalogItem = z.infer<typeof simActivationFeeCatalogItemSchema>;
|
|
export type SimCatalogCollection = z.infer<typeof simCatalogCollectionSchema>;
|
|
|
|
// VPN products
|
|
export type VpnCatalogProduct = z.infer<typeof vpnCatalogProductSchema>;
|
|
export type VpnCatalogCollection = z.infer<typeof vpnCatalogCollectionSchema>;
|
|
|
|
// Union type for all catalog products
|
|
export type CatalogProduct =
|
|
| InternetPlanCatalogItem
|
|
| InternetInstallationCatalogItem
|
|
| InternetAddonCatalogItem
|
|
| SimCatalogProduct
|
|
| SimActivationFeeCatalogItem
|
|
| VpnCatalogProduct
|
|
| CatalogProductBase;
|
|
|