barsa a61c2dd68b Enhance Opportunity Management and Eligibility Handling
- Updated SalesforceOpportunityService to allow filtering by stages during opportunity retrieval, improving flexibility in eligibility checks.
- Integrated DistributedLockService into InternetCatalogService and OrderOrchestrator to prevent race conditions when creating or reusing opportunities.
- Refactored opportunity matching logic to ensure proper handling of stages during eligibility requests and order placements.
- Improved documentation to clarify the opportunity lifecycle and eligibility verification processes, ensuring better understanding for future development.
2025-12-23 16:44:45 +09:00

143 lines
4.7 KiB
TypeScript

/**
* Opportunity Domain
*
* Exports all Opportunity-related contracts, schemas, helpers, and types.
* Used for Salesforce Opportunity lifecycle management including cancellation.
*
* Key features:
* - Service lifecycle tracking (Introduction -> Active -> Cancelling -> Cancelled)
* - Cancellation deadline logic (25th of month rule)
* - Rental equipment return tracking
*
* Types are derived from Zod schemas (Schema-First Approach)
*/
// ============================================================================
// Constants
// ============================================================================
export {
// Stage constants (existing Salesforce picklist values)
OPPORTUNITY_STAGE,
type OpportunityStageValue,
// Application stage constants
APPLICATION_STAGE,
type ApplicationStageValue,
// Cancellation notice constants
CANCELLATION_NOTICE,
type CancellationNoticeValue,
// Line return status constants
LINE_RETURN_STATUS,
type LineReturnStatusValue,
// Commodity type constants (existing Salesforce CommodityType field)
COMMODITY_TYPE,
type CommodityTypeValue,
// Product type constants (simplified, derived from CommodityType)
OPPORTUNITY_PRODUCT_TYPE,
type OpportunityProductTypeValue,
// Default commodity types for portal
PORTAL_DEFAULT_COMMODITY_TYPES,
// Commodity type helpers
getCommodityTypeProductType,
getDefaultCommodityType,
// Source constants
OPPORTUNITY_SOURCE,
type OpportunitySourceValue,
// Matching constants
OPEN_OPPORTUNITY_STAGES,
OPPORTUNITY_MATCH_STAGES_INTERNET_ELIGIBILITY,
OPPORTUNITY_MATCH_STAGES_ORDER_PLACEMENT,
CLOSED_OPPORTUNITY_STAGES,
// Deadline constants
CANCELLATION_DEADLINE_DAY,
RENTAL_RETURN_DEADLINE_DAY,
// Customer-facing service display types
type CustomerServicePhase,
type ServiceLinkStatus,
type OrderTrackingInfo,
type WhmcsServiceDetails,
type CancellationDisplayInfo,
type CustomerServiceView,
// Customer-facing helpers
getCustomerPhaseFromStage,
getOrderTrackingSteps,
canServiceBeCancelled,
} from "./contract.js";
// ============================================================================
// Contract Types (business types, not validated)
// ============================================================================
export type {
OpportunityRecord as OpportunityRecordContract,
CreateOpportunityRequest as CreateOpportunityRequestContract,
UpdateOpportunityStageRequest as UpdateOpportunityStageRequestContract,
CancellationFormData as CancellationFormDataContract,
CancellationOpportunityData as CancellationOpportunityDataContract,
CancellationCaseData as CancellationCaseDataContract,
CancellationEligibility as CancellationEligibilityContract,
CancellationMonthOption as CancellationMonthOptionContract,
CancellationStatus as CancellationStatusContract,
OpportunityMatchResult as OpportunityMatchResultContract,
OpportunityLookupCriteria as OpportunityLookupCriteriaContract,
} from "./contract.js";
// ============================================================================
// Schemas and Validated Types (preferred)
// ============================================================================
export {
// Schemas
opportunityRecordSchema,
createOpportunityRequestSchema,
updateOpportunityStageRequestSchema,
cancellationFormDataSchema,
cancellationOpportunityDataSchema,
cancellationMonthOptionSchema,
cancellationEligibilitySchema,
cancellationStatusSchema,
opportunityLookupCriteriaSchema,
opportunityMatchResultSchema,
opportunityResponseSchema,
createOpportunityResponseSchema,
cancellationPreviewResponseSchema,
// Derived types (preferred - validated)
type OpportunityRecord,
type CreateOpportunityRequest,
type UpdateOpportunityStageRequest,
type CancellationFormData,
type CancellationOpportunityData,
type CancellationMonthOption,
type CancellationEligibility,
type CancellationStatus,
type OpportunityLookupCriteria,
type OpportunityMatchResult,
} from "./schema.js";
// ============================================================================
// Helpers
// ============================================================================
export {
// Date utilities
getLastDayOfMonth,
getRentalReturnDeadline,
parseYearMonth,
formatYearMonth,
formatMonthLabel,
formatDateLabel,
// Cancellation deadline logic
isBeforeCancellationDeadline,
getCancellationDeadline,
getEarliestCancellationMonth,
generateCancellationMonthOptions,
getCancellationEligibility,
validateCancellationMonth,
// Data transformation
transformCancellationFormToOpportunityData,
calculateRentalReturnDeadline,
// Display helpers
getLineReturnStatusLabel,
hasRentalEquipment,
} from "./helpers.js";