@labdigital/commercetools-mock 2.14.2 → 2.15.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 +356 -34
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +18 -15
- package/dist/index.d.ts +18 -15
- package/dist/index.js +356 -34
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/repositories/payment.ts +148 -25
- package/src/repositories/shopping-list.ts +347 -16
- package/src/services/cart.test.ts +2 -2
- package/src/services/shopping-list.test.ts +352 -0
- package/src/storage/in-memory.ts +40 -2
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, 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, CustomerSetFirstNameAction, CustomerSetLastNameAction, CustomerSetCompanyNameAction, CustomerSetVatIdAction, CustomerChangeAddressAction, 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, OrderUpdateSyncInfoAction, MyOrderFromCartDraft, OrderEditDraft, OrderEdit, OrderEditUpdateAction, PaymentDraft, Payment, TransactionDraft, Transaction,
|
|
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, CustomerSetFirstNameAction, CustomerSetLastNameAction, CustomerSetCompanyNameAction, CustomerSetVatIdAction, CustomerChangeAddressAction, 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, OrderUpdateSyncInfoAction, MyOrderFromCartDraft, OrderEditDraft, OrderEdit, OrderEditUpdateAction, PaymentDraft, Payment, TransactionDraft, Transaction, PaymentUpdateAction, 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, ShoppingListSetKeyAction, ShoppingListSetSlugAction, ShoppingListChangeNameAction, ShoppingListSetDescriptionAction, ShoppingListSetCustomerAction, ShoppingListSetStoreAction, ShoppingListSetAnonymousIdAction, ShoppingListSetCustomTypeAction, ShoppingListSetCustomFieldAction, ShoppingListSetDeleteDaysAfterLastModificationAction, ShoppingListAddLineItemAction, ShoppingListRemoveLineItemAction, ShoppingListChangeLineItemQuantityAction, ShoppingListLineItem, 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 Token = {
|
|
7
7
|
access_token: string;
|
|
@@ -260,20 +260,7 @@ declare class PaymentRepository extends AbstractResourceRepository<'payment'> {
|
|
|
260
260
|
getTypeId(): "payment";
|
|
261
261
|
create(context: RepositoryContext, draft: PaymentDraft): Payment;
|
|
262
262
|
transactionFromTransactionDraft: (draft: TransactionDraft, context: RepositoryContext) => Transaction;
|
|
263
|
-
actions:
|
|
264
|
-
addTransaction: (context: RepositoryContext, resource: Writable<Payment>, { transaction }: PaymentAddTransactionAction) => void;
|
|
265
|
-
changeTransactionState: (_context: RepositoryContext, resource: Writable<Payment>, { transactionId, state }: PaymentChangeTransactionStateAction) => void;
|
|
266
|
-
transitionState: (context: RepositoryContext, resource: Writable<Payment>, { state }: PaymentTransitionStateAction) => void;
|
|
267
|
-
setCustomField: (context: RepositoryContext, resource: Payment, { name, value }: PaymentSetCustomFieldAction) => void;
|
|
268
|
-
setCustomType: (context: RepositoryContext, resource: Writable<Payment>, { type, fields }: PaymentSetCustomTypeAction) => void;
|
|
269
|
-
setKey: (_context: RepositoryContext, resource: Writable<Payment>, { key }: PaymentSetKeyAction) => void;
|
|
270
|
-
setStatusInterfaceCode: (_context: RepositoryContext, resource: Writable<Payment>, { interfaceCode }: PaymentSetStatusInterfaceCodeAction) => void;
|
|
271
|
-
setStatusInterfaceText: (_context: RepositoryContext, resource: Writable<Payment>, { interfaceText }: PaymentSetStatusInterfaceTextAction) => void;
|
|
272
|
-
setMethodInfoName: (_context: RepositoryContext, resource: Writable<Payment>, { name }: PaymentSetMethodInfoNameAction) => void;
|
|
273
|
-
setMethodInfoMethod: (_context: RepositoryContext, resource: Writable<Payment>, { method }: PaymentSetMethodInfoMethodAction) => void;
|
|
274
|
-
setMethodInfoInterface: (_context: RepositoryContext, resource: Writable<Payment>, args: PaymentSetMethodInfoInterfaceAction) => void;
|
|
275
|
-
setInterfaceId: (_context: RepositoryContext, resource: Writable<Payment>, { interfaceId }: PaymentSetInterfaceIdAction) => void;
|
|
276
|
-
};
|
|
263
|
+
actions: Record<PaymentUpdateAction['action'], (context: RepositoryContext, resource: Writable<Payment>, action: any) => void>;
|
|
277
264
|
}
|
|
278
265
|
|
|
279
266
|
declare class ProductRepository extends AbstractResourceRepository<'product'> {
|
|
@@ -454,6 +441,22 @@ declare class ShippingMethodRepository extends AbstractResourceRepository<'shipp
|
|
|
454
441
|
declare class ShoppingListRepository extends AbstractResourceRepository<'shopping-list'> {
|
|
455
442
|
getTypeId(): "shopping-list";
|
|
456
443
|
create(context: RepositoryContext, draft: ShoppingListDraft): ShoppingList;
|
|
444
|
+
actions: {
|
|
445
|
+
setKey: (context: RepositoryContext, resource: Writable<ShoppingList>, { key }: ShoppingListSetKeyAction) => void;
|
|
446
|
+
setSlug: (context: RepositoryContext, resource: Writable<ShoppingList>, { slug }: ShoppingListSetSlugAction) => void;
|
|
447
|
+
changeName: (context: RepositoryContext, resource: Writable<ShoppingList>, { name }: ShoppingListChangeNameAction) => void;
|
|
448
|
+
setDescription: (context: RepositoryContext, resource: Writable<ShoppingList>, { description }: ShoppingListSetDescriptionAction) => void;
|
|
449
|
+
setCustomer: (context: RepositoryContext, resource: Writable<ShoppingList>, { customer }: ShoppingListSetCustomerAction) => void;
|
|
450
|
+
setStore: (context: RepositoryContext, resource: Writable<ShoppingList>, { store }: ShoppingListSetStoreAction) => void;
|
|
451
|
+
setAnonymousId: (context: RepositoryContext, resource: Writable<ShoppingList>, { anonymousId }: ShoppingListSetAnonymousIdAction) => void;
|
|
452
|
+
setCustomType: (context: RepositoryContext, resource: Writable<ShoppingList>, { type, fields }: ShoppingListSetCustomTypeAction) => void;
|
|
453
|
+
setCustomField: (context: RepositoryContext, resource: ShoppingList, { name, value }: ShoppingListSetCustomFieldAction) => void;
|
|
454
|
+
setDeleteDaysAfterLastModification: (context: RepositoryContext, resource: Writable<ShoppingList>, { deleteDaysAfterLastModification, }: ShoppingListSetDeleteDaysAfterLastModificationAction) => void;
|
|
455
|
+
addLineItem: (context: RepositoryContext, resource: Writable<ShoppingList>, { productId, variantId, sku, quantity }: ShoppingListAddLineItemAction) => void;
|
|
456
|
+
removeLineItem: (context: RepositoryContext, resource: Writable<ShoppingList>, { lineItemId, quantity }: ShoppingListRemoveLineItemAction) => void;
|
|
457
|
+
changeLineItemQuantity: (context: RepositoryContext, resource: Writable<ShoppingList>, { lineItemId, lineItemKey, quantity, }: ShoppingListChangeLineItemQuantityAction) => void;
|
|
458
|
+
};
|
|
459
|
+
draftLineItemtoLineItem: (projectKey: string, draftLineItem: LineItemDraft) => ShoppingListLineItem;
|
|
457
460
|
}
|
|
458
461
|
|
|
459
462
|
declare class StagedQuoteRepository extends AbstractResourceRepository<'staged-quote'> {
|
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, 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, CustomerSetFirstNameAction, CustomerSetLastNameAction, CustomerSetCompanyNameAction, CustomerSetVatIdAction, CustomerChangeAddressAction, 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, OrderUpdateSyncInfoAction, MyOrderFromCartDraft, OrderEditDraft, OrderEdit, OrderEditUpdateAction, PaymentDraft, Payment, TransactionDraft, Transaction,
|
|
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, CustomerSetFirstNameAction, CustomerSetLastNameAction, CustomerSetCompanyNameAction, CustomerSetVatIdAction, CustomerChangeAddressAction, 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, OrderUpdateSyncInfoAction, MyOrderFromCartDraft, OrderEditDraft, OrderEdit, OrderEditUpdateAction, PaymentDraft, Payment, TransactionDraft, Transaction, PaymentUpdateAction, 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, ShoppingListSetKeyAction, ShoppingListSetSlugAction, ShoppingListChangeNameAction, ShoppingListSetDescriptionAction, ShoppingListSetCustomerAction, ShoppingListSetStoreAction, ShoppingListSetAnonymousIdAction, ShoppingListSetCustomTypeAction, ShoppingListSetCustomFieldAction, ShoppingListSetDeleteDaysAfterLastModificationAction, ShoppingListAddLineItemAction, ShoppingListRemoveLineItemAction, ShoppingListChangeLineItemQuantityAction, ShoppingListLineItem, 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 Token = {
|
|
7
7
|
access_token: string;
|
|
@@ -260,20 +260,7 @@ declare class PaymentRepository extends AbstractResourceRepository<'payment'> {
|
|
|
260
260
|
getTypeId(): "payment";
|
|
261
261
|
create(context: RepositoryContext, draft: PaymentDraft): Payment;
|
|
262
262
|
transactionFromTransactionDraft: (draft: TransactionDraft, context: RepositoryContext) => Transaction;
|
|
263
|
-
actions:
|
|
264
|
-
addTransaction: (context: RepositoryContext, resource: Writable<Payment>, { transaction }: PaymentAddTransactionAction) => void;
|
|
265
|
-
changeTransactionState: (_context: RepositoryContext, resource: Writable<Payment>, { transactionId, state }: PaymentChangeTransactionStateAction) => void;
|
|
266
|
-
transitionState: (context: RepositoryContext, resource: Writable<Payment>, { state }: PaymentTransitionStateAction) => void;
|
|
267
|
-
setCustomField: (context: RepositoryContext, resource: Payment, { name, value }: PaymentSetCustomFieldAction) => void;
|
|
268
|
-
setCustomType: (context: RepositoryContext, resource: Writable<Payment>, { type, fields }: PaymentSetCustomTypeAction) => void;
|
|
269
|
-
setKey: (_context: RepositoryContext, resource: Writable<Payment>, { key }: PaymentSetKeyAction) => void;
|
|
270
|
-
setStatusInterfaceCode: (_context: RepositoryContext, resource: Writable<Payment>, { interfaceCode }: PaymentSetStatusInterfaceCodeAction) => void;
|
|
271
|
-
setStatusInterfaceText: (_context: RepositoryContext, resource: Writable<Payment>, { interfaceText }: PaymentSetStatusInterfaceTextAction) => void;
|
|
272
|
-
setMethodInfoName: (_context: RepositoryContext, resource: Writable<Payment>, { name }: PaymentSetMethodInfoNameAction) => void;
|
|
273
|
-
setMethodInfoMethod: (_context: RepositoryContext, resource: Writable<Payment>, { method }: PaymentSetMethodInfoMethodAction) => void;
|
|
274
|
-
setMethodInfoInterface: (_context: RepositoryContext, resource: Writable<Payment>, args: PaymentSetMethodInfoInterfaceAction) => void;
|
|
275
|
-
setInterfaceId: (_context: RepositoryContext, resource: Writable<Payment>, { interfaceId }: PaymentSetInterfaceIdAction) => void;
|
|
276
|
-
};
|
|
263
|
+
actions: Record<PaymentUpdateAction['action'], (context: RepositoryContext, resource: Writable<Payment>, action: any) => void>;
|
|
277
264
|
}
|
|
278
265
|
|
|
279
266
|
declare class ProductRepository extends AbstractResourceRepository<'product'> {
|
|
@@ -454,6 +441,22 @@ declare class ShippingMethodRepository extends AbstractResourceRepository<'shipp
|
|
|
454
441
|
declare class ShoppingListRepository extends AbstractResourceRepository<'shopping-list'> {
|
|
455
442
|
getTypeId(): "shopping-list";
|
|
456
443
|
create(context: RepositoryContext, draft: ShoppingListDraft): ShoppingList;
|
|
444
|
+
actions: {
|
|
445
|
+
setKey: (context: RepositoryContext, resource: Writable<ShoppingList>, { key }: ShoppingListSetKeyAction) => void;
|
|
446
|
+
setSlug: (context: RepositoryContext, resource: Writable<ShoppingList>, { slug }: ShoppingListSetSlugAction) => void;
|
|
447
|
+
changeName: (context: RepositoryContext, resource: Writable<ShoppingList>, { name }: ShoppingListChangeNameAction) => void;
|
|
448
|
+
setDescription: (context: RepositoryContext, resource: Writable<ShoppingList>, { description }: ShoppingListSetDescriptionAction) => void;
|
|
449
|
+
setCustomer: (context: RepositoryContext, resource: Writable<ShoppingList>, { customer }: ShoppingListSetCustomerAction) => void;
|
|
450
|
+
setStore: (context: RepositoryContext, resource: Writable<ShoppingList>, { store }: ShoppingListSetStoreAction) => void;
|
|
451
|
+
setAnonymousId: (context: RepositoryContext, resource: Writable<ShoppingList>, { anonymousId }: ShoppingListSetAnonymousIdAction) => void;
|
|
452
|
+
setCustomType: (context: RepositoryContext, resource: Writable<ShoppingList>, { type, fields }: ShoppingListSetCustomTypeAction) => void;
|
|
453
|
+
setCustomField: (context: RepositoryContext, resource: ShoppingList, { name, value }: ShoppingListSetCustomFieldAction) => void;
|
|
454
|
+
setDeleteDaysAfterLastModification: (context: RepositoryContext, resource: Writable<ShoppingList>, { deleteDaysAfterLastModification, }: ShoppingListSetDeleteDaysAfterLastModificationAction) => void;
|
|
455
|
+
addLineItem: (context: RepositoryContext, resource: Writable<ShoppingList>, { productId, variantId, sku, quantity }: ShoppingListAddLineItemAction) => void;
|
|
456
|
+
removeLineItem: (context: RepositoryContext, resource: Writable<ShoppingList>, { lineItemId, quantity }: ShoppingListRemoveLineItemAction) => void;
|
|
457
|
+
changeLineItemQuantity: (context: RepositoryContext, resource: Writable<ShoppingList>, { lineItemId, lineItemKey, quantity, }: ShoppingListChangeLineItemQuantityAction) => void;
|
|
458
|
+
};
|
|
459
|
+
draftLineItemtoLineItem: (projectKey: string, draftLineItem: LineItemDraft) => ShoppingListLineItem;
|
|
457
460
|
}
|
|
458
461
|
|
|
459
462
|
declare class StagedQuoteRepository extends AbstractResourceRepository<'staged-quote'> {
|
package/dist/index.js
CHANGED
|
@@ -1201,6 +1201,16 @@ var InMemoryStorage = class extends AbstractStorage {
|
|
|
1201
1201
|
};
|
|
1202
1202
|
_resolveResource = (projectKey, obj, expand) => {
|
|
1203
1203
|
const params = parseExpandClause(expand);
|
|
1204
|
+
if (params.index === "*") {
|
|
1205
|
+
const reference = obj[params.element];
|
|
1206
|
+
if (params.element === "lineItems" && params.rest?.startsWith("variant") && reference.every(
|
|
1207
|
+
(item) => item.variant === void 0 && item.variantId !== void 0
|
|
1208
|
+
)) {
|
|
1209
|
+
reference.forEach((item) => {
|
|
1210
|
+
this._resolveShoppingListLineItemVariant(projectKey, item);
|
|
1211
|
+
});
|
|
1212
|
+
}
|
|
1213
|
+
}
|
|
1204
1214
|
if (!params.index) {
|
|
1205
1215
|
const reference = obj[params.element];
|
|
1206
1216
|
if (reference === void 0) {
|
|
@@ -1241,6 +1251,20 @@ var InMemoryStorage = class extends AbstractStorage {
|
|
|
1241
1251
|
}
|
|
1242
1252
|
}
|
|
1243
1253
|
}
|
|
1254
|
+
_resolveShoppingListLineItemVariant(projectKey, lineItem) {
|
|
1255
|
+
const product = this.getByResourceIdentifier(projectKey, {
|
|
1256
|
+
typeId: "product",
|
|
1257
|
+
id: lineItem.productId
|
|
1258
|
+
});
|
|
1259
|
+
if (!product) {
|
|
1260
|
+
return;
|
|
1261
|
+
}
|
|
1262
|
+
const variant = [
|
|
1263
|
+
product.masterData.current.masterVariant,
|
|
1264
|
+
...product.masterData.current.variants
|
|
1265
|
+
].find((e) => e.id === lineItem.variantId);
|
|
1266
|
+
lineItem.variant = variant;
|
|
1267
|
+
}
|
|
1244
1268
|
};
|
|
1245
1269
|
|
|
1246
1270
|
// src/oauth/server.ts
|
|
@@ -3942,12 +3966,31 @@ var PaymentRepository = class extends AbstractResourceRepository {
|
|
|
3942
3966
|
// Documented as default
|
|
3943
3967
|
});
|
|
3944
3968
|
actions = {
|
|
3969
|
+
addInterfaceInteraction: (context, resource, { type, fields }) => {
|
|
3970
|
+
resource.interfaceInteractions.push(
|
|
3971
|
+
createCustomFields({ type, fields }, context.projectKey, this._storage)
|
|
3972
|
+
);
|
|
3973
|
+
},
|
|
3945
3974
|
addTransaction: (context, resource, { transaction }) => {
|
|
3946
3975
|
resource.transactions = [
|
|
3947
3976
|
...resource.transactions,
|
|
3948
3977
|
this.transactionFromTransactionDraft(transaction, context)
|
|
3949
3978
|
];
|
|
3950
3979
|
},
|
|
3980
|
+
changeAmountPlanned: (_context, resource, { amount }) => {
|
|
3981
|
+
resource.amountPlanned = createCentPrecisionMoney(amount);
|
|
3982
|
+
},
|
|
3983
|
+
changeTransactionInteractionId: (_context, resource, {
|
|
3984
|
+
transactionId,
|
|
3985
|
+
interactionId
|
|
3986
|
+
}) => {
|
|
3987
|
+
const transaction = resource.transactions.find(
|
|
3988
|
+
(e) => e.id === transactionId
|
|
3989
|
+
);
|
|
3990
|
+
if (transaction) {
|
|
3991
|
+
transaction.interactionId = interactionId;
|
|
3992
|
+
}
|
|
3993
|
+
},
|
|
3951
3994
|
changeTransactionState: (_context, resource, { transactionId, state }) => {
|
|
3952
3995
|
const index = resource.transactions.findIndex(
|
|
3953
3996
|
(e) => e.id === transactionId
|
|
@@ -3958,6 +4001,14 @@ var PaymentRepository = class extends AbstractResourceRepository {
|
|
|
3958
4001
|
};
|
|
3959
4002
|
resource.transactions[index] = updatedTransaction;
|
|
3960
4003
|
},
|
|
4004
|
+
changeTransactionTimestamp: (_context, resource, { transactionId, timestamp }) => {
|
|
4005
|
+
const transaction = resource.transactions.find(
|
|
4006
|
+
(e) => e.id === transactionId
|
|
4007
|
+
);
|
|
4008
|
+
if (transaction) {
|
|
4009
|
+
transaction.timestamp = timestamp;
|
|
4010
|
+
}
|
|
4011
|
+
},
|
|
3961
4012
|
transitionState: (context, resource, { state }) => {
|
|
3962
4013
|
const stateObj = this._storage.getByResourceIdentifier(
|
|
3963
4014
|
context.projectKey,
|
|
@@ -3972,6 +4023,21 @@ var PaymentRepository = class extends AbstractResourceRepository {
|
|
|
3972
4023
|
obj: stateObj
|
|
3973
4024
|
};
|
|
3974
4025
|
},
|
|
4026
|
+
setAnonymousId: (_context, resource, { anonymousId }) => {
|
|
4027
|
+
resource.anonymousId = anonymousId;
|
|
4028
|
+
resource.customer = void 0;
|
|
4029
|
+
},
|
|
4030
|
+
setCustomer: (_context, resource, { customer }) => {
|
|
4031
|
+
if (customer) {
|
|
4032
|
+
const c = getReferenceFromResourceIdentifier(
|
|
4033
|
+
customer,
|
|
4034
|
+
_context.projectKey,
|
|
4035
|
+
this._storage
|
|
4036
|
+
);
|
|
4037
|
+
resource.customer = c;
|
|
4038
|
+
resource.anonymousId = void 0;
|
|
4039
|
+
}
|
|
4040
|
+
},
|
|
3975
4041
|
setCustomField: (context, resource, { name, value }) => {
|
|
3976
4042
|
if (!resource.custom) {
|
|
3977
4043
|
throw new Error("Resource has no custom field");
|
|
@@ -3998,33 +4064,63 @@ var PaymentRepository = class extends AbstractResourceRepository {
|
|
|
3998
4064
|
};
|
|
3999
4065
|
}
|
|
4000
4066
|
},
|
|
4067
|
+
setInterfaceId: (_context, resource, { interfaceId }) => {
|
|
4068
|
+
resource.interfaceId = interfaceId;
|
|
4069
|
+
},
|
|
4001
4070
|
setKey: (_context, resource, { key }) => {
|
|
4002
4071
|
resource.key = key;
|
|
4003
4072
|
},
|
|
4004
|
-
|
|
4005
|
-
resource.
|
|
4006
|
-
},
|
|
4007
|
-
setStatusInterfaceText: (_context, resource, { interfaceText }) => {
|
|
4008
|
-
resource.paymentStatus.interfaceText = interfaceText;
|
|
4073
|
+
setMethodInfoMethod: (_context, resource, { method }) => {
|
|
4074
|
+
resource.paymentMethodInfo.method = method;
|
|
4009
4075
|
},
|
|
4010
4076
|
setMethodInfoName: (_context, resource, { name }) => {
|
|
4011
4077
|
resource.paymentMethodInfo.name = name;
|
|
4012
4078
|
},
|
|
4013
|
-
setMethodInfoMethod: (_context, resource, { method }) => {
|
|
4014
|
-
resource.paymentMethodInfo.method = method;
|
|
4015
|
-
},
|
|
4016
4079
|
setMethodInfoInterface: (_context, resource, args) => {
|
|
4017
4080
|
resource.paymentMethodInfo.paymentInterface = args.interface;
|
|
4018
4081
|
},
|
|
4019
|
-
|
|
4020
|
-
resource.
|
|
4082
|
+
setStatusInterfaceCode: (_context, resource, { interfaceCode }) => {
|
|
4083
|
+
resource.paymentStatus.interfaceCode = interfaceCode;
|
|
4084
|
+
},
|
|
4085
|
+
setStatusInterfaceText: (_context, resource, { interfaceText }) => {
|
|
4086
|
+
resource.paymentStatus.interfaceText = interfaceText;
|
|
4087
|
+
},
|
|
4088
|
+
setTransactionCustomField: (_context, resource, { transactionId, name, value }) => {
|
|
4089
|
+
const transaction = resource.transactions.find(
|
|
4090
|
+
(e) => e.id === transactionId
|
|
4091
|
+
);
|
|
4092
|
+
if (transaction) {
|
|
4093
|
+
if (!transaction.custom) {
|
|
4094
|
+
throw new Error("Transaction has no custom field");
|
|
4095
|
+
}
|
|
4096
|
+
transaction.custom.fields[name] = value;
|
|
4097
|
+
}
|
|
4098
|
+
},
|
|
4099
|
+
setTransactionCustomType: (context, resource, { transactionId, type, fields }) => {
|
|
4100
|
+
const transaction = resource.transactions.find(
|
|
4101
|
+
(e) => e.id === transactionId
|
|
4102
|
+
);
|
|
4103
|
+
if (transaction) {
|
|
4104
|
+
if (!type) {
|
|
4105
|
+
transaction.custom = void 0;
|
|
4106
|
+
} else {
|
|
4107
|
+
const resolvedType = this._storage.getByResourceIdentifier(
|
|
4108
|
+
context.projectKey,
|
|
4109
|
+
type
|
|
4110
|
+
);
|
|
4111
|
+
if (!resolvedType) {
|
|
4112
|
+
throw new Error(`Type ${type} not found`);
|
|
4113
|
+
}
|
|
4114
|
+
transaction.custom = {
|
|
4115
|
+
type: {
|
|
4116
|
+
typeId: "type",
|
|
4117
|
+
id: resolvedType.id
|
|
4118
|
+
},
|
|
4119
|
+
fields: fields ?? {}
|
|
4120
|
+
};
|
|
4121
|
+
}
|
|
4122
|
+
}
|
|
4021
4123
|
}
|
|
4022
|
-
// addInterfaceInteraction: () => {},
|
|
4023
|
-
// changeAmountPlanned: () => {},
|
|
4024
|
-
// changeTransactionInteractionId: () => {},
|
|
4025
|
-
// changeTransactionTimestamp: () => {},
|
|
4026
|
-
// setAnonymousId: () => {},
|
|
4027
|
-
// setCustomer: () => {},
|
|
4028
4124
|
};
|
|
4029
4125
|
};
|
|
4030
4126
|
|
|
@@ -5921,11 +6017,15 @@ var ShippingMethodRepository = class extends AbstractResourceRepository {
|
|
|
5921
6017
|
};
|
|
5922
6018
|
|
|
5923
6019
|
// src/repositories/shopping-list.ts
|
|
6020
|
+
import { v4 as uuidv48 } from "uuid";
|
|
5924
6021
|
var ShoppingListRepository = class extends AbstractResourceRepository {
|
|
5925
6022
|
getTypeId() {
|
|
5926
6023
|
return "shopping-list";
|
|
5927
6024
|
}
|
|
5928
6025
|
create(context, draft) {
|
|
6026
|
+
const lineItems = draft.lineItems?.map(
|
|
6027
|
+
(draftLineItem) => this.draftLineItemtoLineItem(context.projectKey, draftLineItem)
|
|
6028
|
+
) ?? [];
|
|
5929
6029
|
const resource = {
|
|
5930
6030
|
...getBaseResourceProperties(),
|
|
5931
6031
|
...draft,
|
|
@@ -5935,20 +6035,7 @@ var ShoppingListRepository = class extends AbstractResourceRepository {
|
|
|
5935
6035
|
this._storage
|
|
5936
6036
|
),
|
|
5937
6037
|
textLineItems: [],
|
|
5938
|
-
lineItems
|
|
5939
|
-
...getBaseResourceProperties(),
|
|
5940
|
-
...e,
|
|
5941
|
-
addedAt: e.addedAt ?? "",
|
|
5942
|
-
productId: e.productId ?? "",
|
|
5943
|
-
name: {},
|
|
5944
|
-
quantity: e.quantity ?? 1,
|
|
5945
|
-
productType: { typeId: "product-type", id: "" },
|
|
5946
|
-
custom: createCustomFields(
|
|
5947
|
-
e.custom,
|
|
5948
|
-
context.projectKey,
|
|
5949
|
-
this._storage
|
|
5950
|
-
)
|
|
5951
|
-
})) ?? [],
|
|
6038
|
+
lineItems,
|
|
5952
6039
|
customer: draft.customer ? getReferenceFromResourceIdentifier(
|
|
5953
6040
|
draft.customer,
|
|
5954
6041
|
context.projectKey,
|
|
@@ -5959,6 +6046,241 @@ var ShoppingListRepository = class extends AbstractResourceRepository {
|
|
|
5959
6046
|
this.saveNew(context, resource);
|
|
5960
6047
|
return resource;
|
|
5961
6048
|
}
|
|
6049
|
+
actions = {
|
|
6050
|
+
setKey: (context, resource, { key }) => {
|
|
6051
|
+
resource.key = key;
|
|
6052
|
+
},
|
|
6053
|
+
setSlug: (context, resource, { slug }) => {
|
|
6054
|
+
resource.slug = slug;
|
|
6055
|
+
},
|
|
6056
|
+
changeName: (context, resource, { name }) => {
|
|
6057
|
+
resource.name = name;
|
|
6058
|
+
},
|
|
6059
|
+
setDescription: (context, resource, { description }) => {
|
|
6060
|
+
resource.description = description;
|
|
6061
|
+
},
|
|
6062
|
+
setCustomer: (context, resource, { customer }) => {
|
|
6063
|
+
if (customer?.key) {
|
|
6064
|
+
throw new Error("set customer on shoppinglist by key not implemented");
|
|
6065
|
+
}
|
|
6066
|
+
if (customer?.id) {
|
|
6067
|
+
resource.customer = { typeId: "customer", id: customer.id };
|
|
6068
|
+
}
|
|
6069
|
+
},
|
|
6070
|
+
setStore: (context, resource, { store }) => {
|
|
6071
|
+
if (store?.key) {
|
|
6072
|
+
resource.store = { typeId: "store", key: store.key };
|
|
6073
|
+
}
|
|
6074
|
+
if (store?.id) {
|
|
6075
|
+
throw new Error("set store on shoppinglist by id not implemented");
|
|
6076
|
+
}
|
|
6077
|
+
},
|
|
6078
|
+
setAnonymousId: (context, resource, { anonymousId }) => {
|
|
6079
|
+
resource.anonymousId = anonymousId;
|
|
6080
|
+
},
|
|
6081
|
+
setCustomType: (context, resource, { type, fields }) => {
|
|
6082
|
+
if (!type) {
|
|
6083
|
+
resource.custom = void 0;
|
|
6084
|
+
} else {
|
|
6085
|
+
const resolvedType = this._storage.getByResourceIdentifier(
|
|
6086
|
+
context.projectKey,
|
|
6087
|
+
type
|
|
6088
|
+
);
|
|
6089
|
+
if (!resolvedType) {
|
|
6090
|
+
throw new Error(`Type ${type} not found`);
|
|
6091
|
+
}
|
|
6092
|
+
resource.custom = {
|
|
6093
|
+
type: {
|
|
6094
|
+
typeId: "type",
|
|
6095
|
+
id: resolvedType.id
|
|
6096
|
+
},
|
|
6097
|
+
fields: fields || {}
|
|
6098
|
+
};
|
|
6099
|
+
}
|
|
6100
|
+
},
|
|
6101
|
+
setCustomField: (context, resource, { name, value }) => {
|
|
6102
|
+
if (!resource.custom) {
|
|
6103
|
+
throw new Error("Resource has no custom field");
|
|
6104
|
+
}
|
|
6105
|
+
resource.custom.fields[name] = value;
|
|
6106
|
+
},
|
|
6107
|
+
setDeleteDaysAfterLastModification: (context, resource, {
|
|
6108
|
+
deleteDaysAfterLastModification
|
|
6109
|
+
}) => {
|
|
6110
|
+
resource.deleteDaysAfterLastModification = deleteDaysAfterLastModification;
|
|
6111
|
+
},
|
|
6112
|
+
addLineItem: (context, resource, { productId, variantId, sku, quantity = 1 }) => {
|
|
6113
|
+
let product = null;
|
|
6114
|
+
if (productId) {
|
|
6115
|
+
product = this._storage.get(
|
|
6116
|
+
context.projectKey,
|
|
6117
|
+
"product",
|
|
6118
|
+
productId,
|
|
6119
|
+
{}
|
|
6120
|
+
);
|
|
6121
|
+
} else if (sku) {
|
|
6122
|
+
const items = this._storage.query(context.projectKey, "product", {
|
|
6123
|
+
where: [
|
|
6124
|
+
`masterData(current(masterVariant(sku="${sku}"))) or masterData(current(variants(sku="${sku}")))`
|
|
6125
|
+
]
|
|
6126
|
+
});
|
|
6127
|
+
if (items.count === 1) {
|
|
6128
|
+
product = items.results[0];
|
|
6129
|
+
}
|
|
6130
|
+
}
|
|
6131
|
+
if (!product) {
|
|
6132
|
+
throw new CommercetoolsError({
|
|
6133
|
+
code: "General",
|
|
6134
|
+
message: sku ? `A product containing a variant with SKU '${sku}' not found.` : `A product with ID '${productId}' not found.`
|
|
6135
|
+
});
|
|
6136
|
+
}
|
|
6137
|
+
let varId = variantId;
|
|
6138
|
+
if (sku) {
|
|
6139
|
+
varId = [
|
|
6140
|
+
product.masterData.current.masterVariant,
|
|
6141
|
+
...product.masterData.current.variants
|
|
6142
|
+
].find((x) => x.sku === sku)?.id;
|
|
6143
|
+
}
|
|
6144
|
+
if (!varId) {
|
|
6145
|
+
varId = product.masterData.current.masterVariant.id;
|
|
6146
|
+
}
|
|
6147
|
+
const alreadyAdded = resource.lineItems.some(
|
|
6148
|
+
(x) => x.productId === product?.id && x.variantId === varId
|
|
6149
|
+
);
|
|
6150
|
+
if (alreadyAdded) {
|
|
6151
|
+
resource.lineItems.forEach((x) => {
|
|
6152
|
+
if (x.productId === product?.id && x.variantId === varId) {
|
|
6153
|
+
x.quantity += quantity;
|
|
6154
|
+
}
|
|
6155
|
+
});
|
|
6156
|
+
} else {
|
|
6157
|
+
resource.lineItems.push({
|
|
6158
|
+
addedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
6159
|
+
id: uuidv48(),
|
|
6160
|
+
productId: product.id,
|
|
6161
|
+
productSlug: product.masterData.current.slug,
|
|
6162
|
+
productType: product.productType,
|
|
6163
|
+
name: product.masterData.current.name,
|
|
6164
|
+
variantId: varId,
|
|
6165
|
+
quantity
|
|
6166
|
+
});
|
|
6167
|
+
}
|
|
6168
|
+
},
|
|
6169
|
+
removeLineItem: (context, resource, { lineItemId, quantity }) => {
|
|
6170
|
+
const lineItem = resource.lineItems.find((x) => x.id === lineItemId);
|
|
6171
|
+
if (!lineItem) {
|
|
6172
|
+
throw new CommercetoolsError({
|
|
6173
|
+
code: "General",
|
|
6174
|
+
message: `A line item with ID '${lineItemId}' not found.`
|
|
6175
|
+
});
|
|
6176
|
+
}
|
|
6177
|
+
const shouldDelete = !quantity || quantity >= lineItem.quantity;
|
|
6178
|
+
if (shouldDelete) {
|
|
6179
|
+
resource.lineItems = resource.lineItems.filter(
|
|
6180
|
+
(x) => x.id !== lineItemId
|
|
6181
|
+
);
|
|
6182
|
+
} else {
|
|
6183
|
+
resource.lineItems.forEach((x) => {
|
|
6184
|
+
if (x.id === lineItemId && quantity) {
|
|
6185
|
+
x.quantity -= quantity;
|
|
6186
|
+
}
|
|
6187
|
+
});
|
|
6188
|
+
}
|
|
6189
|
+
},
|
|
6190
|
+
changeLineItemQuantity: (context, resource, {
|
|
6191
|
+
lineItemId,
|
|
6192
|
+
lineItemKey,
|
|
6193
|
+
quantity
|
|
6194
|
+
}) => {
|
|
6195
|
+
let lineItem;
|
|
6196
|
+
if (lineItemId) {
|
|
6197
|
+
lineItem = resource.lineItems.find((x) => x.id === lineItemId);
|
|
6198
|
+
if (!lineItem) {
|
|
6199
|
+
throw new CommercetoolsError({
|
|
6200
|
+
code: "General",
|
|
6201
|
+
message: `A line item with ID '${lineItemId}' not found.`
|
|
6202
|
+
});
|
|
6203
|
+
}
|
|
6204
|
+
} else if (lineItemKey) {
|
|
6205
|
+
lineItem = resource.lineItems.find((x) => x.id === lineItemId);
|
|
6206
|
+
if (!lineItem) {
|
|
6207
|
+
throw new CommercetoolsError({
|
|
6208
|
+
code: "General",
|
|
6209
|
+
message: `A line item with Key '${lineItemKey}' not found.`
|
|
6210
|
+
});
|
|
6211
|
+
}
|
|
6212
|
+
} else {
|
|
6213
|
+
throw new CommercetoolsError({
|
|
6214
|
+
code: "General",
|
|
6215
|
+
message: `Either lineItemid or lineItemKey needs to be provided.`
|
|
6216
|
+
});
|
|
6217
|
+
}
|
|
6218
|
+
if (quantity === 0) {
|
|
6219
|
+
resource.lineItems = resource.lineItems.filter(
|
|
6220
|
+
(x) => x.id !== lineItemId
|
|
6221
|
+
);
|
|
6222
|
+
} else {
|
|
6223
|
+
resource.lineItems.forEach((x) => {
|
|
6224
|
+
if (x.id === lineItemId && quantity) {
|
|
6225
|
+
x.quantity = quantity;
|
|
6226
|
+
}
|
|
6227
|
+
});
|
|
6228
|
+
}
|
|
6229
|
+
}
|
|
6230
|
+
};
|
|
6231
|
+
draftLineItemtoLineItem = (projectKey, draftLineItem) => {
|
|
6232
|
+
const { sku, productId, variantId } = draftLineItem;
|
|
6233
|
+
const lineItem = {
|
|
6234
|
+
...getBaseResourceProperties(),
|
|
6235
|
+
...draftLineItem,
|
|
6236
|
+
addedAt: draftLineItem.addedAt ?? "",
|
|
6237
|
+
productId: draftLineItem.productId ?? "",
|
|
6238
|
+
name: {},
|
|
6239
|
+
variantId,
|
|
6240
|
+
quantity: draftLineItem.quantity ?? 1,
|
|
6241
|
+
productType: { typeId: "product-type", id: "" },
|
|
6242
|
+
custom: createCustomFields(
|
|
6243
|
+
draftLineItem.custom,
|
|
6244
|
+
projectKey,
|
|
6245
|
+
this._storage
|
|
6246
|
+
)
|
|
6247
|
+
};
|
|
6248
|
+
if (variantId) {
|
|
6249
|
+
return lineItem;
|
|
6250
|
+
}
|
|
6251
|
+
if (sku) {
|
|
6252
|
+
const items = this._storage.query(projectKey, "product", {
|
|
6253
|
+
where: [
|
|
6254
|
+
`masterData(current(masterVariant(sku="${sku}"))) or masterData(current(variants(sku="${sku}")))`
|
|
6255
|
+
]
|
|
6256
|
+
});
|
|
6257
|
+
if (items.count === 0) {
|
|
6258
|
+
throw new Error(`Product with sku ${sku} not found`);
|
|
6259
|
+
}
|
|
6260
|
+
const product = items.results[0];
|
|
6261
|
+
const allVariants = [
|
|
6262
|
+
product.masterData.current.masterVariant,
|
|
6263
|
+
...product.masterData.current.variants
|
|
6264
|
+
];
|
|
6265
|
+
const variantId2 = allVariants.find((e) => e.sku === sku)?.id;
|
|
6266
|
+
lineItem.variantId = variantId2;
|
|
6267
|
+
return lineItem;
|
|
6268
|
+
}
|
|
6269
|
+
if (productId) {
|
|
6270
|
+
const items = this._storage.query(projectKey, "product", {
|
|
6271
|
+
where: [`id="${productId}"`]
|
|
6272
|
+
});
|
|
6273
|
+
if (items.count === 0) {
|
|
6274
|
+
throw new Error(`Product with id ${productId} not found`);
|
|
6275
|
+
}
|
|
6276
|
+
const variantId2 = items.results[0].masterData.current.masterVariant.id;
|
|
6277
|
+
lineItem.variantId = variantId2;
|
|
6278
|
+
return lineItem;
|
|
6279
|
+
}
|
|
6280
|
+
throw new Error(
|
|
6281
|
+
`must provide either sku, productId or variantId for ShoppingListLineItem`
|
|
6282
|
+
);
|
|
6283
|
+
};
|
|
5962
6284
|
};
|
|
5963
6285
|
|
|
5964
6286
|
// src/repositories/staged-quote.ts
|
|
@@ -6177,7 +6499,7 @@ var SubscriptionRepository = class extends AbstractResourceRepository {
|
|
|
6177
6499
|
};
|
|
6178
6500
|
|
|
6179
6501
|
// src/repositories/tax-category.ts
|
|
6180
|
-
import { v4 as
|
|
6502
|
+
import { v4 as uuidv49 } from "uuid";
|
|
6181
6503
|
var TaxCategoryRepository = class extends AbstractResourceRepository {
|
|
6182
6504
|
getTypeId() {
|
|
6183
6505
|
return "tax-category";
|
|
@@ -6193,7 +6515,7 @@ var TaxCategoryRepository = class extends AbstractResourceRepository {
|
|
|
6193
6515
|
}
|
|
6194
6516
|
taxRateFromTaxRateDraft = (draft) => ({
|
|
6195
6517
|
...draft,
|
|
6196
|
-
id:
|
|
6518
|
+
id: uuidv49(),
|
|
6197
6519
|
amount: draft.amount || 0
|
|
6198
6520
|
});
|
|
6199
6521
|
actions = {
|
|
@@ -6752,7 +7074,7 @@ var CustomerGroupService = class extends AbstractService {
|
|
|
6752
7074
|
};
|
|
6753
7075
|
|
|
6754
7076
|
// src/services/customer.ts
|
|
6755
|
-
import { v4 as
|
|
7077
|
+
import { v4 as uuidv410 } from "uuid";
|
|
6756
7078
|
var CustomerService = class extends AbstractService {
|
|
6757
7079
|
repository;
|
|
6758
7080
|
constructor(parent, repository) {
|
|
@@ -6776,7 +7098,7 @@ var CustomerService = class extends AbstractService {
|
|
|
6776
7098
|
...rest,
|
|
6777
7099
|
customerId: customer.results[0].id,
|
|
6778
7100
|
expiresAt: new Date(Date.now() + ttlMinutes * 60).toISOString(),
|
|
6779
|
-
value:
|
|
7101
|
+
value: uuidv410()
|
|
6780
7102
|
});
|
|
6781
7103
|
});
|
|
6782
7104
|
}
|