@labdigital/commercetools-mock 2.28.0 → 2.29.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.js CHANGED
@@ -3890,12 +3890,13 @@ var MyCustomerRepository = class extends CustomerRepository {
3890
3890
  };
3891
3891
 
3892
3892
  // src/repositories/my-order.ts
3893
- import assert3 from "assert";
3893
+ import assert4 from "assert";
3894
3894
 
3895
3895
  // src/repositories/order/index.ts
3896
- import assert2 from "assert";
3896
+ import assert3 from "assert";
3897
3897
 
3898
3898
  // src/repositories/order/actions.ts
3899
+ import assert2 from "assert";
3899
3900
  var OrderUpdateHandler = class extends AbstractUpdateHandler {
3900
3901
  addPayment(context, resource, { payment }) {
3901
3902
  const resolvedPayment = this._storage.getByResourceIdentifier(
@@ -3991,6 +3992,21 @@ var OrderUpdateHandler = class extends AbstractUpdateHandler {
3991
3992
  };
3992
3993
  }
3993
3994
  }
3995
+ setDeliveryCustomField(context, resource, { deliveryId, name, value }) {
3996
+ assert2(resource.shippingInfo, "shippingInfo is not defined");
3997
+ if (Array.isArray(resource.shippingInfo.deliveries)) {
3998
+ resource.shippingInfo.deliveries.map((delivery) => {
3999
+ if (delivery.id !== deliveryId)
4000
+ throw "No matching delivery id found";
4001
+ if (delivery.custom) {
4002
+ const update = delivery.custom.fields;
4003
+ update[name] = value;
4004
+ Object.assign(delivery.custom.fields, update);
4005
+ }
4006
+ return delivery;
4007
+ });
4008
+ }
4009
+ }
3994
4010
  setLocale(context, resource, { locale }) {
3995
4011
  resource.locale = locale;
3996
4012
  }
@@ -4072,7 +4088,7 @@ var OrderRepository = class extends AbstractResourceRepository {
4072
4088
  this.actions = new OrderUpdateHandler(storage);
4073
4089
  }
4074
4090
  create(context, draft) {
4075
- assert2(draft.cart, "draft.cart is missing");
4091
+ assert3(draft.cart, "draft.cart is missing");
4076
4092
  return this.createFromCart(
4077
4093
  context,
4078
4094
  {
@@ -4113,7 +4129,7 @@ var OrderRepository = class extends AbstractResourceRepository {
4113
4129
  return this.saveNew(context, resource);
4114
4130
  }
4115
4131
  import(context, draft) {
4116
- assert2(this, "OrderRepository not valid");
4132
+ assert3(this, "OrderRepository not valid");
4117
4133
  const resource = {
4118
4134
  ...getBaseResourceProperties(),
4119
4135
  billingAddress: createAddress(
@@ -4256,7 +4272,7 @@ var OrderRepository = class extends AbstractResourceRepository {
4256
4272
  // src/repositories/my-order.ts
4257
4273
  var MyOrderRepository = class extends OrderRepository {
4258
4274
  create(context, draft) {
4259
- assert3(draft.id, "draft.id is missing");
4275
+ assert4(draft.id, "draft.id is missing");
4260
4276
  const cartIdentifier = {
4261
4277
  id: draft.id,
4262
4278
  typeId: "cart"
@@ -5087,6 +5103,67 @@ var ProductUpdateHandler = class extends AbstractUpdateHandler {
5087
5103
  checkForStagedChanges(resource);
5088
5104
  return resource;
5089
5105
  }
5106
+ setProductPriceCustomField(context, resource, { name, value, staged, priceId }) {
5107
+ const updatePriceCustomFields = (data) => {
5108
+ const price = [data.masterVariant, ...data.variants ?? []].flatMap((variant) => variant.prices ?? []).find((price2) => price2.id === priceId);
5109
+ if (!price) {
5110
+ throw new Error(
5111
+ `Price with id ${priceId} not found on product ${resource.id}`
5112
+ );
5113
+ }
5114
+ if (price.custom) {
5115
+ if (value === null) {
5116
+ delete price.custom.fields[name];
5117
+ } else {
5118
+ price.custom.fields[name] = value;
5119
+ }
5120
+ }
5121
+ return data;
5122
+ };
5123
+ resource.masterData.staged = updatePriceCustomFields(
5124
+ resource.masterData.staged
5125
+ );
5126
+ const onlyStaged = staged !== void 0 ? staged : true;
5127
+ if (!onlyStaged) {
5128
+ resource.masterData.current = updatePriceCustomFields(
5129
+ resource.masterData.current
5130
+ );
5131
+ }
5132
+ checkForStagedChanges(resource);
5133
+ return resource;
5134
+ }
5135
+ setProductPriceCustomType(context, resource, { type, fields, staged, priceId }) {
5136
+ const updatePriceCustomType = (data) => {
5137
+ const price = [data.masterVariant, ...data.variants ?? []].flatMap((variant) => variant.prices ?? []).find((price2) => price2.id === priceId);
5138
+ if (price) {
5139
+ if (type) {
5140
+ price.custom = createCustomFields(
5141
+ { type, fields },
5142
+ context.projectKey,
5143
+ this._storage
5144
+ );
5145
+ } else {
5146
+ price.custom = void 0;
5147
+ }
5148
+ } else {
5149
+ throw new Error(
5150
+ `Price with id ${priceId} not found on product ${resource.id}`
5151
+ );
5152
+ }
5153
+ return data;
5154
+ };
5155
+ resource.masterData.staged = updatePriceCustomType(
5156
+ resource.masterData.staged
5157
+ );
5158
+ const onlyStaged = staged !== void 0 ? staged : true;
5159
+ if (!onlyStaged) {
5160
+ resource.masterData.current = updatePriceCustomType(
5161
+ resource.masterData.current
5162
+ );
5163
+ }
5164
+ checkForStagedChanges(resource);
5165
+ return resource;
5166
+ }
5090
5167
  setTaxCategory(context, resource, { taxCategory }) {
5091
5168
  let taxCategoryReference = void 0;
5092
5169
  if (taxCategory) {
@@ -5134,8 +5211,6 @@ var ProductUpdateHandler = class extends AbstractUpdateHandler {
5134
5211
  checkForStagedChanges(resource);
5135
5212
  }
5136
5213
  // 'setPrices': () => {},
5137
- // 'setProductPriceCustomType': () => {},
5138
- // 'setProductPriceCustomField': () => {},
5139
5214
  // 'setDiscountedPrice': () => {},
5140
5215
  // 'setAttributeInAllVariants': () => {},
5141
5216
  // 'setCategoryOrderHint': () => {},