-- types

Orders System TypeScript Types

This document provides a comprehensive reference for all TypeScript interfaces and types used within the Orders management system.

Core Order Entities

Commercial Order Types

// Main commercial order entity from SDK
interface CommercialOrder {
  id: string;
  reference: string;
  status: CommercialOrderStatusType;
  totalPrice: number;
  totalPriceWithoutTax: number;
  totalTaxAmount: number;
  totalShippingFees: number;
  currency: string;
  createdAt: string;
  updatedAt: string;
  logistics: LogisticOrder[];
  customFields?: CustomFieldValue[];
  billingInformation?: BillingInformation;
  shippingInformation?: ShippingInformation;
  paymentInfo?: PaymentInfo;
}

// Commercial order status enumeration
type CommercialOrderStatusType =
  | "DRAFT"
  | "CREATED"
  | "PROCESSING"
  | "COMPLETED"
  | "CANCELLED";

Logistic Order Types

// Main logistic order entity from SDK
interface LogisticOrder {
  id: string;
  reference: string;
  status: LogisticOrderStatusType;
  commercialOrderReference: string;
  totalPrice: number;
  totalPriceWithoutTax: number;
  totalTaxAmount: number;
  totalShippingFees: number;
  currency: string;
  createdAt: string;
  updatedAt: string;
  validationDate?: string;
  lines?: LogisticOrderLine[];
  customFields?: CustomFieldValue[];
  billingAddressSnapshot?: AddressSnapshot;
  shippingAddressSnapshot?: AddressSnapshot;
  shippingInformation?: ShippingInformation;
}

// Logistic order status enumeration
type LogisticOrderStatusType =
  | "DRAFT_ORDER"
  | "CREATING"
  | "WAITING_SUPPLIER_APPROVAL"
  | "WAITING_SHIPMENT"
  | "SHIPPED"
  | "COMPLETED"
  | "DECLINED_BY_SUPPLIER"
  | "DECLINED_BY_CUSTOMER";

// Order line entity
interface LogisticOrderLine {
  id: string;
  productId: string;
  productName: string;
  productSku: string;
  variantId: string;
  quantity: number;
  unitPrice: number;
  totalPrice: number;
  currency: string;
  status: string;
  customFields?: CustomFieldValue[];
}

Request Types

Commercial Order Requests

// Get commercial order request
interface GetCommercialOrderRequest {
  orderId: string;
  locale?: string;
  idType?: "ID" | "EXTERNAL_ID";
  nbPreviewLines?: number;
}

// Create commercial order request
interface CreateCommercialOrderRequest {
  nbPreviewLines?: number;
  channel?: string;
  customFields?: CustomFieldValue[];
  locale?: string;
  origin?: string;
  originId?: string;
  paymentInfo?: PaymentInfo;
}

// Update shipping address request
interface UpdateCommercialOrderShippingAddressRequest {
  orderId: string;
  shippingAddressId: string;
}

// Update shipping information request
interface UpdateCommercialOrderShippingInformationRequest {
  orderId: string;
  shippingInformation: ShippingInformation;
}

// Update billing information request
interface UpdateCommercialOrderBillingInformationRequest {
  orderId: string;
  billingInformation: BillingInformation;
}

// Set order status as created request
interface SetCommercialOrderStatusAsCreatedRequest {
  orderId: string;
}

Logistic Order Requests

// Get logistic orders request
interface GetLogisticOrdersRequest {
  approvalIds?: string[];
  locale?: string;
  logisticStatus?: LogisticOrderStatusType[];
  commercialOrderIds?: string[];
  supplierIds?: string[];
  sort?: string[];
  size?: number;
  page?: number;
  nbPreviewLines?: number;
}

// Get single logistic order request
interface GetLogisticOrderRequest {
  orderId: string;
  locale?: string;
  nbPreviewLines?: number;
}

// Get logistic order lines request
interface GetLogisticOrderLinesRequest {
  orderId: string;
  locale?: string;
  size?: number;
  page?: number;
  sort?: string[];
}

// Update custom fields request
interface UpdateOrderLogisticCustomFieldRequest {
  orderId: string;
  customFields: CustomFieldValue[];
}

// Create order thread request
interface CreateLogisticOrderThreadRequest {
  orderId: string;
  lineId: string;
  message: string;
  reasonCode?: string;
}

Response Types

Commercial Order Responses

// Get commercial order response
interface GetCommercialOrderResponse {
  success: boolean;
  order: CommercialOrder;
}

// Create commercial order response
interface CreateCommercialOrderResponse {
  success: boolean;
  order: CommercialOrder;
}

// Update operations response
interface UpdateCommercialOrderResponse {
  success: boolean;
  order: CommercialOrder;
  message: string;
}

Logistic Order Responses

