2025-10-03 14:26:55 +09:00
|
|
|
/**
|
|
|
|
|
* 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(),
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// ============================================================================
|
|
|
|
|
// 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(),
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// ============================================================================
|
|
|
|
|
// 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(),
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// ============================================================================
|
|
|
|
|
// VPN Product Schema
|
|
|
|
|
// ============================================================================
|
|
|
|
|
|
|
|
|
|
export const vpnCatalogProductSchema = catalogProductBaseSchema.extend({
|
|
|
|
|
vpnRegion: z.string().optional(),
|
|
|
|
|
});
|
|
|
|
|
|
2025-10-08 10:33:33 +09:00
|
|
|
// ============================================================================
|
|
|
|
|
// 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>;
|
|
|
|
|
|
|
|
|
|
// SIM products
|
|
|
|
|
export type SimCatalogProduct = z.infer<typeof simCatalogProductSchema>;
|
|
|
|
|
export type SimActivationFeeCatalogItem = z.infer<typeof simActivationFeeCatalogItemSchema>;
|
|
|
|
|
|
|
|
|
|
// VPN products
|
|
|
|
|
export type VpnCatalogProduct = z.infer<typeof vpnCatalogProductSchema>;
|
|
|
|
|
|
|
|
|
|
// Union type for all catalog products
|
|
|
|
|
export type CatalogProduct =
|
|
|
|
|
| InternetPlanCatalogItem
|
|
|
|
|
| InternetInstallationCatalogItem
|
|
|
|
|
| InternetAddonCatalogItem
|
|
|
|
|
| SimCatalogProduct
|
|
|
|
|
| SimActivationFeeCatalogItem
|
|
|
|
|
| VpnCatalogProduct
|
|
|
|
|
| CatalogProductBase;
|
|
|
|
|
|