@labdigital/commercetools-mock 2.14.2 → 2.16.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 +364 -34
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +19 -15
- package/dist/index.d.ts +19 -15
- package/dist/index.js +364 -34
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/repositories/customer.ts +13 -0
- 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/customer.test.ts +40 -0
- 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, CustomerSetCustomerNumberAction, 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;
|
|
@@ -181,6 +181,7 @@ declare class CustomerRepository extends AbstractResourceRepository<'customer'>
|
|
|
181
181
|
changeAddress: (context: RepositoryContext, resource: Writable<Customer>, { addressId, addressKey, address }: CustomerChangeAddressAction) => void;
|
|
182
182
|
setAuthenticationMode: (_context: RepositoryContext, resource: Writable<Customer>, { authMode, password }: CustomerSetAuthenticationModeAction) => void;
|
|
183
183
|
setCustomField: (_context: RepositoryContext, resource: Writable<Customer>, { name, value }: CustomerSetCustomFieldAction) => void;
|
|
184
|
+
setCustomerNumber: (_context: RepositoryContext, resource: Writable<Customer>, { customerNumber }: CustomerSetCustomerNumberAction) => void;
|
|
184
185
|
};
|
|
185
186
|
}
|
|
186
187
|
|
|
@@ -260,20 +261,7 @@ declare class PaymentRepository extends AbstractResourceRepository<'payment'> {
|
|
|
260
261
|
getTypeId(): "payment";
|
|
261
262
|
create(context: RepositoryContext, draft: PaymentDraft): Payment;
|
|
262
263
|
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
|
-
};
|
|
264
|
+
actions: Record<PaymentUpdateAction['action'], (context: RepositoryContext, resource: Writable<Payment>, action: any) => void>;
|
|
277
265
|
}
|
|
278
266
|
|
|
279
267
|
declare class ProductRepository extends AbstractResourceRepository<'product'> {
|
|
@@ -454,6 +442,22 @@ declare class ShippingMethodRepository extends AbstractResourceRepository<'shipp
|
|
|
454
442
|
declare class ShoppingListRepository extends AbstractResourceRepository<'shopping-list'> {
|
|
455
443
|
getTypeId(): "shopping-list";
|
|
456
444
|
create(context: RepositoryContext, draft: ShoppingListDraft): ShoppingList;
|
|
445
|
+
actions: {
|
|
446
|
+
setKey: (context: RepositoryContext, resource: Writable<ShoppingList>, { key }: ShoppingListSetKeyAction) => void;
|
|
447
|
+
setSlug: (context: RepositoryContext, resource: Writable<ShoppingList>, { slug }: ShoppingListSetSlugAction) => void;
|
|
448
|
+
changeName: (context: RepositoryContext, resource: Writable<ShoppingList>, { name }: ShoppingListChangeNameAction) => void;
|
|
449
|
+
setDescription: (context: RepositoryContext, resource: Writable<ShoppingList>, { description }: ShoppingListSetDescriptionAction) => void;
|
|
450
|
+
setCustomer: (context: RepositoryContext, resource: Writable<ShoppingList>, { customer }: ShoppingListSetCustomerAction) => void;
|
|
451
|
+
setStore: (context: RepositoryContext, resource: Writable<ShoppingList>, { store }: ShoppingListSetStoreAction) => void;
|
|
452
|
+
setAnonymousId: (context: RepositoryContext, resource: Writable<ShoppingList>, { anonymousId }: ShoppingListSetAnonymousIdAction) => void;
|
|
453
|
+
setCustomType: (context: RepositoryContext, resource: Writable<ShoppingList>, { type, fields }: ShoppingListSetCustomTypeAction) => void;
|
|
454
|
+
setCustomField: (context: RepositoryContext, resource: ShoppingList, { name, value }: ShoppingListSetCustomFieldAction) => void;
|
|
455
|
+
setDeleteDaysAfterLastModification: (context: RepositoryContext, resource: Writable<ShoppingList>, { deleteDaysAfterLastModification, }: ShoppingListSetDeleteDaysAfterLastModificationAction) => void;
|
|
456
|
+
addLineItem: (context: RepositoryContext, resource: Writable<ShoppingList>, { productId, variantId, sku, quantity }: ShoppingListAddLineItemAction) => void;
|
|
457
|
+
removeLineItem: (context: RepositoryContext, resource: Writable<ShoppingList>, { lineItemId, quantity }: ShoppingListRemoveLineItemAction) => void;
|
|
458
|
+
changeLineItemQuantity: (context: RepositoryContext, resource: Writable<ShoppingList>, { lineItemId, lineItemKey, quantity, }: ShoppingListChangeLineItemQuantityAction) => void;
|
|
459
|
+
};
|
|
460
|
+
draftLineItemtoLineItem: (projectKey: string, draftLineItem: LineItemDraft) => ShoppingListLineItem;
|
|
457
461
|
}
|
|
458
462
|
|
|
459
463
|
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, CustomerSetCustomerNumberAction, 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;
|
|
@@ -181,6 +181,7 @@ declare class CustomerRepository extends AbstractResourceRepository<'customer'>
|
|
|
181
181
|
changeAddress: (context: RepositoryContext, resource: Writable<Customer>, { addressId, addressKey, address }: CustomerChangeAddressAction) => void;
|
|
182
182
|
setAuthenticationMode: (_context: RepositoryContext, resource: Writable<Customer>, { authMode, password }: CustomerSetAuthenticationModeAction) => void;
|
|
183
183
|
setCustomField: (_context: RepositoryContext, resource: Writable<Customer>, { name, value }: CustomerSetCustomFieldAction) => void;
|
|
184
|
+
setCustomerNumber: (_context: RepositoryContext, resource: Writable<Customer>, { customerNumber }: CustomerSetCustomerNumberAction) => void;
|
|
184
185
|
};
|
|
185
186
|
}
|
|
186
187
|
|
|
@@ -260,20 +261,7 @@ declare class PaymentRepository extends AbstractResourceRepository<'payment'> {
|
|
|
260
261
|
getTypeId(): "payment";
|
|
261
262
|
create(context: RepositoryContext, draft: PaymentDraft): Payment;
|
|
262
263
|
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
|
-
};
|
|
264
|
+
actions: Record<PaymentUpdateAction['action'], (context: RepositoryContext, resource: Writable<Payment>, action: any) => void>;
|
|
277
265
|
}
|
|
278
266
|
|
|
279
267
|
declare class ProductRepository extends AbstractResourceRepository<'product'> {
|
|
@@ -454,6 +442,22 @@ declare class ShippingMethodRepository extends AbstractResourceRepository<'shipp
|
|
|
454
442
|
declare class ShoppingListRepository extends AbstractResourceRepository<'shopping-list'> {
|
|
455
443
|
getTypeId(): "shopping-list";
|
|
456
444
|
create(context: RepositoryContext, draft: ShoppingListDraft): ShoppingList;
|
|
445
|
+
actions: {
|
|
446
|
+
setKey: (context: RepositoryContext, resource: Writable<ShoppingList>, { key }: ShoppingListSetKeyAction) => void;
|
|
447
|
+
setSlug: (context: RepositoryContext, resource: Writable<ShoppingList>, { slug }: ShoppingListSetSlugAction) => void;
|
|
448
|
+
changeName: (context: RepositoryContext, resource: Writable<ShoppingList>, { name }: ShoppingListChangeNameAction) => void;
|
|
449
|
+
setDescription: (context: RepositoryContext, resource: Writable<ShoppingList>, { description }: ShoppingListSetDescriptionAction) => void;
|
|
450
|
+
setCustomer: (context: RepositoryContext, resource: Writable<ShoppingList>, { customer }: ShoppingListSetCustomerAction) => void;
|
|
451
|
+
setStore: (context: RepositoryContext, resource: Writable<ShoppingList>, { store }: ShoppingListSetStoreAction) => void;
|
|
452
|
+
setAnonymousId: (context: RepositoryContext, resource: Writable<ShoppingList>, { anonymousId }: ShoppingListSetAnonymousIdAction) => void;
|
|
453
|
+
setCustomType: (context: RepositoryContext, resource: Writable<ShoppingList>, { type, fields }: ShoppingListSetCustomTypeAction) => void;
|
|
454
|
+
setCustomField: (context: RepositoryContext, resource: ShoppingList, { name, value }: ShoppingListSetCustomFieldAction) => void;
|
|
455
|
+
setDeleteDaysAfterLastModification: (context: RepositoryContext, resource: Writable<ShoppingList>, { deleteDaysAfterLastModification, }: ShoppingListSetDeleteDaysAfterLastModificationAction) => void;
|
|
456
|
+
addLineItem: (context: RepositoryContext, resource: Writable<ShoppingList>, { productId, variantId, sku, quantity }: ShoppingListAddLineItemAction) => void;
|
|
457
|
+
removeLineItem: (context: RepositoryContext, resource: Writable<ShoppingList>, { lineItemId, quantity }: ShoppingListRemoveLineItemAction) => void;
|
|
458
|
+
changeLineItemQuantity: (context: RepositoryContext, resource: Writable<ShoppingList>, { lineItemId, lineItemKey, quantity, }: ShoppingListChangeLineItemQuantityAction) => void;
|
|
459
|
+
};
|
|
460
|
+
draftLineItemtoLineItem: (projectKey: string, draftLineItem: LineItemDraft) => ShoppingListLineItem;
|
|
457
461
|
}
|
|
458
462
|
|
|
459
463
|
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
|
|
@@ -3226,6 +3250,14 @@ var CustomerRepository = class extends AbstractResourceRepository {
|
|
|
3226
3250
|
throw new Error("Resource has no custom field");
|
|
3227
3251
|
}
|
|
3228
3252
|
resource.custom.fields[name] = value;
|
|
3253
|
+
},
|
|
3254
|
+
setCustomerNumber: (_context, resource, { customerNumber }) => {
|
|
3255
|
+
if (resource.customerNumber) {
|
|
3256
|
+
throw new Error(
|
|
3257
|
+
"A Customer number already exists and cannot be set again."
|
|
3258
|
+
);
|
|
3259
|
+
}
|
|
3260
|
+
resource.customerNumber = customerNumber;
|
|
3229
3261
|
}
|
|
3230
3262
|
};
|
|
3231
3263
|
};
|
|
@@ -3942,12 +3974,31 @@ var PaymentRepository = class extends AbstractResourceRepository {
|
|
|
3942
3974
|
// Documented as default
|
|
3943
3975
|
});
|
|
3944
3976
|
actions = {
|
|
3977
|
+
addInterfaceInteraction: (context, resource, { type, fields }) => {
|
|
3978
|
+
resource.interfaceInteractions.push(
|
|
3979
|
+
createCustomFields({ type, fields }, context.projectKey, this._storage)
|
|
3980
|
+
);
|
|
3981
|
+
},
|
|
3945
3982
|
addTransaction: (context, resource, { transaction }) => {
|
|
3946
3983
|
resource.transactions = [
|
|
3947
3984
|
...resource.transactions,
|
|
3948
3985
|
this.transactionFromTransactionDraft(transaction, context)
|
|
3949
3986
|
];
|
|
3950
3987
|
},
|
|
3988
|
+
changeAmountPlanned: (_context, resource, { amount }) => {
|
|
3989
|
+
resource.amountPlanned = createCentPrecisionMoney(amount);
|
|
3990
|
+
},
|
|
3991
|
+
changeTransactionInteractionId: (_context, resource, {
|
|
3992
|
+
transactionId,
|
|
3993
|
+
interactionId
|
|
3994
|
+
}) => {
|
|
3995
|
+
const transaction = resource.transactions.find(
|
|
3996
|
+
(e) => e.id === transactionId
|
|
3997
|
+
);
|
|
3998
|
+
if (transaction) {
|
|
3999
|
+
transaction.interactionId = interactionId;
|
|
4000
|
+
}
|
|
4001
|
+
},
|
|
3951
4002
|
changeTransactionState: (_context, resource, { transactionId, state }) => {
|
|
3952
4003
|
const index = resource.transactions.findIndex(
|
|
3953
4004
|
(e) => e.id === transactionId
|
|
@@ -3958,6 +4009,14 @@ var PaymentRepository = class extends AbstractResourceRepository {
|
|
|
3958
4009
|
};
|
|
3959
4010
|
resource.transactions[index] = updatedTransaction;
|
|
3960
4011
|
},
|
|
4012
|
+
changeTransactionTimestamp: (_context, resource, { transactionId, timestamp }) => {
|
|
4013
|
+
const transaction = resource.transactions.find(
|
|
4014
|
+
(e) => e.id === transactionId
|
|
4015
|
+
);
|
|
4016
|
+
if (transaction) {
|
|
4017
|
+
transaction.timestamp = timestamp;
|
|
4018
|
+
}
|
|
4019
|
+
},
|
|
3961
4020
|
transitionState: (context, resource, { state }) => {
|
|
3962
4021
|
const stateObj = this._storage.getByResourceIdentifier(
|
|
3963
4022
|
context.projectKey,
|
|
@@ -3972,6 +4031,21 @@ var PaymentRepository = class extends AbstractResourceRepository {
|
|
|
3972
4031
|
obj: stateObj
|
|
3973
4032
|
};
|
|
3974
4033
|
},
|
|
4034
|
+
setAnonymousId: (_context, resource, { anonymousId }) => {
|
|
4035
|
+
resource.anonymousId = anonymousId;
|
|
4036
|
+
resource.customer = void 0;
|
|
4037
|
+
},
|
|
4038
|
+
setCustomer: (_context, resource, { customer }) => {
|
|
4039
|
+
if (customer) {
|
|
4040
|
+
const c = getReferenceFromResourceIdentifier(
|
|
4041
|
+
customer,
|
|
4042
|
+
_context.projectKey,
|
|
4043
|
+
this._storage
|
|
4044
|
+
);
|
|
4045
|
+
resource.customer = c;
|
|
4046
|
+
resource.anonymousId = void 0;
|
|
4047
|
+
}
|
|
4048
|
+
},
|
|
3975
4049
|
setCustomField: (context, resource, { name, value }) => {
|
|
3976
4050
|
if (!resource.custom) {
|
|
3977
4051
|
throw new Error("Resource has no custom field");
|
|
@@ -3998,33 +4072,63 @@ var PaymentRepository = class extends AbstractResourceRepository {
|
|
|
3998
4072
|
};
|
|
3999
4073
|
}
|
|
4000
4074
|
},
|
|
4075
|
+
setInterfaceId: (_context, resource, { interfaceId }) => {
|
|
4076
|
+
resource.interfaceId = interfaceId;
|
|
4077
|
+
},
|
|
4001
4078
|
setKey: (_context, resource, { key }) => {
|
|
4002
4079
|
resource.key = key;
|
|
4003
4080
|
},
|
|
4004
|
-
|
|
4005
|
-
resource.
|
|
4006
|
-
},
|
|
4007
|
-
setStatusInterfaceText: (_context, resource, { interfaceText }) => {
|
|
4008
|
-
resource.paymentStatus.interfaceText = interfaceText;
|
|
4081
|
+
setMethodInfoMethod: (_context, resource, { method }) => {
|
|
4082
|
+
resource.paymentMethodInfo.method = method;
|
|
4009
4083
|
},
|
|
4010
4084
|
setMethodInfoName: (_context, resource, { name }) => {
|
|
4011
4085
|
resource.paymentMethodInfo.name = name;
|
|
4012
4086
|
},
|
|
4013
|
-
setMethodInfoMethod: (_context, resource, { method }) => {
|
|
4014
|
-
resource.paymentMethodInfo.method = method;
|
|
4015
|
-
},
|
|
4016
4087
|
setMethodInfoInterface: (_context, resource, args) => {
|
|
4017
4088
|
resource.paymentMethodInfo.paymentInterface = args.interface;
|
|
4018
4089
|
},
|
|
4019
|
-
|
|
4020
|
-
resource.
|
|
4090
|
+
setStatusInterfaceCode: (_context, resource, { interfaceCode }) => {
|
|
4091
|
+
resource.paymentStatus.interfaceCode = interfaceCode;
|
|
4092
|
+
},
|
|
4093
|
+
setStatusInterfaceText: (_context, resource, { interfaceText }) => {
|
|
4094
|
+
resource.paymentStatus.interfaceText = interfaceText;
|
|
4095
|
+
},
|
|
4096
|
+
setTransactionCustomField: (_context, resource, { transactionId, name, value }) => {
|
|
4097
|
+
const transaction = resource.transactions.find(
|
|
4098
|
+
(e) => e.id === transactionId
|
|
4099
|
+
);
|
|
4100
|
+
if (transaction) {
|
|
4101
|
+
if (!transaction.custom) {
|
|
4102
|
+
throw new Error("Transaction has no custom field");
|
|
4103
|
+
}
|
|
4104
|
+
transaction.custom.fields[name] = value;
|
|
4105
|
+
}
|
|
4106
|
+
},
|
|
4107
|
+
setTransactionCustomType: (context, resource, { transactionId, type, fields }) => {
|
|
4108
|
+
const transaction = resource.transactions.find(
|
|
4109
|
+
(e) => e.id === transactionId
|
|
4110
|
+
);
|
|
4111
|
+
if (transaction) {
|
|
4112
|
+
if (!type) {
|
|
4113
|
+
transaction.custom = void 0;
|
|
4114
|
+
} else {
|
|
4115
|
+
const resolvedType = this._storage.getByResourceIdentifier(
|
|
4116
|
+
context.projectKey,
|
|
4117
|
+
type
|
|
4118
|
+
);
|
|
4119
|
+
if (!resolvedType) {
|
|
4120
|
+
throw new Error(`Type ${type} not found`);
|
|
4121
|
+
}
|
|
4122
|
+
transaction.custom = {
|
|
4123
|
+
type: {
|
|
4124
|
+
typeId: "type",
|
|
4125
|
+
id: resolvedType.id
|
|
4126
|
+
},
|
|
4127
|
+
fields: fields ?? {}
|
|
4128
|
+
};
|
|
4129
|
+
}
|
|
4130
|
+
}
|
|
4021
4131
|
}
|
|
4022
|
-
// addInterfaceInteraction: () => {},
|
|
4023
|
-
// changeAmountPlanned: () => {},
|
|
4024
|
-
// changeTransactionInteractionId: () => {},
|
|
4025
|
-
// changeTransactionTimestamp: () => {},
|
|
4026
|
-
// setAnonymousId: () => {},
|
|
4027
|
-
// setCustomer: () => {},
|
|
4028
4132
|
};
|
|
4029
4133
|
};
|
|
4030
4134
|
|
|
@@ -5921,11 +6025,15 @@ var ShippingMethodRepository = class extends AbstractResourceRepository {
|
|
|
5921
6025
|
};
|
|
5922
6026
|
|
|
5923
6027
|
// src/repositories/shopping-list.ts
|
|
6028
|
+
import { v4 as uuidv48 } from "uuid";
|
|
5924
6029
|
var ShoppingListRepository = class extends AbstractResourceRepository {
|
|
5925
6030
|
getTypeId() {
|
|
5926
6031
|
return "shopping-list";
|
|
5927
6032
|
}
|
|
5928
6033
|
create(context, draft) {
|
|
6034
|
+
const lineItems = draft.lineItems?.map(
|
|
6035
|
+
(draftLineItem) => this.draftLineItemtoLineItem(context.projectKey, draftLineItem)
|
|
6036
|
+
) ?? [];
|
|
5929
6037
|
const resource = {
|
|
5930
6038
|
...getBaseResourceProperties(),
|
|
5931
6039
|
...draft,
|
|
@@ -5935,20 +6043,7 @@ var ShoppingListRepository = class extends AbstractResourceRepository {
|
|
|
5935
6043
|
this._storage
|
|
5936
6044
|
),
|
|
5937
6045
|
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
|
-
})) ?? [],
|
|
6046
|
+
lineItems,
|
|
5952
6047
|
customer: draft.customer ? getReferenceFromResourceIdentifier(
|
|
5953
6048
|
draft.customer,
|
|
5954
6049
|
context.projectKey,
|
|
@@ -5959,6 +6054,241 @@ var ShoppingListRepository = class extends AbstractResourceRepository {
|
|
|
5959
6054
|
this.saveNew(context, resource);
|
|
5960
6055
|
return resource;
|
|
5961
6056
|
}
|
|
6057
|
+
actions = {
|
|
6058
|
+
setKey: (context, resource, { key }) => {
|
|
6059
|
+
resource.key = key;
|
|
6060
|
+
},
|
|
6061
|
+
setSlug: (context, resource, { slug }) => {
|
|
6062
|
+
resource.slug = slug;
|
|
6063
|
+
},
|
|
6064
|
+
changeName: (context, resource, { name }) => {
|
|
6065
|
+
resource.name = name;
|
|
6066
|
+
},
|
|
6067
|
+
setDescription: (context, resource, { description }) => {
|
|
6068
|
+
resource.description = description;
|
|
6069
|
+
},
|
|
6070
|
+
setCustomer: (context, resource, { customer }) => {
|
|
6071
|
+
if (customer?.key) {
|
|
6072
|
+
throw new Error("set customer on shoppinglist by key not implemented");
|
|
6073
|
+
}
|
|
6074
|
+
if (customer?.id) {
|
|
6075
|
+
resource.customer = { typeId: "customer", id: customer.id };
|
|
6076
|
+
}
|
|
6077
|
+
},
|
|
6078
|
+
setStore: (context, resource, { store }) => {
|
|
6079
|
+
if (store?.key) {
|
|
6080
|
+
resource.store = { typeId: "store", key: store.key };
|
|
6081
|
+
}
|
|
6082
|
+
if (store?.id) {
|
|
6083
|
+
throw new Error("set store on shoppinglist by id not implemented");
|
|
6084
|
+
}
|
|
6085
|
+
},
|
|
6086
|
+
setAnonymousId: (context, resource, { anonymousId }) => {
|
|
6087
|
+
resource.anonymousId = anonymousId;
|
|
6088
|
+
},
|
|
6089
|
+
setCustomType: (context, resource, { type, fields }) => {
|
|
6090
|
+
if (!type) {
|
|
6091
|
+
resource.custom = void 0;
|
|
6092
|
+
} else {
|
|
6093
|
+
const resolvedType = this._storage.getByResourceIdentifier(
|
|
6094
|
+
context.projectKey,
|
|
6095
|
+
type
|
|
6096
|
+
);
|
|
6097
|
+
if (!resolvedType) {
|
|
6098
|
+
throw new Error(`Type ${type} not found`);
|
|
6099
|
+
}
|
|
6100
|
+
resource.custom = {
|
|
6101
|
+
type: {
|
|
6102
|
+
typeId: "type",
|
|
6103
|
+
id: resolvedType.id
|
|
6104
|
+
},
|
|
6105
|
+
fields: fields || {}
|
|
6106
|
+
};
|
|
6107
|
+
}
|
|
6108
|
+
},
|
|
6109
|
+
setCustomField: (context, resource, { name, value }) => {
|
|
6110
|
+
if (!resource.custom) {
|
|
6111
|
+
throw new Error("Resource has no custom field");
|
|
6112
|
+
}
|
|
6113
|
+
resource.custom.fields[name] = value;
|
|
6114
|
+
},
|
|
6115
|
+
setDeleteDaysAfterLastModification: (context, resource, {
|
|
6116
|
+
deleteDaysAfterLastModification
|
|
6117
|
+
}) => {
|
|
6118
|
+
resource.deleteDaysAfterLastModification = deleteDaysAfterLastModification;
|
|
6119
|
+
},
|
|
6120
|
+
addLineItem: (context, resource, { productId, variantId, sku, quantity = 1 }) => {
|
|
6121
|
+
let product = null;
|
|
6122
|
+
if (productId) {
|
|
6123
|
+
product = this._storage.get(
|
|
6124
|
+
context.projectKey,
|
|
6125
|
+
"product",
|
|
6126
|
+
productId,
|
|
6127
|
+
{}
|
|
6128
|
+
);
|
|
6129
|
+
} else if (sku) {
|
|
6130
|
+
const items = this._storage.query(context.projectKey, "product", {
|
|
6131
|
+
where: [
|
|
6132
|
+
`masterData(current(masterVariant(sku="${sku}"))) or masterData(current(variants(sku="${sku}")))`
|
|
6133
|
+
]
|
|
6134
|
+
});
|
|
6135
|
+
if (items.count === 1) {
|
|
6136
|
+
product = items.results[0];
|
|
6137
|
+
}
|
|
6138
|
+
}
|
|
6139
|
+
if (!product) {
|
|
6140
|
+
throw new CommercetoolsError({
|
|
6141
|
+
code: "General",
|
|
6142
|
+
message: sku ? `A product containing a variant with SKU '${sku}' not found.` : `A product with ID '${productId}' not found.`
|
|
6143
|
+
});
|
|
6144
|
+
}
|
|
6145
|
+
let varId = variantId;
|
|
6146
|
+
if (sku) {
|
|
6147
|
+
varId = [
|
|
6148
|
+
product.masterData.current.masterVariant,
|
|
6149
|
+
...product.masterData.current.variants
|
|
6150
|
+
].find((x) => x.sku === sku)?.id;
|
|
6151
|
+
}
|
|
6152
|
+
if (!varId) {
|
|
6153
|
+
varId = product.masterData.current.masterVariant.id;
|
|
6154
|
+
}
|
|
6155
|
+
const alreadyAdded = resource.lineItems.some(
|
|
6156
|
+
(x) => x.productId === product?.id && x.variantId === varId
|
|
6157
|
+
);
|
|
6158
|
+
if (alreadyAdded) {
|
|
6159
|
+
resource.lineItems.forEach((x) => {
|
|
6160
|
+
if (x.productId === product?.id && x.variantId === varId) {
|
|
6161
|
+
x.quantity += quantity;
|
|
6162
|
+
}
|
|
6163
|
+
});
|
|
6164
|
+
} else {
|
|
6165
|
+
resource.lineItems.push({
|
|
6166
|
+
addedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
6167
|
+
id: uuidv48(),
|
|
6168
|
+
productId: product.id,
|
|
6169
|
+
productSlug: product.masterData.current.slug,
|
|
6170
|
+
productType: product.productType,
|
|
6171
|
+
name: product.masterData.current.name,
|
|
6172
|
+
variantId: varId,
|
|
6173
|
+
quantity
|
|
6174
|
+
});
|
|
6175
|
+
}
|
|
6176
|
+
},
|
|
6177
|
+
removeLineItem: (context, resource, { lineItemId, quantity }) => {
|
|
6178
|
+
const lineItem = resource.lineItems.find((x) => x.id === lineItemId);
|
|
6179
|
+
if (!lineItem) {
|
|
6180
|
+
throw new CommercetoolsError({
|
|
6181
|
+
code: "General",
|
|
6182
|
+
message: `A line item with ID '${lineItemId}' not found.`
|
|
6183
|
+
});
|
|
6184
|
+
}
|
|
6185
|
+
const shouldDelete = !quantity || quantity >= lineItem.quantity;
|
|
6186
|
+
if (shouldDelete) {
|
|
6187
|
+
resource.lineItems = resource.lineItems.filter(
|
|
6188
|
+
(x) => x.id !== lineItemId
|
|
6189
|
+
);
|
|
6190
|
+
} else {
|
|
6191
|
+
resource.lineItems.forEach((x) => {
|
|
6192
|
+
if (x.id === lineItemId && quantity) {
|
|
6193
|
+
x.quantity -= quantity;
|
|
6194
|
+
}
|
|
6195
|
+
});
|
|
6196
|
+
}
|
|
6197
|
+
},
|
|
6198
|
+
changeLineItemQuantity: (context, resource, {
|
|
6199
|
+
lineItemId,
|
|
6200
|
+
lineItemKey,
|
|
6201
|
+
quantity
|
|
6202
|
+
}) => {
|
|
6203
|
+
let lineItem;
|
|
6204
|
+
if (lineItemId) {
|
|
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 ID '${lineItemId}' not found.`
|
|
6210
|
+
});
|
|
6211
|
+
}
|
|
6212
|
+
} else if (lineItemKey) {
|
|
6213
|
+
lineItem = resource.lineItems.find((x) => x.id === lineItemId);
|
|
6214
|
+
if (!lineItem) {
|
|
6215
|
+
throw new CommercetoolsError({
|
|
6216
|
+
code: "General",
|
|
6217
|
+
message: `A line item with Key '${lineItemKey}' not found.`
|
|
6218
|
+
});
|
|
6219
|
+
}
|
|
6220
|
+
} else {
|
|
6221
|
+
throw new CommercetoolsError({
|
|
6222
|
+
code: "General",
|
|
6223
|
+
message: `Either lineItemid or lineItemKey needs to be provided.`
|
|
6224
|
+
});
|
|
6225
|
+
}
|
|
6226
|
+
if (quantity === 0) {
|
|
6227
|
+
resource.lineItems = resource.lineItems.filter(
|
|
6228
|
+
(x) => x.id !== lineItemId
|
|
6229
|
+
);
|
|
6230
|
+
} else {
|
|
6231
|
+
resource.lineItems.forEach((x) => {
|
|
6232
|
+
if (x.id === lineItemId && quantity) {
|
|
6233
|
+
x.quantity = quantity;
|
|
6234
|
+
}
|
|
6235
|
+
});
|
|
6236
|
+
}
|
|
6237
|
+
}
|
|
6238
|
+
};
|
|
6239
|
+
draftLineItemtoLineItem = (projectKey, draftLineItem) => {
|
|
6240
|
+
const { sku, productId, variantId } = draftLineItem;
|
|
6241
|
+
const lineItem = {
|
|
6242
|
+
...getBaseResourceProperties(),
|
|
6243
|
+
...draftLineItem,
|
|
6244
|
+
addedAt: draftLineItem.addedAt ?? "",
|
|
6245
|
+
productId: draftLineItem.productId ?? "",
|
|
6246
|
+
name: {},
|
|
6247
|
+
variantId,
|
|
6248
|
+
quantity: draftLineItem.quantity ?? 1,
|
|
6249
|
+
productType: { typeId: "product-type", id: "" },
|
|
6250
|
+
custom: createCustomFields(
|
|
6251
|
+
draftLineItem.custom,
|
|
6252
|
+
projectKey,
|
|
6253
|
+
this._storage
|
|
6254
|
+
)
|
|
6255
|
+
};
|
|
6256
|
+
if (variantId) {
|
|
6257
|
+
return lineItem;
|
|
6258
|
+
}
|
|
6259
|
+
if (sku) {
|
|
6260
|
+
const items = this._storage.query(projectKey, "product", {
|
|
6261
|
+
where: [
|
|
6262
|
+
`masterData(current(masterVariant(sku="${sku}"))) or masterData(current(variants(sku="${sku}")))`
|
|
6263
|
+
]
|
|
6264
|
+
});
|
|
6265
|
+
if (items.count === 0) {
|
|
6266
|
+
throw new Error(`Product with sku ${sku} not found`);
|
|
6267
|
+
}
|
|
6268
|
+
const product = items.results[0];
|
|
6269
|
+
const allVariants = [
|
|
6270
|
+
product.masterData.current.masterVariant,
|
|
6271
|
+
...product.masterData.current.variants
|
|
6272
|
+
];
|
|
6273
|
+
const variantId2 = allVariants.find((e) => e.sku === sku)?.id;
|
|
6274
|
+
lineItem.variantId = variantId2;
|
|
6275
|
+
return lineItem;
|
|
6276
|
+
}
|
|
6277
|
+
if (productId) {
|
|
6278
|
+
const items = this._storage.query(projectKey, "product", {
|
|
6279
|
+
where: [`id="${productId}"`]
|
|
6280
|
+
});
|
|
6281
|
+
if (items.count === 0) {
|
|
6282
|
+
throw new Error(`Product with id ${productId} not found`);
|
|
6283
|
+
}
|
|
6284
|
+
const variantId2 = items.results[0].masterData.current.masterVariant.id;
|
|
6285
|
+
lineItem.variantId = variantId2;
|
|
6286
|
+
return lineItem;
|
|
6287
|
+
}
|
|
6288
|
+
throw new Error(
|
|
6289
|
+
`must provide either sku, productId or variantId for ShoppingListLineItem`
|
|
6290
|
+
);
|
|
6291
|
+
};
|
|
5962
6292
|
};
|
|
5963
6293
|
|
|
5964
6294
|
// src/repositories/staged-quote.ts
|
|
@@ -6177,7 +6507,7 @@ var SubscriptionRepository = class extends AbstractResourceRepository {
|
|
|
6177
6507
|
};
|
|
6178
6508
|
|
|
6179
6509
|
// src/repositories/tax-category.ts
|
|
6180
|
-
import { v4 as
|
|
6510
|
+
import { v4 as uuidv49 } from "uuid";
|
|
6181
6511
|
var TaxCategoryRepository = class extends AbstractResourceRepository {
|
|
6182
6512
|
getTypeId() {
|
|
6183
6513
|
return "tax-category";
|
|
@@ -6193,7 +6523,7 @@ var TaxCategoryRepository = class extends AbstractResourceRepository {
|
|
|
6193
6523
|
}
|
|
6194
6524
|
taxRateFromTaxRateDraft = (draft) => ({
|
|
6195
6525
|
...draft,
|
|
6196
|
-
id:
|
|
6526
|
+
id: uuidv49(),
|
|
6197
6527
|
amount: draft.amount || 0
|
|
6198
6528
|
});
|
|
6199
6529
|
actions = {
|
|
@@ -6752,7 +7082,7 @@ var CustomerGroupService = class extends AbstractService {
|
|
|
6752
7082
|
};
|
|
6753
7083
|
|
|
6754
7084
|
// src/services/customer.ts
|
|
6755
|
-
import { v4 as
|
|
7085
|
+
import { v4 as uuidv410 } from "uuid";
|
|
6756
7086
|
var CustomerService = class extends AbstractService {
|
|
6757
7087
|
repository;
|
|
6758
7088
|
constructor(parent, repository) {
|
|
@@ -6776,7 +7106,7 @@ var CustomerService = class extends AbstractService {
|
|
|
6776
7106
|
...rest,
|
|
6777
7107
|
customerId: customer.results[0].id,
|
|
6778
7108
|
expiresAt: new Date(Date.now() + ttlMinutes * 60).toISOString(),
|
|
6779
|
-
value:
|
|
7109
|
+
value: uuidv410()
|
|
6780
7110
|
});
|
|
6781
7111
|
});
|
|
6782
7112
|
}
|