// Get logistic orders response
interface GetLogisticOrdersResponse {
  success: boolean;
  orders: {
    content: LogisticOrder[];
    totalElements: number;
    totalPages: number;
    size: number;
    number: number;
  };
}

// Get single logistic order response
interface GetLogisticOrderResponse {
  success: boolean;
  order: LogisticOrder;
}

// Get order lines response
interface GetLogisticOrderLinesResponse {
  success: boolean;
  orderLines: {
    content: LogisticOrderLine[];
    totalElements: number;
    totalPages: number;
    size: number;
    number: number;
  };
}

// Create thread response
interface CreateLogisticOrderThreadResponse {
  success: boolean;
  thread: OrderThread;
  message: string;
}

Composable Types

useCommercialOrder Types

// API functions interface
interface CommercialOrderApi {
  getCommercialOrder: (
    params: GetCommercialOrderRequest,
    config?: Partial<DjustConfig>
  ) => Promise<GetCommercialOrderResponse>;

  createCommercialOrder: (
    params: CreateCommercialOrderRequest,
    config?: Partial<DjustConfig>
  ) => Promise<CreateCommercialOrderResponse>;

  updateCommercialOrderShippingAddress: (
    params: UpdateCommercialOrderShippingAddressRequest,
    config?: Partial<DjustConfig>
  ) => Promise<UpdateCommercialOrderResponse>;

  updateCommercialOrderShippingInfo: (
    params: UpdateCommercialOrderShippingInformationRequest,
    config?: Partial<DjustConfig>
  ) => Promise<UpdateCommercialOrderResponse>;

  updateCommercialOrderBillingInformation: (
    params: UpdateCommercialOrderBillingInformationRequest,
    config?: Partial<DjustConfig>
  ) => Promise<UpdateCommercialOrderResponse>;

  setCommercialOrderStatusAsCreated: (
    params: SetCommercialOrderStatusAsCreatedRequest,
    config?: Partial<DjustConfig>
  ) => Promise<UpdateCommercialOrderResponse>;
}

// Getter functions interface
interface CommercialOrderGetters {
  getOrderId: (order: CommercialOrder) => string;
  getOrderCreatedAt: (order: CommercialOrder) => string;
  getOrderReference: (order: CommercialOrder) => string;
  getOrderTotalShippingFees: (order: CommercialOrder) => number;
  getOrderTotalItemPrice: (order: CommercialOrder) => number;
  getOrderTotalPrice: (order: CommercialOrder) => number;
  getOrderTotalPriceWithoutTax: (order: CommercialOrder) => number;
  getOrderTotalTaxAmount: (order: CommercialOrder) => number;
  getOrderLogistics: (order: CommercialOrder) => LogisticOrder[];
  isOrderProcessing: (order: CommercialOrder) => boolean;
  getFirstOrderLogistic: (order: CommercialOrder) => LogisticOrder;
}

// Helper functions interface (currently empty)
interface CommercialOrderHelpers {}

// Complete composable interface
type UseCommercialOrder = CommercialOrderApi &
  CommercialOrderGetters &
  CommercialOrderHelpers;

useLogisticOrder Types

// API functions interface
interface LogisticOrderApi {
  createLogisticOrderLineThread: (
    params: CreateLogisticOrderThreadRequest,
    config?: Partial<DjustConfig>
  ) => Promise<CreateLogisticOrderThreadResponse>;

  getLogisticOrder: (
    params: GetLogisticOrderRequest,
    config?: Partial<DjustConfig>
  ) => Promise<GetLogisticOrderResponse>;

  getLogisticOrders: (
    params: GetLogisticOrdersRequest,
    config?: Partial<DjustConfig>
  ) => Promise<GetLogisticOrdersResponse>;

  getLogisticOrderLines: (
    params: GetLogisticOrderLinesRequest,
    config?: Partial<DjustConfig>
  ) => Promise<GetLogisticOrderLinesResponse>;

  setLogisticOrderStatusAsCreated: (
    params: SetCommercialOrderStatusAsCreatedRequest,
    config?: Partial<DjustConfig>
  ) => Promise<UpdateLogisticOrderResponse>;

  updateLogisticOrderBillingInformation: (
    params: UpdateCommercialOrderBillingInformationRequest,
    config?: Partial<DjustConfig>
  ) => Promise<UpdateLogisticOrderResponse>;

  updateLogisticOrderCustomFieldsValue: (
    params: UpdateOrderLogisticCustomFieldRequest,
    config?: Partial<DjustConfig>
  ) => Promise<UpdateLogisticOrderResponse>;

  updateLogisticOrderShippingAddress: (
    params: UpdateCommercialOrderShippingAddressRequest,
    config?: Partial<DjustConfig>
  ) => Promise<UpdateLogisticOrderResponse>;

