@labdigital/commercetools-mock 1.5.0 → 1.6.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 (129) hide show
  1. package/README.md +5 -4
  2. package/dist/index.cjs +117 -17
  3. package/dist/index.cjs.map +1 -1
  4. package/dist/index.d.cts +30 -7
  5. package/dist/index.d.ts +30 -7
  6. package/dist/index.js +117 -17
  7. package/dist/index.js.map +1 -1
  8. package/package.json +4 -3
  9. package/src/constants.ts +2 -2
  10. package/src/ctMock.ts +176 -176
  11. package/src/exceptions.ts +10 -10
  12. package/src/helpers.ts +26 -26
  13. package/src/index.test.ts +173 -173
  14. package/src/index.ts +3 -3
  15. package/src/lib/expandParser.ts +19 -19
  16. package/src/lib/haversine.test.ts +13 -13
  17. package/src/lib/haversine.ts +14 -14
  18. package/src/lib/masking.ts +15 -15
  19. package/src/lib/parser.ts +2 -2
  20. package/src/lib/predicateParser.test.ts +204 -204
  21. package/src/lib/predicateParser.ts +398 -398
  22. package/src/lib/projectionSearchFilter.test.ts +168 -168
  23. package/src/lib/projectionSearchFilter.ts +272 -269
  24. package/src/lib/proxy.ts +8 -8
  25. package/src/oauth/errors.ts +4 -4
  26. package/src/oauth/helpers.ts +6 -6
  27. package/src/oauth/server.ts +103 -101
  28. package/src/oauth/store.ts +27 -27
  29. package/src/priceSelector.test.ts +68 -68
  30. package/src/priceSelector.ts +70 -70
  31. package/src/product-projection-search.ts +296 -296
  32. package/src/projectAPI.test.ts +3 -3
  33. package/src/projectAPI.ts +46 -46
  34. package/src/repositories/abstract.ts +190 -190
  35. package/src/repositories/associate-role.ts +10 -7
  36. package/src/repositories/attribute-group.ts +63 -8
  37. package/src/repositories/business-unit.ts +10 -7
  38. package/src/repositories/cart-discount.ts +134 -134
  39. package/src/repositories/cart.ts +517 -514
  40. package/src/repositories/category.ts +170 -167
  41. package/src/repositories/channel.ts +114 -111
  42. package/src/repositories/custom-object.ts +66 -63
  43. package/src/repositories/customer-group.ts +72 -69
  44. package/src/repositories/customer.ts +90 -90
  45. package/src/repositories/discount-code.ts +171 -168
  46. package/src/repositories/errors.ts +15 -15
  47. package/src/repositories/extension.ts +79 -76
  48. package/src/repositories/helpers.ts +180 -180
  49. package/src/repositories/index.ts +39 -39
  50. package/src/repositories/inventory-entry.ts +98 -95
  51. package/src/repositories/my-order.ts +11 -11
  52. package/src/repositories/order-edit.ts +29 -29
  53. package/src/repositories/order.test.ts +191 -191
  54. package/src/repositories/order.ts +393 -393
  55. package/src/repositories/payment.ts +155 -155
  56. package/src/repositories/product-discount.ts +149 -149
  57. package/src/repositories/product-projection.ts +135 -50
  58. package/src/repositories/product-selection.ts +31 -31
  59. package/src/repositories/product-type.ts +156 -156
  60. package/src/repositories/product.ts +600 -597
  61. package/src/repositories/project.ts +136 -135
  62. package/src/repositories/quote-request.ts +19 -19
  63. package/src/repositories/quote.ts +19 -19
  64. package/src/repositories/review.ts +24 -24
  65. package/src/repositories/shipping-method.ts +217 -217
  66. package/src/repositories/shopping-list.ts +49 -49
  67. package/src/repositories/staged-quote.ts +20 -20
  68. package/src/repositories/standalone-price.ts +72 -61
  69. package/src/repositories/state.ts +84 -84
  70. package/src/repositories/store.ts +114 -114
  71. package/src/repositories/subscription.ts +40 -40
  72. package/src/repositories/tax-category.ts +98 -98
  73. package/src/repositories/type.ts +157 -157
  74. package/src/repositories/zone.ts +71 -71
  75. package/src/server.ts +2 -2
  76. package/src/services/abstract.ts +173 -173
  77. package/src/services/attribute-group.ts +16 -0
  78. package/src/services/cart-discount.ts +8 -8
  79. package/src/services/cart.test.ts +409 -409
  80. package/src/services/cart.ts +50 -50
  81. package/src/services/category.test.ts +25 -25
  82. package/src/services/category.ts +8 -8
  83. package/src/services/channel.ts +8 -8
  84. package/src/services/custom-object.test.ts +184 -184
  85. package/src/services/custom-object.ts +48 -48
  86. package/src/services/customer-group.ts +8 -8
  87. package/src/services/customer.test.ts +151 -151
  88. package/src/services/customer.ts +27 -27
  89. package/src/services/discount-code.ts +8 -8
  90. package/src/services/extension.ts +8 -8
  91. package/src/services/index.ts +52 -44
  92. package/src/services/inventory-entry.test.ts +162 -162
  93. package/src/services/inventory-entry.ts +8 -8
  94. package/src/services/my-cart.test.ts +78 -78
  95. package/src/services/my-cart.ts +28 -28
  96. package/src/services/my-customer.test.ts +44 -44
  97. package/src/services/my-customer.ts +53 -53
  98. package/src/services/my-order.ts +20 -20
  99. package/src/services/my-payment.test.ts +65 -65
  100. package/src/services/my-payment.ts +8 -8
  101. package/src/services/order.test.ts +527 -527
  102. package/src/services/order.ts +31 -31
  103. package/src/services/payment.test.ts +65 -65
  104. package/src/services/payment.ts +8 -8
  105. package/src/services/product-discount.ts +8 -8
  106. package/src/services/product-projection.test.ts +502 -428
  107. package/src/services/product-projection.ts +32 -18
  108. package/src/services/product-type.test.ts +56 -56
  109. package/src/services/product-type.ts +8 -8
  110. package/src/services/product.test.ts +510 -510
  111. package/src/services/product.ts +8 -8
  112. package/src/services/project.ts +34 -34
  113. package/src/services/shipping-method.test.ts +81 -81
  114. package/src/services/shipping-method.ts +12 -12
  115. package/src/services/shopping-list.ts +8 -8
  116. package/src/services/standalone-price.test.ts +256 -256
  117. package/src/services/standalone-price.ts +8 -8
  118. package/src/services/state.test.ts +42 -42
  119. package/src/services/state.ts +8 -8
  120. package/src/services/store.test.ts +57 -57
  121. package/src/services/store.ts +8 -8
  122. package/src/services/subscription.ts +8 -8
  123. package/src/services/tax-category.test.ts +61 -61
  124. package/src/services/tax-category.ts +8 -8
  125. package/src/services/type.ts +8 -8
  126. package/src/services/zone.ts +8 -8
  127. package/src/storage/abstract.ts +58 -58
  128. package/src/storage/in-memory.ts +419 -419
  129. package/src/types.ts +82 -82
