@labdigital/commercetools-mock 1.2.0 → 1.3.1

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.
Files changed (86) hide show
  1. package/dist/index.d.mts +602 -0
  2. package/dist/index.d.ts +43 -26
  3. package/dist/index.global.js +5827 -5596
  4. package/dist/index.global.js.map +1 -1
  5. package/dist/index.js +344 -167
  6. package/dist/index.js.map +1 -1
  7. package/dist/index.mjs +344 -171
  8. package/dist/index.mjs.map +1 -1
  9. package/package.json +33 -39
  10. package/src/index.test.ts +2 -1
  11. package/src/lib/haversine.test.ts +1 -0
  12. package/src/lib/predicateParser.test.ts +2 -1
  13. package/src/lib/predicateParser.ts +2 -2
  14. package/src/lib/projectionSearchFilter.test.ts +2 -1
  15. package/src/lib/projectionSearchFilter.ts +4 -4
  16. package/src/oauth/server.ts +3 -4
  17. package/src/priceSelector.test.ts +2 -1
  18. package/src/priceSelector.ts +2 -2
  19. package/src/product-projection-search.ts +8 -8
  20. package/src/projectAPI.test.ts +1 -0
  21. package/src/repositories/abstract.ts +1 -1
  22. package/src/repositories/associate-role.ts +11 -0
  23. package/src/repositories/attribute-group.ts +11 -0
  24. package/src/repositories/business-unit.ts +11 -0
  25. package/src/repositories/cart-discount.ts +11 -4
  26. package/src/repositories/cart.ts +90 -13
  27. package/src/repositories/category.ts +3 -3
  28. package/src/repositories/channel.ts +3 -3
  29. package/src/repositories/custom-object.ts +3 -3
  30. package/src/repositories/customer-group.ts +3 -3
  31. package/src/repositories/customer.ts +4 -3
  32. package/src/repositories/discount-code.ts +3 -3
  33. package/src/repositories/errors.ts +1 -1
  34. package/src/repositories/extension.ts +3 -3
  35. package/src/repositories/helpers.ts +49 -6
  36. package/src/repositories/index.ts +6 -0
  37. package/src/repositories/inventory-entry.ts +4 -4
  38. package/src/repositories/my-order.ts +2 -2
  39. package/src/repositories/order-edit.ts +2 -2
  40. package/src/repositories/order.test.ts +10 -39
  41. package/src/repositories/order.ts +31 -16
  42. package/src/repositories/payment.ts +8 -7
  43. package/src/repositories/product-discount.ts +2 -2
  44. package/src/repositories/product-projection.ts +5 -5
  45. package/src/repositories/product-selection.ts +3 -2
  46. package/src/repositories/product-type.ts +2 -2
  47. package/src/repositories/product.ts +4 -9
  48. package/src/repositories/project.ts +2 -2
  49. package/src/repositories/quote-request.ts +2 -2
  50. package/src/repositories/quote.ts +2 -2
  51. package/src/repositories/review.ts +2 -2
  52. package/src/repositories/shipping-method.ts +2 -2
  53. package/src/repositories/shopping-list.ts +19 -13
  54. package/src/repositories/staged-quote.ts +2 -2
  55. package/src/repositories/standalone-price.ts +3 -3
  56. package/src/repositories/state.ts +2 -2
  57. package/src/repositories/store.ts +3 -2
  58. package/src/repositories/subscription.ts +1 -1
  59. package/src/repositories/tax-category.ts +2 -2
  60. package/src/repositories/type.ts +2 -2
  61. package/src/repositories/zone.ts +2 -2
  62. package/src/services/abstract.ts +2 -2
  63. package/src/services/cart.test.ts +2 -1
  64. package/src/services/cart.ts +4 -4
  65. package/src/services/category.test.ts +2 -1
  66. package/src/services/custom-object.test.ts +2 -1
  67. package/src/services/custom-object.ts +3 -3
  68. package/src/services/customer.test.ts +1 -0
  69. package/src/services/inventory-entry.test.ts +2 -1
  70. package/src/services/my-cart.test.ts +7 -3
  71. package/src/services/my-customer.test.ts +4 -2
  72. package/src/services/my-payment.test.ts +2 -1
  73. package/src/services/order.test.ts +2 -1
  74. package/src/services/payment.test.ts +2 -1
  75. package/src/services/product-projection.test.ts +3 -2
  76. package/src/services/product-type.test.ts +2 -1
  77. package/src/services/product.test.ts +2 -1
  78. package/src/services/project.ts +1 -1
  79. package/src/services/shipping-method.test.ts +2 -1
  80. package/src/services/standalone-price.test.ts +255 -244
  81. package/src/services/state.test.ts +2 -1
  82. package/src/services/store.test.ts +6 -1
  83. package/src/services/tax-category.test.ts +2 -1
  84. package/src/storage/abstract.ts +1 -1
  85. package/src/storage/in-memory.ts +7 -1
  86. package/src/types.ts +7 -1
