@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.cjs CHANGED
@@ -3927,12 +3927,13 @@ var MyCustomerRepository = class extends CustomerRepository {
3927
3927
  };
3928
3928
 
3929
3929
  // src/repositories/my-order.ts
3930
- var import_assert3 = __toESM(require("assert"), 1);
3930
+ var import_assert4 = __toESM(require("assert"), 1);
3931
3931
 
3932
3932
  // src/repositories/order/index.ts
3933
- var import_assert2 = __toESM(require("assert"), 1);
3933
+ var import_assert3 = __toESM(require("assert"), 1);
3934
3934
 
3935
3935
  // src/repositories/order/actions.ts
3936
+ var import_assert2 = __toESM(require("assert"), 1);
3936
3937
  var OrderUpdateHandler = class extends AbstractUpdateHandler {
3937
3938
  addPayment(context, resource, { payment }) {
3938
3939
  const resolvedPayment = this._storage.getByResourceIdentifier(
@@ -4028,6 +4029,21 @@ var OrderUpdateHandler = class extends AbstractUpdateHandler {
4028
4029
  };
4029
4030
  }
4030
4031
  }
4032
+ setDeliveryCustomField(context, resource, { deliveryId, name, value }) {
4033
+ (0, import_assert2.default)(resource.shippingInfo, "shippingInfo is not defined");
4034
+ if (Array.isArray(resource.shippingInfo.deliveries)) {
4035
+ resource.shippingInfo.deliveries.map((delivery) => {
4036
+ if (delivery.id !== deliveryId)
4037
+ throw "No matching delivery id found";
4038
+ if (delivery.custom) {
4039
+ const update = delivery.custom.fields;
4040
+ update[name] = value;
4041
+ Object.assign(delivery.custom.fields, update);
4042
+ }
4043
+ return delivery;
4044
+ });
4045
+ }
4046
+ }
4031
4047
  setLocale(context, resource, { locale }) {
4032
4048
  resource.locale = locale;
4033
4049
  }
@@ -4109,7 +4125,7 @@ var OrderRepository = class extends AbstractResourceRepository {
4109
4125
  this.actions = new OrderUpdateHandler(storage);
4110
4126
  }
4111
4127
  create(context, draft) {
4112
- (0, import_assert2.default)(draft.cart, "draft.cart is missing");
4128
+ (0, import_assert3.default)(draft.cart, "draft.cart is missing");
4113
4129
  return this.createFromCart(
4114
4130
  context,
4115
4131
  {
@@ -4150,7 +4166,7 @@ var OrderRepository = class extends AbstractResourceRepository {
4150
4166
  return this.saveNew(context, resource);
4151
4167
  }
4152
4168
  import(context, draft) {
4153
- (0, import_assert2.default)(this, "OrderRepository not valid");
4169
+ (0, import_assert3.default)(this, "OrderRepository not valid");
4154
4170
  const resource = {
4155
4171
  ...getBaseResourceProperties(),
4156
4172
  billingAddress: createAddress(
@@ -4293,7 +4309,7 @@ var OrderRepository = class extends AbstractResourceRepository {
4293
4309
  // src/repositories/my-order.ts
4294
4310
  var MyOrderRepository = class extends OrderRepository {
4295
4311
  create(context, draft) {
4296
- (0, import_assert3.default)(draft.id, "draft.id is missing");
4312
+ (0, import_assert4.default)(draft.id, "draft.id is missing");
4297
4313
  const cartIdentifier = {
4298
4314
  id: draft.id,
4299
4315
  typeId: "cart"
@@ -5124,6 +5140,67 @@ var ProductUpdateHandler = class extends AbstractUpdateHandler {
5124
5140
  checkForStagedChanges(resource);
5125
5141
  return resource;
5126
5142
  }
5143
+ setProductPriceCustomField(context, resource, { name, value, staged, priceId }) {
5144
+ const updatePriceCustomFields = (data) => {
5145
+ const price = [data.masterVariant, ...data.variants ?? []].flatMap((variant) => variant.prices ?? []).find((price2) => price2.id === priceId);
5146
+ if (!price) {
5147
+ throw new Error(
5148
+ `Price with id ${priceId} not found on product ${resource.id}`
5149
+ );
5150
+ }
5151
+ if (price.custom) {
5152
+ if (value === null) {
5153
+ delete price.custom.fields[name];
5154
+ } else {
5155
+ price.custom.fields[name] = value;
5156
+ }
5157
+ }
5158
+ return data;
5159
+ };
5160
+ resource.masterData.staged = updatePriceCustomFields(
5161
+ resource.masterData.staged
5162
+ );
5163
+ const onlyStaged = staged !== void 0 ? staged : true;
5164
+ if (!onlyStaged) {
5165
+ resource.masterData.current = updatePriceCustomFields(
5166
+ resource.masterData.current
5167
+ );
5168
+ }
5169
+ checkForStagedChanges(resource);
5170
+ return resource;
5171
+ }
5172
+ setProductPriceCustomType(context, resource, { type, fields, staged, priceId }) {
5173
+ const updatePriceCustomType = (data) => {
5174
+ const price = [data.masterVariant, ...data.variants ?? []].flatMap((variant) => variant.prices ?? []).find((price2) => price2.id === priceId);
5175
+ if (price) {
5176
+ if (type) {
5177
+ price.custom = createCustomFields(
5178
+ { type, fields },
5179
+ context.projectKey,
5180
+ this._storage
5181
+ );
5182
+ } else {
5183
+ price.custom = void 0;
5184
+ }
5185
+ } else {
5186
+ throw new Error(
5187
+ `Price with id ${priceId} not found on product ${resource.id}`
5188
+ );
5189
+ }
5190
+ return data;
5191
+ };
5192
+ resource.masterData.staged = updatePriceCustomType(
5193
+ resource.masterData.staged
5194
+ );
5195
+ const onlyStaged = staged !== void 0 ? staged : true;
5196
+ if (!onlyStaged) {
5197
+ resource.masterData.current = updatePriceCustomType(
5198
+ resource.masterData.current
5199
+ );
5200
+ }
5201
+ checkForStagedChanges(resource);
5202
+ return resource;
5203
+ }
5127
5204
  setTaxCategory(context, resource, { taxCategory }) {
5128
5205
  let taxCategoryReference = void 0;
5129
5206
  if (taxCategory) {
@@ -5171,8 +5248,6 @@ var ProductUpdateHandler = class extends AbstractUpdateHandler {
5171
5248
  checkForStagedChanges(resource);
5172
5249
  }
5173
5250
  // 'setPrices': () => {},
5174
- // 'setProductPriceCustomType': () => {},
5175
- // 'setProductPriceCustomField': () => {},
5176
5251
  // 'setDiscountedPrice': () => {},
5177
5252
  // 'setAttributeInAllVariants': () => {},
5178
5253
  // 'setCategoryOrderHint': () => {},