Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x | /**
* Order Validation Schemas
*
* Schemas for orders, cart, checkout, and payment operations.
*/
import { z } from 'zod';
import {
idSchema,
quantitySchema,
emailSchema,
phoneSchema,
nameSchema,
addressSchema,
paginationSchema,
} from '../schemas';
// ============================================================================
// CART
// ============================================================================
/**
* Add to cart schema
*/
export const addToCartSchema = z.object({
productId: idSchema,
quantity: quantitySchema.optional().default(1),
variant: z.record(z.string(), z.string()).optional(),
});
export type AddToCartInput = z.infer<typeof addToCartSchema>;
/**
* Update cart item schema
*/
export const updateCartItemSchema = z.object({
quantity: quantitySchema,
});
export type UpdateCartItemInput = z.infer<typeof updateCartItemSchema>;
/**
* Cart item schema (for display)
*/
export const cartItemSchema = z.object({
productId: idSchema,
quantity: quantitySchema,
price: z.number().positive(),
title: z.string(),
image: z.string().optional(),
variant: z.record(z.string(), z.string()).optional(),
});
export type CartItem = z.infer<typeof cartItemSchema>;
// ============================================================================
// CHECKOUT
// ============================================================================
/**
* Shipping address for checkout
*/
export const checkoutAddressSchema = addressSchema.extend({
name: nameSchema,
email: emailSchema,
phone: phoneSchema,
});
export type CheckoutAddressInput = z.infer<typeof checkoutAddressSchema>;
/**
* Checkout schema
*/
export const checkoutSchema = z.object({
shippingAddress: checkoutAddressSchema,
billingAddress: checkoutAddressSchema.optional(),
useSameAddress: z.boolean().default(true),
shippingMethod: z.string().min(1, 'Please select a shipping method'),
paymentMethod: z.enum(['card', 'paypal', 'apple_pay', 'google_pay']).default('card'),
notes: z.string().max(500).optional(),
promoCode: z.string().max(50).optional(),
});
export type CheckoutInput = z.infer<typeof checkoutSchema>;
// ============================================================================
// ORDER
// ============================================================================
/**
* Order status enum
*/
export const orderStatusSchema = z.enum([
'PENDING',
'CONFIRMED',
'PROCESSING',
'SHIPPED',
'DELIVERED',
'CANCELLED',
'REFUNDED',
]);
export type OrderStatus = z.infer<typeof orderStatusSchema>;
/**
* Update order status schema
*/
export const updateOrderStatusSchema = z.object({
status: orderStatusSchema,
notes: z.string().max(500).optional(),
trackingNumber: z.string().max(100).optional(),
carrier: z.string().max(50).optional(),
});
export type UpdateOrderStatusInput = z.infer<typeof updateOrderStatusSchema>;
/**
* Order query params
*/
export const orderQuerySchema = paginationSchema.extend({
status: orderStatusSchema.optional(),
userId: z.coerce.number().optional(),
dateFrom: z.coerce.date().optional(),
dateTo: z.coerce.date().optional(),
});
export type OrderQueryInput = z.infer<typeof orderQuerySchema>;
// ============================================================================
// PAYMENT
// ============================================================================
/**
* Create payment intent schema
*/
export const createPaymentSchema = z.object({
orderId: idSchema,
amount: z.number().positive(),
currency: z.string().length(3).default('USD'),
});
export type CreatePaymentInput = z.infer<typeof createPaymentSchema>;
/**
* Refund request schema
*/
export const refundRequestSchema = z.object({
orderId: idSchema,
amount: z.number().positive().optional(),
reason: z.enum(['DUPLICATE', 'FRAUDULENT', 'REQUESTED_BY_CUSTOMER', 'OTHER']),
notes: z.string().max(500).optional(),
});
export type RefundRequestInput = z.infer<typeof refundRequestSchema>;
// ============================================================================
// PROMO CODE
// ============================================================================
/**
* Apply promo code schema
*/
export const applyPromoCodeSchema = z.object({
code: z.string().min(1, 'Promo code is required').max(50).toUpperCase(),
});
export type ApplyPromoCodeInput = z.infer<typeof applyPromoCodeSchema>;
|