package/dist/index.d.ts CHANGED
@@ -1,12 +1,12 @@
1
1
  import express from 'express';
2
2
  import * as ctp from '@commercetools/platform-sdk';
3
- import { Project, ResourceIdentifier, QueryParam, CartDraft, Cart, CartAddLineItemAction, CartRemoveLineItemAction, CartSetBillingAddressAction, CartSetShippingMethodAction, CartSetCountryAction, CartSetCustomerEmailAction, CartSetCustomFieldAction, CartSetCustomTypeAction, CartSetLocaleAction, CartSetShippingAddressAction, LineItemDraft, LineItem, CartDiscountDraft, CartDiscount, CartDiscountUpdateAction, CategoryDraft, Category, CategoryChangeAssetNameAction, CategoryChangeSlugAction, CategorySetKeyAction, CategorySetAssetDescriptionAction, CategorySetAssetSourcesAction, CategorySetDescriptionAction, CategorySetMetaDescriptionAction, CategorySetMetaKeywordsAction, CategorySetMetaTitleAction, CategorySetCustomTypeAction, CategorySetCustomFieldAction, ChannelDraft, Channel, ChannelUpdateAction, CustomObjectDraft, CustomObject, CustomerDraft, Customer, CustomerChangeEmailAction, CustomerSetAuthenticationModeAction, CustomerGroupDraft, CustomerGroup, CustomerGroupSetKeyAction, CustomerGroupChangeNameAction, CustomerGroupSetCustomTypeAction, CustomerGroupSetCustomFieldAction, DiscountCodeDraft, DiscountCode, DiscountCodeUpdateAction, Extension, ExtensionDraft, ExtensionUpdateAction, InventoryEntryDraft, InventoryEntry, InventoryEntryChangeQuantityAction, InventoryEntrySetExpectedDeliveryAction, InventoryEntrySetCustomFieldAction, InventoryEntrySetCustomTypeAction, InventoryEntrySetRestockableInDaysAction, OrderFromCartDraft, Order, CartReference, OrderImportDraft, OrderAddPaymentAction, OrderChangeOrderStateAction, OrderChangePaymentStateAction, OrderTransitionStateAction, OrderSetBillingAddressAction, OrderSetCustomerEmailAction, OrderSetCustomFieldAction, OrderSetCustomTypeAction, OrderSetLocaleAction, OrderSetOrderNumberAction, OrderSetShippingAddressAction, OrderSetStoreAction, MyOrderFromCartDraft, OrderEditDraft, OrderEdit, OrderEditUpdateAction, PaymentDraft, Payment, TransactionDraft, PaymentSetCustomFieldAction, PaymentSetCustomTypeAction, PaymentAddTransactionAction, PaymentChangeTransactionStateAction, PaymentTransitionStateAction, ProductDraft, Product, ProductUpdateAction, ProductDiscountDraft, ProductDiscount, ProductDiscountUpdateAction, ProductProjectionPagedSearchResponse, ProductProjection, FacetResults, TermFacetResult, FilteredFacetResult, RangeFacetResult, ProductSelectionDraft, ProductSelection, ReviewUpdateAction, Review, ProductTypeDraft, ProductType, AttributeDefinitionDraft, AttributeDefinition, ProductTypeUpdateAction, ProjectUpdateAction, QuoteDraft, Quote, QuoteUpdateAction, QuoteRequestDraft, QuoteRequest, QuoteRequestUpdateAction, ReviewDraft, ShippingMethodDraft, ShippingMethod, ShippingMethodUpdateAction, ShoppingListDraft, ShoppingList, StagedQuoteDraft, StagedQuote, StagedQuoteUpdateAction, StandalonePriceDraft, StandalonePrice, ChannelResourceIdentifier, ChannelReference, DiscountedPriceDraft, StandalonePriceChangeActiveAction, StandalonePriceChangeValueAction, StandalonePriceSetDiscountedPriceAction, StateDraft, State, StateUpdateAction, StoreDraft, Store, StoreUpdateAction, SubscriptionDraft, Subscription, TaxCategoryDraft, TaxCategory, TaxCategoryUpdateAction, TypeDraft, Type, TypeUpdateAction, ZoneDraft, Zone, ZoneUpdateAction, BaseResource, UpdateAction } from '@commercetools/platform-sdk';
3
+ import { Project, ResourceIdentifier, QueryParam, AssociateRole, AttributeGroup, BusinessUnit, CartDraft, Cart, CartAddLineItemAction, CartChangeLineItemQuantityAction, CartRemoveLineItemAction, CartSetBillingAddressAction, CartSetShippingMethodAction, CartSetCountryAction, CartSetCustomerEmailAction, CartSetCustomFieldAction, CartSetCustomTypeAction, CartSetLocaleAction, CartSetShippingAddressAction, LineItemDraft, LineItem, CartDiscountDraft, CartDiscount, CartDiscountUpdateAction, CategoryDraft, Category, CategoryChangeAssetNameAction, CategoryChangeSlugAction, CategorySetKeyAction, CategorySetAssetDescriptionAction, CategorySetAssetSourcesAction, CategorySetDescriptionAction, CategorySetMetaDescriptionAction, CategorySetMetaKeywordsAction, CategorySetMetaTitleAction, CategorySetCustomTypeAction, CategorySetCustomFieldAction, ChannelDraft, Channel, ChannelUpdateAction, CustomObjectDraft, CustomObject, CustomerDraft, Customer, CustomerChangeEmailAction, CustomerSetAuthenticationModeAction, CustomerGroupDraft, CustomerGroup, CustomerGroupSetKeyAction, CustomerGroupChangeNameAction, CustomerGroupSetCustomTypeAction, CustomerGroupSetCustomFieldAction, DiscountCodeDraft, DiscountCode, DiscountCodeUpdateAction, Extension, ExtensionDraft, ExtensionUpdateAction, InventoryEntryDraft, InventoryEntry, InventoryEntryChangeQuantityAction, InventoryEntrySetExpectedDeliveryAction, InventoryEntrySetCustomFieldAction, InventoryEntrySetCustomTypeAction, InventoryEntrySetRestockableInDaysAction, OrderFromCartDraft, Order, CartReference, OrderImportDraft, OrderAddPaymentAction, OrderChangeOrderStateAction, OrderChangePaymentStateAction, OrderTransitionStateAction, OrderSetBillingAddressAction, OrderSetCustomerEmailAction, OrderSetCustomFieldAction, OrderSetCustomTypeAction, OrderSetLocaleAction, OrderSetOrderNumberAction, OrderSetShippingAddressAction, OrderSetStoreAction, MyOrderFromCartDraft, OrderEditDraft, OrderEdit, OrderEditUpdateAction, PaymentDraft, Payment, TransactionDraft, Transaction, PaymentSetCustomFieldAction, PaymentSetCustomTypeAction, PaymentAddTransactionAction, PaymentChangeTransactionStateAction, PaymentTransitionStateAction, ProductDraft, Product, ProductUpdateAction, ProductDiscountDraft, ProductDiscount, ProductDiscountUpdateAction, ProductProjectionPagedSearchResponse, ProductProjection, FacetResults, TermFacetResult, FilteredFacetResult, RangeFacetResult, ProductSelectionDraft, ProductSelection, ReviewUpdateAction, Review, ProductTypeDraft, ProductType, AttributeDefinitionDraft, AttributeDefinition, ProductTypeUpdateAction, ProjectUpdateAction, QuoteDraft, Quote, QuoteUpdateAction, QuoteRequestDraft, QuoteRequest, QuoteRequestUpdateAction, ReviewDraft, ShippingMethodDraft, ShippingMethod, ShippingMethodUpdateAction, ShoppingListDraft, ShoppingList, StagedQuoteDraft, StagedQuote, StagedQuoteUpdateAction, StandalonePriceDraft, StandalonePrice, ChannelResourceIdentifier, ChannelReference, DiscountedPriceDraft, StandalonePriceChangeActiveAction, StandalonePriceChangeValueAction, StandalonePriceSetDiscountedPriceAction, StateDraft, State, StateUpdateAction, StoreDraft, Store, StoreUpdateAction, SubscriptionDraft, Subscription, TaxCategoryDraft, TaxCategory, TaxCategoryUpdateAction, TypeDraft, Type, TypeUpdateAction, ZoneDraft, Zone, ZoneUpdateAction, BaseResource, UpdateAction } from '@commercetools/platform-sdk';
4
4
  import { ParsedQs } from 'qs';
