202 lines
5.5 KiB
TypeScript

/**
* Orders Domain - Contract
*
* Business types and provider-specific mapping types.
* Validated types are derived from schemas (see schema.ts).
*/
import type { SalesforceProductFieldMap } from "../catalog/contract";
import type { SalesforceAccountFieldMap } from "../customer/contract";
import type { UserIdMapping } from "../mappings/contract";
// ============================================================================
// Order Type Constants
// ============================================================================
/**
* Order types available in the system
*/
export const ORDER_TYPE = {
INTERNET: "Internet",
SIM: "SIM",
VPN: "VPN",
OTHER: "Other",
} as const;
export type OrderTypeValue = (typeof ORDER_TYPE)[keyof typeof ORDER_TYPE];
// ============================================================================
// Order Status Constants
// ============================================================================
/**
* Possible order statuses
*/
export const ORDER_STATUS = {
DRAFT: "Draft",
ACTIVATED: "Activated",
PENDING: "Pending",
FAILED: "Failed",
CANCELLED: "Cancelled",
} as const;
export type OrderStatusValue = (typeof ORDER_STATUS)[keyof typeof ORDER_STATUS];
// ============================================================================
// Activation Type Constants
// ============================================================================
/**
* Order activation types
*/
export const ACTIVATION_TYPE = {
IMMEDIATE: "Immediate",
SCHEDULED: "Scheduled",
} as const;
export type ActivationTypeValue = (typeof ACTIVATION_TYPE)[keyof typeof ACTIVATION_TYPE];
// ============================================================================
// SIM Type Constants
// ============================================================================
/**
* SIM card types
*/
export const SIM_TYPE = {
ESIM: "eSIM",
PHYSICAL: "Physical SIM",
} as const;
export type SimTypeValue = (typeof SIM_TYPE)[keyof typeof SIM_TYPE];
// ============================================================================
// Business Types (used internally, not validated at API boundary)
// ============================================================================
/**
* Order creation type used for order creation flows
*/
export type OrderCreationType = "Internet" | "SIM" | "VPN" | "Other";
/**
* Order status (string literal for flexibility)
*/
export type OrderStatus = string;
/**
* Order type (string literal for flexibility)
*/
export type OrderType = string;
/**
* User mapping for order creation (subset of UserIdMapping)
*/
export type UserMapping = Pick<UserIdMapping, "userId" | "whmcsClientId" | "sfAccountId">;
// ============================================================================
// Salesforce Field Configuration (Provider-Specific, Not Validated)
// ============================================================================
/**
* Configuration for MNP (Mobile Number Portability) field mappings.
* Maps logical field names to actual Salesforce custom field names.
*/
export interface SalesforceOrderMnpFieldConfig {
application: string;
reservationNumber: string;
expiryDate: string;
phoneNumber: string;
mvnoAccountNumber: string;
portingDateOfBirth: string;
portingFirstName: string;
portingLastName: string;
portingFirstNameKatakana: string;
portingLastNameKatakana: string;
portingGender: string;
}
/**
* Configuration for billing address field mappings.
* Maps logical field names to actual Salesforce custom field names.
*/
export interface SalesforceOrderBillingFieldConfig {
street: string;
city: string;
state: string;
postalCode: string;
country: string;
}
/**
* Configuration for Order field mappings.
* Maps logical field names to actual Salesforce custom field names.
*/
export interface SalesforceOrderFieldConfig {
orderType: string;
activationType: string;
activationScheduledAt: string;
activationStatus: string;
internetPlanTier: string;
installationType: string;
weekendInstall: string;
accessMode: string;
hikariDenwa: string;
vpnRegion: string;
simType: string;
eid: string;
simVoiceMail: string;
simCallWaiting: string;
mnp: SalesforceOrderMnpFieldConfig;
whmcsOrderId: string;
lastErrorCode?: string;
lastErrorMessage?: string;
lastAttemptAt?: string;
addressChanged: string;
billing: SalesforceOrderBillingFieldConfig;
}
/**
* Configuration for OrderItem field mappings.
* Maps logical field names to actual Salesforce custom field names.
*/
export interface SalesforceOrderItemFieldConfig {
billingCycle: string;
whmcsServiceId: string;
}
/**
* Complete Salesforce field configuration for orders.
* Aggregates all field configurations needed for order operations.
*/
export interface SalesforceOrdersFieldConfig {
account: SalesforceAccountFieldMap;
product: SalesforceProductFieldMap;
order: SalesforceOrderFieldConfig;
orderItem: SalesforceOrderItemFieldConfig;
}
// ============================================================================
// Re-export Types from Schema (Schema-First Approach)
// ============================================================================
export type {
// Fulfillment order types
FulfillmentOrderProduct,
FulfillmentOrderItem,
FulfillmentOrderDetails,
// Order item types
OrderItemSummary,
OrderItemDetails,
// Order types
OrderSummary,
OrderDetails,
// Query and creation types
OrderQueryParams,
OrderConfigurationsAddress,
OrderConfigurations,
CreateOrderRequest,
OrderBusinessValidation,
SfOrderIdParam,
} from './schema';