/** * Order Processing System - SOLID Principles Implementation * * This module demonstrates a refactored order processing system using: * - Single Responsibility Principle: Each strategy handles one order type * - Open/Closed Principle: New order types can be added without modifying existing code * - Liskov Substitution Principle: All strategies can be used interchangeably * - Interface Segregation Principle: Focused interfaces for specific needs * - Dependency Inversion Principle: Depends on abstractions (interfaces) not concretions */ import { z } from 'zod'; /** * Order type enum */ export declare enum OrderType { DIGITAL = "digital", PHYSICAL = "physical", SUBSCRIPTION = "subscription" } /** * Order status enum */ export declare enum OrderStatus { PENDING = "pending", DELIVERED = "delivered", SHIPPED = "shipped", ACTIVE = "active" } /** * Order interface */ export interface Order { id: string; type: OrderType; status: OrderStatus; customerId: string; items: Array<{ productId: string; quantity: number; price: number; }>; createdAt: Date; updatedAt: Date; } /** * Order processing result interface */ export interface ProcessingResult { success: boolean; order: Order; message: string; } /** * Order validation schema using Zod */ export declare const OrderSchema: z.ZodObject<{ id: z.ZodString; type: z.ZodNativeEnum; status: z.ZodDefault>; customerId: z.ZodString; items: z.ZodArray, "many">; createdAt: z.ZodDate; updatedAt: z.ZodDate; }, "strip", z.ZodTypeAny, { type: OrderType; status: OrderStatus; id: string; createdAt: Date; customerId: string; items: { price: number; productId: string; quantity: number; }[]; updatedAt: Date; }, { type: OrderType; id: string; createdAt: Date; customerId: string; items: { price: number; productId: string; quantity: number; }[]; updatedAt: Date; status?: OrderStatus | undefined; }>; /** * OrderProcessor strategy interface * All order processors must implement this interface */ export interface OrderProcessor { /** * Process an order according to its type * @param order - The order to process * @returns Processing result with updated order status * @throws {Error} If processing fails */ process(order: Order): Promise; /** * Validate that the order can be processed * @param order - The order to validate * @returns true if valid, false otherwise */ validate(order: Order): boolean; } /** * Digital order processor strategy * Handles delivery of digital products via email */ export declare class DigitalOrderProcessor implements OrderProcessor { /** * Process a digital order * @param order - The digital order to process * @returns Processing result with delivered status * @throws {Error} If email delivery fails */ process(order: Order): Promise; /** * Validate digital order requirements * @param order - The order to validate * @returns true if valid for digital processing */ validate(order: Order): boolean; /** * Send download link email to customer * @param order - The order containing customer information * @throws {Error} If email cannot be sent */ private sendDownloadLinkEmail; } /** * Physical order processor strategy * Handles shipping of physical products */ export declare class PhysicalOrderProcessor implements OrderProcessor { /** * Process a physical order * @param order - The physical order to process * @returns Processing result with shipped status * @throws {Error} If shipping label creation fails */ process(order: Order): Promise; /** * Validate physical order requirements * @param order - The order to validate * @returns true if valid for physical processing */ validate(order: Order): boolean; /** * Create shipping label for the order * @param order - The order to create label for * @throws {Error} If shipping label cannot be created */ private createShippingLabel; } /** * Subscription order processor strategy * Handles activation of subscription services */ export declare class SubscriptionOrderProcessor implements OrderProcessor { /** * Process a subscription order * @param order - The subscription order to process * @returns Processing result with active status * @throws {Error} If subscription activation fails */ process(order: Order): Promise; /** * Validate subscription order requirements * @param order - The order to validate * @returns true if valid for subscription processing */ validate(order: Order): boolean; /** * Activate subscription service * @param order - The order containing subscription details * @throws {Error} If subscription cannot be activated */ private activateSubscription; } /** * OrderProcessor factory * Responsible for selecting the appropriate processor based on order type * Follows Factory pattern for dependency injection */ export declare class OrderProcessorFactory { private readonly processors; constructor(); /** * Get the appropriate processor for the given order type * @param orderType - The type of order * @returns The appropriate order processor * @throws {Error} If no processor is found for the order type */ getProcessor(orderType: OrderType): OrderProcessor; /** * Register a new processor for a specific order type * @param orderType - The order type to handle * @param processor - The processor implementation */ registerProcessor(orderType: OrderType, processor: OrderProcessor): void; /** * Check if a processor is registered for the given order type * @param orderType - The order type to check * @returns true if a processor exists */ hasProcessor(orderType: OrderType): boolean; } /** * OrderProcessingService * Main service that coordinates order processing using the appropriate strategy */ export declare class OrderProcessingService { private readonly processorFactory; constructor(processorFactory?: OrderProcessorFactory); /** * Process an order using the appropriate strategy * @param orderInput - The order data to process (may be unvalidated) * @returns Processing result with updated order * @throws {Error} If validation fails or processing encounters an error */ processOrder(orderInput: unknown): Promise; } /** * Example usage demonstrating the refactored code */ export declare function exampleUsage(): Promise; //# sourceMappingURL=order-processor.d.ts.map