@labdigital/commercetools-mock 2.54.0 → 2.55.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/dist/index.d.ts +107 -77
  2. package/dist/index.d.ts.map +1 -1
  3. package/dist/index.js +280 -5
  4. package/dist/index.js.map +1 -1
  5. package/package.json +4 -3
  6. package/src/lib/productSearchFilter.test.ts +1 -0
  7. package/src/lib/projectionSearchFilter.test.ts +1 -0
  8. package/src/priceSelector.test.ts +1 -0
  9. package/src/product-projection-search.ts +2 -0
  10. package/src/product-search.ts +1 -0
  11. package/src/repositories/cart/index.test.ts +2 -0
  12. package/src/repositories/cart/index.ts +1 -0
  13. package/src/repositories/cart-discount/index.ts +1 -1
  14. package/src/repositories/customer/index.ts +2 -0
  15. package/src/repositories/discount-group/actions.ts +50 -0
  16. package/src/repositories/discount-group/index.ts +29 -0
  17. package/src/repositories/index.ts +6 -0
  18. package/src/repositories/order/index.test.ts +126 -125
  19. package/src/repositories/payment/actions.ts +87 -0
  20. package/src/repositories/payment/index.ts +1 -1
  21. package/src/repositories/product/index.ts +1 -0
  22. package/src/repositories/product-type.ts +1 -0
  23. package/src/repositories/quote/index.ts +1 -0
  24. package/src/repositories/quote-request/index.test.ts +1 -0
  25. package/src/repositories/quote-request/index.ts +1 -0
  26. package/src/repositories/recurrence-policy/actions.ts +53 -0
  27. package/src/repositories/recurrence-policy/index.ts +36 -0
  28. package/src/repositories/recurring-order/actions.ts +157 -0
  29. package/src/repositories/recurring-order/index.ts +52 -0
  30. package/src/repositories/review.test.ts +2 -0
  31. package/src/repositories/shopping-list/actions.ts +1 -0
  32. package/src/repositories/shopping-list/index.ts +1 -0
  33. package/src/services/discount-group.test.ts +270 -0
  34. package/src/services/discount-group.ts +16 -0
  35. package/src/services/index.ts +12 -0
  36. package/src/services/my-cart.test.ts +1 -0
  37. package/src/services/my-payment.test.ts +1 -0
  38. package/src/services/payment.test.ts +1 -0
  39. package/src/services/product-projection.test.ts +4 -0
  40. package/src/services/product-type.test.ts +1 -0
  41. package/src/services/product.test.ts +1 -0
  42. package/src/services/recurrence-policy.test.ts +316 -0
  43. package/src/services/recurrence-policy.ts +16 -0
  44. package/src/services/recurring-order.test.ts +424 -0
  45. package/src/services/recurring-order.ts +16 -0
  46. package/src/services/shopping-list.test.ts +3 -0
  47. package/src/storage/in-memory.ts +6 -0
  48. package/src/types.ts +6 -0
