import { EntityManager } from "typeorm"; import { ProductVariantInventoryService, ShippingProfileService } from "."; import { TransactionBaseService } from "../interfaces"; import { Fulfillment, LineItem, ShippingMethod } from "../models"; import { FulfillmentRepository } from "../repositories/fulfillment"; import { LineItemRepository } from "../repositories/line-item"; import { TrackingLinkRepository } from "../repositories/tracking-link"; import { FindConfig } from "../types/common"; import { CreateFulfillmentOrder, CreateShipmentConfig, FulfillmentItemPartition, FulFillmentItemType } from "../types/fulfillment"; import FulfillmentProviderService from "./fulfillment-provider"; import LineItemService from "./line-item"; import TotalsService from "./totals"; type InjectedDependencies = { manager: EntityManager; totalsService: TotalsService; shippingProfileService: ShippingProfileService; lineItemService: LineItemService; fulfillmentProviderService: FulfillmentProviderService; fulfillmentRepository: typeof FulfillmentRepository; trackingLinkRepository: typeof TrackingLinkRepository; lineItemRepository: typeof LineItemRepository; productVariantInventoryService: ProductVariantInventoryService; }; /** * Handles Fulfillments */ declare class FulfillmentService extends TransactionBaseService { protected readonly totalsService_: TotalsService; protected readonly lineItemService_: LineItemService; protected readonly shippingProfileService_: ShippingProfileService; protected readonly fulfillmentProviderService_: FulfillmentProviderService; protected readonly fulfillmentRepository_: typeof FulfillmentRepository; protected readonly trackingLinkRepository_: typeof TrackingLinkRepository; protected readonly lineItemRepository_: typeof LineItemRepository; protected readonly productVariantInventoryService_: ProductVariantInventoryService; constructor({ totalsService, fulfillmentRepository, trackingLinkRepository, shippingProfileService, lineItemService, fulfillmentProviderService, lineItemRepository, productVariantInventoryService, }: InjectedDependencies); partitionItems_(shippingMethods: ShippingMethod[], items: LineItem[]): FulfillmentItemPartition[]; /** * Retrieves the order line items, given an array of items. * @param order - the order to get line items from * @param items - the items to get * @param transformer - a function to apply to each of the items * retrieved from the order, should return a line item. If the transformer * returns an undefined value the line item will be filtered from the * returned array. * @return the line items generated by the transformer. */ getFulfillmentItems_(order: CreateFulfillmentOrder, items: FulFillmentItemType[]): Promise<(LineItem | null)[]>; /** * Checks that a given quantity of a line item can be fulfilled. Fails if the * fulfillable quantity is lower than the requested fulfillment quantity. * Fulfillable quantity is calculated by subtracting the already fulfilled * quantity from the quantity that was originally purchased. * @param item - the line item to check has sufficient fulfillable * quantity. * @param quantity - the quantity that is requested to be fulfilled. * @return a line item that has the requested fulfillment quantity * set. */ validateFulfillmentLineItem_(item: LineItem | undefined, quantity: number): LineItem | null; /** * Retrieves a fulfillment by its id. * @param fulfillmentId - the id of the fulfillment to retrieve * @param config - optional values to include with fulfillmentRepository query * @return the fulfillment */ retrieve(fulfillmentId: string, config?: FindConfig): Promise; /** * Creates an order fulfillment * If items needs to be fulfilled by different provider, we make * sure to partition those items, and create fulfillment for * those partitions. * @param order - order to create fulfillment for * @param itemsToFulfill - the items in the order to fulfill * @param custom - potential custom values to add * @return the created fulfillments */ createFulfillment(order: CreateFulfillmentOrder, itemsToFulfill: FulFillmentItemType[], custom?: Partial): Promise; /** * Cancels a fulfillment with the fulfillment provider. Will decrement the * fulfillment_quantity on the line items associated with the fulfillment. * Throws if the fulfillment has already been shipped. * @param fulfillmentOrId - the fulfillment object or id. * @return the result of the save operation * */ cancelFulfillment(fulfillmentOrId: Fulfillment | string): Promise; /** * Creates a shipment by marking a fulfillment as shipped. Adds * tracking links and potentially more metadata. * @param fulfillmentId - the fulfillment to ship * @param trackingLinks - tracking links for the shipment * @param config - potential configuration settings, such as no_notification and metadata * @return the shipped fulfillment */ createShipment(fulfillmentId: string, trackingLinks?: { tracking_number: string; }[], config?: CreateShipmentConfig): Promise; } export default FulfillmentService;