@labdigital/commercetools-mock 2.8.0 → 2.10.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/README.md +9 -4
- package/dist/index.cjs +237 -41
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +33 -2
- package/dist/index.d.ts +33 -2
- package/dist/index.js +237 -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 +86 -33
- package/src/repositories/custom-object.ts +18 -0
- package/src/repositories/shipping-method.ts +98 -22
- package/src/services/cart.test.ts +24 -0
- 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
|
|
|
@@ -81,6 +81,7 @@ declare class CartRepository extends AbstractResourceRepository<'cart'> {
|
|
|
81
81
|
getActiveCart(projectKey: string): Cart | undefined;
|
|
82
82
|
actions: {
|
|
83
83
|
addLineItem: (context: RepositoryContext, resource: Writable<Cart>, { productId, variantId, sku, quantity }: CartAddLineItemAction) => void;
|
|
84
|
+
recalculate: () => void;
|
|
84
85
|
addItemShippingAddress: (context: RepositoryContext, resource: Writable<Cart>, { action, address }: CartAddItemShippingAddressAction) => void;
|
|
85
86
|
changeLineItemQuantity: (context: RepositoryContext, resource: Writable<Cart>, { lineItemId, lineItemKey, quantity }: CartChangeLineItemQuantityAction) => void;
|
|
86
87
|
removeLineItem: (context: RepositoryContext, resource: Writable<Cart>, { lineItemId, quantity }: CartRemoveLineItemAction) => void;
|
|
@@ -89,6 +90,7 @@ declare class CartRepository extends AbstractResourceRepository<'cart'> {
|
|
|
89
90
|
setCountry: (context: RepositoryContext, resource: Writable<Cart>, { country }: CartSetCountryAction) => void;
|
|
90
91
|
setCustomerEmail: (context: RepositoryContext, resource: Writable<Cart>, { email }: CartSetCustomerEmailAction) => void;
|
|
91
92
|
setCustomField: (context: RepositoryContext, resource: Cart, { name, value }: CartSetCustomFieldAction) => void;
|
|
93
|
+
setCustomShippingMethod: (context: RepositoryContext, resource: Writable<Cart>, { shippingMethodName, shippingRate, taxCategory, externalTaxRate, }: CartSetCustomShippingMethodAction) => void;
|
|
92
94
|
setCustomType: (context: RepositoryContext, resource: Writable<Cart>, { type, fields }: CartSetCustomTypeAction) => void;
|
|
93
95
|
setLocale: (context: RepositoryContext, resource: Writable<Cart>, { locale }: CartSetLocaleAction) => void;
|
|
94
96
|
setLineItemShippingDetails: (context: RepositoryContext, resource: Writable<Cart>, { action, shippingDetails, lineItemId, lineItemKey, }: CartSetLineItemShippingDetailsAction) => void;
|
|
@@ -137,6 +139,7 @@ declare class ChannelRepository extends AbstractResourceRepository<'channel'> {
|
|
|
137
139
|
declare class CustomObjectRepository extends AbstractResourceRepository<'key-value-document'> {
|
|
138
140
|
getTypeId(): "key-value-document";
|
|
139
141
|
create(context: RepositoryContext, draft: Writable<CustomObjectDraft>): CustomObject;
|
|
142
|
+
queryWithContainer(context: RepositoryContext, container: string, params?: QueryParams): ctp.CustomObjectPagedQueryResponse;
|
|
140
143
|
getWithContainerAndKey(context: RepositoryContext, container: string, key: string): CustomObject | undefined;
|
|
141
144
|
}
|
|
142
145
|
|
|
@@ -380,6 +383,33 @@ declare class ShippingMethodRepository extends AbstractResourceRepository<'shipp
|
|
|
380
383
|
create(context: RepositoryContext, draft: ShippingMethodDraft): ShippingMethod;
|
|
381
384
|
private _transformZoneRateDraft;
|
|
382
385
|
private _transformShippingRate;
|
|
386
|
+
matchingCart(context: RepositoryContext, cartId: string, params?: GetParams): {
|
|
387
|
+
results: {
|
|
388
|
+
zoneRates: {
|
|
389
|
+
zone: ZoneReference;
|
|
390
|
+
shippingRates: ShippingRate[];
|
|
391
|
+
}[];
|
|
392
|
+
id: string;
|
|
393
|
+
version: number;
|
|
394
|
+
createdAt: string;
|
|
395
|
+
lastModifiedAt: string;
|
|
396
|
+
lastModifiedBy?: ctp.LastModifiedBy | undefined;
|
|
397
|
+
createdBy?: ctp.CreatedBy | undefined;
|
|
398
|
+
key?: string | undefined;
|
|
399
|
+
name: string;
|
|
400
|
+
localizedName?: ctp.LocalizedString | undefined;
|
|
401
|
+
description?: string | undefined;
|
|
402
|
+
localizedDescription?: ctp.LocalizedString | undefined;
|
|
403
|
+
taxCategory: ctp.TaxCategoryReference;
|
|
404
|
+
isDefault: boolean;
|
|
405
|
+
predicate?: string | undefined;
|
|
406
|
+
custom?: ctp.CustomFields | undefined;
|
|
407
|
+
}[];
|
|
408
|
+
limit?: number | undefined;
|
|
409
|
+
count: number;
|
|
410
|
+
total?: number | undefined;
|
|
411
|
+
offset?: number | undefined;
|
|
412
|
+
} | undefined;
|
|
383
413
|
actions: Partial<Record<ShippingMethodUpdateAction['action'], (context: RepositoryContext, resource: Writable<ShippingMethod>, action: any) => void>>;
|
|
384
414
|
}
|
|
385
415
|
|
|
@@ -581,6 +611,7 @@ type QueryParams = {
|
|
|
581
611
|
where?: string[];
|
|
582
612
|
offset?: number;
|
|
583
613
|
limit?: number;
|
|
614
|
+
[key: string]: QueryParam;
|
|
584
615
|
};
|
|
585
616
|
type GetParams = {
|
|
586
617
|
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
|
|
|
@@ -81,6 +81,7 @@ declare class CartRepository extends AbstractResourceRepository<'cart'> {
|
|
|
81
81
|
getActiveCart(projectKey: string): Cart | undefined;
|
|
82
82
|
actions: {
|
|
83
83
|
addLineItem: (context: RepositoryContext, resource: Writable<Cart>, { productId, variantId, sku, quantity }: CartAddLineItemAction) => void;
|
|
84
|
+
recalculate: () => void;
|
|
84
85
|
addItemShippingAddress: (context: RepositoryContext, resource: Writable<Cart>, { action, address }: CartAddItemShippingAddressAction) => void;
|
|
85
86
|
changeLineItemQuantity: (context: RepositoryContext, resource: Writable<Cart>, { lineItemId, lineItemKey, quantity }: CartChangeLineItemQuantityAction) => void;
|
|
86
87
|
removeLineItem: (context: RepositoryContext, resource: Writable<Cart>, { lineItemId, quantity }: CartRemoveLineItemAction) => void;
|
|
@@ -89,6 +90,7 @@ declare class CartRepository extends AbstractResourceRepository<'cart'> {
|
|
|
89
90
|
setCountry: (context: RepositoryContext, resource: Writable<Cart>, { country }: CartSetCountryAction) => void;
|
|
90
91
|
setCustomerEmail: (context: RepositoryContext, resource: Writable<Cart>, { email }: CartSetCustomerEmailAction) => void;
|
|
91
92
|
setCustomField: (context: RepositoryContext, resource: Cart, { name, value }: CartSetCustomFieldAction) => void;
|
|
93
|
+
setCustomShippingMethod: (context: RepositoryContext, resource: Writable<Cart>, { shippingMethodName, shippingRate, taxCategory, externalTaxRate, }: CartSetCustomShippingMethodAction) => void;
|
|
92
94
|
setCustomType: (context: RepositoryContext, resource: Writable<Cart>, { type, fields }: CartSetCustomTypeAction) => void;
|
|
93
95
|
setLocale: (context: RepositoryContext, resource: Writable<Cart>, { locale }: CartSetLocaleAction) => void;
|
|
94
96
|
setLineItemShippingDetails: (context: RepositoryContext, resource: Writable<Cart>, { action, shippingDetails, lineItemId, lineItemKey, }: CartSetLineItemShippingDetailsAction) => void;
|
|
@@ -137,6 +139,7 @@ declare class ChannelRepository extends AbstractResourceRepository<'channel'> {
|
|
|
137
139
|
declare class CustomObjectRepository extends AbstractResourceRepository<'key-value-document'> {
|
|
138
140
|
getTypeId(): "key-value-document";
|
|
139
141
|
create(context: RepositoryContext, draft: Writable<CustomObjectDraft>): CustomObject;
|
|
142
|
+
queryWithContainer(context: RepositoryContext, container: string, params?: QueryParams): ctp.CustomObjectPagedQueryResponse;
|
|
140
143
|
getWithContainerAndKey(context: RepositoryContext, container: string, key: string): CustomObject | undefined;
|
|
141
144
|
}
|
|
142
145
|
|
|
@@ -380,6 +383,33 @@ declare class ShippingMethodRepository extends AbstractResourceRepository<'shipp
|
|
|
380
383
|
create(context: RepositoryContext, draft: ShippingMethodDraft): ShippingMethod;
|
|
381
384
|
private _transformZoneRateDraft;
|
|
382
385
|
private _transformShippingRate;
|
|
386
|
+
matchingCart(context: RepositoryContext, cartId: string, params?: GetParams): {
|
|
387
|
+
results: {
|
|
388
|
+
zoneRates: {
|
|
389
|
+
zone: ZoneReference;
|
|
390
|
+
shippingRates: ShippingRate[];
|
|
391
|
+
}[];
|
|
392
|
+
id: string;
|
|
393
|
+
version: number;
|
|
394
|
+
createdAt: string;
|
|
395
|
+
lastModifiedAt: string;
|
|
396
|
+
lastModifiedBy?: ctp.LastModifiedBy | undefined;
|
|
397
|
+
createdBy?: ctp.CreatedBy | undefined;
|
|
398
|
+
key?: string | undefined;
|
|
399
|
+
name: string;
|
|
400
|
+
localizedName?: ctp.LocalizedString | undefined;
|
|
401
|
+
description?: string | undefined;
|
|
402
|
+
localizedDescription?: ctp.LocalizedString | undefined;
|
|
403
|
+
taxCategory: ctp.TaxCategoryReference;
|
|
404
|
+
isDefault: boolean;
|
|
405
|
+
predicate?: string | undefined;
|
|
406
|
+
custom?: ctp.CustomFields | undefined;
|
|
407
|
+
}[];
|
|
408
|
+
limit?: number | undefined;
|
|
409
|
+
count: number;
|
|
410
|
+
total?: number | undefined;
|
|
411
|
+
offset?: number | undefined;
|
|
412
|
+
} | undefined;
|
|
383
413
|
actions: Partial<Record<ShippingMethodUpdateAction['action'], (context: RepositoryContext, resource: Writable<ShippingMethod>, action: any) => void>>;
|
|
384
414
|
}
|
|
385
415
|
|
|
@@ -581,6 +611,7 @@ type QueryParams = {
|
|
|
581
611
|
where?: string[];
|
|
582
612
|
offset?: number;
|
|
583
613
|
limit?: number;
|
|
614
|
+
[key: string]: QueryParam;
|
|
584
615
|
};
|
|
585
616
|
type GetParams = {
|
|
586
617
|
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: [],
|
|
@@ -2276,6 +2315,8 @@ var CartRepository = class extends AbstractResourceRepository {
|
|
|
2276
2315
|
}
|
|
2277
2316
|
resource.totalPrice.centAmount = calculateCartTotalPrice(resource);
|
|
2278
2317
|
},
|
|
2318
|
+
recalculate: () => {
|
|
2319
|
+
},
|
|
2279
2320
|
addItemShippingAddress: (context, resource, { action, address }) => {
|
|
2280
2321
|
const newAddress = createAddress(
|
|
2281
2322
|
address,
|
|
@@ -2360,9 +2401,6 @@ var CartRepository = class extends AbstractResourceRepository {
|
|
|
2360
2401
|
context.projectKey,
|
|
2361
2402
|
shippingMethod
|
|
2362
2403
|
);
|
|
2363
|
-
if (!method) {
|
|
2364
|
-
throw new Error(`Type ${shippingMethod} not found`);
|
|
2365
|
-
}
|
|
2366
2404
|
resource.shippingInfo = {
|
|
2367
2405
|
shippingMethod: {
|
|
2368
2406
|
typeId: "shipping-method",
|
|
@@ -2386,6 +2424,33 @@ var CartRepository = class extends AbstractResourceRepository {
|
|
|
2386
2424
|
}
|
|
2387
2425
|
resource.custom.fields[name] = value;
|
|
2388
2426
|
},
|
|
2427
|
+
setCustomShippingMethod: (context, resource, {
|
|
2428
|
+
shippingMethodName,
|
|
2429
|
+
shippingRate,
|
|
2430
|
+
taxCategory,
|
|
2431
|
+
externalTaxRate
|
|
2432
|
+
}) => {
|
|
2433
|
+
if (externalTaxRate) {
|
|
2434
|
+
throw new Error("External tax rate is not supported");
|
|
2435
|
+
}
|
|
2436
|
+
const tax = taxCategory ? this._storage.getByResourceIdentifier(
|
|
2437
|
+
context.projectKey,
|
|
2438
|
+
taxCategory
|
|
2439
|
+
) : void 0;
|
|
2440
|
+
resource.shippingInfo = {
|
|
2441
|
+
shippingMethodName,
|
|
2442
|
+
price: createCentPrecisionMoney(shippingRate.price),
|
|
2443
|
+
shippingRate: {
|
|
2444
|
+
price: createTypedMoney(shippingRate.price),
|
|
2445
|
+
tiers: []
|
|
2446
|
+
},
|
|
2447
|
+
taxCategory: tax ? {
|
|
2448
|
+
typeId: "tax-category",
|
|
2449
|
+
id: tax?.id
|
|
2450
|
+
} : void 0,
|
|
2451
|
+
shippingMethodState: "MatchesCart"
|
|
2452
|
+
};
|
|
2453
|
+
},
|
|
2389
2454
|
setCustomType: (context, resource, { type, fields }) => {
|
|
2390
2455
|
if (!type) {
|
|
2391
2456
|
resource.custom = void 0;
|
|
@@ -2937,6 +3002,16 @@ var CustomObjectRepository = class extends AbstractResourceRepository {
|
|
|
2937
3002
|
return resource;
|
|
2938
3003
|
}
|
|
2939
3004
|
}
|
|
3005
|
+
queryWithContainer(context, container, params = {}) {
|
|
3006
|
+
const whereClause = params.where || [];
|
|
3007
|
+
whereClause.push(`container="${container}"`);
|
|
3008
|
+
const result = this._storage.query(context.projectKey, this.getTypeId(), {
|
|
3009
|
+
...params,
|
|
3010
|
+
where: whereClause
|
|
3011
|
+
});
|
|
3012
|
+
result.results = result.results.map(this.postProcessResource);
|
|
3013
|
+
return result;
|
|
3014
|
+
}
|
|
2940
3015
|
getWithContainerAndKey(context, container, key) {
|
|
2941
3016
|
const items = this._storage.all(context.projectKey, this.getTypeId());
|
|
2942
3017
|
return items.find(
|
|
@@ -5465,6 +5540,50 @@ var ReviewRepository = class extends AbstractResourceRepository {
|
|
|
5465
5540
|
|
|
5466
5541
|
// src/repositories/shipping-method.ts
|
|
5467
5542
|
import deepEqual3 from "deep-equal";
|
|
5543
|
+
|
|
5544
|
+
// src/shippingCalculator.ts
|
|
5545
|
+
var markMatchingShippingRate = (cart, shippingRate) => {
|
|
5546
|
+
const isMatching = shippingRate.price.currencyCode === cart.totalPrice.currencyCode;
|
|
5547
|
+
return {
|
|
5548
|
+
...shippingRate,
|
|
5549
|
+
tiers: markMatchingShippingRatePriceTiers(cart, shippingRate.tiers),
|
|
5550
|
+
isMatching
|
|
5551
|
+
};
|
|
5552
|
+
};
|
|
5553
|
+
var markMatchingShippingRatePriceTiers = (cart, tiers) => {
|
|
5554
|
+
if (tiers.length === 0) {
|
|
5555
|
+
return [];
|
|
5556
|
+
}
|
|
5557
|
+
if (new Set(tiers.map((tier) => tier.type)).size > 1) {
|
|
5558
|
+
throw new Error("Can't handle multiple types of tiers");
|
|
5559
|
+
}
|
|
5560
|
+
const tierType = tiers[0].type;
|
|
5561
|
+
switch (tierType) {
|
|
5562
|
+
case "CartValue":
|
|
5563
|
+
return markMatchingCartValueTiers(cart, tiers);
|
|
5564
|
+
default:
|
|
5565
|
+
throw new Error(`Unsupported tier type: ${tierType}`);
|
|
5566
|
+
}
|
|
5567
|
+
};
|
|
5568
|
+
var markMatchingCartValueTiers = (cart, tiers) => {
|
|
5569
|
+
const sortedTiers = [...tiers].sort(
|
|
5570
|
+
(a, b) => b.minimumCentAmount - a.minimumCentAmount
|
|
5571
|
+
);
|
|
5572
|
+
const result = {};
|
|
5573
|
+
let hasMatchingTier = false;
|
|
5574
|
+
for (const tier of sortedTiers) {
|
|
5575
|
+
const isMatching = !hasMatchingTier && cart.totalPrice.currencyCode === tier.price.currencyCode && cart.totalPrice.centAmount >= tier.minimumCentAmount;
|
|
5576
|
+
if (isMatching)
|
|
5577
|
+
hasMatchingTier = true;
|
|
5578
|
+
result[tier.minimumCentAmount] = {
|
|
5579
|
+
...tier,
|
|
5580
|
+
isMatching
|
|
5581
|
+
};
|
|
5582
|
+
}
|
|
5583
|
+
return tiers.map((tier) => result[tier.minimumCentAmount]);
|
|
5584
|
+
};
|
|
5585
|
+
|
|
5586
|
+
// src/repositories/shipping-method.ts
|
|
5468
5587
|
var ShippingMethodRepository = class extends AbstractResourceRepository {
|
|
5469
5588
|
getTypeId() {
|
|
5470
5589
|
return "shipping-method";
|
|
@@ -5504,6 +5623,53 @@ var ShippingMethodRepository = class extends AbstractResourceRepository {
|
|
|
5504
5623
|
freeAbove: rate.freeAbove && createTypedMoney(rate.freeAbove),
|
|
5505
5624
|
tiers: rate.tiers || []
|
|
5506
5625
|
});
|
|
5626
|
+
/*
|
|
5627
|
+
* Retrieves all the ShippingMethods that can ship to the shipping address of
|
|
5628
|
+
* the given Cart. Each ShippingMethod contains exactly one ShippingRate with
|
|
5629
|
+
* the flag isMatching set to true. This ShippingRate is used when the
|
|
5630
|
+
* ShippingMethod is added to the Cart.
|
|
5631
|
+
*/
|
|
5632
|
+
matchingCart(context, cartId, params = {}) {
|
|
5633
|
+
const cart = this._storage.get(context.projectKey, "cart", cartId);
|
|
5634
|
+
if (!cart) {
|
|
5635
|
+
return void 0;
|
|
5636
|
+
}
|
|
5637
|
+
if (!cart.shippingAddress?.country) {
|
|
5638
|
+
throw new CommercetoolsError({
|
|
5639
|
+
code: "InvalidOperation",
|
|
5640
|
+
message: `The cart with ID '${cart.id}' does not have a shipping address set.`
|
|
5641
|
+
});
|
|
5642
|
+
}
|
|
5643
|
+
const zones = this._storage.query(context.projectKey, "zone", {
|
|
5644
|
+
where: [`locations(country="${cart.shippingAddress.country}"))`],
|
|
5645
|
+
limit: 100
|
|
5646
|
+
});
|
|
5647
|
+
const zoneIds = zones.results.map((zone) => zone.id);
|
|
5648
|
+
const shippingMethods = this.query(context, {
|
|
5649
|
+
where: [
|
|
5650
|
+
`zoneRates(zone(id in (:zoneIds)))`,
|
|
5651
|
+
`zoneRates(shippingRates(price(currencyCode="${cart.totalPrice.currencyCode}")))`
|
|
5652
|
+
],
|
|
5653
|
+
"var.zoneIds": zoneIds,
|
|
5654
|
+
expand: params.expand
|
|
5655
|
+
});
|
|
5656
|
+
const results = shippingMethods.results.map((shippingMethod) => {
|
|
5657
|
+
const rates = shippingMethod.zoneRates.map((zoneRate) => ({
|
|
5658
|
+
zone: zoneRate.zone,
|
|
5659
|
+
// Iterate through the shippingRates and mark the matching ones
|
|
5660
|
+
// then we filter out the non-matching ones
|
|
5661
|
+
shippingRates: zoneRate.shippingRates.map((rate) => markMatchingShippingRate(cart, rate)).filter((rate) => rate.isMatching)
|
|
5662
|
+
})).filter((zoneRate) => zoneRate.shippingRates.length > 0);
|
|
5663
|
+
return {
|
|
5664
|
+
...shippingMethod,
|
|
5665
|
+
zoneRates: rates
|
|
5666
|
+
};
|
|
5667
|
+
}).filter((shippingMethod) => shippingMethod.zoneRates.length > 0);
|
|
5668
|
+
return {
|
|
5669
|
+
...shippingMethods,
|
|
5670
|
+
results
|
|
5671
|
+
};
|
|
5672
|
+
}
|
|
5507
5673
|
actions = {
|
|
5508
5674
|
addShippingRate: (_context, resource, { shippingRate, zone }) => {
|
|
5509
5675
|
const rate = this._transformShippingRate(shippingRate);
|
|
@@ -6357,10 +6523,26 @@ var CustomObjectService = class extends AbstractService {
|
|
|
6357
6523
|
return "custom-objects";
|
|
6358
6524
|
}
|
|
6359
6525
|
extraRoutes(router) {
|
|
6526
|
+
router.get("/:container", this.getWithContainer.bind(this));
|
|
6360
6527
|
router.get("/:container/:key", this.getWithContainerAndKey.bind(this));
|
|
6361
6528
|
router.post("/:container/:key", this.createWithContainerAndKey.bind(this));
|
|
6362
6529
|
router.delete("/:container/:key", this.deleteWithContainerAndKey.bind(this));
|
|
6363
6530
|
}
|
|
6531
|
+
getWithContainer(request, response) {
|
|
6532
|
+
const limit = this._parseParam(request.query.limit);
|
|
6533
|
+
const offset = this._parseParam(request.query.offset);
|
|
6534
|
+
const result = this.repository.queryWithContainer(
|
|
6535
|
+
getRepositoryContext(request),
|
|
6536
|
+
request.params.container,
|
|
6537
|
+
{
|
|
6538
|
+
expand: this._parseParam(request.query.expand),
|
|
6539
|
+
where: this._parseParam(request.query.where),
|
|
6540
|
+
limit: limit !== void 0 ? Number(limit) : void 0,
|
|
6541
|
+
offset: offset !== void 0 ? Number(offset) : void 0
|
|
6542
|
+
}
|
|
6543
|
+
);
|
|
6544
|
+
return response.status(200).send(result);
|
|
6545
|
+
}
|
|
6364
6546
|
getWithContainerAndKey(request, response) {
|
|
6365
6547
|
const result = this.repository.getWithContainerAndKey(
|
|
6366
6548
|
getRepositoryContext(request),
|
|
@@ -6799,7 +6981,21 @@ var ShippingMethodService = class extends AbstractService {
|
|
|
6799
6981
|
return "shipping-methods";
|
|
6800
6982
|
}
|
|
6801
6983
|
extraRoutes(parent) {
|
|
6802
|
-
parent.get("/matching-cart", this.
|
|
6984
|
+
parent.get("/matching-cart", this.matchingCart.bind(this));
|
|
6985
|
+
}
|
|
6986
|
+
matchingCart(request, response) {
|
|
6987
|
+
const cartId = queryParamsValue(request.query.cartId);
|
|
6988
|
+
if (!cartId) {
|
|
6989
|
+
return response.status(400).send();
|
|
6990
|
+
}
|
|
6991
|
+
const result = this.repository.matchingCart(
|
|
6992
|
+
getRepositoryContext(request),
|
|
6993
|
+
cartId,
|
|
6994
|
+
{
|
|
6995
|
+
expand: this._parseParam(request.query.expand)
|
|
6996
|
+
}
|
|
6997
|
+
);
|
|
6998
|
+
return response.status(200).send(result);
|
|
6803
6999
|
}
|
|
6804
7000
|
};
|
|
6805
7001
|
|