@labdigital/commercetools-mock 2.8.0 → 2.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +235 -41
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +32 -2
- package/dist/index.d.ts +32 -2
- package/dist/index.js +235 -41
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/lib/predicateParser.test.ts +96 -11
- package/src/lib/predicateParser.ts +43 -12
- package/src/oauth/server.ts +11 -1
- package/src/repositories/abstract.ts +5 -4
- package/src/repositories/cart.ts +77 -33
- package/src/repositories/custom-object.ts +18 -0
- package/src/repositories/shipping-method.ts +98 -22
- package/src/services/custom-object.ts +19 -0
- package/src/services/shipping-method.test.ts +120 -21
- package/src/services/shipping-method.ts +19 -2
- package/src/shippingCalculator.test.ts +280 -0
- package/src/shippingCalculator.ts +74 -0
- package/src/storage/abstract.ts +1 -1
- package/src/storage/in-memory.ts +82 -59
- package/src/types.ts +2 -0
package/dist/index.d.cts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import express from 'express';
|
|
2
2
|
import { SetupServer } from 'msw/node';
|
|
3
3
|
import * as ctp from '@commercetools/platform-sdk';
|
|
4
|
-
import { Project, ResourceIdentifier, QueryParam, AssociateRoleDraft, AssociateRole, AssociateRoleSetNameAction, AssociateRoleSetPermissionsAction, AssociateRoleChangeBuyerAssignableAction, AssociateRoleSetCustomFieldAction, AssociateRoleAddPermissionAction, AssociateRoleRemovePermissionAction, AttributeGroupDraft, AttributeGroup, AttributeGroupSetAttributesAction, AttributeGroupChangeNameAction, AttributeGroupSetDescriptionAction, AttributeGroupSetKeyAction, BusinessUnitDraft, BusinessUnit, BusinessUnitAddAddressAction, BusinessUnitAddAssociateAction, BusinessUnitSetAssociatesAction, BusinessUnitSetContactEmailAction, BusinessUnitSetStoreModeAction, BusinessUnitChangeNameAction, BusinessUnitChangeAddressAction, BusinessUnitAddStoreAction, BusinessUnitChangeParentUnitAction, BusinessUnitChangeStatusAction, CartDraft, Cart, CartAddLineItemAction, CartAddItemShippingAddressAction, CartChangeLineItemQuantityAction, CartRemoveLineItemAction, CartSetBillingAddressAction, CartSetShippingMethodAction, CartSetCountryAction, CartSetCustomerEmailAction, CartSetCustomFieldAction, CartSetCustomTypeAction, CartSetLocaleAction, CartSetLineItemShippingDetailsAction, CartSetShippingAddressAction, CartRemoveDiscountCodeAction, LineItemDraft, LineItem, CartDiscountDraft, CartDiscount, CartDiscountUpdateAction, AssetDraft, Asset, CategoryDraft, Category, CategoryChangeAssetNameAction, CategoryChangeSlugAction, CategoryChangeNameAction, CategoryChangeParentAction, CategorySetKeyAction, CategorySetAssetDescriptionAction, CategorySetAssetSourcesAction, CategorySetDescriptionAction, CategorySetMetaDescriptionAction, CategorySetMetaKeywordsAction, CategorySetMetaTitleAction, CategorySetCustomTypeAction, CategorySetCustomFieldAction, CategoryRemoveAssetAction, CategoryAddAssetAction, ChannelDraft, Channel, ChannelUpdateAction, CustomObjectDraft, CustomObject, CustomerDraft, Customer, CustomerChangeEmailAction, CustomerSetAuthenticationModeAction, CustomerSetCustomFieldAction, CustomerGroupDraft, CustomerGroup, CustomerGroupSetKeyAction, CustomerGroupChangeNameAction, CustomerGroupSetCustomTypeAction, CustomerGroupSetCustomFieldAction, DiscountCodeDraft, DiscountCode, DiscountCodeUpdateAction, Extension, ExtensionDraft, ExtensionUpdateAction, InventoryEntryDraft, InventoryEntry, InventoryEntryChangeQuantityAction, InventoryEntrySetExpectedDeliveryAction, InventoryEntrySetCustomFieldAction, InventoryEntrySetCustomTypeAction, InventoryEntrySetRestockableInDaysAction, OrderFromCartDraft, Order, CartReference, OrderImportDraft, OrderAddPaymentAction, OrderAddReturnInfoAction, OrderChangeOrderStateAction, OrderChangePaymentStateAction, OrderTransitionStateAction, OrderSetBillingAddressAction, OrderSetCustomerEmailAction, OrderSetCustomFieldAction, OrderSetCustomTypeAction, OrderSetLocaleAction, OrderSetOrderNumberAction, OrderSetShippingAddressAction, OrderSetStoreAction, MyOrderFromCartDraft, OrderEditDraft, OrderEdit, OrderEditUpdateAction, PaymentDraft, Payment, TransactionDraft, Transaction, PaymentSetCustomFieldAction, PaymentSetCustomTypeAction, PaymentAddTransactionAction, PaymentChangeTransactionStateAction, PaymentTransitionStateAction, ProductDraft, Product, ProductUpdateAction, ProductDiscountDraft, ProductDiscount, ProductDiscountUpdateAction, ProductProjectionPagedSearchResponse, ProductProjection, FacetResults, TermFacetResult, FilteredFacetResult, RangeFacetResult, ProductSelectionDraft, ProductSelection, ProductSelectionUpdateAction, ProductTypeDraft, ProductType, AttributeDefinitionDraft, AttributeDefinition, ProductTypeUpdateAction, ProjectUpdateAction, QuoteDraft, Quote, QuoteUpdateAction, QuoteRequestDraft, QuoteRequest, QuoteRequestUpdateAction, ReviewDraft, Review, ReviewUpdateAction, ShippingMethodDraft, ShippingMethod, ShippingMethodUpdateAction, ShoppingListDraft, ShoppingList, StagedQuoteDraft, StagedQuote, StagedQuoteUpdateAction, StandalonePriceDraft, StandalonePrice, ChannelResourceIdentifier, ChannelReference, DiscountedPriceDraft, StandalonePriceChangeActiveAction, StandalonePriceChangeValueAction, StandalonePriceSetDiscountedPriceAction, StateDraft, State, StateUpdateAction, StoreDraft, Store, StoreUpdateAction, SubscriptionDraft, Subscription, TaxCategoryDraft, TaxCategory, TaxCategoryUpdateAction, TypeDraft, Type, TypeUpdateAction, ZoneDraft, Zone, ZoneUpdateAction, BaseResource, UpdateAction } from '@commercetools/platform-sdk';
|
|
4
|
+
import { Project, ResourceIdentifier, QueryParam, AssociateRoleDraft, AssociateRole, AssociateRoleSetNameAction, AssociateRoleSetPermissionsAction, AssociateRoleChangeBuyerAssignableAction, AssociateRoleSetCustomFieldAction, AssociateRoleAddPermissionAction, AssociateRoleRemovePermissionAction, AttributeGroupDraft, AttributeGroup, AttributeGroupSetAttributesAction, AttributeGroupChangeNameAction, AttributeGroupSetDescriptionAction, AttributeGroupSetKeyAction, BusinessUnitDraft, BusinessUnit, BusinessUnitAddAddressAction, BusinessUnitAddAssociateAction, BusinessUnitSetAssociatesAction, BusinessUnitSetContactEmailAction, BusinessUnitSetStoreModeAction, BusinessUnitChangeNameAction, BusinessUnitChangeAddressAction, BusinessUnitAddStoreAction, BusinessUnitChangeParentUnitAction, BusinessUnitChangeStatusAction, CartDraft, Cart, CartAddLineItemAction, CartAddItemShippingAddressAction, CartChangeLineItemQuantityAction, CartRemoveLineItemAction, CartSetBillingAddressAction, CartSetShippingMethodAction, CartSetCountryAction, CartSetCustomerEmailAction, CartSetCustomFieldAction, CartSetCustomShippingMethodAction, CartSetCustomTypeAction, CartSetLocaleAction, CartSetLineItemShippingDetailsAction, CartSetShippingAddressAction, CartRemoveDiscountCodeAction, LineItemDraft, LineItem, CartDiscountDraft, CartDiscount, CartDiscountUpdateAction, AssetDraft, Asset, CategoryDraft, Category, CategoryChangeAssetNameAction, CategoryChangeSlugAction, CategoryChangeNameAction, CategoryChangeParentAction, CategorySetKeyAction, CategorySetAssetDescriptionAction, CategorySetAssetSourcesAction, CategorySetDescriptionAction, CategorySetMetaDescriptionAction, CategorySetMetaKeywordsAction, CategorySetMetaTitleAction, CategorySetCustomTypeAction, CategorySetCustomFieldAction, CategoryRemoveAssetAction, CategoryAddAssetAction, ChannelDraft, Channel, ChannelUpdateAction, CustomObjectDraft, CustomObject, CustomerDraft, Customer, CustomerChangeEmailAction, CustomerSetAuthenticationModeAction, CustomerSetCustomFieldAction, CustomerGroupDraft, CustomerGroup, CustomerGroupSetKeyAction, CustomerGroupChangeNameAction, CustomerGroupSetCustomTypeAction, CustomerGroupSetCustomFieldAction, DiscountCodeDraft, DiscountCode, DiscountCodeUpdateAction, Extension, ExtensionDraft, ExtensionUpdateAction, InventoryEntryDraft, InventoryEntry, InventoryEntryChangeQuantityAction, InventoryEntrySetExpectedDeliveryAction, InventoryEntrySetCustomFieldAction, InventoryEntrySetCustomTypeAction, InventoryEntrySetRestockableInDaysAction, OrderFromCartDraft, Order, CartReference, OrderImportDraft, OrderAddPaymentAction, OrderAddReturnInfoAction, OrderChangeOrderStateAction, OrderChangePaymentStateAction, OrderTransitionStateAction, OrderSetBillingAddressAction, OrderSetCustomerEmailAction, OrderSetCustomFieldAction, OrderSetCustomTypeAction, OrderSetLocaleAction, OrderSetOrderNumberAction, OrderSetShippingAddressAction, OrderSetStoreAction, MyOrderFromCartDraft, OrderEditDraft, OrderEdit, OrderEditUpdateAction, PaymentDraft, Payment, TransactionDraft, Transaction, PaymentSetCustomFieldAction, PaymentSetCustomTypeAction, PaymentAddTransactionAction, PaymentChangeTransactionStateAction, PaymentTransitionStateAction, ProductDraft, Product, ProductUpdateAction, ProductDiscountDraft, ProductDiscount, ProductDiscountUpdateAction, ProductProjectionPagedSearchResponse, ProductProjection, FacetResults, TermFacetResult, FilteredFacetResult, RangeFacetResult, ProductSelectionDraft, ProductSelection, ProductSelectionUpdateAction, ProductTypeDraft, ProductType, AttributeDefinitionDraft, AttributeDefinition, ProductTypeUpdateAction, ProjectUpdateAction, QuoteDraft, Quote, QuoteUpdateAction, QuoteRequestDraft, QuoteRequest, QuoteRequestUpdateAction, ReviewDraft, Review, ReviewUpdateAction, ShippingMethodDraft, ShippingMethod, ZoneReference, ShippingRate, ShippingMethodUpdateAction, ShoppingListDraft, ShoppingList, StagedQuoteDraft, StagedQuote, StagedQuoteUpdateAction, StandalonePriceDraft, StandalonePrice, ChannelResourceIdentifier, ChannelReference, DiscountedPriceDraft, StandalonePriceChangeActiveAction, StandalonePriceChangeValueAction, StandalonePriceSetDiscountedPriceAction, StateDraft, State, StateUpdateAction, StoreDraft, Store, StoreUpdateAction, SubscriptionDraft, Subscription, TaxCategoryDraft, TaxCategory, TaxCategoryUpdateAction, TypeDraft, Type, TypeUpdateAction, ZoneDraft, Zone, ZoneUpdateAction, BaseResource, UpdateAction } from '@commercetools/platform-sdk';
|
|
5
5
|
|
|
6
6
|
type GetParams$1 = {
|
|
7
7
|
expand?: string[];
|
|
@@ -26,7 +26,7 @@ declare abstract class AbstractStorage {
|
|
|
26
26
|
abstract saveProject(project: Project): Project;
|
|
27
27
|
abstract delete<RT extends ResourceType>(projectKey: string, typeId: RT, id: string, params: GetParams$1): ResourceMap[RT] | null;
|
|
28
28
|
abstract query<RT extends ResourceType>(projectKey: string, typeId: RT, params: QueryParams$1): PagedQueryResponseMap[RT];
|
|
29
|
-
abstract getByResourceIdentifier<RT extends ResourceType>(projectKey: string, identifier: ResourceIdentifier): ResourceMap[RT]
|
|
29
|
+
abstract getByResourceIdentifier<RT extends ResourceType>(projectKey: string, identifier: ResourceIdentifier): ResourceMap[RT];
|
|
30
30
|
abstract expand<T>(projectKey: string, obj: T, clause: undefined | string | string[]): T;
|
|
31
31
|
}
|
|
32
32
|
|
|
@@ -89,6 +89,7 @@ declare class CartRepository extends AbstractResourceRepository<'cart'> {
|
|
|
89
89
|
setCountry: (context: RepositoryContext, resource: Writable<Cart>, { country }: CartSetCountryAction) => void;
|
|
90
90
|
setCustomerEmail: (context: RepositoryContext, resource: Writable<Cart>, { email }: CartSetCustomerEmailAction) => void;
|
|
91
91
|
setCustomField: (context: RepositoryContext, resource: Cart, { name, value }: CartSetCustomFieldAction) => void;
|
|
92
|
+
setCustomShippingMethod: (context: RepositoryContext, resource: Writable<Cart>, { shippingMethodName, shippingRate, taxCategory, externalTaxRate, }: CartSetCustomShippingMethodAction) => void;
|
|
92
93
|
setCustomType: (context: RepositoryContext, resource: Writable<Cart>, { type, fields }: CartSetCustomTypeAction) => void;
|
|
93
94
|
setLocale: (context: RepositoryContext, resource: Writable<Cart>, { locale }: CartSetLocaleAction) => void;
|
|
94
95
|
setLineItemShippingDetails: (context: RepositoryContext, resource: Writable<Cart>, { action, shippingDetails, lineItemId, lineItemKey, }: CartSetLineItemShippingDetailsAction) => void;
|
|
@@ -137,6 +138,7 @@ declare class ChannelRepository extends AbstractResourceRepository<'channel'> {
|
|
|
137
138
|
declare class CustomObjectRepository extends AbstractResourceRepository<'key-value-document'> {
|
|
138
139
|
getTypeId(): "key-value-document";
|
|
139
140
|
create(context: RepositoryContext, draft: Writable<CustomObjectDraft>): CustomObject;
|
|
141
|
+
queryWithContainer(context: RepositoryContext, container: string, params?: QueryParams): ctp.CustomObjectPagedQueryResponse;
|
|
140
142
|
getWithContainerAndKey(context: RepositoryContext, container: string, key: string): CustomObject | undefined;
|
|
141
143
|
}
|
|
142
144
|
|
|
@@ -380,6 +382,33 @@ declare class ShippingMethodRepository extends AbstractResourceRepository<'shipp
|
|
|
380
382
|
create(context: RepositoryContext, draft: ShippingMethodDraft): ShippingMethod;
|
|
381
383
|
private _transformZoneRateDraft;
|
|
382
384
|
private _transformShippingRate;
|
|
385
|
+
matchingCart(context: RepositoryContext, cartId: string, params?: GetParams): {
|
|
386
|
+
results: {
|
|
387
|
+
zoneRates: {
|
|
388
|
+
zone: ZoneReference;
|
|
389
|
+
shippingRates: ShippingRate[];
|
|
390
|
+
}[];
|
|
391
|
+
id: string;
|
|
392
|
+
version: number;
|
|
393
|
+
createdAt: string;
|
|
394
|
+
lastModifiedAt: string;
|
|
395
|
+
lastModifiedBy?: ctp.LastModifiedBy | undefined;
|
|
396
|
+
createdBy?: ctp.CreatedBy | undefined;
|
|
397
|
+
key?: string | undefined;
|
|
398
|
+
name: string;
|
|
399
|
+
localizedName?: ctp.LocalizedString | undefined;
|
|
400
|
+
description?: string | undefined;
|
|
401
|
+
localizedDescription?: ctp.LocalizedString | undefined;
|
|
402
|
+
taxCategory: ctp.TaxCategoryReference;
|
|
403
|
+
isDefault: boolean;
|
|
404
|
+
predicate?: string | undefined;
|
|
405
|
+
custom?: ctp.CustomFields | undefined;
|
|
406
|
+
}[];
|
|
407
|
+
limit?: number | undefined;
|
|
408
|
+
count: number;
|
|
409
|
+
total?: number | undefined;
|
|
410
|
+
offset?: number | undefined;
|
|
411
|
+
} | undefined;
|
|
383
412
|
actions: Partial<Record<ShippingMethodUpdateAction['action'], (context: RepositoryContext, resource: Writable<ShippingMethod>, action: any) => void>>;
|
|
384
413
|
}
|
|
385
414
|
|
|
@@ -581,6 +610,7 @@ type QueryParams = {
|
|
|
581
610
|
where?: string[];
|
|
582
611
|
offset?: number;
|
|
583
612
|
limit?: number;
|
|
613
|
+
[key: string]: QueryParam;
|
|
584
614
|
};
|
|
585
615
|
type GetParams = {
|
|
586
616
|
expand?: string[];
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import express from 'express';
|
|
2
2
|
import { SetupServer } from 'msw/node';
|
|
3
3
|
import * as ctp from '@commercetools/platform-sdk';
|
|
4
|
-
import { Project, ResourceIdentifier, QueryParam, AssociateRoleDraft, AssociateRole, AssociateRoleSetNameAction, AssociateRoleSetPermissionsAction, AssociateRoleChangeBuyerAssignableAction, AssociateRoleSetCustomFieldAction, AssociateRoleAddPermissionAction, AssociateRoleRemovePermissionAction, AttributeGroupDraft, AttributeGroup, AttributeGroupSetAttributesAction, AttributeGroupChangeNameAction, AttributeGroupSetDescriptionAction, AttributeGroupSetKeyAction, BusinessUnitDraft, BusinessUnit, BusinessUnitAddAddressAction, BusinessUnitAddAssociateAction, BusinessUnitSetAssociatesAction, BusinessUnitSetContactEmailAction, BusinessUnitSetStoreModeAction, BusinessUnitChangeNameAction, BusinessUnitChangeAddressAction, BusinessUnitAddStoreAction, BusinessUnitChangeParentUnitAction, BusinessUnitChangeStatusAction, CartDraft, Cart, CartAddLineItemAction, CartAddItemShippingAddressAction, CartChangeLineItemQuantityAction, CartRemoveLineItemAction, CartSetBillingAddressAction, CartSetShippingMethodAction, CartSetCountryAction, CartSetCustomerEmailAction, CartSetCustomFieldAction, CartSetCustomTypeAction, CartSetLocaleAction, CartSetLineItemShippingDetailsAction, CartSetShippingAddressAction, CartRemoveDiscountCodeAction, LineItemDraft, LineItem, CartDiscountDraft, CartDiscount, CartDiscountUpdateAction, AssetDraft, Asset, CategoryDraft, Category, CategoryChangeAssetNameAction, CategoryChangeSlugAction, CategoryChangeNameAction, CategoryChangeParentAction, CategorySetKeyAction, CategorySetAssetDescriptionAction, CategorySetAssetSourcesAction, CategorySetDescriptionAction, CategorySetMetaDescriptionAction, CategorySetMetaKeywordsAction, CategorySetMetaTitleAction, CategorySetCustomTypeAction, CategorySetCustomFieldAction, CategoryRemoveAssetAction, CategoryAddAssetAction, ChannelDraft, Channel, ChannelUpdateAction, CustomObjectDraft, CustomObject, CustomerDraft, Customer, CustomerChangeEmailAction, CustomerSetAuthenticationModeAction, CustomerSetCustomFieldAction, CustomerGroupDraft, CustomerGroup, CustomerGroupSetKeyAction, CustomerGroupChangeNameAction, CustomerGroupSetCustomTypeAction, CustomerGroupSetCustomFieldAction, DiscountCodeDraft, DiscountCode, DiscountCodeUpdateAction, Extension, ExtensionDraft, ExtensionUpdateAction, InventoryEntryDraft, InventoryEntry, InventoryEntryChangeQuantityAction, InventoryEntrySetExpectedDeliveryAction, InventoryEntrySetCustomFieldAction, InventoryEntrySetCustomTypeAction, InventoryEntrySetRestockableInDaysAction, OrderFromCartDraft, Order, CartReference, OrderImportDraft, OrderAddPaymentAction, OrderAddReturnInfoAction, OrderChangeOrderStateAction, OrderChangePaymentStateAction, OrderTransitionStateAction, OrderSetBillingAddressAction, OrderSetCustomerEmailAction, OrderSetCustomFieldAction, OrderSetCustomTypeAction, OrderSetLocaleAction, OrderSetOrderNumberAction, OrderSetShippingAddressAction, OrderSetStoreAction, MyOrderFromCartDraft, OrderEditDraft, OrderEdit, OrderEditUpdateAction, PaymentDraft, Payment, TransactionDraft, Transaction, PaymentSetCustomFieldAction, PaymentSetCustomTypeAction, PaymentAddTransactionAction, PaymentChangeTransactionStateAction, PaymentTransitionStateAction, ProductDraft, Product, ProductUpdateAction, ProductDiscountDraft, ProductDiscount, ProductDiscountUpdateAction, ProductProjectionPagedSearchResponse, ProductProjection, FacetResults, TermFacetResult, FilteredFacetResult, RangeFacetResult, ProductSelectionDraft, ProductSelection, ProductSelectionUpdateAction, ProductTypeDraft, ProductType, AttributeDefinitionDraft, AttributeDefinition, ProductTypeUpdateAction, ProjectUpdateAction, QuoteDraft, Quote, QuoteUpdateAction, QuoteRequestDraft, QuoteRequest, QuoteRequestUpdateAction, ReviewDraft, Review, ReviewUpdateAction, ShippingMethodDraft, ShippingMethod, ShippingMethodUpdateAction, ShoppingListDraft, ShoppingList, StagedQuoteDraft, StagedQuote, StagedQuoteUpdateAction, StandalonePriceDraft, StandalonePrice, ChannelResourceIdentifier, ChannelReference, DiscountedPriceDraft, StandalonePriceChangeActiveAction, StandalonePriceChangeValueAction, StandalonePriceSetDiscountedPriceAction, StateDraft, State, StateUpdateAction, StoreDraft, Store, StoreUpdateAction, SubscriptionDraft, Subscription, TaxCategoryDraft, TaxCategory, TaxCategoryUpdateAction, TypeDraft, Type, TypeUpdateAction, ZoneDraft, Zone, ZoneUpdateAction, BaseResource, UpdateAction } from '@commercetools/platform-sdk';
|
|
4
|
+
import { Project, ResourceIdentifier, QueryParam, AssociateRoleDraft, AssociateRole, AssociateRoleSetNameAction, AssociateRoleSetPermissionsAction, AssociateRoleChangeBuyerAssignableAction, AssociateRoleSetCustomFieldAction, AssociateRoleAddPermissionAction, AssociateRoleRemovePermissionAction, AttributeGroupDraft, AttributeGroup, AttributeGroupSetAttributesAction, AttributeGroupChangeNameAction, AttributeGroupSetDescriptionAction, AttributeGroupSetKeyAction, BusinessUnitDraft, BusinessUnit, BusinessUnitAddAddressAction, BusinessUnitAddAssociateAction, BusinessUnitSetAssociatesAction, BusinessUnitSetContactEmailAction, BusinessUnitSetStoreModeAction, BusinessUnitChangeNameAction, BusinessUnitChangeAddressAction, BusinessUnitAddStoreAction, BusinessUnitChangeParentUnitAction, BusinessUnitChangeStatusAction, CartDraft, Cart, CartAddLineItemAction, CartAddItemShippingAddressAction, CartChangeLineItemQuantityAction, CartRemoveLineItemAction, CartSetBillingAddressAction, CartSetShippingMethodAction, CartSetCountryAction, CartSetCustomerEmailAction, CartSetCustomFieldAction, CartSetCustomShippingMethodAction, CartSetCustomTypeAction, CartSetLocaleAction, CartSetLineItemShippingDetailsAction, CartSetShippingAddressAction, CartRemoveDiscountCodeAction, LineItemDraft, LineItem, CartDiscountDraft, CartDiscount, CartDiscountUpdateAction, AssetDraft, Asset, CategoryDraft, Category, CategoryChangeAssetNameAction, CategoryChangeSlugAction, CategoryChangeNameAction, CategoryChangeParentAction, CategorySetKeyAction, CategorySetAssetDescriptionAction, CategorySetAssetSourcesAction, CategorySetDescriptionAction, CategorySetMetaDescriptionAction, CategorySetMetaKeywordsAction, CategorySetMetaTitleAction, CategorySetCustomTypeAction, CategorySetCustomFieldAction, CategoryRemoveAssetAction, CategoryAddAssetAction, ChannelDraft, Channel, ChannelUpdateAction, CustomObjectDraft, CustomObject, CustomerDraft, Customer, CustomerChangeEmailAction, CustomerSetAuthenticationModeAction, CustomerSetCustomFieldAction, CustomerGroupDraft, CustomerGroup, CustomerGroupSetKeyAction, CustomerGroupChangeNameAction, CustomerGroupSetCustomTypeAction, CustomerGroupSetCustomFieldAction, DiscountCodeDraft, DiscountCode, DiscountCodeUpdateAction, Extension, ExtensionDraft, ExtensionUpdateAction, InventoryEntryDraft, InventoryEntry, InventoryEntryChangeQuantityAction, InventoryEntrySetExpectedDeliveryAction, InventoryEntrySetCustomFieldAction, InventoryEntrySetCustomTypeAction, InventoryEntrySetRestockableInDaysAction, OrderFromCartDraft, Order, CartReference, OrderImportDraft, OrderAddPaymentAction, OrderAddReturnInfoAction, OrderChangeOrderStateAction, OrderChangePaymentStateAction, OrderTransitionStateAction, OrderSetBillingAddressAction, OrderSetCustomerEmailAction, OrderSetCustomFieldAction, OrderSetCustomTypeAction, OrderSetLocaleAction, OrderSetOrderNumberAction, OrderSetShippingAddressAction, OrderSetStoreAction, MyOrderFromCartDraft, OrderEditDraft, OrderEdit, OrderEditUpdateAction, PaymentDraft, Payment, TransactionDraft, Transaction, PaymentSetCustomFieldAction, PaymentSetCustomTypeAction, PaymentAddTransactionAction, PaymentChangeTransactionStateAction, PaymentTransitionStateAction, ProductDraft, Product, ProductUpdateAction, ProductDiscountDraft, ProductDiscount, ProductDiscountUpdateAction, ProductProjectionPagedSearchResponse, ProductProjection, FacetResults, TermFacetResult, FilteredFacetResult, RangeFacetResult, ProductSelectionDraft, ProductSelection, ProductSelectionUpdateAction, ProductTypeDraft, ProductType, AttributeDefinitionDraft, AttributeDefinition, ProductTypeUpdateAction, ProjectUpdateAction, QuoteDraft, Quote, QuoteUpdateAction, QuoteRequestDraft, QuoteRequest, QuoteRequestUpdateAction, ReviewDraft, Review, ReviewUpdateAction, ShippingMethodDraft, ShippingMethod, ZoneReference, ShippingRate, ShippingMethodUpdateAction, ShoppingListDraft, ShoppingList, StagedQuoteDraft, StagedQuote, StagedQuoteUpdateAction, StandalonePriceDraft, StandalonePrice, ChannelResourceIdentifier, ChannelReference, DiscountedPriceDraft, StandalonePriceChangeActiveAction, StandalonePriceChangeValueAction, StandalonePriceSetDiscountedPriceAction, StateDraft, State, StateUpdateAction, StoreDraft, Store, StoreUpdateAction, SubscriptionDraft, Subscription, TaxCategoryDraft, TaxCategory, TaxCategoryUpdateAction, TypeDraft, Type, TypeUpdateAction, ZoneDraft, Zone, ZoneUpdateAction, BaseResource, UpdateAction } from '@commercetools/platform-sdk';
|
|
5
5
|
|
|
6
6
|
type GetParams$1 = {
|
|
7
7
|
expand?: string[];
|
|
@@ -26,7 +26,7 @@ declare abstract class AbstractStorage {
|
|
|
26
26
|
abstract saveProject(project: Project): Project;
|
|
27
27
|
abstract delete<RT extends ResourceType>(projectKey: string, typeId: RT, id: string, params: GetParams$1): ResourceMap[RT] | null;
|
|
28
28
|
abstract query<RT extends ResourceType>(projectKey: string, typeId: RT, params: QueryParams$1): PagedQueryResponseMap[RT];
|
|
29
|
-
abstract getByResourceIdentifier<RT extends ResourceType>(projectKey: string, identifier: ResourceIdentifier): ResourceMap[RT]
|
|
29
|
+
abstract getByResourceIdentifier<RT extends ResourceType>(projectKey: string, identifier: ResourceIdentifier): ResourceMap[RT];
|
|
30
30
|
abstract expand<T>(projectKey: string, obj: T, clause: undefined | string | string[]): T;
|
|
31
31
|
}
|
|
32
32
|
|
|
@@ -89,6 +89,7 @@ declare class CartRepository extends AbstractResourceRepository<'cart'> {
|
|
|
89
89
|
setCountry: (context: RepositoryContext, resource: Writable<Cart>, { country }: CartSetCountryAction) => void;
|
|
90
90
|
setCustomerEmail: (context: RepositoryContext, resource: Writable<Cart>, { email }: CartSetCustomerEmailAction) => void;
|
|
91
91
|
setCustomField: (context: RepositoryContext, resource: Cart, { name, value }: CartSetCustomFieldAction) => void;
|
|
92
|
+
setCustomShippingMethod: (context: RepositoryContext, resource: Writable<Cart>, { shippingMethodName, shippingRate, taxCategory, externalTaxRate, }: CartSetCustomShippingMethodAction) => void;
|
|
92
93
|
setCustomType: (context: RepositoryContext, resource: Writable<Cart>, { type, fields }: CartSetCustomTypeAction) => void;
|
|
93
94
|
setLocale: (context: RepositoryContext, resource: Writable<Cart>, { locale }: CartSetLocaleAction) => void;
|
|
94
95
|
setLineItemShippingDetails: (context: RepositoryContext, resource: Writable<Cart>, { action, shippingDetails, lineItemId, lineItemKey, }: CartSetLineItemShippingDetailsAction) => void;
|
|
@@ -137,6 +138,7 @@ declare class ChannelRepository extends AbstractResourceRepository<'channel'> {
|
|
|
137
138
|
declare class CustomObjectRepository extends AbstractResourceRepository<'key-value-document'> {
|
|
138
139
|
getTypeId(): "key-value-document";
|
|
139
140
|
create(context: RepositoryContext, draft: Writable<CustomObjectDraft>): CustomObject;
|
|
141
|
+
queryWithContainer(context: RepositoryContext, container: string, params?: QueryParams): ctp.CustomObjectPagedQueryResponse;
|
|
140
142
|
getWithContainerAndKey(context: RepositoryContext, container: string, key: string): CustomObject | undefined;
|
|
141
143
|
}
|
|
142
144
|
|
|
@@ -380,6 +382,33 @@ declare class ShippingMethodRepository extends AbstractResourceRepository<'shipp
|
|
|
380
382
|
create(context: RepositoryContext, draft: ShippingMethodDraft): ShippingMethod;
|
|
381
383
|
private _transformZoneRateDraft;
|
|
382
384
|
private _transformShippingRate;
|
|
385
|
+
matchingCart(context: RepositoryContext, cartId: string, params?: GetParams): {
|
|
386
|
+
results: {
|
|
387
|
+
zoneRates: {
|
|
388
|
+
zone: ZoneReference;
|
|
389
|
+
shippingRates: ShippingRate[];
|
|
390
|
+
}[];
|
|
391
|
+
id: string;
|
|
392
|
+
version: number;
|
|
393
|
+
createdAt: string;
|
|
394
|
+
lastModifiedAt: string;
|
|
395
|
+
lastModifiedBy?: ctp.LastModifiedBy | undefined;
|
|
396
|
+
createdBy?: ctp.CreatedBy | undefined;
|
|
397
|
+
key?: string | undefined;
|
|
398
|
+
name: string;
|
|
399
|
+
localizedName?: ctp.LocalizedString | undefined;
|
|
400
|
+
description?: string | undefined;
|
|
401
|
+
localizedDescription?: ctp.LocalizedString | undefined;
|
|
402
|
+
taxCategory: ctp.TaxCategoryReference;
|
|
403
|
+
isDefault: boolean;
|
|
404
|
+
predicate?: string | undefined;
|
|
405
|
+
custom?: ctp.CustomFields | undefined;
|
|
406
|
+
}[];
|
|
407
|
+
limit?: number | undefined;
|
|
408
|
+
count: number;
|
|
409
|
+
total?: number | undefined;
|
|
410
|
+
offset?: number | undefined;
|
|
411
|
+
} | undefined;
|
|
383
412
|
actions: Partial<Record<ShippingMethodUpdateAction['action'], (context: RepositoryContext, resource: Writable<ShippingMethod>, action: any) => void>>;
|
|
384
413
|
}
|
|
385
414
|
|
|
@@ -581,6 +610,7 @@ type QueryParams = {
|
|
|
581
610
|
where?: string[];
|
|
582
611
|
offset?: number;
|
|
583
612
|
limit?: number;
|
|
613
|
+
[key: string]: QueryParam;
|
|
584
614
|
};
|
|
585
615
|
type GetParams = {
|
|
586
616
|
expand?: string[];
|
package/dist/index.js
CHANGED
|
@@ -683,7 +683,7 @@ var resolveValue = (obj, val) => {
|
|
|
683
683
|
if (Array.isArray(obj)) {
|
|
684
684
|
return Object.values(obj).filter((v) => val.value in v).map((v) => v[val.value]);
|
|
685
685
|
}
|
|
686
|
-
|
|
686
|
+
return void 0;
|
|
687
687
|
}
|
|
688
688
|
return obj[val.value];
|
|
689
689
|
};
|
|
@@ -763,22 +763,43 @@ var generateMatchFunc = (predicate) => {
|
|
|
763
763
|
const expr = parser.parse();
|
|
764
764
|
lexer.expect(")");
|
|
765
765
|
return (obj, vars) => {
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
766
|
+
if (Array.isArray(obj)) {
|
|
767
|
+
return obj.some((item) => {
|
|
768
|
+
const value = resolveValue(item, left);
|
|
769
|
+
if (value) {
|
|
770
|
+
return expr(value, vars);
|
|
771
|
+
}
|
|
772
|
+
return false;
|
|
773
|
+
});
|
|
774
|
+
} else {
|
|
775
|
+
const value = resolveValue(obj, left);
|
|
776
|
+
if (value) {
|
|
777
|
+
return expr(value, vars);
|
|
778
|
+
}
|
|
779
|
+
return false;
|
|
769
780
|
}
|
|
770
|
-
return false;
|
|
771
781
|
};
|
|
772
782
|
}).bp(")", 0).led("=", 20, ({ left, bp }) => {
|
|
773
783
|
const expr = parser.parse({ terminals: [bp - 1] });
|
|
774
784
|
validateSymbol(expr);
|
|
775
785
|
return (obj, vars) => {
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
786
|
+
if (Array.isArray(obj)) {
|
|
787
|
+
return obj.some((item) => {
|
|
788
|
+
const value = resolveValue(item, left);
|
|
789
|
+
const other = resolveSymbol(expr, vars);
|
|
790
|
+
if (Array.isArray(value)) {
|
|
791
|
+
return !!value.some((elem) => elem === other);
|
|
792
|
+
}
|
|
793
|
+
return value === other;
|
|
794
|
+
});
|
|
795
|
+
} else {
|
|
796
|
+
const resolvedValue = resolveValue(obj, left);
|
|
797
|
+
const resolvedSymbol = resolveSymbol(expr, vars);
|
|
798
|
+
if (Array.isArray(resolvedValue)) {
|
|
799
|
+
return !!resolvedValue.some((elem) => elem === resolvedSymbol);
|
|
800
|
+
}
|
|
801
|
+
return resolvedValue === resolvedSymbol;
|
|
780
802
|
}
|
|
781
|
-
return resolvedValue === resolvedSymbol;
|
|
782
803
|
};
|
|
783
804
|
}).led("!=", 20, ({ left, bp }) => {
|
|
784
805
|
const expr = parser.parse({ terminals: [bp - 1] });
|
|
@@ -846,10 +867,11 @@ var generateMatchFunc = (predicate) => {
|
|
|
846
867
|
if (!Array.isArray(symbols)) {
|
|
847
868
|
symbols = [expr];
|
|
848
869
|
}
|
|
849
|
-
const inValues = symbols.
|
|
870
|
+
const inValues = symbols.flatMap(
|
|
850
871
|
(item) => resolveSymbol(item, vars)
|
|
851
872
|
);
|
|
852
|
-
|
|
873
|
+
const value = resolveValue(obj, left);
|
|
874
|
+
return inValues.includes(value);
|
|
853
875
|
};
|
|
854
876
|
}).led("MATCHES_IGNORE_CASE", 20, ({ left, bp }) => {
|
|
855
877
|
const expr = parser.parse({ terminals: [bp - 1] });
|
|
@@ -1027,9 +1049,12 @@ var InMemoryStorage = class extends AbstractStorage {
|
|
|
1027
1049
|
}
|
|
1028
1050
|
let resources = this.all(projectKey, typeId);
|
|
1029
1051
|
if (params.where) {
|
|
1052
|
+
const vars = Object.fromEntries(
|
|
1053
|
+
Object.entries(params).filter(([key]) => key.startsWith("var.")).map(([key, value]) => [key.slice(4), value])
|
|
1054
|
+
);
|
|
1030
1055
|
try {
|
|
1031
1056
|
const filterFunc = parseQueryExpression(params.where);
|
|
1032
|
-
resources = resources.filter((resource) => filterFunc(resource,
|
|
1057
|
+
resources = resources.filter((resource) => filterFunc(resource, vars));
|
|
1033
1058
|
} catch (err) {
|
|
1034
1059
|
throw new CommercetoolsError(
|
|
1035
1060
|
{
|
|
@@ -1096,28 +1121,34 @@ var InMemoryStorage = class extends AbstractStorage {
|
|
|
1096
1121
|
if (resource) {
|
|
1097
1122
|
return resource;
|
|
1098
1123
|
}
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1124
|
+
throw new CommercetoolsError({
|
|
1125
|
+
code: "ReferencedResourceNotFound",
|
|
1126
|
+
message: `The referenced object of type '${identifier.typeId}' with id '${identifier.id}' was not found. It either doesn't exist, or it can't be accessed from this endpoint (e.g., if the endpoint filters by store or customer account).`,
|
|
1127
|
+
typeId: identifier.typeId,
|
|
1128
|
+
id: identifier.id
|
|
1129
|
+
});
|
|
1103
1130
|
}
|
|
1104
1131
|
if (identifier.key) {
|
|
1105
|
-
const
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
return resource;
|
|
1113
|
-
}
|
|
1114
|
-
} else {
|
|
1115
|
-
throw new Error(
|
|
1116
|
-
`No storage found for resource type: ${identifier.typeId}`
|
|
1117
|
-
);
|
|
1132
|
+
const resource = this.getByKey(
|
|
1133
|
+
projectKey,
|
|
1134
|
+
identifier.typeId,
|
|
1135
|
+
identifier.key
|
|
1136
|
+
);
|
|
1137
|
+
if (resource) {
|
|
1138
|
+
return resource;
|
|
1118
1139
|
}
|
|
1140
|
+
throw new CommercetoolsError({
|
|
1141
|
+
code: "ReferencedResourceNotFound",
|
|
1142
|
+
message: `The referenced object of type '${identifier.typeId}' with key '${identifier.key}' was not found. It either doesn't exist, or it can't be accessed from this endpoint (e.g., if the endpoint filters by store or customer account).`,
|
|
1143
|
+
typeId: identifier.typeId,
|
|
1144
|
+
key: identifier.key
|
|
1145
|
+
});
|
|
1119
1146
|
}
|
|
1120
|
-
|
|
1147
|
+
throw new CommercetoolsError({
|
|
1148
|
+
code: "InvalidJsonInput",
|
|
1149
|
+
message: "Request body does not contain valid JSON.",
|
|
1150
|
+
detailedErrorMessage: "ResourceIdentifier requires an 'id' xor a 'key'"
|
|
1151
|
+
});
|
|
1121
1152
|
}
|
|
1122
1153
|
addProject = (projectKey) => {
|
|
1123
1154
|
if (!this.projects[projectKey]) {
|
|
@@ -1271,11 +1302,12 @@ var hashPassword = (clearPassword) => Buffer.from(clearPassword).toString("base6
|
|
|
1271
1302
|
|
|
1272
1303
|
// src/oauth/server.ts
|
|
1273
1304
|
var OAuth2Server = class {
|
|
1274
|
-
store;
|
|
1275
|
-
customerRepository;
|
|
1276
1305
|
constructor(options) {
|
|
1306
|
+
this.options = options;
|
|
1277
1307
|
this.store = new OAuth2Store(options.validate);
|
|
1278
1308
|
}
|
|
1309
|
+
store;
|
|
1310
|
+
customerRepository;
|
|
1279
1311
|
setCustomerRepository(repository) {
|
|
1280
1312
|
this.customerRepository = repository;
|
|
1281
1313
|
}
|
|
@@ -1299,6 +1331,11 @@ var OAuth2Server = class {
|
|
|
1299
1331
|
return router;
|
|
1300
1332
|
}
|
|
1301
1333
|
createMiddleware() {
|
|
1334
|
+
if (!this.options.validate) {
|
|
1335
|
+
return async (request, response, next) => {
|
|
1336
|
+
next();
|
|
1337
|
+
};
|
|
1338
|
+
}
|
|
1302
1339
|
return async (request, response, next) => {
|
|
1303
1340
|
const token = getBearerToken(request);
|
|
1304
1341
|
if (!token) {
|
|
@@ -1836,10 +1873,7 @@ var AbstractResourceRepository = class extends AbstractRepository {
|
|
|
1836
1873
|
}
|
|
1837
1874
|
query(context, params = {}) {
|
|
1838
1875
|
const result = this._storage.query(context.projectKey, this.getTypeId(), {
|
|
1839
|
-
|
|
1840
|
-
where: params.where,
|
|
1841
|
-
offset: params.offset,
|
|
1842
|
-
limit: params.limit
|
|
1876
|
+
...params
|
|
1843
1877
|
});
|
|
1844
1878
|
result.results = result.results.map(this.postProcessResource);
|
|
1845
1879
|
return result;
|
|
@@ -2159,6 +2193,11 @@ var CartRepository = class extends AbstractResourceRepository {
|
|
|
2159
2193
|
fractionDigits: 0
|
|
2160
2194
|
},
|
|
2161
2195
|
shippingMode: "Single",
|
|
2196
|
+
shippingAddress: createAddress(
|
|
2197
|
+
draft.shippingAddress,
|
|
2198
|
+
context.projectKey,
|
|
2199
|
+
this._storage
|
|
2200
|
+
),
|
|
2162
2201
|
shipping: [],
|
|
2163
2202
|
origin: draft.origin ?? "Customer",
|
|
2164
2203
|
refusedGifts: [],
|
|
@@ -2360,9 +2399,6 @@ var CartRepository = class extends AbstractResourceRepository {
|
|
|
2360
2399
|
context.projectKey,
|
|
2361
2400
|
shippingMethod
|
|
2362
2401
|
);
|
|
2363
|
-
if (!method) {
|
|
2364
|
-
throw new Error(`Type ${shippingMethod} not found`);
|
|
2365
|
-
}
|
|
2366
2402
|
resource.shippingInfo = {
|
|
2367
2403
|
shippingMethod: {
|
|
2368
2404
|
typeId: "shipping-method",
|
|
@@ -2386,6 +2422,33 @@ var CartRepository = class extends AbstractResourceRepository {
|
|
|
2386
2422
|
}
|
|
2387
2423
|
resource.custom.fields[name] = value;
|
|
2388
2424
|
},
|
|
2425
|
+
setCustomShippingMethod: (context, resource, {
|
|
2426
|
+
shippingMethodName,
|
|
2427
|
+
shippingRate,
|
|
2428
|
+
taxCategory,
|
|
2429
|
+
externalTaxRate
|
|
2430
|
+
}) => {
|
|
2431
|
+
if (externalTaxRate) {
|
|
2432
|
+
throw new Error("External tax rate is not supported");
|
|
2433
|
+
}
|
|
2434
|
+
const tax = taxCategory ? this._storage.getByResourceIdentifier(
|
|
2435
|
+
context.projectKey,
|
|
2436
|
+
taxCategory
|
|
2437
|
+
) : void 0;
|
|
2438
|
+
resource.shippingInfo = {
|
|
2439
|
+
shippingMethodName,
|
|
2440
|
+
price: createCentPrecisionMoney(shippingRate.price),
|
|
2441
|
+
shippingRate: {
|
|
2442
|
+
price: createTypedMoney(shippingRate.price),
|
|
2443
|
+
tiers: []
|
|
2444
|
+
},
|
|
2445
|
+
taxCategory: tax ? {
|
|
2446
|
+
typeId: "tax-category",
|
|
2447
|
+
id: tax?.id
|
|
2448
|
+
} : void 0,
|
|
2449
|
+
shippingMethodState: "MatchesCart"
|
|
2450
|
+
};
|
|
2451
|
+
},
|
|
2389
2452
|
setCustomType: (context, resource, { type, fields }) => {
|
|
2390
2453
|
if (!type) {
|
|
2391
2454
|
resource.custom = void 0;
|
|
@@ -2937,6 +3000,16 @@ var CustomObjectRepository = class extends AbstractResourceRepository {
|
|
|
2937
3000
|
return resource;
|
|
2938
3001
|
}
|
|
2939
3002
|
}
|
|
3003
|
+
queryWithContainer(context, container, params = {}) {
|
|
3004
|
+
const whereClause = params.where || [];
|
|
3005
|
+
whereClause.push(`container="${container}"`);
|
|
3006
|
+
const result = this._storage.query(context.projectKey, this.getTypeId(), {
|
|
3007
|
+
...params,
|
|
3008
|
+
where: whereClause
|
|
3009
|
+
});
|
|
3010
|
+
result.results = result.results.map(this.postProcessResource);
|
|
3011
|
+
return result;
|
|
3012
|
+
}
|
|
2940
3013
|
getWithContainerAndKey(context, container, key) {
|
|
2941
3014
|
const items = this._storage.all(context.projectKey, this.getTypeId());
|
|
2942
3015
|
return items.find(
|
|
@@ -5465,6 +5538,50 @@ var ReviewRepository = class extends AbstractResourceRepository {
|
|
|
5465
5538
|
|
|
5466
5539
|
// src/repositories/shipping-method.ts
|
|
5467
5540
|
import deepEqual3 from "deep-equal";
|
|
5541
|
+
|
|
5542
|
+
// src/shippingCalculator.ts
|
|
5543
|
+
var markMatchingShippingRate = (cart, shippingRate) => {
|
|
5544
|
+
const isMatching = shippingRate.price.currencyCode === cart.totalPrice.currencyCode;
|
|
5545
|
+
return {
|
|
5546
|
+
...shippingRate,
|
|
5547
|
+
tiers: markMatchingShippingRatePriceTiers(cart, shippingRate.tiers),
|
|
5548
|
+
isMatching
|
|
5549
|
+
};
|
|
5550
|
+
};
|
|
5551
|
+
var markMatchingShippingRatePriceTiers = (cart, tiers) => {
|
|
5552
|
+
if (tiers.length === 0) {
|
|
5553
|
+
return [];
|
|
5554
|
+
}
|
|
5555
|
+
if (new Set(tiers.map((tier) => tier.type)).size > 1) {
|
|
5556
|
+
throw new Error("Can't handle multiple types of tiers");
|
|
5557
|
+
}
|
|
5558
|
+
const tierType = tiers[0].type;
|
|
5559
|
+
switch (tierType) {
|
|
5560
|
+
case "CartValue":
|
|
5561
|
+
return markMatchingCartValueTiers(cart, tiers);
|
|
5562
|
+
default:
|
|
5563
|
+
throw new Error(`Unsupported tier type: ${tierType}`);
|
|
5564
|
+
}
|
|
5565
|
+
};
|
|
5566
|
+
var markMatchingCartValueTiers = (cart, tiers) => {
|
|
5567
|
+
const sortedTiers = [...tiers].sort(
|
|
5568
|
+
(a, b) => b.minimumCentAmount - a.minimumCentAmount
|
|
5569
|
+
);
|
|
5570
|
+
const result = {};
|
|
5571
|
+
let hasMatchingTier = false;
|
|
5572
|
+
for (const tier of sortedTiers) {
|
|
5573
|
+
const isMatching = !hasMatchingTier && cart.totalPrice.currencyCode === tier.price.currencyCode && cart.totalPrice.centAmount >= tier.minimumCentAmount;
|
|
5574
|
+
if (isMatching)
|
|
5575
|
+
hasMatchingTier = true;
|
|
5576
|
+
result[tier.minimumCentAmount] = {
|
|
5577
|
+
...tier,
|
|
5578
|
+
isMatching
|
|
5579
|
+
};
|
|
5580
|
+
}
|
|
5581
|
+
return tiers.map((tier) => result[tier.minimumCentAmount]);
|
|
5582
|
+
};
|
|
5583
|
+
|
|
5584
|
+
// src/repositories/shipping-method.ts
|
|
5468
5585
|
var ShippingMethodRepository = class extends AbstractResourceRepository {
|
|
5469
5586
|
getTypeId() {
|
|
5470
5587
|
return "shipping-method";
|
|
@@ -5504,6 +5621,53 @@ var ShippingMethodRepository = class extends AbstractResourceRepository {
|
|
|
5504
5621
|
freeAbove: rate.freeAbove && createTypedMoney(rate.freeAbove),
|
|
5505
5622
|
tiers: rate.tiers || []
|
|
5506
5623
|
});
|
|
5624
|
+
/*
|
|
5625
|
+
* Retrieves all the ShippingMethods that can ship to the shipping address of
|
|
5626
|
+
* the given Cart. Each ShippingMethod contains exactly one ShippingRate with
|
|
5627
|
+
* the flag isMatching set to true. This ShippingRate is used when the
|
|
5628
|
+
* ShippingMethod is added to the Cart.
|
|
5629
|
+
*/
|
|
5630
|
+
matchingCart(context, cartId, params = {}) {
|
|
5631
|
+
const cart = this._storage.get(context.projectKey, "cart", cartId);
|
|
5632
|
+
if (!cart) {
|
|
5633
|
+
return void 0;
|
|
5634
|
+
}
|
|
5635
|
+
if (!cart.shippingAddress?.country) {
|
|
5636
|
+
throw new CommercetoolsError({
|
|
5637
|
+
code: "InvalidOperation",
|
|
5638
|
+
message: `The cart with ID '${cart.id}' does not have a shipping address set.`
|
|
5639
|
+
});
|
|
5640
|
+
}
|
|
5641
|
+
const zones = this._storage.query(context.projectKey, "zone", {
|
|
5642
|
+
where: [`locations(country="${cart.shippingAddress.country}"))`],
|
|
5643
|
+
limit: 100
|
|
5644
|
+
});
|
|
5645
|
+
const zoneIds = zones.results.map((zone) => zone.id);
|
|
5646
|
+
const shippingMethods = this.query(context, {
|
|
5647
|
+
where: [
|
|
5648
|
+
`zoneRates(zone(id in (:zoneIds)))`,
|
|
5649
|
+
`zoneRates(shippingRates(price(currencyCode="${cart.totalPrice.currencyCode}")))`
|
|
5650
|
+
],
|
|
5651
|
+
"var.zoneIds": zoneIds,
|
|
5652
|
+
expand: params.expand
|
|
5653
|
+
});
|
|
5654
|
+
const results = shippingMethods.results.map((shippingMethod) => {
|
|
5655
|
+
const rates = shippingMethod.zoneRates.map((zoneRate) => ({
|
|
5656
|
+
zone: zoneRate.zone,
|
|
5657
|
+
// Iterate through the shippingRates and mark the matching ones
|
|
5658
|
+
// then we filter out the non-matching ones
|
|
5659
|
+
shippingRates: zoneRate.shippingRates.map((rate) => markMatchingShippingRate(cart, rate)).filter((rate) => rate.isMatching)
|
|
5660
|
+
})).filter((zoneRate) => zoneRate.shippingRates.length > 0);
|
|
5661
|
+
return {
|
|
5662
|
+
...shippingMethod,
|
|
5663
|
+
zoneRates: rates
|
|
5664
|
+
};
|
|
5665
|
+
}).filter((shippingMethod) => shippingMethod.zoneRates.length > 0);
|
|
5666
|
+
return {
|
|
5667
|
+
...shippingMethods,
|
|
5668
|
+
results
|
|
5669
|
+
};
|
|
5670
|
+
}
|
|
5507
5671
|
actions = {
|
|
5508
5672
|
addShippingRate: (_context, resource, { shippingRate, zone }) => {
|
|
5509
5673
|
const rate = this._transformShippingRate(shippingRate);
|
|
@@ -6357,10 +6521,26 @@ var CustomObjectService = class extends AbstractService {
|
|
|
6357
6521
|
return "custom-objects";
|
|
6358
6522
|
}
|
|
6359
6523
|
extraRoutes(router) {
|
|
6524
|
+
router.get("/:container", this.getWithContainer.bind(this));
|
|
6360
6525
|
router.get("/:container/:key", this.getWithContainerAndKey.bind(this));
|
|
6361
6526
|
router.post("/:container/:key", this.createWithContainerAndKey.bind(this));
|
|
6362
6527
|
router.delete("/:container/:key", this.deleteWithContainerAndKey.bind(this));
|
|
6363
6528
|
}
|
|
6529
|
+
getWithContainer(request, response) {
|
|
6530
|
+
const limit = this._parseParam(request.query.limit);
|
|
6531
|
+
const offset = this._parseParam(request.query.offset);
|
|
6532
|
+
const result = this.repository.queryWithContainer(
|
|
6533
|
+
getRepositoryContext(request),
|
|
6534
|
+
request.params.container,
|
|
6535
|
+
{
|
|
6536
|
+
expand: this._parseParam(request.query.expand),
|
|
6537
|
+
where: this._parseParam(request.query.where),
|
|
6538
|
+
limit: limit !== void 0 ? Number(limit) : void 0,
|
|
6539
|
+
offset: offset !== void 0 ? Number(offset) : void 0
|
|
6540
|
+
}
|
|
6541
|
+
);
|
|
6542
|
+
return response.status(200).send(result);
|
|
6543
|
+
}
|
|
6364
6544
|
getWithContainerAndKey(request, response) {
|
|
6365
6545
|
const result = this.repository.getWithContainerAndKey(
|
|
6366
6546
|
getRepositoryContext(request),
|
|
@@ -6799,7 +6979,21 @@ var ShippingMethodService = class extends AbstractService {
|
|
|
6799
6979
|
return "shipping-methods";
|
|
6800
6980
|
}
|
|
6801
6981
|
extraRoutes(parent) {
|
|
6802
|
-
parent.get("/matching-cart", this.
|
|
6982
|
+
parent.get("/matching-cart", this.matchingCart.bind(this));
|
|
6983
|
+
}
|
|
6984
|
+
matchingCart(request, response) {
|
|
6985
|
+
const cartId = queryParamsValue(request.query.cartId);
|
|
6986
|
+
if (!cartId) {
|
|
6987
|
+
return response.status(400).send();
|
|
6988
|
+
}
|
|
6989
|
+
const result = this.repository.matchingCart(
|
|
6990
|
+
getRepositoryContext(request),
|
|
6991
|
+
cartId,
|
|
6992
|
+
{
|
|
6993
|
+
expand: this._parseParam(request.query.expand)
|
|
6994
|
+
}
|
|
6995
|
+
);
|
|
6996
|
+
return response.status(200).send(result);
|
|
6803
6997
|
}
|
|
6804
6998
|
};
|
|
6805
6999
|
|