@labdigital/commercetools-mock 1.1.3 → 1.3.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.
Files changed (85) hide show
  1. package/dist/index.d.mts +602 -0
  2. package/dist/index.d.ts +43 -26
  3. package/dist/index.global.js +6322 -6084
  4. package/dist/index.global.js.map +1 -1
  5. package/dist/index.js +347 -163
  6. package/dist/index.js.map +1 -1
  7. package/dist/index.mjs +343 -163
  8. package/dist/index.mjs.map +1 -1
  9. package/package.json +35 -41
  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/projectionSearchFilter.test.ts +2 -1
  14. package/src/lib/projectionSearchFilter.ts +2 -2
  15. package/src/oauth/server.ts +3 -4
  16. package/src/priceSelector.test.ts +2 -1
  17. package/src/priceSelector.ts +2 -2
  18. package/src/product-projection-search.ts +8 -8
  19. package/src/projectAPI.test.ts +1 -0
  20. package/src/repositories/abstract.ts +1 -1
  21. package/src/repositories/associate-role.ts +11 -0
  22. package/src/repositories/attribute-group.ts +11 -0
  23. package/src/repositories/business-unit.ts +11 -0
  24. package/src/repositories/cart-discount.ts +11 -4
  25. package/src/repositories/cart.ts +91 -9
  26. package/src/repositories/category.ts +3 -3
  27. package/src/repositories/channel.ts +3 -3
  28. package/src/repositories/custom-object.ts +3 -3
  29. package/src/repositories/customer-group.ts +3 -3
  30. package/src/repositories/customer.ts +4 -3
  31. package/src/repositories/discount-code.ts +3 -3
  32. package/src/repositories/errors.ts +1 -1
  33. package/src/repositories/extension.ts +3 -3
  34. package/src/repositories/helpers.ts +49 -6
  35. package/src/repositories/index.ts +6 -0
  36. package/src/repositories/inventory-entry.ts +4 -4
  37. package/src/repositories/my-order.ts +2 -2
  38. package/src/repositories/order-edit.ts +2 -2
  39. package/src/repositories/order.test.ts +10 -39
  40. package/src/repositories/order.ts +31 -16
  41. package/src/repositories/payment.ts +8 -7
  42. package/src/repositories/product-discount.ts +2 -2
  43. package/src/repositories/product-projection.ts +5 -5
  44. package/src/repositories/product-selection.ts +3 -2
  45. package/src/repositories/product-type.ts +2 -2
  46. package/src/repositories/product.ts +4 -9
  47. package/src/repositories/project.ts +2 -2
  48. package/src/repositories/quote-request.ts +2 -2
  49. package/src/repositories/quote.ts +2 -2
  50. package/src/repositories/review.ts +2 -2
  51. package/src/repositories/shipping-method.ts +10 -2
  52. package/src/repositories/shopping-list.ts +19 -13
  53. package/src/repositories/staged-quote.ts +2 -2
  54. package/src/repositories/standalone-price.ts +3 -3
  55. package/src/repositories/state.ts +2 -2
  56. package/src/repositories/store.ts +3 -2
  57. package/src/repositories/subscription.ts +1 -1
  58. package/src/repositories/tax-category.ts +2 -2
  59. package/src/repositories/type.ts +2 -2
  60. package/src/repositories/zone.ts +2 -2
  61. package/src/services/abstract.ts +2 -2
  62. package/src/services/cart.test.ts +2 -1
  63. package/src/services/cart.ts +4 -4
  64. package/src/services/category.test.ts +2 -1
  65. package/src/services/custom-object.test.ts +2 -1
  66. package/src/services/custom-object.ts +3 -3
  67. package/src/services/customer.test.ts +1 -0
  68. package/src/services/inventory-entry.test.ts +2 -1
  69. package/src/services/my-cart.test.ts +7 -3
  70. package/src/services/my-customer.test.ts +4 -2
  71. package/src/services/my-payment.test.ts +2 -1
  72. package/src/services/order.test.ts +2 -1
  73. package/src/services/payment.test.ts +2 -1
  74. package/src/services/product-projection.test.ts +3 -2
  75. package/src/services/product-type.test.ts +2 -1
  76. package/src/services/product.test.ts +2 -1
  77. package/src/services/project.ts +1 -1
  78. package/src/services/shipping-method.test.ts +2 -1
  79. package/src/services/standalone-price.test.ts +255 -244
  80. package/src/services/state.test.ts +2 -1
  81. package/src/services/store.test.ts +6 -1
  82. package/src/services/tax-category.test.ts +2 -1
  83. package/src/storage/abstract.ts +1 -1
  84. package/src/storage/in-memory.ts +7 -1
  85. package/src/types.ts +7 -1