  updateLogisticOrderShippingInfo: (
    params: UpdateCommercialOrderShippingInformationRequest,
    config?: Partial<DjustConfig>
  ) => Promise<UpdateLogisticOrderResponse>;
}

// Getter functions interface
interface LogisticOrderGetters {
  getOrderId: (order: LogisticOrder) => string;
  getOrderCreatedAt: (order: LogisticOrder) => string;
  getOrderReference: (order: LogisticOrder) => string;
  getCommercialOrderReference: (order: LogisticOrder) => string;
  getOrderLinesNb: (order: LogisticOrder) => number;
  getOrderTotalShippingFees: (order: LogisticOrder) => number;
  getOrderTotalItemPrice: (order: LogisticOrder) => number;
  getOrderTotalPrice: (order: LogisticOrder) => number;
  getOrderTotalPriceWithoutTax: (order: LogisticOrder) => number;
  getOrderTotalTaxAmount: (order: LogisticOrder) => number;
  getOrderBillingAddressSnapshot: (
    order: LogisticOrder
  ) => AddressSnapshot | null;
  getOrderShippingAddressSnapshot: (
    order: LogisticOrder
  ) => AddressSnapshot | null;
  getLogisticOrderLinesFromResponse: (
    response: GetLogisticOrderLinesResponse
  ) => LogisticOrderLine[];
}

// Helper functions interface
interface LogisticOrderHelpers {
  getOrdersByStatus: (statusList: LogisticOrderStatusType[]) => LogisticOrder[];
  getOrderLogisticCustomFieldValueByExternalId: (
    orderLogistic: LogisticOrder,
    customFieldExternalId: string
  ) => any;
  getFormattedValidationDate: (order: LogisticOrder) => string;
}

// Complete composable interface
type UseLogisticOrder = LogisticOrderApi &
  LogisticOrderGetters &
  LogisticOrderHelpers;

Store Types

Order Store State

// Pinia store state interface
interface OrderStoreState {
  orders: LogisticOrder[];
  ordersByStatus: Map<string, LogisticOrder[]>;
  orderLines: Map<string, LogisticOrderLine[]>;
}

// Store getters interface
interface OrderStoreGetters {
  getOrders: () => LogisticOrder[];
  getOrdersByStatus: (
    status: LogisticOrderStatusType
  ) => LogisticOrder[] | undefined;
  getOrderLinesById: (orderId: string) => LogisticOrderLine[] | undefined;
}

// Store actions interface
interface OrderStoreActions {
  setOrders: (orders: LogisticOrder[]) => void;
  setOrdersByStatus: (orders: LogisticOrder[]) => void;
  setOrderLines: (orderId: string, orderLines: LogisticOrderLine[]) => void;
}

Supporting Types

Address and Shipping Types

// Address snapshot for order preservation
interface AddressSnapshot {
  name: string;
  street: string;
  city: string;
  country: string;
  postalCode: string;
  region?: string;
  company?: string;
  phone?: string;
  email?: string;
}

// Shipping information
interface ShippingInformation {
  type: string;
  carrier?: string;
  trackingNumber?: string;
  estimatedDeliveryDate?: string;
  notes?: string;
}

// Billing information
interface BillingInformation {
  method: string;
  details?: any;
  notes?: string;
}

Custom Fields and Configuration

// Custom field value
interface CustomFieldValue {
  externalId: string;
  value: any;
  type: string;
  label?: string;
}

// Payment information
interface PaymentInfo {
  method: string;
  details?: any;
  amount?: number;
  currency?: string;
}

// Configuration for API calls
interface DjustConfig {
  customerAccountId?: string;
  storeId?: string;
  storeViewId?: string;
  locale?: string;
  currency?: string;
}

Error Types

API Error Types

// Standard API error interface
interface ApiError {
  message: string;
  code?: string;
  statusCode?: number;
  details?: any;
}

// Order-specific error types
interface OrderError extends ApiError {
  orderType: "commercial" | "logistic";
  operation: string;
  orderId?: string;
}

// Validation error for order operations
interface OrderValidationError extends OrderError {
  validationErrors: Array<{
    field: string;
    message: string;
    code: string;
  }>;
}

Thread Communication Types

// Order thread for communications
interface OrderThread {
  id: string;
  orderId: string;
  lineId?: string;
  message: string;
  createdAt: string;
  authorType: "CUSTOMER" | "SUPPLIER" | "ADMIN";
  reasonCode?: string;
  customFields?: CustomFieldValue[];
}

// Thread creation parameters
interface CreateThreadParams {
  orderId: string;
  lineId?: string;
  message: string;
  reasonCode?: string;
  customFields?: CustomFieldValue[];
}

This types documentation provides a complete reference for all interfaces and types used within the Orders management system, ensuring type safety and clear contracts between different parts of the application.