package/dist/index.js CHANGED
@@ -1129,6 +1129,7 @@ var CartRepository = class extends AbstractResourceRepository {
1129
1129
  itemShippingAddresses: [],
1130
1130
  lineItems,
1131
1131
  locale: draft.locale,
1132
+ priceRoundingMode: draft.priceRoundingMode ?? "HalfEven",
1132
1133
  taxCalculationMode: draft.taxCalculationMode ?? "LineItemLevel",
1133
1134
  taxMode: draft.taxMode ?? "Platform",
1134
1135
  taxRoundingMode: draft.taxRoundingMode ?? "HalfEven",
@@ -1565,6 +1566,7 @@ var QuoteRequestRepository = class extends AbstractResourceRepository {
1565
1566
  directDiscounts: cart.directDiscounts,
1566
1567
  lineItems: cart.lineItems,
1567
1568
  paymentInfo: cart.paymentInfo,
1569
+ priceRoundingMode: cart.priceRoundingMode,
1568
1570
  quoteRequestState: "Submitted",
1569
1571
  shippingAddress: cart.shippingAddress,
1570
1572
  taxCalculationMode: cart.taxCalculationMode,
@@ -1922,7 +1924,7 @@ var CartDiscountRepository = class extends AbstractResourceRepository {
1922
1924
  references: [],
1923
1925
  target: draft.target,
1924
1926
  requiresDiscountCode: draft.requiresDiscountCode || false,
1925
- sortOrder: draft.sortOrder,
1927
+ sortOrder: draft.sortOrder ?? "0.1",
1926
1928
  stackingMode: draft.stackingMode || "Stacking",
1927
1929
  validFrom: draft.validFrom,
1928
1930
  validUntil: draft.validUntil,
@@ -2487,7 +2489,8 @@ var CustomerRepository = class extends AbstractResourceRepository {
2487
2489
  lastModifiedAt: rest.lastModifiedAt,
2488
2490
  customerId: customer.id,
2489
2491
  expiresAt: expiresAt.toISOString(),
2490
- value: token
2492
+ value: token,
2493
+ invalidateOlderTokens: request.invalidateOlderTokens || false
2491
2494
  };
2492
2495
  }
2493
2496
  passwordReset(context, resetPassword) {
@@ -2523,7 +2526,8 @@ var CustomerRepository = class extends AbstractResourceRepository {
2523
2526
  lastModifiedAt: rest.lastModifiedAt,
2524
2527
  customerId: customer.id,
2525
2528
  expiresAt: expiresAt.toISOString(),
2526
- value: token
2529
+ value: token,
2530
+ invalidateOlderTokens: false
2527
2531
  };
2528
2532
  }
2529
2533
  storeReferenceToStoreKeyReference(draftStores, projectKey) {
@@ -2664,6 +2668,42 @@ var DiscountCodeRepository = class extends AbstractResourceRepository {
2664
2668
  }
2665
2669
  };
2666
2670
 
2671
+ //#endregion
2672
+ //#region src/repositories/discount-group/actions.ts
2673
+ var DiscountGroupUpdateHandler = class extends AbstractUpdateHandler {
2674
+ setDescription(context, resource, { description }) {
2675
+ resource.description = description;
2676
+ }
2677
+ setKey(context, resource, { key }) {
2678
+ resource.key = key;
2679
+ }
2680
+ setName(context, resource, { name }) {
2681
+ resource.name = name;
2682
+ }
2683
+ setSortOrder(context, resource, { sortOrder }) {
2684
+ resource.sortOrder = sortOrder;
2685
+ }
2686
+ };
2687
+
2688
+ //#endregion
2689
+ //#region src/repositories/discount-group/index.ts
2690
+ var DiscountGroupRepository = class extends AbstractResourceRepository {
2691
+ constructor(config) {
2692
+ super("discount-group", config);
2693
+ this.actions = new DiscountGroupUpdateHandler(config.storage);
2694
+ }
2695
+ create(context, draft) {
2696
+ const resource = {
2697
+ ...getBaseResourceProperties(),
2698
+ description: draft.description,
2699
+ name: draft.name,
2700
+ key: draft.key,
2701
+ sortOrder: draft.sortOrder
2702
+ };
2703
+ return this.saveNew(context, resource);
2704
+ }
2705
+ };
2706
+
2667
2707
  //#endregion
2668
2708
  //#region src/lib/masking.ts
2669
2709
  const maskSecretValue = (resource, path) => {
@@ -2982,6 +3022,37 @@ var PaymentUpdateHandler = class extends AbstractUpdateHandler {
2982
3022
  obj: stateObj
2983
3023
  };
2984
3024
  }
3025
+ setMethodInfo(context, resource, { paymentInterface, method, name, interfaceAccount, token }) {
3026
+ if (paymentInterface !== void 0) resource.paymentMethodInfo.paymentInterface = paymentInterface;
3027
+ if (method !== void 0) resource.paymentMethodInfo.method = method;
3028
+ if (name !== void 0) resource.paymentMethodInfo.name = name;
3029
+ if (interfaceAccount !== void 0) resource.paymentMethodInfo.interfaceAccount = interfaceAccount;
3030
+ if (token !== void 0) resource.paymentMethodInfo.token = token;
3031
+ }
3032
+ setMethodInfoCustomField(context, resource, { name, value }) {
3033
+ if (!resource.paymentMethodInfo.custom) throw new Error("PaymentMethodInfo has no custom field");
3034
+ resource.paymentMethodInfo.custom.fields[name] = value;
3035
+ }
3036
+ setMethodInfoCustomType(context, resource, { type, fields }) {
3037
+ if (!type) resource.paymentMethodInfo.custom = void 0;
3038
+ else {
3039
+ const resolvedType = this._storage.getByResourceIdentifier(context.projectKey, type);
3040
+ if (!resolvedType) throw new Error(`Type ${type} not found`);
3041
+ resource.paymentMethodInfo.custom = {
3042
+ type: {
3043
+ typeId: "type",
3044
+ id: resolvedType.id
3045
+ },
3046
+ fields: fields ?? {}
3047
+ };
3048
+ }
3049
+ }
3050
+ setMethodInfoInterfaceAccount(_context, resource, { interfaceAccount }) {
3051
+ resource.paymentMethodInfo.interfaceAccount = interfaceAccount;
3052
+ }
3053
+ setMethodInfoToken(_context, resource, { token }) {
3054
+ resource.paymentMethodInfo.token = token;
3055
+ }
2985
3056
  };
2986
3057
 
2987
3058
  //#endregion
@@ -2996,7 +3067,10 @@ var PaymentRepository = class extends AbstractResourceRepository {
2996
3067
  ...getBaseResourceProperties(),
2997
3068
  key: draft.key,
2998
3069
  amountPlanned: createCentPrecisionMoney(draft.amountPlanned),
2999
- paymentMethodInfo: draft.paymentMethodInfo,
3070
+ paymentMethodInfo: {
3071
+ ...draft.paymentMethodInfo,
3072
+ custom: void 0
3073
+ },
3000
3074
  paymentStatus: draft.paymentStatus ? {
3001
3075
  ...draft.paymentStatus,
3002
3076
  state: draft.paymentStatus.state ? getReferenceFromResourceIdentifier(draft.paymentStatus.state, context.projectKey, this._storage) : void 0
@@ -4032,6 +4106,7 @@ var ProductSearch = class {
4032
4106
  metaDescription: obj.metaDescription,
4033
4107
  slug: obj.slug,
4034
4108
  categories: obj.categories,
4109
+ attributes: obj.attributes,
4035
4110
  masterVariant: {
4036
4111
  ...obj.masterVariant,
4037
4112
  availability: getVariantAvailability(obj.masterVariant.sku)
@@ -4496,6 +4571,7 @@ var ProductRepository = class extends AbstractResourceRepository {
4496
4571
  name: draft.name,
4497
4572
  slug: draft.slug,
4498
4573
  description: draft.description,
4574
+ attributes: draft.attributes ?? [],
4499
4575
  categories: categoryReferences,
4500
4576
  masterVariant: variantFromDraft(context, this._storage, 1, draft.masterVariant),
4501
4577
  variants: draft.variants?.map((variant, index) => variantFromDraft(context, this._storage, index + 2, variant)) ?? [],
@@ -4907,6 +4983,7 @@ var ProductProjectionSearch = class {
4907
4983
  return {
4908
4984
  id: product.id,
4909
4985
  createdAt: product.createdAt,
4986
+ attributes: obj.attributes,
4910
4987
  lastModifiedAt: product.lastModifiedAt,
4911
4988
  version: product.version,
4912
4989
  name: obj.name,
@@ -5139,6 +5216,7 @@ var ProductTypeRepository = class extends AbstractResourceRepository {
5139
5216
  };
5140
5217
  const attributeDefinitionFromAttributeDefinitionDraft = (_context, draft) => ({
5141
5218
  ...draft,
5219
+ level: draft.level ?? "Variant",
5142
5220
  attributeConstraint: draft.attributeConstraint ?? "None",
5143
5221
  inputHint: draft.inputHint ?? "SingleLine",
5144
5222
  inputTip: draft.inputTip && Object.keys(draft.inputTip).length > 0 ? draft.inputTip : void 0,
@@ -5347,6 +5425,7 @@ var QuoteRepository = class extends AbstractResourceRepository {
5347
5425
  typeId: "staged-quote",
5348
5426
  id: staged.id
5349
5427
  },
5428
+ priceRoundingMode: cart.priceRoundingMode,
5350
5429
  totalPrice: cart.totalPrice,
5351
5430
  taxedPrice: cart.taxedPrice,
5352
5431
  taxMode: cart.taxMode,
@@ -5421,6 +5500,152 @@ var StagedQuoteRepository = class extends AbstractResourceRepository {
5421
5500
  }
5422
5501
  };
5423
5502
 
5503
+ //#endregion
5504
+ //#region src/repositories/recurrence-policy/actions.ts
5505
+ var RecurrencePolicyUpdateHandler = class extends AbstractUpdateHandler {
5506
+ setKey(context, resource, { key }) {
5507
+ if (key) resource.key = key;
5508
+ }
5509
+ setDescription(context, resource, { description }) {
5510
+ resource.description = description;
5511
+ }
5512
+ setName(context, resource, { name }) {
5513
+ resource.name = name;
5514
+ }
5515
+ setSchedule(context, resource, { schedule }) {
5516
+ resource.schedule = schedule;
5517
+ }
5518
+ };
5519
+
5520
+ //#endregion
5521
+ //#region src/repositories/recurrence-policy/index.ts
5522
+ var RecurrencePolicyRepository = class extends AbstractResourceRepository {
5523
+ constructor(config) {
5524
+ super("recurrence-policy", config);
5525
+ this.actions = new RecurrencePolicyUpdateHandler(config.storage);
5526
+ }
5527
+ create(context, draft) {
5528
+ const resource = {
5529
+ ...getBaseResourceProperties(),
5530
+ key: draft.key,
5531
+ name: draft.name,
5532
+ description: draft.description,
5533
+ schedule: draft.schedule
5534
+ };
5535
+ return this.saveNew(context, resource);
5536
+ }
5537
+ };
5538
+
5539
+ //#endregion
5540
+ //#region src/repositories/recurring-order/actions.ts
5541
+ var RecurringOrderUpdateHandler = class extends AbstractUpdateHandler {
5542
+ setCustomField(context, resource, { name, value }) {
5543
+ if (!resource.custom) throw new Error("Resource has no custom field");
5544
+ if (value === null) delete resource.custom.fields[name];
5545
+ else resource.custom.fields[name] = value;
5546
+ }
5547
+ setCustomType(context, resource, { type, fields }) {
5548
+ if (!type) resource.custom = void 0;
5549
+ else {
5550
+ const resolvedType = this._storage.getByResourceIdentifier(context.projectKey, type);
5551
+ if (!resolvedType) throw new Error(`Type ${type} not found`);
5552
+ resource.custom = {
5553
+ type: {
5554
+ typeId: "type",
5555
+ id: resolvedType.id
5556
+ },
5557
+ fields: fields || {}
5558
+ };
5559
+ }
5560
+ }
5561
+ setExpiresAt(context, resource, { expiresAt }) {
5562
+ resource.expiresAt = expiresAt;
5563
+ }
5564
+ setKey(context, resource, { key }) {
5565
+ resource.key = key;
5566
+ }
5567
+ setOrderSkipConfiguration(context, resource, { skipConfiguration, updatedExpiresAt }) {
5568
+ if (skipConfiguration) resource.skipConfiguration = {
5569
+ type: skipConfiguration.type,
5570
+ totalToSkip: skipConfiguration.totalToSkip,
5571
+ skipped: 0,
5572
+ lastSkippedAt: void 0
5573
+ };
5574
+ else resource.skipConfiguration = void 0;
5575
+ if (updatedExpiresAt !== void 0) resource.expiresAt = updatedExpiresAt;
5576
+ }
5577
+ setSchedule(context, resource, { recurrencePolicy }) {
5578
+ resource.schedule = {
5579
+ ...resource.schedule,
5580
+ ...recurrencePolicy
5581
+ };
5582
+ }
5583
+ setStartsAt(context, resource, { startsAt }) {
5584
+ resource.startsAt = startsAt;
5585
+ }
5586
+ setRecurringOrderState(context, resource, { recurringOrderState }) {
5587
+ switch (recurringOrderState.type) {
5588
+ case "active":
5589
+ resource.recurringOrderState = "Active";
5590
+ if (recurringOrderState.resumesAt) resource.resumesAt = recurringOrderState.resumesAt;
5591
+ break;
5592
+ case "canceled":
5593
+ resource.recurringOrderState = "Canceled";
5594
+ break;
5595
+ case "expired":
5596
+ resource.recurringOrderState = "Expired";
5597
+ break;
5598
+ case "paused":
5599
+ resource.recurringOrderState = "Paused";
5600
+ break;
5601
+ }
5602
+ }
5603
+ transitionState(context, resource, { state, force }) {
5604
+ resource.state = {
5605
+ typeId: "state",
5606
+ id: state.id
5607
+ };
5608
+ }
5609
+ };
5610
+
5611
+ //#endregion
5612
+ //#region src/repositories/recurring-order/index.ts
5613
+ var RecurringOrderRepository = class extends AbstractResourceRepository {
5614
+ constructor(config) {
5615
+ super("recurring-order", config);
5616
+ this.actions = new RecurringOrderUpdateHandler(config.storage);
5617
+ }
5618
+ create(context, draft) {
5619
+ assert(draft.cart, "draft.cart is missing");
5620
+ const orderRepo = new OrderRepository(this.config);
5621
+ const initialOrder = orderRepo.createFromCart(context, {
5622
+ id: draft.cart.id,
5623
+ typeId: "cart"
5624
+ });
5625
+ const resource = {
5626
+ ...getBaseResourceProperties(),
5627
+ key: draft.key,
5628
+ cart: {
5629
+ typeId: "cart",
5630
+ id: draft.cart.id
5631
+ },
5632
+ originOrder: {
5633
+ typeId: "order",
5634
+ id: initialOrder.id
5635
+ },
5636
+ startsAt: draft.startsAt,
5637
+ expiresAt: draft.expiresAt,
5638
+ recurringOrderState: "Active",
5639
+ schedule: {
5640
+ type: "standard",
5641
+ intervalUnit: "month",
5642
+ value: 1
5643
+ }
5644
+ };
5645
+ return this.saveNew(context, resource);
5646
+ }
5647
+ };
5648
+
5424
5649
  //#endregion
5425
5650
  //#region src/repositories/review.ts
5426
5651
  var ReviewRepository = class extends AbstractResourceRepository {
@@ -5640,7 +5865,8 @@ var ShoppingListUpdateHandler = class extends AbstractUpdateHandler {
5640
5865
  productType: product.productType,
5641
5866
  name: product.masterData.current.name,
5642
5867
  variantId: varId,
5643
- quantity
5868
+ quantity,
5869
+ published: Boolean(product.masterData.current)
5644
5870
  });
5645
5871
  }
5646
5872
  changeLineItemQuantity(context, resource, { lineItemId, lineItemKey, quantity }) {
@@ -5760,6 +5986,7 @@ var ShoppingListRepository = class extends AbstractResourceRepository {
5760
5986
  productId: draftLineItem.productId ?? "",
5761
5987
  name: {},
5762
5988
  variantId,
5989
+ published: true,
5763
5990
  quantity: draftLineItem.quantity ?? 1,
5764
5991
  productType: {
5765
5992
  typeId: "product-type",
@@ -6161,6 +6388,7 @@ const createRepositories = (config) => ({
6161
6388
  channel: new ChannelRepository(config),
6162
6389
  "customer-group": new CustomerGroupRepository(config),
6163
6390
  "discount-code": new DiscountCodeRepository(config),
6391
+ "discount-group": new DiscountGroupRepository(config),
6164
6392
  extension: new ExtensionRepository(config),
6165
6393
  "inventory-entry": new InventoryEntryRepository(config),
6166
6394
  "key-value-document": new CustomObjectRepository(config),
@@ -6179,6 +6407,8 @@ const createRepositories = (config) => ({
6179
6407
  "product-selection": new ProductSelectionRepository(config),
6180
6408
  "product-tailoring": new ProductTailoringRepository(config),
6181
6409
  project: new ProjectRepository(config),
6410
+ "recurring-order": new RecurringOrderRepository(config),
6411
+ "recurrence-policy": new RecurrencePolicyRepository(config),
6182
6412
  review: new ReviewRepository(config),
6183
6413
  quote: new QuoteRepository(config),
6184
6414
  "quote-request": new QuoteRequestRepository(config),
@@ -6670,6 +6900,19 @@ var DiscountCodeService = class extends AbstractService {
6670
6900
  }
6671
6901
  };
6672
6902
 
6903
+ //#endregion
6904
+ //#region src/services/discount-group.ts
6905
+ var DiscountGroupService = class extends AbstractService {
6906
+ repository;
6907
+ constructor(parent, repository) {
6908
+ super(parent);
6909
+ this.repository = repository;
6910
+ }
6911
+ getBasePath() {
6912
+ return "discount-groups";
6913
+ }
6914
+ };
6915
+
6673
6916
  //#endregion
6674
6917
  //#region src/services/extension.ts
6675
6918
  var ExtensionServices = class extends AbstractService {
@@ -7101,6 +7344,32 @@ var StagedQuoteService = class extends AbstractService {
7101
7344
  }
7102
7345
  };
7103
7346
 
7347
+ //#endregion
7348
+ //#region src/services/recurrence-policy.ts
7349
+ var RecurrencePolicyService = class extends AbstractService {
7350
+ repository;
7351
+ constructor(parent, repository) {
7352
+ super(parent);
7353
+ this.repository = repository;
7354
+ }
7355
+ getBasePath() {
7356
+ return "recurrence-policies";
7357
+ }
7358
+ };
7359
+
7360
+ //#endregion
7361
+ //#region src/services/recurring-order.ts
7362
+ var RecurringOrderService = class extends AbstractService {
7363
+ repository;
7364
+ constructor(parent, repository) {
7365
+ super(parent);
7366
+ this.repository = repository;
7367
+ }
7368
+ getBasePath() {
7369
+ return "recurring-orders";
7370
+ }
7371
+ };
7372
+
7104
7373
  //#endregion
7105
7374
  //#region src/services/reviews.ts
7106
7375
  var ReviewService = class extends AbstractService {
@@ -7258,6 +7527,7 @@ const createServices = (router, repos) => ({
7258
7527
  channel: new ChannelService(router, repos.channel),
7259
7528
  "customer-group": new CustomerGroupService(router, repos["customer-group"]),
7260
7529
  "discount-code": new DiscountCodeService(router, repos["discount-code"]),
7530
+ "discount-group": new DiscountGroupService(router, repos["discount-group"]),
7261
7531
  extension: new ExtensionServices(router, repos.extension),
7262
7532
  "inventory-entry": new InventoryEntryService(router, repos["inventory-entry"]),
7263
7533
  "key-value-document": new CustomObjectService(router, repos["key-value-document"]),
@@ -7278,6 +7548,8 @@ const createServices = (router, repos) => ({
7278
7548
  "product-selection": new ProductSelectionService(router, repos["product-selection"]),
7279
7549
  quotes: new QuoteService(router, repos.quote),
7280
7550
  "quote-request": new QuoteRequestService(router, repos["quote-request"]),
7551
+ "recurrence-policy": new RecurrencePolicyService(router, repos["recurrence-policy"]),
7552
+ "recurring-order": new RecurringOrderService(router, repos["recurring-order"]),
7281
7553
  reviews: new ReviewService(router, repos.review),
7282
7554
  "shopping-list": new ShoppingListService(router, repos["shopping-list"]),
7283
7555
  "staged-quote": new StagedQuoteService(router, repos["staged-quote"]),
@@ -7402,6 +7674,7 @@ var InMemoryStorage = class extends AbstractStorage {
7402
7674
  customer: new Map(),
7403
7675
  "customer-group": new Map(),
7404
7676
  "discount-code": new Map(),
7677
+ "discount-group": new Map(),
7405
7678
  extension: new Map(),
7406
7679
  "inventory-entry": new Map(),
7407
7680
  "key-value-document": new Map(),
@@ -7416,6 +7689,8 @@ var InMemoryStorage = class extends AbstractStorage {
7416
7689
  "product-type": new Map(),
7417
7690
  "product-projection": new Map(),
7418
7691
  "product-tailoring": new Map(),
7692
+ "recurrence-policy": new Map(),
7693
+ "recurring-order": new Map(),
7419
7694
  review: new Map(),
7420
7695
  "shipping-method": new Map(),
7421
7696
  "staged-quote": new Map(),