@@ -0,0 +1,602 @@
1
+ import express from 'express';
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, 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
+ import { ParsedQs } from 'qs';
5
+
6
+ type GetParams$1 = {
7
+ expand?: string[];
8
+ };
9
+ type QueryParams$1 = {
10
+ expand?: string | string[];
11
+ sort?: string | string[];
12
+ limit?: number;
13
+ offset?: number;
14
+ withTotal?: boolean;
15
+ where?: string | string[];
16
+ [key: string]: QueryParam;
17
+ };
18
+ declare abstract class AbstractStorage {
19
+ abstract clear(): void;
20
+ abstract all<RT extends ResourceType>(projectKey: string, typeId: RT): Array<ResourceMap[RT]>;
21
+ abstract add<RT extends ResourceType>(projectKey: string, typeId: RT, obj: ResourceMap[RT]): void;
22
+ abstract get<RT extends ResourceType>(projectKey: string, typeId: RT, id: string, params?: GetParams$1): ResourceMap[RT] | null;
23
+ abstract getByKey<RT extends ResourceType>(projectKey: string, typeId: RT, key: string, params: GetParams$1): ResourceMap[RT] | null;
24
+ abstract addProject(projectKey: string): Project;
25
+ abstract getProject(projectKey: string): Project;
26
+ abstract saveProject(project: Project): Project;
27
+ abstract delete<RT extends ResourceType>(projectKey: string, typeId: RT, id: string, params: GetParams$1): ResourceMap[RT] | null;
28
+ abstract query<RT extends ResourceType>(projectKey: string, typeId: RT, params: QueryParams$1): PagedQueryResponseMap[RT];
29
+ abstract getByResourceIdentifier<RT extends ResourceType>(projectKey: string, identifier: ResourceIdentifier): ResourceMap[RT] | null;
30
+ abstract expand<T>(projectKey: string, obj: T, clause: undefined | string | string[]): T;
31
+ }
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
+
48
+ declare class CartRepository extends AbstractResourceRepository<'cart'> {
49
+ getTypeId(): "cart";
50
+ create(context: RepositoryContext, draft: CartDraft): Cart;
51
+ getActiveCart(projectKey: string): Cart | undefined;
52
+ actions: {
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;
55
+ removeLineItem: (context: RepositoryContext, resource: Writable<Cart>, { lineItemId, quantity }: CartRemoveLineItemAction) => void;
56
+ setBillingAddress: (context: RepositoryContext, resource: Writable<Cart>, { address }: CartSetBillingAddressAction) => void;
57
+ setShippingMethod: (context: RepositoryContext, resource: Writable<Cart>, { shippingMethod }: CartSetShippingMethodAction) => void;
58
+ setCountry: (context: RepositoryContext, resource: Writable<Cart>, { country }: CartSetCountryAction) => void;
59
+ setCustomerEmail: (context: RepositoryContext, resource: Writable<Cart>, { email }: CartSetCustomerEmailAction) => void;
60
+ setCustomField: (context: RepositoryContext, resource: Cart, { name, value }: CartSetCustomFieldAction) => void;
61
+ setCustomType: (context: RepositoryContext, resource: Writable<Cart>, { type, fields }: CartSetCustomTypeAction) => void;
62
+ setLocale: (context: RepositoryContext, resource: Writable<Cart>, { locale }: CartSetLocaleAction) => void;
63
+ setShippingAddress: (context: RepositoryContext, resource: Writable<Cart>, { address }: CartSetShippingAddressAction) => void;
64
+ };
65
+ draftLineItemtoLineItem: (projectKey: string, draftLineItem: LineItemDraft, currency: string, country: string | undefined) => LineItem;
66
+ }
67
+
68
+ declare class CartDiscountRepository extends AbstractResourceRepository<'cart-discount'> {
69
+ getTypeId(): "cart-discount";
70
+ create(context: RepositoryContext, draft: CartDiscountDraft): CartDiscount;
71
+ private transformValueDraft;
72
+ actions: Partial<Record<CartDiscountUpdateAction['action'], (context: RepositoryContext, resource: Writable<CartDiscount>, action: any) => void>>;
73
+ }
74
+
75
+ declare class CategoryRepository extends AbstractResourceRepository<'category'> {
76
+ getTypeId(): "category";
77
+ create(context: RepositoryContext, draft: CategoryDraft): Category;
78
+ actions: {
79
+ changeAssetName: (context: RepositoryContext, resource: Writable<Category>, { assetId, assetKey, name }: CategoryChangeAssetNameAction) => void;
80
+ changeSlug: (context: RepositoryContext, resource: Writable<Category>, { slug }: CategoryChangeSlugAction) => void;
81
+ setKey: (context: RepositoryContext, resource: Writable<Category>, { key }: CategorySetKeyAction) => void;
82
+ setAssetDescription: (context: RepositoryContext, resource: Writable<Category>, { assetId, assetKey, description }: CategorySetAssetDescriptionAction) => void;
83
+ setAssetSources: (context: RepositoryContext, resource: Writable<Category>, { assetId, assetKey, sources }: CategorySetAssetSourcesAction) => void;
84
+ setDescription: (context: RepositoryContext, resource: Writable<Category>, { description }: CategorySetDescriptionAction) => void;
85
+ setMetaDescription: (context: RepositoryContext, resource: Writable<Category>, { metaDescription }: CategorySetMetaDescriptionAction) => void;
86
+ setMetaKeywords: (context: RepositoryContext, resource: Writable<Category>, { metaKeywords }: CategorySetMetaKeywordsAction) => void;
87
+ setMetaTitle: (context: RepositoryContext, resource: Writable<Category>, { metaTitle }: CategorySetMetaTitleAction) => void;
88
+ setCustomType: (context: RepositoryContext, resource: Writable<Category>, { type, fields }: CategorySetCustomTypeAction) => void;
89
+ setCustomField: (context: RepositoryContext, resource: Writable<Category>, { name, value }: CategorySetCustomFieldAction) => void;
90
+ };
91
+ }
92
+
93
+ declare class ChannelRepository extends AbstractResourceRepository<'channel'> {
94
+ getTypeId(): "channel";
95
+ create(context: RepositoryContext, draft: ChannelDraft): Channel;
96
+ actions: Partial<Record<ChannelUpdateAction['action'], (context: RepositoryContext, resource: Writable<Channel>, action: any) => void>>;
97
+ }
98
+
99
+ declare class CustomObjectRepository extends AbstractResourceRepository<'key-value-document'> {
100
+ getTypeId(): "key-value-document";
101
+ create(context: RepositoryContext, draft: Writable<CustomObjectDraft>): CustomObject;
102
+ getWithContainerAndKey(context: RepositoryContext, container: string, key: string): CustomObject | undefined;
103
+ }
104
+
105
+ declare class CustomerRepository extends AbstractResourceRepository<'customer'> {
106
+ getTypeId(): "customer";
107
+ create(context: RepositoryContext, draft: CustomerDraft): Customer;
108
+ getMe(context: RepositoryContext): Customer | undefined;
109
+ actions: {
110
+ changeEmail: (_context: RepositoryContext, resource: Writable<Customer>, { email }: CustomerChangeEmailAction) => void;
111
+ setAuthenticationMode: (_context: RepositoryContext, resource: Writable<Customer>, { authMode, password }: CustomerSetAuthenticationModeAction) => void;
112
+ };
113
+ }
114
+
115
+ declare class CustomerGroupRepository extends AbstractResourceRepository<'customer-group'> {
116
+ getTypeId(): "customer-group";
117
+ create(context: RepositoryContext, draft: CustomerGroupDraft): CustomerGroup;
118
+ actions: {
119
+ setKey: (context: RepositoryContext, resource: Writable<CustomerGroup>, { key }: CustomerGroupSetKeyAction) => void;
120
+ changeName: (context: RepositoryContext, resource: Writable<CustomerGroup>, { name }: CustomerGroupChangeNameAction) => void;
121
+ setCustomType: (context: RepositoryContext, resource: Writable<CustomerGroup>, { type, fields }: CustomerGroupSetCustomTypeAction) => void;
122
+ setCustomField: (context: RepositoryContext, resource: Writable<CustomerGroup>, { name, value }: CustomerGroupSetCustomFieldAction) => void;
123
+ };
124
+ }
125
+
126
+ declare class DiscountCodeRepository extends AbstractResourceRepository<'discount-code'> {
127
+ getTypeId(): "discount-code";
128
+ create(context: RepositoryContext, draft: DiscountCodeDraft): DiscountCode;
129
+ actions: Partial<Record<DiscountCodeUpdateAction['action'], (context: RepositoryContext, resource: Writable<DiscountCode>, action: any) => void>>;
130
+ }
131
+
132
+ declare class ExtensionRepository extends AbstractResourceRepository<'extension'> {
133
+ getTypeId(): "extension";
134
+ postProcessResource(resource: Extension): Extension;
135
+ create(context: RepositoryContext, draft: ExtensionDraft): Extension;
136
+ actions: Record<ExtensionUpdateAction['action'], (context: RepositoryContext, resource: Writable<Extension>, action: any) => void>;
137
+ }
138
+
139
+ declare class InventoryEntryRepository extends AbstractResourceRepository<'inventory-entry'> {
140
+ getTypeId(): "inventory-entry";
141
+ create(context: RepositoryContext, draft: InventoryEntryDraft): InventoryEntry;
142
+ actions: {
143
+ changeQuantity: (context: RepositoryContext, resource: Writable<InventoryEntry>, { quantity }: InventoryEntryChangeQuantityAction) => void;
144
+ setExpectedDelivery: (context: RepositoryContext, resource: Writable<InventoryEntry>, { expectedDelivery }: InventoryEntrySetExpectedDeliveryAction) => void;
145
+ setCustomField: (context: RepositoryContext, resource: InventoryEntry, { name, value }: InventoryEntrySetCustomFieldAction) => void;
146
+ setCustomType: (context: RepositoryContext, resource: Writable<InventoryEntry>, { type, fields }: InventoryEntrySetCustomTypeAction) => void;
147
+ setRestockableInDays: (context: RepositoryContext, resource: Writable<InventoryEntry>, { restockableInDays }: InventoryEntrySetRestockableInDaysAction) => void;
148
+ };
149
+ }
150
+
151
+ declare class OrderRepository extends AbstractResourceRepository<'order'> {
152
+ getTypeId(): "order";
153
+ create(context: RepositoryContext, draft: OrderFromCartDraft): Order;
154
+ createFromCart(context: RepositoryContext, cartReference: CartReference, orderNumber?: string): Order;
155
+ import(context: RepositoryContext, draft: OrderImportDraft): Order;
156
+ private lineItemFromImportDraft;
157
+ private customLineItemFromImportDraft;
158
+ getWithOrderNumber(context: RepositoryContext, orderNumber: string, params?: QueryParams): Order | undefined;
159
+ actions: {
160
+ addPayment: (context: RepositoryContext, resource: Writable<Order>, { payment }: OrderAddPaymentAction) => void;
161
+ changeOrderState: (context: RepositoryContext, resource: Writable<Order>, { orderState }: OrderChangeOrderStateAction) => void;
162
+ changePaymentState: (context: RepositoryContext, resource: Writable<Order>, { paymentState }: OrderChangePaymentStateAction) => void;
163
+ transitionState: (context: RepositoryContext, resource: Writable<Order>, { state }: OrderTransitionStateAction) => void;
164
+ setBillingAddress: (context: RepositoryContext, resource: Writable<Order>, { address }: OrderSetBillingAddressAction) => void;
165
+ setCustomerEmail: (context: RepositoryContext, resource: Writable<Order>, { email }: OrderSetCustomerEmailAction) => void;
166
+ setCustomField: (context: RepositoryContext, resource: Order, { name, value }: OrderSetCustomFieldAction) => void;
167
+ setCustomType: (context: RepositoryContext, resource: Writable<Order>, { type, fields }: OrderSetCustomTypeAction) => void;
168
+ setLocale: (context: RepositoryContext, resource: Writable<Order>, { locale }: OrderSetLocaleAction) => void;
169
+ setOrderNumber: (context: RepositoryContext, resource: Writable<Order>, { orderNumber }: OrderSetOrderNumberAction) => void;
170
+ setShippingAddress: (context: RepositoryContext, resource: Writable<Order>, { address }: OrderSetShippingAddressAction) => void;
171
+ setStore: (context: RepositoryContext, resource: Writable<Order>, { store }: OrderSetStoreAction) => void;
172
+ };
173
+ }
174
+
175
+ declare class MyOrderRepository extends OrderRepository {
176
+ create(context: RepositoryContext, draft: MyOrderFromCartDraft): Order;
177
+ }
178
+
179
+ declare class OrderEditRepository extends AbstractResourceRepository<'order-edit'> {
180
+ getTypeId(): "order-edit";
181
+ create(context: RepositoryContext, draft: OrderEditDraft): OrderEdit;
182
+ actions: Partial<Record<OrderEditUpdateAction['action'], (context: RepositoryContext, resource: Writable<OrderEdit>, action: any) => void>>;
183
+ }
184
+
185
+ declare class PaymentRepository extends AbstractResourceRepository<'payment'> {
186
+ getTypeId(): "payment";
187
+ create(context: RepositoryContext, draft: PaymentDraft): Payment;
188
+ transactionFromTransactionDraft: (draft: TransactionDraft, context: RepositoryContext) => Transaction;
189
+ actions: {
190
+ setCustomField: (context: RepositoryContext, resource: Payment, { name, value }: PaymentSetCustomFieldAction) => void;
191
+ setCustomType: (context: RepositoryContext, resource: Writable<Payment>, { type, fields }: PaymentSetCustomTypeAction) => void;
192
+ addTransaction: (context: RepositoryContext, resource: Writable<Payment>, { transaction }: PaymentAddTransactionAction) => void;
193
+ changeTransactionState: (_context: RepositoryContext, resource: Writable<Payment>, { transactionId, state }: PaymentChangeTransactionStateAction) => void;
194
+ transitionState: (context: RepositoryContext, resource: Writable<Payment>, { state }: PaymentTransitionStateAction) => void;
195
+ };
196
+ }
197
+
198
+ declare class ProductRepository extends AbstractResourceRepository<'product'> {
199
+ getTypeId(): "product";
200
+ create(context: RepositoryContext, draft: ProductDraft): Product;
201
+ actions: Partial<Record<ProductUpdateAction['action'], (context: RepositoryContext, resource: Writable<Product>, action: any) => void>>;
202
+ }
203
+
204
+ declare class ProductDiscountRepository extends AbstractResourceRepository<'product-discount'> {
205
+ getTypeId(): "product-discount";
206
+ create(context: RepositoryContext, draft: ProductDiscountDraft): ProductDiscount;
207
+ private transformValueDraft;
208
+ actions: Partial<Record<ProductDiscountUpdateAction['action'], (context: RepositoryContext, resource: Writable<ProductDiscount>, action: any) => void>>;
209
+ }
210
+
211
+ /**
212
+ * This module implements the commercetools product projection filter expression.
213
+ */
214
+
215
+ type RangeExpression = {
216
+ type: 'RangeExpression';
217
+ start?: number;
218
+ stop?: number;
219
+ match: (obj: any) => boolean;
220
+ };
221
+ type FilterExpression = {
222
+ type: 'FilterExpression';
223
+ match: (obj: any) => boolean;
224
+ };
225
+
226
+ type ProductProjectionSearchParams = {
227
+ fuzzy?: boolean;
228
+ fuzzyLevel?: number;
229
+ markMatchingVariants?: boolean;
230
+ staged?: boolean;
231
+ filter?: string[];
232
+ 'filter.facets'?: string[];
233
+ 'filter.query'?: string[];
234
+ facet?: string | string[];
235
+ sort?: string | string[];
236
+ limit?: number;
237
+ offset?: number;
238
+ withTotal?: boolean;
239
+ priceCurrency?: string;
240
+ priceCountry?: string;
241
+ priceCustomerGroup?: string;
242
+ priceChannel?: string;
243
+ localeProjection?: string;
244
+ storeProjection?: string;
245
+ expand?: string | string[];
246
+ [key: string]: QueryParam;
247
+ };
248
+ declare class ProductProjectionSearch {
249
+ protected _storage: AbstractStorage;
250
+ constructor(storage: AbstractStorage);
251
+ search(projectKey: string, params: ProductProjectionSearchParams): ProductProjectionPagedSearchResponse;
252
+ transform(product: Product, staged: boolean): ProductProjection;
253
+ getFacets(params: ProductProjectionSearchParams, products: ProductProjection[]): FacetResults;
254
+ /**
255
+ * TODO: This implemention needs the following additional features:
256
+ * - counting products
257
+ * - correct dataType
258
+ */
259
+ termFacet(facet: string, products: ProductProjection[]): TermFacetResult;
260
+ filterFacet(source: string, filters: FilterExpression[] | undefined, products: ProductProjection[]): FilteredFacetResult;
261
+ rangeFacet(source: string, ranges: RangeExpression[] | undefined, products: ProductProjection[]): RangeFacetResult;
262
+ }
263
+
264
+ declare class ProductProjectionRepository extends AbstractResourceRepository<'product-projection'> {
265
+ protected _searchService: ProductProjectionSearch;
266
+ constructor(storage: AbstractStorage);
267
+ getTypeId(): "product-projection";
268
+ create(context: RepositoryContext, draft: ProductDraft): ProductProjection;
269
+ query(context: RepositoryContext, params?: QueryParams): {
270
+ results: ProductProjection[];
271
+ limit: number;
272
+ offset: number;
273
+ count: number;
274
+ total?: number | undefined;
275
+ };
276
+ search(context: RepositoryContext, query: ParsedQs): ctp.ProductProjectionPagedSearchResponse;
277
+ actions: {};
278
+ }
279
+
280
+ declare class ProductSelectionRepository extends AbstractResourceRepository<'product-selection'> {
281
+ getTypeId(): "product-selection";
282
+ create(context: RepositoryContext, draft: ProductSelectionDraft): ProductSelection;
283
+ actions: Partial<Record<ReviewUpdateAction['action'], (context: RepositoryContext, resource: Writable<Review>, action: any) => void>>;
284
+ }
285
+
286
+ declare class ProductTypeRepository extends AbstractResourceRepository<'product-type'> {
287
+ getTypeId(): "product-type";
288
+ create(context: RepositoryContext, draft: ProductTypeDraft): ProductType;
289
+ attributeDefinitionFromAttributeDefinitionDraft: (_context: RepositoryContext, draft: AttributeDefinitionDraft) => AttributeDefinition;
290
+ actions: Partial<Record<ProductTypeUpdateAction['action'], (context: RepositoryContext, resource: Writable<ProductType>, action: any) => void>>;
291
+ }
292
+
293
+ declare class ProjectRepository extends AbstractRepository<Project> {
294
+ get(context: RepositoryContext): Project | null;
295
+ postProcessResource(resource: Project): Project;
296
+ saveNew(context: RepositoryContext, resource: Writable<Project>): void;
297
+ saveUpdate(context: RepositoryContext, version: number, resource: Project): void;
298
+ actions: Partial<Record<ProjectUpdateAction['action'], (context: RepositoryContext, resource: Writable<Project>, action: any) => void>>;
299
+ }
300
+
301
+ declare class QuoteRepository extends AbstractResourceRepository<'quote'> {
302
+ getTypeId(): "quote";
303
+ create(context: RepositoryContext, draft: QuoteDraft): Quote;
304
+ actions: Partial<Record<QuoteUpdateAction['action'], (context: RepositoryContext, resource: Writable<Quote>, action: any) => void>>;
305
+ }
306
+
307
+ declare class QuoteRequestRepository extends AbstractResourceRepository<'quote-request'> {
308
+ getTypeId(): "quote-request";
309
+ create(context: RepositoryContext, draft: QuoteRequestDraft): QuoteRequest;
310
+ actions: Partial<Record<QuoteRequestUpdateAction['action'], (context: RepositoryContext, resource: Writable<QuoteRequest>, action: any) => void>>;
311
+ }
312
+
313
+ declare class ReviewRepository extends AbstractResourceRepository<'review'> {
314
+ getTypeId(): "review";
315
+ create(context: RepositoryContext, draft: ReviewDraft): Review;
316
+ actions: Partial<Record<ReviewUpdateAction['action'], (context: RepositoryContext, resource: Writable<Review>, action: any) => void>>;
317
+ }
318
+
319
+ declare class ShippingMethodRepository extends AbstractResourceRepository<'shipping-method'> {
320
+ getTypeId(): "shipping-method";
321
+ create(context: RepositoryContext, draft: ShippingMethodDraft): ShippingMethod;
322
+ private _transformZoneRateDraft;
323
+ private _transformShippingRate;
324
+ actions: Partial<Record<ShippingMethodUpdateAction['action'], (context: RepositoryContext, resource: Writable<ShippingMethod>, action: any) => void>>;
325
+ }
326
+
327
+ declare class ShoppingListRepository extends AbstractResourceRepository<'shopping-list'> {
328
+ getTypeId(): "shopping-list";
329
+ create(context: RepositoryContext, draft: ShoppingListDraft): ShoppingList;
330
+ }
331
+
332
+ declare class StagedQuoteRepository extends AbstractResourceRepository<'staged-quote'> {
333
+ getTypeId(): "staged-quote";
334
+ create(context: RepositoryContext, draft: StagedQuoteDraft): StagedQuote;
335
+ actions: Partial<Record<StagedQuoteUpdateAction['action'], (context: RepositoryContext, resource: Writable<Quote>, action: any) => void>>;
336
+ }
337
+
338
+ declare class StandAlonePriceRepository extends AbstractResourceRepository<'standalone-price'> {
339
+ getTypeId(): "standalone-price";
340
+ create(context: RepositoryContext, draft: StandalonePriceDraft): StandalonePrice;
341
+ transformChannelReferenceDraft(channel: ChannelResourceIdentifier): ChannelReference;
342
+ transformDiscountDraft(discounted: DiscountedPriceDraft): {
343
+ value: ctp.TypedMoney;
344
+ discount: ctp.ProductDiscountReference;
345
+ };
346
+ actions: {
347
+ setActive: (context: RepositoryContext, resource: Writable<StandalonePrice>, action: StandalonePriceChangeActiveAction) => void;
348
+ changeValue: (context: RepositoryContext, resource: Writable<StandalonePrice>, action: StandalonePriceChangeValueAction) => void;
349
+ setDiscountedPrice: (context: RepositoryContext, resource: Writable<StandalonePrice>, action: StandalonePriceSetDiscountedPriceAction) => void;
350
+ };
351
+ }
352
+
353
+ declare class StateRepository extends AbstractResourceRepository<'state'> {
354
+ getTypeId(): "state";
355
+ create(context: RepositoryContext, draft: StateDraft): State;
356
+ actions: Partial<Record<StateUpdateAction['action'], (context: RepositoryContext, resource: Writable<State>, action: any) => void>>;
357
+ }
358
+
359
+ declare class StoreRepository extends AbstractResourceRepository<'store'> {
360
+ getTypeId(): "store";
361
+ create(context: RepositoryContext, draft: StoreDraft): Store;
362
+ private transformChannels;
363
+ actions: Partial<Record<StoreUpdateAction['action'], (context: RepositoryContext, resource: Writable<Store>, action: any) => void>>;
364
+ }
365
+
366
+ declare class SubscriptionRepository extends AbstractResourceRepository<'subscription'> {
367
+ getTypeId(): "subscription";
368
+ create(context: RepositoryContext, draft: SubscriptionDraft): Subscription;
369
+ }
370
+
371
+ declare class TaxCategoryRepository extends AbstractResourceRepository<'tax-category'> {
372
+ getTypeId(): "tax-category";
373
+ create(context: RepositoryContext, draft: TaxCategoryDraft): TaxCategory;
374
+ private taxRateFromTaxRateDraft;
375
+ actions: Partial<Record<TaxCategoryUpdateAction['action'], (context: RepositoryContext, resource: Writable<TaxCategory>, action: any) => void>>;
376
+ }
377
+
378
+ declare class TypeRepository extends AbstractResourceRepository<'type'> {
379
+ getTypeId(): "type";
380
+ create(context: RepositoryContext, draft: TypeDraft): Type;
381
+ actions: Partial<Record<TypeUpdateAction['action'], (context: RepositoryContext, resource: Writable<Type>, action: any) => void>>;
382
+ }
383
+
384
+ declare class ZoneRepository extends AbstractResourceRepository<'zone'> {
385
+ getTypeId(): "zone";
386
+ create(context: RepositoryContext, draft: ZoneDraft): Zone;
387
+ actions: Partial<Record<ZoneUpdateAction['action'], (context: RepositoryContext, resource: Writable<Zone>, action: any) => void>>;
388
+ }
389
+
390
+ type RepositoryMap = ReturnType<typeof createRepositories>;
391
+ declare const createRepositories: (storage: AbstractStorage) => {
392
+ 'associate-role': AssociateRoleRepository;
393
+ 'attribute-group': AttributeGroupRepository;
394
+ 'business-unit': BusinessUnitRepository;
395
+ category: CategoryRepository;
396
+ cart: CartRepository;
397
+ 'cart-discount': CartDiscountRepository;
398
+ customer: CustomerRepository;
399
+ channel: ChannelRepository;
400
+ 'customer-group': CustomerGroupRepository;
401
+ 'discount-code': DiscountCodeRepository;
402
+ extension: ExtensionRepository;
403
+ 'inventory-entry': InventoryEntryRepository;
404
+ 'key-value-document': CustomObjectRepository;
405
+ order: OrderRepository;
406
+ 'order-edit': OrderEditRepository;
407
+ payment: PaymentRepository;
408
+ 'my-cart': CartRepository;
409
+ 'my-order': MyOrderRepository;
410
+ 'my-customer': CustomerRepository;
411
+ 'my-payment': PaymentRepository;
412
+ product: ProductRepository;
413
+ 'product-type': ProductTypeRepository;
414
+ 'product-discount': ProductDiscountRepository;
415
+ 'product-projection': ProductProjectionRepository;
416
+ 'product-selection': ProductSelectionRepository;
417
+ project: ProjectRepository;
418
+ review: ReviewRepository;
419
+ quote: QuoteRepository;
420
+ 'quote-request': QuoteRequestRepository;
421
+ 'shipping-method': ShippingMethodRepository;
422
+ 'shopping-list': ShoppingListRepository;
423
+ 'staged-quote': StagedQuoteRepository;
424
+ 'standalone-price': StandAlonePriceRepository;
425
+ state: StateRepository;
426
+ store: StoreRepository;
427
+ subscription: SubscriptionRepository;
428
+ 'tax-category': TaxCategoryRepository;
429
+ type: TypeRepository;
430
+ zone: ZoneRepository;
431
+ };
432
+
433
+ type Writable<T> = {
434
+ -readonly [P in keyof T]: Writable<T[P]>;
435
+ };
436
+ type ShallowWritable<T> = {
437
+ -readonly [P in keyof T]: T[P];
438
+ };
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;
444
+ 'cart-discount': ctp.CartDiscount;
445
+ cart: ctp.Cart;
446
+ category: ctp.Category;
447
+ channel: ctp.Channel;
448
+ 'customer-email-token': never;
449
+ 'customer-group': ctp.CustomerGroup;
450
+ 'customer-password-token': never;
451
+ customer: ctp.Customer;
452
+ 'discount-code': ctp.DiscountCode;
453
+ extension: ctp.Extension;
454
+ 'inventory-entry': ctp.InventoryEntry;
455
+ 'key-value-document': ctp.CustomObject;
456
+ 'order-edit': ctp.OrderEdit;
457
+ order: ctp.Order;
458
+ payment: ctp.Payment;
459
+ 'product-discount': ctp.ProductDiscount;
460
+ 'product-price': ctp.StandalonePrice;
461
+ 'product-projection': ctp.ProductProjection;
462
+ 'product-selection': ctp.ProductSelection;
463
+ 'product-type': ctp.ProductType;
464
+ product: ctp.Product;
465
+ 'quote-request': ctp.QuoteRequest;
466
+ quote: ctp.Quote;
467
+ review: ctp.Review;
468
+ 'shipping-method': ctp.ShippingMethod;
469
+ 'shopping-list': ctp.ShoppingList;
470
+ 'staged-quote': ctp.StagedQuote;
471
+ 'standalone-price': ctp.StandalonePrice;
472
+ state: ctp.State;
473
+ store: ctp.Store;
474
+ subscription: ctp.Subscription;
475
+ 'tax-category': ctp.TaxCategory;
476
+ type: ctp.Type;
477
+ zone: ctp.Zone;
478
+ };
479
+ type PagedQueryResponseMap = {
480
+ 'attribute-group': ctp.AttributeGroupPagedQueryResponse;
481
+ 'associate-role': ctp.AssociateRolePagedQueryResponse;
482
+ 'business-unit': ctp.BusinessUnitPagedQueryResponse;
483
+ 'cart-discount': ctp.CartDiscountPagedQueryResponse;
484
+ cart: ctp.CartPagedQueryResponse;
485
+ category: ctp.CategoryPagedQueryResponse;
486
+ channel: ctp.ChannelPagedQueryResponse;
487
+ 'customer-email-token': never;
488
+ 'customer-group': ctp.CustomerGroupPagedQueryResponse;
489
+ 'customer-password-token': never;
490
+ customer: ctp.CustomerPagedQueryResponse;
491
+ 'discount-code': ctp.DiscountCodePagedQueryResponse;
492
+ extension: ctp.ExtensionPagedQueryResponse;
493
+ 'inventory-entry': ctp.InventoryPagedQueryResponse;
494
+ 'key-value-document': ctp.CustomObjectPagedQueryResponse;
495
+ 'order-edit': ctp.OrderEditPagedQueryResponse;
496
+ order: ctp.OrderPagedQueryResponse;
497
+ payment: ctp.PaymentPagedQueryResponse;
498
+ 'product-discount': ctp.ProductDiscountPagedQueryResponse;
499
+ 'product-price': ctp.StandalonePricePagedQueryResponse;
500
+ 'product-projection': ctp.ProductProjectionPagedQueryResponse;
501
+ 'product-selection': ctp.ProductSelectionPagedQueryResponse;
502
+ 'product-type': ctp.ProductTypePagedQueryResponse;
503
+ product: ctp.ProductPagedQueryResponse;
504
+ 'quote-request': ctp.QuoteRequestPagedQueryResponse;
505
+ quote: ctp.QuotePagedQueryResponse;
506
+ review: ctp.ReviewPagedQueryResponse;
507
+ 'shipping-method': ctp.ShippingMethodPagedQueryResponse;
508
+ 'shopping-list': ctp.ShoppingListPagedQueryResponse;
509
+ 'staged-quote': ctp.StagedQuotePagedQueryResponse;
510
+ 'standalone-price': ctp.StandalonePricePagedQueryResponse;
511
+ state: ctp.StatePagedQueryResponse;
512
+ store: ctp.StorePagedQueryResponse;
513
+ subscription: ctp.SubscriptionPagedQueryResponse;
514
+ 'tax-category': ctp.TaxCategoryPagedQueryResponse;
515
+ type: ctp.TypePagedQueryResponse;
516
+ zone: ctp.ZonePagedQueryResponse;
517
+ };
518
+
519
+ type QueryParams = {
520
+ expand?: string[];
521
+ where?: string[];
522
+ offset?: number;
523
+ limit?: number;
524
+ };
525
+ type GetParams = {
526
+ expand?: string[];
527
+ };
528
+ type RepositoryContext = {
529
+ projectKey: string;
530
+ storeKey?: string;
531
+ };
532
+ declare abstract class AbstractRepository<R extends BaseResource | Project> {
533
+ protected _storage: AbstractStorage;
534
+ protected actions: Partial<Record<any, (context: RepositoryContext, resource: any, action: any) => void>>;
535
+ constructor(storage: AbstractStorage);
536
+ abstract saveNew({ projectKey }: RepositoryContext, resource: R): void;
537
+ abstract saveUpdate({ projectKey }: RepositoryContext, version: number, resource: R): void;
538
+ processUpdateActions(context: RepositoryContext, resource: R, version: number, actions: UpdateAction[]): R;
539
+ abstract postProcessResource(resource: any): any;
540
+ }
541
+ declare abstract class AbstractResourceRepository<T extends ResourceType> extends AbstractRepository<ResourceMap[T]> {
542
+ abstract create(context: RepositoryContext, draft: any): ResourceMap[T];
543
+ abstract getTypeId(): T;
544
+ constructor(storage: AbstractStorage);
545
+ postProcessResource(resource: ResourceMap[T]): ResourceMap[T];
546
+ query(context: RepositoryContext, params?: QueryParams): PagedQueryResponseMap[T];
547
+ get(context: RepositoryContext, id: string, params?: GetParams): ResourceMap[T] | null;
548
+ getByKey(context: RepositoryContext, key: string, params?: GetParams): ResourceMap[T] | null;
549
+ delete(context: RepositoryContext, id: string, params?: GetParams): ResourceMap[T] | null;
550
+ saveNew(context: RepositoryContext, resource: ShallowWritable<ResourceMap[T]>): void;
551
+ saveUpdate(context: RepositoryContext, version: number, resource: ShallowWritable<ResourceMap[T]>): ShallowWritable<ResourceMap[T]>;
552
+ }
553
+
554
+ declare class ProjectAPI {
555
+ private projectKey;
556
+ private _storage;
557
+ private _repositories;
558
+ constructor(projectKey: string, repositories: RepositoryMap, storage: AbstractStorage);
559
+ add<T extends keyof RepositoryMap & keyof ResourceMap>(typeId: T, resource: ResourceMap[T]): void;
560
+ get<RT extends ResourceType>(typeId: RT, id: string, params?: GetParams): ResourceMap[RT];
561
+ getRepository<RT extends keyof RepositoryMap>(typeId: RT): RepositoryMap[RT];
562
+ }
563
+
564
+ type CommercetoolsMockOptions = {
565
+ validateCredentials: boolean;
566
+ enableAuthentication: boolean;
567
+ defaultProjectKey: string | undefined;
568
+ apiHost: RegExp | string;
569
+ authHost: RegExp | string;
570
+ silent: boolean;
571
+ };
572
+ type AppOptions = {
573
+ silent?: boolean;
574
+ };
575
+ declare class CommercetoolsMock {
576
+ app: express.Express;
577
+ options: CommercetoolsMockOptions;
578
+ private _storage;
579
+ private _oauth2;
580
+ private _nockScopes;
581
+ private _services;
582
+ private _repositories;
583
+ private _projectService?;
584
+ constructor(options?: Partial<CommercetoolsMockOptions>);
585
+ start(): void;
586
+ stop(): void;
587
+ clear(): void;
588
+ project(projectKey?: string): ProjectAPI;
589
+ runServer(port?: number, options?: AppOptions): void;
590
+ private createApp;
591
+ private mockApiHost;
592
+ private mockAuthHost;
593
+ }
594
+
595
+ declare const getBaseResourceProperties: () => {
596
+ id: string;
597
+ createdAt: string;
598
+ lastModifiedAt: string;
599
+ version: number;
600
+ };
601
+
602
+ export { CommercetoolsMock, CommercetoolsMockOptions, getBaseResourceProperties };