ordercloud-api / ordercloud-javascript-sdk

The official Javascript SDK for the OrderCloud eCommerce platform
MIT License
16 stars 15 forks source link

Enhancement Idea - Reduce number of generic parameters in models #78

Open oliverheywood451 opened 1 year ago

oliverheywood451 commented 1 year ago

This is a minor enhancement idea. If you look at models in the C# SDK, type parameters are handled slightly better (IMHO). OrderWorksheet is a good comparison because its so complex

    public class OrderWorksheet<TOrder, TLineItems, TOrderPromotions, TShipEstimateResponse, TOrderCalculateResponse, TOrderSubmitResponse, TOrderSubmitForApprovalResponse, TOrderApprovedResponse> : OrderWorksheet
        where TOrder : Order
        where TLineItems : LineItem
        where TOrderPromotions : OrderPromotion
        where TShipEstimateResponse : ShipEstimateResponse
        where TOrderCalculateResponse : OrderCalculateResponse
        where TOrderSubmitResponse : OrderSubmitResponse
        where TOrderSubmitForApprovalResponse : OrderSubmitForApprovalResponse
        where TOrderApprovedResponse : OrderApprovedResponse
    {
              ....
        }
export interface OrderWorksheet<TFromUserXp = any, TBillingAddressXp = any, TOrderXp = any, TProductXp = any, TVariantXp = any, TShippingAddressXp = any, TShipFromAddressXp = any, TLineItemsXp = any, TOrderPromotionsXp = any, TShipEstimatesXp = any, TShipEstimateResponseXp = any, TOrderCalculateResponseXp = any, TOrderSubmitResponseXp = any, TOrderSubmitForApprovalResponseXp = any, TOrderApprovedResponseXp = any> {
    Order?: Order<TOrderXp,TFromUserXp,TBillingAddressXp>
    LineItems?: LineItem<TLineItemsXp,TProductXp,TVariantXp,TShippingAddressXp,TShipFromAddressXp>[]
    OrderPromotions?: OrderPromotion<TOrderPromotionsXp>[]
    ShipEstimateResponse?: ShipEstimateResponse<TShipEstimateResponseXp,TShipEstimatesXp>
    OrderCalculateResponse?: OrderCalculateResponse<TOrderCalculateResponseXp>
    OrderSubmitResponse?: OrderSubmitResponse<TOrderSubmitResponseXp>
    OrderSubmitForApprovalResponse?: OrderSubmitForApprovalResponse<TOrderSubmitForApprovalResponseXp>
    OrderApprovedResponse?: OrderApprovedResponse<TOrderApprovedResponseXp>
}

In the C# sdk types are expected that extend the SDK models like Order and LineItem. In the JS sdk types are expected that hold the xp fields. This means there are more type arguments. The C# method is less verbose in the sdk code and in the client project code.

It also does require the creation of models like interface MyOrderPromotion extends OrderPromotion<MyOrderPromotionsXp> { }

oliverheywood451 commented 1 year ago

Thought of this because I saw there were breaking changes happening anyway ;)

crhistianramirez commented 1 year ago

@oliverheywood451 would be open to including this but honestly won't have any free time to dedicate to this for the next week or so. If you have bandwidth and are willing to add this functionality I will merge it in.