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