5
5
 
6
- declare type GetParams$1 = {
6
+ type GetParams$1 = {
7
7
  expand?: string[];
8
8
  };
9
- declare type QueryParams$1 = {
9
+ type QueryParams$1 = {
10
10
  expand?: string | string[];
11
11
  sort?: string | string[];
12
12
  limit?: number;
@@ -30,12 +30,28 @@ declare abstract class AbstractStorage {
30
30
  abstract expand<T>(projectKey: string, obj: T, clause: undefined | string | string[]): T;
31
31
  }
32
32
 
33
+ declare class AssociateRoleRepository extends AbstractResourceRepository<'associate-role'> {
34
+ getTypeId(): "associate-role";
35
+ create(context: RepositoryContext, draft: any): AssociateRole;
36
+ }
37
+
38
+ declare class AttributeGroupRepository extends AbstractResourceRepository<'attribute-group'> {
39
+ getTypeId(): "attribute-group";
40
+ create(context: RepositoryContext, draft: any): AttributeGroup;
41
+ }
42
+
43
+ declare class BusinessUnitRepository extends AbstractResourceRepository<'business-unit'> {
44
+ getTypeId(): "business-unit";
45
+ create(context: RepositoryContext, draft: any): BusinessUnit;
46
+ }
47
+
33
48
  declare class CartRepository extends AbstractResourceRepository<'cart'> {
34
49
  getTypeId(): "cart";
35
50
  create(context: RepositoryContext, draft: CartDraft): Cart;
36
51
  getActiveCart(projectKey: string): Cart | undefined;
37
52
  actions: {
38
53
  addLineItem: (context: RepositoryContext, resource: Writable<Cart>, { productId, variantId, sku, quantity }: CartAddLineItemAction) => void;
54
+ changeLineItemQuantity: (context: RepositoryContext, resource: Writable<Cart>, { lineItemId, lineItemKey, quantity }: CartChangeLineItemQuantityAction) => void;
39
55
  removeLineItem: (context: RepositoryContext, resource: Writable<Cart>, { lineItemId, quantity }: CartRemoveLineItemAction) => void;
40
56
  setBillingAddress: (context: RepositoryContext, resource: Writable<Cart>, { address }: CartSetBillingAddressAction) => void;
41
57
  setShippingMethod: (context: RepositoryContext, resource: Writable<Cart>, { shippingMethod }: CartSetShippingMethodAction) => void;
@@ -169,15 +185,7 @@ declare class OrderEditRepository extends AbstractResourceRepository<'order-edit
169
185
  declare class PaymentRepository extends AbstractResourceRepository<'payment'> {
170
186
  getTypeId(): "payment";
171
187
  create(context: RepositoryContext, draft: PaymentDraft): Payment;
172
- transactionFromTransactionDraft: (draft: TransactionDraft, context: RepositoryContext) => {
173
- id: string;
174
- amount: ctp.TypedMoney;
175
- custom: ctp.CustomFields | undefined;
176
- timestamp?: string | undefined;
177
- type: ctp.TransactionType;
178
- interactionId?: string | undefined;
179
- state?: ctp.TransactionState | undefined;
180
- };
188
+ transactionFromTransactionDraft: (draft: TransactionDraft, context: RepositoryContext) => Transaction;
181
189
  actions: {
182
190
  setCustomField: (context: RepositoryContext, resource: Payment, { name, value }: PaymentSetCustomFieldAction) => void;
183
191
  setCustomType: (context: RepositoryContext, resource: Writable<Payment>, { type, fields }: PaymentSetCustomTypeAction) => void;
@@ -204,18 +212,18 @@ declare class ProductDiscountRepository extends AbstractResourceRepository<'prod
204
212
  * This module implements the commercetools product projection filter expression.
205
213
  */
206
214
 
207
- declare type RangeExpression = {
215
+ type RangeExpression = {
208
216
  type: 'RangeExpression';
209
217
  start?: number;
210
218
  stop?: number;
211
219
  match: (obj: any) => boolean;
212
220
  };
213
- declare type FilterExpression = {
221
+ type FilterExpression = {
214
222
  type: 'FilterExpression';
215
223
  match: (obj: any) => boolean;
216
224
  };
217
225
 
218
- declare type ProductProjectionSearchParams = {
226
+ type ProductProjectionSearchParams = {
219
227
  fuzzy?: boolean;
220
228
  fuzzyLevel?: number;
221
229
  markMatchingVariants?: boolean;
@@ -379,8 +387,11 @@ declare class ZoneRepository extends AbstractResourceRepository<'zone'> {
379
387
  actions: Partial<Record<ZoneUpdateAction['action'], (context: RepositoryContext, resource: Writable<Zone>, action: any) => void>>;
380
388
  }
381
389
 
382
- declare type RepositoryMap = ReturnType<typeof createRepositories>;
390
+ type RepositoryMap = ReturnType<typeof createRepositories>;
383
391
  declare const createRepositories: (storage: AbstractStorage) => {
392
+ 'associate-role': AssociateRoleRepository;
393
+ 'attribute-group': AttributeGroupRepository;
394
+ 'business-unit': BusinessUnitRepository;
384
395
  category: CategoryRepository;
385
396
  cart: CartRepository;
386
397
  'cart-discount': CartDiscountRepository;
@@ -419,14 +430,17 @@ declare const createRepositories: (storage: AbstractStorage) => {
419
430
  zone: ZoneRepository;
420
431
  };
421
432
 
422
- declare type Writable<T> = {
433
+ type Writable<T> = {
423
434
  -readonly [P in keyof T]: Writable<T[P]>;
424
435
  };
425
- declare type ShallowWritable<T> = {
436
+ type ShallowWritable<T> = {
426
437
  -readonly [P in keyof T]: T[P];
427
438
  };
428
- declare type ResourceType = keyof ResourceMap & keyof RepositoryMap;
429
- declare type ResourceMap = {
439
+ type ResourceType = keyof ResourceMap & keyof RepositoryMap;
440
+ type ResourceMap = {
441
+ 'attribute-group': ctp.AttributeGroup;
442
+ 'associate-role': ctp.AssociateRole;
443
+ 'business-unit': ctp.BusinessUnit;
430
444
  'cart-discount': ctp.CartDiscount;
431
445
  cart: ctp.Cart;
432
446
  category: ctp.Category;
@@ -462,7 +476,10 @@ declare type ResourceMap = {
462
476
  type: ctp.Type;
463
477
  zone: ctp.Zone;
464
478
  };
465
- declare type PagedQueryResponseMap = {
479
+ type PagedQueryResponseMap = {
480
+ 'attribute-group': ctp.AttributeGroupPagedQueryResponse;
481
+ 'associate-role': ctp.AssociateRolePagedQueryResponse;
482
+ 'business-unit': ctp.BusinessUnitPagedQueryResponse;
466
483
  'cart-discount': ctp.CartDiscountPagedQueryResponse;
467
484
  cart: ctp.CartPagedQueryResponse;
468
485
  category: ctp.CategoryPagedQueryResponse;
@@ -499,16 +516,16 @@ declare type PagedQueryResponseMap = {
499
516
  zone: ctp.ZonePagedQueryResponse;
500
517
  };
501
518
 
502
- declare type QueryParams = {
519
+ type QueryParams = {
503
520
  expand?: string[];
504
521
  where?: string[];
505
522
  offset?: number;
506
523
  limit?: number;
507
524
  };
508
- declare type GetParams = {
525
+ type GetParams = {
509
526
  expand?: string[];
510
527
  };
511
- declare type RepositoryContext = {
528
+ type RepositoryContext = {
512
529
  projectKey: string;
513
530
  storeKey?: string;
514
531
  };
@@ -544,7 +561,7 @@ declare class ProjectAPI {
544
561
  getRepository<RT extends keyof RepositoryMap>(typeId: RT): RepositoryMap[RT];
545
562
  }
546
563
 
547
- declare type CommercetoolsMockOptions = {
564
+ type CommercetoolsMockOptions = {
548
565
  validateCredentials: boolean;
549
566
  enableAuthentication: boolean;
550
567
  defaultProjectKey: string | undefined;
@@ -552,7 +569,7 @@ declare type CommercetoolsMockOptions = {
552
569
  authHost: RegExp | string;
553
570
  silent: boolean;
554
571
  };
555
- declare type AppOptions = {
572
+ type AppOptions = {
556
573
  silent?: boolean;
557
574
  };
558
575
  declare class CommercetoolsMock {