@labdigital/commercetools-mock 0.6.1 → 0.6.4

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 (81) hide show
  1. package/dist/commercetools-mock.cjs.development.js +365 -332
  2. package/dist/commercetools-mock.cjs.development.js.map +1 -1
  3. package/dist/commercetools-mock.cjs.production.min.js +1 -1
  4. package/dist/commercetools-mock.cjs.production.min.js.map +1 -1
  5. package/dist/commercetools-mock.esm.js +365 -332
  6. package/dist/commercetools-mock.esm.js.map +1 -1
  7. package/dist/projectAPI.d.ts +1 -1
  8. package/dist/repositories/abstract.d.ts +13 -9
  9. package/dist/repositories/cart-discount.d.ts +3 -3
  10. package/dist/repositories/cart.d.ts +12 -12
  11. package/dist/repositories/category.d.ts +11 -11
  12. package/dist/repositories/channel.d.ts +2 -2
  13. package/dist/repositories/custom-object.d.ts +3 -3
  14. package/dist/repositories/customer-group.d.ts +4 -4
  15. package/dist/repositories/customer.d.ts +4 -4
  16. package/dist/repositories/discount-code.d.ts +3 -3
  17. package/dist/repositories/extension.d.ts +3 -3
  18. package/dist/repositories/helpers.d.ts +3 -0
  19. package/dist/repositories/inventory-entry.d.ts +7 -7
  20. package/dist/repositories/my-order.d.ts +6 -0
  21. package/dist/repositories/order.d.ts +18 -17
  22. package/dist/repositories/payment.d.ts +8 -8
  23. package/dist/repositories/product-projection.d.ts +3 -3
  24. package/dist/repositories/product-type.d.ts +5 -5
  25. package/dist/repositories/product.d.ts +4 -4
  26. package/dist/repositories/project.d.ts +4 -4
  27. package/dist/repositories/shipping-method.d.ts +3 -3
  28. package/dist/repositories/shopping-list.d.ts +2 -2
  29. package/dist/repositories/state.d.ts +3 -3
  30. package/dist/repositories/store.d.ts +4 -4
  31. package/dist/repositories/subscription.d.ts +2 -2
  32. package/dist/repositories/tax-category.d.ts +4 -4
  33. package/dist/repositories/type.d.ts +3 -3
  34. package/dist/repositories/zone.d.ts +3 -3
  35. package/dist/services/my-order.d.ts +2 -2
  36. package/dist/storage.d.ts +1 -1
  37. package/package.json +1 -1
  38. package/src/ctMock.ts +6 -0
  39. package/src/projectAPI.ts +1 -1
  40. package/src/repositories/abstract.ts +37 -17
  41. package/src/repositories/cart-discount.ts +11 -11
  42. package/src/repositories/cart.ts +28 -19
  43. package/src/repositories/category.ts +17 -13
  44. package/src/repositories/channel.ts +3 -3
  45. package/src/repositories/custom-object.ts +16 -8
  46. package/src/repositories/customer-group.ts +5 -5
  47. package/src/repositories/customer.ts +10 -6
  48. package/src/repositories/discount-code.ts +14 -14
  49. package/src/repositories/errors.ts +3 -3
  50. package/src/repositories/extension.ts +12 -8
  51. package/src/repositories/helpers.ts +9 -0
  52. package/src/repositories/inventory-entry.ts +17 -10
  53. package/src/repositories/my-order.ts +19 -0
  54. package/src/repositories/order.test.ts +79 -3
  55. package/src/repositories/order.ts +77 -37
  56. package/src/repositories/payment.ts +21 -17
  57. package/src/repositories/product-projection.ts +5 -5
  58. package/src/repositories/product-type.ts +14 -10
  59. package/src/repositories/product.ts +5 -5
  60. package/src/repositories/project.ts +21 -17
  61. package/src/repositories/shipping-method.ts +27 -20
  62. package/src/repositories/shopping-list.ts +10 -6
  63. package/src/repositories/state.ts +13 -9
  64. package/src/repositories/store.ts +18 -14
  65. package/src/repositories/subscription.ts +3 -3
  66. package/src/repositories/tax-category.ts +16 -12
  67. package/src/repositories/type.ts +15 -11
  68. package/src/repositories/zone.ts +13 -9
  69. package/src/services/abstract.ts +17 -9
  70. package/src/services/cart.ts +6 -12
  71. package/src/services/custom-object.ts +8 -4
  72. package/src/services/customer.ts +5 -2
  73. package/src/services/my-customer.ts +7 -3
  74. package/src/services/my-order.ts +3 -3
  75. package/src/services/order.ts +3 -2
  76. package/src/services/product-projection.ts +2 -1
  77. package/src/services/product-type.ts +2 -1
  78. package/src/services/project.ts +4 -4
  79. package/src/services/store.ts +2 -1
  80. package/src/services/tax-category.ts +2 -1
  81. package/src/storage.ts +1 -1
@@ -7,6 +7,6 @@ export declare class ProjectAPI {
7
7
  private _services;
8
8
  constructor(projectKey: string, services: Services, storage: AbstractStorage);
9
9
  add<ReferenceTypeId extends keyof ResourceMap>(typeId: ReferenceTypeId | 'custom-object', resource: ResourceMap[ReferenceTypeId]): void;
10
- get<ReferenceTypeId extends keyof ResourceMap>(typeId: ReferenceTypeId, id: string, params: GetParams): ResourceMap[ReferenceTypeId];
10
+ get<ReferenceTypeId extends keyof ResourceMap>(typeId: ReferenceTypeId, id: string, params?: GetParams): ResourceMap[ReferenceTypeId];
11
11
  getRepository<ReferenceTypeId extends keyof RepositoryMap>(typeId: ReferenceTypeId): RepositoryMap[ReferenceTypeId];
12
12
  }
