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