- Adjusted .prettierrc to ensure consistent formatting with a newline at the end of the file. - Reformatted eslint.config.mjs for improved readability by aligning array elements. - Updated pnpm-lock.yaml to use single quotes for consistency across dependencies. - Simplified worktree setup in .cursor/worktrees.json for cleaner configuration. - Enhanced documentation in .cursor/plans to clarify architecture refactoring. - Refactored various service files for improved readability and maintainability, including rate-limiting and auth services. - Updated imports and exports across multiple files for consistency and clarity. - Improved error handling and logging in service methods to enhance debugging capabilities. - Streamlined utility functions for better performance and maintainability across the domain packages.
85 lines
3.1 KiB
TypeScript
85 lines
3.1 KiB
TypeScript
/**
|
|
* ID Mapping Domain - Schemas
|
|
*/
|
|
|
|
import { z } from "zod";
|
|
import type { CreateMappingRequest, UpdateMappingRequest, UserIdMapping } from "./contract.js";
|
|
|
|
export const createMappingRequestSchema: z.ZodType<CreateMappingRequest> = z.object({
|
|
userId: z.string().uuid(),
|
|
whmcsClientId: z.number().int().positive(),
|
|
sfAccountId: z.string().min(1, "Salesforce account ID must be at least 1 character").optional(),
|
|
});
|
|
|
|
export const updateMappingRequestSchema: z.ZodType<UpdateMappingRequest> = z.object({
|
|
whmcsClientId: z.number().int().positive().optional(),
|
|
sfAccountId: z.string().min(1, "Salesforce account ID must be at least 1 character").optional(),
|
|
});
|
|
|
|
export const userIdMappingSchema: z.ZodType<UserIdMapping> = z.object({
|
|
id: z.string().uuid(),
|
|
userId: z.string().uuid(),
|
|
whmcsClientId: z.number().int().positive(),
|
|
sfAccountId: z.string().nullable().optional(),
|
|
createdAt: z.union([z.string(), z.date()]),
|
|
updatedAt: z.union([z.string(), z.date()]),
|
|
});
|
|
|
|
// ============================================================================
|
|
// Query and Filter Schemas
|
|
// ============================================================================
|
|
|
|
export const mappingSearchFiltersSchema = z.object({
|
|
userId: z.string().uuid().optional(),
|
|
whmcsClientId: z.number().int().positive().optional(),
|
|
sfAccountId: z.string().optional(),
|
|
hasWhmcsMapping: z.boolean().optional(),
|
|
hasSfMapping: z.boolean().optional(),
|
|
});
|
|
|
|
// ============================================================================
|
|
// Stats and Analytics Schemas
|
|
// ============================================================================
|
|
|
|
export const mappingStatsSchema = z.object({
|
|
totalMappings: z.number().int().nonnegative(),
|
|
whmcsMappings: z.number().int().nonnegative(),
|
|
salesforceMappings: z.number().int().nonnegative(),
|
|
completeMappings: z.number().int().nonnegative(),
|
|
orphanedMappings: z.number().int().nonnegative(),
|
|
});
|
|
|
|
// ============================================================================
|
|
// Bulk Operations Schemas
|
|
// ============================================================================
|
|
|
|
export const bulkMappingOperationSchema = z.object({
|
|
operation: z.enum(["create", "update", "delete"]),
|
|
mappings: z.union([
|
|
z.array(createMappingRequestSchema),
|
|
z.array(updateMappingRequestSchema),
|
|
z.array(z.string().uuid()),
|
|
]),
|
|
});
|
|
|
|
export const bulkMappingResultSchema = z.object({
|
|
successful: z.number().int().nonnegative(),
|
|
failed: z.number().int().nonnegative(),
|
|
errors: z.array(
|
|
z.object({
|
|
index: z.number().int().nonnegative(),
|
|
error: z.string(),
|
|
data: z.unknown(),
|
|
})
|
|
),
|
|
});
|
|
|
|
// ============================================================================
|
|
// Inferred Types from Schemas (Schema-First Approach)
|
|
// ============================================================================
|
|
|
|
export type MappingSearchFilters = z.infer<typeof mappingSearchFiltersSchema>;
|
|
export type MappingStats = z.infer<typeof mappingStatsSchema>;
|
|
export type BulkMappingOperation = z.infer<typeof bulkMappingOperationSchema>;
|
|
export type BulkMappingResult = z.infer<typeof bulkMappingResultSchema>;
|