barsa 6096c15659 Refactor Salesforce Opportunity Integration for SIM and Internet Cancellations
- Updated opportunity field mappings to replace deprecated fields with new ones for SIM and Internet cancellations, enhancing clarity and consistency.
- Introduced separate data structures for Internet and SIM cancellation data, improving type safety and validation.
- Refactored SalesforceOpportunityService to handle updates for both Internet and SIM cancellations, ensuring accurate data handling.
- Enhanced cancellation query fields to support new SIM cancellation requirements, improving the overall cancellation process.
- Cleaned up the portal integration to reflect changes in opportunity source fields, promoting better data integrity and tracking.
2026-01-05 17:08:33 +09:00

148 lines
4.9 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,
// Internet Cancellation notice constants
CANCELLATION_NOTICE,
type CancellationNoticeValue,
// Line return status constants (Internet)
LINE_RETURN_STATUS,
type LineReturnStatusValue,
// SIM Cancellation notice constants
SIM_CANCELLATION_NOTICE,
type SimCancellationNoticeValue,
// 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,
InternetCancellationOpportunityData,
SimCancellationOpportunityData,
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";