@@ -10,20 +10,24 @@ export declare type QueryParams = {
10
10
  export declare type GetParams = {
11
11
  expand?: string[];
12
12
  };
13
+ export declare type RepositoryContext = {
14
+ projectKey: string;
15
+ storeKey?: string;
16
+ };
13
17
  export declare abstract class AbstractRepository {
14
18
  protected _storage: AbstractStorage;
15
- protected actions: Partial<Record<any, (projectKey: string, resource: any, action: any) => void>>;
19
+ protected actions: Partial<Record<any, (context: RepositoryContext, resource: any, action: any) => void>>;
16
20
  constructor(storage: AbstractStorage);
17
- abstract save(projectKey: string, resource: BaseResource | Project): void;
18
- processUpdateActions(projectKey: string, resource: BaseResource | Project, actions: UpdateAction[]): BaseResource;
21
+ abstract save({ projectKey }: RepositoryContext, resource: BaseResource | Project): void;
22
+ processUpdateActions(context: RepositoryContext, resource: BaseResource | Project, actions: UpdateAction[]): BaseResource;
19
23
  }
20
24
  export declare abstract class AbstractResourceRepository extends AbstractRepository {
21
- abstract create(projectKey: string, draft: any): BaseResource;
25
+ abstract create(context: RepositoryContext, draft: any): BaseResource;
22
26
  abstract getTypeId(): RepositoryTypes;
23
27
  constructor(storage: AbstractStorage);
24
- query(projectKey: string, params?: QueryParams): import("@commercetools/platform-sdk").PagedQueryResponse;
25
- get(projectKey: string, id: string, params?: GetParams): BaseResource | null;
26
- getByKey(projectKey: string, key: string, params?: GetParams): BaseResource | null;
27
- delete(projectKey: string, id: string, params?: GetParams): BaseResource | null;
28
- save(projectKey: string, resource: BaseResource): void;
28
+ query(context: RepositoryContext, params?: QueryParams): import("@commercetools/platform-sdk").PagedQueryResponse;
29
+ get(context: RepositoryContext, id: string, params?: GetParams): BaseResource | null;
30
+ getByKey(context: RepositoryContext, key: string, params?: GetParams): BaseResource | null;
31
+ delete(context: RepositoryContext, id: string, params?: GetParams): BaseResource | null;
32
+ save(context: RepositoryContext, resource: BaseResource): void;
29
33
  }
@@ -1,9 +1,9 @@
1
1
  import { CartDiscount, CartDiscountDraft, CartDiscountUpdateAction, ReferenceTypeId } from '@commercetools/platform-sdk';
2
2
  import { Writable } from 'types';
3
- import { AbstractResourceRepository } from './abstract';
3
+ import { AbstractResourceRepository, RepositoryContext } from './abstract';
4
4
  export declare class CartDiscountRepository extends AbstractResourceRepository {
5
5
  getTypeId(): ReferenceTypeId;
6
- create(projectKey: string, draft: CartDiscountDraft): CartDiscount;
6
+ create(context: RepositoryContext, draft: CartDiscountDraft): CartDiscount;
7
7
  private transformValueDraft;
8
- actions: Partial<Record<CartDiscountUpdateAction['action'], (projectKey: string, resource: Writable<CartDiscount>, action: any) => void>>;
8
+ actions: Partial<Record<CartDiscountUpdateAction['action'], (context: RepositoryContext, resource: Writable<CartDiscount>, action: any) => void>>;
9
9
  }
@@ -1,21 +1,21 @@
1
1
  import { Cart, CartAddLineItemAction, CartDraft, CartRemoveLineItemAction, CartSetBillingAddressAction, CartSetCountryAction, CartSetCustomerEmailAction, CartSetCustomFieldAction, CartSetCustomTypeAction, CartSetLocaleAction, CartSetShippingAddressAction, CartSetShippingMethodAction, LineItem, LineItemDraft, ReferenceTypeId } from '@commercetools/platform-sdk';
2
- import { AbstractResourceRepository } from './abstract';
2
+ import { AbstractResourceRepository, RepositoryContext } from './abstract';
3
3
  import { Writable } from '../types';
4
4
  export declare class CartRepository extends AbstractResourceRepository {
5
5
  getTypeId(): ReferenceTypeId;
6
- create(projectKey: string, draft: CartDraft): Cart;
6
+ create(context: RepositoryContext, draft: CartDraft): Cart;
7
7
  getActiveCart(projectKey: string): Cart | undefined;
8
8
  actions: {
9
- addLineItem: (projectKey: string, resource: Writable<Cart>, { productId, variantId, sku, quantity }: CartAddLineItemAction) => void;
10
- removeLineItem: (projectKey: string, resource: Writable<Cart>, { lineItemId, quantity }: CartRemoveLineItemAction) => void;
11
- setBillingAddress: (projectKey: string, resource: Writable<Cart>, { address }: CartSetBillingAddressAction) => void;
12
- setShippingMethod: (projectKey: string, resource: Writable<Cart>, { shippingMethod }: CartSetShippingMethodAction) => void;
13
- setCountry: (projectKey: string, resource: Writable<Cart>, { country }: CartSetCountryAction) => void;
14
- setCustomerEmail: (projectKey: string, resource: Writable<Cart>, { email }: CartSetCustomerEmailAction) => void;
15
- setCustomField: (projectKey: string, resource: Cart, { name, value }: CartSetCustomFieldAction) => void;
16
- setCustomType: (projectKey: string, resource: Writable<Cart>, { type, fields }: CartSetCustomTypeAction) => void;
17
- setLocale: (projectKey: string, resource: Writable<Cart>, { locale }: CartSetLocaleAction) => void;
18
- setShippingAddress: (projectKey: string, resource: Writable<Cart>, { address }: CartSetShippingAddressAction) => void;
9
+ addLineItem: (context: RepositoryContext, resource: Writable<Cart>, { productId, variantId, sku, quantity }: CartAddLineItemAction) => void;
10
+ removeLineItem: (context: RepositoryContext, resource: Writable<Cart>, { lineItemId, quantity }: CartRemoveLineItemAction) => void;
11
+ setBillingAddress: (context: RepositoryContext, resource: Writable<Cart>, { address }: CartSetBillingAddressAction) => void;
12
+ setShippingMethod: (context: RepositoryContext, resource: Writable<Cart>, { shippingMethod }: CartSetShippingMethodAction) => void;
13
+ setCountry: (context: RepositoryContext, resource: Writable<Cart>, { country }: CartSetCountryAction) => void;
14
+ setCustomerEmail: (context: RepositoryContext, resource: Writable<Cart>, { email }: CartSetCustomerEmailAction) => void;
15
+ setCustomField: (context: RepositoryContext, resource: Cart, { name, value }: CartSetCustomFieldAction) => void;
16
+ setCustomType: (context: RepositoryContext, resource: Writable<Cart>, { type, fields }: CartSetCustomTypeAction) => void;
17
+ setLocale: (context: RepositoryContext, resource: Writable<Cart>, { locale }: CartSetLocaleAction) => void;
18
+ setShippingAddress: (context: RepositoryContext, resource: Writable<Cart>, { address }: CartSetShippingAddressAction) => void;
19
19
  };
20
20
  draftLineItemtoLineItem: (projectKey: string, draftLineItem: LineItemDraft, currency: string, country: string | undefined) => LineItem;
21
21
  }
@@ -1,18 +1,18 @@
1
1
  import { Category, CategoryChangeAssetNameAction, CategoryChangeSlugAction, CategoryDraft, CategorySetAssetDescriptionAction, CategorySetAssetSourcesAction, CategorySetDescriptionAction, CategorySetKeyAction, CategorySetMetaDescriptionAction, CategorySetMetaKeywordsAction, CategorySetMetaTitleAction, ReferenceTypeId } from '@commercetools/platform-sdk';
2
2
  import { Writable } from 'types';
3
- import { AbstractResourceRepository } from './abstract';
3
+ import { AbstractResourceRepository, RepositoryContext } from './abstract';
4
4
  export declare class CategoryRepository extends AbstractResourceRepository {
5
5
  getTypeId(): ReferenceTypeId;
6
- create(projectKey: string, draft: CategoryDraft): Category;
6
+ create(context: RepositoryContext, draft: CategoryDraft): Category;
7
7
  actions: {
8
- changeAssetName: (projectKey: string, resource: Writable<Category>, { assetId, assetKey, name }: CategoryChangeAssetNameAction) => void;
9
- changeSlug: (projectKey: string, resource: Writable<Category>, { slug }: CategoryChangeSlugAction) => void;
10
- setKey: (projectKey: string, resource: Writable<Category>, { key }: CategorySetKeyAction) => void;
11
- setAssetDescription: (projectKey: string, resource: Writable<Category>, { assetId, assetKey, description }: CategorySetAssetDescriptionAction) => void;
12
- setAssetSources: (projectKey: string, resource: Writable<Category>, { assetId, assetKey, sources }: CategorySetAssetSourcesAction) => void;
13
- setDescription: (projectKey: string, resource: Writable<Category>, { description }: CategorySetDescriptionAction) => void;
14
- setMetaDescription: (projectKey: string, resource: Writable<Category>, { metaDescription }: CategorySetMetaDescriptionAction) => void;
15
- setMetaKeywords: (projectKey: string, resource: Writable<Category>, { metaKeywords }: CategorySetMetaKeywordsAction) => void;
16
- setMetaTitle: (projectKey: string, resource: Writable<Category>, { metaTitle }: CategorySetMetaTitleAction) => void;
8
+ changeAssetName: (context: RepositoryContext, resource: Writable<Category>, { assetId, assetKey, name }: CategoryChangeAssetNameAction) => void;
9
+ changeSlug: (context: RepositoryContext, resource: Writable<Category>, { slug }: CategoryChangeSlugAction) => void;
10
+ setKey: (context: RepositoryContext, resource: Writable<Category>, { key }: CategorySetKeyAction) => void;
11
+ setAssetDescription: (context: RepositoryContext, resource: Writable<Category>, { assetId, assetKey, description }: CategorySetAssetDescriptionAction) => void;
12
+ setAssetSources: (context: RepositoryContext, resource: Writable<Category>, { assetId, assetKey, sources }: CategorySetAssetSourcesAction) => void;
13
+ setDescription: (context: RepositoryContext, resource: Writable<Category>, { description }: CategorySetDescriptionAction) => void;
14
+ setMetaDescription: (context: RepositoryContext, resource: Writable<Category>, { metaDescription }: CategorySetMetaDescriptionAction) => void;
15
+ setMetaKeywords: (context: RepositoryContext, resource: Writable<Category>, { metaKeywords }: CategorySetMetaKeywordsAction) => void;
16
+ setMetaTitle: (context: RepositoryContext, resource: Writable<Category>, { metaTitle }: CategorySetMetaTitleAction) => void;
17
17
  };
18
18
  }
@@ -1,6 +1,6 @@
1
1
  import { Channel, ChannelDraft, ReferenceTypeId } from '@commercetools/platform-sdk';
2
- import { AbstractResourceRepository } from './abstract';
2
+ import { AbstractResourceRepository, RepositoryContext } from './abstract';
3
3
  export declare class ChannelRepository extends AbstractResourceRepository {
4
4
  getTypeId(): ReferenceTypeId;
5
- create(projectKey: string, draft: ChannelDraft): Channel;
5
+ create(context: RepositoryContext, draft: ChannelDraft): Channel;
6
6
  }
@@ -1,8 +1,8 @@
1
1
  import { CustomObject, CustomObjectDraft, ReferenceTypeId } from '@commercetools/platform-sdk';
2
- import { AbstractResourceRepository } from './abstract';
2
+ import { AbstractResourceRepository, RepositoryContext } from './abstract';
3
3
  import { Writable } from '../types';
4
4
  export declare class CustomObjectRepository extends AbstractResourceRepository {
5
5
  getTypeId(): ReferenceTypeId;
6
- create(projectKey: string, draft: Writable<CustomObjectDraft>): CustomObject;
7
- getWithContainerAndKey(projectKey: string, container: string, key: string): CustomObject | undefined;
6
+ create(context: RepositoryContext, draft: Writable<CustomObjectDraft>): CustomObject;
7
+ getWithContainerAndKey(context: RepositoryContext, container: string, key: string): CustomObject | undefined;
8
8
  }
@@ -1,11 +1,11 @@
1
1
  import { CustomerGroup, CustomerGroupChangeNameAction, CustomerGroupDraft, CustomerGroupSetKeyAction, ReferenceTypeId } from '@commercetools/platform-sdk';
2
2
  import { Writable } from 'types';
3
- import { AbstractResourceRepository } from './abstract';
3
+ import { AbstractResourceRepository, RepositoryContext } from './abstract';
4
4
  export declare class CustomerGroupRepository extends AbstractResourceRepository {
5
5
  getTypeId(): ReferenceTypeId;
6
- create(projectKey: string, draft: CustomerGroupDraft): CustomerGroup;
6
+ create(context: RepositoryContext, draft: CustomerGroupDraft): CustomerGroup;
7
7
  actions: {
8
- setKey: (projectKey: string, resource: Writable<CustomerGroup>, { key }: CustomerGroupSetKeyAction) => void;
9
- changeName: (projectKey: string, resource: Writable<CustomerGroup>, { name }: CustomerGroupChangeNameAction) => void;
8
+ setKey: (context: RepositoryContext, resource: Writable<CustomerGroup>, { key }: CustomerGroupSetKeyAction) => void;
9
+ changeName: (context: RepositoryContext, resource: Writable<CustomerGroup>, { name }: CustomerGroupChangeNameAction) => void;
10
10
  };
11
11
  }
@@ -1,11 +1,11 @@
1
1
  import { Customer, CustomerChangeEmailAction, CustomerDraft, ReferenceTypeId } from '@commercetools/platform-sdk';
2
2
  import { Writable } from 'types';
3
- import { AbstractResourceRepository } from './abstract';
3
+ import { AbstractResourceRepository, RepositoryContext } from './abstract';
4
4
  export declare class CustomerRepository extends AbstractResourceRepository {
5
5
  getTypeId(): ReferenceTypeId;
6
- create(projectKey: string, draft: CustomerDraft): Customer;
7
- getMe(projectKey: string): Customer | undefined;
6
+ create(context: RepositoryContext, draft: CustomerDraft): Customer;
7
+ getMe(context: RepositoryContext): Customer | undefined;
8
8
  actions: {
9
- changeEmail: (_projectKey: string, resource: Writable<Customer>, { email }: CustomerChangeEmailAction) => void;
9
+ changeEmail: (_context: RepositoryContext, resource: Writable<Customer>, { email }: CustomerChangeEmailAction) => void;
10
10
  };
11
11
  }
@@ -1,8 +1,8 @@
1
1
  import { DiscountCode, DiscountCodeDraft, DiscountCodeUpdateAction, ReferenceTypeId } from '@commercetools/platform-sdk';
2
2
  import { Writable } from 'types';
3
- import { AbstractResourceRepository } from './abstract';
3
+ import { AbstractResourceRepository, RepositoryContext } from './abstract';
4
4
  export declare class DiscountCodeRepository extends AbstractResourceRepository {
5
5
  getTypeId(): ReferenceTypeId;
6
- create(projectKey: string, draft: DiscountCodeDraft): DiscountCode;
7
- actions: Partial<Record<DiscountCodeUpdateAction['action'], (projectKey: string, resource: Writable<DiscountCode>, action: any) => void>>;
6
+ create(context: RepositoryContext, draft: DiscountCodeDraft): DiscountCode;
7
+ actions: Partial<Record<DiscountCodeUpdateAction['action'], (context: RepositoryContext, resource: Writable<DiscountCode>, action: any) => void>>;
8
8
  }
@@ -1,8 +1,8 @@
1
1
  import { Extension, ExtensionDraft, ExtensionUpdateAction, ReferenceTypeId } from '@commercetools/platform-sdk';
2
2
  import { Writable } from '../types';
3
- import { AbstractResourceRepository } from './abstract';
3
+ import { AbstractResourceRepository, RepositoryContext } from './abstract';
4
4
  export declare class ExtensionRepository extends AbstractResourceRepository {
5
5
  getTypeId(): ReferenceTypeId;
6
- create(projectKey: string, draft: ExtensionDraft): Extension;
7
- actions: Record<ExtensionUpdateAction['action'], (projectKey: string, resource: Writable<Extension>, action: any) => void>;
6
+ create(context: RepositoryContext, draft: ExtensionDraft): Extension;
7
+ actions: Record<ExtensionUpdateAction['action'], (context: RepositoryContext, resource: Writable<Extension>, action: any) => void>;
8
8
  }
@@ -1,7 +1,10 @@
1
1
  import { CustomFields, CustomFieldsDraft, Money, Price, PriceDraft, Reference, ResourceIdentifier, StoreKeyReference, StoreResourceIdentifier, TypedMoney } from '@commercetools/platform-sdk';
2
2
  import { AbstractStorage } from '../storage';
3
+ import { RepositoryContext } from './abstract';
4
+ import { Request } from 'express';
3
5
  export declare const createCustomFields: (draft: CustomFieldsDraft | undefined, projectKey: string, storage: AbstractStorage) => CustomFields | undefined;
4
6
  export declare const createPrice: (draft: PriceDraft) => Price;
5
7
  export declare const createTypedMoney: (value: Money) => TypedMoney;
6
8
  export declare const resolveStoreReference: (ref: StoreResourceIdentifier | undefined, projectKey: string, storage: AbstractStorage) => StoreKeyReference | undefined;
7
9
  export declare const getReferenceFromResourceIdentifier: <T extends Reference>(resourceIdentifier: ResourceIdentifier, projectKey: string, storage: AbstractStorage) => T;
10
+ export declare const getRepositoryContext: (request: Request) => RepositoryContext;
@@ -1,14 +1,14 @@
1
1
  import { InventoryEntry, InventoryEntryChangeQuantityAction, InventoryEntryDraft, InventoryEntrySetCustomFieldAction, InventoryEntrySetCustomTypeAction, InventoryEntrySetExpectedDeliveryAction, InventoryEntrySetRestockableInDaysAction, ReferenceTypeId } from '@commercetools/platform-sdk';
2
- import { AbstractResourceRepository } from './abstract';
2
+ import { AbstractResourceRepository, RepositoryContext } from './abstract';
3
3
  import { Writable } from '../types';
4
4
  export declare class InventoryEntryRepository extends AbstractResourceRepository {
5
5
  getTypeId(): ReferenceTypeId;
6
- create(projectKey: string, draft: InventoryEntryDraft): InventoryEntry;
6
+ create(context: RepositoryContext, draft: InventoryEntryDraft): InventoryEntry;
7
7
  actions: {
8
- changeQuantity: (projectKey: string, resource: Writable<InventoryEntry>, { quantity }: InventoryEntryChangeQuantityAction) => void;
9
- setExpectedDelivery: (projectKey: string, resource: Writable<InventoryEntry>, { expectedDelivery }: InventoryEntrySetExpectedDeliveryAction) => void;
10
- setCustomField: (projectKey: string, resource: InventoryEntry, { name, value }: InventoryEntrySetCustomFieldAction) => void;
11
- setCustomType: (projectKey: string, resource: Writable<InventoryEntry>, { type, fields }: InventoryEntrySetCustomTypeAction) => void;
12
- setRestockableInDays: (projectKey: string, resource: Writable<InventoryEntry>, { restockableInDays }: InventoryEntrySetRestockableInDaysAction) => void;
8
+ changeQuantity: (context: RepositoryContext, resource: Writable<InventoryEntry>, { quantity }: InventoryEntryChangeQuantityAction) => void;
9
+ setExpectedDelivery: (context: RepositoryContext, resource: Writable<InventoryEntry>, { expectedDelivery }: InventoryEntrySetExpectedDeliveryAction) => void;
10
+ setCustomField: (context: RepositoryContext, resource: InventoryEntry, { name, value }: InventoryEntrySetCustomFieldAction) => void;
11
+ setCustomType: (context: RepositoryContext, resource: Writable<InventoryEntry>, { type, fields }: InventoryEntrySetCustomTypeAction) => void;
12
+ setRestockableInDays: (context: RepositoryContext, resource: Writable<InventoryEntry>, { restockableInDays }: InventoryEntrySetRestockableInDaysAction) => void;
13
13
  };
14
14
  }
@@ -0,0 +1,6 @@
1
+ import { MyOrderFromCartDraft, Order } from '@commercetools/platform-sdk';
2
+ import { OrderRepository } from './order';
3
+ import { RepositoryContext } from './abstract';
4
+ export declare class MyOrderRepository extends OrderRepository {
5
+ create(context: RepositoryContext, draft: MyOrderFromCartDraft): Order;
6
+ }
@@ -1,25 +1,26 @@
1
- import { Order, OrderAddPaymentAction, OrderChangeOrderStateAction, OrderChangePaymentStateAction, OrderFromCartDraft, OrderImportDraft, OrderSetBillingAddressAction, OrderSetCustomerEmailAction, OrderSetCustomFieldAction, OrderSetCustomTypeAction, OrderSetLocaleAction, OrderSetOrderNumberAction, OrderSetShippingAddressAction, OrderSetStoreAction, OrderTransitionStateAction, ReferenceTypeId } from '@commercetools/platform-sdk';
2
- import { AbstractResourceRepository, QueryParams } from './abstract';
1
+ import { CartReference, Order, OrderAddPaymentAction, OrderChangeOrderStateAction, OrderChangePaymentStateAction, OrderFromCartDraft, OrderImportDraft, OrderSetBillingAddressAction, OrderSetCustomerEmailAction, OrderSetCustomFieldAction, OrderSetCustomTypeAction, OrderSetLocaleAction, OrderSetOrderNumberAction, OrderSetShippingAddressAction, OrderSetStoreAction, OrderTransitionStateAction, ReferenceTypeId } from '@commercetools/platform-sdk';
2
+ import { AbstractResourceRepository, QueryParams, RepositoryContext } from './abstract';
3
3
  import { Writable } from '../types';
4
4
  export declare class OrderRepository extends AbstractResourceRepository {
5
5
  getTypeId(): ReferenceTypeId;
6
- create(projectKey: string, draft: OrderFromCartDraft): Order;
7
- import(projectKey: string, draft: OrderImportDraft): Order;
6
+ create(context: RepositoryContext, draft: OrderFromCartDraft): Order;
7
+ createFromCart(context: RepositoryContext, cartReference: CartReference, orderNumber?: string): Order;
8
+ import(context: RepositoryContext, draft: OrderImportDraft): Order;
8
9
  private lineItemFromImportDraft;
9
10
  private customLineItemFromImportDraft;
10
- getWithOrderNumber(projectKey: string, orderNumber: string, params?: QueryParams): Order | undefined;
11
+ getWithOrderNumber(context: RepositoryContext, orderNumber: string, params?: QueryParams): Order | undefined;
11
12
  actions: {
12
- addPayment: (projectKey: string, resource: Writable<Order>, { payment }: OrderAddPaymentAction) => void;
13
- changeOrderState: (projectKey: string, resource: Writable<Order>, { orderState }: OrderChangeOrderStateAction) => void;
14
- changePaymentState: (projectKey: string, resource: Writable<Order>, { paymentState }: OrderChangePaymentStateAction) => void;
15
- transitionState: (projectKey: string, resource: Writable<Order>, { state }: OrderTransitionStateAction) => void;
16
- setBillingAddress: (projectKey: string, resource: Writable<Order>, { address }: OrderSetBillingAddressAction) => void;
17
- setCustomerEmail: (projectKey: string, resource: Writable<Order>, { email }: OrderSetCustomerEmailAction) => void;
18
- setCustomField: (projectKey: string, resource: Order, { name, value }: OrderSetCustomFieldAction) => void;
19
- setCustomType: (projectKey: string, resource: Writable<Order>, { type, fields }: OrderSetCustomTypeAction) => void;
20
- setLocale: (projectKey: string, resource: Writable<Order>, { locale }: OrderSetLocaleAction) => void;
21
- setOrderNumber: (projectKey: string, resource: Writable<Order>, { orderNumber }: OrderSetOrderNumberAction) => void;
22
- setShippingAddress: (projectKey: string, resource: Writable<Order>, { address }: OrderSetShippingAddressAction) => void;
23
- setStore: (projectKey: string, resource: Writable<Order>, { store }: OrderSetStoreAction) => void;
13
+ addPayment: (context: RepositoryContext, resource: Writable<Order>, { payment }: OrderAddPaymentAction) => void;
14
+ changeOrderState: (context: RepositoryContext, resource: Writable<Order>, { orderState }: OrderChangeOrderStateAction) => void;
15
+ changePaymentState: (context: RepositoryContext, resource: Writable<Order>, { paymentState }: OrderChangePaymentStateAction) => void;
16
+ transitionState: (context: RepositoryContext, resource: Writable<Order>, { state }: OrderTransitionStateAction) => void;
17
+ setBillingAddress: (context: RepositoryContext, resource: Writable<Order>, { address }: OrderSetBillingAddressAction) => void;
18
+ setCustomerEmail: (context: RepositoryContext, resource: Writable<Order>, { email }: OrderSetCustomerEmailAction) => void;
19
+ setCustomField: (context: RepositoryContext, resource: Order, { name, value }: OrderSetCustomFieldAction) => void;
20
+ setCustomType: (context: RepositoryContext, resource: Writable<Order>, { type, fields }: OrderSetCustomTypeAction) => void;
21
+ setLocale: (context: RepositoryContext, resource: Writable<Order>, { locale }: OrderSetLocaleAction) => void;
22
+ setOrderNumber: (context: RepositoryContext, resource: Writable<Order>, { orderNumber }: OrderSetOrderNumberAction) => void;
23
+ setShippingAddress: (context: RepositoryContext, resource: Writable<Order>, { address }: OrderSetShippingAddressAction) => void;
24
+ setStore: (context: RepositoryContext, resource: Writable<Order>, { store }: OrderSetStoreAction) => void;
24
25
  };
25
26
  }
@@ -1,10 +1,10 @@
1
1
  import { Payment, PaymentAddTransactionAction, PaymentChangeTransactionStateAction, PaymentDraft, PaymentSetCustomFieldAction, PaymentSetCustomTypeAction, PaymentTransitionStateAction, ReferenceTypeId, TransactionDraft } from '@commercetools/platform-sdk';
2
- import { AbstractResourceRepository } from './abstract';
2
+ import { AbstractResourceRepository, RepositoryContext } from './abstract';
3
3
  import { Writable } from '../types';
4
4
  export declare class PaymentRepository extends AbstractResourceRepository {
5
5
  getTypeId(): ReferenceTypeId;
6
- create(projectKey: string, draft: PaymentDraft): Payment;
7
- transactionFromTransactionDraft: (draft: TransactionDraft, projectKey: string) => {
6
+ create(context: RepositoryContext, draft: PaymentDraft): Payment;
7
+ transactionFromTransactionDraft: (draft: TransactionDraft, context: RepositoryContext) => {
8
8
  id: string;
9
9
  amount: import("@commercetools/platform-sdk").TypedMoney;
10
10
  custom: import("@commercetools/platform-sdk").CustomFields | undefined;
@@ -14,10 +14,10 @@ export declare class PaymentRepository extends AbstractResourceRepository {
14
14
  state?: "Failure" | "Initial" | "Pending" | "Success" | undefined;
15
15
  };
16
16
  actions: {
17
- setCustomField: (projectKey: string, resource: Payment, { name, value }: PaymentSetCustomFieldAction) => void;
18
- setCustomType: (projectKey: string, resource: Writable<Payment>, { type, fields }: PaymentSetCustomTypeAction) => void;
19
- addTransaction: (projectKey: string, resource: Writable<Payment>, { transaction }: PaymentAddTransactionAction) => void;
20
- changeTransactionState: (_projectKey: string, resource: Writable<Payment>, { transactionId, state }: PaymentChangeTransactionStateAction) => void;
21
- transitionState: (projectKey: string, resource: Writable<Payment>, { state }: PaymentTransitionStateAction) => void;
17
+ setCustomField: (context: RepositoryContext, resource: Payment, { name, value }: PaymentSetCustomFieldAction) => void;
18
+ setCustomType: (context: RepositoryContext, resource: Writable<Payment>, { type, fields }: PaymentSetCustomTypeAction) => void;
19
+ addTransaction: (context: RepositoryContext, resource: Writable<Payment>, { transaction }: PaymentAddTransactionAction) => void;
20
+ changeTransactionState: (_context: RepositoryContext, resource: Writable<Payment>, { transactionId, state }: PaymentChangeTransactionStateAction) => void;
21
+ transitionState: (context: RepositoryContext, resource: Writable<Payment>, { state }: PaymentTransitionStateAction) => void;
22
22
  };
23
23
  }
@@ -1,10 +1,10 @@
1
1
  import { ParsedQs } from 'qs';
2
2
  import { ProductDraft, ProductProjection } from '@commercetools/platform-sdk';
3
- import { AbstractResourceRepository } from './abstract';
3
+ import { AbstractResourceRepository, RepositoryContext } from './abstract';
4
4
  import { RepositoryTypes } from '../types';
5
5
  export declare class ProductProjectionRepository extends AbstractResourceRepository {
6
6
  getTypeId(): RepositoryTypes;
7
- create(projectKey: string, draft: ProductDraft): ProductProjection;
8
- search(projectKey: string, query: ParsedQs): import("@commercetools/platform-sdk").PagedQueryResponse;
7
+ create(context: RepositoryContext, draft: ProductDraft): ProductProjection;
8
+ search(context: RepositoryContext, query: ParsedQs): import("@commercetools/platform-sdk").PagedQueryResponse;
9
9
  actions: {};
10
10
  }
@@ -1,10 +1,10 @@
1
1
  import { AttributeDefinition, AttributeDefinitionDraft, ProductType, ProductTypeDraft, ProductTypeUpdateAction, ReferenceTypeId } from '@commercetools/platform-sdk';
2
- import { AbstractResourceRepository } from './abstract';
2
+ import { AbstractResourceRepository, RepositoryContext } from './abstract';
3
3
  import { Writable } from 'types';
4
4
  export declare class ProductTypeRepository extends AbstractResourceRepository {
5
5
  getTypeId(): ReferenceTypeId;
6
- create(projectKey: string, draft: ProductTypeDraft): ProductType;
7
- attributeDefinitionFromAttributeDefinitionDraft: (_projectKey: string, draft: AttributeDefinitionDraft) => AttributeDefinition;
8
- getWithKey(projectKey: string, key: string): ProductType | undefined;
9
- actions: Partial<Record<ProductTypeUpdateAction['action'], (projectKey: string, resource: Writable<ProductType>, action: any) => void>>;
6
+ create(context: RepositoryContext, draft: ProductTypeDraft): ProductType;
7
+ attributeDefinitionFromAttributeDefinitionDraft: (_context: RepositoryContext, draft: AttributeDefinitionDraft) => AttributeDefinition;
8
+ getWithKey(context: RepositoryContext, key: string): ProductType | undefined;
9
+ actions: Partial<Record<ProductTypeUpdateAction['action'], (context: RepositoryContext, resource: Writable<ProductType>, action: any) => void>>;
10
10
  }
@@ -1,11 +1,11 @@
1
1
  import { Product, ProductDraft, ProductPublishAction, ProductSetAttributeAction, ReferenceTypeId } from '@commercetools/platform-sdk';
2
- import { AbstractResourceRepository } from './abstract';
2
+ import { AbstractResourceRepository, RepositoryContext } from './abstract';
3
3
  import { Writable } from '../types';
4
4
  export declare class ProductRepository extends AbstractResourceRepository {
5
5
  getTypeId(): ReferenceTypeId;
6
- create(projectKey: string, draft: ProductDraft): Product;
6
+ create(context: RepositoryContext, draft: ProductDraft): Product;
7
7
  actions: {
8
- publish: (projectKey: string, resource: Writable<Product>, { scope }: ProductPublishAction) => void;
9
- setAttribute: (projectKey: string, resource: Writable<Product>, { variantId, sku, name, value, staged }: ProductSetAttributeAction) => void;
8
+ publish: (context: RepositoryContext, resource: Writable<Product>, { scope }: ProductPublishAction) => void;
9
+ setAttribute: (context: RepositoryContext, resource: Writable<Product>, { variantId, sku, name, value, staged }: ProductSetAttributeAction) => void;
10
10
  };
11
11
  }
@@ -1,8 +1,8 @@
1
1
  import { Project, ProjectUpdateAction } from '@commercetools/platform-sdk';
2
2
  import { Writable } from 'types';
3
- import { AbstractRepository } from './abstract';
3
+ import { AbstractRepository, RepositoryContext } from './abstract';
4
4
  export declare class ProjectRepository extends AbstractRepository {
5
- get(projectKey: string): Project | null;
6
- save(projectKey: string, resource: Project): void;
7
- actions: Partial<Record<ProjectUpdateAction['action'], (projectKey: string, resource: Writable<Project>, action: any) => void>>;
5
+ get(context: RepositoryContext): Project | null;
6
+ save(context: RepositoryContext, resource: Project): void;
7
+ actions: Partial<Record<ProjectUpdateAction['action'], (context: RepositoryContext, resource: Writable<Project>, action: any) => void>>;
8
8
  }
@@ -1,10 +1,10 @@
1
1
  import { ReferenceTypeId, ShippingMethod, ShippingMethodDraft, ShippingMethodUpdateAction } from '@commercetools/platform-sdk';
2
- import { AbstractResourceRepository } from './abstract';
2
+ import { AbstractResourceRepository, RepositoryContext } from './abstract';
3
3
  import { Writable } from 'types';
4
4
  export declare class ShippingMethodRepository extends AbstractResourceRepository {
5
5
  getTypeId(): ReferenceTypeId;
6
- create(projectKey: string, draft: ShippingMethodDraft): ShippingMethod;
6
+ create(context: RepositoryContext, draft: ShippingMethodDraft): ShippingMethod;
7
7
  private _transformZoneRateDraft;
8
8
  private _transformShippingRate;
9
- actions: Partial<Record<ShippingMethodUpdateAction['action'], (projectKey: string, resource: Writable<ShippingMethod>, action: any) => void>>;
9
+ actions: Partial<Record<ShippingMethodUpdateAction['action'], (context: RepositoryContext, resource: Writable<ShippingMethod>, action: any) => void>>;
10
10
  }
@@ -1,6 +1,6 @@
1
1
  import { ReferenceTypeId, ShoppingList, ShoppingListDraft } from '@commercetools/platform-sdk';
2
- import { AbstractResourceRepository } from './abstract';
2
+ import { AbstractResourceRepository, RepositoryContext } from './abstract';
3
3
  export declare class ShoppingListRepository extends AbstractResourceRepository {
4
4
  getTypeId(): ReferenceTypeId;
5
- create(projectKey: string, draft: ShoppingListDraft): ShoppingList;
5
+ create(context: RepositoryContext, draft: ShoppingListDraft): ShoppingList;
6
6
  }
@@ -1,8 +1,8 @@
1
1
  import { ReferenceTypeId, State, StateDraft, StateUpdateAction } from '@commercetools/platform-sdk';
2
- import { AbstractResourceRepository } from './abstract';
2
+ import { AbstractResourceRepository, RepositoryContext } from './abstract';
3
3
  import { Writable } from 'types';
4
4
  export declare class StateRepository extends AbstractResourceRepository {
5
5
  getTypeId(): ReferenceTypeId;
6
- create(projectKey: string, draft: StateDraft): State;
7
- actions: Partial<Record<StateUpdateAction['action'], (projectKey: string, resource: Writable<State>, action: any) => void>>;
6
+ create(context: RepositoryContext, draft: StateDraft): State;
7
+ actions: Partial<Record<StateUpdateAction['action'], (context: RepositoryContext, resource: Writable<State>, action: any) => void>>;
8
8
  }
@@ -1,10 +1,10 @@
1
1
  import { Store, StoreDraft, ReferenceTypeId, StoreUpdateAction } from '@commercetools/platform-sdk';
2
2
  import { Writable } from 'types';
3
- import { AbstractResourceRepository } from './abstract';
3
+ import { AbstractResourceRepository, RepositoryContext } from './abstract';
4
4
  export declare class StoreRepository extends AbstractResourceRepository {
5
5
  getTypeId(): ReferenceTypeId;
6
- create(projectKey: string, draft: StoreDraft): Store;
6
+ create(context: RepositoryContext, draft: StoreDraft): Store;
7
7
  private transformChannels;
8
- getWithKey(projectKey: string, key: string): Store | undefined;
9
- actions: Partial<Record<StoreUpdateAction['action'], (projectKey: string, resource: Writable<Store>, action: any) => void>>;
8
+ getWithKey(context: RepositoryContext, key: string): Store | undefined;
9
+ actions: Partial<Record<StoreUpdateAction['action'], (context: RepositoryContext, resource: Writable<Store>, action: any) => void>>;
10
10
  }
@@ -1,6 +1,6 @@
1
1
  import { ReferenceTypeId, Subscription, SubscriptionDraft } from '@commercetools/platform-sdk';
2
- import { AbstractResourceRepository } from './abstract';
2
+ import { AbstractResourceRepository, RepositoryContext } from './abstract';
3
3
  export declare class SubscriptionRepository extends AbstractResourceRepository {
4
4
  getTypeId(): ReferenceTypeId;
5
- create(projectKey: string, draft: SubscriptionDraft): Subscription;
5
+ create(context: RepositoryContext, draft: SubscriptionDraft): Subscription;
6
6
  }
@@ -1,10 +1,10 @@
1
1
  import { ReferenceTypeId, TaxCategory, TaxCategoryDraft, TaxCategoryUpdateAction } from '@commercetools/platform-sdk';
2
- import { AbstractResourceRepository } from './abstract';
2
+ import { AbstractResourceRepository, RepositoryContext } from './abstract';
3
3
  import { Writable } from 'types';
4
4
  export declare class TaxCategoryRepository extends AbstractResourceRepository {
5
5
  getTypeId(): ReferenceTypeId;
6
- create(projectKey: string, draft: TaxCategoryDraft): TaxCategory;
6
+ create(context: RepositoryContext, draft: TaxCategoryDraft): TaxCategory;
7
7
  private taxRateFromTaxRateDraft;
8
- getWithKey(projectKey: string, key: string): TaxCategory | undefined;
9
- actions: Partial<Record<TaxCategoryUpdateAction['action'], (projectKey: string, resource: Writable<TaxCategory>, action: any) => void>>;
8
+ getWithKey(context: RepositoryContext, key: string): TaxCategory | undefined;
9
+ actions: Partial<Record<TaxCategoryUpdateAction['action'], (context: RepositoryContext, resource: Writable<TaxCategory>, action: any) => void>>;
10
10
  }
@@ -1,8 +1,8 @@
1
1
  import { Type, TypeDraft, ReferenceTypeId, TypeUpdateAction } from '@commercetools/platform-sdk';
2
2
  import { Writable } from 'types';
3
- import { AbstractResourceRepository } from './abstract';
3
+ import { AbstractResourceRepository, RepositoryContext } from './abstract';
4
4
  export declare class TypeRepository extends AbstractResourceRepository {
5
5
  getTypeId(): ReferenceTypeId;
6
- create(projectKey: string, draft: TypeDraft): Type;
7
- actions: Partial<Record<TypeUpdateAction['action'], (projectKey: string, resource: Writable<Type>, action: any) => void>>;
6
+ create(context: RepositoryContext, draft: TypeDraft): Type;
7
+ actions: Partial<Record<TypeUpdateAction['action'], (context: RepositoryContext, resource: Writable<Type>, action: any) => void>>;
8
8
  }
@@ -1,8 +1,8 @@
1
1
  import { ReferenceTypeId, Zone, ZoneDraft, ZoneUpdateAction } from '@commercetools/platform-sdk';
2
2
  import { Writable } from 'types';
3
- import { AbstractResourceRepository } from './abstract';
3
+ import { AbstractResourceRepository, RepositoryContext } from './abstract';
4
4
  export declare class ZoneRepository extends AbstractResourceRepository {
5
5
  getTypeId(): ReferenceTypeId;
6
- create(projectKey: string, draft: ZoneDraft): Zone;
7
- actions: Partial<Record<ZoneUpdateAction['action'], (projectKey: string, resource: Writable<Zone>, action: any) => void>>;
6
+ create(context: RepositoryContext, draft: ZoneDraft): Zone;
7
+ actions: Partial<Record<ZoneUpdateAction['action'], (context: RepositoryContext, resource: Writable<Zone>, action: any) => void>>;
8
8
  }
@@ -1,9 +1,9 @@
1
1
  import AbstractService from './abstract';
2
2
  import { Router } from 'express';
3
3
  import { AbstractStorage } from '../storage';
4
- import { OrderRepository } from '../repositories/order';
4
+ import { MyOrderRepository } from '../repositories/my-order';
5
5
  export declare class MyOrderService extends AbstractService {
6
- repository: OrderRepository;
6
+ repository: MyOrderRepository;
7
7
  constructor(parent: Router, storage: AbstractStorage);
8
8
  getBasePath(): string;
9
9
  registerRoutes(parent: Router): void;
package/dist/storage.d.ts CHANGED
@@ -17,7 +17,7 @@ export declare abstract class AbstractStorage {
17
17
  abstract assertStorage(typeId: RepositoryTypes): void;
18
18
  abstract all(projectKey: string, typeId: RepositoryTypes): Array<BaseResource>;
19
19
  abstract add<RepositoryTypes extends keyof ResourceMap>(projectKey: string, typeId: RepositoryTypes, obj: ResourceMap[RepositoryTypes]): void;
20
- abstract get<RepositoryTypes extends keyof ResourceMap>(projectKey: string, typeId: RepositoryTypes, id: string, params: GetParams): ResourceMap[RepositoryTypes] | null;
20
+ abstract get<RepositoryTypes extends keyof ResourceMap>(projectKey: string, typeId: RepositoryTypes, id: string, params?: GetParams): ResourceMap[RepositoryTypes] | null;
21
21
  abstract getByKey<RepositoryTypes extends keyof ResourceMap>(projectKey: string, typeId: RepositoryTypes, key: string, params: GetParams): ResourceMap[RepositoryTypes] | null;
22
22
  abstract addProject(projectKey: string): Project;
23
23
  abstract getProject(projectKey: string): Project;
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.6.1",
2
+ "version": "0.6.4",
3
3
  "license": "MIT",
4
4
  "main": "dist/index.js",
5
5
  "typings": "dist/index.d.ts",
package/src/ctMock.ts CHANGED
@@ -139,8 +139,14 @@ export class CommercetoolsMock {
139
139
  // Only enable auth middleware if we have enabled this
140
140
  if (this.options.enableAuthentication) {
141
141
  app.use('/:projectKey', this._oauth2.createMiddleware(), projectRouter)
142
+ app.use(
143
+ '/:projectKey/in-store/key=:storeKey',
144
+ this._oauth2.createMiddleware(),
145
+ projectRouter
146
+ )
142
147
  } else {
143
148
  app.use('/:projectKey', projectRouter)
149
+ app.use('/:projectKey/in-store/key=:storeKey', projectRouter)
144
150
  }
145
151
 
146
152
  this._projectService = new ProjectService(projectRouter, this._storage)
package/src/projectAPI.ts CHANGED
@@ -41,7 +41,7 @@ export class ProjectAPI {
41
41
  get<ReferenceTypeId extends keyof ResourceMap>(
42
42
  typeId: ReferenceTypeId,
43
43
  id: string,
44
- params: GetParams
44
+ params?: GetParams
45
45
  ): ResourceMap[ReferenceTypeId] {
46
46
  return this._storage.get(
47
47
  this.projectKey,