package/dist/index.d.cts CHANGED
@@ -1,6 +1,6 @@
1
1
  import express from 'express';
2
2
  import * as ctp 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, 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, 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';
3
+ import { Project, ResourceIdentifier, QueryParam, AssociateRole, AttributeGroupDraft, AttributeGroup, AttributeGroupSetAttributesAction, AttributeGroupChangeNameAction, AttributeGroupSetDescriptionAction, AttributeGroupSetKeyAction, 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, 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, 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
6
  type GetParams$1 = {
@@ -37,7 +37,13 @@ declare class AssociateRoleRepository extends AbstractResourceRepository<'associ
37
37
 
38
38
  declare class AttributeGroupRepository extends AbstractResourceRepository<'attribute-group'> {
39
39
  getTypeId(): "attribute-group";
40
- create(context: RepositoryContext, draft: any): AttributeGroup;
40
+ create(context: RepositoryContext, draft: AttributeGroupDraft): AttributeGroup;
41
+ actions: {
42
+ setAttributes: (_context: RepositoryContext, resource: Writable<AttributeGroup>, { attributes }: AttributeGroupSetAttributesAction) => void;
43
+ changeName: (_context: RepositoryContext, resource: Writable<AttributeGroup>, { name }: AttributeGroupChangeNameAction) => void;
44
+ setDescription: (_context: RepositoryContext, resource: Writable<AttributeGroup>, { description }: AttributeGroupSetDescriptionAction) => void;
45
+ setKey: (_context: RepositoryContext, resource: Writable<AttributeGroup>, { key }: AttributeGroupSetKeyAction) => void;
46
+ };
41
47
  }
42
48
 
43
49
  declare class BusinessUnitRepository extends AbstractResourceRepository<'business-unit'> {
@@ -262,17 +268,34 @@ declare class ProductProjectionSearch {
262
268
  rangeFacet(source: string, ranges: RangeExpression[] | undefined, products: ProductProjection[]): RangeFacetResult;
263
269
  }
264
270
 
271
+ type ProductProjectionQueryParams = {
272
+ staged?: boolean;
273
+ priceCurrency?: string;
274
+ priceCountry?: string;
275
+ priceCustomerGroup?: string;
276
+ priceChannel?: string;
277
+ localeProjection?: string | string[];
278
+ storeProjection?: string;
279
+ expand?: string | string[];
280
+ sort?: string | string[];
281
+ limit?: number;
282
+ offset?: number;
283
+ withTotal?: boolean;
284
+ where?: string | string[];
285
+ [key: string]: QueryParam;
286
+ };
265
287
  declare class ProductProjectionRepository extends AbstractResourceRepository<'product-projection'> {
266
288
  protected _searchService: ProductProjectionSearch;
267
289
  constructor(storage: AbstractStorage);
268
290
  getTypeId(): "product-projection";
269
291
  create(context: RepositoryContext, draft: ProductDraft): ProductProjection;
270
- query(context: RepositoryContext, params?: QueryParams): {
271
- results: ProductProjection[];
272
- limit: number;
273
- offset: number;
292
+ get(context: RepositoryContext, id: string, params?: GetParams): ProductProjection | null;
293
+ query(context: RepositoryContext, params?: ProductProjectionQueryParams): {
274
294
  count: number;
275
- total?: number | undefined;
295
+ total: number;
296
+ offset: number;
297
+ limit: number;
298
+ results: ProductProjection[];
276
299
  };
277
300
  search(context: RepositoryContext, query: ParsedQs): ctp.ProductProjectionPagedSearchResponse;
278
301
  actions: {};
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import express from 'express';
2
2
  import * as ctp 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, 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, 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';
3
+ import { Project, ResourceIdentifier, QueryParam, AssociateRole, AttributeGroupDraft, AttributeGroup, AttributeGroupSetAttributesAction, AttributeGroupChangeNameAction, AttributeGroupSetDescriptionAction, AttributeGroupSetKeyAction, 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, 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, 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
6
  type GetParams$1 = {
@@ -37,7 +37,13 @@ declare class AssociateRoleRepository extends AbstractResourceRepository<'associ
37
37
 
38
38
  declare class AttributeGroupRepository extends AbstractResourceRepository<'attribute-group'> {
39
39
  getTypeId(): "attribute-group";
40
- create(context: RepositoryContext, draft: any): AttributeGroup;
40
+ create(context: RepositoryContext, draft: AttributeGroupDraft): AttributeGroup;
41
+ actions: {
42
+ setAttributes: (_context: RepositoryContext, resource: Writable<AttributeGroup>, { attributes }: AttributeGroupSetAttributesAction) => void;
43
+ changeName: (_context: RepositoryContext, resource: Writable<AttributeGroup>, { name }: AttributeGroupChangeNameAction) => void;
44
+ setDescription: (_context: RepositoryContext, resource: Writable<AttributeGroup>, { description }: AttributeGroupSetDescriptionAction) => void;
45
+ setKey: (_context: RepositoryContext, resource: Writable<AttributeGroup>, { key }: AttributeGroupSetKeyAction) => void;
46
+ };
41
47
  }
42
48
 
43
49
  declare class BusinessUnitRepository extends AbstractResourceRepository<'business-unit'> {
@@ -262,17 +268,34 @@ declare class ProductProjectionSearch {
262
268
  rangeFacet(source: string, ranges: RangeExpression[] | undefined, products: ProductProjection[]): RangeFacetResult;
263
269
  }
264
270
 
271
+ type ProductProjectionQueryParams = {
272
+ staged?: boolean;
273
+ priceCurrency?: string;
274
+ priceCountry?: string;
275
+ priceCustomerGroup?: string;
276
+ priceChannel?: string;
277
+ localeProjection?: string | string[];
278
+ storeProjection?: string;
279
+ expand?: string | string[];
280
+ sort?: string | string[];
281
+ limit?: number;
282
+ offset?: number;
283
+ withTotal?: boolean;
284
+ where?: string | string[];
285
+ [key: string]: QueryParam;
286
+ };
265
287
  declare class ProductProjectionRepository extends AbstractResourceRepository<'product-projection'> {
266
288
  protected _searchService: ProductProjectionSearch;
267
289
  constructor(storage: AbstractStorage);
268
290
  getTypeId(): "product-projection";
269
291
  create(context: RepositoryContext, draft: ProductDraft): ProductProjection;
270
- query(context: RepositoryContext, params?: QueryParams): {
271
- results: ProductProjection[];
272
- limit: number;
273
- offset: number;
292
+ get(context: RepositoryContext, id: string, params?: GetParams): ProductProjection | null;
293
+ query(context: RepositoryContext, params?: ProductProjectionQueryParams): {
274
294
  count: number;
275
- total?: number | undefined;
295
+ total: number;
296
+ offset: number;
297
+ limit: number;
298
+ results: ProductProjection[];
276
299
  };
277
300
  search(context: RepositoryContext, query: ParsedQs): ctp.ProductProjectionPagedSearchResponse;
278
301
  actions: {};
package/dist/index.js CHANGED
@@ -194,10 +194,13 @@ var TokenTypes = class {
194
194
  }
195
195
  peek(source, position) {
196
196
  const s = source.substr(position);
197
- return first(this.tokenTypes.filter((tt) => tt.enabled), (tt) => {
198
- tt.regex.lastIndex = 0;
199
- return tt.regex.exec(s);
200
- });
197
+ return first(
198
+ this.tokenTypes.filter((tt) => tt.enabled),
199
+ (tt) => {
200
+ tt.regex.lastIndex = 0;
201
+ return tt.regex.exec(s);
202
+ }
203
+ );
201
204
  }
202
205
  token(type, pattern, skip = false) {
203
206
  this.tokenTypes.push({
@@ -642,7 +645,7 @@ var validateSymbol = (val) => {
642
645
  };
643
646
  var resolveSymbol = (val, vars) => {
644
647
  if (val.type === "var") {
645
- if (!(val.value in vars)) {
648
+ if (!(val.value in (vars ?? {}))) {
646
649
  throw new PredicateError(`Missing parameter value for ${val.value}`);
647
650
  }
648
651
  return vars[val.value];
@@ -739,7 +742,7 @@ var generateMatchFunc = (predicate) => {
739
742
  return (obj, vars) => {
740
743
  const value = resolveValue(obj, left);
741
744
  if (value) {
742
- return expr(value);
745
+ return expr(value, vars);
743
746
  }
744
747
  return false;
745
748
  };
@@ -1716,8 +1719,30 @@ var AttributeGroupRepository = class extends AbstractResourceRepository {
1716
1719
  return "attribute-group";
1717
1720
  }
1718
1721
  create(context, draft) {
1719
- throw new Error("Method not implemented.");
1722
+ const resource = {
1723
+ ...getBaseResourceProperties(),
1724
+ name: draft.name,
1725
+ description: draft.description,
1726
+ key: draft.key,
1727
+ attributes: draft.attributes
1728
+ };
1729
+ this.saveNew(context, resource);
1730
+ return resource;
1720
1731
  }
1732
+ actions = {
1733
+ setAttributes: (_context, resource, { attributes }) => {
1734
+ resource.attributes = attributes;
1735
+ },
1736
+ changeName: (_context, resource, { name }) => {
1737
+ resource.name = name;
1738
+ },
1739
+ setDescription: (_context, resource, { description }) => {
1740
+ resource.description = description;
1741
+ },
1742
+ setKey: (_context, resource, { key }) => {
1743
+ resource.key = key;
1744
+ }
1745
+ };
1721
1746
  };
1722
1747
 
1723
1748
  // src/repositories/business-unit.ts
@@ -4207,18 +4232,62 @@ var ProductProjectionRepository = class extends AbstractResourceRepository {
4207
4232
  create(context, draft) {
4208
4233
  throw new Error("No valid action");
4209
4234
  }
4235
+ get(context, id, params = {}) {
4236
+ const resource = this._storage.get(
4237
+ context.projectKey,
4238
+ "product",
4239
+ id,
4240
+ params
4241
+ );
4242
+ if (resource) {
4243
+ return this._searchService.transform(resource, false);
4244
+ }
4245
+ return null;
4246
+ }
4210
4247
  query(context, params = {}) {
4211
- const response = this._storage.query(context.projectKey, "product", {
4212
- expand: params.expand,
4213
- where: params.where,
4214
- offset: params.offset,
4215
- limit: params.limit
4248
+ let resources = this._storage.all(context.projectKey, "product").map((r) => this._searchService.transform(r, params.staged ?? false)).filter((p) => {
4249
+ if (!params.staged) {
4250
+ return p.published;
4251
+ }
4252
+ return true;
4216
4253
  });
4254
+ if (params.where) {
4255
+ const variableMap = {};
4256
+ for (const [k, v] of Object.entries(params)) {
4257
+ if (k.startsWith("var.")) {
4258
+ variableMap[k.substring(4)] = v;
4259
+ }
4260
+ }
4261
+ try {
4262
+ const filterFunc = parseQueryExpression(params.where);
4263
+ resources = resources.filter(
4264
+ (resource) => filterFunc(resource, variableMap)
4265
+ );
4266
+ } catch (err) {
4267
+ throw new CommercetoolsError(
4268
+ {
4269
+ code: "InvalidInput",
4270
+ message: err.message
4271
+ },
4272
+ 400
4273
+ );
4274
+ }
4275
+ }
4276
+ if (params.expand !== void 0) {
4277
+ resources = resources.map(
4278
+ (resource) => this._storage.expand(context.projectKey, resource, params.expand)
4279
+ );
4280
+ }
4281
+ const totalResults = resources.length;
4282
+ const offset = params.offset || 0;
4283
+ const limit = params.limit || 20;
4284
+ const results = resources.slice(offset, offset + limit);
4217
4285
  return {
4218
- ...response,
4219
- results: response.results.map(
4220
- (r) => this._searchService.transform(r, false)
4221
- )
4286
+ count: totalResults,
4287
+ total: results.length,
4288
+ offset,
4289
+ limit,
4290
+ results
4222
4291
  };
4223
4292
  }
4224
4293
  search(context, query) {
@@ -5656,6 +5725,18 @@ var ProductProjectionService = class extends AbstractService {
5656
5725
  extraRoutes(router) {
5657
5726
  router.get("/search", this.search.bind(this));
5658
5727
  }
5728
+ get(request, response) {
5729
+ const limit = this._parseParam(request.query.limit);
5730
+ const offset = this._parseParam(request.query.offset);
5731
+ const result = this.repository.query(getRepositoryContext(request), {
5732
+ ...request.query,
5733
+ expand: this._parseParam(request.query.expand),
5734
+ where: this._parseParam(request.query.where),
5735
+ limit: limit !== void 0 ? Number(limit) : void 0,
5736
+ offset: offset !== void 0 ? Number(offset) : void 0
5737
+ });
5738
+ return response.status(200).send(result);
5739
+ }
5659
5740
  search(request, response) {
5660
5741
  const resource = this.repository.search(
5661
5742
  getRepositoryContext(request),
@@ -5789,6 +5870,18 @@ var ZoneService = class extends AbstractService {
5789
5870
  }
5790
5871
  };
5791
5872
 
5873
+ // src/services/attribute-group.ts
5874
+ var AttributeGroupService = class extends AbstractService {
5875
+ repository;
5876
+ constructor(parent, repository) {
5877
+ super(parent);
5878
+ this.repository = repository;
5879
+ }
5880
+ getBasePath() {
5881
+ return "attribute-groups";
5882
+ }
5883
+ };
5884
+
5792
5885
  // src/services/index.ts
5793
5886
  var createServices = (router, repos) => ({
5794
5887
  category: new CategoryServices(router, repos["category"]),
@@ -5809,7 +5902,10 @@ var createServices = (router, repos) => ({
5809
5902
  ),
5810
5903
  order: new OrderService(router, repos["order"]),
5811
5904
  payment: new PaymentService(router, repos["payment"]),
5812
- "standalone-price": new StandAlonePriceService(router, repos["standalone-price"]),
5905
+ "standalone-price": new StandAlonePriceService(
5906
+ router,
5907
+ repos["standalone-price"]
5908
+ ),
5813
5909
  "my-cart": new MyCartService(router, repos["my-cart"]),
5814
5910
  "my-order": new MyOrderService(router, repos["my-order"]),
5815
5911
  "my-customer": new MyCustomerService(router, repos["my-customer"]),
@@ -5833,6 +5929,10 @@ var createServices = (router, repos) => ({
5833
5929
  store: new StoreService(router, repos["store"]),
5834
5930
  subscription: new SubscriptionService(router, repos["subscription"]),
5835
5931
  "tax-category": new TaxCategoryService(router, repos["tax-category"]),
5932
+ "attribute-group": new AttributeGroupService(
5933
+ router,
5934
+ repos["attribute-group"]
5935
+ ),
5836
5936
  type: new TypeService(router, repos["type"]),
5837
5937
  zone: new ZoneService(router, repos["zone"])
5838
5938
  });